diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/date.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/date.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/date.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/date.inl 2020-12-12 17:06:43.052345522 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * date.inl + * template function of "date" and "time" types. + * + * + * src/backend/vecexecutor/vecprimitive/date.inl + * + *------------------------------------------------------------------------- + */ + +#ifndef DATE_INL +#define DATE_INL + +#include "utils/date.h" +#include "utils/datetime.h" + + +#endif + diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/float.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/float.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/float.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/float.inl 2020-12-12 17:06:43.052345522 +0800 @@ -0,0 +1,611 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * float.inl + * template implementation of float. + * + * + * src/backend/vecexecutor/vecprimitive/float.inl + * + *------------------------------------------------------------------------- + */ + +#ifndef FLOAT_INL +#define FLOAT_INL + +#include "vecexecutor/vechashtable.h" +#include "utils/array.h" + +template +ScalarVector* +vfloat4_sop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + uint8* pflag = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (PG_GETARG_VECTOR(1)->m_flag); + int i; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = DatumGetBool(DirectFunctionCall2(floatFun,parg1[i], parg2[i])); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = DatumGetBool(DirectFunctionCall2(floatFun,parg1[i], parg2[i])); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = BOOLOID; + + return PG_GETARG_VECTOR(3); +} + +/* +* @Description: For each level of avg/stddev_samp, a final operation is needed +* @in isTransition - is the first stage of avg/stddev_samp. If so, input is int8 type, or array type. +* @in singlenode - is the last stage of avg/stddev_samp. If so, output is float8 type, or array type. +* @in is_samp- is avg or stddev_samp +* @return - ScalarVector +*/ +template +Datum +vfloat_avg_final(PG_FUNCTION_ARGS) +{ + hashCell* cell = (hashCell*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + ScalarValue* m_vals = (ScalarValue*)PG_GETARG_DATUM(2); + uint8 *m_flag = (uint8*)PG_GETARG_DATUM(3); + ArrayType *transarray = NULL; + float8 *transvalues = NULL; + + Datum args[3]; + Datum arg; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + if(singlenode) + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[0] = cell->m_val[idx].val; + if (isTransition) + args[1] = DirectFunctionCall1(i8tod,cell->m_val[idx + 1].val); + else + args[1] = cell->m_val[idx + 1].val; + + if (is_samp) + { + args[2] = cell->m_val[idx + 2].val; + } + else + { + args[2] = DatumGetFloat8(args[0]) * DatumGetFloat8(args[0]); + } + + if (false == is_samp) + { + *m_vals = float8div(&finfo); + SET_NOTNULL(*m_flag); + } + else + { + transarray = construct_array(args, 3, FLOAT8OID, sizeof(float8), true, 'd'); + transvalues = check_float8_array(transarray, "float8_accum", 3); + + transvalues[0] = DatumGetFloat8(args[1]); + transvalues[1] = DatumGetFloat8(args[0]); + transvalues[2] = DatumGetFloat8(args[2]); + + finfo.arg = &arg; + arg = PointerGetDatum(transarray); + + finfo.isnull = false; + *m_vals = float8_stddev_samp(&finfo); + + if (finfo.isnull) + SET_NULL(*m_flag); + else + SET_NOTNULL(*m_flag); + } + } + else //construct a array type. + { + if (IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[0] = cell->m_val[idx].val; + if (isTransition) + args[1] = DirectFunctionCall1(i8tod,cell->m_val[idx + 1].val); + else + args[1] = cell->m_val[idx + 1].val; + + if (is_samp) + { + args[2] = cell->m_val[idx + 2].val; + } + else + { + args[2] = DatumGetFloat8(args[0]) * DatumGetFloat8(args[0]); + } + + transarray = construct_array(args, 3, FLOAT8OID, sizeof(float8), true, 'd'); + transvalues = check_float8_array(transarray, "float8_accum", 3); + + transvalues[0] = DatumGetFloat8(args[1]); + transvalues[1] = DatumGetFloat8(args[0]); + transvalues[2] = DatumGetFloat8(args[2]); + + *m_vals = PointerGetDatum(transarray); + SET_NOTNULL(*m_flag); + } + + return (Datum) 0; +} + + +/* +* @Description: For each level of avg/stddev_samp, a trans operation is needed +* @in isTransition - is the first stage of avg/stddev_samp. +* @in is_samp- is avg or stddev_samp +* @return - ScalarVector +*/ +template +ScalarVector* +vfloat8_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector1 = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector1->m_vals; + uint8* flag = pVector1->m_flag; + int nrows = pVector1->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + ArrayType *transarray = NULL; + float8 *transvalues = NULL; + + finfo.arg = &args[0]; + + for (i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if (cell && IS_NULL(flag[i]) == false) //only do when not null + { + if (IS_NULL(cell->m_val[idx].flag)) + { + if (isTransition) + { + cell->m_val[idx].val = pVal[i]; + cell->m_val[idx + 1].val = 1; //count set 1 + if (is_samp) + { + cell->m_val[idx + 2].val = DirectFunctionCall2(float8mul, pVal[i], pVal[i]); + } + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transvalues = check_float8_array(transarray, "float8_avg", 3); + cell->m_val[idx].val = Float8GetDatum(transvalues[1]); + cell->m_val[idx + 1].val = Float8GetDatum(transvalues[0]); + if (is_samp) + { + cell->m_val[idx + 2].val = Float8GetDatum(transvalues[2]); + } + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + if (is_samp) + { + SET_NOTNULL(cell->m_val[idx + 2].flag); + } + else + { + SET_NULL(cell->m_val[idx + 2].flag); + } + } + else + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + + if (isTransition) + { + result = float8pl(&finfo); + cell->m_val[idx].val = result; + cell->m_val[idx + 1].val++; //count++ + if (is_samp) + { + args[0] = cell->m_val[idx + 2].val; + args[1] = DirectFunctionCall2(float8mul, pVal[i], pVal[i]); + result = float8pl(&finfo); + cell->m_val[idx + 2].val = result; + } + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transvalues = check_float8_array(transarray, "float8_avg", 3); + + cell->m_val[idx].val = DirectFunctionCall2(float8pl,cell->m_val[idx].val, Float8GetDatum(transvalues[1])); + cell->m_val[idx + 1].val = DirectFunctionCall2(float8pl,cell->m_val[idx + 1].val,Float8GetDatum(transvalues[0])); + if (is_samp) + { + cell->m_val[idx + 2].val = DirectFunctionCall2(float8pl, cell->m_val[idx + 2].val, Float8GetDatum(transvalues[2])); + } + } + } + } + } + + return NULL; +} + +/* +* @Description: For each level of avg/stddev_samp, a trans operation is needed +* @in isTransition - is the first stage of avg/stddev_samp. +* @in is_samp- is avg or stddev_samp +* @return - ScalarVector +*/ +template +ScalarVector* +vfloat4_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector1 = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector1->m_vals; + uint8* flag = pVector1->m_flag; + int nrows = pVector1->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + ArrayType *transarray = NULL; + float8 *transvalues = NULL; + Datum pvalue; + + finfo.arg = &args[0]; + + for (i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if (cell && IS_NULL(flag[i]) == false) //only do when not null + { + if (IS_NULL(cell->m_val[idx].flag)) + { + if (isTransition) + { + pvalue = DirectFunctionCall1(ftod,pVal[i]); + cell->m_val[idx].val = pvalue; + cell->m_val[idx + 1].val = 1; //count set 1 + if (is_samp) + { + cell->m_val[idx + 2].val = DirectFunctionCall2(float8mul, pvalue, pvalue); + } + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transvalues = check_float8_array(transarray, "float8_avg", 3); + + cell->m_val[idx].val = Float8GetDatum(transvalues[1]); + cell->m_val[idx + 1].val = Float8GetDatum(transvalues[0]); + if (is_samp) + { + cell->m_val[idx + 2].val = Float8GetDatum(transvalues[2]); + } + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + if (is_samp) + { + SET_NOTNULL(cell->m_val[idx + 2].flag); + } + else + { + SET_NULL(cell->m_val[idx + 2].flag); + } + } + else + { + if (isTransition) + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + result = float84pl(&finfo); + cell->m_val[idx].val = result; + cell->m_val[idx + 1].val++; //count++ + if (is_samp) + { + args[0] = cell->m_val[idx + 2].val; + pvalue = DirectFunctionCall1(ftod,pVal[i]); + args[1] = DirectFunctionCall2(float8mul, pvalue, pvalue); + result = float8pl(&finfo); + cell->m_val[idx + 2].val = result; + } + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transvalues = check_float8_array(transarray, "float8_avg", 3); + + + cell->m_val[idx].val = DirectFunctionCall2(float8pl,cell->m_val[idx].val, Float8GetDatum(transvalues[1])); + cell->m_val[idx + 1].val = DirectFunctionCall2(float8pl,cell->m_val[idx + 1].val,Float8GetDatum(transvalues[0])); + if (is_samp) + { + cell->m_val[idx + 2].val = DirectFunctionCall2(float8pl,cell->m_val[idx + 2].val,Float8GetDatum(transvalues[2])); + } + } + } + } + } + + return NULL; +} + +template +ScalarVector* +vfloat_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + cell->m_val[idx].val = pVal[i]; + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + + result = floatFun(&finfo); + + cell->m_val[idx].val = result; + } + } + } + + return NULL; +} + +template +ScalarVector* +vfloat_sum(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + cell->m_val[idx].val = pVal[i]; + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + + result = floatFun(&finfo); + cell->m_val[idx].val = result; + } + } + } + + return NULL; +} + +template +ScalarVector* +vfloat4_mop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + int i; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = parg1[i]; + args[1] = parg2[i]; + + result = floatFun(&finfo); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = parg1[i]; + args[1] = parg2[i]; + + result = floatFun(&finfo); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = FLOAT4OID; + return PG_GETARG_VECTOR(3); +} + + +template +ScalarVector* +vfloat8_mop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + int i; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = parg1[i]; + args[1] = parg2[i]; + + result = floatFun(&finfo); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = parg1[i]; + args[1] = parg2[i]; + + result = floatFun(&finfo); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = FLOAT8OID; + return PG_GETARG_VECTOR(3); +} + +#endif + diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/int4.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/int4.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/int4.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/int4.inl 2020-12-12 17:06:43.053345535 +0800 @@ -0,0 +1,812 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * int4.inl + * template implementation of 32-bit integers. + * + * + * src/backend/vecexecutor/vecprimitive/int4.inl + * + *------------------------------------------------------------------------- + */ + +#ifndef INT4_INL +#define INT4_INL + +#include "catalog/pg_type.h" +#include +#include +#include "vecexecutor/vechashtable.h" +#include "utils/array.h" +#include "utils/biginteger.h" +#include "vectorsonic/vsonichashagg.h" + +#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0)) + +typedef struct vecInt8TransTypeData +{ + int64 count; + int64 sum; +} VecInt8TransTypeData; + +template +ScalarVector* +vint_sop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + uint8* pflag = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + int i; + + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = eval_simple_op((Datatype)parg1[i], (Datatype)parg2[i]); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = eval_simple_op((Datatype)parg1[i], (Datatype)parg2[i]); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = BOOLOID; + return PG_GETARG_VECTOR(3); +} + +/* + * vint_avg_final: For each level of avg, a final operation is needed. + * + * singlenode: is the last stage of avg. If so, output is numeric type, or array type. + */ +template +Datum +vint_avg_final(PG_FUNCTION_ARGS) +{ + hashCell* cell = (hashCell*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + ScalarValue* pvals = (ScalarValue*)PG_GETARG_DATUM(2); + uint8 *pflag = (uint8*)PG_GETARG_DATUM(3); + Datum args[2]; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + if(singlenode) + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + /* call int8_numeric_bi and numeric_div, the avg result can be big integer type */ + args[0] = DirectFunctionCall1(int8_numeric_bi, cell->m_val[idx].val); + args[1] = DirectFunctionCall1(int8_numeric_bi, cell->m_val[idx+1].val); + + *pvals = numeric_div(&finfo); + SET_NOTNULL(*pflag); + } + else + { + ArrayType *transarray = NULL; + VecInt8TransTypeData *transdata = NULL; + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + args[0] = cell->m_val[idx].val; + args[1] = cell->m_val[idx+1].val; + + transarray = construct_array(args, 2, INT8OID, sizeof(int64), true, 'd'); + + transdata = (VecInt8TransTypeData *) ARR_DATA_PTR(transarray); + transdata->count = args[1]; + transdata->sum = args[0]; + *pvals = PointerGetDatum(transarray); + SET_NOTNULL(*pflag); + } + + return (Datum) 0; +} + +/* + * @Description : avg(int)'s final function, support int4 and int2. + * + * @in m_data[idx] : value of sum(int) for each group. + * @in m_data[idx + 1]: number of sum(int) for each group. + * @out pVal : avg(int)'s result for nrows-th row. + */ +template +Datum +vsint_avg_final(PG_FUNCTION_ARGS) +{ + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(2); + int dataIdx = (int)PG_GETARG_DATUM(3); + + SonicDatumArray* data = sdata[idx]; + SonicDatumArray* count = sdata[idx + 1]; + + int nrows = pVector->m_rows; + uint8* pflag = &pVector->m_flag[nrows]; + ScalarValue* pvals = &pVector->m_vals[nrows]; + Datum args[2]; + Datum *leftdata = NULL; + Datum *countdata = NULL; + uint8 leftflag; + FunctionCallInfoData finfo; + int arrIndx, atomIndx; + + finfo.arg = &args[0]; + nrows = nrows + 1; + + /* the same index are used for data and m_count */ + arrIndx = getArrayIndx(dataIdx, data->m_nbit); + atomIndx = getArrayLoc(dataIdx, data->m_atomSize - 1); + + /* get sum (leftdata) amd count (countdata) */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + countdata = &((Datum *)count->m_arr[arrIndx]->data)[atomIndx]; + + if (singlenode) + { + if (IS_NULL(leftflag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + /* call int8_numeric_bi and numeric_div, the avg result can be big integer type */ + args[0] = DirectFunctionCall1(int8_numeric_bi, *leftdata); + args[1] = DirectFunctionCall1(int8_numeric_bi, *countdata); + + *pvals = numeric_div(&finfo); + SET_NOTNULL(*pflag); + } + else + { + ArrayType *transarray = NULL; + VecInt8TransTypeData *transdata = NULL; + if (IS_NULL(leftflag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + args[0] = *leftdata; + args[1] = *countdata; + + transarray = construct_array(args, 2, INT8OID, sizeof(int64), true, 'd'); + transdata = (VecInt8TransTypeData *) ARR_DATA_PTR(transarray); + transdata->count = args[1]; + transdata->sum = args[0]; + *pvals = PointerGetDatum(transarray); + SET_NOTNULL(*pflag); + } + + return (Datum) 0; +} + +/* + * vint_avg: For each level of avg, a final operation is needed. + * + * isTransition: is the first stage of avg. If so, input is simple type, or array type. + */ +template +ScalarVector* +vint_avg(PG_FUNCTION_ARGS) +{ + + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + ArrayType *transarray = NULL; + VecInt8TransTypeData *transdata = NULL; + + finfo.arg = &args[0]; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + { + if(int_size == 4) + cell->m_val[idx].val = (int64)DatumGetInt32(pVal[i]); + else if(int_size == 2) + cell->m_val[idx].val = (int64)DatumGetInt16(pVal[i]); + else if(int_size == 1) + cell->m_val[idx].val = (int64)DatumGetUInt8(pVal[i]); + + cell->m_val[idx + 1].val = 1; //count set 1 + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transdata = (VecInt8TransTypeData *) ARR_DATA_PTR(transarray); + cell->m_val[idx].val = transdata->sum; + cell->m_val[idx + 1].val = transdata->count; + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + SET_NULL(cell->m_val[idx + 2].flag); + } + else + { + + if(isTransition) + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + + if(int_size == 4) + result = int84pl(&finfo); + else if(int_size == 2) + result = int82pl(&finfo); + else if(int_size == 1) + { + args[1] = Int64GetDatum((int64)DatumGetUInt8(pVal[i])); + result = int8pl(&finfo); + } + + cell->m_val[idx].val = result; + cell->m_val[idx + 1].val++; //count++ + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transdata = (VecInt8TransTypeData *) ARR_DATA_PTR(transarray); + + cell->m_val[idx].val = DirectFunctionCall2(int8pl,cell->m_val[idx].val, Int64GetDatum(transdata->sum)); + cell->m_val[idx+1].val += transdata->count; + } + } + } + } + + return NULL; +} + +/* + * @Description : avg(int)'s transition function, support int2 and int4. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of sum(int) for each group. + * @out m_data[idx + 1] : number of sum(int) for each group. + */ +template +ScalarVector* +vsint_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicDatumArray* data = sdata[idx]; + SonicDatumArray* count = sdata[idx + 1]; + + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + int arrIndx, atomIndx; + + Datum args[2]; + Datum *leftdata = NULL; + Datum *countdata = NULL; + uint8 leftflag; + int i; + + ArrayType *transarray = NULL; + VecInt8TransTypeData *transdata = NULL; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + for (i = 0; i < nrows; i++) + { + if (loc[i] != 0 && NOT_NULL(flag[i])) + { + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + /* previous sum result(leftdata) */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + /* previous count result(countdata) */ + countdata = &((Datum *)count->m_arr[arrIndx]->data)[atomIndx]; + + if (IS_NULL(leftflag)) + { + /* store the first data pVal[i] in data and count */ + if (isTransition) + { + /* convert to int64 and then convert to uint64 */ + if (int_size == 4) + *leftdata = (int64)DatumGetInt32(pVal[i]); + else if (int_size == 2) + *leftdata = (int64)DatumGetInt16(pVal[i]); + else if (int_size == 1) + *leftdata = (int64)DatumGetUInt8(pVal[i]); + data->setNthNullFlag(arrIndx, atomIndx, false); + + *countdata = 1; + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transdata = (VecInt8TransTypeData *) ARR_DATA_PTR(transarray); + + *leftdata = transdata->sum; + data->setNthNullFlag(arrIndx, atomIndx, false); + + *countdata = transdata->count; + } + } + else + { + /* updata previous sum result based on the given pVal[i] */ + if (isTransition) + { + args[0] = *leftdata; + args[1] = pVal[i]; + + if (int_size == 4) + *leftdata = int84pl(&finfo); + else if (int_size == 2) + *leftdata = int82pl(&finfo); + else if (int_size == 1) + { + args[1] = Int64GetDatum((int64)DatumGetUInt8(pVal[i])); + *leftdata = int8pl(&finfo); + } + (*countdata)++; + } + else + { + transarray = DatumGetArrayTypeP(pVal[i]); + transdata = (VecInt8TransTypeData *)ARR_DATA_PTR(transarray); + + *leftdata = DirectFunctionCall2(int8pl, *leftdata, Int64GetDatum(transdata->sum)); + *countdata += transdata->count; + } + } + } + } + return NULL; +} + +template +ScalarVector* +vint_sum(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + { + if(isInt32) + cell->m_val[idx].val = (int64)DatumGetInt32(pVal[i]); + else + cell->m_val[idx].val = (int64)DatumGetInt16(pVal[i]); + } + else + cell->m_val[idx].val = pVal[i]; + + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + if(isTransition) + { + if(isInt32) + result = DirectFunctionCall2(int84pl,args[0],args[1]); + else + result = DirectFunctionCall2(int82pl,args[0],args[1]); + } + else + result = DirectFunctionCall2(int8pl,args[0],args[1]); + + cell->m_val[idx].val = result; + } + } + } + return NULL; +} + +/* + * @Description : sum(int)'s agg function, support int2 and int4. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of sum(int) for each group. + */ +template +ScalarVector* +vsint_sum(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicDatumArray* data = sdata[idx]; + + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + + Datum *leftdata = NULL; + uint8 leftflag; + int i; + int arrIndx, atomIndx; + + for(i = 0 ; i < nrows; i++) + { + if (loc[i] != 0 && NOT_NULL(flag[i])) + { + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + /* get sum (leftdata) */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + if (IS_NULL(leftflag)) + { + /* store the first data pVal[i] in data */ + if (isTransition) + { + if (isInt32) + *leftdata = DatumGetInt32(pVal[i]); + else + *leftdata = DatumGetInt16(pVal[i]); + } + else + *leftdata = pVal[i]; + + data->setNthNullFlag(arrIndx, atomIndx, false); + } + else + { + /* updata previous sum result based on the given pVal[i] */ + args[0] = *leftdata; + args[1] = pVal[i]; + if (isTransition) + { + if (isInt32) + *leftdata = DirectFunctionCall2(int84pl, args[0], args[1]); + else + *leftdata = DirectFunctionCall2(int82pl, args[0], args[1]); + } + else + *leftdata = DirectFunctionCall2(int8pl, args[0], args[1]); + } + } + } + return NULL; +} + +template +ScalarVector* +vtimetz_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + cell->m_val[idx].val = addVariable(context, pVal[i]); + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args[0] = PointerGetDatum((char*)ScalarVector::Decode(cell->m_val[idx].val) + VARHDRSZ_SHORT); + args[1] = PointerGetDatum((char*)ScalarVector::Decode(pVal[i]) + VARHDRSZ_SHORT); + result = timetzFun(&finfo); + if(result != args[0]) + { + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, pVal[i]); + } + } + } + } + + return NULL; +} + +/* + * vinterval_avg: For each level of avg, a final operation is needed. + * + * isTransition: is the first stage of avg. If so, input is interval type, or array type. + */ +template +ScalarVector* +vinterval_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + Datum sum; + Datum *transdatums = NULL; + int ndatums; + Interval *N = NULL; + + finfo.arg = &args[0]; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + { + cell->m_val[idx].val = addVariable(context, pVal[i]); + cell->m_val[idx + 1].val = 1; //count set 1 + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + INTERVALOID, sizeof(Interval), false, 'd', + &transdatums, NULL, &ndatums); + + N = DatumGetIntervalP(transdatums[1]); + + cell->m_val[idx].val = addVariable(context, ScalarVector::DatumToScalar(transdatums[0],INTERVALOID,false)); + + cell->m_val[idx + 1].val = N->time; + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + SET_NULL(cell->m_val[idx + 2].flag); + } + else + { + args[0] = PointerGetDatum((char*)cell->m_val[idx].val + VARHDRSZ_SHORT); + args[1] = PointerGetDatum((char*)pVal[i] + VARHDRSZ_SHORT); + + if(isTransition) + { + result = interval_pl(&finfo); + ScalarValue val = ScalarVector::DatumToScalar(result,INTERVALOID,false); + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, val); + cell->m_val[idx + 1].val++; //count++ + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + INTERVALOID, sizeof(Interval), false, 'd', + &transdatums, NULL, &ndatums); + + N = DatumGetIntervalP(transdatums[1]); + + sum = DirectFunctionCall2(interval_pl, transdatums[0], args[0]); + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, ScalarVector::DatumToScalar(sum,INTERVALOID,false)); + + cell->m_val[idx + 1].val += N->time; + } + } + } + } + return NULL; +} + +/* + * vinterval_avg_final: For each level of avg, a final operation is needed. + * + * singlenode: is the last stage of avg. If so, output is interval type, or array type. + */ +template +Datum +vinterval_avg_final(PG_FUNCTION_ARGS) +{ + hashCell* cell = (hashCell*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + ScalarValue* m_vals = (ScalarValue*)PG_GETARG_DATUM(2); + uint8 *m_flag = (uint8*)PG_GETARG_DATUM(3); + + Datum args[2]; + FunctionCallInfoData finfo; + Datum transdatums[2]; + Interval N; + + finfo.arg = &args[0]; + if(singlenode) + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[0] = PointerGetDatum((char*)cell->m_val[idx].val + VARHDRSZ_SHORT); + args[1] = DirectFunctionCall1(i8tod,cell->m_val[idx+1].val); + + *m_vals = ScalarVector::DatumToScalar(interval_div(&finfo),INTERVALOID,false); + SET_NOTNULL(*m_flag); + } + else + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[0] = cell->m_val[idx].val; + args[1] = cell->m_val[idx+1].val; + + N.time = args[1]; + + transdatums[0] = PointerGetDatum((char*)args[0] + VARHDRSZ_SHORT); + transdatums[1] = IntervalPGetDatum(&N); + + *m_vals = PointerGetDatum(construct_array(transdatums, 2, INTERVALOID, sizeof(Interval), false, 'd')); + SET_NOTNULL(*m_flag); + } + + return (Datum) 0; +} + +template +ScalarVector* +vctid_sop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + uint8* pflag = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + Oid typeId1 = PG_GETARG_VECTOR(0)->m_desc.typeId; + Oid typeId2 = PG_GETARG_VECTOR(1)->m_desc.typeId; + int i; + Datum args[2]; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = typeId1 == TIDOID?parg1[i]:PointerGetDatum(parg1+i); + args[1] = typeId2 == TIDOID?parg2[i]:PointerGetDatum(parg2+i); + + presult[i] = ctidFun(&finfo); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + args[0] = typeId1 == TIDOID?parg1[i]:PointerGetDatum(parg1+i); + args[1] = typeId2 == TIDOID?parg2[i]:PointerGetDatum(parg2+i); + + presult[i] = ctidFun(&finfo); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = BOOLOID; + return PG_GETARG_VECTOR(3); +} + +#endif diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/int8.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/int8.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/int8.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/int8.inl 2020-12-12 17:06:43.053345535 +0800 @@ -0,0 +1,973 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * int8.inl + * template implementation of 64-bit integers. + * + * + * src/backend/vecexecutor/vecprimitive/int8.inl + * + *------------------------------------------------------------------------- + */ + +#ifndef INT8_INL +#define INT8_INL + +#include "utils/int8.h" +#include "utils/biginteger.h" +#include "catalog/pg_type.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vechashagg.h" +#include "vectorsonic/vsonichashagg.h" +#include "vectorsonic/vsonicarray.h" + +#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0)) + +template +ScalarVector* +vint8_sop(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + uint8* pflag = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + int i; + + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = eval_simple_op((Datatype1)parg1[i], (Datatype2)parg2[i]); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + presult[i] = eval_simple_op((Datatype1)parg1[i], (Datatype2)parg2[i]); + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = BOOLOID; + return PG_GETARG_VECTOR(3); +} + +template +ScalarVector* +vint_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + cell->m_val[idx].val = pVal[i]; + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args[0] = cell->m_val[idx].val; + args[1] = pVal[i]; + + if (sop == SOP_GT) + result = (((datatype)args[0] > (datatype)args[1]) ? args[0] : args[1]); + else + result = (((datatype)args[0] < (datatype)args[1]) ? args[0] : args[1]); + + cell->m_val[idx].val = result; + } + } + } + + return NULL; +} + +/* + * @Description : min or max(int)'s agg function that supprot int2, int4, int8. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of min or max(int) for each group. + */ +template +ScalarVector* +vsint_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*) sdata[idx]; + + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + datatype* leftdata = NULL; + uint8 leftflag; + int arrIndx, atomIndx; + + for (i = 0 ; i < nrows; i++) + { + /* only do when not null */ + if (loc[i] != 0 && NOT_NULL(flag[i])) + { + /* previous result(leftdata) */ + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + leftdata = &((datatype *)data->m_arr[arrIndx]->data)[atomIndx]; + + if (IS_NULL(leftflag)) + { + *leftdata = pVal[i]; + data->setNthNullFlag(arrIndx, atomIndx, false); + } + else + { + if (sop == SOP_GT) + *leftdata = (((datatype)leftdata[0] > (datatype)pVal[i]) ? leftdata[0] : pVal[i]); + else + *leftdata = (((datatype)leftdata[0] < (datatype)pVal[i]) ? leftdata[0] : pVal[i]); + } + } + } + + return NULL; +} + +template +ScalarVector* +vint8_avg(PG_FUNCTION_ARGS) +{ + + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + + hashCell* cell = NULL; + int arg1, arg2, i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum *datumarray = NULL; + int ndatum; + bictl ctl; + Numeric leftarg, rightarg; // left-hand and right-hand operand of addition + ctl.context = context; + + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(NOT_NULL(cell->m_val[idx].flag)) + { + if (isTransition) + { + /* leftarg is bi64 or bi128 */ + leftarg = (Numeric)(cell->m_val[idx].val); + /* rightarg is bi64 */ + rightarg = (Numeric)(makeNumeric64(pVal[i], 0)); + ctl.store_pos = cell->m_val[idx].val; + arg1 = NUMERIC_IS_BI128(leftarg); + /* call big integer fast add function: bi128 add bi64 */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][0])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + cell->m_val[idx].val = ctl.store_pos; + cell->m_val[idx + 1].val++; //count++ + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + /* leftarg is bi64 or bi128 */ + leftarg = (Numeric)(cell->m_val[idx].val); + /* rightarg is bi64 or bi128 */ + rightarg = (Numeric)(datumarray[1]); + ctl.store_pos = cell->m_val[idx].val; + arg1 = NUMERIC_IS_BI128(leftarg); + arg2 = NUMERIC_IS_BI128(rightarg); + /* call big integer fast add function: bi128 add bi128 */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + cell->m_val[idx].val = ctl.store_pos; + + /* calculate count: count = oldcount + count */ + /* the count num can be stored by int64, call bi64add64 directly */ + ctl.store_pos = cell->m_val[idx + 1].val; + BiAggFunMatrix[BI_AGG_ADD][0][0]((Numeric)(ctl.store_pos), (Numeric)(datumarray[0]), &ctl); + } + } + else + { + if(isTransition) + { + /* store the first value to bi64 */ + cell->m_val[idx].val = addVariable(context, makeNumeric64(pVal[i], 0)); + cell->m_val[idx + 1].val = 1; //count set 1 + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + cell->m_val[idx].val = addVariable(context, datumarray[1]); + cell->m_val[idx + 1].val = addVariable(context, datumarray[0]); + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + SET_NULL(cell->m_val[idx + 2].flag); + } + } + } + return NULL; +} + +/* + * @Description : avg(int8)'s transition function. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of sum(int) for each group. + * @out m_data[idx + 1] : number of sum(int8) for each group. + */ +template +ScalarVector* +vsint8_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*)sdata[idx]; + + SonicDatumArray* count = sdata[idx + 1]; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + + /* left-hand and right-hand operand of addition */ + Datum args[2]; + Datum *leftdata = NULL; + Datum *countdata = NULL; + uint8 leftflag; + /* left-hand and right-hand operand of addition */ + Numeric leftarg, rightarg; + int arg1, arg2, i; + Datum *datumarray = NULL; + int arrIndx,atomIndx; + int ndatum; + + FunctionCallInfoData finfo; + bictl ctl; + finfo.arg = &args[0]; + ctl.context = data->m_cxt; + + for (i = 0 ; i < nrows; i++) + { + /* only do when not null */ + if (loc[i] != 0 && NOT_NULL(flag[i])) + { + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + /* get previous datum flag */ + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + /* previous count result(leftdata) */ + countdata = &((Datum *)count->m_arr[arrIndx]->data)[atomIndx]; + + if (NOT_NULL(leftflag)) + { + /* get data value */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + + /* updata previous sum result based on the given pVal[i] */ + if (isTransition) + { + /* leftarg is bi64 or bi128 */ + leftarg = (Numeric)(leftdata[0]); + /* rightarg is bi64 */ + rightarg = (Numeric)(makeNumeric64(pVal[i], 0)); + ctl.store_pos = leftdata[0]; + arg1 = NUMERIC_IS_BI128(leftarg); + /* call big integer fast add function: bi128 add bi64 */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][0])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + leftdata[0] = ctl.store_pos; + countdata[0]++; + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + /* leftarg is bi64 or bi128 */ + leftarg = (Numeric)(leftdata[0]); + /* rightarg is bi64 or bi128 */ + rightarg = (Numeric)(datumarray[1]); + ctl.store_pos = leftdata[0]; + arg1 = NUMERIC_IS_BI128(leftarg); + arg2 = NUMERIC_IS_BI128(rightarg); + /* call big integer fast add function: bi128 add bi128 */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + leftdata[0] = ctl.store_pos; + + /* calculate count: count = oldcount + count */ + *countdata = *countdata + NUMERIC_64VALUE((Numeric)datumarray[0]); + } + } + else + { + /* store the first data pVal[i] in data and m_count */ + if (isTransition) + { + /* store the first value to bi64 */ + data->setValue(makeNumeric64(pVal[i], 0), false, arrIndx, atomIndx); + countdata[0] = 1; + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + data->setValue(datumarray[1], false, arrIndx, atomIndx); + *countdata = NUMERIC_64VALUE((Numeric)datumarray[0]); + } + } + } + } + return NULL; +} + +template +ScalarVector* +vector_abs(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + int32 nvalues = PG_GETARG_INT32(1); + ScalarValue* presult = PG_GETARG_VECVAL(2); + bool* pselection = PG_GETARG_SELECTION(3); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(2)->m_flag); + int i; + Datum args; + FunctionCallInfoData finfo; + + finfo.arg = &args; + + if (likely(pselection == NULL)) + { + for (i = 0 ; i < nvalues; i++) + { + if (NOT_NULL(pflags1[i])) + { + args = parg1[i]; + presult[i] = absfun(&finfo); + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0 ; i < nvalues; i++) + { + if(pselection[i]) + { + if (NOT_NULL(pflags1[i])) + { + args = parg1[i]; + presult[i] = absfun(&finfo); + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + PG_GETARG_VECTOR(2)->m_rows = nvalues; + + return PG_GETARG_VECTOR(2); + +} + +template +ScalarVector* +vint8mul(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + uint32 mask = 0; + int i; + Datatype1 arg1; + Datatype2 arg2; + int64 result; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 * arg2; + mask |= (arg1 != (int64) ((int32) arg1) || arg2 != (int64) ((int32) arg2)) + && (arg2 != 0 && + (result / arg2 != arg1 || (arg2 == -1 && arg1 < 0 && result < 0))); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 * arg2; + mask |= (unsigned int)((arg1 != (int64) ((int32) arg1) || arg2 != (int64) ((int32) arg2)) + && (arg2 != 0 && + (result / arg2 != arg1 || (arg2 == -1 && arg1 < 0 && result < 0)))); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + if (mask != 0) + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("bigint out of range"))); + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = INT8OID; + return PG_GETARG_VECTOR(3); +} + +template +ScalarVector* +vint8mi(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + uint32 mask = 0; + int i; + Datatype1 arg1; + Datatype2 arg2; + int64 result; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 - arg2; + mask |= !SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 - arg2; + mask |= (unsigned int)(!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1)); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + if (mask != 0) + { + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("bigint out of range"))); + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = INT8OID; + return PG_GETARG_VECTOR(3); +} + +template +ScalarVector* +vint8pl(PG_FUNCTION_ARGS) +{ + ScalarValue* parg1 = PG_GETARG_VECVAL(0); + ScalarValue* parg2 = PG_GETARG_VECVAL(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue* presult = PG_GETARG_VECVAL(3); + bool* pselection = PG_GETARG_SELECTION(4); + uint8* pflags1 = (uint8*)(PG_GETARG_VECTOR(0)->m_flag); + uint8* pflags2 = (uint8*)(PG_GETARG_VECTOR(1)->m_flag); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + uint32 mask = 0; + int i; + Datatype1 arg1; + Datatype2 arg2; + int64 result; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 + arg2; + mask |= SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + arg1 = (Datatype1)parg1[i]; + arg2 = (Datatype2)parg2[i]; + + result = arg1 + arg2; + mask |= (unsigned int)(SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1)); + presult[i] = result; + SET_NOTNULL(pflagsRes[i]); + } + else + SET_NULL(pflagsRes[i]); + } + } + } + + + if (mask != 0) + { + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("bigint out of range"))); + } + + PG_GETARG_VECTOR(3)->m_rows = nvalues; + PG_GETARG_VECTOR(3)->m_desc.typeId = INT8OID; + return PG_GETARG_VECTOR(3); +} + +/* +* @Description: calculate agg funtion stddev_sam's trans value for int2/int4/int8/numeric +* @in type_size - for diffent data type +* @in isTransition - is the trans value +* @return - ScalarVector +*/ +template +ScalarVector* +vint_stddev_samp(PG_FUNCTION_ARGS) +{ + + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result[2]; + Datum bi_result; + Datum *datumarray = NULL; + int ndatum; + Datum newval; + FunctionCallInfoData finfo; + + bictl ctl; + Numeric leftarg, rightarg; /* left-hand and right-hand operand of addition */ + uint16 num1Flags, num2Flags; /* numeric flags of num1 and num2 */ + int arg1, arg2; + + finfo.arg = &args[0]; + ctl.context = context; + + for (i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if (cell && IS_NULL(flag[i]) == false) //only do when not null + { + if (IS_NULL(cell->m_val[idx].flag)) + { + if (isTransition) + { + if (type_size == 4) + { + newval = DirectFunctionCall1(int4_numeric_bi, pVal[i]); + } + else if (type_size == 8) + { + newval = DirectFunctionCall1(int8_numeric_bi, pVal[i]); + } + else if (type_size == 2) + { + newval = DirectFunctionCall1(int2_numeric_bi, pVal[i]); + } + else + { + newval = pVal[i]; + } + + leftarg = DatumGetBINumeric(newval); + + cell->m_val[idx].val = addVariable(context, NumericGetDatum(leftarg)); + cell->m_val[idx + 1].val = 1; /* first time set count to 1 */ + cell->m_val[idx + 2].val = addVariable(context, DirectFunctionCall2(numeric_mul, newval, newval)); + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + cell->m_val[idx].val = addVariable(context, datumarray[1]); + cell->m_val[idx + 1].val = addVariable(context, datumarray[0]); + cell->m_val[idx + 2].val = addVariable(context, datumarray[2]); + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + SET_NOTNULL(cell->m_val[idx + 2].flag); + } + else + { + if (isTransition) + { + args[0] = cell->m_val[idx].val; + + if (type_size == 4) + { + newval = DirectFunctionCall1(int4_numeric_bi, pVal[i]); + } + else if (type_size == 2) + { + newval = DirectFunctionCall1(int2_numeric_bi, pVal[i]); + } + else if (type_size == 8) + { + newval = DirectFunctionCall1(int8_numeric_bi, pVal[i]); + } + else + { + newval = pVal[i]; + } + + args[1] = newval; + + leftarg = (Numeric)(args[0]); + rightarg = DatumGetBINumeric(newval); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx].val; + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address. */ + cell->m_val[idx].val = ctl.store_pos; + } + else /* call numeric_add */ + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + + result[0] = DirectFunctionCall2(numeric_add, args[0], args[1]); + cell->m_val[idx].val = addVariable(context, result[0]); + } + + leftarg = (Numeric)(cell->m_val[idx + 2].val); + rightarg = DatumGetBINumeric(DirectFunctionCall2(numeric_mul, newval, newval)); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx + 2].val; + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address. */ + cell->m_val[idx + 2].val = ctl.store_pos; + } + else /* call numeric_add */ + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + + result[1] = DirectFunctionCall2(numeric_add, cell->m_val[idx + 2].val, DirectFunctionCall2(numeric_mul, newval, newval)); + cell->m_val[idx + 2].val = addVariable(context, result[1]); + } + + cell->m_val[idx + 1].val++; + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + /* calculate sum: sum = sum + num */ + leftarg = (Numeric)(cell->m_val[idx].val); + rightarg = DatumGetBINumeric(datumarray[1]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx].val; + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address. */ + cell->m_val[idx].val = ctl.store_pos; + } + else /* call numeric_add */ + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + bi_result = numeric_add(&finfo); + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, bi_result); + } + + leftarg = (Numeric)(cell->m_val[idx + 2].val); + rightarg = DatumGetBINumeric(datumarray[2]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx + 2].val; + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address. */ + cell->m_val[idx + 2].val = ctl.store_pos; + } + else /* call numeric_add */ + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + bi_result = numeric_add(&finfo); + cell->m_val[idx + 2].val = replaceVariable(context, cell->m_val[idx + 2].val, bi_result); + } + + /* + * calculate count: count = oldcount + count + * the count num can be stored by int64, call bi64add64 directly. + */ + ctl.store_pos = cell->m_val[idx + 1].val; + BiAggFunMatrix[BI_AGG_ADD][0][0]((Numeric)(ctl.store_pos), (Numeric)(datumarray[0]), &ctl); + } + } + } + } + + return NULL; +} + + +/* +* @Description: calculate agg funtion stddev_sam's trans value for int2/int4/int8/numeric +* @in isTransition - is the trans value +* @in singlenode - only in datanode +* @return - ScalarVector +*/ +template +Datum +vnumeric_stddev_samp_final(PG_FUNCTION_ARGS) +{ + hashCell* cell = (hashCell*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + ScalarValue* m_vals = (ScalarValue*)PG_GETARG_DATUM(2); + uint8 *m_flag = (uint8*)PG_GETARG_DATUM(3); + + Datum args; + Datum arg[3]; + FunctionCallInfoData finfo; + + finfo.arg = &args; + Numeric tmp_arg; + + if (singlenode) + { + if (IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + if (isTransition) + { + tmp_arg = DatumGetNumeric(DirectFunctionCall1(int8_numeric, cell->m_val[idx + 1].val)); + } + else + { + tmp_arg = bitonumeric(cell->m_val[idx + 1].val); + } + + arg[0] = NumericGetDatum(tmp_arg); + arg[1] = NumericGetDatum(bitonumeric(cell->m_val[idx].val)); + arg[2] = NumericGetDatum(bitonumeric(cell->m_val[idx + 2].val)); + + args = PointerGetDatum(construct_array(arg, 3, NUMERICOID, -1, false, 'i')); + + finfo.isnull = false; + *m_vals = numeric_stddev_samp(&finfo); + if (finfo.isnull) + { + SET_NULL(*m_flag); + } + else + { + SET_NOTNULL(*m_flag); + } + } + else + { + if (IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + arg[1] = cell->m_val[idx].val; + arg[2] = cell->m_val[idx + 2].val; + + if (isTransition) + { + arg[0] = makeNumeric64(cell->m_val[idx + 1].val, 0); + } + else + { + arg[0] = cell->m_val[idx + 1].val; + } + + *m_vals = PointerGetDatum(construct_array(arg, 3, NUMERICOID, -1, false, 'i')); + SET_NOTNULL(*m_flag); + } + + return (Datum) 0; +} + +#endif diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl 2020-12-12 17:06:43.053345535 +0800 @@ -0,0 +1,954 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * numeric.inl + * + * Created on: Jul 30, 2014 + * Author: zanky + */ + +#ifndef NUMERIC_INL_ +#define NUMERIC_INL_ + +#include +#include "catalog/pg_type.h" +#include "utils/array.h" +#include "utils/biginteger.h" +#include "utils/numeric.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vechashagg.h" +#include "vectorsonic/vsonichashagg.h" +#include "vectorsonic/vsonicarray.h" + +/* + * vnumeric_avg_final: For each level of avg, a final operation is needed. + * + * isTransition: is the first stage of avg. If so, input is int8 type, or array type. + * singlenode: is the last stage of avg. If so, output is numeric type, or array type. + */ +template +Datum +vnumeric_avg_final(PG_FUNCTION_ARGS) +{ + hashCell* cell = (hashCell*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + ScalarValue* m_vals = (ScalarValue*)PG_GETARG_DATUM(2); + uint8 *m_flag = (uint8*)PG_GETARG_DATUM(3); + + Datum args[2]; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + if(singlenode) + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[0] = cell->m_val[idx].val; + if (isTransition) + args[1] = makeNumeric64(cell->m_val[idx + 1].val, 0); + else + args[1] = cell->m_val[idx+1].val; + + *m_vals = numeric_div(&finfo); + SET_NOTNULL(*m_flag); + } + else + { + if(IS_NULL(cell->m_val[idx].flag)) + { + SET_NULL(*m_flag); + return (Datum) 0; + } + + args[1] = cell->m_val[idx].val; + if (isTransition) + args[0] = makeNumeric64(cell->m_val[idx + 1].val, 0); + else + args[0] = cell->m_val[idx+1].val; + *m_vals = PointerGetDatum(construct_array(args, 2, NUMERICOID, -1, false, 'i')); + SET_NOTNULL(*m_flag); + } + + return (Datum) 0; +} + +template +ScalarVector* +vnumeric_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + + hashCell* cell = NULL; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + Datum *datumarray = NULL; + int ndatum; + bictl ctl; + Numeric leftarg, rightarg; // left-hand and right-hand operand of addition + uint16 num1Flags, num2Flags; // numeric flags of num1 and num2 + int arg1, arg2, i; + + finfo.arg = &args[0]; + ctl.context = context; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && NOT_NULL(flag[i])) //only do when not null + { + if(NOT_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + { + leftarg = (Numeric)(cell->m_val[idx].val); + rightarg = DatumGetBINumeric(pVal[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx].val; + // call big integer fast add function + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + // ctl.store_pos may be pointed to new address. + cell->m_val[idx].val = ctl.store_pos; + } + else // call numeric_add + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numeric_add(&finfo); + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, result); + } + cell->m_val[idx + 1].val++; //count++ + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + // calculate sum: sum = sum + num + leftarg = (Numeric)(cell->m_val[idx].val); + rightarg = DatumGetBINumeric(datumarray[1]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + if(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx].val; + // call big integer fast add function + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + // ctl.store_pos may be pointed to new address. + cell->m_val[idx].val = ctl.store_pos; + } + else // call numeric_add + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numeric_add(&finfo); + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, result); + } + + // calculate count: count = oldcount + count + // the count num can be stored by int64, call bi64add64 directly. + ctl.store_pos = cell->m_val[idx + 1].val; + BiAggFunMatrix[BI_AGG_ADD][0][0]((Numeric)(ctl.store_pos), (Numeric)(datumarray[0]), &ctl); + } + } + else + { + if(isTransition) + { + leftarg = DatumGetBINumeric(pVal[i]); + cell->m_val[idx].val = addVariable(context, NumericGetDatum(leftarg)); + cell->m_val[idx + 1].val = 1; //count set 1 + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + cell->m_val[idx].val = addVariable(context, datumarray[1]); + cell->m_val[idx + 1].val = addVariable(context, datumarray[0]); + } + + SET_NOTNULL(cell->m_val[idx].flag); + SET_NOTNULL(cell->m_val[idx + 1].flag); + SET_NULL(cell->m_val[idx + 2].flag); + } + } + } + + return NULL; +} + +/* + * @Description : avg(numeric)'s final function. + * + * @in m_data[idx] : value of sum(numeric) for each group. + * @in m_data[idx + 1]: number of sum(numeric) for each group. + * @out pVal : avg(numeric)'s result for nrows-th row. + */ +template +Datum +vsnumeric_avg_final(PG_FUNCTION_ARGS) +{ + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(2); + uint32 dataIdx = (uint32)PG_GETARG_DATUM(3); + + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*)sdata[idx]; + SonicDatumArray* scount = sdata[idx + 1]; + int nrows = pVector->m_rows; + uint8* pflag = &pVector->m_flag[nrows]; + ScalarValue* pvals = &pVector->m_vals[nrows]; + Datum args[2]; + Datum *countdata = NULL; + Datum *leftdata = NULL; + + uint8 leftflag; + int arrIndx,atomIndx; + + FunctionCallInfoData finfo; + finfo.arg = &args[0]; + nrows = nrows + 1; + + arrIndx = getArrayIndx(dataIdx, data->m_nbit); + atomIndx = getArrayLoc(dataIdx, data->m_atomSize - 1); + + /* sum result(leftdata) */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + /* count result(leftdata) */ + countdata = &((Datum *)scount->m_arr[arrIndx]->data)[atomIndx]; + + if (singlenode) + { + if (IS_NULL(leftflag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + args[0] = *leftdata; + args[1] = makeNumeric64(*countdata, 0); + + /* avg result(m_vals) */ + *pvals = numeric_div(&finfo); + SET_NOTNULL(*pflag); + } + else + { + if (IS_NULL(leftflag)) + { + SET_NULL(*pflag); + return (Datum) 0; + } + + args[1] = *leftdata; + args[0] = makeNumeric64(*countdata, 0); + + *pvals = PointerGetDatum(construct_array(args, 2, NUMERICOID, -1, false, 'i')); + SET_NOTNULL(*pflag); + } + return (Datum) 0; +} + +/* + * @Description : avg(numeric)'s transition function. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of sum(numeric) for each group. + * @out m_data[idx + 1] : number of sum(numeric) for each group. + */ +template +ScalarVector* +vsnumeric_avg(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*)sdata[idx]; + SonicDatumArray* scount = sdata[idx + 1]; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + Datum *leftdata = NULL; + Datum *countdata = NULL; + uint8 leftflag; + FunctionCallInfoData finfo; + bictl ctl; + /* left-hand and right-hand operand of addition */ + Numeric leftarg, rightarg; + /* numeric flags of num1 and num2 */ + uint16 num1Flags, num2Flags; + int arg1, arg2, i; + Datum *datumarray = NULL; + int ndatum; + int arrIndx, atomIndx; + + finfo.arg = &args[0]; + ctl.context = data->m_cxt; + + for(i = 0 ; i < nrows; i++) + { + if ((loc[i] != 0) && NOT_NULL(flag[i])) + { + /* previous sum result(leftdata) */ + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + /* first get data flag */ + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + /* previous count result(leftdata) */ + countdata = &((Datum *)scount->m_arr[arrIndx]->data)[atomIndx]; + + if (NOT_NULL(leftflag)) + { + /* get data value */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + + /* updata previous sum and count result based on the given pVal[i] */ + if (isTransition) + { + leftarg = (Numeric)(leftdata[0]); + rightarg = DatumGetBINumeric(pVal[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = leftdata[0]; + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + leftdata[0] = ctl.store_pos; + } + else + { + /* call numeric_add */ + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numeric_add(&finfo); + leftdata[0] = data -> replaceVariable(leftdata[0], result); + } + /* add count */ + countdata[0]++; + } + else + { + /* We assume the input is array of numeric */ + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + /* calculate sum: sum = sum + num */ + leftarg = (Numeric)(leftdata[0]); + rightarg = DatumGetBINumeric(datumarray[1]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + if (NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags)) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + /* call big integer fast add function */ + ctl.store_pos = leftdata[0]; + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + leftdata[0] = ctl.store_pos; + } + else + { + /* call numeric_add */ + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numeric_add(&finfo); + leftdata[0] = data -> replaceVariable(leftdata[0], result); + } + + /* calculate count: count = oldcount + count */ + *countdata = *countdata + NUMERIC_64VALUE((Numeric)datumarray[0]); + } + } + else + { + /* store the first data pVal[i] in data and m_count */ + if (isTransition) + { + leftarg = DatumGetBINumeric(pVal[i]); + data->setValue(NumericGetDatum(leftarg), false, arrIndx, atomIndx); + *countdata = 1; + } + else + { + deconstruct_array(DatumGetArrayTypeP(pVal[i]), + NUMERICOID, -1, false, 'i', + &datumarray, NULL, &ndatum); + + data->setValue(datumarray[1], false, arrIndx, atomIndx); + *countdata = NUMERIC_64VALUE((Numeric)datumarray[0]); + } + } + } + } + + return NULL; +} + + +template +ScalarVector* +vnumeric_op(PG_FUNCTION_ARGS) +{ + ScalarValue *parg1 = PG_GETARG_VECVAL(0); + ScalarValue *parg2 = PG_GETARG_VECVAL(1); + ScalarVector* pvector1 = PG_GETARG_VECTOR(0); + ScalarVector* pvector2 = PG_GETARG_VECTOR(1); + uint8* flag1 = pvector1->m_flag; + uint8* flag2 = pvector2->m_flag; + + int32 nvalues = PG_GETARG_INT32(2); + ScalarValue *presult = PG_GETARG_VECVAL(3); + ScalarVector* presultVector = PG_GETARG_VECTOR(3); + uint8* pflagsRes = (uint8*)(PG_GETARG_VECTOR(3)->m_flag); + bool *pselection = PG_GETARG_SELECTION(4); + int arg1, arg2, i; + Numeric leftarg, rightarg; // left-hand and right-hand operand of addition + uint16 num1Flags, num2Flags; // numeric flags of num1 and num2 + Datum args[2]; + FunctionCallInfoData finfo; + finfo.arg = &args[0]; + + if(likely(pselection == NULL)) + { + for(i = 0 ; i < nvalues; i++) + { + if(BOTH_NOT_NULL(flag1[i], flag2[i])) + { + leftarg = DatumGetBINumeric(parg1[i]); + rightarg = DatumGetBINumeric(parg2[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if(likely(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags))) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + // call big integer fast calculate function + presult[i] = (BiFunMatrix[op][arg1][arg2])(leftarg, rightarg, NULL); + } + else // numeric_funcs + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + presult[i] = numericFun(&finfo); + } + SET_NOTNULL(pflagsRes[i]); + } + else + { + SET_NULL(pflagsRes[i]); + } + + } + } + else + { + for(i = 0 ; i < nvalues; i++) + { + if(pselection[i] == true) + { + if(BOTH_NOT_NULL(flag1[i], flag2[i])) + { + leftarg = DatumGetBINumeric(parg1[i]); + rightarg = DatumGetBINumeric(parg2[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + + if(likely(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags))) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + // call big integer fast calculate function + presult[i] = (BiFunMatrix[op][arg1][arg2])(leftarg, rightarg, NULL); + } + else // numeric_funcs + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + presult[i] = numericFun(&finfo); + } + SET_NOTNULL(pflagsRes[i]); + } + else + { + SET_NULL(pflagsRes[i]); + } + } + } + + } + presultVector->m_rows = PG_GETARG_INT32(2); + + return presultVector; +} + +template +ScalarVector* +vnumeric_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell* cell = NULL; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + FunctionCallInfoData finfo; + Numeric leftarg, rightarg; // left-hand and right-hand operand of addition + uint16 num1Flags, num2Flags; // numeric flags of num1 and num2 + int arg1, arg2, i; + bictl ctl; + finfo.arg = &args[0]; + + ctl.context = context; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + leftarg = DatumGetBINumeric(pVal[i]); + cell->m_val[idx].val = addVariable(context, NumericGetDatum(leftarg)); + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + leftarg = (Numeric)(cell->m_val[idx].val); + rightarg = DatumGetBINumeric(pVal[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + // try to use big integer fast compare function + if(likely(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags))) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = cell->m_val[idx].val; + // call big integer fast compare function + if(get_smaller) + (BiAggFunMatrix[BI_AGG_SMALLER][arg1][arg2])(leftarg, rightarg, &ctl); + else + (BiAggFunMatrix[BI_AGG_LARGER][arg1][arg2])(leftarg, rightarg, &ctl); + // ctl.store_pos may be pointed to new address. + cell->m_val[idx].val = ctl.store_pos; + } + else + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numericFun(&finfo); + if(result != cell->m_val[idx].val) + cell->m_val[idx].val = replaceVariable(context, cell->m_val[idx].val, result); + } + } + } + } + + return NULL; +} + +/* + * @Description : min or max(numeric)'s agg function. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of min or max(numeric) for each group. + */ +template +ScalarVector* +vsnumeric_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*) sdata[idx]; + + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args[2]; + Datum result; + Datum *leftdata = NULL; + FunctionCallInfoData finfo; + /* left-hand and right-hand operand of addition */ + Numeric leftarg, rightarg; + /* numeric flags of num1 and num2 */ + uint16 num1Flags, num2Flags; + int arg1, arg2, i; + bictl ctl; + uint8 leftflag; + int arrIndx, atomIndx; + + finfo.arg = &args[0]; + ctl.context = data->m_cxt; + + for (i = 0; i < nrows; i++) + { + /*only do when not null */ + if ((loc[i] != 0) && NOT_NULL(flag[i])) + { + /* previous result(leftdata) */ + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + + /* check data flag */ + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + if (IS_NULL(leftflag)) + { + leftarg = DatumGetBINumeric(pVal[i]); + data->setValue(NumericGetDatum(leftarg), false, arrIndx, atomIndx); + } + else + { + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + + leftarg = (Numeric)(leftdata[0]); + rightarg = DatumGetBINumeric(pVal[i]); + num1Flags = NUMERIC_NB_FLAGBITS(leftarg); + num2Flags = NUMERIC_NB_FLAGBITS(rightarg); + /* try to use big integer fast compare function */ + if (likely(NUMERIC_FLAG_IS_BI(num1Flags) && NUMERIC_FLAG_IS_BI(num2Flags))) + { + arg1 = NUMERIC_FLAG_IS_BI128(num1Flags); + arg2 = NUMERIC_FLAG_IS_BI128(num2Flags); + ctl.store_pos = leftdata[0]; + /* call big integer fast compare function */ + if (get_smaller) + (BiAggFunMatrix[BI_AGG_SMALLER][arg1][arg2])(leftarg, rightarg, &ctl); + else + (BiAggFunMatrix[BI_AGG_LARGER][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address. */ + leftdata[0] = ctl.store_pos; + } + else + { + args[0] = NumericGetDatum(leftarg); + args[1] = NumericGetDatum(rightarg); + result = numericFun(&finfo); + if(result != leftdata[0]) + leftdata[0] = data->replaceVariable(leftdata[0], result); + } + } + } + } + + return NULL; +} + +template +ScalarVector* +vector_count(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if (cell != NULL) + { + if(IS_NULL(flag[i]) == false || allcount) + { + if(IS_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + cell->m_val[idx].val = 1; + else + cell->m_val[idx].val = pVal[i]; + + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + if(isTransition) + cell->m_val[idx].val++; + else + cell->m_val[idx].val += pVal[i]; + } + } + else + SET_NOTNULL(cell->m_val[idx].flag); + } + } + + return NULL; +} + +/* + * @Description : Calculate total numbers of input data with respect to different group. + * @in isTransition : Mark if need to transfer or not + * @in allcount : Mark count null value or not. + * @return : NULL, actual result has been inserted into m_data. + */ +template +ScalarVector* +vsonic_count(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicDatumArray* data = sdata[idx]; + + /* information about input scalarvector */ + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + int arrIdx, atomIdx; + Datum *aggval = NULL; + + Assert(data->m_atomTypeSize == sizeof(Datum)); + + for(int i = 0 ; i < nrows; i++) + { + if (0 != loc[i]) + { + if(IS_NULL(flag[i]) == false || allcount) + { + /* get n-th data's actual position in hash table, including arrIdx and atomIdx */ + arrIdx = getArrayIndx(loc[i], data->m_nbit); + atomIdx = getArrayLoc(loc[i], data->m_atomSize - 1); + aggval = &((Datum*)(data->m_arr[arrIdx])->data)[atomIdx]; + + if(IS_NULL(data->getNthNullFlag(arrIdx, atomIdx))) + { + /* initialize count number */ + aggval[0] = isTransition ? 1 : pVal[i]; + + data->setNthNullFlag(loc[i], false); + } + else + { + /* count if not null in same group */ + aggval[0] = isTransition ? (aggval[0] + 1) : (aggval[0] + pVal[i]); + } + } + else + data->setNthNullFlag(loc[i], false); + } + } + + return NULL; +} + +template +ScalarVector* +vint8_sum(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell* cell = NULL; + int arg1, arg2, i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + bictl ctl; + Numeric leftarg, rightarg; // left-hand and right-hand operand of addition + ctl.context = context; + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(NOT_NULL(cell->m_val[idx].flag)) + { + if(isTransition) + { + /* leftarg maybe bi64 or bi128 */ + leftarg = (Numeric)(cell->m_val[idx].val); + /* store pVal[i](int8) to bi64 */ + rightarg = (Numeric)(makeNumeric64(pVal[i], 0)); + ctl.store_pos = cell->m_val[idx].val; + arg1 = NUMERIC_IS_BI128(leftarg); + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][0])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + cell->m_val[idx].val = ctl.store_pos; + } + else + { + /* leftarg maybe bi64 or bi128 */ + leftarg = (Numeric)(cell->m_val[idx].val); + /* rightarg maybe bi64 or bi128 */ + rightarg = (Numeric)(pVal[i]); + ctl.store_pos = cell->m_val[idx].val; + arg1 = NUMERIC_IS_BI128(leftarg); + arg2 = NUMERIC_IS_BI128(rightarg); + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + cell->m_val[idx].val = ctl.store_pos; + } + } + else + { + if(isTransition) //copy the first value + { + /* store the first value to bi64 */ + cell->m_val[idx].val = addVariable(context, makeNumeric64(pVal[i], 0)); + } + else + { + /* copy the sum data to hash table */ + cell->m_val[idx].val = addVariable(context, pVal[i]); + } + SET_NOTNULL(cell->m_val[idx].flag); + } + } + } + return NULL; +} + +/* + * @Description : sum(int8)'s agg function. + * + * @in m_loc : location in hash table. + * @in pVal : vector to be calculated. + * @out m_data[idx] : value of sum(int8) for each group. + */ +template +ScalarVector* +vsint8_sum(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = (int)PG_GETARG_DATUM(1); + uint32* loc = (uint32*)PG_GETARG_DATUM(2); + SonicDatumArray** sdata = (SonicDatumArray**)PG_GETARG_DATUM(3); + SonicEncodingDatumArray* data = (SonicEncodingDatumArray*)sdata[idx]; + + Datum *leftdata = NULL; + uint8 leftflag; + Numeric leftarg, rightarg; + int arg1, arg2, i; + int arrIndx, atomIndx; + bictl ctl; + + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + ctl.context = data->m_cxt; + + for (i = 0; i < nrows; i++) + { + if (loc[i] != 0 && NOT_NULL(flag[i])) + { + /* get sum (leftdata) */ + arrIndx = getArrayIndx(loc[i], data->m_nbit); + atomIndx = getArrayLoc(loc[i], data->m_atomSize - 1); + /* first check flag */ + leftflag = data->getNthNullFlag(arrIndx, atomIndx); + + if (NOT_NULL(leftflag)) + { + /* get data value */ + leftdata = &((Datum *)data->m_arr[arrIndx]->data)[atomIndx]; + + if (isTransition) + { + /* leftarg maybe bi64 or bi128 */ + leftarg = (Numeric)(leftdata[0]); + /* store pVal[i](int8) to bi64 */ + rightarg = (Numeric)(makeNumeric64(pVal[i], 0)); + ctl.store_pos = leftdata[0]; + arg1 = NUMERIC_IS_BI128(leftarg); + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][0])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + leftdata[0]= ctl.store_pos; + } + else + { + /* leftarg maybe bi64 or bi128 */ + leftarg = (Numeric)(leftdata[0]); + /* rightarg maybe bi64 or bi128 */ + rightarg = (Numeric)(pVal[i]); + ctl.store_pos = leftdata[0]; + arg1 = NUMERIC_IS_BI128(leftarg); + arg2 = NUMERIC_IS_BI128(rightarg); + /* call big integer fast add function */ + (BiAggFunMatrix[BI_AGG_ADD][arg1][arg2])(leftarg, rightarg, &ctl); + /* ctl.store_pos may be pointed to new address */ + leftdata[0] = ctl.store_pos; + } + } + else + { + /* copy the first value */ + if (isTransition) + { + /* store the first value to bi64 */ + data->setValue(makeNumeric64(pVal[i], 0), false, arrIndx, atomIndx); + } + else + { + /* copy the sum data to hash table */ + data->setValue(pVal[i], false, arrIndx, atomIndx); + } + } + } + } + return NULL; +} + +#endif /* NUMERIC_INL_ */ diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/timestamp.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/timestamp.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/timestamp.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/timestamp.inl 2020-12-12 17:06:43.053345535 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * timestamp.inl + * template implementation of 64-bit integer based timestamps. + * + * src/backend/vecexecutor/vecprimitive/timestamp.inl + * + *----------------------------------------------------------------------- + */ + +#ifndef TIMESTAMP_INL +#define TIMESTAMP_INL + +#include "postgres.h" +#include "knl/knl_variable.h" + +#ifndef HAVE_INT64_TIMESTAMP +#error 'Only compile with 64bit OS' +#endif + + +#endif diff -uprN postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl --- postgresql-hll-2.14_old/gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl 2020-12-12 17:06:43.053345535 +0800 @@ -0,0 +1,836 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * 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. + * ------------------------------------------------------------------------- + * + * varchar.inl + * template implementation of char/varchar routines. + * + * + * src/include/utils/varchar.inl + * + *------------------------------------------------------------------------- + */ + +#ifndef VARCHAR_INL +#define VARCHAR_INL + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include +#include +#include "utils/formatting.h" +#include "utils/builtins.h" +#include "vecexecutor/vechashtable.h" +#include "mb/pg_wchar.h" +#include "fmgr.h" +#include "vecexecutor/vecfunc.h" +#include "access/tuptoaster.h" + + +/* Comparison Functions used for bpchar type + * vectorize function + */ +template +static FORCE_INLINE bool +bpchar_sop(Datum arg1, Datum arg2, Oid collation) +{ + if (sop == SOP_EQ) + { + return DatumGetBool(DirectFunctionCall2(bpchareq, arg1, arg2)); + } + else if (sop == SOP_NEQ) + { + return DatumGetBool(DirectFunctionCall2(bpcharne, arg1, arg2)); + } + else if (sop == SOP_LE) + { + return DatumGetBool(DirectFunctionCall2Coll(bpcharle, collation, arg1, arg2)); + } + else if (sop == SOP_LT) + { + return DatumGetBool(DirectFunctionCall2Coll(bpcharlt, collation, arg1, arg2)); + } + else if (sop == SOP_GE) + { + return DatumGetBool(DirectFunctionCall2Coll(bpcharge, collation, arg1, arg2)); + } + else if (sop == SOP_GT) + { + return DatumGetBool(DirectFunctionCall2Coll(bpchargt, collation, arg1, arg2)); + } +} + + +/* Comparison Functions used for text type + * vectorize function + */ +template +static FORCE_INLINE bool +text_sop(Datum arg1, Datum arg2, Oid collation) +{ + if (sop == SOP_EQ) + { + return DatumGetBool(DirectFunctionCall2(texteq, arg1, arg2)); + } + else if (sop == SOP_NEQ) + { + return DatumGetBool(DirectFunctionCall2(textne, arg1, arg2)); + } + else if (sop == SOP_LE) + { + return DatumGetBool(DirectFunctionCall2Coll(text_le, collation, arg1, arg2)); + } + else if (sop == SOP_LT) + { + return DatumGetBool(DirectFunctionCall2Coll(text_lt, collation, arg1, arg2)); + } + else if (sop == SOP_GE) + { + return DatumGetBool(DirectFunctionCall2Coll(text_ge, collation, arg1, arg2)); + } + else if (sop == SOP_GT) + { + return DatumGetBool(DirectFunctionCall2Coll(text_gt, collation, arg1, arg2)); + } +} + +/* Comparison Functions used for bpchar + * vectorize function + */ + +template +ScalarVector * +vbpchar_sop(PG_FUNCTION_ARGS) +{ + ScalarVector *VecParg1 = PG_GETARG_VECTOR(0); + ScalarVector *VecParg2 = PG_GETARG_VECTOR(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarVector *VecResult = PG_GETARG_VECTOR(3); + uint8* pflag = (uint8*)(VecResult->m_flag); + bool *pselection = PG_GETARG_SELECTION(4); + ScalarValue *presult = VecResult->m_vals; + ScalarValue *parg1 = VecParg1->m_vals; + ScalarValue *parg2 = VecParg2->m_vals; + uint8* pflags1 = VecParg1->m_flag; + uint8* pflags2 = VecParg2->m_flag; + Datum value1; + Datum value2; + Oid collation = PG_GET_COLLATION(); + int i; + bool result = false; + + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + value1= ScalarVector::Decode(parg1[i]); + value2 = ScalarVector::Decode(parg2[i]); + result = bpchar_sop(value1, value2, collation); + presult[i] = result; + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + value1= ScalarVector::Decode(parg1[i]); + value2 = ScalarVector::Decode(parg2[i]); + result = bpchar_sop(value1, value2, collation); + presult[i] = result; + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + VecResult->m_rows = nvalues; + + return VecResult; +} + + +template +ScalarVector * +vtext_sop(PG_FUNCTION_ARGS) +{ + ScalarVector *VecParg1 = PG_GETARG_VECTOR(0); + ScalarVector *VecParg2 = PG_GETARG_VECTOR(1); + int32 nvalues = PG_GETARG_INT32(2); + ScalarVector *VecResult = PG_GETARG_VECTOR(3); + uint8* pflag = (uint8*)(VecResult->m_flag); + bool *pselection = PG_GETARG_SELECTION(4); + ScalarValue *parg1 = VecParg1->m_vals; + ScalarValue *parg2 = VecParg2->m_vals; + ScalarValue *presult = VecResult->m_vals; + uint8* pflags1 = VecParg1->m_flag; + uint8* pflags2 = VecParg2->m_flag; + Datum value1; + Datum value2; + Oid collation = PG_GET_COLLATION(); + int i; + bool result = false; + + if(likely(pselection == NULL)) + { + for (i = 0; i < nvalues; i++) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + value1= ScalarVector::Decode(parg1[i]); + value2 = ScalarVector::Decode(parg2[i]); + result = text_sop(value1, value2, collation); + presult[i] = result; + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if(pselection[i]) + { + if (BOTH_NOT_NULL(pflags1[i], pflags2[i])) + { + value1= ScalarVector::Decode(parg1[i]); + value2 = ScalarVector::Decode(parg2[i]); + result = text_sop(value1, value2, collation); + presult[i] = result; + SET_NOTNULL(pflag[i]); + } + else + SET_NULL(pflag[i]); + } + } + } + + VecResult->m_rows = nvalues; + + return VecResult; +} + +// if bigerOrSmaller equals 1, means find the larger, otherwise find the smaller one +// +template +ScalarVector* +vbpchar_min_max(PG_FUNCTION_ARGS) +{ + ScalarVector* pVector = (ScalarVector*)PG_GETARG_DATUM(0); + int idx = PG_GETARG_DATUM(1); + + MemoryContext context = (MemoryContext)PG_GETARG_DATUM(3); + hashCell** loc = (hashCell**)PG_GETARG_DATUM(2); + hashCell* cell = NULL; + int i; + ScalarValue* pVal = pVector->m_vals; + uint8* flag = pVector->m_flag; + int nrows = pVector->m_rows; + Datum args1; + Datum args2; + int result = 0; + Oid collation = PG_GET_COLLATION(); + + + for(i = 0 ; i < nrows; i++) + { + cell = loc[i]; + if(cell && IS_NULL(flag[i]) == false) //only do when not null + { + if(IS_NULL(cell->m_val[idx].flag)) + { + cell->m_val[idx].val = addVariable(context, pVal[i]); + SET_NOTNULL(cell->m_val[idx].flag); + } + else + { + args1 = ScalarVector::Decode(cell->m_val[idx].val); + args2 = ScalarVector::Decode(pVal[i]); + result = DirectFunctionCall2Coll(bpcharFun, collation, args1, args2); + if(bigerOrSmaller * result < 0) + cell->m_val[idx].val = replaceVariable(context, args1, args2); + } + } + } + + return NULL; +} + +template +inline int32 +vec_text_len(Datum str, mblen_converter fun_mblen) +{ + int len = 0; + + /* fastpath when max encoding length is one */ + if (eml == 1) + len = toast_raw_datum_size(str) - VARHDRSZ; + else + { + text *t = DatumGetTextPP(str); + const char *mbstr; + int limit; + + mbstr = VARDATA_ANY(t); + limit = VARSIZE_ANY_EXHDR(t); + while (limit > 0 && *mbstr) + { + int l = fun_mblen((const unsigned char *)mbstr); + + limit -= l; + mbstr += l; + len++; + } + if (limit < 0) //Prevent string length from exceeding the limit. + len--; + } + + return len; +} + + +inline static Datum +null_return(bool *is_null) +{ + text *result = NULL; + if(u_sess->attr.attr_sql.sql_compatibility == A_FORMAT) + { + *is_null = true; + return (Datum)0; + } + else + { + result = cstring_to_text(""); + PG_RETURN_TEXT_P(result); + } +} +template +Datum +vec_text_substr(Datum str, int32 start, int32 length, bool *is_null, mblen_converter fun_mblen) +{ + int32 S = start; /* start position */ + int32 S1; /* adjusted start position */ + int32 L1; /* adjusted substring length */ + text *result = NULL; + text *slice = NULL; + int32 i; + char *p = NULL; + char *s = NULL; + int E; /* end position */ + int32 slice_size; + int32 slice_strlen; + int32 E1; + int total; + errno_t rc; + + + total = vec_text_len(str, fun_mblen); + + if(orclcompat) + { + if(withlen) + { + if ((length <= 0) || (start > total) || (start + total < 0)) + { + return null_return(is_null); + } + } + else + { + if ((start > total) || (start + total < 0)) + { + return null_return(is_null); + } + } + /* + * amend the start position. when S < 0, + * amend the sartPosition to abs(start) from last char, + * when s==0, the start position is set 1. + */ + if (S < 0) + { + S = total + S + 1; + } + else if (0 == S) + { + S = 1; + } + } + + S1 = Max(S, 1); + + if (withlen == false) + { + slice_size = L1 = -1; + E = total + 1; + } + else + { + E = S + length; + /* + * A negative value for L is the only way for the end position to + * be before the start. SQL99 says to throw an error. + */ + if (E < S) + { + + if (length < 0) + { + ereport(ERROR, + (errcode(ERRCODE_SUBSTRING_ERROR), + errmsg("negative substring length not allowed"))); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_SUBSTRING_ERROR), + errmsg("the giving length is too long, it lets the end postion integer out of range"))); + } + } + /* + * A zero or negative value for the end position can happen if the + * start was negative or one. SQL99 says to return a zero-length + * string. + */ + if (E < 1) + { + return null_return(is_null); + } + + L1 = E - S1; + + if(eml > 1) + slice_size = E * eml; + } + + + E = Min(E,total + 1); + + if(eml == 1) + { + result = DatumGetTextPSlice(str, S1 - 1, L1); + + /* null return for oracle format */ + if (result == NULL || 0 == VARSIZE_ANY_EXHDR(result)) + return null_return(is_null); + else + PG_RETURN_TEXT_P(result); + } + else + { + /* + * If we're working with an untoasted source, no need to do an extra + * copying step. + */ + if (is_compress) + { + slice = DatumGetTextPSlice(str, 0, slice_size); + + /* Now we can get the actual length of the slice in MB characters */ + slice_strlen = pg_mbstrlen_with_len(VARDATA_ANY(slice), VARSIZE_ANY_EXHDR(slice)); + + /* + * Check that the start position wasn't > slice_strlen. If so, SQL99 + * says to return a zero-length string. + */ + if (S1 > slice_strlen) + { + if (slice != (text *) DatumGetPointer(str)) + pfree_ext(slice); + return null_return(is_null); + + } + + /* + * Adjust L1 and E1 now that we know the slice string length. Again + * remember that S1 is one based, and slice_start is zero based. + */ + if (L1 > -1) + E1 = Min(S1 + L1, 1 + slice_strlen); + else + E1 = 1 + slice_strlen; + } + else + { + slice = (text *) DatumGetPointer(str); + E1 = E ; + } + + if (S1 >= E1) + { + return null_return(is_null); + } + + p = VARDATA_ANY(slice); + for (i = 0; i < S1 - 1; i++) + { + p += fun_mblen((const unsigned char *)p); + } + + /* hang onto a pointer to our start position */ + s = p; + + /* + * Count the actual bytes used by the substring of the requested + * length. + */ + for (i = S1; i < E1; i++) + { + p += fun_mblen((const unsigned char *)p); + } + + if(0 == (p - s)) + { + return null_return(is_null); + } + + result = (text *) palloc(VARHDRSZ + (p - s)); + SET_VARSIZE(result, VARHDRSZ + (p - s)); + rc = memcpy_s(VARDATA(result), (p - s), s, (p - s)); + securec_check(rc,"\0","\0"); + PG_RETURN_TEXT_P(result); + } +} + +/* + * vtext_substr() vectorize function + * + * Return a substring starting at the specified position. + * Input: + * - string + * - starting position (is one-based) + * - string length + */ +template +ScalarVector * +vtext_substr (PG_FUNCTION_ARGS) +{ + ScalarVector *VecParg1 = PG_GETARG_VECTOR(0); + ScalarValue *parg2 = PG_GETARG_VECVAL(1); + uint8 *flag2 = PG_GETARG_VECTOR(1)->m_flag; + + uint8 *flag3 = NULL; + ScalarValue *parg3 = NULL; + int32 nvalues = 0; + ScalarVector *VecResult = NULL; + bool *pselection = NULL; + Datum result; + int i = 0; + int32 eml; + int start; + int length = 0; + bool isnull = false; + bool is_compress = false; + int baseIdx = 0; + + eml = pg_database_encoding_max_length(); + mblen_converter fun_mblen; + fun_mblen = *pg_wchar_table[GetDatabaseEncoding()].mblen; + + if(withlen) + { + parg3 = PG_GETARG_VECVAL(2); + flag3 = PG_GETARG_VECTOR(2)->m_flag; + nvalues = PG_GETARG_INT32(3); + VecResult = PG_GETARG_VECTOR(4); + pselection = PG_GETARG_SELECTION(5); + } + else + { + nvalues = PG_GETARG_INT32(2); + VecResult = PG_GETARG_VECTOR(3); + pselection = PG_GETARG_SELECTION(4); + } + + ScalarValue *parg1 = VecParg1->m_vals; + uint8 *flag1 = VecParg1->m_flag; + uint8 *ResultFlag = VecResult->m_flag; + if (pselection != NULL) + { + for (i = 0; i < nvalues; i++) + { + isnull = false; + if (pselection[i]) + { + if (NOT_NULL(flag1[i]) && NOT_NULL(flag2[i]) && (withlen ? NOT_NULL(flag3[i]) : true)) + { + start = parg2[i]; + if(withlen) + length = parg3[i]; + + is_compress = (VARATT_IS_COMPRESSED(DatumGetPointer(parg1[i])) || VARATT_IS_EXTERNAL(DatumGetPointer(parg1[i]))); + baseIdx = orclcompat * 4 + withlen * 2 + is_compress + (eml - 1) * 8; + + result = (*substr_Array[baseIdx])(parg1[i],start,length,&isnull,fun_mblen); + + if(isnull == true) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + else + { + SET_NULL(ResultFlag[i]); + } + } + } + } + else + { + for (i = 0; i < nvalues; i++) + { + isnull = false; + if (NOT_NULL(flag1[i]) && NOT_NULL(flag2[i]) && (withlen ? NOT_NULL(flag3[i]) : true)) + { + start = parg2[i]; + if(withlen) + length = parg3[i]; + + is_compress = (VARATT_IS_COMPRESSED(DatumGetPointer(parg1[i])) || VARATT_IS_EXTERNAL(DatumGetPointer(parg1[i]))); + + baseIdx = orclcompat * 4 + withlen * 2 + is_compress + (eml - 1) * 8; + + result = (*substr_Array[baseIdx])(parg1[i],start,length,&isnull,fun_mblen); + + if(isnull == true) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + else + { + SET_NULL(ResultFlag[i]); + } + } + + } + + VecResult->m_rows = nvalues; + + return VecResult; +} + +template +ScalarVector * +vbpchar(PG_FUNCTION_ARGS) +{ + ScalarVector *VecParg1 = PG_GETARG_VECTOR(0); + ScalarValue *parg2 = NULL; + ScalarValue *parg3 = NULL; + int32 nvalues = 0; + ScalarVector *VecResult = NULL; + bool *pselection = NULL; + Datum result; + int i; + Datum args[3]; + FunctionCallInfoData finfo; + + if (bpcharFunc == name_bpchar) + { + nvalues = PG_GETARG_INT32(1); + VecResult = PG_GETARG_VECTOR(2); + pselection = PG_GETARG_SELECTION(3); + } + else if (bpcharFunc == bpchar) + { + parg2 = PG_GETARG_VECVAL(1); + parg3 = PG_GETARG_VECVAL(2); + nvalues = PG_GETARG_INT32(3); + VecResult = PG_GETARG_VECTOR(4); + pselection = PG_GETARG_SELECTION(5); + } + else if (bpcharFunc == char_bpchar) + { + nvalues = PG_GETARG_INT32(1); + VecResult = PG_GETARG_VECTOR(2); + pselection = PG_GETARG_SELECTION(3); + } + else + { + nvalues = PG_GETARG_INT32(1); + VecResult = PG_GETARG_VECTOR(2); + pselection = PG_GETARG_SELECTION(3); + } + + ScalarValue *parg1 = VecParg1->m_vals; + uint8 *flag1 = VecParg1->m_flag; + uint8 *ResultFlag = VecResult->m_flag; + finfo.arg = &args[0]; + + if (pselection != NULL) + { + for (i = 0; i < nvalues; i++) + { + if (pselection[i]) + { + if (NOT_NULL(flag1[i])) + { + args[0] = ScalarVector::Decode(parg1[i]); + + if(bpcharFunc == bpchar) + { + args[1] = parg2[i]; + args[2] = parg3[i]; + } + finfo.isnull = false; + result = bpcharFunc(&finfo); + if(finfo.isnull == true) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + else + { + SET_NULL(ResultFlag[i]); + } + } + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if (NOT_NULL(flag1[i])) + { + args[0] = ScalarVector::Decode(parg1[i]); + + if(bpcharFunc == bpchar) + { + args[1] = parg2[i]; + args[2] = parg3[i]; + } + finfo.isnull = false; + result = bpcharFunc(&finfo); + if(finfo.isnull == true) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + else + { + SET_NULL(ResultFlag[i]); + } + } + + } + + VecResult->m_rows = nvalues; + + return VecResult; +} + +template +ScalarVector * +vtrim1(PG_FUNCTION_ARGS) +{ + ScalarVector *VecParg1 = PG_GETARG_VECTOR(0); + int32 nvalues = PG_GETARG_INT32(1); + ScalarVector *VecResult = PG_GETARG_VECTOR(2); + bool *pselection = PG_GETARG_SELECTION(3); + + ScalarValue *parg1 = VecParg1->m_vals; + uint8 *flag = VecParg1->m_flag; + uint8 *ResultFlag = VecResult->m_flag; + Datum result; + int i; + Datum args[1]; + FunctionCallInfoData finfo; + + finfo.arg = &args[0]; + + + if (pselection != NULL) + { + for (i = 0; i < nvalues; i++) + { + if (pselection[i]) + { + if (IS_NULL(flag[i])) + { + SET_NULL(ResultFlag[i]); + } + else + { + args[0] = ScalarVector::Decode(parg1[i]); + finfo.isnull = false; + result = trim1Func(&finfo); + if(unlikely(finfo.isnull == true)) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + } + } + } + else + { + for (i = 0; i < nvalues; i++) + { + if (IS_NULL(flag[i])) + { + SET_NULL(ResultFlag[i]); + } + else + { + args[0] = ScalarVector::Decode(parg1[i]); + finfo.isnull = false; + result = trim1Func(&finfo); + if(unlikely(finfo.isnull == true)) + SET_NULL(ResultFlag[i]); + else + { + VecResult->m_vals[i] = result; + SET_NOTNULL(ResultFlag[i]); + } + } + } + } + + PG_GETARG_VECTOR(2)->m_rows = nvalues; + return PG_GETARG_VECTOR(2); +} + +#endif // VARCHAR_INL diff -uprN postgresql-hll-2.14_old/hll.cpp postgresql-hll-2.14/hll.cpp --- postgresql-hll-2.14_old/hll.cpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/hll.cpp 2020-12-12 17:06:53.680481868 +0800 @@ -0,0 +1,3814 @@ +/*$$$!!Warning: Huawei key information asset. No spread without permission.$$$*/ +/*CODEMARK:WQcKBKQLgyHkXlCLiGIlSvGdiRVlDYpIJLLeBa8CyrNJleUkOpTtwkJAoYct18IqCBpJnKNz +xHjEu+uXc8LQFsBPAN6RG3/a8MnU36eZoStdshKdySYPRbwAIpth0SoG2y9LyT4zsfl8J/br +RRAPGyECREP7CJ0gHxqjIhh5muQBJQ1xpxUmABZ/aMVsKNru5BTOInIzMnbTuU3UrjrGBkHz +YTUEwb9tGQXmKWuR6udoh2xM0GdkxyNtwKLofOylsjpy3Nq3hohaHCq038+5RA==#*/ +/*$$$!!Warning: Deleting or modifying the preceding information is prohibited.$$$*/ +/* Copyright 2013 Aggregate Knowledge, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include // Needs to be first. + +#if defined(__APPLE__) +#include +#define bswap_64 OSSwapInt64 +#elif defined(__FreeBSD__) || defined(__DragonFly__) +#include +#define bswap_64 bswap64 +#else +#include +#endif + +#include +#include +#include +#include +#include +#include +#if PG_VERSION_NUM >= 120000 +#include "access/genam.h" +#include "access/heapam.h" +#endif +#include "access/sysattr.h" +#include "access/htup.h" +#include "commands/extension.h" +#include "optimizer/planner.h" +#include "utils/array.h" +#include "utils/bytea.h" +#include "utils/builtins.h" +#include "utils/fmgroids.h" +#if (PG_VERSION_NUM >= 100000) +#include "utils/fmgrprotos.h" +#endif +#include "utils/guc.h" +#include "utils/int8.h" +#include "utils/lsyscache.h" +#include "hll.h" +#include "utils/memutils.h" +#if (PG_VERSION_NUM >= 100000) +#include "utils/regproc.h" +#endif +#include "catalog/indexing.h" +#include "catalog/namespace.h" +#include "catalog/pg_type.h" +#include "catalog/pg_extension.h" +#include "lib/stringinfo.h" +#include "libpq/pqformat.h" +#include "nodes/print.h" +#if PG_VERSION_NUM >= 120000 +#include "optimizer/optimizer.h" +#else +#include "optimizer/var.h" +#endif +#include "miscadmin.h" + +#include "MurmurHash3.h" +#include "fmgr.h" +#ifdef PG_MODULE_MAGIC +PG_MODULE_MAGIC; +#endif + +// ---------------------------------------------------------------- +// Output Version Control +// ---------------------------------------------------------------- +THR_LOCAL uint8_t g_output_version = 1; + +// ---------------------------------------------------------------- +// Type Modifiers +// ---------------------------------------------------------------- + + +static int32 g_default_log2m = DEFAULT_LOG2M; +static int32 g_default_regwidth = DEFAULT_REGWIDTH; +static int64 g_default_expthresh = DEFAULT_EXPTHRESH; +static int32 g_default_sparseon = DEFAULT_SPARSEON; + +// Support disabling hash aggregation functionality for PG > 9.6 +#if PG_VERSION_NUM >= 90600 + +#define EXTENSION_NAME "hll" +#define ADD_AGG_NAME "hll_add_agg" +#define UNION_AGG_NAME "hll_union_agg" +#define HLL_AGGREGATE_COUNT 6 + +static Oid hllAggregateArray[HLL_AGGREGATE_COUNT]; +static bool aggregateValuesInitialized = false; + +bool ForceGroupAgg = false; + +static create_upper_paths_hook_type previous_upper_path_hook; +static void RegisterConfigVariables(void); + +#if (PG_VERSION_NUM >= 110000) +static void hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, + RelOptInfo *input_rel, RelOptInfo *output_rel, + void *extra); +#else +static void hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, + RelOptInfo *input_rel, RelOptInfo *output_rel); +#endif + +static void MaximizeCostOfHashAggregate(Path *path); +static Oid get_extension_schema(Oid ext_oid); +static Oid FunctionOid(const char *schemaName, const char *functionName, int argumentCount, bool missingOk); +static void InitializeHllAggregateOids(void); +static bool HllAggregateOid(Oid aggregateOid); + +void _PG_init(void); +void _PG_fini(void); + +/* _PG_init is the shared library initialization function */ +void _PG_init(void) +{ + /* + * Register HLL configuration variables. + */ + RegisterConfigVariables(); + + previous_upper_path_hook = create_upper_paths_hook; + create_upper_paths_hook = hll_aggregation_restriction_hook; +} + +/* + * hll_aggregation_restriction_hook is assigned to create_upper_paths_hook to + * check whether there exist a path with hash aggregate. If that aggregate is + * introduced by hll, it's cost is maximized to force planner to not to select + * hash aggregate. + * + * Since the signature of the hook changes after PG 11, we define the signature + * and the previous hook call part of this function depending on the PG version. + */ +void +#if (PG_VERSION_NUM >= 110000) + +hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, + RelOptInfo *input_rel, RelOptInfo *output_rel, + void *extra) +#else +hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, + RelOptInfo *input_rel, RelOptInfo *output_rel) +#endif +{ + Oid extensionOid = InvalidOid; + + // If previous hook exist, call it first to get most update path + if (previous_upper_path_hook != NULL) + { + #if (PG_VERSION_NUM >= 110000) + previous_upper_path_hook(root, stage, input_rel, output_rel, extra); + #else + previous_upper_path_hook(root, stage, input_rel, output_rel); + #endif + } + + /* If HLL extension is not loaded, do nothing */ + extensionOid = get_extension_oid(EXTENSION_NAME, true); + if (!OidIsValid(extensionOid)) + { + return; + } + + /* If we have the extension, that means we also have aggregations */ + if (!aggregateValuesInitialized) + { + InitializeHllAggregateOids(); + } + + /* + * If the client force the group agg, maximize the cost of the path with + * the hash agg to force planner to choose group agg instead. + */ + if (ForceGroupAgg) + { + if (stage == UPPERREL_GROUP_AGG || stage == UPPERREL_FINAL) + { + ListCell *pathCell = list_head(output_rel->pathlist); + foreach(pathCell, output_rel->pathlist) + { + Path *path = (Path *) lfirst(pathCell); + if(path->pathtype == T_Agg && ((AggPath *)path)->aggstrategy == AGG_HASHED) + { + MaximizeCostOfHashAggregate(path); + } + } + } + } +} + +/* + * InitializeHllAggregateOids initializes the array of hll aggregate oids. + */ +void +InitializeHllAggregateOids() +{ + Oid extensionId = get_extension_oid(EXTENSION_NAME, false); + Oid hllSchemaOid = get_extension_schema(extensionId); + const char *hllSchemaName = get_namespace_name(hllSchemaOid); + char *aggregateName = NULL; + Oid aggregateOid = InvalidOid; + int addAggArgumentCounter; + + /* Initialize HLL_UNION_AGG oid */ + aggregateName = UNION_AGG_NAME; + aggregateOid = FunctionOid(hllSchemaName, aggregateName, 1, true); + hllAggregateArray[0] = aggregateOid; + + /* Initialize HLL_ADD_AGG with different signatures */ + aggregateName = ADD_AGG_NAME; + for (addAggArgumentCounter = 1 ; addAggArgumentCounter < HLL_AGGREGATE_COUNT ; addAggArgumentCounter++) + { + aggregateOid = FunctionOid(hllSchemaName, aggregateName, addAggArgumentCounter, true); + hllAggregateArray[addAggArgumentCounter] = aggregateOid; + } + + aggregateValuesInitialized = true; +} + +/* + * get_extension_schema - given an extension OID, fetch its extnamespace + * Returns InvalidOid if no such extension. + * + * Copied from postgresql extension.c. + */ +Oid +get_extension_schema(Oid ext_oid) +{ + Oid result; + Relation rel; + SysScanDesc scandesc; + HeapTuple tuple; + ScanKeyData entry[1]; + + rel = heap_open(ExtensionRelationId, AccessShareLock); + + ScanKeyInit(&entry[0], +#if PG_VERSION_NUM >= 120000 + Anum_pg_extension_oid, +#else + ObjectIdAttributeNumber, +#endif + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(ext_oid)); + + scandesc = systable_beginscan(rel, ExtensionOidIndexId, true, + NULL, 1, entry); + + tuple = systable_getnext(scandesc); + + /* We assume that there can be at most one matching tuple */ + if (HeapTupleIsValid(tuple)) + result = ((Form_pg_extension) GETSTRUCT(tuple))->extnamespace; + else + result = InvalidOid; + + systable_endscan(scandesc); + + heap_close(rel, AccessShareLock); + + return result; +} + +/* + * FunctionOid searches for a given function identified by schema, functionName + * and argumentCount. It reports error if the function is not found or there + * are more than one match. If the missingOK parameter is set and there are + * no matches, then the function returns InvalidOid. + */ +Oid +FunctionOid(const char *schemaName, const char *functionName, int argumentCount, + bool missingOK) +{ + FuncCandidateList functionList = NULL; + Oid functionOid = InvalidOid; + + char *qualifiedFunctionName = quote_qualified_identifier(schemaName, functionName); + List *qualifiedFunctionNameList = stringToQualifiedNameList(qualifiedFunctionName); + List *argumentList = NIL; + const bool findVariadics = false; + const bool findDefaults = false; + + functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount, + argumentList, findVariadics, + findDefaults, true); + + if (functionList == NULL) + { + if (missingOK) + { + return InvalidOid; + } + + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("function \"%s\" does not exist", functionName))); + } + else if (functionList->next != NULL) + { + ereport(ERROR, (errcode(ERRCODE_AMBIGUOUS_FUNCTION), + errmsg("more than one function named \"%s\"", functionName))); + } + + /* get function oid from function list's head */ + functionOid = functionList->oid; + + return functionOid; +} + +/* + * MaximizeCostOfHashAggregate maximizes the cost of the path if it tries + * to run hll aggregate function with hash aggregate. + */ +void +MaximizeCostOfHashAggregate(Path *path) +{ + List *varList = pull_var_clause((Node*) path->pathtarget->exprs, + PVC_INCLUDE_AGGREGATES); + ListCell *varCell = NULL; + + foreach(varCell, varList) + { + Var *var = (Var *) lfirst(varCell); + + if (nodeTag(var) == T_Aggref) + { + Aggref *aggref = (Aggref *) var; + + if(HllAggregateOid(aggref->aggfnoid)) + { + path->total_cost = INT_MAX; + } + } + } +} + +/* + * HllAggregateOid checkes whether the given Oid is an id of any hll aggregate + * function using the pre-initialized hllAggregateArray. + */ +bool +HllAggregateOid(Oid aggregateOid) +{ + int arrayCounter; + + for (arrayCounter = 0 ; arrayCounter < HLL_AGGREGATE_COUNT ; arrayCounter++) + { + if (aggregateOid == hllAggregateArray[arrayCounter]) + { + return true; + } + } + + return false; +} + +/* Register HLL configuration variables. */ +void +RegisterConfigVariables(void) +{ + DefineCustomBoolVariable( + "hll.force_groupagg", + gettext_noop("Forces using group aggregate with hll aggregate functions"), + NULL, + &ForceGroupAgg, + false, + PGC_USERSET, + 0, + NULL, NULL, NULL); +} + +/* _PG_fini uninstalls extension hooks */ +void _PG_fini(void) +{ + create_upper_paths_hook = previous_upper_path_hook; +} +#endif + +int32 typmod_log2m(int32 typmod) +{ + return (typmod >> (TYPMOD_BITS - LOG2M_BITS)) + & MAX_BITVAL(LOG2M_BITS); +} + +int32 typmod_regwidth(int32 typmod) +{ + return (typmod >> (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS)) + & MAX_BITVAL(REGWIDTH_BITS); +} + +int32 typmod_expthresh(int32 typmod) +{ + return (typmod >> (TYPMOD_BITS - LOG2M_BITS - + REGWIDTH_BITS - EXPTHRESH_BITS)) + & MAX_BITVAL(EXPTHRESH_BITS); +} + +int32 typmod_sparseon(int32 typmod) +{ + return (typmod >> (TYPMOD_BITS - LOG2M_BITS - + REGWIDTH_BITS - EXPTHRESH_BITS - SPARSEON_BITS)) + & MAX_BITVAL(SPARSEON_BITS); +} + +// The expthresh is represented in a encoded format in the +// type modifier to save metadata bits. This routine is used +// when the expthresh comes from a typmod value or hll header. +// +int64 decode_expthresh(int32 encoded_expthresh) +{ + // This routine presumes the encoded value is correct and + // doesn't range check. + // + if (encoded_expthresh == 63) + return -1LL; + else if (encoded_expthresh == 0) + return 0; + else + return 1LL << (encoded_expthresh - 1); +} + +int32 integer_log2(int64 val) +{ + // Take the log2 of the expthresh. + int32 count = 0; + int64 value = val; + + Assert(val >= 0); + + while (value) + { + ++count; + value >>= 1; + } + return count - 1; +} + +int64 integer_exp2(int64 val) +{ + int64 result = 1; + if (val == 0 || val == -1) + return val; + + result <<= val; + return result; +} + +// This routine is used to encode an expthresh value to be stored +// in the typmod metadata or a hll header. +// +int32 encode_expthresh(int64 expthresh) +{ + // This routine presumes the uncompressed value is correct and + // doesn't range check. + // + if (expthresh == -1) + return 63; + else if (expthresh == 0) + return 0; + else + return integer_log2(expthresh) + 1; +} + +// If expthresh == -1 (auto select expthresh) determine +// the expthresh to use from nbits and nregs. +// +size_t +expthresh_value(int64 expthresh, size_t nbits, size_t nregs) +{ + if (expthresh != -1) + { + return (size_t) expthresh; + } + else + { + // Auto is selected, choose the maximum number of explicit + // registers that fits in the same space as the compressed + // encoding. + size_t cmpsz = ((nbits * nregs) + 7) / 8; + return cmpsz / sizeof(uint64_t); + } +} + +// ---------------------------------------------------------------- +// Maximum Sparse Control +// ---------------------------------------------------------------- + +// By default we set the sparse to full compressed threshold +// automatically to the point where the sparse representation would +// start to be larger. This can be overridden with the +// hll_set_max_sparse directive ... +// +static int g_max_sparse = -1; + + +// ---------------------------------------------------------------- +// Aggregating Data Structure +// ---------------------------------------------------------------- + +uint32_t +bitstream_unpack(bitstream_read_cursor_t * brcp) +{ + uint32_t retval; + + // Fetch the quadword containing our data. + uint64_t qw = * (uint64_t const *) brcp->brc_curp; + + // Swap the bytes. + qw = bswap_64(qw); + + // Shift the bits we want into place. + qw >>= 64 - brcp->brc_nbits - brcp->brc_used; + + // Mask the bits we want. + retval = (uint32_t) (qw & 0xffffffff) & brcp->brc_mask; + + // We've used some more bits now. + brcp->brc_used += brcp->brc_nbits; + + // Normalize the cursor. + while (brcp->brc_used >= 8) + { + brcp->brc_used -= 8; + brcp->brc_curp += 1; + } + + return retval; +} + +void +compressed_unpack(compreg_t * i_regp, + size_t i_width, + size_t i_nregs, + uint8_t const * i_bitp, + size_t i_size, + uint8_t i_vers) +{ + size_t bitsz; + size_t padsz; + + bitstream_read_cursor_t brc; + + bitsz = i_width * i_nregs; + + // Fail fast if the compressed array isn't big enough. + if (i_size * 8 < bitsz) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("compressed hll argument not large enough"))); + + padsz = i_size * 8 - bitsz; + + // Fail fast if the pad size doesn't make sense. + if (padsz >= 8) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistent padding in compressed hll argument"))); + + brc.brc_nbits = i_width; + brc.brc_mask = (1 << i_width) - 1; + brc.brc_curp = i_bitp; + brc.brc_used = 0; + + for (size_t ndx = 0; ndx < i_nregs; ++ndx) + { + uint32_t val = bitstream_unpack(&brc); + i_regp[ndx] = val; + } +} + +void +sparse_unpack(compreg_t * i_regp, + size_t i_width, + size_t i_log2nregs, + size_t i_nfilled, + uint8_t const * i_bitp, + size_t i_size) +{ + size_t bitsz; + size_t padsz; + size_t chunksz; + uint32_t regmask; + + bitstream_read_cursor_t brc; + + chunksz = i_log2nregs + i_width; + bitsz = chunksz * i_nfilled; + padsz = i_size * 8 - bitsz; + + // Fail fast if the pad size doesn't make sense. + if (padsz >= 8) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistent padding in sparse hll argument"))); + + regmask = (1 << i_width) - 1; + + brc.brc_nbits = chunksz; + brc.brc_mask = (1 << chunksz) - 1; + brc.brc_curp = i_bitp; + brc.brc_used = 0; + + for (size_t ii = 0; ii < i_nfilled; ++ii) + { + uint32_t buffer = bitstream_unpack(&brc); + uint32_t val = buffer & regmask; + uint32_t ndx = buffer >> i_width; + i_regp[ndx] = val; + } +} + + + +void +bitstream_pack(bitstream_write_cursor_t * bwcp, uint32_t val) +{ + size_t bits_left_in_first_byte = 8 - bwcp->bwc_used; + size_t bits_to_write_after_first_byte = bwcp->bwc_nbits - bits_left_in_first_byte; + size_t full_bytes_to_write = bits_to_write_after_first_byte / 8; + size_t remainder_bits_after_full_bytes = bits_to_write_after_first_byte % 8; + + // write is small enough that it fits in current byte's remaining space with + // room to spare, so pad the bottom of the byte by left-shifting + if (bwcp->bwc_nbits < bits_left_in_first_byte) + { + * bwcp->bwc_curp = (* bwcp->bwc_curp) | ((uint8_t)(val << (bits_left_in_first_byte - bwcp->bwc_nbits))); + + // consume part of the byte and exit + bwcp->bwc_used += bwcp->bwc_nbits; + return; + } + + // write fits exactly in current byte's remaining space, so just OR it in to + // the bottom bits of the byte + if (bwcp->bwc_nbits == bits_left_in_first_byte) + { + * bwcp->bwc_curp = (* bwcp->bwc_curp) | (uint8_t)(val); + + // consume remainder of byte and exit + bwcp->bwc_used = 0; + bwcp->bwc_curp += 1; + return; + } + + // write DOES NOT fit into current byte, so shift off all but the topmost + // bits from the value and OR those into the bottom bits of the byte + /* bwcp->bwc_nbits > bits_left_in_first_byte */ + * bwcp->bwc_curp = (* bwcp->bwc_curp) | ((uint8_t)(val >> (bwcp->bwc_nbits - bits_left_in_first_byte))); + + // consume remainder of byte + bwcp->bwc_used = 0; + bwcp->bwc_curp += 1; + + // if there are 8 or more bits of the value left to write, write them in one + // byte chunks, higher chunks first + if (full_bytes_to_write > 0) + { + for (size_t i = 0; i < full_bytes_to_write; ++i) + { + size_t bits_to_keep = bits_left_in_first_byte + (8 * (i + 1)); + size_t right_shift = (bwcp->bwc_nbits - bits_to_keep); + + // no OR here because byte is guaranteed to be completely unused + // see above, before conditional + * bwcp->bwc_curp = (uint8_t)(val >> right_shift); + + // consume entire byte + bwcp->bwc_used = 0; + bwcp->bwc_curp += 1; + } + } + if (remainder_bits_after_full_bytes > 0) + { + uint8_t mask = (1 << remainder_bits_after_full_bytes) - 1; + // no OR here because byte is guaranteed to be completely unused + * bwcp->bwc_curp = ((uint8_t)val & mask) << (8 - remainder_bits_after_full_bytes); + + // consume part of the byte + bwcp->bwc_used = remainder_bits_after_full_bytes; + } +} + +void +compressed_pack(compreg_t const * i_regp, + size_t i_width, + size_t i_nregs, + uint8_t * o_bitp, + size_t i_size, + uint8_t i_vers) +{ + size_t bitsz; + size_t padsz; + + bitstream_write_cursor_t bwc; + + // We need to zero the output array because we use + // an bitwise-or-accumulator below. + errno_t rc = memset_s(o_bitp, i_size, '\0', i_size); + securec_check(rc, "\0", "\0"); + + bitsz = i_width * i_nregs; + + // Fail fast if the compressed array isn't big enough. + if (i_size * 8 < bitsz) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("compressed output buffer not large enough"))); + + padsz = i_size * 8 - bitsz; + + // Fail fast if the pad size doesn't make sense. + if (padsz >= 8) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistent compressed output pad size"))); + + bwc.bwc_nbits = i_width; + bwc.bwc_curp = o_bitp; + bwc.bwc_used = 0; + + for (size_t ndx = 0; ndx < i_nregs; ++ndx) + bitstream_pack(&bwc, i_regp[ndx]); +} + +void +sparse_pack(compreg_t const * i_regp, + size_t i_width, + size_t i_nregs, + size_t i_log2nregs, + size_t i_nfilled, + uint8_t * o_bitp, + size_t i_size) +{ + size_t bitsz; + size_t padsz; + + bitstream_write_cursor_t bwc; + + // We need to zero the output array because we use + // an bitwise-or-accumulator below. + errno_t rc = memset_s(o_bitp, i_size, '\0', i_size); + securec_check(rc, "\0", "\0"); + + bitsz = i_nfilled * (i_log2nregs + i_width); + + // Fail fast if the compressed array isn't big enough. + if (i_size * 8 < bitsz) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("sparse output buffer not large enough"))); + + padsz = i_size * 8 - bitsz; + + // Fail fast if the pad size doesn't make sense. + if (padsz >= 8) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistent sparse output pad size"))); + + bwc.bwc_nbits = i_log2nregs + i_width; + bwc.bwc_curp = o_bitp; + bwc.bwc_used = 0; + + for (size_t ndx = 0; ndx < i_nregs; ++ndx) + { + if (i_regp[ndx] != 0) + { + uint32_t buffer = (ndx << i_width) | i_regp[ndx]; + bitstream_pack(&bwc, buffer); + } + } +} + +void +check_metadata(multiset_t const * i_omp, multiset_t const * i_imp) +{ + if (i_omp->ms_nbits != i_imp->ms_nbits) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("register width does not match: " + "source uses %zu and dest uses %zu", + i_imp->ms_nbits, i_omp->ms_nbits))); + } + + if (i_omp->ms_nregs != i_imp->ms_nregs) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("register count does not match: " + "source uses %zu and dest uses %zu", + i_imp->ms_nregs, i_omp->ms_nregs))); + } + + // Don't need to compare log2nregs because we compared nregs ... + + if (i_omp->ms_expthresh != i_imp->ms_expthresh) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("explicit threshold does not match: " + "source uses " INT64_FORMAT " and dest uses " INT64_FORMAT, + i_imp->ms_expthresh, i_omp->ms_expthresh))); + } + + if (i_omp->ms_sparseon != i_imp->ms_sparseon) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("sparse enable does not match: " + "source uses %d and dest uses %d", + i_imp->ms_sparseon, i_omp->ms_sparseon))); + } +} + +void +copy_metadata(multiset_t * o_msp, multiset_t const * i_msp) +{ + o_msp->ms_nbits = i_msp->ms_nbits; + o_msp->ms_nregs = i_msp->ms_nregs; + o_msp->ms_log2nregs = i_msp->ms_log2nregs; + o_msp->ms_expthresh = i_msp->ms_expthresh; + o_msp->ms_sparseon = i_msp->ms_sparseon; +} + +void +compressed_add(multiset_t * o_msp, uint64_t elem) +{ + size_t nbits = o_msp->ms_nbits; + size_t nregs = o_msp->ms_nregs; + size_t log2nregs = o_msp->ms_log2nregs; + + ms_compressed_t * mscp = &o_msp->ms_data.as_comp; + + uint64_t mask = nregs - 1; + + size_t maxregval = (1 << nbits) - 1; + + size_t ndx = elem & mask; + + uint64_t ss_val = elem >> log2nregs; + + size_t p_w = ss_val == 0 ? 0 : __builtin_ctzll(ss_val) + 1; + + if (p_w > maxregval) + p_w = maxregval; + + if (mscp->msc_regs[ndx] < p_w) + mscp->msc_regs[ndx] = p_w; +} + +void +compressed_explicit_union(multiset_t * o_msp, multiset_t const * i_msp) +{ + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + for (size_t ii = 0; ii < msep->mse_nelem; ++ii) + compressed_add(o_msp, msep->mse_elems[ii]); +} + +void +explicit_to_compressed(multiset_t * msp) +{ + // Make a copy of the explicit multiset. + multiset_t ms; + errno_t rc; + + rc = memcpy_s(&ms, sizeof(ms), msp, sizeof(ms)); + securec_check(rc, "\0", "\0"); + + // Clear the multiset. + rc = memset_s(msp, sizeof(*msp), '\0', sizeof(*msp)); + securec_check(rc, "\0", "\0"); + + // Restore the metadata. + copy_metadata(msp, &ms); + + // Make it MST_COMPRESSED. + msp->ms_type = MST_COMPRESSED; + + // Add all the elements back into the compressed multiset. + compressed_explicit_union(msp, &ms); +} + +int +element_compare(void const * ptr1, void const * ptr2) +{ + // We used signed integer comparison to be compatible + // with the java code. + + int64_t v1 = * (int64_t const *) ptr1; + int64_t v2 = * (int64_t const *) ptr2; + + return (v1 < v2) ? -1 : (v1 > v2) ? 1 : 0; +} + +size_t numfilled(multiset_t const * i_msp) +{ + ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; + size_t nfilled = 0; + size_t nregs = i_msp->ms_nregs; + for (size_t ii = 0; ii < nregs; ++ii) + if (mscp->msc_regs[ii] > 0) + ++nfilled; + + return nfilled; +} + +char * +multiset_tostring(multiset_t const * i_msp) +{ + char expbuf[256]; + char * retstr = NULL; + size_t len; + size_t used; + size_t nbits = i_msp->ms_nbits; + size_t nregs = i_msp->ms_nregs; + int64 expthresh = i_msp->ms_expthresh; + size_t sparseon = i_msp->ms_sparseon; + + size_t expval = expthresh_value(expthresh, nbits, nregs); + + // If the expthresh is set to -1 (auto) augment the value + // with the automatically determined value. + // + errno_t rc; + if (expthresh == -1) + rc = snprintf_s(expbuf, sizeof(expbuf), sizeof(expbuf) - 1, INT64_FORMAT "(%zu)", expthresh, expval); + else + rc = snprintf_s(expbuf, sizeof(expbuf), sizeof(expbuf) - 1, INT64_FORMAT, expthresh); + + securec_check_ss(rc, "\0", "\0"); + // Allocate an initial return buffer. + len = 1024; + retstr = (char *) palloc0(len); + rc = memset_s(retstr, len, '\0', len); + securec_check(rc, "\0", "\0"); + + // We haven't used any return buffer yet. + used = 0; + + // Print in a type-dependent way. + switch (i_msp->ms_type) + { + case MST_EMPTY: + used += snprintf(retstr, len, "EMPTY, " + "nregs=%zu, nbits=%zu, expthresh=%s, sparseon=%zu", + nregs, nbits, expbuf, sparseon); + break; + case MST_EXPLICIT: + { + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + size_t size = msep->mse_nelem; + char linebuf[1024]; + ssize_t rv; + + used += snprintf(retstr, len, "EXPLICIT, %zu elements, " + "nregs=%zu, nbits=%zu, " + "expthresh=%s, sparseon=%zu:", + size, nregs, nbits, expbuf, sparseon); + for (size_t ii = 0; ii < size; ++ii) + { + int64 val = * (int64 const *) & msep->mse_elems[ii]; + rv = snprintf(linebuf, sizeof(linebuf), + "\n%zu: %20ld ", + ii, val); + // Do we need to reallocate the return buffer? + if (rv + used > len - 1) + { + len += 1024; + retstr = (char *) repalloc(retstr, len); + } + rc = strncpy_s(&retstr[used], len, linebuf, len - used); + securec_check(rc, "\0", "\0"); + used += rv; + } + } + break; + case MST_COMPRESSED: + { + ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; + + char linebuf[1024] = {0}; + + size_t rowsz = 32; + size_t nrows = nregs / rowsz; + size_t ndx = 0; + + used += snprintf(retstr, len, + "COMPRESSED, %zu filled " + "nregs=%zu, nbits=%zu, expthresh=%s, " + "sparseon=%zu:", + numfilled(i_msp), + nregs, nbits, expbuf, sparseon); + + for (size_t rr = 0; rr < nrows; ++rr) + { + size_t pos = 0; + pos = snprintf(linebuf, sizeof(linebuf), "\n%4zu: ", ndx); + for (size_t cc = 0; cc < rowsz; ++cc) + { + pos += snprintf(&linebuf[pos], sizeof(linebuf) - pos, + "%2d ", mscp->msc_regs[ndx]); + ++ndx; + } + + // Do we need to reallocate the return buffer? + if (pos + used > len - 1) + { + len += 1024; + retstr = (char *) repalloc(retstr, len); + } + errno_t rc = strncpy_s(&retstr[used], len - used + 1, linebuf, len - used); + securec_check(rc, "\0", "\0"); + + used += pos; + } + } + break; + case MST_UNDEFINED: + used += snprintf(retstr, len, "UNDEFINED " + "nregs=%zu, nbits=%zu, expthresh=%s, sparseon=%zu", + nregs, nbits, expbuf, sparseon); + break; + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unexpected multiset type value"))); + break; + } + + return retstr; +} + +void +explicit_validate(multiset_t const * i_msp, ms_explicit_t const * i_msep) +{ + // Allow explicit multisets with no elements. + if (i_msep->mse_nelem == 0) + return; + + // Confirm that all elements are ascending with no duplicates. + for (size_t ii = 0; ii < i_msep->mse_nelem - 1; ++ii) + { + if (element_compare(&i_msep->mse_elems[ii], + &i_msep->mse_elems[ii + 1]) != -1) + { + char * buf = multiset_tostring(i_msp); + + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("duplicate or descending explicit elements: %s", + buf))); + + pfree(buf); + } + } +} + +size_t +upper_bound(const uint64_t elements[], size_t n, uint64_t value) +{ + size_t low = 0; + size_t high = n; + + while (low < high) + { + size_t middle = low + (high - low) / 2; + int cmp = element_compare(&value, &elements[middle]); + if (cmp == 0) { + low = high = middle; + } + else if (cmp > 0) { + low = middle + 1; + } + else { + high = middle; + } + } + return low; +} + +void +multiset_add(multiset_t * o_msp, uint64_t element) +{ + // WARNING! This routine can change the type of the multiset! + + size_t expval = expthresh_value(o_msp->ms_expthresh, + o_msp->ms_nbits, + o_msp->ms_nregs); + + switch (o_msp->ms_type) + { + case MST_EMPTY: + // Are we forcing compressed? + if (expval == 0) + { + // Now we're explicit with no elements. + o_msp->ms_type = MST_EXPLICIT; + o_msp->ms_data.as_expl.mse_nelem = 0; + + // Convert it to compressed. + explicit_to_compressed(o_msp); + + // Add the element in compressed format. + compressed_add(o_msp, element); + } + else + { + // Now we're explicit with one element. + o_msp->ms_type = MST_EXPLICIT; + o_msp->ms_data.as_expl.mse_nelem = 1; + o_msp->ms_data.as_expl.mse_elems[0] = element; + } + break; + + case MST_EXPLICIT: + { + ms_explicit_t * msep = &o_msp->ms_data.as_expl; + size_t insert_pos = upper_bound(msep->mse_elems, msep->mse_nelem, element); + // If the element is already in the set we're done. + if (insert_pos < msep->mse_nelem && + element_compare(&element, &msep->mse_elems[insert_pos]) == 0) + { + return; + } + + // Is the explicit multiset full? + if (msep->mse_nelem == expval) + { + // Convert it to compressed. + explicit_to_compressed(o_msp); + + // Add the element in compressed format. + compressed_add(o_msp, element); + } + else + { + // If not at end, move all elements one step + if (insert_pos < msep->mse_nelem) + { + errno_t rc = memmove_s(&msep->mse_elems[insert_pos + 1], + (msep->mse_nelem - insert_pos) * sizeof(uint64_t), + &msep->mse_elems[insert_pos], + (msep->mse_nelem - insert_pos) * sizeof(uint64_t)); + securec_check(rc, "\0", "\0"); + } + // Actually add the element + msep->mse_nelem += 1; + msep->mse_elems[insert_pos] = element; + } + } + break; + + case MST_COMPRESSED: + compressed_add(o_msp, element); + break; + + case MST_UNDEFINED: + // Result is unchanged. + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #1"))); + break; + } +} + +void +explicit_union(multiset_t * o_msp, ms_explicit_t const * i_msep) +{ + // NOTE - This routine is optimized to add a batch of elements; + // it doesn't resort until they are all added ... + // + // WARNING! This routine can change the type of the target multiset! + + size_t expval = expthresh_value(o_msp->ms_expthresh, + o_msp->ms_nbits, + o_msp->ms_nregs); + + ms_explicit_t * msep = &o_msp->ms_data.as_expl; + + // Note the starting size of the target set. + size_t orig_nelem = msep->mse_nelem; + + for (size_t ii = 0; ii < i_msep->mse_nelem; ++ii) + { + uint64_t element = i_msep->mse_elems[ii]; + + switch (o_msp->ms_type) + { + case MST_EXPLICIT: + if (bsearch(&element, + msep->mse_elems, + orig_nelem, + sizeof(uint64_t), + element_compare)) + continue; + + if (msep->mse_nelem < expval) + { + // Add the element at the end. + msep->mse_elems[msep->mse_nelem++] = element; + } + else + { + // Convert it to compressed. + explicit_to_compressed(o_msp); + + // Add the element in compressed format. + compressed_add(o_msp, element); + } + break; + + case MST_COMPRESSED: + compressed_add(o_msp, element); + break; + } + } + + // If the target multiset is still explicit it needs to be + // resorted. + if (o_msp->ms_type == MST_EXPLICIT) + { + // Resort the elements. + qsort(msep->mse_elems, + msep->mse_nelem, + sizeof(uint64_t), + element_compare); + } +} + +void unpack_header(multiset_t * o_msp, + uint8_t const * i_bitp, + uint8_t vers, + uint8_t type) +{ + o_msp->ms_nbits = (i_bitp[1] >> 5) + 1; + o_msp->ms_log2nregs = i_bitp[1] & 0x1f; + o_msp->ms_nregs = 1 << o_msp->ms_log2nregs; + o_msp->ms_expthresh = decode_expthresh(i_bitp[2] & 0x3f); + o_msp->ms_sparseon = (i_bitp[2] >> 6) & 0x1; +} + +uint8_t +multiset_unpack(multiset_t * o_msp, + uint8_t const * i_bitp, + size_t i_size, + uint8_t * o_encoded_type) +{ + // First byte is the version and type header. + uint8_t vers = (i_bitp[0] >> 4) & 0xf; + uint8_t type = i_bitp[0] & 0xf; + + if (vers != 1) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unknown schema version %d", (int) vers))); + + if (o_encoded_type != NULL) + *o_encoded_type = type; + + // Set the type. NOTE - MST_SPARSE are converted to MST_COMPRESSED. + o_msp->ms_type = (type == MST_SPARSE) ? MST_COMPRESSED : type; + + switch (type) + { + case MST_EMPTY: + if (vers == 1) + { + size_t hdrsz = 3; + + // Make sure the size is consistent. + if (i_size != hdrsz) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistently sized empty multiset"))); + } + + unpack_header(o_msp, i_bitp, vers, type); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unsupported empty version %d", + (int) vers))); + } + + break; + + case MST_EXPLICIT: + if (vers == 1) + { + ms_explicit_t * msep = &o_msp->ms_data.as_expl; + size_t hdrsz = 3; + size_t nelem = (i_size - hdrsz) / 8; + size_t ndx = hdrsz; + + // Make sure the size is consistent. + if (((i_size - hdrsz) % 8) != 0) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistently sized explicit multiset"))); + } + + // Make sure the explicit array fits in memory. + if ((i_size - hdrsz) > MS_MAXDATA) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("explicit multiset too large"))); + } + + unpack_header(o_msp, i_bitp, vers, type); + + msep->mse_nelem = nelem; + for (size_t ii = 0; ii < nelem; ++ii) + { + uint64_t val = 0; + val |= ((uint64_t) i_bitp[ndx++] << 56); + val |= ((uint64_t) i_bitp[ndx++] << 48); + val |= ((uint64_t) i_bitp[ndx++] << 40); + val |= ((uint64_t) i_bitp[ndx++] << 32); + val |= ((uint64_t) i_bitp[ndx++] << 24); + val |= ((uint64_t) i_bitp[ndx++] << 16); + val |= ((uint64_t) i_bitp[ndx++] << 8); + val |= ((uint64_t) i_bitp[ndx++] << 0); + msep->mse_elems[ii] = val; + } + + explicit_validate(o_msp, msep); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unsupported explicit version %d", + (int) vers))); + } + break; + + case MST_COMPRESSED: + if (vers == 1) + { + size_t hdrsz = 3; + + // Decode the parameter byte. + uint8_t param = i_bitp[1]; + size_t nbits = (param >> 5) + 1; + size_t log2nregs = param & 0x1f; + size_t nregs = 1 << log2nregs; + + // Make sure the size is consistent. + size_t bitsz = nbits * nregs; + size_t packedbytesz = (bitsz + 7) / 8; + if ((i_size - hdrsz) != packedbytesz) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("inconsistently sized " + "compressed multiset"))); + } + + // Make sure the compressed array fits in memory. + if (nregs * sizeof(compreg_t) > MS_MAXDATA) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("compressed multiset too large"))); + } + + unpack_header(o_msp, i_bitp, vers, type); + + // Fill the registers. + compressed_unpack(o_msp->ms_data.as_comp.msc_regs, + nbits, nregs, &i_bitp[hdrsz], i_size - hdrsz, + vers); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unsupported compressed version %d", + (int) vers))); + } + break; + + case MST_UNDEFINED: + if (vers == 1) + { + size_t hdrsz = 3; + + // Make sure the size is consistent. + if (i_size != hdrsz) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset value"))); + } + + unpack_header(o_msp, i_bitp, vers, type); + } + else + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unsupported undefined version %d", + (int) vers))); + } + + break; + + case MST_SPARSE: + if (vers == 1) + { + size_t hdrsz = 3; + + ms_compressed_t * mscp = NULL; + + if (i_size < hdrsz) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("sparse multiset too small"))); + } + else + { + // Decode the parameter byte. + uint8_t param = i_bitp[1]; + size_t nbits = (param >> 5) + 1; + size_t log2nregs = param & 0x1f; + size_t nregs = 1 << log2nregs; + + // Figure out how many encoded registers are in the + // bitstream. We depend on the log2nregs + nbits being + // greater then the pad size so we aren't left with + // ambiguity in the final pad byte. + + size_t bitsz = (i_size - hdrsz) * 8; + size_t chunksz = log2nregs + nbits; + size_t nfilled = bitsz / chunksz; + + // Make sure the compressed array fits in memory. + if (nregs * sizeof(compreg_t) > MS_MAXDATA) + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("sparse multiset too large"))); + } + + unpack_header(o_msp, i_bitp, vers, type); + + mscp = &o_msp->ms_data.as_comp; + + // Pre-zero the registers since sparse only fills + // in occasional ones. + // + for (size_t ii = 0; ii < nregs; ++ii) + mscp->msc_regs[ii] = 0; + + // Fill the registers. + sparse_unpack(mscp->msc_regs, + nbits, log2nregs, nfilled, + &i_bitp[hdrsz], i_size - hdrsz); + } + } + else + { + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("unsupported sparse version %d", + (int) vers))); + } + break; + + default: + // This is always an error. + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type"))); + break; + } + + return vers; +} + +size_t +pack_header(uint8_t * o_bitp, + uint8_t vers, + uint8_t type, + size_t nbits, + size_t log2nregs, + int64 expthresh, + size_t sparseon) +{ + size_t ndx = 0; + + o_bitp[ndx++] = (vers << 4) | type; + o_bitp[ndx++] = ((nbits - 1) << 5) | log2nregs; + o_bitp[ndx++] = (sparseon << 6) | encode_expthresh(expthresh); + + return ndx; +} + +void +multiset_pack(multiset_t const * i_msp, uint8_t * o_bitp, size_t i_size) +{ + uint8_t vers = g_output_version; + + size_t nbits = i_msp->ms_nbits; + size_t log2nregs = i_msp->ms_log2nregs; + int64 expthresh = i_msp->ms_expthresh; + size_t sparseon = i_msp->ms_sparseon; + + switch (i_msp->ms_type) + { + case MST_EMPTY: + pack_header(o_bitp, vers, MST_EMPTY, + nbits, log2nregs, expthresh, sparseon); + break; + + case MST_EXPLICIT: + { + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + size_t size = msep->mse_nelem; + + size_t ndx = pack_header(o_bitp, vers, MST_EXPLICIT, + nbits, log2nregs, expthresh, sparseon); + + for (size_t ii = 0; ii < size; ++ii) + { + uint64_t val = msep->mse_elems[ii]; + + o_bitp[ndx++] = (val >> 56) & 0xff; + o_bitp[ndx++] = (val >> 48) & 0xff; + o_bitp[ndx++] = (val >> 40) & 0xff; + o_bitp[ndx++] = (val >> 32) & 0xff; + o_bitp[ndx++] = (val >> 24) & 0xff; + o_bitp[ndx++] = (val >> 16) & 0xff; + o_bitp[ndx++] = (val >> 8) & 0xff; + o_bitp[ndx++] = (val >> 0) & 0xff; + } + } + break; + + case MST_COMPRESSED: + { + ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; + size_t nregs = i_msp->ms_nregs; + size_t nfilled = numfilled(i_msp); + + // Should we pack this as MST_SPARSE or MST_COMPRESSED? + // IMPORTANT - matching code in multiset_packed_size! + size_t sparsebitsz; + size_t cmprssbitsz; + sparsebitsz = nfilled * (log2nregs + nbits); + cmprssbitsz = nregs * nbits; + + // If the vector does not have sparse enabled use + // compressed. + // + // If the vector is smaller then the max sparse size use + // compressed. + // + // If the max sparse size is auto (-1) use if smaller then + // compressed. + // + if (sparseon && + ((u_sess->attr.attr_sql.g_max_sparse != -1 && nfilled <= (size_t) u_sess->attr.attr_sql.g_max_sparse) || + (u_sess->attr.attr_sql.g_max_sparse == -1 && sparsebitsz < cmprssbitsz))) + { + size_t ndx = pack_header(o_bitp, vers, MST_SPARSE, + nbits, log2nregs, expthresh, sparseon); + + // Marshal the registers. + sparse_pack(mscp->msc_regs, + nbits, nregs, log2nregs, nfilled, + &o_bitp[ndx], i_size - ndx); + } + else + { + size_t ndx = pack_header(o_bitp, vers, MST_COMPRESSED, + nbits, log2nregs, expthresh, sparseon); + + // Marshal the registers. + compressed_pack(mscp->msc_regs, nbits, nregs, + &o_bitp[ndx], i_size - ndx, vers); + } + break; + } + + case MST_UNDEFINED: + pack_header(o_bitp, vers, MST_UNDEFINED, + nbits, log2nregs, expthresh, sparseon); + break; + + case MST_SPARSE: + // We only marshal (pack) into sparse format; complain if + // an in-memory multiset claims it is sparse. + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid internal sparse format"))); + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #2"))); + break; + } +} + +size_t +multiset_copy_size(multiset_t const * i_msp) +{ + size_t retval = 0; + + switch (i_msp->ms_type) + { + case MST_EMPTY: + retval = __builtin_offsetof(multiset_t, ms_data); + break; + + case MST_EXPLICIT: + { + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + retval = __builtin_offsetof(multiset_t, ms_data.as_expl.mse_elems); + retval += (msep->mse_nelem * sizeof(uint64_t)); + } + break; + + case MST_COMPRESSED: + { + retval = __builtin_offsetof(multiset_t, ms_data.as_comp.msc_regs); + retval += (i_msp->ms_nregs * sizeof(compreg_t)); + } + break; + + case MST_UNDEFINED: + retval = __builtin_offsetof(multiset_t, ms_data); + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #3"))); + break; + } + + return retval; +} + +size_t +multiset_packed_size(multiset_t const * i_msp) +{ + uint8_t vers = g_output_version; + + size_t retval = 0; + + switch (i_msp->ms_type) + { + case MST_EMPTY: + switch (vers) + { + case 1: + retval = 3; + break; + default: + Assert(vers == 1); + } + break; + + case MST_EXPLICIT: + switch (vers) + { + case 1: + { + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + retval = 3 + (8 * msep->mse_nelem); + } + break; + default: + Assert(vers == 1); + } + break; + + case MST_COMPRESSED: + if (vers == 1) + { + size_t hdrsz = 3; + size_t nbits = i_msp->ms_nbits; + size_t nregs = i_msp->ms_nregs; + size_t nfilled = numfilled(i_msp); + size_t log2nregs = i_msp->ms_log2nregs; + size_t sparseon = i_msp->ms_sparseon; + size_t sparsebitsz; + size_t cmprssbitsz; + + // Should we pack this as MST_SPARSE or MST_COMPRESSED? + // IMPORTANT - matching code in multiset_pack! + // + sparsebitsz = numfilled(i_msp) * (log2nregs + nbits); + cmprssbitsz = nregs * nbits; + + // If the vector does not have sparse enabled use + // compressed. + // + // If the vector is smaller then the max sparse size use + // compressed. + // + // If the max sparse size is auto (-1) use if smaller then + // compressed. + // + if (sparseon && + ((u_sess->attr.attr_sql.g_max_sparse != -1 && nfilled <= (size_t) u_sess->attr.attr_sql.g_max_sparse) || + (u_sess->attr.attr_sql.g_max_sparse == -1 && sparsebitsz < cmprssbitsz))) + + { + // MST_SPARSE is more compact. + retval = hdrsz + ((sparsebitsz + 7) / 8); + } + else + { + // MST_COMPRESSED is more compact. + retval = hdrsz + ((cmprssbitsz + 7) / 8); + } + } + else + { + Assert(vers == 1); + } + break; + + case MST_UNDEFINED: + if (vers == 1) + { + size_t hdrsz = 3; + retval = hdrsz; + } + else + { + Assert(vers == 1); + } + break; + + case MST_SPARSE: + // We only marshal (pack) into sparse format; complain if + // an in-memory multiset claims it is sparse. + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("invalid internal sparse format"))); + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #4"))); + break; + } + + return retval; +} + +PG_FUNCTION_INFO_V1(hll_in); +Datum hll_in(PG_FUNCTION_ARGS); +Datum +hll_in(PG_FUNCTION_ARGS) +{ + Datum dd = DirectFunctionCall1(byteain, PG_GETARG_DATUM(0)); + + int32 typmod = PG_GETARG_INT32(2); + + // Unpack to make sure the data is valid. + bytea * bp = DatumGetByteaP(dd); + size_t sz = VARSIZE(bp) - VARHDRSZ; + multiset_t ms; + multiset_unpack(&ms, (uint8_t *) VARDATA(bp), sz, NULL); + + // The typmod value will be valid for COPY and \COPY statements. + // Check the metadata consistency in these cases. + if (typmod != -1) + { + int32 log2m = typmod_log2m(typmod); + int32 regwidth = typmod_regwidth(typmod); + int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); + int32 sparseon = typmod_sparseon(typmod); + + // Create a placeholder w/ declared metadata. + multiset_t msx; + msx.ms_nbits = regwidth; + msx.ms_nregs = (1 << log2m); + msx.ms_log2nregs = log2m; + msx.ms_expthresh = expthresh; + msx.ms_sparseon = sparseon; + + // Make sure the declared metadata matches the incoming. + check_metadata(&msx, &ms); + } + + return dd; +} + +PG_FUNCTION_INFO_V1(hll_out); +Datum hll_out(PG_FUNCTION_ARGS); +Datum +hll_out(PG_FUNCTION_ARGS) +{ + // NOTE - It's still worth interposing on these calls in case + // we want to support alternate representations in the future. + + Datum dd = DirectFunctionCall1(byteaout, PG_GETARG_DATUM(0)); + return dd; +} + +PG_FUNCTION_INFO_V1(hll); +Datum hll(PG_FUNCTION_ARGS); +Datum +hll(PG_FUNCTION_ARGS) +{ + Datum dd = PG_GETARG_DATUM(0); + bytea * bp = DatumGetByteaP(dd); + size_t sz = VARSIZE(bp) - VARHDRSZ; + int32 typmod = PG_GETARG_INT32(1); // !! DIFFERENT THEN IN hll_in! + bool isexplicit = PG_GETARG_BOOL(2); // explicit cast, not explicit vector + int32 log2m = typmod_log2m(typmod); + int32 regwidth = typmod_regwidth(typmod); + int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); + int32 sparseon = typmod_sparseon(typmod); + + multiset_t ms; + multiset_t msx; + + // Unpack the bit data. + multiset_unpack(&ms, (uint8_t *) VARDATA(bp), sz, NULL); + + // Make the compiler happpy. + (void) isexplicit; + + // Create a placeholder w/ declared metadata. + msx.ms_nbits = regwidth; + msx.ms_nregs = (1 << log2m); + msx.ms_log2nregs = log2m; + msx.ms_expthresh = expthresh; + msx.ms_sparseon = sparseon; + + // Make sure the declared metadata matches the incoming. + check_metadata(&msx, &ms); + + // If we make it here we're good. + return dd; +} + +PG_FUNCTION_INFO_V1(hll_hashval_in); +Datum hll_hashval_in(PG_FUNCTION_ARGS); +Datum +hll_hashval_in(PG_FUNCTION_ARGS) +{ + Datum dd = DirectFunctionCall1(int8in, PG_GETARG_DATUM(0)); + return dd; +} + +PG_FUNCTION_INFO_V1(hll_hashval_out); +Datum hll_hashval_out(PG_FUNCTION_ARGS); +Datum +hll_hashval_out(PG_FUNCTION_ARGS) +{ + Datum dd = DirectFunctionCall1(int8out, PG_GETARG_DATUM(0)); + return dd; +} + +PG_FUNCTION_INFO_V1(hll_hashval_eq); +Datum hll_hashval_eq(PG_FUNCTION_ARGS); +Datum +hll_hashval_eq(PG_FUNCTION_ARGS) +{ + int64 aa = PG_GETARG_INT64(0); + int64 bb = PG_GETARG_INT64(1); + PG_RETURN_BOOL(aa == bb); +} + +PG_FUNCTION_INFO_V1(hll_hashval_ne); +Datum hll_hashval_ne(PG_FUNCTION_ARGS); +Datum +hll_hashval_ne(PG_FUNCTION_ARGS) +{ + int64 aa = PG_GETARG_INT64(0); + int64 bb = PG_GETARG_INT64(1); + PG_RETURN_BOOL(aa != bb); +} + +PG_FUNCTION_INFO_V1(hll_hashval); +Datum hll_hashval(PG_FUNCTION_ARGS); +Datum +hll_hashval(PG_FUNCTION_ARGS) +{ + int64 aa = PG_GETARG_INT64(0); + PG_RETURN_INT64(aa); +} + +PG_FUNCTION_INFO_V1(hll_hashval_int4); +Datum hll_hashval_int4(PG_FUNCTION_ARGS); +Datum +hll_hashval_int4(PG_FUNCTION_ARGS) +{ + int32 aa = PG_GETARG_INT32(0); + int64 aaaa = aa; // extend value to 64 bits. + PG_RETURN_INT64(aaaa); +} + +void +check_modifiers(int32 log2m, int32 regwidth, int64 expthresh, int32 sparseon) +{ + // Range check each of the modifiers. + if (log2m < 0 || log2m > MAX_BITVAL(LOG2M_BITS)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("log2m modifier must be between 0 and 31"))); + + if (regwidth < 0 || regwidth > MAX_BITVAL(REGWIDTH_BITS)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("regwidth modifier must be between 0 and 7"))); + + if (expthresh < -1 || expthresh > 4294967296LL) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("expthresh modifier must be between -1 and 2^32"))); + + if (expthresh > 0 && (1LL << integer_log2(expthresh)) != expthresh) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("expthresh modifier must be power of 2"))); + + if (sparseon < 0 || sparseon > MAX_BITVAL(SPARSEON_BITS)) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("sparseon modifier must be 0 or 1"))); +} + +// This routine is cloned from the arrayutils ArrayGetIntegerTypmods +// and converted to return 64 bit integers. +// +int64 * +ArrayGetInteger64Typmods(ArrayType *arr, int *n) +{ + int64 *result = NULL; + Datum *elem_values = NULL; + int i; + + if (ARR_ELEMTYPE(arr) != CSTRINGOID) + ereport(ERROR, + (errcode(ERRCODE_ARRAY_ELEMENT_ERROR), + errmsg("typmod array must be type cstring[]"))); + + if (ARR_NDIM(arr) != 1) + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("typmod array must be one-dimensional"))); + + if (array_contains_nulls(arr)) + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("typmod array must not contain nulls"))); + + /* hardwired knowledge about cstring's representation details here */ + deconstruct_array(arr, CSTRINGOID, + -2, false, 'c', + &elem_values, NULL, n); + + result = (int64 *) palloc(*n * sizeof(int64)); + + for (i = 0; i < *n; i++) + { + char * endp = NULL; + result[i] = strtoll(DatumGetCString(elem_values[i]), &endp, 0); + if (*endp != '\0') + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("typmod array must contain integers"))); + } + + pfree(elem_values); + + return result; +} + +PG_FUNCTION_INFO_V1(hll_typmod_in); +Datum hll_typmod_in(PG_FUNCTION_ARGS); +Datum +hll_typmod_in(PG_FUNCTION_ARGS) +{ + ArrayType * ta = PG_GETARG_ARRAYTYPE_P(0); + int64 *tl = NULL; + int nmods; + int32 typmod; + int32 log2m; + int32 regwidth; + int64 expthresh; + int32 sparseon; + + tl = ArrayGetInteger64Typmods(ta, &nmods); + + // Make sure the number of type modifiers is in a valid range. + if (nmods > 4 || nmods < 0) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid number of type modifiers"))); + typmod = 0; /* keep compiler quiet */ + } + else + { + // Process the type modifiers, supply defaults if necessary. + log2m = (nmods >= 1) ? tl[0] : u_sess->attr.attr_sql.g_default_log2m; + regwidth = (nmods >= 2) ? tl[1] : u_sess->attr.attr_sql.g_default_regwidth; + expthresh = (nmods >= 3) ? tl[2] : u_sess->attr.attr_sql.g_default_expthresh; + sparseon = (nmods == 4) ? tl[3] : u_sess->attr.attr_sql.g_default_sparseon; + + check_hll_para_range(log2m, regwidth, expthresh, sparseon); + expthresh = integer_exp2(expthresh); + check_modifiers(log2m, regwidth, expthresh, sparseon); + + // Construct the typmod value. + typmod = + (log2m << (TYPMOD_BITS - LOG2M_BITS)) | + (regwidth << (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS)) | + (encode_expthresh(expthresh) << + (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS - + EXPTHRESH_BITS)) | + (sparseon << (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS - + EXPTHRESH_BITS - SPARSEON_BITS)); + } + + PG_RETURN_INT32(typmod); +} + +PG_FUNCTION_INFO_V1(hll_typmod_out); +Datum hll_typmod_out(PG_FUNCTION_ARGS); +Datum +hll_typmod_out(PG_FUNCTION_ARGS) +{ + int32 typmod = (uint32) PG_GETARG_INT32(0); + int32 log2m = typmod_log2m(typmod); + int32 regwidth = typmod_regwidth(typmod); + int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); + int32 sparseon = typmod_sparseon(typmod); + + char buffer[1024]; + size_t len; + char * typmodstr = NULL; + + errno_t rc = memset_s(buffer, sizeof(buffer), '\0', sizeof(buffer)); + securec_check(rc, "\0", "\0"); + snprintf(buffer, sizeof(buffer), "(%d,%d," INT64_FORMAT ",%d)", + log2m, regwidth, expthresh, sparseon); + + len = strlen(buffer) + 1; + typmodstr = (char *) palloc0(len); + rc = strncpy_s(typmodstr, len, buffer, len - 1); + securec_check(rc, "\0", "\0"); + + PG_RETURN_CSTRING(typmodstr); +} + +void +multiset_union(multiset_t * o_msap, multiset_t const * i_msbp) +{ + int typea = o_msap->ms_type; + int typeb = i_msbp->ms_type; + + // If either multiset is MST_UNDEFINED result is MST_UNDEFINED. + if (typea == MST_UNDEFINED || typeb == MST_UNDEFINED) + { + o_msap->ms_type = MST_UNDEFINED; + return; + } + + // If B is MST_EMPTY, we're done, A is unchanged. + if (typeb == MST_EMPTY) + return; + + // If A is MST_EMPTY, return B instead. + if (typea == MST_EMPTY) + { + errno_t rc = memcpy_s(o_msap, sizeof(*o_msap), i_msbp, multiset_copy_size(i_msbp)); + securec_check(rc, "\0", "\0"); + + return; + } + + switch (typea) + { + case MST_EXPLICIT: + { + switch (typeb) + { + case MST_EXPLICIT: + { + ms_explicit_t const * msebp = + (ms_explicit_t const *) &i_msbp->ms_data.as_expl; + + // Note - we may not be explicit after this ... + explicit_union(o_msap, msebp); + } + break; + + case MST_COMPRESSED: + { + // Make a copy of B since we can't modify it in place. + multiset_t mst; + errno_t rc = memcpy_s(&mst, sizeof(mst), i_msbp, multiset_copy_size(i_msbp)); + securec_check(rc, "\0", "\0"); + // Union into the copy. + compressed_explicit_union(&mst, o_msap); + // Copy the result over the A argument. + rc = memcpy_s(o_msap, sizeof(*o_msap), &mst, multiset_copy_size(&mst)); + securec_check(rc, "\0", "\0"); + } + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #5"))); + break; + } + } + break; + + case MST_COMPRESSED: + { + ms_compressed_t * mscap = + (ms_compressed_t *) &o_msap->ms_data.as_comp; + + switch (typeb) + { + case MST_EXPLICIT: + { + compressed_explicit_union(o_msap, i_msbp); + } + break; + + case MST_COMPRESSED: + { + ms_compressed_t const * mscbp = + (ms_compressed_t const *) &i_msbp->ms_data.as_comp; + + // The compressed vectors must be the same length. + if (o_msap->ms_nregs != i_msbp->ms_nregs) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("union of differently length " + "compressed vectors not supported"))); + + for (unsigned ii = 0; ii < o_msap->ms_nregs; ++ii) + { + if (mscap->msc_regs[ii] < mscbp->msc_regs[ii]) + mscap->msc_regs[ii] = mscbp->msc_regs[ii]; + } + } + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #6"))); + break; + } + } + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #7"))); + break; + } +} + +double gamma_register_count_squared(int nregs); +double +gamma_register_count_squared(int nregs) +{ + if (nregs <= 8) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("number of registers too small"))); + + switch (nregs) + { + case 16: return 0.673 * nregs * nregs; + case 32: return 0.697 * nregs * nregs; + case 64: return 0.709 * nregs * nregs; + default: return (0.7213 / (1.0 + 1.079 / nregs)) * nregs * nregs; + } +} + +double +multiset_card(multiset_t const * i_msp) +{ + size_t nbits = i_msp->ms_nbits; + size_t log2m = i_msp->ms_log2nregs; + + double retval = 0.0; + + uint64 max_register_value = (1ULL << nbits) - 1; + uint64 pw_bits = (max_register_value - 1); + uint64 total_bits = (pw_bits + log2m); + uint64 two_to_l = (1ULL << total_bits); + + double large_estimator_cutoff = (double) two_to_l/30.0; + + switch (i_msp->ms_type) + { + case MST_EMPTY: + retval = 0.0; + break; + + case MST_EXPLICIT: + { + ms_explicit_t const * msep = &i_msp->ms_data.as_expl; + return msep->mse_nelem; + } + break; + + case MST_COMPRESSED: + { + unsigned ii; + double sum; + int zero_count; + uint64_t rval; + double estimator; + + ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; + size_t nregs = i_msp->ms_nregs; + + sum = 0.0; + zero_count = 0; + + for (ii = 0; ii < nregs; ++ii) + { + rval = mscp->msc_regs[ii]; + sum += 1.0 / (1L << rval); + if (rval == 0) + ++zero_count; + } + + estimator = gamma_register_count_squared(nregs) / sum; + + if ((zero_count != 0) && (estimator < (5.0 * nregs / 2.0))) + retval = nregs * log((double) nregs / zero_count); + else if (estimator <= large_estimator_cutoff) + retval = estimator; + else + return (-1 * (int64_t)two_to_l) * log(1.0 - (estimator/two_to_l)); + } + break; + + case MST_UNDEFINED: + // Our caller will convert this to a NULL. + retval = -1.0; + break; + + default: + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("undefined multiset type value #8"))); + break; + } + + return retval; +} + +// Cardinality of a multiset. +// +PG_FUNCTION_INFO_V1(hll_cardinality); +Datum hll_cardinality(PG_FUNCTION_ARGS); +Datum +hll_cardinality(PG_FUNCTION_ARGS) +{ + double retval = 0.0; + + bytea *ab = NULL; + size_t asz; + multiset_t ms; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + multiset_unpack(&ms, (uint8_t *) VARDATA(ab), asz, NULL); + + retval = multiset_card(&ms); + + if (retval == -1.0) + PG_RETURN_NULL(); + else + PG_RETURN_FLOAT8(retval); +} + +// Union of a pair of multiset. +// +PG_FUNCTION_INFO_V1(hll_union); +Datum hll_union(PG_FUNCTION_ARGS); +Datum +hll_union(PG_FUNCTION_ARGS) +{ + bytea * ab = NULL; + size_t asz; + bytea * bb = NULL; + size_t bsz; + + bytea * cb = NULL; + size_t csz; + + multiset_t msa; + multiset_t msb; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + bb = PG_GETARG_BYTEA_P(1); + bsz = VARSIZE(bb) - VARHDRSZ; + + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + multiset_unpack(&msb, (uint8_t *) VARDATA(bb), bsz, NULL); + + check_metadata(&msa, &msb); + + multiset_union(&msa, &msb); + + csz = multiset_packed_size(&msa); + cb = (bytea *) palloc(VARHDRSZ + csz); + SET_VARSIZE(cb, VARHDRSZ + csz); + + multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); + + PG_RETURN_BYTEA_P(cb); +} + +// Add an integer hash to a multiset. +// +PG_FUNCTION_INFO_V1(hll_add); +Datum hll_add(PG_FUNCTION_ARGS); +Datum +hll_add(PG_FUNCTION_ARGS) +{ + bytea * ab = NULL; + size_t asz; + int64 val; + + bytea * cb = NULL; + size_t csz; + + multiset_t msa; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + val = PG_GETARG_INT64(1); + + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + multiset_add(&msa, val); + + csz = multiset_packed_size(&msa); + cb = (bytea *) palloc(VARHDRSZ + csz); + SET_VARSIZE(cb, VARHDRSZ + csz); + + multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); + + PG_RETURN_BYTEA_P(cb); +} + +// Add a multiset to an integer hash. +// +PG_FUNCTION_INFO_V1(hll_add_rev); +Datum hll_add_rev(PG_FUNCTION_ARGS); +Datum +hll_add_rev(PG_FUNCTION_ARGS) +{ + bytea * ab = NULL; + size_t asz; + int64 val; + + bytea * cb = NULL; + size_t csz; + + multiset_t msa; + + val = PG_GETARG_INT64(0); + + ab = PG_GETARG_BYTEA_P(1); + asz = VARSIZE(ab) - VARHDRSZ; + + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + multiset_add(&msa, val); + + csz = multiset_packed_size(&msa); + cb = (bytea *) palloc(VARHDRSZ + csz); + SET_VARSIZE(cb, VARHDRSZ + csz); + + multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); + + PG_RETURN_BYTEA_P(cb); +} + +// Pretty-print a multiset +// +PG_FUNCTION_INFO_V1(hll_print); +Datum hll_print(PG_FUNCTION_ARGS); +Datum +hll_print(PG_FUNCTION_ARGS) +{ + bytea * ab = NULL; + size_t asz; + char * retstr = NULL; + multiset_t msa; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + retstr = multiset_tostring(&msa); + + PG_RETURN_CSTRING(retstr); +} + +// Create an empty multiset with parameters. +// +PG_FUNCTION_INFO_V1(hll_empty0); +Datum hll_empty0(PG_FUNCTION_ARGS); +Datum +hll_empty0(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, + Int32GetDatum(u_sess->attr.attr_sql.g_default_log2m), + Int32GetDatum(u_sess->attr.attr_sql.g_default_regwidth), + Int64GetDatum(u_sess->attr.attr_sql.g_default_expthresh), + Int32GetDatum(u_sess->attr.attr_sql.g_default_sparseon))); +} + +// Create an empty multiset with parameters. +// +PG_FUNCTION_INFO_V1(hll_empty1); +Datum hll_empty1(PG_FUNCTION_ARGS); +Datum +hll_empty1(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, + PG_GETARG_DATUM(0), + Int32GetDatum(u_sess->attr.attr_sql.g_default_regwidth), + Int64GetDatum(u_sess->attr.attr_sql.g_default_expthresh), + Int32GetDatum(u_sess->attr.attr_sql.g_default_sparseon))); +} + +// Create an empty multiset with parameters. +// +PG_FUNCTION_INFO_V1(hll_empty2); +Datum hll_empty2(PG_FUNCTION_ARGS); +Datum +hll_empty2(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1), + Int64GetDatum(u_sess->attr.attr_sql.g_default_expthresh), + Int32GetDatum(u_sess->attr.attr_sql.g_default_sparseon))); +} + +// Create an empty multiset with parameters. +// +PG_FUNCTION_INFO_V1(hll_empty3); +Datum hll_empty3(PG_FUNCTION_ARGS); +Datum +hll_empty3(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(2), + Int32GetDatum(u_sess->attr.attr_sql.g_default_sparseon))); +} + +// Create an empty multiset with parameters. +// +PG_FUNCTION_INFO_V1(hll_empty4); +Datum hll_empty4(PG_FUNCTION_ARGS); +Datum +hll_empty4(PG_FUNCTION_ARGS) +{ + bytea * cb = NULL; + size_t csz; + + int32 log2m = PG_GETARG_INT32(0); + int32 regwidth = PG_GETARG_INT32(1); + int64 expthresh = PG_GETARG_INT64(2); + int32 sparseon = PG_GETARG_INT32(3); + + /* check all parameters of hll*/ + check_hll_para_range(log2m, regwidth, expthresh, sparseon); + expthresh = integer_exp2(expthresh); + + multiset_t ms; + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + errno_t rc = memset_s(&ms, sizeof(ms), '\0', sizeof(ms)); + securec_check(rc, "\0", "\0"); + + ms.ms_type = MST_EMPTY; + ms.ms_nbits = regwidth; + ms.ms_nregs = 1 << (unsigned int)log2m; + ms.ms_log2nregs = log2m; + ms.ms_expthresh = expthresh; + ms.ms_sparseon = sparseon; + + csz = multiset_packed_size(&ms); + cb = (bytea *) palloc(VARHDRSZ + csz); + SET_VARSIZE(cb, VARHDRSZ + csz); + + multiset_pack(&ms, (uint8_t *) VARDATA(cb), csz); + + PG_RETURN_BYTEA_P(cb); +} + + + +// Returns the schema version of an hll. +// +PG_FUNCTION_INFO_V1(hll_schema_version); +Datum hll_schema_version(PG_FUNCTION_ARGS); +Datum +hll_schema_version(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + uint8_t vers; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + vers = multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + PG_RETURN_INT32(vers); +} + +// Returns the type of an hll. +// +PG_FUNCTION_INFO_V1(hll_type); +Datum hll_type(PG_FUNCTION_ARGS); +Datum +hll_type(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + uint8_t type; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, &type); + + PG_RETURN_INT32(type); +} + +// Returns the log2m of an hll. +// +PG_FUNCTION_INFO_V1(hll_log2m); +Datum hll_log2m(PG_FUNCTION_ARGS); +Datum +hll_log2m(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + PG_RETURN_INT32(msa.ms_log2nregs); +} + +// Returns the regwidth of an hll. +// +PG_FUNCTION_INFO_V1(hll_regwidth); +Datum hll_regwidth(PG_FUNCTION_ARGS); +Datum +hll_regwidth(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + PG_RETURN_INT32(msa.ms_nbits); +} + +// Returns the expthresh of an hll. +// +PG_FUNCTION_INFO_V1(hll_expthresh); +Datum hll_expthresh(PG_FUNCTION_ARGS); +Datum +hll_expthresh(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + + size_t nbits; + size_t nregs; + int64 expthresh; + + int64 effective; + + Datum result; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + nbits = msa.ms_nbits; + nregs = msa.ms_nregs; + expthresh = msa.ms_expthresh; + + effective = expthresh_value(expthresh, nbits, nregs); + + // Build the result tuple. + { + TupleDesc tupleDesc; + int j; + char * values[2]; + HeapTuple tuple; + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupleDesc) != + TYPEFUNC_COMPOSITE) + ereport(ERROR, + (errmodule(MOD_OPT), + errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("return type must be a row type"))); + + j = 0; + + values[j] = (char *)palloc(32); + snprintf(values[j++], 32, INT64_FORMAT, expthresh); + values[j] = (char *)palloc(32); + snprintf(values[j++], 32, INT64_FORMAT, effective); + + tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), + values); + + result = HeapTupleGetDatum(tuple); + } + + PG_RETURN_DATUM(result); +} + +// Returns the sparseon of an hll. +// +PG_FUNCTION_INFO_V1(hll_sparseon); +Datum hll_sparseon(PG_FUNCTION_ARGS); +Datum +hll_sparseon(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + multiset_t msa; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + // Unpack the multiset. + multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); + + PG_RETURN_INT32(msa.ms_sparseon); +} + + + +// Hash a 1 byte fixed-size object. +// +PG_FUNCTION_INFO_V1(hll_set_output_version); +Datum hll_set_output_version(PG_FUNCTION_ARGS); +Datum +hll_set_output_version(PG_FUNCTION_ARGS) +{ + int32 old_vers = g_output_version; + int32 vers = PG_GETARG_INT32(0); + + if (vers != 1) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("output version must be 1"))); + + g_output_version = vers; + + PG_RETURN_INT32(old_vers); +} + +// Set sparse to full compressed threshold to fixed value. +// +PG_FUNCTION_INFO_V1(hll_set_max_sparse); +Datum hll_set_max_sparse(PG_FUNCTION_ARGS); +Datum +hll_set_max_sparse(PG_FUNCTION_ARGS) +{ + int32 old_maxsparse = g_max_sparse; + int32 maxsparse = PG_GETARG_INT32(0); + + if (maxsparse < -1) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("sparse threshold must be in range [-1,MAXINT]"))); + + g_max_sparse = maxsparse; + + PG_RETURN_INT32(old_maxsparse); +} + +// Change the default type modifier, empty and add aggregate defaults. +// +PG_FUNCTION_INFO_V1(hll_set_defaults); +Datum hll_set_defaults(PG_FUNCTION_ARGS); +Datum +hll_set_defaults(PG_FUNCTION_ARGS) +{ + int32 old_log2m = g_default_log2m; + int32 old_regwidth = g_default_regwidth; + int64 old_expthresh = g_default_expthresh; + int32 old_sparseon = g_default_sparseon; + + int32 log2m = PG_GETARG_INT32(0); + int32 regwidth = PG_GETARG_INT32(1); + int64 expthresh = PG_GETARG_INT64(2); + int32 sparseon = PG_GETARG_INT32(3); + + Datum result; + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + g_default_log2m = log2m; + g_default_regwidth = regwidth; + g_default_expthresh = expthresh; + g_default_sparseon = sparseon; + + // Build the result tuple. + { + TupleDesc tupleDesc; + int j; + char * values[4]; + HeapTuple tuple; + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupleDesc) != + TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + j = 0; + values[j] =(char *) palloc(32); + snprintf(values[j++], 32, "%d", old_log2m); + values[j] =(char *) palloc(32); + snprintf(values[j++], 32, "%d", old_regwidth); + values[j] =(char *) palloc(32); + snprintf(values[j++], 32, INT64_FORMAT, old_expthresh); + values[j] =(char *) palloc(32); + snprintf(values[j++], 32, "%d", old_sparseon); + + tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), + values); + + result = HeapTupleGetDatum(tuple); + } + + PG_RETURN_DATUM(result); +} + +// Hash a 1 byte fixed-size object. +// +Datum +hll_hash_1byte(PG_FUNCTION_ARGS) +{ + char key = PG_GETARG_CHAR(0); + uint64 out[2]; + + MurmurHash3_x64_128(&key, sizeof(key), 0, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash a 1 byte fixed-size object with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_1bytes); +Datum hll_hash_1bytes(PG_FUNCTION_ARGS); +Datum +hll_hash_1bytes(PG_FUNCTION_ARGS) +{ + char key = PG_GETARG_CHAR(0); + int32 seed = PG_GETARG_INT32(1); + uint64 out[2]; + + if (seed < 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("negative seed values not compatible"))); + + MurmurHash3_x64_128(&key, sizeof(key), seed, out); + + PG_RETURN_INT64(out[0]); +} + + +// Hash a 2 byte fixed-size object. +// +// Hash a 2 byte fixed-size object. +// +Datum +hll_hash_2byte(PG_FUNCTION_ARGS) +{ + int16 key = PG_GETARG_INT16(0); + uint64 out[2]; + + MurmurHash3_x64_128(&key, sizeof(key), 0, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash a 2 byte fixed-size object with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_2bytes); +Datum hll_hash_2bytes(PG_FUNCTION_ARGS); +Datum +hll_hash_2bytes(PG_FUNCTION_ARGS) +{ + int16 key = PG_GETARG_INT16(0); + int32 seed = PG_GETARG_INT32(1); + uint64 out[2]; + + if (seed < 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("negative seed values not compatible"))); + + MurmurHash3_x64_128(&key, sizeof(key), seed, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash a 4 byte fixed-size object. +// +// Hash a 4 byte fixed-size object. +// +Datum +hll_hash_4byte(PG_FUNCTION_ARGS) +{ + int32 key = PG_GETARG_INT32(0); + uint64 out[2]; + + MurmurHash3_x64_128(&key, sizeof(key), 0, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash a 4 byte fixed-size object with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_4bytes); +Datum hll_hash_4bytes(PG_FUNCTION_ARGS); +Datum +hll_hash_4bytes(PG_FUNCTION_ARGS) +{ + int32 key = PG_GETARG_INT32(0); + int32 seed = PG_GETARG_INT32(1); + uint64 out[2]; + + if (seed < 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("negative seed values not compatible"))); + + MurmurHash3_x64_128(&key, sizeof(key), seed, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash an 8 byte fixed-size object. +// +// Hash an 8 byte fixed-size object. +// +Datum +hll_hash_8byte(PG_FUNCTION_ARGS) +{ + int64 key = PG_GETARG_INT64(0); + uint64 out[2]; + + MurmurHash3_x64_128(&key, sizeof(key), 0, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash an 8 byte fixed-size object with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_8bytes); +Datum hll_hash_8bytes(PG_FUNCTION_ARGS); +Datum +hll_hash_8bytes(PG_FUNCTION_ARGS) +{ + int64 key = PG_GETARG_INT64(0); + int32 seed = PG_GETARG_INT32(1); + uint64 out[2]; + + if (seed < 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("negative seed values not compatible"))); + + MurmurHash3_x64_128(&key, sizeof(key), seed, out); + + PG_RETURN_INT64(out[0]); +} + +// Hash a varlena object. +// +Datum +hll_hash_varlena(PG_FUNCTION_ARGS) +{ + struct varlena * vlap = PG_GETARG_VARLENA_PP(0); + + void * keyp = VARDATA_ANY(vlap); + int len = VARSIZE_ANY_EXHDR(vlap); + + uint64 out[2]; + + MurmurHash3_x64_128(keyp, len, 0, out); + + /* Avoid leaking memory for toasted inputs */ + PG_FREE_IF_COPY(vlap, 0); + + PG_RETURN_INT64(out[0]); +} + +// Hash a varlena object with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_varlenas); +Datum hll_hash_varlenas(PG_FUNCTION_ARGS); +Datum +hll_hash_varlenas(PG_FUNCTION_ARGS) +{ + struct varlena * vlap = PG_GETARG_VARLENA_PP(0); + + void * keyp = VARDATA_ANY(vlap); + int len = VARSIZE_ANY_EXHDR(vlap); + + int32 seed = PG_GETARG_INT32(1); + + uint64 out[2]; + + if (seed < 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("negative seed values not compatible"))); + + MurmurHash3_x64_128(keyp, len, seed, out); + + /* Avoid leaking memory for toasted inputs */ + PG_FREE_IF_COPY(vlap, 0); + + PG_RETURN_INT64(out[0]); +} + + +// Hash any scalar data type. +// +Datum +hll_hash_any(PG_FUNCTION_ARGS) +{ + Datum keyDatum = PG_GETARG_DATUM(0); + Datum hashResultDatum = 0; + + Oid keyTypeId = get_fn_expr_argtype(fcinfo->flinfo, 0); + int16 keyTypeLength = get_typlen(keyTypeId); + + /* dispatch to corresponding hash function for key type */ + switch (keyTypeLength) + { + case 1: + hashResultDatum = DirectFunctionCall2(hll_hash_1byte, keyDatum, Int32GetDatum(0)); + break; + + case 2: + hashResultDatum = DirectFunctionCall2(hll_hash_2byte, keyDatum, Int32GetDatum(0)); + break; + + case 4: + hashResultDatum = DirectFunctionCall2(hll_hash_4byte, keyDatum, Int32GetDatum(0)); + break; + + case 8: + hashResultDatum = DirectFunctionCall2(hll_hash_8byte, keyDatum, Int32GetDatum(0)); + break; + + case -1: + case -2: + hashResultDatum = DirectFunctionCall2(hll_hash_varlena, keyDatum, Int32GetDatum(0)); + break; + + default: + { + /* + * We have a fixed-size type such as char(10), macaddr, circle, etc. We + * first convert this type to its variable-length binary representation + * and then dispatch to the variable-length hashing function. + */ + Oid keyTypeSendFunction = InvalidOid; + bool keyTypeVarlena = false; + Datum keyBinaryDatum = 0; + + /* no need to worry about SPI for these types' output functions */ + getTypeBinaryOutputInfo(keyTypeId, &keyTypeSendFunction, &keyTypeVarlena); + keyBinaryDatum = OidFunctionCall1(keyTypeSendFunction, keyDatum); + + hashResultDatum = DirectFunctionCall2(hll_hash_varlena, keyBinaryDatum, + Int32GetDatum(0)); + break; + } + } + + PG_RETURN_INT64(hashResultDatum); +} + +// Hash any scalar data type with one parameter hash seed. +// +PG_FUNCTION_INFO_V1(hll_hash_anys); +Datum hll_hash_anys(PG_FUNCTION_ARGS); +Datum +hll_hash_anys(PG_FUNCTION_ARGS) +{ + Datum keyDatum = PG_GETARG_DATUM(0); + Datum seedDatum = PG_GETARG_DATUM(1); + Datum hashResultDatum = 0; + + Oid keyTypeId = get_fn_expr_argtype(fcinfo->flinfo, 0); + int16 keyTypeLength = get_typlen(keyTypeId); + + /* dispatch to corresponding hash function for key type */ + switch (keyTypeLength) + { + case 1: + hashResultDatum = DirectFunctionCall2(hll_hash_1bytes, keyDatum, seedDatum); + break; + + case 2: + hashResultDatum = DirectFunctionCall2(hll_hash_2bytes, keyDatum, seedDatum); + break; + + case 4: + hashResultDatum = DirectFunctionCall2(hll_hash_4bytes, keyDatum, seedDatum); + break; + + case 8: + hashResultDatum = DirectFunctionCall2(hll_hash_8bytes, keyDatum, seedDatum); + break; + + case -1: + case -2: + hashResultDatum = DirectFunctionCall2(hll_hash_varlenas, keyDatum, seedDatum); + break; + + default: + { + /* + * We have a fixed-size type such as char(10), macaddr, circle, etc. We + * first convert this type to its variable-length binary representation + * and then dispatch to the variable-length hashing function. + */ + Oid keyTypeSendFunction = InvalidOid; + bool keyTypeVarlena = false; + Datum keyBinaryDatum = 0; + + /* no need to worry about SPI for these types' output functions */ + getTypeBinaryOutputInfo(keyTypeId, &keyTypeSendFunction, &keyTypeVarlena); + keyBinaryDatum = OidFunctionCall1(keyTypeSendFunction, keyDatum); + + hashResultDatum = DirectFunctionCall2(hll_hash_varlenas, keyBinaryDatum, + seedDatum); + break; + } + } + + PG_RETURN_INT64(hashResultDatum); +} + + +PG_FUNCTION_INFO_V1(hll_eq); +Datum hll_eq(PG_FUNCTION_ARGS); +Datum +hll_eq(PG_FUNCTION_ARGS) +{ + bytea *ab = NULL; + size_t asz; + bytea *bb = NULL; + size_t bsz; + bool retval = false; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + bb = PG_GETARG_BYTEA_P(1); + bsz = VARSIZE(bb) - VARHDRSZ; + + if (asz != bsz) + { + retval = false; + } + else + { + void const * ap = VARDATA(ab); + void const * bp = VARDATA(bb); + int rv = memcmp(ap, bp, asz); + retval = rv == 0; + } + + PG_FREE_IF_COPY(ab, 0); + PG_FREE_IF_COPY(bb, 1); + PG_RETURN_BOOL(retval); +} + +PG_FUNCTION_INFO_V1(hll_ne); +Datum hll_ne(PG_FUNCTION_ARGS); +Datum +hll_ne(PG_FUNCTION_ARGS) +{ + bytea * ab = NULL; + size_t asz; + bytea * bb = NULL; + size_t bsz; + bool retval = false; + + ab = PG_GETARG_BYTEA_P(0); + asz = VARSIZE(ab) - VARHDRSZ; + + bb = PG_GETARG_BYTEA_P(1); + bsz = VARSIZE(bb) - VARHDRSZ; + + if (asz != bsz) + { + retval = true; + } + else + { + void const * ap = VARDATA(ab); + void const * bp = VARDATA(bb); + int rv = memcmp(ap, bp, asz); + retval = rv != 0; + } + + PG_FREE_IF_COPY(ab, 0); + PG_FREE_IF_COPY(bb, 1); + PG_RETURN_BOOL(retval); +} + +// This function creates a multiset_t in a temporary context. +// +multiset_t * setup_multiset_new(MemoryContext rcontext); +multiset_t * +setup_multiset_new(MemoryContext rcontext) +{ + MemoryContext tmpcontext; + MemoryContext oldcontext; + multiset_t * msp; + + tmpcontext = AllocSetContextCreate(rcontext, + "multiset", + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); + + oldcontext = MemoryContextSwitchTo(tmpcontext); + + msp = (multiset_t *) palloc(sizeof(multiset_t)); + + msp->ms_type = MST_UNINIT; + + MemoryContextSwitchTo(oldcontext); + + return msp; +} + +// Union aggregate transition function, first arg unpacked, second packed. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_union_trans_new); +Datum hll_union_trans_new(PG_FUNCTION_ARGS); +Datum +hll_union_trans_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + bytea * bb; + size_t bsz; + + multiset_t * msap; + + multiset_t msb; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_union_trans_new outside transition context"))); + + // Is the first argument a NULL? + if (PG_ARGISNULL(0)) + { + msap = setup_multiset_new(aggctx); + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + // This is the packed "argument" vector. + bb = PG_GETARG_BYTEA_P(1); + bsz = VARSIZE(bb) - VARHDRSZ; + + multiset_unpack(&msb, (uint8_t *) VARDATA(bb), bsz, NULL); + + // Was the first argument uninitialized? + if (msap->ms_type == MST_UNINIT) + { + // Yes, clone the metadata from the second arg. + copy_metadata(msap, &msb); + msap->ms_type = MST_EMPTY; + } + else + { + // Nope, make sure the metadata is compatible. + check_metadata(msap, &msb); + } + + multiset_union(msap, &msb); + } + + PG_RETURN_POINTER(msap); +} + +// Add aggregate transition function. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_add_trans4_new); +Datum hll_add_trans4_new(PG_FUNCTION_ARGS); +Datum +hll_add_trans4_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_add_trans4_new outside transition context"))); + + // If the first argument is a NULL on first call, init an hll_empty + if (PG_ARGISNULL(0)) + { + int32 log2m = PG_GETARG_INT32(2); + int32 regwidth = PG_GETARG_INT32(3); + int64 expthresh = PG_GETARG_INT64(4); + int32 sparseon = PG_GETARG_INT32(5); + + msap = setup_multiset_new(aggctx); + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + memset(msap, '\0', sizeof(multiset_t)); + + msap->ms_type = MST_EMPTY; + msap->ms_nbits = regwidth; + msap->ms_nregs = 1 << log2m; + msap->ms_log2nregs = log2m; + msap->ms_expthresh = expthresh; + msap->ms_sparseon = sparseon; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + int64 val = PG_GETARG_INT64(1); + + multiset_add(msap, val); + } + + PG_RETURN_POINTER(msap); +} + +// Add aggregate transition function. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_add_trans3_new); +Datum hll_add_trans3_new(PG_FUNCTION_ARGS); +Datum +hll_add_trans3_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_add_trans3_new outside transition context"))); + + // If the first argument is a NULL on first call, init an hll_empty + if (PG_ARGISNULL(0)) + { + int32 log2m = PG_GETARG_INT32(2); + int32 regwidth = PG_GETARG_INT32(3); + int64 expthresh = PG_GETARG_INT64(4); + int32 sparseon = g_default_sparseon; + + msap = setup_multiset_new(aggctx); + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + memset(msap, '\0', sizeof(multiset_t)); + + msap->ms_type = MST_EMPTY; + msap->ms_nbits = regwidth; + msap->ms_nregs = 1 << log2m; + msap->ms_log2nregs = log2m; + msap->ms_expthresh = expthresh; + msap->ms_sparseon = sparseon; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + int64 val = PG_GETARG_INT64(1); + + multiset_add(msap, val); + } + + PG_RETURN_POINTER(msap); +} + +// Add aggregate transition function. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_add_trans2_new); +Datum hll_add_trans2_new(PG_FUNCTION_ARGS); +Datum +hll_add_trans2_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_add_trans2_new outside transition context"))); + + // If the first argument is a NULL on first call, init an hll_empty + if (PG_ARGISNULL(0)) + { + int32 log2m = PG_GETARG_INT32(2); + int32 regwidth = PG_GETARG_INT32(3); + int64 expthresh = g_default_expthresh; + int32 sparseon = g_default_sparseon; + + msap = setup_multiset_new(aggctx); + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + memset(msap, '\0', sizeof(multiset_t)); + + msap->ms_type = MST_EMPTY; + msap->ms_nbits = regwidth; + msap->ms_nregs = 1 << log2m; + msap->ms_log2nregs = log2m; + msap->ms_expthresh = expthresh; + msap->ms_sparseon = sparseon; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + int64 val = PG_GETARG_INT64(1); + + multiset_add(msap, val); + } + + PG_RETURN_POINTER(msap); +} + +// Add aggregate transition function. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_add_trans1_new); +Datum hll_add_trans1_new(PG_FUNCTION_ARGS); +Datum +hll_add_trans1_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_add_trans1_new outside transition context"))); + + // If the first argument is a NULL on first call, init an hll_empty + if (PG_ARGISNULL(0)) + { + int32 log2m = PG_GETARG_INT32(2); + int32 regwidth = g_default_regwidth; + int64 expthresh = g_default_expthresh; + int32 sparseon = g_default_sparseon; + + msap = setup_multiset_new(aggctx); + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + memset(msap, '\0', sizeof(multiset_t)); + + msap->ms_type = MST_EMPTY; + msap->ms_nbits = regwidth; + msap->ms_nregs = 1 << log2m; + msap->ms_log2nregs = log2m; + msap->ms_expthresh = expthresh; + msap->ms_sparseon = sparseon; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + int64 val = PG_GETARG_INT64(1); + + multiset_add(msap, val); + } + + PG_RETURN_POINTER(msap); +} + +// Add aggregate transition function. +// +// NOTE - This function is not declared STRICT, it is initialized with +// a NULL ... +// +PG_FUNCTION_INFO_V1(hll_add_trans0_new); +Datum hll_add_trans0_new(PG_FUNCTION_ARGS); +Datum +hll_add_trans0_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_add_trans0_new outside transition context"))); + + // If the first argument is a NULL on first call, init an hll_empty + if (PG_ARGISNULL(0)) + { + int32 log2m = g_default_log2m; + int32 regwidth = g_default_regwidth; + int64 expthresh = g_default_expthresh; + int32 sparseon = g_default_sparseon; + + msap = setup_multiset_new(aggctx); + + check_modifiers(log2m, regwidth, expthresh, sparseon); + + memset(msap, '\0', sizeof(multiset_t)); + + msap->ms_type = MST_EMPTY; + msap->ms_nbits = regwidth; + msap->ms_nregs = 1 << log2m; + msap->ms_log2nregs = log2m; + msap->ms_expthresh = expthresh; + msap->ms_sparseon = sparseon; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + } + + // Is the second argument non-null? + if (!PG_ARGISNULL(1)) + { + int64 val = PG_GETARG_INT64(1); + + multiset_add(msap, val); + } + + PG_RETURN_POINTER(msap); +} + +// Final function, converts multiset_t into packed format. +// +PG_FUNCTION_INFO_V1(hll_pack_new); +Datum hll_pack_new(PG_FUNCTION_ARGS); +Datum +hll_pack_new(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + bytea * cb; + size_t csz; + + multiset_t * msap; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_pack_new outside aggregate context"))); + + // Is the first argument a NULL? + if (PG_ARGISNULL(0)) + { + PG_RETURN_NULL(); + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + + // Was the aggregation uninitialized? + if (msap->ms_type == MST_UNINIT) + { + PG_RETURN_NULL(); + } + else + { + csz = multiset_packed_size(msap); + cb = (bytea *) palloc(VARHDRSZ + csz); + SET_VARSIZE(cb, VARHDRSZ + csz); + + multiset_pack(msap, (uint8_t *) VARDATA(cb), csz); + + // We don't need to pfree the msap memory because it is zone + // allocated inside postgres. + // + // Furthermore, sometimes final functions are called multiple + // times so deallocating it the first time leads to badness. + + PG_RETURN_BYTEA_P(cb); + } + } +} + +// Final function, computes cardinality of unpacked bytea. +// +PG_FUNCTION_INFO_V1(hll_card_unpacked); +Datum hll_card_unpacked(PG_FUNCTION_ARGS); +Datum +hll_card_unpacked(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + double retval; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_card_unpacked outside aggregate context"))); + + // Is the first argument a NULL? + if (PG_ARGISNULL(0)) + { + retval = -1.0; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + + if (msap->ms_type == MST_UNINIT) + { + retval = -1.0; + } + else + { + retval = multiset_card(msap); + } + + // We don't need to pfree the msap memory because it is zone + // allocated inside postgres. + // + // Furthermore, sometimes final functions are called multiple + // times so deallocating it the first time leads to badness. + } + + if (retval == -1.0) + PG_RETURN_NULL(); + else + PG_RETURN_FLOAT8(retval); +} + +// Final function, computes floor of cardinality of multiset_t. +// +PG_FUNCTION_INFO_V1(hll_floor_card_unpacked); +Datum hll_floor_card_unpacked(PG_FUNCTION_ARGS); +Datum +hll_floor_card_unpacked(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + double retval; + int64_t floorval; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_floor_card_unpacked " + "outside aggregate context"))); + + // Is the first argument a NULL? + if (PG_ARGISNULL(0)) + { + retval = -1.0; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + + if (msap->ms_type == MST_UNINIT) + { + retval = -1.0; + } + else + { + retval = multiset_card(msap); + } + + // NOTE - The following comment from array_agg_final suggests we + // should not free the memory here: + // + // "Make the result. We cannot release the ArrayBuildState + // because sometimes aggregate final functions are + // re-executed. Rather, it is nodeAgg.c's responsibility to reset the + // aggcontext when it's safe to do so." + } + + if (retval == -1.0) + { + PG_RETURN_NULL(); + } + else + { + // Take the floor of the value. + floorval = (int64) floor(retval); + PG_RETURN_INT64(floorval); + } +} + +// Final function, computes ceil of cardinality of multiset_t. +// +PG_FUNCTION_INFO_V1(hll_ceil_card_unpacked); +Datum hll_ceil_card_unpacked(PG_FUNCTION_ARGS); +Datum +hll_ceil_card_unpacked(PG_FUNCTION_ARGS) +{ + MemoryContext aggctx; + + multiset_t * msap; + + double retval; + int64_t ceilval; + + // We must be called as a transition routine or we fail. + if (!AggCheckCallContext(fcinfo, &aggctx)) + ereport(ERROR, + (errcode(ERRCODE_DATA_EXCEPTION), + errmsg("hll_ceil_card_unpacked outside aggregate context"))); + + // Is the first argument a NULL? + if (PG_ARGISNULL(0)) + { + retval = -1.0; + } + else + { + msap = (multiset_t *) PG_GETARG_POINTER(0); + + if (msap->ms_type == MST_UNINIT) + { + retval = -1.0; + } + else + { + retval = multiset_card(msap); + } + + // We don't need to pfree the msap memory because it is zone + // allocated inside postgres. + // + // Furthermore, sometimes final functions are called multiple + // times so deallocating it the first time leads to badness. + } + + if (retval == -1.0) + { + PG_RETURN_NULL(); + } + else + { + // Take the ceil of the value. + ceilval = (int64) ceil(retval); + PG_RETURN_INT64(ceilval); + } +} + +PG_FUNCTION_INFO_V1(hll_recv); +Datum hll_recv(PG_FUNCTION_ARGS); +Datum +hll_recv(PG_FUNCTION_ARGS) +{ + Datum dd = DirectFunctionCall1(bytearecv, PG_GETARG_DATUM(0)); + return dd; +} + +PG_FUNCTION_INFO_V1(hll_send); +Datum hll_send(PG_FUNCTION_ARGS); +Datum +hll_send(PG_FUNCTION_ARGS) +{ + Datum dd = PG_GETARG_DATUM(0); + bytea* bp = DatumGetByteaP(dd); + StringInfoData buf; + pq_begintypsend(&buf); + pq_sendbytes(&buf, VARDATA(bp), VARSIZE(bp) - VARHDRSZ); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} diff -uprN postgresql-hll-2.14_old/hll.h postgresql-hll-2.14/hll.h --- postgresql-hll-2.14_old/hll.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/hll.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,297 @@ +/*------------------------------------------------------------------------- + * + * hll.h + * routins for hyper log log + * + * Copyright (c) Huawei Technologies Co., Ltd. All rights reserved. + * + * NOTICE: part of code (hll.cpp) refers to open-source project + * for those part of code we retain the orignal lisence. + * refer to header of hll.cpp + * + * Description: routins for hyper log log + * + * + * IDENTIFICATION + * src/include/utils/hll.h + * + *------------------------------------------------------------------------- + */ + +#ifndef HLL_H +#define HLL_H + +#include "fmgr.h" + +// ---------------------------------------------------------------- +// Output Version Control +// ---------------------------------------------------------------- + +// Set the default output schema. +extern THR_LOCAL uint8_t g_output_version; + +// ---------------------------------------------------------------- +// Type Modifiers +// ---------------------------------------------------------------- + +// The type modifiers need to be packed in the lower 31 bits +// of an int32. We currently use the lowest 15 bits. +// +#define LOG2M_BITS 5 +#define REGWIDTH_BITS 3 +#define EXPTHRESH_BITS 6 +#define SPARSEON_BITS 1 +#define TYPMOD_BITS 15 + +#define MAX_BITVAL(nbits) ((1 << nbits) - 1) + +//numbers of parameter in hll_add_trans functions +#define HLL_PARAMETER0 2 +#define HLL_PARAMETER1 3 +#define HLL_PARAMETER2 4 +#define HLL_PARAMETER3 5 +#define HLL_PARAMETER4 6 + +// Defaults if type modifier values are not specified. +// +#define DEFAULT_LOG2M 11 +#define DEFAULT_REGWIDTH 5 +#define DEFAULT_EXPTHRESH -1 +#define DEFAULT_SPARSEON 1 +#define MAX_SPARSE -1 + +//Maximum and minimum of hll parameters +#define HLL_MAX_LOG2M 16 +#define HLL_MAX_REGWIDTH 5 +#define HLL_MAX_SPARSEON 1 + +#define HLL_MIN_EXPTHRESH -1 +#define HLL_MAX_EXPTHRESH 7 +#define HLL_MIN_LOG2M 10 +#define HLL_MIN_REGWIDTH 1 +#define HLL_MIN_SPARSEON 0 +#define HLL_MIN_MAX_SPARSE -1 + +enum { + MST_UNDEFINED = 0x0, // Invalid/undefined set. + MST_EMPTY = 0x1, // Empty set. + MST_EXPLICIT = 0x2, // List of explicit ids. + MST_SPARSE = 0x3, // Sparse set of compression registers. + MST_COMPRESSED = 0x4, // Array of compression registers. + + MST_UNINIT = 0xffff, // Internal uninitialized. +}; + + +// ---------------------------------------------------------------- +// Maximum Sparse Control +// ---------------------------------------------------------------- + +// By default we set the sparse to full compressed threshold +// automatically to the point where the sparse representation would +// start to be larger. This can be overridden with the +// hll_set_max_sparse directive ... +// + + +// ---------------------------------------------------------------- +// Aggregating Data Structure +// ---------------------------------------------------------------- + +typedef struct +{ + size_t mse_nelem; + uint64_t mse_elems[0]; + +} ms_explicit_t; + +// Defines the *unpacked* register. +typedef uint8_t compreg_t; + +typedef struct +{ + compreg_t msc_regs[0]; + +} ms_compressed_t; + +typedef struct +{ + size_t bwc_nbits; // Write size. + uint8_t * bwc_curp; // Current byte. + size_t bwc_used; // Used bits. + +} bitstream_write_cursor_t; + +// Size of the compressed or explicit data. +#define MS_MAXDATA (128 * 1024) + +typedef struct +{ + size_t ms_nbits; + size_t ms_nregs; + size_t ms_log2nregs; + int64 ms_expthresh; + bool ms_sparseon; + + uint64_t ms_type; // size is only for alignment. + + union + { + // MST_EMPTY and MST_UNDEFINED don't need data. + // MST_SPARSE is only used in the packed format. + // + ms_explicit_t as_expl; // MST_EXPLICIT + ms_compressed_t as_comp; // MST_COMPRESSED + uint8_t as_size[MS_MAXDATA]; // sizes the union. + + } ms_data; + +} multiset_t; + +typedef struct +{ + size_t brc_nbits; // Read size. + uint32_t brc_mask; // Read mask. + uint8_t const * brc_curp; // Current byte. + size_t brc_used; // Used bits. + +} bitstream_read_cursor_t; + +extern bytea * setup_multiset(MemoryContext rcontext); + + +extern int32 typmod_log2m(int32 typmod); +extern int32 typmod_regwidth(int32 typmod); +extern int32 typmod_expthresh(int32 typmod); +extern int32 typmod_sparseon(int32 typmod); +extern int64 decode_expthresh(int32 encoded_expthresh); +extern int32 integer_log2(int64 val); +extern int64 integer_exp2(int64 val); +extern int32 encode_expthresh(int64 expthresh); +extern size_t expthresh_value(int64 expthresh, size_t nbits, size_t nregs); +extern uint32_t bitstream_unpack(bitstream_read_cursor_t * brcp); +extern void compressed_unpack(compreg_t * i_regp, + size_t i_width, + size_t i_nregs, + uint8_t const * i_bitp, + size_t i_size, + uint8_t i_vers); +extern void sparse_unpack(compreg_t * i_regp, + size_t i_width, + size_t i_log2nregs, + size_t i_nfilled, + uint8_t const * i_bitp, + size_t i_size); +extern void bitstream_pack(bitstream_write_cursor_t * bwcp, uint32_t val); +extern void compressed_pack(compreg_t const * i_regp, + size_t i_width, + size_t i_nregs, + uint8_t * o_bitp, + size_t i_size, + uint8_t i_vers); +extern void sparse_pack(compreg_t const * i_regp, + size_t i_width, + size_t i_nregs, + size_t i_log2nregs, + size_t i_nfilled, + uint8_t * o_bitp, + size_t i_size); +extern void check_metadata(multiset_t const * i_omp, multiset_t const * i_imp); +extern void copy_metadata(multiset_t * o_msp, multiset_t const * i_msp); +extern void compressed_add(multiset_t * o_msp, uint64_t elem); +extern void compressed_explicit_union(multiset_t * o_msp, multiset_t const * i_msp); +extern void explicit_to_compressed(multiset_t * msp); +extern int element_compare(void const * ptr1, void const * ptr2); +extern size_t numfilled(multiset_t const * i_msp); +extern char * multiset_tostring(multiset_t const * i_msp); +extern void explicit_validate(multiset_t const * i_msp, ms_explicit_t const * i_msep); +extern size_t upper_bound(const uint64_t elements[], size_t n, uint64_t value); +extern void multiset_add(multiset_t * o_msp, uint64_t element); +extern void multiset_union(multiset_t * o_msap, multiset_t const * i_msbp); +extern void explicit_union(multiset_t * o_msp, ms_explicit_t const * i_msep); +extern void unpack_header(multiset_t * o_msp, + uint8_t const * i_bitp, + uint8_t vers, + uint8_t type); +extern uint8_t multiset_unpack(multiset_t * o_msp, + uint8_t const * i_bitp, + size_t i_size, + uint8_t * o_encoded_type); +extern size_t pack_header(uint8_t * o_bitp, + uint8_t vers, + uint8_t type, + size_t nbits, + size_t log2nregs, + int64 expthresh, + size_t sparseon); +extern void multiset_pack(multiset_t const * i_msp, uint8_t * o_bitp, size_t i_size); +extern size_t multiset_copy_size(multiset_t const * i_msp); +extern size_t multiset_packed_size(multiset_t const * i_msp); +extern void check_modifiers(int32 log2m, int32 regwidth, int64 expthresh, int32 sparseon); +extern double gamma_register_count_squared(int nregs); +extern int64 *ArrayGetInteger64Typmods(ArrayType *arr, int *n); +extern double estimate_hllagg_size(double numGroups, List *tleList); +extern void check_hll_para_range(int32 log2m, int32 regwidth, int64 expthresh, int32 sparseon); + +/* + * INTERFACES + */ +extern Datum hll_in(PG_FUNCTION_ARGS); +extern Datum hll_out(PG_FUNCTION_ARGS); +extern Datum hll(PG_FUNCTION_ARGS); +extern Datum hll_hashval_in(PG_FUNCTION_ARGS); +extern Datum hll_hashval_out(PG_FUNCTION_ARGS); +extern Datum hll_hashval_eq(PG_FUNCTION_ARGS); +extern Datum hll_hashval_ne(PG_FUNCTION_ARGS); +extern Datum hll_hashval(PG_FUNCTION_ARGS); +extern Datum hll_hashval_int4(PG_FUNCTION_ARGS); +extern Datum hll_typmod_in(PG_FUNCTION_ARGS); +extern Datum hll_typmod_out(PG_FUNCTION_ARGS); +extern Datum hll_cardinality(PG_FUNCTION_ARGS); +extern Datum hll_union(PG_FUNCTION_ARGS); +extern Datum hll_add(PG_FUNCTION_ARGS); +extern Datum hll_add_rev(PG_FUNCTION_ARGS); +extern Datum hll_print(PG_FUNCTION_ARGS); +extern Datum hll_empty0(PG_FUNCTION_ARGS); +extern Datum hll_empty1(PG_FUNCTION_ARGS); +extern Datum hll_empty2(PG_FUNCTION_ARGS); +extern Datum hll_empty3(PG_FUNCTION_ARGS); +extern Datum hll_empty4(PG_FUNCTION_ARGS); +extern Datum hll_schema_version(PG_FUNCTION_ARGS); +extern Datum hll_type(PG_FUNCTION_ARGS); +extern Datum hll_log2m(PG_FUNCTION_ARGS); +extern Datum hll_regwidth(PG_FUNCTION_ARGS); +extern Datum hll_expthresh(PG_FUNCTION_ARGS); +extern Datum hll_sparseon(PG_FUNCTION_ARGS); +extern Datum hll_hash_1byte(PG_FUNCTION_ARGS); +extern Datum hll_hash_1bytes(PG_FUNCTION_ARGS); +extern Datum hll_hash_2byte(PG_FUNCTION_ARGS); +extern Datum hll_hash_2bytes(PG_FUNCTION_ARGS); +extern Datum hll_hash_4byte(PG_FUNCTION_ARGS); +extern Datum hll_hash_4bytes(PG_FUNCTION_ARGS); +extern Datum hll_hash_8byte(PG_FUNCTION_ARGS); +extern Datum hll_hash_8bytes(PG_FUNCTION_ARGS); +extern Datum hll_hash_varlena(PG_FUNCTION_ARGS); +extern Datum hll_hash_varlenas(PG_FUNCTION_ARGS); +extern Datum hll_hash_any(PG_FUNCTION_ARGS); +extern Datum hll_hash_anys(PG_FUNCTION_ARGS); +extern Datum hll_eq(PG_FUNCTION_ARGS); +extern Datum hll_ne(PG_FUNCTION_ARGS); +extern Datum hll_recv(PG_FUNCTION_ARGS); +extern Datum hll_send(PG_FUNCTION_ARGS); + +// MPP hll +extern Datum hll_add_trans0(PG_FUNCTION_ARGS); +extern Datum hll_add_trans1(PG_FUNCTION_ARGS); +extern Datum hll_add_trans2(PG_FUNCTION_ARGS); +extern Datum hll_add_trans3(PG_FUNCTION_ARGS); +extern Datum hll_add_trans4(PG_FUNCTION_ARGS); +extern Datum hll_add_trans_n(PG_FUNCTION_ARGS); +extern Datum hll_union_trans(PG_FUNCTION_ARGS); +extern Datum hll_union_collect(PG_FUNCTION_ARGS); +extern Datum hll_pack(PG_FUNCTION_ARGS); +extern Datum hll_trans_recv(PG_FUNCTION_ARGS); +extern Datum hll_trans_send(PG_FUNCTION_ARGS); +extern Datum hll_trans_in(PG_FUNCTION_ARGS); +extern Datum hll_trans_out(PG_FUNCTION_ARGS); +#endif diff -uprN postgresql-hll-2.14_old/include/access/attnum.h postgresql-hll-2.14/include/access/attnum.h --- postgresql-hll-2.14_old/include/access/attnum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/attnum.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * attnum.h + * POSTGRES attribute number definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/attnum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATTNUM_H +#define ATTNUM_H + +#include "c.h" + +/* + * user defined attribute numbers start at 1. -ay 2/95 + */ +typedef int16 AttrNumber; + +#define InvalidAttrNumber 0 +#define MaxAttrNumber 32767 + +/* ---------------- + * support macros + * ---------------- + */ +/* + * AttributeNumberIsValid + * True iff the attribute number is valid. + */ +#define AttributeNumberIsValid(attributeNumber) ((bool)((attributeNumber) != InvalidAttrNumber)) + +/* + * AttrNumberIsForUserDefinedAttr + * True iff the attribute number corresponds to an user defined attribute. + */ +#define AttrNumberIsForUserDefinedAttr(attributeNumber) ((bool)((attributeNumber) > 0)) + +/* + * AttrNumberGetAttrOffset + * Returns the attribute offset for an attribute number. + * + * Note: + * Assumes the attribute number is for an user defined attribute. + */ +#define AttrNumberGetAttrOffset(attNum) (AssertMacro(AttrNumberIsForUserDefinedAttr(attNum)), ((attNum)-1)) + +/* + * AttributeOffsetGetAttributeNumber + * Returns the attribute number for an attribute offset. + */ +#define AttrOffsetGetAttrNumber(attributeOffset) ((AttrNumber)(1 + (attributeOffset))) + +#endif /* ATTNUM_H */ diff -uprN postgresql-hll-2.14_old/include/access/cbmparsexlog.h postgresql-hll-2.14/include/access/cbmparsexlog.h --- postgresql-hll-2.14_old/include/access/cbmparsexlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cbmparsexlog.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,289 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbmparsexlog.h + * Definitions for cbm-parsing-xlog facility + * + * + * IDENTIFICATION + * src/include/access/cbmparsexlog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CBMPARSEXLOG_H +#define CBMPARSEXLOG_H + +#include "access/xlogrecord.h" +#include "c.h" +#include "lib/dllist.h" +#include "port/pg_crc32c.h" +#include "securec_check.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/hsearch.h" + +/* Struct for single bitmap file information */ +typedef struct BitmapFileStruct { + char name[MAXPGPATH]; /* Name with full path */ + int fd; /* Handle to opened file */ + uint64 size; /* Size of the file */ + off_t offset; /* Offset of the next read */ +} BitmapFile; + +#define CBMDIR "pg_cbm/" +#define MAX_CBM_FILENAME_LENGTH 66 + +/* CBM xlog read structure */ +typedef struct CBMXlogReadStruct { + int fd; + XLogSegNo logSegNo; + char filePath[MAXPGPATH]; +} CBMXlogRead; + +/* Xlog parsing and bitmap output data structure */ +typedef struct XlogBitmapStruct { + char cbmFileHome[MAXPGPATH]; /* directory for bitmap files */ + BitmapFile out; /* The current bitmap file */ + uint64 outSeqNum; /* the bitmap file sequence number */ + XLogRecPtr startLSN; /* the LSN of the next unparsed + record and the start of the next LSN + interval to be parsed. */ + XLogRecPtr endLSN; /* the end of the LSN interval to be + parsed, equal to the next checkpoint + LSN at the time of parse */ + HTAB* cbmPageHash; /* the current modified page set, + organized as htab with the keys of + (rNode, forkNum) pairs */ + Dllist pageFreeList; /* doublely-linked list of freed CBM pages */ + uint64 totalPageNum; /* total cbm page number during one parse cycle */ + CBMXlogRead xlogRead; /* file information of xlog files to be parsed */ + bool xlogParseFailed; /* true if failed during last xlog parse */ + bool needReset; /* true if failed during last CBMFollowXlog */ + bool firstCPCreated; /* if first checkpoint has been created after recovery */ +} XlogBitmap; + +typedef struct cbmpageheader { + pg_crc32c pageCrc; + bool isLastBlock; + uint8 pageType; + XLogRecPtr pageStartLsn; + XLogRecPtr pageEndLsn; + RelFileNode rNode; + ForkNumber forkNum; + BlockNumber firstBlkNo; + BlockNumber truncBlkNo; +} CbmPageHeader; + +typedef struct XLogPageReadPrivateCbm { + const char* datadir; + TimeLineID tli; +} XLogPageReadPrivateCBM; + +#define PAGETYPE_DROP 0x04 +#define PAGETYPE_CREATE 0x02 +#define PAGETYPE_TRUNCATE 0x01 +#define PAGETYPE_MODIFY 0x00 + +/* a segment of data file shared a list */ +#define BLOCK_NUM_PER_CBMLIST 131072 + +#define GET_SEG_INDEX_FROM_BLOCK_NUM(block_num) ((block_num)/(BLOCK_NUM_PER_CBMLIST)) + +/* Max size of each bitmap file, in bytes. */ +#define MAXCBMFILESIZE (128 * 1024 * 1024) + +/* Size of the bitmap page, in bytes. */ +#define CBMPAGESIZE 512 + +/* Size of the bitmap on each cbm map page, in bytes. */ +#define CBMMAPSIZE (CBMPAGESIZE - MAXALIGN(sizeof(CbmPageHeader))) + +/* Max total size of all reserved free pages, in bytes. */ +#define MAXCBMFREEPAGESIZE (64 * 1024 * 1024) + +/* Max total number of all reserved free pages. */ +#define MAXCBMFREEPAGENUM (MAXCBMFREEPAGESIZE / CBMPAGESIZE) + +/* Number of bits allocated for each heap block. */ +#define CBM_BITS_PER_BLOCK 1 + +/* Number of heap blocks we can represent in one byte. */ +#define CBM_BLOCKS_PER_BYTE 8 + +/* Number of blocks we can represent in one cbm map page. */ +#define CBM_BLOCKS_PER_PAGE (CBMMAPSIZE * CBM_BLOCKS_PER_BYTE) + +#define BLKNO_TO_CBM_PAGEFIRSTBOCK(x) (BlockNumberIsValid(x) ? ((x) - ((x) % CBM_BLOCKS_PER_PAGE)) : InvalidBlockNumber) +#define BLKNO_TO_CBMBYTEOFPAGE(x) (((x) % CBM_BLOCKS_PER_PAGE) / CBM_BLOCKS_PER_BYTE) +#define BLKNO_TO_CBMBITOFBYTE(x) ((x) % CBM_BLOCKS_PER_BYTE) + +#define CBM_PAGE_NOT_CHANGED 0 +#define CBM_PAGE_CHANGED ((uint32)1) + +#define CBM_PAGE_BITMASK ((uint32)1) + +#define SET_CBM_PAGE_BITMAP(byte, bit, status) \ + do { \ + char byteval = byte; \ + byteval &= ~(CBM_PAGE_BITMASK << bit); \ + byteval |= (status << bit); \ + byte = byteval; \ + } while (0) + +#define CLEAR_CBM_PAGE_BITMAP(byte, bit) (byte) &= ~(CBM_PAGE_BITMASK << (bit)) + +#define CBM_BLOCKNO_CMP(a, b) \ + ((a) == (b) ? 0 : ((a) == InvalidBlockNumber ? -1 : ((b) == InvalidBlockNumber ? 1 : ((a) < (b) ? -1 : 1)))) + +/* + * Note: if there are any pad bytes in the struct, INIT_CBMPAGETAG have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct cbmpagetag { + RelFileNode rNode; + ForkNumber forkNum; +} CBMPageTag; + +#define INIT_CBMPAGETAG(a, xx_rnode, xx_forkNum) ((a).rNode = (xx_rnode), (a).forkNum = (xx_forkNum)) + +#define InvalidRelFileNode ((RelFileNode){0, 0, 0, -1}) + +#define INIT_DUMMYCBMPAGETAG(a) ((a).rNode = InvalidRelFileNode, (a).forkNum = InvalidForkNumber) + +#define CBMPAGETAG_EQUAL(a, b) (RelFileNodeEquals((a).rNode, (b).rNode) && (a).forkNum == (b).forkNum) + +typedef struct cbmhashentry { + CBMPageTag cbmTag; + Dllist cbmSegPageList; + int pageNum; +} CbmHashEntry; + +typedef struct cbmsegpagelist { + int segIndex; + Dllist pageDllist; +} CbmSegPageList; + +#define INIT_CBMPAGEENTRY(a) \ + do { \ + (a)->pageNum = 0; \ + DLInitList(&((a)->cbmSegPageList)); \ + } while (0) + +#define INIT_CBMPAGEHEADER(a, xx_pagetag, xx_firstblkno) \ + ((a)->rNode = (xx_pagetag.rNode), \ + (a)->forkNum = (xx_pagetag.forkNum), \ + (a)->firstBlkNo = (xx_firstblkno), \ + (a)->pageType = PAGETYPE_MODIFY, \ + (a)->truncBlkNo = InvalidBlockNumber) + +#define CBM_PAGE_IS_DUMMY(a) ((RelFileNodeEquals((a)->rNode, InvalidRelFileNode)) && ((a)->forkNum == InvalidForkNumber)) + +#define INITCBMPAGEHASHSIZE 400 + +/* Struct for cbm filename information */ +typedef struct cbmfilename { + char* name; /* file name pointer */ + uint64 seqNum; /* file sequence number */ + XLogRecPtr startLSN; /* file start lsn */ + XLogRecPtr endLSN; /* file end lsn */ +} CbmFileName; + +#define INIT_CBMFILENAME(a, xx_name, xx_seqnum, xx_startlsn, xx_endlsn) \ + do { \ + (a)->name = pstrdup(xx_name); \ + (a)->seqNum = xx_seqnum; \ + (a)->startLSN = xx_startlsn; \ + (a)->endLSN = xx_endlsn; \ + } while (0) + +typedef struct cbmpageiterator { + FILE* file; + off_t readOffset; + char* buffer; + XLogRecPtr pageStartLsn; + XLogRecPtr pageEndLsn; + bool isLastBlock; + bool checksumOk; + XLogRecPtr prevStartLsn; + XLogRecPtr prevEndLsn; + bool isPrevLastBlock; +} cbmPageIterator; + +#define INIT_CBMPAGEITERATOR(a, xx_file, xx_buffer) \ + ((a).file = (xx_file), \ + (a).readOffset = (off_t)0, \ + (a).buffer = (xx_buffer), \ + (a).pageStartLsn = InvalidXLogRecPtr, \ + (a).pageEndLsn = InvalidXLogRecPtr, \ + (a).checksumOk = false, \ + (a).isLastBlock = false, \ + (a).prevStartLsn = InvalidXLogRecPtr, \ + (a).prevEndLsn = InvalidXLogRecPtr, \ + (a).isPrevLastBlock = false) + +typedef struct cbmarrayentry { + CBMPageTag cbmTag; + uint8 changeType; + BlockNumber truncBlockNum; + uint32 totalBlockNum; + uint32 maxSize; + BlockNumber* changedBlock; +} CBMArrayEntry; + +#define INIT_CBMARRAYENTRY(a, xx_cbmTag) \ + do { \ + (a)->cbmTag = (xx_cbmTag); \ + (a)->changeType = PAGETYPE_MODIFY; \ + (a)->truncBlockNum = InvalidBlockNumber; \ + (a)->totalBlockNum = 0; \ + InitCBMArrayEntryBlockArray(a); \ + } while (0) + +typedef struct cbmarray { + XLogRecPtr startLSN; + XLogRecPtr endLSN; + long arrayLength; + CBMArrayEntry* arrayEntry; +} CBMArray; + +#define INITBLOCKARRAYSIZE 16 + +typedef struct cbmbitmapiterator { + char* bitmap; + BlockNumber nextBlkNo; + BlockNumber startBlkNo; + BlockNumber endBlkNo; +} CBMBitmapIterator; + +/* for block number printed in tuple */ +#define MAX_STRLEN_PER_BLOCKNO 12 +#define MAX_BLOCKNO_PER_TUPLE ((MaxAllocSize - 1) / MAX_STRLEN_PER_BLOCKNO) + +#define INIT_CBMBITMAPITERATOR(a, xx_bitmap, xx_start, xx_end) \ + ((a).bitmap = (xx_bitmap), (a).nextBlkNo = (xx_start), (a).startBlkNo = (xx_start), (a).endBlkNo = (xx_end)) + +extern void InitXlogCbmSys(void); +extern void CBMTrackInit(bool startupXlog, XLogRecPtr startupCPRedo); +extern void CBMFollowXlog(void); +extern void CBMGetMergedFile(XLogRecPtr startLSN, XLogRecPtr endLSN, char* mergedFileName); +extern CBMArray* CBMGetMergedArray(XLogRecPtr startLSN, XLogRecPtr endLSN); +extern void FreeCBMArray(CBMArray* cbmArray); +extern CBMArray *SplitCBMArray(CBMArray **orgCBMArrayPtr); +extern void CBMRecycleFile(XLogRecPtr targetLSN, XLogRecPtr* endLSN); +extern XLogRecPtr ForceTrackCBMOnce(XLogRecPtr targetLSN, int timeOut, bool wait, bool lockHeld, bool isRecEnd = true); +extern void advanceXlogPtrToNextPageIfNeeded(XLogRecPtr* recPtr); +extern void cbm_rotate_file(XLogRecPtr rotateLsn); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cbtree.h postgresql-hll-2.14/include/access/cbtree.h --- postgresql-hll-2.14_old/include/access/cbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cbtree.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbtree.h + * + * + * + * IDENTIFICATION + * src/include/access/cbtree.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CTREE_H +#define CTREE_H + +#include "fmgr.h" + +Datum cbtreebuild(PG_FUNCTION_ARGS); +Datum cbtreeoptions(PG_FUNCTION_ARGS); +Datum cbtreegettuple(PG_FUNCTION_ARGS); +Datum cbtreecanreturn(PG_FUNCTION_ARGS); + +#endif /* CBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/access/clog.h postgresql-hll-2.14/include/access/clog.h --- postgresql-hll-2.14_old/include/access/clog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/clog.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,105 @@ +/* + * clog.h + * + * PostgreSQL transaction-commit-log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/clog.h + */ +#ifndef CLOG_H +#define CLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* + * Defines for CLOG page sizes. A page is the same BLCKSZ as is used + * everywhere else in Postgres. + * + * Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF, + * CLOG page numbering also wraps around at 0xFFFFFFFF/CLOG_XACTS_PER_PAGE, + * and CLOG segment numbering at + * 0xFFFFFFFF/CLOG_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need take no + * explicit notice of that fact in this module, except when comparing segment + * and page numbers in TruncateCLOG (see CLOGPagePrecedes). + */ + +/* We need two bits per xact, so four xacts fit in a byte */ +#define CLOG_BITS_PER_XACT 2 +#define CLOG_XACTS_PER_BYTE 4 +#define CLOG_XACTS_PER_PAGE (BLCKSZ * CLOG_XACTS_PER_BYTE) +#define CLOG_XACT_BITMASK ((1 << CLOG_BITS_PER_XACT) - 1) + +#define TransactionIdToPage(xid) ((xid) / (TransactionId)CLOG_XACTS_PER_PAGE) +#define TransactionIdToPgIndex(xid) ((xid) % (TransactionId)CLOG_XACTS_PER_PAGE) +#define TransactionIdToByte(xid) (TransactionIdToPgIndex(xid) / CLOG_XACTS_PER_BYTE) +#define TransactionIdToBIndex(xid) ((xid) % (TransactionId)CLOG_XACTS_PER_BYTE) + +#define CLogPageNoToStartXactId(pageno) ((pageno > 0)?((pageno -1) * CLOG_XACTS_PER_PAGE): 0) +/* CLog lwlock partition*/ +#define CBufHashPartition(hashcode) \ + ((hashcode) % NUM_CLOG_PARTITIONS) +#define CBufMappingPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCBufMappingLock + CBufHashPartition(hashcode)].lock) +#define CBufMappingPartitionLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCBufMappingLock + i].lock) + +/* + * Possible transaction statuses --- note that all-zeroes is the initial + * state. + * + */ +typedef int CLogXidStatus; + +#define CLOG_XID_STATUS_IN_PROGRESS 0x00 +#define CLOG_XID_STATUS_COMMITTED 0x01 +#define CLOG_XID_STATUS_ABORTED 0x02 + +/* + * A "subcommitted" transaction is a committed subtransaction whose parent + * hasn't committed or aborted yet. + */ +#define CLOG_XID_STATUS_SUB_COMMITTED 0x03 + +extern void CLogSetTreeStatus( + TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status, XLogRecPtr lsn); +extern CLogXidStatus CLogGetStatus(TransactionId xid, XLogRecPtr* lsn); +extern Size CLOGShmemBuffers(void); +extern Size CLOGShmemSize(void); +extern void CLOGShmemInit(void); +extern void BootStrapCLOG(void); +extern void StartupCLOG(void); +extern void TrimCLOG(void); +extern void ShutdownCLOG(void); +extern void CheckPointCLOG(void); +extern void ExtendCLOG(TransactionId newestXact, bool allowXlog = true); +extern void TruncateCLOG(TransactionId oldestXact); +extern bool IsCLogTruncate(XLogReaderState* record); + +/* XLOG stuff */ +#define CLOG_ZEROPAGE 0x00 +#define CLOG_TRUNCATE 0x10 + +extern void clog_redo(XLogReaderState* record); +extern void clog_desc(StringInfo buf, XLogReaderState* record); + +#ifdef USE_ASSERT_CHECKING + +typedef enum { FIT_CLOG_EXTEND_PAGE = 0, FIT_CLOG_READ_PAGE, FIT_LWLOCK_DEADLOCK, FIT_MAX_TYPE } FIT_type; + +#endif /* FAULT_INJECTION_TEST */ + +#include "fmgr.h" +extern Datum gs_fault_inject(PG_FUNCTION_ARGS); + +#endif /* CLOG_H */ + +#ifdef ENABLE_UT +extern void set_status_by_pages(int nsubxids, TransactionId* subxids, CLogXidStatus status, XLogRecPtr lsn); + +extern void CLogSetPageStatus(TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status, + XLogRecPtr lsn, int64 pageno, bool all_xact_same_page); +extern int FIT_lw_deadlock(int n_edges); +#endif diff -uprN postgresql-hll-2.14_old/include/access/csnlog.h postgresql-hll-2.14/include/access/csnlog.h --- postgresql-hll-2.14_old/include/access/csnlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/csnlog.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,40 @@ +/* --------------------------------------------------------------------------------------- + * + * csnlog.h + * Commit-Sequence-Number log. + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/csnlog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSNLOG_H +#define CSNLOG_H + +#include "access/xlog.h" + +#define CSNBufHashPartition(hashcode) ((hashcode) % NUM_CSNLOG_PARTITIONS) +#define CSNBufMappingPartitionLock(hashcode) (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCSNBufMappingLock + CSNBufHashPartition(hashcode)].lock) +#define CSNBufMappingPartitionLockByIndex(i) (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCSNBufMappingLock + i].lock) + +extern void CSNLogSetCommitSeqNo(TransactionId xid, int nsubxids, TransactionId* subxids, CommitSeqNo csn); +extern CommitSeqNo CSNLogGetCommitSeqNo(TransactionId xid); +extern CommitSeqNo CSNLogGetNestCommitSeqNo(TransactionId xid); +extern TransactionId CSNLogGetNextInProgressXid(TransactionId start, TransactionId end); + +extern Size CSNLOGShmemBuffers(void); +extern Size CSNLOGShmemSize(void); +extern void CSNLOGShmemInit(void); +extern void BootStrapCSNLOG(void); +extern void StartupCSNLOG(bool isUpgrade); +extern void TrimCSNLOG(void); +extern void ShutdownCSNLOG(void); +extern void CheckPointCSNLOG(void); +extern void ExtendCSNLOG(TransactionId newestXact); +extern void TruncateCSNLOG(TransactionId oldestXact); + +#endif /* CSNLOG_H */ diff -uprN postgresql-hll-2.14_old/include/access/cstore_am.h postgresql-hll-2.14/include/access/cstore_am.h --- postgresql-hll-2.14_old/include/access/cstore_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_am.h 2020-12-12 17:06:43.055345561 +0800 @@ -0,0 +1,428 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_am.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_am.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTOREAM_H +#define CSTOREAM_H + +#include "access/cstore_roughcheck_func.h" +#include "access/cstore_minmax_func.h" +#include "cstore.h" +#include "storage/cu.h" +#include "storage/custorage.h" +#include "storage/cucache_mgr.h" +#include "utils/snapshot.h" + +#define MAX_CU_PREFETCH_REQSIZ (64) + +#define MaxDelBitmapSize ((int)DefaultFullCUSize / 8 + 1) + +class BatchCUData; + +// If we load all CUDesc, the memory will be huge, +// So we define this data structure defining the load CUDesc information +// +struct LoadCUDescCtl : public BaseObject { + uint32 curLoadNum; + uint32 lastLoadNum; + uint32 nextCUID; + CUDesc* cuDescArray; + + LoadCUDescCtl(uint32 startCUID) + { + Reset(startCUID); + cuDescArray = (CUDesc*)palloc0(sizeof(CUDesc) * u_sess->attr.attr_storage.max_loaded_cudesc); + } + + virtual ~LoadCUDescCtl() + { + } + + virtual void Destroy() + { + if (cuDescArray != NULL) { + pfree(cuDescArray); + cuDescArray = NULL; + } + } + + inline bool HasFreeSlot() + { + return curLoadNum < (uint32)u_sess->attr.attr_storage.max_loaded_cudesc; + } + + inline void Reset(uint32 startCUID) + { + curLoadNum = 0; + lastLoadNum = 0; + nextCUID = startCUID; + } +}; + +struct CStoreScanState; +typedef CStoreScanState *CStoreScanDesc; + +struct CStoreIndexScanState; + +/* + * CStore include a set of common API for ColStore. + * In future, we can add more API. + */ +class CStore : public BaseObject { + // public static area +public: + // create data files + static void CreateStorage(Relation rel, Oid newRelFileNode = InvalidOid); + + // unlink data files + static void UnlinkColDataFile(const RelFileNode &rnode, AttrNumber attrnum, bool bcmIncluded); + static void InvalidRelSpaceCache(RelFileNode *rnode); + + // trunccate data files which relation CREATE and TRUNCATE in same XACT block + static void TruncateStorageInSameXact(Relation rel); + + // form and deform CU Desc tuple + static HeapTuple FormCudescTuple(_in_ CUDesc *pCudesc, _in_ TupleDesc pCudescTupDesc, + _in_ Datum values[CUDescMaxAttrNum], _in_ bool nulls[CUDescMaxAttrNum], + _in_ Form_pg_attribute pColAttr); + + static void DeformCudescTuple(_in_ HeapTuple pCudescTup, _in_ TupleDesc pCudescTupDesc, + _in_ Form_pg_attribute pColAttr, _out_ CUDesc *pCudesc); + + // Save CU description information into CUDesc table + static void SaveCUDesc(_in_ Relation rel, _in_ CUDesc *cuDescPtr, _in_ int col, _in_ int options); + + // form and deform VC CU Desc tuple. + // We add a virtual column for marking deleted rows. + // The VC is divided into CUs. + static HeapTuple FormVCCUDescTup(_in_ TupleDesc cudesc, _in_ const char *delMask, _in_ uint32 cuId, + _in_ int32 rowCount, _in_ uint32 magic); + + static void SaveVCCUDesc(_in_ Oid cudescOid, _in_ uint32 cuId, _in_ int rowCount, _in_ uint32 magic, + _in_ int options, _in_ const char *delBitmap = NULL); + + static bool IsTheWholeCuDeleted(_in_ char *delBitmap, _in_ int rowsInCu); + bool IsTheWholeCuDeleted(_in_ int rowsInCu); + + // get Min/Max value from given *pCudesc*. + // *min* = true, return the Min value. + // *min* = false, return the Max value. + static Datum CudescTupGetMinMaxDatum(_in_ CUDesc *pCudesc, _in_ Form_pg_attribute pColAttr, _in_ bool min, + _out_ bool *shouldFree); + + static bool SetCudescModeForMinMaxVal(_in_ bool fullNulls, _in_ bool hasMinMaxFunc, _in_ bool hasNull, + _in_ int maxVarStrLen, _in_ int attlen, __inout CUDesc *cuDescPtr); + + static bool SetCudescModeForTheSameVal(_in_ bool fullNulls, _in_ FuncSetMinMax SetMinMaxFunc, _in_ int attlen, + _in_ Datum attVal, __inout CUDesc *cuDescPtr); + + static uint32 GetMaxCUID(_in_ Oid cudescHeap, _in_ TupleDesc cstoreRelTupDesc, _in_ Snapshot snapshotArg = NULL); + static uint32 GetMaxIndexCUID(_in_ Relation heapRel, _in_ List *btreeIndex); + + static CUPointer GetMaxCUPointerFromDesc(_in_ int attrno, _in_ Oid cudescHeap); + + static CUPointer GetMaxCUPointer(_in_ int attrno, _in_ Relation rel); + +public: + CStore(); + virtual ~CStore(); + virtual void Destroy(); + + // Scan APIs + void InitScan(CStoreScanState *state, Snapshot snapshot = NULL); + void InitReScan(); + void InitPartReScan(Relation rel); + bool IsEndScan() const; + + // late read APIs + bool IsLateRead(int id) const; + void ResetLateRead(); + + // update cstore scan timing flag + void SetTiming(CStoreScanState *state); + + // CStore scan : pass vector to VE. + void ScanByTids(_in_ CStoreIndexScanState *state, _in_ VectorBatch *idxOut, _out_ VectorBatch *vbout); + void CStoreScanWithCU(_in_ CStoreScanState *state, BatchCUData *tmpCUData, _in_ bool isVerify = false); + + // Load CUDesc information of column according to loadInfoPtr + // LoadCUDescCtrl include maxCUDescNum for this load, because if we load all + // it need big memory to hold + // + bool LoadCUDesc(_in_ int col, __inout LoadCUDescCtl *loadInfoPtr, _in_ bool prefetch_control, + _in_ Snapshot snapShot = NULL); + + // Get CU description information from CUDesc table + bool GetCUDesc(_in_ int col, _in_ uint32 cuid, _out_ CUDesc *cuDescPtr, _in_ Snapshot snapShot = NULL); + + // Get tuple deleted information from VC CU description. + void GetCUDeleteMaskIfNeed(_in_ uint32 cuid, _in_ Snapshot snapShot); + + bool GetCURowCount(_in_ int col, __inout LoadCUDescCtl *loadCUDescInfoPtr, _in_ Snapshot snapShot); + // Get live row numbers. + int64 GetLivedRowNumbers(int64 *deadrows); + + // Get CU data. + // Note that the CU is pinned + CU *GetCUData(_in_ CUDesc *cuDescPtr, _in_ int colIdx, _in_ int valSize, _out_ int &slotId); + + CU *GetUnCompressCUData(Relation rel, int col, uint32 cuid, _out_ int &slotId, ForkNumber forkNum = MAIN_FORKNUM, + bool enterCache = true) const; + + // Fill Vector APIs + int FillVecBatch(_out_ VectorBatch *vecBatchOut); + + // Fill Vector of column + template + int FillVector(_in_ int colIdx, _in_ CUDesc *cu_desc_ptr, _out_ ScalarVector *vec); + + template + void FillVectorByTids(_in_ int colIdx, _in_ ScalarVector *tids, _out_ ScalarVector *vec); + + template + void FillVectorLateRead(_in_ int seq, _in_ ScalarVector *tids, _in_ CUDesc *cuDescPtr, _out_ ScalarVector *vec); + + void FillVectorByIndex(_in_ int colIdx, _in_ ScalarVector *tids, _in_ ScalarVector *srcVec, + _out_ ScalarVector *destVec); + + // Fill system column into ScalarVector + int FillSysColVector(_in_ int colIdx, _in_ CUDesc *cu_desc_ptr, _out_ ScalarVector *vec); + + template + void FillSysVecByTid(_in_ ScalarVector *tids, _out_ ScalarVector *destVec); + + template + int FillTidForLateRead(_in_ CUDesc *cuDescPtr, _out_ ScalarVector *vec); + + void FillScanBatchLateIfNeed(__inout VectorBatch *vecBatch); + + /* Set CU range for scan in redistribute. */ + void SetScanRange(); + + // Judge whether dead row + bool IsDeadRow(uint32 cuid, uint32 row) const; + + void CUListPrefetch(); + void CUPrefetch(CUDesc *cudesc, int col, AioDispatchCUDesc_t **dList, int &count, File *vfdList); + + /* Point to scan function */ + typedef void (CStore::*ScanFuncPtr)(_in_ CStoreScanState *state, _out_ VectorBatch *vecBatchOut); + void RunScan(_in_ CStoreScanState *state, _out_ VectorBatch *vecBatchOut); + + int GetLateReadCtid() const; + void IncLoadCuDescCursor(); + +public: // public vars + // Inserted/Scan Relation + Relation m_relation; + +private: // private methods. + // CStore scan : pass vector to VE. + void CStoreScan(CStoreScanState *state, VectorBatch *vecBatchOut); + void CStoreMinMaxScan(CStoreScanState *state, VectorBatch *vecBatchOut); + + // The number of holding CUDesc is max_loaded_cudesc + // if we load all CUDesc once, the memory will not enough. + // So we load CUdesc once for max_loaded_cudesc + void LoadCUDescIfNeed(); + + // Do RoughCheck if need + // elimiate CU by min/max value of CU. + void RoughCheckIfNeed(_in_ CStoreScanState *state); + + // Refresh cursor + void RefreshCursor(int row, int deadRows); + + void InitRoughCheckEnv(CStoreScanState *state); + + void BindingFp(CStoreScanState *state); + void InitFillVecEnv(CStoreScanState *state); + + // indicate whether only accessing system column or const column. + // true, means that m_virtualCUDescInfo is a new and single object. + // false, means that m_virtualCUDescInfo just a pointer to m_CUDescInfo[0]. + // + inline bool OnlySysOrConstCol(void) + { + return ((m_colNum == 0 && m_sysColNum != 0) || m_onlyConstCol); + } + + int LoadCudescMinus(int start, int end) const; + bool HasEnoughCuDescSlot(int start, int end) const; + bool NeedLoadCUDesc(int32 &cudesc_idx); + void IncLoadCuDescIdx(int &idx) const; + bool RoughCheck(CStoreScanKey scanKey, int nkeys, int cuDescIdx); + + void FillColMinMax(CUDesc *cuDescPtr, ScalarVector *vec, int pos); + + inline TransactionId GetCUXmin(uint32 cuid); + + // only called by GetCUData() + CUUncompressedRetCode GetCUDataFromRemote(CUDesc *cuDescPtr, CU *cuPtr, int colIdx, int valSize, const int &slotId); + + /* defence functions */ + void CheckConsistenceOfCUDescCtl(void); + void CheckConsistenceOfCUDesc(int cudescIdx) const; + void CheckConsistenceOfCUData(CUDesc *cuDescPtr, CU *cu, AttrNumber col) const; + +private: + // control private memory used locally. + // m_scanMemContext: for objects alive during the whole cstore-scan + // m_perScanMemCnxt: for memory per heap table scan and temp space + // during decompression. + MemoryContext m_scanMemContext; + MemoryContext m_perScanMemCnxt; + + // current snapshot to use. + Snapshot m_snapshot; + + // 1. Accessed user column id + // 2. Accessed system column id + // 3. flags for late read + // 4. each CU storage fro each user column. + int *m_colId; + int *m_sysColId; + bool *m_lateRead; + CUStorage **m_cuStorage; + + // 1. The CUDesc info of accessed columns + // 2. virtual CUDesc for sys or const columns + LoadCUDescCtl **m_CUDescInfo; + LoadCUDescCtl *m_virtualCUDescInfo; + + // Accessed CUDesc index array + // After RoughCheck, which CU will be accessed + // + int *m_CUDescIdx; + + // adio param + int m_lastNumCUDescIdx; + int m_prefetch_quantity; + int m_prefetch_threshold; + bool m_load_finish; + + // Current scan position inside CU + // + int *m_scanPosInCU; + + // Rough Check Functions + // + RoughCheckFunc *m_RCFuncs; + + typedef int (CStore::*m_colFillFun)(int seq, CUDesc *cuDescPtr, ScalarVector *vec); + + typedef struct { + m_colFillFun colFillFun[2]; + } colFillArray; + + typedef void (CStore::*FillVectorByTidsFun)(_in_ int colIdx, _in_ ScalarVector *tids, _out_ ScalarVector *vec); + + typedef void (CStore::*FillVectorLateReadFun)(_in_ int seq, _in_ ScalarVector *tids, _in_ CUDesc *cuDescPtr, + _out_ ScalarVector *vec); + + FillVectorByTidsFun *m_fillVectorByTids; + FillVectorLateReadFun *m_fillVectorLateRead; + colFillArray *m_colFillFunArrary; + + typedef void (CStore::*fillMinMaxFuncPtr)(CUDesc *cuDescPtr, ScalarVector *vec, int pos); + fillMinMaxFuncPtr *m_fillMinMaxFunc; + + ScanFuncPtr m_scanFunc; // cstore scan function ptr + + // node id of this plan + int m_plan_node_id; + + // 1. Number of accessed user columns + // 2. Number of accessed system columns. + int m_colNum; + int m_sysColNum; + + // 1. length of loaded CUDesc info or virtual CUDesc info + // 2. length of m_CUDescIdx + int m_NumLoadCUDesc; + int m_NumCUDescIdx; + + // 1. CU id of current deleted mask. + // 2. Current access cursor in m_CUDescIdx + // 3. Current access row cursor inside CU + uint32 m_delMaskCUId; + int m_cursor; + int m_rowCursorInCU; + + uint32 m_startCUID; /* scan start CU ID. */ + uint32 m_endCUID; /* scan end CU ID. */ + + unsigned char m_cuDelMask[MaxDelBitmapSize]; + + // whether dead rows exist + bool m_hasDeadRow; + // Is need do rough check + bool m_needRCheck; + // Only access const column + bool m_onlyConstCol; + + bool m_timing_on; /* timing CStoreScan steps */ + + RangeScanInRedis m_rangeScanInRedis; /* if it is a range scan at redistribution time */ + + // cbtree index flag + bool m_useBtreeIndex; + + // the first column index, start from 0 + int m_firstColIdx; + + // for late read + // the cuDesc id of batch in the cuDescArray. + int m_cuDescIdx; + + // for late read + // the first late read column idx which is filled with ctid. + int m_laterReadCtidColIdx; +}; + +// CStore Scan interface for sequential scan +// +extern void InitScanDeltaRelation(CStoreScanState *node, Snapshot snapshot); +extern void ScanDeltaStore(CStoreScanState *node, VectorBatch *outBatch, List *indexqual); +extern void EndScanDeltaRelation(CStoreScanState *node); +extern CStoreScanDesc CStoreBeginScan(Relation relation, int colNum, int16 *colIdx, Snapshot snapshot, bool scanDelta); +extern VectorBatch *CStoreGetNextBatch(CStoreScanDesc cstoreScanState); +extern bool CStoreIsEndScan(CStoreScanDesc cstoreScanState); +extern void CStoreEndScan(CStoreScanDesc cstoreScanState); + +extern void CStoreScanNextTrunkOfCU(_in_ CStoreScanDesc cstoreScanState, __inout BatchCUData *tmpCUData); + +// CStoreRelGetCUNum +// Get CU numbers of relation by now +// +extern uint32 CStoreRelGetCUNumByNow(CStoreScanDesc cstoreScanState); +// Delete the info of the dropped column from the cudesc for a cstore table +extern void CStoreDropColumnInCuDesc(Relation rel, AttrNumber attrnum); +/* CStoreGet1stUndroppedColIdx get the first colum index that is not dropped */ +extern int CStoreGetfstColIdx(Relation rel); + +void CStoreAbortCU(); +void VerifyAbortCU(); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_delete.h postgresql-hll-2.14/include/access/cstore_delete.h --- postgresql-hll-2.14_old/include/access/cstore_delete.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_delete.h 2020-12-12 17:06:43.056345574 +0800 @@ -0,0 +1,95 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_delete.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_delete.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORE_DELETE_H +#define CSTORE_DELETE_H + +#include "access/cstore_am.h" +#include "utils/batchsort.h" +#include "access/cstore_vector.h" + +class CStoreDelete : public BaseObject { +public: + CStoreDelete(_in_ Relation rel, _in_ EState *estate, _in_ bool is_update_cu, _in_ Plan *plan, + _in_ MemInfoArg *ArgmemInfo); + virtual ~CStoreDelete(); + virtual void Destroy(); + void InitDeleteMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + void ExecDelete(_in_ Relation rel, _in_ ScalarVector *vecRowId, _in_ Snapshot snapshot, _in_ Oid tableOid); + void InitSortState(); + void InitSortState(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void PutDeleteBatch(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 ExecDelete(); + void setReportErrorForUpdate(bool isEnable) + { + m_isRptRepeatTupErrForUpdate = isEnable; + }; + /* record memory auto spread info for delete sort. */ + MemInfoArg *m_DelMemInfo; + +protected: + void CollectPartDeltaOids(); + void UpdateVCBitmap(_in_ Relation rel, _in_ uint32 cuid, _in_ const int *rowoffset, _in_ int updateRowNum, + _in_ Snapshot snapshot); + void InitDeleteSortStateForTable(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void InitDeleteSortStateForPartition(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void PutDeleteBatchForTable(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + void PutDeleteBatchForPartition(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + void PutDeleteBatchForUpdate(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 ExecDeleteForTable(); + uint64 ExecDeleteForPartition(); + bool IsFull() const; + void ResetSortState(); + + Relation m_relation; + Relation m_deltaRealtion; + List *m_partDeltaOids; + + bool m_isUpdate; + + EState *m_estate; + + TupleDesc m_sortTupDesc; + Batchsortstate *m_deleteSortState; + int m_partidIdx; + int m_ctidIdx; + bool m_isTupDescCreateBySelf; + + VectorBatch *m_sortBatch; + int *m_rowOffset; + + int m_maxSortNum; + int m_curSortedNum; + uint64 m_totalDeleteNum; + + // report repeat delete tuple error for update + bool m_isRptRepeatTupErrForUpdate; + + void (CStoreDelete::*m_InitDeleteSortStatePtr)(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, + _in_ int ctidAttNo); + void (CStoreDelete::*m_PutDeleteBatchPtr)(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 (CStoreDelete::*m_ExecDeletePtr)(); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_insert.h postgresql-hll-2.14/include/access/cstore_insert.h --- postgresql-hll-2.14_old/include/access/cstore_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_insert.h 2020-12-12 17:06:43.056345574 +0800 @@ -0,0 +1,419 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_insert.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_insert.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_INSERT_H +#define CSTORE_INSERT_H + +#include "access/cstore_am.h" +#include "access/cstore_psort.h" +#include "access/cstore_vector.h" +#include "access/cstore_minmax_func.h" +#include "storage/cstore_compress.h" +#include "storage/spin.h" + +struct InsertArg { + /* map to CStoreInsert::m_tmpBatchRows. + * + * because it's a temp batchrows, so + * 1. it's used by each batch inserter when PCK exists, or + * 2. it's shared by each partition when inserting into partitioned table, + */ + bulkload_rows *tmpBatchRows; + + /* map to CStoreInsert::m_idxBatchRow + * + * because it's a temp batchrows, so + * 1. it's shared by each index inserter when inserting into ordinary table, or + * 2. it's shared by each index inserter of each partition when inserting into + * partitioned table. + */ + bulkload_rows *idxBatchRow; + + ResultRelInfo *es_result_relations; + + /* sort type: tuple sorting or batch sorting */ + int sortType; + + /* which function will be called, + * 1. false => void CStoreInsert::BatchInsert(bulkload_rows *batchRowPtr, int options) + * 2. true => void CStoreInsert::BatchInsert(VectorBatch *pBatch, int options) + * this value must be defined explicitly. + */ + bool using_vectorbatch; + + InsertArg() + { + tmpBatchRows = NULL; + idxBatchRow = NULL; + es_result_relations = NULL; + sortType = TUPLE_SORT; /* default psort type */ + using_vectorbatch = true; /* caller should specify the right way */ + } +}; + +/* + * This class provides some API for batch insert in ColStore. + * In future, we can add more API. + */ +class CStoreInsert : public BaseObject { +public: + CStoreInsert(_in_ Relation relation, _in_ const InsertArg &args, _in_ bool is_update_cu, _in_ Plan *plan, + _in_ MemInfoArg *ArgmemInfo); + + virtual ~CStoreInsert(); + virtual void Destroy(); + + void BeginBatchInsert(const InsertArg &args); + void EndBatchInsert(); + + /* + * Batch insert interface + */ + void BatchInsert(bulkload_rows *batchRowPtr, int options); + void BatchInsert(VectorBatch *pVec, int options); + void BatchInsertCommon(bulkload_rows *batchRowPtr, int options); + void FlashData(int options); + + void CUInsert(_in_ BatchCUData *CUData, _in_ int options); + + void SetEndFlag(); + + inline bool IsEnd() + { + return m_insert_end_flag; + } + + static void InitInsertArg(Relation rel, ResultRelInfo *resultRelInfo, bool using_vectorbatch, InsertArg &args); + static void DeInitInsertArg(InsertArg &args); + static void InitIndexInsertArg(Relation heap_rel, const int *keys_map, int nkeys, InsertArg &args); + void InitInsertMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + Relation m_relation; + CU ***m_aio_cu_PPtr; + AioDispatchCUDesc_t ***m_aio_dispath_cudesc; + int *m_aio_dispath_idx; + + /* memory info for memory adjustment */ + MemInfoArg *m_cstorInsertMem; + +private: + void FreeMemAllocateByAdio(); + // Whether need partial clustering when load + // + inline bool NeedPartialSort(void) const; + + // Write CU data and CUDesc + // + void SaveAll(int options, const char *delBitmap = NULL); + + void CUListFlushAll(int attno); + void CUListWriteCompeleteIO(int col, int count); + + void CUWrite(int attno, int col); + void CUListWrite(); + + // Compress batch rows into CU + // Get min/max of CU + // + CU *FormCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr); + Size FormCUTInitMem(CU *cuPtr, bulkload_rows *batchRowPtr, int col, bool hasNull); + void FormCUTCopyMem(CU *cuPtr, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, Size dtSize, int col, bool hasNull); + template + void FormCUT(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + template + void FormCUTNumeric(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + template + void FormCUTNumString(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + + template + bool FormNumberStringCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + + template + bool TryFormNumberStringCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr, uint32 atttypid); + + void InitIndexColId(int which_index); + + void InitIndexInfo(); + + void InitDeltaInfo(); + + // Insert delta table + void InsertDeltaTable(bulkload_rows *batchRowPtr, int options); + + // Insert index table + // + void InsertIdxTableIfNeed(bulkload_rows *batchRowPtr, uint32 cuId); + + void InsertNotPsortIdx(int indice); + + void FlushIndexDataIfNeed(); + + void InitFuncPtr(); + + void InitColSpaceAlloc(); + + bool TryEncodeNumeric(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr, bool hasNull); + void DoBatchInsert(int options); + typedef void (CStoreInsert::*m_formCUFunc)(int, bulkload_rows *, CUDesc *, CU *); + struct FormCUFuncArray { + m_formCUFunc colFormCU[2]; + }; + inline void SetFormCUFuncArray(Form_pg_attribute attr, int col); + + bool m_isUpdate; + /* Function Pointer Array Area */ + FuncSetMinMax *m_setMinMaxFuncs; /* min/max value function */ + FormCUFuncArray *m_formCUFuncArray; /* Form CU function pointer */ + + /* If relation has cluster key, it will work for partial sort */ + CStorePSort *m_sorter; + + CUDesc **m_cuDescPPtr; /* The cudesc of all columns of m_relation */ + CU **m_cuPPtr; /* The CU of all columns of m_relation; */ + CUStorage **m_cuStorage; /* CU storage */ + compression_options *m_cuCmprsOptions; /* compression filter */ + cu_tmp_compress_info m_cuTempInfo; /* temp info for CU compression */ + + /* buffered batchrows for many VectorBatch values */ + bulkload_rows *m_bufferedBatchRows; + + /* temp batchrows for fetching values from sort processor */ + bulkload_rows *m_tmpBatchRows; + + /* memory context for avoiding memory leaks during bulk-insert */ + MemoryContext m_tmpMemCnxt; + MemoryContext m_batchInsertCnxt; + + /* work for delta insert */ + Relation m_delta_relation; + TupleDesc m_delta_desc; + bool m_append_only; /* don't insert into delta when true */ + + /* work for Index insert */ + ResultRelInfo *m_resultRelInfo; /* contain index meta info */ + + Relation *m_idxRelation; /* index relations */ + InsertArg *m_idxInsertArgs; /* index inserting arguments */ + CStoreInsert **m_idxInsert; /* index inserter */ + int **m_idxKeyAttr; /* index keys */ + int *m_idxKeyNum; /* index keys' number */ + bulkload_rows *m_idxBatchRow; /* shallow copy for index insert */ + EState *m_estate; /* estate information */ + ExprContext *m_econtext; /* curr context for expr eval */ + Datum *m_fake_values; /* value array to form fake heap tuple */ + bool *m_fake_isnull; /* null array to from fake heap tuple */ + + /* ADIO info */ + MemoryContext m_aio_memcnxt; + int32 *m_aio_cache_write_threshold; + File **m_vfdList; + + /* the max number of values within one CU */ + int m_fullCUSize; + + /* the number delta threshold */ + int m_delta_rows_threshold; + + /* compression options. */ + int16 m_compress_modes; + + /* indicate the end of insert or not */ + bool m_insert_end_flag; +}; + +enum PartitionCacheStrategy { + CACHE_EACH_PARTITION_AS_POSSIBLE = 0, // cache every partition as much as possible, default strategy + FLASH_WHEN_SWICH_PARTITION // flash cached data when switch partition +}; + +class PartitionValueCache : public BaseObject { +public: + PartitionValueCache(Relation rel); + + virtual ~PartitionValueCache(); + virtual void Destroy(); + + // Serialize row value to partition value cache + Size WriteRow(Datum *values, const bool *nulls); + + // Deserialize values from partition value cache + int ReadBatchRow(bulkload_rows *batch, Datum *values, bool *nulls); + + void Reset(); + + void EndWrite() + { + FlushData(); + } + + int m_rows; + +private: + int ReadRow(_out_ Datum *values, _out_ bool *nulls); + + int InternalRead(char *buf, int len); + + int InternalWrite(const char *buf, int len); + + FORCE_INLINE int InternalWriteInt(int data) + { + return InternalWrite((char *)&data, sizeof(data)); + } + + int FillBuffer(); + + void FlushData(); + + Relation m_rel; + char *m_buffer; + uint64 m_writeOffset; + File m_fd; + int m_bufCursor; + int m_dataLen; + uint64 m_readOffset; + + const static int MAX_BUFFER_SIZE = 32768; +}; + +// Work for loading partition table +// Do real batch insert using CStoreInsert objection for each partition +// Note that we should control memory size for each partition +// +class CStorePartitionInsert : public CStore { +public: + CStorePartitionInsert(_in_ Relation relation, _in_ ResultRelInfo *es_result_relations, _in_ int type, + _in_ bool is_update_cu, _in_ Plan *plan, _in_ MemInfoArg *ArgmemInfo); + virtual ~CStorePartitionInsert(); + virtual void Destroy(); + void BatchInsert(_in_ Datum *values, _in_ const bool *nulls, _in_ int options); + void BatchInsert(VectorBatch *batch, int hi_options); + + void EndBatchInsert(); + void SetEndFlag() + { + } + + void SetPartitionCacheStrategy(int partition_cache_strategy); + bool hasEnoughMem(int partitionidx, int64 memsize_used); + int findBiggestPartition() const; + void InitInsertPartMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + /* record memory auto spread info. bulkload memory */ + MemInfoArg *m_memInfo; + +private: + void InitValueCache(); + + void DeInitValueCache(); + + bool CacheValues(Datum *values, const bool *nulls, int partitionidx); + + void SaveCacheValues(int partitionidx, bool doFlush, int options); + + void MoveBatchRowToPartitionValueCache(int partitionidx); + + // Try to get a batchrow from free list + // + bulkload_rows *GetBatchRow(int partitionIdx); + + // Return the batchrow held by the partition to the free list + // + void ReleaseBatchRow(int partitionIdx); + + /* + * @Description: is insert value switch partition + * @IN partitionIdx: current partition number + * @Return: true switch partiton, false not switch + */ + inline bool IsSwitchPartition(int partitionIdx) + { + return (m_last_insert_partition != -1) && (m_last_insert_partition != partitionIdx); + }; + + inline Relation GetPartFakeRelation(int partitionIdx) + { + AutoContextSwitch contextSwitcher(m_cstorePartMemContext); + + Relation partitionRelation = m_storePartFakeRelation[partitionIdx]; + if (NULL == partitionRelation) { + Assert(m_relation->partMap->type == PART_TYPE_RANGE); + + PartitionIdentifier partitionIdentifier; + partitionIdentifier.partSeq = partitionIdx; + partitionIdentifier.partArea = PART_AREA_RANGE; + Oid partoid = partIDGetPartOid(m_relation, &partitionIdentifier); + Partition partition = partitionOpen(m_relation, partoid, RowExclusiveLock); + partitionRelation = partitionGetRelation(m_relation, partition); + m_storePartFakeRelation[partitionIdx] = partitionRelation; + partitionClose(m_relation, partition, NoLock); + } + + return partitionRelation; + }; + + // CStoreInsert object for each partition + // + CStoreInsert **m_insert; + + Relation *m_storePartFakeRelation; + int m_partitionNum; + InsertArg m_insertArgs; + + bool m_isUpdate; + /* disk cache objects for each partition */ + PartitionValueCache **m_partValCache; + /* flag to use disk cache */ + bool *m_partUseCahce; + List *m_batchFreeList; + + /* batchrows for each partition */ + bulkload_rows **m_partRelBatchRows; + /* temp batchrows for disk cache */ + bulkload_rows *m_partTmpBatch; + + /* temp memory context to avoid space leaks during disk cache inserting */ + MemoryContext m_tmpMemCnxt; + /* memory context for all objects alive during partitioned table inserting */ + MemoryContext m_cstorePartMemContext; + + /* partition cache strategy */ + int m_cache_strategy; + + /* last insert partition number */ + int m_last_insert_partition; + + /* all partition relation keep the same value to the one of their parent + * relation. so we can share this var between all the partition relations. + */ + int m_fullCUSize; + Datum *m_val; + bool *m_null; + Datum *m_tmp_val; + bool *m_tmp_null; + + Size *m_diskFileSize; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_minmax_func.h postgresql-hll-2.14/include/access/cstore_minmax_func.h --- postgresql-hll-2.14_old/include/access/cstore_minmax_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_minmax_func.h 2020-12-12 17:06:43.056345574 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_minmax_func.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_minmax_func.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_MINMAX_FUNC_H +#define CSTORE_MINMAX_FUNC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/cu.h" + +typedef void (*FuncSetMinMax)(Datum v, CUDesc *cuDescPtr, bool *); +typedef void (*CompareDatum)(char *minval, char *maxval, Datum v, bool *first, int *varstr_maxlen); +typedef void (*FinishCompareDatum)(const char *minval, const char *maxval, CUDesc *cuDescPtr); + +extern FuncSetMinMax GetMinMaxFunc(Oid typeOid); + +extern CompareDatum GetCompareDatumFunc(Oid typeOid); +extern FinishCompareDatum GetFinishCompareDatum(Oid typeOid); +extern bool IsCompareDatumDummyFunc(CompareDatum f); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_psort.h postgresql-hll-2.14/include/access/cstore_psort.h --- postgresql-hll-2.14_old/include/access/cstore_psort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_psort.h 2020-12-12 17:06:43.056345574 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_psort.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_psort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTOREPSORT_H +#define CSTOREPSORT_H + +#include "access/cstore_vector.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/batchsort.h" +#include "utils/tuplesort.h" +#include "utils/rel.h" +#include "utils/relcache.h" +#include "storage/cu.h" + +enum PSORT_TYPE { + TUPLE_SORT = 0, + BATCH_SORT +}; +extern THR_LOCAL int psort_work_mem; + +#define InvalidBathCursor (-1) +#define BathCursorIsValid(_c) ((_c) > InvalidBathCursor) + +class CStorePSort : public BaseObject { +public: + CStorePSort(Relation rel, AttrNumber *sortKeys, int keyNum, int type, MemInfoArg *m_memInfo = NULL); + + virtual ~CStorePSort(); + + virtual void Destroy(); + void InitPsortMemArg(MemInfoArg *ArgmemInfo); + + void PutVecBatch(Relation rel, VectorBatch *pVecBatch); + + void PutBatchValues(bulkload_rows *batchRowPtr); + + void PutTuple(_in_ Datum *values, _in_ bool *nulls); + + void PutSingleTuple(Datum *values, bool *nulls); + + void RunSort(); + + void GetBatchValue(bulkload_rows *batchRowsPtr); + + VectorBatch *GetVectorBatch(); + + TupleTableSlot *GetTuple(); + + void Reset(bool endFlag); + + bool IsFull() const; + + int GetRowNum() const; + + void ResetTupleSortState(bool endFlag); + + void ResetBatchSortState(bool endFlag); + + void GetBatchValueFromTupleSort(bulkload_rows *batchRowsPtr); + + void GetBatchValueFromBatchSort(bulkload_rows *batchRowsPtr); + + Tuplesortstate *m_tupleSortState; + Batchsortstate *m_batchSortState; + VectorBatch *m_vecBatch; + TupleTableSlot *m_tupleSlot; + +private: +#ifdef USE_ASSERT_CHECKING + void AssertCheck(void); +#endif + int m_type; + + Relation m_rel; + AttrNumber *m_sortKeys; + int m_keyNum; + + Oid *m_sortOperators; + Oid *m_sortCollations; + bool *m_nullsFirst; + + TupleDesc m_tupDesc; + + int m_curSortedRowNum; + int m_partialClusterRowNum; + int m_fullCUSize; + // current index of tuple to fetch. + int m_vecBatchCursor; + + MemoryContext m_psortMemContext; + + Datum *m_val; + + bool *m_null; + + MemInfoArg *m_psortMemInfo; + + void (CStorePSort::*m_funcGetBatchValue)(bulkload_rows *batchRowsPtr); + + void (CStorePSort::*m_funcReset)(bool endFlag); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_rewrite.h postgresql-hll-2.14/include/access/cstore_rewrite.h --- postgresql-hll-2.14_old/include/access/cstore_rewrite.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_rewrite.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,332 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_rewrite.h + * routinues to support Column Store Rewrite + * + * + * IDENTIFICATION + * src/include/access/cstore_rewrite.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_REWRITE_H +#define CSTORE_REWRITE_H + +#include "c.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/cstore_am.h" +#include "access/cstore_minmax_func.h" +#include "access/reloptions.h" +#include "access/transam.h" +#include "access/tupdesc.h" +#include "access/xact.h" +#include "access/xlogutils.h" +#include "catalog/storage.h" +#include "commands/cluster.h" +#include "commands/vacuum.h" +#include "executor/executor.h" +#include "nodes/execnodes.h" +#include "storage/cstore_compress.h" +#include "storage/custorage.h" +#include "utils/fmgroids.h" +#include "utils/memutils.h" +#include "access/heapam.h" + +#define MAX_CSTORE_MERGE_PARTITIONS 31 + +typedef enum CStoreRewriteType { + CSRT_ADD_COL = 0, // --> ADD COLUMN + CSRT_SET_DATA_TYPE, // --> ALTER COLUMN SET DATA TYPE + CSRT_NUM // add new type above please. +} CStoreRewriteType; + +typedef struct ColumnNewValue { + Expr *expr; // expression to compute + ExprState *exprstate; // execution state +} ColumnNewValue; + +typedef struct CStoreRewriteColumn { + AttrNumber attrno; + bool isDropped; + bool isAdded; + bool notNull; + ColumnNewValue *newValue; + + static CStoreRewriteColumn *CreateForAddColumn(AttrNumber attNo); + static CStoreRewriteColumn *CreateForSetDataType(AttrNumber attNo); + static void Destroy(CStoreRewriteColumn **rewriteInfo); +} CStoreRewriteColumn; + +// Bulk Insert For Heap Relation +// +// Notice: we just bulk-insert heap tuples for this heap relation, without +// handling its indexes and triggers, etc. +// +class HeapBulkInsert : public BaseObject { +public: + HeapBulkInsert(Relation cudescHeapRel); + virtual ~HeapBulkInsert(){}; + virtual void Destroy(); + + // interfaces for bulk-insert heap tuples. + // BulkInsertCopy() will copy this tuple before appending, + // but BulkInsert() will not. so call the pair of EnterBulkMemCnxt() + // and LeaveBulkMemCnxt() before BulkInsert() is invoked. + // + void BulkInsert(HeapTuple tuple); + void BulkInsertCopy(HeapTuple tuple); + void Finish(); + + FORCE_INLINE void EnterBulkMemCnxt() + { + m_OldMemCnxt = MemoryContextSwitchTo(m_MemCnxt); + Assert(m_OldMemCnxt != NULL); + } + + FORCE_INLINE void LeaveBulkMemCnxt() + { + Assert(m_OldMemCnxt != NULL); + (void)MemoryContextSwitchTo(m_OldMemCnxt); + m_OldMemCnxt = NULL; + } + + // limit private memory context' upmost resource to use. + static const int MaxBufferedTupNum = 10000; + static const Size MaxBufferedTupSize = 8192 * 128; + +private: + MemoryContext m_OldMemCnxt; + MemoryContext m_MemCnxt; + HeapTuple *m_BufferedTups; + Size m_BufferedTupsSize; + int m_BufferedTupsNum; + + Relation m_HeapRel; + BulkInsertState m_BIState; + CommandId m_CmdId; + int m_InsertOpt; + + template + void Append(HeapTuple tuple); + + FORCE_INLINE void Flush(); + FORCE_INLINE bool Full() const; +}; + +class LoadSingleCu : public BaseObject { +public: + // load data for single cu. + // caller should delete CU object returned. + static CU *LoadSingleCuData(_in_ CUDesc *pCuDesc, _in_ int colIdx, _in_ int colAttrLen, _in_ int colTypeMode, + _in_ uint32 colAtttyPid, _in_ Relation rel, __inout CUStorage *pCuStorage); +}; + +// remember those relation oids +// which ALTER TABLE SET DATATYPE is exec on. +class CStoreAlterRegister : public BaseObject { +public: + CStoreAlterRegister() : m_Oids(NULL), m_used(0), m_maxs(0) + { + } + virtual ~CStoreAlterRegister() + { + } + virtual void Destroy(); + + void Add(Oid relid); + bool Find(Oid relid) const; + +private: + Oid *m_Oids; // Oid array + int m_used; // Oid used number + int m_maxs; // Oid array max number + + bool DynSearch(Oid relid, int *pos) const; +}; + +// GetCstoreAlterReg(): get the global instance, and create it the first time. +// DestroyCstoreAlterReg(): destroy the global instance in COMMIT or ROLLBACK. +extern CStoreAlterRegister *GetCstoreAlterReg(); +extern void DestroyCstoreAlterReg(); + +class CStoreRewriter : public BaseObject { +public: + CStoreRewriter(Relation oldHeapRel, TupleDesc oldTupDesc, TupleDesc newTupDesc); + virtual ~CStoreRewriter(){}; + virtual void Destroy(); + + void ChangeTableSpace(Relation CUReplicationRel); + void BeginRewriteCols(_in_ int nRewriteCols, _in_ CStoreRewriteColumn **pRewriteCols, + _in_ const int *rewriteColsNum, _in_ bool *rewriteFlags); + void RewriteColsData(); + void EndRewriteCols(); + +public: + template + void HandleCuWithSameValue(_in_ Relation rel, _in_ Form_pg_attribute newColAttr, _in_ Datum newColVal, + _in_ bool newColValIsNull, _in_ FuncSetMinMax func, _in_ CUStorage *colStorage, + __inout CUDesc *newColCudesc, __inout CUPointer *pOffset); + + static void FormCuDataForTheSameVal(__inout CU *cuPtr, _in_ int rowsCntInCu, _in_ Datum newColVal, + _in_ Form_pg_attribute newColAttr); + + static void CompressCuData(CU *cuPtr, CUDesc *cuDesc, Form_pg_attribute newColAttr, int16 compressing_modes); + + FORCE_INLINE + static void SaveCuData(_in_ CU *cuPtr, _in_ CUDesc *cuDesc, _in_ CUStorage *cuStorage); + +private: + FORCE_INLINE bool NeedRewrite() const; + + void AddColumns(_in_ uint32 cuId, _in_ int rowsCntInCu, _in_ bool wholeCuIsDeleted); + void AddColumnInitPhrase1(); + void AddColumnInitPhrase2(_in_ CStoreRewriteColumn *addColInfo, _in_ int idx); + void AddColumnDestroy(); + + void SetDataType(_in_ uint32 cuId, _in_ HeapTuple *cudescTup, _in_ TupleDesc oldCudescTupDesc, + _in_ const char *delMaskDataPtr, _in_ int rowsCntInCu, _in_ bool wholeCuIsDeleted); + void SetDataTypeInitPhase1(); + void SetDataTypeInitPhase2(_in_ CStoreRewriteColumn *sdtColInfo, _in_ int idx); + void SetDataTypeDestroy(); + + FORCE_INLINE + void SetDataTypeHandleFullNullCu(_in_ CUDesc *oldColCudesc, _out_ CUDesc *newColCudesc); + + void SetDataTypeHandleSameValCu(_in_ int sdtIndex, _in_ CUDesc *oldColCudesc, _out_ CUDesc *newColCudesc); + + void SetDataTypeHandleNormalCu(_in_ int sdtIndex, _in_ const char *delMaskDataPtr, _in_ CUDesc *oldColCudesc, + _out_ CUDesc *newColCudesc); + + void FetchCudescFrozenXid(Relation oldCudescHeap); + + void InsertNewCudescTup(_in_ CUDesc *pCudesc, _in_ TupleDesc pCudescTupDesc, _in_ Form_pg_attribute pColNewAttr); + + void HandleWholeDeletedCu(_in_ uint32 cuId, _in_ int rowsCntInCu, _in_ int nRewriteCols, + _in_ CStoreRewriteColumn **rewriteColsInfo); + + void FlushAllCUData() const; + +private: + Relation m_OldHeapRel; + TupleDesc m_OldTupDesc; + TupleDesc m_NewTupDesc; + + Oid m_NewCuDescHeap; + bool *m_ColsRewriteFlag; + + // Set New Tablespace + bool m_TblspcChanged; + Oid m_TargetTblspc; + Oid m_TargetRelFileNode; + /* user a new relation for CU Replication + * if tablespace is changed, we used a spicail CU Replication relation for new relfilenode. + * else heap relation is also available. + */ + Relation m_CUReplicationRel; + CUPointer *m_SDTColAppendOffset; + + // ADD COLUMN + int m_AddColsNum; + CStoreRewriteColumn **m_AddColsInfo; + CUStorage **m_AddColsStorage; + FuncSetMinMax *m_AddColsMinMaxFunc; + CUPointer *m_AddColsAppendOffset; + + // SET DATA TYPE + int m_SDTColsNum; + CStoreRewriteColumn **m_SDTColsInfo; + CUStorage **m_SDTColsReader; + FuncSetMinMax *m_SDTColsMinMaxFunc; + CUStorage **m_SDTColsWriter; + Datum *m_SDTColValues; + bool *m_SDTColIsNull; + + // new cudesc relation's + Relation m_NewCudescRel; + HeapBulkInsert *m_NewCudescBulkInsert; + TransactionId m_NewCudescFrozenXid; + + // m_estate is used during rewriting table data. + // so it cannot be freed or reset before RewriteColsData() is end. + // m_econtext is the same , but its ecxt_per_tuple_memory + // must be reset after each data is handled successfully. + EState *m_estate; + ExprContext *m_econtext; +}; + +class BatchCUData : public BaseObject { +public: + CUDesc **CUDescData; + CU **CUptrData; + char *bitmap; // The delete bitmap that we would keep for the CU that's been moved + int colNum; + bool hasValue; + + BatchCUData() + { + CUDescData = NULL; + CUptrData = NULL; + bitmap = NULL; + colNum = 0; + hasValue = false; + } + + virtual ~BatchCUData() + { + } + + void Init(const int &relColNum) + { + colNum = relColNum; + CUDescData = (CUDesc **)palloc0(colNum * sizeof(CUDesc *)); + CUptrData = (CU **)palloc0(colNum * sizeof(CU *)); + for (int i = 0; i < colNum; ++i) { + CUDescData[i] = New(CurrentMemoryContext) CUDesc; + } + } + + void CopyDelMask(unsigned char *cuDelMask) + { + bitmap = (char *)cuDelMask; + } + + bool batchCUIsNULL() + { + return !hasValue; + } + + void reset() + { + hasValue = false; + } + virtual void Destroy() + { + for (int i = 0; i < colNum; ++i) { + DELETE_EX(CUDescData[i]); + } + pfree_ext(CUDescData); + pfree_ext(CUptrData); + } +}; + +extern void CStoreCopyColumnData(Relation CUReplicationRel, Relation rel, AttrNumber attrnum); +extern void CStoreCopyColumnDataEnd(Relation colRel, Oid targetTableSpace, Oid newrelfilenode); +extern Oid CStoreSetTableSpaceForColumnData(Relation colRel, Oid targetTableSpace); +extern void ATExecCStoreMergePartition(Relation partTableRel, AlterTableCmd *cmd); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_roughcheck_func.h postgresql-hll-2.14/include/access/cstore_roughcheck_func.h --- postgresql-hll-2.14_old/include/access/cstore_roughcheck_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_roughcheck_func.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_roughcheck_func.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_roughcheck_func.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_ROUGHCHECK_FUNC_H +#define CSTORE_ROUGHCHECK_FUNC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/cstoreskey.h" +#include "storage/cu.h" + +typedef bool (*RoughCheckFunc)(CUDesc *cudesc, Datum arg); + +RoughCheckFunc GetRoughCheckFunc(Oid typeOid, int strategy, Oid collation); + +#endif /* CSTORE_ROUGHCHECK_FUNC_H */ diff -uprN postgresql-hll-2.14_old/include/access/cstoreskey.h postgresql-hll-2.14/include/access/cstoreskey.h --- postgresql-hll-2.14_old/include/access/cstoreskey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstoreskey.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,64 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstoreskey.h + * POSTGRES column store scan key definitions. + * + * + * IDENTIFICATION + * src/include/access/cstoreskey.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORESKEY_H +#define CSTORESKEY_H + +#include "access/attnum.h" +#include "fmgr.h" + +/* + * Strategy numbers identify the semantics that particular operators have. + */ +typedef uint16 CStoreStrategyNumber; + +#define InvalidCStoreStrategy ((CStoreStrategyNumber)0) + +/* + * define the strategy numbers for cstore scan. + */ +const CStoreStrategyNumber CStoreLessStrategyNumber = 1; +const CStoreStrategyNumber CStoreLessEqualStrategyNumber = 2; +const CStoreStrategyNumber CStoreEqualStrategyNumber = 3; +const CStoreStrategyNumber CStoreGreaterEqualStrategyNumber = 4; +const CStoreStrategyNumber CStoreGreaterStrategyNumber = 5; + +const CStoreStrategyNumber CStoreMaxStrategyNumber = 5; + +typedef struct CStoreScanKeyData { + uint16 cs_flags; // no use. + AttrNumber cs_attno; // a sequence column numbers, begin with 0 + CStoreStrategyNumber cs_strategy; // operator strategy number + Oid cs_collation; // collation to use, if needed + FmgrInfo cs_func; // op func + Datum cs_argument; // op args. + Oid cs_left_type; // op left type +} CStoreScanKeyData; + +typedef CStoreScanKeyData *CStoreScanKey; + +void CStoreScanKeyInit(CStoreScanKey entry, uint16 flags, AttrNumber attributeNumber, CStoreStrategyNumber strategy, + Oid collation, RegProcedure procedure, Datum argument, Oid left_type); + +#endif /* CSTORESKEY_H */ diff -uprN postgresql-hll-2.14_old/include/access/cstore_update.h postgresql-hll-2.14/include/access/cstore_update.h --- postgresql-hll-2.14_old/include/access/cstore_update.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_update.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_update.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_update.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_UPDATE_H +#define CSTORE_UPDATE_H + +#include "access/cstore_am.h" +#include "access/cstore_delete.h" +#include "access/cstore_insert.h" + +class CStoreUpdate : public BaseObject { +public: + CStoreUpdate(_in_ Relation rel, _in_ EState *estate, _in_ Plan *plan); + virtual ~CStoreUpdate(); + virtual void Destroy(); + void InitSortState(TupleDesc sortTupDesc); + uint64 ExecUpdate(_in_ VectorBatch *batch, _in_ int options); + void EndUpdate(_in_ int options); + void InitUpdateMemArg(Plan *plan); + MemInfoArg *m_delMemInfo; + MemInfoArg *m_insMemInfo; + +private: + Relation m_relation; + + CStoreDelete *m_delete; + CStoreInsert *m_insert; + CStorePartitionInsert *m_partionInsert; + + ResultRelInfo *m_resultRelInfo; + EState *m_estate; + bool m_isPartition; + static int BATCHROW_TIMES; + + InsertArg m_insert_args; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/access/cstore_vector.h postgresql-hll-2.14/include/access/cstore_vector.h --- postgresql-hll-2.14_old/include/access/cstore_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/cstore_vector.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,335 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_vector.h + * batch buffer for bulk-loading, including + * 1. bulkload_block + * 2. bulkload_block_list + * 3. bulkload_minmax + * 4. bulkload_vector + * 5. bulkload_vector_iter + * 6. bulkload_rows + * 7. bulkload_rows_iter + * + * + * IDENTIFICATION + * src/include/access/cstore_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H +#define GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H + +#include "access/cstore_minmax_func.h" +#include "catalog/pg_attribute.h" +#include "vecexecutor/vectorbatch.h" + +extern bool bulkload_memsize_reach_limitation(void); + +/* Limitation about the total memory size of using blocks of one bulkload_rows object */ +#define BULKLOAD_MAX_MEMSIZE (1024 * 1024 * 1024LL) + +/* type declaration */ +struct bulkload_block; +struct bulkload_block_list; +struct bulkload_minmax; +struct bulkload_datums; +struct bulkload_vector; +struct bulkload_vector_iter; +struct bulkload_rows; + +struct MemInfoArg { + /* record memory auto spread info. bulkload memory */ + int canSpreadmaxMem; + int MemInsert; + int MemSort; + int spreadNum; + int partitionNum; + + MemInfoArg() + { + canSpreadmaxMem = 0; + MemInsert = 0; + MemSort = 0; + spreadNum = 0; + partitionNum = 0; + } +}; + +/* bulkload_block + * memory block for bulk loading. + */ +struct bulkload_block { + struct bulkload_block *next; /* next bulkload_block */ + char *buff; /* memory buffer */ + int used; /* used space by bytes */ + int total; /* total space by bytes */ + + /* *data_unit* see data_unit() function */ + static bulkload_block *create(int block_size, int data_unit); +}; + +/* bulkload_block_list + * memory block list for bulk loading. + */ +struct bulkload_block_list { + bulkload_block *m_head; /* the first block */ + bulkload_block *m_current; /* the m_current block */ + int m_block_num; /* block number */ + + /* + * for fixed length data type, all the blocks have the same block size; + * for varied length data type, not all the block sizes are the same, + * but we remember the minimum block size in m_block_size. if data size if + * larger than m_block_size, the block to hold the data will adopt the block + * size which is equal to data size. + */ + int m_block_size; + + void init(Form_pg_attribute attr); + void destroy(); + void expand(void); + void expand(int needed); + void reset(bool reuse_blocks); + void configure(int attlen); + +private: + template + void reset_inner(void); +}; + +/* bulkload_minmax + * min/max info during bulk loading. + */ +struct bulkload_minmax { + CompareDatum m_compare; /* datum compare function */ + FinishCompareDatum m_finish_compare; /* datum compare finishing function */ + + /* make min/max buffer address be 8 aligned, + * because the first 8 bytes will be accessed as Datum pointer. + * so place the two after function pointers, and MIN_MAX_LEN = 8*N . + */ + char m_min_buf[MIN_MAX_LEN]; /* buffer for min value */ + char m_max_buf[MIN_MAX_LEN]; /* buffer for max value */ + + int m_varstr_maxlen; /* max length of variable length column */ + bool m_first_compare; /* indicate the first comparing action */ + + void init(Oid atttypid); + void reset(void); + void configure(Oid atttypid); +}; + +/* bulkload_datums + * values/nulls info during bulk loading. + */ +struct bulkload_datums { + Datum *m_vals_points; /* only for attlen > 8 or attlen < 0 */ + char *m_null_bitmap; /* NULLs bitmap */ + int m_vals_num; /* current number of values in m_vals_points including NULLs */ + bool m_has_null; /* indicate at least one NULL exists */ + bool m_all_null; /* indicate all are NULL */ + + void init(Form_pg_attribute attr, int max_num); + void destroy(); + void reset(int max_num); + bool is_null(int which); + void set_null(int which); + Datum get_datum(int which) const; +}; + +/* bulkload_vector + * a batch of values for one column. + */ +struct bulkload_vector : public BaseObject { + /* memory block info && m_append api */ + bulkload_block_list m_blocks; + int m_attlen; + + /* function pointer */ + Datum (bulkload_vector::*m_decode)(ScalarVector *, int) const; + Datum (bulkload_vector::*m_append)(bulkload_rows *, Datum, int); + + /* Values/Nulls info */ + bulkload_datums m_values_nulls; + + /* Min/Max info */ + bulkload_minmax m_minmax; + + /* ====== bulkload_vector API ====== */ + void init(Form_pg_attribute attr, int max_values); + void configure(Form_pg_attribute attr); + void reset(int max_values, bool reuse_blocks); + void destroy(void); + + Size data_size(void); + void data_copy(char *outbuf); + + void new_fixedsize_block(int data_unit); + void choose_fixedsize_block(bulkload_rows *batch_rows, int data_unit); + + void new_varsize_block(int data_len); + void choose_varsize_block(bulkload_rows *batch_rows, int data_len); + +private: + /* append functions for all datatype */ + Datum append_int8(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int16(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int32(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int64(bulkload_rows *batch_rows, Datum v, int len); + Datum append_fixed_length(bulkload_rows *batch_rows, Datum v, int len); + template + Datum append_var_length(bulkload_rows *batch_rows, Datum v, int len); + + /* decode functions for all datatype */ + Datum decode_integer(ScalarVector *pvector, int rowIdx) const; + Datum decode_fixed_length(ScalarVector *pvector, int rowIdx) const; + Datum decode_var_length(ScalarVector *pvector, int rowIdx) const; +}; + +/* Vector Itor */ +struct bulkload_vector_iter { + void begin(bulkload_vector *vect, int max_values); + void next(Datum *value, bool *null); + bool not_end(void) const; + +private: + bulkload_vector *m_vector; /* current accessing vector */ + bulkload_block *m_block; /* current accessing block */ + int m_block_pos; /* position of current block */ + int m_cur_num; /* current number of accessed values */ + int m_max_num; /* max number of accessed values */ + + /* next function point */ + void (bulkload_vector_iter::*m_next)(Datum *, bool *); + + /* next function */ + void next_int8(Datum *value, bool *null); + void next_int16(Datum *value, bool *null); + void next_int32(Datum *value, bool *null); + void next_int64(Datum *value, bool *null); + void next_var_length(Datum *value, bool *null); +}; + +/* batch rows for bulk loading */ +struct bulkload_rows : public BaseObject { + /* make all the used memory within m_context */ + MemoryContext m_context; + + /* we must control total memory size used by this object, + * so m_using_blocks_total_rawsize will remember using memory size. + */ + Size m_using_blocks_total_rawsize; + Size m_using_blocks_init_rawsize; + + /* values vectors for each attribute/field */ + bulkload_vector *m_vectors; + int m_attr_num; + + /* the current and max number of values to hold within each vector */ + int m_rows_maxnum; + int m_rows_curnum; + + /* becuase buffer is lazy-created, so we can + * 1. create all buffers if needed, + * 2. re-create all buffers and reuse after the previous destroy. + */ + bool m_inited; + + typedef bool (bulkload_rows::*FormAppendColumnFuncType)(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + FormAppendColumnFuncType m_form_append_column_func; + + typedef Size (bulkload_rows::*FormSampleTupleSizeFuncType)(TupleDesc tup_desc, VectorBatch *p_batch, + int idx_sample); + FormSampleTupleSizeFuncType m_form_sample_tuple_size_func; + + bool m_has_dropped_column; + + /* constructor and deconstructor */ + bulkload_rows(TupleDesc tuple_desc, int rows_maxnum, bool to_init = true); + ~bulkload_rows() + { + } + + /* important: + * Destroy is the common funtion to release all resources, + * so don't change this function name. + */ + void Destroy(void) + { + destroy(); + } + + void init(TupleDesc tup_desc, int rows_maxnum); + void reset(bool reuse_blocks); + bool append_one_vector(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx, MemInfoArg *m_memInfo = NULL); + bool append_one_tuple(Datum *values, const bool *isnull, TupleDesc tup_desc); + void append_one_column(Datum *values, const bool *isnull, int rows, TupleDesc tup_desc, int dest_idx); + + Size total_memory_size(void) const; + + /* + * @Description: check whether row number reaches limitation. + * @Return: true if row number reaches limitation; otherwise false. + * @See also: + */ + inline bool full_rownum(void) + { + return (m_rows_curnum == m_rows_maxnum); + } + + /* + * @Description: check whether rows size reaches limitation. + * @Return: true if rows size reaches limitation; otherwise false. + * @See also: + */ + inline bool full_rowsize(void) + { + return (m_using_blocks_total_rawsize >= BULKLOAD_MAX_MEMSIZE); + } + + Size calculate_tuple_size(TupleDesc tup_desc, Datum *tup_values, const bool *tup_nulls) const; + +private: + template + bool append_in_column_orientation(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + bool append_in_row_orientation(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + template + Size sample_tuple_size(TupleDesc tup_desc, VectorBatch *p_batch, int start_idx); + void destroy(void); +}; + +/* itor for bulkload_rows */ +struct bulkload_rows_iter { + void begin(bulkload_rows *batch_rows); + void next(Datum *values, bool *nulls); + bool not_end(void) const; + void end(void); + +private: + bulkload_rows *m_batch; + bulkload_vector_iter *m_vec_iters; +}; + +extern void init_tid_attinfo(FormData_pg_attribute *tid_attr); +extern void init_tid_vector(bulkload_vector *vect, int max_values); +extern bulkload_rows *bulkload_indexbatch_init(int max_key_num, int max_values); +extern void bulkload_indexbatch_set_tids(bulkload_rows *index_batch, uint32 cuid, int copy_num); +extern void bulkload_indexbatch_copy(bulkload_rows *index_batch, int dest_idx, bulkload_rows *src, int src_idx); +extern void bulkload_indexbatch_copy_tids(bulkload_rows *index_batch, int dest_idx); +extern void bulkload_indexbatch_deinit(bulkload_rows *index_batch); + +#endif /* GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H */ diff -uprN postgresql-hll-2.14_old/include/access/dfs/carbondata_index_reader.h postgresql-hll-2.14/include/access/dfs/carbondata_index_reader.h --- postgresql-hll-2.14_old/include/access/dfs/carbondata_index_reader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/carbondata_index_reader.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,208 @@ +#ifndef CARBONDATA_INDEX_READER_H_ +#define CARBONDATA_INDEX_READER_H_ + +#include +#include +#include +#include + +#include "carbondata/format/carbondata_types.h" +#include "carbondata/format/carbondata_index_types.h" +#include "carbondata/format/schema_types.h" +#include "carbondata/index_file_reader.h" +#include "carbondata/inputstream.h" +#include "carbondata/memory.h" +#include "carbondata/thrift_adapter.h" + +#include "postgres.h" + +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_stream.h" +#include "nodes/pg_list.h" +#include "pgxc/locator.h" + +extern THR_LOCAL char* PGXCNodeName; + +namespace dfs { +#define CARBONDATA_FILENUMBER 1024 +#define OBS_OBJECT_NAME_MAXSIZE 1024 + +#define CARBONDATA_INDEX ".carbonindex" +#define CARBONDATA_DATA ".carbondata" + +/* + * get file name from path + * @IN FilePath + * @return: file name + */ +extern const char* FileNameFromPath(const char* filePath); + +/* + * filter file name to filetype + * @IN fileList + * @IN fileType + * @return: fileList after filter + */ +extern List* CarbonFileFilter(List* fileList, const char* fileType); + +/* + * Get the data filename list after match obs filelist. + * @IN fileList: obs data fileList + * @IN dataFileList: carbonindex analysis data fileList + * @return filename list: data filename need to be schedule. + */ +extern List* CarbonDataFileMatch(List* fileList, List* dataFileList); + +namespace reader { + +class CarbondataIndexReader : public BaseObject { +public: + CarbondataIndexReader( + List* allColumnList, List* queryRestrictionList, bool* restrictRequired, bool* readRequired, int16 attrNum); + + ~CarbondataIndexReader() + {} + + /* Initialization */ + void init(std::unique_ptr gsInputStream); + + /* read index file */ + void readIndex(); + + /* Clear the memory and resource. */ + void Destroy(); + + /* + * Get the data filename list from carbonindex file. + * @return filename list: data filename list. + */ + List* getDataFileList(); + + /* + * Get the data filepath list from carbonindex file. + * @return filepath list: data filepath list. + */ + List* getDataFilePathList(); + + /* + * Get the not repeat data filename list from carbonindex file. + * @return filename list: data filename list only. + */ + List* getDataFileDeduplication(); + +private: + /* + * Min-max filter, try to skip carbondata blocklet. + * @IN currentBlocklet: current blocklet index + * @Out bool: true : skip current blocklet; + * false: not skip current blocklet. + */ + bool tryToSkipCurrentBlocklet(uint64 currentBlocklet); + + bool checkPredicateOnCurrentBlocklet(uint64 currentBlocklet); + + List* buildRestriction(uint64 rowGroupIndex); + + Node* buildColRestriction(int32 columnIndex, uint64 blockletIndex); + + int32_t GetBlockletMinMax( + int32 columnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxString(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxVarchar(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxBoolean(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxByte(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxShort(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxInt(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxLong(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxFloat(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDouble(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxTimestamp(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDate(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDecimal(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + /* + * filepath cut to path and name + * @IN FilePath: filePath need to be cut + * @OUT Path: path + * @OUT Name: Name + */ + void FilePathCut(char*& path, char*& name, const char* filePath); + + /* + * path and name joint to filepath + * @IN name: file name + * @IN path: file path + * @OUT filePath: filepath + */ + void FilePathJoint(char*& filePath, const char* name, const char* path); + + inline bool isColumnRequiredToRead(int32 columnIndexInRead) + { + return m_readRequired != NULL ? m_readRequired[columnIndexInRead] : false; + } + + inline bool hasRestriction() + { + return m_queryRestrictionList != NULL; + } + + inline int32 getSchemaOrdinal(int32 columnIndex) + { + return m_schemaOrdinalList[columnIndex]; + } + +private: + HTAB* m_dataname_hashtbl; + + char* m_filePath; + char* m_fileName; + uint64 m_block_size; + + const Var* m_var; + OpExpr* m_lessThanExpr; + OpExpr* m_greaterThanExpr; + + List* m_allColumnList; + List* m_queryRestrictionList; + + bool* m_restrictRequired; + bool* m_readRequired; + + /* carbondata columns schema ordinal list. */ + int32* m_schemaOrdinalList; + + int32 m_relAttrNum; + + carbondata::IndexFileReader m_indexfile_reader; + + carbondata::format::IndexHeader m_indexheader; + + std::vector m_vec_blockindex; +}; +} // namespace reader +} // namespace dfs +#endif /* CARBONDATA_INDEX_READER_H_ */ diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_am.h postgresql-hll-2.14/include/access/dfs/dfs_am.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_am.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,506 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_am.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_am.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_AM_H +#define DFS_AM_H + +#include "storage/dfs/dfs_connector.h" +#include "dfsdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "utils/bloom_filter.h" +#include "vecexecutor/vectorbatch.h" +#include "pgxc/locator.h" + +#define INVALID_ENCODING (-1) /* For hdfs table, there is no encoding */ + +extern void CleanupDfsHandlers(bool isTop); +extern void ResetDfsHandlerPtrs(void); +extern void RemoveDfsReadHandler(const void *handler); +extern void RemoveDfsWriteHandler(const void *handler); + +struct IndexInsertInfo; + +extern char *HdfsGetOptionValue(Oid foreignTableId, const char *optionName); +extern DefElem *HdfsGetOptionDefElem(Oid foreignTableId, const char *optionName); + +struct DfsScanState; +namespace dfs { +typedef uint64 uint64_t; +typedef int64 int64_t; + +/* The type of file to be read, there is only ORC currently. */ +enum FileType { + ORC = 0, + PARQUET = 1, + TEXT = 2, + CSV = 3, + CARBONDATA = 4 +}; + +namespace reader { + +typedef struct FileOffset { + uint32 rowIndexInFile[BatchMaxSize]; + uint32 numelements; +} FileOffset; + +/* + * The interface which provides some basic functions. + */ +class Reader : public BaseObject { +public: + virtual ~Reader() + { + } + + /* + * The reserved interface to add finish work when there is no rows + * to read. + */ + virtual void Destroy() = 0; + + /* + * Fetch the next one tuple. + * @_in_out_param tuple: The tuple to be filled by the reader. + */ + virtual void nextTuple(TupleTableSlot *tuple) = 0; + + /* + * Fetch the next 1000 or less rows in a vector batch. + * @_in_out_param batch: The vector batch to be filled by the reader. + */ + virtual void nextBatch(VectorBatch *batch) = 0; + + /* + * @Description: Fetch the next batch according to the tid vector batch. + * @IN/OUT batch: vector batch + * @IN tids: tid vector batch + * @See also: + */ + virtual void nextBatchByTids(VectorBatch *batch, VectorBatch *tidBatch) = 0; + + /* + * Fetch the next batch according to the tid vector batch which includes all the columns we need. + * @OUT batch: the target vector batch + * @IN tidBatch: the tid vector batch + * @IN prepareCols: the prepared cols list in the tid vector batch + */ + virtual void nextBatchByTidsForIndexOnly(VectorBatch *batch, VectorBatch *tidBatch, List *prepareCols) = 0; + + /* + * Add a bloom filter into the reader. + * @_in_param bloomFilter: The bloom filter to be added. + * @_in_param colIdx: The index of the column on which to add the bloom filter. + * @_in_param is_runtime: Is between runtime or not. + */ + virtual void addBloomFilter(filter::BloomFilter *bloomFilter, int colIdx, bool is_runtime) = 0; + + /* + * Copy bloomFilter to runTimeBloomFilter + */ + virtual void copyBloomFilter() = 0; + + /* + * The reserved interface to add prepared processes before calling + * @_in_param conn: The connector handler to hdfs. + * @_in_param type: The type of the file to read. + * the nextBatch. + */ + virtual void begin(dfs::DFSConnector *conn, FileType type) = 0; + + /* + * Handle the tailing works which are not destroyers. + */ + virtual void end() = 0; + + /* Get DFS table name */ + virtual const char *getRelName() = 0; + + /* Get the current reader's transaction ID. */ + virtual const int getCurrentTransactionLevel() = 0; + + /* Just before the first execution iterator, we assign splits for current worker. */ + virtual void dynamicAssignSplits() = 0; +}; + +/* + * Includes all the params which are used during reading. + */ +typedef struct ReaderState { + /* DFS storage type */ + int dfsType; + + /* The number of the columns defined in the relation. */ + uint32_t relAttrNum; + + /* The number of parition columns. */ + uint32_t partNum; + + /* + * The mapping array from mpp column index to file column index, this + * has been adjusted for partition and default columns. + */ + uint32_t *readColIDs; + + /* + * When create ReaderImpl object, initialize the globalColIds, It represnets + * a possible column order in file. The partition column index has any meaning. + * The globalColIds must used in conjunction with globalReadRequired. + * It starts from 0. + */ + uint32_t *globalColIds; + + /* + * The mapping array from the column id defined in relation to column id + * stored in file, this start at 1 and will be null for non-partition table. + */ + uint32_t *colNoMapArr; + + /* + * The ordered column id according to the selectivity. Use the + * column id defined in relation to visit it. + */ + uint32_t *orderedCols; + + /* Count up the number of files wich are static pruned */ + uint64_t staticPruneFiles; + + /* Count up the number of files which are pruned dynamically. */ + uint64_t dynamicPrunFiles; + + /* Count up the number of rows which are filtered by the bloom filter. */ + uint64_t bloomFilterRows; + + /* Count up the number of strides which are filtered by the bloom filter. */ + uint64_t bloomFilterBlocks; + + /* Count up the number of rows which are filtered by the min/max. */ + uint64_t minmaxFilterRows; + + /* min/max filtering data */ + uint64_t minmaxCheckFiles; /* the number of checking files totally */ + uint64_t minmaxFilterFiles; /* the number of filtered files */ + uint64_t minmaxCheckStripe; /* the number of checking stripes totally */ + uint64_t minmaxFilterStripe; /* the number of filtered stripes, orc is stripe and parquet is row group */ + uint64_t minmaxCheckStride; /* the number of checking strides totally */ + uint64_t minmaxFilterStride; /* the number of filtered strides, orc is stride and parquet is chunk page */ + + /* Count up the number of cache hint of orc data */ + uint64 orcDataCacheBlockCount; + uint64 orcDataCacheBlockSize; + /* Count up the number of load of orc data */ + uint64 orcDataLoadBlockCount; + uint64 orcDataLoadBlockSize; + /* Count up the number of cache hint of orc meta data */ + uint64 orcMetaCacheBlockCount; + uint64 orcMetaCacheBlockSize; + /* Count up the number of oad of orc meta data */ + uint64 orcMetaLoadBlockCount; + uint64 orcMetaLoadBlockSize; + + /* + * The array stores the the columns which is required by the query + * and includes the satisfied partition columns. + */ + bool *isRequired; + + /* + * The array to indicate which columns need to be send back + * and includes the satisfied partition columns. + */ + bool *targetRequired; + + /* + * The array to indicate which columns have restrictions. Normally we ignore the + * partition columns unless the restriction comes from the run time predicate. + */ + bool *restrictRequired; + + /* + * The array to indicate which columns need to be read from the file + * and excludes the partition columns with the non-exist columns. + */ + bool *readRequired; + /* + * When create ReaderImpl object, initialize the globalReadRequired. it represents + * which column may be read from file. not include partition column. + */ + bool *globalReadRequired; + + /* The list of files to be read. */ + List *splitList; + + /* The list of the required columns including the partition columns. */ + List *allColumnList; + + /* The list of partition columns. */ + List *partList; + + /* The list of restrictions for block skip. */ + List *queryRestrictionList; + List *runtimeRestrictionList; + + /* + * The list array stores the predicates upon each column. Use the + * column id stored in file to visit it. + */ + List **hdfsScanPredicateArr; + + /* + * The array of string stores value of partition column for each file. + * Use the column id defined in relation to visit it. + */ + char **partitionColValueArr; + + /* The array of bloom filters on each column. */ + filter::BloomFilter **bloomFilters; + + /* The current file to be read. */ + SplitInfo *currentSplit; + + /* + * The pointer to the file reader which need to be cleared when error occurs, + * So i add it here to avoid resource leak. + */ + Reader *fileReader; + + /* hdfs table <= 0, forigen table < 0(-1) */ + int currentFileID; + + /* The size of the current file, this is 0 for foreign table. */ + int64_t currentFileSize; + + /* The memory context to store the persist state when reading the file. */ + MemoryContext persistCtx; + + /* The memory contex which will be reset when rescaning. */ + MemoryContext rescanCtx; + + /* Scan state. */ + ScanState *scanstate; + + /* The snapshot used while reading. */ + Snapshot snapshot; + + /* Count up the number of hdfs local/remote block read by dn. */ + uint64_t localBlock; + uint64_t remoteBlock; + + /* Count the number of intersections with dfs namenode/datanode. */ + uint64_t nnCalls; + uint64_t dnCalls; + + /* Encoding type for the dfs foreign table. */ + int fdwEncoding; + + /* The level of encoding check,2 = high, 1 = low, 0 = no check */ + int checkEncodingLevel; + + /* Count how many elements are invalid for the encoding and are converted to ? automatically. */ + int incompatibleCount; + int dealWithCount; + + /* special case for obs scan time */ + instr_time obsScanTime; +} ReaderState; + +/* + * @Description: The factory function to create a reader for ORC file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createOrcReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for Parquet file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createParquetReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for Carbondata file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader* createCarbondataReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for TEXT file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createTextReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for CSV file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createCsvReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: Initialize the neccessary variables for analyze or copy to on dfs table(not foreign table). + * @IN rel: The relation to scan. + * @IN splitList: The list of file to scan. + * @IN colNum: The number of the columns for scanning, set it 0 if colIdx is null. + * @IN colIdx: The target column list((with system column at tail)1,2,..,-1) for scanning, scan all the columns if this + * is null. + * @IN snapshot: The snapshot(NULL, mvcc or snapshotNow). + * @Return: the DfsScanState which is build inside the function. + * @See also: + */ +DfsScanState *DFSBeginScan(Relation rel, List *splitList, int colNum, int16 *colIdx, Snapshot snapshot = NULL); + +/* + * Fetch the next vector batch for analyze or copy to on dfs table(not foreign table). + * _in_param scanState: The state for scaning which is returned by DFSBeginScan. + * @return the vector batch. + */ +VectorBatch *DFSGetNextBatch(DfsScanState *scanState); + +/* + * Fetch the next tuple of dfs table for analyze operator. The table to be scanned is not + * foreign HDFS table. + * _in_param scanState: The state for scaning which is returned by DFSBeginScan. + * _out_param scanTupleSlot: The TupleTableSlot struct in which the scanned tuple is filled. + * @return None. + */ +void DFSGetNextTuple(DfsScanState *scanState, TupleTableSlot *scanTupleSlot); + +/* + * Destroy the neccessary variables when the scan is over. + * @_in_param scanState: The state for scaning which is returned by DFSBeginScan. + */ +void DFSEndScan(DfsScanState *scanState); + +} // namespace reader + +namespace writer { + +class Writer : public BaseObject { +public: + virtual ~Writer() + { + } + + /* Initialize the class member, this must be called just after construct a new object. */ + virtual void init(IndexInsertInfo *indexInsertInfo) = 0; + + /* Add a batch into the buffer. */ + virtual void appendBatch(const VectorBatch *batch) = 0; + + /* Add a tuple into the buffer. */ + virtual void appendTuple(Datum *values, bool *nulls) = 0; + + /* Check if the buffer is available to hold special number of rows. */ + virtual bool canAppend(uint64 size) = 0; + + /* Spill the buffer into the current file. */ + virtual int spillToCurFile() = 0; + + /* Spill the buffer into a new file. */ + virtual int spillToNewFile(const char *filePath) = 0; + + /* Spill the buffer into delta table. */ + virtual void deltaInsert(int option) = 0; + + /* Set the file ID of the current writer. */ + virtual void setFileID(uint64 fileID) = 0; + + /* Get the file ID of the current writer. */ + virtual uint64 getFileID() = 0; + + /* Get the rows in the hdfs file, this function must be called after the m_orcWriter is closed. */ + virtual uint64 getTotalRows() = 0; + + /* Get the totoal number of serialized rows of the current writer. */ + virtual uint64 getSerializedRows() = 0; + + /* Get the totoal number of buffer rows of the current writer. */ + virtual uint64 getBufferRows() = 0; + + /* + * @Description: Acquire the min max value of the column. Return false when there is no min/max. + * @IN colId: the column id + * @OUT minStr: the string of min value if exist + * @OUT maxStr: the string of max value if exist + * @OUT hasMin: whether the min value exist + * @OUT hasMax: whether the max value exist + * @Return: false if there is no min or max value of the column, else return true. + * @See also: + */ + virtual bool getMinMax(uint32 colId, char *&minstr, char *&maxstr, bool &hasMin, bool &hasMax) = 0; + + /* Close the current writer and flush the data and return the file size. */ + virtual int64 closeCurWriter(char *filePath) = 0; + + /* Clean the class member. */ + virtual void Destroy() = 0; + + /* Get DFS table name */ + virtual const char *getRelName() = 0; + + /* Deal the clean works on dfs writer. */ + virtual void handleTail() = 0; + + /* Get the current writer's transaction ID. */ + virtual const int getCurrentTransactionLevel() = 0; +}; + +/* + * @Description: Create an instance of orc writer + * @IN context: memory context + * @IN rel: the current relation + * @IN DestRel: the dest relation(used for vacuum) + * @IN IndexInsertInfo: includes index information + * @IN parsig: dirctory information which is used for value partition table + * @Return: writer pointer + * @See also: + */ +Writer *createOrcWriter(MemoryContext context, Relation rel, Relation DestRel, IndexInsertInfo *indexInsertInfo, + const char *parsig); + +} // namespace writer +} // namespace dfs + +List *BuildSplitList(Relation rel, StringInfo RootDir, Snapshot snapshot = NULL); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_common.h postgresql-hll-2.14/include/access/dfs/dfs_common.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_common.h 2020-12-12 17:06:43.057345587 +0800 @@ -0,0 +1,180 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_common.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_COMMON_H +#define DFS_COMMON_H + +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +#ifndef MIN +#define MIN(A, B) ((B) < (A) ? (B) : (A)) +#endif + +#define DFS_PRIVATE_ITEM "DfsPrivateItem" +#define DFS_NUMERIC64_MAX_PRECISION 18 + +/* MACROS which help to catch and print the exception. */ +#define DFS_TRY() \ + bool saveStatus = t_thrd.int_cxt.ImmediateInterruptOK; \ + t_thrd.int_cxt.ImmediateInterruptOK = false; \ + bool errOccur = false; \ + int errNo = ERRCODE_SYSTEM_ERROR; \ + StringInfo errMsg = makeStringInfo(); \ + StringInfo errDetail = makeStringInfo(); \ + try +#define DFS_CATCH() \ + catch (abi::__forced_unwind &) \ + { \ + throw; \ + } \ + catch (orc::OrcException & ex) \ + { \ + errOccur = true; \ + errNo = ex.getErrNo(); \ + try { \ + appendStringInfo(errMsg, "%s", ex.what()); \ + appendStringInfo(errDetail, "%s", ex.msg().c_str()); \ + } catch (abi::__forced_unwind &) { \ + throw; \ + } catch (...) { \ + } \ + } \ + catch (std::exception & ex) \ + { \ + errOccur = true; \ + try { \ + appendStringInfo(errMsg, "%s", ex.what()); \ + } catch (abi::__forced_unwind &) { \ + throw; \ + } catch (...) { \ + } \ + } \ + catch (...) \ + { \ + errOccur = true; \ + } \ + t_thrd.int_cxt.ImmediateInterruptOK = saveStatus; \ + saveStatus = InterruptPending; \ + InterruptPending = false; \ + if (errOccur && errDetail->len > 0) { \ + ereport(LOG, (errmodule(MOD_DFS), errmsg("Caught exceptiion for: %s.", errDetail->data))); \ + } \ + InterruptPending = saveStatus; \ + pfree_ext(errDetail->data); \ + pfree_ext(errDetail); + +#define DFS_ERRREPORT(msg, module) \ + if (errOccur) { \ + destroy(); \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + +#define DFS_ERRREPORT_WITHARGS(msg, module, ...) \ + if (errOccur) { \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, __VA_ARGS__, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + +#define DFS_ERRREPORT_WITHOUTARGS(msg, module) \ + if (errOccur) { \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + + +#define DEFAULT_HIVE_NULL "__HIVE_DEFAULT_PARTITION__" +#define DEFAULT_HIVE_NULL_LENGTH 26 + +/* + * Check partition signature creation exception in case of the content exceeding + * max allowed partition length + */ +#define partition_err_msg \ + "The length of the partition directory exceeds the current value(%d) of the option " \ + "\"dfs_partition_directory_length\", change the option to the greater value." +#define CHECK_PARTITION_SIGNATURE(rc, dirname) do { \ + if (rc != 0) { \ + ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmodule(MOD_DFS), \ + errmsg(partition_err_msg, u_sess->attr.attr_storage.dfs_max_parsig_length), \ + errdetail("the path name is \"%s\".", dirname))); \ + } \ + securec_check(rc, "\0", "\0"); \ +} while (0) + +#define strpos(p, s) (strstr(p, s) != NULL ? strstr(p, s) - p : -1) +#define basename_len(p, s) (strrchr(p, s) != NULL ? strrchr(p, s) - p : -1) + +#define INT_CMP_HDFS(arg1, arg2, compare) do { \ + if ((arg1) < (arg2)) { \ + compare = -1; \ + } else if ((arg1) > (arg2)) { \ + compare = 1; \ + } else { \ + compare = 0; \ + } \ +} while (0) + +/* + * 1. NAN = NAN + * 2. NAN > non-NAN + * 3. non-NAN < NAN + * 4. non-NAN cmp non-NAN + * 5. arg2 will never be NAN here + */ +#define FLOAT_CMP_HDFS(arg1, arg2, compare) do { \ + if (isnan(arg1)) { \ + compare = 1; \ + } else { \ + if ((arg1) > (arg2)) { \ + compare = 1; \ + } else if ((arg1) < (arg2)) { \ + compare = -1; \ + } else { \ + compare = 0; \ + } \ + } \ +} while (0) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_delete.h postgresql-hll-2.14/include/access/dfs/dfs_delete.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_delete.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_delete.h 2020-12-12 17:06:43.058345600 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_delete.h + * routines to support DFS(such as HDFS, DFS,...) + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_delete.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_DELETE_H +#define DFS_DELETE_H + +#include "access/cstore_delete.h" +#include "dfsdesc.h" + +class DfsDelete : public CStoreDelete { +public: + DfsDelete(Relation, EState *, bool is_update = false, Plan *plan = NULL, MemInfoArg *m_dfsInsertMemInfo = NULL); + virtual ~DfsDelete(); + + /* + * save batch to sort cache + */ + void PutDeleteBatch(VectorBatch *, JunkFilter *); + + /* + * called on deinitialization, make sure that tids in sort cache can be + * deleted. + */ + uint64 ExecDelete(); + + /* + * do "delete" job really with tids in sort cache, and return the number of + * deleted rows. + */ + uint64 ExecDeleteForTable(); + +protected: + /* + * used to handle desc table, such as mark deletemap, ... + */ + DFSDescHandler *m_handler; +}; + +#endif /* DFS_DELETE_H */ diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_insert.h postgresql-hll-2.14/include/access/dfs/dfs_insert.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_insert.h 2020-12-12 17:06:43.058345600 +0800 @@ -0,0 +1,459 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_insert.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_insert.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_INSERT_H +#define DFS_INSERT_H + +#include "access/dfs/dfs_am.h" +#include "access/cstore_insert.h" +#include "access/cstore_psort.h" +#include "access/cstore_vector.h" +#include "catalog/heap.h" +#include "catalog/pg_partition.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "vecexecutor/vectorbatch.h" + +class DfsInsertInter; + +/* + * ScalarValue => Datum, Datum should point to data without length header + * for varing length data type. + */ +extern Datum convertScalarToDatum(Oid typid, ScalarValue val); + +/* + * Create the insertion object for dfs table. + */ +extern DfsInsertInter *CreateDfsInsert(Relation rel, bool is_update, Relation dataDestRel = NULL, Plan *plan = NULL, + MemInfoArg *m_dfsInsertMemInfo = NULL); + +/* The globle variable which contains the insert files' info. */ +extern HTAB *g_dfsSpaceCache; + +typedef void (*InsertPendingFunc)(const char *, Oid, uint64); + +/* options for cstore_insert_mode */ +#define TO_AUTO 1 /* means enable_delta_store = true, tail data to delta table */ +#define TO_MAIN 2 /* means enable_delta_store = false, all data to hdfs store */ +#define TO_DELTA 3 /* new option, all data to delta table */ + +#define MAX_PARSIG_LENGTH (u_sess->attr.attr_storage.dfs_max_parsig_length + 1) +#define MAX_PARSIGS_LENGTH (VALUE_PARTKEYMAXNUM * u_sess->attr.attr_storage.dfs_max_parsig_length + 1) + +#define MAX_ACTIVE_PARNUM ((u_sess->attr.attr_storage.partition_max_cache_size * 1024L) / (64 * 1024 * 1024)) + +typedef struct IndexInsertInfo { + /* psort index need */ + Relation *idxRelation; + int *idxKeyNum; + InsertArg *idxInsertArgs; /* index inserting arguments */ + CStoreInsert **idxInsert; + int **idxKeyAttr; + int maxKeyNum; + int indexNum; +} IndexInsertInfo; + +/* Construct the struct of index insert information. */ +extern IndexInsertInfo *BuildIndexInsertInfo(Relation rel, ResultRelInfo *resultRelInfo); + +/* + * The Dfs table insert handler, it provides basic interface for Dfs insert protocol + * > BeginBatchInsert() + * > BatchInsert()/TupleInsert() + * > SetEnd() + * > Destroy() + * + * Which is exposed to executor/vecexcetutor level + */ +class DfsInsertInter : public BaseObject { +public: + virtual ~DfsInsertInter(){}; + + /* Prepare the members which are needed while inserting. */ + virtual void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL) = 0; + + /* Insert a vector batch into DFS. */ + virtual void BatchInsert(VectorBatch *batch, int option) = 0; + + /* Insert a tuple into DFS. */ + virtual void TupleInsert(Datum *values, bool *nulls, int option) = 0; + + /* Clean the member. */ + virtual void Destroy() = 0; + + /* empty function, just for FLUSH_DATA */ + virtual void EndBatchInsert() = 0; + + /* Set the end flag. */ + inline void SetEndFlag() + { + m_end = true; + }; + + /* Get the end flag */ + inline bool isEnd() + { + return m_end; + }; + + /* data redistribution for DFS table. */ + /* Set dataDestRel. */ + inline void setDataDestRel(Relation dataDestRel) + { + m_dataDestRelation = dataDestRel; + }; + + /* Set the index insert object. */ + inline void setIndexInsertInfo(IndexInsertInfo *indexInsertInfo) + { + m_indexInsertInfo = indexInsertInfo; + m_indexInfoOuterDestroy = true; + } + + /* Get dataDestRel. */ + inline Relation getDataDestRel() + { + return m_dataDestRelation; + }; + + /* register function which can insert new file name to pendingDfsDelete */ + inline void RegisterInsertPendingFunc(InsertPendingFunc fn) + { + m_insert_fn = fn; + } + + /* Clean the object of index insert if it is not set outer. */ + inline void clearIndexInsert() + { + if (NULL != m_indexInsertInfo && !m_indexInfoOuterDestroy) { + for (int i = 0; i < m_indexInsertInfo->indexNum; ++i) { + if (m_indexInsertInfo->idxInsert[i] != NULL) { + m_indexInsertInfo->idxInsert[i]->SetEndFlag(); + m_indexInsertInfo->idxInsert[i]->BatchInsert((bulkload_rows *)NULL, 0); + DELETE_EX(m_indexInsertInfo->idxInsert[i]); + CStoreInsert::DeInitInsertArg(m_indexInsertInfo->idxInsertArgs[i]); + } + relation_close(m_indexInsertInfo->idxRelation[i], RowExclusiveLock); + } + } + } + +public: + /* + * The m_dataDestRelation keeps the data path destination when execute insert operation. + * If the m_dataDestRelation is NULL, the data path destination would be acquired from + * m_relation. + * In the process of data redistribution, when execute the following command + * "insert into dataDestRelation select * form redistribution_table",there are two + * file lists in HDFS directory of redistribution table. The new files that + * are produced by the above command will be existed in HDFS directory of + * redistribution table. The old files is data of redistribution table. + * The two file lists must keep it until finish commit or abort transaction. + * If commit, delete the old file(file of redistribution table), + * otherwise delete new file. + */ + Relation m_dataDestRelation; + +protected: + /* The end flag which must be set outside. */ + bool m_end; + + /* + * The columns bitmap, it excludes dropped columns. + * When insert data to new file, must insert column bitmap to DESC table. + * Every file has different columns, only get the real columns by colmap of DESC table. + */ + char *m_colMap; + + /* used to insert new orc file name to pendingDfsDelete */ + InsertPendingFunc m_insert_fn; + + /* Index cstore insert info */ + IndexInsertInfo *m_indexInsertInfo; + bool m_indexInfoOuterDestroy; +}; + +class DfsInsert : public DfsInsertInter { +public: + DfsInsert(Relation relation, bool is_update, const char *parsigs = NULL, Plan *plan = NULL, + MemInfoArg *ArgmemInfo = NULL); + virtual ~DfsInsert(){}; + + /* prepare the memory for insert and sort to use. plan is for insert condition, ArgmemInfo is for update condition. */ + void InitInsertMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + /* Prepare the members which are needed while inserting. */ + void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL); + + /* Insert a vector batch into DFS. */ + void BatchInsert(VectorBatch *batch, int option); + + /* Insert a tuple into DFS. */ + void TupleInsert(Datum *values, bool *nulls, int option); + + /** + * @Description: Set the column map for DFS table. Get the all columns + * from pg_attribute, but excludes dropped columns. + * @return None. + */ + void setColMap(); + + /** + * @Description: Get the column map for DFS table. + * @return Node. + */ + const char *getColMap() + { + Assert(NULL != m_colMap); + return m_colMap; + } + + /* Initialize the dfs space cache. */ + static void InitDfsSpaceCache(); + + /* Remove the file space alloc cache. */ + static void InvalidSpaceAllocCache(Oid relid); + + /* Remove all the elements in the space cache. */ + static void ResetDfsSpaceCache(void); + + /* Clean the member. */ + virtual void Destroy(); + + /* empty function, just for FLUSH_DATA */ + void EndBatchInsert(){}; + +private: + /* The internal entry for batch insert. */ + void batchInsertInternal(VectorBatch *batch, int option, bool isEnd); + + /* THe internal entry for tuple insert. */ + void tupleInsertInternal(Datum *values, bool *nulls, int option, bool isEnd); + + /* Initialze the fixed prefix of file path. */ + void initPathPrefix(); + + /* Acquire the absolute path according to the file id. */ + char *getFilePath(uint64 offset) const; + + /* Acquire the file name of the path according to the file id. */ + char *getFileName(uint64 offset) const; + + /* Get the max file ID stored in btree index. */ + uint32 GetMaxIndexFileID(Relation heapRel); + + /* Acquire the max file id stored in space cache for rel. */ + uint64 getMaxFileID(Relation rel) const; + + /* Check if the space cache already exist. */ + bool dfsSpaceCacheExist(Oid relOid) const; + + /* Build the space cache according to maxFileID with entry "relid". */ + void buildSpaceAllocCache(Oid relid, uint64 maxFileID) const; + + /* + * Initialize the file space alloc cache to provide unique file id + * according to desc table of rel concurrently. + */ + void initSpaceAllocCache(Relation rel); + + /* Get the next file id which must be unique from global hashtable with entry "relOid". */ + uint64 allocNextSpace(Oid relOid) const; + + /* Spill the buffer into DFS. */ + void spillOut(int option); + + /* Deal with the tail data when the insert process ends. */ + void handleTailData(int option); + + /* Insert a record into desc table. */ + void descInsert(int option); + + inline bool NeedPartialSort() + { + return m_sorter != NULL; + } + +private: + Relation m_relation; + bool m_isUpdate; + TupleDesc m_desc; + + /* The common prefix of all the file path. */ + StringInfo m_filePathPrefix; + + /* The writer to store the buffer and save the file. */ + dfs::writer::Writer *m_writer; + + /* If relation has cluster key, it will work for partial sort. */ + CStorePSort *m_sorter; + + /* The memory context which will be cleaned for each insert iteration. */ + MemoryContext m_iterContext; + + /* The flag which indicates whether we need to create a new file while spilling in the next time. */ + bool m_nextFile; + + /* valid iff TO_DELTA == cstore_insert_mode */ + Relation m_delta; + Datum *m_values; + bool *m_nulls; + + /* dfs insert partition memory info. */ + MemInfoArg *m_dfsInsertMemInfo; + +public: + /* partitioned ONLY */ + StringInfo m_parsigs; +}; + +typedef struct PartitionStagingFile { + StringInfo parsig; + BufFile *sfile; +} PartitionStagingFile; + +class DfsPartitionInsert : public DfsInsertInter { +public: + DfsPartitionInsert(Relation relation, bool is_update, Plan *plan = NULL, MemInfoArg *ArgmemInfo = NULL); + virtual ~DfsPartitionInsert(){}; + + /* Prepare the members which are needed while inserting. */ + void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL); + + /* empty function, just for FLUSH_DATA */ + void EndBatchInsert(){}; + + /* Insert a vector batch into DFS. */ + void BatchInsert(VectorBatch *batch, int option); + + /* Insert a tuple into DFS. */ + void TupleInsert(Datum *values, bool *nulls, int option); + + /* Clean the member. */ + virtual void Destroy(); + + /* init insert memory info. */ + void InitInsertPartMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + +private: + /* + * Get One partition's DfsInsert by scanning p_pWriters[], if there is no writer slot + * available in current DfsPartitionInsert, return NULL to let caller to proper + * do action like swap tuple content to disk as temp files + */ + inline DfsInsert *GetDfsInsert(const char *parsig); + + /* + * Form a partition signature targeting to identify a parition directory for + * real data file layout. e.g c1=1/c2=1/c3=5/ + * + * Note: Per-Tuple invoking so INLINE defined + */ + inline void GetCStringFromDatum(Oid typeOid, int typeMode, Datum value, const char *attname, char *buf) const; + + /* + * Create a partition signature with current tuple(values/nulls) + */ + inline char *FormPartitionSignature(Datum *values, const bool *nulls); + + /* + * Flush buffer tuples into ORCfile or delta table also including those swapped + * in staging file + */ + void HandleTailData(int option); + + /* + * ------- member values ------------------------------- + * Pre-allocated partition-signatures to buffer the content of which is 'c1=1/c2=1/c3=1/', + * allocated at DfsPartitionInsert constructor + */ + char *m_parsigs; + + /* The relation of the partition table. */ + Relation m_relation; + bool m_isUpdate; + + /* The tuple description of the m_relation. */ + TupleDesc m_desc; + + /* The information of index. */ + ResultRelInfo *m_resultRelInfo; + + /* + * The common prefix of all the file path. + * e.g /user/tzhong/30_tzhong_mppdb.db/postgres/public.t1p/ + */ + StringInfo m_tableDirPath; + + /* + * Temp files hold tuples whose DfsInsert is not in active list when number of + * partition exceeds MAX allowed partitions. + */ + PartitionStagingFile **m_partitionStagingFiles; + + /* The context for partition buffer files. */ + MemoryContext m_partitionCtx; + + /* cache of for spilled partitions */ + HTAB *m_SpilledPartitionSearchCache; + + /* cache of for active partitions */ + HTAB *m_ActivePartitionSearchCache; + + /* TUPLE_SORT or BATCH_SORT */ + int m_type; + + /* + * Array length of m_parttitionStagingFiles + */ + int m_numPartitionStagingFiles; + + /* + * Get paritition staging file handler with given partition signature + */ + PartitionStagingFile *GetPartitionStagingFile(const char *parsig); + + /* valid iff TO_DELTA == cstore_insert_mode */ + Relation m_delta; + + /* Array for values and null flags. */ + Datum *m_values; + bool *m_nulls; + + /* + * Active 'patition writer' which is used to do TupleInsert() + */ + DfsInsert **m_pDfsInserts; + + /* The max number of writers which can be used for one partition writer */ + int m_maxPartitionWriters; + + /* The number of active writers for partition table currently. */ + int m_activePartitionWriters; + + /* dfs insert partition memory info. */ + MemInfoArg *dfsPartMemInfo; +}; +#endif diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_query_check.h postgresql-hll-2.14/include/access/dfs/dfs_query_check.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_query_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_query_check.h 2020-12-12 17:06:43.058345600 +0800 @@ -0,0 +1,115 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query_check.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query_check.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_QUERY_CHECK_H +#define DFS_QUERY_CHECK_H + +#include "access/dfs/dfs_wrapper.h" +/* + * Function to check if a value of basic type can match the clauses list pushed down. Here we do not + * check the length of scanClauses, and the caller need ensure it. + * + * @_in param value: The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * @_in param scanClauses: Clauses which can be pushed down to orc reader. + * + * @return True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + */ +template +bool HdfsPredicateCheckValue(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNULL == predicate->m_strategy) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + + return true; +} + +/* + * Function to check if a null value can match the clauses list pushed down. + * + * @_in param scanClauses: Clauses which can be pushed down for the partition and orc reader. + * + * @return True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + */ +template +bool HdfsPredicateCheckNull(List *scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + if (0 == list_length(scanClauses)) + return true; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + if (true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNULL == predicate->m_strategy) { + continue; + } else { + return false; + } + } + + return true; +} + +/* + * @Description: Check the column value by predicates. + * @in isNull, Whether the column is null value. + * @in value, If the column is not null, it presents the column value. + * @in predicateList, The pushdown predicates on this column. + * @return If the column value satisfies the predicates, return true, otherwise + * return false. + */ +template +bool HdfsPredicateCheck(bool isNull, baseType value, List *predicateList) +{ + bool filtered = false; + if (isNull) { + filtered = HdfsPredicateCheckNull(predicateList); + } else { + filtered = HdfsPredicateCheckValue(value, predicateList); + } + + return filtered; +} + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_query.h postgresql-hll-2.14/include/access/dfs/dfs_query.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_query.h 2020-12-12 17:06:43.058345600 +0800 @@ -0,0 +1,583 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_QUERY_H +#define DFS_QUERY_H + +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +#define DFS_PRIVATE_ITEM "DfsPrivateItem" +#define DFS_NUMERIC64_MAX_PRECISION 18 + +#ifdef ENABLE_LLVM_COMPILE +extern bool CodeGenThreadObjectReady(); +extern bool ForeignScanExprCodeGen(Expr *expr, PlanState *parent, void **jittedFunc); + +/* + * Declare the function pointers for LLVM machine code address. + */ +typedef bool (*evaPredicateDouble)(double value); +typedef bool (*evaPredicateInt)(int64_t value); +#endif + +/* + * define the strategy numbers for hdfs foriegn scan. -1 is invalid, + * 0-6 stand for op strategy, 11-12 stand for isnull/is not null. + */ +typedef enum { + HDFS_QUERY_INVALID = -1, + + /* + * 0-6 stand for OpExpr strategy, + * HDFS_QUERY_EQ: '=' + * HDFS_QUERY_LT: '<' + * HDFS_QUERY_GT: '>' + * HDFS_QUERY_LTE: '<=' + * HDFS_QUERY_GTE: '>=' + * HDFS_QUERY_NE1: '<>' + * HDFS_QUERY_NE2: '!=' + */ + HDFS_QUERY_EQ = 0, + HDFS_QUERY_LT = 1, + HDFS_QUERY_GT = 2, + HDFS_QUERY_LTE = 3, + HDFS_QUERY_GTE = 4, + HDFS_QUERY_NE1 = 5, + HDFS_QUERY_NE2 = 6, + + /* 11-12 stand for isnull/is not null */ + HDFS_QUERY_ISNULL = 11, + HDFS_QUERY_ISNOTNULL = 12, +} HdfsQueryOperator; + +typedef enum { + NO_ENCODING_CHECK = 0, + LOW_ENCODING_CHECK = 1, + HIGH_ENCODING_CHECK = 2 +} EncodingLevel; + +/* + * A template class which stores the info from the expression. This predicate will be pushed down to orc reader and + * check it before the conversion to datum. + */ +template +class HdfsScanPredicate : public BaseObject { +public: + AttrNumber m_attno; // column no + Oid m_attType; // column data type + int32 m_varTypMod; // the var type of the value + HdfsQueryOperator m_strategy; // the number of strategy + Oid m_collation; // collation to use, if needed + bool m_keepFalse; // the check result keeps false if it is true + T *m_argument; // store value +#ifdef ENABLE_LLVM_COMPILE + char *m_predFunc; /* IR function pointer */ + bool m_isPredJitted; /* whether use LLVM optimization or not. if the m_isPredJitted is true, use it */ + void *m_jittedFunc; /* machine code address pointer. */ +#endif + +public: + /* + * Construct function of template class HdfsScanPredicate + * + * @_in param attNo: the index no of the column in the relation defination. + * @_in param attType: the data type oid of the current var. + * @_in param strategy: the HdfsQueryOperator(=,<,>,<=,>=,<>,!=,is null,is not null) + */ + HdfsScanPredicate(AttrNumber attNo, Oid attType, HdfsQueryOperator strategy, Oid collation, int32 varTypMod) + : m_attno(attNo), + m_attType(attType), + m_varTypMod(varTypMod), + m_strategy(strategy), + m_collation(collation), + m_keepFalse(false) + { + m_argument = New(CurrentMemoryContext) T(strategy); +#ifdef ENABLE_LLVM_COMPILE + m_predFunc = NULL; + m_isPredJitted = false; + m_jittedFunc = NULL; +#endif + } + + ~HdfsScanPredicate() + { + delete (m_argument); + m_argument = NULL; + } + + /* + * Initialize the m_argument of HdfsScanPredicate by datumValue if it is a operation predicate. + * + * @_in param datumValue: Just as the name says, it is a value of datum. + * @_in param datumType: THe data type of the datum. + */ + inline void Init(Datum datumValue, Oid datumType, int32 typeMod) + { + if (m_strategy >= HDFS_QUERY_EQ && m_strategy <= HDFS_QUERY_NE2) { + m_argument->SetValueFromDatum(datumValue, datumType, typeMod); + } + } + + /* + * Set the keepFalse flag. + * + * @_in param keepFalse: flag indicates whether the check result keeps false. + */ + inline void setKeepFalse(bool keepFalse) + { + m_keepFalse = keepFalse; + } + + /* + * Build HdfsScanPredicate which will be pushed down to orc_reader according to the filtered and-clauses, we + * can not push down the or-clauses now. + * + * @_in param expr: Expression which has been filtered by the optimizer. + * @_in param state: PlanState is used when the expr is extern_param or exec_param to afford information. + * @_in param scanstate: ScanState is used when init rumtime predicate. + * @_in param varNoPos: An order number of var in the hdfsScanPredicateArr. + * @_in param predicateArrPos: The parameter predicate position in *hdfsScanPredicateArr. + * @return True: has init predicate; False, do not init predicate, need init dynamicly on running time phase. + */ + bool BuildHdfsScanPredicateFromClause(Expr *expr, PlanState *ps, ScanState *scanstate, AttrNumber varNoPos, + int predicateArrPos); + + /* + * Check the value by the predicate. + * + * @_in param value: The value to be checked, it is of basic type like int64 or char*. + * @return True: match and not filtered; False: filtered and set isSelected to false. + */ + inline bool HdfsPredicateCheckOne(baseType value) + { + return m_argument->CheckPredicate(value, m_collation); + } +}; + +#ifdef ENABLE_LLVM_COMPILE +/* + * Brief : Function to check if a value of basic type can match the clauses list pushed + * down. Here we do not check the length of scanClauses, and the caller need ensure it. + * Description : + * Input : value, The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * scanClauses, Clauses which can be pushed down to orc reader. + * Output : None. + * Return Value : True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + * Notes : If the predicate->m_isPredJitted is true, we choose LLVM optimization to check scanclauses. + */ +template +bool HdfsPredicateCheckValueIntForLlvm(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (NULL != predicate->m_jittedFunc) { + if (!((evaPredicateInt)(predicate->m_jittedFunc))(value)) { + return false; + } + + } else { + if (HDFS_QUERY_ISNULL == predicate->m_strategy || true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + } + + return true; +} + +/* + * Brief : Function to check if a value of basic type can match the clauses list pushed + * down. Here we do not check the length of scanClauses, and the caller need ensure it. + * Description : + * Input : value, The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * scanClauses, Clauses which can be pushed down to orc reader. + * Output : None. + * Return Value : True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + * Notes : If the predicate->m_isPredJitted is true, we choose LLVM optimization to check scanclauses. + */ +template +bool HdfsPredicateCheckValueDoubleForLlvm(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (NULL != predicate->m_jittedFunc) { + if (!((evaPredicateDouble)(predicate->m_jittedFunc))((double)value)) { + return false; + } + + } else { + if (HDFS_QUERY_ISNULL == predicate->m_strategy || true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + } + + return true; +} +#endif + + +/** + * @Description: Identify the qual which could be pushed down to + * file level(e.g. ORC reader level). + * @out hdfsPushDownQual: List to store all the clauses to push down. + * @in/out primitiveQual: As a input parameter, it represents all expression + * restrictions. As a output parameter, it represents actual expression + * restrictions for bottom scan(.e.g. dfs scan, foreign scan). + * @return Return the list of the column no which maps the pushdown qual. + */ +List *fix_pushdown_qual(List **hdfsPushDownQual, List **primitiveQual, const List *part_list); + +/* + * Convert a char* to Datum according to the data type oid. + * + * @_in param typeOid: The oid of the type in pg_type catalog. + * @_in param typeMod: The mod of data type. + * @_in param value: The string value which need to be converted to datum. + * @return Return the datum converted from String. + */ +Datum GetDatumFromString(Oid typeOid, int4 typeMod, char *value); + +void GetStringFromDatum(Oid typeOid, int4 typeMod, Datum data, StringInfo string); + +/* + * Initialize a folder split by the folder name, filename(both folder name and filename comprise the absolute file + * path), columnNo list of partition and column value list of partition. + * + * @_in param fileName: name of the file. + * @_in param partContentList: the list of value in partition column. + * @_in param objectSize: the size of the current object + * @return Return the constructed split. + */ +SplitInfo *InitFolderSplit(char *fileName, List *partContentList, int64 objectSize); + +/* + * Initialize a file split by the file path, columnNo list of partition and column value list of partition. This is + * different from InitFolderSplit for it use the absolute file path as the param and has no file name which is used for + * partition only. + * + * @_in param filePath: the absolute path of the split file. + * @_in param partContentList: the list of value in partition column. + * @_in param fileSize: the size of the current object + * @return Return the constructed split. + */ +SplitInfo *InitFileSplit(char *filePath, List *partContentList, int64 fileSize); + +/* + * Destroy all the structors in the split. + * @_in param split: The split need to to clean and is not used any more. + */ +void DestroySplit(SplitInfo *split); + +/* + * Build a basic Operator expression. + * @_in param variable: The var according to whose type we build the base constraint. + * @return Return and OpExpression. + */ +Node *MakeBaseConstraint(Var *variable, Datum minValue, Datum maxValue, bool hasMinimum, bool hasMaximum); + +Node *MakeBaseConstraintWithExpr(OpExpr *lessThanExpr, OpExpr *greaterThanExpr, Datum minValue, Datum maxValue, + bool hasMinimum, bool hasMaximum); + +OpExpr *MakeOperatorExpression(Var *variable, int16 strategyNumber); + +/* + * Build a new null test expr with the given type. + * + * @_in param variable: The value based on which we build a NullTest expression. + * @_in param type: is null or is not null. + * @return Return the NullTest expression we build here. + */ +Node *BuildNullTestConstraint(Var *variable, NullTestType type); + +/* + * Fill the expression with the const value. + * @_in param equalExpr: the expression of the constraint. + * @_in param value: Value to be filled for the right op. + * @_in param isNull: Whether the value is null. + * @return Return the constraint. + */ +void BuildConstraintConst(Expr *equalExpr, Datum value, bool isNull); + +/* + * Fetch the Var according to the column no from the columnList, used in partition filter. + * + * @_in param columnList: The column list from which we find the var. + * @_in param colNo: The column index by which we find the var. + * @return Return null: we don't find the var in the list with the colno; not null: we find the var and return it. + */ +Var *GetVarFromColumnList(List *columnList, int colNo); + +/* + * Return the digits of a int value. like 0 return 1, 10 return 2. + */ +uint64 GetDigitOfInt(uint64 x); + +/* + * Encode the uri char. Like "#" -> "%23", used in partition filter. + * + * @_in param pSrc: The uri format string to be encoded. + * @return Return the encoded string. + */ +char *UriEncode(const char *pSrc); + +/* + * Decode the uri char. Like "%23" -> "#", used in partition filter. + * + * @_in param pSrc: The uri format string to be decoded. + * @return Return the decoded string. + */ +char *UriDecode(const char *pSrc); + +/* + * Construct a node of DfsPrivateItem. + */ +DfsPrivateItem *MakeDfsPrivateItem(List *columnList, List *targetList, List *restrictColList, List *opExpressionList, + List *dnTask, List *hdfsQual, double *selectivity, int colNum, List *partList); + +/* + * Parse the fileNames string from the split List. + * @_in_out param splitList: point to the original split List, which may contain multiple files. + * @_in param currentFileName: point to the first file or the only file '/user/demai/file1.orc' (new buffer). + * @return Return the split parsed from the list. + */ +SplitInfo *ParseFileSplitList(List **splitList, char **currentFileName); + +/* + * @Description: find a split from the split list by file ID + * @IN splitList: the list of all splits + * @IN fileID: the file id + * @Return: the split if found, or return NULL + * @See also: + */ +SplitInfo *FindFileSplitByID(List *splitList, int fileID); + +/** + * @Description: Set all the rows of current ScalarVector with the same value transfered. + * The value can be null. + * @in vec, The scalar vector to which we set the value. + * @in rowsToRead, The number of rows to set. + * @in value: The fixed value to set all the rows. + * @in isNull, Whether the column value is null. + * @return None. + */ +void SetAllValue(ScalarVector *vec, int rows, Datum value, bool isNull); + +/* Brief: Acquires column information needed for this foreign table from the restriction. + * Returns them in a new list. + * input param @rel: relation information struct pointer. + */ +List *GetRestrictColumns(List *neededList, int count); + +/* + * Merge two list and kick out the repeated one. + * _in_param targetList: The list of the target columns. + * _in_param restrictList: The list of the restriction columns. + * _in_param count: The length of the result list. + * @return the merged and de-duplicated list. + */ +List *MergeList(List *targetList, List *restrictList, int count); + +/* + * @Description: build the columns list for dfsscan, which comes from reltargetlist + * and exclude the index columns. + * @IN reltargetlist: the primitive target list + * @IN excludedColList: the columns which should be abandoned. + * @Return: the final reader list for dfs scan + * @See also: + */ +List *build_dfs_reader_tlist(List *reltargetlist, List *excludedColList); + +/* + * Calculate the predicate selectivity of each column. + */ +void CalculateWeightByColumns(PlannerInfo *root, List *hdfsQualColumn, List *hdfsQual, double *selectivity, int colNum); + +/* + *brief: Check column data type for orc table. + *input param @ColType: Oid of column data type; + *input param @ColName: column name. + */ +void DFSCheckDataType(TypeName *typName, char* ColName, int format); + +/* + * brief: Check foldername, filenames, hdfscfgpath format. The rules are the followings: + * 1. The space do not allow appear in the entrie OptStr, but '\ ' is needed + * 2. The comma do not appera in beignning and ending of OptStr + * 3. The comma as a separator exists if OptStr have many filenames path + * 4. Only a foldername path exists for foldername option and hdfscfgpath + * 5. The OptStr do not be empty + * input param @OptStr: the foldername path or file names or hdfscfgpath string + * input param @OptType: a foldername, a filenames or a hdfscfgpath type + */ +void CheckFoldernameOrFilenamesOrCfgPtah(const char *OptStr, char *OptType); + +/* + * brief: Check or get port and ip of foreign server(Only support ipv4 format), + * the rules are the followings: + * 1. The space do not allow appear in the entrie Address + * 2. The comma do not appera in beignning and ending of Address + * 3. The comma as a separator exists if OptStr have many address + * 4. The Address do not be empty + * input param @Address: address option of foreign server + * output param @AddrList: return List included port and ip + * input param @IsCheck: if IsCheck is true, only check, else get port and ip + */ +void CheckGetServerIpAndPort(const char *Address, List **AddrList, bool IsCheck, int real_addr_max); + +/* + * brief: Build internal executor parameter predicate for pushdown of dfs scan + * when excute plan. + * input param @readerState: Includes all the params which are used during reading. + */ +void BuildRunTimePredicates(dfs::reader::ReaderState *readerState); + +/** + * @Description: Get the int64 data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. As for decimal data, the + * precision store here. + * @return return the transformed data. + */ +int64_t datumGetInt64ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the int128 data according to the column type. Currently, + * only the decimal may be converted to int128 data. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. As for decimal data, the + * precision store here. + * @return return the transformed data. + */ +__int128 datumGetInt128ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the float8 data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. + * @return return the transformed data. + */ +double datumGetFloat8ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the string data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. + * @return return the transformed data. + */ +char *datumGetStringByVar(Datum datumValue, Var *colVar); + +/* + * + * brief: Generate column list. + * input param @attributes: information of pg_attribure; + * input param @columnCount: the count of column. + * input param @colIdx: The column idx array. + */ +List *CreateColList(Form_pg_attribute *attributes, const int columnCount, const int16 *colIdx = NULL); + +/* + * @Description: remove the elements of the 'del' list in the 'src' list + */ +void list_delete_list(List **src, List *del); + +/** + * @Description: Check the given file encoding. + * @in optionDef: The envoding string. + * @return None. + */ +void checkEncoding(DefElem *optionDef); + +int FindLastCharPos(char seperator, const char *srcString); + +bool IsVarNode(Node *node); + +/** + * @Description: The default column value satisfies whether predicates. + * @in isNull, The default column whether is null. + * @in value, The default column value. + * @in colVar, The Var sturct of default column. + * @in predicateList, The default column predicates. + * @return If the default column value satisfies the default column predicates, + * return true, otherwise return false. + * @Notes: Only the column of the pushed down data type can reach here. + */ +bool defColSatisfyPredicates(bool isNull, Datum value, Var *col_var, List *predicate_list); +bool IsParamConst(Node *node); + +/** + * @Description: Convert the string according to the database encoding and original encoding. + * @in src: the input string. + * @in length: the length of the input string. + * @in encoding: the original encoding. + * @return the converted string. + */ +char *pg_to_server_withfailure(char *src, int64 length, int32 encoding, int32 checkEncodingLevel, bool &meetError); + +BlockNumber getPageCountForFt(void *additionalData); + +#define QUERY_NOT_SUPPORT(foreignTableId, msg) do { \ + Relation relation = RelationIdGetRelation(foreignTableId); \ + if (RelationIsValid(relation)) \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), \ + errmsg(msg, RelationGetRelationName(relation)))); \ + else \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), \ + errmsg("could not open relation with OID %u", foreignTableId))); \ +} while (0) + +#endif /* DFS_QUERY_H */ diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_query_reader.h postgresql-hll-2.14/include/access/dfs/dfs_query_reader.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_query_reader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_query_reader.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query_reader.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query_reader.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_QUERY_READER_H +#define DFS_QUERY_READER_H +extern HdfsQueryOperator HdfsGetQueryOperator(const char *operatorName); +/* + * Fill up the structure: readerState which can not be NULL. + */ +extern void FillReaderState(dfs::reader::ReaderState *readerState, ScanState *ss, + DfsPrivateItem *item, Snapshot snapshot = NULL); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_stream_factory.h postgresql-hll-2.14/include/access/dfs/dfs_stream_factory.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_stream_factory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_stream_factory.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_stream_factory.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_stream_factory.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_STREAM_FACTORY_H +#define DFS_STREAM_FACTORY_H + +#include + +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_stream.h" + +namespace dfs { + +DFS_UNIQUE_PTR InputStreamFactory(dfs::DFSConnector *conn, const std::string &path, + dfs::reader::ReaderState *readerState, bool use_cache); +} +#endif diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_stream.h postgresql-hll-2.14/include/access/dfs/dfs_stream.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_stream.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_stream.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_STREAM_H +#define DFS_STREAM_H + +#include +#include +#include + +#include "dfs_config.h" // for DFS_UNIQUE_PTR + +namespace dfs { + +class GSInputStream { +public: + virtual ~GSInputStream(){}; + + /* + * Get the total length of the file in bytes. + */ + virtual uint64_t getLength() const = 0; + + /* + * Get the natural size for reads. + * @return the number of bytes that should be read at once + */ + virtual uint64_t getNaturalReadSize() const = 0; + + /* + * Read length bytes from the file starting at offset into + * the buffer starting at buf. + * @param buf the starting position of a buffer. + * @param length the number of bytes to read. + * @param offset the position in the stream to read from. + */ + virtual void read(void *buf, uint64_t length, uint64_t offset) = 0; + + /* + * Get the name of the stream for error messages. + */ + virtual const std::string &getName() const = 0; + + virtual void getStat(uint64_t *localBlock, uint64_t *remoteBlock, uint64_t *nnCalls, uint64_t *dnCalls) = 0; + + virtual void getLocalRemoteReadCnt(uint64_t *localReadCnt, uint64_t *remoteReadCnt) = 0; + + virtual DFS_UNIQUE_PTR copy() = 0; +}; + +} // namespace dfs + +#endif diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_update.h postgresql-hll-2.14/include/access/dfs/dfs_update.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_update.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_update.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,84 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_update.h + * routines to support dfs + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_update.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_UPDATE_H +#define DFS_UPDATE_H + +#include "access/cstore_update.h" +#include "access/dfs/dfs_insert.h" +#include "access/dfs/dfs_delete.h" + +class DfsUpdate : public BaseObject { +public: + DfsUpdate(Relation, EState *, Plan *plan = NULL); + virtual ~DfsUpdate(); + + virtual void Destroy(); + + /* initialize the memory info */ + void InitUpdateMemArg(Plan *plan = NULL); + + /* + * initialize sort cache with tuple descriptor. + */ + void InitSortState(TupleDesc sortTupDesc); + + /* + * do "update" job really, and return the number of updated rows. + */ + uint64 ExecUpdate(VectorBatch *batch, int options); + + /* + * called at last step, make sure that data in cache can be deleted and new + * data can be inserted. + */ + void EndUpdate(int options); + +private: + /* + * target relation to be updated + */ + Relation m_relation; + + /* + * objects used to implement "delete" and "insert" + */ + DfsDelete *m_delete; + DfsInsertInter *m_insert; + + /* + * state data used on update + */ + ResultRelInfo *m_resultRelInfo; + EState *m_estate; + + /* + * the memory info to "delete" and "insert" + */ + MemInfoArg *m_dfsUpDelMemInfo; + MemInfoArg *m_dfsUpInsMemInfo; +}; + +#endif /* DFS_UPDATE_H */ diff -uprN postgresql-hll-2.14_old/include/access/dfs/dfs_wrapper.h postgresql-hll-2.14/include/access/dfs/dfs_wrapper.h --- postgresql-hll-2.14_old/include/access/dfs/dfs_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/dfs/dfs_wrapper.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,484 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_wrapper.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_wrapper.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_WRAPPER_H +#define DFS_WRAPPER_H +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_common.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +/* + * The base template class for all the data type wrapper to inherit. + */ +template +class HdfsCheckWrapper : public BaseObject { +public: + virtual ~HdfsCheckWrapper() + { + } + /* + * Abstract function to compare the argument and velue. + * @_in param argument: The target to be compared with the member value. + * @_in param collation: the collation of the var, it is used in function varstr_cmp. + * @return Return 1=eq, -1=lt, 1=gt. + */ + virtual int compareT(T argument, Oid collation) = 0; + + /* + * Set the value in the class which is converted from datum. + * @_in param datumValue: the datum value to be set. + * @_in param datumType: the data type oid of the datum. + * @_in param typeMod: the mod of the datum type. + */ + virtual void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) = 0; + + /* + * A template function to check if the argument transfered in can be filtered. All the non-string + * wrapper will inherit this function for call. + * + * @_in param argument: the value transfered in to be checked + * @_in param strategy: the strategy used in the predicate. + * @_in param collation: the collation of the var, it is used in function varstr_cmp. + * @return True: match and not filtered; False: filtered and set isSelected to false. + */ + inline bool CheckPredicate(T argument, Oid collation) + { + int cmpResult = compareT(argument, collation); + return HdfsCheckCompareResult(cmpResult); + } + + /* + * Get the value of the wrapper. + * @return Return the value in the class. + */ + inline const T getValue() + { + return value; + } + + /* + * Get the datum of the wrapper. + * @return the datum value. + */ + inline Datum getDatum() + { + return dValue; + } + +private: + /* + * Check the compare result depending on the strategy of the predicate pushed down. + * + * @_in param cmpResult: The result of comparision, (o=eq, -1=lt, 1=gt) + * + * @return True: indicates the value of the row and column match the preidcate pushed down; False: + * indicates the value does not match the predicate and need to be filtered. + */ + bool HdfsCheckCompareResult(int cmpResult); + +protected: + /* Store the real value of the wrapper with type T. */ + T value; + Datum dValue; + + /* + * The strategy of the predicate's operator, which must between HDFS_QUERY_EQ + * and HDFS_QUERY_NE2. + */ + HdfsQueryOperator strategy; + int32 typeMod; + Oid datumType; +}; + +/* + * Check the result of comparation according to the strategy. + */ +template +inline bool HdfsCheckWrapper::HdfsCheckCompareResult(int cmpResult) +{ + bool result = false; + switch (strategy) { + case HDFS_QUERY_LT: { + if (0 > cmpResult) + result = true; + break; + } + case HDFS_QUERY_LTE: { + if (0 >= cmpResult) + result = true; + break; + } + case HDFS_QUERY_EQ: { + if (0 == cmpResult) + result = true; + break; + } + case HDFS_QUERY_GTE: { + if (0 <= cmpResult) + result = true; + break; + } + case HDFS_QUERY_GT: { + if (0 < cmpResult) + result = true; + break; + } + case HDFS_QUERY_NE1: + case HDFS_QUERY_NE2: { + if (0 != cmpResult) + result = true; + break; + } + case HDFS_QUERY_INVALID: + default: { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), + errmsg("Find unsupported strategy %d!", strategy))); + } + } + + return result; +} + +/* + * A wrapper class of int64 type, inherit HdfsCheckWrapper. Here we do not seperate + * int16, int 32 and int64 wrapper just because what we read from orc file directly for int16,int32 and int64 + * is int64, then it will convert to int16,int32 or int64 datum. Since the predicate need to be checked before + * the conversion from basic type to datum, so we will compare the int64 value directly and needn't + * Int32Wrapper and Int16Wrapper. + */ +class Int64Wrapper : public HdfsCheckWrapper { +public: + Int64Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Int64Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + + if (INT1OID == datumType) { + value = DatumGetChar(datumValue); + } else if (INT2OID == datumType) { + value = DatumGetInt16(datumValue); + } else if (INT4OID == datumType) { + value = DatumGetInt32(datumValue); + } else if (NUMERICOID == datumType) { + int dscale = (unsigned int)(typeMod - VARHDRSZ) & 0xffff; + Numeric n = DatumGetNumeric(datumValue); + if (NUMERIC_IS_BI(n)) { + Assert(dscale == NUMERIC_BI_SCALE(n)); + Assert(NUMERIC_IS_BI64(n)); + + value = NUMERIC_64VALUE(n); + } else + value = convert_short_numeric_to_int64_byscale(n, dscale); + } else { + value = DatumGetInt64(datumValue); + } + } + +private: + inline int compareT(int64 argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* just for decimal128, 18 < p <= 38 */ +class Int128Wrapper : public HdfsCheckWrapper { +public: + Int128Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Int128Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + int dscale = (unsigned int)(typeMod - VARHDRSZ) & 0xffff; + + dValue = datumValue; + Numeric n = DatumGetNumeric(datumValue); + if (NUMERIC_IS_BI(n)) { + Assert(dscale == NUMERIC_BI_SCALE(n)); + + if (NUMERIC_IS_BI128(n)) { + errno_t rc = EOK; + rc = memcpy_s(&value, sizeof(int128), (n)->choice.n_bi.n_data, sizeof(int128)); + securec_check(rc, "\0", "\0"); + } else + value = NUMERIC_64VALUE(n); + } else + convert_short_numeric_to_int128_byscale(n, dscale, value); + } + +private: + inline int compareT(int128 argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of bool type, inherit HdfsCheckWrapper. The actual value stored is a char here. + */ +class BoolWrapper : public HdfsCheckWrapper { +public: + BoolWrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~BoolWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + value = DatumGetBool(datumValue); + } + +private: + inline int compareT(char argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of float8 type, inherit HdfsCheckWrapper. + */ +class Float8Wrapper : public HdfsCheckWrapper { +public: + Float8Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Float8Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid _datumType, int32 typeMod) + { + datumType = _datumType; + /* + * For float4/8, there may be data convertion of the const value, so we + * need to process seperately here. + */ + if (FLOAT4OID == datumType) { + value = (float8)DatumGetFloat4(datumValue); + dValue = Float8GetDatum(value); + } else // float8 + { + value = DatumGetFloat8(datumValue); + dValue = datumValue; + } + } + +private: + inline int compareT(float8 argument, Oid collation) + { + int cmp = 0; + FLOAT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of Timestamp type, inherit HdfsCheckWrapper. Since there is not actual Date type + * in PG, we just need the wrapper for Timestamp here, and convert the hive date to timestamp before + * the comparasion with predicate. + */ +class TimestampWrapper : public HdfsCheckWrapper { +public: + TimestampWrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~TimestampWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + + /* + * For different time types, we use different ways to convert to timestamp. + */ + if (DATEOID == datumType) { + value = date2timestamp(DatumGetDateADT(datumValue)); + } else if (TIMESTAMPTZOID == datumType) { + Datum out = DirectFunctionCall1(timestamptz_out, datumValue); + Datum in = DirectFunctionCall3(timestamp_in, out, ObjectIdGetDatum(InvalidOid), Int32GetDatum(typeMod)); + value = DatumGetTimestamp(in); + } else { + value = DatumGetTimestamp(datumValue); + } + } + +private: + inline int compareT(Timestamp argument, Oid collation) + { + int cmp = 0; +#ifdef HAVE_INT64_TIMESTAMP + INT_CMP_HDFS(argument, value, cmp); +#else + FLOAT_CMP_HDFS(argument, value, cmp); +#endif + return cmp; + } +}; + +/* + * Since we only care about equality or not-equality, we can avoid all the + * expense of strcoll() here, and just do bitwise comparison. + * The caller must ensure that both src1 and src2 are valid strings with '\0' at end. + * return 0 if the two strings are equal. + */ +static int stringEQ(const char *src1, const char *src2) +{ + int result = 0; + int len1 = strlen(src1); + int len2 = strlen(src2); + if (len1 != len2) { + result = 1; + } else { + result = memcmp(src1, src2, len1); + } + return result; +} + +/* + * A wrapper class of string type includes varchar,bpchar,text because these types is actually the same for hive. + */ +class StringWrapper : public HdfsCheckWrapper { +public: + StringWrapper(HdfsQueryOperator _strategy) + { + value = NULL; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~StringWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid _datumType, int32 typeMod) + { + dValue = datumValue; + datumType = _datumType; + + if (BPCHAROID == datumType) { + int varLen = 0; + char *str = TextDatumGetCString(datumValue); + int strLen = strlen(str); + + /* variable length */ + if (typeMod < (int32)VARHDRSZ) { + varLen = strLen; + } else /* fixed length */ + { + varLen = typeMod - VARHDRSZ; + } + + /* + * When the length of the var is larger than the const string's length, it needs to + * add some blanks in the tail. + */ + if (varLen >= strLen) { + Datum bpchar = DirectFunctionCall3(bpcharin, CStringGetDatum(str), ObjectIdGetDatum(InvalidOid), + Int32GetDatum(typeMod)); + value = TextDatumGetCString(bpchar); + } else { + value = str; + } + } else { + value = TextDatumGetCString(datumValue); + } + } + +private: + inline int compareT(char *argument, Oid collation) + { + int cmp = 0; + if (HDFS_QUERY_EQ == strategy || HDFS_QUERY_NE1 == strategy || HDFS_QUERY_NE2 == strategy) { + cmp = stringEQ(argument, value); + } else { + cmp = varstr_cmp(argument, strlen(argument), value, strlen(value), collation); + } + return cmp; + } +}; + +/* + * This wrapper is only used for HdfsPredicateCheckNull, and there is need to store any value here. We don't + * remove it because Null check is processed specially and keeping a special empty wrapper for null can + * make it less confused. + */ +class NullWrapper { +}; + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/double_write_basic.h postgresql-hll-2.14/include/access/double_write_basic.h --- postgresql-hll-2.14_old/include/access/double_write_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/double_write_basic.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,152 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * double_write_basic.h + * Define some basic structs of double write which is needed in knl_instance.h + * + * + * IDENTIFICATION + * src/include/access/double_write_basic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DOUBLE_WRITE_BASIC_H +#define DOUBLE_WRITE_BASIC_H + +#include /* need open() flags */ +#include "c.h" +#include "knl/knl_thread.h" +#include "utils/palloc.h" + +static const uint32 HALF_K = 512; + +static const char DW_FILE_NAME[] = "global/pg_dw"; +static const char SINGLE_DW_FILE_NAME[] = "global/pg_dw_single"; +static const char DW_BUILD_FILE_NAME[] = "global/pg_dw.build"; + +static const uint32 DW_TRY_WRITE_TIMES = 8; + +static const int DW_FILE_FLAG = (O_RDWR | O_SYNC | O_DIRECT | PG_BINARY); + +static const mode_t DW_FILE_PERM = (S_IRUSR | S_IWUSR); + +static const int DW_FILE_EXTEND_SIZE = (BLCKSZ * HALF_K); + +/* 32k pages, 8k each, file size 256M in total */ +static const uint16 DW_FILE_PAGE = 32768; + +static const int64 DW_FILE_SIZE = (DW_FILE_PAGE * BLCKSZ); + +/* make file head size to 512 bytes in total, 12 bytes including head and tail, 500 bytes alignment */ +static const uint32 DW_FILE_HEAD_ALIGN_BYTES = 500; + +/** + * | file_head | batch head | data pages | batch tail/next batch head | ... | + * | 0 | 1 | 409 at most | 1 | ... | + */ +static const uint16 DW_BATCH_FILE_START = 1; + +#define REDUCE_CKS2UINT16(cks) (((cks) >> 16) ^ ((cks)&0xFFFF)) + +typedef struct st_dw_page_head { + uint16 page_id; /* page_id in file */ + uint16 dwn; /* double write number, updated when file header changed */ +} dw_page_head_t; + +typedef struct st_dw_page_tail { + uint16 checksum; + uint16 dwn; /* double write number, updated when file header changed */ +} dw_page_tail_t; + +typedef struct st_dw_file_head { + dw_page_head_t head; + uint16 start; + uint16 buftag_version; + uint8 unused[DW_FILE_HEAD_ALIGN_BYTES]; /* 512 bytes total, one sector for most disks */ + dw_page_tail_t tail; +} dw_file_head_t; + +static const uint32 DW_FILE_HEAD_ID_NUM = 3; + +/* write file head 3 times, distributed in start, middle, end of the first page of dw file */ +static const uint16 g_dw_file_head_ids[DW_FILE_HEAD_ID_NUM] = {0, 8, 15}; + +const static uint64 DW_SLEEP_US = 1000L; + +const static uint16 DW_WRITE_STAT_LOWER_LIMIT = 16; + +const static int DW_VIEW_COL_NUM = 11; +const static int DW_SINGLE_VIEW_COL_NUM = 6; + +const static uint32 DW_VIEW_COL_NAME_LEN = 32; + +#define DW_PAGE_TAIL(page) ((dw_page_tail_t*)((char*)(page) + (BLCKSZ - sizeof(dw_page_tail_t)))) + +#define DW_PAGE_CHECKSUM(page) (DW_PAGE_TAIL(page)->checksum) + +#ifdef DW_DEBUG +#define DW_LOG_LEVEL LOG +#else +#define DW_LOG_LEVEL DEBUG1 +#endif + +typedef Datum (*dw_view_get_data_func)(); + +typedef struct st_dw_view_col { + char name[DW_VIEW_COL_NAME_LEN]; + Oid data_type; + dw_view_get_data_func get_data; +} dw_view_col_t; + +typedef struct st_dw_read_asst { + int fd; + uint16 file_start; /* reading start page id in file */ + uint16 file_capacity; /* max pages of the file */ + uint16 buf_start; /* start page of the buf */ + uint16 buf_end; /* end page of the buf */ + uint16 buf_capacity; /* max pages the buf can hold */ + char* buf; +} dw_read_asst_t; + +typedef struct dw_stat_info_batch { + volatile uint64 file_trunc_num; /* truncate file */ + volatile uint64 file_reset_num; /* file full and restart from beginning */ + volatile uint64 total_writes; /* total double write */ + volatile uint64 low_threshold_writes; /* less than 16 pages */ + volatile uint64 high_threshold_writes; /* more than one full batch (409 pages) */ + volatile uint64 total_pages; /* pages total */ + volatile uint64 low_threshold_pages; /* less than 16 pages total */ + volatile uint64 high_threshold_pages; /* more than one full batch (409 pages) total */ +} dw_stat_info_batch; + +typedef struct dw_stat_info_single { + volatile uint64 file_trunc_num; /* truncate file */ + volatile uint64 file_reset_num; /* file full and restart from beginning */ + volatile uint64 total_writes; /* total double write */ +} dw_stat_info_single; + +typedef struct single_slot_pos { + LWLock* write_lock; /* The dw write lock corresponding to the slot */ + uint16 actual_pos; /* correspond to the actual double write file slot */ +}single_slot_pos; + +typedef struct single_slot_state { + bool data_flush; /* The buffer corresponding to the slot finish data file flush */ +}single_slot_state; + +extern const dw_view_col_t g_dw_view_col_arr[DW_VIEW_COL_NUM]; +extern const dw_view_col_t g_dw_single_view[DW_SINGLE_VIEW_COL_NUM]; + +#endif /* DOUBLE_WRITE_BASIC_H */ diff -uprN postgresql-hll-2.14_old/include/access/double_write.h postgresql-hll-2.14/include/access/double_write.h --- postgresql-hll-2.14_old/include/access/double_write.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/double_write.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,282 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * double_write.h + * Define some inline function of double write and export some interfaces. + * + * + * IDENTIFICATION + * src/include/access/double_write.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DOUBLE_WRITE_H +#define DOUBLE_WRITE_H + +#include "double_write_basic.h" +#include "storage/buf_internals.h" +#include "storage/checksum_impl.h" + +typedef enum BufTagVer { + ORIGIN_TAG = 0, + HASHBUCKET_TAG +} BufTagVer; + +typedef struct st_dw_batch { + dw_page_head_t head; + uint16 page_num; /* for batch head, number of data pages */ + uint16 buftag_ver; + BufferTag buf_tag[0]; /* to locate the data pages in batch */ +} dw_batch_t; + +typedef struct st_dw_batch_nohbkt { + dw_page_head_t head; + uint16 page_num; /* for batch head, number of data pages */ + uint16 buftag_ver; + BufferTagFirstVer buf_tag[0]; /* to locate the data pages in batch */ +} dw_batch_first_ver; + +typedef struct dw_single_flush_item { + uint16 data_page_idx; /* from zero start, indicates the slot of the data page. */ + uint16 dwn; /* double write number, updated when file header changed */ + BufferTag buf_tag; + pg_crc32c crc; /* CRC of all above ... MUST BE LAST! */ +}dw_single_flush_item; + +/* Used by double_write to mark the buffers which are not flushed in the given buf_id array. */ +static const int DW_INVALID_BUFFER_ID = -1; +/* steal high bit from pagenum as the flag of hashbucket */ +#define IS_HASH_BKT_MASK (0x8000) +#define GET_REL_PGAENUM(pagenum) (pagenum & ~IS_HASH_BKT_MASK) + +/** + * Dirty data pages in one batch + * The number of data pages depends on the number of BufferTag one page can hold + */ +static const uint16 DW_BATCH_DATA_PAGE_MAX = + (uint16)((BLCKSZ - sizeof(dw_batch_t) - sizeof(dw_page_tail_t)) / sizeof(BufferTag)); + +static const uint16 DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK = + (uint16)((BLCKSZ - sizeof(dw_batch_first_ver) - sizeof(dw_page_tail_t)) / sizeof(BufferTagFirstVer)); + + +/* 1 head + data + 1 tail */ +static const uint16 DW_EXTRA_FOR_ONE_BATCH = 2; + +/* 1 head + data + [1 tail, 2 head] + data + 2 tail */ +static const uint16 DW_EXTRA_FOR_TWO_BATCH = 3; + +static const uint16 DW_BATCH_MIN = (1 + DW_EXTRA_FOR_ONE_BATCH); + +static const uint16 DW_BATCH_MAX = (DW_BATCH_DATA_PAGE_MAX + DW_EXTRA_FOR_ONE_BATCH); + +/* 2 batches at most for one perform */ +static const uint16 DW_DIRTY_PAGE_MAX = (DW_BATCH_DATA_PAGE_MAX + DW_BATCH_DATA_PAGE_MAX); + +static const uint16 DW_BUF_MAX = (DW_DIRTY_PAGE_MAX + DW_EXTRA_FOR_TWO_BATCH); + +static const uint16 DW_BATCH_MAX_FOR_NOHBK = (DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK + DW_EXTRA_FOR_ONE_BATCH); + +/* 2 batches at most for one perform */ +static const uint16 DW_DIRTY_PAGE_MAX_FOR_NOHBK = (DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK + DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK); + +static const uint16 DW_BUF_MAX_FOR_NOHBK = (DW_DIRTY_PAGE_MAX_FOR_NOHBK + DW_EXTRA_FOR_TWO_BATCH); + + +#define GET_DW_BATCH_DATA_PAGE_MAX(contain_hashbucket) (!contain_hashbucket ? DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK : DW_BATCH_DATA_PAGE_MAX) + +#define GET_DW_BATCH_MAX(contain_hashbucket) (!contain_hashbucket ? DW_BATCH_MAX_FOR_NOHBK : DW_BATCH_MAX) + + +#define GET_DW_DIRTY_PAGE_MAX(contain_hashbucket) (!contain_hashbucket ? DW_DIRTY_PAGE_MAX_FOR_NOHBK : DW_DIRTY_PAGE_MAX) + +#define GET_DW_MEM_CTX_MAX_BLOCK_SIZE(contain_hashbucket) (!contain_hashbucket ? DW_MEM_CTX_MAX_BLOCK_SIZE_FOR_NOHBK : DW_MEM_CTX_MAX_BLOCK_SIZE) + +/* + * 1 block for alignment, 1 for file_head, 1 for reading data_page during recovery + * and DW_BUF_MAX for double_write buffer. + */ +static const uint32 DW_MEM_CTX_MAX_BLOCK_SIZE = ((1 + 1 + 1 + DW_BUF_MAX) * BLCKSZ); + +static const uint32 DW_MEM_CTX_MAX_BLOCK_SIZE_FOR_NOHBK = ((1 + 1 + 1 + DW_BUF_MAX_FOR_NOHBK) * BLCKSZ); + +const uint16 SINGLE_BLOCK_TAG_NUM = BLCKSZ / sizeof(dw_single_flush_item); + +static const uint32 DW_BOOTSTRAP_VERSION = 91261; +const uint32 DW_SUPPORT_SINGLE_FLUSH_VERSION = 92266; + +/* dw single flush file information */ +/* file head + storage buffer tag page + data page */ +const int DW_SINGLE_FILE_SIZE = (1 + 161 + 32768) * 8192; + +/* Reserve 8 bytes for bufferTag upgrade. now usepage num is 32768 * sizeof(dw_single_flush_item) / 8192 */ +const int DW_SINGLE_BUFTAG_PAGE_NUM = 161; +const int DW_SINGLE_DIRTY_PAGE_NUM = 32768; + +inline bool dw_buf_valid_dirty(uint32 buf_state) +{ + return ((buf_state & (BM_VALID | BM_DIRTY)) == (BM_VALID | BM_DIRTY)); +} + +inline bool dw_buf_ckpt_needed(uint32 buf_state) +{ + return ((buf_state & (BM_VALID | BM_DIRTY | BM_CHECKPOINT_NEEDED)) == (BM_VALID | BM_DIRTY | BM_CHECKPOINT_NEEDED)); +} + +inline bool dw_verify_file_head_checksum(dw_file_head_t* file_head) +{ + uint32 checksum; + uint16 org_cks = file_head->tail.checksum; + + file_head->tail.checksum = 0; + checksum = pg_checksum_block((char*)file_head, sizeof(dw_file_head_t)); + file_head->tail.checksum = org_cks; + + return (org_cks == REDUCE_CKS2UINT16(checksum)); +} + +inline bool dw_verify_file_head(dw_file_head_t* file_head) +{ + return file_head->head.dwn == file_head->tail.dwn && dw_verify_file_head_checksum(file_head); +} + +inline void dw_calc_file_head_checksum(dw_file_head_t* file_head) +{ + uint32 checksum; + file_head->tail.checksum = 0; + checksum = pg_checksum_block((char*)file_head, sizeof(dw_file_head_t)); + file_head->tail.checksum = REDUCE_CKS2UINT16(checksum); +} + +inline bool dw_verify_batch_checksum(dw_batch_t* batch) +{ + uint32 checksum; + uint16 org_cks = DW_PAGE_CHECKSUM(batch); + + DW_PAGE_CHECKSUM(batch) = 0; + checksum = pg_checksum_block((char*)batch, BLCKSZ); + DW_PAGE_CHECKSUM(batch) = org_cks; + + return (org_cks == REDUCE_CKS2UINT16(checksum)); +} + +inline bool dw_verify_page(dw_batch_t* page) +{ + return (page)->head.dwn == DW_PAGE_TAIL(page)->dwn && dw_verify_batch_checksum(page); +} + +inline void dw_calc_batch_checksum(dw_batch_t* batch) +{ + uint32 checksum; + + DW_PAGE_CHECKSUM(batch) = 0; + checksum = pg_checksum_block((char*)batch, BLCKSZ); + DW_PAGE_CHECKSUM(batch) = REDUCE_CKS2UINT16(checksum); +} + +inline dw_batch_t* dw_batch_tail_page(dw_batch_t* head_page) +{ + return (dw_batch_t*)((char*)head_page + BLCKSZ * (GET_REL_PGAENUM(head_page->page_num) + 1)); +} + +/** + * verify the batch head and tail page, including dwn and checksum + * @param head_page batch head + * @param dwn double write number + * @return true dwn and checksum match + */ +inline bool dw_verify_batch(dw_batch_t* head_page, uint16 dwn) +{ + if (head_page->head.dwn == dwn && dw_verify_page(head_page)) { + dw_batch_t* tail_page = dw_batch_tail_page(head_page); + return tail_page->head.dwn == dwn && dw_verify_page(tail_page); + } + + return false; +} + +inline uint64 dw_page_distance(void* left, void* right) +{ + return ((char*)right - (char*)left) / BLCKSZ; +} + +int64 dw_seek_file(int fd, int64 offset, int32 origin); + +void dw_pread_file(int fd, void* buf, int size, int64 offset); + +void dw_pwrite_file(int fd, const void* buf, int size, int64 offset); + +/** + * generate the file for the database first boot + */ +void dw_bootstrap(); + +/** + * do the memory allocate, spin_lock init, LWLock assign and double write recovery + * all the half-written pages should be recovered after this + * it should be finished before XLOG module start which may replay redo log + */ +void dw_init(bool shutdown); + +/** + * double write only work when incremental checkpoint enabled and double write enabled + * @return true if both enabled + */ +inline bool dw_enabled() +{ + return ( + g_instance.attr.attr_storage.enableIncrementalCheckpoint && g_instance.attr.attr_storage.enable_double_write); +} + +/** + * flush the buffers identified by the buf_id in buf_id_arr to double write file + * a token_id is returned, thus double write wish the caller to return it after the + * caller finish flushing the buffers to data file and forwarding the fsync request + * @param buf_id_arr the buffer id array which is used to get page from global buffer + * @param size the array size + */ +void dw_perform_batch_flush(uint32 size, CkptSortItem *dirty_buf_list, ThrdDwCxt* thrd_dw_cxt); + +/** + * truncate the pages in double write file after ckpt or before exit + * wait for tokens, thus all the relative data file flush and fsync request forwarded + * then its safe to call fsync to make sure pages on data file + * and then safe to discard those pages on double write file + */ +void dw_truncate(); + +/** + * double write exit after XLOG exit. + * data file flushing, page writer and checkpointer thread may still running. wait for them. + */ +void dw_exit(bool single); + +/** + * If double write is enabled and pagewriter is running, + * the dirty pages should only be flushed by pagewriter. + */ +inline bool dw_page_writer_running() +{ + return (dw_enabled() && pg_atomic_read_u32(&g_instance.ckpt_cxt_ctl->current_page_writer_count) > 0); +} + +extern uint16 dw_single_flush(BufferDesc *buf_desc); +extern bool dw_single_file_recycle(bool trunc_file); +extern bool backend_can_flush_dirty_page(); +extern void dw_force_reset_single_file(); +extern void reset_dw_pos_flag(); +extern void clean_proc_dw_buf(); +extern void init_proc_dw_buf(); +#endif /* DOUBLE_WRITE_H */ diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/batch_redo.h postgresql-hll-2.14/include/access/extreme_rto/batch_redo.h --- postgresql-hll-2.14_old/include/access/extreme_rto/batch_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/batch_redo.h 2020-12-12 17:06:43.059345612 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * batch_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/batch_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BATCH_REDO_H +#define BATCH_REDO_H + +#include "c.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "lib/dllist.h" +#include "utils/hsearch.h" +#include "access/xlogproc.h" +#include "access/xlogutils.h" + +namespace extreme_rto { + +#define PAGETYPE_DROP 0x04 +#define PAGETYPE_CREATE 0x02 +#define PAGETYPE_TRUNCATE 0x01 +#define PAGETYPE_MODIFY 0x00 + +#define INITredoItemHashSIZE 1024 + +#define INIT_REDO_ITEM_TAG(a, xx_rnode, xx_forkNum, xx_blockNum) \ + ((a).rNode = (xx_rnode), (a).forkNum = (xx_forkNum), (a).blockNum = (xx_blockNum)) + +#define InvalidRelFileNode ((RelFileNode){ 0, 0, 0 }) + +/* + * Note: if there are any pad bytes in the struct, INIT_RedoItemTag have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct redoitemtag { + RelFileNode rNode; + ForkNumber forkNum; + BlockNumber blockNum; +} RedoItemTag; + +typedef struct redoitemhashentry { + RedoItemTag redoItemTag; + XLogRecParseState *head; + XLogRecParseState *tail; + int redoItemNum; +} RedoItemHashEntry; + +extern void PRPrintRedoItemHashTab(HTAB *redoItemHash); +extern HTAB *PRRedoItemHashInitialize(MemoryContext context); +extern void PRTrackClearBlock(XLogRecParseState *recordBlockState, HTAB *redoItemHash); +extern void PRTrackAddBlock(XLogRecParseState *recordBlockState, HTAB *redoItemHash); + +} // namespace extreme_rto +#endif /* BATCH_REDO_H */ diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/dispatcher.h postgresql-hll-2.14/include/access/extreme_rto/dispatcher.h --- postgresql-hll-2.14_old/include/access/extreme_rto/dispatcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/dispatcher.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,253 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dispatcher.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/dispatcher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_DISPATCHER_H +#define EXTREME_RTO_DISPATCHER_H + +#include "gs_thread.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" +#include "access/redo_statistic.h" +#include "access/extreme_rto/redo_item.h" +#include "access/extreme_rto/page_redo.h" +#include "access/extreme_rto/txn_redo.h" + +namespace extreme_rto { + +typedef struct { + PageRedoWorker *batchThd; /* BatchRedoThread */ + PageRedoWorker *managerThd; /* PageRedoManager */ + PageRedoWorker **redoThd; /* RedoThreadPool */ + uint32 redoThdNum; + uint32 *chosedRTIds; /* chosedRedoThdIds */ + uint32 chosedRTCnt; /* chosedRedoThdCount */ +} PageRedoPipeline; + +typedef struct { + PageRedoWorker *managerThd; /* TrxnRedoManager */ + PageRedoWorker *redoThd; /* TrxnRedoWorker */ +} TrxnRedoPipeline; + +typedef struct ReadPipeline { + PageRedoWorker *managerThd; /* readthrd */ + PageRedoWorker *readPageThd; /* readthrd */ + PageRedoWorker *readThd; /* readthrd */ +} ReadPipeline; + +#define MAX_XLOG_READ_BUFFER (0xFFFFF) /* 8k uint */ + +#define MAX_ALLOC_SEGNUM (4) /* 16* 4 */ + +typedef enum { + WORKER_STATE_STOP = 0, + WORKER_STATE_RUN, + WORKER_STATE_STOPPING, + WORKER_STATE_EXIT, + WORKER_STATE_EXITING, +} ReadWorkersState; + +typedef enum { + TRIGGER_NORMAL = 0, + TRIGGER_PRIMARY, + TRIGGER_STADNBY, + TRIGGER_FAILOVER, + TRIGGER_SWITCHOVER, + TRIGGER_SMARTSHUTDOWN, +} Enum_TriggeredState; + +typedef enum { + NONE, + APPLYING, + APPLIED, +} ReadBufState; + +typedef enum { + READ_MANAGER_STOP, + READ_MANAGER_RUN, +} XLogReadManagerState; + +typedef struct RecordBufferAarray { + XLogSegNo segno; + XLogRecPtr segoffset; + uint32 readlen; + char *readsegbuf; + uint32 bufState; +} RecordBufferAarray; + +#ifdef USE_ASSERT_CHECKING +#define LSN_CHECK_BUF_SIZE (128*1024*1024) +typedef struct { + uint64 curPosition; + XLogRecPtr curLsn; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + uint32 lsnCheckBuf[LSN_CHECK_BUF_SIZE]; +}LsnCheckCtl; + +#endif + +typedef struct RecordBufferState { + XLogReaderState *initreader; + uint32 readWorkerState; + uint32 readPageWorkerState; + uint32 readSource; + uint32 failSource; + uint32 xlogReadManagerState; + uint32 applyindex; + uint32 readindex; + RecordBufferAarray xlogsegarray[MAX_ALLOC_SEGNUM]; + char *readsegbuf; + char *readBuf; + char *errormsg_buf; + void *readprivate; + XLogRecPtr targetRecPtr; + XLogRecPtr expectLsn; +} RecordBufferState; + +typedef struct { + MemoryContext oldCtx; + PageRedoPipeline *pageLines; + uint32 pageLineNum; /* PageLineNum */ + uint32 *chosedPageLineIds; /* chosedPageLineIds */ + uint32 chosedPLCnt; /* chosedPageLineCount */ + TrxnRedoPipeline trxnLine; + ReadPipeline readLine; + RecordBufferState rtoXlogBufState; + PageRedoWorker **allWorkers; /* Array of page redo workers. */ + uint32 allWorkersCnt; + RedoItem *freeHead; /* Head of freed-item list. */ + RedoItem *freeStateHead; + RedoItem *allocatedRedoItem; + int exitCode; /* Thread exit code. */ + uint64 totalCostTime; + uint64 txnCostTime; /* txn cost time */ + uint64 pprCostTime; + uint32 maxItemNum; + uint32 curItemNum; + + uint32 syncEnterCount; + uint32 syncExitCount; + + pg_atomic_uint32 standbyState; /* sync standbyState from trxn worker to startup */ + + bool needImmediateCheckpoint; + bool needFullSyncCheckpoint; + volatile sig_atomic_t smartShutdown; +#ifdef USE_ASSERT_CHECKING + void *originLsnCheckAddr; + LsnCheckCtl *lsnCheckCtl; +#endif + RedoInterruptCallBackFunc oldStartupIntrruptFunc; +} LogDispatcher; + +typedef struct { + bool (*rm_dispatch)(XLogReaderState *record, List *expectedTLIs, TimestampTz recordXTime); + bool (*rm_loginfovalid)(XLogReaderState *record, uint8 minInfo, uint8 maxInfo); + RmgrId rm_id; + uint8 rm_mininfo; + uint8 rm_maxinfo; +} RmgrDispatchData; + +extern LogDispatcher *g_dispatcher; +extern RedoItem g_GlobalLsnForwarder; +extern RedoItem g_cleanupMark; +extern THR_LOCAL RecordBufferState *g_recordbuffer; + +const static uint64 OUTPUT_WAIT_COUNT = 0x7FFFFFF; +const static uint64 PRINT_ALL_WAIT_COUNT = 0x7FFFFFFFF; +extern RedoItem g_redoEndMark; +extern uint32 g_startupTriggerState; +extern uint32 g_readManagerTriggerFlag; + +inline int get_batch_redo_num() +{ + return g_instance.attr.attr_storage.batch_redo_num; +} + +inline int get_page_redo_worker_num_per_manager() +{ + return g_instance.attr.attr_storage.recovery_redo_workers_per_paser_worker; +} + +inline int get_trxn_redo_manager_num() +{ + return TRXN_REDO_MANAGER_NUM; +} + +inline int get_trxn_redo_worker_num() +{ + return TRXN_REDO_WORKER_NUM; +} + +void StartRecoveryWorkers(XLogReaderState *xlogreader, uint32 privateLen); + +/* RedoItem lifecycle. */ +void DispatchRedoRecordToFile(XLogReaderState *record, List *expectedTLIs, TimestampTz recordXTime); +void ProcessPendingRecords(bool fullSync = false); +void FreeRedoItem(RedoItem *item); + +/* Dispatcher phases. */ +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); + +/* Dispatcher states. */ +int GetDispatcherExitCode(); +bool DispatchPtrIsNull(); +uint32 GetBatchCount(); +uint32 GetAllWorkerCount(); +bool OnHotStandBy(); +PGPROC *StartupPidGetProc(ThreadId pid); +extern void SetStartupBufferPinWaitBufId(int bufid); +extern void GetStartupBufferPinWaitBufId(int *bufids, uint32 len); +void UpdateStandbyState(HotStandbyState newState); + +/* Redo end state saved by each page worker. */ +void **GetXLogInvalidPagesFromWorkers(); + +/* Other utility functions. */ +uint32 GetSlotId(const RelFileNode node, BlockNumber block, ForkNumber forkNum, uint32 workerCount); +bool XactWillRemoveRelFiles(XLogReaderState *record); +XLogReaderState *NewReaderState(XLogReaderState *readerState, bool bCopyState = false); +void FreeAllocatedRedoItem(); +void DiagLogRedoRecord(XLogReaderState *record, const char *funcName); +List *CheckImcompleteAction(List *imcompleteActionList); +void SetPageWorkStateByThreadId(uint32 threadState); +void UpdateDispatcherStandbyState(HotStandbyState *state); +void GetReplayedRecPtr(XLogRecPtr *startPtr, XLogRecPtr *endPtr); +void StartupSendFowarder(RedoItem *item); +XLogRecPtr GetSafeMinCheckPoint(); +RedoWaitInfo redo_get_io_event(int32 event_id); +void redo_get_wroker_statistic(uint32 *realNum, RedoWorkerStatsData *worker, uint32 workerLen); + +} // namespace extreme_rto + +extreme_rto::Enum_TriggeredState CheckForSatartupStatus(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/page_redo.h postgresql-hll-2.14/include/access/extreme_rto/page_redo.h --- postgresql-hll-2.14_old/include/access/extreme_rto/page_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/page_redo.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,224 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * page_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/page_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_PAGE_REDO_H +#define EXTREME_RTO_PAGE_REDO_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/extreme_rto/redo_item.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/extreme_rto/posix_semaphore.h" +#include "access/extreme_rto/spsc_blocking_queue.h" +#include "access/xlogproc.h" + +namespace extreme_rto { + +static const uint32 PAGE_WORK_QUEUE_SIZE = 4096; + +static const uint32 EXTREME_RTO_ALIGN_LEN = 16; /* need 128-bit aligned */ + + +typedef enum { + REDO_BATCH, + REDO_PAGE_MNG, + REDO_PAGE_WORKER, + REDO_TRXN_MNG, + REDO_TRXN_WORKER, + REDO_READ_WORKER, + REDO_READ_PAGE_WORKER, + REDO_READ_MNG, + REDO_ROLE_NUM, +} RedoRole; + +struct PageRedoWorker { + /* + * The last successfully applied log record's end position + 1 as an + * atomic uint64. The type of a log record's position is XLogRecPtr. + * Here the position is stored as an uint64 so it can be read and + * written atomically. + */ + XLogRecPtr lastReplayedReadRecPtr; + XLogRecPtr lastReplayedEndRecPtr; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + PageRedoWorker *selfOrinAddr; + /* Worker id. */ + uint32 id; + int index; + /* Thread id */ + gs_thread_t tid; + /* The proc struct of this worker thread. */ + PGPROC *proc; + RedoRole role; + uint32 slotId; + /* --------------------------------------------- + * Initial context + * + * Global variable values at worker creation time. + */ + + /* Initial server mode from the dispatcher. */ + ServerMode initialServerMode; + /* Initial timeline ID from the dispatcher. */ + TimeLineID initialTimeLineID; + List *expectedTLIs; + /* --------------------------------------------- + * Redo item queue. + * + * Redo items are provided by the dispatcher and consumed by each + * worker. See AddPageRedoItem() for the use of the additional + * pending list. + */ + + /* The head of the pending item list. */ + RedoItem *pendingHead; + /* The tail of the pending item list. */ + RedoItem *pendingTail; + /* To-be-replayed log-record-list queue. */ + SPSCBlockingQueue *queue; + + /* + * The last recovery restart point seen by the txn worker. Restart + * points before this is useless and can be removed. + */ + XLogRecPtr lastCheckedRestartPoint; + /* min recovery point */ + XLogRecPtr minRecoveryPoint; + /* --------------------------------------------- + * Per-worker run-time context + * + * States maintained by each individual page-redo worker during + * log replay. These are read by the txn-redo worker. + */ + + /* --------------------------------------------- + * Global run-time context + * + * States maintained outside page-redo worker during log replay. + * Updates to these states must be synchronized to all page-redo workers. + */ + + /* + * Global standbyState set by the txn worker. + */ + HotStandbyState standbyState; + TransactionId latestObservedXid; + bool StandbyMode; + char *DataDir; + + TransactionId RecentXmin; + /* --------------------------------------------- + * Redo end context + * + * Thread-local variable values saved after log replay has completed. + * These values are collected by each redo worker at redo end and + * are used by the dispatcher. + */ + /* XLog invalid pages. */ + void *xlogInvalidPages; + + /* --------------------------------------------- + * Phase barrier. + * + * A barrier for synchronizing the dispatcher and page redo worker + * between different phases. + */ + + /* Semaphore marking the completion of the current phase. */ + PosixSemaphore phaseMarker; + MemoryContext oldCtx; + + HTAB *redoItemHash; + TimeLineID recoveryTargetTLI; + bool ArchiveRecoveryRequested; + bool StandbyModeRequested; + bool InArchiveRecovery; + bool ArchiveRestoreRequested; + bool InRecovery; + + uint32 fullSyncFlag; + RedoParseManager parseManager; + RedoBufferManager bufferManager; +}; + +extern THR_LOCAL PageRedoWorker *g_redoWorker; + +/* Worker lifecycle. */ +PageRedoWorker *StartPageRedoWorker(PageRedoWorker *worker); +void DestroyPageRedoWorker(PageRedoWorker *worker); + +/* Thread creation utility functions. */ +bool IsPageRedoWorkerProcess(int argc, char *argv[]); +void AdaptArgvForPageRedoWorker(char *argv[]); +void GetThreadNameIfPageRedoWorker(int argc, char *argv[], char **threadNamePtr); + +uint32 GetMyPageRedoWorkerIdWithLock(); +PGPROC *GetPageRedoWorkerProc(PageRedoWorker *worker); + +/* Worker main function. */ +void ParallelRedoThreadRegister(); +void ParallelRedoThreadMain(); + +/* Dispatcher phases. */ +bool SendPageRedoEndMark(PageRedoWorker *worker); +void WaitPageRedoWorkerReachLastMark(PageRedoWorker *worker); + +/* Redo processing. */ +void AddPageRedoItem(PageRedoWorker *worker, void *item); + +/* Run-time worker states. */ +uint64 GetCompletedRecPtr(PageRedoWorker *worker); +void SetWorkerRestartPoint(PageRedoWorker *worker, XLogRecPtr restartPoint); + +void UpdatePageRedoWorkerStandbyState(PageRedoWorker *worker, HotStandbyState newState); + +/* Redo end states. */ +void ClearBTreeIncompleteActions(PageRedoWorker *worker); +void *GetXLogInvalidPages(PageRedoWorker *worker); +bool RedoWorkerIsIdle(PageRedoWorker *worker); +void PageRedoSetAffinity(uint32 id); + +void DumpPageRedoWorker(PageRedoWorker *worker); +PageRedoWorker *CreateWorker(uint32 id); +extern void UpdateRecordGlobals(RedoItem *item, HotStandbyState standbyState); +void ReferenceRedoItem(void *item); +void DereferenceRedoItem(void *item); +void PushToWorkerLsn(bool force); +void GetCompletedReadEndPtr(PageRedoWorker *worker, XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void SetReadBufferForExtRto(XLogReaderState *state, XLogRecPtr pageptr, int reqLen); +void DumpExtremeRtoReadBuf(); +void PutRecordToReadQueue(XLogReaderState *recordreader); +bool LsnUpdate(); +void ResetRtoXlogReadBuf(XLogRecPtr targetPagePtr); +bool XLogPageReadForExtRto(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen); + +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/posix_semaphore.h postgresql-hll-2.14/include/access/extreme_rto/posix_semaphore.h --- postgresql-hll-2.14_old/include/access/extreme_rto/posix_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/posix_semaphore.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * posix_semaphore.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/posix_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_POSIX_SEMAPHORE_H +#define EXTREME_RTO_POSIX_SEMAPHORE_H + +#include +namespace extreme_rto { + +typedef struct { + sem_t semaphore; + bool initialized; +} PosixSemaphore; + +void PosixSemaphoreInit(PosixSemaphore *sem, unsigned int initValue); +void PosixSemaphoreDestroy(PosixSemaphore *sem); +void PosixSemaphoreWait(PosixSemaphore *sem); +void PosixSemaphorePost(PosixSemaphore *sem); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/redo_item.h postgresql-hll-2.14/include/access/extreme_rto/redo_item.h --- postgresql-hll-2.14_old/include/access/extreme_rto/redo_item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/redo_item.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_item.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/redo_item.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_REDO_ITEM_H +#define EXTREME_RTO_REDO_ITEM_H + +#include "access/xlogreader.h" +#include "datatype/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/atomic.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "access/extreme_rto/posix_semaphore.h" +#include "replication/replicainternal.h" + +namespace extreme_rto { + +typedef struct RedoItem_s { + /* Old version. */ + bool oldVersion; + bool needImmediateCheckpoint; + bool needFullSyncCheckpoint; + /* Number of workers sharing this item. */ + uint32 shareCount; + /* Id of the worker designated to apply this item. */ + uint32 designatedWorker; + /* The expected timelines for this record. */ + List *expectedTLIs; + /* The timestamp of the log record if it is a transaction record. */ + TimestampTz recordXTime; + /* Next item on the free list. */ + struct RedoItem_s *freeNext; + /* Number of workers holding a reference to this item. */ + pg_atomic_uint32 refCount; + /* If this item has been replayed. */ + pg_atomic_uint32 replayed; + /* A "deep" copy of the log record. */ + XLogReaderState record; + /* Used for really free */ + struct RedoItem_s *allocatedNext; + TimestampTz syncXLogReceiptTime; + int syncXLogReceiptSource; + TransactionId RecentXmin; + ServerMode syncServerMode; + + /* temp variable indicate number of redo items with same block number */ + pg_atomic_uint32 blkShareCount; + + bool isForceAll; + pg_atomic_uint32 distributeCount; +} RedoItem; + +static const int32 ANY_BLOCK_ID = -1; +static const uint32 ANY_WORKER = (uint32)-1; +static const uint32 TRXN_WORKER = (uint32)-2; +static const uint32 ALL_WORKER = (uint32)-3; + +static inline RedoItem *GetRedoItemPtr(XLogReaderState *record) +{ + return (RedoItem *)(((char *)record) - offsetof(RedoItem, record)); +} + +RedoItem *CreateRedoItem(XLogReaderState *record, uint32 shareCount, uint32 designatedWorker, List *expectedTLIs, + TimestampTz recordXTime, bool buseoriginal, bool isForceAll = false); + +void ApplyRedoRecord(XLogReaderState *record, bool bOld); +} // namespace extreme_rto + +#endif diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/spsc_blocking_queue.h postgresql-hll-2.14/include/access/extreme_rto/spsc_blocking_queue.h --- postgresql-hll-2.14_old/include/access/extreme_rto/spsc_blocking_queue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/spsc_blocking_queue.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * spsc_blocking_queue.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/spsc_blocking_queue.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_SPSC_BLOCKING_QUEUE_H +#define EXTREME_RTO_SPSC_BLOCKING_QUEUE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/parallel_recovery/posix_semaphore.h" + + +namespace extreme_rto { +typedef void (*CallBackFunc)(); + +struct SPSCBlockingQueue { + pg_atomic_uint32 writeHead; /* Array index for the next write. */ + pg_atomic_uint32 readTail; /* Array index for the next read. */ + uint32 capacity; /* Queue capacity, must be power of 2. */ + uint32 mask; /* Bit mask for computing index. */ + pg_atomic_uint32 maxUsage; + pg_atomic_uint64 totalCnt; + CallBackFunc callBackFunc; + void *buffer[1]; /* Queue buffer, the actual size is capacity. */ +}; + +SPSCBlockingQueue *SPSCBlockingQueueCreate(uint32 capacity, CallBackFunc func = NULL); +void SPSCBlockingQueueDestroy(SPSCBlockingQueue *queue); + +bool SPSCBlockingQueuePut(SPSCBlockingQueue *queue, void *element); +void *SPSCBlockingQueueTake(SPSCBlockingQueue *queue); +bool SPSCBlockingQueueIsEmpty(SPSCBlockingQueue *queue); +void *SPSCBlockingQueueTop(SPSCBlockingQueue *queue); +void SPSCBlockingQueuePop(SPSCBlockingQueue *queue); +void DumpQueue(const SPSCBlockingQueue *queue); +uint32 SPSCGetQueueCount(SPSCBlockingQueue *queue); +bool SPSCBlockingQueueGetAll(SPSCBlockingQueue *queue, void ***eleArry, uint32 *eleNum); +void SPSCBlockingQueuePopN(SPSCBlockingQueue *queue, uint32 n); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/access/extreme_rto/txn_redo.h postgresql-hll-2.14/include/access/extreme_rto/txn_redo.h --- postgresql-hll-2.14_old/include/access/extreme_rto/txn_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/extreme_rto/txn_redo.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * txn_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/txn_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_TXN_REDO_H +#define EXTREME_RTO_TXN_REDO_H + +#include "access/parallel_recovery/redo_item.h" + +namespace extreme_rto { +void AddTxnRedoItem(PageRedoWorker *worker, void *item); +void TrxnMngProc(RedoItem *item, PageRedoWorker *wk); +void TrxnWorkerProc(RedoItem *item); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/access/genam.h postgresql-hll-2.14/include/access/genam.h --- postgresql-hll-2.14_old/include/access/genam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/genam.h 2020-12-12 17:06:43.060345625 +0800 @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------------- + * + * genam.h + * POSTGRES generalized index access method definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/genam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GENAM_H +#define GENAM_H + +#include "access/sdir.h" +#include "access/skey.h" +#include "nodes/tidbitmap.h" +#include "storage/lock.h" +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "vecexecutor/vectorbatch.h" + +// EB: +// removed execnodes.h + +/* + * Struct for statistics returned by ambuild + */ +typedef struct IndexBuildResult { + double heap_tuples; /* # of tuples seen in parent table */ + double index_tuples; /* # of tuples inserted into index */ + double* all_part_tuples; +} IndexBuildResult; + +/* + * Struct for input arguments passed to ambulkdelete and amvacuumcleanup + * + * num_heap_tuples is accurate only when estimated_count is false; + * otherwise it's just an estimate (currently, the estimate is the + * prior value of the relation's pg_class.reltuples field). It will + * always just be an estimate during ambulkdelete. + */ +typedef struct IndexVacuumInfo { + Relation index; /* the index being vacuumed */ + bool analyze_only; /* ANALYZE (without any actual vacuum) */ + bool estimated_count; /* num_heap_tuples is an estimate */ + int message_level; /* ereport level for progress messages */ + double num_heap_tuples; /* tuples remaining in heap */ + BufferAccessStrategy strategy; /* access strategy for reads */ +} IndexVacuumInfo; + +/* + * Struct for statistics returned by ambulkdelete and amvacuumcleanup + * + * This struct is normally allocated by the first ambulkdelete call and then + * passed along through subsequent ones until amvacuumcleanup; however, + * amvacuumcleanup must be prepared to allocate it in the case where no + * ambulkdelete calls were made (because no tuples needed deletion). + * Note that an index AM could choose to return a larger struct + * of which this is just the first field; this provides a way for ambulkdelete + * to communicate additional private data to amvacuumcleanup. + * + * Note: pages_removed is the amount by which the index physically shrank, + * if any (ie the change in its total size on disk). pages_deleted and + * pages_free refer to free space within the index file. Some index AMs + * may compute num_index_tuples by reference to num_heap_tuples, in which + * case they should copy the estimated_count field from IndexVacuumInfo. + */ +typedef struct IndexBulkDeleteResult { + BlockNumber num_pages; /* pages remaining in index */ + BlockNumber pages_removed; /* # removed during vacuum operation */ + bool estimated_count; /* num_index_tuples is an estimate */ + double num_index_tuples; /* tuples remaining */ + double tuples_removed; /* # removed during vacuum operation */ + BlockNumber pages_deleted; /* # unused pages in index */ + BlockNumber pages_free; /* # pages available for reuse */ +} IndexBulkDeleteResult; + +/* Typedef for callback function to determine if a tuple is bulk-deletable */ +typedef bool (*IndexBulkDeleteCallback)(ItemPointer itemptr, void* state, Oid partOid); + +/* struct definitions appear in relscan.h */ +typedef struct IndexScanDescData* IndexScanDesc; +typedef struct SysScanDescData* SysScanDesc; +struct ScanState; + +/* + * Enumeration specifying the type of uniqueness check to perform in + * index_insert(). + * + * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly + * blocking to see if a conflicting transaction commits. + * + * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at + * insertion time. The index AM should test if the tuple is unique, but + * should not throw error, block, or prevent the insertion if the tuple + * appears not to be unique. We'll recheck later when it is time for the + * constraint to be enforced. The AM must return true if the tuple is + * known unique, false if it is possibly non-unique. In the "true" case + * it is safe to omit the later recheck. + * + * When it is time to recheck the deferred constraint, a pseudo-insertion + * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the + * index in this case, so it should not be inserted again. Rather, just + * check for conflicting live tuples (possibly blocking). + */ +typedef enum IndexUniqueCheck { + UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */ + UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */ + UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */ + UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */ +} IndexUniqueCheck; + +/* + * generalized index_ interface routines (in indexam.c) + */ + +/* + * IndexScanIsValid + * True iff the index scan is valid. + */ +#define IndexScanIsValid(scan) PointerIsValid(scan) + +extern Relation index_open(Oid relationId, LOCKMODE lockmode, int2 bucketId=-1); +extern void index_close(Relation relation, LOCKMODE lockmode); + +extern bool index_insert(Relation indexRelation, Datum* values, const bool* isnull, ItemPointer heap_t_ctid, + Relation heapRelation, IndexUniqueCheck checkUnique); + +extern IndexScanDesc index_beginscan( + Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys, ScanState* scan_state=NULL); +extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, int nkeys, ScanState* scan_state=NULL); +extern void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys); +extern void index_endscan(IndexScanDesc scan); +extern void index_markpos(IndexScanDesc scan); +extern void index_restrpos(IndexScanDesc scan); +extern ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction); +extern HeapTuple index_fetch_heap(IndexScanDesc scan); +extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction); +extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap* bitmap); +extern int64 index_column_getbitmap(IndexScanDesc scandesc, const void* sort, VectorBatch* tids); + +extern IndexBulkDeleteResult* index_bulk_delete( + IndexVacuumInfo* info, IndexBulkDeleteResult* stats, IndexBulkDeleteCallback callback, const void* callback_state); +extern IndexBulkDeleteResult* index_vacuum_cleanup(IndexVacuumInfo* info, IndexBulkDeleteResult* stats); +extern bool index_can_return(Relation indexRelation); +extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum); +extern FmgrInfo* index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum); + +/* + * index access method support routines (in genam.c) + */ +extern IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys); +extern void IndexScanEnd(IndexScanDesc scan); +extern char* BuildIndexValueDescription(Relation indexRelation, Datum* values, const bool* isnull); + +/* + * heap-or-index access to system catalogs (in genam.c) + */ +extern SysScanDesc systable_beginscan( + Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapTuple systable_getnext(SysScanDesc sysscan); +extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup); +extern void systable_endscan(SysScanDesc sysscan); +extern SysScanDesc systable_beginscan_ordered( + Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction); +extern void systable_endscan_ordered(SysScanDesc sysscan); + +HeapTuple systable_getnext_back(SysScanDesc sysscan); + +/* + * global partition index access method support routines (in genam.c) + */ +typedef struct GPIScanDescData { + HTAB* fakeRelationTable; /* fake partition relation and partition hash table */ + Bitmapset* invisiblePartMap; /* cache invisible partition oid in GPI */ + Relation parentRelation; /* parent relation of partition */ + Relation fakePartRelation; /* fake-relation using partition */ + Partition partition; /* partition use to fake partition rel */ + Oid currPartOid; /* current partition oid in GPI */ +} GPIScanDescData; + +typedef GPIScanDescData* GPIScanDesc; + +/* Check input partition oid is same as global-partition-index current work partition oid */ +inline bool GPIScanCheckPartOid(GPIScanDesc gpiScan, Oid currScanPartOid) +{ + if (!PointerIsValid(gpiScan)) { + return false; + } + + return gpiScan->currPartOid != currScanPartOid; +} +extern void GPIScanInit(GPIScanDesc* gpiScan); +extern void GPIScanEnd(GPIScanDesc gpiScan); +extern bool GPIGetNextPartRelation(GPIScanDesc gpiScan, MemoryContext cxt, LOCKMODE lmode); +extern void GPISetCurrPartOid(GPIScanDesc gpiScan, Oid partOid); +extern Oid GPIGetCurrPartOid(const GPIScanDesc gpiScan); + +#endif /* GENAM_H */ diff -uprN postgresql-hll-2.14_old/include/access/gin.h postgresql-hll-2.14/include/access/gin.h --- postgresql-hll-2.14_old/include/access/gin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gin.h 2020-12-12 17:06:43.061345638 +0800 @@ -0,0 +1,78 @@ +/* -------------------------------------------------------------------------- + * gin.h + * Public header file for Generalized Inverted Index access method. + * + * Copyright (c) 2006-2014, PostgreSQL Global Development Group + * + * src/include/access/gin.h + * -------------------------------------------------------------------------- + */ +#ifndef GIN_H +#define GIN_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/block.h" +#include "utils/relcache.h" + +/* + * amproc indexes for inverted indexes. + */ +#define GIN_COMPARE_PROC 1 +#define GIN_EXTRACTVALUE_PROC 2 +#define GIN_EXTRACTQUERY_PROC 3 +#define GIN_CONSISTENT_PROC 4 +#define GIN_COMPARE_PARTIAL_PROC 5 +#define GIN_TRICONSISTENT_PROC 6 +#define GINNProcs 6 + +/* + * searchMode settings for extractQueryFn. + */ +#define GIN_SEARCH_MODE_DEFAULT 0 +#define GIN_SEARCH_MODE_INCLUDE_EMPTY 1 +#define GIN_SEARCH_MODE_ALL 2 +#define GIN_SEARCH_MODE_EVERYTHING 3 /* for internal use only */ + +/* + * GinStatsData represents stats data for planner use + */ +typedef struct GinStatsData { + BlockNumber nPendingPages; + BlockNumber nTotalPages; + BlockNumber nEntryPages; + BlockNumber nDataPages; + int64 nEntries; + int32 ginVersion; +} GinStatsData; + +/* + * A ternary value used by tri-consistent functions. + * + * For convenience, this is compatible with booleans. A boolean can be + * safely cast to a GinTernaryValue. + */ +typedef char GinTernaryValue; + +#define GIN_FALSE 0 /* item is not present / does not match */ +#define GIN_TRUE 1 /* item is present / matches */ +#define GIN_MAYBE \ + 2 /* don't know if item is present / don't know \ + * if matches */ + +#define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X)) +#define GinTernaryValueGetDatum(X) ((Datum)(X)) +#define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x) + +/* ginutil.c */ +extern void ginGetStats(Relation index, GinStatsData *stats); +extern void ginUpdateStats(Relation index, const GinStatsData *stats); + +/* ginxlog.c */ +extern void gin_redo(XLogReaderState *record); +extern void gin_desc(StringInfo buf, XLogReaderState *record); +extern void gin_xlog_startup(void); +extern void gin_xlog_cleanup(void); +extern bool IsGinVacuumPages(XLogReaderState *record); + +#endif /* GIN_H */ diff -uprN postgresql-hll-2.14_old/include/access/gin_private.h postgresql-hll-2.14/include/access/gin_private.h --- postgresql-hll-2.14_old/include/access/gin_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gin_private.h 2020-12-12 17:06:43.061345638 +0800 @@ -0,0 +1,927 @@ +/* -------------------------------------------------------------------------- + * gin_private.h + * header file for postgres inverted index access method implementation. + * + * Copyright (c) 2006-2014, PostgreSQL Global Development Group + * + * src/include/access/gin_private.h + * -------------------------------------------------------------------------- + */ +#ifndef GIN_PRIVATE_H +#define GIN_PRIVATE_H + +#include "access/genam.h" +#include "access/gin.h" +#include "access/itup.h" +#include "fmgr.h" +#include "storage/bufmgr.h" +#include "utils/rbtree.h" + +/* + * Page opaque data in an inverted index page. + * + * Note: GIN does not include a page ID word as do the other index types. + * This is OK because the opaque data is only 8 bytes and so can be reliably + * distinguished by size. Revisit this if the size ever increases. + * Further note: as of 9.2, SP-GiST also uses 8-byte special space. This is + * still OK, as long as GIN isn't using all of the high-order bits in its + * flags word, because that way the flags word cannot match the page ID used + * by SP-GiST. + */ +typedef struct GinPageOpaqueData { + BlockNumber rightlink; /* next page if any */ + OffsetNumber maxoff; /* number of PostingItems on GIN_DATA & + * ~GIN_LEAF page. On GIN_LIST page, number of + * heap tuples. */ + uint16 flags; /* see bit definitions below */ +} GinPageOpaqueData; + +typedef GinPageOpaqueData *GinPageOpaque; + +#define GIN_DATA (1 << 0) +#define GIN_LEAF (1 << 1) +#define GIN_DELETED (1 << 2) +#define GIN_META (1 << 3) +#define GIN_LIST (1 << 4) +#define GIN_LIST_FULLROW (1 << 5) /* makes sense only on GIN_LIST page */ +#define GIN_INCOMPLETE_SPLIT \ + (1 << 6) /* page was split, but parent not \ + * updated */ +#define GIN_COMPRESSED (1 << 7) + +/* Page numbers of fixed-location pages */ +#define GIN_METAPAGE_BLKNO (0) +#define GIN_ROOT_BLKNO (1) + +typedef struct GinMetaPageData { + /* + * Pointers to head and tail of pending list, which consists of GIN_LIST + * pages. These store fast-inserted entries that haven't yet been moved + * into the regular GIN structure. + */ + BlockNumber head; + BlockNumber tail; + + /* + * Free space in bytes in the pending list's tail page. + */ + uint32 tailFreeSize; + + /* + * We store both number of pages and number of heap tuples that are in the + * pending list. + */ + BlockNumber nPendingPages; + int64 nPendingHeapTuples; + + /* + * Statistics for planner use (accurate as of last VACUUM) + */ + BlockNumber nTotalPages; + BlockNumber nEntryPages; + BlockNumber nDataPages; + int64 nEntries; + + /* + * GIN version number (ideally this should have been at the front, but too + * late now. Don't move it!) + * + * Currently 2 (for indexes initialized in 9.4 or later) + * + * Version 1 (indexes initialized in version 9.1, 9.2 or 9.3), is + * compatible, but may contain uncompressed posting tree (leaf) pages and + * posting lists. They will be converted to compressed format when + * modified. + * + * Version 0 (indexes initialized in 9.0 or before) is compatible but may + * be missing null entries, including both null keys and placeholders. + * Reject full-index-scan attempts on such indexes. + */ + int32 ginVersion; +} GinMetaPageData; + +#define GIN_CURRENT_VERSION 2 + +#define GinPageGetMeta(p) ((GinMetaPageData *)PageGetContents(p)) + +/* + * Macros for accessing a GIN index page's opaque data + */ +#define GinPageGetOpaque(page) ((GinPageOpaque)PageGetSpecialPointer(page)) + +#define GinPageIsLeaf(page) (GinPageGetOpaque(page)->flags & GIN_LEAF) +#define GinPageSetLeaf(page) (GinPageGetOpaque(page)->flags |= GIN_LEAF) +#define GinPageSetNonLeaf(page) (GinPageGetOpaque(page)->flags &= ~GIN_LEAF) +#define GinPageIsData(page) (GinPageGetOpaque(page)->flags & GIN_DATA) +#define GinPageSetData(page) (GinPageGetOpaque(page)->flags |= GIN_DATA) +#define GinPageIsList(page) (GinPageGetOpaque(page)->flags & GIN_LIST) +#define GinPageSetList(page) (GinPageGetOpaque(page)->flags |= GIN_LIST) +#define GinPageHasFullRow(page) (GinPageGetOpaque(page)->flags & GIN_LIST_FULLROW) +#define GinPageSetFullRow(page) (GinPageGetOpaque(page)->flags |= GIN_LIST_FULLROW) +#define GinPageIsCompressed(page) (GinPageGetOpaque(page)->flags & GIN_COMPRESSED) +#define GinPageSetCompressed(page) (GinPageGetOpaque(page)->flags |= GIN_COMPRESSED) + +#define GinPageIsDeleted(page) (GinPageGetOpaque(page)->flags & GIN_DELETED) +#define GinPageSetDeleted(page) (GinPageGetOpaque(page)->flags |= GIN_DELETED) +#define GinPageSetNonDeleted(page) (GinPageGetOpaque(page)->flags &= ~GIN_DELETED) +#define GinPageIsIncompleteSplit(page) (GinPageGetOpaque(page)->flags & GIN_INCOMPLETE_SPLIT) + +#define GinPageRightMost(page) (GinPageGetOpaque(page)->rightlink == InvalidBlockNumber) + +/* + * We use our own ItemPointerGet(BlockNumber|OffsetNumber) + * to avoid Asserts, since sometimes the ip_posid isn't "valid" + */ +#define GinItemPointerGetBlockNumber(pointer) BlockIdGetBlockNumber(&(pointer)->ip_blkid) + +#define GinItemPointerGetOffsetNumber(pointer) ((pointer)->ip_posid) + +/* + * Special-case item pointer values needed by the GIN search logic. + * MIN: sorts less than any valid item pointer + * MAX: sorts greater than any valid item pointer + * LOSSY PAGE: indicates a whole heap page, sorts after normal item + * pointers for that page + * Note that these are all distinguishable from an "invalid" item pointer + * (which is InvalidBlockNumber/0) as well as from all normal item + * pointers (which have item numbers in the range 1..MaxHeapTuplesPerPage). + */ +#define ItemPointerSetMin(p) ItemPointerZero(p) +#define ItemPointerIsMin(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0 && GinItemPointerGetBlockNumber(p) == (BlockNumber)0) +#define ItemPointerSetMax(p) ItemPointerSet((p), InvalidBlockNumber, (OffsetNumber)0xffff) +#define ItemPointerIsMax(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && GinItemPointerGetBlockNumber(p) == InvalidBlockNumber) +#define ItemPointerSetLossyPage(p, b) ItemPointerSet((p), (b), (OffsetNumber)0xffff) +#define ItemPointerIsLossyPage(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && GinItemPointerGetBlockNumber(p) != InvalidBlockNumber) + +/* + * Posting item in a non-leaf posting-tree page + */ +typedef struct { + /* We use BlockIdData not BlockNumber to avoid padding space wastage */ + BlockIdData child_blkno; + ItemPointerData key; +} PostingItem; + +#define PostingItemGetBlockNumber(pointer) BlockIdGetBlockNumber(&(pointer)->child_blkno) + +#define PostingItemSetBlockNumber(pointer, blockNumber) BlockIdSet(&((pointer)->child_blkno), (blockNumber)) + +/* + * Category codes to distinguish placeholder nulls from ordinary NULL keys. + * Note that the datatype size and the first two code values are chosen to be + * compatible with the usual usage of bool isNull flags. + * + * GIN_CAT_EMPTY_QUERY is never stored in the index; and notice that it is + * chosen to sort before not after regular key values. + */ +typedef signed char GinNullCategory; + +#define GIN_CAT_NORM_KEY 0 /* normal, non-null key value */ +#define GIN_CAT_NULL_KEY 1 /* null key value */ +#define GIN_CAT_EMPTY_ITEM 2 /* placeholder for zero-key item */ +#define GIN_CAT_NULL_ITEM 3 /* placeholder for null item */ +#define GIN_CAT_EMPTY_QUERY (-1) /* placeholder for full-scan query */ + +/* + * Access macros for null category byte in entry tuples + */ +#define GinCategoryOffset(itup, ginstate) \ + (IndexInfoFindDataOffset((itup)->t_info) + ((ginstate)->oneCol ? 0 : sizeof(int16))) +#define GinGetNullCategory(itup, ginstate) (*((GinNullCategory *)((char *)(itup) + GinCategoryOffset(itup, ginstate)))) +#define GinSetNullCategory(itup, ginstate, c) \ + (*((GinNullCategory *)((char *)(itup) + GinCategoryOffset(itup, ginstate))) = (c)) + +/* + * Access macros for leaf-page entry tuples (see discussion in README) + */ +#define GinGetNPosting(itup) GinItemPointerGetOffsetNumber(&(itup)->t_tid) +#define GinSetNPosting(itup, n) ItemPointerSetOffsetNumber(&(itup)->t_tid, n) +#define GIN_TREE_POSTING ((OffsetNumber)0xffff) +#define GinIsPostingTree(itup) (GinGetNPosting(itup) == GIN_TREE_POSTING) +#define GinSetPostingTree(itup, blkno) do { \ + GinSetNPosting((itup), GIN_TREE_POSTING); \ + ItemPointerSetBlockNumber(&(itup)->t_tid, blkno); \ +} while (0) + +#define GinGetPostingTree(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid) + +#define GIN_ITUP_COMPRESSED ((uint32)1 << 31) +#define GinGetPostingOffset(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & (~GIN_ITUP_COMPRESSED)) +#define GinSetPostingOffset(itup, n) ItemPointerSetBlockNumber(&(itup)->t_tid, (n) | GIN_ITUP_COMPRESSED) +#define GinGetPosting(itup) ((Pointer)((char *)(itup) + GinGetPostingOffset(itup))) +#define GinItupIsCompressed(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED) + +/* + * Maximum size of an item on entry tree page. Make sure that we fit at least + * three items on each page. (On regular B-tree indexes, we must fit at least + * three items: two data items and the "high key". In GIN entry tree, we don't + * currently store the high key explicitly, we just use the rightmost item on + * the page, so it would actually be enough to fit two items.) + */ +#define GinMaxItemSize \ + Min(INDEX_SIZE_MASK, MAXALIGN_DOWN(((BLCKSZ - MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \ + MAXALIGN(sizeof(GinPageOpaqueData))) / \ + 3))) + +/* + * Access macros for non-leaf entry tuples + */ +#define GinGetDownlink(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid) +#define GinSetDownlink(itup, blkno) ItemPointerSet(&(itup)->t_tid, blkno, InvalidOffsetNumber) + +/* + * Data (posting tree) pages + * + * Posting tree pages don't store regular tuples. Non-leaf pages contain + * PostingItems, which are pairs of ItemPointers and child block numbers. + * Leaf pages contain GinPostingLists and an uncompressed array of item + * pointers. + * + * In a leaf page, the compressed posting lists are stored after the regular + * page header, one after each other. Although we don't store regular tuples, + * pd_lower is used to indicate the end of the posting lists. After that, free + * space follows. This layout is compatible with the "standard" heap and + * index page layout described in bufpage.h, so that we can e.g set buffer_std + * when writing WAL records. + * + * In the special space is the GinPageOpaque struct. + */ +#define GinDataLeafPageGetPostingList(page) \ + (GinPostingList *)((PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData)))) +#define GinDataLeafPageGetPostingListSize(page) \ + (((PageHeader)page)->pd_lower - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(ItemPointerData))) + +#define GinDataLeafPageIsEmpty(page) \ + (GinPageIsCompressed(page) ? (GinDataLeafPageGetPostingListSize(page) == 0) \ + : (GinPageGetOpaque(page)->maxoff < FirstOffsetNumber)) + +#define GinDataLeafPageGetFreeSpace(page) PageGetExactFreeSpace(page) + +#define GinDataPageGetRightBound(page) ((ItemPointer)PageGetContents(page)) +/* + * Pointer to the data portion of a posting tree page. For internal pages, + * that's the beginning of the array of PostingItems. For compressed leaf + * pages, the first compressed posting list. For uncompressed (pre-9.4) leaf + * pages, it's the beginning of the ItemPointer array. + */ +#define GinDataPageGetData(page) (PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData))) +/* non-leaf pages contain PostingItems */ +#define GinDataPageGetPostingItem(page, i) ((PostingItem *)(GinDataPageGetData(page) + ((i)-1) * sizeof(PostingItem))) + +/* + * Note: there is no GinDataPageGetDataSize macro, because before version + * 9.4, we didn't set pd_lower on data pages. There can be pages in the index + * that were binary-upgraded from earlier versions and still have an invalid + * pd_lower, so we cannot trust it in general. Compressed posting tree leaf + * pages are new in 9.4, however, so we can trust them; see + * GinDataLeafPageGetPostingListSize. + */ +#define GinDataPageSetDataSize(page, size) do { \ + Assert((uintptr_t)size <= GinDataPageMaxDataSize); \ + ((PageHeader)page)->pd_lower = (size) + MAXALIGN(SizeOfPageHeaderData) + MAXALIGN(sizeof(ItemPointerData)); \ +} while (0) + +#define GinNonLeafDataPageGetFreeSpace(page) \ + (GinDataPageMaxDataSize - GinPageGetOpaque(page)->maxoff * sizeof(PostingItem)) + +#define GinDataPageMaxDataSize \ + (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(ItemPointerData)) - MAXALIGN(sizeof(GinPageOpaqueData))) + +/* + * List pages + */ +#define GinListPageSize (BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GinPageOpaqueData))) + +/* + * Storage type for GIN's reloptions + */ +typedef struct GinOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + bool useFastUpdate; /* use fast updates? */ + int pendingListCleanupSize; /* maximum size of pending list */ +} GinOptions; + +#define GIN_DEFAULT_USE_FASTUPDATE true +#define GinGetUseFastUpdate(relation) \ + ((relation)->rd_options ? ((GinOptions *)(relation)->rd_options)->useFastUpdate : GIN_DEFAULT_USE_FASTUPDATE) +#define GinGetPendingListCleanupSize(relation) \ + ((relation)->rd_options && ((GinOptions *)(relation)->rd_options)->pendingListCleanupSize != -1 \ + ? ((GinOptions *)(relation)->rd_options)->pendingListCleanupSize \ + : u_sess->attr.attr_storage.gin_pending_list_limit) + +/* Macros for buffer lock/unlock operations */ +#define GIN_UNLOCK BUFFER_LOCK_UNLOCK +#define GIN_SHARE BUFFER_LOCK_SHARE +#define GIN_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE + +/* + * GinState: working data structure describing the index being worked on + */ +typedef struct GinState { + Relation index; + bool oneCol; /* true if single-column index */ + + /* + * origTupDesc is the nominal tuple descriptor of the index, ie, the i'th + * attribute shows the key type (not the input data type!) of the i'th + * index column. In a single-column index this describes the actual leaf + * index tuples. In a multi-column index, the actual leaf tuples contain + * a smallint column number followed by a key datum of the appropriate + * type for that column. We set up tupdesc[i] to describe the actual + * rowtype of the index tuples for the i'th column, ie, (int2, keytype). + * Note that in any case, leaf tuples contain more data than is known to + * the TupleDesc; see access/gin/README for details. + */ + TupleDesc origTupdesc; + TupleDesc tupdesc[INDEX_MAX_KEYS]; + + /* + * Per-index-column opclass support functions + */ + FmgrInfo compareFn[INDEX_MAX_KEYS]; + FmgrInfo extractValueFn[INDEX_MAX_KEYS]; + FmgrInfo extractQueryFn[INDEX_MAX_KEYS]; + FmgrInfo consistentFn[INDEX_MAX_KEYS]; + FmgrInfo triConsistentFn[INDEX_MAX_KEYS]; + FmgrInfo comparePartialFn[INDEX_MAX_KEYS]; /* optional method */ + /* canPartialMatch[i] is true if comparePartialFn[i] is valid */ + bool canPartialMatch[INDEX_MAX_KEYS]; + /* Collations to pass to the support functions */ + Oid supportCollation[INDEX_MAX_KEYS]; +} GinState; + +typedef enum { + ROW_STORE_TYPE = 0, + COL_STORE_TYPE = 1, +} GinPostingListType; + +/* + * A compressed posting list. + * + * Note: This requires 2-byte alignment. + */ +typedef struct { + GinPostingListType type; /* posting list type for row or column cstore */ + ItemPointerData first; /* first item in this posting list (unpacked) */ + uint16 nbytes; /* number of bytes that follow */ + unsigned char bytes[FLEXIBLE_ARRAY_MEMBER]; /* varbyte encoded items (variable length) */ +} GinPostingList; + +#define SizeOfGinPostingList(plist) (offsetof(GinPostingList, bytes) + SHORTALIGN((plist)->nbytes)) +#define GinNextPostingListSegment(cur) ((GinPostingList *)(((char *)(cur)) + SizeOfGinPostingList((cur)))) + +/* XLog stuff */ +#define XLOG_GIN_CREATE_INDEX 0x00 +#define XLOG_GIN_CREATE_PTREE 0x10 + +typedef struct ginxlogCreatePostingTree { + uint32 size; + /* A compressed posting list follows */ +} ginxlogCreatePostingTree; + +/* + * The format of the insertion record varies depending on the page type. + * ginxlogInsert is the common part between all variants. + * + * Backup Blk 0: target page + * Backup Blk 1: left child, if this insertion finishes an incomplete split + */ +#define XLOG_GIN_INSERT 0x20 + +typedef struct { + uint16 flags; /* GIN_INSERT_ISLEAF and/or GIN_INSERT_ISDATA */ + + /* + * FOLLOWS: + * + * 1. if not leaf page, block numbers of the left and right child pages + * whose split this insertion finishes, as BlockIdData[2] (beware of + * adding fields in this struct that would make them not 16-bit aligned) + * + * 2. a ginxlogInsertEntry or ginxlogRecompressDataLeaf struct, depending + * on tree type. + * + * NB: the below structs are only 16-bit aligned when appended to a + * ginxlogInsert struct! Beware of adding fields to them that require + * stricter alignment. + */ +} ginxlogInsert; + +typedef struct ginxlogInsertEntry { + OffsetNumber offset; + bool isDelete; + IndexTupleData tuple; /* variable length */ +} ginxlogInsertEntry; + +typedef struct { + uint16 nactions; + + /* Variable number of 'actions' follow */ +} ginxlogRecompressDataLeaf; + +/* + * Note: this struct is currently not used in code, and only acts as + * documentation. The WAL record format is as specified here, but the code + * uses straight access through a Pointer and memcpy to read/write these. + */ +typedef struct { + uint8 segno; /* segment this action applies to */ + char type; /* action type (see below) */ + + /* + * Action-specific data follows. For INSERT and REPLACE actions that is a + * GinPostingList struct. For ADDITEMS, a uint16 for the number of items + * added, followed by the items themselves as ItemPointers. DELETE actions + * have no further data. + */ +} ginxlogSegmentAction; + +/* Action types */ +#define GIN_SEGMENT_UNMODIFIED 0 /* no action (not used in WAL records) */ +#define GIN_SEGMENT_DELETE 1 /* a whole segment is removed */ +#define GIN_SEGMENT_INSERT 2 /* a whole segment is added */ +#define GIN_SEGMENT_REPLACE 3 /* a segment is replaced */ +#define GIN_SEGMENT_ADDITEMS 4 /* items are added to existing segment */ + +typedef struct ginxlogInsertDataInternal { + OffsetNumber offset; + PostingItem newitem; +} ginxlogInsertDataInternal; + +/* + * Backup Blk 0: new left page (= original page, if not root split) + * Backup Blk 1: new right page + * Backup Blk 2: original page / new root page, if root split + * Backup Blk 3: left child, if this insertion completes an earlier split + */ +#define XLOG_GIN_SPLIT 0x30 + +typedef struct ginxlogSplit { + RelFileNode node; + BlockNumber rrlink; /* right link, or root's blocknumber if root + * split */ + BlockNumber leftChildBlkno; /* valid on a non-leaf split */ + BlockNumber rightChildBlkno; + uint16 flags; /* see below */ +} ginxlogSplit; + +/* + * Flags used in ginxlogInsert and ginxlogSplit records + */ +#define GIN_INSERT_ISDATA 0x01 /* for both insert and split records */ +#define GIN_INSERT_ISLEAF 0x02 /* ditto */ +#define GIN_SPLIT_ROOT 0x04 /* only for split records */ + +typedef struct { + OffsetNumber separator; + OffsetNumber nitem; + + /* FOLLOWS: IndexTuples */ +} ginxlogSplitEntry; + +typedef struct { + uint16 lsize; + uint16 rsize; + ItemPointerData lrightbound; /* new right bound of left page */ + ItemPointerData rrightbound; /* new right bound of right page */ + + /* FOLLOWS: new compressed posting lists of left and right page */ + char newdata[1]; +} ginxlogSplitDataLeaf; + +typedef struct { + OffsetNumber separator; + OffsetNumber nitem; + ItemPointerData rightbound; + + /* FOLLOWS: array of PostingItems */ +} ginxlogSplitDataInternal; + +/* + * Vacuum simply WAL-logs the whole page, when anything is modified. This + * is functionally identical to heap_newpage records, but is kept separate for + * debugging purposes. (When inspecting the WAL stream, it's easier to see + * what's going on when GIN vacuum records are marked as such, not as heap + * records.) This is currently only used for entry tree leaf pages. + */ +#define XLOG_GIN_VACUUM_PAGE 0x40 + +/* + * Vacuuming posting tree leaf page is WAL-logged like recompression caused + * by insertion. + */ +#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE 0x90 + +typedef struct ginxlogVacuumDataLeafPage { + ginxlogRecompressDataLeaf data; +} ginxlogVacuumDataLeafPage; + +/* + * Backup Blk 0: deleted page + * Backup Blk 1: parent + * Backup Blk 2: left sibling + */ +#define XLOG_GIN_DELETE_PAGE 0x50 + +typedef struct ginxlogDeletePage { + OffsetNumber parentOffset; + BlockNumber rightLink; +} ginxlogDeletePage; + +#define XLOG_GIN_UPDATE_META_PAGE 0x60 + +/* + * Backup Blk 0: metapage + * Backup Blk 1: tail page + */ +typedef struct ginxlogUpdateMeta { + RelFileNode node; + GinMetaPageData metadata; + BlockNumber prevTail; + BlockNumber newRightlink; + int32 ntuples; /* if ntuples > 0 then metadata.tail was + * updated with that many tuples; else new sub + * list was inserted */ + /* array of inserted tuples follows */ +} ginxlogUpdateMeta; + +#define XLOG_GIN_INSERT_LISTPAGE 0x70 + +typedef struct ginxlogInsertListPage { + BlockNumber rightlink; + int32 ntuples; + /* array of inserted tuples follows */ +} ginxlogInsertListPage; +/* + * Backup Blk 0: metapage + * Backup Blk 1 to (ndeleted + 1): deleted pages + */ +#define XLOG_GIN_DELETE_LISTPAGE 0x80 + +/* + * The WAL record for deleting list pages must contain a block reference to + * all the deleted pages, so the number of pages that can be deleted in one + * record is limited by XLR_MAX_BLOCK_ID. (block_id 0 is used for the + * metapage.) + */ +#define GIN_NDELETE_AT_ONCE Min(16, XLR_MAX_BLOCK_ID - 1) +typedef struct ginxlogDeleteListPages { + GinMetaPageData metadata; + int32 ndeleted; +} ginxlogDeleteListPages; + +/* ginutil.c */ +extern Datum ginoptions(PG_FUNCTION_ARGS); +extern void initGinState(GinState *state, Relation index); +extern Buffer GinNewBuffer(Relation index); +extern void GinInitBuffer(Buffer b, uint32 f); +extern void GinInitPage(Page page, uint32 f, Size pageSize); +extern void GinInitMetabuffer(Buffer b); +extern void GinInitMetaPage(Page page, Size pageSize); +extern int ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, GinNullCategory categorya, Datum b, + GinNullCategory categoryb); +extern int ginCompareAttEntries(GinState *ginstate, OffsetNumber attnuma, Datum a, GinNullCategory categorya, + OffsetNumber attnumb, Datum b, GinNullCategory categoryb); +extern Datum *ginExtractEntries(GinState *ginstate, OffsetNumber attnum, Datum value, bool isNull, int32 *nentries, + GinNullCategory **categories); + +extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple); +extern Datum gintuple_get_key(GinState *ginstate, IndexTuple tuple, GinNullCategory *category); + +/* gininsert.c */ +extern Datum ginmerge(PG_FUNCTION_ARGS); +extern Datum ginbuild(PG_FUNCTION_ARGS); +extern Datum ginbuildempty(PG_FUNCTION_ARGS); +extern Datum gininsert(PG_FUNCTION_ARGS); +extern void ginEntryInsert(GinState *ginstate, OffsetNumber attnum, Datum key, GinNullCategory category, + ItemPointerData *items, uint32 nitem, GinStatsData *buildStats); +extern Datum cginbuild(PG_FUNCTION_ARGS); + +/* ginbtree.c */ +typedef struct GinBtreeStack { + BlockNumber blkno; + Buffer buffer; + OffsetNumber off; + ItemPointerData iptr; + /* predictNumber contains predicted number of pages on current level */ + uint32 predictNumber; + struct GinBtreeStack *parent; +} GinBtreeStack; + +typedef struct GinBtreeData *GinBtree; + +/* Return codes for GinBtreeData.beginPlaceToPage method */ +typedef enum { + GPTP_NO_WORK, + GPTP_INSERT, + GPTP_SPLIT +} GinPlaceToPageRC; + +typedef struct GinBtreeData { + /* search methods */ + BlockNumber (*findChildPage)(GinBtree, GinBtreeStack *); + BlockNumber (*getLeftMostChild)(GinBtree, Page); + bool (*isMoveRight)(GinBtree, Page); + bool (*findItem)(GinBtree, GinBtreeStack *); + + /* insert methods */ + OffsetNumber (*findChildPtr)(GinBtree, Page, BlockNumber, OffsetNumber); + GinPlaceToPageRC (*beginPlaceToPage)(GinBtree, Buffer, GinBtreeStack *, void *, BlockNumber, void **, Page *, + Page *); + void (*execPlaceToPage)(GinBtree, Buffer, GinBtreeStack *, void *, BlockNumber, void *); + void *(*prepareDownlink)(GinBtree, Buffer); + void (*fillRoot)(GinBtree, Page, BlockNumber, Page, BlockNumber, Page); + + bool isData; + + Relation index; + BlockNumber rootBlkno; + GinState *ginstate; /* not valid in a data scan */ + bool fullScan; + bool isBuild; + + /* Search key for Entry tree */ + OffsetNumber entryAttnum; + Datum entryKey; + GinNullCategory entryCategory; + + /* Search key for data tree (posting tree) */ + ItemPointerData itemptr; +} GinBtreeData; + +/* This represents a tuple to be inserted to entry tree. */ +typedef struct { + IndexTuple entry; /* tuple to insert */ + bool isDelete; /* delete old tuple at same offset? */ +} GinBtreeEntryInsertData; + +/* + * This represents an itempointer, or many itempointers, to be inserted to + * a data (posting tree) leaf page + */ +typedef struct { + ItemPointerData *items; + uint32 nitem; + uint32 curitem; +} GinBtreeDataLeafInsertData; + +/* + * For internal data (posting tree) pages, the insertion payload is a + * PostingItem + */ +extern GinBtreeStack *ginFindLeafPage(GinBtree btree, bool searchMode); +extern Buffer ginStepRight(Buffer buffer, Relation index, int lockmode); +extern void freeGinBtreeStack(GinBtreeStack *stack); +extern void ginInsertValue(GinBtree btree, GinBtreeStack *stack, void *insertdata, GinStatsData *buildStats); + +/* ginentrypage.c */ +extern IndexTuple GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key, GinNullCategory category, + Pointer data, Size dataSize, int nipd, bool errorTooBig); +extern void ginPrepareEntryScan(GinBtree btree, OffsetNumber attnum, Datum key, GinNullCategory category, + GinState *ginstate); +extern void ginEntryFillRoot(GinBtree btree, Page root, BlockNumber lblkno, Page lpage, BlockNumber rblkno, Page rpage); +extern ItemPointer ginReadTuple(GinState *ginstate, OffsetNumber attnum, IndexTuple itup, int *nitems); + +/* gindatapage.c */ +extern ItemPointer GinDataLeafPageGetItems(Page page, int *nitems, ItemPointerData advancePast); +extern int GinDataLeafPageGetItemsToTbm(Page page, TIDBitmap *tbm); +extern BlockNumber createPostingTree(Relation index, ItemPointerData *items, uint32 nitems, GinStatsData *buildStats); +extern void GinDataPageAddPostingItem(Page page, PostingItem *data, OffsetNumber offset); +extern void GinPageDeletePostingItem(Page page, OffsetNumber offset); +extern void ginInsertItemPointers(Relation index, BlockNumber rootBlkno, ItemPointerData *items, uint32 nitem, + GinStatsData *buildStats); +extern GinBtreeStack *ginScanBeginPostingTree(GinBtree btree, Relation index, BlockNumber rootBlkno); +extern void ginDataFillRoot(GinBtree btree, Page root, BlockNumber lblkno, Page lpage, BlockNumber rblkno, Page rpage); +extern void ginPrepareDataScan(GinBtree btree, Relation index, BlockNumber rootBlkno); + +/* + * This is declared in ginvacuum.c, but is passed between ginVacuumItemPointers + * and ginVacuumPostingTreeLeaf and as an opaque struct, so we need a forward + * declaration for it. + */ +typedef struct GinVacuumState GinVacuumState; + +extern void ginVacuumPostingTreeLeaf(Relation rel, Buffer buf, GinVacuumState *gvs); + +/* ginscan.c */ +/* + * GinScanKeyData describes a single GIN index qualifier expression. + * + * From each qual expression, we extract one or more specific index search + * conditions, which are represented by GinScanEntryData. It's quite + * possible for identical search conditions to be requested by more than + * one qual expression, in which case we merge such conditions to have just + * one unique GinScanEntry --- this is particularly important for efficiency + * when dealing with full-index-scan entries. So there can be multiple + * GinScanKeyData.scanEntry pointers to the same GinScanEntryData. + * + * In each GinScanKeyData, nentries is the true number of entries, while + * nuserentries is the number that extractQueryFn returned (which is what + * we report to consistentFn). The "user" entries must come first. + */ +typedef struct GinScanKeyData *GinScanKey; + +typedef struct GinScanEntryData *GinScanEntry; + +typedef struct GinScanKeyData { + /* Real number of entries in scanEntry[] (always > 0) */ + uint32 nentries; + /* Number of entries that extractQueryFn and consistentFn know about */ + uint32 nuserentries; + + /* array of GinScanEntry pointers, one per extracted search condition */ + GinScanEntry *scanEntry; + + /* + * At least one of the entries in requiredEntries must be present for a + * tuple to match the overall qual. + * + * additionalEntries contains entries that are needed by the consistent + * function to decide if an item matches, but are not sufficient to + * satisfy the qual without entries from requiredEntries. + */ + GinScanEntry *requiredEntries; + int nrequired; + GinScanEntry *additionalEntries; + int nadditional; + + /* array of check flags, reported to consistentFn */ + GinTernaryValue *entryRes; + bool (*boolConsistentFn)(GinScanKey key); + GinTernaryValue (*triConsistentFn)(GinScanKey key); + FmgrInfo *consistentFmgrInfo; + FmgrInfo *triConsistentFmgrInfo; + Oid collation; + + /* other data needed for calling consistentFn */ + Datum query; + /* NB: these three arrays have only nuserentries elements! */ + Datum *queryValues; + GinNullCategory *queryCategories; + Pointer *extra_data; + StrategyNumber strategy; + int32 searchMode; + OffsetNumber attnum; + + /* + * Match status data. curItem is the TID most recently tested (could be a + * lossy-page pointer). curItemMatches is TRUE if it passes the + * consistentFn test; if so, recheckCurItem is the recheck flag. + * isFinished means that all the input entry streams are finished, so this + * key cannot succeed for any later TIDs. + */ + ItemPointerData curItem; + bool curItemMatches; + bool recheckCurItem; + bool isFinished; +} GinScanKeyData; + +typedef struct GinScanEntryData { + /* query key and other information from extractQueryFn */ + Datum queryKey; + GinNullCategory queryCategory; + bool isPartialMatch; + Pointer extra_data; + StrategyNumber strategy; + int32 searchMode; + OffsetNumber attnum; + + /* Current page in posting tree */ + Buffer buffer; + + /* current ItemPointer to heap */ + ItemPointerData curItem; + + /* for a partial-match or full-scan query, we accumulate all TIDs here */ + TIDBitmap *matchBitmap; + TBMIterator *matchIterator; + TBMIterateResult *matchResult; + + ItemPointerData *matchList; + int matchNum; + + /* used for Posting list and one page in Posting tree */ + ItemPointerData *list; + int nlist; + int offset; + + bool isFinished; + bool reduceResult; + uint32 predictNumberResult; + GinBtreeData btree; +} GinScanEntryData; + +typedef struct GinScanOpaqueData { + MemoryContext tempCtx; + GinState ginstate; + + GinScanKey keys; /* one per scan qualifier expr */ + uint32 nkeys; + + GinScanEntry *entries; /* one per index search condition */ + uint32 totalentries; + uint32 allocentries; /* allocated length of entries[] */ + + MemoryContext keyCtx; /* used to hold key and entry data */ + + bool isVoidRes; /* true if query is unsatisfiable */ +} GinScanOpaqueData; + +typedef GinScanOpaqueData *GinScanOpaque; + +extern Datum ginbeginscan(PG_FUNCTION_ARGS); +extern Datum ginendscan(PG_FUNCTION_ARGS); +extern Datum ginrescan(PG_FUNCTION_ARGS); +extern Datum ginmarkpos(PG_FUNCTION_ARGS); +extern Datum ginrestrpos(PG_FUNCTION_ARGS); +extern void ginNewScanKey(IndexScanDesc scan); +extern void ginFreeScanKeys(GinScanOpaque so); + +/* ginget.c */ +extern Datum gingetbitmap(PG_FUNCTION_ARGS); +extern Datum cgingetbitmap(PG_FUNCTION_ARGS); + +/* ginfast.c */ +extern Datum gin_clean_pending_list(PG_FUNCTION_ARGS); + +/* ginlogic.c */ +extern void ginInitConsistentFunction(GinState *ginstate, GinScanKey key); + +/* ginvacuum.c */ +extern Datum ginbulkdelete(PG_FUNCTION_ARGS); +extern Datum ginvacuumcleanup(PG_FUNCTION_ARGS); +extern ItemPointer ginVacuumItemPointers(GinVacuumState *gvs, ItemPointerData *items, int nitem, int *nremaining); + +/* ginbulk.c */ +typedef struct GinEntryAccumulator { + RBNode rbnode; + Datum key; + GinNullCategory category; + OffsetNumber attnum; + bool shouldSort; + ItemPointerData *list; + uint32 maxcount; /* allocated size of list[] */ + uint32 count; /* current number of list[] entries */ +} GinEntryAccumulator; + +typedef struct { + GinState *ginstate; + Size allocatedMemory; + GinEntryAccumulator *entryallocator; + uint32 eas_used; + RBTree *tree; +} BuildAccumulator; + +extern void ginInitBA(BuildAccumulator *accum); +extern void ginInsertBAEntries(BuildAccumulator *accum, ItemPointer heapptr, OffsetNumber attnum, Datum *entries, + GinNullCategory *categories, int32 nentries); +extern void ginBeginBAScan(BuildAccumulator *accum); +extern ItemPointerData *ginGetBAEntry(BuildAccumulator *accum, OffsetNumber *attnum, Datum *key, + GinNullCategory *category, uint32 *n); + +/* ginfast.c */ +typedef struct GinTupleCollector { + IndexTuple *tuples; + uint32 ntuples; + uint32 lentuples; + uint32 sumsize; +} GinTupleCollector; + +extern void ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector); +extern void ginHeapTupleFastCollect(GinState *ginstate, GinTupleCollector *collector, OffsetNumber attnum, Datum value, + bool isNull, ItemPointer ht_ctid); +extern void ginInsertCleanup(GinState* ginstate, bool full_clean, bool fill_fsm, bool forceCleanup, + IndexBulkDeleteResult* stats); + +/* ginpostinglist.c */ +extern GinPostingList *ginCompressPostingList(const ItemPointer ptrs, int nptrs, int maxsize, int *nwritten, + bool isColStore); +extern int ginPostingListDecodeAllSegmentsToTbm(GinPostingList *ptr, int totalsize, TIDBitmap *tbm); + +extern ItemPointer ginPostingListDecodeAllSegments(GinPostingList *ptr, int len, int *ndecoded); +extern ItemPointer ginPostingListDecode(GinPostingList *ptr, int *ndecoded); +extern ItemPointer ginMergeItemPointers(ItemPointerData *a, uint32 na, ItemPointerData *b, uint32 nb, int *nmerged); +extern void GinRedoRecompress(Page page, ginxlogRecompressDataLeaf* data); +/* + * Merging the results of several gin scans compares item pointers a lot, + * so we want this to be inlined. But if the compiler doesn't support that, + * fall back on the non-inline version from itemptr.c. See STATIC_IF_INLINE in + * c.h. + */ +static inline int ginCompareItemPointers(ItemPointer a, ItemPointer b) +{ + uint64 ia = ((uint64)a->ip_blkid.bi_hi << 32) | ((uint64)a->ip_blkid.bi_lo << 16) | a->ip_posid; + uint64 ib = ((uint64)b->ip_blkid.bi_hi << 32) | ((uint64)b->ip_blkid.bi_lo << 16) | b->ip_posid; + + if (ia == ib) + return 0; + else if (ia > ib) + return 1; + else + return -1; +} + +#endif /* GIN_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/access/gist.h postgresql-hll-2.14/include/access/gist.h --- postgresql-hll-2.14_old/include/access/gist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gist.h 2020-12-12 17:06:43.061345638 +0800 @@ -0,0 +1,178 @@ +/* ------------------------------------------------------------------------- + * + * gist.h + * The public API for GiST indexes. This API is exposed to + * individuals implementing GiST indexes, so backward-incompatible + * changes should be made with care. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GIST_H +#define GIST_H + +#include "access/xlog.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/bufpage.h" +#include "utils/relcache.h" + +/* + * amproc indexes for GiST indexes. + */ +#define GIST_CONSISTENT_PROC 1 +#define GIST_UNION_PROC 2 +#define GIST_COMPRESS_PROC 3 +#define GIST_DECOMPRESS_PROC 4 +#define GIST_PENALTY_PROC 5 +#define GIST_PICKSPLIT_PROC 6 +#define GIST_EQUAL_PROC 7 +#define GIST_DISTANCE_PROC 8 +#define GISTNProcs 8 + +/* + * strategy numbers for GiST opclasses that want to implement the old + * RTREE behavior. + */ +#define RTLeftStrategyNumber 1 +#define RTOverLeftStrategyNumber 2 +#define RTOverlapStrategyNumber 3 +#define RTOverRightStrategyNumber 4 +#define RTRightStrategyNumber 5 +#define RTSameStrategyNumber 6 +#define RTContainsStrategyNumber 7 /* for @> */ +#define RTContainedByStrategyNumber 8 /* for <@ */ +#define RTOverBelowStrategyNumber 9 +#define RTBelowStrategyNumber 10 +#define RTAboveStrategyNumber 11 +#define RTOverAboveStrategyNumber 12 +#define RTOldContainsStrategyNumber 13 /* for old spelling of @> */ +#define RTOldContainedByStrategyNumber 14 /* for old spelling of <@ */ +#define RTKNNSearchStrategyNumber 15 + +/* + * Page opaque data in a GiST index page. + */ +#define F_LEAF (1 << 0) /* leaf page */ +#define F_DELETED (1 << 1) /* the page has been deleted */ +#define F_TUPLES_DELETED (1 << 2) /* some tuples on the page are dead */ +#define F_FOLLOW_RIGHT (1 << 3) /* page to the right has no downlink */ + +typedef XLogRecPtr GistNSN; + +typedef struct GISTPageOpaqueData { + GistNSN nsn; /* this value must change on page split */ + BlockNumber rightlink; /* next page if any */ + uint16 flags; /* see bit definitions above */ + uint16 gist_page_id; /* for identification of GiST indexes */ +} GISTPageOpaqueData; + +typedef GISTPageOpaqueData *GISTPageOpaque; + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define GIST_PAGE_ID 0xFF81 + +/* + * This is the Split Vector to be returned by the PickSplit method. + * PickSplit should fill the indexes of tuples to go to the left side into + * spl_left[], and those to go to the right into spl_right[] (note the method + * is responsible for palloc'ing both of these arrays!). The tuple counts + * go into spl_nleft/spl_nright, and spl_ldatum/spl_rdatum must be set to + * the union keys for each side. + * + * If spl_ldatum_exists and spl_rdatum_exists are true, then we are performing + * a "secondary split" using a non-first index column. In this case some + * decisions have already been made about a page split, and the set of tuples + * being passed to PickSplit is just the tuples about which we are undecided. + * spl_ldatum/spl_rdatum then contain the union keys for the tuples already + * chosen to go left or right. Ideally the PickSplit method should take those + * keys into account while deciding what to do with the remaining tuples, ie + * it should try to "build out" from those unions so as to minimally expand + * them. If it does so, it should union the given tuples' keys into the + * existing spl_ldatum/spl_rdatum values rather than just setting those values + * from scratch, and then set spl_ldatum_exists/spl_rdatum_exists to false to + * show it has done this. + * + * If the PickSplit method fails to clear spl_ldatum_exists/spl_rdatum_exists, + * the core GiST code will make its own decision about how to merge the + * secondary-split results with the previously-chosen tuples, and will then + * recompute the union keys from scratch. This is a workable though often not + * optimal approach. + */ +typedef struct GIST_SPLITVEC { + OffsetNumber *spl_left; /* array of entries that go left */ + int spl_nleft; /* size of this array */ + Datum spl_ldatum; /* Union of keys in spl_left */ + bool spl_ldatum_exists; /* true, if spl_ldatum already exists. */ + + OffsetNumber *spl_right; /* array of entries that go right */ + int spl_nright; /* size of the array */ + Datum spl_rdatum; /* Union of keys in spl_right */ + bool spl_rdatum_exists; /* true, if spl_rdatum already exists. */ +} GIST_SPLITVEC; + +/* + * An entry on a GiST node. Contains the key, as well as its own + * location (rel,page,offset) which can supply the matching pointer. + * leafkey is a flag to tell us if the entry is in a leaf node. + */ +typedef struct GISTENTRY { + Datum key; + Relation rel; + Page page; + OffsetNumber offset; + bool leafkey; +} GISTENTRY; + +#define GistPageGetOpaque(page) ((GISTPageOpaque)PageGetSpecialPointer(page)) + +#define GistPageIsLeaf(page) (GistPageGetOpaque(page)->flags & F_LEAF) +#define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page)) +#define GistPageSetLeaf(page) (GistPageGetOpaque(page)->flags |= F_LEAF) +#define GistPageSetNonLeaf(page) (GistPageGetOpaque(page)->flags &= ~F_LEAF) + +#define GistPageIsDeleted(page) (GistPageGetOpaque(page)->flags & F_DELETED) +#define GistPageSetDeleted(page) (GistPageGetOpaque(page)->flags |= F_DELETED) +#define GistPageSetNonDeleted(page) (GistPageGetOpaque(page)->flags &= ~F_DELETED) + +#define GistTuplesDeleted(page) (GistPageGetOpaque(page)->flags & F_TUPLES_DELETED) +#define GistMarkTuplesDeleted(page) (GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED) +#define GistClearTuplesDeleted(page) (GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED) + +#define GistFollowRight(page) (GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT) +#define GistMarkFollowRight(page) (GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT) +#define GistClearFollowRight(page) (GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT) + +/* + * Vector of GISTENTRY structs; user-defined methods union and picksplit + * take it as one of their arguments + */ +typedef struct { + int32 n; /* number of elements */ + GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]; +} GistEntryVector; + +#define GEVHDRSZ (offsetof(GistEntryVector, vector)) + +/* + * macro to initialize a GISTENTRY + */ +#define gistentryinit(e, k, r, pg, o, l) do { \ + (e).key = (k); \ + (e).rel = (r); \ + (e).page = (pg); \ + (e).offset = (o); \ + (e).leafkey = (l); \ +} while (0) + +#endif /* GIST_H */ diff -uprN postgresql-hll-2.14_old/include/access/gist_private.h postgresql-hll-2.14/include/access/gist_private.h --- postgresql-hll-2.14_old/include/access/gist_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gist_private.h 2020-12-12 17:06:43.061345638 +0800 @@ -0,0 +1,500 @@ +/* ------------------------------------------------------------------------- + * + * gist_private.h + * private declarations for GiST -- declarations related to the + * internal implementation of GiST, not the public API + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gist_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GIST_PRIVATE_H +#define GIST_PRIVATE_H + +#include "access/gist.h" +#include "access/itup.h" +#include "access/xlogreader.h" +#include "fmgr.h" +#include "storage/bufmgr.h" +#include "storage/buffile.h" +#include "utils/rbtree.h" +#include "utils/hsearch.h" + +/* + * Maximum number of "halves" a page can be split into in one operation. + * Typically a split produces 2 halves, but can be more if keys have very + * different lengths, or when inserting multiple keys in one operation (as + * when inserting downlinks to an internal node). There is no theoretical + * limit on this, but in practice if you get more than a handful page halves + * in one split, there's something wrong with the opclass implementation. + * GIST_MAX_SPLIT_PAGES is an arbitrary limit on that, used to size some + * local arrays used during split. Note that there is also a limit on the + * number of buffers that can be held locked at a time, MAX_SIMUL_LWLOCKS, + * so if you raise this higher than that limit, you'll just get a different + * error. + */ +#define GIST_MAX_SPLIT_PAGES 75 + +/* Buffer lock modes */ +#define GIST_SHARE BUFFER_LOCK_SHARE +#define GIST_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE +#define GIST_UNLOCK BUFFER_LOCK_UNLOCK + +typedef struct { + BlockNumber prev; + uint32 freespace; + char tupledata[1]; +} GISTNodeBufferPage; + +#define BUFFER_PAGE_DATA_OFFSET MAXALIGN(offsetof(GISTNodeBufferPage, tupledata)) +/* Returns free space in node buffer page */ +#define PAGE_FREE_SPACE(nbp) (nbp->freespace) +/* Checks if node buffer page is empty */ +#define PAGE_IS_EMPTY(nbp) (nbp->freespace == BLCKSZ - BUFFER_PAGE_DATA_OFFSET) +/* Checks if node buffers page don't contain sufficient space for index tuple */ +#define PAGE_NO_SPACE(nbp, itup) (PAGE_FREE_SPACE(nbp) < MAXALIGN(IndexTupleSize(itup))) + +/* + * GISTSTATE: information needed for any GiST index operation + * + * This struct retains call info for the index's opclass-specific support + * functions (per index column), plus the index's tuple descriptor. + * + * scanCxt holds the GISTSTATE itself as well as any data that lives for the + * lifetime of the index operation. We pass this to the support functions + * via fn_mcxt, so that they can store scan-lifespan data in it. The + * functions are invoked in tempCxt, which is typically short-lifespan + * (that is, it's reset after each tuple). However, tempCxt can be the same + * as scanCxt if we're not bothering with per-tuple context resets. + */ +typedef struct GISTSTATE { + MemoryContext scanCxt; /* context for scan-lifespan data */ + MemoryContext tempCxt; /* short-term context for calling functions */ + + TupleDesc tupdesc; /* index's tuple descriptor */ + + FmgrInfo consistentFn[INDEX_MAX_KEYS]; + FmgrInfo unionFn[INDEX_MAX_KEYS]; + FmgrInfo compressFn[INDEX_MAX_KEYS]; + FmgrInfo decompressFn[INDEX_MAX_KEYS]; + FmgrInfo penaltyFn[INDEX_MAX_KEYS]; + FmgrInfo picksplitFn[INDEX_MAX_KEYS]; + FmgrInfo equalFn[INDEX_MAX_KEYS]; + FmgrInfo distanceFn[INDEX_MAX_KEYS]; + + /* Collations to pass to the support functions */ + Oid supportCollation[INDEX_MAX_KEYS]; +} GISTSTATE; + +/* + * During a GiST index search, we must maintain a queue of unvisited items, + * which can be either individual heap tuples or whole index pages. If it + * is an ordered search, the unvisited items should be visited in distance + * order. Unvisited items at the same distance should be visited in + * depth-first order, that is heap items first, then lower index pages, then + * upper index pages; this rule avoids doing extra work during a search that + * ends early due to LIMIT. + * + * To perform an ordered search, we use an RBTree to manage the distance-order + * queue. Each GISTSearchTreeItem stores all unvisited items of the same + * distance; they are GISTSearchItems chained together via their next fields. + * + * In a non-ordered search (no order-by operators), the RBTree degenerates + * to a single item, which we use as a queue of unvisited index pages only. + * In this case matched heap items from the current index leaf page are + * remembered in GISTScanOpaqueData.pageData[] and returned directly from + * there, instead of building a separate GISTSearchItem for each one. + */ + +/* Individual heap tuple to be visited */ +typedef struct GISTSearchHeapItem { + ItemPointerData heapPtr; + bool recheck; /* T if quals must be rechecked */ +} GISTSearchHeapItem; + +/* Unvisited item, either index page or heap tuple */ +typedef struct GISTSearchItem { + struct GISTSearchItem *next; /* list link */ + BlockNumber blkno; /* index page number, or InvalidBlockNumber */ + union { + GistNSN parentlsn; /* parent page's LSN, if index page */ + /* we must store parentlsn to detect whether a split occurred */ + GISTSearchHeapItem heap; /* heap info, if heap tuple */ + } data; +} GISTSearchItem; + +#define GISTSearchItemIsHeap(item) ((item).blkno == InvalidBlockNumber) + +/* + * Within a GISTSearchTreeItem's chain, heap items always appear before + * index-page items, since we want to visit heap items first. lastHeap points + * to the last heap item in the chain, or is NULL if there are none. + */ +typedef struct GISTSearchTreeItem { + RBNode rbnode; /* this is an RBTree item */ + GISTSearchItem *head; /* first chain member */ + GISTSearchItem *lastHeap; /* last heap-tuple member, if any */ + double distances[FLEXIBLE_ARRAY_MEMBER]; /* array with numberOfOrderBys entries */ +} GISTSearchTreeItem; + +#define GSTIHDRSZ offsetof(GISTSearchTreeItem, distances) + +/* + * GISTScanOpaqueData: private state for a scan of a GiST index + */ +typedef struct GISTScanOpaqueData { + GISTSTATE *giststate; /* index information, see above */ + RBTree *queue; /* queue of unvisited items */ + MemoryContext queueCxt; /* context holding the queue */ + bool qual_ok; /* false if qual can never be satisfied */ + bool firstCall; /* true until first gistgettuple call */ + + GISTSearchTreeItem *curTreeItem; /* current queue item, if any */ + + /* pre-allocated workspace arrays */ + GISTSearchTreeItem *tmpTreeItem; /* workspace to pass to rb_insert */ + double *distances; /* output area for gistindex_keytest */ + + /* In a non-ordered search, returnable heap items are stored here: */ + GISTSearchHeapItem pageData[BLCKSZ / sizeof(IndexTupleData)]; + OffsetNumber nPageData; /* number of valid items in array */ + OffsetNumber curPageData; /* next item to return */ +} GISTScanOpaqueData; + +typedef GISTScanOpaqueData *GISTScanOpaque; + +/* XLog stuff */ +#define XLOG_GIST_PAGE_UPDATE 0x00 +#define XLOG_GIST_PAGE_SPLIT 0x30 +#define XLOG_GIST_CREATE_INDEX 0x50 +#define XLOG_GIST_PAGE_DELETE 0x60 + +/* + * Backup Blk 0: updated page. + * Backup Blk 1: If this operation completes a page split, by inserting a + * downlink for the split page, the left half of the split + */ +typedef struct gistxlogPageUpdate { + /* number of deleted offsets */ + uint16 ntodelete; + uint16 ntoinsert; + + /* + * In payload of blk 0 : 1. todelete OffsetNumbers 2. tuples to insert + */ +} gistxlogPageUpdate; + +/* + * Backup Blk 0: If this operation completes a page split, by inserting a + * downlink for the split page, the left half of the split + * Backup Blk 1 - npage: split pages (1 is the original page) + */ +typedef struct gistxlogPageSplit { + BlockNumber origrlink; /* rightlink of the page before split */ + GistNSN orignsn; /* NSN of the page before split */ + bool origleaf; /* was splitted page a leaf page? */ + + uint16 npage; /* # of pages in the split */ + bool markfollowright; /* set F_FOLLOW_RIGHT flags */ + + /* + * follow: 1. gistxlogPage and array of IndexTupleData per page + */ +} gistxlogPageSplit; + +typedef struct gistxlogPage { + BlockNumber blkno; + int num; /* number of index tuples following */ +} gistxlogPage; + +typedef struct gistxlogPageDelete { + RelFileNode node; + BlockNumber blkno; +} gistxlogPageDelete; + +/* SplitedPageLayout - gistSplit function result */ +typedef struct SplitedPageLayout { + gistxlogPage block; + IndexTupleData *list; + int lenlist; + IndexTuple itup; /* union key for page */ + Page page; /* to operate */ + Buffer buffer; /* to write after all proceed */ + + struct SplitedPageLayout *next; +} SplitedPageLayout; + +/* + * GISTInsertStack used for locking buffers and transfer arguments during + * insertion + */ +typedef struct GISTInsertStack { + /* current page */ + BlockNumber blkno; + Buffer buffer; + Page page; + + /* + * log sequence number from page->lsn to recognize page update and compare + * it with page's nsn to recognize page split + */ + GistNSN lsn; + + /* offset of the downlink in the parent page, that points to this page */ + OffsetNumber downlinkoffnum; + + /* pointer to parent */ + struct GISTInsertStack *parent; +} GISTInsertStack; + +/* Working state and results for multi-column split logic in gistsplit.c */ +typedef struct GistSplitVector { + GIST_SPLITVEC splitVector; /* passed to/from user PickSplit method */ + + Datum spl_lattr[INDEX_MAX_KEYS]; /* Union of subkeys in + * splitVector.spl_left */ + bool spl_lisnull[INDEX_MAX_KEYS]; + + Datum spl_rattr[INDEX_MAX_KEYS]; /* Union of subkeys in + * splitVector.spl_right */ + bool spl_risnull[INDEX_MAX_KEYS]; + + bool *spl_dontcare; /* flags tuples which could go to either side + * of the split for zero penalty */ +} GistSplitVector; + +typedef struct { + Relation r; + Size freespace; /* free space to be left */ + + GISTInsertStack *stack; +} GISTInsertState; + +/* root page of a gist index */ +#define GIST_ROOT_BLKNO 0 + +/* + * Before PostgreSQL 9.1, we used rely on so-called "invalid tuples" on inner + * pages to finish crash recovery of incomplete page splits. If a crash + * happened in the middle of a page split, so that the downlink pointers were + * not yet inserted, crash recovery inserted a special downlink pointer. The + * semantics of an invalid tuple was that it if you encounter one in a scan, + * it must always be followed, because we don't know if the tuples on the + * child page match or not. + * + * We no longer create such invalid tuples, we now mark the left-half of such + * an incomplete split with the F_FOLLOW_RIGHT flag instead, and finish the + * split properly the next time we need to insert on that page. To retain + * on-disk compatibility for the sake of pg_upgrade, we still store 0xffff as + * the offset number of all inner tuples. If we encounter any invalid tuples + * with 0xfffe during insertion, we throw an error, though scans still handle + * them. You should only encounter invalid tuples if you pg_upgrade a pre-9.1 + * gist index which already has invalid tuples in it because of a crash. That + * should be rare, and you are recommended to REINDEX anyway if you have any + * invalid tuples in an index, so throwing an error is as far as we go with + * supporting that. + */ +#define TUPLE_IS_VALID 0xffff +#define TUPLE_IS_INVALID 0xfffe + +#define GistTupleIsInvalid(itup) (ItemPointerGetOffsetNumber(&((itup)->t_tid)) == TUPLE_IS_INVALID) +#define GistTupleSetValid(itup) ItemPointerSetOffsetNumber(&((itup)->t_tid), TUPLE_IS_VALID) + +/* + * A buffer attached to an internal node, used when building an index in + * buffering mode. + */ +typedef struct { + BlockNumber nodeBlocknum; /* index block # this buffer is for */ + int32 blocksCount; /* current # of blocks occupied by buffer */ + + BlockNumber pageBlocknum; /* temporary file block # */ + GISTNodeBufferPage *pageBuffer; /* in-memory buffer page */ + + /* is this buffer queued for emptying? */ + bool queuedForEmptying; + + /* is this a temporary copy, not in the hash table? */ + bool isTemp; + + int level; /* 0 == leaf */ +} GISTNodeBuffer; + +/* + * Does specified level have buffers? (Beware of multiple evaluation of + * arguments.) + */ +#define LEVEL_HAS_BUFFERS(nlevel, gfbb) \ + ((nlevel) != 0 && (nlevel) % (gfbb)->levelStep == 0 && (nlevel) != (gfbb)->rootlevel) + +/* Is specified buffer at least half-filled (should be queued for emptying)? */ +#define BUFFER_HALF_FILLED(nodeBuffer, gfbb) ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer / 2) + +/* + * Is specified buffer full? Our buffers can actually grow indefinitely, + * beyond the "maximum" size, so this just means whether the buffer has grown + * beyond the nominal maximum size. + */ +#define BUFFER_OVERFLOWED(nodeBuffer, gfbb) ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer) + +/* + * Data structure with general information about build buffers. + */ +typedef struct GISTBuildBuffers { + /* Persistent memory context for the buffers and metadata. */ + MemoryContext context; + + BufFile *pfile; /* Temporary file to store buffers in */ + long nFileBlocks; /* Current size of the temporary file */ + + /* + * resizable array of free blocks. + */ + long *freeBlocks; + int nFreeBlocks; /* # of currently free blocks in the array */ + int freeBlocksLen; /* current allocated length of the array */ + + /* Hash for buffers by block number */ + HTAB *nodeBuffersTab; + + /* List of buffers scheduled for emptying */ + List *bufferEmptyingQueue; + + /* + * Parameters to the buffering build algorithm. levelStep determines which + * levels in the tree have buffers, and pagesPerBuffer determines how + * large each buffer is. + */ + int levelStep; + int pagesPerBuffer; + + /* Array of lists of buffers on each level, for final emptying */ + List **buffersOnLevels; + int buffersOnLevelsLen; + + /* + * Dynamically-sized array of buffers that currently have their last page + * loaded in main memory. + */ + GISTNodeBuffer **loadedBuffers; + int loadedBuffersCount; /* # of entries in loadedBuffers */ + int loadedBuffersLen; /* allocated size of loadedBuffers */ + + /* Level of the current root node (= height of the index tree - 1) */ + int rootlevel; +} GISTBuildBuffers; + +/* + * Storage type for GiST's reloptions + */ +typedef struct GiSTOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int fillfactor; /* page fill factor in percent (0..100) */ + int bufferingModeOffset; /* use buffering build? */ +} GiSTOptions; + +/* gist.c */ +extern Datum gistbuildempty(PG_FUNCTION_ARGS); +extern Datum gistinsert(PG_FUNCTION_ARGS); +extern MemoryContext createTempGistContext(void); +extern GISTSTATE *initGISTstate(Relation index); +extern void freeGISTstate(GISTSTATE *giststate); +extern void gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *GISTstate); + +/* A List of these is returned from gistplacetopage() in *splitinfo */ +typedef struct { + Buffer buf; /* the split page "half" */ + IndexTuple downlink; /* downlink for this half. */ +} GISTPageSplitInfo; + +extern bool gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, Buffer buffer, IndexTuple *itup, + int ntup, OffsetNumber oldoffnum, BlockNumber *newblkno, Buffer leftchildbuf, + List **splitinfo, bool markleftchild); + +extern SplitedPageLayout *gistSplit(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate); + +/* gistxlog.c */ +extern void gist_redo(XLogReaderState *record); +extern void gist_desc(StringInfo buf, XLogReaderState *record); +extern void gist_xlog_startup(void); +extern void gist_xlog_cleanup(void); + +extern XLogRecPtr gistXLogUpdate(Buffer buffer, OffsetNumber *todelete, int ntodelete, IndexTuple *itup, int ntup, + Buffer leftchild); + +extern XLogRecPtr gistXLogSplit(bool page_is_leaf, SplitedPageLayout *dist, BlockNumber origrlink, GistNSN oldnsn, + Buffer leftchild, bool markfollowright); + +/* gistget.c */ +extern Datum gistgettuple(PG_FUNCTION_ARGS); +extern Datum gistgetbitmap(PG_FUNCTION_ARGS); + +/* gistutil.c */ +#define GiSTPageSize (BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GISTPageOpaqueData))) + +#define GIST_MIN_FILLFACTOR 10 +#define GIST_DEFAULT_FILLFACTOR 90 + +extern Datum gistoptions(PG_FUNCTION_ARGS); +extern bool gistfitpage(IndexTuple *itvec, int len); +extern bool gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace); +extern void gistcheckpage(Relation rel, Buffer buf); +extern Buffer gistNewBuffer(Relation r); +extern void gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off); +extern IndexTuple *gistextractpage(Page page, int *len /* out */); +extern IndexTuple *gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen); +extern IndexTupleData *gistfillitupvec(IndexTuple *vec, int veclen, int *memlen); + +extern IndexTuple gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate); +extern IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate); +extern IndexTuple gistFormTuple(GISTSTATE *giststate, Relation r, Datum *attdata, const bool *isnull, bool newValues); + +extern OffsetNumber gistchoose(Relation r, Page p, IndexTuple it, GISTSTATE *giststate); +extern void gistcentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, + bool l, bool isNull); + +extern void GISTInitBuffer(Buffer b, uint32 f); +extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, + bool l, bool isNull); + +extern float gistpenalty(GISTSTATE *giststate, int attno, GISTENTRY *key1, bool isNull1, GISTENTRY *key2, bool isNull2); +extern void gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, Datum *attr, bool *isnull); +extern bool gistKeyIsEQ(GISTSTATE *giststate, int attno, Datum a, Datum b); +extern void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, OffsetNumber o, + GISTENTRY *attdata, bool *isnull); + +extern void gistMakeUnionKey(GISTSTATE *giststate, int attno, GISTENTRY *entry1, bool isnull1, GISTENTRY *entry2, + bool isnull2, Datum *dst, bool *dstisnull); + +extern XLogRecPtr GetXLogRecPtrForTemp(void); + +/* gistvacuum.c */ +extern Datum gistbulkdelete(PG_FUNCTION_ARGS); +extern Datum gistvacuumcleanup(PG_FUNCTION_ARGS); + +/* gistsplit.c */ +extern void gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate, GistSplitVector *v, + int attno); + +/* gistbuild.c */ +extern Datum gistmerge(PG_FUNCTION_ARGS); +extern Datum gistbuild(PG_FUNCTION_ARGS); +extern void gistValidateBufferingOption(const char *value); + +/* gistbuildbuffers.c */ +extern GISTBuildBuffers *gistInitBuildBuffers(int pagesPerBuffer, int levelStep, int maxLevel); +extern GISTNodeBuffer *gistGetNodeBuffer(GISTBuildBuffers *gfbb, GISTSTATE *giststate, BlockNumber blkno, int level); +extern void gistPushItupToNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple item); +extern bool gistPopItupFromNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple *item); +extern void gistFreeBuildBuffers(GISTBuildBuffers *gfbb); +extern void gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate, Relation r, int level, + Buffer buffer, List *splitinfo); +extern void gistUnloadNodeBuffers(GISTBuildBuffers *gfbb); +extern bool IsGistPageUpdate(XLogReaderState *record); +extern void GISTInitPage(Page page, uint32 f, Size pageSize); +extern IndexTuple *decodePageSplitRecord(char *begin, int len, int *n); + +#endif /* GIST_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/access/gistscan.h postgresql-hll-2.14/include/access/gistscan.h --- postgresql-hll-2.14_old/include/access/gistscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gistscan.h 2020-12-12 17:06:43.061345638 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * gistscan.h + * routines defined in access/gist/gistscan.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gistscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GISTSCAN_H +#define GISTSCAN_H + +#include "fmgr.h" + +extern Datum gistbeginscan(PG_FUNCTION_ARGS); +extern Datum gistrescan(PG_FUNCTION_ARGS); +extern Datum gistmarkpos(PG_FUNCTION_ARGS); +extern Datum gistrestrpos(PG_FUNCTION_ARGS); +extern Datum gistendscan(PG_FUNCTION_ARGS); + +#endif /* GISTSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/access/gtm.h postgresql-hll-2.14/include/access/gtm.h --- postgresql-hll-2.14_old/include/access/gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/gtm.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * gtm.h + * + * Module interfacing with GTM definitions + * + * + * ------------------------------------------------------------------------- + */ +#ifndef ACCESS_GTM_H +#define ACCESS_GTM_H + +#include "gtm/gtm_c.h" +#include "workload/workload.h" +#include "commands/sequence.h" + +extern bool IsGTMConnected(void); +extern GtmHostIndex InitGTM(void); +extern void CloseGTM(void); +extern void ResetGtmHandleXmin(GTM_TransactionKey txnKey); +extern int SetGTMVacuumFlag(GTM_TransactionKey txnKey, bool is_vacuum); + +extern GTM_TransactionKey BeginTranGTM(GTM_Timestamp *timestamp); +extern GlobalTransactionId GetGxidGTM(GTM_TransactionKey txnKey, bool is_sub_xact); +extern CommitSeqNo GetCSNGTM(); +extern CommitSeqNo CommitCSNGTM(bool need_clean); +extern TransactionId GetGTMGlobalXmin(); +extern GlobalTransactionId BeginTranAutovacuumGTM(void); +extern int CommitTranGTM(GlobalTransactionId gxid, TransactionId *childXids, int nChildXids); +extern int CommitTranHandleGTM(GTM_TransactionKey txnKey, GlobalTransactionId transactionId, + GlobalTransactionId &outgxid); +extern int RollbackTranGTM(GlobalTransactionId gxid, GlobalTransactionId *childXids, int nChildXids); +extern int RollbackTranHandleGTM(GTM_TransactionKey txnKey, GlobalTransactionId &outgxid); +extern int StartPreparedTranGTM(GlobalTransactionId gxid, const char *gid, const char *nodestring); +extern int PrepareTranGTM(GlobalTransactionId gxid); +extern int GetGIDDataGTM(const char *gid, GlobalTransactionId *gxid, GlobalTransactionId *prepared_gxid, + char **nodestring); +extern int CommitPreparedTranGTM(GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); + +extern GTM_Snapshot GetSnapshotGTM(GTM_TransactionKey txnKey, GlobalTransactionId gxid, bool canbe_grouped, + bool is_vacuum); +extern GTM_Snapshot GetSnapshotGTMLite(void); +extern GTM_SnapshotStatus GetGTMSnapshotStatus(GTM_TransactionKey txnKey); +extern GTMLite_Status GetGTMLiteStatus(void); + +/* Sequence interface APIs with GTM */ +extern GTM_UUID GetSeqUUIDGTM(); +extern int CreateSequenceWithUUIDGTM(FormData_pg_sequence seq, GTM_UUID uuid); +extern GTM_Sequence GetNextValGTM(Form_pg_sequence seq, GTM_Sequence range, GTM_Sequence *rangemax, GTM_UUID uuid); +extern int SetValGTM(GTM_UUID seq_uuid, GTM_Sequence nextval, bool iscalled); + +extern int AlterSequenceGTM(GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +extern int DropSequenceGTM(GTM_UUID seq_uuid, const char *dbname = NULL); +extern int RenameSequenceGTM(char *seqname, char *newseqname, GTM_SequenceKeyType keytype = GTM_SEQ_FULL_NAME); +/* Barrier */ +extern int ReportBarrierGTM(const char *barrier_id); +/* Set gtm rw timeout */ +extern void SetGTMrwTimeout(int timeout); +/* Initiate GTM connection and report connected GTM host timeline to MyBEEntry */ +extern void InitGTM_Reporttimeline(void); +extern void SetGTMInterruptFlag(); +extern bool PingGTM(struct gtm_conn* conn); + +#endif /* ACCESS_GTM_H */ diff -uprN postgresql-hll-2.14_old/include/access/hash.h postgresql-hll-2.14/include/access/hash.h --- postgresql-hll-2.14_old/include/access/hash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/hash.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,370 @@ +/* ------------------------------------------------------------------------- + * + * hash.h + * header file for postgres hash access method implementation + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hash.h + * + * NOTES + * modeled after Margo Seltzer's hash implementation for unix. + * + * ------------------------------------------------------------------------- + */ +#ifndef HASH_H +#define HASH_H + +#include "access/genam.h" +#include "access/itup.h" +#include "access/sdir.h" +#include "access/xlogreader.h" +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "storage/bufmgr.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +/* + * Mapping from hash bucket number to physical block number of bucket's + * starting page. Beware of multiple evaluations of argument! + */ +typedef uint32 Bucket; + +#define INVALID_BUCKET_NUM (0xFFFFFFFF) +#define BUCKET_TO_BLKNO(metap, B) ((BlockNumber)((B) + ((B) ? (metap)->hashm_spares[_hash_log2((B) + 1) - 1] : 0)) + 1) + +/* + * Special space for hash index pages. + * + * hasho_flag tells us which type of page we're looking at. For + * example, knowing overflow pages from bucket pages is necessary + * information when you're deleting tuples from a page. If all the + * tuples are deleted from an overflow page, the overflow is made + * available to other buckets by calling _hash_freeovflpage(). If all + * the tuples are deleted from a bucket page, no additional action is + * necessary. + */ +#define LH_UNUSED_PAGE (0) +#define LH_OVERFLOW_PAGE (1 << 0) +#define LH_BUCKET_PAGE (1 << 1) +#define LH_BITMAP_PAGE (1 << 2) +#define LH_META_PAGE (1 << 3) + +typedef struct HashPageOpaqueData { + BlockNumber hasho_prevblkno; /* previous ovfl (or bucket) blkno */ + BlockNumber hasho_nextblkno; /* next ovfl blkno */ + Bucket hasho_bucket; /* bucket number this pg belongs to */ + uint16 hasho_flag; /* page type code, see above */ + uint16 hasho_page_id; /* for identification of hash indexes */ +} HashPageOpaqueData; + +typedef HashPageOpaqueData* HashPageOpaque; + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define HASHO_PAGE_ID 0xFF80 + +/* + * HashScanOpaqueData is private state for a hash index scan. + */ +typedef struct HashScanOpaqueData { + /* Hash value of the scan key, ie, the hash key we seek */ + uint32 hashso_sk_hash; + + /* + * By definition, a hash scan should be examining only one bucket. We + * record the bucket number here as soon as it is known. + */ + Bucket hashso_bucket; + bool hashso_bucket_valid; + + /* + * If we have a share lock on the bucket, we record it here. When + * hashso_bucket_blkno is zero, we have no such lock. + */ + BlockNumber hashso_bucket_blkno; + + /* + * We also want to remember which buffer we're currently examining in the + * scan. We keep the buffer pinned (but not locked) across hashgettuple + * calls, in order to avoid doing a ReadBuffer() for every tuple in the + * index. + */ + Buffer hashso_curbuf; + + /* Current position of the scan, as an index TID */ + ItemPointerData hashso_curpos; + + /* Current position of the scan, as a heap TID */ + ItemPointerData hashso_heappos; +} HashScanOpaqueData; + +typedef HashScanOpaqueData* HashScanOpaque; + +/* + * Definitions for metapage. + */ + +#define HASH_METAPAGE 0 /* metapage is always block 0 */ + +#define HASH_MAGIC 0x6440640 +#define HASH_VERSION 2 /* 2 signifies only hash key value is stored */ + +/* + * Spares[] holds the number of overflow pages currently allocated at or + * before a certain splitpoint. For example, if spares[3] = 7 then there are + * 7 ovflpages before splitpoint 3 (compare BUCKET_TO_BLKNO macro). The + * value in spares[ovflpoint] increases as overflow pages are added at the + * end of the index. Once ovflpoint increases (ie, we have actually allocated + * the bucket pages belonging to that splitpoint) the number of spares at the + * prior splitpoint cannot change anymore. + * + * ovflpages that have been recycled for reuse can be found by looking at + * bitmaps that are stored within ovflpages dedicated for the purpose. + * The blknos of these bitmap pages are kept in bitmaps[]; nmaps is the + * number of currently existing bitmaps. + * + * The limitation on the size of spares[] comes from the fact that there's + * no point in having more than 2^32 buckets with only uint32 hashcodes. + * There is no particular upper limit on the size of mapp[], other than + * needing to fit into the metapage. (With 8K block size, 128 bitmaps + * limit us to 64 Gb of overflow space...) + */ +#define HASH_MAX_SPLITPOINTS 32 +#define HASH_MAX_BITMAPS 128 + +typedef struct HashMetaPageData { + uint32 hashm_magic; /* magic no. for hash tables */ + uint32 hashm_version; /* version ID */ + double hashm_ntuples; /* number of tuples stored in the table */ + uint16 hashm_ffactor; /* target fill factor (tuples/bucket) */ + uint16 hashm_bsize; /* index page size (bytes) */ + uint16 hashm_bmsize; /* bitmap array size (bytes) - must be a power + * of 2 */ + uint16 hashm_bmshift; /* log2(bitmap array size in BITS) */ + uint32 hashm_maxbucket; /* ID of maximum bucket in use */ + uint32 hashm_highmask; /* mask to modulo into entire table */ + uint32 hashm_lowmask; /* mask to modulo into lower half of table */ + uint32 hashm_ovflpoint; /* splitpoint from which ovflpgs being + * allocated */ + uint32 hashm_firstfree; /* lowest-number free ovflpage (bit#) */ + uint32 hashm_nmaps; /* number of bitmap pages */ + RegProcedure hashm_procid; /* hash procedure id from pg_proc */ + uint32 hashm_spares[HASH_MAX_SPLITPOINTS]; /* spare pages before + * each splitpoint */ + BlockNumber hashm_mapp[HASH_MAX_BITMAPS]; /* blknos of ovfl bitmaps */ +} HashMetaPageData; + +typedef HashMetaPageData* HashMetaPage; + +/* + * Maximum size of a hash index item (it's okay to have only one per page) + */ +#define HashMaxItemSize(page) \ + MAXALIGN_DOWN( \ + PageGetPageSize(page) - SizeOfPageHeaderData - sizeof(ItemIdData) - MAXALIGN(sizeof(HashPageOpaqueData))) + +#define INDEX_MOVED_BY_SPLIT_MASK INDEX_AM_RESERVED_BIT + +#define HASH_MIN_FILLFACTOR 10 +#define HASH_DEFAULT_FILLFACTOR 75 + +/* + * Constants + */ +#define BYTE_TO_BIT 3 /* 2^3 bits/byte */ +#define ALL_SET ((uint32)~0) + +/* + * Bitmap pages do not contain tuples. They do contain the standard + * page headers and trailers; however, everything in between is a + * giant bit array. The number of bits that fit on a page obviously + * depends on the page size and the header/trailer overhead. We require + * the number of bits per page to be a power of 2. + */ +#define BMPGSZ_BYTE(metap) ((metap)->hashm_bmsize) +#define BMPGSZ_BIT(metap) ((metap)->hashm_bmsize << BYTE_TO_BIT) +#define BMPG_SHIFT(metap) ((metap)->hashm_bmshift) +#define BMPG_MASK(metap) (BMPGSZ_BIT(metap) - 1) + +#define HashPageGetBitmap(page) ((uint32*)PageGetContents(page)) + +#define HashGetMaxBitmapSize(page) \ + (PageGetPageSize((Page)page) - (MAXALIGN(SizeOfPageHeaderData) + MAXALIGN(sizeof(HashPageOpaqueData)))) + +#define HashPageGetMeta(page) ((HashMetaPage)PageGetContents(page)) + +/* + * The number of bits in an ovflpage bitmap word. + */ +#define BITS_PER_MAP 32 /* Number of bits in uint32 */ + +/* Given the address of the beginning of a bit map, clear/set the nth bit */ +#define CLRBIT(A, N) ((A)[(N) / BITS_PER_MAP] &= ~(1U << ((N) % BITS_PER_MAP))) +#define SETBIT(A, N) ((A)[(N) / BITS_PER_MAP] |= (1 << ((N) % BITS_PER_MAP))) +#define ISSET(A, N) ((A)[(N) / BITS_PER_MAP] & (1 << ((N) % BITS_PER_MAP))) + +/* + * page-level and high-level locking modes (see README) + */ +#define HASH_READ BUFFER_LOCK_SHARE +#define HASH_WRITE BUFFER_LOCK_EXCLUSIVE +#define HASH_NOLOCK (-1) + +#define HASH_SHARE ShareLock +#define HASH_EXCLUSIVE ExclusiveLock + +/* + * Strategy number. There's only one valid strategy for hashing: equality. + */ +#define HTEqualStrategyNumber 1 +#define HTMaxStrategyNumber 1 + +/* + * When a new operator class is declared, we require that the user supply + * us with an amproc procudure for hashing a key of the new type. + * Since we only have one such proc in amproc, it's number 1. + */ +#define HASHPROC 1 + +/* public routines */ +extern Datum hashmerge(PG_FUNCTION_ARGS); +extern Datum hashbuild(PG_FUNCTION_ARGS); +extern Datum hashbuildempty(PG_FUNCTION_ARGS); +extern Datum hashinsert(PG_FUNCTION_ARGS); +extern Datum hashbeginscan(PG_FUNCTION_ARGS); +extern Datum hashgettuple(PG_FUNCTION_ARGS); +extern Datum hashgetbitmap(PG_FUNCTION_ARGS); +extern Datum hashrescan(PG_FUNCTION_ARGS); +extern Datum hashendscan(PG_FUNCTION_ARGS); +extern Datum hashmarkpos(PG_FUNCTION_ARGS); +extern Datum hashrestrpos(PG_FUNCTION_ARGS); +extern Datum hashbulkdelete(PG_FUNCTION_ARGS); +extern Datum hashvacuumcleanup(PG_FUNCTION_ARGS); +extern Datum hashoptions(PG_FUNCTION_ARGS); + +/* + * Datatype-specific hash functions in hashfunc.c. + * + * These support both hash indexes and hash joins. + * + * NOTE: some of these are also used by catcache operations, without + * any direct connection to hash indexes. Also, the common hash_any + * routine is also used by dynahash tables. + */ +extern Datum hashchar(PG_FUNCTION_ARGS); +extern Datum hashint1(PG_FUNCTION_ARGS); +extern Datum hashint2(PG_FUNCTION_ARGS); +extern Datum hashint4(PG_FUNCTION_ARGS); +extern Datum hashint8(PG_FUNCTION_ARGS); +extern Datum hashoid(PG_FUNCTION_ARGS); +extern Datum hashenum(PG_FUNCTION_ARGS); +extern Datum hashfloat4(PG_FUNCTION_ARGS); +extern Datum hashfloat8(PG_FUNCTION_ARGS); +extern Datum hashoidvector(PG_FUNCTION_ARGS); +extern Datum hashint2vector(PG_FUNCTION_ARGS); +extern Datum hashname(PG_FUNCTION_ARGS); +extern Datum hashtext(PG_FUNCTION_ARGS); +extern Datum hashvarlena(PG_FUNCTION_ARGS); +extern Datum hash_any(register const unsigned char* k, register int keylen); +extern Datum hash_uint32(uint32 k); +extern Datum hash_new_uint32(uint32 k); + +/* private routines */ + +/* hashinsert.c */ +extern void _hash_doinsert(Relation rel, IndexTuple itup); +extern OffsetNumber _hash_pgaddtup(Relation rel, Buffer buf, Size itemsize, IndexTuple itup); + +/* hashovfl.c */ +extern Buffer _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf); +extern BlockNumber _hash_freeovflpage(Relation rel, Buffer ovflbuf, BufferAccessStrategy bstrategy); +extern void _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno, ForkNumber forkNum); +extern void _hash_squeezebucket(Relation rel, Bucket bucket, BlockNumber bucket_blkno, BufferAccessStrategy bstrategy); + +/* hashpage.c */ +extern void _hash_getlock(Relation rel, BlockNumber whichlock, int access); +extern bool _hash_try_getlock(Relation rel, BlockNumber whichlock, int access); +extern void _hash_droplock(Relation rel, BlockNumber whichlock, int access); +extern Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags); +extern Buffer _hash_getinitbuf(Relation rel, BlockNumber blkno); +extern Buffer _hash_getnewbuf(Relation rel, BlockNumber blkno, ForkNumber forkNum); +extern Buffer _hash_getbuf_with_strategy( + Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy); +extern void _hash_relbuf(Relation rel, Buffer buf); +extern void _hash_dropbuf(Relation rel, Buffer buf); +extern void _hash_wrtbuf(Relation rel, Buffer buf); +extern void _hash_chgbufaccess(Relation rel, Buffer buf, int from_access, int to_access); +extern uint32 _hash_metapinit(Relation rel, double num_tuples, ForkNumber forkNum); +extern void _hash_pageinit(Page page, Size size); +extern void _hash_expandtable(Relation rel, Buffer metabuf); + +/* hashscan.c */ +extern void _hash_regscan(IndexScanDesc scan); +extern void _hash_dropscan(IndexScanDesc scan); +extern bool _hash_has_active_scan(Relation rel, Bucket bucket); +extern void ReleaseResources_hash(void); + +/* hashsearch.c */ +extern bool _hash_next(IndexScanDesc scan, ScanDirection dir); +extern bool _hash_first(IndexScanDesc scan, ScanDirection dir); +extern bool _hash_step(IndexScanDesc scan, Buffer* bufP, ScanDirection dir); + +/* hashsort.c */ +typedef struct HSpool HSpool; /* opaque struct in hashsort.c */ + +extern HSpool* _h_spoolinit(Relation index, uint32 num_buckets, void* meminfo); +extern void _h_spooldestroy(HSpool* hspool); +extern void _h_spool(HSpool* hspool, ItemPointer self, Datum* values, const bool* isnull); +extern void _h_indexbuild(HSpool* hspool); + +/* hashutil.c */ +extern bool _hash_checkqual(IndexScanDesc scan, IndexTuple itup); +extern uint32 _hash_datum2hashkey(Relation rel, Datum key); +extern uint32 _hash_datum2hashkey_type(Relation rel, Datum key, Oid keytype); +extern Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask); +extern uint32 _hash_log2(uint32 num); +extern void _hash_checkpage(Relation rel, Buffer buf, int flags); +extern uint32 _hash_get_indextuple_hashkey(IndexTuple itup); +extern IndexTuple _hash_form_tuple(Relation index, Datum* values, const bool* isnull); +extern OffsetNumber _hash_binsearch(Page page, uint32 hash_value); +extern OffsetNumber _hash_binsearch_last(Page page, uint32 hash_value); + +/* hash.c */ +extern void hash_redo(XLogReaderState* record); +extern void hash_desc(StringInfo buf, XLogReaderState* record); + +#ifdef PGXC +extern Datum compute_hash(Oid type, Datum value, char locator); +extern uint32 hashValueCombination(uint32 hashValue, Oid colType, Datum val, bool allIsNull, char locatorType = 'H'); +extern char* get_compute_hash_function(Oid type, char locator); +extern Datum getbucket(PG_FUNCTION_ARGS); +extern ScalarVector* vgetbucket(PG_FUNCTION_ARGS); +extern ScalarVector* vtable_data_skewness(PG_FUNCTION_ARGS); +// template function implementation +// +#include "hash.inl" +#endif + +typedef struct MultiHashKey +{ + uint32 keyNum; + Oid* keyTypes; + Datum* keyValues; + bool* isNulls; + char locatorType; /* see LOCATOR_TYPE_?, e.g., LOCATOR_TYPE_HASH, LOCATOR_TYPE_NONE */ +} MultiHashKey; + +/* compute the hash value of mulitily keys */ +extern uint32 hash_multikey(MultiHashKey* mkeys); + +#define GetBucketID(hashval) (compute_modulo(abs((int)hashval), BUCKETDATALEN)) + +#endif /* HASH_H */ diff -uprN postgresql-hll-2.14_old/include/access/hash.inl postgresql-hll-2.14/include/access/hash.inl --- postgresql-hll-2.14_old/include/access/hash.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/hash.inl 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,157 @@ +/*------------------------------------------------------------------------- + * + * hash.inl + * header file for hash template implementation + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hash.inl + * + * + *------------------------------------------------------------------------- + */ + +#ifndef HASHTEMPLATE_INL +#define HASHTEMPLATE_INL + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/hash.h" + +#ifdef PGXC +#include "catalog/pg_type.h" +#include "utils/builtins.h" +#include "utils/timestamp.h" +#include "utils/date.h" +#include "utils/nabstime.h" +#endif + +template +Datum +computeHashT(Datum value) +{ + uint8 tmp8; + int16 tmp16; + int32 tmp32; + int64 tmp64; + Oid tmpoid; + char tmpch; + + switch (type) + { + case INT8OID: + /* This gives added advantage that + * a = 8446744073709551359 + * and a = 8446744073709551359::int8 both work*/ + tmp64 = DatumGetInt64(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint8, value); + return tmp64; + case INT1OID: + tmp8 = DatumGetUInt8(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint1, tmp8); + return tmp8; + case INT2OID: + tmp16 = DatumGetInt16(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint2, tmp16); + return tmp16; + case OIDOID: + tmpoid = DatumGetObjectId(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashoid, tmpoid); + return tmpoid; + case INT4OID: + tmp32 = DatumGetInt32(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case BOOLOID: + tmpch = DatumGetBool(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashchar, tmpch); + return tmpch; + + case CHAROID: + return DirectFunctionCall1(hashchar, value); + case NAMEOID: + return DirectFunctionCall1(hashname, value); + case INT2VECTOROID: + return DirectFunctionCall1(hashint2vector, value); + + case CLOBOID: + case NVARCHAR2OID: + case VARCHAROID: + case TEXTOID: + return DirectFunctionCall1(hashtext, value); + + case OIDVECTOROID: + return DirectFunctionCall1(hashoidvector, value); + case FLOAT4OID: + return DirectFunctionCall1(hashfloat4, value); + case FLOAT8OID: + return DirectFunctionCall1(hashfloat8, value); + + case ABSTIMEOID: + tmp32 = DatumGetAbsoluteTime(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case RELTIMEOID: + tmp32 = DatumGetRelativeTime(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case CASHOID: + return DirectFunctionCall1(hashint8, value); + + case BPCHAROID: + return DirectFunctionCall1(hashbpchar, value); + case BYTEAWITHOUTORDERWITHEQUALCOLOID: + case BYTEAWITHOUTORDERCOLOID: + case RAWOID: + case BYTEAOID: + return DirectFunctionCall1(hashvarlena, value); + + case DATEOID: + tmp32 = DatumGetDateADT(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case TIMEOID: + return DirectFunctionCall1(time_hash, value); + case TIMESTAMPOID: + return DirectFunctionCall1(timestamp_hash, value); + case TIMESTAMPTZOID: + return DirectFunctionCall1(timestamp_hash, value); + case INTERVALOID: + if (ifCol) + value = PointerGetDatum((char*)value + VARHDRSZ_SHORT); + return DirectFunctionCall1(interval_hash, value); + case TIMETZOID: + if (ifCol) + value = PointerGetDatum((char*)value + VARHDRSZ_SHORT); + return DirectFunctionCall1(timetz_hash, value); + case SMALLDATETIMEOID: + return DirectFunctionCall1(timestamp_hash, value); + + case NUMERICOID: + return DirectFunctionCall1(hash_numeric, value); + case UUIDOID: + return DirectFunctionCall1(uuid_hash, value); + default: + ereport(ERROR,(errcode(ERRCODE_INDETERMINATE_DATATYPE), + errmsg("Unhandled datatype for modulo or hash distribution\n"))); + } + /* Control should not come here. */ + ereport(ERROR,(errcode(ERRCODE_INDETERMINATE_DATATYPE), + errmsg("Unhandled datatype for modulo or hash distribution\n"))); + /* Keep compiler silent */ + return (Datum)0; +} + +#endif /* HASH_H */ diff -uprN postgresql-hll-2.14_old/include/access/hbindex_am.h postgresql-hll-2.14/include/access/hbindex_am.h --- postgresql-hll-2.14_old/include/access/hbindex_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/hbindex_am.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hbindex_am.h + * hash bucket index access method definitions. + + * + * + * IDENTIFICATION + * src/include/access/hbindex_am.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef HBINDEX_AM_H +#define HBINDEX_AM_H + +#include "access/relscan.h" +#include "access/heapam.h" +#include "utils/relcache.h" +#include "optimizer/bucketinfo.h" +#include "utils/rel_gs.h" + + +static inline bool hbkt_idx_need_switch_bkt(IndexScanDesc scan, int targetSlot) +{ + if (RELATION_OWN_BUCKET(scan->indexRelation)) { + HBktIdxScanDesc hbScan = (HBktIdxScanDesc)scan; + return targetSlot < list_length(hbScan->hBktList) && targetSlot != hbScan->curr_slot; + } else { + return false; + } +} + +extern bool hbkt_idx_bitmapscan_switch_bucket(IndexScanDesc scan, int target_slot); + +extern bool hbkt_idx_bitmapscan_switch_bucket(IndexScanDesc scan, int targetSlot); +extern IndexScanDesc scan_handler_idx_beginscan(Relation heap_relation, Relation index_relation, Snapshot snapshot, int nkeys, int norderbys, ScanState* scan_state); +extern IndexScanDesc scan_handler_idx_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, int nkeys, ScanState* scan_state); +extern void scan_handler_idx_rescan(IndexScanDesc scan, ScanKey key, int nkeys, ScanKey orderbys, int norderbys); +extern void scan_handler_idx_rescan_local(IndexScanDesc scan, ScanKey key, int nkeys, ScanKey orderbys, int norderbys); +extern void scan_handler_idx_endscan(IndexScanDesc scan); +extern void scan_handler_idx_markpos(IndexScanDesc scan); +extern void scan_handler_idx_restrpos(IndexScanDesc scan); +extern HeapTuple scan_handler_idx_fetch_heap(IndexScanDesc scan); +extern HeapTuple scan_handler_idx_getnext(IndexScanDesc scan, ScanDirection direction); +extern ItemPointer scan_handler_idx_getnext_tid(IndexScanDesc scan, ScanDirection direction); +extern int64 scan_handler_idx_getbitmap(IndexScanDesc scan, TIDBitmap* bitmap); + +#endif /* HBINDEX_AM_H */ diff -uprN postgresql-hll-2.14_old/include/access/hbucket_am.h postgresql-hll-2.14/include/access/hbucket_am.h --- postgresql-hll-2.14_old/include/access/hbucket_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/hbucket_am.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,78 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hbucket_am.h + * hash bucket table access method definitions. + * + * + * IDENTIFICATION + * src/include/access/hbucket_am.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HASHPART_AM_H +#define HASHPART_AM_H + +#include "access/relscan.h" +#include "access/heapam.h" +#include "utils/relcache.h" +#include "optimizer/bucketinfo.h" +#include "access/tableam.h" + +/* +* redis need merge item +*/ +typedef struct RedisMergeItem { + int2 bktid; + uint64 start; + uint64 end; +}RedisMergeItem; + +typedef struct RedisMergeItemOrderArray { + RedisMergeItem *itemarray; + int length; +}RedisMergeItemOrderArray; + +extern RedisMergeItem *hbkt_get_merge_item_from_str(char *merge_list, int merge_list_length, int2 bucketid); + +extern TableScanDesc GetHeapScanDesc(TableScanDesc scan, Relation rel); +extern IndexScanDesc GetIndexScanDesc(IndexScanDesc scan); +extern List* hbkt_load_buckets(Relation relation, BucketInfo* bkt_info); + +extern RedisMergeItemOrderArray *hbkt_get_merge_list_from_str(char* merge_list, int merge_list_length); + +void hbkt_set_merge_list_to_pgxc_class_option(Oid pcrelid, RedisMergeItemOrderArray* merge_items, bool first_set); + +extern RedisMergeItem *search_redis_merge_item(const RedisMergeItemOrderArray *merge_items, const int2 bucketid); +extern void freeRedisMergeItemOrderArray(RedisMergeItemOrderArray *merge_items); + +extern bool hbkt_sampling_scan_nextbucket(TableScanDesc hpScan); +extern bool hbkt_bitmapheap_scan_nextbucket(HBktTblScanDesc hpScan); +extern bool hbkt_tbl_tid_nextbucket(HBktTblScanDesc hpScan); + +extern TableScanDesc scan_handler_tbl_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, ScanState* sstate = NULL); +extern TableScanDesc scan_handler_tbl_begin_tidscan(Relation relation, ScanState* state); +extern void scan_handler_tbl_end_tidscan(TableScanDesc scan); +extern void scan_handler_tbl_markpos(TableScanDesc scan); +extern void scan_handler_tbl_restrpos(TableScanDesc scan); +extern TableScanDesc scan_handler_tbl_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, ScanState* sstate); +extern TableScanDesc scan_handler_tbl_beginscan_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync, ScanState* sstate); +extern Tuple scan_handler_tbl_getnext(TableScanDesc scan, ScanDirection direction, Relation rel); +extern void scan_handler_tbl_endscan(TableScanDesc scan, Relation rel); +extern void scan_handler_tbl_rescan(TableScanDesc scan, struct ScanKeyData* key, Relation rel); +#define NOT_EXIST_MERGE_LIST "not_exist_merge_list" + +#endif /* HASHPART_AM_H */ diff -uprN postgresql-hll-2.14_old/include/access/heapam.h postgresql-hll-2.14/include/access/heapam.h --- postgresql-hll-2.14_old/include/access/heapam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/heapam.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,345 @@ +/* ------------------------------------------------------------------------- + * + * heapam.h + * POSTGRES heap access method definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/heapam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HEAPAM_H +#define HEAPAM_H + +#include "access/sdir.h" +#include "access/skey.h" +#include "access/xlogrecord.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "storage/pagecompress.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/snapshot.h" +#include "replication/bcm.h" + +/* "options" flag bits for heap_insert */ +#define HEAP_INSERT_SKIP_WAL 0x0001 +#define HEAP_INSERT_SKIP_FSM 0x0002 +#define HEAP_INSERT_FROZEN 0x0004 +#define HEAP_INSERT_SPECULATIVE 0x0008 + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ +typedef struct SeqScanAccessor { + BlockNumber sa_last_prefbf; /* last prefetch block number */ + BlockNumber sa_pref_trigbf; /* last triggle block number */ + uint32 sa_prefetch_quantity; /* preftch quantity*/ + uint32 sa_prefetch_trigger; /* the prefetch-trigger distance bewteen last prefetched buffer and currently accessed buffer */ +} SeqScanAccessor; + +typedef struct RangeScanInRedis{ + uint8 isRangeScanInRedis; + uint8 sliceTotal; + uint8 sliceIndex; +} RangeScanInRedis; + +/* + * Generic descriptor for table scans. This is the base-class for table scans, + * which needs to be embedded in the scans of individual AMs. + */ +typedef struct TableScanDescData +{ + /* scan parameters */ + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; /* heap relation descriptor */ + Snapshot rs_snapshot; /* snapshot to see */ + int rs_nkeys; /* number of scan keys */ + ScanKey rs_key; /* array of scan key descriptors */ + bool rs_pageatatime; /* verify visibility page-at-a-time? */ + + /* + * Information about type and behaviour of the scan, a bitmask of members + * of the ScanOptions enum (see tableam.h). + */ + uint32 rs_flags; + + /* state set up at initscan time */ + BlockNumber rs_nblocks; /* number of blocks to scan */ + BlockNumber rs_startblock; /* block # to start at */ + BufferAccessStrategy rs_strategy; /* access strategy for reads */ + bool rs_syncscan; /* report location to syncscan logic? */ + + /* scan current state */ + bool rs_inited; /* false = scan not init'd yet */ + BlockNumber rs_cblock; /* current block # in scan, if any */ + Buffer rs_cbuf; /* current buffer in scan, if any */ + + /* these fields only used in page-at-a-time mode and for bitmap scans */ + int rs_cindex; /* current tuple's index in vistuples */ + int rs_ntuples; /* number of visible tuples on page */ + OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */ + SeqScanAccessor* rs_ss_accessor; /* adio use it to init prefetch quantity and trigger */ + + /* state set up at initscan time */ + RangeScanInRedis rs_rangeScanInRedis; /* if it is a range scan in redistribution */ +} TableScanDescData; + +/* struct definition appears in relscan.h */ +typedef struct TableScanDescData *TableScanDesc; +typedef struct HeapScanDescData* HeapScanDesc; +typedef struct IndexScanDescData* IndexScanDesc; + +/* + * Base class for fetches from a table via an index. This is the base-class + * for such scans, which needs to be embedded in the respective struct for + * individual AMs. + */ +typedef struct IndexFetchTableData +{ + Relation rel; +} IndexFetchTableData; + +/* + * Descriptor for fetches from heap via an index. + */ +typedef struct IndexFetchHeapData +{ + IndexFetchTableData xs_base; /* AM independent part of the descriptor */ + + /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ +} IndexFetchHeapData; + +struct ScanState; + +typedef struct BulkInsertStateData* BulkInsertState; + +typedef enum { LockTupleShared, LockTupleExclusive } LockTupleMode; + +/* the last arguments info for heap_multi_insert() */ +typedef struct { + /* compression info: dictionary buffer and its size */ + const char* dictData; + int dictSize; + + /* forbid to use page replication */ + bool disablePageReplication; +} HeapMultiInsertExtraArgs; + +/* + * When tuple_update, tuple_delete, or tuple_lock fail because the target + * tuple is already outdated, they fill in this struct to provide information + * to the caller about what happened. + * + * ctid is the target's ctid link: it is the same as the target's TID if the + * target was deleted, or the location of the replacement tuple if the target + * was updated. + * + * xmax is the outdating transaction's XID. If the caller wants to visit the + * replacement tuple, it must check that this matches before believing the + * replacement is really a match. + * + * cmax is the outdating command's CID, but only when the failure code is + * HeapTupleSelfUpdated (i.e., something in the current transaction outdated the + * tuple); otherwise cmax is zero. (We make this restriction because + * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other + * transactions.) + */ +typedef struct TM_FailureData +{ + ItemPointerData ctid; + TransactionId xmax; + TransactionId xmin; + CommandId cmax; +} TM_FailureData; + +#define enable_heap_bcm_data_replication() \ + (u_sess->attr.attr_storage.enable_data_replicate && !g_instance.attr.attr_storage.enable_mix_replication) + +/* ---------------- + * function prototypes for heap access method + * + * heap_create, heap_create_with_catalog, and heap_drop_with_catalog + * are declared in catalog/heap.h + * ---------------- + */ + +/* in heap/heapam.c */ +extern Relation relation_open(Oid relationId, LOCKMODE lockmode, int2 bucketId=-1); +extern Partition partitionOpenWithRetry(Relation relation, Oid partitionId, LOCKMODE lockmode, const char * stmt); +extern Partition partitionOpen(Relation relation, Oid partitionId, LOCKMODE lockmode, int2 bucketId=-1); +extern void partitionClose(Relation relation, Partition partition, LOCKMODE lockmode); +extern Partition tryPartitionOpen(Relation relation, Oid partitionId, LOCKMODE lockmode); +extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode); +extern Relation relation_openrv(const RangeVar* relation, LOCKMODE lockmode); +extern Relation relation_openrv_extended(const RangeVar* relation, LOCKMODE lockmode, bool missing_ok, + bool isSupportSynonym = false, StringInfo detailInfo = NULL); +extern void relation_close(Relation relation, LOCKMODE lockmode); +#define bucketCloseRelation(bucket) releaseDummyRelation(&(bucket)) +extern Relation bucketGetRelation(Relation rel, Partition part, int2 bucketId); +extern Relation heap_open(Oid relationId, LOCKMODE lockmode, int2 bucketid=-1); +extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode); +extern Relation heap_openrv_extended(const RangeVar* relation, LOCKMODE lockmode, bool missing_ok, + bool isSupportSynonym = false, StringInfo detailInfo = NULL); +extern Partition bucketGetPartition(Partition part, int2 bucketid); +extern void bucketClosePartition(Partition bucket); + +#define heap_close(r,l) relation_close(r,l) + +/* struct definition appears in relscan.h */ +typedef struct HeapScanDescData* HeapScanDesc; + +/* + * HeapScanIsValid + * True iff the heap scan is valid. + */ +#define HeapScanIsValid(scan) PointerIsValid(scan) + +extern TableScanDesc heap_beginscan( + Relation relation, Snapshot snapshot, int nkeys, ScanKey key, RangeScanInRedis rangeScanInRedis = {false,0,0}); +extern TableScanDesc heap_beginscan_strat( + Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync); +extern TableScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key); +extern TableScanDesc heap_beginscan_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis); + +extern void heapgetpage(TableScanDesc scan, BlockNumber page); + +extern void heap_rescan(TableScanDesc sscan, ScanKey key); +extern void heap_endscan(TableScanDesc scan); +extern HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction); + +extern void heap_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir); + +extern HeapTuple heapGetNextForVerify(TableScanDesc scan, ScanDirection direction, bool& isValidRelationPage); +extern bool heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation); +extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, Snapshot snapshot, + HeapTuple heapTuple, HeapTupleHeaderData* uncompressTup, bool* all_dead, bool first_call); +extern bool heap_hot_search(ItemPointer tid, Relation relation, Snapshot snapshot, bool* all_dead); + +extern void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid); + +extern void setLastTid(const ItemPointer tid); +extern void heap_get_max_tid(Relation rel, ItemPointer ctid); + +extern BulkInsertState GetBulkInsertState(void); +extern void FreeBulkInsertState(BulkInsertState); + +extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid, int options, BulkInsertState bistate); +extern void heap_abort_speculative(Relation relation, HeapTuple tuple); +extern bool heap_page_prepare_for_xid( + Relation relation, Buffer buffer, TransactionId xid, bool multi, bool pageReplication = false); +extern bool heap_change_xidbase_after_freeze(Relation relation, Buffer buffer); + +extern bool rewrite_page_prepare_for_xid(Page page, TransactionId xid, bool multi); +extern int heap_multi_insert(Relation relation, Relation parent, HeapTuple* tuples, int ntuples, CommandId cid, int options, + BulkInsertState bistate, HeapMultiInsertExtraArgs* args); +extern TM_Result heap_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, + bool wait, TM_FailureData *tmfd, bool allow_delete_self = false); +extern TM_Result heap_update(Relation relation, Relation parentRelation, ItemPointer otid, HeapTuple newtup, + CommandId cid, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool allow_delete_self = false); +extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer* buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, bool allow_lock_self = false); + +extern void heap_inplace_update(Relation relation, HeapTuple tuple); +extern bool heap_freeze_tuple(HeapTuple tuple, TransactionId cutoff_xid); +extern bool heap_tuple_needs_freeze(HeapTuple tuple, TransactionId cutoff_xid, Buffer buf); + +extern Oid simple_heap_insert(Relation relation, HeapTuple tup); +extern void simple_heap_delete(Relation relation, ItemPointer tid, int options = 0); +extern void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup); + +extern void heap_markpos(TableScanDesc scan); +extern void heap_restrpos(TableScanDesc scan); + +extern void heap_sync(Relation relation, LOCKMODE lockmode = RowExclusiveLock); + +extern void partition_sync(Relation rel, Oid partitionId, LOCKMODE toastLockmode); + +extern void heap_redo(XLogReaderState* rptr); +extern void heap_desc(StringInfo buf, XLogReaderState* record); +extern void heap2_redo(XLogReaderState* rptr); +extern void heap2_desc(StringInfo buf, XLogReaderState* record); +extern void heap3_redo(XLogReaderState* rptr); +extern void heap3_desc(StringInfo buf, XLogReaderState* record); +extern void heap_bcm_redo(xl_heap_bcm* xlrec, RelFileNode node, XLogRecPtr lsn); + +extern bool heap_page_upgrade(Relation relation, Buffer buffer); +extern void heap_page_upgrade_nocheck(Relation relation, Buffer buffer); + +extern XLogRecPtr log_heap_cleanup_info(const RelFileNode* rnode, TransactionId latestRemovedXid); +extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer, OffsetNumber* redirected, int nredirected, + OffsetNumber* nowdead, int ndead, OffsetNumber* nowunused, int nunused, TransactionId latestRemovedXid, + bool repair_fragmentation); +extern XLogRecPtr log_heap_freeze( + Relation reln, Buffer buffer, TransactionId cutoff_xid, OffsetNumber* offsets, int offcnt); +extern XLogRecPtr log_heap_visible(RelFileNode rnode, BlockNumber block, Buffer heap_buffer, Buffer vm_buffer, + TransactionId cutoff_xid, bool free_dict); +extern XLogRecPtr log_cu_bcm(const RelFileNode* rnode, int col, uint64 block, int status, int count); +extern XLogRecPtr log_heap_bcm(const RelFileNode* rnode, int col, uint64 block, int status); +extern XLogRecPtr log_newpage(RelFileNode* rnode, ForkNumber forkNum, BlockNumber blk, Page page, bool page_std); +extern XLogRecPtr log_logical_newpage( + RelFileNode* rnode, ForkNumber forkNum, BlockNumber blk, Page page, Buffer buffer); +extern XLogRecPtr log_logical_newcu( + RelFileNode* rnode, ForkNumber forkNum, int attid, Size offset, int size, char* cuData); +extern XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std); +/* in heap/pruneheap.c */ +extern void heap_page_prune_opt(Relation relation, Buffer buffer); +extern int heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, bool report_stats, + TransactionId* latestRemovedXid, bool repairFragmentation); +extern void heap_page_prune_execute(Page page, OffsetNumber* redirected, int nredirected, OffsetNumber* nowdead, + int ndead, OffsetNumber* nowunused, int nunused, bool repairFragmentation); +extern void heap_get_root_tuples(Page page, OffsetNumber* root_offsets); + +extern IndexFetchTableData * heapam_index_fetch_begin(Relation rel); +extern void heapam_index_fetch_reset(IndexFetchTableData *scan); +extern void heapam_index_fetch_end(IndexFetchTableData *scan); +extern HeapTuple heapam_index_fetch_tuple(IndexScanDesc scan, bool *all_dead); + +/* in heap/syncscan.c */ +extern void ss_report_location(Relation rel, BlockNumber location); +extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks); +extern void SyncScanShmemInit(void); +extern Size SyncScanShmemSize(void); + +extern void PushHeapPageToDataQueue(Buffer buffer); + +/* + * HeapTupleSatisfiesVisibility + * True iff heap tuple satisfies a time qual. + * + * Notes: + * Assumes heap tuple is valid. + * Beware of multiple evaluations of snapshot argument. + * Hint bits in the HeapTuple's t_infomask may be updated as a side effect; + * if so, the indicated buffer is marked dirty. + */ +extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot, Buffer buffer); + +/* Result codes for HeapTupleSatisfiesVacuum */ +typedef enum { + HEAPTUPLE_DEAD, /* tuple is dead and deletable */ + HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */ + HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */ + HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */ + HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */ +} HTSV_Result; + +/* Special "satisfies" routines with different APIs */ +extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid, Buffer buffer, bool self_visible = false); +extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer, bool isAnalyzing = false); +extern bool HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin); +extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer, uint16 infomask, TransactionId xid); + +/* + * To avoid leaking to much knowledge about reorderbuffer implementation + * details this is implemented in reorderbuffer.c not tqual.c. + */ +extern bool ResolveCminCmaxDuringDecoding( + struct HTAB* tuplecid_data, Snapshot snapshot, HeapTuple htup, Buffer buffer, CommandId* cmin, CommandId* cmax); + +#endif /* HEAPAM_H */ diff -uprN postgresql-hll-2.14_old/include/access/hio.h postgresql-hll-2.14/include/access/hio.h --- postgresql-hll-2.14_old/include/access/hio.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/hio.h 2020-12-12 17:06:43.062345651 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * hio.h + * POSTGRES heap access method input/output definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hio.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HIO_H +#define HIO_H + +#include "access/heapam.h" +#include "access/htup.h" +#include "utils/relcache.h" +#include "storage/buf.h" + +/* + * state for bulk inserts --- private to heapam.c and hio.c + * + * If current_buf isn't InvalidBuffer, then we are holding an extra pin + * on that buffer. + * + * "typedef struct BulkInsertStateData *BulkInsertState" is in heapam.h + */ +typedef struct BulkInsertStateData { + BufferAccessStrategy strategy; /* our BULKWRITE strategy object */ + Buffer current_buf; /* current insertion target page */ +} BulkInsertStateData; + +extern void RelationPutHeapTuple(Relation relation, Buffer buffer, HeapTuple tuple, TransactionId xid); +extern Buffer RelationGetBufferForTuple(Relation relation, Size len, Buffer otherBuffer, int options, + BulkInsertState bistate, Buffer* vmbuffer, Buffer* vmbuffer_other, BlockNumber end_rel_block); +extern Buffer RelationGetNewBufferForBulkInsert(Relation relation, Size len, Size dictSize, BulkInsertState bistate); +extern void RelationAddExtraBlocks(Relation relation, BulkInsertState bistate); + +#endif /* HIO_H */ diff -uprN postgresql-hll-2.14_old/include/access/htup.h postgresql-hll-2.14/include/access/htup.h --- postgresql-hll-2.14_old/include/access/htup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/htup.h 2020-12-12 17:06:43.063345664 +0800 @@ -0,0 +1,1153 @@ +/* ------------------------------------------------------------------------- + * + * htup.h + * POSTGRES heap tuple definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/htup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HTUP_H +#define HTUP_H + +#include "access/tupdesc.h" +#include "access/tupmacs.h" +#include "access/xlogreader.h" +#include "storage/buf.h" +#include "storage/bufpage.h" +#include "storage/itemptr.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + + /* Number of internal columns added by Redis during scale-in/scale-out. */ +#define REDIS_NUM_INTERNAL_COLUMNS (4) + +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFFFFFFFFF) /* First four bits reserved */ +#define MaxShortTransactionId ((TransactionId)0xFFFFFFFF) + +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) + +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +#define ShortTransactionIdToNormal(base, xid) \ + (TransactionIdIsNormal(xid) ? (TransactionId)(xid) + (base) : (TransactionId)(xid)) +#define NormalTransactionIdToShort(base, xid) \ + (TransactionIdIsNormal(xid) ? (ShortTransactionId)(AssertMacro((xid) >= (base) + FirstNormalTransactionId), \ + AssertMacro((xid) <= (base) + MaxShortTransactionId), \ + (xid) - (base)) \ + : (ShortTransactionId)(xid)) + +/* + * MaxTupleAttributeNumber limits the number of (user) columns in a tuple. + * The key limit on this value is that the size of the fixed overhead for + * a tuple, plus the size of the null-values bitmap (at 1 bit per column), + * plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most + * machines the upper limit without making t_hoff wider would be a little + * over 1700. We use round numbers here and for MaxHeapAttributeNumber + * so that alterations in HeapTupleHeaderData layout won't change the + * supported max number of columns. + */ +#define MaxTupleAttributeNumber 1664 /* 8 * 208 */ + +/* + * MaxHeapAttributeNumber limits the number of (user) columns in a table. + * This should be somewhat less than MaxTupleAttributeNumber. It must be + * at least one less, else we will fail to do UPDATEs on a maximal-width + * table (because UPDATE has to form working tuples that include CTID). + * In practice we want some additional daylight so that we can gracefully + * support operations that add hidden "resjunk" columns, for example + * SELECT * FROM wide_table ORDER BY foo, bar, baz. + * In any case, depending on column data types you will likely be running + * into the disk-block-based limit on overall tuple size if you have more + * than a thousand or so columns. TOAST won't help. + */ +#define MaxHeapAttributeNumber 1600 /* 8 * 200 */ + +/* + * Heap tuple header. To avoid wasting space, the fields should be + * laid out in such a way as to avoid structure padding. + * + * Datums of composite types (row types) share the same general structure + * as on-disk tuples, so that the same routines can be used to build and + * examine them. However the requirements are slightly different: a Datum + * does not need any transaction visibility information, and it does need + * a length word and some embedded type information. We can achieve this + * by overlaying the xmin/cmin/xmax/cmax/xvac fields of a heap tuple + * with the fields needed in the Datum case. Typically, all tuples built + * in-memory will be initialized with the Datum fields; but when a tuple is + * about to be inserted in a table, the transaction fields will be filled, + * overwriting the datum fields. + * + * The overall structure of a heap tuple looks like: + * fixed fields (HeapTupleHeaderData struct) + * nulls bitmap (if HEAP_HASNULL is set in t_infomask) + * alignment padding (as needed to make user data MAXALIGN'd) + * object ID (if HEAP_HASOID is set in t_infomask) + * user data fields + * + * We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac in three + * physical fields. Xmin and Xmax are always really stored, but Cmin, Cmax + * and Xvac share a field. This works because we know that Cmin and Cmax + * are only interesting for the lifetime of the inserting and deleting + * transaction respectively. If a tuple is inserted and deleted in the same + * transaction, we store a "combo" command id that can be mapped to the real + * cmin and cmax, but only by use of local state within the originating + * backend. See combocid.c for more details. Meanwhile, Xvac is only set by + * old-style VACUUM FULL, which does not have any command sub-structure and so + * does not need either Cmin or Cmax. (This requires that old-style VACUUM + * FULL never try to move a tuple whose Cmin or Cmax is still interesting, + * ie, an insert-in-progress or delete-in-progress tuple.) + * + * A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid + * is initialized with its own TID (location). If the tuple is ever updated, + * its t_ctid is changed to point to the replacement version of the tuple. + * Thus, a tuple is the latest version of its row iff XMAX is invalid or + * t_ctid points to itself (in which case, if XMAX is valid, the tuple is + * either locked or deleted). One can follow the chain of t_ctid links + * to find the newest version of the row. Beware however that VACUUM might + * erase the pointed-to (newer) tuple before erasing the pointing (older) + * tuple. Hence, when following a t_ctid link, it is necessary to check + * to see if the referenced slot is empty or contains an unrelated tuple. + * Check that the referenced tuple has XMIN equal to the referencing tuple's + * XMAX to verify that it is actually the descendant version and not an + * unrelated tuple stored into a slot recently freed by VACUUM. If either + * check fails, one may assume that there is no live descendant version. + * + * Following the fixed header fields, the nulls bitmap is stored (beginning + * at t_bits). The bitmap is *not* stored if t_infomask shows that there + * are no nulls in the tuple. If an OID field is present (as indicated by + * t_infomask), then it is stored just before the user data, which begins at + * the offset shown by t_hoff. Note that t_hoff must be a multiple of + * MAXALIGN. + */ + +typedef struct HeapTupleFields { + ShortTransactionId t_xmin; /* inserting xact ID */ + ShortTransactionId t_xmax; /* deleting or locking xact ID */ + + union { + CommandId t_cid; /* inserting or deleting command ID, or both */ + ShortTransactionId t_xvac; /* old-style VACUUM FULL xact ID */ + } t_field3; +} HeapTupleFields; + +typedef struct DatumTupleFields { + int32 datum_len_; /* varlena header (do not touch directly!) */ + + int32 datum_typmod; /* -1, or identifier of a record type */ + + Oid datum_typeid; /* composite type OID, or RECORDOID */ + + /* + * Note: field ordering is chosen with thought that Oid might someday + * widen to 64 bits. + */ +} DatumTupleFields; + +typedef struct HeapTupleHeaderData { + union { + HeapTupleFields t_heap; + DatumTupleFields t_datum; + } t_choice; + + ItemPointerData t_ctid; /* current TID of this or newer tuple */ + + /* Fields below here must match MinimalTupleData! */ + + uint16 t_infomask2; /* number of attributes + various flags */ + + uint16 t_infomask; /* various flag bits, see below */ + + uint8 t_hoff; /* sizeof header incl. bitmap, padding */ + + /* ^ - 23 bytes - ^ */ + + bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs -- VARIABLE LENGTH */ + + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} HeapTupleHeaderData; +typedef HeapTupleHeaderData* HeapTupleHeader; + +#define SizeofMinimalTupleHeader offsetof(MinimalTupleData, t_bits) +#define SizeofHeapTupleHeader offsetof(HeapTupleHeaderData, t_bits) + +/* + * information stored in t_infomask: + */ +#define HEAP_HASNULL 0x0001 /* has null attribute(s) */ +#define HEAP_HASVARWIDTH 0x0002 /* has variable-width attribute(s) */ +#define HEAP_HASEXTERNAL 0x0004 /* has external stored attribute(s) */ +#define HEAP_HASOID 0x0008 /* has an object-id field */ +#define HEAP_COMPRESSED 0x0010 /* has compressed data */ +#define HEAP_COMBOCID 0x0020 /* t_cid is a combo cid */ +#define HEAP_XMAX_EXCL_LOCK 0x0040 /* xmax is exclusive locker */ +#define HEAP_XMAX_SHARED_LOCK 0x0080 /* xmax is shared locker */ +/* if either LOCK bit is set, xmax hasn't deleted the tuple, only locked it */ +#define HEAP_IS_LOCKED (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_SHARED_LOCK) +#define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */ +#define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */ +#define HEAP_XMIN_FROZEN (HEAP_XMIN_INVALID | HEAP_XMIN_COMMITTED) +#define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */ +#define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */ +#define HEAP_XMAX_IS_MULTI 0x1000 /* t_xmax is a MultiXactId */ +#define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */ +#define HEAP_MOVED_OFF \ + 0x4000 /* moved to another place by pre-9.0 \ + * VACUUM FULL; kept for binary \ + * upgrade support */ +#define HEAP_MOVED_IN \ + 0x8000 /* moved from another place by pre-9.0 \ + * VACUUM FULL; kept for binary \ + * upgrade support */ +#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN) + +#define HEAP_XACT_MASK 0xFFE0 /* visibility-related bits */ + +/* + * information stored in t_infomask2: + */ +#define HEAP_NATTS_MASK 0x07FF /* 11 bits for number of attributes */ +/* bits 0x1800 are available */ +#define HEAP_HAS_REDIS_COLUMNS 0x2000 /* tuple has hidden columns added by redis */ +#define HEAP_HOT_UPDATED 0x4000 /* tuple was HOT-updated */ +#define HEAP_ONLY_TUPLE 0x8000 /* this is heap-only tuple */ + +#define HEAP2_XACT_MASK 0xC000 /* visibility-related bits */ + +/* + * HEAP_TUPLE_HAS_MATCH is a temporary flag used during hash joins. It is + * only used in tuples that are in the hash table, and those don't need + * any visibility information, so we can overlay it on a visibility flag + * instead of using up a dedicated bit. + */ +#define HEAP_TUPLE_HAS_MATCH HEAP_ONLY_TUPLE /* tuple has a join match */ + +/* + * HeapTupleHeader accessor macros + * + * Note: beware of multiple evaluations of "tup" argument. But the Set + * macros evaluate their other argument only once. + */ +/* + * HeapTupleHeaderGetRawXmin returns the "raw" xmin field, which is the xid + * originally used to insert the tuple. However, the tuple might actually + * be frozen (via HeapTupleHeaderSetXminFrozen) in which case the tuple's xmin + * is visible to every snapshot. Prior to PostgreSQL 9.4, we actually changed + * the xmin to FrozenTransactionId, and that value may still be encountered + * on disk. + */ + +#define HeapTupleCopyBaseFromPage(tup, page) \ + { \ + if (PageIs8BXidHeapVersion(page)) { \ + (tup)->t_xid_base = ((HeapPageHeader)(page))->pd_xid_base; \ + (tup)->t_multi_base = ((HeapPageHeader)(page))->pd_multi_base; \ + } else { \ + (tup)->t_xid_base = 0; \ + (tup)->t_multi_base = 0; \ + } \ + } + +#define HeapTupleCopyBase(dest, src) \ + do { \ + (dest)->t_xid_base = (src)->t_xid_base; \ + (dest)->t_multi_base = (src)->t_multi_base; \ + } while (0) + +#define HeapTupleSetZeroBase(tup) \ + { \ + (tup)->t_xid_base = InvalidTransactionId; \ + (tup)->t_multi_base = InvalidTransactionId; \ + } +#define HeapTupleHeaderXminCommitted(tup) ((tup)->t_infomask & HEAP_XMIN_COMMITTED) + +#define HeapTupleHeaderXminInvalid(tup) \ + (((tup)->t_infomask & (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)) == HEAP_XMIN_INVALID) +#define HeapTupleHeaderGetXmin(page, tup) \ + (ShortTransactionIdToNormal( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, (tup)->t_choice.t_heap.t_xmin)) +#define HeapTupleHeaderGetRawXmax(page, tup) HeapTupleHeaderGetXmax(page, tup) +#define HeapTupleGetRawXmin(tup) (ShortTransactionIdToNormal((tup)->t_xid_base, (tup)->t_data->t_choice.t_heap.t_xmin)) + +#define HeapTupleHeaderXminInvalid(tup) \ + (((tup)->t_infomask & (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)) == HEAP_XMIN_INVALID) + +#define HeapTupleHeaderXminFrozen(tup) (((tup)->t_infomask & (HEAP_XMIN_FROZEN)) == HEAP_XMIN_FROZEN) + +#define HeapTupleHeaderSetXminCommitted(tup) \ + (AssertMacro(!HeapTupleHeaderXminInvalid(tup)), ((tup)->t_infomask |= HEAP_XMIN_COMMITTED)) + +#define HeapTupleHeaderSetXminInvalid(tup) \ + (AssertMacro(!HeapTupleHeaderXminCommitted(tup)), ((tup)->t_infomask |= HEAP_XMIN_INVALID)) + +#define HeapTupleHeaderSetXminFrozen(tup) \ + (AssertMacro(!HeapTupleHeaderXminInvalid(tup)), ((tup)->t_infomask |= HEAP_XMIN_FROZEN)) + +#define HeapTupleGetRawXmax(tup) \ + (ShortTransactionIdToNormal( \ + ((tup)->t_data->t_infomask & HEAP_XMAX_IS_MULTI ? (tup)->t_multi_base: (tup)->t_xid_base), \ + ((tup)->t_data->t_choice.t_heap.t_xmax) \ + )) + +#define HeapTupleHeaderGetXmax(page, tup) \ + (ShortTransactionIdToNormal(((tup)->t_infomask & HEAP_XMAX_IS_MULTI) \ + ? (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_multi_base : 0) \ + : (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0), \ + ((tup)->t_choice.t_heap.t_xmax))) + +#define HeapTupleHeaderSetXmax(page, tup, xid) \ + ((tup)->t_choice.t_heap.t_xmax = NormalTransactionIdToShort( \ + (((tup)->t_infomask & HEAP_XMAX_IS_MULTI) \ + ? (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_multi_base : 0) \ + : (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0)), \ + (xid))) +#define HeapTupleHeaderSetXmin(page, tup, xid) \ + ((tup)->t_choice.t_heap.t_xmin = NormalTransactionIdToShort( \ + (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0), (xid))) + +#define HeapTupleSetXmax(tup, xid) \ + ((tup)->t_data->t_choice.t_heap.t_xmax = NormalTransactionIdToShort( \ + ((tup)->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ? tup->t_multi_base : tup->t_xid_base, (xid))) + +#define HeapTupleSetXmin(tup, xid) \ + ((tup)->t_data->t_choice.t_heap.t_xmin = NormalTransactionIdToShort(tup->t_xid_base, (xid))) + +/* + * HeapTupleHeaderGetRawCommandId will give you what's in the header whether + * it is useful or not. Most code should use HeapTupleHeaderGetCmin or + * HeapTupleHeaderGetCmax instead, but note that those Assert that you can + * get a legitimate result, ie you are in the originating transaction! + */ +#define HeapTupleHeaderGetRawCommandId(tup) ((tup)->t_choice.t_heap.t_field3.t_cid) + +/* SetCmin is reasonably simple since we never need a combo CID */ +#define HeapTupleHeaderSetCmin(tup, cid) \ + do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ + (tup)->t_infomask &= ~HEAP_COMBOCID; \ + } while (0) + +/* SetCmax must be used after HeapTupleHeaderAdjustCmax; see combocid.c */ +#define HeapTupleHeaderSetCmax(tup, cid, iscombo) \ + do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ + if (iscombo) \ + (tup)->t_infomask |= HEAP_COMBOCID; \ + else \ + (tup)->t_infomask &= ~HEAP_COMBOCID; \ + } while (0) + +#define HeapTupleHeaderGetDatumLength(tup) VARSIZE(tup) + +#define HeapTupleHeaderSetDatumLength(tup, len) SET_VARSIZE(tup, len) + +#define HeapTupleHeaderGetTypeId(tup) ((tup)->t_choice.t_datum.datum_typeid) + +#define HeapTupleHeaderSetTypeId(tup, typeid) ((tup)->t_choice.t_datum.datum_typeid = (typeid)) + +#define HeapTupleHeaderGetTypMod(tup) ((tup)->t_choice.t_datum.datum_typmod) + +#define HeapTupleHeaderSetTypMod(tup, typmod) ((tup)->t_choice.t_datum.datum_typmod = (typmod)) + +#define HeapTupleHeaderGetOid(tup) \ + (((tup)->t_infomask & HEAP_HASOID) ? *((Oid*)((char*)(tup) + (tup)->t_hoff - sizeof(Oid))) : InvalidOid) + +#define HeapTupleHeaderSetOid(tup, oid) \ + do { \ + Assert((tup)->t_infomask& HEAP_HASOID); \ + *((Oid*)((char*)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid); \ + } while (0) + +#define HeapTupleHeaderHasOid(tup) (((tup)->t_infomask & HEAP_HASOID) != 0) + +/* + * Note that we stop considering a tuple HOT-updated as soon as it is known + * aborted or the would-be updating transaction is known aborted. For best + * efficiency, check tuple visibility before using this macro, so that the + * INVALID bits will be as up to date as possible. + */ +#define HeapTupleHeaderIsHotUpdated(tup) \ + (((tup)->t_infomask2 & HEAP_HOT_UPDATED) != 0 && ((tup)->t_infomask & HEAP_XMAX_INVALID) == 0 && \ + !HeapTupleHeaderXminInvalid(tup)) + +#define HeapTupleHeaderSetHotUpdated(tup) ((tup)->t_infomask2 |= HEAP_HOT_UPDATED) + +#define HeapTupleHeaderClearHotUpdated(tup) ((tup)->t_infomask2 &= ~HEAP_HOT_UPDATED) + +#define HeapTupleHeaderIsHeapOnly(tup) (((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0) + +#define HeapTupleHeaderSetHeapOnly(tup) ((tup)->t_infomask2 |= HEAP_ONLY_TUPLE) + +#define HeapTupleHeaderClearHeapOnly(tup) ((tup)->t_infomask2 &= ~HEAP_ONLY_TUPLE) + +#define HeapTupleHeaderHasRedisColumns(tup) (((tup)->t_infomask2 & HEAP_HAS_REDIS_COLUMNS) != 0) + +#define HeapTupleHeaderSetRedisColumns(tup) ((tup)->t_infomask2 |= HEAP_HAS_REDIS_COLUMNS) + +#define HeapTupleHeaderUnsetRedisColumns(tup) ((tup)->t_infomask2 &= ~HEAP_HAS_REDIS_COLUMNS) + +#define HeapTupleHeaderHasMatch(tup) (((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0) + +#define HeapTupleHeaderSetMatch(tup) ((tup)->t_infomask2 |= HEAP_TUPLE_HAS_MATCH) + +#define HeapTupleHeaderClearMatch(tup) ((tup)->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH) + +/* + * Tuple Descriptor is added to ignore the hidden columns added by redis (if any) + * from the tuple. + */ +static inline uint32 HeapTupleHeaderGetNatts(HeapTupleHeader tup, TupleDesc tup_desc) +{ + Assert(tup != NULL); + uint32 natts = (tup->t_infomask2 & HEAP_NATTS_MASK); + + /* + * If the tuple header has HEAP_HAS_REDIS_COLUMNS bit set, it means that the + * tuple has values for the REDIS_NUM_INTERNAL_COLUMNS added by redis. + * These column values are valid only for the duration of table redistribution. + * Once the table redistribution is completed (the relation is not + * REDIS_REL_DESTINATION anymore), these column values must be ignored from + * the tuple. + */ + if (HeapTupleHeaderHasRedisColumns(tup) && tup_desc && !tup_desc->tdisredistable) { + Assert(natts >= REDIS_NUM_INTERNAL_COLUMNS); + natts -= REDIS_NUM_INTERNAL_COLUMNS; + } + + return natts; +} + +#define HeapTupleHeaderSetNatts(tup, natts) ((tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts)) + +/* tuple' compression macro */ +#define HEAP_TUPLE_SET_COMPRESSED(tup) ((tup)->t_infomask |= HEAP_COMPRESSED) + +#define HEAP_TUPLE_IS_COMPRESSED(tup) (((tup)->t_infomask & HEAP_COMPRESSED) != 0) + +#define HEAP_TUPLE_CLEAR_COMPRESSED(tup) ((tup)->t_infomask &= ~HEAP_COMPRESSED) + +/* Struct for forming compressed tuple. + * + * compressed: comppressed flag for each attribute in one tuple. + * delta/prefix/dict values are mixed in values of heapFormTuple(desc, values, isnulls, void*) + * delta compression: --> char* delta, whose size is in valsize[] + * prefix compression: --> char* ended with '\0', whose size is in valsize[] + * dict compression: --> the index of dict item, whose size is in valsize[] + */ +typedef struct { + bool* isnulls; + bool* compressed; + Datum* values; + int* valsize; +} FormCmprTupleData; + +/* + * BITMAPLEN(NATTS) - + * Computes size of null bitmap given number of data columns. + */ +#define BITMAPLEN(NATTS) (((int)(NATTS) + 7) / 8) + +/* + * MaxHeapTupleSize is the maximum allowed size of a heap tuple, including + * header and MAXALIGN alignment padding. Basically it's BLCKSZ minus the + * other stuff that has to be on a disk page. Since heap pages use no + * "special space", there's no deduction for that. + * + * NOTE: we allow for the ItemId that must point to the tuple, ensuring that + * an otherwise-empty page can indeed hold a tuple of this size. Because + * ItemIds and tuples have different alignment requirements, don't assume that + * you can, say, fit 2 tuples of size MaxHeapTupleSize/2 on the same page. + */ +#define MaxHeapTupleSize (BLCKSZ - MAXALIGN(SizeOfHeapPageHeaderData + sizeof(ItemIdData))) +#define MinHeapTupleSize MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + +/* + * MaxHeapTuplesPerPage is an upper bound on the number of tuples that can + * fit on one heap page. (Note that indexes could have more, because they + * use a smaller tuple header.) We arrive at the divisor because each tuple + * must be maxaligned, and it must have an associated item pointer. + * + * Note: with HOT, there could theoretically be more line pointers (not actual + * tuples) than this on a heap page. However we constrain the number of line + * pointers to this anyway, to avoid excessive line-pointer bloat and not + * require increases in the size of work arrays. + */ +#define MaxHeapTuplesPerPage \ + ((int)((BLCKSZ - SizeOfHeapPageHeaderData) / \ + (MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData)))) + +/* + * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of + * data fields of char(n) and similar types. It need not have anything + * directly to do with the *actual* upper limit of varlena values, which + * is currently 1Gb (see TOAST structures in postgres.h). I've set it + * at 10Mb which seems like a reasonable number --- tgl 8/6/00. + */ +#define MaxAttrSize (10 * 1024 * 1024) + +/* + * MinimalTuple is an alternative representation that is used for transient + * tuples inside the executor, in places where transaction status information + * is not required, the tuple rowtype is known, and shaving off a few bytes + * is worthwhile because we need to store many tuples. The representation + * is chosen so that tuple access routines can work with either full or + * minimal tuples via a HeapTupleData pointer structure. The access routines + * see no difference, except that they must not access the transaction status + * or t_ctid fields because those aren't there. + * + * For the most part, MinimalTuples should be accessed via TupleTableSlot + * routines. These routines will prevent access to the "system columns" + * and thereby prevent accidental use of the nonexistent fields. + * + * MinimalTupleData contains a length word, some padding, and fields matching + * HeapTupleHeaderData beginning with t_infomask2. The padding is chosen so + * that offsetof(t_infomask2) is the same modulo MAXIMUM_ALIGNOF in both + * structs. This makes data alignment rules equivalent in both cases. + * + * When a minimal tuple is accessed via a HeapTupleData pointer, t_data is + * set to point MINIMAL_TUPLE_OFFSET bytes before the actual start of the + * minimal tuple --- that is, where a full tuple matching the minimal tuple's + * data would start. This trick is what makes the structs seem equivalent. + * + * Note that t_hoff is computed the same as in a full tuple, hence it includes + * the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however. + * + * MINIMAL_TUPLE_DATA_OFFSET is the offset to the first useful (non-pad) data + * other than the length word. tuplesort.c and tuplestore.c use this to avoid + * writing the padding to disk. + */ +#define MINIMAL_TUPLE_OFFSET \ + ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF) +#define MINIMAL_TUPLE_PADDING ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF) +#define MINIMAL_TUPLE_DATA_OFFSET offsetof(MinimalTupleData, t_infomask2) + +typedef struct MinimalTupleData { + uint32 t_len; /* actual length of minimal tuple */ + char mt_padding[MINIMAL_TUPLE_PADDING]; + + /* Fields below here must match HeapTupleHeaderData! */ + uint16 t_infomask2; /* number of attributes + various flags */ + + uint16 t_infomask; /* various flag bits, see below */ + + uint8 t_hoff; /* sizeof header incl. bitmap, padding */ + + /* ^ - 23 bytes - ^ */ + + bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs -- VARIABLE LENGTH */ + + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} MinimalTupleData; + +typedef MinimalTupleData* MinimalTuple; + +/* + * HeapTupleData is an in-memory data structure that points to a tuple. + * + * There are several ways in which this data structure is used: + * + * * Pointer to a tuple in a disk buffer: t_data points directly into the + * buffer (which the code had better be holding a pin on, but this is not + * reflected in HeapTupleData itself). + * + * * Pointer to nothing: t_data is NULL. This is used as a failure indication + * in some functions. + * + * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple + * form a single palloc'd chunk. t_data points to the memory location + * immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE). + * This is the output format of heap_form_tuple and related routines. + * + * * Separately allocated tuple: t_data points to a palloc'd chunk that + * is not adjacent to the HeapTupleData. (This case is deprecated since + * it's difficult to tell apart from case #1. It should be used only in + * limited contexts where the code knows that case #1 will never apply.) + * + * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET + * bytes before the start of a MinimalTuple. As with the previous case, + * this can't be told apart from case #1 by inspection; code setting up + * or destroying this representation has to know what it's doing. + * + * t_len should always be valid, except in the pointer-to-nothing case. + * t_self and t_tableOid should be valid if the HeapTupleData points to + * a disk buffer, or if it represents a copy of a tuple on disk. They + * should be explicitly set invalid in manufactured tuples. + */ +typedef struct HeapTupleData { + uint32 tupTableType = HEAP_TUPLE; + uint32 t_len; /* length of *t_data */ + ItemPointerData t_self; /* SelfItemPointer */ + Oid t_tableOid; /* table the tuple came from */ + TransactionId t_xid_base; + TransactionId t_multi_base; +#ifdef PGXC + uint32 t_xc_node_id; /* Data node the tuple came from */ +#endif + HeapTupleHeader t_data; /* -> tuple header and data */ + int2 t_bucketId; +} HeapTupleData; + +typedef HeapTupleData* HeapTuple; +typedef void* Tuple; + +inline HeapTuple heaptup_alloc(Size size) +{ + HeapTuple tup = (HeapTuple)palloc0(size); + tup->tupTableType = HEAP_TUPLE; + return tup; +} + +#define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData)) + +/* + * GETSTRUCT - given a HeapTuple pointer, return address of the user data + */ +#define GETSTRUCT(TUP) ((char*)((TUP)->t_data) + (TUP)->t_data->t_hoff) + +/* + * Accessor macros to be used with HeapTuple pointers. + */ +#define HeapTupleIsValid(tuple) PointerIsValid(tuple) + +#define HeapTupleHasNulls(tuple) (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0) + +#define HeapTupleNoNulls(tuple) (!((tuple)->t_data->t_infomask & HEAP_HASNULL)) + +#define HeapTupleHasVarWidth(tuple) (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0) + +#define HeapTupleAllFixed(tuple) (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH)) + +#define HeapTupleHasExternal(tuple) (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0) + +#define HeapTupleIsHotUpdated(tuple) HeapTupleHeaderIsHotUpdated((tuple)->t_data) + +#define HeapTupleSetHotUpdated(tuple) HeapTupleHeaderSetHotUpdated((tuple)->t_data) + +#define HeapTupleClearHotUpdated(tuple) HeapTupleHeaderClearHotUpdated((tuple)->t_data) + +#define HeapTupleIsHeapOnly(tuple) HeapTupleHeaderIsHeapOnly((tuple)->t_data) + +#define HeapTupleSetHeapOnly(tuple) HeapTupleHeaderSetHeapOnly((tuple)->t_data) + +#define HeapTupleClearHeapOnly(tuple) HeapTupleHeaderClearHeapOnly((tuple)->t_data) + +#define HeapTupleGetOid(tuple) HeapTupleHeaderGetOid((tuple)->t_data) + +#define HeapTupleSetOid(tuple, oid) HeapTupleHeaderSetOid((tuple)->t_data, (oid)) + +/* + * WAL record definitions for heapam.c's WAL operations + * + * XLOG allows to store some information in high 4 bits of log + * record xl_info field. We use 3 for opcode and one for init bit. + */ +#define XLOG_HEAP_INSERT 0x00 +#define XLOG_HEAP_DELETE 0x10 +#define XLOG_HEAP_UPDATE 0x20 +#define XLOG_HEAP_BASE_SHIFT 0x30 +#define XLOG_HEAP_HOT_UPDATE 0x40 +#define XLOG_HEAP_NEWPAGE 0x50 +#define XLOG_HEAP_LOCK 0x60 +#define XLOG_HEAP_INPLACE 0x70 + +#define XLOG_HEAP_OPMASK 0x70 +/* + * When we insert 1st item on new page in INSERT, UPDATE, HOT_UPDATE, + * or MULTI_INSERT, we can (and we do) restore entire page in redo + */ +#define XLOG_HEAP_INIT_PAGE 0x80 +/* + * We ran out of opcodes, so heapam.c now has a second RmgrId. These opcodes + * are associated with RM_HEAP2_ID, but are not logically different from + * the ones above associated with RM_HEAP_ID. XLOG_HEAP_OPMASK applies to + * these, too. + */ +#define XLOG_HEAP2_FREEZE 0x00 +#define XLOG_HEAP2_CLEAN 0x10 +/* 0x20 is free, was XLOG_HEAP2_CLEAN_MOVE */ +#define XLOG_HEAP2_PAGE_UPGRADE 0x20 +#define XLOG_HEAP2_CLEANUP_INFO 0x30 +#define XLOG_HEAP2_VISIBLE 0x40 +#define XLOG_HEAP2_MULTI_INSERT 0x50 +#define XLOG_HEAP2_BCM 0x60 + +#define XLOG_HEAP2_LOGICAL_NEWPAGE 0x70 + +/* + * When we prune page, sometimes not call PageRepairFragmentation (e.g freeze_single_heap_page), + * so need a flag to notify the standby DN the PageRepairFragmentation is not required. + */ +#define XLOG_HEAP2_NO_REPAIR_PAGE 0x80 + +/* XLOG_HEAP_NEW_CID with 0x30 in heap is XLOGHEAP2_NEW_CID with 0x70 in heap2 in PG9.4 */ +#define XLOG_HEAP3_NEW_CID 0x00 +#define XLOG_HEAP3_REWRITE 0x10 + +/* we used to put all xl_heap_* together, which made us run out of opcodes (quickly) + * when trying to add a DELETE_IS_SUPER operation. Thus we split the codes carefully + * for INSERT, UPDATE, DELETE individually. each has 8 bits available to use. + */ +/* + * xl_heap_insert/xl_heap_multi_insert flag values, 8 bits are available + */ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_INSERT_ALL_VISIBLE_CLEARED (1<<0) +#define XLH_INSERT_CONTAINS_NEW_TUPLE (1<<4) +#define XLH_INSERT_LAST_IN_MULTI (1<<7) + +/* + * xl_heap_update flag values, 8 bits are available. +*/ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_UPDATE_OLD_ALL_VISIBLE_CLEARED (1<<0) +/* PD_ALL_VISIBLE was cleared in the 2nd page */ +#define XLH_UPDATE_NEW_ALL_VISIBLE_CLEARED (1<<1) +#define XLH_UPDATE_CONTAINS_OLD_TUPLE (1<<2) +#define XLH_UPDATE_CONTAINS_OLD_KEY (1<<3) +#define XLH_UPDATE_CONTAINS_NEW_TUPLE (1<<4) +#define XLH_UPDATE_PREFIX_FROM_OLD (1<<5) +#define XLH_UPDATE_SUFFIX_FROM_OLD (1<<6) + +/* convenience macro for checking whether any form of old tuple was logged */ +#define XLH_UPDATE_CONTAINS_OLD \ + (XLH_UPDATE_CONTAINS_OLD_TUPLE | XLH_UPDATE_CONTAINS_OLD_KEY) + +/* +* xl_heap_delete flag values, 8 bits are available. +*/ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_DELETE_ALL_VISIBLE_CLEARED (1<<0) +#define XLH_DELETE_IS_SUPER (1<<1) +#define XLH_DELETE_CONTAINS_OLD_TUPLE (1<<2) +#define XLH_DELETE_CONTAINS_OLD_KEY (1<<3) + +/* convenience macro for checking whether any form of old tuple was logged */ +#define XLH_DELETE_CONTAINS_OLD \ + (XLH_DELETE_CONTAINS_OLD_TUPLE | XLH_DELETE_CONTAINS_OLD_KEY) + +/* This is what we need to know about delete */ +typedef struct xl_heap_delete { + OffsetNumber offnum; /* deleted tuple's offset */ + uint8 flags; +} xl_heap_delete; + +#define SizeOfHeapDelete (offsetof(xl_heap_delete, flags) + sizeof(bool)) + +/* + * We don't store the whole fixed part (HeapTupleHeaderData) of an inserted + * or updated tuple in WAL; we can save a few bytes by reconstructing the + * fields that are available elsewhere in the WAL record, or perhaps just + * plain needn't be reconstructed. These are the fields we must store. + * NOTE: t_hoff could be recomputed, but we may as well store it because + * it will come for free due to alignment considerations. + */ +typedef struct xl_heap_header { + uint16 t_infomask2; + uint16 t_infomask; + uint8 t_hoff; +} xl_heap_header; + +#define SizeOfHeapHeader (offsetof(xl_heap_header, t_hoff) + sizeof(uint8)) + +/* This is what we need to know about insert */ +typedef struct xl_heap_insert { + OffsetNumber offnum; /* inserted tuple's offset */ + uint8 flags; + + /* xl_heap_header & TUPLE DATA in backup block 0 */ +} xl_heap_insert; + +#define SizeOfHeapInsert (offsetof(xl_heap_insert, flags) + sizeof(uint8)) + +/* + * This is what we need to know about a multi-insert. + * + * The main data of the record consists of this xl_heap_multi_insert header. + * 'offsets' array is omitted if the whole page is reinitialized + * (XLOG_HEAP_INIT_PAGE). + * + * If this block is compressed with dictionary, then this dictionary will follow + * header, but before tuples and + * tuples' data. indicates whether there is a dictionary. + * + * In block 0's data portion, there is an xl_multi_insert_tuple struct, + * followed by the tuple data for each tuple. There is padding to align + * each xl_multi_insert struct. + */ +typedef struct xl_heap_multi_insert { + uint8 flags; + bool isCompressed; + uint16 ntuples; + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} xl_heap_multi_insert; + +#define SizeOfHeapMultiInsert offsetof(xl_heap_multi_insert, offsets) + +typedef struct xl_multi_insert_tuple { + uint16 datalen; /* size of tuple data that follows */ + uint16 t_infomask2; + uint16 t_infomask; + uint8 t_hoff; + /* TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_multi_insert_tuple; + +#define SizeOfMultiInsertTuple (offsetof(xl_multi_insert_tuple, t_hoff) + sizeof(uint8)) + +/* + * This is what we need to know about update|hot_update + * + * Backup blk 0: new page + * + * If XLOG_HEAP_PREFIX_FROM_OLD or XLOG_HEAP_SUFFIX_FROM_OLD flags are set, + * the prefix and/or suffix come first, as one or two uint16s. + * + * After that, xl_heap_header and new tuple data follow. The new tuple + * data doesn't include the prefix and suffix, which are copied from the + * old tuple on replay. + * + * If HEAP_CONTAINS_NEW_TUPLE_DATA flag is given, the tuple data is + * included even if a full-page image was taken. + * + * Backup blk 1: old page, if different. (no data, just a reference to the blk) + */ +typedef struct xl_heap_update { + OffsetNumber old_offnum; /* old tuple's offset */ + OffsetNumber new_offnum; /* new tuple's offset */ + uint8 flags; /* NEW TUPLE xl_heap_header AND TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_heap_update; + +#define SizeOfHeapUpdate (offsetof(xl_heap_update, flags) + sizeof(uint8)) +/* + * This is what we need to know about vacuum page cleanup/redirect + * + * The array of OffsetNumbers following the fixed part of the record contains: + * * for each redirected item: the item offset, then the offset redirected to + * * for each now-dead item: the item offset + * * for each now-unused item: the item offset + * The total number of OffsetNumbers is therefore 2*nredirected+ndead+nunused. + * Note that nunused is not explicitly stored, but may be found by reference + * to the total record length. + */ +typedef struct xl_heap_clean { + TransactionId latestRemovedXid; + uint16 nredirected; + uint16 ndead; + /* OFFSET NUMBERS are in the block reference 0 */ +} xl_heap_clean; + +#define SizeOfHeapClean (offsetof(xl_heap_clean, ndead) + sizeof(uint16)) + +/* + * Cleanup_info is required in some cases during a lazy VACUUM. + * Used for reporting the results of HeapTupleHeaderAdvanceLatestRemovedXid() + * see vacuumlazy.c for full explanation + */ +typedef struct xl_heap_cleanup_info { + RelFileNodeOld node; + TransactionId latestRemovedXid; +} xl_heap_cleanup_info; + +#define SizeOfHeapCleanupInfo (sizeof(xl_heap_cleanup_info)) + +/* Logical xlog for multi_insert or new index when data replication store is row*/ +typedef struct xl_heap_logical_newpage { + RelFileNodeOld node; // relfilenode + BlockNumber blkno; // block number + ForkNumber forknum; + StorageEngine type; + bool hasdata; // flag of save cu xlog + int attid; // column id + Size offset; // CU offset + int32 blockSize; + /* Other infos?: offset datalen Row or column store */ +} xl_heap_logical_newpage; + +#define SizeOfHeapLogicalNewPage (offsetof(xl_heap_logical_newpage, blockSize) + sizeof(int32)) + +/* This is what we need to know about lock */ +typedef struct xl_heap_lock { + TransactionId locking_xid; /* might be a MultiXactId not xid */ + OffsetNumber offnum; /* locked tuple's offset on page */ + bool xid_is_mxact; /* is it? */ + bool shared_lock; /* shared or exclusive row lock? */ +} xl_heap_lock; + +#define SizeOfHeapLock (offsetof(xl_heap_lock, shared_lock) + sizeof(bool)) + +/* This is what we need to know about in-place update */ +typedef struct xl_heap_inplace { + OffsetNumber offnum; /* updated tuple's offset on page */ + /* TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_heap_inplace; + +#define SizeOfHeapInplace (offsetof(xl_heap_inplace, offnum) + sizeof(OffsetNumber)) + +/* + * This is what we need to know about a block being frozen during vacuum + * + * Backup block 0's data contains an array of xl_heap_freeze structs, + * one for each tuple. + */ +typedef struct xl_heap_freeze { + TransactionId cutoff_xid; + /* TUPLE OFFSET NUMBERS FOLLOW AT THE END */ +} xl_heap_freeze; + +#define SizeOfHeapFreeze (offsetof(xl_heap_freeze, cutoff_xid) + sizeof(TransactionId)) + +typedef struct xl_heap_freeze_tuple { + TransactionId xmax; + OffsetNumber offset; + uint16 t_infomask2; + uint16 t_infomask; + uint8 frzflags; +} xl_heap_freeze_tuple; + +/* + * This is what we need to know about setting a visibility map bit + * + * Backup blk 0: visibility map buffer + * Backup blk 1: heap buffer if exists (except partition merge) + */ +typedef struct xl_heap_visible { + BlockNumber block; + TransactionId cutoff_xid; + bool free_dict; /* dick will be checked and freed when switching visibility. */ +} xl_heap_visible; + +#define SizeOfHeapVisible (offsetof(xl_heap_visible, free_dict) + sizeof(bool)) + +/* This is what we need to know about setting a bcm map bit */ +typedef struct xl_heap_bcm { + RelFileNodeOld node; + uint32 col; + uint64 block; + int count; + int status; +} xl_heap_bcm; + +#define SizeOfHeapBcm (offsetof(xl_heap_bcm, status) + sizeof(int)) + +/* shift the base of xids on heap page */ +typedef struct xl_heap_base_shift { + int64 delta; /* delta value to shift the base */ + bool multi; /* true to shift multixact base */ +} xl_heap_base_shift; + +#define SizeOfHeapBaseShift (offsetof(xl_heap_base_shift, multi) + sizeof(bool)) + +typedef struct xl_heap_new_cid { + /* + * store toplevel xid so we don't have to merge cids from different + * transactions + */ + TransactionId top_xid; + CommandId cmin; + CommandId cmax; + CommandId combocid; /* just for debugging */ + + /* + * Store the relfilenode/ctid pair to facilitate lookups. + */ + RelFileNodeOld target_node; + ItemPointerData target_tid; +} xl_heap_new_cid; + +#define SizeOfHeapNewCid (offsetof(xl_heap_new_cid, target_tid) + sizeof(ItemPointerData)) + +/* logical rewrite xlog record header */ +typedef struct xl_heap_rewrite_mapping { + TransactionId mapped_xid; /* xid that might need to see the row */ + Oid mapped_db; /* DbOid or InvalidOid for shared rels */ + Oid mapped_rel; /* Oid of the mapped relation */ + off_t offset; /* How far have we written so far */ + uint32 num_mappings; /* Number of in-memory mappings */ + XLogRecPtr start_lsn; /* Insert LSN at begin of rewrite */ +} xl_heap_rewrite_mapping; +extern void HeapTupleHeaderAdvanceLatestRemovedXid(HeapTuple tuple, TransactionId* latestRemovedXid); + +/* HeapTupleHeader functions implemented in utils/time/combocid.c */ +extern CommandId HeapTupleGetCmin(HeapTuple tup); +extern CommandId HeapTupleGetCmax(HeapTuple tup); +extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup, Page page); +extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup, Page page); +extern bool CheckStreamCombocid(HeapTupleHeader tup, CommandId current_cid, Page page); +extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, CommandId* cmax, bool* iscombo, Buffer buffer); + +/* ---------------- + * fastgetattr && fastgetattr_with_dict + * + * Fetch a user attribute's value as a Datum (might be either a + * value, or a pointer into the data area of the tuple). + * + * This must not be used when a system attribute might be requested. + * Furthermore, the passed attnum MUST be valid. Use heap_getattr() + * instead, if in doubt. + * + * This gets called many times, so we macro the cacheable and NULL + * lookups, and call nocachegetattr() for the rest. + * ---------------- + */ + +#if !defined(DISABLE_COMPLEX_MACRO) + +#define fastgetattr(tup, attnum, tuple_desc, isnull) \ + (AssertMacro(!HEAP_TUPLE_IS_COMPRESSED((tup)->t_data)), \ + AssertMacro((attnum) > 0), \ + (*(isnull) = false), \ + HeapTupleNoNulls(tup) \ + ? ((tuple_desc)->attrs[(attnum)-1]->attcacheoff >= 0 \ + ? (fetchatt((tuple_desc)->attrs[(attnum)-1], \ + (char*)(tup)->t_data + (tup)->t_data->t_hoff + \ + (tuple_desc)->attrs[(attnum)-1]->attcacheoff)) \ + : nocachegetattr((tup), (attnum), (tuple_desc))) \ + : (att_isnull((attnum)-1, (tup)->t_data->t_bits) ? ((*(isnull) = true), (Datum)NULL) \ + : (nocachegetattr((tup), (attnum), (tuple_desc))))) + +#define fastgetattr_with_dict(tup, attnum, tuple_desc, isnull, page_dict) \ + (AssertMacro(HEAP_TUPLE_IS_COMPRESSED((tup)->t_data)), \ + AssertMacro((attnum) > 0), \ + (*(isnull) = false), \ + (HeapTupleHasNulls(tup) && att_isnull((attnum)-1, (tup)->t_data->t_bits)) \ + ? ((*(isnull) = true), (Datum)NULL) \ + : nocache_cmprs_get_attr(tup, attnum, tuple_desc, page_dict)) + +#else /* defined(DISABLE_COMPLEX_MACRO) */ + +extern Datum fastgetattr_with_dict(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool* isnull, char* pageDict); +extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool* isnull); +#endif /* defined(DISABLE_COMPLEX_MACRO) */ + +/* ---------------- + * heap_getattr + * + * Extract an attribute of a heap tuple and return it as a Datum. + * This works for either system or user attributes. The given attnum + * is properly range-checked. + * + * If the field in question has a NULL value, we return a zero Datum + * and set *isnull == true. Otherwise, we set *isnull == false. + * + * is the pointer to the heap tuple. is the attribute + * number of the column (field) caller wants. is a + * pointer to the structure describing the row and all its fields. + * ---------------- + */ +#define heap_getattr_with_dict(tup, attnum, tuple_desc, isnull, pagedict) \ + (((int)(attnum) > 0) ? (((int)(attnum) > (int)HeapTupleHeaderGetNatts((tup)->t_data, tuple_desc)) \ + ? (/* get init default value from tupleDesc.*/ \ + heapGetInitDefVal((attnum), (tuple_desc), (isnull))) \ + : (HEAP_TUPLE_IS_COMPRESSED((tup)->t_data) \ + ? (fastgetattr_with_dict((tup), (attnum), (tuple_desc), (isnull), (pagedict))) \ + : (fastgetattr((tup), (attnum), (tuple_desc), (isnull))))) \ + : heap_getsysattr((tup), (attnum), (tuple_desc), (isnull))) + +#define heap_getattr(tup, attnum, tuple_desc, isnull) heap_getattr_with_dict(tup, attnum, tuple_desc, isnull, NULL) + +/* prototypes for functions in common/heaptuple.c */ +extern Size heap_compute_data_size(TupleDesc tuple_desc, Datum* values, const bool* isnull); + +extern void heap_fill_tuple( + TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit); +extern bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tuple_desc); +extern Datum nocache_cmprs_get_attr(HeapTuple tuple, uint32 attnum, TupleDesc tuple_desc, char* page_dict); +extern Datum nocachegetattr(HeapTuple tup, uint32 attnum, TupleDesc att); +extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tuple_desc, bool* isnull); + +extern HeapTuple heap_copytuple(HeapTuple tuple); +extern HeapTuple heapCopyCompressedTuple(HeapTuple tuple, TupleDesc tup_desc, Page dict_page, HeapTuple dest = NULL); +extern HeapTuple heapCopyTuple(HeapTuple tuple, TupleDesc tup_desc, Page page); + +#define COPY_TUPLE_HEADERINFO(_dest_tup, _src_tup) \ + do { \ + (_dest_tup)->t_choice = (_src_tup)->t_choice; \ + (_dest_tup)->t_ctid = (_src_tup)->t_ctid; \ + (_dest_tup)->t_infomask2 = (_src_tup)->t_infomask2; \ + (_dest_tup)->t_infomask = (_src_tup)->t_infomask; \ + } while (0) + +#define COPY_TUPLE_HEADER_XACT_INFO(_dest_tuple, _src_tuple) \ + do { \ + HeapTupleHeader _dest = (_dest_tuple)->t_data; \ + HeapTupleHeader _src = (_src_tuple)->t_data; \ + (_dest)->t_choice = (_src)->t_choice; \ + (_dest)->t_ctid = (_src)->t_ctid; \ + (_dest)->t_infomask2 = (((_dest)->t_infomask2 & ~HEAP2_XACT_MASK) | ((_src)->t_infomask2 & HEAP2_XACT_MASK)); \ + (_dest)->t_infomask = (((_dest)->t_infomask & ~HEAP_XACT_MASK) | ((_src)->t_infomask & HEAP_XACT_MASK)); \ + } while (0) + +extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest); + +extern HeapTuple heap_form_tuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull); +extern HeapTuple heap_form_cmprs_tuple(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info); + +extern HeapTuple heap_modify_tuple( + HeapTuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace); + +extern void heap_deform_cmprs_tuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info); +extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull); +extern void heap_deform_tuple2(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, Buffer buffer); +extern void heap_deform_tuple3(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, Page page); + +/* these three are deprecated versions of the three above: */ +extern HeapTuple heap_formtuple(TupleDesc tuple_descriptor, Datum* values, const char* nulls); +extern HeapTuple heap_modifytuple( + HeapTuple tuple, TupleDesc tuple_desc, Datum* repl_values, const char* repl_nulls, const char* repl_actions); +extern void heap_deformtuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, char* nulls); +extern void heap_freetuple(HeapTuple htup); + +#define heap_freetuple_ext(htup) \ + do { \ + if ((htup) != NULL) { \ + heap_freetuple(htup); \ + htup = NULL; \ + } \ + } while (0) + +extern MinimalTuple heap_form_minimal_tuple( + TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple = NULL); +extern void heap_free_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup); +extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup); + +extern Datum heapGetInitDefVal(int att_num, TupleDesc tuple_desc, bool* is_null); +extern bool relationAttIsNull(HeapTuple tup, int att_num, TupleDesc tuple_desc); +extern MinimalTuple heapFormMinimalTuple(HeapTuple tuple, TupleDesc tuple_desc); + +extern MinimalTuple heapFormMinimalTuple(HeapTuple tuple, TupleDesc tuple_desc, Page page); + +/* for GPI clean up metadata */ +typedef bool (*KeepInvisbleTupleFunc)(Datum checkDatum); +typedef struct KeepInvisbleOpt { + Oid tableOid; + int checkAttnum; + KeepInvisbleTupleFunc checkKeepFunc; +} KeepInvisbleOpt; + +bool HeapKeepInvisbleTuple(HeapTuple tuple, TupleDesc tupleDesc, KeepInvisbleTupleFunc checkKeepFunc = NULL); + +// for ut test +extern HeapTuple test_HeapUncompressTup2(HeapTuple tuple, TupleDesc tuple_desc, Page dict_page); + +/* + * Prefix for delete delta table name used in redis. + * There is no other suitable common header file included in pg_redis.cpp, so defining it here. + */ +#define REDIS_DELETE_DELTA_TABLE_PREFIX "pg_delete_delta_" +#define REDIS_MULTI_CATCHUP_DELETE_DELTA_TABLE_PREFIX "pg_delete_delta_x_" + +#endif /* HTUP_H */ diff -uprN postgresql-hll-2.14_old/include/access/itup.h postgresql-hll-2.14/include/access/itup.h --- postgresql-hll-2.14_old/include/access/itup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/itup.h 2020-12-12 17:06:43.063345664 +0800 @@ -0,0 +1,119 @@ +/* ------------------------------------------------------------------------- + * + * itup.h + * POSTGRES index tuple definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/itup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITUP_H +#define ITUP_H + +#include "access/tupdesc.h" +#include "access/tupmacs.h" +#include "storage/bufpage.h" +#include "storage/itemptr.h" + +/* + * Index tuple header structure + * + * All index tuples start with IndexTupleData. If the HasNulls bit is set, + * this is followed by an IndexAttributeBitMapData. The index attribute + * values follow, beginning at a MAXALIGN boundary. + * + * Note that the space allocated for the bitmap does not vary with the number + * of attributes; that is because we don't have room to store the number of + * attributes in the header. Given the MAXALIGN constraint there's no space + * savings to be had anyway, for usual values of INDEX_MAX_KEYS. + */ + +typedef struct IndexTupleData { + ItemPointerData t_tid; /* reference TID to heap tuple */ + + /* --------------- + * t_info is laid out in the following fashion: + * + * 15th (high) bit: has nulls + * 14th bit: has var-width attributes + * 13th bit: AM-defined meaning + * 12-0 bit: size of tuple + * --------------- + */ + + unsigned short t_info; /* various info about tuple */ + +} IndexTupleData; /* MORE DATA FOLLOWS AT END OF STRUCT */ + +typedef IndexTupleData* IndexTuple; + +typedef struct IndexAttributeBitMapData { + bits8 bits[(INDEX_MAX_KEYS + 8 - 1) / 8]; +} IndexAttributeBitMapData; + +typedef IndexAttributeBitMapData* IndexAttributeBitMap; + +/* + * t_info manipulation macros + */ +#define INDEX_SIZE_MASK 0x1FFF +#define INDEX_AM_RESERVED_BIT 0x2000 /* reserved for index-AM specific usage */ +#define INDEX_VAR_MASK 0x4000 +#define INDEX_NULL_MASK 0x8000 + +#define IndexTupleSize(itup) ((Size)(((IndexTuple)(itup))->t_info & INDEX_SIZE_MASK)) +#define IndexTupleDSize(itup) ((Size)((itup).t_info & INDEX_SIZE_MASK)) +#define IndexTupleHasNulls(itup) ((((IndexTuple)(itup))->t_info & INDEX_NULL_MASK)) +#define IndexTupleHasVarwidths(itup) ((((IndexTuple)(itup))->t_info & INDEX_VAR_MASK)) + +/* + * Takes an infomask as argument (primarily because this needs to be usable + * at index_form_tuple time so enough space is allocated). + */ +#define IndexInfoFindDataOffset(t_info) \ + ((!((t_info)&INDEX_NULL_MASK)) ? ((Size)MAXALIGN(sizeof(IndexTupleData))) \ + : ((Size)MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)))) + +/* ---------------- + * index_getattr + * + * This gets called many times, so we macro the cacheable and NULL + * lookups, and call nocache_index_getattr() for the rest. + * + * ---------------- + */ +#define index_getattr(tup, attnum, tupleDesc, isnull) \ + (AssertMacro(PointerIsValid(isnull) && (attnum) > 0), \ + *(isnull) = false, \ + !IndexTupleHasNulls(tup) ? ((tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 \ + ? (fetchatt((tupleDesc)->attrs[(attnum)-1], \ + (char*)(tup) + IndexInfoFindDataOffset((tup)->t_info) + \ + (tupleDesc)->attrs[(attnum)-1]->attcacheoff)) \ + : nocache_index_getattr((tup), (attnum), (tupleDesc))) \ + : ((att_isnull((attnum)-1, (char*)(tup) + sizeof(IndexTupleData))) \ + ? (*(isnull) = true, (Datum)NULL) \ + : (nocache_index_getattr((tup), (attnum), (tupleDesc))))) + +/* + * MaxIndexTuplesPerPage is an upper bound on the number of tuples that can + * fit on one index page. An index tuple must have either data or a null + * bitmap, so we can safely assume it's at least 1 byte bigger than a bare + * IndexTupleData struct. We arrive at the divisor because each tuple + * must be maxaligned, and it must have an associated item pointer. + */ +#define MinIndexTupleSize MAXALIGN(sizeof(IndexTupleData) + 1) +#define MaxIndexTuplesPerPage \ + ((int)((BLCKSZ - SizeOfPageHeaderData) / (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData)))) + +/* routines in indextuple.c */ +extern IndexTuple index_form_tuple(TupleDesc tuple_descriptor, Datum* values, const bool* isnull); +extern Datum nocache_index_getattr(IndexTuple tup, uint32 attnum, TupleDesc tuple_desc); +extern void index_deform_tuple(IndexTuple tup, TupleDesc tuple_descriptor, Datum* values, bool* isnull); +extern IndexTuple index_truncate_tuple(TupleDesc tupleDescriptor, IndexTuple olditup, int new_indnatts); +extern IndexTuple CopyIndexTuple(IndexTuple source); + +#endif /* ITUP_H */ diff -uprN postgresql-hll-2.14_old/include/access/multi_redo_api.h postgresql-hll-2.14/include/access/multi_redo_api.h --- postgresql-hll-2.14_old/include/access/multi_redo_api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/multi_redo_api.h 2020-12-12 17:06:43.063345664 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * multi_redo_api.h + * + * + * IDENTIFICATION + * src/include/access/multi_redo_api.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MULTI_REDO_API_H +#define MULTI_REDO_API_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" +#include "access/redo_statistic.h" + + + + +typedef enum { + NOT_PAGE_REDO_THREAD, + PAGE_REDO_THREAD_EXIT_NORMAL, + PAGE_REDO_THREAD_EXIT_ABNORMAL, +} PageRedoExitStatus; + +extern bool g_supportHotStandby; + +const static bool SUPPORT_FPAGE_DISPATCH = true; /* support file dispatch if true, else support page dispatche */ + +const static bool SUPPORT_DFS_BATCH = false; +const static bool SUPPORT_COLUMN_BATCH = true; /* don't support column batch redo */ + + + +static const uint32 PAGE_REDO_WORKER_INVALID = 0; +static const uint32 PAGE_REDO_WORKER_START = 1; +static const uint32 PAGE_REDO_WORKER_READY = 2; +static const uint32 PAGE_REDO_WORKER_EXIT = 3; + +static inline int get_real_recovery_parallelism() +{ + return g_instance.attr.attr_storage.real_recovery_parallelism; +} + +static inline bool IsExtremeRedo() +{ + return g_instance.comm_cxt.predo_cxt.redoType == EXTREME_REDO && (get_real_recovery_parallelism() > 1); +} + +static inline bool IsParallelRedo() +{ + return g_instance.comm_cxt.predo_cxt.redoType == PARALLEL_REDO && (get_real_recovery_parallelism() > 1); +} + + +static inline bool IsMultiThreadRedo() +{ + return (get_real_recovery_parallelism() > 1); +} + +uint32 GetRedoWorkerCount(); + +bool IsMultiThreadRedoRunning(); +bool IsExtremeRtoRunning(); +void DispatchRedoRecord(XLogReaderState* record, List* expectedTLIs, TimestampTz recordXTime); +void GetThreadNameIfMultiRedo(int argc, char* argv[], char** threadNamePtr); + +PGPROC* MultiRedoThreadPidGetProc(ThreadId pid); +void MultiRedoUpdateStandbyState(HotStandbyState newState); +uint32 MultiRedoGetWorkerId(); +bool IsAllPageWorkerExit(); +void SetPageRedoWorkerIndex(int index); +int GetPageRedoWorkerIndex(int index); +PageRedoExitStatus CheckExitPageWorkers(ThreadId pid); +void SetMyPageRedoWorker(knl_thread_arg* arg); +uint32 GetMyPageRedoWorkerId(); +void MultiRedoMain(); +void StartUpMultiRedo(XLogReaderState* xlogreader, uint32 privateLen); + +void ProcTxnWorkLoad(bool force); +void EndDispatcherContext(); +void SwitchToDispatcherContext(); + +void FreeAllocatedRedoItem(); +void** GetXLogInvalidPagesFromWorkers(); +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); +bool IsExtremeRtoReadWorkerRunning(); +RedoWaitInfo GetRedoIoEvent(int32 event_id); +void GetRedoWrokerStatistic(uint32* realNum, RedoWorkerStatsData* worker, uint32 workerLen); +bool IsExtremeRtoSmartShutdown(); +void ExtremeRtoRedoManagerSendEndToStartup(); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/multi_redo_settings.h postgresql-hll-2.14/include/access/multi_redo_settings.h --- postgresql-hll-2.14_old/include/access/multi_redo_settings.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/multi_redo_settings.h 2020-12-12 17:06:43.063345664 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * multi_redo_settings.h + * + * + * IDENTIFICATION + * src/include/access/multi_redo_settings.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MULTI_REDO_SETTINGS_H +#define MULTI_REDO_SETTINGS_H + + +/* if you change MOST_FAST_RECOVERY_LIMIT, remember to change max_recovery_parallelism in cluster_guc.conf */ +static const int MOST_FAST_RECOVERY_LIMIT = 20; +static const int MAX_PARSE_WORKERS = 16; +static const int MAX_REDO_WORKERS_PER_PARSE = 8; + + + + +static const int TRXN_REDO_MANAGER_NUM = 1; +static const int TRXN_REDO_WORKER_NUM = 1; +static const int XLOG_READER_NUM = 3; + +static const int MAX_EXTREME_THREAD_NUM = MAX_PARSE_WORKERS * MAX_REDO_WORKERS_PER_PARSE + MAX_PARSE_WORKERS + + MAX_PARSE_WORKERS + TRXN_REDO_MANAGER_NUM + TRXN_REDO_WORKER_NUM + XLOG_READER_NUM; + +static const int MAX_RECOVERY_THREAD_NUM = (MAX_EXTREME_THREAD_NUM > MOST_FAST_RECOVERY_LIMIT) ? + MAX_EXTREME_THREAD_NUM : MOST_FAST_RECOVERY_LIMIT; + +void ConfigRecoveryParallelism(); + + +#endif diff -uprN postgresql-hll-2.14_old/include/access/multixact.h postgresql-hll-2.14/include/access/multixact.h --- postgresql-hll-2.14_old/include/access/multixact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/multixact.h 2020-12-12 17:06:43.063345664 +0800 @@ -0,0 +1,82 @@ +/* + * multixact.h + * + * PostgreSQL multi-transaction-log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/multixact.h + */ +#ifndef MULTIXACT_H +#define MULTIXACT_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +#define InvalidMultiXactId UINT64CONST(0) +#define FirstMultiXactId UINT64CONST(1) +#define MaxMultiXactId UINT64CONST(0xFFFFFFFFFFFFFFFF) + +#define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId) + +#define MaxMultiXactOffset UINT64CONST(0xFFFFFFFFFFFFFFFF) + +/* Number of SLRU buffers to use for multixact */ +#define NUM_MXACTOFFSET_BUFFERS 8 +#define NUM_MXACTMEMBER_BUFFERS 16 + +/* ---------------- + * multixact-related XLOG entries + * ---------------- + */ + +#define XLOG_MULTIXACT_ZERO_OFF_PAGE 0x00 +#define XLOG_MULTIXACT_ZERO_MEM_PAGE 0x10 +#define XLOG_MULTIXACT_CREATE_ID 0x20 + +#define XLOG_MULTIXACT_MASK 0x70 +#define XLOG_MULTIXACT_INT64_PAGENO 0x80 + + +typedef struct xl_multixact_create { + MultiXactId mid; /* new MultiXact's ID */ + MultiXactOffset moff; /* its starting offset in members file */ + int32 nxids; /* number of member XIDs */ + TransactionId xids[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_multixact_create; + +#define MinSizeOfMultiXactCreate offsetof(xl_multixact_create, xids) + +extern MultiXactId MultiXactIdCreate(TransactionId xid1, TransactionId xid2); +extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid); +extern bool MultiXactIdIsRunning(MultiXactId multi); +extern bool MultiXactIdIsCurrent(MultiXactId multi); +extern MultiXactId ReadNextMultiXactId(void); +extern void MultiXactIdWait(MultiXactId multi, bool allow_con_update = false); +extern bool ConditionalMultiXactIdWait(MultiXactId multi); +extern void MultiXactIdSetOldestMember(void); +extern int GetMultiXactIdMembers(MultiXactId multi, TransactionId** xids); + +extern void AtEOXact_MultiXact(void); +extern void AtPrepare_MultiXact(void); +extern void PostPrepare_MultiXact(TransactionId xid); + +extern Size MultiXactShmemSize(void); +extern void MultiXactShmemInit(void); +extern void BootStrapMultiXact(void); +extern void StartupMultiXact(void); +extern void ShutdownMultiXact(void); +extern void MultiXactGetCheckptMulti(bool is_shutdown, MultiXactId* nextMulti, MultiXactOffset* nextMultiOffset); +extern void CheckPointMultiXact(void); +extern void MultiXactSetNextMXact(MultiXactId nextMulti, MultiXactOffset nextMultiOffset); +extern void MultiXactAdvanceNextMXact(MultiXactId minMulti, MultiXactOffset minMultiOffset); + +extern void multixact_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void multixact_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void multixact_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern void multixact_redo(XLogReaderState* record); +extern void multixact_desc(StringInfo buf, XLogReaderState* record); + +#endif /* MULTIXACT_H */ diff -uprN postgresql-hll-2.14_old/include/access/nbtree.h postgresql-hll-2.14/include/access/nbtree.h --- postgresql-hll-2.14_old/include/access/nbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/nbtree.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,925 @@ +/* ------------------------------------------------------------------------- + * + * nbtree.h + * header file for postgres btree access method implementation. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/nbtree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NBTREE_H +#define NBTREE_H + +#include "access/genam.h" +#include "access/itup.h" +#include "access/sdir.h" +#include "access/xlogreader.h" +#include "catalog/pg_index.h" +#include "lib/stringinfo.h" +#include "storage/bufmgr.h" + +/* There's room for a 16-bit vacuum cycle ID in BTPageOpaqueData */ +typedef uint16 BTCycleId; + +/* + * BTPageOpaqueData -- At the end of every page, we store a pointer + * to both siblings in the tree. This is used to do forward/backward + * index scans. The next-page link is also critical for recovery when + * a search has navigated to the wrong page due to concurrent page splits + * or deletions; see src/backend/access/nbtree/README for more info. + * + * In addition, we store the page's btree level (counting upwards from + * zero at a leaf page) as well as some flag bits indicating the page type + * and status. If the page is deleted, we replace the level with the + * next-transaction-ID value indicating when it is safe to reclaim the page. + * + * We also store a "vacuum cycle ID". When a page is split while VACUUM is + * processing the index, a nonzero value associated with the VACUUM run is + * stored into both halves of the split page. (If VACUUM is not running, + * both pages receive zero cycleids.) This allows VACUUM to detect whether + * a page was split since it started, with a small probability of false match + * if the page was last split some exact multiple of MAX_BT_CYCLE_ID VACUUMs + * ago. Also, during a split, the BTP_SPLIT_END flag is cleared in the left + * (original) page, and set in the right page, but only if the next page + * to its right has a different cycleid. + * + * NOTE: the BTP_LEAF flag bit is redundant since level==0 could be tested + * instead. + */ + +typedef struct BTPageOpaqueDataInternal { + BlockNumber btpo_prev; /* left sibling, or P_NONE if leftmost */ + BlockNumber btpo_next; /* right sibling, or P_NONE if rightmost */ + union { + uint32 level; /* tree level --- zero for leaf pages */ + ShortTransactionId xact_old; /* next transaction ID, if deleted */ + } btpo; + uint16 btpo_flags; /* flag bits, see below */ + BTCycleId btpo_cycleid; /* vacuum cycle ID of latest split */ +} BTPageOpaqueDataInternal; + +typedef BTPageOpaqueDataInternal* BTPageOpaqueInternal; + +typedef struct BTPageOpaqueData { + BTPageOpaqueDataInternal bt_internal; + TransactionId xact; /* next transaction ID, if deleted */ +} BTPageOpaqueData; + +typedef BTPageOpaqueData* BTPageOpaque; + +/* Bits defined in btpo_flags */ +#define BTP_LEAF (1 << 0) /* leaf page, i.e. not internal page */ +#define BTP_ROOT (1 << 1) /* root page (has no parent) */ +#define BTP_DELETED (1 << 2) /* page has been deleted from tree */ +#define BTP_META (1 << 3) /* meta-page */ +#define BTP_HALF_DEAD (1 << 4) /* empty, but still in tree */ +#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */ +#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */ +#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */ + +/* + * The max allowed value of a cycle ID is a bit less than 64K. This is + * for convenience of pg_filedump and similar utilities: we want to use + * the last 2 bytes of special space as an index type indicator, and + * restricting cycle ID lets btree use that space for vacuum cycle IDs + * while still allowing index type to be identified. + */ +#define MAX_BT_CYCLE_ID 0xFF7F + +/* + * The Meta page is always the first page in the btree index. + * Its primary purpose is to point to the location of the btree root page. + * We also point to the "fast" root, which is the current effective root; + * see README for discussion. + */ + +typedef struct BTMetaPageData { + uint32 btm_magic; /* should contain BTREE_MAGIC */ + uint32 btm_version; /* should contain BTREE_VERSION */ + BlockNumber btm_root; /* current root location */ + uint32 btm_level; /* tree level of the root page */ + BlockNumber btm_fastroot; /* current "fast" root location */ + uint32 btm_fastlevel; /* tree level of the "fast" root page */ +} BTMetaPageData; + +#define BTPageGetMeta(p) ((BTMetaPageData*)PageGetContents(p)) + +#define BTREE_METAPAGE 0 /* first page is meta */ +#define BTREE_MAGIC 0x053162 /* magic number of btree pages */ +#define BTREE_VERSION 2 /* current version number */ + +/* Upgrade support for btree split/delete optimization. */ +#define BTREE_SPLIT_DELETE_UPGRADE_VERSION 92136 +#define BTREE_SPLIT_UPGRADE_FLAG 0x01 +#define BTREE_DELETE_UPGRADE_FLAG 0x02 + +/* + * Maximum size of a btree index entry, including its tuple header. + * + * We actually need to be able to fit three items on every page, + * so restrict any one item to 1/3 the per-page available space. + */ +#define BTMaxItemSize(page) \ + MAXALIGN_DOWN((PageGetPageSize(page) - MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \ + MAXALIGN(sizeof(BTPageOpaqueData))) / \ + 3) + +/* + * The leaf-page fillfactor defaults to 90% but is user-adjustable. + * For pages above the leaf level, we use a fixed 70% fillfactor. + * The fillfactor is applied during index build and when splitting + * a rightmost page; when splitting non-rightmost pages we try to + * divide the data equally. + */ +#define BTREE_MIN_FILLFACTOR 10 +#define BTREE_DEFAULT_FILLFACTOR 90 +#define BTREE_NONLEAF_FILLFACTOR 70 + +/* + * Test whether two btree entries are "the same". + * + * Old comments: + * In addition, we must guarantee that all tuples in the index are unique, + * in order to satisfy some assumptions in Lehman and Yao. The way that we + * do this is by generating a new OID for every insertion that we do in the + * tree. This adds eight bytes to the size of btree index tuples. Note + * that we do not use the OID as part of a composite key; the OID only + * serves as a unique identifier for a given index tuple (logical position + * within a page). + * + * New comments: + * actually, we must guarantee that all tuples in A LEVEL + * are unique, not in ALL INDEX. So, we can use the t_tid + * as unique identifier for a given index tuple (logical position + * within a level). - vadim 04/09/97 + */ +#define BTTidSame(i1, i2) \ + ((i1).ip_blkid.bi_hi == (i2).ip_blkid.bi_hi && (i1).ip_blkid.bi_lo == (i2).ip_blkid.bi_lo && \ + (i1).ip_posid == (i2).ip_posid) +#define BTEntrySame(i1, i2) BTTidSame((i1)->t_tid, (i2)->t_tid) + +/* + * In general, the btree code tries to localize its knowledge about + * page layout to a couple of routines. However, we need a special + * value to indicate "no page number" in those places where we expect + * page numbers. We can use zero for this because we never need to + * make a pointer to the metadata page. + */ + +#define P_NONE 0 + +/* + * Macros to test whether a page is leftmost or rightmost on its tree level, + * as well as other state info kept in the opaque data. + */ +#define P_LEFTMOST(opaque) ((opaque)->btpo_prev == P_NONE) +#define P_RIGHTMOST(opaque) ((opaque)->btpo_next == P_NONE) +#define P_ISLEAF(opaque) ((opaque)->btpo_flags & BTP_LEAF) +#define P_ISROOT(opaque) ((opaque)->btpo_flags & BTP_ROOT) +#define P_ISDELETED(opaque) ((opaque)->btpo_flags & BTP_DELETED) +#define P_ISHALFDEAD(opaque) ((opaque)->btpo_flags & BTP_HALF_DEAD) +#define P_IGNORE(opaque) ((opaque)->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD)) +#define P_HAS_GARBAGE(opaque) ((opaque)->btpo_flags & BTP_HAS_GARBAGE) +#define P_INCOMPLETE_SPLIT(opaque) ((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) + +/* + * Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost + * page. The high key is not a data key, but gives info about what range of + * keys is supposed to be on this page. The high key on a page is required + * to be greater than or equal to any data key that appears on the page. + * If we find ourselves trying to insert a key > high key, we know we need + * to move right (this should only happen if the page was split since we + * examined the parent page). + * + * Our insertion algorithm guarantees that we can use the initial least key + * on our right sibling as the high key. Once a page is created, its high + * key changes only if the page is split. + * + * On a non-rightmost page, the high key lives in item 1 and data items + * start in item 2. Rightmost pages have no high key, so we store data + * items beginning in item 1. + */ + +#define P_HIKEY ((OffsetNumber)1) +#define P_FIRSTKEY ((OffsetNumber)2) +#define P_FIRSTDATAKEY(opaque) (P_RIGHTMOST(opaque) ? P_HIKEY : P_FIRSTKEY) + +/* + * XLOG records for btree operations + * + * XLOG allows to store some information in high 4 bits of log + * record xl_info field + */ +#define XLOG_BTREE_INSERT_LEAF 0x00 /* add index tuple without split */ +#define XLOG_BTREE_INSERT_UPPER 0x10 /* same, on a non-leaf page */ +#define XLOG_BTREE_INSERT_META 0x20 /* same, plus update metapage */ +#define XLOG_BTREE_SPLIT_L 0x30 /* add index tuple with split */ +#define XLOG_BTREE_SPLIT_R 0x40 /* as above, new item on right */ +#define XLOG_BTREE_SPLIT_L_ROOT 0x50 /* add tuple with split of root */ +#define XLOG_BTREE_SPLIT_R_ROOT 0x60 /* as above, new item on right */ +#define XLOG_BTREE_DELETE 0x70 /* delete leaf index tuples for a page */ +#define XLOG_BTREE_UNLINK_PAGE 0x80 /* delete an entire page */ +#define XLOG_BTREE_UNLINK_PAGE_META 0x90 /* same, and update metapage */ +#define XLOG_BTREE_NEWROOT 0xA0 /* new root page */ +#define XLOG_BTREE_MARK_PAGE_HALFDEAD \ + 0xB0 /* page deletion that makes \ + * parent half-dead */ +#define XLOG_BTREE_VACUUM \ + 0xC0 /* delete entries on a page during \ + * vacuum */ +#define XLOG_BTREE_REUSE_PAGE \ + 0xD0 /* old page is about to be reused from \ + * FSM */ + + +enum { + BTREE_INSERT_ORIG_BLOCK_NUM = 0, + BTREE_INSERT_CHILD_BLOCK_NUM, + BTREE_INSERT_META_BLOCK_NUM, +}; + +enum { + BTREE_SPLIT_LEFT_BLOCK_NUM = 0, + BTREE_SPLIT_RIGHT_BLOCK_NUM, + BTREE_SPLIT_RIGHTNEXT_BLOCK_NUM, + BTREE_SPLIT_CHILD_BLOCK_NUM +}; + +enum { + BTREE_VACUUM_ORIG_BLOCK_NUM = 0, +}; + +enum { + BTREE_DELETE_ORIG_BLOCK_NUM = 0, +}; + +enum { + BTREE_HALF_DEAD_LEAF_PAGE_NUM = 0, + BTREE_HALF_DEAD_PARENT_PAGE_NUM, +}; + +enum { + BTREE_UNLINK_PAGE_CUR_PAGE_NUM = 0, + BTREE_UNLINK_PAGE_LEFT_NUM, + BTREE_UNLINK_PAGE_RIGHT_NUM, + BTREE_UNLINK_PAGE_CHILD_NUM, + BTREE_UNLINK_PAGE_META_NUM, +}; + + +enum { + BTREE_NEWROOT_ORIG_BLOCK_NUM = 0, + BTREE_NEWROOT_LEFT_BLOCK_NUM, + BTREE_NEWROOT_META_BLOCK_NUM +}; + +/* + * All that we need to regenerate the meta-data page + */ +typedef struct xl_btree_metadata { + BlockNumber root; + uint32 level; + BlockNumber fastroot; + uint32 fastlevel; +} xl_btree_metadata; + +/* + * This is what we need to know about simple (without split) insert. + * + * This data record is used for INSERT_LEAF, INSERT_UPPER, INSERT_META. + * Note that INSERT_META implies it's not a leaf page. + * + * Backup Blk 0: original page (data contains the inserted tuple) + * Backup Blk 1: xl_btree_metadata, if INSERT_META + */ +typedef struct xl_btree_insert { + OffsetNumber offnum; +} xl_btree_insert; + +#define SizeOfBtreeInsert (offsetof(xl_btree_insert, offnum) + sizeof(OffsetNumber)) + +/* + * On insert with split, we save all the items going into the right sibling + * so that we can restore it completely from the log record. This way takes + * less xlog space than the normal approach, because if we did it standardly, + * XLogInsert would almost always think the right page is new and store its + * whole page image. The left page, however, is handled in the normal + * incremental-update fashion. + * + * Note: the four XLOG_BTREE_SPLIT xl_info codes all use this data record. + * The _L and _R variants indicate whether the inserted tuple went into the + * left or right split page (and thus, whether newitemoff and the new item + * are stored or not). The _HIGHKEY variants indicate that we've logged + * explicitly left page high key value, otherwise redo should use right page + * leftmost key as a left page high key. _HIGHKEY is specified for internal + * pages where right page leftmost key is suppressed, and for leaf pages + * of covering indexes where high key have non-key attributes truncated. + * + * Backup Blk 0: original page / new left page + * + * The left page's data portion contains the new item, if it's the _L variant. + * (In the _R variants, the new item is one of the right page's tuples.) + * If level > 0, an IndexTuple representing the HIKEY of the left page + * follows. We don't need this on leaf pages, because it's the same as the + * leftmost key in the new right page. + * + * Backup Blk 1: new right page + * + * The right page's data portion contains the right page's tuples in the + * form used by _bt_restore_page. + * + * Backup Blk 2: next block (orig page's rightlink), if any + */ +typedef struct xl_btree_split { + uint32 level; /* tree level of page being split */ + OffsetNumber firstright; /* first item moved to right page */ + OffsetNumber newitemoff; /* new item's offset (if placed on left page) */ +} xl_btree_split; + +#define SizeOfBtreeSplit (offsetof(xl_btree_split, newitemoff) + sizeof(OffsetNumber)) + +/* + * This is what we need to know about delete of individual leaf index tuples. + * The WAL record can represent deletion of any number of index tuples on a + * single index page when *not* executed by VACUUM. + * + * Backup Blk 0: index page + */ +typedef struct xl_btree_delete { + RelFileNodeOld hnode; /* RelFileNode of the heap the index currently + * points at */ + int nitems; + + /* TARGET OFFSET NUMBERS FOLLOW AT THE END */ +} xl_btree_delete; + +#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nitems) + sizeof(int)) + +/* + * This is what we need to know about page reuse within btree. + */ +typedef struct xl_btree_reuse_page { + RelFileNodeOld node; + BlockNumber block; + TransactionId latestRemovedXid; +} xl_btree_reuse_page; + +#define SizeOfBtreeReusePage (sizeof(xl_btree_reuse_page)) + +/* + * This is what we need to know about vacuum of individual leaf index tuples. + * The WAL record can represent deletion of any number of index tuples on a + * single index page when executed by VACUUM. + * + * The correctness requirement for applying these changes during recovery is + * that we must do one of these two things for every block in the index: + * * lock the block for cleanup and apply any required changes + * * EnsureBlockUnpinned() + * The purpose of this is to ensure that no index scans started before we + * finish scanning the index are still running by the time we begin to remove + * heap tuples. + * + * Any changes to any one block are registered on just one WAL record. All + * blocks that we need to run EnsureBlockUnpinned() are listed as a block range + * starting from the last block vacuumed through until this one. Individual + * block numbers aren't given. + * + * Note that the *last* WAL record in any vacuum of an index is allowed to + * have a zero length array of offsets. Earlier records must have at least one. + */ +typedef struct xl_btree_vacuum { + BlockNumber lastBlockVacuumed; + + /* TARGET OFFSET NUMBERS FOLLOW */ +} xl_btree_vacuum; + +#define SizeOfBtreeVacuum (offsetof(xl_btree_vacuum, lastBlockVacuumed) + sizeof(BlockNumber)) + +/* + * This is what we need to know about deletion of a btree page. The target + * identifies the tuple removed from the parent page (note that we remove + * this tuple's downlink and the *following* tuple's key). Note we do not + * store any content for the deleted page --- it is just rewritten as empty + * during recovery, apart from resetting the btpo.xact. + * + * Backup Blk 0: target block being deleted + * Backup Blk 1: target block's left sibling, if any + * Backup Blk 2: target block's right sibling + * Backup Blk 3: target block's parent + * Backup Blk 4: metapage (if rightsib becomes new fast root) + */ +typedef struct xl_btree_delete_page { + OffsetNumber poffset; /* deleted tuple id in parent page */ + BlockNumber leftblk; /* child block's left sibling, if any */ + BlockNumber rightblk; /* child block's right sibling */ + TransactionId btpo_xact; /* value of btpo.xact for use in recovery */ + /* xl_btree_metadata FOLLOWS IF XLOG_BTREE_DELETE_PAGE_META */ +} xl_btree_delete_page; + +#define SizeOfBtreeDeletePage (offsetof(xl_btree_delete_page, btpo_xact) + sizeof(TransactionId)) + + +/* + * This is what we need to know about marking an empty branch for deletion. + * The target identifies the tuple removed from the parent page (note that we + * remove this tuple's downlink and the *following* tuple's key). Note that + * the leaf page is empty, so we don't need to store its content --- it is + * just reinitialized during recovery using the rest of the fields. + * + * Backup Blk 0: leaf block + * Backup Blk 1: top parent + */ +typedef struct xl_btree_mark_page_halfdead +{ + OffsetNumber poffset; /* deleted tuple id in parent page */ + + /* information needed to recreate the leaf page: */ + BlockNumber leafblk; /* leaf block ultimately being deleted */ + BlockNumber leftblk; /* leaf block's left sibling, if any */ + BlockNumber rightblk; /* leaf block's right sibling */ + BlockNumber topparent; /* topmost internal page in the branch */ +} xl_btree_mark_page_halfdead; + +#define SizeOfBtreeMarkPageHalfDead (offsetof(xl_btree_mark_page_halfdead, topparent) + sizeof(BlockNumber)) + +/* + * This is what we need to know about deletion of a btree page. Note we do + * not store any content for the deleted page --- it is just rewritten as empty + * during recovery, apart from resetting the btpo.xact. + * + * Backup Blk 0: target block being deleted + * Backup Blk 1: target block's left sibling, if any + * Backup Blk 2: target block's right sibling + * Backup Blk 3: leaf block (if different from target) + * Backup Blk 4: metapage (if rightsib becomes new fast root) + */ +typedef struct xl_btree_unlink_page +{ + BlockNumber leftsib; /* target block's left sibling, if any */ + BlockNumber rightsib; /* target block's right sibling */ + + /* + * Information needed to recreate the leaf page, when target is an + * internal page. + */ + BlockNumber leafleftsib; + BlockNumber leafrightsib; + BlockNumber topparent; /* next child down in the branch */ + + TransactionId btpo_xact; /* value of btpo.xact for use in recovery */ + /* xl_btree_metadata FOLLOWS IF XLOG_BTREE_UNLINK_PAGE_META */ +} xl_btree_unlink_page; + +#define SizeOfBtreeUnlinkPage (offsetof(xl_btree_unlink_page, btpo_xact) + sizeof(TransactionId)) + +/* + * New root log record. There are zero tuples if this is to establish an + * empty root, or two if it is the result of splitting an old root. + * + * Note that although this implies rewriting the metadata page, we don't need + * an xl_btree_metadata record --- the rootblk and level are sufficient. + * + * Backup Blk 0: new root page (2 tuples as payload, if splitting old root) + * Backup Blk 1: metapage + */ +typedef struct xl_btree_newroot { + BlockNumber rootblk; /* location of new root (redundant with blk 0) */ + uint32 level; /* its tree level */ + /* 0 or 2 INDEX TUPLES FOLLOW AT END OF STRUCT */ +} xl_btree_newroot; + +#define SizeOfBtreeNewroot (offsetof(xl_btree_newroot, level) + sizeof(uint32)) + +/* + * INCLUDE B-Tree indexes have non-key attributes. These are extra + * attributes that may be returned by index-only scans, but do not influence + * the order of items in the index (formally, non-key attributes are not + * considered to be part of the key space). Non-key attributes are only + * present in leaf index tuples whose item pointers actually point to heap + * tuples. All other types of index tuples (collectively, "pivot" tuples) + * only have key attributes, since pivot tuples only ever need to represent + * how the key space is separated. In general, any B-Tree index that has + * more than one level (i.e. any index that does not just consist of a + * metapage and a single leaf root page) must have some number of pivot + * tuples, since pivot tuples are used for traversing the tree. + * + * We store the number of attributes present inside pivot tuples by abusing + * their item pointer offset field, since pivot tuples never need to store a + * real offset (downlinks only need to store a block number). The offset + * field only stores the number of attributes when the INDEX_ALT_TID_MASK + * bit is set (we never assume that pivot tuples must explicitly store the + * number of attributes, and currently do not bother storing the number of + * attributes unless indnkeyatts actually differs from indnatts). + * INDEX_ALT_TID_MASK is only used for pivot tuples at present, though it's + * possible that it will be used within non-pivot tuples in the future. Do + * not assume that a tuple with INDEX_ALT_TID_MASK set must be a pivot + * tuple. + * + * The 12 least significant offset bits are used to represent the number of + * attributes in INDEX_ALT_TID_MASK tuples, leaving 4 bits that are reserved + * for future use (BT_RESERVED_OFFSET_MASK bits). BT_N_KEYS_OFFSET_MASK should + * be large enough to store any number <= INDEX_MAX_KEYS. + */ +#define INDEX_ALT_TID_MASK INDEX_AM_RESERVED_BIT +#define BT_RESERVED_OFFSET_MASK 0xF000 +#define BT_N_KEYS_OFFSET_MASK 0x0FFF + +/* Get/set downlink block number */ +#define BTreeInnerTupleGetDownLink(itup) ItemPointerGetBlockNumberNoCheck(&((itup)->t_tid)) +#define BTreeInnerTupleSetDownLink(itup, blkno) ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)) + +/* + * Get/set leaf page highkey's link. During the second phase of deletion, the + * target leaf page's high key may point to an ancestor page (at all other + * times, the leaf level high key's link is not used). See the nbtree README + * for full details. + */ +#define BTreeTupleGetTopParent(itup) ItemPointerGetBlockNumberNoCheck(&((itup)->t_tid)) +#define BTreeTupleSetTopParent(itup, blkno) \ + do { \ + ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)); \ + BTreeTupleSetNAtts((itup), 0); \ + } while (0) + +/* + * Get/set number of attributes within B-tree index tuple. Asserts should be + * removed when BT_RESERVED_OFFSET_MASK bits will be used. + */ +#define BTreeTupleGetNAtts(itup, rel) \ + ((itup)->t_info & INDEX_ALT_TID_MASK \ + ? (AssertMacro((ItemPointerGetOffsetNumberNoCheck(&(itup)->t_tid) & BT_RESERVED_OFFSET_MASK) == 0), \ + ItemPointerGetOffsetNumberNoCheck(&(itup)->t_tid) & BT_N_KEYS_OFFSET_MASK) \ + : IndexRelationGetNumberOfAttributes(rel)) + +#define BTreeTupleSetNAtts(itup, n) \ + do { \ + (itup)->t_info |= INDEX_ALT_TID_MASK; \ + Assert(((n) & BT_RESERVED_OFFSET_MASK) == 0); \ + ItemPointerSetOffsetNumber(&(itup)->t_tid, (n) & BT_N_KEYS_OFFSET_MASK); \ + } while (0) + +/* + * Operator strategy numbers for B-tree have been moved to access/skey.h, + * because many places need to use them in ScanKeyInit() calls. + * + * The strategy numbers are chosen so that we can commute them by + * subtraction, thus: + */ +#define BTCommuteStrategyNumber(strat) (BTMaxStrategyNumber + 1 - (strat)) + +/* + * When a new operator class is declared, we require that the user + * supply us with an amproc procedure (BTORDER_PROC) for determining + * whether, for two keys a and b, a < b, a = b, or a > b. This routine + * must return < 0, 0, > 0, respectively, in these three cases. (It must + * not return INT_MIN, since we may negate the result before using it.) + * + * To facilitate accelerated sorting, an operator class may choose to + * offer a second procedure (BTSORTSUPPORT_PROC). For full details, see + * src/include/utils/sortsupport.h. + */ + +#define BTORDER_PROC 1 +#define BTSORTSUPPORT_PROC 2 + +/* + * We need to be able to tell the difference between read and write + * requests for pages, in order to do locking correctly. + */ + +#define BT_READ BUFFER_LOCK_SHARE +#define BT_WRITE BUFFER_LOCK_EXCLUSIVE + +/* + * BTStackData -- As we descend a tree, we push the (location, downlink) + * pairs from internal pages onto a private stack. If we split a + * leaf, we use this stack to walk back up the tree and insert data + * into parent pages (and possibly to split them, too). Lehman and + * Yao's update algorithm guarantees that under no circumstances can + * our private stack give us an irredeemably bad picture up the tree. + * Again, see the paper for details. + */ + +typedef struct BTStackData { + BlockNumber bts_blkno; + OffsetNumber bts_offset; + BlockNumber bts_btentry; + struct BTStackData* bts_parent; +} BTStackData; + +typedef BTStackData* BTStack; + +/* + * BTScanOpaqueData is the btree-private state needed for an indexscan. + * This consists of preprocessed scan keys (see _bt_preprocess_keys() for + * details of the preprocessing), information about the current location + * of the scan, and information about the marked location, if any. (We use + * BTScanPosData to represent the data needed for each of current and marked + * locations.) In addition we can remember some known-killed index entries + * that must be marked before we can move off the current page. + * + * Index scans work a page at a time: we pin and read-lock the page, identify + * all the matching items on the page and save them in BTScanPosData, then + * release the read-lock while returning the items to the caller for + * processing. This approach minimizes lock/unlock traffic. Note that we + * keep the pin on the index page until the caller is done with all the items + * (this is needed for VACUUM synchronization, see nbtree/README). When we + * are ready to step to the next page, if the caller has told us any of the + * items were killed, we re-lock the page to mark them killed, then unlock. + * Finally we drop the pin and step to the next page in the appropriate + * direction. + * + * If we are doing an index-only scan, we save the entire IndexTuple for each + * matched item, otherwise only its heap TID and offset. The IndexTuples go + * into a separate workspace array; each BTScanPosItem stores its tuple's + * offset within that array. + */ + +typedef struct BTScanPosItem { /* what we remember about each match */ + ItemPointerData heapTid; /* TID of referenced heap item */ + OffsetNumber indexOffset; /* index item's location within page */ + LocationIndex tupleOffset; /* IndexTuple's offset in workspace, if any */ + Oid partitionOid; /* partition table oid in workspace, if any */ +} BTScanPosItem; + +typedef struct BTScanPosData { + Buffer buf; /* if valid, the buffer is pinned */ + + BlockNumber nextPage; /* page's right link when we scanned it */ + + /* + * moreLeft and moreRight track whether we think there may be matching + * index entries to the left and right of the current page, respectively. + * We can clear the appropriate one of these flags when _bt_checkkeys() + * returns continuescan = false. + */ + bool moreLeft; + bool moreRight; + + /* + * If we are doing an index-only scan, nextTupleOffset is the first free + * location in the associated tuple storage workspace. + */ + int nextTupleOffset; + + /* + * The items array is always ordered in index order (ie, increasing + * indexoffset). When scanning backwards it is convenient to fill the + * array back-to-front, so we start at the last slot and fill downwards. + * Hence we need both a first-valid-entry and a last-valid-entry counter. + * itemIndex is a cursor showing which entry was last returned to caller. + */ + int firstItem; /* first valid index in items[] */ + int lastItem; /* last valid index in items[] */ + int itemIndex; /* current index in items[] */ + + BTScanPosItem items[MaxIndexTuplesPerPage]; /* MUST BE LAST */ +} BTScanPosData; + +typedef BTScanPosData* BTScanPos; + +#define BTScanPosIsValid(scanpos) BufferIsValid((scanpos).buf) + +/* We need one of these for each equality-type SK_SEARCHARRAY scan key */ +typedef struct BTArrayKeyInfo { + int scan_key; /* index of associated key in arrayKeyData */ + int cur_elem; /* index of current element in elem_values */ + int mark_elem; /* index of marked element in elem_values */ + int num_elems; /* number of elems in current array value */ + Datum* elem_values; /* array of num_elems Datums */ +} BTArrayKeyInfo; + +typedef struct BTScanOpaqueData { + /* these fields are set by _bt_preprocess_keys(): */ + bool qual_ok; /* false if qual can never be satisfied */ + int numberOfKeys; /* number of preprocessed scan keys */ + ScanKey keyData; /* array of preprocessed scan keys */ + + /* workspace for SK_SEARCHARRAY support */ + ScanKey arrayKeyData; /* modified copy of scan->keyData */ + int numArrayKeys; /* number of equality-type array keys (-1 if + * there are any unsatisfiable array keys) */ + BTArrayKeyInfo* arrayKeys; /* info about each equality-type array key */ + MemoryContext arrayContext; /* scan-lifespan context for array data */ + + /* info about killed items if any (killedItems is NULL if never used) */ + int* killedItems; /* currPos.items indexes of killed items */ + int numKilled; /* number of currently stored items */ + + /* + * If we are doing an index-only scan, these are the tuple storage + * workspaces for the currPos and markPos respectively. Each is of size + * BLCKSZ, so it can hold as much as a full page's worth of tuples. + */ + char* currTuples; /* tuple storage for currPos */ + char* markTuples; /* tuple storage for markPos */ + + /* + * If the marked position is on the same page as current position, we + * don't use markPos, but just keep the marked itemIndex in markItemIndex + * (all the rest of currPos is valid for the mark position). Hence, to + * determine if there is a mark, first look at markItemIndex, then at + * markPos. + */ + int markItemIndex; /* itemIndex, or -1 if not valid */ + + /* keep these last in struct for efficiency */ + BTScanPosData currPos; /* current position data */ + BTScanPosData markPos; /* marked position, if any */ +} BTScanOpaqueData; + +typedef BTScanOpaqueData* BTScanOpaque; + +/* + * We use some private sk_flags bits in preprocessed scan keys. We're allowed + * to use bits 16-31 (see skey.h). The uppermost bits are copied from the + * index's indoption[] array entry for the index attribute. + */ +#define SK_BT_REQFWD 0x00010000 /* required to continue forward scan */ +#define SK_BT_REQBKWD 0x00020000 /* required to continue backward scan */ +#define SK_BT_INDOPTION_SHIFT 24 /* must clear the above bits */ +#define SK_BT_DESC (INDOPTION_DESC << SK_BT_INDOPTION_SHIFT) +#define SK_BT_NULLS_FIRST (INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT) + +// BTPageState and BTWriteState are moved here from nbtsort.cpp +/* + * Status record for a btree page being built. We have one of these + * for each active tree level. + * + * The reason we need to store a copy of the minimum key is that we'll + * need to propagate it to the parent node when this page is linked + * into its parent. However, if the page is not a leaf page, the first + * entry on the page doesn't need to contain a key, so we will not have + * stored the key itself on the page. (You might think we could skip + * copying the minimum key on leaf pages, but actually we must have a + * writable copy anyway because we'll poke the page's address into it + * before passing it up to the parent...) + */ +typedef struct BTPageState { + Page btps_page; /* workspace for page building */ + BlockNumber btps_blkno; /* block # to write this page at */ + IndexTuple btps_minkey; /* copy of minimum key (first item) on page */ + OffsetNumber btps_lastoff; /* last item offset loaded */ + uint32 btps_level; /* tree level (0 = leaf) */ + Size btps_full; /* "full" if less than this much free space */ + struct BTPageState* btps_next; /* link to parent level, if any */ +} BTPageState; + +/* + * Overall status record for index writing phase. + */ +typedef struct BTWriteState { + Relation index; + bool btws_use_wal; /* dump pages to WAL? */ + BlockNumber btws_pages_alloced; /* # pages allocated */ + BlockNumber btws_pages_written; /* # pages written out */ + Page btws_zeropage; /* workspace for filling zeroes */ +} BTWriteState; + +typedef struct BTOrderedIndexListElement { + IndexTuple itup; + BlockNumber heapModifiedOffset; + IndexScanDesc indexScanDesc; +} BTOrderedIndexListElement; + +/* + * prototypes for functions in nbtree.c (external entry points for btree) + */ +extern Datum btbuild(PG_FUNCTION_ARGS); +extern Datum btbuildempty(PG_FUNCTION_ARGS); +extern Datum btinsert(PG_FUNCTION_ARGS); +extern Datum btbeginscan(PG_FUNCTION_ARGS); +extern Datum btgettuple(PG_FUNCTION_ARGS); +extern Datum btgetbitmap(PG_FUNCTION_ARGS); +extern Datum cbtreegetbitmap(PG_FUNCTION_ARGS); +extern Datum btrescan(PG_FUNCTION_ARGS); +extern Datum btendscan(PG_FUNCTION_ARGS); +extern Datum btmarkpos(PG_FUNCTION_ARGS); +extern Datum btrestrpos(PG_FUNCTION_ARGS); +extern Datum btbulkdelete(PG_FUNCTION_ARGS); +extern Datum btvacuumcleanup(PG_FUNCTION_ARGS); +extern Datum btcanreturn(PG_FUNCTION_ARGS); +extern Datum btoptions(PG_FUNCTION_ARGS); +/* + * this is the interface of merge 2 or more index for btree index + * we also have similar interfaces for other kind of indexes, like hash/gist/gin + * thought, we are not going to implement them right now. + */ +extern Datum btmerge(PG_FUNCTION_ARGS); + +/* + * prototypes for functions in nbtinsert.c + */ +extern bool _bt_doinsert(Relation rel, IndexTuple itup, IndexUniqueCheck checkUnique, Relation heapRel); +extern Buffer _bt_getstackbuf(Relation rel, BTStack stack); +extern void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf, BTStack stack, bool is_root, bool is_only); +extern void _bt_finish_split(Relation rel, Buffer bbuf, BTStack stack); +extern IndexTuple _bt_nonkey_truncate(Relation idxrel, IndexTuple olditup); + +/* + * prototypes for functions in nbtpage.c + */ +extern void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level); +extern Buffer _bt_getroot(Relation rel, int access); +extern Buffer _bt_gettrueroot(Relation rel); +extern void _bt_checkpage(Relation rel, Buffer buf); +extern Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access); +extern Buffer _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access); +extern void _bt_relbuf(Relation rel, Buffer buf); +extern void _bt_pageinit(Page page, Size size); +extern bool _bt_page_recyclable(Page page); +extern void _bt_delitems_delete(Relation rel, Buffer buf, OffsetNumber* itemnos, int nitems, Relation heapRel); +extern void _bt_delitems_vacuum( + Relation rel, Buffer buf, OffsetNumber* itemnos, int nitems, BlockNumber lastBlockVacuumed); +extern int _bt_pagedel(Relation rel, Buffer buf, BTStack stack); +extern void _bt_page_localupgrade(Page page); +/* + * prototypes for functions in nbtsearch.c + */ +extern BTStack _bt_search( + Relation rel, int keysz, ScanKey scankey, bool nextkey, Buffer* bufP, int access, bool needStack = true); +extern Buffer _bt_moveright(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey, bool forupdate, BTStack stack, int access); +extern OffsetNumber _bt_binsrch(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey); +extern int32 _bt_compare(Relation rel, int keysz, ScanKey scankey, Page page, OffsetNumber offnum); +extern bool _bt_first(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_next(IndexScanDesc scan, ScanDirection dir); +extern Buffer _bt_get_endpoint(Relation rel, uint32 level, bool rightmost); +extern bool _bt_gettuple_internal(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_check_natts(const Relation index, Page page, OffsetNumber offnum); + +/* + * prototypes for functions in nbtutils.c + */ +extern ScanKey _bt_mkscankey(Relation rel, IndexTuple itup); +extern ScanKey _bt_mkscankey_nodata(Relation rel); +extern void _bt_freeskey(ScanKey skey); +extern void _bt_freestack(BTStack stack); +extern int _bt_sort_array_elements( + IndexScanDesc scan, ScanKey skey, bool reverse, Datum* elems, int nelems); +extern void _bt_preprocess_array_keys(IndexScanDesc scan); +extern void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_advance_array_keys(IndexScanDesc scan, ScanDirection dir); +extern void _bt_mark_array_keys(IndexScanDesc scan); +extern void _bt_restore_array_keys(IndexScanDesc scan); +extern void _bt_preprocess_keys(IndexScanDesc scan); +extern IndexTuple _bt_checkkeys( + IndexScanDesc scan, Page page, OffsetNumber offnum, ScanDirection dir, bool* continuescan); +extern void _bt_killitems(IndexScanDesc scan, bool haveLock); +extern BTCycleId _bt_vacuum_cycleid(Relation rel); +extern BTCycleId _bt_start_vacuum(Relation rel); +extern void _bt_end_vacuum(Relation rel); +extern void _bt_end_vacuum_callback(int code, Datum arg); +extern Size BTreeShmemSize(void); +extern void BTreeShmemInit(void); + +/* + * prototypes for functions in nbtsort.c + */ +typedef struct BTSpool BTSpool; /* opaque type known only within nbtsort.c */ + +/* Working state for btbuild and its callback */ +typedef struct { + bool isUnique; + bool haveDead; + Relation heapRel; + BTSpool* spool; + + /* + * spool2 is needed only when the index is an unique index. Dead tuples + * are put into spool2 instead of spool in order to avoid uniqueness + * check. + */ + BTSpool* spool2; + double indtuples; +} BTBuildState; + +extern BTSpool* _bt_spoolinit(Relation index, bool isunique, bool isdead, void* meminfo); +extern void _bt_spooldestroy(BTSpool* btspool); +extern void _bt_spool(BTSpool* btspool, ItemPointer self, Datum* values, const bool* isnull); +extern void _bt_leafbuild(BTSpool* btspool, BTSpool* spool2); +// these 4 functions are move here from nbtsearch.cpp(static functions) +extern void _bt_buildadd(BTWriteState* wstate, BTPageState* state, IndexTuple itup); +extern void _bt_uppershutdown(BTWriteState* wstate, BTPageState* state); +BTPageState* _bt_pagestate(BTWriteState* wstate, uint32 level); +extern bool _index_tuple_compare(TupleDesc tupdes, ScanKey indexScanKey, int keysz, IndexTuple itup, IndexTuple itup2); +extern List* insert_ordered_index(List* list, TupleDesc tupdes, ScanKey indexScanKey, int keysz, IndexTuple itup, + BlockNumber heapModifiedOffset, IndexScanDesc srcIdxRelScan); +/* + * prototypes for functions in nbtxlog.c + */ +extern void btree_redo(XLogReaderState* record); +extern void btree_desc(StringInfo buf, XLogReaderState* record); +extern void btree_xlog_startup(void); +extern void btree_xlog_cleanup(void); +extern bool btree_safe_restartpoint(void); +extern void* btree_get_incomplete_actions(); +extern void btree_clear_imcompleteAction(); +extern bool IsBtreeVacuum(const XLogReaderState* record); +extern void _bt_restore_page(Page page, char* from, int len); +extern void DumpBtreeDeleteInfo(XLogRecPtr lsn, OffsetNumber offsetList[], uint64 offsetNum); + +#endif /* NBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/access/obs/obs_am.h postgresql-hll-2.14/include/access/obs/obs_am.h --- postgresql-hll-2.14_old/include/access/obs/obs_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/obs/obs_am.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,149 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * obs_am.h + * obs access method definitions. + * + * + * IDENTIFICATION + * src/include/access/obs/obs_am.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OBS_AM_H +#define OBS_AM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "nodes/pg_list.h" +#include "storage/buffile.h" +#include "eSDKOBS.h" + + +/* OBS operation types */ +typedef enum { + OBS_UNKNOWN, + OBS_READ, + OBS_WRITE, + /* + * ... + * More supported option types added here + */ +} OBSHandlerType; + +/* OBS operation options */ +#define OBS_TRANSPORT_ENCRYPT 0x0001 + +typedef struct ObsOptions { + Oid serverOid; + char* address; + bool encrypt; + char* access_key; + char* secret_access_key; + char* bucket; + char* prefix; + uint32_t chunksize; +} ObsOptions; + +typedef struct ObsCopyOptions { + bool encrypt; + uint32_t chunksize; + char* access_key; + char* secret_access_key; +} ObsCopyOptions; + +typedef struct OBSReadWriteHandler { + char* m_url; + char* m_hostname; + char* m_bucket; + /* char *m_prefix; =>m_object_info.key */ + + ObsOptions* m_obs_options; + OBSHandlerType m_type; + bool in_computing; + /* size_t m_offset; =>get_cond.start_byte */ + /* obs_bucket_context m_bucketCtx; =>m_option.bucket_options */ + + obs_options m_option; + obs_object_info m_object_info; + + union { + obs_get_conditions get_cond; + obs_put_properties put_cond; + /* + * S3ListParts + * S3ListVersions + * ... + * More OBS operation properties added here + */ + } properties; +} OBSReadWriteHandler; + +typedef struct list_service_data { + int headerPrinted; + int allDetails; + obs_status ret_status; +} list_service_data; + +extern void SetObsMemoryContext(MemoryContext mctx); +extern MemoryContext GetObsMemoryContext(void); +extern void UnSetObsMemoryContext(void); + +extern OBSReadWriteHandler *CreateObsReadWriteHandler(const char *object_url, OBSHandlerType type, + ObsCopyOptions *options); +extern OBSReadWriteHandler *CreateObsReadWriteHandlerForQuery(ObsOptions *options); +extern void ObsReadWriteHandlerSetType(OBSReadWriteHandler *handler, OBSHandlerType type); +extern void DestroyObsReadWriteHandler(OBSReadWriteHandler *handler, bool obsQueryType); + +/* ---------------- + * function prototypes for obs access method + * ---------------- + */ +/* in obs/obs_am.cpp */ +extern List *list_obs_bucket_objects(const char *uri, bool encrypt, const char *access_key, + const char *secret_access_key); +extern List *list_bucket_objects_analyze(const char *uri, bool encrypt, const char *access_key, + const char *secret_access_key); +extern List *list_bucket_objects_for_query(OBSReadWriteHandler *handler, const char *bucket, char *prefix); +extern int writeObsTempFile(OBSReadWriteHandler *handler, const char *bufferData, int64 dataSize); +extern size_t read_bucket_object(OBSReadWriteHandler *handler, char *output_buffer, uint32_t len); +extern size_t write_bucket_object(OBSReadWriteHandler *handler, BufFile *buffile, uint32_t total_len); +extern void release_object_list(List *object_list); +extern void FetchUrlProperties(const char *url, char **hostname, char **bucket, char **prefix); +extern void FetchUrlPropertiesForQuery(const char *folderName, char **bucket, char **prefix); +extern int deleteOBSObject(OBSReadWriteHandler *handler); + +/* + * Function: initOBSCacheObjet + * Description: This function is called only by postmastermain to initialize OBS CA Info + * and secret key used to encrypt OBS access key and secret access key. + * input: none + * output: none + */ +extern void initOBSCacheObject(); + +extern int find_Nth(const char* str, unsigned N, const char* find); + +extern void checkOBSServerValidity(char* addres, char* ak, char* sk, bool encrypt); + +ObsOptions* copyObsOptions(ObsOptions* from); + +void freeObsOptions(ObsOptions* obsOptions, bool freeUseIpsiFree); + +extern bool is_ip_address_format(const char * addr); +extern void encryptKeyString(char* keyStr, char destplainStr[], uint32 destplainLength); +extern void decryptKeyString(const char *keyStr, char destplainStr[], uint32 destplainLength, const char *obskey); + +#endif /* OBS_AM_H */ diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/dispatcher.h postgresql-hll-2.14/include/access/parallel_recovery/dispatcher.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/dispatcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/dispatcher.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dispatcher.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/dispatcher.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_DISPATCHER_H +#define PARALLEL_RECOVERY_DISPATCHER_H + +#include "gs_thread.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/parallel_recovery/redo_item.h" +#include "access/parallel_recovery/page_redo.h" +#include "access/parallel_recovery/txn_redo.h" +#include "access/redo_statistic.h" + +namespace parallel_recovery { + +typedef struct LogDispatcher { + MemoryContext oldCtx; + PageRedoWorker** pageWorkers; /* Array of page redo workers. */ + uint32 pageWorkerCount; /* Number of page redo workers that are ready to work. */ + uint32 totalWorkerCount; /* Number of page redo workers started. */ + TxnRedoWorker* txnWorker; /* Txn redo worker. */ + RedoItem* freeHead; /* Head of freed-item list. */ + RedoItem* freeStateHead; + RedoItem* allocatedRedoItem; + int32 pendingCount; /* Number of records pending. */ + int32 pendingMax; /* The max. pending count per batch. */ + int exitCode; /* Thread exit code. */ + uint64 totalCostTime; + uint64 txnCostTime; /* txn cost time */ + uint64 pprCostTime; + uint32 maxItemNum; + uint32 curItemNum; + + uint32* chosedWorkerIds; + uint32 chosedWorkerCount; + uint32 readyWorkerCnt; + bool checkpointNeedFullSync; +} LogDispatcher; + +extern LogDispatcher* g_dispatcher; + +#ifdef ENABLE_MULTIPLE_NODES +const static bool SUPPORT_HOT_STANDBY = false; /* don't support consistency view */ +#else +const static bool SUPPORT_HOT_STANDBY = true; +#endif +const static bool SUPPORT_FPAGE_DISPATCH = true; /* support file dispatch if true, else support page dispatche */ + +const static uint64 OUTPUT_WAIT_COUNT = 0x7FFFFFF; +const static uint64 PRINT_ALL_WAIT_COUNT = 0x7FFFFFFFF; + + +void StartRecoveryWorkers(); + +/* RedoItem lifecycle. */ +void DispatchRedoRecordToFile(XLogReaderState* record, List* expectedTLIs, TimestampTz recordXTime); +void ProcessPendingRecords(bool fullSync = false); +void ProcessTrxnRecords(bool fullSync = false); +void FreeRedoItem(RedoItem* item); + +/* Dispatcher phases. */ +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); + +/* Dispatcher states. */ +int GetDispatcherExitCode(); +bool DispatchPtrIsNull(); +uint32 GetPageWorkerCount(); +bool OnHotStandBy(); +PGPROC* StartupPidGetProc(ThreadId pid); + +/* Run-time aggregated page worker states. */ +bool IsRecoveryRestartPointSafeForWorkers(XLogRecPtr restartPoint); + +void UpdateStandbyState(HotStandbyState newState); + +/* Redo end state saved by each page worker. */ +void** GetXLogInvalidPagesFromWorkers(); + +/* Other utility functions. */ +uint32 GetWorkerId(const RelFileNode& node, BlockNumber block, ForkNumber forkNum); +bool XactWillRemoveRelFiles(XLogReaderState* record); +XLogReaderState* NewReaderState(XLogReaderState* readerState, bool bCopyState = false); +void FreeAllocatedRedoItem(); +void GetReplayedRecPtrFromWorkers(XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void DiagLogRedoRecord(XLogReaderState* record, const char* funcName); +List* CheckImcompleteAction(List* imcompleteActionList); +void SetPageWorkStateByThreadId(uint32 threadState); +RedoWaitInfo redo_get_io_event(int32 event_id); +void redo_get_wroker_statistic(uint32* realNum, RedoWorkerStatsData* worker, uint32 workerLen); +extern void redo_dump_all_stats(); +void WaitRedoWorkerIdle(); +void SendClearMarkToAllWorkers(); +extern void SetStartupBufferPinWaitBufId(int bufid); +extern void GetStartupBufferPinWaitBufId(int *bufids, uint32 len); +extern uint32 GetStartupBufferPinWaitBufLen(); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/page_redo.h postgresql-hll-2.14/include/access/parallel_recovery/page_redo.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/page_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/page_redo.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,219 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * page_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/page_redo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_PAGE_REDO_H +#define PARALLEL_RECOVERY_PAGE_REDO_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/parallel_recovery/redo_item.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/parallel_recovery/posix_semaphore.h" +#include "access/parallel_recovery/spsc_blocking_queue.h" + +namespace parallel_recovery { + + +static const uint32 PAGE_WORK_QUEUE_SIZE = 1024; + +static const uint32 PAGE_REDO_WORKER_APPLY_ITEM = 0; +static const uint32 PAGE_REDO_WORKER_SKIP_ITEM = 1; + +struct SafeRestartPoint { + SafeRestartPoint* next; + XLogRecPtr restartPoint; +}; + +struct PageRedoWorker { + /* + * The last successfully applied log record's end position + 1 as an + * atomic uint64. The type of a log record's position is XLogRecPtr. + * Here the position is stored as an uint64 so it can be read and + * written atomically. + */ + XLogRecPtr lastReplayedReadRecPtr; + XLogRecPtr lastReplayedEndRecPtr; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + PageRedoWorker* selfOrinAddr; + /* Worker id. */ + uint32 id; + /* Worker id. */ + uint32 originId; + int index; + /* Thread id */ + gs_thread_t tid; + /* The proc struct of this worker thread. */ + PGPROC* proc; + + /* --------------------------------------------- + * Initial context + * + * Global variable values at worker creation time. + */ + + /* Initial server mode from the dispatcher. */ + ServerMode initialServerMode; + /* Initial timeline ID from the dispatcher. */ + TimeLineID initialTimeLineID; + + /* --------------------------------------------- + * Redo item queue. + * + * Redo items are provided by the dispatcher and consumed by each + * worker. See AddPageRedoItem() for the use of the additional + * pending list. + */ + + /* The head of the pending item list. */ + RedoItem* pendingHead; + /* The tail of the pending item list. */ + RedoItem* pendingTail; + /* To-be-replayed log-record-list queue. */ + SPSCBlockingQueue* queue; + + /* --------------------------------------------- + * Safe restart point handling. + */ + + /* + * A list of safe recovery restart point seen by this worker. + * The restart points are listed in reverse LSN order to ease the + * lock-free implementation. + */ + SafeRestartPoint* safePointHead; + /* + * The last recovery restart point seen by the txn worker. Restart + * points before this is useless and can be removed. + */ + XLogRecPtr lastCheckedRestartPoint; + + /* --------------------------------------------- + * Per-worker run-time context + * + * States maintained by each individual page-redo worker during + * log replay. These are read by the txn-redo worker. + */ + /* --------------------------------------------- + * Global run-time context + * + * States maintained outside page-redo worker during log replay. + * Updates to these states must be synchronized to all page-redo workers. + */ + + /* + * Global standbyState set by the txn worker. + */ + HotStandbyState standbyState; + + char* DataDir; + + TransactionId RecentXmin; + /* --------------------------------------------- + * Redo end context + * + * Thread-local variable values saved after log replay has completed. + * These values are collected by each redo worker at redo end and + * are used by the dispatcher. + */ + + /* B-Tree incomplete actions. */ + void* btreeIncompleteActions; + /* XLog invalid pages. */ + void* xlogInvalidPages; + + /* --------------------------------------------- + * Phase barrier. + * + * A barrier for synchronizing the dispatcher and page redo worker + * between different phases. + */ + + /* Semaphore marking the completion of the current phase. */ + PosixSemaphore phaseMarker; + + uint32 statMulpageCnt; + uint64 statWaitReach; + uint64 statWaitReplay; + pg_atomic_uint32 readyStatus; + pg_atomic_uint32 skipItemFlg; + MemoryContext oldCtx; + int bufferPinWaitBufId; +}; + +extern THR_LOCAL PageRedoWorker* g_redoWorker; + +/* Worker lifecycle. */ +PageRedoWorker* StartPageRedoWorker(uint32 id); +void DestroyPageRedoWorker(PageRedoWorker* worker); + +/* Thread creation utility functions. */ +bool IsPageRedoWorkerProcess(int argc, char* argv[]); +void AdaptArgvForPageRedoWorker(char* argv[]); +void GetThreadNameIfPageRedoWorker(int argc, char* argv[], char** threadNamePtr); + +uint32 GetMyPageRedoWorkerOrignId(); +PGPROC* GetPageRedoWorkerProc(PageRedoWorker* worker); + +/* Worker main function. */ +void PageRedoWorkerMain(); + +/* Dispatcher phases. */ +bool SendPageRedoEndMark(PageRedoWorker* worker); +bool SendPageRedoClearMark(PageRedoWorker* worker); +void WaitPageRedoWorkerReachLastMark(PageRedoWorker* worker); + +/* Redo processing. */ +void AddPageRedoItem(PageRedoWorker* worker, RedoItem* item); +bool ProcessPendingPageRedoItems(PageRedoWorker* worker); + +/* Run-time worker states. */ +uint64 GetCompletedRecPtr(PageRedoWorker* worker); +bool IsRecoveryRestartPointSafe(PageRedoWorker* worker, XLogRecPtr restartPoint); +void SetWorkerRestartPoint(PageRedoWorker* worker, XLogRecPtr restartPoint); + +void UpdatePageRedoWorkerStandbyState(PageRedoWorker* worker, HotStandbyState newState); + +/* Redo end states. */ +void* GetBTreeIncompleteActions(PageRedoWorker* worker); +void ClearBTreeIncompleteActions(PageRedoWorker* worker); +void* GetXLogInvalidPages(PageRedoWorker* worker); +bool RedoWorkerIsIdle(PageRedoWorker* worker); +void PageRedoSetAffinity(uint32 id); + +void DumpPageRedoWorker(PageRedoWorker* worker); +void SetPageRedoWorkerIndex(int index); +void OnlyFreeRedoItem(RedoItem* item); +void SetCompletedReadEndPtr(PageRedoWorker* worker, XLogRecPtr readPtr, XLogRecPtr endPtr); +void GetCompletedReadEndPtr(PageRedoWorker* worker, XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void UpdateRecordGlobals(RedoItem* item, HotStandbyState standbyState); +void redo_dump_worker_queue_info(); + +} +#endif diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/posix_semaphore.h postgresql-hll-2.14/include/access/parallel_recovery/posix_semaphore.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/posix_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/posix_semaphore.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * posix_semaphore.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/posix_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_POSIX_SEMAPHORE_H +#define PARALLEL_RECOVERY_POSIX_SEMAPHORE_H + +#include +namespace parallel_recovery { + +typedef struct PosixSemaphore { + sem_t semaphore; + bool initialized; +} PosixSemaphore; + +void PosixSemaphoreInit(PosixSemaphore* sem, unsigned int initValue); +void PosixSemaphoreDestroy(PosixSemaphore* sem); +void PosixSemaphoreWait(PosixSemaphore* sem); +void PosixSemaphorePost(PosixSemaphore* sem); +} +#endif diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/redo_item.h postgresql-hll-2.14/include/access/parallel_recovery/redo_item.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/redo_item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/redo_item.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,155 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_item.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/redo_item.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_REDO_ITEM_H +#define PARALLEL_RECOVERY_REDO_ITEM_H + +#include "access/xlogreader.h" +#include "datatype/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/atomic.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "access/parallel_recovery/posix_semaphore.h" +#include "replication/replicainternal.h" + + +namespace parallel_recovery { + + +typedef struct BTreeIncompleteAction { + RelFileNode node; + BlockNumber block; + bool is_root; +} BTreeIncompleteAction; + +typedef struct XLogInvalidPage { + RelFileNode node; + ForkNumber fork; + BlockNumber minBlock; + Oid dbid; +} XLogInvalidPage; + +typedef union ContextUpdateData { + BTreeIncompleteAction btree; + XLogInvalidPage xlog; +} ContextUpdateData; + +typedef enum ContextUpdateType { + BTREE_FORGET_SPLIT, + BTREE_FORGET_DELETE, + XLOG_FORGET_PAGES, + XLOG_FORGET_PAGES_DB +} ContextUpdateType; + +typedef void (*ContextUpdateFunc)(const ContextUpdateData* data); + +/* + * Btree's incomplete_actions and XLog's invalid_page_tab need special + * treatment. Both use log_xxx() and forget_xxx() functions to maintain + * inconsistent states during log replay. Each of the log_xxx() functions + * remembers an inconsistent condition, and each of the forget_xxx() + * functions removes some inconsistent conditions. Because the two + * variables are thread local, the key to make it work under parallel log + * replay is to make sure the log_xxx() and the forget_xxx() for matching + * conditions are called in the same thread so they can correctly cancel + * each other. A ContextUpdateOp can be used to send a request to call + * log_xxx() or forget_xxx() from one worker to another worker. The + * protocol is to set up the ContextUpdateOp during the redo function, and + * after the record has been replayed each of the other workers checks + * the ContextUpdateOp and calls the ContextUpdateFunc if it is the + * ContextUpdateOp's designatedWorker. See comments on incomplete_actions + * and invalid_page_tab for detailed descriptions. + */ +typedef struct ContextUpdateOp { + /* The type of the operation. */ + ContextUpdateType type; + /* The data for the operation. */ + ContextUpdateData data; + /* The function that performs the operation. */ + ContextUpdateFunc func; + /* The id of the worker who needs to perform the operation. */ + uint32 designatedWorker; + /* If the operation is valid. */ + bool inUse; +} ContextUpdateOp; + +typedef struct RedoItem { + /* Old version. */ + bool oldVersion; + bool sharewithtrxn; /* if ture when designatedWorker is trxn or all and need sync with pageworker */ + bool blockbytrxn; /* if ture when designatedWorker is pagerworker and need sync with trxn */ + bool imcheckpoint; + /* Number of workers sharing this item. */ + uint32 shareCount; + /* Id of the worker designated to apply this item. */ + uint32 designatedWorker; + /* The expected timelines for this record. */ + List* expectedTLIs; + /* The timestamp of the log record if it is a transaction record. */ + TimestampTz recordXTime; + /* Next item on each worker's list. */ + RedoItem** nextByWorker; + /* Next item on the free list. */ + RedoItem* freeNext; + /* Operation to update thread-local variables after replay. */ + ContextUpdateOp contextUpdateOp; + /* Number of workers holding a reference to this item. */ + pg_atomic_uint32 refCount; + /* If this item has been replayed. */ + pg_atomic_uint32 replayed; + /* A "deep" copy of the log record. */ + XLogReaderState record; + /* Used for really free */ + RedoItem* allocatedNext; + TimestampTz syncXLogReceiptTime; + int syncXLogReceiptSource; + TransactionId RecentXmin; + ServerMode syncServerMode; + pg_atomic_uint32 freed; +} RedoItem; + +static const int32 ANY_BLOCK_ID = -1; +static const uint32 ANY_WORKER = (uint32)-1; +static const uint32 TRXN_WORKER = (uint32)-2; +static const uint32 ALL_WORKER = (uint32)-3; + +RedoItem* CreateRedoItem(XLogReaderState* record, uint32 shareCount, uint32 designatedWorker, List* expectedTLIs, + TimestampTz recordXTime, bool buseoriginal); +RedoItem* CreateLSNMarker(XLogReaderState* record, List* expectedTLIs, bool buseoriginal = false); + +bool IsLSNMarker(const RedoItem* item); + +void ApplyRedoRecord(XLogReaderState* record, bool bOld); + +static inline RedoItem* GetRedoItemPtr(XLogReaderState* record) +{ + return (RedoItem*)(((char*)record) - offsetof(RedoItem, record)); +} + + +} + +#endif diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/spsc_blocking_queue.h postgresql-hll-2.14/include/access/parallel_recovery/spsc_blocking_queue.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/spsc_blocking_queue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/spsc_blocking_queue.h 2020-12-12 17:06:43.064345677 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * spsc_blocking_queue.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/spsc_blocking_queue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_SPSC_BLOCKING_QUEUE_H +#define PARALLEL_RECOVERY_SPSC_BLOCKING_QUEUE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/parallel_recovery/posix_semaphore.h" + +namespace parallel_recovery { +typedef void (*CallBackFunc)(); + +struct SPSCBlockingQueue { + pg_atomic_uint32 writeHead; /* Array index for the next write. */ + pg_atomic_uint32 readTail; /* Array index for the next read. */ + uint32 capacity; /* Queue capacity, must be power of 2. */ + uint32 mask; /* Bit mask for computing index. */ + pg_atomic_uint32 maxUsage; + pg_atomic_uint64 totalCnt; + CallBackFunc callBackFunc; + void* buffer[1]; /* Queue buffer, the actual size is capacity. */ +}; + +SPSCBlockingQueue *SPSCBlockingQueueCreate(uint32 capacity, CallBackFunc func = NULL); +void SPSCBlockingQueueDestroy(SPSCBlockingQueue* queue); + +bool SPSCBlockingQueuePut(SPSCBlockingQueue* queue, void* element); +void* SPSCBlockingQueueTake(SPSCBlockingQueue* queue); +bool SPSCBlockingQueueIsEmpty(SPSCBlockingQueue* queue); +void* SPSCBlockingQueueTop(SPSCBlockingQueue* queue); +void SPSCBlockingQueuePop(SPSCBlockingQueue* queue); +void DumpQueue(SPSCBlockingQueue* queue); +uint32 SPSCGetQueueCount(SPSCBlockingQueue* queue); +void* SPSCTimeseriesQueueTop(SPSCBlockingQueue* queue); +} +#endif diff -uprN postgresql-hll-2.14_old/include/access/parallel_recovery/txn_redo.h postgresql-hll-2.14/include/access/parallel_recovery/txn_redo.h --- postgresql-hll-2.14_old/include/access/parallel_recovery/txn_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/parallel_recovery/txn_redo.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * txn_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/txn_redo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_TXN_REDO_H +#define PARALLEL_RECOVERY_TXN_REDO_H + +#include "access/parallel_recovery/redo_item.h" +namespace parallel_recovery { + +typedef struct TxnRedoWorker TxnRedoWorker; + +TxnRedoWorker* StartTxnRedoWorker(); +void DestroyTxnRedoWorker(TxnRedoWorker* worker); + +void AddTxnRedoItem(TxnRedoWorker* worker, RedoItem* item); +void ApplyReadyTxnLogRecords(TxnRedoWorker* worker, bool forceAll); +void MoveTxnItemToApplyQueue(TxnRedoWorker* worker); +void DumpTxnWorker(TxnRedoWorker* txnWorker); +bool IsTxnWorkerIdle(TxnRedoWorker* worker); +void FreeTxnItem(); +} +#endif diff -uprN postgresql-hll-2.14_old/include/access/printtup.h postgresql-hll-2.14/include/access/printtup.h --- postgresql-hll-2.14_old/include/access/printtup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/printtup.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * printtup.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/printtup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRINTTUP_H +#define PRINTTUP_H + +#include "utils/portal.h" +#include "distributelayer/streamProducer.h" + +extern DestReceiver* printtup_create_DR(CommandDest dest); +extern DestReceiver* createStreamDestReceiver(CommandDest dest); +extern void SetStreamReceiverParams(DestReceiver* self, StreamProducer* arg, Portal portal); +extern void SetRemoteDestReceiverParams(DestReceiver* self, Portal portal); + +extern void SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo, List* targetlist, int16* formats); + +extern void debugStartup(DestReceiver* self, int operation, TupleDesc typeinfo); +extern void debugtup(TupleTableSlot* slot, DestReceiver* self); + +/* XXX these are really in executor/spi.c */ +extern void spi_dest_startup(DestReceiver* self, int operation, TupleDesc typeinfo); +extern void spi_printtup(TupleTableSlot* slot, DestReceiver* self); + +extern void printBatch(VectorBatch* batch, DestReceiver* self); +extern void printtup(TupleTableSlot* slot, DestReceiver* self); +extern void printbatchStream(VectorBatch* batch, DestReceiver* self); +extern void printtupStream(TupleTableSlot* slot, DestReceiver* self); +extern void assembleStreamMessage(TupleTableSlot* slot, DestReceiver* self, StringInfo buf); +extern void assembleStreamBatchMessage(BatchCompressType ctype, VectorBatch* batch, StringInfo buf); + +typedef struct { /* Per-attribute information */ + Oid typoutput; /* Oid for the type's text output fn */ + Oid typsend; /* Oid for the type's binary output fn */ + bool typisvarlena; /* is it varlena (ie possibly toastable)? */ + int16 format; /* format code for this column */ + FmgrInfo finfo; /* Precomputed call info for output fn */ +} PrinttupAttrInfo; + +typedef struct { + DestReceiver pub; /* publicly-known function pointers */ + StringInfoData buf; /* output buffer */ + Portal portal; /* the Portal we are printing from */ + bool sendDescrip; /* send RowDescription at startup? */ + TupleDesc attrinfo; /* The attr info we are set up for */ + int nattrs; + PrinttupAttrInfo* myinfo; /* Cached info about each attr */ + int16* formats; /* format code for each column */ +} DR_printtup; + +typedef struct { + DestReceiver pub; /* publicly-known function pointers */ + StringInfoData buf; /* output buffer */ + Portal portal; /* the Portal we are printing from */ + bool sendDescrip; /* send RowDescription at startup? */ + TupleDesc attrinfo; /* The attr info we are set up for */ + int nattrs; + PrinttupAttrInfo* myinfo; /* Cached info about each attr */ + StreamProducer* arg; +} streamReceiver; + +#endif /* PRINTTUP_H */ diff -uprN postgresql-hll-2.14_old/include/access/psort.h postgresql-hll-2.14/include/access/psort.h --- postgresql-hll-2.14_old/include/access/psort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/psort.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * psort.h + * + * + * + * IDENTIFICATION + * src/include/access/psort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PSORT_H +#define PSORT_H + +#include "fmgr.h" + +Datum psortbuild(PG_FUNCTION_ARGS); +Datum psortoptions(PG_FUNCTION_ARGS); +Datum psortgettuple(PG_FUNCTION_ARGS); +Datum psortgetbitmap(PG_FUNCTION_ARGS); +Datum psortcanreturn(PG_FUNCTION_ARGS); + +#endif /* PSORT_H */ diff -uprN postgresql-hll-2.14_old/include/access/redo_common.h postgresql-hll-2.14/include/access/redo_common.h --- postgresql-hll-2.14_old/include/access/redo_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/redo_common.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,47 @@ +/* + * redo_common.h + * + * Utilities for replaying WAL records. + * + * PostgreSQL transaction log manager utility routines + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/redo_common.h + */ +#ifndef REDO_COMMON_H +#define REDO_COMMON_H + +#ifdef BUILD_ALONE + +#define pfree(pointer) free(pointer) +#define palloc(sz) malloc(sz) + +#define module_logging_is_on(a) false + +#define securec_check(errno, charList, ...) \ + { \ + if (unlikely(EOK != errno)) { \ + elog(ERROR, "%s : %d : securec check error.", __FILE__, __LINE__); \ + } \ + } + +#define START_CRIT_SECTION() +#define END_CRIT_SECTION() + +#define elog(...) +#define elog_finish(a, b, ...) +#define elog_start(a, b, c) +#define errstart(...) +#define ereport(...) +#define errfinish(a, ...) +#define errmodule(a) +#define errmsg(c, ...) +#define errcode(a) + +extern THR_LOCAL bool assert_enabled; + +#endif + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/redo_statistic.h postgresql-hll-2.14/include/access/redo_statistic.h --- postgresql-hll-2.14_old/include/access/redo_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/redo_statistic.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_statistic.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/redo_statistic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REDO_STATISTIC_H +#define REDO_STATISTIC_H + +#include "gs_thread.h" +#include "knl/knl_instance.h" +#include "pgstat.h" +#include "access/redo_statistic_msg.h" + +typedef Datum (*GetViewDataFunc)(); + +typedef struct RedoStatsViewObj { + char name[VIEW_NAME_SIZE]; + Oid data_type; + GetViewDataFunc get_data; +} RedoStatsViewObj; + +typedef enum RedoWorkerWaitSyncStats { + WAIT_SYNC_AP_REF = 0, /* ApplyMultiPageRecord refCount*/ + WAIT_SYNC_AP_REP, /* ApplyMultiPageRecord replayed*/ + WAIT_SYNC_AMPSH, /* ApplyMultiPageShareWithTrxnRecord */ + WAIT_SYNC_AMPSY, /* ApplyMultiPageSyncWithTrxnRecord */ + WAIT_SYNC_ARAS, /* ApplyReadyAllShareLogRecords */ + WAIT_SYNC_ARTS, /* ApplyReadyTxnShareLogRecords */ + WAIT_SYNC_GXR, /* GetXlogReader */ + WAIT_SYNC_NUM +} RedoWorkerWaitSyncStats; + +/* Redo statistics */ +typedef struct RedoWorkerStatsData { + uint32 id; /* Worker id. */ + uint32 queue_usage; /* queue usage */ + uint32 queue_max_usage; /* the max usage of queue */ + /* XLogRecPtr head_ptr; do not try to get head_ptr and tail_ptr, */ + /* XLogRecPtr tail_ptr; because the memory of redoItem maybe be freed already */ + uint64 redo_rec_count; +} RedoWorkerStatsData; + +extern const RedoStatsViewObj g_redoViewArr[REDO_VIEW_COL_SIZE]; + +extern void redo_fill_redo_event(); +extern void redo_refresh_stats(uint64 speed); +extern void redo_unlink_stats_file(); + +static const uint64 US_TRANSFER_TO_S = (1000000); +static const uint64 BYTES_TRANSFER_KBYTES = (1024); + +WaitEventIO redo_get_event_type_by_wait_type(uint32 type); +char* redo_get_name_by_wait_type(uint32 type); + + +#endif /* DOUBLE_WRITE_H */ diff -uprN postgresql-hll-2.14_old/include/access/redo_statistic_msg.h postgresql-hll-2.14/include/access/redo_statistic_msg.h --- postgresql-hll-2.14_old/include/access/redo_statistic_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/redo_statistic_msg.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_statistic_msg.h + * + * + * + * IDENTIFICATION + * src/include/access/redo_statistic_msg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REDO_STATISTIC_MSG_H +#define REDO_STATISTIC_MSG_H +#include "access/multi_redo_settings.h" + + +const static uint32 REDO_WORKER_INFO_BUFFER_SIZE = 64 * (1 + MOST_FAST_RECOVERY_LIMIT); +const static uint32 VIEW_NAME_SIZE = 32; +const static uint32 REDO_VIEW_COL_SIZE = 23; + +typedef struct RedoWaitInfo { + int64 total_duration; + int64 counter; +} RedoWaitInfo; + +typedef enum RedoWaitStats { + WAIT_READ_XLOG = 0, + WAIT_READ_DATA, + WAIT_WRITE_DATA, + WAIT_PROCESS_PENDING, + WAIT_APPLY, + WAIT_REDO_NUM +} RedoWaitStats; + +/* Redo statistics */ +typedef struct RedoStatsData { + XLogRecPtr redo_start_ptr; + int64 redo_start_time; + int64 redo_done_time; + int64 curr_time; + XLogRecPtr min_recovery_point; + XLogRecPtr read_ptr; + XLogRecPtr last_replayed_read_ptr; + XLogRecPtr recovery_done_ptr; + RedoWaitInfo wait_info[WAIT_REDO_NUM]; + uint32 speed_according_seg; + XLogRecPtr local_max_lsn; + uint32 worker_info_len; + char worker_info[REDO_WORKER_INFO_BUFFER_SIZE]; +} RedoStatsData; + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/access/reloptions.h postgresql-hll-2.14/include/access/reloptions.h --- postgresql-hll-2.14_old/include/access/reloptions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/reloptions.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,276 @@ +/* ------------------------------------------------------------------------- + * + * reloptions.h + * Core support for relation and tablespace options (pg_class.reloptions + * and pg_tablespace.spcoptions) + * + * Note: the functions dealing with text-array reloptions values declare + * them as Datum, not ArrayType *, to avoid needing to include array.h + * into a lot of low-level code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/reloptions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELOPTIONS_H +#define RELOPTIONS_H + +#include "access/htup.h" +#include "nodes/pg_list.h" +#include "nodes/primnodes.h" + +/* types supported by reloptions */ +typedef enum relopt_type { + RELOPT_TYPE_BOOL, + RELOPT_TYPE_INT, + RELOPT_TYPE_INT64, + RELOPT_TYPE_REAL, + RELOPT_TYPE_STRING +} relopt_type; + +/* kinds supported by reloptions */ +typedef enum relopt_kind { + RELOPT_KIND_HEAP = (1 << 0), + RELOPT_KIND_TOAST = (1 << 1), + RELOPT_KIND_BTREE = (1 << 2), + RELOPT_KIND_HASH = (1 << 3), + RELOPT_KIND_GIN = (1 << 4), + RELOPT_KIND_GIST = (1 << 5), + RELOPT_KIND_ATTRIBUTE = (1 << 6), + RELOPT_KIND_TABLESPACE = (1 << 7), + RELOPT_KIND_SPGIST = (1 << 8), + RELOPT_KIND_VIEW = (1 << 9), + RELOPT_KIND_PSORT = (1 << 10), + RELOPT_KIND_ZHPARSER = (1 << 11), /* text search configuration options defined by zhparser */ + RELOPT_KIND_NPARSER = (1 << 12), /* text search configuration options defined by ngram */ + RELOPT_KIND_CBTREE = (1 << 13), + RELOPT_KIND_PPARSER = (1 << 14), /* text search configuration options defined by pound */ + /* if you add a new kind, make sure you update "last_default" too */ + RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_PPARSER, + /* some compilers treat enums as signed ints, so we can't use 1 << 31 */ + RELOPT_KIND_MAX = (1 << 30) +} relopt_kind; + +/* reloption namespaces allowed for heaps -- currently only TOAST */ +#define HEAP_RELOPT_NAMESPACES \ + { \ + "toast", NULL \ + } + +/* generic struct to hold shared data */ +typedef struct relopt_gen { + const char* name; /* must be first (used as list termination + * marker) */ + const char* desc; + bits32 kinds; + int namelen; + relopt_type type; +} relopt_gen; + +/* holds a parsed value */ +typedef struct relopt_value { + relopt_gen* gen; + bool isset; + union { + bool bool_val; + int int_val; + int64 int64_val; + double real_val; + char* string_val; /* allocated separately */ + } values; +} relopt_value; + +/* reloptions records for specific variable types */ +typedef struct relopt_bool { + relopt_gen gen; + bool default_val; +} relopt_bool; + +typedef struct relopt_int { + relopt_gen gen; + int default_val; + int min; + int max; +} relopt_int; + +typedef struct relopt_int64 { + relopt_gen gen; + int64 default_val; + int64 min; + int64 max; +} relopt_int64; + +typedef struct relopt_real { + relopt_gen gen; + double default_val; + double min; + double max; +} relopt_real; + +/* validation routines for strings */ +typedef void (*validate_string_relopt)(const char* value); + +typedef struct relopt_string { + relopt_gen gen; + int default_len; + bool default_isnull; + validate_string_relopt validate_cb; + char* default_val; +} relopt_string; + +/* This is the table datatype for fillRelOptions */ +typedef struct { + const char* optname; /* option's name */ + relopt_type opttype; /* option's datatype */ + int offset; /* offset of field in result struct */ +} relopt_parse_elt; + +/* + * The following are the table append modes currently supported. + * on: mark the table on-line scaleout mode, when it is set, later data write by append mode. + * off:close on-line scaleout mode, when it is set, later date write by normal way. + * refresh:refresh start_ctid and end_ctid. + * read_only:off-line scaleout mode, when it is set, operators on table are not allowed. + * dest:the scaleout table can drop hidden columns when it's set. + */ +#define APPEND_MODE_ON "on" +#define APPEND_MODE_OFF "off" +#define APPEND_MODE_REFRESH "refresh" +#define APPEND_MODE_READ_ONLY "read_only" +#define APPEND_MODE_DEST "dest" + +/* + * These macros exist for the convenience of amoptions writers (but consider + * using fillRelOptions, which is a lot simpler). Beware of multiple + * evaluation of arguments! + * + * The last argument in the HANDLE_*_RELOPTION macros allows the caller to + * determine whether the option was set (true), or its value acquired from + * defaults (false); it can be passed as (char *) NULL if the caller does not + * need this information. + * + * optname is the option name (a string), var is the variable + * on which the value should be stored (e.g. StdRdOptions->fillfactor), and + * option is a relopt_value pointer. + * + * The normal way to use this is to loop on the relopt_value array returned by + * parseRelOptions: + * for (i = 0; options[i].gen->name; i++) + * { + * if (HAVE_RELOPTION("fillfactor", options[i]) + * { + * HANDLE_INT_RELOPTION("fillfactor", rdopts->fillfactor, options[i], &isset); + * continue; + * } + * if (HAVE_RELOPTION("default_row_acl", options[i]) + * { + * ... + * } + * ... + * if (validate) + * ereport(ERROR, + * (errmsg("unknown option"))); + * } + * + * Note that this is more or less the same that fillRelOptions does, so only + * use this if you need to do something non-standard within some option's + * code block. + */ +#define HAVE_RELOPTION(optname, option) (pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0) + +#define HANDLE_INT_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.int_val; \ + else \ + var = ((relopt_int*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.bool_val; \ + else \ + var = ((relopt_bool*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +#define HANDLE_REAL_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.real_val; \ + else \ + var = ((relopt_real*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +/* + * For use during amoptions: get the strlen of a string option + * (either default or the user defined value) + */ +#define GET_STRING_RELOPTION_LEN(option) \ + ((option).isset ? strlen((option).values.string_val) : ((relopt_string*)(option).gen)->default_len) + +#define GET_STRING_RELOPTION_DATA(option) \ + ((option).isset ? ((option).values.string_val) : ((relopt_string*)(option).gen)->default_val) + +/* + * For use by code reading options already parsed: get a pointer to the string + * value itself. "optstruct" is the StdRdOption struct or equivalent, "member" + * is the struct member corresponding to the string option + */ +#define GET_STRING_RELOPTION(optstruct, member) \ + ((optstruct)->member == 0 ? NULL : (char*)(optstruct) + (optstruct)->member) + +extern relopt_kind add_reloption_kind(void); +extern void add_bool_reloption(bits32 kinds, const char* name, const char* desc, bool default_val); +extern void add_int_reloption( + bits32 kinds, const char* name, const char* desc, int default_val, int min_val, int max_val); +extern void add_int64_reloption( + bits32 kinds, const char* name, const char* desc, int64 default_val, int64 min_val, int64 max_val); +extern void add_real_reloption( + bits32 kinds, const char* name, const char* desc, double default_val, double min_val, double max_val); +extern void add_string_reloption( + bits32 kinds, const char* name, const char* desc, const char* default_val, validate_string_relopt validator); + +extern Datum transformRelOptions(Datum old_options, List* def_list, const char* namspace, const char* const validnsps[], + bool ignore_oids, bool is_reset); +extern List* untransformRelOptions(Datum options); +extern bytea* extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions); +extern relopt_value* parseRelOptions(Datum options, bool validate, relopt_kind kind, int* numrelopts); +extern void* allocateReloptStruct(Size base, relopt_value* options, int numoptions); +extern void fillRelOptions(void* rdopts, Size basesize, relopt_value* options, int numoptions, bool validate, + const relopt_parse_elt* elems, int nelems); + +extern bytea* default_reloptions(Datum reloptions, bool validate, relopt_kind kind); +extern bytea* heap_reloptions(char relkind, Datum reloptions, bool validate); +extern bytea* index_reloptions(RegProcedure amoptions, Datum reloptions, bool validate); +extern bytea* attribute_reloptions(Datum reloptions, bool validate); +extern bytea* tablespace_reloptions(Datum reloptions, bool validate); +extern bytea* tsearch_config_reloptions(Datum tsoptions, bool validate, Oid prsoid, bool missing_ok); +extern void heaprel_set_compressing_modes(Relation rel, int16* modes); +extern int8 heaprel_get_compresslevel_from_modes(int16 modes); +extern int8 heaprel_get_compression_from_modes(int16 modes); + +extern void CheckGetServerIpAndPort(const char* Address, List** AddrList, bool IsCheck, int real_addr_max); +extern void CheckFoldernameOrFilenamesOrCfgPtah(const char* OptStr, char* OptType); +extern void CheckWaitCleanGpi(const char* value); + +extern void ForbidToSetOptionsForPSort(List* options); +extern void ForbidOutUsersToSetInnerOptions(List* user_options); +extern void ForbidToSetOptionsForAttribute(List* options); +extern void ForbidUserToSetUnsupportedOptions( + List* options, const char* optnames[], int numoptnames, const char* detail); +extern void ForbidToSetOptionsForColTbl(List* options); +extern void ForbidToSetOptionsForRowTbl(List* options); +extern void ForbidUserToSetDefinedOptions(List* options); +extern bool CheckRelOptionValue(Datum options, const char* opt_name); +extern void forbid_to_set_options_for_timeseries_tbl(List* options); +extern List* RemoveRelOption(List* options, const char* optName, bool* removed); +#endif /* RELOPTIONS_H */ + diff -uprN postgresql-hll-2.14_old/include/access/relscan.h postgresql-hll-2.14/include/access/relscan.h --- postgresql-hll-2.14_old/include/access/relscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/relscan.h 2020-12-12 17:06:43.065345690 +0800 @@ -0,0 +1,160 @@ +/* ------------------------------------------------------------------------- + * + * relscan.h + * POSTGRES relation scan descriptor definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/relscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELSCAN_H +#define RELSCAN_H + +#include "access/genam.h" +#include "access/heapam.h" +#include "access/itup.h" +#include "access/tupdesc.h" + +#define PARALLEL_SCAN_GAP 100 + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ +#define IsValidScanDesc(sd) (sd != NULL) + +typedef struct HeapScanDescData { + TableScanDescData rs_base; /* AM independent part of the descriptor */ + + /* scan parameters */ + bool rs_allow_strat; /* allow or disallow use of access strategy */ + + /* scan current state */ + TupleDesc rs_tupdesc; /* heap tuple descriptor for rs_ctup */ + /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ + ItemPointerData rs_mctid; /* marked scan position, if any */ + + /* these fields only used in page-at-a-time mode and for bitmap scans */ + int rs_mindex; /* marked tuple's saved index */ + int dop; /* scan parallel degree */ + /* put decompressed tuple data into rs_ctbuf be careful , when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr + */ + HeapTupleData rs_ctup; /* current tuple in scan, if any */ + HeapTupleHeaderData rs_ctbuf_hdr; +} HeapScanDescData; + +#define SizeofHeapScanDescData (offsetof(HeapScanDescData, rs_ctbuf_hdr) + SizeofHeapTupleHeader) + +struct ScanState; + +/* + * The ScanDescData for hash-bucket table + */ +typedef struct HBktTblScanDescData { + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; + + struct ScanState* scanState; + List* hBktList; /* hash bucket list that used to scan */ + int curr_slot; + Relation currBktRel; + TableScanDesc currBktScan; +} HBktTblScanDescData; + +typedef struct HBktTblScanDescData* HBktTblScanDesc; + +struct IndexFetchTableData; +/* + * We use the same IndexScanDescData structure for both amgettuple-based + * and amgetbitmap-based index scans. Some fields are only relevant in + * amgettuple-based scans. + */ +typedef struct IndexScanDescData { + /* scan parameters */ + // !! heapRelation MUST BE FIRST MEMBER !! + Relation heapRelation; /* heap relation descriptor, or NULL */ + + Relation indexRelation; /* index relation descriptor */ + GPIScanDesc xs_gpi_scan; /* global partition index scan use information */ + Snapshot xs_snapshot; /* snapshot to see */ + int numberOfKeys; /* number of index qualifier conditions */ + int numberOfOrderBys; /* number of ordering operators */ + ScanKey keyData; /* array of index qualifier descriptors */ + ScanKey orderByData; /* array of ordering op descriptors */ + bool xs_want_itup; /* caller requests index tuples */ + bool xs_want_ext_oid; /* global partition index need partition oid */ + + /* signaling to index AM about killing index tuples */ + bool kill_prior_tuple; /* last-returned tuple is dead */ + bool ignore_killed_tuples; /* do not return killed entries */ + bool xactStartedInRecovery; /* prevents killing/seeing killed + * tuples */ + + /* index access method's private state */ + void* opaque; /* access-method-specific info */ + + /* in an index-only scan, this is valid after a successful amgettuple */ + IndexTuple xs_itup; /* index tuple returned by AM */ + TupleDesc xs_itupdesc; /* rowtype descriptor of xs_itup */ + + /* xs_ctup/xs_cbuf/xs_recheck are valid after a successful index_getnext */ + HeapTupleData xs_ctup; /* current heap tuple, if any */ + Buffer xs_cbuf; /* current heap buffer in scan, if any */ + /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ + bool xs_recheck; /* T means scan keys must be rechecked */ + + /* state data for traversing HOT chains in index_getnext */ + bool xs_continue_hot; /* T if must keep walking HOT chain */ + IndexFetchTableData *xs_heapfetch; + /* put decompressed heap tuple data into xs_ctbuf_hdr be careful! when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr + */ + HeapTupleHeaderData xs_ctbuf_hdr; + /* DO NOT add any other members here. xs_ctbuf_hdr must be the last one. */ +} IndexScanDescData; + +#define SizeofIndexScanDescData (offsetof(IndexScanDescData, xs_ctbuf_hdr) + SizeofHeapTupleHeader) + +/* Get partition heap oid for bitmap index scan */ +#define IndexScanGetPartHeapOid(scan) \ + ((scan)->indexRelation != NULL \ + ? (RelationIsPartition((scan)->indexRelation) ? (scan)->indexRelation->rd_partHeapOid : InvalidOid) \ + : InvalidOid) + +/* + * When the global partition index is used for index scanning, + * checks whether the partition table needs to be + * switched each time an indextuple is obtained. + */ +#define IndexScanNeedSwitchPartRel(scan) \ + ((scan)->xs_want_ext_oid && GPIScanCheckPartOid((scan)->xs_gpi_scan, (scan)->heapRelation->rd_id)) + +typedef struct HBktIdxScanDescData { + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; /* heap relation descriptor */ + + Relation idx_rd; /* index relation descriptor */ + struct ScanState* scanState; + List* hBktList; + int curr_slot; + Relation currBktHeapRel; + Relation currBktIdxRel; + IndexScanDescData* currBktIdxScan; +} HBktIdxScanDescData; + +typedef HBktIdxScanDescData* HBktIdxScanDesc; + +/* Struct for heap-or-index scans of system tables */ +typedef struct SysScanDescData { + Relation heap_rel; /* catalog being scanned */ + Relation irel; /* NULL if doing heap scan */ + HeapScanDesc scan; /* only valid in heap-scan case */ + IndexScanDesc iscan; /* only valid in index-scan case */ +} SysScanDescData; + +#endif /* RELSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/access/rewriteheap.h postgresql-hll-2.14/include/access/rewriteheap.h --- postgresql-hll-2.14_old/include/access/rewriteheap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/rewriteheap.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * rewriteheap.h + * Declarations for heap rewrite support functions + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/access/rewriteheap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITE_HEAP_H +#define REWRITE_HEAP_H + +#include "access/htup.h" +#include "storage/itemptr.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +/* struct definition is private to rewriteheap.c */ +typedef struct RewriteStateData* RewriteState; + +extern RewriteState begin_heap_rewrite( + Relation OldHeap, Relation NewHeap, TransactionId OldestXmin, TransactionId FreezeXid, bool use_wal); +extern void end_heap_rewrite(RewriteState state); +extern void rewrite_heap_tuple(RewriteState state, HeapTuple oldTuple, HeapTuple newTuple); +extern bool rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple); + +// private memory context must be used for forming new tuples and caching them +// +extern MemoryContext get_heap_rewrite_memcxt(RewriteState state); +extern bool use_heap_rewrite_memcxt(RewriteState state); +extern void RewriteAndCompressTup(RewriteState state, HeapTuple old_tuple, HeapTuple new_tuple); +/* + * On-Disk data format for an individual logical rewrite mapping. + */ +typedef struct LogicalRewriteMappingData { + RelFileNode old_node; + RelFileNode new_node; + ItemPointerData old_tid; + ItemPointerData new_tid; +} LogicalRewriteMappingData; + +/* --- + * The filename consists out of the following, dash separated, + * components: + * 1) database oid or InvalidOid for shared relations + * 2) the oid of the relation + * 3) xid we are mapping for + * 4) upper 32bit of the LSN at which a rewrite started + * 5) lower 32bit of the LSN at which a rewrite started + * 6) xid of the xact performing the mapping + * --- + */ +#define LOGICAL_REWRITE_FORMAT "map-%x-%x-%X_%X-%lx-%lx" +void CheckPointLogicalRewriteHeap(void); + +#endif /* REWRITE_HEAP_H */ diff -uprN postgresql-hll-2.14_old/include/access/rmgr.h postgresql-hll-2.14/include/access/rmgr.h --- postgresql-hll-2.14_old/include/access/rmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/rmgr.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,31 @@ +/* + * rmgr.h + * + * Resource managers definition + * + * src/include/access/rmgr.h + */ +#ifndef RMGR_H +#define RMGR_H + +typedef uint8 RmgrId; + +/* + * Built-in resource managers + * + * The actual numerical values for each rmgr ID are defined by the order + * of entries in rmgrlist.h. + * + * Note: RM_MAX_ID must fit in RmgrId; widening that type will affect the XLOG + * file format. + */ +#define PG_RMGR(symname, name, redo, parse, startup, cleanup, restartpoint) symname, + +typedef enum RmgrIds { +#include "access/rmgrlist.h" + RM_NEXT_ID +} RmgrIds; + +#undef PG_RMGR +#define RM_MAX_ID (RM_NEXT_ID - 1) +#endif /* RMGR_H */ diff -uprN postgresql-hll-2.14_old/include/access/rmgrlist.h postgresql-hll-2.14/include/access/rmgrlist.h --- postgresql-hll-2.14_old/include/access/rmgrlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/rmgrlist.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,63 @@ +/* --------------------------------------------------------------------------------------- + * + * rmgrlist.h + * + * + * The resource manager list is kept in its own source file for possible + * use by automatic tools. The exact representation of a rmgr is determined + * by the PG_RMGR macro, which is not defined in this file; it can be + * defined by the caller for special purposes. + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/rmgrlist.h + * + * --------------------------------------------------------------------------------------- + */ + +/* there is deliberately not an #ifndef RMGRLIST_H here + * The header file needs to be repeated in the rmgrdesc.cpp package for array initialization. + * An #ifndef RMGRLIST_H cannot be added. + */ + +/* + * List of resource manager entries. Note that order of entries defines the + * numerical values of each rmgr's ID, which is stored in WAL records. New + * entries should be added at the end, to avoid changing IDs of existing + * entries. + * + * Changes to this list possibly need an XLOG_PAGE_MAGIC bump. + */ + +/* symbol name, textual name, redo, desc, identify, startup, cleanup */ +PG_RMGR(RM_XLOG_ID, "XLOG", xlog_redo, xlog_desc, NULL, NULL, NULL) +PG_RMGR(RM_XACT_ID, "Transaction", xact_redo, xact_desc, NULL, NULL, NULL) +PG_RMGR(RM_SMGR_ID, "Storage", smgr_redo, smgr_desc, NULL, NULL, NULL) +PG_RMGR(RM_CLOG_ID, "CLOG", clog_redo, clog_desc, NULL, NULL, NULL) +PG_RMGR(RM_DBASE_ID, "Database", dbase_redo, dbase_desc, NULL, NULL, NULL) +PG_RMGR(RM_TBLSPC_ID, "Tablespace", tblspc_redo, tblspc_desc, NULL, NULL, NULL) +PG_RMGR(RM_MULTIXACT_ID, "MultiXact", multixact_redo, multixact_desc, NULL, NULL, NULL) +PG_RMGR(RM_RELMAP_ID, "RelMap", relmap_redo, relmap_desc, NULL, NULL, NULL) +#ifndef ENABLE_MULTIPLE_NODES +PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, StandbyXlogStartup, StandbyXlogCleanup, StandbySafeRestartpoint) +#else +PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, NULL, NULL, NULL) +#endif +PG_RMGR(RM_HEAP2_ID, "Heap2", heap2_redo, heap2_desc, NULL, NULL, NULL) +PG_RMGR(RM_HEAP_ID, "Heap", heap_redo, heap_desc, NULL, NULL, NULL) +PG_RMGR(RM_BTREE_ID, "Btree", btree_redo, btree_desc, btree_xlog_startup, btree_xlog_cleanup, btree_safe_restartpoint) +PG_RMGR(RM_HASH_ID, "Hash", hash_redo, hash_desc, NULL, NULL, NULL) +PG_RMGR(RM_GIN_ID, "Gin", gin_redo, gin_desc, gin_xlog_startup, gin_xlog_cleanup, NULL) +PG_RMGR(RM_GIST_ID, "Gist", gist_redo, gist_desc, gist_xlog_startup, gist_xlog_cleanup, NULL) +PG_RMGR(RM_SEQ_ID, "Sequence", seq_redo, seq_desc, NULL, NULL, NULL) +PG_RMGR(RM_SPGIST_ID, "SPGist", spg_redo, spg_desc, spg_xlog_startup, spg_xlog_cleanup, NULL) +PG_RMGR(RM_SLOT_ID, "Slot", slot_redo, slot_desc, NULL, NULL, NULL) +PG_RMGR(RM_HEAP3_ID, "Heap3", heap3_redo, heap3_desc, NULL, NULL, NULL) +#ifdef ENABLE_MULTIPLE_NODES +PG_RMGR(RM_BARRIER_ID, "Barrier", barrier_redo, barrier_desc, NULL, NULL, NULL) +#endif +#ifdef ENABLE_MOT +PG_RMGR(RM_MOT_ID, "MOT", MOTRedo, MOTDesc, NULL, NULL, NULL) +#endif diff -uprN postgresql-hll-2.14_old/include/access/sdir.h postgresql-hll-2.14/include/access/sdir.h --- postgresql-hll-2.14_old/include/access/sdir.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/sdir.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,52 @@ +/* ------------------------------------------------------------------------- + * + * sdir.h + * POSTGRES scan direction definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/sdir.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SDIR_H +#define SDIR_H + +/* + * ScanDirection was an int8 for no apparent reason. I kept the original + * values because I'm not sure if I'll break anything otherwise. -ay 2/95 + */ +typedef enum ScanDirection { + BackwardScanDirection = -1, + NoMovementScanDirection = 0, + ForwardScanDirection = 1 +} ScanDirection; + +/* + * ScanDirectionIsValid + * True iff scan direction is valid. + */ +#define ScanDirectionIsValid(direction) \ + ((bool)(BackwardScanDirection <= (direction) && (direction) <= ForwardScanDirection)) + +/* + * ScanDirectionIsBackward + * True iff scan direction is backward. + */ +#define ScanDirectionIsBackward(direction) ((bool)((direction) == BackwardScanDirection)) + +/* + * ScanDirectionIsNoMovement + * True iff scan direction indicates no movement. + */ +#define ScanDirectionIsNoMovement(direction) ((bool)((direction) == NoMovementScanDirection)) + +/* + * ScanDirectionIsForward + * True iff scan direction is forward. + */ +#define ScanDirectionIsForward(direction) ((bool)((direction) == ForwardScanDirection)) + +#endif /* SDIR_H */ diff -uprN postgresql-hll-2.14_old/include/access/skey.h postgresql-hll-2.14/include/access/skey.h --- postgresql-hll-2.14_old/include/access/skey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/skey.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,159 @@ +/* ------------------------------------------------------------------------- + * + * skey.h + * POSTGRES scan key definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/skey.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SKEY_H +#define SKEY_H + +#include "access/attnum.h" +#include "fmgr.h" + +/* + * Strategy numbers identify the semantics that particular operators have + * with respect to particular operator classes. In some cases a strategy + * subtype (an OID) is used as further information. + */ +typedef uint16 StrategyNumber; + +#define InvalidStrategy ((StrategyNumber)0) + +/* + * We define the strategy numbers for B-tree indexes here, to avoid having + * to import access/nbtree.h into a lot of places that shouldn't need it. + */ +#define BTLessStrategyNumber 1 +#define BTLessEqualStrategyNumber 2 +#define BTEqualStrategyNumber 3 +#define BTGreaterEqualStrategyNumber 4 +#define BTGreaterStrategyNumber 5 + +#define BTMaxStrategyNumber 5 + +#ifndef MADLIB +static_assert(BTMaxStrategyNumber == 5, "Strategy Number is not matched"); +#endif + +/* + * A ScanKey represents the application of a comparison operator between + * a table or index column and a constant. When it's part of an array of + * ScanKeys, the comparison conditions are implicitly ANDed. The index + * column is the left argument of the operator, if it's a binary operator. + * (The data structure can support unary indexable operators too; in that + * case sk_argument would go unused. This is not currently implemented.) + * + * For an index scan, sk_strategy and sk_subtype must be set correctly for + * the operator. When using a ScanKey in a heap scan, these fields are not + * used and may be set to InvalidStrategy/InvalidOid. + * + * If the operator is collation-sensitive, sk_collation must be set + * correctly as well. + * + * A ScanKey can also represent a ScalarArrayOpExpr, that is a condition + * "column op ANY(ARRAY[...])". This is signaled by the SK_SEARCHARRAY + * flag bit. The sk_argument is not a value of the operator's right-hand + * argument type, but rather an array of such values, and the per-element + * comparisons are to be ORed together. + * + * A ScanKey can also represent a condition "column IS NULL" or "column + * IS NOT NULL"; these cases are signaled by the SK_SEARCHNULL and + * SK_SEARCHNOTNULL flag bits respectively. The argument is always NULL, + * and the sk_strategy, sk_subtype, sk_collation, and sk_func fields are + * not used (unless set by the index AM). + * + * SK_SEARCHARRAY, SK_SEARCHNULL and SK_SEARCHNOTNULL are supported only + * for index scans, not heap scans; and not all index AMs support them, + * only those that set amsearcharray or amsearchnulls respectively. + * + * A ScanKey can also represent an ordering operator invocation, that is + * an ordering requirement "ORDER BY indexedcol op constant". This looks + * the same as a comparison operator, except that the operator doesn't + * (usually) yield boolean. We mark such ScanKeys with SK_ORDER_BY. + * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. + * + * Note: in some places, ScanKeys are used as a convenient representation + * for the invocation of an access method support procedure. In this case + * sk_strategy/sk_subtype are not meaningful (but sk_collation can be); and + * sk_func may refer to a function that returns something other than boolean. + */ +typedef struct ScanKeyData { + uint32 sk_flags; /* flags, see below */ + AttrNumber sk_attno; /* table or index column number */ + StrategyNumber sk_strategy; /* operator strategy number */ + Oid sk_subtype; /* strategy subtype */ + Oid sk_collation; /* collation to use, if needed */ + FmgrInfo sk_func; /* lookup info for function to call */ + Datum sk_argument; /* data to compare */ +} ScanKeyData; + +typedef ScanKeyData* ScanKey; + +/* + * About row comparisons: + * + * The ScanKey data structure also supports row comparisons, that is ordered + * tuple comparisons like (x, y) > (c1, c2), having the SQL-spec semantics + * "x > c1 OR (x = c1 AND y > c2)". Note that this is currently only + * implemented for btree index searches, not for heapscans or any other index + * type. A row comparison is represented by a "header" ScanKey entry plus + * a separate array of ScanKeys, one for each column of the row comparison. + * The header entry has these properties: + * sk_flags = SK_ROW_HEADER + * sk_attno = index column number for leading column of row comparison + * sk_strategy = btree strategy code for semantics of row comparison + * (ie, < <= > or >=) + * sk_subtype, sk_collation, sk_func: not used + * sk_argument: pointer to subsidiary ScanKey array + * If the header is part of a ScanKey array that's sorted by attno, it + * must be sorted according to the leading column number. + * + * The subsidiary ScanKey array appears in logical column order of the row + * comparison, which may be different from index column order. The array + * elements are like a normal ScanKey array except that: + * sk_flags must include SK_ROW_MEMBER, plus SK_ROW_END in the last + * element (needed since row header does not include a count) + * sk_func points to the btree comparison support function for the + * opclass, NOT the operator's implementation function. + * sk_strategy must be the same in all elements of the subsidiary array, + * that is, the same as in the header entry. + * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. + */ + +/* + * ScanKeyData sk_flags + * + * sk_flags bits 0-15 are reserved for system-wide use (symbols for those + * bits should be defined here). Bits 16-31 are reserved for use within + * individual index access methods. + */ +#define SK_ISNULL 0x0001 /* sk_argument is NULL */ +#define SK_UNARY 0x0002 /* unary operator (not supported!) */ +#define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */ +#define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */ +#define SK_ROW_END 0x0010 /* last row comparison member */ +#define SK_SEARCHARRAY 0x0020 /* scankey represents ScalarArrayOp */ +#define SK_SEARCHNULL 0x0040 /* scankey represents "col IS NULL" */ +#define SK_SEARCHNOTNULL \ + 0x0080 /* scankey represents "col IS NOT \ + * NULL" */ +#define SK_ORDER_BY 0x0100 /* scankey is for ORDER BY op */ + +/* + * prototypes for functions in access/common/scankey.c + */ +extern void ScanKeyInit( + ScanKey entry, AttrNumber attribute_number, StrategyNumber strategy, RegProcedure procedure, Datum argument); +extern void ScanKeyEntryInitialize(ScanKey entry, uint32 flags, AttrNumber attribute_number, StrategyNumber strategy, + Oid subtype, Oid collation, RegProcedure procedure, Datum argument); +extern void ScanKeyEntryInitializeWithInfo(ScanKey entry, uint32 flags, AttrNumber attribute_number, + StrategyNumber strategy, Oid subtype, Oid collation, FmgrInfo* finfo, Datum argument); + +#endif /* SKEY_H */ diff -uprN postgresql-hll-2.14_old/include/access/slru.h postgresql-hll-2.14/include/access/slru.h --- postgresql-hll-2.14_old/include/access/slru.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/slru.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,174 @@ +/* ------------------------------------------------------------------------- + * + * slru.h + * Simple LRU buffering for transaction status logfiles + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/slru.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SLRU_H +#define SLRU_H + +#include "access/xlogdefs.h" +#include "storage/lwlock.h" + +/* + * Define SLRU segment size. A page is the same BLCKSZ as is used everywhere + * else in Postgres. The segment size can be chosen somewhat arbitrarily; + * we make it 2048 pages by default, or 16Mb, i.e. 64M transactions for CLOG + * or 2M transactions for SUBTRANS. + * + * Note: slru.c currently assumes that segment file names will be twelve hex + * digits. This sets a lower bound on the segment size ( 4M transactions + * for 64-bit TransactionIds). + */ +#define SLRU_PAGES_PER_SEGMENT 2048 + +/* Maximum length of an SLRU name */ +#define SLRU_MAX_NAME_LENGTH 64 + +/* + * Page status codes. Note that these do not include the "dirty" bit. + * page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states; + * in the latter case it implies that the page has been re-dirtied since + * the write started. + */ +typedef enum { + SLRU_PAGE_EMPTY, /* buffer is not in use */ + SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */ + SLRU_PAGE_VALID, /* page is valid and not being written */ + SLRU_PAGE_WRITE_IN_PROGRESS, /* page is being written out */ +} SlruPageStatus; + +/* Saved info for SlruReportIOError */ +typedef enum { + SLRU_OPEN_FAILED, + SLRU_SEEK_FAILED, + SLRU_READ_FAILED, + SLRU_WRITE_FAILED, + SLRU_FSYNC_FAILED, + SLRU_CLOSE_FAILED, + SLRU_MAX_FAILED // used to initialize slru_errcause +} SlruErrorCause; + +/* + * Shared-memory state + */ +typedef struct SlruSharedData { + LWLock* control_lock; + + /* Number of buffers managed by this SLRU structure */ + int num_slots; + + /* + * Arrays holding info for each buffer slot. Page number is undefined + * when status is EMPTY, as is page_lru_count. + */ + char** page_buffer; + SlruPageStatus* page_status; + bool* page_dirty; + int64* page_number; + int* page_lru_count; + LWLock** buffer_locks; + + /* + * Optional array of WAL flush LSNs associated with entries in the SLRU + * pages. If not zero/NULL, we must flush WAL before writing pages (true + * for pg_clog, false for multixact, pg_subtrans, pg_notify). group_lsn[] + * has lsn_groups_per_page entries per buffer slot, each containing the + * highest LSN known for a contiguous group of SLRU entries on that slot's + * page. + */ + XLogRecPtr* group_lsn; + int lsn_groups_per_page; + + /* ---------- + * We mark a page "most recently used" by setting + * page_lru_count[slotno] = ++cur_lru_count; + * The oldest page is therefore the one with the highest value of + * cur_lru_count - page_lru_count[slotno] + * The counts will eventually wrap around, but this calculation still + * works as long as no page's age exceeds INT_MAX counts. + * ---------- + */ + int cur_lru_count; + + /* + * latest_page_number is the page number of the current end of the log in PG, + * this is not critical data, since we use it only to avoid swapping out + * the latest page. But not in MPPDB. Older MPPDB version use it to keep the + * latest active page. The latest active page is same as the current end page + * of the log in PG, but keep in mind that these two might be different in MPPDB + * as the larger xid might occur in datanode before minor xid. + */ + int64 latest_page_number; + + /* + * In StartupCLOG or TrimCLOG during recovery, latest_page_number is determined + * by the computed ShmemVariableCache->nextXid after replaying all xlog records. + * If ShmemVariableCache->nextXid happens to be the first xid of a new clog page, + * extension of this page will not occur due to the shortcut mechanism of ExtendCLOG. + * We distinguish such scenario by setting force_check_first_xid true and bypass the shortcut + * in order not to miss the clog page extension. + */ + bool force_check_first_xid; + +} SlruSharedData; + +typedef SlruSharedData* SlruShared; + +/* + * SlruCtlData is an unshared structure that points to the active information + * in shared memory. + */ +typedef struct SlruCtlData { + SlruShared shared; + + /* + * This flag tells whether to fsync writes (true for pg_clog and multixact + * stuff, false for pg_subtrans and pg_notify). + */ + bool do_fsync; + + /* + * Dir is set during SimpleLruInit and does not change thereafter. Since + * it's always the same, it doesn't need to be in shared memory. + */ + char dir[64]; +} SlruCtlData; + +typedef SlruCtlData* SlruCtl; + +extern Size SimpleLruShmemSize(int nslots, int nlsns); +extern void SimpleLruInit( + SlruCtl ctl, const char* name, int trancheId, int nslots, int nlsns, LWLock* ctllock, const char* subdir, int index = 0); +extern int SimpleLruZeroPage(SlruCtl ctl, int64 pageno, bool* pbZeroPage = NULL); +extern int SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok, TransactionId xid); +extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid); +extern int SimpleLruReadPage_ReadOnly_Locked(SlruCtl ctl, int64 pageno, TransactionId xid); +extern void SimpleLruWritePage(SlruCtl ctl, int slotno); +extern int SimpleLruFlush(SlruCtl ctl, bool checkpoint); +extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage); + +typedef bool (*SlruScanCallback)(SlruCtl ctl, const char* filename, int64 segpage, const void* data); +extern bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, const void* data); + +/* SlruScanDirectory public callbacks */ +extern bool SlruScanDirCbReportPresence(SlruCtl ctl, const char* filename, int64 segpage, const void* data); +extern bool SlruScanDirCbDeleteAll(SlruCtl ctl, const char* filename, int64 segpage, const void* data); + +#ifdef ENABLE_UT + +extern void ut_SetErrCause(int errcause); +extern void ut_SlruReportIOError(SlruCtl ctl, int64 pageno, TransactionId xid); + +#endif + +extern void SimpleLruWaitIO(SlruCtl ctl, int slotno); +extern bool SlruScanDirCbDeleteCutoff(SlruCtl ctl, const char* filename, int64 segpage, const void* data); + +#endif /* SLRU_H */ diff -uprN postgresql-hll-2.14_old/include/access/spgist.h postgresql-hll-2.14/include/access/spgist.h --- postgresql-hll-2.14_old/include/access/spgist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/spgist.h 2020-12-12 17:06:43.066345703 +0800 @@ -0,0 +1,193 @@ +/* ------------------------------------------------------------------------- + * + * spgist.h + * Public header file for SP-GiST access method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/spgist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPGIST_H +#define SPGIST_H + +#include "access/skey.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "fmgr.h" + +/* reloption parameters */ +#define SPGIST_MIN_FILLFACTOR 10 +#define SPGIST_DEFAULT_FILLFACTOR 80 + +/* SPGiST opclass support function numbers */ +#define SPGIST_CONFIG_PROC 1 +#define SPGIST_CHOOSE_PROC 2 +#define SPGIST_PICKSPLIT_PROC 3 +#define SPGIST_INNER_CONSISTENT_PROC 4 +#define SPGIST_LEAF_CONSISTENT_PROC 5 +#define SPGISTNProc 5 + +/* + * Argument structs for spg_config method + */ +typedef struct spgConfigIn { + Oid attType; /* Data type to be indexed */ +} spgConfigIn; + +typedef struct spgConfigOut { + Oid prefixType; /* Data type of inner-tuple prefixes */ + Oid labelType; /* Data type of inner-tuple node labels */ + bool canReturnData; /* Opclass can reconstruct original data */ + bool longValuesOK; /* Opclass can cope with values > 1 page */ +} spgConfigOut; + +/* + * Argument structs for spg_choose method + */ +typedef struct spgChooseIn { + Datum datum; /* original datum to be indexed */ + Datum leafDatum; /* current datum to be stored at leaf */ + int level; /* current level (counting from zero) */ + + /* Data from current inner tuple */ + bool allTheSame; /* tuple is marked all-the-same? */ + bool hasPrefix; /* tuple has a prefix? */ + Datum prefixDatum; /* if so, the prefix value */ + int nNodes; /* number of nodes in the inner tuple */ + Datum* nodeLabels; /* node label values (NULL if none) */ +} spgChooseIn; + +typedef enum spgChooseResultType { + spgMatchNode = 1, /* descend into existing node */ + spgAddNode, /* add a node to the inner tuple */ + spgSplitTuple /* split inner tuple (change its prefix) */ +} spgChooseResultType; + +typedef struct spgChooseOut { + spgChooseResultType resultType; /* action code, see above */ + union { + struct /* results for spgMatchNode */ + { + int nodeN; /* descend to this node (index from 0) */ + int levelAdd; /* increment level by this much */ + Datum restDatum; /* new leaf datum */ + } matchNode; + struct /* results for spgAddNode */ + { + Datum nodeLabel; /* new node's label */ + int nodeN; /* where to insert it (index from 0) */ + } addNode; + struct /* results for spgSplitTuple */ + { + /* Info to form new inner tuple with one node */ + bool prefixHasPrefix; /* tuple should have a prefix? */ + Datum prefixPrefixDatum; /* if so, its value */ + Datum nodeLabel; /* node's label */ + + /* Info to form new lower-level inner tuple with all old nodes */ + bool postfixHasPrefix; /* tuple should have a prefix? */ + Datum postfixPrefixDatum; /* if so, its value */ + } splitTuple; + } result; +} spgChooseOut; + +/* + * Argument structs for spg_picksplit method + */ +typedef struct spgPickSplitIn { + int nTuples; /* number of leaf tuples */ + Datum* datums; /* their datums (array of length nTuples) */ + int level; /* current level (counting from zero) */ +} spgPickSplitIn; + +typedef struct spgPickSplitOut { + bool hasPrefix; /* new inner tuple should have a prefix? */ + Datum prefixDatum; /* if so, its value */ + + int nNodes; /* number of nodes for new inner tuple */ + Datum* nodeLabels; /* their labels (or NULL for no labels) */ + + int* mapTuplesToNodes; /* node index for each leaf tuple */ + Datum* leafTupleDatums; /* datum to store in each new leaf tuple */ +} spgPickSplitOut; + +/* + * Argument structs for spg_inner_consistent method + */ +typedef struct spgInnerConsistentIn { + ScanKey scankeys; /* array of operators and comparison values */ + int nkeys; /* length of array */ + + Datum reconstructedValue; /* value reconstructed at parent */ + int level; /* current level (counting from zero) */ + bool returnData; /* original data must be returned? */ + + /* Data from current inner tuple */ + bool allTheSame; /* tuple is marked all-the-same? */ + bool hasPrefix; /* tuple has a prefix? */ + Datum prefixDatum; /* if so, the prefix value */ + int nNodes; /* number of nodes in the inner tuple */ + Datum* nodeLabels; /* node label values (NULL if none) */ +} spgInnerConsistentIn; + +typedef struct spgInnerConsistentOut { + int nNodes; /* number of child nodes to be visited */ + int* nodeNumbers; /* their indexes in the node array */ + int* levelAdds; /* increment level by this much for each */ + Datum* reconstructedValues; /* associated reconstructed values */ +} spgInnerConsistentOut; + +/* + * Argument structs for spg_leaf_consistent method + */ +typedef struct spgLeafConsistentIn { + ScanKey scankeys; /* array of operators and comparison values */ + int nkeys; /* length of array */ + + Datum reconstructedValue; /* value reconstructed at parent */ + int level; /* current level (counting from zero) */ + bool returnData; /* original data must be returned? */ + + Datum leafDatum; /* datum in leaf tuple */ +} spgLeafConsistentIn; + +typedef struct spgLeafConsistentOut { + Datum leafValue; /* reconstructed original data, if any */ + bool recheck; /* set true if operator must be rechecked */ +} spgLeafConsistentOut; + +/* spginsert.c */ +extern Datum spgmerge(PG_FUNCTION_ARGS); +extern Datum spgbuild(PG_FUNCTION_ARGS); +extern Datum spgbuildempty(PG_FUNCTION_ARGS); +extern Datum spginsert(PG_FUNCTION_ARGS); + +/* spgscan.c */ +extern Datum spgbeginscan(PG_FUNCTION_ARGS); +extern Datum spgendscan(PG_FUNCTION_ARGS); +extern Datum spgrescan(PG_FUNCTION_ARGS); +extern Datum spgmarkpos(PG_FUNCTION_ARGS); +extern Datum spgrestrpos(PG_FUNCTION_ARGS); +extern Datum spggetbitmap(PG_FUNCTION_ARGS); +extern Datum spggettuple(PG_FUNCTION_ARGS); +extern Datum spgcanreturn(PG_FUNCTION_ARGS); + +/* spgutils.c */ +extern Datum spgoptions(PG_FUNCTION_ARGS); + +/* spgvacuum.c */ +extern Datum spgbulkdelete(PG_FUNCTION_ARGS); +extern Datum spgvacuumcleanup(PG_FUNCTION_ARGS); + +/* spgxlog.c */ +extern void spg_redo(XLogReaderState* record); +extern void spg_desc(StringInfo buf, XLogReaderState* record); +extern void spg_xlog_startup(void); +extern void spg_xlog_cleanup(void); +extern bool IsSpgistVacuum(XLogReaderState* record); + +#endif /* SPGIST_H */ diff -uprN postgresql-hll-2.14_old/include/access/spgist_private.h postgresql-hll-2.14/include/access/spgist_private.h --- postgresql-hll-2.14_old/include/access/spgist_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/spgist_private.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,610 @@ +/* ------------------------------------------------------------------------- + * + * spgist_private.h + * Private declarations for SP-GiST access method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/spgist_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPGIST_PRIVATE_H +#define SPGIST_PRIVATE_H + +#include "access/itup.h" +#include "access/spgist.h" +#include "nodes/tidbitmap.h" +#include "storage/buf.h" +#include "utils/rel.h" + +/* Page numbers of fixed-location pages */ +#define SPGIST_METAPAGE_BLKNO (0) /* metapage */ +#define SPGIST_ROOT_BLKNO (1) /* root for normal entries */ +#define SPGIST_NULL_BLKNO (2) /* root for null-value entries */ +#define SPGIST_LAST_FIXED_BLKNO SPGIST_NULL_BLKNO + +#define SpGistBlockIsRoot(blkno) ((blkno) == SPGIST_ROOT_BLKNO || (blkno) == SPGIST_NULL_BLKNO) +#define SpGistBlockIsFixed(blkno) ((BlockNumber)(blkno) <= (BlockNumber)SPGIST_LAST_FIXED_BLKNO) + +/* + * Contents of page special space on SPGiST index pages + */ +typedef struct SpGistPageOpaqueData { + uint16 flags; /* see bit definitions below */ + uint16 nRedirection; /* number of redirection tuples on page */ + uint16 nPlaceholder; /* number of placeholder tuples on page */ + /* note there's no count of either LIVE or DEAD tuples ... */ + uint16 spgist_page_id; /* for identification of SP-GiST indexes */ +} SpGistPageOpaqueData; + +typedef SpGistPageOpaqueData* SpGistPageOpaque; + +/* Flag bits in page special space */ +#define SPGIST_META (1 << 0) +#define SPGIST_DELETED (1 << 1) +#define SPGIST_LEAF (1 << 2) +#define SPGIST_NULLS (1 << 3) + +#define SpGistPageGetOpaque(page) ((SpGistPageOpaque)PageGetSpecialPointer(page)) +#define SpGistPageIsMeta(page) (SpGistPageGetOpaque(page)->flags & SPGIST_META) +#define SpGistPageIsDeleted(page) (SpGistPageGetOpaque(page)->flags & SPGIST_DELETED) +#define SpGistPageSetDeleted(page) (SpGistPageGetOpaque(page)->flags |= SPGIST_DELETED) +#define SpGistPageIsLeaf(page) (SpGistPageGetOpaque(page)->flags & SPGIST_LEAF) +#define SpGistPageStoresNulls(page) (SpGistPageGetOpaque(page)->flags & SPGIST_NULLS) + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define SPGIST_PAGE_ID 0xFF82 + +/* + * Each backend keeps a cache of last-used page info in its index->rd_amcache + * area. This is initialized from, and occasionally written back to, + * shared storage in the index metapage. + */ +typedef struct SpGistLastUsedPage { + BlockNumber blkno; /* block number, or InvalidBlockNumber */ + int freeSpace; /* page's free space (could be obsolete!) */ +} SpGistLastUsedPage; + +/* Note: indexes in cachedPage[] match flag assignments for SpGistGetBuffer */ +#define SPGIST_CACHED_PAGES 8 + +typedef struct SpGistLUPCache { + SpGistLastUsedPage cachedPage[SPGIST_CACHED_PAGES]; +} SpGistLUPCache; + +/* + * metapage + */ +typedef struct SpGistMetaPageData { + uint32 magicNumber; /* for identity cross-check */ + SpGistLUPCache lastUsedPages; /* shared storage of last-used info */ +} SpGistMetaPageData; + +#define SPGIST_MAGIC_NUMBER (0xBA0BABEE) + +#define SpGistPageGetMeta(p) ((SpGistMetaPageData*)PageGetContents(p)) + +/* + * Private state of index AM. SpGistState is common to both insert and + * search code; SpGistScanOpaque is for searches only. + */ + +/* Per-datatype info needed in SpGistState */ +typedef struct SpGistTypeDesc { + Oid type; + bool attbyval; + int16 attlen; +} SpGistTypeDesc; + +typedef struct SpGistState { + spgConfigOut config; /* filled in by opclass config method */ + + SpGistTypeDesc attType; /* type of input data and leaf values */ + SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */ + SpGistTypeDesc attLabelType; /* type of node label values */ + + char* deadTupleStorage; /* workspace for spgFormDeadTuple */ + + TransactionId myXid; /* XID to use when creating a redirect tuple */ + bool isBuild; /* true if doing index build */ +} SpGistState; + +/* + * Private state of an index scan + */ +typedef struct SpGistScanOpaqueData { + SpGistState state; /* see above */ + MemoryContext tempCxt; /* short-lived memory context */ + + /* Control flags showing whether to search nulls and/or non-nulls */ + bool searchNulls; /* scan matches (all) null entries */ + bool searchNonNulls; /* scan matches (some) non-null entries */ + + /* Index quals to be passed to opclass (null-related quals removed) */ + int numberOfKeys; /* number of index qualifier conditions */ + ScanKey keyData; /* array of index qualifier descriptors */ + + /* Stack of yet-to-be-visited pages */ + List* scanStack; /* List of ScanStackEntrys */ + + /* These fields are only used in amgetbitmap scans: */ + TIDBitmap* tbm; /* bitmap being filled */ + int64 ntids; /* number of TIDs passed to bitmap */ + Oid partHeapOid; /* partition oid passed to bitmap */ + + /* These fields are only used in amgettuple scans: */ + bool want_itup; /* are we reconstructing tuples? */ + TupleDesc indexTupDesc; /* if so, tuple descriptor for them */ + int nPtrs; /* number of TIDs found on current page */ + int iPtr; /* index for scanning through same */ + ItemPointerData heapPtrs[MaxIndexTuplesPerPage]; /* TIDs from cur page */ + bool recheck[MaxIndexTuplesPerPage]; /* their recheck flags */ + IndexTuple indexTups[MaxIndexTuplesPerPage]; /* reconstructed tuples */ + + /* + * Note: using MaxIndexTuplesPerPage above is a bit hokey since + * SpGistLeafTuples aren't exactly IndexTuples; however, they are larger, + * so this is safe. + */ +} SpGistScanOpaqueData; + +typedef SpGistScanOpaqueData* SpGistScanOpaque; + +/* + * This struct is what we actually keep in index->rd_amcache. It includes + * static configuration information as well as the lastUsedPages cache. + */ +typedef struct SpGistCache { + spgConfigOut config; /* filled in by opclass config method */ + + SpGistTypeDesc attType; /* type of input data and leaf values */ + SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */ + SpGistTypeDesc attLabelType; /* type of node label values */ + + SpGistLUPCache lastUsedPages; /* local storage of last-used info */ +} SpGistCache; + +/* + * SPGiST tuple types. Note: inner, leaf, and dead tuple structs + * must have the same tupstate field in the same position! Real inner and + * leaf tuples always have tupstate = LIVE; if the state is something else, + * use the SpGistDeadTuple struct to inspect the tuple. + */ + +/* values of tupstate (see README for more info) */ +#define SPGIST_LIVE 0 /* normal live tuple (either inner or leaf) */ +#define SPGIST_REDIRECT 1 /* temporary redirection placeholder */ +#define SPGIST_DEAD 2 /* dead, cannot be removed because of links */ +#define SPGIST_PLACEHOLDER 3 /* placeholder, used to preserve offsets */ + +/* + * SPGiST inner tuple: list of "nodes" that subdivide a set of tuples + * + * Inner tuple layout: + * header/optional prefix/array of nodes, which are SpGistNodeTuples + * + * size and prefixSize must be multiples of MAXALIGN + */ +typedef struct SpGistInnerTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + allTheSame : 1, /* all nodes in tuple are equivalent */ + nNodes : 13, /* number of nodes within inner tuple */ + prefixSize : 16; /* size of prefix, or 0 if none */ + uint16 size; /* total size of inner tuple */ + /* On most machines there will be a couple of wasted bytes here */ + /* prefix datum follows, then nodes */ +} SpGistInnerTupleData; + +typedef SpGistInnerTupleData* SpGistInnerTuple; + +/* these must match largest values that fit in bit fields declared above */ +#define SGITMAXNNODES 0x1FFF +#define SGITMAXPREFIXSIZE 0xFFFF +#define SGITMAXSIZE 0xFFFF + +#define SGITHDRSZ MAXALIGN(sizeof(SpGistInnerTupleData)) +#define _SGITDATA(x) (((char*)(x)) + SGITHDRSZ) +#define SGITDATAPTR(x) ((x)->prefixSize ? _SGITDATA(x) : NULL) +#define SGITDATUM(x, s) \ + ((x)->prefixSize ? ((s)->attPrefixType.attbyval ? *(Datum*)_SGITDATA(x) : PointerGetDatum(_SGITDATA(x))) : (Datum)0) +#define SGITNODEPTR(x) ((SpGistNodeTuple)(_SGITDATA(x) + (x)->prefixSize)) + +/* Macro for iterating through the nodes of an inner tuple */ +#define SGITITERATE(x, i, nt) \ + for ((i) = 0, (nt) = SGITNODEPTR(x); (i) < (x)->nNodes; \ + (i)++, (nt) = (SpGistNodeTuple)(((char*)(nt)) + IndexTupleSize(nt))) + +/* + * SPGiST node tuple: one node within an inner tuple + * + * Node tuples use the same header as ordinary Postgres IndexTuples, but + * we do not use a null bitmap, because we know there is only one column + * so the INDEX_NULL_MASK bit suffices. Also, pass-by-value datums are + * stored as a full Datum, the same convention as for inner tuple prefixes + * and leaf tuple datums. + */ + +typedef IndexTupleData SpGistNodeTupleData; + +typedef SpGistNodeTupleData* SpGistNodeTuple; + +#define SGNTHDRSZ MAXALIGN(sizeof(SpGistNodeTupleData)) +#define SGNTDATAPTR(x) (((char*)(x)) + SGNTHDRSZ) +#define SGNTDATUM(x, s) ((s)->attLabelType.attbyval ? *(Datum*)SGNTDATAPTR(x) : PointerGetDatum(SGNTDATAPTR(x))) + +/* + * SPGiST leaf tuple: carries a datum and a heap tuple TID + * + * In the simplest case, the datum is the same as the indexed value; but + * it could also be a suffix or some other sort of delta that permits + * reconstruction given knowledge of the prefix path traversed to get here. + * + * The size field is wider than could possibly be needed for an on-disk leaf + * tuple, but this allows us to form leaf tuples even when the datum is too + * wide to be stored immediately, and it costs nothing because of alignment + * considerations. + * + * Normally, nextOffset links to the next tuple belonging to the same parent + * node (which must be on the same page). But when the root page is a leaf + * page, we don't chain its tuples, so nextOffset is always 0 on the root. + * + * size must be a multiple of MAXALIGN; also, it must be at least SGDTSIZE + * so that the tuple can be converted to REDIRECT status later. (This + * restriction only adds bytes for the null-datum case, otherwise alignment + * restrictions force it anyway.) + * + * In a leaf tuple for a NULL indexed value, there's no useful datum value; + * however, the SGDTSIZE limit ensures that's there's a Datum word there + * anyway, so SGLTDATUM can be applied safely as long as you don't do + * anything with the result. + */ +typedef struct SpGistLeafTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + size : 30; /* large enough for any palloc'able value */ + OffsetNumber nextOffset; /* next tuple in chain, or InvalidOffset */ + ItemPointerData heapPtr; /* TID of represented heap tuple */ + /* leaf datum follows */ +} SpGistLeafTupleData; + +typedef SpGistLeafTupleData* SpGistLeafTuple; + +#define SGLTHDRSZ MAXALIGN(sizeof(SpGistLeafTupleData)) +#define SGLTDATAPTR(x) (((char*)(x)) + SGLTHDRSZ) +#define SGLTDATUM(x, s) ((s)->attType.attbyval ? *(Datum*)SGLTDATAPTR(x) : PointerGetDatum(SGLTDATAPTR(x))) + +/* + * SPGiST dead tuple: declaration for examining non-live tuples + * + * The tupstate field of this struct must match those of regular inner and + * leaf tuples, and its size field must match a leaf tuple's. + * Also, the pointer field must be in the same place as a leaf tuple's heapPtr + * field, to satisfy some Asserts that we make when replacing a leaf tuple + * with a dead tuple. + * We don't use nextOffset, but it's needed to align the pointer field. + * pointer and xid are only valid when tupstate = REDIRECT. + */ +typedef struct SpGistDeadTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + size : 30; + OffsetNumber nextOffset; /* not used in dead tuples */ + ItemPointerData pointer; /* redirection inside index */ + TransactionId xid; /* ID of xact that inserted this tuple */ +} SpGistDeadTupleData; + +typedef SpGistDeadTupleData* SpGistDeadTuple; + +#define SGDTSIZE MAXALIGN(sizeof(SpGistDeadTupleData)) + +/* + * Macros for doing free-space calculations. Note that when adding up the + * space needed for tuples, we always consider each tuple to need the tuple's + * size plus sizeof(ItemIdData) (for the line pointer). This works correctly + * so long as tuple sizes are always maxaligned. + */ + +/* Page capacity after allowing for fixed header and special space */ +#define SPGIST_PAGE_CAPACITY MAXALIGN_DOWN(BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(SpGistPageOpaqueData))) + +/* + * Compute free space on page, assuming that up to n placeholders can be + * recycled if present (n should be the number of tuples to be inserted) + */ +#define SpGistPageGetFreeSpace(p, n) \ + (PageGetExactFreeSpace(p) + Min(SpGistPageGetOpaque(p)->nPlaceholder, n) * (SGDTSIZE + sizeof(ItemIdData))) + +/* + * XLOG stuff + */ + +/* XLOG record types for SPGiST */ +#define XLOG_SPGIST_CREATE_INDEX 0x00 +#define XLOG_SPGIST_ADD_LEAF 0x10 +#define XLOG_SPGIST_MOVE_LEAFS 0x20 +#define XLOG_SPGIST_ADD_NODE 0x30 +#define XLOG_SPGIST_SPLIT_TUPLE 0x40 +#define XLOG_SPGIST_PICKSPLIT 0x50 +#define XLOG_SPGIST_VACUUM_LEAF 0x60 +#define XLOG_SPGIST_VACUUM_ROOT 0x70 +#define XLOG_SPGIST_VACUUM_REDIRECT 0x80 + +/* + * Some redo functions need an SpGistState, although only a few of its fields + * need to be valid. spgxlogState carries the required info in xlog records. + * (See fillFakeState in spgxlog.c for more comments.) + */ +typedef struct spgxlogState { + TransactionId myXid; + bool isBuild; +} spgxlogState; + +#define STORE_STATE(s, d) \ + do { \ + (d).myXid = (s)->myXid; \ + (d).isBuild = (s)->isBuild; \ + } while (0) + +/* + * Backup Blk 0: destination page for leaf tuple + * Backup Blk 1: parent page (if any) + */ +typedef struct spgxlogAddLeaf { + bool newPage; /* init dest page? */ + bool storesNulls; /* page is in the nulls tree? */ + OffsetNumber offnumLeaf; /* offset where leaf tuple gets placed */ + OffsetNumber offnumHeadLeaf; /* offset of head tuple in chain, if any */ + + OffsetNumber offnumParent; /* where the parent downlink is, if any */ + uint16 nodeI; + + /* + * new leaf tuple follows, on an intalign boundary (replay only needs to + * fetch its size field, so that should be enough alignment) + */ +} spgxlogAddLeaf; + +/* + * Backup Blk 0: source leaf page + * Backup Blk 1: destination leaf page + * Backup Blk 2: parent page + */ +typedef struct spgxlogMoveLeafs { + uint16 nMoves; /* number of tuples moved from source page */ + bool newPage; /* init dest page? */ + bool replaceDead; /* are we replacing a DEAD source tuple? */ + bool storesNulls; /* pages are in the nulls tree? */ + + /* where the parent downlink is */ + OffsetNumber offnumParent; + uint16 nodeI; + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * array of deleted tuple numbers, length nMoves + * array of inserted tuple numbers, length nMoves + 1 or 1 + * list of leaf tuples, length nMoves + 1 or 1 (must be maxaligned) + * the tuple number arrays are padded to maxalign boundaries so that the + * leaf tuples will be suitably aligned + * + * Note: if replaceDead is true then there is only one inserted tuple + * number and only one leaf tuple in the data, because we are not copying + * the dead tuple from the source + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogMoveLeafs; + +#define SizeOfSpgxlogMoveLeafs offsetof(spgxlogMoveLeafs, offsets) + +/* + * Backup Blk 0: original page + * Backup Blk 1: where new tuple goes, if not same place + * Backup Blk 2: where parent downlink is, if updated and different from + * the old and new + */ +typedef struct spgxlogAddNode { + /* + * Offset of the original inner tuple, in the original page (on backup + * block 0). + */ + OffsetNumber offnum; + + /* + * Offset of the new tuple, on the new page (on backup block 1). Invalid, + * if we overwrote the old tuple in the original page). + */ + OffsetNumber offnumNew; + bool newPage; /* init new page? */ + + /* ---- + * Where is the parent downlink? parentBlk indicates which page it's on, + * and offnumParent is the offset within the page. The possible values for + * parentBlk are: + * + * 0: parent == original page + * 1: parent == new page + * 2: parent == different page (blk ref 2) + * -1: parent not updated + * ---- + */ + char parentBlk; + OffsetNumber offnumParent; /* offset within the parent page */ + + uint16 nodeI; + + spgxlogState stateSrc; + + /* + * updated inner tuple follows, on an intalign boundary (replay only needs + * to fetch its size field, so that should be enough alignment) + */ +} spgxlogAddNode; + +/* + * Backup Blk 0: where the prefix tuple goes + * Backup Blk 1: where the postfix tuple goes (if different page) + */ +typedef struct spgxlogSplitTuple { + /* where the prefix tuple goes */ + OffsetNumber offnumPrefix; + + /* where the postfix tuple goes */ + OffsetNumber offnumPostfix; + bool newPage; /* need to init that page? */ + bool postfixBlkSame; /* was postfix tuple put on same page as + * prefix? */ + + /* + * new prefix inner tuple follows, then new postfix inner tuple, on + * intalign boundaries (replay only needs to fetch size fields, so that + * should be enough alignment) + */ +} spgxlogSplitTuple; + +/* + * Buffer references in the rdata array are: + * Backup Blk 0: Src page (only if not root) + * Backup Blk 1: Dest page (if used) + * Backup Blk 2: Inner page + * Backup Blk 3: Parent page (if any, and different from Inner) + */ +typedef struct spgxlogPickSplit { + bool isRootSplit; + + uint16 nDelete; /* n to delete from Src */ + uint16 nInsert; /* n to insert on Src and/or Dest */ + bool initSrc; /* re-init the Src page? */ + bool initDest; /* re-init the Dest page? */ + + /* where to put new inner tuple */ + OffsetNumber offnumInner; + bool initInner; /* re-init the Inner page? */ + + bool storesNulls; /* pages are in the nulls tree? */ + + /* where the parent downlink is, if any */ + bool innerIsParent; /* is parent the same as inner page? */ + OffsetNumber offnumParent; + uint16 nodeI; + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * new inner tuple (assumed to have a maxaligned length) + * array of deleted tuple numbers, length nDelete + * array of inserted tuple numbers, length nInsert + * array of page selector bytes for inserted tuples, length nInsert + * list of leaf tuples, length nInsert (must be maxaligned) + * the tuple number and page selector arrays are padded to maxalign + * boundaries so that the leaf tuples will be suitably aligned + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogPickSplit; + +#define SizeOfSpgxlogPickSplit offsetof(spgxlogPickSplit, offsets) + +typedef struct spgxlogVacuumLeaf { + uint16 nDead; /* number of tuples to become DEAD */ + uint16 nPlaceholder; /* number of tuples to become PLACEHOLDER */ + uint16 nMove; /* number of tuples to move */ + uint16 nChain; /* number of tuples to re-chain */ + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * tuple numbers to become DEAD + * tuple numbers to become PLACEHOLDER + * tuple numbers to move from (and replace with PLACEHOLDER) + * tuple numbers to move to (replacing what is there) + * tuple numbers to update nextOffset links of + * tuple numbers to insert in nextOffset links + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumLeaf; + +#define SizeOfSpgxlogVacuumLeaf offsetof(spgxlogVacuumLeaf, offsets) + +typedef struct spgxlogVacuumRoot { + /* vacuum a root page when it is also a leaf */ + uint16 nDelete; /* number of tuples to delete */ + + spgxlogState stateSrc; + + /* offsets of tuples to delete follow */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumRoot; + +#define SizeOfSpgxlogVacuumRoot offsetof(spgxlogVacuumRoot, offsets) + +typedef struct spgxlogVacuumRedirect { + uint16 nToPlaceholder; /* number of redirects to make placeholders */ + OffsetNumber firstPlaceholder; /* first placeholder tuple to remove */ + TransactionId newestRedirectXid; /* newest XID of removed redirects */ + + /* offsets of redirect tuples to make placeholders follow */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumRedirect; + +#define SizeOfSpgxlogVacuumRedirect offsetof(spgxlogVacuumRedirect, offsets) + +/* + * The "flags" argument for SpGistGetBuffer should be either GBUF_LEAF to + * get a leaf page, or GBUF_INNER_PARITY(blockNumber) to get an inner + * page in the same triple-parity group as the specified block number. + * (Typically, this should be GBUF_INNER_PARITY(parentBlockNumber + 1) + * to follow the rule described in spgist/README.) + * In addition, GBUF_NULLS can be OR'd in to get a page for storage of + * null-valued tuples. + * + * Note: these flag values are used as indexes into lastUsedPages. + */ +#define GBUF_LEAF 0x03 +#define GBUF_INNER_PARITY(x) ((x) % 3) +#define GBUF_NULLS 0x04 + +#define GBUF_PARITY_MASK 0x03 +#define GBUF_REQ_LEAF(flags) (((flags)&GBUF_PARITY_MASK) == GBUF_LEAF) +#define GBUF_REQ_NULLS(flags) ((flags)&GBUF_NULLS) + +/* spgutils.c */ +extern SpGistCache* spgGetCache(Relation index); +extern void initSpGistState(SpGistState* state, Relation index); +extern Buffer SpGistNewBuffer(Relation index); +extern void SpGistUpdateMetaPage(Relation index); +extern Buffer SpGistGetBuffer(Relation index, int flags, int needSpace, bool* isNew); +extern void SpGistSetLastUsedPage(Relation index, Buffer buffer); +extern void SpGistInitPage(Page page, uint16 f); +extern void SpGistInitBuffer(Buffer b, uint16 f); +extern void SpGistInitMetapage(Page page); +extern unsigned int SpGistGetTypeSize(SpGistTypeDesc* att, Datum datum); +extern SpGistLeafTuple spgFormLeafTuple(SpGistState* state, ItemPointer heapPtr, Datum datum, bool isnull); +extern SpGistNodeTuple spgFormNodeTuple(SpGistState* state, Datum label, bool isnull); +extern SpGistInnerTuple spgFormInnerTuple( + SpGistState* state, bool hasPrefix, Datum prefix, int nNodes, SpGistNodeTuple* nodes); +extern SpGistDeadTuple spgFormDeadTuple(SpGistState* state, int tupstate, BlockNumber blkno, OffsetNumber offnum); +extern Datum* spgExtractNodeLabels(SpGistState* state, SpGistInnerTuple innerTuple); +extern OffsetNumber SpGistPageAddNewItem( + SpGistState* state, Page page, Item item, Size size, OffsetNumber* startOffset, bool errorOK); + +/* spgdoinsert.c */ +extern void spgUpdateNodeLink(SpGistInnerTuple tup, int nodeN, BlockNumber blkno, OffsetNumber offset); +extern void spgPageIndexMultiDelete(SpGistState* state, Page page, OffsetNumber* itemnos, int nitems, int firststate, + int reststate, BlockNumber blkno, OffsetNumber offnum); +extern void spgdoinsert(Relation index, SpGistState* state, ItemPointer heapPtr, Datum datum, bool isnull); +extern void addOrReplaceTuple(Page page, Item tuple, int size, OffsetNumber offset); +extern void fillFakeState(SpGistState* state, const spgxlogState& stateSrc); + +#endif /* SPGIST_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/access/subtrans.h postgresql-hll-2.14/include/access/subtrans.h --- postgresql-hll-2.14_old/include/access/subtrans.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/subtrans.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,20 @@ +/* + * subtrans.h + * + * PostgreSQL subtransaction-log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/subtrans.h + */ +#ifndef SUBTRANS_H +#define SUBTRANS_H + +#include "access/clog.h" + +extern void SubTransSetParent(TransactionId xid, TransactionId parent); +extern TransactionId SubTransGetParent(TransactionId xid, CLogXidStatus* status, bool force_wait_parent); +extern TransactionId SubTransGetTopmostTransaction(TransactionId xid); + +#endif /* SUBTRANS_H */ diff -uprN postgresql-hll-2.14_old/include/access/sysattr.h postgresql-hll-2.14/include/access/sysattr.h --- postgresql-hll-2.14_old/include/access/sysattr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/sysattr.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * sysattr.h + * POSTGRES system attribute definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/sysattr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SYSATTR_H +#define SYSATTR_H + +/* + * Attribute numbers for the system-defined attributes + */ +#define SelfItemPointerAttributeNumber (-1) +#define ObjectIdAttributeNumber (-2) +#define MinTransactionIdAttributeNumber (-3) +#define MinCommandIdAttributeNumber (-4) +#define MaxTransactionIdAttributeNumber (-5) +#define MaxCommandIdAttributeNumber (-6) +#define TableOidAttributeNumber (-7) +#ifdef PGXC + +#define XC_NodeIdAttributeNumber (-8) +#define BucketIdAttributeNumber (-9) +#define FirstLowInvalidHeapAttributeNumber (-10) + +#else +#define FirstLowInvalidHeapAttributeNumber (-8) +#endif + +#endif /* SYSATTR_H */ diff -uprN postgresql-hll-2.14_old/include/access/tableam.h postgresql-hll-2.14/include/access/tableam.h --- postgresql-hll-2.14_old/include/access/tableam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/tableam.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,781 @@ +/*------------------------------------------------------------------------- + * + * tableam.h + * POSTGRES table access method definitions. + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tableam.h + * + * NOTES + * See tableam.sgml for higher level documentation. + * + *------------------------------------------------------------------------- + */ + +#ifndef TABLEAM_H +#define TABLEAM_H + +#include "access/hbindex_am.h" +#include "access/hbucket_am.h" +#include "access/relscan.h" +#include "access/sdir.h" +#include "catalog/index.h" +#include "executor/executor.h" +#include "optimizer/bucketinfo.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/snapshot.h" +#include "nodes/execnodes.h" + +/* + * * Bitmask values for the flags argument to the scan_begin callback. + * */ +typedef enum ScanOptions +{ + /* one of SO_TYPE_* may be specified */ + SO_TYPE_SEQSCAN = 1 << 0, + SO_TYPE_BITMAPSCAN = 1 << 1, + SO_TYPE_SAMPLESCAN = 1 << 2, + SO_TYPE_ANALYZE = 1 << 3, + SO_TYPE_TIDSCAN = 1 << 8, + + /* several of SO_ALLOW_* may be specified */ + /* allow or disallow use of access strategy */ + SO_ALLOW_STRAT = 1 << 4, + /* report location to syncscan logic? */ + SO_ALLOW_SYNC = 1 << 5, + /* verify visibility page-at-a-time? */ + SO_ALLOW_PAGEMODE = 1 << 6, + + /* unregister snapshot at scan end? */ + SO_TEMP_SNAPSHOT = 1 << 7 +} ScanOptions; + + +/* ------------------------------------------------------------------------ + * Table Access Method Layer + * ------------------------------------------------------------------------ + */ + +/* "options" flag bits for tuple_insert */ +#define TABLE_INSERT_SKIP_WAL 0x0001 +#define TABLE_INSERT_SKIP_FSM 0x0002 +#define TABLE_INSERT_FROZEN 0x0004 +#define TABLE_INSERT_SPECULATIVE 0x0008 + +extern RangeScanInRedis reset_scan_qual(Relation currHeapRel, ScanState * node); + +/* + * Macros on tuple assertions from tuple and typeType + * and retrieve the index for table type from tuple type. + */ +#define TUPLE_IS_HEAP_TUPLE(tup) (((HeapTuple)tup)->tupTableType == HEAP_TUPLE) +//#define TUPLE_IS_UHEAP_TUPLE(tup) (((UHeapTuple)tup)->tupTableType == UHEAP_TUPLE) +#define AssertValidTupleType(tupType) Assert(tupType == HEAP_TUPLE || tupType == UHEAP_TUPLE) +#define AssertValidTuple(tup) Assert(TUPLE_IS_HEAP_TUPLE(tup)) +#define GetTableAMIndex(tupType) tupType >> 1 +#define GetTabelAmIndexTuple(tup) GetTableAMIndex(((HeapTuple)tup)->tupTableType) + +/* + * Common interface for table AM. + * This abstracts away the accessor methods to different kinds of tables. + */ + +typedef struct TableAmRoutine +{ + /* ------------------------------------------------------------------------ + * TABLE SLOT AM APIs + * ------------------------------------------------------------------------ + */ + + /* + * Clear the contents of the slot. Only the contents are expected to be + * cleared and not the tuple descriptor. Typically an implementation of + * this callback should free the memory allocated for the tuple(minimal/physical/Datum and isnull array) + *contained in the slot. + */ + void (*tslot_clear) (TupleTableSlot *slot); + + /* + * Make the contents of the slot solely depend on the slot(make them a local copy), + * and not on underlying external resources like another memory context, buffers etc for HeapTable. + * or return a copy of HeapTuple from slots's content for other Tables. + * + * @pram slot: slot to be materialized. + */ + HeapTuple (*tslot_materialize) (TupleTableSlot *slot); + + /* + * Return a minimal tuple "owned" by the slot. It is slot's responsibility + * to free the memory consumed by the minimal tuple. If the slot can not + * "own" a minimal tuple, it should not implement this callback and should + * set it as NULL. + * + * @param slot: slot from minimal tuple to fetch. + * @return slot's minimal tuple. + * + */ + MinimalTuple (*tslot_get_minimal_tuple) (TupleTableSlot *slot); + + /* + * Return a copy of minimal tuple representing the contents of the slot. + * The copy needs to be palloc'd in the current memory context. The slot + * itself is expected to remain unaffected. It is *not* expected to have + * meaningful "system columns" in the copy. The copy is not be "owned" by + * the slot i.e. the caller has to take responsibility to free memory + * consumed by the slot. + * + * @param slot: slot from which minimal tuple to be copied. + * @return slot's tuple minimal tuple copy + */ + MinimalTuple (*tslot_copy_minimal_tuple) (TupleTableSlot *slot); + + /* + * Stores heaps minimal tuple in the TupleTableSlot. Release the current slots buffer and Free's any slot's + * minimal and heap tuple. + * + * @param mtup: minimal tuple to be stored. + * @param slot: slot to store tuple. + * @param: should_free true if clear the slot's tuple contents by pfree_ext() during ExecClearTuple. + */ + void (*tslot_store_minimal_tuple) (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree); + + /* + * Returns a heap tuple "owned" by the slot. It is the slot's responsibility to free the memory + * associated with this tuple. If the slot cannot own the tuple constructed or returned, it should + * not implement this method, and should return NULL. + * + * @param slot: slot from tuple to fetch. + * @return slot's tuple. + */ + HeapTuple (*tslot_get_heap_tuple) (TupleTableSlot* slot); + + + /* + * Return a copy of heap tuple representing the contents of the slot. The + * copy needs to be palloc'd in the current memory context. The slot + * itself is expected to remain unaffected. It is *not* expected to have + * meaningful "system columns" in the copy. The copy is not be "owned" by + * the slot i.e. the caller has to take responsibility to free memory + * consumed by the slot. + * + * @param slot: slot from which tuple to be copied. + * @return slot's tuple copy + */ + HeapTuple (*tslot_copy_heap_tuple) (TupleTableSlot *slot); + + /* + * Stores the physical tuple into a slot. + * + * @param tuple: tuple to be stored. + * @param slot: slot to store tuple. + * @param: should_free true if clear the slot's tuple contents by pfree_ext() during ExecClearTuple + * @return: none + */ + void (*tslot_store_tuple)(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free); + + /* + * Fill up first natts entries of tts_values and tts_isnull arrays with + * values from the tuple contained in the slot. The function may be called + * with natts more than the number of attributes available in the tuple, + * in which case it should set tts_nvalid to the number of returned + * columns. + * + * @param slot:input Tuple Table slot from which attributes are extracted. + * @param attnum: index until which slots attributes are extracted. + */ + void (*tslot_getsomeattrs) (TupleTableSlot *slot, int natts); + + /* + * Fetches a given attribute from the slot's current tuple. + * attnums beyond the slot's tupdesc's last attribute will be considered NULL + * even when the physical tuple is longer than the tupdesc. + * + * @param slot: TableTuple slot from this attribute is extracted + * @param attnum: index of the atribute to be extracted. + * @param isnull: set to true, if the attribute is NULL. + */ + Datum (*tslot_getattr)(TupleTableSlot* slot, int attnum, bool* isnull); + + /* + * This function forces all the entries of slot's Datum/isnull array to be valid + * The caller may then extract data directly + * from those arrays instead of using getattr. + * + * @param slot: TableTuple slot from this attributes are extracted + */ + void (*tslot_getallattrs)(TupleTableSlot* slot); + + /* + * Detects if specified attribute is null without actually fetching it. + * + * @param slot: Tabletuple slot + * @para attnum: attribute index that should be checked for null value. + */ + bool (*tslot_attisnull)(TupleTableSlot* slot, int attnum); + + /* ------------------------------------------------------------------------ + * TABLE TUPLE AM APIs + * ------------------------------------------------------------------------ + */ + + /* + * Returns value of the given system attribute as a datum and sets isnull + * to false, if it's not NULL. Throws an error if the slot type does not + * support system attributes. + */ + Datum (*tops_getsysattr) (Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buf); + + /* + * form_minimal_tuple + * construct a MinimalTuple from the given values[] and isnull[] arrays, + * which are of the length indicated by tupleDescriptor->natts + * + * The result is allocated in the current memory context. + */ + MinimalTuple (*tops_form_minimal_tuple)(TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple); + + + /* + * form_tuple + * construct a tuple from the given values[] and isnull[] arrays, + * which are of the length indicated by tupleDescriptor->natts + * + * The result is allocated in the current memory context. + */ + Tuple (*tops_form_tuple)(TupleDesc tuple_descriptor, Datum* values, bool* isnull); + + /* + * form_cmprs_tuple + * construct a compressed tuple from the given cmprsInfo. + * + * The result is allocated in the current memory context. + */ + HeapTuple (*tops_form_cmprs_tuple)(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info); + + /* + * deform_tuple + * Given a tuple, extract data into values/isnull arrays; this is + * the inverse of heap_form_tuple. + */ + void (*tops_deform_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull); + + /* + * deform_cmprs_tuple + * Given a tuple, extract data into values/isnull arrays; this is + * the inverse of heap_form_cmprs_tuple. + */ + void (*tops_deform_cmprs_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info); + + /* + * compute_data_size + * Determine size of the data area of a tuple to be constructed + */ + Size (*tops_computedatasize_tuple)(TupleDesc tuple_desc, Datum* values, const bool* isnull, uint32 hoff); + + /* + * fill_tuple + * Load data portion of a tuple from values/isnull arrays + */ + void (*tops_fill_tuple)(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit); + + /* + * modify_tuple + * form a new tuple from an old tuple and a set of replacement values. + * + * The result is allocated in the current memory context. + */ + Tuple (*tops_modify_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace); + + /* + * tuple_getattr + * Fetches the attribute for a given index.. + */ + Datum (*tops_tuple_getattr)(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null); + + /* + * tuple_attisnull + * Fetches if the attribute is null for a given index. + */ + bool (*tops_tuple_attisnull)(Tuple tup, int attnum, TupleDesc tuple_desc); + + /* + * tops_copy_tuple + * Returns a copy of the entire tuple + */ + Tuple (*tops_copy_tuple) (Tuple tuple); + + /* --------------------------------------------------------------------- + * SCAN AM API + * --------------------------------------------------------------------- + */ + + IndexFetchTableData * (*scan_index_fetch_begin) (Relation rel); + + void (*scan_index_fetch_reset) (IndexFetchTableData *scan); + + void (*scan_index_fetch_end) (IndexFetchTableData *scan); + + HeapTuple (*scan_index_fetch_tuple) (IndexScanDesc scan, bool *all_dead); + + /* + * begin relation scan + */ + TableScanDesc (*scan_begin) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key, RangeScanInRedis rangeScanInRedis); + + /* + * begin relation scan for bit map + */ + TableScanDesc (*scan_begin_bm) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key); + + /* + * begin relation scan for sampling + */ + TableScanDesc (*scan_begin_sampling) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis); + + /* + * Re scan + */ + void (*scan_rescan) (TableScanDesc sscan, ScanKey key); + + /* + * Restore scan position + */ + void (*scan_restrpos) (TableScanDesc sscan); + + /* + * Mark scan position + */ + void (*scan_markpos) (TableScanDesc sscan); + + /* + * init parallel seq scan + */ + void (*scan_init_parallel_seqscan) (TableScanDesc sscan, int32 dop, ScanDirection dir); + + /* + * Get next tuple + * Will return a Generic "Tuple" type + */ + Tuple (*scan_getnexttuple) (TableScanDesc sscan, ScanDirection direction); + + /* + * Get next page + */ + void (*scan_getpage) (TableScanDesc sscan, BlockNumber page); + + /* + * end relation scan + */ + void (*scan_end) (TableScanDesc sscan); + + + /* ------------------------------------------------------------------------ + * DQL AM APIs + * ------------------------------------------------------------------------ + */ + + bool (*tuple_fetch) (Relation relation, Snapshot snapshot, HeapTuple tuple, + Buffer *userbuf, bool keep_buf, Relation stats_relation); + + bool (*tuple_satisfies_snapshot) (Relation relation, HeapTuple tuple, + Snapshot snapshot, Buffer buffer); + + void (*tuple_get_latest_tid) (Relation relation, Snapshot snapshot, + ItemPointer tid); + + /* ------------------------------------------------------------------------ + * DML AM APIs + * ------------------------------------------------------------------------ + */ + Oid (*tuple_insert) (Relation relation, Tuple tup, CommandId cid, + int options, struct BulkInsertStateData *bistate); + + int (*tuple_multi_insert) (Relation relation, Relation parent, + Tuple* tuples, int ntuples, CommandId cid, + int options, struct BulkInsertStateData *bistate, + HeapMultiInsertExtraArgs *args); + + TM_Result (*tuple_delete) (Relation relation, ItemPointer tid, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool allow_delete_self); + + TM_Result (*tuple_update) (Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self); + + // XXXTAM: see of we can get rid of some uheap_lock_tuple() params + TM_Result (*tuple_lock) (Relation relation, Tuple tuple, Buffer *buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, + bool allow_lock_self, bool follow_updates, bool eval, Snapshot snapshot, + ItemPointer tid, bool isSelectForUpdate); + + HeapTuple (*tuple_lock_updated)(CommandId cid, Relation relation, + int lockmode, ItemPointer tid, TransactionId priorXmax); + + + /* ------------------------------------------------------------------------ + * DDL AM APIs + * ------------------------------------------------------------------------ + */ + + double (*index_build_scan) (Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, bool allow_sync, + IndexBuildCallback callback, void* callback_state); + + void (*index_validate_scan) (Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state); + + double (*relation_copy_for_cluster) (Relation OldHeap, Relation OldIndex, + Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, + bool use_sort, AdaptMem* memUsage, + TransactionId* ptrFreezeXid); + +} TableAmRoutine; + +extern const TableAmRoutine * const g_tableam_routines[]; + +static inline const TableAmRoutine *GetTableAmRoutine(TableAmType type) { + return g_tableam_routines[type]; +} + +/* + * Clears the contents of the table slot that contains heap table tuple data. + */ +static inline void tableam_tslot_clear(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_clear(slot); +} + +static inline HeapTuple tableam_tslot_materialize(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_materialize(slot); +} + +static inline MinimalTuple tableam_tslot_get_minimal_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_get_minimal_tuple(slot); +} + + +static inline MinimalTuple tableam_tslot_copy_minimal_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_copy_minimal_tuple(slot); +} + +static inline void tableam_tslot_store_minimal_tuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree) +{ + g_tableam_routines[slot->tts_tupslotTableAm]->tslot_store_minimal_tuple(mtup, slot, shouldFree); +} + +static inline HeapTuple tableam_tslot_get_heap_tuple(TupleTableSlot* slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_get_heap_tuple(slot); +} + +static inline HeapTuple tableam_tslot_copy_heap_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_copy_heap_tuple(slot); +} + +// XXXTAM +// WE have the tuple type in the tuple now, we can use it to select the right function! +static inline void tableam_tslot_store_tuple(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free) +{ + g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tslot_store_tuple(tuple, slot, buffer, should_free); +} + + +static inline void tableam_tslot_getsomeattrs(TupleTableSlot *slot, int natts) +{ + g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getsomeattrs(slot, natts); +} + +static inline Datum tableam_tslot_getattr(TupleTableSlot* slot, int attnum, bool* isnull) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getattr(slot, attnum, isnull); +} + +static inline void tableam_tslot_getallattrs(TupleTableSlot* slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getallattrs(slot); +} + +static inline bool tableam_tslot_attisnull(TupleTableSlot* slot, int attnum) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_attisnull(slot, attnum); +} + +/* ------------------------------------------------------------------------ + * TABLE TUPLE AM APIs + * ------------------------------------------------------------------------ + */ + +static inline Datum tableam_tops_getsysattr(Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buf = InvalidBuffer) { + AssertValidTuple(tup); + return g_tableam_routines[GetTabelAmIndexTuple(tup)]->tops_getsysattr(tup, attnum, tuple_desc, isnull, buf); +} + +static inline MinimalTuple tableam_tops_form_minimal_tuple( + TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_minimal_tuple(tuple_descriptor, values, isnull, in_tuple); +} + +static inline Tuple tableam_tops_form_tuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_tuple(tuple_descriptor, values, isnull); +} + +static inline Tuple tableam_tops_form_cmprs_tuple(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_cmprs_tuple(tuple_descriptor, cmprs_info); +} + + +static inline void tableam_tops_deform_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_tuple(tuple, tuple_desc, values, isnull); +} + +static inline void tableam_tops_deform_cmprs_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_cmprs_tuple(tuple, tuple_desc, values, isnull, cmprs_info); +} + +static inline Size tableam_tops_computedatasize_tuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, uint32 hoff, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_computedatasize_tuple(tuple_desc, values, isnull, hoff); +} + +static inline void tableam_tops_fill_tuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit) +{ + return g_tableam_routines[tuple_desc->tdTableAmType]->tops_fill_tuple(tuple_desc, values, isnull, data, data_size, infomask, bit); +} + +// there is no uheapam_tops_modify_tuple +// but this is done for completeness +static inline Tuple tableam_tops_modify_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_modify_tuple(tuple, tuple_desc, repl_values, repl_isnull, do_replace); +} + +static inline void tableam_tops_free_tuple(HeapTuple &htup) +{ + heap_freetuple_ext(htup); +} + +static inline Datum tableam_tops_tuple_getattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_getattr(tuple, att_num, tuple_desc, is_null); +} + +static inline bool tableam_tops_tuple_attisnull(Tuple tuple, int attnum, TupleDesc tuple_desc) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_attisnull(tuple, attnum, tuple_desc); +} + +static inline Tuple tableam_tops_copy_tuple(Tuple tuple) +{ + AssertValidTuple(tuple); + + // TODO: assert tuple returned and tuple are same type + + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_copy_tuple(tuple); + // return heap_copytuple(tuple); +} + +static inline MinimalTuple tableam_tops_copy_minimal_tuple(MinimalTuple mtup) +{ + return heap_copy_minimal_tuple(mtup); +} + +static inline void tableam_tops_free_minimal_tuple(MinimalTuple mtup) +{ + heap_free_minimal_tuple(mtup); +} + + +/* ------------------------------------------------------------------------ + * DQL AM APIs + * ------------------------------------------------------------------------ + */ +static inline bool tableam_tuple_fetch(Relation relation, Snapshot snapshot, + HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation) { + return g_tableam_routines[relation->rd_tam_type]->tuple_fetch(relation, snapshot, tuple, userbuf, keep_buf, stats_relation); +} + +static inline bool tableam_tuple_satisfies_snapshot(Relation relation, HeapTuple tuple, + Snapshot snapshot, Buffer buffer) { + return g_tableam_routines[relation->rd_tam_type]->tuple_satisfies_snapshot(relation, tuple, snapshot, buffer); +} + +static inline void tableam_tuple_get_latest_tid(Relation relation, Snapshot snapshot, + ItemPointer tid) { + return g_tableam_routines[relation->rd_tam_type]->tuple_get_latest_tid(relation, snapshot, tid); +} + +static inline Oid tableam_tuple_insert (Relation relation, Tuple tup, CommandId cid, + int options, struct BulkInsertStateData *bistate) { + return g_tableam_routines[relation->rd_tam_type]->tuple_insert(relation, tup, cid, options, bistate); +} + +static inline int tableam_tuple_multi_insert(Relation relation, Relation parent, + Tuple* tuples, int ntuples, CommandId cid, + int options, struct BulkInsertStateData *bistate, + HeapMultiInsertExtraArgs *args) { + return g_tableam_routines[relation->rd_tam_type]->tuple_multi_insert(relation, parent, tuples, ntuples, cid, options, bistate, args); +} + +static inline TM_Result tableam_tuple_delete(Relation relation, ItemPointer tid, + CommandId cid, Snapshot crosscheck, Snapshot snapshot, + bool wait, TM_FailureData *tmfd, bool allow_delete_self = false) { + return g_tableam_routines[relation->rd_tam_type]->tuple_delete(relation, tid, cid, crosscheck, snapshot, wait, tmfd, allow_delete_self); +} + + +static inline TM_Result tableam_tuple_update(Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self = false) { + return g_tableam_routines[relation->rd_tam_type]->tuple_update(relation, parentRelation, otid, newtup, cid, crosscheck, + snapshot, wait, tmfd, update_indexes, allow_update_self); +} + +static inline TM_Result tableam_tuple_lock(Relation relation, Tuple tuple, Buffer *buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, + bool allow_lock_self, bool follow_updates, bool eval, Snapshot snapshot, + ItemPointer tid, bool isSelectForUpdate) { + return g_tableam_routines[relation->rd_tam_type]->tuple_lock(relation, tuple, buffer, cid, mode, nowait, tmfd, + allow_lock_self, follow_updates, eval, snapshot, + tid, isSelectForUpdate); +} + +static inline HeapTuple tableam_tuple_lock_updated(CommandId cid, Relation relation, + int lockmode, ItemPointer tid, TransactionId priorXmax) { + return g_tableam_routines[relation->rd_tam_type]->tuple_lock_updated(cid, relation, lockmode, tid, priorXmax); +} + + +/* ----------------------------------------------------------------------- + * SCAN AM APIS FOR HEAP + * ------------------------------------------------------------------------ + */ + +extern IndexFetchTableData * heapam_scan_index_fetch_begin(Relation rel); +static inline IndexFetchTableData * tableam_scan_index_fetch_begin(Relation rel) +{ + return heapam_scan_index_fetch_begin(rel); +} + +extern void heapam_index_fetch_reset(IndexFetchTableData *scan); +static inline void tableam_scan_index_fetch_reset(IndexFetchTableData *scan) +{ + heapam_index_fetch_reset(scan); +} + +extern void heapam_scan_index_fetch_end(IndexFetchTableData *scan); +static inline void tableam_scan_index_fetch_end(IndexFetchTableData *scan) +{ + heapam_scan_index_fetch_end(scan); +} + +static inline HeapTuple tableam_scan_index_fetch_tuple(IndexScanDesc scan, bool *all_dead) +{ + return g_tableam_routines[scan->heapRelation->rd_tam_type]->scan_index_fetch_tuple(scan, all_dead); +} + +static inline TableScanDesc tableam_scan_begin(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + RangeScanInRedis rangeScanInRedis = {false, 0, 0}) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin(relation, snapshot, nkeys, key, rangeScanInRedis); +} + +static inline TableScanDesc tableam_scan_begin_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin_bm(relation, snapshot, nkeys, key); +} + +static inline TableScanDesc tableam_scan_begin_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, + bool allow_sync, RangeScanInRedis rangeScanInRedis = {false, 0, 0}) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin_sampling(relation, snapshot, nkeys, key, allow_strat, allow_sync, rangeScanInRedis); +} + +static inline Tuple tableam_scan_getnexttuple(TableScanDesc sscan, ScanDirection direction) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getnexttuple(sscan, direction); +} + +static inline void tableam_scan_getpage(TableScanDesc sscan, BlockNumber page) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getpage(sscan, page); +} + +static inline void tableam_scan_end(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_end(sscan); +} + +static inline void tableam_scan_rescan(TableScanDesc sscan, ScanKey key) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_rescan(sscan, key); +} + +static inline void tableam_scan_restrpos(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_restrpos(sscan); +} + +static inline void tableam_scan_markpos(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_markpos(sscan); +} + +static inline void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_init_parallel_seqscan(sscan, dop, dir); +} + +static inline double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, bool allow_sync, + IndexBuildCallback callback, void* callback_state) { + return g_tableam_routines[heapRelation->rd_tam_type]->index_build_scan(heapRelation, indexRelation, indexInfo, allow_sync, callback, callback_state); +} + + +static inline void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state) { + return g_tableam_routines[heapRelation->rd_tam_type]->index_validate_scan(heapRelation, indexRelation, indexInfo, snapshot, state); +} + +static inline double tableam_relation_copy_for_cluster(Relation OldHeap, Relation OldIndex, + Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, + bool use_sort, AdaptMem* memUsage, + TransactionId* ptrFreezeXid) { + return g_tableam_routines[OldHeap->rd_tam_type]->relation_copy_for_cluster(OldHeap, OldIndex, NewHeap, OldestXmin, FreezeXid, verbose, use_sort, memUsage, ptrFreezeXid); +} + + +//XXXTAM TEMPORARY +extern TM_Result heapam_tuple_update(Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self = false); + +#endif /* TABLEAM_H */ diff -uprN postgresql-hll-2.14_old/include/access/transam.h postgresql-hll-2.14/include/access/transam.h --- postgresql-hll-2.14_old/include/access/transam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/transam.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,243 @@ +/* ------------------------------------------------------------------------- + * + * transam.h + * postgres transaction access method support code + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/access/transam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TRANSAM_H +#define TRANSAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xact.h" +#include "access/xlogdefs.h" +#ifdef PGXC +#include "gtm/gtm_c.h" +#endif +#include "utils/atomic.h" + +/* ---------------- + * Special transaction ID values + * + * BootstrapTransactionId is the XID for "bootstrap" operations, and + * FrozenTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFFFFFFFFF) /* First four bits reserved */ +#define MaxShortTransactionId ((TransactionId)0xFFFFFFFF) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +#define ShortTransactionIdToNormal(base, xid) \ + (TransactionIdIsNormal(xid) ? (TransactionId)(xid) + (base) : (TransactionId)(xid)) +#define NormalTransactionIdToShort(base, xid) \ + (TransactionIdIsNormal(xid) ? (ShortTransactionId)(AssertMacro((xid) >= (base) + FirstNormalTransactionId), \ + AssertMacro((xid) <= (base) + MaxShortTransactionId), \ + (xid) - (base)) \ + : (ShortTransactionId)(xid)) + +/* advance a transaction ID variable */ +#define TransactionIdAdvance(dest) \ + do { \ + (dest)++; \ + Assert((dest) > FirstNormalTransactionId); \ + } while (0) + +/* back up a transaction ID variable */ +#define TransactionIdRetreat(dest) \ + do { \ + Assert((dest) > FirstNormalTransactionId); \ + (dest)--; \ + } while ((dest) < FirstNormalTransactionId) + +/* compare two XIDs already known to be normal; this is a macro for speed */ +#define NormalTransactionIdPrecedes(id1, id2) \ + (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), (int64)((id1) - (id2)) < 0) +/* compare two XIDs already known to be normal; this is a macro for speed */ +#define NormalTransactionIdFollows(id1, id2) \ + (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), (int32)((id1) - (id2)) > 0) +/* ---------- + * Object ID (OID) zero is InvalidOid. + * + * OIDs 1-9999 are reserved for manual assignment (see the files + * in src/include/catalog/). + * + * OIDS 10000-16383 are reserved for assignment during initdb + * using the OID generator. (We start the generator at 10000.) + * + * OIDs beginning at 16384 are assigned from the OID generator + * during normal multiuser operation. (We force the generator up to + * 16384 as soon as we are in normal operation.) + * + * The choices of 10000 and 16384 are completely arbitrary, and can be moved + * if we run low on OIDs in either category. Changing the macros below + * should be sufficient to do this. + * + * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383 + * and resume with 16384. This minimizes the odds of OID conflict, by not + * reassigning OIDs that might have been assigned during initdb. + * ---------- + */ +#define FirstBootstrapObjectId 10000 +#define FirstNormalObjectId 16384 + +#define IsSystemObjOid(id) ((OidIsValid(id)) && (id < FirstBootstrapObjectId)) +/* + * VariableCache is a data structure in shared memory that is used to track + * OID and XID assignment state. For largely historical reasons, there is + * just one struct with different fields that are protected by different + * LWLocks. + */ +typedef struct VariableCacheData { + /* + * These fields are protected by OidGenLock. + */ + Oid nextOid; /* next OID to assign */ + uint32 oidCount; /* OIDs available before must do XLOG work */ + + /* + * These fields are protected by XidGenLock. + */ + TransactionId nextXid; /* next XID to assign */ + + TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + TransactionId xidVacLimit; /* start forcing autovacuums here */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + int64 lastExtendCSNLogpage; /* last extend csnlog page number */ + + /* + * The page from which the last extending do, this will be reset when + * extend from recentGlobalXmin. + */ + int64 startExtendCSNLogpage; + + /* + * Fields related to MVCC snapshots. + * + * lastCommitSeqNo is the CSN assigned to last committed transaction. + * It is protected by CommitSeqNoLock. + * + * latestCompletedXid is the highest XID that has committed. Anything + * > this is seen by still in-progress by everyone. Use atomic ops to + * update. + * + * oldestActiveXid is the XID of the oldest transaction that's still + * in-progress. (Or rather, the oldest XID among all still in-progress + * transactions; it's not necessarily the one that started first). + * Must hold ProcArrayLock in shared mode, and use atomic ops, to update. + */ + CommitSeqNo nextCommitSeqNo; + TransactionId latestCompletedXid; /* newest XID that has committed or + * aborted */ + /* + * These fields only set in startup to normal + */ + TransactionId startupMaxXid; /* the latest xid in prev shut down */ + TransactionId xmin; + TransactionId recentLocalXmin; /* the lastest xmin in local node */ + pg_atomic_uint64 recentGlobalXmin; /* the lastest xmin in global */ + pg_atomic_uint32 CriticalCacheBuildLock; /* lock of create relcache init file */ + + pg_atomic_uint64 cutoff_csn_min; + TransactionId keep_xmin; /* quickly to calculate oldestxmin */ + CommitSeqNo keep_csn; /* quickly to calculate oldestxmin */ + CommitSeqNo local_csn_min; +} VariableCacheData; + +typedef VariableCacheData* VariableCache; + +/* ---------------- + * extern declarations + * ---------------- + */ + +/* in transam/xact.c */ +extern bool TransactionStartedDuringRecovery(void); + +/* + * prototypes for functions in transam/transam.c + */ +extern bool TransactionIdDidCommit(TransactionId transactionId); +extern bool TransactionIdDidAbort(TransactionId transactionId); + +#define COMMITSEQNO_INPROGRESS UINT64CONST(0x0) +#define COMMITSEQNO_ABORTED UINT64CONST(0x1) +#define COMMITSEQNO_FROZEN UINT64CONST(0x2) +#define COMMITSEQNO_FIRST_NORMAL UINT64CONST(0x3) + +#define COMMITSEQNO_COMMIT_INPROGRESS (UINT64CONST(1) << 62) +#define COMMITSEQNO_SUBTRANS_BIT (UINT64CONST(1) << 63) + +#define MAX_COMMITSEQNO UINT64CONST((UINT64CONST(1) << 60) - 1) /* First four bits reserved */ + +#define COMMITSEQNO_IS_INPROGRESS(csn) (((csn)&MAX_COMMITSEQNO) == COMMITSEQNO_INPROGRESS) +#define COMMITSEQNO_IS_ABORTED(csn) ((csn) == COMMITSEQNO_ABORTED) +#define COMMITSEQNO_IS_FROZEN(csn) ((csn) == COMMITSEQNO_FROZEN) +#define COMMITSEQNO_IS_COMMITTED(csn) \ + (((csn)&MAX_COMMITSEQNO) >= COMMITSEQNO_FROZEN && !COMMITSEQNO_IS_SUBTRANS(csn) && !COMMITSEQNO_IS_COMMITTING(csn)) +#define COMMITSEQNO_IS_COMMITTING(csn) (((csn)&COMMITSEQNO_COMMIT_INPROGRESS) == COMMITSEQNO_COMMIT_INPROGRESS) + +#define COMMITSEQNO_IS_SUBTRANS(csn) (((csn)&COMMITSEQNO_SUBTRANS_BIT) == COMMITSEQNO_SUBTRANS_BIT) + +#define GET_COMMITSEQNO(csn) ((csn)&MAX_COMMITSEQNO) +#define GET_PARENTXID(csn) ((csn)&MAX_COMMITSEQNO) + +typedef enum { XID_COMMITTED, XID_ABORTED, XID_INPROGRESS } TransactionIdStatus; + +extern void SetLatestFetchState(TransactionId transactionId, CommitSeqNo result); +extern CommitSeqNo TransactionIdGetCommitSeqNo(TransactionId xid, bool isCommit, bool isMvcc, bool isNest); +extern CommitSeqNo TransactionIdGetCommitSeqNoNCache( + TransactionId transactionId, bool isCommit, bool isMvcc, bool isNest); +extern void TransactionIdAbort(TransactionId transactionId); +extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId* xids, uint64 csn); +extern bool TransactionIdIsKnownCompleted(TransactionId transactionId); +extern void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId* xids, XLogRecPtr lsn, uint64 csn); +extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId* xids); +extern TransactionId TransactionIdLatest(TransactionId mainxid, int nxids, const TransactionId* xids); +extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid); +extern bool LatestFetchTransactionIdDidAbort(TransactionId transactionId); +extern bool LatestFetchCSNDidAbort(TransactionId transactionId); +extern bool TransactionIdLogicallyPrecedes(TransactionId id1, TransactionId id2); + +/* in transam/varsup.c */ +#ifdef PGXC /* PGXC_DATANODE */ +extern void SetNextTransactionId(TransactionId xid, bool updateLatestCompletedXid); +extern void SetForceXidFromGTM(bool value); +extern bool GetForceXidFromGTM(void); +extern TransactionId GetNewTransactionId(bool isSubXact, TransactionState s); +#else +extern TransactionId GetNewTransactionId(bool isSubXact); +#endif /* PGXC */ +extern TransactionId ReadNewTransactionId(void); +extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid); +extern bool ForceTransactionIdLimitUpdate(void); +extern Oid GetNewObjectId(bool IsToastRel = false); +extern TransactionId SubTransGetTopParentXidFromProcs(TransactionId xid); +extern TransactionIdStatus TransactionIdGetStatus(TransactionId transactionId); + +#endif /* TRAMSAM_H */ diff -uprN postgresql-hll-2.14_old/include/access/tupconvert.h postgresql-hll-2.14/include/access/tupconvert.h --- postgresql-hll-2.14_old/include/access/tupconvert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/tupconvert.h 2020-12-12 17:06:43.067345716 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * tupconvert.h + * Tuple conversion support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupconvert.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPCONVERT_H +#define TUPCONVERT_H + +#include "access/htup.h" + +typedef struct TupleConversionMap { + TupleDesc indesc; /* tupdesc for source rowtype */ + TupleDesc outdesc; /* tupdesc for result rowtype */ + AttrNumber* attrMap; /* indexes of input fields, or 0 for null */ + Datum* invalues; /* workspace for deconstructing source */ + bool* inisnull; + Datum* outvalues; /* workspace for constructing result */ + bool* outisnull; +} TupleConversionMap; + +extern TupleConversionMap* convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char* msg); + +extern TupleConversionMap* convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc, const char* msg); + +extern HeapTuple do_convert_tuple(HeapTuple tuple, TupleConversionMap* map); + +extern void free_conversion_map(TupleConversionMap* map); + +#endif /* TUPCONVERT_H */ diff -uprN postgresql-hll-2.14_old/include/access/tupdesc.h postgresql-hll-2.14/include/access/tupdesc.h --- postgresql-hll-2.14_old/include/access/tupdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/tupdesc.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,182 @@ +/* ------------------------------------------------------------------------- + * + * tupdesc.h + * POSTGRES tuple descriptor definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupdesc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPDESC_H +#define TUPDESC_H + +#ifndef FRONTEND_PARSER +#include "postgres.h" +#else +#include "postgres_fe.h" +#endif +#include "access/attnum.h" +#include "catalog/pg_attribute.h" +#include "nodes/pg_list.h" + +/* + * Total number of different Table Access Method types. + */ +const int NUM_TABLE_AM = 2; + +/* + * range based values to specify the indexes + * for different table types to map access methods in + * class TableAccessorMethods + */ +typedef enum tableAmType +{ + TAM_INVALID = -1, + TAM_HEAP = 0, + TAM_USTORE = 1, +} TableAmType; + +const static uint32 HEAP_TUPLE = 1; +const static uint32 UHEAP_TUPLE = 2; + +#define TableAMGetTupleType(tableamType) (tableamType + 1) + +typedef struct attrDefault { + AttrNumber adnum; + char* adbin; /* nodeToString representation of expr */ +} AttrDefault; + +typedef struct constrCheck { + char* ccname; + char* ccbin; /* nodeToString representation of expr */ + bool ccvalid; + bool ccnoinherit; /* this is a non-inheritable constraint */ +} ConstrCheck; + +/* This structure contains constraints of a tuple */ +typedef struct tupleConstr { + AttrDefault* defval; /* array */ + ConstrCheck* check; /* array */ + AttrNumber* clusterKeys; /* cluster keys */ + uint16 clusterKeyNum; + uint16 num_defval; + uint16 num_check; + bool has_not_null; +} TupleConstr; + +/* This structure contains initdefval of a tuple */ +typedef struct tupInitDefVal { + Datum* datum; + bool isNull; + uint16 dataLen; +} TupInitDefVal; + +/* + * @hdfs + * This strrcture constains the following informations about on + * informational constraint: + * 1. constrname records informational constaint name. + * 2. contype records the informational constraint type. + * 'p' represnets pirmary key constraint. 'u' represents unique + * constraint. + * 3. nonforced records the enforced or forced attributtes of informationanl constaint. + * 4. enableOpt records the enalbe or disbale query optimization attribute of informational constaint. + */ +typedef struct InformationalConstraint { + NodeTag type; + char* constrname; + char contype; + bool nonforced; + bool enableOpt; +} InformationalConstraint; + +/* + * This struct is passed around within the backend to describe the structure + * of tuples. For tuples coming from on-disk relations, the information is + * collected from the pg_attribute, pg_attrdef, and pg_constraint catalogs. + * Transient row types (such as the result of a join query) have anonymous + * TupleDesc structs that generally omit any constraint info; therefore the + * structure is designed to let the constraints be omitted efficiently. + * + * Note that only user attributes, not system attributes, are mentioned in + * TupleDesc; with the exception that tdhasoid indicates if OID is present. + * + * If the tupdesc is known to correspond to a named rowtype (such as a table's + * rowtype) then tdtypeid identifies that type and tdtypmod is -1. Otherwise + * tdtypeid is RECORDOID, and tdtypmod can be either -1 for a fully anonymous + * row type, or a value >= 0 to allow the rowtype to be looked up in the + * typcache.c type cache. + * + * Tuple descriptors that live in caches (relcache or typcache, at present) + * are reference-counted: they can be deleted when their reference count goes + * to zero. Tuple descriptors created by the executor need no reference + * counting, however: they are simply created in the appropriate memory + * context and go away when the context is freed. We set the tdrefcount + * field of such a descriptor to -1, while reference-counted descriptors + * always have tdrefcount >= 0. + */ +typedef struct tupleDesc { + int natts; /* number of attributes in the tuple */ + bool tdisredistable; /* temp table created for data redistribution by the redis tool */ + Form_pg_attribute* attrs; + /* attrs[N] is a pointer to the description of Attribute Number N+1 */ + TupleConstr* constr; /* constraints, or NULL if none */ + TupInitDefVal* initdefvals; /* init default value due to ADD COLUMN */ + Oid tdtypeid; /* composite type ID for tuple type */ + int32 tdtypmod; /* typmod for tuple type */ + bool tdhasoid; /* tuple has oid attribute in its header */ + int tdrefcount; /* reference count, or -1 if not counting */ + TableAmType tdTableAmType; /*index for accessing the Table Accessor methods on singleton TableAccessorMethods */ +} * TupleDesc; + +/* Accessor for the i'th attribute of tupdesc. */ +#define TupleDescAttr(tupdesc, i) (tupdesc->attrs[(i)]) + +extern TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid, TableAmType tam = TAM_HEAP); + +extern TupleDesc CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute* attrs, TableAmType tam = TAM_HEAP); + +extern TupleDesc CreateTupleDescCopy(TupleDesc tupdesc); + +extern TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc); + +extern void FreeTupleDesc(TupleDesc tupdesc); + +extern void IncrTupleDescRefCount(TupleDesc tupdesc); +extern void DecrTupleDescRefCount(TupleDesc tupdesc); + +#define PinTupleDesc(tupdesc) \ + do { \ + if ((tupdesc)->tdrefcount >= 0) \ + IncrTupleDescRefCount(tupdesc); \ + } while (0) + +#define ReleaseTupleDesc(tupdesc) \ + do { \ + if ((tupdesc)->tdrefcount >= 0) \ + DecrTupleDescRefCount(tupdesc); \ + } while (0) + +extern bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2); +extern bool equalDeltaTupleDescs(TupleDesc main_tupdesc, TupleDesc delta_tupdesc); + +extern void TupleDescInitEntry( + TupleDesc desc, AttrNumber attribute_number, const char* attribute_name, Oid oidtypeid, int32 typmod, int attdim); + +extern void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attribute_number, Oid collationid); + +extern void VerifyAttrCompressMode(int8 mode, int attlen, const char* attname); + +extern TupleDesc BuildDescForRelation(List* schema, Node* oriented_from, char relkind = '\0'); + +extern TupleDesc BuildDescFromLists(List* names, List* types, List* typmods, List* collations); + +extern bool tupledesc_have_pck(TupleConstr* constr); + +extern void copyDroppedAttribute(Form_pg_attribute target, Form_pg_attribute source); + +#endif /* TUPDESC_H */ diff -uprN postgresql-hll-2.14_old/include/access/tupmacs.h postgresql-hll-2.14/include/access/tupmacs.h --- postgresql-hll-2.14_old/include/access/tupmacs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/tupmacs.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,188 @@ +/* ------------------------------------------------------------------------- + * + * tupmacs.h + * Tuple macros used by both index tuples and heap tuples. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupmacs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPMACS_H +#define TUPMACS_H + +/* + * check to see if the ATT'th bit of an array of 8-bit bytes is set. + */ +#define att_isnull(ATT, BITS) (!((BITS)[(uint32)(int32)(ATT) >> 3] & (1 << ((ATT)&0x07)))) + +/* + * Given a Form_pg_attribute and a pointer into a tuple's data area, + * return the correct value or pointer. + * + * We return a Datum value in all cases. If the attribute has "byval" false, + * we return the same pointer into the tuple data area that we're passed. + * Otherwise, we return the correct number of bytes fetched from the data + * area and extended to Datum form. + * + * On machines where Datum is 8 bytes, we support fetching 8-byte byval + * attributes; otherwise, only 1, 2, and 4-byte values are supported. + * + * Note that T must already be properly aligned for this to work correctly. + */ +#define fetchatt(A, T) fetch_att(T, (A)->attbyval, (A)->attlen) + +/* + * Same, but work from byval/len parameters rather than Form_pg_attribute. + */ +#if SIZEOF_DATUM == 8 + +#define fetch_att(T, attbyval, attlen) \ + ((attbyval) ? ((attlen) == (int)sizeof(Datum) \ + ? *((Datum*)(T)) \ + : ((attlen) == (int)sizeof(int32) \ + ? Int32GetDatum(*((int32*)(T))) \ + : ((attlen) == (int)sizeof(int16) \ + ? Int16GetDatum(*((int16*)(T))) \ + : (AssertMacro((attlen) == 1), CharGetDatum(*((char*)(T))))))) \ + : PointerGetDatum((char*)(T))) +#else /* SIZEOF_DATUM != 8 */ + +#define fetch_att(T, attbyval, attlen) \ + ((attbyval) \ + ? ((attlen) == (int)sizeof(int32) \ + ? Int32GetDatum(*((int32*)(T))) \ + : ((attlen) == (int)sizeof(int16) ? Int16GetDatum(*((int16*)(T))) \ + : (AssertMacro((attlen) == 1), CharGetDatum(*((char*)(T)))))) \ + : PointerGetDatum((char*)(T))) +#endif /* SIZEOF_DATUM == 8 */ + +/* + * att_align_datum aligns the given offset as needed for a datum of alignment + * requirement attalign and typlen attlen. attdatum is the Datum variable + * we intend to pack into a tuple (it's only accessed if we are dealing with + * a varlena type). Note that this assumes the Datum will be stored as-is; + * callers that are intending to convert non-short varlena datums to short + * format have to account for that themselves. + */ +#define att_align_datum(cur_offset, attalign, attlen, attdatum) \ + (((attlen) == -1 && VARATT_IS_SHORT(DatumGetPointer(attdatum))) ? (intptr_t)(cur_offset) \ + : att_align_nominal(cur_offset, attalign)) + +/* + * att_align_pointer performs the same calculation as att_align_datum, + * but is used when walking a tuple. attptr is the current actual data + * pointer; when accessing a varlena field we have to "peek" to see if we + * are looking at a pad byte or the first byte of a 1-byte-header datum. + * (A zero byte must be either a pad byte, or the first byte of a correctly + * aligned 4-byte length word; in either case we can align safely. A non-zero + * byte must be either a 1-byte length word, or the first byte of a correctly + * aligned 4-byte length word; in either case we need not align.) + * + * Note: some callers pass a "char *" pointer for cur_offset. This is + * a bit of a hack but should work all right as long as intptr_t is the + * correct width. + */ +#define att_align_pointer(cur_offset, attalign, attlen, attptr) \ + (((attlen) == -1 && VARATT_NOT_PAD_BYTE(attptr)) ? (intptr_t)(cur_offset) : att_align_nominal(cur_offset, attalign)) + +/* + * att_align_nominal aligns the given offset as needed for a datum of alignment + * requirement attalign, ignoring any consideration of packed varlena datums. + * There are three main use cases for using this macro directly: + * * we know that the att in question is not varlena (attlen != -1); + * in this case it is cheaper than the above macros and just as good. + * * we need to estimate alignment padding cost abstractly, ie without + * reference to a real tuple. We must assume the worst case that + * all varlenas are aligned. + * * within arrays, we unconditionally align varlenas (XXX this should be + * revisited, probably). + * + * The attalign cases are tested in what is hopefully something like their + * frequency of occurrence. + */ +#define att_align_nominal(cur_offset, attalign) \ + (((attalign) == 'i') \ + ? INTALIGN(cur_offset) \ + : (((attalign) == 'c') \ + ? (uintptr_t)(cur_offset) \ + : (((attalign) == 'd') ? DOUBLEALIGN(cur_offset) \ + : (AssertMacro((attalign) == 's'), SHORTALIGN(cur_offset))))) + +/* + * att_addlength_datum increments the given offset by the space needed for + * the given Datum variable. attdatum is only accessed if we are dealing + * with a variable-length attribute. + */ +#define att_addlength_datum(cur_offset, attlen, attdatum) \ + att_addlength_pointer(cur_offset, attlen, DatumGetPointer(attdatum)) + +/* + * att_addlength_pointer performs the same calculation as att_addlength_datum, + * but is used when walking a tuple --- attptr is the pointer to the field + * within the tuple. + * + * Note: some callers pass a "char *" pointer for cur_offset. This is + * actually perfectly OK, but probably should be cleaned up along with + * the same practice for att_align_pointer. + */ +#define att_addlength_pointer(cur_offset, attlen, attptr) \ + (((attlen) > 0) \ + ? ((cur_offset) + (attlen)) \ + : (((attlen) == -1) ? ((cur_offset) + VARSIZE_ANY(attptr)) \ + : (AssertMacro((attlen) == -2), (cur_offset) + (strlen((char*)(attptr)) + 1)))) + +/* + * store_att_byval is a partial inverse of fetch_att: store a given Datum + * value into a tuple data area at the specified address. However, it only + * handles the byval case, because in typical usage the caller needs to + * distinguish by-val and by-ref cases anyway, and so a do-it-all macro + * wouldn't be convenient. + */ +#if SIZEOF_DATUM == 8 + +#define store_att_byval(T, newdatum, attlen) \ + do { \ + switch (attlen) { \ + case sizeof(char): \ + *(char*)(T) = DatumGetChar(newdatum); \ + break; \ + case sizeof(int16): \ + *(int16*)(T) = DatumGetInt16(newdatum); \ + break; \ + case sizeof(int32): \ + *(int32*)(T) = DatumGetInt32(newdatum); \ + break; \ + case sizeof(Datum): \ + *(Datum*)(T) = (newdatum); \ + break; \ + default: \ + elog(ERROR, "unsupported byval length: %d", (int)(attlen)); \ + break; \ + } \ + } while (0) +#else /* SIZEOF_DATUM != 8 */ + +#define store_att_byval(T, newdatum, attlen) \ + do { \ + switch (attlen) { \ + case sizeof(char): \ + *(char*)(T) = DatumGetChar(newdatum); \ + break; \ + case sizeof(int16): \ + *(int16*)(T) = DatumGetInt16(newdatum); \ + break; \ + case sizeof(int32): \ + *(int32*)(T) = DatumGetInt32(newdatum); \ + break; \ + default: \ + elog(ERROR, "unsupported byval length: %d", (int)(attlen)); \ + break; \ + } \ + } while (0) +#endif /* SIZEOF_DATUM == 8 */ + +#endif diff -uprN postgresql-hll-2.14_old/include/access/tuptoaster.h postgresql-hll-2.14/include/access/tuptoaster.h --- postgresql-hll-2.14_old/include/access/tuptoaster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/tuptoaster.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,245 @@ +/* ------------------------------------------------------------------------- + * + * tuptoaster.h + * POSTGRES definitions for external and compressed storage + * of variable size attributes. + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * + * src/include/access/tuptoaster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPTOASTER_H +#define TUPTOASTER_H + +#include "access/htup.h" +#include "utils/relcache.h" + +/* + * This enables de-toasting of index entries. Needed until VACUUM is + * smart enough to rebuild indexes from scratch. + */ +#define TOAST_INDEX_HACK + +/* + * Find the maximum size of a tuple if there are to be N tuples per page. + */ +#define MaximumBytesPerTuple(tuplesPerPage) \ + MAXALIGN_DOWN((BLCKSZ - MAXALIGN(SizeOfPageHeaderData + (tuplesPerPage) * sizeof(ItemIdData))) / (tuplesPerPage)) + +/* + * These symbols control toaster activation. If a tuple is larger than + * TOAST_TUPLE_THRESHOLD, we will try to toast it down to no more than + * TOAST_TUPLE_TARGET bytes through compressing compressible fields and + * moving EXTENDED and EXTERNAL data out-of-line. + * + * The numbers need not be the same, though they currently are. It doesn't + * make sense for TARGET to exceed THRESHOLD, but it could be useful to make + * it be smaller. + * + * Currently we choose both values to match the largest tuple size for which + * TOAST_TUPLES_PER_PAGE tuples can fit on a heap page. + * + * XXX while these can be modified without initdb, some thought needs to be + * given to needs_toast_table() in toasting.c before unleashing random + * changes. Also see LOBLKSIZE in large_object.h, which can *not* be + * changed without initdb. + */ +#define TOAST_TUPLES_PER_PAGE 4 + +#define TOAST_TUPLE_THRESHOLD MaximumBytesPerTuple(TOAST_TUPLES_PER_PAGE) + +#define TOAST_TUPLE_TARGET TOAST_TUPLE_THRESHOLD + +/* + * The code will also consider moving MAIN data out-of-line, but only as a + * last resort if the previous steps haven't reached the target tuple size. + * In this phase we use a different target size, currently equal to the + * largest tuple that will fit on a heap page. This is reasonable since + * the user has told us to keep the data in-line if at all possible. + */ +#define TOAST_TUPLES_PER_PAGE_MAIN 1 + +#define TOAST_TUPLE_TARGET_MAIN MAXALIGN_DOWN(BLCKSZ - MAXALIGN(SizeOfHeapPageHeaderData + sizeof(ItemIdData))) + +/* + * If an index value is larger than TOAST_INDEX_TARGET, we will try to + * compress it (we can't move it out-of-line, however). Note that this + * number is per-datum, not per-tuple, for simplicity in index_form_tuple(). + */ +#define TOAST_INDEX_TARGET (MaxHeapTupleSize / 16) + +/* + * When we store an oversize datum externally, we divide it into chunks + * containing at most TOAST_MAX_CHUNK_SIZE data bytes. This number *must* + * be small enough that the completed toast-table tuple (including the + * ID and sequence fields and all overhead) will fit on a page. + * The coding here sets the size on the theory that we want to fit + * EXTERN_TUPLES_PER_PAGE tuples of maximum size onto a page. + * + * NB: Changing TOAST_MAX_CHUNK_SIZE requires an initdb. + */ +#define EXTERN_TUPLES_PER_PAGE 4 /* tweak only this */ + +#define EXTERN_TUPLE_MAX_SIZE MaximumBytesPerTuple(EXTERN_TUPLES_PER_PAGE) + +#define TOAST_MAX_CHUNK_SIZE \ + (EXTERN_TUPLE_MAX_SIZE - MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) - sizeof(Oid) - sizeof(int32) - VARHDRSZ) + +/* Size of an EXTERNAL datum that contains a standard TOAST pointer */ +#define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(struct varatt_external)) + +/* Size of an indirect datum that contains a standard TOAST pointer */ +#define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(struct varatt_indirect)) +/* + * Testing whether an externally-stored value is compressed now requires + * comparing extsize (the actual length of the external data) to rawsize + * (the original uncompressed datum's size). The latter includes VARHDRSZ + * overhead, the former doesn't. We never use compression unless it actually + * saves space, so we expect either equality or less-than. + */ +#define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer) \ + ((toast_pointer).va_extsize < (toast_pointer).va_rawsize - VARHDRSZ) + +/* + * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum + * into a local "struct varatt_external" toast pointer. This should be + * just a memcpy, but some versions of gcc seem to produce broken code + * that assumes the datum contents are aligned. Introducing an explicit + * intermediate "varattrib_1b_e *" variable seems to fix it. + */ +#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \ +do { \ + varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \ + errno_t rcs; \ + Assert(VARATT_IS_EXTERNAL(attre)); \ + if (VARATT_IS_EXTERNAL_BUCKET(attre)) \ + { \ + Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL + sizeof(int2)); \ + }\ + else\ + { \ + Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \ + }\ + rcs = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \ + securec_check(rcs, "", ""); \ +} while (0) + + +#define VARATT_EXTERNAL_GET_POINTER_B(toast_pointer, attr, bucketid) \ +do { \ + varattrib_1b_e *_attre = (varattrib_1b_e *) (attr); \ + errno_t _rc; \ + Assert(VARATT_IS_EXTERNAL(_attre)); \ + if (VARATT_IS_EXTERNAL_BUCKET(_attre)) \ + { \ + Assert(VARSIZE_EXTERNAL(_attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL + sizeof(int2)); \ + _rc = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(_attre), sizeof(toast_pointer)); \ + securec_check(_rc, "", ""); \ + _rc= memcpy_s(&(bucketid), sizeof(int2), VARDATA_EXTERNAL(_attre)+sizeof(toast_pointer), sizeof(int2)); \ + securec_check(_rc, "", ""); \ + } \ + else \ + { \ + Assert(VARSIZE_EXTERNAL(_attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \ + _rc = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(_attre), sizeof(toast_pointer)); \ + securec_check(_rc, "", ""); \ + bucketid = -1; \ + } \ +} while (0) + + +/* ---------- + * toast_insert_or_update - + * + * Called by heap_insert() and heap_update(). + * ---------- + */ +extern HeapTuple toast_insert_or_update( + Relation rel, HeapTuple newtup, HeapTuple oldtup, int options, Page pageForOldTup); + +/* ---------- + * toast_delete - + * + * Called by heap_delete(). + * ---------- + */ +extern void toast_delete(Relation rel, HeapTuple oldtup, int options); + +/* ---------- + * heap_tuple_fetch_attr() - + * + * Fetches an external stored attribute from the toast + * relation. Does NOT decompress it, if stored external + * in compressed format. + * ---------- + */ +extern struct varlena* heap_tuple_fetch_attr(struct varlena* attr); + +/* ---------- + * heap_tuple_untoast_attr() - + * + * Fully detoasts one attribute, fetching and/or decompressing + * it as needed. + * ---------- + */ +extern struct varlena* heap_tuple_untoast_attr(struct varlena* attr); + +/* ---------- + * heap_tuple_untoast_attr_slice() - + * + * Fetches only the specified portion of an attribute. + * (Handles all cases for attribute storage) + * ---------- + */ +extern struct varlena* heap_tuple_untoast_attr_slice(struct varlena* attr, int32 sliceoffset, int32 slicelength); + +/* ---------- + * toast_flatten_tuple - + * + * "Flatten" a tuple to contain no out-of-line toasted fields. + * (This does not eliminate compressed or short-header datums.) + * ---------- + */ +extern HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc); + +/* ---------- + * toast_flatten_tuple_attribute - + * + * If a Datum is of composite type, "flatten" it to contain no toasted fields. + * This must be invoked on any potentially-composite field that is to be + * inserted into a tuple. Doing this preserves the invariant that toasting + * goes only one level deep in a tuple. + * ---------- + */ +extern Datum toast_flatten_tuple_attribute(Datum value, Oid typeId, int32 typeMod); + +/* ---------- + * toast_compress_datum - + * + * Create a compressed version of a varlena datum, if possible + * ---------- + */ +extern Datum toast_compress_datum(Datum value); + +/* ---------- + * toast_raw_datum_size - + * + * Return the raw (detoasted) size of a varlena datum + * ---------- + */ +extern Size toast_raw_datum_size(Datum value); + +/* ---------- + * toast_datum_size - + * + * Return the storage size of a varlena datum + * ---------- + */ +extern Size toast_datum_size(Datum value); + +extern bool toastrel_valueid_exists(Relation toastrel, Oid valueid); + +#endif /* TUPTOASTER_H */ + diff -uprN postgresql-hll-2.14_old/include/access/twophase.h postgresql-hll-2.14/include/access/twophase.h --- postgresql-hll-2.14_old/include/access/twophase.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/twophase.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,179 @@ +/* ------------------------------------------------------------------------- + * + * twophase.h + * Two-phase-commit related declarations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/twophase.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TWOPHASE_H +#define TWOPHASE_H + +#include "storage/proc.h" +#include "utils/snapshot.h" +#include "gtm/gtm_c.h" + +#define GIDSIZE 200 +#define MAX_PREP_XACT_VERSIONS 64 + +/* + * GlobalTransactionData is defined in twophase.c; other places have no + * business knowing the internal definition. + */ +typedef struct GlobalTransactionData* GlobalTransaction; +typedef struct recover_two_phase_file_key { + TransactionId xid; /* recover the prepared transaction */ +} recover_two_phase_file_key; + +typedef struct recover_two_phase_file { + recover_two_phase_file_key key; /* hash key ... must be first */ + XLogRecPtr prepare_start_lsn; /* XLOG offset of prepare record start */ + XLogRecPtr prepare_end_lsn; /* XLOG offset of prepare record end */ +} recover_two_phase_file; + +typedef struct GlobalTransactionData { + GlobalTransaction next; /* list link for free list */ + int pgprocno; /* ID of associated dummy PGPROC */ + BackendId dummyBackendId; /* similar to backend id for backends */ + TimestampTz prepared_at; /* time of preparation */ + + /* + * Note that we need to keep track of two LSNs for each GXACT. + * We keep track of the start LSN because this is the address we must + * use to read state data back from WAL when committing a prepared GXACT. + * We keep track of the end LSN because that is the LSN we need to wait + * for prior to commit. + */ + XLogRecPtr prepare_start_lsn; /* XLOG offset of prepare record start */ + XLogRecPtr prepare_end_lsn; /* XLOG offset of prepare record end */ + TransactionId xid; /* The GXACT id */ + + Oid owner; /* ID of user that executed the xact */ + BackendId locking_backend; /* backend currently working on the xact */ + bool valid; /* TRUE if PGPROC entry is in proc array */ + bool ondisk; /* TRUE if prepare state file is on disk */ + bool inredo; /* TRUE if entry was added via xlog_redo */ + char gid[GIDSIZE]; /* The GID assigned to the prepared xact */ +} GlobalTransactionData; + +/* + * 2PC state file format: + * + * 1. TwoPhaseFileHeader + * 2. TransactionId[] (subtransactions) + * 3. ColFileNode[] (files to be deleted at commit) + * 4. ColFileNode[] (files to be deleted at abort) + * 5. SharedInvalidationMessage[] (inval messages to be sent at commit) + * 6. TwoPhaseRecordOnDisk + * 7. ... + * 8. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID) + * 9. CRC32 + * + * Each segment except the final CRC32 is MAXALIGN'd. + */ +/* + * Header for a 2PC state file + */ +#define TWOPHASE_MAGIC 0x57F94532 /* format identifier */ + +typedef struct TwoPhaseFileHeader { + uint32 magic; /* format identifier */ + uint32 total_len; /* actual file length */ + TransactionId xid; /* original transaction XID */ + Oid database; /* OID of database it was in */ + TimestampTz prepared_at; /* time of preparation */ + Oid owner; /* user running the transaction */ + int32 nsubxacts; /* number of following subxact XIDs */ + int32 ncommitrels; /* number of delete-on-commit rels */ + int32 nabortrels; /* number of delete-on-abort rels */ + int32 ninvalmsgs; /* number of cache invalidation messages */ + bool initfileinval; /* does relcache init file need invalidation? */ + char gid[GIDSIZE]; /* GID for transaction */ + int32 ncommitlibrarys; /* number of delete-on-commit library file */ + int32 nabortlibrarys; /* number of delete-on-abort library file */ +} TwoPhaseFileHeader; + +typedef struct ValidPrepXidData +{ + volatile unsigned int refCount; + unsigned int numPrepXid; + bool isOverflow; + TransactionId *validPrepXid; +} ValidPrepXidData; + +typedef ValidPrepXidData *ValidPrepXid; + +/* + * Two Phase Commit shared state. Access to this struct is protected + * by TwoPhaseStateLock. + */ +typedef struct TwoPhaseStateData { + /* Head of linked list of free GlobalTransactionData structs */ + GlobalTransaction freeGXacts; + + /* Number of valid prepXacts entries. */ + int numPrepXacts; + + /* GTM-LITE preplist ring buffer */ + ValidPrepXidData validPrepXids[MAX_PREP_XACT_VERSIONS]; + volatile ValidPrepXid currPrepXid; + volatile ValidPrepXid nextPrepXid; + + /* + * There are max_prepared_xacts items in this array, but C wants a + * fixed-size array. + */ + GlobalTransaction prepXacts[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} TwoPhaseStateData; /* VARIABLE LENGTH STRUCT */ + +extern int PendingPreparedXactsCount; + +extern Size TwoPhaseShmemSize(void); +extern void TwoPhaseShmemInit(void); + +extern void AtAbort_Twophase(void); +extern void PostPrepare_Twophase(void); + +extern PGPROC* TwoPhaseGetDummyProc(TransactionId xid); +extern BackendId TwoPhaseGetDummyBackendId(TransactionId xid); + +extern GlobalTransaction MarkAsPreparing(GTM_TransactionHandle handle, TransactionId xid, const char* gid, + TimestampTz prepared_at, Oid owner, Oid databaseid); + +extern void EndPrepare(GlobalTransaction gxact); +extern void StartPrepare(GlobalTransaction gxact); +extern bool StandbyTransactionIdIsPrepared(TransactionId xid); + +extern TransactionId PrescanPreparedTransactions(TransactionId** xids_p, int* nxids_p); +extern void StandbyRecoverPreparedTransactions(void); +extern void RecoverPreparedTransactions(void); + +extern void CheckPointTwoPhase(XLogRecPtr redo_horizon); + +void DropBufferForDelRelinXlogUsingScan(ColFileNodeRel *delrels, int ndelrels); +void DropBufferForDelRelsinXlogUsingHash(ColFileNodeRel *delrels, int ndelrels); + +extern void FinishPreparedTransaction(const char* gid, bool isCommit); + +extern bool TransactionIdIsPrepared(TransactionId xid); + +extern bool IsTransactionIdMarkedPrepared(TransactionId xid); + +extern void SetLocalSnapshotPreparedArray(Snapshot snapshot); + +extern int GetPendingXactCount(void); + +extern void PrepareRedoAdd(char* buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn); +extern void PrepareRedoRemove(TransactionId xid, bool giveWarning); +extern void restoreTwoPhaseData(void); +extern void RemoveStaleTwophaseState(TransactionId xid); + +extern void RecoverPrepareTransactionCSNLog(char* buf); +extern int get_snapshot_defualt_prepared_num(void); + +#endif /* TWOPHASE_H */ diff -uprN postgresql-hll-2.14_old/include/access/twophase_rmgr.h postgresql-hll-2.14/include/access/twophase_rmgr.h --- postgresql-hll-2.14_old/include/access/twophase_rmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/twophase_rmgr.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * twophase_rmgr.h + * Two-phase-commit resource managers definition + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/twophase_rmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TWOPHASE_RMGR_H +#define TWOPHASE_RMGR_H + +typedef void (*TwoPhaseCallback)(TransactionId xid, uint16 info, void* recdata, uint32 len); +typedef uint8 TwoPhaseRmgrId; + +/* + * Built-in resource managers + */ +#define TWOPHASE_RM_END_ID 0 +#define TWOPHASE_RM_LOCK_ID 1 +#define TWOPHASE_RM_PGSTAT_ID 2 +#define TWOPHASE_RM_MULTIXACT_ID 3 +#define TWOPHASE_RM_PREDICATELOCK_ID 4 +#define TWOPHASE_RM_MAX_ID TWOPHASE_RM_PREDICATELOCK_ID + +extern const TwoPhaseCallback g_twophase_recover_callbacks[]; +extern const TwoPhaseCallback g_twophase_postcommit_callbacks[]; +extern const TwoPhaseCallback g_twophase_postabort_callbacks[]; +extern const TwoPhaseCallback g_twophase_standby_recover_callbacks[]; + +extern void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void* data, uint32 len); + +#endif /* TWOPHASE_RMGR_H */ diff -uprN postgresql-hll-2.14_old/include/access/valid.h postgresql-hll-2.14/include/access/valid.h --- postgresql-hll-2.14_old/include/access/valid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/valid.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,56 @@ +/* ------------------------------------------------------------------------- + * + * valid.h + * POSTGRES tuple qualification validity definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/valid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VALID_H +#define VALID_H + +/* + * HeapKeyTest + * + * Test a heap tuple to see if it satisfies a scan key. + */ +#define HeapKeyTest(tuple, tupdesc, nkeys, keys, result) \ + do { \ + /* Use underscores to protect the variables passed in as parameters */ \ + int __cur_nkeys = (nkeys); \ + ScanKey __cur_keys = (keys); \ + \ + (result) = true; /* may change */ \ + for (; __cur_nkeys--; __cur_keys++) { \ + Datum __atp; \ + bool __isnull; \ + Datum __test; \ + \ + if (__cur_keys->sk_flags & SK_ISNULL) { \ + (result) = false; \ + break; \ + } \ + \ + __atp = heap_getattr((tuple), __cur_keys->sk_attno, (tupdesc), &__isnull); \ + \ + if (__isnull) { \ + (result) = false; \ + break; \ + } \ + \ + __test = \ + FunctionCall2Coll(&__cur_keys->sk_func, __cur_keys->sk_collation, __atp, __cur_keys->sk_argument); \ + \ + if (!DatumGetBool(__test)) { \ + (result) = false; \ + break; \ + } \ + } \ + } while (0) + +#endif /* VALID_H */ diff -uprN postgresql-hll-2.14_old/include/access/visibilitymap.h postgresql-hll-2.14/include/access/visibilitymap.h --- postgresql-hll-2.14_old/include/access/visibilitymap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/visibilitymap.h 2020-12-12 17:06:43.068345729 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * visibilitymap.h + * visibility map interface + * + * + * Portions Copyright (c) 2007-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/visibilitymap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VISIBILITYMAP_H +#define VISIBILITYMAP_H + +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "utils/relcache.h" + +/* + * Size of the bitmap on each visibility map page, in bytes. There's no + * extra headers, so the whole page minus the standard page header is + * used for the bitmap. + */ +#define MAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData)) + +/* Number of bits allocated for each heap block. */ +#define BITS_PER_HEAPBLOCK 1 + +/* Number of heap blocks we can represent in one byte. */ +#define HEAPBLOCKS_PER_BYTE 8 + +/* Number of heap blocks we can represent in one visibility map page. */ +#define HEAPBLOCKS_PER_PAGE (MAPSIZE * HEAPBLOCKS_PER_BYTE) + +/* Mapping from heap block number to the right bit in the visibility map */ +#define HEAPBLK_TO_MAPBLOCK(x) ((x) / HEAPBLOCKS_PER_PAGE) +#define HEAPBLK_TO_MAPBYTE(x) (((x) % HEAPBLOCKS_PER_PAGE) / HEAPBLOCKS_PER_BYTE) +#define HEAPBLK_TO_MAPBIT(x) ((x) % HEAPBLOCKS_PER_BYTE) + +extern void visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf); +extern bool visibilitymap_clear_page(Page mappage, BlockNumber heapBlk); + +extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer* vmbuf); +extern bool visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf); + +extern void visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf, XLogRecPtr recptr, Buffer vmbuf, + TransactionId cutoff_xid, bool free_dict); +extern bool visibilitymap_test(Relation rel, BlockNumber heapBlk, Buffer* vmbuf); +extern BlockNumber visibilitymap_count(Relation rel, Partition part); + +extern void visibilitymap_truncate(Relation rel, BlockNumber nheapblocks); +extern BlockNumber VisibilityMapCalTruncBlkNo(BlockNumber relBlkNo); +extern bool visibilitymap_set_page(Page page, BlockNumber heapBlk); +extern void XLogBlockTruncateRelVM(Relation rel, BlockNumber nheapblocks); + +#endif /* VISIBILITYMAP_H */ diff -uprN postgresql-hll-2.14_old/include/access/xact.h postgresql-hll-2.14/include/access/xact.h --- postgresql-hll-2.14_old/include/access/xact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xact.h 2020-12-12 17:06:43.069345742 +0800 @@ -0,0 +1,431 @@ +/* ------------------------------------------------------------------------- + * + * xact.h + * postgres transaction system definitions + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/access/xact.h + * + * ------------------------------------------------------------------------- + */ +#ifndef XACT_H +#define XACT_H + +#include "access/cstore_am.h" +#include "access/xlogreader.h" +#ifdef PGXC +#include "gtm/gtm_c.h" +#endif +#include "nodes/pg_list.h" +#include "storage/relfilenode.h" +#include "utils/datetime.h" +#include "utils/hsearch.h" +#include "utils/snapshot.h" +#include "utils/plancache.h" +#include "threadpool/threadpool_worker.h" + +/* + * Xact isolation levels + */ +#define XACT_READ_UNCOMMITTED 0 +#define XACT_READ_COMMITTED 1 +#define XACT_REPEATABLE_READ 2 +#define XACT_SERIALIZABLE 3 + +/* + * start- and end-of-transaction callbacks for dynamically loaded modules + */ +typedef enum { + XACT_EVENT_START, // For MOT, callback will notify us about new transaction. + XACT_EVENT_COMMIT, + XACT_EVENT_END_TRANSACTION, + XACT_EVENT_RECORD_COMMIT, // For MOT, to write redo and apply changes (after setCommitCsn). + XACT_EVENT_ABORT, + XACT_EVENT_PREPARE, + XACT_EVENT_COMMIT_PREPARED, + XACT_EVENT_ROLLBACK_PREPARED, + XACT_EVENT_PREROLLBACK_CLEANUP // For MOT, to cleanup some internal resources. +} XactEvent; + +typedef void (*XactCallback)(XactEvent event, void* arg); + +typedef enum { + SUBXACT_EVENT_START_SUB, + SUBXACT_EVENT_COMMIT_SUB, + SUBXACT_EVENT_ABORT_SUB +} SubXactEvent; + +typedef void (*SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void* arg); + +#ifdef PGXC +/* + * GTM callback events + */ +typedef enum { + GTM_EVENT_COMMIT, + GTM_EVENT_ABORT, + GTM_EVENT_PREPARE +} GTMEvent; + +typedef void (*GTMCallback)(GTMEvent event, void* arg); +#endif + +/* + * We implement three isolation levels internally. + * The two stronger ones use one snapshot per database transaction; + * the others use one snapshot per statement. + * Serializable uses predicate locks in addition to snapshots. + * These macros should be used to check which isolation level is selected. + */ +#define IsolationUsesXactSnapshot() (u_sess->utils_cxt.XactIsoLevel >= XACT_REPEATABLE_READ) +#define IsolationIsSerializable() (u_sess->utils_cxt.XactIsoLevel == XACT_SERIALIZABLE) + +extern THR_LOCAL bool TwoPhaseCommit; + +typedef enum { + SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */ + SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */ + SYNCHRONOUS_COMMIT_REMOTE_RECEIVE, /* wait for local flush and remote receive */ + SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote write */ + SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */ + SYNCHRONOUS_BAD +} SyncCommitLevel; + +/* Define the default setting for synchonous_commit */ +#define SYNCHRONOUS_COMMIT_ON SYNCHRONOUS_COMMIT_REMOTE_FLUSH + +/* Synchronous commit level */ +extern volatile int synchronous_commit; + +/* ---------------- + * transaction-related XLOG entries + * ---------------- + */ + +/* + * XLOG allows to store some information in high 4 bits of log + * record xl_info field + */ +#define XLOG_XACT_COMMIT 0x00 +#define XLOG_XACT_PREPARE 0x10 +#define XLOG_XACT_ABORT 0x20 +#define XLOG_XACT_COMMIT_PREPARED 0x30 +#define XLOG_XACT_ABORT_PREPARED 0x40 +#define XLOG_XACT_ASSIGNMENT 0x50 +#define XLOG_XACT_COMMIT_COMPACT 0x60 + +typedef struct xl_xact_assignment { + TransactionId xtop; /* assigned XID's top-level XID */ + int nsubxacts; /* number of subtransaction XIDs */ + TransactionId xsub[1]; /* assigned subxids */ +} xl_xact_assignment; + +#define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub) + +typedef struct xl_xact_commit_compact { + TimestampTz xact_time; /* time of commit */ + uint64 csn; /* commit sequence number */ + int nsubxacts; /* number of subtransaction XIDs */ + /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */ + TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_xact_commit_compact; + +#define MinSizeOfXactCommitCompact offsetof(xl_xact_commit_compact, subxacts) + +typedef struct xl_xact_commit { + TimestampTz xact_time; /* time of commit */ + uint64 csn; /* commit sequence number */ + uint64 xinfo; /* info flags */ + int nrels; /* number of RelFileNodes */ + int nsubxacts; /* number of subtransaction XIDs */ + int nmsgs; /* number of shared inval msgs */ + Oid dbId; /* u_sess->proc_cxt.MyDatabaseId */ + Oid tsId; /* u_sess->proc_cxt.MyDatabaseTableSpace */ + int nlibrary; /* number of library */ + /* Array of ColFileNode(s) to drop at commit */ + ColFileNodeRel xnodes[1]; /* VARIABLE LENGTH ARRAY */ + /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */ + /* ARRAY OF SHARED INVALIDATION MESSAGES FOLLOWS */ +} xl_xact_commit; + +#define MinSizeOfXactCommit offsetof(xl_xact_commit, xnodes) + +/* + * These flags are set in the xinfo fields of WAL commit records, + * indicating a variety of additional actions that need to occur + * when emulating transaction effects during recovery. + * They are named XactCompletion... to differentiate them from + * EOXact... routines which run at the end of the original + * transaction completion. + */ +#define XACT_COMPLETION_UPDATE_RELCACHE_FILE 0x01 +#define XACT_COMPLETION_FORCE_SYNC_COMMIT 0x02 +#define XACT_MOT_ENGINE_USED 0x04 + +/* Access macros for above flags */ +#define XactCompletionRelcacheInitFileInval(xinfo) (xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) +#define XactCompletionForceSyncCommit(xinfo) (xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) +#define XactMOTEngineUsed(xinfo) (xinfo & XACT_MOT_ENGINE_USED) + +typedef struct xl_xact_abort { + TimestampTz xact_time; /* time of abort */ + int nrels; /* number of RelFileNodes */ + int nsubxacts; /* number of subtransaction XIDs */ + int nlibrary; /* number of library */ + /* Array of ColFileNode(s) to drop at abort */ + ColFileNodeRel xnodes[1]; /* VARIABLE LENGTH ARRAY */ + /* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */ +} xl_xact_abort; + +/* Note the intentional lack of an invalidation message array c.f. commit */ + +#define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes) + +/* + * COMMIT_PREPARED and ABORT_PREPARED are identical to COMMIT/ABORT records + * except that we have to store the XID of the prepared transaction explicitly + * --- the XID in the record header will be for the transaction doing the + * COMMIT PREPARED or ABORT PREPARED command. + */ + +typedef struct xl_xact_commit_prepared { + TransactionId xid; /* XID of prepared xact */ + xl_xact_commit crec; /* COMMIT record */ + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} xl_xact_commit_prepared; + +#define MinSizeOfXactCommitPrepared offsetof(xl_xact_commit_prepared, crec.xnodes) + +typedef struct xl_xact_abort_prepared { + TransactionId xid; /* XID of prepared xact */ + xl_xact_abort arec; /* ABORT record */ + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} xl_xact_abort_prepared; + +#define MinSizeOfXactAbortPrepared offsetof(xl_xact_abort_prepared, arec.xnodes) + +typedef struct TransactionStateData TransactionStateData; +typedef TransactionStateData* TransactionState; + +extern TransactionId NextXidAfterReovery; +extern TransactionId OldestXidAfterRecovery; +extern volatile bool IsPendingXactsRecoveryDone; + +typedef struct { + TransactionId txnId; + Snapshot snapshot; + + /* Combocid.c */ + HTAB* comboHash; + void* comboCids; /* ComboCidKey */ + int usedComboCids; + int sizeComboCids; + + /* xact.c */ + void* CurrentTransactionState; /* TransactionState */ + SubTransactionId subTransactionId; + SubTransactionId currentSubTransactionId; + CommandId currentCommandId; + TimestampTz xactStartTimestamp; + TimestampTz stmtStartTimestamp; + TimestampTz xactStopTimestamp; + TimestampTz GTMxactStartTimestamp; + TimestampTz stmtSystemTimestamp; + + /* snapmgr.c */ + TransactionId RecentGlobalXmin; + TransactionId TransactionXmin; + TransactionId RecentXmin; + + /* procarray.c */ + TransactionId* allDiffXids; /*different xids between GTM and the local */ + uint32 DiffXidsCount; /*number of different xids between GTM and the local*/ +} StreamTxnContext; + +#define STCSaveElem(dest, src) ((dest) = (src)) +#define STCRestoreElem(dest, src) ((src) = (dest)) + +#ifdef ENABLE_MOT +typedef void (*RedoCommitCallback)(TransactionId xid, void* arg); +void RegisterRedoCommitCallback(RedoCommitCallback callback, void* arg); +void CallRedoCommitCallback(TransactionId xid); +#endif + +typedef enum SavepointStmtType +{ + SUB_STMT_SAVEPOINT, + SUB_STMT_RELEASE, + SUB_STMT_ROLLBACK_TO +} SavepointStmtType; + +/* + * savepoint sent state structure + * It record whether the savepoint cmd has been sent to non-execution cn. + */ +typedef struct SavepointData +{ + char* cmd; + char* name; + bool hasSent; + SavepointStmtType stmtType; + GlobalTransactionId transactionId; +} SavepointData; + +/* ---------------- + * extern definitions + * ---------------- + */ +extern void InitTopTransactionState(void); +extern void InitCurrentTransactionState(void); +extern bool IsTransactionState(void); +extern bool IsAbortedTransactionBlockState(void); +extern void RemoveFromDnHashTable(void); +extern bool WorkerThreadCanSeekAnotherMission(ThreadStayReason* reason); +extern TransactionId GetTopTransactionId(void); +extern TransactionId GetTopTransactionIdIfAny(void); +extern TransactionId GetCurrentTransactionId(void); +extern TransactionId GetCurrentTransactionIdIfAny(void); +extern GTM_TransactionKey GetCurrentTransactionKey(void); +extern GTM_TransactionKey GetCurrentTransactionKeyIfAny(void); +extern GTM_TransactionHandle GetTransactionHandleIfAny(TransactionState s); +extern GTM_TransactionHandle GetCurrentTransactionHandleIfAny(void); +extern GTM_Timeline GetCurrentTransactionTimeline(void); +extern TransactionState GetCurrentTransactionState(void); +extern TransactionId GetParentTransactionIdIfAny(TransactionState s); +extern void ResetTransactionInfo(void); + +#ifdef PGXC /* PGXC_COORD */ +extern TransactionId GetNewGxidGTM(TransactionState s, bool is_sub_xact); +extern bool GetCurrentLocalParamStatus(void); +extern void SetCurrentLocalParamStatus(bool status); +extern GlobalTransactionId GetTopGlobalTransactionId(void); +extern void SetTopGlobalTransactionId(GlobalTransactionId gxid); +#endif +extern TransactionId GetTransactionIdFromGidStr(char* gid); +extern TransactionId GetStableLatestTransactionId(void); +extern SubTransactionId GetCurrentSubTransactionId(void); +extern bool SubTransactionIsActive(SubTransactionId subxid); +extern CommandId GetCurrentCommandId(bool used); +extern TimestampTz GetCurrentTransactionStartTimestamp(void); +extern TimestampTz GetCurrentStatementStartTimestamp(void); +extern TimestampTz GetCurrentStatementLocalStartTimestamp(void); +extern TimestampTz GetCurrentTransactionStopTimestamp(void); +extern void SetCurrentStatementStartTimestamp(); +extern void SetStatementStartTimestamp(TimestampTz timestamp); +#ifdef PGXC +extern TimestampTz GetCurrentGTMStartTimestamp(void); +extern TimestampTz GetCurrentStmtsysTimestamp(void); +extern void SetCurrentGTMTimestamp(TimestampTz timestamp); +extern void SetCurrentStmtTimestamp(TimestampTz timestamp); +void SetCurrentStmtTimestamp(); +extern void SetCurrentGTMDeltaTimestamp(void); +extern void SetStmtSysGTMDeltaTimestamp(void); +extern void CleanGTMDeltaTimeStamp(); +extern void CleanstmtSysGTMDeltaTimeStamp(); +#endif +extern int GetCurrentTransactionNestLevel(void); +extern void MarkCurrentTransactionIdLoggedIfAny(void); +extern void CopyTransactionIdLoggedIfAny(TransactionState state); +extern bool TransactionIdIsCurrentTransactionId(TransactionId xid); +extern void CommandCounterIncrement(void); +extern void ForceSyncCommit(void); +extern void StartTransactionCommand(bool STP_rollback = false); +extern void CommitTransactionCommand(bool STP_commit = false); +extern bool CommitSubTransactionExpectionCheck(void); +extern void SaveCurrentSTPTopTransactionState(); +extern void RestoreCurrentSTPTopTransactionState(); +extern bool IsStpInOuterSubTransaction(); +#ifdef PGXC +extern void AbortCurrentTransactionOnce(void); +#endif +extern void AbortCurrentTransaction(bool STP_rollback = false); +extern void AbortSubTransaction(bool STP_rollback = false); +extern void CleanupSubTransaction(void); +extern void BeginTransactionBlock(void); +extern bool EndTransactionBlock(void); +extern bool PrepareTransactionBlock(const char* gid); +extern void UserAbortTransactionBlock(void); +extern void ReleaseSavepoint(List* options); +extern void DefineSavepoint(const char* name); +extern void RollbackToSavepoint(List* options); +extern void BeginInternalSubTransaction(const char* name); +extern void ReleaseCurrentSubTransaction(void); +extern void RollbackAndReleaseCurrentSubTransaction(void); +extern bool IsSubTransaction(void); +extern void SetCurrentTransactionId(TransactionId tid); +extern bool IsTransactionBlock(void); +extern bool IsTransactionOrTransactionBlock(void); +extern char TransactionBlockStatusCode(void); +extern void AbortOutOfAnyTransaction(bool reserve_topxact_abort = false); +extern void PreventTransactionChain(bool isTopLevel, const char* stmtType); +extern void RequireTransactionChain(bool isTopLevel, const char* stmtType); +extern bool IsInTransactionChain(bool isTopLevel); +extern void RegisterXactCallback(XactCallback callback, void* arg); +extern void UnregisterXactCallback(XactCallback callback, const void* arg); +extern void RegisterSubXactCallback(SubXactCallback callback, void* arg); +extern void UnregisterSubXactCallback(SubXactCallback callback, const void* arg); +extern void CallXactCallbacks(XactEvent event); +extern bool AtEOXact_GlobalTxn(bool commit, bool is_write = false); + +#ifdef PGXC +extern void RegisterGTMCallback(GTMCallback callback, void* arg); +extern void RegisterSequenceCallback(GTMCallback callback, void* arg); +extern void UnregisterGTMCallback(GTMCallback callback, const void* arg); +extern void RegisterTransactionNodes(int count, void** connections, bool write); +extern void PrintRegisteredTransactionNodes(void); +extern void ForgetTransactionNodes(void); +extern void RegisterTransactionLocalNode(bool write); +extern bool IsTransactionLocalNode(bool write); +extern void ForgetTransactionLocalNode(void); +extern bool IsXidImplicit(const char* xid); +extern void SaveReceivedCommandId(CommandId cid); +extern void SetReceivedCommandId(CommandId cid); +extern CommandId GetReceivedCommandId(void); +extern void ReportCommandIdChange(CommandId cid); +extern void ReportTopXid(TransactionId local_top_xid); +extern bool IsSendCommandId(void); +extern void SetSendCommandId(bool status); +extern bool IsPGXCNodeXactReadOnly(void); +extern bool IsPGXCNodeXactDatanodeDirect(void); +#endif + +extern int xactGetCommittedChildren(TransactionId** ptr); + +extern void xact_redo(XLogReaderState* record); +extern void xact_desc(StringInfo buf, XLogReaderState* record); + +extern void xactApplyXLogDropRelation(XLogReaderState* record); + +extern void StreamTxnContextSaveXact(StreamTxnContext* stc); +extern void StreamTxnContextRestoreXact(StreamTxnContext* stc); +extern void StreamTxnContextSetTransactionState(StreamTxnContext* stc); +extern void StreamTxnContextSetSnapShot(void* snapshotPtr); +extern void StreamTxnContextSetMyPgXactXmin(TransactionId xmin); + +extern void WLMTxnContextSetTransactionState(); +extern void parseAndRemoveLibrary(char* library, int nlibrary); +extern bool IsInLiveSubtransaction(); +extern void ExtendCsnlogForSubtrans(TransactionId parent_xid, int nsub_xid, TransactionId* sub_xids); +extern CommitSeqNo SetXact2CommitInProgress(TransactionId xid, CommitSeqNo csn); +extern void XactGetRelFiles(XLogReaderState* record, ColFileNodeRel** xnodesPtr, int* nrelsPtr); +extern HTAB* relfilenode_hashtbl_create(); +extern CommitSeqNo getLocalNextCSN(); +#ifdef ENABLE_MOT +extern bool IsMOTEngineUsed(); +extern bool IsMOTEngineUsedInParentTransaction(); +extern bool IsPGEngineUsed(); +extern bool IsMixedEngineUsed(); +extern void SetCurrentTransactionStorageEngine(StorageEngineType storageEngineType); +#endif + +extern char* GetSavepointName(List* options); +extern void RecordSavepoint(const char* cmd, const char* name, bool hasSent, SavepointStmtType stmtType); +extern void SendSavepointToRemoteCoordinator(); +extern void HandleReleaseOrRollbackSavepoint(const char* cmd, const char* name, SavepointStmtType stmtType); +extern void FreeSavepointList(); + +#endif /* XACT_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlog_basic.h postgresql-hll-2.14/include/access/xlog_basic.h --- postgresql-hll-2.14_old/include/access/xlog_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlog_basic.h 2020-12-12 17:06:43.069345742 +0800 @@ -0,0 +1,397 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * 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. + * --------------------------------------------------------------------------------------- + * + * xlog_basic.h + * Some basic definations of xlog operation . + * + * + * IDENTIFICATION + * src/include/access/xlog_basic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOG_BASIC_H +#define XLOG_BASIC_H + +#include "c.h" +#include "access/xlogdefs.h" +#include "storage/relfilenode.h" +#include "access/rmgr.h" +#include "port/pg_crc32c.h" +#include "utils/pg_crc.h" +/* + * These macros encapsulate knowledge about the exact layout of XLog file + * names, timeline history file names, and archive-status file names. + */ +#define MAXFNAMELEN 64 + +/* size of the buffer allocated for error message. */ +#define MAX_ERRORMSG_LEN 1000 + +/* + * Each page of XLOG file has a header like this: + */ +#define XLOG_PAGE_MAGIC 0xD074 /* can be used as WAL version indicator */ +#define XLOG_PAGE_MAGIC_OLD 0xD073 /* can be used as WAL old version indicator */ + +/* + * The XLOG is split into WAL segments (physical files) of the size indicated + * by XLOG_SEG_SIZE. + */ +#define XLogSegSize ((uint32)XLOG_SEG_SIZE) +#define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLOG_SEG_SIZE) +#define XLogRecordMaxSize ((uint32)0x3fffffff) /* 1 gigabyte - 1 */ + +/* Compute XLogRecPtr with segment number and offset. */ +#define XLogSegNoOffsetToRecPtr(segno, offset, dest) (dest) = (segno)*XLOG_SEG_SIZE + (offset) + +/* + * Compute ID and segment from an XLogRecPtr. + * + * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg, + * a boundary byte is taken to be in the previous segment. This is suitable + * for deciding which segment to write given a pointer to a record end, + * for example. + */ +#define XLByteToSeg(xlrp, logSegNo) logSegNo = (xlrp) / XLogSegSize + +#define XLByteToPrevSeg(xlrp, logSegNo) logSegNo = ((xlrp)-1) / XLogSegSize + +/* + * Is an XLogRecPtr within a particular XLOG segment? + * + * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg, + * a boundary byte is taken to be in the previous segment. + */ +#define XLByteInSeg(xlrp, logSegNo) (((xlrp) / XLogSegSize) == (logSegNo)) + +#define XLByteInPrevSeg(xlrp, logSegNo) ((((xlrp)-1) / XLogSegSize) == (logSegNo)) + +/* Check if an XLogRecPtr value is in a plausible range */ +#define XRecOffIsValid(xlrp) ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD) + +/* + * The XLog directory and control file (relative to $PGDATA) + */ +#define XLOGDIR "pg_xlog" +#define XLOG_CONTROL_FILE "global/pg_control" +#define XLOG_CONTROL_FILE_BAK "global/pg_control.backup" +#define MAX_PAGE_FLUSH_LSN_FILE "global/max_page_flush_lsn" + +#define PG_LSN_XLOG_FLUSH_CHK_FILE "global/pg_lsnxlogflushchk" +#define REDO_STATS_FILE "redo.state" +#define REDO_STATS_FILE_TMP "redo.state.tmp" + + +#define InvalidRepOriginId 0 + +/* + * Block IDs used to distinguish different kinds of record fragments. Block + * references are numbered from 0 to XLR_MAX_BLOCK_ID. A rmgr is free to use + * any ID number in that range (although you should stick to small numbers, + * because the WAL machinery is optimized for that case). A couple of ID + * numbers are reserved to denote the "main" data portion of the record. + * + * The maximum is currently set at 32, quite arbitrarily. Most records only + * need a handful of block references, but there are a few exceptions that + * need more. + */ +#define XLR_MAX_BLOCK_ID 32 + +#define XLR_BLOCK_ID_DATA_SHORT 255 +#define XLR_BLOCK_ID_DATA_LONG 254 +#define XLR_BLOCK_ID_ORIGIN 253 + +/* + * The fork number fits in the lower 4 bits in the fork_flags field. The upper + * bits are used for flags. + */ +#define BKPBLOCK_FORK_MASK 0x0F +#define BKPBLOCK_FLAG_MASK 0xF0 +#define BKPBLOCK_HAS_IMAGE 0x10 /* block data is an XLogRecordBlockImage */ +#define BKPBLOCK_HAS_DATA 0x20 +#define BKPBLOCK_WILL_INIT 0x40 /* redo will re-init the page */ +#define BKPBLOCK_SAME_REL 0x80 /* RelFileNode omitted, same as previous */ + +typedef struct XLogReaderState XLogReaderState; + +/* Function type definition for the read_page callback */ +typedef int (*XLogPageReadCB)(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* readBuf, TimeLineID* pageTLI); + +typedef struct { + /* Is this block ref in use? */ + bool in_use; + + /* Identify the block this refers to */ + RelFileNode rnode; + ForkNumber forknum; + BlockNumber blkno; + + /* copy of the fork_flags field from the XLogRecordBlockHeader */ + uint8 flags; + + /* Information on full-page image, if any */ + bool has_image; + char* bkp_image; + uint16 hole_offset; + uint16 hole_length; + + /* Buffer holding the rmgr-specific data associated with this block */ + bool has_data; + char* data; + uint16 data_len; + uint16 data_bufsz; + XLogRecPtr last_lsn; + uint16 extra_flag; +#ifdef USE_ASSERT_CHECKING + uint8 replayed; +#endif +} DecodedBkpBlock; + +/* + * The overall layout of an XLOG record is: + * Fixed-size header (XLogRecord struct) + * XLogRecordBlockHeader struct + * XLogRecordBlockHeader struct + * ... + * XLogRecordDataHeader[Short|Long] struct + * block data + * block data + * ... + * main data + * + * There can be zero or more XLogRecordBlockHeaders, and 0 or more bytes of + * rmgr-specific data not associated with a block. XLogRecord structs + * always start on MAXALIGN boundaries in the WAL files, but the rest of + * the fields are not aligned. + * + * The XLogRecordBlockHeader, XLogRecordDataHeaderShort and + * XLogRecordDataHeaderLong structs all begin with a single 'id' byte. It's + * used to distinguish between block references, and the main data structs. + */ +typedef struct XLogRecord { + uint32 xl_tot_len; /* total len of entire record */ + uint32 xl_term; + TransactionId xl_xid; /* xact id */ + XLogRecPtr xl_prev; /* ptr to previous record in log */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + int2 xl_bucket_id; + pg_crc32c xl_crc; /* CRC for this record */ + + /* XLogRecordBlockHeaders and XLogRecordDataHeader follow, no padding */ +} XLogRecord; + +typedef struct XLogRecordOld { + uint32 xl_tot_len; /* total len of entire record */ + ShortTransactionId xl_xid; /* xact id */ + XLogRecPtrOld xl_prev; /* ptr to previous record in log */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + /* 2 bytes of padding here, initialize to zero */ + pg_crc32 xl_crc; /* CRC for this record */ +} XLogRecordOld; + +struct XLogReaderState { + /* + * + * Public parameters + * + */ + + /* + * Data input callback (mandatory). + * + * This callback shall read at least reqLen valid bytes of the xlog page + * starting at targetPagePtr, and store them in readBuf. The callback + * shall return the number of bytes read (never more than XLOG_BLCKSZ), or + * -1 on failure. The callback shall sleep, if necessary, to wait for the + * requested bytes to become available. The callback will not be invoked + * again for the same page unless more than the returned number of bytes + * are needed. + * + * targetRecPtr is the position of the WAL record we're reading. Usually + * it is equal to targetPagePtr + reqLen, but sometimes xlogreader needs + * to read and verify the page or segment header, before it reads the + * actual WAL record it's interested in. In that case, targetRecPtr can + * be used to determine which timeline to read the page from. + * + * The callback shall set *pageTLI to the TLI of the file the page was + * read from. It is currently used only for error reporting purposes, to + * reconstruct the name of the WAL file where an error occurred. + */ + XLogPageReadCB read_page; + + /* + * System identifier of the xlog files we're about to read. Set to zero + * (the default value) if unknown or unimportant. + */ + uint64 system_identifier; + + /* + * Opaque data for callbacks to use. Not used by XLogReader. + */ + void* private_data; + + /* + * Start and end point of last record read. EndRecPtr is also used as the + * position to read next, if XLogReadRecord receives an invalid recptr. + */ + XLogRecPtr ReadRecPtr; /* start of last record read */ + XLogRecPtr EndRecPtr; /* end+1 of last record read */ + + RepOriginId record_origin; + + /* ---------------------------------------- + * Decoded representation of current record + * + * Use XLogRecGet* functions to investigate the record; these fields + * should not be accessed directly. + * ---------------------------------------- + */ + XLogRecord* decoded_record; /* currently decoded record */ + + char* main_data; /* record's main data portion */ + uint32 main_data_len; /* main data portion's length */ + uint32 main_data_bufsz; /* allocated size of the buffer */ + + /* information about blocks referenced by the record. */ + DecodedBkpBlock blocks[XLR_MAX_BLOCK_ID + 1]; + + int max_block_id; /* highest block_id in use (-1 if none) */ + + /* ---------------------------------------- + * private/internal state + * ---------------------------------------- + */ + + /* + * Buffer for currently read page (XLOG_BLCKSZ bytes, valid up to at least + * readLen bytes) + */ + char* readBuf; + uint32 readLen; + + /* last read segment, segment offset, TLI for data currently in readBuf */ + XLogSegNo readSegNo; + uint32 readOff; + TimeLineID readPageTLI; + + /* the current read segment, segment offset */ + XLogSegNo curReadSegNo; + uint32 curReadOff; + + /* + * Beginning of prior page read, and its TLI. Doesn't necessarily + * correspond to what's in readBuf; used for timeline sanity checks. + */ + XLogRecPtr latestPagePtr; + TimeLineID latestPageTLI; + + /* beginning of the WAL record being read. */ + XLogRecPtr currRecPtr; + + /* Buffer for current ReadRecord result (expandable) */ + char* readRecordBuf; + uint32 readRecordBufSize; + + /* Buffer to hold error message */ + char* errormsg_buf; + + /* add for batch redo */ + uint32 refcount; + // For parallel recovery + bool isPRProcess; + bool isDecode; + bool isFullSyncCheckpoint; +}; + +#define SizeOfXLogRecord (offsetof(XLogRecord, xl_crc) + sizeof(pg_crc32c)) +#define SizeOfXLogRecordOld (offsetof(XLogRecordOld, xl_crc) + sizeof(pg_crc32)) + +typedef struct XLogPageHeaderData { + uint16 xlp_magic; /* magic value for correctness checks */ + uint16 xlp_info; /* flag bits, see below */ + TimeLineID xlp_tli; /* TimeLineID of first record on page */ + XLogRecPtr xlp_pageaddr; /* XLOG address of this page */ + + /* + * When there is not enough space on current page for whole record, we + * continue on the next page. xlp_rem_len is the number of bytes + * remaining from a previous page. + * + * Note that xl_rem_len includes backup-block data; that is, it tracks + * xl_tot_len not xl_len in the initial header. Also note that the + * continuation data isn't necessarily aligned. + */ + uint32 xlp_rem_len; /* total len of remaining data for record */ +} XLogPageHeaderData; + +#define SizeOfXLogShortPHD MAXALIGN(sizeof(XLogPageHeaderData)) + +typedef XLogPageHeaderData* XLogPageHeader; + +/* + * When the XLP_LONG_HEADER flag is set, we store additional fields in the + * page header. (This is ordinarily done just in the first page of an + * XLOG file.) The additional fields serve to identify the file accurately. + */ +typedef struct XLogLongPageHeaderData { + XLogPageHeaderData std; /* standard header fields */ + uint64 xlp_sysid; /* system identifier from pg_control */ + uint32 xlp_seg_size; /* just as a cross-check */ + uint32 xlp_xlog_blcksz; /* just as a cross-check */ +} XLogLongPageHeaderData; +typedef struct PageLsnInfo +{ + XLogRecPtr max_page_flush_lsn; + pg_crc32c crc; +} PageLsnInfo; + +#define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData)) + +typedef XLogLongPageHeaderData* XLogLongPageHeader; + +/* When record crosses page boundary, set this flag in new page's header */ +#define XLP_FIRST_IS_CONTRECORD 0x0001 +/* This flag indicates a "long" page header */ +#define XLP_LONG_HEADER 0x0002 +/* This flag indicates backup blocks starting in this page are optional */ +#define XLP_BKP_REMOVABLE 0x0004 +/* All defined flag bits in xlp_info (used for validity checking of header) */ +#define XLP_ALL_FLAGS 0x0007 + +/* + * Macros for manipulating XLOG pointers + */ +#define XLogPageHeaderSize(hdr) (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD) + +/* Align a record pointer to next page */ +#define NextLogPage(recptr) \ + do { \ + if ((recptr) % XLOG_BLCKSZ != 0) \ + XLByteAdvance(recptr, (XLOG_BLCKSZ - (recptr) % XLOG_BLCKSZ)); \ + } while (0) + +/* transform old version LSN into new version. */ +#define XLogRecPtrSwap(x) (((uint64)((x).xlogid)) << 32 | (x).xrecoff) + + + +#endif /* XLOG_BASIC_H */ + diff -uprN postgresql-hll-2.14_old/include/access/xlogdefs.h postgresql-hll-2.14/include/access/xlogdefs.h --- postgresql-hll-2.14_old/include/access/xlogdefs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlogdefs.h 2020-12-12 17:06:43.069345742 +0800 @@ -0,0 +1,133 @@ +/* + * xlogdefs.h + * + * Postgres transaction log manager record pointer and + * timeline number definitions + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlogdefs.h + */ +#ifndef XLOG_DEFS_H +#define XLOG_DEFS_H + +#include /* need open() flags */ + +typedef struct XLogRecPtrOld { + uint32 xlogid; /* log file #, 0 based */ + uint32 xrecoff; /* byte offset of location in log file */ +} XLogRecPtrOld; + +#define InvalidXLogRecPtrOld \ + (XLogRecPtrOld) \ + { \ + 0, 0 \ + } + +/* + * Pointer to a location in the XLOG. These pointers are 64 bits wide, + * because we don't want them ever to overflow. + */ +typedef uint64 XLogRecPtr; + +/* + * Zero is used indicate an invalid pointer. Bootstrap skips the first possible + * WAL segment, initializing the first WAL page at XLOG_SEG_SIZE, so no XLOG + * record can begin at zero. + */ +#define InvalidXLogRecPtr (XLogRecPtr)0 +#define InvalidXLogSegPtr 0 +const uint32 g_InvalidTermDN = 0; + +#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr) + +/* + * XLogSegNo - physical log file sequence number. + */ +typedef uint64 XLogSegNo; + +/* + * Macros for comparing XLogRecPtrs + */ +#define XLByteLT(a, b) ((a) < (b)) +#define XLByteLE(a, b) ((a) <= (b)) +#define XLByteEQ(a, b) ((a) == (b)) +/* + * Macro for caculate the difference between two given record pointer. + */ +#define XLByteDifference(a, b) (a - b) + +/* + * Macro for advancing a record pointer by the specified number of bytes. + */ +#define XLByteAdvance(recptr, nbytes) (recptr) += nbytes + +/* + * TimeLineID (TLI) - identifies different database histories to prevent + * confusion after restoring a prior state of a database installation. + * TLI does not change in a normal stop/restart of the database (including + * crash-and-recover cases); but we must assign a new TLI after doing + * a recovery to a prior state, a/k/a point-in-time recovery. This makes + * the new WAL logfile sequence we generate distinguishable from the + * sequence that was generated in the previous incarnation. + */ +typedef uint32 TimeLineID; +#define DEFAULT_TIMELINE_ID 1 + +/* + * Replication origin id - this is located in this file to avoid having to + * include origin.h in a bunch of xlog related places. + */ +typedef int RepOriginId; + +/* + * Because O_DIRECT bypasses the kernel buffers, and because we never + * read those buffers except during crash recovery or if wal_level != minimal, + * it is a win to use it in all cases where we sync on each write(). We could + * allow O_DIRECT with fsync(), but it is unclear if fsync() could process + * writes not buffered in the kernel. Also, O_DIRECT is never enough to force + * data to the drives, it merely tries to bypass the kernel cache, so we still + * need O_SYNC/O_DSYNC. + */ +#ifdef O_DIRECT +#define PG_O_DIRECT O_DIRECT +#else +#define PG_O_DIRECT 0 +#endif + +/* + * This chunk of hackery attempts to determine which file sync methods + * are available on the current platform, and to choose an appropriate + * default method. We assume that fsync() is always available, and that + * configure determined whether fdatasync() is. + */ +#if defined(O_SYNC) +#define OPEN_SYNC_FLAG O_SYNC +#elif defined(O_FSYNC) +#define OPEN_SYNC_FLAG O_FSYNC +#endif + +#if defined(O_DSYNC) +#if defined(OPEN_SYNC_FLAG) +/* O_DSYNC is distinct? */ +#if O_DSYNC != OPEN_SYNC_FLAG +#define OPEN_DATASYNC_FLAG O_DSYNC +#endif +#else /* !defined(OPEN_SYNC_FLAG) */ +/* Win32 only has O_DSYNC */ +#define OPEN_DATASYNC_FLAG O_DSYNC +#endif +#endif + +#if defined(PLATFORM_DEFAULT_SYNC_METHOD) +#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD +#elif defined(OPEN_DATASYNC_FLAG) +#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC +#elif defined(HAVE_FDATASYNC) +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#else +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC +#endif + +#endif /* XLOG_DEFS_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlog.h postgresql-hll-2.14/include/access/xlog.h --- postgresql-hll-2.14_old/include/access/xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlog.h 2020-12-12 17:06:43.069345742 +0800 @@ -0,0 +1,509 @@ +/* + * xlog.h + * + * PostgreSQL transaction log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlog.h + */ +#ifndef XLOG_H +#define XLOG_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "access/xloginsert.h" +#include "access/xlogreader.h" +#include "catalog/pg_control.h" +#include "datatype/timestamp.h" +#include "lib/stringinfo.h" +#include "access/parallel_recovery/redo_item.h" +#include "knl/knl_instance.h" +#include "access/htup.h" +#include "storage/lwlock.h" + +#include + +/* Sync methods */ +#define SYNC_METHOD_FSYNC 0 +#define SYNC_METHOD_FDATASYNC 1 +#define SYNC_METHOD_OPEN 2 /* for O_SYNC */ +#define SYNC_METHOD_FSYNC_WRITETHROUGH 3 +#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */ + +/* + * Like InRecovery, standbyState is only valid in the startup process. + * In all other processes it will have the value STANDBY_DISABLED (so + * InHotStandby will read as FALSE). + * + * In DISABLED state, we're performing crash recovery or hot standby was + * disabled in postgresql.conf. + * + * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but + * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record + * to initialize our master-transaction tracking system. + * + * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING + * state. The tracked information might still be incomplete, so we can't allow + * connections yet, but redo functions must update the in-memory state when + * appropriate. + * + * In SNAPSHOT_READY mode, we have full knowledge of transactions that are + * (or were) running in the master at the current WAL location. Snapshots + * can be taken, and read-only queries can be run. + */ +typedef enum { + STANDBY_DISABLED, + STANDBY_INITIALIZED, + STANDBY_SNAPSHOT_PENDING, + STANDBY_SNAPSHOT_READY +} HotStandbyState; + +#define InHotStandby (t_thrd.xlog_cxt.standbyState >= STANDBY_SNAPSHOT_PENDING) + +#define DUMMYSTANDBY_CONNECT_INTERVAL 3 // unit second +#define DUMMYSTANDBY_CHECK_INTERVAL 1 // unit second +#define SYNC_DUMMY_STANDBY_END 100 + +#define REP_CONN_ARRAY 2 // support 2 relp connection + +const static XLogRecPtr MAX_XLOG_REC_PTR = (XLogRecPtr)0xFFFFFFFFFFFFFFFF; +extern volatile uint64 sync_system_identifier; + +/* + * Codes indicating where we got a WAL file from during recovery, or where + * to attempt to get one. These are chosen so that they can be OR'd together + * in a bitmask state variable. + */ +#define XLOG_FROM_ARCHIVE (1 << 0) /* Restored using restore_command */ +#define XLOG_FROM_PG_XLOG (1 << 1) /* Existing file in pg_xlog */ +#define XLOG_FROM_STREAM (1 << 2) /* Streamed from master */ + +/* + * Recovery target type. + * Only set during a Point in Time recovery, not when standby_mode = on + */ +typedef enum { + RECOVERY_TARGET_UNSET, + RECOVERY_TARGET_XID, + RECOVERY_TARGET_TIME, + RECOVERY_TARGET_NAME, + RECOVERY_TARGET_LSN +#ifdef PGXC + , + RECOVERY_TARGET_BARRIER +#endif +} RecoveryTargetType; + +/* WAL levels */ +typedef enum WalLevel { + WAL_LEVEL_MINIMAL = 0, + WAL_LEVEL_ARCHIVE, + WAL_LEVEL_HOT_STANDBY, + WAL_LEVEL_LOGICAL +} WalLevel; + +#define XLogArchivingActive() \ + (u_sess->attr.attr_common.XLogArchiveMode && g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_ARCHIVE) +#define XLogArchiveCommandSet() (u_sess->attr.attr_storage.XLogArchiveCommand[0] != '\0') +#define XLogArchiveDestSet() (u_sess->attr.attr_storage.XLogArchiveDest[0] != '\0') + +/* + * Is WAL-logging necessary for archival or log-shipping, or can we skip + * WAL-logging if we fsync() the data before committing instead? + */ +#define XLogIsNeeded() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_ARCHIVE) + +/* + * Is a full-page image needed for hint bit updates? + * + * Normally, we don't WAL-log hint bit updates, but if checksums are enabled, + * we have to protect them against torn page writes. When you only set + * individual bits on a page, it's still consistent no matter what combination + * of the bits make it to disk, but the checksum wouldn't match. Also WAL-log + * them if forced by wal_log_hints=on. + */ +#define XLogHintBitIsNeeded() (g_instance.attr.attr_storage.wal_log_hints) + +/* Do we need to WAL-log information required only for Hot Standby and logical replication? */ +#define XLogStandbyInfoActive() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_HOT_STANDBY) +/* Do we need to WAL-log information required only for logical replication? */ +#define XLogLogicalInfoActive() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_LOGICAL) +extern const char* DemoteModeDescs[]; +extern const int DemoteModeNum; + +#define DemoteModeDesc(mode) (((mode) > 0 && (mode) < DemoteModeNum) ? DemoteModeDescs[(mode)] : DemoteModeDescs[0]) + +extern bool XLogBackgroundFlush(void); + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALFlushWaitLock; + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALInitSegLock; + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALBufferInitWaitLock; + +#define WAL_INSERT_STATUS_ENTRIES 4194304 +#define WAL_NOT_COPIED 0 +#define WAL_COPIED 1 +#define WAL_COPY_SUSPEND (-1) +#define WAL_SCANNED_LRC_INIT (-2) + +/* (ientry + 1) % WAL_INSERT_STATUS_ENTRIES */ +#define GET_NEXT_STATUS_ENTRY(ientry) ((ientry + 1) & (WAL_INSERT_STATUS_ENTRIES - 1)) + +#define GET_STATUS_ENTRY_INDEX(ientry) ientry + +struct WalInsertStatusEntry { + /* The end LSN of the record corresponding to this entry */ + uint64 endLSN; + + /* The log record counter of the record corresponding to this entry */ + int32 LRC; + + /* WAL copy status: "0" - not copied; "1" - copied */ + uint32 status; +}; + +struct WALFlushWaitLockPadded { + WALFlushWaitLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +struct WALBufferInitWaitLockPadded { + WALBufferInitWaitLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +struct WALInitSegLockPadded { + WALInitSegLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +/* + * OR-able request flag bits for checkpoints. The "cause" bits are used only + * for logging purposes. Note: the flags must be defined so that it's + * sensible to OR together request flags arising from different requestors. + * + * Note: one exception is CHECKPOINT_FILE_SYNC, with which checkpointer + * will only do file sync operation. Since normal checkpointer process also + * includes file sync, this flag is unset while there are concurrent normal checkpoint + * requests. + */ + +/* These directly affect the behavior of CreateCheckPoint and subsidiaries */ +#define CHECKPOINT_IS_SHUTDOWN 0x0001 /* Checkpoint is for shutdown */ +#define CHECKPOINT_END_OF_RECOVERY \ + 0x0002 /* Like shutdown checkpoint, \ + * but issued at end of WAL \ + * recovery */ +#define CHECKPOINT_FILE_SYNC 0x0004 /* File sync */ +#define CHECKPOINT_IMMEDIATE 0x0008 /* Do it without delays */ +#define CHECKPOINT_FORCE 0x0010 /* Force even if no activity */ +/* These are important to RequestCheckpoint */ +#define CHECKPOINT_WAIT 0x0020 /* Wait for completion */ +/* These indicate the cause of a checkpoint request */ +#define CHECKPOINT_CAUSE_XLOG 0x0040 /* XLOG consumption */ +#define CHECKPOINT_CAUSE_TIME 0x0080 /* Elapsed time */ + +/* Passed to PageListBackWrite() */ +#define CHECKPOINT_BACKWRITE 0x0100 /* checkpoint request */ +#define STRATEGY_BACKWRITE 0x0200 /* strategy backwrite */ +#define LAZY_BACKWRITE 0x0400 /* lazy backwrite */ +#define PAGERANGE_BACKWRITE 0x0800 /* PageRangeBackWrite */ + +/* Checkpoint statistics */ +typedef struct CheckpointStatsData { + TimestampTz ckpt_start_t; /* start of checkpoint */ + TimestampTz ckpt_write_t; /* start of flushing buffers */ + TimestampTz ckpt_sync_t; /* start of fsyncs */ + TimestampTz ckpt_sync_end_t; /* end of fsyncs */ + TimestampTz ckpt_end_t; /* end of checkpoint */ + + int ckpt_bufs_written; /* # of buffers written */ + + int ckpt_segs_added; /* # of new xlog segments created */ + int ckpt_segs_removed; /* # of xlog segments deleted */ + int ckpt_segs_recycled; /* # of xlog segments recycled */ + + int ckpt_sync_rels; /* # of relations synced */ + uint64 ckpt_longest_sync; /* Longest sync for one relation */ + uint64 ckpt_agg_sync_time; /* The sum of all the individual sync + * times, which is not necessarily the + * same as the total elapsed time for + * the entire sync phase. */ +} CheckpointStatsData; + +/* + * Current full page write info we get. forcePageWrites here is different with + * forcePageWrites in XLogInsert, if forcePageWrites sets, we force to write + * the page regardless of the page lsn. + */ +typedef struct XLogFPWInfo { + XLogRecPtr redoRecPtr; + bool doPageWrites; + bool forcePageWrites; +} XLogFPWInfo; + +struct XLogRecData; + +/* + * Shared-memory data structures for XLOG control + * + * LogwrtRqst indicates a byte position that we need to write and/or fsync + * the log up to (all records before that point must be written or fsynced). + * LogwrtResult indicates the byte positions we have already written/fsynced. + * These structs are identical but are declared separately to indicate their + * slightly different functions. + * + * To read XLogCtl->LogwrtResult, you must hold either info_lck or + * WALWriteLock. To update it, you need to hold both locks. The point of + * this arrangement is that the value can be examined by code that already + * holds WALWriteLock without needing to grab info_lck as well. In addition + * to the shared variable, each backend has a private copy of LogwrtResult, + * which is updated when convenient. + * + * The request bookkeeping is simpler: there is a shared XLogCtl->LogwrtRqst + * (protected by info_lck), but we don't need to cache any copies of it. + * + * info_lck is only held long enough to read/update the protected variables, + * so it's a plain spinlock. The other locks are held longer (potentially + * over I/O operations), so we use LWLocks for them. These locks are: + * + * WALInsertLock: must be held to insert a record into the WAL buffers. + * + * WALWriteLock: must be held to write WAL buffers to disk (XLogWrite or + * XLogFlush). + * + * ControlFileLock: must be held to read/update control file or create + * new log file. + * + * CheckpointLock: must be held to do a checkpoint or restartpoint (ensures + * only one checkpointer at a time; currently, with all checkpoints done by + * the checkpointer, this is just pro forma). + * + * ---------- + */ + +typedef struct XLogwrtRqst { + XLogRecPtr Write; /* last byte + 1 to write out */ + XLogRecPtr Flush; /* last byte + 1 to flush */ +} XLogwrtRqst; + +typedef struct XLogwrtResult { + XLogRecPtr Write; /* last byte + 1 written out */ + XLogRecPtr Flush; /* last byte + 1 flushed */ +} XLogwrtResult; + +extern void XLogMultiFileInit(int advance_xlog_file_num); + +typedef struct TermFileData { + uint32 term; + bool finish_redo; +} TermFileData; + +extern void XLogMultiFileInit(int advance_xlog_file_num); +extern XLogRecPtr XLogInsertRecord(struct XLogRecData* rdata, XLogRecPtr fpw_lsn, bool isupgrade = false); +extern void XLogWaitFlush(XLogRecPtr recptr); +extern void XLogWaitBufferInit(XLogRecPtr recptr); +extern void UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force); +extern bool XLogBackgroundFlush(void); +extern bool XLogNeedsFlush(XLogRecPtr RecPtr); +extern int XLogFileInit(XLogSegNo segno, bool* use_existent, bool use_lock); +extern int XLogFileOpen(XLogSegNo segno); + +extern void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli); +extern void XLogSetAsyncXactLSN(XLogRecPtr record); +extern void XLogSetReplicationSlotMinimumLSN(XLogRecPtr lsn); +extern void XLogSetReplicationSlotMaximumLSN(XLogRecPtr lsn); +extern XLogRecPtr XLogGetReplicationSlotMaximumLSN(void); +extern XLogRecPtr XLogGetReplicationSlotMinimumLSNByOther(void); + +extern XLogRecPtr XLogGetLastRemovedSegno(void); +extern void xlog_redo(XLogReaderState* record); +extern void xlog_desc(StringInfo buf, XLogReaderState* record); + +extern void issue_xlog_fsync(int fd, XLogSegNo segno); + +extern bool RecoveryInProgress(void); +extern bool HotStandbyActive(void); +extern bool HotStandbyActiveInReplay(void); +extern bool XLogInsertAllowed(void); +extern void GetXLogReceiptTime(TimestampTz* rtime, bool* fromStream); +extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID* targetTLI, XLogRecPtr* ReplayReadPtr = NULL); +extern void SetXLogReplayRecPtr(XLogRecPtr readRecPtr, XLogRecPtr endRecPtr); +extern void DumpXlogCtl(); + +extern void CheckRecoveryConsistency(void); + +extern XLogRecPtr GetXLogReplayRecPtrInPending(void); +extern XLogRecPtr GetStandbyFlushRecPtr(TimeLineID* targetTLI); +extern XLogRecPtr GetXLogInsertRecPtr(void); +extern XLogRecPtr GetXLogInsertEndRecPtr(void); +extern XLogRecPtr GetXLogWriteRecPtr(void); +extern bool RecoveryIsPaused(void); +extern void SetRecoveryPause(bool recoveryPause); +extern TimestampTz GetLatestXTime(void); +extern TimestampTz GetCurrentChunkReplayStartTime(void); +extern char* XLogFileNameP(TimeLineID tli, XLogSegNo segno); +extern pg_crc32 GetXlogRecordCrc(XLogRecPtr RecPtr, bool& crcvalid); +extern bool IsCheckPoint(XLogReaderState* record); +extern bool IsRestartPointSafe(const XLogRecPtr checkPoint); +extern bool HasTimelineUpdate(XLogReaderState* record, bool bOld); +extern void UpdateTimeline(CheckPoint* checkPoint); + +extern void UpdateControlFile(void); +extern uint64 GetSystemIdentifier(void); +extern void SetSystemIdentifier(uint64 system_identifier); +extern TimeLineID GetThisTimeID(void); +extern void SetThisTimeID(uint64 timelineID); +extern Size XLOGShmemSize(void); +extern void XLOGShmemInit(void); +extern void BootStrapXLOG(void); +extern int XLogSemas(void); +extern void InitWalSemaphores(void); +extern void StartupXLOG(void); +extern void ShutdownXLOG(int code, Datum arg); +extern void InitXLOGAccess(void); +extern void StartupDummyStandby(void); +extern void CreateCheckPoint(int flags); +extern bool CreateRestartPoint(int flags); +extern void XLogPutNextOid(Oid nextOid); +extern XLogRecPtr XLogRestorePoint(const char* rpName); +extern void UpdateFullPageWrites(void); +extern void GetFullPageWriteInfo(XLogFPWInfo* fpwInfo_p); +extern XLogRecPtr GetRedoRecPtr(void); +extern XLogRecPtr GetInsertRecPtr(void); +extern XLogRecPtr GetFlushRecPtr(void); +extern TimeLineID GetRecoveryTargetTLI(void); +extern void DummyStandbySetRecoveryTargetTLI(TimeLineID timeLineID); + +extern bool CheckFinishRedoSignal(void); +extern bool CheckPromoteSignal(void); +extern bool CheckPrimarySignal(void); +extern bool CheckStandbySignal(void); +extern bool CheckNormalSignal(void); +extern int CheckSwitchoverSignal(void); + +extern void WakeupRecovery(void); +extern void WakeupDataRecovery(void); +extern void SetWalWriterSleeping(bool sleeping); +extern uint64 XLogDiff(XLogRecPtr end, XLogRecPtr start); + +extern bool CheckFpwBeforeFirstCkpt(void); +extern void DisableFpwBeforeFirstCkpt(void); + +extern Size LsnXlogFlushChkShmemSize(void); +extern void LsnXlogFlushChkShmInit(void); +extern void heap_xlog_logical_new_page(XLogReaderState* record); +extern bool IsServerModeStandby(void); + +extern void SetCBMTrackedLSN(XLogRecPtr trackedLSN); +extern XLogRecPtr GetCBMTrackedLSN(void); +extern XLogRecPtr GetCBMRotateLsn(void); +void SetCBMRotateLsn(XLogRecPtr rotate_lsn); +extern void SetCBMFileStartLsn(XLogRecPtr currCbmNameStartLsn); +extern XLogRecPtr GetCBMFileStartLsn(void); + +extern void SetDelayXlogRecycle(bool toDelay, bool isRedo = false); +extern bool GetDelayXlogRecycle(void); +extern void SetDDLDelayStartPtr(XLogRecPtr ddlDelayStartPtr); +extern XLogRecPtr GetDDLDelayStartPtr(void); +extern void heap_xlog_bcm_new_page(xl_heap_logical_newpage* xlrec, RelFileNode node, char* cuData); + +/* + * Starting/stopping a base backup + */ +extern XLogRecPtr do_pg_start_backup(const char* backupidstr, bool fast, char** labelfile); +extern void startupInitRoachBackup(void); +extern void set_start_backup_flag(bool startFlag); +extern bool get_startBackup_flag(void); +extern bool GetDelayXlogRecycle(void); +extern XLogRecPtr GetDDLDelayStartPtr(void); +extern XLogRecPtr do_pg_stop_backup(char* labelfile, bool waitforarchive); +extern void do_pg_abort_backup(void); +extern void enable_delay_xlog_recycle(bool isRedo = false); +extern void disable_delay_xlog_recycle(bool isRedo = false); +extern void startupInitDelayXlog(void); +extern XLogRecPtr enable_delay_ddl_recycle(void); +extern char* getLastRewindTime(); +extern void disable_delay_ddl_recycle(XLogRecPtr barrierLSN, bool isForce, XLogRecPtr* startLSN, XLogRecPtr* endLSN); +extern void startupInitDelayDDL(void); +extern void execDelayedDDL(XLogRecPtr startLSN, XLogRecPtr endLSN, bool ignoreCBMErr); +extern bool IsRoachRestore(void); + +extern void CloseXlogFilesAtThreadExit(void); +extern void SetLatestXTime(TimestampTz xtime); +extern CheckPoint update_checkpoint(XLogReaderState* record); +XLogRecord* XLogParallelReadNextRecord(XLogReaderState* xlogreader); + +void ResourceManagerStartup(void); +void ResourceManagerStop(void); +void rm_redo_error_callback(void* arg); +extern void load_server_mode(void); +extern void WaitCheckpointSync(void); +extern void btree_clear_imcompleteAction(); +extern void update_max_page_flush_lsn(XLogRecPtr biggest_lsn, ThreadId thdId, bool is_force); +extern void set_global_max_page_flush_lsn(XLogRecPtr lsn); +XLogRecPtr get_global_max_page_flush_lsn(); +void GetRecoveryLatch(); +void ReLeaseRecoveryLatch(); +void ExtremRtoUpdateMinCheckpoint(); +bool IsRecoveryDone(); + +void CopyXlogForForceFinishRedo(XLogSegNo logSegNo, uint32 termId, XLogReaderState *xlogreader, + XLogRecPtr lastRplEndLsn); +void RenameXlogForForceFinishRedo(XLogSegNo beginSegNo, TimeLineID tli, uint32 termId); +void ReOpenXlog(XLogReaderState *xlogreader); +void SetSwitchHistoryFile(XLogRecPtr switchLsn, XLogRecPtr catchLsn, uint32 termId); +void CheckMaxPageFlushLSN(XLogRecPtr reqLsn); +bool CheckForForceFinishRedoTrigger(TermFileData *term_file); + +extern XLogRecPtr XlogRemoveSegPrimary; + +/* File path names (all relative to $PGDATA) */ +#define BACKUP_LABEL_FILE "backup_label" +#define DISABLE_CONN_FILE "disable_conn_file" +#define BACKUP_LABEL_OLD "backup_label.old" +#define BACKUP_LABEL_FILE_ROACH "backup_label.roach" +#define BACKUP_LABEL_FILE_ROACH_DONE "backup_label_roach.done" +#define DELAY_XLOG_RECYCLE_FILE "delay_xlog_recycle" +#define DELAY_DDL_RECYCLE_FILE "delay_ddl_recycle" +#define REWIND_LABLE_FILE "rewind_lable" + +typedef struct delayddlrange { + XLogRecPtr startLSN; + XLogRecPtr endLSN; +} DelayDDLRange; + +#define InvalidDelayRange \ + (DelayDDLRange) \ + { \ + InvalidXLogRecPtr, InvalidXLogRecPtr \ + } +#define DISABLE_DDL_DELAY_TIMEOUT 1800000 +#define ENABLE_DDL_DELAY_TIMEOUT 60000 +#define ROACH_BARRIER_PREFIX "roach_barrier_" +static const uint64 INVALID_READ_OFF = 0xFFFFFFFF; + +inline bool force_finish_enabled() +{ + return (g_instance.attr.attr_storage.enable_update_max_page_flush_lsn != 0); +} + +static inline void WakeupWalSemaphore(PGSemaphore sema) +{ + PGSemaphoreReset(sema); + PGSemaphoreUnlock(sema); +} + +#endif /* XLOG_H */ diff -uprN postgresql-hll-2.14_old/include/access/xloginsert.h postgresql-hll-2.14/include/access/xloginsert.h --- postgresql-hll-2.14_old/include/access/xloginsert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xloginsert.h 2020-12-12 17:06:43.069345742 +0800 @@ -0,0 +1,59 @@ +/* --------------------------------------------------------------------------------------- + * + * xloginsert.h + * Functions for generating WAL records + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/xloginsert.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGINSERT_H +#define XLOGINSERT_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/relfilenode.h" + +/* + * The minimum size of the WAL construction working area. If you need to + * register more than XLR_NORMAL_MAX_BLOCK_ID block references or have more + * than XLR_NORMAL_RDATAS data chunks in a single WAL record, you must call + * XLogEnsureRecordSpace() first to allocate more working memory. + */ +#define XLR_NORMAL_MAX_BLOCK_ID 4 +#define XLR_NORMAL_RDATAS 20 + +/* flags for XLogRegisterBuffer */ +#define REGBUF_FORCE_IMAGE 0x01 /* force a full-page image */ +#define REGBUF_NO_IMAGE 0x02 /* don't take a full-page image */ +#define REGBUF_WILL_INIT \ + (0x04 | 0x02) /* page will be re-initialized at \ + * replay (implies NO_IMAGE) */ +#define REGBUF_STANDARD \ + 0x08 /* page follows "standard" page layout, \ + * (data between pd_lower and pd_upper \ + * will be skipped) */ +#define REGBUF_KEEP_DATA \ + 0x10 /* include data even if a full-page image \ + * is taken */ +/* prototypes for public functions in xloginsert.c: */ +extern void XLogBeginInsert(void); +extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, bool isupgrade = false, int bucket_id = InvalidBktId); +extern void XLogEnsureRecordSpace(int nbuffers, int ndatas); +extern void XLogRegisterData(char* data, int len); +extern void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags); +extern void XLogRegisterBlock( + uint8 block_id, RelFileNode* rnode, ForkNumber forknum, BlockNumber blknum, char* page, uint8 flags); +extern void XLogRegisterBufData(uint8 block_id, char* data, int len); +extern void XLogResetInsertion(void); +extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std); +extern void InitXLogInsert(void); +extern void XLogIncludeOrigin(void); + +#endif /* XLOGINSERT_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlog_internal.h postgresql-hll-2.14/include/access/xlog_internal.h --- postgresql-hll-2.14_old/include/access/xlog_internal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlog_internal.h 2020-12-12 17:06:43.070345754 +0800 @@ -0,0 +1,252 @@ +/* + * xlog_internal.h + * + * PostgreSQL transaction log internal declarations + * + * NOTE: this file is intended to contain declarations useful for + * manipulating the XLOG files directly, but it is not supposed to be + * needed by rmgr routines (redo support for individual record types). + * So the XLogRecord typedef and associated stuff appear in xlogrecord.h. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlog_internal.h + */ +#ifndef XLOG_INTERNAL_H +#define XLOG_INTERNAL_H + +#include "access/xlogdefs.h" +#include "access/xlogreader.h" +#include "access/xlog_basic.h" +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "pgtime.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/buf.h" + +/* + * if ValidateXlogRecord Failed in XLOG_FROM_STREAM source, the unexpected + * walreceiver shutdown will be caused. To avoid this, add retry for readrecord in xlog redo + */ +#define XLOG_STREAM_READREC_MAXTRY 10 +#define XLOG_STREAM_READREC_INTERVAL 100 * 1000L + +#ifndef FRONTEND +/* Compute the xlog filename with timelineId and segment number.*/ +#define XLogFileName(fname, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute xlog file path with timelineId and segment number. */ +#define XLogFilePath(path, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) +#else +#define XLogFileName(fname, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss_c(nRet, "\0", "\0"); \ + } while (0) + +#define XLogFilePath(path, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss_c(nRet, "\0", "\0"); \ + } while (0) +#endif + +/* compute the xlog segment number with xlog filename and timelineId. */ +#define XLogFromFileName(fname, tli, logSegNo) \ + do { \ + uint32 log; \ + uint32 seg; \ + int ret; \ + ret = sscanf_s(fname, "%08X%08X%08X", tli, &log, &seg); \ + securec_check_for_sscanf_s(ret, 3, "\0", "\0"); \ + *logSegNo = (uint64)log * XLogSegmentsPerXLogId + seg; \ + } while (0) + +/* compute history filename with timelineID. */ +#define TLHistoryFileName(fname, tli) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(fname, MAXFNAMELEN, MAXFNAMELEN - 1, "%08X.history", tli); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute history filepath with timelineID. */ +#define TLHistoryFilePath(path, tli) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, MAXPGPATH, MAXPGPATH - 1, XLOGDIR "/%08X.history", tli); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute status filePath with xlog name and suffix. */ +#define StatusFilePath(path, xlog, suffix) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, MAXPGPATH, MAXPGPATH - 1, XLOGDIR "/archive_status/%s%s", xlog, suffix); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/*compute backup history filename with timelineID, segment number and offset. */ +#define BackupHistoryFileName(fname, tli, logSegNo, offset) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X.%08X.backup", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId), \ + offset); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/**/ +#define BackupHistoryFilePath(path, tli, logSegNo, offset) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X.%08X.backup", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId), \ + offset); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* + * Information logged when we detect a change in one of the parameters + * important for Hot Standby. + */ +typedef struct xl_parameter_change { + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + int wal_level; +} xl_parameter_change; + +/* logs restore point */ +typedef struct xl_restore_point { + TimestampTz rp_time; + char rp_name[MAXFNAMELEN]; +} xl_restore_point; + +/* + * The functions in xloginsert.c construct a chain of XLogRecData structs + * to represent the final WAL record. + */ +typedef struct XLogRecData { + struct XLogRecData* next; /* next struct in chain, or NULL */ + char* data; /* start of rmgr data to include */ + uint32 len; /* length of rmgr data to include */ + Buffer buffer; /* buffer associated with data, if any */ +} XLogRecData; + +/* + * Method table for resource managers. + * + * This struct must be kept in sync with the PG_RMGR definition in + * rmgr.cpp. + * + * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). + */ +typedef struct RmgrData { + const char* rm_name; + void (*rm_redo)(XLogReaderState* record); + void (*rm_desc)(StringInfo buf, XLogReaderState* record); + void (*rm_startup)(void); + void (*rm_cleanup)(void); + bool (*rm_safe_restartpoint)(void); +} RmgrData; + +/* + * New XLogCtlInsert Structure. + */ +struct Combined128 { + uint64 currentBytePos; + uint32 byteSize; + int32 LRC; +}; +union Union128 { + uint128_u value; + struct Combined128 struct128; +}; + +extern const RmgrData RmgrTable[]; + +/* + * Exported to support xlog switching from checkpointer + */ +extern pg_time_t GetLastSegSwitchTime(void); +extern XLogRecPtr RequestXLogSwitch(void); + +/* + * Exported to support xlog archive status setting from WALReceiver + */ +extern void XLogArchiveForceDone(const char* xlog); + +/* + * These aren't in xlog.h because I'd rather not include fmgr.h there. + */ +extern Datum pg_start_backup(PG_FUNCTION_ARGS); +extern Datum pg_stop_backup(PG_FUNCTION_ARGS); +extern Datum pg_switch_xlog(PG_FUNCTION_ARGS); +extern Datum pg_create_restore_point(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS); +extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS); +extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS); +extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS); + +int XLogPageRead(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, + char* readBuf, TimeLineID* readTLI); +bool XLogReadFromWriteBuffer(XLogRecPtr targetStartPtr, int reqLen, char* readBuf, uint32 *rereadlen); + +#endif /* XLOG_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlogproc.h postgresql-hll-2.14/include/access/xlogproc.h --- postgresql-hll-2.14_old/include/access/xlogproc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlogproc.h 2020-12-12 17:06:43.070345754 +0800 @@ -0,0 +1,920 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * xlogproc.h + * + * + * IDENTIFICATION + * src/include/access/xlogproc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef XLOG_PROC_H +#define XLOG_PROC_H +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xlogreader.h" +#include "storage/bufmgr.h" +#include "access/xlog_basic.h" +#include "access/xlogutils.h" +#include "access/clog.h" + +#ifndef byte +#define byte unsigned char +#endif + +typedef void (*relasexlogreadstate)(void* record); +/* **************define for parse end******************************* */ +#define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a)) + +/* for common blockhead begin */ + +#define XLogBlockHeadGetInfo(blockhead) ((blockhead)->xl_info) +#define XLogBlockHeadGetXid(blockhead) ((blockhead)->xl_xid) +#define XLogBlockHeadGetRmid(blockhead) ((blockhead)->xl_rmid) + +#define XLogBlockHeadGetLSN(blockhead) ((blockhead)->end_ptr) +#define XLogBlockHeadGetRelNode(blockhead) ((blockhead)->relNode) +#define XLogBlockHeadGetSpcNode(blockhead) ((blockhead)->spcNode) +#define XLogBlockHeadGetDbNode(blockhead) ((blockhead)->dbNode) +#define XLogBlockHeadGetForkNum(blockhead) ((blockhead)->forknum) +#define XLogBlockHeadGetBlockNum(blockhead) ((blockhead)->blkno) +#define XLogBlockHeadGetBucketId(blockhead) ((blockhead)->bucketNode) +#define XLogBlockHeadGetValidInfo(blockhead) ((blockhead)->block_valid) + +/* for common blockhead end */ + +/* for block data beging */ +#define XLogBlockDataHasBlockImage(blockdata) ((blockdata)->blockhead.has_image) +#define XLogBlockDataHasBlockData(blockdata) ((blockdata)->blockhead.has_data) +#define XLogBlockDataGetLastBlockLSN(_blockdata) ((_blockdata)->blockdata.last_lsn) +#define XLogBlockDataGetBlockFlags(blockdata) ((blockdata)->blockhead.flags) + +#define XLogBlockDataGetBlockId(blockdata) ((blockdata)->blockhead.cur_block_id) +#define XLogBlockDataGetAuxiBlock1(blockdata) ((blockdata)->blockhead.auxiblk1) +#define XLogBlockDataGetAuxiBlock2(blockdata) ((blockdata)->blockhead.auxiblk2) +/* for block data end */ + +typedef struct { + RelFileNode rnode; + ForkNumber forknum; + BlockNumber blkno; +} RedoBufferTag; + +typedef struct { + Page page; // pagepointer + Size pagesize; +} RedoPageInfo; + +typedef struct { + XLogRecPtr lsn; /* block cur lsn */ + Buffer buf; + RedoBufferTag blockinfo; + RedoPageInfo pageinfo; + int dirtyflag; /* true if the buffer changed */ +} RedoBufferInfo; + +#define MakeRedoBufferDirty(bufferinfo) ((bufferinfo)->dirtyflag = true) +#define RedoBufferDirtyClear(bufferinfo) ((bufferinfo)->dirtyflag = false) +#define IsRedoBufferDirty(bufferinfo) ((bufferinfo)->dirtyflag == true) + +#define RedoMemIsValid(memctl, bufferid) (((bufferid) > InvalidBuffer) && ((bufferid) <= (memctl->totalblknum))) + +typedef struct { + RedoBufferTag blockinfo; + pg_atomic_uint32 state; +} RedoBufferDesc; + +typedef struct { + Buffer buff_id; + pg_atomic_uint32 state; +} ParseBufferDesc; + +#define RedoBufferSlotGetBuffer(bslot) ((bslot)->buf_id) + +#define EnalbeWalLsnCheck true + +#pragma pack(push, 1) + +#define INVALID_BLOCK_ID (XLR_MAX_BLOCK_ID + 2) + +#define LOW_BLOKNUMBER_BITS (32) +#define LOW_BLOKNUMBER_MASK (((uint64)1 << 32) - 1) + + +/* ********BLOCK COMMON HEADER BEGIN ***************** */ +typedef enum { + BLOCK_DATA_MAIN_DATA_TYPE = 0, /* BLOCK DATA */ + BLOCK_DATA_VM_TYPE, /* VM */ + BLOCK_DATA_FSM_TYPE, /* FSM */ + BLOCK_DATA_DDL_TYPE, /* DDL */ + BLOCK_DATA_BCM_TYPE, /* bcm */ + BLOCK_DATA_NEWCU_TYPE, /* cu newlog */ + BLOCK_DATA_CLOG_TYPE, /* CLog */ + BLOCK_DATA_MULITACT_OFF_TYPE, /* MultiXact */ + BLOCK_DATA_MULITACT_MEM_TYPE, + BLOCK_DATA_CSNLOG_TYPE, /* CSNLog */ + /* *****xact don't need sent to dfv */ + BLOCK_DATA_MULITACT_UPDATEOID_TYPE, + BLOCK_DATA_XACTDATA_TYPE, /* XACT */ + BLOCK_DATA_RELMAP_TYPE, /* RELMAP */ + BLOCK_DATA_SLOT_TYPE, + BLOCK_DATA_BARRIER_TYPE, + BLOCK_DATA_PREPARE_TYPE, /* prepare */ + BLOCK_DATA_INVALIDMSG_TYPE, /* INVALIDMSG */ + BLOCK_DATA_INCOMPLETE_TYPE, + BLOCK_DATA_VACUUM_PIN_TYPE, + BLOCK_DATA_XLOG_COMMON_TYPE, + BLOCK_DATA_CREATE_DATABASE_TYPE, + BLOCK_DATA_DROP_DATABASE_TYPE, + BLOCK_DATA_CREATE_TBLSPC_TYPE, + BLOCK_DATA_DROP_TBLSPC_TYPE, + BLOCK_DATA_DROP_SLICE_TYPE, +} XLogBlockParseEnum; + +/* ********BLOCK COMMON HEADER END ***************** */ + +/* **************define for parse begin ******************************* */ + +/* ********BLOCK DATE BEGIN ***************** */ + +typedef struct { + uint8 cur_block_id; /* blockid */ + uint8 flags; + uint8 has_image; + uint8 has_data; + BlockNumber auxiblk1; + BlockNumber auxiblk2; +} XLogBlocDatakHead; + +#define XLOG_BLOCK_DATAHEAD_LEN sizeof(XLogBlocDatakHead) + +typedef struct { + uint16 extra_flag; + uint16 hole_offset; + uint16 hole_length; /* image position */ + uint16 data_len; /* data length */ + XLogRecPtr last_lsn; + char* bkp_image; + char* data; +} XLogBlockData; + +#define XLOG_BLOCK_DATA_LEN sizeof(XLogBlockData) + +typedef struct { + XLogBlocDatakHead blockhead; + XLogBlockData blockdata; + uint32 main_data_len; /* main data portion's length */ + char* main_data; /* point to XLogReaderState's main_data */ +} XLogBlockDataParse; +/* ********BLOCK DATE END ***************** */ +#define XLOG_BLOCK_DATA_PARSE_LEN sizeof(XLogBlockDataParse) + +/* ********BLOCK DDL BEGIN ***************** */ +typedef enum { + BLOCK_DDL_TYPE_NONE = 0, + BLOCK_DDL_CREATE_RELNODE, + BLOCK_DDL_DROP_RELNODE, + BLOCK_DDL_EXTEND_RELNODE, + BLOCK_DDL_TRUNCATE_RELNODE, + BLOCK_DDL_CLOG_ZERO, + BLOCK_DDL_CLOG_TRUNCATE, + BLOCK_DDL_MULTIXACT_OFF_ZERO, + BLOCK_DDL_MULTIXACT_MEM_ZERO +} XLogBlockDdlInfoEnum; + +typedef struct { + uint32 blockddltype; + uint32 columnrel; + Oid ownerid; + char *mainData; +} XLogBlockDdlParse; + +/* ********BLOCK DDL END ***************** */ + +/* ********BLOCK CLOG BEGIN ***************** */ + +#define MAX_BLOCK_XID_NUMS (28) +typedef struct { + TransactionId topxid; + uint16 status; + uint16 xidnum; + uint16 xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockCLogParse; + +/* ********BLOCK CLOG END ***************** */ + +/* ********BLOCK CSNLOG BEGIN ***************** */ +typedef struct { + TransactionId topxid; + CommitSeqNo cslseq; + uint32 xidnum; + uint16 xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockCSNLogParse; + +/* ********BLOCK CSNLOG END ***************** */ + +/* ********BLOCK prepare BEGIN ***************** */ +struct TwoPhaseFileHeader; + +typedef struct { + TransactionId maxxid; + Size maindatalen; + char* maindata; +} XLogBlockPrepareParse; + +/* ********BLOCK prepare END ***************** */ + +/* ********BLOCK Bcm BEGIN ***************** */ +typedef struct { + uint64 startblock; + int count; + int status; +} XLogBlockBcmParse; + +/* ********BLOCK Bcm END ***************** */ + +/* ********BLOCK Vm BEGIN ***************** */ +typedef struct { + BlockNumber heapBlk; +} XLogBlockVmParse; + +#define XLOG_BLOCK_VM_PARSE_LEN sizeof(XLogBlockVmParse) +/* ********BLOCK Vm END ***************** */ + +/* ********BLOCK NewCu BEGIN ***************** */ +typedef struct { + uint32 main_data_len; /* main data portion's length */ + char* main_data; /* point to XLogReaderState's main_data */ +} XLogBlockNewCuParse; + + +/* ********BLOCK NewCu END ***************** */ + +/* ********BLOCK InvalidMsg BEGIN ***************** */ +typedef struct { + TransactionId cutoffxid; +} XLogBlockInvalidParse; + +/* ********BLOCK InvalidMsg END ***************** */ + +/* ********BLOCK Incomplete BEGIN ***************** */ + +typedef enum { + INCOMPLETE_ACTION_LOG = 0, + INCOMPLETE_ACTION_FORGET +} XLogBlockIncompleteEnum; + +typedef struct { + uint16 action; /* split or delete */ + bool issplit; + bool isroot; + BlockNumber downblk; + BlockNumber leftblk; + BlockNumber rightblk; +} XLogBlockIncompleteParse; + +/* ********BLOCK Incomplete END ***************** */ + +/* ********BLOCK VacuumPin BEGIN ***************** */ +typedef struct { + BlockNumber lastBlockVacuumed; +} XLogBlockVacuumPinParse; + +/* ********BLOCK XLOG Common BEGIN ***************** */ +typedef struct { + XLogRecPtr readrecptr; + Size maindatalen; + char* maindata; +} XLogBlockXLogComParse; + +/* ********BLOCK XLOG Common END ***************** */ + +/* ********BLOCK DataBase BEGIN ***************** */ +typedef struct { + Oid src_db_id; + Oid src_tablespace_id; +} XLogBlockDataBaseParse; + +/* ********BLOCK DataBase Common END ***************** */ + +/* ********BLOCK table spc BEGIN ***************** */ +typedef struct { + char* tblPath; + bool isRelativePath; +} XLogBlockTblSpcParse; + +/* ********BLOCK table spc END ***************** */ + +/* ********BLOCK Multi Xact Offset BEGIN ***************** */ +typedef struct { + MultiXactId multi; + MultiXactOffset moffset; +} XLogBlockMultiXactOffParse; + +/* ********BLOCK Multi Xact Offset END ***************** */ + +/* ********BLOCK Multi Xact Mem BEGIN ***************** */ +typedef struct { + MultiXactId multi; + MultiXactOffset startoffset; + uint64 xidnum; + TransactionId xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockMultiXactMemParse; +/* ********BLOCK Multi Xact Mem END ***************** */ + +/* ********BLOCK Multi Xact update oid BEGIN ***************** */ +typedef struct { + MultiXactId nextmulti; + MultiXactOffset nextoffset; + TransactionId maxxid; +} XLogBlockMultiUpdateParse; +/* ********BLOCK Multi Xact update oid END ***************** */ + +/* ********BLOCK rel map BEGIN ***************** */ +typedef struct { + Size maindatalen; + char* maindata; +} XLogBlockRelMapParse; +/* ********BLOCK rel map END ***************** */ + +typedef struct { + uint32 xl_term; +} XLogBlockRedoHead; + +#define XLogRecRedoHeadEncodeSize (offsetof(XLogBlockRedoHead, refrecord)) +typedef struct { + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; /* copy from XLogReaderState's EndRecPtr */ + BlockNumber blkno; + Oid relNode; /* relation */ + uint16 block_valid; /* block data validinfo see XLogBlockInfoEnum */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + ForkNumber forknum; + TransactionId xl_xid; /* xact id */ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + int4 bucketNode; /* bucket */ +} XLogBlockHead; + +#define XLogBlockHeadEncodeSize (sizeof(XLogBlockHead)) + +#define BYTE_NUM_BITS (8) +#define BYTE_MASK (0xFF) +#define U64_BYTES_NUM (8) +#define U32_BYTES_NUM (4) +#define U16_BYTES_NUM (2) +#define U8_BYTES_NUM (1) + +#define U32_BITS_NUM (BYTE_NUM_BITS * U32_BYTES_NUM) + +extern uint64 XLog_Read_N_Bytes(char* buffer, Size buffersize, Size readbytes); + +#define XLog_Read_1_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U8_BYTES_NUM) +#define XLog_Read_2_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U16_BYTES_NUM) +#define XLog_Read_4_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U32_BYTES_NUM) +#define XLog_Read_8_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U64_BYTES_NUM) + +extern bool XLog_Write_N_bytes(uint64 values, Size writebytes, byte* buffer); + +#define XLog_Write_1_Bytes(values, buffer) XLog_Write_N_bytes(values, U8_BYTES_NUM, buffer) +#define XLog_Write_2_Bytes(values, buffer) XLog_Write_N_bytes(values, U16_BYTES_NUM, buffer) +#define XLog_Write_4_Bytes(values, buffer) XLog_Write_N_bytes(values, U32_BYTES_NUM, buffer) +#define XLog_Write_8_Bytes(values, buffer) XLog_Write_N_bytes(values, U64_BYTES_NUM, buffer) + +typedef struct XLogBlockEnCode { + bool (*xlog_encodefun)(byte* buffer, Size buffersize, Size* encodesize, void* xlogbody); + uint16 block_valid; +} XLogBlockEnCode; + +typedef struct XLogBlockRedoCode { + void (*xlog_redofun)(char* buffer, Size buffersize, XLogBlockHead* blockhead, XLogBlockRedoHead* redohead, + void* page, Size pagesize); + uint16 block_valid; +} XLogBlockRedoCode; + +#pragma pack(pop) + +/* ********BLOCK Xact BEGIN ***************** */ +typedef struct { + uint8 delayddlflag; + uint8 updateminrecovery; + uint16 committype; + int invalidmsgnum; + int nrels; /* delete rels */ + int nlibs; /* delete libs */ + uint64 xinfo; + TimestampTz xact_time; + TransactionId maxxid; + CommitSeqNo maxcommitseq; + void* invalidmsg; + void* xnodes; + void* libfilename; +} XLogBlockXactParse; + +typedef struct { + Size maindatalen; + char* maindata; +} XLogBlockSlotParse; +/* ********BLOCK slot END ***************** */ + +/* ********BLOCK barrier BEGIN ***************** */ +typedef struct { + XLogRecPtr startptr; + XLogRecPtr endptr; +} XLogBlockBarrierParse; + +/* ********BLOCK Xact END ***************** */ + +/* ********BLOCK VacuumPin END ***************** */ +typedef struct { + XLogBlockHead blockhead; + XLogBlockRedoHead redohead; + union { + XLogBlockDataParse blockdatarec; + XLogBlockVmParse blockvmrec; + XLogBlockDdlParse blockddlrec; + XLogBlockBcmParse blockbcmrec; + XLogBlockNewCuParse blocknewcu; + XLogBlockCLogParse blockclogrec; + XLogBlockCSNLogParse blockcsnlogrec; + XLogBlockXactParse blockxact; + XLogBlockPrepareParse blockprepare; + XLogBlockInvalidParse blockinvalidmsg; + // XLogBlockIncompleteParse blockincomplete; + XLogBlockVacuumPinParse blockvacuumpin; + XLogBlockXLogComParse blockxlogcommon; + XLogBlockDataBaseParse blockdatabase; + XLogBlockTblSpcParse blocktblspc; + XLogBlockMultiXactOffParse blockmultixactoff; + XLogBlockMultiXactMemParse blockmultixactmem; + XLogBlockMultiUpdateParse blockmultiupdate; + XLogBlockRelMapParse blockrelmap; + XLogBlockSlotParse blockslot; + XLogBlockBarrierParse blockbarrier; + } extra_rec; +} XLogBlockParse; + + +typedef struct +{ + Buffer buf_id; + Buffer freeNext; +} RedoMemSlot; + +typedef void (*InterruptFunc)(); + +typedef struct +{ + int totalblknum; /* total slot */ + int usedblknum; /* used slot */ + Size itemsize; + Buffer firstfreeslot; /* first free slot */ + Buffer firstreleaseslot; /* first release slot */ + RedoMemSlot *memslot; /* slot itme */ + bool isInit; + InterruptFunc doInterrupt; +}RedoMemManager; + +typedef void (*RefOperateFunc)(void *record); +#ifdef USE_ASSERT_CHECKING +typedef void (*RecordCheckFunc)(void *record, XLogRecPtr curPageLsn, uint32 blockId, bool replayed); +#endif + +typedef struct { + RefOperateFunc refCount; + RefOperateFunc DerefCount; +#ifdef USE_ASSERT_CHECKING + RecordCheckFunc checkFunc; +#endif +}RefOperate; + +typedef struct +{ + void *BufferBlockPointers; /* RedoBufferDesc + block */ + RedoMemManager memctl; + RefOperate *refOperate; +}RedoBufferManager; + + + +typedef struct +{ + void *parsebuffers; /* ParseBufferDesc + XLogRecParseState */ + RedoMemManager memctl; + RefOperate *refOperate; +}RedoParseManager; + + + +typedef struct { + void* nextrecord; + XLogBlockParse blockparse; /* block data */ + RedoParseManager* manager; + void* refrecord; /* origin dataptr, for mem release */ + uint64 batchcount; + bool isFullSyncCheckpoint; +} XLogRecParseState; + +typedef struct XLogBlockRedoExtreRto { + void (*xlog_redoextrto)(XLogBlockHead* blockhead, void* blockrecbody, RedoBufferInfo* bufferinfo); + uint16 block_valid; +} XLogBlockRedoExtreRto; + +typedef struct XLogParseBlock { + XLogRecParseState* (*xlog_parseblock)(XLogReaderState* record, uint32* blocknum); + RmgrId rmid; +} XLogParseBlock; + +typedef enum { + HEAP_INSERT_ORIG_BLOCK_NUM = 0 +} XLogHeapInsertBlockEnum; + +typedef enum { + HEAP_DELETE_ORIG_BLOCK_NUM = 0 +} XLogHeapDeleteBlockEnum; + +typedef enum { + HEAP_UPDATE_NEW_BLOCK_NUM = 0, + HEAP_UPDATE_OLD_BLOCK_NUM +} XLogHeapUpdateBlockEnum; + +typedef enum { + HEAP_BASESHIFT_ORIG_BLOCK_NUM = 0 +} XLogHeapBaeShiftBlockEnum; + +typedef enum { + HEAP_NEWPAGE_ORIG_BLOCK_NUM = 0 +} XLogHeapNewPageBlockEnum; + +typedef enum { + HEAP_LOCK_ORIG_BLOCK_NUM = 0 +} XLogHeapLockBlockEnum; + +typedef enum { + HEAP_INPLACE_ORIG_BLOCK_NUM = 0 +} XLogHeapInplaceBlockEnum; + +typedef enum { + HEAP_FREEZE_ORIG_BLOCK_NUM = 0 +} XLogHeapFreezeBlockEnum; + +typedef enum { + HEAP_CLEAN_ORIG_BLOCK_NUM = 0 +} XLogHeapCleanBlockEnum; + +typedef enum { + HEAP_VISIBLE_VM_BLOCK_NUM = 0, + HEAP_VISIBLE_DATA_BLOCK_NUM +} XLogHeapVisibleBlockEnum; + +typedef enum { + HEAP_MULTI_INSERT_ORIG_BLOCK_NUM = 0 +} XLogHeapMultiInsertBlockEnum; + +typedef enum { + HEAP_PAGE_UPDATE_ORIG_BLOCK_NUM = 0 +} XLogHeapPageUpdateBlockEnum; + +extern THR_LOCAL RedoParseManager* g_parseManager; +extern THR_LOCAL RedoBufferManager* g_bufferManager; + +extern void* XLogMemCtlInit(RedoMemManager* memctl, Size itemsize, int itemnum); +extern RedoMemSlot* XLogMemAlloc(RedoMemManager* memctl); +extern void XLogMemRelease(RedoMemManager* memctl, Buffer bufferid); + +extern void XLogRedoBufferInit(RedoBufferManager* buffermanager, int buffernum, RefOperate *refOperate, + InterruptFunc interruptOperte); +extern void XLogRedoBufferDestory(RedoBufferManager* buffermanager); +extern RedoMemSlot* XLogRedoBufferAlloc( + RedoBufferManager* buffermanager, RelFileNode relnode, ForkNumber forkNum, BlockNumber blockNum); +extern bool XLogRedoBufferIsValid(RedoBufferManager* buffermanager, Buffer bufferid); +extern void XLogRedoBufferRelease(RedoBufferManager* buffermanager, Buffer bufferid); +extern BlockNumber XLogRedoBufferGetBlkNumber(RedoBufferManager* buffermanager, Buffer bufferid); +extern Block XLogRedoBufferGetBlk(RedoBufferManager* buffermanager, RedoMemSlot* bufferslot); +extern Block XLogRedoBufferGetPage(RedoBufferManager* buffermanager, Buffer bufferid); +extern void XLogRedoBufferSetState(RedoBufferManager* buffermanager, RedoMemSlot* bufferslot, uint32 state); + +#define XLogRedoBufferInitFunc(bufferManager, buffernum, defOperate, interruptOperte) do { \ + XLogRedoBufferInit(bufferManager, buffernum, defOperate, interruptOperte); \ +} while (0) +#define XLogRedoBufferDestoryFunc(bufferManager) do { \ + XLogRedoBufferDestory(bufferManager); \ +} while (0) +#define XLogRedoBufferAllocFunc(relnode, forkNum, blockNum, bufferslot) do { \ + *bufferslot = XLogRedoBufferAlloc(g_bufferManager, relnode, forkNum, blockNum); \ +} while (0) +#define XLogRedoBufferIsValidFunc(bufferid, isvalid) do { \ + *isvalid = XLogRedoBufferIsValid(g_bufferManager, bufferid); \ +} while (0) +#define XLogRedoBufferReleaseFunc(bufferid) do { \ + XLogRedoBufferRelease(g_bufferManager, bufferid); \ +} while (0) + +#define XLogRedoBufferGetBlkNumberFunc(bufferid, blknumber) do { \ + *blknumber = XLogRedoBufferGetBlkNumber(g_bufferManager, bufferid); \ +} while (0) + +#define XLogRedoBufferGetBlkFunc(bufferslot, blockdata) do { \ + *blockdata = XLogRedoBufferGetBlk(g_bufferManager, bufferslot); \ +} while (0) + +#define XLogRedoBufferGetPageFunc(bufferid, blockdata) do { \ + *blockdata = (Page)XLogRedoBufferGetPage(g_bufferManager, bufferid); \ +} while (0) +#define XLogRedoBufferSetStateFunc(bufferslot, state) do { \ + XLogRedoBufferSetState(g_bufferManager, bufferslot, state); \ +} while (0) + +extern void XLogParseBufferInit(RedoParseManager* parsemanager, int buffernum, RefOperate *refOperate, + InterruptFunc interruptOperte); +extern void XLogParseBufferDestory(RedoParseManager* parsemanager); +extern void XLogParseBufferRelease(XLogRecParseState* recordstate); +extern XLogRecParseState* XLogParseBufferAllocList(RedoParseManager* parsemanager, XLogRecParseState* blkstatehead, void *record); +extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState* record, uint8 buffer_id, RedoBufferInfo* bufferinfo); +extern void XLogInitBufferForRedo(XLogReaderState* record, uint8 block_id, RedoBufferInfo* bufferinfo); +extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState* record, uint8 buffer_id, ReadBufferMode mode, + bool get_cleanup_lock, RedoBufferInfo* bufferinfo, ReadBufferMethod readmethod = WITH_NORMAL_CACHE); + +#define XLogParseBufferInitFunc(parseManager, buffernum, defOperate, interruptOperte) do { \ + XLogParseBufferInit(parseManager, buffernum, defOperate, interruptOperte); \ +} while (0) + +#define XLogParseBufferDestoryFunc(parseManager) do { \ + XLogParseBufferDestory(parseManager); \ +} while (0) + +#define XLogParseBufferReleaseFunc(recordstate) do { \ + XLogParseBufferRelease(recordstate); \ +} while (0) + +#define XLogParseBufferAllocListFunc(record, newblkstate, blkstatehead) do { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, blkstatehead, record); \ +} while (0) + +#define XLogParseBufferAllocListStateFunc(record, newblkstate, blkstatehead) do { \ + if (*blkstatehead == NULL) { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, NULL, record); \ + *blkstatehead = *newblkstate; \ + } else { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, *blkstatehead, record); \ + } \ +} while (0) + + + + +#ifdef EXTREME_RTO_DEBUG_AB +typedef void (*AbnormalProcFunc)(void); +typedef enum { + A_THREAD_EXIT, + ALLOC_FAIL, + OPEN_FILE_FAIL, + WAIT_LONG, + ABNORMAL_NUM, +}AbnormalType; +extern AbnormalProcFunc g_AbFunList[ABNORMAL_NUM]; + + +#define ADD_ABNORMAL_POSITION(pos) do { \ + static int __count##pos = 0; \ + __count##pos++; \ + if (g_instance.attr.attr_storage.extreme_rto_ab_pos == pos) { \ + if (g_instance.attr.attr_storage.extreme_rto_ab_count == __count##pos) { \ + ereport(LOG, (errmsg("extreme rto debug abnormal stop pos:%d, type:%d, count:%d", pos, \ + g_instance.attr.attr_storage.extreme_rto_ab_type, __count##pos))); \ + g_AbFunList[g_instance.attr.attr_storage.extreme_rto_ab_type % ABNORMAL_NUM](); \ + } \ + } \ +} while(0) +#else +#define ADD_ABNORMAL_POSITION(pos) +#endif + + + +void HeapXlogCleanOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen, Size* freespace, bool repairFragmentation); +void HeapXlogFreezeOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen); +void HeapXlogVisibleOperatorPage(RedoBufferInfo* buffer, void* recorddata); +void HeapXlogVisibleOperatorVmpage(RedoBufferInfo* vmbuffer, void* recorddata); +void HeapXlogDeleteOperatorPage(RedoBufferInfo* buffer, void* recorddata, TransactionId recordxid); +void HeapXlogInsertOperatorPage(RedoBufferInfo* buffer, void* recorddata, bool isinit, void* blkdata, Size datalen, + TransactionId recxid, Size* freespace); +void HeapXlogMultiInsertOperatorPage(RedoBufferInfo* buffer, void* recoreddata, bool isinit, void* blkdata, + Size len, TransactionId recordxid, Size* freespace); +void HeapXlogUpdateOperatorOldpage(RedoBufferInfo* buffer, void* recoreddata, bool hot_update, bool isnewinit, + BlockNumber newblk, TransactionId recordxid); +void HeapXlogUpdateOperatorNewpage(RedoBufferInfo* buffer, void* recorddata, bool isinit, void* blkdata, + Size datalen, TransactionId recordxid, Size* freespace); +void HeapXlogPageUpgradeOperatorPage(RedoBufferInfo* buffer); +void HeapXlogLockOperatorPage(RedoBufferInfo* buffer, void* recorddata); +void HeapXlogInplaceOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size newlen); +void HeapXlogBaseShiftOperatorPage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeRestoreMetaOperatorPage(RedoBufferInfo* metabuf, void* recorddata, Size datalen); +void BtreeXlogInsertOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* data, Size datalen); +void BtreeXlogSplitOperatorRightpage( + RedoBufferInfo* rbuf, void* recorddata, BlockNumber leftsib, BlockNumber rnext, void* blkdata, Size datalen); +void BtreeXlogSplitOperatorNextpage(RedoBufferInfo* buffer, BlockNumber rightsib); +void BtreeXlogSplitOperatorLeftpage( + RedoBufferInfo* lbuf, void* recorddata, BlockNumber rightsib, bool onleft, void* blkdata, Size datalen); +void BtreeXlogVacuumOperatorPage(RedoBufferInfo* redobuffer, void* recorddata, void* blkdata, Size len); +void BtreeXlogDeleteOperatorPage(RedoBufferInfo* buffer, void* recorddata, Size recorddatalen); +void btreeXlogDeletePageOperatorRightpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogDeletePageOperatorLeftpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogDeletePageOperatorCurrentpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogNewrootOperatorPage(RedoBufferInfo* buffer, void* record, void* blkdata, Size len, BlockNumber* downlink); +void BtreeXlogHalfdeadPageOperatorParentpage( + RedoBufferInfo* pbuf, void* recorddata); +void BtreeXlogHalfdeadPageOperatorLeafpage( + RedoBufferInfo* lbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorRightpage(RedoBufferInfo* rbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorLeftpage(RedoBufferInfo* lbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorCurpage(RedoBufferInfo* buf, void* recorddata); +void BtreeXlogUnlinkPageOperatorChildpage(RedoBufferInfo* cbuf, void* recorddata); + +void BtreeXlogClearIncompleteSplit(RedoBufferInfo* buffer); + +void XLogRecSetBlockCommonState(XLogReaderState* record, XLogBlockParseEnum blockvalid, ForkNumber forknum, + BlockNumber blockknum, RelFileNode* relnode, XLogRecParseState* recordblockstate); + +void XLogRecSetBlockCLogState( + XLogBlockCLogParse* blockclogstate, TransactionId topxid, uint16 status, uint16 xidnum, uint16* xidsarry); + +void XLogRecSetBlockCSNLogState( + XLogBlockCSNLogParse* blockcsnlogstate, TransactionId topxid, CommitSeqNo csnseq, uint16 xidnum, uint16* xidsarry); +void XLogRecSetXactRecoveryState(XLogBlockXactParse* blockxactstate, TransactionId maxxid, CommitSeqNo maxcsnseq, + uint8 delayddlflag, uint8 updateminrecovery); +void XLogRecSetXactDdlState(XLogBlockXactParse* blockxactstate, int nrels, void* xnodes, int invalidmsgnum, + void* invalidmsg, int nlibs, void* libfilename); +void XLogRecSetXactCommonState( + XLogBlockXactParse* blockxactstate, uint16 committype, uint64 xinfo, TimestampTz xact_time); +void XLogRecSetBcmState(XLogBlockBcmParse* blockbcmrec, uint64 startblock, int count, int status); +void XLogRecSetNewCuState(XLogBlockNewCuParse* blockcudata, char* main_data, uint32 main_data_len); +void XLogRecSetInvalidMsgState(XLogBlockInvalidParse* blockinvalid, TransactionId cutoffxid); +void XLogRecSetIncompleteMsgState(XLogBlockIncompleteParse* blockincomplete, uint16 action, bool issplit, bool isroot, + BlockNumber downblk, BlockNumber leftblk, BlockNumber rightblk); +void XLogRecSetPinVacuumState(XLogBlockVacuumPinParse* blockvacuum, BlockNumber lastblknum); + +void XLogRecSetAuxiBlkNumState(XLogBlockDataParse* blockdatarec, BlockNumber auxilaryblkn1, BlockNumber auxilaryblkn2); +void XLogRecSetBlockDataState(XLogReaderState* record, uint32 blockid, XLogRecParseState* recordblockstate); +extern char* XLogBlockDataGetBlockData(XLogBlockDataParse* datadecode, Size* len); +void Heap2RedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void HeapRedoDataBlock( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void xlog_redo_data_block( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void XLogRecSetBlockDdlState(XLogBlockDdlParse* blockddlstate, uint32 blockddltype, uint32 columnrel, + char *mainData, Oid ownerid = InvalidOid); +XLogRedoAction XLogCheckBlockDataRedoAction(XLogBlockDataParse* datadecode, RedoBufferInfo* bufferinfo); +void BtreeRedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +XLogRecParseState* XactXlogCsnlogParseToBlock(XLogReaderState* record, uint32* blocknum, TransactionId xid, + int nsubxids, TransactionId* subxids, CommitSeqNo csn, XLogRecParseState* recordstatehead); +extern void XLogRecSetVmBlockState(XLogReaderState* record, uint32 blockid, XLogRecParseState* recordblockstate); +extern void DoLsnCheck(RedoBufferInfo* bufferinfo, bool willInit, XLogRecPtr lastLsn); +char* XLogBlockDataGetMainData(XLogBlockDataParse* datadecode, Size* len); +void HeapRedoVmBlock(XLogBlockHead* blockhead, XLogBlockVmParse* blockvmrec, RedoBufferInfo* bufferinfo); +void Heap2RedoVmBlock(XLogBlockHead* blockhead, XLogBlockVmParse* blockvmrec, RedoBufferInfo* bufferinfo); +XLogRecParseState* xlog_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* smgr_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* XactXlogClogParseToBlock(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status); +XLogRecParseState* xact_xlog_commit_parse_to_block(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId maxxid, CommitSeqNo maxseqnum); +void visibilitymap_clear_buffer(RedoBufferInfo* bufferinfo, BlockNumber heapBlk); +XLogRecParseState* xact_xlog_abort_parse_to_block(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId maxxid, CommitSeqNo maxseqnum); +XLogRecParseState* xact_xlog_prepare_parse_to_block( + XLogReaderState* record, XLogRecParseState* recordstatehead, uint32* blocknum, TransactionId maxxid); +XLogRecParseState* xact_xlog_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* ClogRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +XLogRecParseState* DbaseRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +XLogRecParseState* Heap2RedoParseIoBlock(XLogReaderState* record, uint32* blocknum); + +extern XLogRecParseState* HeapRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* BtreeRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* Heap3RedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern Size SalEncodeXLogBlock(void* recordblockstate, byte* buffer, void* sliceinfo); + +extern XLogRecParseState* XLogParseToBlockForDfv(XLogReaderState* record, uint32* blocknum); +extern Size getBlockSize(XLogRecParseState* recordblockstate); +extern XLogRecParseState* GistRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* GinRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern void GistRedoClearFollowRightOperatorPage(RedoBufferInfo* buffer); +extern void GistRedoPageUpdateOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen); +extern void GistRedoPageSplitOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* data, Size datalen, bool Markflag, BlockNumber rightlink); +extern void GistRedoCreateIndexOperatorPage(RedoBufferInfo* buffer); + +extern void GinRedoCreateIndexOperatorMetaPage(RedoBufferInfo* MetaBuffer); +extern void GinRedoCreateIndexOperatorRootPage(RedoBufferInfo* RootBuffer); +extern void GinRedoCreatePTreeOperatorPage(RedoBufferInfo* buffer, void* recordData); +extern void GinRedoClearIncompleteSplitOperatorPage(RedoBufferInfo* buffer); +extern void GinRedoVacuumDataOperatorLeafPage(RedoBufferInfo* buffer, void* recorddata); +extern void GinRedoDeletePageOperatorCurPage(RedoBufferInfo* dbuffer); +extern void GinRedoDeletePageOperatorParentPage(RedoBufferInfo* pbuffer, void* recorddata); +extern void GinRedoDeletePageOperatorLeftPage(RedoBufferInfo* lbuffer, void* recorddata); +extern void GinRedoUpdateOperatorMetapage(RedoBufferInfo* metabuffer, void* recorddata); +extern void GinRedoUpdateOperatorTailPage(RedoBufferInfo* buffer, void* payload, Size totaltupsize, int32 ntuples); +extern void GinRedoInsertListPageOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* payload, Size totaltupsize); +extern void GinRedoUpdateAddNewTail(RedoBufferInfo* buffer, BlockNumber newRightlink); +extern void GinRedoInsertData(RedoBufferInfo* buffer, bool isLeaf, BlockNumber rightblkno, void* rdata); +extern void GinRedoInsertEntry(RedoBufferInfo* buffer, bool isLeaf, BlockNumber rightblkno, void* rdata); + +extern void GinRedoDeleteListPagesOperatorPage(RedoBufferInfo* metabuffer, const void* recorddata); +extern void GinRedoDeleteListPagesMarkDelete(RedoBufferInfo* buffer); + +extern void spgRedoCreateIndexOperatorMetaPage(RedoBufferInfo* buffer); +extern void spgRedoCreateIndexOperatorRootPage(RedoBufferInfo* buffer); +extern void spgRedoCreateIndexOperatorLeafPage(RedoBufferInfo* buffer); +extern void spgRedoAddLeafOperatorPage(RedoBufferInfo* bufferinfo, void* recorddata); +extern void spgRedoAddLeafOperatorParent(RedoBufferInfo* bufferinfo, void* recorddata, BlockNumber blknoLeaf); +extern void spgRedoMoveLeafsOpratorDstPage(RedoBufferInfo* buffer, void* recorddata, void* insertdata, void* tupledata); +extern void spgRedoMoveLeafsOpratorSrcPage( + RedoBufferInfo* buffer, void* recorddata, void* insertdata, void* deletedata, BlockNumber blknoDst, int nInsert); +extern void spgRedoMoveLeafsOpratorParentPage( + RedoBufferInfo* buffer, void* recorddata, void* insertdata, BlockNumber blknoDst, int nInsert); +extern void spgRedoAddNodeUpdateSrcPage(RedoBufferInfo* buffer, void* recorddata, void* tuple, void* tupleheader); +extern void spgRedoAddNodeOperatorSrcPage(RedoBufferInfo* buffer, void* recorddata, BlockNumber blknoNew); +extern void spgRedoAddNodeOperatorDestPage( + RedoBufferInfo* buffer, void* recorddata, void* tuple, void* tupleheader, BlockNumber blknoNew); +extern void spgRedoAddNodeOperatorParentPage(RedoBufferInfo* buffer, void* recorddata, BlockNumber blknoNew); +extern void spgRedoSplitTupleOperatorDestPage(RedoBufferInfo* buffer, void* recorddata, void* tuple); +extern void spgRedoSplitTupleOperatorSrcPage(RedoBufferInfo* buffer, void* recorddata, void* pretuple, void* posttuple); +extern void spgRedoPickSplitRestoreLeafTuples( + RedoBufferInfo* buffer, void* recorddata, bool destflag, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorSrcPage(RedoBufferInfo* srcBuffer, void* recorddata, void* deleteoffset, + BlockNumber blknoInner, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorDestPage( + RedoBufferInfo* destBuffer, void* recorddata, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorInnerPage( + RedoBufferInfo* innerBuffer, void* recorddata, void* tuple, void* tupleheader, BlockNumber blknoInner); +extern void spgRedoPickSplitOperatorParentPage(RedoBufferInfo* parentBuffer, void* recorddata, BlockNumber blknoInner); +extern void spgRedoVacuumLeafOperatorPage(RedoBufferInfo* buffer, void* recorddata); +extern void spgRedoVacuumRootOperatorPage(RedoBufferInfo* buffer, void* recorddata); +extern void spgRedoVacuumRedirectOperatorPage(RedoBufferInfo* buffer, void* recorddata); + +extern XLogRecParseState* SpgRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern void seqRedoOperatorPage(RedoBufferInfo* buffer, void* itmedata, Size itemsz); +extern void seq_redo_data_block(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); + +extern void Heap3RedoDataBlock( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); + +extern XLogRecParseState* xact_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); + +extern bool XLogBlockRedoForExtremeRTO(XLogRecParseState* redoblocktate, RedoBufferInfo *bufferinfo, + bool notfound); +void XLogBlockParseStateRelease_debug(XLogRecParseState* recordstate, const char *func, uint32 line); +#define XLogBlockParseStateRelease(recordstate) XLogBlockParseStateRelease_debug(recordstate, __FUNCTION__, __LINE__) +#ifdef USE_ASSERT_CHECKING +extern void DoRecordCheck(XLogRecParseState *recordstate, XLogRecPtr pageLsn, bool replayed); +#endif +extern XLogRecParseState* XLogParseBufferCopy(XLogRecParseState *srcState); +extern XLogRecParseState* XLogParseToBlockForExtermeRTO(XLogReaderState* record, uint32* blocknum); +extern XLogRedoAction XLogReadBufferForRedoBlockExtend(RedoBufferTag* redoblock, ReadBufferMode mode, bool get_cleanup_lock, + RedoBufferInfo* redobufferinfo, XLogRecPtr xloglsn, ReadBufferMethod readmethod); +extern XLogRecParseState* tblspc_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* relmap_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* HashRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* seq_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* slot_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +#ifdef ENABLE_MULTIPLE_NODES +extern XLogRecParseState* barrier_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +#endif +extern XLogRecParseState* multixact_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern void ExtremeRtoFlushBuffer(RedoBufferInfo *bufferinfo, bool updateFsm); +extern void XLogForgetDDLRedo(XLogRecParseState* redoblockstate); +extern void SyncOneBufferForExtremRto(RedoBufferInfo *bufferinfo); +extern void XLogBlockInitRedoBlockInfo(XLogBlockHead* blockhead, RedoBufferTag* blockinfo); +extern void XLogBlockDdlDoSmgrAction(XLogBlockHead* blockhead, void* blockrecbody, RedoBufferInfo* bufferinfo); +extern void GinRedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void GistRedoDataBlock(XLogBlockHead *blockhead, XLogBlockDataParse *blockdatarec, RedoBufferInfo *bufferinfo); +extern bool IsCheckPoint(const XLogRecParseState *parseState); + +#endif diff -uprN postgresql-hll-2.14_old/include/access/xlogreader.h postgresql-hll-2.14/include/access/xlogreader.h --- postgresql-hll-2.14_old/include/access/xlogreader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlogreader.h 2020-12-12 17:06:43.070345754 +0800 @@ -0,0 +1,99 @@ +/* --------------------------------------------------------------------------------------- + * + * xlogreader.h + * Definitions for the generic XLog reading facility + * Portions Copyright (c) 2013-2015, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/access/xlogreader.h + * + * NOTES + * See the definition of the XLogReaderState struct for instructions on + * how to use the XLogReader infrastructure. + * + * The basic idea is to allocate an XLogReaderState via + * XLogReaderAllocate(), and call XLogReadRecord() until it returns NULL. + * + * After reading a record with XLogReadRecord(), it's decomposed into + * the per-block and main data parts, and the parts can be accessed + * with the XLogRec* macros and functions. You can also decode a + * record that's already constructed in memory, without reading from + * disk, by calling the DecodeXLogRecord() function. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGREADER_H +#define XLOGREADER_H + +#include "access/xlogrecord.h" +#include "securec_check.h" +#include "access/xlog_basic.h" + +#define offsetof_twoversion(type, typeold, field) (offsetof(type, field) - offsetof(typeold, field)) +#define XLOG_READER_MAX_MSGLENTH 1024 + +/* Get a new XLogReader */ +extern XLogReaderState* XLogReaderAllocate(XLogPageReadCB pagereadfunc, void* private_data); + +/* Free an XLogReader */ +extern void XLogReaderFree(XLogReaderState* state); +/* The function has the stronger ability to find the next xlog record with XLogReadRecord() deployed. */ +extern bool ValidateNextXLogRecordPtr(XLogReaderState* state, XLogRecPtr& cur_ptr, char** err_msg); +/* Adjust the start ptr of XlogRecoed for XlogReadRecord */ +extern void AlignXlogPtrToNextPageIfNeeded(XLogRecPtr* recPtr); +/* Read the next XLog record. Returns NULL on end-of-WAL or failure */ +extern struct XLogRecord* XLogReadRecord( + XLogReaderState* state, XLogRecPtr recptr, char** errormsg, bool readoldversion = false, bool doDecode = true); + +extern bool XLogRecGetBlockTag( + XLogReaderState* record, uint8 block_id, RelFileNode* rnode, ForkNumber* forknum, BlockNumber* blknum); +extern bool XLogRecGetBlockLastLsn(XLogReaderState* record, uint8 block_id, XLogRecPtr* lsn); +extern char* XLogRecGetBlockImage(XLogReaderState* record, uint8 block_id, uint16* hole_offset, uint16* hole_length); + +/* Invalidate read state */ +extern void XLogReaderInvalReadState(XLogReaderState* state); + +extern XLogRecPtr XLogFindNextRecord(XLogReaderState* state, XLogRecPtr RecPtr); +extern XLogRecPtr FindMaxLSN(char* workingpath, char* returnmsg, int msg_len, pg_crc32* maxLsnCrc); +extern void CloseXlogFile(void); +extern int SimpleXLogPageRead(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* readBuf, TimeLineID* pageTLI); +extern void CloseXlogFile(void); + +/* Functions for decoding an XLogRecord */ +extern bool DecodeXLogRecord(XLogReaderState* state, XLogRecord* record, char** errmsg, bool readoldversion); + +#define XLogRecGetTotalLen(decoder) ((decoder)->decoded_record->xl_tot_len) +#define XLogRecGetPrev(decoder) ((decoder)->decoded_record->xl_prev) +#define XLogRecGetInfo(decoder) ((decoder)->decoded_record->xl_info) +#define XLogRecGetRmid(decoder) ((decoder)->decoded_record->xl_rmid) +#define XLogRecGetXid(decoder) ((decoder)->decoded_record->xl_xid) +#define XLogRecGetTerm(decoder) ((decoder)->decoded_record->xl_term) +#define XLogRecGetBucketId(decoder) ((decoder)->decoded_record->xl_bucket_id - 1) +#define XLogRecGetCrc(decoder) ((decoder)->decoded_record->xl_crc) +#define XLogRecGetOrigin(decoder) ((decoder)->record_origin) +#define XLogRecGetData(decoder) ((decoder)->main_data) +#define XLogRecGetDataLen(decoder) ((decoder)->main_data_len) +#define XLogRecHasAnyBlockRefs(decoder) ((decoder)->max_block_id >= 0) +#define XLogRecHasBlockRef(decoder, block_id) ((decoder)->blocks[block_id].in_use) +#define XLogRecHasBlockImage(decoder, block_id) ((decoder)->blocks[block_id].has_image) + +extern void RestoreBlockImage(const char* bkp_image, uint16 hole_offset, uint16 hole_length, char* page); +extern char* XLogRecGetBlockData(XLogReaderState* record, uint8 block_id, Size* len); +extern bool allocate_recordbuf(XLogReaderState* state, uint32 reclength); +extern bool XlogFileIsExisted(const char* workingPath, XLogRecPtr inputLsn, TimeLineID timeLine); +extern void ResetDecoder(XLogReaderState* state); +bool ValidXLogPageHeader(XLogReaderState* state, XLogRecPtr recptr, XLogPageHeader hdr, bool readoldversion); +void report_invalid_record(XLogReaderState* state, const char* fmt, ...) + /* + * This extension allows gcc to check the format string for consistency with + * the supplied arguments. + */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +bool ValidXLogRecordHeader( + XLogReaderState* state, XLogRecPtr RecPtr, XLogRecPtr PrevRecPtr, XLogRecord* record, bool randAccess); +bool ValidXLogRecord(XLogReaderState* state, XLogRecord* record, XLogRecPtr recptr); + +#endif /* XLOGREADER_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlogrecord.h postgresql-hll-2.14/include/access/xlogrecord.h --- postgresql-hll-2.14_old/include/access/xlogrecord.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlogrecord.h 2020-12-12 17:06:43.070345754 +0800 @@ -0,0 +1,118 @@ +/* --------------------------------------------------------------------------------------- + * + * xlogrecord.h + * Definitions for the WAL record format. + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/xlogrecord.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGRECORD_H +#define XLOGRECORD_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/pg_crc.h" +#include "port/pg_crc32c.h" + +/* + * The high 4 bits in xl_info may be used freely by rmgr. The + * XLR_SPECIAL_REL_UPDATE bit can be passed by XLogInsert caller. The rest + * are set internally by XLogInsert. + */ +#define XLR_INFO_MASK 0x0F +#define XLR_RMGR_INFO_MASK 0xF0 + +/* + * If a WAL record modifies any relation files, in ways not covered by the + * usual block references, this flag is set. This is not used for anything + * by PostgreSQL itself, but it allows external tools that read WAL and keep + * track of modified blocks to recognize such special record types. + */ +#define XLR_SPECIAL_REL_UPDATE 0x01 +/* If xlog record contains bucket node id */ +#define XLR_REL_HAS_BUCKET 0x02 + +/* + * Header info for block data appended to an XLOG record. + * + * Note that we don't attempt to align the XLogRecordBlockHeader struct! + * So, the struct must be copied to aligned local storage before use. + * 'data_length' is the length of the payload data associated with this, + * and includes the possible full-page image, and rmgr-specific data. It + * does not include the XLogRecordBlockHeader struct itself. + */ +typedef struct XLogRecordBlockHeader { + uint8 id; /* block reference ID */ + uint8 fork_flags; /* fork within the relation, and flags */ + uint16 data_length; /* number of payload bytes (not including page + * image) */ + + /* If BKPBLOCK_HAS_IMAGE, an XLogRecordBlockImageHeader struct follows */ + /* If !BKPBLOCK_SAME_REL is not set, a RelFileNode follows */ + /* BlockNumber follows */ +} XLogRecordBlockHeader; + +#define SizeOfXLogRecordBlockHeader (offsetof(XLogRecordBlockHeader, data_length) + sizeof(uint16)) + +/* + * We use the highest bit of XLogRecordBlockHeader->id for hash bucket table. + * The RelFileNode is for hash bucket tables, and RelFileNodeOld is for regular tables. + */ +#define BKID_HAS_BUCKET (0x80) +#define BKID_GET_BKID(id) (id & 0x7F) + +/* + * Additional header information when a full-page image is included + * (i.e. when BKPBLOCK_HAS_IMAGE is set). + * + * As a trivial form of data compression, the XLOG code is aware that + * PG data pages usually contain an unused "hole" in the middle, which + * contains only zero bytes. If hole_length > 0 then we have removed + * such a "hole" from the stored data (and it's not counted in the + * XLOG record's CRC, either). Hence, the amount of block data actually + * present is BLCKSZ - hole_length bytes. + */ +typedef struct XLogRecordBlockImageHeader { + uint16 hole_offset; /* number of bytes before "hole" */ + uint16 hole_length; /* number of bytes in "hole" */ +} XLogRecordBlockImageHeader; + +#define SizeOfXLogRecordBlockImageHeader sizeof(XLogRecordBlockImageHeader) + +/* + * Maximum size of the header for a block reference. This is used to size a + * temporary buffer for constructing the header. + */ +#define MaxSizeOfXLogRecordBlockHeader \ + (SizeOfXLogRecordBlockHeader + SizeOfXLogRecordBlockImageHeader + sizeof(RelFileNode) + sizeof(BlockNumber)) + +/* + * XLogRecordDataHeaderShort/Long are used for the "main data" portion of + * the record. If the length of the data is less than 256 bytes, the short + * form is used, with a single byte to hold the length. Otherwise the long + * form is used. + * + * (These structs are currently not used in the code, they are here just for + * documentation purposes). + */ +typedef struct XLogRecordDataHeaderShort { + uint8 id; /* XLR_BLOCK_ID_DATA_SHORT */ + uint8 data_length; /* number of payload bytes */ +} XLogRecordDataHeaderShort; + +#define SizeOfXLogRecordDataHeaderShort (sizeof(uint8) * 2) + +typedef struct XLogRecordDataHeaderLong { + uint8 id; /* XLR_BLOCK_ID_DATA_LONG */ + /* followed by uint32 data_length, unaligned */ +} XLogRecordDataHeaderLong; + +#define SizeOfXLogRecordDataHeaderLong (sizeof(uint8) + sizeof(uint32)) +#endif /* XLOGRECORD_H */ diff -uprN postgresql-hll-2.14_old/include/access/xlogutils.h postgresql-hll-2.14/include/access/xlogutils.h --- postgresql-hll-2.14_old/include/access/xlogutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/access/xlogutils.h 2020-12-12 17:06:43.070345754 +0800 @@ -0,0 +1,68 @@ +/* + * xlogutils.h + * + * Utilities for replaying WAL records. + * + * PostgreSQL transaction log manager utility routines + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlogutils.h + */ +#ifndef XLOG_UTILS_H +#define XLOG_UTILS_H + +#include "access/xlogreader.h" +#include "storage/bufmgr.h" + +/* Result codes for XLogReadBufferForRedo[Extended] */ +typedef enum { + BLK_NEEDS_REDO, /* changes from WAL record need to be applied */ + NO_BLK, /* ddl no need get block */ + BLK_DONE, /* block is already up-to-date */ + BLK_RESTORED, /* block was restored from a full-page image */ + BLK_NOTFOUND /* block was not found (and hence does not need to be + * replayed) */ +} XLogRedoAction; + +extern bool XLogHaveInvalidPages(void); +extern void* XLogGetInvalidPages(); + +extern void XLogCheckInvalidPages(void); + +extern void XLogDropRelation(const RelFileNode& rnode, ForkNumber forknum); +extern void XlogDropRowReation(RelFileNode rnode); +extern void XLogDropDatabase(Oid dbid); +extern void XLogTruncateRelation(XLogReaderState* record, const RelFileNode& rnode, ForkNumber forkNum, BlockNumber nblocks); +extern void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum, BlockNumber nblocks); + +extern Buffer XLogReadBufferExtended(const RelFileNode& rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState* record, uint8 buffer_id, Buffer* buf); +extern Relation CreateFakeRelcacheEntry(const RelFileNode& rnode); +extern Relation CreateCUReplicationRelation(const RelFileNode& rnode, int BackendId, char relpersistence, const char* relname); +extern void FreeFakeRelcacheEntry(Relation fakerel); +extern void log_invalid_page(const RelFileNode& node, ForkNumber forkno, BlockNumber blkno, bool present); +extern int read_local_xlog_page(XLogReaderState* state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, + char* cur_page, TimeLineID* pageTLI); +extern void closeXLogRead(); +extern bool IsDataBaseDrop(XLogReaderState* record); +extern bool IsTableSpaceDrop(XLogReaderState* record); +extern bool IsTableSpaceCreate(XLogReaderState* record); +extern bool IsDataBaseCreate(XLogReaderState* record); + +extern Buffer XLogReadBufferExtendedWithoutBuffer( + RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern Buffer XLogReadBufferExtendedWithLocalBuffer( + RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern void XlogUpdateFullPageWriteLsn(Page page, XLogRecPtr lsn); +void XLogSynAllBuffer(); +bool ParseStateUseShareBuf(); +bool ParseStateUseLocalBuf(); +bool ParseStateWithoutCache(); + + +#endif diff -uprN postgresql-hll-2.14_old/include/alarm/alarm.h postgresql-hll-2.14/include/alarm/alarm.h --- postgresql-hll-2.14_old/include/alarm/alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/alarm.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,208 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarm.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/alarm/alarm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ALARM_H +#define ALARM_H + +#include "c.h" + +/*GaussDB alarm module.*/ +typedef enum AlarmId { + ALM_AI_Unknown = 0, + + /*alarm on data instances(alarm checker)*/ + ALM_AI_MissingDataInstDataOrRedoDir = 0x404E0001, + ALM_AI_MissingDataInstWalSegmt = 0x404E0003, + ALM_AI_TooManyDataInstConn = 0x404F0001, + + /*alarm on monitor instances*/ + ALM_AI_AbnormalGTMInst = 0x404F0002, + ALM_AI_AbnormalDatanodeInst = 0x404F0004, + + ALM_AI_AbnormalGTMProcess = 0x404F0008, + ALM_AI_AbnormalCoordinatorProcess = 0x404F0009, + ALM_AI_AbnormalDatanodeProcess = 0x404F0010, + + ALM_AI_DatanodeSwitchOver = 0x404F0021, + ALM_AI_DatanodeFailOver = 0x404F0022, + + ALM_AI_GTMSwitchOver = 0x404F0023, + ALM_AI_GTMFailOver = 0x404F0024, + + ALM_AI_ForceFinishRedo = 0x404F0025, + + ALM_AI_AbnormalCMSProcess = 0x404F003B, + ALM_AI_UnbalancedCluster = 0x404F0038, + ALM_AI_AbnormalCMAProcess = 0x404F003A, + ALM_AI_AbnormalETCDProcess = 0x404F003E, + + /*alarm when occur errors*/ + ALM_AI_AbnormalDataHAInstListeningSocket = 0x404F0039, + ALM_AI_AbnormalGTMSocket = 0x404F003D, + ALM_AI_AbnormalDataInstConnToGTM = 0x404F003C, + ALM_AI_AbnormalDataInstConnAuthMethod = 0x404F0036, + ALM_AI_TooManyDatabaseConn = 0x404F0037, + ALM_AI_TooManyDbUserConn = 0x404F0033, + ALM_AI_DataInstLockFileExist = 0x404F0034, + ALM_AI_InsufficientDataInstFileDesc = 0x404F0031, + ALM_AI_AbnormalDataInstArch = 0x404F0032, + ALM_AI_AbnormalTableSkewness = 0x404F0035, + + ALM_AI_AbnormalTDEFile = 0x404F0041, + ALM_AI_AbnormalTDEValue = 0x404F0042, + ALM_AI_AbnormalConnToKMS = 0x404F0043, + + ALM_AI_AbnormalDataInstDisk = 0x404F0047, + + ALM_AI_AbnormalEtcdDown = 0x404F0048, + ALM_AI_AbnormalEtcdUnhealth = 0x404F0049, + + ALM_AI_AbnormalPhonyDead = 0x404F004A, + ALM_AI_AbnormalCmaConnFail = 0x404F004B, + ALM_AI_Build = 0x404F004C, + ALM_AI_AbnormalBuild = 0x404F004D, + ALM_AI_TransactionReadOnly = 0x404F0059, + ALM_AI_ServerSwitchOver = 0x404F005A, + + ALM_AI_AbnormalEtcdNearQuota = 0x404F005B, + + ALM_AI_StorageThresholdPreAlarm = 0x404F005C, + ALM_AI_StorageDilatationAlarmNotice = 0x404F005D, + ALM_AI_StorageDilatationAlarmMajor = 0x404F005E, + + ALM_AI_FeaturePermissionDenied = 0x404F0050, /* No permission to invoke specific features. */ + ALM_AI_BUTT = 0x7FFFFFFFFFFFFFFF /*force compiler to decide AlarmId as uint64*/ +} AlarmId; + +typedef struct AlarmName { + AlarmId id; + char nameEn[256]; + char nameCh[256]; + char alarmInfoEn[1024]; + char alarmInfoCh[1024]; + char alarmLevel[256]; +} AlarmName; + +typedef struct AlarmAdditionalParam { + char clusterName[256]; + char hostName[256]; + char hostIP[256]; + char instanceName[256]; + char databaseName[256]; + char dbUserName[128]; + char logicClusterName[128]; + char additionInfo[256]; +} AlarmAdditionalParam; + +/*total alarm types of alarm module.*/ +typedef enum AlarmType { ALM_AT_Fault = 0, ALM_AT_Resume = 2, ALM_AT_OPLog, ALM_AT_Event, ALM_AT_Delete } AlarmType; + +/*status of a specific alarm.*/ +typedef enum AlarmStat { ALM_AS_Normal, ALM_AS_Reported } AlarmStat; + +/*result types of alarm check functions.*/ +typedef enum AlarmCheckResult { + ALM_ACR_UnKnown = 0, + + ALM_ACR_Normal, + ALM_ACR_Abnormal +} AlarmCheckResult; + +typedef enum AlarmModule { + ALM_AM_NoModule = 0, + + ALM_AM_Coordinator, + ALM_AM_Datanode, + ALM_AM_GTM, + ALM_AM_CMServer +} AlarmModule; + +typedef struct Alarm { + AlarmId id; + AlarmStat stat; + time_t lastReportTime; + long startTimeStamp; + long endTimeStamp; + int reportCount; + char infoEn[256]; + char infoCh[256]; + + AlarmCheckResult (*checker)(Alarm* alarm, AlarmAdditionalParam* additionalParam); +} Alarm; + +typedef AlarmCheckResult (*CheckerFunc)(Alarm* alarm, AlarmAdditionalParam* additionalParam); + +/*common function to check*/ +extern void AlarmEnvInitialize(void); + +extern void AlarmItemInitialize(Alarm* alarmItem, AlarmId alarmId, AlarmStat alarmStat, CheckerFunc checkerFunc, + time_t reportTime = 0, int reportCount = 0); + +extern void AlarmCheckerLoop(Alarm* checkList, int checkListSize); + +extern void WriteAlarmAdditionalInfo(AlarmAdditionalParam* additionalParam, const char* instanceName, + const char* databaseName, const char* dbUserName, Alarm* alarmItem, AlarmType type, ...); + +extern void WriteAlarmAdditionalInfoForLC(AlarmAdditionalParam* additionalParam, const char* instanceName, + const char* databaseName, const char* dbUserName, const char* logicClusterName, Alarm* alarmItem, AlarmType type, + ...); + +extern void AlarmReporter(Alarm* alarmItem, AlarmType type, AlarmAdditionalParam* additionalParam); + +/*alarm module only log in two level.*/ +#define ALM_LOG 1 +#define ALM_DEBUG 2 +#define AlarmLogPrefix "[Alarm Module]" + +#define CLUSTER_NAME_LEN 64 + +extern void AlarmLog(int level, const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/*below things must be implemented by other modules(gaussdb, gtm, cmserver etc.).*/ + +/*declare the guc variable of alarm module*/ +extern char* Alarm_component; +extern THR_LOCAL int AlarmReportInterval; + +/*declare the global variable of alarm module*/ +extern int g_alarmReportInterval; +extern int g_alarmReportMaxCount; +extern char g_alarmComponentPath[MAXPGPATH]; + +/*alarm module memory alloc method maybe different in different module.*/ +extern void* AlarmAlloc(size_t size); +extern void AlarmFree(void* pointer); + +/*callback protype for get logic cluster name.*/ +typedef void (*cb_for_getlc)(char*); +/*set callback function for get logic cluster name*/ +void SetcbForGetLCName(cb_for_getlc get_lc_name); + +/*alarm log implementation.*/ +extern void AlarmLogImplementation(int level, const char* prefix, const char* logtext); + +#endif diff -uprN postgresql-hll-2.14_old/include/alarm/alarm_log.h postgresql-hll-2.14/include/alarm/alarm_log.h --- postgresql-hll-2.14_old/include/alarm/alarm_log.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/alarm_log.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarm_log.h + * alarm logging and reporting + * + * + * IDENTIFICATION + * src/include/alarm/alarm_log.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ALARM_LOG_H +#define ALARM_LOG_H +#include "alarm/alarm.h" + +#define SYSQUOTE "\"" +#define SYSCOLON ":" +#define SYSCOMMA "," + +#define MAX_BUF_SIZE 1024 +extern char g_alarm_scope[MAX_BUF_SIZE]; + +void clean_system_alarm_log(const char* file_name, const char* sys_log_path); + +void create_system_alarm_log(const char* sys_log_path); + +void write_alarm(Alarm* alarmItem, const char* alarmName, const char* alarmLevel, AlarmType type, + AlarmAdditionalParam* additionalParam); + +void set_alarm_scope(const char* alarmScope); + +#endif diff -uprN postgresql-hll-2.14_old/include/alarm/GaussAlarm_client.h postgresql-hll-2.14/include/alarm/GaussAlarm_client.h --- postgresql-hll-2.14_old/include/alarm/GaussAlarm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/GaussAlarm_client.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,88 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * GaussAlarm_client.h + * + * + * + * IDENTIFICATION + * src/include/alarm/GaussAlarm_client.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GAUSS_ALARM_CLENT_H__ +#define __GAUSS_ALARM_CLENT_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +#ifndef CM_ALARM_TYPE_MACRO +/* �澯���� */ +typedef enum tagCM_ALARM_TYPE { + ALM_ALARM_TYPE_FAULT = 0, /* ���� */ + // ALM_ALARM_TYPE_EVENT = 1, /* �¼� */ + ALM_ALARM_TYPE_RESUME = 2, /* �ָ� */ + ALM_ALARM_TYPE_OPLOG = 3, /* ������־ */ + ALM_ALARM_TYPE_EVENT = 4, /* �¼�--> ������־ */ + ALM_ALARM_TYPE_DELETE = 5, /* ɾ�� */ + +} CM_ALARM_TYPE; +#define CM_ALARM_TYPE_MACRO +#endif /* #ifndef CM_ALARM_TYPE_MACRO */ + +#ifndef CM_SUBSYSTEM_ID_MACRO +/* �澯ģ��ID���� */ +typedef enum tagCM_SUBSYSTEM_ID { + SUBSYSID_CM = 0, /* CM */ + SUBSYSID_PRO = 1, /* protocol */ + SUBSYSID_TS = 2, /* TSģ�� */ + SUBSYSID_CA = 3, /* CA */ + SUBSYSID_MDS = 4, /* MDS */ + SUBSYSID_DS = 5, /* DS*/ + SUBSYSID_DLM = 6, /* BASE DLM*/ + SUBSYSID_MONC = 7, /* MONC */ + SUBSYSID_TRNS = 8, /* TRNS */ + SUBSYSID_NVCACHE = 9, /* NVCACHE */ + SUBSYSID_PMA = 10, /* PMA */ + SUBSYSID_BASE = 11, /* BASE */ + SUBSYSID_MONS = 12, /* MONS */ + SUBSYSID_NOFS = 13, /* NOFS */ + + SUBSYSID_SQL = 20, /* ��˹���ݿ� */ + SUBSYSID_HD = 21, /* hadoop */ + SUBSYSID_MDM = 22, /* �ļ�ϵͳԪ���ݹ��� */ + + SUBSYSID_BUTT /* ���ֵ */ +} CM_SUBSYSTEM_ID; +#define CM_SUBSYSTEM_ID_MACRO +#endif /*# ifndef CM_SUBSYSTEM_ID_MACRO */ + +/** +���Ʒ���͸澯. +alarmMsg����󳤶�Ϊ1024���������ֻᱻ�ض� +����ֵ�� 0 �ɹ�����0 ʧ�� +*/ +int Gauss_alarm_report(int moduleID, long long alarmID, CM_ALARM_TYPE type, char* alarmMsg, int msgLength); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif //__GAUSS_ALARM_CLENT_H__ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/alarm/gauss_libpq_wrapper.h postgresql-hll-2.14/include/alarm/gauss_libpq_wrapper.h --- postgresql-hll-2.14_old/include/alarm/gauss_libpq_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gauss_libpq_wrapper.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gauss_libpq_wrapper.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gauss_libpq_wrapper.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_GAUSS_WRAPPER_H__ +#define __GS_GAUSS_WRAPPER_H__ + +#include "alarm/gs_config.h" +#include "alarm/gs_server.h" +#include "alarm/gt_threads.h" + +/* Table name to create and use. If you are changing, + also check for create table function */ +#define WARN_TABLENAME "gswarnings" +#define WARN_CREATE_TABLE_QRY \ + "CREATE TABLE IF NOT EXISTS " WARN_TABLENAME "(moduleid integer, " \ + "submoduleid integer, " \ + "alarmid bigint, " \ + "params varchar(512), " \ + "isresolved boolean, " \ + "warning_time timestamp, " \ + "resolve_time timestamp); " + +/* Have to bind module,submodule,alarm,param, ==> yet to add "warningtime" */ +#define WARN_INSERT_TABLE_QRY \ + "INSERT INTO " WARN_TABLENAME " (moduleid, submoduleid, alarmid, params) VALUES ($1, $2, $3, $4);" + +#define WARN_UPDATE_QRY \ + "UPDATE " WARN_TABLENAME " SET isresolved=true where moduleid=$1 and submoduleid=$2 " \ + "and alarmid=$3;" + +WARNERRCODE gaussConnection(LP_GS_CONFIG config, char* password, LP_GAUSS_CONN* conn); + +void gaussDisconnect(LP_GAUSS_CONN* conn); + +WARNERRCODE createWarningTableIfNotExits(LP_GAUSS_CONN conn); + +WARNERRCODE insertWarning(LP_GAUSS_CONN conn, LP_GS_ALARM alarm); + +WARNERRCODE isOpenWarningExists(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE isOpenWarningExists(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE isOpenWarningExistInLast3Mins(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE updateWarningStatusInDB(LP_GAUSS_CONN conn, LP_GS_ALARM alarm); + +#endif //__GS_GAUSS_WRAPPER_H__ diff -uprN postgresql-hll-2.14_old/include/alarm/gs_config.h postgresql-hll-2.14/include/alarm/gs_config.h --- postgresql-hll-2.14_old/include/alarm/gs_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gs_config.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_config.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_config.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_CONFIG_H__ +#define __GS_CONFIG_H__ + +#include "alarm/gs_warn_common.h" + +#define WARN_MAX_NAME_LEN 64 +#define MAX_LEN_USERNAME WARN_MAX_NAME_LEN +#define MAX_LEN_CLUSTERNAME WARN_MAX_NAME_LEN + +typedef enum tagConfigType { + CONFIG_PORT, + CONFIG_GAUSS_HOST, + CONFIG_GAUSS_PORT, + CONFIG_GAUSS_DBNAME, + CONFIG_GAUSS_USERNAME, + CONFIG_GAUSS_PASSWORD, + CONFIG_LOG_FILENAME, + + CONFIG_BUTT = 0xffffffff +} CONFIG_TYPE; + +typedef struct tagGsConfig { + int32 portNum; + char dbHost[MAX_LEN_SERVADDR]; + int32 dbPort; + char username[MAX_LEN_USERNAME]; + char dbname[MAX_LEN_USERNAME]; + char clustername[MAX_LEN_CLUSTERNAME]; +} GS_CONFIG, *LP_GS_CONFIG; + +WARNERRCODE processConfiguration(int32 argc, char* argv[], char** password); +void fillDefaultGaussInfo(); + +#endif //__GS_CONFIG_H__ diff -uprN postgresql-hll-2.14_old/include/alarm/gs_server.h postgresql-hll-2.14/include/alarm/gs_server.h --- postgresql-hll-2.14_old/include/alarm/gs_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gs_server.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_server.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_WARN_SERVER_H__ +#define __GS_WARN_SERVER_H__ + +#include "alarm/gs_warn_common.h" +#include "libpq-fe.h" +#include "alarm/gt_threads.h" +#include "alarm/gs_config.h" + +#define MAX_THREAD_COUNT 128 + +typedef enum tagGaussConnState { + GAUSS_CONN_INIT, + GAUSS_CONN_CONNECTED, + GAUSS_CONN_CONNECT_FAILED, + GAUSS_CONN_EXECUTING, + GAUSS_CONN_ERROR, + + GAUSS_CONN_BUTT = 0xffffffff +} GAUSS_CONN_STATE; + +typedef struct tagGaussConn { + PGconn* connHandle; + THREAD_LOCK globalsLock; /* Global lock */ + GAUSS_CONN_STATE state; +} GAUSS_CONN, *LP_GAUSS_CONN; + +typedef enum tagServerStates { + SERVER_STATE_INIT, + SERVER_STATE_CONNECTED, + SERVER_STATE_LISTENING, + SERVER_STATE_EXITING, + + SERVER_STATE_BUTT = 0xffffffff +} GAUSS_SERVER_STATES; + +typedef struct tagWmpGlobals { + GT_SOCKET sock; /* Server socket */ + GS_CONFIG config; /* Configuration parameters */ + GAUSS_CONN gaussConn; +} WARN_GLOBALS, *LP_WARN_GLOBALS; + +typedef struct tagClientSession { + GT_SOCKET sock; + char* sendBuf; + char* recvBuf; +} GS_CLIENT_SESSION, *LP_GS_CLIENT_SESSION; + +/* Mock structure of Alarm. If one exits in Gauss then use that. */ +typedef struct tagGsAlarm { + uint64 alarmId; + uint32 moduleId; + uint32 submoduleId; + bool isResolved; + char alarmParam[MAX_ALARM_PARAM_LEN]; +} GS_ALARM, *LP_GS_ALARM; + +extern LP_WARN_GLOBALS globals; +extern bool gIsExit; + +void collectClientWarnings(LPGT_THREAD_S pstThread); +WARNERRCODE getNewThreadCtx(LPGT_THREAD_S* newthreadCtx); + +#endif //__GS_WARN_SERVER_H__ diff -uprN postgresql-hll-2.14_old/include/alarm/gs_server_network.h postgresql-hll-2.14/include/alarm/gs_server_network.h --- postgresql-hll-2.14_old/include/alarm/gs_server_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gs_server_network.h 2020-12-12 17:06:43.071345767 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_server_network.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_server_network.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_SERVER_NETWORK_H__ +#define __GS_SERVER_NETWORK_H__ + +#include "alarm/gs_warn_common.h" +#include "alarm/gs_server.h" + +WARNERRCODE initNetworkLayer(); + +WARNERRCODE acceptOnSocket(GT_SOCKET listernSock, GT_SOCKET* iClientSock, char* ipAddr, uint16* psPort); + +WARNERRCODE recvData(GT_SOCKET Sock, char* buf, int32 bufSize, int32* dataRecvSize); + +WARNERRCODE sendPacketToClient(GT_SOCKET sock, char* pucBuf, int32 iSize); + +WARNERRCODE sendAck(GT_SOCKET sock, char* sendBuf, int32 errCode); + +void disconnectClient(GT_SOCKET sock); + +WARNERRCODE retrySendAck(LP_GS_CLIENT_SESSION session, int32 errCode); + +WARNERRCODE validateClientPacket(LPGT_PACKET_HEAD header); + +#endif //__GS_SERVER_NETWORK_H__ diff -uprN postgresql-hll-2.14_old/include/alarm/gs_utils.h postgresql-hll-2.14/include/alarm/gs_utils.h --- postgresql-hll-2.14_old/include/alarm/gs_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gs_utils.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_utils.h + * Header file for Gauss warning module utility functions. + * + * + * IDENTIFICATION + * src/include/alarm/gs_utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_UTILS_H__ +#define __GS_UTILS_H__ + +#include "alarm/gs_warn_common.h" + +#define BASE_DECIMAL 10 + +#define MAX_STR_LEN_OF_UINT32 11 + +#define MAX_STR_LEN_OF_UINT64 22 + +WARNERRCODE stringToLong(char* str, int32 base, long* value); + +WARNERRCODE validateIPAddress(char* pucIp, char* key, uint32 slLen); + +WARNERRCODE validatePort(char* str, char* key, int32* port); + +void stringCopy(char* dest, char* src, uint32 iMaxLen); + +bool compareString(char* str1, char* str2); + +void uint32ToStr(uint32 intVal, char* strVal); + +void uint64ToStr(uint64 longVal, char* strVal); + +void writeUIntToBuffer(char* buf, uint32 value, int32* iBufPos); + +void writeULongToBuffer(char* buf, uint64 value, int32* iBufPos); + +void writeNULLToBuffer(char* buf, int32* iBufPos); + +void writeStringToBuffer(char* buf, char* str, int32* iBufPos); + +#endif //__GS_UTILS_H__ diff -uprN postgresql-hll-2.14_old/include/alarm/gs_warn_common.h postgresql-hll-2.14/include/alarm/gs_warn_common.h --- postgresql-hll-2.14_old/include/alarm/gs_warn_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gs_warn_common.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,145 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_warn_common.h + * Warning module common header file. + * + * + * IDENTIFICATION + * src/include/alarm/gs_warn_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GT_WARN_COMMON_H__ +#define __GT_WARN_COMMON_H__ + +#include "c.h" +#include "alarm/GaussAlarm_client.h" + +#define GT_FALSE 0 +#define GT_TRUE 1 +#define GT_NULL_POINTER NULL +#define GT_SOCKET int32 +#define MAX_PORT_CHAR_SIZE 6 +#define LOCALHOST "127.0.0.1" +#define SOCKET_OPT_IS_REUSE_ADDR 1 +#define SOCKET_OPT_IS_KEEP_ALIVE 1 +#define GT_MAGIC_NUMBER 0xabcdef87 +#define GT_PROTOCOL_VERSION 0x0001 +#define MAX_ALARM_PARAM_LEN 1024 // Alarm params length +#define MAX_SEND_RETRY_COUNT 3 +#define MAX_RECV_RETRY_COUNT 3 + +#define GT_NETWORK_BYTE_ORDER 0 +#define GT_NON_NETWORK_BYTE_ORDER 1 +#define SYS_BYTE_ORDER \ + ((0x01020304 == *(int32*)(void*)"\x1\x2\x3\x4") ? GT_NETWORK_BYTE_ORDER : GT_NON_NETWORK_BYTE_ORDER) + +/* Packet header size */ +#define GT_PACKET_HEADER_SIZE sizeof(GT_PACKET_HEAD) +#define GT_PACKET_MAX_PAYLOAD_SIZE (GT_SEND_BUFFER_SIZE - GT_PACKET_HEADER_SIZE) + +#define GT_SEND_BUFFER_SIZE 4096 /* 4K */ +#define GT_RECV_BUFFER_SIZE 4096 /* 4K */ +/* The max length of address consisting of IP */ +#define MAX_LEN_SERVADDR 32 + +/* Mapping system function to own functions, to enable future changes */ +#define GT_MALLOC malloc +#define GT_FREE(mem) \ + if (GT_NULL_POINTER != mem) { \ + free(mem); \ + } +#define GTLOG(...) printf(__VA_ARGS__) +#define GTCONSOLELOG(...) printf(__VA_ARGS__) + +/* Error codes - to be integrated with Gauss */ +typedef enum tagWarnErrorCodes { + GT_SUCCESS = 0, + GTERR_END_OF_WARNINGS, + + GTERR_MEMORY_ALLOC_FAILED = 0x00001100, + GTERR_THREAD_INIT_FAILED, + GTERR_THREAD_CREATE_FAILED, + GTERR_THREAD_DESTROY_FAILED, + GTERR_THREAD_ACQUIRE_LOCK_FAILED, + GTERR_THREAD_RELEASE_LOCK_FAILED, + + GTERR_SOCKET_CONNECT_FAILED, + GTERR_SOCKET_WRITE_FAILED, + GTERR_SOCKET_READ_FAILED, + GTERR_SOCKET_CLOSED, + + GTERR_INTEGER_OVERFLOW, + GTERR_INVALID_VALUE, + + GTERR_LISTENER_START_FAILED, + GTERR_INSUFFICIENT_CONFIGS, + GTERR_INVALID_CONFIG_VALUE, + + GTERR_SHUTDOWN_INPROGRESS, + GTERR_CONNECT_TO_WMP_FAILED, + GTERR_INVALID_PACKET, + GTERR_COMMAND_SEND_TIMEDOUT, + GTERR_RESEND_WARNING, + + GTERR_GAUSS_CONN_FAILED, + GTERR_GAUSS_CONNECTION_LOST, + GTERR_GAUSS_DATA_FETCH_FAILED, + + GTERR_BUTT = 0xffffffff +} WARNERRCODE; + +/*** + * List of commands understood by Client - Server network layer. + ***/ +typedef enum tagGTPacketHeadCmds { + GT_PKT_WARNING = 0x00022001, + GT_PKT_END_OF_WARNINGS, + GT_PKT_SERVER_ERROR, + GT_PKT_GET_ALL_WARNINGS, + GT_PKT_ACK, + + GT_PKT_BUTT = 0xffffffff +} GT_PACKET_HEAD_CMDS; + +/*** + * Packet header for Client-Server communication. + * + ***/ +typedef struct tagGtPacketHead { + uint32 ulMagicNum; /* Magic number used for packet validation */ + int32 packetCmd; /* Type of command being executed */ + uint16 usProtocolVersion; /* Protocol version */ + int8 rsvd1[2]; /*Alignment */ + uint32 uiSize; /* Size of the packet including header */ + int32 uiErrorCode; /* Error code. 0 for success */ + uint32 uiTotDataSize; /* Size of the complete Data, valid for 1st packet */ + int8 cByteOrder; /* Byte order */ + bool bIsPendingData; /* Is the data partial */ + int8 rsvd2[2]; + int32 cOptions; /* Placeholder holder for future use */ +} GT_PACKET_HEAD, *LPGT_PACKET_HEAD; + +/*** + * Client Server Packet overall structure + ***/ +typedef struct tagGtPacket { + GT_PACKET_HEAD packetHeader; + unsigned char* packetPayload; +} GT_PACKET, *LPGT_PACKET; + +#endif /* __GT_WARN_COMMON_H__ */ diff -uprN postgresql-hll-2.14_old/include/alarm/gt_threads.h postgresql-hll-2.14/include/alarm/gt_threads.h --- postgresql-hll-2.14_old/include/alarm/gt_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/alarm/gt_threads.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,142 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gt_threads.h + * Thread operations functionality header file. Uses pthread library. + * This library is part of Gauss tools common code library. + * + * + * IDENTIFICATION + * src/include/alarm/gt_threads.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GT_THREADS_H__ +#define __GT_THREADS_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include +#include +#include "alarm/gs_warn_common.h" + +extern "C" { + +#define GT_THREAD_STACK_SIZE 131072 /* 128K [32768 - 32K thread stack size] */ +#define GT_THREAD_SLEEP_TIME (100) /* 1/10th of a sec */ +#define GT_THREAD_START_MAX_RETRY_COUNT (10000) /* 10s */ +#define MAX_THREAD_NAME_LEN 16 + +typedef pthread_mutex_t THREAD_LOCK; + +/* Thread state enum. */ +typedef enum tagGTThreadStatUS_E { + GT_THREAD_FREE = 0, + GT_THREAD_STARTING, + GT_THREAD_STARTED, + GT_THREAD_RUNNING, + GT_THREAD_START_FAILED, + GT_THREAD_EXITING, + + GT_THREAD_BUTT = 0xffff +} GT_THREAD_STATUS_E; + +/* Thread structure definition. */ +typedef struct tagGTThread { + pthread_t id; + + /* thread's run-time status, other thread can read it*/ + GT_THREAD_STATUS_E enStatus; + + void* pvProc; /* pointer of thread entry procedure*/ + void* pvArgument; /* argument */ + int32 ulResult; /* result of thread's execution */ + bool bExitThreadFlag; /* thread will quit gracefully, if set */ + void* pvCleanup; /* Any cleanup like release thread to pool etc */ +} GT_THREAD_S, *LPGT_THREAD_S; + +/*** + * Function signature for the thread entry functions. + * + * @param pstThread Thread context + * @return NA + ***/ +typedef void (*LPGT_THREAD_PROC)(LPGT_THREAD_S pstThread); + +/*** + * Create thread on demand. + * + * @param pfnProc : Function pointer, entry function to the thread. + * @param pvArgs : Argument to the entry function. + * @param ulStackSize : Stack size of the new thread. + * @param pstThread : Thread context structure. + * + * @ return GT_SUCCESS on success or error code on failure. + ***/ +WARNERRCODE createThread(LPGT_THREAD_PROC pfnThreadProc, void* pvArgs, uint32 ulStackSize, LPGT_THREAD_S pstThread); + +/*** + * Joins the thread to parent. Wait for the thread to close. + * + * @param pstThread : Thread context structure. + * @ return NA. + ***/ +void closeThread(LPGT_THREAD_S pstThread); + +/*** + * Get the current thread id + * + * @return id of the current thread. + ***/ +int32 getThreadID(); + +/*** + * Sleep function for the thread. + * + * @param sleep time in milli-second + ***/ +void threadSleep(uint32 ulSleepMs); + +/*** + * Initialize the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE initThreadLock(THREAD_LOCK* lock); + +/*** + * Destory the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE destroyThreadLock(THREAD_LOCK* lock); + +/*** + * Acquire Lock the thread + * + * @param lock parameter + ***/ +WARNERRCODE lock(THREAD_LOCK* lock); + +/*** + * Release the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE unlock(THREAD_LOCK* lock); +} + +#endif /* __GT_THREADS_H__ */ diff -uprN postgresql-hll-2.14_old/include/auditfuncs.h postgresql-hll-2.14/include/auditfuncs.h --- postgresql-hll-2.14_old/include/auditfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/auditfuncs.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,52 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * auditfuncs.h + * record the aduit informations of the database operation + * + * + * IDENTIFICATION + * src/include/auditfuncs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PGAUDIT_AGENT_H +#define PGAUDIT_AGENT_H +#include "pgaudit.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/namespace.h" + +#define PGAUDIT_MAXLENGTH 1024 +#define NoShutdown 0 +#define SmartShutdown 1 +#define FastShutdown 2 +#define ImmediateShutdown 3 + +char* pgaudit_get_relation_name(List* relation_name_list); +void pgaudit_dml_table(const char* objectname, const char* cmdtext); +void pgaudit_dml_table_select(const char* objectname, const char* cmdtext); + +extern void pgaudit_agent_init(void); +extern void pgaudit_agent_fini(void); +extern void pgaudit_user_no_privileges(const char* object_name, const char* detailsinfo); +extern void pgaudit_system_start_ok(int port); +extern void pgaudit_system_switchover_ok(const char* detaisinfo); +extern void pgaudit_system_recovery_ok(void); +extern void pgaudit_system_stop_ok(int shutdown); +extern void pgaudit_user_login(bool login_ok, const char* object_name, const char* detaisinfo); +extern void pgaudit_user_logout(void); +extern void pgaudit_lock_or_unlock_user(bool islocked, const char* user_name); +#endif diff -uprN postgresql-hll-2.14_old/include/bin/elog.h postgresql-hll-2.14/include/bin/elog.h --- postgresql-hll-2.14_old/include/bin/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bin/elog.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * elog.h + * + * + * + * IDENTIFICATION + * src/include/bin/elog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMMON_H +#define COMMON_H + +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); +extern void write_log(const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); +extern void init_log(char* prefix_name); +extern void check_env_value_c(const char* input_env_value); +extern void check_env_name_c(const char* input_env_value); +#endif /* COMMON_H */ diff -uprN postgresql-hll-2.14_old/include/bootstrap/bootstrap.h postgresql-hll-2.14/include/bootstrap/bootstrap.h --- postgresql-hll-2.14_old/include/bootstrap/bootstrap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bootstrap/bootstrap.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * bootstrap.h + * include file for the bootstrapping code + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/bootstrap/bootstrap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BOOTSTRAP_H +#define BOOTSTRAP_H + +#include "nodes/execnodes.h" + +/* + * MAXATTR is the maximum number of attributes in a relation supported + * at bootstrap time (i.e., the max possible in a system table). + */ +#define MAXATTR 40 + +extern void BootStrapProcessMain(int argc, char* argv[]); + +extern void err_out(void); + +extern void closerel(char* name); +extern void boot_openrel(char* name); + +extern void DefineAttr(const char* name, char* type, int attnum); +extern void InsertOneTuple(Oid objectid); +extern void InsertOneValue(char* value, int i); +extern void InsertOneNull(int i); + +extern const char* MapArrayTypeName(const char* s); + +extern void index_register(Oid heap, Oid ind, IndexInfo* indexInfo); +extern void build_indices(void); + +extern void boot_get_type_io_data(Oid typid, int16* typlen, bool* typbyval, char* typalign, char* typdelim, + Oid* typioparam, Oid* typinput, Oid* typoutput); + +extern int boot_yyparse(void); + +extern int boot_yylex(void); +extern void boot_yyerror(const char* str); + +#endif /* BOOTSTRAP_H */ diff -uprN postgresql-hll-2.14_old/include/bulkload/dist_fdw.h postgresql-hll-2.14/include/bulkload/dist_fdw.h --- postgresql-hll-2.14_old/include/bulkload/dist_fdw.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/dist_fdw.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,144 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dist_fdw.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/dist_fdw.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __DIST_FDW_H__ +#define __DIST_FDW_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" +#include "nodes/nodes.h" +#include "nodes/pg_list.h" +#include "storage/block.h" +#include "storage/fd.h" +#include "nodes/parsenodes.h" +#include "bulkload/importerror.h" + +extern "C" Datum dist_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum dist_fdw_validator(PG_FUNCTION_ARGS); + +extern "C" Datum file_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum file_fdw_validator(PG_FUNCTION_ARGS); + +extern "C" Datum hdfs_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum hdfs_fdw_validator(PG_FUNCTION_ARGS); + +#ifdef ENABLE_MOT +extern "C" Datum mot_fdw_validator(PG_FUNCTION_ARGS); +extern "C" Datum mot_fdw_handler(PG_FUNCTION_ARGS); +#endif + +extern void encryptOBSForeignTableOption(List** options); + +/* + * in shared mode coordinator assign file to data node + */ +typedef struct DistFdwFileSegment { + NodeTag type; + char* filename; + long begin; + long end; /* -1 means read the end of file*/ + int64 ObjectSize; +} DistFdwFileSegment; + +typedef struct DistFdwDataNodeTask { + NodeTag type; + char* dnName; + List* task; +} DistFdwDataNodeTask; + +typedef struct { + NodeTag type; + int logger_num; /* number of loggers */ + RangeTblEntry* rte; /* error relation*/ + char* filename; /* path of cache file*/ + ImportErrorLogger** loggers; /* error logger */ +} ErrorCacheEntry; + +extern const char* optLocation; +extern const char* optFormat; +extern const char* optHeader; +extern const char* optDelimiter; +extern const char* optQutote; +extern const char* optEscape; +extern const char* optNull; +extern const char* optEncoding; +extern const char* optFillMissFields; +extern const char* optRejectLimit; +extern const char* optMode; +extern const char* optForceNotNull; +extern const char* optWriteOnly; +extern const char* optWithoutEscaping; +extern const char* optErrorRel; +extern const char* optFormatter; +extern const char* optFix; +extern const char* optFileHeader; +extern const char* optOutputFilePrefix; +extern const char* optOutputFixAlignment; + +extern const char* optLogRemote; +extern const char* optSessionKey; +extern const char* optTaskList; +extern const char* optIgnoreExtraData; + +/* OBS specific options */ +extern const char* optChunkSize; +extern const char* optAsync; +extern const char* optEncrypt; +extern const char* optAccessKey; +extern const char* optSecretAccessKey; +#define DEST_CIPHER_LENGTH 1024 + +/* + * bulkload compatible illegal chars option + */ +extern const char* optCompatibleIllegalChars; +/* + * bulkload datetime format options + */ +extern const char* optDateFormat; +extern const char* optTimeFormat; +extern const char* optTimestampFormat; +extern const char* optSmalldatetimeFormat; + +extern const char* GSFS_PREFIX; +extern const char* GSFSS_PREFIX; +extern const char* LOCAL_PREFIX; +extern const char* ROACH_PREFIX; +extern const char* GSOBS_PREFIX; +extern const int GSFS_PREFIX_LEN; +extern const int GSFSS_PREFIX_LEN; +extern const int LOCAL_PREFIX_LEN; +extern const int ROACH_PREFIX_LEN; +extern const int GSOBS_PREFIX_LEN; + +extern bool is_obs_protocol(const char* filename); +// reject_limit is set as unlimited +// +#define REJECT_UNLIMITED -1 + +extern ErrorCacheEntry* GetForeignErrCacheEntry(Oid relid, uint32 distSessionKey); +List* CNSchedulingForDistOBSFt(Oid foreignTableId); + +#endif diff -uprN postgresql-hll-2.14_old/include/bulkload/foreignroutine.h postgresql-hll-2.14/include/bulkload/foreignroutine.h --- postgresql-hll-2.14_old/include/bulkload/foreignroutine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/foreignroutine.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,100 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * foreignroutine.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/foreignroutine.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FOREIGNROUTINE_H +#define FOREIGNROUTINE_H + +#include "nodes/execnodes.h" +#include "commands/copy.h" +#include "commands/explain.h" + +#define IS_SHARED_MODE(mode) ((mode) == MODE_SHARED) +#define IS_NORMAL_MODE(mode) ((mode) == MODE_NORMAL) +#define IS_PRIVATE_MODE(mode) ((mode) == MODE_PRIVATE) +#define IS_INVALID_MODE(mode) ((mode) == MODE_INVALID) + +typedef struct DistImportExecutionState : public CopyStateData { + List* source; /* data input source */ + List* options; /* merged COPY options, excluding filename */ + int rejectLimit; + Relation errLogRel; + Datum beginTime; + List* elogger; + bool isLogRemote; + bool needSaveError; +} DistImportExecutionState; + +typedef struct DistImportPlanState { + char* filename; + List* source; /* data input source */ + List* options; /* merged options, excluding filename */ + BlockNumber pages; /* estimate of file's physical size */ + double ntuples; /* estimate of number of rows in file */ + int rejectLimit; + char* errorName; + ImportMode mode; + bool writeOnly; + int fileEncoding; + bool doLogRemote; + char* remoteName; + + // explicit constructor + DistImportPlanState() + : filename(NULL), + source(NULL), + options(NULL), + pages(0), + ntuples(0), + rejectLimit(0), + errorName(NULL), + mode(MODE_INVALID), + writeOnly(false), + fileEncoding(0), + doLogRemote(false), + remoteName(NULL) + { + } +} DistImportPlanState; + +extern void ProcessDistImportOptions(DistImportPlanState *planstate, List *options, bool isPropagateToFE, + bool isValidate = false); + +extern void distImportGetRelSize(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); +extern void distImportGetPaths(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); +extern ForeignScan* distImportGetPlan(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid, + ForeignPath* best_path, List* tlist, List* scan_clauses); + +extern void distImportExplain(ForeignScanState* node, ExplainState* es); + +extern void distImportBegin(ForeignScanState* node, int eflags); + +extern TupleTableSlot* distExecImport(ForeignScanState* node); + +extern void distImportEnd(ForeignScanState* node); + +extern void distReImport(ForeignScanState* node); + +extern void getOBSOptions(ObsCopyOptions* obs_copy_options, List* options); + +#endif diff -uprN postgresql-hll-2.14_old/include/bulkload/importerror.h postgresql-hll-2.14/include/bulkload/importerror.h --- postgresql-hll-2.14_old/include/bulkload/importerror.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/importerror.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,205 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * importerror.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/importerror.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef IMPORTERROR_H +#define IMPORTERROR_H + +#include "access/tupdesc.h" +#include "commands/gds_stream.h" +#include "storage/fd.h" + +typedef struct CopyStateData* CopyState; + +struct ErrLogInfo { + /* SMP ID */ + uint32 smp_id; + + /* + * T, responsibility for unlinking local cache file. + * see also FD_ERRTBL_LOG_OWNER flag. + */ + bool unlink_owner; +}; + +class BaseError : public BaseObject { +public: + BaseError() + { + m_desc = NULL; + Reset(); + } + virtual ~BaseError() + { + } + + virtual void Serialize(StringInfo buf); + + virtual void Deserialize(StringInfo buf); + + virtual void serializeMaxNumOfValue(StringInfo buf) = 0; + + void Reset(); + + static const int StartTimeIdx = 1; + static const int FileNameIdx = 2; + static const int LineNOIdx = 3; + static const int RawDataIdx = 4; + static const int DetailIdx = 5; + static const int MaxNumOfValue = 6; + + Datum m_values[MaxNumOfValue]; + bool m_isNull[MaxNumOfValue]; + TupleDesc m_desc; +}; + +class ImportError : public BaseError { +public: + ImportError() + { + } + ~ImportError() + { + } + + void serializeMaxNumOfValue(StringInfo buf) override; + + static const int NodeIdIdx = 0; +}; + +/* ImportError for Copy */ +class CopyError : public BaseError { +public: + CopyError() + { + } + ~CopyError() + { + } + + void serializeMaxNumOfValue(StringInfo buf) override; + + static const int RelNameIdx = 0; +}; + +class BaseErrorLogger : public BaseObject { +public: + BaseErrorLogger() : m_memCxt(NULL), m_errDesc(NULL), m_buffer(NULL), m_fd(-1), m_offset(0) + { + } + virtual ~BaseErrorLogger() + { + } + + virtual void Destroy() = 0; + virtual int FetchError(BaseError* edata); + virtual void SaveError(BaseError* edata); + + MemoryContext m_memCxt; + TupleDesc m_errDesc; + +protected: + /* for LocalErrorLogger and CopyErrorLogger */ + StringInfo m_buffer; + File m_fd; + Size m_offset; +}; + +class ImportErrorLogger : public BaseErrorLogger { +public: + ImportErrorLogger() + { + } + virtual ~ImportErrorLogger() + { + } + + virtual void Destroy() override; + + virtual void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo); + virtual void FormError(CopyState cstate, Datum begintime, ImportError* edata){}; +}; + +class GDSErrorLogger : public ImportErrorLogger { +public: + GDSErrorLogger() : m_output(NULL), m_name(NULL) + { + } + ~GDSErrorLogger() + { + } + + void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo) override; + void Destroy() override; + /* GDSErrorLogger doesn't support FetchError method */ + int FetchError(BaseError* edata) override; + void SaveError(BaseError* edata) override; + void FormError(CopyState cstate, Datum begintime, ImportError* edata) override; + +private: + GDSStream* m_output; + char* m_name; +#ifdef USE_ASSERT_CHECKING + int m_counter; +#endif +}; + +class LocalErrorLogger : public ImportErrorLogger { +public: + LocalErrorLogger() + { + } + ~LocalErrorLogger() + { + } + + void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo) override; + void Destroy() override; + void FormError(CopyState cstate, Datum begintime, ImportError* edata) override; +}; + +/* Error logger for copy */ +class CopyErrorLogger : public BaseErrorLogger { +public: + CopyErrorLogger() : m_namespace(NULL) + { + } + ~CopyErrorLogger() + { + } + + void Destroy() override; + + void Initialize(CopyState cstate); + void Reset(); + void FormError(CopyState cstate, Datum begintime, CopyError* edata); + + char* m_namespace; +}; + +extern char* generate_unique_cache_name_prefix(Oid oid, uint32 distSessionKey); +extern char* generate_unique_cache_name_prefix(const char* relname); +extern void unlink_local_cache_file(const char* prefix, const uint32 smpId); + +#endif diff -uprN postgresql-hll-2.14_old/include/bulkload/roach_adpter.h postgresql-hll-2.14/include/bulkload/roach_adpter.h --- postgresql-hll-2.14_old/include/bulkload/roach_adpter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/roach_adpter.h 2020-12-12 17:06:43.072345780 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * roach_adpter.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/roach_adpter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __ROACH_ADPTER_H__ +#define __ROACH_ADPTER_H__ + +#include "bulkload/roach_api.h" +#include "commands/copy.h" + +template +extern bool getNextRoach(CopyState cstate); + +extern int copyGetRoachData(CopyState cstate, void* databuf, int minread, int maxread); + +template +extern void initRoachState(CopyState cstate, const char* filename, List* totalTask); + +extern void endRoachBulkLoad(CopyState cstate); + +extern void exportRoach(CopyState cstate); + +extern void exportRoachFlushOut(CopyState cstate, bool isWholeLineAtEnd); + +extern RoachRoutine* initRoachRoutine(); + +#endif diff -uprN postgresql-hll-2.14_old/include/bulkload/roach_api.h postgresql-hll-2.14/include/bulkload/roach_api.h --- postgresql-hll-2.14_old/include/bulkload/roach_api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/roach_api.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * roach_api.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/roach_api.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __ROACH_API_H__ +#define __ROACH_API_H__ + +#include "nodes/nodes.h" + +#ifndef __cplusplus + +#ifndef bool +typedef char bool; +#endif + +#ifndef true +#define true((bool)1) +#endif + +#ifndef false +#define false((bool)0) +#endif + +#endif /* __cplusplus */ + +typedef void* (*OpenFunc)(char* url, char* mode); +typedef size_t (*WriteFunc)(void* buf, size_t size, size_t len, void* roach_context, bool complete_line); +typedef size_t (*ReadFunc)(void* buf, size_t size, size_t len, void* roach_context); +typedef int (*CloseFunc)(void* roach_context); +typedef int (*ErrorFunc)(void* roach_context); + +typedef struct RoachRoutine { + NodeTag type; + OpenFunc Open; + WriteFunc Write; + ReadFunc Read; + CloseFunc Close; + ErrorFunc Error; +} RoachRoutine; + +#endif /*__ROACH_API_H__*/ diff -uprN postgresql-hll-2.14_old/include/bulkload/utils.h postgresql-hll-2.14/include/bulkload/utils.h --- postgresql-hll-2.14_old/include/bulkload/utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/utils.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,312 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * utils.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef UTILS_H_ +#define UTILS_H_ + +#ifndef WIN32 +#include "postgres.h" +#include "knl/knl_variable.h" +#endif + +#ifndef GDS_SERVER +#include "cjson/cJSON.h" +#else +#include "gds.h" +#endif + +typedef enum { + CMD_TYPE_BEGIN, // 0db->gds + CMD_TYPE_END, // 1db<->gds + CMD_TYPE_EXPLAIN, // 2not support + CMD_TYPE_RESPONSE, // 3db<-gds + CMD_TYPE_CANCEL, // 4not support + CMD_TYPE_REQ, // 5db->gds + CMD_TYPE_ERROR, // 6db<-gds + CMD_TYPE_FILE_SWITCH, // 7db<-gds + CMD_TYPE_DATA, // 8db<->gds + CMD_TYPE_QUERY_RESULT, // 9db<-gds + CMD_TYPE_REMOTELOG, // 10db->gds + CMD_TYPE_DATA_SEG, // 11indicate a segment of line, db<-gds + CMD_TYPE_QUERY_RESULT_V1, // 12update version of QR, db<-gds + CMD_TYPE_INVALID +} GDSCmdType; + +struct CmdBase { + char m_type; + + // explicit constructor + CmdBase() : m_type(0) + { + } + + virtual ~CmdBase(){}; +}; + +struct CmdData : public CmdBase { + char* m_data; + uint32 m_len; + + CmdData() : m_data(NULL), m_len(0) + { + } +}; + +struct CmdBegin : public CmdBase { + char* m_url; + uint64 m_id; + char m_format; + char m_nodeType; + char m_quote; + char m_escape; + char* m_eol; + bool m_header; + int m_nodeNum; + char* m_nodeName; + int m_fixSize; + char* m_prefix; + char* m_fileheader; + + CmdBegin() + { + m_url = NULL; + m_id = 0; + m_format = -1; + m_nodeType = 'C'; + m_quote = '"'; + m_escape = '"'; + m_eol = NULL; + m_header = false; + m_nodeNum = 0; + m_nodeName = NULL; + m_fixSize = 0; + m_prefix = NULL; + m_fileheader = NULL; + } + ~CmdBegin() + { + if (m_url) + cJSON_free(m_url); + if (m_eol) + cJSON_free(m_eol); + if (m_nodeName) + cJSON_free(m_nodeName); + if (m_prefix) + cJSON_free(m_prefix); + if (m_fileheader) + cJSON_free(m_fileheader); + } +}; + +struct CmdResponse : public CmdBase { + int m_result; + char* m_reason; + CmdResponse() : m_result(0), m_reason(NULL) + { + } + + ~CmdResponse() + { + if (m_reason) + cJSON_free(m_reason); + } +}; + +struct CmdError : public CmdBase { + char m_level; + char* m_detail; + + CmdError() : m_level(0), m_detail(NULL) + { + } + + ~CmdError() + { + if (m_detail) + cJSON_free(m_detail); + } +}; + +struct CmdRemoteLog : public CmdBase { + int m_datasize; + char* m_data; + char* m_name; + CmdRemoteLog() : m_datasize(0), m_data(NULL), m_name(NULL) + { + } + + ~CmdRemoteLog() + { + if (m_name) + cJSON_free(m_name); + } +}; + +struct CmdFileSwitch : public CmdBase { + char* m_fileName; + + CmdFileSwitch() : m_fileName(NULL) + { + } + ~CmdFileSwitch() + { + if (m_fileName) + cJSON_free(m_fileName); + } +}; + +struct CmdQueryResult : public CmdBase { + int m_result; + const char* m_version_num; + + // explicit constructor + CmdQueryResult() : m_result(0) + { + } +}; + +inline void U64ToString(uint64 in, char* out, int len) +{ +#if __WORDSIZE == 64 + int rc = snprintf_s(out, len, len - 1, "%lu", in); + securec_check_ss(rc, "\0", "\0"); +#else + int rc = snprintf_s(out, len, len - 1, "%llu", in); + securec_check_ss(rc, "\0", "\0"); +#endif +} + +#define WRITE_JSON_START(_type, obj) do { \ + cJSON *json = cJSON_CreateObject(); \ + char *print = NULL; \ + _type *tmp = obj; \ + if (json == NULL) \ +break +#define WRITE_JSON_INT(_field) cJSON_AddNumberToObject(json, #_field, tmp->_field) +#define WRITE_JSON_BOOL(_field) cJSON_AddBoolToObject(json, #_field, tmp->_field) +#define WRITE_JSON_STRING(_field) do { \ + if (tmp->_field) \ + cJSON_AddStringToObject(json, #_field, tmp->_field); \ +} while (0) + +#define WRITE_JSON_UINT64(_field) do { \ + char tmpstr[128]; \ + U64ToString(tmp->_field, tmpstr, 128); \ + cJSON_AddStringToObject(json, #_field, tmpstr); \ +} while (0) + +#define WRITE_JSON_END() \ + print = cJSON_Print(json); \ + cJSON_Delete(json); \ + return print; \ + } \ + while (0) \ + ; \ + return NULL + +#define READ_JSON_START(_type, obj, msg) do { \ + cJSON *json = cJSON_Parse(msg); \ + _type *tmp = obj; \ + cJSON *tmpObj = NULL; \ + if (json == NULL) \ +return -1 + +#define READ_JSON_INT(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = tmpObj->valueint; \ + else \ + return -1; \ + } while (0) + +#define READ_JSON_STRING(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = (char*)cJSON_strdup((const unsigned char*)tmpObj->valuestring); \ + else \ + tmp->_field = NULL; \ + } while (0) + +#define READ_JSON_BOOL(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = tmpObj->type == cJSON_True; \ + else \ + return -1; \ + } while (0) + +#define READ_JSON_UINT64(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) { \ + char* str = tmpObj->valuestring; \ + if (str) { \ + char* _end; \ + tmp->_field = strtoul(str, &_end, 10); \ + } else { \ + return -1; \ + } \ + } else { \ + return -1; \ + } \ + } while (0) + +#define READ_JSON_END() \ + cJSON_Delete(json); \ + } \ + while (0) \ + ; \ + return 0 + +typedef enum { + LEVEL_STATUS = 17, + LEVEL_LOG, + LEVEL_WARNING, + LEVEL_ERROR +} LogLevel; + +#define GDSCmdHeaderSize 5 /*length of Cmd header*/ + +typedef enum { + FORMAT_UNKNOWN, + FORMAT_BINARY, + FORMAT_CSV, + FORMAT_TEXT, + FORMAT_FIXED, + FORMAT_REMOTEWRITE +} FileFormat; + +typedef enum { + NOTIFY_CMD_ADD_SESSION, /* used to add a new session just for worker thread */ + NOTIFY_CMD_DEL_WORKLOAD, /* used to delete a work load just for main thread */ + NOTIFY_CMD_ERROR_LOG, /* used to commit all kinds of error log for main thread and worker threads */ + NOTIFY_CMD_EXIT, /* used to notify threads to exit */ + NOTIFY_CMD_UNKNOWN /* a boundary */ +} NotifyCmdType; + +#endif /* UTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/bulkload/vecforeignroutine.h postgresql-hll-2.14/include/bulkload/vecforeignroutine.h --- postgresql-hll-2.14_old/include/bulkload/vecforeignroutine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/bulkload/vecforeignroutine.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecforeignroutine.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/vecforeignroutine.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H +#define SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H +#include "nodes/execnodes.h" + +extern VectorBatch* distExecVecImport(VecForeignScanState* node); + +#endif // SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/catalog/catalog.h postgresql-hll-2.14/include/catalog/catalog.h --- postgresql-hll-2.14_old/include/catalog/catalog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/catalog.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * catalog.h + * prototypes for functions in backend/catalog/catalog.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/catalog.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATALOG_H +#define CATALOG_H + +/* + * 'pgrminclude ignore' needed here because CppAsString2() does not throw + * an error if the symbol is not defined. + */ +#include "catalog/catversion.h" /* pgrminclude ignore */ +#include "catalog/pg_class.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +#define FORKNAMECHARS 4 /* max chars for a fork name */ +#define OIDCHARS 10 /* max chars printed by %u */ +#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \ + CppAsString2(CATALOG_VERSION_NO) + +/* file name: Cxxxxx.0 + * the max length is up to MaxAttrNumber + */ +#define COLFILE_SUFFIX "C" +#define COLFILE_SUFFIX_MAXLEN 8 + +extern const char *forkNames[]; +extern ForkNumber forkname_to_number(char *forkName, BlockNumber *segno = NULL); +extern int forkname_chars(const char *str, ForkNumber *); + +extern char *relpathbackend(RelFileNode rnode, BackendId backend, ForkNumber forknum); +extern char *GetDatabasePath(Oid dbNode, Oid spcNode); +extern char* GetBucketDirPath(const RelFileNodeBackend& rel_file_node_backend); + + +/* First argument is a RelFileNodeBackend */ +#define relpath(rnode, forknum) \ + relpathbackend((rnode).node, (rnode).backend, (forknum)) + +/* First argument is a RelFileNode */ +#define relpathperm(rnode, forknum) \ + relpathbackend((rnode), InvalidBackendId, (forknum)) + +extern RelFileNodeForkNum relpath_to_filenode(char *path); + +extern bool IsSystemRelation(Relation relation); +extern bool IsToastRelation(Relation relation); +extern bool IsCatalogRelation(Relation relation); + +extern bool IsSystemClass(Form_pg_class reltuple); +extern bool IsToastClass(Form_pg_class reltuple); +extern bool IsCatalogClass(Oid relid, Form_pg_class reltuple); + +extern bool IsSystemNamespace(Oid namespaceId); +extern bool IsToastNamespace(Oid namespaceId); +extern bool IsCStoreNamespace(Oid namespaceId); + +extern bool IsPerformanceNamespace(Oid namespaceId); +extern bool IsSnapshotNamespace(Oid namespaceId); + +extern bool IsReservedName(const char *name); + +extern bool IsSharedRelation(Oid relationId); + +extern Oid GetNewOid(Relation relation); +extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); +extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence); + +#endif /* CATALOG_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/catversion.h postgresql-hll-2.14/include/catalog/catversion.h --- postgresql-hll-2.14_old/include/catalog/catversion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/catversion.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * catversion.h + * "Catalog version number" for PostgreSQL. + * + * The catalog version number is used to flag incompatible changes in + * the PostgreSQL system catalogs. Whenever anyone changes the format of + * a system catalog relation, or adds, deletes, or modifies standard + * catalog entries in such a way that an updated backend wouldn't work + * with an old database (or vice versa), the catalog version number + * should be changed. The version number stored in pg_control by initdb + * is checked against the version number compiled into the backend at + * startup time, so that a backend can refuse to run in an incompatible + * database. + * + * The point of this feature is to provide a finer grain of compatibility + * checking than is possible from looking at the major version number + * stored in PG_VERSION. It shouldn't matter to end users, but during + * development cycles we usually make quite a few incompatible changes + * to the contents of the system catalogs, and we don't want to bump the + * major version number for each one. What we can do instead is bump + * this internal version number. This should save some grief for + * developers who might otherwise waste time tracking down "bugs" that + * are really just code-vs-database incompatibilities. + * + * The rule for developers is: if you commit a change that requires + * an initdb, you should update the catalog version number (as well as + * notifying the pghackers mailing list, which has been the informal + * practice for a long time). + * + * The catalog version number is placed here since modifying files in + * include/catalog is the most common kind of initdb-forcing change. + * But it could be used to protect any kind of incompatible change in + * database contents or layout, such as altering tuple headers. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/catversion.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATVERSION_H +#define CATVERSION_H + +/* + * We could use anything we wanted for version numbers, but I recommend + * following the "YYYYMMDDN" style often used for DNS zone serial numbers. + * YYYYMMDD are the date of the change, and N is the number of the change + * on that day. (Hopefully we'll never commit ten independent sets of + * catalog changes on the same day...) + * + * yyyymmddN + * */ +#ifdef PGXC +#define CATALOG_VERSION_NO 201611171 +#else +#define CATALOG_VERSION_NO 201611171 +#endif + +#define NAILED_IN_CATALOG_NUM 8 +#define CATALOG_NUM 90 + +#endif diff -uprN postgresql-hll-2.14_old/include/catalog/cstore_ctlg.h postgresql-hll-2.14/include/catalog/cstore_ctlg.h --- postgresql-hll-2.14_old/include/catalog/cstore_ctlg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/cstore_ctlg.h 2020-12-12 17:06:43.073345793 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_ctlg.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/catalog/cstore_ctlg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_CTLG_H +#define CSTORE_CTLG_H + +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +extern void AlterCStoreCreateTables(Oid relOid, Datum reloptions, CreateStmt *mainTblStmt); + +extern bool CreateDeltaTable(Relation rel, Datum reloptions, bool isPartition, CreateStmt *mainTblStmt); +extern bool CreateCUDescTable(Relation rel, Datum reloptions, bool isPartition); +extern bool createDeltaTableForPartition(Oid relOid, Oid partOid, Datum reloptions, CreateStmt *mainTblStmt); +extern bool createCUDescTableForPartition(Oid relOid, Oid partOid, Datum reloptions); +extern Datum AddInternalOption(Datum reloptions, int mask); +extern Datum AddOrientationOption(Datum relOptions, bool isColStore); + + +#endif + diff -uprN postgresql-hll-2.14_old/include/catalog/dependency.h postgresql-hll-2.14/include/catalog/dependency.h --- postgresql-hll-2.14_old/include/catalog/dependency.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/dependency.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,367 @@ +/* ------------------------------------------------------------------------- + * + * dependency.h + * Routines to support inter-object dependencies. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/dependency.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEPENDENCY_H +#define DEPENDENCY_H + +#include "catalog/objectaddress.h" +#include "catalog/dfsstore_ctlg.h" +#include "catalog/pg_directory.h" + + +/* + * Precise semantics of a dependency relationship are specified by the + * DependencyType code (which is stored in a "char" field in pg_depend, + * so we assign ASCII-code values to the enumeration members). + * + * In all cases, a dependency relationship indicates that the referenced + * object may not be dropped without also dropping the dependent object. + * However, there are several subflavors: + * + * DEPENDENCY_NORMAL ('n'): normal relationship between separately-created + * objects. The dependent object may be dropped without affecting the + * referenced object. The referenced object may only be dropped by + * specifying CASCADE, in which case the dependent object is dropped too. + * Example: a table column has a normal dependency on its datatype. + * + * DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately + * from the referenced object, and should be automatically dropped + * (regardless of RESTRICT or CASCADE mode) if the referenced object + * is dropped. + * Example: a named constraint on a table is made auto-dependent on + * the table, so that it will go away if the table is dropped. + * + * DEPENDENCY_INTERNAL ('i'): the dependent object was created as part + * of creation of the referenced object, and is really just a part of + * its internal implementation. A DROP of the dependent object will be + * disallowed outright (we'll tell the user to issue a DROP against the + * referenced object, instead). A DROP of the referenced object will be + * propagated through to drop the dependent object whether CASCADE is + * specified or not. + * Example: a trigger that's created to enforce a foreign-key constraint + * is made internally dependent on the constraint's pg_constraint entry. + * + * DEPENDENCY_EXTENSION ('e'): the dependent object is a member of the + * extension that is the referenced object. The dependent object can be + * dropped only via DROP EXTENSION on the referenced object. Functionally + * this dependency type acts the same as an internal dependency, but it's + * kept separate for clarity and to simplify pg_dump. + * + * DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry + * is a signal that the system itself depends on the referenced object, + * and so that object must never be deleted. Entries of this type are + * created only during initdb. The fields for the dependent object + * contain zeroes. + * + * Other dependency flavors may be needed in future. + */ + +typedef enum DependencyType { + DEPENDENCY_NORMAL = 'n', + DEPENDENCY_AUTO = 'a', + DEPENDENCY_INTERNAL = 'i', + DEPENDENCY_EXTENSION = 'e', + DEPENDENCY_PIN = 'p' +} DependencyType; + +/* + * Deletion processing requires additional state for each ObjectAddress that + * it's planning to delete. For simplicity and code-sharing we make the + * ObjectAddresses code support arrays with or without this extra state. + */ +typedef struct { + int flags; /* bitmask, see bit definitions below */ + ObjectAddress dependee; /* object whose deletion forced this one */ +} ObjectAddressExtra; + +/* expansible list of ObjectAddresses */ +struct ObjectAddresses { + ObjectAddress *refs; /* => palloc'd array */ + ObjectAddressExtra *extras; /* => palloc'd array, or NULL if not used */ + int numrefs; /* current number of references */ + int maxrefs; /* current size of palloc'd array(s) */ +}; + +/* typedef ObjectAddresses appears in dependency.h */ + +/* threaded list of ObjectAddresses, for recursion detection */ +typedef struct ObjectAddressStack { + const ObjectAddress* object; /* object being visited */ + int flags; /* its current flag bits */ + struct ObjectAddressStack* next; /* next outer stack level */ +} ObjectAddressStack; + +/* for find_expr_references_walker */ +typedef struct { + ObjectAddresses* addrs; /* addresses being accumulated */ + List* rtables; /* list of rangetables to resolve Vars */ +} find_expr_references_context; + +/* + * There is also a SharedDependencyType enum type that determines the exact + * semantics of an entry in pg_shdepend. Just like regular dependency entries, + * any pg_shdepend entry means that the referenced object cannot be dropped + * unless the dependent object is dropped at the same time. There are some + * additional rules however: + * + * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object -- + * rather, the referenced object is an essential part of the system. This + * applies to the initdb-created superuser. Entries of this type are only + * created by initdb; objects in this category don't need further pg_shdepend + * entries if more objects come to depend on them. + * + * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is + * the role owning the dependent object. The referenced object must be + * a pg_authid entry. + * + * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is + * a role mentioned in the ACL field of the dependent object. The referenced + * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not + * created for the owner of an object; hence two objects may be linked by + * one or the other, but not both, of these dependency types.) + * + * (d) a SHARED_DEPENDENCY_RLSPOLICY entry means that the referenced object + * is the role mentioned in a policy object. The referenced object must be a + * pg_authid entry. + * + * (m) a SHARED_DEPENDENCY_MOT_TABLE entry means that the referenced object + * is the database holding FDW table. The dependent object must be a FDW table entry. + * + * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal + * routines, and is not valid in the catalog itself. + */ +typedef enum SharedDependencyType { + SHARED_DEPENDENCY_PIN = 'p', + SHARED_DEPENDENCY_OWNER = 'o', + SHARED_DEPENDENCY_ACL = 'a', + SHARED_DEPENDENCY_RLSPOLICY = 'r', + SHARED_DEPENDENCY_MOT_TABLE = 'm', + SHARED_DEPENDENCY_INVALID = 0 +} SharedDependencyType; + +/* expansible list of ObjectAddresses (private in dependency.c) */ +typedef struct ObjectAddresses ObjectAddresses; + +/* + * This enum covers all system catalogs whose OIDs can appear in + * pg_depend.classId or pg_shdepend.classId. + */ +typedef enum ObjectClass { + OCLASS_CLASS, /* pg_class */ + OCLASS_PROC, /* pg_proc */ + OCLASS_TYPE, /* pg_type */ + OCLASS_CAST, /* pg_cast */ + OCLASS_COLLATION, /* pg_collation */ + OCLASS_CONSTRAINT, /* pg_constraint */ + OCLASS_CONVERSION, /* pg_conversion */ + OCLASS_DEFAULT, /* pg_attrdef */ + OCLASS_LANGUAGE, /* pg_language */ + OCLASS_LARGEOBJECT, /* pg_largeobject */ + OCLASS_OPERATOR, /* pg_operator */ + OCLASS_OPCLASS, /* pg_opclass */ + OCLASS_OPFAMILY, /* pg_opfamily */ + OCLASS_AMOP, /* pg_amop */ + OCLASS_AMPROC, /* pg_amproc */ + OCLASS_REWRITE, /* pg_rewrite */ + OCLASS_TRIGGER, /* pg_trigger */ + OCLASS_SCHEMA, /* pg_namespace */ + OCLASS_TSPARSER, /* pg_ts_parser */ + OCLASS_TSDICT, /* pg_ts_dict */ + OCLASS_TSTEMPLATE, /* pg_ts_template */ + OCLASS_TSCONFIG, /* pg_ts_config */ + OCLASS_ROLE, /* pg_authid */ + OCLASS_DATABASE, /* pg_database */ + OCLASS_TBLSPACE, /* pg_tablespace */ + OCLASS_FDW, /* pg_foreign_data_wrapper */ + OCLASS_FOREIGN_SERVER, /* pg_foreign_server */ + OCLASS_USER_MAPPING, /* pg_user_mapping */ + OCLASS_SYNONYM, /* pg_synonym */ +#ifdef PGXC + OCLASS_PGXC_CLASS, /* pgxc_class */ + OCLASS_PGXC_NODE, /* pgxc_node */ + OCLASS_PGXC_GROUP, /* pgxc_group */ +#endif + OCLASS_GLOBAL_SETTING, /* global setting */ + OCLASS_COLUMN_SETTING, /* column setting */ + OCLASS_CL_CACHED_COLUMN, /* client logic cached column */ + OCLASS_GLOBAL_SETTING_ARGS, /* global setting args */ + OCLASS_COLUMN_SETTING_ARGS, /* column setting args */ + OCLASS_DEFACL, /* pg_default_acl */ + OCLASS_EXTENSION, /* pg_extension */ + OCLASS_DATA_SOURCE, /* data source */ + OCLASS_DIRECTORY, /* pg_directory */ + OCLASS_PG_JOB, /* pg_job */ + OCLASS_RLSPOLICY, /* pg_rlspolicy */ + MAX_OCLASS /* MUST BE LAST */ +} ObjectClass; + + +/* in dependency.c */ + +#define PERFORM_DELETION_INTERNAL 0x0001 +#define PERFORM_DELETION_CONCURRENTLY 0x0002 + +/* ObjectAddressExtra flag bits */ +#define DEPFLAG_ORIGINAL 0x0001 /* an original deletion target */ +#define DEPFLAG_NORMAL 0x0002 /* reached via normal dependency */ +#define DEPFLAG_AUTO 0x0004 /* reached via auto dependency */ +#define DEPFLAG_INTERNAL 0x0008 /* reached via internal dependency */ +#define DEPFLAG_EXTENSION 0x0010 /* reached via extension dependency */ +#define DEPFLAG_REVERSE 0x0020 /* reverse internal/extension link */ + + +extern void performDeletion(const ObjectAddress *object, + DropBehavior behavior, + int flags); + +extern void performMultipleDeletions(const ObjectAddresses *objects, + DropBehavior behavior, + uint32 flags); + +extern void deleteWhatDependsOn(const ObjectAddress *object, + bool showNotices); + +extern void recordDependencyOnExpr(const ObjectAddress *depender, + Node *expr, + List *rtable, + DependencyType behavior); + +extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, + Node *expr, + Oid relId, + DependencyType behavior, + DependencyType self_behavior); + +extern ObjectClass getObjectClass(const ObjectAddress *object); + +extern char *getObjectDescription(const ObjectAddress *object); +extern char *getObjectDescriptionOids(Oid classid, Oid objid); + +extern ObjectAddresses *new_object_addresses(const int maxRefs = 32); + +extern void add_exact_object_address(const ObjectAddress *object, + ObjectAddresses *addrs); + +extern bool object_address_present(const ObjectAddress *object, + const ObjectAddresses *addrs); + +extern void record_object_address_dependencies(const ObjectAddress *depender, + ObjectAddresses *referenced, + DependencyType behavior); + +extern void free_object_addresses(ObjectAddresses *addrs); + +/* in pg_depend.c */ +extern void recordDependencyOn(const ObjectAddress *depender, + const ObjectAddress *referenced, + DependencyType behavior); + +extern void recordMultipleDependencies(const ObjectAddress *depender, + const ObjectAddress *referenced, + int nreferenced, + DependencyType behavior); + +extern void recordDependencyOnCurrentExtension(const ObjectAddress *object, + bool isReplace); + +extern void recordPinnedDependency(const ObjectAddress *object); + +extern long deleteDependencyRecordsFor(Oid classId, + Oid objectId, + bool skipExtensionDeps); + +extern long deleteDependencyRecordsForClass(Oid classId, + Oid objectId, + Oid refclassId, + char deptype); + +extern long changeDependencyFor(Oid classId, + Oid objectId, + Oid refClassId, + Oid oldRefObjectId, + Oid newRefObjectId); + +extern Oid getExtensionOfObject(Oid classId, Oid objectId); + +extern bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId); + +extern void markSequenceUnowned(Oid seqId); + +extern List *getOwnedSequences(Oid relid, List *attrList = NULL); + +extern Oid get_constraint_index(Oid constraintId); + +extern Oid get_index_constraint(Oid indexId); + +/* in pg_shdepend.c */ +extern void recordSharedDependencyOn(ObjectAddress *depender, + ObjectAddress *referenced, + SharedDependencyType deptype, + const char *objfile = NULL); + +extern void deleteSharedDependencyRecordsFor(Oid classId, + Oid objectId, + int32 objectSubId); + +extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner, const char *objfile = NULL); +#ifdef ENABLE_MOT +extern void recordDependencyOnDatabase(Oid classId, Oid objectId, Oid serverId, Oid owner, const char *objfile = NULL); +#endif + +extern void changeDependencyOnOwner(Oid classId, + Oid objectId, + Oid newOwnerId); + +extern void updateAclDependencies(Oid classId, + Oid objectId, + int32 objectSubId, + Oid ownerId, + int noldmembers, + Oid *oldmembers, + int nnewmembers, + Oid *newmembers); + +extern bool checkSharedDependencies(Oid classId, + Oid objectId, + char **detail_msg, + char **detail_log_msg); + +extern void shdepLockAndCheckObject(Oid classId, Oid objectId); + +extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId); + +extern void dropDatabaseDependencies(Oid databaseId); + +extern void shdepDropOwned(List *relids, DropBehavior behavior); + +extern void shdepReassignOwned(List *relids, Oid newrole); + +extern bool TSConfigurationHasDependentObjects(Oid tsconfoid); + +extern void recordDependencyOnRespool(Oid classId, Oid objectId, Oid owner); + +extern bool CheckDependencyOnRespool(Oid classId, Oid objectId, List **foundlist, bool full); +extern void changeDependencyOnRespool(Oid classId, Oid objectId, Oid newOwnerId); +extern void prepareDatabaseCFunLibrary(Oid databaseId); + +extern void deleteDictionaryTSFile(Oid dictId); +extern void deleteDatabaseTSFile(Oid databaseId); +extern void changeDependencyOnObjfile(Oid objectId, Oid refobjId, const char *newObjfile); + +#ifdef ENABLE_MULTIPLE_NODES +namespace Tsdb { +extern void performTsCudescDeletion(List* cudesc_oids); +} +#endif /* ENABLE_MULTIPLE_NODES */ +#endif /* DEPENDENCY_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/dfsstore_ctlg.h postgresql-hll-2.14/include/catalog/dfsstore_ctlg.h --- postgresql-hll-2.14_old/include/catalog/dfsstore_ctlg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/dfsstore_ctlg.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfsstore_ctlg.h + * routines to support HdfsStore + * + * + * IDENTIFICATION + * src/include/catalog/dfsstore_ctlg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFSSTORE_CTLG_H +#define DFSSTORE_CTLG_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/objectaddress.h" +#include "lib/stringinfo.h" +#include "utils/relcache.h" +#include "storage/block.h" +#include "storage/dfs/dfs_connector.h" + + +/* + * DropDfsTblInfo holds the some information when drop + * a Dfs table. + */ +typedef struct DropDfsTblInfo { + DfsSrvOptions *srvOptions; + StringInfo dfsTblPath; + Oid tblSpaceOid; +}DropDfsTblInfo; + + +void createDfsDescTable(Relation rel, Datum reloptions); +StringInfo getDfsStorePath(Relation rel); +extern Oid getDfsDescTblOid(Oid mainTblOid); +extern Oid getDfsDescIndexOid(Oid mainTblOid); +extern List* getDataFiles(Oid tbloid); +extern void InsertDeletedFilesForTransaction(Relation dataDestRelation); +extern int64 getDFSRelSize(Relation rel); +extern StringInfo getHDFSTblSpcStorePath(Oid tblSpcOid); + +#endif diff -uprN postgresql-hll-2.14_old/include/catalog/duplicate_oids postgresql-hll-2.14/include/catalog/duplicate_oids --- postgresql-hll-2.14_old/include/catalog/duplicate_oids 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/duplicate_oids 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,30 @@ +#!/bin/sh +# +# duplicate_oids +# +# src/include/catalog/duplicate_oids +# +# finds manually-assigned oids that are duplicated in the system tables. +# +# run this script in src/include/catalog. +# + +# note: we exclude BKI_BOOTSTRAP relations since they are expected to have +# matching DATA lines in pg_class.h and pg_type.h + +cat pgxc_*.h pg_*.h toasting.h indexing.h | \ +egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \ +sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \ +tr ',' '\n' | \ +sort -n | \ +uniq -d | \ +grep '.' + +# nonzero exit code if lines were produced +[ $? -eq 1 ] +exit diff -uprN postgresql-hll-2.14_old/include/catalog/genbki.h postgresql-hll-2.14/include/catalog/genbki.h --- postgresql-hll-2.14_old/include/catalog/genbki.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/genbki.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,52 @@ +/* ------------------------------------------------------------------------- + * + * genbki.h + * Required include file for all POSTGRES catalog header files + * + * genbki.h defines CATALOG(), DATA(), BKI_BOOTSTRAP and related macros + * so that the catalog header files can be read by the C compiler. + * (These same words are recognized by genbki.pl to build the BKI + * bootstrap file from these header files.) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/genbki.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GENBKI_H +#define GENBKI_H + +/* Introduces a catalog's structure definition */ +#define CATALOG(name,oid) typedef struct CppConcat(FormData_,name) + +/* + * This is never defined; it's here only for documentation. + * + * Variable-length catalog fields (except possibly the first not nullable one) + * should not be visible in C structures, so they are made invisible by #ifdefs + * of an undefined symbol. See also MARKNOTNULL in bootstrap.c for how this is + * handled. + */ +#undef CATALOG_VARLEN + +/* Options that may appear after CATALOG (on the same line) */ +#define BKI_BOOTSTRAP +#define BKI_SHARED_RELATION +#define BKI_WITHOUT_OIDS +#define BKI_ROWTYPE_OID(oid) +#define BKI_SCHEMA_MACRO + +/* Declarations that provide the initial content of a catalog */ +/* In C, these need to expand into some harmless, repeatable declaration */ +#define DATA(x) extern int no_such_variable +#define DESCR(x) extern int no_such_variable +#define SHDESCR(x) extern int no_such_variable + +/* PHONY type definitions for use in catalog structure definitions only */ +typedef int aclitem; +typedef int pg_node_tree; + +#endif /* GENBKI_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/gs_asp.h postgresql-hll-2.14/include/catalog/gs_asp.h --- postgresql-hll-2.14_old/include/catalog/gs_asp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_asp.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,97 @@ +#ifndef PG_ASP_H +#define PG_ASP_H + +#include "postgres.h" +#include "utils/inet.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" +#include "utils/date.h" + +#define timestamptz Datum +#define int8 int64 + +/*------------------------------------------------------------------------- + * gs_asp definition. cpp turns this into + * typedef struct GsAspRelation_Rowtype_Id + *------------------------------------------------------------------------- + * */ +#define GsAspRelationId 9534 +#define GsAspRelation_Rowtype_Id 3465 + +CATALOG(gs_asp,9534) BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(3465) BKI_SCHEMA_MACRO +{ + int8 sampleid; + timestamptz sample_time; + bool need_flush_sample; + Oid databaseid; + int8 thread_id; + int8 sessionid; + timestamptz start_time; +#ifdef CATALOG_VARLEN /* Null value constrain */ + text event; + int4 lwtid; + int8 psessionid; + int4 tlevel; + int4 smpid; + Oid userid; + text application_name; + inet client_addr; + text client_hostname; + int4 client_port; + int8 query_id; + int8 unique_query_id; + Oid user_id; + int4 cn_id; + text unique_query; + text locktag; + text lockmode; + int8 block_sessionid; + text wait_status; +#endif +} FormData_gs_asp; + +#undef timestamp +#undef int8 + +/*------------------------------------------------------------------------- + * FormData_gs_asp corresponds to a pointer to a tuple with + * the format of gs_asp relation. + *------------------------------------------------------------------------- + * */ +typedef FormData_gs_asp* Form_gs_asp; + +/*------------------------------------------------------------------------- + * compiler constants for gs_asp + *------------------------------------------------------------------------- + */ +#define Natts_gs_asp 26 +#define Anum_gs_asp_sample_id 1 +#define Anum_gs_asp_sample_time 2 +#define Anum_gs_asp_need_flush_sample 3 +#define Anum_gs_asp_databaseid 4 +#define Anum_gs_asp_tid 5 +#define Anum_gs_asp_sessionid 6 +#define Anum_gs_asp_start_time 7 +#define Anum_gs_asp_event 8 +#define Anum_gs_asp_lwtid 9 +#define Anum_gs_asp_psessionid 10 +#define Anum_gs_asp_tlevel 11 +#define Anum_gs_asp_smpid 12 +#define Anum_gs_asp_useid 13 +#define Anum_gs_asp_application_name 14 +#define Anum_gs_asp_client_addr 15 +#define Anum_gs_asp_client_hostname 16 +#define Anum_gs_asp_client_port 17 +#define Anum_gs_asp_query_id 18 +#define Anum_gs_asp_unique_query_id 19 +#define Anum_gs_asp_user_id 20 +#define Anum_gs_asp_cn_id 21 +#define Anum_gs_asp_unique_query 22 +#define Anum_gs_asp_locktag 23 +#define Anum_gs_asp_lockmode 24 +#define Anum_gs_asp_block_sessionid 25 +#define Anum_gs_asp_wait_status 26 + +#endif /* GS_ASP */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_acc.h postgresql-hll-2.14/include/catalog/gs_auditing_policy_acc.h --- postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_acc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_auditing_policy_acc.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_acc.h + * Definition about access catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_acc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_ACC_H +#define GS_AUDITING_POLICY_ACC_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyAccessRelationId 9520 +#define GsAuditingPolicyAccessRelationId_Rowtype_Id 9523 + +CATALOG(gs_auditing_policy_access,9520) BKI_SCHEMA_MACRO +{ + NameData accesstype; + NameData labelname; + Oid policyoid; + timestamp modifydate; +} FormData_gs_auditing_policy_access; + +typedef FormData_gs_auditing_policy_access *Form_gs_auditing_policy_access; + +#define Natts_gs_auditing_policy_acc 4 + +#define Anum_gs_auditing_policy_acc_type 1 +#define Anum_gs_auditing_policy_acc_label_name 2 +#define Anum_gs_auditing_policy_acc_policy_oid 3 +#define Anum_gs_auditing_policy_acc_modify_date 4 + +#endif /* GS_AUDITING_POLICY_ACC_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_filter.h postgresql-hll-2.14/include/catalog/gs_auditing_policy_filter.h --- postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_filter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_auditing_policy_filter.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Definition about filter catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_filter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_FILTER_H +#define GS_AUDITING_POLICY_FILTER_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyFiltersRelationId 9540 +#define GsAuditingPolicyFiltersRelationId_Rowtype_Id 9543 + +CATALOG(gs_auditing_policy_filters,9540) BKI_SCHEMA_MACRO +{ + NameData filtertype; + NameData labelname; + Oid policyoid; + timestamp modifydate; + text logicaloperator; +} FormData_gs_auditing_policy_filters; + +typedef FormData_gs_auditing_policy_filters *Form_gs_auditing_policy_filters; + +#define Natts_gs_auditing_policy_filters 5 + +#define Anum_gs_auditing_policy_fltr_filter_type 1 +#define Anum_gs_auditing_policy_fltr_label_name 2 +#define Anum_gs_auditing_policy_fltr_policy_oid 3 +#define Anum_gs_auditing_policy_fltr_modify_date 4 +#define Anum_gs_auditing_policy_fltr_logical_operator 5 + +#endif /* GS_AUDITING_POLICY_FILTER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_auditing_policy.h postgresql-hll-2.14/include/catalog/gs_auditing_policy.h --- postgresql-hll-2.14_old/include/catalog/gs_auditing_policy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_auditing_policy.h 2020-12-12 17:06:43.074345806 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy.h + * Definition of gs_auditing_policy catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_H +#define GS_AUDITING_POLICY_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyRelationId 9510 +#define GsAuditingPolicyRelationId_Rowtype_Id 9513 + +CATALOG(gs_auditing_policy,9510) BKI_SCHEMA_MACRO +{ + NameData polname; + NameData polcomments; + timestamp modifydate; + bool polenabled; +} FormData_gs_auditing_policy; + +typedef FormData_gs_auditing_policy *Form_gs_auditing_policy; + +#define Natts_gs_auditing_policy 4 + +#define Anum_gs_auditing_policy_pol_name 1 +#define Anum_gs_auditing_policy_pol_comments 2 +#define Anum_gs_auditing_policy_pol_modify_date 3 +#define Anum_gs_auditing_policy_pol_enabled 4 + + +#endif /* GS_AUDITING_POLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_priv.h postgresql-hll-2.14/include/catalog/gs_auditing_policy_priv.h --- postgresql-hll-2.14_old/include/catalog/gs_auditing_policy_priv.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_auditing_policy_priv.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Definition about privileges(DML) catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_priv.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_PRIV_H +#define GS_AUDITING_POLICY_PRIV_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyPrivilegesRelationId 9530 +#define GsAuditingPolicyPrivilegesRelationId_Rowtype_Id 9533 + +CATALOG(gs_auditing_policy_privileges,9530) BKI_SCHEMA_MACRO +{ + NameData privilegetype; + NameData labelname; + Oid policyoid; + timestamp modifydate; +} FormData_gs_auditing_policy_privileges; + +typedef FormData_gs_auditing_policy_privileges *Form_gs_auditing_policy_privileges; + +#define Natts_gs_auditing_policy_priv 4 + +#define Anum_gs_auditing_policy_priv_type 1 +#define Anum_gs_auditing_policy_priv_label_name 2 +#define Anum_gs_auditing_policy_priv_policy_oid 3 +#define Anum_gs_auditing_policy_priv_modify_date 4 + +#endif /* GS_AUDITING_POLICY_PRIV_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_client_global_keys_args.h postgresql-hll-2.14/include/catalog/gs_client_global_keys_args.h --- postgresql-hll-2.14_old/include/catalog/gs_client_global_keys_args.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_client_global_keys_args.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_client_global_keys_args.h + * + * IDENTIFICATION + * src\include\catalog\gs_client_global_keys_args.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include "catalog/genbki.h" + +#define ClientLogicGlobalSettingsArgsId 9730 +#define ClientLogicGlobalSettingsArgsId_Rowtype_Id 9730 +CATALOG(gs_client_global_keys_args,9730) BKI_SCHEMA_MACRO +{ + Oid global_key_id; /* ID of the master client key that was used to encrypt the columd encryption key. (foreign key) */ + NameData function_name; + NameData key; + bytea value; +} FormData_gs_client_global_keys_args; + +typedef FormData_gs_client_global_keys_args *Form_gs_client_global_keys_args; + +#define Natts_gs_client_global_keys_args 4 +#define Anum_gs_client_global_keys_args_global_key_id 1 +#define Anum_gs_client_global_keys_args_function_name 2 +#define Anum_gs_client_global_keys_args_key 3 +#define Anum_gs_client_global_keys_args_value 4 + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_client_global_keys.h postgresql-hll-2.14/include/catalog/gs_client_global_keys.h --- postgresql-hll-2.14_old/include/catalog/gs_client_global_keys.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_client_global_keys.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_client_global_keys.h + * + * IDENTIFICATION + * src\include\catalog\gs_client_global_keys.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include "catalog/genbki.h" + + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicGlobalSettingsId 9710 +#define ClientLogicGlobalSettingsId_Rowtype_Id 9713 +CATALOG(gs_client_global_keys,9710) BKI_SCHEMA_MACRO +{ + NameData global_key_name; /* An alias for client encrypyion key */ + Oid key_namespace; + Oid key_owner; +#ifdef CATALOG_VARLEN + aclitem key_acl[1]; +#endif + timestamp create_date; +} FormData_gs_client_global_keys; + +typedef FormData_gs_client_global_keys *Form_gs_client_global_keys; + +#define Natts_gs_client_global_keys 5 +#define Anum_gs_client_global_keys_global_key_name 1 +#define Anum_gs_client_global_keys_key_namespace 2 +#define Anum_gs_client_global_keys_key_owner 3 +#define Anum_gs_client_global_keys_key_acl 4 +#define Anum_gs_client_global_keys_create_date 5 + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_column_keys_args.h postgresql-hll-2.14/include/catalog/gs_column_keys_args.h --- postgresql-hll-2.14_old/include/catalog/gs_column_keys_args.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_column_keys_args.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_column_keys_args.h + * + * IDENTIFICATION + * src\include\catalog\gs_column_keys_args.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include "catalog/genbki.h" + +#define ClientLogicColumnSettingsArgsId 9740 +#define ClientLogicColumnSettingsArgsId_Rowtype_Id 9743 +CATALOG(gs_column_keys_args,9740) BKI_SCHEMA_MACRO +{ + Oid column_key_id; + NameData function_name; + NameData key; + bytea value; +} FormData_gs_column_keys_args; + +typedef FormData_gs_column_keys_args *Form_gs_column_keys_args; + +#define Natts_gs_column_keys_args 4 +#define Anum_gs_column_keys_args_column_key_id 1 +#define Anum_gs_column_keys_args_function_name 2 +#define Anum_gs_column_keys_args_key 3 +#define Anum_gs_column_keys_args_value 4 + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_column_keys.h postgresql-hll-2.14/include/catalog/gs_column_keys.h --- postgresql-hll-2.14_old/include/catalog/gs_column_keys.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_column_keys.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_column_keys.h + * + * IDENTIFICATION + * src\include\catalog\gs_column_keys.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include "catalog/genbki.h" +#include "utils/timestamp.h" + + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicColumnSettingsId 9720 +#define ClientLogicColumnSettingsId_Rowtype_Id 9724 + +CATALOG(gs_column_keys,9720) BKI_SCHEMA_MACRO +{ + NameData column_key_name; /* An alias for column encrypyion key */ + Oid column_key_distributed_id; /* id created from hasing fqdn */ + Oid global_key_id; /* ID of the client encryption key that was used to encrypt the columd encryption key. (foreign key) */ + Oid key_namespace; + Oid key_owner; + timestamp create_date; +#ifdef CATALOG_VARLEN + aclitem key_acl[1]; /* access permissions */ +#endif +} FormData_gs_column_keys; + +typedef FormData_gs_column_keys *Form_gs_column_keys; + +#define Natts_gs_column_keys 7 + +#define Anum_gs_column_keys_column_key_name 1 // do not change this number without changing on encryptionkeys.cpp +#define Anum_gs_column_keys_column_key_distributed_id 2 +#define Anum_gs_column_keys_global_key_id 3 +#define Anum_gs_column_keys_key_namespace 4 +#define Anum_gs_column_keys_key_owner 5 +#define Anum_gs_column_keys_create_date 6 +#define Anum_gs_column_keys_key_acl 7 + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_encrypted_columns.h postgresql-hll-2.14/include/catalog/gs_encrypted_columns.h --- postgresql-hll-2.14_old/include/catalog/gs_encrypted_columns.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_encrypted_columns.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_encrypted_columns.h + * + * IDENTIFICATION + * src\include\catalog\gs_encrypted_columns.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_CL_CACHED_COLUMNS_H +#define GS_CL_CACHED_COLUMNS_H + +#include "catalog/genbki.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicCachedColumnsId 9700 +#define ClientLogicCachedColumnsId_Rowtype_Id 9703 +CATALOG(gs_encrypted_columns,9700) BKI_SCHEMA_MACRO +{ + Oid rel_id; + NameData column_name; + Oid column_key_id; + int1 encryption_type; + Oid data_type_original_oid; + int4 data_type_original_mod; + timestamp create_date; +} FormData_gs_encrypted_columns; + +typedef FormData_gs_encrypted_columns *Form_gs_encrypted_columns; + +#define Natts_gs_encrypted_columns 7 + +#define Anum_gs_encrypted_columns_rel_id 1 +#define Anum_gs_encrypted_columns_column_name 2 +#define Anum_gs_encrypted_columns_column_key_id 3 +#define Anum_gs_sec_encrypted_columns_encryption_type 4 +#define Anum_gs_encrypted_columns_data_type_original_oid 5 +#define Anum_gs_encrypted_columns_data_type_original_mod 6 +#define Anum_gs_encrypted_columns_create_date 7 + +#endif /* GS_CL_CACHED_COLUMNS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_global_config.h postgresql-hll-2.14/include/catalog/gs_global_config.h --- postgresql-hll-2.14_old/include/catalog/gs_global_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_global_config.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,43 @@ +/*------------------------------------------------------------------------- + * + * gs_global_config.h + * definition of the system global configuration parameters + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/gs_global_config.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + *------------------------------------------------------------------------- + */ +#ifndef GS_GLOBAL_CONFIG_H +#define GS_GLOBAL_CONFIG_H + +#include "catalog/genbki.h" + +#define GsGlobalConfigRelationId 9080 +#define GsGlobalConfigRelationId_Rowtype_Id 9081 + +CATALOG(gs_global_config,9080) BKI_SHARED_RELATION BKI_SCHEMA_MACRO BKI_WITHOUT_OIDS +{ + NameData name; /* Configure name */ + +#ifdef CATALOG_VARLEN + text value; /* Configure value */ +#endif +} FormData_gs_global_config; + +typedef FormData_gs_global_config *Form_gs_global_config; + +#define Natts_gs_global_config 2 + +#define Anum_gs_global_config_name 1 +#define Anum_gs_global_config_value 2 + +#endif /* GS_GLOBAL_CONFIG_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/gs_masking_policy_actions.h postgresql-hll-2.14/include/catalog/gs_masking_policy_actions.h --- postgresql-hll-2.14_old/include/catalog/gs_masking_policy_actions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_masking_policy_actions.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy_actions.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy_actions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_ACTIONS_H +#define GS_MASKING_POLICY_ACTIONS_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyActionsId 9650 +#define GsMaskingPolicyActionsId_Rowtype_Id 9654 + +CATALOG(gs_masking_policy_actions,9650) BKI_SCHEMA_MACRO +{ + NameData actiontype; + NameData actparams; + NameData actlabelname; + Oid policyoid; + timestamp actmodifydate; +} FormData_gs_masking_policy_actions; + +typedef FormData_gs_masking_policy_actions *Form_gs_masking_policy_actions; + +#define Natts_gs_masking_policy_actions 5 + +#define Anum_gs_masking_policy_act_action_type 1 +#define Anum_gs_masking_policy_act_action_params 2 +#define Anum_gs_masking_policy_act_label_name 3 +#define Anum_gs_masking_policy_act_policy_oid 4 +#define Anum_gs_masking_policy_act_modify_date 5 + + +#endif /* GS_MASKING_POLICY_ACTIONS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_masking_policy_filters.h postgresql-hll-2.14/include/catalog/gs_masking_policy_filters.h --- postgresql-hll-2.14_old/include/catalog/gs_masking_policy_filters.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_masking_policy_filters.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy_filter.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy_filter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_FILTER_H +#define GS_MASKING_POLICY_FILTER_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyFiltersId 9640 +#define GsMaskingPolicyFiltersId_Rowtype_Id 9643 + +CATALOG(gs_masking_policy_filters,9640) BKI_SCHEMA_MACRO +{ + NameData filtertype; + NameData filterlabelname; + Oid policyoid; + timestamp modifydate; +#ifdef CATALOG_VARLEN + text logicaloperator; +#endif +} FormData_gs_masking_policy_filters; + +typedef FormData_gs_masking_policy_filters *Form_gs_masking_policy_filters; + +#define Natts_gs_masking_policy_filters 5 + +#define Anum_gs_masking_policy_fltr_filter_type 1 +#define Anum_gs_masking_policy_fltr_label_name 2 +#define Anum_gs_masking_policy_fltr_policy_oid 3 +#define Anum_gs_masking_policy_fltr_modify_date 4 +#define Anum_gs_masking_policy_fltr_logical_operator 5 + + +#endif /* GS_MASKING_POLICY_FILTER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_masking_policy.h postgresql-hll-2.14/include/catalog/gs_masking_policy.h --- postgresql-hll-2.14_old/include/catalog/gs_masking_policy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_masking_policy.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_H +#define GS_MASKING_POLICY_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyRelationId 9610 +#define GsMaskingPolicyRelationId_Rowtype_Id 9613 + +CATALOG(gs_masking_policy,9610) BKI_SCHEMA_MACRO +{ + NameData polname; + NameData polcomments; + timestamp modifydate; + bool polenabled; +} FormData_gs_masking_policy; + +typedef FormData_gs_masking_policy *Form_gs_masking_policy; + +#define Natts_gs_masking_policy 4 + +#define Anum_gs_masking_policy_pol_name 1 +#define Anum_gs_masking_policy_pol_comments 2 +#define Anum_gs_masking_policy_pol_modify_date 3 +#define Anum_gs_masking_policy_pol_enabled 4 + + +#endif /* GS_MASKING_POLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/gs_matview_dependency.h postgresql-hll-2.14/include/catalog/gs_matview_dependency.h --- postgresql-hll-2.14_old/include/catalog/gs_matview_dependency.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_matview_dependency.h 2020-12-12 17:06:43.075345819 +0800 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * --------------------------------------------------------------------------------------- + * + * gs_matview_dependency.h + * Definition about catalog of matviews dependency + * + * + * IDENTIFICATION + * src/include/catalog/gs_matview_dependency.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_MATVIEW_DEPENDENCY_H +#define GS_MATVIEW_DEPENDENCY_H + +#include "catalog/genbki.h" +#include "c.h" + +#define MatviewDependencyId 9985 +#define MatviewDependencyId_Rowtype_Id 9987 + +CATALOG(gs_matview_dependency,9985) BKI_SCHEMA_MACRO +{ + Oid matviewid; + Oid relid; + Oid mlogid; + int4 mxmin; +} FormData_gs_matview_dependency; + +typedef FormData_gs_matview_dependency *Form_gs_matview_dependency; + +#define Natts_gs_matview_dependency 4 + +#define Anum_gs_matview_dep_matviewid 1 +#define Anum_gs_matview_dep_relid 2 +#define Anum_gs_matview_dep_mlogid 3 +#define Anum_gs_matview_dep_mxmin 4 + + +#endif /* GS_MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/gs_matview.h postgresql-hll-2.14/include/catalog/gs_matview.h --- postgresql-hll-2.14_old/include/catalog/gs_matview.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_matview.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * --------------------------------------------------------------------------------------- + * + * gs_matview.h + * Definition about catalog of matviews. + * + * + * IDENTIFICATION + * src/include/catalog/gs_matview.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_MATVIEW_H +#define GS_MATVIEW_H + +#include "catalog/genbki.h" +#include "nodes/parsenodes.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define MatviewRelationId 9982 +#define MatviewRelationId_Rowtype_Id 9984 + +typedef enum { + MATVIEW_NOT = 0, /* Not a matview related table */ + MATVIEW_MAP, /* Matviewmap table */ + MATVIEW_LOG /* Mlog table */ +} MvRelationType; + +CATALOG(gs_matview,9982) BKI_SCHEMA_MACRO +{ + Oid matviewid; + Oid mapid; + bool ivm; + bool needrefresh; + timestamp refreshtime; +} FormData_gs_matview; + +typedef FormData_gs_matview *Form_gs_matview; + +#define Natts_gs_matview 5 + +#define Anum_gs_matview_matviewid 1 +#define Anum_gs_matview_mapid 2 +#define Anum_gs_matview_ivm 3 +#define Anum_gs_matview_needrefresh 4 +#define Anum_gs_matview_refreshtime 5 + +extern void create_matview_tuple(Oid matviewOid, Oid mapid, bool isIncremental); +extern void update_matview_tuple(Oid matviewOid, bool needrefresh, Datum curtime); +extern void delete_matview_tuple(Oid matviewOid); + +extern void insert_matviewdep_tuple(Oid matviewOid, Oid relid, Oid mlogid); +extern void delete_matviewdep_tuple(Oid matviewOid); +extern void delete_matdep_table(Oid mlogid); + +extern Datum get_matview_refreshtime(Oid matviewOid, bool *isNUll); +extern Datum get_matview_mapid(Oid matviewOid); +extern bool is_incremental_matview(Oid oid); +extern bool IsMatviewRelationbyOid(Oid relOid, MvRelationType *matviewRelationType); +extern Oid MatviewRelationGetBaseid(Oid relOid, MvRelationType matviewRelationType); +extern Query *get_matview_query(Relation matviewRel); +extern void CheckRefreshMatview(RefreshMatViewStmt *stmt); +extern bool CheckPermissionForBasetable(Oid relid); + +#endif /* GS_MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/gs_obsscaninfo.h postgresql-hll-2.14/include/catalog/gs_obsscaninfo.h --- postgresql-hll-2.14_old/include/catalog/gs_obsscaninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_obsscaninfo.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_obsscaninfo.h + * definition of the system "obsscaninfo" relation (gs_obsscaninfo) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/gs_obsscaninfo.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GS_OBSSCANINFO_H +#define GS_OBSSCANINFO_H + +#include "catalog/genbki.h" + +/* ---------------- + * gs_obsscaninfo definition.cpp turns this into + * typedef struct FormData_gs_obsscaninfo + * ---------------- + */ +#define timestamptz Datum +#define GSObsScanInfoRelationId 5680 +#define GSObsScanInfoRelation_Rowtype_Id 11661 + +CATALOG(gs_obsscaninfo,5680) BKI_SHARED_RELATION BKI_WITHOUT_OIDS +{ + /* These fields form the unique key for the entry: */ + int8 query_id; +#ifdef CATALOG_VARLEN + text user_id; + text table_name; + text file_type; +#endif + timestamptz time_stamp; + float8 actual_time; + int8 file_scanned; + float8 data_size; +#ifdef CATALOG_VARLEN + text billing_info; +#endif +} FormData_gs_obsscaninfo; + +#undef timestamptz + +/* ---------------- + * Form_gs_obsscaninfo corresponds to a pointer to a tuple with + * the format of gs_obsscaninfo relation. + * ---------------- + */ +typedef FormData_gs_obsscaninfo *Form_gs_obsscaninfo; + +/* ---------------- + * compiler constants for gs_obsscaninfo + * ---------------- + */ +#define Natts_gs_obsscaninfo 9 +#define Anum_gs_obsscaninfo_query_id 1 +#define Anum_gs_obsscaninfo_user_id 2 +#define Anum_gs_obsscaninfo_table_name 3 +#define Anum_gs_obsscaninfo_file_type 4 +#define Anum_gs_obsscaninfo_time_stamp 5 +#define Anum_gs_obsscaninfo_actual_time 6 +#define Anum_gs_obsscaninfo_file_scanned 7 +#define Anum_gs_obsscaninfo_data_size 8 +#define Anum_gs_obsscaninfo_billing_info 9 + +#endif /* GS_OBSSCANINFO_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/gs_policy_label.h postgresql-hll-2.14/include/catalog/gs_policy_label.h --- postgresql-hll-2.14_old/include/catalog/gs_policy_label.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/gs_policy_label.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_policy_label.h + * + * IDENTIFICATION + * src/include/catalog/gs_policy_label.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_LABEL_H +#define GS_POLICY_LABEL_H + +#include "postgres.h" +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsPolicyLabelRelationId 9500 +#define GsPolicyLabelRelationId_Rowtype_Id 9503 + +CATALOG(gs_policy_label,9500) BKI_SCHEMA_MACRO +{ + NameData labelname; + NameData labeltype; /* resource label */ + Oid fqdnnamespace; /* namespace oid */ + Oid fqdnid; /* relation oid */ + NameData relcolumn; /* column name */ + NameData fqdntype; /* schema, table, column, view etc. */ +} FormData_gs_policy_label; + +typedef FormData_gs_policy_label *Form_gs_policy_label; + +#define Natts_gs_policy_label 6 + +#define Anum_gs_policy_label_labelname 1 +#define Anum_gs_policy_label_labeltype 2 +#define Anum_gs_policy_label_fqdnnamespace 3 +#define Anum_gs_policy_label_fqdnid 4 +#define Anum_gs_policy_label_relcolumn 5 +#define Anum_gs_policy_label_fqdntype 6 + +#endif /* GS_POLICY_LABEL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/catalog/heap.h postgresql-hll-2.14/include/catalog/heap.h --- postgresql-hll-2.14_old/include/catalog/heap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/heap.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,216 @@ +/* ------------------------------------------------------------------------- + * + * heap.h + * prototypes for functions in backend/catalog/heap.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/heap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HEAP_H +#define HEAP_H + +#include "parser/parse_node.h" +#include "catalog/indexing.h" +#include "utils/partcache.h" + +#define PSORT_RESERVE_COLUMN "tid" +#define CHCHK_PSORT_RESERVE_COLUMN(attname) (strcmp(PSORT_RESERVE_COLUMN, (attname)) == 0) + +typedef struct RawColumnDefault { + AttrNumber attnum; /* attribute to attach default to */ + Node *raw_default; /* default value (untransformed parse tree) */ +} RawColumnDefault; + +typedef struct CookedConstraint { + ConstrType contype; /* CONSTR_DEFAULT or CONSTR_CHECK */ + char *name; /* name, or NULL if none */ + AttrNumber attnum; /* which attr (only for DEFAULT) */ + Node *expr; /* transformed default or check expr */ + bool skip_validation; /* skip validation? (only for CHECK) */ + bool is_local; /* constraint has local (non-inherited) def */ + int inhcount; /* number of times constraint is inherited */ + bool is_no_inherit; /* constraint has local def and cannot be + * inherited */ +} CookedConstraint; + +typedef struct CeHeapInfo { + int8 alg_type; /* int representation of encryption type RANDOMIZED/DETERMINISTIC */ + Oid orig_typ; + int32 orig_mod; + Oid cek_id; + NameData column_name; + int4 attnum; +} CeHeapInfo; + +typedef struct HashBucketInfo { + oidvector *bucketlist; + int2vector *bucketcol; + Oid bucketOid; +} HashBucketInfo; + +extern Relation heap_create(const char *relname, + Oid relnamespace, + Oid reltablespace, + Oid relid, + Oid relfilenode, + Oid bucketOid, + TupleDesc tupDesc, + char relkind, + char relpersistence, + bool partitioned_relation, + bool rowMovement, + bool shared_relation, + bool mapped_relation, + bool allow_system_table_mods, + int8 row_compress, + Oid ownerid, + bool skip_create_storage, + TableAmType tam_type); + +extern bool heap_is_matview_init_state(Relation rel); + +extern Partition +heapCreatePartition(const char* part_name, + bool for_partitioned_table, + Oid part_tablespace, + Oid part_id, + Oid partFileNode, + Oid bucketOid, + Oid ownerid); + +extern Oid heap_create_with_catalog(const char *relname, + Oid relnamespace, + Oid reltablespace, + Oid relid, + Oid reltypeid, + Oid reloftypeid, + Oid ownerid, + TupleDesc tupdesc, + List *cooked_constraints, + char relkind, + char relpersistence, + bool shared_relation, + bool mapped_relation, + bool oidislocal, + int oidinhcount, + OnCommitAction oncommit, + Datum reloptions, + bool use_user_acl, + bool allow_system_table_mods, + PartitionState *partTableState, + int8 row_compress, + List *filenodelist, + HashBucketInfo *bucketinfo, + bool record_dependce = true, + List* ceLst = NULL); + +extern void heap_create_init_fork(Relation rel); + +extern void heap_drop_with_catalog(Oid relid); +extern void heapDropPartition(Relation rel, Partition part); +extern void dropToastTableOnPartition(Oid partId); +extern void dropCuDescTableOnPartition(Oid partId); +extern void dropDeltaTableOnPartition(Oid partId); + + +extern void heapDropPartitionToastList(List* toastList); +extern void heapDropPartitionList(Relation rel, List* partitionList); +extern Oid heapAddRangePartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, RangePartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern Oid HeapAddListPartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, ListPartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern Oid HeapAddHashPartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, HashPartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern void heapDropPartitionIndex(Relation parentIndex, Oid partIndexId); +extern void addNewPartitionTuple(Relation pg_part_desc, Partition new_part_desc, int2vector* pkey, oidvector *intablespace, + Datum interval, Datum maxValues, Datum transitionPoint, Datum reloptions); + +extern void heap_truncate_one_part(Relation rel , Oid partOid); +extern Oid heapTupleGetPartitionId(Relation rel, HeapTuple tuple); +extern void heap_truncate(List *relids); +extern void heap_truncate_one_rel(Relation rel); +extern void heap_truncate_check_FKs(List *relations, bool tempTables); +extern List *heap_truncate_find_FKs(List *relationIds); +extern void InsertPgAttributeTuple(Relation pg_attribute_rel, Form_pg_attribute new_attribute, CatalogIndexState indstate); + +extern void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, + Datum reloptions, char relkind, int2vector *bucketcol); + +extern List *AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local); + +extern List *AddRelClusterConstraints(Relation rel, List *clusterKeys); +extern void StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr); +extern Node *cookDefault(ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, char *attname); +extern void DeleteRelationTuple(Oid relid); +extern void DeleteAttributeTuples(Oid relid); +extern void DeleteSystemAttributeTuples(Oid relid); +extern void RemoveAttributeById(Oid relid, AttrNumber attnum); +extern void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal); +extern void RemoveAttrDefaultById(Oid attrdefId); + +template +extern void RemoveStatistics(Oid relid, AttrNumber attnum); + +extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno, bool relhasoids, bool relhasbucket); +extern Form_pg_attribute SystemAttributeByName(const char *attname, bool relhasoids); + +extern int GetSysAttLength(bool hasBucketAttr = true); + +extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, bool allow_system_table_mods); +extern void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, bool allow_system_table_mods); + +#ifdef PGXC +/* Functions related to distribution data of relations */ +extern void AddRelationDistribution(const char *relname, Oid relid, DistributeBy *distributeby, + PGXCSubCluster *subcluster, List *parentOids, TupleDesc descriptor, bool isinstallationgroup); +extern void GetRelationDistributionItems(Oid relid, DistributeBy *distributeby, TupleDesc descriptor, char *locatortype, + int *hashalgorithm, int *hashbuckets, AttrNumber *attnum); +extern HashBucketInfo *GetRelationBucketInfo(DistributeBy *distributeby, TupleDesc tupledsc, + bool *createbucket, Oid bucket, bool enable_createbucket); +extern void TryReuseIndex(Oid oldId, IndexStmt *stmt); +extern void tryReusePartedIndex(Oid oldId, IndexStmt *stmt, Relation rel); +extern Oid *GetRelationDistributionNodes(PGXCSubCluster *subcluster, int *numnodes); +extern Oid *BuildRelationDistributionNodes(List *nodes, int *numnodes); +extern Oid *SortRelationDistributionNodes(Oid *nodeoids, int numnodes); +#endif + +extern void SetRelHasClusterKey(Relation rel, bool has); +extern int2vector* buildPartitionKey(List *keys, TupleDesc tupledsc); +/* + * @hdfs + * Check the constraint from pg_constraint. + */ +extern bool FindExistingConstraint(const char *ccname, Relation rel); +/** + * @Description: Build the column map. Store the column number using + * bitmap method. + * @in tuple_desc, A tuple descriptor. + * @return reutrn the column map. + */ +extern char* make_column_map(TupleDesc tuple_desc); + +/** + * @Description: check whether the partition keys has timestampwithzone type. + * @input: partTableRel, the partition table relation. + * @return: a bool array to indicate the result. The length of array is equal to the number of partition keys. + * @Notes: remember to pfree the array. + */ +extern bool* check_partkey_has_timestampwithzone(Relation partTableRel); + +extern Oid AddNewIntervalPartition(Relation rel, HeapTuple insertTuple); + +extern int GetIndexKeyAttsByTuple(Relation relation, HeapTuple indexTuple); + +#endif /* HEAP_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/index.h postgresql-hll-2.14/include/catalog/index.h --- postgresql-hll-2.14_old/include/catalog/index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/index.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,205 @@ +/* ------------------------------------------------------------------------- + * + * index.h + * prototypes for catalog/index.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/index.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEX_H +#define INDEX_H + +#include "nodes/execnodes.h" +#include "utils/tuplesort.h" + +#define DEFAULT_INDEX_TYPE "btree" +#define DEFAULT_CSTORE_INDEX_TYPE "psort" +#define DEFAULT_GIST_INDEX_TYPE "gist" +#define CSTORE_BTREE_INDEX_TYPE "cbtree" +#define DEFAULT_GIN_INDEX_TYPE "gin" +#define CSTORE_GINBTREE_INDEX_TYPE "cgin" + +/* Typedef for callback function for IndexBuildHeapScan */ +typedef void (*IndexBuildCallback)(Relation index, HeapTuple htup, Datum *values, const bool *isnull, + bool tupleIsAlive, void *state); + +typedef void (*IndexBuildVecBatchScanCallback)(Relation index, ItemPointer tid, Datum *values, + const bool *isnull, void *state); + +/* Action code for index_set_state_flags */ +typedef enum +{ + INDEX_CREATE_SET_READY, + INDEX_CREATE_SET_VALID, + INDEX_DROP_CLEAR_VALID, + INDEX_DROP_SET_DEAD +} IndexStateFlagsAction; + +/* */ +#define REINDEX_BTREE_INDEX (1<<1) +#define REINDEX_HASH_INDEX (1<<2) +#define REINDEX_GIN_INDEX (1<<3) +#define REINDEX_GIST_INDEX (1<<4) +#define REINDEX_CGIN_INDEX (1<<5) +#define REINDEX_ALL_INDEX (REINDEX_BTREE_INDEX|REINDEX_HASH_INDEX|REINDEX_GIN_INDEX|REINDEX_GIST_INDEX|REINDEX_CGIN_INDEX) + + +/* state info for validate_index bulkdelete callback */ +typedef struct { + Tuplesortstate* tuplesort; /* for sorting the index TIDs */ + /* statistics (for debug purposes only): */ + double htups, itups, tups_inserted; +} v_i_state; + + +typedef enum CheckWaitMode +{ + CHECK_WAIT, + CHECK_NOWAIT, +} CheckWaitMode; + +extern void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table); + +/* + * Parameter isPartitionedIndex indicates whether the index is a partition index. + * Parameter isGlobalPartitionedIndex indicates whether the index is a global partition index. + * ------------------------------------------------------------------------- + * | isPartitionedIndex | isGlobalPartitionedIndex | Description | + * ------------------------------------------------------------------------- + * | false | false | normal relation index | + * ------------------------------------------------------------------------- + * | true | false | local partition index | + * ------------------------------------------------------------------------- + * | false | true | can not happen | + * ------------------------------------------------------------------------- + * | true | true | global partition index | + * ------------------------------------------------------------------------- + */ +typedef struct +{ + Oid existingPSortOid; + bool isPartitionedIndex; + bool isGlobalPartitionedIndex; +} IndexCreateExtraArgs; + +typedef enum { + INDEX_CREATE_NONE_PARTITION, + INDEX_CREATE_LOCAL_PARTITION, + INDEX_CREATE_GLOBAL_PARTITION +} IndexCreatePartitionType; + +typedef enum { ALL_KIND, GLOBAL_INDEX, LOCAL_INDEX } IndexKind; + +#define PARTITION_TYPE(extra) \ + (extra->isPartitionedIndex == false ? INDEX_CREATE_NONE_PARTITION \ + : (extra->isGlobalPartitionedIndex == false ? INDEX_CREATE_LOCAL_PARTITION \ + : INDEX_CREATE_GLOBAL_PARTITION)) + + +extern Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, + Oid relFileNode, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, + Oid tableSpaceId, Oid *collationObjectId, Oid *classObjectId, int16 *coloptions, + Datum reloptions, bool isprimary, bool isconstraint, bool deferrable, + bool initdeferred, bool allow_system_table_mods, bool skip_build, bool concurrent, + IndexCreateExtraArgs *extra); + +extern void index_constraint_create(Relation heapRelation, Oid indexRelationId, IndexInfo *indexInfo, + const char *constraintName, char constraintType, bool deferrable, + bool initdeferred, bool mark_as_primary, bool update_pgindex, + bool remove_old_dependencies, bool allow_system_table_mods); + +extern void index_drop(Oid indexId, bool concurrent); + +extern IndexInfo *BuildIndexInfo(Relation index); +extern IndexInfo *BuildDummyIndexInfo(Relation index); + +extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo* ii); + +extern void FormIndexDatum(IndexInfo *indexInfo, + TupleTableSlot *slot, + EState *estate, + Datum *values, + bool *isnull); +extern void index_build(Relation heapRelation, + Partition heapPartition, + Relation indexRelation, + Partition indexPartition, + IndexInfo *indexInfo, + bool isprimary, + bool isreindex, + IndexCreatePartitionType partitionType); + +extern double IndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + bool allow_sync, IndexBuildCallback callback, void *callback_state); +extern double* GlobalIndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo* indexInfo, + IndexBuildCallback callback, void* callbackState); +extern double IndexBuildVectorBatchScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + VectorBatch *vecScanBatch, Snapshot snapshot, + IndexBuildVecBatchScanCallback callback, void *callback_state, + void *transferFuncs); + + +extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot); +extern void validate_index_heapscan( + Relation heapRelation, Relation indexRelation, IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state); + +extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action); +extern void reindex_indexpart_internal(Relation heapRelation, + Relation iRel, + IndexInfo* indexInfo, + Oid indexPartId); +extern void reindex_index(Oid indexId, Oid indexPartId, + bool skip_constraint_checks, AdaptMem *memInfo, + bool dbWide); +extern void ReindexGlobalIndexInternal(Relation heapRelation, Relation iRel, IndexInfo* indexInfo); + +/* Flag bits for reindex_relation(): */ +#define REINDEX_REL_PROCESS_TOAST 0x01 +#define REINDEX_REL_SUPPRESS_INDEX_USE 0x02 +#define REINDEX_REL_CHECK_CONSTRAINTS 0x04 + +extern bool reindex_relation(Oid relid, int flags, int reindexType, AdaptMem* memInfo = NULL, bool dbWide = false, + IndexKind indexKind = ALL_KIND); +extern bool ReindexIsProcessingHeap(Oid heapOid); +extern bool ReindexIsProcessingIndex(Oid indexOid); +extern Oid IndexGetRelation(Oid indexId, bool missing_ok); + +typedef struct +{ + Oid existingPSortOid; +} PartIndexCreateExtraArgs; + +extern Oid partition_index_create(const char* partIndexName, + Oid partIndexFileNode, + Partition partition, + Oid tspid, + Relation parentIndex, + Relation partitionedTable, + Relation pg_partition_rel, + IndexInfo *indexInfo, + List *indexColNames, + Datum indexRelOptions, + bool skipBuild, + PartIndexCreateExtraArgs *extra); +extern void addIndexForPartition(Relation partitionedRelation, Oid partOid); +extern void dropIndexForPartition(Oid partOid); +extern void index_update_stats(Relation rel, bool hasindex, bool isprimary, + Oid reltoastidxid, Oid relcudescidx, double reltuples); +extern void PartitionNameCallbackForIndexPartition(Oid partitionedRelationOid, + const char *partitionName, + Oid partId, + Oid oldPartId, + char partition_type, + void *arg, + LOCKMODE callbackobj_lockMode); +extern void reindex_partIndex(Relation heapRel, Partition heapPart, Relation indexRel , Partition indexPart); +extern bool reindexPartition(Oid relid, Oid partOid, int flags, int reindexType); +extern void AddGPIForPartition(Oid partTableOid, Oid partOid); +extern void mergeBTreeIndexes(List* mergingBtreeIndexes, List* srcPartMergeOffset); +extern void SetIndexCreateExtraArgs(IndexCreateExtraArgs* extra, Oid psortOid, bool isPartition, bool isGlobal); +#endif /* INDEX_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/indexing.h postgresql-hll-2.14/include/catalog/indexing.h --- postgresql-hll-2.14_old/include/catalog/indexing.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/indexing.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,548 @@ +/* ------------------------------------------------------------------------- + * + * indexing.h + * This file provides some definitions to support indexing + * on system catalogs + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/indexing.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEXING_H +#define INDEXING_H + +#include "access/htup.h" +#include "utils/relcache.h" + +/* + * The state object used by CatalogOpenIndexes and friends is actually the + * same as the executor's ResultRelInfo, but we give it another type name + * to decouple callers from that fact. + */ +typedef struct ResultRelInfo *CatalogIndexState; + +/* + * indexing.c prototypes + */ +extern CatalogIndexState CatalogOpenIndexes(Relation heapRel); +extern void CatalogCloseIndexes(CatalogIndexState indstate); +extern void CatalogIndexInsert(CatalogIndexState indstate, + HeapTuple heapTuple); +extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple); + + +/* + * These macros are just to keep the C compiler from spitting up on the + * upcoming commands for genbki.pl. + */ +#define DECLARE_INDEX(name,oid,decl) extern int no_such_variable +#define DECLARE_UNIQUE_INDEX(name,oid,decl) extern int no_such_variable +#define BUILD_INDICES + + +/* + * What follows are lines processed by genbki.pl to create the statements + * the bootstrap parser will turn into DefineIndex commands. + * + * The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX. The first two + * arguments are the index name and OID, the rest is much like a standard + * 'create index' SQL command. + * + * For each index, we also provide a #define for its OID. References to + * the index in the C code should always use these #defines, not the actual + * index name (much less the numeric OID). + */ + +DECLARE_UNIQUE_INDEX(pg_aggregate_fnoid_index, 2650, on pg_aggregate using btree(aggfnoid oid_ops)); +#define AggregateFnoidIndexId 2650 + +DECLARE_UNIQUE_INDEX(pg_am_name_index, 2651, on pg_am using btree(amname name_ops)); +#define AmNameIndexId 2651 +DECLARE_UNIQUE_INDEX(pg_am_oid_index, 2652, on pg_am using btree(oid oid_ops)); +#define AmOidIndexId 2652 + +DECLARE_UNIQUE_INDEX(pg_amop_fam_strat_index, 2653, on pg_amop using btree(amopfamily oid_ops, amoplefttype oid_ops, amoprighttype oid_ops, amopstrategy int2_ops)); +#define AccessMethodStrategyIndexId 2653 +DECLARE_UNIQUE_INDEX(pg_amop_opr_fam_index, 2654, on pg_amop using btree(amopopr oid_ops, amoppurpose char_ops, amopfamily oid_ops)); +#define AccessMethodOperatorIndexId 2654 +DECLARE_UNIQUE_INDEX(pg_amop_oid_index, 2756, on pg_amop using btree(oid oid_ops)); +#define AccessMethodOperatorOidIndexId 2756 + +DECLARE_UNIQUE_INDEX(pg_amproc_fam_proc_index, 2655, on pg_amproc using btree(amprocfamily oid_ops, amproclefttype oid_ops, amprocrighttype oid_ops, amprocnum int2_ops)); +#define AccessMethodProcedureIndexId 2655 +DECLARE_UNIQUE_INDEX(pg_amproc_oid_index, 2757, on pg_amproc using btree(oid oid_ops)); +#define AccessMethodProcedureOidIndexId 2757 + +DECLARE_UNIQUE_INDEX(pg_attrdef_adrelid_adnum_index, 2656, on pg_attrdef using btree(adrelid oid_ops, adnum int2_ops)); +#define AttrDefaultIndexId 2656 +DECLARE_UNIQUE_INDEX(pg_attrdef_oid_index, 2657, on pg_attrdef using btree(oid oid_ops)); +#define AttrDefaultOidIndexId 2657 + +DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index, 2658, on pg_attribute using btree(attrelid oid_ops, attname name_ops)); +#define AttributeRelidNameIndexId 2658 +DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnum_index, 2659, on pg_attribute using btree(attrelid oid_ops, attnum int2_ops)); +#define AttributeRelidNumIndexId 2659 + +DECLARE_UNIQUE_INDEX(pg_authid_rolname_index, 2676, on pg_authid using btree(rolname name_ops)); +#define AuthIdRolnameIndexId 2676 +DECLARE_UNIQUE_INDEX(pg_authid_oid_index, 2677, on pg_authid using btree(oid oid_ops)); +#define AuthIdOidIndexId 2677 + +DECLARE_UNIQUE_INDEX(pg_auth_members_role_member_index, 2694, on pg_auth_members using btree(roleid oid_ops, member oid_ops)); +#define AuthMemRoleMemIndexId 2694 +DECLARE_UNIQUE_INDEX(pg_auth_members_member_role_index, 2695, on pg_auth_members using btree(member oid_ops, roleid oid_ops)); +#define AuthMemMemRoleIndexId 2695 + +DECLARE_UNIQUE_INDEX(pg_cast_oid_index, 2660, on pg_cast using btree(oid oid_ops)); +#define CastOidIndexId 2660 +DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, on pg_cast using btree(castsource oid_ops, casttarget oid_ops)); +#define CastSourceTargetIndexId 2661 + +DECLARE_UNIQUE_INDEX(pg_class_oid_index, 2662, on pg_class using btree(oid oid_ops)); +#define ClassOidIndexId 2662 +DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, on pg_class using btree(relname name_ops, relnamespace oid_ops)); +#define ClassNameNspIndexId 2663 +DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 9981, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops)); +#define ClassTblspcRelfilenodeIndexId 9981 +DECLARE_UNIQUE_INDEX(pg_collation_name_enc_nsp_index, 3164, on pg_collation using btree(collname name_ops, collencoding int4_ops, collnamespace oid_ops)); +#define CollationNameEncNspIndexId 3164 +DECLARE_UNIQUE_INDEX(pg_collation_oid_index, 3085, on pg_collation using btree(oid oid_ops)); +#define CollationOidIndexId 3085 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_conname_nsp_index, 2664, on pg_constraint using btree(conname name_ops, connamespace oid_ops)); +#define ConstraintNameNspIndexId 2664 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_conrelid_index, 2665, on pg_constraint using btree(conrelid oid_ops)); +#define ConstraintRelidIndexId 2665 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_contypid_index, 2666, on pg_constraint using btree(contypid oid_ops)); +#define ConstraintTypidIndexId 2666 +DECLARE_UNIQUE_INDEX(pg_constraint_oid_index, 2667, on pg_constraint using btree(oid oid_ops)); +#define ConstraintOidIndexId 2667 + +DECLARE_UNIQUE_INDEX(pg_conversion_default_index, 2668, on pg_conversion using btree(connamespace oid_ops, conforencoding int4_ops, contoencoding int4_ops, oid oid_ops)); +#define ConversionDefaultIndexId 2668 +DECLARE_UNIQUE_INDEX(pg_conversion_name_nsp_index, 2669, on pg_conversion using btree(conname name_ops, connamespace oid_ops)); +#define ConversionNameNspIndexId 2669 +DECLARE_UNIQUE_INDEX(pg_conversion_oid_index, 2670, on pg_conversion using btree(oid oid_ops)); +#define ConversionOidIndexId 2670 + +DECLARE_UNIQUE_INDEX(pg_database_datname_index, 2671, on pg_database using btree(datname name_ops)); +#define DatabaseNameIndexId 2671 +DECLARE_UNIQUE_INDEX(pg_database_oid_index, 2672, on pg_database using btree(oid oid_ops)); +#define DatabaseOidIndexId 2672 + +/* This follwing index is used for Data Source */ +DECLARE_UNIQUE_INDEX(pg_extension_data_source_oid_index, 7166, on pg_extension_data_source using btree(oid oid_ops)); +#define DataSourceOidIndexId 7166 + +DECLARE_UNIQUE_INDEX(pg_extension_data_source_name_index, 7167, on pg_extension_data_source using btree(srcname name_ops)); +#define DataSourceNameIndexId 7167 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_depend_depender_index, 2673, on pg_depend using btree(classid oid_ops, objid oid_ops, objsubid int4_ops)); +#define DependDependerIndexId 2673 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_depend_reference_index, 2674, on pg_depend using btree(refclassid oid_ops, refobjid oid_ops, refobjsubid int4_ops)); +#define DependReferenceIndexId 2674 + +DECLARE_UNIQUE_INDEX(pg_description_o_c_o_index, 2675, on pg_description using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops)); +#define DescriptionObjIndexId 2675 +DECLARE_UNIQUE_INDEX(pg_shdescription_o_c_index, 2397, on pg_shdescription using btree(objoid oid_ops, classoid oid_ops)); +#define SharedDescriptionObjIndexId 2397 + +DECLARE_UNIQUE_INDEX(pg_enum_oid_index, 3502, on pg_enum using btree(oid oid_ops)); +#define EnumOidIndexId 3502 +DECLARE_UNIQUE_INDEX(pg_enum_typid_label_index, 3503, on pg_enum using btree(enumtypid oid_ops, enumlabel name_ops)); +#define EnumTypIdLabelIndexId 3503 +DECLARE_UNIQUE_INDEX(pg_enum_typid_sortorder_index, 3534, on pg_enum using btree(enumtypid oid_ops, enumsortorder float4_ops)); +#define EnumTypIdSortOrderIndexId 3534 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_index_indrelid_index, 2678, on pg_index using btree(indrelid oid_ops)); +#define IndexIndrelidIndexId 2678 +DECLARE_UNIQUE_INDEX(pg_index_indexrelid_index, 2679, on pg_index using btree(indexrelid oid_ops)); +#define IndexRelidIndexId 2679 + +DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index, 2680, on pg_inherits using btree(inhrelid oid_ops, inhseqno int4_ops)); +#define InheritsRelidSeqnoIndexId 2680 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_inherits_parent_index, 2187, on pg_inherits using btree(inhparent oid_ops)); +#define InheritsParentIndexId 2187 + +DECLARE_UNIQUE_INDEX(pg_language_name_index, 2681, on pg_language using btree(lanname name_ops)); +#define LanguageNameIndexId 2681 +DECLARE_UNIQUE_INDEX(pg_language_oid_index, 2682, on pg_language using btree(oid oid_ops)); +#define LanguageOidIndexId 2682 + +DECLARE_UNIQUE_INDEX(pg_largeobject_loid_pn_index, 2683, on pg_largeobject using btree(loid oid_ops, pageno int4_ops)); +#define LargeObjectLOidPNIndexId 2683 + +DECLARE_UNIQUE_INDEX(pg_largeobject_metadata_oid_index, 2996, on pg_largeobject_metadata using btree(oid oid_ops)); +#define LargeObjectMetadataOidIndexId 2996 + +DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, on pg_namespace using btree(nspname name_ops)); +#define NamespaceNameIndexId 2684 +DECLARE_UNIQUE_INDEX(pg_namespace_oid_index, 2685, on pg_namespace using btree(oid oid_ops)); +#define NamespaceOidIndexId 2685 + +DECLARE_UNIQUE_INDEX(pg_opclass_am_name_nsp_index, 2686, on pg_opclass using btree(opcmethod oid_ops, opcname name_ops, opcnamespace oid_ops)); +#define OpclassAmNameNspIndexId 2686 +DECLARE_UNIQUE_INDEX(pg_opclass_oid_index, 2687, on pg_opclass using btree(oid oid_ops)); +#define OpclassOidIndexId 2687 + +DECLARE_UNIQUE_INDEX(pg_operator_oid_index, 2688, on pg_operator using btree(oid oid_ops)); +#define OperatorOidIndexId 2688 +DECLARE_UNIQUE_INDEX(pg_operator_oprname_l_r_n_index, 2689, on pg_operator using btree(oprname name_ops, oprleft oid_ops, oprright oid_ops, oprnamespace oid_ops)); +#define OperatorNameNspIndexId 2689 + +DECLARE_UNIQUE_INDEX(pg_opfamily_am_name_nsp_index, 2754, on pg_opfamily using btree(opfmethod oid_ops, opfname name_ops, opfnamespace oid_ops)); +#define OpfamilyAmNameNspIndexId 2754 +DECLARE_UNIQUE_INDEX(pg_opfamily_oid_index, 2755, on pg_opfamily using btree(oid oid_ops)); +#define OpfamilyOidIndexId 2755 + +DECLARE_UNIQUE_INDEX(pg_pltemplate_name_index, 1137, on pg_pltemplate using btree(tmplname name_ops)); +#define PLTemplateNameIndexId 1137 + +DECLARE_UNIQUE_INDEX(pg_proc_oid_index, 2690, on pg_proc using btree(oid oid_ops)); +#define ProcedureOidIndexId 2690 +DECLARE_UNIQUE_INDEX(pg_proc_proname_args_nsp_index, 2691, on pg_proc using btree(proname name_ops, proargtypes oidvector_ops, pronamespace oid_ops)); +#define ProcedureNameArgsNspIndexId 2691 + +DECLARE_UNIQUE_INDEX(pg_rewrite_oid_index, 2692, on pg_rewrite using btree(oid oid_ops)); +#define RewriteOidIndexId 2692 +DECLARE_UNIQUE_INDEX(pg_rewrite_rel_rulename_index, 2693, on pg_rewrite using btree(ev_class oid_ops, rulename name_ops)); +#define RewriteRelRulenameIndexId 2693 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_shdepend_depender_index, 1232, on pg_shdepend using btree(dbid oid_ops, classid oid_ops, objid oid_ops, objsubid int4_ops)); +#define SharedDependDependerIndexId 1232 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_shdepend_reference_index, 1233, on pg_shdepend using btree(refclassid oid_ops, refobjid oid_ops)); +#define SharedDependReferenceIndexId 1233 + +DECLARE_UNIQUE_INDEX(pg_statistic_relid_kind_att_inh_index, 2696, on pg_statistic using btree(starelid oid_ops, starelkind char_ops, staattnum int2_ops, stainherit bool_ops)); +#define StatisticRelidKindAttnumInhIndexId 2696 + +DECLARE_UNIQUE_INDEX(pg_statistic_ext_relid_kind_inh_key_index, 3222, on pg_statistic_ext using btree(starelid oid_ops, starelkind char_ops, stainherit bool_ops, stakey array_ops)); +#define StatisticExtRelidKindInhKeyIndexId 3222 + +DECLARE_UNIQUE_INDEX(pg_tablespace_oid_index, 2697, on pg_tablespace using btree(oid oid_ops)); +#define TablespaceOidIndexId 2697 +DECLARE_UNIQUE_INDEX(pg_tablespace_spcname_index, 2698, on pg_tablespace using btree(spcname name_ops)); +#define TablespaceNameIndexId 2698 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_trigger_tgconstraint_index, 2699, on pg_trigger using btree(tgconstraint oid_ops)); +#define TriggerConstraintIndexId 2699 +DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index, 2701, on pg_trigger using btree(tgrelid oid_ops, tgname name_ops)); +#define TriggerRelidNameIndexId 2701 +DECLARE_UNIQUE_INDEX(pg_trigger_oid_index, 2702, on pg_trigger using btree(oid oid_ops)); +#define TriggerOidIndexId 2702 + +DECLARE_UNIQUE_INDEX(pg_ts_config_cfgname_index, 3608, on pg_ts_config using btree(cfgname name_ops, cfgnamespace oid_ops)); +#define TSConfigNameNspIndexId 3608 +DECLARE_UNIQUE_INDEX(pg_ts_config_oid_index, 3712, on pg_ts_config using btree(oid oid_ops)); +#define TSConfigOidIndexId 3712 + +DECLARE_UNIQUE_INDEX(pg_ts_config_map_index, 3609, on pg_ts_config_map using btree(mapcfg oid_ops, maptokentype int4_ops, mapseqno int4_ops)); +#define TSConfigMapIndexId 3609 + +DECLARE_UNIQUE_INDEX(pg_ts_dict_dictname_index, 3604, on pg_ts_dict using btree(dictname name_ops, dictnamespace oid_ops)); +#define TSDictionaryNameNspIndexId 3604 +DECLARE_UNIQUE_INDEX(pg_ts_dict_oid_index, 3605, on pg_ts_dict using btree(oid oid_ops)); +#define TSDictionaryOidIndexId 3605 + +DECLARE_UNIQUE_INDEX(pg_ts_parser_prsname_index, 3606, on pg_ts_parser using btree(prsname name_ops, prsnamespace oid_ops)); +#define TSParserNameNspIndexId 3606 +DECLARE_UNIQUE_INDEX(pg_ts_parser_oid_index, 3607, on pg_ts_parser using btree(oid oid_ops)); +#define TSParserOidIndexId 3607 + +DECLARE_UNIQUE_INDEX(pg_ts_template_tmplname_index, 3766, on pg_ts_template using btree(tmplname name_ops, tmplnamespace oid_ops)); +#define TSTemplateNameNspIndexId 3766 +DECLARE_UNIQUE_INDEX(pg_ts_template_oid_index, 3767, on pg_ts_template using btree(oid oid_ops)); +#define TSTemplateOidIndexId 3767 + +DECLARE_UNIQUE_INDEX(pg_type_oid_index, 2703, on pg_type using btree(oid oid_ops)); +#define TypeOidIndexId 2703 +DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index, 2704, on pg_type using btree(typname name_ops, typnamespace oid_ops)); +#define TypeNameNspIndexId 2704 + +DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_oid_index, 112, on pg_foreign_data_wrapper using btree(oid oid_ops)); +#define ForeignDataWrapperOidIndexId 112 + +DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_name_index, 548, on pg_foreign_data_wrapper using btree(fdwname name_ops)); +#define ForeignDataWrapperNameIndexId 548 + +DECLARE_UNIQUE_INDEX(pg_foreign_server_oid_index, 113, on pg_foreign_server using btree(oid oid_ops)); +#define ForeignServerOidIndexId 113 + +DECLARE_UNIQUE_INDEX(pg_foreign_server_name_index, 549, on pg_foreign_server using btree(srvname name_ops)); +#define ForeignServerNameIndexId 549 + +DECLARE_UNIQUE_INDEX(pg_user_mapping_oid_index, 174, on pg_user_mapping using btree(oid oid_ops)); +#define UserMappingOidIndexId 174 + +DECLARE_UNIQUE_INDEX(pg_user_mapping_user_server_index, 175, on pg_user_mapping using btree(umuser oid_ops, umserver oid_ops)); +#define UserMappingUserServerIndexId 175 + +#ifdef PGXC +DECLARE_UNIQUE_INDEX(pgxc_class_pcrelid_index, 9002, on pgxc_class using btree(pcrelid oid_ops)); +#define PgxcClassPgxcRelIdIndexId 9002 + +DECLARE_UNIQUE_INDEX(pgxc_node_oid_index, 9010, on pgxc_node using btree(oid oid_ops)); +#define PgxcNodeOidIndexId 9010 + +DECLARE_UNIQUE_INDEX(pgxc_node_name_type_index, 9024, on pgxc_node using btree(node_name name_ops, node_type char_ops, oid oid_ops)); +#define PgxcNodeNodeNameIndexId 9024 +#define PgxcNodeNodeNameIndexIdOld 9011 + +DECLARE_UNIQUE_INDEX(pgxc_group_name_index, 9012, on pgxc_group using btree(group_name name_ops)); +#define PgxcGroupGroupNameIndexId 9012 + +DECLARE_UNIQUE_INDEX(pgxc_group_oid, 9013, on pgxc_group using btree(oid oid_ops)); +#define PgxcGroupOidIndexId 9013 + +DECLARE_UNIQUE_INDEX(pg_resource_pool_name_index, 9000, on pg_resource_pool using btree(respool_name name_ops)); +#define ResourcePoolPoolNameIndexId 9000 + +DECLARE_UNIQUE_INDEX(pg_resource_pool_oid_index, 9017, on pg_resource_pool using btree(oid oid_ops)); +#define ResourcePoolOidIndexId 9017 + +DECLARE_UNIQUE_INDEX(pg_workload_group_name_index, 9018, on pg_workload_group using btree(workload_gpname name_ops)); +#define WorkloadGroupGroupNameIndexId 9018 + +DECLARE_UNIQUE_INDEX(pg_workload_group_oid_index, 9019, on pg_workload_group using btree(oid oid_ops)); +#define WorkloadGroupOidIndexId 9019 + +DECLARE_UNIQUE_INDEX(pg_app_workloadgroup_mapping_name_index, 9020, on pg_app_workloadgroup_mapping using btree(appname name_ops)); +#define AppWorkloadGroupMappingNameIndexId 9020 + +DECLARE_UNIQUE_INDEX(pg_app_workloadgroup_mapping_oid_index, 9021, on pg_app_workloadgroup_mapping using btree(oid oid_ops)); +#define AppWorkloadGroupMappingOidIndexId 9021 + +DECLARE_UNIQUE_INDEX(pgxc_node_id_index, 9003, on pgxc_node using btree(node_id int4_ops)); +#define PgxcNodeNodeIdIndexId 9003 + +DECLARE_UNIQUE_INDEX(pgxc_slice_relid_index, 9033, on pgxc_slice using btree(relid oid_ops, type char_ops, relname name_ops, sindex int4_ops)); +#define PgxcSliceIndexId 9033 + +DECLARE_UNIQUE_INDEX(pgxc_slice_order_index, 9034, on pgxc_slice using btree(relid oid_ops, type char_ops, sliceorder int4_ops, sindex int4_ops)); +#define PgxcSliceOrderIndexId 9034 + +#endif + +DECLARE_UNIQUE_INDEX(pg_foreign_table_relid_index, 3119, on pg_foreign_table using btree(ftrelid oid_ops)); +#define ForeignTableRelidIndexId 3119 + +DECLARE_UNIQUE_INDEX(pg_default_acl_role_nsp_obj_index, 827, on pg_default_acl using btree(defaclrole oid_ops, defaclnamespace oid_ops, defaclobjtype char_ops)); +#define DefaultAclRoleNspObjIndexId 827 +DECLARE_UNIQUE_INDEX(pg_default_acl_oid_index, 828, on pg_default_acl using btree(oid oid_ops)); +#define DefaultAclOidIndexId 828 + +DECLARE_UNIQUE_INDEX(pg_db_role_setting_databaseid_rol_index, 2965, on pg_db_role_setting using btree(setdatabase oid_ops, setrole oid_ops)); +#define DbRoleSettingDatidRolidIndexId 2965 + +DECLARE_UNIQUE_INDEX(pg_seclabel_object_index, 3597, on pg_seclabel using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops, provider text_ops)); +#define SecLabelObjectIndexId 3597 + +DECLARE_UNIQUE_INDEX(pg_shseclabel_object_index, 3593, on pg_shseclabel using btree(objoid oid_ops, classoid oid_ops, provider text_ops)); +#define SharedSecLabelObjectIndexId 3593 + +DECLARE_UNIQUE_INDEX(pg_extension_oid_index, 3080, on pg_extension using btree(oid oid_ops)); +#define ExtensionOidIndexId 3080 + +DECLARE_UNIQUE_INDEX(pg_extension_name_index, 3081, on pg_extension using btree(extname name_ops)); +#define ExtensionNameIndexId 3081 + +DECLARE_UNIQUE_INDEX(pg_range_rngtypid_index, 3542, on pg_range using btree(rngtypid oid_ops)); +#define RangeTypidIndexId 3542 + +/* add index of passwordtime for pg_auth_history */ +DECLARE_UNIQUE_INDEX(pg_auth_history_index, 3458, on pg_auth_history using btree(roloid oid_ops, passwordtime timestamptz_ops)); +#define AuthHistoryIndexId 3458 +DECLARE_UNIQUE_INDEX(pg_auth_history_oid_index, 3459, on pg_auth_history using btree(oid oid_ops)); +#define AuthHistoryOidIndexId 3459 +/* add index of roleid for pg_user_status */ +DECLARE_UNIQUE_INDEX(pg_user_status_index, 3461, on pg_user_status using btree(roloid oid_ops)); +#define UserStatusRoleidIndexId 3461 +DECLARE_UNIQUE_INDEX(pg_user_status_oid_index, 3462, on pg_user_status using btree(oid oid_ops)); +#define UserStatusOidIndexId 3462 +DECLARE_UNIQUE_INDEX(pg_partition_reloid_index, 3472, on pg_partition using btree(oid oid_ops)); +#define PartitionOidIndexId 3472 +DECLARE_INDEX(pg_partition_parentoid_index,3473, on pg_partition using btree(parttype char_ops, parentid oid_ops)); +#define PartitionParentOidIndexId 3473 +DECLARE_INDEX(pg_partition_indextblid_index,3474, on pg_partition using btree(indextblid oid_ops)); +#define PartitionIndexTableIdIndexId 3474 +DECLARE_UNIQUE_INDEX(pg_partition_partoid_index, 3479, on pg_partition using btree(relname name_ops, parttype char_ops, parentid oid_ops)); +#define PartitionPartOidIndexId 3479 + +/* Add index of table oid for pg_hashbucket */ +DECLARE_UNIQUE_INDEX(pg_hashbucket_oid_index, 3490, on pg_hashbucket using btree(oid oid_ops)); +#define HashBucketOidIndexId 3490 +DECLARE_INDEX(pg_hashbucket_bid_index,3491, on pg_hashbucket using btree(bucketid oid_ops, bucketcnt int4_ops)); +#define HashBucketBidIndexId 3491 + +/* Add index of table oid for pg_job, pg_job_proc */ +DECLARE_UNIQUE_INDEX(pg_job_oid_index, 3453, on pg_job using btree(oid oid_ops)); +#define PgJobOidIndexId 3453 +DECLARE_UNIQUE_INDEX(pg_job_id_index, 3454, on pg_job using btree(job_id int8_ops)); +#define PgJobIdIndexId 3454 +DECLARE_UNIQUE_INDEX(pg_job_proc_oid_index, 3455, on pg_job_proc using btree(oid oid_ops)); +#define PgJobProcOidIndexId 3455 +DECLARE_UNIQUE_INDEX(pg_job_proc_id_index, 3449, on pg_job_proc using btree(job_id int4_ops)); +#define PgJobProcIdIndexId 3449 + +DECLARE_INDEX(gs_asp_sampletime_index, 2999, on gs_asp using btree(sample_time timestamptz_ops)); +#define GsAspSampleIdTimedexId 2999 + +/* Add index of table oid for pg_directory */ +DECLARE_UNIQUE_INDEX(pg_directory_oid_index, 4349, on pg_directory using btree(oid oid_ops)); +#define PgDirectoryOidIndexId 4349 +DECLARE_UNIQUE_INDEX(pg_directory_name_index, 4350, on pg_directory using btree(dirname name_ops)); +#define PgDirectoryDirectoriesNameIndexId 4350 + +/* Add index of table oid for gs_policy_label */ +DECLARE_UNIQUE_INDEX(gs_policy_label_oid_index, 9501, on gs_policy_label using btree(oid oid_ops)); +#define GsPolicyLabelOidIndexId 9501 +DECLARE_INDEX(gs_policy_label_name_index, 9502, on gs_policy_label using btree(labelname name_ops, fqdnnamespace oid_ops, fqdnid oid_ops)); +#define GsPolicyLabelNameIndexId 9502 + +/* Add index of table oid for gs_auditing_policy */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_oid_index, 9511, on gs_auditing_policy using btree(oid oid_ops)); +#define GsAuditingPolicyOidIndexId 9511 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_name_index, 9512, on gs_auditing_policy using btree(polname name_ops)); +#define GsAuditingPolicyNameIndexId 9512 + +/* Add index of table oid for policy access and privileges */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_access_oid_index, 9521, on gs_auditing_policy_access using btree(oid oid_ops)); +#define GsAuditingPolicyAccessOidIndexId 9521 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_privileges_oid_index, 9531, on gs_auditing_policy_privileges using btree(oid oid_ops)); +#define GsAuditingPolicyPrivilegesOidIndexId 9531 + +/* Add index for whole policy access and privileges row */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_access_row_index, 9522, on gs_auditing_policy_access using btree(accesstype name_ops, labelname name_ops, policyoid oid_ops)); +#define GsAuditingPolicyAccessRowIndexId 9522 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_privileges_row_index, 9532, on gs_auditing_policy_privileges using btree(privilegetype name_ops, labelname name_ops, policyoid oid_ops)); +#define GsAuditingPolicyPrivilegesRowIndexId 9532 + +/* Add index for table oid for auditing policy filters */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_filters_oid_index, 9541, on gs_auditing_policy_filters using btree(oid oid_ops)); +#define GsAuditingPolicyFiltersOidIndexId 9541 +/* Add index for policy oid filter row */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_filters_row_index, 9542, on gs_auditing_policy_filters using btree(policyoid oid_ops)); +#define GsAuditingPolicyFiltersPolicyOidIndexId 9542 + +/* Add index of table oid for gs_masking_policy */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_oid_index, 9611, on gs_masking_policy using btree(oid oid_ops)); +#define GsMaskingPolicyOidIndexId 9611 +DECLARE_UNIQUE_INDEX(gs_masking_policy_name_index, 9612, on gs_masking_policy using btree(polname name_ops)); +#define GsMaskingPolicyNameIndexId 9612 + +/* Add index for table oid for masking policy filters */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_filters_oid_index, 9641, on gs_masking_policy_filters using btree(oid oid_ops)); +#define GsMaskingPolicyFiltersOidIndexId 9641 +/* Add index for whole masking policy filter row */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_filters_row_index, 9642, on gs_masking_policy_filters using btree(policyoid oid_ops)); +#define GsMaskingPolicyFiltersPolicyOidIndexId 9642 + +/* Add index of table oid for gs_masking_policy_actions */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_actions_oid_index, 9651, on gs_masking_policy_actions using btree(oid oid_ops)); +#define GsMaskingPolicyActionsOidIndexId 9651 + +/* Add index for whole masking actions row */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_actions_row_index, 9652, on gs_masking_policy_actions using btree(actiontype name_ops, actlabelname name_ops, policyoid oid_ops)); +#define GsMaskingPolicyActionsRowIndexId 9652 +/* Add index for whole masking actions row */ +DECLARE_INDEX(gs_masking_policy_actions_policy_oid_index, 9653, on gs_masking_policy_actions using btree(policyoid oid_ops)); +#define GsMaskingPolicyActionsPolicyOidIndexId 9653 + +/* Add index of table oid for pg_rlspolicy */ +DECLARE_UNIQUE_INDEX(pg_rlspolicy_oid_index, 3224, on pg_rlspolicy using btree(oid oid_ops)); +#define PgRlspolicyOidIndex 3224 +DECLARE_UNIQUE_INDEX(pg_rlspolicy_polrelid_polname_index, 3225, on pg_rlspolicy using btree(polrelid oid_ops, polname name_ops)); +#define PgRlspolicyPolrelidPolnameIndex 3225 + +/* Add index for pg_objcet */ +DECLARE_UNIQUE_INDEX(pg_object_index, 3227, on pg_object using btree(object_oid oid_ops, object_type char_ops)); +#define PgObjectIndex 3227 + +/* Add index of table oid for pg_synonym */ +DECLARE_UNIQUE_INDEX(pg_synonym_name_nsp_index, 3547, on pg_synonym using btree(synname name_ops, synnamespace oid_ops)); +#define SynonymNameNspIndexId 3547 +DECLARE_UNIQUE_INDEX(pg_synonym_oid_index, 3548, on pg_synonym using btree(oid oid_ops)); +#define SynonymOidIndexId 3548 + +/* Add index of table oid for streaming_stream, streaming_cont_query */ +DECLARE_UNIQUE_INDEX(streaming_stream_oid_index, 3228, on streaming_stream using btree(oid oid_ops)); +#define StreamingStreamOidIndexId 3228 +DECLARE_UNIQUE_INDEX(streaming_stream_relid_index, 3229, on streaming_stream using btree(relid oid_ops)); +#define StreamingStreamRelidIndexId 3229 + +DECLARE_UNIQUE_INDEX(streaming_cont_query_relid_index, 3230, on streaming_cont_query using btree(relid oid_ops)); +#define StreamingContQueryRelidIndexId 3230 +DECLARE_UNIQUE_INDEX(streaming_cont_query_defrelid_index, 3231, on streaming_cont_query using btree(defrelid oid_ops)); +#define StreamingContQueryDefrelidIndexId 3231 +DECLARE_UNIQUE_INDEX(streaming_cont_query_id_index, 3232, on streaming_cont_query using btree(id int4_ops)); +#define StreamingContQueryIdIndexId 3232 +DECLARE_UNIQUE_INDEX(streaming_cont_query_oid_index, 3233, on streaming_cont_query using btree(oid oid_ops)); +#define StreamingContQueryOidIndexId 3233 +DECLARE_INDEX(streaming_cont_query_matrelid_index, 3234, on streaming_cont_query using btree(matrelid oid_ops)); +#define StreamingContQueryMatrelidIndexId 3234 +DECLARE_INDEX(streaming_cont_query_lookupidxid_index, 3235, on streaming_cont_query using btree(lookupidxid oid_ops)); +#define StreamingContQueryLookupidxidIndexId 3235 +DECLARE_INDEX(streaming_cont_query_schema_change_index, 3236, on streaming_cont_query using btree(matrelid oid_ops, active bool_ops)); +#define StreamingContQuerySchemaChangeIndexId 3236 +DECLARE_INDEX(streaming_gather_agg_index, 3237, on pg_aggregate using btree(aggtransfn oid_ops, aggcollectfn oid_ops, aggfinalfn oid_ops)); +#define StreamingGatherAggIndexId 3237 + +/* Add index of contquery oid for streaming_reaper_status */ +DECLARE_UNIQUE_INDEX(streaming_reaper_status_id_index, 9998, on streaming_reaper_status using btree(id int4_ops)); +#define StreamingReaperStatusOidIndexId 9998 +DECLARE_UNIQUE_INDEX(streaming_reaper_status_oid_index, 9999, on streaming_reaper_status using btree(oid oid_ops)); +#define StreamingCQReaperStatusOidIndexId 9999 + +/* Add index of table oid for gs_encrypted_columns */ +DECLARE_UNIQUE_INDEX(gs_encrypted_columns_oid_index, 9701, on gs_encrypted_columns using btree(oid oid_ops)); +#define GsSecEncryptedColumnsOidIndexId 9701 +DECLARE_UNIQUE_INDEX(gs_encrypted_columns_rel_id_column_name_index, 9702, on gs_encrypted_columns using btree(rel_id oid_ops, column_name name_ops)); +#define GsSecEncryptedColumnsRelidColumnnameIndexId 9702 + +/* Add index of table oid for gs_client_global_keys */ +DECLARE_UNIQUE_INDEX(gs_client_global_keys_oid_index, 9711, on gs_client_global_keys using btree(oid oid_ops)); +#define ClientLogicGlobalSettingsOidIndexId 9711 +DECLARE_UNIQUE_INDEX(gs_client_global_keys_name_index, 9712, on gs_client_global_keys using btree(global_key_name name_ops, key_namespace oid_ops)); +#define ClientLogicGlobalSettingsNameIndexId 9712 + +/* Add index of table oid for gs_column_keys */ +DECLARE_UNIQUE_INDEX(gs_column_keys_oid_index, 9721, on gs_column_keys using btree(oid oid_ops)); +#define ClientLogicColumnSettingsOidIndexId 9721 +DECLARE_UNIQUE_INDEX(gs_column_keys_name_index, 9722, on gs_column_keys using btree(column_key_name name_ops, key_namespace oid_ops)); +#define ClientLogicColumnSettingsNameIndexId 9722 +DECLARE_UNIQUE_INDEX(gs_column_keys_distributed_id_index, 9723, on gs_column_keys using btree(column_key_distributed_id oid_ops)); +#define ClientLogicColumnSettingDistributedIdIndexId 9723 + +/* Add index of table oid for gs_client_global_keys_args */ +DECLARE_UNIQUE_INDEX(gs_client_global_keys_args_oid_index, 9731, on gs_client_global_keys_args using btree(oid oid_ops)); +#define ClientLogicGlobalSettingsArgsOidIndexId 9731 + +/* Add index of table oid for gs_sec_column_encrption_keys_args */ +DECLARE_UNIQUE_INDEX(gs_column_keys_args_oid_index, 9741, on gs_column_keys_args using btree(oid oid_ops)); +#define ClientLogicColumnSettingsArgsOidIndexId 9741 +/* Add index for matview catalog*/ +DECLARE_UNIQUE_INDEX(gs_matview_oid_index, 9991, on gs_matview using btree(oid oid_ops)); +#define GsMatviewOidIndexId 9991 +DECLARE_UNIQUE_INDEX(gs_matviewdep_oid_index, 9992, on gs_matview_dependency using btree(oid oid_ops)); +#define GsMatviewDepOidIndexId 9992 + + +/* last step of initialization script: build the indexes declared above */ +BUILD_INDICES + +#endif /* INDEXING_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/namespace.h postgresql-hll-2.14/include/catalog/namespace.h --- postgresql-hll-2.14_old/include/catalog/namespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/namespace.h 2020-12-12 17:06:43.076345832 +0800 @@ -0,0 +1,221 @@ +/* ------------------------------------------------------------------------- + * + * namespace.h + * prototypes for functions in backend/catalog/namespace.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/namespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NAMESPACE_H +#define NAMESPACE_H + +#include "access/htup.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "lib/stringinfo.h" + + +/* + * This structure holds a list of possible functions or operators + * found by namespace lookup. Each function/operator is identified + * by OID and by argument types; the list must be pruned by type + * resolution rules that are embodied in the parser, not here. + * See FuncnameGetCandidates's comments for more info. + */ +typedef struct _FuncCandidateList +{ + struct _FuncCandidateList *next; + int pathpos; /* for internal use of namespace lookup */ + Oid oid; /* the function or operator's OID */ + int nargs; /* number of arg types returned */ + int nvargs; /* number of args to become variadic array */ + int ndargs; /* number of defaulted args */ + int *argnumbers; /* args' positional indexes, if named call */ + Oid refSynOid; /* referenced synonym's OID if mapping successfully, and drop it when view decoupling */ + Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types --- VARIABLE LENGTH ARRAY */ +} *FuncCandidateList; /* VARIABLE LENGTH STRUCT */ + +#define MinSizeOfFuncCandidateList offsetof(struct _FuncCandidateList, args) + +typedef struct _KeyCandidateList { + struct _KeyCandidateList *next; + int pathpos; /* for internal use of namespace lookup */ + Oid oid; /* the function or operator's OID */ +} *KeyCandidateList; /* VARIABLE LENGTH STRUCT */ + +#define SEARCH_PATH_GUC_NAME "search_path" +#define CURRENT_SCHEMA_GUC_NAME "current_schema" +#define SCHEMA_TEMP_NAME "pg_temp" +#define SCHEMA_CATALOG_NAME "pg_catalog" + +/* + * Structure for xxxOverrideSearchPath functions + */ +typedef struct OverrideSearchPath +{ + List *schemas; /* OIDs of explicitly named schemas */ + bool addCatalog; /* implicitly prepend pg_catalog? */ + bool addTemp; /* implicitly prepend temp schema? */ + bool addUser; /* implicitly postfix $user */ +} OverrideSearchPath; + +/* Override requests are remembered in a stack of OverrideStackEntry structs */ + +typedef struct +{ + List *searchPath; /* the desired search path */ + Oid creationNamespace; /* the desired creation namespace */ + int nestLevel; /* subtransaction nesting level */ + bool inProcedure; /* is true if in plpgsql */ +} OverrideStackEntry; + +typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId, + Oid oldRelId, bool target_is_partition, void *callback_arg); + +#define RangeVarGetRelid(relation, lockmode, missing_ok) \ + RangeVarGetRelidExtended(relation, lockmode, missing_ok, false, false, false, NULL, NULL, NULL, NULL) + +#define isTempNamespaceName(name) \ + (strncasecmp((name), "pg_temp_", 8) == 0) + +#define isTempNamespaceNameWithQuote(name) \ + (strncasecmp((name), "\"pg_temp_", 9) == 0) + +#define isToastTempNamespaceName(name) \ + (strncasecmp((name), "pg_toast_temp_", 14) == 0) + +#define IS_TEMP_NAMESPACE(name) \ + (strncasecmp((name), "pg_temp", 7) == 0) + +#define IS_CATALOG_NAMESPACE(name) \ + (strncasecmp((name), "pg_catalog", 10) == 0) + +extern Oid RangeVarGetRelidExtended(const RangeVar *relation, + LOCKMODE lockmode, bool missing_ok, bool nowait, bool target_is_partition, + bool isSupportSynonym, + RangeVarGetRelidCallback callback, + void *callback_arg, + StringInfo detailInfo = NULL, + Oid *refSynOid = NULL); +extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation); +extern Oid RangeVarGetAndCheckCreationNamespace(RangeVar *newRelation, + LOCKMODE lockmode, + Oid *existing_relation_id); +extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid); +extern Oid RelnameGetRelid(const char *relname, StringInfo detailInfo = NULL); +extern char* RelnameGetRelidExtended(const char *relname, Oid *relOid, Oid *refSynOid = NULL, + StringInfo detailInfo = NULL); +extern bool RelationIsVisible(Oid relid); + +extern Oid TypenameGetTypid(const char *typname); +extern bool TypeIsVisible(Oid typid); + +extern void SetTempFromSearchPath(List* namelist); + + +extern FuncCandidateList FuncnameGetCandidates(List *names, + int nargs, List *argnames, + bool expand_variadic, + bool expand_defaults, + bool func_create, + bool include_out = false); + +extern bool FunctionIsVisible(Oid funcid); + +extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright); +extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind); +extern bool OperatorIsVisible(Oid oprid); + +extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname); +extern bool OpclassIsVisible(Oid opcid); + +extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname); +extern bool OpfamilyIsVisible(Oid opfid); + +extern Oid CollationGetCollid(const char *collname); +extern bool CollationIsVisible(Oid collid); + +extern Oid ConversionGetConid(const char *conname); +extern bool ConversionIsVisible(Oid conid); + +extern Oid get_ts_parser_oid(List *names, bool missing_ok); +extern bool TSParserIsVisible(Oid prsId); + +extern Oid get_ts_dict_oid(List *names, bool missing_ok); +extern bool TSDictionaryIsVisible(Oid dictId); + +extern Oid get_ts_template_oid(List *names, bool missing_ok); +extern bool TSTemplateIsVisible(Oid tmplId); + +extern Oid get_ts_config_oid(List *names, bool missing_ok); +extern bool TSConfigIsVisible(Oid cfgid); + +extern void DeconstructQualifiedName(const List *names, + char **nspname_p, + char **objname_p); +extern Oid LookupNamespaceNoError(const char *nspname); +extern Oid LookupExplicitNamespace(const char *nspname); +extern Oid get_namespace_oid(const char *nspname, bool missing_ok); +extern Oid SchemaNameGetSchemaOid(const char *schemaname, bool missing_ok = false); +extern Oid GetOidBySchemaName(bool missing_ok = false); +extern Oid LookupCreationNamespace(const char *nspname); +extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid, Oid classid, + Oid objid); +extern Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p); +extern RangeVar *makeRangeVarFromNameList(List *names); +extern char *NameListToString(const List *names); +extern char *NameListToQuotedString(List *names); + +extern bool isTempNamespace(Oid namespaceId); +extern bool isTempToastNamespace(Oid namespaceId); +extern bool isTempOrToastNamespace(Oid namespaceId); +extern bool isAnyTempNamespace(Oid namespaceId); +extern bool isOtherTempNamespace(Oid namespaceId); +extern Oid GetTempToastNamespace(void); +extern void ResetTempTableNamespace(void); + +extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); +extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path); +extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path); +extern void PushOverrideSearchPath(OverrideSearchPath *newpath, bool inProcedure=false); +extern void PopOverrideSearchPath(void); +extern void AddTmpNspToOverrideSearchPath(Oid tmpnspId); +extern void RemoveTmpNspFromSearchPath(Oid tmpnspId); + +extern Oid get_collation_oid(List *collname, bool missing_ok); +extern Oid get_conversion_oid(List *conname, bool missing_ok); +extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding); + +/* initialization & transaction cleanup code */ +extern void InitializeSearchPath(void); +extern void AtEOXact_Namespace(bool isCommit); +extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid, + SubTransactionId parentSubid); + + +extern List *fetch_search_path(bool includeImplicit); +extern int fetch_search_path_array(Oid *sarray, int sarray_len); +extern Oid get_my_temp_schema(); + +extern void FetchDefaultArgumentPos(int **defpos, int2vector *adefpos, + const char *argmodes, int pronallargs); +extern Oid GetUserIdFromNspId(Oid nspid, bool is_securityadmin = false); + +extern void SetTempNamespace(Node *stmt, Oid namespaceOid); +extern void setTempToastNspName(); +extern void validateTempRelation(Relation rel); +extern bool checkGroup(Oid relid, bool missing_ok); + +extern bool validateTempNamespace(Oid tmepNspId); + +extern bool IsPackageFunction(List* funcname); + +extern void recomputeNamespacePath(StringInfo error_info = NULL); +extern KeyCandidateList GlobalSettingGetCandidates(List *names, bool); +extern KeyCandidateList CeknameGetCandidates(List *names, bool); +#endif /* NAMESPACE_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/objectaccess.h postgresql-hll-2.14/include/catalog/objectaccess.h --- postgresql-hll-2.14_old/include/catalog/objectaccess.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/objectaccess.h 2020-12-12 17:06:43.077345845 +0800 @@ -0,0 +1,63 @@ +/* + * objectaccess.h + * + * Object access hooks. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + */ + +#ifndef OBJECTACCESS_H +#define OBJECTACCESS_H + +/* + * Object access hooks are intended to be called just before or just after + * performing certain actions on a SQL object. This is intended as + * infrastructure for security or logging pluggins. + * + * OAT_POST_CREATE should be invoked just after the object is created. + * Typically, this is done after inserting the primary catalog records and + * associated dependencies. + * + * OAT_DROP should be invoked just before deletion of objects; typically + * deleteOneObject(). Its arguments are packed within ObjectAccessDrop. + * + * Other types may be added in the future. + */ +typedef enum ObjectAccessType +{ + OAT_POST_CREATE, + OAT_DROP, +} ObjectAccessType; + +/* + * Arguments of OAT_DROP event + */ +typedef struct +{ + /* + * Flags to inform extensions the context of this deletion. Also see + * PERFORM_DELETION_* in dependency.h + */ + int dropflags; +} ObjectAccessDrop; + +/* + * Hook, and a macro to invoke it. + */ +typedef void (*object_access_hook_type) (ObjectAccessType access, + Oid classId, + Oid objectId, + int subId, + void *arg); + +extern THR_LOCAL PGDLLIMPORT object_access_hook_type object_access_hook; + +#define InvokeObjectAccessHook(access,classId,objectId,subId,arg) \ + do { \ + if (object_access_hook) \ + (*object_access_hook)((access),(classId), \ + (objectId),(subId),(arg)); \ + } while(0) + +#endif /* OBJECTACCESS_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/objectaddress.h postgresql-hll-2.14/include/catalog/objectaddress.h --- postgresql-hll-2.14_old/include/catalog/objectaddress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/objectaddress.h 2020-12-12 17:06:43.077345845 +0800 @@ -0,0 +1,40 @@ +/* ------------------------------------------------------------------------- + * + * objectaddress.h + * functions for working with object addresses + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/objectaddress.h + * + * ------------------------------------------------------------------------- + */ +#ifndef OBJECTADDRESS_H +#define OBJECTADDRESS_H + +#include "nodes/parsenodes.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +/* + * An ObjectAddress represents a database object of any type. + */ +typedef struct ObjectAddress +{ + Oid classId; /* Class Id from pg_class */ + Oid objectId; /* OID of the object */ + int32 objectSubId; /* Subitem within object (eg column), or 0 */ +} ObjectAddress; + +extern ObjectAddress get_object_address(ObjectType objtype, List *objname, + List *objargs, Relation *relp, + LOCKMODE lockmode, bool missing_ok); + +extern void check_object_ownership(Oid roleid, + ObjectType objtype, ObjectAddress address, + List *objname, List *objargs, Relation relation); + +extern Oid get_object_namespace(const ObjectAddress *address); + +#endif /* PARSE_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_aggregate.h postgresql-hll-2.14/include/catalog/pg_aggregate.h --- postgresql-hll-2.14_old/include/catalog/pg_aggregate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_aggregate.h 2020-12-12 17:06:43.077345845 +0800 @@ -0,0 +1,488 @@ +/* ------------------------------------------------------------------------- + * + * pg_aggregate.h + * definition of the system "aggregate" relation (pg_aggregate) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_aggregate.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AGGREGATE_H +#define PG_AGGREGATE_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------------------------------------------------------- + * pg_aggregate definition. + * + * cpp turns this into typedef struct FormData_pg_aggregate + * +#ifdef PGXC + * Derived from pg_aggregate, added collection function, collection data + * type and collection initial value. +#endif + * + * aggfnoid pg_proc OID of the aggregate itself + * aggtransfn transition function +#ifdef PGXC + * aggcollectfn collectition function +#endif + * aggfinalfn final function (0 if none) + * aggsortop associated sort operator (0 if none) + * aggtranstype type of aggregate's transition (state) data + * agginitval initial value for transition state (can be NULL) +#ifdef PGXC + * agginitcollect initial value for collection state (can be NULL) +#endif + * ---------------------------------------------------------------- + */ +#define AggregateRelationId 2600 +#define AggregateRelation_Rowtype_Id 11326 + +CATALOG(pg_aggregate,2600) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + regproc aggfnoid; + regproc aggtransfn; + regproc aggcollectfn; /* PGXC */ + regproc aggfinalfn; + Oid aggsortop; + Oid aggtranstype; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text agginitval; + text agginitcollect; /* PGXC, VARIABLE LENGTH FIELD */ +#endif + char aggkind; + int2 aggnumdirectargs; +} FormData_pg_aggregate; + +/* ---------------- + * Form_pg_aggregate corresponds to a pointer to a tuple with + * the format of pg_aggregate relation. + * ---------------- + */ +typedef FormData_pg_aggregate *Form_pg_aggregate; + +/* ---------------- + * compiler constants for pg_aggregate + * ---------------- + */ + +#ifdef PGXC +#define Natts_pg_aggregate 10 +#define Anum_pg_aggregate_aggfnoid 1 +#define Anum_pg_aggregate_aggtransfn 2 +#define Anum_pg_aggregate_aggcollectfn 3 +#define Anum_pg_aggregate_aggfinalfn 4 +#define Anum_pg_aggregate_aggsortop 5 +#define Anum_pg_aggregate_aggtranstype 6 +#define Anum_pg_aggregate_agginitval 7 +#define Anum_pg_aggregate_agginitcollect 8 +#define Anum_pg_aggregate_aggkind 9 +#define Anum_pg_aggregate_aggnumdirectargs 10 +#endif + +/* + * Symbolic values for aggkind column. We distinguish normal aggregates + * from ordered-set aggregates (which have two sets of arguments, namely + * direct and aggregated arguments). + */ +#define AGGKIND_NORMAL 'n' +#define AGGKIND_DEFAULT 'n' +#define AGGKIND_ORDERED_SET 'o' +#define AGGKIND_IS_ORDERED_SET(kind) ((kind) == AGGKIND_ORDERED_SET) +#define AGGNUMDIRECTARGS_DEFAULT 0 +/* ---------------- + * initial contents of pg_aggregate + * --------------- + */ + +/* avg */ +#ifdef PGXC +DATA(insert ( 2100 int8_avg_accum numeric_avg_collect numeric_avg 0 1231 "{0,0}" "{0,0}" n 0)); +#define INT8AVGFUNCOID 2100 +DATA(insert ( 2101 int4_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT4AVGFUNCOID 2101 +DATA(insert ( 2102 int2_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT2AVGFUNCOID 2102 +DATA(insert ( 5537 int1_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT1AVGFUNCOID 5537 +DATA(insert ( 2103 numeric_avg_accum numeric_avg_collect numeric_avg 0 1231 "{0,0}" "{0,0}" n 0)); +#define NUMERICAVGFUNCOID 2103 +DATA(insert ( 2104 float4_accum float8_collect float8_avg 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +#define FLOAT4AVGFUNCOID 2104 +DATA(insert ( 2105 float8_accum float8_collect float8_avg 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +#define FLOAT8AVGFUNCOID 2105 +DATA(insert ( 2106 interval_accum interval_collect interval_avg 0 1187 "{0 second,0 second}" "{0 second,0 second}" n 0)); +#define INTERVALAGGAVGFUNCOID 2106 +#endif + +/* sum */ +#ifdef PGXC +DATA(insert ( 2107 int8_sum numeric_add - 0 1700 _null_ _null_ n 0)); +#define INT8SUMFUNCOID 2107 +DATA(insert ( 2108 int4_sum int8_sum_to_int8 - 0 20 _null_ _null_ n 0)); +#define INT4SUMFUNCOID 2108 +DATA(insert ( 2109 int2_sum int8_sum_to_int8 - 0 20 _null_ _null_ n 0)); +#define INT2SUMFUNCOID 2109 +DATA(insert ( 2110 float4pl float4pl - 0 700 _null_ _null_ n 0)); +DATA(insert ( 2111 float8pl float8pl - 0 701 _null_ _null_ n 0)); +DATA(insert ( 2112 cash_pl cash_pl - 0 790 _null_ _null_ n 0)); +DATA(insert ( 2113 interval_pl interval_pl - 0 1186 _null_ _null_ n 0)); +DATA(insert ( 2114 numeric_add numeric_add - 0 1700 _null_ _null_ n 0)); +#define NUMERICSUMFUNCOID 2114 +#endif + +/* max */ +#ifdef PGXC +DATA(insert ( 2115 int8larger int8larger - 413 20 _null_ _null_ n 0)); +#define INT8LARGERFUNCOID 2115 +DATA(insert ( 2116 int4larger int4larger - 521 23 _null_ _null_ n 0)); +#define INT4LARGERFUNCOID 2116 +DATA(insert ( 2117 int2larger int2larger - 520 21 _null_ _null_ n 0)); +#define INT2LARGERFUNCOID 2117 +DATA(insert ( 5538 int1larger int1larger - 5517 5545 _null_ _null_ n 0)); +DATA(insert ( 2118 oidlarger oidlarger - 610 26 _null_ _null_ n 0)); +DATA(insert ( 2119 float4larger float4larger - 623 700 _null_ _null_ n 0)); +DATA(insert ( 2120 float8larger float8larger - 674 701 _null_ _null_ n 0)); +DATA(insert ( 2121 int4larger int4larger - 563 702 _null_ _null_ n 0)); +DATA(insert ( 2122 date_larger date_larger - 1097 1082 _null_ _null_ n 0)); +DATA(insert ( 2123 time_larger time_larger - 1112 1083 _null_ _null_ n 0)); +DATA(insert ( 2124 timetz_larger timetz_larger - 1554 1266 _null_ _null_ n 0)); +DATA(insert ( 2125 cashlarger cashlarger - 903 790 _null_ _null_ n 0)); +DATA(insert ( 2126 timestamp_larger timestamp_larger - 2064 1114 _null_ _null_ n 0)); +DATA(insert ( 2127 timestamptz_larger timestamptz_larger - 1324 1184 _null_ _null_ n 0)); +DATA(insert ( 2128 interval_larger interval_larger - 1334 1186 _null_ _null_ n 0)); +DATA(insert ( 2129 text_larger text_larger - 666 25 _null_ _null_ n 0)); +DATA(insert ( 2130 numeric_larger numeric_larger - 1756 1700 _null_ _null_ n 0)); +#define NUMERICLARGERFUNCOID 2130 +DATA(insert ( 2050 array_larger array_larger - 1073 2277 _null_ _null_ n 0)); +DATA(insert ( 2244 bpchar_larger bpchar_larger - 1060 1042 _null_ _null_ n 0)); +DATA(insert ( 2797 tidlarger tidlarger - 2800 27 _null_ _null_ n 0)); +DATA(insert ( 3526 enum_larger enum_larger - 3519 3500 _null_ _null_ n 0)); +DATA(insert ( 9010 smalldatetime_larger smalldatetime_larger - 5554 9003 _null_ _null_ n 0)); +DATA(insert ( 9009 smalldatetime_smaller smalldatetime_smaller - 5552 9003 _null_ _null_ n 0)); +#endif + +/* min */ +#ifdef PGXC +DATA(insert ( 2131 int8smaller int8smaller - 412 20 _null_ _null_ n 0)); +#define INT8SMALLERFUNCOID 2131 +DATA(insert ( 2132 int4smaller int4smaller - 97 23 _null_ _null_ n 0)); +#define INT4SMALLERFUNCOID 2132 +DATA(insert ( 2133 int2smaller int2smaller - 95 21 _null_ _null_ n 0)); +#define INT2SMALLERFUNCOID 2133 +DATA(insert ( 2134 oidsmaller oidsmaller - 609 26 _null_ _null_ n 0)); +DATA(insert ( 2135 float4smaller float4smaller - 622 700 _null_ _null_ n 0)); +DATA(insert ( 2136 float8smaller float8smaller - 672 701 _null_ _null_ n 0)); +DATA(insert ( 2137 int4smaller int4smaller - 562 702 _null_ _null_ n 0)); +DATA(insert ( 2138 date_smaller date_smaller - 1095 1082 _null_ _null_ n 0)); +DATA(insert ( 2139 time_smaller time_smaller - 1110 1083 _null_ _null_ n 0)); +DATA(insert ( 2140 timetz_smaller timetz_smaller - 1552 1266 _null_ _null_ n 0)); +DATA(insert ( 2141 cashsmaller cashsmaller - 902 790 _null_ _null_ n 0)); +DATA(insert ( 2142 timestamp_smaller timestamp_smaller - 2062 1114 _null_ _null_ n 0)); +DATA(insert ( 2143 timestamptz_smaller timestamptz_smaller - 1322 1184 _null_ _null_ n 0)); +DATA(insert ( 2144 interval_smaller interval_smaller - 1332 1186 _null_ _null_ n 0)); +DATA(insert ( 2145 text_smaller text_smaller - 664 25 _null_ _null_ n 0)); +DATA(insert ( 2146 numeric_smaller numeric_smaller - 1754 1700 _null_ _null_ n 0)); +#define NUMERICSMALLERFUNCOID 2146 +DATA(insert ( 2051 array_smaller array_smaller - 1072 2277 _null_ _null_ n 0)); +DATA(insert ( 2245 bpchar_smaller bpchar_smaller - 1058 1042 _null_ _null_ n 0)); +DATA(insert ( 2798 tidsmaller tidsmaller - 2799 27 _null_ _null_ n 0)); +DATA(insert ( 3527 enum_smaller enum_smaller - 3518 3500 _null_ _null_ n 0)); +#endif + +/* count */ +/* Final function is data type conversion function numeric_int8 is referenced by OID because of ambiguous definition in pg_proc */ +#ifdef PGXC +DATA(insert ( 2147 int8inc_any int8_sum_to_int8 - 0 20 "0" "0" n 0)); +DATA(insert ( 2803 int8inc int8_sum_to_int8 - 0 20 "0" "0" n 0)); +#endif + +/* var_pop */ +#ifdef PGXC +DATA(insert ( 2718 int8_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2719 int4_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2720 int2_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2721 float4_accum float8_collect float8_var_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2722 float8_accum float8_collect float8_var_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2723 numeric_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* var_samp */ +#ifdef PGXC +DATA(insert ( 2641 int8_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2642 int4_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2643 int2_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2644 float4_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2645 float8_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2646 numeric_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* variance: historical Postgres syntax for var_samp */ +#ifdef PGXC +DATA(insert ( 2148 int8_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2149 int4_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2150 int2_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2151 float4_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2152 float8_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2153 numeric_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev_pop */ +#ifdef PGXC +DATA(insert ( 2724 int8_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2725 int4_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2726 int2_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2727 float4_accum float8_collect float8_stddev_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2728 float8_accum float8_collect float8_stddev_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2729 numeric_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev_samp */ +#ifdef PGXC +DATA(insert ( 2712 int8_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2713 int4_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2714 int2_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2715 float4_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2716 float8_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2717 numeric_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev: historical Postgres syntax for stddev_samp */ +#ifdef PGXC +DATA(insert ( 2154 int8_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2155 int4_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2156 int2_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2157 float4_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2158 float8_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2159 numeric_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* SQL2003 binary regression aggregates */ +#ifdef PGXC +DATA(insert ( 2818 int8inc_float8_float8 int8_sum_to_int8 - 0 20 "0" _null_ n 0)); +DATA(insert ( 2819 float8_regr_accum float8_regr_collect float8_regr_sxx 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2820 float8_regr_accum float8_regr_collect float8_regr_syy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2821 float8_regr_accum float8_regr_collect float8_regr_sxy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2822 float8_regr_accum float8_regr_collect float8_regr_avgx 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2823 float8_regr_accum float8_regr_collect float8_regr_avgy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2824 float8_regr_accum float8_regr_collect float8_regr_r2 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2825 float8_regr_accum float8_regr_collect float8_regr_slope 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2826 float8_regr_accum float8_regr_collect float8_regr_intercept 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2827 float8_regr_accum float8_regr_collect float8_covar_pop 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2828 float8_regr_accum float8_regr_collect float8_covar_samp 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2829 float8_regr_accum float8_regr_collect float8_corr 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +#endif + +/* boolean-and and boolean-or */ +#ifdef PGXC +DATA(insert ( 2517 booland_statefunc booland_statefunc - 58 16 _null_ _null_ n 0)); +DATA(insert ( 2518 boolor_statefunc boolor_statefunc - 59 16 _null_ _null_ n 0)); +DATA(insert ( 2519 booland_statefunc booland_statefunc - 58 16 _null_ _null_ n 0)); +#endif + +/* bitwise integer */ +#ifdef PGXC +DATA(insert ( 5539 int1and int1and - 0 5545 _null_ _null_ n 0)); +DATA(insert ( 5540 int1or int1or - 0 5545 _null_ _null_ n 0)); +DATA(insert ( 2236 int2and int2and - 0 21 _null_ _null_ n 0)); +DATA(insert ( 2237 int2or int2or - 0 21 _null_ _null_ n 0)); +DATA(insert ( 2238 int4and int4and - 0 23 _null_ _null_ n 0)); +DATA(insert ( 2239 int4or int4or - 0 23 _null_ _null_ n 0)); +DATA(insert ( 2240 int8and int8and - 0 20 _null_ _null_ n 0)); +DATA(insert ( 2241 int8or int8or - 0 20 _null_ _null_ n 0)); +DATA(insert ( 2242 bitand bitand - 0 1560 _null_ _null_ n 0)); +DATA(insert ( 2243 bitor bitor - 0 1560 _null_ _null_ n 0)); +#endif + +/* xml */ +#ifdef PGXC +DATA(insert ( 2901 xmlconcat2 xmlconcat2 - 0 142 _null_ _null_ n 0)); +#endif + +/* array */ +#ifdef PGXC +DATA(insert ( 2335 array_agg_transfn - array_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* text */ +#ifdef PGXC +DATA(insert ( 3538 string_agg_transfn - string_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* checksum */ +#ifdef PGXC +DATA(insert ( 4600 checksumtext_agg_transfn numeric_add - 0 1700 _null_ _null_ n 0)); +#endif + +/* bytea */ +#ifdef PGXC +DATA(insert ( 3545 bytea_string_agg_transfn - bytea_string_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* hll distribute agg */ +DATA(insert ( 4366 hll_add_trans0 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS0_OID 4366 +DATA(insert ( 4380 hll_add_trans1 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS1_OID 4380 +DATA(insert ( 4381 hll_add_trans2 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS2_OID 4381 +DATA(insert ( 4382 hll_add_trans3 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS3_OID 4382 +DATA(insert ( 4383 hll_add_trans4 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS4_OID 4383 +DATA(insert ( 4367 hll_union_trans hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_UNION_TRANS_OID 4367 + +/* list (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3552 list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3554 list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int2) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3556 int2_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int2) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3558 int2_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int4) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3560 int4_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int4) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3562 int4_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int8) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3564 int8_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int8) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3566 int8_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (float4) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3568 float4_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (float4) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3570 float4_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (float8) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3572 float8_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (float8) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3574 float8_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (numeric) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3576 numeric_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (numeric) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3578 numeric_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (date) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3580 date_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (date) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3582 date_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (timestamp) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3584 timestamp_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (timestamptz) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3586 timestamp_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (timestamptz) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3588 timestamptz_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (timestamptz) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 3590 timestamptz_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (interval) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 4506 interval_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (interval) (oracle 11g2)*/ +#ifdef PGXC +DATA(insert ( 4508 interval_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* ordered-set aggregates XXX shall we add collect funcs? */ +DATA(insert ( 4452 ordered_set_transition - percentile_cont_float8_final 0 2281 _null_ _null_ o 1)); +DATA(insert ( 4454 ordered_set_transition - percentile_cont_interval_final 0 2281 _null_ _null_ o 1)); +DATA(insert (4461 ordered_set_transition - mode_final 0 2281 _null_ _null_ o 0)); + +DATA(insert (5555 median_transfn - median_float8_finalfn 0 2281 _null_ _null_ n 0)); +DATA(insert (5556 median_transfn - median_interval_finalfn 0 2281 _null_ _null_ n 0)); + +/* + * prototypes for functions in pg_aggregate.c + */ +extern void AggregateCreate(const char *aggName, + Oid aggNamespace, + char aggKind, + Oid *aggArgTypes, + int numArgs, + List *aggtransfnName, +#ifdef PGXC + List *aggcollectfnName, +#endif + List *aggfinalfnName, + List *aggsortopName, + Oid aggTransType, +#ifdef PGXC + const char *agginitval, + const char *agginitcollect); +#else + const char *agginitval); +#endif + +#endif /* PG_AGGREGATE_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_am.h postgresql-hll-2.14/include/catalog/pg_am.h --- postgresql-hll-2.14_old/include/catalog/pg_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_am.h 2020-12-12 17:06:43.077345845 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * pg_am.h + * definition of the system "access method" relation (pg_am) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_am.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AM_H +#define PG_AM_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_am definition. cpp turns this into + * typedef struct FormData_pg_am + * ---------------- + */ +#define AccessMethodRelationId 2601 +#define AccessMethodRelation_Rowtype_Id 10164 + +CATALOG(pg_am,2601) BKI_SCHEMA_MACRO +{ + NameData amname; /* access method name */ + int2 amstrategies; /* total number of strategies (operators) by + * which we can traverse/search this AM. Zero + * if AM does not have a fixed set of strategy + * assignments. */ + int2 amsupport; /* total number of support functions that this + * AM uses */ + bool amcanorder; /* does AM support order by column value? */ + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amcanbackward; /* does AM support backward scan? */ + bool amcanunique; /* does AM support UNIQUE indexes? */ + bool amcanmulticol; /* does AM support multi-column indexes? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amstorage; /* can storage type differ from column type? */ + bool amclusterable; /* does AM support cluster command? */ + bool ampredlocks; /* does AM handle predicate locks? */ + Oid amkeytype; /* type of data in index, or InvalidOid */ + regproc aminsert; /* "insert this tuple" function */ + regproc ambeginscan; /* "prepare for index scan" function */ + regproc amgettuple; /* "next valid tuple" function, or 0 */ + regproc amgetbitmap; /* "fetch all valid tuples" function, or 0 */ + regproc amrescan; /* "(re)start index scan" function */ + regproc amendscan; /* "end index scan" function */ + regproc ammarkpos; /* "mark current scan position" function */ + regproc amrestrpos; /* "restore marked scan position" function */ + regproc ammerge; /* "merge several index relation into one" function */ + regproc ambuild; /* "build new index" function */ + regproc ambuildempty; /* "build empty index" function */ + regproc ambulkdelete; /* bulk-delete function */ + regproc amvacuumcleanup; /* post-VACUUM cleanup function */ + regproc amcanreturn; /* can indexscan return IndexTuples? */ + regproc amcostestimate; /* estimate cost of an indexscan */ + regproc amoptions; /* parse AM-specific parameters */ +} FormData_pg_am; + +/* ---------------- + * Form_pg_am corresponds to a pointer to a tuple with + * the format of pg_am relation. + * ---------------- + */ +typedef FormData_pg_am *Form_pg_am; + +/* ---------------- + * compiler constants for pg_am + * ---------------- + */ +#define Natts_pg_am 31 +#define Anum_pg_am_amname 1 +#define Anum_pg_am_amstrategies 2 +#define Anum_pg_am_amsupport 3 +#define Anum_pg_am_amcanorder 4 +#define Anum_pg_am_amcanorderbyop 5 +#define Anum_pg_am_amcanbackward 6 +#define Anum_pg_am_amcanunique 7 +#define Anum_pg_am_amcanmulticol 8 +#define Anum_pg_am_amoptionalkey 9 +#define Anum_pg_am_amsearcharray 10 +#define Anum_pg_am_amsearchnulls 11 +#define Anum_pg_am_amstorage 12 +#define Anum_pg_am_amclusterable 13 +#define Anum_pg_am_ampredlocks 14 +#define Anum_pg_am_amkeytype 15 +#define Anum_pg_am_aminsert 16 +#define Anum_pg_am_ambeginscan 17 +#define Anum_pg_am_amgettuple 18 +#define Anum_pg_am_amgetbitmap 19 +#define Anum_pg_am_amrescan 20 +#define Anum_pg_am_amendscan 21 +#define Anum_pg_am_ammarkpos 22 +#define Anum_pg_am_amrestrpos 23 +#define Anum_pg_am_ammerge 24 +#define Anum_pg_am_ambuild 25 +#define Anum_pg_am_ambuildempty 26 +#define Anum_pg_am_ambulkdelete 27 +#define Anum_pg_am_amvacuumcleanup 28 +#define Anum_pg_am_amcanreturn 29 +#define Anum_pg_am_amcostestimate 30 +#define Anum_pg_am_amoptions 31 + +/* ---------------- + * initial contents of pg_am + * ---------------- + */ + +DATA(insert OID = 403 ( btree 5 2 t f t t t t t t f t t 0 btinsert btbeginscan btgettuple btgetbitmap btrescan btendscan btmarkpos btrestrpos btmerge btbuild btbuildempty btbulkdelete btvacuumcleanup btcanreturn btcostestimate btoptions )); +DESCR("b-tree index access method"); +#define BTREE_AM_OID 403 +DATA(insert OID = 405 ( hash 1 1 f f t f f f f f f f f 23 hashinsert hashbeginscan hashgettuple hashgetbitmap hashrescan hashendscan hashmarkpos hashrestrpos hashmerge hashbuild hashbuildempty hashbulkdelete hashvacuumcleanup - hashcostestimate hashoptions )); +DESCR("hash index access method"); +#define HASH_AM_OID 405 +DATA(insert OID = 783 ( gist 0 8 f t f f t t f t t t f 0 gistinsert gistbeginscan gistgettuple gistgetbitmap gistrescan gistendscan gistmarkpos gistrestrpos gistmerge gistbuild gistbuildempty gistbulkdelete gistvacuumcleanup - gistcostestimate gistoptions )); +DESCR("GiST index access method"); +#define GIST_AM_OID 783 +DATA(insert OID = 2742 ( gin 0 6 f f f f t t f f t f f 0 gininsert ginbeginscan - gingetbitmap ginrescan ginendscan ginmarkpos ginrestrpos ginmerge ginbuild ginbuildempty ginbulkdelete ginvacuumcleanup - gincostestimate ginoptions )); +DESCR("GIN index access method"); +#define GIN_AM_OID 2742 +DATA(insert OID = 4000 ( spgist 0 5 f f f f f t f t f f f 0 spginsert spgbeginscan spggettuple spggetbitmap spgrescan spgendscan spgmarkpos spgrestrpos spgmerge spgbuild spgbuildempty spgbulkdelete spgvacuumcleanup spgcanreturn spgcostestimate spgoptions )); +DESCR("SP-GiST index access method"); +#define SPGIST_AM_OID 4000 + +DATA(insert OID = 4039 ( psort 5 1 f f f f t t f t f f f 0 - - psortgettuple psortgetbitmap - - - - - psortbuild - - - psortcanreturn psortcostestimate psortoptions )); +DESCR("psort index access method"); +#define PSORT_AM_OID 4039 + +DATA(insert OID = 4239 ( cbtree 5 1 f f f f t t f t f f t 0 btinsert btbeginscan cbtreegettuple cbtreegetbitmap btrescan btendscan - - - cbtreebuild btbuildempty - - cbtreecanreturn cbtreecostestimate cbtreeoptions )); +DESCR("cstore btree index access method"); +#define CBTREE_AM_OID 4239 + +DATA(insert OID = 4444 ( cgin 0 6 f f f f t t f f t f f 0 gininsert ginbeginscan - cgingetbitmap ginrescan ginendscan ginmarkpos ginrestrpos ginmerge cginbuild ginbuildempty ginbulkdelete ginvacuumcleanup - gincostestimate ginoptions )); +DESCR("cstore GIN index access method"); +#define CGIN_AM_OID 4444 + +#endif /* PG_AM_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_amop.h postgresql-hll-2.14/include/catalog/pg_amop.h --- postgresql-hll-2.14_old/include/catalog/pg_amop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_amop.h 2020-12-12 17:06:43.077345845 +0800 @@ -0,0 +1,1233 @@ +/* ------------------------------------------------------------------------- + * + * pg_amop.h + * definition of the system "amop" relation (pg_amop) + * along with the relation's initial contents. + * + * The amop table identifies the operators associated with each index operator + * family and operator class (classes are subsets of families). An associated + * operator can be either a search operator or an ordering operator, as + * identified by amoppurpose. + * + * The primary key for this table is . amoplefttype and amoprighttype are just copies of the + * operator's oprleft/oprright, ie its declared input data types. The + * "default" operators for a particular opclass within the family are those + * with amoplefttype = amoprighttype = opclass's opcintype. An opfamily may + * also contain other operators, typically cross-data-type operators. All the + * operators within a family are supposed to be compatible, in a way that is + * defined by each individual index AM. + * + * We also keep a unique index on , so that + * we can use a syscache to quickly answer questions of the form "is this + * operator in this opfamily, and if so what are its semantics with respect to + * the family?" This implies that the same operator cannot be listed for + * multiple strategy numbers within a single opfamily, with the exception that + * it's possible to list it for both search and ordering purposes (with + * different strategy numbers for the two purposes). + * + * amopmethod is a copy of the owning opfamily's opfmethod field. This is an + * intentional denormalization of the catalogs to buy lookup speed. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_amop.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AMOP_H +#define PG_AMOP_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_amop definition. cpp turns this into + * typedef struct FormData_pg_amop + * ---------------- + */ +#define AccessMethodOperatorRelationId 2602 +#define AccessMethodOperatorRelation_Rowtype_Id 10165 + +CATALOG(pg_amop,2602) BKI_SCHEMA_MACRO +{ + Oid amopfamily; /* the index opfamily this entry is for */ + Oid amoplefttype; /* operator's left input data type */ + Oid amoprighttype; /* operator's right input data type */ + int2 amopstrategy; /* operator strategy number */ + char amoppurpose; /* is operator for 's'earch or 'o'rdering? */ + Oid amopopr; /* the operator's pg_operator OID */ + Oid amopmethod; /* the index access method this entry is for */ + Oid amopsortfamily; /* ordering opfamily OID, or 0 if search op */ +} FormData_pg_amop; + +/* allowed values of amoppurpose: */ +#define AMOP_SEARCH 's' /* operator is for search */ +#define AMOP_ORDER 'o' /* operator is for ordering */ + +/* ---------------- + * Form_pg_amop corresponds to a pointer to a tuple with + * the format of pg_amop relation. + * ---------------- + */ +typedef FormData_pg_amop *Form_pg_amop; + +/* ---------------- + * compiler constants for pg_amop + * ---------------- + */ +#define Natts_pg_amop 8 +#define Anum_pg_amop_amopfamily 1 +#define Anum_pg_amop_amoplefttype 2 +#define Anum_pg_amop_amoprighttype 3 +#define Anum_pg_amop_amopstrategy 4 +#define Anum_pg_amop_amoppurpose 5 +#define Anum_pg_amop_amopopr 6 +#define Anum_pg_amop_amopmethod 7 +#define Anum_pg_amop_amopsortfamily 8 + +/* ---------------- + * initial contents of pg_amop + * ---------------- + */ + +/* + * btree integer_ops + */ + +/* default operators int2 */ +DATA(insert ( 1976 21 21 1 s 95 403 0 )); +DATA(insert ( 1976 21 21 2 s 522 403 0 )); +DATA(insert ( 1976 21 21 3 s 94 403 0 )); +DATA(insert ( 1976 21 21 4 s 524 403 0 )); +DATA(insert ( 1976 21 21 5 s 520 403 0 )); +/* crosstype operators int24 */ +DATA(insert ( 1976 21 23 1 s 534 403 0 )); +DATA(insert ( 1976 21 23 2 s 540 403 0 )); +DATA(insert ( 1976 21 23 3 s 532 403 0 )); +DATA(insert ( 1976 21 23 4 s 542 403 0 )); +DATA(insert ( 1976 21 23 5 s 536 403 0 )); +/* crosstype operators int28 */ +DATA(insert ( 1976 21 20 1 s 1864 403 0 )); +DATA(insert ( 1976 21 20 2 s 1866 403 0 )); +DATA(insert ( 1976 21 20 3 s 1862 403 0 )); +DATA(insert ( 1976 21 20 4 s 1867 403 0 )); +DATA(insert ( 1976 21 20 5 s 1865 403 0 )); +/* default operators int4 */ +DATA(insert ( 1976 23 23 1 s 97 403 0 )); +DATA(insert ( 1976 23 23 2 s 523 403 0 )); +DATA(insert ( 1976 23 23 3 s 96 403 0 )); +DATA(insert ( 1976 23 23 4 s 525 403 0 )); +DATA(insert ( 1976 23 23 5 s 521 403 0 )); +/* crosstype operators int42 */ +DATA(insert ( 1976 23 21 1 s 535 403 0 )); +DATA(insert ( 1976 23 21 2 s 541 403 0 )); +DATA(insert ( 1976 23 21 3 s 533 403 0 )); +DATA(insert ( 1976 23 21 4 s 543 403 0 )); +DATA(insert ( 1976 23 21 5 s 537 403 0 )); +/* crosstype operators int48 */ +DATA(insert ( 1976 23 20 1 s 37 403 0 )); +DATA(insert ( 1976 23 20 2 s 80 403 0 )); +DATA(insert ( 1976 23 20 3 s 15 403 0 )); +DATA(insert ( 1976 23 20 4 s 82 403 0 )); +DATA(insert ( 1976 23 20 5 s 76 403 0 )); +/* default operators int8 */ +DATA(insert ( 1976 20 20 1 s 412 403 0 )); +DATA(insert ( 1976 20 20 2 s 414 403 0 )); +DATA(insert ( 1976 20 20 3 s 410 403 0 )); +DATA(insert ( 1976 20 20 4 s 415 403 0 )); +DATA(insert ( 1976 20 20 5 s 413 403 0 )); +/* crosstype operators int82 */ +DATA(insert ( 1976 20 21 1 s 1870 403 0 )); +DATA(insert ( 1976 20 21 2 s 1872 403 0 )); +DATA(insert ( 1976 20 21 3 s 1868 403 0 )); +DATA(insert ( 1976 20 21 4 s 1873 403 0 )); +DATA(insert ( 1976 20 21 5 s 1871 403 0 )); +/* crosstype operators int84 */ +DATA(insert ( 1976 20 23 1 s 418 403 0 )); +DATA(insert ( 1976 20 23 2 s 420 403 0 )); +DATA(insert ( 1976 20 23 3 s 416 403 0 )); +DATA(insert ( 1976 20 23 4 s 430 403 0 )); +DATA(insert ( 1976 20 23 5 s 419 403 0 )); + +/* + * btree oid_ops + */ + +DATA(insert ( 1989 26 26 1 s 609 403 0 )); +DATA(insert ( 1989 26 26 2 s 611 403 0 )); +DATA(insert ( 1989 26 26 3 s 607 403 0 )); +DATA(insert ( 1989 26 26 4 s 612 403 0 )); +DATA(insert ( 1989 26 26 5 s 610 403 0 )); + +/* + * btree tid_ops + */ + +DATA(insert ( 2789 27 27 1 s 2799 403 0 )); +DATA(insert ( 2789 27 27 2 s 2801 403 0 )); +DATA(insert ( 2789 27 27 3 s 387 403 0 )); +DATA(insert ( 2789 27 27 4 s 2802 403 0 )); +DATA(insert ( 2789 27 27 5 s 2800 403 0 )); + +/* + * btree oidvector_ops + */ + +DATA(insert ( 1991 30 30 1 s 645 403 0 )); +DATA(insert ( 1991 30 30 2 s 647 403 0 )); +DATA(insert ( 1991 30 30 3 s 649 403 0 )); +DATA(insert ( 1991 30 30 4 s 648 403 0 )); +DATA(insert ( 1991 30 30 5 s 646 403 0 )); + +/* + * btree float_ops + */ + +/* default operators float4 */ +DATA(insert ( 1970 700 700 1 s 622 403 0 )); +DATA(insert ( 1970 700 700 2 s 624 403 0 )); +DATA(insert ( 1970 700 700 3 s 620 403 0 )); +DATA(insert ( 1970 700 700 4 s 625 403 0 )); +DATA(insert ( 1970 700 700 5 s 623 403 0 )); +/* crosstype operators float48 */ +DATA(insert ( 1970 700 701 1 s 1122 403 0 )); +DATA(insert ( 1970 700 701 2 s 1124 403 0 )); +DATA(insert ( 1970 700 701 3 s 1120 403 0 )); +DATA(insert ( 1970 700 701 4 s 1125 403 0 )); +DATA(insert ( 1970 700 701 5 s 1123 403 0 )); +/* default operators float8 */ +DATA(insert ( 1970 701 701 1 s 672 403 0 )); +DATA(insert ( 1970 701 701 2 s 673 403 0 )); +DATA(insert ( 1970 701 701 3 s 670 403 0 )); +DATA(insert ( 1970 701 701 4 s 675 403 0 )); +DATA(insert ( 1970 701 701 5 s 674 403 0 )); +/* crosstype operators float84 */ +DATA(insert ( 1970 701 700 1 s 1132 403 0 )); +DATA(insert ( 1970 701 700 2 s 1134 403 0 )); +DATA(insert ( 1970 701 700 3 s 1130 403 0 )); +DATA(insert ( 1970 701 700 4 s 1135 403 0 )); +DATA(insert ( 1970 701 700 5 s 1133 403 0 )); + +/* + * btree char_ops + */ + +DATA(insert ( 429 18 18 1 s 631 403 0 )); +DATA(insert ( 429 18 18 2 s 632 403 0 )); +DATA(insert ( 429 18 18 3 s 92 403 0 )); +DATA(insert ( 429 18 18 4 s 634 403 0 )); +DATA(insert ( 429 18 18 5 s 633 403 0 )); + +/* + * btree name_ops + */ + +DATA(insert ( 1986 19 19 1 s 660 403 0 )); +DATA(insert ( 1986 19 19 2 s 661 403 0 )); +DATA(insert ( 1986 19 19 3 s 93 403 0 )); +DATA(insert ( 1986 19 19 4 s 663 403 0 )); +DATA(insert ( 1986 19 19 5 s 662 403 0 )); + +/* + * btree text_ops + */ + +DATA(insert ( 1994 25 25 1 s 664 403 0 )); +DATA(insert ( 1994 25 25 2 s 665 403 0 )); +DATA(insert ( 1994 25 25 3 s 98 403 0 )); +DATA(insert ( 1994 25 25 4 s 667 403 0 )); +DATA(insert ( 1994 25 25 5 s 666 403 0 )); + +/* + * btree bpchar_ops + */ + +DATA(insert ( 426 1042 1042 1 s 1058 403 0 )); +DATA(insert ( 426 1042 1042 2 s 1059 403 0 )); +DATA(insert ( 426 1042 1042 3 s 1054 403 0 )); +DATA(insert ( 426 1042 1042 4 s 1061 403 0 )); +DATA(insert ( 426 1042 1042 5 s 1060 403 0 )); + +/* + * btree bytea_ops + */ + +DATA(insert ( 428 17 17 1 s 1957 403 0 )); +DATA(insert ( 428 17 17 2 s 1958 403 0 )); +DATA(insert ( 428 17 17 3 s 1955 403 0 )); +DATA(insert ( 428 17 17 4 s 1960 403 0 )); +DATA(insert ( 428 17 17 5 s 1959 403 0 )); + +/* + * btree byteawithoutorderwithequalcol_ops + */ + +DATA(insert ( 436 4402 4402 3 s 4453 403 0 )); + +/* + * btree raw_ops + */ + +DATA(insert ( 3806 86 86 1 s 3800 403 0 )); +DATA(insert ( 3806 86 86 2 s 3801 403 0 )); +DATA(insert ( 3806 86 86 3 s 3798 403 0 )); +DATA(insert ( 3806 86 86 4 s 3803 403 0 )); +DATA(insert ( 3806 86 86 5 s 3802 403 0 )); +DATA(insert ( 5535 5545 5545 1 s 5515 403 0 )); +DATA(insert ( 5535 5545 5545 2 s 5516 403 0 )); +DATA(insert ( 5535 5545 5545 3 s 5513 403 0 )); +DATA(insert ( 5535 5545 5545 4 s 5518 403 0 )); +DATA(insert ( 5535 5545 5545 5 s 5517 403 0 )); + +/* + * btree abstime_ops + */ + +DATA(insert ( 421 702 702 1 s 562 403 0 )); +DATA(insert ( 421 702 702 2 s 564 403 0 )); +DATA(insert ( 421 702 702 3 s 560 403 0 )); +DATA(insert ( 421 702 702 4 s 565 403 0 )); +DATA(insert ( 421 702 702 5 s 563 403 0 )); + +/* + * btree datetime_ops + */ + +/* default operators date */ +DATA(insert ( 434 1082 1082 1 s 1095 403 0 )); +DATA(insert ( 434 1082 1082 2 s 1096 403 0 )); +DATA(insert ( 434 1082 1082 3 s 1093 403 0 )); +DATA(insert ( 434 1082 1082 4 s 1098 403 0 )); +DATA(insert ( 434 1082 1082 5 s 1097 403 0 )); +/* crosstype operators vs timestamp */ +DATA(insert ( 434 1082 1114 1 s 2345 403 0 )); +DATA(insert ( 434 1082 1114 2 s 2346 403 0 )); +DATA(insert ( 434 1082 1114 3 s 2347 403 0 )); +DATA(insert ( 434 1082 1114 4 s 2348 403 0 )); +DATA(insert ( 434 1082 1114 5 s 2349 403 0 )); +/* crosstype operators vs timestamptz */ +DATA(insert ( 434 1082 1184 1 s 2358 403 0 )); +DATA(insert ( 434 1082 1184 2 s 2359 403 0 )); +DATA(insert ( 434 1082 1184 3 s 2360 403 0 )); +DATA(insert ( 434 1082 1184 4 s 2361 403 0 )); +DATA(insert ( 434 1082 1184 5 s 2362 403 0 )); +/* default operators timestamp */ +DATA(insert ( 434 1114 1114 1 s 2062 403 0 )); +DATA(insert ( 434 1114 1114 2 s 2063 403 0 )); +DATA(insert ( 434 1114 1114 3 s 2060 403 0 )); +DATA(insert ( 434 1114 1114 4 s 2065 403 0 )); +DATA(insert ( 434 1114 1114 5 s 2064 403 0 )); +/* crosstype operators vs date */ +DATA(insert ( 434 1114 1082 1 s 2371 403 0 )); +DATA(insert ( 434 1114 1082 2 s 2372 403 0 )); +DATA(insert ( 434 1114 1082 3 s 2373 403 0 )); +DATA(insert ( 434 1114 1082 4 s 2374 403 0 )); +DATA(insert ( 434 1114 1082 5 s 2375 403 0 )); +/* crosstype operators vs timestamptz */ +DATA(insert ( 434 1114 1184 1 s 2534 403 0 )); +DATA(insert ( 434 1114 1184 2 s 2535 403 0 )); +DATA(insert ( 434 1114 1184 3 s 2536 403 0 )); +DATA(insert ( 434 1114 1184 4 s 2537 403 0 )); +DATA(insert ( 434 1114 1184 5 s 2538 403 0 )); +/* default operators timestamptz */ +DATA(insert ( 434 1184 1184 1 s 1322 403 0 )); +DATA(insert ( 434 1184 1184 2 s 1323 403 0 )); +DATA(insert ( 434 1184 1184 3 s 1320 403 0 )); +DATA(insert ( 434 1184 1184 4 s 1325 403 0 )); +DATA(insert ( 434 1184 1184 5 s 1324 403 0 )); +/* crosstype operators vs date */ +DATA(insert ( 434 1184 1082 1 s 2384 403 0 )); +DATA(insert ( 434 1184 1082 2 s 2385 403 0 )); +DATA(insert ( 434 1184 1082 3 s 2386 403 0 )); +DATA(insert ( 434 1184 1082 4 s 2387 403 0 )); +DATA(insert ( 434 1184 1082 5 s 2388 403 0 )); +/* crosstype operators vs timestamp */ +DATA(insert ( 434 1184 1114 1 s 2540 403 0 )); +DATA(insert ( 434 1184 1114 2 s 2541 403 0 )); +DATA(insert ( 434 1184 1114 3 s 2542 403 0 )); +DATA(insert ( 434 1184 1114 4 s 2543 403 0 )); +DATA(insert ( 434 1184 1114 5 s 2544 403 0 )); + +/* + * btree time_ops + */ + +DATA(insert ( 1996 1083 1083 1 s 1110 403 0 )); +DATA(insert ( 1996 1083 1083 2 s 1111 403 0 )); +DATA(insert ( 1996 1083 1083 3 s 1108 403 0 )); +DATA(insert ( 1996 1083 1083 4 s 1113 403 0 )); +DATA(insert ( 1996 1083 1083 5 s 1112 403 0 )); + +/* + * btree timetz_ops + */ + +DATA(insert ( 2000 1266 1266 1 s 1552 403 0 )); +DATA(insert ( 2000 1266 1266 2 s 1553 403 0 )); +DATA(insert ( 2000 1266 1266 3 s 1550 403 0 )); +DATA(insert ( 2000 1266 1266 4 s 1555 403 0 )); +DATA(insert ( 2000 1266 1266 5 s 1554 403 0 )); + +/* + * btree interval_ops + */ + +DATA(insert ( 1982 1186 1186 1 s 1332 403 0 )); +DATA(insert ( 1982 1186 1186 2 s 1333 403 0 )); +DATA(insert ( 1982 1186 1186 3 s 1330 403 0 )); +DATA(insert ( 1982 1186 1186 4 s 1335 403 0 )); +DATA(insert ( 1982 1186 1186 5 s 1334 403 0 )); + +/* + * btree macaddr + */ + +DATA(insert ( 1984 829 829 1 s 1222 403 0 )); +DATA(insert ( 1984 829 829 2 s 1223 403 0 )); +DATA(insert ( 1984 829 829 3 s 1220 403 0 )); +DATA(insert ( 1984 829 829 4 s 1225 403 0 )); +DATA(insert ( 1984 829 829 5 s 1224 403 0 )); + +/* + * btree network + */ + +DATA(insert ( 1974 869 869 1 s 1203 403 0 )); +DATA(insert ( 1974 869 869 2 s 1204 403 0 )); +DATA(insert ( 1974 869 869 3 s 1201 403 0 )); +DATA(insert ( 1974 869 869 4 s 1206 403 0 )); +DATA(insert ( 1974 869 869 5 s 1205 403 0 )); + +/* + * btree numeric + */ + +DATA(insert ( 1988 1700 1700 1 s 1754 403 0 )); +DATA(insert ( 1988 1700 1700 2 s 1755 403 0 )); +DATA(insert ( 1988 1700 1700 3 s 1752 403 0 )); +DATA(insert ( 1988 1700 1700 4 s 1757 403 0 )); +DATA(insert ( 1988 1700 1700 5 s 1756 403 0 )); + +/* + * btree bool + */ + +DATA(insert ( 424 16 16 1 s 58 403 0 )); +DATA(insert ( 424 16 16 2 s 1694 403 0 )); +DATA(insert ( 424 16 16 3 s 91 403 0 )); +DATA(insert ( 424 16 16 4 s 1695 403 0 )); +DATA(insert ( 424 16 16 5 s 59 403 0 )); + +/* + * btree bit + */ + +DATA(insert ( 423 1560 1560 1 s 1786 403 0 )); +DATA(insert ( 423 1560 1560 2 s 1788 403 0 )); +DATA(insert ( 423 1560 1560 3 s 1784 403 0 )); +DATA(insert ( 423 1560 1560 4 s 1789 403 0 )); +DATA(insert ( 423 1560 1560 5 s 1787 403 0 )); + +/* + * btree varbit + */ + +DATA(insert ( 2002 1562 1562 1 s 1806 403 0 )); +DATA(insert ( 2002 1562 1562 2 s 1808 403 0 )); +DATA(insert ( 2002 1562 1562 3 s 1804 403 0 )); +DATA(insert ( 2002 1562 1562 4 s 1809 403 0 )); +DATA(insert ( 2002 1562 1562 5 s 1807 403 0 )); + +/* + * btree text pattern + */ + +DATA(insert ( 2095 25 25 1 s 2314 403 0 )); +DATA(insert ( 2095 25 25 2 s 2315 403 0 )); +DATA(insert ( 2095 25 25 3 s 98 403 0 )); +DATA(insert ( 2095 25 25 4 s 2317 403 0 )); +DATA(insert ( 2095 25 25 5 s 2318 403 0 )); + +/* + * btree bpchar pattern + */ + +DATA(insert ( 2097 1042 1042 1 s 2326 403 0 )); +DATA(insert ( 2097 1042 1042 2 s 2327 403 0 )); +DATA(insert ( 2097 1042 1042 3 s 1054 403 0 )); +DATA(insert ( 2097 1042 1042 4 s 2329 403 0 )); +DATA(insert ( 2097 1042 1042 5 s 2330 403 0 )); + +/* + * btree money_ops + */ + +DATA(insert ( 2099 790 790 1 s 902 403 0 )); +DATA(insert ( 2099 790 790 2 s 904 403 0 )); +DATA(insert ( 2099 790 790 3 s 900 403 0 )); +DATA(insert ( 2099 790 790 4 s 905 403 0 )); +DATA(insert ( 2099 790 790 5 s 903 403 0 )); + +/* + * btree reltime_ops + */ + +DATA(insert ( 2233 703 703 1 s 568 403 0 )); +DATA(insert ( 2233 703 703 2 s 570 403 0 )); +DATA(insert ( 2233 703 703 3 s 566 403 0 )); +DATA(insert ( 2233 703 703 4 s 571 403 0 )); +DATA(insert ( 2233 703 703 5 s 569 403 0 )); + +/* + * btree tinterval_ops + */ + +DATA(insert ( 2234 704 704 1 s 813 403 0 )); +DATA(insert ( 2234 704 704 2 s 815 403 0 )); +DATA(insert ( 2234 704 704 3 s 811 403 0 )); +DATA(insert ( 2234 704 704 4 s 816 403 0 )); +DATA(insert ( 2234 704 704 5 s 814 403 0 )); + +/* + * btree array_ops + */ + +DATA(insert ( 397 2277 2277 1 s 1072 403 0 )); +DATA(insert ( 397 2277 2277 2 s 1074 403 0 )); +DATA(insert ( 397 2277 2277 3 s 1070 403 0 )); +DATA(insert ( 397 2277 2277 4 s 1075 403 0 )); +DATA(insert ( 397 2277 2277 5 s 1073 403 0 )); + +/* + * btree record_ops + */ + +DATA(insert ( 2994 2249 2249 1 s 2990 403 0 )); +DATA(insert ( 2994 2249 2249 2 s 2992 403 0 )); +DATA(insert ( 2994 2249 2249 3 s 2988 403 0 )); +DATA(insert ( 2994 2249 2249 4 s 2993 403 0 )); +DATA(insert ( 2994 2249 2249 5 s 2991 403 0 )); + +/* + * btree uuid_ops + */ + +DATA(insert ( 2968 2950 2950 1 s 2974 403 0 )); +DATA(insert ( 2968 2950 2950 2 s 2976 403 0 )); +DATA(insert ( 2968 2950 2950 3 s 2972 403 0 )); +DATA(insert ( 2968 2950 2950 4 s 2977 403 0 )); +DATA(insert ( 2968 2950 2950 5 s 2975 403 0 )); + +/* + * hash index _ops + */ + +/* bpchar_ops */ +DATA(insert ( 427 1042 1042 1 s 1054 405 0 )); +/* char_ops */ +DATA(insert ( 431 18 18 1 s 92 405 0 )); +/* date_ops */ +DATA(insert ( 435 1082 1082 1 s 1093 405 0 )); +/* float_ops */ +DATA(insert ( 1971 700 700 1 s 620 405 0 )); +DATA(insert ( 1971 701 701 1 s 670 405 0 )); +DATA(insert ( 1971 700 701 1 s 1120 405 0 )); +DATA(insert ( 1971 701 700 1 s 1130 405 0 )); +/* network_ops */ +DATA(insert ( 1975 869 869 1 s 1201 405 0 )); +/* integer_ops */ +DATA(insert ( 1977 21 21 1 s 94 405 0 )); +DATA(insert ( 1977 23 23 1 s 96 405 0 )); +DATA(insert ( 1977 20 20 1 s 410 405 0 )); +DATA(insert ( 1977 21 23 1 s 532 405 0 )); +DATA(insert ( 1977 21 20 1 s 1862 405 0 )); +DATA(insert ( 1977 23 21 1 s 533 405 0 )); +DATA(insert ( 1977 23 20 1 s 15 405 0 )); +DATA(insert ( 1977 20 21 1 s 1868 405 0 )); +DATA(insert ( 1977 20 23 1 s 416 405 0 )); +/* interval_ops */ +DATA(insert ( 1983 1186 1186 1 s 1330 405 0 )); +/* macaddr_ops */ +DATA(insert ( 1985 829 829 1 s 1220 405 0 )); +/* name_ops */ +DATA(insert ( 1987 19 19 1 s 93 405 0 )); +/* oid_ops */ +DATA(insert ( 1990 26 26 1 s 607 405 0 )); +/* oidvector_ops */ +DATA(insert ( 1992 30 30 1 s 649 405 0 )); +/* text_ops */ +DATA(insert ( 1995 25 25 1 s 98 405 0 )); +/* time_ops */ +DATA(insert ( 1997 1083 1083 1 s 1108 405 0 )); +/* timestamptz_ops */ +DATA(insert ( 1999 1184 1184 1 s 1320 405 0 )); +/* timetz_ops */ +DATA(insert ( 2001 1266 1266 1 s 1550 405 0 )); +/* timestamp_ops */ +DATA(insert ( 2040 1114 1114 1 s 2060 405 0 )); +/* bool_ops */ +DATA(insert ( 2222 16 16 1 s 91 405 0 )); +/* bytea_ops */ +DATA(insert ( 2223 17 17 1 s 1955 405 0 )); +/* byteawithoutorderwithequalcol_ops */ +DATA(insert ( 4470 4402 4402 1 s 4453 405 0 )); + +/* raw_ops */ +DATA(insert ( 3807 86 86 1 s 3798 405 0 )); +/* tinyint_ops */ +DATA(insert ( 5536 5545 5545 1 s 5513 405 0 )); +/* int2vector_ops */ +DATA(insert ( 2224 22 22 1 s 386 405 0 )); +/* xid_ops */ +DATA(insert ( 2225 28 28 1 s 352 405 0 )); +DATA(insert ( 2232 31 31 1 s 355 405 0 )); +/* cid_ops */ +DATA(insert ( 2226 29 29 1 s 385 405 0 )); +/* abstime_ops */ +DATA(insert ( 2227 702 702 1 s 560 405 0 )); +/* reltime_ops */ +DATA(insert ( 2228 703 703 1 s 566 405 0 )); +/* text_pattern_ops */ +DATA(insert ( 2229 25 25 1 s 98 405 0 )); +/* bpchar_pattern_ops */ +DATA(insert ( 2231 1042 1042 1 s 1054 405 0 )); +/* aclitem_ops */ +DATA(insert ( 2235 1033 1033 1 s 974 405 0 )); +/* uuid_ops */ +DATA(insert ( 2969 2950 2950 1 s 2972 405 0 )); +/* numeric_ops */ +DATA(insert ( 1998 1700 1700 1 s 1752 405 0 )); +/* array_ops */ +DATA(insert ( 627 2277 2277 1 s 1070 405 0 )); + + +/* + * gist box_ops + */ + +DATA(insert ( 2593 603 603 1 s 493 783 0 )); +DATA(insert ( 2593 603 603 2 s 494 783 0 )); +DATA(insert ( 2593 603 603 3 s 500 783 0 )); +DATA(insert ( 2593 603 603 4 s 495 783 0 )); +DATA(insert ( 2593 603 603 5 s 496 783 0 )); +DATA(insert ( 2593 603 603 6 s 499 783 0 )); +DATA(insert ( 2593 603 603 7 s 498 783 0 )); +DATA(insert ( 2593 603 603 8 s 497 783 0 )); +DATA(insert ( 2593 603 603 9 s 2571 783 0 )); +DATA(insert ( 2593 603 603 10 s 2570 783 0 )); +DATA(insert ( 2593 603 603 11 s 2573 783 0 )); +DATA(insert ( 2593 603 603 12 s 2572 783 0 )); +DATA(insert ( 2593 603 603 13 s 2863 783 0 )); +DATA(insert ( 2593 603 603 14 s 2862 783 0 )); + +/* + * gist point_ops + */ +DATA(insert ( 1029 600 600 11 s 506 783 0 )); +DATA(insert ( 1029 600 600 1 s 507 783 0 )); +DATA(insert ( 1029 600 600 5 s 508 783 0 )); +DATA(insert ( 1029 600 600 10 s 509 783 0 )); +DATA(insert ( 1029 600 600 6 s 510 783 0 )); +DATA(insert ( 1029 600 600 15 o 517 783 1970 )); +DATA(insert ( 1029 600 603 28 s 511 783 0 )); +DATA(insert ( 1029 600 604 48 s 756 783 0 )); +DATA(insert ( 1029 600 718 68 s 758 783 0 )); + + +/* + * gist poly_ops (supports polygons) + */ + +DATA(insert ( 2594 604 604 1 s 485 783 0 )); +DATA(insert ( 2594 604 604 2 s 486 783 0 )); +DATA(insert ( 2594 604 604 3 s 492 783 0 )); +DATA(insert ( 2594 604 604 4 s 487 783 0 )); +DATA(insert ( 2594 604 604 5 s 488 783 0 )); +DATA(insert ( 2594 604 604 6 s 491 783 0 )); +DATA(insert ( 2594 604 604 7 s 490 783 0 )); +DATA(insert ( 2594 604 604 8 s 489 783 0 )); +DATA(insert ( 2594 604 604 9 s 2575 783 0 )); +DATA(insert ( 2594 604 604 10 s 2574 783 0 )); +DATA(insert ( 2594 604 604 11 s 2577 783 0 )); +DATA(insert ( 2594 604 604 12 s 2576 783 0 )); +DATA(insert ( 2594 604 604 13 s 2861 783 0 )); +DATA(insert ( 2594 604 604 14 s 2860 783 0 )); + +/* + * gist circle_ops + */ + +DATA(insert ( 2595 718 718 1 s 1506 783 0 )); +DATA(insert ( 2595 718 718 2 s 1507 783 0 )); +DATA(insert ( 2595 718 718 3 s 1513 783 0 )); +DATA(insert ( 2595 718 718 4 s 1508 783 0 )); +DATA(insert ( 2595 718 718 5 s 1509 783 0 )); +DATA(insert ( 2595 718 718 6 s 1512 783 0 )); +DATA(insert ( 2595 718 718 7 s 1511 783 0 )); +DATA(insert ( 2595 718 718 8 s 1510 783 0 )); +DATA(insert ( 2595 718 718 9 s 2589 783 0 )); +DATA(insert ( 2595 718 718 10 s 1515 783 0 )); +DATA(insert ( 2595 718 718 11 s 1514 783 0 )); +DATA(insert ( 2595 718 718 12 s 2590 783 0 )); +DATA(insert ( 2595 718 718 13 s 2865 783 0 )); +DATA(insert ( 2595 718 718 14 s 2864 783 0 )); + +/* + * gin array_ops (these anyarray operators are used with all the opclasses + * of the family) + */ +DATA(insert ( 2745 2277 2277 1 s 2750 2742 0 )); +DATA(insert ( 2745 2277 2277 2 s 2751 2742 0 )); +DATA(insert ( 2745 2277 2277 3 s 2752 2742 0 )); +DATA(insert ( 2745 2277 2277 4 s 1070 2742 0 )); + +/* + * cgin array_ops (these anyarray operators are used with all the opclasses + * of the family) + */ +/* +DATA(insert ( 4445 2277 2277 1 s 2750 4444 0 )); +DATA(insert ( 4445 2277 2277 2 s 2751 4444 0 )); +DATA(insert ( 4445 2277 2277 3 s 2752 4444 0 )); +DATA(insert ( 4445 2277 2277 4 s 1070 4444 0 )); +*/ + +/* + * btree enum_ops + */ +DATA(insert ( 3522 3500 3500 1 s 3518 403 0 )); +DATA(insert ( 3522 3500 3500 2 s 3520 403 0 )); +DATA(insert ( 3522 3500 3500 3 s 3516 403 0 )); +DATA(insert ( 3522 3500 3500 4 s 3521 403 0 )); +DATA(insert ( 3522 3500 3500 5 s 3519 403 0 )); + +/* + * hash enum_ops + */ +DATA(insert ( 3523 3500 3500 1 s 3516 405 0 )); + +/* + * btree tsvector_ops + */ +DATA(insert ( 3626 3614 3614 1 s 3627 403 0 )); +DATA(insert ( 3626 3614 3614 2 s 3628 403 0 )); +DATA(insert ( 3626 3614 3614 3 s 3629 403 0 )); +DATA(insert ( 3626 3614 3614 4 s 3631 403 0 )); +DATA(insert ( 3626 3614 3614 5 s 3632 403 0 )); + +/* + * GiST tsvector_ops + */ +DATA(insert ( 3655 3614 3615 1 s 3636 783 0 )); + +/* + * GIN tsvector_ops + */ +DATA(insert ( 3659 3614 3615 1 s 3636 2742 0 )); +DATA(insert ( 3659 3614 3615 2 s 3660 2742 0 )); + +/* + * CGIN tsvector_ops + */ +DATA(insert ( 4446 3614 3615 1 s 3636 4444 0 )); +DATA(insert ( 4446 3614 3615 2 s 3660 4444 0 )); + +/* + * btree tsquery_ops + */ +DATA(insert ( 3683 3615 3615 1 s 3674 403 0 )); +DATA(insert ( 3683 3615 3615 2 s 3675 403 0 )); +DATA(insert ( 3683 3615 3615 3 s 3676 403 0 )); +DATA(insert ( 3683 3615 3615 4 s 3678 403 0 )); +DATA(insert ( 3683 3615 3615 5 s 3679 403 0 )); + +/* + * GiST tsquery_ops + */ +DATA(insert ( 3702 3615 3615 7 s 3693 783 0 )); +DATA(insert ( 3702 3615 3615 8 s 3694 783 0 )); + +/* + * btree range_ops + */ +DATA(insert ( 3901 3831 3831 1 s 3884 403 0 )); +DATA(insert ( 3901 3831 3831 2 s 3885 403 0 )); +DATA(insert ( 3901 3831 3831 3 s 3882 403 0 )); +DATA(insert ( 3901 3831 3831 4 s 3886 403 0 )); +DATA(insert ( 3901 3831 3831 5 s 3887 403 0 )); + +/* + * hash range_ops + */ +DATA(insert ( 3903 3831 3831 1 s 3882 405 0 )); + +/* + * GiST range_ops + */ +DATA(insert ( 3919 3831 3831 1 s 3893 783 0 )); +DATA(insert ( 3919 3831 3831 2 s 3895 783 0 )); +DATA(insert ( 3919 3831 3831 3 s 3888 783 0 )); +DATA(insert ( 3919 3831 3831 4 s 3896 783 0 )); +DATA(insert ( 3919 3831 3831 5 s 3894 783 0 )); +DATA(insert ( 3919 3831 3831 6 s 3897 783 0 )); +DATA(insert ( 3919 3831 3831 7 s 3890 783 0 )); +DATA(insert ( 3919 3831 3831 8 s 3892 783 0 )); +DATA(insert ( 3919 3831 2283 16 s 3889 783 0 )); +DATA(insert ( 3919 3831 3831 18 s 3882 783 0 )); + +/* + * SP-GiST quad_point_ops + */ +DATA(insert ( 4015 600 600 11 s 506 4000 0 )); +DATA(insert ( 4015 600 600 1 s 507 4000 0 )); +DATA(insert ( 4015 600 600 5 s 508 4000 0 )); +DATA(insert ( 4015 600 600 10 s 509 4000 0 )); +DATA(insert ( 4015 600 600 6 s 510 4000 0 )); +DATA(insert ( 4015 600 603 8 s 511 4000 0 )); + +/* + * SP-GiST kd_point_ops + */ +DATA(insert ( 4016 600 600 11 s 506 4000 0 )); +DATA(insert ( 4016 600 600 1 s 507 4000 0 )); +DATA(insert ( 4016 600 600 5 s 508 4000 0 )); +DATA(insert ( 4016 600 600 10 s 509 4000 0 )); +DATA(insert ( 4016 600 600 6 s 510 4000 0 )); +DATA(insert ( 4016 600 603 8 s 511 4000 0 )); + +/* + * SP-GiST text_ops + */ +DATA(insert ( 4017 25 25 1 s 2314 4000 0 )); +DATA(insert ( 4017 25 25 2 s 2315 4000 0 )); +DATA(insert ( 4017 25 25 3 s 98 4000 0 )); +DATA(insert ( 4017 25 25 4 s 2317 4000 0 )); +DATA(insert ( 4017 25 25 5 s 2318 4000 0 )); +DATA(insert ( 4017 25 25 11 s 664 4000 0 )); +DATA(insert ( 4017 25 25 12 s 665 4000 0 )); +DATA(insert ( 4017 25 25 14 s 667 4000 0 )); +DATA(insert ( 4017 25 25 15 s 666 4000 0 )); +DATA(insert ( 5570 9003 9003 1 s 5552 403 0 )); +DATA(insert ( 5570 9003 9003 2 s 5553 403 0 )); +DATA(insert ( 5570 9003 9003 3 s 5550 403 0 )); +DATA(insert ( 5570 9003 9003 4 s 5549 403 0 )); +DATA(insert ( 5570 9003 9003 5 s 5554 403 0 )); +DATA(insert ( 5571 9003 9003 1 s 5550 405 0 )); + +/* psort, fake data just make index work */ +DATA(insert ( 4050 21 21 1 s 95 4039 0 )); +DATA(insert ( 4050 21 21 2 s 522 4039 0 )); +DATA(insert ( 4050 21 21 3 s 94 4039 0 )); +DATA(insert ( 4050 21 21 4 s 524 4039 0 )); +DATA(insert ( 4050 21 21 5 s 520 4039 0 )); + +DATA(insert ( 4050 21 23 1 s 534 4039 0 )); +DATA(insert ( 4050 21 23 2 s 540 4039 0 )); +DATA(insert ( 4050 21 23 3 s 532 4039 0 )); +DATA(insert ( 4050 21 23 4 s 542 4039 0 )); +DATA(insert ( 4050 21 23 5 s 536 4039 0 )); + +DATA(insert ( 4050 21 20 1 s 1864 4039 0 )); +DATA(insert ( 4050 21 20 2 s 1866 4039 0 )); +DATA(insert ( 4050 21 20 3 s 1862 4039 0 )); +DATA(insert ( 4050 21 20 4 s 1867 4039 0 )); +DATA(insert ( 4050 21 20 5 s 1865 4039 0 )); + +DATA(insert ( 4050 23 23 1 s 97 4039 0 )); +DATA(insert ( 4050 23 23 2 s 523 4039 0 )); +DATA(insert ( 4050 23 23 3 s 96 4039 0 )); +DATA(insert ( 4050 23 23 4 s 525 4039 0 )); +DATA(insert ( 4050 23 23 5 s 521 4039 0 )); + +DATA(insert ( 4050 23 21 1 s 535 4039 0 )); +DATA(insert ( 4050 23 21 2 s 541 4039 0 )); +DATA(insert ( 4050 23 21 3 s 533 4039 0 )); +DATA(insert ( 4050 23 21 4 s 543 4039 0 )); +DATA(insert ( 4050 23 21 5 s 537 4039 0 )); + +DATA(insert ( 4050 23 20 1 s 37 4039 0 )); +DATA(insert ( 4050 23 20 2 s 80 4039 0 )); +DATA(insert ( 4050 23 20 3 s 15 4039 0 )); +DATA(insert ( 4050 23 20 4 s 82 4039 0 )); +DATA(insert ( 4050 23 20 5 s 76 4039 0 )); + +DATA(insert ( 4050 20 20 1 s 412 4039 0 )); +DATA(insert ( 4050 20 20 2 s 414 4039 0 )); +DATA(insert ( 4050 20 20 3 s 410 4039 0 )); +DATA(insert ( 4050 20 20 4 s 415 4039 0 )); +DATA(insert ( 4050 20 20 5 s 413 4039 0 )); + +DATA(insert ( 4050 20 21 1 s 1870 4039 0 )); +DATA(insert ( 4050 20 21 2 s 1872 4039 0 )); +DATA(insert ( 4050 20 21 3 s 1868 4039 0 )); +DATA(insert ( 4050 20 21 4 s 1873 4039 0 )); +DATA(insert ( 4050 20 21 5 s 1871 4039 0 )); + +DATA(insert ( 4050 20 23 1 s 418 4039 0 )); +DATA(insert ( 4050 20 23 2 s 420 4039 0 )); +DATA(insert ( 4050 20 23 3 s 416 4039 0 )); +DATA(insert ( 4050 20 23 4 s 430 4039 0 )); +DATA(insert ( 4050 20 23 5 s 419 4039 0 )); + +DATA(insert ( 4051 26 26 1 s 609 4039 0 )); +DATA(insert ( 4051 26 26 2 s 611 4039 0 )); +DATA(insert ( 4051 26 26 3 s 607 4039 0 )); +DATA(insert ( 4051 26 26 4 s 612 4039 0 )); +DATA(insert ( 4051 26 26 5 s 610 4039 0 )); + +DATA(insert ( 4052 1082 1082 1 s 1095 4039 0 )); +DATA(insert ( 4052 1082 1082 2 s 1096 4039 0 )); +DATA(insert ( 4052 1082 1082 3 s 1093 4039 0 )); +DATA(insert ( 4052 1082 1082 4 s 1098 4039 0 )); +DATA(insert ( 4052 1082 1082 5 s 1097 4039 0 )); + +DATA(insert ( 4052 1082 1114 1 s 2345 4039 0 )); +DATA(insert ( 4052 1082 1114 2 s 2346 4039 0 )); +DATA(insert ( 4052 1082 1114 3 s 2347 4039 0 )); +DATA(insert ( 4052 1082 1114 4 s 2348 4039 0 )); +DATA(insert ( 4052 1082 1114 5 s 2349 4039 0 )); + +DATA(insert ( 4052 1082 1184 1 s 2358 4039 0 )); +DATA(insert ( 4052 1082 1184 2 s 2359 4039 0 )); +DATA(insert ( 4052 1082 1184 3 s 2360 4039 0 )); +DATA(insert ( 4052 1082 1184 4 s 2361 4039 0 )); +DATA(insert ( 4052 1082 1184 5 s 2362 4039 0 )); + +DATA(insert ( 4052 1114 1114 1 s 2062 4039 0 )); +DATA(insert ( 4052 1114 1114 2 s 2063 4039 0 )); +DATA(insert ( 4052 1114 1114 3 s 2060 4039 0 )); +DATA(insert ( 4052 1114 1114 4 s 2065 4039 0 )); +DATA(insert ( 4052 1114 1114 5 s 2064 4039 0 )); + +DATA(insert ( 4052 1114 1082 1 s 2371 4039 0 )); +DATA(insert ( 4052 1114 1082 2 s 2372 4039 0 )); +DATA(insert ( 4052 1114 1082 3 s 2373 4039 0 )); +DATA(insert ( 4052 1114 1082 4 s 2374 4039 0 )); +DATA(insert ( 4052 1114 1082 5 s 2375 4039 0 )); + +DATA(insert ( 4052 1114 1184 1 s 2534 4039 0 )); +DATA(insert ( 4052 1114 1184 2 s 2535 4039 0 )); +DATA(insert ( 4052 1114 1184 3 s 2536 4039 0 )); +DATA(insert ( 4052 1114 1184 4 s 2537 4039 0 )); +DATA(insert ( 4052 1114 1184 5 s 2538 4039 0 )); + +DATA(insert ( 4052 1184 1184 1 s 1322 4039 0 )); +DATA(insert ( 4052 1184 1184 2 s 1323 4039 0 )); +DATA(insert ( 4052 1184 1184 3 s 1320 4039 0 )); +DATA(insert ( 4052 1184 1184 4 s 1325 4039 0 )); +DATA(insert ( 4052 1184 1184 5 s 1324 4039 0 )); + +DATA(insert ( 4052 1184 1082 1 s 2384 4039 0 )); +DATA(insert ( 4052 1184 1082 2 s 2385 4039 0 )); +DATA(insert ( 4052 1184 1082 3 s 2386 4039 0 )); +DATA(insert ( 4052 1184 1082 4 s 2387 4039 0 )); +DATA(insert ( 4052 1184 1082 5 s 2388 4039 0 )); + +DATA(insert ( 4052 1184 1114 1 s 2540 4039 0 )); +DATA(insert ( 4052 1184 1114 2 s 2541 4039 0 )); +DATA(insert ( 4052 1184 1114 3 s 2542 4039 0 )); +DATA(insert ( 4052 1184 1114 4 s 2543 4039 0 )); +DATA(insert ( 4052 1184 1114 5 s 2544 4039 0 )); + +DATA(insert ( 4053 700 700 1 s 622 4039 0 )); +DATA(insert ( 4053 700 700 2 s 624 4039 0 )); +DATA(insert ( 4053 700 700 3 s 620 4039 0 )); +DATA(insert ( 4053 700 700 4 s 625 4039 0 )); +DATA(insert ( 4053 700 700 5 s 623 4039 0 )); + +DATA(insert ( 4053 700 701 1 s 1122 4039 0 )); +DATA(insert ( 4053 700 701 2 s 1124 4039 0 )); +DATA(insert ( 4053 700 701 3 s 1120 4039 0 )); +DATA(insert ( 4053 700 701 4 s 1125 4039 0 )); +DATA(insert ( 4053 700 701 5 s 1123 4039 0 )); + +DATA(insert ( 4053 701 701 1 s 672 4039 0 )); +DATA(insert ( 4053 701 701 2 s 673 4039 0 )); +DATA(insert ( 4053 701 701 3 s 670 4039 0 )); +DATA(insert ( 4053 701 701 4 s 675 4039 0 )); +DATA(insert ( 4053 701 701 5 s 674 4039 0 )); + +DATA(insert ( 4053 701 700 1 s 1132 4039 0 )); +DATA(insert ( 4053 701 700 2 s 1134 4039 0 )); +DATA(insert ( 4053 701 700 3 s 1130 4039 0 )); +DATA(insert ( 4053 701 700 4 s 1135 4039 0 )); +DATA(insert ( 4053 701 700 5 s 1133 4039 0 )); + +DATA(insert ( 4054 1700 1700 1 s 1754 4039 0 )); +DATA(insert ( 4054 1700 1700 2 s 1755 4039 0 )); +DATA(insert ( 4054 1700 1700 3 s 1752 4039 0 )); +DATA(insert ( 4054 1700 1700 4 s 1757 4039 0 )); +DATA(insert ( 4054 1700 1700 5 s 1756 4039 0 )); + +DATA(insert ( 4055 25 25 1 s 664 4039 0 )); +DATA(insert ( 4055 25 25 2 s 665 4039 0 )); +DATA(insert ( 4055 25 25 3 s 98 4039 0 )); +DATA(insert ( 4055 25 25 4 s 667 4039 0 )); +DATA(insert ( 4055 25 25 5 s 666 4039 0 )); + +DATA(insert ( 4056 1042 1042 1 s 1058 4039 0 )); +DATA(insert ( 4056 1042 1042 2 s 1059 4039 0 )); +DATA(insert ( 4056 1042 1042 3 s 1054 4039 0 )); +DATA(insert ( 4056 1042 1042 4 s 1061 4039 0 )); +DATA(insert ( 4056 1042 1042 5 s 1060 4039 0 )); + +DATA(insert ( 4057 1083 1083 1 s 1110 4039 0 )); +DATA(insert ( 4057 1083 1083 2 s 1111 4039 0 )); +DATA(insert ( 4057 1083 1083 3 s 1108 4039 0 )); +DATA(insert ( 4057 1083 1083 4 s 1113 4039 0 )); +DATA(insert ( 4057 1083 1083 5 s 1112 4039 0 )); + +DATA(insert ( 4058 1266 1266 1 s 1552 4039 0 )); +DATA(insert ( 4058 1266 1266 2 s 1553 4039 0 )); +DATA(insert ( 4058 1266 1266 3 s 1550 4039 0 )); +DATA(insert ( 4058 1266 1266 4 s 1555 4039 0 )); +DATA(insert ( 4058 1266 1266 5 s 1554 4039 0 )); + +DATA(insert ( 4059 790 790 1 s 902 4039 0 )); +DATA(insert ( 4059 790 790 2 s 904 4039 0 )); +DATA(insert ( 4059 790 790 3 s 900 4039 0 )); +DATA(insert ( 4059 790 790 4 s 905 4039 0 )); +DATA(insert ( 4059 790 790 5 s 903 4039 0 )); + +DATA(insert ( 4060 1186 1186 1 s 1332 4039 0 )); +DATA(insert ( 4060 1186 1186 2 s 1333 4039 0 )); +DATA(insert ( 4060 1186 1186 3 s 1330 4039 0 )); +DATA(insert ( 4060 1186 1186 4 s 1335 4039 0 )); +DATA(insert ( 4060 1186 1186 5 s 1334 4039 0 )); + +DATA(insert ( 4061 704 704 1 s 813 4039 0 )); +DATA(insert ( 4061 704 704 2 s 815 4039 0 )); +DATA(insert ( 4061 704 704 3 s 811 4039 0 )); +DATA(insert ( 4061 704 704 4 s 816 4039 0 )); +DATA(insert ( 4061 704 704 5 s 814 4039 0 )); + +DATA(insert ( 4062 5545 5545 1 s 5515 4039 0 )); +DATA(insert ( 4062 5545 5545 2 s 5516 4039 0 )); +DATA(insert ( 4062 5545 5545 3 s 5513 4039 0 )); +DATA(insert ( 4062 5545 5545 4 s 5518 4039 0 )); +DATA(insert ( 4062 5545 5545 5 s 5517 4039 0 )); + +DATA(insert ( 4063 16 16 1 s 58 4039 0 )); +DATA(insert ( 4063 16 16 2 s 1694 4039 0 )); +DATA(insert ( 4063 16 16 3 s 91 4039 0 )); +DATA(insert ( 4063 16 16 4 s 1695 4039 0 )); +DATA(insert ( 4063 16 16 5 s 59 4039 0 )); + +DATA(insert ( 4064 9003 9003 1 s 5552 4039 0 )); +DATA(insert ( 4064 9003 9003 2 s 5553 4039 0 )); +DATA(insert ( 4064 9003 9003 3 s 5550 4039 0 )); +DATA(insert ( 4064 9003 9003 4 s 5549 4039 0 )); +DATA(insert ( 4064 9003 9003 5 s 5554 4039 0 )); + +/* cbtree, fake data just make index work */ +DATA(insert ( 4250 21 21 1 s 95 4239 0 )); +DATA(insert ( 4250 21 21 2 s 522 4239 0 )); +DATA(insert ( 4250 21 21 3 s 94 4239 0 )); +DATA(insert ( 4250 21 21 4 s 524 4239 0 )); +DATA(insert ( 4250 21 21 5 s 520 4239 0 )); + +DATA(insert ( 4250 21 23 1 s 534 4239 0 )); +DATA(insert ( 4250 21 23 2 s 540 4239 0 )); +DATA(insert ( 4250 21 23 3 s 532 4239 0 )); +DATA(insert ( 4250 21 23 4 s 542 4239 0 )); +DATA(insert ( 4250 21 23 5 s 536 4239 0 )); + +DATA(insert ( 4250 21 20 1 s 1864 4239 0 )); +DATA(insert ( 4250 21 20 2 s 1866 4239 0 )); +DATA(insert ( 4250 21 20 3 s 1862 4239 0 )); +DATA(insert ( 4250 21 20 4 s 1867 4239 0 )); +DATA(insert ( 4250 21 20 5 s 1865 4239 0 )); + +DATA(insert ( 4250 23 23 1 s 97 4239 0 )); +DATA(insert ( 4250 23 23 2 s 523 4239 0 )); +DATA(insert ( 4250 23 23 3 s 96 4239 0 )); +DATA(insert ( 4250 23 23 4 s 525 4239 0 )); +DATA(insert ( 4250 23 23 5 s 521 4239 0 )); + +DATA(insert ( 4250 23 21 1 s 535 4239 0 )); +DATA(insert ( 4250 23 21 2 s 541 4239 0 )); +DATA(insert ( 4250 23 21 3 s 533 4239 0 )); +DATA(insert ( 4250 23 21 4 s 543 4239 0 )); +DATA(insert ( 4250 23 21 5 s 537 4239 0 )); + +DATA(insert ( 4250 23 20 1 s 37 4239 0 )); +DATA(insert ( 4250 23 20 2 s 80 4239 0 )); +DATA(insert ( 4250 23 20 3 s 15 4239 0 )); +DATA(insert ( 4250 23 20 4 s 82 4239 0 )); +DATA(insert ( 4250 23 20 5 s 76 4239 0 )); + +DATA(insert ( 4250 20 20 1 s 412 4239 0 )); +DATA(insert ( 4250 20 20 2 s 414 4239 0 )); +DATA(insert ( 4250 20 20 3 s 410 4239 0 )); +DATA(insert ( 4250 20 20 4 s 415 4239 0 )); +DATA(insert ( 4250 20 20 5 s 413 4239 0 )); + +DATA(insert ( 4250 20 21 1 s 1870 4239 0 )); +DATA(insert ( 4250 20 21 2 s 1872 4239 0 )); +DATA(insert ( 4250 20 21 3 s 1868 4239 0 )); +DATA(insert ( 4250 20 21 4 s 1873 4239 0 )); +DATA(insert ( 4250 20 21 5 s 1871 4239 0 )); + +DATA(insert ( 4250 20 23 1 s 418 4239 0 )); +DATA(insert ( 4250 20 23 2 s 420 4239 0 )); +DATA(insert ( 4250 20 23 3 s 416 4239 0 )); +DATA(insert ( 4250 20 23 4 s 430 4239 0 )); +DATA(insert ( 4250 20 23 5 s 419 4239 0 )); + +DATA(insert ( 4251 26 26 1 s 609 4239 0 )); +DATA(insert ( 4251 26 26 2 s 611 4239 0 )); +DATA(insert ( 4251 26 26 3 s 607 4239 0 )); +DATA(insert ( 4251 26 26 4 s 612 4239 0 )); +DATA(insert ( 4251 26 26 5 s 610 4239 0 )); + +DATA(insert ( 4252 1082 1082 1 s 1095 4239 0 )); +DATA(insert ( 4252 1082 1082 2 s 1096 4239 0 )); +DATA(insert ( 4252 1082 1082 3 s 1093 4239 0 )); +DATA(insert ( 4252 1082 1082 4 s 1098 4239 0 )); +DATA(insert ( 4252 1082 1082 5 s 1097 4239 0 )); + +DATA(insert ( 4252 1082 1114 1 s 2345 4239 0 )); +DATA(insert ( 4252 1082 1114 2 s 2346 4239 0 )); +DATA(insert ( 4252 1082 1114 3 s 2347 4239 0 )); +DATA(insert ( 4252 1082 1114 4 s 2348 4239 0 )); +DATA(insert ( 4252 1082 1114 5 s 2349 4239 0 )); + +DATA(insert ( 4252 1082 1184 1 s 2358 4239 0 )); +DATA(insert ( 4252 1082 1184 2 s 2359 4239 0 )); +DATA(insert ( 4252 1082 1184 3 s 2360 4239 0 )); +DATA(insert ( 4252 1082 1184 4 s 2361 4239 0 )); +DATA(insert ( 4252 1082 1184 5 s 2362 4239 0 )); + +DATA(insert ( 4252 1114 1114 1 s 2062 4239 0 )); +DATA(insert ( 4252 1114 1114 2 s 2063 4239 0 )); +DATA(insert ( 4252 1114 1114 3 s 2060 4239 0 )); +DATA(insert ( 4252 1114 1114 4 s 2065 4239 0 )); +DATA(insert ( 4252 1114 1114 5 s 2064 4239 0 )); + +DATA(insert ( 4252 1114 1082 1 s 2371 4239 0 )); +DATA(insert ( 4252 1114 1082 2 s 2372 4239 0 )); +DATA(insert ( 4252 1114 1082 3 s 2373 4239 0 )); +DATA(insert ( 4252 1114 1082 4 s 2374 4239 0 )); +DATA(insert ( 4252 1114 1082 5 s 2375 4239 0 )); + +DATA(insert ( 4252 1114 1184 1 s 2534 4239 0 )); +DATA(insert ( 4252 1114 1184 2 s 2535 4239 0 )); +DATA(insert ( 4252 1114 1184 3 s 2536 4239 0 )); +DATA(insert ( 4252 1114 1184 4 s 2537 4239 0 )); +DATA(insert ( 4252 1114 1184 5 s 2538 4239 0 )); + +DATA(insert ( 4252 1184 1184 1 s 1322 4239 0 )); +DATA(insert ( 4252 1184 1184 2 s 1323 4239 0 )); +DATA(insert ( 4252 1184 1184 3 s 1320 4239 0 )); +DATA(insert ( 4252 1184 1184 4 s 1325 4239 0 )); +DATA(insert ( 4252 1184 1184 5 s 1324 4239 0 )); + +DATA(insert ( 4252 1184 1082 1 s 2384 4239 0 )); +DATA(insert ( 4252 1184 1082 2 s 2385 4239 0 )); +DATA(insert ( 4252 1184 1082 3 s 2386 4239 0 )); +DATA(insert ( 4252 1184 1082 4 s 2387 4239 0 )); +DATA(insert ( 4252 1184 1082 5 s 2388 4239 0 )); + +DATA(insert ( 4252 1184 1114 1 s 2540 4239 0 )); +DATA(insert ( 4252 1184 1114 2 s 2541 4239 0 )); +DATA(insert ( 4252 1184 1114 3 s 2542 4239 0 )); +DATA(insert ( 4252 1184 1114 4 s 2543 4239 0 )); +DATA(insert ( 4252 1184 1114 5 s 2544 4239 0 )); + +DATA(insert ( 4253 700 700 1 s 622 4239 0 )); +DATA(insert ( 4253 700 700 2 s 624 4239 0 )); +DATA(insert ( 4253 700 700 3 s 620 4239 0 )); +DATA(insert ( 4253 700 700 4 s 625 4239 0 )); +DATA(insert ( 4253 700 700 5 s 623 4239 0 )); + +DATA(insert ( 4253 700 701 1 s 1122 4239 0 )); +DATA(insert ( 4253 700 701 2 s 1124 4239 0 )); +DATA(insert ( 4253 700 701 3 s 1120 4239 0 )); +DATA(insert ( 4253 700 701 4 s 1125 4239 0 )); +DATA(insert ( 4253 700 701 5 s 1123 4239 0 )); + +DATA(insert ( 4253 701 701 1 s 672 4239 0 )); +DATA(insert ( 4253 701 701 2 s 673 4239 0 )); +DATA(insert ( 4253 701 701 3 s 670 4239 0 )); +DATA(insert ( 4253 701 701 4 s 675 4239 0 )); +DATA(insert ( 4253 701 701 5 s 674 4239 0 )); + +DATA(insert ( 4253 701 700 1 s 1132 4239 0 )); +DATA(insert ( 4253 701 700 2 s 1134 4239 0 )); +DATA(insert ( 4253 701 700 3 s 1130 4239 0 )); +DATA(insert ( 4253 701 700 4 s 1135 4239 0 )); +DATA(insert ( 4253 701 700 5 s 1133 4239 0 )); + +DATA(insert ( 4254 1700 1700 1 s 1754 4239 0 )); +DATA(insert ( 4254 1700 1700 2 s 1755 4239 0 )); +DATA(insert ( 4254 1700 1700 3 s 1752 4239 0 )); +DATA(insert ( 4254 1700 1700 4 s 1757 4239 0 )); +DATA(insert ( 4254 1700 1700 5 s 1756 4239 0 )); + +DATA(insert ( 4255 25 25 1 s 664 4239 0 )); +DATA(insert ( 4255 25 25 2 s 665 4239 0 )); +DATA(insert ( 4255 25 25 3 s 98 4239 0 )); +DATA(insert ( 4255 25 25 4 s 667 4239 0 )); +DATA(insert ( 4255 25 25 5 s 666 4239 0 )); + +DATA(insert ( 4256 1042 1042 1 s 1058 4239 0 )); +DATA(insert ( 4256 1042 1042 2 s 1059 4239 0 )); +DATA(insert ( 4256 1042 1042 3 s 1054 4239 0 )); +DATA(insert ( 4256 1042 1042 4 s 1061 4239 0 )); +DATA(insert ( 4256 1042 1042 5 s 1060 4239 0 )); + +DATA(insert ( 4257 1083 1083 1 s 1110 4239 0 )); +DATA(insert ( 4257 1083 1083 2 s 1111 4239 0 )); +DATA(insert ( 4257 1083 1083 3 s 1108 4239 0 )); +DATA(insert ( 4257 1083 1083 4 s 1113 4239 0 )); +DATA(insert ( 4257 1083 1083 5 s 1112 4239 0 )); + +DATA(insert ( 4258 1266 1266 1 s 1552 4239 0 )); +DATA(insert ( 4258 1266 1266 2 s 1553 4239 0 )); +DATA(insert ( 4258 1266 1266 3 s 1550 4239 0 )); +DATA(insert ( 4258 1266 1266 4 s 1555 4239 0 )); +DATA(insert ( 4258 1266 1266 5 s 1554 4239 0 )); + +DATA(insert ( 4259 790 790 1 s 902 4239 0 )); +DATA(insert ( 4259 790 790 2 s 904 4239 0 )); +DATA(insert ( 4259 790 790 3 s 900 4239 0 )); +DATA(insert ( 4259 790 790 4 s 905 4239 0 )); +DATA(insert ( 4259 790 790 5 s 903 4239 0 )); + +DATA(insert ( 4260 1186 1186 1 s 1332 4239 0 )); +DATA(insert ( 4260 1186 1186 2 s 1333 4239 0 )); +DATA(insert ( 4260 1186 1186 3 s 1330 4239 0 )); +DATA(insert ( 4260 1186 1186 4 s 1335 4239 0 )); +DATA(insert ( 4260 1186 1186 5 s 1334 4239 0 )); + +DATA(insert ( 4261 704 704 1 s 813 4239 0 )); +DATA(insert ( 4261 704 704 2 s 815 4239 0 )); +DATA(insert ( 4261 704 704 3 s 811 4239 0 )); +DATA(insert ( 4261 704 704 4 s 816 4239 0 )); +DATA(insert ( 4261 704 704 5 s 814 4239 0 )); + +DATA(insert ( 4262 5545 5545 1 s 5515 4239 0 )); +DATA(insert ( 4262 5545 5545 2 s 5516 4239 0 )); +DATA(insert ( 4262 5545 5545 3 s 5513 4239 0 )); +DATA(insert ( 4262 5545 5545 4 s 5518 4239 0 )); +DATA(insert ( 4262 5545 5545 5 s 5517 4239 0 )); + +DATA(insert ( 4263 16 16 1 s 58 4239 0 )); +DATA(insert ( 4263 16 16 2 s 1694 4239 0 )); +DATA(insert ( 4263 16 16 3 s 91 4239 0 )); +DATA(insert ( 4263 16 16 4 s 1695 4239 0 )); +DATA(insert ( 4263 16 16 5 s 59 4239 0 )); + +DATA(insert ( 4264 9003 9003 1 s 5552 4239 0 )); +DATA(insert ( 4264 9003 9003 2 s 5553 4239 0 )); +DATA(insert ( 4264 9003 9003 3 s 5550 4239 0 )); +DATA(insert ( 4264 9003 9003 4 s 5549 4239 0 )); +DATA(insert ( 4264 9003 9003 5 s 5554 4239 0 )); + +#endif /* PG_AMOP_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_amproc.h postgresql-hll-2.14/include/catalog/pg_amproc.h --- postgresql-hll-2.14_old/include/catalog/pg_amproc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_amproc.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,501 @@ +/* ------------------------------------------------------------------------- + * + * pg_amproc.h + * definition of the system "amproc" relation (pg_amproc) + * along with the relation's initial contents. + * + * The amproc table identifies support procedures associated with index + * operator families and classes. These procedures can't be listed in pg_amop + * since they are not the implementation of any indexable operator. + * + * The primary key for this table is . The "default" support functions for a + * particular opclass within the family are those with amproclefttype = + * amprocrighttype = opclass's opcintype. These are the ones loaded into the + * relcache for an index and typically used for internal index operations. + * Other support functions are typically used to handle cross-type indexable + * operators with oprleft/oprright matching the entry's amproclefttype and + * amprocrighttype. The exact behavior depends on the index AM, however, and + * some don't pay attention to non-default functions at all. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_amproc.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AMPROC_H +#define PG_AMPROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_amproc definition. cpp turns this into + * typedef struct FormData_pg_amproc + * ---------------- + */ +#define AccessMethodProcedureRelationId 2603 +#define AccessMethodProcedureRelation_Rowtype_Id 10920 + +CATALOG(pg_amproc,2603) BKI_SCHEMA_MACRO +{ + Oid amprocfamily; /* the index opfamily this entry is for */ + Oid amproclefttype; /* procedure's left input data type */ + Oid amprocrighttype; /* procedure's right input data type */ + int2 amprocnum; /* support procedure index */ + regproc amproc; /* OID of the proc */ +} FormData_pg_amproc; + +/* ---------------- + * Form_pg_amproc corresponds to a pointer to a tuple with + * the format of pg_amproc relation. + * ---------------- + */ +typedef FormData_pg_amproc *Form_pg_amproc; + +/* ---------------- + * compiler constants for pg_amproc + * ---------------- + */ +#define Natts_pg_amproc 5 +#define Anum_pg_amproc_amprocfamily 1 +#define Anum_pg_amproc_amproclefttype 2 +#define Anum_pg_amproc_amprocrighttype 3 +#define Anum_pg_amproc_amprocnum 4 +#define Anum_pg_amproc_amproc 5 + +/* ---------------- + * initial contents of pg_amproc + * ---------------- + */ + +/* btree */ +DATA(insert ( 397 2277 2277 1 382 )); +DATA(insert ( 421 702 702 1 357 )); +DATA(insert ( 423 1560 1560 1 1596 )); +DATA(insert ( 424 16 16 1 1693 )); +DATA(insert ( 426 1042 1042 1 1078 )); +DATA(insert ( 426 1042 1042 2 3256 )); +DATA(insert ( 428 17 17 1 1954 )); +DATA(insert ( 428 17 17 2 3452 )); +DATA(insert ( 429 18 18 1 358 )); +DATA(insert ( 434 1082 1082 1 1092 )); +DATA(insert ( 434 1082 1082 2 3136 )); +DATA(insert ( 434 1082 1114 1 2344 )); +DATA(insert ( 434 1082 1184 1 2357 )); +DATA(insert ( 434 1114 1114 1 2045 )); +DATA(insert ( 434 1114 1114 2 3137 )); +DATA(insert ( 434 1114 1082 1 2370 )); +DATA(insert ( 434 1114 1184 1 2526 )); +DATA(insert ( 434 1184 1184 1 1314 )); +DATA(insert ( 434 1184 1184 2 3137 )); +DATA(insert ( 434 1184 1082 1 2383 )); +DATA(insert ( 434 1184 1114 1 2533 )); +DATA(insert ( 436 4402 4402 1 4418 )); +DATA(insert ( 436 4402 4402 2 3452 )); +DATA(insert ( 1970 700 700 1 354 )); +DATA(insert ( 1970 700 700 2 3132 )); +DATA(insert ( 1970 700 701 1 2194 )); +DATA(insert ( 1970 701 701 1 355 )); +DATA(insert ( 1970 701 701 2 3133 )); +DATA(insert ( 1970 701 700 1 2195 )); +DATA(insert ( 1974 869 869 1 926 )); +DATA(insert ( 1976 21 21 1 350 )); +DATA(insert ( 1976 21 21 2 3129 )); +DATA(insert ( 1976 21 23 1 2190 )); +DATA(insert ( 1976 21 20 1 2192 )); +DATA(insert ( 1976 23 23 1 351 )); +DATA(insert ( 1976 23 23 2 3130 )); +DATA(insert ( 1976 23 20 1 2188 )); +DATA(insert ( 1976 23 21 1 2191 )); +DATA(insert ( 1976 20 20 1 842 )); +DATA(insert ( 1976 20 20 2 3131 )); +DATA(insert ( 1976 20 23 1 2189 )); +DATA(insert ( 1976 20 21 1 2193 )); +DATA(insert ( 1982 1186 1186 1 1315 )); +DATA(insert ( 1984 829 829 1 836 )); +DATA(insert ( 1986 19 19 1 359 )); +DATA(insert ( 1986 19 19 2 3135 )); +DATA(insert ( 1988 1700 1700 1 1769 )); +DATA(insert ( 1988 1700 1700 2 3283 )); +DATA(insert ( 1989 26 26 1 356 )); +DATA(insert ( 1989 26 26 2 3134 )); +DATA(insert ( 1991 30 30 1 404 )); +DATA(insert ( 2994 2249 2249 1 2987 )); +DATA(insert ( 1994 25 25 1 360 )); +DATA(insert ( 1994 25 25 2 3255 )); +DATA(insert ( 1996 1083 1083 1 1107 )); +DATA(insert ( 2000 1266 1266 1 1358 )); +DATA(insert ( 2002 1562 1562 1 1672 )); +DATA(insert ( 2095 25 25 1 2166 )); +DATA(insert ( 2097 1042 1042 1 2180 )); +DATA(insert ( 2099 790 790 1 377 )); +DATA(insert ( 2233 703 703 1 380 )); +DATA(insert ( 2234 704 704 1 381 )); +DATA(insert ( 2789 27 27 1 2794 )); +DATA(insert ( 2968 2950 2950 1 2960 )); +DATA(insert ( 3522 3500 3500 1 3514 )); + +DATA(insert ( 3806 86 86 1 3475 )); +DATA(insert ( 3807 86 86 1 456 )); +DATA(insert ( 5535 5545 5545 1 5519 )); +DATA(insert ( 5536 5545 5545 1 5520 )); +/* hash */ +DATA(insert ( 427 1042 1042 1 1080 )); +DATA(insert ( 431 18 18 1 454 )); +DATA(insert ( 435 1082 1082 1 450 )); +DATA(insert ( 627 2277 2277 1 626 )); +DATA(insert ( 1971 700 700 1 451 )); +DATA(insert ( 1971 701 701 1 452 )); +DATA(insert ( 1975 869 869 1 422 )); +DATA(insert ( 1977 21 21 1 449 )); +DATA(insert ( 1977 23 23 1 450 )); +DATA(insert ( 1977 20 20 1 949 )); +DATA(insert ( 1983 1186 1186 1 1697 )); +DATA(insert ( 1985 829 829 1 399 )); +DATA(insert ( 1987 19 19 1 455 )); +DATA(insert ( 1990 26 26 1 453 )); +DATA(insert ( 1992 30 30 1 457 )); +DATA(insert ( 1995 25 25 1 400 )); +DATA(insert ( 1997 1083 1083 1 1688 )); +DATA(insert ( 1998 1700 1700 1 432 )); +DATA(insert ( 1999 1184 1184 1 2039 )); +DATA(insert ( 2001 1266 1266 1 1696 )); +DATA(insert ( 2040 1114 1114 1 2039 )); +DATA(insert ( 2222 16 16 1 454 )); +DATA(insert ( 2223 17 17 1 456 )); +DATA(insert ( 4470 4402 4402 1 456 )); +DATA(insert ( 2224 22 22 1 398 )); +DATA(insert ( 2225 28 28 1 949 )); +DATA(insert ( 2226 29 29 1 450 )); +DATA(insert ( 2227 702 702 1 450 )); +DATA(insert ( 2228 703 703 1 450 )); +DATA(insert ( 2229 25 25 1 400 )); +DATA(insert ( 2231 1042 1042 1 1080 )); +DATA(insert ( 2232 31 31 1 450 )); +DATA(insert ( 2235 1033 1033 1 329 )); +DATA(insert ( 2969 2950 2950 1 2963 )); +DATA(insert ( 3523 3500 3500 1 3515 )); + + +/* gist */ +DATA(insert ( 2593 603 603 1 2578 )); +DATA(insert ( 2593 603 603 2 2583 )); +DATA(insert ( 2593 603 603 3 2579 )); +DATA(insert ( 2593 603 603 4 2580 )); +DATA(insert ( 2593 603 603 5 2581 )); +DATA(insert ( 2593 603 603 6 2582 )); +DATA(insert ( 2593 603 603 7 2584 )); +DATA(insert ( 2594 604 604 1 2585 )); +DATA(insert ( 2594 604 604 2 2583 )); +DATA(insert ( 2594 604 604 3 2586 )); +DATA(insert ( 2594 604 604 4 2580 )); +DATA(insert ( 2594 604 604 5 2581 )); +DATA(insert ( 2594 604 604 6 2582 )); +DATA(insert ( 2594 604 604 7 2584 )); +DATA(insert ( 2595 718 718 1 2591 )); +DATA(insert ( 2595 718 718 2 2583 )); +DATA(insert ( 2595 718 718 3 2592 )); +DATA(insert ( 2595 718 718 4 2580 )); +DATA(insert ( 2595 718 718 5 2581 )); +DATA(insert ( 2595 718 718 6 2582 )); +DATA(insert ( 2595 718 718 7 2584 )); +DATA(insert ( 3655 3614 3614 1 3654 )); +DATA(insert ( 3655 3614 3614 2 3651 )); +DATA(insert ( 3655 3614 3614 3 3648 )); +DATA(insert ( 3655 3614 3614 4 3649 )); +DATA(insert ( 3655 3614 3614 5 3653 )); +DATA(insert ( 3655 3614 3614 6 3650 )); +DATA(insert ( 3655 3614 3614 7 3652 )); +DATA(insert ( 3702 3615 3615 1 3701 )); +DATA(insert ( 3702 3615 3615 2 3698 )); +DATA(insert ( 3702 3615 3615 3 3695 )); +DATA(insert ( 3702 3615 3615 4 3696 )); +DATA(insert ( 3702 3615 3615 5 3700 )); +DATA(insert ( 3702 3615 3615 6 3697 )); +DATA(insert ( 3702 3615 3615 7 3699 )); +DATA(insert ( 1029 600 600 1 2179 )); +DATA(insert ( 1029 600 600 2 2583 )); +DATA(insert ( 1029 600 600 3 1030 )); +DATA(insert ( 1029 600 600 4 2580 )); +DATA(insert ( 1029 600 600 5 2581 )); +DATA(insert ( 1029 600 600 6 2582 )); +DATA(insert ( 1029 600 600 7 2584 )); +DATA(insert ( 1029 600 600 8 3064 )); + + +/* gin */ +DATA(insert ( 2745 1007 1007 1 351 )); +DATA(insert ( 2745 1007 1007 2 2743 )); +DATA(insert ( 2745 1007 1007 3 2774 )); +DATA(insert ( 2745 1007 1007 4 2744 )); +DATA(insert ( 2745 1007 1007 6 3920 )); +DATA(insert ( 2745 1009 1009 1 360 )); +DATA(insert ( 2745 1009 1009 2 2743 )); +DATA(insert ( 2745 1009 1009 3 2774 )); +DATA(insert ( 2745 1009 1009 4 2744 )); +DATA(insert ( 2745 1009 1009 6 3920 )); +DATA(insert ( 2745 1015 1015 1 360 )); +DATA(insert ( 2745 1015 1015 2 2743 )); +DATA(insert ( 2745 1015 1015 3 2774 )); +DATA(insert ( 2745 1015 1015 4 2744 )); +DATA(insert ( 2745 1015 1015 6 3920 )); +DATA(insert ( 2745 1023 1023 1 357 )); +DATA(insert ( 2745 1023 1023 2 2743 )); +DATA(insert ( 2745 1023 1023 3 2774 )); +DATA(insert ( 2745 1023 1023 4 2744 )); +DATA(insert ( 2745 1023 1023 6 3920 )); +DATA(insert ( 2745 1561 1561 1 1596 )); +DATA(insert ( 2745 1561 1561 2 2743 )); +DATA(insert ( 2745 1561 1561 3 2774 )); +DATA(insert ( 2745 1561 1561 4 2744 )); +DATA(insert ( 2745 1561 1561 6 3920 )); +DATA(insert ( 2745 1000 1000 1 1693 )); +DATA(insert ( 2745 1000 1000 2 2743 )); +DATA(insert ( 2745 1000 1000 3 2774 )); +DATA(insert ( 2745 1000 1000 4 2744 )); +DATA(insert ( 2745 1000 1000 6 3920 )); +DATA(insert ( 2745 1014 1014 1 1078 )); +DATA(insert ( 2745 1014 1014 2 2743 )); +DATA(insert ( 2745 1014 1014 3 2774 )); +DATA(insert ( 2745 1014 1014 4 2744 )); +DATA(insert ( 2745 1014 1014 6 3920 )); +DATA(insert ( 2745 1001 1001 1 1954 )); +DATA(insert ( 2745 1001 1001 2 2743 )); +DATA(insert ( 2745 1001 1001 3 2774 )); +DATA(insert ( 2745 1001 1001 4 2744 )); +DATA(insert ( 2745 1001 1001 6 3920 )); +DATA(insert ( 2745 1002 1002 1 358 )); +DATA(insert ( 2745 1002 1002 2 2743 )); +DATA(insert ( 2745 1002 1002 3 2774 )); +DATA(insert ( 2745 1002 1002 4 2744 )); +DATA(insert ( 2745 1002 1002 6 3920 )); +DATA(insert ( 2745 1182 1182 1 1092 )); +DATA(insert ( 2745 1182 1182 2 2743 )); +DATA(insert ( 2745 1182 1182 3 2774 )); +DATA(insert ( 2745 1182 1182 4 2744 )); +DATA(insert ( 2745 1182 1182 6 3920 )); +DATA(insert ( 2745 1021 1021 1 354 )); +DATA(insert ( 2745 1021 1021 2 2743 )); +DATA(insert ( 2745 1021 1021 3 2774 )); +DATA(insert ( 2745 1021 1021 4 2744 )); +DATA(insert ( 2745 1021 1021 6 3920 )); +DATA(insert ( 2745 1022 1022 1 355 )); +DATA(insert ( 2745 1022 1022 2 2743 )); +DATA(insert ( 2745 1022 1022 3 2774 )); +DATA(insert ( 2745 1022 1022 4 2744 )); +DATA(insert ( 2745 1022 1022 6 3920 )); +DATA(insert ( 2745 1041 1041 1 926 )); +DATA(insert ( 2745 1041 1041 2 2743 )); +DATA(insert ( 2745 1041 1041 3 2774 )); +DATA(insert ( 2745 1041 1041 4 2744 )); +DATA(insert ( 2745 1041 1041 6 3920 )); +DATA(insert ( 2745 651 651 1 926 )); +DATA(insert ( 2745 651 651 2 2743 )); +DATA(insert ( 2745 651 651 3 2774 )); +DATA(insert ( 2745 651 651 4 2744 )); +DATA(insert ( 2745 651 651 6 3920 )); +DATA(insert ( 2745 1005 1005 1 350 )); +DATA(insert ( 2745 1005 1005 2 2743 )); +DATA(insert ( 2745 1005 1005 3 2774 )); +DATA(insert ( 2745 1005 1005 4 2744 )); +DATA(insert ( 2745 1005 1005 6 3920 )); +DATA(insert ( 2745 1016 1016 1 842 )); +DATA(insert ( 2745 1016 1016 2 2743 )); +DATA(insert ( 2745 1016 1016 3 2774 )); +DATA(insert ( 2745 1016 1016 4 2744 )); +DATA(insert ( 2745 1016 1016 6 3920 )); +DATA(insert ( 2745 1187 1187 1 1315 )); +DATA(insert ( 2745 1187 1187 2 2743 )); +DATA(insert ( 2745 1187 1187 3 2774 )); +DATA(insert ( 2745 1187 1187 4 2744 )); +DATA(insert ( 2745 1187 1187 6 3920 )); +DATA(insert ( 2745 1040 1040 1 836 )); +DATA(insert ( 2745 1040 1040 2 2743 )); +DATA(insert ( 2745 1040 1040 3 2774 )); +DATA(insert ( 2745 1040 1040 4 2744 )); +DATA(insert ( 2745 1040 1040 6 3920 )); +DATA(insert ( 2745 1003 1003 1 359 )); +DATA(insert ( 2745 1003 1003 2 2743 )); +DATA(insert ( 2745 1003 1003 3 2774 )); +DATA(insert ( 2745 1003 1003 4 2744 )); +DATA(insert ( 2745 1003 1003 6 3920 )); +DATA(insert ( 2745 1231 1231 1 1769 )); +DATA(insert ( 2745 1231 1231 2 2743 )); +DATA(insert ( 2745 1231 1231 3 2774 )); +DATA(insert ( 2745 1231 1231 4 2744 )); +DATA(insert ( 2745 1231 1231 6 3920 )); +DATA(insert ( 2745 1028 1028 1 356 )); +DATA(insert ( 2745 1028 1028 2 2743 )); +DATA(insert ( 2745 1028 1028 3 2774 )); +DATA(insert ( 2745 1028 1028 4 2744 )); +DATA(insert ( 2745 1028 1028 6 3920 )); +DATA(insert ( 2745 1013 1013 1 404 )); +DATA(insert ( 2745 1013 1013 2 2743 )); +DATA(insert ( 2745 1013 1013 3 2774 )); +DATA(insert ( 2745 1013 1013 4 2744 )); +DATA(insert ( 2745 1013 1013 6 3920 )); +DATA(insert ( 2745 1183 1183 1 1107 )); +DATA(insert ( 2745 1183 1183 2 2743 )); +DATA(insert ( 2745 1183 1183 3 2774 )); +DATA(insert ( 2745 1183 1183 4 2744 )); +DATA(insert ( 2745 1183 1183 6 3920 )); +DATA(insert ( 2745 1185 1185 1 1314 )); +DATA(insert ( 2745 1185 1185 2 2743 )); +DATA(insert ( 2745 1185 1185 3 2774 )); +DATA(insert ( 2745 1185 1185 4 2744 )); +DATA(insert ( 2745 1185 1185 6 3920 )); +DATA(insert ( 2745 1270 1270 1 1358 )); +DATA(insert ( 2745 1270 1270 2 2743 )); +DATA(insert ( 2745 1270 1270 3 2774 )); +DATA(insert ( 2745 1270 1270 4 2744 )); +DATA(insert ( 2745 1270 1270 6 3920 )); +DATA(insert ( 2745 1563 1563 1 1672 )); +DATA(insert ( 2745 1563 1563 2 2743 )); +DATA(insert ( 2745 1563 1563 3 2774 )); +DATA(insert ( 2745 1563 1563 4 2744 )); +DATA(insert ( 2745 1563 1563 6 3920 )); +DATA(insert ( 2745 1115 1115 1 2045 )); +DATA(insert ( 2745 1115 1115 2 2743 )); +DATA(insert ( 2745 1115 1115 3 2774 )); +DATA(insert ( 2745 1115 1115 4 2744 )); +DATA(insert ( 2745 1115 1115 6 3920 )); +DATA(insert ( 2745 791 791 1 377 )); +DATA(insert ( 2745 791 791 2 2743 )); +DATA(insert ( 2745 791 791 3 2774 )); +DATA(insert ( 2745 791 791 4 2744 )); +DATA(insert ( 2745 791 791 6 3920 )); +DATA(insert ( 2745 1024 1024 1 380 )); +DATA(insert ( 2745 1024 1024 2 2743 )); +DATA(insert ( 2745 1024 1024 3 2774 )); +DATA(insert ( 2745 1024 1024 4 2744 )); +DATA(insert ( 2745 1024 1024 6 3920 )); +DATA(insert ( 2745 1025 1025 1 381 )); +DATA(insert ( 2745 1025 1025 2 2743 )); +DATA(insert ( 2745 1025 1025 3 2774 )); +DATA(insert ( 2745 1025 1025 4 2744 )); +DATA(insert ( 2745 1025 1025 6 3920 )); +DATA(insert ( 3659 3614 3614 1 3724 )); +DATA(insert ( 3659 3614 3614 2 3656 )); +DATA(insert ( 3659 3614 3614 3 3657 )); +DATA(insert ( 3659 3614 3614 4 3658 )); +DATA(insert ( 3659 3614 3614 5 2700 )); +DATA(insert ( 3659 3614 3614 6 3921 )); +DATA(insert ( 3626 3614 3614 1 3622 )); +DATA(insert ( 3683 3615 3615 1 3668 )); +DATA(insert ( 3901 3831 3831 1 3870 )); +DATA(insert ( 3903 3831 3831 1 3902 )); +DATA(insert ( 3919 3831 3831 1 3875 )); +DATA(insert ( 3919 3831 3831 2 3876 )); +DATA(insert ( 3919 3831 3831 3 3877 )); +DATA(insert ( 3919 3831 3831 4 3878 )); +DATA(insert ( 3919 3831 3831 5 3879 )); +DATA(insert ( 3919 3831 3831 6 3880 )); +DATA(insert ( 3919 3831 3831 7 3881 )); + +/* cgin */ +DATA(insert ( 4446 3614 3614 1 3724 )); +DATA(insert ( 4446 3614 3614 2 3656 )); +DATA(insert ( 4446 3614 3614 3 3657 )); +DATA(insert ( 4446 3614 3614 4 3658 )); +DATA(insert ( 4446 3614 3614 5 2700 )); +DATA(insert ( 4446 3614 3614 6 3921 )); + +/* sp-gist */ +DATA(insert ( 4015 600 600 1 4018 )); +DATA(insert ( 4015 600 600 2 4019 )); +DATA(insert ( 4015 600 600 3 4020 )); +DATA(insert ( 4015 600 600 4 4021 )); +DATA(insert ( 4015 600 600 5 4022 )); +DATA(insert ( 4016 600 600 1 4023 )); +DATA(insert ( 4016 600 600 2 4024 )); +DATA(insert ( 4016 600 600 3 4025 )); +DATA(insert ( 4016 600 600 4 4026 )); +DATA(insert ( 4016 600 600 5 4022 )); +DATA(insert ( 4017 25 25 1 4027 )); +DATA(insert ( 4017 25 25 2 4028 )); +DATA(insert ( 4017 25 25 3 4029 )); +DATA(insert ( 4017 25 25 4 4030 )); +DATA(insert ( 4017 25 25 5 4031 )); +DATA(insert ( 5570 9003 9003 1 5586 )); +DATA(insert ( 5571 9003 9003 1 5587 )); + +/* psort, fake data just make index work */ +DATA(insert ( 4050 21 21 1 350)); +DATA(insert ( 4050 21 23 1 2190)); +DATA(insert ( 4050 21 20 1 2192)); +DATA(insert ( 4050 23 23 1 351)); +DATA(insert ( 4050 23 20 1 2188)); +DATA(insert ( 4050 23 21 1 2191)); +DATA(insert ( 4050 20 20 1 842)); +DATA(insert ( 4050 20 23 1 2189)); +DATA(insert ( 4050 20 21 1 2193)); +DATA(insert ( 4051 26 26 1 356)); +DATA(insert ( 4052 1082 1082 1 1092)); +DATA(insert ( 4052 1082 1114 1 2344)); +DATA(insert ( 4052 1082 1184 1 2357)); +DATA(insert ( 4052 1114 1114 1 2045)); +DATA(insert ( 4052 1114 1082 1 2370)); +DATA(insert ( 4052 1114 1184 1 2526)); +DATA(insert ( 4052 1184 1184 1 1314)); +DATA(insert ( 4052 1184 1082 1 2383)); +DATA(insert ( 4052 1184 1114 1 2533)); +DATA(insert ( 4053 700 700 1 354)); +DATA(insert ( 4053 700 701 1 2194)); +DATA(insert ( 4053 701 701 1 355)); +DATA(insert ( 4053 701 700 1 2195)); +DATA(insert ( 4054 1700 1700 1 1769)); +DATA(insert ( 4055 25 25 1 360)); +DATA(insert ( 4056 1042 1042 1 1078)); +DATA(insert ( 4057 1083 1083 1 1107)); +DATA(insert ( 4058 1266 1266 1 1358)); +DATA(insert ( 4059 790 790 1 377)); +DATA(insert ( 4060 1186 1186 1 1315)); +DATA(insert ( 4061 704 704 1 381)); +DATA(insert ( 4062 5545 5545 1 5519)); +DATA(insert ( 4063 16 16 1 1693)); +DATA(insert ( 4064 9003 9003 1 5586)); + +/* cbtree, fake data just make index work */ +DATA(insert ( 4250 21 21 1 350)); +DATA(insert ( 4250 21 23 1 2190)); +DATA(insert ( 4250 21 20 1 2192)); +DATA(insert ( 4250 23 23 1 351)); +DATA(insert ( 4250 23 20 1 2188)); +DATA(insert ( 4250 23 21 1 2191)); +DATA(insert ( 4250 20 20 1 842)); +DATA(insert ( 4250 20 23 1 2189)); +DATA(insert ( 4250 20 21 1 2193)); +DATA(insert ( 4251 26 26 1 356)); +DATA(insert ( 4252 1082 1082 1 1092)); +DATA(insert ( 4252 1082 1114 1 2344)); +DATA(insert ( 4252 1082 1184 1 2357)); +DATA(insert ( 4252 1114 1114 1 2045)); +DATA(insert ( 4252 1114 1082 1 2370)); +DATA(insert ( 4252 1114 1184 1 2526)); +DATA(insert ( 4252 1184 1184 1 1314)); +DATA(insert ( 4252 1184 1082 1 2383)); +DATA(insert ( 4252 1184 1114 1 2533)); +DATA(insert ( 4253 700 700 1 354)); +DATA(insert ( 4253 700 701 1 2194)); +DATA(insert ( 4253 701 701 1 355)); +DATA(insert ( 4253 701 700 1 2195)); +DATA(insert ( 4254 1700 1700 1 1769)); +DATA(insert ( 4255 25 25 1 360)); +DATA(insert ( 4256 1042 1042 1 1078)); +DATA(insert ( 4257 1083 1083 1 1107)); +DATA(insert ( 4258 1266 1266 1 1358)); +DATA(insert ( 4259 790 790 1 377)); +DATA(insert ( 4260 1186 1186 1 1315)); +DATA(insert ( 4261 704 704 1 381)); +DATA(insert ( 4262 5545 5545 1 5519)); +DATA(insert ( 4263 16 16 1 1693)); +DATA(insert ( 4264 9003 9003 1 5586)); + +#endif /* PG_AMPROC_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_app_workloadgroup_mapping.h postgresql-hll-2.14/include/catalog/pg_app_workloadgroup_mapping.h --- postgresql-hll-2.14_old/include/catalog/pg_app_workloadgroup_mapping.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_app_workloadgroup_mapping.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_app_workloadgroup_mapping.h + * define the mapping between application and workload group. + * + * + * IDENTIFICATION + * src/include/catalog/pg_app_workloadgroup_mapping.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_APP_WORKLOADGROUP_MAPPING_H +#define PG_APP_WORKLOADGROUP_MAPPING_H + +#include "catalog/genbki.h" +#include "catalog/pg_workload_group.h" + + +/* define the OID of the table pg_app_workloadgroup_mapping*/ +#define AppWorkloadGroupMappingRelationId 3464 +#define AppWorkloadGroupMappingRelation_Rowtype_Id 3468 + +CATALOG(pg_app_workloadgroup_mapping,3464) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3468) BKI_SCHEMA_MACRO +{ + NameData appname; /*Name of application*/ + NameData workload_gpname; /*Name of workload group*/ +} FormData_pg_app_workloadgroup_mapping; + + +/*------------------------------------------------------------------------- + * Form_pg_app_workloadgroup_mapping corresponds to a pointer to a tuple with + * the format of pg_app_workloadgroup_mapping relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_app_workloadgroup_mapping *Form_pg_app_workloadgroup_mapping; + +/*------------------------------------------------------------------------- + * compiler constants for pg_app_workloadgroup_mapping + *------------------------------------------------------------------------- + */ +#define Natts_pg_app_workloadgroup_mapping 2 +#define Anum_pg_app_workloadgroup_mapping_appname 1 +#define Anum_pg_app_workloadgroup_mapping_wgname 2 + +DATA(insert OID = 10 ("default_application" "default_group")); +#define DEFAULT_APP_OID 10 +#define DEFAULT_APP_NAME "default_application" + +/*default setting for user defined application*/ +#define DEFAULT_WORKLOAD_GROUP DEFAULT_GROUP_NAME +#define DEFAULT_WORKLOAD_GROUP_OID DEFAULT_GROUP_OID + +#endif /* PG_APP_WORKLOADGROUP_MAPPING_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_attrdef.h postgresql-hll-2.14/include/catalog/pg_attrdef.h --- postgresql-hll-2.14_old/include/catalog/pg_attrdef.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_attrdef.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_attrdef.h + * definition of the system "attribute defaults" relation (pg_attrdef) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_attrdef.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ATTRDEF_H +#define PG_ATTRDEF_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_attrdef definition. cpp turns this into + * typedef struct FormData_pg_attrdef + * ---------------- + */ +#define AttrDefaultRelationId 2604 +#define AttrDefaultRelation_Rowtype_Id 10000 + +CATALOG(pg_attrdef,2604) BKI_SCHEMA_MACRO +{ + Oid adrelid; /* OID of table containing attribute */ + int2 adnum; /* attnum of attribute */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + pg_node_tree adbin; /* nodeToString representation of default */ + text adsrc; /* human-readable representation of default */ +#endif +} FormData_pg_attrdef; + +/* ---------------- + * Form_pg_attrdef corresponds to a pointer to a tuple with + * the format of pg_attrdef relation. + * ---------------- + */ +typedef FormData_pg_attrdef *Form_pg_attrdef; + +/* ---------------- + * compiler constants for pg_attrdef + * ---------------- + */ +#define Natts_pg_attrdef 4 +#define Anum_pg_attrdef_adrelid 1 +#define Anum_pg_attrdef_adnum 2 +#define Anum_pg_attrdef_adbin 3 +#define Anum_pg_attrdef_adsrc 4 + +#endif /* PG_ATTRDEF_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_attribute.h postgresql-hll-2.14/include/catalog/pg_attribute.h --- postgresql-hll-2.14_old/include/catalog/pg_attribute.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_attribute.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,235 @@ +/* ------------------------------------------------------------------------- + * + * pg_attribute.h + * definition of the system "attribute" relation (pg_attribute) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_attribute.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ATTRIBUTE_H +#define PG_ATTRIBUTE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_attribute definition. cpp turns this into + * typedef struct FormData_pg_attribute + * + * If you change the following, make sure you change the structs for + * system attributes in catalog/heap.c also. + * You may need to change catalog/genbki.pl as well. + * ---------------- + */ +#define AttributeRelationId 1249 +#define AttributeRelation_Rowtype_Id 75 + +#define IsAttributeRelation(rel) (RelationGetRelid(rel) == AttributeRelationId) +#define IsAttributeCache(cache) ((cache)->cc_reloid == AttributeRelationId) + +CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BKI_SCHEMA_MACRO +{ + Oid attrelid; /* OID of relation containing this attribute */ + NameData attname; /* name of attribute */ + + /* + * atttypid is the OID of the instance in Catalog Class pg_type that + * defines the data type of this attribute (e.g. int4). Information in + * that instance is redundant with the attlen, attbyval, and attalign + * attributes of this instance, so they had better match or Postgres will + * fail. + */ + Oid atttypid; + + /* + * attstattarget is the target number of statistics datapoints to collect + * during VACUUM ANALYZE of this column. A zero here indicates that we do + * not wish to collect any stats about this column. A "-1" here indicates + * that no value has been explicitly set for this column, so ANALYZE + * should use the default setting. + */ + int4 attstattarget; + + /* + * attlen is a copy of the typlen field from pg_type for this attribute. + * See atttypid comments above. + */ + int2 attlen; + + /* + * attnum is the "attribute number" for the attribute: A value that + * uniquely identifies this attribute within its class. For user + * attributes, Attribute numbers are greater than 0 and not greater than + * the number of attributes in the class. I.e. if the Class pg_class says + * that Class XYZ has 10 attributes, then the user attribute numbers in + * Class pg_attribute must be 1-10. + * + * System attributes have attribute numbers less than 0 that are unique + * within the class, but not constrained to any particular range. + * + * Note that (attnum - 1) is often used as the index to an array. + */ + int2 attnum; + + /* + * attndims is the declared number of dimensions, if an array type, + * otherwise zero. + */ + int4 attndims; + + /* + * fastgetattr() uses attcacheoff to cache byte offsets of attributes in + * heap tuples. The value actually stored in pg_attribute (-1) indicates + * no cached value. But when we copy these tuples into a tuple + * descriptor, we may then update attcacheoff in the copies. This speeds + * up the attribute walking process. + * + * Important: this is only for uncompressed tuples, both cached and updated. + * And it cann't be applied to compressed tuples. Each attribute within + * compressed tuple should be accessed one by one, step by step. + */ + int4 attcacheoff; + + /* + * atttypmod records type-specific data supplied at table creation time + * (for example, the max length of a varchar field). It is passed to + * type-specific input and output functions as the third argument. The + * value will generally be -1 for types that do not need typmod. + */ + int4 atttypmod; + + /* + * attbyval is a copy of the typbyval field from pg_type for this + * attribute. See atttypid comments above. + */ + bool attbyval; + + /* ---------- + * attstorage tells for VARLENA attributes, what the heap access + * methods can do to it if a given tuple doesn't fit into a page. + * Possible values are + * 'p': Value must be stored plain always + * 'e': Value can be stored in "secondary" relation (if relation + * has one, see pg_class.reltoastrelid) + * 'm': Value can be stored compressed inline + * 'x': Value can be stored compressed inline or in "secondary" + * Note that 'm' fields can also be moved out to secondary storage, + * but only as a last resort ('e' and 'x' fields are moved first). + * ---------- + */ + char attstorage; + + /* + * attalign is a copy of the typalign field from pg_type for this + * attribute. See atttypid comments above. + */ + char attalign; + + /* This flag represents the "NOT NULL" constraint */ + bool attnotnull; + + /* Has DEFAULT value or not */ + bool atthasdef; + + /* Is dropped (ie, logically invisible) or not */ + bool attisdropped; + + /* Has a local definition (hence, do not drop when attinhcount is 0) */ + bool attislocal; + + /* Compression Mode for this attribute + * its size is 1Byte, and the 7 fields before are also 1Btye wide, so place it here; + * its valid value is: CMPR_NONE ~ CMPR_NUMSTR. see also pagecompress.h + */ + int1 attcmprmode; + + /* Number of times inherited from direct parent relation(s) */ + int4 attinhcount; + + /* attribute's collation */ + Oid attcollation; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* NOTE: The following fields are not present in tuple descriptors. */ + + /* Column-level access permissions */ + aclitem attacl[1]; + + /* Column-level options */ + text attoptions[1]; + + /* Column-level FDW options */ + text attfdwoptions[1]; + + /* the value is not null only when ALTER TABLE ... ADD COLUMN call */ + bytea attinitdefval; + +#endif + /* the attribute type for kv storage: tag(1), field(2), time(3), hide(4) or default(0) */ + int1 attkvtype; +} FormData_pg_attribute; + +/* + * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout, + * guaranteed-not-null part of a pg_attribute row. This is in fact as much + * of the row as gets copied into tuple descriptors, so don't expect you + * can access fields beyond attcollation except in a real tuple! + */ +#define ATTRIBUTE_FIXED_PART_SIZE \ + (offsetof(FormData_pg_attribute, attkvtype) + sizeof(Oid)) + +/* ---------------- + * Form_pg_attribute corresponds to a pointer to a tuple with + * the format of pg_attribute relation. + * ---------------- + */ +typedef FormData_pg_attribute *Form_pg_attribute; + +/* ---------------- + * compiler constants for pg_attribute + * ---------------- + */ +#define Natts_pg_attribute 24 +#define Anum_pg_attribute_attrelid 1 +#define Anum_pg_attribute_attname 2 +#define Anum_pg_attribute_atttypid 3 +#define Anum_pg_attribute_attstattarget 4 +#define Anum_pg_attribute_attlen 5 +#define Anum_pg_attribute_attnum 6 +#define Anum_pg_attribute_attndims 7 +#define Anum_pg_attribute_attcacheoff 8 +#define Anum_pg_attribute_atttypmod 9 +#define Anum_pg_attribute_attbyval 10 +#define Anum_pg_attribute_attstorage 11 +#define Anum_pg_attribute_attalign 12 +#define Anum_pg_attribute_attnotnull 13 +#define Anum_pg_attribute_atthasdef 14 +#define Anum_pg_attribute_attisdropped 15 +#define Anum_pg_attribute_attislocal 16 +#define Anum_pg_attribute_attcmprmode 17 +#define Anum_pg_attribute_attinhcount 18 +#define Anum_pg_attribute_attcollation 19 +#define Anum_pg_attribute_attacl 20 +#define Anum_pg_attribute_attoptions 21 +#define Anum_pg_attribute_attfdwoptions 22 +#define Anum_pg_attribute_attinitdefval 23 +#define Anum_pg_attribute_attkvtype 24 + +/* ---------------- + * initial contents of pg_attribute + * + * The initial contents of pg_attribute are generated at compile time by + * genbki.pl. Only "bootstrapped" relations need be included. + * ---------------- + */ +#endif /* PG_ATTRIBUTE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_auth_history.h postgresql-hll-2.14/include/catalog/pg_auth_history.h --- postgresql-hll-2.14_old/include/catalog/pg_auth_history.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_auth_history.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_auth_history.h + * definition of the system "authorization history" relation (pg_auth_history) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_auth_history.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_AUTH_HISTORY_H +#define PG_AUTH_HISTORY_H + +/* define the timestamptz for the passwordtime in pg_auth_history*/ +#define timestamptz Datum + +/* define the OID of the table pg_auth_history*/ +#define AuthHistoryRelationId 3457 +#define AuthHistoryRelation_Rowtype_Id 11642 + +CATALOG(pg_auth_history,3457) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + Oid roloid; /* role OID*/ + timestamptz passwordtime; /* the time while create or alter password */ + text rolpassword; /* role password, md5-encryption,sha256-encryption, or none-encryption */ +} FormData_pg_auth_history; + +#undef timestamptz + +/*------------------------------------------------------------------------- + * Form_pg_auth_history corresponds to a pointer to a tuple with + * the format of pg_auth_history relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_auth_history *Form_pg_auth_history; + +/*------------------------------------------------------------------------- + * compiler constants for pg_auth_history + *------------------------------------------------------------------------- + */ +#define Natts_pg_auth_history 3 +#define Anum_pg_auth_history_roloid 1 +#define Anum_pg_auth_history_passwordtime 2 +#define Anum_pg_auth_history_rolpassword 3 + +#endif /* PG_AUTH_HISTORY_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_authid.h postgresql-hll-2.14/include/catalog/pg_authid.h --- postgresql-hll-2.14_old/include/catalog/pg_authid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_authid.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,138 @@ +/* ------------------------------------------------------------------------- + * + * pg_authid.h + * definition of the system "authorization identifier" relation (pg_authid) + * along with the relation's initial contents. + * + * pg_shadow and pg_group are now publicly accessible views on pg_authid. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_authid.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AUTHID_H +#define PG_AUTHID_H + +#include "catalog/genbki.h" +#include "catalog/pg_resource_pool.h" + +/* + * The CATALOG definition has to refer to the type of rolvaliduntil as + * "timestamptz" (lower case) so that bootstrap mode recognizes it. But + * the C header files define this type as TimestampTz. Since the field is + * potentially-null and therefore can't be accessed directly from C code, + * there is no particular need for the C struct definition to show the + * field type as TimestampTz --- instead we just make it int. + */ +#define timestamptz int + + +/* ---------------- + * pg_authid definition. cpp turns this into + * typedef struct FormData_pg_authid + * ---------------- + */ +#define AuthIdRelationId 1260 +#define AuthIdRelation_Rowtype_Id 2842 + +CATALOG(pg_authid,1260) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2842) BKI_SCHEMA_MACRO +{ + NameData rolname; /* name of role */ + bool rolsuper; /* the first role created by initdb.*/ + bool rolinherit; /* inherit privileges from other roles? */ + bool rolcreaterole; /* allowed to create more roles? */ + bool rolcreatedb; /* allowed to create databases? */ + bool rolcatupdate; /* allowed to alter catalogs manually? */ + bool rolcanlogin; /* allowed to log in as session user? */ + bool rolreplication; /* role used for streaming replication */ + bool rolauditadmin; /* role used for administer audit data */ + bool rolsystemadmin; + int4 rolconnlimit; /* max connections allowed (-1=no limit) */ + + /* remaining fields may be null; use heap_getattr to read them! */ +#ifdef CATALOG_VARLEN + text rolpassword; /* password, if any */ + timestamptz rolvalidbegin; /* password initiation time, if any */ + timestamptz rolvaliduntil; /* password expiration time, if any */ + + NameData rolrespool; /* wlm resource pool */ + bool roluseft; /* allowed to use foreign table? */ + Oid rolparentid; /* parent user oid */ + text roltabspace; /* user perm space */ + char rolkind; /* role kind for special use. */ + Oid rolnodegroup; /* nodegroup id */ + text roltempspace; /* user temp space */ + text rolspillspace; /* user spill space */ + text rolexcpdata; /* user exception data */ +#endif + bool rolmonitoradmin; + bool roloperatoradmin; + bool rolpolicyadmin; +} FormData_pg_authid; + +#undef timestamptz + + +/* ---------------- + * Form_pg_authid corresponds to a pointer to a tuple with + * the format of pg_authid relation. + * ---------------- + */ +typedef FormData_pg_authid *Form_pg_authid; + +/* ---------------- + * compiler constants for pg_authid + * ---------------- + */ +#define Natts_pg_authid 26 +#define Anum_pg_authid_rolname 1 +#define Anum_pg_authid_rolsuper 2 +#define Anum_pg_authid_rolinherit 3 +#define Anum_pg_authid_rolcreaterole 4 +#define Anum_pg_authid_rolcreatedb 5 +#define Anum_pg_authid_rolcatupdate 6 +#define Anum_pg_authid_rolcanlogin 7 +#define Anum_pg_authid_rolreplication 8 +#define Anum_pg_authid_rolauditadmin 9 +#define Anum_pg_authid_rolsystemadmin 10 +#define Anum_pg_authid_rolconnlimit 11 +#define Anum_pg_authid_rolpassword 12 +#define Anum_pg_authid_rolvalidbegin 13 +#define Anum_pg_authid_rolvaliduntil 14 +#define Anum_pg_authid_rolrespool 15 +#define Anum_pg_authid_roluseft 16 +#define Anum_pg_authid_rolparentid 17 +#define Anum_pg_authid_roltabspace 18 +#define Anum_pg_authid_rolkind 19 +#define Anum_pg_authid_rolnodegroup 20 +#define Anum_pg_authid_roltempspace 21 +#define Anum_pg_authid_rolspillspace 22 +#define Anum_pg_authid_rolexcpdata 23 +#define Anum_pg_authid_rolmonitoradmin 24 +#define Anum_pg_authid_roloperatoradmin 25 +#define Anum_pg_authid_rolpolicyadmin 26 + +/* ---------------- + * initial contents of pg_authid + * + * The uppercase quantities will be replaced at initdb time with + * user choices. + * ---------------- + */ +DATA(insert OID = 10 ( "POSTGRES" t t t t t t t t t -1 _null_ _null_ _null_ "default_pool" t 0 _null_ n 0 _null_ _null_ _null_ t t t)); + +#define BOOTSTRAP_SUPERUSERID 10 +#define ROLKIND_NORMAL 'n' /* regular user */ +#define ROLKIND_INDEPENDENT 'i' /* independent user */ +#define ROLKIND_VCADMIN 'v' /* logic cluster admin user */ +#define ROLKIND_PERSISTENCE 'p' /* persistence user */ + +#endif /* PG_AUTHID_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_auth_members.h postgresql-hll-2.14/include/catalog/pg_auth_members.h --- postgresql-hll-2.14_old/include/catalog/pg_auth_members.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_auth_members.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,57 @@ +/* ------------------------------------------------------------------------- + * + * pg_auth_members.h + * definition of the system "authorization identifier members" relation + * (pg_auth_members) along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_auth_members.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AUTH_MEMBERS_H +#define PG_AUTH_MEMBERS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_auth_members definition. cpp turns this into + * typedef struct FormData_pg_auth_members + * ---------------- + */ +#define AuthMemRelationId 1261 +#define AuthMemRelation_Rowtype_Id 2843 + +CATALOG(pg_auth_members,1261) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(2843) BKI_SCHEMA_MACRO +{ + Oid roleid; /* ID of a role */ + Oid member; /* ID of a member of that role */ + Oid grantor; /* who granted the membership */ + bool admin_option; /* granted with admin option? */ +} FormData_pg_auth_members; + +/* ---------------- + * Form_pg_auth_members corresponds to a pointer to a tuple with + * the format of pg_auth_members relation. + * ---------------- + */ +typedef FormData_pg_auth_members *Form_pg_auth_members; + +/* ---------------- + * compiler constants for pg_auth_members + * ---------------- + */ +#define Natts_pg_auth_members 4 +#define Anum_pg_auth_members_roleid 1 +#define Anum_pg_auth_members_member 2 +#define Anum_pg_auth_members_grantor 3 +#define Anum_pg_auth_members_admin_option 4 + +#endif /* PG_AUTH_MEMBERS_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_cast.h postgresql-hll-2.14/include/catalog/pg_cast.h --- postgresql-hll-2.14_old/include/catalog/pg_cast.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_cast.h 2020-12-12 17:06:43.078345858 +0800 @@ -0,0 +1,535 @@ +/* ------------------------------------------------------------------------- + * + * pg_cast.h + * definition of the system "type casts" relation (pg_cast) + * along with the relation's initial contents. + * + * As of Postgres 8.0, pg_cast describes not only type coercion functions + * but also length coercion functions. + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/catalog/pg_cast.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CAST_H +#define PG_CAST_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_cast definition. cpp turns this into + * typedef struct FormData_pg_cast + * ---------------- + */ +#define CastRelationId 2605 +#define CastRelation_Rowtype_Id 11331 + +CATALOG(pg_cast,2605) BKI_SCHEMA_MACRO +{ + Oid castsource; /* source datatype for cast */ + Oid casttarget; /* destination datatype for cast */ + Oid castfunc; /* cast function; 0 = binary coercible */ + char castcontext; /* contexts in which cast can be used */ + char castmethod; /* cast method */ +} FormData_pg_cast; + +typedef FormData_pg_cast *Form_pg_cast; + +/* + * The allowable values for pg_cast.castcontext are specified by this enum. + * Since castcontext is stored as a "char", we use ASCII codes for human + * convenience in reading the table. Note that internally to the backend, + * these values are converted to the CoercionContext enum (see primnodes.h), + * which is defined to sort in a convenient order; the ASCII codes don't + * have to sort in any special order. + */ + +typedef enum CoercionCodes +{ + COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */ + COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */ + COERCION_CODE_EXPLICIT = 'e' /* explicit cast operation */ +} CoercionCodes; + +/* + * The allowable values for pg_cast.castmethod are specified by this enum. + * Since castmethod is stored as a "char", we use ASCII codes for human + * convenience in reading the table. + */ +typedef enum CoercionMethod +{ + COERCION_METHOD_FUNCTION = 'f', /* use a function */ + COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */ + COERCION_METHOD_INOUT = 'i' /* use input/output functions */ +} CoercionMethod; + + +/* ---------------- + * compiler constants for pg_cast + * ---------------- + */ +#define Natts_pg_cast 5 +#define Anum_pg_cast_castsource 1 +#define Anum_pg_cast_casttarget 2 +#define Anum_pg_cast_castfunc 3 +#define Anum_pg_cast_castcontext 4 +#define Anum_pg_cast_castmethod 5 + +/* ---------------- + * initial contents of pg_cast + * + * Note: this table has OIDs, but we don't bother to assign them manually, + * since nothing needs to know the specific OID of any built-in cast. + * ---------------- + */ + +/* + * Numeric category: implicit casts are allowed in the direction + * int2->int4->int8->numeric->float4->float8, while casts in the + * reverse direction are assignment-only. + */ +DATA(insert ( 23 5545 5526 i f )); +DATA(insert ( 5545 16 5533 i f )); +DATA(insert ( 16 5545 5534 i f )); +DATA(insert ( 5545 26 5525 i f )); +DATA(insert ( 5545 24 5525 i f )); +DATA(insert ( 5545 2202 5525 i f )); +DATA(insert ( 5545 2203 5525 i f )); +DATA(insert ( 5545 2204 5525 i f )); +DATA(insert ( 5545 2205 5525 i f )); +DATA(insert ( 5545 2206 5525 i f )); +DATA(insert ( 5545 3734 5525 i f )); +DATA(insert ( 5545 3769 5525 i f )); +DATA(insert ( 5545 21 5523 i f )); +DATA(insert ( 5545 23 5525 i f )); +DATA(insert ( 5545 20 5527 i f )); +DATA(insert ( 5545 1700 5521 i f )); +DATA(insert ( 5545 700 5529 i f )); +DATA(insert ( 5545 701 5531 i f )); +DATA(insert ( 20 5545 5528 a f )); +DATA(insert ( 21 5545 5524 i f )); +DATA(insert ( 700 5545 5530 i f )); +DATA(insert ( 701 5545 5532 i f )); +DATA(insert ( 1700 5545 5522 i f )); +DATA(insert ( 20 21 714 a f )); +DATA(insert ( 20 23 480 a f )); +DATA(insert ( 20 700 652 i f )); +DATA(insert ( 20 701 482 i f )); +DATA(insert ( 20 1700 1781 i f )); +DATA(insert ( 21 20 754 i f )); +DATA(insert ( 21 23 313 i f )); +DATA(insert ( 21 700 236 i f )); +DATA(insert ( 21 701 235 i f )); +DATA(insert ( 21 1700 1782 i f )); +DATA(insert ( 23 20 481 i f )); +DATA(insert ( 23 21 314 i f )); +DATA(insert ( 23 700 318 i f )); +DATA(insert ( 23 701 316 i f )); +DATA(insert ( 23 1700 1740 i f )); +DATA(insert ( 700 20 653 i f )); +DATA(insert ( 700 21 238 i f )); +DATA(insert ( 700 23 319 i f )); +DATA(insert ( 700 701 311 i f )); +DATA(insert ( 700 1700 1742 i f )); +DATA(insert ( 701 20 483 i f )); +DATA(insert ( 701 21 237 i f )); +DATA(insert ( 701 23 317 i f )); +DATA(insert ( 701 700 312 i f )); + +/* + * convert float8 to numeric implicit(not assignment-only) + * support mod(numeric, float8) and mod(float8, numeric) + */ +DATA(insert ( 701 1700 1743 i f )); +DATA(insert ( 1700 20 1779 i f )); +DATA(insert ( 1700 21 1783 i f )); +DATA(insert ( 1700 23 1744 i f )); +DATA(insert ( 1700 700 1745 i f )); +DATA(insert ( 1700 701 1746 i f )); +DATA(insert ( 790 1700 3823 a f )); +DATA(insert ( 1700 790 3824 a f )); +DATA(insert ( 23 790 3811 a f )); +DATA(insert ( 20 790 3812 a f )); + +/* Allow explicit coercions between int4 and bool */ + +/*Bool <-->INT4*/ +DATA(insert ( 23 16 2557 i f )); +DATA(insert ( 16 23 2558 i f )); +/*Bool <-->INT2*/ +DATA(insert ( 21 16 3180 i f )); +DATA(insert ( 16 21 3181 i f )); +/*Bool <-->INT8*/ +DATA(insert ( 20 16 3177 i f )); +DATA(insert ( 16 20 3178 i f )); + +/* int4 ->bpchar */ +DATA(insert ( 23 1042 3192 i f )); + +/* numeric ->interval */ +DATA(insert ( 1700 1186 3842 i f )); + +/* float8-> interval */ +DATA(insert ( 701 1186 4229 i f )); + +/* int1 ->interval */ +DATA(insert ( 5545 1186 3189 i f )); + +/* int2 ->interval */ +DATA(insert ( 21 1186 3190 i f )); + +/* int4 ->interval */ +DATA(insert ( 23 1186 3191 i f )); + +/* + * OID category: allow implicit conversion from any integral type (including + * int8, to support OID literals > 2G) to OID, as well as assignment coercion + * from OID to int4 or int8. Similarly for each OID-alias type. Also allow + * implicit coercions between OID and each OID-alias type, as well as + * regproc<->regprocedure and regoper<->regoperator. (Other coercions + * between alias types must pass through OID.) Lastly, there are implicit + * casts from text and varchar to regclass, which exist mainly to support + * legacy forms of nextval() and related functions. + */ +DATA(insert ( 20 26 1287 i f )); +DATA(insert ( 21 26 313 i f )); +DATA(insert ( 23 26 0 i b )); +DATA(insert ( 26 20 1288 a f )); +DATA(insert ( 26 23 0 a b )); +DATA(insert ( 26 24 0 i b )); +DATA(insert ( 24 26 0 i b )); +DATA(insert ( 20 24 1287 i f )); +DATA(insert ( 21 24 313 i f )); +DATA(insert ( 23 24 0 i b )); +DATA(insert ( 24 20 1288 a f )); +DATA(insert ( 24 23 0 a b )); +DATA(insert ( 24 2202 0 i b )); +DATA(insert ( 2202 24 0 i b )); +DATA(insert ( 26 2202 0 i b )); +DATA(insert ( 2202 26 0 i b )); +DATA(insert ( 20 2202 1287 i f )); +DATA(insert ( 21 2202 313 i f )); +DATA(insert ( 23 2202 0 i b )); +DATA(insert ( 2202 20 1288 a f )); +DATA(insert ( 2202 23 0 a b )); +DATA(insert ( 26 2203 0 i b )); +DATA(insert ( 2203 26 0 i b )); +DATA(insert ( 20 2203 1287 i f )); +DATA(insert ( 21 2203 313 i f )); +DATA(insert ( 23 2203 0 i b )); +DATA(insert ( 2203 20 1288 a f )); +DATA(insert ( 2203 23 0 a b )); +DATA(insert ( 2203 2204 0 i b )); +DATA(insert ( 2204 2203 0 i b )); +DATA(insert ( 26 2204 0 i b )); +DATA(insert ( 2204 26 0 i b )); +DATA(insert ( 20 2204 1287 i f )); +DATA(insert ( 21 2204 313 i f )); +DATA(insert ( 23 2204 0 i b )); +DATA(insert ( 2204 20 1288 a f )); +DATA(insert ( 2204 23 0 a b )); +DATA(insert ( 26 2205 0 i b )); +DATA(insert ( 2205 26 0 i b )); +DATA(insert ( 20 2205 1287 i f )); +DATA(insert ( 21 2205 313 i f )); +DATA(insert ( 23 2205 0 i b )); +DATA(insert ( 2205 20 1288 a f )); +DATA(insert ( 2205 23 0 a b )); +DATA(insert ( 26 2206 0 i b )); +DATA(insert ( 2206 26 0 i b )); +DATA(insert ( 20 2206 1287 i f )); +DATA(insert ( 21 2206 313 i f )); +DATA(insert ( 23 2206 0 i b )); +DATA(insert ( 2206 20 1288 a f )); +DATA(insert ( 2206 23 0 a b )); +DATA(insert ( 26 3734 0 i b )); +DATA(insert ( 3734 26 0 i b )); +DATA(insert ( 20 3734 1287 i f )); +DATA(insert ( 21 3734 313 i f )); +DATA(insert ( 23 3734 0 i b )); +DATA(insert ( 3734 20 1288 a f )); +DATA(insert ( 3734 23 0 a b )); +DATA(insert ( 26 3769 0 i b )); +DATA(insert ( 3769 26 0 i b )); +DATA(insert ( 20 3769 1287 i f )); +DATA(insert ( 21 3769 313 i f )); +DATA(insert ( 23 3769 0 i b )); +DATA(insert ( 3769 20 1288 a f )); +DATA(insert ( 3769 23 0 a b )); +DATA(insert ( 25 2205 1079 i f )); +DATA(insert ( 90 2205 1079 i f )); +DATA(insert ( 1043 2205 1079 i f )); +DATA(insert ( 3969 2205 1079 i f )); + +/* + * String category + */ +DATA(insert ( 25 1042 0 i b )); +DATA(insert ( 25 1043 0 i b )); +DATA(insert ( 25 3969 0 i b )); +DATA(insert ( 90 1042 0 i b )); +DATA(insert ( 90 1043 0 i b )); +DATA(insert ( 90 3969 0 i b )); +DATA(insert ( 1042 25 401 i f )); +DATA(insert ( 1042 90 401 i f )); +DATA(insert ( 1042 1043 401 i f )); +DATA(insert ( 1043 25 0 i b )); +DATA(insert ( 1043 90 0 i b )); +DATA(insert ( 1043 1042 0 i b )); +DATA(insert ( 1042 3969 401 i f )); +DATA(insert ( 3969 25 0 i b )); +DATA(insert ( 3969 90 0 i b )); +DATA(insert ( 3969 1042 0 i b )); +DATA(insert ( 3969 1043 0 i b )); +DATA(insert ( 1043 3969 0 i b )); +DATA(insert ( 18 25 946 i f )); +DATA(insert ( 18 90 946 i f )); +DATA(insert ( 18 1042 860 a f )); +DATA(insert ( 18 1043 946 a f )); +DATA(insert ( 18 3969 946 a f )); +DATA(insert ( 19 25 406 i f )); +DATA(insert ( 19 90 406 i f )); +DATA(insert ( 19 1042 408 a f )); +DATA(insert ( 19 1043 1401 a f )); +DATA(insert ( 19 3969 1401 a f )); +DATA(insert ( 25 18 944 a f )); +DATA(insert ( 90 18 944 a f )); +DATA(insert ( 1042 18 944 a f )); +DATA(insert ( 1043 18 944 a f )); +DATA(insert ( 3969 18 944 a f )); +DATA(insert ( 25 19 407 i f )); +DATA(insert ( 90 19 407 i f )); +DATA(insert ( 1042 19 409 i f )); +DATA(insert ( 1043 19 1400 i f )); +DATA(insert ( 3969 19 1400 i f )); + + + +/* Allow explicit coercions between int4 and "char" */ +DATA(insert ( 18 23 77 e f )); +DATA(insert ( 23 18 78 e f )); + +/* pg_node_tree can be coerced to, but not from, text */ +DATA(insert ( 194 25 0 i b )); +DATA(insert ( 194 90 0 i b )); + +/* + * Datetime category + */ +DATA(insert ( 702 1082 1179 a f )); +DATA(insert ( 702 1083 1364 a f )); +DATA(insert ( 702 1114 2023 i f )); +DATA(insert ( 702 1184 1173 i f )); +DATA(insert ( 703 1186 1177 i f )); +DATA(insert ( 1082 1114 2024 i f )); +DATA(insert ( 1082 1184 1174 i f )); +DATA(insert ( 1083 1186 1370 i f )); +DATA(insert ( 1083 1266 2047 i f )); +DATA(insert ( 1114 702 2030 a f )); +DATA(insert ( 1114 1082 2029 a f )); +DATA(insert ( 1114 1083 1316 a f )); +DATA(insert ( 1114 1184 2028 i f )); +DATA(insert ( 1184 702 1180 a f )); +DATA(insert ( 1184 1082 1178 a f )); +DATA(insert ( 1184 1083 2019 a f )); +DATA(insert ( 1184 1114 2027 a f )); +DATA(insert ( 1184 1266 1388 a f )); +DATA(insert ( 1186 703 1194 a f )); +DATA(insert ( 1186 1083 1419 a f )); +DATA(insert ( 1266 1083 2046 a f )); +DATA(insert ( 25 1114 4073 i f )); +DATA(insert ( 90 1114 4073 i f )); + +/* Cross-category casts between int4 and abstime, reltime */ +DATA(insert ( 23 702 0 e b )); +DATA(insert ( 702 23 0 e b )); +DATA(insert ( 23 703 0 e b )); +DATA(insert ( 703 23 0 e b )); + +/* + * Geometric category + */ +DATA(insert ( 601 600 1532 e f )); +DATA(insert ( 602 600 1533 e f )); +DATA(insert ( 602 604 1449 a f )); +DATA(insert ( 603 600 1534 e f )); +DATA(insert ( 603 601 1541 e f )); +DATA(insert ( 603 604 1448 a f )); +DATA(insert ( 603 718 1479 e f )); +DATA(insert ( 604 600 1540 e f )); +DATA(insert ( 604 602 1447 a f )); +DATA(insert ( 604 603 1446 e f )); +DATA(insert ( 604 718 1474 e f )); +DATA(insert ( 718 600 1416 e f )); +DATA(insert ( 718 603 1480 e f )); +DATA(insert ( 718 604 1544 e f )); + +/* + * INET category + */ +DATA(insert ( 650 869 0 i b )); +DATA(insert ( 869 650 1715 a f )); + +/* + * BitString category + */ +DATA(insert ( 1560 1562 0 i b )); +DATA(insert ( 1562 1560 0 i b )); +/* Cross-category casts between bit and int4, int8 */ +DATA(insert ( 20 1560 2075 e f )); +DATA(insert ( 23 1560 1683 e f )); +DATA(insert ( 1560 20 2076 e f )); +DATA(insert ( 1560 23 1684 e f )); + +/* + * Cross-category casts to and from TEXT + * + * We need entries here only for a few specialized cases where the behavior + * of the cast function differs from the datatype's I/O functions. Otherwise, + * parse_coerce.c will generate CoerceViaIO operations without any prompting. + * + * Note that the castcontext values specified here should be no stronger than + * parse_coerce.c's automatic casts ('a' to text, 'e' from text) else odd + * behavior will ensue when the automatic cast is applied instead of the + * pg_cast entry! + */ +DATA(insert ( 650 25 730 a f )); +DATA(insert ( 869 25 730 a f )); +DATA(insert ( 16 25 2971 a f )); +DATA(insert ( 142 25 0 a b )); +DATA(insert ( 25 142 2896 e f )); + +DATA(insert ( 650 90 730 a f )); +DATA(insert ( 869 90 730 a f )); +DATA(insert ( 16 90 2971 a f )); +DATA(insert ( 142 90 0 a b )); +DATA(insert ( 90 142 2896 e f )); + +/* + * Cross-category casts to and from VARCHAR + * + * We support all the same casts as for TEXT. + */ +DATA(insert ( 650 1043 730 a f )); +DATA(insert ( 869 1043 730 a f )); +DATA(insert ( 16 1043 2971 a f )); +DATA(insert ( 142 1043 0 a b )); +DATA(insert ( 1043 142 2896 e f )); +DATA(insert ( 650 3969 730 a f )); +DATA(insert ( 869 3969 730 a f )); +DATA(insert ( 16 3969 2971 a f )); +DATA(insert ( 142 3969 0 a b )); +DATA(insert ( 3969 142 2896 e f )); + +/* + * Cross-category casts to and from BPCHAR + * + * We support all the same casts as for TEXT. + */ +DATA(insert ( 650 1042 730 a f )); +DATA(insert ( 869 1042 730 a f )); +DATA(insert ( 16 1042 2971 a f )); +DATA(insert ( 142 1042 0 a b )); +DATA(insert ( 1042 142 2896 e f )); +DATA(insert ( 1042 20 4195 i f )); + + +/* + * Length-coercion functions + */ +DATA(insert ( 1042 1042 668 i f )); +DATA(insert ( 1043 1043 669 i f )); +DATA(insert ( 3969 3969 3961 i f )); +DATA(insert ( 1083 1083 1968 i f )); +DATA(insert ( 1114 1114 1961 i f )); +DATA(insert ( 1184 1184 1967 i f )); +DATA(insert ( 1186 1186 1200 i f )); +DATA(insert ( 1266 1266 1969 i f )); +DATA(insert ( 1560 1560 1685 i f )); +DATA(insert ( 1562 1562 1687 i f )); +DATA(insert ( 1700 1700 1703 i f )); + +DATA(insert ( 1082 25 4159 i f )); +/*DATA(insert ( 1082 90 4159 i f ));*/ +DATA(insert ( 1082 1042 4160 i f )); +DATA(insert ( 1082 1043 4161 i f )); +DATA(insert ( 1043 1082 4162 i f )); +DATA(insert ( 1042 1082 4163 i f )); +DATA(insert ( 25 1082 4164 i f )); +/*DATA(insert ( 90 1082 4164 i f ));*/ + +DATA(insert ( 5545 25 4165 i f )); +DATA(insert ( 21 25 4166 i f )); +DATA(insert ( 23 25 4167 i f )); +DATA(insert ( 20 25 4168 i f )); +DATA(insert ( 700 25 4169 i f )); +DATA(insert ( 701 25 4170 i f )); +DATA(insert ( 1700 25 4171 i f )); +DATA(insert ( 5545 90 4165 i f )); +DATA(insert ( 21 90 4166 i f )); +DATA(insert ( 23 90 4167 i f )); +DATA(insert ( 20 90 4168 i f )); +DATA(insert ( 700 90 4169 i f )); +DATA(insert ( 701 90 4170 i f )); +DATA(insert ( 1700 90 4171 i f )); +DATA(insert ( 1042 1700 4172 i f )); +DATA(insert ( 1043 1700 4173 i f )); +DATA(insert ( 1043 23 4174 i f )); +DATA(insert ( 1042 23 4175 i f )); +DATA(insert ( 1043 20 4176 i f )); +DATA(insert ( 1184 25 4177 i f )); +DATA(insert ( 1114 25 4178 i f )); +DATA(insert ( 1184 90 4177 i f )); +DATA(insert ( 1114 90 4178 i f )); +DATA(insert ( 1114 1043 4179 i f )); +DATA(insert ( 21 1043 4180 i f )); +DATA(insert ( 23 1043 4181 i f )); +DATA(insert ( 20 1043 4182 i f )); +DATA(insert ( 1700 1043 4183 i f )); +DATA(insert ( 700 1043 4184 i f )); +DATA(insert ( 701 1043 4185 i f )); +DATA(insert ( 1043 1114 4186 i f )); +DATA(insert ( 1042 1114 4187 i f )); + +DATA(insert ( 25 5545 4188 i f )); +DATA(insert ( 25 21 4189 i f )); +DATA(insert ( 25 23 4190 i f )); +DATA(insert ( 25 20 4191 i f )); +DATA(insert ( 25 700 4192 i f )); +DATA(insert ( 25 701 4193 i f )); +DATA(insert ( 25 1700 4194 i f )); + +DATA(insert ( 90 5545 4188 i f )); +DATA(insert ( 90 21 4189 i f )); +DATA(insert ( 90 23 4190 i f )); +DATA(insert ( 90 20 4191 i f )); +DATA(insert ( 90 700 4192 i f )); +DATA(insert ( 90 701 4193 i f )); +DATA(insert ( 90 1700 4194 i f )); + +DATA(insert (5545 1043 4065 i f )); +DATA(insert (5545 3969 4066 i f )); +DATA(insert (5545 1042 4067 i f )); +DATA(insert (21 1042 4068 i f )); +DATA(insert (20 1042 4069 i f )); +DATA(insert (700 1042 4070 i f )); +DATA(insert (701 1042 4071 i f )); +DATA(insert (1700 1042 4072 i f )); + +/* hll */ +DATA(insert (4301 4301 4311 i f )); +DATA(insert (17 4301 0 e b )); +DATA(insert (20 4303 0 e b )); +DATA(insert (23 4303 4317 e f )); +DATA(insert (4402 4301 0 e b )); + + + +#endif /* PG_CAST_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_class.h postgresql-hll-2.14/include/catalog/pg_class.h --- postgresql-hll-2.14_old/include/catalog/pg_class.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_class.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,207 @@ +/* ------------------------------------------------------------------------- + * + * pg_class.h + * definition of the system "relation" relation (pg_class) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_class.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CLASS_H +#define PG_CLASS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_class definition. cpp turns this into + * typedef struct FormData_pg_class + * ---------------- + */ +#define RelationRelationId 1259 +#define RelationRelation_Rowtype_Id 83 + +CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO +{ + NameData relname; /* class name */ + Oid relnamespace; /* OID of namespace containing this class */ + Oid reltype; /* OID of entry in pg_type for table's + * implicit row type */ + Oid reloftype; /* OID of entry in pg_type for underlying + * composite type */ + Oid relowner; /* class owner */ + Oid relam; /* index access method; 0 if not an index */ + Oid relfilenode; /* identifier of physical storage file */ + + /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */ + Oid reltablespace; /* identifier of table space for relation */ + float8 relpages; /* # of blocks (not always up-to-date) */ + float8 reltuples; /* # of tuples (not always up-to-date) */ + int4 relallvisible; /* # of all-visible blocks (not always + * up-to-date) */ + Oid reltoastrelid; /* OID of toast table; 0 if none */ + Oid reltoastidxid; /* if toast table, OID of chunk_id index */ + Oid reldeltarelid; /* if ColStore table, it is not 0 */ + Oid reldeltaidx; + Oid relcudescrelid; /* if ColStore table, it is not 0, if TsStore, it is partition oid */ + Oid relcudescidx; + bool relhasindex; /* T if has (or has had) any indexes */ + bool relisshared; /* T if shared across databases */ + char relpersistence; /* see RELPERSISTENCE_xxx constants below */ + char relkind; /* see RELKIND_xxx constants below */ + int2 relnatts; /* number of user attributes */ + + /* + * Class pg_attribute must contain exactly "relnatts" user attributes + * (with attnums ranging from 1 to relnatts) for this class. It may also + * contain entries with negative attnums for system attributes. + */ + int2 relchecks; /* # of CHECK constraints for class */ + bool relhasoids; /* T if we generate OIDs for rows of rel */ + bool relhaspkey; /* has (or has had) PRIMARY KEY index */ + bool relhasrules; /* has (or has had) any rules */ + bool relhastriggers; /* has (or has had) any TRIGGERs */ + bool relhassubclass; /* has (or has had) derived classes */ + int1 relcmprs; /* row compression attribution */ + bool relhasclusterkey; /* has (or has had) any PARTIAL CLUSTER KEY */ + bool relrowmovement; /* enable or disable rowmovement */ + char parttype; /* 'p' for partitioned relation, 'n' for non-partitioned relation */ + ShortTransactionId relfrozenxid; /* all Xids < this are frozen in this rel */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* NOTE: These fields are not present in a relcache entry's rd_rel field. */ + aclitem relacl[1]; /* access permissions */ + text reloptions[1]; /* access-method-specific options */ +#endif + char relreplident; /* see REPLICA_IDENTITY_xxx constants */ + TransactionId relfrozenxid64; /* all Xids < this are frozen in this rel */ + Oid relbucket; /* bucket info in pg_hashbucket */ + int2vector relbucketkey; /* Column number of hash partition */ +} +FormData_pg_class; + +/* Size of fixed part of pg_class tuples, not counting var-length fields */ +#define CLASS_TUPLE_SIZE (offsetof(FormData_pg_class, relfrozenxid) + sizeof(ShortTransactionId)) + +/* ---------------- + * Form_pg_class corresponds to a pointer to a tuple with + * the format of pg_class relation. + * ---------------- + */ +typedef FormData_pg_class* Form_pg_class; + +/* ---------------- + * compiler constants for pg_class + * ---------------- + */ +#define Natts_pg_class 39 +#define Anum_pg_class_relname 1 +#define Anum_pg_class_relnamespace 2 +#define Anum_pg_class_reltype 3 +#define Anum_pg_class_reloftype 4 +#define Anum_pg_class_relowner 5 +#define Anum_pg_class_relam 6 +#define Anum_pg_class_relfilenode 7 +#define Anum_pg_class_reltablespace 8 +#define Anum_pg_class_relpages 9 +#define Anum_pg_class_reltuples 10 +#define Anum_pg_class_relallvisible 11 +#define Anum_pg_class_reltoastrelid 12 +#define Anum_pg_class_reltoastidxid 13 +#define Anum_pg_class_reldeltarelid 14 +#define Anum_pg_class_reldeltaidx 15 +#define Anum_pg_class_relcudescrelid 16 +#define Anum_pg_class_relcudescidx 17 +#define Anum_pg_class_relhasindex 18 +#define Anum_pg_class_relisshared 19 +#define Anum_pg_class_relpersistence 20 +#define Anum_pg_class_relkind 21 +#define Anum_pg_class_relnatts 22 +#define Anum_pg_class_relchecks 23 +#define Anum_pg_class_relhasoids 24 +#define Anum_pg_class_relhaspkey 25 +#define Anum_pg_class_relhasrules 26 +#define Anum_pg_class_relhastriggers 27 +#define Anum_pg_class_relhassubclass 28 +#define ANUM_PG_CLASS_RELCMPRS 29 +#define Anum_pg_class_relhasclusterkey 30 +#define Anum_pg_clsss_relrowmovement 31 +#define Anum_pg_class_parttype 32 +#define Anum_pg_class_relfrozenxid 33 +#define Anum_pg_class_relacl 34 +#define Anum_pg_class_reloptions 35 +#define Anum_pg_class_relreplident 36 +#define Anum_pg_class_relfrozenxid64 37 +#define Anum_pg_class_relbucket 38 +#define Anum_pg_class_relbucketkey 39 + +/* ---------------- + * initial contents of pg_class + * + * NOTE: only "bootstrapped" relations need to be declared here. Be sure that + * the OIDs listed here match those given in their CATALOG macros, and that + * the relnatts values are correct. + * ---------------- + */ + +/* Note: "3" in the relfrozenxid and the relfrozenxid64 column stands for FirstNormalTransactionId */ +DATA(insert OID = 1247 ( pg_type PGNSP 71 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 30 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1249 ( pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 24 0 f f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 32 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 39 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); + +#define RELKIND_RELATION 'r' /* ordinary table */ +#define RELKIND_INDEX 'i' /* secondary index */ +#define RELKIND_GLOBAL_INDEX 'I' /* GLOBAL partitioned index */ +#define RELKIND_SEQUENCE 'S' /* sequence object */ +#define RELKIND_TOASTVALUE 't' /* for out-of-line values */ +#define RELKIND_VIEW 'v' /* view */ +#define RELKIND_MATVIEW 'm' /* materialized view */ +#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */ +#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */ +#define RELKIND_STREAM 'e' /* stream */ +#define RELKIND_CONTQUERY 'o' /* contquery */ +#define PARTTYPE_PARTITIONED_RELATION 'p' /* partitioned relation */ +#define PARTTYPE_VALUE_PARTITIONED_RELATION 'v' /* value partitioned relation */ +#define PARTTYPE_NON_PARTITIONED_RELATION 'n' /* non-partitioned relation */ +#define RELPERSISTENCE_PERMANENT 'p' /* regular table */ +#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */ +#define RELPERSISTENCE_TEMP 't' /* temporary table */ +#define RELPERSISTENCE_GLOBAL_TEMP 'g' /* global temporary table */ + +/* default selection for replica identity (primary key or nothing) */ +#define REPLICA_IDENTITY_DEFAULT 'd' +/* no replica identity is logged for this relation */ +#define REPLICA_IDENTITY_NOTHING 'n' +/* all columns are loged as replica identity */ +#define REPLICA_IDENTITY_FULL 'f' + +/* + * Relation kinds that have physical storage. These relations normally have + * relfilenode set to non-zero, but it can also be zero if the relation is + * mapped. + */ +#define RELKIND_HAS_STORAGE(relkind) \ + ((relkind) == RELKIND_RELATION || \ + (relkind) == RELKIND_INDEX || \ + (relkind) == RELKIND_SEQUENCE || \ + (relkind) == RELKIND_TOASTVALUE) + +/* + * an explicitly chosen candidate key's columns are used as identity; + * will still be set if the index has been dropped, in that case it + * has the same meaning as 'd' + */ +#define REPLICA_IDENTITY_INDEX 'i' +#endif /* PG_CLASS_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_collation_fn.h postgresql-hll-2.14/include/catalog/pg_collation_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_collation_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_collation_fn.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * pg_collation_fn.h + * prototypes for functions in catalog/pg_collation.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_collation_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_COLLATION_FN_H +#define PG_COLLATION_FN_H + +extern Oid CollationCreate(const char *collname, Oid collnamespace, Oid collowner, int32 collencoding, + const char *collcollate, const char *collctype); +extern void RemoveCollationById(Oid collationOid); + +#endif /* PG_COLLATION_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_collation.h postgresql-hll-2.14/include/catalog/pg_collation.h --- postgresql-hll-2.14_old/include/catalog/pg_collation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_collation.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * pg_collation.h + * definition of the system "collation" relation (pg_collation) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/pg_collation.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_COLLATION_H +#define PG_COLLATION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_collation definition. cpp turns this into + * typedef struct FormData_pg_collation + * ---------------- + */ +#define CollationRelationId 3456 +#define CollationRelation_Rowtype_Id 11656 + +CATALOG(pg_collation,3456) BKI_SCHEMA_MACRO +{ + NameData collname; /* collation name */ + Oid collnamespace; /* OID of namespace containing collation */ + Oid collowner; /* owner of collation */ + int4 collencoding; /* encoding for this collation; -1 = "all" */ + NameData collcollate; /* LC_COLLATE setting */ + NameData collctype; /* LC_CTYPE setting */ +} FormData_pg_collation; + +/* ---------------- + * Form_pg_collation corresponds to a pointer to a row with + * the format of pg_collation relation. + * ---------------- + */ +typedef FormData_pg_collation *Form_pg_collation; + +/* ---------------- + * compiler constants for pg_collation + * ---------------- + */ +#define Natts_pg_collation 6 +#define Anum_pg_collation_collname 1 +#define Anum_pg_collation_collnamespace 2 +#define Anum_pg_collation_collowner 3 +#define Anum_pg_collation_collencoding 4 +#define Anum_pg_collation_collcollate 5 +#define Anum_pg_collation_collctype 6 + +/* ---------------- + * initial contents of pg_collation + * ---------------- + */ + +DATA(insert OID = 100 ( default PGNSP PGUID -1 "" "" )); +DESCR("database's default collation"); +#define DEFAULT_COLLATION_OID 100 +DATA(insert OID = 950 ( C PGNSP PGUID -1 "C" "C" )); +DESCR("standard C collation"); +#define C_COLLATION_OID 950 +DATA(insert OID = 951 ( POSIX PGNSP PGUID -1 "POSIX" "POSIX" )); +DESCR("standard POSIX collation"); +#define POSIX_COLLATION_OID 951 + +#endif /* PG_COLLATION_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_constraint.h postgresql-hll-2.14/include/catalog/pg_constraint.h --- postgresql-hll-2.14_old/include/catalog/pg_constraint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_constraint.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,283 @@ +/* ------------------------------------------------------------------------- + * + * pg_constraint.h + * definition of the system "constraint" relation (pg_constraint) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_constraint.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONSTRAINT_H +#define PG_CONSTRAINT_H + +#include "catalog/genbki.h" +#include "catalog/dependency.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_constraint definition. cpp turns this into + * typedef struct FormData_pg_constraint + * ---------------- + */ +#define ConstraintRelationId 2606 +#define ConstraintRelation_Rowtype_Id 10001 + +CATALOG(pg_constraint,2606) BKI_SCHEMA_MACRO +{ + /* + * conname + connamespace is deliberately not unique; we allow, for + * example, the same name to be used for constraints of different + * relations. This is partly for backwards compatibility with past + * Postgres practice, and partly because we don't want to have to obtain a + * global lock to generate a globally unique name for a nameless + * constraint. We associate a namespace with constraint names only for + * SQL-spec compatibility. + */ + NameData conname; /* name of this constraint */ + Oid connamespace; /* OID of namespace containing constraint */ + char contype; /* constraint type; see codes below */ + bool condeferrable; /* deferrable constraint? */ + bool condeferred; /* deferred by default? */ + bool convalidated; /* constraint has been validated? */ + + /* + * conrelid and conkey are only meaningful if the constraint applies to a + * specific relation (this excludes domain constraints and assertions). + * Otherwise conrelid is 0 and conkey is NULL. + */ + Oid conrelid; /* relation this constraint constrains */ + + /* + * contypid links to the pg_type row for a domain if this is a domain + * constraint. Otherwise it's 0. + * + * For SQL-style global ASSERTIONs, both conrelid and contypid would be + * zero. This is not presently supported, however. + */ + Oid contypid; /* domain this constraint constrains */ + + /* + * conindid links to the index supporting the constraint, if any; + * otherwise it's 0. This is used for unique, primary-key, and exclusion + * constraints, and less obviously for foreign-key constraints (where the + * index is a unique index on the referenced relation's referenced + * columns). Notice that the index is on conrelid in the first case but + * confrelid in the second. + */ + Oid conindid; /* index supporting this constraint */ + + /* + * These fields, plus confkey, are only meaningful for a foreign-key + * constraint. Otherwise confrelid is 0 and the char fields are spaces. + */ + Oid confrelid; /* relation referenced by foreign key */ + char confupdtype; /* foreign key's ON UPDATE action */ + char confdeltype; /* foreign key's ON DELETE action */ + char confmatchtype; /* foreign key's match type */ + + /* Has a local definition (hence, do not drop when coninhcount is 0) */ + bool conislocal; + + /* Number of times inherited from direct parent relation(s) */ + int4 coninhcount; + + /* Has a local definition and cannot be inherited */ + bool connoinherit; + + bool consoft; /* @hdfs show informational constraint. */ + bool conopt; /* @hdfs decide whether to optimize plan by using informational constraint. */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + + /* + * Columns of conrelid that the constraint applies to, if known (this is + * NULL for trigger constraints) + */ + int2 conkey[1]; + + /* + * If a foreign key, the referenced columns of confrelid + */ + int2 confkey[1]; + + /* + * If a foreign key, the OIDs of the PK = FK equality operators for each + * column of the constraint + */ + Oid conpfeqop[1]; + + /* + * If a foreign key, the OIDs of the PK = PK equality operators for each + * column of the constraint (i.e., equality for the referenced columns) + */ + Oid conppeqop[1]; + + /* + * If a foreign key, the OIDs of the FK = FK equality operators for each + * column of the constraint (i.e., equality for the referencing columns) + */ + Oid conffeqop[1]; + + /* + * If an exclusion constraint, the OIDs of the exclusion operators for + * each column of the constraint + */ + Oid conexclop[1]; + + /* + * If a check constraint, nodeToString representation of expression + */ + pg_node_tree conbin; + + /* + * If a check constraint, source-text representation of expression + */ + text consrc; + + /* + * Columns of conrelid that the constraint does not apply to, but included + * into the same index with key columns. + */ + int2 conincluding[1]; +#endif +} FormData_pg_constraint; + +/* ---------------- + * Form_pg_constraint corresponds to a pointer to a tuple with + * the format of pg_constraint relation. + * ---------------- + */ +typedef FormData_pg_constraint *Form_pg_constraint; + +/* ---------------- + * compiler constants for pg_constraint + * ---------------- + */ +#define Natts_pg_constraint 27 +#define Anum_pg_constraint_conname 1 +#define Anum_pg_constraint_connamespace 2 +#define Anum_pg_constraint_contype 3 +#define Anum_pg_constraint_condeferrable 4 +#define Anum_pg_constraint_condeferred 5 +#define Anum_pg_constraint_convalidated 6 +#define Anum_pg_constraint_conrelid 7 +#define Anum_pg_constraint_contypid 8 +#define Anum_pg_constraint_conindid 9 +#define Anum_pg_constraint_confrelid 10 +#define Anum_pg_constraint_confupdtype 11 +#define Anum_pg_constraint_confdeltype 12 +#define Anum_pg_constraint_confmatchtype 13 +#define Anum_pg_constraint_conislocal 14 +#define Anum_pg_constraint_coninhcount 15 +#define Anum_pg_constraint_connoinherit 16 +#define Anum_pg_constraint_consoft 17 +#define Anum_pg_constraint_conopt 18 +#define Anum_pg_constraint_conkey 19 +#define Anum_pg_constraint_confkey 20 +#define Anum_pg_constraint_conpfeqop 21 +#define Anum_pg_constraint_conppeqop 22 +#define Anum_pg_constraint_conffeqop 23 +#define Anum_pg_constraint_conexclop 24 +#define Anum_pg_constraint_conbin 25 +#define Anum_pg_constraint_consrc 26 +#define Anum_pg_constraint_conincluding 27 + + +/* Valid values for contype */ +#define CONSTRAINT_CHECK 'c' +#define CONSTRAINT_FOREIGN 'f' +#define CONSTRAINT_PRIMARY 'p' +#define CONSTRAINT_UNIQUE 'u' +#define CONSTRAINT_TRIGGER 't' +#define CONSTRAINT_EXCLUSION 'x' +#define CONSTRAINT_CLUSTER 's' +#define CONSTRAINT_INVALID 'i' + + +/* + * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx + * constants defined in parsenodes.h. Valid values for confmatchtype are + * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h. + */ + +/* + * Identify constraint type for lookup purposes + */ +typedef enum ConstraintCategory +{ + CONSTRAINT_RELATION, + CONSTRAINT_DOMAIN, + CONSTRAINT_ASSERTION /* for future expansion */ +} ConstraintCategory; + +/* + * prototypes for functions in pg_constraint.c + */ +extern Oid CreateConstraintEntry(const char *constraintName, + Oid constraintNamespace, + char constraintType, + bool isDeferrable, + bool isDeferred, + bool isValidated, + Oid relId, + const int16 *constraintKey, + int constraintNKeys, + int constraintNTotalKeys, + Oid domainId, + Oid indexRelId, + Oid foreignRelId, + const int16 *foreignKey, + const Oid *pfEqOp, + const Oid *ppEqOp, + const Oid *ffEqOp, + int foreignNKeys, + char foreignUpdateType, + char foreignDeleteType, + char foreignMatchType, + const Oid *exclOp, + Node *conExpr, + const char *conBin, + const char *conSrc, + bool conIsLocal, + int conInhCount, + bool conNoInherit, + InformationalConstraint *inforConstraint); + +extern void RemoveConstraintById(Oid conId); +extern void RenameConstraintById(Oid conId, const char *newname); +extern void SetValidatedConstraintById(Oid conId); + +extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, + Oid objNamespace, const char *conname); +extern char *ChooseConstraintName(const char *name1, const char *name2, + const char *label, Oid namespaceid, + List *others); + +extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, + Oid newNspId, bool isType, ObjectAddresses *objsMoved); +extern void get_constraint_relation_oids(Oid constraint_oid, Oid *conrelid, Oid *confrelid); +extern Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok); +extern Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok); + +extern bool check_functional_grouping(Oid relid, + Index varno, Index varlevelsup, + List *grouping_columns, + List **constraintDeps); + +extern List *get_parse_dependency_rel_list(List *conids); + +#ifdef PGXC +extern int pgxc_find_primarykey(Oid relid, int16 **indexed_col, bool check_is_immediate = false); +#endif + +#endif /* PG_CONSTRAINT_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_control.h postgresql-hll-2.14/include/catalog/pg_control.h --- postgresql-hll-2.14_old/include/catalog/pg_control.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_control.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,305 @@ +/* ------------------------------------------------------------------------- + * + * pg_control.h + * The system control file "pg_control" is not a heap relation. + * However, we define it here so that the format is documented. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_control.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONTROL_H +#define PG_CONTROL_H + +#include "access/xlogdefs.h" +#include "pgtime.h" /* for pg_time_t */ +#include "utils/pg_crc.h" +#include "port/pg_crc32c.h" + + +/* Version identifier for this pg_control format */ +#define PG_CONTROL_VERSION 923 + +/* + * Body of CheckPoint XLOG records. This is declared here because we keep + * a copy of the latest one in pg_control for possible disaster recovery. + * Changing this struct requires a PG_CONTROL_VERSION bump. + */ +typedef struct CheckPoint { + XLogRecPtr redo; /* next RecPtr available when we began to + * create CheckPoint (i.e. REDO start point) */ + TimeLineID ThisTimeLineID; /* current TLI */ + bool fullPageWrites; /* current full_page_writes */ + TransactionId nextXid; /* next free XID */ + Oid nextOid; /* next free OID */ + MultiXactId nextMulti; /* next free MultiXactId */ + MultiXactOffset nextMultiOffset; /* next free MultiXact offset */ + TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + pg_time_t time; /* time stamp of checkpoint */ + XLogSegNo remove_seg; /*the xlog segno we keep during this checkpoint*/ + /* + * Oldest XID still running. This is only needed to initialize hot standby + * mode from an online checkpoint, so we only bother calculating this for + * online checkpoints and only when wal_level is hot_standby. Otherwise + * it's set to InvalidTransactionId. + */ + TransactionId oldestActiveXid; +} CheckPoint; + +/* + * checkpoint new + */ +typedef struct CheckPointNew { + CheckPoint ori_checkpoint; + CommitSeqNo next_csn; +} CheckPointNew; + +/* add length to distinguish between different versions of checkpoint */ +typedef struct CheckPointPlus +{ + CheckPoint ori_checkpoint; + CommitSeqNo next_csn; + uint64 length; + TransactionId recent_global_xmin; + /* you can add more attributes here */ +} CheckPointPlus; + +typedef struct CheckPointOld { + XLogRecPtrOld redo; /* next RecPtr available when we began to + * create CheckPoint (i.e. REDO start point) */ + TimeLineID ThisTimeLineID; /* current TLI */ + bool fullPageWrites; /* current full_page_writes */ + uint32 nextXidEpoch; /* higher-order bits of nextXid */ + ShortTransactionId nextXid; /* next free XID */ + Oid nextOid; /* next free OID */ + ShortTransactionId nextMulti; /* next free MultiXactId */ + ShortTransactionId nextMultiOffset; /* next free MultiXact offset */ + ShortTransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + pg_time_t time; /* time stamp of checkpoint */ + ShortTransactionId oldestActiveXid; +} CheckPointOld; + + +/* XLOG info values for XLOG rmgr */ + +#define XLOG_CHECKPOINT_SHUTDOWN 0x00 +#define XLOG_CHECKPOINT_ONLINE 0x10 +#define XLOG_NOOP 0x20 +#define XLOG_NEXTOID 0x30 +#define XLOG_SWITCH 0x40 +#define XLOG_BACKUP_END 0x50 +#define XLOG_PARAMETER_CHANGE 0x60 +#define XLOG_RESTORE_POINT 0x70 +#define XLOG_FPW_CHANGE 0x80 +#define XLOG_END_OF_RECOVERY 0x90 /* not use in mppdb*/ +#define XLOG_FPI_FOR_HINT 0xA0 +#define XLOG_FPI 0xB0 /* not use in mppdb*/ +#define XLOG_DELAY_XLOG_RECYCLE 0xC0 + + +/* + * System status indicator. Note this is stored in pg_control; if you change + * it, you must bump PG_CONTROL_VERSION + */ +typedef enum DBState { + DB_STARTUP = 0, + DB_SHUTDOWNED, + DB_SHUTDOWNED_IN_RECOVERY, + DB_SHUTDOWNING, + DB_IN_CRASH_RECOVERY, + DB_IN_ARCHIVE_RECOVERY, + DB_IN_PRODUCTION +} DBState; + +/* + * Contents of pg_control. + * + * NOTE: try to keep this under 512 bytes so that it will fit on one physical + * sector of typical disk drives. This reduces the odds of corruption due to + * power failure midway through a write. + */ +typedef struct ControlFileData { + /* + * Unique system identifier --- to ensure we match up xlog files with the + * installation that produced them. + */ + uint64 system_identifier; + + /* + * Version identifier information. Keep these fields at the same offset, + * especially pg_control_version; they won't be real useful if they move + * around. (For historical reasons they must be 8 bytes into the file + * rather than immediately at the front.) + * + * pg_control_version identifies the format of pg_control itself. + * catalog_version_no identifies the format of the system catalogs. + * + * There are additional version identifiers in individual files; for + * example, WAL logs contain per-page magic numbers that can serve as + * version cues for the WAL log. + */ + uint32 pg_control_version; /* PG_CONTROL_VERSION */ + uint32 catalog_version_no; /* see catversion.h */ + uint32 timeline; + + /* + * System status data + */ + DBState state; /* see enum above */ + pg_time_t time; /* time stamp of last pg_control update */ + XLogRecPtr checkPoint; /* last check point record ptr */ + XLogRecPtr prevCheckPoint; /* previous check point record ptr */ + + CheckPoint checkPointCopy; /* copy of last check point record */ + + /* + * These two values determine the minimum point we must recover up to + * before starting up: + * + * minRecoveryPoint is updated to the latest replayed LSN whenever we + * flush a data change during archive recovery. That guards against + * starting archive recovery, aborting it, and restarting with an earlier + * stop location. If we've already flushed data changes from WAL record X + * to disk, we mustn't start up until we reach X again. Zero when not + * doing archive recovery. + * + * backupStartPoint is the redo pointer of the backup start checkpoint, if + * we are recovering from an online backup and haven't reached the end of + * backup yet. It is reset to zero when the end of backup is reached, and + * we mustn't start up before that. A boolean would suffice otherwise, but + * we use the redo pointer as a cross-check when we see an end-of-backup + * record, to make sure the end-of-backup record corresponds the base + * backup we're recovering from. + * + * backupEndPoint is the backup end location, if we are recovering from an + * online backup which was taken from the standby and haven't reached the + * end of backup yet. It is initialized to the minimum recovery point in + * pg_control which was backed up last. It is reset to zero when the end + * of backup is reached, and we mustn't start up before that. + * + * If backupEndRequired is true, we know for sure that we're restoring + * from a backup, and must see a backup-end record before we can safely + * start up. If it's false, but backupStartPoint is set, a backup_label + * file was found at startup but it may have been a leftover from a stray + * pg_start_backup() call, not accompanied by pg_stop_backup(). + */ + XLogRecPtr minRecoveryPoint; + XLogRecPtr backupStartPoint; + XLogRecPtr backupEndPoint; + bool backupEndRequired; + + /* + * Parameter settings that determine if the WAL can be used for archival + * or hot standby. + */ + int wal_level; + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + + /* + * This data is used to check for hardware-architecture compatibility of + * the database and the backend executable. We need not check endianness + * explicitly, since the pg_control version will surely look wrong to a + * machine of different endianness, but we do need to worry about MAXALIGN + * and floating-point format. (Note: storage layout nominally also + * depends on SHORTALIGN and INTALIGN, but in practice these are the same + * on all architectures of interest.) + * + * Testing just one double value is not a very bulletproof test for + * floating-point compatibility, but it will catch most cases. + */ + uint32 maxAlign; /* alignment requirement for tuples */ + double floatFormat; /* constant 1234567.0 */ +#define FLOATFORMAT_VALUE 1234567.0 + + /* + * This data is used to make sure that configuration of this database is + * compatible with the backend executable. + */ + uint32 blcksz; /* data block size for this DB */ + uint32 relseg_size; /* blocks per segment of large relation */ + + uint32 xlog_blcksz; /* block size within WAL files */ + uint32 xlog_seg_size; /* size of each WAL segment */ + + uint32 nameDataLen; /* catalog name field width */ + uint32 indexMaxKeys; /* max number of columns in an index */ + + uint32 toast_max_chunk_size; /* chunk size in TOAST tables */ + + /* flag indicating internal format of timestamp, interval, time */ + bool enableIntTimes; /* int64 storage enabled? */ + + /* flags indicating pass-by-value status of various types */ + bool float4ByVal; /* float4 pass-by-value? */ + bool float8ByVal; /* float8, int8, etc pass-by-value? */ + + /* CRC of all above ... MUST BE LAST! */ + pg_crc32c crc; +} ControlFileData; + +/*This struct is used to verify the checksum of old version control file*/ +typedef struct ControlFileDataOld { + uint64 system_identifier; + uint32 pg_control_version; + uint32 catalog_version_no; + uint32 timeline; + DBState state; + pg_time_t time; + XLogRecPtrOld checkPoint; + XLogRecPtrOld prevCheckPoint; + CheckPointOld checkPointCopy; + XLogRecPtrOld minRecoveryPoint; + XLogRecPtrOld backupStartPoint; + XLogRecPtrOld backupEndPoint; + bool backupEndRequired; + int wal_level; + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + uint32 maxAlign; + double floatFormat; + uint32 blcksz; + uint32 relseg_size; + uint32 xlog_blcksz; + uint32 xlog_seg_size; + uint32 nameDataLen; + uint32 indexMaxKeys; + uint32 toast_max_chunk_size; + bool enableIntTimes; + bool float4ByVal; + bool float8ByVal; + pg_crc32 crc; +}ControlFileDataOld; + +typedef struct LsnXlogFlushData { + XLogRecPtr localLsnFlushPoint; /* latest flush buffer's lsn postion on primary*/ + XLogRecPtr peerXlogFlushPoint; /* flush xlog postion on standby */ + pg_crc32 crc; +} LsnXlogFlushData; + +/* + * Physical size of the pg_control file. Note that this is considerably + * bigger than the actually used size (ie, sizeof(ControlFileData)). + * The idea is to keep the physical size constant independent of format + * changes, so that ReadControlFile will deliver a suitable wrong-version + * message instead of a read error if it's looking at an incompatible file. + */ +#define PG_CONTROL_SIZE 8192 + +#define PG_LSNXLOGFLUSHCHK_FILESIZE 512 +extern uint32 get_controlfile_timeline(void); +/* + * LsnXlogFlushData struct reserved 40 bytes,may be used in the future. + */ +#define PG_LSNXLOGFLUSHCHK_DATASIZE (40 + 2 * sizeof (XLogRecPtr)) + +#endif /* PG_CONTROL_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_conversion_fn.h postgresql-hll-2.14/include/catalog/pg_conversion_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_conversion_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_conversion_fn.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * pg_conversion_fn.h + * prototypes for functions in catalog/pg_conversion.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_conversion_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONVERSION_FN_H +#define PG_CONVERSION_FN_H + +extern Oid ConversionCreate(const char *conname, Oid connamespace, + Oid conowner, + int32 conforencoding, int32 contoencoding, + Oid conproc, bool def); +extern void RemoveConversionById(Oid conversionOid); +extern Oid FindDefaultConversion(Oid connamespace, int32 for_encoding, int32 to_encoding); + +#endif /* PG_CONVERSION_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_conversion.h postgresql-hll-2.14/include/catalog/pg_conversion.h --- postgresql-hll-2.14_old/include/catalog/pg_conversion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_conversion.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * pg_conversion.h + * definition of the system "conversion" relation (pg_conversion) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_conversion.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONVERSION_H +#define PG_CONVERSION_H + +#include "catalog/genbki.h" + +/* ---------------------------------------------------------------- + * pg_conversion definition. + * + * cpp turns this into typedef struct FormData_pg_namespace + * + * conname name of the conversion + * connamespace name space which the conversion belongs to + * conowner owner of the conversion + * conforencoding FOR encoding id + * contoencoding TO encoding id + * conproc OID of the conversion proc + * condefault TRUE if this is a default conversion + * ---------------------------------------------------------------- + */ +#define ConversionRelationId 2607 +#define ConversionRelation_Rowtype_Id 11630 + +CATALOG(pg_conversion,2607) BKI_SCHEMA_MACRO +{ + NameData conname; + Oid connamespace; + Oid conowner; + int4 conforencoding; + int4 contoencoding; + regproc conproc; + bool condefault; +} FormData_pg_conversion; + +/* ---------------- + * Form_pg_conversion corresponds to a pointer to a tuple with + * the format of pg_conversion relation. + * ---------------- + */ +typedef FormData_pg_conversion *Form_pg_conversion; + +/* ---------------- + * compiler constants for pg_conversion + * ---------------- + */ +#define Natts_pg_conversion 7 +#define Anum_pg_conversion_conname 1 +#define Anum_pg_conversion_connamespace 2 +#define Anum_pg_conversion_conowner 3 +#define Anum_pg_conversion_conforencoding 4 +#define Anum_pg_conversion_contoencoding 5 +#define Anum_pg_conversion_conproc 6 +#define Anum_pg_conversion_condefault 7 + +/* ---------------- + * initial contents of pg_conversion + * --------------- + */ +#endif /* PG_CONVERSION_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_database.h postgresql-hll-2.14/include/catalog/pg_database.h --- postgresql-hll-2.14_old/include/catalog/pg_database.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_database.h 2020-12-12 17:06:43.079345871 +0800 @@ -0,0 +1,91 @@ +/* ------------------------------------------------------------------------- + * + * pg_database.h + * definition of the system "database" relation (pg_database) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_database.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DATABASE_H +#define PG_DATABASE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_database definition. cpp turns this into + * typedef struct FormData_pg_database + * ---------------- + */ +#define DatabaseRelationId 1262 +#define DatabaseRelation_Rowtype_Id 1248 + +CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_MACRO +{ + NameData datname; /* database name */ + Oid datdba; /* owner of database */ + int4 encoding; /* character encoding */ + NameData datcollate; /* LC_COLLATE setting */ + NameData datctype; /* LC_CTYPE setting */ + bool datistemplate; /* allowed as CREATE DATABASE template? */ + bool datallowconn; /* new connections allowed? */ + int4 datconnlimit; /* max connections allowed (-1=no limit) */ + Oid datlastsysoid; /* highest OID to consider a system OID */ + ShortTransactionId datfrozenxid; /* all Xids < this are frozen in this DB */ + Oid dattablespace; /* default table space for this DB */ + NameData datcompatibility; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem datacl[1]; /* access permissions */ +#endif + TransactionId datfrozenxid64; /* all Xids < this are frozen in this DB */ +} FormData_pg_database; + +/* Size of fixed part of pg_database tuples, not counting var-length fields */ +#define DATABASE_TUPLE_SIZE \ + (offsetof(FormData_pg_database, datcompatibility) + sizeof(NameData)) + +/* ---------------- + * Form_pg_database corresponds to a pointer to a tuple with + * the format of pg_database relation. + * ---------------- + */ +typedef FormData_pg_database *Form_pg_database; + +/* ---------------- + * compiler constants for pg_database + * ---------------- + */ +#define Natts_pg_database 14 +#define Anum_pg_database_datname 1 +#define Anum_pg_database_datdba 2 +#define Anum_pg_database_encoding 3 +#define Anum_pg_database_datcollate 4 +#define Anum_pg_database_datctype 5 +#define Anum_pg_database_datistemplate 6 +#define Anum_pg_database_datallowconn 7 +#define Anum_pg_database_datconnlimit 8 +#define Anum_pg_database_datlastsysoid 9 +#define Anum_pg_database_datfrozenxid 10 +#define Anum_pg_database_dattablespace 11 +#define Anum_pg_database_compatibility 12 +#define Anum_pg_database_datacl 13 +#define Anum_pg_database_datfrozenxid64 14 + +DATA(insert OID = 1 ( template1 PGUID ENCODING "LC_COLLATE" "LC_CTYPE" t t -1 0 0 1663 "DB_COMPATIBILITY" _null_ 3)); +SHDESCR("default template for new databases"); +#define TemplateDbOid 1 + +#define DEFAULT_DATABASE "postgres" + +#endif /* PG_DATABASE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_db_role_setting.h postgresql-hll-2.14/include/catalog/pg_db_role_setting.h --- postgresql-hll-2.14_old/include/catalog/pg_db_role_setting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_db_role_setting.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,69 @@ +/* ------------------------------------------------------------------------- + * + * pg_db_role_setting.h + * definition of configuration settings + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_db_role_setting.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DB_ROLE_SETTING_H +#define PG_DB_ROLE_SETTING_H + +#include "utils/guc.h" +#include "utils/relcache.h" + +/* ---------------- + * pg_db_role_setting definition. cpp turns this into + * typedef struct FormData_pg_db_role_setting + * ---------------- + */ +#define DbRoleSettingRelationId 2964 +#define DbRoleSettingRelation_Rowtype_Id 11632 + +CATALOG(pg_db_role_setting,2964) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid setdatabase; /* database */ + Oid setrole; /* role */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text setconfig[1]; /* GUC settings to apply at login */ +#endif +} FormData_pg_db_role_setting; + +typedef FormData_pg_db_role_setting *Form_pg_db_role_setting; + +/* ---------------- + * compiler constants for pg_db_role_setting + * ---------------- + */ +#define Natts_pg_db_role_setting 3 +#define Anum_pg_db_role_setting_setdatabase 1 +#define Anum_pg_db_role_setting_setrole 2 +#define Anum_pg_db_role_setting_setconfig 3 + +/* ---------------- + * initial contents of pg_db_role_setting are NOTHING + * ---------------- + */ + +/* + * prototypes for functions in pg_db_role_setting.h + */ +extern void AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt); +extern void DropSetting(Oid databaseid, Oid roleid); +extern void ApplySetting(Oid databaseid, Oid roleid, Relation relsetting, GucSource source); + +#endif /* PG_DB_ROLE_SETTING_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_default_acl.h postgresql-hll-2.14/include/catalog/pg_default_acl.h --- postgresql-hll-2.14_old/include/catalog/pg_default_acl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_default_acl.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------------- + * + * pg_default_acl.h + * definition of default ACLs for new objects. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_default_acl.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DEFAULT_ACL_H +#define PG_DEFAULT_ACL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_default_acl definition. cpp turns this into + * typedef struct FormData_pg_default_acl + * ---------------- + */ +#define DefaultAclRelationId 826 +#define DefaultAclRelation_Rowtype_Id 11653 + +CATALOG(pg_default_acl,826) BKI_SCHEMA_MACRO +{ + Oid defaclrole; /* OID of role owning this ACL */ + Oid defaclnamespace; /* OID of namespace, or 0 for all */ + char defaclobjtype; /* see DEFACLOBJ_xxx constants below */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem defaclacl[1]; /* permissions to add at CREATE time */ +#endif +} FormData_pg_default_acl; + +/* ---------------- + * Form_pg_default_acl corresponds to a pointer to a tuple with + * the format of pg_default_acl relation. + * ---------------- + */ +typedef FormData_pg_default_acl *Form_pg_default_acl; + +/* ---------------- + * compiler constants for pg_default_acl + * ---------------- + */ +#define Natts_pg_default_acl 4 +#define Anum_pg_default_acl_defaclrole 1 +#define Anum_pg_default_acl_defaclnamespace 2 +#define Anum_pg_default_acl_defaclobjtype 3 +#define Anum_pg_default_acl_defaclacl 4 + +/* ---------------- + * pg_default_acl has no initial contents + * ---------------- + */ + +/* + * Types of objects for which the user is allowed to specify default + * permissions through pg_default_acl. These codes are used in the + * defaclobjtype column. + */ +#define DEFACLOBJ_RELATION 'r' /* table, view */ +#define DEFACLOBJ_SEQUENCE 'S' /* sequence */ +#define DEFACLOBJ_FUNCTION 'f' /* function */ +#define DEFACLOBJ_TYPE 'T' /* type */ +#define DEFACLOBJ_GLOBAL_SETTING 'K' /* Global Setting */ +#define DEFACLOBJ_COLUMN_SETTING 'k' /* Column Setting */ +#endif /* PG_DEFAULT_ACL_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_depend.h postgresql-hll-2.14/include/catalog/pg_depend.h --- postgresql-hll-2.14_old/include/catalog/pg_depend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_depend.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,92 @@ +/* ------------------------------------------------------------------------- + * + * pg_depend.h + * definition of the system "dependency" relation (pg_depend) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_depend.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DEPEND_H +#define PG_DEPEND_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_depend definition. cpp turns this into + * typedef struct FormData_pg_depend + * ---------------- + */ +#define DependRelationId 2608 +#define DependRelation_Rowtype_Id 11631 + +CATALOG(pg_depend,2608) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* + * Identification of the dependent (referencing) object. + * + * These fields are all zeroes for a DEPENDENCY_PIN entry. + */ + Oid classid; /* OID of table containing object */ + Oid objid; /* OID of object itself */ + int4 objsubid; /* column number, or 0 if not used */ + + /* + * Identification of the independent (referenced) object. + */ + Oid refclassid; /* OID of table containing object */ + Oid refobjid; /* OID of object itself */ + int4 refobjsubid; /* column number, or 0 if not used */ + + /* + * Precise semantics of the relationship are specified by the deptype + * field. See DependencyType in catalog/dependency.h. + */ + char deptype; /* see codes in dependency.h */ +} FormData_pg_depend; + +/* ---------------- + * Form_pg_depend corresponds to a pointer to a row with + * the format of pg_depend relation. + * ---------------- + */ +typedef FormData_pg_depend *Form_pg_depend; + +/* ---------------- + * compiler constants for pg_depend + * ---------------- + */ +#define Natts_pg_depend 7 +#define Anum_pg_depend_classid 1 +#define Anum_pg_depend_objid 2 +#define Anum_pg_depend_objsubid 3 +#define Anum_pg_depend_refclassid 4 +#define Anum_pg_depend_refobjid 5 +#define Anum_pg_depend_refobjsubid 6 +#define Anum_pg_depend_deptype 7 + + +/* + * pg_depend has no preloaded contents; system-defined dependencies are + * loaded into it during a late stage of the initdb process. + * + * NOTE: we do not represent all possible dependency pairs in pg_depend; + * for example, there's not much value in creating an explicit dependency + * from an attribute to its relation. Usually we make a dependency for + * cases where the relationship is conditional rather than essential + * (for example, not all triggers are dependent on constraints, but all + * attributes are dependent on relations) or where the dependency is not + * convenient to find from the contents of other catalogs. + */ + +#endif /* PG_DEPEND_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_description.h postgresql-hll-2.14/include/catalog/pg_description.h --- postgresql-hll-2.14_old/include/catalog/pg_description.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_description.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,89 @@ +/* ------------------------------------------------------------------------- + * + * pg_description.h + * definition of the system "description" relation (pg_description) + * + * NOTE: an object is identified by the OID of the row that primarily + * defines the object, plus the OID of the table that that row appears in. + * For example, a function is identified by the OID of its pg_proc row + * plus the pg_class OID of table pg_proc. This allows unique identification + * of objects without assuming that OIDs are unique across tables. + * + * Since attributes don't have OIDs of their own, we identify an attribute + * comment by the objoid+classoid of its parent table, plus an "objsubid" + * giving the attribute column number. "objsubid" must be zero in a comment + * for a table itself, so that it is distinct from any column comment. + * Currently, objsubid is unused and zero for all other kinds of objects, + * but perhaps it might be useful someday to associate comments with + * constituent elements of other kinds of objects (arguments of a function, + * for example). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_description.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DESCRIPTION_H +#define PG_DESCRIPTION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_description definition. cpp turns this into + * typedef struct FormData_pg_description + * ---------------- + */ +#define DescriptionRelationId 2609 +#define DescriptionRelation_Rowtype_Id 11330 + +CATALOG(pg_description,2609) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of object itself */ + Oid classoid; /* OID of table containing object */ + int4 objsubid; /* column number, or 0 if not used */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text description; /* description of object */ +#endif +} FormData_pg_description; + +/* ---------------- + * Form_pg_description corresponds to a pointer to a tuple with + * the format of pg_description relation. + * ---------------- + */ +typedef FormData_pg_description *Form_pg_description; + +/* ---------------- + * compiler constants for pg_description + * ---------------- + */ +#define Natts_pg_description 4 +#define Anum_pg_description_objoid 1 +#define Anum_pg_description_classoid 2 +#define Anum_pg_description_objsubid 3 +#define Anum_pg_description_description 4 + +/* ---------------- + * initial contents of pg_description + * ---------------- + */ + +/* + * Because the contents of this table are taken from the other *.h files, + * there is no initialization here. The initial contents are extracted + * by genbki.pl and loaded during initdb. + */ + +#endif /* PG_DESCRIPTION_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_directory.h postgresql-hll-2.14/include/catalog/pg_directory.h --- postgresql-hll-2.14_old/include/catalog/pg_directory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_directory.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_directory.h + * definition of the system "pg_directory" relation (pg_directory) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_directory.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_DIRECTORY_H +#define PG_DIRECTORY_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" + +/* ------------------------------------------------------------------------- + * pg_directories definition. cpp turns this into + * typedef struct FormData_pg_directory + * ------------------------------------------------------------------------- + */ +#define PgDirectoryRelationId 4347 +#define PgDirectoryRelation_Rowtype_Id 11662 + +CATALOG(pg_directory,4347) BKI_SCHEMA_MACRO +{ + NameData dirname; /* directory name */ + Oid owner; /* owner of directory */ + text dirpath; /* real directory path */ +#ifdef CATALOG_VARLEN /* variable-length fields start here*/ + aclitem diracl[1]; /* access permissions */ +#endif +} FormData_pg_directory; + + +/* ------------------------------------------------------------------------- + * Form_pg_directory corresponds to a pointer to a tuple with + * the format of pg_directory relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_directory* Form_pg_directory; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_directory + * ------------------------------------------------------------------------- + */ +#define Natts_pg_directory 4 +#define Anum_pg_directory_directory_name 1 +#define Anum_pg_directory_owner 2 +#define Anum_pg_directory_directory_path 3 +#define Anum_pg_directory_directory_acl 4 + +#endif /* PG_DIRECTORY_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_enum.h postgresql-hll-2.14/include/catalog/pg_enum.h --- postgresql-hll-2.14_old/include/catalog/pg_enum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_enum.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,74 @@ +/* ------------------------------------------------------------------------- + * + * pg_enum.h + * definition of the system "enum" relation (pg_enum) + * along with the relation's initial contents. + * + * + * Copyright (c) 2006-2012, PostgreSQL Global Development Group + * + * src/include/catalog/pg_enum.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ENUM_H +#define PG_ENUM_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_enum definition. cpp turns this into + * typedef struct FormData_pg_enum + * ---------------- + */ +#define EnumRelationId 3501 +#define EnumRelation_Rowtype_Id 11628 + +CATALOG(pg_enum,3501) BKI_SCHEMA_MACRO +{ + Oid enumtypid; /* OID of owning enum type */ + float4 enumsortorder; /* sort position of this enum value */ + NameData enumlabel; /* text representation of enum value */ +} FormData_pg_enum; + +/* ---------------- + * Form_pg_enum corresponds to a pointer to a tuple with + * the format of pg_enum relation. + * ---------------- + */ +typedef FormData_pg_enum *Form_pg_enum; + +/* ---------------- + * compiler constants for pg_enum + * ---------------- + */ +#define Natts_pg_enum 3 +#define Anum_pg_enum_enumtypid 1 +#define Anum_pg_enum_enumsortorder 2 +#define Anum_pg_enum_enumlabel 3 + +/* ---------------- + * pg_enum has no initial contents + * ---------------- + */ + +/* + * prototypes for functions in pg_enum.c + */ +extern void EnumValuesCreate(Oid enumTypeOid, List *vals); +extern void EnumValuesDelete(Oid enumTypeOid); +extern void AddEnumLabel(Oid enumTypeOid, const char *newVal, + const char *neighbor, bool newValIsAfter, + bool skipIfExists); +extern void RenameEnumLabel(Oid enumTypeOid, const char *oldVal, const char *newVal); + +#endif /* PG_ENUM_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_extension_data_source.h postgresql-hll-2.14/include/catalog/pg_extension_data_source.h --- postgresql-hll-2.14_old/include/catalog/pg_extension_data_source.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_extension_data_source.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,65 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_extension_data_source.h + * definition of the system "data source" relation (pg_extension_data_source) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/catalog/pg_extension_data_source.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_EXTENSION_DATA_SOURCE_H +#define PG_EXTENSION_DATA_SOURCE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_extension_data_source definition. cpp turns this into + * typedef struct FormData_pg_extension_data_source + * ---------------- + */ +#define DataSourceRelationId 4211 +#define DataSourceRelation_Rowtype_Id 7177 + +CATALOG(pg_extension_data_source,4211) BKI_SHARED_RELATION BKI_ROWTYPE_OID(7177) BKI_SCHEMA_MACRO +{ + NameData srcname; /* data source name */ + Oid srcowner; /* source owner */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text srctype; /* source type */ + text srcversion; /* source version */ + aclitem srcacl[1]; /* access permissions */ + text srcoptions[1]; /* options */ +#endif +} FormData_pg_extension_data_source; + +/* ---------------- + * Form_data_source corresponds to a pointer to a tuple with + * the format of pg_extension_data_source relation. + * ---------------- + */ +typedef FormData_pg_extension_data_source *Form_pg_extension_data_source; + +/* ---------------- + * compiler constants for pg_extension_data_source + * ---------------- + */ +#define Natts_pg_extension_data_source 6 +#define Anum_pg_extension_data_source_srcname 1 +#define Anum_pg_extension_data_source_srcowner 2 +#define Anum_pg_extension_data_source_srctype 3 +#define Anum_pg_extension_data_source_srcversion 4 +#define Anum_pg_extension_data_source_srcacl 5 +#define Anum_pg_extension_data_source_srcoptions 6 + +#endif /* PG_EXTENSION_DATA_SOURCE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_extension.h postgresql-hll-2.14/include/catalog/pg_extension.h --- postgresql-hll-2.14_old/include/catalog/pg_extension.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_extension.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,73 @@ +/* ------------------------------------------------------------------------- + * + * pg_extension.h + * definition of the system "extension" relation (pg_extension) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_extension.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_EXTENSION_H +#define PG_EXTENSION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_extension definition. cpp turns this into + * typedef struct FormData_pg_extension + * ---------------- + */ +#define ExtensionRelationId 3079 +#define ExtensionRelation_Rowtype_Id 11643 + +CATALOG(pg_extension,3079) BKI_SCHEMA_MACRO +{ + NameData extname; /* extension name */ + Oid extowner; /* extension owner */ + Oid extnamespace; /* namespace of contained objects */ + bool extrelocatable; /* if true, allow ALTER EXTENSION SET SCHEMA */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* extversion should never be null, but the others can be. */ + text extversion; /* extension version name */ + Oid extconfig[1]; /* dumpable configuration tables */ + text extcondition[1]; /* WHERE clauses for config tables */ +#endif +} FormData_pg_extension; + +/* ---------------- + * Form_pg_extension corresponds to a pointer to a tuple with + * the format of pg_extension relation. + * ---------------- + */ +typedef FormData_pg_extension *Form_pg_extension; + +/* ---------------- + * compiler constants for pg_extension + * ---------------- + */ +#define Natts_pg_extension 7 +#define Anum_pg_extension_extname 1 +#define Anum_pg_extension_extowner 2 +#define Anum_pg_extension_extnamespace 3 +#define Anum_pg_extension_extrelocatable 4 +#define Anum_pg_extension_extversion 5 +#define Anum_pg_extension_extconfig 6 +#define Anum_pg_extension_extcondition 7 + +/* ---------------- + * pg_extension has no initial contents + * ---------------- + */ + +#endif /* PG_EXTENSION_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_foreign_data_wrapper.h postgresql-hll-2.14/include/catalog/pg_foreign_data_wrapper.h --- postgresql-hll-2.14_old/include/catalog/pg_foreign_data_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_foreign_data_wrapper.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_data_wrapper.h + * definition of the system "foreign-data wrapper" relation (pg_foreign_data_wrapper) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_data_wrapper.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_DATA_WRAPPER_H +#define PG_FOREIGN_DATA_WRAPPER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_data_wrapper definition. cpp turns this into + * typedef struct FormData_pg_foreign_data_wrapper + * ---------------- + */ +#define ForeignDataWrapperRelationId 2328 +#define ForeignDataWrapperRelation_Rowtype_Id 11645 + +CATALOG(pg_foreign_data_wrapper,2328) BKI_SCHEMA_MACRO +{ + NameData fdwname; /* foreign-data wrapper name */ + Oid fdwowner; /* FDW owner */ + Oid fdwhandler; /* handler function, or 0 if none */ + Oid fdwvalidator; /* option validation function, or 0 if none */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem fdwacl[1]; /* access permissions */ + text fdwoptions[1]; /* FDW options */ +#endif +} FormData_pg_foreign_data_wrapper; + +/* ---------------- + * Form_pg_fdw corresponds to a pointer to a tuple with + * the format of pg_fdw relation. + * ---------------- + */ +typedef FormData_pg_foreign_data_wrapper *Form_pg_foreign_data_wrapper; + +/* ---------------- + * compiler constants for pg_fdw + * ---------------- + */ +#define Natts_pg_foreign_data_wrapper 6 +#define Anum_pg_foreign_data_wrapper_fdwname 1 +#define Anum_pg_foreign_data_wrapper_fdwowner 2 +#define Anum_pg_foreign_data_wrapper_fdwhandler 3 +#define Anum_pg_foreign_data_wrapper_fdwvalidator 4 +#define Anum_pg_foreign_data_wrapper_fdwacl 5 +#define Anum_pg_foreign_data_wrapper_fdwoptions 6 + +#endif /* PG_FOREIGN_DATA_WRAPPER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_foreign_server.h postgresql-hll-2.14/include/catalog/pg_foreign_server.h --- postgresql-hll-2.14_old/include/catalog/pg_foreign_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_foreign_server.h 2020-12-12 17:06:43.080345883 +0800 @@ -0,0 +1,66 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_server.h + * definition of the system "foreign server" relation (pg_foreign_server) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_server.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_SERVER_H +#define PG_FOREIGN_SERVER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_server definition. cpp turns this into + * typedef struct FormData_pg_foreign_server + * ---------------- + */ +#define ForeignServerRelationId 1417 +#define ForeignServerRelation_Rowtype_Id 11646 + + +CATALOG(pg_foreign_server,1417) BKI_SCHEMA_MACRO +{ + NameData srvname; /* foreign server name */ + Oid srvowner; /* server owner */ + Oid srvfdw; /* server FDW */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text srvtype; + text srvversion; + aclitem srvacl[1]; /* access permissions */ + text srvoptions[1]; /* FDW-specific options */ +#endif +} FormData_pg_foreign_server; + +/* ---------------- + * Form_pg_foreign_server corresponds to a pointer to a tuple with + * the format of pg_foreign_server relation. + * ---------------- + */ +typedef FormData_pg_foreign_server *Form_pg_foreign_server; + +/* ---------------- + * compiler constants for pg_foreign_server + * ---------------- + */ +#define Natts_pg_foreign_server 7 +#define Anum_pg_foreign_server_srvname 1 +#define Anum_pg_foreign_server_srvowner 2 +#define Anum_pg_foreign_server_srvfdw 3 +#define Anum_pg_foreign_server_srvtype 4 +#define Anum_pg_foreign_server_srvversion 5 +#define Anum_pg_foreign_server_srvacl 6 +#define Anum_pg_foreign_server_srvoptions 7 + +#endif /* PG_FOREIGN_SERVER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_foreign_table.h postgresql-hll-2.14/include/catalog/pg_foreign_table.h --- postgresql-hll-2.14_old/include/catalog/pg_foreign_table.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_foreign_table.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_table.h + * definition of the system "foreign table" relation (pg_foreign_table) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_table.h + * + * NOTES + * the genbki.sh script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_TABLE_H +#define PG_FOREIGN_TABLE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_table definition. cpp turns this into + * typedef struct FormData_pg_foreign_table + * ---------------- + */ +#define ForeignTableRelationId 3118 +#define ForeignTableRelation_Rowtype_Id 11651 + +CATALOG(pg_foreign_table,3118) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid ftrelid; /* OID of foreign table */ + Oid ftserver; /* OID of foreign server */ + bool ftwriteonly; /* Read/Write only, Notice: all low case */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text ftoptions[1]; /* FDW-specific options */ +#endif +} FormData_pg_foreign_table; + +/* ---------------- + * Form_pg_foreign_table corresponds to a pointer to a tuple with + * the format of pg_foreign_table relation. + * ---------------- + */ +typedef FormData_pg_foreign_table *Form_pg_foreign_table; + +/* ---------------- + * compiler constants for pg_foreign_table + * ---------------- + */ +#define Natts_pg_foreign_table 4 +#define Anum_pg_foreign_table_ftrelid 1 +#define Anum_pg_foreign_table_ftserver 2 +#define Anum_pg_foreign_table_ftwriteonly 3 +#define Anum_pg_foreign_table_ftoptions 4 + +#endif /* PG_FOREIGN_TABLE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_hashbucket_fn.h postgresql-hll-2.14/include/catalog/pg_hashbucket_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_hashbucket_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_hashbucket_fn.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_hashbucket_fn.h + * + * + * IDENTIFICATION + * src/include/catalog/pg_hashbucket_fn.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_HASHBUCKET_FN_H +#define PG_HASHBUCKET_FN_H + +extern Oid insertHashBucketEntry(oidvector *bucketlist, Oid bucketid); +extern Oid searchHashBucketByBucketid(oidvector *bucketlist, Oid bucketid); +extern text* searchMergeListByRelid(Oid reloid, bool *find, bool retresult = true); + +extern oidvector *searchHashBucketByOid(Oid bucketOid); +extern List *relationGetBucketRelList(Relation rel, Partition part); +extern void BucketCacheInitialize(void); +extern void AtEOXact_BucketCache(bool isCommit); +extern void AtEOSubXact_BucketCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern int64 execute_drop_bucketlist(Oid relOid1, Oid relOid2, bool isPart); +extern int64 execute_move_bucketlist(Oid relOid1, Oid relOid2, bool isPart); +extern void relation_swap_bucket(Oid r1, Oid r2); +#endif + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_hashbucket.h postgresql-hll-2.14/include/catalog/pg_hashbucket.h --- postgresql-hll-2.14_old/include/catalog/pg_hashbucket.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_hashbucket.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_hashbucket.h + * + * + * IDENTIFICATION + * src/include/catalog/pg_hashbucket.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef PG_HASHBUCKET_H +#define PG_HASHBUCKET_H +#include "catalog/genbki.h" + +#define HashBucketRelationId 9026 +#define HashBucketRelationId_Rowtype_Id 9007 + +CATALOG(pg_hashbucket,9026) BKI_SCHEMA_MACRO +{ + Oid bucketid; + int4 bucketcnt; +#ifdef CATALOG_VARLEN + oidvector_extend bucketvector; +#endif +} FormData_pg_hashbucket; + +#define Natts_pg_hashbucket 3 +#define Anum_pg_hashbucket_bucketid 1 +#define Anum_pg_hashbucket_bucketcnt 2 +#define Anum_pg_hashbucket_bucketvector 3 +#endif /* PG_HASHBUCKET_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_index.h postgresql-hll-2.14/include/catalog/pg_index.h --- postgresql-hll-2.14_old/include/catalog/pg_index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_index.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,117 @@ +/* ------------------------------------------------------------------------- + * + * pg_index.h + * definition of the system "index" relation (pg_index) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_index.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INDEX_H +#define PG_INDEX_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_index definition. cpp turns this into + * typedef struct FormData_pg_index. + * ---------------- + */ +#define IndexRelationId 2610 +#define IndexRelation_Rowtype_Id 10003 + +CATALOG(pg_index,2610) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid indexrelid; /* OID of the index */ + Oid indrelid; /* OID of the relation it indexes */ + int2 indnatts; /* total number of columns in index */ + bool indisunique; /* is this a unique index? */ + bool indisprimary; /* is this index for primary key? */ + bool indisexclusion; /* is this index for exclusion constraint? */ + bool indimmediate; /* is uniqueness enforced immediately? */ + bool indisclustered; /* is this the index last clustered by? */ + bool indisusable; /* is this index useable for insert and select?*/ + /*if yes, insert and select should ignore this index*/ + bool indisvalid; /* is this index valid for use by queries? */ + bool indcheckxmin; /* must we wait for xmin to be old? */ + bool indisready; /* is this index ready for inserts? */ + + /* variable-length fields start here, but we allow direct access to indkey */ + int2vector indkey; /* column numbers of indexed cols, or 0 */ + +#ifdef CATALOG_VARLEN + oidvector indcollation; /* collation identifiers */ + oidvector indclass; /* opclass identifiers */ + int2vector indoption; /* per-column flags (AM-specific meanings) */ + pg_node_tree indexprs; /* expression trees for index attributes that + * are not simple column references; one for + * each zero entry in indkey[] */ + pg_node_tree indpred; /* expression tree for predicate, if a partial + * index; else NULL */ + bool indisreplident; /* is this index the identity for replication? */ + int2 indnkeyatts; /* number of key columns in index */ +#endif +} FormData_pg_index; + +/* ---------------- + * Form_pg_index corresponds to a pointer to a tuple with + * the format of pg_index relation. + * ---------------- + */ +typedef FormData_pg_index *Form_pg_index; + +/* ---------------- + * compiler constants for pg_index + * ---------------- + */ +#define Natts_pg_index 20 +#define Anum_pg_index_indexrelid 1 +#define Anum_pg_index_indrelid 2 +#define Anum_pg_index_indnatts 3 +#define Anum_pg_index_indisunique 4 +#define Anum_pg_index_indisprimary 5 +#define Anum_pg_index_indisexclusion 6 +#define Anum_pg_index_indimmediate 7 +#define Anum_pg_index_indisclustered 8 +#define Anum_pg_index_indisusable 9 +#define Anum_pg_index_indisvalid 10 +#define Anum_pg_index_indcheckxmin 11 +#define Anum_pg_index_indisready 12 +#define Anum_pg_index_indkey 13 +#define Anum_pg_index_indcollation 14 +#define Anum_pg_index_indclass 15 +#define Anum_pg_index_indoption 16 +#define Anum_pg_index_indexprs 17 +#define Anum_pg_index_indpred 18 +#define Anum_pg_index_indisreplident 19 +#define Anum_pg_index_indnkeyatts 20 + +/* + * Index AMs that support ordered scans must support these two indoption + * bits. Otherwise, the content of the per-column indoption fields is + * open for future definition. + */ +#define INDOPTION_DESC 0x0001 /* values are in reverse order */ +#define INDOPTION_NULLS_FIRST 0x0002 /* NULLs are first instead of last */ + +/* + * Use of these macros is recommended over direct examination of the state + * flag columns where possible; this allows source code compatibility with + * the less ugly representation used after 9.2. + */ +#define IndexIsUsable(indexForm) ((indexForm)->indisusable) +#define IndexIsReady(indexForm) ((indexForm)->indisready) +#define IndexIsValid(indexForm) (((indexForm)->indisvalid && (indexForm)->indisready) && ((indexForm)->indisusable)) +#define IndexIsLive(indexForm) (((indexForm)->indisready || !(indexForm)->indisvalid) && ((indexForm)->indisusable)) + +#endif /* PG_INDEX_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_inherits_fn.h postgresql-hll-2.14/include/catalog/pg_inherits_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_inherits_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_inherits_fn.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * pg_inherits_fn.h + * prototypes for functions in catalog/pg_inherits.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_inherits_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INHERITS_FN_H +#define PG_INHERITS_FN_H + +#include "nodes/pg_list.h" +#include "storage/lock.h" + +extern List *find_inheritance_children(Oid parentrelId, LOCKMODE lockmode); +extern List *find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **parents); +extern bool has_subclass(Oid relationId); +extern bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId); + +#endif /* PG_INHERITS_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_inherits.h postgresql-hll-2.14/include/catalog/pg_inherits.h --- postgresql-hll-2.14_old/include/catalog/pg_inherits.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_inherits.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_inherits.h + * definition of the system "inherits" relation (pg_inherits) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_inherits.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INHERITS_H +#define PG_INHERITS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_inherits definition. cpp turns this into + * typedef struct FormData_pg_inherits + * ---------------- + */ +#define InheritsRelationId 2611 +#define InheritsRelation_Rowtype_Id 10002 + +CATALOG(pg_inherits,2611) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid inhrelid; + Oid inhparent; + int4 inhseqno; +} FormData_pg_inherits; + +/* ---------------- + * Form_pg_inherits corresponds to a pointer to a tuple with + * the format of pg_inherits relation. + * ---------------- + */ +typedef FormData_pg_inherits *Form_pg_inherits; + +/* ---------------- + * compiler constants for pg_inherits + * ---------------- + */ +#define Natts_pg_inherits 3 +#define Anum_pg_inherits_inhrelid 1 +#define Anum_pg_inherits_inhparent 2 +#define Anum_pg_inherits_inhseqno 3 + +/* ---------------- + * pg_inherits has no initial contents + * ---------------- + */ +#endif /* PG_INHERITS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_job.h postgresql-hll-2.14/include/catalog/pg_job.h --- postgresql-hll-2.14_old/include/catalog/pg_job.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_job.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,160 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_job.h + * definition of the system "job" relation (pg_job) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_job.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_JOB_H +#define PG_JOB_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define int8 int64 + +/* ------------------------------------------------------------------------- + * pg_job definition. cpp turns this into + * typedef struct FormData_pg_job + * ------------------------------------------------------------------------- + */ +#define PgJobRelationId 9022 +#define PgJobRelation_Rowtype_Id 11658 + +CATALOG(pg_job,9022) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + int8 job_id; /* Identifier of job. */ + int8 current_postgres_pid; /* if jobstatus is 'r', this is postgres's pid which is running this job */ + NameData log_user; /* Login user when the job was submitted */ + NameData priv_user; /* User whose default privileges apply to this job, reserved, unused at present */ + NameData dbname; /* A database name against which to run the script */ + NameData node_name; /* Identify the which coordinator the job create and execute */ + char job_status; /* Status of job: r=running, s=successfully finished, f=failed stopping job, + * i=ignored failure, d=aborted */ + timestamp start_date; /* Date that this job first started executing */ + timestamp next_run_date; /* Date that this job will next be executed, this is calculated by + * pg_job_schedule.RECURRENCE_EXPR */ + int2 failure_count; /* Number of times the job has started and failed since its last success, + * if more than 16, this job will be terminated */ +#ifdef CATALOG_VARLEN /* Null value constrain */ + text interval; /* A date function, evaluated at the start of execution, becomes next NEXT_DATE */ + timestamp last_start_date; /* This is when the last execution started. */ + timestamp last_end_date; /* This is when the last execution stoped. */ + timestamp last_suc_date; /* This is when the last successful execution started. */ + timestamp this_run_date; /* Date that this job started executing (usually null if not executing) */ +#endif + NameData nspname; +} FormData_pg_job; + +#undef timestamp +#undef int8 + +/* ------------------------------------------------------------------------- + * Form_pg_job corresponds to a pointer to a tuple with + * the format of pg_job relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_job* Form_pg_job; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_job + * ------------------------------------------------------------------------- + */ +#define Natts_pg_job 16 +#define Anum_pg_job_job_id 1 +#define Anum_pg_job_current_postgres_pid 2 +#define Anum_pg_job_log_user 3 +#define Anum_pg_job_priv_user 4 +#define Anum_pg_job_dbname 5 +#define Anum_pg_job_node_name 6 +#define Anum_pg_job_job_status 7 +#define Anum_pg_job_start_date 8 +#define Anum_pg_job_next_run_date 9 +#define Anum_pg_job_failure_count 10 +#define Anum_pg_job_interval 11 +#define Anum_pg_job_last_start_date 12 +#define Anum_pg_job_last_end_date 13 +#define Anum_pg_job_last_suc_date 14 +#define Anum_pg_job_this_run_date 15 +#define Anum_pg_job_nspname 16 + + + +/* Type of pg job command. */ +typedef enum +{ + Job_Submit, + Job_ISubmit, + Job_ISubmit_Node, + Job_ISubmit_Node_Internal, + Job_Remove, + Job_Update, + Job_Finish +} Pgjob_Command_Type; + +/* Status of pg job. */ +typedef enum { + Pgjob_Run, + Pgjob_Succ, + Pgjob_Fail, /* Execute what fail */ +} Update_Pgjob_Status; + +/* Oid of related for delete pg_job. */ +typedef enum { + DbOid, + UserOid +} Delete_Pgjob_Oid; + +/* Define job status. */ +#define PGJOB_RUN_STATUS 'r' +#define PGJOB_SUCC_STATUS 's' +#define PGJOB_FAIL_STATUS 'f' +#define PGJOB_ABORT_STATUS 'd' + +/* job run type */ +#define PGJOB_TYPE_ALL_CN "ALL_CN" +#define PGJOB_TYPE_ALL_DN "ALL_DN" +#define PGJOB_TYPE_ALL "ALL_NODE" +#define PGJOB_TYPE_CCN "CCN" + +extern void update_run_job_to_fail(); +extern void remove_job_by_oid(const char *objname, Delete_Pgjob_Oid oidFlag, bool local); +extern void execute_job(int4 job_id); +extern void get_job_values(int4 job_id, HeapTuple tup, Relation relation, Datum *values, bool *visnull); +extern void RemoveJobById(Oid objectId); +extern void check_job_permission(HeapTuple tuple, bool check_running = true); +#define JOBID_MAX_NUMBER ((uint16)(32767)) + +#define JOBID_ALLOC_OK 0 /* alloc jobid ok */ +#define JOBID_ALLOC_ERROR 1 /* alloc jobid error */ + +#endif /* PG_JOB_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_job_proc.h postgresql-hll-2.14/include/catalog/pg_job_proc.h --- postgresql-hll-2.14_old/include/catalog/pg_job_proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_job_proc.h 2020-12-12 17:06:43.081345896 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_job_proc.h + * definition of the system "job task" relation (pg_job_proc) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_job_proc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_JOB_PROC_H +#define PG_JOB_PROC_H + +#include "catalog/genbki.h" + +/*------------------------------------------------------------------------- + * pg_job_proc definition. cpp turns this into + * typedef struct FormData_pg_job_proc + *------------------------------------------------------------------------- + */ +#define PgJobProcRelationId 9023 +#define PgJobProcRelation_Rowtype_Id 11659 + +CATALOG(pg_job_proc,9023) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + int4 job_id; /* foreign key, reference to pg_job.job_id */ + text what; /* Body of the anonymous PL/pgSQL block that the job executes */ +} FormData_pg_job_proc; + +/*------------------------------------------------------------------------- + * Form_pg_job_proc corresponds to a pointer to a tuple with + * the format of pg_job_proc relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_job_proc* Form_pg_job_proc; + +/*------------------------------------------------------------------------- + * compiler constants for pg_job_schedule + *------------------------------------------------------------------------- + */ +#define Natts_pg_job_proc 2 +#define Anum_pg_job_proc_job_id 1 +#define Anum_pg_job_proc_what 2 + +#endif /* PG_JOB_PROC_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_language.h postgresql-hll-2.14/include/catalog/pg_language.h --- postgresql-hll-2.14_old/include/catalog/pg_language.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_language.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_language.h + * definition of the system "language" relation (pg_language) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_language.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LANGUAGE_H +#define PG_LANGUAGE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_language definition. cpp turns this into + * typedef struct FormData_pg_language + * ---------------- + */ +#define LanguageRelationId 2612 +#define LanguageRelation_Rowtype_Id 11323 + +CATALOG(pg_language,2612) BKI_SCHEMA_MACRO +{ + NameData lanname; /* Language name */ + Oid lanowner; /* Language's owner */ + bool lanispl; /* Is a procedural language */ + bool lanpltrusted; /* PL is trusted */ + Oid lanplcallfoid; /* Call handler for PL */ + Oid laninline; /* Optional anonymous-block handler function */ + Oid lanvalidator; /* Optional validation function */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem lanacl[1]; /* Access privileges */ +#endif +} FormData_pg_language; + +/* ---------------- + * Form_pg_language corresponds to a pointer to a tuple with + * the format of pg_language relation. + * ---------------- + */ +typedef FormData_pg_language *Form_pg_language; + +/* ---------------- + * compiler constants for pg_language + * ---------------- + */ +#define Natts_pg_language 8 +#define Anum_pg_language_lanname 1 +#define Anum_pg_language_lanowner 2 +#define Anum_pg_language_lanispl 3 +#define Anum_pg_language_lanpltrusted 4 +#define Anum_pg_language_lanplcallfoid 5 +#define Anum_pg_language_laninline 6 +#define Anum_pg_language_lanvalidator 7 +#define Anum_pg_language_lanacl 8 + +/* ---------------- + * initial contents of pg_language + * ---------------- + */ +DATA(insert OID = 12 ( "internal" PGUID f f 0 0 2246 _null_ )); +DESCR("built-in functions"); +#define INTERNALlanguageId 12 +DATA(insert OID = 13 ( "c" PGUID f f 0 0 2247 _null_ )); +DESCR("dynamically-loaded C functions"); +#define ClanguageId 13 +DATA(insert OID = 14 ( "sql" PGUID f t 0 0 2248 _null_ )); +DESCR("SQL-language functions"); +#define SQLlanguageId 14 +DATA(insert OID = 15 ( "java" PGUID f f 0 0 0 _null_ )); +DESCR("dynamically-loaded Java functions"); +#define JavalanguageId 15 + +#endif /* PG_LANGUAGE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_largeobject.h postgresql-hll-2.14/include/catalog/pg_largeobject.h --- postgresql-hll-2.14_old/include/catalog/pg_largeobject.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_largeobject.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * pg_largeobject.h + * definition of the system "largeobject" relation (pg_largeobject) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_largeobject.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LARGEOBJECT_H +#define PG_LARGEOBJECT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_largeobject definition. cpp turns this into + * typedef struct FormData_pg_largeobject + * ---------------- + */ +#define LargeObjectRelationId 2613 +#define LargeObjectRelation_Rowtype_Id 11325 + +CATALOG(pg_largeobject,2613) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid loid; /* Identifier of large object */ + int4 pageno; /* Page number (starting from 0) */ + + /* data has variable length, but we allow direct access; see inv_api.c */ + bytea data; /* Data for page (may be zero-length) */ +} FormData_pg_largeobject; + +/* ---------------- + * Form_pg_largeobject corresponds to a pointer to a tuple with + * the format of pg_largeobject relation. + * ---------------- + */ +typedef FormData_pg_largeobject *Form_pg_largeobject; + +/* ---------------- + * compiler constants for pg_largeobject + * ---------------- + */ +#define Natts_pg_largeobject 3 +#define Anum_pg_largeobject_loid 1 +#define Anum_pg_largeobject_pageno 2 +#define Anum_pg_largeobject_data 3 + +extern Oid LargeObjectCreate(Oid loid); +extern void LargeObjectDrop(Oid loid); +extern void LargeObjectAlterOwner(Oid loid, Oid newOwnerId); +extern bool LargeObjectExists(Oid loid); + +#endif /* PG_LARGEOBJECT_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_largeobject_metadata.h postgresql-hll-2.14/include/catalog/pg_largeobject_metadata.h --- postgresql-hll-2.14_old/include/catalog/pg_largeobject_metadata.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_largeobject_metadata.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,57 @@ +/* ------------------------------------------------------------------------- + * + * pg_largeobject_metadata.h + * definition of the system "largeobject_metadata" relation (pg_largeobject_metadata) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_largeobject_metadata.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LARGEOBJECT_METADATA_H +#define PG_LARGEOBJECT_METADATA_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_largeobject_metadata definition. cpp turns this into + * typedef struct FormData_pg_largeobject_metadata + * ---------------- + */ +#define LargeObjectMetadataRelationId 2995 +#define LargeObjectMetadataRelation_Rowtype_Id 11324 + +CATALOG(pg_largeobject_metadata,2995) BKI_SCHEMA_MACRO +{ + Oid lomowner; /* OID of the largeobject owner */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem lomacl[1]; /* access permissions */ +#endif +} FormData_pg_largeobject_metadata; + +/* ---------------- + * Form_pg_largeobject_metadata corresponds to a pointer to a tuple + * with the format of pg_largeobject_metadata relation. + * ---------------- + */ +typedef FormData_pg_largeobject_metadata *Form_pg_largeobject_metadata; + +/* ---------------- + * compiler constants for pg_largeobject_metadata + * ---------------- + */ +#define Natts_pg_largeobject_metadata 2 +#define Anum_pg_largeobject_metadata_lomowner 1 +#define Anum_pg_largeobject_metadata_lomacl 2 + +#endif /* PG_LARGEOBJECT_METADATA_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_namespace.h postgresql-hll-2.14/include/catalog/pg_namespace.h --- postgresql-hll-2.14_old/include/catalog/pg_namespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_namespace.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,107 @@ +/* ------------------------------------------------------------------------- + * + * pg_namespace.h + * definition of the system "namespace" relation (pg_namespace) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_namespace.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_NAMESPACE_H +#define PG_NAMESPACE_H + +#include "catalog/genbki.h" + +/* ---------------------------------------------------------------- + * pg_namespace definition. + * + * cpp turns this into typedef struct FormData_pg_namespace + * + * nspname name of the namespace + * nspowner owner (creator) of the namespace + * nspacl access privilege list + * ---------------------------------------------------------------- + */ +#define NamespaceRelationId 2615 +#define NamespaceRelation_Rowtype_Id 11629 + +CATALOG(pg_namespace,2615) BKI_SCHEMA_MACRO +{ + NameData nspname; + Oid nspowner; + int8 nsptimeline; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem nspacl[1]; +#endif + char in_redistribution; +} FormData_pg_namespace; + +/* ---------------- + * Form_pg_namespace corresponds to a pointer to a tuple with + * the format of pg_namespace relation. + * ---------------- + */ +typedef FormData_pg_namespace *Form_pg_namespace; + +/* ---------------- + * compiler constants for pg_namespace + * ---------------- + */ + +#define Natts_pg_namespace 5 +#define Anum_pg_namespace_nspname 1 +#define Anum_pg_namespace_nspowner 2 +#define Anum_pg_namespace_nsptimeline 3 +#define Anum_pg_namespace_nspacl 4 +#define Anum_pg_namespace_in_redistribution 5 + + +/* ---------------- + * initial contents of pg_namespace + * --------------- + */ + +DATA(insert OID = 11 ( "pg_catalog" PGUID 0 _null_ n)); +DESCR("system catalog schema"); +#define PG_CATALOG_NAMESPACE 11 +DATA(insert OID = 99 ( "pg_toast" PGUID 0 _null_ n)); +DESCR("reserved schema for TOAST tables"); +#define PG_TOAST_NAMESPACE 99 + +DATA(insert OID = 100 ( "cstore" PGUID 0 _null_ n)); +DESCR("reserved schema for DELTA tables"); +#define CSTORE_NAMESPACE 100 + +DATA(insert OID = 3988 ( "pkg_service" PGUID 0 _null_ n)); +DESCR("pkg_service schema"); +#define PG_PKG_SERVICE_NAMESPACE 3988 + +DATA(insert OID = 2200 ( "public" PGUID 0 _null_ n)); +DESCR("standard public schema"); +#define PG_PUBLIC_NAMESPACE 2200 + +DATA(insert OID = 4988 ( "dbe_perf" PGUID 0 _null_ n)); +DESCR("dbe_perf schema"); +#define PG_DBEPERF_NAMESPACE 4988 + +DATA(insert OID = 4989 ( "snapshot" PGUID 0 _null_ n)); +DESCR("snapshot schema"); +#define PG_SNAPSHOT_NAMESPACE 4989 + +/* + * prototypes for functions in pg_namespace.c + */ +extern Oid NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp); + +#endif /* PG_NAMESPACE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_object.h postgresql-hll-2.14/include/catalog/pg_object.h --- postgresql-hll-2.14_old/include/catalog/pg_object.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_object.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_object.h + * definition of the system "object" relation (pg_object). + * + * + * IDENTIFICATION + * src/include/catalog/pg_object.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_OBJECT_H +#define PG_OBJECT_H + +#include "catalog/genbki.h" +#include "fmgr.h" +#include "nodes/parsenodes.h" +#include "catalog/objectaddress.h" +#include "postgres.h" + + +#ifndef timestamptz +#ifdef HAVE_INT64_TIMESTAMP +#define timestamptz int64 +#else +#define timestamptz double +#endif +#define new_timestamptz +#endif + +/*------------------------------------------------------------------------- + * pg_object definition. cpp turns this into + * typedef struct FormData_pg_object + *------------------------------------------------------------------------- + */ +#define PgObjectRelationId 9025 +#define PgObjectRelationId_Rowtype_Id 11661 + +CATALOG(pg_object,9025) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid object_oid; /* Object oid. */ + char object_type; /* Object type. */ + Oid creator; /* Who create the object. */ + timestamptz ctime; /* When create the object. */ + timestamptz mtime; /* When modify the object. */ +} FormData_pg_object; + +#ifdef new_timestamptz +#undef new_timestamptz +#undef timestamptz +#endif + +/*------------------------------------------------------------------------- + * Form_pg_object corresponds to a pointer to a tuple with + * the format of pg_object relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_object* Form_pg_object; + +/*------------------------------------------------------------------------- + * compiler constants for pg_object + *------------------------------------------------------------------------- + */ +#define Natts_pg_object 5 +#define Anum_pg_object_oid 1 +#define Anum_pg_object_type 2 +#define Anum_pg_object_creator 3 +#define Anum_pg_object_ctime 4 +#define Anum_pg_object_mtime 5 + +#define PgObjectType char + +/* Define the type of object which maybe different with object is pg_class. */ +#define OBJECT_TYPE_INVALID '\0' +#define OBJECT_TYPE_RELATION 'r' +#define OBJECT_TYPE_FOREIGN_TABLE 'f' +#define OBJECT_TYPE_INDEX 'i' +#define OBJECT_TYPE_SEQUENCE 's' +#define OBJECT_TYPE_VIEW 'v' +#define OBJECT_TYPE_CONTQUERY 'o' +#define OBJECT_TYPE_PROC 'P' +#define OBJECT_TYPE_STREAM 'e' + +extern void CreatePgObject(Oid objectOid, PgObjectType objectType, Oid creator, bool hasCtime, bool hasMtime); +extern void DeletePgObject(Oid objectOid, PgObjectType objectType); +extern void UpdatePgObjectMtime(Oid objectOid, PgObjectType objectType); +extern PgObjectType GetPgObjectTypePgClass(char relkind); +extern void recordCommentObjectTime(ObjectAddress addr, Relation rel, ObjectType objType); +extern void recordRelationMTime(Oid relOid, char relkind); + +#endif /* PG_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_obsscaninfo.h postgresql-hll-2.14/include/catalog/pg_obsscaninfo.h --- postgresql-hll-2.14_old/include/catalog/pg_obsscaninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_obsscaninfo.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,76 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_obsscaninfo.h + * definition of the system "obsscaninfo" relation (pg_obsscaninfo) + * along with the relation's initial contents. + + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/catalog/pg_obsscaninfo.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_OBSSCANINFO_H +#define PG_OBSSCANINFO_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_obsscaninfo definition.cpp turns this into + * typedef struct FormData_pg_obsscaninfo + * ---------------- + */ +#define timestamptz Datum +#define ObsScanInfoRelationId 5679 +#define ObsScanInfoRelation_Rowtype_Id 11644 + +CATALOG(pg_obsscaninfo,5679) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + int8 query_id; +#ifdef CATALOG_VARLEN + text user_id; + text table_name; + text file_type; +#endif + timestamptz time_stamp; + float8 actual_time; + int8 file_scanned; + float8 data_size; +#ifdef CATALOG_VARLEN + text billing_info; +#endif +} FormData_pg_obsscaninfo; + + +/* ---------------- + * Form_pg_obsscaninfo corresponds to a pointer to a tuple with + * the format of pg_obsscaninfo relation. + * ---------------- + */ +typedef FormData_pg_obsscaninfo *Form_pg_obsscaninfo; + +/* ---------------- + * compiler constants for pg_obsscaninfo + * ---------------- + */ +#define Natts_pg_obsscaninfo 9 +#define Anum_pg_obsscaninfo_query_id 1 +#define Anum_pg_obsscaninfo_user_id 2 +#define Anum_pg_obsscaninfo_table_name 3 +#define Anum_pg_obsscaninfo_file_type 4 +#define Anum_pg_obsscaninfo_time_stamp 5 +#define Anum_pg_obsscaninfo_actual_time 6 +#define Anum_pg_obsscaninfo_file_scanned 7 +#define Anum_pg_obsscaninfo_data_size 8 +#define Anum_pg_obsscaninfo_billing_info 9 + +#endif /* PG_OBSSCANINFO_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_opclass.h postgresql-hll-2.14/include/catalog/pg_opclass.h --- postgresql-hll-2.14_old/include/catalog/pg_opclass.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_opclass.h 2020-12-12 17:06:43.082345909 +0800 @@ -0,0 +1,318 @@ +/* ------------------------------------------------------------------------- + * + * pg_opclass.h + * definition of the system "opclass" relation (pg_opclass) + * along with the relation's initial contents. + * + * The primary key for this table is --- + * that is, there is a row for each valid combination of opclass name and + * index access method type. This row specifies the expected input data type + * for the opclass (the type of the heap column, or the expression output type + * in the case of an index expression). Note that types binary-coercible to + * the specified type will be accepted too. + * + * For a given pair, there can be at most one row that + * has opcdefault = true; this row is the default opclass for such data in + * such an index. (This is not currently enforced by an index, because we + * don't support partial indexes on system catalogs.) + * + * Normally opckeytype = InvalidOid (zero), indicating that the data stored + * in the index is the same as the data in the indexed column. If opckeytype + * is nonzero then it indicates that a conversion step is needed to produce + * the stored index data, which will be of type opckeytype (which might be + * the same or different from the input datatype). Performing such a + * conversion is the responsibility of the index access method --- not all + * AMs support this. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_opclass.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPCLASS_H +#define PG_OPCLASS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_opclass definition. cpp turns this into + * typedef struct FormData_pg_opclass + * ---------------- + */ +#define OperatorClassRelationId 2616 +#define OperatorClassRelation_Rowtype_Id 10006 + +CATALOG(pg_opclass,2616) BKI_SCHEMA_MACRO +{ + Oid opcmethod; /* index access method opclass is for */ + NameData opcname; /* name of this opclass */ + Oid opcnamespace; /* namespace of this opclass */ + Oid opcowner; /* opclass owner */ + Oid opcfamily; /* containing operator family */ + Oid opcintype; /* type of data indexed by opclass */ + bool opcdefault; /* T if opclass is default for opcintype */ + Oid opckeytype; /* type of data in index, or InvalidOid */ +} FormData_pg_opclass; + +/* ---------------- + * Form_pg_opclass corresponds to a pointer to a tuple with + * the format of pg_opclass relation. + * ---------------- + */ +typedef FormData_pg_opclass *Form_pg_opclass; + +/* ---------------- + * compiler constants for pg_opclass + * ---------------- + */ +#define Natts_pg_opclass 8 +#define Anum_pg_opclass_opcmethod 1 +#define Anum_pg_opclass_opcname 2 +#define Anum_pg_opclass_opcnamespace 3 +#define Anum_pg_opclass_opcowner 4 +#define Anum_pg_opclass_opcfamily 5 +#define Anum_pg_opclass_opcintype 6 +#define Anum_pg_opclass_opcdefault 7 +#define Anum_pg_opclass_opckeytype 8 + +/* ---------------- + * initial contents of pg_opclass + * + * Note: we hard-wire an OID only for a few entries that have to be explicitly + * referenced in the C code or in built-in catalog entries. The rest get OIDs + * assigned on-the-fly during initdb. + * ---------------- + */ +DATA(insert ( 403 abstime_ops PGNSP PGUID 421 702 t 0 )); +DATA(insert ( 403 array_ops PGNSP PGUID 397 2277 t 0 )); +DATA(insert ( 405 array_ops PGNSP PGUID 627 2277 t 0 )); +DATA(insert ( 403 bit_ops PGNSP PGUID 423 1560 t 0 )); +DATA(insert ( 403 bool_ops PGNSP PGUID 424 16 t 0 )); +DATA(insert ( 403 bpchar_ops PGNSP PGUID 426 1042 t 0 )); +DATA(insert ( 405 bpchar_ops PGNSP PGUID 427 1042 t 0 )); +DATA(insert ( 403 bytea_ops PGNSP PGUID 428 17 t 0 )); +DATA(insert ( 403 byteawithoutorderwithequalcol_ops PGNSP PGUID 436 4402 t 0 )); +DATA(insert ( 403 char_ops PGNSP PGUID 429 18 t 0 )); +DATA(insert ( 405 char_ops PGNSP PGUID 431 18 t 0 )); +DATA(insert ( 403 cidr_ops PGNSP PGUID 1974 869 f 0 )); +DATA(insert ( 405 cidr_ops PGNSP PGUID 1975 869 f 0 )); +DATA(insert OID = 3122 ( 403 date_ops PGNSP PGUID 434 1082 t 0 )); +#define DATE_BTREE_OPS_OID 3122 +DATA(insert ( 405 date_ops PGNSP PGUID 435 1082 t 0 )); +DATA(insert ( 403 float4_ops PGNSP PGUID 1970 700 t 0 )); +DATA(insert ( 405 float4_ops PGNSP PGUID 1971 700 t 0 )); +DATA(insert OID = 3123 ( 403 float8_ops PGNSP PGUID 1970 701 t 0 )); +#define FLOAT8_BTREE_OPS_OID 3123 +DATA(insert ( 405 float8_ops PGNSP PGUID 1971 701 t 0 )); +DATA(insert ( 403 inet_ops PGNSP PGUID 1974 869 t 0 )); +DATA(insert ( 405 inet_ops PGNSP PGUID 1975 869 t 0 )); +DATA(insert OID = 1979 ( 403 int2_ops PGNSP PGUID 1976 21 t 0 )); +#define INT2_BTREE_OPS_OID 1979 +DATA(insert ( 405 int2_ops PGNSP PGUID 1977 21 t 0 )); +DATA(insert OID = 1978 ( 403 int4_ops PGNSP PGUID 1976 23 t 0 )); +#define INT4_BTREE_OPS_OID 1978 +DATA(insert ( 405 int4_ops PGNSP PGUID 1977 23 t 0 )); +DATA(insert OID = 3124 ( 403 int8_ops PGNSP PGUID 1976 20 t 0 )); +#define INT8_BTREE_OPS_OID 3124 +DATA(insert ( 405 int8_ops PGNSP PGUID 1977 20 t 0 )); +DATA(insert ( 403 interval_ops PGNSP PGUID 1982 1186 t 0 )); +DATA(insert ( 405 interval_ops PGNSP PGUID 1983 1186 t 0 )); +DATA(insert ( 403 macaddr_ops PGNSP PGUID 1984 829 t 0 )); +DATA(insert ( 405 macaddr_ops PGNSP PGUID 1985 829 t 0 )); +/* + * Here's an ugly little hack to save space in the system catalog indexes. + * btree doesn't ordinarily allow a storage type different from input type; + * but cstring and name are the same thing except for trailing padding, + * and we can safely omit that within an index entry. So we declare the + * btree opclass for name as using cstring storage type. + */ +DATA(insert ( 403 name_ops PGNSP PGUID 1986 19 t 2275 )); +DATA(insert ( 405 name_ops PGNSP PGUID 1987 19 t 0 )); +DATA(insert OID = 3125 ( 403 numeric_ops PGNSP PGUID 1988 1700 t 0 )); +#define NUMERIC_BTREE_OPS_OID 3125 +DATA(insert ( 405 numeric_ops PGNSP PGUID 1998 1700 t 0 )); +DATA(insert OID = 1981 ( 403 oid_ops PGNSP PGUID 1989 26 t 0 )); +#define OID_BTREE_OPS_OID 1981 +DATA(insert ( 405 oid_ops PGNSP PGUID 1990 26 t 0 )); +DATA(insert ( 403 oidvector_ops PGNSP PGUID 1991 30 t 0 )); +DATA(insert ( 405 oidvector_ops PGNSP PGUID 1992 30 t 0 )); +DATA(insert ( 403 record_ops PGNSP PGUID 2994 2249 t 0 )); +DATA(insert OID = 3126 ( 403 text_ops PGNSP PGUID 1994 25 t 0 )); +#define TEXT_BTREE_OPS_OID 3126 +DATA(insert ( 405 text_ops PGNSP PGUID 1995 25 t 0 )); +DATA(insert ( 403 time_ops PGNSP PGUID 1996 1083 t 0 )); +DATA(insert ( 405 time_ops PGNSP PGUID 1997 1083 t 0 )); +DATA(insert OID = 3127 ( 403 timestamptz_ops PGNSP PGUID 434 1184 t 0 )); +#define TIMESTAMPTZ_BTREE_OPS_OID 3127 +DATA(insert ( 405 timestamptz_ops PGNSP PGUID 1999 1184 t 0 )); +DATA(insert ( 403 timetz_ops PGNSP PGUID 2000 1266 t 0 )); +DATA(insert ( 405 timetz_ops PGNSP PGUID 2001 1266 t 0 )); +DATA(insert ( 403 varbit_ops PGNSP PGUID 2002 1562 t 0 )); +DATA(insert ( 403 varchar_ops PGNSP PGUID 1994 25 f 0 )); +DATA(insert ( 405 varchar_ops PGNSP PGUID 1995 25 f 0 )); +DATA(insert OID = 3128 ( 403 timestamp_ops PGNSP PGUID 434 1114 t 0 )); +#define TIMESTAMP_BTREE_OPS_OID 3128 +DATA(insert ( 405 timestamp_ops PGNSP PGUID 2040 1114 t 0 )); +DATA(insert ( 403 text_pattern_ops PGNSP PGUID 2095 25 f 0 )); +DATA(insert ( 403 varchar_pattern_ops PGNSP PGUID 2095 25 f 0 )); +DATA(insert ( 403 bpchar_pattern_ops PGNSP PGUID 2097 1042 f 0 )); +DATA(insert ( 403 money_ops PGNSP PGUID 2099 790 t 0 )); +DATA(insert ( 405 bool_ops PGNSP PGUID 2222 16 t 0 )); +DATA(insert ( 405 bytea_ops PGNSP PGUID 2223 17 t 0 )); +DATA(insert ( 405 byteawithoutorderwithequalcol_ops PGNSP PGUID 4470 4402 t 0 )); +DATA(insert ( 405 int2vector_ops PGNSP PGUID 2224 22 t 0 )); +DATA(insert ( 403 tid_ops PGNSP PGUID 2789 27 t 0 )); +DATA(insert ( 405 xid_ops PGNSP PGUID 2225 28 t 0 )); +DATA(insert ( 405 xid32_ops PGNSP PGUID 2232 31 t 0 )); +DATA(insert ( 405 cid_ops PGNSP PGUID 2226 29 t 0 )); +DATA(insert ( 405 abstime_ops PGNSP PGUID 2227 702 t 0 )); +DATA(insert ( 405 reltime_ops PGNSP PGUID 2228 703 t 0 )); +DATA(insert ( 405 text_pattern_ops PGNSP PGUID 2229 25 f 0 )); +DATA(insert ( 405 varchar_pattern_ops PGNSP PGUID 2229 25 f 0 )); +DATA(insert ( 405 bpchar_pattern_ops PGNSP PGUID 2231 1042 f 0 )); +DATA(insert ( 403 reltime_ops PGNSP PGUID 2233 703 t 0 )); +DATA(insert ( 403 tinterval_ops PGNSP PGUID 2234 704 t 0 )); +DATA(insert ( 405 aclitem_ops PGNSP PGUID 2235 1033 t 0 )); +DATA(insert ( 783 box_ops PGNSP PGUID 2593 603 t 0 )); +DATA(insert ( 783 point_ops PGNSP PGUID 1029 600 t 603 )); +DATA(insert ( 783 poly_ops PGNSP PGUID 2594 604 t 603 )); +DATA(insert ( 783 circle_ops PGNSP PGUID 2595 718 t 603 )); +DATA(insert ( 2742 _int4_ops PGNSP PGUID 2745 1007 t 23 )); +DATA(insert ( 2742 _text_ops PGNSP PGUID 2745 1009 t 25 )); +DATA(insert ( 2742 _abstime_ops PGNSP PGUID 2745 1023 t 702 )); +DATA(insert ( 2742 _bit_ops PGNSP PGUID 2745 1561 t 1560 )); +DATA(insert ( 2742 _bool_ops PGNSP PGUID 2745 1000 t 16 )); +DATA(insert ( 2742 _bpchar_ops PGNSP PGUID 2745 1014 t 1042 )); +DATA(insert ( 2742 _bytea_ops PGNSP PGUID 2745 1001 t 17 )); +DATA(insert ( 2742 _char_ops PGNSP PGUID 2745 1002 t 18 )); +DATA(insert ( 2742 _cidr_ops PGNSP PGUID 2745 651 t 650 )); +DATA(insert ( 2742 _date_ops PGNSP PGUID 2745 1182 t 1082 )); +DATA(insert ( 2742 _float4_ops PGNSP PGUID 2745 1021 t 700 )); +DATA(insert ( 2742 _float8_ops PGNSP PGUID 2745 1022 t 701 )); +DATA(insert ( 2742 _inet_ops PGNSP PGUID 2745 1041 t 869 )); +DATA(insert ( 2742 _int2_ops PGNSP PGUID 2745 1005 t 21 )); +DATA(insert ( 2742 _int8_ops PGNSP PGUID 2745 1016 t 20 )); +DATA(insert ( 2742 _interval_ops PGNSP PGUID 2745 1187 t 1186 )); +DATA(insert ( 2742 _macaddr_ops PGNSP PGUID 2745 1040 t 829 )); +DATA(insert ( 2742 _name_ops PGNSP PGUID 2745 1003 t 19 )); +DATA(insert ( 2742 _numeric_ops PGNSP PGUID 2745 1231 t 1700 )); +DATA(insert ( 2742 _oid_ops PGNSP PGUID 2745 1028 t 26 )); +DATA(insert ( 2742 _oidvector_ops PGNSP PGUID 2745 1013 t 30 )); +DATA(insert ( 2742 _time_ops PGNSP PGUID 2745 1183 t 1083 )); +DATA(insert ( 2742 _timestamptz_ops PGNSP PGUID 2745 1185 t 1184 )); +DATA(insert ( 2742 _timetz_ops PGNSP PGUID 2745 1270 t 1266 )); +DATA(insert ( 2742 _varbit_ops PGNSP PGUID 2745 1563 t 1562 )); +DATA(insert ( 2742 _varchar_ops PGNSP PGUID 2745 1015 t 1043 )); +DATA(insert ( 2742 _timestamp_ops PGNSP PGUID 2745 1115 t 1114 )); +DATA(insert ( 2742 _money_ops PGNSP PGUID 2745 791 t 790 )); +DATA(insert ( 2742 _reltime_ops PGNSP PGUID 2745 1024 t 703 )); +DATA(insert ( 2742 _tinterval_ops PGNSP PGUID 2745 1025 t 704 )); +/* +DATA(insert ( 4444 _int4_ops PGNSP PGUID 4445 1007 t 23 )); +DATA(insert ( 4444 _text_ops PGNSP PGUID 4445 1009 t 25 )); +DATA(insert ( 4444 _abstime_ops PGNSP PGUID 4445 1023 t 702 )); +DATA(insert ( 4444 _bit_ops PGNSP PGUID 4445 1561 t 1560 )); +DATA(insert ( 4444 _bool_ops PGNSP PGUID 4445 1000 t 16 )); +DATA(insert ( 4444 _bpchar_ops PGNSP PGUID 4445 1014 t 1042 )); +DATA(insert ( 4444 _bytea_ops PGNSP PGUID 4445 1001 t 17 )); +DATA(insert ( 4444 _char_ops PGNSP PGUID 4445 1002 t 18 )); +DATA(insert ( 4444 _cidr_ops PGNSP PGUID 4445 651 t 650 )); +DATA(insert ( 4444 _date_ops PGNSP PGUID 4445 1182 t 1082 )); +DATA(insert ( 4444 _float4_ops PGNSP PGUID 4445 1021 t 700 )); +DATA(insert ( 4444 _float8_ops PGNSP PGUID 4445 1022 t 701 )); +DATA(insert ( 4444 _inet_ops PGNSP PGUID 4445 1041 t 869 )); +DATA(insert ( 4444 _int2_ops PGNSP PGUID 4445 1005 t 21 )); +DATA(insert ( 4444 _int8_ops PGNSP PGUID 4445 1016 t 20 )); +DATA(insert ( 4444 _interval_ops PGNSP PGUID 4445 1187 t 1186 )); +DATA(insert ( 4444 _macaddr_ops PGNSP PGUID 4445 1040 t 829 )); +DATA(insert ( 4444 _name_ops PGNSP PGUID 4445 1003 t 19 )); +DATA(insert ( 4444 _numeric_ops PGNSP PGUID 4445 1231 t 1700 )); +DATA(insert ( 4444 _oid_ops PGNSP PGUID 4445 1028 t 26 )); +DATA(insert ( 4444 _oidvector_ops PGNSP PGUID 4445 1013 t 30 )); +DATA(insert ( 4444 _time_ops PGNSP PGUID 4445 1183 t 1083 )); +DATA(insert ( 4444 _timestamptz_ops PGNSP PGUID 4445 1185 t 1184 )); +DATA(insert ( 4444 _timetz_ops PGNSP PGUID 4445 1270 t 1266 )); +DATA(insert ( 4444 _varbit_ops PGNSP PGUID 4445 1563 t 1562 )); +DATA(insert ( 4444 _varchar_ops PGNSP PGUID 4445 1015 t 1043 )); +DATA(insert ( 4444 _timestamp_ops PGNSP PGUID 4445 1115 t 1114 )); +DATA(insert ( 4444 _money_ops PGNSP PGUID 4445 791 t 790 )); +DATA(insert ( 4444 _reltime_ops PGNSP PGUID 4445 1024 t 703 )); +DATA(insert ( 4444 _tinterval_ops PGNSP PGUID 4445 1025 t 704 )); +*/ +DATA(insert ( 403 uuid_ops PGNSP PGUID 2968 2950 t 0 )); +DATA(insert ( 405 uuid_ops PGNSP PGUID 2969 2950 t 0 )); +DATA(insert ( 403 enum_ops PGNSP PGUID 3522 3500 t 0 )); +DATA(insert ( 405 enum_ops PGNSP PGUID 3523 3500 t 0 )); +DATA(insert ( 403 tsvector_ops PGNSP PGUID 3626 3614 t 0 )); +DATA(insert ( 783 tsvector_ops PGNSP PGUID 3655 3614 t 3642 )); +DATA(insert ( 2742 tsvector_ops PGNSP PGUID 3659 3614 t 25 )); +DATA(insert ( 4444 tsvector_ops PGNSP PGUID 4446 3614 t 25 )); +DATA(insert ( 403 tsquery_ops PGNSP PGUID 3683 3615 t 0 )); +DATA(insert ( 783 tsquery_ops PGNSP PGUID 3702 3615 t 20 )); +DATA(insert ( 403 range_ops PGNSP PGUID 3901 3831 t 0 )); +DATA(insert ( 405 range_ops PGNSP PGUID 3903 3831 t 0 )); +DATA(insert ( 783 range_ops PGNSP PGUID 3919 3831 t 0 )); +DATA(insert ( 4000 quad_point_ops PGNSP PGUID 4015 600 t 0 )); +DATA(insert ( 4000 kd_point_ops PGNSP PGUID 4016 600 f 0 )); +DATA(insert ( 4000 text_ops PGNSP PGUID 4017 25 t 0 )); + +DATA(insert ( 403 raw_ops PGNSP PGUID 3806 86 t 0 )); +DATA(insert ( 405 raw_ops PGNSP PGUID 3807 86 t 0 )); +DATA(insert ( 403 int1_ops PGNSP PGUID 5535 5545 t 0 )); +DATA(insert ( 405 int1_ops PGNSP PGUID 5536 5545 t 0 )); +DATA(insert ( 403 smalldatetime_ops PGNSP PGUID 5570 9003 t 0 )); +DATA(insert ( 405 smalldatetime_ops PGNSP PGUID 5571 9003 t 0 )); + +/* psort index, fake data just make index work */ +DATA(insert ( 4039 int4_ops PGNSP PGUID 4050 23 t 0)); +DATA(insert ( 4039 int2_ops PGNSP PGUID 4050 21 t 0)); +DATA(insert ( 4039 int8_ops PGNSP PGUID 4050 20 t 0)); +DATA(insert ( 4039 oid_ops PGNSP PGUID 4051 26 t 0)); +DATA(insert ( 4039 date_ops PGNSP PGUID 4052 1082 t 0)); +DATA(insert ( 4039 timestamp_ops PGNSP PGUID 4052 1114 t 0)); +DATA(insert ( 4039 timestamptz_ops PGNSP PGUID 4052 1184 t 0)); +DATA(insert ( 4039 float4_ops PGNSP PGUID 4053 700 t 0)); +DATA(insert ( 4039 float8_ops PGNSP PGUID 4053 701 t 0)); +DATA(insert ( 4039 numeric_ops PGNSP PGUID 4054 1700 t 0)); +DATA(insert ( 4039 text_ops PGNSP PGUID 4055 25 t 0)); +DATA(insert ( 4039 bpchar_ops PGNSP PGUID 4056 1042 t 0)); +DATA(insert ( 4039 time_ops PGNSP PGUID 4057 1083 t 0)); +DATA(insert ( 4039 timetz_ops PGNSP PGUID 4058 1266 t 0)); +DATA(insert ( 4039 money_ops PGNSP PGUID 4059 790 t 0)); +DATA(insert ( 4039 interval_ops PGNSP PGUID 4060 1186 t 0)); +DATA(insert ( 4039 tinterval_ops PGNSP PGUID 4061 704 t 0)); +DATA(insert ( 4039 int1_ops PGNSP PGUID 4062 5545 t 0)); +DATA(insert ( 4039 bool_ops PGNSP PGUID 4063 16 t 0)); +DATA(insert ( 4039 smalldatetime_ops PGNSP PGUID 4064 9003 t 0)); + +/* cbtree index, fake data just make index work */ +DATA(insert ( 4239 int4_ops PGNSP PGUID 4250 23 t 0)); +DATA(insert ( 4239 int2_ops PGNSP PGUID 4250 21 t 0)); +DATA(insert ( 4239 int8_ops PGNSP PGUID 4250 20 t 0)); +DATA(insert ( 4239 oid_ops PGNSP PGUID 4251 26 t 0)); +DATA(insert ( 4239 date_ops PGNSP PGUID 4252 1082 t 0)); +DATA(insert ( 4239 timestamp_ops PGNSP PGUID 4252 1114 t 0)); +DATA(insert ( 4239 timestamptz_ops PGNSP PGUID 4252 1184 t 0)); +DATA(insert ( 4239 float4_ops PGNSP PGUID 4253 700 t 0)); +DATA(insert ( 4239 float8_ops PGNSP PGUID 4253 701 t 0)); +DATA(insert ( 4239 numeric_ops PGNSP PGUID 4254 1700 t 0)); +DATA(insert ( 4239 text_ops PGNSP PGUID 4255 25 t 0)); +DATA(insert ( 4239 bpchar_ops PGNSP PGUID 4256 1042 t 0)); +DATA(insert ( 4239 time_ops PGNSP PGUID 4257 1083 t 0)); +DATA(insert ( 4239 timetz_ops PGNSP PGUID 4258 1266 t 0)); +DATA(insert ( 4239 money_ops PGNSP PGUID 4259 790 t 0)); +DATA(insert ( 4239 interval_ops PGNSP PGUID 4260 1186 t 0)); +DATA(insert ( 4239 tinterval_ops PGNSP PGUID 4261 704 t 0)); +DATA(insert ( 4239 int1_ops PGNSP PGUID 4262 5545 t 0)); +DATA(insert ( 4239 bool_ops PGNSP PGUID 4263 16 t 0)); +DATA(insert ( 4239 smalldatetime_ops PGNSP PGUID 4264 9003 t 0)); + +#endif /* PG_OPCLASS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_operator.h postgresql-hll-2.14/include/catalog/pg_operator.h --- postgresql-hll-2.14_old/include/catalog/pg_operator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_operator.h 2020-12-12 17:06:43.083345922 +0800 @@ -0,0 +1,1962 @@ +/* ------------------------------------------------------------------------- + * + * pg_operator.h + * definition of the system "operator" relation (pg_operator) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_operator.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPERATOR_H +#define PG_OPERATOR_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_operator definition. cpp turns this into + * typedef struct FormData_pg_operator + * ---------------- + */ +#define OperatorRelationId 2617 +#define OperatorRelation_Rowtype_Id 10004 + +CATALOG(pg_operator,2617) BKI_SCHEMA_MACRO +{ + NameData oprname; /* name of operator */ + Oid oprnamespace; /* OID of namespace containing this oper */ + Oid oprowner; /* operator owner */ + char oprkind; /* 'l', 'r', or 'b' */ + bool oprcanmerge; /* can be used in merge join? */ + bool oprcanhash; /* can be used in hash join? */ + Oid oprleft; /* left arg type, or 0 if 'l' oprkind */ + Oid oprright; /* right arg type, or 0 if 'r' oprkind */ + Oid oprresult; /* result datatype */ + Oid oprcom; /* OID of commutator oper, or 0 if none */ + Oid oprnegate; /* OID of negator oper, or 0 if none */ + regproc oprcode; /* OID of underlying function */ + regproc oprrest; /* OID of restriction estimator, or 0 */ + regproc oprjoin; /* OID of join estimator, or 0 */ +} FormData_pg_operator; + +/* ---------------- + * Form_pg_operator corresponds to a pointer to a tuple with + * the format of pg_operator relation. + * ---------------- + */ +typedef FormData_pg_operator *Form_pg_operator; + +/* ---------------- + * compiler constants for pg_operator + * ---------------- + */ +#define Natts_pg_operator 14 +#define Anum_pg_operator_oprname 1 +#define Anum_pg_operator_oprnamespace 2 +#define Anum_pg_operator_oprowner 3 +#define Anum_pg_operator_oprkind 4 +#define Anum_pg_operator_oprcanmerge 5 +#define Anum_pg_operator_oprcanhash 6 +#define Anum_pg_operator_oprleft 7 +#define Anum_pg_operator_oprright 8 +#define Anum_pg_operator_oprresult 9 +#define Anum_pg_operator_oprcom 10 +#define Anum_pg_operator_oprnegate 11 +#define Anum_pg_operator_oprcode 12 +#define Anum_pg_operator_oprrest 13 +#define Anum_pg_operator_oprjoin 14 + +/* ---------------- + * initial contents of pg_operator + * ---------------- + */ + +/* + * Note: every entry in pg_operator.h is expected to have a DESCR() comment. + * If the operator is a deprecated equivalent of some other entry, be sure + * to comment it as such so that initdb doesn't think it's a preferred name + * for the underlying function. + */ + +DATA(insert OID = 15 ("=" PGNSP PGUID b t t 23 20 16 416 36 int48eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT48EQOID 15 +DATA(insert OID = 36 ("<>" PGNSP PGUID b f f 23 20 16 417 15 int48ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT48NEOID 36 +DATA(insert OID = 37 ("<" PGNSP PGUID b f f 23 20 16 419 82 int48lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT48LTOID 37 +DATA(insert OID = 76 (">" PGNSP PGUID b f f 23 20 16 418 80 int48gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT48GTOID 76 +DATA(insert OID = 80 ("<=" PGNSP PGUID b f f 23 20 16 430 76 int48le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT48LEOID 80 +DATA(insert OID = 82 (">=" PGNSP PGUID b f f 23 20 16 420 37 int48ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT48GEOID 82 + +DATA(insert OID = 58 ("<" PGNSP PGUID b f f 16 16 16 59 1695 boollt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 59 (">" PGNSP PGUID b f f 16 16 16 58 1694 boolgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 85 ("<>" PGNSP PGUID b f f 16 16 16 85 91 boolne neqsel neqjoinsel)); +DESCR("not equal"); +#define BooleanNotEqualOperator 85 +DATA(insert OID = 91 ("=" PGNSP PGUID b t t 16 16 16 91 85 booleq eqsel eqjoinsel)); +DESCR("equal"); +#define BooleanEqualOperator 91 +DATA(insert OID = 1694 ("<=" PGNSP PGUID b f f 16 16 16 1695 59 boolle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1695 (">=" PGNSP PGUID b f f 16 16 16 1694 58 boolge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define CHAREQOID 92 +DATA(insert OID = 92 ("=" PGNSP PGUID b t t 18 18 16 92 630 chareq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 93 ("=" PGNSP PGUID b t t 19 19 16 93 643 nameeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 94 ("=" PGNSP PGUID b t t 21 21 16 94 519 int2eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT2EQOID 94 +DATA(insert OID = 95 ("<" PGNSP PGUID b f f 21 21 16 520 524 int2lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT2LTOID 95 +DATA(insert OID = 96 ("=" PGNSP PGUID b t t 23 23 16 96 518 int4eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT4EQOID 96 +DATA(insert OID = 97 ("<" PGNSP PGUID b f f 23 23 16 521 525 int4lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT4LTOID 97 +DATA(insert OID = 98 ("=" PGNSP PGUID b t t 25 25 16 98 531 texteq eqsel eqjoinsel)); +DESCR("equal"); +#define TEXTEQOID 98 + +DATA(insert OID = 349 ("||" PGNSP PGUID b f f 2277 2283 2277 0 0 array_append - - )); +DESCR("append element onto end of array"); +DATA(insert OID = 374 ("||" PGNSP PGUID b f f 2283 2277 2277 0 0 array_prepend - - )); +DESCR("prepend element onto front of array"); +DATA(insert OID = 375 ("||" PGNSP PGUID b f f 2277 2277 2277 0 0 array_cat - - )); +DESCR("concatenate"); + +DATA(insert OID = 352 ("=" PGNSP PGUID b f t 28 28 16 352 0 xideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 353 ("=" PGNSP PGUID b f f 28 20 16 0 0 xideqint8 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 354 ("<" PGNSP PGUID b f f 28 28 16 0 0 xidlt neqsel neqjoinsel)); +DESCR("less than"); +DATA(insert OID = 355 ("=" PGNSP PGUID b f t 31 31 16 355 0 xideq4 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 356 ("=" PGNSP PGUID b f f 31 23 16 0 0 xideqint4 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 357 ("<" PGNSP PGUID b f f 31 31 16 0 0 xidlt4 neqsel neqjoinsel)); +DESCR("less than"); +DATA(insert OID = 388 ("!" PGNSP PGUID r f f 20 0 1700 0 0 numeric_fac - -)); +DESCR("factorial"); +DATA(insert OID = 389 ("!!" PGNSP PGUID l f f 0 20 1700 0 0 numeric_fac - -)); +DESCR("deprecated, use ! instead"); +DATA(insert OID = 385 ("=" PGNSP PGUID b f t 29 29 16 385 0 cideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 386 ("=" PGNSP PGUID b f t 22 22 16 386 0 int2vectoreq eqsel eqjoinsel)); +DESCR("equal"); + +DATA(insert OID = 387 ("=" PGNSP PGUID b t f 27 27 16 387 402 tideq eqsel eqjoinsel)); +DESCR("equal"); +#define TIDEqualOperator 387 +DATA(insert OID = 402 ("<>" PGNSP PGUID b f f 27 27 16 402 387 tidne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2799 ("<" PGNSP PGUID b f f 27 27 16 2800 2802 tidlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIDLessOperator 2799 +DATA(insert OID = 2800 (">" PGNSP PGUID b f f 27 27 16 2799 2801 tidgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2801 ("<=" PGNSP PGUID b f f 27 27 16 2802 2800 tidle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2802 (">=" PGNSP PGUID b f f 27 27 16 2801 2799 tidge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 410 ("=" PGNSP PGUID b t t 20 20 16 410 411 int8eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT8EQOID 410 +DATA(insert OID = 411 ("<>" PGNSP PGUID b f f 20 20 16 411 410 int8ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT8NEOID 411 +DATA(insert OID = 412 ("<" PGNSP PGUID b f f 20 20 16 413 415 int8lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT8LTOID 412 +DATA(insert OID = 413 (">" PGNSP PGUID b f f 20 20 16 412 414 int8gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT8GTOID 413 +DATA(insert OID = 414 ("<=" PGNSP PGUID b f f 20 20 16 415 413 int8le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT8LEOID 414 +DATA(insert OID = 415 (">=" PGNSP PGUID b f f 20 20 16 414 412 int8ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT8GEOID 415 + +DATA(insert OID = 416 ("=" PGNSP PGUID b t t 20 23 16 15 417 int84eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT84EQOID 416 +DATA(insert OID = 417 ("<>" PGNSP PGUID b f f 20 23 16 36 416 int84ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT84NEOID 417 +DATA(insert OID = 418 ("<" PGNSP PGUID b f f 20 23 16 76 430 int84lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT84LTOID 418 +DATA(insert OID = 419 (">" PGNSP PGUID b f f 20 23 16 37 420 int84gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT84GTOID 419 +DATA(insert OID = 420 ("<=" PGNSP PGUID b f f 20 23 16 82 419 int84le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT84LEOID 420 +DATA(insert OID = 430 (">=" PGNSP PGUID b f f 20 23 16 80 418 int84ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT84GEOID 430 +DATA(insert OID = 439 ("%" PGNSP PGUID b f f 20 20 20 0 0 int8mod - -)); +DESCR("modulus"); +DATA(insert OID = 473 ("@" PGNSP PGUID l f f 0 20 20 0 0 int8abs - -)); +DESCR("absolute value"); + +DATA(insert OID = 484 ("-" PGNSP PGUID l f f 0 20 20 0 0 int8um - -)); +DESCR("negate"); +DATA(insert OID = 485 ("<<" PGNSP PGUID b f f 604 604 16 0 0 poly_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 486 ("&<" PGNSP PGUID b f f 604 604 16 0 0 poly_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 487 ("&>" PGNSP PGUID b f f 604 604 16 0 0 poly_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 488 (">>" PGNSP PGUID b f f 604 604 16 0 0 poly_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 489 ("<@" PGNSP PGUID b f f 604 604 16 490 0 poly_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 490 ("@>" PGNSP PGUID b f f 604 604 16 489 0 poly_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 491 ("~=" PGNSP PGUID b f f 604 604 16 491 0 poly_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 492 ("&&" PGNSP PGUID b f f 604 604 16 492 0 poly_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 493 ("<<" PGNSP PGUID b f f 603 603 16 0 0 box_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 494 ("&<" PGNSP PGUID b f f 603 603 16 0 0 box_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 495 ("&>" PGNSP PGUID b f f 603 603 16 0 0 box_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 496 (">>" PGNSP PGUID b f f 603 603 16 0 0 box_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 497 ("<@" PGNSP PGUID b f f 603 603 16 498 0 box_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 498 ("@>" PGNSP PGUID b f f 603 603 16 497 0 box_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 499 ("~=" PGNSP PGUID b f f 603 603 16 499 0 box_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 500 ("&&" PGNSP PGUID b f f 603 603 16 500 0 box_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 501 (">=" PGNSP PGUID b f f 603 603 16 505 504 box_ge areasel areajoinsel)); +DESCR("greater than or equal by area"); +DATA(insert OID = 502 (">" PGNSP PGUID b f f 603 603 16 504 505 box_gt areasel areajoinsel)); +DESCR("greater than by area"); +DATA(insert OID = 503 ("=" PGNSP PGUID b f f 603 603 16 503 0 box_eq eqsel eqjoinsel)); +DESCR("equal by area"); +DATA(insert OID = 504 ("<" PGNSP PGUID b f f 603 603 16 502 501 box_lt areasel areajoinsel)); +DESCR("less than by area"); +DATA(insert OID = 505 ("<=" PGNSP PGUID b f f 603 603 16 501 502 box_le areasel areajoinsel)); +DESCR("less than or equal by area"); +DATA(insert OID = 506 (">^" PGNSP PGUID b f f 600 600 16 0 0 point_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 507 ("<<" PGNSP PGUID b f f 600 600 16 0 0 point_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 508 (">>" PGNSP PGUID b f f 600 600 16 0 0 point_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 509 ("<^" PGNSP PGUID b f f 600 600 16 0 0 point_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 510 ("~=" PGNSP PGUID b f f 600 600 16 510 713 point_eq eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 511 ("<@" PGNSP PGUID b f f 600 603 16 433 0 on_pb contsel contjoinsel)); +DESCR("point inside box"); +DATA(insert OID = 433 ("@>" PGNSP PGUID b f f 603 600 16 511 0 box_contain_pt contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 512 ("<@" PGNSP PGUID b f f 600 602 16 755 0 on_ppath - -)); +DESCR("point within closed path, or point on open path"); +DATA(insert OID = 513 ("@@" PGNSP PGUID l f f 0 603 600 0 0 box_center - -)); +DESCR("center of"); +DATA(insert OID = 514 ("*" PGNSP PGUID b f f 23 23 23 514 0 int4mul - -)); +DESCR("multiply"); +#define INT4MULOID 514 +DATA(insert OID = 517 ("<->" PGNSP PGUID b f f 600 600 701 517 0 point_distance - -)); +DESCR("distance between"); +DATA(insert OID = 518 ("<>" PGNSP PGUID b f f 23 23 16 518 96 int4ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT4NEOID 518 +DATA(insert OID = 519 ("<>" PGNSP PGUID b f f 21 21 16 519 94 int2ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT2NEOID 519 +DATA(insert OID = 520 (">" PGNSP PGUID b f f 21 21 16 95 522 int2gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT2GTOID 520 +DATA(insert OID = 521 (">" PGNSP PGUID b f f 23 23 16 97 523 int4gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT4GTOID 521 +DATA(insert OID = 522 ("<=" PGNSP PGUID b f f 21 21 16 524 520 int2le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT2LEOID 522 +DATA(insert OID = 523 ("<=" PGNSP PGUID b f f 23 23 16 525 521 int4le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT4LEOID 523 +DATA(insert OID = 524 (">=" PGNSP PGUID b f f 21 21 16 522 95 int2ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT2GEOID 524 +DATA(insert OID = 525 (">=" PGNSP PGUID b f f 23 23 16 523 97 int4ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT4GEOID 525 +DATA(insert OID = 526 ("*" PGNSP PGUID b f f 21 21 21 526 0 int2mul - -)); +DESCR("multiply"); +#define INT2MULOID 526 +DATA(insert OID = 527 ("/" PGNSP PGUID b f f 21 21 701 0 0 int2div - -)); +DESCR("divide"); +#define INT2DIVOID 527 +DATA(insert OID = 528 ("/" PGNSP PGUID b f f 23 23 701 0 0 int4div - -)); +DESCR("divide"); +#define INT4DIVOID 528 +DATA(insert OID = 529 ("%" PGNSP PGUID b f f 21 21 21 0 0 int2mod - -)); +DESCR("modulus"); +DATA(insert OID = 530 ("%" PGNSP PGUID b f f 23 23 23 0 0 int4mod - -)); +DESCR("modulus"); +DATA(insert OID = 531 ("<>" PGNSP PGUID b f f 25 25 16 531 98 textne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 532 ("=" PGNSP PGUID b t t 21 23 16 533 538 int24eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT24EQOID 532 +DATA(insert OID = 533 ("=" PGNSP PGUID b t t 23 21 16 532 539 int42eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT42EQOID 533 +DATA(insert OID = 534 ("<" PGNSP PGUID b f f 21 23 16 537 542 int24lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT24LTOID 534 +DATA(insert OID = 535 ("<" PGNSP PGUID b f f 23 21 16 536 543 int42lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT42LTOID 535 +DATA(insert OID = 536 (">" PGNSP PGUID b f f 21 23 16 535 540 int24gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT24GTOID 536 +DATA(insert OID = 537 (">" PGNSP PGUID b f f 23 21 16 534 541 int42gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT42GTOID 537 +DATA(insert OID = 538 ("<>" PGNSP PGUID b f f 21 23 16 539 532 int24ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT24NEOID 538 +DATA(insert OID = 539 ("<>" PGNSP PGUID b f f 23 21 16 538 533 int42ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT42NEOID 539 +DATA(insert OID = 540 ("<=" PGNSP PGUID b f f 21 23 16 543 536 int24le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT24LEOID 540 +DATA(insert OID = 541 ("<=" PGNSP PGUID b f f 23 21 16 542 537 int42le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT42LEOID 541 +DATA(insert OID = 542 (">=" PGNSP PGUID b f f 21 23 16 541 534 int24ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT24GEOID 542 +DATA(insert OID = 543 (">=" PGNSP PGUID b f f 23 21 16 540 535 int42ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT42GEOID 543 +DATA(insert OID = 544 ("*" PGNSP PGUID b f f 21 23 23 545 0 int24mul - -)); +DESCR("multiply"); +#define INT24MULOID 544 +DATA(insert OID = 545 ("*" PGNSP PGUID b f f 23 21 23 544 0 int42mul - -)); +DESCR("multiply"); +#define INT42MULOID 545 +DATA(insert OID = 546 ("/" PGNSP PGUID b f f 21 23 701 0 0 int24div - -)); +DESCR("divide"); +#define INT24DIVOID 546 +DATA(insert OID = 547 ("/" PGNSP PGUID b f f 23 21 701 0 0 int42div - -)); +DESCR("divide"); +#define INT42DIVOID 547 +DATA(insert OID = 550 ("+" PGNSP PGUID b f f 21 21 21 550 0 int2pl - -)); +DESCR("add"); +#define INT2PLOID 550 +DATA(insert OID = 551 ("+" PGNSP PGUID b f f 23 23 23 551 0 int4pl - -)); +DESCR("add"); +#define INT4PLOID 551 +DATA(insert OID = 552 ("+" PGNSP PGUID b f f 21 23 23 553 0 int24pl - -)); +DESCR("add"); +#define INT24PLOID 552 +DATA(insert OID = 553 ("+" PGNSP PGUID b f f 23 21 23 552 0 int42pl - -)); +DESCR("add"); +#define INT42PLOID 553 +DATA(insert OID = 554 ("-" PGNSP PGUID b f f 21 21 21 0 0 int2mi - -)); +DESCR("subtract"); +#define INT2MIOID 554 +DATA(insert OID = 555 ("-" PGNSP PGUID b f f 23 23 23 0 0 int4mi - -)); +DESCR("subtract"); +#define INT4MIOID 555 +DATA(insert OID = 556 ("-" PGNSP PGUID b f f 21 23 23 0 0 int24mi - -)); +DESCR("subtract"); +#define INT24MIOID 556 +DATA(insert OID = 557 ("-" PGNSP PGUID b f f 23 21 23 0 0 int42mi - -)); +DESCR("subtract"); +#define INT42MIOID 557 +DATA(insert OID = 558 ("-" PGNSP PGUID l f f 0 23 23 0 0 int4um - -)); +DESCR("negate"); +DATA(insert OID = 559 ("-" PGNSP PGUID l f f 0 21 21 0 0 int2um - -)); +DESCR("negate"); +DATA(insert OID = 560 ("=" PGNSP PGUID b t t 702 702 16 560 561 abstimeeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 561 ("<>" PGNSP PGUID b f f 702 702 16 561 560 abstimene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 562 ("<" PGNSP PGUID b f f 702 702 16 563 565 abstimelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 563 (">" PGNSP PGUID b f f 702 702 16 562 564 abstimegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 564 ("<=" PGNSP PGUID b f f 702 702 16 565 563 abstimele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 565 (">=" PGNSP PGUID b f f 702 702 16 564 562 abstimege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 566 ("=" PGNSP PGUID b t t 703 703 16 566 567 reltimeeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 567 ("<>" PGNSP PGUID b f f 703 703 16 567 566 reltimene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 568 ("<" PGNSP PGUID b f f 703 703 16 569 571 reltimelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 569 (">" PGNSP PGUID b f f 703 703 16 568 570 reltimegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 570 ("<=" PGNSP PGUID b f f 703 703 16 571 569 reltimele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 571 (">=" PGNSP PGUID b f f 703 703 16 570 568 reltimege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 572 ("~=" PGNSP PGUID b f f 704 704 16 572 0 tintervalsame eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 573 ("<<" PGNSP PGUID b f f 704 704 16 0 0 tintervalct - -)); +DESCR("contains"); +DATA(insert OID = 574 ("&&" PGNSP PGUID b f f 704 704 16 574 0 tintervalov - -)); +DESCR("overlaps"); +DATA(insert OID = 575 ("#=" PGNSP PGUID b f f 704 703 16 0 576 tintervalleneq - -)); +DESCR("equal by length"); +DATA(insert OID = 576 ("#<>" PGNSP PGUID b f f 704 703 16 0 575 tintervallenne - -)); +DESCR("not equal by length"); +DATA(insert OID = 577 ("#<" PGNSP PGUID b f f 704 703 16 0 580 tintervallenlt - -)); +DESCR("less than by length"); +DATA(insert OID = 578 ("#>" PGNSP PGUID b f f 704 703 16 0 579 tintervallengt - -)); +DESCR("greater than by length"); +DATA(insert OID = 579 ("#<=" PGNSP PGUID b f f 704 703 16 0 578 tintervallenle - -)); +DESCR("less than or equal by length"); +DATA(insert OID = 580 ("#>=" PGNSP PGUID b f f 704 703 16 0 577 tintervallenge - -)); +DESCR("greater than or equal by length"); +DATA(insert OID = 581 ("+" PGNSP PGUID b f f 702 703 702 0 0 timepl - -)); +DESCR("add"); +DATA(insert OID = 582 ("-" PGNSP PGUID b f f 702 703 702 0 0 timemi - -)); +DESCR("subtract"); +DATA(insert OID = 583 ("" PGNSP PGUID b f f 702 704 16 0 0 intinterval - -)); +DESCR("is contained by"); +DATA(insert OID = 584 ("-" PGNSP PGUID l f f 0 700 700 0 0 float4um - -)); +DESCR("negate"); +DATA(insert OID = 585 ("-" PGNSP PGUID l f f 0 701 701 0 0 float8um - -)); +DESCR("negate"); +DATA(insert OID = 586 ("+" PGNSP PGUID b f f 700 700 700 586 0 float4pl - -)); +DESCR("add"); +DATA(insert OID = 587 ("-" PGNSP PGUID b f f 700 700 700 0 0 float4mi - -)); +DESCR("subtract"); +DATA(insert OID = 588 ("/" PGNSP PGUID b f f 700 700 700 0 0 float4div - -)); +DESCR("divide"); +DATA(insert OID = 589 ("*" PGNSP PGUID b f f 700 700 700 589 0 float4mul - -)); +DESCR("multiply"); +DATA(insert OID = 590 ("@" PGNSP PGUID l f f 0 700 700 0 0 float4abs - -)); +DESCR("absolute value"); +DATA(insert OID = 591 ("+" PGNSP PGUID b f f 701 701 701 591 0 float8pl - -)); +DESCR("add"); +DATA(insert OID = 592 ("-" PGNSP PGUID b f f 701 701 701 0 0 float8mi - -)); +DESCR("subtract"); +DATA(insert OID = 593 ("/" PGNSP PGUID b f f 701 701 701 0 0 float8div - -)); +DESCR("divide"); +DATA(insert OID = 594 ("*" PGNSP PGUID b f f 701 701 701 594 0 float8mul - -)); +DESCR("multiply"); +DATA(insert OID = 595 ("@" PGNSP PGUID l f f 0 701 701 0 0 float8abs - -)); +DESCR("absolute value"); +DATA(insert OID = 596 ("|/" PGNSP PGUID l f f 0 701 701 0 0 dsqrt - -)); +DESCR("square root"); +DATA(insert OID = 597 ("||/" PGNSP PGUID l f f 0 701 701 0 0 dcbrt - -)); +DESCR("cube root"); +DATA(insert OID = 1284 ("|" PGNSP PGUID l f f 0 704 702 0 0 tintervalstart - -)); +DESCR("start of interval"); +DATA(insert OID = 606 ("<#>" PGNSP PGUID b f f 702 702 704 0 0 mktinterval - -)); +DESCR("convert to tinterval"); + +DATA(insert OID = 607 ("=" PGNSP PGUID b t t 26 26 16 607 608 oideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 608 ("<>" PGNSP PGUID b f f 26 26 16 608 607 oidne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 609 ("<" PGNSP PGUID b f f 26 26 16 610 612 oidlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 610 (">" PGNSP PGUID b f f 26 26 16 609 611 oidgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 611 ("<=" PGNSP PGUID b f f 26 26 16 612 610 oidle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 612 (">=" PGNSP PGUID b f f 26 26 16 611 609 oidge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 644 ("<>" PGNSP PGUID b f f 30 30 16 644 649 oidvectorne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 645 ("<" PGNSP PGUID b f f 30 30 16 646 648 oidvectorlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 646 (">" PGNSP PGUID b f f 30 30 16 645 647 oidvectorgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 647 ("<=" PGNSP PGUID b f f 30 30 16 648 646 oidvectorle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 648 (">=" PGNSP PGUID b f f 30 30 16 647 645 oidvectorge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 649 ("=" PGNSP PGUID b t t 30 30 16 649 644 oidvectoreq eqsel eqjoinsel)); +DESCR("equal"); + +DATA(insert OID = 613 ("<->" PGNSP PGUID b f f 600 628 701 0 0 dist_pl - -)); +DESCR("distance between"); +DATA(insert OID = 614 ("<->" PGNSP PGUID b f f 600 601 701 0 0 dist_ps - -)); +DESCR("distance between"); +DATA(insert OID = 615 ("<->" PGNSP PGUID b f f 600 603 701 0 0 dist_pb - -)); +DESCR("distance between"); +DATA(insert OID = 616 ("<->" PGNSP PGUID b f f 601 628 701 0 0 dist_sl - -)); +DESCR("distance between"); +DATA(insert OID = 617 ("<->" PGNSP PGUID b f f 601 603 701 0 0 dist_sb - -)); +DESCR("distance between"); +DATA(insert OID = 618 ("<->" PGNSP PGUID b f f 600 602 701 0 0 dist_ppath - -)); +DESCR("distance between"); + +DATA(insert OID = 620 ("=" PGNSP PGUID b t t 700 700 16 620 621 float4eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT4EQOID 620 +DATA(insert OID = 621 ("<>" PGNSP PGUID b f f 700 700 16 621 620 float4ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT4NEOID 621 +DATA(insert OID = 622 ("<" PGNSP PGUID b f f 700 700 16 623 625 float4lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT4LTOID 622 +DATA(insert OID = 623 (">" PGNSP PGUID b f f 700 700 16 622 624 float4gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT4GTOID 623 +DATA(insert OID = 624 ("<=" PGNSP PGUID b f f 700 700 16 625 623 float4le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT4LEOID 624 +DATA(insert OID = 625 (">=" PGNSP PGUID b f f 700 700 16 624 622 float4ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT4GEOID 625 +DATA(insert OID = 630 ("<>" PGNSP PGUID b f f 18 18 16 630 92 charne neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 631 ("<" PGNSP PGUID b f f 18 18 16 633 634 charlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 632 ("<=" PGNSP PGUID b f f 18 18 16 634 633 charle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 633 (">" PGNSP PGUID b f f 18 18 16 631 632 chargt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 634 (">=" PGNSP PGUID b f f 18 18 16 632 631 charge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT1EQOID 5513 +DATA(insert OID = 5513 ("=" PGNSP PGUID b t t 5545 5545 16 5513 5514 int1eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 5514 ("<>" PGNSP PGUID b f f 5545 5545 16 5514 5513 int1ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 5515 ("<" PGNSP PGUID b f f 5545 5545 16 5517 5518 int1lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 5516 ("<=" PGNSP PGUID b f f 5545 5545 16 5518 5517 int1le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 5517 (">" PGNSP PGUID b f f 5545 5545 16 5515 5516 int1gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 5518 (">=" PGNSP PGUID b f f 5545 5545 16 5516 5515 int1ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 639 ("~" PGNSP PGUID b f f 19 25 16 0 640 nameregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_NAME_REGEXEQ_OP 639 +DATA(insert OID = 640 ("!~" PGNSP PGUID b f f 19 25 16 0 639 nameregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 641 ("~" PGNSP PGUID b f f 25 25 16 0 642 textregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_TEXT_REGEXEQ_OP 641 +DATA(insert OID = 642 ("!~" PGNSP PGUID b f f 25 25 16 0 641 textregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 643 ("<>" PGNSP PGUID b f f 19 19 16 643 93 namene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 654 ("||" PGNSP PGUID b f f 25 25 25 0 0 textcat - -)); +DESCR("concatenate"); + +DATA(insert OID = 660 ("<" PGNSP PGUID b f f 19 19 16 662 663 namelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 661 ("<=" PGNSP PGUID b f f 19 19 16 663 662 namele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 662 (">" PGNSP PGUID b f f 19 19 16 660 661 namegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 663 (">=" PGNSP PGUID b f f 19 19 16 661 660 namege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 664 ("<" PGNSP PGUID b f f 25 25 16 666 667 text_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TEXTLTOID 664 +DATA(insert OID = 665 ("<=" PGNSP PGUID b f f 25 25 16 667 666 text_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 666 (">" PGNSP PGUID b f f 25 25 16 664 665 text_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TEXTGTOID 666 +DATA(insert OID = 667 (">=" PGNSP PGUID b f f 25 25 16 665 664 text_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 670 ("=" PGNSP PGUID b t t 701 701 16 670 671 float8eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT8EQOID 670 +DATA(insert OID = 671 ("<>" PGNSP PGUID b f f 701 701 16 671 670 float8ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT8NEOID 671 +DATA(insert OID = 672 ("<" PGNSP PGUID b f f 701 701 16 674 675 float8lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT8LTOID 672 +DATA(insert OID = 673 ("<=" PGNSP PGUID b f f 701 701 16 675 674 float8le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT8LEOID 673 +DATA(insert OID = 674 (">" PGNSP PGUID b f f 701 701 16 672 673 float8gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT8GTOID 674 +DATA(insert OID = 675 (">=" PGNSP PGUID b f f 701 701 16 673 672 float8ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT8GEOID 675 + +DATA(insert OID = 682 ("@" PGNSP PGUID l f f 0 21 21 0 0 int2abs - -)); +DESCR("absolute value"); +DATA(insert OID = 684 ("+" PGNSP PGUID b f f 20 20 20 684 0 int8pl - -)); +DESCR("add"); +#define INT8PLOID 684 +DATA(insert OID = 685 ("-" PGNSP PGUID b f f 20 20 20 0 0 int8mi - -)); +DESCR("subtract"); +#define INT8MIOID 685 +DATA(insert OID = 686 ("*" PGNSP PGUID b f f 20 20 20 686 0 int8mul - -)); +DESCR("multiply"); +#define INT8MULOID 686 +DATA(insert OID = 687 ("/" PGNSP PGUID b f f 20 20 701 0 0 int8div - -)); +DESCR("divide"); +#define INT8DIVOID 687 +DATA(insert OID = 688 ("+" PGNSP PGUID b f f 20 23 20 692 0 int84pl - -)); +DESCR("add"); +#define INT84PLOID 688 +DATA(insert OID = 689 ("-" PGNSP PGUID b f f 20 23 20 0 0 int84mi - -)); +DESCR("subtract"); +#define INT84MIOID 689 +DATA(insert OID = 690 ("*" PGNSP PGUID b f f 20 23 20 694 0 int84mul - -)); +DESCR("multiply"); +#define INT84MULOID 690 +DATA(insert OID = 691 ("/" PGNSP PGUID b f f 20 23 701 0 0 int84div - -)); +DESCR("divide"); +#define INT84DIVOID 691 +DATA(insert OID = 692 ("+" PGNSP PGUID b f f 23 20 20 688 0 int48pl - -)); +DESCR("add"); +#define INT48PLOID 692 +DATA(insert OID = 693 ("-" PGNSP PGUID b f f 23 20 20 0 0 int48mi - -)); +DESCR("subtract"); +#define INT48MIOID 693 +DATA(insert OID = 694 ("*" PGNSP PGUID b f f 23 20 20 690 0 int48mul - -)); +DESCR("multiply"); +#define INT48MULOID 694 +DATA(insert OID = 695 ("/" PGNSP PGUID b f f 23 20 701 0 0 int48div - -)); +DESCR("divide"); +#define INT48DIVOID 695 +DATA(insert OID = 818 ("+" PGNSP PGUID b f f 20 21 20 822 0 int82pl - -)); +DESCR("add"); +#define INT82PLOID 818 +DATA(insert OID = 819 ("-" PGNSP PGUID b f f 20 21 20 0 0 int82mi - -)); +DESCR("subtract"); +#define INT82MIOID 819 +DATA(insert OID = 820 ("*" PGNSP PGUID b f f 20 21 20 824 0 int82mul - -)); +DESCR("multiply"); +#define INT82MULOID 820 +DATA(insert OID = 821 ("/" PGNSP PGUID b f f 20 21 701 0 0 int82div - -)); +DESCR("divide"); +#define INT82DIVOID 821 +DATA(insert OID = 822 ("+" PGNSP PGUID b f f 21 20 20 818 0 int28pl - -)); +DESCR("add"); +#define INT28PLOID 822 +DATA(insert OID = 823 ("-" PGNSP PGUID b f f 21 20 20 0 0 int28mi - -)); +DESCR("subtract"); +#define INT28MIOID 823 +DATA(insert OID = 824 ("*" PGNSP PGUID b f f 21 20 20 820 0 int28mul - -)); +DESCR("multiply"); +#define INT28MULOID 824 +DATA(insert OID = 825 ("/" PGNSP PGUID b f f 21 20 701 0 0 int28div - -)); +DESCR("divide"); +#define INT28DIVOID 825 +DATA(insert OID = 706 ("<->" PGNSP PGUID b f f 603 603 701 706 0 box_distance - -)); +DESCR("distance between"); +DATA(insert OID = 707 ("<->" PGNSP PGUID b f f 602 602 701 707 0 path_distance - -)); +DESCR("distance between"); +DATA(insert OID = 708 ("<->" PGNSP PGUID b f f 628 628 701 708 0 line_distance - -)); +DESCR("distance between"); +DATA(insert OID = 709 ("<->" PGNSP PGUID b f f 601 601 701 709 0 lseg_distance - -)); +DESCR("distance between"); +DATA(insert OID = 712 ("<->" PGNSP PGUID b f f 604 604 701 712 0 poly_distance - -)); +DESCR("distance between"); + +DATA(insert OID = 713 ("<>" PGNSP PGUID b f f 600 600 16 713 510 point_ne neqsel neqjoinsel)); +DESCR("not equal"); + +/* add translation/rotation/scaling operators for geometric types. - thomas 97/05/10 */ +DATA(insert OID = 731 ("+" PGNSP PGUID b f f 600 600 600 731 0 point_add - -)); +DESCR("add points (translate)"); +DATA(insert OID = 732 ("-" PGNSP PGUID b f f 600 600 600 0 0 point_sub - -)); +DESCR("subtract points (translate)"); +DATA(insert OID = 733 ("*" PGNSP PGUID b f f 600 600 600 733 0 point_mul - -)); +DESCR("multiply points (scale/rotate)"); +DATA(insert OID = 734 ("/" PGNSP PGUID b f f 600 600 600 0 0 point_div - -)); +DESCR("divide points (scale/rotate)"); +DATA(insert OID = 735 ("+" PGNSP PGUID b f f 602 602 602 735 0 path_add - -)); +DESCR("concatenate"); +DATA(insert OID = 736 ("+" PGNSP PGUID b f f 602 600 602 0 0 path_add_pt - -)); +DESCR("add (translate path)"); +DATA(insert OID = 737 ("-" PGNSP PGUID b f f 602 600 602 0 0 path_sub_pt - -)); +DESCR("subtract (translate path)"); +DATA(insert OID = 738 ("*" PGNSP PGUID b f f 602 600 602 0 0 path_mul_pt - -)); +DESCR("multiply (rotate/scale path)"); +DATA(insert OID = 739 ("/" PGNSP PGUID b f f 602 600 602 0 0 path_div_pt - -)); +DESCR("divide (rotate/scale path)"); +DATA(insert OID = 755 ("@>" PGNSP PGUID b f f 602 600 16 512 0 path_contain_pt - -)); +DESCR("contains"); +DATA(insert OID = 756 ("<@" PGNSP PGUID b f f 600 604 16 757 0 pt_contained_poly contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 757 ("@>" PGNSP PGUID b f f 604 600 16 756 0 poly_contain_pt contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 758 ("<@" PGNSP PGUID b f f 600 718 16 759 0 pt_contained_circle contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 759 ("@>" PGNSP PGUID b f f 718 600 16 758 0 circle_contain_pt contsel contjoinsel)); +DESCR("contains"); + +DATA(insert OID = 773 ("@" PGNSP PGUID l f f 0 23 23 0 0 int4abs - -)); +DESCR("absolute value"); + +/* additional operators for geometric types - thomas 1997-07-09 */ +DATA(insert OID = 792 ("=" PGNSP PGUID b f f 602 602 16 792 0 path_n_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 793 ("<" PGNSP PGUID b f f 602 602 16 794 0 path_n_lt - -)); +DESCR("less than"); +DATA(insert OID = 794 (">" PGNSP PGUID b f f 602 602 16 793 0 path_n_gt - -)); +DESCR("greater than"); +DATA(insert OID = 795 ("<=" PGNSP PGUID b f f 602 602 16 796 0 path_n_le - -)); +DESCR("less than or equal"); +DATA(insert OID = 796 (">=" PGNSP PGUID b f f 602 602 16 795 0 path_n_ge - -)); +DESCR("greater than or equal"); +DATA(insert OID = 797 ("#" PGNSP PGUID l f f 0 602 23 0 0 path_npoints - -)); +DESCR("number of points"); +DATA(insert OID = 798 ("?#" PGNSP PGUID b f f 602 602 16 0 0 path_inter - -)); +DESCR("intersect"); +DATA(insert OID = 799 ("@-@" PGNSP PGUID l f f 0 602 701 0 0 path_length - -)); +DESCR("sum of path segment lengths"); +DATA(insert OID = 800 (">^" PGNSP PGUID b f f 603 603 16 0 0 box_above_eq positionsel positionjoinsel)); +DESCR("is above (allows touching)"); +DATA(insert OID = 801 ("<^" PGNSP PGUID b f f 603 603 16 0 0 box_below_eq positionsel positionjoinsel)); +DESCR("is below (allows touching)"); +DATA(insert OID = 802 ("?#" PGNSP PGUID b f f 603 603 16 0 0 box_overlap areasel areajoinsel)); +DESCR("deprecated, use && instead"); +DATA(insert OID = 803 ("#" PGNSP PGUID b f f 603 603 603 0 0 box_intersect - -)); +DESCR("box intersection"); +DATA(insert OID = 804 ("+" PGNSP PGUID b f f 603 600 603 0 0 box_add - -)); +DESCR("add point to box (translate)"); +DATA(insert OID = 805 ("-" PGNSP PGUID b f f 603 600 603 0 0 box_sub - -)); +DESCR("subtract point from box (translate)"); +DATA(insert OID = 806 ("*" PGNSP PGUID b f f 603 600 603 0 0 box_mul - -)); +DESCR("multiply box by point (scale)"); +DATA(insert OID = 807 ("/" PGNSP PGUID b f f 603 600 603 0 0 box_div - -)); +DESCR("divide box by point (scale)"); +DATA(insert OID = 808 ("?-" PGNSP PGUID b f f 600 600 16 808 0 point_horiz - -)); +DESCR("horizontally aligned"); +DATA(insert OID = 809 ("?|" PGNSP PGUID b f f 600 600 16 809 0 point_vert - -)); +DESCR("vertically aligned"); + +DATA(insert OID = 811 ("=" PGNSP PGUID b t f 704 704 16 811 812 tintervaleq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 812 ("<>" PGNSP PGUID b f f 704 704 16 812 811 tintervalne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 813 ("<" PGNSP PGUID b f f 704 704 16 814 816 tintervallt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 814 (">" PGNSP PGUID b f f 704 704 16 813 815 tintervalgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 815 ("<=" PGNSP PGUID b f f 704 704 16 816 814 tintervalle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 816 (">=" PGNSP PGUID b f f 704 704 16 815 813 tintervalge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 843 ("*" PGNSP PGUID b f f 790 700 790 845 0 cash_mul_flt4 - -)); +DESCR("multiply"); +DATA(insert OID = 844 ("/" PGNSP PGUID b f f 790 700 790 0 0 cash_div_flt4 - -)); +DESCR("divide"); +DATA(insert OID = 845 ("*" PGNSP PGUID b f f 700 790 790 843 0 flt4_mul_cash - -)); +DESCR("multiply"); + +DATA(insert OID = 900 ("=" PGNSP PGUID b t f 790 790 16 900 901 cash_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 901 ("<>" PGNSP PGUID b f f 790 790 16 901 900 cash_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 902 ("<" PGNSP PGUID b f f 790 790 16 903 905 cash_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 903 (">" PGNSP PGUID b f f 790 790 16 902 904 cash_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 904 ("<=" PGNSP PGUID b f f 790 790 16 905 903 cash_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 905 (">=" PGNSP PGUID b f f 790 790 16 904 902 cash_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 906 ("+" PGNSP PGUID b f f 790 790 790 906 0 cash_pl - -)); +DESCR("add"); +DATA(insert OID = 907 ("-" PGNSP PGUID b f f 790 790 790 0 0 cash_mi - -)); +DESCR("subtract"); +DATA(insert OID = 908 ("*" PGNSP PGUID b f f 790 701 790 916 0 cash_mul_flt8 - -)); +DESCR("multiply"); +DATA(insert OID = 909 ("/" PGNSP PGUID b f f 790 701 790 0 0 cash_div_flt8 - -)); +DESCR("divide"); +DATA(insert OID = 3346 ("*" PGNSP PGUID b f f 790 20 790 3349 0 cash_mul_int8 - -)); +DESCR("multiply"); +DATA(insert OID = 3347 ("/" PGNSP PGUID b f f 790 20 790 0 0 cash_div_int8 - -)); +DESCR("divide"); +DATA(insert OID = 912 ("*" PGNSP PGUID b f f 790 23 790 917 0 cash_mul_int4 - -)); +DESCR("multiply"); +DATA(insert OID = 913 ("/" PGNSP PGUID b f f 790 23 790 0 0 cash_div_int4 - -)); +DESCR("divide"); +DATA(insert OID = 914 ("*" PGNSP PGUID b f f 790 21 790 918 0 cash_mul_int2 - -)); +DESCR("multiply"); +DATA(insert OID = 915 ("/" PGNSP PGUID b f f 790 21 790 0 0 cash_div_int2 - -)); +DESCR("divide"); +DATA(insert OID = 3352 ("*" PGNSP PGUID b f f 790 5545 790 3354 0 cash_mul_int1 - -)); +DESCR("multiply"); +DATA(insert OID = 3353 ("/" PGNSP PGUID b f f 790 5545 790 0 0 cash_div_int1 - -)); +DESCR("divide"); +DATA(insert OID = 916 ("*" PGNSP PGUID b f f 701 790 790 908 0 flt8_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3349 ("*" PGNSP PGUID b f f 20 790 790 3346 0 int8_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 917 ("*" PGNSP PGUID b f f 23 790 790 912 0 int4_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 918 ("*" PGNSP PGUID b f f 21 790 790 914 0 int2_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3354 ("*" PGNSP PGUID b f f 5545 790 790 3352 0 int1_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3825 ("/" PGNSP PGUID b f f 790 790 701 0 0 cash_div_cash - -)); +DESCR("divide"); + +DATA(insert OID = 965 ("^" PGNSP PGUID b f f 701 701 701 0 0 dpow - -)); +DESCR("exponentiation"); +DATA(insert OID = 966 ("+" PGNSP PGUID b f f 1034 1033 1034 0 0 aclinsert - -)); +DESCR("add/update ACL item"); +DATA(insert OID = 967 ("-" PGNSP PGUID b f f 1034 1033 1034 0 0 aclremove - -)); +DESCR("remove ACL item"); +DATA(insert OID = 968 ("@>" PGNSP PGUID b f f 1034 1033 16 0 0 aclcontains - -)); +DESCR("contains"); +DATA(insert OID = 974 ("=" PGNSP PGUID b f t 1033 1033 16 974 0 aclitemeq eqsel eqjoinsel)); +DESCR("equal"); + +/* additional geometric operators - thomas 1997-07-09 */ +DATA(insert OID = 969 ("@@" PGNSP PGUID l f f 0 601 600 0 0 lseg_center - -)); +DESCR("center of"); +DATA(insert OID = 970 ("@@" PGNSP PGUID l f f 0 602 600 0 0 path_center - -)); +DESCR("center of"); +DATA(insert OID = 971 ("@@" PGNSP PGUID l f f 0 604 600 0 0 poly_center - -)); +DESCR("center of"); + +DATA(insert OID = 1054 ("=" PGNSP PGUID b t t 1042 1042 16 1054 1057 bpchareq eqsel eqjoinsel)); +DESCR("equal"); +#define BPCHAREQOID 1054 +DATA(insert OID = 1055 ("~" PGNSP PGUID b f f 1042 25 16 0 1056 bpcharregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_BPCHAR_REGEXEQ_OP 1055 +DATA(insert OID = 1056 ("!~" PGNSP PGUID b f f 1042 25 16 0 1055 bpcharregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 1057 ("<>" PGNSP PGUID b f f 1042 1042 16 1057 1054 bpcharne neqsel neqjoinsel)); +DESCR("not equal"); +#define BPCHARNEOID 1057 +DATA(insert OID = 1058 ("<" PGNSP PGUID b f f 1042 1042 16 1060 1061 bpcharlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define BPCHARLTOID 1058 +DATA(insert OID = 1059 ("<=" PGNSP PGUID b f f 1042 1042 16 1061 1060 bpcharle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1060 (">" PGNSP PGUID b f f 1042 1042 16 1058 1059 bpchargt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define BPCHARGTOID 1060 +DATA(insert OID = 1061 (">=" PGNSP PGUID b f f 1042 1042 16 1059 1058 bpcharge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* generic array comparison operators */ +DATA(insert OID = 1070 ("=" PGNSP PGUID b t t 2277 2277 16 1070 1071 array_eq eqsel eqjoinsel)); +DESCR("equal"); +#define ARRAY_EQ_OP 1070 +DATA(insert OID = 1071 ("<>" PGNSP PGUID b f f 2277 2277 16 1071 1070 array_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1072 ("<" PGNSP PGUID b f f 2277 2277 16 1073 1075 array_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define ARRAY_LT_OP 1072 +DATA(insert OID = 1073 (">" PGNSP PGUID b f f 2277 2277 16 1072 1074 array_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define ARRAY_GT_OP 1073 +DATA(insert OID = 1074 ("<=" PGNSP PGUID b f f 2277 2277 16 1075 1073 array_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1075 (">=" PGNSP PGUID b f f 2277 2277 16 1074 1072 array_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* date operators */ +DATA(insert OID = 1076 ("+" PGNSP PGUID b f f 1082 1186 1114 2551 0 date_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1077 ("-" PGNSP PGUID b f f 1082 1186 1114 0 0 date_mi_interval - -)); +DESCR("subtract"); +DATA(insert OID = 1093 ("=" PGNSP PGUID b t t 1082 1082 16 1093 1094 date_eq eqsel eqjoinsel)); +DESCR("equal"); +#define DATEEQOID 1093 +DATA(insert OID = 1094 ("<>" PGNSP PGUID b f f 1082 1082 16 1094 1093 date_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define DATENEOID 1094 +DATA(insert OID = 1095 ("<" PGNSP PGUID b f f 1082 1082 16 1097 1098 date_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define DATELTOID 1095 +DATA(insert OID = 1096 ("<=" PGNSP PGUID b f f 1082 1082 16 1098 1097 date_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define DATELEOID 1096 +DATA(insert OID = 1097 (">" PGNSP PGUID b f f 1082 1082 16 1095 1096 date_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define DATEGTOID 1097 +DATA(insert OID = 1098 (">=" PGNSP PGUID b f f 1082 1082 16 1096 1095 date_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define DATEGEOID 1098 +DATA(insert OID = 1099 ("-" PGNSP PGUID b f f 1082 1082 23 0 0 date_mi - -)); +DESCR("subtract"); +DATA(insert OID = 1100 ("+" PGNSP PGUID b f f 1082 23 1082 2555 0 date_pli - -)); +DESCR("add"); +DATA(insert OID = 1101 ("-" PGNSP PGUID b f f 1082 23 1082 0 0 date_mii - -)); +DESCR("subtract"); + +/* time operators */ +DATA(insert OID = 1108 ("=" PGNSP PGUID b t t 1083 1083 16 1108 1109 time_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1109 ("<>" PGNSP PGUID b f f 1083 1083 16 1109 1108 time_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1110 ("<" PGNSP PGUID b f f 1083 1083 16 1112 1113 time_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1111 ("<=" PGNSP PGUID b f f 1083 1083 16 1113 1112 time_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1112 (">" PGNSP PGUID b f f 1083 1083 16 1110 1111 time_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1113 (">=" PGNSP PGUID b f f 1083 1083 16 1111 1110 time_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* timetz operators */ +DATA(insert OID = 1550 ("=" PGNSP PGUID b t t 1266 1266 16 1550 1551 timetz_eq eqsel eqjoinsel)); +DESCR("equal"); +#define TIMETZEQOID 1550 +DATA(insert OID = 1551 ("<>" PGNSP PGUID b f f 1266 1266 16 1551 1550 timetz_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1552 ("<" PGNSP PGUID b f f 1266 1266 16 1554 1555 timetz_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1553 ("<=" PGNSP PGUID b f f 1266 1266 16 1555 1554 timetz_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1554 (">" PGNSP PGUID b f f 1266 1266 16 1552 1553 timetz_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1555 (">=" PGNSP PGUID b f f 1266 1266 16 1553 1552 timetz_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* float48 operators */ +DATA(insert OID = 1116 ("+" PGNSP PGUID b f f 700 701 701 1126 0 float48pl - -)); +DESCR("add"); +DATA(insert OID = 1117 ("-" PGNSP PGUID b f f 700 701 701 0 0 float48mi - -)); +DESCR("subtract"); +DATA(insert OID = 1118 ("/" PGNSP PGUID b f f 700 701 701 0 0 float48div - -)); +DESCR("divide"); +DATA(insert OID = 1119 ("*" PGNSP PGUID b f f 700 701 701 1129 0 float48mul - -)); +DESCR("multiply"); +DATA(insert OID = 1120 ("=" PGNSP PGUID b t t 700 701 16 1130 1121 float48eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT48EQOID 1120 +DATA(insert OID = 1121 ("<>" PGNSP PGUID b f f 700 701 16 1131 1120 float48ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT48NEOID 1121 +DATA(insert OID = 1122 ("<" PGNSP PGUID b f f 700 701 16 1133 1125 float48lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT48LTOID 1122 +DATA(insert OID = 1123 (">" PGNSP PGUID b f f 700 701 16 1132 1124 float48gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT48GTOID 1123 +DATA(insert OID = 1124 ("<=" PGNSP PGUID b f f 700 701 16 1135 1123 float48le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT48LEOID 1124 +DATA(insert OID = 1125 (">=" PGNSP PGUID b f f 700 701 16 1134 1122 float48ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT48GEOID 1125 + +/* float84 operators */ +DATA(insert OID = 1126 ("+" PGNSP PGUID b f f 701 700 701 1116 0 float84pl - -)); +DESCR("add"); +DATA(insert OID = 1127 ("-" PGNSP PGUID b f f 701 700 701 0 0 float84mi - -)); +DESCR("subtract"); +DATA(insert OID = 1128 ("/" PGNSP PGUID b f f 701 700 701 0 0 float84div - -)); +DESCR("divide"); +DATA(insert OID = 1129 ("*" PGNSP PGUID b f f 701 700 701 1119 0 float84mul - -)); +DESCR("multiply"); +DATA(insert OID = 1130 ("=" PGNSP PGUID b t t 701 700 16 1120 1131 float84eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT84EQOID 1130 +DATA(insert OID = 1131 ("<>" PGNSP PGUID b f f 701 700 16 1121 1130 float84ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT84NEOID 1131 +DATA(insert OID = 1132 ("<" PGNSP PGUID b f f 701 700 16 1123 1135 float84lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT84LTOID 1132 +DATA(insert OID = 1133 (">" PGNSP PGUID b f f 701 700 16 1122 1134 float84gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT84GTOID 1133 +DATA(insert OID = 1134 ("<=" PGNSP PGUID b f f 701 700 16 1125 1133 float84le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT84LEOID 1134 +DATA(insert OID = 1135 (">=" PGNSP PGUID b f f 701 700 16 1124 1132 float84ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT84GEOID 1135 + + +/* LIKE hacks by Keith Parks. */ +DATA(insert OID = 1207 ("~~" PGNSP PGUID b f f 19 25 16 0 1208 namelike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_NAME_LIKE_OP 1207 +DATA(insert OID = 1208 ("!~~" PGNSP PGUID b f f 19 25 16 0 1207 namenlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define OID_NAME_NOT_LIKE_OP 1208 +DATA(insert OID = 1209 ("~~" PGNSP PGUID b f f 25 25 16 0 1210 textlike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_TEXT_LIKE_OP 1209 +DATA(insert OID = 1210 ("!~~" PGNSP PGUID b f f 25 25 16 0 1209 textnlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define TEXTNOTLIKEOID 1210 +DATA(insert OID = 1211 ("~~" PGNSP PGUID b f f 1042 25 16 0 1212 bpcharlike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_BPCHAR_LIKE_OP 1211 +DATA(insert OID = 1212 ("!~~" PGNSP PGUID b f f 1042 25 16 0 1211 bpcharnlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define OID_BPCHAR_NOT_LIKE_OP 1212 + +/* case-insensitive regex hacks */ +DATA(insert OID = 1226 ("~*" PGNSP PGUID b f f 19 25 16 0 1227 nameicregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_NAME_ICREGEXEQ_OP 1226 +DATA(insert OID = 1227 ("!~*" PGNSP PGUID b f f 19 25 16 0 1226 nameicregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); +DATA(insert OID = 1228 ("~*" PGNSP PGUID b f f 25 25 16 0 1229 texticregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_TEXT_ICREGEXEQ_OP 1228 +DATA(insert OID = 1229 ("!~*" PGNSP PGUID b f f 25 25 16 0 1228 texticregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); +DATA(insert OID = 1234 ("~*" PGNSP PGUID b f f 1042 25 16 0 1235 bpcharicregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_BPCHAR_ICREGEXEQ_OP 1234 +DATA(insert OID = 1235 ("!~*" PGNSP PGUID b f f 1042 25 16 0 1234 bpcharicregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); + +/* timestamptz operators */ +DATA(insert OID = 1320 ("=" PGNSP PGUID b t t 1184 1184 16 1320 1321 timestamptz_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1321 ("<>" PGNSP PGUID b f f 1184 1184 16 1321 1320 timestamptz_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1322 ("<" PGNSP PGUID b f f 1184 1184 16 1324 1325 timestamptz_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIMESTAMPTZLTOID 1322 +DATA(insert OID = 1323 ("<=" PGNSP PGUID b f f 1184 1184 16 1325 1324 timestamptz_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define TIMESTAMPTZLEOID 1323 +DATA(insert OID = 1324 (">" PGNSP PGUID b f f 1184 1184 16 1322 1323 timestamptz_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TIMESTAMPTZGTOID 1324 +DATA(insert OID = 1325 (">=" PGNSP PGUID b f f 1184 1184 16 1323 1322 timestamptz_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define TIMESTAMPTZGEOID 1325 +DATA(insert OID = 1327 ("+" PGNSP PGUID b f f 1184 1186 1184 2554 0 timestamptz_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1328 ("-" PGNSP PGUID b f f 1184 1184 1186 0 0 timestamptz_mi - -)); +DESCR("subtract"); +DATA(insert OID = 1329 ("-" PGNSP PGUID b f f 1184 1186 1184 0 0 timestamptz_mi_interval - -)); +DESCR("subtract"); + +/* interval operators */ +DATA(insert OID = 1330 ("=" PGNSP PGUID b t t 1186 1186 16 1330 1331 interval_eq eqsel eqjoinsel)); +DESCR("equal"); +#define INTERVALEQOID 1330 +DATA(insert OID = 1331 ("<>" PGNSP PGUID b f f 1186 1186 16 1331 1330 interval_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1332 ("<" PGNSP PGUID b f f 1186 1186 16 1334 1335 interval_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1333 ("<=" PGNSP PGUID b f f 1186 1186 16 1335 1334 interval_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1334 (">" PGNSP PGUID b f f 1186 1186 16 1332 1333 interval_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1335 (">=" PGNSP PGUID b f f 1186 1186 16 1333 1332 interval_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 1336 ("-" PGNSP PGUID l f f 0 1186 1186 0 0 interval_um - -)); +DESCR("negate"); +DATA(insert OID = 1337 ("+" PGNSP PGUID b f f 1186 1186 1186 1337 0 interval_pl - -)); +DESCR("add"); +DATA(insert OID = 1338 ("-" PGNSP PGUID b f f 1186 1186 1186 0 0 interval_mi - -)); +DESCR("subtract"); + +DATA(insert OID = 1360 ("+" PGNSP PGUID b f f 1082 1083 1114 1363 0 datetime_pl - -)); +DESCR("convert date and time to timestamp"); +DATA(insert OID = 1361 ("+" PGNSP PGUID b f f 1082 1266 1184 1366 0 datetimetz_pl - -)); +DESCR("convert date and time with time zone to timestamp with time zone"); +DATA(insert OID = 1363 ("+" PGNSP PGUID b f f 1083 1082 1114 1360 0 timedate_pl - -)); +DESCR("convert time and date to timestamp"); +DATA(insert OID = 1366 ("+" PGNSP PGUID b f f 1266 1082 1184 1361 0 timetzdate_pl - -)); +DESCR("convert time with time zone and date to timestamp with time zone"); + +DATA(insert OID = 1399 ("-" PGNSP PGUID b f f 1083 1083 1186 0 0 time_mi_time - -)); +DESCR("subtract"); + +/* additional geometric operators - thomas 97/04/18 */ +DATA(insert OID = 1420 ("@@" PGNSP PGUID l f f 0 718 600 0 0 circle_center - -)); +DESCR("center of"); +DATA(insert OID = 1500 ("=" PGNSP PGUID b f f 718 718 16 1500 1501 circle_eq eqsel eqjoinsel)); +DESCR("equal by area"); +DATA(insert OID = 1501 ("<>" PGNSP PGUID b f f 718 718 16 1501 1500 circle_ne neqsel neqjoinsel)); +DESCR("not equal by area"); +DATA(insert OID = 1502 ("<" PGNSP PGUID b f f 718 718 16 1503 1505 circle_lt areasel areajoinsel)); +DESCR("less than by area"); +DATA(insert OID = 1503 (">" PGNSP PGUID b f f 718 718 16 1502 1504 circle_gt areasel areajoinsel)); +DESCR("greater than by area"); +DATA(insert OID = 1504 ("<=" PGNSP PGUID b f f 718 718 16 1505 1503 circle_le areasel areajoinsel)); +DESCR("less than or equal by area"); +DATA(insert OID = 1505 (">=" PGNSP PGUID b f f 718 718 16 1504 1502 circle_ge areasel areajoinsel)); +DESCR("greater than or equal by area"); + +DATA(insert OID = 1506 ("<<" PGNSP PGUID b f f 718 718 16 0 0 circle_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 1507 ("&<" PGNSP PGUID b f f 718 718 16 0 0 circle_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 1508 ("&>" PGNSP PGUID b f f 718 718 16 0 0 circle_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 1509 (">>" PGNSP PGUID b f f 718 718 16 0 0 circle_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 1510 ("<@" PGNSP PGUID b f f 718 718 16 1511 0 circle_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 1511 ("@>" PGNSP PGUID b f f 718 718 16 1510 0 circle_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 1512 ("~=" PGNSP PGUID b f f 718 718 16 1512 0 circle_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 1513 ("&&" PGNSP PGUID b f f 718 718 16 1513 0 circle_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 1514 ("|>>" PGNSP PGUID b f f 718 718 16 0 0 circle_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 1515 ("<<|" PGNSP PGUID b f f 718 718 16 0 0 circle_below positionsel positionjoinsel)); +DESCR("is below"); + +DATA(insert OID = 1516 ("+" PGNSP PGUID b f f 718 600 718 0 0 circle_add_pt - -)); +DESCR("add"); +DATA(insert OID = 1517 ("-" PGNSP PGUID b f f 718 600 718 0 0 circle_sub_pt - -)); +DESCR("subtract"); +DATA(insert OID = 1518 ("*" PGNSP PGUID b f f 718 600 718 0 0 circle_mul_pt - -)); +DESCR("multiply"); +DATA(insert OID = 1519 ("/" PGNSP PGUID b f f 718 600 718 0 0 circle_div_pt - -)); +DESCR("divide"); + +DATA(insert OID = 1520 ("<->" PGNSP PGUID b f f 718 718 701 1520 0 circle_distance - -)); +DESCR("distance between"); +DATA(insert OID = 1521 ("#" PGNSP PGUID l f f 0 604 23 0 0 poly_npoints - -)); +DESCR("number of points"); +DATA(insert OID = 1522 ("<->" PGNSP PGUID b f f 600 718 701 0 0 dist_pc - -)); +DESCR("distance between"); +DATA(insert OID = 1523 ("<->" PGNSP PGUID b f f 718 604 701 0 0 dist_cpoly - -)); +DESCR("distance between"); + +/* additional geometric operators - thomas 1997-07-09 */ +DATA(insert OID = 1524 ("<->" PGNSP PGUID b f f 628 603 701 0 0 dist_lb - -)); +DESCR("distance between"); + +DATA(insert OID = 1525 ("?#" PGNSP PGUID b f f 601 601 16 1525 0 lseg_intersect - -)); +DESCR("intersect"); +DATA(insert OID = 1526 ("?||" PGNSP PGUID b f f 601 601 16 1526 0 lseg_parallel - -)); +DESCR("parallel"); +DATA(insert OID = 1527 ("?-|" PGNSP PGUID b f f 601 601 16 1527 0 lseg_perp - -)); +DESCR("perpendicular"); +DATA(insert OID = 1528 ("?-" PGNSP PGUID l f f 0 601 16 0 0 lseg_horizontal - -)); +DESCR("horizontal"); +DATA(insert OID = 1529 ("?|" PGNSP PGUID l f f 0 601 16 0 0 lseg_vertical - -)); +DESCR("vertical"); +DATA(insert OID = 1535 ("=" PGNSP PGUID b f f 601 601 16 1535 1586 lseg_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1536 ("#" PGNSP PGUID b f f 601 601 600 1536 0 lseg_interpt - -)); +DESCR("intersection point"); +DATA(insert OID = 1537 ("?#" PGNSP PGUID b f f 601 628 16 0 0 inter_sl - -)); +DESCR("intersect"); +DATA(insert OID = 1538 ("?#" PGNSP PGUID b f f 601 603 16 0 0 inter_sb - -)); +DESCR("intersect"); +DATA(insert OID = 1539 ("?#" PGNSP PGUID b f f 628 603 16 0 0 inter_lb - -)); +DESCR("intersect"); + +DATA(insert OID = 1546 ("<@" PGNSP PGUID b f f 600 628 16 0 0 on_pl - -)); +DESCR("point on line"); +DATA(insert OID = 1547 ("<@" PGNSP PGUID b f f 600 601 16 0 0 on_ps - -)); +DESCR("is contained by"); +DATA(insert OID = 1548 ("<@" PGNSP PGUID b f f 601 628 16 0 0 on_sl - -)); +DESCR("lseg on line"); +DATA(insert OID = 1549 ("<@" PGNSP PGUID b f f 601 603 16 0 0 on_sb - -)); +DESCR("is contained by"); + +DATA(insert OID = 1557 ("##" PGNSP PGUID b f f 600 628 600 0 0 close_pl - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1558 ("##" PGNSP PGUID b f f 600 601 600 0 0 close_ps - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1559 ("##" PGNSP PGUID b f f 600 603 600 0 0 close_pb - -)); +DESCR("closest point to A on B"); + +DATA(insert OID = 1566 ("##" PGNSP PGUID b f f 601 628 600 0 0 close_sl - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1567 ("##" PGNSP PGUID b f f 601 603 600 0 0 close_sb - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1568 ("##" PGNSP PGUID b f f 628 603 600 0 0 close_lb - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1577 ("##" PGNSP PGUID b f f 628 601 600 0 0 close_ls - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1578 ("##" PGNSP PGUID b f f 601 601 600 0 0 close_lseg - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1583 ("*" PGNSP PGUID b f f 1186 701 1186 1584 0 interval_mul - -)); +DESCR("multiply"); +DATA(insert OID = 1584 ("*" PGNSP PGUID b f f 701 1186 1186 1583 0 mul_d_interval - -)); +DESCR("multiply"); +DATA(insert OID = 1585 ("/" PGNSP PGUID b f f 1186 701 1186 0 0 interval_div - -)); +DESCR("divide"); + +DATA(insert OID = 1586 ("<>" PGNSP PGUID b f f 601 601 16 1586 1535 lseg_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1587 ("<" PGNSP PGUID b f f 601 601 16 1589 1590 lseg_lt - -)); +DESCR("less than by length"); +DATA(insert OID = 1588 ("<=" PGNSP PGUID b f f 601 601 16 1590 1589 lseg_le - -)); +DESCR("less than or equal by length"); +DATA(insert OID = 1589 (">" PGNSP PGUID b f f 601 601 16 1587 1588 lseg_gt - -)); +DESCR("greater than by length"); +DATA(insert OID = 1590 (">=" PGNSP PGUID b f f 601 601 16 1588 1587 lseg_ge - -)); +DESCR("greater than or equal by length"); + +DATA(insert OID = 1591 ("@-@" PGNSP PGUID l f f 0 601 701 0 0 lseg_length - -)); +DESCR("distance between endpoints"); + +DATA(insert OID = 1611 ("?#" PGNSP PGUID b f f 628 628 16 1611 0 line_intersect - -)); +DESCR("intersect"); +DATA(insert OID = 1612 ("?||" PGNSP PGUID b f f 628 628 16 1612 0 line_parallel - -)); +DESCR("parallel"); +DATA(insert OID = 1613 ("?-|" PGNSP PGUID b f f 628 628 16 1613 0 line_perp - -)); +DESCR("perpendicular"); +DATA(insert OID = 1614 ("?-" PGNSP PGUID l f f 0 628 16 0 0 line_horizontal - -)); +DESCR("horizontal"); +DATA(insert OID = 1615 ("?|" PGNSP PGUID l f f 0 628 16 0 0 line_vertical - -)); +DESCR("vertical"); +DATA(insert OID = 1616 ("=" PGNSP PGUID b f f 628 628 16 1616 0 line_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1617 ("#" PGNSP PGUID b f f 628 628 600 1617 0 line_interpt - -)); +DESCR("intersection point"); + +/* MAC type */ +DATA(insert OID = 1220 ("=" PGNSP PGUID b t t 829 829 16 1220 1221 macaddr_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1221 ("<>" PGNSP PGUID b f f 829 829 16 1221 1220 macaddr_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1222 ("<" PGNSP PGUID b f f 829 829 16 1224 1225 macaddr_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1223 ("<=" PGNSP PGUID b f f 829 829 16 1225 1224 macaddr_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1224 (">" PGNSP PGUID b f f 829 829 16 1222 1223 macaddr_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1225 (">=" PGNSP PGUID b f f 829 829 16 1223 1222 macaddr_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 3147 ("~" PGNSP PGUID l f f 0 829 829 0 0 macaddr_not - -)); +DESCR("bitwise not"); +DATA(insert OID = 3148 ("&" PGNSP PGUID b f f 829 829 829 0 0 macaddr_and - -)); +DESCR("bitwise and"); +DATA(insert OID = 3149 ("|" PGNSP PGUID b f f 829 829 829 0 0 macaddr_or - -)); +DESCR("bitwise or"); + +/* INET type (these also support CIDR via implicit cast) */ +DATA(insert OID = 1201 ("=" PGNSP PGUID b t t 869 869 16 1201 1202 network_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1202 ("<>" PGNSP PGUID b f f 869 869 16 1202 1201 network_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1203 ("<" PGNSP PGUID b f f 869 869 16 1205 1206 network_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1204 ("<=" PGNSP PGUID b f f 869 869 16 1206 1205 network_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1205 (">" PGNSP PGUID b f f 869 869 16 1203 1204 network_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1206 (">=" PGNSP PGUID b f f 869 869 16 1204 1203 network_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 931 ("<<" PGNSP PGUID b f f 869 869 16 933 0 network_sub - -)); +DESCR("is subnet"); +#define OID_INET_SUB_OP 931 +DATA(insert OID = 932 ("<<=" PGNSP PGUID b f f 869 869 16 934 0 network_subeq - -)); +DESCR("is subnet or equal"); +#define OID_INET_SUBEQ_OP 932 +DATA(insert OID = 933 (">>" PGNSP PGUID b f f 869 869 16 931 0 network_sup - -)); +DESCR("is supernet"); +#define OID_INET_SUP_OP 933 +DATA(insert OID = 934 (">>=" PGNSP PGUID b f f 869 869 16 932 0 network_supeq - -)); +DESCR("is supernet or equal"); +#define OID_INET_SUPEQ_OP 934 + +DATA(insert OID = 2634 ("~" PGNSP PGUID l f f 0 869 869 0 0 inetnot - -)); +DESCR("bitwise not"); +DATA(insert OID = 2635 ("&" PGNSP PGUID b f f 869 869 869 0 0 inetand - -)); +DESCR("bitwise and"); +DATA(insert OID = 2636 ("|" PGNSP PGUID b f f 869 869 869 0 0 inetor - -)); +DESCR("bitwise or"); +DATA(insert OID = 2637 ("+" PGNSP PGUID b f f 869 20 869 2638 0 inetpl - -)); +DESCR("add"); +DATA(insert OID = 2638 ("+" PGNSP PGUID b f f 20 869 869 2637 0 int8pl_inet - -)); +DESCR("add"); +DATA(insert OID = 2639 ("-" PGNSP PGUID b f f 869 20 869 0 0 inetmi_int8 - -)); +DESCR("subtract"); +DATA(insert OID = 2640 ("-" PGNSP PGUID b f f 869 869 20 0 0 inetmi - -)); +DESCR("subtract"); + +/* case-insensitive LIKE hacks */ +DATA(insert OID = 1625 ("~~*" PGNSP PGUID b f f 19 25 16 0 1626 nameiclike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_NAME_ICLIKE_OP 1625 +DATA(insert OID = 1626 ("!~~*" PGNSP PGUID b f f 19 25 16 0 1625 nameicnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); +DATA(insert OID = 1627 ("~~*" PGNSP PGUID b f f 25 25 16 0 1628 texticlike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_TEXT_ICLIKE_OP 1627 +DATA(insert OID = 1628 ("!~~*" PGNSP PGUID b f f 25 25 16 0 1627 texticnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); +DATA(insert OID = 1629 ("~~*" PGNSP PGUID b f f 1042 25 16 0 1630 bpchariclike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_BPCHAR_ICLIKE_OP 1629 +DATA(insert OID = 1630 ("!~~*" PGNSP PGUID b f f 1042 25 16 0 1629 bpcharicnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); + +/* NUMERIC type - OID's 1700-1799 */ +DATA(insert OID = 1751 ("-" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_uminus - -)); +DESCR("negate"); +#define NUMEQOID 1752 +DATA(insert OID = 1752 ("=" PGNSP PGUID b t t 1700 1700 16 1752 1753 numeric_eq eqsel eqjoinsel)); +DESCR("equal"); +#define NUMERICEQOID 1752 +DATA(insert OID = 1753 ("<>" PGNSP PGUID b f f 1700 1700 16 1753 1752 numeric_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define NUMERICNEOID 1753 +DATA(insert OID = 1754 ("<" PGNSP PGUID b f f 1700 1700 16 1756 1757 numeric_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define NUMERICLTOID 1754 +DATA(insert OID = 1755 ("<=" PGNSP PGUID b f f 1700 1700 16 1757 1756 numeric_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define NUMERICLEOID 1755 +DATA(insert OID = 1756 (">" PGNSP PGUID b f f 1700 1700 16 1754 1755 numeric_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define NUMERICGTOID 1756 +DATA(insert OID = 1757 (">=" PGNSP PGUID b f f 1700 1700 16 1755 1754 numeric_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define NUMERICGEOID 1757 +DATA(insert OID = 1758 ("+" PGNSP PGUID b f f 1700 1700 1700 1758 0 numeric_add - -)); +DESCR("add"); +#define NUMERICADDOID 1758 +DATA(insert OID = 1759 ("-" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_sub - -)); +DESCR("subtract"); +#define NUMERICSUBOID 1759 +DATA(insert OID = 1760 ("*" PGNSP PGUID b f f 1700 1700 1700 1760 0 numeric_mul - -)); +DESCR("multiply"); +#define NUMERICMULOID 1760 +DATA(insert OID = 1761 ("/" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_div - -)); +DESCR("divide"); +#define NUMERICDIVOID 1761 +DATA(insert OID = 1762 ("%" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_mod - -)); +DESCR("modulus"); +#define NUMERICMODOID 1762 +DATA(insert OID = 1038 ("^" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_power - -)); +DESCR("exponentiation"); +DATA(insert OID = 1763 ("@" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_abs - -)); +DESCR("absolute value"); + +DATA(insert OID = 1784 ("=" PGNSP PGUID b t f 1560 1560 16 1784 1785 biteq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1785 ("<>" PGNSP PGUID b f f 1560 1560 16 1785 1784 bitne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1786 ("<" PGNSP PGUID b f f 1560 1560 16 1787 1789 bitlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1787 (">" PGNSP PGUID b f f 1560 1560 16 1786 1788 bitgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1788 ("<=" PGNSP PGUID b f f 1560 1560 16 1789 1787 bitle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1789 (">=" PGNSP PGUID b f f 1560 1560 16 1788 1786 bitge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 1791 ("&" PGNSP PGUID b f f 1560 1560 1560 1791 0 bitand - -)); +DESCR("bitwise and"); +DATA(insert OID = 1792 ("|" PGNSP PGUID b f f 1560 1560 1560 1792 0 bitor - -)); +DESCR("bitwise or"); +DATA(insert OID = 1793 ("#" PGNSP PGUID b f f 1560 1560 1560 1793 0 bitxor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1794 ("~" PGNSP PGUID l f f 0 1560 1560 0 0 bitnot - -)); +DESCR("bitwise not"); +DATA(insert OID = 1795 ("<<" PGNSP PGUID b f f 1560 23 1560 0 0 bitshiftleft - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1796 (">>" PGNSP PGUID b f f 1560 23 1560 0 0 bitshiftright - -)); +DESCR("bitwise shift right"); +DATA(insert OID = 1797 ("||" PGNSP PGUID b f f 1562 1562 1562 0 0 bitcat - -)); +DESCR("concatenate"); + +DATA(insert OID = 1800 ("+" PGNSP PGUID b f f 1083 1186 1083 1849 0 time_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1801 ("-" PGNSP PGUID b f f 1083 1186 1083 0 0 time_mi_interval - -)); +DESCR("subtract"); +DATA(insert OID = 1802 ("+" PGNSP PGUID b f f 1266 1186 1266 2552 0 timetz_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1803 ("-" PGNSP PGUID b f f 1266 1186 1266 0 0 timetz_mi_interval - -)); +DESCR("subtract"); + +DATA(insert OID = 1804 ("=" PGNSP PGUID b t f 1562 1562 16 1804 1805 varbiteq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1805 ("<>" PGNSP PGUID b f f 1562 1562 16 1805 1804 varbitne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1806 ("<" PGNSP PGUID b f f 1562 1562 16 1807 1809 varbitlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1807 (">" PGNSP PGUID b f f 1562 1562 16 1806 1808 varbitgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1808 ("<=" PGNSP PGUID b f f 1562 1562 16 1809 1807 varbitle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1809 (">=" PGNSP PGUID b f f 1562 1562 16 1808 1806 varbitge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 1849 ("+" PGNSP PGUID b f f 1186 1083 1083 1800 0 interval_pl_time - -)); +DESCR("add"); + +DATA(insert OID = 1862 ("=" PGNSP PGUID b t t 21 20 16 1868 1863 int28eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT28EQOID 1862 +DATA(insert OID = 1863 ("<>" PGNSP PGUID b f f 21 20 16 1869 1862 int28ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT28NEOID 1863 +DATA(insert OID = 1864 ("<" PGNSP PGUID b f f 21 20 16 1871 1867 int28lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT28LTOID 1864 +DATA(insert OID = 1865 (">" PGNSP PGUID b f f 21 20 16 1870 1866 int28gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT28GTOID 1865 +DATA(insert OID = 1866 ("<=" PGNSP PGUID b f f 21 20 16 1873 1865 int28le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT28LEOID 1866 +DATA(insert OID = 1867 (">=" PGNSP PGUID b f f 21 20 16 1872 1864 int28ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT28GEOID 1867 + +DATA(insert OID = 1868 ("=" PGNSP PGUID b t t 20 21 16 1862 1869 int82eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT82EQOID 1868 +DATA(insert OID = 1869 ("<>" PGNSP PGUID b f f 20 21 16 1863 1868 int82ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT82NEOID 1869 +DATA(insert OID = 1870 ("<" PGNSP PGUID b f f 20 21 16 1865 1873 int82lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT82LTOID 1870 +DATA(insert OID = 1871 (">" PGNSP PGUID b f f 20 21 16 1864 1872 int82gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT82GTOID 1871 +DATA(insert OID = 1872 ("<=" PGNSP PGUID b f f 20 21 16 1867 1871 int82le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT82LEOID 1872 +DATA(insert OID = 1873 (">=" PGNSP PGUID b f f 20 21 16 1866 1870 int82ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT82GEOID 1873 + +DATA(insert OID = 1874 ("&" PGNSP PGUID b f f 21 21 21 1874 0 int2and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1875 ("|" PGNSP PGUID b f f 21 21 21 1875 0 int2or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1876 ("#" PGNSP PGUID b f f 21 21 21 1876 0 int2xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1877 ("~" PGNSP PGUID l f f 0 21 21 0 0 int2not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1878 ("<<" PGNSP PGUID b f f 21 23 21 0 0 int2shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1879 (">>" PGNSP PGUID b f f 21 23 21 0 0 int2shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1880 ("&" PGNSP PGUID b f f 23 23 23 1880 0 int4and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1881 ("|" PGNSP PGUID b f f 23 23 23 1881 0 int4or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1882 ("#" PGNSP PGUID b f f 23 23 23 1882 0 int4xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1883 ("~" PGNSP PGUID l f f 0 23 23 0 0 int4not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1884 ("<<" PGNSP PGUID b f f 23 23 23 0 0 int4shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1885 (">>" PGNSP PGUID b f f 23 23 23 0 0 int4shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1886 ("&" PGNSP PGUID b f f 20 20 20 1886 0 int8and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1887 ("|" PGNSP PGUID b f f 20 20 20 1887 0 int8or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1888 ("#" PGNSP PGUID b f f 20 20 20 1888 0 int8xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1889 ("~" PGNSP PGUID l f f 0 20 20 0 0 int8not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1890 ("<<" PGNSP PGUID b f f 20 23 20 0 0 int8shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1891 (">>" PGNSP PGUID b f f 20 23 20 0 0 int8shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1916 ("+" PGNSP PGUID l f f 0 20 20 0 0 int8up - -)); +DESCR("unary plus"); +DATA(insert OID = 1917 ("+" PGNSP PGUID l f f 0 21 21 0 0 int2up - -)); +DESCR("unary plus"); +DATA(insert OID = 1918 ("+" PGNSP PGUID l f f 0 23 23 0 0 int4up - -)); +DESCR("unary plus"); +DATA(insert OID = 1919 ("+" PGNSP PGUID l f f 0 700 700 0 0 float4up - -)); +DESCR("unary plus"); +DATA(insert OID = 1920 ("+" PGNSP PGUID l f f 0 701 701 0 0 float8up - -)); +DESCR("unary plus"); +DATA(insert OID = 1921 ("+" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_uplus - -)); +DESCR("unary plus"); + +/* bytea operators */ +DATA(insert OID = 1955 ("=" PGNSP PGUID b t t 17 17 16 1955 1956 byteaeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1956 ("<>" PGNSP PGUID b f f 17 17 16 1956 1955 byteane neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1957 ("<" PGNSP PGUID b f f 17 17 16 1959 1960 bytealt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1958 ("<=" PGNSP PGUID b f f 17 17 16 1960 1959 byteale scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1959 (">" PGNSP PGUID b f f 17 17 16 1957 1958 byteagt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1960 (">=" PGNSP PGUID b f f 17 17 16 1958 1957 byteage scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 2016 ("~~" PGNSP PGUID b f f 17 17 16 0 2017 bytealike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_BYTEA_LIKE_OP 2016 +DATA(insert OID = 2017 ("!~~" PGNSP PGUID b f f 17 17 16 0 2016 byteanlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 2018 ("||" PGNSP PGUID b f f 17 17 17 0 0 byteacat - -)); +DESCR("concatenate"); + +/* byteawithoutorderwithequalcol operators */ +DATA(insert OID = 4453 ("=" PGNSP PGUID b t t 4402 4402 16 4453 4454 byteawithoutorderwithequalcoleq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4454 ("<>" PGNSP PGUID b f f 4402 4402 16 4454 4453 byteawithoutorderwithequalcolne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 4422 ("=" PGNSP PGUID b f f 4402 17 16 4431 4423 byteawithoutorderwithequalcoleqbytear eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4423 ("<>" PGNSP PGUID b f f 4402 17 16 4432 4422 byteawithoutorderwithequalcolnebytear neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 4431 ("=" PGNSP PGUID b f f 17 4402 16 4422 4432 byteawithoutorderwithequalcoleqbyteal eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4432 ("<>" PGNSP PGUID b f f 17 4402 16 4423 4431 byteawithoutorderwithequalcolnebyteal neqsel neqjoinsel)); +DESCR("not equal"); + +/* raw operators */ +DATA(insert OID = 3798 ("=" PGNSP PGUID b t t 86 86 16 3798 3799 raweq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3799 ("<>" PGNSP PGUID b f f 86 86 16 3799 3798 rawne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3800 ("<" PGNSP PGUID b f f 86 86 16 3802 3803 rawlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3801 ("<=" PGNSP PGUID b f f 86 86 16 3803 3802 rawle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3802 (">" PGNSP PGUID b f f 86 86 16 3800 3801 rawgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3803 (">=" PGNSP PGUID b f f 86 86 16 3801 3800 rawge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3804 ("~~" PGNSP PGUID b f f 86 86 16 0 3805 rawlike likesel likejoinsel)); +DESCR("matches like expression"); +#define OID_RAW_LIKE_OP 3804 +DATA(insert OID = 3805 ("!~~" PGNSP PGUID b f f 86 86 16 0 3804 rawnlike nlikesel nlikejoinsel)); +DESCR("does not match like expression"); + +/* timestamp operators */ +DATA(insert OID = 2060 ("=" PGNSP PGUID b t t 1114 1114 16 2060 2061 timestamp_eq eqsel eqjoinsel)); +DESCR("equal"); +#define TIMESTAMPEQOID 2060 +DATA(insert OID = 2061 ("<>" PGNSP PGUID b f f 1114 1114 16 2061 2060 timestamp_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define TIMESTAMPNEOID 2061 +DATA(insert OID = 2062 ("<" PGNSP PGUID b f f 1114 1114 16 2064 2065 timestamp_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIMESTAMPLTOID 2062 +DATA(insert OID = 2063 ("<=" PGNSP PGUID b f f 1114 1114 16 2065 2064 timestamp_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define TIMESTAMPLEOID 2063 +DATA(insert OID = 2064 (">" PGNSP PGUID b f f 1114 1114 16 2062 2063 timestamp_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TIMESTAMPGTOID 2064 +DATA(insert OID = 2065 (">=" PGNSP PGUID b f f 1114 1114 16 2063 2062 timestamp_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define TIMESTAMPGEOID 2065 +DATA(insert OID = 2066 ("+" PGNSP PGUID b f f 1114 1186 1114 2553 0 timestamp_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 2067 ("-" PGNSP PGUID b f f 1114 1114 1186 0 0 timestamp_mi - -)); +DESCR("subtract"); +DATA(insert OID = 2068 ("-" PGNSP PGUID b f f 1114 1186 1114 0 0 timestamp_mi_interval - -)); +DESCR("subtract"); + +/* character-by-character (not collation order) comparison operators for character types */ +DATA(insert OID = 2314 ("~<~" PGNSP PGUID b f f 25 25 16 2318 2317 text_pattern_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2315 ("~<=~" PGNSP PGUID b f f 25 25 16 2317 2318 text_pattern_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2317 ("~>=~" PGNSP PGUID b f f 25 25 16 2315 2314 text_pattern_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2318 ("~>~" PGNSP PGUID b f f 25 25 16 2314 2315 text_pattern_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); + +DATA(insert OID = 2326 ("~<~" PGNSP PGUID b f f 1042 1042 16 2330 2329 bpchar_pattern_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2327 ("~<=~" PGNSP PGUID b f f 1042 1042 16 2329 2330 bpchar_pattern_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2329 ("~>=~" PGNSP PGUID b f f 1042 1042 16 2327 2326 bpchar_pattern_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2330 ("~>~" PGNSP PGUID b f f 1042 1042 16 2326 2327 bpchar_pattern_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); + +/* crosstype operations for date vs. timestamp and timestamptz */ +DATA(insert OID = 2345 ("<" PGNSP PGUID b f f 1082 1114 16 2375 2348 date_lt_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2346 ("<=" PGNSP PGUID b f f 1082 1114 16 2374 2349 date_le_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2347 ("=" PGNSP PGUID b t f 1082 1114 16 2373 2350 date_eq_timestamp eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2348 (">=" PGNSP PGUID b f f 1082 1114 16 2372 2345 date_ge_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2349 (">" PGNSP PGUID b f f 1082 1114 16 2371 2346 date_gt_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2350 ("<>" PGNSP PGUID b f f 1082 1114 16 2376 2347 date_ne_timestamp neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2358 ("<" PGNSP PGUID b f f 1082 1184 16 2388 2361 date_lt_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2359 ("<=" PGNSP PGUID b f f 1082 1184 16 2387 2362 date_le_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2360 ("=" PGNSP PGUID b t f 1082 1184 16 2386 2363 date_eq_timestamptz eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2361 (">=" PGNSP PGUID b f f 1082 1184 16 2385 2358 date_ge_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2362 (">" PGNSP PGUID b f f 1082 1184 16 2384 2359 date_gt_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2363 ("<>" PGNSP PGUID b f f 1082 1184 16 2389 2360 date_ne_timestamptz neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2371 ("<" PGNSP PGUID b f f 1114 1082 16 2349 2374 timestamp_lt_date scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2372 ("<=" PGNSP PGUID b f f 1114 1082 16 2348 2375 timestamp_le_date scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2373 ("=" PGNSP PGUID b t f 1114 1082 16 2347 2376 timestamp_eq_date eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2374 (">=" PGNSP PGUID b f f 1114 1082 16 2346 2371 timestamp_ge_date scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2375 (">" PGNSP PGUID b f f 1114 1082 16 2345 2372 timestamp_gt_date scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2376 ("<>" PGNSP PGUID b f f 1114 1082 16 2350 2373 timestamp_ne_date neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2384 ("<" PGNSP PGUID b f f 1184 1082 16 2362 2387 timestamptz_lt_date scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2385 ("<=" PGNSP PGUID b f f 1184 1082 16 2361 2388 timestamptz_le_date scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2386 ("=" PGNSP PGUID b t f 1184 1082 16 2360 2389 timestamptz_eq_date eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2387 (">=" PGNSP PGUID b f f 1184 1082 16 2359 2384 timestamptz_ge_date scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2388 (">" PGNSP PGUID b f f 1184 1082 16 2358 2385 timestamptz_gt_date scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2389 ("<>" PGNSP PGUID b f f 1184 1082 16 2363 2386 timestamptz_ne_date neqsel neqjoinsel)); +DESCR("not equal"); + +/* crosstype operations for timestamp vs. timestamptz */ +DATA(insert OID = 2534 ("<" PGNSP PGUID b f f 1114 1184 16 2544 2537 timestamp_lt_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2535 ("<=" PGNSP PGUID b f f 1114 1184 16 2543 2538 timestamp_le_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2536 ("=" PGNSP PGUID b t f 1114 1184 16 2542 2539 timestamp_eq_timestamptz eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2537 (">=" PGNSP PGUID b f f 1114 1184 16 2541 2534 timestamp_ge_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2538 (">" PGNSP PGUID b f f 1114 1184 16 2540 2535 timestamp_gt_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2539 ("<>" PGNSP PGUID b f f 1114 1184 16 2545 2536 timestamp_ne_timestamptz neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2540 ("<" PGNSP PGUID b f f 1184 1114 16 2538 2543 timestamptz_lt_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2541 ("<=" PGNSP PGUID b f f 1184 1114 16 2537 2544 timestamptz_le_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2542 ("=" PGNSP PGUID b t f 1184 1114 16 2536 2545 timestamptz_eq_timestamp eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2543 (">=" PGNSP PGUID b f f 1184 1114 16 2535 2540 timestamptz_ge_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2544 (">" PGNSP PGUID b f f 1184 1114 16 2534 2541 timestamptz_gt_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2545 ("<>" PGNSP PGUID b f f 1184 1114 16 2539 2542 timestamptz_ne_timestamp neqsel neqjoinsel)); +DESCR("not equal"); + +/* formerly-missing interval + datetime operators */ +DATA(insert OID = 2551 ("+" PGNSP PGUID b f f 1186 1082 1114 1076 0 interval_pl_date - -)); +DESCR("add"); +DATA(insert OID = 2552 ("+" PGNSP PGUID b f f 1186 1266 1266 1802 0 interval_pl_timetz - -)); +DESCR("add"); +DATA(insert OID = 2553 ("+" PGNSP PGUID b f f 1186 1114 1114 2066 0 interval_pl_timestamp - -)); +DESCR("add"); +DATA(insert OID = 2554 ("+" PGNSP PGUID b f f 1186 1184 1184 1327 0 interval_pl_timestamptz - -)); +DESCR("add"); +DATA(insert OID = 2555 ("+" PGNSP PGUID b f f 23 1082 1082 1100 0 integer_pl_date - -)); +DESCR("add"); + +/* new operators for Y-direction rtree opfamilies */ +DATA(insert OID = 2570 ("<<|" PGNSP PGUID b f f 603 603 16 0 0 box_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 2571 ("&<|" PGNSP PGUID b f f 603 603 16 0 0 box_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2572 ("|&>" PGNSP PGUID b f f 603 603 16 0 0 box_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); +DATA(insert OID = 2573 ("|>>" PGNSP PGUID b f f 603 603 16 0 0 box_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 2574 ("<<|" PGNSP PGUID b f f 604 604 16 0 0 poly_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 2575 ("&<|" PGNSP PGUID b f f 604 604 16 0 0 poly_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2576 ("|&>" PGNSP PGUID b f f 604 604 16 0 0 poly_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); +DATA(insert OID = 2577 ("|>>" PGNSP PGUID b f f 604 604 16 0 0 poly_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 2589 ("&<|" PGNSP PGUID b f f 718 718 16 0 0 circle_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2590 ("|&>" PGNSP PGUID b f f 718 718 16 0 0 circle_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); + +/* overlap/contains/contained for arrays */ +DATA(insert OID = 2750 ("&&" PGNSP PGUID b f f 2277 2277 16 2750 0 arrayoverlap arraycontsel arraycontjoinsel)); +DESCR("overlaps"); +#define OID_ARRAY_OVERLAP_OP 2750 +DATA(insert OID = 2751 ("@>" PGNSP PGUID b f f 2277 2277 16 2752 0 arraycontains arraycontsel arraycontjoinsel)); +DESCR("contains"); +#define OID_ARRAY_CONTAINS_OP 2751 +DATA(insert OID = 2752 ("<@" PGNSP PGUID b f f 2277 2277 16 2751 0 arraycontained arraycontsel arraycontjoinsel)); +DESCR("is contained by"); +#define OID_ARRAY_CONTAINED_OP 2752 + +/* capturing operators to preserve pre-8.3 behavior of text concatenation */ +DATA(insert OID = 2779 ("||" PGNSP PGUID b f f 25 2776 25 0 0 textanycat - -)); +DESCR("concatenate"); +DATA(insert OID = 2780 ("||" PGNSP PGUID b f f 2776 25 25 0 0 anytextcat - -)); +DESCR("concatenate"); + +/* obsolete names for contains/contained-by operators; remove these someday */ +DATA(insert OID = 2860 ("@" PGNSP PGUID b f f 604 604 16 2861 0 poly_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2861 ("~" PGNSP PGUID b f f 604 604 16 2860 0 poly_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2862 ("@" PGNSP PGUID b f f 603 603 16 2863 0 box_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2863 ("~" PGNSP PGUID b f f 603 603 16 2862 0 box_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2864 ("@" PGNSP PGUID b f f 718 718 16 2865 0 circle_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2865 ("~" PGNSP PGUID b f f 718 718 16 2864 0 circle_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2866 ("@" PGNSP PGUID b f f 600 603 16 0 0 on_pb - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2867 ("@" PGNSP PGUID b f f 600 602 16 2868 0 on_ppath - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2868 ("~" PGNSP PGUID b f f 602 600 16 2867 0 path_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2869 ("@" PGNSP PGUID b f f 600 604 16 2870 0 pt_contained_poly - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2870 ("~" PGNSP PGUID b f f 604 600 16 2869 0 poly_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2871 ("@" PGNSP PGUID b f f 600 718 16 2872 0 pt_contained_circle - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2872 ("~" PGNSP PGUID b f f 718 600 16 2871 0 circle_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2873 ("@" PGNSP PGUID b f f 600 628 16 0 0 on_pl - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2874 ("@" PGNSP PGUID b f f 600 601 16 0 0 on_ps - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2875 ("@" PGNSP PGUID b f f 601 628 16 0 0 on_sl - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2876 ("@" PGNSP PGUID b f f 601 603 16 0 0 on_sb - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2877 ("~" PGNSP PGUID b f f 1034 1033 16 0 0 aclcontains - -)); +DESCR("deprecated, use @> instead"); + +/* uuid operators */ +DATA(insert OID = 2972 ("=" PGNSP PGUID b t t 2950 2950 16 2972 2973 uuid_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2973 ("<>" PGNSP PGUID b f f 2950 2950 16 2973 2972 uuid_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2974 ("<" PGNSP PGUID b f f 2950 2950 16 2975 2977 uuid_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2975 (">" PGNSP PGUID b f f 2950 2950 16 2974 2976 uuid_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2976 ("<=" PGNSP PGUID b f f 2950 2950 16 2977 2975 uuid_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2977 (">=" PGNSP PGUID b f f 2950 2950 16 2976 2974 uuid_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* enum operators */ +DATA(insert OID = 3516 ("=" PGNSP PGUID b t t 3500 3500 16 3516 3517 enum_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3517 ("<>" PGNSP PGUID b f f 3500 3500 16 3517 3516 enum_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3518 ("<" PGNSP PGUID b f f 3500 3500 16 3519 3521 enum_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3519 (">" PGNSP PGUID b f f 3500 3500 16 3518 3520 enum_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3520 ("<=" PGNSP PGUID b f f 3500 3500 16 3521 3519 enum_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3521 (">=" PGNSP PGUID b f f 3500 3500 16 3520 3518 enum_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* + * tsearch operations + */ +DATA(insert OID = 3627 ("<" PGNSP PGUID b f f 3614 3614 16 3632 3631 tsvector_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3628 ("<=" PGNSP PGUID b f f 3614 3614 16 3631 3632 tsvector_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3629 ("=" PGNSP PGUID b t f 3614 3614 16 3629 3630 tsvector_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3630 ("<>" PGNSP PGUID b f f 3614 3614 16 3630 3629 tsvector_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3631 (">=" PGNSP PGUID b f f 3614 3614 16 3628 3627 tsvector_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3632 (">" PGNSP PGUID b f f 3614 3614 16 3627 3628 tsvector_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3633 ("||" PGNSP PGUID b f f 3614 3614 3614 0 0 tsvector_concat - -)); +DESCR("concatenate"); +DATA(insert OID = 3636 ("@@" PGNSP PGUID b f f 3614 3615 16 3637 0 ts_match_vq tsmatchsel tsmatchjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3637 ("@@" PGNSP PGUID b f f 3615 3614 16 3636 0 ts_match_qv tsmatchsel tsmatchjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3660 ("@@@" PGNSP PGUID b f f 3614 3615 16 3661 0 ts_match_vq tsmatchsel tsmatchjoinsel)); +DESCR("deprecated, use @@ instead"); +DATA(insert OID = 3661 ("@@@" PGNSP PGUID b f f 3615 3614 16 3660 0 ts_match_qv tsmatchsel tsmatchjoinsel)); +DESCR("deprecated, use @@ instead"); +DATA(insert OID = 3674 ("<" PGNSP PGUID b f f 3615 3615 16 3679 3678 tsquery_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3675 ("<=" PGNSP PGUID b f f 3615 3615 16 3678 3679 tsquery_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3676 ("=" PGNSP PGUID b t f 3615 3615 16 3676 3677 tsquery_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3677 ("<>" PGNSP PGUID b f f 3615 3615 16 3677 3676 tsquery_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3678 (">=" PGNSP PGUID b f f 3615 3615 16 3675 3674 tsquery_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3679 (">" PGNSP PGUID b f f 3615 3615 16 3674 3675 tsquery_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3680 ("&&" PGNSP PGUID b f f 3615 3615 3615 0 0 tsquery_and - -)); +DESCR("AND-concatenate"); +DATA(insert OID = 3681 ("||" PGNSP PGUID b f f 3615 3615 3615 0 0 tsquery_or - -)); +DESCR("OR-concatenate"); +DATA(insert OID = 3682 ("!!" PGNSP PGUID l f f 0 3615 3615 0 0 tsquery_not - -)); +DESCR("NOT tsquery"); +DATA(insert OID = 3693 ("@>" PGNSP PGUID b f f 3615 3615 16 3694 0 tsq_mcontains contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3694 ("<@" PGNSP PGUID b f f 3615 3615 16 3693 0 tsq_mcontained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3762 ("@@" PGNSP PGUID b f f 25 25 16 0 0 ts_match_tt contsel contjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3763 ("@@" PGNSP PGUID b f f 25 3615 16 0 0 ts_match_tq contsel contjoinsel)); +DESCR("text search match"); + +/* generic record comparison operators */ +DATA(insert OID = 2988 ("=" PGNSP PGUID b t f 2249 2249 16 2988 2989 record_eq eqsel eqjoinsel)); +DESCR("equal"); +#define RECORD_EQ_OP 2988 +DATA(insert OID = 2989 ("<>" PGNSP PGUID b f f 2249 2249 16 2989 2988 record_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2990 ("<" PGNSP PGUID b f f 2249 2249 16 2991 2993 record_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define RECORD_LT_OP 2990 +DATA(insert OID = 2991 (">" PGNSP PGUID b f f 2249 2249 16 2990 2992 record_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define RECORD_GT_OP 2991 +DATA(insert OID = 2992 ("<=" PGNSP PGUID b f f 2249 2249 16 2993 2991 record_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2993 (">=" PGNSP PGUID b f f 2249 2249 16 2992 2990 record_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* generic range type operators */ +DATA(insert OID = 3882 ("=" PGNSP PGUID b t t 3831 3831 16 3882 3883 range_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3883 ("<>" PGNSP PGUID b f f 3831 3831 16 3883 3882 range_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3884 ("<" PGNSP PGUID b f f 3831 3831 16 3887 3886 range_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3885 ("<=" PGNSP PGUID b f f 3831 3831 16 3886 3887 range_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3886 (">=" PGNSP PGUID b f f 3831 3831 16 3885 3884 range_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3887 (">" PGNSP PGUID b f f 3831 3831 16 3884 3885 range_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3888 ("&&" PGNSP PGUID b f f 3831 3831 16 3888 0 range_overlaps areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 3889 ("@>" PGNSP PGUID b f f 3831 2283 16 3891 0 range_contains_elem contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3890 ("@>" PGNSP PGUID b f f 3831 3831 16 3892 0 range_contains contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3891 ("<@" PGNSP PGUID b f f 2283 3831 16 3889 0 elem_contained_by_range contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3892 ("<@" PGNSP PGUID b f f 3831 3831 16 3890 0 range_contained_by contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3893 ("<<" PGNSP PGUID b f f 3831 3831 16 3894 0 range_before scalarltsel scalarltjoinsel)); +DESCR("is left of"); +DATA(insert OID = 3894 (">>" PGNSP PGUID b f f 3831 3831 16 3893 0 range_after scalargtsel scalargtjoinsel)); +DESCR("is right of"); +DATA(insert OID = 3895 ("&<" PGNSP PGUID b f f 3831 3831 16 0 0 range_overleft scalarltsel scalarltjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 3896 ("&>" PGNSP PGUID b f f 3831 3831 16 0 0 range_overright scalargtsel scalargtjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 3897 ("-|-" PGNSP PGUID b f f 3831 3831 16 3897 0 range_adjacent contsel contjoinsel)); +DESCR("is adjacent to"); +DATA(insert OID = 3898 ("+" PGNSP PGUID b f f 3831 3831 3831 3898 0 range_union - -)); +DESCR("range union"); +DATA(insert OID = 3899 ("-" PGNSP PGUID b f f 3831 3831 3831 0 0 range_minus - -)); +DESCR("range difference"); +DATA(insert OID = 3900 ("*" PGNSP PGUID b f f 3831 3831 3831 3900 0 range_intersect - -)); +DESCR("range intersection"); +DATA(insert OID = 5550 ("=" PGNSP PGUID b t t 9003 9003 16 5550 5551 smalldatetime_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 5551 ("<>" PGNSP PGUID b f f 9003 9003 16 5551 5550 smalldatetime_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 5552 ("<" PGNSP PGUID b f f 9003 9003 16 5554 5549 smalldatetime_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 5553 ("<=" PGNSP PGUID b f f 9003 9003 16 5549 5554 smalldatetime_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 5554 (">" PGNSP PGUID b f f 9003 9003 16 5552 5553 smalldatetime_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 5549 (">=" PGNSP PGUID b f f 9003 9003 16 5553 5552 smalldatetime_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* hll */ +DATA(insert OID = 4372 ( "=" PGNSP PGUID b f f 4301 4301 16 4372 4373 hll_eq eqsel eqjoinsel )); +DESCR("hyper log log equal op"); +DATA(insert OID = 4373 ( "<>" PGNSP PGUID b f f 4301 4301 16 4373 4372 hll_ne neqsel neqjoinsel )); +DESCR("hyper log log not equal op"); +DATA(insert OID = 4374 ( "||" PGNSP PGUID b f f 4301 4301 4301 0 0 hll_union - - )); +DESCR("hyper log log union op"); +DATA(insert OID = 4375 ( "||" PGNSP PGUID b f f 4301 4303 4301 0 0 hll_add - - )); +DESCR("hyper log log add op"); +DATA(insert OID = 4376 ( "||" PGNSP PGUID b f f 4303 4301 4301 0 0 hll_add_rev - - )); +DESCR("hyper log log add rev op"); +DATA(insert OID = 4377 ( "#" PGNSP PGUID l f f 0 4301 701 0 0 hll_cardinality - - )); +DESCR("hyper log log cardinality op"); +DATA(insert OID = 4378 ( "=" PGNSP PGUID b f f 4303 4303 16 4378 4379 hll_hashval_eq eqsel eqjoinsel )); +DESCR("hyper log log equal hashval op"); +DATA(insert OID = 4379 ( "<>" PGNSP PGUID b f f 4303 4303 16 4379 4378 hll_hashval_ne neqsel neqjoinsel )); +DESCR("hyper log log not equal hashval op"); +/* + * function prototypes + */ +extern void OperatorCreate(const char *operatorName, Oid operatorNamespace, Oid leftTypeId, Oid rightTypeId, Oid procedureId, + List *commutatorName, List *negatorName, Oid restrictionId, Oid joinId, bool canMerge, bool canHash); + +extern Oid OperatorGet(const char *operatorName, Oid operatorNamespace, Oid leftObjectId, Oid rightObjectId, bool *defined); + +#endif /* PG_OPERATOR_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_opfamily.h postgresql-hll-2.14/include/catalog/pg_opfamily.h --- postgresql-hll-2.14_old/include/catalog/pg_opfamily.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_opfamily.h 2020-12-12 17:06:43.083345922 +0800 @@ -0,0 +1,197 @@ +/* ------------------------------------------------------------------------- + * + * pg_opfamily.h + * definition of the system "opfamily" relation (pg_opfamily) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_opfamily.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPFAMILY_H +#define PG_OPFAMILY_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_opfamily definition. cpp turns this into + * typedef struct FormData_pg_opfamily + * ---------------- + */ +#define OperatorFamilyRelationId 2753 +#define OperatorFamilyRelation_Rowtype_Id 10005 + +CATALOG(pg_opfamily,2753) BKI_SCHEMA_MACRO +{ + Oid opfmethod; /* index access method opfamily is for */ + NameData opfname; /* name of this opfamily */ + Oid opfnamespace; /* namespace of this opfamily */ + Oid opfowner; /* opfamily owner */ +} FormData_pg_opfamily; + +/* ---------------- + * Form_pg_opfamily corresponds to a pointer to a tuple with + * the format of pg_opfamily relation. + * ---------------- + */ +typedef FormData_pg_opfamily *Form_pg_opfamily; + +/* ---------------- + * compiler constants for pg_opfamily + * ---------------- + */ +#define Natts_pg_opfamily 4 +#define Anum_pg_opfamily_opfmethod 1 +#define Anum_pg_opfamily_opfname 2 +#define Anum_pg_opfamily_opfnamespace 3 +#define Anum_pg_opfamily_opfowner 4 + +/* ---------------- + * initial contents of pg_opfamily + * ---------------- + */ +DATA(insert OID = 421 (403 abstime_ops PGNSP PGUID)); +DATA(insert OID = 397 (403 array_ops PGNSP PGUID)); +DATA(insert OID = 627 (405 array_ops PGNSP PGUID)); +DATA(insert OID = 423 (403 bit_ops PGNSP PGUID)); +DATA(insert OID = 424 (403 bool_ops PGNSP PGUID)); +#define BOOL_BTREE_FAM_OID 424 +DATA(insert OID = 426 (403 bpchar_ops PGNSP PGUID)); +#define BPCHAR_BTREE_FAM_OID 426 +DATA(insert OID = 427 (405 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 428 (403 bytea_ops PGNSP PGUID)); +#define BYTEA_BTREE_FAM_OID 428 +DATA(insert OID = 436 (403 byteawithoutorderwithequalcol_ops PGNSP PGUID)); +#define ENCRYPTEDCOL_BTREE_FAM_OID 436 +DATA(insert OID = 429 (403 char_ops PGNSP PGUID)); +DATA(insert OID = 431 (405 char_ops PGNSP PGUID)); +DATA(insert OID = 434 (403 datetime_ops PGNSP PGUID)); +DATA(insert OID = 435 (405 date_ops PGNSP PGUID)); +DATA(insert OID = 1970 (403 float_ops PGNSP PGUID)); +DATA(insert OID = 1971 (405 float_ops PGNSP PGUID)); +DATA(insert OID = 1974 (403 network_ops PGNSP PGUID)); +#define NETWORK_BTREE_FAM_OID 1974 +DATA(insert OID = 1975 (405 network_ops PGNSP PGUID)); +DATA(insert OID = 1976 (403 integer_ops PGNSP PGUID)); +#define INTEGER_BTREE_FAM_OID 1976 +DATA(insert OID = 1977 (405 integer_ops PGNSP PGUID)); +DATA(insert OID = 1982 (403 interval_ops PGNSP PGUID)); +DATA(insert OID = 1983 (405 interval_ops PGNSP PGUID)); +DATA(insert OID = 1984 (403 macaddr_ops PGNSP PGUID)); +DATA(insert OID = 1985 (405 macaddr_ops PGNSP PGUID)); +DATA(insert OID = 1986 (403 name_ops PGNSP PGUID)); +#define NAME_BTREE_FAM_OID 1986 +DATA(insert OID = 1987 (405 name_ops PGNSP PGUID)); +DATA(insert OID = 1988 (403 numeric_ops PGNSP PGUID)); +DATA(insert OID = 1998 (405 numeric_ops PGNSP PGUID)); +DATA(insert OID = 1989 (403 oid_ops PGNSP PGUID)); +#define OID_BTREE_FAM_OID 1989 +DATA(insert OID = 1990 (405 oid_ops PGNSP PGUID)); +DATA(insert OID = 1991 (403 oidvector_ops PGNSP PGUID)); +DATA(insert OID = 1992 (405 oidvector_ops PGNSP PGUID)); +DATA(insert OID = 2994 (403 record_ops PGNSP PGUID)); +DATA(insert OID = 1994 (403 text_ops PGNSP PGUID)); +#define TEXT_BTREE_FAM_OID 1994 +DATA(insert OID = 1995 (405 text_ops PGNSP PGUID)); +DATA(insert OID = 1996 (403 time_ops PGNSP PGUID)); +DATA(insert OID = 1997 (405 time_ops PGNSP PGUID)); +DATA(insert OID = 1999 (405 timestamptz_ops PGNSP PGUID)); +DATA(insert OID = 2000 (403 timetz_ops PGNSP PGUID)); +DATA(insert OID = 2001 (405 timetz_ops PGNSP PGUID)); +DATA(insert OID = 2002 (403 varbit_ops PGNSP PGUID)); +DATA(insert OID = 2040 (405 timestamp_ops PGNSP PGUID)); +DATA(insert OID = 2095 (403 text_pattern_ops PGNSP PGUID)); +#define TEXT_PATTERN_BTREE_FAM_OID 2095 +DATA(insert OID = 2097 (403 bpchar_pattern_ops PGNSP PGUID)); +#define BPCHAR_PATTERN_BTREE_FAM_OID 2097 +DATA(insert OID = 2099 (403 money_ops PGNSP PGUID)); +DATA(insert OID = 2222 (405 bool_ops PGNSP PGUID)); +#define BOOL_HASH_FAM_OID 2222 +DATA(insert OID = 2223 (405 bytea_ops PGNSP PGUID)); +DATA(insert OID = 4470 (405 byteawithoutorderwithequalcol_ops PGNSP PGUID )); +DATA(insert OID = 2224 (405 int2vector_ops PGNSP PGUID)); +DATA(insert OID = 2789 (403 tid_ops PGNSP PGUID)); +DATA(insert OID = 2225 (405 xid_ops PGNSP PGUID)); +DATA(insert OID = 2232 (405 xid32_ops PGNSP PGUID)); +DATA(insert OID = 2226 (405 cid_ops PGNSP PGUID)); +DATA(insert OID = 2227 (405 abstime_ops PGNSP PGUID)); +DATA(insert OID = 2228 (405 reltime_ops PGNSP PGUID)); +DATA(insert OID = 2229 (405 text_pattern_ops PGNSP PGUID)); +DATA(insert OID = 2231 (405 bpchar_pattern_ops PGNSP PGUID)); +DATA(insert OID = 2233 (403 reltime_ops PGNSP PGUID)); +DATA(insert OID = 2234 (403 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 2235 (405 aclitem_ops PGNSP PGUID)); +DATA(insert OID = 2593 (783 box_ops PGNSP PGUID)); +DATA(insert OID = 2594 (783 poly_ops PGNSP PGUID)); +DATA(insert OID = 2595 (783 circle_ops PGNSP PGUID)); +DATA(insert OID = 1029 (783 point_ops PGNSP PGUID)); +DATA(insert OID = 2745 (2742 array_ops PGNSP PGUID)); +DATA(insert OID = 2968 (403 uuid_ops PGNSP PGUID)); +DATA(insert OID = 2969 (405 uuid_ops PGNSP PGUID)); +DATA(insert OID = 3522 (403 enum_ops PGNSP PGUID)); +DATA(insert OID = 3523 (405 enum_ops PGNSP PGUID)); +DATA(insert OID = 3626 (403 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3655 (783 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3659 (2742 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 4446 (4444 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3683 (403 tsquery_ops PGNSP PGUID)); +DATA(insert OID = 3702 (783 tsquery_ops PGNSP PGUID)); +DATA(insert OID = 3901 (403 range_ops PGNSP PGUID)); +DATA(insert OID = 3903 (405 range_ops PGNSP PGUID)); +DATA(insert OID = 3919 (783 range_ops PGNSP PGUID)); +DATA(insert OID = 4015 (4000 quad_point_ops PGNSP PGUID)); +DATA(insert OID = 4016 (4000 kd_point_ops PGNSP PGUID)); +DATA(insert OID = 4017 (4000 text_ops PGNSP PGUID)); +#define TEXT_SPGIST_FAM_OID 4017 + +DATA(insert OID = 3806 (403 raw_ops PGNSP PGUID)); +DATA(insert OID = 3807 (405 raw_ops PGNSP PGUID)); +DATA(insert OID = 5535 (403 int1_ops PGNSP PGUID)); +DATA(insert OID = 5536 (405 int1_ops PGNSP PGUID)); +DATA(insert OID = 5570 (403 smalldatetime_ops PGNSP PGUID)); +DATA(insert OID = 5571 (405 smalldatetime_ops PGNSP PGUID)); + +/* psort index, fake data just make index work */ +DATA(insert OID = 4050 (4039 integer_ops PGNSP PGUID)); +DATA(insert OID = 4051 (4039 oid_ops PGNSP PGUID)); +DATA(insert OID = 4052 (4039 datetime_ops PGNSP PGUID)); +DATA(insert OID = 4053 (4039 float_ops PGNSP PGUID)); +DATA(insert OID = 4054 (4039 numeric_ops PGNSP PGUID)); +DATA(insert OID = 4055 (4039 text_ops PGNSP PGUID)); +DATA(insert OID = 4056 (4039 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 4057 (4039 time_ops PGNSP PGUID)); +DATA(insert OID = 4058 (4039 timetz_ops PGNSP PGUID)); +DATA(insert OID = 4059 (4039 money_ops PGNSP PGUID)); +DATA(insert OID = 4060 (4039 interval_ops PGNSP PGUID)); +DATA(insert OID = 4061 (4039 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 4062 (4039 int1_ops PGNSP PGUID)); +DATA(insert OID = 4063 (4039 bool_ops PGNSP PGUID)); +DATA(insert OID = 4064 (4039 smalldatetime_ops PGNSP PGUID)); + +/* cbtree index, fake data just make index work */ +DATA(insert OID = 4250 (4239 integer_ops PGNSP PGUID)); +DATA(insert OID = 4251 (4239 oid_ops PGNSP PGUID)); +DATA(insert OID = 4252 (4239 datetime_ops PGNSP PGUID)); +DATA(insert OID = 4253 (4239 float_ops PGNSP PGUID)); +DATA(insert OID = 4254 (4239 numeric_ops PGNSP PGUID)); +DATA(insert OID = 4255 (4239 text_ops PGNSP PGUID)); +DATA(insert OID = 4256 (4239 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 4257 (4239 time_ops PGNSP PGUID)); +DATA(insert OID = 4258 (4239 timetz_ops PGNSP PGUID)); +DATA(insert OID = 4259 (4239 money_ops PGNSP PGUID)); +DATA(insert OID = 4260 (4239 interval_ops PGNSP PGUID)); +DATA(insert OID = 4261 (4239 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 4262 (4239 int1_ops PGNSP PGUID)); +DATA(insert OID = 4263 (4239 bool_ops PGNSP PGUID)); +DATA(insert OID = 4264 (4239 smalldatetime_ops PGNSP PGUID)); + +#endif /* PG_OPFAMILY_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_partition_fn.h postgresql-hll-2.14/include/catalog/pg_partition_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_partition_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_partition_fn.h 2020-12-12 17:06:43.084345935 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_partition_fn.h + * + * + * + * IDENTIFICATION + * src/include/catalog/pg_partition_fn.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_PARTITION_FN_H +#define PG_PARTITION_FN_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/indexing.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/array.h" +#include "utils/builtins.h" +#include "nodes/pg_list.h" +#include "access/htup.h" +#include "storage/lock.h" +#include "access/heapam.h" + +#define MAX_PARTITIONKEY_NUM 4 +#define MAX_PARTITION_NUM 32767 /* update LEN_PARTITION_PREFIX as well ! */ +#define MAX_LH_PARTITION_NUM 64 /* update LEN_LIST/HASH_PARTITION_PREFIX as well ! */ +#define INTERVAL_PARTITION_NAME_PREFIX "sys_p" +#define INTERVAL_PARTITION_NAME_PREFIX_FMT "sys_p%u" +#define INTERVAL_PARTITION_NAME_SUFFIX_LEN 5 /* max length of partitio num */ + +/* + * In start/end syntax, partition name is of form: + * PARTITION_PREFIX_NUM, + * so length of the name prefix must be restricted to: + * NAMEDATALEN (64) - 1 - LENGTH ( "MAX_PARTITION_NUM" ) - 1 + * NOTICE: please update LEN_PARTITION_PREFIX if you modify macro MAX_PARTITION_NUM + */ +#define LEN_PARTITION_PREFIX 57 + +/* + * A suppositional sequence number for partition. + */ +#define ADD_PARTITION_ACTION (MAX_PARTITION_NUM + 1) + +/* + * We acquire a AccessExclusiveLock on ADD_PARTITION_ACTION before we decide + * to add an interval partition to prevent parallel complaints. + */ +#define lockRelationForAddIntervalPartition(relation) \ + LockPartition(RelationGetRelid(relation), ADD_PARTITION_ACTION, \ + AccessExclusiveLock, PARTITION_SEQUENCE_LOCK); + +#define unLockRelationForAddIntervalPartition(relation) \ + UnlockPartition(RelationGetRelid(relation), ADD_PARTITION_ACTION, \ + AccessExclusiveLock, PARTITION_SEQUENCE_LOCK); + +typedef void (*PartitionNameGetPartidCallback) (Oid partitioned_relation, const char *partition_name, Oid partId, + Oid oldPartId, char partition_type, void *callback_arg, LOCKMODE callbackobj_lockMode); +extern void insertPartitionEntry(Relation pg_partition_desc, Partition new_part_desc, Oid new_part_id, + int2vector *pkey, const oidvector *inttablespace, Datum interval, + Datum maxValues, Datum transitionPoint, Datum reloptions, char parttype); +extern bool isPartitionedObject(Oid relid, char relkind, bool missing_ok); +extern bool isPartitionObject(Oid partid, char partkind, bool missing_ok); +extern Oid getPartitionIndexOid(Oid indexid, Oid partitionid); +extern Oid getPartitionIndexTblspcOid(Oid indexid, Oid partitionid); +extern Oid indexPartGetHeapPart(Oid indexPart, bool missing_ok); +extern Oid searchPartitionIndexOid(Oid partitionedIndexid, List *pindex); +extern List *getPartitionObjectIdList(Oid relid, char relkind); +extern Oid partitionNameGetPartitionOid (Oid partitionedTableOid, + const char *partitionName, + char objectType, + LOCKMODE lockMode, + bool missingOk, + bool nowWait, + PartitionNameGetPartidCallback callback, + void *callback_arg, + LOCKMODE callbackobj_lockMode); +extern Oid partitionValuesGetPartitionOid(Relation rel, List *partKeyValueList, LOCKMODE lockMode, bool topClosed, + bool missingOk, bool noWait); +extern List *searchPartitionIndexesByblid(Oid blid); +extern List *searchPgPartitionByParentId(char parttype, Oid parentId); +extern void freePartList(List *l); +extern HeapTuple searchPgPartitionByParentIdCopy(char parttype, Oid parentId); + +#endif + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_partition.h postgresql-hll-2.14/include/catalog/pg_partition.h --- postgresql-hll-2.14_old/include/catalog/pg_partition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_partition.h 2020-12-12 17:06:43.084345935 +0800 @@ -0,0 +1,124 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_partition.h + * + * + * + * IDENTIFICATION + * src/include/catalog/pg_partition.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_PARTITION_H +#define PG_PARTITION_H +#include "catalog/genbki.h" + +#define PartitionRelationId 9016 +#define PartitionRelation_Rowtype_Id 3790 +CATALOG(pg_partition,9016) BKI_ROWTYPE_OID(3790) BKI_SCHEMA_MACRO +{ + NameData relname; + char parttype; + Oid parentid; + int4 rangenum; + int4 intervalnum; + char partstrategy; + Oid relfilenode; + Oid reltablespace; + float8 relpages; + float8 reltuples; + int4 relallvisible; + Oid reltoastrelid; + Oid reltoastidxid; + Oid indextblid; /* index partition's table partition's oid */ + bool indisusable; /* is this index partition useable for insert and select? */ + /*if yes, insert and select should ignore this index partition */ + Oid reldeltarelid; /* if ColStore table, it is not 0 */ + Oid reldeltaidx; + Oid relcudescrelid; /* if ColStore table, it is not 0 */ + Oid relcudescidx; + ShortTransactionId relfrozenxid; + int4 intspnum; +#ifdef CATALOG_VARLEN + int2vector partkey; + oidvector intervaltablespace; + text interval[1]; + text boundaries[1]; + text transit[1]; + text reloptions[1]; /* access-method-specific options */ +#endif + TransactionId relfrozenxid64; +} FormData_pg_partition; +/* Size of fixed part of pg_partition tuples, not counting var-length fields */ +#define PARTITION_TUPLE_SIZE \ + (offsetof(FormData_pg_partition,intspnum) + sizeof(int4)) + +/* Get a more readable name of partition strategy by given abbreviation */ +#define GetPartitionStrategyNameByType(s)\ +(\ + (s == 'r') ? "RANGE-PARTITION" : \ + (s == 'i') ? "INTERVAL-PARTITION" : \ + (s == 'l') ? "LIST-PARTITION" : \ + (s == 'h') ? "HASH-PARTITION" : \ + (s == 'v') ? "VALUE-PARTITION" : "INVALID"\ +)\ + +typedef FormData_pg_partition *Form_pg_partition; + +#define PART_STRATEGY_RANGE 'r' +#define PART_STRATEGY_INTERVAL 'i' +#define PART_STRATEGY_VALUE 'v' +#define PART_STRATEGY_LIST 'l' +#define PART_STRATEGY_HASH 'h' +#define PART_STRATEGY_INVALID 'n' + +#define PART_OBJ_TYPE_PARTED_TABLE 'r' +#define PART_OBJ_TYPE_TOAST_TABLE 't' +#define PART_OBJ_TYPE_TABLE_PARTITION 'p' +#define PART_OBJ_TYPE_INDEX_PARTITION 'x' + +#define Natts_pg_partition 28 +#define Anum_pg_partition_relname 1 +#define Anum_pg_partition_parttype 2 +#define Anum_pg_partition_parentid 3 +#define Anum_pg_partition_rangenum 4 +#define Anum_pg_partition_intervalnum 5 +#define Anum_pg_partition_partstrategy 6 +#define Anum_pg_partition_relfilenode 7 +#define Anum_pg_partition_reltablespace 8 +#define Anum_pg_partition_relpages 9 +#define Anum_pg_partition_reltuples 10 +#define Anum_pg_partition_relallvisible 11 +#define Anum_pg_partition_reltoastrelid 12 +#define Anum_pg_partition_reltoastidxid 13 +#define Anum_pg_partition_indextblid 14 +#define Anum_pg_partition_indisusable 15 +#define Anum_pg_partition_deltarelid 16 +#define Anum_pg_partition_reldeltaidx 17 +#define Anum_pg_partition_relcudescrelid 18 +#define Anum_pg_partition_relcudescidx 19 +#define Anum_pg_partition_relfrozenxid 20 +#define Anum_pg_partition_intspnum 21 +#define Anum_pg_partition_partkey 22 +#define Anum_pg_partition_intablespace 23 +#define Anum_pg_partition_interval 24 +#define Anum_pg_partition_boundaries 25 +#define Anum_pg_partition_transit 26 +#define Anum_pg_partition_reloptions 27 +#define Anum_pg_partition_relfrozenxid64 28 +#endif/*PG_PARTITION_H*/ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_pltemplate.h postgresql-hll-2.14/include/catalog/pg_pltemplate.h --- postgresql-hll-2.14_old/include/catalog/pg_pltemplate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_pltemplate.h 2020-12-12 17:06:43.084345935 +0800 @@ -0,0 +1,84 @@ +/* ------------------------------------------------------------------------- + * + * pg_pltemplate.h + * definition of the system "PL template" relation (pg_pltemplate) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_pltemplate.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PLTEMPLATE_H +#define PG_PLTEMPLATE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_pltemplate definition. cpp turns this into + * typedef struct FormData_pg_pltemplate + * ---------------- + */ +#define PLTemplateRelationId 1136 +#define PLTemplateRelation_Rowtype_Id 11634 + + +CATALOG(pg_pltemplate,1136) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + NameData tmplname; /* name of PL */ + bool tmpltrusted; /* PL is trusted? */ + bool tmpldbacreate; /* PL is installable by db owner? */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text tmplhandler; /* name of call handler function */ + text tmplinline; /* name of anonymous-block handler, or NULL */ + text tmplvalidator; /* name of validator function, or NULL */ + text tmpllibrary; /* path of shared library */ + aclitem tmplacl[1]; /* access privileges for template */ +#endif +} FormData_pg_pltemplate; + +/* ---------------- + * Form_pg_pltemplate corresponds to a pointer to a row with + * the format of pg_pltemplate relation. + * ---------------- + */ +typedef FormData_pg_pltemplate *Form_pg_pltemplate; + +/* ---------------- + * compiler constants for pg_pltemplate + * ---------------- + */ +#define Natts_pg_pltemplate 8 +#define Anum_pg_pltemplate_tmplname 1 +#define Anum_pg_pltemplate_tmpltrusted 2 +#define Anum_pg_pltemplate_tmpldbacreate 3 +#define Anum_pg_pltemplate_tmplhandler 4 +#define Anum_pg_pltemplate_tmplinline 5 +#define Anum_pg_pltemplate_tmplvalidator 6 +#define Anum_pg_pltemplate_tmpllibrary 7 +#define Anum_pg_pltemplate_tmplacl 8 + + +/* ---------------- + * initial contents of pg_pltemplate + * ---------------- + */ +DATA(insert ("plpgsql" t t "plpgsql_call_handler" "plpgsql_inline_handler" "plpgsql_validator" "$libdir/plpgsql" _null_)); +DATA(insert ("pltcl" t t "pltcl_call_handler" _null_ _null_ "$libdir/pltcl" _null_)); +DATA(insert ("pltclu" f f "pltclu_call_handler" _null_ _null_ "$libdir/pltcl" _null_)); +DATA(insert ("plperl" t t "plperl_call_handler" "plperl_inline_handler" "plperl_validator" "$libdir/plperl" _null_)); +DATA(insert ("plperlu" f f "plperlu_call_handler" "plperlu_inline_handler" "plperlu_validator" "$libdir/plperl" _null_)); +DATA(insert ("plpythonu" f f "plpython_call_handler" "plpython_inline_handler" "plpython_validator" "$libdir/plpython2" _null_)); +DATA(insert ("plpython2u" f f "plpython2_call_handler" "plpython2_inline_handler" "plpython2_validator" "$libdir/plpython2" _null_)); +DATA(insert ("plpython3u" f f "plpython3_call_handler" "plpython3_inline_handler" "plpython3_validator" "$libdir/plpython3" _null_)); + +#endif /* PG_PLTEMPLATE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_proc_fn.h postgresql-hll-2.14/include/catalog/pg_proc_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_proc_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_proc_fn.h 2020-12-12 17:06:43.084345935 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * pg_proc_fn.h + * prototypes for functions in catalog/pg_proc.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PROC_FN_H +#define PG_PROC_FN_H + +#include "nodes/pg_list.h" + +extern Oid ProcedureCreate(const char *procedureName, + Oid procNamespace, + bool isOraStyle, + bool replace, + bool returnsSet, + Oid returnType, + Oid proowner, + Oid languageObjectId, + Oid languageValidator, + const char *prosrc, + const char *probin, + bool isAgg, + bool isWindowFunc, + bool security_definer, + bool isLeakProof, + bool isStrict, + char volatility, + oidvector *parameterTypes, + Datum allParameterTypes, + Datum parameterModes, + Datum parameterNames, + List *parameterDefaults, + Datum proconfig, + float4 procost, + float4 prorows, + int2vector *prodefaultargpos, + bool fenced, + bool shippable, + bool package, + bool proIsProcedure); + +extern bool function_parse_error_transpose(const char *prosrc); + +#endif /* PG_PROC_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_proc.h postgresql-hll-2.14/include/catalog/pg_proc.h --- postgresql-hll-2.14_old/include/catalog/pg_proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_proc.h 2020-12-12 17:06:43.084345935 +0800 @@ -0,0 +1,444 @@ +/* +------------------------------------------------------------------------ + * + * pg_proc.h + * definition of the system "procedure" relation (pg_proc) + * along with the relation's initial contents. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc.h + * + * NOTES + * The script catalog/genbki.pl reads this file and generates .bki + * information from the DATA() statements. utils/Gen_fmgrtab.pl + * generates fmgroids.h and fmgrtab.c the same way. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * XXX (eg. #if 0 #endif won't do what you think) + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PROC_H +#define PG_PROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_proc definition. cpp turns this into + * typedef struct FormData_pg_proc + * ---------------- + */ +#define ProcedureRelationId 1255 +#define ProcedureRelation_Rowtype_Id 81 + +#define IsProcRelation(rel) (RelationGetRelid(rel) == ProcedureRelationId) +#define IsProcCache(cache) ((cache)->cc_reloid == ProcedureRelationId) + +CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO +{ + NameData proname; /* procedure name */ + Oid pronamespace; /* OID of namespace containing this proc */ + Oid proowner; /* procedure owner */ + Oid prolang; /* OID of pg_language entry */ + float4 procost; /* estimated execution cost */ + float4 prorows; /* estimated # of rows out (if proretset) */ + Oid provariadic; /* element type of variadic array, or 0 */ + regproc protransform; /* transforms calls to it during planning */ + bool proisagg; /* is it an aggregate? */ + bool proiswindow; /* is it a window function? */ + bool prosecdef; /* security definer */ + bool proleakproof; /* is it a leak-proof function? */ + bool proisstrict; /* strict with respect to NULLs? */ + bool proretset; /* returns a set? */ + char provolatile; /* see PROVOLATILE_ categories below */ + int2 pronargs; /* number of arguments */ + int2 pronargdefaults; /* number of arguments with defaults */ + Oid prorettype; /* OID of result type */ + + /* + * variable-length fields start here, but we allow direct access to + * proargtypes + */ + oidvector proargtypes; /* parameter types (excludes OUT params) */ + +#ifdef CATALOG_VARLEN + Oid proallargtypes[1]; /* all param types (NULL if IN only) */ + char proargmodes[1]; /* parameter modes (NULL if IN only) */ + text proargnames[1]; /* parameter names (NULL if no names) */ + pg_node_tree proargdefaults; /* list of expression trees for argument + * defaults (NULL if none) */ + text prosrc; /* procedure source text */ + text probin; /* secondary procedure info (can be NULL) */ + text proconfig[1]; /* procedure-local GUC settings */ + aclitem proacl[1]; /* access permissions */ + int2vector prodefaultargpos; + bool fencedmode; + bool proshippable; /* if provolatile is not 'i', proshippable will determine if the func can be shipped */ + bool propackage; + char prokind; /* see PROKIND_ categories below */ +#endif +} FormData_pg_proc; + +/* ---------------- + * Form_pg_proc corresponds to a pointer to a tuple with + * the format of pg_proc relation. + * ---------------- + */ +typedef FormData_pg_proc *Form_pg_proc; + +/* ---------------- + * compiler constants for pg_proc + * ---------------- + */ +#define Natts_pg_proc 32 +#define Anum_pg_proc_proname 1 +#define Anum_pg_proc_pronamespace 2 +#define Anum_pg_proc_proowner 3 +#define Anum_pg_proc_prolang 4 +#define Anum_pg_proc_procost 5 +#define Anum_pg_proc_prorows 6 +#define Anum_pg_proc_provariadic 7 +#define Anum_pg_proc_protransform 8 +#define Anum_pg_proc_proisagg 9 +#define Anum_pg_proc_proiswindow 10 +#define Anum_pg_proc_prosecdef 11 +#define Anum_pg_proc_proleakproof 12 +#define Anum_pg_proc_proisstrict 13 +#define Anum_pg_proc_proretset 14 +#define Anum_pg_proc_provolatile 15 +#define Anum_pg_proc_pronargs 16 +#define Anum_pg_proc_pronargdefaults 17 +#define Anum_pg_proc_prorettype 18 +#define Anum_pg_proc_proargtypes 19 +#define Anum_pg_proc_proallargtypes 20 +#define Anum_pg_proc_proargmodes 21 +#define Anum_pg_proc_proargnames 22 +#define Anum_pg_proc_proargdefaults 23 +#define Anum_pg_proc_prosrc 24 +#define Anum_pg_proc_probin 25 +#define Anum_pg_proc_proconfig 26 +#define Anum_pg_proc_proacl 27 +#define Anum_pg_proc_prodefaultargpos 28 +#define Anum_pg_proc_fenced 29 +#define Anum_pg_proc_shippable 30 +#define Anum_pg_proc_package 31 +#define Anum_pg_proc_prokind 32 + +/* proc_oid is only for builitin + * func view shouldn't be included in Natts_pg_proc + */ +#define Anum_pg_proc_oid 33 + +/* ---------------- + * initial contents of pg_proc + * ---------------- + */ + +/* + * Note: every entry in pg_proc.h is expected to have a DESCR() comment, + * except for functions that implement pg_operator.h operators and don't + * have a good reason to be called directly rather than via the operator. + * (If you do expect such a function to be used directly, you should + * duplicate the operator's comment.) initdb will supply suitable default + * comments for functions referenced by pg_operator. + * + * Try to follow the style of existing functions' comments. + * Some recommended conventions: + * "I/O" for typinput, typoutput, typreceive, typsend functions + * "I/O typmod" for typmodin, typmodout functions + * "aggregate transition function" for aggtransfn functions, unless + * they are reasonably useful in their own right + * "aggregate final function" for aggfinalfn functions (likewise) + * "convert srctypename to desttypename" for cast functions + * "less-equal-greater" for B-tree comparison functions + */ + +/* keep the following ordered by OID so that later changes can be made easier */ + /* OIDS 1 - 99 */ +#define TEXTLENOID 1257 +#define EQSELRETURNOID 101 +#define NEQSELRETURNOID 102 +#define ABSTIMEINFUNCOID 240 +#define ABSTIMEOUTFUNCOID 241 +#define RELTIMEINFUNCOID 242 +#define RELTIMEOUTFUNCOID 243 +#define TINTERVALINFUNCOID 246 +#define TINTERVALOUTFUNCOID 247 +#define TIMENOWFUNCOID 250 +#define INT4TOFLOAT8FUNCOID 316 +#define BTINT4CMP_OID 351 +#define RTRIM1FUNCOID 401 +#define NAME2TEXTFUNCOID 406 +#define HASHINT4OID 450 +#define HASHINT8OID 949 +#define HASHTEXTOID 400 +#define GETPGUSERNAMEFUNCOID 710 +#define CURRENTUSERFUNCOID 745 +#define SESSIONUSERFUNCOID 746 +#define ARRAYTOSTRINGFUNCOID 395 +#define ARRAYTOSTRINGNULLFUNCOID 384 +#define ARRAYAGGFUNCOID 2335 +#define POSITIONFUNCOID 849 +#define CURRENTDATABASEFUNCOID 861 +#define CASHINFUNCOID 886 +#define CASHOUTFUNCOID 887 +#define CASH2NUMERICFUNCOID 3823 +#define NUMERIC2CASHFUNCOID 3824 +#define INTEGER2CASHFUNCOID 3811 +#define BIGINT2CASHFUNCOID 3812 +#define HASHBPCHAROID 1080 +#define DATEINFUNCOID 1084 +#define DATEOUTFUNCOID 1085 +#define TIMEINFUNCOID 1143 +#define TIMEOUTFUNCOID 1144 +#define TIMESTAMPTZINFUNCOID 1150 +#define TIMESTAMPTZOUTFUNCOID 1151 +#define INTERVALINFUNCOID 1160 +#define TIMESTAMPTZPARTFUNCOID 1171 +#define INTERVALPARTFUNCOID 1172 +#define DATETIMESTAMPTZFUNCOID 1174 +#define DTAETIME2TIMESTAMPTZFUNCOID 1176 +#define TIMESTAMPTZ2DATEFUNCOID 1178 +#define ABSTIME2DATEFUNCOID 1179 +#define TIMESTAMPTZPLINTERVALFUNCOID 1189 +#define TIMESTAMPTZMIINTERVALFUNCOID 1190 +#define TIMESTAMPTZTRUNCFUNCOID 1217 +#define INTERVALTRUNCFUNCOID 1218 +#define TIMEZPARTFUNCOID 1273 +#define NOWFUNCOID 1299 +#define TRANSACTIONTIMESTAMPFUNCOID 2647 +#define STATEMENTTIMESTAMPFUNCOID 2648 +#define PGSYSTIMESTAMPFUNCOID 3951 +#define OVERLAPSV1FUNCOID 1305 +#define OVERLAPSV2FUNCOID 1306 +#define OVERLAPSV3FUNCOID 1307 +#define TIMESTAMPINFUNCOID 1312 +#define TIMESTAMPOUTFUNCOID 1313 +#define LENGTHFUNCOID 1317 +#define BPLENFUNCOID 1318 +#define TEXTOCTLENFUNCOID 3175 +#define BPOCTLENFUNCOID 3176 +#define SQRTFUNCOID 1344 +#define POWFUNCOID 1346 +#define POWERFUNCOID 1368 +#define TIMETZINFUNCOID 1350 +#define ABSTIME2TIMEFUNCOID 1364 +#define CHARLENFUNCOID 1381 +#define DATEPARTFROMABSTIMEFUNCOID 1382 +#define DATEPARTFROMRELTIMEFUNCOID 1383 +#define DATEPARTFUNCOID 1384 +#define TIMEPARTFUNCOID 1385 +#define AGEDATETOTIMETZFUNCOID 1386 +#define TIMESTAMPTZ2TIMETZFUNCOID 1388 +#define CURRENTSCHEMAFUNCOID 1402 +#define NEXTVALFUNCOID 1574 +#define CURRVALFUNCOID 1575 +#define SETVAL1FUNCOID 1576 +#define SETVAL3FUNCOID 1765 +#define INT4NUMERICFUNCOID 1740 +#define INT8NUMERICFUNCOID 1781 +#define VARCHARINT8FUNCOID 4176 +#define RANDOMFUNCOID 1598 +#define ECEXTENSIONFUNCOID 4244 +#define ECHADOOPFUNCOID 4255 +#define ARCSINEFUNCOID 1600 +#define SINEFUNCOID 1604 +#define COSINEFUNCOID 1605 +#define STRPOSFUNCOID 868 +#define LPADFUNCOID 873 +#define RPADFUNCOID 874 +#define LTRIMFUNCOID 875 +#define RTRIMFUNCOID 876 +#define SUBSTRFUNCOID 877 +#define SUBSTRBWITHLENFUNCOID 3205 +#define SUBSTRBNOLENFUNCOID 3206 +#define LPADPARAFUNCOID 879 +#define RPADPARAFUNCOID 880 +#define LTRIMPARAFUNCOID 881 +#define RTRIMPARAFUNCOID 882 +#define SUBSTRNOLENFUNCOID 883 +#define BTRIMPARAFUNCOID 884 +#define BTRIMFUNCOID 885 +#define SUBSTRINNFUNCOID 3182 +#define SUBSTRINNNOLENFUNCOID 3183 +#define TEXTSUBSTRINGFUNCOID 936 +#define TEXTSUBSTRINGNOLENFUNCOID 937 +#define PGCLIENTENCODINGFUNCOID 810 +#define CONVERTFROMFUNCOID 1714 +#define CONVERTTOFUNCOID 1717 +#define CONVERTFUNCOID 1813 +#define PGCHARTOENCODINGFUNCOID 1264 +#define PGENCODINGTOCHARFUNCOID 1597 +#define PGTYPEOFFUNCOID 1619 +#define BITSUBSTRINGFUNOID 1680 +#define BITPOSITIONFUNCOID 1698 +#define BITSUBSTRINGNOLENFUNCOID 1699 +#define NUMTOFLOAT8FUNCOID 1746 +#define TIMESTAMPTZ2CHARFUNCOID 1770 +#define NUMERIC2CHARFUNCOID 1772 +#define INTEGER2CHARFUNCOID 1773 +#define BIGINT2CHARFUNCOID 1774 +#define FLOAT4TOCHARFUNCOID 1775 +#define FLOAT8TOCHARFUNCOID 1776 +#define TONUMBERFUNCOID 1777 +#define TOTIMESTAMPFUNCOID 1778 +#define TOTIMESTAMPDEFAULTFUNCOID 3207 +#define TODATEFUNCOID 1780 +#define INTERVALTOCHARFUNCOID 1768 +#define CONCATFUNCOID 3058 +#define CONCATWSFUNCOID 3059 +#define ANYTOTEXTFORMATFUNCOID 3539 +#define DEFAULTFORMATFUNCOID 3540 +#define INTERVALACCUMFUNCOID 1843 +#define INTERVALAVGFUNCOID 1844 +#define STRINGAGGTRANSFNFUNCOID 3535 +#define STRINGAGGFUNCOID 3538 +#define BYTEASTRINGAGGFUNCOID 3545 +#define LISTAGGFUNCOID 3552 +#define LISTAGGNOARG2FUNCOID 3554 +#define INT2LISTAGGFUNCOID 3556 +#define INT2LISTAGGNOARG2FUNCOID 3558 +#define INT4LISTAGGFUNCOID 3560 +#define INT4LISTAGGNOARG2FUNCOID 3562 +#define INT8LISTAGGFUNCOID 3564 +#define INT8LISTAGGNOARG2FUNCOID 3566 +#define FLOAT4LISTAGGFUNCOID 3568 +#define FLOAT4LISTAGGNOARG2FUNCOID 3570 +#define FLOAT8LISTAGGFUNCOID 3572 +#define FLOAT8LISTAGGNOARG2FUNCOID 3574 +#define NUMERICLISTAGGFUNCOID 3576 +#define NUMERICLISTAGGNOARG2FUNCOID 3578 +#define DATELISTAGGFUNCOID 3580 +#define DATELISTAGGNOARG2FUNCOID 3582 +#define TIMESTAMPLISTAGGFUNCOID 3584 +#define TIMESTAMPLISTAGGNOARG2FUNCOID 3586 +#define TIMESTAMPTZLISTAGGFUNCOID 3588 +#define TIMESTAMPTZLISTAGGNOARG2FUNCOID 3590 +#define INTERVALLISTAGGFUNCOID 4506 +#define INTERVALLISTAGGNOARG2FUNCOID 4508 +#define PGBACKENDPIDFUNCOID 2026 +#define PGSTATGETBACKENDPIDFUNCOID 1937 +#define TEXTANYCATFUNCOID 2003 +#define ANYTEXTCATFUNCOID 2004 +#define BYTEASUBSTRINGFUNCOID 2012 +#define BYTEASUBSTRINGNOLENOID 2013 +#define BYTEASUBSTRFUNCOID 2085 +#define BYTEASUBSTRNOLENFUNCOID 2086 +#define BYTEAPOSFUNCOID 2014 +#define TIMESTAMPTZ2TIMEFUNCOID 2019 +#define TIMESTAMPTRUNCFUNCOID 2020 +#define TIMESTAMPPARTFUNCOID 2021 +#define ABSTIMETIMESTAMPFUNCOID 2023 +#define TIMESTAMPTZ2TIMESTAMPFUNCOID 2027 +#define TIMESTAMP2TIMESTAMPTZFUNCOID 2028 +#define TIMESTAMP2DATEOID 2029 +#define TIMESTAMP2ABSTIMEFUNCOID 2030 +#define TIMEZONETZFUNCOID 2037 +#define TIMESTAMPHASHOID 2039 +#define TIME2TIMETZFUNCOID 2047 +#define TIMESTAMP2CHARFUNCOID 2049 +#define DEFAULTFORMATTIMESTAMP2CHARFUNCOID 3808 +#define DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID 3813 +#define AGEDATETOTIMEFUNCOID 2059 +#define TEXTREGEXSUBSTRINGOID 2073 +#define SUBSTRINGESCAPEFUNCOID 2074 +#define ANYCOUNTOID 2147 +#define COUNTOID 2803 +#define PGCOLUMNSIZEFUNCOID 1269 +#define ANYARRAYINFUNCOID 2296 +#define DATELTTIMESTAMPTZFUNCOID 2351 +#define DATELETIMESTAMPTZFUNCOID 2352 +#define DATEEQTIMESTAMPTZFUNCOID 2353 +#define DATEGTTIMESTAMPTZFUNCOID 2354 +#define DATEGETIMESTAMPTZFUNCOID 2355 +#define DATENETIMESTAMPTZFUNCOID 2356 +#define DATECMPTIMESTAMPTZFUNCOID 2357 +#define TIMESTAMPTZLTDATEFUNCOID 2377 +#define TIMESTAMPTZLEDATEFUNCOID 2378 +#define TIMESTAMPTZEQDATEFUNCOID 2379 +#define TIMESTAMPTZGTDATEFUNCOID 2380 +#define TIMESTAMPTZGEDATEFUNCOID 2381 +#define TIMESTAMPTZNEDATEFUNCOID 2382 +#define TIMESTAMPTZCMPDATEFUNCOID 2383 +#define TIMESTAMPLTTIMESTAMPTZFUNCOID 2520 +#define TIMESTAMPLETIMESTAMPTZFUNCOID 2521 +#define TIMESTAMPEQTIMESTAMPTZFUNCOID 2522 +#define TIMESTAMPGTTIMESTAMPTZFUNCOID 2523 +#define TIMESTAMPGETIMESTAMPTZFUNCOID 2524 +#define TIMESTAMPNETIMESTAMPTZFUNCOID 2525 +#define TIMESTAMPCMPTIMESTAMPTZFUNCOID 2526 +#define TIMESTAMPTZLTTIMESTAMPFUNCOID 2527 +#define TIMESTAMPTZLETIMESTAMPFUNCOID 2528 +#define TIMESTAMPTZEQTIMESTAMPFUNCOID 2529 +#define TIMESTAMPTZGTTIMESTAMPFUNCOID 2530 +#define TIMESTAMPTZGETIMESTAMPFUNCOID 2531 +#define TIMESTAMPTZNETIMESTAMPFUNCOID 2532 +#define TIMESTAMPTZCMPTIMESTAMPFUNCOID 2533 +#define GENERATESERIESFUNCOID 939 +#define EVERYFUNCOID 2519 +#define INTERVALPLTIMESTAMPTZFUNCOID 2549 +#define LASTVALFUNCOID 2559 +#define XMLAGGFUNCOID 2901 +#define ROWNUMBERFUNCOID 3100 +#define RANKFUNCOID 3101 +#define DENSERANKFUNCOID 3102 +#define INSTR2FUNCOID 3167 +#define INSTR3FUNCOID 3168 +#define INSTR4FUNCOID 3169 +#define SMALLDATETIMEINFUNCOID 9004 +#define SMALLDATETIMEOUTFUNCOID 9006 +#define TODATEDEFAULTFUNCOID 5560 +#define GSENCRYPTAES128FUNCOID 3464 +#define TESTSKEWNESSRETURNTYPE 4048 +#define PERCENTILECONTAGGFUNCOID 4452 +#define MODEAGGFUNCOID 4461 +#define PGCHECKAUTHIDFUNCOID 3228 + +/* + * Symbolic values for prokind column + */ +#define PROKIND_FUNCTION 'f' +#define PROKIND_AGGREGATE 'a' +#define PROKIND_WINDOW 'w' +#define PROKIND_PROCEDURE 'p' + +#define PROC_IS_FUNC(prokind) ((prokind) == PROKIND_FUNCTION) +#define PROC_IS_AGG(prokind) ((prokind) == PROKIND_AGGREGATE) +#define PROC_IS_WIN(prokind) ((prokind) == PROKIND_WINDOW) +#define PROC_IS_PRO(prokind) ((prokind) == PROKIND_PROCEDURE) + +/* + * Symbolic values for provolatile column: these indicate whether the result + * of a function is dependent *only* on the values of its explicit arguments, + * or can change due to outside factors (such as parameter variables or + * table contents). NOTE: functions having side-effects, such as setval(), + * must be labeled volatile to ensure they will not get optimized away, + * even if the actual return value is not changeable. + */ +#define PROVOLATILE_IMMUTABLE 'i' /* never changes for given input */ +#define PROVOLATILE_STABLE 's' /* does not change within a scan */ +#define PROVOLATILE_VOLATILE 'v' /* can change even within a scan */ + +/* + * Symbolic values for proargmodes column. Note that these must agree with + * the FunctionParameterMode enum in parsenodes.h; we declare them here to + * be accessible from either header. + */ +#define PROARGMODE_IN 'i' +#define PROARGMODE_OUT 'o' +#define PROARGMODE_INOUT 'b' +#define PROARGMODE_VARIADIC 'v' +#define PROARGMODE_TABLE 't' + +#define PROC_LIB_PATH "$libdir/" +#define PORC_PLUGIN_LIB_PATH "$libdir/pg_plugin/" +#define PORC_SRC_LIB_PATH "$libdir/proc_srclib/" + +#define OID_REGEXP_SPLIT_TO_TABLE 2765 +#define OID_REGEXP_SPLIT_TO_TABLE_NO_FLAG 2766 + +#endif /* PG_PROC_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_proc.h_for_llt postgresql-hll-2.14/include/catalog/pg_proc.h_for_llt --- postgresql-hll-2.14_old/include/catalog/pg_proc.h_for_llt 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_proc.h_for_llt 2020-12-12 17:06:43.088345987 +0800 @@ -0,0 +1,5739 @@ +/*------------------------------------------------------------------------- + * + * pg_proc.h + * definition of the system "procedure" relation (pg_proc) + * along with the relation's initial contents. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc.h + * + * NOTES + * The script catalog/genbki.pl reads this file and generates .bki + * information from the DATA() statements. utils/Gen_fmgrtab.pl + * generates fmgroids.h and fmgrtab.c the same way. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * XXX (eg. #if 0 #endif won't do what you think) + * + *------------------------------------------------------------------------- + */ +#ifndef PG_PROC_H +#define PG_PROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_proc definition. cpp turns this into + * typedef struct FormData_pg_proc + * ---------------- + */ +#define ProcedureRelationId 1255 +#define ProcedureRelation_Rowtype_Id 81 + +CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO +{ + NameData proname; /* procedure name */ + Oid pronamespace; /* OID of namespace containing this proc */ + Oid proowner; /* procedure owner */ + Oid prolang; /* OID of pg_language entry */ + float4 procost; /* estimated execution cost */ + float4 prorows; /* estimated # of rows out (if proretset) */ + Oid provariadic; /* element type of variadic array, or 0 */ + regproc protransform; /* transforms calls to it during planning */ + bool proisagg; /* is it an aggregate? */ + bool proiswindow; /* is it a window function? */ + bool prosecdef; /* security definer */ + bool proleakproof; /* is it a leak-proof function? */ + bool proisstrict; /* strict with respect to NULLs? */ + bool proretset; /* returns a set? */ + char provolatile; /* see PROVOLATILE_ categories below */ + int2 pronargs; /* number of arguments */ + int2 pronargdefaults; /* number of arguments with defaults */ + Oid prorettype; /* OID of result type */ + + /* + * variable-length fields start here, but we allow direct access to + * proargtypes + */ + oidvector proargtypes; /* parameter types (excludes OUT params) */ + +#ifdef CATALOG_VARLEN + Oid proallargtypes[1]; /* all param types (NULL if IN only) */ + char proargmodes[1]; /* parameter modes (NULL if IN only) */ + text proargnames[1]; /* parameter names (NULL if no names) */ + pg_node_tree proargdefaults;/* list of expression trees for argument + * defaults (NULL if none) */ + text prosrc; /* procedure source text */ + text probin; /* secondary procedure info (can be NULL) */ + text proconfig[1]; /* procedure-local GUC settings */ + aclitem proacl[1]; /* access permissions */ + int2vector prodefaultargpos; +#endif + bool fencedmode; +} FormData_pg_proc; + +/* ---------------- + * Form_pg_proc corresponds to a pointer to a tuple with + * the format of pg_proc relation. + * ---------------- + */ +typedef FormData_pg_proc *Form_pg_proc; + +/* ---------------- + * compiler constants for pg_proc + * ---------------- + */ +#define Natts_pg_proc 29 +#define Anum_pg_proc_proname 1 +#define Anum_pg_proc_pronamespace 2 +#define Anum_pg_proc_proowner 3 +#define Anum_pg_proc_prolang 4 +#define Anum_pg_proc_procost 5 +#define Anum_pg_proc_prorows 6 +#define Anum_pg_proc_provariadic 7 +#define Anum_pg_proc_protransform 8 +#define Anum_pg_proc_proisagg 9 +#define Anum_pg_proc_proiswindow 10 +#define Anum_pg_proc_prosecdef 11 +#define Anum_pg_proc_proleakproof 12 +#define Anum_pg_proc_proisstrict 13 +#define Anum_pg_proc_proretset 14 +#define Anum_pg_proc_provolatile 15 +#define Anum_pg_proc_pronargs 16 +#define Anum_pg_proc_pronargdefaults 17 +#define Anum_pg_proc_prorettype 18 +#define Anum_pg_proc_proargtypes 19 +#define Anum_pg_proc_proallargtypes 20 +#define Anum_pg_proc_proargmodes 21 +#define Anum_pg_proc_proargnames 22 +#define Anum_pg_proc_proargdefaults 23 +#define Anum_pg_proc_prosrc 24 +#define Anum_pg_proc_probin 25 +#define Anum_pg_proc_proconfig 26 +#define Anum_pg_proc_proacl 27 +#define Anum_pg_proc_prodefaultargpos 28 +#define Anum_pg_proc_fenced 29 + + +/* ---------------- + * initial contents of pg_proc + * ---------------- + */ + +/* + * Note: every entry in pg_proc.h is expected to have a DESCR() comment, + * except for functions that implement pg_operator.h operators and don't + * have a good reason to be called directly rather than via the operator. + * (If you do expect such a function to be used directly, you should + * duplicate the operator's comment.) initdb will supply suitable default + * comments for functions referenced by pg_operator. + * + * Try to follow the style of existing functions' comments. + * Some recommended conventions: + * "I/O" for typinput, typoutput, typreceive, typsend functions + * "I/O typmod" for typmodin, typmodout functions + * "aggregate transition function" for aggtransfn functions, unless + * they are reasonably useful in their own right + * "aggregate final function" for aggfinalfn functions (likewise) + * "convert srctypename to desttypename" for cast functions + * "less-equal-greater" for B-tree comparison functions + */ + +/* keep the following ordered by OID so that later changes can be made easier */ + +/* OIDS 1 - 99 */ + +DATA(insert OID = 1242 ( boolin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "2275" _null_ _null_ _null_ _null_ boolin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1243 ( boolout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "16" _null_ _null_ _null_ _null_ boolout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1244 ( byteain PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ byteain _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 31 ( byteaout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ byteaout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + + +DATA(insert OID = 4035 ( rawin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ rawin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4036 ( rawout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ rawout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 1245 ( charin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "2275" _null_ _null_ _null_ _null_ charin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 33 ( charout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "18" _null_ _null_ _null_ _null_ charout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 34 ( namein PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "2275" _null_ _null_ _null_ _null_ namein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 35 ( nameout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "19" _null_ _null_ _null_ _null_ nameout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 38 ( int2in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "2275" _null_ _null_ _null_ _null_ int2in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 39 ( int2out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "21" _null_ _null_ _null_ _null_ int2out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5541 ( int1in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "2275" _null_ _null_ _null_ _null_ int1in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5542 ( int1out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "5545" _null_ _null_ _null_ _null_ int1out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 40 ( int2vectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 22 "2275" _null_ _null_ _null_ _null_ int2vectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 41 ( int2vectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "22" _null_ _null_ _null_ _null_ int2vectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 42 ( int4in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2275" _null_ _null_ _null_ _null_ int4in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 43 ( int4out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ int4out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 44 ( regprocin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 24 "2275" _null_ _null_ _null_ _null_ regprocin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 45 ( regprocout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "24" _null_ _null_ _null_ _null_ regprocout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 46 ( textin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2275" _null_ _null_ _null_ _null_ textin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 47 ( textout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "25" _null_ _null_ _null_ _null_ textout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 48 ( tidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 27 "2275" _null_ _null_ _null_ _null_ tidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 49 ( tidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "27" _null_ _null_ _null_ _null_ tidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 50 ( xidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 28 "2275" _null_ _null_ _null_ _null_ xidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 51 ( xidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "28" _null_ _null_ _null_ _null_ xidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 52 ( cidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 29 "2275" _null_ _null_ _null_ _null_ cidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 53 ( cidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "29" _null_ _null_ _null_ _null_ cidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 54 ( oidvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 30 "2275" _null_ _null_ _null_ _null_ oidvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 55 ( oidvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "30" _null_ _null_ _null_ _null_ oidvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 56 ( boollt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boollt _null_ _null_ _null_ "" f)); +DATA(insert OID = 57 ( boolgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 60 ( booleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ booleq _null_ _null_ _null_ "" f)); +DATA(insert OID = 61 ( chareq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ chareq _null_ _null_ _null_ "" f)); +DATA(insert OID = 62 ( nameeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ nameeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 63 ( int2eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 64 ( int2lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 65 ( int4eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 66 ( int4lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 67 ( texteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 68 ( xideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "28 28" _null_ _null_ _null_ _null_ xideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 69 ( cideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "29 29" _null_ _null_ _null_ _null_ cideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 70 ( charne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1246 ( charlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 72 ( charle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charle _null_ _null_ _null_ "" f)); +DATA(insert OID = 73 ( chargt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ chargt _null_ _null_ _null_ "" f)); +DATA(insert OID = 74 ( charge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charge _null_ _null_ _null_ "" f)); +DATA(insert OID = 77 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "18" _null_ _null_ _null_ _null_ chartoi4 _null_ _null_ _null_ "" f)); +DESCR("convert char to int4"); +DATA(insert OID = 78 ( char PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "23" _null_ _null_ _null_ _null_ i4tochar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to char"); +DATA(insert OID = 5547 ( int1eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1eq _null_ _null_ _null_ "" f)); +DESCR("equal"); +DATA(insert OID = 5508 ( int1ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1ne _null_ _null_ _null_ "" f)); +DESCR("not equal"); +DATA(insert OID = 5509 ( int1lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1lt _null_ _null_ _null_ "" f)); +DESCR("less than"); +DATA(insert OID = 5510 ( int1le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1le _null_ _null_ _null_ "" f)); +DESCR("less than or equal"); +DATA(insert OID = 5511 ( int1gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1gt _null_ _null_ _null_ "" f)); +DESCR("greater than"); +DATA(insert OID = 5512 ( int1ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1ge _null_ _null_ _null_ "" f)); +DESCR("greater than or equal"); +DATA(insert OID = 5519 ( int1cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 5545" _null_ _null_ _null_ _null_ int1cmp _null_ _null_ _null_ "" f)); +DESCR("int1"); +DATA(insert OID = 79 ( nameregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1252 ( nameregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1254 ( textregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1256 ( textregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1257 ( textlen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("length"); +#define TEXTLENOID 1257 +DATA(insert OID = 1258 ( textcat PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ textcat _null_ _null_ _null_ "" f)); + +DATA(insert OID = 84 ( boolne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolne _null_ _null_ _null_ "" f)); +DATA(insert OID = 89 ( version PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pgsql_version _null_ _null_ _null_ "" f)); +DESCR("PostgreSQL version string"); +#ifdef PGXC +DATA(insert OID = 90 ( pgxc_version PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pgxc_version _null_ _null_ _null_ "" f)); +DESCR("Postgres-XC version string"); +#endif + +/* OIDS 100 - 199 */ + +DATA(insert OID = 101 ( eqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ eqsel _null_ _null_ _null_ "" f)); +#define EQSELRETURNOID 101 +DESCR("restriction selectivity of = and related operators"); +DATA(insert OID = 102 ( neqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ neqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of <> and related operators"); +#define NEQSELRETURNOID 102 +DATA(insert OID = 103 ( scalarltsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ scalarltsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of < and related operators on scalar datatypes"); +DATA(insert OID = 104 ( scalargtsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ scalargtsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of > and related operators on scalar datatypes"); +DATA(insert OID = 105 ( eqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ eqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of = and related operators"); +DATA(insert OID = 106 ( neqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ neqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of <> and related operators"); +DATA(insert OID = 107 ( scalarltjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ scalarltjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of < and related operators on scalar datatypes"); +DATA(insert OID = 108 ( scalargtjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ scalargtjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of > and related operators on scalar datatypes"); + +DATA(insert OID = 109 ( unknownin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 705 "2275" _null_ _null_ _null_ _null_ unknownin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 110 ( unknownout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "705" _null_ _null_ _null_ _null_ unknownout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 111 ( numeric_fac PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ numeric_fac _null_ _null_ _null_ "" f)); + +DATA(insert OID = 115 ( box_above_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_above_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 116 ( box_below_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_below_eq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 117 ( point_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "2275" _null_ _null_ _null_ _null_ point_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 118 ( point_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "600" _null_ _null_ _null_ _null_ point_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 119 ( lseg_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "2275" _null_ _null_ _null_ _null_ lseg_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 120 ( lseg_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "601" _null_ _null_ _null_ _null_ lseg_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 121 ( path_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "2275" _null_ _null_ _null_ _null_ path_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 122 ( path_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "602" _null_ _null_ _null_ _null_ path_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 123 ( box_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "2275" _null_ _null_ _null_ _null_ box_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 124 ( box_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "603" _null_ _null_ _null_ _null_ box_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 125 ( box_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 126 ( box_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 127 ( box_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 128 ( box_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 129 ( box_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 130 ( box_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 131 ( point_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 132 ( point_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 133 ( point_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 134 ( point_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 135 ( point_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 136 ( on_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 603" _null_ _null_ _null_ _null_ on_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 137 ( on_ppath PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 602" _null_ _null_ _null_ _null_ on_ppath _null_ _null_ _null_ "" f)); +DATA(insert OID = 138 ( box_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 139 ( areasel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ areasel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for area-comparison operators"); +DATA(insert OID = 140 ( areajoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ areajoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for area-comparison operators"); +DATA(insert OID = 141 ( int4mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 144 ( int4ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 145 ( int2ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 146 ( int2gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 147 ( int4gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 148 ( int2le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2le _null_ _null_ _null_ "" f)); +DATA(insert OID = 149 ( int4le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4le _null_ _null_ _null_ "" f)); +DATA(insert OID = 150 ( int4ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 151 ( int2ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 152 ( int2mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 153 ( int2div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 21" _null_ _null_ _null_ _null_ int2div _null_ _null_ _null_ "" f)); +DATA(insert OID = 154 ( int4div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 23" _null_ _null_ _null_ _null_ int4div _null_ _null_ _null_ "" f)); +DATA(insert OID = 155 ( int2mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 156 ( int4mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 157 ( textne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textne _null_ _null_ _null_ "" f)); +DATA(insert OID = 158 ( int24eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 159 ( int42eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 160 ( int24lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 161 ( int42lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 162 ( int24gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 163 ( int42gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 164 ( int24ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 165 ( int42ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 166 ( int24le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24le _null_ _null_ _null_ "" f)); +DATA(insert OID = 167 ( int42le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42le _null_ _null_ _null_ "" f)); +DATA(insert OID = 168 ( int24ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 169 ( int42ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 170 ( int24mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 171 ( int42mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 172 ( int24div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 23" _null_ _null_ _null_ _null_ int24div _null_ _null_ _null_ "" f)); +DATA(insert OID = 173 ( int42div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 21" _null_ _null_ _null_ _null_ int42div _null_ _null_ _null_ "" f)); +DATA(insert OID = 176 ( int2pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 177 ( int4pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 178 ( int24pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 179 ( int42pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 180 ( int2mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 181 ( int4mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 182 ( int24mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 183 ( int42mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 6109 ( int1pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1pl _null_ _null_ _null_ "" f)); +DESCR("int1 plus"); +DATA(insert OID = 6110 ( int1mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mi _null_ _null_ _null_ "" f)); +DESCR("int1 minus"); +DATA(insert OID = 6111 ( int1mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mul _null_ _null_ _null_ "" f)); +DESCR("int1 multiply"); +DATA(insert OID = 6112 ( int1div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1div _null_ _null_ _null_ "" f)); +DESCR("int1 divid"); +DATA(insert OID = 184 ( oideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 185 ( oidne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidne _null_ _null_ _null_ "" f)); +DATA(insert OID = 186 ( box_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 187 ( box_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 188 ( box_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 189 ( box_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 190 ( box_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 191 ( box_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 192 ( box_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 193 ( box_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 600" _null_ _null_ _null_ _null_ box_contain_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 195 ( pg_node_tree_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 194 "2275" _null_ _null_ _null_ _null_ pg_node_tree_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 196 ( pg_node_tree_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "194" _null_ _null_ _null_ _null_ pg_node_tree_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 197 ( pg_node_tree_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 194 "2281" _null_ _null_ _null_ _null_ pg_node_tree_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 198 ( pg_node_tree_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "194" _null_ _null_ _null_ _null_ pg_node_tree_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* OIDS 200 - 299 */ + +DATA(insert OID = 200 ( float4in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "2275" _null_ _null_ _null_ _null_ float4in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 201 ( float4out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "700" _null_ _null_ _null_ _null_ float4out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 202 ( float4mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 203 ( float4div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4div _null_ _null_ _null_ "" f)); +DATA(insert OID = 204 ( float4pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 205 ( float4mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 206 ( float4um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4um _null_ _null_ _null_ "" f)); +DATA(insert OID = 207 ( float4abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 208 ( float4_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 700" _null_ _null_ _null_ _null_ float4_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 209 ( float4larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 211 ( float4smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 212 ( int4um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4um _null_ _null_ _null_ "" f)); +DATA(insert OID = 213 ( int2um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2um _null_ _null_ _null_ "" f)); +DATA(insert OID = 6108 ( int1um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "5545" _null_ _null_ _null_ _null_ int1um _null_ _null_ _null_ "" f)); +DESCR("int1um"); +DATA(insert OID = 214 ( float8in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "2275" _null_ _null_ _null_ _null_ float8in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 215 ( float8out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "701" _null_ _null_ _null_ _null_ float8out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 216 ( float8mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 217 ( float8div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8div _null_ _null_ _null_ "" f)); +DATA(insert OID = 218 ( float8pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 219 ( float8mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 220 ( float8um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8um _null_ _null_ _null_ "" f)); +DATA(insert OID = 221 ( float8abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 222 ( float8_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 701" _null_ _null_ _null_ _null_ float8_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 223 ( float8larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 224 ( float8smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 225 ( lseg_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "601" _null_ _null_ _null_ _null_ lseg_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 226 ( path_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "602" _null_ _null_ _null_ _null_ path_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 227 ( poly_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "604" _null_ _null_ _null_ _null_ poly_center _null_ _null_ _null_ "" f)); + +DATA(insert OID = 228 ( dround PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dround _null_ _null_ _null_ "" f)); +DESCR("round to nearest integer"); +DATA(insert OID = 229 ( dtrunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtrunc _null_ _null_ _null_ "" f)); +DESCR("truncate to integer"); +DATA(insert OID = 2308 ( ceil PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2320 ( ceiling PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2309 ( floor PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dfloor _null_ _null_ _null_ "" f)); +DESCR("nearest integer <= value"); +DATA(insert OID = 2310 ( sign PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsign _null_ _null_ _null_ "" f)); +DESCR("sign of value"); +DATA(insert OID = 230 ( dsqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsqrt _null_ _null_ _null_ "" f)); +DATA(insert OID = 231 ( dcbrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcbrt _null_ _null_ _null_ "" f)); +DATA(insert OID = 232 ( dpow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DATA(insert OID = 233 ( dexp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dexp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 234 ( dlog1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog1 _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 235 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "21" _null_ _null_ _null_ _null_ i2tod _null_ _null_ _null_ "" f)); +DESCR("convert int2 to float8"); +DATA(insert OID = 236 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "21" _null_ _null_ _null_ _null_ i2tof _null_ _null_ _null_ "" f)); +DESCR("convert int2 to float4"); +DATA(insert OID = 237 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "701" _null_ _null_ _null_ _null_ dtoi2 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int2"); +DATA(insert OID = 238 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "700" _null_ _null_ _null_ _null_ ftoi2 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int2"); +DATA(insert OID = 239 ( line_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "628 628" _null_ _null_ _null_ _null_ line_distance _null_ _null_ _null_ "" f)); + +DATA(insert OID = 240 ( abstimein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 702 "2275" _null_ _null_ _null_ _null_ abstimein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ABSTIMEINFUNCOID 240 +DATA(insert OID = 241 ( abstimeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "702" _null_ _null_ _null_ _null_ abstimeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ABSTIMEOUTFUNCOID 241 +DATA(insert OID = 242 ( reltimein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 703 "2275" _null_ _null_ _null_ _null_ reltimein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define RELTIMEINFUNCOID 242 +DATA(insert OID = 243 ( reltimeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "703" _null_ _null_ _null_ _null_ reltimeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define RELTIMEOUTFUNCOID 243 + +DATA(insert OID = 244 ( timepl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 702 "702 703" _null_ _null_ _null_ _null_ timepl _null_ _null_ _null_ "" f)); +DATA(insert OID = 245 ( timemi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 702 "702 703" _null_ _null_ _null_ _null_ timemi _null_ _null_ _null_ "" f)); +DATA(insert OID = 246 ( tintervalin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 704 "2275" _null_ _null_ _null_ _null_ tintervalin _null_ _null_ _null_ "" f)); +#define TINTERVALINFUNCOID 246 +DESCR("I/O"); +DATA(insert OID = 247 ( tintervalout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "704" _null_ _null_ _null_ _null_ tintervalout _null_ _null_ _null_ "" f)); +#define TINTERVALOUTFUNCOID 247 +DESCR("I/O"); +DATA(insert OID = 248 ( intinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "702 704" _null_ _null_ _null_ _null_ intinterval _null_ _null_ _null_ "" f)); +DATA(insert OID = 249 ( tintervalrel PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "704" _null_ _null_ _null_ _null_ tintervalrel _null_ _null_ _null_ "" f)); +DESCR("tinterval to reltime"); +DATA(insert OID = 250 ( timenow PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 702 "" _null_ _null_ _null_ _null_ timenow _null_ _null_ _null_ "" f)); +DESCR("current date and time (abstime)"); +DATA(insert OID = 251 ( abstimeeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimeeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 252 ( abstimene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimene _null_ _null_ _null_ "" f)); +DATA(insert OID = 253 ( abstimelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 254 ( abstimegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 255 ( abstimele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimele _null_ _null_ _null_ "" f)); +DATA(insert OID = 256 ( abstimege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimege _null_ _null_ _null_ "" f)); +DATA(insert OID = 257 ( reltimeeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimeeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 258 ( reltimene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimene _null_ _null_ _null_ "" f)); +DATA(insert OID = 259 ( reltimelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 260 ( reltimegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 261 ( reltimele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimele _null_ _null_ _null_ "" f)); +DATA(insert OID = 262 ( reltimege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimege _null_ _null_ _null_ "" f)); +DATA(insert OID = 263 ( tintervalsame PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalsame _null_ _null_ _null_ "" f)); +DATA(insert OID = 264 ( tintervalct PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalct _null_ _null_ _null_ "" f)); +DATA(insert OID = 265 ( tintervalov PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalov _null_ _null_ _null_ "" f)); +DATA(insert OID = 266 ( tintervalleneq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervalleneq _null_ _null_ _null_ "" f)); +DATA(insert OID = 267 ( tintervallenne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenne _null_ _null_ _null_ "" f)); +DATA(insert OID = 268 ( tintervallenlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 269 ( tintervallengt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallengt _null_ _null_ _null_ "" f)); +DATA(insert OID = 270 ( tintervallenle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenle _null_ _null_ _null_ "" f)); +DATA(insert OID = 271 ( tintervallenge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenge _null_ _null_ _null_ "" f)); +DATA(insert OID = 272 ( tintervalstart PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "704" _null_ _null_ _null_ _null_ tintervalstart _null_ _null_ _null_ "" f)); +DATA(insert OID = 273 ( tintervalend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "704" _null_ _null_ _null_ _null_ tintervalend _null_ _null_ _null_ "" f)); +DESCR("end of interval"); +DATA(insert OID = 274 ( timeofday PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ timeofday _null_ _null_ _null_ "" f)); +DESCR("current date and time - increments during transactions"); +DATA(insert OID = 275 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "702" _null_ _null_ _null_ _null_ abstime_finite _null_ _null_ _null_ "" f)); +DESCR("finite abstime?"); + +DATA(insert OID = 277 ( inter_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 628" _null_ _null_ _null_ _null_ inter_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 278 ( inter_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 603" _null_ _null_ _null_ _null_ inter_lb _null_ _null_ _null_ "" f)); + +DATA(insert OID = 279 ( float48mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 280 ( float48div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48div _null_ _null_ _null_ "" f)); +DATA(insert OID = 281 ( float48pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 282 ( float48mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 283 ( float84mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 284 ( float84div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84div _null_ _null_ _null_ "" f)); +DATA(insert OID = 285 ( float84pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 286 ( float84mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84mi _null_ _null_ _null_ "" f)); + +DATA(insert OID = 287 ( float4eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 288 ( float4ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 289 ( float4lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 290 ( float4le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4le _null_ _null_ _null_ "" f)); +DATA(insert OID = 291 ( float4gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 292 ( float4ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 293 ( float8eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 294 ( float8ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 295 ( float8lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 296 ( float8le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8le _null_ _null_ _null_ "" f)); +DATA(insert OID = 297 ( float8gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 298 ( float8ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 299 ( float48eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48eq _null_ _null_ _null_ "" f)); + +/* OIDS 300 - 399 */ + +DATA(insert OID = 300 ( float48ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 301 ( float48lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 302 ( float48le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48le _null_ _null_ _null_ "" f)); +DATA(insert OID = 303 ( float48gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 304 ( float48ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 305 ( float84eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 306 ( float84ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 307 ( float84lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 308 ( float84le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84le _null_ _null_ _null_ "" f)); +DATA(insert OID = 309 ( float84gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 310 ( float84ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 320 ( width_bucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "701 701 701 23" _null_ _null_ _null_ _null_ width_bucket_float8 _null_ _null_ _null_ "" f)); +DESCR("bucket number of operand in equidepth histogram"); + +DATA(insert OID = 311 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "700" _null_ _null_ _null_ _null_ ftod _null_ _null_ _null_ "" f)); +DESCR("convert float4 to float8"); +DATA(insert OID = 312 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "701" _null_ _null_ _null_ _null_ dtof _null_ _null_ _null_ "" f)); +DESCR("convert float8 to float4"); +DATA(insert OID = 313 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "21" _null_ _null_ _null_ _null_ i2toi4 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int4"); +DATA(insert OID = 314 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "23" _null_ _null_ _null_ _null_ i4toi2 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int2"); +DATA(insert OID = 315 ( int2vectoreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "22 22" _null_ _null_ _null_ _null_ int2vectoreq _null_ _null_ _null_ "" f)); +DATA(insert OID = 316 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "23" _null_ _null_ _null_ _null_ i4tod _null_ _null_ _null_ "" f)); +DESCR("convert int4 to float8"); +#define INT4TOFLOAT8FUNCOID 316 +DATA(insert OID = 317 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "701" _null_ _null_ _null_ _null_ dtoi4 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int4"); +DATA(insert OID = 318 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "23" _null_ _null_ _null_ _null_ i4tof _null_ _null_ _null_ "" f)); +DESCR("convert int4 to float4"); +DATA(insert OID = 319 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "700" _null_ _null_ _null_ _null_ ftoi4 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int4"); + +DATA(insert OID = 330 ( btgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ btgettuple _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 636 ( btgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ btgetbitmap _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 331 ( btinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btinsert _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 333 ( btbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ btbeginscan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 334 ( btrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btrescan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 335 ( btendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btendscan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 336 ( btmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btmarkpos _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 337 ( btrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btrestrpos _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 3184 ( btmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btmerge _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 338 ( btbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ btbuild _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 328 ( btbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btbuildempty _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 332 ( btbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ btbulkdelete _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 972 ( btvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ btvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 276 ( btcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ btcanreturn _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 1268 ( btcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btcostestimate _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 2785 ( btoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ btoptions _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); + +DATA(insert OID = 339 ( poly_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 340 ( poly_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 341 ( poly_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 342 ( poly_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 343 ( poly_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 344 ( poly_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 345 ( poly_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 346 ( poly_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 347 ( poly_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "2275" _null_ _null_ _null_ _null_ poly_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 348 ( poly_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "604" _null_ _null_ _null_ _null_ poly_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 350 ( btint2cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 21" _null_ _null_ _null_ _null_ btint2cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3129 ( btint2sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint2sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 351 ( btint4cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ btint4cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3130 ( btint4sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint4sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 842 ( btint8cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 20" _null_ _null_ _null_ _null_ btint8cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3131 ( btint8sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint8sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 354 ( btfloat4cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 700" _null_ _null_ _null_ _null_ btfloat4cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3132 ( btfloat4sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btfloat4sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 355 ( btfloat8cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 701" _null_ _null_ _null_ _null_ btfloat8cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3133 ( btfloat8sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btfloat8sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 356 ( btoidcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 26" _null_ _null_ _null_ _null_ btoidcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3134 ( btoidsortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btoidsortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 404 ( btoidvectorcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 30" _null_ _null_ _null_ _null_ btoidvectorcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 357 ( btabstimecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 702" _null_ _null_ _null_ _null_ btabstimecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 358 ( btcharcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 18" _null_ _null_ _null_ _null_ btcharcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 359 ( btnamecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 19" _null_ _null_ _null_ _null_ btnamecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3135 ( btnamesortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btnamesortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 360 ( bttextcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ bttextcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3255 ( bttextsortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bttextsortsupport _null_ _null_ _null_ ""f)); +DESCR("sort support"); +DATA(insert OID = 377 ( cash_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 790" _null_ _null_ _null_ _null_ cash_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 380 ( btreltimecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 703" _null_ _null_ _null_ _null_ btreltimecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 381 ( bttintervalcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "704 704" _null_ _null_ _null_ _null_ bttintervalcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 382 ( btarraycmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 2277" _null_ _null_ _null_ _null_ btarraycmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 361 ( lseg_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 601" _null_ _null_ _null_ _null_ lseg_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 362 ( lseg_interpt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 601" _null_ _null_ _null_ _null_ lseg_interpt _null_ _null_ _null_ "" f)); +DATA(insert OID = 363 ( dist_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 601" _null_ _null_ _null_ _null_ dist_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 364 ( dist_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 603" _null_ _null_ _null_ _null_ dist_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 365 ( dist_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 603" _null_ _null_ _null_ _null_ dist_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 366 ( close_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 601" _null_ _null_ _null_ _null_ close_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 367 ( close_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 603" _null_ _null_ _null_ _null_ close_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 368 ( close_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 603" _null_ _null_ _null_ _null_ close_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 369 ( on_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 601" _null_ _null_ _null_ _null_ on_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 370 ( path_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "602 602" _null_ _null_ _null_ _null_ path_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 371 ( dist_ppath PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 602" _null_ _null_ _null_ _null_ dist_ppath _null_ _null_ _null_ "" f)); +DATA(insert OID = 372 ( on_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 603" _null_ _null_ _null_ _null_ on_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 373 ( inter_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 603" _null_ _null_ _null_ _null_ inter_sb _null_ _null_ _null_ "" f)); + +/* OIDS 400 - 499 */ + +DATA(insert OID = 401 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1042" _null_ _null_ _null_ _null_ rtrim1 _null_ _null_ _null_ "" f)); +DESCR("convert char(n) to text"); +#define RTRIM1FUNCOID 401 +DATA(insert OID = 406 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "19" _null_ _null_ _null_ _null_ name_text _null_ _null_ _null_ "" f)); +DESCR("convert name to text"); +DATA(insert OID = 407 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "25" _null_ _null_ _null_ _null_ text_name _null_ _null_ _null_ "" f)); +DESCR("convert text to name"); +DATA(insert OID = 408 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "19" _null_ _null_ _null_ _null_ name_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert name to char(n)"); +DATA(insert OID = 409 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "1042" _null_ _null_ _null_ _null_ bpchar_name _null_ _null_ _null_ "" f)); +DESCR("convert char(n) to name"); + +DATA(insert OID = 440 ( hashgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ hashgettuple _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 637 ( hashgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ hashgetbitmap _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 441 ( hashinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashinsert _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 443 ( hashbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ hashbeginscan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 444 ( hashrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashrescan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 445 ( hashendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashendscan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 446 ( hashmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashmarkpos _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 447 ( hashrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashrestrpos _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 3185 ( hashmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashmerge _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 448 ( hashbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ hashbuild _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 327 ( hashbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashbuildempty _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 442 ( hashbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashbulkdelete _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 425 ( hashvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ hashvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 438 ( hashcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashcostestimate _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 2786 ( hashoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ hashoptions _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 5520 ( hashint1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "5545" _null_ _null_ _null_ _null_ hashint1 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 449 ( hashint2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "21" _null_ _null_ _null_ _null_ hashint2 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 450 ( hashint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ hashint4 _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHINT4OID 450 +DATA(insert OID = 949 ( hashint8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "20" _null_ _null_ _null_ _null_ hashint8 _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHINT8OID 949 +DATA(insert OID = 451 ( hashfloat4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "700" _null_ _null_ _null_ _null_ hashfloat4 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 452 ( hashfloat8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "701" _null_ _null_ _null_ _null_ hashfloat8 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 453 ( hashoid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "26" _null_ _null_ _null_ _null_ hashoid _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 454 ( hashchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "18" _null_ _null_ _null_ _null_ hashchar _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 455 ( hashname PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "19" _null_ _null_ _null_ _null_ hashname _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 400 ( hashtext PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ hashtext _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHTEXTOID 400 +DATA(insert OID = 456 ( hashvarlena PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2281" _null_ _null_ _null_ _null_ hashvarlena _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 457 ( hashoidvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "30" _null_ _null_ _null_ _null_ hashoidvector _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 329 ( hash_aclitem PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1033" _null_ _null_ _null_ _null_ hash_aclitem _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 398 ( hashint2vector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "22" _null_ _null_ _null_ _null_ hashint2vector _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 399 ( hashmacaddr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "829" _null_ _null_ _null_ _null_ hashmacaddr _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 422 ( hashinet PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ hashinet _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 432 ( hash_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1700" _null_ _null_ _null_ _null_ hash_numeric _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 458 ( text_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ text_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 459 ( text_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ text_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 460 ( int8in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2275" _null_ _null_ _null_ _null_ int8in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 461 ( int8out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "20" _null_ _null_ _null_ _null_ int8out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 462 ( int8um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8um _null_ _null_ _null_ "" f)); +DATA(insert OID = 463 ( int8pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 464 ( int8mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 465 ( int8mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 466 ( int8div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 20" _null_ _null_ _null_ _null_ int8div _null_ _null_ _null_ "" f)); +DATA(insert OID = 467 ( int8eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 468 ( int8ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 469 ( int8lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 470 ( int8gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 471 ( int8le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8le _null_ _null_ _null_ "" f)); +DATA(insert OID = 472 ( int8ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 474 ( int84eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 475 ( int84ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 476 ( int84lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 477 ( int84gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 478 ( int84le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84le _null_ _null_ _null_ "" f)); +DATA(insert OID = 479 ( int84ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3177 ( int8_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "20" _null_ _null_ _null_ _null_ int8_bool _null_ _null_ _null_ "" f)); +DESCR("convert int8 to boolean"); +DATA(insert OID = 3178 ( bool_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "16" _null_ _null_ _null_ _null_ bool_int8 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int8"); + +DATA(insert OID = 3180 ( int2_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "21" _null_ _null_ _null_ _null_ int2_bool _null_ _null_ _null_ "" f)); +DESCR("convert int2 to boolean"); +DATA(insert OID = 3181 ( bool_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "16" _null_ _null_ _null_ _null_ bool_int2 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int2"); + + +DATA(insert OID = 480 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "20" _null_ _null_ _null_ _null_ int84 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int4"); +DATA(insert OID = 481 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "23" _null_ _null_ _null_ _null_ int48 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int8"); +DATA(insert OID = 482 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "20" _null_ _null_ _null_ _null_ i8tod _null_ _null_ _null_ "" f)); +DESCR("convert int8 to float8"); +DATA(insert OID = 483 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "701" _null_ _null_ _null_ _null_ dtoi8 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int8"); + +/* OIDS 500 - 599 */ + +/* OIDS 600 - 699 */ + +DATA(insert OID = 626 ( hash_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ hash_array _null_ _null_ _null_ "" f)); +DESCR("hash"); + +DATA(insert OID = 652 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "20" _null_ _null_ _null_ _null_ i8tof _null_ _null_ _null_ "" f)); +DESCR("convert int8 to float4"); +DATA(insert OID = 653 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "700" _null_ _null_ _null_ _null_ ftoi8 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int8"); + +DATA(insert OID = 714 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "20" _null_ _null_ _null_ _null_ int82 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int2"); +DATA(insert OID = 754 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "21" _null_ _null_ _null_ _null_ int28 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int8"); + +DATA(insert OID = 655 ( namelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 656 ( namele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namele _null_ _null_ _null_ "" f)); +DATA(insert OID = 657 ( namegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 658 ( namege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namege _null_ _null_ _null_ "" f)); +DATA(insert OID = 659 ( namene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namene _null_ _null_ _null_ "" f)); + +DATA(insert OID = 668 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1042 "1042 23 16" _null_ _null_ _null_ _null_ bpchar _null_ _null_ _null_ "" f)); +DESCR("adjust char() to typmod length"); +DATA(insert OID = 3097 ( varchar_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ varchar_transform _null_ _null_ _null_ "" f)); +DESCR("transform a varchar length coercion"); +DATA(insert OID = 669 ( varchar PGNSP PGUID 12 1 0 0 varchar_transform f f f f t f i 3 0 1043 "1043 23 16" _null_ _null_ _null_ _null_ varchar _null_ _null_ _null_ "" f)); +DESCR("adjust varchar() to typmod length"); +DATA(insert OID = 3961 ( nvarchar2 PGNSP PGUID 12 1 0 0 varchar_transform f f f f t f i 3 0 3969 "3969 23 16" _null_ _null_ _null_ _null_ nvarchar2 _null_ _null_ _null_ "" f)); +DESCR("adjust nvarchar2() to typmod length"); + +DATA(insert OID = 676 ( mktinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 704 "702 702" _null_ _null_ _null_ _null_ mktinterval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 619 ( oidvectorne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorne _null_ _null_ _null_ "" f)); +DATA(insert OID = 677 ( oidvectorlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 678 ( oidvectorle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorle _null_ _null_ _null_ "" f)); +DATA(insert OID = 679 ( oidvectoreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectoreq _null_ _null_ _null_ "" f)); +DATA(insert OID = 680 ( oidvectorge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorge _null_ _null_ _null_ "" f)); +DATA(insert OID = 681 ( oidvectorgt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorgt _null_ _null_ _null_ "" f)); + +/* OIDS 700 - 799 */ +DATA(insert OID = 710 ( getpgusername PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_user _null_ _null_ _null_ "" f)); +DESCR("deprecated, use current_user instead"); +DATA(insert OID = 716 ( oidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 717 ( oidle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidle _null_ _null_ _null_ "" f)); + +DATA(insert OID = 720 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ byteaoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 721 ( get_byte PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ byteaGetByte _null_ _null_ _null_ "" f)); +DESCR("get byte"); +DATA(insert OID = 722 ( set_byte PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ byteaSetByte _null_ _null_ _null_ "" f)); +DESCR("set byte"); +DATA(insert OID = 723 ( get_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ byteaGetBit _null_ _null_ _null_ "" f)); +DESCR("get bit"); +DATA(insert OID = 724 ( set_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ byteaSetBit _null_ _null_ _null_ "" f)); +DESCR("set bit"); +DATA(insert OID = 749 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 17 "17 17 23 23" _null_ _null_ _null_ _null_ byteaoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); +DATA(insert OID = 752 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 17 23" _null_ _null_ _null_ _null_ byteaoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); + +DATA(insert OID = 725 ( dist_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 628" _null_ _null_ _null_ _null_ dist_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 726 ( dist_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "628 603" _null_ _null_ _null_ _null_ dist_lb _null_ _null_ _null_ "" f)); +DATA(insert OID = 727 ( dist_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 628" _null_ _null_ _null_ _null_ dist_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 728 ( dist_cpoly PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "718 604" _null_ _null_ _null_ _null_ dist_cpoly _null_ _null_ _null_ "" f)); +DATA(insert OID = 729 ( poly_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "604 604" _null_ _null_ _null_ _null_ poly_distance _null_ _null_ _null_ "" f)); + +DATA(insert OID = 740 ( text_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 741 ( text_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 742 ( text_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 743 ( text_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 745 ( current_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_user _null_ _null_ _null_ "" f)); +DESCR("current user name"); +DATA(insert OID = 3216 ( definer_current_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pseudo_current_user _null_ _null_ _null_ "" f)); +DATA(insert OID = 746 ( session_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ session_user _null_ _null_ _null_ "" f)); +DESCR("session user name"); + +DATA(insert OID = 744 ( array_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 390 ( array_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 391 ( array_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 392 ( array_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 393 ( array_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 396 ( array_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 747 ( array_dims PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2277" _null_ _null_ _null_ _null_ array_dims _null_ _null_ _null_ "" f)); +DESCR("array dimensions"); +DATA(insert OID = 748 ( array_ndims PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ array_ndims _null_ _null_ _null_ "" f)); +DESCR("number of array dimensions"); +DATA(insert OID = 750 ( array_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2275 26 23" _null_ _null_ _null_ _null_ array_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 756 ( complex_array_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2275 26 2275" _null_ _null_ _null_ _null_ complex_array_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 751 ( array_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2277" _null_ _null_ _null_ _null_ array_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2091 ( array_lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_lower _null_ _null_ _null_ "" f)); +DESCR("array lower dimension"); +DATA(insert OID = 2092 ( array_upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_upper _null_ _null_ _null_ "" f)); +DESCR("array upper dimension"); +DATA(insert OID = 2176 ( array_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_length _null_ _null_ _null_ "" f)); +DESCR("array length"); +DATA(insert OID = 378 ( array_append PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2277 2283" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ "" f)); +DATA(insert OID = 3179 ( array_extend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "23" _null_ _null_ _null_ _null_ array_extend _null_ _null_ _null_ "" f)); +DESCR("array extend"); +DESCR("append element onto end of array"); +DATA(insert OID = 379 ( array_prepend PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2283 2277" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ "" f)); +DESCR("prepend element onto front of array"); +DATA(insert OID = 383 ( array_cat PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_cat _null_ _null_ _null_ "" f)); +DATA(insert OID = 394 ( string_to_array PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ text_to_array _null_ _null_ _null_ "" f)); +DESCR("split delimited text into text[]"); +DATA(insert OID = 395 ( array_to_string PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "2277 25" _null_ _null_ _null_ _null_ array_to_text _null_ _null_ _null_ "" f)); +DESCR("concatenate array elements, using delimiter, into text"); +#define ARRAYTOSTRINGFUNCOID 395 +DATA(insert OID = 376 ( string_to_array PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ text_to_array_null _null_ _null_ _null_ "" f)); +DESCR("split delimited text into text[], with null string"); +DATA(insert OID = 384 ( array_to_string PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 25 "2277 25 25" _null_ _null_ _null_ _null_ array_to_text_null _null_ _null_ _null_ "" f)); +DESCR("concatenate array elements, using delimiter and null string, into text"); +#define ARRAYTOSTRINGNULLFUNCOID 384 +DATA(insert OID = 515 ( array_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 516 ( array_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1191 ( generate_subscripts PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 23 "2277 23 16" _null_ _null_ _null_ _null_ generate_subscripts _null_ _null_ _null_ "" f)); +DESCR("array subscripts generator"); +DATA(insert OID = 1192 ( generate_subscripts PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ generate_subscripts_nodir _null_ _null_ _null_ "" f)); +DESCR("array subscripts generator"); +DATA(insert OID = 1193 ( array_fill PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2283 1007" _null_ _null_ _null_ _null_ array_fill _null_ _null_ _null_ "" f)); +DESCR("array constructor with value"); +DATA(insert OID = 1286 ( array_fill PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2277 "2283 1007 1007" _null_ _null_ _null_ _null_ array_fill_with_lower_bounds _null_ _null_ _null_ "" f)); +DESCR("array constructor with value"); +DATA(insert OID = 2331 ( unnest PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 2283 "2277" _null_ _null_ _null_ _null_ array_unnest _null_ _null_ _null_ "" f)); +DESCR("expand array to set of rows"); +DATA(insert OID = 2333 ( array_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2281 "2281 2283" _null_ _null_ _null_ _null_ array_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2334 ( array_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2277 "2281" _null_ _null_ _null_ _null_ array_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2335 ( array_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2283" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into an array"); +#define ARRAYAGGFUNCOID 2335 +DATA(insert OID = 3816 ( array_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ array_typanalyze _null_ _null_ _null_ "" f)); +DESCR("array typanalyze"); +DATA(insert OID = 3817 ( arraycontsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ arraycontsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for array-containment operators"); +DATA(insert OID = 3818 ( arraycontjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ arraycontjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for array-containment operators"); + +DATA(insert OID = 760 ( smgrin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 210 "2275" _null_ _null_ _null_ _null_ smgrin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 761 ( smgrout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "210" _null_ _null_ _null_ _null_ smgrout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 762 ( smgreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "210 210" _null_ _null_ _null_ _null_ smgreq _null_ _null_ _null_ "" f)); +DESCR("storage manager"); +DATA(insert OID = 763 ( smgrne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "210 210" _null_ _null_ _null_ _null_ smgrne _null_ _null_ _null_ "" f)); +DESCR("storage manager"); + +DATA(insert OID = 764 ( lo_import PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "25" _null_ _null_ _null_ _null_ lo_import _null_ _null_ _null_ "" f)); +DESCR("large object import"); +DATA(insert OID = 767 ( lo_import PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 26 "25 26" _null_ _null_ _null_ _null_ lo_import_with_oid _null_ _null_ _null_ "" f)); +DESCR("large object import"); +DATA(insert OID = 765 ( lo_export PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "26 25" _null_ _null_ _null_ _null_ lo_export _null_ _null_ _null_ "" f)); +DESCR("large object export"); +DATA(insert OID = 6117 ( int1inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 766 ( int4inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 768 ( int4larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 769 ( int4smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 770 ( int2larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 771 ( int2smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 6115 ( int1larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 6116 ( int1smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 774 ( gistgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ gistgettuple _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 638 ( gistgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ gistgetbitmap _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 775 ( gistinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistinsert _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 777 ( gistbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gistbeginscan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 778 ( gistrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistrescan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 779 ( gistendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistendscan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 780 ( gistmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistmarkpos _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 781 ( gistrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistrestrpos _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 3187 ( gistmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistmerge _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 782 ( gistbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gistbuild _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 326 ( gistbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistbuildempty _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 776 ( gistbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistbulkdelete _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 2561 ( gistvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gistvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 772 ( gistcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistcostestimate _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 2787 ( gistoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ gistoptions _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); + +DATA(insert OID = 784 ( tintervaleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervaleq _null_ _null_ _null_ "" f)); +DATA(insert OID = 785 ( tintervalne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalne _null_ _null_ _null_ "" f)); +DATA(insert OID = 786 ( tintervallt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervallt _null_ _null_ _null_ "" f)); +DATA(insert OID = 787 ( tintervalgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 788 ( tintervalle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalle _null_ _null_ _null_ "" f)); +DATA(insert OID = 789 ( tintervalge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalge _null_ _null_ _null_ "" f)); + +/* OIDS 800 - 899 */ + +DATA(insert OID = 846 ( cash_mul_flt4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 700" _null_ _null_ _null_ _null_ cash_mul_flt4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 847 ( cash_div_flt4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 700" _null_ _null_ _null_ _null_ cash_div_flt4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 848 ( flt4_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "700 790" _null_ _null_ _null_ _null_ flt4_mul_cash _null_ _null_ _null_ "" f)); + +DATA(insert OID = 849 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define POSITIONFUNCOID 849 +DATA(insert OID = 850 ( textlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 851 ( textnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 852 ( int48eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 853 ( int48ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 854 ( int48lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 855 ( int48gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 856 ( int48le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48le _null_ _null_ _null_ "" f)); +DATA(insert OID = 857 ( int48ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 858 ( namelike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namelike _null_ _null_ _null_ "" f)); +DATA(insert OID = 859 ( namenlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namenlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 860 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "18" _null_ _null_ _null_ _null_ char_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert char to char(n)"); + +DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_database _null_ _null_ _null_ "" f)); +DESCR("name of the current database"); +DATA(insert OID = 817 ( current_query PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 25 "" _null_ _null_ _null_ _null_ current_query _null_ _null_ _null_ "" f)); +DESCR("get the currently executing query"); + +DATA(insert OID = 862 ( int4_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "23 790" _null_ _null_ _null_ _null_ int4_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 863 ( int2_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "21 790" _null_ _null_ _null_ _null_ int2_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 864 ( cash_mul_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 23" _null_ _null_ _null_ _null_ cash_mul_int4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 865 ( cash_div_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 23" _null_ _null_ _null_ _null_ cash_div_int4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 866 ( cash_mul_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 21" _null_ _null_ _null_ _null_ cash_mul_int2 _null_ _null_ _null_ "" f)); +DATA(insert OID = 867 ( cash_div_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 21" _null_ _null_ _null_ _null_ cash_div_int2 _null_ _null_ _null_ "" f)); + +DATA(insert OID = 886 ( cash_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "2275" _null_ _null_ _null_ _null_ cash_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define CASHINFUNCOID 886 +DATA(insert OID = 887 ( cash_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "790" _null_ _null_ _null_ _null_ cash_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define CASHOUTFUNCOID 887 +DATA(insert OID = 888 ( cash_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 889 ( cash_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 890 ( cash_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 891 ( cash_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 892 ( cash_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 893 ( cash_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 894 ( cash_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cash_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 895 ( cash_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cash_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 896 ( cash_mul_flt8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 701" _null_ _null_ _null_ _null_ cash_mul_flt8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 897 ( cash_div_flt8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 701" _null_ _null_ _null_ _null_ cash_div_flt8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 898 ( cashlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cashlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 899 ( cashsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cashsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 919 ( flt8_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "701 790" _null_ _null_ _null_ _null_ flt8_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 935 ( cash_words PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "790" _null_ _null_ _null_ _null_ cash_words _null_ _null_ _null_ "" f)); +DESCR("output money amount as words"); +DATA(insert OID = 3822 ( cash_div_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "790 790" _null_ _null_ _null_ _null_ cash_div_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 3823 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1700 "790" _null_ _null_ _null_ _null_ cash_numeric _null_ _null_ _null_ "" f)); +DESCR("convert money to numeric"); +#define CASH2NUMERICFUNCOID 3823 +DATA(insert OID = 3824 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "1700" _null_ _null_ _null_ _null_ numeric_cash _null_ _null_ _null_ "" f)); +DESCR("convert numeric to money"); +#define NUMERIC2CASHFUNCOID 3824 +DATA(insert OID = 3811 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "23" _null_ _null_ _null_ _null_ int4_cash _null_ _null_ _null_ "" f)); +DESCR("convert int4 to money"); +#define INTEGER2CASHFUNCOID 3811 +DATA(insert OID = 3812 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "20" _null_ _null_ _null_ _null_ int8_cash _null_ _null_ _null_ "" f)); +DESCR("convert int8 to money"); +#define BIGINT2CASHFUNCOID 3812 + + +/* OIDS 900 - 999 */ +DATA(insert OID = 6114 ( int1mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 940 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 941 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); + +DATA(insert OID = 945 ( int8mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 947 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); + +DATA(insert OID = 944 ( char PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "25" _null_ _null_ _null_ _null_ text_char _null_ _null_ _null_ "" f)); +DESCR("convert text to char"); +DATA(insert OID = 946 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "18" _null_ _null_ _null_ _null_ char_text _null_ _null_ _null_ "" f)); +DESCR("convert char to text"); + +DATA(insert OID = 952 ( lo_open PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "26 23" _null_ _null_ _null_ _null_ lo_open _null_ _null_ _null_ "" f)); +DESCR("large object open"); +DATA(insert OID = 953 ( lo_close PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "23" _null_ _null_ _null_ _null_ lo_close _null_ _null_ _null_ "" f)); +DESCR("large object close"); +DATA(insert OID = 954 ( loread PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 17 "23 23" _null_ _null_ _null_ _null_ loread _null_ _null_ _null_ "" f)); +DESCR("large object read"); +DATA(insert OID = 955 ( lowrite PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "23 17" _null_ _null_ _null_ _null_ lowrite _null_ _null_ _null_ "" f)); +DESCR("large object write"); +DATA(insert OID = 956 ( lo_lseek PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ lo_lseek _null_ _null_ _null_ "" f)); +DESCR("large object seek"); +DATA(insert OID = 957 ( lo_creat PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "23" _null_ _null_ _null_ _null_ lo_creat _null_ _null_ _null_ "" f)); +DESCR("large object create"); +DATA(insert OID = 715 ( lo_create PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "26" _null_ _null_ _null_ _null_ lo_create _null_ _null_ _null_ "" f)); +DESCR("large object create"); +DATA(insert OID = 958 ( lo_tell PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "23" _null_ _null_ _null_ _null_ lo_tell _null_ _null_ _null_ "" f)); +DESCR("large object position"); +DATA(insert OID = 1004 ( lo_truncate PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "23 23" _null_ _null_ _null_ _null_ lo_truncate _null_ _null_ _null_ "" f)); +DESCR("truncate large object"); + +DATA(insert OID = 959 ( on_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 628" _null_ _null_ _null_ _null_ on_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 960 ( on_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 628" _null_ _null_ _null_ _null_ on_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 961 ( close_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 628" _null_ _null_ _null_ _null_ close_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 962 ( close_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 628" _null_ _null_ _null_ _null_ close_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 963 ( close_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 603" _null_ _null_ _null_ _null_ close_lb _null_ _null_ _null_ "" f)); + +DATA(insert OID = 964 ( lo_unlink PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "26" _null_ _null_ _null_ _null_ lo_unlink _null_ _null_ _null_ "" f)); +DESCR("large object unlink (delete)"); + +DATA(insert OID = 973 ( path_inter PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_inter _null_ _null_ _null_ "" f)); +DATA(insert OID = 975 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_area _null_ _null_ _null_ "" f)); +DESCR("box area"); +DATA(insert OID = 976 ( width PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_width _null_ _null_ _null_ "" f)); +DESCR("box width"); +DATA(insert OID = 977 ( height PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_height _null_ _null_ _null_ "" f)); +DESCR("box height"); +DATA(insert OID = 978 ( box_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "603 603" _null_ _null_ _null_ _null_ box_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 979 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_area _null_ _null_ _null_ "" f)); +DESCR("area of a closed path"); +DATA(insert OID = 980 ( box_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 603" _null_ _null_ _null_ _null_ box_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 981 ( diagonal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "603" _null_ _null_ _null_ _null_ box_diagonal _null_ _null_ _null_ "" f)); +DESCR("box diagonal"); +DATA(insert OID = 982 ( path_n_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 983 ( path_n_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 984 ( path_n_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 985 ( path_n_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 986 ( path_n_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 987 ( path_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_length _null_ _null_ _null_ "" f)); +DATA(insert OID = 988 ( point_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 989 ( point_vert PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_vert _null_ _null_ _null_ "" f)); +DATA(insert OID = 990 ( point_horiz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_horiz _null_ _null_ _null_ "" f)); +DATA(insert OID = 991 ( point_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 600" _null_ _null_ _null_ _null_ point_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 992 ( slope PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 600" _null_ _null_ _null_ _null_ point_slope _null_ _null_ _null_ "" f)); +DESCR("slope between points"); +DATA(insert OID = 993 ( lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 601 "600 600" _null_ _null_ _null_ _null_ lseg_construct _null_ _null_ _null_ "" f)); +DESCR("convert points to line segment"); +DATA(insert OID = 994 ( lseg_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 995 ( lseg_parallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_parallel _null_ _null_ _null_ "" f)); +DATA(insert OID = 996 ( lseg_perp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_perp _null_ _null_ _null_ "" f)); +DATA(insert OID = 997 ( lseg_vertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_vertical _null_ _null_ _null_ "" f)); +DATA(insert OID = 998 ( lseg_horizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_horizontal _null_ _null_ _null_ "" f)); +DATA(insert OID = 999 ( lseg_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_eq _null_ _null_ _null_ "" f)); + +/* OIDS 1000 - 1999 */ + +DATA(insert OID = 1026 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1186 1184" _null_ _null_ _null_ _null_ timestamptz_izone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); + +DATA(insert OID = 1031 ( aclitemin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1033 "2275" _null_ _null_ _null_ _null_ aclitemin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1032 ( aclitemout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1033" _null_ _null_ _null_ _null_ aclitemout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1035 ( aclinsert PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "1034 1033" _null_ _null_ _null_ _null_ aclinsert _null_ _null_ _null_ "" f)); +DESCR("add/update ACL item"); +DATA(insert OID = 1036 ( aclremove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "1034 1033" _null_ _null_ _null_ _null_ aclremove _null_ _null_ _null_ "" f)); +DESCR("remove ACL item"); +DATA(insert OID = 1037 ( aclcontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1034 1033" _null_ _null_ _null_ _null_ aclcontains _null_ _null_ _null_ "" f)); +DESCR("contains"); +DATA(insert OID = 1062 ( aclitemeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1033 1033" _null_ _null_ _null_ _null_ aclitem_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1365 ( makeaclitem PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 1033 "26 26 25 16" _null_ _null_ _null_ _null_ makeaclitem _null_ _null_ _null_ "" f)); +DESCR("make ACL item"); +DATA(insert OID = 3943 ( acldefault PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "18 26" _null_ _null_ _null_ _null_ acldefault_sql _null_ _null_ _null_ "" f)); +DESCR("TODO"); +DATA(insert OID = 1689 ( aclexplode PGNSP PGUID 12 1 10 0 0 f f f f t t s 1 0 2249 "1034" "{1034,26,26,25,16}" "{i,o,o,o,o}" "{acl,grantor,grantee,privilege_type,is_grantable}" _null_ aclexplode _null_ _null_ _null_ "" f)); +DESCR("convert ACL item array to table, for use by information schema"); +DATA(insert OID = 1044 ( bpcharin PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1042 "2275 26 23" _null_ _null_ _null_ _null_ bpcharin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1045 ( bpcharout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1042" _null_ _null_ _null_ _null_ bpcharout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2913 ( bpchartypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ bpchartypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2914 ( bpchartypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ bpchartypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1046 ( varcharin PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1043 "2275 26 23" _null_ _null_ _null_ _null_ varcharin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1047 ( varcharout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1043" _null_ _null_ _null_ _null_ varcharout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3962 ( nvarchar2in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 3969 "2275 26 23" _null_ _null_ _null_ _null_ nvarchar2in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3963 ( nvarchar2out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3969" _null_ _null_ _null_ _null_ nvarchar2out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3964 ( nvarchar2typmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ nvarchar2typmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 3965 ( nvarchar2typmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ nvarchar2typmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2915 ( varchartypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ varchartypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2916 ( varchartypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ varchartypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1048 ( bpchareq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchareq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1049 ( bpcharlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1050 ( bpcharle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1051 ( bpchargt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchargt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1052 ( bpcharge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1053 ( bpcharne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1063 ( bpchar_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1042 "1042 1042" _null_ _null_ _null_ _null_ bpchar_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1064 ( bpchar_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1042 "1042 1042" _null_ _null_ _null_ _null_ bpchar_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1078 ( bpcharcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 1042" _null_ _null_ _null_ _null_ bpcharcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3256 ( bpchar_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bpchar_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 1080 ( hashbpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ hashbpchar _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHBPCHAROID 1080 +DATA(insert OID = 1081 ( format_type PGNSP PGUID 12 1 0 0 0 f f f f f f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ format_type _null_ _null_ _null_ "" f)); +DESCR("format a type oid and atttypmod to canonical SQL"); +DATA(insert OID = 1084 ( date_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "2275" _null_ _null_ _null_ _null_ date_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define DATEINFUNCOID 1084 +DATA(insert OID = 1085 ( date_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1082" _null_ _null_ _null_ _null_ date_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define DATEOUTFUNCOID 1085 +DATA(insert OID = 1086 ( date_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1087 ( date_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1088 ( date_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1089 ( date_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1090 ( date_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1091 ( date_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1092 ( date_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1082" _null_ _null_ _null_ _null_ date_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3136 ( date_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ date_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); + +/* OIDS 1100 - 1199 */ + +DATA(insert OID = 1102 ( time_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1103 ( time_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1104 ( time_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1105 ( time_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1106 ( time_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1107 ( time_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 1083" _null_ _null_ _null_ _null_ time_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1138 ( date_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 1082" _null_ _null_ _null_ _null_ date_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1139 ( date_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 1082" _null_ _null_ _null_ _null_ date_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1140 ( date_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1082" _null_ _null_ _null_ _null_ date_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1141 ( date_pli PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 23" _null_ _null_ _null_ _null_ date_pli _null_ _null_ _null_ "" f)); +DATA(insert OID = 1142 ( date_mii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 23" _null_ _null_ _null_ _null_ date_mii _null_ _null_ _null_ "" f)); +DATA(insert OID = 1143 ( time_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1083 "2275 26 23" _null_ _null_ _null_ _null_ time_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMEINFUNCOID 1143 +DATA(insert OID = 1144 ( time_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1083" _null_ _null_ _null_ _null_ time_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMEOUTFUNCOID 1144 +DATA(insert OID = 2909 ( timetypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timetypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2910 ( timetypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timetypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1145 ( time_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_eq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1146 ( circle_add_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_add_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1147 ( circle_sub_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_sub_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1148 ( circle_mul_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_mul_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1149 ( circle_div_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_div_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1150 ( timestamptz_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1184 "2275 26 23" _null_ _null_ _null_ _null_ timestamptz_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPTZINFUNCOID 1150 +DATA(insert OID = 1151 ( timestamptz_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1184" _null_ _null_ _null_ _null_ timestamptz_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPTZOUTFUNCOID 1151 +DATA(insert OID = 2907 ( timestamptztypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timestamptztypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2908 ( timestamptztypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timestamptztypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1152 ( timestamptz_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1153 ( timestamptz_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1154 ( timestamptz_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1155 ( timestamptz_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1156 ( timestamptz_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1157 ( timestamptz_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1158 ( to_timestamp PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1184 "701" _null_ _null_ _null_ _null_ "select (''epoch''::pg_catalog.timestamptz + $1 * ''1 second''::pg_catalog.interval)" _null_ _null_ _null_ "" f)); +DESCR("convert UNIX epoch to timestamptz"); +DATA(insert OID = 1159 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "25 1184" _null_ _null_ _null_ _null_ timestamptz_zone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); + +DATA(insert OID = 1160 ( interval_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1186 "2275 26 23" _null_ _null_ _null_ _null_ interval_in _null_ _null_ _null_ "" f)); +#define INTERVALINFUNCOID 1160 +DESCR("I/O"); +DATA(insert OID = 1161 ( interval_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1186" _null_ _null_ _null_ _null_ interval_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2903 ( intervaltypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ intervaltypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2904 ( intervaltypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ intervaltypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1162 ( interval_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1163 ( interval_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1164 ( interval_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1165 ( interval_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1166 ( interval_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1167 ( interval_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1168 ( interval_um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_um _null_ _null_ _null_ "" f)); +DATA(insert OID = 1169 ( interval_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1170 ( interval_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1171 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 701 "25 1184" _null_ _null_ _null_ _null_ timestamptz_part _null_ _null_ _null_ "" f)); +DESCR("extract field from timestamp with time zone"); +#define TIMESTAMPTZPARTFUNCOID 1171 +DATA(insert OID = 1172 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1186" _null_ _null_ _null_ _null_ interval_part _null_ _null_ _null_ "" f)); +DESCR("extract field from interval"); +#define INTERVALPARTFUNCOID 1172 +DATA(insert OID = 1173 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1184 "702" _null_ _null_ _null_ _null_ abstime_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert abstime to timestamp with time zone"); +DATA(insert OID = 1174 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "1082" _null_ _null_ _null_ _null_ date_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert date to timestamp with time zone"); +#define DATETIMESTAMPTZFUNCOID 1174 +DATA(insert OID = 2711 ( justify_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_interval _null_ _null_ _null_ "" f)); +DESCR("promote groups of 24 hours to numbers of days and promote groups of 30 days to numbers of months"); +DATA(insert OID = 1175 ( justify_hours PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_hours _null_ _null_ _null_ "" f)); +DESCR("promote groups of 24 hours to numbers of days"); +DATA(insert OID = 1295 ( justify_days PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_days _null_ _null_ _null_ "" f)); +DESCR("promote groups of 30 days to numbers of months"); +DATA(insert OID = 1176 ( timestamptz PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 1184 "1082 1083" _null_ _null_ _null_ _null_ "select cast(($1 + $2) as timestamp with time zone)" _null_ _null_ _null_ "" f)); +DESCR("convert date and time to timestamp with time zone"); +#define DTAETIME2TIMESTAMPTZFUNCOID 1176 +DATA(insert OID = 1177 ( interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "703" _null_ _null_ _null_ _null_ reltime_interval _null_ _null_ _null_ "" f)); +DESCR("convert reltime to interval"); +DATA(insert OID = 1178 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "1184" _null_ _null_ _null_ _null_ timestamptz_date _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to date"); +#define TIMESTAMPTZ2DATEFUNCOID 1178 +DATA(insert OID = 1179 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "702" _null_ _null_ _null_ _null_ abstime_date _null_ _null_ _null_ "" f)); +DESCR("convert abstime to date"); +#define ABSTIME2DATEFUNCOID 1179 +DATA(insert OID = 1180 ( abstime PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "1184" _null_ _null_ _null_ _null_ timestamptz_abstime _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to abstime"); +DATA(insert OID = 1181 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "28" _null_ _null_ _null_ _null_ xid_age _null_ _null_ _null_ "" f)); +DESCR("age of a transaction ID, in transactions before current transaction"); + +DATA(insert OID = 1188 ( timestamptz_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1184 1184" _null_ _null_ _null_ _null_ timestamp_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1189 ( timestamptz_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "1184 1186" _null_ _null_ _null_ _null_ timestamptz_pl_interval _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZPLINTERVALFUNCOID 1189 +DATA(insert OID = 1190 ( timestamptz_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "1184 1186" _null_ _null_ _null_ _null_ timestamptz_mi_interval _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZMIINTERVALFUNCOID 1190 +DATA(insert OID = 1194 ( reltime PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "1186" _null_ _null_ _null_ _null_ interval_reltime _null_ _null_ _null_ "" f)); +DESCR("convert interval to reltime"); +DATA(insert OID = 1195 ( timestamptz_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1184 1184" _null_ _null_ _null_ _null_ timestamp_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1196 ( timestamptz_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1184 1184" _null_ _null_ _null_ _null_ timestamp_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1197 ( interval_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1198 ( interval_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1199 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1184 1184" _null_ _null_ _null_ _null_ timestamptz_age _null_ _null_ _null_ "" f)); +DESCR("date difference preserving months and years"); + +/* OIDS 1200 - 1299 */ + +DATA(insert OID = 3918 ( interval_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ interval_transform _null_ _null_ _null_ "" f)); +DESCR("transform an interval length coercion"); +DATA(insert OID = 1200 ( interval PGNSP PGUID 12 1 0 0 interval_transform f f f f t f i 2 0 1186 "1186 23" _null_ _null_ _null_ _null_ interval_scale _null_ _null_ _null_ "" f)); +DESCR("adjust interval precision"); + +DATA(insert OID = 1215 ( obj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 19" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and classoid = (select oid from pg_catalog.pg_class where relname = $2 and relnamespace = PGNSP) and objsubid = 0" _null_ _null_ _null_ "" f)); +DESCR("get description for object id and catalog name"); +DATA(insert OID = 1216 ( col_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and classoid = ''pg_catalog.pg_class''::pg_catalog.regclass and objsubid = $2" _null_ _null_ _null_ "" f)); +DESCR("get description for table column"); +DATA(insert OID = 1993 ( shobj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 19" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_shdescription where objoid = $1 and classoid = (select oid from pg_catalog.pg_class where relname = $2 and relnamespace = PGNSP)" _null_ _null_ _null_ "" f)); +DESCR("get description for object id and shared catalog name"); + +DATA(insert OID = 1217 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "25 1184" _null_ _null_ _null_ _null_ timestamptz_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate timestamp with time zone to specified units"); +#define TIMESTAMPTZTRUNCFUNCOID 1217 +DATA(insert OID = 1218 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "25 1186" _null_ _null_ _null_ _null_ interval_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate interval to specified units"); +#define INTERVALTRUNCFUNCOID 1218 + +DATA(insert OID = 1219 ( int8inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 2804 ( int8inc_any PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 2276" _null_ _null_ _null_ _null_ int8inc_any _null_ _null_ _null_ "" f)); +DESCR("increment, ignores second argument"); +DATA(insert OID = 1230 ( int8abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8abs _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1236 ( int8larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1237 ( int8smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1238 ( texticregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1239 ( texticregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1240 ( nameicregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1241 ( nameicregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicregexne _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1251 ( int4abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 1253 ( int2abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 6113 ( int1abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1abs _null_ _null_ _null_ "" f)); +DESCR("absolute value "); +DATA(insert OID = 1271 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1266 1266 1266 1266" _null_ _null_ _null_ _null_ overlaps_timetz _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1272 ( datetime_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1083" _null_ _null_ _null_ _null_ datetime_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 1273 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1266" _null_ _null_ _null_ _null_ timetz_part _null_ _null_ _null_ "" f)); +DESCR("extract field from time with time zone"); +#define TIMEZPARTFUNCOID 1273 +DATA(insert OID = 1274 ( int84pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1275 ( int84mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1276 ( int84mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1277 ( int84div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 23" _null_ _null_ _null_ _null_ int84div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1278 ( int48pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1279 ( int48mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1280 ( int48mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1281 ( int48div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 20" _null_ _null_ _null_ _null_ int48div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 837 ( int82pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 838 ( int82mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 839 ( int82mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 840 ( int82div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 21" _null_ _null_ _null_ _null_ int82div _null_ _null_ _null_ "" f)); +DATA(insert OID = 841 ( int28pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 942 ( int28mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 943 ( int28mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 948 ( int28div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 20" _null_ _null_ _null_ _null_ int28div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1287 ( oid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "20" _null_ _null_ _null_ _null_ i8tooid _null_ _null_ _null_ "" f)); +DESCR("convert int8 to oid"); +DATA(insert OID = 1288 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "26" _null_ _null_ _null_ _null_ oidtoi8 _null_ _null_ _null_ "" f)); +DESCR("convert oid to int8"); + +DATA(insert OID = 1291 ( suppress_redundant_updates_trigger PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ suppress_redundant_updates_trigger _null_ _null_ _null_ "" f)); +DESCR("trigger to suppress updates when new and old records match"); + +DATA(insert OID = 1292 ( tideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1293 ( currtid PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 27 "26 27" _null_ _null_ _null_ _null_ currtid_byreloid _null_ _null_ _null_ "" f)); +DESCR("latest tid of a tuple"); +DATA(insert OID = 1294 ( currtid2 PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 27 "25 27" _null_ _null_ _null_ _null_ currtid_byrelname _null_ _null_ _null_ "" f)); +DESCR("latest tid of a tuple"); +DATA(insert OID = 1265 ( tidne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2790 ( tidgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2791 ( tidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2792 ( tidge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2793 ( tidle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidle _null_ _null_ _null_ "" f)); +DATA(insert OID = 2794 ( bttidcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "27 27" _null_ _null_ _null_ _null_ bttidcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2795 ( tidlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 27 "27 27" _null_ _null_ _null_ _null_ tidlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2796 ( tidsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 27 "27 27" _null_ _null_ _null_ _null_ tidsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1296 ( timedate_pl PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1083 1082" _null_ _null_ _null_ _null_ "select ($2 + $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1297 ( datetimetz_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1082 1266" _null_ _null_ _null_ _null_ datetimetz_timestamptz _null_ _null_ _null_ "" f)); +DATA(insert OID = 1298 ( timetzdate_pl PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1184 "1266 1082" _null_ _null_ _null_ _null_ "select ($2 + $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1299 ( now PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ now _null_ _null_ _null_ "" f)); +DESCR("current transaction time"); +DATA(insert OID = 2647 ( transaction_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ now _null_ _null_ _null_ "" f)); +DESCR("current transaction time"); +DATA(insert OID = 2648 ( statement_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ statement_timestamp _null_ _null_ _null_ "" f)); +DESCR("current statement time"); +DATA(insert OID = 2649 ( clock_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ clock_timestamp _null_ _null_ _null_ "" f)); +DESCR("current clock time"); +DATA(insert OID = 3951 ( pg_systimestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ pg_system_timestamp _null_ _null_ _null_ "" f)); + +/* OIDS 1300 - 1399 */ + +DATA(insert OID = 1300 ( positionsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ positionsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for position-comparison operators"); +DATA(insert OID = 1301 ( positionjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ positionjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for position-comparison operators"); +DATA(insert OID = 1302 ( contsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ contsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for containment comparison operators"); +DATA(insert OID = 1303 ( contjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ contjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for containment comparison operators"); + +DATA(insert OID = 1304 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1184 1184 1184 1184" _null_ _null_ _null_ _null_ overlaps_timestamp _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1305 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1186 1184 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1306 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1184 1184 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1307 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1186 1184 1184" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); + +DATA(insert OID = 1308 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1083 1083 1083 1083" _null_ _null_ _null_ _null_ overlaps_time _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1309 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1186 1083 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1310 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1083 1083 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1311 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1186 1083 1083" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); + +DATA(insert OID = 1312 ( timestamp_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1114 "2275 26 23" _null_ _null_ _null_ _null_ timestamp_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPINFUNCOID 1312 +DATA(insert OID = 1313 ( timestamp_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1114" _null_ _null_ _null_ _null_ timestamp_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPOUTFUNCOID 1313 +DATA(insert OID = 2905 ( timestamptypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timestamptypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2906 ( timestamptypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timestamptypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1314 ( timestamptz_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 1184" _null_ _null_ _null_ _null_ timestamp_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1315 ( interval_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 1186" _null_ _null_ _null_ _null_ interval_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1316 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1114" _null_ _null_ _null_ _null_ timestamp_time _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to time"); + +DATA(insert OID = 1317 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +#define LENGTHFUNCOID 1317 +DESCR("length"); +DATA(insert OID = 1318 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +#define BPLENFUNCOID 1318 + +DATA(insert OID = 3175 ( lengthb PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textoctetlen _null_ _null_ _null_ "" f)); +DESCR("lengthb"); +#define TEXTOCTLENFUNCOID 3175 +DATA(insert OID = 3176 ( lengthb PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlenb _null_ _null_ _null_ "" f)); +DESCR("character lengthb"); +#define BPOCTLENFUNCOID 3176 + +DATA(insert OID = 1319 ( xideqint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "28 23" _null_ _null_ _null_ _null_ xideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1320 ( xidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "28 28" _null_ _null_ _null_ _null_ xidlt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1326 ( interval_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 701" _null_ _null_ _null_ _null_ interval_div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1339 ( dlog10 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog10 _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1340 ( log PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog10 _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1341 ( ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog1 _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1342 ( round PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dround _null_ _null_ _null_ "" f)); +DESCR("round to nearest integer"); +DATA(insert OID = 1343 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtrunc _null_ _null_ _null_ "" f)); +DESCR("truncate to integer"); +DATA(insert OID = 1344 ( sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +#define SQRTFUNCOID 1344 +DATA(insert OID = 1345 ( cbrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcbrt _null_ _null_ _null_ "" f)); +DESCR("cube root"); +DATA(insert OID = 1346 ( pow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +#define POWFUNCOID 1346 +DATA(insert OID = 1368 ( power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +#define POWERFUNCOID 1368 +DATA(insert OID = 1347 ( exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dexp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); + +/* + * This form of obj_description is now deprecated, since it will fail if + * OIDs are not unique across system catalogs. Use the other form instead. + */ +DATA(insert OID = 1348 ( obj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and objsubid = 0" _null_ _null_ _null_ "" f)); +DESCR("deprecated, use two-argument form instead"); +DATA(insert OID = 1349 ( oidvectortypes PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "30" _null_ _null_ _null_ _null_ oidvectortypes _null_ _null_ _null_ "" f)); +DESCR("print type names of oidvector field"); + + +DATA(insert OID = 1350 ( timetz_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1266 "2275 26 23" _null_ _null_ _null_ _null_ timetz_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMETZINFUNCOID 1350 +DATA(insert OID = 1351 ( timetz_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1266" _null_ _null_ _null_ _null_ timetz_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2911 ( timetztypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timetztypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2912 ( timetztypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timetztypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1352 ( timetz_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1353 ( timetz_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1354 ( timetz_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1355 ( timetz_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1356 ( timetz_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1357 ( timetz_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1358 ( timetz_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 1266" _null_ _null_ _null_ _null_ timetz_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1359 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1082 1266" _null_ _null_ _null_ _null_ datetimetz_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert date and time with time zone to timestamp with time zone"); + +DATA(insert OID = 1364 ( time PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1083 "702" _null_ _null_ _null_ _null_ "select cast(cast($1 as timestamp without time zone) as pg_catalog.time)" _null_ _null_ _null_ "" f)); +DESCR("convert abstime to time"); +#define ABSTIME2TIMEFUNCOID 1364 +DATA(insert OID = 1367 ( character_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +DATA(insert OID = 1369 ( character_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("character length"); + +DATA(insert OID = 1370 ( interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1083" _null_ _null_ _null_ _null_ time_interval _null_ _null_ _null_ "" f)); +DESCR("convert time to interval"); +DATA(insert OID = 1372 ( char_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +DATA(insert OID = 1374 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 1375 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); + +DATA(insert OID = 1377 ( time_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1083" _null_ _null_ _null_ _null_ time_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1378 ( time_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1083" _null_ _null_ _null_ _null_ time_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1379 ( timetz_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1266" _null_ _null_ _null_ _null_ timetz_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1380 ( timetz_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1266" _null_ _null_ _null_ _null_ timetz_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1381 ( char_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +#define CHARLENFUNCOID 1381 + +DATA(insert OID = 1382 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 701 "25 702" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as timestamp with time zone))" _null_ _null_ _null_ "" f)); +DESCR("extract field from abstime"); +#define DATEPARTFROMABSTIMEFUNCOID 1382 +DATA(insert OID = 1383 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 701 "25 703" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as pg_catalog.interval))" _null_ _null_ _null_ "" f)); +DESCR("extract field from reltime"); +#define DATEPARTFROMRELTIMEFUNCOID 1383 +DATA(insert OID = 1384 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 701 "25 1082" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as timestamp without time zone))" _null_ _null_ _null_ "" f)); +DESCR("extract field from date"); +#define DATEPARTFUNCOID 1384 +DATA(insert OID = 1385 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1083" _null_ _null_ _null_ _null_ time_part _null_ _null_ _null_ "" f)); +DESCR("extract field from time"); +#define TIMEPARTFUNCOID 1385 +DATA(insert OID = 1386 ( age PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1186 "1184" _null_ _null_ _null_ _null_ "select pg_catalog.age(cast(current_date as timestamp with time zone), $1)" _null_ _null_ _null_ "" f)); +DESCR("date difference from today preserving months and years"); + +DATA(insert OID = 1388 ( timetz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1266 "1184" _null_ _null_ _null_ _null_ timestamptz_timetz _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to time with time zone"); +#define TIMESTAMPTZ2TIMETZFUNCOID 1388 +DATA(insert OID = 1373 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1082" _null_ _null_ _null_ _null_ date_finite _null_ _null_ _null_ "" f)); +DESCR("finite date?"); +DATA(insert OID = 1389 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1184" _null_ _null_ _null_ _null_ timestamp_finite _null_ _null_ _null_ "" f)); +DESCR("finite timestamp?"); +DATA(insert OID = 1390 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1186" _null_ _null_ _null_ _null_ interval_finite _null_ _null_ _null_ "" f)); +DESCR("finite interval?"); + + +DATA(insert OID = 1376 ( factorial PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ numeric_fac _null_ _null_ _null_ "" f)); +DESCR("factorial"); +DATA(insert OID = 1394 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1395 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1396 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1397 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1398 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); + +/* OIDS 1400 - 1499 */ + +DATA(insert OID = 1400 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "1043" _null_ _null_ _null_ _null_ text_name _null_ _null_ _null_ "" f)); +DESCR("convert varchar to name"); +DATA(insert OID = 1401 ( varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "19" _null_ _null_ _null_ _null_ name_text _null_ _null_ _null_ "" f)); +DESCR("convert name to varchar"); + +DATA(insert OID = 1402 ( current_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_schema _null_ _null_ _null_ "" f)); +DESCR("current schema name"); +DATA(insert OID = 1403 ( current_schemas PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1003 "16" _null_ _null_ _null_ _null_ current_schemas _null_ _null_ _null_ "" f)); +DESCR("current schema search list"); + +DATA(insert OID = 1404 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 25 "25 25 23 23" _null_ _null_ _null_ _null_ textoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); +DATA(insert OID = 1405 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 23" _null_ _null_ _null_ _null_ textoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); + +DATA(insert OID = 1406 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_vert _null_ _null_ _null_ "" f)); +DESCR("vertically aligned"); +DATA(insert OID = 1407 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_horiz _null_ _null_ _null_ "" f)); +DESCR("horizontally aligned"); +DATA(insert OID = 1408 ( isparallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_parallel _null_ _null_ _null_ "" f)); +DESCR("parallel"); +DATA(insert OID = 1409 ( isperp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_perp _null_ _null_ _null_ "" f)); +DESCR("perpendicular"); +DATA(insert OID = 1410 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_vertical _null_ _null_ _null_ "" f)); +DESCR("vertical"); +DATA(insert OID = 1411 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_horizontal _null_ _null_ _null_ "" f)); +DESCR("horizontal"); +DATA(insert OID = 1412 ( isparallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_parallel _null_ _null_ _null_ "" f)); +DESCR("parallel"); +DATA(insert OID = 1413 ( isperp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_perp _null_ _null_ _null_ "" f)); +DESCR("perpendicular"); +DATA(insert OID = 1414 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_vertical _null_ _null_ _null_ "" f)); +DESCR("vertical"); +DATA(insert OID = 1415 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_horizontal _null_ _null_ _null_ "" f)); +DESCR("horizontal"); +DATA(insert OID = 1416 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DESCR("center of"); + +DATA(insert OID = 1419 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1186" _null_ _null_ _null_ _null_ interval_time _null_ _null_ _null_ "" f)); +DESCR("convert interval to time"); + +DATA(insert OID = 1421 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "600 600" _null_ _null_ _null_ _null_ points_box _null_ _null_ _null_ "" f)); +DESCR("convert points to box"); +DATA(insert OID = 1422 ( box_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1423 ( box_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1424 ( box_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1425 ( box_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1426 ( path_contain_pt PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 16 "602 600" _null_ _null_ _null_ _null_ "select pg_catalog.on_ppath($2, $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1428 ( poly_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 600" _null_ _null_ _null_ _null_ poly_contain_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1429 ( pt_contained_poly PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 604" _null_ _null_ _null_ _null_ pt_contained_poly _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1430 ( isclosed PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "602" _null_ _null_ _null_ _null_ path_isclosed _null_ _null_ _null_ "" f)); +DESCR("path closed?"); +DATA(insert OID = 1431 ( isopen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "602" _null_ _null_ _null_ _null_ path_isopen _null_ _null_ _null_ "" f)); +DESCR("path open?"); +DATA(insert OID = 1432 ( path_npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "602" _null_ _null_ _null_ _null_ path_npoints _null_ _null_ _null_ "" f)); + +/* pclose and popen might better be named close and open, but that crashes initdb. + * - thomas 97/04/20 + */ + +DATA(insert OID = 1433 ( pclose PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "602" _null_ _null_ _null_ _null_ path_close _null_ _null_ _null_ "" f)); +DESCR("close path"); +DATA(insert OID = 1434 ( popen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "602" _null_ _null_ _null_ _null_ path_open _null_ _null_ _null_ "" f)); +DESCR("open path"); +DATA(insert OID = 1435 ( path_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 602" _null_ _null_ _null_ _null_ path_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1436 ( path_add_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_add_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1437 ( path_sub_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_sub_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1438 ( path_mul_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_mul_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1439 ( path_div_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_div_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1440 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "701 701" _null_ _null_ _null_ _null_ construct_point _null_ _null_ _null_ "" f)); +DESCR("convert x, y to point"); +DATA(insert OID = 1441 ( point_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1442 ( point_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1443 ( point_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1444 ( point_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1445 ( poly_npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "604" _null_ _null_ _null_ _null_ poly_npoints _null_ _null_ _null_ "" f)); +DATA(insert OID = 1446 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "604" _null_ _null_ _null_ _null_ poly_box _null_ _null_ _null_ "" f)); +DESCR("convert polygon to bounding box"); +DATA(insert OID = 1447 ( path PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "604" _null_ _null_ _null_ _null_ poly_path _null_ _null_ _null_ "" f)); +DESCR("convert polygon to path"); +DATA(insert OID = 1448 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "603" _null_ _null_ _null_ _null_ box_poly _null_ _null_ _null_ "" f)); +DESCR("convert box to polygon"); +DATA(insert OID = 1449 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "602" _null_ _null_ _null_ _null_ path_poly _null_ _null_ _null_ "" f)); +DESCR("convert path to polygon"); + +DATA(insert OID = 1450 ( circle_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "2275" _null_ _null_ _null_ _null_ circle_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1451 ( circle_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "718" _null_ _null_ _null_ _null_ circle_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1452 ( circle_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 1453 ( circle_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 1454 ( circle_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 1455 ( circle_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 1456 ( circle_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 1457 ( circle_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 1458 ( circle_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 1459 ( circle_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 1460 ( circle_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 1461 ( circle_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 1462 ( circle_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1463 ( circle_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1464 ( circle_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1465 ( circle_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1466 ( circle_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1467 ( circle_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1468 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_area _null_ _null_ _null_ "" f)); +DESCR("area of circle"); +DATA(insert OID = 1469 ( diameter PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_diameter _null_ _null_ _null_ "" f)); +DESCR("diameter of circle"); +DATA(insert OID = 1470 ( radius PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_radius _null_ _null_ _null_ "" f)); +DESCR("radius of circle"); +DATA(insert OID = 1471 ( circle_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "718 718" _null_ _null_ _null_ _null_ circle_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 1472 ( circle_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 1473 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "600 701" _null_ _null_ _null_ _null_ cr_circle _null_ _null_ _null_ "" f)); +DESCR("convert point and radius to circle"); +DATA(insert OID = 1474 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "604" _null_ _null_ _null_ _null_ poly_circle _null_ _null_ _null_ "" f)); +DESCR("convert polygon to circle"); +DATA(insert OID = 1475 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 604 "23 718" _null_ _null_ _null_ _null_ circle_poly _null_ _null_ _null_ "" f)); +DESCR("convert vertex count and circle to polygon"); +DATA(insert OID = 1476 ( dist_pc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 718" _null_ _null_ _null_ _null_ dist_pc _null_ _null_ _null_ "" f)); +DATA(insert OID = 1477 ( circle_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 600" _null_ _null_ _null_ _null_ circle_contain_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1478 ( pt_contained_circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 718" _null_ _null_ _null_ _null_ pt_contained_circle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1479 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "603" _null_ _null_ _null_ _null_ box_circle _null_ _null_ _null_ "" f)); +DESCR("convert box to circle"); +DATA(insert OID = 1480 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "718" _null_ _null_ _null_ _null_ circle_box _null_ _null_ _null_ "" f)); +DESCR("convert circle to box"); +DATA(insert OID = 1481 ( tinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 704 "702 702" _null_ _null_ _null_ _null_ mktinterval _null_ _null_ _null_ "" f)); +DESCR("convert to tinterval"); + +DATA(insert OID = 1482 ( lseg_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1483 ( lseg_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1484 ( lseg_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1485 ( lseg_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1486 ( lseg_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1487 ( lseg_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "601" _null_ _null_ _null_ _null_ lseg_length _null_ _null_ _null_ "" f)); +DATA(insert OID = 1488 ( close_ls PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 601" _null_ _null_ _null_ _null_ close_ls _null_ _null_ _null_ "" f)); +DATA(insert OID = 1489 ( close_lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 601" _null_ _null_ _null_ _null_ close_lseg _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1490 ( line_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 628 "2275" _null_ _null_ _null_ _null_ line_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1491 ( line_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "628" _null_ _null_ _null_ _null_ line_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1492 ( line_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1493 ( line PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 628 "600 600" _null_ _null_ _null_ _null_ line_construct_pp _null_ _null_ _null_ "" f)); +DESCR("construct line from points"); +DATA(insert OID = 1494 ( line_interpt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 628" _null_ _null_ _null_ _null_ line_interpt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1495 ( line_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 1496 ( line_parallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_parallel _null_ _null_ _null_ "" f)); +DATA(insert OID = 1497 ( line_perp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_perp _null_ _null_ _null_ "" f)); +DATA(insert OID = 1498 ( line_vertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_vertical _null_ _null_ _null_ "" f)); +DATA(insert OID = 1499 ( line_horizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_horizontal _null_ _null_ _null_ "" f)); + +/* OIDS 1500 - 1599 */ + +DATA(insert OID = 1530 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "601" _null_ _null_ _null_ _null_ lseg_length _null_ _null_ _null_ "" f)); +DESCR("distance between endpoints"); +DATA(insert OID = 1531 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_length _null_ _null_ _null_ "" f)); +DESCR("sum of path segments"); + + +DATA(insert OID = 1532 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "601" _null_ _null_ _null_ _null_ lseg_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1533 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "602" _null_ _null_ _null_ _null_ path_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1534 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1540 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "604" _null_ _null_ _null_ _null_ poly_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1541 ( lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "603" _null_ _null_ _null_ _null_ box_diagonal _null_ _null_ _null_ "" f)); +DESCR("diagonal of"); +DATA(insert OID = 1542 ( center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1543 ( center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1544 ( polygon PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 604 "718" _null_ _null_ _null_ _null_ "select pg_catalog.polygon(12, $1)" _null_ _null_ _null_ "" f)); +DESCR("convert circle to 12-vertex polygon"); +DATA(insert OID = 1545 ( npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "602" _null_ _null_ _null_ _null_ path_npoints _null_ _null_ _null_ "" f)); +DESCR("number of points"); +DATA(insert OID = 1556 ( npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "604" _null_ _null_ _null_ _null_ poly_npoints _null_ _null_ _null_ "" f)); +DESCR("number of points"); + +DATA(insert OID = 1564 ( bit_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2275 26 23" _null_ _null_ _null_ _null_ bit_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1565 ( bit_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1560" _null_ _null_ _null_ _null_ bit_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2919 ( bittypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ bittypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2920 ( bittypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ bittypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); + +DATA(insert OID = 1569 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 1570 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 1571 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namelike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 1572 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namenlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); + + +/* SEQUENCE functions */ +DATA(insert OID = 1574 ( nextval PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ nextval_oid _null_ _null_ _null_ "" f)); +DESCR("sequence next value"); +#define NEXTVALFUNCOID 1574 +DATA(insert OID = 1575 ( currval PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ currval_oid _null_ _null_ _null_ "" f)); +DESCR("sequence current value"); +#define CURRVALFUNCOID 1575 +DATA(insert OID = 1576 ( setval PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 20" _null_ _null_ _null_ _null_ setval_oid _null_ _null_ _null_ "" f)); +DESCR("set sequence value"); +#define SETVAL1FUNCOID 1576 +DATA(insert OID = 1765 ( setval PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 20 "2205 20 16" _null_ _null_ _null_ _null_ setval3_oid _null_ _null_ _null_ "" f)); +DESCR("set sequence value and is_called status"); +#define SETVAL3FUNCOID 1765 +DATA(insert OID = 3078 ( pg_sequence_parameters PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2249 "26" "{26,20,20,20,20,16}" "{i,o,o,o,o,o}" "{sequence_oid,start_value,minimum_value,maximum_value,increment,cycle_option}" _null_ pg_sequence_parameters _null_ _null_ _null_"" f)); +DESCR("sequence parameters, for use by information schema"); + +DATA(insert OID = 1579 ( varbit_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1562 "2275 26 23" _null_ _null_ _null_ _null_ varbit_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1580 ( varbit_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1562" _null_ _null_ _null_ _null_ varbit_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2902 ( varbittypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ varbittypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2921 ( varbittypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ varbittypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); + +DATA(insert OID = 1581 ( biteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ biteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1582 ( bitne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1592 ( bitge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1593 ( bitgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1594 ( bitle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1595 ( bitlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1596 ( bitcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 1560" _null_ _null_ _null_ _null_ bitcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1598 ( random PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 701 "" _null_ _null_ _null_ _null_ drandom _null_ _null_ _null_ "" f)); +DESCR("random value"); +#define RANDOMFUNCOID 1598 +DATA(insert OID = 1599 ( setseed PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "701" _null_ _null_ _null_ _null_ setseed _null_ _null_ _null_ "" f)); +DESCR("set random seed"); +/* For LLT +DATA(insert OID = 4244 ( exec_on_extension PGNSP PGUID 12 1 1000 0 0 f f f f f t v 2 0 2249 "25 25" _null_ _null_ _null_ _null_ exec_on_extension _null_ _null_ _null_ "" f)); +DESCR("get data from remote database"); +*/ +#define ECFUNCOID 4244 +/*For LLT +DATA(insert OID = 4255 ( exec_hadoop_sql PGNSP PGUID 12 1 1000 0 0 f f f f f t v 3 0 2249 "25 25 25" _null_ _null_ _null_ _null_ exec_hadoop_sql _null_ _null_ _null_ "" f)); +DESCR("get data from remote database in hadoop"); +*/ +/* OIDS 1600 - 1699 */ + +DATA(insert OID = 1600 ( asin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dasin _null_ _null_ _null_ "" f)); +DESCR("arcsine"); +#define ARCSINEFUNCOID 1600 +DATA(insert OID = 1601 ( acos PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dacos _null_ _null_ _null_ "" f)); +DESCR("arccosine"); +DATA(insert OID = 1602 ( atan PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ datan _null_ _null_ _null_ "" f)); +DESCR("arctangent"); +DATA(insert OID = 1603 ( atan2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ datan2 _null_ _null_ _null_ "" f)); +DESCR("arctangent, two arguments"); +DATA(insert OID = 1604 ( sin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsin _null_ _null_ _null_ "" f)); +DESCR("sine"); +#define SINEFUNCOID 1604 +DATA(insert OID = 1605 ( cos PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcos _null_ _null_ _null_ "" f)); +DESCR("cosine"); +#define COSINEFUNCOID 1605 +DATA(insert OID = 1606 ( tan PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtan _null_ _null_ _null_ "" f)); +DESCR("tangent"); +DATA(insert OID = 1607 ( cot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcot _null_ _null_ _null_ "" f)); +DESCR("cotangent"); +DATA(insert OID = 1608 ( degrees PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ degrees _null_ _null_ _null_ "" f)); +DESCR("radians to degrees"); +DATA(insert OID = 1609 ( radians PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ radians _null_ _null_ _null_ "" f)); +DESCR("degrees to radians"); +DATA(insert OID = 1610 ( pi PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 701 "" _null_ _null_ _null_ _null_ dpi _null_ _null_ _null_ "" f)); +DESCR("PI"); + +DATA(insert OID = 1618 ( interval_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 701" _null_ _null_ _null_ _null_ interval_mul _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1620 ( ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ ascii _null_ _null_ _null_ "" f)); +DESCR("convert first char to int4"); +DATA(insert OID = 1621 ( chr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "23" _null_ _null_ _null_ _null_ chr _null_ _null_ _null_ "" f)); +DESCR("convert int4 to char"); +DATA(insert OID = 1622 ( repeat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ repeat _null_ _null_ _null_ "" f)); +DESCR("replicate string n times"); + +DATA(insert OID = 1623 ( similar_escape PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ similar_escape _null_ _null_ _null_ "" f)); +DESCR("convert SQL99 regexp pattern to POSIX style"); + +DATA(insert OID = 1624 ( mul_d_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "701 1186" _null_ _null_ _null_ _null_ mul_d_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1631 ( bpcharlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1632 ( bpcharnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1633 ( texticlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1634 ( texticnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticnlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1635 ( nameiclike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameiclike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1636 ( nameicnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicnlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1637 ( like_escape PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ like_escape _null_ _null_ _null_ "" f)); +DESCR("convert LIKE pattern to use backslash escapes"); + +DATA(insert OID = 1656 ( bpcharicregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1657 ( bpcharicregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1658 ( bpcharregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1659 ( bpcharregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1660 ( bpchariclike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1661 ( bpcharicnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticnlike _null_ _null_ _null_ "" f)); + +/* Oracle Compatibility Related Functions - By Edmund Mergl */ +DATA(insert OID = 868 ( strpos PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define STRPOSFUNCOID 868 +DATA(insert OID = 870 ( lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ lower _null_ _null_ _null_ "" f)); +DESCR("lowercase"); +DATA(insert OID = 871 ( upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ upper _null_ _null_ _null_ "" f)); +DESCR("uppercase"); +DATA(insert OID = 872 ( initcap PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ initcap _null_ _null_ _null_ "" f)); +DESCR("capitalize each word"); +DATA(insert OID = 873 ( lpad PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 25" _null_ _null_ _null_ _null_ lpad _null_ _null_ _null_ "" f)); +DESCR("left-pad string to length"); +#define LPADFUNCOID 873 +DATA(insert OID = 874 ( rpad PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 25" _null_ _null_ _null_ _null_ rpad _null_ _null_ _null_ "" f)); +DESCR("right-pad string to length"); +#define RPADFUNCOID 874 +DATA(insert OID = 875 ( ltrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ ltrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from left end of string"); +#define LTRIMFUNCOID 875 +DATA(insert OID = 876 ( rtrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ rtrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from right end of string"); +#define RTRIMFUNCOID 876 +DATA(insert OID = 877 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr_orclcompat _null_ _null_ _null_ "" f)); +#define SUBSTRFUNCOID 877 +DESCR("extract portion of string"); +DATA(insert OID = 3814 ( empty_blob PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 88 "" _null_ _null_ _null_ _null_ get_empty_blob _null_ _null_ _null_ "" f)); +DESCR("return empty blob"); +DATA(insert OID = 3205 ( substrb PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ substrb_with_lenth - _null_ _null_ "" f)); +DESCR("return portion of byte string"); +#define SUBSTRBWITHLENFUNCOID 3205 +DATA(insert OID = 3206 ( substrb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ substrb_without_lenth - _null_ _null_ "" f)); +DESCR("return portion of byte string"); +#define SUBSTRBNOLENFUNCOID 3206 +DATA(insert OID = 878 ( translate PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ translate _null_ _null_ _null_ "" f)); +DESCR("map a set of characters appearing in string"); +DATA(insert OID = 879 ( lpad PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ "select pg_catalog.lpad($1, $2, '' '')" _null_ _null_ _null_ "" f)); +DESCR("left-pad string to length"); +#define LPADPARAFUNCOID 879 +DATA(insert OID = 880 ( rpad PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ "select pg_catalog.rpad($1, $2, '' '')" _null_ _null_ _null_ "" f)); +DESCR("right-pad string to length"); +#define RPADPARAFUNCOID 880 +DATA(insert OID = 881 ( ltrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ ltrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from left end of string"); +#define LTRIMPARAFUNCOID 881 +DATA(insert OID = 882 ( rtrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ rtrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from right end of string"); +#define RTRIMPARAFUNCOID 882 +DATA(insert OID = 883 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRNOLENFUNCOID 883 +DATA(insert OID = 884 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ btrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from both ends of string"); +#define BTRIMPARAFUNCOID 884 +DATA(insert OID = 885 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ btrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from both ends of string"); +#define BTRIMFUNCOID 885 + +DATA(insert OID = 3182 ( substring_inner PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRINNFUNCOID 3182 +DATA(insert OID = 3183 ( substring_inner PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRINNNOLENFUNCOID 3183 +DATA(insert OID = 936 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr_null _null_ _null_ _null_ "" f)); +#define TEXTSUBSTRINGFUNCOID 936 +DESCR("extract portion of string"); +DATA(insert OID = 937 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len_null _null_ _null_ _null_ "" f)); +#define TEXTSUBSTRINGNOLENFUNCOID 937 +DESCR("extract portion of string"); +DATA(insert OID = 2087 ( replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ replace_text _null_ _null_ _null_ "" f)); +DESCR("replace all occurrences in string of old_substr with new_substr"); +DATA(insert OID = 2284 ( regexp_replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ textregexreplace_noopt _null_ _null_ _null_ "" f)); +DESCR("replace text using regexp"); +DATA(insert OID = 2285 ( regexp_replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 25 "25 25 25 25" _null_ _null_ _null_ _null_ textregexreplace _null_ _null_ _null_ "" f)); +DESCR("replace text using regexp"); +DATA(insert OID = 2763 ( regexp_matches PGNSP PGUID 12 1 1 0 0 f f f f t t i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ regexp_matches_no_flags _null_ _null_ _null_ "" f)); +DESCR("find all match groups for regexp"); +DATA(insert OID = 2764 ( regexp_matches PGNSP PGUID 12 1 10 0 0 f f f f t t i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ regexp_matches _null_ _null_ _null_ "" f)); +DESCR("find all match groups for regexp"); +DATA(insert OID = 2088 ( split_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 23" _null_ _null_ _null_ _null_ split_text _null_ _null_ _null_ "" f)); +DESCR("split string by field_sep and return field_num"); +DATA(insert OID = 2765 ( regexp_split_to_table PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 25 "25 25" _null_ _null_ _null_ _null_ regexp_split_to_table_no_flags _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2766 ( regexp_split_to_table PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ regexp_split_to_table _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2767 ( regexp_split_to_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ regexp_split_to_array_no_flags _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2768 ( regexp_split_to_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ regexp_split_to_array _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2089 ( to_hex PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "23" _null_ _null_ _null_ _null_ to_hex32 _null_ _null_ _null_ "" f)); +DESCR("convert int4 number to hex"); +DATA(insert OID = 2090 ( to_hex PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "20" _null_ _null_ _null_ _null_ to_hex64 _null_ _null_ _null_ "" f)); +DESCR("convert int8 number to hex"); + +/* for character set encoding support */ + +/* return database encoding name */ +DATA(insert OID = 1039 ( getdatabaseencoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ getdatabaseencoding _null_ _null_ _null_ "" f)); +DESCR("encoding name of current database"); + +/* return client encoding name i.e. session encoding */ +DATA(insert OID = 810 ( pg_client_encoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pg_client_encoding _null_ _null_ _null_ "" f)); +DESCR("encoding name of current database"); + +DATA(insert OID = 1713 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "17 19" _null_ _null_ _null_ _null_ length_in_encoding _null_ _null_ _null_ "" f)); +DESCR("length of string in specified encoding"); + +DATA(insert OID = 1714 ( convert_from PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "17 19" _null_ _null_ _null_ _null_ pg_convert_from _null_ _null_ _null_ "" f)); +DESCR("convert string with specified source encoding name"); + +DATA(insert OID = 1717 ( convert_to PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "25 19" _null_ _null_ _null_ _null_ pg_convert_to _null_ _null_ _null_ "" f)); +DESCR("convert string with specified destination encoding name"); + +DATA(insert OID = 1813 ( convert PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 17 "17 19 19" _null_ _null_ _null_ _null_ pg_convert _null_ _null_ _null_ "" f)); +DESCR("convert string with specified encoding names"); + +DATA(insert OID = 1264 ( pg_char_to_encoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "19" _null_ _null_ _null_ _null_ PG_char_to_encoding _null_ _null_ _null_ "" f)); +DESCR("convert encoding name to encoding id"); + +DATA(insert OID = 1597 ( pg_encoding_to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "23" _null_ _null_ _null_ _null_ PG_encoding_to_char _null_ _null_ _null_ "" f)); +DESCR("convert encoding id to encoding name"); + +DATA(insert OID = 2319 ( pg_encoding_max_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ pg_encoding_max_length_sql _null_ _null_ _null_ "" f)); +DESCR("maximum octet length of a character in given encoding"); + +DATA(insert OID = 1638 ( oidgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1639 ( oidge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidge _null_ _null_ _null_ "" f)); + +/* System-view support functions */ +DATA(insert OID = 1573 ( pg_get_ruledef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_ruledef _null_ _null_ _null_ "" f)); +DESCR("source text of a rule"); +DATA(insert OID = 1640 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "25" _null_ _null_ _null_ _null_ pg_get_viewdef_name _null_ _null_ _null_ "" f)); +DESCR("select statement of a view"); +DATA(insert OID = 1641 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_viewdef _null_ _null_ _null_ "" f)); +DESCR("select statement of a view"); +DATA(insert OID = 1642 ( pg_get_userbyid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "26" _null_ _null_ _null_ _null_ pg_get_userbyid _null_ _null_ _null_ "" f)); +DESCR("role name by OID (with fallback)"); +DATA(insert OID = 1643 ( pg_get_indexdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_indexdef _null_ _null_ _null_ "" f)); +DESCR("index description"); +DATA(insert OID = 1662 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_triggerdef _null_ _null_ _null_ "" f)); +DESCR("trigger description"); +DATA(insert OID = 1387 ( pg_get_constraintdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_constraintdef _null_ _null_ _null_ "" f)); +DESCR("constraint description"); +DATA(insert OID = 1716 ( pg_get_expr PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "194 26" _null_ _null_ _null_ _null_ pg_get_expr _null_ _null_ _null_ "" f)); +DESCR("deparse an encoded expression"); +DATA(insert OID = 1665 ( pg_get_serial_sequence PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 25" _null_ _null_ _null_ _null_ pg_get_serial_sequence _null_ _null_ _null_ "" f)); +DESCR("name of sequence for a serial column"); +DATA(insert OID = 2098 ( pg_get_functiondef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2249 "26" "{26,23,25}" "{i,o,o}" "{funcid,headerlines,definition}" _null_ pg_get_functiondef _null_ _null_ _null_ "" f)); +DESCR("definition of a function"); +DATA(insert OID = 2162 ( pg_get_function_arguments PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_arguments _null_ _null_ _null_ "" f)); +DESCR("argument list of a function"); +DATA(insert OID = 2232 ( pg_get_function_identity_arguments PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_identity_arguments _null_ _null_ _null_ "" f)); +DESCR("identity argument list of a function"); +DATA(insert OID = 2165 ( pg_get_function_result PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_result _null_ _null_ _null_ "" f)); +DESCR("result type of a function"); + +DATA(insert OID = 1686 ( pg_get_keywords PGNSP PGUID 12 10 400 0 0 f f f f t t s 0 0 2249 "" "{25,18,25}" "{o,o,o}" "{word,catcode,catdesc}" _null_ pg_get_keywords _null_ _null_ _null_ "" f)); +DESCR("list of SQL keywords"); + +DATA(insert OID = 2289 ( pg_options_to_table PGNSP PGUID 12 1 3 0 0 f f f f t t s 1 0 2249 "1009" "{1009,25,25}" "{i,o,o}" "{options_array,option_name,option_value}" _null_ pg_options_to_table _null_ _null_ _null_ "" f)); +DESCR("convert generic options array to name/value table"); + +DATA(insert OID = 1619 ( pg_typeof PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 2206 "2276" _null_ _null_ _null_ _null_ pg_typeof _null_ _null_ _null_ "" f)); +DESCR("type of the argument"); +DATA(insert OID = 3162 ( pg_collation_for PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 25 "2276" _null_ _null_ _null_ _null_ pg_collation_for _null_ _null_ _null_ "" f)); +DESCR("collation of the argument; implementation of the COLLATION FOR expression"); + +/* Deferrable unique constraint trigger */ +DATA(insert OID = 1250 ( unique_key_recheck PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ unique_key_recheck _null_ _null_ _null_ "" f)); +DESCR("deferred UNIQUE constraint check"); + +/* Generic referential integrity constraint triggers */ +DATA(insert OID = 1644 ( RI_FKey_check_ins PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_check_ins _null_ _null_ _null_ "" f)); +DESCR("referential integrity FOREIGN KEY ... REFERENCES"); +DATA(insert OID = 1645 ( RI_FKey_check_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_check_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity FOREIGN KEY ... REFERENCES"); +DATA(insert OID = 1646 ( RI_FKey_cascade_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_cascade_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE CASCADE"); +DATA(insert OID = 1647 ( RI_FKey_cascade_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_cascade_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE CASCADE"); +DATA(insert OID = 1648 ( RI_FKey_restrict_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_restrict_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE RESTRICT"); +DATA(insert OID = 1649 ( RI_FKey_restrict_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_restrict_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE RESTRICT"); +DATA(insert OID = 1650 ( RI_FKey_setnull_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setnull_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE SET NULL"); +DATA(insert OID = 1651 ( RI_FKey_setnull_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setnull_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE SET NULL"); +DATA(insert OID = 1652 ( RI_FKey_setdefault_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setdefault_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE SET DEFAULT"); +DATA(insert OID = 1653 ( RI_FKey_setdefault_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setdefault_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE SET DEFAULT"); +DATA(insert OID = 1654 ( RI_FKey_noaction_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_noaction_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE NO ACTION"); +DATA(insert OID = 1655 ( RI_FKey_noaction_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_noaction_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE NO ACTION"); + +DATA(insert OID = 1666 ( varbiteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ biteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1667 ( varbitne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1668 ( varbitge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1669 ( varbitgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1670 ( varbitle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1671 ( varbitlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1672 ( varbitcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1562 1562" _null_ _null_ _null_ _null_ bitcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1673 ( bitand PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bit_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1674 ( bitor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bit_or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1675 ( bitxor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bitxor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1676 ( bitnot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ bitnot _null_ _null_ _null_ "" f)); +DATA(insert OID = 1677 ( bitshiftleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitshiftleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 1678 ( bitshiftright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitshiftright _null_ _null_ _null_ "" f)); +DATA(insert OID = 1679 ( bitcat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1562 "1562 1562" _null_ _null_ _null_ _null_ bitcat _null_ _null_ _null_ "" f)); +DATA(insert OID = 1680 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 23" _null_ _null_ _null_ _null_ bitsubstr _null_ _null_ _null_ "" f)); +#define BITSUBSTRINGFUNOID 1680 +DESCR("extract portion of bitstring"); +DATA(insert OID = 1681 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bitlength _null_ _null_ _null_ "" f)); +DESCR("bitstring length"); +DATA(insert OID = 1682 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bitoctetlength _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 1683 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "23 23" _null_ _null_ _null_ _null_ bitfromint4 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to bitstring"); +DATA(insert OID = 1684 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bittoint4 _null_ _null_ _null_ "" f)); +DESCR("convert bitstring to int4"); + +DATA(insert OID = 1685 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 16" _null_ _null_ _null_ _null_ bit _null_ _null_ _null_ "" f)); +DESCR("adjust bit() to typmod length"); +DATA(insert OID = 3158 ( varbit_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ varbit_transform _null_ _null_ _null_ "" f)); +DESCR("transform a varbit length coercion"); +DATA(insert OID = 1687 ( varbit PGNSP PGUID 12 1 0 0 varbit_transform f f f f t f i 3 0 1562 "1562 23 16" _null_ _null_ _null_ _null_ varbit _null_ _null_ _null_ "" f)); +DESCR("adjust varbit() to typmod length"); + +DATA(insert OID = 1698 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 1560" _null_ _null_ _null_ _null_ bitposition _null_ _null_ _null_ "" f)); +DESCR("position of sub-bitstring"); +#define BITPOSITIONFUNCOID 1698 +DATA(insert OID = 1699 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitsubstr_no_len _null_ _null_ _null_ "" f)); +#define BITSUBSTRINGNOLENFUNCOID 1699 +DESCR("extract portion of bitstring"); + +DATA(insert OID = 3030 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 1560 "1560 1560 23 23" _null_ _null_ _null_ _null_ bitoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of bitstring"); +DATA(insert OID = 3031 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 1560 23" _null_ _null_ _null_ _null_ bitoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of bitstring"); +DATA(insert OID = 3032 ( get_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 23" _null_ _null_ _null_ _null_ bitgetbit _null_ _null_ _null_ "" f)); +DESCR("get bit"); +DATA(insert OID = 3033 ( set_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 23" _null_ _null_ _null_ _null_ bitsetbit _null_ _null_ _null_ "" f)); +DESCR("set bit"); + +/* for mac type support */ +DATA(insert OID = 436 ( macaddr_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "2275" _null_ _null_ _null_ _null_ macaddr_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 437 ( macaddr_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "829" _null_ _null_ _null_ _null_ macaddr_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 753 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "829" _null_ _null_ _null_ _null_ macaddr_trunc _null_ _null_ _null_ "" f)); +DESCR("MAC manufacturer fields"); + +DATA(insert OID = 830 ( macaddr_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 831 ( macaddr_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 832 ( macaddr_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 833 ( macaddr_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 834 ( macaddr_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 835 ( macaddr_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 836 ( macaddr_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "829 829" _null_ _null_ _null_ _null_ macaddr_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3144 ( macaddr_not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "829" _null_ _null_ _null_ _null_ macaddr_not _null_ _null_ _null_ "" f)); +DATA(insert OID = 3145 ( macaddr_and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 829 "829 829" _null_ _null_ _null_ _null_ macaddr_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 3146 ( macaddr_or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 829 "829 829" _null_ _null_ _null_ _null_ macaddr_or _null_ _null_ _null_ "" f)); + +/* for inet type support */ +DATA(insert OID = 910 ( inet_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "2275" _null_ _null_ _null_ _null_ inet_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 911 ( inet_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "869" _null_ _null_ _null_ _null_ inet_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* for cidr type support */ +DATA(insert OID = 1267 ( cidr_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "2275" _null_ _null_ _null_ _null_ cidr_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1427 ( cidr_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "650" _null_ _null_ _null_ _null_ cidr_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* these are used for both inet and cidr */ +DATA(insert OID = 920 ( network_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 921 ( network_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 922 ( network_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 923 ( network_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 924 ( network_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 925 ( network_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 926 ( network_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "869 869" _null_ _null_ _null_ _null_ network_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 927 ( network_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 928 ( network_subeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_subeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 929 ( network_sup PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sup _null_ _null_ _null_ "" f)); +DATA(insert OID = 930 ( network_supeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_supeq _null_ _null_ _null_ "" f)); + +/* inet/cidr functions */ +DATA(insert OID = 598 ( abbrev PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ inet_abbrev _null_ _null_ _null_ "" f)); +DESCR("abbreviated display of inet value"); +DATA(insert OID = 599 ( abbrev PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "650" _null_ _null_ _null_ _null_ cidr_abbrev _null_ _null_ _null_ "" f)); +DESCR("abbreviated display of cidr value"); +DATA(insert OID = 605 ( set_masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 23" _null_ _null_ _null_ _null_ inet_set_masklen _null_ _null_ _null_ "" f)); +DESCR("change netmask of inet"); +DATA(insert OID = 635 ( set_masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 650 "650 23" _null_ _null_ _null_ _null_ cidr_set_masklen _null_ _null_ _null_ "" f)); +DESCR("change netmask of cidr"); +DATA(insert OID = 711 ( family PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ network_family _null_ _null_ _null_ "" f)); +DESCR("address family (4 for IPv4, 6 for IPv6)"); +DATA(insert OID = 683 ( network PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "869" _null_ _null_ _null_ _null_ network_network _null_ _null_ _null_ "" f)); +DESCR("network part of address"); +DATA(insert OID = 696 ( netmask PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_netmask _null_ _null_ _null_ "" f)); +DESCR("netmask of address"); +DATA(insert OID = 697 ( masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ network_masklen _null_ _null_ _null_ "" f)); +DESCR("netmask length"); +DATA(insert OID = 698 ( broadcast PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_broadcast _null_ _null_ _null_ "" f)); +DESCR("broadcast address of network"); +DATA(insert OID = 699 ( host PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ network_host _null_ _null_ _null_ "" f)); +DESCR("show address octets only"); +DATA(insert OID = 730 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ network_show _null_ _null_ _null_ "" f)); +DESCR("show all parts of inet/cidr value"); +DATA(insert OID = 1362 ( hostmask PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_hostmask _null_ _null_ _null_ "" f)); +DESCR("hostmask of address"); +DATA(insert OID = 1715 ( cidr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "869" _null_ _null_ _null_ _null_ inet_to_cidr _null_ _null_ _null_ "" f)); +DESCR("convert inet to cidr"); + +DATA(insert OID = 2196 ( inet_client_addr PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 869 "" _null_ _null_ _null_ _null_ inet_client_addr _null_ _null_ _null_ "" f)); +DESCR("inet address of the client"); +DATA(insert OID = 2197 ( inet_client_port PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 23 "" _null_ _null_ _null_ _null_ inet_client_port _null_ _null_ _null_ "" f)); +DESCR("client's port number for this connection"); +DATA(insert OID = 2198 ( inet_server_addr PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 869 "" _null_ _null_ _null_ _null_ inet_server_addr _null_ _null_ _null_ "" f)); +DESCR("inet address of the server"); +DATA(insert OID = 2199 ( inet_server_port PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 23 "" _null_ _null_ _null_ _null_ inet_server_port _null_ _null_ _null_ "" f)); +DESCR("server's port number for this connection"); + +DATA(insert OID = 2627 ( inetnot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ inetnot _null_ _null_ _null_ "" f)); +DATA(insert OID = 2628 ( inetand PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ inetand _null_ _null_ _null_ "" f)); +DATA(insert OID = 2629 ( inetor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ inetor _null_ _null_ _null_ "" f)); +DATA(insert OID = 2630 ( inetpl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 20" _null_ _null_ _null_ _null_ inetpl _null_ _null_ _null_ "" f)); +DATA(insert OID = 2631 ( int8pl_inet PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 869 "20 869" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2632 ( inetmi_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 20" _null_ _null_ _null_ _null_ inetmi_int8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 2633 ( inetmi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "869 869" _null_ _null_ _null_ _null_ inetmi _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1690 ( time_mi_time PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1083 1083" _null_ _null_ _null_ _null_ time_mi_time _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1691 ( boolle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1692 ( boolge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1693 ( btboolcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 16" _null_ _null_ _null_ _null_ btboolcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1688 ( time_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1083" _null_ _null_ _null_ _null_ time_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 1696 ( timetz_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1266" _null_ _null_ _null_ _null_ timetz_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 1697 ( interval_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1186" _null_ _null_ _null_ _null_ interval_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); + + +/* OID's 1700 - 1799 NUMERIC data type */ +DATA(insert OID = 1701 ( numeric_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1700 "2275 26 23" _null_ _null_ _null_ _null_ numeric_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1702 ( numeric_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1700" _null_ _null_ _null_ _null_ numeric_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2917 ( numerictypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ numerictypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2918 ( numerictypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ numerictypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 3157 ( numeric_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ numeric_transform _null_ _null_ _null_ "" f)); +DESCR("transform a numeric length coercion"); +DATA(insert OID = 1703 ( numeric PGNSP PGUID 12 1 0 0 numeric_transform f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric _null_ _null_ _null_ "" f)); +DESCR("adjust numeric to typmod precision/scale"); +DATA(insert OID = 1704 ( numeric_abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 1705 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1706 ( sign PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sign _null_ _null_ _null_ "" f)); +DESCR("sign of value"); +DATA(insert OID = 1707 ( round PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric_round _null_ _null_ _null_ "" f)); +DESCR("value rounded to 'scale'"); +DATA(insert OID = 1708 ( round PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.round($1,0)" _null_ _null_ _null_ "" f)); +DESCR("value rounded to 'scale' of zero"); +DATA(insert OID = 1709 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric_trunc _null_ _null_ _null_ "" f)); +DESCR("value truncated to 'scale'"); +DATA(insert OID = 1710 ( trunc PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.trunc($1,0)" _null_ _null_ _null_ "" f)); +DESCR("value truncated to 'scale' of zero"); +DATA(insert OID = 1711 ( ceil PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2167 ( ceiling PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 1712 ( floor PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_floor _null_ _null_ _null_ "" f)); +DESCR("nearest integer <= value"); +DATA(insert OID = 1718 ( numeric_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1719 ( numeric_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1720 ( numeric_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1721 ( numeric_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1722 ( numeric_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1723 ( numeric_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1724 ( numeric_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1725 ( numeric_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1726 ( numeric_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1727 ( numeric_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1728 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 1729 ( numeric_mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 1730 ( sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +DATA(insert OID = 1731 ( numeric_sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +DATA(insert OID = 1732 ( exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_exp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 1733 ( numeric_exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_exp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 1734 ( ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ln _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1735 ( numeric_ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ln _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1736 ( log PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_log _null_ _null_ _null_ "" f)); +DESCR("logarithm base m of n"); +DATA(insert OID = 1737 ( numeric_log PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_log _null_ _null_ _null_ "" f)); +DESCR("logarithm base m of n"); +DATA(insert OID = 1738 ( pow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +DATA(insert OID = 2169 ( power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +DATA(insert OID = 1739 ( numeric_power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DATA(insert OID = 1740 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "23" _null_ _null_ _null_ _null_ int4_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int4 to numeric"); +DATA(insert OID = 1741 ( log PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.log(10, $1)" _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1742 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "700" _null_ _null_ _null_ _null_ float4_numeric _null_ _null_ _null_ "" f)); +DESCR("convert float4 to numeric"); +DATA(insert OID = 1743 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "701" _null_ _null_ _null_ _null_ float8_numeric _null_ _null_ _null_ "" f)); +DESCR("convert float8 to numeric"); +DATA(insert OID = 1744 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1700" _null_ _null_ _null_ _null_ numeric_int4 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int4"); +DATA(insert OID = 1745 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1700" _null_ _null_ _null_ _null_ numeric_float4 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to float4"); +DATA(insert OID = 1746 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1700" _null_ _null_ _null_ _null_ numeric_float8 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to float8"); +#define NUMTOFLOAT8FUNCOID 1746 +DATA(insert OID = 1973 ( div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div_trunc _null_ _null_ _null_ "" f)); +DESCR("trunc(x/y)"); +DATA(insert OID = 1980 ( numeric_div_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div_trunc _null_ _null_ _null_ "" f)); +DESCR("trunc(x/y)"); +DATA(insert OID = 2170 ( width_bucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "1700 1700 1700 23" _null_ _null_ _null_ _null_ width_bucket_numeric _null_ _null_ _null_ "" f)); +DESCR("bucket number of operand in equidepth histogram"); + +DATA(insert OID = 1747 ( time_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1186" _null_ _null_ _null_ _null_ time_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1748 ( time_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1186" _null_ _null_ _null_ _null_ time_mi_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1749 ( timetz_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1186" _null_ _null_ _null_ _null_ timetz_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1750 ( timetz_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1186" _null_ _null_ _null_ _null_ timetz_mi_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1764 ( numeric_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_inc _null_ _null_ _null_ "" f)); +DESCR("increment by one"); +DATA(insert OID = 1766 ( numeric_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1767 ( numeric_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1769 ( numeric_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 1700" _null_ _null_ _null_ _null_ numeric_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3283 ( numeric_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ numeric_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 1771 ( numeric_uminus PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_uminus _null_ _null_ _null_ "" f)); +DATA(insert OID = 1779 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1700" _null_ _null_ _null_ _null_ numeric_int8 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int8"); +DATA(insert OID = 1781 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ int8_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int8 to numeric"); +DATA(insert OID = 1782 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "21" _null_ _null_ _null_ _null_ int2_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int2 to numeric"); +DATA(insert OID = 1783 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "1700" _null_ _null_ _null_ _null_ numeric_int2 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int2"); + +/* formatting */ +DATA(insert OID = 1770 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1184 25" _null_ _null_ _null_ _null_ timestamptz_to_char _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZ2CHARFUNCOID 1770 +DESCR("format timestamp with time zone to text"); +DATA(insert OID = 1772 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1700 25" _null_ _null_ _null_ _null_ numeric_to_char _null_ _null_ _null_ "" f)); +#define NUMERIC2CHARFUNCOID 1772 +DESCR("format numeric to text"); +DATA(insert OID = 1773 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "23 25" _null_ _null_ _null_ _null_ int4_to_char _null_ _null_ _null_ "" f)); +#define INTEGER2CHARFUNCOID 1773 +DESCR("format int4 to text"); +DATA(insert OID = 1774 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "20 25" _null_ _null_ _null_ _null_ int8_to_char _null_ _null_ _null_ "" f)); +#define BIGINT2CHARFUNCOID 1774 +DESCR("format int8 to text"); +DATA(insert OID = 1775 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "700 25" _null_ _null_ _null_ _null_ float4_to_char _null_ _null_ _null_ "" f)); +DESCR("format float4 to text"); +DATA(insert OID = 1776 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "701 25" _null_ _null_ _null_ _null_ float8_to_char _null_ _null_ _null_ "" f)); +DESCR("format float8 to text"); +DATA(insert OID = 1777 ( to_number PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1700 "25 25" _null_ _null_ _null_ _null_ numeric_to_number _null_ _null_ _null_ "" f)); +DESCR("convert text to numeric"); +DATA(insert OID = 1778 ( to_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1114 "25 25" _null_ _null_ _null_ _null_ to_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp with time zone"); +#define TOTIMESTAMPFUNCOID 1778 +DATA(insert OID = 3207 ( to_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "25" _null_ _null_ _null_ _null_ to_timestamp_default_format _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp without time zone"); +DATA(insert OID = 1780 ( to_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1114 "25 25" _null_ _null_ _null_ _null_ to_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to date"); +#define TODATEFUNCOID 1780 +DATA(insert OID = 1768 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1186 25" _null_ _null_ _null_ _null_ interval_to_char _null_ _null_ _null_ "" f)); +DESCR("format interval to text"); + +DATA(insert OID = 1282 ( quote_ident PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_ident _null_ _null_ _null_ "" f)); +DESCR("quote an identifier for usage in a querystring"); +DATA(insert OID = 1283 ( quote_literal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_literal _null_ _null_ _null_ "" f)); +DESCR("quote a literal for usage in a querystring"); +DATA(insert OID = 1285 ( quote_literal PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 25 "2283" _null_ _null_ _null_ _null_ "select pg_catalog.quote_literal($1::pg_catalog.text)" _null_ _null_ _null_ "" f)); +DESCR("quote a data value for usage in a querystring"); +DATA(insert OID = 1289 ( quote_nullable PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_nullable _null_ _null_ _null_ "" f)); +DESCR("quote a possibly-null literal for usage in a querystring"); +DATA(insert OID = 1290 ( quote_nullable PGNSP PGUID 14 1 0 0 0 f f f f f f s 1 0 25 "2283" _null_ _null_ _null_ _null_ "select pg_catalog.quote_nullable($1::pg_catalog.text)" _null_ _null_ _null_ "" f)); +DESCR("quote a possibly-null data value for usage in a querystring"); + +DATA(insert OID = 1798 ( oidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2275" _null_ _null_ _null_ _null_ oidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1799 ( oidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ oidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3058 ( concat PGNSP PGUID 12 1 0 2276 0 f f f f f f s 1 0 25 "2276" "{2276}" "{v}" _null_ _null_ text_concat _null_ _null_ _null_ "" f)); +DESCR("concatenate values"); +DATA(insert OID = 3059 ( concat_ws PGNSP PGUID 12 1 0 2276 0 f f f f f f s 2 0 25 "25 2276" "{25,2276}" "{i,v}" _null_ _null_ text_concat_ws _null_ _null_ _null_ "" f)); +DESCR("concatenate values with separators"); +DATA(insert OID = 3060 ( left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_left _null_ _null_ _null_ "" f)); +DESCR("extract the first n characters"); +DATA(insert OID = 3061 ( right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_right _null_ _null_ _null_ "" f)); +DESCR("extract the last n characters"); +DATA(insert OID = 3062 ( reverse PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ text_reverse _null_ _null_ _null_ "" f)); +DESCR("reverse text"); +DATA(insert OID = 3539 ( format PGNSP PGUID 12 1 0 2276 0 f f f f f f s 2 0 25 "25 2276" "{25,2276}" "{i,v}" _null_ _null_ text_format _null_ _null_ _null_ "" f)); +DESCR("format text message"); +DATA(insert OID = 3540 ( format PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 25 "25" _null_ _null_ _null_ _null_ text_format_nv _null_ _null_ _null_ "" f)); +DESCR("format text message"); + +DATA(insert OID = 1810 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ "select pg_catalog.octet_length($1) * 8" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); +DATA(insert OID = 1811 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ "select pg_catalog.octet_length($1) * 8" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); +DATA(insert OID = 1812 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ "select pg_catalog.length($1)" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); + +/* Selectivity estimators for LIKE and related operators */ +DATA(insert OID = 1814 ( iclikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ iclikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of ILIKE"); +DATA(insert OID = 1815 ( icnlikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icnlikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of NOT ILIKE"); +DATA(insert OID = 1816 ( iclikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ iclikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of ILIKE"); +DATA(insert OID = 1817 ( icnlikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icnlikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of NOT ILIKE"); +DATA(insert OID = 1818 ( regexeqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ regexeqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of regex match"); +DATA(insert OID = 1819 ( likesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ likesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of LIKE"); +DATA(insert OID = 1820 ( icregexeqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icregexeqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of case-insensitive regex match"); +DATA(insert OID = 1821 ( regexnesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ regexnesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of regex non-match"); +DATA(insert OID = 1822 ( nlikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ nlikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of NOT LIKE"); +DATA(insert OID = 1823 ( icregexnesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icregexnesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of case-insensitive regex non-match"); +DATA(insert OID = 1824 ( regexeqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ regexeqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of regex match"); +DATA(insert OID = 1825 ( likejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ likejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of LIKE"); +DATA(insert OID = 1826 ( icregexeqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icregexeqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of case-insensitive regex match"); +DATA(insert OID = 1827 ( regexnejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ regexnejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of regex non-match"); +DATA(insert OID = 1828 ( nlikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ nlikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of NOT LIKE"); +DATA(insert OID = 1829 ( icregexnejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icregexnejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of case-insensitive regex non-match"); + +/* Aggregate-related functions */ +DATA(insert OID = 1830 ( float8_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2512 ( float8_var_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_var_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1831 ( float8_var_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_var_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2513 ( float8_stddev_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_stddev_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1832 ( float8_stddev_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_stddev_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1833 ( numeric_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1700" _null_ _null_ _null_ _null_ numeric_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2858 ( numeric_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1700" _null_ _null_ _null_ _null_ numeric_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1834 ( int2_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 21" _null_ _null_ _null_ _null_ int2_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1835 ( int4_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 23" _null_ _null_ _null_ _null_ int4_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1836 ( int8_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 20" _null_ _null_ _null_ _null_ int8_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2746 ( int8_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 20" _null_ _null_ _null_ _null_ int8_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1837 ( numeric_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2514 ( numeric_var_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_var_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1838 ( numeric_var_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_var_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2596 ( numeric_stddev_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_stddev_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1839 ( numeric_stddev_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_stddev_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1840 ( int2_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int2_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1841 ( int4_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int4_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1842 ( int8_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1700 "1700 20" _null_ _null_ _null_ _null_ int8_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1843 ( interval_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1187 "1187 1186" _null_ _null_ _null_ _null_ interval_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1844 ( interval_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1187" _null_ _null_ _null_ _null_ interval_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 5548 ( int1_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 5545" _null_ _null_ _null_ _null_ int1_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1962 ( int2_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 21" _null_ _null_ _null_ _null_ int2_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1963 ( int4_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 23" _null_ _null_ _null_ _null_ int4_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1964 ( int8_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1016" _null_ _null_ _null_ _null_ int8_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2805 ( int8inc_float8_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 20 "20 701 701" _null_ _null_ _null_ _null_ int8inc_float8_float8 _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2806 ( float8_regr_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1022 "1022 701 701" _null_ _null_ _null_ _null_ float8_regr_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2807 ( float8_regr_sxx PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_sxx _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2808 ( float8_regr_syy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_syy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2809 ( float8_regr_sxy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_sxy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2810 ( float8_regr_avgx PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_avgx _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2811 ( float8_regr_avgy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_avgy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2812 ( float8_regr_r2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_r2 _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2813 ( float8_regr_slope PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_slope _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2814 ( float8_regr_intercept PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_intercept _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2815 ( float8_covar_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_covar_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2816 ( float8_covar_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_covar_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2817 ( float8_corr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_corr _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); + +DATA(insert OID = 3535 ( string_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2281 "2281 25 25" _null_ _null_ _null_ _null_ string_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +#define STRINGAGGTRANSFNFUNCOID 3535 +#ifdef PGXC +DATA(insert OID = 2966 ( float8_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 1022" _null_ _null_ _null_ _null_ float8_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2964 ( numeric_avg_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1231" _null_ _null_ _null_ _null_ numeric_avg_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2968 ( numeric_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1231" _null_ _null_ _null_ _null_ numeric_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2967 ( interval_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1187 "1187 1187" _null_ _null_ _null_ _null_ interval_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2965 ( int8_avg_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 1016" _null_ _null_ _null_ _null_ int8_avg_collect _null_ _null_ _null_ "" f)); +DESCR("AVG(int) collection function"); +DATA(insert OID = 2996 ( int8_sum_to_int8 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8_sum_to_int8 _null_ _null_ _null_ "" f)); +DESCR("SUM(int) collection function"); +DATA(insert OID = 2995 ( float8_regr_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 1022" _null_ _null_ _null_ _null_ float8_regr_collect _null_ _null_ _null_ "" f)); +DESCR("REGR_...(double, double) collection function"); +#endif +DATA(insert OID = 3536 ( string_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "2281" _null_ _null_ _null_ _null_ string_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 3538 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into a string"); +#define STRINGAGGFUNCOID 3538 +DATA(insert OID = 3543 ( bytea_string_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2281 "2281 17 17" _null_ _null_ _null_ _null_ bytea_string_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 3544 ( bytea_string_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytea_string_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 3545 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into a bytea"); +#define BYTEASTRINGAGGFUNCOID 3545 + +DATA(insert OID = 4600 ( checksum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("checksum aggregate text input into a numeric"); +DATA(insert OID = 4601 ( checksumtext_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1700 "1700 25" _null_ _null_ _null_ _null_ checksumtext_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("checksumtext aggregate transition function"); + +/* To ASCII conversion */ +DATA(insert OID = 1845 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ to_ascii_default _null_ _null_ _null_ "" f)); +DESCR("encode text from DB encoding to ASCII text"); +DATA(insert OID = 1846 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ to_ascii_enc _null_ _null_ _null_ "" f)); +DESCR("encode text from encoding to ASCII text"); +DATA(insert OID = 1847 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 19" _null_ _null_ _null_ _null_ to_ascii_encname _null_ _null_ _null_ "" f)); +DESCR("encode text from encoding to ASCII text"); + +DATA(insert OID = 1848 ( interval_pl_time PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1083 "1186 1083" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1850 ( int28eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1851 ( int28ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1852 ( int28lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1853 ( int28gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1854 ( int28le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1855 ( int28ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1856 ( int82eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1857 ( int82ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1858 ( int82lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1859 ( int82gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1860 ( int82le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1861 ( int82ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 6101 ( int1and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1and _null_ _null_ _null_ "" f)); +DESCR("int1 and int1"); +DATA(insert OID = 6102 ( int1or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1or _null_ _null_ _null_ "" f)); +DESCR("int1 or int1"); +DATA(insert OID = 6103 ( int1xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1xor _null_ _null_ _null_ "" f)); +DESCR("int1 xor int1"); +DATA(insert OID = 6104 ( int1not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1not _null_ _null_ _null_ "" f)); +DESCR("int1 not int1"); +DATA(insert OID = 6105 ( int1shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 23" _null_ _null_ _null_ _null_ int1shl _null_ _null_ _null_ "" f)); +DESCR("left shift"); +DATA(insert OID = 6106 ( int1shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 23" _null_ _null_ _null_ _null_ int1shr _null_ _null_ _null_ "" f)); +DESCR("right shift"); +DATA(insert OID = 1892 ( int2and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1893 ( int2or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1894 ( int2xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1895 ( int2not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1896 ( int2shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 23" _null_ _null_ _null_ _null_ int2shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1897 ( int2shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 23" _null_ _null_ _null_ _null_ int2shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1898 ( int4and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1899 ( int4or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1900 ( int4xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1901 ( int4not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1902 ( int4shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1903 ( int4shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1904 ( int8and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1905 ( int8or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1906 ( int8xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1907 ( int8not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1908 ( int8shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int8shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1909 ( int8shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int8shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1910 ( int8up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8up _null_ _null_ _null_ "" f)); +DATA(insert OID = 6107 ( int1up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1up _null_ _null_ _null_ "" f)); +DESCR("int1up"); +DATA(insert OID = 1911 ( int2up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1912 ( int4up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1913 ( float4up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1914 ( float8up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1915 ( numeric_uplus PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_uplus _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1922 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_table_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by username, rel name"); +DATA(insert OID = 1923 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_table_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by username, rel oid"); +DATA(insert OID = 1924 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_table_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by user oid, rel name"); +DATA(insert OID = 1925 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_table_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by user oid, rel oid"); +DATA(insert OID = 1926 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_table_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on relation by rel name"); +DATA(insert OID = 1927 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_table_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on relation by rel oid"); + +DATA(insert OID = 2181 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by username, seq name"); +DATA(insert OID = 2182 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by username, seq oid"); +DATA(insert OID = 2183 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by user oid, seq name"); +DATA(insert OID = 2184 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by user oid, seq oid"); +DATA(insert OID = 2185 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on sequence by seq name"); +DATA(insert OID = 2186 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on sequence by seq oid"); + +DATA(insert OID = 3012 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel name, col name"); +DATA(insert OID = 3013 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel name, col attnum"); +DATA(insert OID = 3014 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel oid, col name"); +DATA(insert OID = 3015 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_id_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel oid, col attnum"); +DATA(insert OID = 3016 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel name, col name"); +DATA(insert OID = 3017 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel name, col attnum"); +DATA(insert OID = 3018 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel oid, col name"); +DATA(insert OID = 3019 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_id_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel oid, col attnum"); +DATA(insert OID = 3020 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel name, col name"); +DATA(insert OID = 3021 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_attnum _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel name, col attnum"); +DATA(insert OID = 3022 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel oid, col name"); +DATA(insert OID = 3023 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_attnum _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel oid, col attnum"); + +DATA(insert OID = 3024 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by username, rel name"); +DATA(insert OID = 3025 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by username, rel oid"); +DATA(insert OID = 3026 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by user oid, rel name"); +DATA(insert OID = 3027 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by user oid, rel oid"); +DATA(insert OID = 3028 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on any column by rel name"); +DATA(insert OID = 3029 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on any column by rel oid"); + + +DATA(insert OID = 3843 ( pg_control_group_config PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pg_control_group_config _null_ _null_ _null_ "" f)); +DESCR("control group config on current node."); +DATA(insert OID = 1928 ( pg_stat_get_numscans PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_numscans _null_ _null_ _null_ "" f)); +DESCR("statistics: number of scans done for table/index"); +DATA(insert OID = 1929 ( pg_stat_get_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples read by seqscan"); +DATA(insert OID = 1930 ( pg_stat_get_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples fetched by idxscan"); +DATA(insert OID = 1931 ( pg_stat_get_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples inserted"); +DATA(insert OID = 1932 ( pg_stat_get_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples updated"); +DATA(insert OID = 1933 ( pg_stat_get_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples deleted"); +DATA(insert OID = 1972 ( pg_stat_get_tuples_hot_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_hot_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples hot updated"); +DATA(insert OID = 2878 ( pg_stat_get_live_tuples PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_live_tuples _null_ _null_ _null_ "" f)); +DESCR("statistics: number of live tuples"); +DATA(insert OID = 2879 ( pg_stat_get_dead_tuples PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_dead_tuples _null_ _null_ _null_ "" f)); +DESCR("statistics: number of dead tuples"); +DATA(insert OID = 1934 ( pg_stat_get_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks fetched"); +DATA(insert OID = 1935 ( pg_stat_get_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks found in cache"); +DATA(insert OID = 2781 ( pg_stat_get_last_vacuum_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_vacuum_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last manual vacuum time for a table"); +DATA(insert OID = 2782 ( pg_stat_get_last_autovacuum_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_autovacuum_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last auto vacuum time for a table"); +DATA(insert OID = 2783 ( pg_stat_get_last_analyze_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_analyze_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last manual analyze time for a table"); +DATA(insert OID = 2784 ( pg_stat_get_last_autoanalyze_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_autoanalyze_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last auto analyze time for a table"); +DATA(insert OID = 3054 ( pg_stat_get_vacuum_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_vacuum_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of manual vacuums for a table"); +DATA(insert OID = 3055 ( pg_stat_get_autovacuum_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autovacuum_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of auto vacuums for a table"); +DATA(insert OID = 3056 ( pg_stat_get_analyze_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_analyze_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of manual analyzes for a table"); +DATA(insert OID = 3057 ( pg_stat_get_autoanalyze_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autoanalyze_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of auto analyzes for a table"); +DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 0 f f f f t t s 0 0 23 "" _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ "" f)); +DESCR("statistics: currently active backend IDs"); +DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,26,20,26,25,25,25,16,1184,1184,1184,1184,869,25,23,25,20}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,pid,usesysid,application_name,state,query,waiting,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,enqueue,query_id}" _null_ pg_stat_get_activity _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active backends"); +DATA(insert OID = 3980 ( pg_stat_get_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,25,25,25,20,20,23,23,23,23,25,25}" "{i,o,o,o,o,o,o,o,o,o,o,o}" "{tid,node_name,db_name,thread_name,query_id,tid,lwtid,ptid,tlevel,smpid,wait_status,wait_event}" _null_ pg_stat_get_status _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active threads"); +DATA(insert OID = 3981 ( pg_stat_get_thread PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,20,23,25,1184}" "{o,o,o,o,o}" "{node_name,pid,lwpid,thread_name,creation_time}" _null_ pg_stat_get_thread _null_ _null_ _null_ "" f)); +DESCR("statistics: information about now active threads"); +DATA(insert OID = 3982 ( pg_stat_get_env PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,23,23,25,25,25}" "{o,o,o,o,o,o,o}" "{node_name,host,process,port,installpath,datapath,log_directory}" _null_ pg_stat_get_env _null_ _null_ _null_ "" f)); +DESCR("statistics: information about environment variables"); +DATA(insert OID = 3947 ( pg_stat_get_sql_count PGNSP PGUID 12 1 0 0 0 f f f f f t s 0 0 2249 "" "{25,25,20,20,20,20,20}" "{o,o,o,o,o,o,o}" "{node_name,user_name,select_count,update_count,insert_count,delete_count,mergeinto_count}" _null_ pg_stat_get_sql_count _null_ _null_ _null_ "" f)); +DESCR("statistics: sql count information about currently node"); + +/* stream replication */ +DATA(insert OID = 3099 ( pg_stat_get_wal_senders PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{20,23,25,25,25,25,1184,1184,25,25,25,25,25,25,25,25,25,25,23,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,sender_pid,local_role,peer_role,peer_state,state,catchup_start,catchup_end,sender_sent_location,sender_write_location,sender_flush_location,sender_replay_location,receiver_received_location,receiver_write_location,receiver_flush_location,receiver_replay_location,sync_percent,sync_state,sync_priority,sync_most_available,channel}" _null_ pg_stat_get_wal_senders _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active wal senders"); +DATA(insert OID = 3819 ( pg_stat_get_wal_receiver PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{23,25,25,25,25,25,25,25,25,25,25,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{receiver_pid,local_role,peer_role,peer_state,state,sender_sent_location,sender_write_location,sender_flush_location,sender_replay_location,receiver_received_location,receiver_write_location,receiver_flush_location,receiver_replay_location,sync_percent,channel}" _null_ pg_stat_get_wal_receiver _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently wal receiver"); +DATA(insert OID = 3499 ( pg_stat_get_stream_replications PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,25}" "{o,o,o,o}" "{local_role,static_connections,db_state,detail_information}" _null_ pg_stat_get_stream_replications _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently stream replication"); +DATA(insert OID = 3785 ( pg_stat_get_data_senders PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{20,23,25,25,25,1184,1184,23,25,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,sender_pid,local_role,peer_role,state,catchup_start,catchup_end,queue_size,queue_lower_tail,queue_header,queue_upper_tail,send_position,receive_position}" _null_ pg_stat_get_data_senders _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active data senders"); +DATA(insert OID = 3972 ( pv_instance_time PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{23,25,20}" "{o,o,o}" "{stat_id,stat_name,value}" _null_ pv_instance_time _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the instance time for various operations"); +DATA(insert OID = 3970 ( pv_os_run_info PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{23,25,1700,25,16}" "{o,o,o,o,o}" "{id,name,value,comments,cumulative}" _null_ pv_os_run_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about system performance."); +DATA(insert OID = 3971 ( pv_session_memory_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,25,21,25,20,20,20}" "{o,o,o,o,o,o,o,o}" "{sessid,sesstype,contextname,level,parent,totalsize,freesize,usedsize}" _null_ pv_session_memory_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session memory detail"); +DATA(insert OID = 3972 ( pv_session_time PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,20}" "{o,o,o,o}" "{sessid,stat_id,stat_name,value}" _null_ pv_session_time _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the session-accumulated time for various operations"); +DATA(insert OID = 3973 ( pg_stat_get_redo_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o}" "{phywrts,phyblkwrt,writetim,avgiotim,lstiotim,miniotim,maxiowtm}" _null_ pg_stat_get_redo_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about pv_redo_stat"); +DATA(insert OID = 3974 ( pv_session_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,25,20}" "{o,o,o,o,o}" "{sessid,statid,statname,statunit,value}" _null_ pv_session_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session status"); +DATA(insert OID = 3975 ( pg_stat_get_file_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{26,26,26,20,20,20,20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o}" "{filenum,dbid,spcid,phyrds,phywrts,phyblkrd,phyblkwrt,readtim,writetim,avgiotim,lstiotim,miniotim,maxiowtm}" _null_ pg_stat_get_file_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about pv_file_stat"); +DATA(insert OID = 3976 ( total_cpu PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ total_cpu _null_ _null_ _null_ "" f)); +DESCR("statistics: MppDB cpu usage."); +DATA(insert OID = 3977 ( get_hostname PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ get_hostname _null_ _null_ _null_ "" f)); +DESCR("statistics: current host name"); +DATA(insert OID = 3978 ( sessionid2pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "2275" _null_ _null_ _null_ _null_ sessionid_to_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: convert session id to pid"); +DATA(insert OID = 3979 ( total_memory PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ total_memory _null_ _null_ _null_ "" f)); +DESCR("statistics: convert session id to pid"); +DATA(insert OID = 3983 ( pv_session_memctx_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 2 0 16 "20 2275" _null_ _null_ _null_ _null_ pv_session_memctx_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session memory detail"); +DATA(insert OID = 3986 ( pg_shared_memory_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,21,25,20,20,20}" "{o,o,o,o,o,o}" "{contextname,level,parent,totalsize,freesize,usedsize}" _null_ pg_shared_memory_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently shared memory detail"); +DATA(insert OID = 3987 ( pg_shared_memctx_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 16 "2275" _null_ _null_ _null_ _null_ pg_shared_memctx_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently shared memory debug detail"); +DATA(insert OID = 2026 ( pg_backend_pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_backend_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: current backend PID"); +DATA(insert OID = 3984 ( pv_session_memory PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{25,23,23,23}" "{o,o,o,o}" "{sessid,init_mem,used_mem,peak_mem}" _null_ pv_session_memory _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the session-accumulated memory for various operations"); +DATA(insert OID = 3985 ( pv_total_memory_detail PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,25,23}" "{o,o,o}" "{nodename,memorytype,memorymbytes}" _null_ pv_total_memory_detail _null_ _null_ _null_ "" f)); +DESCR("total memory information on node"); +DATA(insert OID = 4500 ( gs_control_group_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{25,25,25,25,20,20,20,20,25}" "{o,o,o,o,o,o,o,o,o}" "{name,class,workload,type,gid,shares,limits,rate,cpucores}" _null_ gs_control_group_info _null_ _null_ _null_ "" f)); +DESCR("control group information on node"); +DATA(insert OID = 4501 ( gs_respool_exception_info PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 2249 "2275" "{25,25,25,25,25,20}" "{o,o,o,o,o,o}" "{name,class,workload,rule,type,value}" _null_ gs_respool_exception_info _null_ _null_ _null_ "" f)); +DESCR("resouce pool exception information on node"); +DATA(insert OID = 4502 ( gs_all_control_group_info PGNSP PGUID 12 1 100 0 0 f f f f t t v 0 0 2249 "" "{25,25,20,20,25,25,20,20,20,25}" "{o,o,o,o,o,o,o,o,o,o}" "{name,type,gid,classgid,class,workload,shares,limits,wdlevel,cpucores}" _null_ gs_all_control_group_info _null_ _null_ _null_ "" f)); +DESCR("get all control group information on node"); +DATA(insert OID = 4503 ( gs_cgroup_map_ng_conf PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 16 "2275" _null_ _null_ _null_ _null_ gs_cgroup_map_ng_conf _null_ _null_ _null_ "" f)); +DESCR("logical cluster: map the cgroup information into process for the logical cluster"); +#define PGBACKENDPIDFUNCOID 2026 +DATA(insert OID = 1937 ( pg_stat_get_backend_pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: PID of backend"); +#define PGSTATGETBACKENDPIDFUNCOID 1937 +DATA(insert OID = 1938 ( pg_stat_get_backend_dbid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_dbid _null_ _null_ _null_ "" f)); +DESCR("statistics: database ID of backend"); +DATA(insert OID = 1939 ( pg_stat_get_backend_userid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_userid _null_ _null_ _null_ "" f)); +DESCR("statistics: user ID of backend"); +DATA(insert OID = 1940 ( pg_stat_get_backend_activity PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_activity _null_ _null_ _null_ "" f)); +DESCR("statistics: current query of backend"); +DATA(insert OID = 2853 ( pg_stat_get_backend_waiting PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_waiting _null_ _null_ _null_ "" f)); +DESCR("statistics: is backend currently waiting for a lock"); +DATA(insert OID = 2094 ( pg_stat_get_backend_activity_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_activity_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for current query of backend"); +DATA(insert OID = 2857 ( pg_stat_get_backend_xact_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_xact_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for backend's current transaction"); +DATA(insert OID = 1391 ( pg_stat_get_backend_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for current backend session"); +DATA(insert OID = 1392 ( pg_stat_get_backend_client_addr PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 869 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_client_addr _null_ _null_ _null_ "" f)); +DESCR("statistics: address of client connected to backend"); +DATA(insert OID = 1393 ( pg_stat_get_backend_client_port PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_client_port _null_ _null_ _null_ "" f)); +DESCR("statistics: port number of client connected to backend"); +DATA(insert OID = 1941 ( pg_stat_get_db_numbackends PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_numbackends _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backends in database"); +DATA(insert OID = 1942 ( pg_stat_get_db_xact_commit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_xact_commit _null_ _null_ _null_ "" f)); +DESCR("statistics: transactions committed"); +DATA(insert OID = 1943 ( pg_stat_get_db_xact_rollback PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_xact_rollback _null_ _null_ _null_ "" f)); +DESCR("statistics: transactions rolled back"); +DATA(insert OID = 1944 ( pg_stat_get_db_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: blocks fetched for database"); +DATA(insert OID = 1945 ( pg_stat_get_db_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: blocks found in cache for database"); +DATA(insert OID = 2758 ( pg_stat_get_db_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples returned for database"); +DATA(insert OID = 2759 ( pg_stat_get_db_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples fetched for database"); +DATA(insert OID = 2760 ( pg_stat_get_db_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples inserted in database"); +DATA(insert OID = 2761 ( pg_stat_get_db_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples updated in database"); +DATA(insert OID = 2762 ( pg_stat_get_db_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples deleted in database"); +DATA(insert OID = 3065 ( pg_stat_get_db_conflict_tablespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_tablespace _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by drop tablespace"); +DATA(insert OID = 3066 ( pg_stat_get_db_conflict_lock PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_lock _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by relation lock"); +DATA(insert OID = 3067 ( pg_stat_get_db_conflict_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_snapshot _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by snapshot expiry"); +DATA(insert OID = 3068 ( pg_stat_get_db_conflict_bufferpin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_bufferpin _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by shared buffer pin"); +DATA(insert OID = 3069 ( pg_stat_get_db_conflict_startup_deadlock PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_startup_deadlock _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by buffer deadlock"); +DATA(insert OID = 3070 ( pg_stat_get_db_conflict_all PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_all _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database"); +DATA(insert OID = 3152 ( pg_stat_get_db_deadlocks PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_deadlocks _null_ _null_ _null_ "" f)); +DESCR("statistics: deadlocks detected in database"); +DATA(insert OID = 3074 ( pg_stat_get_db_stat_reset_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_stat_reset_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last reset for a database"); +DATA(insert OID = 3150 ( pg_stat_get_db_temp_files PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_temp_files _null_ _null_ _null_ "" f)); +DESCR("statistics: number of temporary files written"); +DATA(insert OID = 3151 ( pg_stat_get_db_temp_bytes PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_temp_bytes _null_ _null_ _null_ "" f)); +DESCR("statistics: number of bytes in temporary files written"); +DATA(insert OID = 2844 ( pg_stat_get_db_blk_read_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_read_time _null_ _null_ _null_ "" f)); +DESCR("statistics: block read time, in msec"); +DATA(insert OID = 2845 ( pg_stat_get_db_blk_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_write_time _null_ _null_ _null_ "" f)); +DESCR("statistics: block write time, in msec"); +DATA(insert OID = 2846 ( pg_stat_get_mem_mbytes_reserved PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "20" _null_ _null_ _null_ _null_ pg_stat_get_mem_mbytes_reserved _null_ _null_ _null_ "" f)); +DESCR("statistics: memory reserved, in Mbytes"); +DATA(insert OID = 3500 ( pg_stat_get_realtime_info_internal PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 25 "26 26 20 2275 26" _null_ _null_ _null_ _null_ pg_stat_get_realtime_info_internal _null_ _null_ _null_ "" f)); +DESCR("statistics: datanode session info"); +DATA(insert OID = 3501 ( pg_stat_get_wlm_statistics PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,20,20,20,20,23,25,25,25}" "{o,o,o,o,o,o,o,o,o}" "{statement,block_time,elapsed_time,total_cpu_time,qualification_time,skew_percent,control_group,status,action}" _null_ pg_stat_get_wlm_statistics _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of statement"); +DATA(insert OID = 3502 ( pg_stat_get_session_wlmstat PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,20,23,26,25,25,20,20,20,20,23,23,23,23,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{datid,threadid,threadpid,usesysid,appname,query,priority,block_time,elapsed_time,total_cpu_time,skew_percent,statement_mem,active_points,dop_value,current_cgroup,current_status,enqueue_state,attribute}" _null_ pg_stat_get_session_wlmstat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session wlm statistics"); +DATA(insert OID = 3503 ( pg_wlm_jump_queue PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_wlm_jump_queue _null_ _null_ _null_ "" f)); +DESCR("wlm jump the queue"); +DATA(insert OID = 5001 ( pg_stat_get_wlm_session_info_internal PGNSP PGUID 12 1 100 0 0 f f f f f t s 4 0 25 "26 26 20 26" _null_ _null_ _null_ _null_ pg_stat_get_wlm_session_info_internal _null_ _null_ _null_ "" f)); +DESCR("session info: information about session wlm info"); +DATA(insert OID = 5002 ( pg_stat_get_wlm_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "26" "{26,25,25,25,25,25,869,25,23,25,20,1184,1184,20,20,25,25,25,25,23,23,23,23,23,25,23,23,23,23,20,20,20,23,20,20,20,23,23,23,23,23,25,23,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{datid,dbname,schemaname,nodename,username,application_name,client_addr,client_hostname,client_port,query_band,block_time,start_time,finish_time,duration,estimate_total_time,status,abort_info,resource_pool,control_group,estimate_memory,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,spill_info,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_dn_time,max_dn_time,average_dn_time,dntime_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,min_peak_iops,max_peak_iops,average_peak_iops,iops_skew_percent,warning,queryid,query,query_plan}" _null_ pg_stat_get_wlm_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of statement"); +DATA(insert OID = 5003 ( pg_stat_get_wlm_realtime_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,20,20,20,20,20,25,25,25,25,23,23,23,23,23,23,23,23,23,20,20,20,23,20,20,20,23,23,23,23,23,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{nodename,threadid,block_time,duration,estimate_total_time,estimate_left_time,schemaname,query_band,spill_info,control_group,estimate_memory,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_dn_time,max_dn_time,average_dn_time,dntime_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,min_peak_iops,max_peak_iops,average_peak_iops,iops_skew_percent,warning,query,query_plan}" _null_ pg_stat_get_wlm_realtime_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about realtime wlm statistics of statement"); +DATA(insert OID = 5004 ( gs_wlm_get_resource_pool_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{respool_oid,ref_count,active_points,running_count,waiting_count,iops_limits,io_priority}" _null_ pg_stat_get_resource_pool_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about resource pool data"); +DATA(insert OID = 5005 ( gs_wlm_switch_cgroup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "20 2275" _null_ _null_ _null_ _null_ gs_wlm_switch_cgroup _null_ _null_ _null_ "" f)); +DESCR("wlm attah the cgroup"); +DATA(insert OID = 5006 ( gs_wlm_rebuild_user_resource_pool PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "25" _null_ _null_ _null_ _null_ gs_wlm_rebuild_user_resource_pool _null_ _null_ _null_ "" f)); +DESCR("rebuild user and resource pool data"); +DATA(insert OID = 5007 ( gs_wlm_get_user_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,16,26,26,20,20,23,25}" "{o,o,o,o,o,o,o,o}" "{userid,sysadmin,rpoid,parentid,totalspace,spacelimit,childcount,childlist}" _null_ pg_stat_get_wlm_user_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about user data"); +DATA(insert OID = 5008 ( pg_stat_get_cgroup_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,23,23,20,20,25,25,25}" "{o,o,o,o,o,o,o,o}" "{cgroup_name,percent,usage_percent,shares,usage,cpuset,relpath,valid}" _null_ pg_stat_get_cgroup_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about cgroup"); +DATA(insert OID = 5009 ( gs_wlm_get_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,25,23,23,23,20,23,23}" "{o,o,o,o,o,o,o,o}" "{threadid,node_name,used_memory,peak_memory,spill_count,cpu_time,peak_iops,curr_iops}" _null_ pg_wlm_get_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session"); +DATA(insert OID = 5010 ( pg_stat_get_role_name PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ gs_get_role_name _null_ _null_ _null_ "" f)); +DESCR("statistics: get role name"); +DATA(insert OID = 5011 ( gs_wlm_readjust_user_space PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ gs_wlm_readjust_user_space _null_ _null_ _null_ "" f)); +DESCR("statistics: readjust user space"); +DATA(insert OID = 5012 ( gs_wlm_user_resource_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{26,23,23,23,23,20,20}" "{o,o,o,o,o,o,o}" "{userid,used_memory,total_memory,used_cpu,total_cpu,used_space,total_space}" _null_ pg_stat_get_wlm_user_resource_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get user resource info"); +DATA(insert OID = 5017 ( gs_wlm_node_recover PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "16" _null_ _null_ _null_ _null_ gs_wlm_node_recover _null_ _null_ _null_ "" f)); +DESCR("do recover of the node"); +DATA(insert OID = 5018 ( gs_wlm_get_workload_records PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,26,20,23,23,23,23,25,25,25}" "{o,o,o,o,o,o,o,o,o,o}" "{node_idx,query_pid,start_time,memory,actpts,maxpts,priority,resource_pool,node_name,queue_type}" _null_ pg_stat_get_workload_records _null_ _null_ _null_ "" f)); +DESCR("get dynamic workload records"); +DATA(insert OID = 5015 ( get_nodename PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pg_get_nodename _null_ _null_ _null_ "" f)); +DESCR("statistics: current node name"); +DATA(insert OID = 5016 ( gs_wlm_node_clean PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "2275" _null_ _null_ _null_ _null_ gs_wlm_node_clean _null_ _null_ _null_ "" f)); +DESCR("wlm clean node info on central node"); +DATA(insert OID = 5013 ( pg_user_iostat PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{26,23,23,23,23,23,25}" "{o,o,o,o,o,o,o}" "{userid,min_curr_iops,max_curr_iops,min_peak_iops,max_peak_iops,io_limits,io_priority}" _null_ pg_stat_get_wlm_user_iostat_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get user iostat info"); +DATA(insert OID = 5014 ( pg_stat_get_wlm_session_iostat_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{20,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{threadid,maxcurr_iops,mincurr_iops,maxpeak_iops,minpeak_iops,iops_limits,io_priority}" _null_ pg_stat_get_wlm_session_iostat_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get query iostat info"); +DATA(insert OID = 5019 ( pg_stat_get_wlm_node_resource_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{23,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{min_mem_util,max_mem_util,min_cpu_util,max_cpu_util,min_io_util,max_io_util,used_mem_rate}" _null_ pg_stat_get_wlm_node_resource_info _null_ _null_ _null_ "" f)); +DESCR("get resource usage info of nodes"); +DATA(insert OID = 5020 ( gs_wlm_get_user_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{25,25,23,23,23,20,23,23}" "{o,o,o,o,o,o,o,o}" "{username,node_name,used_memory,peak_memory,spill_count,cpu_time,peak_iops,curr_iops}" _null_ pg_wlm_get_user_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about user"); +DATA(insert OID = 5021 ( gs_wlm_session_respool PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{26,20,23,26,25,19}" "{o,o,o,o,o,o}" "{datid,threadid,threadpid,usesysid,cgroup,session_respool}" _null_ pg_stat_get_session_respool _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session_respool"); +DATA(insert OID = 5022 ( pg_stat_get_wlm_realtime_operator_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{20,20,23,25,1184,20,25,23,20,20,23,23,23,23,23,23,23,23,20,20,20,23,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{queryid,pid,plan_node_id,plan_node_name,start_time,duration,status,query_dop,estimated_rows,tuple_processed,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,warning}" _null_ pg_stat_get_wlm_realtime_operator_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about realtime wlm statistics of operator"); +DATA(insert OID = 5023 ( pg_stat_get_wlm_operator_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "26" "{20,20,23,25,1184,20,23,20,20,23,23,23,23,23,23,23,23,20,20,20,23,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{queryid,pid,plan_node_id,plan_node_name,start_time,duration,query_dop,estimated_rows,tuple_processed,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,warning}" _null_ pg_stat_get_wlm_operator_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of operator"); +DATA(insert OID = 2769 ( pg_stat_get_bgwriter_timed_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_timed_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of timed checkpoints started by the bgwriter"); +DATA(insert OID = 2770 ( pg_stat_get_bgwriter_requested_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_requested_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backend requested checkpoints started by the bgwriter"); +DATA(insert OID = 2771 ( pg_stat_get_bgwriter_buf_written_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by the bgwriter during checkpoints"); +DATA(insert OID = 2772 ( pg_stat_get_bgwriter_buf_written_clean PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_clean _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by the bgwriter for cleaning dirty buffers"); +DATA(insert OID = 2773 ( pg_stat_get_bgwriter_maxwritten_clean PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_maxwritten_clean _null_ _null_ _null_ "" f)); +DESCR("statistics: number of times the bgwriter stopped processing when it had written too many buffers while cleaning"); +DATA(insert OID = 3075 ( pg_stat_get_bgwriter_stat_reset_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_stat_reset_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last reset for the bgwriter"); +DATA(insert OID = 3160 ( pg_stat_get_checkpoint_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_write_time _null_ _null_ _null_ "" f)); +DESCR("statistics: checkpoint time spent writing buffers to disk, in msec"); +DATA(insert OID = 3161 ( pg_stat_get_checkpoint_sync_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_sync_time _null_ _null_ _null_ "" f)); +DESCR("statistics: checkpoint time spent synchronizing buffers to disk, in msec"); +DATA(insert OID = 2775 ( pg_stat_get_buf_written_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_written_backend _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by backends"); +DATA(insert OID = 3063 ( pg_stat_get_buf_fsync_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_fsync_backend _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backend buffer writes that did their own fsync"); +DATA(insert OID = 2859 ( pg_stat_get_buf_alloc PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_alloc _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffer allocations"); + +DATA(insert OID = 2978 ( pg_stat_get_function_calls PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_calls _null_ _null_ _null_ "" f)); +DESCR("statistics: number of function calls"); +DATA(insert OID = 2979 ( pg_stat_get_function_total_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_total_time _null_ _null_ _null_ "" f)); +DESCR("statistics: total execution time of function, in msec"); +DATA(insert OID = 2980 ( pg_stat_get_function_self_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_self_time _null_ _null_ _null_ "" f)); +DESCR("statistics: self execution time of function, in msec"); + +DATA(insert OID = 3037 ( pg_stat_get_xact_numscans PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_numscans _null_ _null_ _null_ "" f)); +DESCR("statistics: number of scans done for table/index in current transaction"); +DATA(insert OID = 3038 ( pg_stat_get_xact_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples read by seqscan in current transaction"); +DATA(insert OID = 3039 ( pg_stat_get_xact_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples fetched by idxscan in current transaction"); +DATA(insert OID = 3040 ( pg_stat_get_xact_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples inserted in current transaction"); +DATA(insert OID = 3041 ( pg_stat_get_xact_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples updated in current transaction"); +DATA(insert OID = 3042 ( pg_stat_get_xact_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples deleted in current transaction"); +DATA(insert OID = 3043 ( pg_stat_get_xact_tuples_hot_updated PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_hot_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples hot updated in current transaction"); +DATA(insert OID = 3044 ( pg_stat_get_xact_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks fetched in current transaction"); +DATA(insert OID = 3045 ( pg_stat_get_xact_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks found in cache in current transaction"); +DATA(insert OID = 3046 ( pg_stat_get_xact_function_calls PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_calls _null_ _null_ _null_ "" f)); +DESCR("statistics: number of function calls in current transaction"); +DATA(insert OID = 3047 ( pg_stat_get_xact_function_total_time PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_total_time _null_ _null_ _null_ "" f)); +DESCR("statistics: total execution time of function in current transaction, in msec"); +DATA(insert OID = 3048 ( pg_stat_get_xact_function_self_time PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_self_time _null_ _null_ _null_ "" f)); +DESCR("statistics: self execution time of function in current transaction, in msec"); + +DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_clear_snapshot _null_ _null_ _null_ "" f)); +DESCR("statistics: discard current transaction's statistics snapshot"); +DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_reset _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for current database"); +DATA(insert OID = 3775 ( pg_stat_reset_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "25" _null_ _null_ _null_ _null_ pg_stat_reset_shared _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics shared across the cluster"); +DATA(insert OID = 3776 ( pg_stat_reset_single_table_counters PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_table_counters _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for a single table or index in the current database"); +DATA(insert OID = 3777 ( pg_stat_reset_single_function_counters PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_function_counters _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for a single function in the current database"); + +DATA(insert OID = 3480 ( pg_stat_get_cu_mem_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_mem_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu found in memory"); +DATA(insert OID = 3483 ( pg_stat_get_cu_hdd_sync PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_hdd_sync _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu synchronous read from hdd"); +DATA(insert OID = 3484 ( pg_stat_get_cu_hdd_asyn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_hdd_asyn _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu asynchronous read from hdd"); +DATA(insert OID = 3485 ( pg_stat_get_db_cu_mem_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_mem_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: cu found in memory for database"); +DATA(insert OID = 3488 ( pg_stat_get_db_cu_hdd_sync PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_hdd_sync _null_ _null_ _null_ "" f)); +DESCR("statistics: cu synchronous read from hdd for database"); +DATA(insert OID = 3489 ( pg_stat_get_db_cu_hdd_asyn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_hdd_asyn _null_ _null_ _null_ "" f)); +DESCR("statistics: cu asynchronous read from hdd for database"); + +/* add pgaudit functions */ +DATA(insert OID = 3780 ( pg_query_audit PGNSP PGUID 12 1 10 0 0 f f f f f t v 2 0 2249 "1184 1184" "{1184,1184,1184,25,25,25,25,25,25,25,25,25,25,25}" "{i,i,o,o,o,o,o,o,o,o,o,o,o,o}" "{begin,end,time,type,result,username,database,client_conninfo,object_name,detail_info,node_name,thread_id,local_port,remote_port}" _null_ pg_query_audit _null_ _null_ _null_ "" f)); +DESCR("audit: query audit information"); +DATA(insert OID = 3782 ( pg_query_audit PGNSP PGUID 12 1 10 0 0 f f f f f t v 3 0 2249 "1184 1184 25" "{1184,1184,25,1184,25,25,25,25,25,25,25,25,25,25,25}" "{i,i,i,o,o,o,o,o,o,o,o,o,o,o,o}" "{begin,end,directory,time,type,result,username,database,client_conninfo,object_name,detail_info,node_name,thread_id,local_port,remote_port}" _null_ pg_query_audit _null_ _null_ _null_ "" f)); +DESCR("audit: query audit information"); +DATA(insert OID = 3781 ( pg_delete_audit PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2278 "1184 1184" "{1184,1184}" "{i,i}" "{begin,end}" _null_ pg_delete_audit _null_ _null_ _null_ "" f)); +DESCR("audit: delete audit information"); + +DATA(insert OID = 3163 ( pg_trigger_depth PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 23 "" _null_ _null_ _null_ _null_ pg_trigger_depth _null_ _null_ _null_ "" f)); +DESCR("current trigger depth"); + +DATA(insert OID = 3778 ( pg_tablespace_location PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_tablespace_location _null_ _null_ _null_ "" f)); +DESCR("tablespace location"); + +DATA(insert OID = 1946 ( encode PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "17 25" _null_ _null_ _null_ _null_ binary_encode _null_ _null_ _null_ "" f)); +DESCR("convert bytea value into some ascii-only text string"); +DATA(insert OID = 1947 ( decode PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "25 25" _null_ _null_ _null_ _null_ binary_decode _null_ _null_ _null_ "" f)); +DESCR("convert ascii-encoded text string into bytea value"); + +DATA(insert OID = 1948 ( byteaeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteaeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1949 ( bytealt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1950 ( byteale PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteale _null_ _null_ _null_ "" f)); +DATA(insert OID = 1951 ( byteagt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteagt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1952 ( byteage PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteage _null_ _null_ _null_ "" f)); +DATA(insert OID = 1953 ( byteane PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteane _null_ _null_ _null_ "" f)); +DATA(insert OID = 1954 ( byteacmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 17" _null_ _null_ _null_ _null_ byteacmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3452 ( bytea_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bytea_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); + +DATA(insert OID = 3931 ( raweq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ raweq _null_ _null_ _null_"" f)); +DESCR("equal"); +DATA(insert OID = 3932 ( rawlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawlt _null_ _null_ _null_ ""f)); +DESCR("less than"); +DATA(insert OID = 3935 ( rawle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawle _null_ _null_ _null_ ""f)); +DESCR("less than or equal"); +DATA(insert OID = 3936 ( rawgt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawgt _null_ _null_ _null_ ""f)); +DESCR("greater than"); +DATA(insert OID = 3939 ( rawge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawge _null_ _null_ _null_ ""f)); +DESCR("greater than or equal"); +DATA(insert OID = 3940 ( rawne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawne _null_ _null_ _null_ ""f)); +DESCR("not equal"); +DATA(insert OID = 3475 ( rawcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 86" _null_ _null_ _null_ _null_ rawcmp _null_ _null_ _null_"" f)); +DESCR("less equal greater"); +DATA(insert OID = 3476 ( rawlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawlike _null_ _null_ _null_"" f)); +DESCR("matches like expression"); +DATA(insert OID = 3477 ( rawnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawnlike _null_ _null_ _null_"" f)); +DESCR("does not match like expression"); +DATA(insert OID = 3478 ( rawcat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 86 "86 86" _null_ _null_ _null_ _null_ rawcat _null_ _null_ _null_"" f)); +DESCR("concatenate"); + +DATA(insert OID = 3917 ( timestamp_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ timestamp_transform _null_ _null_ _null_ "" f)); +DESCR("transform a timestamp length coercion"); +DATA(insert OID = 3944 ( time_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ time_transform _null_ _null_ _null_ "" f)); +DESCR("transform a time length coercion"); + +DATA(insert OID = 1961 ( timestamp PGNSP PGUID 12 1 0 0 timestamp_transform f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ timestamp_scale _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp precision"); + +DATA(insert OID = 1965 ( oidlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 26 "26 26" _null_ _null_ _null_ _null_ oidlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1966 ( oidsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 26 "26 26" _null_ _null_ _null_ _null_ oidsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1967 ( timestamptz PGNSP PGUID 12 1 0 0 timestamp_transform f f f f t f i 2 0 1184 "1184 23" _null_ _null_ _null_ _null_ timestamptz_scale _null_ _null_ _null_ "" f)); +DESCR("adjust timestamptz precision"); +DATA(insert OID = 1968 ( time PGNSP PGUID 12 1 0 0 time_transform f f f f t f i 2 0 1083 "1083 23" _null_ _null_ _null_ _null_ time_scale _null_ _null_ _null_ "" f)); +DESCR("adjust time precision"); +DATA(insert OID = 1969 ( timetz PGNSP PGUID 12 1 0 0 time_transform f f f f t f i 2 0 1266 "1266 23" _null_ _null_ _null_ _null_ timetz_scale _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone precision"); + +DATA(insert OID = 2003 ( textanycat PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 25 "25 2776" _null_ _null_ _null_ _null_ "select $1 || $2::pg_catalog.text" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2004 ( anytextcat PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 25 "2776 25" _null_ _null_ _null_ _null_ "select $1::pg_catalog.text || $2" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2005 ( bytealike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealike _null_ _null_ _null_ "" f)); +DATA(insert OID = 2006 ( byteanlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteanlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 2007 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 2008 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteanlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 2009 ( like_escape PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ like_escape_bytea _null_ _null_ _null_ "" f)); +DESCR("convert LIKE pattern to use backslash escapes"); +DATA(insert OID = 2010 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ byteaoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 2011 ( byteacat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ byteacat _null_ _null_ _null_ "" f)); +DATA(insert OID = 2012 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ bytea_substr _null_ _null_ _null_ "" f)); +#define BYTEASUBSTRINGFUNCOID 2012 +DESCR("extract portion of string"); +DATA(insert OID = 2013 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 23" _null_ _null_ _null_ _null_ bytea_substr_no_len _null_ _null_ _null_ "" f)); +#define BYTEASUBSTRINGNOLENOID 2013 +DESCR("extract portion of string"); +DATA(insert OID = 2085 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ bytea_substr_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define BYTEASUBSTRFUNCOID 2085 +DATA(insert OID = 2086 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 23" _null_ _null_ _null_ _null_ bytea_substr_no_len_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define BYTEASUBSTRNOLENFUNCOID 2086 +DATA(insert OID = 2014 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 17" _null_ _null_ _null_ _null_ byteapos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define BYTEAPOSFUNCOID 2014 +DATA(insert OID = 2015 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ byteatrim _null_ _null_ _null_ "" f)); +DESCR("trim both ends of string"); + +DATA(insert OID = 2019 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1083 "1184" _null_ _null_ _null_ _null_ timestamptz_time _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to time"); +#define TIMESTAMPTZ2TIMEFUNCOID 2019 +DATA(insert OID = 2020 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "25 1114" _null_ _null_ _null_ _null_ timestamp_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate timestamp to specified units"); +#define TIMESTAMPTRUNCFUNCOID 2020 +DATA(insert OID = 2021 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1114" _null_ _null_ _null_ _null_ timestamp_part _null_ _null_ _null_ "" f)); +DESCR("extract field from timestamp"); +#define TIMESTAMPPARTFUNCOID 2021 +DATA(insert OID = 2023 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "702" _null_ _null_ _null_ _null_ abstime_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert abstime to timestamp"); +#define ABSTIMETIMESTAMPFUNCOID 2023 +DATA(insert OID = 2024 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1082" _null_ _null_ _null_ _null_ date_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert date to timestamp"); +DATA(insert OID = 2025 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1083" _null_ _null_ _null_ _null_ datetime_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert date and time to timestamp"); +DATA(insert OID = 2027 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "1184" _null_ _null_ _null_ _null_ timestamptz_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to timestamp"); +#define TIMESTAMPTZ2TIMESTAMPFUNCOID 2027 +DATA(insert OID = 2028 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "1114" _null_ _null_ _null_ _null_ timestamp_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to timestamp with time zone"); +#define TIMESTAMP2TIMESTAMPTZFUNCOID 2028 +DATA(insert OID = 2029 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1114" _null_ _null_ _null_ _null_ timestamp_date _null_ _null_ _null_ "" f)); +#define TIMESTAMP2DATEOID 2029 +DESCR("convert timestamp to date"); +DATA(insert OID = 2030 ( abstime PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 702 "1114" _null_ _null_ _null_ _null_ timestamp_abstime _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to abstime"); +#define TIMESTAMP2ABSTIMEFUNCOID 2030 +DATA(insert OID = 2031 ( timestamp_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1114 1114" _null_ _null_ _null_ _null_ timestamp_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 2032 ( timestamp_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1186" _null_ _null_ _null_ _null_ timestamp_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2033 ( timestamp_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1186" _null_ _null_ _null_ _null_ timestamp_mi_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2035 ( timestamp_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1114" _null_ _null_ _null_ _null_ timestamp_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 2036 ( timestamp_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1114" _null_ _null_ _null_ _null_ timestamp_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2037 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 1266 "25 1266" _null_ _null_ _null_ _null_ timetz_zone _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone to new zone"); +DATA(insert OID = 2038 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1186 1266" _null_ _null_ _null_ _null_ timetz_izone _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone to new zone"); +DATA(insert OID = 2039 ( timestamp_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1114" _null_ _null_ _null_ _null_ timestamp_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define TIMESTAMPHASHOID 2039 +DATA(insert OID = 2041 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1114 1114 1114 1114" _null_ _null_ _null_ _null_ overlaps_timestamp _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2042 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1186 1114 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2043 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1114 1114 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2044 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1186 1114 1114" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2045 ( timestamp_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 1114" _null_ _null_ _null_ _null_ timestamp_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3137 ( timestamp_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ timestamp_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 2046 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1266" _null_ _null_ _null_ _null_ timetz_time _null_ _null_ _null_ "" f)); +DESCR("convert time with time zone to time"); +DATA(insert OID = 2047 ( timetz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1266 "1083" _null_ _null_ _null_ _null_ time_timetz _null_ _null_ _null_ "" f)); +DESCR("convert time to time with time zone"); +#define TIME2TIMETZFUNCOID 2047 +DATA(insert OID = 2048 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1114" _null_ _null_ _null_ _null_ timestamp_finite _null_ _null_ _null_ "" f)); +DESCR("finite timestamp?"); +DATA(insert OID = 2049 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1114 25" _null_ _null_ _null_ _null_ timestamp_to_char _null_ _null_ _null_ "" f)); +#define TIMESTAMP2CHARFUNCOID 2049 +DESCR("format timestamp to text"); +DATA(insert OID = 3808 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "1114" _null_ _null_ _null_ _null_ timestamp_to_char_default_format _null_ _null_ _null_ "" f)); +#define DEFAULTFORMATTIMESTAMP2CHARFUNCOID 3808 +DESCR("default format timestamp to text"); +DATA(insert OID = 3813 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "1184" _null_ _null_ _null_ _null_ timestamptz_to_char_default_format _null_ _null_ _null_ "" f)); +#define DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID 3813 +DESCR("default format timestamptz to text"); +DATA(insert OID = 2052 ( timestamp_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2053 ( timestamp_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2054 ( timestamp_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2055 ( timestamp_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2056 ( timestamp_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2057 ( timestamp_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2058 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1114 1114" _null_ _null_ _null_ _null_ timestamp_age _null_ _null_ _null_ "" f)); +DESCR("date difference preserving months and years"); +DATA(insert OID = 2059 ( age PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1186 "1114" _null_ _null_ _null_ _null_ "select pg_catalog.age(cast(current_date as timestamp without time zone), $1)" _null_ _null_ _null_ "" f)); +DESCR("date difference from today preserving months and years"); + +DATA(insert OID = 2069 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "25 1114" _null_ _null_ _null_ _null_ timestamp_zone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); +DATA(insert OID = 2070 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1186 1114" _null_ _null_ _null_ _null_ timestamp_izone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); +DATA(insert OID = 2071 ( date_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1186" _null_ _null_ _null_ _null_ date_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2072 ( date_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1186" _null_ _null_ _null_ _null_ date_mi_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2073 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ textregexsubstr _null_ _null_ _null_ "" f)); +#define TEXTREGEXSUBSTRINGOID 2073 +DESCR("extract text matching regular expression"); +DATA(insert OID = 2074 ( substring PGNSP PGUID 14 1 0 0 0 f f f f t f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ "select pg_catalog.substring($1, pg_catalog.similar_escape($2, $3))" _null_ _null_ _null_ "" f)); +#define SUBSTRINGESCAPEFUNCOID 2074 +DESCR("extract text matching SQL99 regular expression"); + +DATA(insert OID = 2075 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "20 23" _null_ _null_ _null_ _null_ bitfromint8 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to bitstring"); +DATA(insert OID = 2076 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1560" _null_ _null_ _null_ _null_ bittoint8 _null_ _null_ _null_ "" f)); +DESCR("convert bitstring to int8"); + +DATA(insert OID = 2077 ( current_setting PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "25" _null_ _null_ _null_ _null_ show_config_by_name _null_ _null_ _null_ "" f)); +DESCR("SHOW X as a function"); +DATA(insert OID = 2078 ( set_config PGNSP PGUID 12 1 0 0 0 f f f f f f v 3 0 25 "25 25 16" _null_ _null_ _null_ _null_ set_config_by_name _null_ _null_ _null_ "" f)); +DESCR("SET X as a function"); +DATA(insert OID = 2084 ( pg_show_all_settings PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,25,25,25,25,25,25,25,25,25,1009,25,25,25,23}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{name,setting,unit,category,short_desc,extra_desc,context,vartype,source,min_val,max_val,enumvals,boot_val,reset_val,sourcefile,sourceline}" _null_ show_all_settings _null_ _null_ _null_ "" f)); +DESCR("SHOW ALL as a function"); +DATA(insert OID = 1371 ( pg_lock_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,26,26,23,21,25,28,26,26,21,25,20,25,16,16}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid,mode,granted,fastpath}" _null_ pg_lock_status _null_ _null_ _null_ "" f)); +DESCR("view system lock information"); +DATA(insert OID = 1065 ( pg_prepared_xact PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,25,1184,26,26}" "{o,o,o,o,o}" "{transaction,gid,prepared,ownerid,dbid}" _null_ pg_prepared_xact _null_ _null_ _null_ "" f)); +DESCR("view two-phase transactions"); +DATA(insert OID = 3212 ( pg_parse_clog PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,25}" "{o,o}" "{xid,status}" _null_ pg_parse_clog _null_ _null_ _null_ "" f)); +DESCR("view transaction clog"); +DATA(insert OID = 1998 ( pg_get_running_xacts PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{23,28,5545,25,28,16,20,28,20,28}" "{o,o,o,o,o,o,o,o,o,o}" "{handle,gxid,state,node,xmin,vacuum,timeline,prepare_xid,pid,next_xid}" _null_ pg_get_running_xacts _null_ _null_ _null_ "" f)); +DESCR("view running transactions"); +DATA(insert OID = 3199 ( get_prepared_pending_xid PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ get_prepared_pending_xid _null_ _null_ _null_ "" f)); +DESCR("nextxid when recovery done"); +DATA(insert OID = 1999 ( pg_check_xidlimit PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_check_xidlimit _null_ _null_ _null_ "" f)); +DESCR("is nextXid >= dWarnLimit?"); +DATA(insert OID = 1983 ( pg_log_comm_status PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_log_comm_status _null_ _null_ _null_ "" f)); +DESCR("log communication layer status"); +DATA(insert OID = 1984 ( pg_comm_recv_stream PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,25,20,23,23,23,25,23,23,23,23,23,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{node_name,local_tid,remote_name,remote_tid,idx,sid,tcp_sock,state,query_id,plan_id,pn_id,send_smp,recv_smp,recv_bytes,time,speed,quota,buff_usize}" _null_ pg_comm_recv_stream _null_ _null_ _null_ "" f)); +DESCR("communication recv stream status"); +DATA(insert OID = 1985 ( pg_comm_send_stream PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,25,20,23,23,23,25,23,23,23,23,23,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{node_name,local_tid,remote_name,remote_tid,idx,sid,tcp_sock,state,query_id,plan_id,pn_id,send_smp,recv_smp,send_bytes,time,speed,quota,wait_quota}" _null_ pg_comm_send_stream _null_ _null_ _null_ "" f)); +DESCR("communication send stream status"); +DATA(insert OID = 1986 ( pg_comm_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o,o}" "{node_name,recv_speed,min_recv_idx,max_recv_idx,send_speed,min_send_idx,max_send_idx,mem_used}" _null_ pg_comm_status _null_ _null_ _null_ "" f)); +DESCR("communication net status"); +DATA(insert OID = 1987 ( pg_comm_delay PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,25,25,23,23,23,23}" "{o,o,o,o,o,o,o}" "{node_name,remote_name,remote_host,stream_num,min_delay,average,max_delay}" _null_ pg_comm_delay _null_ _null_ _null_ "" f)); +DESCR("sctp communication delay information"); +DATA(insert OID = 2000 ( pg_get_xidlimit PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,28,28,28,28,28,26}" "{o,o,o,o,o,o,o}" "{nextXid,oldestXid,xidVacLimit,xidWarnLimit,xidStopLimit,xidWrapLimit,oldestXidDB}" _null_ pg_get_xidlimit _null_ _null_ _null_ "" f)); +DESCR("view TransactionId information"); +DATA(insert OID = 3537 ( pg_describe_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "26 26 23" _null_ _null_ _null_ _null_ pg_describe_object _null_ _null_ _null_ "" f)); +DESCR("get identification of SQL object"); +DATA(insert OID = 2079 ( pg_table_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_table_is_visible _null_ _null_ _null_ "" f)); +DESCR("is table visible in search path?"); +DATA(insert OID = 2080 ( pg_type_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_type_is_visible _null_ _null_ _null_ "" f)); +DESCR("is type visible in search path?"); +DATA(insert OID = 2081 ( pg_function_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_function_is_visible _null_ _null_ _null_ "" f)); +DESCR("is function visible in search path?"); +DATA(insert OID = 2082 ( pg_operator_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_operator_is_visible _null_ _null_ _null_ "" f)); +DESCR("is operator visible in search path?"); +DATA(insert OID = 2083 ( pg_opclass_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opclass_is_visible _null_ _null_ _null_ "" f)); +DESCR("is opclass visible in search path?"); +DATA(insert OID = 3829 ( pg_opfamily_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opfamily_is_visible _null_ _null_ _null_ "" f)); +DESCR("is opfamily visible in search path?"); +DATA(insert OID = 2093 ( pg_conversion_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_conversion_is_visible _null_ _null_ _null_ "" f)); +DESCR("is conversion visible in search path?"); +DATA(insert OID = 3756 ( pg_ts_parser_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_parser_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search parser visible in search path?"); +DATA(insert OID = 3757 ( pg_ts_dict_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_dict_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search dictionary visible in search path?"); +DATA(insert OID = 3768 ( pg_ts_template_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_template_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search template visible in search path?"); +DATA(insert OID = 3758 ( pg_ts_config_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_config_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search configuration visible in search path?"); +DATA(insert OID = 3815 ( pg_collation_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_collation_is_visible _null_ _null_ _null_ "" f)); +DESCR("is collation visible in search path?"); + +DATA(insert OID = 2854 ( pg_my_temp_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 26 "" _null_ _null_ _null_ _null_ pg_my_temp_schema _null_ _null_ _null_ "" f)); +DESCR("get OID of current session's temp schema, if any"); +DATA(insert OID = 2855 ( pg_is_other_temp_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_is_other_temp_schema _null_ _null_ _null_ "" f)); +DESCR("is schema another session's temp schema?"); + +DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_cancel_backend _null_ _null_ _null_ "" f)); +DESCR("cancel a server process' current query"); +DATA(insert OID = 3213 ( pg_cancel_invalid_query PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_cancel_invalid_query _null_ _null_ _null_ "" f)); +DESCR("cancel queries on coordinator sessions connected to demoted GTM"); +DATA(insert OID = 2537 ( report_fatal PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ report_fatal _null_ _null_ _null_ "" f)); +DESCR("report a fatal error"); +DATA(insert OID = 2539 ( signal_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "20 23" _null_ _null_ _null_ _null_ signal_backend _null_ _null_ _null_ "" f)); +DESCR("signal a server thread"); +DATA(insert OID = 2096 ( pg_terminate_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_terminate_backend _null_ _null_ _null_ "" f)); +DESCR("terminate a server process"); +DATA(insert OID = 2172 ( pg_start_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 25 "25 16" _null_ _null_ _null_ _null_ pg_start_backup _null_ _null_ _null_ "" f)); +DESCR("prepare for taking an online backup"); +DATA(insert OID = 2173 ( pg_stop_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_stop_backup _null_ _null_ _null_ "" f)); +DESCR("finish taking an online backup"); +DATA(insert OID = 2848 ( pg_switch_xlog PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_switch_xlog _null_ _null_ _null_ "" f)); +DESCR("switch to new xlog file"); +DATA(insert OID = 3098 ( pg_create_restore_point PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_create_restore_point _null_ _null_ _null_ "" f)); +DESCR("create a named restore point"); +DATA(insert OID = 2849 ( pg_current_xlog_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_current_xlog_location _null_ _null_ _null_ "" f)); +DESCR("current xlog write location"); +DATA(insert OID = 2852 ( pg_current_xlog_insert_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_current_xlog_insert_location _null_ _null_ _null_ "" f)); +DESCR("current xlog insert location"); +DATA(insert OID = 2850 ( pg_xlogfile_name_offset PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2249 "25" "{25,25,23}" "{i,o,o}" "{wal_location,file_name,file_offset}" _null_ pg_xlogfile_name_offset _null_ _null_ _null_ "" f)); +DESCR("xlog filename and byte offset, given an xlog location"); +DATA(insert OID = 2851 ( pg_xlogfile_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ pg_xlogfile_name _null_ _null_ _null_ "" f)); +DESCR("xlog filename, given an xlog location"); + +DATA(insert OID = 3165 ( pg_xlog_location_diff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "25 25" _null_ _null_ _null_ _null_ pg_xlog_location_diff _null_ _null_ _null_ "" f)); +DESCR("difference in bytes, given two xlog locations"); + +DATA(insert OID = 3809 ( pg_export_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_export_snapshot _null_ _null_ _null_ "" f)); +DESCR("export a snapshot"); + +DATA(insert OID = 3810 ( pg_is_in_recovery PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_in_recovery _null_ _null_ _null_ "" f)); +DESCR("true if server is in recovery"); + +DATA(insert OID = 3820 ( pg_last_xlog_receive_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_receive_location _null_ _null_ _null_ "" f)); +DESCR("current xlog flush location"); +DATA(insert OID = 3821 ( pg_last_xlog_replay_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_replay_location _null_ _null_ _null_ "" f)); +DESCR("last xlog replay location"); +DATA(insert OID = 3830 ( pg_last_xact_replay_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ pg_last_xact_replay_timestamp _null_ _null_ _null_ "" f)); +DESCR("timestamp of last replay xact"); + +DATA(insert OID = 3071 ( pg_xlog_replay_pause PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_xlog_replay_pause _null_ _null_ _null_ "" f)); +DESCR("pause xlog replay"); +DATA(insert OID = 3072 ( pg_xlog_replay_resume PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_xlog_replay_resume _null_ _null_ _null_ "" f)); +DESCR("resume xlog replay, if it was paused"); +DATA(insert OID = 3073 ( pg_is_xlog_replay_paused PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_xlog_replay_paused _null_ _null_ _null_ "" f)); +DESCR("true if xlog replay is paused"); + +DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_reload_conf _null_ _null_ _null_ "" f)); +DESCR("reload configuration files"); +DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_rotate_logfile _null_ _null_ _null_ "" f)); +DESCR("rotate log file"); + +DATA(insert OID = 2623 ( pg_stat_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2249 "25" "{25,20,1184,1184,1184,1184,16}" "{i,o,o,o,o,o,o}" "{filename,size,access,modification,change,creation,isdir}" _null_ pg_stat_file _null_ _null_ _null_ "" f)); +DESCR("get information about file"); +DATA(insert OID = 6321 ( pg_stat_file_recursive PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 2249 "25" "{25,25,25,20,16}" "{i,o,o,o,o}" "{location,path,filename,size,isdir}" _null_ pg_stat_file_recursive _null_ _null_ _null_ "" f)); +DESCR("get information about a few files"); +DATA(insert OID = 2624 ( pg_read_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 25 "25 20 20" _null_ _null_ _null_ _null_ pg_read_file _null_ _null_ _null_ "" f)); +DESCR("read text from a file"); +DATA(insert OID = 3826 ( pg_read_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_read_file_all _null_ _null_ _null_ "" f)); +DESCR("read text from a file"); +DATA(insert OID = 3827 ( pg_read_binary_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 17 "25 20 20 16" _null_ _null_ _null_ _null_ pg_read_binary_file _null_ _null_ _null_ "" f)); +DESCR("read bytea from a file"); +DATA(insert OID = 3828 ( pg_read_binary_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 17 "25" _null_ _null_ _null_ _null_ pg_read_binary_file_all _null_ _null_ _null_ "" f)); +DESCR("read bytea from a file"); +DATA(insert OID = 2625 ( pg_ls_dir PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_ls_dir _null_ _null_ _null_ "" f)); +DESCR("list all files in a directory"); +DATA(insert OID = 2626 ( pg_sleep PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "701" _null_ _null_ _null_ _null_ pg_sleep _null_ _null_ _null_ "" f)); +DESCR("sleep for the specified time in seconds"); +DATA(insert OID = 9999 ( pg_test_err_contain_err PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "23" _null_ _null_ _null_ _null_ pg_test_err_contain_err _null_ _null_ _null_ "" f)); +DESCR("test error contain error"); + +DATA(insert OID = 2971 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "16" _null_ _null_ _null_ _null_ booltext _null_ _null_ _null_ "" f)); +DESCR("convert boolean to text"); + +/* Aggregates (moved here from pg_aggregate for 7.3) */ + +DATA(insert OID = 2100 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all bigint values"); +DATA(insert OID = 2101 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all integer values"); +DATA(insert OID = 2102 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all smallint values"); +DATA(insert OID = 2103 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all numeric values"); +DATA(insert OID = 2104 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as float8 of all float4 values"); +DATA(insert OID = 2105 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as float8 of all float8 values"); +DATA(insert OID = 2106 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as interval of all interval values"); +DATA(insert OID = 5537 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all tinyint values"); +DATA(insert OID = 2107 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as numeric across all bigint input values"); +DATA(insert OID = 2108 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as bigint across all integer input values"); +DATA(insert OID = 2109 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as bigint across all smallint input values"); +DATA(insert OID = 2110 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as float4 across all float4 input values"); +DATA(insert OID = 2111 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as float8 across all float8 input values"); +DATA(insert OID = 2112 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as money across all money input values"); +DATA(insert OID = 2113 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as interval across all interval input values"); +DATA(insert OID = 2114 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as numeric across all numeric input values"); + +DATA(insert OID = 2115 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all bigint input values"); +DATA(insert OID = 2116 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all integer input values"); +DATA(insert OID = 2117 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all smallint input values"); +DATA(insert OID = 2118 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 26 "26" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all oid input values"); +DATA(insert OID = 2119 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all float4 input values"); +DATA(insert OID = 2120 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all float8 input values"); +DATA(insert OID = 2121 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 702 "702" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all abstime input values"); +DATA(insert OID = 2122 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1082 "1082" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all date input values"); +DATA(insert OID = 2123 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1083 "1083" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all time input values"); +DATA(insert OID = 2124 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1266 "1266" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all time with time zone input values"); +DATA(insert OID = 2125 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all money input values"); +DATA(insert OID = 2126 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all timestamp input values"); +DATA(insert OID = 9010 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 9003 "9003" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all smalldatetime input values"); +DATA(insert OID = 9009 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 9003 "9003" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all smalldatetime input values"); +DATA(insert OID = 9011 ( smalldatetime_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 9003 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 9012 ( smalldatetime_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 9003 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2127 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1184 "1184" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all timestamp with time zone input values"); +DATA(insert OID = 2128 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all interval input values"); +DATA(insert OID = 2129 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all text input values"); +DATA(insert OID = 2130 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all numeric input values"); +DATA(insert OID = 2050 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2277" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all anyarray input values"); +DATA(insert OID = 2244 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "1042" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all bpchar input values"); +DATA(insert OID = 2797 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all tid input values"); +DATA(insert OID = 5538 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all tinyint input values"); +DATA(insert OID = 2131 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all bigint input values"); +DATA(insert OID = 2132 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all integer input values"); +DATA(insert OID = 2133 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all smallint input values"); +DATA(insert OID = 2134 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 26 "26" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all oid input values"); +DATA(insert OID = 2135 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all float4 input values"); +DATA(insert OID = 2136 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all float8 input values"); +DATA(insert OID = 2137 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 702 "702" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all abstime input values"); +DATA(insert OID = 2138 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1082 "1082" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all date input values"); +DATA(insert OID = 2139 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1083 "1083" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all time input values"); +DATA(insert OID = 2140 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1266 "1266" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all time with time zone input values"); +DATA(insert OID = 2141 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all money input values"); +DATA(insert OID = 2142 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all timestamp input values"); +DATA(insert OID = 2143 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1184 "1184" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all timestamp with time zone input values"); +DATA(insert OID = 2144 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all interval input values"); +DATA(insert OID = 2145 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all text values"); +DATA(insert OID = 2146 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all numeric input values"); +DATA(insert OID = 2051 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2277" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all anyarray input values"); +DATA(insert OID = 2245 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "1042" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all bpchar input values"); +DATA(insert OID = 2798 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all tid input values"); + +/* count has two forms: count(any) and count(*) */ +DATA(insert OID = 2147 ( count PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "2276" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows for which the input expression is not null"); +#define ANYCOUNTOID 2147 +DATA(insert OID = 2803 ( count PGNSP PGUID 12 1 0 0 0 t f f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows"); +#define COUNTOID 2803 + +DATA(insert OID = 2718 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of bigint input values (square of the population standard deviation)"); +DATA(insert OID = 2719 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of integer input values (square of the population standard deviation)"); +DATA(insert OID = 2720 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of smallint input values (square of the population standard deviation)"); +DATA(insert OID = 2721 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of float4 input values (square of the population standard deviation)"); +DATA(insert OID = 2722 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of float8 input values (square of the population standard deviation)"); +DATA(insert OID = 2723 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of numeric input values (square of the population standard deviation)"); + +DATA(insert OID = 2641 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of bigint input values (square of the sample standard deviation)"); +DATA(insert OID = 2642 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of integer input values (square of the sample standard deviation)"); +DATA(insert OID = 2643 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of smallint input values (square of the sample standard deviation)"); +DATA(insert OID = 2644 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of float4 input values (square of the sample standard deviation)"); + +DATA(insert OID = 2645 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of float8 input values (square of the sample standard deviation)"); +DATA(insert OID = 2646 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of numeric input values (square of the sample standard deviation)"); + +DATA(insert OID = 2148 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2149 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2150 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2151 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2152 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2153 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); + +DATA(insert OID = 2724 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of bigint input values"); +DATA(insert OID = 2725 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of integer input values"); +DATA(insert OID = 2726 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of smallint input values"); +DATA(insert OID = 2727 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of float4 input values"); +DATA(insert OID = 2728 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of float8 input values"); +DATA(insert OID = 2729 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of numeric input values"); + +DATA(insert OID = 2712 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of bigint input values"); +DATA(insert OID = 2713 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of integer input values"); +DATA(insert OID = 2714 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of smallint input values"); +DATA(insert OID = 2715 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of float4 input values"); +DATA(insert OID = 2716 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of float8 input values"); +DATA(insert OID = 2717 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of numeric input values"); + +DATA(insert OID = 2154 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2155 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2156 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2157 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2158 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2159 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); + +DATA(insert OID = 2818 ( regr_count PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 20 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows in which both expressions are not null"); +DATA(insert OID = 2819 ( regr_sxx PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of squares of the independent variable (sum(X^2) - sum(X)^2/N)"); +DATA(insert OID = 2820 ( regr_syy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of squares of the dependent variable (sum(Y^2) - sum(Y)^2/N)"); +DATA(insert OID = 2821 ( regr_sxy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of products of independent times dependent variable (sum(X*Y) - sum(X) * sum(Y)/N)"); +DATA(insert OID = 2822 ( regr_avgx PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("average of the independent variable (sum(X)/N)"); +DATA(insert OID = 2823 ( regr_avgy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("average of the dependent variable (sum(Y)/N)"); +DATA(insert OID = 2824 ( regr_r2 PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("square of the correlation coefficient"); +DATA(insert OID = 2825 ( regr_slope PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("slope of the least-squares-fit linear equation determined by the (X, Y) pairs"); +DATA(insert OID = 2826 ( regr_intercept PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs"); + +DATA(insert OID = 2827 ( covar_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population covariance"); +DATA(insert OID = 2828 ( covar_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample covariance"); +DATA(insert OID = 2829 ( corr PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("correlation coefficient"); + +DATA(insert OID = 2160 ( text_pattern_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2161 ( text_pattern_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2163 ( text_pattern_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2164 ( text_pattern_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2166 ( bttext_pattern_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ bttext_pattern_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2174 ( bpchar_pattern_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2175 ( bpchar_pattern_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2177 ( bpchar_pattern_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2178 ( bpchar_pattern_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2180 ( btbpchar_pattern_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 1042" _null_ _null_ _null_ _null_ btbpchar_pattern_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2188 ( btint48cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 20" _null_ _null_ _null_ _null_ btint48cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2189 ( btint84cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ btint84cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2190 ( btint24cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ btint24cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2191 ( btint42cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ btint42cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2192 ( btint28cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 20" _null_ _null_ _null_ _null_ btint28cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2193 ( btint82cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 21" _null_ _null_ _null_ _null_ btint82cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2194 ( btfloat48cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 701" _null_ _null_ _null_ _null_ btfloat48cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2195 ( btfloat84cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 700" _null_ _null_ _null_ _null_ btfloat84cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2212 ( regprocedurein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2202 "2275" _null_ _null_ _null_ _null_ regprocedurein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2213 ( regprocedureout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2202" _null_ _null_ _null_ _null_ regprocedureout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2214 ( regoperin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2203 "2275" _null_ _null_ _null_ _null_ regoperin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2215 ( regoperout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2203" _null_ _null_ _null_ _null_ regoperout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2216 ( regoperatorin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2204 "2275" _null_ _null_ _null_ _null_ regoperatorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2217 ( regoperatorout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2204" _null_ _null_ _null_ _null_ regoperatorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2218 ( regclassin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "2275" _null_ _null_ _null_ _null_ regclassin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2219 ( regclassout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2205" _null_ _null_ _null_ _null_ regclassout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2220 ( regtypein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2206 "2275" _null_ _null_ _null_ _null_ regtypein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2221 ( regtypeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2206" _null_ _null_ _null_ _null_ regtypeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ "" f)); +DESCR("convert text to regclass"); + +DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 2248 ( fmgr_sql_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_sql_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 2250 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_database_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by username, database name"); +DATA(insert OID = 2251 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_database_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by username, database oid"); +DATA(insert OID = 2252 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_database_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by user oid, database name"); +DATA(insert OID = 2253 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_database_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by user oid, database oid"); +DATA(insert OID = 2254 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_database_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on database by database name"); +DATA(insert OID = 2255 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_database_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on database by database oid"); + +DATA(insert OID = 2256 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_function_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by username, function name"); +DATA(insert OID = 2257 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_function_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by username, function oid"); +DATA(insert OID = 2258 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_function_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by user oid, function name"); +DATA(insert OID = 2259 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_function_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by user oid, function oid"); +DATA(insert OID = 2260 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_function_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on function by function name"); +DATA(insert OID = 2261 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_function_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on function by function oid"); + +DATA(insert OID = 2262 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_language_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by username, language name"); +DATA(insert OID = 2263 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_language_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by username, language oid"); +DATA(insert OID = 2264 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_language_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by user oid, language name"); +DATA(insert OID = 2265 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_language_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by user oid, language oid"); +DATA(insert OID = 2266 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_language_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on language by language name"); +DATA(insert OID = 2267 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_language_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on language by language oid"); + +DATA(insert OID = 2268 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_schema_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by username, schema name"); +DATA(insert OID = 2269 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_schema_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by username, schema oid"); +DATA(insert OID = 2270 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_schema_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by user oid, schema name"); +DATA(insert OID = 2271 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_schema_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by user oid, schema oid"); +DATA(insert OID = 2272 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_schema_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on schema by schema name"); +DATA(insert OID = 2273 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_schema_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on schema by schema oid"); + +DATA(insert OID = 2390 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by username, tablespace name"); +DATA(insert OID = 2391 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by username, tablespace oid"); +DATA(insert OID = 2392 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by user oid, tablespace name"); +DATA(insert OID = 2393 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by user oid, tablespace oid"); +DATA(insert OID = 2394 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on tablespace by tablespace name"); +DATA(insert OID = 2395 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on tablespace by tablespace oid"); + +DATA(insert OID = 3000 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by username, foreign data wrapper name"); +DATA(insert OID = 3001 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by username, foreign data wrapper oid"); +DATA(insert OID = 3002 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by user oid, foreign data wrapper name"); +DATA(insert OID = 3003 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by user oid, foreign data wrapper oid"); +DATA(insert OID = 3004 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on foreign data wrapper by foreign data wrapper name"); +DATA(insert OID = 3005 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on foreign data wrapper by foreign data wrapper oid"); + +DATA(insert OID = 3006 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_server_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by username, server name"); +DATA(insert OID = 3007 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_server_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by username, server oid"); +DATA(insert OID = 3008 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_server_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by user oid, server name"); +DATA(insert OID = 3009 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_server_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by user oid, server oid"); +DATA(insert OID = 3010 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_server_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on server by server name"); +DATA(insert OID = 3011 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_server_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on server by server oid"); + +DATA(insert OID = 3138 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_type_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by username, type name"); +DATA(insert OID = 3139 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_type_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by username, type oid"); +DATA(insert OID = 3140 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_type_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by user oid, type name"); +DATA(insert OID = 3141 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_type_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by user oid, type oid"); +DATA(insert OID = 3142 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_type_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on type by type name"); +DATA(insert OID = 3143 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_type_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on type by type oid"); + +DATA(insert OID = 2705 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 19 25" _null_ _null_ _null_ _null_ pg_has_role_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by username, role name"); +DATA(insert OID = 2706 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ pg_has_role_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by username, role oid"); +DATA(insert OID = 2707 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 19 25" _null_ _null_ _null_ _null_ pg_has_role_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by user oid, role name"); +DATA(insert OID = 2708 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ pg_has_role_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by user oid, role oid"); +DATA(insert OID = 2709 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "19 25" _null_ _null_ _null_ _null_ pg_has_role_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on role by role name"); +DATA(insert OID = 2710 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ pg_has_role_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on role by role oid"); + +DATA(insert OID = 1269 ( pg_column_size PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "2276" _null_ _null_ _null_ _null_ pg_column_size _null_ _null_ _null_ "" f)); +DESCR("bytes required to store the value, perhaps with compression"); +#define PGCOLUMNSIZEFUNCOID 1269 +DATA(insert OID = 2322 ( pg_tablespace_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_tablespace_size_oid _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified tablespace"); +DATA(insert OID = 2323 ( pg_tablespace_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "19" _null_ _null_ _null_ _null_ pg_tablespace_size_name _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified tablespace"); +DATA(insert OID = 2324 ( pg_database_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_database_size_oid _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified database"); +DATA(insert OID = 4049 ( gs_switch_relfilenode PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 2205" _null_ _null_ _null_ _null_ pg_switch_relfilenode_name _null_ _null_ _null_ "" f)); +DESCR("exchange relfilenodes between relations or partitions"); +DATA(insert OID = 2168 ( pg_database_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "19" _null_ _null_ _null_ _null_ pg_database_size_name _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified database"); +DATA(insert OID = 2325 ( pg_relation_size PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ "select pg_catalog.pg_relation_size($1, ''main'')" _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the main fork of the specified table or index"); +DATA(insert OID = 2332 ( pg_relation_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 25" _null_ _null_ _null_ _null_ pg_relation_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified fork of a table or index"); +DATA(insert OID = 2286 ( pg_total_relation_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_total_relation_size _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified table and associated indexes"); +DATA(insert OID = 2288 ( pg_size_pretty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "20" _null_ _null_ _null_ _null_ pg_size_pretty _null_ _null_ _null_ "" f)); +DESCR("convert a long int to a human readable text using size units"); +DATA(insert OID = 3166 ( pg_size_pretty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "1700" _null_ _null_ _null_ _null_ pg_size_pretty_numeric _null_ _null_ _null_ "" f)); +DESCR("convert a numeric to a human readable text using size units"); +DATA(insert OID = 2997 ( pg_table_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_table_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified table, including TOAST, free space and visibility map"); +DATA(insert OID = 3193 ( pg_partition_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "25 25" _null_ _null_ _null_ _null_ pg_partition_size_name _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified partition, including TOAST, free space and visibility map"); +DATA(insert OID = 3194 ( pg_partition_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "26 26" _null_ _null_ _null_ _null_ pg_partition_size_oid _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified partition, including TOAST, free space and visibility map"); +DATA(insert OID = 3195 ( pg_partition_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "25 25" _null_ _null_ _null_ _null_ pg_partition_indexes_size_name _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified partition"); +DATA(insert OID = 3196 ( pg_partition_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "26 26" _null_ _null_ _null_ _null_ pg_partition_indexes_size_oid _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified partition"); +DATA(insert OID = 2998 ( pg_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_indexes_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified table"); +DATA(insert OID = 2999 ( pg_relation_filenode PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "2205" _null_ _null_ _null_ _null_ pg_relation_filenode _null_ _null_ _null_ "" f)); +DESCR("filenode identifier of relation"); +DATA(insert OID = 3197 ( pg_partition_filenode PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "2205" _null_ _null_ _null_ _null_ pg_partition_filenode _null_ _null_ _null_ "" f)); +DESCR("filenode identifier of partition"); +DATA(insert OID = 3034 ( pg_relation_filepath PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "2205" _null_ _null_ _null_ _null_ pg_relation_filepath _null_ _null_ _null_ "" f)); +DESCR("file path of relation"); + +/* usable for column orientated table */ +DATA(insert OID = 3210 ( pg_relation_with_compression PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ pg_relation_with_compression _null_ _null_ _null_ "" f)); +DESCR("query the relation's compression attrubute"); +DATA(insert OID = 3211 ( pg_relation_compression_ratio PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "25" _null_ _null_ _null_ _null_ pg_relation_compression_ratio _null_ _null_ _null_ "" f)); +DESCR("query the relation data's compression ration"); + +DATA(insert OID = 2316 ( postgresql_fdw_validator PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1009 26" _null_ _null_ _null_ _null_ postgresql_fdw_validator _null_ _null_ _null_"" f)); +DESCR("(internal)"); + +DATA(insert OID = 2290 ( record_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2249 "2275 26 23" _null_ _null_ _null_ _null_ record_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2291 ( record_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2249" _null_ _null_ _null_ _null_ record_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2292 ( cstring_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2275" _null_ _null_ _null_ _null_ cstring_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2293 ( cstring_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2275" _null_ _null_ _null_ _null_ cstring_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2294 ( any_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2276 "2275" _null_ _null_ _null_ _null_ any_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2295 ( any_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2276" _null_ _null_ _null_ _null_ any_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2296 ( anyarray_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2277 "2275" _null_ _null_ _null_ _null_ anyarray_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ANYARRAYINFUNCOID 2296 +DATA(insert OID = 2297 ( anyarray_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2277" _null_ _null_ _null_ _null_ anyarray_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2298 ( void_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2275" _null_ _null_ _null_ _null_ void_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2299 ( void_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2278" _null_ _null_ _null_ _null_ void_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2300 ( trigger_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2279 "2275" _null_ _null_ _null_ _null_ trigger_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2301 ( trigger_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2279" _null_ _null_ _null_ _null_ trigger_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2302 ( language_handler_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2280 "2275" _null_ _null_ _null_ _null_ language_handler_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2303 ( language_handler_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2280" _null_ _null_ _null_ _null_ language_handler_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2304 ( internal_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2281 "2275" _null_ _null_ _null_ _null_ internal_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2305 ( internal_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2281" _null_ _null_ _null_ _null_ internal_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2306 ( opaque_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2282 "2275" _null_ _null_ _null_ _null_ opaque_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2307 ( opaque_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2282" _null_ _null_ _null_ _null_ opaque_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2312 ( anyelement_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "2275" _null_ _null_ _null_ _null_ anyelement_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2313 ( anyelement_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2283" _null_ _null_ _null_ _null_ anyelement_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2398 ( shell_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2282 "2275" _null_ _null_ _null_ _null_ shell_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2399 ( shell_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2282" _null_ _null_ _null_ _null_ shell_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2597 ( domain_in PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2276 "2275 26 23" _null_ _null_ _null_ _null_ domain_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2598 ( domain_recv PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2276 "2281 26 23" _null_ _null_ _null_ _null_ domain_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2777 ( anynonarray_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2776 "2275" _null_ _null_ _null_ _null_ anynonarray_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2778 ( anynonarray_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2776" _null_ _null_ _null_ _null_ anynonarray_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3116 ( fdw_handler_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 3115 "2275" _null_ _null_ _null_ _null_ fdw_handler_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3117 ( fdw_handler_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3115" _null_ _null_ _null_ _null_ fdw_handler_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* cryptographic */ +DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ md5_text _null_ _null_ _null_ "" f)); +DESCR("MD5 hash"); +DATA(insert OID = 2321 ( md5 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "17" _null_ _null_ _null_ _null_ md5_bytea _null_ _null_ _null_ "" f)); +DESCR("MD5 hash"); + +/* crosstype operations for date vs. timestamp and timestamptz */ +DATA(insert OID = 2338 ( date_lt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_lt_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2339 ( date_le_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_le_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2340 ( date_eq_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_eq_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2341 ( date_gt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_gt_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2342 ( date_ge_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_ge_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2343 ( date_ne_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_ne_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2344 ( date_cmp_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1114" _null_ _null_ _null_ _null_ date_cmp_timestamp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2351 ( date_lt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_lt_timestamptz _null_ _null_ _null_ "" f)); +#define DATELTTIMESTAMPTZFUNCOID 2351 +DATA(insert OID = 2352 ( date_le_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_le_timestamptz _null_ _null_ _null_ "" f)); +#define DATELETIMESTAMPTZFUNCOID 2352 +DATA(insert OID = 2353 ( date_eq_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_eq_timestamptz _null_ _null_ _null_ "" f)); +#define DATEEQTIMESTAMPTZFUNCOID 2353 +DATA(insert OID = 2354 ( date_gt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_gt_timestamptz _null_ _null_ _null_ "" f)); +#define DATEGTTIMESTAMPTZFUNCOID 2354 +DATA(insert OID = 2355 ( date_ge_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_ge_timestamptz _null_ _null_ _null_ "" f)); +#define DATEGETIMESTAMPTZFUNCOID 2355 +DATA(insert OID = 2356 ( date_ne_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_ne_timestamptz _null_ _null_ _null_ "" f)); +#define DATENETIMESTAMPTZFUNCOID 2356 +DATA(insert OID = 2357 ( date_cmp_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1082 1184" _null_ _null_ _null_ _null_ date_cmp_timestamptz _null_ _null_ _null_ "" f)); +#define DATECMPTIMESTAMPTZFUNCOID 2357 +DESCR("less-equal-greater"); + +DATA(insert OID = 2364 ( timestamp_lt_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_lt_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2365 ( timestamp_le_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_le_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2366 ( timestamp_eq_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_eq_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2367 ( timestamp_gt_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_gt_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2368 ( timestamp_ge_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_ge_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2369 ( timestamp_ne_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_ne_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2370 ( timestamp_cmp_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 1082" _null_ _null_ _null_ _null_ timestamp_cmp_date _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2377 ( timestamptz_lt_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_lt_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLTDATEFUNCOID 2377 +DATA(insert OID = 2378 ( timestamptz_le_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_le_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLEDATEFUNCOID 2378 +DATA(insert OID = 2379 ( timestamptz_eq_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_eq_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZEQDATEFUNCOID 2379 +DATA(insert OID = 2380 ( timestamptz_gt_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_gt_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGTDATEFUNCOID 2380 +DATA(insert OID = 2381 ( timestamptz_ge_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_ge_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGEDATEFUNCOID 2381 +DATA(insert OID = 2382 ( timestamptz_ne_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_ne_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZNEDATEFUNCOID 2382 +DATA(insert OID = 2383 ( timestamptz_cmp_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_cmp_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZCMPDATEFUNCOID 2383 + +DESCR("less-equal-greater"); + +/* crosstype operations for timestamp vs. timestamptz */ +DATA(insert OID = 2520 ( timestamp_lt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_lt_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPLTTIMESTAMPTZFUNCOID 2520 + +DATA(insert OID = 2521 ( timestamp_le_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_le_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPLETIMESTAMPTZFUNCOID 2521 +DATA(insert OID = 2522 ( timestamp_eq_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_eq_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPEQTIMESTAMPTZFUNCOID 2522 +DATA(insert OID = 2523 ( timestamp_gt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_gt_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPGTTIMESTAMPTZFUNCOID 2523 +DATA(insert OID = 2524 ( timestamp_ge_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_ge_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPGETIMESTAMPTZFUNCOID 2524 +DATA(insert OID = 2525 ( timestamp_ne_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_ne_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPNETIMESTAMPTZFUNCOID 2525 +DATA(insert OID = 2526 ( timestamp_cmp_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1114 1184" _null_ _null_ _null_ _null_ timestamp_cmp_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPCMPTIMESTAMPTZFUNCOID 2526 +DESCR("less-equal-greater"); + +DATA(insert OID = 2527 ( timestamptz_lt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_lt_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLTTIMESTAMPFUNCOID 2527 +DATA(insert OID = 2528 ( timestamptz_le_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_le_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLETIMESTAMPFUNCOID 2528 +DATA(insert OID = 2529 ( timestamptz_eq_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_eq_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZEQTIMESTAMPFUNCOID 2529 +DATA(insert OID = 2530 ( timestamptz_gt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_gt_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGTTIMESTAMPFUNCOID 2530 +DATA(insert OID = 2531 ( timestamptz_ge_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_ge_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGETIMESTAMPFUNCOID 2531 +DATA(insert OID = 2532 ( timestamptz_ne_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_ne_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZNETIMESTAMPFUNCOID 2532 +DATA(insert OID = 2533 ( timestamptz_cmp_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_cmp_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZCMPTIMESTAMPFUNCOID 2533 +DESCR("less-equal-greater"); + + +/* send/receive functions */ +DATA(insert OID = 2400 ( array_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2281 26 23" _null_ _null_ _null_ _null_ array_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2401 ( array_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2277" _null_ _null_ _null_ _null_ array_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2402 ( record_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2249 "2281 26 23" _null_ _null_ _null_ _null_ record_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2403 ( record_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2249" _null_ _null_ _null_ _null_ record_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2404 ( int2recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "2281" _null_ _null_ _null_ _null_ int2recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2405 ( int2send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "21" _null_ _null_ _null_ _null_ int2send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5543 ( int1recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "2281" _null_ _null_ _null_ _null_ int1recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5544 ( int1send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "5545" _null_ _null_ _null_ _null_ int1send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5521 ( int1_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "5545" _null_ _null_ _null_ _null_ int1_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int1 to numeric"); +DATA(insert OID = 5522 ( numeric_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "1700" _null_ _null_ _null_ _null_ numeric_int1 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int1"); +DATA(insert OID = 5523 ( i1toi2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "5545" _null_ _null_ _null_ _null_ i1toi2 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int2"); +DATA(insert OID = 5524 ( i2toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "21" _null_ _null_ _null_ _null_ i2toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int1"); +DATA(insert OID = 5525 ( i1toi4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "5545" _null_ _null_ _null_ _null_ i1toi4 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int4"); +DATA(insert OID = 5526 ( i4toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "23" _null_ _null_ _null_ _null_ i4toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int1"); +DATA(insert OID = 5527 ( i1toi8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "5545" _null_ _null_ _null_ _null_ i1toi8 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int8"); +DATA(insert OID = 5528 ( i8toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "20" _null_ _null_ _null_ _null_ i8toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int1"); +DATA(insert OID = 5529 ( i1tof4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "5545" _null_ _null_ _null_ _null_ i1tof4 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to float4"); +DATA(insert OID = 5530 ( f4toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "700" _null_ _null_ _null_ _null_ f4toi1 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int1"); +DATA(insert OID = 5531 ( i1tof8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "5545" _null_ _null_ _null_ _null_ i1tof8 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to float8"); +DATA(insert OID = 5532 ( f8toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "701" _null_ _null_ _null_ _null_ f8toi1 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int1"); +DATA(insert OID = 5533 ( int1_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "5545" _null_ _null_ _null_ _null_ int1_bool _null_ _null_ _null_ "" f)); +DESCR("convert int1 to bool"); +DATA(insert OID = 5534 ( bool_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "16" _null_ _null_ _null_ _null_ bool_int1 _null_ _null_ _null_ "" f)); +DESCR("convert bool to int1"); +DATA(insert OID = 3192 ( int4_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "23" _null_ _null_ _null_ _null_ int4_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to bpchar"); +DATA(insert OID = 2406 ( int4recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2281" _null_ _null_ _null_ _null_ int4recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2407 ( int4send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "23" _null_ _null_ _null_ _null_ int4send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2408 ( int8recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2281" _null_ _null_ _null_ _null_ int8recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2409 ( int8send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "20" _null_ _null_ _null_ _null_ int8send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2410 ( int2vectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 22 "2281" _null_ _null_ _null_ _null_ int2vectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2411 ( int2vectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "22" _null_ _null_ _null_ _null_ int2vectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2412 ( bytearecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytearecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2413 ( byteasend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "17" _null_ _null_ _null_ _null_ byteasend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 4033 ( rawrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 86 "2281" _null_ _null_ _null_ _null_ bytearecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4034 ( rawsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "86" _null_ _null_ _null_ _null_ byteasend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4037 ( rawtohex PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "86" _null_ _null_ _null_ _null_ rawtotext _null_ _null_ _null_ "" f)); +DESCR("raw convert text"); +DATA(insert OID = 4038 ( hextoraw PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 86 "25" _null_ _null_ _null_ _null_ texttoraw _null_ _null_ _null_ "" f)); +DESCR("text convert to raw"); + +DATA(insert OID = 2414 ( textrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "2281" _null_ _null_ _null_ _null_ textrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2415 ( textsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "25" _null_ _null_ _null_ _null_ textsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2416 ( unknownrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 705 "2281" _null_ _null_ _null_ _null_ unknownrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2417 ( unknownsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "705" _null_ _null_ _null_ _null_ unknownsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2418 ( oidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2281" _null_ _null_ _null_ _null_ oidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2419 ( oidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "26" _null_ _null_ _null_ _null_ oidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2420 ( oidvectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 30 "2281" _null_ _null_ _null_ _null_ oidvectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2421 ( oidvectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "30" _null_ _null_ _null_ _null_ oidvectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2422 ( namerecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "2281" _null_ _null_ _null_ _null_ namerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2423 ( namesend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "19" _null_ _null_ _null_ _null_ namesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2424 ( float4recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "2281" _null_ _null_ _null_ _null_ float4recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2425 ( float4send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "700" _null_ _null_ _null_ _null_ float4send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2426 ( float8recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "2281" _null_ _null_ _null_ _null_ float8recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2427 ( float8send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "701" _null_ _null_ _null_ _null_ float8send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2428 ( point_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "2281" _null_ _null_ _null_ _null_ point_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2429 ( point_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "600" _null_ _null_ _null_ _null_ point_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2430 ( bpcharrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1042 "2281 26 23" _null_ _null_ _null_ _null_ bpcharrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2431 ( bpcharsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "1042" _null_ _null_ _null_ _null_ bpcharsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2432 ( varcharrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1043 "2281 26 23" _null_ _null_ _null_ _null_ varcharrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2433 ( varcharsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "1043" _null_ _null_ _null_ _null_ varcharsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3966 ( nvarchar2recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3969 "2281 26 23" _null_ _null_ _null_ _null_ nvarchar2recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3967 ( nvarchar2send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3969" _null_ _null_ _null_ _null_ nvarchar2send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2434 ( charrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "2281" _null_ _null_ _null_ _null_ charrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2435 ( charsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "18" _null_ _null_ _null_ _null_ charsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2436 ( boolrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "2281" _null_ _null_ _null_ _null_ boolrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2437 ( boolsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "16" _null_ _null_ _null_ _null_ boolsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2438 ( tidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 27 "2281" _null_ _null_ _null_ _null_ tidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2439 ( tidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "27" _null_ _null_ _null_ _null_ tidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2440 ( xidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 28 "2281" _null_ _null_ _null_ _null_ xidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2441 ( xidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "28" _null_ _null_ _null_ _null_ xidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2442 ( cidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 29 "2281" _null_ _null_ _null_ _null_ cidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2443 ( cidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "29" _null_ _null_ _null_ _null_ cidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2444 ( regprocrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 24 "2281" _null_ _null_ _null_ _null_ regprocrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2445 ( regprocsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "24" _null_ _null_ _null_ _null_ regprocsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2446 ( regprocedurerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2202 "2281" _null_ _null_ _null_ _null_ regprocedurerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2447 ( regproceduresend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2202" _null_ _null_ _null_ _null_ regproceduresend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2448 ( regoperrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2203 "2281" _null_ _null_ _null_ _null_ regoperrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2449 ( regopersend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2203" _null_ _null_ _null_ _null_ regopersend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2450 ( regoperatorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2204 "2281" _null_ _null_ _null_ _null_ regoperatorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2451 ( regoperatorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2204" _null_ _null_ _null_ _null_ regoperatorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2452 ( regclassrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2205 "2281" _null_ _null_ _null_ _null_ regclassrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2453 ( regclasssend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2205" _null_ _null_ _null_ _null_ regclasssend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2206 "2281" _null_ _null_ _null_ _null_ regtyperecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2458 ( varbit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1562 "2281 26 23" _null_ _null_ _null_ _null_ varbit_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2459 ( varbit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1562" _null_ _null_ _null_ _null_ varbit_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2460 ( numeric_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1700 "2281 26 23" _null_ _null_ _null_ _null_ numeric_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2461 ( numeric_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1700" _null_ _null_ _null_ _null_ numeric_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2462 ( abstimerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "2281" _null_ _null_ _null_ _null_ abstimerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2463 ( abstimesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "702" _null_ _null_ _null_ _null_ abstimesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2464 ( reltimerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "2281" _null_ _null_ _null_ _null_ reltimerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2465 ( reltimesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "703" _null_ _null_ _null_ _null_ reltimesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2466 ( tintervalrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 704 "2281" _null_ _null_ _null_ _null_ tintervalrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2467 ( tintervalsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "704" _null_ _null_ _null_ _null_ tintervalsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2468 ( date_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "2281" _null_ _null_ _null_ _null_ date_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2469 ( date_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1082" _null_ _null_ _null_ _null_ date_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2470 ( time_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1083 "2281 26 23" _null_ _null_ _null_ _null_ time_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2471 ( time_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1083" _null_ _null_ _null_ _null_ time_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2472 ( timetz_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1266 "2281 26 23" _null_ _null_ _null_ _null_ timetz_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2473 ( timetz_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1266" _null_ _null_ _null_ _null_ timetz_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2474 ( timestamp_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1114 "2281 26 23" _null_ _null_ _null_ _null_ timestamp_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2475 ( timestamp_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1114" _null_ _null_ _null_ _null_ timestamp_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2476 ( timestamptz_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1184 "2281 26 23" _null_ _null_ _null_ _null_ timestamptz_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2477 ( timestamptz_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1184" _null_ _null_ _null_ _null_ timestamptz_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2478 ( interval_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1186 "2281 26 23" _null_ _null_ _null_ _null_ interval_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2479 ( interval_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1186" _null_ _null_ _null_ _null_ interval_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2480 ( lseg_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "2281" _null_ _null_ _null_ _null_ lseg_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2481 ( lseg_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "601" _null_ _null_ _null_ _null_ lseg_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2482 ( path_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "2281" _null_ _null_ _null_ _null_ path_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2483 ( path_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "602" _null_ _null_ _null_ _null_ path_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2484 ( box_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "2281" _null_ _null_ _null_ _null_ box_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2485 ( box_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "603" _null_ _null_ _null_ _null_ box_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2486 ( poly_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "2281" _null_ _null_ _null_ _null_ poly_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2487 ( poly_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "604" _null_ _null_ _null_ _null_ poly_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2488 ( line_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 628 "2281" _null_ _null_ _null_ _null_ line_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2489 ( line_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "628" _null_ _null_ _null_ _null_ line_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2490 ( circle_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "2281" _null_ _null_ _null_ _null_ circle_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2491 ( circle_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "718" _null_ _null_ _null_ _null_ circle_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2492 ( cash_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 790 "2281" _null_ _null_ _null_ _null_ cash_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2493 ( cash_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "790" _null_ _null_ _null_ _null_ cash_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2494 ( macaddr_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "2281" _null_ _null_ _null_ _null_ macaddr_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2495 ( macaddr_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "829" _null_ _null_ _null_ _null_ macaddr_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2496 ( inet_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "2281" _null_ _null_ _null_ _null_ inet_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2497 ( inet_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "869" _null_ _null_ _null_ _null_ inet_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2498 ( cidr_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "2281" _null_ _null_ _null_ _null_ cidr_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2499 ( cidr_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "650" _null_ _null_ _null_ _null_ cidr_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2500 ( cstring_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2281" _null_ _null_ _null_ _null_ cstring_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2501 ( cstring_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2275" _null_ _null_ _null_ _null_ cstring_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2502 ( anyarray_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2277 "2281" _null_ _null_ _null_ _null_ anyarray_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2277" _null_ _null_ _null_ _null_ anyarray_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3120 ( void_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ void_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3121 ( void_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2278" _null_ _null_ _null_ _null_ void_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* System-view support functions with pretty-print option */ +DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_ruledef_ext _null_ _null_ _null_ "" f)); +DESCR("source text of a rule with pretty-print option"); +DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 16" _null_ _null_ _null_ _null_ pg_get_viewdef_name_ext _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-print option"); +DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_viewdef_ext _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-print option"); +DATA(insert OID = 3159 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ pg_get_viewdef_wrap _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-printing and specified line wrapping"); +DATA(insert OID = 2507 ( pg_get_indexdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "26 23 16" _null_ _null_ _null_ _null_ pg_get_indexdef_ext _null_ _null_ _null_ "" f)); +DESCR("index description (full create statement or single expression) with pretty-print option"); +DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_constraintdef_ext _null_ _null_ _null_ "" f)); +DESCR("constraint description with pretty-print option"); +DATA(insert OID = 2509 ( pg_get_expr PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "194 26 16" _null_ _null_ _null_ _null_ pg_get_expr_ext _null_ _null_ _null_ "" f)); +DESCR("deparse an encoded expression with pretty-print option"); +DATA(insert OID = 2510 ( pg_prepared_statement PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,1184,2211,16}" "{o,o,o,o,o}" "{name,statement,prepare_time,parameter_types,from_sql}" _null_ pg_prepared_statement _null_ _null_ _null_ "" f)); +DESCR("get the prepared statements for this session"); +DATA(insert OID = 2511 ( pg_cursor PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,16,16,16,1184}" "{o,o,o,o,o,o}" "{name,statement,is_holdable,is_binary,is_scrollable,creation_time}" _null_ pg_cursor _null_ _null_ _null_ "" f)); +DESCR("get the open cursors for this session"); +DATA(insert OID = 2599 ( pg_timezone_abbrevs PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,1186,16}" "{o,o,o}" "{abbrev,utc_offset,is_dst}" _null_ pg_timezone_abbrevs _null_ _null_ _null_ "" f)); +DESCR("get the available time zone abbreviations"); +DATA(insert OID = 2856 ( pg_timezone_names PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,1186,16}" "{o,o,o,o}" "{name,abbrev,utc_offset,is_dst}" _null_ pg_timezone_names _null_ _null_ _null_ "" f)); +DESCR("get the available time zone names"); +DATA(insert OID = 2730 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_triggerdef_ext _null_ _null_ _null_ "" f)); +DESCR("trigger description with pretty-print option"); +DATA(insert OID = 3035 ( pg_listening_channels PGNSP PGUID 12 1 10 0 0 f f f f t t s 0 0 25 "" _null_ _null_ _null_ _null_ pg_listening_channels _null_ _null_ _null_ "" f)); +DESCR("get the channels that the current backend listens to"); +DATA(insert OID = 3036 ( pg_notify PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2278 "25 25" _null_ _null_ _null_ _null_ pg_notify _null_ _null_ _null_ "" f)); +DESCR("send a notification event"); + +/* non-persistent series generator */ +DATA(insert OID = 1066 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ generate_series_step_int4 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1067 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 23 "23 23" _null_ _null_ _null_ _null_ generate_series_int4 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1068 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 20 "20 20 20" _null_ _null_ _null_ _null_ generate_series_step_int8 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1069 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 20 "20 20" _null_ _null_ _null_ _null_ generate_series_int8 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 938 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 1114 "1114 1114 1186" _null_ _null_ _null_ _null_ generate_series_timestamp _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 939 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t s 3 0 1184 "1184 1184 1186" _null_ _null_ _null_ _null_ generate_series_timestamptz _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); + +/* boolean aggregates */ +DATA(insert OID = 2515 ( booland_statefunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ booland_statefunc _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2516 ( boolor_statefunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolor_statefunc _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2517 ( bool_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-and aggregate"); +/* ANY, SOME? These names conflict with subquery operators. See doc. */ +DATA(insert OID = 2518 ( bool_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-or aggregate"); +DATA(insert OID = 2519 ( every PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-and aggregate"); +#define EVERYFUNCOID 2519 + +/* bitwise integer aggregates */ +DATA(insert OID = 5539 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and tinyint aggregate"); +DATA(insert OID = 5540 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or tinyint aggregate"); +DATA(insert OID = 2236 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and smallint aggregate"); +DATA(insert OID = 2237 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or smallint aggregate"); +DATA(insert OID = 2238 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and integer aggregate"); +DATA(insert OID = 2239 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or integer aggregate"); +DATA(insert OID = 2240 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and bigint aggregate"); +DATA(insert OID = 2241 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or bigint aggregate"); +DATA(insert OID = 2242 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and bit aggregate"); +DATA(insert OID = 2243 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or bit aggregate"); + +/* formerly-missing interval + datetime operators */ +DATA(insert OID = 2546 ( interval_pl_date PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1186 1082" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2547 ( interval_pl_timetz PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1266 "1186 1266" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2548 ( interval_pl_timestamp PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1186 1114" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2549 ( interval_pl_timestamptz PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 1184 "1186 1184" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +#define INTERVALPLTIMESTAMPTZFUNCOID 2549 +DATA(insert OID = 2550 ( integer_pl_date PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1082 "23 1082" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2556 ( pg_tablespace_databases PGNSP PGUID 12 1 1000 0 0 f f f f t t s 1 0 26 "26" _null_ _null_ _null_ _null_ pg_tablespace_databases _null_ _null_ _null_ "" f)); +DESCR("get OIDs of databases in a tablespace"); + +DATA(insert OID = 2557 ( bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "23" _null_ _null_ _null_ _null_ int4_bool _null_ _null_ _null_ "" f)); +DESCR("convert int4 to boolean"); +DATA(insert OID = 2558 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "16" _null_ _null_ _null_ _null_ bool_int4 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int4"); +DATA(insert OID = 2559 ( lastval PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 20 "" _null_ _null_ _null_ _null_ lastval _null_ _null_ _null_ "" f)); +DESCR("current value from last used sequence"); +#define LASTVALFUNCOID 2559 + +/* start time function */ +DATA(insert OID = 2560 ( pg_postmaster_start_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_postmaster_start_time _null_ _null_ _null_ "" f)); +DESCR("postmaster start time"); +/* config reload time function */ +DATA(insert OID = 2034 ( pg_conf_load_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_conf_load_time _null_ _null_ _null_ "" f)); +DESCR("configuration load time"); + +/* new functions for Y-direction rtree opclasses */ +DATA(insert OID = 2562 ( box_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 2563 ( box_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2564 ( box_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overabove _null_ _null_ _null_ "" f)); +DATA(insert OID = 2565 ( box_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 2566 ( poly_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 2567 ( poly_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2568 ( poly_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overabove _null_ _null_ _null_ "" f)); +DATA(insert OID = 2569 ( poly_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 2587 ( circle_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2588 ( circle_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overabove _null_ _null_ _null_ "" f)); + +/* support functions for GiST r-tree emulation */ +DATA(insert OID = 2578 ( gist_box_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 603 23 26 2281" _null_ _null_ _null_ _null_ gist_box_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2579 ( gist_box_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_box_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2580 ( gist_box_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_box_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2581 ( gist_box_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gist_box_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2582 ( gist_box_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gist_box_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2583 ( gist_box_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "2281 2281" _null_ _null_ _null_ _null_ gist_box_union _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2584 ( gist_box_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "603 603 2281" _null_ _null_ _null_ _null_ gist_box_same _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2585 ( gist_poly_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 604 23 26 2281" _null_ _null_ _null_ _null_ gist_poly_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2586 ( gist_poly_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_poly_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2591 ( gist_circle_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 718 23 26 2281" _null_ _null_ _null_ _null_ gist_circle_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2592 ( gist_circle_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_circle_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 1030 ( gist_point_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_point_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2179 ( gist_point_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 600 23 26 2281" _null_ _null_ _null_ _null_ gist_point_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3064 ( gist_point_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 701 "2281 600 23 26" _null_ _null_ _null_ _null_ gist_point_distance _null_ _null_ _null_ "" f)); +DESCR("GiST support"); + +/* GIN */ +DATA(insert OID = 2731 ( gingetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ gingetbitmap _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2732 ( gininsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gininsert _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2733 ( ginbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ginbeginscan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2734 ( ginrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginrescan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2735 ( ginendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginendscan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2736 ( ginmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginmarkpos _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2737 ( ginrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginrestrpos _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 3186 ( ginmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginmerge _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2738 ( ginbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ginbuild _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 325 ( ginbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginbuildempty _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2739 ( ginbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginbulkdelete _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2740 ( ginvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ ginvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2741 ( gincostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gincostestimate _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2788 ( ginoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ ginoptions _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); + +/* GIN array support */ +DATA(insert OID = 2743 ( ginarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2277 2281 2281" _null_ _null_ _null_ _null_ ginarrayextract _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 2774 ( ginqueryarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "2277 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginqueryarrayextract _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 2744 ( ginarrayconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 2277 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginarrayconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 3920 ( ginarraytriconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 16 "2281 21 2277 23 2281 2281 2281" _null_ _null_ _null_ _null_ ginarraytriconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 3076 ( ginarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2277 2281" _null_ _null_ _null_ _null_ ginarrayextract_2args _null_ _null_ _null_ "" f)); +DESCR("GIN array support (obsolete)"); + +/* overlap/contains/contained */ +DATA(insert OID = 2747 ( arrayoverlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arrayoverlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 2748 ( arraycontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arraycontains _null_ _null_ _null_ "" f)); +DATA(insert OID = 2749 ( arraycontained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arraycontained _null_ _null_ _null_ "" f)); + +/* userlock replacements */ +DATA(insert OID = 2880 ( pg_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 3089 ( pg_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 2881 ( pg_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 3090 ( pg_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 2882 ( pg_try_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 3091 ( pg_try_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 2883 ( pg_try_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 3092 ( pg_try_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 2884 ( pg_advisory_unlock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_advisory_unlock_int8 _null_ _null_ _null_ "" f)); +DESCR("release exclusive advisory lock"); +DATA(insert OID = 2885 ( pg_advisory_unlock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_advisory_unlock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("release shared advisory lock"); +DATA(insert OID = 2886 ( pg_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 3093 ( pg_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 2887 ( pg_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 3094 ( pg_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 2888 ( pg_try_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 3095 ( pg_try_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 2889 ( pg_try_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 3096 ( pg_try_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 2890 ( pg_advisory_unlock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_advisory_unlock_int4 _null_ _null_ _null_ "" f)); +DESCR("release exclusive advisory lock"); +DATA(insert OID = 2891 ( pg_advisory_unlock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_advisory_unlock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("release shared advisory lock"); +DATA(insert OID = 2892 ( pg_advisory_unlock_all PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_advisory_unlock_all _null_ _null_ _null_ "" f)); +DESCR("release all advisory locks"); + +/* XML support */ +DATA(insert OID = 2893 ( xml_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "2275" _null_ _null_ _null_ _null_ xml_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2894 ( xml_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "142" _null_ _null_ _null_ _null_ xml_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2895 ( xmlcomment PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 142 "25" _null_ _null_ _null_ _null_ xmlcomment _null_ _null_ _null_ "" f)); +DESCR("generate XML comment"); +DATA(insert OID = 2896 ( xml PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "25" _null_ _null_ _null_ _null_ texttoxml _null_ _null_ _null_ "" f)); +DESCR("perform a non-validating parse of a character string to produce an XML value"); +DATA(insert OID = 2897 ( xmlvalidate PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "142 25" _null_ _null_ _null_ _null_ xmlvalidate _null_ _null_ _null_ "" f)); +DESCR("validate an XML value"); +DATA(insert OID = 2898 ( xml_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "2281" _null_ _null_ _null_ _null_ xml_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2899 ( xml_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "142" _null_ _null_ _null_ _null_ xml_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2900 ( xmlconcat2 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 142 "142 142" _null_ _null_ _null_ _null_ xmlconcat2 _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2901 ( xmlagg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 142 "142" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate XML values"); +#define XMLAGGFUNCOID 2901 +DATA(insert OID = 2922 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "142" _null_ _null_ _null_ _null_ xmltotext _null_ _null_ _null_ "" f)); +DESCR("serialize an XML value to a character string"); + +DATA(insert OID = 2923 ( table_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xml _null_ _null_ _null_ "" f)); +DESCR("map table contents to XML"); +DATA(insert OID = 2924 ( query_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xml _null_ _null_ _null_ "" f)); +DESCR("map query result to XML"); +DATA(insert OID = 2925 ( cursor_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 5 0 142 "1790 23 16 16 25" _null_ _null_ "{cursor,count,nulls,tableforest,targetns}" _null_ cursor_to_xml _null_ _null_ _null_ "" f)); +DESCR("map rows from cursor to XML"); +DATA(insert OID = 2926 ( table_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map table structure to XML Schema"); +DATA(insert OID = 2927 ( query_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map query result structure to XML Schema"); +DATA(insert OID = 2928 ( cursor_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "1790 16 16 25" _null_ _null_ "{cursor,nulls,tableforest,targetns}" _null_ cursor_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map cursor structure to XML Schema"); +DATA(insert OID = 2929 ( table_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map table contents and structure to XML and XML Schema"); +DATA(insert OID = 2930 ( query_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map query result and structure to XML and XML Schema"); + +DATA(insert OID = 2933 ( schema_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xml _null_ _null_ _null_ "" f)); +DESCR("map schema contents to XML"); +DATA(insert OID = 2934 ( schema_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map schema structure to XML Schema"); +DATA(insert OID = 2935 ( schema_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map schema contents and structure to XML and XML Schema"); + +DATA(insert OID = 2936 ( database_to_xml PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xml _null_ _null_ _null_ "" f)); +DESCR("map database contents to XML"); +DATA(insert OID = 2937 ( database_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map database structure to XML Schema"); +DATA(insert OID = 2938 ( database_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map database contents and structure to XML and XML Schema"); + +DATA(insert OID = 2931 ( xpath PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 143 "25 142 1009" _null_ _null_ _null_ _null_ xpath _null_ _null_ _null_ "" f)); +DESCR("evaluate XPath expression, with namespaces support"); +DATA(insert OID = 2932 ( xpath PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 143 "25 142" _null_ _null_ _null_ _null_ "select pg_catalog.xpath($1, $2, ''{}''::pg_catalog.text[])" _null_ _null_ _null_ "" f)); +DESCR("evaluate XPath expression"); + +DATA(insert OID = 2614 ( xmlexists PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 142" _null_ _null_ _null_ _null_ xmlexists _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression"); + +DATA(insert OID = 3049 ( xpath_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 16 "25 142 1009" _null_ _null_ _null_ _null_ xpath_exists _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression, with namespace support"); +DATA(insert OID = 3050 ( xpath_exists PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 16 "25 142" _null_ _null_ _null_ _null_ "select pg_catalog.xpath_exists($1, $2, ''{}''::pg_catalog.text[])" _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression"); +DATA(insert OID = 3051 ( xml_is_well_formed PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML"); +DATA(insert OID = 3052 ( xml_is_well_formed_document PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed_document _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML document"); +DATA(insert OID = 3053 ( xml_is_well_formed_content PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed_content _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML content"); + +/* json */ +DATA(insert OID = 321 ( json_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2275" _null_ _null_ _null_ _null_ json_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 322 ( json_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "114" _null_ _null_ _null_ _null_ json_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 323 ( json_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2281" _null_ _null_ _null_ _null_ json_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 324 ( json_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "114" _null_ _null_ _null_ _null_ json_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3153 ( array_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2277" _null_ _null_ _null_ _null_ array_to_json _null_ _null_ _null_ "" f)); +DESCR("map array to json"); +DATA(insert OID = 3154 ( array_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "2277 16" _null_ _null_ _null_ _null_ array_to_json_pretty _null_ _null_ _null_ "" f)); +DESCR("map array to json with optional pretty printing"); +DATA(insert OID = 3155 ( row_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2249" _null_ _null_ _null_ _null_ row_to_json _null_ _null_ _null_ "" f)); +DESCR("map row to json"); +DATA(insert OID = 3156 ( row_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "2249 16" _null_ _null_ _null_ _null_ row_to_json_pretty _null_ _null_ _null_ "" f)); +DESCR("map row to json with optional pretty printing"); + +/* uuid */ +DATA(insert OID = 2952 ( uuid_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2950 "2275" _null_ _null_ _null_ _null_ uuid_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2953 ( uuid_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2950" _null_ _null_ _null_ _null_ uuid_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2954 ( uuid_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2955 ( uuid_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2956 ( uuid_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2957 ( uuid_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2958 ( uuid_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2959 ( uuid_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2960 ( uuid_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2950 2950" _null_ _null_ _null_ _null_ uuid_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2961 ( uuid_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2950 "2281" _null_ _null_ _null_ _null_ uuid_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2962 ( uuid_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2950" _null_ _null_ _null_ _null_ uuid_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2963 ( uuid_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2950" _null_ _null_ _null_ _null_ uuid_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); + +/* enum related procs */ +DATA(insert OID = 3504 ( anyenum_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3500 "2275" _null_ _null_ _null_ _null_ anyenum_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3505 ( anyenum_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3500" _null_ _null_ _null_ _null_ anyenum_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3506 ( enum_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 3500 "2275 26" _null_ _null_ _null_ _null_ enum_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3507 ( enum_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3500" _null_ _null_ _null_ _null_ enum_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3508 ( enum_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3509 ( enum_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3510 ( enum_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3511 ( enum_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3512 ( enum_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3513 ( enum_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3514 ( enum_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3500 3500" _null_ _null_ _null_ _null_ enum_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3515 ( hashenum PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3500" _null_ _null_ _null_ _null_ hashenum _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 3524 ( enum_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3500 "3500 3500" _null_ _null_ _null_ _null_ enum_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 3525 ( enum_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3500 "3500 3500" _null_ _null_ _null_ _null_ enum_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 3526 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 3500 "3500" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all enum input values"); +DATA(insert OID = 3527 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 3500 "3500" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all enum input values"); +DATA(insert OID = 3528 ( enum_first PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 3500 "3500" _null_ _null_ _null_ _null_ enum_first _null_ _null_ _null_ "" f)); +DESCR("first value of the input enum type"); +DATA(insert OID = 3529 ( enum_last PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 3500 "3500" _null_ _null_ _null_ _null_ enum_last _null_ _null_ _null_ "" f)); +DESCR("last value of the input enum type"); +DATA(insert OID = 3530 ( enum_range PGNSP PGUID 12 1 0 0 0 f f f f f f s 2 0 2277 "3500 3500" _null_ _null_ _null_ _null_ enum_range_bounds _null_ _null_ _null_ "" f)); +DESCR("range between the two given enum values, as an ordered array"); +DATA(insert OID = 3531 ( enum_range PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 2277 "3500" _null_ _null_ _null_ _null_ enum_range_all _null_ _null_ _null_ "" f)); +DESCR("range of the given enum type, as an ordered array"); +DATA(insert OID = 3532 ( enum_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 3500 "2275 26" _null_ _null_ _null_ _null_ enum_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3533 ( enum_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3500" _null_ _null_ _null_ _null_ enum_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* text search stuff */ +DATA(insert OID = 3610 ( tsvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "2275" _null_ _null_ _null_ _null_ tsvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3639 ( tsvectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "2281" _null_ _null_ _null_ _null_ tsvectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3611 ( tsvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3614" _null_ _null_ _null_ _null_ tsvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3638 ( tsvectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3614" _null_ _null_ _null_ _null_ tsvectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3612 ( tsqueryin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "2275" _null_ _null_ _null_ _null_ tsqueryin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3641 ( tsqueryrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "2281" _null_ _null_ _null_ _null_ tsqueryrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3613 ( tsqueryout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3615" _null_ _null_ _null_ _null_ tsqueryout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3640 ( tsquerysend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3615" _null_ _null_ _null_ _null_ tsquerysend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3646 ( gtsvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3642 "2275" _null_ _null_ _null_ _null_ gtsvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3647 ( gtsvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3642" _null_ _null_ _null_ _null_ gtsvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3616 ( tsvector_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3617 ( tsvector_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3618 ( tsvector_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3619 ( tsvector_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3620 ( tsvector_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3621 ( tsvector_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3622 ( tsvector_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3614 3614" _null_ _null_ _null_ _null_ tsvector_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 3711 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3614" _null_ _null_ _null_ _null_ tsvector_length _null_ _null_ _null_ "" f)); +DESCR("number of lexemes"); +DATA(insert OID = 3623 ( strip PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "3614" _null_ _null_ _null_ _null_ tsvector_strip _null_ _null_ _null_ "" f)); +DESCR("strip position information"); +DATA(insert OID = 3624 ( setweight PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3614 18" _null_ _null_ _null_ _null_ tsvector_setweight _null_ _null_ _null_ "" f)); +DESCR("set weight of lexeme's entries"); +DATA(insert OID = 3625 ( tsvector_concat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3614 3614" _null_ _null_ _null_ _null_ tsvector_concat _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3634 ( ts_match_vq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3615" _null_ _null_ _null_ _null_ ts_match_vq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3635 ( ts_match_qv PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3614" _null_ _null_ _null_ _null_ ts_match_qv _null_ _null_ _null_ "" f)); +DATA(insert OID = 3760 ( ts_match_tt PGNSP PGUID 12 3 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ ts_match_tt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3761 ( ts_match_tq PGNSP PGUID 12 2 0 0 0 f f f f t f s 2 0 16 "25 3615" _null_ _null_ _null_ _null_ ts_match_tq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3648 ( gtsvector_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsvector_compress _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3649 ( gtsvector_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsvector_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3650 ( gtsvector_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsvector_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3651 ( gtsvector_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsvector_union _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3652 ( gtsvector_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3642 3642 2281" _null_ _null_ _null_ _null_ gtsvector_same _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3653 ( gtsvector_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gtsvector_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3654 ( gtsvector_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 3642 23 26 2281" _null_ _null_ _null_ _null_ gtsvector_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); + +DATA(insert OID = 3656 ( gin_extract_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3614 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsvector _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3657 ( gin_extract_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "3615 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3658 ( gin_tsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 3615 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_consistent _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3921 ( gin_tsquery_triconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 16 "2281 21 3615 23 2281 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_triconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3724 ( gin_cmp_tslexeme PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ gin_cmp_tslexeme _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 2700 ( gin_cmp_prefix PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "25 25 21 2281" _null_ _null_ _null_ _null_ gin_cmp_prefix _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3077 ( gin_extract_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "3614 2281" _null_ _null_ _null_ _null_ gin_extract_tsvector_2args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); +DATA(insert OID = 3087 ( gin_extract_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 2281 "3615 2281 21 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery_5args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); +DATA(insert OID = 3088 ( gin_tsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 6 0 16 "2281 21 3615 23 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_consistent_6args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); + +DATA(insert OID = 3989 ( gin_clean_pending_list PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ gin_clean_pending_list _null_ _null_ _null_ "" f)); +DESCR("clean up GIN pending list"); + +DATA(insert OID = 3662 ( tsquery_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3663 ( tsquery_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3664 ( tsquery_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3665 ( tsquery_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3666 ( tsquery_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3667 ( tsquery_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3668 ( tsquery_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3615 3615" _null_ _null_ _null_ _null_ tsquery_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 3669 ( tsquery_and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3615 3615" _null_ _null_ _null_ _null_ tsquery_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 3670 ( tsquery_or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3615 3615" _null_ _null_ _null_ _null_ tsquery_or _null_ _null_ _null_ "" f)); +DATA(insert OID = 3671 ( tsquery_not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "3615" _null_ _null_ _null_ _null_ tsquery_not _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3691 ( tsq_mcontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsq_mcontains _null_ _null_ _null_ "" f)); +DATA(insert OID = 3692 ( tsq_mcontained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsq_mcontained _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3672 ( numnode PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3615" _null_ _null_ _null_ _null_ tsquery_numnode _null_ _null_ _null_ "" f)); +DESCR("number of nodes"); +DATA(insert OID = 3673 ( querytree PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3615" _null_ _null_ _null_ _null_ tsquerytree _null_ _null_ _null_ "" f)); +DESCR("show real useful query for GiST index"); + +DATA(insert OID = 3684 ( ts_rewrite PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 3615 "3615 3615 3615" _null_ _null_ _null_ _null_ tsquery_rewrite _null_ _null_ _null_ "" f)); +DESCR("rewrite tsquery"); +DATA(insert OID = 3685 ( ts_rewrite PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 3615 "3615 25" _null_ _null_ _null_ _null_ tsquery_rewrite_query _null_ _null_ _null_ "" f)); +DESCR("rewrite tsquery"); + +DATA(insert OID = 3695 ( gtsquery_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsquery_compress _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3696 ( gtsquery_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsquery_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3697 ( gtsquery_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsquery_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3698 ( gtsquery_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsquery_union _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3699 ( gtsquery_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "20 20 2281" _null_ _null_ _null_ _null_ gtsquery_same _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3700 ( gtsquery_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gtsquery_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3701 ( gtsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 2281 23 26 2281" _null_ _null_ _null_ _null_ gtsquery_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); + +DATA(insert OID = 3686 ( tsmatchsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ tsmatchsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of tsvector @@ tsquery"); +DATA(insert OID = 3687 ( tsmatchjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ tsmatchjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of tsvector @@ tsquery"); +DATA(insert OID = 3688 ( ts_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ ts_typanalyze _null_ _null_ _null_ "" f)); +DESCR("tsvector typanalyze"); + +DATA(insert OID = 3689 ( ts_stat PGNSP PGUID 12 10 10000 0 0 f f f f t t v 1 0 2249 "25" "{25,25,23,23}" "{i,o,o,o}" "{query,word,ndoc,nentry}" _null_ ts_stat1 _null_ _null_ _null_ "" f)); +DESCR("statistics of tsvector column"); +DATA(insert OID = 3690 ( ts_stat PGNSP PGUID 12 10 10000 0 0 f f f f t t v 2 0 2249 "25 25" "{25,25,25,23,23}" "{i,i,o,o,o}" "{query,weights,word,ndoc,nentry}" _null_ ts_stat2 _null_ _null_ _null_ "" f)); +DESCR("statistics of tsvector column"); + +DATA(insert OID = 3703 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 700 "1021 3614 3615 23" _null_ _null_ _null_ _null_ ts_rank_wttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3704 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "1021 3614 3615" _null_ _null_ _null_ _null_ ts_rank_wtt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3705 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "3614 3615 23" _null_ _null_ _null_ _null_ ts_rank_ttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3706 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "3614 3615" _null_ _null_ _null_ _null_ ts_rank_tt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3707 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 700 "1021 3614 3615 23" _null_ _null_ _null_ _null_ ts_rankcd_wttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3708 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "1021 3614 3615" _null_ _null_ _null_ _null_ ts_rankcd_wtt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3709 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "3614 3615 23" _null_ _null_ _null_ _null_ ts_rankcd_ttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3710 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "3614 3615" _null_ _null_ _null_ _null_ ts_rankcd_tt _null_ _null_ _null_ "" f)); +DESCR("relevance"); + +DATA(insert OID = 3713 ( ts_token_type PGNSP PGUID 12 1 16 0 0 f f f f t t i 1 0 2249 "26" "{26,23,25,25}" "{i,o,o,o}" "{parser_oid,tokid,alias,description}" _null_ ts_token_type_byid _null_ _null_ _null_ "" f)); +DESCR("get parser's token types"); +DATA(insert OID = 3714 ( ts_token_type PGNSP PGUID 12 1 16 0 0 f f f f t t s 1 0 2249 "25" "{25,23,25,25}" "{i,o,o,o}" "{parser_name,tokid,alias,description}" _null_ ts_token_type_byname _null_ _null_ _null_ "" f)); +DESCR("get parser's token types"); +DATA(insert OID = 3715 ( ts_parse PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 2249 "26 25" "{26,25,23,25}" "{i,i,o,o}" "{parser_oid,txt,tokid,token}" _null_ ts_parse_byid _null_ _null_ _null_ "" f)); +DESCR("parse text to tokens"); +DATA(insert OID = 3716 ( ts_parse PGNSP PGUID 12 1 1000 0 0 f f f f t t s 2 0 2249 "25 25" "{25,25,23,25}" "{i,i,o,o}" "{parser_name,txt,tokid,token}" _null_ ts_parse_byname _null_ _null_ _null_ "" f)); +DESCR("parse text to tokens"); + +DATA(insert OID = 3717 ( prsd_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ prsd_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3718 ( prsd_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ prsd_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3719 ( prsd_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ prsd_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3720 ( prsd_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 3615" _null_ _null_ _null_ _null_ prsd_headline _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3721 ( prsd_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ prsd_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3723 ( ts_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1009 "3769 25" _null_ _null_ _null_ _null_ ts_lexize _null_ _null_ _null_ "" f)); +DESCR("normalize one word by dictionary"); + +DATA(insert OID = 3725 ( dsimple_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dsimple_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3726 ( dsimple_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dsimple_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3728 ( dsynonym_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dsynonym_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3729 ( dsynonym_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dsynonym_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3731 ( dispell_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dispell_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3732 ( dispell_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dispell_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3740 ( thesaurus_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ thesaurus_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3741 ( thesaurus_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ thesaurus_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3743 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 25 "3734 25 3615 25" _null_ _null_ _null_ _null_ ts_headline_byid_opt _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3744 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "3734 25 3615" _null_ _null_ _null_ _null_ ts_headline_byid _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3754 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "25 3615 25" _null_ _null_ _null_ _null_ ts_headline_opt _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3755 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 3615" _null_ _null_ _null_ _null_ ts_headline _null_ _null_ _null_ "" f)); +DESCR("generate headline"); + +DATA(insert OID = 3745 ( to_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3734 25" _null_ _null_ _null_ _null_ to_tsvector_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3746 ( to_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3734 25" _null_ _null_ _null_ _null_ to_tsquery_byid _null_ _null_ _null_ "" f)); +DESCR("make tsquery"); +DATA(insert OID = 3747 ( plainto_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3734 25" _null_ _null_ _null_ _null_ plainto_tsquery_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsquery"); +DATA(insert OID = 3749 ( to_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "25" _null_ _null_ _null_ _null_ to_tsvector _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3750 ( to_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "25" _null_ _null_ _null_ _null_ to_tsquery _null_ _null_ _null_ "" f)); +DESCR("make tsquery"); +DATA(insert OID = 3751 ( plainto_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3615 "25" _null_ _null_ _null_ _null_ plainto_tsquery _null_ _null_ _null_ "" f)); +DESCR("transform to tsquery"); + +DATA(insert OID = 3752 ( tsvector_update_trigger PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2279 "" _null_ _null_ _null_ _null_ tsvector_update_trigger_byid _null_ _null_ _null_ "" f)); +DESCR("trigger for automatic update of tsvector column"); +DATA(insert OID = 3753 ( tsvector_update_trigger_column PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2279 "" _null_ _null_ _null_ _null_ tsvector_update_trigger_bycolumn _null_ _null_ _null_ "" f)); +DESCR("trigger for automatic update of tsvector column"); + +DATA(insert OID = 3759 ( get_current_ts_config PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 3734 "" _null_ _null_ _null_ _null_ get_current_ts_config _null_ _null_ _null_ "" f)); +DESCR("get current tsearch configuration"); + +DATA(insert OID = 3736 ( regconfigin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3734 "2275" _null_ _null_ _null_ _null_ regconfigin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3737 ( regconfigout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3734" _null_ _null_ _null_ _null_ regconfigout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3738 ( regconfigrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3734 "2281" _null_ _null_ _null_ _null_ regconfigrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3739 ( regconfigsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3734" _null_ _null_ _null_ _null_ regconfigsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3771 ( regdictionaryin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3769 "2275" _null_ _null_ _null_ _null_ regdictionaryin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3772 ( regdictionaryout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3769" _null_ _null_ _null_ _null_ regdictionaryout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3773 ( regdictionaryrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3769 "2281" _null_ _null_ _null_ _null_ regdictionaryrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3774 ( regdictionarysend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3769" _null_ _null_ _null_ _null_ regdictionarysend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* replication slots */ +DATA(insert OID = 3779 ( pg_create_physical_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2249 "19 16" "{19,16,25,25}" "{i,i,o,o}" "{slotname,dummy_standby,slotname,xlog_position}" _null_ pg_create_physical_replication_slot _null_ _null_ _null_ ""f)); +DESCR("create a physical replication slot"); +DATA(insert OID = 3783 ( pg_drop_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "19" _null_ _null_ _null_ _null_ pg_drop_replication_slot _null_ _null_ _null_ ""f)); +DESCR("drop a replication slot"); +DATA(insert OID = 3784 ( pg_get_replication_slots PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{25,25,26,16,28,25,16}" "{o,o,o,o,o,o,o}" "{slot_name,slot_type,datoid,active,xmin,restart_lsn,dummy_standby}" _null_ pg_get_replication_slots _null_ _null_ _null_ ""f)); +DESCR("information about replication slots currently in use"); + +/* Parser function for ngram */ +DATA(insert OID = 3786 ( ngram_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ ngram_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3787 ( ngram_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ngram_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3788 ( ngram_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ ngram_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3789 ( ngram_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ ngram_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3792 ( zhprs_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ zhprs_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3793 ( zhprs_getlexeme PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ zhprs_getlexeme _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3794 ( zhprs_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ zhprs_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3795 ( zhprs_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ zhprs_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +/* Parser function for pound */ +DATA(insert OID = 3798 ( pound_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ pound_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3799 ( pound_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ pound_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3800 ( pound_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ pound_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3801 ( pound_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ pound_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + + +/* txid */ +DATA(insert OID = 2939 ( txid_snapshot_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2970 "2275" _null_ _null_ _null_ _null_ txid_snapshot_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2940 ( txid_snapshot_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2970" _null_ _null_ _null_ _null_ txid_snapshot_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2941 ( txid_snapshot_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2970 "2281" _null_ _null_ _null_ _null_ txid_snapshot_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2942 ( txid_snapshot_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2970" _null_ _null_ _null_ _null_ txid_snapshot_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2943 ( txid_current PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ txid_current _null_ _null_ _null_ "" f)); +DESCR("get current transaction ID"); +DATA(insert OID = 2944 ( txid_current_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 2970 "" _null_ _null_ _null_ _null_ txid_current_snapshot _null_ _null_ _null_ "" f)); +DESCR("get current snapshot"); +DATA(insert OID = 2945 ( txid_snapshot_xmin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xmin _null_ _null_ _null_ "" f)); +DESCR("get xmin of snapshot"); +DATA(insert OID = 2946 ( txid_snapshot_xmax PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xmax _null_ _null_ _null_ "" f)); +DESCR("get xmax of snapshot"); +DATA(insert OID = 2947 ( txid_snapshot_xip PGNSP PGUID 12 1 50 0 0 f f f f t t i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xip _null_ _null_ _null_ "" f)); +DESCR("get set of in-progress txids in snapshot"); +DATA(insert OID = 2948 ( txid_visible_in_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "20 2970" _null_ _null_ _null_ _null_ txid_visible_in_snapshot _null_ _null_ _null_ "" f)); +DESCR("is txid visible in snapshot?"); +DATA(insert OID = 2949 ( pgxc_snapshot_status PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 2249 "" "{28,28,23,28,28,23,23,23,23,20}" "{o,o,o,o,o,o,o,o,o,o}" "{xmin,xmax,xcnt,oldestxmin,next_xid,timeline,active_thread_num,max_active_thread_num,snapshot_num,snapshot_totalsize}" _null_ pgxc_snapshot_status _null_ _null_ _null_ "" f)); +DESCR("get gtm snapshot status information"); + +/* record comparison */ +DATA(insert OID = 2981 ( record_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2982 ( record_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2983 ( record_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2984 ( record_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2985 ( record_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2986 ( record_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2987 ( btrecordcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2249 2249" _null_ _null_ _null_ _null_ btrecordcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +/* Extensions */ +DATA(insert OID = 3082 ( pg_available_extensions PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{19,25,25}" "{o,o,o}" "{name,default_version,comment}" _null_ pg_available_extensions _null_ _null_ _null_ "" f)); +DESCR("list available extensions"); +DATA(insert OID = 3083 ( pg_available_extension_versions PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{19,25,16,16,19,1003,25}" "{o,o,o,o,o,o,o}" "{name,version,superuser,relocatable,schema,requires,comment}" _null_ pg_available_extension_versions _null_ _null_ _null_ "" f)); +DESCR("list available extension versions"); +DATA(insert OID = 3084 ( pg_extension_update_paths PGNSP PGUID 12 10 100 0 0 f f f f t t s 1 0 2249 "19" "{19,25,25,25}" "{i,o,o,o}" "{name,source,target,path}" _null_ pg_extension_update_paths _null_ _null_ _null_ "" f)); +DESCR("list an extension's version update paths"); +DATA(insert OID = 3086 ( pg_extension_config_dump PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "2205 25" _null_ _null_ _null_ _null_ pg_extension_config_dump _null_ _null_ _null_ "" f)); +DESCR("flag an extension's table contents to be emitted by gs_dump"); + +/* SQL-spec window functions */ +DATA(insert OID = 3100 ( row_number PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_row_number _null_ _null_ _null_ "" f)); +DESCR("row number within partition"); +#define ROWNUMBERFUNCOID 3100 +DATA(insert OID = 3101 ( rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_rank _null_ _null_ _null_ "" f)); +DESCR("integer rank with gaps"); +#define RANKFUNCOID 3101 +DATA(insert OID = 3102 ( dense_rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_dense_rank _null_ _null_ _null_ "" f)); +DESCR("integer rank without gaps"); +#define DENSERANKFUNCOID 3102 +DATA(insert OID = 3103 ( percent_rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 701 "" _null_ _null_ _null_ _null_ window_percent_rank _null_ _null_ _null_ "" f)); +DESCR("fractional rank within partition"); +DATA(insert OID = 3104 ( cume_dist PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 701 "" _null_ _null_ _null_ _null_ window_cume_dist _null_ _null_ _null_ "" f)); +DESCR("fractional row number within partition"); +DATA(insert OID = 3105 ( ntile PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ window_ntile _null_ _null_ _null_ "" f)); +DESCR("split rows into N groups"); +DATA(insert OID = 3106 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_lag _null_ _null_ _null_ "" f)); +DESCR("fetch the preceding row value"); +DATA(insert OID = 3107 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_lag_with_offset _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth preceding row value"); +DATA(insert OID = 3108 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 3 0 2283 "2283 23 2283" _null_ _null_ _null_ _null_ window_lag_with_offset_and_default _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth preceding row value with default"); +DATA(insert OID = 3109 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_lead _null_ _null_ _null_ "" f)); +DESCR("fetch the following row value"); +DATA(insert OID = 3110 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_lead_with_offset _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth following row value"); +DATA(insert OID = 3111 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 3 0 2283 "2283 23 2283" _null_ _null_ _null_ _null_ window_lead_with_offset_and_default _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth following row value with default"); +DATA(insert OID = 3112 ( first_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_first_value _null_ _null_ _null_ "" f)); +DESCR("fetch the first row value"); +DATA(insert OID = 3113 ( last_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_last_value _null_ _null_ _null_ "" f)); +DESCR("fetch the last row value"); +DATA(insert OID = 3114 ( nth_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_nth_value _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth row value"); +DATA(insert OID = 3167 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos - _null_ _null_ "" f)); +DESCR("find position of substringi with two args"); +#define INSTR2FUNCOID 3167 +DATA(insert OID = 3168 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 23 "25 25 23" _null_ _null_ _null_ _null_ instr_3args - _null_ _null_"" f)); +DESCR("find position of substring with three args"); +#define INSTR3FUNCOID 3168 +DATA(insert OID = 3169 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "25 25 23 23" _null_ _null_ _null_ _null_ instr_4args - _null_ _null_"" f)); +DESCR("find position of substring with four args"); +#define INSTR4FUNCOID 3169 +DATA(insert OID = 3170 ( multiply PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 701" _null_ _null_ _null_ _null_ text_multiply_float8 _null_ _null_ _null_"" f)); +DATA(insert OID = 3171 ( multiply PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 25" _null_ _null_ _null_ _null_ float8_multiply_text _null_ _null_ _null_"" f)); +DATA(insert OID = 3172 ( numtodsinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1700 25" _null_ _null_ _null_ _null_ numtodsinterval - _null_ _null_ "" f)); +DESCR("convert numeric to interval"); +DATA(insert OID = 3842 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1700" _null_ _null_ _null_ _null_ numeric_interval - _null_ _null_ "" f)); +DESCR("convert numeric to interval"); +DATA(insert OID = 3189 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "5545" _null_ _null_ _null_ _null_ int1_interval - _null_ _null_ "" f)); +DESCR("convert int1 to interval"); +DATA(insert OID = 3190 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "21" _null_ _null_ _null_ _null_ int2_interval - _null_ _null_ "" f)); +DESCR("convert int2 to interval"); +DATA(insert OID = 3191 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "23" _null_ _null_ _null_ _null_ int4_interval - _null_ _null_ "" f)); +DESCR("convert int4 to interval"); +/* functions for range types */ +DATA(insert OID = 3832 ( anyrange_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2275 26 23" _null_ _null_ _null_ _null_ anyrange_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3833 ( anyrange_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3831" _null_ _null_ _null_ _null_ anyrange_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3834 ( range_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2275 26 23" _null_ _null_ _null_ _null_ range_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3835 ( range_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3831" _null_ _null_ _null_ _null_ range_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3836 ( range_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2281 26 23" _null_ _null_ _null_ _null_ range_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3837 ( range_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3831" _null_ _null_ _null_ _null_ range_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3848 ( lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "3831" _null_ _null_ _null_ _null_ range_lower _null_ _null_ _null_ "" f)); +DESCR("lower bound of range"); +DATA(insert OID = 3849 ( upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "3831" _null_ _null_ _null_ _null_ range_upper _null_ _null_ _null_ "" f)); +DESCR("upper bound of range"); +DATA(insert OID = 3850 ( isempty PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_empty _null_ _null_ _null_ "" f)); +DESCR("is the range empty?"); +DATA(insert OID = 3851 ( lower_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_lower_inc _null_ _null_ _null_ "" f)); +DESCR("is the range's lower bound inclusive?"); +DATA(insert OID = 3852 ( upper_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_upper_inc _null_ _null_ _null_ "" f)); +DESCR("is the range's upper bound inclusive?"); +DATA(insert OID = 3853 ( lower_inf PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_lower_inf _null_ _null_ _null_ "" f)); +DESCR("is the range's lower bound infinite?"); +DATA(insert OID = 3854 ( upper_inf PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_upper_inf _null_ _null_ _null_ "" f)); +DESCR("is the range's upper bound infinite?"); +DATA(insert OID = 3855 ( range_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_eq _null_ _null_ _null_ "" f)); +DESCR("implementation of = operator"); +DATA(insert OID = 3856 ( range_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_ne _null_ _null_ _null_ "" f)); +DESCR("implementation of <> operator"); +DATA(insert OID = 3857 ( range_overlaps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overlaps _null_ _null_ _null_ "" f)); +DESCR("implementation of && operator"); +DATA(insert OID = 3858 ( range_contains_elem PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 2283" _null_ _null_ _null_ _null_ range_contains_elem _null_ _null_ _null_ "" f)); +DESCR("implementation of @> operator"); +DATA(insert OID = 3859 ( range_contains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_contains _null_ _null_ _null_ "" f)); +DESCR("implementation of @> operator"); +DATA(insert OID = 3860 ( elem_contained_by_range PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2283 3831" _null_ _null_ _null_ _null_ elem_contained_by_range _null_ _null_ _null_ "" f)); +DESCR("implementation of <@ operator"); +DATA(insert OID = 3861 ( range_contained_by PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_contained_by _null_ _null_ _null_ "" f)); +DESCR("implementation of <@ operator"); +DATA(insert OID = 3862 ( range_adjacent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_adjacent _null_ _null_ _null_ "" f)); +DESCR("implementation of -|- operator"); +DATA(insert OID = 3863 ( range_before PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_before _null_ _null_ _null_ "" f)); +DESCR("implementation of << operator"); +DATA(insert OID = 3864 ( range_after PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_after _null_ _null_ _null_ "" f)); +DESCR("implementation of >> operator"); +DATA(insert OID = 3865 ( range_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overleft _null_ _null_ _null_ "" f)); +DESCR("implementation of &< operator"); +DATA(insert OID = 3866 ( range_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overright _null_ _null_ _null_ "" f)); +DESCR("implementation of &> operator"); +DATA(insert OID = 3867 ( range_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_union _null_ _null_ _null_ "" f)); +DESCR("implementation of + operator"); +DATA(insert OID = 3868 ( range_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_intersect _null_ _null_ _null_ "" f)); +DESCR("implementation of * operator"); +DATA(insert OID = 3869 ( range_minus PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_minus _null_ _null_ _null_ "" f)); +DESCR("implementation of - operator"); +DATA(insert OID = 3870 ( range_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3831 3831" _null_ _null_ _null_ _null_ range_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3871 ( range_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3872 ( range_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3873 ( range_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3874 ( range_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3875 ( range_gist_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 3831 23 26 2281" _null_ _null_ _null_ _null_ range_gist_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3876 ( range_gist_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ range_gist_union _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3877 ( range_gist_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ range_gist_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3878 ( range_gist_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ range_gist_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3879 ( range_gist_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ range_gist_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3880 ( range_gist_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ range_gist_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3881 ( range_gist_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3831 3831 2281" _null_ _null_ _null_ _null_ range_gist_same _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3902 ( hash_range PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3831" _null_ _null_ _null_ _null_ hash_range _null_ _null_ _null_ "" f)); +DESCR("hash a range"); +DATA(insert OID = 3916 ( range_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ range_typanalyze _null_ _null_ _null_ "" f)); +DESCR("range typanalyze"); + +DATA(insert OID = 3914 ( int4range_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3904 "3904" _null_ _null_ _null_ _null_ int4range_canonical _null_ _null_ _null_ "" f)); +DESCR("convert an int4 range to canonical form"); +DATA(insert OID = 3928 ( int8range_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3926 "3926" _null_ _null_ _null_ _null_ int8range_canonical _null_ _null_ _null_ "" f)); +DESCR("convert an int8 range to canonical form"); +DATA(insert OID = 3915 ( daterange_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3912 "3912" _null_ _null_ _null_ _null_ daterange_canonical _null_ _null_ _null_ "" f)); +DESCR("convert a date range to canonical form"); +DATA(insert OID = 3922 ( int4range_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 23" _null_ _null_ _null_ _null_ int4range_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two int4 values"); +DATA(insert OID = 3923 ( int8range_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 20" _null_ _null_ _null_ _null_ int8range_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two int8 values"); +DATA(insert OID = 3924 ( numrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1700 1700" _null_ _null_ _null_ _null_ numrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two numeric values"); +DATA(insert OID = 3925 ( daterange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1082 1082" _null_ _null_ _null_ _null_ daterange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two date values"); +DATA(insert OID = 3929 ( tsrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1114 1114" _null_ _null_ _null_ _null_ tsrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two timestamp values"); +DATA(insert OID = 3930 ( tstzrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1184 1184" _null_ _null_ _null_ _null_ tstzrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two timestamp with time zone values"); + +DATA(insert OID = 3840 ( int4range PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3904 "23 23" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("int4range constructor"); +DATA(insert OID = 3841 ( int4range PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3904 "23 23 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("int4range constructor"); +DATA(insert OID = 3844 ( numrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3906 "1700 1700" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("numrange constructor"); +DATA(insert OID = 3845 ( numrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3906 "1700 1700 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("numrange constructor"); +DATA(insert OID = 3933 ( tsrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3908 "1114 1114" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("tsrange constructor"); +DATA(insert OID = 3934 ( tsrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3908 "1114 1114 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("tsrange constructor"); +DATA(insert OID = 3937 ( tstzrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3910 "1184 1184" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("tstzrange constructor"); +DATA(insert OID = 3938 ( tstzrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3910 "1184 1184 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("tstzrange constructor"); +DATA(insert OID = 3941 ( daterange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3912 "1082 1082" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("daterange constructor"); +DATA(insert OID = 3942 ( daterange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3912 "1082 1082 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("daterange constructor"); +DATA(insert OID = 3945 ( int8range PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3926 "20 20" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("int8range constructor"); +DATA(insert OID = 3946 ( int8range PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3926 "20 20 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("int8range constructor"); + +/* spgist support functions */ +DATA(insert OID = 4001 ( spggettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spggettuple _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4002 ( spggetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ spggetbitmap _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4003 ( spginsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spginsert _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4004 ( spgbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ spgbeginscan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4005 ( spgrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgrescan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4006 ( spgendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgendscan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4007 ( spgmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgmarkpos _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4008 ( spgrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgrestrpos _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 3188 ( spgmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgmerge _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4009 ( spgbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ spgbuild _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4010 ( spgbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgbuildempty _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4011 ( spgbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgbulkdelete _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4012 ( spgvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ spgvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4032 ( spgcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ spgcanreturn _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4013 ( spgcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgcostestimate _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4014 ( spgoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ spgoptions _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); + +/* spgist opclasses */ +DATA(insert OID = 4018 ( spg_quad_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4019 ( spg_quad_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4020 ( spg_quad_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4021 ( spg_quad_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4022 ( spg_quad_leaf_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_leaf_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree and k-d tree over point"); + +DATA(insert OID = 4023 ( spg_kd_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4024 ( spg_kd_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4025 ( spg_kd_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4026 ( spg_kd_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); + +DATA(insert OID = 4027 ( spg_text_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4028 ( spg_text_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4029 ( spg_text_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4030 ( spg_text_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4031 ( spg_text_leaf_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spg_text_leaf_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); + +DATA(insert OID = 5580 ( smalldatetime_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_eq _null_ _null_ _null_ "" f)); +DESCR("equal"); +DATA(insert OID = 5581 ( smalldatetime_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_ne _null_ _null_ _null_ "" f)); +DESCR("not equal"); +DATA(insert OID = 5582 ( smalldatetime_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_lt _null_ _null_ _null_ "" f)); +DESCR("less than"); +DATA(insert OID = 5583 ( smalldatetime_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_le _null_ _null_ _null_ "" f)); +DESCR("less than or equal"); +DATA(insert OID = 5584 ( smalldatetime_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_ge _null_ _null_ _null_ "" f)); +DESCR("greater than or equal"); +DATA(insert OID = 5585 ( smalldatetime_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_gt _null_ _null_ _null_ "" f)); +DESCR("greater than"); +DATA(insert OID = 5586 ( smalldatetime_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_cmp _null_ _null_ _null_ "" f)); +DESCR("smalldatetime compare"); +DATA(insert OID = 5587 ( smalldatetime_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "9003" _null_ _null_ _null_ _null_ smalldatetime_hash _null_ _null_ _null_ "" f)); +DESCR("smalldatetime difference preserving months and years"); +DATA(insert OID = 9004 ( smalldatetime_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 9003 "2275 26 23" _null_ _null_ _null_ _null_ smalldatetime_in _null_ _null_ _null_ "" f)); +#define SMALLDATETIMEINFUNCOID 9004 +DESCR("I/O"); +DATA(insert OID = 9006 ( smalldatetime_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "9003" _null_ _null_ _null_ _null_ smalldatetime_out _null_ _null_ _null_ "" f)); +#define SMALLDATETIMEOUTFUNCOID 9006 +DESCR("I/O"); +DATA(insert OID = 9007 ( smalldatetime_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 9003 "2281 26 23" _null_ _null_ _null_ _null_ smalldatetime_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 9008 ( smalldatetime_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "9003" _null_ _null_ _null_ _null_ smalldatetime_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3198 ( convert_to_nocase PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "25 19" _null_ _null_ _null_ _null_ pg_convert_to_nocase _null_ _null_ _null_ "" f)); +DESCR("convert string with specified destination encoding name"); +DATA(insert OID = 5560 ( to_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "25" _null_ _null_ _null_ _null_ to_date_default_format _null_ _null_ _null_ "" f)); +#define TODATEDEFAULTFUNCOID 5560 +DESCR("to_date_default_format"); + +#ifdef PGXC +DATA(insert OID = 3200 ( pgxc_pool_check PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_check _null_ _null_ _null_ "" f)); +DESCR("check connection information consistency in pooler"); +DATA(insert OID = 3201 ( pgxc_pool_reload PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_reload _null_ _null_ _null_ "" f)); +DESCR("reload connection information in pooler and reload server sessions"); +DATA(insert OID = 3202 ( pgxc_node_str PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pgxc_node_str _null_ _null_ _null_ "" f)); +DESCR("get the name of the node"); +DATA(insert OID = 3203 ( pgxc_is_committed PGNSP PGUID 12 1 1 0 0 f f f f t t s 1 0 16 "28" _null_ _null_ _null_ _null_ pgxc_is_committed _null_ _null_ _null_ "" f)); +DESCR("is given GXID committed or aborted?"); +DATA(insert OID = 3204 ( pgxc_lock_for_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_lock_for_backup _null_ _null_ _null_ "" f)); +DESCR("lock the cluster for taking backup"); +DATA(insert OID = 3950 ( node_oid_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ node_oid_name _null_ _null_ _null_ ""f)); +DESCR("transfer node oid to node name"); +DATA(insert OID = 3952 ( tablespace_oid_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ tablespace_oid_name _null_ _null_ _null_ ""f)); +DESCR("transfer tablespace oid to tablespace name"); +DATA(insert OID = 3953 ( get_schema_oid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2275" _null_ _null_ _null_ _null_ get_schema_oid _null_ _null_ _null_ ""f)); +DESCR("transfer schema name to schema/namespace oid"); +DATA(insert OID = 3954 ( pgxc_pool_connection_status PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_connection_status _null_ _null_ _null_ "" f)); +DESCR("check if pooler connection is normal"); +DATA(insert OID = 3471 ( pg_pool_validate PGNSP PGUID 12 1 100 0 0 f f f f t t s 2 0 2249 "16 2275" "{16,2275,20,25}" "{i,i,o,o}" "{clear,co_node_name,pid,node_name}" _null_ pg_pool_validate _null_ _null_ _null_ "" f)); +DESCR("cancel the invalid connections to standby"); +DATA(insert OID = 3955 ( pg_stat_get_pooler_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,20,25,20,16}" "{o,o,o,o,o,o}" "{database_name,user_name,tid,pgoptions,node_oid,in_use}" _null_ pg_stat_get_pooler_status _null_ _null_ _null_ "" f)); +DESCR("check pooler connection status"); +DATA(insert OID = 3472 ( pg_pool_ping PGNSP PGUID 12 1 1 0 0 f f f f t t s 1 0 16 "16" _null_ _null_ _null_ _null_ pg_pool_ping _null_ _null_ _null_ "" f)); +DESCR("enable pooler ping"); +DATA(insert OID = 1982 ( comm_check_connection_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25, 25, 25, 23, 16}" "{o,o,o,o,o}" "{node_name,remote_name,remote_host,remote_port,is_connected}" _null_ comm_check_connection_status _null_ _null_ _null_ "" f)); +DESCR("check connections status"); +#endif + +/* used for bulkload */ +DATA(insert OID = 3208 ( to_tsvector_for_batch PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3734 25" _null_ _null_ _null_ _null_ to_tsvector_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3209 ( to_tsvector_for_batch PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "25" _null_ _null_ _null_ _null_ to_tsvector _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); + +/* used for aes encrypt/decrypt */ +DATA(insert OID = 3464 ( gs_encrypt_aes128 PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 25 "25 25" _null_ _null_ _null_ _null_ gs_encrypt_aes128 _null_ _null_ _null_ "" f)); +DESCR("internal encrypt"); +#define GSENCRYPTAES128FUNCOID 3464 +DATA(insert OID = 3465 ( gs_decrypt_aes128 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ gs_decrypt_aes128 _null_ _null_ _null_ "" f)); +DESCR("internal decrypt"); + +/* used for show password expired time and notice time user set. */ +DATA(insert OID = 3469 ( gs_password_deadline PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 1186 "" _null_ _null_ _null_ _null_ gs_password_deadline _null_ _null_ _null_ "" f)); +DESCR("password deadline"); +DATA(insert OID = 3470 ( gs_password_notifytime PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 23 "" _null_ _null_ _null_ _null_ gs_password_notifytime _null_ _null_ _null_ "" f)); +DESCR("password noticetime"); + +DATA(insert OID = 4000 ( gs_fault_inject PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 20 "20 25 25 25 25 25" _null_ _null_ _null_ _null_ gs_fault_inject _null_ _null_ _null_ "" f)); +DESCR("SQL function for fault injection"); + +/* psort index */ +DATA(insert OID = 4040 ( psortbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ psortbuild _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4041 ( psortoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ psortoptions _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4042 ( psortgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ psortgettuple _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4043 ( psortgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ psortgetbitmap _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4044 ( psortcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ psortcostestimate _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4045 ( psortcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ psortcanreturn _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); + +/* cbtree index */ +DATA(insert OID = 4240 ( cbtreebuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ cbtreebuild _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4241 ( cbtreeoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ cbtreeoptions _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4242 ( cbtreegettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ cbtreegettuple _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4243 ( cbtreecostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ cbtreecostestimate _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4245 ( cbtreecanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ cbtreecanreturn _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4246 ( cbtreegetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ cbtreegetbitmap _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); + + +/* cginbtree index */ +DATA(insert OID = 4400 ( cginbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ cginbuild _null_ _null_ _null_ "" f)); +DESCR("cgin(internal)"); +DATA(insert OID = 4401 ( cgingetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ cgingetbitmap _null_ _null_ _null_ "" f)); +DESCR("cgin(internal)"); + + + +/* used for data redistribution bucket functions OID from 4100 to 4129 */ +/* support type should match with IsTypeDistributable(Oid col_type) in locator.cpp */ +DATA(insert OID = 4100 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ bucketint4 _null_ _null_ _null_ "" f)); +DESCR("int4 value"); +DATA(insert OID = 4101 ( bucketint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ bucketint4 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int4 value"); +DATA(insert OID = 4102 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ bucketint2 _null_ _null_ _null_ "" f)); +DESCR("int2 value"); +DATA(insert OID = 4103 ( bucketint2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ bucketint2 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int2 value"); +DATA(insert OID = 4104 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ bucketint8 _null_ _null_ _null_ "" f)); +DESCR("int8 value"); +DATA(insert OID = 4105 ( bucketint8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ bucketint8 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int8 value"); +DATA(insert OID = 4106 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 23" _null_ _null_ _null_ _null_ bucketbpchar _null_ _null_ _null_ "" f)); +DESCR("bpchar value"); +DATA(insert OID = 4107 ( bucketbpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 23" _null_ _null_ _null_ _null_ bucketbpchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from bpchar value"); +DATA(insert OID = 4108 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 23" _null_ _null_ _null_ _null_ bucketchar _null_ _null_ _null_ "" f)); +DESCR("char value"); +DATA(insert OID = 4109 ( bucketchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 23" _null_ _null_ _null_ _null_ bucketchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from char value"); +DATA(insert OID = 4110 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1043 23" _null_ _null_ _null_ _null_ bucketvarchar _null_ _null_ _null_ "" f)); +DESCR("varchar value"); +DATA(insert OID = 4111 ( bucketvarchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1043 23" _null_ _null_ _null_ _null_ bucketvarchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from varchar value"); +DATA(insert OID = 4112 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 23" _null_ _null_ _null_ _null_ bucketdate _null_ _null_ _null_ "" f)); +DESCR("date value"); +DATA(insert OID = 4113 ( bucketdate PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 23" _null_ _null_ _null_ _null_ bucketdate _null_ _null_ _null_ "" f)); +DESCR("get bucket from date value"); +DATA(insert OID = 4114 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 23" _null_ _null_ _null_ _null_ buckettime _null_ _null_ _null_ "" f)); +DESCR("time value"); +DATA(insert OID = 4115 ( buckettime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 23" _null_ _null_ _null_ _null_ buckettime _null_ _null_ _null_ "" f)); +DESCR("get bucket from time value"); +DATA(insert OID = 4116 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 23" _null_ _null_ _null_ _null_ buckettimestamp _null_ _null_ _null_ "" f)); +DESCR("timestamp value"); +DATA(insert OID = 4117 ( buckettimestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 23" _null_ _null_ _null_ _null_ buckettimestamp _null_ _null_ _null_ "" f)); +DESCR("get bucket from timestamp value"); +DATA(insert OID = 4118 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 23" _null_ _null_ _null_ _null_ buckettimetz _null_ _null_ _null_ "" f)); +DESCR("date value"); +DATA(insert OID = 4119 ( buckettimetz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 23" _null_ _null_ _null_ _null_ buckettimetz _null_ _null_ _null_ "" f)); +DESCR("get bucket from date value"); +DATA(insert OID = 4120 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 23" _null_ _null_ _null_ _null_ bucketinterval _null_ _null_ _null_ "" f)); +DESCR("time value"); +DATA(insert OID = 4121 ( bucketinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 23" _null_ _null_ _null_ _null_ bucketinterval _null_ _null_ _null_ "" f)); +DESCR("get bucket from time value"); +DATA(insert OID = 4122 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 23" _null_ _null_ _null_ _null_ buckettimestamptz _null_ _null_ _null_ "" f)); +DESCR("timestamp value"); +DATA(insert OID = 4123 ( buckettimestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 23" _null_ _null_ _null_ _null_ buckettimestamptz _null_ _null_ _null_ "" f)); +DESCR("get bucket from timestamp value"); +DATA(insert OID = 4124 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 23" _null_ _null_ _null_ _null_ bucketint1 _null_ _null_ _null_ "" f)); +DESCR("int1 value"); +DATA(insert OID = 4125 ( bucketint1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 23" _null_ _null_ _null_ _null_ bucketint1 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int1 value"); +DATA(insert OID = 4126 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 23" _null_ _null_ _null_ _null_ bucketsmalldatetime _null_ _null_ _null_ "" f)); +DESCR("smalldatetime value"); +DATA(insert OID = 4127 ( bucketsmalldatetime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 23" _null_ _null_ _null_ _null_ bucketsmalldatetime _null_ _null_ _null_ "" f)); +DESCR("get bucket from smalldatetime value"); +DATA(insert OID = 4128 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3969 23" _null_ _null_ _null_ _null_ bucketnvarchar2 _null_ _null_ _null_ "" f)); +DESCR("varchar value"); +DATA(insert OID = 4129 ( bucketnvarchar2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3969 23" _null_ _null_ _null_ _null_ bucketnvarchar2 _null_ _null_ _null_ "" f)); +DESCR("get bucket from varchar value"); +DATA(insert OID = 4130 ( pg_buffercache_pages PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{23,26,26,26,21,20,16,21}" "{o,o,o,o,o,o,o,o}" "{bufferid,relfilenode,reltablespace,reldatabase,relforknumber,relblocknumber,isdirty,usage_count}" _null_ pg_buffercache_pages _null_ _null_ _null_ "" f)); +DESCR("statistics: information about shared buffer cache detail"); +DATA(insert OID = 4131 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 23" _null_ _null_ _null_ _null_ bucketnumeric _null_ _null_ _null_ "" f)); +DESCR("numeric value"); +DATA(insert OID = 4132 ( bucketnumeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 23" _null_ _null_ _null_ _null_ bucketnumeric _null_ _null_ _null_ "" f)); +DESCR("get bucket from numeric value"); +DATA(insert OID = 4133 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 23" _null_ _null_ _null_ _null_ bucketoid _null_ _null_ _null_ "" f)); +DESCR("oid value"); +DATA(insert OID = 4134 ( bucketoid PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 23" _null_ _null_ _null_ _null_ bucketoid _null_ _null_ _null_ "" f)); +DESCR("get bucket from oid value"); +DATA(insert OID = 4135 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 23" _null_ _null_ _null_ _null_ bucketabstime _null_ _null_ _null_ "" f)); +DESCR("abstime value"); +DATA(insert OID = 4136 ( bucketabstime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 23" _null_ _null_ _null_ _null_ bucketabstime _null_ _null_ _null_ "" f)); +DESCR("get bucket from abstime value"); +DATA(insert OID = 4137 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 23" _null_ _null_ _null_ _null_ bucketreltime _null_ _null_ _null_ "" f)); +DESCR("reltime value"); +DATA(insert OID = 4138 ( bucketreltime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 23" _null_ _null_ _null_ _null_ bucketreltime _null_ _null_ _null_ "" f)); +DESCR("get bucket from reltime value"); +DATA(insert OID = 4139 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 23" _null_ _null_ _null_ _null_ bucketcash _null_ _null_ _null_ "" f)); +DESCR("cash value"); +DATA(insert OID = 4140 ( bucketcash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 23" _null_ _null_ _null_ _null_ bucketcash _null_ _null_ _null_ "" f)); +DESCR("get bucket from cash value"); +DATA(insert OID = 4141 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ bucketbytea _null_ _null_ _null_ "" f)); +DESCR("bytea value"); +DATA(insert OID = 4142 ( bucketbytea PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ bucketbytea _null_ _null_ _null_ "" f)); +DESCR("get bucket from bytea value"); +DATA(insert OID = 4143 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 23" _null_ _null_ _null_ _null_ bucketraw _null_ _null_ _null_ "" f)); +DESCR("raw value"); +DATA(insert OID = 4144 ( bucketraw PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 23" _null_ _null_ _null_ _null_ bucketraw _null_ _null_ _null_ "" f)); +DESCR("get bucket from raw value"); +DATA(insert OID = 4145 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 23" _null_ _null_ _null_ _null_ bucketbool _null_ _null_ _null_ "" f)); +DESCR("bool value"); +DATA(insert OID = 4146 ( bucketbool PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 23" _null_ _null_ _null_ _null_ bucketbool _null_ _null_ _null_ "" f)); +DESCR("get bucket from bool value"); +DATA(insert OID = 4147 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 23" _null_ _null_ _null_ _null_ bucketname _null_ _null_ _null_ "" f)); +DESCR("name value"); +DATA(insert OID = 4148 ( bucketname PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 23" _null_ _null_ _null_ _null_ bucketname _null_ _null_ _null_ "" f)); +DESCR("get bucket from name value"); +DATA(insert OID = 4149 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "22 23" _null_ _null_ _null_ _null_ bucketint2vector _null_ _null_ _null_ "" f)); +DESCR("int2vector value"); +DATA(insert OID = 4150 ( bucketint2vector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "22 23" _null_ _null_ _null_ _null_ bucketint2vector _null_ _null_ _null_ "" f)); +DESCR("get bucket from int2vector value"); +DATA(insert OID = 4151 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 23" _null_ _null_ _null_ _null_ buckettext _null_ _null_ _null_ "" f)); +DESCR("text value"); +DATA(insert OID = 4152 ( buckettext PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 23" _null_ _null_ _null_ _null_ buckettext _null_ _null_ _null_ "" f)); +DESCR("get bucket from text value"); +DATA(insert OID = 4153 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 23" _null_ _null_ _null_ _null_ bucketoidvector _null_ _null_ _null_ "" f)); +DESCR("oidvector value"); +DATA(insert OID = 4154 ( bucketoidvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 23" _null_ _null_ _null_ _null_ bucketoidvector _null_ _null_ _null_ "" f)); +DESCR("get bucket from oidvector value"); +DATA(insert OID = 4155 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 23" _null_ _null_ _null_ _null_ bucketfloat4 _null_ _null_ _null_ "" f)); +DESCR("float4 value"); +DATA(insert OID = 4156 ( bucketfloat4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 23" _null_ _null_ _null_ _null_ bucketfloat4 _null_ _null_ _null_ "" f)); +DESCR("get bucket from float4 value"); +DATA(insert OID = 4157 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 23" _null_ _null_ _null_ _null_ bucketfloat8 _null_ _null_ _null_ "" f)); +DESCR("float8 value"); +DATA(insert OID = 4158 ( bucketfloat8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 23" _null_ _null_ _null_ _null_ bucketfloat8 _null_ _null_ _null_ "" f)); +DESCR("get bucket from float8 value"); + +DATA(insert OID = 4159 ( date_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1082" _null_ _null_ _null_ _null_ date_text _null_ _null_ _null_ "" f)); +DESCR("convert date to text"); +DATA(insert OID = 4160 ( date_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "1082" _null_ _null_ _null_ _null_ date_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert date to bpchar"); +DATA(insert OID = 4161 ( date_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1082" _null_ _null_ _null_ _null_ date_varchar _null_ _null_ _null_ "" f)); +DESCR("convert date to varchar"); +DATA(insert OID = 4162 ( varchar_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1043" _null_ _null_ _null_ _null_ varchar_date _null_ _null_ _null_ "" f)); +DESCR("convert varchar to date"); +DATA(insert OID = 4163 ( bpchar_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1042" _null_ _null_ _null_ _null_ bpchar_date _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to date"); +DATA(insert OID = 4164 ( text_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "25" _null_ _null_ _null_ _null_ text_date _null_ _null_ _null_ "" f)); +DESCR("convert text to date"); + +DATA(insert OID = 4165 ( int1_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "5545" _null_ _null_ _null_ _null_ int1_text _null_ _null_ _null_ "" f)); +DESCR("convert int1 to text"); +DATA(insert OID = 4166 ( int2_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "21" _null_ _null_ _null_ _null_ int2_text _null_ _null_ _null_ "" f)); +DESCR("convert int2 to text"); +DATA(insert OID = 4167 ( int4_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "23" _null_ _null_ _null_ _null_ int4_text _null_ _null_ _null_ "" f)); +DESCR("convert int4 to text"); +DATA(insert OID = 4168 ( int8_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "20" _null_ _null_ _null_ _null_ int8_text _null_ _null_ _null_ "" f)); +DESCR("convert int8 to text"); +DATA(insert OID = 4169 ( float4_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "700" _null_ _null_ _null_ _null_ float4_text _null_ _null_ _null_ "" f)); +DESCR("convert float4 to text"); +DATA(insert OID = 4170 ( float8_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "701" _null_ _null_ _null_ _null_ float8_text _null_ _null_ _null_ "" f)); +DESCR("convert float8 to text"); +DATA(insert OID = 4171 ( numeric_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1700" _null_ _null_ _null_ _null_ numeric_text _null_ _null_ _null_ "" f)); +DESCR("convert numeric to text"); +DATA(insert OID = 4172 ( bpchar_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1042" _null_ _null_ _null_ _null_ bpchar_numeric _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to numeric"); +DATA(insert OID = 4173 ( varchar_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1043" _null_ _null_ _null_ _null_ varchar_numeric _null_ _null_ _null_ "" f)); +DESCR("convert varchar to numeric"); +DATA(insert OID = 4174 ( varchar_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1043" _null_ _null_ _null_ _null_ varchar_int4 _null_ _null_ _null_ "" f)); +DESCR("convert varchar to int4"); +DATA(insert OID = 4175 ( bpchar_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpchar_int4 _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to int4"); +DATA(insert OID = 4176 ( varchar_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1043" _null_ _null_ _null_ _null_ varchar_int8 _null_ _null_ _null_ "" f)); +DESCR("convert varchar to int8"); +DATA(insert OID = 4177 ( timestampzone_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1184" _null_ _null_ _null_ _null_ timestampzone_text _null_ _null_ _null_ "" f)); +DESCR("convert timestampzone to text"); +DATA(insert OID = 4178 ( timestamp_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1114" _null_ _null_ _null_ _null_ timestamp_text _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to text"); +DATA(insert OID = 4179 ( timestamp_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1114" _null_ _null_ _null_ _null_ timestamp_varchar _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to text"); +DATA(insert OID = 4180 ( int2_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "21" _null_ _null_ _null_ _null_ int2_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int2 to varchar"); +DATA(insert OID = 4181 ( int4_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "23" _null_ _null_ _null_ _null_ int4_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to varchar"); +DATA(insert OID = 4182 ( int8_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "20" _null_ _null_ _null_ _null_ int8_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int8 to varchar"); +DATA(insert OID = 4183 ( numeric_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1700" _null_ _null_ _null_ _null_ numeric_varchar _null_ _null_ _null_ "" f)); +DESCR("convert numeric to varchar"); +DATA(insert OID = 4184 ( float4_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "700" _null_ _null_ _null_ _null_ float4_varchar _null_ _null_ _null_ "" f)); +DESCR("convert float4 to varchar"); +DATA(insert OID = 4185 ( float8_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "701" _null_ _null_ _null_ _null_ float8_varchar _null_ _null_ _null_ "" f)); +DESCR("convert float8 to varchar"); +DATA(insert OID = 4186 ( varchar_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1043" _null_ _null_ _null_ _null_ varchar_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert varchar to timestamp"); +DATA(insert OID = 4187 ( bpchar_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1042" _null_ _null_ _null_ _null_ bpchar_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to timestamp"); +DATA(insert OID = 4188 ( text_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "25" _null_ _null_ _null_ _null_ text_int1 _null_ _null_ _null_ "" f)); +DESCR("convert text to int1"); +DATA(insert OID = 4189 ( text_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "25" _null_ _null_ _null_ _null_ text_int2 _null_ _null_ _null_ "" f)); +DESCR("convert text to int2"); +DATA(insert OID = 4190 ( text_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ text_int4 _null_ _null_ _null_ "" f)); +DESCR("convert text to int4"); +DATA(insert OID = 4191 ( text_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "25" _null_ _null_ _null_ _null_ text_int8 _null_ _null_ _null_ "" f)); +DESCR("convert text to int8"); +DATA(insert OID = 4192 ( text_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "25" _null_ _null_ _null_ _null_ text_float4 _null_ _null_ _null_ "" f)); +DESCR("convert text to float4"); +DATA(insert OID = 4193 ( text_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "25" _null_ _null_ _null_ _null_ text_float8 _null_ _null_ _null_ "" f)); +DESCR("convert text to float8"); +DATA(insert OID = 4194 ( text_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "25" _null_ _null_ _null_ _null_ text_numeric _null_ _null_ _null_ "" f)); +DESCR("convert text to numeric"); +DATA(insert OID = 4195 ( bpchar_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1042" _null_ _null_ _null_ _null_ bpchar_int8 _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to int8"); +DATA(insert OID = 4196 ( bpchar_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1042" _null_ _null_ _null_ _null_ bpchar_float4 _null_ _null_ _null_ ""f)); +DESCR("convert bpchar to float4"); +DATA(insert OID = 4197 ( bpchar_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1042" _null_ _null_ _null_ _null_ bpchar_float8 _null_ _null_ _null_ ""f)); +DESCR("convert bpchar to float8"); +DATA(insert OID = 4198 ( varchar_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1043" _null_ _null_ _null_ _null_ varchar_float4 _null_ _null_ _null_ ""f)); +DESCR("convert varchar to float4"); +DATA(insert OID = 4199 ( varchar_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1043" _null_ _null_ _null_ _null_ varchar_float8 _null_ _null_ _null_ ""f)); +DESCR("convert varchar to float8"); +DATA(insert OID = 4200 ( plan_seed PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ get_plan_seed _null_ _null_ _null_ ""f)); +DESCR("get plan seed"); +DATA(insert OID = 4046 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2249 18" _null_ _null_ _null_ _null_ getbucket _null_ _null_ _null_ "" f)); +DESCR("get bucket"); +DATA(insert OID = 4047 ( getdistributekey PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2205" _null_ _null_ _null_ _null_ getDistributeKey _null_ _null_ _null_ "" f)); +DESCR("Get distribute columns"); +DATA(insert OID = 4048 ( table_data_skewness PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "2249 18" _null_ _null_ _null_ _null_ table_data_skewness _null_ _null_ _null_ "" f)); +DESCR("get datanode series number"); +#define TESTSKEWNESSRETURNTYPE 4048 +DATA(insert OID = 4065 ( int1_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "5545" _null_ _null_ _null_ _null_ int1_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int1 to varchar"); +DATA(insert OID = 4066 ( int1_nvarchar2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3969 "5545" _null_ _null_ _null_ _null_ int1_nvarchar2 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to nvarchar2"); +DATA(insert OID = 4067 ( int1_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "5545" _null_ _null_ _null_ _null_ int1_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int1 to bpchar"); +DATA(insert OID = 4068 ( int2_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "21" _null_ _null_ _null_ _null_ int2_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int2 to bpchar"); +DATA(insert OID = 4069 ( int8_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "20" _null_ _null_ _null_ _null_ int8_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int8 to bpchar"); +DATA(insert OID = 4070 ( float4_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "700" _null_ _null_ _null_ _null_ float4_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert float4 to bpchar"); +DATA(insert OID = 4071 ( float8_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "701" _null_ _null_ _null_ _null_ float8_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert float8 to bpchar"); +DATA(insert OID = 4072 ( numeric_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "1700" _null_ _null_ _null_ _null_ numeric_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert numeric to bpchar"); +DATA(insert OID = 4073 ( text_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "25" _null_ _null_ _null_ _null_ text_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp"); +/* add months to a timestamp */ +DATA(insert OID = 4074 ( add_months PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ add_months _null_ _null_ _null_ "" f)); +DESCR("add a int months to a timestamp"); +DATA(insert OID = 4075 ( last_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ last_day _null_ _null_ _null_ "" f)); +DESCR("the last day of the month"); +DATA(insert OID = 4076 ( next_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ next_day_int _null_ _null_ _null_ "" f)); +DESCR("next_day with offset number"); +DATA(insert OID = 4077 ( next_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 25" _null_ _null_ _null_ _null_ next_day_str _null_ _null_ _null_ "" f)); +DESCR("next_day with offset string of week"); + +DATA(insert OID = 3990 ( task_submit 3988 PGUID 12 1 0 0 0 f f f f f f i 4 0 2278 "20 25 1114 25" _null_ _null_ _null_ _null_ task_submit _null_ _null_ _null_ "" f)); +DESCR("add job"); +DATA(insert OID = 3991 ( remove 3988 PGUID 12 1 0 0 0 f f f f f f i 1 0 2278 "20" _null_ _null_ _null_ _null_ remove_job _null_ _null_ _null_ "" f)); +DESCR("remove job"); +DESCR("add job"); +DATA(insert OID = 3993 ( broken 3988 PGUID 12 1 0 0 0 f f f f f f i 3 0 2278 "20 16 1114" _null_ _null_ _null_ _null_ broken_job_state _null_ _null_ _null_ "" f)); +DESCR("broken job"); +DATA(insert OID = 3994 ( change 3988 PGUID 12 1 0 0 0 f f f f f f i 4 0 2278 "20 25 1114 25" _null_ _null_ _null_ _null_ change_job _null_ _null_ _null_ "" f)); +DESCR("change job"); +DATA(insert OID = 3995 ( what 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 25" _null_ _null_ _null_ _null_ update_what _null_ _null_ _null_ "" f)); +DESCR("update job what"); +DATA(insert OID = 3996 ( next_date 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 1114" _null_ _null_ _null_ _null_ update_next_date _null_ _null_ _null_ "" f)); +DESCR("update job next date"); +DATA(insert OID = 3997 ( interval 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 25" _null_ _null_ _null_ _null_ update_interval_date _null_ _null_ _null_ "" f)); +DESCR("update job interval"); +DATA(insert OID = 3998 ( update_pgjob PGNSP PGUID 12 1 0 0 0 f f f f f f v 9 0 2278 "20 18 20 1114 1114 1114 1114 1114 21" _null_ _null_ _null_ _null_ syn_update_pg_job _null_ _null_ _null_ "" f)); +DESCR("update pg_job synchronize from original coordinator."); +DATA(insert OID = 7998 ( set_working_grand_version_num_manually PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "26" _null_ _null_ _null_ _null_ set_working_grand_version_num_manually _null_ _null_ _null_ "" f)); +DESCR("Manually set the working grand version number of the instance."); +DATA(insert OID = 4201 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by username, nodegroup name"); +DATA(insert OID = 4202 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by username, nodegroup oid"); +DATA(insert OID = 4203 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by user oid, nodegroup name"); +DATA(insert OID = 4204 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by user oid, nodegroup oid"); +DATA(insert OID = 4205 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on nodegroup by nodegroup name"); +DATA(insert OID = 4206 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on nodegroup by nodegroup oid"); +DATA(insert OID = 4207 ( fenced_udf_process PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "23" _null_ _null_ _null_ _null_ fenced_udf_process _null_ _null_ _null_ "" f)); +DATA(insert OID = 4300 ( pv_compute_pool_workload PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,23,23,25}" "{o,o,o,o}" "{nodename, rpinuse, maxrp, nodestate}" _null_ pv_compute_pool_workload _null_ _null_ _null_ "" f)); +DESCR("the current workload of the compute pool"); +DATA(insert OID = 4208 ( get_db_source_datasize PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 20 "" _null_ _null_ _null_ _null_ get_db_source_datasize _null_ _null_ _null_ "" f)); +DESCR("total source datasize for the current database"); +DATA(insert OID = 4209 ( pg_clean_region_info PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1043 "" _null_ _null_ _null_ _null_ pg_clean_region_info _null_ _null_ _null_ "" f)); +DESCR("clean region map information cache for the current database"); + +/* + * Symbolic values for provolatile column: these indicate whether the result + * of a function is dependent *only* on the values of its explicit arguments, + * or can change due to outside factors (such as parameter variables or + * table contents). NOTE: functions having side-effects, such as setval(), + * must be labeled volatile to ensure they will not get optimized away, + * even if the actual return value is not changeable. + */ +#define PROVOLATILE_IMMUTABLE 'i' /* never changes for given input */ +#define PROVOLATILE_STABLE 's' /* does not change within a scan */ +#define PROVOLATILE_VOLATILE 'v' /* can change even within a scan */ + +/* + * Symbolic values for proargmodes column. Note that these must agree with + * the FunctionParameterMode enum in parsenodes.h; we declare them here to + * be accessible from either header. + */ +#define PROARGMODE_IN 'i' +#define PROARGMODE_OUT 'o' +#define PROARGMODE_INOUT 'b' +#define PROARGMODE_VARIADIC 'v' +#define PROARGMODE_TABLE 't' + +DATA(insert OID = 4440 ( byteawithoutorderwithequalcolin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolin _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4446 ( byteawithoutorderwithequalcolout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolout _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4444 ( byteawithoutorderwithequalcolrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2281" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolrecv _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4451 ( byteawithoutorderwithequalcolsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolsend _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4412 ( byteawithoutorderwithequalcoleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleq _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4417 ( byteawithoutorderwithequalcolne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolne _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4418 ( byteawithoutorderwithequalcolcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmp _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4447 ( byteawithoutorderwithequalcoleqbytear PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleqbytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4460 ( byteawithoutorderwithequalcolnebytear PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolnebytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4456 ( byteawithoutorderwithequalcolcmpbytear PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmpbytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4457 ( byteawithoutorderwithequalcoleqbyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleqbyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4461 ( byteawithoutorderwithequalcolgebyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolgebyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4462 ( byteawithoutorderwithequalcolnebyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolnebyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4463 ( byteawithoutorderwithequalcolcmpbyteal PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmpbyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4369 ( hll_hash_byteawithoutorderwithequalcol PGNSP PGUID 12 1 0 0 - f f f f t f i 1 0 4303 "4402" _null_ _null_ _null_ _null_ hll_hash_varlena _null_ _null_ _null_ "" f f f)); +DESCR("hypper log log hash a byteawithoutorderwithequalcol type"); +DATA(insert OID = 4449 ( byteawithoutorderwithequalcoltypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoltypmodin _null_ _null_ _null_ "" f _null_ f)); +#endif /* PG_PROC_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_range.h postgresql-hll-2.14/include/catalog/pg_range.h --- postgresql-hll-2.14_old/include/catalog/pg_range.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_range.h 2020-12-12 17:06:43.088345987 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_range.h + * definition of the system "range" relation (pg_range) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_range.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_RANGE_H +#define PG_RANGE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_range definition. cpp turns this into + * typedef struct FormData_pg_range + * ---------------- + */ +#define RangeRelationId 3541 +#define RangeRelation_Rowtype_Id 11657 + +CATALOG(pg_range,3541) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid rngtypid; /* OID of owning range type */ + Oid rngsubtype; /* OID of range's element type (subtype) */ + Oid rngcollation; /* collation for this range type, or 0 */ + Oid rngsubopc; /* subtype's btree opclass */ + regproc rngcanonical; /* canonicalize range, or 0 */ + regproc rngsubdiff; /* subtype difference as a float8, or 0 */ +} FormData_pg_range; + +/* ---------------- + * Form_pg_range corresponds to a pointer to a tuple with + * the format of pg_range relation. + * ---------------- + */ +typedef FormData_pg_range *Form_pg_range; + +/* ---------------- + * compiler constants for pg_range + * ---------------- + */ +#define Natts_pg_range 6 +#define Anum_pg_range_rngtypid 1 +#define Anum_pg_range_rngsubtype 2 +#define Anum_pg_range_rngcollation 3 +#define Anum_pg_range_rngsubopc 4 +#define Anum_pg_range_rngcanonical 5 +#define Anum_pg_range_rngsubdiff 6 + + +/* ---------------- + * initial contents of pg_range + * ---------------- + */ +DATA(insert (3904 23 0 1978 int4range_canonical int4range_subdiff)); +DATA(insert (3906 1700 0 3125 - numrange_subdiff)); +DATA(insert (3908 1114 0 3128 - tsrange_subdiff)); +DATA(insert (3910 1184 0 3127 - tstzrange_subdiff)); +DATA(insert (3912 1082 0 3122 daterange_canonical daterange_subdiff)); +DATA(insert (3926 20 0 3124 int8range_canonical int8range_subdiff)); + + +/* + * prototypes for functions in pg_range.c + */ + +extern void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation, + Oid rangeSubOpclass, RegProcedure rangeCanonical, + RegProcedure rangeSubDiff); +extern void RangeDelete(Oid rangeTypeOid); + +#endif /* PG_RANGE_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_resource_pool.h postgresql-hll-2.14/include/catalog/pg_resource_pool.h --- postgresql-hll-2.14_old/include/catalog/pg_resource_pool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_resource_pool.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,117 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_resource_pool.h + * define the system resource pool information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_resource_pool.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_RESOURCE_POOL_H +#define PG_RESOURCE_POOL_H + +#include "catalog/genbki.h" +#include "workload/workload.h" + +/* define the OID of the table pg_resource_pool */ +#define ResourcePoolRelationId 3450 +#define ResourcePoolRelation_Rowtype_Id 3466 + +CATALOG(pg_resource_pool,3450) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3466) BKI_SCHEMA_MACRO +{ + NameData respool_name; /* Name of resource pool */ + int4 mem_percent; /* Memory percentage */ + int8 cpu_affinity; /* CPU affinity mask */ + NameData control_group; /* Name of control group */ + int4 active_statements; /* Active statements */ + int4 max_dop; /* Max dop */ + NameData memory_limit; /* Memory limit to use */ + Oid parentid; /* parent resource pool oid */ + int4 io_limits; /* iops limit */ + NameData io_priority; /* percentage of IO resource for DN */ + NameData nodegroup; /* node group */ + bool is_foreign; /* flag to indicate the resource pool for foreign users */ +} FormData_pg_resource_pool; + + +/* ------------------------------------------------------------------------- + * Form_pg_resource_pool corresponds to a pointer to a tuple with + * the format of pg_resource_pool relation. + * There is different meaning that "int8" means 8-bits in C codes, while + * it means 64-bits in catalogs. + * ------------------------------------------------------------------------- + */ +typedef struct FormData_pg_resource_pool_real { + NameData respool_name; /* Name of resource pool */ + int4 mem_percent; /* Memory percentage */ + int64 cpu_affinity; /* CPU affinity mask */ + NameData control_group; /* Name of control group */ + int4 active_statements; /* Active statements */ + int4 max_dop; /* Max dop */ + NameData memory_limit; /* Memory limit to use */ + Oid parentid; /* parent resource pool oid */ + int4 iops_limits; /* iops limit */ + NameData io_priority; /* percentage of IO resource for DN */ + NameData nodegroup; /* node group */ + bool is_foreign; /* flag to indicate the resource pool for foreign users */ +} FormData_pg_resource_pool_real; + +typedef FormData_pg_resource_pool_real *Form_pg_resource_pool; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_resource_pool + * ------------------------------------------------------------------------- + */ +#define Natts_pg_resource_pool 12 +#define Anum_pg_resource_pool_rpname 1 +#define Anum_pg_resource_pool_mem_percentage 2 +#define Anum_pg_resource_pool_cpu_affinity 3 +#define Anum_pg_resource_pool_control_group 4 +#define Anum_pg_resource_pool_active_statements 5 +#define Anum_pg_resource_pool_max_dop 6 +#define Anum_pg_resource_pool_memory_limit 7 +#define Anum_pg_resource_pool_parent 8 +#define Anum_pg_resource_pool_iops_limits 9 +#define Anum_pg_resource_pool_io_priority 10 +#define Anum_pg_resource_pool_nodegroup 11 +#define Anum_pg_resource_pool_is_foreign 12 + +/* -1 means 0xffffffffffffffff */ +DATA(insert OID = 10 ("default_pool" 100 -1 "DefaultClass:Medium" -1 1 "8GB" 0 0 "None" "installation" f)); + +#define DEFAULT_POOL_OID 10 +#define DEFAULT_POOL_NAME "default_pool" +#define INVALID_POOL_NAME "invalid_pool" +#define ULIMITED_MEMORY_PERCENTAGE 100 +#define ULIMITED_CPU_AFFINITY 0xffffffffffffffffULL +#define ULIMITED_ACT_STATEMENTS -1 +#define DEFAULT_CONTROL_GROUP "DefaultClass:Medium" +#define DEFAULT_MAX_DOP 1 +#define DEFAULT_MEMORY_LIMIT "8GB" +#define DEFAULT_IOPS_LIMITS 0 +#define DEFAULT_IO_PRIORITY "None" +#define DEFAULT_NODE_GROUP "installation" // the same as CNG_OPTION_INSTALLATION + +/* default setting for user defined resource pool */ +#define DEFAULT_MEMORY_PERCENTAGE 0 +#define DEFAULT_MULTI_TENANT_MEMPCT 20 +#define DEFAULT_ACT_STATEMENTS 10 + +#endif /* PG_RESOURCE_POOL_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_rewrite.h postgresql-hll-2.14/include/catalog/pg_rewrite.h --- postgresql-hll-2.14_old/include/catalog/pg_rewrite.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_rewrite.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pg_rewrite.h + * definition of the system "rewrite-rule" relation (pg_rewrite) + * along with the relation's initial contents. + * + * As of Postgres 7.3, the primary key for this table is + * --- ie, rule names are only unique among the rules of a given table. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_rewrite.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_REWRITE_H +#define PG_REWRITE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_rewrite definition. cpp turns this into + * typedef struct FormData_pg_rewrite + * ---------------- + */ +#define RewriteRelationId 2618 +#define RewriteRelation_Rowtype_Id 11328 + +CATALOG(pg_rewrite,2618) BKI_SCHEMA_MACRO +{ + NameData rulename; + Oid ev_class; + int2 ev_attr; + char ev_type; + char ev_enabled; + bool is_instead; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + pg_node_tree ev_qual; + pg_node_tree ev_action; +#endif +} FormData_pg_rewrite; + +/* ---------------- + * Form_pg_rewrite corresponds to a pointer to a tuple with + * the format of pg_rewrite relation. + * ---------------- + */ +typedef FormData_pg_rewrite *Form_pg_rewrite; + +/* ---------------- + * compiler constants for pg_rewrite + * ---------------- + */ +#define Natts_pg_rewrite 8 +#define Anum_pg_rewrite_rulename 1 +#define Anum_pg_rewrite_ev_class 2 +#define Anum_pg_rewrite_ev_attr 3 +#define Anum_pg_rewrite_ev_type 4 +#define Anum_pg_rewrite_ev_enabled 5 +#define Anum_pg_rewrite_is_instead 6 +#define Anum_pg_rewrite_ev_qual 7 +#define Anum_pg_rewrite_ev_action 8 + +#endif /* PG_REWRITE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_rlspolicy.h postgresql-hll-2.14/include/catalog/pg_rlspolicy.h --- postgresql-hll-2.14_old/include/catalog/pg_rlspolicy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_rlspolicy.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_rlspolicy.h + * definition of the row level security policy system catalog (pg_rlspolicy) + * the genbki.pl script reads this file and generates postgres.bki information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_rlspolicy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_RLSPOLICY_H +#define PG_RLSPOLICY_H + +#include "catalog/genbki.h" + +#define RlsPolicyRelationId 3254 +#define RlsPolicyRelation_Rowtype_Id 11652 + +CATALOG(pg_rlspolicy,3254) BKI_SCHEMA_MACRO +{ + NameData polname; /* Rlspolicy name */ + Oid polrelid; /* Oid of the relation with rlspolicy */ + char polcmd; /* Keep same with ACL_*_CHR, support 'a','r','w','d','*'(all) */ + bool polpermissive; /* Permissive or Restrictive rlspolicy */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + Oid polroles[1]; /* Roles associated with rlspolicy */ + pg_node_tree polqual; /* Using quals */ +#endif +} FormData_pg_rlspolicy; + +/* ---------------- + * Form_pg_rlspolicy corresponds to a pointer to a row with + * the format of pg_rlspolicy relation. + * ---------------- + */ +typedef FormData_pg_rlspolicy *Form_pg_rlspolicy; + +/* ---------------- + * compiler constants for pg_rlspolicy + * ---------------- + */ +#define Natts_pg_rlspolicy 6 +#define Anum_pg_rlspolicy_polname 1 +#define Anum_pg_rlspolicy_polrelid 2 +#define Anum_pg_rlspolicy_polcmd 3 +#define Anum_pg_rlspolicy_polpermissive 4 +#define Anum_pg_rlspolicy_polroles 5 +#define Anum_pg_rlspolicy_polqual 6 + +#endif /* PG_RLSPOLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_seclabel.h postgresql-hll-2.14/include/catalog/pg_seclabel.h --- postgresql-hll-2.14_old/include/catalog/pg_seclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_seclabel.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * pg_seclabel.h + * definition of the system "security label" relation (pg_seclabel) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SECLABEL_H +#define PG_SECLABEL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_seclabel definition. cpp turns this into + * typedef struct FormData_pg_seclabel + * ---------------- + */ +#define SecLabelRelationId 3596 +#define SecLabelRelation_Rowtype_Id 33654 + +CATALOG(pg_seclabel,3596) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of the object itself */ + Oid classoid; /* OID of table containing the object */ + int4 objsubid; /* column number, or 0 if not used */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text provider; /* name of label provider */ + text label; /* security label of the object */ +#endif +} FormData_pg_seclabel; + +/* ---------------- + * compiler constants for pg_seclabel + * ---------------- + */ +#define Natts_pg_seclabel 5 +#define Anum_pg_seclabel_objoid 1 +#define Anum_pg_seclabel_classoid 2 +#define Anum_pg_seclabel_objsubid 3 +#define Anum_pg_seclabel_provider 4 +#define Anum_pg_seclabel_label 5 + +#endif /* PG_SECLABEL_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_shdepend.h postgresql-hll-2.14/include/catalog/pg_shdepend.h --- postgresql-hll-2.14_old/include/catalog/pg_shdepend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_shdepend.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,96 @@ +/* ------------------------------------------------------------------------- + * + * pg_shdepend.h + * definition of the system "shared dependency" relation (pg_shdepend) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_shdepend.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHDEPEND_H +#define PG_SHDEPEND_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shdepend definition. cpp turns this into + * typedef struct FormData_pg_shdepend + * ---------------- + */ +#define SharedDependRelationId 1214 +#define SharedDependRelation_Rowtype_Id 11635 + +CATALOG(pg_shdepend,1214) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* + * Identification of the dependent (referencing) object. + * + * These fields are all zeroes for a DEPENDENCY_PIN entry. Also, dbid can + * be zero to denote a shared object. + */ + Oid dbid; /* OID of database containing object */ + Oid classid; /* OID of table containing object */ + Oid objid; /* OID of object itself */ + int4 objsubid; /* column number, or 0 if not used */ + + /* + * Identification of the independent (referenced) object. This is always + * a shared object, so we need no database ID field. We don't bother with + * a sub-object ID either. + */ + Oid refclassid; /* OID of table containing object */ + Oid refobjid; /* OID of object itself */ + + /* + * Precise semantics of the relationship are specified by the deptype + * field. See SharedDependencyType in catalog/dependency.h. + */ + char deptype; /* see codes in dependency.h */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text objfile; /* library file path */ +#endif +} FormData_pg_shdepend; + +/* ---------------- + * Form_pg_shdepend corresponds to a pointer to a row with + * the format of pg_shdepend relation. + * ---------------- + */ +typedef FormData_pg_shdepend *Form_pg_shdepend; + +/* ---------------- + * compiler constants for pg_shdepend + * ---------------- + */ +#define Natts_pg_shdepend 8 +#define Anum_pg_shdepend_dbid 1 +#define Anum_pg_shdepend_classid 2 +#define Anum_pg_shdepend_objid 3 +#define Anum_pg_shdepend_objsubid 4 +#define Anum_pg_shdepend_refclassid 5 +#define Anum_pg_shdepend_refobjid 6 +#define Anum_pg_shdepend_deptype 7 +#define Anum_pg_shdepend_objfile 8 + + +/* + * pg_shdepend has no preloaded contents; system-defined dependencies are + * loaded into it during a late stage of the initdb process. + * + * NOTE: we do not represent all possible dependency pairs in pg_shdepend; + * for example, there's not much value in creating an explicit dependency + * from a relation to its database. Currently, only dependencies on roles + * are explicitly stored in pg_shdepend. + */ + +#endif /* PG_SHDEPEND_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_shdescription.h postgresql-hll-2.14/include/catalog/pg_shdescription.h --- postgresql-hll-2.14_old/include/catalog/pg_shdescription.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_shdescription.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * pg_shdescription.h + * definition of the system "shared description" relation + * (pg_shdescription) + * + * NOTE: an object is identified by the OID of the row that primarily + * defines the object, plus the OID of the table that that row appears in. + * For example, a database is identified by the OID of its pg_database row + * plus the pg_class OID of table pg_database. This allows unique + * identification of objects without assuming that OIDs are unique + * across tables. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_shdescription.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHDESCRIPTION_H +#define PG_SHDESCRIPTION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shdescription definition. cpp turns this into + * typedef struct FormData_pg_shdescription + * ---------------- + */ +#define SharedDescriptionRelationId 2396 +#define SharedDescriptionRelation_Rowtype_Id 11636 + +CATALOG(pg_shdescription,2396) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of object itself */ + Oid classoid; /* OID of table containing object */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text description; /* description of object */ +#endif +} FormData_pg_shdescription; + +/* ---------------- + * Form_pg_shdescription corresponds to a pointer to a tuple with + * the format of pg_shdescription relation. + * ---------------- + */ +typedef FormData_pg_shdescription *Form_pg_shdescription; + +/* ---------------- + * compiler constants for pg_shdescription + * ---------------- + */ +#define Natts_pg_shdescription 3 +#define Anum_pg_shdescription_objoid 1 +#define Anum_pg_shdescription_classoid 2 +#define Anum_pg_shdescription_description 3 + +/* ---------------- + * initial contents of pg_shdescription + * ---------------- + */ + +/* + * Because the contents of this table are taken from the other *.h files, + * there is no initialization here. The initial contents are extracted + * by genbki.pl and loaded during initdb. + */ + +#endif /* PG_SHDESCRIPTION_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_shseclabel.h postgresql-hll-2.14/include/catalog/pg_shseclabel.h --- postgresql-hll-2.14_old/include/catalog/pg_shseclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_shseclabel.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * pg_shseclabel.h + * definition of the system "security label" relation (pg_shseclabel) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHSECLABEL_H +#define PG_SHSECLABEL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shseclabel definition. cpp turns this into + * typedef struct FormData_pg_shseclabel + * ---------------- + */ +#define SharedSecLabelRelationId 3592 +#define SharedSecLabelRelation_Rowtype_Id 11655 + +CATALOG(pg_shseclabel,3592) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of the shared object itself */ + Oid classoid; /* OID of table containing the shared object */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text provider; /* name of label provider */ + text label; /* security label of the object */ +#endif +} FormData_pg_shseclabel; + +/* ---------------- + * compiler constants for pg_shseclabel + * ---------------- + */ +#define Natts_pg_shseclabel 4 +#define Anum_pg_shseclabel_objoid 1 +#define Anum_pg_shseclabel_classoid 2 +#define Anum_pg_shseclabel_provider 3 +#define Anum_pg_shseclabel_label 4 + +#endif /* PG_SHSECLABEL_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_statistic_ext.h postgresql-hll-2.14/include/catalog/pg_statistic_ext.h --- postgresql-hll-2.14_old/include/catalog/pg_statistic_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_statistic_ext.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,188 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_statistic_ext.h + * definition of the system "extended statistic" relation (pg_statistic_ext) + * along with the relation's initial contents. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/pg_statistic_ext.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_STATISTIC_EXT_H +#define PG_STATISTIC_EXT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_statistic_ext definition. cpp turns this into + * typedef struct FormData_pg_statistic_ext + * ---------------- + */ +#define StatisticExtRelationId 3220 +#define StatisticExtRelation_Rowtype_Id 11660 + +CATALOG(pg_statistic_ext,3220) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + Oid starelid; /* relation containing attribute */ + char starelkind; /* 'c': starelid ref pg_class.oid + * 'p': starelid ref pg_partition.oid */ + bool stainherit; /* true if inheritance children are included */ + + /* the fraction of the column's entries that are NULL: */ + float4 stanullfrac; + + /* + * stawidth is the average width in bytes of non-null entries. For + * fixed-width datatypes this is of course the same as the typlen, but for + * var-width types it is more useful. Note that this is the average width + * of the data as actually stored, post-TOASTing (eg, for a + * moved-out-of-line value, only the size of the pointer object is + * counted). This is the appropriate definition for the primary use of + * the statistic, which is to estimate sizes of in-memory hash tables of + * tuples. + */ + int4 stawidth; + + /* ---------------- + * stadistinct indicates the (approximate) number of distinct non-null + * data values in the column. The interpretation is: + * 0 unknown or not computed + * > 0 actual number of distinct values + * < 0 negative of multiplier for number of rows + * The special negative case allows us to cope with columns that are + * unique (stadistinct = -1) or nearly so (for example, a column in + * which values appear about twice on the average could be represented + * by stadistinct = -0.5). Because the number-of-rows statistic in + * pg_class may be updated more frequently than pg_statistic_ext is, it's + * important to be able to describe such situations as a multiple of + * the number of rows, rather than a fixed number of distinct values. + * But in other cases a fixed number is correct (eg, a boolean column). + * ---------------- + */ + float4 stadistinct; + float4 stadndistinct; + + /* ---------------- + * To allow keeping statistics on different kinds of datatypes, + * we do not hard-wire any particular meaning for the remaining + * statistical fields. Instead, we provide several "slots" in which + * statistical data can be placed. Each slot includes: + * kind integer code identifying kind of data (see below) + * op OID of associated operator, if needed + * numbers float4 array (for statistical values) + * values anyarray (for representations of data values) + * The ID and operator fields are never NULL; they are zeroes in an + * unused slot. The numbers and values fields are NULL in an unused + * slot, and might also be NULL in a used slot if the slot kind has + * no need for one or the other. + * ---------------- + */ + int2 stakind1; + int2 stakind2; + int2 stakind3; + int2 stakind4; + int2 stakind5; + + Oid staop1; + Oid staop2; + Oid staop3; + Oid staop4; + Oid staop5; + + /* variable-length fields start here, but we allow direct access to stakey */ + int2vector stakey; /* attribute (column) stats are for */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + float4 stanumbers1[1]; + float4 stanumbers2[1]; + float4 stanumbers3[1]; + float4 stanumbers4[1]; + float4 stanumbers5[1]; + + /* + * Values in these arrays are values of the column's data type, or of some + * related type such as an array element type. We presently have to cheat + * quite a bit to allow polymorphic arrays of this kind, but perhaps + * someday it'll be a less bogus facility. + */ + anyarray stavalues1; + anyarray stavalues2; + anyarray stavalues3; + anyarray stavalues4; + anyarray stavalues5; + pg_node_tree staexprs; +#endif +} FormData_pg_statistic_ext; + +#define STATISTIC_NUM_SLOTS 5 +#define STATISTIC_KIND_TBLSIZE 6 +#define STARELKIND_CLASS 'c' +#define STARELKIND_PARTITION 'p' + +/* ---------------- + * Form_pg_statistic_ext corresponds to a pointer to a tuple with + * the format of pg_statistic_ext relation. + * ---------------- + */ +typedef FormData_pg_statistic_ext *Form_pg_statistic_ext; + +/* ---------------- + * compiler constants for pg_statistic + * ---------------- + */ +#define Natts_pg_statistic_ext 29 +#define Anum_pg_statistic_ext_starelid 1 +#define Anum_pg_statistic_ext_starelkind 2 +#define Anum_pg_statistic_ext_stainherit 3 +#define Anum_pg_statistic_ext_stanullfrac 4 +#define Anum_pg_statistic_ext_stawidth 5 +#define Anum_pg_statistic_ext_stadistinct 6 +#define Anum_pg_statistic_ext_stadndistinct 7 +#define Anum_pg_statistic_ext_stakind1 8 +#define Anum_pg_statistic_ext_stakind2 9 +#define Anum_pg_statistic_ext_stakind3 10 +#define Anum_pg_statistic_ext_stakind4 11 +#define Anum_pg_statistic_ext_stakind5 12 +#define Anum_pg_statistic_ext_staop1 13 +#define Anum_pg_statistic_ext_staop2 14 +#define Anum_pg_statistic_ext_staop3 15 +#define Anum_pg_statistic_ext_staop4 16 +#define Anum_pg_statistic_ext_staop5 17 +#define Anum_pg_statistic_ext_stakey 18 +#define Anum_pg_statistic_ext_stanumbers1 19 +#define Anum_pg_statistic_ext_stanumbers2 20 +#define Anum_pg_statistic_ext_stanumbers3 21 +#define Anum_pg_statistic_ext_stanumbers4 22 +#define Anum_pg_statistic_ext_stanumbers5 23 +#define Anum_pg_statistic_ext_stavalues1 24 +#define Anum_pg_statistic_ext_stavalues2 25 +#define Anum_pg_statistic_ext_stavalues3 26 +#define Anum_pg_statistic_ext_stavalues4 27 +#define Anum_pg_statistic_ext_stavalues5 28 +#define Anum_pg_statistic_ext_staexprs 29 + +/* statistic definition for extended statistic */ +/* + * In a "most common values" slot that contains NULL value staop is the OID + * of the "=" operator used to decide whether values are the same or not. + * stavalues contains the K most common values(NULLS contains ) appearing in + * the column, and stanumbers contains their frequencies (fractions of total + * row count). The values shall be ordered in decreasing frequency. Note that + * since the arrays are variable-size, K may be chosen by the statistics + * collector. Values should not appear in MCV unless they have been observed + * to occur more than once; a unique column will have no MCV slot. + */ +#define STATISTIC_KIND_NULL_MCV 6 + +#define STATISTIC_KIND_MULTICOLUMN 10001 + +#endif /* PG_STATISTIC_EXT_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_statistic.h postgresql-hll-2.14/include/catalog/pg_statistic.h --- postgresql-hll-2.14_old/include/catalog/pg_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_statistic.h 2020-12-12 17:06:43.089346000 +0800 @@ -0,0 +1,281 @@ +/* ------------------------------------------------------------------------- + * + * pg_statistic.h + * definition of the system "statistic" relation (pg_statistic) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_statistic.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_STATISTIC_H +#define PG_STATISTIC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_statistic definition. cpp turns this into + * typedef struct FormData_pg_statistic + * ---------------- + */ +#define StatisticRelationId 2619 +#define StatisticRelation_Rowtype_Id 11327 + +CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + Oid starelid; /* relation containing attribute */ + char starelkind; /*'c': starelid ref pg_class.oid + *'p': starelid ref pg_partition.oid*/ + int2 staattnum; /* attribute (column) stats are for */ + bool stainherit; /* true if inheritance children are included */ + + /* the fraction of the column's entries that are NULL: */ + float4 stanullfrac; + + /* + * stawidth is the average width in bytes of non-null entries. For + * fixed-width datatypes this is of course the same as the typlen, but for + * var-width types it is more useful. Note that this is the average width + * of the data as actually stored, post-TOASTing (eg, for a + * moved-out-of-line value, only the size of the pointer object is + * counted). This is the appropriate definition for the primary use of + * the statistic, which is to estimate sizes of in-memory hash tables of + * tuples. + */ + int4 stawidth; + + /* ---------------- + * stadistinct indicates the (approximate) number of distinct non-null + * data values in the column. The interpretation is: + * 0 unknown or not computed + * > 0 actual number of distinct values + * < 0 negative of multiplier for number of rows + * The special negative case allows us to cope with columns that are + * unique (stadistinct = -1) or nearly so (for example, a column in + * which values appear about twice on the average could be represented + * by stadistinct = -0.5). Because the number-of-rows statistic in + * pg_class may be updated more frequently than pg_statistic is, it's + * important to be able to describe such situations as a multiple of + * the number of rows, rather than a fixed number of distinct values. + * But in other cases a fixed number is correct (eg, a boolean column). + * ---------------- + */ + float4 stadistinct; + + /* ---------------- + * To allow keeping statistics on different kinds of datatypes, + * we do not hard-wire any particular meaning for the remaining + * statistical fields. Instead, we provide several "slots" in which + * statistical data can be placed. Each slot includes: + * kind integer code identifying kind of data (see below) + * op OID of associated operator, if needed + * numbers float4 array (for statistical values) + * values anyarray (for representations of data values) + * The ID and operator fields are never NULL; they are zeroes in an + * unused slot. The numbers and values fields are NULL in an unused + * slot, and might also be NULL in a used slot if the slot kind has + * no need for one or the other. + * ---------------- + */ + int2 stakind1; + int2 stakind2; + int2 stakind3; + int2 stakind4; + int2 stakind5; + + Oid staop1; + Oid staop2; + Oid staop3; + Oid staop4; + Oid staop5; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + float4 stanumbers1[1]; + float4 stanumbers2[1]; + float4 stanumbers3[1]; + float4 stanumbers4[1]; + float4 stanumbers5[1]; + + /* + * Values in these arrays are values of the column's data type, or of some + * related type such as an array element type. We presently have to cheat + * quite a bit to allow polymorphic arrays of this kind, but perhaps + * someday it'll be a less bogus facility. + */ + anyarray stavalues1; + anyarray stavalues2; + anyarray stavalues3; + anyarray stavalues4; + anyarray stavalues5; + float4 stadndistinct; + text staextinfo; +#endif +} FormData_pg_statistic; + +#define STATISTIC_NUM_SLOTS 5 +#define STATISTIC_KIND_TBLSIZE 6 +#define STARELKIND_CLASS 'c' +#define STARELKIND_PARTITION 'p' + +/* ---------------- + * Form_pg_statistic corresponds to a pointer to a tuple with + * the format of pg_statistic relation. + * ---------------- + */ +typedef FormData_pg_statistic *Form_pg_statistic; + +/* ---------------- + * compiler constants for pg_statistic + * ---------------- + */ +#define Natts_pg_statistic 29 +#define Anum_pg_statistic_starelid 1 +#define Anum_pg_statistic_starelkind 2 +#define Anum_pg_statistic_staattnum 3 +#define Anum_pg_statistic_stainherit 4 +#define Anum_pg_statistic_stanullfrac 5 +#define Anum_pg_statistic_stawidth 6 +#define Anum_pg_statistic_stadistinct 7 +#define Anum_pg_statistic_stakind1 8 +#define Anum_pg_statistic_stakind2 9 +#define Anum_pg_statistic_stakind3 10 +#define Anum_pg_statistic_stakind4 11 +#define Anum_pg_statistic_stakind5 12 +#define Anum_pg_statistic_staop1 13 +#define Anum_pg_statistic_staop2 14 +#define Anum_pg_statistic_staop3 15 +#define Anum_pg_statistic_staop4 16 +#define Anum_pg_statistic_staop5 17 +#define Anum_pg_statistic_stanumbers1 18 +#define Anum_pg_statistic_stanumbers2 19 +#define Anum_pg_statistic_stanumbers3 20 +#define Anum_pg_statistic_stanumbers4 21 +#define Anum_pg_statistic_stanumbers5 22 +#define Anum_pg_statistic_stavalues1 23 +#define Anum_pg_statistic_stavalues2 24 +#define Anum_pg_statistic_stavalues3 25 +#define Anum_pg_statistic_stavalues4 26 +#define Anum_pg_statistic_stavalues5 27 +#define Anum_pg_statistic_stadndistinct 28 +#define Anum_pg_statistic_staextinfo 29 + +/* + * Currently, five statistical slot "kinds" are defined by core PostgreSQL, + * as documented below. Additional "kinds" will probably appear in + * future to help cope with non-scalar datatypes. Also, custom data types + * can define their own "kind" codes by mutual agreement between a custom + * typanalyze routine and the selectivity estimation functions of the type's + * operators. + * + * Code reading the pg_statistic relation should not assume that a particular + * data "kind" will appear in any particular slot. Instead, search the + * stakind fields to see if the desired data is available. (The standard + * function get_attstatsslot() may be used for this.) + */ + +/* + * The present allocation of "kind" codes is: + * + * 1-99: reserved for assignment by the core PostgreSQL project + * (values in this range will be documented in this file) + * 100-199: reserved for assignment by the PostGIS project + * (values to be documented in PostGIS documentation) + * 200-299: reserved for assignment by the ESRI ST_Geometry project + * (values to be documented in ESRI ST_Geometry documentation) + * 300-9999: reserved for future public assignments + * + * For private use you may choose a "kind" code at random in the range + * 10000-30000. However, for code that is to be widely disseminated it is + * better to obtain a publicly defined "kind" code by request from the + * PostgreSQL Global Development Group. + */ + +/* + * In a "most common values" slot, staop is the OID of the "=" operator + * used to decide whether values are the same or not. stavalues contains + * the K most common non-null values appearing in the column, and stanumbers + * contains their frequencies (fractions of total row count). The values + * shall be ordered in decreasing frequency. Note that since the arrays are + * variable-size, K may be chosen by the statistics collector. Values should + * not appear in MCV unless they have been observed to occur more than once; + * a unique column will have no MCV slot. + */ +#define STATISTIC_KIND_MCV 1 + +/* + * A "histogram" slot describes the distribution of scalar data. staop is + * the OID of the "<" operator that describes the sort ordering. (In theory, + * more than one histogram could appear, if a datatype has more than one + * useful sort operator.) stavalues contains M (>=2) non-null values that + * divide the non-null column data values into M-1 bins of approximately equal + * population. The first stavalues item is the MIN and the last is the MAX. + * stanumbers is not used and should be NULL. IMPORTANT POINT: if an MCV + * slot is also provided, then the histogram describes the data distribution + * *after removing the values listed in MCV* (thus, it's a "compressed + * histogram" in the technical parlance). This allows a more accurate + * representation of the distribution of a column with some very-common + * values. In a column with only a few distinct values, it's possible that + * the MCV list describes the entire data population; in this case the + * histogram reduces to empty and should be omitted. + */ +#define STATISTIC_KIND_HISTOGRAM 2 + +/* + * A "correlation" slot describes the correlation between the physical order + * of table tuples and the ordering of data values of this column, as seen + * by the "<" operator identified by staop. (As with the histogram, more + * than one entry could theoretically appear.) stavalues is not used and + * should be NULL. stanumbers contains a single entry, the correlation + * coefficient between the sequence of data values and the sequence of + * their actual tuple positions. The coefficient ranges from +1 to -1. + */ +#define STATISTIC_KIND_CORRELATION 3 + +/* + * A "most common elements" slot is similar to a "most common values" slot, + * except that it stores the most common non-null *elements* of the column + * values. This is useful when the column datatype is an array or some other + * type with identifiable elements (for instance, tsvector). staop contains + * the equality operator appropriate to the element type. stavalues contains + * the most common element values, and stanumbers their frequencies. Unlike + * MCV slots, frequencies are measured as the fraction of non-null rows the + * element value appears in, not the frequency of all rows. Also unlike + * MCV slots, the values are sorted into the element type's default order + * (to support binary search for a particular value). Since this puts the + * minimum and maximum frequencies at unpredictable spots in stanumbers, + * there are two extra members of stanumbers, holding copies of the minimum + * and maximum frequencies. Optionally, there can be a third extra member, + * which holds the frequency of null elements (expressed in the same terms: + * the fraction of non-null rows that contain at least one null element). If + * this member is omitted, the column is presumed to contain no null elements. + * + * Note: in current usage for tsvector columns, the stavalues elements are of + * type text, even though their representation within tsvector is not + * exactly text. + */ +#define STATISTIC_KIND_MCELEM 4 + +/* + * A "distinct elements count histogram" slot describes the distribution of + * the number of distinct element values present in each row of an array-type + * column. Only non-null rows are considered, and only non-null elements. + * staop contains the equality operator appropriate to the element type. + * stavalues is not used and should be NULL. The last member of stanumbers is + * the average count of distinct element values over all non-null rows. The + * preceding M (>=2) members form a histogram that divides the population of + * distinct-elements counts into M-1 bins of approximately equal population. + * The first of these is the minimum observed count, and the last the maximum. + */ +#define STATISTIC_KIND_DECHIST 5 + +#endif /* PG_STATISTIC_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_streaming_cont_query.h postgresql-hll-2.14/include/catalog/pg_streaming_cont_query.h --- postgresql-hll-2.14_old/include/catalog/pg_streaming_cont_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_streaming_cont_query.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,59 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_cont_query.h + * streaming continuous query catalog schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_cont_query.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_CONT_QUERY_H +#define STREAMING_CONT_QUERY_H + +#include "catalog/genbki.h" + +#define StreamingContQueryRelationId 9029 +#define StreamingContQueryRelation_Rowtype_Id 7201 + +CATALOG(streaming_cont_query,9029) BKI_SCHEMA_MACRO +{ + int4 id; + char type; + Oid relid; + Oid defrelid; + bool active; + Oid streamrelid; + Oid matrelid; + Oid lookupidxid; + int2 step_factor; + int4 ttl; + int2 ttl_attno; + Oid dictrelid; + int2 grpnum; + int2vector grpidx; +} FormData_streaming_cont_query; + +typedef FormData_streaming_cont_query *Form_streaming_cont_query; + + +#define Natts_streaming_cont_query 14 + +#define Anum_streaming_cont_query_id 1 +#define Anum_streaming_cont_query_type 2 +#define Anum_streaming_cont_query_relid 3 +#define Anum_streaming_cont_query_defrelid 4 +#define Anum_streaming_cont_query_active 5 +#define Anum_streaming_cont_query_streamrelid 6 +#define Anum_streaming_cont_query_matrelid 7 +#define Anum_streaming_cont_query_lookupidxid 8 +#define Anum_streaming_cont_query_step_factor 9 +#define Anum_streaming_cont_query_ttl 10 +#define Anum_streaming_cont_query_ttl_attno 11 +#define Anum_streaming_cont_query_dictrelid 12 +#define Anum_streaming_cont_query_grpnum 13 +#define Anum_streaming_cont_query_grpidx 14 + +#endif diff -uprN postgresql-hll-2.14_old/include/catalog/pg_streaming_fn.h postgresql-hll-2.14/include/catalog/pg_streaming_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_streaming_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_streaming_fn.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,29 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_fn.h + * streaming functions + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_fn.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef PG_STREAMING_FN_H +#define PG_STREAMING_FN_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/indexing.h" +#include "catalog/pg_type.h" + +#define STREAMING_SERVER "streaming" + +void lookup_pg_stream_cont_query(); + +bool relid_is_stream(Oid relid); +bool range_var_is_stream(const RangeVar *rv, bool missingOK); +bool relid_is_cv_tab(Oid relid); + +#endif diff -uprN postgresql-hll-2.14_old/include/catalog/pg_streaming_reaper_status.h postgresql-hll-2.14/include/catalog/pg_streaming_reaper_status.h --- postgresql-hll-2.14_old/include/catalog/pg_streaming_reaper_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_streaming_reaper_status.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,41 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_reaper_status.h + * streaming continuous query catalog schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_reaper_status.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_REAPER_STATUS_H +#define STREAMING_REAPER_STATUS_H + +#include "catalog/genbki.h" + +#define StreamingReaperStatusRelationId 9030 +#define StreamingReaperStatusRelation_Rowtype_Id 7202 + +CATALOG(streaming_reaper_status,9030) BKI_SCHEMA_MACRO +{ + int4 id; + NameData contquery_name; +#ifdef CATALOG_VARLEN + text gather_interval; + text gather_completion_time; +#endif +} FormData_streaming_reaper_status; + +typedef FormData_streaming_reaper_status *Form_streaming_reaper_status; + + +#define Natts_streaming_reaper_status 4 + +#define Anum_streaming_reaper_status_id 1 +#define Anum_streaming_reaper_status_contquery_name 2 +#define Anum_streaming_reaper_status_gather_interval 3 +#define Anum_streaming_reaper_status_gather_completion_time 4 + +#endif diff -uprN postgresql-hll-2.14_old/include/catalog/pg_streaming_stream.h postgresql-hll-2.14/include/catalog/pg_streaming_stream.h --- postgresql-hll-2.14_old/include/catalog/pg_streaming_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_streaming_stream.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,34 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_stream.h + * streaming stream schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_stream.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_STREAM_H +#define STREAMING_STREAM_H + +#include "catalog/genbki.h" + +#define StreamingStreamRelationId 9028 +#define StreamingStreamRelation_Rowtype_Id 7200 + +CATALOG(streaming_stream,9028) BKI_SCHEMA_MACRO +{ + Oid relid; + bytea queries; +} FormData_streaming_stream; + +typedef FormData_streaming_stream *Form_streaming_stream; + +#define Natts_streaming_stream 2 + +#define Anum_streaming_stream_relid 1 +#define Anum_streaming_stream_queries 2 + +#endif /* PG_STREAMING_STREAM_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_synonym.h postgresql-hll-2.14/include/catalog/pg_synonym.h --- postgresql-hll-2.14_old/include/catalog/pg_synonym.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_synonym.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,99 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_synonym.h + * definition of the system "synonym" relation (pg_synonym) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_synonym.h + * + * NOTES + * the genbki.sh script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_SYNONYM_H +#define PG_SYNONYM_H + +#include "catalog/genbki.h" +#include "nodes/parsenodes.h" + +/* ---------------------------------------------------------------- + * pg_synonym definition. + * + * synname name of the synonym + * synnamespace name space which the synonym belongs to + * synowner owner of the synonym + * synobjschema schema name which the referenced object belongs to + * synobjname referenced object name + * ---------------------------------------------------------------- + */ +#define PgSynonymRelationId 3546 +#define PgSynonymRelationId_Rowtype_Id 11662 + +#define SYNONYM_VERSION_NUM 92059 + +CATALOG(pg_synonym,3546) BKI_SCHEMA_MACRO +{ + NameData synname; + Oid synnamespace; + Oid synowner; + NameData synobjschema; + NameData synobjname; +} FormData_pg_synonym; + +/* ---------------- + * Form_pg_synonym corresponds to a pointer to a tuple with + * the format of pg_synonym relation. + * ---------------- + */ +typedef FormData_pg_synonym *Form_pg_synonym; + +/* ---------------- + * compiler constants for pg_synonym + * ---------------- + */ +#define Natts_pg_synonym 5 +#define Anum_pg_synonym_synname 1 +#define Anum_pg_synonym_synnamespace 2 +#define Anum_pg_synonym_synowner 3 +#define Anum_pg_synonym_synobjschema 4 +#define Anum_pg_synonym_synobjname 5 + +/* ---------------- + * initial contents of pg_synonym + * --------------- + */ + +/* + * function prototypes + */ +extern void CreateSynonym(CreateSynonymStmt *stmt); +extern void DropSynonym(DropSynonymStmt *stmt); +extern void AlterSynonymOwner(List *name, Oid newOwnerId); +extern void RemoveSynonymById(Oid synonymOid); +extern RangeVar* SearchReferencedObject(const char *synName, Oid synNamespace); +extern RangeVar* ReplaceReferencedObject(const RangeVar *relation); +extern char* CheckReferencedObject(Oid relOid, RangeVar *objVar, const char *synName); +extern Oid GetSynonymOid(const char *synName, Oid synNamespace, bool missing); +extern char* GetQualifiedSynonymName(Oid synOid, bool qualified = true); +extern void GetSynonymAndSchemaName(Oid synOid, char **synName_p, char **synSchema_p); + +#endif /* PG_SYNONYM_H */ + + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_tablespace.h postgresql-hll-2.14/include/catalog/pg_tablespace.h --- postgresql-hll-2.14_old/include/catalog/pg_tablespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_tablespace.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,85 @@ +/* ------------------------------------------------------------------------- + * + * pg_tablespace.h + * definition of the system "tablespace" relation (pg_tablespace) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_tablespace.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TABLESPACE_H +#define PG_TABLESPACE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_tablespace definition. cpp turns this into + * typedef struct FormData_pg_tablespace + * ---------------- + */ +#define TableSpaceRelationId 1213 +#define TableSpaceRelation_Rowtype_Id 11633 + +CATALOG(pg_tablespace,1213) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData spcname; /* tablespace name */ + Oid spcowner; /* owner of tablespace */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem spcacl[1]; /* access permissions */ + text spcoptions[1]; /* per-tablespace options */ + text spcmaxsize; /* tablespace max size */ + bool relative; /* relative location */ +#endif +} FormData_pg_tablespace; + +/* ---------------- + * Form_pg_tablespace corresponds to a pointer to a tuple with + * the format of pg_tablespace relation. + * ---------------- + */ +typedef FormData_pg_tablespace *Form_pg_tablespace; + +/* ---------------- + * compiler constants for pg_tablespace + * ---------------- + */ +#define Natts_pg_tablespace 6 +#define Anum_pg_tablespace_spcname 1 +#define Anum_pg_tablespace_spcowner 2 +#define Anum_pg_tablespace_spcacl 3 +#define Anum_pg_tablespace_spcoptions 4 +#define Anum_pg_tablespace_maxsize 5 +#define Anum_pg_tablespace_relative 6 + + +DATA(insert OID = 1663 (pg_default PGUID _null_ _null_ _null_ f)); +DATA(insert OID = 1664 (pg_global PGUID _null_ _null_ _null_ f)); + +#define DEFAULTTABLESPACE_OID 1663 +#define GLOBALTABLESPACE_OID 1664 + +#define MAX_TABLESPACE_LIMITED_STRING_LEN 21 + +#define TABLESPACE_OPTION_FILESYSTEM "filesystem" +#define TABLESPACE_OPTION_ADDRESS "address" +#define TABLESPACE_OPTION_CFGPATH "cfgpath" +#define TABLESPACE_OPTION_STOREPATH "storepath" +#define TABLESPACE_OPTION_SEQ_PAGE_COST "seq_page_cost" +#define TABLESPACE_OPTION_RANDOM_PAGE_COST "random_page_cost" + +#define DFS_TABLESPACE_SUBDIR "tablespace_secondary" +#define DFS_TABLESPACE_TEMPDIR_SUFFIX "pgsql_tmp" + + +#endif /* PG_TABLESPACE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_trigger.h postgresql-hll-2.14/include/catalog/pg_trigger.h --- postgresql-hll-2.14_old/include/catalog/pg_trigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_trigger.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,151 @@ + +/* ------------------------------------------------------------------------- + * + * pg_trigger.h + * definition of the system "trigger" relation (pg_trigger) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_trigger.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TRIGGER_H +#define PG_TRIGGER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_trigger definition. cpp turns this into + * typedef struct FormData_pg_trigger + * + * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid, + * tgdeferrable, and tginitdeferred are largely redundant with the referenced + * pg_constraint entry. However, it is possible for a non-deferrable trigger + * to be associated with a deferrable constraint. + * ---------------- + */ +#define TriggerRelationId 2620 +#define TriggerRelation_Rowtype_Id 11329 + +CATALOG(pg_trigger,2620) BKI_SCHEMA_MACRO +{ + Oid tgrelid; /* relation trigger is attached to */ + NameData tgname; /* trigger's name */ + Oid tgfoid; /* OID of function to be called */ + int2 tgtype; /* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT, + * ROW/STATEMENT; see below */ + char tgenabled; /* trigger's firing configuration WRT + * session_replication_role */ + bool tgisinternal; /* trigger is system-generated */ + Oid tgconstrrelid; /* constraint's FROM table, if any */ + Oid tgconstrindid; /* constraint's supporting index, if any */ + Oid tgconstraint; /* associated pg_constraint entry, if any */ + bool tgdeferrable; /* constraint trigger is deferrable */ + bool tginitdeferred; /* constraint trigger is deferred initially */ + int2 tgnargs; /* # of extra arguments in tgargs */ + + /* + * Variable-length fields start here, but we allow direct access to + * tgattr. Note: tgattr and tgargs must not be null. + */ + int2vector tgattr; /* column numbers, if trigger is on columns */ + +#ifdef CATALOG_VARLEN + bytea tgargs; /* first\000second\000tgnargs\000 */ + pg_node_tree tgqual; /* WHEN expression, or NULL if none */ + Oid tgowner; /* trigger owner's oid */ +#endif +} FormData_pg_trigger; + +/* ---------------- + * Form_pg_trigger corresponds to a pointer to a tuple with + * the format of pg_trigger relation. + * ---------------- + */ +typedef FormData_pg_trigger *Form_pg_trigger; + +/* ---------------- + * compiler constants for pg_trigger + * ---------------- + */ +#define Natts_pg_trigger 16 +#define Anum_pg_trigger_tgrelid 1 +#define Anum_pg_trigger_tgname 2 +#define Anum_pg_trigger_tgfoid 3 +#define Anum_pg_trigger_tgtype 4 +#define Anum_pg_trigger_tgenabled 5 +#define Anum_pg_trigger_tgisinternal 6 +#define Anum_pg_trigger_tgconstrrelid 7 +#define Anum_pg_trigger_tgconstrindid 8 +#define Anum_pg_trigger_tgconstraint 9 +#define Anum_pg_trigger_tgdeferrable 10 +#define Anum_pg_trigger_tginitdeferred 11 +#define Anum_pg_trigger_tgnargs 12 +#define Anum_pg_trigger_tgattr 13 +#define Anum_pg_trigger_tgargs 14 +#define Anum_pg_trigger_tgqual 15 +#define Anum_pg_trigger_tgowner 16 + + +/* Bits within tgtype */ +#define TRIGGER_TYPE_ROW (1 << 0) +#define TRIGGER_TYPE_BEFORE (1 << 1) +#define TRIGGER_TYPE_INSERT (1 << 2) +#define TRIGGER_TYPE_DELETE (1 << 3) +#define TRIGGER_TYPE_UPDATE (1 << 4) +#define TRIGGER_TYPE_TRUNCATE (1 << 5) +#define TRIGGER_TYPE_INSTEAD (1 << 6) + +#define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW) +#define TRIGGER_TYPE_STATEMENT 0 + +/* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */ +#define TRIGGER_TYPE_TIMING_MASK \ + (TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD) +#define TRIGGER_TYPE_AFTER 0 + +#define TRIGGER_TYPE_EVENT_MASK \ + (TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE) + +/* Macros for manipulating tgtype */ +#define TRIGGER_CLEAR_TYPE(type) ((type) = 0) + +#define TRIGGER_SETT_ROW(type) ((type) |= TRIGGER_TYPE_ROW) +#define TRIGGER_SETT_STATEMENT(type) ((type) |= TRIGGER_TYPE_STATEMENT) +#define TRIGGER_SETT_BEFORE(type) ((type) |= TRIGGER_TYPE_BEFORE) +#define TRIGGER_SETT_AFTER(type) ((type) |= TRIGGER_TYPE_AFTER) +#define TRIGGER_SETT_INSTEAD(type) ((type) |= TRIGGER_TYPE_INSTEAD) +#define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT) +#define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE) +#define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE) +#define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE) + +#define TRIGGER_FOR_ROW(type) (((uint32)(type)) & TRIGGER_TYPE_ROW) +#define TRIGGER_FOR_BEFORE(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE) +#define TRIGGER_FOR_AFTER(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER) +#define TRIGGER_FOR_INSTEAD(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD) +#define TRIGGER_FOR_INSERT(type) (((uint32)(type)) & TRIGGER_TYPE_INSERT) +#define TRIGGER_FOR_DELETE(type) (((uint32)(type)) & TRIGGER_TYPE_DELETE) +#define TRIGGER_FOR_UPDATE(type) (((uint32)(type)) & TRIGGER_TYPE_UPDATE) +#define TRIGGER_FOR_TRUNCATE(type) (((uint32)(type)) & TRIGGER_TYPE_TRUNCATE) + +/* + * Efficient macro for checking if tgtype matches a particular level + * (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE, + * TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT, + * TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE). Note + * that a tgtype can match more than one event, but only one level or timing. + */ +#define TRIGGER_TYPE_MATCHES(type, level, timing, event) \ + ((((uint32)type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | ((uint32)event))) == (((uint32)level) | ((uint32)timing) | ((uint32)event))) + +#endif /* PG_TRIGGER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_ts_config.h postgresql-hll-2.14/include/catalog/pg_ts_config.h --- postgresql-hll-2.14_old/include/catalog/pg_ts_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_ts_config.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_config.h + * definition of configuration of tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_config.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_CONFIG_H +#define PG_TS_CONFIG_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_config definition. cpp turns this into + * typedef struct FormData_pg_ts_config + * ---------------- + */ +#define TSConfigRelationId 3602 +#define TSConfigRelation_Rowtype_Id 11637 + +CATALOG(pg_ts_config,3602) BKI_SCHEMA_MACRO +{ + NameData cfgname; /* name of configuration */ + Oid cfgnamespace; /* name space */ + Oid cfgowner; /* owner */ + Oid cfgparser; /* OID of parser (in pg_ts_parser) */ + text cfoptions[1]; /* configuration options */ +} FormData_pg_ts_config; + +typedef FormData_pg_ts_config *Form_pg_ts_config; + +/* ---------------- + * compiler constants for pg_ts_config + * ---------------- + */ +#define Natts_pg_ts_config 5 +#define Anum_pg_ts_config_cfgname 1 +#define Anum_pg_ts_config_cfgnamespace 2 +#define Anum_pg_ts_config_cfgowner 3 +#define Anum_pg_ts_config_cfgparser 4 +#define Anum_pg_ts_config_cfoptions 5 + +/* ---------------- + * initial contents of pg_ts_config + * ---------------- + */ +DATA(insert OID = 3748 ( "simple" PGNSP PGUID 3722 _null_)); +DESCR("simple configuration"); +DATA(insert OID = 3791 ( "ngram" PGNSP PGUID 3789 _null_)); +DESCR("ngram configuration"); +DATA(insert OID = 3792 ( "zhparser" PGNSP PGUID 3790 _null_)); +DESCR("zhparser configuration"); +DATA(insert OID = 3793 ( "pound" PGNSP PGUID 3801 _null_)); +DESCR("pound configuration"); + + +#endif /* PG_TS_CONFIG_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_ts_config_map.h postgresql-hll-2.14/include/catalog/pg_ts_config_map.h --- postgresql-hll-2.14_old/include/catalog/pg_ts_config_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_ts_config_map.h 2020-12-12 17:06:43.090346012 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_config_map.h + * definition of token mappings for configurations of tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_config_map.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_CONFIG_MAP_H +#define PG_TS_CONFIG_MAP_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_config_map definition. cpp turns this into + * typedef struct FormData_pg_ts_config_map + * ---------------- + */ +#define TSConfigMapRelationId 3603 +#define TSConfigMapRelation_Rowtype_Id 11638 + +CATALOG(pg_ts_config_map,3603) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid mapcfg; /* OID of configuration owning this entry */ + int4 maptokentype; /* token type from parser */ + int4 mapseqno; /* order in which to consult dictionaries */ + Oid mapdict; /* dictionary to consult */ +} FormData_pg_ts_config_map; + +typedef FormData_pg_ts_config_map *Form_pg_ts_config_map; + +/* ---------------- + * compiler constants for pg_ts_config_map + * ---------------- + */ +#define Natts_pg_ts_config_map 4 +#define Anum_pg_ts_config_map_mapcfg 1 +#define Anum_pg_ts_config_map_maptokentype 2 +#define Anum_pg_ts_config_map_mapseqno 3 +#define Anum_pg_ts_config_map_mapdict 4 + +/* ---------------- + * initial contents of pg_ts_config_map + * ---------------- + */ +DATA(insert (3748 1 1 3765)); +DATA(insert (3748 2 1 3765)); +DATA(insert (3748 3 1 3765)); +DATA(insert (3748 4 1 3765)); +DATA(insert (3748 5 1 3765)); +DATA(insert (3748 6 1 3765)); +DATA(insert (3748 7 1 3765)); +DATA(insert (3748 8 1 3765)); +DATA(insert (3748 9 1 3765)); +DATA(insert (3748 10 1 3765)); +DATA(insert (3748 11 1 3765)); +DATA(insert (3748 15 1 3765)); +DATA(insert (3748 16 1 3765)); +DATA(insert (3748 17 1 3765)); +DATA(insert (3748 18 1 3765)); +DATA(insert (3748 19 1 3765)); +DATA(insert (3748 20 1 3765)); +DATA(insert (3748 21 1 3765)); +DATA(insert (3748 22 1 3765)); + +#endif /* PG_TS_CONFIG_MAP_H */ + + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_ts_dict.h postgresql-hll-2.14/include/catalog/pg_ts_dict.h --- postgresql-hll-2.14_old/include/catalog/pg_ts_dict.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_ts_dict.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,69 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_dict.h + * definition of dictionaries for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_dict.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_DICT_H +#define PG_TS_DICT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_dict definition. cpp turns this into + * typedef struct FormData_pg_ts_dict + * ---------------- + */ +#define TSDictionaryRelationId 3600 +#define TSDictionaryRelation_Rowtype_Id 11639 + +CATALOG(pg_ts_dict,3600) BKI_SCHEMA_MACRO +{ + NameData dictname; /* dictionary name */ + Oid dictnamespace; /* name space */ + Oid dictowner; /* owner */ + Oid dicttemplate; /* dictionary's template */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text dictinitoption; /* options passed to dict_init() */ +#endif +} FormData_pg_ts_dict; + +typedef FormData_pg_ts_dict *Form_pg_ts_dict; + +/* ---------------- + * compiler constants for pg_ts_dict + * ---------------- + */ +#define Natts_pg_ts_dict 5 +#define Anum_pg_ts_dict_dictname 1 +#define Anum_pg_ts_dict_dictnamespace 2 +#define Anum_pg_ts_dict_dictowner 3 +#define Anum_pg_ts_dict_dicttemplate 4 +#define Anum_pg_ts_dict_dictinitoption 5 + +/* ---------------- + * initial contents of pg_ts_dict + * ---------------- + */ + +DATA(insert OID = 3765 ( "simple" PGNSP PGUID 3727 _null_)); +DESCR("simple dictionary: just lower case and check for stopword"); + +#endif /* PG_TS_DICT_H */ + + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_ts_parser.h postgresql-hll-2.14/include/catalog/pg_ts_parser.h --- postgresql-hll-2.14_old/include/catalog/pg_ts_parser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_ts_parser.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_parser.h + * definition of parsers for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_parser.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_PARSER_H +#define PG_TS_PARSER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_parser definition. cpp turns this into + * typedef struct FormData_pg_ts_parser + * ---------------- + */ +#define TSParserRelationId 3601 +#define TSParserRelation_Rowtype_Id 11640 + +CATALOG(pg_ts_parser,3601) BKI_SCHEMA_MACRO +{ + NameData prsname; /* parser's name */ + Oid prsnamespace; /* name space */ + regproc prsstart; /* init parsing session */ + regproc prstoken; /* return next token */ + regproc prsend; /* finalize parsing session */ + regproc prsheadline; /* return data for headline creation */ + regproc prslextype; /* return descriptions of lexeme's types */ +} FormData_pg_ts_parser; + +typedef FormData_pg_ts_parser *Form_pg_ts_parser; + +/* ---------------- + * compiler constants for pg_ts_parser + * ---------------- + */ +#define Natts_pg_ts_parser 7 +#define Anum_pg_ts_parser_prsname 1 +#define Anum_pg_ts_parser_prsnamespace 2 +#define Anum_pg_ts_parser_prsstart 3 +#define Anum_pg_ts_parser_prstoken 4 +#define Anum_pg_ts_parser_prsend 5 +#define Anum_pg_ts_parser_prsheadline 6 +#define Anum_pg_ts_parser_prslextype 7 + +/* ---------------- + * initial contents of pg_ts_parser + * ---------------- + */ + +DATA(insert OID = 3722 ( "default" PGNSP prsd_start prsd_nexttoken prsd_end prsd_headline prsd_lextype )); +DESCR("default word parser"); + +DATA(insert OID = 3789 ( "ngram" PGNSP ngram_start ngram_nexttoken ngram_end prsd_headline ngram_lextype )); +DESCR("ngram chinese word parser"); +#define NGRAM_PARSER 3789 + +DATA(insert OID = 3790 ( "zhparser" PGNSP zhprs_start zhprs_getlexeme zhprs_end prsd_headline zhprs_lextype )); +DESCR("zhparser chinese word parser"); +#define ZHPARSER_PARSER 3790 + +DATA(insert OID = 3801 ( "pound" PGNSP pound_start pound_nexttoken pound_end prsd_headline pound_lextype )); +DESCR(" pound split parser"); +#define POUND_PARSER 3801 + +#endif /* PG_TS_PARSER_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_ts_template.h postgresql-hll-2.14/include/catalog/pg_ts_template.h --- postgresql-hll-2.14_old/include/catalog/pg_ts_template.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_ts_template.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_template.h + * definition of dictionary templates for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_template.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_TEMPLATE_H +#define PG_TS_TEMPLATE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_template definition. cpp turns this into + * typedef struct FormData_pg_ts_template + * ---------------- + */ +#define TSTemplateRelationId 3764 +#define TSTemplateRelation_Rowtype_Id 11641 + +CATALOG(pg_ts_template,3764) BKI_SCHEMA_MACRO +{ + NameData tmplname; /* template name */ + Oid tmplnamespace; /* name space */ + regproc tmplinit; /* initialization method of dict (may be 0) */ + regproc tmpllexize; /* base method of dictionary */ +} FormData_pg_ts_template; + +typedef FormData_pg_ts_template *Form_pg_ts_template; + +/* ---------------- + * compiler constants for pg_ts_template + * ---------------- + */ +#define Natts_pg_ts_template 4 +#define Anum_pg_ts_template_tmplname 1 +#define Anum_pg_ts_template_tmplnamespace 2 +#define Anum_pg_ts_template_tmplinit 3 +#define Anum_pg_ts_template_tmpllexize 4 + +/* ---------------- + * initial contents of pg_ts_template + * ---------------- + */ + +DATA(insert OID = 3727 ( "simple" PGNSP dsimple_init dsimple_lexize )); +DESCR("simple dictionary: just lower case and check for stopword"); +DATA(insert OID = 3730 ( "synonym" PGNSP dsynonym_init dsynonym_lexize )); +DESCR("synonym dictionary: replace word by its synonym"); +#define TSTemplateSynonymId 3730 +DATA(insert OID = 3733 ( "ispell" PGNSP dispell_init dispell_lexize )); +DESCR("ispell dictionary"); +#define TSTemplateIspellId 3733 +DATA(insert OID = 3742 ( "thesaurus" PGNSP thesaurus_init thesaurus_lexize )); +DESCR("thesaurus dictionary: phrase by phrase substitution"); +#define TSTemplateThesaurusId 3742 + +#endif /* PG_TS_TEMPLATE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_type_fn.h postgresql-hll-2.14/include/catalog/pg_type_fn.h --- postgresql-hll-2.14_old/include/catalog/pg_type_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_type_fn.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_type_fn.h + * prototypes for functions in catalog/pg_type.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_type_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TYPE_FN_H +#define PG_TYPE_FN_H + +#include "nodes/nodes.h" + + +extern Oid TypeShellMake(const char *typname, + Oid typeNamespace, + Oid ownerId); + +extern Oid TypeCreate(Oid newTypeOid, + const char *typname, + Oid typeNamespace, + Oid relationOid, + char relationKind, + Oid ownerId, + int16 internalSize, + char typeType, + char typeCategory, + bool typePreferred, + char typDelim, + Oid inputProcedure, + Oid outputProcedure, + Oid receiveProcedure, + Oid sendProcedure, + Oid typmodinProcedure, + Oid typmodoutProcedure, + Oid analyzeProcedure, + Oid elementType, + bool isImplicitArray, + Oid arrayType, + Oid baseType, + const char *defaultTypeValue, + char *defaultTypeBin, + bool passedByValue, + char alignment, + char storage, + int32 typeMod, + int32 typNDims, + bool typeNotNull, + Oid typeCollation); + +extern void GenerateTypeDependencies(Oid typeNamespace, + Oid typeObjectId, + Oid relationOid, + char relationKind, + Oid owner, + Oid inputProcedure, + Oid outputProcedure, + Oid receiveProcedure, + Oid sendProcedure, + Oid typmodinProcedure, + Oid typmodoutProcedure, + Oid analyzeProcedure, + Oid elementType, + bool isImplicitArray, + Oid baseType, + Oid typeCollation, + Node *defaultExpr, + bool rebuild); + +extern void RenameTypeInternal(Oid typeOid, + const char *newTypeName, + Oid typeNamespace); + +extern char *makeArrayTypeName(const char *typname, Oid typeNamespace); + +extern bool moveArrayTypeName(Oid typeOid, + const char *typname, + Oid typeNamespace); + +#endif /* PG_TYPE_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_type.h postgresql-hll-2.14/include/catalog/pg_type.h --- postgresql-hll-2.14_old/include/catalog/pg_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_type.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,798 @@ +/* ------------------------------------------------------------------------- + * + * pg_type.h + * definition of the system "type" relation (pg_type) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_type.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TYPE_H +#define PG_TYPE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_type definition. cpp turns this into + * typedef struct FormData_pg_type + * + * Some of the values in a pg_type instance are copied into + * pg_attribute instances. Some parts of Postgres use the pg_type copy, + * while others use the pg_attribute copy, so they must match. + * See struct FormData_pg_attribute for details. + * ---------------- + */ +#define TypeRelationId 1247 +#define TypeRelation_Rowtype_Id 71 + +CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71) BKI_SCHEMA_MACRO +{ + NameData typname; /* type name */ + Oid typnamespace; /* OID of namespace containing this type */ + Oid typowner; /* type owner */ + + /* + * For a fixed-size type, typlen is the number of bytes we use to + * represent a value of this type, e.g. 4 for an int4. But for a + * variable-length type, typlen is negative. We use -1 to indicate a + * "varlena" type (one that has a length word), -2 to indicate a + * null-terminated C string. + */ + int2 typlen; + + /* + * typbyval determines whether internal Postgres routines pass a value of + * this type by value or by reference. typbyval had better be FALSE if + * the length is not 1, 2, or 4 (or 8 on 8-byte-Datum machines). + * Variable-length types are always passed by reference. Note that + * typbyval can be false even if the length would allow pass-by-value; + * this is currently true for type float4, for example. + */ + bool typbyval; + + /* + * typtype is 'b' for a base type, 'c' for a composite type (e.g., a + * table's rowtype), 'd' for a domain, 'e' for an enum type, 'p' for a + * pseudo-type, or 'r' for a range type. (Use the TYPTYPE macros below.) + * + * If typtype is 'c', typrelid is the OID of the class' entry in pg_class. + */ + char typtype; + + /* + * typcategory and typispreferred help the parser distinguish preferred + * and non-preferred coercions. The category can be any single ASCII + * character (but not \0). The categories used for built-in types are + * identified by the TYPCATEGORY macros below. + */ + char typcategory; /* arbitrary type classification */ + + bool typispreferred; /* is type "preferred" within its category? */ + + /* + * If typisdefined is false, the entry is only a placeholder (forward + * reference). We know the type name, but not yet anything else about it. + */ + bool typisdefined; + + char typdelim; /* delimiter for arrays of this type */ + + Oid typrelid; /* 0 if not a composite type */ + + /* + * If typelem is not 0 then it identifies another row in pg_type. The + * current type can then be subscripted like an array yielding values of + * type typelem. A non-zero typelem does not guarantee this type to be a + * "real" array type; some ordinary fixed-length types can also be + * subscripted (e.g., name, point). Variable-length types can *not* be + * turned into pseudo-arrays like that. Hence, the way to determine + * whether a type is a "true" array type is if: + * + * typelem != 0 and typlen == -1. + */ + Oid typelem; + + /* + * If there is a "true" array type having this type as element type, + * typarray links to it. Zero if no associated "true" array type. + */ + Oid typarray; + + /* + * I/O conversion procedures for the datatype. + */ + regproc typinput; /* text format (required) */ + regproc typoutput; + regproc typreceive; /* binary format (optional) */ + regproc typsend; + + /* + * I/O functions for optional type modifiers. + */ + regproc typmodin; + regproc typmodout; + + /* + * Custom ANALYZE procedure for the datatype (0 selects the default). + */ + regproc typanalyze; + + /* ---------------- + * typalign is the alignment required when storing a value of this + * type. It applies to storage on disk as well as most + * representations of the value inside Postgres. When multiple values + * are stored consecutively, such as in the representation of a + * complete row on disk, padding is inserted before a datum of this + * type so that it begins on the specified boundary. The alignment + * reference is the beginning of the first datum in the sequence. + * + * 'c' = CHAR alignment, ie no alignment needed. + * 's' = SHORT alignment (2 bytes on most machines). + * 'i' = INT alignment (4 bytes on most machines). + * 'd' = DOUBLE alignment (8 bytes on many machines, but by no means all). + * + * See include/access/tupmacs.h for the macros that compute these + * alignment requirements. Note also that we allow the nominal alignment + * to be violated when storing "packed" varlenas; the TOAST mechanism + * takes care of hiding that from most code. + * + * NOTE: for types used in system tables, it is critical that the + * size and alignment defined in pg_type agree with the way that the + * compiler will lay out the field in a struct representing a table row. + * ---------------- + */ + char typalign; + + /* ---------------- + * typstorage tells if the type is prepared for toasting and what + * the default strategy for attributes of this type should be. + * + * 'p' PLAIN type not prepared for toasting + * 'e' EXTERNAL external storage possible, don't try to compress + * 'x' EXTENDED try to compress and store external if required + * 'm' MAIN like 'x' but try to keep in main tuple + * ---------------- + */ + char typstorage; + + /* + * This flag represents a "NOT NULL" constraint against this datatype. + * + * If true, the attnotnull column for a corresponding table column using + * this datatype will always enforce the NOT NULL constraint. + * + * Used primarily for domain types. + */ + bool typnotnull; + + /* + * Domains use typbasetype to show the base (or domain) type that the + * domain is based on. Zero if the type is not a domain. + */ + Oid typbasetype; + + /* + * Domains use typtypmod to record the typmod to be applied to their base + * type (-1 if base type does not use a typmod). -1 if this type is not a + * domain. + */ + int4 typtypmod; + + /* + * typndims is the declared number of dimensions for an array domain type + * (i.e., typbasetype is an array type). Otherwise zero. + */ + int4 typndims; + + /* + * Collation: 0 if type cannot use collations, DEFAULT_COLLATION_OID for + * collatable base types, possibly other OID for domains + */ + Oid typcollation; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + + /* + * If typdefaultbin is not NULL, it is the nodeToString representation of + * a default expression for the type. Currently this is only used for + * domains. + */ + pg_node_tree typdefaultbin; + + /* + * typdefault is NULL if the type has no associated default value. If + * typdefaultbin is not NULL, typdefault must contain a human-readable + * version of the default expression represented by typdefaultbin. If + * typdefaultbin is NULL and typdefault is not, then typdefault is the + * external representation of the type's default value, which may be fed + * to the type's input converter to produce a constant. + */ + text typdefault; + + /* + * Access permissions + */ + aclitem typacl[1]; +#endif +} FormData_pg_type; + +/* ---------------- + * Form_pg_type corresponds to a pointer to a row with + * the format of pg_type relation. + * ---------------- + */ +typedef FormData_pg_type *Form_pg_type; + +/* ---------------- + * compiler constants for pg_type + * ---------------- + */ +#define Natts_pg_type 30 +#define Anum_pg_type_typname 1 +#define Anum_pg_type_typnamespace 2 +#define Anum_pg_type_typowner 3 +#define Anum_pg_type_typlen 4 +#define Anum_pg_type_typbyval 5 +#define Anum_pg_type_typtype 6 +#define Anum_pg_type_typcategory 7 +#define Anum_pg_type_typispreferred 8 +#define Anum_pg_type_typisdefined 9 +#define Anum_pg_type_typdelim 10 +#define Anum_pg_type_typrelid 11 +#define Anum_pg_type_typelem 12 +#define Anum_pg_type_typarray 13 +#define Anum_pg_type_typinput 14 +#define Anum_pg_type_typoutput 15 +#define Anum_pg_type_typreceive 16 +#define Anum_pg_type_typsend 17 +#define Anum_pg_type_typmodin 18 +#define Anum_pg_type_typmodout 19 +#define Anum_pg_type_typanalyze 20 +#define Anum_pg_type_typalign 21 +#define Anum_pg_type_typstorage 22 +#define Anum_pg_type_typnotnull 23 +#define Anum_pg_type_typbasetype 24 +#define Anum_pg_type_typtypmod 25 +#define Anum_pg_type_typndims 26 +#define Anum_pg_type_typcollation 27 +#define Anum_pg_type_typdefaultbin 28 +#define Anum_pg_type_typdefault 29 +#define Anum_pg_type_typacl 30 + + +/* ---------------- + * initial contents of pg_type + * ---------------- + */ + +/* + * Keep the following ordered by OID so that later changes can be made more + * easily. + * + * For types used in the system catalogs, make sure the values here match + * TypInfo[] in bootstrap.c. + */ + +/* OIDS 1 - 99 */ +DATA(insert OID = 16 ( bool PGNSP PGUID 1 t b B t t \054 0 0 1000 boolin boolout boolrecv boolsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("boolean, 'true'/'false'"); +#define BOOLOID 16 + +DATA(insert OID = 17 ( bytea PGNSP PGUID -1 f b U f t \054 0 0 1001 byteain byteaout bytearecv byteasend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length string, binary values escaped"); +#define BYTEAOID 17 + +DATA(insert OID = 18 ( char PGNSP PGUID 1 t b S f t \054 0 0 1002 charin charout charrecv charsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("single character"); +#define CHAROID 18 + +DATA(insert OID = 19 ( name PGNSP PGUID NAMEDATALEN f b S f t \054 0 18 1003 namein nameout namerecv namesend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("63-byte type for storing system identifiers"); +#define NAMEOID 19 + +DATA(insert OID = 20 ( int8 PGNSP PGUID 8 FLOAT8PASSBYVAL b N f t \054 0 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("~18 digit integer, 8-byte storage"); +#define INT8OID 20 + +DATA(insert OID = 21 ( int2 PGNSP PGUID 2 t b N f t \054 0 0 1005 int2in int2out int2recv int2send - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("-32 thousand to 32 thousand, 2-byte storage"); +#define INT2OID 21 + +DATA(insert OID = 5545 ( int1 PGNSP PGUID 1 t b N f t \054 0 0 5546 int1in int1out int1recv int1send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("0 to 255, 1-byte storage"); +#define INT1OID 5545 +DATA(insert OID = 22 ( int2vector PGNSP PGUID -1 f b A f t \054 0 21 1006 int2vectorin int2vectorout int2vectorrecv int2vectorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of int2, used in system tables"); +#define INT2VECTOROID 22 + +DATA(insert OID = 23 ( int4 PGNSP PGUID 4 t b N f t \054 0 0 1007 int4in int4out int4recv int4send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("-2 billion to 2 billion integer, 4-byte storage"); +#define INT4OID 23 + +DATA(insert OID = 24 ( regproc PGNSP PGUID 4 t b N f t \054 0 0 1008 regprocin regprocout regprocrecv regprocsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered procedure"); +#define REGPROCOID 24 + +DATA(insert OID = 25 ( text PGNSP PGUID -1 f b S t t \054 0 0 1009 textin textout textrecv textsend - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("variable-length string, no limit specified"); +#define TEXTOID 25 + +DATA(insert OID = 26 ( oid PGNSP PGUID 4 t b N t t \054 0 0 1028 oidin oidout oidrecv oidsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("object identifier(oid), maximum 4 billion"); +#define OIDOID 26 + +DATA(insert OID = 27 ( tid PGNSP PGUID 6 f b U f t \054 0 0 1010 tidin tidout tidrecv tidsend - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("(block, offset), physical location of tuple"); +#define TIDOID 27 +#define TID_TYPE_LEN 6 + +DATA(insert OID = 28 ( xid PGNSP PGUID 8 FLOAT8PASSBYVAL b U f t \054 0 0 1011 xidin xidout xidrecv xidsend - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("transaction id"); +#define XIDOID 28 + +DATA(insert OID = 31 ( xid32 PGNSP PGUID 4 t b U f t \054 0 0 1029 xidin4 xidout4 xidrecv4 xidsend4 - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("short transaction id"); +#define SHORTXIDOID 31 + +DATA(insert OID = 29 ( cid PGNSP PGUID 4 t b U f t \054 0 0 1012 cidin cidout cidrecv cidsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("command identifier type, sequence in transaction id"); +#define CIDOID 29 + +DATA(insert OID = 30 ( oidvector PGNSP PGUID -1 f b A f t \054 0 26 1013 oidvectorin oidvectorout oidvectorrecv oidvectorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of oids, used in system tables"); +#define OIDVECTOROID 30 + +DATA(insert OID = 32 ( oidvector_extend PGNSP PGUID -1 f b A f t \054 0 26 1013 oidvectorin_extend oidvectorout_extend oidvectorrecv_extend oidvectorsend_extend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of oids, used in system tables and support toast storage"); +#define OIDVECTOREXTENDOID 32 + +DATA(insert OID = 86 ( raw PGNSP PGUID -1 f b U f t \054 0 0 87 rawin rawout rawrecv rawsend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length string, binary values escaped"); +#define RAWOID 86 +DATA(insert OID = 87 ( _raw PGNSP PGUID -1 f b A f t \054 0 86 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 88 ( blob PGNSP PGUID -1 f b U f t \054 0 0 3201 rawin rawout bytearecv byteasend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BLOBOID 88 +DATA(insert OID = 3201 ( _blob PGNSP PGUID -1 f b A f t \054 0 88 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 90 ( clob PGNSP PGUID -1 f b S t t \054 0 0 3202 textin textout textrecv textsend - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define CLOBOID 90 +DATA(insert OID = 3202 ( _clob PGNSP PGUID -1 f b A f t \054 0 90 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); + +/* hand-built rowtype entries for bootstrapped catalogs */ +/* NB: OIDs assigned here must match the BKI_ROWTYPE_OID declarations */ + +DATA(insert OID = 71 ( pg_type PGNSP PGUID -1 f c C f t \054 1247 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 75 ( pg_attribute PGNSP PGUID -1 f c C f t \054 1249 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 81 ( pg_proc PGNSP PGUID -1 f c C f t \054 1255 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 83 ( pg_class PGNSP PGUID -1 f c C f t \054 1259 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* OIDS 100 - 199 */ +DATA(insert OID = 114 ( json PGNSP PGUID -1 f b U f t \054 0 0 199 json_in json_out json_recv json_send - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define JSONOID 114 +DATA(insert OID = 142 ( xml PGNSP PGUID -1 f b U f t \054 0 0 143 xml_in xml_out xml_recv xml_send - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("XML content"); +#define XMLOID 142 +DATA(insert OID = 143 ( _xml PGNSP PGUID -1 f b A f t \054 0 142 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 199 ( _json PGNSP PGUID -1 f b A f t \054 0 114 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 194 ( pg_node_tree PGNSP PGUID -1 f b S f t \054 0 0 0 pg_node_tree_in pg_node_tree_out pg_node_tree_recv pg_node_tree_send - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("string representing an internal node tree"); +#define PGNODETREEOID 194 + +/* OIDS 200 - 299 */ + +DATA(insert OID = 210 ( smgr PGNSP PGUID 2 t b U f t \054 0 0 0 smgrin smgrout - - - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("storage manager"); +#define SMGROID 210 + +/* OIDS 300 - 399 */ + +/* OIDS 400 - 499 */ + +/* OIDS 500 - 599 */ + +/* OIDS 600 - 699 */ +DATA(insert OID = 600 ( point PGNSP PGUID 16 f b G f t \054 0 701 1017 point_in point_out point_recv point_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric point '(x, y)'"); +#define POINTOID 600 +DATA(insert OID = 601 ( lseg PGNSP PGUID 32 f b G f t \054 0 600 1018 lseg_in lseg_out lseg_recv lseg_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric line segment '(pt1,pt2)'"); +#define LSEGOID 601 +DATA(insert OID = 602 ( path PGNSP PGUID -1 f b G f t \054 0 0 1019 path_in path_out path_recv path_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric path '(pt1,...)'"); +#define PATHOID 602 +DATA(insert OID = 603 ( box PGNSP PGUID 32 f b G f t \073 0 600 1020 box_in box_out box_recv box_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric box '(lower left,upper right)'"); +#define BOXOID 603 +DATA(insert OID = 604 ( polygon PGNSP PGUID -1 f b G f t \054 0 0 1027 poly_in poly_out poly_recv poly_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric polygon '(pt1,...)'"); +#define POLYGONOID 604 + +DATA(insert OID = 628 ( line PGNSP PGUID 32 f b G f t \054 0 701 629 line_in line_out line_recv line_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric line (not implemented)"); +#define LINEOID 628 +DATA(insert OID = 629 ( _line PGNSP PGUID -1 f b A f t \054 0 628 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR(""); + +/* OIDS 700 - 799 */ + +DATA(insert OID = 700 ( float4 PGNSP PGUID 4 FLOAT4PASSBYVAL b N f t \054 0 0 1021 float4in float4out float4recv float4send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("single-precision floating point number, 4-byte storage"); +#define FLOAT4OID 700 +DATA(insert OID = 701 ( float8 PGNSP PGUID 8 FLOAT8PASSBYVAL b N t t \054 0 0 1022 float8in float8out float8recv float8send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("double-precision floating point number, 8-byte storage"); +#define FLOAT8OID 701 +DATA(insert OID = 702 ( abstime PGNSP PGUID 4 t b D f t \054 0 0 1023 abstimein abstimeout abstimerecv abstimesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("absolute, limited-range date and time (Unix system time)"); +#define ABSTIMEOID 702 +DATA(insert OID = 703 ( reltime PGNSP PGUID 4 t b T f t \054 0 0 1024 reltimein reltimeout reltimerecv reltimesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("relative, limited-range time interval (Unix delta time)"); +#define RELTIMEOID 703 +DATA(insert OID = 704 ( tinterval PGNSP PGUID 12 f b T f t \054 0 0 1025 tintervalin tintervalout tintervalrecv tintervalsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("(abstime,abstime), time interval"); +#define TINTERVALOID 704 +DATA(insert OID = 705 ( unknown PGNSP PGUID -2 f b X f t \054 0 0 0 unknownin unknownout unknownrecv unknownsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR(""); +#define UNKNOWNOID 705 + +DATA(insert OID = 718 ( circle PGNSP PGUID 24 f b G f t \054 0 0 719 circle_in circle_out circle_recv circle_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric circle '(center,radius)'"); +#define CIRCLEOID 718 +DATA(insert OID = 719 ( _circle PGNSP PGUID -1 f b A f t \054 0 718 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 790 ( money PGNSP PGUID 8 FLOAT8PASSBYVAL b N f t \054 0 0 791 cash_in cash_out cash_recv cash_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("monetary amounts, $d,ddd.cc"); +#define CASHOID 790 +DATA(insert OID = 791 ( _money PGNSP PGUID -1 f b A f t \054 0 790 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CASHARRAYOID 791 + +/* OIDS 800 - 899 */ +DATA(insert OID = 829 ( macaddr PGNSP PGUID 6 f b U f t \054 0 0 1040 macaddr_in macaddr_out macaddr_recv macaddr_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("XX:XX:XX:XX:XX:XX, MAC address"); +#define MACADDROID 829 +DATA(insert OID = 869 ( inet PGNSP PGUID -1 f b I t t \054 0 0 1041 inet_in inet_out inet_recv inet_send - - - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("IP address/netmask, host address, netmask optional"); +#define INETOID 869 +DATA(insert OID = 650 ( cidr PGNSP PGUID -1 f b I f t \054 0 0 651 cidr_in cidr_out cidr_recv cidr_send - - - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("network IP address/netmask, network address"); +#define CIDROID 650 + +/* OIDS 900 - 999 */ + +/* OIDS 1000 - 1099 */ +DATA(insert OID = 1000 ( _bool PGNSP PGUID -1 f b A f t \054 0 16 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BOOLARRAYOID 1000 +DATA(insert OID = 1001 ( _bytea PGNSP PGUID -1 f b A f t \054 0 17 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BYTEARRAYOID 1001 +DATA(insert OID = 1002 ( _char PGNSP PGUID -1 f b A f t \054 0 18 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CHARARRAYOID 1002 +DATA(insert OID = 1003 ( _name PGNSP PGUID -1 f b A f t \054 0 19 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define NAMEARRAYOID 1003 +DATA(insert OID = 1005 ( _int2 PGNSP PGUID -1 f b A f t \054 0 21 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT2ARRAYOID 1005 +DATA(insert OID = 5546 ( _int1 PGNSP PGUID -1 f b A f t \054 0 5545 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT1ARRAYOID 5546 +DATA(insert OID = 1006 ( _int2vector PGNSP PGUID -1 f b A f t \054 0 22 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1007 ( _int4 PGNSP PGUID -1 f b A f t \054 0 23 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT4ARRAYOID 1007 +DATA(insert OID = 1008 ( _regproc PGNSP PGUID -1 f b A f t \054 0 24 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1009 ( _text PGNSP PGUID -1 f b A f t \054 0 25 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define TEXTARRAYOID 1009 +DATA(insert OID = 1028 ( _oid PGNSP PGUID -1 f b A f t \054 0 26 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1010 ( _tid PGNSP PGUID -1 f b A f t \054 0 27 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1011 ( _xid PGNSP PGUID -1 f b A f t \054 0 28 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1029 ( _xid32 PGNSP PGUID -1 f b A f t \054 0 31 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1012 ( _cid PGNSP PGUID -1 f b A f t \054 0 29 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1013 ( _oidvector PGNSP PGUID -1 f b A f t \054 0 30 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1014 ( _bpchar PGNSP PGUID -1 f b A f t \054 0 1042 0 array_in array_out array_recv array_send bpchartypmodin bpchartypmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define BPCHARARRAYOID 1014 +DATA(insert OID = 1015 ( _varchar PGNSP PGUID -1 f b A f t \054 0 1043 0 array_in array_out array_recv array_send varchartypmodin varchartypmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define VARCHARARRAYOID 1015 +DATA(insert OID = 1016 ( _int8 PGNSP PGUID -1 f b A f t \054 0 20 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT8ARRAYOID 1016 +DATA(insert OID = 1017 ( _point PGNSP PGUID -1 f b A f t \054 0 600 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1018 ( _lseg PGNSP PGUID -1 f b A f t \054 0 601 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1019 ( _path PGNSP PGUID -1 f b A f t \054 0 602 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1020 ( _box PGNSP PGUID -1 f b A f t \073 0 603 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1021 ( _float4 PGNSP PGUID -1 f b A f t \054 0 700 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define FLOAT4ARRAYOID 1021 +DATA(insert OID = 1022 ( _float8 PGNSP PGUID -1 f b A f t \054 0 701 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define FLOAT8ARRAYOID 1022 +DATA(insert OID = 1023 ( _abstime PGNSP PGUID -1 f b A f t \054 0 702 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ABSTIMEARRAYOID 1023 +DATA(insert OID = 1024 ( _reltime PGNSP PGUID -1 f b A f t \054 0 703 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RELTIMEARRAYOID 1024 +DATA(insert OID = 1025 ( _tinterval PGNSP PGUID -1 f b A f t \054 0 704 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYTINTERVALOID 1025 +DATA(insert OID = 1027 ( _polygon PGNSP PGUID -1 f b A f t \054 0 604 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1033 ( aclitem PGNSP PGUID 12 f b U f t \054 0 0 1034 aclitemin aclitemout - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("access control list"); +#define ACLITEMOID 1033 +DATA(insert OID = 1034 ( _aclitem PGNSP PGUID -1 f b A f t \054 0 1033 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ACLITEMARRAYOID 1034 +DATA(insert OID = 1040 ( _macaddr PGNSP PGUID -1 f b A f t \054 0 829 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1041 ( _inet PGNSP PGUID -1 f b A f t \054 0 869 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INETARRAYOID 1041 +DATA(insert OID = 651 ( _cidr PGNSP PGUID -1 f b A f t \054 0 650 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CIDRARRAYOID 651 +DATA(insert OID = 1263 ( _cstring PGNSP PGUID -1 f b A f t \054 0 2275 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CSTRINGARRAYOID 1263 + +DATA(insert OID = 1042 ( bpchar PGNSP PGUID -1 f b S f t \054 0 0 1014 bpcharin bpcharout bpcharrecv bpcharsend bpchartypmodin bpchartypmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("char(length), blank-padded string, fixed storage length"); +#define BPCHAROID 1042 +DATA(insert OID = 1043 ( varchar PGNSP PGUID -1 f b S f t \054 0 0 1015 varcharin varcharout varcharrecv varcharsend varchartypmodin varchartypmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("varchar(length), non-blank-padded string, variable storage length"); +#define VARCHAROID 1043 + +DATA(insert OID = 3969 ( nvarchar2 PGNSP PGUID -1 f b S f t \054 0 0 3968 nvarchar2in nvarchar2out nvarchar2recv nvarchar2send nvarchar2typmodin nvarchar2typmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("nvarchar2(length), non-blank-padded string, variable storage length"); +#define NVARCHAR2OID 3969 +DATA(insert OID = 3968 ( _nvarchar2 PGNSP PGUID -1 f b A f t \054 0 3969 0 array_in array_out array_recv array_send nvarchar2typmodin nvarchar2typmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define NVARCHAR2ARRAYOID 3968 + +DATA(insert OID = 1082 ( date PGNSP PGUID 4 t b D f t \054 0 0 1182 date_in date_out date_recv date_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date"); +#define DATEOID 1082 +DATA(insert OID = 1083 ( time PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 1183 time_in time_out time_recv time_send timetypmodin timetypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("time of day"); +#define TIMEOID 1083 + +/* OIDS 1100 - 1199 */ +DATA(insert OID = 1114 ( timestamp PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 1115 timestamp_in timestamp_out timestamp_recv timestamp_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time"); +#define TIMESTAMPOID 1114 +DATA(insert OID = 1115 ( _timestamp PGNSP PGUID -1 f b A f t \054 0 1114 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMESTAMPARRAYOID 1115 +DATA(insert OID = 1182 ( _date PGNSP PGUID -1 f b A f t \054 0 1082 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define DATEARRAYOID 1182 +DATA(insert OID = 1183 ( _time PGNSP PGUID -1 f b A f t \054 0 1083 0 array_in array_out array_recv array_send timetypmodin timetypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMEARRAYOID 1183 +DATA(insert OID = 1184 ( timestamptz PGNSP PGUID 8 FLOAT8PASSBYVAL b D t t \054 0 0 1185 timestamptz_in timestamptz_out timestamptz_recv timestamptz_send timestamptztypmodin timestamptztypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time with time zone"); +#define TIMESTAMPTZOID 1184 +DATA(insert OID = 1185 ( _timestamptz PGNSP PGUID -1 f b A f t \054 0 1184 0 array_in array_out array_recv array_send timestamptztypmodin timestamptztypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMESTAMPTZARRAYOID 1185 +DATA(insert OID = 1186 ( interval PGNSP PGUID 16 f b T t t \054 0 0 1187 interval_in interval_out interval_recv interval_send intervaltypmodin intervaltypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("@ , time interval"); +#define INTERVALOID 1186 +DATA(insert OID = 1187 ( _interval PGNSP PGUID -1 f b A f t \054 0 1186 0 array_in array_out array_recv array_send intervaltypmodin intervaltypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYINTERVALOID 1187 +/* OIDS 1200 - 1299 */ +DATA(insert OID = 1231 ( _numeric PGNSP PGUID -1 f b A f t \054 0 1700 0 array_in array_out array_recv array_send numerictypmodin numerictypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYNUMERICOID 1231 + +DATA(insert OID = 1266 ( timetz PGNSP PGUID 12 f b D f t \054 0 0 1270 timetz_in timetz_out timetz_recv timetz_send timetztypmodin timetztypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("time of day with time zone"); +#define TIMETZOID 1266 +DATA(insert OID = 1270 ( _timetz PGNSP PGUID -1 f b A f t \054 0 1266 0 array_in array_out array_recv array_send timetztypmodin timetztypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYTIMETZOID 1270 + +/* OIDS 1500 - 1599 */ +DATA(insert OID = 1560 ( bit PGNSP PGUID -1 f b V f t \054 0 0 1561 bit_in bit_out bit_recv bit_send bittypmodin bittypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("fixed-length bit string"); +#define BITOID 1560 +DATA(insert OID = 1561 ( _bit PGNSP PGUID -1 f b A f t \054 0 1560 0 array_in array_out array_recv array_send bittypmodin bittypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BITARRAYOID 1561 +DATA(insert OID = 1562 ( varbit PGNSP PGUID -1 f b V t t \054 0 0 1563 varbit_in varbit_out varbit_recv varbit_send varbittypmodin varbittypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length bit string"); +#define VARBITOID 1562 +DATA(insert OID = 1563 ( _varbit PGNSP PGUID -1 f b A f t \054 0 1562 0 array_in array_out array_recv array_send varbittypmodin varbittypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define VARBITARRAYOID 1563 + +/* OIDS 1600 - 1699 */ + +/* OIDS 1700 - 1799 */ +DATA(insert OID = 1700 ( numeric PGNSP PGUID -1 f b N f t \054 0 0 1231 numeric_in numeric_out numeric_recv numeric_send numerictypmodin numerictypmodout - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("numeric(precision, decimal), arbitrary precision number"); +#define NUMERICOID 1700 + +DATA(insert OID = 1790 ( refcursor PGNSP PGUID -1 f b U f t \054 0 0 2201 textin textout textrecv textsend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("reference to cursor (portal name)"); +#define REFCURSOROID 1790 + +/* OIDS 2200 - 2299 */ +DATA(insert OID = 2201 ( _refcursor PGNSP PGUID -1 f b A f t \054 0 1790 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 2202 ( regprocedure PGNSP PGUID 4 t b N f t \054 0 0 2207 regprocedurein regprocedureout regprocedurerecv regproceduresend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered procedure (with args)"); +#define REGPROCEDUREOID 2202 + +DATA(insert OID = 2203 ( regoper PGNSP PGUID 4 t b N f t \054 0 0 2208 regoperin regoperout regoperrecv regopersend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered operator"); +#define REGOPEROID 2203 + +DATA(insert OID = 2204 ( regoperator PGNSP PGUID 4 t b N f t \054 0 0 2209 regoperatorin regoperatorout regoperatorrecv regoperatorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered operator (with args)"); +#define REGOPERATOROID 2204 + +DATA(insert OID = 2205 ( regclass PGNSP PGUID 4 t b N f t \054 0 0 2210 regclassin regclassout regclassrecv regclasssend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered class"); +#define REGCLASSOID 2205 + +DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regtypein regtypeout regtyperecv regtypesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered type"); +#define REGTYPEOID 2206 + +DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define REGTYPEARRAYOID 2211 + +/* uuid */ +DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("UUID datatype"); +#define UUIDOID 2950 + +DATA(insert OID = 2951 ( _uuid PGNSP PGUID -1 f b A f t \054 0 2950 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* text search */ +DATA(insert OID = 3614 ( tsvector PGNSP PGUID -1 f b U f t \054 0 0 3643 tsvectorin tsvectorout tsvectorrecv tsvectorsend - - ts_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("text representation for text search"); +#define TSVECTOROID 3614 +DATA(insert OID = 3642 ( gtsvector PGNSP PGUID -1 f b U f t \054 0 0 3644 gtsvectorin gtsvectorout - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("GiST index internal text representation for text search"); +#define GTSVECTOROID 3642 +DATA(insert OID = 3615 ( tsquery PGNSP PGUID -1 f b U f t \054 0 0 3645 tsqueryin tsqueryout tsqueryrecv tsquerysend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("query representation for text search"); +#define TSQUERYOID 3615 +DATA(insert OID = 3734 ( regconfig PGNSP PGUID 4 t b N f t \054 0 0 3735 regconfigin regconfigout regconfigrecv regconfigsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered text search configuration"); +#define REGCONFIGOID 3734 +DATA(insert OID = 3769 ( regdictionary PGNSP PGUID 4 t b N f t \054 0 0 3770 regdictionaryin regdictionaryout regdictionaryrecv regdictionarysend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered text search dictionary"); +#define REGDICTIONARYOID 3769 + +DATA(insert OID = 3643 ( _tsvector PGNSP PGUID -1 f b A f t \054 0 3614 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3644 ( _gtsvector PGNSP PGUID -1 f b A f t \054 0 3642 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3645 ( _tsquery PGNSP PGUID -1 f b A f t \054 0 3615 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3735 ( _regconfig PGNSP PGUID -1 f b A f t \054 0 3734 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3770 ( _regdictionary PGNSP PGUID -1 f b A f t \054 0 3769 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 2970 ( txid_snapshot PGNSP PGUID -1 f b U f t \054 0 0 2949 txid_snapshot_in txid_snapshot_out txid_snapshot_recv txid_snapshot_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("txid snapshot"); +DATA(insert OID = 2949 ( _txid_snapshot PGNSP PGUID -1 f b A f t \054 0 2970 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* range types */ +DATA(insert OID = 3904 ( int4range PGNSP PGUID -1 f r R f t \054 0 0 3905 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of integers"); +#define INT4RANGEOID 3904 +DATA(insert OID = 3905 ( _int4range PGNSP PGUID -1 f b A f t \054 0 3904 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3906 ( numrange PGNSP PGUID -1 f r R f t \054 0 0 3907 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of numerics"); +DATA(insert OID = 3907 ( _numrange PGNSP PGUID -1 f b A f t \054 0 3906 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3908 ( tsrange PGNSP PGUID -1 f r R f t \054 0 0 3909 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of timestamps without time zone"); +DATA(insert OID = 3909 ( _tsrange PGNSP PGUID -1 f b A f t \054 0 3908 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3910 ( tstzrange PGNSP PGUID -1 f r R f t \054 0 0 3911 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of timestamps with time zone"); +DATA(insert OID = 3911 ( _tstzrange PGNSP PGUID -1 f b A f t \054 0 3910 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3912 ( daterange PGNSP PGUID -1 f r R f t \054 0 0 3913 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of dates"); +DATA(insert OID = 3913 ( _daterange PGNSP PGUID -1 f b A f t \054 0 3912 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3926 ( int8range PGNSP PGUID -1 f r R f t \054 0 0 3927 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of bigints"); +DATA(insert OID = 3927 ( _int8range PGNSP PGUID -1 f b A f t \054 0 3926 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +/* + * pseudo-types + * + * types with typtype='p' represent various special cases in the type system. + * + * These cannot be used to define table columns, but are valid as function + * argument and result types (if supported by the function's implementation + * language). + * + * Note: cstring is a borderline case; it is still considered a pseudo-type, + * but there is now support for it in records and arrays. Perhaps we should + * just treat it as a regular base type? + */ +DATA(insert OID = 2249 ( record PGNSP PGUID -1 f p P f t \054 0 0 2287 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RECORDOID 2249 +DATA(insert OID = 2287 ( _record PGNSP PGUID -1 f p P f t \054 0 2249 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RECORDARRAYOID 2287 +DATA(insert OID = 2275 ( cstring PGNSP PGUID -2 f p P f t \054 0 0 1263 cstring_in cstring_out cstring_recv cstring_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +#define CSTRINGOID 2275 +DATA(insert OID = 2276 ( any PGNSP PGUID 4 t p P f t \054 0 0 0 any_in any_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYOID 2276 +DATA(insert OID = 2277 ( anyarray PGNSP PGUID -1 f p P f t \054 0 0 0 anyarray_in anyarray_out anyarray_recv anyarray_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYARRAYOID 2277 +DATA(insert OID = 2278 ( void PGNSP PGUID 4 t p P f t \054 0 0 0 void_in void_out void_recv void_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define VOIDOID 2278 +DATA(insert OID = 2279 ( trigger PGNSP PGUID 4 t p P f t \054 0 0 0 trigger_in trigger_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define TRIGGEROID 2279 +DATA(insert OID = 2280 ( language_handler PGNSP PGUID 4 t p P f t \054 0 0 0 language_handler_in language_handler_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define LANGUAGE_HANDLEROID 2280 +DATA(insert OID = 2281 ( internal PGNSP PGUID SIZEOF_POINTER t p P f t \054 0 0 0 internal_in internal_out - - - - - ALIGNOF_POINTER p f 0 -1 0 0 _null_ _null_ _null_ )); +#define INTERNALOID 2281 +DATA(insert OID = 2282 ( opaque PGNSP PGUID 4 t p P f t \054 0 0 0 opaque_in opaque_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define OPAQUEOID 2282 +DATA(insert OID = 2283 ( anyelement PGNSP PGUID 4 t p P f t \054 0 0 0 anyelement_in anyelement_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYELEMENTOID 2283 +DATA(insert OID = 2776 ( anynonarray PGNSP PGUID 4 t p P f t \054 0 0 0 anynonarray_in anynonarray_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYNONARRAYOID 2776 +DATA(insert OID = 3500 ( anyenum PGNSP PGUID 4 t p P f t \054 0 0 0 anyenum_in anyenum_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYENUMOID 3500 +DATA(insert OID = 3115 ( fdw_handler PGNSP PGUID 4 t p P f t \054 0 0 0 fdw_handler_in fdw_handler_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define FDW_HANDLEROID 3115 +DATA(insert OID = 3831 ( anyrange PGNSP PGUID -1 f p P f t \054 0 0 0 anyrange_in anyrange_out - - - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYRANGEOID 3831 +DATA(insert OID = 9003 ( smalldatetime PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 9005 smalldatetime_in smalldatetime_out smalldatetime_recv smalldatetime_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time"); +#define SMALLDATETIMEOID 9003 +DATA(insert OID = 9005 ( _smalldatetime PGNSP PGUID -1 f b A f t \054 0 9003 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define SMALLDATETIMEARRAYOID 9005 +DATA(insert OID = 4301 ( hll PGNSP PGUID -1 f b U f t \054 0 0 4302 hll_in hll_out hll_recv hll_send hll_typmod_in hll_typmod_out - i e f 0 -1 0 0 _null_ _null_ _null_ )); +#define HLL_OID 4301 +DESCR("hypper log log type"); +DATA(insert OID = 4302 ( _hll PGNSP PGUID -1 f p P f t \054 0 4301 0 array_in array_out array_recv array_send hll_typmod_in hll_typmod_out array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log array"); +#define HLL_ARRAYOID 4302 +DATA(insert OID = 4303 ( hll_hashval PGNSP PGUID 8 t p P f t \054 0 0 4304 hll_hashval_in hll_hashval_out - - - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +#define HLL_HASHVAL_OID 4303 +DESCR("hypper log log hashval"); +DATA(insert OID = 4304 ( _hll_hashval PGNSP PGUID -1 f p P f t \054 0 4303 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log hashval array"); +#define HLL_HASHVAL_ARRAYOID 4304 +DATA(insert OID = 4370 ( hll_trans_type PGNSP PGUID -1 f p P f t \054 0 0 4371 hll_trans_in hll_trans_out hll_trans_recv hll_trans_send - - - i e f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log internal type"); +DATA(insert OID = 4371 ( _hll_trans_type PGNSP PGUID -1 f p P f t \054 0 4370 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log internal type"); + +DATA(insert OID = 4402 ( byteawithoutorderwithequalcol PGNSP PGUID -1 f b U f t \054 0 0 1001 byteawithoutorderwithequalcolin byteawithoutorderwithequalcolout byteawithoutorderwithequalcolrecv byteawithoutorderwithequalcolsend byteawithoutorderwithequalcoltypmodin byteawithoutorderwithequalcoltypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("encrypted data variable-length string, binary values escaped"); +#define BYTEAWITHOUTORDERWITHEQUALCOLOID 4402 + +DATA(insert OID = 4403 ( byteawithoutordercol PGNSP PGUID -1 f b U f t \054 0 0 1001 byteawithoutordercolin byteawithoutordercolout byteawithoutorderwithequalcolrecv byteawithoutorderwithequalcolsend byteawithoutorderwithequalcoltypmodin byteawithoutorderwithequalcoltypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("encrypted data variable-length string, binary values escaped"); +#define BYTEAWITHOUTORDERCOLOID 4403 + +/* + * macros + */ +#define TYPTYPE_BASE 'b' /* base type (ordinary scalar type) */ +#define TYPTYPE_COMPOSITE 'c' /* composite (e.g., table's rowtype) */ +#define TYPTYPE_DOMAIN 'd' /* domain over another type */ +#define TYPTYPE_ENUM 'e' /* enumerated type */ +#define TYPTYPE_PSEUDO 'p' /* pseudo-type */ +#define TYPTYPE_RANGE 'r' /* range type */ + +#define TYPCATEGORY_INVALID '\0' /* not an allowed category */ +#define TYPCATEGORY_ARRAY 'A' +#define TYPCATEGORY_BOOLEAN 'B' +#define TYPCATEGORY_COMPOSITE 'C' +#define TYPCATEGORY_DATETIME 'D' +#define TYPCATEGORY_ENUM 'E' +#define TYPCATEGORY_GEOMETRIC 'G' +#define TYPCATEGORY_NETWORK 'I' /* think INET */ +#define TYPCATEGORY_NUMERIC 'N' +#define TYPCATEGORY_PSEUDOTYPE 'P' +#define TYPCATEGORY_RANGE 'R' +#define TYPCATEGORY_STRING 'S' +#define TYPCATEGORY_TIMESPAN 'T' +#define TYPCATEGORY_USER 'U' +#define TYPCATEGORY_BITSTRING 'V' /* er ... "varbit"? */ +#define TYPCATEGORY_UNKNOWN 'X' + +/* Is a type OID a polymorphic pseudotype? (Beware of multiple evaluation) */ +#define IsPolymorphicType(typid) \ + ((typid) == ANYELEMENTOID || \ + (typid) == ANYARRAYOID || \ + (typid) == ANYNONARRAYOID || \ + (typid) == ANYENUMOID || \ + (typid) == ANYRANGEOID) +#define IsClientLogicType(typid) \ +((typid) == BYTEAWITHOUTORDERCOLOID || \ +(typid) == BYTEAWITHOUTORDERWITHEQUALCOLOID) + +#endif /* PG_TYPE_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/pg_user_mapping.h postgresql-hll-2.14/include/catalog/pg_user_mapping.h --- postgresql-hll-2.14_old/include/catalog/pg_user_mapping.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_user_mapping.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * pg_user_mapping.h + * definition of the system "user mapping" relation (pg_user_mapping) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_user_mapping.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_USER_MAPPING_H +#define PG_USER_MAPPING_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_user_mapping definition. cpp turns this into + * typedef struct FormData_pg_user_mapping + * ---------------- + */ +#define UserMappingRelationId 1418 +#define UserMappingRelation_Rowtype_Id 11647 + +CATALOG(pg_user_mapping,1418) BKI_SCHEMA_MACRO +{ + Oid umuser; /* Id of the user, InvalidOid if PUBLIC + * is wanted */ + Oid umserver; /* server of this mapping */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text umoptions[1]; /* user mapping options */ +#endif +} FormData_pg_user_mapping; + +/* ---------------- + * Form_pg_user_mapping corresponds to a pointer to a tuple with + * the format of pg_user_mapping relation. + * ---------------- + */ +typedef FormData_pg_user_mapping *Form_pg_user_mapping; + +/* ---------------- + * compiler constants for pg_user_mapping + * ---------------- + */ +#define Natts_pg_user_mapping 3 +#define Anum_pg_user_mapping_umuser 1 +#define Anum_pg_user_mapping_umserver 2 +#define Anum_pg_user_mapping_umoptions 3 + +#endif /* PG_USER_MAPPING_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_user_status.h postgresql-hll-2.14/include/catalog/pg_user_status.h --- postgresql-hll-2.14_old/include/catalog/pg_user_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_user_status.h 2020-12-12 17:06:43.091346025 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_user_status.h + * definition of the system "user status" relation (pg_user_status) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_user_status.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_USER_STATUS_H +#define PG_USER_STATUS_H + +#include "catalog/genbki.h" + + +/* define the timestamptz for the locktime in pg_user_status */ +#define timestamptz Datum + +/* define the OID of the table pg_user_status */ +#define UserStatusRelationId 3460 +#define UserStatusRelation_Rowtype_Id 3463 + +CATALOG(pg_user_status,3460) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3463) BKI_SCHEMA_MACRO +{ + Oid roloid; /* role OID */ + int4 failcount; /* failed num of login attampts */ + timestamptz locktime; /* role lock time */ + int2 rolstatus; /* role status */ + int8 permspace; /* perm space */ + int8 tempspace; /* temp space */ + int2 passwordexpired; /* password expired status */ +} FormData_pg_user_status; + +#undef timestamptz + +/* ------------------------------------------------------------------------- + * Form_pg_user_status corresponds to a pointer to a tuple with + * the format of pg_user_status relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_user_status *Form_pg_user_status; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_user_status + * ------------------------------------------------------------------------- + */ +#define Natts_pg_user_status 7 +#define Anum_pg_user_status_roloid 1 +#define Anum_pg_user_status_failcount 2 +#define Anum_pg_user_status_locktime 3 +#define Anum_pg_user_status_rolstatus 4 +#define Anum_pg_user_status_permspace 5 +#define Anum_pg_user_status_tempspace 6 +#define Anum_pg_user_status_passwordexpired 7 + +#endif /* PG_USER_STATUS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pg_workload_group.h postgresql-hll-2.14/include/catalog/pg_workload_group.h --- postgresql-hll-2.14_old/include/catalog/pg_workload_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pg_workload_group.h 2020-12-12 17:06:43.092346038 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_workload_group.h + * define the system workload group information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_workload_group.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_WORKLOAD_GROUP_H +#define PG_WORKLOAD_GROUP_H + +#include "catalog/genbki.h" +#include "catalog/pg_resource_pool.h" + + +/* define the OID of the table pg_workload_group */ +#define WorkloadGroupRelationId 3451 +#define WorkloadGroupRelation_Rowtype_Id 3467 + +CATALOG(pg_workload_group,3451) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3467) BKI_SCHEMA_MACRO +{ + NameData workload_gpname; /* Name of worload group */ + Oid respool_oid; /* The oid of resource pool which the workload group is created under */ + int4 act_statements; /* The number of active statements */ +} FormData_pg_workload_group; + + +/*------------------------------------------------------------------------- + * Form_pg_workload_group corresponds to a pointer to a tuple with + * the format of pg_workload_group relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_workload_group *Form_pg_workload_group; + +/*------------------------------------------------------------------------- + * compiler constants for pg_workload_group + * ------------------------------------------------------------------------- + */ +#define Natts_pg_workload_group 3 +#define Anum_pg_workload_group_wgname 1 +#define Anum_pg_workload_group_rgoid 2 +#define Anum_pg_workload_group_acstatements 3 + +DATA(insert OID = 10 ( "default_group" 10 -1)); /* -1 means ulimited */ +#define DEFAULT_GROUP_OID 10 +#define DEFAULT_GROUP_NAME "default_group" +#define ULIMITED_ACTIVE_STATEMENTS -1 + +/* default setting for user defined workload group */ +#define DEFAULT_RESOURCE_POOL DEFAULT_POOL_OID +#define DEFAULT_ACTIVE_STATEMENTS -1 + +#endif /* PG_WORKLOAD_GROUP_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pgxc_class.h postgresql-hll-2.14/include/catalog/pgxc_class.h --- postgresql-hll-2.14_old/include/catalog/pgxc_class.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pgxc_class.h 2020-12-12 17:06:43.092346038 +0800 @@ -0,0 +1,81 @@ +/* ----------------------------------------------------------- + * + * Copyright (c) 2010-2013 Postgres-XC Development Group + * + * ----------------------------------------------------------- + */ +#ifndef PGXC_CLASS_H +#define PGXC_CLASS_H + +#include "nodes/parsenodes.h" + +#define PgxcClassRelationId 9001 +#define PgxcClassRelation_Rowtype_Id 11648 + +CATALOG(pgxc_class,9001) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid pcrelid; /* Table Oid */ + char pclocatortype; /* Type of distribution */ + int2 pchashalgorithm; /* Hashing algorithm */ + int2 pchashbuckets; /* Number of buckets */ + NameData pgroup; /* Group name */ + char redistributed; /* relation is re-distributed */ + int4 redis_order; /* data redistribution order */ + + int2vector pcattnum; /* Column number of distribution */ + +#ifdef CATALOG_VARLEN + /* VARIABLE LENGTH FIELDS: */ + oidvector_extend nodeoids; /* List of nodes used by table */ + text options; /* Reserve column */ +#endif +} FormData_pgxc_class; + +typedef FormData_pgxc_class *Form_pgxc_class; + +#define Natts_pgxc_class 10 + +#define Anum_pgxc_class_pcrelid 1 +#define Anum_pgxc_class_pclocatortype 2 +#define Anum_pgxc_class_pchashalgorithm 3 +#define Anum_pgxc_class_pchashbuckets 4 +#define Anum_pgxc_class_pgroup 5 +#define Anum_pgxc_class_redistributed 6 +#define Anum_pgxc_class_redis_order 7 +#define Anum_pgxc_class_pcattnum 8 +#define Anum_pgxc_class_nodes 9 +#define Anum_pgxc_class_option 10 + +typedef enum PgxcClassAlterType { + PGXC_CLASS_ALTER_DISTRIBUTION, + PGXC_CLASS_ALTER_NODES, + PGXC_CLASS_ALTER_ALL +} PgxcClassAlterType; + +extern void PgxcClassCreate(Oid pcrelid, + char pclocatortype, + int2* pcattnum, + int pchashalgorithm, + int pchashbuckets, + int numnodes, + Oid *nodes, + int distributeNum, + const char *groupname); +extern void PgxcClassAlter(Oid pcrelid, + char pclocatortype, + int2 *pcattnum, + int numpcattnum, + int pchashalgorithm, + int pchashbuckets, + int numnodes, + Oid *nodes, + char ch_redis, + PgxcClassAlterType type, + const char *groupname); +extern void RemovePgxcClass(Oid pcrelid); +extern bool RelationRedisCheck(Relation rel); +extern void PgxcClassAlterForReloption(Oid pcrelid, const char* reloptionstr); +extern void PgxcClassCreateForReloption(Oid pcrelid, const char* reloptionstr); + +#endif /* PGXC_CLASS_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pgxc_group.h postgresql-hll-2.14/include/catalog/pgxc_group.h --- postgresql-hll-2.14_old/include/catalog/pgxc_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pgxc_group.h 2020-12-12 17:06:43.092346038 +0800 @@ -0,0 +1,68 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_group.h + * definition of the system "PGXC group" relation (pgxc_group) + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/pgxc_group.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_GROUP_H +#define PGXC_GROUP_H + +#include "nodes/parsenodes.h" +#include "pgxc/groupmgr.h" + +#define PgxcGroupRelationId 9014 +#define PgxcGroupRelation_Rowtype_Id 11650 + +CATALOG(pgxc_group,9014) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData group_name; /* Group name */ + char in_redistribution; /* flag to determine if node group is under re-dsitribution */ + +#ifdef CATALOG_VARLEN + /* VARIABLE LENGTH FIELDS: */ + oidvector_extend group_members; /* Group members */ + text group_buckets; /* hash bucket location -- which node */ +#endif + + bool is_installation; /* flag to indicate if this nodegroup is installation nodegroup */ +#ifdef CATALOG_VARLEN + aclitem group_acl[1]; /* access permissions */ +#endif + char group_kind; /* Node group kind: 'v' ,'i','e','n' */ +} FormData_pgxc_group; + +typedef FormData_pgxc_group *Form_pgxc_group; + +#define Natts_pgxc_group 7 + +#define Anum_pgxc_group_name 1 +#define Anum_pgxc_group_in_redistribution 2 +#define Anum_pgxc_group_members 3 +#define Anum_pgxc_group_buckets 4 +#define Anum_pgxc_group_is_installation 5 +#define Anum_pgxc_group_group_acl 6 +#define Anum_pgxc_group_kind 7 + +#define PGXC_REDISTRIBUTION_SRC_GROUP 'y' +#define PGXC_REDISTRIBUTION_DST_GROUP 't' +#define PGXC_NON_REDISTRIBUTION_GROUP 'n' + +#define PGXC_GROUPKIND_INSTALLATION 'i' +#define PGXC_GROUPKIND_NODEGROUP 'n' +#define PGXC_GROUPKIND_LCGROUP 'v' +#define PGXC_GROUPKING_ELASTIC 'e' + +#endif /* PGXC_GROUP_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pgxc_node.h postgresql-hll-2.14/include/catalog/pgxc_node.h --- postgresql-hll-2.14_old/include/catalog/pgxc_node.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pgxc_node.h 2020-12-12 17:06:43.092346038 +0800 @@ -0,0 +1,135 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_node.h + * definition of the system "PGXC node" relation (pgxc_node) + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/pgxc_node.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_NODE_H +#define PGXC_NODE_H + +#include "catalog/genbki.h" + +#define PgxcNodeRelationId 9015 +#define PgxcNodeRelation_Rowtype_Id 11649 + +CATALOG(pgxc_node,9015) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData node_name; + + /* + * Possible node types are defined as follows + * Types are defined below PGXC_NODES_XXXX + */ + char node_type; + + /* + * Port number of the node to connect to + */ + int4 node_port; + + /* + * Host name of IP address of the node to connect to + */ + NameData node_host; + + /* + * Port1 number of the node to connect to + */ + int4 node_port1; + + /* + * Host1 name of IP address of the node to connect to + */ + NameData node_host1; + + /* + * Is static config primary node primary + */ + bool hostis_primary; + + /* + * Is this node primary + */ + bool nodeis_primary; + + /* + * Is this node preferred + */ + bool nodeis_preferred; + + /* + * Node identifier to be used at places where a fixed length node identification is required + */ + int4 node_id; + + /* + * Sctp port start number of the data node to connect to each ohter + */ + int4 sctp_port; + + /* + * Stream control port start number of the data node to connect to each ohter + */ + int4 control_port; + + /* + * Sctp port1 number of the data node to connect to each ohter + */ + int4 sctp_port1; + + /* + * Stream control port start number of the data node to connect to each ohter + */ + int4 control_port1; + + bool nodeis_central; + + bool nodeis_active; +} FormData_pgxc_node; + +typedef FormData_pgxc_node *Form_pgxc_node; + +#define Natts_pgxc_node 16 + +#define Anum_pgxc_node_name 1 +#define Anum_pgxc_node_type 2 +#define Anum_pgxc_node_port 3 +#define Anum_pgxc_node_host 4 +#define Anum_pgxc_node_port1 5 +#define Anum_pgxc_node_host1 6 +#define Anum_pgxc_host_is_primary 7 +#define Anum_pgxc_node_is_primary 8 +#define Anum_pgxc_node_is_preferred 9 +#define Anum_pgxc_node_id 10 + +#define Anum_pgxc_node_sctp_port 11 +#define Anum_pgxc_node_strmctl_port 12 +#define Anum_pgxc_node_sctp_port1 13 +#define Anum_pgxc_node_strmctl_port1 14 + +#define Anum_pgxc_node_is_central 15 +#define Anum_pgxc_node_is_active 16 + +/* Possible types of nodes */ +#define PGXC_NODE_COORDINATOR 'C' +#define PGXC_NODE_DATANODE 'D' +#define PGXC_NODE_DATANODE_STANDBY 'S' +#define PGXC_NODE_NONE 'N' + +#define IS_DATA_NODE(type) ((type) == PGXC_NODE_DATANODE || (type) == PGXC_NODE_DATANODE_STANDBY) +#define IS_PRIMARY_DATA_NODE(type) ((type) == PGXC_NODE_DATANODE) + +#endif /* PGXC_NODE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/pgxc_slice.h postgresql-hll-2.14/include/catalog/pgxc_slice.h --- postgresql-hll-2.14_old/include/catalog/pgxc_slice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/pgxc_slice.h 2020-12-12 17:06:43.092346038 +0800 @@ -0,0 +1,82 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pgxc_slice.h + * system catalog table that storing slice information for list/range distributed table. + * + * + * IDENTIFICATION + * src/include/catalog/pgxc_slice.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PGXC_SLICE_H +#define PGXC_SLICE_H + +#include "access/tupdesc.h" +#include "catalog/genbki.h" +#include "nodes/primnodes.h" + +#define PgxcSliceRelationId 9035 +#define PgxcSliceRelation_Rowtype_Id 9032 + +CATALOG(pgxc_slice,9035) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + NameData relname; /* list/range distributed table name or slice name of the table */ + char type; + char strategy; + Oid relid; /* table oid */ + Oid referenceoid; /* table oid that slice referenced to */ + int4 sindex; + +#ifdef CATALOG_VARLEN + text interval[1]; + text transitboundary[1]; +#endif + int4 transitno; + Oid nodeoid; +#ifdef CATALOG_VARLEN + text boundaries[1]; +#endif + bool specified; /* whether nodeoid is specified by user in DDL */ + int4 sliceorder; +} FormData_pgxc_slice; + +typedef FormData_pgxc_slice *Form_pgxc_slice; + +#define Natts_pgxc_slice 13 +#define Anum_pgxc_slice_relname 1 +#define Anum_pgxc_slice_type 2 +#define Anum_pgxc_slice_strategy 3 +#define Anum_pgxc_slice_relid 4 +#define Anum_pgxc_slice_referenceoid 5 +#define Anum_pgxc_slice_sindex 6 +#define Anum_pgxc_slice_interval 7 +#define Anum_pgxc_slice_transitboundary 8 +#define Anum_pgxc_slice_transitno 9 +#define Anum_pgxc_slice_nodeoid 10 +#define Anum_pgxc_slice_boundaries 11 +#define Anum_pgxc_slice_specified 12 +#define Anum_pgxc_slice_sliceorder 13 + +#define PGXC_SLICE_TYPE_TABLE 't' +#define PGXC_SLICE_TYPE_SLICE 's' + +extern void PgxcSliceCreate(const char* relname, Oid relid, DistributeBy* distributeby, + TupleDesc desc, const Oid* nodeoids, uint32 nodenum, uint32 startpos); +extern void RemovePgxcSlice(Oid relid); + +#endif /* PGXC_SLICE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/schemapg.h postgresql-hll-2.14/include/catalog/schemapg.h --- postgresql-hll-2.14_old/include/catalog/schemapg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/schemapg.h 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,1013 @@ +/*------------------------------------------------------------------------- + * + * schemapg.h + * Schema_pg_xxx macros for use by relcache.c + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * NOTES + * ****************************** + * *** DO NOT EDIT THIS FILE! *** + * ****************************** + * + * It has been GENERATED by genbki.pl + * + *------------------------------------------------------------------------- + */ +#ifndef SCHEMAPG_H +#define SCHEMAPG_H + +#define Schema_pg_proc \ +{ 1255, {"proname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prolang"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"procost"}, 700, -1, 4, 5, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prorows"}, 700, -1, 4, 6, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"provariadic"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"protransform"}, 24, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proisagg"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proiswindow"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prosecdef"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proleakproof"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proisstrict"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proretset"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"provolatile"}, 18, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronargs"}, 21, -1, 2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronargdefaults"}, 21, -1, 2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prorettype"}, 26, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargtypes"}, 30, -1, -1, 19, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proallargtypes"}, 1028, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargmodes"}, 1002, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargnames"}, 1009, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proargdefaults"}, 194, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"prosrc"}, 25, -1, -1, 24, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"probin"}, 25, -1, -1, 25, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proconfig"}, 1009, -1, -1, 26, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proacl"}, 1034, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prodefaultargpos"}, 22, -1, -1, 28, 1, -1, -1, false, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"fencedmode"}, 16, -1, 1, 29, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proshippable"}, 16, -1, 1, 30, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"propackage"}, 16, -1, 1, 31, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prokind"}, 18, -1, 1, 32, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_type \ +{ 1247, {"typname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typlen"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typbyval"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typtype"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typcategory"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typispreferred"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typisdefined"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typdelim"}, 18, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typrelid"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typelem"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typarray"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typinput"}, 24, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typoutput"}, 24, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typreceive"}, 24, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typsend"}, 24, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typmodin"}, 24, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typmodout"}, 24, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typanalyze"}, 24, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typalign"}, 18, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typstorage"}, 18, -1, 1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typnotnull"}, 16, -1, 1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typbasetype"}, 26, -1, 4, 24, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typtypmod"}, 23, -1, 4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typndims"}, 23, -1, 4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typcollation"}, 26, -1, 4, 27, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typdefaultbin"}, 194, -1, -1, 28, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1247, {"typdefault"}, 25, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1247, {"typacl"}, 1034, -1, -1, 30, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_attribute \ +{ 1249, {"attrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atttypid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attstattarget"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attlen"}, 21, -1, 2, 5, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attnum"}, 21, -1, 2, 6, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attndims"}, 23, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcacheoff"}, 23, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atttypmod"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attbyval"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attstorage"}, 18, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attalign"}, 18, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attnotnull"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atthasdef"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attisdropped"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attislocal"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcmprmode"}, 5545, -1, 1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attinhcount"}, 23, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcollation"}, 26, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attacl"}, 1034, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attoptions"}, 1009, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1249, {"attfdwoptions"}, 1009, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1249, {"attinitdefval"}, 17, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attkvtype"}, 5545, -1, 1, 24, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_class \ +{ 1259, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reloftype"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relowner"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relam"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfilenode"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltablespace"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relpages"}, 701, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltuples"}, 701, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relallvisible"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltoastrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltoastidxid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reldeltarelid"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reldeltaidx"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcudescrelid"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcudescidx"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasindex"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relisshared"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relpersistence"}, 18, -1, 1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relkind"}, 18, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relnatts"}, 21, -1, 2, 22, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relchecks"}, 21, -1, 2, 23, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasoids"}, 16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhaspkey"}, 16, -1, 1, 25, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasrules"}, 16, -1, 1, 26, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhastriggers"}, 16, -1, 1, 27, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhassubclass"}, 16, -1, 1, 28, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcmprs"}, 5545, -1, 1, 29, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasclusterkey"}, 16, -1, 1, 30, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relrowmovement"}, 16, -1, 1, 31, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"parttype"}, 18, -1, 1, 32, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfrozenxid"}, 31, -1, 4, 33, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relacl"}, 1034, -1, -1, 34, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reloptions"}, 1009, -1, -1, 35, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1259, {"relreplident"}, 18, -1, 1, 36, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfrozenxid64"}, 28, -1, 8, 37, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relbucket"}, 26, -1, 4, 38, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relbucketkey"}, 22, -1, -1, 39, 1, -1, -1, false, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_partition \ +{ 9016, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"parttype"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"parentid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"rangenum"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intervalnum"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"partstrategy"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relfilenode"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltablespace"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relpages"}, 701, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltuples"}, 701, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relallvisible"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltoastrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltoastidxid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"indextblid"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"indisusable"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reldeltarelid"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reldeltaidx"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relcudescrelid"}, 26, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relcudescidx"}, 26, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relfrozenxid"}, 31, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intspnum"}, 23, -1, 4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"partkey"}, 22, -1, -1, 22, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intervaltablespace"}, 30, -1, -1, 23, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"interval"}, 1009, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"boundaries"}, 1009, -1, -1, 25, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"transit"}, 1009, -1, -1, 26, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"reloptions"}, 1009, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"relfrozenxid64"}, 28, -1, 8, 28, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_attrdef \ +{ 2604, {"adrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2604, {"adnum"}, 21, -1, 2, 2, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2604, {"adbin"}, 194, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2604, {"adsrc"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_constraint \ +{ 2606, {"conname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"connamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"contype"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"condeferrable"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"condeferred"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"convalidated"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"contypid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conindid"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confrelid"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confupdtype"}, 18, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confdeltype"}, 18, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confmatchtype"}, 18, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conislocal"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"coninhcount"}, 23, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"connoinherit"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"consoft"}, 16, -1, 1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conopt"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conkey"}, 1005, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confkey"}, 1005, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conpfeqop"}, 1028, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conppeqop"}, 1028, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conffeqop"}, 1028, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conexclop"}, 1028, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conbin"}, 194, -1, -1, 25, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2606, {"consrc"}, 25, -1, -1, 26, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2606, {"conincluding"}, 1005, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_inherits \ +{ 2611, {"inhrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2611, {"inhparent"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2611, {"inhseqno"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_index \ +{ 2610, {"indexrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indrelid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indnatts"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisunique"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisprimary"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisexclusion"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indimmediate"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisclustered"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisusable"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisvalid"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indcheckxmin"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisready"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indkey"}, 22, -1, -1, 13, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indcollation"}, 30, -1, -1, 14, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indclass"}, 30, -1, -1, 15, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indoption"}, 22, -1, -1, 16, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indexprs"}, 194, -1, -1, 17, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2610, {"indpred"}, 194, -1, -1, 18, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2610, {"indisreplident"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indnkeyatts"}, 21, -1, 2, 20, 0, -1, -1, true, 'p', 's', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_operator \ +{ 2617, {"oprname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprkind"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcanmerge"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcanhash"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprleft"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprright"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprresult"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcom"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprnegate"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcode"}, 24, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprrest"}, 24, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprjoin"}, 24, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_opfamily \ +{ 2753, {"opfmethod"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfowner"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_opclass \ +{ 2616, {"opcmethod"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcowner"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcfamily"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcintype"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcdefault"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opckeytype"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_am \ +{ 2601, {"amname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amstrategies"}, 21, -1, 2, 2, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsupport"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanorder"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanorderbyop"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanbackward"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanunique"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanmulticol"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amoptionalkey"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsearcharray"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsearchnulls"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amstorage"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amclusterable"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ampredlocks"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amkeytype"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"aminsert"}, 24, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambeginscan"}, 24, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amgettuple"}, 24, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amgetbitmap"}, 24, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amrescan"}, 24, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amendscan"}, 24, -1, 4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ammarkpos"}, 24, -1, 4, 22, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amrestrpos"}, 24, -1, 4, 23, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ammerge"}, 24, -1, 4, 24, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambuild"}, 24, -1, 4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambuildempty"}, 24, -1, 4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambulkdelete"}, 24, -1, 4, 27, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amvacuumcleanup"}, 24, -1, 4, 28, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanreturn"}, 24, -1, 4, 29, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcostestimate"}, 24, -1, 4, 30, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amoptions"}, 24, -1, 4, 31, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_amop \ +{ 2602, {"amopfamily"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoplefttype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoprighttype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopstrategy"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoppurpose"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopopr"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopmethod"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopsortfamily"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_amproc \ +{ 2603, {"amprocfamily"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amproclefttype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amprocrighttype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amprocnum"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amproc"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_language \ +{ 2612, {"lanname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanispl"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanpltrusted"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanplcallfoid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"laninline"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanvalidator"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanacl"}, 1034, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_largeobject_metadata \ +{ 2995, {"lomowner"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2995, {"lomacl"}, 1034, -1, -1, 2, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_largeobject \ +{ 2613, {"loid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2613, {"pageno"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2613, {"data"}, 17, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_aggregate \ +{ 2600, {"aggfnoid"}, 24, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggtransfn"}, 24, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggcollectfn"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggfinalfn"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggsortop"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggtranstype"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"agginitval"}, 25, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2600, {"agginitcollect"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2600, {"aggkind"}, 18, -1, 1, 9, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggnumdirectargs"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_statistic \ +{ 2619, {"starelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"starelkind"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staattnum"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stainherit"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanullfrac"}, 700, -1, 4, 5, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stawidth"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stadistinct"}, 700, -1, 4, 7, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind1"}, 21, -1, 2, 8, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind2"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind3"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind4"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind5"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop1"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop2"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop3"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop4"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop5"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers1"}, 1021, -1, -1, 18, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers2"}, 1021, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers3"}, 1021, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers4"}, 1021, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers5"}, 1021, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues1"}, 2277, -1, -1, 23, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues2"}, 2277, -1, -1, 24, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues3"}, 2277, -1, -1, 25, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues4"}, 2277, -1, -1, 26, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues5"}, 2277, -1, -1, 27, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stadndistinct"}, 700, -1, 4, 28, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staextinfo"}, 25, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_rewrite \ +{ 2618, {"rulename"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_class"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_attr"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_type"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_enabled"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"is_instead"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_qual"}, 194, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2618, {"ev_action"}, 194, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_trigger \ +{ 2620, {"tgrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgfoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgtype"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgenabled"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgisinternal"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstrrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstrindid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstraint"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgdeferrable"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tginitdeferred"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgnargs"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgattr"}, 22, -1, -1, 13, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgargs"}, 17, -1, -1, 14, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgqual"}, 194, -1, -1, 15, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2620, {"tgowner"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_description \ +{ 2609, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"description"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_cast \ +{ 2605, {"castsource"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"casttarget"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castfunc"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castcontext"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castmethod"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_enum \ +{ 3501, {"enumtypid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3501, {"enumsortorder"}, 700, -1, 4, 2, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3501, {"enumlabel"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_namespace \ +{ 2615, {"nspname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nspowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nsptimeline"}, 20, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nspacl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"in_redistribution"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_conversion \ +{ 2607, {"conname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"connamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conforencoding"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"contoencoding"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conproc"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"condefault"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_depend \ +{ 2608, {"classid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"objid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refclassid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refobjid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refobjsubid"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"deptype"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_database \ +{ 1262, {"datname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datdba"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"encoding"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datcollate"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datctype"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datistemplate"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datallowconn"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datconnlimit"}, 23, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datlastsysoid"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datfrozenxid"}, 31, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"dattablespace"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datcompatibility"}, 19, -1, NAMEDATALEN, 12, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datacl"}, 1034, -1, -1, 13, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datfrozenxid64"}, 28, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_db_role_setting \ +{ 2964, {"setdatabase"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2964, {"setrole"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2964, {"setconfig"}, 1009, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_tablespace \ +{ 1213, {"spcname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcacl"}, 1034, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcoptions"}, 1009, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1213, {"spcmaxsize"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1213, {"relative"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_pltemplate \ +{ 1136, {"tmplname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmpltrusted"}, 16, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmpldbacreate"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmplhandler"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplinline"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplvalidator"}, 25, -1, -1, 6, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmpllibrary"}, 25, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplacl"}, 1034, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_authid \ +{ 1260, {"rolname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolsuper"}, 16, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolinherit"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcreaterole"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcreatedb"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcatupdate"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcanlogin"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolreplication"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolauditadmin"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolsystemadmin"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolconnlimit"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolpassword"}, 25, -1, -1, 12, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolvalidbegin"}, 1184, -1, 8, 13, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolvaliduntil"}, 1184, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolrespool"}, 19, -1, NAMEDATALEN, 15, 0, -1, -1, false, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roluseft"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolparentid"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roltabspace"}, 25, -1, -1, 18, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolkind"}, 18, -1, 1, 19, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolnodegroup"}, 26, -1, 4, 20, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roltempspace"}, 25, -1, -1, 21, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolspillspace"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolexcpdata"}, 25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolmonitoradmin"}, 16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roloperatoradmin"}, 16, -1, 1, 25, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolpolicyadmin"}, 16, -1, 1, 26, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_auth_members \ +{ 1261, {"roleid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"member"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"grantor"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"admin_option"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_shdepend \ +{ 1214, {"dbid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"classid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objsubid"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"refclassid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"refobjid"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"deptype"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objfile"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_shdescription \ +{ 2396, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2396, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2396, {"description"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_config \ +{ 3602, {"cfgname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgparser"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfoptions"}, 1009, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_config_map \ +{ 3603, {"mapcfg"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"maptokentype"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"mapseqno"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"mapdict"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_ts_dict \ +{ 3600, {"dictname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dicttemplate"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictinitoption"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_parser \ +{ 3601, {"prsname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsstart"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prstoken"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsend"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsheadline"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prslextype"}, 24, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_ts_template \ +{ 3764, {"tmplname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmplnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmplinit"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmpllexize"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_auth_history \ +{ 3457, {"roloid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3457, {"passwordtime"}, 1184, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3457, {"rolpassword"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_user_status \ +{ 3460, {"roloid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"failcount"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"locktime"}, 1184, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"rolstatus"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"permspace"}, 20, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"tempspace"}, 20, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"passwordexpired"}, 21, -1, 2, 7, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_extension \ +{ 3079, {"extname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extrelocatable"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extversion"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3079, {"extconfig"}, 1028, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extcondition"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_obsscaninfo \ +{ 5679, {"query_id"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"user_id"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"table_name"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"file_type"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"time_stamp"}, 1184, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"actual_time"}, 701, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"file_scanned"}, 20, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"data_size"}, 701, -1, 8, 8, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"billing_info"}, 25, -1, -1, 9, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_foreign_data_wrapper \ +{ 2328, {"fdwname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwhandler"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwvalidator"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwacl"}, 1034, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwoptions"}, 1009, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_foreign_server \ +{ 1417, {"srvname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvfdw"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvtype"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1417, {"srvversion"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1417, {"srvacl"}, 1034, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvoptions"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_user_mapping \ +{ 1418, {"umuser"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1418, {"umserver"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1418, {"umoptions"}, 1009, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pgxc_class \ +{ 9001, {"pcrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pclocatortype"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pchashalgorithm"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pchashbuckets"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pgroup"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"redistributed"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"redis_order"}, 23, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pcattnum"}, 22, -1, -1, 8, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"nodeoids"}, 32, -1, -1, 9, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"options"}, 25, -1, -1, 10, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pgxc_node \ +{ 9015, {"node_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_port"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_host"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_port1"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_host1"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"hostis_primary"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_primary"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_preferred"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_id"}, 23, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"sctp_port"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"control_port"}, 23, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"sctp_port1"}, 23, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"control_port1"}, 23, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_central"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_active"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pgxc_group \ +{ 9014, {"group_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"in_redistribution"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_members"}, 32, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_buckets"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9014, {"is_installation"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_acl"}, 1034, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_kind"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_resource_pool \ +{ 3450, {"respool_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"mem_percent"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"cpu_affinity"}, 20, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"control_group"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"active_statements"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"max_dop"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"memory_limit"}, 19, -1, NAMEDATALEN, 7, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"parentid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"io_limits"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"io_priority"}, 19, -1, NAMEDATALEN, 10, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"nodegroup"}, 19, -1, NAMEDATALEN, 11, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"is_foreign"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_workload_group \ +{ 3451, {"workload_gpname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3451, {"respool_oid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3451, {"act_statements"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_app_workloadgroup_mapping \ +{ 3464, {"appname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3464, {"workload_gpname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_foreign_table \ +{ 3118, {"ftrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftserver"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftwriteonly"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftoptions"}, 1009, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_rlspolicy \ +{ 3254, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polrelid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polcmd"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polpermissive"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polroles"}, 1028, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polqual"}, 194, -1, -1, 6, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_default_acl \ +{ 826, {"defaclrole"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclobjtype"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclacl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_seclabel \ +{ 3596, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"provider"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3596, {"label"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_shseclabel \ +{ 3592, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3592, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3592, {"provider"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3592, {"label"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_collation \ +{ 3456, {"collname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collencoding"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collcollate"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collctype"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_range \ +{ 3541, {"rngtypid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubtype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngcollation"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubopc"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngcanonical"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubdiff"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_policy_label \ +{ 9500, {"labelname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"labeltype"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdnnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdnid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"relcolumn"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdntype"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy \ +{ 9510, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"polcomments"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"modifydate"}, 1114, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"polenabled"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_access \ +{ 9520, {"accesstype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_privileges \ +{ 9530, {"privilegetype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_filters \ +{ 9540, {"filtertype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"logicaloperator"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_masking_policy \ +{ 9610, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"polcomments"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"modifydate"}, 1114, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"polenabled"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_masking_policy_actions \ +{ 9650, {"actiontype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actparams"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actlabelname"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"policyoid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actmodifydate"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_masking_policy_filters \ +{ 9640, {"filtertype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"filterlabelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"logicaloperator"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_encrypted_columns \ +{ 9700, {"rel_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"column_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"column_key_id"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"encryption_type"}, 5545, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"data_type_original_oid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"data_type_original_mod"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"create_date"}, 1114, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_column_keys \ +{ 9720, {"column_key_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"column_key_distributed_id"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"global_key_id"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_namespace"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_owner"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"create_date"}, 1114, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_acl"}, 1034, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_column_keys_args \ +{ 9740, {"column_key_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"function_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"key"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"value"}, 17, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_client_global_keys \ +{ 9710, {"global_key_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_namespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_owner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_acl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"create_date"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_client_global_keys_args \ +{ 9730, {"global_key_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"function_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"key"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"value"}, 17, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_job \ +{ 9022, {"job_id"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"current_postgres_pid"}, 20, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"log_user"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"priv_user"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"dbname"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"node_name"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"job_status"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"start_date"}, 1114, -1, 8, 8, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"next_run_date"}, 1114, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"failure_count"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"interval"}, 25, -1, -1, 11, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9022, {"last_start_date"}, 1114, -1, 8, 12, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"last_end_date"}, 1114, -1, 8, 13, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"last_suc_date"}, 1114, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"this_run_date"}, 1114, -1, 8, 15, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"nspname"}, 19, -1, NAMEDATALEN, 16, 0, -1, -1, false, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_asp \ +{ 9534, {"sampleid"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"sample_time"}, 1184, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"need_flush_sample"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"databaseid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"thread_id"}, 20, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"sessionid"}, 20, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"start_time"}, 1184, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"event"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"lwtid"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"psessionid"}, 20, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"tlevel"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"smpid"}, 23, -1, 4, 12, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"userid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"application_name"}, 25, -1, -1, 14, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"client_addr"}, 869, -1, -1, 15, 0, -1, -1, false, 'm', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"client_hostname"}, 25, -1, -1, 16, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"client_port"}, 23, -1, 4, 17, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"query_id"}, 20, -1, 8, 18, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"unique_query_id"}, 20, -1, 8, 19, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"user_id"}, 26, -1, 4, 20, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"cn_id"}, 23, -1, 4, 21, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"unique_query"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"locktag"}, 25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"lockmode"}, 25, -1, -1, 24, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"block_sessionid"}, 20, -1, 8, 25, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"wait_status"}, 25, -1, -1, 26, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_job_proc \ +{ 9023, {"job_id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9023, {"what"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_extension_data_source \ +{ 4211, {"srcname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srcowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srctype"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4211, {"srcversion"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4211, {"srcacl"}, 1034, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srcoptions"}, 1009, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_statistic_ext \ +{ 3220, {"starelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"starelkind"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stainherit"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanullfrac"}, 700, -1, 4, 4, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stawidth"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stadistinct"}, 700, -1, 4, 6, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stadndistinct"}, 700, -1, 4, 7, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind1"}, 21, -1, 2, 8, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind2"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind3"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind4"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind5"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop1"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop2"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop3"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop4"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop5"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakey"}, 22, -1, -1, 18, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers1"}, 1021, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers2"}, 1021, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers3"}, 1021, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers4"}, 1021, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers5"}, 1021, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues1"}, 2277, -1, -1, 24, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues2"}, 2277, -1, -1, 25, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues3"}, 2277, -1, -1, 26, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues4"}, 2277, -1, -1, 27, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues5"}, 2277, -1, -1, 28, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staexprs"}, 194, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_object \ +{ 9025, {"object_oid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"object_type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"creator"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"ctime"}, 1184, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"mtime"}, 1184, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_synonym \ +{ 3546, {"synname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synobjschema"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synobjname"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_directory \ +{ 4347, {"dirname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4347, {"owner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4347, {"dirpath"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4347, {"diracl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_hashbucket \ +{ 9026, {"bucketid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9026, {"bucketcnt"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9026, {"bucketvector"}, 32, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_global_config \ +{ 9080, {"name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9080, {"value"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_streaming_stream \ +{ 9028, {"relid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9028, {"queries"}, 17, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_streaming_cont_query \ +{ 9029, {"id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"relid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"defrelid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"active"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"streamrelid"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"matrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"lookupidxid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"step_factor"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"ttl"}, 23, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"ttl_attno"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"dictrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"grpnum"}, 21, -1, 2, 13, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"grpidx"}, 22, -1, -1, 14, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_streaming_reaper_status \ +{ 9030, {"id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9030, {"contquery_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9030, {"gather_interval"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9030, {"gather_completion_time"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_matview \ +{ 9982, {"matviewid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"mapid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"ivm"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"needrefresh"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"refreshtime"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_matview_dependency \ +{ 9985, {"matviewid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"relid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"mlogid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"mxmin"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pgxc_slice \ +{ 9035, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"strategy"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"relid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"referenceoid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"sindex"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"interval"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"transitboundary"}, 1009, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"transitno"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"nodeoid"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"boundaries"}, 1009, -1, -1, 11, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"specified"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"sliceorder"}, 23, -1, 4, 13, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#endif /* SCHEMAPG_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/storage_gtt.h postgresql-hll-2.14/include/catalog/storage_gtt.h --- postgresql-hll-2.14_old/include/catalog/storage_gtt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/storage_gtt.h 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * storage_gtt.h + * prototypes for functions in backend/catalog/storage_gtt.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/storage_gtt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STORAGE_GTT_H +#define STORAGE_GTT_H + +#include "access/htup.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "nodes/execnodes.h" +#include "utils/relcache.h" + +extern Size active_gtt_shared_hash_size(void); +extern void active_gtt_shared_hash_init(void); +extern void remember_gtt_storage_info(const RelFileNode rnode, Relation rel); +extern void forget_gtt_storage_info(Oid relid, const RelFileNode relfilenode, bool isCommit); +extern bool is_other_backend_use_gtt(Oid relid); +extern bool gtt_storage_attached(Oid relid); +extern Bitmapset *copy_active_gtt_bitmap(Oid relid); +extern void up_gtt_att_statistic( + Oid reloid, int attnum, int natts, TupleDesc tupleDescriptor, Datum* values, bool* isnull); +extern HeapTuple get_gtt_att_statistic(Oid reloid, int attnum); +extern void release_gtt_statistic_cache(HeapTuple tup); +extern void up_gtt_relstats(const Relation relation, + BlockNumber numPages, + double numTuples, + BlockNumber numAllVisiblePages, + TransactionId relfrozenxid); +extern bool get_gtt_relstats( + Oid relid, BlockNumber* relpages, double* reltuples, BlockNumber* relallvisible, TransactionId* relfrozenxid); +extern void gtt_force_enable_index(Relation index); +extern void gtt_fix_index_state(Relation index); +extern void init_gtt_storage(CmdType operation, ResultRelInfo *resultRelInfo); +extern Oid gtt_fetch_current_relfilenode(Oid relid); +extern void gtt_switch_rel_relfilenode(Oid rel1, Oid relfilenode1, Oid rel2, Oid relfilenode2, bool footprint); +extern void gtt_create_storage_files(Oid relid); +extern void remove_gtt_att_statistic(Oid reloid, int attnum); +#endif /* STORAGE_GTT_H */ diff -uprN postgresql-hll-2.14_old/include/catalog/storage.h postgresql-hll-2.14/include/catalog/storage.h --- postgresql-hll-2.14_old/include/catalog/storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/storage.h 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------------- + * + * storage.h + * prototypes for functions in backend/catalog/storage.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/storage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STORAGE_H +#define STORAGE_H +#include "dfsdesc.h" +#include "storage/dfs/dfs_connector.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/lmgr.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" + +#define DFS_STOR_FLAG -1 + +extern void RelationCreateStorage(RelFileNode rnode, char relpersistence, Oid ownerid, Oid bucketOid = InvalidOid, + Oid relfilenode=InvalidOid, Relation rel = NULL); +extern void RelationDropStorage(Relation rel, bool isDfsTruncate = false); +extern void RelationPreserveStorage(RelFileNode rnode, bool atCommit); +extern void RelationTruncate(Relation rel, BlockNumber nblocks); +extern void PartitionTruncate(Relation parent, Partition part, BlockNumber nblocks); +extern void PartitionDropStorage(Relation rel, Partition part); +extern void BucketCreateStorage(RelFileNode rnode, Oid bucketOid, Oid ownerid, Oid relfilenode); +extern void BucketDropStorage(Relation relation, Partition partition); + +#ifdef ENABLE_MULTIPLE_NODES +namespace Tsdb { +extern void DropPartStorage( + Oid partition_id, RelFileNode* partition_rnode, BackendId backend, Oid ownerid, List* target_cudesc_relids); +extern void InsertPartStorageIntoPendingList(_in_ RelFileNode* partition_rnode, _in_ AttrNumber part_id, + _in_ BackendId backend, _in_ Oid ownerid, _in_ bool atCommit); +} +#endif /* ENABLE_MULTIPLE_NODES */ + +// column-storage relation api +extern void CStoreRelCreateStorage(RelFileNode* rnode, AttrNumber attrnum, char relpersistence, Oid ownerid); +extern void CStoreRelDropColumn(Relation rel, AttrNumber attrnum, Oid ownerid); +extern void DfsStoreRelCreateStorage(RelFileNode* rnode, AttrNumber attrnum, char relpersistence); + +/* + * These functions used to be in storage/smgr/smgr.c, which explains the + * naming + */ +extern void smgrDoPendingDeletes(bool isCommit); +extern int smgrGetPendingDeletes(bool forCommit, ColFileNodeRel **ptr); +extern void AtSubCommit_smgr(void); +extern void AtSubAbort_smgr(void); +extern void PostPrepare_smgr(void); + +extern void InsertIntoPendingDfsDelete(const char* filename, bool atCommit, Oid ownerid, uint64 filesize); +extern void ResetPendingDfsDelete(); +extern void doPendingDfsDelete(bool isCommit, TransactionId *xid); + +extern void ColMainFileNodesCreate(void); +extern void ColMainFileNodesDestroy(void); +extern void ColMainFileNodesAppend(RelFileNode* bcmFileNode, BackendId backend); +extern void ColumnRelationDoDeleteFiles(RelFileNode* bcmFileNode, ForkNumber forknum, BackendId backend, Oid ownerid); +extern void RowRelationDoDeleteFiles(RelFileNode rnode, BackendId backend, Oid ownerid, Oid relOid = InvalidOid, + bool isCommit = false); + +extern uint64 GetSMgrRelSize(RelFileNode* relfilenode, BackendId backend, ForkNumber forkNum); + +/* + * dfs storage api + */ +extern void ClearDfsStorage(ColFileNode* pFileNode, int nrels, bool dropDir, bool cfgFromMapper); +extern void DropMapperFiles(ColFileNode* pColFileNode, int nrels); +extern void UnregisterDfsSpace(ColFileNode* pColFileNode, int rels); +extern void CreateDfsStorage(Relation rel); +extern void DropDfsStorage(Relation rel, bool isDfsTruncate = false); +extern void DropDfsDirectory(ColFileNode *colFileNode, bool cfgFromMapper); +extern void DropMapperFile(RelFileNode fNode); +extern void ClearDfsDirectory(ColFileNode *colFileNode, bool cfgFromMapper); +extern void DropDfsFilelist(RelFileNode fNode); +extern int ReadDfsFilelist(RelFileNode fNode, Oid ownerid, List** pendingList); +extern void SaveDfsFilelist(Relation rel, DFSDescHandler *handler); +extern uint64 GetDfsDelFileSize(List *dfsfilelist, bool isCommit); +extern bool IsSmgrTruncate(const XLogReaderState *record); +extern bool IsSmgrCreate(const XLogReaderState* record); + +extern void smgrApplyXLogTruncateRelation(XLogReaderState *record); +extern void XLogBlockSmgrRedoTruncate(RelFileNode rnode, BlockNumber blkno); + +/* + * to check whether is external storage + */ +#define IsDfsStor(flag) \ + ((bool) ((flag) == DFS_STOR_FLAG)) + +#endif /* STORAGE_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/storage_xlog.h postgresql-hll-2.14/include/catalog/storage_xlog.h --- postgresql-hll-2.14_old/include/catalog/storage_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/storage_xlog.h 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,51 @@ +/* --------------------------------------------------------------------------------------- + * + * storage_xlog.h + * prototypes for functions in backend/catalog/storage.cpp + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/storage_xlog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STORAGE_XLOG_H +#define STORAGE_XLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +/* + * Declarations for smgr-related XLOG records + * + * Note: we log file creation and truncation here, but logging of deletion + * actions is handled by xact.c, because it is part of transaction commit. + */ + +/* XLOG gives us high 4 bits */ +#define XLOG_SMGR_CREATE 0x10 +#define XLOG_SMGR_TRUNCATE 0x20 + +typedef struct xl_smgr_create { + RelFileNodeOld rnode; + ForkNumber forkNum; +} xl_smgr_create; + +typedef struct xl_smgr_truncate { + BlockNumber blkno; + RelFileNodeOld rnode; +} xl_smgr_truncate; + +extern void log_smgrcreate(RelFileNode *rnode, ForkNumber forkNum, const oidvector* bucketlist = NULL); + +extern void smgr_redo(XLogReaderState *record); +extern void smgr_desc(StringInfo buf, XLogReaderState *record); +extern void smgr_redo_create(RelFileNode rnode, ForkNumber forkNum, char *data); +extern void xlog_block_smgr_redo_truncate(RelFileNode rnode, BlockNumber blkno, XLogRecPtr lsn); + +#endif /* STORAGE_XLOG_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/toasting.h postgresql-hll-2.14/include/catalog/toasting.h --- postgresql-hll-2.14_old/include/catalog/toasting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/toasting.h 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * toasting.h + * This file provides some definitions to support creation of toast tables + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/toasting.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TOASTING_H +#define TOASTING_H + +/* + * toasting.c prototypes + */ +extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions, List *filenodelist = NIL); +extern void BootstrapToastTable(char *relName, + Oid toastOid, + Oid toastIndexOid); +extern bool createToastTableForPartition(Oid relOid, + Oid partOid, + Datum reloptions, + List *relfilenode); + +/* + * This macro is just to keep the C compiler from spitting up on the + * upcoming commands for genbki.pl. + */ +#define DECLARE_TOAST(name,toastoid, indexoid) extern int no_such_variable + +/* + * What follows are lines processed by genbki.pl to create the statements + * the bootstrap parser will turn into BootstrapToastTable commands. + * Each line specifies the system catalog that needs a toast table, + * the OID to assign to the toast table, and the OID to assign to the + * toast table's index. The reason we hard-wire these OIDs is that we + * need stable OIDs for shared relations, and that includes toast tables + * of shared relations. + */ + +/* normal catalogs */ +DECLARE_TOAST(pg_attrdef, 2830, 2831); +DECLARE_TOAST(pg_constraint, 2832, 2833); +DECLARE_TOAST(pg_description, 2834, 2835); +DECLARE_TOAST(pg_proc, 2836, 2837); +DECLARE_TOAST(pg_rewrite, 2838, 2839); +DECLARE_TOAST(pg_rlspolicy, 3173, 3174); +DECLARE_TOAST(pg_seclabel, 3598, 3599); +DECLARE_TOAST(pg_statistic, 2840, 2841); +DECLARE_TOAST(pg_statistic_ext, 3439, 3440); +DECLARE_TOAST(pg_trigger, 2336, 2337); +DECLARE_TOAST(pg_partition, 5502, 5503); +DECLARE_TOAST(pgxc_class, 5506, 5507); +DECLARE_TOAST(pg_hashbucket, 4390, 4391); + +/* shared catalogs */ +DECLARE_TOAST(pg_shdescription, 2846, 2847); +#define PgShdescriptionToastTable 2846 +#define PgShdescriptionToastIndex 2847 +DECLARE_TOAST(pg_db_role_setting, 2966, 2967); +#define PgDbRoleSettingToastTable 2966 +#define PgDbRoleSettingToastIndex 2967 +DECLARE_TOAST(pgxc_group, 5504, 5505); +#define PgxcGroupToastTable 5504 +#define PgxcGroupToastIndex 5505 +#endif /* TOASTING_H */ + diff -uprN postgresql-hll-2.14_old/include/catalog/unused_oids postgresql-hll-2.14/include/catalog/unused_oids --- postgresql-hll-2.14_old/include/catalog/unused_oids 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/catalog/unused_oids 2020-12-12 17:06:43.093346051 +0800 @@ -0,0 +1,57 @@ +#!/bin/sh +# +# unused_oids +# +# src/include/catalog/unused_oids +# +# finds blocks of manually-assignable oids that have not already been +# claimed by post_hackers. primarily useful for finding available +# oids for new internal functions. the numbers printed are inclusive +# ranges of unused oids. +# +# before using a large empty block, make sure you aren't about +# to take over what was intended as expansion space for something +# else. +# +# run this script in src/include/catalog. +# + + +AWK="awk" + +# Get FirstBootstrapObjectId from access/transam.h +FIRSTOBJECTID=`grep '#define[ ]*FirstBootstrapObjectId' ../access/transam.h | $AWK '{ print $3 }'` +export FIRSTOBJECTID + +# this part (down to the uniq step) should match the duplicate_oids script +# note: we exclude BKI_BOOTSTRAP relations since they are expected to have +# matching DATA lines in pg_class.h and pg_type.h + +cat pgxc_*.h pg_*.h toasting.h indexing.h | \ +egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \ +sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \ +tr ',' '\n' | \ +sort -n | \ +uniq | \ +$AWK ' +BEGIN { + last = 0; +} +/^[0-9]/ { + if ($1 > last + 1) { + if ($1 > last + 2) { + print last + 1, "-", $1 - 1; + } else { + print last + 1; + } + } + last = $1; +} +END { + print last + 1, "-", ENVIRON["FIRSTOBJECTID"]-1; +}' diff -uprN postgresql-hll-2.14_old/include/c.h postgresql-hll-2.14/include/c.h --- postgresql-hll-2.14_old/include/c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/c.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,1182 @@ +/* ------------------------------------------------------------------------- + * + * c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/c.h + * + * ------------------------------------------------------------------------- + */ +/* + * ---------------------------------------------------------------- + * TABLE OF CONTENTS + * + * When adding stuff to this file, please try to put stuff + * into the relevant section, or add new sections as appropriate. + * + * section description + * ------- ------------------------------------------------ + * 0) pg_config.h and standard system headers + * 1) hacks to cope with non-ANSI C compilers + * 2) bool, true, false, TRUE, FALSE, NULL + * 3) standard system types + * 4) IsValid macros for system types + * 5) offsetof, lengthof, endof, alignment + * 6) widely useful macros + * 7) random stuff + * 8) system-specific hacks + * 9) C++-specific stuff + * + * NOTE: since this file is included by both frontend and backend modules, it's + * almost certainly wrong to put an "extern" declaration here. typedefs and + * macros are the kind of thing that might go here. + * + * ---------------------------------------------------------------- + */ +#ifndef C_H +#define C_H + +/* + * We have to include stdlib.h here because it defines many of these macros + * on some platforms, and we only want our definitions used if stdlib.h doesn't + * have its own. The same goes for stddef and stdarg if present. + */ + +#include "pg_config.h" +#include "pg_config_manual.h" /* must be after pg_config.h */ +#if !defined(WIN32) && !defined(__CYGWIN__) /* win32 will include further \ + * down */ +#include "pg_config_os.h" /* must be before any system header files */ +#endif +#include "postgres_ext.h" + +#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H) +#define errcode __msvc_errcode +#include +#undef errcode +#endif + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#ifdef HAVE_STDINT_H +/* to use INT64_MIN and INT64_MAX */ +#define __STDC_LIMIT_MACROS +#include +#endif +#include +#include + +#include +#if defined(WIN32) || defined(__CYGWIN__) +#include /* ensure O_BINARY is available */ +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +/* We have to redefine some system functions after they are included above. */ +#include "pg_config_os.h" +#endif + +/* Must be before gettext() games below */ +#include + +#define _(x) gettext(x) + +#ifndef likely +#define likely(x) __builtin_expect((x) != 0, 1) +#endif +#ifndef unlikely +#define unlikely(x) __builtin_expect((x) != 0, 0) +#endif + +#ifdef ENABLE_NLS +#include +#else +#define gettext(x) (x) + +#define dgettext(d, x) (x) +#define ngettext(s, p, n) ((n) == 1 ? (s) : (p)) +#define dngettext(d, s, p, n) ((n) == 1 ? (s) : (p)) +#endif + +/* + * Use this to mark string constants as needing translation at some later + * time, rather than immediately. This is useful for cases where you need + * access to the original string and translated string, and for cases where + * immediate translation is not possible, like when initializing global + * variables. + * http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html + */ +#define gettext_noop(x) (x) + +/* ---------------------------------------------------------------- + * Section 1: hacks to cope with non-ANSI C compilers + * + * type prefixes (const, signed, volatile, inline) are handled in pg_config.h. + * ---------------------------------------------------------------- + */ + +/* + * CppAsString + * Convert the argument to a string, using the C preprocessor. + * CppConcat + * Concatenate two arguments together, using the C preprocessor. + * + * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks + * whether #identifier works, but if we have that we likely have ## too. + */ +#if defined(HAVE_STRINGIZE) + +#define CppAsString(identifier) #identifier +#define CppConcat(x, y) x##y +#else /* !HAVE_STRINGIZE */ + +#define CppAsString(identifier) "identifier" + +/* + * CppIdentity -- On Reiser based cpp's this is used to concatenate + * two tokens. That is + * CppIdentity(A)B ==> AB + * We renamed it to _private_CppIdentity because it should not + * be referenced outside this file. On other cpp's it + * produces A B. + */ +#define _priv_CppIdentity(x) x +#define CppConcat(x, y) _priv_CppIdentity(x) y +#endif /* !HAVE_STRINGIZE */ + +/* + * dummyret is used to set return values in macros that use ?: to make + * assignments. gcc wants these to be void, other compilers like char + */ +#ifdef __GNUC__ /* GNU cc */ +#define dummyret void +#else +#define dummyret char +#endif + +#ifndef __GNUC__ +#define __attribute__(_arg_) +#endif + +/* ---------------------------------------------------------------- + * Section 2: bool, true, false, TRUE, FALSE, NULL + * ---------------------------------------------------------------- + */ + +/* + * bool + * Boolean value, either true or false. + * + * XXX for C++ compilers, we assume the compiler has a compatible + * built-in definition of bool. + */ + +#ifndef __cplusplus + +#ifndef bool +typedef char bool; +#endif + +#ifndef true +#define true ((bool)1) +#endif + +#ifndef false +#define false ((bool)0) +#endif +#endif /* not C++ */ + +typedef bool* BoolPtr; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/* + * NULL + * Null pointer. + */ +#ifndef NULL +#define NULL ((void*)0) +#endif + +/* ---------------------------------------------------------------- + * Section 3: standard system types + * ---------------------------------------------------------------- + */ + +/* + * Pointer + * Variable holding address of any memory resident object. + * + * XXX Pointer arithmetic is done with this, so it can't be void * + * under "true" ANSI compilers. + */ +typedef char* Pointer; + +/* + * intN + * Signed integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. + */ +#ifndef HAVE_INT8 +typedef signed char int8; /* == 8 bits */ +typedef signed short int16; /* == 16 bits */ +typedef signed int int32; /* == 32 bits */ +#endif /* not HAVE_INT8 */ + +/* + * uintN + * Unsigned integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. + */ +#ifndef HAVE_UINT8 +typedef unsigned char uint8; /* == 8 bits */ +typedef unsigned short uint16; /* == 16 bits */ +typedef unsigned int uint32; /* == 32 bits */ +#endif /* not HAVE_UINT8 */ + +typedef unsigned int uint; /* == 32 bits */ + +/* + * bitsN + * Unit of bitwise operation, AT LEAST N BITS IN SIZE. + */ +typedef uint8 bits8; /* >= 8 bits */ +typedef uint16 bits16; /* >= 16 bits */ +typedef uint32 bits32; /* >= 32 bits */ + +/* + * 64-bit integers + */ +#ifdef HAVE_LONG_INT_64 +/* Plain "long int" fits, use it */ + +#ifndef HAVE_INT64 +typedef long int int64; +#endif +#ifndef HAVE_UINT64 +typedef unsigned long int uint64; +#endif +#elif defined(HAVE_LONG_LONG_INT_64) +/* We have working support for "long long int", use that */ + +#ifndef HAVE_INT64 +typedef long long int int64; +#endif +#ifndef HAVE_UINT64 +typedef unsigned long long int uint64; +#endif +#else +/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */ +#error must have a working 64-bit integer datatype +#endif + +/* Decide if we need to decorate 64-bit constants */ +#ifdef HAVE_LL_CONSTANTS +#define INT64CONST(x) ((int64)x##LL) +#define UINT64CONST(x) ((uint64)x##ULL) +#else +#define INT64CONST(x) ((int64)(x)) +#define UINT64CONST(x) ((uint64)(x)) +#endif + +/* + * stdint.h limits aren't guaranteed to be present and aren't guaranteed to + * have compatible types with our fixed width types. So just define our own. + */ +#define PG_INT8_MIN (-0x7F - 1) +#define PG_INT8_MAX 0x7F +#define PG_UINT8_MAX 0xFF +#define PG_INT16_MIN (-0x7FFF - 1) +#define PG_INT16_MAX 0x7FFF +#define PG_UINT16_MAX 0xFFFF +#define PG_INT32_MIN (-0x7FFFFFFF - 1) +#define PG_INT32_MAX (0x7FFFFFFF) +#define PG_UINT32_MAX 0xFFFFFFFFU +#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1) +#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF) +#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF) + +/* Select timestamp representation (float8 or int64) */ +#ifdef USE_INTEGER_DATETIMES +#define HAVE_INT64_TIMESTAMP +#endif + +/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */ +#ifndef HAVE_SIG_ATOMIC_T +typedef int sig_atomic_t; +#endif + +/* + * Size + * Size of any memory resident object, as returned by sizeof. + */ +typedef size_t Size; + +/* + * Index + * Index into any memory resident array. + * + * Note: + * Indices are non negative. + */ +typedef unsigned int Index; + +/* + * Offset + * Offset into any memory resident array. + * + * Note: + * This differs from an Index in that an Index is always + * non negative, whereas Offset may be negative. + */ +typedef signed int Offset; + +/* + * Common Postgres datatype names (as used in the catalogs) + */ + +typedef int8 int1; +typedef int16 int2; +typedef int32 int4; +typedef float float4; +typedef double float8; + +typedef uint8 uint1; +typedef uint16 uint2; +typedef uint32 uint4; + +/* + * Define signed 128 bit int type. + * Define unsigned 128 bit int type. + */ +#ifndef ENABLE_DEFAULT_GCC +#if !defined(WIN32) +typedef __int128 int128; +typedef unsigned __int128 uint128; +#endif +#else +#ifdef __linux__ +#if __GNUC__ >= 7 +typedef __int128 int128; +typedef unsigned __int128 uint128; +#endif +#endif +#endif + + +typedef union { + uint128 u128; + uint64 u64[2]; + uint32 u32[4]; +} uint128_u; + +/* + * int128 type has 128 bits. + * INT128_MIN is (-1 * (1 << 127)) + * INT128_MAX is ((1 << 127) - 1) + * UINT128_MIN is 0 + * UINT128_MAX is ((1 << 128) - 1) + * + */ +#define INT128_MAX (int128)(((uint128)1 << 127) - 1) +#define INT128_MIN (-INT128_MAX - 1) +#define UINT128_MAX (((uint128)INT128_MAX << 1) + 1) + +#define UINT128_IS_EQUAL(x, y) ((x).u128 == (y).u128) +#define UINT128_COPY(x, y) (x).u128 = (y).u128 + + +/* + * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId, + * CommandId + */ + +/* typedef Oid is in postgres_ext.h */ + +/* + * regproc is the type name used in the include/catalog headers, but + * RegProcedure is the preferred name in C code. + */ +typedef Oid regproc; +typedef regproc RegProcedure; + +/* Macro for checking XID 64-bitness */ +#define XID_IS_64BIT +#define MAX_START_XID UINT64CONST(0x3fffffffffffffff) + +typedef uint64 TransactionId; + +#define TransactionIdPrecedes(id1, id2) ((id1) < (id2)) +#define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) +#define TransactionIdFollows(id1, id2) ((id1) > (id2)) +#define TransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +#define StartTransactionIdIsValid(start_xid) ((start_xid) <= MAX_START_XID) + +typedef uint32 ShortTransactionId; + +typedef uint64 LocalTransactionId; + +typedef uint64 SubTransactionId; + +#define XID_FMT UINT64_FORMAT + +#define CSN_FMT UINT64_FORMAT + +#define InvalidSubTransactionId ((SubTransactionId)0) +#define TopSubTransactionId ((SubTransactionId)1) + +typedef TransactionId MultiXactId; +#define MultiXactIdPrecedes(id1, id2) ((id1) < (id2)) +#define MultiXactIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) +#define MultiXactIdFollows(id1, id2) ((id1) > (id2)) +#define MultiXactIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +typedef uint64 MultiXactOffset; + +/* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */ +#define StartMultiXactIdIsValid(start_mx_id) ((start_mx_id) <= MAX_START_XID) +#define StartMultiXactOffsetIsValid(start_mx_offset) ((start_mx_offset) <= MAX_START_XID) +typedef uint32 CommandId; + +#define FirstCommandId ((CommandId)0) +#define InvalidCommandId (~(CommandId)0) + +/* + * CommitSeqNo is currently an LSN, but keep use a separate datatype for clarity. + */ +typedef uint64 CommitSeqNo; + +#define InvalidCommitSeqNo ((CommitSeqNo)0) + +/* + * Array indexing support + */ +#define MAXDIM 6 +typedef struct { + int indx[MAXDIM]; +} IntArray; + +/* ---------------- + * Variable-length datatypes all share the 'struct varlena' header. + * + * NOTE: for TOASTable types, this is an oversimplification, since the value + * may be compressed or moved out-of-line. However datatype-specific routines + * are mostly content to deal with de-TOASTed values only, and of course + * client-side routines should never see a TOASTed value. But even in a + * de-TOASTed value, beware of touching vl_len_ directly, as its representation + * is no longer convenient. It's recommended that code always use the VARDATA, + * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of + * the struct fields. See postgres.h for details of the TOASTed form. + * ---------------- + */ +struct varlena { + char vl_len_[4]; /* Do not touch this field directly! */ + char vl_dat[FLEXIBLE_ARRAY_MEMBER]; +}; + +#define VARHDRSZ ((int32)sizeof(int32)) + +/* + * These widely-used datatypes are just a varlena header and the data bytes. + * There is no terminating null or anything like that --- the data length is + * always VARSIZE(ptr) - VARHDRSZ. + */ +typedef struct varlena bytea; +typedef struct varlena byteawithoutorderwithequalcol; +typedef struct varlena text; +typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */ +typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */ +typedef struct varlena NVarChar2; /* var-length char, ie SQL nvarchar2(n) */ +/* + * Specialized array types. These are physically laid out just the same + * as regular arrays (so that the regular array subscripting code works + * with them). They exist as distinct types mostly for historical reasons: + * they have nonstandard I/O behavior which we don't want to change for fear + * of breaking applications that look at the system catalogs. There is also + * an implementation issue for oidvector: it's part of the primary key for + * pg_proc, and we can't use the normal btree array support routines for that + * without circularity. + */ +typedef struct { + int32 vl_len_; /* these fields must match ArrayType! */ + int ndim; /* always 1 for int2vector */ + int32 dataoffset; /* always 0 for int2vector */ + Oid elemtype; + int dim1; + int lbound1; + int2 values[FLEXIBLE_ARRAY_MEMBER]; +} int2vector; + +typedef struct { + int32 vl_len_; /* these fields must match ArrayType! */ + int ndim; /* always 1 for oidvector */ + int32 dataoffset; /* always 0 for oidvector */ + Oid elemtype; + int dim1; + int lbound1; + Oid values[FLEXIBLE_ARRAY_MEMBER]; +} oidvector; + +typedef oidvector oidvector_extend; + +typedef struct ArrayInt4 { + int32 count; + int4* values; +} ArrayInt4; + +typedef struct ArrayInt2 { + int32 count; + int2* values; +} ArrayInt2; + +typedef struct ArrayOid { + int32 count; + Oid* values; +} ArrayOid; + +typedef struct ArrayChar { + int32 count; + char* values; +} ArrayChar; + +typedef struct ArrayCStr { + int32 count; + char** values; +} ArrayCStr; + +/* the array type of aclitem */ +typedef ArrayInt4 ArrayAcl; + +#define MakeArray(_type, cnt, ...) \ + { \ + .count = cnt, .values = (cnt == 0) ? NULL : (_type[cnt]) \ + { \ + __VA_ARGS__ \ + } \ + } + +#define MakeArrayInt4(cnt, ...) (ArrayInt4) MakeArray(int4, cnt, __VA_ARGS__) +#define MakeArrayInt2(cnt, ...) (ArrayInt2) MakeArray(int2, cnt, __VA_ARGS__) +#define MakeArrayOid(cnt, ...) (ArrayOid) MakeArray(Oid, cnt, __VA_ARGS__) +#define MakeArrayChar(cnt, ...) (ArrayChar) MakeArray(char, cnt, __VA_ARGS__) +#define MakeArrayCStr(cnt, ...) (ArrayCStr) MakeArray(char*, cnt, __VA_ARGS__) + +#define MakeArrayOidPtr(cnt, ...) \ + (ArrayOid[1]) \ + { \ + MakeArray(Oid, cnt, __VA_ARGS__) \ + } +#define MakeArrayCStrPtr(cnt, ...) \ + (ArrayCStr[1]) \ + { \ + MakeArray(char*, cnt, __VA_ARGS__) \ + } +#define MakeArrayCharPtr(cnt, ...) \ + (ArrayChar[1]) \ + { \ + MakeArray(char, cnt, __VA_ARGS__) \ + } +#define MakeArrayInt4Ptr(cnt, ...) \ + (ArrayInt4[1]) \ + { \ + MakeArray(int4, cnt, __VA_ARGS__) \ + } +#define MakeArrayInt2Ptr(cnt, ...) \ + (ArrayInt2[1]) \ + { \ + MakeArray(int2, cnt, __VA_ARGS__) \ + } + +#define MakeSingleValuePtr(_type, val) \ + (_type[1]) \ + { \ + val \ + } + +/* + * Representation of a Name: effectively just a C string, but null-padded to + * exactly NAMEDATALEN bytes. The use of a struct is historical. + */ +typedef struct nameData { + char data[NAMEDATALEN]; +} NameData; +typedef NameData* Name; + +#define NameStr(name) ((name).data) + +typedef struct pathData { + char data[MAXPGPATH]; +} PathData; + +/* + * Support macros for escaping strings. escape_backslash should be TRUE + * if generating a non-standard-conforming string. Prefixing a string + * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming. + * Beware of multiple evaluation of the "ch" argument! + */ +#define SQL_STR_DOUBLE(ch, escape_backslash) ((ch) == '\'' || ((ch) == '\\' && (escape_backslash))) + +#define ESCAPE_STRING_SYNTAX 'E' + +/* ---------------------------------------------------------------- + * Section 4: IsValid macros for system types + * ---------------------------------------------------------------- + */ +/* + * BoolIsValid + * True iff bool is valid. + */ +#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true) + +/* + * PointerIsValid + * True iff pointer is valid. + */ +#define PointerIsValid(pointer) ((const void*)(pointer) != NULL) + +/* + * PointerIsAligned + * True iff pointer is properly aligned to point to the given type. + */ +#define PointerIsAligned(pointer, type) (((intptr_t)(pointer) % (sizeof(type))) == 0) + +#define OidIsValid(objectId) ((bool)((objectId) != InvalidOid)) + +#define RegProcedureIsValid(p) OidIsValid(p) + +/* ---------------------------------------------------------------- + * Section 5: offsetof, lengthof, endof, alignment + * ---------------------------------------------------------------- + */ +/* + * offsetof + * Offset of a structure/union field within that structure/union. + * + * XXX This is supposed to be part of stddef.h, but isn't on + * some systems (like SunOS 4). + */ +#ifndef offsetof +#define offsetof(type, field) ((long)&((type*)0)->field) +#endif /* offsetof */ + +/* + * lengthof + * Number of elements in an array. + */ +#define lengthof(array) (sizeof(array) / sizeof((array)[0])) + +/* + * endof + * Address of the element one past the last in an array. + */ +#define endof(array) (&(array)[lengthof(array)]) + +/* ---------------- + * Alignment macros: align a length or address appropriately for a given type. + * The fooALIGN() macros round up to a multiple of the required alignment, + * while the fooALIGN_DOWN() macros round down. The latter are more useful + * for problems like "how many X-sized structures will fit in a page?". + * + * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2. + * That case seems extremely unlikely to be needed in practice, however. + * ---------------- + */ + +#define TYPEALIGN(ALIGNVAL, LEN) (((uintptr_t)(LEN) + ((ALIGNVAL)-1)) & ~((uintptr_t)((ALIGNVAL)-1))) + +#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN)) +#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN)) +#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN)) +#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN)) +#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN)) +/* MAXALIGN covers only built-in types, not buffers */ +#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN)) +#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN)) + +#define TYPEALIGN_DOWN(ALIGNVAL, LEN) (((uintptr_t)(LEN)) & ~((uintptr_t)((ALIGNVAL)-1))) + +#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN)) +#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN)) +#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN)) +#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN)) +#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN)) + +/* ---------------------------------------------------------------- + * Section 6: widely useful macros + * ---------------------------------------------------------------- + */ +/* + * Max + * Return the maximum of two numbers. + */ +#define Max(x, y) ((x) > (y) ? (x) : (y)) + +#define MaxTriple(x, y, z) ((x) > (y) ? ((x) > (z) ? (x) : (z)) : ((y) > (z) ? (y) : (z))) + +/* + * Min + * Return the minimum of two numbers. + */ +#define Min(x, y) ((x) < (y) ? (x) : (y)) + +/* + * Abs + * Return the absolute value of the argument. + */ +#define Abs(x) ((x) >= 0 ? (x) : -(x)) + +/* + * MemCpy + * same as memcpy. + */ +#if defined(__x86_64__) && !defined(WIN32) + +static inline void* MemCpy(void* dest, const void* src, Size len) +{ + if (len <= 1024) { + if (len >= 4) { + __asm__ __volatile__("shr $2,%2\n" + "rep movsl\n" + "testb $2,%b6\n" + "je 1f\n" + "movsw\n" + "1:\n" + "testb $1,%b6\n" + "je 2f\n" + "movsb\n" + "2:" + : "=&D"(dest), "=&S"(src), "=&c"(len) + : "0"(dest), "1"(src), "2"(len), "q"(len) + : "memory"); + + return dest; + } + + __asm__ __volatile__("rep movsb" + : "=&D"(dest), "=&S"(src), "=&c"(len) + : "0"(dest), "1"(src), "2"(len) + : "memory"); + + return dest; + } + + return memcpy(dest, src, len); +} + +#else +static inline void* MemCpy(void* dest, const void* src, Size len) +{ + return memcpy(dest, src, len); +} +#endif + +/* + * StrNCpy + * Like standard library function strncpy(), except that result string + * is guaranteed to be null-terminated --- that is, at most N-1 bytes + * of the source string will be kept. + * Also, the macro returns no result (too hard to do that without + * evaluating the arguments multiple times, which seems worse). + * + * BTW: when you need to copy a non-null-terminated string (like a text + * datum) and add a null, do not do it with StrNCpy(..., len+1). That + * might seem to work, but it fetches one byte more than there is in the + * text object. One fine day you'll have a SIGSEGV because there isn't + * another byte before the end of memory. Don't laugh, we've had real + * live bug reports from real live users over exactly this mistake. + * Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead. + */ +#define StrNCpy(dst, src, len) \ + do { \ + char* _dst = (dst); \ + Size _len = (len); \ + \ + if (_len > 0) { \ + strncpy(_dst, (src), _len); \ + _dst[_len - 1] = '\0'; \ + } \ + } while (0) + +/* Get a bit mask of the bits set in non-long aligned addresses */ +#define LONG_ALIGN_MASK (sizeof(long) - 1) + +/* + * MemSet + * Exactly the same as standard library function memset(), but considerably + * faster for zeroing small word-aligned structures (such as parsetree nodes). + * This has to be a macro because the main point is to avoid function-call + * overhead. However, we have also found that the loop is faster than + * native libc memset() on some platforms, even those with assembler + * memset() functions. More research needs to be done, perhaps with + * MEMSET_LOOP_LIMIT tests in configure. + */ +#define MemSet(start, val, len) \ + do { \ + /* must be void* because we don't know if it is integer aligned yet */ \ + void* _vstart = (void*)(start); \ + int _val = (val); \ + Size _len = (len); \ + \ + if ((((uintptr_t)_vstart) & LONG_ALIGN_MASK) == 0 && (_len & LONG_ALIGN_MASK) == 0 && _val == 0 && \ + _len <= MEMSET_LOOP_LIMIT && /* \ + * If MEMSET_LOOP_LIMIT == 0, optimizer should find \ + * the whole "if" false at compile time. \ + */ \ + MEMSET_LOOP_LIMIT != 0) { \ + long* _start = (long*)_vstart; \ + long* _stop = (long*)((char*)_start + _len); \ + while (_start < _stop) \ + *_start++ = 0; \ + } else \ + memset(_vstart, _val, _len); \ + } while (0) + +/* + * MemSetAligned is the same as MemSet except it omits the test to see if + * "start" is word-aligned. This is okay to use if the caller knows a-priori + * that the pointer is suitably aligned (typically, because he just got it + * from palloc(), which always delivers a max-aligned pointer). + */ +#define MemSetAligned(start, val, len) \ + do { \ + long* _start = (long*)(start); \ + int _val = (val); \ + Size _len = (len); \ + \ + if ((_len & LONG_ALIGN_MASK) == 0 && _val == 0 && _len <= MEMSET_LOOP_LIMIT && MEMSET_LOOP_LIMIT != 0) { \ + long* _stop = (long*)((char*)_start + _len); \ + while (_start < _stop) \ + *_start++ = 0; \ + } else \ + memset(_start, _val, _len); \ + } while (0) + +/* + * MemSetTest/MemSetLoop are a variant version that allow all the tests in + * MemSet to be done at compile time in cases where "val" and "len" are + * constants *and* we know the "start" pointer must be word-aligned. + * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use + * MemSetAligned. Beware of multiple evaluations of the arguments when using + * this approach. + */ +#define MemSetTest(val, len) \ + (((len)&LONG_ALIGN_MASK) == 0 && (len) <= MEMSET_LOOP_LIMIT && MEMSET_LOOP_LIMIT != 0 && (val) == 0) + +#define MemSetLoop(start, val, len) \ + do { \ + long* _start = (long*)(start); \ + long* _stop = (long*)((char*)_start + (Size)(len)); \ + \ + while (_start < _stop) \ + *_start++ = 0; \ + } while (0) + +/* ---------------------------------------------------------------- + * Section 7: random stuff + * ---------------------------------------------------------------- + */ + +/* msb for char */ +#define HIGHBIT 0x80 +#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch)&HIGHBIT) + +#define STATUS_OK 0 +#define STATUS_ERROR (-1) +#define STATUS_EOF (-2) +#define STATUS_WRONG_PASSWORD (-3) +#define STATUS_EXPIRED (-4) +#define STATUS_FOUND 1 +#define STATUS_WAITING 2 +#define STATUS_FOUND_NEED_CANCEL 3 + +/* + * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only + * used in assert-enabled builds, to avoid compiler warnings about unused + * variables in assert-disabled builds. + */ +#ifdef USE_ASSERT_CHECKING +#define PG_USED_FOR_ASSERTS_ONLY +#else +#define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused)) +#endif + +// Conditionally disable a feature +// +// To reduce the exposure surface of the engine, we disabled some seldom +// used, or not-confident features. But we still want keep them minimally +// execised to make sure later code changes won't break them totally. Thus +// we differentiate them with a configure directive, and test them only +// when it is enabled. For public release, the features are disabled. +// + +#ifdef PGXC +#define FEATURE_NOT_PUBLIC_ERROR(x) \ + do { \ + /* initdb might use some of the features, hornour it */ \ + if (!IsInitdb && !g_instance.attr.attr_common.support_extended_features && \ + !u_sess->attr.attr_common.IsInplaceUpgrade) \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg(x))); \ + } while (0) +#endif /*PGXC*/ + +/* gettext domain name mangling */ + +/* + * To better support parallel installations of major PostgeSQL + * versions as well as parallel installations of major library soname + * versions, we mangle the gettext domain name by appending those + * version numbers. The coding rule ought to be that whereever the + * domain name is mentioned as a literal, it must be wrapped into + * PG_TEXTDOMAIN(). The macros below do not work on non-literals; but + * that is somewhat intentional because it avoids having to worry + * about multiple states of premangling and postmangling as the values + * are being passed around. + * + * Make sure this matches the installation rules in nls-global.mk. + */ + +/* need a second indirection because we want to stringize the macro value, not the name */ +#define CppAsString2(x) CppAsString(x) + +#ifdef SO_MAJOR_VERSION +#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION) +#else +#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION) +#endif + +#ifndef WIN32 +// Compiler hint to force inlining or unlining a function +// +#if defined(_MSC_VER) +#define FORCE_INLINE __forceinline +#define NO_INLINE __declspec(noinline) +#else +#if (!defined ENABLE_LLT) && (!defined ENABLE_UT) +#define FORCE_INLINE __attribute__((always_inline)) +#else +#define FORCE_INLINE +#endif +#define NO_INLINE __attribute__((noinline)) +#endif + +// SAL annotations -- remove when compiler annotation header is fixed. +// +#define _in_ // input argument: function reads it +#define _out_ // output argument: function writes it +#define __inout // both in and out argument: function r/w it +#endif /* WIN32 */ +/* ---------------------------------------------------------------- + * Section 8: system-specific hacks + * + * This should be limited to things that absolutely have to be + * included in every source file. The port-specific header file + * is usually a better place for this sort of thing. + * ---------------------------------------------------------------- + */ + +/* + * NOTE: this is also used for opening text files. + * WIN32 treats Control-Z as EOF in files opened in text mode. + * Therefore, we open files in binary mode on Win32 so we can read + * literal control-Z. The other affect is that we see CRLF, but + * that is OK because we can already handle those cleanly. + */ +#if defined(WIN32) || defined(__CYGWIN__) +#define PG_BINARY O_BINARY +#define PG_BINARY_A "ab" +#define PG_BINARY_R "rb" +#define PG_BINARY_W "wb" +#define PG_BINARY_RW "r+" +#else +#define PG_BINARY 0 +#define PG_BINARY_A "a" +#define PG_BINARY_R "r" +#define PG_BINARY_W "w" +#define PG_BINARY_RW "r+" +#endif + +/* + * Macros to support compile-time assertion checks. + * + * If the "condition" (a compile-time-constant expression) evaluates to false, + * throw a compile error using the "errmessage" (a string literal). + * + * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic + * placement restrictions. These macros make it safe to use as a statement + * or in an expression, respectively. + * + * Otherwise we fall back on a kluge that assumes the compiler will complain + * about a negative width for a struct bit-field. This will not include a + * helpful error message, but it beats not getting an error at all. + */ +#define StaticAssertStmt(condition, errmessage) ((void)(1 / (int)(!!(condition)))) +#define StaticAssertExpr(condition, errmessage) StaticAssertStmt(condition, errmessage) + +/* + * Compile-time checks that a variable (or expression) has the specified type. + * + * AssertVariableIsOfType() can be used as a statement. + * AssertVariableIsOfTypeMacro() is intended for use in macros, eg + * #define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x)) + * + * If we don't have __builtin_types_compatible_p, we can still assert that + * the types have the same size. This is far from ideal (especially on 32-bit + * platforms) but it provides at least some coverage. + */ + +#define AssertVariableIsOfType(varname, typename) \ + StaticAssertStmt( \ + sizeof(varname) == sizeof(typename), CppAsString(varname) " does not have type " CppAsString(typename)) +#define AssertVariableIsOfTypeMacro(varname, typename) \ + (StaticAssertExpr( \ + sizeof(varname) == sizeof(typename), CppAsString(varname) " does not have type " CppAsString(typename))) +/* + * Provide prototypes for routines not present in a particular machine's + * standard C library. + */ + +#if !HAVE_DECL_SNPRINTF +extern int snprintf(char* str, size_t count, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4))); +#endif + +#if !HAVE_DECL_VSNPRINTF +extern int vsnprintf(char* str, size_t count, const char* fmt, va_list args); +#endif + +/* no special DLL markers on most ports */ +#ifndef PGDLLIMPORT +#define PGDLLIMPORT +#endif +#ifndef PGDLLEXPORT +#define PGDLLEXPORT +#endif + +/* + * The following is used as the arg list for signal handlers. Any ports + * that take something other than an int argument should override this in + * their pg_config_os.h file. Note that variable names are required + * because it is used in both the prototypes as well as the definitions. + * Note also the long name. We expect that this won't collide with + * other names causing compiler warnings. + */ + +#ifndef SIGNAL_ARGS +#define SIGNAL_ARGS int postgres_signal_arg +#endif + +/* + * When there is no sigsetjmp, its functionality is provided by plain + * setjmp. Incidentally, nothing provides setjmp's functionality in + * that case. + */ +#ifndef HAVE_SIGSETJMP +#define sigjmp_buf jmp_buf +#define sigsetjmp(x, y) setjmp(x) +#define siglongjmp longjmp +#endif + +#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC +extern int fdatasync(int fildes); +#endif + +/* If strtoq() exists, rename it to the more standard strtoll() */ +#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ) +#define strtoll strtoq +#define HAVE_STRTOLL 1 +#endif + +/* If strtouq() exists, rename it to the more standard strtoull() */ +#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ) +#define strtoull strtouq +#define HAVE_STRTOULL 1 +#endif + +/* + * We assume if we have these two functions, we have their friends too, and + * can use the wide-character functions. + */ +#if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER) +#define USE_WIDE_UPPER_LOWER +#endif + +#define EXEC_BACKEND + +/* EXEC_BACKEND defines */ +#ifdef EXEC_BACKEND +#define NON_EXEC_STATIC +#else +#define NON_EXEC_STATIC static +#endif + +/* ---------------------------------------------------------------- + * Section 9: C++-specific stuff + * + * This should be limited to stuff that are C++ language specific. + * ---------------------------------------------------------------- + */ +#ifndef WIN32 +#ifdef __cplusplus + +// The rtl namespace (read as "run time library") contains some crystally clear +// stuff from STL, which we do not encourage to use to avoid potential issues. +// Fortunately there shouldn't be much to copy here. +// +namespace rtl { +template +const T& max(const T& a, const T& b) +{ + return (a >= b) ? a : b; +} + +template +const T& min(const T& a, const T& b) +{ + return (a < b) ? a : b; +} +} // namespace rtl + +#endif /* __cplusplus */ +#endif /* WIN32 */ + +/* /port compatibility functions */ +#include "port.h" + +#define LOG2(x) (log(x) / 0.693147180559945) + +#define pg_restrict __restrict + +#define INT2UINT64(val) (unsigned int64)((unsigned int)(val)) + +#define INT2ULONG(val) (unsigned long)((unsigned int)(val)) + +#define INT2SIZET(val) (Size)((unsigned int)(val)) + +#define isIntergratedMachine false // not work for now, adapt it later + +#endif /* C_H */ diff -uprN postgresql-hll-2.14_old/include/cipher.h postgresql-hll-2.14/include/cipher.h --- postgresql-hll-2.14_old/include/cipher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cipher.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,137 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cipher.h + * + * + * + * IDENTIFICATION + * src/include/cipher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CIPHER_H +#define CIPHER_H + +#include +#include +#include + +#include "c.h" + +#include "utils/pg_crc.h" +#include "openssl/ssl.h" +#include "openssl/tls1.h" +#include "openssl/ossl_typ.h" +#include "openssl/obj_mac.h" + +#ifdef WIN32 +typedef unsigned __int64 GS_UINT64; +#else +typedef unsigned long long GS_UINT64; +#endif +#if defined(__LP64__) || defined(__64BIT__) +typedef unsigned int GS_UINT32; + +typedef signed int GS_INT32; +#else +typedef unsigned long GS_UINT32; + +typedef signed long GS_INT32; +#endif + +typedef unsigned char GS_UCHAR; + +#define CIPHER_KEY_FILE ".key.cipher" +#define RAN_KEY_FILE ".key.rand" +#define RANDOM_LEN 16 +#define CIPHER_LEN 16 +#define DEK_LEN 16 +#define ITERATE_TIMES 10000 +#define MAC_ITERATE_TIMES 10000 +#define MAC_LEN 20 +#define MIN_KEY_LEN 8 +#define MAX_KEY_LEN 16 +#define AK_LEN 512 +#define SK_LEN 512 +#define AK_VALID_CHRS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +#define SK_VALID_CHRS AK_VALID_CHRS +#define DEK_SAMPLE_STRING "TRANS_ENCRYPT_SAMPLE_STRING" + +typedef enum { + UNKNOWN_KEY_MODE, + SERVER_MODE, + CLIENT_MODE, + OBS_MODE, + SOURCE_MODE, + GDS_MODE +} KeyMode; + +typedef struct { + GS_UCHAR cipherkey[CIPHER_LEN + 1]; /* cipher text vector */ + GS_UCHAR key_salt[RANDOM_LEN + 1]; /* salt vector used to derive key */ + GS_UCHAR vector_salt[RANDOM_LEN + 1]; /* salt vector used to encrypt/decrypt text */ + pg_crc32 crc; +} CipherkeyFile; + +typedef struct { + GS_UCHAR randkey[CIPHER_LEN + 1]; + pg_crc32 crc; +} RandkeyFile; + +typedef enum { + OBS_CLOUD_TYPE = 0, /* on cloud obs cipher for encrypt and decrypt ak/sk */ + INITDB_NOCLOUDOBS_TYPE, /* non-cloud obs use the cipher same as initdb */ + GSQL_SSL_TYPE, /* gsql ssl connection cipher */ + GDS_SSL_TYPE, /* gds ssl connection cipher */ + CIPHER_TYPE_MAX /* The max number of types should be at the end */ +} CipherType; + +extern void gen_cipher_rand_files( + KeyMode mode, const char* plain_key, const char* user_name, const char* datadir, const char* preStr); +extern void decode_cipher_files( + KeyMode mode, const char* user_name, const char* datadir, GS_UCHAR* plainpwd, bool obs_server_mode = false); +extern bool check_input_password(const char* password); +extern bool EncryptInputKey(GS_UCHAR* pucPlainText, GS_UCHAR* initrand, GS_UCHAR* keySaltVector, + GS_UCHAR* encryptVector, GS_UCHAR* pucCipherText, GS_UINT32* pulCLen); +extern bool ReadContentFromFile(const char* filename, void* content, size_t csize); +extern bool check_certificate_signature_algrithm(const SSL_CTX* SSL_context); +extern long check_certificate_time(const SSL_CTX* SSL_context, const int alarm_days); +extern bool CipherFileIsValid(CipherkeyFile* cipher); +extern bool RandFileIsValid(RandkeyFile* randfile); +extern void ClearCipherKeyFile(CipherkeyFile* cipher_file_content); +extern void ClearRandKeyFile(RandkeyFile* rand_file_content); +extern bool DecryptInputKey(GS_UCHAR* pucCipherText, GS_UINT32 ulCLen, GS_UCHAR* initrand, GS_UCHAR* initVector, + GS_UCHAR* decryptVector, GS_UCHAR* pucPlainText, GS_UINT32* pulPLen); + +extern bool getTransEncryptKeyString(GS_UCHAR** cipherKey, GS_UCHAR** rndm); +extern bool getAkSkForTransEncrypt(char* ak, int akbuflen, char* sk, int skbuflen); +extern bool getKeyVectorFromCipherFile(const char* cipherkeyfile, const char* cipherrndfile, GS_UCHAR* key, GS_UCHAR* vector); +extern bool encryptStringByAES128Speed(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern char* getGaussHome(); +extern bool getAndCheckTranEncryptDEK(); + +extern char* SEC_decodeBase64(const char* pucInBuf, GS_UINT32* pulOutBufLen); +extern char* SEC_encodeBase64(const char* pucInBuf, GS_UINT32 ulInBufLen); +extern GS_UINT32 CRYPT_encrypt(GS_UINT32 ulAlgId, const GS_UCHAR* pucKey, GS_UINT32 ulKeyLen, const GS_UCHAR* pucIV, + GS_UINT32 ulIVLen, GS_UCHAR* pucPlainText, GS_UINT32 ulPlainLen, GS_UCHAR* pucCipherText, GS_UINT32* pulCLen); +extern GS_UINT32 CRYPT_decrypt(GS_UINT32 ulAlgId, const GS_UCHAR* pucKey, GS_UINT32 ulKeyLen, const GS_UCHAR* pucIV, + GS_UINT32 ulIVLen, GS_UCHAR* pucCipherText, GS_UINT32 ulCLen, GS_UCHAR* pucPlainText, GS_UINT32* pulPLen); +extern GS_UINT32 CRYPT_hmac(GS_UINT32 ulAlgType, const GS_UCHAR* pucKey, GS_UINT32 upucKeyLen, const GS_UCHAR* pucData, + GS_UINT32 ulDataLen, GS_UCHAR* pucDigest, GS_UINT32* pulDigestLen); + +#endif diff -uprN postgresql-hll-2.14_old/include/cjson/cJSON.h postgresql-hll-2.14/include/cjson/cJSON.h --- postgresql-hll-2.14_old/include/cjson/cJSON.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cjson/cJSON.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,294 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif + +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +#define CJSON_CDECL __cdecl +#define CJSON_STDCALL __stdcall + +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type CJSON_STDCALL +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#endif +#else /* !__WINDOWS__ */ +#define CJSON_CDECL +#define CJSON_STDCALL + +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 7 +#define CJSON_VERSION_PATCH 13 + +#include + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; + + /* The type of the item, as above. */ + int type; + + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); + +/* Render a cJSON entity to text for transfer/storage. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* Check item type and return its value */ +CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* Create a string where valuestring references a string so + * it will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); +/* Create an object/array that only references it's elements so + * they will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); + +/* These utilities create an Array of count items. + * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detach items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + * need to be released. With recurse!=0, it will duplicate any children connected to the item. + * The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); + +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. + * The input pointer json cannot point to a read-only address area, such as a string constant, + * but should point to a readable and writable adress area. */ +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Helper functions for creating and adding items to an object at the same time. + * They return the added item or NULL on failure. */ +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); + +/* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); + +CJSON_PUBLIC(unsigned char*) cJSON_strdup(const unsigned char* string); +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/cjson/cJSON_Utils.h postgresql-hll-2.14/include/cjson/cJSON_Utils.h --- postgresql-hll-2.14_old/include/cjson/cJSON_Utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cjson/cJSON_Utils.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,88 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON_Utils__h +#define cJSON_Utils__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "cJSON.h" + +/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */ +CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer); +CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointerCaseSensitive(cJSON * const object, const char *pointer); + +/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */ +/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */ +CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to); +CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to); +/* Utility for generating patch array entries. */ +CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value); +/* Returns 0 for success. */ +CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches); +CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches); + +/* +// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use: +//int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches) +//{ +// cJSON *modme = cJSON_Duplicate(*object, 1); +// int error = cJSONUtils_ApplyPatches(modme, patches); +// if (!error) +// { +// cJSON_Delete(*object); +// *object = modme; +// } +// else +// { +// cJSON_Delete(modme); +// } +// +// return error; +//} +// Code not added to library since this strategy is a LOT slower. +*/ + +/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */ +/* target will be modified by patch. return value is new ptr for target. */ +CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch); +CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch); +/* generates a patch to move from -> to */ +/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */ +CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON * const from, cJSON * const to); +CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatchCaseSensitive(cJSON * const from, cJSON * const to); + +/* Given a root object and a target object, construct a pointer from one to the other. */ +CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const object, const cJSON * const target); + +/* Sorts the members of the object into alphabetical order. */ +CJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON * const object); +CJSON_PUBLIC(void) cJSONUtils_SortObjectCaseSensitive(cJSON * const object); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/client_logic/cache.h postgresql-hll-2.14/include/client_logic/cache.h --- postgresql-hll-2.14_old/include/client_logic/cache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/client_logic/cache.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cache.h + * + * IDENTIFICATION + * src\include\client_logic\cache.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include "utils/syscache.h" +#include "access/htup.h" + +HeapTuple search_syscache_cmk_name(const char *key_name, Oid namespace_id); +HeapTuple search_sys_cache_ce_col_name(Oid relid, const char *attname); +HeapTuple search_sys_cache_copy_ce_col_name(Oid relid, const char *attname); +bool search_sys_cache_exists_ce_col_name(Oid relid, const char *attname); diff -uprN postgresql-hll-2.14_old/include/client_logic/client_logic_common.h postgresql-hll-2.14/include/client_logic/client_logic_common.h --- postgresql-hll-2.14_old/include/client_logic/client_logic_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/client_logic/client_logic_common.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic_common.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic_common.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_CL_COMMON_H +#define GS_CL_COMMON_H + +#include +#include "cstrings_map.h" + +enum class ArgsParseState { + KEY, + VALUE, + FLUSH +}; + +typedef CStringsMap StringArgsVec; +#endif diff -uprN postgresql-hll-2.14_old/include/client_logic/client_logic_enums.h postgresql-hll-2.14/include/client_logic/client_logic_enums.h --- postgresql-hll-2.14_old/include/client_logic/client_logic_enums.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/client_logic/client_logic_enums.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,103 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic_enums.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic_enums.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include + +typedef enum class CmkKeyStore { + INVALID_KEYSTORE = -1, + GS_KTOOL +} CmkKeyStore; + +typedef enum class CmkAlgorithm { + INVALID_ALGORITHM, + AES_256_CBC +} CmkAlgorithm; + +typedef enum class EncryptionType { + NONE, + RANDOMIZED, + DETERMINISTIC +} EncryptionType; + + +typedef enum ColumnEncryptionAlgorithm { + INVALID_ALGORITHM, + AEAD_AES_256_CBC_HMAC_SHA256, + AEAD_AES_128_CBC_HMAC_SHA256 +} ColumnEncryptionAlgorithm; + + +inline ColumnEncryptionAlgorithm get_cek_algorithm_from_string(const char *alg) +{ + if (alg == NULL || strlen(alg) == 0) { + return ColumnEncryptionAlgorithm::INVALID_ALGORITHM; + } + if (strncasecmp(alg, "AEAD_AES_256_CBC_HMAC_SHA256", strlen("AEAD_AES_256_CBC_HMAC_SHA256")) == 0) { + return ColumnEncryptionAlgorithm::AEAD_AES_256_CBC_HMAC_SHA256; + } else if (strncasecmp(alg, "AEAD_AES_128_CBC_HMAC_SHA256", strlen("AEAD_AES_128_CBC_HMAC_SHA256")) == 0) { + return ColumnEncryptionAlgorithm::AEAD_AES_128_CBC_HMAC_SHA256; + } + return ColumnEncryptionAlgorithm::INVALID_ALGORITHM; +} + +inline CmkKeyStore get_key_store_from_string(const char *key_store) +{ + if (key_store == NULL || strlen(key_store) == 0) { + return CmkKeyStore::INVALID_KEYSTORE; + } + + if (strncasecmp(key_store, "gs_ktool", strlen("gs_ktool")) == 0) { + return CmkKeyStore::GS_KTOOL; + } + + return CmkKeyStore::INVALID_KEYSTORE; +} + +inline CmkAlgorithm get_algorithm_from_string(const char *algorithm) +{ + if (algorithm == NULL || strlen(algorithm) == 0) { + return CmkAlgorithm::INVALID_ALGORITHM; + } + + if (strncasecmp(algorithm, "AES_256_CBC", strlen("AES_256_CBC")) == 0) { + return CmkAlgorithm::AES_256_CBC; + } + + return CmkAlgorithm::INVALID_ALGORITHM; +} + +inline EncryptionType get_algorithm_type_from_string(const char *algorithm_type) +{ + if (algorithm_type == NULL || strlen(algorithm_type) == 0) { + return EncryptionType::NONE; + } + if (strncasecmp(algorithm_type, "DETERMINISTIC", strlen("DETERMINISTIC")) == 0) { + return EncryptionType::DETERMINISTIC; + } else if (strncasecmp(algorithm_type, "RANDOMIZED", strlen("RANDOMIZED")) == 0) { + return EncryptionType::RANDOMIZED; + } + + return EncryptionType::NONE; +} diff -uprN postgresql-hll-2.14_old/include/client_logic/client_logic.h postgresql-hll-2.14/include/client_logic/client_logic.h --- postgresql-hll-2.14_old/include/client_logic/client_logic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/client_logic/client_logic.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include "postgres.h" +#include "catalog/heap.h" +#include "client_logic_common.h" +int set_column_encryption(const ColumnDef *def, CeHeapInfo *ce_heap_info); +int process_global_settings(CreateClientLogicGlobal *parsetree); +int process_column_settings(CreateClientLogicColumn *parsetree); +int drop_global_settings(DropStmt *stmt); +int drop_column_settings(DropStmt *stmt); +void remove_cmk_by_id(Oid id); +void remove_cek_by_id(Oid id); +void remove_encrypted_col_by_id(Oid id); +void remove_cmk_args_by_id(Oid id); +void remove_cek_args_by_id(Oid id); +void insert_gs_sec_encrypted_column_tuple(CeHeapInfo *ce_heap_info, Relation rel, const Oid rel_id, + CatalogIndexState indstate); diff -uprN postgresql-hll-2.14_old/include/client_logic/cstrings_map.h postgresql-hll-2.14/include/client_logic/cstrings_map.h --- postgresql-hll-2.14_old/include/client_logic/cstrings_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/client_logic/cstrings_map.h 2020-12-12 17:06:43.094346064 +0800 @@ -0,0 +1,65 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cstrings_map.h + * + * IDENTIFICATION + * src\include\client_logic\cstrings_map.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include +#include + +#define MAX_VAL_LEN 1024 +#define NAMEDATALEN 64 +#define NAME_CNT 4 + +struct ConstKeyValue { + char key[NAMEDATALEN + 1]; + char value[MAX_VAL_LEN]; + size_t valsize; +}; + +class CStringsMap { +public: + CStringsMap(); + CStringsMap(const CStringsMap &other); + CStringsMap &operator = (const CStringsMap &other); + ~CStringsMap(); + void set(const char *key, const char *value, size_t valsize = 0); + void clear(); + const char *find(const char *key) const; + const char *find(const char *key, size_t *size) const; + const size_t Size() const + { + return size; + } + ConstKeyValue *at(size_t i) const + { + if (i < size) { + return &k_v_map[i]; + } else { + return NULL; + } + } + +private: + size_t size; + struct ConstKeyValue *k_v_map; + const size_t index(const char *key) const; +}; diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_alarm.h postgresql-hll-2.14/include/cm/cm_agent/cma_alarm.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_alarm.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,42 @@ +/** + * @file cma_alarm.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_ALARM_H +#define CMA_ALARM_H + +extern Alarm* StartupAlarmList; +extern int StartupAlarmListSize; + +extern Alarm* AbnormalAlarmList; +extern int AbnormalAlarmListSize; + +extern Alarm* AbnormalCmaConnAlarmList; +extern int AbnormalCmaConnAlarmListSize; + +extern Alarm* AbnormalBuildAlarmList; +extern Alarm* AbnormalDataInstDiskAlarmList; +extern int DatanodeAbnormalAlarmListSize; + +extern Alarm* AbnormalEtcdAlarmList; +extern int AbnormalEtcdAlarmListSize; + +extern void StorageScalingAlarmItemInitialize(void); +extern void ReportStorageScalingAlarm(AlarmType alarmType, const char* instanceName, int alarmIndex); +extern void StartupAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void AbnormalAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void AbnormalCmaConnAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void DatanodeAbnormalAlarmItemInitialize(staticNodeConfig* g_currentNode); + +extern void report_build_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); +extern void report_dn_disk_alarm(AlarmType alarmType, char* instanceName, int alarmIndex, char* data_path); +extern void report_etcd_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); +extern void InitializeAlarmItem(staticNodeConfig* g_currentNode); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_common.h postgresql-hll-2.14/include/cm/cm_agent/cma_common.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_common.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,31 @@ +/** + * @file cma_common.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_COMMON_H +#define CMA_COMMON_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +void set_thread_state(pthread_t thrId); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); + +char* type_int_to_str_binname(InstanceTypes ins_type); +char* type_int_to_str_name(InstanceTypes ins_type); + +int ExecuteCmd(const char* command, struct timeval timeout); +int cmagent_getenv(const char* env_var, char* output_env_value, uint32 env_value_len); + +void listen_ip_merge(uint32 ip_count, char ip_listen[][CM_IP_LENGTH], char* ret_ip_merge, uint32 ipMergeLength); +void reload_parameters_from_configfile(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_connect.h postgresql-hll-2.14/include/cm/cm_agent/cma_connect.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_connect.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_connect.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,29 @@ +/** + * @file cma_connect.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_CONNECT_H +#define CMA_CONNECT_H + +#include "cm/libpq-fe.h" +#include "cm/libpq-int.h" + +#define MAX_PRE_CONN_CMS 2 +#define MAX_CONN_TIMEOUT 3 + +extern CM_Conn* agent_cm_server_connect; +extern CM_Conn* GetConnToCmserver(uint32 nodeid); + +void CloseConnToCmserver(void); + +int cm_client_flush_msg(CM_Conn* conn); +int cm_client_send_msg(CM_Conn* conn, char msgtype, const char* s, size_t lenmsg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_coordinator.h postgresql-hll-2.14/include/cm/cm_agent/cma_coordinator.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_coordinator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_coordinator.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,44 @@ +/** + * @file cma_coordinator.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_COORDINATOR_H +#define CMA_COORDINATOR_H + +#include "cm/cm_msg.h" + +void* auto_repair_cn(void* arg); + +int set_pgxc_node_isactive_to_false(); +int cmagent_to_coordinator_disconnect(void); +int cm_check_to_coordinate_node_group(char* pid_path, char* node_group_name1, char* node_group_members1, + char* node_group_name2, char* node_group_members2); +int cm_static_config_check_to_coordinate_wrapper(const char* pid_path, int* coordinate_node_check, + char data_node_check[][CM_MAX_DATANODE_PER_NODE], char* name_record[CM_NODE_MAXNUM * CM_MAX_INSTANCE_PER_NODE], + uint32* name_record_count, int* currentNodeNum); +int coordinate_status_check_and_report_wrapper( + const char* pid_path, agent_to_cm_coordinate_status_report* report_msg, uint32 lc_count); +int drop_fault_coordinator(const char* pid_path, agent_to_cm_coordinate_status_report* report_msg); +int agent_notify_coordinator_cancel_session(const char* pid_path); +int process_notify_ccn_command(const cm_to_agent_notify_cn_central_node* notify); +int coordinate_status_check_phony_dead(const char* pid_path); +int process_notify_ccn_command_internal(const char* pid_path); +int update_ha_relation_to_coordinator(const char* pid_path); + +bool create_connection_to_healthcn(uint32 healthCn); +bool IsCnDnDisconnected(); +bool lock_coordinator(); +bool unlock_coordinator(); +bool update_pgxc_node(uint32 healthCn); +bool start_delay_xlog_recycle(); +bool stop_delay_xlog_recycle(); +void CnDnDisconnectCheck(); +void close_reset_conn(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_create_conn_cms.h postgresql-hll-2.14/include/cm/cm_agent/cma_create_conn_cms.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_create_conn_cms.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_create_conn_cms.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,21 @@ +/** + * @file cma_create_conn_cms.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_CREATE_CONN_CMS_H +#define CMA_CREATE_CONN_CMS_H + +typedef enum CMA_OPERATION_ { + CMA_KILL_SELF_INSTANCES = 0, +} cma_operation; + +void* ConnCmsPMain(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_datanode.h postgresql-hll-2.14/include/cm/cm_agent/cma_datanode.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_datanode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_datanode.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,37 @@ +/** + * @file cma_datanode.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_DATANODE_H +#define CMA_DATANODE_H + +#include "cma_main.h" + +void* DNStorageScalingCheckMain(void * const arg); + +bool is_process_alive(pgpid_t pid); + +pgpid_t get_pgpid(char* pid_path); + +uint32 GetDatanodeNumSort(staticNodeConfig* p_node_config, uint32 sort); + +int cm_check_install_nodegroup_is_exist(); +int cm_select_datanode_names( + char* pid_path, char datanode_names[][CM_NODE_NAME], char datanode_name_oids[][CM_NODE_NAME], int* datanode_count); +int ReadDBStateFile(GaussState* state, char* state_path); +int process_unlock_command(uint32 instance_id); +/* Agent to DN connection */ +int process_lock_no_primary_command(uint32 instance_id); +int process_lock_chosen_primary_command(cm_to_agent_lock2* msg_type_lock2_ptr); +int check_datanode_status(const char* pid_path, int* role); + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_datanode_utils.h postgresql-hll-2.14/include/cm/cm_agent/cma_datanode_utils.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_datanode_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_datanode_utils.h 2020-12-12 17:06:43.095346077 +0800 @@ -0,0 +1,73 @@ +/** + * @file cma_datanode_utils.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_DATANODE_UTILS_H +#define CMA_DATANODE_UTILS_H + +#include "libpq/libpq-int.h" +#include "libpq/libpq-fe.h" +#include "cma_main.h" + + +#define close_and_reset_connection(conn) \ + if (conn != NULL) { \ + closePGconn(conn); \ + freePGconn(conn); \ + conn = NULL; \ + } + +#define CLOSE_CONNECTION(con) \ + do { \ + close_and_reset_connection(con); \ + assert(NULL == con); \ + return -1; \ + } while (0) + +#define CLEAR_AND_CLOSE_CONNECTION(node_result, con) \ + do { \ + PQclear(node_result); \ + close_and_reset_connection(con); \ + assert(NULL == con); \ + return -1; \ + } while (0) + + +int GetAllDatabaseInfo(int index, DNDatabaseInfo **dnDatabaseInfo, int *dnDatabaseCount); +int GetDBTableFromSQL(int index, uint32 databaseId, uint32 tableId, uint32 tableIdSize, + DNDatabaseInfo *dnDatabaseInfo, int dnDatabaseCount, char* databaseName, char* tableName); +int cmagent_execute_query_and_check_result(PGconn* db_connection, const char* run_command); +int cmagent_execute_query(PGconn* db_connection, const char* run_command); + +const int MAXCONNINFO = 1024; +extern PGconn* DN_conn[CM_MAX_DATANODE_PER_NODE]; +extern THR_LOCAL PGconn* g_Conn; + +extern void check_parallel_redo_status_by_file( + agent_to_cm_datanode_status_report* report_msg, uint32 ii, char* redo_state_path); +extern int check_datanode_status_by_SQL0(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL1(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL2(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL3(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL4(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern void check_datanode_status_by_SQL5(agent_to_cm_datanode_status_report* report_msg, uint32 ii, char* data_path); +extern int check_datanode_status_by_SQL6( + agent_to_cm_datanode_status_report* report_msg, uint32 ii, const char* data_path); +extern int cmagent_execute_query(PGconn* db_connection, const char* run_command); +extern int cmagent_execute_query_and_check_result(PGconn* db_connection, const char* run_command); + +extern int cmagent_to_coordinator_connect(const char* pid_path); +uint32 find_cn_active_info_index(agent_to_cm_coordinate_status_report_old* report_msg, uint32 coordinatorId); +extern int is_cn_connect_ok(uint32 coordinatorId); +extern int datanode_rebuild_reason_enum_to_int(HaRebuildReason reason); +extern PGconn* get_connection(const char* pid_path, bool isCoordinater = false, int connectTimeOut = 5); +extern LocalMaxLsnMng g_LMLsn[CM_MAX_DATANODE_PER_NODE]; + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_global_params.h postgresql-hll-2.14/include/cm/cm_agent/cma_global_params.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_global_params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_global_params.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,232 @@ +/** + * @file cma_global_params.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_GLOBAL_PARAMS_H +#define CMA_GLOBAL_PARAMS_H + +#include "cm/cm_c.h" +#include "cm/cm_misc.h" +#include "cm/etcdapi.h" +#include "cma_main.h" + +typedef enum MAINTENANCE_MODE_ { + MAINTENANCE_MODE_NONE = 0, + MAINTENANCE_MODE_UPGRADE, + MAINTENANCE_MODE_UPGRADE_OBSERVATION, + MAINTENANCE_MODE_DILATATION, +} maintenance_mode; + +#define CM_SERVER_DATA_DIR "cm_server" +#define CM_INSTANCE_REPLACE "instance_replace" +#define PROC_NET_TCP "/proc/net/tcp" + +/* + * ssh connect does not exit automatically when the network is fault, + * this will cause cm_ctl hang for several hours, + * so we should add the following timeout options for ssh. + */ +#define SSH_CONNECT_TIMEOUT "5" +#define SSH_CONNECT_ATTEMPTS "3" +#define SSH_SERVER_ALIVE_INTERVAL "15" +#define SSH_SERVER_ALIVE_COUNT_MAX "3" +#define PSSH_TIMEOUT_OPTION \ + " -t 60 -O ConnectTimeout=" SSH_CONNECT_TIMEOUT " -O ConnectionAttempts=" SSH_CONNECT_ATTEMPTS \ + " -O ServerAliveInterval=" SSH_SERVER_ALIVE_INTERVAL " -O ServerAliveCountMax=" SSH_SERVER_ALIVE_COUNT_MAX " " + +/* UDF_DEFAULT_MEMORY is 200*1024 kB */ +/* Must be same as UDF_DEFAULT_MEMORY in memprot.h and udf_memory_limit in cluster_guc.conf */ +#define UDF_DEFAULT_MEMORY (200 * 1024) +#define AGENT_RECV_CYCLE (200 * 1000) +#define AGENT_REPORT_ETCD_CYCLE 600 +#define INSTANCE_ID_LEN 8 +#define SINGLE_INSTANCE 0 +#define SINGLE_NODE 1 +#define ALL_NODES 2 +#define COMM_PORT_TYPE_DATA 1 +#define COMM_PORT_TYPE_CTRL 2 +#define MAX_RETRY_TIME 10 +#define MAX_INSTANCE_BUILD 3 +#define COMM_DATA_DFLT_PORT 7000 +#define COMM_CTRL_DFLT_PORT 7001 + +#define INSTANCE_START_CYCLE 20 +#define INSTANCE_BUILD_CYCLE 10 + +#define STARTUP_DN_CHECK_TIMES 3 +#define STARTUP_CN_CHECK_TIMES 3 +#define STARTUP_GTM_CHECK_TIMES 3 +#define STARTUP_CMS_CHECK_TIMES 3 + +#define LISTEN 10 + +extern struct passwd* pw; +extern FILE* lockfile; +extern EtcdSession g_sess; +extern cm_instance_central_node g_central_node; +extern gtm_status_info gtm_report_msg; +extern coordinate_status_info cn_report_msg; +extern datanode_status_info dn_report_msg[CM_MAX_DATANODE_PER_NODE]; +extern etcd_status_info etcd_report_msg; +extern kerberos_status_info g_kerberos_report_msg; +/* Enable the datanode incremental build mode */ +extern volatile bool incremental_build; +extern volatile bool security_mode; +extern bool enable_xc_maintenance_mode; +extern char sys_log_path[MAX_PATH_LEN]; +extern FILE* syslogFile; +extern LocalMaxLsnMng g_LMLsn[CM_MAX_DATANODE_PER_NODE]; +extern pthread_t g_repair_cn_thread; +extern struct timeval gServerHeartbeatTime; +extern struct timeval gDisconnectTime; + +extern EtcdTlsAuthPath g_tlsPath; +extern pthread_t g_thread_id[CM_MAX_DATANODE_PER_NODE + 5]; +extern syscalllock cmagent_env_lock; + +extern const char* progname; +extern char configDir[MAX_PATH_LEN]; +extern char bin_path[MAX_PATH_LEN]; +extern char cmagent_lockfile[MAX_PATH_LEN]; +extern char run_long_command[MAX_LOGIC_DATANODE * CM_NODE_NAME + 64]; +extern char cn_name_buf[MAXPGPATH]; +extern char logic_cluster_list_path[MAXPGPATH]; +extern char system_call_log_name[MAXPGPATH]; +extern char result_path[MAX_PATH_LEN]; +extern char cm_agent_log_path[MAX_PATH_LEN]; +extern char cm_static_configure_path[MAX_PATH_LEN]; +extern char cm_manual_start_path[MAX_PATH_LEN]; +extern char cm_instance_manual_start_path[MAX_PATH_LEN]; +extern char cm_resuming_cn_stop_path[MAX_PATH_LEN]; +extern int datanode_num; +extern char datanode_names[MAX_LOGIC_DATANODE][CM_NODE_NAME]; +extern char datanode_name_oids[MAX_LOGIC_DATANODE][CM_NODE_NAME]; +extern char system_alarm_log[MAXPGPATH]; +extern char dn_name_buf[MAX_LOGIC_DATANODE * CM_NODE_NAME]; +extern char node_group_members1[MAX_NODE_GROUP_MEMBERS_LEN]; +extern char node_group_members2[MAX_NODE_GROUP_MEMBERS_LEN]; +extern char cm_cluster_resize_path[MAX_PATH_LEN]; +extern char cm_cluster_replace_path[MAX_PATH_LEN]; +extern char system_call_log[MAXPGPATH]; +extern char g_unix_socket_directory[MAXPGPATH]; +extern char log_base_path[MAXPGPATH]; +extern char g_enable_cn_auto_repair[10]; +extern char g_enableOnlineOrOffline[10]; +extern char g_enableLogCompress[10]; +extern char instance_maintance_path[MAX_PATH_LEN]; + +extern volatile bool g_repair_cn; +extern bool shutdown_request; +extern bool g_sync_dropped_coordinator; +extern bool exit_flag; +extern bool cm_do_force; /* stop by force */ +extern bool g_pgxc_node_consist; +extern bool cm_agent_first_start; +extern bool cm_static_config_need_verify_to_coordinator; +extern bool cm_server_need_reconnect; +extern bool cm_agent_need_alter_pgxc_node; +extern bool cm_agent_need_check_libcomm_port; +extern bool is_cma_building_dn[CM_MAX_DATANODE_PER_NODE]; +extern bool needUpdateSecboxConf; +extern bool gtm_disk_damage; +extern bool cn_disk_damage; +extern bool cms_disk_damage; +extern bool fenced_UDF_stopped; +extern bool cn_nic_down; +extern bool cms_nic_down; +extern bool gtm_nic_down; +extern bool dn_disk_damage[CM_MAX_DATANODE_PER_NODE]; +extern bool dn_build[CM_MAX_DATANODE_PER_NODE]; +extern bool nic_down[CM_MAX_DATANODE_PER_NODE]; +extern bool g_cm_server_instance_pending; +extern bool cm_agent_first_start; +extern bool isStart; +extern bool suppressAlarm; +extern bool g_need_reload_active; + +extern const uint32 AGENT_WATCH_DOG_THRESHOLD; +/* cm_agent config parameters */ +extern uint32 agent_report_interval; +extern uint32 agent_heartbeat_timeout; +extern uint32 agent_connect_timeout; +extern uint32 agent_connect_retries; +extern uint32 agent_check_interval; +extern uint32 agent_kill_instance_timeout; +extern uint32 agent_kerberos_status_check_interval; +extern uint32 agentDiskUsageStatusCheckTimes; +extern uint32 cn_auto_repair_delay; +extern uint32 dilatation_shard_count_for_disk_capacity_alarm; +extern uint32 g_check_disc_instance_now; +extern uint32 g_nodeId; +extern uint32 g_health_cn_for_repair; +extern uint32 agent_phony_dead_check_interval; +extern uint32 g_agentToDb; +extern uint32 thread_dead_effective_time; +extern uint32 enable_gtm_phony_dead_check; +extern uint32 g_cmaConnectCmsInOtherNodeCount; +extern uint32 g_cmaConnectCmsPrimaryInLocalNodeCount; +extern uint32 g_cmaConnectCmsInOtherAzCount; +extern uint32 g_cmaConnectCmsPrimaryInLocalAzCount; +extern uint32 dn_build_check_times[CM_MAX_DATANODE_PER_NODE]; +extern uint32 g_node_index_for_cm_server[CM_PRIMARY_STANDBY_NUM]; + +extern const int cn_repair_build_full; +extern const int cn_repair_build_incre; +extern int cm_shutdown_level; /* cm_ctl stop single instance, single node or all nodes */ +extern int cm_shutdown_mode; /* fast shutdown */ +extern int cn_frequent_restart_counts; +extern int g_CnDnPairsCount; +extern int is_catalog_changed; +extern int g_currenPgxcNodeNum; +extern int normalStopTryTimes; +extern int gtm_start_counts; +extern int co_start_counts; +extern int dn_start_counts[CM_MAX_DATANODE_PER_NODE]; +extern int primary_dn_restart_counts[CM_MAX_DATANODE_PER_NODE]; +extern int primary_dn_restart_counts_in_hour[CM_MAX_DATANODE_PER_NODE]; + +extern int startCMSCount; +extern int startCNCount; +extern int startDNCount[CM_MAX_DATANODE_PER_NODE]; +extern int startGTMCount; +extern int g_clean_drop_cn_flag; +extern int g_cm_server_instance_status; +extern int g_dn_role_for_phony_dead[CM_MAX_DATANODE_PER_NODE]; +extern int g_gtm_role_for_phony_dead; +extern int g_cn_state_for_phony_dead; +extern int g_dn_phony_dead_times[CM_MAX_DATANODE_PER_NODE]; +extern int g_gtm_phony_dead_times; +extern int g_cn_phony_dead_times; +extern volatile uint32 g_cn_dn_disconnect_times; + +extern int64 log_max_size; +extern uint32 log_max_count; +extern uint32 log_saved_days; +extern uint32 log_threshold_check_interval; +extern long g_check_disc_state; +extern long g_thread_state[CM_MAX_DATANODE_PER_NODE + 5]; +extern uint32 g_serverNodeId; +#define FENCE_TIMEOUT (agent_connect_retries * (agent_connect_timeout + agent_report_interval)) + +#ifdef __aarch64__ +extern uint32 agent_process_cpu_affinity; +extern uint32 g_datanode_primary_and_standby_num; +extern uint32 g_datanode_primary_num; +extern uint32 total_cpu_core_num; +extern bool g_dn_report_msg_ok; +/* cm_agent start_command parameters */ +#define PHYSICAL_CPU_NUM (1 << agent_process_cpu_affinity) +#define CPU_AFFINITY_MAX 2 +#endif + +bool find_instance_by_id( + uint32 instanceId, int* instance_type, uint32* node, uint32* node_index, uint32* instance_index); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_gtm.h postgresql-hll-2.14/include/cm/cm_agent/cma_gtm.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_gtm.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_gtm.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_GTM_H +#define CMA_GTM_H + +#include "gtm/gtm_c.h" +#include "gtm/utils/libpq-fe.h" +#include "cm/cm_c.h" + +extern void* GtmModeMain(void* arg); +extern GTM_Conn* GetConnectionToGTM(char gtm_pid_file[MAXPGPATH], int connectTimeOut = 5); +extern void CloseGTMConnection(GTM_Conn* conn); + +/* this is used for cm_agent to query gtm status. */ +extern int query_gtm_status(GTM_Conn* conn, int* server_mode, int* connection_status, GlobalTransactionId* pxid, + long* send_count, long* receive_count, int* sync_mode); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_instance_management.h postgresql-hll-2.14/include/cm/cm_agent/cma_instance_management.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_instance_management.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_instance_management.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,37 @@ +/** + * @file cma_instance_management.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_INSTANCE_MANAGEMENT_H +#define CMA_INSTANCE_MANAGEMENT_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +#define MAX_BUF_LEN 10 +#define CHECK_DN_BUILD_TIME 25 + +void start_coordinator(); +void kill_instance_force(const char* data_path, InstanceTypes ins_type); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); +void immediate_shutdown_nodes(bool kill_cmserver, bool kill_cn); +void* agentStartAndStopMain(void* arg); + +bool ExecuteCmdWithResult(char* cmd, char* result); +bool getnicstatus(uint32 listen_ip_count, char ips[][CM_IP_LENGTH]); +bool Is_cluster_replacing(void); +bool Is_cluster_resizing(void); + +int agentCheckPort(uint32 port); + +uint32 GetLibcommPort(const char* file_path, uint32 base_port, int port_type); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_log_management.h postgresql-hll-2.14/include/cm/cm_agent/cma_log_management.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_log_management.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_log_management.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,31 @@ +/** + * @file cma_log_management.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_LOG_MANAGEMENT_H +#define CMA_LOG_MANAGEMENT_H + +/* compress buffer size */ +#define GZ_BUFFER_LEN 65535 +/* + * trace will be deleted directly if exceeded LOG_GUARD_COUNT + * the priority of this guard higher than save days but lower than maximum capacity + */ +#define LOG_GUARD_COUNT 20000 +#define LOG_GUARD_COUNT_BUF 21000 + +/* Initialize log pattern and log count when started */ +extern LogPattern* logPattern; +extern uint32 len; + +int isLogFile(char* fileName); +int get_log_pattern(); +void* CompressAndRemoveLogFile(void* arg); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_main.h postgresql-hll-2.14/include/cm/cm_agent/cma_main.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_main.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_main.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,228 @@ +/** + * @file cma_main.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-11 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_MAIN_H +#define CMA_MAIN_H + + +#include "common/config/cm_config.h" +#include "alarm/alarm.h" +#include "cm/elog.h" +#include "cm/cm_msg.h" +#include "cma_alarm.h" + +#define STOP_PRIMARY_RESULT "stop_primary_result" +#define CHECK_VERSION_RESULT "check_version_result" + +#define CM_AGENT_LOG_FILE "cm_agent.log" +#define CM_STATIC_CONFIG_FILE "cluster_static_config" +#define CM_CLUSTER_MANUAL_START "cluster_manual_start" +#define CM_INSTANCE_MANUAL_START "instance_manual_start" +#define CM_RESUMING_CN_STOP "resuming_cn_stop" +#define CM_CLUSTER_RESIZE "cluster_resize.progress" +#define CM_CLUSTER_REPLACE "cluster_replace.progress" +#define LOGIC_CLUSTER_LIST "logic_cluster_name.txt" +#define CM_AGENT_DATA_DIR "cm_agent" +#define INSTANCE_MAINTANCE "instance_maintance" +#define SYSTEM_CALL_LOG "system_call" +#define MAX_LOGFILE_TIMESTAMP "99991231235959" + +#define CONN_FAIL_TIMES 3 +#define MAX_PATH_LEN 1024 +/*time style length*/ +#define MAX_TIME_LEN 20 +const int cn_repair_retry_times = 3; +/* interval set to 10s to reduce invalid log */ +const uint32 g_check_dn_sql5_interval = 10; + +typedef long pgpid_t; + +/* These global variables are used to compressed traces */ +typedef struct LogFile { + char fileName[MAX_PATH_LEN]; + char basePath[MAX_PATH_LEN]; + char pattern[MAX_TIME_LEN]; + char timestamp[MAX_TIME_LEN]; + int64 fileSize; +} LogFile; + +/* Log pattern for compress */ +typedef struct LogPattern { + char patternName[MAX_PATH_LEN]; +} LogPattern; + +/* get local max lsn */ +typedef struct LocalMaxLsnMng { + bool checked; + XLogRecPtr max_lsn; +} LocalMaxLsnMng; + +/* get dn database info */ +typedef struct DNDatabaseInfo { + char dbname[NAMEDATALEN]; + uint32 oid; +} DNDatabaseInfo; + +/* + * Cut time from trace name. + * This time will be used to sort traces. + */ +void cutTimeFromFileLog(const char* fileName, char* pattern, char* time); +/* + * Sort of trace file by time asc. + * This time is part of trace name. + */ +void sortLogFileByTimeAsc(LogFile* logFile, int low, int high); + +/* + * get the mode of the cluster. + */ +void get_start_mode(char* config_file); + +/* + * used for connection mode or option between cm_agent and cn/dn. + */ +void get_connection_mode(char* config_file); + +/* + * Read parameter from cm_agent.conf by accurate parameter name. + */ +int get_config_param(const char* config_file, const char* srcParam, char* destParam, int destLen); + +/* + * Compressed trace to gz by zlib. + * The gzread() function shall read data from the compressed file referenced by file, + * which shall have been opened in a read mode (see gzopen() and gzdopen()). The gzread() + * function shall read data from file, and * uncompress it into buf. At most, len + * bytes of uncompressed data shall be copied to buf. If the file is not compressed, + * gzread() shall simply copy data from file to buf without alteration. + * The gzwrite() function shall write data to the compressed file referenced by file, which shall + * have been opened in a write mode (see gzopen() and gzdopen()). On entry, buf shall point to a + * buffer containing lenbytes of uncompressed data. The gzwrite() function shall compress this + * data and write it to file. The gzwrite() function shall return the number of uncompressed + * bytes actually written. + */ + +int GZCompress(char* inpath, char* outpath); + +/* + * Get trace pattern from cm_agent.conf. + * All trace pattern to be compressed are defined in cm_agent.conf. + */ + +/* + * Create compress and remove thread for trace. + * Use Thread for this task avoid taking too much starting time of cm server. + */ +void CreateLogFileCompressAndRemoveThread(const char* patternName); + +/* + * Read all traces by log pattern,including zip file and non zip file. + * Trace information are file time,file size,file path.These traces are + * saved in the global variable. + */ +int readFileList(char* basePath, LogFile* logFile, uint32* count, int64* totalSize); +/* + * Remove a file. + * It's always used to remove a trace compressed. + */ +void delLogFile(const char* fileName); +extern int check_datanode_status_phony_dead(char pid_path[MAXPGPATH], int agentCheckTimeInterval); + +typedef enum { STARTING, ALL_NORMAL, INSTANCE_NEED_REPAIR, ALL_PENDING } ClusterStatus; + +typedef enum { INSTANCE_CN, INSTANCE_DN, INSTANCE_GTM, INSTANCE_CM, INSTANCE_FENCED, INSTANCE_KERBEROS} InstanceTypes; + +typedef enum { DOWN, PRIMARY, STANDBY, PENDING } InstanceStatus; + +typedef enum { UNKNOWN_HA_STATE, NORMAL_HA_STATE, NEED_REPAIR, BUILD } HAStatus; + +typedef enum { NA, SYSTEM_MARK_INCONSISTENT, TIMELINE_INCONSISTENT, LOG_NOT_EXIST } BuildReason; + +typedef enum { SMART_MODE, FAST_MODE, IMMEDIATE_MODE, RESUME_MODE } ShutdownMode; + +typedef enum { INSTANCE_START, INSTANCE_STOP } OperateType; + +typedef struct InstanceStatusReport { + uint32 node; + + char DataPath[CM_PATH_LENGTH]; + uint32 type; + uint32 InstanceStatus; + + char LogPath[CM_PATH_LENGTH]; + uint32 HAStatus; + uint32 reason; +} InstanceStatusReport; + +typedef enum { NORMAL, UNKNOWN } CoordinateStatus; + +typedef struct NodeStatusReport { + uint32 node; + char nodeName[CM_NODE_NAME]; + uint32 isCn; + uint32 CoordinateStatus; + uint32 isGtm; + InstanceStatusReport gtm; + uint32 datanodesNum; + InstanceStatusReport datanodes[CM_MAX_DATANODE_PER_NODE]; +} NodeStatusReport; + +typedef struct datanode_failover { + bool datanodes[CM_MAX_DATANODE_PER_NODE]; + bool coordinator; +} datanode_failover; + +typedef struct gtm_failover { + bool gtmnodes; + bool coordinator; +} gtm_failover; + +typedef struct coordinator_status { + int cn_status; + bool delayed_repair; +} coordinator_status; + +extern volatile bool g_repair_cn; +extern coordinator_status* g_cn_status; +extern bool* g_coordinators_drop; +extern pthread_rwlock_t g_coordinators_drop_lock; +extern uint32* g_dropped_coordinatorId; +extern bool g_coordinators_cancel; +extern pthread_rwlock_t g_coordinators_cancel_lock; +extern cm_instance_central_node_msg g_ccn_notify; + +/* Control whether agent request cluster state */ +extern bool pooler_ping_end_request; +/* Control whether agent close the pooler ping switch */ +extern bool pooler_ping_end; + +extern datanode_failover* g_datanodes_failover; +extern gtm_failover* g_gtms_failover; +extern pthread_rwlock_t g_datanodes_failover_lock; +extern pthread_rwlock_t g_gtms_failover_lock; +extern int g_gtmMode; + +extern int datanode_status_check_and_report_wrapper(agent_to_cm_datanode_status_report* report_msg, uint32 ii, + char* data_path, bool do_build, uint32 check_dn_sql5_timer); +extern int node_match_find(char* node_type, const char* node_port, const char* node_host, char* node_port1, + char* node_host1, int* node_index, int* instance_index, int* inode_type); +extern int check_one_instance_status(const char *process_name, const char *cmd_line, int *isPhonyDead); +extern void report_conn_fail_alarm(AlarmType alarmType, InstanceTypes instance_type, uint32 instanceId); +extern int get_connection_to_coordinator(); +typedef bool (*IsResultExpectedFunPtr)(const void*); +int cmagent_to_coordinator_execute_query(char* run_command, IsResultExpectedFunPtr IsResultExpected = NULL); +bool IsResultExpectedPoolReload(const void* result); + +#ifdef __aarch64__ +void process_bind_cpu(uint32 instance_index, uint32 primary_dn_index, pgpid_t pid); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_phony_dead_check.h postgresql-hll-2.14/include/cm/cm_agent/cma_phony_dead_check.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_phony_dead_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_phony_dead_check.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_phony_dead_check.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_PHONY_DEAD_CHECK_H +#define CMA_PHONY_DEAD_CHECK_H + +void* DNPhonyDeadStatusCheckMain(void * const arg); +void* CNPhonyDeadStatusCheckMain(void* arg); +void* GTMPhonyDeadStatusCheckMain(void* arg); +void* FaultDetectMain(void* arg); + + + + + + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_process_messages.h postgresql-hll-2.14/include/cm/cm_agent/cma_process_messages.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_process_messages.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_process_messages.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_process_messages.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_PROCESS_MESSAGES_H +#define CMA_PROCESS_MESSAGES_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +void* SendCmsMsgMain(void* arg); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); +void kill_instance_force(const char* data_path, InstanceTypes ins_type); +int search_HA_node(uint32 loal_port, uint32 LocalHAListenCount, char LocalHAIP[][CM_IP_LENGTH], uint32 Peer_port, + uint32 PeerHAListenCount, char PeerHAIP[][CM_IP_LENGTH], uint32* node_index, uint32* instance_index, + uint32 loal_role); +char* get_logicClusterName_by_dnInstanceId(uint32 dnInstanceId); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_status_check.h postgresql-hll-2.14/include/cm/cm_agent/cma_status_check.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_status_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_status_check.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,46 @@ +/** + * @file cma_status_check.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_STATUS_CHECK_H +#define CMA_STATUS_CHECK_H + +#define DN_RESTART_COUNT_CHECK_TIME 600 +#define DN_RESTART_COUNT_CHECK_TIME_HOUR 3600 + +#define MAX_DEVICE_DIR 1024 +#define FILE_CPUSTAT "/proc/stat" +#define FILE_DISKSTAT "/proc/diskstats" +#define FILE_MOUNTS "/proc/mounts" + +#define ETCD_NODE_UNHEALTH_FRE 15 +#define CHECK_INVALID_ETCD_TIMES 15 + +/* when report_interval has changed to bigger ,this number 3 will also change */ +#define CHECK_DUMMY_STATE_TIMES 3 + +void gtm_status_check_and_report(void); +void coordinator_status_check_and_report(void); +void datanode_status_check_and_report(void); +void fenced_UDF_status_check_and_report(void); +void etcd_status_check_and_report(void); +void kerberos_status_check_and_report(); +void CheckDiskForCNDataPathAndReport(); +void CheckDiskForDNDataPathAndReport(); + +void* ETCDStatusCheckMain(void* arg); +void* GTMStatusCheckMain(void* arg); +void* DNStatusCheckMain(void * const arg); +void* CNStatusCheckMain(void* arg); +void* CCNStatusCheckMain(void* const arg); +void* KerberosStatusCheckMain(void* const arg); + +void* CNDnDisconnectCheckMain(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_threads.h postgresql-hll-2.14/include/cm/cm_agent/cma_threads.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_threads.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,32 @@ +/** + * @file cma_thread.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_THREADS_H +#define CMA_THREADS_H + +void CreateETCDStatusCheckThread(); +void CreatePhonyDeadCheckThread(); +void CreateCnDnDisconnectCheckThread(); +void CreateStartAndStopThread(); +void CreateGTMStatusCheckThread(); +void CreateCNStatusCheckThread(); +void CreateCCNStatusCheckThread(void); +void CreateDNStatusCheckThread(int* i); +void CreateDNXlogCheckThread(int* i); +void CreateDNStorageScalingAlarmThread(int* i); +void CreateFaultDetectThread(); +void CreateGtmModeThread(); +void CreateConnCmsPThread(); +void CreateSendCmsMsgThread(); +void CreateKerberosStatusCheckThread(); +void CreateAutoRepairCnThread(); +void CreateLogFileCompressAndRemoveThread(); + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_agent/cma_xlog.h postgresql-hll-2.14/include/cm/cm_agent/cma_xlog.h --- postgresql-hll-2.14_old/include/cm/cm_agent/cma_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_agent/cma_xlog.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,70 @@ +/** + * @file cma_xlog.h + * @brief Define functions of reading xlog for agent. + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + + +#ifndef CMA_XLOG_H +#define CMA_XLOG_H + +#include "access/xlog_basic.h" + +typedef struct AgentXLogPageReadPrivate { + const char* datadir; + TimeLineID tli; +} AgentXLogPageReadPrivate; + +typedef struct AgentXlogFileList { + AgentXlogFileList* next; + char* filename; +} AgentXlogFileList; + +void* DNXlogCheckMain(void * const arg); + +/* + * Allocate and initialize a new XLogReader. + * + * Returns NULL if the xlogreader couldn't be allocated. + */ +extern XLogReaderState* AgentXLogReaderAllocate(XLogPageReadCB pagereadfunc, void* private_data); + +/* + * Find the first record with at an lsn >= RecPtr. + * + * Useful for checking wether RecPtr is a valid xlog address for reading and to + * find the first valid address after some address when dumping records for + * debugging purposes. + */ +extern XLogRecPtr AgentXLogFindNextRecord(XLogReaderState* state, XLogRecPtr RecPtr); + +/* + * Attempt to read an XLOG record. + * + * If RecPtr is not NULL, try to read a record at that position. Otherwise + * try to read a record just after the last one previously read. + * + * If the page read callback fails to read the requested data, NULL is + * returned. The callback is expected to have reported the error; errormsg + * is set to NULL. + * + * If the reading fails for some other reason, NULL is also returned, and + * *errormsg is set to a string with details of the failure. + * + * The returned pointer (or *errormsg) points to an internal buffer that's + * valid until the next call to XLogReadRecord. + */ +extern XLogRecord* AgentXLogReadRecord( + XLogReaderState* state, XLogRecPtr RecPtr, char** errormsg, bool readoldversion = false); + +/* + * Free the xlog reader memory. + */ +extern void AgentXLogReaderFree(XLogReaderState* state); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_cgroup.h postgresql-hll-2.14/include/cm/cm_cgroup.h --- postgresql-hll-2.14_old/include/cm/cm_cgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_cgroup.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_cgroup.h + * + * + * + * IDENTIFICATION + * src/include/cm/cm_cgroup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_CGROUP_H +#define CM_CGROUP_H +#ifdef ENABLE_MULTIPLE_NODES +/* get the cm cgroup relpath and initialize cgroup. + * Please note,caller should free the return value. + */ +extern char* gscgroup_cm_init(); + +/* make the current thread attach to cm cgroup */ +extern void gscgroup_cm_attach_task(const char* relpath); +extern void gscgroup_cm_attach_task_pid(const char* relpath, pid_t tid); +#endif +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_c.h postgresql-hll-2.14/include/cm/cm_c.h --- postgresql-hll-2.14_old/include/cm/cm_c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_c.h 2020-12-12 17:06:43.096346090 +0800 @@ -0,0 +1,134 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_c.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_C_H +#define CM_C_H + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#include +#include +#include +#include +#include "c.h" +#include "cm/cm_misc.h" +#include "securec.h" +#include "securec_check.h" + +#ifdef PC_LINT +#ifndef Assert +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#endif /* Assert */ +#else +#ifndef USE_ASSERT_CHECKING +#ifndef Assert +#define Assert(condition) +#endif /* Assert */ +#else +#ifdef Assert +#undef Assert +#endif +#ifndef Assert +#define Assert(condition) assert(condition) +#endif /* Assert */ +#endif +#endif +/* Possible type of nodes for registration */ +typedef enum CM_PGXCNodeType { + CM_NODE_GTM_PROXY = 1, + CM_NODE_GTM_PROXY_POSTMASTER = 2, + /* Used by Proxy to communicate with GTM and not use Proxy headers */ + CM_NODE_COORDINATOR = 3, + CM_NODE_DATANODE = 4, + CM_NODE_GTM = 5, + CM_NODE_DEFAULT = 6 /* In case nothing is associated to connection */ +} CM_PGXCNodeType; + +typedef enum CM_PortLastCall { + CM_LastCall_NONE = 0, + CM_LastCall_SEND, + CM_LastCall_RECV, + CM_LastCall_READ, + CM_LastCall_WRITE +} CM_PortLastCall; + +#define TCP_SOCKET_ERROR_EPIPE (-2) +#define TCP_SOCKET_ERROR_NO_MESSAGE (-3) +#define TCP_SOCKET_ERROR_NO_BUFFER (-4) +#define TCP_SOCKET_ERROR_INVALID_IP (-5) + +/* Define max size of user in start up packet */ +#define SP_USER 32 + +/* Define max size of node name in start up packet */ +#define SP_NODE_NAME 64 +#define MAX_PATH_LEN 1024 + +/* Define max size of host in start up packet */ +#define SP_HOST 16 + +typedef struct CM_StartupPacket { + char sp_user[SP_USER]; + char sp_node_name[SP_NODE_NAME]; + char sp_host[SP_HOST]; + int node_id; + int sp_remotetype; + bool sp_ispostmaster; +} CM_StartupPacket; + +#define _(x) gettext(x) + +#define MAX_NODE_GROUP_MEMBERS_LEN (CM_NODE_MAXNUM * LOGIC_DN_PER_NODE * (CM_NODE_NAME + 1)) + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) \ + do { \ + if (NULL != (ptr)) { \ + free(ptr); \ + (ptr) = NULL; \ + } \ + } while (0) +#endif + +#endif /* GTM_C_H */ diff -uprN postgresql-hll-2.14_old/include/cm/cm_ip.h postgresql-hll-2.14/include/cm/cm_ip.h --- postgresql-hll-2.14_old/include/cm/cm_ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_ip.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_ip.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_IP_H +#define CM_IP_H + +#include "cm/pqcomm.h" + +extern int cm_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void cm_freeaddrinfo_all(int hint_ai_family, struct addrinfo* ai); + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* CM_IP_H */ diff -uprN postgresql-hll-2.14_old/include/cm/cm_misc.h postgresql-hll-2.14/include/cm/cm_misc.h --- postgresql-hll-2.14_old/include/cm/cm_misc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_misc.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,222 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_misc.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_misc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_MISC_H +#define CM_MISC_H + +#include "utils/syscall_lock.h" +#include "cm/etcdapi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct instance_not_exist_reason_string { + const char* level_string; + int level_val; +} instance_not_exist_reason_string; + +typedef struct log_level_string { + + const char* level_string; + int level_val; +} log_level_string; + +typedef struct instance_datanode_build_reason_string { + + const char* reason_string; + int reason_val; +} instance_datanode_build_reason_string; + +typedef struct instacne_type_string { + + const char* type_string; + int type_val; +} instacne_type_string; + +typedef struct gtm_con_string { + + const char* con_string; + int con_val; +} gtm_con_string; + +typedef struct instance_coordinator_active_status_string { + + const char* active_status_string; + int active_status_val; +} instance_coordinator_active_status_string; + +typedef struct instance_datanode_lockmode_string { + const char* lockmode_string; + uint32 lockmode_val; +} instance_datanode_lockmode_string; + +typedef struct instacne_datanode_role_string { + + const char* role_string; + uint32 role_val; +} instacne_datanode_role_string; + +typedef struct instacne_datanode_dbstate_string { + + const char* dbstate_string; + int dbstate_val; +} instacne_datanode_dbstate_string; + +typedef struct instacne_datanode_wal_send_state_string { + + const char* wal_send_state_string; + int wal_send_state_val; +} instacne_datanode_wal_send_state_string; + +typedef struct instacne_datanode_sync_state_string { + + const char* wal_sync_state_string; + int wal_sync_state_val; +} instacne_datanode_sync_state_string; + +typedef struct cluster_state_string { + + const char* cluster_state_string; + int cluster_state_val; +} cluster_state_string; + +typedef struct cluster_msg_string { + const char* cluster_msg_str; + int cluster_msg_val; +} cluster_msg_string; + +typedef struct server_role_string { + int role_val; + const char* role_string; +} server_role_string; + +#define LOCK_FILE_LINE_PID 1 +#define LOCK_FILE_LINE_DATA_DIR 2 +#define LOCK_FILE_LINE_START_TIME 3 +#define LOCK_FILE_LINE_PORT 4 +#define LOCK_FILE_LINE_SOCKET_DIR 5 +#define LOCK_FILE_LINE_LISTEN_ADDR 6 +#define LOCK_FILE_LINE_SHMEM_KEY 7 + +#ifndef ERROR_LIMIT_LEN +#define ERROR_LIMIT_LEN 256 +#endif + +/** + * @def SHELL_RETURN_CODE + * @brief Get the shell command return code. + * @return Return the shell command return code. + */ +#define SHELL_RETURN_CODE(systemReturn) \ + (systemReturn > 0 ? static_cast(static_cast(systemReturn) >> 8) : systemReturn) + +extern char** readfile(const char* path); +extern void freefile(char** lines); +extern int log_level_string_to_int(const char* log_level); +extern int datanode_rebuild_reason_string_to_int(const char* reason); +extern const char* instance_not_exist_reason_to_string(int reason); +extern int datanode_lockmode_string_to_int(const char* lockmode); +extern int datanode_role_string_to_int(const char* role); +extern int datanode_dbstate_string_to_int(const char* dbstate); +extern int datanode_wal_send_state_string_to_int(const char* dbstate); +extern int datanode_wal_sync_state_string_to_int(const char* dbstate); +extern const char* log_level_int_to_string(int log_level); +extern const char* cluster_state_int_to_string(int cluster_state); +extern const char* cluster_msg_int_to_string(int cluster_msg); +extern const char* datanode_wal_sync_state_int_to_string(int dbstate); +extern const char * datanode_wal_send_state_int_to_string(int dbstate); + +extern const char* datanode_dbstate_int_to_string(int dbstate); +extern const char* type_int_to_string(int type); +const char* gtm_con_int_to_string(int con); +extern const char* datanode_role_int_to_string(int role); +extern const char* datanode_static_role_int_to_string(uint32 role); +extern const char* datanode_rebuild_reason_int_to_string(int reason); +extern const char* server_role_to_string(int role, bool is_pending); +extern const char* etcd_role_to_string(int role); +extern const char* kerberos_status_to_string(int role); + +extern void cm_sleep(unsigned int sec); +extern void cm_usleep(unsigned int usec); + +extern uint32 get_healthy_etcd_node_count(EtcdTlsAuthPath* tlsPath, int programType); + +extern void check_input_for_security(char* input); +extern void check_env_value(const char* input_env_value); + +extern void print_environ(void); + +/** + * @brief + * Creates a lock file for a process with a specified PID. + * + * @note + * When pid is set to -1, the specified process is the current process. + * + * @param [in] filename + * The name of the lockfile to create. + * @param [in] data_path + * The data path of the instance. + * @param [in] pid + * The pid of the process. + * + * @return + * - 0 Create successfully. + * - -1 Create failure. + */ +extern int create_lock_file(const char* filename, const char* data_path, const pid_t pid = -1); + + +/** + * @brief + * Delete pid file. + * + * @param [in] filename + * The pid file to be deleted. + * + * @return + * void. + */ +extern void delete_lock_file(const char *filename); + +extern void cm_pthread_rw_lock(pthread_rwlock_t* rwlock); +extern void cm_pthread_rw_unlock(pthread_rwlock_t* rwlock); + +extern int cm_getenv( + const char* env_var, char* output_env_value, uint32 env_value_len, syscalllock cmLock, int elevel = -1); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_msg.h postgresql-hll-2.14/include/cm/cm_msg.h --- postgresql-hll-2.14_old/include/cm/cm_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_msg.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,1337 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_msg.h + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/cm_msg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_MSG_H +#define CM_MSG_H + +#include "replication/replicainternal.h" +#include "access/xlogdefs.h" +#include "access/redo_statistic_msg.h" +#include "../common/config/cm_config.h" +#include +#include + +#define CM_MAX_SENDER_NUM 2 +#define LOGIC_CLUSTER_NUMBER (32 + 1) ////max 32 logic + 1 elastic group +#define CM_LOGIC_CLUSTER_NAME_LEN 64 +#define CM_MSG_ERR_INFORMATION_LENGTH 1024 +#define MAX_INT32 (2147483600) +#define CN_INFO_NUM 8 +#define RESERVE_NUM 160 +#define RESERVE_NUM_USED 4 + +using std::string; +using std::vector; + +/* + * Symbols in the following enum are usd in cluster_msg_map_string defined in cm_misc.cpp. + * Modifictaion to the following enum should be reflected to cluster_msg_map_string as well. + */ +typedef enum CM_MessageType { + MSG_CTL_CM_SWITCHOVER = 0, + MSG_CTL_CM_BUILD = 1, + MSG_CTL_CM_SYNC = 2, + MSG_CTL_CM_QUERY = 3, + MSG_CTL_CM_NOTIFY = 4, + MSG_CTL_CM_BUTT = 5, + MSG_CM_CTL_DATA_BEGIN = 6, + MSG_CM_CTL_DATA = 7, + MSG_CM_CTL_NODE_END = 8, + MSG_CM_CTL_DATA_END = 9, + MSG_CM_CTL_COMMAND_ACK = 10, + + MSG_CM_AGENT_SWITCHOVER = 11, + MSG_CM_AGENT_FAILOVER = 12, + MSG_CM_AGENT_BUILD = 13, + MSG_CM_AGENT_SYNC = 14, + MSG_CM_AGENT_NOTIFY = 15, + MSG_CM_AGENT_NOTIFY_CN = 16, + MSG_AGENT_CM_NOTIFY_CN_FEEDBACK = 17, + MSG_CM_AGENT_CANCEL_SESSION = 18, + MSG_CM_AGENT_RESTART = 19, + MSG_CM_AGENT_RESTART_BY_MODE = 20, + MSG_CM_AGENT_REP_SYNC = 21, + MSG_CM_AGENT_REP_ASYNC = 22, + MSG_CM_AGENT_REP_MOST_AVAILABLE = 23, + MSG_CM_AGENT_BUTT = 24, + + MSG_AGENT_CM_DATA_INSTANCE_REPORT_STATUS = 25, + MSG_AGENT_CM_COORDINATE_INSTANCE_STATUS = 26, + MSG_AGENT_CM_GTM_INSTANCE_STATUS = 27, + MSG_AGENT_CM_BUTT = 28, + + /**************** =====CAUTION===== ****************: + If you want to add a new MessageType, you should add at the end , + It's forbidden to insert new MessageType at middle, it will change the other MessageType value. + The MessageType is transfered between cm_agent and cm_server on different host, + You should ensure the type value be identical and compatible between old and new versions */ + + MSG_CM_CM_VOTE = 29, + MSG_CM_CM_BROADCAST = 30, + MSG_CM_CM_NOTIFY = 31, + MSG_CM_CM_SWITCHOVER = 32, + MSG_CM_CM_FAILOVER = 33, + MSG_CM_CM_SYNC = 34, + MSG_CM_CM_SWITCHOVER_ACK = 35, + MSG_CM_CM_FAILOVER_ACK = 36, + MSG_CM_CM_ROLE_CHANGE_NOTIFY = 37, + MSG_CM_CM_REPORT_SYNC = 38, + + MSG_AGENT_CM_HEARTBEAT = 39, + MSG_CM_AGENT_HEARTBEAT = 40, + MSG_CTL_CM_SET = 41, + MSG_CTL_CM_SWITCHOVER_ALL = 42, + MSG_CM_CTL_SWITCHOVER_ALL_ACK = 43, + MSG_CTL_CM_BALANCE_CHECK = 44, + MSG_CM_CTL_BALANCE_CHECK_ACK = 45, + MSG_CTL_CM_BALANCE_RESULT = 46, + MSG_CM_CTL_BALANCE_RESULT_ACK = 47, + MSG_CTL_CM_QUERY_CMSERVER = 48, + MSG_CM_CTL_CMSERVER = 49, + + MSG_TYPE_BUTT = 50, + MSG_CM_AGENT_NOTIFY_CN_CENTRAL_NODE = 51, + MSG_CM_AGENT_DROP_CN = 52, + MSG_CM_AGENT_DROPPED_CN = 53, + MSG_AGENT_CM_FENCED_UDF_INSTANCE_STATUS = 54, + MSG_CTL_CM_SWITCHOVER_FULL = 55, /* inform cm agent to do switchover -A */ + MSG_CM_CTL_SWITCHOVER_FULL_ACK = 56, /* inform cm ctl that cm server is doing swtichover -A */ + MSG_CM_CTL_SWITCHOVER_FULL_DENIED = 57, /* inform cm ctl that switchover -A is denied by cm server */ + MSG_CTL_CM_SWITCHOVER_FULL_CHECK = 58, /* cm ctl inform cm server to check if swtichover -A is done */ + MSG_CM_CTL_SWITCHOVER_FULL_CHECK_ACK = 59, /* inform cm ctl that swtichover -A is done */ + MSG_CTL_CM_SWITCHOVER_FULL_TIMEOUT = 60, /* cm ctl inform cm server to swtichover -A timed out */ + MSG_CM_CTL_SWITCHOVER_FULL_TIMEOUT_ACK = 61, /* inform cm ctl that swtichover -A stopped */ + + MSG_CTL_CM_SETMODE = 62, /* new mode */ + MSG_CM_CTL_SETMODE_ACK = 63, + + MSG_CTL_CM_SWITCHOVER_AZ = 64, /* inform cm agent to do switchover -zazName */ + MSG_CM_CTL_SWITCHOVER_AZ_ACK = 65, /* inform cm ctl that cm server is doing swtichover -zazName */ + MSG_CM_CTL_SWITCHOVER_AZ_DENIED = 66, /* inform cm ctl that switchover -zazName is denied by cm server */ + MSG_CTL_CM_SWITCHOVER_AZ_CHECK = 67, /* cm ctl inform cm server to check if swtichover -zazName is done */ + MSG_CM_CTL_SWITCHOVER_AZ_CHECK_ACK = 68, /* inform cm ctl that swtichover -zazName is done */ + MSG_CTL_CM_SWITCHOVER_AZ_TIMEOUT = 69, /* cm ctl inform cm server to swtichover -zazName timed out */ + MSG_CM_CTL_SWITCHOVER_AZ_TIMEOUT_ACK = 70, /* inform cm ctl that swtichover -zazName stopped */ + + MSG_CM_CTL_SET_ACK = 71, + MSG_CTL_CM_GET = 72, + MSG_CM_CTL_GET_ACK = 73, + MSG_CM_AGENT_GS_GUC = 74, + MSG_AGENT_CM_GS_GUC_ACK = 75, + MSG_CM_CTL_SWITCHOVER_INCOMPLETE_ACK = 76, + MSG_CM_CM_TIMELINE = 77, /*when restart cluster , cmserver primary and standy timeline*/ + MSG_CM_BUILD_DOING = 78, + MSG_AGENT_CM_ETCD_CURRENT_TIME = 79, /*etcd clock monitoring message*/ + MSG_CM_QUERY_INSTANCE_STATUS = 80, + MSG_CM_SERVER_TO_AGENT_CONN_CHECK = 81, + MSG_CTL_CM_GET_DATANODE_RELATION = 82, /* depracated for the removal of quick switchover */ + MSG_CM_BUILD_DOWN = 83, + MSG_CTL_CM_HOTPATCH = 84, + MSG_CM_SERVER_REPAIR_CN_ACK = 85, + MSG_CTL_CM_DISABLE_CN = 86, + MSG_CTL_CM_DISABLE_CN_ACK = 87, + MSG_CM_AGENT_LOCK_NO_PRIMARY = 88, + MSG_CM_AGENT_LOCK_CHOSEN_PRIMARY = 89, + MSG_CM_AGENT_UNLOCK = 90, + MSG_CTL_CM_STOP_ARBITRATION = 91, + MSG_CTL_CM_FINISH_REDO = 92, + MSG_CM_CTL_FINISH_REDO_ACK = 93, + MSG_CM_AGENT_FINISH_REDO = 94, + MSG_CTL_CM_FINISH_REDO_CHECK = 95, + MSG_CM_CTL_FINISH_REDO_CHECK_ACK = 96, + MSG_AGENT_CM_KERBEROS_STATUS = 97, + MSG_CTL_CM_QUERY_KERBEROS = 98, + MSG_CTL_CM_QUERY_KERBEROS_ACK = 99, + MSG_AGENT_CM_DISKUSAGE_STATUS = 100 +} CM_MessageType; + +#define UNDEFINED_LOCKMODE 0 +#define POLLING_CONNECTION 1 +#define SPECIFY_CONNECTION 2 +#define PROHIBIT_CONNECTION 3 + +#define INSTANCE_ROLE_INIT 0 +#define INSTANCE_ROLE_PRIMARY 1 +#define INSTANCE_ROLE_STANDBY 2 +#define INSTANCE_ROLE_PENDING 3 +#define INSTANCE_ROLE_NORMAL 4 +#define INSTANCE_ROLE_UNKNOWN 5 +#define INSTANCE_ROLE_DUMMY_STANDBY 6 +#define INSTANCE_ROLE_DELETED 7 +#define INSTANCE_ROLE_DELETING 8 +#define INSTANCE_ROLE_READONLY 9 + +#define INSTANCE_ROLE_FIRST_INIT 1 +#define INSTANCE_ROLE_HAVE_INIT 2 + +#define INSTANCE_DATA_REPLICATION_SYNC 1 +#define INSTANCE_DATA_REPLICATION_ASYNC 2 +#define INSTANCE_DATA_REPLICATION_MOST_AVAILABLE 3 +#define INSTANCE_DATA_REPLICATION_POTENTIAL_SYNC 4 +#define INSTANCE_DATA_REPLICATION_QUORUM 5 +#define INSTANCE_DATA_REPLICATION_UNKONWN 6 + +#define INSTANCE_TYPE_GTM 1 +#define INSTANCE_TYPE_DATANODE 2 +#define INSTANCE_TYPE_COORDINATE 3 +#define INSTANCE_TYPE_FENCED_UDF 4 +#define INSTANCE_TYPE_UNKNOWN 5 + +#define INSTANCE_WALSNDSTATE_STARTUP 0 +#define INSTANCE_WALSNDSTATE_BACKUP 1 +#define INSTANCE_WALSNDSTATE_CATCHUP 2 +#define INSTANCE_WALSNDSTATE_STREAMING 3 +#define INSTANCE_WALSNDSTATE_DUMPLOG 4 +const int INSTANCE_WALSNDSTATE_NORMAL = 5; +const int INSTANCE_WALSNDSTATE_UNKNOWN = 6; + +#define CON_OK 0 +#define CON_BAD 1 +#define CON_STARTED 2 +#define CON_MADE 3 +#define CON_AWAITING_RESPONSE 4 +#define CON_AUTH_OK 5 +#define CON_SETEN 6 +#define CON_SSL_STARTUP 7 +#define CON_NEEDED 8 +#define CON_UNKNOWN 9 +#define CON_MANUAL_STOPPED 10 +#define CON_DISK_DEMAGED 11 +#define CON_PORT_USED 12 +#define CON_NIC_DOWN 13 +#define CON_GTM_STARTING 14 + +#define CM_SERVER_UNKNOWN 0 +#define CM_SERVER_PRIMARY 1 +#define CM_SERVER_STANDBY 2 +#define CM_SERVER_INIT 3 +#define CM_SERVER_DOWN 4 + +#define CM_ETCD_UNKNOWN 0 +#define CM_ETCD_FOLLOWER 1 +#define CM_ETCD_LEADER 2 +#define CM_ETCD_DOWN 3 + +#define SWITCHOVER_UNKNOWN 0 +#define SWITCHOVER_FAIL 1 +#define SWITCHOVER_SUCCESS 2 +#define SWITCHOVER_EXECING 3 +#define SWITCHOVER_PARTLY_SUCCESS 4 +#define SWITCHOVER_ABNORMAL 5 + +#define UNKNOWN_BAD_REASON 0 +#define PORT_BAD_REASON 1 +#define NIC_BAD_REASON 2 +#define DISC_BAD_REASON 3 +#define STOPPED_REASON 4 +#define CN_DELETEED_REASON 5 + +#define KERBEROS_STATUS_UNKNOWN 0 +#define KERBEROS_STATUS_NORMAL 1 +#define KERBEROS_STATUS_ABNORMAL 2 +#define KERBEROS_STATUS_DOWN 3 + +#define HOST_LENGTH 32 +// the length of cm_serer sync msg is 9744, msg type is MSG_CM_CM_REPORT_SYNC +#define CM_MSG_MAX_LENGTH (12288 * 2) + +#define CMAGENT_NO_CCN "NoCentralNode" + +extern int g_gtm_phony_dead_times; +extern int g_dn_phony_dead_times[CM_MAX_DATANODE_PER_NODE]; +extern int g_cn_phony_dead_times; + +typedef enum {DN, CN} GetinstanceType; +typedef struct cm_msg_type { + int msg_type; +} cm_msg_type; + +typedef struct cm_switchover_incomplete_msg { + int msg_type; + char errMsg[CM_MSG_ERR_INFORMATION_LENGTH]; +} cm_switchover_incomplete_msg; + +typedef struct cm_redo_stats { + int is_by_query; + uint64 redo_replayed_speed; + XLogRecPtr standby_last_replayed_read_Ptr; +} cm_redo_stats; + +typedef struct ctl_to_cm_stop_arbitration { + int msg_type; +} ctl_to_cm_stop_arbitration; + +typedef struct ctl_to_cm_switchover { + int msg_type; + char azName[CM_AZ_NAME]; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_switchover; + +typedef struct ctl_to_cm_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_failover; + +typedef struct cm_to_ctl_finish_redo_check_ack { + int msg_type; + int finish_redo_count; +} cm_to_ctl_finish_redo_check_ack; + +typedef struct ctl_to_cm_finish_redo { + int msg_type; +} ctl_to_cm_finish_redo; + +#define CM_CTL_UNFORCE_BUILD 0 +#define CM_CTL_FORCE_BUILD 1 + +typedef struct ctl_to_cm_build { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int force_build; + int full_build; +} ctl_to_cm_build; + +typedef struct ctl_to_cm_query { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int detail; + int relation; +} ctl_to_cm_query; + +typedef struct ctl_to_cm_disable_cn { + int msg_type; + uint32 instanceId; + int wait_seconds; +} ctl_to_cm_disable_cn; + +typedef struct ctl_to_cm_disable_cn_ack { + int msg_type; + bool disable_ok; + char errMsg[CM_MSG_ERR_INFORMATION_LENGTH]; +} ctl_to_cm_disable_cn_ack; + +typedef enum arbitration_mode { + UNKNOWN_ARBITRATION = 0, + MAJORITY_ARBITRATION = 1, + MINORITY_ARBITRATION = 2 +} arbitration_mode; + +typedef enum cm_start_mode { + UNKNOWN_START = 0, + MAJORITY_START = 1, + MINORITY_START = 2, + OTHER_MINORITY_START = 3 +} cm_start_mode; + +typedef enum switchover_az_mode { + UNKNOWN_SWITCHOVER_AZ = 0, + NON_AUTOSWITCHOVER_AZ = 1, + AUTOSWITCHOVER_AZ = 2 +} switchover_az_mode; + +typedef enum logic_cluster_restart_mode { + UNKNOWN_LOGIC_CLUSTER_RESTART = 0, + INITIAL_LOGIC_CLUSTER_RESTART = 1, + MODIFY_LOGIC_CLUSTER_RESTART = 2 +} logic_cluster_restart_mode; + +typedef enum cluster_mode { + INVALID_CLUSTER_MODE = 0, + ONE_MASTER_1_SLAVE, + ONE_MASTER_2_SLAVE, + ONE_MASTER_3_SLAVE, + ONE_MASTER_4_SLAVE, + ONE_MASTER_5_SLAVE +} cluster_mode; + +typedef enum synchronous_standby_mode { + AnyFirstNo = 0, /* don't have */ + AnyAz1, /* ANY 1(az1) */ + FirstAz1, /* FIRST 1(az1) */ + AnyAz2, /* ANY 1(az2) */ + FirstAz2, /* FIRST 1(az2) */ + Any2Az1Az2, /* ANY 2(az1,az2) */ + First2Az1Az2, /* FIRST 2(az1,az2) */ + Any3Az1Az2, /* ANY 3(az1, az2) */ + First3Az1Az2 /* FIRST 3(az1, az2) */ +} synchronous_standby_mode; + +typedef struct ctl_to_cm_set { + int msg_type; + int log_level; + uint32 logic_cluster_delay; + arbitration_mode cm_arbitration_mode; + switchover_az_mode cm_switchover_az_mode; + logic_cluster_restart_mode cm_logic_cluster_restart_mode; +} ctl_to_cm_set, cm_to_ctl_get; + +typedef struct cm_to_agent_switchover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int role; + uint32 term; +} cm_to_agent_switchover; + +typedef struct cm_to_agent_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + uint32 term; +} cm_to_agent_failover; + +typedef struct cm_to_agent_build { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int role; + int full_build; + uint32 term; +} cm_to_agent_build; + +typedef struct cm_to_agent_lock1 { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_lock1; + +typedef struct cm_to_agent_lock2 { + int msg_type; + uint32 node; + uint32 instanceId; + char disconn_host[HOST_LENGTH]; + uint32 disconn_port; +} cm_to_agent_lock2; + +typedef struct cm_to_agent_unlock { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_unlock; + +typedef struct cm_to_agent_finish_redo { + int msg_type; + uint32 node; + uint32 instanceId; + bool is_finish_redo_cmd_sent; +} cm_to_agent_finish_redo; + +typedef struct cm_to_agent_gs_guc { + int msg_type; + uint32 node; + uint32 instanceId; + synchronous_standby_mode type; +} cm_to_agent_gs_guc; + +typedef struct agent_to_cm_gs_guc_feedback { + int msg_type; + uint32 node; + uint32 instanceId; /* node of this agent */ + synchronous_standby_mode type; + bool status; /* gs guc command exec status */ +} agent_to_cm_gs_guc_feedback; + +typedef struct cm_to_agent_notify { + int msg_type; + uint32 node; + uint32 instanceId; + int role; + uint32 term; +} cm_to_agent_notify; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_notify_cn { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + int datanodeCount; /* current count of datanode got primaryed */ + uint32 coordinatorId; + int notifyCount; + /* datanode instance id array */ + uint32 datanodeId[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} cm_to_agent_notify_cn; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_drop_cn { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + uint32 coordinatorId; + int role; + bool delay_repair; +} cm_to_agent_drop_cn; + +typedef struct cm_to_agent_notify_cn_central_node { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + char cnodename[NAMEDATALEN]; /* central node id */ + char nodename[NAMEDATALEN]; +} cm_to_agent_notify_cn_central_node; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_cancel_session { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ +} cm_to_agent_cancel_session; + +/* + * msg struct using for cmagent to cmserver + * feedback msg for notify cn. + */ +typedef struct agent_to_cm_notify_cn_feedback { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + bool status; /* notify command exec status */ + int notifyCount; +} agent_to_cm_notify_cn_feedback; + +typedef struct cm_to_agent_restart { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_restart; + +typedef struct cm_to_agent_restart_by_mode { + int msg_type; + uint32 node; + uint32 instanceId; + int role_old; + int role_new; +} cm_to_agent_restart_by_mode; + +typedef struct cm_to_agent_rep_sync { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_sync; + +typedef struct cm_to_agent_rep_async { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_async; + +typedef struct cm_to_agent_rep_most_available { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_most_available; + +typedef struct cm_instance_central_node { + pthread_rwlock_t rw_lock; + pthread_mutex_t mt_lock; + uint32 instanceId; + uint32 node; + uint32 recover; + uint32 isCentral; + uint32 nodecount; + char nodename[NAMEDATALEN]; + char cnodename[NAMEDATALEN]; + char* failnodes; + cm_to_agent_notify_cn_central_node notify; +} cm_instance_central_node; + +typedef struct cm_instance_central_node_msg { + pthread_rwlock_t rw_lock; + cm_to_agent_notify_cn_central_node notify; +} cm_instance_central_node_msg; + +#define MAX_LENGTH_HP_CMD (9) +#define MAX_LENGTH_HP_PATH (256) +#define MAX_LENGTH_HP_RETURN_MSG (1024) + +typedef struct cm_hotpatch_msg { + int msg_type; + char command[MAX_LENGTH_HP_CMD]; + char path[MAX_LENGTH_HP_PATH]; +} cm_hotpatch_msg; + +typedef struct cm_hotpatch_ret_msg { + char msg[MAX_LENGTH_HP_RETURN_MSG]; +} cm_hotpatch_ret_msg; + +#define IP_LEN 64 +#define MAX_REPL_CONNINFO_LEN 256 +#define MAX_REBUILD_REASON_LEN 256 + +const int cn_active_unknown = 0; +const int cn_active = 1; +const int cn_inactive = 2; + +#define INSTANCE_HA_STATE_UNKONWN 0 +#define INSTANCE_HA_STATE_NORMAL 1 +#define INSTANCE_HA_STATE_NEED_REPAIR 2 +#define INSTANCE_HA_STATE_STARTING 3 +#define INSTANCE_HA_STATE_WAITING 4 +#define INSTANCE_HA_STATE_DEMOTING 5 +#define INSTANCE_HA_STATE_PROMOTING 6 +#define INSTANCE_HA_STATE_BUILDING 7 +#define INSTANCE_HA_STATE_CATCH_UP 8 +#define INSTANCE_HA_STATE_COREDUMP 9 +#define INSTANCE_HA_STATE_MANUAL_STOPPED 10 +#define INSTANCE_HA_STATE_DISK_DAMAGED 11 +#define INSTANCE_HA_STATE_PORT_USED 12 +#define INSTANCE_HA_STATE_BUILD_FAILED 13 +#define INSTANCE_HA_STATE_HEARTBEAT_TIMEOUT 14 +#define INSTANCE_HA_STATE_NIC_DOWN 15 +#define INSTANCE_HA_STATE_READ_ONLY 16 + +#define INSTANCE_HA_DATANODE_BUILD_REASON_NORMAL 0 +#define INSTANCE_HA_DATANODE_BUILD_REASON_WALSEGMENT_REMOVED 1 +#define INSTANCE_HA_DATANODE_BUILD_REASON_DISCONNECT 2 +#define INSTANCE_HA_DATANODE_BUILD_REASON_VERSION_NOT_MATCHED 3 +#define INSTANCE_HA_DATANODE_BUILD_REASON_MODE_NOT_MATCHED 4 +#define INSTANCE_HA_DATANODE_BUILD_REASON_SYSTEMID_NOT_MATCHED 5 +#define INSTANCE_HA_DATANODE_BUILD_REASON_TIMELINE_NOT_MATCHED 6 +#define INSTANCE_HA_DATANODE_BUILD_REASON_UNKNOWN 7 +#define INSTANCE_HA_DATANODE_BUILD_REASON_USER_PASSWD_INVALID 8 +#define INSTANCE_HA_DATANODE_BUILD_REASON_CONNECTING 9 + +#define UNKNOWN_LEVEL 0 + +typedef uint64 XLogRecPtr; + +typedef struct cm_local_replconninfo { + int local_role; + int static_connections; + int db_state; + XLogRecPtr last_flush_lsn; + int buildReason; + uint32 term; + uint32 disconn_mode; + char disconn_host[HOST_LENGTH]; + uint32 disconn_port; + char local_host[HOST_LENGTH]; + uint32 local_port; + bool redo_finished; +} cm_local_replconninfo; + +typedef struct cm_sender_replconninfo { + pid_t sender_pid; + int local_role; + int peer_role; + int peer_state; + int state; + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + int sync_percent; + int sync_state; + int sync_priority; +} cm_sender_replconninfo; + +typedef struct cm_receiver_replconninfo { + pid_t receiver_pid; + int local_role; + int peer_role; + int peer_state; + int state; + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + int sync_percent; +} cm_receiver_replconninfo; + +typedef struct cm_gtm_replconninfo { + int local_role; + int connect_status; + TransactionId xid; + uint64 send_msg_count; + uint64 receive_msg_count; + int sync_mode; +} cm_gtm_replconninfo; + +typedef struct cm_coordinate_replconninfo { + int status; + int db_state; +} cm_coordinate_replconninfo; + +typedef enum cm_coordinate_group_mode { + GROUP_MODE_INIT, + GROUP_MODE_NORMAL, + GROUP_MODE_PENDING, + GROUP_MODE_BUTT +} cm_coordinate_group_mode; + +#define AGENT_TO_INSTANCE_CONNECTION_BAD 0 +#define AGENT_TO_INSTANCE_CONNECTION_OK 1 + +#define INSTANCE_PROCESS_DIED 0 +#define INSTANCE_PROCESS_RUNNING 1 + +const int max_cn_node_num_for_old_version = 16; + +typedef struct cluster_cn_info { + uint32 cn_Id; + uint32 cn_active; + bool cn_connect; + bool drop_success; +} cluster_cn_info; + +typedef struct agent_to_cm_coordinate_status_report_old { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + cluster_cn_info cn_active_info[max_cn_node_num_for_old_version]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report_old; + + +typedef struct agent_to_cm_coordinate_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + int cn_active_info[CN_INFO_NUM]; + char resevered[RESERVE_NUM]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report; + +typedef struct agent_to_cm_coordinate_status_report_v1 { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + int cn_active_info[CN_INFO_NUM]; + int cn_dn_disconnect_times; + char resevered[RESERVE_NUM - RESERVE_NUM_USED]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report_v1; + +typedef struct agent_to_cm_fenced_UDF_status_report { + int msg_type; + uint32 nodeid; + int status; +} agent_to_cm_fenced_UDF_status_report; + +typedef struct agent_to_cm_datanode_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + cm_local_replconninfo local_status; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + int dn_restart_counts; + int phony_dead_times; + int dn_restart_counts_in_hour; + +} agent_to_cm_datanode_status_report; + +typedef struct agent_to_cm_gtm_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + cm_gtm_replconninfo status; + int phony_dead_times; +} agent_to_cm_gtm_status_report; + +typedef struct agent_to_cm_current_time_report { + int msg_type; + uint32 nodeid; + long int etcd_time; +} agent_to_cm_current_time_report; + +typedef struct AgentToCMS_DiskUsageStatusReport { + int msgType; + uint32 instanceId; + uint32 dataPathUsage; + uint32 logPathUsage; +} AgentToCMS_DiskUsageStatusReport; + +typedef struct agent_to_cm_heartbeat { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int cluster_status_request; +} agent_to_cm_heartbeat; + +typedef struct coordinate_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_coordinate_status_report report_msg; +} coordinate_status_info; + +typedef struct datanode_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_datanode_status_report report_msg; +} datanode_status_info; + +typedef struct gtm_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_gtm_status_report report_msg; +} gtm_status_info; + +typedef struct cm_to_agent_heartbeat { + int msg_type; + uint32 node; + int type; + int cluster_status; + uint32 healthCoorId; +} cm_to_agent_heartbeat; + +typedef struct cm_to_cm_vote { + int msg_type; + uint32 node; + uint32 instanceId; + int role; +} cm_to_cm_vote; + +typedef struct cm_to_cm_timeline { + int msg_type; + uint32 node; + uint32 instanceId; + long timeline; +} cm_to_cm_timeline; + +typedef struct cm_to_cm_broadcast { + int msg_type; + uint32 node; + uint32 instanceId; + int role; +} cm_to_cm_broadcast; + +typedef struct cm_to_cm_notify { + int msg_type; + int role; +} cm_to_cm_notify; + +typedef struct cm_to_cm_switchover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_switchover; + +typedef struct cm_to_cm_switchover_ack { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_switchover_ack; + +typedef struct cm_to_cm_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_failover; + +typedef struct cm_to_cm_failover_ack { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_failover_ack; + +typedef struct cm_to_cm_sync { + int msg_type; + int role; +} cm_to_cm_sync; + +typedef struct cm_instance_command_status { + int command_status; + int command_send_status; + int command_send_times; + int command_send_num; + int pengding_command; + int time_out; + int role_changed; + int heat_beat; + int arbitrate_delay_time_out; + int arbitrate_delay_set; + int local_arbitrate_delay_role; + int peerl_arbitrate_delay_role; + int full_build; + int notifyCnCount; + int keep_heartbeat_timeout; + int sync_mode; +} cm_instance_command_status; + +// need to keep consist with cm_to_ctl_instance_datanode_status +typedef struct cm_instance_datanode_report_status { + cm_local_replconninfo local_status; + int sender_count; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + synchronous_standby_mode sync_standby_mode; + int send_gs_guc_time; + int dn_restart_counts; + bool arbitrateFlag; + int failoverStep; + int failoverTimeout; + int phony_dead_times; + int phony_dead_interval; + int dn_restart_counts_in_hour; + bool is_finish_redo_cmd_sent; +} cm_instance_datanode_report_status; + +typedef struct cm_instance_gtm_report_status { + cm_gtm_replconninfo local_status; + int phony_dead_times; + int phony_dead_interval; +} cm_instance_gtm_report_status; + +/* + * each coordinator manage a list of datanode notify status + */ +typedef struct cm_notify_msg_status { + uint32* datanode_instance; + uint32* datanode_index; + bool* notify_status; + bool* have_notified; + bool* have_dropped; + bool have_canceled; +} cm_notify_msg_status; + +typedef struct cm_instance_coordinate_report_status { + cm_coordinate_replconninfo status; + int isdown; + int clean; + uint32 exec_drop_instanceId; + cm_coordinate_group_mode group_mode; + cm_notify_msg_status notify_msg; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + uint32 cn_restart_counts; + int phony_dead_times; + int phony_dead_interval; + bool delay_repair; + bool isCnDnDisconnected; + int auto_delete_delay_time; + int disable_time_out; + int cma_fault_timeout_to_killcn; +} cm_instance_coordinate_report_status; + +typedef struct cm_instance_arbitrate_status { + int sync_mode; + bool restarting; + int promoting_timeout; +} cm_instance_arbitrate_status; + +#define MAX_CM_TO_CM_REPORT_SYNC_COUNT_PER_CYCLE 5 +typedef struct cm_to_cm_report_sync { + int msg_type; + uint32 node[CM_PRIMARY_STANDBY_NUM]; + uint32 instanceId[CM_PRIMARY_STANDBY_NUM]; + int instance_type[CM_PRIMARY_STANDBY_NUM]; + cm_instance_command_status command_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_coordinate_report_status coordinatemember; + cm_instance_arbitrate_status arbitrate_status_member[CM_PRIMARY_STANDBY_NUM]; +} cm_to_cm_report_sync; + +typedef struct cm_instance_role_status { + // available zone information + char azName[CM_AZ_NAME]; + uint32 azPriority; + + uint32 node; + uint32 instanceId; + int instanceType; + int role; + int dataReplicationMode; + int instanceRoleInit; +} cm_instance_role_status; + +typedef struct cm_instance_role_status_0 { + uint32 node; + uint32 instanceId; + int instanceType; + int role; + int dataReplicationMode; + int instanceRoleInit; +} cm_instance_role_status_0; + +#define CM_PRIMARY_STANDBY_MAX_NUM 8 // supprot 1 primary and [1, 7] standby +#define CM_PRIMARY_STANDBY_MAX_NUM_0 3 // support master standby dummy + +typedef struct cm_instance_role_group_0 { + int count; + cm_instance_role_status_0 instanceMember[CM_PRIMARY_STANDBY_MAX_NUM_0]; +} cm_instance_role_group_0; + +typedef struct cm_instance_role_group { + int count; + cm_instance_role_status instanceMember[CM_PRIMARY_STANDBY_MAX_NUM]; +} cm_instance_role_group; + +typedef struct cm_to_cm_role_change_notify { + int msg_type; + cm_instance_role_group role_change; +} cm_to_cm_role_change_notify; + +typedef struct ctl_to_cm_datanode_relation_info { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_datanode_relation_info; + +typedef struct cm_to_ctl_get_datanode_relation_ack { + int command_result; + int member_index; + cm_instance_role_status instanceMember[CM_PRIMARY_STANDBY_MAX_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_MAX_NUM]; +} cm_to_ctl_get_datanode_relation_ack; + +// need to keep consist with the struct cm_instance_datanode_report_status +typedef struct cm_to_ctl_instance_datanode_status { + cm_local_replconninfo local_status; + int sender_count; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + synchronous_standby_mode sync_standby_mode; + int send_gs_guc_time; +} cm_to_ctl_instance_datanode_status; + +typedef struct cm_to_ctl_instance_gtm_status { + cm_gtm_replconninfo local_status; +} cm_to_ctl_instance_gtm_status; + +typedef struct cm_to_ctl_instance_coordinate_status { + int status; + cm_coordinate_group_mode group_mode; + /* no notify map in ctl */ +} cm_to_ctl_instance_coordinate_status; + +typedef struct cm_to_ctl_instance_status { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int member_index; + int is_central; + int fenced_UDF_status; + cm_to_ctl_instance_datanode_status data_node_member; + cm_to_ctl_instance_gtm_status gtm_member; + cm_to_ctl_instance_coordinate_status coordinatemember; +} cm_to_ctl_instance_status; + +typedef struct cm_to_ctl_central_node_status { + uint32 instanceId; + int node_index; + int status; +} cm_to_ctl_central_node_status; + +#define CM_CAN_PRCESS_COMMAND 0 +#define CM_ANOTHER_COMMAND_RUNNING 1 +#define CM_INVALID_COMMAND 2 +#define CM_DN_NORMAL_STATE 3 + +typedef struct cm_to_ctl_command_ack { + int msg_type; + int command_result; + uint32 node; + uint32 instanceId; + int instance_type; + int command_status; + int pengding_command; + int time_out; +} cm_to_ctl_command_ack; + +typedef struct cm_to_ctl_balance_check_ack { + int msg_type; + int switchoverDone; +} cm_to_ctl_balance_check_ack; + +typedef struct cm_to_ctl_switchover_full_check_ack { + int msg_type; + int switchoverDone; +} cm_to_ctl_switchover_full_check_ack, cm_to_ctl_switchover_az_check_ack; + +#define MAX_INSTANCES_LEN 512 +typedef struct cm_to_ctl_balance_result { + int msg_type; + int imbalanceCount; + uint32 instances[MAX_INSTANCES_LEN]; +} cm_to_ctl_balance_result; + +#define CM_STATUS_STARTING 0 +#define CM_STATUS_PENDING 1 +#define CM_STATUS_NORMAL 2 +#define CM_STATUS_NEED_REPAIR 3 +#define CM_STATUS_DEGRADE 4 +#define CM_STATUS_UNKNOWN 5 +#define CM_STATUS_NORMAL_WITH_CN_DELETED 6 + +typedef struct cm_to_ctl_cluster_status { + int msg_type; + int cluster_status; + bool is_all_group_mode_pending; + int switchedCount; + int node_id; +} cm_to_ctl_cluster_status; + +typedef struct cm_to_ctl_logic_cluster_status { + int msg_type; + int cluster_status; + bool is_all_group_mode_pending; + int switchedCount; + + int logic_cluster_status[LOGIC_CLUSTER_NUMBER]; + bool logic_is_all_group_mode_pending[LOGIC_CLUSTER_NUMBER]; + int logic_switchedCount[LOGIC_CLUSTER_NUMBER]; +} cm_to_ctl_logic_cluster_status; + +typedef struct cm_to_ctl_cmserver_status { + int msg_type; + int local_role; + bool is_pending; +} cm_to_ctl_cmserver_status; + +typedef struct cm_query_instance_status { + int msg_type; + uint32 nodeId; + uint32 instanceType; // only for etcd and cmserver + uint32 msg_step; + uint32 status; + bool pending; +} cm_query_instance_status; + +typedef struct etcd_status_info { + pthread_rwlock_t lk_lock; + cm_query_instance_status report_msg; +} etcd_status_info; + +/* kerberos information */ +#define ENV_MAX 100 +#define ENVLUE_NUM 3 +#define MAX_BUFF 1024 +#define MAXLEN 20 +#define KERBEROS_NUM 2 + +typedef struct agent_to_cm_kerberos_status_report { + int msg_type; + uint32 node; + char kerberos_ip[CM_IP_LENGTH]; + uint32 port; + uint32 status; + char role[MAXLEN]; + char nodeName[CM_NODE_NAME]; +} agent_to_cm_kerberos_status_report; + +typedef struct kerberos_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_kerberos_status_report report_msg; +} kerberos_status_info; + +typedef struct cm_to_ctl_kerberos_status_query { + int msg_type; + uint32 heartbeat[KERBEROS_NUM]; + uint32 node[KERBEROS_NUM]; + char kerberos_ip[KERBEROS_NUM][CM_IP_LENGTH]; + uint32 port[KERBEROS_NUM]; + uint32 status[KERBEROS_NUM]; + char role[KERBEROS_NUM][MAXLEN]; + char nodeName[KERBEROS_NUM][CM_NODE_NAME]; +} cm_to_ctl_kerberos_status_query; + +typedef struct kerberos_group_report_status { + pthread_rwlock_t lk_lock; + cm_to_ctl_kerberos_status_query kerberos_status; +} kerberos_group_report_status; + + +typedef uint32 ShortTransactionId; + +/* ---------------- + * Special transaction ID values + * + * BootstrapTransactionId is the XID for "bootstrap" operations, and + * FrozenTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFF) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +/* + * Macros for comparing XLogRecPtrs + * + * Beware of passing expressions with side-effects to these macros, + * since the arguments may be evaluated multiple times. + */ +#define XLByteLT(a, b) ((a) < (b)) +#define XLByteLE(a, b) ((a) <= (b)) +#define XLByteEQ(a, b) ((a) == (b)) + +#define InvalidTerm (0) +#define FirstTerm (1) + +#define XLByteLT_W_TERM(a_term, a_logptr, b_term, b_logptr) \ + (((a_term) < (b_term)) || (((a_term) == (b_term)) && ((a_logptr) < (b_logptr)))) +#define XLByteLE_W_TERM(a_term, a_logptr, b_term, b_logptr) \ + (((a_term) < (b_term)) || (((a_term) == (b_term)) && ((a_logptr) <= (b_logptr)))) +#define XLByteEQ_W_TERM(a_term, a_logptr, b_term, b_logptr) (((a_term) == (b_term)) && ((a_logptr) == (b_logptr))) + +#define CM_RESULT_COMM_ERROR (-2) /* Communication error */ +#define CM_RESULT_ERROR (-1) +#define CM_RESULT_OK (0) +/* + * This error is used ion the case where allocated buffer is not large + * enough to store the errors. It may happen of an allocation failed + * so it's status is considered as unknown. + */ +#define CM_RESULT_UNKNOWN (1) + +typedef struct ResultDataPacked { + char pad[CM_MSG_MAX_LENGTH]; + +} ResultDataPacked; + +typedef union CM_ResultData { + ResultDataPacked packed; + +} CM_ResultData; + +typedef struct CM_Result { + int gr_msglen; + int gr_status; + int gr_type; + CM_ResultData gr_resdata; +} CM_Result; + +extern int query_gtm_status_wrapper(char pid_path[MAXPGPATH], agent_to_cm_gtm_status_report& agent_to_cm_gtm); +extern int query_gtm_status_for_phony_dead(char pid_path[MAXPGPATH]); + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_alarm.h postgresql-hll-2.14/include/cm/cm_server/cms_alarm.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_alarm.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,36 @@ +#ifndef CMS_ALARM_H +#define CMS_ALARM_H + +#include "alarm/alarm.h" + +typedef enum CM_DiskPreAlarmType { + PRE_ALARM_LOG = 0, + PRE_ALARM_CN = 1, + PRE_ALARM_DN = 2 +} CM_DiskPreAlarmType; + +typedef struct instance_phony_dead_alarm { + uint32 instanceId; + Alarm PhonyDeadAlarmItem[1]; +} instance_phony_dead_alarm; + +extern void StorageThresholdPreAlarmItemInitialize(void); +extern void ReportStorageThresholdPreAlarm( + AlarmType alarmType, + const char* instanceName, + CM_DiskPreAlarmType alarmNode, + uint32 alarmIndex); +extern void ReadOnlyAlarmItemInitialize(void); +extern void ReportReadOnlyAlarm(AlarmType alarmType, const char* instanceName, uint32 alarmIndex); +extern void PhonyDeadAlarmItemInitialize(void); +extern void report_phony_dead_alarm(AlarmType alarmType, const char* instanceName, uint32 instanceid); +extern void report_unbalanced_alarm(AlarmType alarmType); + + +extern void EtcdAbnormalAlarmItemInitialize(void); +extern void UnbalanceAlarmItemInitialize(void); +extern void ServerSwitchAlarmItemInitialize(void); +extern void report_server_switch_alarm(AlarmType alarmType, const char* instanceName); +void report_etcd_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_cms.h postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_cms.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_cms.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_cms.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,17 @@ +/** + * @file cms_arbitrate_cms.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_ARBITRATE_CMS_H +#define CMS_ARBITRATE_CMS_H + +extern void CloseHAConnection(CM_Connection* con); +extern void* CM_ThreadHAMain(void* argp); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_datanode.h postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_datanode.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_datanode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_datanode.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,42 @@ +/** + * @file cms_arbitrate_datanode.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMS_ARBITRATE_DATANODE_H +#define CMS_ARBITRATE_DATANODE_H + +#include "cm/elog.h" +#include "cm/cm_msg.h" +#include "cm_server.h" +#include "cms_global_params.h" + +extern uint32 find_primary_term(uint32 group_index); +extern uint32 read_term_from_etcd(uint32 group_index); +bool check_datanode_arbitrate_status(uint32 group_index, int member_index); + +cm_instance_datanode_report_status &GetDataNodeMember(const uint32 &group, const int &member); + +int find_candiate_primary_node_in_instance_role_group(uint32 group_index, int member_index); +int find_auto_switchover_primary_node(uint32 group_index, int member_index); + +void datanode_instance_arbitrate( + CM_Connection *con, agent_to_cm_datanode_status_report *agent_to_cm_datanode_status_ptr); +void datanode_instance_arbitrate_for_psd( + CM_Connection *con, agent_to_cm_datanode_status_report *agent_to_cm_datanode_status_ptr); +void datanode_instance_arbitrate_new( + CM_Connection* con, agent_to_cm_datanode_status_report* agent_to_cm_datanode_status_ptr, + uint32 group_index, int member_index, maintenance_mode mode); +void datanode_instance_arbitrate_single( + CM_Connection* con, agent_to_cm_datanode_status_report* agent_to_cm_datanode_status_ptr); + +void DealDataNodeDBStateChange(const uint32 &group, const int &member, const int &dbStatePrev); +void NotifyDatanodeDynamicPrimary(CM_Connection *con, const uint32 &node, const uint32 &instanceId, const uint32 &group, + const int &member); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_gtm.h postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_gtm.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_arbitrate_gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_arbitrate_gtm.h 2020-12-12 17:06:43.097346103 +0800 @@ -0,0 +1,11 @@ + +#ifndef CMS_ARBITRATE_GTM_H +#define CMS_ARBITRATE_GTM_H + +#include "cm/cm_msg.h" + +extern void gtm_instance_arbitrate(CM_Connection* con, agent_to_cm_gtm_status_report* agent_to_cm_gtm_status_ptr); +extern void gtm_instance_arbitrate_single(CM_Connection* con, + agent_to_cm_gtm_status_report* agent_to_cm_gtm_status_ptr); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_az.h postgresql-hll-2.14/include/cm/cm_server/cms_az.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_az.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_az.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,45 @@ +/** + * @file cms_az.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_AZ_CHECK_H +#define CMS_AZ_CHECK_H + +#define AZ_STATUS_RUNNING 0 +#define AZ_STAUTS_STOPPED 1 + +#define PING_TIMEOUT_OPTION " -c 2 -W 2" +/* for the limit of check node of success, when check az1 is success */ +#define AZ1_AND_AZ2_CHECK_SUCCESS_NODE_LIMIT 10 +#define AZ1_AZ2_CONNECT_PING_TRY_TIMES 3 + +const int MAX_PING_NODE_NUM = 10; + +/* data structure to store input/output of ping-check thread function */ +typedef struct PingCheckThreadParmInfo { + /* the node to ping */ + uint32 azNode; + /* ping thread idnex */ + uint32 threadIdx; + /* the array of ping result */ + uint32 *pingResultArrayRef; +}PingCheckThreadParmInfo; + +typedef enum {START_AZ, STOP_AZ} OperateType; +typedef enum {SET_ETCD_AZ, GET_ETCD_AZ} EtcdOperateType; +typedef enum {UNKNOWN_AZ_DEPLOYMENT, TWO_AZ_DEPLOYMENT, THREE_AZ_DEPLOYMENT} AZDeploymentType; + +extern void* Az1Az2ConnectStateCheck(void* arg); +extern void* MultiAzConnectStateCheckMain(void* arg); +extern void getAZDyanmicStatus( + int azCount, int* statusOnline, int* statusPrimary, int* statusFail, int* statusDnFail, char azArray[][CM_AZ_NAME]); + +extern void* AZStatusCheckAndArbitrate(void* arg); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_cluster_switchover.h postgresql-hll-2.14/include/cm/cm_server/cms_cluster_switchover.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_cluster_switchover.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_cluster_switchover.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,22 @@ +/** + * @file cms_cluster_switchover.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_CLUSTER_SWITCHOVER_H +#define CMS_CLUSTER_SWITCHOVER_H + +#include "cm_server.h" + +#define MAX_CYCLE 600 + +extern char switchover_flag_file_path[MAX_PATH_LEN]; +extern void* Deal_switchover_for_init_cluster(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_cn.h postgresql-hll-2.14/include/cm/cm_server/cms_cn.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_cn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_cn.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,26 @@ +/** + * @file cms_cn.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_CN_H +#define CMS_CN_H + +#include "cm_server.h" + +#ifdef ENABLE_MULTIPLE_NODES +void process_cm_to_agent_repair_ack(CM_Connection* con, uint32 group_index); +void process_agent_to_cm_coordinate_status_report_msg( + CM_Connection* con, agent_to_cm_coordinate_status_report* agent_to_cm_coordinate_status_ptr); +void process_ctl_to_cm_disable_cn(CM_Connection* con, ctl_to_cm_disable_cn* ctl_to_cm_disable_cn_ptr); +void process_agent_to_central_coordinate_status( + CM_Connection* con, const agent_to_cm_coordinate_status_report* report_msg, int group_index, uint32 count); +#endif + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_common.h postgresql-hll-2.14/include/cm/cm_server/cms_common.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_common.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,30 @@ +/** + * @file cms_common.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_COMMON_H +#define CMS_COMMON_H + + +uint32 findMinCmServerInstanceIdIndex(); +uint32 findCmServerOrderIndex(uint32 nodeIndex); +void setNotifyCnFlagByNodeId(uint32 nodeId); +bool is_valid_host(CM_Connection* con, int remote_type); +bool findMinCmServerId(int primaryId); +void get_parameters_from_configfile(); +#ifdef ENABLE_MULTIPLE_NODES +void get_paramter_coordinator_heartbeat_timeout(); +#endif +void clean_init_cluster_state(); +void get_config_param(const char* config_file, const char* srcParam, char* destParam, int destLen); +int StopCheckNode(uint32 nodeIdCheck); +void SendSignalToAgentThreads(); +extern int GetCtlThreadNum(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_conn.h postgresql-hll-2.14/include/cm/cm_server/cms_conn.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_conn.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,41 @@ +/** + * @file cms_conn.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_CONN_H +#define CMS_CONN_H + +#include "cm/libpq-fe.h" +#include "cm_server.h" + + +#define CM_SERVER_PACKET_ERROR_MSG 128 +#define MSG_COUNT_FOR_LOG 300 + +extern int ServerListenSocket[MAXLISTEN]; + +void* CM_ThreadMain(void* argp); +void RemoveCMAgentConnection(CM_Connection* con); +void ConnCloseAndFree(CM_Connection* con); +void CloseHAConnection(CM_Connection* con); +void set_socket_timeout(Port* my_port, int timeout); + +Port* ConnCreate(int serverFd); +void ConnFree(Port* conn); +int initMasks(const int* ListenSocket, fd_set* rmask); +int CMHandleCheckAuth(CM_Connection* con); +int cm_server_flush_msg(CM_Connection* conn); + +int EventAdd(int epoll_handle, int events, CM_Connection* con); +void EventDel(int epollFd, CM_Connection* con); +void CMPerformAuthentication(CM_Connection* con); +int ReadCommand(Port* myport, CM_StringInfo inBuf); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_disk_check.h postgresql-hll-2.14/include/cm/cm_server/cms_disk_check.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_disk_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_disk_check.h 2020-12-12 17:06:43.098346116 +0800 @@ -0,0 +1,25 @@ + +#ifndef CMS_DISK_CHECK_H +#define CMS_DISK_CHECK_H + +#include "common/config/cm_config.h" + +#define INSTANCE_NAME_LENGTH 256 + +extern int InitNodeReadonlyInfo(); +extern bool checkReadOnlyStatus(uint32 instanceId); + +extern void* StorageDetectMain(void* arg); + +extern void SetPreAlarmForNodeInstance(uint32 instanceId); +extern void ReportPreAlarmForNodeInstance(); +extern void PreAlarmForNodeThreshold(); + +extern void SetPreAlarmForLogDiskInstance(const char* nodeName); +extern void RepostPreAlarmForLogDiskInstance(); +extern void PreAlarmForLogPathThreshold(); +extern void SetNodeInstanceReadOnlyStatus(int instanceType, uint32 instanceId, uint32 readonly); +extern void SaveNodeReadOnlyConfig(); +extern void CheckAndSetStorageThresholdReadOnlyAlarm(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cm_server.h postgresql-hll-2.14/include/cm/cm_server/cm_server.h --- postgresql-hll-2.14_old/include/cm/cm_server/cm_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cm_server.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,239 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_server.h + * + * + * + * IDENTIFICATION + * src/include/cm/cm_server/cm_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SERVER_MAIN_H +#define SERVER_MAIN_H + +#include "common/config/cm_config.h" +#include "cm/elog.h" +#include "cm/stringinfo.h" +#include "cm/libpq-be.h" +#include "cm/cm_msg.h" +#include "cm/pqsignal.h" + +#define CM_MAX_CONNECTIONS 1024 +#define CM_MAX_THREADS 1024 + +#define CM_MONITOR_THREAD_NUM 1 +#define CM_HA_THREAD_NUM 1 + +#define MAXLISTEN 64 + +#define MAX_EVENTS 512 + +#define DEFAULT_THREAD_NUM 5 + +#define INVALIDFD (-1) + +#define CM_INCREMENT_TERM_VALUE 100 + +#define CM_UINT32_MAX 0xFFFFFFFFU + +#define CM_MIN_CONN_TO_ETCD 2 + +#define CM_MAX_CONN_TO_ETCD 100 + +#define CM_TEN_DIVISOR 10 + +typedef void (*PCallback)(int fd, int events, void* arg); + +typedef struct CM_Connection { + int fd; + int epHandle; + int events; + PCallback callback; + void* arg; + Port* port; + CM_StringInfo inBuffer; + long last_active; + bool gss_check; + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +} CM_Connection; + +typedef struct CM_Connections { + uint32 count; + CM_Connection* connections[CM_MAX_CONNECTIONS + MAXLISTEN]; + pthread_rwlock_t lock; +} CM_Connections; + +typedef struct CM_Thread { + pthread_t tid; + int type; + int epHandle; + +} CM_Thread; + +typedef struct CM_Threads { + uint32 count; + CM_Thread threads[CM_MAX_THREADS]; +} CM_Threads; + +typedef struct CM_HAThread { + CM_Thread thread; + int heartbeat; + CM_Connection conn; +} CM_HAThread; + +typedef struct CM_HAThreads { + uint32 count; + CM_HAThread threads[CM_HA_THREAD_NUM]; +} CM_HAThreads; + +typedef struct CM_MonitorThread { + CM_Thread thread; +} CM_MonitorThread; + +typedef struct CM_MonitorNodeStopThread { + CM_Thread thread; +} CM_MonitorNodeStopThread; + +typedef enum CM_ThreadStatus { + CM_THREAD_STARTING, + CM_THREAD_RUNNING, + CM_THREAD_EXITING, + CM_THREAD_INVALID +} CM_ThreadStatus; + +typedef struct CM_Server_HA_Status { + int local_role; + int peer_role; + int status; + bool is_all_group_mode_pending; + pthread_rwlock_t ha_lock; +} CM_Server_HA_Status; + +typedef struct CM_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + +} CM_ConnectionInfo; + +typedef struct CM_ConnEtcdInfo { + uint32 count; + EtcdSession etcdSession[CM_MAX_CONN_TO_ETCD]; +} CM_ConnEtcdInfo; + +#define THREAD_TYPE_HA 1 +#define THREAD_TYPE_MONITOR 2 +#define THREAD_TYPE_CTL_SERVER 3 +#define THREAD_TYPE_AGENT_SERVER 4 +#define THREAD_TYPE_INIT 5 +#define THREAD_TYPE_ALARM_CHECKER 6 + +#define MONITOR_CYCLE_TIMER 1000000 +#define MONITOR_CYCLE_TIMER_OUT 6000000 +#define MONITOR_CYCLE_MAX_COUNT (MONITOR_CYCLE_TIMER_OUT / MONITOR_CYCLE_TIMER) + +// ARBITRATE_DELAY_CYCLE 10s +#define MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT (10) + +#define MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT2 (MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT * 2) +#define BUILD_TIMER_OUT (60 * 60 * 2) +#define PROMOTING_TIME_OUT (30) + +#define CM_INSTANCE_GROUP_SIZE 128 + +#define INSTANCE_NONE_COMMAND 0 +#define INSTANCE_COMMAND_WAIT_SEND_SERVER 1 +#define INSTANCE_COMMAND_WAIT_SERVER_ACK 2 +#define INSTANCE_COMMAND_WAIT_EXEC 3 +#define INSTANCE_COMMAND_WAIT_EXEC_ACK 4 + +#define INSTANCE_COMMAND_SEND_STATUS_NONE 0 +#define INSTANCE_COMMAND_SEND_STATUS_SENDING 1 +#define INSTANCE_COMMAND_SEND_STATUS_OK 2 +#define INSTANCE_COMMAND_SEND_STATUS_FAIL 3 + +#define INSTANCE_ROLE_NO_CHANGE 0 +#define INSTANCE_ROLE_CHANGED 1 + +#define INSTANCE_ARBITRATE_DELAY_NO_SET 0 +#define INSTANCE_ARBITRATE_DELAY_HAVE_SET 1 +constexpr int NO_NEED_TO_SET_PARAM = -1; + +typedef struct cm_instance_report_status { + cm_instance_command_status command_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_coordinate_report_status coordinatemember; + cm_instance_arbitrate_status arbitrate_status_member[CM_PRIMARY_STANDBY_NUM]; + uint32 time; + uint32 term; + int etcd_synced; + int cma_kill_instance_timeout; + struct timeval finishredo_time; + bool finish_redo; +} cm_instance_report_status; + +typedef struct cm_instance_group_report_status { + pthread_rwlock_t lk_lock; + cm_instance_report_status instance_status; +} cm_instance_group_report_status; + +typedef struct cm_fenced_UDF_report_status { + pthread_rwlock_t lk_lock; + int heart_beat; + int status; +} cm_fenced_UDF_report_status; + +typedef enum ProcessingMode { + BootstrapProcessing, /* bootstrap creation of template database */ + InitProcessing, /* initializing system */ + NormalProcessing, /* normal processing */ + PostUpgradeProcessing /* Post upgrade to run script */ +} ProcessingMode; + +#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing) +#define IsInitProcessingMode() (Mode == InitProcessing) +#define IsNormalProcessingMode() (Mode == NormalProcessing) +#define IsPostUpgradeProcessingMode() (Mode == PostUpgradeProcessing) + +#define GetProcessingMode() Mode + +#define SetProcessingMode(mode) \ + do { \ + if ((mode) == BootstrapProcessing || (mode) == InitProcessing || (mode) == NormalProcessing || \ + (mode) == PostUpgradeProcessing) \ + Mode = (mode); \ + } while (0) + +extern volatile sig_atomic_t got_stop; +extern volatile sig_atomic_t got_parameter_reload; +extern volatile sig_atomic_t ha_connection_closed; +extern THR_LOCAL volatile sig_atomic_t got_conns_close; + +extern void ProcessStartupPacket(int epollFd, int events, void* arg); +extern int cm_server_process_ha_startuppacket(CM_Connection* con, CM_StringInfo msg); +extern int cm_server_send_msg(CM_Connection* con, char msgtype, const char* s, size_t len, int log_level = LOG); +void set_pending_command( + const uint32 &group_index, + const int &member_index, + const CM_MessageType &pending_command, + const int &time_out = NO_NEED_TO_SET_PARAM, + const int &full_build = NO_NEED_TO_SET_PARAM); + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_etcd.h postgresql-hll-2.14/include/cm/cm_server/cms_etcd.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_etcd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_etcd.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,55 @@ +/** + * @file cms_etcd.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_ETCD_H +#define CMS_ETCD_H + +#include "cm_server.h" +#include "cms_global_params.h" + +extern volatile bool g_arbitration_changed_from_minority; +uint32 read_term_from_etcd(uint32 group_index); +void clear_sync_with_etcd_flag(); +void etcd_ip_port_info_balance(EtcdServerSocket* server); +void CmsGetKerberosInfoFromEtcd(); + +void get_all_cmserver_heartbeat_from_etcd(); +bool set_heartbeat_to_etcd(char* key); +bool get_finish_redo_flag_from_etcd(uint32 group_index); +bool GetFinishRedoFlagFromEtcdNew(); +bool getDnFailStatusFromEtcd(int* statusOnline); +bool setDnFailStatusToEtcd(int* statusOnline); + +bool getOnlineStatusFromEtcd(int* statusOnline); +bool setOnlineStatusToEtcd(int* statusOnline); + +void set_dynamic_config_change_to_etcd(uint32 group_index, int member_index); +void get_coordinator_dynamic_config_change_from_etcd(uint32 group_index); +void GetCoordinatorDynamicConfigChangeFromEtcdNew(uint32 group_index); +void get_datanode_dynamic_config_change_from_etcd(uint32 group_index); +void GetDatanodeDynamicConfigChangeFromEtcdNew(uint32 group_index); +void get_gtm_dynamic_config_change_from_etcd(uint32 group_index); +void SetStaticPrimaryRole(uint32 group_index, int static_primary__index); + +void GetNodeReadOnlyStatusFromEtcd(); +errno_t SetNodeReadOnlyStatusToEtcd(const char* bitsString); + +int try_etcd_get(char* key, char* value, int max_size, int tryTimes); +long GetTimeMinus(struct timeval checkEnd, struct timeval checkBegin); +int GetInstanceKeyValueFromEtcd(const char *key, InstanceStatusKeyValue *keyValue, const int length); + +void server_etcd_init(); + +void CloseAllEtcdSession(); +EtcdSession GetNextEtcdSession(); +int SetTermToEtcd(uint32 term); +int IncrementTermToEtcd(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_global_params.h postgresql-hll-2.14/include/cm/cm_server/cms_global_params.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_global_params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_global_params.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,391 @@ +/** + * @file cms_global_params.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_GLOBAL_PARAMS_H +#define CMS_GLOBAL_PARAMS_H + +#include +#include +#include +#include "common/config/cm_config.h" +#include "alarm/alarm.h" +#include "cm_server.h" +#include "cm/cm_c.h" +#include "cm/etcdapi.h" + +using std::set; +using std::string; +using std::vector; + + +typedef struct azInfo { + char azName[CM_AZ_NAME]; + uint32 nodes[CM_NODE_MAXNUM]; +} azInfo; + +typedef enum CMS_OPERATION_ { + CMS_SWITCHOVER_DN = 0, + CMS_FAILOVER_DN, + CMS_BUILD_DN, + CMS_DROP_CN, + CMS_PHONY_DEAD_CHECK, +} cms_operation ; + +typedef enum MAINTENANCE_MODE_ { + MAINTENANCE_MODE_NONE = 0, + MAINTENANCE_MODE_UPGRADE, + MAINTENANCE_MODE_UPGRADE_OBSERVATION, + MAINTENANCE_MODE_DILATATION, +} maintenance_mode; + +/* data structures to record instances that are in switchover procedure */ +typedef struct switchover_instance { + uint32 node; + uint32 instanceId; + int instanceType; +} switchover_instance; +typedef struct DataNodeReadOnlyInfo { + char dataNodePath[CM_PATH_LENGTH]; + uint32 instanceId; + uint32 currReadOnly; + uint32 lastReadOnly; + uint32 currPreAlarm; + uint32 lastPreAlarm; + uint32 dataDiskUsage; +} DataNodeReadOnlyInfo; + +typedef struct InstanceStatusKeyValue { + char key[ETCD_KEY_LENGTH]; + char value[ETCD_VLAUE_LENGTH]; +} InstanceStatusKeyValue; + +typedef struct DynamicNodeReadOnlyInfo { + char nodeName[CM_NODE_NAME]; + uint32 dataNodeCount; + DataNodeReadOnlyInfo dataNode[CM_MAX_DATANODE_PER_NODE]; + + DataNodeReadOnlyInfo coordinateNode; + uint32 currLogDiskPreAlarm; + uint32 lastLogDiskPreAlarm; + uint32 logDiskUsage; +} DynamicNodeReadOnlyInfo; + +#define ELASTICGROUP "elastic_group" + +#define PROCESS_NOT_EXIST 0 +#define PROCESS_CORPSE 1 +#define PROCESS_RUNNING 2 + +#define CMS_CURRENT_VERSION 1 +#define LOGIC_CLUSTER_LIST "logic_cluster_name.txt" +#define CM_STATIC_CONFIG_FILE "cluster_static_config" +#define CM_CLUSTER_MANUAL_START "cluster_manual_start" +#define CM_INSTANCE_MANUAL_START "instance_manual_start" +#define MINORITY_AZ_START "minority_az_start" +#define INSTANCE_MAINTANCE "instance_maintance" +#define CM_PID_FILE "cm_server.pid" + +#define PRIMARY "PRIMARY" +#define STANDBY "STANDBY" +#define DELETED "DELETED" +#define DELETING "DELETING" +#define UNKNOWN "UNKNOWN" +#define NORMAL "NORMAL" +#define DATANODE_ALL 0 +#define READONLY_OFF 0 +#define READONLY_ON 1 +#define DN_RESTART_COUNTS 3 /* DN restarts frequently due to core down */ +#define DN_RESTART_COUNTS_IN_HOUR 8 /* DN restarts in hour */ +#define TRY_TIME_GET_STATUSONLINE_FROM_ETCD 1 +#define CMA_KILL_INSTANCE_BALANCE_TIME 10 +/* + * the sum of cm_server heartbeat timeout and arbitrate delay time must be less than + * cm_agent disconnected timeout. or else, cm_agent may self-kill before cm_server + * standby failover. + */ +#define AZ_MEMBER_MAX_COUNT (3) +#define INIT_CLUSTER_MODE_INSTANCE_DEAL_TIME 180 +#define CM_SERVER_ARBITRATE_DELAY_CYCLE_MAX_COUNT 3 +#define MAX_CN_COUNT 100 +#define MAX_PATH_LEN 1024 +#define THREAHOLD_LEN 10 +#define BYTENUM 4 +#define DEFAULT_THREAD_NUM 5 +#define SWITCHOVER_SEND_CHECK_NUM 3 +#define MAX_VALUE_OF_CM_PRIMARY_HEARTBEAT 86400 +#define MAX_COUNT_OF_NOTIFY_CN 86400 +#define CM_MAX_AUTH_TOKEN_LENGTH 65535 +#define INSTANCE_ID_LEN 5 +#define CM_GS_GUC_SEND_INTERVAL 3 + +#define CN_DELETE_DELAY_SECONDS 10 +#define MAX_QUERY_DOWN_COUNTS 30 + +#define AZ1_INDEX 0 // for the index flag, az1 +#define AZ2_INDEX 1 // for the index flag, az2 +#define AZ3_INDEX 2 // for the index flag, az3 +#define AZ_ALL_INDEX (-1) // for the index flag, az1 and az2,az3 + + +#define GS_GUC_SYNCHRONOUS_STANDBY_MODE 1 +/* + * ssh connect does not exit automatically when the network is fault, + * this will cause cm_ctl hang for several hours, + * so we should add the following timeout options for ssh. + */ +#define SSH_CONNECT_TIMEOUT "5" +#define SSH_CONNECT_ATTEMPTS "3" +#define SSH_SERVER_ALIVE_INTERVAL "15" +#define SSH_SERVER_ALIVE_COUNT_MAX "3" +#define PSSH_TIMEOUT_OPTION \ + " -t 60 -O ConnectTimeout=" SSH_CONNECT_TIMEOUT " -O ConnectionAttempts=" SSH_CONNECT_ATTEMPTS \ + " -O ServerAliveInterval=" SSH_SERVER_ALIVE_INTERVAL " -O ServerAliveCountMax=" SSH_SERVER_ALIVE_COUNT_MAX " " +#define PSSH_TIMEOUT " -t 30 " + + +/* + * the sum of cm_server heartbeat timeout and arbitrate delay time must be less than + * cm_agent disconnected timeout. or else, cm_agent may self-kill before cm_server + * standby failover. + */ +#define AZ_MEMBER_MAX_COUNT (3) +#define SWITCHOVER_DEFAULT_WAIT 1200 /* It needs an integer multiple of 3, because of sleep(3) */ + +#define AUTHENTICATION_TIMEOUT 60 + + +#define IS_CN_INSTANCEID(instanceId) \ + ((instanceId) > 5000 && (instanceId) < 6000) +#define IS_DN_INSTANCEID(instanceId) \ + ((instanceId) > 6000 && (instanceId) < 7000) +#define IS_GTM_INSTANCEID(instanceId) \ + ((instanceId) > 1000 && (instanceId) < 2000) + +extern set g_stopNodes; +extern set::iterator g_stopNodeIter; +extern vector switchOverInstances; +extern vector vecSortCmId; + +extern const int HALF_HOUR; +extern const int MINUS_ONE; +extern const uint32 ZERO; +extern const uint32 FIVE; + +extern volatile arbitration_mode cm_arbitration_mode; +extern uint32 ctl_stop_cluster_server_halt_arbitration_timeout; +extern struct passwd* pw; +/* extern CM_Server_HA_Status g_HA_status_data; */ +extern CM_Server_HA_Status* g_HA_status; +extern dynamicConfigHeader* g_dynamic_header; +extern cm_instance_role_group* g_instance_role_group_ptr; +extern CM_ConnEtcdInfo* g_sess; +extern EtcdTlsAuthPath g_tlsPath; +extern dynamicConfigHeader* g_dynamic_header; +extern cm_instance_group_report_status* g_instance_group_report_status_ptr; +extern CM_Connections gConns; +extern cm_instance_central_node g_central_node; +extern pthread_rwlock_t switchover_az_rwlock; +extern pthread_rwlock_t etcd_access_lock; +extern pthread_rwlock_t gsguc_feedback_rwlock; +extern pthread_rwlock_t g_finish_redo_rwlock; +extern syscalllock cmserver_env_lock; +extern synchronous_standby_mode current_cluster_az_status; +extern CM_Threads gThreads; +extern CM_HAThreads gHAThreads; +extern CM_MonitorThread gMonitorThread; +extern CM_MonitorNodeStopThread gMonitorNodeStopThread; +extern cm_fenced_UDF_report_status* g_fenced_UDF_report_status_ptr; +extern pthread_rwlock_t instance_status_rwlock; +extern pthread_rwlock_t dynamic_file_rwlock; +extern pthread_rwlock_t term_update_rwlock; +extern pthread_rwlock_t switchover_full_rwlock; +extern kerberos_group_report_status g_kerberos_group_report_status; +extern dynamic_cms_timeline* g_timeline; +extern DynamicNodeReadOnlyInfo *g_dynamicNodeReadOnlyInfo; +extern Alarm UnbalanceAlarmItem[1]; +extern Alarm ServerSwitchAlarmItem[1]; +extern Alarm* AbnormalEtcdAlarmList; +extern volatile logic_cluster_restart_mode cm_logic_cluster_restart_mode; +extern volatile cm_start_mode cm_server_start_mode; +extern volatile switchover_az_mode cm_switchover_az_mode; + +extern THR_LOCAL ProcessingMode Mode; + +extern const int majority_reelection_timeout_init; +#ifdef ENABLE_MULTIPLE_NODES +extern const int coordinator_deletion_timeout_init; +#endif +extern const int ctl_stop_cluster_server_halt_arbitration_timeout_init; +extern const int cn_dn_disconnect_to_delete_time; +extern int AbnormalEtcdAlarmListSize; +extern int switch_rto; +extern int force_promote; +extern int cm_auth_method; +extern int g_cms_ha_heartbeat; +extern int cm_server_arbitrate_delay_set; +extern int g_init_cluster_delay_time; +extern int g_sever_agent_conn_check_interval; +extern int datastorage_threshold_check_interval; +extern int max_datastorage_threshold_check; +extern int az_switchover_threshold; +extern int az_check_and_arbitrate_interval; +extern int az1_and_az2_connect_check_interval; +extern int az1_and_az2_connect_check_delay_time; +extern int phony_dead_effective_time; +extern int instance_phony_dead_restart_interval; +extern int enable_az_auto_switchover; +extern int cmserver_demote_delay_on_etcd_fault; +extern int cmserver_demote_delay_on_conn_less; +extern int cmserver_promote_delay_count; +extern int g_cmserver_promote_delay_count; +extern int g_cmserver_demote_delay_on_etcd_fault; +extern int g_monitor_thread_check_invalid_times; +extern int cm_server_current_role; +extern int ccn_change_delay_time; +extern int* cn_dn_disconnect_times; +extern int g_cms_ha_heartbeat_timeout[CM_PRIMARY_STANDBY_NUM]; +extern int g_cms_ha_heartbeat_from_etcd[CM_PRIMARY_STANDBY_NUM]; +extern int HAListenSocket[MAXLISTEN]; + + +extern const uint32 min_normal_cn_number; +extern uint32 g_instance_manual_start_file_exist; +extern uint32 g_gaussdb_restart_counts; +extern uint32 g_cm_to_cm_report_sync_cycle_count; +extern uint32 g_current_node_index; +extern uint32 cm_server_arbitrate_delay_time_out; +extern uint32 arbitration_majority_reelection_timeout; +#ifdef ENABLE_MULTIPLE_NODES +extern uint32 g_cnDeleteDelayTimeForClusterStarting; +extern uint32 g_cnDeleteDelayTimeForDnWithoutPrimary; +extern uint32 g_cmd_disable_coordinatorId; +#endif +extern uint32 g_instance_failover_delay_time_from_set; +extern uint32 cmserver_gs_guc_reload_timeout; +extern uint32 serverHATimeout; +extern uint32 cmserver_switchover_timeout; +extern uint32 g_datanode_instance_count; +extern uint32 g_health_etcd_count_for_pre_conn; +extern uint32 cn_delete_default_time; +extern uint32 instance_heartbeat_timeout; +extern uint32 instance_failover_delay_timeout; +extern uint32 cmserver_ha_connect_timeout; +extern uint32 cmserver_ha_heartbeat_timeout; +extern uint32 cmserver_ha_status_interval; +extern uint32 cmserver_self_vote_timeout; +extern uint32 instance_keep_heartbeat_timeout; +extern uint32 cm_server_arbitrate_delay_base_time_out; +extern uint32 cm_server_arbitrate_delay_incrememtal_time_out; +#ifdef ENABLE_MULTIPLE_NODES +extern uint32 coordinator_heartbeat_timeout; +#endif +extern uint32 g_pre_agent_conn_count; +extern uint32 g_cm_agent_kill_instance_time; +extern uint32 cmserver_switchover_timeout; +extern uint32 cmserver_and_etcd_instance_status_for_timeout; +extern uint32 g_dropped_cn[MAX_CN_NUM]; +extern uint32 g_instance_status_for_etcd[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_etcd_timeout[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_node_index_for_cm_server[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_cm_server_timeout[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_cm_server[CM_PRIMARY_STANDBY_NUM]; + +extern azInfo g_azArray[CM_NODE_MAXNUM]; +extern uint32 g_azNum; +extern bool do_finish_redo; +extern bool isNeedCancel; +extern bool g_init_cluster_mode; +extern bool g_gtm_free_mode; +extern bool g_open_new_logical; +extern bool isStart; +extern bool switchoverAZInProgress; +extern bool agentVotePrimary; +extern bool g_dnWithoutPrimaryFlag; +extern bool g_syncDNReadOnlyStatusFromEtcd; +extern bool switchoverFullInProgress; +extern bool g_elastic_exist_node; +extern bool g_kerberos_check_cms_primary_standby; +extern bool g_sync_dn_finish_redo_flag_from_etcd; +extern bool g_getHistoryDnStatusFromEtcd; +extern bool g_getHistoryCnStatusFromEtcd; +extern volatile uint32 g_refreshDynamicCfgNum; +extern bool g_needIncTermToEtcdAgain; +extern bool g_instance_status_for_cm_server_pending[CM_PRIMARY_STANDBY_NUM]; +/* thread count of thread pool */ +extern unsigned int cm_thread_count; + +extern FILE* syslogFile; +extern char* cm_server_dataDir; +extern char sys_log_path[MAX_PATH_LEN]; +extern char curLogFileName[MAXPGPATH]; +extern char system_alarm_log[MAXPGPATH]; +extern char cm_krb_server_keyfile[MAX_PATH_LEN]; +extern char configDir[MAX_PATH_LEN]; +extern char minority_az_start_file[MAX_PATH_LEN]; +extern char cm_instance_manual_start_path[MAX_PATH_LEN]; + +extern char g_enableSetReadOnly[10]; +extern char g_enableSetReadOnlyThreshold[THREAHOLD_LEN]; +extern char g_storageReadOnlyCheckCmd[MAX_PATH_LEN]; +extern char cm_static_configure_path[MAX_PATH_LEN]; +extern char cm_dynamic_configure_path[MAX_PATH_LEN]; +extern char g_pre_agent_conn_flag[CM_MAX_CONNECTIONS]; +extern char logic_cluster_list_path[MAX_PATH_LEN]; +extern char instance_maintance_path[MAX_PATH_LEN]; +extern char cm_manual_start_path[MAX_PATH_LEN]; +extern char cm_force_start_file_path[MAX_PATH_LEN]; + +extern volatile int log_min_messages; +extern volatile int maxLogFileSize; +extern volatile int curLogFileNum; +extern volatile bool logInitFlag; +extern volatile bool cm_server_pending; + +extern void clean_init_cluster_state(); +extern void instance_delay_arbitrate_time_out_direct_clean(uint32 group_index, int member_index, uint32 delay_max_count); +extern void instance_delay_arbitrate_time_out_clean( + int local_dynamic_role, int peerl_dynamic_role, uint32 group_index, int member_index, int delay_max_count); + +extern int find_node_in_dynamic_configure( + uint32 node, uint32 instanceId, int instanceType, uint32* group_index, int* member_index); + +extern void change_primary_member_index(uint32 group_index, int primary_member_index); +extern void ChangeDnPrimaryMemberIndex(uint32 group_index, int primary_member_index); +extern void deal_dbstate_normal_primary_down(uint32 group_index, int instanceType); +extern int find_other_member_index(uint32 group_index, int member_index, int role, bool* majority); +extern int instance_delay_arbitrate_time_out( + int local_dynamic_role, int peerl_dynamic_role, uint32 group_index, int member_index, int delay_max_count); +extern void CleanCommand(uint32 group_index, int member_index); +extern bool isLoneNode(int timeout); +extern int SetNotifyPrimaryInfoToEtcd(uint32 groupIndex, int memberIndex); +extern void deal_phony_dead_status( + CM_Connection *con, int instanceRole, int group_index, int member_index, maintenance_mode mode); +extern void kill_instance_for_agent_fault(uint32 node, uint32 instanceId, int insType); +extern int find_other_member_index_for_DN_psd(uint32 group_index, int member_index); +extern int find_other_member_index_for_DN(uint32 group_index, int member_index, bool* majority); +extern int find_other_member_index_for_Gtm(uint32 group_index, int member_index); +extern int cmserver_getenv(const char* env_var, char* output_env_value, uint32 env_value_len, int elevel); +extern bool IsMaintenanceModeDisableOperation(const cms_operation &op, maintenance_mode mode); +extern void cm_pending_notify_broadcast_msg(uint32 group_index, uint32 instanceId); +extern inline bool isDisableSwitchoverDN(const maintenance_mode &mode); +extern inline bool isDisableFailoverDN(const maintenance_mode &mode); +extern inline bool isDisableDropCN(const maintenance_mode &mode); +extern inline bool isDisablePhonyDeadCheck(const maintenance_mode &mode); +extern inline bool isDisableBuildDN(const maintenance_mode &mode); +extern maintenance_mode getMaintenanceMode(const uint32 &group_index); +extern uint32 GetTermForMinorityStart(void); +extern cm_start_mode get_cm_start_mode(const char* path); + +extern void initazArray(char azArray[][CM_AZ_NAME]); +bool isLargerNode(); +void setStorageCheckCmd(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_monitor_main.h postgresql-hll-2.14/include/cm/cm_server/cms_monitor_main.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_monitor_main.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_monitor_main.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,18 @@ +/** + * @file cms_monitor_main.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_MONITOR_MAIN_H +#define CMS_MONITOR_MAIN_H + +extern void* CM_ThreadMonitorMain(void* argp); +extern void* CM_ThreadMonitorNodeStopMain(void* argp); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_phony_dead_check.h postgresql-hll-2.14/include/cm/cm_server/cms_phony_dead_check.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_phony_dead_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_phony_dead_check.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,17 @@ +/** + * @file cms_phony_dead_check.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_PHONY_DEAD_CHECK_H +#define CMS_PHONY_DEAD_CHECK_H + +extern void* deal_phony_dead_alarm(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_process_messages.h postgresql-hll-2.14/include/cm/cm_server/cms_process_messages.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_process_messages.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_process_messages.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,72 @@ +#ifndef CMS_PROCESS_MESSAGES_H +#define CMS_PROCESS_MESSAGES_H + +#ifndef CM_AZ_NAME +#define CM_AZ_NAME 65 +#endif + +// ETCD TIME THRESHOLD +#define ETCD_CLOCK_THRESHOLD 3 +#define SWITCHOVER_SEND_CHECK_RATE 30 + +extern int cmserver_getenv(const char* env_var, char* output_env_value, uint32 env_value_len, int elevel); +extern int check_if_candidate_is_in_faulty_az(uint32 group_index, int candidate_member_index); +extern int findAzIndex(char azArray[][CM_AZ_NAME], const char* azName); +extern int ReadCommand(Port* myport, CM_StringInfo inBuf); +extern int isNodeBalanced(uint32* switchedInstance); +extern int get_logicClusterId_by_dynamic_dataNodeId(uint32 dataNodeId); + +extern bool process_auto_switchover_full_check(); +extern bool existMaintenanceInstanceInGroup(uint32 group_index,int *init_primary_member_index); +extern bool isMaintenanceInstance(const char *file_path,uint32 notify_instance_id); + +extern uint32 GetClusterUpgradeMode(); + +extern void cm_to_cm_report_sync_setting(cm_to_cm_report_sync* cm_to_cm_report_sync_content, uint32 sync_cycle_count); +extern void cm_server_process_msg(CM_Connection* con, CM_StringInfo inBuffer); +extern void set_command_status_due_send_status(int send_status); +extern void SwitchOverSetting(int time_out, int instanceType, int ptrIndex, int memberIndex); + +extern void getAZDyanmicStatus( + int azCount, int* statusOnline, int* statusPrimary, int* statusFail, int* statusDnFail, char azArray[][CM_AZ_NAME]); +extern void process_cm_to_cm_report_sync_msg(cm_to_cm_report_sync* cm_to_cm_report_sync_ptr); +extern void process_cm_to_cm_role_change_msg(cm_to_cm_role_change_notify* cm_to_cm_role_change_notify_content_ptr); +extern void process_cm_to_cm_broadcast_msg(cm_to_cm_broadcast* cm_to_cm_broadcast_msg_content_ptr); +extern void process_cm_to_cm_vote_msg(cm_to_cm_vote* cm_to_cm_vote_msg_content_ptr); +extern void check_cluster_status(); +int switchoverFullDone(void); +void set_cluster_status(void); + +void process_ctl_to_cm_balance_result_msg(CM_Connection* con); +void process_ctl_to_cm_get_msg(CM_Connection* con); +void process_ctl_to_cm_build_msg(CM_Connection* con, ctl_to_cm_build* ctl_to_cm_build_ptr); +void process_ctl_to_cm_query_msg(CM_Connection* con, ctl_to_cm_query* ctl_to_cm_query_ptr); +void process_ctl_to_cm_query_kerberos_status_msg(CM_Connection* con); +void process_ctl_to_cm_query_cmserver_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_all_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_full_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_full_check_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_full_timeout_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_az_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_az_check_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_az_timeout_msg(CM_Connection* con); +void process_ctl_to_cm_setmode(CM_Connection* con); +void process_ctl_to_cm_set_msg(CM_Connection* con, ctl_to_cm_set* ctl_to_cm_set_ptr); +void process_ctl_to_cm_balance_check_msg(CM_Connection* con); +void process_ctl_to_cm_get_datanode_relation_msg( + CM_Connection* con, ctl_to_cm_datanode_relation_info* ctl_to_cm_datanode_relation_info_ptr); + +void process_cm_to_cm_timeline_msg(cm_to_cm_timeline* cm_to_cm_timeline_msg_content_ptr); + +void process_gs_guc_feedback_msg(agent_to_cm_gs_guc_feedback* feedback_ptr); +void process_notify_cn_feedback_msg(CM_Connection* con, agent_to_cm_notify_cn_feedback* feedback_ptr); +void process_agent_to_cm_heartbeat_msg(CM_Connection* con, agent_to_cm_heartbeat* agent_to_cm_heartbeat_ptr); +void process_agent_to_cm_disk_usage_msg(CM_Connection* con, AgentToCMS_DiskUsageStatusReport* agent_to_cm_disk_usage_ptr); +void process_agent_to_cm_current_time_msg(agent_to_cm_current_time_report* etcd_time_ptr); +void process_agent_to_cm_kerberos_status_report_msg( + CM_Connection* con, agent_to_cm_kerberos_status_report* agent_to_cm_kerberos_status_ptr); +void process_agent_to_cm_fenced_UDF_status_report_msg( + agent_to_cm_fenced_UDF_status_report* agent_to_cm_fenced_UDF_status_ptr); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_sync_dynamic_info.h postgresql-hll-2.14/include/cm/cm_server/cms_sync_dynamic_info.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_sync_dynamic_info.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_sync_dynamic_info.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,17 @@ +/** + * @file cms_sync_dynamic_info.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_SYNC_DYNAMIC_INFO_H +#define CMS_SYNC_DYNAMIC_INFO_H + +extern void* SyncDynamicInfoFromEtcd(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_threads.h postgresql-hll-2.14/include/cm/cm_server/cms_threads.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_threads.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,35 @@ +/** + * @file cms_threads.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_THREADS_H +#define CMS_THREADS_H + +#define SWITCHOVER_FLAG_FILE "cms_need_to_switchover" + +extern int CM_CreateHA(void); +extern int CM_CreateMonitor(void); +extern int CM_CreateMonitorStopNode(void); +extern int CM_CreateThreadPool(int thrCount); + +extern void CreateStorageThresholdCheckThread(); +extern void create_deal_phony_alarm_thread(); +extern void CreateAzStatusCheckForAzThread(); +extern void CreateAz1Az2ConnectStateCheckThread(); +extern void Init_cluster_to_switchover(); +extern void CreateSyncDynamicInfoThread(); +extern void CreateMultiAzConnectStateCheckThread(); +extern void CreateCheckBlackListThread(); +extern void* CheckBlackList(void* arg); +extern void CreateDynamicCfgSyncThread(); +extern CM_Thread* GetNextThread(int ctlThreadNum); +extern CM_Thread* GetNextCtlThread(int threadNum); + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/cm_server/cms_write_dynamic_config.h postgresql-hll-2.14/include/cm/cm_server/cms_write_dynamic_config.h --- postgresql-hll-2.14_old/include/cm/cm_server/cms_write_dynamic_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/cm_server/cms_write_dynamic_config.h 2020-12-12 17:06:43.099346129 +0800 @@ -0,0 +1,18 @@ +/** + * @file cms_write_dynamic_config.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-11-10 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_WRITE_DYNAMIC_CONFIG_H +#define CMS_WRITE_DYNAMIC_CONFIG_H + +extern bool NeedCreateWriteDynamicThread(); +extern int WriteDynamicConfigFile(bool isRealWriteDynamic); +extern void *WriteDynamicCfgMain(void *arg); +#endif diff -uprN postgresql-hll-2.14_old/include/cm/elog.h postgresql-hll-2.14/include/cm/elog.h --- postgresql-hll-2.14_old/include/cm/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/elog.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/elog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include "c.h" +#include "pgtime.h" +#include + +#ifdef HAVE_SYSLOG +#ifndef MONITOR_SYSLOG_LIMIT +#define MONITOR_SYSLOG_LIMIT 900 +#endif +#endif + +#define LOG_DESTION_STDERR 0 +#define LOG_DESTION_SYSLOG 1 +#define LOG_DESTION_FILE 2 +#define LOG_DESTION_DEV_NULL 3 + +extern int log_destion_choice; +extern volatile int log_min_messages; +extern volatile int maxLogFileSize; +extern volatile int curLogFileNum; +extern volatile bool logInitFlag; +/* unify log style */ +extern THR_LOCAL const char* thread_name; + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ + +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ + +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define FATAL 22 /* fatal error - abort process */ + +/* + * express means you want to free the space alloced + * by yourself. e.g. express could be "free(str1);free(str2)" + */ +#define check_errno(errno, express, file, line) \ + { \ + if (EOK != errno) { \ + express; \ + write_runlog(ERROR, "%s : %d failed on calling security function, err:%u.\n", file, line, errno); \ + exit(1); \ + } \ + } + +#define securec_check_errno(errno, express) check_errno(errno, express, __FILE__, __LINE__) + +/* Only used in sprintf_s or scanf_s cluster function */ +#define check_intval(errno, express, file, line) \ + { \ + if (errno == -1) { \ + express; \ + write_runlog(ERROR, "check_intval %s : %d failed on calling security function.\n", file, line); \ + exit(1); \ + } \ + } + +#define securec_check_intval(errno, express) check_intval(errno, express, __FILE__, __LINE__) + +#define check_sscanf_s_result(rc, expect_rc) \ + { \ + if (rc != expect_rc) { \ + write_runlog(ERROR, "get value by sscanf_s return error:%d, %s:%d \n", rc, __FILE__, __LINE__); \ + } \ + } + +#define PG_CTL_NAME "gs_ctl" +#define PG_REWIND_NAME "gs_rewind" +#define GTM_CTL_NAME "gtm_ctl" +#define CM_CTL_NAME "cm_ctl" + +#define COORDINATE_BIN_NAME "gaussdb" +#define DATANODE_BIN_NAME "gaussdb" +#define GTM_BIN_NAME "gs_gtm" +#define CM_SERVER_BIN_NAME "cm_server" +#define CM_AGENT_NAME "cm_agent" +#define FENCED_MASTER_BIN_NAME "gaussdb" +#define KERBEROS_BIN_NAME "krb5kdc" + +#define CM_AUTH_REJECT (0) +#define CM_AUTH_TRUST (1) +#define CM_AUTH_GSS (2) + +extern void write_runlog(int elevel, const char* fmt, ...) __attribute__((format(printf, 2, 3))); + +FILE* logfile_open(const char* filename, const char* mode); +void write_runlog(int elevel, const char* fmt, ...); +void add_log_prefix(char* str); + +void write_log_file(const char* buffer, int count); + +#define curLogFileMark ("-current.log") + +int logfile_init(); +void openLogFile(void); +void switchLogFile(void); + +void get_log_paramter(const char* confDir); +int get_cm_thread_count(const char* config_file); +void get_build_mode(const char* config_file); +/*trim blank characters on both ends*/ +char* trim(char* src); +int is_comment_line(const char* str); +int is_digit_string(char* str); +int SetFdCloseExecFlag(FILE* fp); + +/* + * @Description: get value of paramater from configuration file + * + * @in config_file: configuration file path + * @in key: name of paramater + * @in defaultValue: default value of parameter + * + * @out: value of parameter + */ +int get_int_value_from_config(const char* config_file, const char* key, int defaultValue); +int64 get_int64_value_from_config(const char* config_file, const char* key, int64 defaultValue); +uint32 get_uint32_value_from_config(const char* config_file, const char* key, uint32 defaultValue); +extern int get_authentication_type(const char* config_file); +extern void get_krb_server_keyfile(const char* config_file); + +extern const char* prefix_name; + +#define LOG_MAX_TIMELEN 80 + +/* inplace upgrade stuffs */ +extern volatile uint32 undocumentedVersion; +#define INPLACE_UPGRADE_PRECOMMIT_VERSION 1 + +#endif /* GTM_ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/cm/etcdapi.h postgresql-hll-2.14/include/cm/etcdapi.h --- postgresql-hll-2.14_old/include/cm/etcdapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/etcdapi.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,339 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * etcdapi.h + * + * + * + * IDENTIFICATION + * src/include/cm/etcdapi.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _ETCD_API_H_ +#define _ETCD_API_H_ + +typedef int EtcdSession; + +typedef enum { + ETCD_OK = 0, + ETCD_WTF = -1, + EcodeKeyNotFound = 100, + EcodeTestFailed = 101, + EcodeNotFile = 102, + ecodeNoMorePeer = 103, + EcodeNotDir = 104, + EcodeNodeExist = 105, + ecodeKeyIsPreserved = 106, + EcodeRootROnly = 107, + EcodeDirNotEmpty = 108, + ecodeExistingPeerAddr = 109, + EcodeUnauthorized = 110, + ecodeValueRequired = 200, + EcodePrevValueRequired = 201, + EcodeTTLNaN = 202, + EcodeIndexNaN = 203, + ecodeValueOrTTLRequired = 204, + ecodeTimeoutNaN = 205, + ecodeNameRequired = 206, + ecodeIndexOrValueRequired = 207, + ecodeIndexValueMutex = 208, + EcodeInvalidField = 209, + EcodeInvalidForm = 210, + EcodeRefreshValue = 211, + EcodeRefreshTTLRequired = 212, + EcodeRaftInternal = 300, + EcodeLeaderElect = 301, + EcodeWatcherCleared = 400, + EcodeEventIndexCleared = 401, + ecodeStandbyInternal = 402, + ecodeInvalidActiveSize = 403, + ecodeInvalidRemoveDelay = 404, + ecodeClientInternal = 500 +} EtcdResult; + +typedef struct { + // PrevValue specifies what the current value of the Node must + // be in order for the Set operation to succeed. + // Leaving this field empty or NULL means that the caller wishes to + // ignore the current value of the Node. This cannot be used + // to compare the Node's current value to an empty string. + // PrevValue is ignored if Dir=true + char* prevValue; + + // PrevIndex indicates what the current ModifiedIndex of the + // Node must be in order for the Set operation to succeed. + // + // If PrevIndex is set to 0 (default), no comparison is made. + uint64_t prevIndex; + + // TTL defines a period of time after-which the Node should + // expire and no longer exist. Values <= 0 are ignored. Given + // that the zero-value is ignored, TTL cannot be used to set + // a TTL of 0. + int64_t ttl; + + // PrevExist specifies whether the Node must currently exist + // (PrevExist) or not (PrevNoExist). If the caller does not + // care about existence, set PrevExist to PrevIgnore, or simply + // leave it unset. + char prevExist[5]; + + // Refresh set to true means a TTL value can be updated + // without firing a watch or changing the node value. A + // value must not be provided when refreshing a key. + bool refresh; + + // Dir specifies whether or not this Node should be created as a directory. + bool dir; + + // NoValueOnSuccess specifies whether the response contains the current value of the Node. + // If set, the response will only contain the current value when the request fails. + bool noValueOnSuccess; +} SetEtcdOption; + +typedef struct { + // Recursive defines whether or not all children of the Node + // should be returned. + bool recursive; + + // Sort instructs the server whether or not to sort the Nodes. + // If true, the Nodes are sorted alphabetically by key in + // ascending order (A to z). If false (default), the Nodes will + // not be sorted and the ordering used should not be considered + // predictable. + bool sort; + + // Quorum specifies whether it gets the latest committed value that + // has been applied in quorum of members, which ensures external + // consistency (or linearizability). + bool quorum; +} GetEtcdOption; + +typedef struct { + // PrevValue specifies what the current value of the Node must + // be in order for the Delete operation to succeed. + // + // Leaving this field empty means that the caller wishes to + // ignore the current value of the Node. This cannot be used + // to compare the Node's current value to an empty string. + char* prevValue; + + // PrevIndex indicates what the current ModifiedIndex of the + // Node must be in order for the Delete operation to succeed. + // + // If PrevIndex is set to 0 (default), no comparison is made. + uint64_t prevIndex; + + // Recursive defines whether or not all children of the Node + // should be deleted. If set to true, all children of the Node + // identified by the given key will be deleted. If left unset + // or explicitly set to false, only a single Node will be + // deleted. + bool recursive; + + // Dir specifies whether or not this Node should be removed as a directory. + bool dir; +} DeleteEtcdOption; + +typedef struct { + char* host; + unsigned short port; +} EtcdServerSocket; + +const int ETCD_MAX_PATH_LEN = 1024; + +typedef struct { + char etcd_ca_path[ETCD_MAX_PATH_LEN]; + char client_crt_path[ETCD_MAX_PATH_LEN]; + char client_key_path[ETCD_MAX_PATH_LEN]; +} EtcdTlsAuthPath; + +#define ETCD_VALUE_LEN 128 +#define ERR_LEN 1024 +#define ETCD_STATE_LEN 16 +/* The default timeout is 2s */ +const int ETCD_DEFAULT_TIMEOUT = 2000; + +/* + * etcd_open + * + * Establish a session to an etcd cluster.On success, 0 is returned; + * on failure, an error code is returned + * + * session + * The index of the session being created + * + * server_list + * Array of etcd_server structures, with the last having host=NULL. The + * caller is responsible for ensuring that this remains valid as long as + * the session exists. + * + * tls_path + * Certificate information required for HTTPS connection + * + * time_out + * This parameter is used to set the session timeout period. + */ +int etcd_open(EtcdSession* session, EtcdServerSocket* server_list, EtcdTlsAuthPath* tls_path, int time_out); + +/* + * etcd_close + * + * Terminate a session, closing connections and freeing memory (or any other + * resources) associated with it. + * + * session + * The index of the session to be closed. + */ +int etcd_close(int session); + +/* + * etcd_open_str + * + * Create a session for the ETCD cluster with a string containing + * the list of services and certificates and timeout information. + * + * session + * The index of the session being created + * + * server_names + * String containing the service list. If the session information + * exists, The caller is responsible for ensuring that this remains + * valid as long as the session exists. + * + * tls_path + * Certificate information required for HTTPS connection + * + * timeout + * This parameter is used to set the session timeout period. + */ +int etcd_open_str(EtcdSession* session, char* server_names, EtcdTlsAuthPath* tls_path, int timeout); + +/* + * etcd_set + * + * Write a key, with optional previous value (as a precondition). + * + * session + * The index of the session + * + * key + * The etcd key (path) to set. + * + * value + * New value as a null-terminated string. + * + * option + * Indicates the operation information structure of the set operation. + * Currently, only prevValue is used. If prevValue = NULL, prevValue + * is not used. That is, the value of the current node is not considered. + */ +int etcd_set(EtcdSession session, char* key, char* value, SetEtcdOption* option); + +/* + * etcd_get + * + * Fetch a key from one of the servers in a session.On success, 0 is returned; + * on failure, an error code is returned + * + * session + * The index of the session + * + * key + * The etcd key (path) to fetch. + * + * value + * The value of the key, it is a newly allocated string, which must be + * freed by the caller. + * + * max_size + * defines the max buffer size of health_member + * + * option + * Operation information structure of the Get operation. Currently, + * only quorum is used to specify whether to obtain the latest committed + * value applied in the member arbitration to ensure external consistency + * (or linearization). + */ +int etcd_get(int session, char* key, char* value, int max_size, GetEtcdOption* option); + +/* + * etcd_delete + * + * Delete a key from one of the servers in a session. + * + * session + * The index of the session + * + * key + * The etcd key (path) to delete. + * + * option + * Indicates the operation information structure of the Delete operation. + * No information is used at present. + */ +int etcd_delete(int session, char* key, DeleteEtcdOption* option); + +/* + * etcd_cluster_health + * + * Get the health of the cluster.If member_name is not empty, check the health + * status of the corresponding etcd node and store the health status into + * health_member. If member_name is empty, check the health status of the entire + * etcd cluster and write health_member. + * + * session + * The index of the session + * + * member_name + * etcd member name,If this parameter is set to NULL or an empty string, + * the health status of the ETCD cluster is obtained. If the character + * string is a node name, it indicates the health status of a node. + * + * health_state + * Save the etcd cluster health information + * + * state_Size + * defines the max buffer size of health_member + */ +int etcd_cluster_health(int session, char* member_name, char* health_state, int state_Size); + +/* + * etcd_cluster_state + * + * Get the state of the cluster member. + * + * session + * The index of the session + * + * member_name + * etcd member name + * + * is_leader + * Whether this node is the leader node or not + */ +int etcd_cluster_state(int session, char* member_name, bool* is_leader); + +/* + * get_last_error + * + * Obtains the information that fails to be invoked and saves the information to the buffer. If the interface is + * successfully invoked, the buffer is empty. + * + */ +const char* get_last_error(); + +#endif diff -uprN postgresql-hll-2.14_old/include/cm/ip.h postgresql-hll-2.14/include/cm/ip.h --- postgresql-hll-2.14_old/include/cm/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/ip.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/ip.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "cm/pqcomm.h" + +extern int cmpg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void cmpg_freeaddrinfo_all(struct addrinfo* ai); + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/cm/libpq-be.h postgresql-hll-2.14/include/cm/libpq-be.h --- postgresql-hll-2.14_old/include/cm/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/libpq-be.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,129 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-be.h + * This file contains definitions for structures and externs used + * by the cm server during client coonect. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/libpq-be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_BE_H +#define CM_LIBPQ_BE_H + +#include "cm/pqcomm.h" +#include "cm/cm_c.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * This is used by the cm server in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMostMemoryContext, + * so that it survives into GTM_ThreadMain execution! + */ + +typedef struct Port { + int sock; /* File descriptor */ + CMSockAddr laddr; /* local addr (postmaster) */ + CMSockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_port; /* text rep of remote port */ + CM_PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ + + char* user_name; + int remote_type; /* Type of remote connection */ + uint32 node_id; + char* node_name; + bool is_postmaster; /* Is remote a node postmaster? */ + bool startpack_have_processed; +#define PQ_BUFFER_SIZE (16 * 1024) + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + + /* + * GTM communication error handling. See libpq-int.h for details. + */ + int connErr_WaitOpt; + int connErr_WaitInterval; + int connErr_WaitCount; + + /* Support kerberos authentication for gtm server */ + char* krbsrvname; /* Kerberos service name */ +} Port; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); +extern int pq_getbyte(Port* myport); +extern int pq_getmessage(Port* myport, CM_StringInfo s, int maxlen); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int SetSocketNoBlock(int isocketId); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/cm/libpq-fe.h postgresql-hll-2.14/include/cm/libpq-fe.h --- postgresql-hll-2.14_old/include/cm/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/libpq-fe.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * + * IDENTIFICATION + * src/include/cm/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_FE_H +#define CM_LIBPQ_FE_H + +#include +#include "cm_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define libpq_gettext(x) x + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +/* Application-visible enum types */ + +/* + * Although it is okay to add to these lists, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + +typedef enum { + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} CMConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} CMPostgresPollingStatusType; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or CMPQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. CMPQconninfoFree() + * will release both the val strings and the CMPQconninfoOption array itself. + * ---------------- + */ +typedef struct _CMPQconninfoOption { + char* keyword; /* The keyword of the option */ + char* val; /* Option's current value, or NULL */ +} CMPQconninfoOption; + +typedef struct cm_conn CM_Conn; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern CM_Conn* PQconnectCMStart(const char* conninfo); +extern CMPostgresPollingStatusType CMPQconnectPoll(CM_Conn* conn); + +/* Synchronous (blocking) */ +extern CM_Conn* PQconnectCM(const char* conninfo); + +/* close the current connection and free the CM_Conn data structure */ +extern void CMPQfinish(CM_Conn* conn); + +/* free the data structure returned by PQconndefaults() or CMPQconninfoParse() */ +extern void CMPQconninfoFree(CMPQconninfoOption* connOptions); + +extern CMConnStatusType CMPQstatus(const CM_Conn* conn); +extern char* CMPQerrorMessage(const CM_Conn* conn); + +/* Force the write buffer to be written (or at least try) */ +extern int CMPQflush(CM_Conn* conn); + +extern int CMPQPacketSend(CM_Conn* conn, char packet_type, const void* buf, size_t buf_len); +extern char* gs_getenv_with_check(const char* envKey); + +#ifdef __cplusplus +} +#endif + +#endif /* CM_LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/cm/libpq.h postgresql-hll-2.14/include/cm/libpq.h --- postgresql-hll-2.14_old/include/cm/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/libpq.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/libpq.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_H +#define CM_LIBPQ_H + +#include +#include + +#include "cm/stringinfo.h" +#include "cm/libpq-be.h" + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); + +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len, size_t* recvlen); + +extern int pq_getmessage(Port* myport, CM_StringInfo s, int maxlen); +extern int pq_getbyte(Port* myport); + +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/cm/libpq-int.h postgresql-hll-2.14/include/cm/libpq-int.h --- postgresql-hll-2.14_old/include/cm/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/libpq-int.h 2020-12-12 17:06:43.100346142 +0800 @@ -0,0 +1,162 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * + * IDENTIFICATION + * src/include/cm/libpq-int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_INT_H +#define CM_LIBPQ_INT_H + +#include +#include +#include +#include "cm/pqcomm.h" +#include "cm/pqexpbuffer.h" +#include "cm/cm_c.h" +#include "cm/cm_msg.h" + +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * cm_Conn stores all the state data associated with a single connection + * to a backend. + */ +struct cm_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the IPv4 address of the machine on which + * the server is running, in IPv4 + * numbers-and-dots notation. Takes precedence + * over above. */ + char* pgport; /* the server's communication port */ + char* pglocalhost; + char* pglocalport; + char* connect_timeout; /* connection timeout (numeric string) */ + char* pguser; /* CM username and password, if any */ + int node_id; + char* gc_node_name; /* PGXC Node Name */ + int remote_type; /* is this a connection to/from a proxy ? */ + int is_postmaster; /* is this connection to/from a postmaster instance */ + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Status indicators */ + CMConnStatusType status; + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + CMSockAddr laddr; /* Local address */ + CMSockAddr raddr; /* Remote address */ + + /* Error info for cm communication */ + int last_call; + int last_errno; /* Last errno. zero if the last call succeeds. */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + + /* Pointer to the result of last operation */ + CM_Result* result; + + /* Support kerberos authentication for gtm server */ + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_name_t gss_targ_nam; /* GSS target name */ + gss_buffer_desc gss_inbuf; /* GSS input token */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +}; + +/* === in fe-misc.c === */ + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int cmpqCheckOutBufferSpace(size_t bytes_needed, CM_Conn* conn); +extern int cmpqCheckInBufferSpace(size_t bytes_needed, CM_Conn* conn); +extern int cmpqGetc(char* result, CM_Conn* conn); +extern int cmpqGets(PQExpBuffer buf, CM_Conn* conn); +extern int cmpqGets_append(PQExpBuffer buf, CM_Conn* conn); +extern int cmpqPutnchar(const char* s, size_t len, CM_Conn* conn); +extern int cmpqGetnchar(char* s, size_t len, CM_Conn* conn); +extern int cmpqGetInt(int* result, size_t bytes, CM_Conn* conn); +extern int cmpqPutMsgStart(char msg_type, bool force_len, CM_Conn* conn); +extern int cmpqPutMsgEnd(CM_Conn* conn); +extern int cmpqReadData(CM_Conn* conn); +extern int cmpqFlush(CM_Conn* conn); +extern int cmpqWait(int forRead, int forWrite, CM_Conn* conn); +extern int cmpqWaitTimed(int forRead, int forWrite, CM_Conn* conn, time_t finish_time); +extern int cmpqReadReady(CM_Conn* conn); + +/* + * In fe-protocol.c + */ +extern CM_Result* cmpqGetResult(CM_Conn* conn); +extern int cmpqGetError(CM_Conn* conn, CM_Result* result); +extern void cmpqResetResultData(CM_Result* result); + +#define SOCK_ERRNO errno +#define SOCK_ERRNO_SET(e) (errno = (e)) + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/cm/path.h postgresql-hll-2.14/include/cm/path.h --- postgresql-hll-2.14_old/include/cm/path.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/path.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * path.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/path.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PATH_H +#define _PATH_H + +#include "cm/cm_c.h" + +extern void trim_directory(char* path); +#endif diff -uprN postgresql-hll-2.14_old/include/cm/pqcomm.h postgresql-hll-2.14/include/cm/pqcomm.h --- postgresql-hll-2.14_old/include/cm/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/pqcomm.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/pqcomm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_PQCOMM_H +#define CM_PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} CMSockAddr; + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +/* These are the authentication request codes sent by gtm server. */ +#define CM_AUTH_REQ_OK 0 /* User is authenticated */ +#define CM_AUTH_REQ_GSS 1 /* GSSAPI without wrap() */ +#define CM_AUTH_REQ_GSS_CONT 2 /* Continue GSS exchange */ + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/cm/pqexpbuffer.h postgresql-hll-2.14/include/cm/pqexpbuffer.h --- postgresql-hll-2.14_old/include/cm/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/pqexpbuffer.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqexpbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H + +/*------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + *------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/*------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + *------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/*------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + *------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/*------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + *------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/*------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createCMPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initCMPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + *------------------------- + */ + +/*------------------------ + * initCMPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyCMPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createCMPQExpBuffer(). + * + * termCMPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initCMPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void termCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * resetCMPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * enlargeCMPQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargeCMPQExpBuffer(PQExpBuffer str, size_t needed); + +/*------------------------ + * printfCMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetCMPQExpBuffer() followed by appendCMPQExpBuffer(). + */ +extern void printfCMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendCMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendCMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendBinaryCMPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryCMPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/cm/pqformat.h postgresql-hll-2.14/include/cm/pqformat.h --- postgresql-hll-2.14_old/include/cm/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/pqformat.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqformat.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "cm/stringinfo.h" +#include "cm/cm_msg.h" + +extern const char* pq_get_msg_type(CM_StringInfo msg, int datalen); +extern const char* pq_getmsgbytes(CM_StringInfo msg, int datalen); +extern const char* pq_getmsgbytes(CM_Result* msg, int datalen); +#endif diff -uprN postgresql-hll-2.14_old/include/cm/pqsignal.h postgresql-hll-2.14/include/cm/pqsignal.h --- postgresql-hll-2.14_old/include/cm/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/pqsignal.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqsignal.h + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +extern sigset_t unblock_sig, block_sig; + +typedef void (*sigfunc)(int); + +extern void init_signal_mask(void); + +#ifndef WIN32 +extern sigfunc setup_signal_handle(int signo, sigfunc func); +#endif /* WIN32 */ + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/cm/stringinfo.h postgresql-hll-2.14/include/cm/stringinfo.h --- postgresql-hll-2.14_old/include/cm/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cm/stringinfo.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,184 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/stringinfo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_STRINGINFO_H +#define CM_STRINGINFO_H + +#include + +/*------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + *------------------------- + */ +typedef struct CM_StringInfoData { + char* data; + int len; + int maxlen; + int cursor; + int qtype; + int msglen; +} CM_StringInfoData; + +typedef CM_StringInfoData* CM_StringInfo; + +#define CM_MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define CM_AllocSizeIsValid(size) ((Size)(size) <= CM_MaxAllocSize) + +/*------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + *------------------------- + */ + +/*------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern CM_StringInfo CM_makeStringInfo(void); + +/*------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void CM_initStringInfo(CM_StringInfo str); + +/*------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void CM_resetStringInfo(CM_StringInfo str); + +/*------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void CM_appendStringInfo(CM_StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool CM_appendStringInfoVA(CM_StringInfo str, const char* fmt, va_list args) + __attribute__((format(printf, 2, 0))); + +/*------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void CM_appendStringInfoString(CM_StringInfo str, const char* s); + +/*------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void CM_appendStringInfoChar(CM_StringInfo str, char ch); + +/*------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define CM_appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? CM_appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/*------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void CM_appendBinaryStringInfo(CM_StringInfo str, const char* data, int datalen); + +/*------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern int CM_enlargeStringInfo(CM_StringInfo str, int needed); + +/*----------------------- + * dupStringInfo + * Get new StringInfo and copy the original to it. + */ +extern CM_StringInfo CM_dupStringInfo(CM_StringInfo orig); + +/*------------------------ + * copyStringInfo + * Copy StringInfo. Deep copy: Data will be copied too. + * cursor of "to" will be initialized to zero. + */ +extern void CM_copyStringInfo(CM_StringInfo to, CM_StringInfo from); + +extern int CM_is_str_all_digit(const char* name); +extern void CM_destroyStringInfo(CM_StringInfo str); +extern void CM_freeStringInfo(CM_StringInfo str); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/codegen/builtinscodegen.h postgresql-hll-2.14/include/codegen/builtinscodegen.h --- postgresql-hll-2.14_old/include/codegen/builtinscodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/builtinscodegen.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,173 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * builtinscodegen.h + * Declarations of code generation for operations on built-in types. + * + * + * IDENTIFICATION + * src/include/codegen/builtinscodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_BUILTINS_H +#define LLVM_BUILTINS_H +#include "catalog/pg_type.h" +#include "codegen/gscodegen.h" +#include "fmgr.h" +#include "nodes/execnodes.h" +#include "nodes/primnodes.h" +#include "utils/biginteger.h" + +namespace dorado { +/* Get the byte length of a multibyte character. */ +#define MB_LEN(mlen, string) \ + if ((*string & 0x80) == 0) \ + mlen = 1; \ + else if ((*string & 0xe0) == 0xc0) \ + mlen = 2; \ + else if ((*string & 0xf0) == 0xe0) \ + mlen = 3; \ + else if ((*string & 0xf8) == 0xf0) \ + mlen = 4; \ + else \ + mlen = 1; + +/* + * int_codegen.inl + * template function for simple op('='/'!='/'<='/'>='/'<'/'>') of int type. + */ +template +llvm::Function* int2_sop_codegen(); +template +llvm::Function* int4_sop_codegen(); +template +llvm::Function* int8_sop_codegen(); +template +llvm::Function* int2_int4_sop_codegen(); +template +llvm::Function* int4_int8_sop_codegen(); + +/* + * numeric_codegen.inl + * template function for simple op('='/'!='/'<='/'>='/'<'/'>') of numeric type. + * Since most cases the data can be converted to BI integer, we especially + * codegen the bi64 operations. For orginal numeric data, just call original + * row functions. + */ +template +llvm::Function* numeric_sop_codegen(); +template +llvm::Function* bi64cmp64_codegen(); +template +llvm::Function* fast_numericbi_sop_codegen(); +template +llvm::Value* WrapnumericFuncCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* arg); + +/* boolcodegen.cpp */ +llvm::Function* booleq_codegen(); + +/* intcodegen.cpp */ +llvm::Function* int4pl_codegen(); +llvm::Function* int4mi_codegen(); +llvm::Function* int4mul_codegen(); +llvm::Function* int4div_codegen(); +llvm::Function* int8pl_codegen(); +llvm::Function* int8mi_codegen(); +llvm::Function* int8mul_codegen(); +llvm::Function* int8div_codegen(); +llvm::Function* int48pl_codegen(); +llvm::Function* int84pl_codegen(); +llvm::Function* int48mi_codegen(); +llvm::Function* int84mi_codegen(); +llvm::Function* int48mul_codegen(); +llvm::Function* int84mul_codegen(); +llvm::Function* int48div_codegen(); +llvm::Function* int84div_codegen(); + +/* floatcodegen.cpp */ +llvm::Function* float8eq_codegen(); +llvm::Function* float8ne_codegen(); +llvm::Function* float8lt_codegen(); +llvm::Function* float8le_codegen(); +llvm::Function* float8gt_codegen(); +llvm::Function* float8ge_codegen(); + +/* numericcodegen.cpp */ +llvm::Function* int8_sum_codegen(Aggref* aggref); +llvm::Function* int8_avg_codegen(Aggref* aggref); +llvm::Function* numeric_sum_codegen(Aggref* aggref); +llvm::Function* vsnumeric_sum_codegen(Aggref* aggref); +llvm::Function* numeric_avg_codegen(Aggref* aggref); +llvm::Function* vsnumeric_avg_codegen(Aggref* aggref); +llvm::Function* vec_count_codegen(Aggref* aggref); +llvm::Function* vsonic_count_codegen(Aggref* aggref); + +/* assistant function needed by numeric agg functions */ +llvm::Value* DatumGetBINumericCodeGenShort(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval); +llvm::Value* DatumGetBINumericCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval); +llvm::Value* WrapaddVariableCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ccontext, llvm::Value* val); +llvm::Value* WrapreplVariableCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ccontext, llvm::Value* oldval, llvm::Value* val); +llvm::Value* WrapmakeNumeric64CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* scale); +llvm::Value* WrapmakeNumeric128CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* scale); +void WrapBiAggAddMatrixCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* arg1, llvm::Value* arg2, + llvm::Value* leftarg, llvm::Value* rightarg, llvm::Value* ctl); +llvm::Value* WrapBiFunMatrixCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* op, llvm::Value* arg1, + llvm::Value* arg2, llvm::Value* leftarg, llvm::Value* rightarg); +void WrapDeconstructArrayCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval, llvm::Value* datumarray, llvm::Value* ndatum); +void WrapcallnumericaddCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* cell, llvm::Value* mct, + llvm::Value* larg, llvm::Value* rarg, llvm::Value* nidx); +void WrapcallscnumaddCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* larg, llvm::Value* rarg, llvm::Value* loc); + +/* bigintegercodegen.cpp */ +llvm::Function* bi64add64_codegen(bool use_ctl); +llvm::Function* bi64sub64_codegen(); +llvm::Function* bi64mul64_codegen(); +llvm::Function* bi64div64_codegen(); + +/* assistant function needed by biginteger functions */ +llvm::Value* GetInt64MulOutofBoundCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +llvm::Value* ScaleMultiCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +llvm::Value* GetScaleMultiCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +void WrapReplVarWithOldCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ctl, llvm::Value* Val); +llvm::Value* Wrapbi64div64CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* larg, llvm::Value* rarg); + +/* varcharcodegen.cpp */ +llvm::Function* bpchareq_codegen(); +llvm::Function* bpcharne_codegen(); +llvm::Function* bpcharlen_codegen(int current_encoding); + +/* varlenacodegen.cpp */ +llvm::Function* texteq_codegen(); +llvm::Function* textlt_codegen(); +llvm::Function* textgt_codegen(); +llvm::Function* substr_codegen(); +llvm::Function* rtrim1_codegen(); +llvm::Function* btrim1_codegen(); +llvm::Function* textlike_codegen(); +llvm::Function* textnlike_codegen(); + +llvm::Function* VarlenaCvtCodeGen(); +llvm::Value* VarlenaGetDatumCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* len, llvm::Value* data); +} // namespace dorado + +/* Include template function in int_codegen.inl */ +#include "../../gausskernel/runtime/codegen/codegenutil/int_codegen.inl" +#include "../../gausskernel/runtime/codegen/codegenutil/numeric_codegen.inl" + +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/codegendebuger.h postgresql-hll-2.14/include/codegen/codegendebuger.h --- postgresql-hll-2.14_old/include/codegen/codegendebuger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/codegendebuger.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,89 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * codegendebuger.h + * + * + * + * IDENTIFICATION + * src/include/codegen/codegendebuger.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CODEGEN_DEBUGER_H +#define CODEGEN_DEBUGER_H + +#include "codegen/gscodegen.h" + +namespace dorado { +class DebugerCodeGen : public BaseObject { +public: + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Support debuging in machine code by calling c-function + * WrapCodeGenDebuger. + * Input : ptrbuilder : in which builder we call this function + * value : the actual value when running. + * flag : mask the position to distinct diffrent cases + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void CodeGenDebugInfo(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* value, Datum flag); + + static void CodeGenDebugString(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* value, Datum flag); + + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Support debuging in machine code by calling c-function + * WrapElog. + * Input : ptrbuilder : in which builder we call this function + * eleval : reporting level. + * cvalue : the actual error string defined in LLVM function. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void CodeGenElogInfo(GsCodeGen::LlvmBuilder* ptrbuilder, Datum elevel, const char* cvalue); + + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Wrap the elog function, with which we could easily + * see the actual value when debugging. + * Input : value : the actual value when running. + * flag : mask the position to distinct diffrent cases + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void WrapCodeGenDebuger(Datum value, Datum flag); + + static void WrapCodeGenString(char* string, Datum flag); + + /* + * Brief : Wrap an elog function with different error level. + * Description : Wrap the elog function, which will be call in LLVM + * to support error reporting. + * Input : elevel : reporting level. + * strdate : the actual error string. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void WrapCodeGenElog(Datum elevel, char* strdata); +}; +} // namespace dorado + +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/datecodegen.h postgresql-hll-2.14/include/codegen/datecodegen.h --- postgresql-hll-2.14_old/include/codegen/datecodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/datecodegen.h 2020-12-12 17:06:43.101346154 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datecodegen.h + * Definitions of code generation for the SQL92 "date" and + * "time" types. + * + * + * IDENTIFICATION + * src/include/codegen/datecodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_DATE_H +#define LLVM_DATE_H +#include "codegen/gscodegen.h" + +namespace dorado { +/* + * Comparision functions for dates + */ +llvm::Function* date_eq_codegen(); +llvm::Function* date_ne_codegen(); +llvm::Function* date_lt_codegen(); +llvm::Function* date_le_codegen(); +llvm::Function* date_gt_codegen(); +llvm::Function* date_ge_codegen(); +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/codegen/foreignscancodegen.h postgresql-hll-2.14/include/codegen/foreignscancodegen.h --- postgresql-hll-2.14_old/include/codegen/foreignscancodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/foreignscancodegen.h 2020-12-12 17:06:43.102346167 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * foreignscancodegen.h + * + * + * + * IDENTIFICATION + * src/include/codegen/foreignscancodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_FOREIGN_SCAN_H +#define LLVM_FOREIGN_SCAN_H + +#include "codegen/gscodegen.h" +#include "optimizer/clauses.h" +#include "nodes/execnodes.h" + +namespace dorado { + +/* + * LlvmForeignScan class implements specific optimization by using LLVM. + * Just now, pushed down predicate is optimized by using LLVM. + */ +class ForeignScanCodeGen : public BaseObject { +public: + static bool ScanCodeGen(Expr* expr, PlanState* parent, void** jittedFunc); + + /* + * Brief : Check whether operator is legal or not. + * Description : Just now, the follwing operator is legal. + * "=", "!=", ">", ">=", "<", "<=". + * These operator must act on the following data types. + * int2, int4, int8, float4, float8. + * Input : expr, the node to be checked. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static bool IsJittableExpr(Expr* expr); + + /* + * Brief : Build LLVM value by using node. + * Description : + * Input : node, the node to be used to create IR. + * llvm_args, the argument of IR functionto to be created. + * builder, a LlvmBuilder object. + * fname, function name. + * Output : None. + * Return Value : Retrun llvm::Value. + * Notes : None. + */ + static llvm::Value* buildConstValue( + Expr* node, llvm::Value* llvm_args[], GsCodeGen::LlvmBuilder builder, StringInfo fname); +}; +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/codegen/gscodegen.h postgresql-hll-2.14/include/codegen/gscodegen.h --- postgresql-hll-2.14_old/include/codegen/gscodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/gscodegen.h 2020-12-12 17:06:43.102346167 +0800 @@ -0,0 +1,756 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gscodegen.h + * + * + * + * IDENTIFICATION + * src/include/codegen/gscodegen.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_CODEGENH +#define GS_CODEGENH + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +#endif + +#include "llvm/IR/Verifier.h" +#include "llvm/ExecutionEngine/MCJIT.h" +#include "llvm/ExecutionEngine/ObjectCache.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Intrinsics.h" +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/circular_raw_ostream.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/raw_os_ostream.h" + +#undef __STDC_LIMIT_MACROS +#include "c.h" +#include "nodes/pg_list.h" +#include "lib/stringinfo.h" +#include "utils/dfs_vector.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +#ifndef BITS +#define BITS 8 +#endif + +/* The max length of the IR Function's path */ +#define MAX_LLVMIR_PATH 1024 + +/* position of elements that needed in vechashtbl */ +#define pos_hashtbl_size 0 +#define pos_hashtbl_data 1 + +/* position of elements that needed in VectorBatch class */ +#define pos_batch_mrows 0 +#define pos_batch_mcols 1 +#define pos_batch_marr 4 + +/* position of elements that needed in ScalarVector class */ +#define pos_scalvec_mrows 0 +#define pos_scalvec_flag 3 +#define pos_scalvec_vals 5 + +/* position of elements that needed in hashJoinTbl class */ +#define pos_hjointbl_inbatch 12 +#define pos_hjointbl_outbatch 13 +#define pos_hjointbl_StateLog 23 +#define pos_hjointbl_match 26 + +/* position of elements that needed in hashBasedOperator class */ +#define pos_hBOper_htbl 1 +#define pos_hBOper_hcxt 2 +#define pos_hBOper_cacheLoc 4 +#define pos_hBOper_cellCache 5 +#define pos_hBOper_keyMatch 6 +#define pos_hBOper_cols 18 +#define pos_hBOper_mkey 19 +#define pos_hBOper_keyIdx 20 + +/* position of elements that needed in HashAggRunner class */ +#define pos_hAggR_hashVal 3 +#define pos_hAggR_hSegTbl 12 +#define pos_hAggR_hsegmax 14 +#define pos_hAggR_hashSize 15 + +/* position of elements that needed in BaseAggRunner class */ +#define pos_bAggR_keyIdxInCell 8 +#define pos_bAggR_keySimple 11 +#define pos_bAggR_Loc 18 +#define pos_bAggR_econtext 22 + +/* position of elements that needed in ExprContext structure */ +#define pos_ecxt_pertuple 5 +#define pos_ecxt_scanbatch 17 +#define pos_ecxt_innerbatch 18 +#define pos_ecxt_outerbatch 19 + +/* position of elements that needed in hashCell structure */ +#define pos_hcell_mval 1 + +/* position of elements that needed in hashVal structure */ +#define pos_hval_val 0 +#define pos_hval_flag 1 + +/* position of elements that needed in StringInfo structure */ +#define pos_strinfo_data 0 +#define pos_strinfo_len 1 + +/* position of elements that needed in SonicHashAgg structure */ +#define pos_shashagg_ecxt 12 + +/* position of elements that needed in SonicHash structure */ +#define pos_shash_data 1 +#define pos_shash_sonichmemctl 14 +#define pos_shash_loc 16 + +/* position of elements that needed in SonicHashMemoryControl structure */ +#define pos_sonichmemctl_hcxt 8 + +/* position of elements that needed in SonicDatumArray structure */ +#define pos_sdarray_cxt 1 +#define pos_sdarray_atomsize 5 +#define pos_sdarray_nbit 7 +#define pos_sdarray_arr 8 + +/* position of elements that needed in atom structure */ +#define pos_atom_data 0 +#define pos_atom_nullflag 1 + +/* + * Declare related LLVM classes to avoid namespace pollution. + */ +namespace llvm { +class AllocaInst; +class BasicBlock; +class ConstantFolder; +class ExecutionEngine; +class Function; +using legacy::FunctionPassManager; +class LLVMContext; +class Module; +class NoFolder; +using legacy::PassManager; +class PointerType; +class StructType; +class TargetData; +class Type; +class Value; +class PassManagerBuilder; + +template +class IRBuilder; + +class IRBuilderDefaultInserter; +} // namespace llvm + +namespace dorado { + +/* + * @Description : Check whether we have the right to init codegen inviroment. + * @return : Return true if we can initialize the codgen inviroment. + */ +bool canInitCodegenInvironment(); + +/* + * @Description : Check whether we can initialize the CodeGen Object. + * @return : Return true if we can initialize the GsCodeGen Obj. + */ +bool canInitThreadCodeGen(); + +class GsCodeGen : public BaseObject { +public: + void initialize(); + + /* + * @Brief : Initialize LLVM environment. + * @Description : This function must be called once per process before + * any llvm API called. LLVM needs to allocate data + * structures for multi-threading support and to enable + * dynamic linking of jitted code. if 'load_backend' is + * true, load the backend static object for llvm. This + * is needed when libbackend.so is loaded from java. llvm + * will be default only look in the current object and + * not be able to find the backend symbols. + * @in load_backend : Decide to load the backend static object or not. + * The default value is false. + * @return : Return true if succeed. + */ + static bool InitializeLlvm(bool load_backend = false); + + /* + * @Description : Clear up the LLVM environment. + */ + static void cleanUpLlvm(); + + /* + * @Description : Load IR file and create a module. + * @in filename : Finename, a IR file path, like:\user\xxx\xxx.ir. + * @return : Return true if succeed.. + */ + bool parseIRFile(StringInfo filename); + + /* + * @Description : Find the location of IR file and load it. + */ + void loadIRFile(); + + /* + * Typedef builder in case we want to change the template arguments later + */ + typedef llvm::IRBuilder<> LlvmBuilder; + + /* + * Utility struct that wraps a variable name and llvm type. + */ + struct NamedVariable { + char* name; + llvm::Type* type; + + NamedVariable(char* name = "", llvm::Type* type = NULL) + { + this->name = name; + this->type = type; + } + }; + + /* + * define a Llvm_map which is similar to std::map + * in order to stroe the key-value pairs. + */ + template + class Llvm_Map : public BaseObject { + public: + T_KEY key; + T_VALUE value; + }; + + /* + * Abstraction over function prototypes. Contains helpers to build prototypes and + * generate IR for the types. + */ + class FnPrototype { + public: + /* + * @Description : Create a function prototype object + * @in gen : A LlvmCodeGen pointer. + * @in name : A specified function name. + * @in ret_type : The return value of the LLVM function. + * @Notes : It is a constructor. + */ + FnPrototype(GsCodeGen* gen, const char* name, llvm::Type* ret_type); + + /* + * @Description : Add a argument for the function. + * @in var : var, a struct for function argument + */ + void addArgument(const NamedVariable& var) + { + functionArgs.push_back(var); + } + + /* + * @Description : Create a LLVM function prototype. + * @in builder : The LLVM object, obtain many api for building LLVM function. + * @in params : return argumnets of LLVM function created. + * @return : return a created LLVM function pointer. + * @Notes : If params is non-null, this function will also + * return the arguments. + */ + llvm::Function* generatePrototype(LlvmBuilder* builder = NULL, llvm::Value** params = NULL); + + private: + friend class GsCodeGen; + + GsCodeGen* codeGen; + + char* functionName; /* functions name */ + llvm::Type* returnType; + + Vector functionArgs; /* the functions parameters */ + }; + + /* + * @Brief : Get a PointerType pointer. + * @Description : Get a LLVM Type pointer point to 'type'. + * @in type : a type struct of LLVM namespace. + * @return : return a PointerType pointer. + */ + llvm::PointerType* getPtrType(llvm::Type* type); + + /* + * @Brief : Get a Void Type of LLVM namespace + * @return : return the void type in LLVM Data Type. + */ + llvm::Type* getVoidType(); + + /* + * @Description : Get a Type of LLVM namespace according to a type OID. + * @in type : A type OID in Gauss200 database. + * @return : return a LLVM Data Type . + */ + llvm::Type* getType(unsigned int type); + + /* + * @Description : Get a PointerType pointer of LLVM namespace. + * @in type : A type OID in Gauss200 database. + * @return : return a PointerType Type . + */ + llvm::PointerType* getPtrType(unsigned int type); + + /* + * @Description : Get a Type of LLVM namespace according to a type name. + * : This name should be the one recorded in LLVM module. + * @in name : name of the struct type/class type. + * @return : return a Type . + */ + llvm::Type* getType(const char* name); + + /* + * @Description : Get a Type of LLVM namespace according to the 'name' type. + * @in type : A type name which can be recognized in Gauss200 database. + * @return : return a PointerType Type. + */ + llvm::PointerType* getPtrType(const char* name); + + /* + * @Description : Create a llvm pointer value from 'ptr'. This is used + * to pass pointers between c-code and code-generated IR. + * @in type : Data type in LLVM assemble with respect to the actual + * c-type we want to codegen. + * @in ptr : Pointer point to the actual c-code data type. + * @return : value in 'type' type. + */ + llvm::Value* CastPtrToLlvmPtr(llvm::Type* type, const void* ptr); + + /* + * @Description : Get reference to llvm context object. + * Each GsCodeGen has its own context to allow multiple + * threads to be calling into llvm at the same time. + * @return : Return reference to llvm context object. + */ + llvm::LLVMContext& context(); + + /* + * @Description : Get a current module. + * Module looks likes a container, which contains varibles, + * functions and types. + * @return : Return the current module in use. + */ + llvm::Module* module() + { + return m_currentModule; + } + + /* + * @Description : Adds the IR function to m_machineCodeJitCompiled List + * of GsCodeGen Object. Make a map which is consisted of + * IR function and machine code function pointer. At this + * time, the machine function pointer is a NULL pointer. + * @in F : A IR function which will be as a key of map. + * @in result_fn_ptr : A machine code function pointer which will be as + * a value of map. + * @return : void + */ + void addFunctionToMCJit(llvm::Function* F, void** result_fn_ptr); + + /* + * @Description : Adds the c-function calls to m_cfunctions_calls List in case of + * codegen_strategy is 'full'. + * each element in this List is a pair of funcName and funcOid. + * @return : void + */ + void recordCFunctionCalls(char* name); + + /* + * @Description : check whether we have used C-function calls in codegen. + * it will check C-function call recording list, + * and return whether m_cfunction_calls is empty or not + * @return : bool + */ + bool hasCFunctionCalls(); + + /* + * @Description : Clearing the C-function calls list m_cfunction_calls. + * @return : void + */ + void clearCFunctionCalls(); + + /* + * @Description : Dumping out the C-function calls in m_cfunction_calls. + * @in plan_id : plan id as extra information to display. + * @in location : description string for Filter Codegen or Targetlist Codegen. + * @return :void + */ + void dumpCFunctionCalls(const char* location, int plan_id); + + /** + * @Description : Verfies the generated IR function. + * + * @in function : The compiled function. + * @return : Return true if the funcion is valid, else retrun false. . + */ + bool verifyFunction(llvm::Function* function); + + /** + * @Description : + * @in function : LLVM Function we need to check. + * @in plan_node_id : The string flag of this IR function in module . + * @return : Void + */ + void FinalizeFunction(llvm::Function* function, int plan_node_id = 0); + + /* + * @Description : Returns the constant 'val' of 'type'. Since LLVM could only + * deal with arguments with the same type, we should make a + * difference between these types, even with the same value, + * say, int32 0 and int64 0. + * @in type : The corresponding type defined in PG we need to use in LLVM + * @in val : the natural value + * @return : the actual value defined in LLVM + */ + llvm::Value* getIntConstant(unsigned int type, int64_t val); + + /* + * @Description : Loads an LLVM module. 'file' should be the local path to the + * LLVM bitcode (.ll) file. If 'file_size' is not NULL, it will + * be set to the size of 'file'. The caller is responsible for + * cleaning up module. + * @in codegen : A GsCodeGen object. + * @in file : file, a IR file to be loaded. + * @in module : The current module we need to load. + * @return : Return true if successed. + */ + static bool loadModule(GsCodeGen* codegen, char* file, llvm::Module** module); + + /* + * @Description : Get a new llvm::ExecutionEngine with all the IR function + * be compiled. + * @in M : A llvm::Module pointer. + * @in enable_jitcache : If enable_jitcache is true, we need to use cache, + * else we do not need to use cache. + * @return : ExecutionEngien, which includs the module. + */ + llvm::ExecutionEngine* compileModule(llvm::Module* M, bool enable_jitcache); + + /* + * @Description : A GsCodeGen constructor. + * Initialize some variables of LlvmCodegen object. + */ + GsCodeGen(); + + /* + * @Description : release some variables of LlvmCodegen object. + */ + virtual ~GsCodeGen(); + + /* + * @Description : Turns on/off optimization passes for current module. + * @in : enable value, used to decide optimize passes or not + * @out : flag to optimization or not. + */ + void enableOptimizations(bool enable); + + /* + * @Description : Create a new module. + */ + bool createNewModule(); + + /* + * @Description : Create a new engine. + */ + llvm::ExecutionEngine* createNewEngine(llvm::Module* module); + + /* + * @Description : Close the current module. + */ + void closeCurrentModule() + { + m_currentModule = NULL; + } + + /* + * @Description : IR compile to machine code. + */ + void compileCurrentModule(bool enable_jitcache); + + /* + * @Description : Release resource. + * The resource includes IR function lists and execution engine. + */ + void releaseResource(); + + /* + * @Description : Get the pointer to the current module. + * @return : Current module in use. + */ + llvm::Module* getCurrentModule() + { + return m_currentModule; + } + + /* reset m_machineCodeJitCompiled */ + void resetMCJittedFunc() + { + m_machineCodeJitCompiled = NIL; + } + +public: + /* The module in use during this query process */ + llvm::Module* m_currentModule; + +private: + /* Initializes the jitter and execution engine. */ + bool init(); + + /* + * Optimize the module, this includes pruning the module of any unused + * functions. + */ + void optimizeModule(llvm::Module* module); + + /* Flag used to optimize the module or not */ + bool m_optimizations_enabled; + + /* Flag used to mask if we have loaded the ir file or not */ + bool m_llvmIRLoaded; + + /* + * If true, the module is corrupt and we cannot codegen this query. + * we could consider just removing the offending function and attempting to + * codegen the rest of the query. This requires more testing though to make sure + * that the error is recoverable. + */ + bool m_isCorrupt; + + /* Flag used to mask if the GsCodeGen Obj has been initialized or not */ + bool m_initialized; + + llvm::LLVMContext* m_llvmContext; + + /* The map of function to MCJIT compiled object */ + List* m_machineCodeJitCompiled; + + /* Execution Engine in use during this query process */ + llvm::ExecutionEngine* m_currentEngine; + + /* + * If true, the module has been compiled. It is not valid to add additional + * functions after this point. + */ + bool m_moduleCompiled; + + MemoryContext m_codeGenContext; + + /* Records the c-function calls in codegen IR fucntion of expression tree */ + List* m_cfunction_calls; +}; + +/* + * Macros used to define the variables + * + * By following all these regulars, we could easily define + * consts + */ +#define DEFINE_CGVAR_INT1(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(BITOID, val) +#define DEFINE_CGVAR_INT8(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(CHAROID, val) +#define DEFINE_CGVAR_INT16(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT2OID, val) +#define DEFINE_CGVAR_INT32(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT4OID, val) +#define DEFINE_CGVAR_INT64(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT8OID, val) + +/* + * Macros used to define the data types + */ +#define DEFINE_CG_VOIDTYPE(name) llvm::Type* name = llvmCodeGen->getVoidType() +#define DEFINE_CG_TYPE(name, typoid) llvm::Type* name = llvmCodeGen->getType(typoid) +#define DEFINE_CG_PTRTYPE(name, typoid) llvm::Type* name = llvmCodeGen->getPtrType(typoid) +#define DEFINE_CG_NINTTYP(name, nbit) llvm::Type* name = llvm::IntegerType::getIntNTy(context, nbit) +#define DEFINE_CG_ARRTYPE(name, typoid, num) llvm::Type* name = llvm::ArrayType::get(typoid, num) + +/* + * Define some operation + */ +#define DEFINE_BLOCK(name, insertbfpointer) \ + llvm::BasicBlock* name = llvm::BasicBlock::Create(context, #name, insertbfpointer); + +/* + * Define macros which help to catch and print the exception + * use SEGSEGVhandler to catch internal coredump occurred in LLVM. + */ +#define LLVM_TRY() \ + bool llvm_oper_success = true; \ + try + +#define LLVM_CATCH(msg) \ + catch (...) \ + { \ + llvm_oper_success = false; \ + } \ + if (!llvm_oper_success) { \ + ereport(ERROR, (errcode(ERRCODE_CODEGEN_ERROR), errmodule(MOD_LLVM), errmsg(msg))); \ + } + +} // namespace dorado + +/* + * Series of llvm::crc32 function. + * + * Contains llvm_crc32_32_8, llvm_crc32_32_16, llvm_crc32_32_32, llvm_crc32_32_64. + * + * All functions have three input parameters. The first parameter is the result value, + * and the next two parameters are input values. + * Each funtion's parameters are indicated through the function name. + * + * For example, llvm_crc32_32_8 indicates the result value is 32bits, + * the first input parameter is 32bits, and the second input is 8bits. + */ + +#ifdef __aarch64__ /* on ARM platform */ + +/* its function proto is: i32 @llvm.aarch64.crc32cb(i32 %cur, i32 %bits) */ +#define llvm_crc32_32_8(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cb); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cb function!\n"))); \ + } \ + llvm::Value* next_ext = builder.CreateZExt(next, int32Type); \ + res = builder.CreateCall(fn_crc, {current, next_ext}, "crc32_8"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32ch(i32 %cur, i32 %bits) */ +#define llvm_crc32_32_16(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32ch); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32ch function!\n"))); \ + } \ + llvm::Value* next_ext = builder.CreateZExt(next, int32Type); \ + res = builder.CreateCall(fn_crc, {current, next_ext}, "crc32_16"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32cw(i32 %cur, i32 %next) */ +#define llvm_crc32_32_32(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cw); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cw function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_32"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32cx(i32 %cur, i64 %next) */ +#define llvm_crc32_32_64(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cx); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cx function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_64"); \ + } while (0) + +#else /* on X86 platform */ + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.8(i32 %a, i8 %b) */ +#define llvm_crc32_32_8(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_8); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_8 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_8"); \ + } while (0) + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.16(i32 %a, i16 %b) */ +#define llvm_crc32_32_16(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_16); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_16 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_16"); \ + } while (0) + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.32(i32 %a, i32 %b) */ +#define llvm_crc32_32_32(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_32); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_32 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_32"); \ + } while (0) + +/* + * its function proto is: i64 @llvm.x86.sse42.crc32.64.64(i64 %a0, i64 %a1). + * x86_sse42_crc32_64_64 gets two 64bit inputs, and returns 64bits. + * So we have to convert its first input param and the result. + */ +#define llvm_crc32_32_64(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_64_64); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_64_64 function!\n"))); \ + } \ + llvm::Value* current_ext = builder.CreateZExt(current, int64Type); \ + res = builder.CreateCall(fn_crc, {current_ext, next}, "crc32_64"); \ + res = builder.CreateTrunc(res, int32Type); \ + } while (0) + +#endif /* end of definition of series of llvm::crc32 function */ + +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/timestampcodegen.h postgresql-hll-2.14/include/codegen/timestampcodegen.h --- postgresql-hll-2.14_old/include/codegen/timestampcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/timestampcodegen.h 2020-12-12 17:06:43.102346167 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * timestampcodegen.h + * Definitions of code generation for timestamp operation + * + * + * IDENTIFICATION + * src/include/codegen/timestampcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_TIMESTAMP_H +#define LLVM_TIMESTAMP_H +#include "codegen/gscodegen.h" + +namespace dorado { +llvm::Function* timestamp_eq_codegen(); +llvm::Function* timestamp_ne_codegen(); +llvm::Function* timestamp_lt_codegen(); +llvm::Function* timestamp_le_codegen(); +llvm::Function* timestamp_gt_codegen(); +llvm::Function* timestamp_ge_codegen(); +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/codegen/vecexprcodegen.h postgresql-hll-2.14/include/codegen/vecexprcodegen.h --- postgresql-hll-2.14_old/include/codegen/vecexprcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/vecexprcodegen.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,468 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexprcodegen.h + * Declarations of code generation for vecexpression funtions. + * + * For each expression, first decide if this expression can be LLVM optimized + * or not according to the detail information. The expression functions + * accomplished here have the same functionality as the ones defined in + * vecexpression.h, though more constraints are used. + * + * IDENTIFICATION + * src/include/codegen/vecexprcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECEXPRESSION_H +#define LLVM_VECEXPRESSION_H +#include "optimizer/clauses.h" +#include "nodes/execnodes.h" +#include "codegen/gscodegen.h" + +namespace dorado { +/* + * @Description : Arguments used for Vectorized Expression CodeGen Engine. + */ +typedef struct { + ExprState* exprstate; /* Expression information used to + generate IR function */ + PlanState* parent; /* The parent planstate information */ + GsCodeGen::LlvmBuilder* builder; /* LLVM builder in upper level */ + llvm::Value** llvm_args; /* LLVM parameters*/ +} ExprCodeGenArgs; + +/* + * @Description : Parameters needed to pass to the original c-function. + */ +typedef struct { + int nargs; /* number of args */ + llvm::Value** args; /* values of parameters with length nargs */ + llvm::Value** argnulls; /* flags of parameters with length nargs */ +} LLVMFuncCallInfo; + +typedef llvm::Value* (*VectorExprCodeGen)(ExprCodeGenArgs* args); + +/* + * LlvmExecQual class implements specific optimization by using LLVM. + */ +class VecExprCodeGen : public BaseObject { +public: + /* + * @Brief : Check whether state could be legal or not. + * @Description : Check is the current state->expr could be codegened + * or not. + * @in state : exprstate, the node to be checked. + * @return : return true is state could be codegened. + */ + static bool ExprJittable(ExprState* state); + + /* + * The following functions are codegen functions and their guardian function: + * Since each expression has its own restricts, we should consider them + * independently. For each expression, we have one guardian function and + * one codegen function. + */ + + /* + * @Brief : Check if the whole qual list can be codegened or not. + * @Description : Check if the qual list can be codegened or not. The qual + * list can be joinqual, hashjoin_clauses and so on. + * @in qual : the expr node list need to be checked. + * @return : return true if the whole qual can be codegened. + */ + static bool QualJittable(List* qual); + + /* + * @Brief : Code generation for ExecEvalQual. + * @Description : Since ExprState stored the plan-tree information, ExprContext + * stored the actual data information during execution. We need + * to separate these two parameters in 'InitNode' and 'ExecNode' + * status. So during expression processes, we should pass through + * 'Expr' as parameter in 'InitNode' and pass through 'econtext' + * as LLVM parameter in 'ExecNode'. + * @in qual : the expr node list need to be codegened. + * @in parent : the whole planstate of the expr node. + * @return : ScalarVector result of the qual list in LLVM assemble. + * @notes : firstly, econtext is passed when qual is needed; secondly, for + * each LLVM function in ExecVecQual, the interface is + * LLVM_Expr_Func(ExprCodeGenArgs); + */ + static llvm::Function* QualCodeGen(List* qual, PlanState* parent, bool isReset = true); + + /* + * @Description : Check if the scalararrayop expr can be codegened or not. + * @in state : ExprState of ScalarArrayOpExpr. + * @return : return true if scalararrayop expr can be codegened. + */ + static bool ScalarArrayJittable(ExprState* state); + + /* + * @Brief : Codegen for scalararrayop expression. + * @Description : Codegeneration of the ExecEvalVecScalarArrayOp: + * For integer/float/date/timestamp, we use switch + * structure in LLVM, for bpchar/varchar/text, we use + * codegen function. + * @in args : arguments of vector expr codegen engine. + * @return : return true when tuple satisfies the condition + * @Notes : Support ...in (...) and any(array[....]) only. + */ + static llvm::Value* ScalarArrayCodeGen(ExprCodeGenArgs* args); + + /* + * @Description : Check if the boolean test expr can be codegened or not. + * @in state : ExprState of BooleanTest Expr. + * @Output : return true if boolean test expr can be codegened. + */ + static bool BooleanTestJittable(ExprState* state); + + /* + * @Brief : Codegen for boolean test expression. + * @Description : Codegeneration of the ExecEvalBooleanTest. + * @in args : arguments of vector expr codegen engine. + * @return : return the result of Boolean Test Expr. + */ + static llvm::Value* BooleanTestCodeGen(ExprCodeGenArgs* args); + + /* + * @Description : Check if the null test expr can be codegened or not. + * + * @in state : NullTest ExprState. + * @return : return true if nulltest expr can be codegened. + */ + static bool NullTestJittable(ExprState* state); + + /* + * @Brief : Codegen for NullTest expression. + * @Description : Codegeneration of the ExecEvalNullTest: contains + * IS_NULL, IS_NOT_NULL. + * @in args : arguments of vector expr codegen engine. + * @return : return true only if argument is nulll, else return false. + */ + static llvm::Value* NullTestCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the oper func can be codegened or not. + * @Description : Check if the FuncExprState can be codegened or not : + * right now most of the oper expr can be codegened, but + * some of them still have some constraints. + * @in state : ExprState representation of FuncExprSate. + * @return : return true if the operation function can be codegened. + */ + static bool OpJittable(ExprState* state); + + /* + * @Brief : Check if the oper func with numeric data can be codegened in special path. + * @Description : Check if the Numeric OperExpr can be codegened in a special way: + * the data we considered here are all can be represented in BI64. + * @in state : ExprState representation of OperExprSate. + * @return : return true if the operation function can be codegened in fast path. + */ + static bool NumericOpFastJittable(ExprState* state); + + /* + * @Brief : Codegen for vecoper expression. + * @Description : Codegeneration of the ExecEvalVecOp: Right row + * we only support several cases with data type + * int/float/date/timestamp and text(eq,gt)/bpchar(eq) + * @in args : arguments of vector expr codegen engine. + * @return : return the result of oper expr in LLVM assemble. + * @Notes : Since we have not codegen ExecMakeVecFunctionResult + * as we do in vecexpression.cpp, only seveal cases + * are supported. + */ + static llvm::Value* OpCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for numeric type operation expression. + * @Description : Codegeneration for numeric operation expression: we make a special + * path for data that can be transformed to BI64. While for other cases, + * we use normal codegen path(NormalNumericOpCodeGen). + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in estate : opexprstate associated with current operation. + * @in funcoid : function oid of current numeric operation. + * @in larg : left argument passed to llvm. + * @in rarg : right argument passed to llvm. + */ + static llvm::Value* FastNumericOpCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, ExprState* estate, llvm::Value* larg, llvm::Value* rarg); + static llvm::Value* NormalNumericOpCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, Oid funcoid, llvm::Value* larg, llvm::Value* rarg); + + /* + * @Brief : Check if the FuncExpr can be codegened or not. + * @Description : Check if the FuncExprState can be codegened or not : + * right now most of the func expr can be codegened, but + * some of them still have some constraints. + * @in state : ExprState representation of FuncExprSate. + * @return : return true if the func can be codegen. + * @Notes : We only support C / UTF-8 encoding. + */ + static bool FuncJittable(ExprState* state); + + /* + * @Brief : Codegen for vecfunc expression. + * @Description : Codegeneration of the ExecEvalVecFunc: Only part of them + * have been codegened, the rest would be used by + * call original C-Function. + * @in args : arguments of vector expr codegen engine. + * @return : result of ExecEvalFunc in LLVM assemble. + * @Notes : We only support C / UTF-8 encoding. + */ + static llvm::Value* FuncCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if veccase expression can be codegened or not. + * @Description : Codegeneration of the ExecEvalVecCase: The logic here + * is the same as ExecEvalVecCase. Since operation is only + * partly supported, the exprs in case arg/when expr/default + * expr are the ones supported by OpCodeGen. + * @in state : context of CaseExprState + * @return : return true if veccase expr can be codegened. + */ + static bool CaseJittable(ExprState* state); + + /* + * @Brief : Codegen for veccase expression. + * @Description : Codegeneration of the ExecEvalVecCase: The logic here + * is the same as ExecEvalVecCase. Since operation is only + * partly supported, the exprs in case arg/when expr/default + * expr are the ones supported by OpCodeGen. + * @in args : arguments of vector expr codegen engine. + * @return : wclause->result or default->result in LLVM assemble. + */ + static llvm::Value* CaseCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if nullif expression can be codegened or not. + * @Description : Codegeneration of the ExecEvalVecNullif checking. + * @in state : ExprState + * @return : return true if nullif expr can be codegened. + */ + static bool NullIfJittable(ExprState* state); + + /* + * Brief : Codegen for nullif expression. + * Description : NullIfCodeGen is the codegeneration of the ExecEvalVecNullIf. + * Input : ExprCodeGenArgs + * Output : when expr1=expr2 return null, else return expr1. + * Notes : None. + */ + static llvm::Value* NullIfCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if and/or/not expr can be codegened or not. + * @Description : Check if the bool expr can be codegened or not. The + * expr type contatins and, or and not expr. While + * and/or expression and not expression should be + * considered independently. + * @in state : the context of bool expr state + * @return : return true the expr in state can be codegened. + */ + static bool BoolJittable(ExprState* state); + + /* + * @Brief : Codegen for vector and/or expression. + * @Description : Codegeneration of the ExecEvalProcessAndOrLogic: The + * logic here is the same as ExecEvalProcessAndOrLogic. + * BoolJittable would check and/or/not expression argument, + * but and/or expression and not expression would be + * considered independently. + * @in args : arguments of vector expr codegen engine. + * @return : the and/or expr's result in LLVM assemble. + */ + static llvm::Value* AndOrLogicCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for vector not expression. + * @Description : Codegeneration of the ExecEvalVecNot. + * @in args : arguments of vector expr codegen engine. + * @return : the not expr's result in LLVM assemble. + */ + static llvm::Value* NotCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if vecrelabel expr can be codegened or not. + * @Description : Check if the relabel expr in genericexprstate can be + * : codegened or not. Only support the case when arg + * : is a var or casetestexpr. + * @in state : context of relabel expr. + * @return : return true if relabel expr can be codegened. + */ + static bool RelabelJittable(ExprState* state); + + /* + * @Brief : Codegen for vecrelabel expression. + * @Description : Codegeneration of the ExecEvalVecRelabelType: + * Support the case when arg is a var or casetestexpr. + * @in args : arguments of vector expr codegen engine. + * @return : result of relabel expr in LLVM assemble + */ + static llvm::Value* RelabelCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the var expr can be codegened or not. + * @Description : Check if the Var in state can be codegened or not, + * : only need to consider the var type. + * @in state : context of Var Expr State + * @return : return true if const expr can be codegened. + */ + static bool VarJittable(ExprState* state); + + /* + * @Brief : Codegen for evalvar expr. + * @Description : Codegeneration of the ExecEvalVecVar : Get the + * values from econtext->vectorbatch with fixed + * column index and row index(loop_index). Also we + * should restore the null flag. + * @in args : arguments of vector expr codegen engine. + * @out isNull : null flag of batch->m_arr[varattno-1] + * @return : return true if const expr can be codegened. + */ + static llvm::Value* VarCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for vecconst expression. + * @Description : Check is const expr could be codegened or not. + * @in state : const expr state. + * @return : return true if const expr can be codegened. + */ + static bool ConstJittable(ExprState* state); + + /* + * @Brief : Codegen for vecconst expression. + * @Description : Codegeneration of the ExecEvalVecConst + * @in args : arguments of vector expr codegen engine. + * @return : the value in const expr. + */ + static llvm::Value* ConstCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the targetlist could be codegened or not. + * @Description : Check the jittable of the ExecVecTargetList, which + * : evaluates a targetlist with respect to the given + * : expression context in LLVM assemble. + * @in targetlist : the expr node list need to be checked. + * @return : return true if we were able to codegen the list. + */ + static bool TargetListJittable(List* targetlist); + + /* + * @Brief : Codegen for TargetList expression. + * @Description : Codegeneration of the ExecVecTargetList, which + * : evaluates a targetlist with respect to the given + * : expression context in LLVM assemble. + * @in targetlist : the expr node list need to be codegened. + * @in parent : PlanState of the whole targetlist. + * @return : LLVM function of targetlist expr. + */ + static llvm::Function* TargetListCodeGen(List* targetlist, PlanState* parent); + + /* + * @Description : CodeGen routine for Expression. + * @in args : arguments of vector expr codegen engine. + * @return : the result of current args->exprstate. + */ + static llvm::Value* CodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : CodeGen for general function call. + * @Description : For functions we do not codegened, invoke these + * function in LLVM assemble, and reduce the logical + * branches in dealing with arguments and return vals + * by using LLVM optimization. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcache : The function expr dealed with. + * @in isNull : used to record the null flag of the return value. + * @in lfcinfo : arguments about fcache. + * + */ + static llvm::Value* EvalFuncResultCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, FuncExprState* fcache, llvm::Value* isNull, LLVMFuncCallInfo* lfcinfo); + + /* + * @Brief : Make sure the ExtractFunc according the datum type. + * @Description : Wrap all the Extract Func in LLVM assemble, which could + * : easily deal with input argument according the different + * : datum type. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in argtyp : input argument datum type.type + * @in data : input data + * @return : the result after extraction. + */ + static llvm::Value* WrapChooExtFunCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, Oid argtyp, llvm::Value* argval); + static llvm::Value* WrapExtFixedTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtAddrTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtCStrTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtVarTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + + /* + * @Brief : Wrap Datum to Scalar Func according the datum type. + * @Description : Wrap all the Convert Func in LLVM assemble. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in val : input data argument. + * @in len : the argument data len with respect to datum type. + * @return : the result after conversation. + */ + static llvm::Value* WrapDFixLToScalCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* val, llvm::Value* len); + static llvm::Value* WrapDCStrToScalCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* val); + + /* + * @Description : Wrap the c-function : GetVectorBatch, which is used to + * get the vectorbatch during vectargetlist-codegeneration. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in econtext : exprcontext in LLVM assemble. + */ + static llvm::Value* WrapGetVectorBatchCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - FunctionCallInvoke, only consider strict + * : function, where we do not consider the flag of args. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcinfo : data with FunctionCallInfo type in LLVM assemble. + * @in arg : array of arguments, contain the arguments of fcinfo + * : and the flag of the result. + */ + static llvm::Value* WrapStrictOpFuncCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* fcinfo, llvm::Value* arg, llvm::Value* isNull); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - FunctionCallInvoke, only consider non-strict + * : function. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcinfo : data with FunctionCallInfo type in LLVM assemble. + * @in arg : array of arguments, contain the arguments of fcinfo + * : and the flag of the result. + * @in argnull : the flag of the input args. + * @in isNull : the flag of the result. + */ + static llvm::Value* WrapNonStrictOpFuncCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* fcinfo, + llvm::Value* arg, llvm::Value* argnull, llvm::Value* isNull); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - MemoryContextSwitchTo. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in context : MemoryContext that we want to access. + */ + static llvm::Value* MemCxtSwitToCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* context); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/vechashaggcodegen.h postgresql-hll-2.14/include/codegen/vechashaggcodegen.h --- postgresql-hll-2.14_old/include/codegen/vechashaggcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/vechashaggcodegen.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,230 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashaggcodegen.h + * Declarations of code generation for vechashagg funtions. + * + * For each vechashagg function, they have the same functionality as the ones + * defined in vechashagg.h. Code generation will not change the logical of the + * the whole function. + * + * IDENTIFICATION + * src/include/codegen/vechashaggcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECHASHAGG_H +#define LLVM_VECHASHAGG_H +#include "codegen/gscodegen.h" +#include "executor/nodeAgg.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +namespace dorado { +/* + * VecHashAggCodeGen class implements specific optimization by using LLVM + */ +class VecHashAggCodeGen : public BaseObject { +public: + /* + * @Brief : Calculate scale of expression. + * @Description : Give expression node, calculate the scale of current, + * this function only be used when we can use fast codegen. + * @in node : The expression that we need to evaluate scale. + * @return : return the scale of current node expr. + */ + static int GetAlignedScale(Expr* node); + + /* + * @Brief : Check the expressions we supported + * @Description : Since we only support simple expression in agg + * operator, we should restrict the ones we support. + * @in state : Input expression state node. + * @return : If the current node is allowed to do codegen or not. + */ + static bool AggRefJittable(ExprState* state); + + /* + * @Brief : Check if current expression can use special codegen path. + * @Description : For simple var expression and simple algorithm expression + * with numeric data type, if we could represent it by + * big integer, use fast path at the beginning. + * @in state : Input expression state node. + * @return : Return true if the expression can use fast codegen path. + */ + static bool AggRefFastJittable(ExprState* state); + + /* + * @Brief : Check the validation of VecAggState for agghashing. + * @Description : Check if the current agg node could be codegened + * or not. We only support sum and avg operation. The + * data type could only be int8 and numeric with + * precision less than or equal to 18. + * @in node : vecaggstate, the node to be checked. + * @return : Return true if current agg node could be codegened. + */ + static bool AgghashingJittable(VecAggState* node); + + /* + * @Brief : Main function process to build LLVM ir function used to generate + * : machine code. + * @Description : Build LLVM ir function with respect to special query according to + * : current agg state, including build function and agg function. + * @in node : vector aggregate state information. + */ + static void HashAggCodeGen(VecAggState* node); + + /* + * @Brief : Main function process to build LLVM IR function used to generate + * : machine code. + * @Description : Build LLVM ir function with respect to special query according to + * : current sonic agg state, including agg function. + * @in node : vector aggregate state information, special for sonic case. + */ + static void SonicHashAggCodeGen(VecAggState* node); + + /* + * @Brief : Code generation for Hashing process + * @Description : The whole HashAggRunner::BuildAggTbl functions + * can be divieded into three part. AgghashingCodeGen + * contains (a)computing hash value & compare hash value + * & match key and (b)allocate new hash cell. + * @in node : vecaggstate, the node to be codegened + * @return : The codegeneration of part of HashAggRunner::BuildAggTbl + * function. + */ + template + static llvm::Function* AgghashingCodeGenorSglTbl(VecAggState* node); + + /* + * @Description : Same as above function except the prefetching hashCell. + */ + template + static llvm::Function* AgghashingWithPrefetchCodeGenorSglTbl(VecAggState* node); + /* + * @Brief : Code generation for vechashtable::hashBatch function. + * @Description : Code generation for hashBatch function with the fixed + * row number 'idx'. The original function calculate the + * whole hash values of that batch with respect to the + * group by clauses. hashBatchCodeGen only calculate the + * hash value of one row. + * @in node : node which contains aggstate information. + * @in idx : the row number of the batch. + * @in rehash : check if we need to rehash the row. + * @return : LLVM function pointer. + * + */ + static llvm::Function* HashBatchCodeGen(VecAggState* node, int idx, bool rehash); + + /* + * @Brief : Code generation for match_key function with respect to + * one key. + * @Description : Code generation for match_key function with the fixed + * row number 'idx' and fixed key. We only consider the + * idx-th cell and the idx-th tuple in batch. + * @in node : Node which contains aggstate information. + * @in idx : The row number of the batch. + * @return : LLVM function pointer. + */ + static llvm::Function* MatchOneKeyCodeGen(VecAggState* node, int idx); + + /* + * @Brief : Check the validation of VecAggState for batch aggregation. + * @Description : Check if the current node can be codegened for aggregation + * or not. Since we only support sum and avg operation with + * data type int8 and numeric with allowed precision(<=18). + * @in node : vecaggstate, the node to be codegened + * @return : return true if current node is allowed to do codegen of + * batch aggregation. + */ + static bool BatchAggJittable(VecAggState* node, bool isSonic); + + /* + * @Brief : Code generation for BatchAggregation. + * @Description : Do codegen for function BaseAggRunner::BatchAggregation. + * The main process contains projection of expressions and + * aggregation of the agg operator. + * @in node : vecaggstate, the node to be codegened + * @in use_prefetch : Flag used to decide if we need to prefetch data. + * @return : LLVM function pointer that point to the codegeneration of + * BatchAggregation. + */ + static llvm::Function* BatchAggregationCodeGen(VecAggState* node, bool use_prefetch); + + /* + * @Brief : LLVM function used to evaluation numeric expression in + * fast path. + * @Description : Evaluate numeric expression in fast path if the mid-result + * can be represented in BI64 by avoiding make numeric + * result all the time. + * @in state : ExprState node + * @in builder : LLVM Builder associated with the current module. + * @in jitted_func : the current llvm function that we need to generate. + * @in bb_null : null basicblock used for deal with null value. + * @in bb_last : maks parent basic block dynamically to get value from + * last basicblock. + * @bb_outofbound : basicblock used to deal with the case where the result + * can not be represented in BI64. + * @econtext : ExprContext of the current operator. + * @argVector : the input scalevector. + * @phi_idx : the idxth row that we need to evaluation. + * @return : the result of this value if no outofbound or null is meet. + */ + static llvm::Value* EvalFastExprInBatchAgg(ExprState* state, GsCodeGen::LlvmBuilder builder, + llvm::Function* jitted_func, llvm::BasicBlock** bb_null, llvm::BasicBlock** bb_last, + llvm::BasicBlock** bb_outofbound, llvm::Value* econtext, llvm::Value* argVector, llvm::Value* phi_idx); + + /* + * @Brief : Code generation for expressions in agg function. + * @Description : Do codegen for ExecVecProject function in BatchAggregation. + * Since we only deal with simple expressions, we could list + * these simple cases one by one. + * @in node : ExprState node. + * @in builder : LLVM Builder associated with the current module. + * @in econtext : Expr Context with respect to current aggref Expr. + * @in phi_idx : the index of the current tuple. + * @in isNull : flag used to mask the return value is null or not. + * @return : return the result of this expression. + */ + static llvm::Value* EvalSimpleExprInBatchAgg(ExprState* node, GsCodeGen::LlvmBuilder builder, llvm::Value* econtext, + llvm::Value* phi_idx, llvm::Value* isNull); + + static llvm::Function* SonicBatchAggregationCodeGen(VecAggState* node, bool use_prefetch); + + /* + * @Brief : Code generation for allocating a new hash cell and initialization. + * @Description : Code generation for allocating hash cell and initilize the + * hash cell. It has the same functionality as the orginal one. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in hAggRunner : HashAggRunner information. + * @in batch : vectorbatch which needed to creat hash cell. + * @in idx : the index of the current tuple. + * @in keysimple : mark whether the key is simple or not. + */ + static void WarpAllocHashSlotCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* hAggRunner, + llvm::Value* batch, llvm::Value* idx, llvm::Value* keysimple); + static void WarpSglTblAllocHashSlotCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* hAggRunner, + llvm::Value* batch, llvm::Value* idx, llvm::Value* keysimple); + + /* + * @Brief : Reset current expr context. + * @Description : Codeg generation for reset expr context in LLVM assemble. + * @in econtext : Current expr context. + */ + static void WrapResetEContextCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext); +}; + +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/vechashjoincodegen.h postgresql-hll-2.14/include/codegen/vechashjoincodegen.h --- postgresql-hll-2.14_old/include/codegen/vechashjoincodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/vechashjoincodegen.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,172 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashjoincodegen.h + * Declarations of code generation for vechashjoin funtions. + * + * Since the most cpu intensive part of hashjoin function locates + * at build hash table part and join part, we mainly do codegeneration + * for buildHashTable, innerJoin and so on. + * + * IDENTIFICATION + * src/include/codegen/vechashjoincodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECHASHJOIN_H +#define LLVM_VECHASHJOIN_H +#include "codegen/gscodegen.h" +#include "codegen/vecexprcodegen.h" +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +namespace dorado { +/* + * VecHashJoinCodeGen class implements specific optimization by using LLVM + */ +class VecHashJoinCodeGen : public BaseObject { +public: + /* + * @Brief : Check if the hash key is simple var or not. + * @Description : Since we only support simple hash condition now, + * the hash key expr should be simple var. If this + * var is marked as not_null, we could use fast + * key match path. + * @in node : VecHashJoinState, the node to be checked. + * @in estate : The expr of hashkey. + * @in is_simple_var : Flag used to mark if hash cond expr is simple var + * or not. + * @in enable_fast_keymatch : Flag used to mark fast codegen path. + * @return : Return simple var expression. + */ + static Var* GetSimpHashCondExpr( + VecHashJoinState* node, ExprState* estate, bool* is_simple_var, int* enable_fast_keyMatch); + + /* + * @Brief : Check the validation of VecHashJoinState. + * @Description : Check if the current hash join node could be codegened + * or not. We only support hash inner join. The + * data type of hash keys could only be int4, int8 or bpchar. + * @in node : VecHashJoinState, the node to be checked. + * @return : Return true if current hash join node could be codegened. + * set VecHashJoinState->enable_fast_keyMatch = 2 if + * (1) all hash keys are NOT NULL columns from base tables + * (2) all hash key data types are int4 or int8 + * else set VecHashJoinState->enable_fast_keyMatch = 1 if + * (1) there is only one hash clause + * else set VecHashJoinState->enable_fast_keyMatch = 0 + */ + static bool JittableHashJoin(VecHashJoinState* node); + + /* @Brief : Check if we can do codegen on buildHashTable and probeHashTable + * @Description : We separate this check from the JittableHashJoin for + * innerJoinT/matchKey since the build/probe function can + * be used for all joins (inner, semi, anti, ...). + * @in : VecHashJoinState, the node to be checked. + * @return : true if we can do codegen on buildHashTable/probeHashTable + * (1) No any complicate hash clauses + * (2) only support hash keys with int4,int8,bpchar type. + */ + static bool JittableHashJoin_buildandprobe(VecHashJoinState* node); + + /* + * @Brief : Check if we can do codegen on bloom filter function. + * @Description : During initialization, we initilized the runtime bloomfilter. + * If the var type is int2, int4 or int8, we chould use + * codegen optimization for bloom filter function. + * @in : VecHashJoinState, the node to be checked. + * @return : return true if we can do codegen on addLong and includeLong + * function in bloom filter. + */ + static bool JittableHashJoin_bloomfilter(VecHashJoinState* node); + + /* + * @Brief : Code generation for hash join + * @Description : Codegen for the hot path in innerJoinT + * match_key, buildHashTable, probeHashTable + * @in node : VecHashJoinState, the node to be codegened + * @return : true if innerJoinT is generated; otherwise, false. + */ + static void HashJoinCodeGen(VecHashJoinState* node); + static llvm::Function* HashJoinCodeGen_normal(VecHashJoinState* node); + + /* + * @Description : Generate more efficient code with less memory access + * and less branches. + * @in node : Hash join state node. + * @return : LLVM function about specialized hash inner join. + * @Note : The condition is one hash clause, hash keys are NOT NULL, + * and hash keys are integer type. + */ + static llvm::Function* HashJoinCodeGen_fastpath(VecHashJoinState* node); + + /* + * @Brief : Code generation for keyMatch function in hash join + * @Description : Codegen for the whole function keyMatch for hash join + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of keyMatch for hash join + */ + static llvm::Function* KeyMatchCodeGen(VecHashJoinState* node, Var* variable); + + /* + * @Brief : Code generation for buildHashTable function in hash join + * @Description : The hash function (hashint4 + hash_uint32) is replaced by + * CRC32 hardware instruction. Need to make sure the + * probeHashTable use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of buildHashTable for hash join + */ + static llvm::Function* HashJoinCodeGen_buildHashTable(VecHashJoinState* node); + + /* + * @Description : Similiar as above function except NeedCopy is true. + * @Note : NeedCopy is true when we have partition table. + */ + static llvm::Function* HashJoinCodeGen_buildHashTable_NeedCopy(VecHashJoinState* node); + + /* + * @Brief : Code generation for probeHashTable function in hash join + * @Description : The hash function (hashint4 + hash_uint32) is replaced by + * CRC32 hardware instruction. Need to make sure the + * buildHashTable use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of probeHashTable for hash join + */ + static llvm::Function* HashJoinCodeGen_probeHashTable(VecHashJoinState* node); + + /* + * @Brief : Code generation for addLongInternal in bloom filter + * @Description : We use CRC32 hash function to replace the original Thomas + * Wang's hash function. When addLongInternal function is + * codegened, includeLong must use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of addLongInternal for hash bloom filter. + */ + static llvm::Function* HashJoinCodeGen_bf_addLong(VecHashJoinState* node); + + /* + * @Brief : Code generation for includeLong in bloom filter + * @Description : We use CRC32 hash function to replace the original Thomas + * Wang's hash function. When includeLong function is + * codegened, addLong must use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of includeLong for hash bloom filter. + */ + static llvm::Function* HashJoinCodeGen_bf_includeLong(VecHashJoinState* node); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/codegen/vecsortcodegen.h postgresql-hll-2.14/include/codegen/vecsortcodegen.h --- postgresql-hll-2.14_old/include/codegen/vecsortcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/codegen/vecsortcodegen.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,155 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsortcodegen.h + * Declarations of code generation for vecsort funtions. + * + * Since the most cpu intensive part of sort function locates + * at CompareMultiColumn, we mainly do code generation for CompareMultiColumn + * and the functions it calls. + * + * + * IDENTIFICATION + * src/include/codegen/vecsortcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECSORT_H +#define LLVM_VECSORT_H +#include "codegen/gscodegen.h" +#include "vecexecutor/vecnodesort.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "utils/batchsort.h" +#include "access/tuptoaster.h" + +namespace dorado { +/* + * VecSortCodeGen class implements specific optimization by using LLVM + */ +class VecSortCodeGen : public BaseObject { +public: + /* + * @Brief : Check the validation of VecSortState. + * @Description : Check if the current sort node could be codegened + * or not. We only support the codegen on CompareMultiColumn + * and functions it calls. The data type of sort keys + * could only be int4, int8, char, text, varchar or numeric. + * @in node : VecSortState, the node to be checked. + * @return : return true if current sort node could be codegened. + */ + static bool JittableCompareMultiColumn(VecSortState* node); + + /* + * @Brief : Code generation for CompareMultiColumn + * @Description : Codegen for the hot path in sort + * @in node : VecSortState, the node to be codegened + * @return : The codegeneration of part of CompareMultiColumn + * function. + */ + static llvm::Function* CompareMultiColumnCodeGen(VecSortState* node, bool use_prefetch); + + /* + * @Brief : Code generation for CompareMultiColumn under Top N sort + * @Description : Codegen for the hot path in sort for Top N + * @in node : VecSortState, the node to be codegened + * @return : The codegeneration of part of CompareMultiColumn + * function. + */ + static llvm::Function* CompareMultiColumnCodeGen_TOPN(VecSortState* node, bool use_prefetch); + + /* + * @Brief : Code generation for bpcharcmp function + * @Description : Codegen for bpcharcmp and all functions it calls. + * If bpchar length is greater than 16 bytes, use bpcharcmpCodeGen_long() + * Otherwise, use bpcharcmpCodeGen_short() + * the generated function will be called by CompareMultiColumn + * @return : The codegeneration of bpcharcmp + * function. + */ + static llvm::Function* bpcharcmpCodeGen_long(); + static llvm::Function* bpcharcmpCodeGen_short(); + + /* + * @Brief : Code generation for memcmp function. + * @Description : Codegen for memcmp and all functions it calls. In sort + * node this function is called by varstr_cmp inlined + * into bpcharcmp function. + * @return : The LLVM IR function generated for memcmp function + * called by varstr_cmp inlined into bpcharcmp. + */ + static llvm::Function* LLVMIRmemcmp_CMC_CodeGen(); + + /* + * @Brief : Code generation for text_cmp function + * @return : The LLVM IR function generated for text_cmp function + */ + static llvm::Function* textcmpCodeGen(); + + /* + * @Brief : Code generation for numeric_cmp function + * @return : The LLVM IR function generated for numeric compare. + */ + static llvm::Function* numericcmpCodeGen(); + static llvm::Function* numericcmpCodeGen_fastpath(); + + /* + * @Brief : Check the validation of VecAggState. + * @Description : Check if the match_key function in sort aggregation + * could be codegened or not. + * @in node : VecAggState, the node to be checked. + * @return : true if it's jittable, otherwise, false. + */ + static bool JittableSortAggMatchKey(VecAggState* node); + + /* + * @Brief : Codegeneration for match_key function in Sort Aggregation. + * @Description : Codegeneration for match_key function in sort aggregation, + * The data type of sort keys could only be int4, int8, + * char, text, varchar or numeric, and we only support the + * group by rollup case without considering multiple phases. + * @in node : VecAggState, the node to be codegened. + * @return : The LLVM IR function generated for match_key function. + */ + static llvm::Function* SortAggMatchKeyCodeGen(VecAggState* node); + + /* + * @Description : Code generation for bpchareq function called by + * match_key function in Sort Aggregation. + * @in length : The length of the bpchar definition. + * @return : The LLVM IR function generated for bpchareq function + * in match_key of sortagg. + */ + static llvm::Function* SortAggBpchareqCodeGen(int length); + + /* + * @Description : Code generation for memcmp function called by bpchareq + * in match_key function of Sort Aggregation. If the bpchar + * length is >= 16, call SortAggMemcmpCodeGen_long(), + * otherwise, call SortAggMemcmpCodeGen_short(). + * @return : The LLVM IR function generated for memcmp function + * called by bpchareq in match_key of sortagg. + */ + static llvm::Function* SortAggMemcmpCodeGen_long(); + static llvm::Function* SortAggMemcmpCodeGen_short(); + + /* + * @Description : Code generation for texteq function in match_key of sortagg. + * @return : The LLVM IR function generated for texteq function. + */ + static llvm::Function* SortAggTexteqCodeGen(); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/commands/alter.h postgresql-hll-2.14/include/commands/alter.h --- postgresql-hll-2.14_old/include/commands/alter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/alter.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * alter.h + * prototypes for commands/alter.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/alter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ALTER_H +#define ALTER_H + +#include "catalog/dependency.h" +#include "utils/acl.h" +#include "utils/relcache.h" + +extern void ExecRenameStmt(RenameStmt* stmt); +extern void ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt* stmt); +extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses* objsMoved); +extern Oid AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId, Oid objid, Oid nspOid, int Anum_name, + int Anum_namespace, int Anum_owner, AclObjectKind acl_kind); +extern void ExecAlterOwnerStmt(AlterOwnerStmt* stmt); + +#endif /* ALTER_H */ diff -uprN postgresql-hll-2.14_old/include/commands/async.h postgresql-hll-2.14/include/commands/async.h --- postgresql-hll-2.14_old/include/commands/async.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/async.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * async.h + * Asynchronous notification: NOTIFY, LISTEN, UNLISTEN + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/async.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ASYNC_H +#define ASYNC_H + +#include +#include "fmgr.h" + +/* + * The number of SLRU page buffers we use for the notification queue. + */ +#define NUM_ASYNC_BUFFERS 8 + +extern THR_LOCAL volatile sig_atomic_t notifyInterruptPending; + +extern Size AsyncShmemSize(void); +extern void AsyncShmemInit(void); + +/* notify-related SQL statements */ +extern void Async_Notify(const char* channel, const char* payload); +extern void Async_Listen(const char* channel); +extern void Async_Unlisten(const char* channel); +extern void Async_UnlistenAll(void); + +/* notify-related SQL functions */ +extern Datum pg_listening_channels(PG_FUNCTION_ARGS); +extern Datum pg_notify(PG_FUNCTION_ARGS); + +/* perform (or cancel) outbound notify processing at transaction commit */ +extern void PreCommit_Notify(void); +extern void AtCommit_Notify(void); +extern void AtAbort_Notify(void); +extern void AtSubStart_Notify(void); +extern void AtSubCommit_Notify(void); +extern void AtSubAbort_Notify(void); +extern void AtPrepare_Notify(void); +extern void ProcessCompletedNotifies(void); + +/* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ +extern void HandleNotifyInterrupt(void); + +/* process interrupts */ +extern void ProcessNotifyInterrupt(void); + +#endif /* ASYNC_H */ diff -uprN postgresql-hll-2.14_old/include/commands/cluster.h postgresql-hll-2.14/include/commands/cluster.h --- postgresql-hll-2.14_old/include/commands/cluster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/cluster.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * cluster.h + * header file for postgres cluster command stuff + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/cluster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CLUSTER_H +#define CLUSTER_H + +#include "nodes/parsenodes.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +extern void cluster(ClusterStmt* stmt, bool isTopLevel); +extern void cluster_rel(Oid tableOid, Oid partitionOid, Oid indexOid, bool recheck, bool verbose, int freeze_min_age, + int freeze_table_age, void* mem_info, bool onerel); +extern void check_index_is_clusterable( + Relation OldHeap, Oid indexOid, bool recheck, LOCKMODE lockmode, Oid* amid = NULL); +extern void mark_index_clustered(Relation rel, Oid indexOid); + +extern Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, int lockMode = AccessExclusiveLock); + +extern Oid makePartitionNewHeap(Relation partitionedTableRel, TupleDesc partTabHeapDesc, Datum partTabRelOptions, + Oid oldPartOid, Oid partToastOid, Oid NewTableSpace, bool isCStore = false); +extern double copy_heap_data_internal(Relation OldHeap, Relation OldIndex, Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, bool use_sort, AdaptMem* memUsage); +extern TransactionId getPartitionRelfrozenxid(Relation ordTableRel); +extern TransactionId getRelationRelfrozenxid(Relation ordTableRel); +extern void setRelationRelfrozenxid(Oid relid, TransactionId frozenXid); +extern void setPartitionRelfrozenxid(Oid partid, TransactionId frozenXid); +extern void finishPartitionHeapSwap(Oid partitionOid, Oid tempTableOid, bool swapToastByContent, + TransactionId frozenXid, bool tempTableIsPartition = false); + +extern void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, + bool check_constraints, TransactionId frozenXid, AdaptMem* memInfo = NULL); + +extern void vacuumFullPart(Oid partOid, VacuumStmt* vacstmt, int freeze_min_age, int freeze_table_age); +extern void GpiVacuumFullMainPartiton(Oid parentOid); +extern void updateRelationName(Oid relOid, bool isPartition, const char* relNewName); + +#endif /* CLUSTER_H */ diff -uprN postgresql-hll-2.14_old/include/commands/collationcmds.h postgresql-hll-2.14/include/commands/collationcmds.h --- postgresql-hll-2.14_old/include/commands/collationcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/collationcmds.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * collationcmds.h + * prototypes for collationcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/collationcmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef COLLATIONCMDS_H +#define COLLATIONCMDS_H + +#include "nodes/parsenodes.h" + +extern void DefineCollation(List* names, List* parameters); +extern void RenameCollation(List* name, const char* newname); +extern void AlterCollationOwner(List* name, Oid newOwnerId); +extern void AlterCollationOwner_oid(Oid collationOid, Oid newOwnerId); +extern void AlterCollationNamespace(List* name, const char* newschema); +extern Oid AlterCollationNamespace_oid(Oid collOid, Oid newNspOid); + +#endif /* COLLATIONCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/comment.h postgresql-hll-2.14/include/commands/comment.h --- postgresql-hll-2.14_old/include/commands/comment.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/comment.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,44 @@ +/* + * src/include/commands/comment.h + * + * ------------------------------------------------------------------------- + * + * comment.h + * + * Prototypes for functions in commands/comment.c + * + * Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * ------------------------------------------------------------------------- + */ + +#ifndef COMMENT_H +#define COMMENT_H + +#include "nodes/parsenodes.h" + +/* ------------------------------------------------------------------ + * Function Prototypes -- + * + * The following prototypes define the public functions of the comment + * related routines. CommentObject() implements the SQL "COMMENT ON" + * command. DeleteComments() deletes all comments for an object. + * CreateComments creates (or deletes, if comment is NULL) a comment + * for a specific key. There are versions of these two methods for + * both normal and shared objects. + * ------------------------------------------------------------------ + */ + +extern void CommentObject(CommentStmt* stmt); + +extern void DeleteComments(Oid oid, Oid classoid, int32 subid); + +extern void CreateComments(Oid oid, Oid classoid, int32 subid, const char* comment); + +extern void DeleteSharedComments(Oid oid, Oid classoid); + +extern void CreateSharedComments(Oid oid, Oid classoid, const char* comment); + +extern char* GetComment(Oid oid, Oid classoid, int32 subid); + +#endif /* COMMENT_H */ diff -uprN postgresql-hll-2.14_old/include/commands/conversioncmds.h postgresql-hll-2.14/include/commands/conversioncmds.h --- postgresql-hll-2.14_old/include/commands/conversioncmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/conversioncmds.h 2020-12-12 17:06:43.103346180 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * conversioncmds.h + * prototypes for conversioncmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/conversioncmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CONVERSIONCMDS_H +#define CONVERSIONCMDS_H + +#include "nodes/parsenodes.h" + +extern void CreateConversionCommand(CreateConversionStmt* parsetree); +extern void RenameConversion(List* name, const char* newname); +extern void AlterConversionOwner(List* name, Oid newOwnerId); +extern void AlterConversionOwner_oid(Oid conversionOid, Oid newOwnerId); +extern void AlterConversionNamespace(List* name, const char* newschema); +extern Oid AlterConversionNamespace_oid(Oid convOid, Oid newNspOid); + +#endif /* CONVERSIONCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/copy.h postgresql-hll-2.14/include/commands/copy.h --- postgresql-hll-2.14_old/include/commands/copy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/copy.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,383 @@ +/* ------------------------------------------------------------------------- + * + * copy.h + * Definitions for using the POSTGRES copy command. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/copy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COPY_H +#define COPY_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "executor/execdesc.h" +#include "commands/gds_stream.h" +#include "bulkload/utils.h" + +#ifdef PGXC +#include "pgxc/pgxc.h" +#include "pgxc/execRemote.h" +#include "pgxc/locator.h" +#include "pgxc/remotecopy.h" +#include "nodes/nodes.h" +#include "pgxc/poolmgr.h" +#include "catalog/pgxc_node.h" +#include "access/obs/obs_am.h" +#endif + +struct Formatter; + +/* CopyStateData is private in commands/copy.c */ +struct CopyStateData; +typedef struct CopyStateData* CopyState; + +/* + * Represents the different source/dest cases we need to worry about at + * the bottom level + */ +typedef enum CopyDest { + COPY_FILE, /* to/from file */ + COPY_OLD_FE, /* to/from frontend (2.0 protocol) */ + COPY_NEW_FE /* to/from frontend (3.0 protocol) */ +#ifdef PGXC + , + COPY_BUFFER /* Do not send, just prepare */ +#endif + , + COPY_GDS, + COPY_FILE_SEGMENT, + COPY_ROACH, + COPY_OBS +} CopyDest; + +/* + * Represents the end-of-line terminator type of the input + */ +typedef enum EolType { EOL_UNKNOWN, EOL_NL, EOL_CR, EOL_CRNL, EOL_UD } EolType; + +typedef enum { MODE_INVALID, MODE_NORMAL, MODE_SHARED, MODE_PRIVATE } ImportMode; + +typedef struct BulkLoadFunc { + void (*initBulkLoad)(CopyState cstate, const char* filename, List* totalTask); + void (*endBulkLoad)(CopyState cstate); +} BulkLoadFunc; + +typedef int (*CopyGetDataFunc)(CopyState cstate, void* databuf, int minread, int maxread); +typedef bool (*CopyReadlineFunc)(CopyState cstate); +typedef void (*CopyWriteLineFunc)(CopyState cstate); +typedef bool (*GetNextCopyFunc)(CopyState cstate); +typedef int (*CopyReadAttrsFunc)(CopyState cstate); + +/* + * This struct is used to record original illegal chars error info; + * For non-char type field illegal_chars_fault_torlerance doesn't work, + * so still report illegal chars error. + */ +typedef struct IllegalCharErrInfo { + int err_offset; /* original error offset in each bulkload date line */ + int err_field_no; /* original error corresponding to the number of field */ + int err_code; /* original error code */ + char* err_info; /* original error info */ + + int src_encoding; + int dest_encoding; +} IllegalCharErrInfo; + +/* StringInfo pointer */ +struct stringinfo_pointer { + char* data; /* data buffer */ + int len; /* data length */ + int cursor; /* cursor to scan data buffer */ + + inline void reset(void) + { + data = NULL; + len = 0; + cursor = 0; + } + + void set(char* strinfo, int strinfo_len) + { + data = strinfo; + len = strinfo_len; + cursor = 0; + } +}; + +typedef stringinfo_pointer* stringinfo_ptr; + +/* custom format about date/time/timestamp/small datetime. */ +struct user_time_format { + /* text about date/time/timestamp/small datetime. */ + char* str; + + /* + * FormatNode info about date/time/timestamp/small datetime. + * because FormatNode is defined in CPP file, so use void* type here. + */ + void* fmt; +}; + +/* OBS Manipulation functions */ +extern void initOBSModeState(CopyState cstate, const char* filename, List* totalTask); +extern void endOBSModeBulkLoad(CopyState cstate); +extern bool CopyGetNextLineFromOBS(CopyState cstate); +extern bool getNextOBS(CopyState cstate); + +/* + * This struct contains all the state variables used throughout a COPY + * operation. For simplicity, we use the same struct for all variants of COPY, + * even though some fields are used in only some cases. + * + * Multi-byte encodings: all supported client-side encodings encode multi-byte + * characters by having the first byte's high bit set. Subsequent bytes of the + * character can have the high bit not set. When scanning data in such an + * encoding to look for a match to a single-byte (ie ASCII) character, we must + * use the full pg_encoding_mblen() machinery to skip over multibyte + * characters, else we might find a false match to a trailing byte. In + * supported server encodings, there is no possibility of a false match, and + * it's faster to make useless comparisons to trailing bytes than it is to + * invoke pg_encoding_mblen() to skip over them. encoding_embeds_ascii is TRUE + * when we have to do it the hard way. + */ +typedef struct CopyStateData { + /* low-level state data */ + CopyDest copy_dest; /* type of copy source/destination */ + bool is_from; /* Is this a Copy From or Copy To? */ + FILE* copy_file; /* used if copy_dest == COPY_FILE */ + StringInfo fe_msgbuf; /* used for all dests during COPY TO, only for + * dest == COPY_NEW_FE in COPY FROM */ + bool fe_eof; /* true if detected end of copy data */ + EolType eol_type; /* EOL type of input */ + int file_encoding; /* file or remote side's character encoding */ + bool need_transcoding; /* file encoding diff from server? */ + bool encoding_embeds_ascii; /* ASCII can be non-first byte? */ + + /* parameters from the COPY command */ + Relation rel; /* relation to copy to or from */ + Relation curPartionRel; /* current partion to copy to*/ + QueryDesc* queryDesc; /* executable query to copy from */ + List* attnumlist; /* integer list of attnums to copy */ + char* filename; /* filename, or NULL for STDIN/STDOUT */ + char* null_print; /* NULL marker string (server encoding!) */ + char* delim; /* column delimiter (must be no more than 10 bytes) */ + int null_print_len; /* length of same */ + int delim_len; + char* null_print_client; /* same converted to file encoding */ + char* quote; /* CSV quote char (must be 1 byte) */ + char* escape; /* CSV escape char (must be 1 byte) */ + char* eol; /* user defined EOL string */ + List* force_quote; /* list of column names */ + bool* force_quote_flags; /* per-column CSV FQ flags */ + List* force_notnull; /* list of column names */ + bool* force_notnull_flags; /* per-column CSV FNN flags */ + user_time_format date_format; /* user-defined date format */ + user_time_format time_format; /* user-defined time format */ + user_time_format timestamp_format; /* user-defined timestamp format */ + user_time_format smalldatetime_format; /* user-defined smalldatetime format */ + /* the flag used to control whether illegal characters can be fault-tolerant or not */ + bool compatible_illegal_chars; + bool oids; /* include OIDs? */ + bool freeze; + bool header_line; /* CSV header line? */ + bool force_quote_all; /* FORCE QUOTE *? */ + bool without_escaping; + + /* these are just for error messages, see CopyFromErrorCallback */ + const char* cur_relname; /* table name for error messages */ + uint32 cur_lineno; /* line number for error messages */ + const char* cur_attname; /* current att for error messages */ + const char* cur_attval; /* current att value for error messages */ + + /* + * Working state for COPY TO/FROM + */ + MemoryContext copycontext; /* per-copy execution context */ + + /* + * Working state for COPY TO + */ + FmgrInfo* out_functions; /* lookup info for output functions */ + MemoryContext rowcontext; /* per-row evaluation context */ + + /* + * Working state for COPY FROM + */ + AttrNumber num_defaults; + bool file_has_oids; + FmgrInfo oid_in_function; + Oid oid_typioparam; + FmgrInfo* in_functions; /* array of input functions for each attrs */ + Oid* typioparams; /* array of element types for in_functions */ + bool* accept_empty_str; /* is type of each column can accept empty string? */ + int* defmap; /* array of default att numbers */ + ExprState** defexprs; /* array of default att expressions */ + bool volatile_defexprs; /* is any of defexprs volatile? */ + List* range_table; + Datum copy_beginTime; /* log the query start time*/ + bool log_errors; /* mark where we tolerate data exceptions and log them into copy_error_log */ + int reject_limit; /* number of data exceptions we allow per Copy (on coordinator) */ + bool logErrorsData; /* mark where we tolerate data exceptions and log them into copy_error_log and make sure + Whether to fill the rowrecord field of the copy_error_log*/ + Relation err_table; /* opened copy_error_log table */ + CopyErrorLogger* logger; /* logger used for copy from error logging*/ + FmgrInfo* err_out_functions; /* lookup info for output functions of copy_error_log*/ + + /* + * These variables are used to reduce overhead in textual COPY FROM. + * + * attribute_buf holds the separated, de-escaped text for each field of + * the current line. The CopyReadAttributes functions return arrays of + * pointers into this buffer. We avoid palloc/pfree overhead by re-using + * the buffer on each cycle. + */ + StringInfoData attribute_buf; + + /* field raw data pointers found by COPY FROM */ + + int max_fields; + char** raw_fields; + + /* + * Similarly, line_buf holds the whole input line being processed. The + * input cycle is first to read the whole line into line_buf, convert it + * to server encoding there, and then extract the individual attribute + * fields into attribute_buf. line_buf is preserved unmodified so that we + * can display it in error messages if appropriate. + */ + StringInfoData line_buf; + bool line_buf_converted; /* converted to server encoding? */ + + /* + * Finally, raw_buf holds raw data read from the data source (file or + * client connection). CopyReadLine parses this data sufficiently to + * locate line boundaries, then transfers the data to line_buf and + * converts it. Note: we guarantee that there is a \0 at + * raw_buf[raw_buf_len]. + */ +#define RAW_BUF_SIZE 65536 /* we palloc RAW_BUF_SIZE+1 bytes */ + char* raw_buf; + int raw_buf_index; /* next byte to process */ + int raw_buf_len; /* total # of bytes stored */ + + PageCompress* pcState; + +#ifdef PGXC + /* Remote COPY state data */ + RemoteCopyData* remoteCopyState; +#endif + bool fill_missing_fields; + bool ignore_extra_data; /* ignore overflowing fields */ + + Formatter* formatter; + FileFormat fileformat; + char* headerFilename; /* User define header filename */ + char* out_filename_prefix; + char* out_fix_alignment; + StringInfo headerString; + + /* For bulkload*/ + BulkLoadStream* io_stream; + List* file_list; + ListCell* file_index; + ImportMode mode; + List* taskList; + ListCell* curTaskPtr; + long curReadOffset; + BulkLoadFunc bulkLoadFunc; + CopyGetDataFunc copyGetDataFunc; + CopyReadlineFunc readlineFunc; + CopyReadAttrsFunc readAttrsFunc; + GetNextCopyFunc getNextCopyFunc; + stringinfo_pointer inBuffer; + + uint32 distSessionKey; + List* illegal_chars_error; /* used to record every illegal_chars_error for each imported data line. */ + + bool isExceptionShutdown; /* To differentiate normal end of a bulkload task or a task abort because of exceptions*/ + + // For export + // + uint64 distCopyToTotalSize; + CopyWriteLineFunc writelineFunc; + bool remoteExport; + StringInfo outBuffer; + + // For Roach + void* roach_context; + Node* roach_routine; + + // For OBS parallel import/export + ObsCopyOptions obs_copy_options; + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; +} CopyStateData; + +#define IS_CSV(cstate) ((cstate)->fileformat == FORMAT_CSV) +#define IS_BINARY(cstate) ((cstate)->fileformat == FORMAT_BINARY) +#define IS_FIXED(cstate) ((cstate)->fileformat == FORMAT_FIXED) +#define IS_TEXT(cstate) ((cstate)->fileformat == FORMAT_TEXT) +#define IS_REMOTEWRITE(cstate) ((cstate)->fileformat == FORMAT_WRITABLE) + +extern uint64 DoCopy(CopyStmt* stmt, const char* queryString); + +extern void ProcessCopyOptions(CopyState cstate, bool is_from, List* options); +extern bool IsTypeAcceptEmptyStr(Oid typeOid); +extern CopyState BeginCopyFrom(Relation rel, const char* filename, List* attnamelist, List* options, void* mem_info); +extern void EndCopyFrom(CopyState cstate); +extern bool NextCopyFrom(CopyState cstate, ExprContext* econtext, Datum* values, bool* nulls, Oid* tupleOid); +extern bool NextCopyFromRawFields(CopyState cstate, char*** fields, int* nfields); +extern void CopyFromErrorCallback(void* arg); +extern void BulkloadErrorCallback(void* arg); + +extern DestReceiver* CreateCopyDestReceiver(void); + +extern CopyState begin_dist_copy_from( + Relation rel, const char* filename, List* attnamelist, List* options, List* totalTask); + +extern void end_dist_copy(CopyState cstate); + +extern List* DeserializeLocations(const char* location); + +extern bool is_valid_location(const char* location); + +extern bool is_local_location(const char* location); + +extern bool is_roach_location(const char* location); + +extern void getPathAndPattern(char* url, char** path, char** pattern); + +extern char* scan_dir(DIR* dir, const char* dirpath, const char* pattern, long* filesize); + +extern CopyState beginExport( + Relation rel, const char* filename, List* options, bool isRemote, uint32 sessionKey, List* tasklist); +extern void execExport(CopyState cpstate, TupleTableSlot* slot); +extern void endExport(CopyState cstate); + +extern uint64 exportGetTotalSize(CopyState cstate); +extern void exportResetTotalSize(CopyState cstate); +extern void exportAllocNewFile(CopyState cstate, const char* newfile); +extern void exportFlushOutBuffer(CopyState cstate); + +extern void ProcessFileHeader(CopyState cstate); + +extern List* addNullTask(List* taskList); +extern void CopySendString(CopyState cstate, const char* str); +extern void CopySendChar(CopyState cstate, char c); + +extern void cstate_fields_buffer_init(CopyState cstate); +extern bool IsCharType(Oid attr_type); +extern int GetDecimalFromHex(char hex); +extern char* limit_printout_length(const char* str); + +extern char* TrimStr(const char* str); + +#endif /* COPY_H */ diff -uprN postgresql-hll-2.14_old/include/commands/copypartition.h postgresql-hll-2.14/include/commands/copypartition.h --- postgresql-hll-2.14_old/include/commands/copypartition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/copypartition.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,206 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * copypartition.h + * + * + * + * IDENTIFICATION + * src/include/commands/copypartition.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COPYPARTITION_H +#define COPYPARTITION_H + +#define MAX_BUFFERED_TUPLES 20000 +#define MAX_TUPLES_SIZE (1024 * 1024) + +#define MIN_MEMCXT_NUM (16) +#define MAX_MEMCXT_NUM (1024) +#define PART_NUM_PER_MEMCXT (4) +#define LMT_SIZE_PER_PART (BLCKSZ * 4) +#define MAX_SIZE_PER_MEMCXT (LMT_SIZE_PER_PART * PART_NUM_PER_MEMCXT) +#define MAX_HASH_ENTRY_NUM (PART_NUM_PER_MEMCXT * MAX_MEMCXT_NUM) +#define DEF_BUFFERED_TUPLES (128) + +struct CopyFromMemCxtData; +typedef struct CopyFromMemCxtData* CopyFromMemCxt; +typedef struct CopyFromManagerData* CopyFromManager; +typedef struct CopyFromBulkData* CopyFromBulk; + +typedef struct CopyFromMemCxtData { + /* used for tuples' memory in the partition chunk */ + MemoryContext memCxtCandidate; + uint32 memCxtSize; + + /* members for bulk chunk */ + int16 nextBulk; /* nextBulk < PART_NUM_PER_MEMCXT, otherwise this chunk is full */ + int16 id; + CopyFromBulk chunk[PART_NUM_PER_MEMCXT]; +} CopyFromMemCxtData; + +typedef struct CopyFromBulkKey +{ + /* the hash key */ + Oid partOid; + int4 bucketId; +} CopyFromBulkKey; + +typedef struct CopyFromBulkData { + /* the hash key */ + Oid partOid; + int4 bucketId; + + /* the other entry info in hash table */ + int numTuples; + int maxTuples; + HeapTuple* tuples; + Size sizeTuples; + /* bulk-insert Memory Context */ + CopyFromMemCxt memCxt; +} CopyFromBulkData; + +typedef struct CopyFromManagerData { + /* members under PARTITION condition */ + MemoryContext parent; + CopyFromMemCxt* memCxt; + uint16 numMemCxt; + uint16 maxMemCxt; + uint16 nextMemCxt; + uint16 numFreeMemCxt; + uint16 freeMemCxt[MAX_MEMCXT_NUM]; + + HTAB* hash; + + /* members without PARTITION */ + bool isPartRel; + bool LastFlush; + CopyFromBulk bulk; + CopyFromBulkKey switchKey; +} CopyFromManagerData; + +extern void CopyFromBulkInsert(EState* estate, CopyFromBulk bulk, PageCompress* pcState, CommandId mycid, + int hi_options, ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, bool forceToFlush, BulkInsertState bistate); + +extern CopyFromBulk findBulk(CopyFromManager mgr, Oid partOid, int2 bucketId, bool *toFlush); +extern bool isBulkFull(CopyFromBulk bulk); +template +void addToBulk(CopyFromBulk bulk, HeapTuple tup, bool needCopy) +{ + MemoryContext oldCxt = NULL; + CopyFromMemCxt copyFromMemCxt = NULL; + HeapTuple newTuple = NULL; + + Assert(bulk != NULL && tup != NULL); + if (needCopy) { +#ifdef USE_ASSERT_CHECKING + int idx; + bool found = false; +#endif + copyFromMemCxt = bulk->memCxt; + Assert(copyFromMemCxt != NULL); + +#ifdef USE_ASSERT_CHECKING + if (!isInsertSelect) { + for (idx = 0; idx < copyFromMemCxt->nextBulk; idx++) { + found = found || (copyFromMemCxt->chunk[idx] == bulk); + } + Assert(true == found); + } +#endif + + oldCxt = MemoryContextSwitchTo(copyFromMemCxt->memCxtCandidate); + + newTuple = heap_copytuple(tup); + copyFromMemCxt->memCxtSize += newTuple->t_len; + if (bulk->numTuples == bulk->maxTuples) { + bulk->maxTuples *= 2; + bulk->tuples = (HeapTuple*)repalloc(bulk->tuples, sizeof(HeapTuple) * bulk->maxTuples); + } + + (void)MemoryContextSwitchTo(oldCxt); + } else { + Assert(InvalidOid == bulk->partOid); + Assert(NULL == bulk->memCxt); + Assert(bulk->numTuples < MAX_BUFFERED_TUPLES); + Assert(bulk->sizeTuples < MAX_TUPLES_SIZE); + newTuple = tup; + } + + Assert(bulk->numTuples < bulk->maxTuples); + bulk->tuples[bulk->numTuples] = newTuple; + bulk->sizeTuples += newTuple->t_len; + bulk->numTuples++; +} + +template +bool CopyFromChunkInsert(CopyState cstate, EState* estate, CopyFromBulk bulk, CopyFromManager mgr, + PageCompress* pCState, CommandId mycid, int hiOptions, ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, + BulkInsertState bistate) +{ + int cnt; + CopyFromMemCxt copyFromMemCxt = bulk->memCxt; + MemoryContext oldCxt; + + if (!mgr->isPartRel) { + + if (isInsertSelect) { + CopyFromBulkInsert(estate, bulk, pCState, mycid, hiOptions, resultRelInfo, myslot, mgr->LastFlush, bistate); + if (bulk->numTuples == 0) { + MemoryContextReset(copyFromMemCxt->memCxtCandidate); + copyFromMemCxt->memCxtSize = 0; + } + } else + CopyFromBulkInsert(estate, bulk, pCState, mycid, hiOptions, resultRelInfo, myslot, mgr->LastFlush, bistate); + return (0 == bulk->numTuples); + } + + Assert(((InvalidOid != bulk->partOid) && (InvalidOid == mgr->switchKey.partOid)) || + ((InvalidOid == bulk->partOid) && (InvalidOid != mgr->switchKey.partOid))); + for (cnt = 0; cnt < copyFromMemCxt->nextBulk; cnt++) { + CopyFromBulk bulkItem = copyFromMemCxt->chunk[cnt]; + CopyFromBulkKey key = {bulkItem->partOid, bulkItem->bucketId}; + bool found = false; + CopyFromBulkInsert(estate, bulkItem, pCState, mycid, hiOptions, resultRelInfo, myslot, true, bistate); + (void)hash_search(mgr->hash, &key, HASH_REMOVE, &found); + Assert(found); + } + + /* reset CopyFromMemCxt */ + copyFromMemCxt->nextBulk = 0; + MemoryContextReset(copyFromMemCxt->memCxtCandidate); + copyFromMemCxt->memCxtSize = 0; + + if (InvalidOid == mgr->switchKey.partOid) { + /* add to freelist */ + mgr->freeMemCxt[mgr->numFreeMemCxt++] = copyFromMemCxt->id; + } else { + copyFromMemCxt->chunk[copyFromMemCxt->nextBulk++] = bulk; + + /* reset Bulk, excluding memCxt */ + bulk->partOid = mgr->switchKey.partOid; + bulk->bucketId = mgr->switchKey.bucketId; + mgr->switchKey.partOid = InvalidOid; + mgr->switchKey.bucketId = InvalidBktId; + bulk->maxTuples = DEF_BUFFERED_TUPLES; + oldCxt = MemoryContextSwitchTo(copyFromMemCxt->memCxtCandidate); + bulk->tuples = (HeapTuple*)palloc(sizeof(HeapTuple) * bulk->maxTuples); + (void)MemoryContextSwitchTo(oldCxt); + } + + return true; +} +#endif diff -uprN postgresql-hll-2.14_old/include/commands/createas.h postgresql-hll-2.14/include/commands/createas.h --- postgresql-hll-2.14_old/include/commands/createas.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/createas.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,32 @@ +/* ------------------------------------------------------------------------- + * + * createas.h + * prototypes for createas.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/createas.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CREATEAS_H +#define CREATEAS_H + +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "tcop/dest.h" + +extern void ExecCreateTableAs( + CreateTableAsStmt* stmt, const char* queryString, ParamListInfo params, char* completionTag); + +extern int GetIntoRelEFlags(IntoClause* intoClause); + +extern DestReceiver* CreateIntoRelDestReceiver(IntoClause* intoClause); + +extern Query *SetupForCreateTableAs(Query *query, IntoClause *into, + const char *queryString, + ParamListInfo params, DestReceiver *dest); + +#endif /* CREATEAS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/dbcommands.h postgresql-hll-2.14/include/commands/dbcommands.h --- postgresql-hll-2.14_old/include/commands/dbcommands.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/dbcommands.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * dbcommands.h + * Database management commands (create/drop database). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/dbcommands.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DBCOMMANDS_H +#define DBCOMMANDS_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" + +/* XLOG stuff */ +#define XLOG_DBASE_CREATE 0x00 +#define XLOG_DBASE_DROP 0x10 + +typedef struct xl_dbase_create_rec_old { + /* Records copying of a single subdirectory incl. contents */ + Oid db_id; + char src_path[1]; /* VARIABLE LENGTH STRING */ + /* dst_path follows src_path */ +} xl_dbase_create_rec_old; + +typedef struct xl_dbase_drop_rec_old { + /* Records dropping of a single subdirectory incl. contents */ + Oid db_id; + char dir_path[1]; /* VARIABLE LENGTH STRING */ +} xl_dbase_drop_rec_old; + +typedef struct xl_dbase_create_rec { + /* Records copying of a single subdirectory incl. contents */ + Oid db_id; + Oid tablespace_id; + Oid src_db_id; + Oid src_tablespace_id; +} xl_dbase_create_rec; + +typedef struct xl_dbase_drop_rec { + /* Records dropping of a single subdirectory incl. contents */ + Oid db_id; + Oid tablespace_id; +} xl_dbase_drop_rec; + +extern void createdb(const CreatedbStmt* stmt); +extern void dropdb(const char* dbname, bool missing_ok); +extern void RenameDatabase(const char* oldname, const char* newname); +extern void AlterDatabase(AlterDatabaseStmt* stmt, bool isTopLevel); +extern void AlterDatabaseSet(AlterDatabaseSetStmt* stmt); +extern void AlterDatabaseOwner(const char* dbname, Oid newOwnerId); + +extern Oid get_database_oid(const char* dbname, bool missingok); +extern char* get_database_name(Oid dbid); +extern char* get_and_check_db_name(Oid dbid, bool is_ereport = false); +extern bool have_createdb_privilege(void); + +extern void dbase_redo(XLogReaderState* rptr); +extern void dbase_desc(StringInfo buf, XLogReaderState* record); +extern void xlog_db_drop(Oid dbId, Oid tbSpcId); +extern void xlog_db_create(Oid dstDbId, Oid dstTbSpcId, Oid srcDbId, Oid srcTbSpcId); + +extern void check_encoding_locale_matches(int encoding, const char* collate, const char* ctype); + +#ifdef PGXC +extern bool IsSetTableSpace(AlterDatabaseStmt* stmt); +extern int errdetail_busy_db(int notherbackends, int npreparedxacts); +extern void PreCleanAndCheckConns(const char* dbname, bool missing_ok); +#endif + +extern List* HDFSTablespaceDirExistDatabase(Oid db_id); + +#endif /* DBCOMMANDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/defrem.h postgresql-hll-2.14/include/commands/defrem.h --- postgresql-hll-2.14_old/include/commands/defrem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/defrem.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * + * defrem.h + * POSTGRES define and remove utility definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/defrem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEFREM_H +#define DEFREM_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" + +/* commands/dropcmds.c */ +extern void RemoveObjects(DropStmt* stmt, bool missing_ok, bool is_securityadmin = false); + +/* commands/indexcmds.c */ +extern Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_alter_table, bool check_rights, + bool skip_build, bool quiet); +extern void ReindexIndex(RangeVar* indexRelation, const char* partition_name, AdaptMem* mem_info); +extern void ReindexTable(RangeVar* relation, const char* partition_name, AdaptMem* mem_info); +extern void ReindexInternal(RangeVar* relation, const char* partition_name); + +extern void ReindexDatabase(const char* databaseName, bool do_system, bool do_user, AdaptMem* mem_info); +extern char* makeObjectName(const char* name1, const char* name2, const char* label, bool reverseTruncate = false); +extern char* ChooseRelationName( + const char* name1, const char* name2, const char* label, size_t labelLength, Oid namespaceid, + bool reverseTruncate = false); +extern bool CheckIndexCompatible(Oid oldId, char* accessMethodName, List* attributeList, List* exclusionOpNames); +extern Oid GetDefaultOpClass(Oid type_id, Oid am_id); + +/* commands/functioncmds.c */ +extern bool PrepareCFunctionLibrary(HeapTuple tup); +extern void InsertIntoPendingLibraryDelete(const char* filename, bool atCommit); +extern void libraryDoPendingDeletes(bool isCommit); +extern void ResetPendingLibraryDelete(); +extern void CreateFunction(CreateFunctionStmt* stmt, const char* queryString); +extern void RemoveFunctionById(Oid funcOid); +extern void SetFunctionReturnType(Oid funcOid, Oid newRetType); +extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType); +extern void RenameFunction(List* name, List* argtypes, const char* newname); +extern void AlterFunctionOwner(List* name, List* argtypes, Oid newOwnerId); +extern void AlterFunctionOwner_oid(Oid procOid, Oid newOwnerId); +extern bool IsFunctionTemp(AlterFunctionStmt* stmt); +extern void AlterFunction(AlterFunctionStmt* stmt); +extern void CreateCast(CreateCastStmt* stmt); +extern void DropCastById(Oid castOid); +extern void AlterFunctionNamespace(List* name, List* argtypes, bool isagg, const char* newschema); +extern Oid AlterFunctionNamespace_oid(Oid procOid, Oid nspOid); +extern void ExecuteDoStmt(DoStmt* stmt, bool atomic); +extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok); + +/* commands/operatorcmds.c */ +extern void DefineOperator(List* names, List* parameters); +extern void RemoveOperatorById(Oid operOid); +extern void AlterOperatorOwner(List* name, TypeName* typeName1, TypeName* typename2, Oid newOwnerId); +extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId); +extern void AlterOperatorNamespace(List* names, List* argtypes, const char* newschema); +extern Oid AlterOperatorNamespace_oid(Oid operOid, Oid newNspOid); + +/* commands/aggregatecmds.c */ +extern void DefineAggregate(List* name, List* args, bool oldstyle, List* parameters); +extern void RenameAggregate(List* name, List* args, const char* newname); +extern void AlterAggregateOwner(List* name, List* args, Oid newOwnerId); + +/* commands/opclasscmds.c */ +extern void DefineOpClass(CreateOpClassStmt* stmt); +extern void DefineOpFamily(CreateOpFamilyStmt* stmt); +extern void AlterOpFamily(AlterOpFamilyStmt* stmt); +extern void RemoveOpClassById(Oid opclassOid); +extern void RemoveOpFamilyById(Oid opfamilyOid); +extern void RemoveAmOpEntryById(Oid entryOid); +extern void RemoveAmProcEntryById(Oid entryOid); +extern void RenameOpClass(List* name, const char* access_method, const char* newname); +extern void RenameOpFamily(List* name, const char* access_method, const char* newname); +extern void AlterOpClassOwner(List* name, const char* access_method, Oid newOwnerId); +extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId); +extern void AlterOpClassNamespace(List* name, char* access_method, const char* newschema); +extern Oid AlterOpClassNamespace_oid(Oid opclassOid, Oid newNspOid); +extern void AlterOpFamilyOwner(List* name, const char* access_method, Oid newOwnerId); +extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId); +extern void AlterOpFamilyNamespace(List* name, char* access_method, const char* newschema); +extern Oid AlterOpFamilyNamespace_oid(Oid opfamilyOid, Oid newNspOid); +extern Oid get_am_oid(const char* amname, bool missing_ok); +extern Oid get_opclass_oid(Oid amID, List* opclassname, bool missing_ok); +extern Oid get_opfamily_oid(Oid amID, List* opfamilyname, bool missing_ok); + +/* commands/tsearchcmds.c */ +extern void DefineTSParser(List* names, List* parameters); +extern void RenameTSParser(List* oldname, const char* newname); +extern void AlterTSParserNamespace(List* name, const char* newschema); +extern Oid AlterTSParserNamespace_oid(Oid prsId, Oid newNspOid); +extern void RemoveTSParserById(Oid prsId); + +extern void DefineTSDictionary(List* names, List* parameters); +extern void RenameTSDictionary(List* oldname, const char* newname); +extern void RemoveTSDictionaryById(Oid dictId); +extern void AlterTSDictionary(AlterTSDictionaryStmt* stmt); +extern void AlterTSDictionaryOwner(List* name, Oid newOwnerId); +extern void AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId); +extern void AlterTSDictionaryNamespace(List* name, const char* newschema); +extern Oid AlterTSDictionaryNamespace_oid(Oid dictId, Oid newNspOid); + +extern void DefineTSTemplate(List* names, List* parameters); +extern void RenameTSTemplate(List* oldname, const char* newname); +extern void AlterTSTemplateNamespace(List* name, const char* newschema); +extern Oid AlterTSTemplateNamespace_oid(Oid tmplId, Oid newNspOid); +extern void RemoveTSTemplateById(Oid tmplId); + +extern void DefineTSConfiguration(List* names, List* parameters, List* cfoptions); +extern void RenameTSConfiguration(List* oldname, const char* newname); +extern void RemoveTSConfigurationById(Oid cfgId); +extern void AlterTSConfiguration(AlterTSConfigurationStmt* stmt); +extern void AlterTSConfigurationOwner(List* name, Oid newOwnerId); +extern void AlterTSConfigurationNamespace(List* name, const char* newschema); +extern Oid AlterTSConfigurationNamespace_oid(Oid cfgId, Oid newNspOid); + +extern text* serialize_deflist(List* deflist); +extern List* deserialize_deflist(Datum txt); + +/* commands/weak_password_dictioanry.c */ +extern void CreateWeakPasswordDictionary(CreateWeakPasswordDictionaryStmt* stmt); +extern void DropWeakPasswordDictionary(); + +/* commands/foreigncmds.c */ +extern void RenameForeignServer(const char* oldname, const char* newname); +extern void RenameForeignDataWrapper(const char* oldname, const char* newname); +extern void AlterForeignServerOwner(const char* name, Oid newOwnerId); +extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId); +extern void AlterForeignDataWrapperOwner(const char* name, Oid newOwnerId); +extern void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId); +extern void CreateForeignDataWrapper(CreateFdwStmt* stmt); +extern void AlterForeignDataWrapper(AlterFdwStmt* stmt); +extern void RemoveForeignDataWrapperById(Oid fdwId); +extern void CreateForeignServer(CreateForeignServerStmt* stmt); +extern void AlterForeignServer(AlterForeignServerStmt* stmt); +extern void RemoveForeignServerById(Oid srvId); +extern void CreateUserMapping(CreateUserMappingStmt* stmt); +extern void AlterUserMapping(AlterUserMappingStmt* stmt); +extern void RemoveUserMapping(DropUserMappingStmt* stmt); +extern void RemoveUserMappingById(Oid umId); +extern void CreateForeignTable(CreateForeignTableStmt* stmt, Oid relid); +#ifdef ENABLE_MOT +extern void CreateForeignIndex(IndexStmt* stmt, Oid indexRelationId); +#endif +extern Datum transformGenericOptions(Oid catalogId, Datum oldOptions, List* options, Oid fdwvalidator); +extern Datum optionListToArray(List* options); +extern List* FindOrRemoveForeignTableOption(List* optList, const char* optName, bool remove, bool* found); + +/* support routines in commands/define.c */ + +extern char* defGetString(DefElem* def); +extern double defGetNumeric(DefElem* def); +extern bool defGetBoolean(DefElem* def); +extern int64 defGetInt64(DefElem* def); +extern List* defGetQualifiedName(DefElem* def); +extern TypeName* defGetTypeName(DefElem* def); +extern int defGetTypeLength(DefElem* def); +extern List* defSetOption(List* options, const char* name, Node* value); +extern void delete_file_handle(const char* library_path); +extern int libraryGetPendingDeletes(bool forCommit, char** str_ptr, int* libraryLen); +extern void removeLibrary(const char* filename); + +/* support routines in commands/datasourcecmds.cpp */ +extern void CreateDataSource(CreateDataSourceStmt* stmt); +extern void AlterDataSource(AlterDataSourceStmt* stmt); +extern void RenameDataSource(const char* oldname, const char* newname); +extern void AlterDataSourceOwner(const char* name, Oid newOwnerId); +extern void RemoveDataSourceById(Oid src_Id); + +extern Oid GetFunctionNodeGroup(CreateFunctionStmt* stmt, bool* multi_group); +extern Oid GetFunctionNodeGroupByFuncid(Oid funcid); +extern Oid GetFunctionNodeGroup(AlterFunctionStmt* stmt); + +#endif /* !FRONTEND_PARSER */ +extern DefElem* defWithOids(bool value); +#endif /* DEFREM_H */ diff -uprN postgresql-hll-2.14_old/include/commands/directory.h postgresql-hll-2.14/include/commands/directory.h --- postgresql-hll-2.14_old/include/commands/directory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/directory.h 2020-12-12 17:06:43.104346193 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * directory.h + * The declaration of directory operate function. The functions + * use to simulate oracle's directory. + * + * + * IDENTIFICATION + * src/include/commands/directory.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DIRECTORY_H +#define DIRECTORY_H + +#include "nodes/parsenodes.h" + +/* directory.h */ +extern void CreatePgDirectory(CreateDirectoryStmt* stmt); +extern void DropPgDirectory(DropDirectoryStmt* stmt); +extern Oid get_directory_oid(const char* directoryname, bool missing_ok); +extern char* get_directory_name(Oid dir_oid); +extern void RemoveDirectoryById(Oid dirOid); +extern void AlterDirectoryOwner(const char* dirname, Oid newOwnerId); + +#endif /* DIRECTORY_H*/ diff -uprN postgresql-hll-2.14_old/include/commands/discard.h postgresql-hll-2.14/include/commands/discard.h --- postgresql-hll-2.14_old/include/commands/discard.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/discard.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,20 @@ +/* ------------------------------------------------------------------------- + * + * discard.h + * prototypes for discard.c. + * + * + * Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/commands/discard.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DISCARD_H +#define DISCARD_H + +#include "nodes/parsenodes.h" + +extern void DiscardCommand(DiscardStmt* stmt, bool isTopLevel); + +#endif /* DISCARD_H */ diff -uprN postgresql-hll-2.14_old/include/commands/explain.h postgresql-hll-2.14/include/commands/explain.h --- postgresql-hll-2.14_old/include/commands/explain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/explain.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,497 @@ +/* ------------------------------------------------------------------------- + * + * explain.h + * prototypes for explain.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/explain.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXPLAIN_H +#define EXPLAIN_H + +#include "executor/executor.h" +#include "utils/portal.h" + +extern uint32 RunGetSlotFromExplain(Portal portal, TupleTableSlot* slot, DestReceiver* dest, int count); + +typedef enum ExplainFormat { + EXPLAIN_FORMAT_TEXT, + EXPLAIN_FORMAT_XML, + EXPLAIN_FORMAT_JSON, + EXPLAIN_FORMAT_YAML +} ExplainFormat; + +struct ExplainState; + +#define ASCE 1 +#define DESC 5 + +typedef enum PlanInfoType { + PLANID = 0, + PLAN, + ACTUAL_TIME, + ACTUAL_ROWS, + ESTIMATE_ROWS, + ESTIMATE_DISTINCT, + ACTUAL_MEMORY, + ESTIMATE_MEMORY, + ACTUAL_WIDTH, + ESTIMATE_WIDTH, + ESTIMATE_COSTS, + + SLOT_NUMBER // this is the length of the slot number, this is the last number +} PlanInfoType; + +typedef enum Plantype { + PLANINFO = 0, + DETAILINFO, + STATICINFO, + VERBOSEINFO, + DATANODEINFO, + IOINFO, + RUNTIMEINFO, + PROFILEINFO, + RECURSIVEINFO, + QUERYSUMMARY +} Plantype; + +typedef enum ExplainType { + QUERY_ID = 0, + PLAN_PARENT_ID, + PLAN_NODE_ID, + PLAN_TYPE, + FROM_DATANODE, + NODE_NAME, + PLAN_NAME, + START_TIME, + TOTAL_TIME, + OPER_TIME, + PLAN_ROWS, + PLAN_LOOPS, + EX_CYC, + INC_CYC, + EX_CYC_PER_ROWS, + PEAK_OP_MEMORY, + PEAK_NODE_MEMORY, + + SHARED_BLK_HIT, + SHARED_BLK_READ, + SHARED_BLK_DIRTIED, + SHARED_BLK_WRITTEN, + LOCAL_BLK_HIT, + LOCAL_BLK_READ, + LOCAL_BLK_DIRTIED, + LOCAL_BLK_WRITTEN, + TEMP_BLK_READ, + TEMP_BLK_WRITTEN, + BLK_READ_TIME, + BLK_WRITE_TIME, + + CU_NONE, + CU_SOME, + + SORT_METHOD, + SORT_TYPE, + SORT_SPACE, + + HASH_BATCH, + HASH_BATCH_ORIGNAL, + HASH_BUCKET, + HASH_SPACE, + + HASH_FILENUM, + + QUERY_NETWORK, + NETWORK_POLL_TIME, + + LLVM_OPTIMIZATION, + BLOOM_FILTER_INFO, + DFS_BLOCK_INFO, + + MERGE_INSERTED, + MERGE_UPDATED, + + EXPLAIN_TOTAL_ATTNUM // this is the attnum of the table +} ExplainType; + +typedef struct MultiInfo { + Datum* m_Datum; + bool* m_Nulls; +} MultiInfo; + +typedef struct CompareInfo { + SortSupport ssup; + int attnum; + int* att; +} CompareInfo; + +/* plan table entry of each column in the table */ +typedef enum PlanColOpt { ANAL_OPT = 0, COST_OPT, VERBOSE_OPT } PlanColOpt; +typedef enum ExecutorTime { DN_START_TIME = 0, DN_RUN_TIME, DN_END_TIME} ExecutorTime; +typedef struct PlanTableEntry { + const char* name; /* column name */ + int val; /* column enum index in PlanInfoType */ + Oid typid; /* column type */ + PlanColOpt disoption; /* explain display option */ +} PlanTableEntry; + +/* --------------------------for explain plan && plan_table--------------------------- */ +/* for table "plan_table_data". */ +#define T_PLAN_TABLE_DATA "plan_table_data" +/* for view "plan_table". */ +#define V_PLAN_TABLE "plan_table" + +/* plan_table column length for explain plan. */ +#define PLANTABLECOLNUM 11 +#define SESSIONIDLEN 32 +#define STMTIDLEN 31 /* the max statement_id length is 30 byte. */ +#define OPERATIONLEN 31 +#define OPTIONSLEN 256 +#define OBJECTLEN 31 +#define PROJECTIONLEN 4001 + +/* plan_table_data column defination. */ +typedef struct PlanTableData { + char session_id[SESSIONIDLEN]; /* start time + thread id */ + Oid user_id; /* user id of this record, uint32 */ + char statement_id[STMTIDLEN]; /* statement_id that user input. */ + uint64 query_id; /* Oracle use plan_id instead of query_id as column name*/ + int node_id; /* plan node id. */ + char operation[OPERATIONLEN]; /* plan node operation. */ + char options[OPTIONSLEN]; /* plan node options. */ + char object_name[NAMEDATALEN]; /* object_name of this node operate. */ + char object_type[OBJECTLEN]; /* object type. */ + char object_owner[NAMEDATALEN]; /* object schema */ + StringInfo projection; /* output targetlist of the node */ +} PlanTableData; + +typedef enum PlanTableCol { + PT_SESSION_ID = 0, + PT_USER_ID, + PT_STATEMENT_ID, + PT_QUERY_ID, + + PT_NODE_ID, + + PT_OPERATION, + PT_OPTIONS, + + PT_OBJECT_NAME, + PT_OBJECT_TYPE, + PT_OBJECT_OWNER, + + PT_PROJECTION +} PlanTableCol; + +/* Store all node tupls of one plan. */ +typedef struct PlanTableMultiData { + PlanTableData* m_datum; + bool* m_isnull; +} PlanTableMultiData; + +extern THR_LOCAL bool OnlySelectFromPlanTable; +extern THR_LOCAL bool OnlyDeleteFromPlanTable; +extern THR_LOCAL bool PTFastQueryShippingStore; +extern THR_LOCAL bool IsExplainPlanStmt; +/* --------------------------end--------------------------- */ + +typedef int (*SortCompareFunc)(const MultiInfo* arg1, const MultiInfo* arg2, CompareInfo* ssup); + +class PlanTable : public BaseObject { + friend class PlanInformation; + +public: + Datum get(int type); + void put(int infotype, Datum datum); + void put(int nodeId, int smpId, int type, Datum value); + void flush(DestReceiver* dest, int plantype); + int print_plan(Portal portal, DestReceiver* dest); + void init(int plantype); + void set(int planNodeId) + { + m_plan_node_id = planNodeId; + m_has_write_planname = false; + } + + template + void set_plan_name(); + void flush_data_to_file(); + void set_datanode_name(char* nodename, int smp_idx, int dop); + + /* -----------Functions for explain plan stmt. ---------------- */ + void make_session_id(char* sessid); + + /* Set session_id, user_id, statement_id, query_id and plan node id for the query. */ + void set_plan_table_ids(uint64 query_id, ExplainState* es); + + /* Set object_name, object_type, object_owner for one paln node. */ + void set_plan_table_objs( + int plan_node_id, const char* object_name, const char* object_type, const char* object_owner); + + /* Set object_type according to relkind in pg_class. */ + void set_object_type(RangeTblEntry* rte, char** object_type); + + /* Set operation and options for remote query and stream node.*/ + void set_plan_table_streaming_ops(char* pname, char** operation, char** options); + + /* Set join option 'CARTESIAN' to fit with Oracle. */ + void set_plan_table_join_options(Plan* plan, char** options); + + /* Set operation and options for node except stream node. */ + void set_plan_table_ops(int plan_node_id, char* operation, char* options); + + /* Set projection for one paln node. */ + void set_plan_table_projection(int plan_node_id, List* tlist); + + /* Call heap_insert to insert all nodes tuples of the plan into table. */ + void insert_plan_table_tuple(); + +public: + StringInfo info_str; + int64 m_size; + int m_plan_node_id; + TupleDesc m_desc; + bool m_costs; + bool m_verbose; + bool m_cpu; + bool m_analyze; + bool m_timing; + StringInfoData m_pname; + bool m_has_write_planname; + double m_total_time; + int m_plan_size; + int m_data_size; + int* m_node_num; + int m_consumer_data_size; /* the number of datanode that has consumer info */ + bool m_query_mem_mode; + PlanTableMultiData** m_plan_table; + int m_plan_node_num; + +private: + Datum** m_data; + bool** m_isnull; + MultiInfo*** m_multi_info; + int2 m_col_loc[SLOT_NUMBER]; + + void init_planinfo(int plansize); + void init_multi_info(ExplainState* es, int plansize, int num_nodes); + /* init the data of MultiInfo. */ + void init_multi_info_data(MultiInfo* multi_info, int dop); + + /* For explain plan: init the data of plan_table. */ + void init_plan_table_data(int num_plan_nodes); + + TupleDesc getTupleDesc(); + TupleDesc getTupleDesc(const char* attname); + TupleDesc getTupleDesc_detail(); + + void flush_plan(TupOutputState* tstate); + void flush_other(TupOutputState* tstate); + void set_pname(char* data); +}; + +class PlanInformation : public BaseObject { +public: + void init(ExplainState* es, int size, int num_nodes, bool quey_mem_mode); + + void dump(DestReceiver* dest) + { + if (m_runtimeinfo && t_thrd.explain_cxt.explain_perf_mode == EXPLAIN_RUN) + dump_runtimeinfo_file(); + if (m_planInfo) + m_planInfo->flush(dest, PLANINFO); + if (m_detailInfo) + m_detailInfo->flush(dest, DETAILINFO); + if (m_staticInfo) + m_staticInfo->flush(dest, STATICINFO); + if (m_verboseInfo) + m_verboseInfo->flush(dest, VERBOSEINFO); + if (m_datanodeInfo && m_runtimeinfo) + m_datanodeInfo->flush(dest, DATANODEINFO); + if (m_IOInfo) + m_IOInfo->flush(dest, IOINFO); + if (m_recursiveInfo) + m_recursiveInfo->flush(dest, RECURSIVEINFO); + if (m_profileInfo) + m_profileInfo->flush(dest, PROFILEINFO); + if (m_query_summary) + m_query_summary->flush(dest, QUERYSUMMARY); + } + + int print_plan(Portal portal, DestReceiver* dest); + + void set_id(int plan_id) + { + if (m_planInfo) + m_planInfo->set(plan_id); + if (m_detailInfo) + m_detailInfo->set(plan_id); + if (m_staticInfo) + m_staticInfo->set(plan_id); + if (m_verboseInfo) + m_verboseInfo->set(plan_id); + if (m_datanodeInfo) + m_datanodeInfo->set(plan_id); + if (m_IOInfo) + m_IOInfo->set(plan_id); + if (m_recursiveInfo) + m_recursiveInfo->set(plan_id); + if (m_query_summary) + m_query_summary->set(plan_id); + } + + void set_pname(char* data) + { + if (m_planInfo) + m_planInfo->set_pname(data); + if (m_detailInfo) + m_detailInfo->set_pname(data); + if (m_staticInfo) + m_staticInfo->set_pname(data); + if (m_verboseInfo) + m_verboseInfo->set_pname(data); + if (m_datanodeInfo) + m_datanodeInfo->set_pname(data); + if (m_IOInfo) + m_IOInfo->set_pname(data); + if (m_recursiveInfo) + m_recursiveInfo->set_pname(data); + if (m_query_summary) + m_query_summary->set_pname(data); + } + + void append_str_info(const char* data, int id, const char* value); + + PlanTable* m_planInfo; + PlanTable* m_detailInfo; + PlanTable* m_staticInfo; + PlanTable* m_verboseInfo; + PlanTable* m_datanodeInfo; + PlanTable* m_IOInfo; + PlanTable* m_profileInfo; + PlanTable* m_query_summary; + PlanTable* m_recursiveInfo; + + /* For explain plan */ + PlanTable* m_planTableData; + + int m_count; + PlanTable* m_runtimeinfo; + bool m_detail; + int m_query_id; + +private: + void dump_runtimeinfo_file(); + void flush_runtime_info(DestReceiver* dest); + void flush_summary_info(DestReceiver* dest); + void flush_memory_info(DestReceiver* dest); + + void write_datanode(); + void append_time_info(int node_idx, int plan_idx, bool from_datanode); + void append_cpu_info(int node_idx, int plan_idx, bool from_datanode); + void append_buffer_info(int node_idx, int plan_idx, bool from_datanode); + void append_roughcheck_info(int node_idx, int plan_idx, bool from_datanode); + void append_llvm_info(int node_idx, int plan_idx, bool from_datanode); + void append_bloomfilter_info(int node_idx, int plan_idx, bool from_datanode); + void append_dfs_block_info(int node_idx, int plan_idx, bool from_datanode); + + void write_memory(); + void append_peak_memory_info(int node_idx, int plan_idx, bool from_datanode); + void append_memory_info(int node_idx, int plan_idx, bool from_datanode); + void append_network_info(int node_idx, int plan_idx); + void append_sort_info(int node_idx, int plan_idx, bool from_datanode); + void append_filenum_info(int node_idx, int plan_idx, bool from_datanode); + void append_hash_info(int node_idx, int plan_idx, bool from_datanode); + void append_vechash_info(int node_idx, int plan_idx, bool from_datanode); + + void free_memory(); +}; + +typedef struct DN_RunInfo { + bool all_datanodes; + int len_nodelist; + int* node_index; +} DN_RunInfo; + +typedef struct ExplainState { + StringInfo str; /* output buffer */ + /* options */ + bool plan; /* do not print plan */ + bool verbose; /* be verbose */ + bool analyze; /* print actual times */ + bool costs; /* print costs */ + bool buffers; /* print buffer usage */ +#ifdef PGXC + bool nodes; /* print nodes in RemoteQuery node */ + bool num_nodes; /* print number of nodes in RemoteQuery node */ +#endif /* PGXC */ + bool timing; /* print timing */ + bool cpu; + bool detail; + bool performance; + bool from_dn; + bool sql_execute; + bool isexplain_execute; /* is explain execute statement */ + ExplainFormat format; /* output format */ + /* other states */ + PlannedStmt* pstmt; /* top of plan */ + List* rtable; /* range table */ + int indent; /* current indentation level */ + int pindent; + List* grouping_stack; /* format-specific grouping state */ + PlanInformation* planinfo; + DN_RunInfo datanodeinfo; + int* wlm_statistics_plan_max_digit; /* print plan for wlm statistics */ + char* statement_id; /* statement_id for EXPLAIN PLAN */ + bool is_explain_gplan; +} ExplainState; + +/* Hook for plugins to get control in explain_get_index_name() */ +typedef const char *(*explain_get_index_name_hook_type) (Oid indexId); +extern THR_LOCAL PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook; + +extern void ExplainQuery( + ExplainStmt* stmt, const char* queryString, ParamListInfo params, DestReceiver* dest, char* completionTag); + +extern void ExplainInitState(ExplainState* es); + +extern TupleDesc ExplainResultDesc(ExplainStmt* stmt); + +extern void ExplainOneUtility( + Node* utilityStmt, IntoClause* into, ExplainState* es, const char* queryString, ParamListInfo params); + +extern void ExplainOnePlan( + PlannedStmt* plannedstmt, IntoClause* into, ExplainState* es, const char* queryString, + DestReceiver *dest, ParamListInfo params); + +extern void ExplainPrintPlan(ExplainState* es, QueryDesc* queryDesc); + +extern void ExplainQueryText(ExplainState* es, QueryDesc* queryDesc); + +extern void ExplainOneQueryForStatistics(QueryDesc* queryDesc); + +extern void ExplainBeginOutput(ExplainState* es); +extern void ExplainEndOutput(ExplainState* es); +extern void ExplainSeparatePlans(ExplainState* es); + +extern void ExplainPropertyList(const char* qlabel, List* data, ExplainState* es); +extern void ExplainPropertyText(const char* qlabel, const char* value, ExplainState* es); +extern void ExplainPropertyInteger(const char* qlabel, int value, ExplainState* es); +extern void ExplainPropertyLong(const char* qlabel, long value, ExplainState* es); +extern void ExplainPropertyFloat(const char* qlabel, double value, int ndigits, ExplainState* es); + +extern int get_track_time(ExplainState* es, PlanState* planstate, bool show_track, bool show_buffer, + bool show_dummygroup, bool show_indexinfo, bool show_storage_info = false); + +extern void ExplainPropertyListNested(const char* qlabel, List* data, ExplainState* es); +extern List* set_deparse_context_planstate(List* dpcontext, Node* planstate, List* ancestors); +extern double elapsed_time(instr_time* starttime); +extern void print_explain_info(StreamInstrumentation* instrumentdata, QueryDesc* querydesc, ExplainState* es); +extern bool checkSelectStmtForPlanTable(List* rangeTable); +extern int checkPermsForPlanTable(RangeTblEntry* rte); + +#endif /* EXPLAIN_H */ diff -uprN postgresql-hll-2.14_old/include/commands/extension.h postgresql-hll-2.14/include/commands/extension.h --- postgresql-hll-2.14_old/include/commands/extension.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/extension.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * extension.h + * Extension management commands (create/drop extension). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/extension.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXTENSION_H +#define EXTENSION_H + +#include "nodes/parsenodes.h" + +/* + * creating_extension is only true while running a CREATE EXTENSION command. + * It instructs recordDependencyOnCurrentExtension() to register a dependency + * on the current pg_extension object for each SQL object created by its + * installation script. + */ +extern THR_LOCAL bool creating_extension; + +extern void CreateExtension(CreateExtensionStmt* stmt); + +extern void RemoveExtensionById(Oid extId); + +extern Oid InsertExtensionTuple(const char* extName, Oid extOwner, Oid schemaOid, bool relocatable, + const char* extVersion, Datum extConfig, Datum extCondition, List* requiredExtensions); + +extern void ExecAlterExtensionStmt(AlterExtensionStmt* stmt); + +extern void ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt* stmt); + +extern Oid get_extension_oid(const char* extname, bool missing_ok); +extern char* get_extension_name(Oid ext_oid); + +extern void AlterExtensionNamespace(List* names, const char* newschema); + +extern void AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId); + +#endif /* EXTENSION_H */ diff -uprN postgresql-hll-2.14_old/include/commands/formatter.h postgresql-hll-2.14/include/commands/formatter.h --- postgresql-hll-2.14_old/include/commands/formatter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/formatter.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * formatter.h + * + * + * + * IDENTIFICATION + * src/include/commands/formatter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef FORMATTER_H_ +#define FORMATTER_H_ + +#include "c.h" +#include "nodes/pg_list.h" +#include "bulkload/utils.h" + +typedef enum { ALIGN_INVALID, ALIGN_LEFT, ALIGN_RIGHT } FieldAlign; + +struct FieldDesc { + char* fieldname; + char* nullString; + int fieldPos; + int fieldSize; + int attnum; + FieldAlign align; +}; + +struct Formatter { + FileFormat format; + int nfield; +}; + +struct FixFormatter : public Formatter { + int lineSize; + FieldDesc* fieldDesc; + bool forceLineSize; +}; + +#endif /* FORMATTER_H_ */ diff -uprN postgresql-hll-2.14_old/include/commands/gds_stream.h postgresql-hll-2.14/include/commands/gds_stream.h --- postgresql-hll-2.14_old/include/commands/gds_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/gds_stream.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gds_stream.h + * + * + * + * IDENTIFICATION + * src/include/commands/gds_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GDS_STREAM_H +#define GDS_STREAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "bulkload/utils.h" +#include "ssl/gs_openssl_client.h" + +/* + * Bulkload base class + */ +class BulkLoadStream : public BaseObject { +public: + /* Bulkload stream close */ + virtual void Close() = 0; + + /* Bulkload stream read */ + virtual int Read() = 0; + + virtual int InternalRead() = 0; + + virtual int ReadMessage(StringInfoData& dst) = 0; + + /* Bulkload stream write */ + virtual int Write(void* src, Size len) = 0; + + virtual void Flush() = 0; + + virtual void VerifyAddr() = 0; +}; + +class GDSUri : public BaseObject { +public: + GDSUri() + { + m_uri = NULL; + m_protocol = NULL; + m_host = NULL; + m_port = -1; + m_path = NULL; + } + + ~GDSUri() + { + if (m_uri) + pfree(m_uri); + if (m_protocol) + pfree(m_protocol); + if (m_host) + pfree(m_host); + if (m_path) + pfree(m_path); + } + + void Parse(const char* uri); + + const char* ToString() + { + return m_uri; + } + + static void Trim(char* str); + + char* m_uri; + char* m_protocol; + char* m_host; + int m_port; + char* m_path; +}; + +class GDSStream : public BulkLoadStream { +public: + GDSStream(); + + virtual ~GDSStream(); + + void Initialize(const char* uri); + + void Close(); + + int Read(); + + int ReadMessage(StringInfoData& dst); + + int Write(void* src, Size len); + + void Flush(); + + void VerifyAddr(); + + GDSUri* m_uri; + int m_fd; + bool m_ssl_enable; + gs_openssl_cli m_ssl; + StringInfo m_inBuf; + StringInfo m_outBuf; + +private: + /* function type pointer defination */ + typedef int (GDSStream::*readfun)(void); + readfun m_read; + + void PrepareReadBuf(void); + int InternalRead(void); + int InternalReadSSL(void); + + void InitSSL(void); +}; + +extern void SerializeCmd(CmdBase* cmd, StringInfo buf); +extern CmdBase* DeserializeCmd(StringInfo buf); +extern void PackData(StringInfo data, StringInfo dst); + +#endif diff -uprN postgresql-hll-2.14_old/include/commands/lockcmds.h postgresql-hll-2.14/include/commands/lockcmds.h --- postgresql-hll-2.14_old/include/commands/lockcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/lockcmds.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * lockcmds.h + * prototypes for lockcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/lockcmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCKCMDS_H +#define LOCKCMDS_H + +#include "nodes/parsenodes.h" + +/* + * LOCK + */ +extern void LockTableCommand(LockStmt* lockstmt); + +#endif /* LOCKCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/matview.h postgresql-hll-2.14/include/commands/matview.h --- postgresql-hll-2.14_old/include/commands/matview.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/matview.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,75 @@ +/*------------------------------------------------------------------------- + * + * matview.h + * prototypes for matview.c. + * + * src/include/commands/matview.h + * + * ------------------------------------------------------------------------ + */ +#ifndef MATVIEW_H +#define MATVIEW_H + +#include "nodes/params.h" +#include "tcop/dest.h" +#include "utils/relcache.h" + +#define MlogAttributeNum 5 + +#define MlogAttributeAction 1 +#define MlogAttributeTime 2 +#define MlogAttributeCtid 3 +#define MlogAttributeXid 4 +#define MlogAttributeSeqno 5 + +#define MatMapAttributeNum 5 +#define MatMapAttributeMatid 1 +#define MatMapAttributeMatctid 2 +#define MatMapAttributeRelid 3 +#define MatMapAttributeRelctid 4 +#define MatMapAttributeRelxid 5 + +#define ActionCreateMat 1 +#define ActionRefreshInc 2 + +/* used to blocking ANALYZE */ +#define MLOGLEN 5 +#define MATMAPLEN 11 +#define MATMAPNAME "matviewmap_" +#define MLOGNAME "mlog_" + +#define ISMATMAP(relname) (strncmp(relname, MATMAPNAME, MATMAPLEN) == 0) +#define ISMLOG(relname) (strncmp(relname, MLOGNAME, MLOGLEN) == 0) + +extern Size MatviewShmemSize(void); +extern void MatviewShmemInit(void); + +extern void SetRelationIsScannable(Relation relation); + +extern void ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); + +extern void ExecRefreshMatViewInc(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); +extern void ExecCreateMatViewInc(CreateTableAsStmt* stmt, const char* queryString, ParamListInfo params); +extern void ExecRefreshMatViewAll(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); + +extern DestReceiver *CreateTransientRelDestReceiver(Oid oid); + +extern void build_matview_dependency(Oid matviewOid, Relation materRel); +extern Oid create_matview_map(Oid intoRelationId); +extern void insert_into_matview_map(Oid mapid, Oid matid, ItemPointer matcitd, + Oid relid, ItemPointer relctid, TransactionId xid); +extern Oid find_matview_mlog_table(Oid relid); +extern void insert_into_mlog_table(Relation rel, Oid mlogid, HeapTuple tuple, + ItemPointer tid, TransactionId xid, char action); +extern void create_matview_meta(Query *query, RangeVar *rel, bool incremental); + +extern void check_matview_op_supported(CreateTableAsStmt *ctas); +extern DistributeBy *infer_incmatview_distkey(CreateTableAsStmt *stmt); +extern void check_basetable(Query *query); +extern bool isIncMatView(RangeVar *rv); +extern void MatviewShmemSetInvalid(); + +#endif /* MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/commands/obs_stream.h postgresql-hll-2.14/include/commands/obs_stream.h --- postgresql-hll-2.14_old/include/commands/obs_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/obs_stream.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,97 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * obs_stream.h + * + * + * + * IDENTIFICATION + * src/include/commands/obs_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OBS_STREAM_H +#define OBS_STREAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "bulkload/utils.h" +#include "../../bin/gds/parser.h" +#include "commands/copy.h" +#include "commands/gds_stream.h" +#include "storage/buffile.h" + +class OBSStream : public BulkLoadStream { +public: + /* Constructor & De-constructor */ + OBSStream(FileFormat format, bool is_write); + virtual ~OBSStream(); + + /* Routines inherited from interface */ + void Initialize(const char* uri, CopyState cstate); + + void Close(); /* virtual function */ + + int Read(); /* virtual function */ + + int InternalRead(); /* virtual function */ + + int ReadMessage(StringInfoData& dst); /* virtual function */ + + int Write(void* src, Size len); /* virtual function */ + + void Flush(); /* virtual function */ + + void VerifyAddr(); + + /* Getter & Setter */ + inline GDS::Parser* GetOBSParser() + { + Assert(m_parser != NULL); + return this->m_parser; + }; + + void set_parser_chunksize(uint32_t chunksize); + void set_source_obs_copy_options(ObsCopyOptions* options); + + const ObsCopyOptions* get_obs_copy_options(void); + void set_obs_copy_options(ObsCopyOptions* options); + + const char* StartNewSegment(void); + +private: + FileList m_filelist; + + /* Parser to handle OBS objects */ + GDS::Parser* m_parser; + + /* OBS object realted variables */ + string m_url; + char* m_hostname; + char* m_bucket; + char* m_prefix; + + /* writer specific */ + bool m_write; + BufFile* m_buffile; + StringInfo m_cur_segment; + size_t m_cur_segment_offset; + int m_cur_segment_num; + + ObsCopyOptions* m_obs_options; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/commands/portalcmds.h postgresql-hll-2.14/include/commands/portalcmds.h --- postgresql-hll-2.14_old/include/commands/portalcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/portalcmds.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * portalcmds.h + * prototypes for portalcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/portalcmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PORTALCMDS_H +#define PORTALCMDS_H + +#include "nodes/parsenodes.h" +#include "utils/portal.h" + +extern void PerformCursorOpen(PlannedStmt* stmt, ParamListInfo params, const char* queryString, bool isTopLevel); + +extern void PerformPortalFetch(FetchStmt* stmt, DestReceiver* dest, char* completionTag); + +extern void PerformPortalClose(const char* name); + +extern void PortalCleanup(Portal portal); + +extern void PersistHoldablePortal(Portal portal); + +#endif /* PORTALCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/prepare.h postgresql-hll-2.14/include/commands/prepare.h --- postgresql-hll-2.14_old/include/commands/prepare.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/prepare.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------------- + * + * prepare.h + * PREPARE, EXECUTE and DEALLOCATE commands, and prepared-stmt storage + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/commands/prepare.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREPARE_H +#define PREPARE_H + +#include "commands/explain.h" +#include "utils/globalplancache.h" +#include "utils/plancache.h" + +#ifdef PGXC +typedef struct DatanodeStatement { + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + int current_nodes_number; /* number of nodes where statement is active */ + int max_nodes_number; /* maximum number of nodes where statement is active */ + int* dns_node_indices; /* node ids where statement is active */ + instr_time* last_used_time; /* for gpc, save time when use this statement to send msg to dn */ +} DatanodeStatement; +#endif + +#define NEED_SEND_PARSE_AGAIN(last_used_time, cur_time) \ + (INSTR_TIME_GET_DOUBLE(cur_time) - INSTR_TIME_GET_DOUBLE(last_used_time)) > ((double)MAX_PREPARE_WAIING_TIME / 2) + +/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */ +extern void PrepareQuery(PrepareStmt* stmt, const char* queryString); +extern void ExecuteQuery(ExecuteStmt* stmt, IntoClause* intoClause, const char* queryString, ParamListInfo params, + DestReceiver* dest, char* completionTag); +extern void DeallocateQuery(DeallocateStmt* stmt); +extern void ExplainExecuteQuery( + ExecuteStmt* execstmt, IntoClause* into, ExplainState* es, const char* queryString, ParamListInfo params); + +/* Low-level access to stored prepared statements */ +extern void StorePreparedStatementCNGPC(const char *stmt_name, CachedPlanSource *plansource, + bool from_sql, bool is_share); +extern void StorePreparedStatement(const char* stmt_name, CachedPlanSource* plansource, bool from_sql); +extern PreparedStatement* FetchPreparedStatement(const char* stmt_name, bool throwError, bool need_valid = true); +extern void DropPreparedStatement(const char* stmt_name, bool showError); +extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt); +extern List* FetchPreparedStatementTargetList(PreparedStatement *stmt); + +extern void DropAllPreparedStatements(void); +extern void HandlePreparedStatementsForReload(void); +extern void HandlePreparedStatementsForRetry(void); +extern bool HaveActiveCoordinatorPreparedStatement(const char* stmt_name); + +#ifdef PGXC +extern DatanodeStatement* FetchDatanodeStatement(const char* stmt_name, bool throwError); +extern bool ActivateDatanodeStatementOnNode(const char* stmt_name, int noid); +extern void DeActiveAllDataNodeStatements(void); +extern bool HaveActiveDatanodeStatements(void); +extern void DropDatanodeStatement(const char* stmt_name); +extern int SetRemoteStatementName(Plan* plan, const char* stmt_name, int num_params, Oid* param_types, int n, + bool isBuildingCustomPlan, bool is_plan_shared = false); +extern char* get_datanode_statement_name(const char* stmt_name, int n); +#endif +extern bool needRecompileQuery(ExecuteStmt* stmt); +extern void RePrepareQuery(ExecuteStmt* stmt); +extern bool checkRecompileCondition(CachedPlanSource* plansource); + +extern void GetRemoteQuery(PlannedStmt* stmt, const char* queryString); +extern void GetRemoteQueryWalker(Plan* plan, void* context, const char* queryString); +extern void PlanTreeWalker( + Plan* plan, void (*walker)(Plan*, void*, const char*), void* context, const char* queryString); + +extern DatanodeStatement* light_set_datanode_queries(const char* stmt_name); +#endif /* PREPARE_H */ diff -uprN postgresql-hll-2.14_old/include/commands/proclang.h postgresql-hll-2.14/include/commands/proclang.h --- postgresql-hll-2.14_old/include/commands/proclang.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/proclang.h 2020-12-12 17:06:43.105346206 +0800 @@ -0,0 +1,25 @@ +/* + * src/include/commands/proclang.h + * + * ------------------------------------------------------------------------- + * + * proclang.h + * prototypes for proclang.c. + * + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCLANG_H +#define PROCLANG_H + +#include "nodes/parsenodes.h" + +extern void CreateProceduralLanguage(CreatePLangStmt* stmt); +extern void DropProceduralLanguageById(Oid langOid); +extern void RenameLanguage(const char* oldname, const char* newname); +extern void AlterLanguageOwner(const char* name, Oid newOwnerId); +extern void AlterLanguageOwner_oid(Oid oid, Oid newOwnerId); +extern bool PLTemplateExists(const char* languageName); +extern Oid get_language_oid(const char* langname, bool missing_ok); + +#endif /* PROCLANG_H */ diff -uprN postgresql-hll-2.14_old/include/commands/schemacmds.h postgresql-hll-2.14/include/commands/schemacmds.h --- postgresql-hll-2.14_old/include/commands/schemacmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/schemacmds.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * schemacmds.h + * prototypes for schemacmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/schemacmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCHEMACMDS_H +#define SCHEMACMDS_H + +#include "nodes/parsenodes.h" + +#ifdef PGXC +extern void CreateSchemaCommand(CreateSchemaStmt* parsetree, const char* queryString, bool is_top_level); +#else +extern void CreateSchemaCommand(CreateSchemaStmt* parsetree, const char* queryString); +#endif +extern void RemoveSchemaById(Oid schemaOid); + +extern void RenameSchema(const char* oldname, const char* newname); +extern void AlterSchemaOwner(const char* name, Oid newOwnerId); +extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId); + +#endif /* SCHEMACMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/seclabel.h postgresql-hll-2.14/include/commands/seclabel.h --- postgresql-hll-2.14_old/include/commands/seclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/seclabel.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,30 @@ +/* + * seclabel.h + * + * Prototypes for functions in commands/seclabel.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + */ +#ifndef SECLABEL_H +#define SECLABEL_H + +#include "catalog/objectaddress.h" + +/* + * Internal APIs + */ +extern char* GetSecurityLabel(const ObjectAddress* object, const char* provider); +extern void SetSecurityLabel(const ObjectAddress* object, const char* provider, const char* label); +extern void DeleteSecurityLabel(const ObjectAddress* object); +extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId); + +/* + * Statement and ESP hook support + */ +extern void ExecSecLabelStmt(SecLabelStmt* stmt); + +typedef void (*check_object_relabel_type)(const ObjectAddress* object, const char* seclabel); +extern void register_label_provider(const char* provider, check_object_relabel_type hook); + +#endif /* SECLABEL_H */ diff -uprN postgresql-hll-2.14_old/include/commands/sec_rls_cmds.h postgresql-hll-2.14/include/commands/sec_rls_cmds.h --- postgresql-hll-2.14_old/include/commands/sec_rls_cmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/sec_rls_cmds.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * sec_rls_cmds.h + * Security Module. + * Variables and function commands used in Row Level Security Policy. + * + * + * IDENTIFICATION + * src/include/commands/sec_rls_cmds.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_RLS_CMDS_H +#define SEC_RLS_CMDS_H + +#include "nodes/parsenodes.h" + +extern void CreateRlsPolicy(CreateRlsPolicyStmt* stmt); +extern void AlterRlsPolicy(AlterRlsPolicyStmt* stmt); +extern void RenameRlsPolicy(RenameStmt* stmt); +extern void RemoveRlsPolicyById(Oid rlsPolicyOid); +extern bool RemoveRoleFromRlsPolicy(Oid roleid, Oid rlsrelid, Oid rlspolicyid); +extern void RelationBuildRlsPolicies(Relation relation); +extern Oid get_rlspolicy_oid(Oid relid, const char* policy_name, bool missing_ok); +extern bool RelationHasRlspolicy(Oid relid); +extern void CreateRlsPolicyForSystem( + char* schemaName, char* relName, char* policyName, char* funcName, char* relColname, char* privType); + +#endif /* SEC_RLS_CMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/sequence.h postgresql-hll-2.14/include/commands/sequence.h --- postgresql-hll-2.14_old/include/commands/sequence.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/sequence.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,166 @@ +/* ------------------------------------------------------------------------- + * + * sequence.h + * prototypes for sequence.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/sequence.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SEQUENCE_H +#define SEQUENCE_H + +#include "access/xlogreader.h" +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "storage/relfilenode.h" + +#ifdef PGXC +#include "utils/relcache.h" +#include "gtm/gtm_c.h" +#include "access/xact.h" +#include "optimizer/streamplan.h" +#include "pgxc/pgxcnode.h" +#include "tcop/utility.h" +#endif + +#define INVALIDSEQUUID 0 + +// extern THR_LOCAL char *PGXCNodeName; + +typedef int64 GTM_UUID; + +typedef struct FormData_pg_sequence { + NameData sequence_name; + int64 last_value; + int64 start_value; + int64 increment_by; + int64 max_value; + int64 min_value; + int64 cache_value; + int64 log_cnt; + bool is_cycled; + bool is_called; + GTM_UUID uuid; +} FormData_pg_sequence; + +typedef FormData_pg_sequence* Form_pg_sequence; + +/* + * Columns of a sequence relation + */ + +#define SEQ_COL_NAME 1 +#define SEQ_COL_LASTVAL 2 +#define SEQ_COL_STARTVAL 3 +#define SEQ_COL_INCBY 4 +#define SEQ_COL_MAXVALUE 5 +#define SEQ_COL_MINVALUE 6 +#define SEQ_COL_CACHE 7 +#define SEQ_COL_LOG 8 +#define SEQ_COL_CYCLE 9 +#define SEQ_COL_CALLED 10 +#define SEQ_COL_UUID 11 + +#define SEQ_COL_FIRSTCOL SEQ_COL_NAME +#define SEQ_COL_LASTCOL SEQ_COL_UUID + +/* XLOG stuff */ +#define XLOG_SEQ_LOG 0x00 + +/* + * The "special area" of a sequence's buffer page looks like this. + */ +#define SEQ_MAGIC 0x1717 + +typedef struct xl_seq_rec { + RelFileNodeOld node; + /* SEQUENCE TUPLE DATA FOLLOWS AT THE END */ +} xl_seq_rec; + +/* + * We don't want to log each fetching of a value from a sequence, + * so we pre-log a few fetches in advance. In the event of + * crash we can lose (skip over) as many values as we pre-logged. + */ +#define SEQ_LOG_VALS 32 + + +/* + * The "special area" of a old version sequence's buffer page looks like this. + */ + +typedef struct sequence_magic { + uint32 magic; +} sequence_magic; + + +extern Datum nextval(PG_FUNCTION_ARGS); +extern Datum nextval_oid(PG_FUNCTION_ARGS); +extern Datum currval_oid(PG_FUNCTION_ARGS); +extern Datum setval_oid(PG_FUNCTION_ARGS); +extern Datum setval3_oid(PG_FUNCTION_ARGS); +extern Datum lastval(PG_FUNCTION_ARGS); + +extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS); + +extern void DefineSequence(CreateSeqStmt* stmt); +extern void AlterSequence(AlterSeqStmt* stmt); +extern void PreventAlterSeqInTransaction(bool isTopLevel, AlterSeqStmt* stmt); +extern void ResetSequence(Oid seq_relid); + +extern void seq_redo(XLogReaderState* rptr); +extern void seq_desc(StringInfo buf, XLogReaderState* record); +extern GTM_UUID get_uuid_from_rel(Relation rel); +extern void lockNextvalOnCn(Oid relid); + +extern void get_sequence_params(Relation rel, int64* uuid, int64* start, int64* increment, int64* maxvalue, + int64* minvalue, int64* cache, bool* cycle); + +#ifdef PGXC +/* + * List of actions that registered the callback. + * This is listed here and not in sequence.c because callback can also + * be registered in dependency.c and tablecmds.c as sequences can be dropped + * or renamed in cascade. + */ +typedef enum { GTM_CREATE_SEQ, GTM_DROP_SEQ } GTM_SequenceDropType; +/* + * Arguments for callback of sequence drop on GTM + */ +typedef struct drop_sequence_callback_arg { + GTM_UUID seq_uuid; + GTM_SequenceDropType type; + GTM_SequenceKeyType key; +} drop_sequence_callback_arg; + +/* + * Arguments for callback of sequence rename on GTM + */ +typedef struct rename_sequence_callback_arg { + char* newseqname; + char* oldseqname; +} rename_sequence_callback_arg; + +extern void delete_global_seq(Oid relid, Relation seqrel); +/* Sequence callbacks on GTM */ +extern void register_sequence_rename_cb(const char* oldseqname, const char* newseqname); +extern void rename_sequence_cb(GTMEvent event, void* args); +extern void register_sequence_cb(GTM_UUID seq_uuid, GTM_SequenceDropType type); +extern void drop_sequence_cb(GTMEvent event, void* args); + +extern bool IsTempSequence(Oid relid); +extern char* GetGlobalSeqName(Relation rel, const char* new_seqname, const char* new_schemaname); +extern char* gen_hybirdmsg_for_CreateSeqStmt(CreateSeqStmt* stmt, const char* queryString); +extern int64 gen_uuid(List* uuids); +extern char* gen_hybirdmsg_for_CreateSchemaStmt(CreateSchemaStmt* stmt, const char* queryString); +extern void gen_uuid_for_CreateStmt(CreateStmt* stmt, List* uuids); +extern void gen_uuid_for_CreateSchemaStmt(List* stmts, List* uuids); + +#endif + +#endif /* SEQUENCE_H */ diff -uprN postgresql-hll-2.14_old/include/commands/shutdown.h postgresql-hll-2.14/include/commands/shutdown.h --- postgresql-hll-2.14_old/include/commands/shutdown.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/shutdown.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,19 @@ +/* ------------------------------------------------------------------------- + * + * shutdown.h + * prototypes for shutdown.cpp + * + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * src/include/commands/shutdown.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SHUTDOWN_H +#define SHUTDOWN_H + +#include "nodes/parsenodes.h" + +extern void DoShutdown(ShutdownStmt* stmt); + +#endif /* SHUTDOWN_H */ diff -uprN postgresql-hll-2.14_old/include/commands/tablecmds.h postgresql-hll-2.14/include/commands/tablecmds.h --- postgresql-hll-2.14_old/include/commands/tablecmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/tablecmds.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * tablecmds.h + * prototypes for tablecmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablecmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TABLECMDS_H +#define TABLECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "rewrite/rewriteRlsPolicy.h" +#include "storage/lock.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" + +#define MAX_MERGE_PARTITIONS 300 +#define ATT_DEFAULT_LEN 128 + +#define FOREIGNTABLE_SUPPORT_AT_CMD(cmd) \ + ((cmd) == AT_ChangeOwner || (cmd) == AT_AddNodeList || (cmd) == AT_SubCluster || (cmd) == AT_DeleteNodeList || \ + (cmd) == AT_GenericOptions) + +#define DIST_OBS_SUPPORT_AT_CMD(cmd) \ + ((cmd) == AT_ChangeOwner || (cmd) == AT_AddNodeList || (cmd) == AT_DeleteNodeList || (cmd) == AT_SubCluster || \ + (cmd) == AT_GenericOptions || (cmd) == AT_DropNotNull || (cmd) == AT_SetNotNull || \ + (cmd) == AT_SetStatistics || (cmd) == AT_AlterColumnType || (cmd) == AT_AlterColumnGenericOptions || \ + (cmd) == AT_AddIndex || (cmd) == AT_DropConstraint) + +extern Oid DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId); + +extern void RemoveRelationsonMainExecCN(DropStmt* drop, ObjectAddresses* objects); + +extern bool check_ts_idx_ddl(RangeVar* rel, Oid* idx_id, IndexStmt* stmt = NULL); + +extern void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExecType* exec_type); + +extern void RemoveObjectsonMainExecCN(DropStmt* drop, ObjectAddresses* objects, bool isFirstNode); + +extern ObjectAddresses* PreCheckforRemoveObjects(DropStmt* stmt, StringInfo tmp_queryString, + RemoteQueryExecType* exec_type, bool isFirstNode, bool is_securityadmin = false); + +extern ObjectAddresses* PreCheckforRemoveRelation( + DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExecType* exec_type); + +extern Oid AlterTableLookupRelation(AlterTableStmt* stmt, LOCKMODE lockmode, bool unlock = false); + +extern void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt* stmt); + +extern LOCKMODE AlterTableGetLockLevel(List* cmds); + +extern void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode); + +extern void AlterTableInternal(Oid relid, List* cmds, bool recurse); + +extern void AlterTableNamespace(AlterObjectSchemaStmt* stmt); + +extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses* objsMoved); + +extern void AlterRelationNamespaceInternal( + Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses* objsMoved); + +extern void CheckTableNotInUse(Relation rel, const char* stmt); +extern void CheckPartitionNotInUse(Partition part, const char* stmt); +#ifdef PGXC +extern void ExecuteTruncate(TruncateStmt* stmt, const char* sql_statement); +#else +extern void ExecuteTruncate(TruncateStmt* stmt); +#endif + +extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass); + +extern void renameatt(RenameStmt* stmt); + +extern void RenameConstraint(RenameStmt* stmt); + +extern void RenameRelation(RenameStmt* stmt); + +extern void RenameRelationInternal(Oid myrelid, const char* newrelname); + +extern void find_composite_type_dependencies(Oid typeOid, Relation origRelation, const char* origTypeName); + +extern void check_of_type(HeapTuple typetuple); + +extern void register_on_commit_action(Oid relid, OnCommitAction action); +extern void remove_on_commit_action(Oid relid); + +extern void PreCommit_on_commit_actions(void); +extern void AtEOXact_on_commit_actions(bool isCommit); +extern void AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +#ifdef PGXC +extern bool IsTempTable(Oid relid); +extern bool IsRelaionView(Oid relid); +extern bool IsIndexUsingTempTable(Oid relid); +extern bool IsOnCommitActions(void); +extern void DropTableThrowErrorExternal(RangeVar* relation, ObjectType removeType, bool missing_ok); +#endif + +extern void RangeVarCallbackOwnsTable( + const RangeVar* relation, Oid relId, Oid oldRelId, bool target_is_partition, void* arg); +extern void RangeVarCallbackOwnsRelation( + const RangeVar* relation, Oid relId, Oid oldRelId, bool target_is_partition, void* noCatalogs); +extern void checkPartNotInUse(Partition part, const char* stmt); +extern List* transformConstIntoTargetType(Form_pg_attribute* attrs, int2vector* partitionKey, List* boundary); +extern List* transformIntoTargetType(Form_pg_attribute* attrs, int2 pos, List* boundary); + +extern void renamePartitionedTable(Oid partitionedTableOid, const char* partitionedTableNewName); +extern void renamePartition(RenameStmt* stmt); +extern void renamePartitionIndex(RenameStmt* stmt); +extern void renamePartitionInternal(Oid partitionedTableOid, Oid partitionOid, const char* partitionNewName); + +extern Oid addPartitionBySN(Relation rel, int seqnum); +extern Datum caculateBoundary(Datum transpoint, Oid attrtypid, Datum intervalue, Oid intertypid, int seqnum); +extern void ATExecSetIndexUsableState(Oid objclassOid, Oid objOid, bool newState); +extern bool checkPartitionLocalIndexesUsable(Oid partitionOid); +extern bool checkRelationLocalIndexesUsable(Relation relation); +extern List* GetPartitionkeyPos(List* partitionkeys, List* schema); + +extern void ComparePartitionValue(List* pos, Form_pg_attribute* attrs, List *partitionList, bool isPartition = true); +extern void clearAttrInitDefVal(Oid relid); + +extern void AlterDfsCreateTables(Oid relOid, Datum toast_options, CreateStmt* mainTblStmt); +/** + * @Description: Whether judge the column is partition column. + * @in rel, A relation. + * @in att_no, Attribute number. + * @return If the the column is partition column, return true, otherwise return false. + */ +extern bool is_partition_column(Relation rel, AttrNumber att_no); +extern Const* GetPartitionValue(List* pos, Form_pg_attribute* attrs, List* value, bool isinterval, bool isPartition); +extern Node* GetTargetValue(Form_pg_attribute attrs, Const* src, bool isinterval); +extern void ATExecEnableDisableRls(Relation rel, RelationRlsStatus changeType, LOCKMODE lockmode); +extern bool isQueryUsingTempRelation(Query *query); +#ifdef ENABLE_MULTIPLE_NODES +extern void create_part_policy_if_needed(CreateStmt *stmt, Oid relOid); +void delete_ts_aux_table(Node* parsetree, const char* query_string); +#endif /* ENABLE_MULTIPLE_NODES */ +extern void addToastTableForNewPartition(Relation relation, Oid newPartId); +extern void fastDropPartition(Relation rel, Oid partOid, const char* stmt, Oid intervalPartOid = InvalidOid); +#endif /* TABLECMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/tablespace.h postgresql-hll-2.14/include/commands/tablespace.h --- postgresql-hll-2.14_old/include/commands/tablespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/tablespace.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,139 @@ +/* ------------------------------------------------------------------------- + * + * tablespace.h + * Tablespace management commands (create/drop tablespace). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TABLESPACE_H +#define TABLESPACE_H + +#include "access/xloginsert.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "storage/dfs/dfs_connector.h" +#include "workload/workload.h" + +/* XLOG stuff */ +#define XLOG_TBLSPC_CREATE 0x00 +#define XLOG_TBLSPC_DROP 0x10 +#define XLOG_TBLSPC_RELATIVE_CREATE 0x20 + +#define TABLESPACE_USAGE_SLOT_NUM 65536U +#define TABLESPACE_BUCKET_CONFLICT_LISTLEN 2 +#define CRITICA_POINT_VALUE 104857600 /* 100 MB */ +#define TABLESPACE_THRESHOLD_RATE 0.9 /* threshold rate */ +#define TABLESPACE_UNLIMITED_STRING "unlimited" +#define PG_LOCATION_DIR "pg_location" + +typedef struct TableSpaceUsageSlot { + uint64 maxSize; + uint64 currentSize; + uint64 thresholdSize; + Oid tableSpaceOid; +} TableSpaceUsageSlot; + +typedef struct TableSpaceUsageBucket { + int count; + slock_t mutex; + TableSpaceUsageSlot spcUsage[TABLESPACE_BUCKET_CONFLICT_LISTLEN]; +} TableSpaceUsageBucket; + +typedef struct TableSpaceUsageStruct { + TableSpaceUsageBucket m_tab[TABLESPACE_USAGE_SLOT_NUM]; +} TableSpaceUsageStruct; + +class TableSpaceUsageManager { +public: + static int ShmemSize(void); + static void Init(void); + static void IsExceedMaxsize(Oid tableSpaceOid, uint64 requestSize); + +private: + static bool IsLimited(Oid tableSpaceOid, uint64* maxSize); + static inline int GetBucketIndex(Oid tableSpaceOid); + static inline void ResetUsageSlot(TableSpaceUsageSlot* info); + static inline void ResetBucket(TableSpaceUsageBucket* bucket); + static inline bool WithinLimit(TableSpaceUsageSlot* slot, uint64 currentSize, uint64 requestSize); + static inline bool IsFull(uint64 maxSize, uint64 currentSize, uint64 requestSize); + static inline uint64 GetThresholdSize(uint64 maxSize, uint64 currentSize); +}; + +typedef struct xl_tblspc_create_rec { + Oid ts_id; + char ts_path[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH STRING */ +} xl_tblspc_create_rec; + +typedef struct xl_tblspc_drop_rec { + Oid ts_id; +} xl_tblspc_drop_rec; + +typedef struct TableSpaceOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ + float8 random_page_cost; + float8 seq_page_cost; + char* filesystem; + char* address; + char* cfgpath; + char* storepath; +} TableSpaceOpts; + +/* This definition is used when storage space is increasing, it includes two main functionalities: + * 1. Check tablespace is exceed the specified size + * 2. Increase the permanent space on users' record + */ +#define STORAGE_SPACE_OPERATION(relation, requestSize) \ + { \ + TableSpaceUsageManager::IsExceedMaxsize(relation->rd_node.spcNode, requestSize); \ + perm_space_increase( \ + relation->rd_rel->relowner, requestSize, RelationUsesSpaceType(relation->rd_rel->relpersistence)); \ + } + +extern void CreateTableSpace(CreateTableSpaceStmt* stmt); +extern void DropTableSpace(DropTableSpaceStmt* stmt); +extern void RenameTableSpace(const char* oldname, const char* newname); +extern void AlterTableSpaceOwner(const char* name, Oid newOwnerId); +extern void AlterTableSpaceOptions(AlterTableSpaceOptionsStmt* stmt); +extern bool IsSpecifiedTblspc(Oid spcOid, const char* specifedTblspc); + +extern void TablespaceCreateDbspace(const RelFileNode rnode, bool isRedo); + +extern Oid GetDefaultTablespace(char relpersistence); +extern DataSpaceType RelationUsesSpaceType(char relpersistence); + +/* + * Get the Specified optioin value. + */ +extern char* GetTablespaceOptionValue(Oid spcNode, const char* optionName); +/* + * Get the all optioin values. + */ +extern List* GetTablespaceOptionValues(Oid spcNode); +/* + * Get the DfsSrvOptions info from pg_tablespace. + */ +extern DfsSrvOptions* GetDfsSrvOptions(Oid spcNode); + +extern void PrepareTempTablespaces(void); + +extern Oid get_tablespace_oid(const char* tablespacename, bool missing_ok); +extern char* get_tablespace_name(Oid spc_oid); + +extern bool directory_is_empty(const char* path); +extern void check_create_dir(char* location); + +extern void tblspc_redo(XLogReaderState* rptr); +extern void tblspc_desc(StringInfo buf, XLogReaderState* record); +extern uint64 pg_cal_tablespace_size_oid(Oid tblspcOid); +extern Oid ConvertToPgclassRelTablespaceOid(Oid tblspc); +extern Oid ConvertToRelfilenodeTblspcOid(Oid tblspc); +extern void xlog_create_tblspc(Oid tsId, char* tsPath, bool isRelativePath); +extern void xlog_drop_tblspc(Oid tsId); + +#endif /* TABLESPACE_H */ diff -uprN postgresql-hll-2.14_old/include/commands/trigger.h postgresql-hll-2.14/include/commands/trigger.h --- postgresql-hll-2.14_old/include/commands/trigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/trigger.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,197 @@ +/* ------------------------------------------------------------------------- + * + * trigger.h + * Declarations for trigger handling. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/trigger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TRIGGER_H +#define TRIGGER_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" + +#define InvalidTgOwnerId ((Oid)(-1)) /* An invalid trigger owner oid, for old version pg_trigger */ + +/* + * TriggerData is the node type that is passed as fmgr "context" info + * when a function is called by the trigger manager. + */ + +#define CALLED_AS_TRIGGER(fcinfo) ((fcinfo)->context != NULL && IsA((fcinfo)->context, TriggerData)) + +typedef uint32 TriggerEvent; + +typedef struct TriggerData { + NodeTag type; + TriggerEvent tg_event; + Relation tg_relation; + HeapTuple tg_trigtuple; + HeapTuple tg_newtuple; + Trigger* tg_trigger; + Buffer tg_trigtuplebuf; + Buffer tg_newtuplebuf; +} TriggerData; + +/* + * TriggerEvent bit flags + * + * Note that we assume different event types (INSERT/DELETE/UPDATE/TRUNCATE) + * can't be OR'd together in a single TriggerEvent. This is unlike the + * situation for pg_trigger rows, so pg_trigger.tgtype uses a different + * representation! + */ +#define TRIGGER_EVENT_INSERT 0x00000000 +#define TRIGGER_EVENT_DELETE 0x00000001 +#define TRIGGER_EVENT_UPDATE 0x00000002 +#define TRIGGER_EVENT_TRUNCATE 0x00000003 +#define TRIGGER_EVENT_OPMASK 0x00000003 + +#define TRIGGER_EVENT_ROW 0x00000004 + +#define TRIGGER_EVENT_BEFORE 0x00000008 +#define TRIGGER_EVENT_AFTER 0x00000000 +#define TRIGGER_EVENT_INSTEAD 0x00000010 +#define TRIGGER_EVENT_TIMINGMASK 0x00000018 + +/* More TriggerEvent flags, used only within trigger.c */ + +#define AFTER_TRIGGER_DEFERRABLE 0x00000020 +#define AFTER_TRIGGER_INITDEFERRED 0x00000040 + +#define TRIGGER_FIRED_BY_INSERT(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_INSERT) + +#define TRIGGER_FIRED_BY_DELETE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_DELETE) + +#define TRIGGER_FIRED_BY_UPDATE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_UPDATE) + +#define TRIGGER_FIRED_BY_TRUNCATE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_TRUNCATE) + +#define TRIGGER_FIRED_FOR_ROW(event) ((event)&TRIGGER_EVENT_ROW) + +#define TRIGGER_FIRED_FOR_STATEMENT(event) (!TRIGGER_FIRED_FOR_ROW(event)) + +#define TRIGGER_FIRED_BEFORE(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_BEFORE) + +#define TRIGGER_FIRED_AFTER(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_AFTER) + +#define TRIGGER_FIRED_INSTEAD(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_INSTEAD) + +/* + * Definitions for replication role based firing. + */ +#define SESSION_REPLICATION_ROLE_ORIGIN 0 +#define SESSION_REPLICATION_ROLE_REPLICA 1 +#define SESSION_REPLICATION_ROLE_LOCAL 2 +extern THR_LOCAL PGDLLIMPORT int SessionReplicationRole; + +/* + * States at which a trigger can be fired. These are the + * possible values for pg_trigger.tgenabled. + */ +#define TRIGGER_FIRES_ON_ORIGIN 'O' +#define TRIGGER_FIRES_ALWAYS 'A' +#define TRIGGER_FIRES_ON_REPLICA 'R' +#define TRIGGER_DISABLED 'D' + +extern Oid CreateTrigger(CreateTrigStmt* stmt, const char* queryString, Oid relOid, Oid refRelOid, Oid constraintOid, + Oid indexOid, bool isInternal); + +extern void RemoveTriggerById(Oid trigOid); +extern Oid get_trigger_oid(Oid relid, const char* name, bool missing_ok); + +extern void renametrig(RenameStmt* stmt); + +extern void EnableDisableTrigger(Relation rel, const char* tgname, char fires_when, bool skip_system); + +extern void RelationBuildTriggers(Relation relation); + +extern TriggerDesc* CopyTriggerDesc(TriggerDesc* trigdesc); + +extern void FreeTriggerDesc(TriggerDesc* trigdesc); + +extern void ExecBSInsertTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASInsertTriggers(EState* estate, ResultRelInfo* relinfo); +extern TupleTableSlot* ExecBRInsertTriggers(EState* estate, ResultRelInfo* relinfo, TupleTableSlot* slot); +extern void ExecARInsertTriggers( + EState* estate, ResultRelInfo* relinfo, Oid insertPartition, int2 bucketid, HeapTuple trigtuple, List* recheckIndexes); +extern TupleTableSlot* ExecIRInsertTriggers(EState* estate, ResultRelInfo* relinfo, TupleTableSlot* slot); +extern void ExecBSDeleteTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASDeleteTriggers(EState* estate, ResultRelInfo* relinfo); +extern bool ExecBRDeleteTriggers(EState* estate, EPQState* epqstate, ResultRelInfo* relinfo, Oid deletePartitionOid, + int2 bucketid, + +#ifdef PGXC + HeapTupleHeader datanode_tuphead, +#endif + ItemPointer tupleid); +extern void ExecARDeleteTriggers(EState* estate, ResultRelInfo* relinfo, Oid deletePartitionOid, int2 bucketid, + +#ifdef PGXC + HeapTupleHeader trigtuphead, +#endif + ItemPointer tupleid); +extern bool ExecIRDeleteTriggers(EState* estate, ResultRelInfo* relinfo, HeapTuple trigtuple); +extern void ExecBSUpdateTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASUpdateTriggers(EState* estate, ResultRelInfo* relinfo); +extern TupleTableSlot* ExecBRUpdateTriggers(EState* estate, EPQState* epqstate, ResultRelInfo* relinfo, + Oid oldPartitionOid, int2 bucketid, +#ifdef PGXC + HeapTupleHeader datanode_tuphead, +#endif + ItemPointer tupleid, TupleTableSlot* slot); +extern void ExecARUpdateTriggers(EState* estate, ResultRelInfo* relinfo, Oid oldPartitionOid, int2 bucketid, Oid newPartitionOid, + ItemPointer tupleid, HeapTuple newtuple, +#ifdef PGXC + HeapTupleHeader trigtuphead, +#endif + List* recheckIndexes); +extern TupleTableSlot* ExecIRUpdateTriggers( + EState* estate, ResultRelInfo* relinfo, HeapTuple trigtuple, TupleTableSlot* slot); +extern void ExecBSTruncateTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASTruncateTriggers(EState* estate, ResultRelInfo* relinfo); + +extern void AfterTriggerBeginXact(void); +extern void AfterTriggerBeginQuery(void); +extern void AfterTriggerEndQuery(EState* estate); +extern void AfterTriggerFireDeferred(void); +extern bool IsAfterTriggerBegin(void); +#ifdef PGXC +extern bool IsAnyAfterTriggerDeferred(void); +#endif +extern void AfterTriggerEndXact(bool isCommit); +extern void AfterTriggerBeginSubXact(void); +extern void AfterTriggerEndSubXact(bool isCommit); +extern void AfterTriggerSetState(ConstraintsSetStmt* stmt); +extern bool AfterTriggerPendingOnRel(Oid relid); + +/* + * in utils/adt/ri_triggers.c + */ +extern bool RI_FKey_keyequal_upd_pk(Trigger* trigger, Relation pk_rel, HeapTuple old_row, HeapTuple new_row); +extern bool RI_FKey_keyequal_upd_fk(Trigger* trigger, Relation fk_rel, HeapTuple old_row, HeapTuple new_row); +extern bool RI_Initial_Check(Trigger* trigger, Relation fk_rel, Relation pk_rel); + +/* result values for RI_FKey_trigger_type: */ +#define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */ +#define RI_TRIGGER_FK 2 /* is a trigger on the FK relation */ +#define RI_TRIGGER_NONE 0 /* is not an RI trigger function */ + +extern int RI_FKey_trigger_type(Oid tgfoid); + +extern Datum pg_trigger_depth(PG_FUNCTION_ARGS); + +#ifdef PGXC +/* Postgres-XC related functions for triggers */ +extern bool pgxc_trig_oldrow_reqd(Relation rel, CmdType commandType); +extern int16 pgxc_get_trigevent(CmdType commandType); +extern bool pgxc_should_exec_br_trigger(Relation rel, int16 trigevent, EState* estate = NULL); +extern bool pgxc_has_trigger_for_event(int16 tg_event, TriggerDesc* trigdesc); +#endif + +#endif /* TRIGGER_H */ diff -uprN postgresql-hll-2.14_old/include/commands/typecmds.h postgresql-hll-2.14/include/commands/typecmds.h --- postgresql-hll-2.14_old/include/commands/typecmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/typecmds.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * typecmds.h + * prototypes for typecmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/typecmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TYPECMDS_H +#define TYPECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "nodes/parsenodes.h" + +#define DEFAULT_TYPDELIM ',' + +extern void DefineType(List* names, List* parameters); +extern void RemoveTypeById(Oid typeOid); +extern void DefineDomain(CreateDomainStmt* stmt); +extern void DefineEnum(CreateEnumStmt* stmt); +extern void DefineRange(CreateRangeStmt* stmt); +extern void AlterEnum(AlterEnumStmt* stmt); +extern Oid DefineCompositeType(RangeVar* typevar, List* coldeflist); +extern Oid AssignTypeArrayOid(void); + +extern void AlterDomainDefault(List* names, Node* defaultRaw); +extern void AlterDomainNotNull(List* names, bool notNull); +extern void AlterDomainAddConstraint(List* names, Node* constr); +extern void AlterDomainValidateConstraint(List* names, char* constrName); +extern void AlterDomainDropConstraint(List* names, const char* constrName, DropBehavior behavior, bool missing_ok); + +extern void checkDomainOwner(HeapTuple tup); + +extern List* GetDomainConstraints(Oid typeOid); + +extern void RenameType(RenameStmt* stmt); +extern void AlterTypeOwner(List* names, Oid newOwnerId, ObjectType objecttype); +extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId, bool hasDependEntry); +extern void AlterTypeNamespace(List* names, const char* newschema, ObjectType objecttype); +extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses* objsMoved); +extern Oid AlterTypeNamespaceInternal( + Oid typeOid, Oid nspOid, bool isImplicitArray, bool errorOnTableType, ObjectAddresses* objsMoved); + +#endif /* TYPECMDS_H */ diff -uprN postgresql-hll-2.14_old/include/commands/user.h postgresql-hll-2.14/include/commands/user.h --- postgresql-hll-2.14_old/include/commands/user.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/user.h 2020-12-12 17:06:43.106346219 +0800 @@ -0,0 +1,96 @@ +/* ------------------------------------------------------------------------- + * + * user.h + * Commands for manipulating roles (formerly called users). + * + * + * src/include/commands/user.h + * + * ------------------------------------------------------------------------- + */ +#ifndef USER_H +#define USER_H + +#include "nodes/parsenodes.h" +#include "utils/timestamp.h" + +/* Hook to check passwords in CreateRole() and AlterRole() */ +#define PASSWORD_TYPE_PLAINTEXT 0 +#define PASSWORD_TYPE_MD5 1 +typedef struct LockInfoBuck { + Oid pid; + Oid relation; + Oid database; + Oid nspoid; +} LockInfoBuck; + +typedef struct AccountLockHashEntry { + Oid roleoid; + int4 failcount; + TimestampTz locktime; + int2 rolstatus; + slock_t mutex; +} AccountLockHashEntry; + +#define PASSWORD_TYPE_SHA256 2 +#define UNLOCK_FLAG -1 + +/* status of the account */ +typedef enum { UNLOCK_STATUS = 0, LOCK_STATUS, SUPERLOCK_STATUS } USER_STATUS; +typedef enum { UNEXPIRED_STATUS = 0, EXPIRED_STATUS } PASSWORD_STATUS; + +typedef void (*check_password_hook_type)( + const char* username, const char* password, int password_type, Datum validuntil_time, bool validuntil_null); + +extern THR_LOCAL PGDLLIMPORT check_password_hook_type check_password_hook; + +extern void CreateRole(CreateRoleStmt* stmt); +extern void AlterRole(AlterRoleStmt* stmt); +extern void AlterRoleSet(AlterRoleSetStmt* stmt); +extern void DropRole(DropRoleStmt* stmt); +extern void GrantRole(GrantRoleStmt* stmt); +extern void RenameRole(const char* oldname, const char* newname); +extern void DropOwnedObjects(DropOwnedStmt* stmt); +extern void ReassignOwnedObjects(ReassignOwnedStmt* stmt); +extern void TryLockAccount(Oid roleID, int extrafails, bool superlock); +extern bool TryUnlockAccount(Oid roleID, bool superunlock, bool isreset); +void TryUnlockAllAccounts(void); +extern USER_STATUS GetAccountLockedStatus(Oid roleID); +extern void DropUserStatus(Oid roleID); +extern Oid GetRoleOid(const char* username); +extern bool IsRoleExist(const char* username); +bool HasModifiedInitPwdByChkAuthHistory(Oid roleID); +void CheckLockPrivilege(Oid roleID, HeapTuple tuple, bool is_opradmin); +extern bool is_role_persistence(Oid roleid); +void CheckAlterAuditadminPrivilege(Oid roleid, bool isOnlyAlterPassword); +extern char* GetRoleName(Oid rolid, char* rolname, size_t size); +extern char* GetSuperUserName(char* username); +extern int decode_iteration(const char* auth_iteration_string); +extern void initSqlCount(); +extern void initWaitCount(Oid userid); +extern PASSWORD_STATUS GetAccountPasswordExpired(Oid roleID); + +void ReportLockAccountMessage(bool locked, const char *rolename); +bool LockAccountParaValid(Oid roleID, int extrafails, bool superlock); +void UpdateFailCountToHashTable(Oid roleid, int extrafails, bool superlock); +bool UnlockAccountToHashTable(Oid roleid, bool superlock, bool isreset); +int64 SearchAllAccounts(); +void InitAccountLockHashTable(); +extern USER_STATUS GetAccountLockedStatusFromHashTable(Oid roleid); +extern void UpdateAccountInfoFromHashTable(); + + +extern inline void str_reset(char* str) +{ + if (str != NULL) { + memset(str, 0, strlen(str)); + } + + return; +} + +#ifdef PGXC +extern void PreCleanAndCheckUserConns(const char* username, bool missing_ok); +#endif /* PGXC */ + +#endif /* USER_H */ diff -uprN postgresql-hll-2.14_old/include/commands/vacuum.h postgresql-hll-2.14/include/commands/vacuum.h --- postgresql-hll-2.14_old/include/commands/vacuum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/vacuum.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,431 @@ +/* ------------------------------------------------------------------------- + * + * vacuum.h + * header file for postgres vacuum cleaner and statistics analyzer + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/vacuum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VACUUM_H +#define VACUUM_H +#include "dfsdesc.h" +#include "access/htup.h" +#include "catalog/pg_partition_fn.h" +#include "catalog/pg_statistic.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "storage/buf.h" +#include "storage/cu.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +typedef enum DELETE_STATS_OPTION { + DELETE_STATS_NONE = 0x00u, + DELETE_STATS_SINGLE = 0x01u, + DELETE_STATS_MULTI = 0x02u, + DELETE_STATS_ALL = 0x03u, +} DELETE_STATS_OPTION; + +/* ---------- + * ANALYZE builds one of these structs for each attribute (column) that is + * to be analyzed. The struct and subsidiary data are in anl_context, + * so they live until the end of the ANALYZE operation. + * + * The type-specific typanalyze function is passed a pointer to this struct + * and must return TRUE to continue analysis, FALSE to skip analysis of this + * column. In the TRUE case it must set the compute_stats and minrows fields, + * and can optionally set extra_data to pass additional info to compute_stats. + * minrows is its request for the minimum number of sample rows to be gathered + * (but note this request might not be honored, eg if there are fewer rows + * than that in the table). + * + * The compute_stats routine will be called after sample rows have been + * gathered. Aside from this struct, it is passed: + * fetchfunc: a function for accessing the column values from the + * sample rows + * samplerows: the number of sample tuples + * totalrows: estimated total number of rows in relation + * The fetchfunc may be called with rownum running from 0 to samplerows-1. + * It returns a Datum and an isNull flag. + * + * compute_stats should set stats_valid TRUE if it is able to compute + * any useful statistics. If it does, the remainder of the struct holds + * the information to be stored in a pg_statistic row for the column. Be + * careful to allocate any pointed-to data in anl_context, which will NOT + * be CurrentMemoryContext when compute_stats is called. + * + * Note: for the moment, all comparisons done for statistical purposes + * should use the database's default collation (DEFAULT_COLLATION_OID). + * This might change in some future release. + * ---------- + */ +typedef struct VacAttrStats* VacAttrStatsP; + +typedef Datum (*AnalyzeAttrFetchFunc)(VacAttrStatsP stats, int rownum, bool* isNull, Relation rel); + +typedef void (*AnalyzeAttrComputeStatsFunc)( + VacAttrStatsP stats, AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows, Relation rel); + +typedef struct VacAttrStats { + /* + * These fields are set up by the main ANALYZE code before invoking the + * type-specific typanalyze function. + * + * Note: do not assume that the data being analyzed has the same datatype + * shown in attr, ie do not trust attr->atttypid, attlen, etc. This is + * because some index opclasses store a different type than the underlying + * column/expression. Instead use attrtypid, attrtypmod, and attrtype for + * information about the datatype being fed to the typanalyze function. + */ + unsigned int num_attrs; + Form_pg_attribute* attrs; /* copy of pg_attribute row for columns */ + Oid* attrtypid; /* type of data being analyzed */ + int32* attrtypmod; /* typmod of data being analyzed */ + Form_pg_type* attrtype; /* copy of pg_type row for attrtypid */ + MemoryContext anl_context; /* where to save long-lived data */ + + /* + * These fields must be filled in by the typanalyze routine, unless it + * returns FALSE. + */ + AnalyzeAttrComputeStatsFunc compute_stats; /* function pointer */ + int minrows; /* Minimum # of rows wanted for stats */ + void* extra_data; /* for extra type-specific data */ + + /* + * These fields are to be filled in by the compute_stats routine. (They + * are initialized to zero when the struct is created.) + */ + bool stats_valid; + float4 stanullfrac; /* fraction of entries that are NULL */ + int4 stawidth; /* average width of column values */ + float4 stadistinct; /* # distinct values */ + float4 stadndistinct; /* # distinct value of dn1*/ + int2 stakind[STATISTIC_NUM_SLOTS]; + Oid staop[STATISTIC_NUM_SLOTS]; + int numnumbers[STATISTIC_NUM_SLOTS]; + float4* stanumbers[STATISTIC_NUM_SLOTS]; + int numvalues[STATISTIC_NUM_SLOTS]; + Datum* stavalues[STATISTIC_NUM_SLOTS]; + bool* stanulls[STATISTIC_NUM_SLOTS]; + + /* + * These fields describe the stavalues[n] element types. They will be + * initialized to match attrtypid, but a custom typanalyze function might + * want to store an array of something other than the analyzed column's + * elements. It should then overwrite these fields. + */ + Oid statypid[STATISTIC_NUM_SLOTS]; + int2 statyplen[STATISTIC_NUM_SLOTS]; + bool statypbyval[STATISTIC_NUM_SLOTS]; + char statypalign[STATISTIC_NUM_SLOTS]; + + /* + * These fields are private to the main ANALYZE code and should not be + * looked at by type-specific functions. + */ + int tupattnum; /* attribute number within tuples */ + HeapTuple* rows; /* access info for std fetch function */ + TupleDesc tupDesc; + Datum* exprvals; /* access info for index fetch function */ + bool* exprnulls; + int rowstride; +} VacAttrStats; + +/* + * flags for vacuum object + */ +typedef enum VacuumFlags { + VACFLG_SIMPLE_HEAP = 1 << 0, /* simple heap */ + VACFLG_SIMPLE_BTREE = 1 << 1, /* no use, btree index on simple heap */ + VACFLG_MAIN_PARTITION = 1 << 2, /* partitioned table */ + VACFLG_MAIN_PARTITION_BTREE = 1 << 3, /* no use, btree index on partitioned table */ + VACFLG_SUB_PARTITION = 1 << 4, /* table partition */ + VACFLG_SUB_PARTITION_BTREE = 1 << 5, /* no use, btree index on table partition */ + VACFLG_TOAST = 1 << 6, /* no use*/ + VACFLG_TOAST_BTREE = 1 << 7 /* no use*/ +} VacuumFlags; + +typedef struct vacuum_object { + Oid tab_oid; /* object id for a table, index or a partition */ + Oid parent_oid; /* parent object id if it's a partition */ + + /* + * we ues following flag to skip some check + * 1. for partitioned table , we vacuum all the partitiones when we + * vacuum partitioned so we just skip check all partiitons + * 2. for main table, we vaccum toast table when we vacuum main table + */ + bool dovacuum; + bool dovacuum_toast; /* flags for vacuum toast table, do vacuum on toast if true */ + bool doanalyze; + bool need_freeze; /* flag to freeze old tuple for recycle clog */ + bool is_internal_relation; /* flag to mark if it is an internal relation */ + bool is_tsdb_deltamerge; /* flag to mark if it is a tsdb deltamerge task */ + int flags; /* flags for vacuum object */ +} vacuum_object; + +/* + * This struct is used to store the partitioned table's information in pg_class, + * after the VACUUM or ANALYZE, update pg_class with it. + */ +typedef struct UpdatePartitionedTableData { + Oid tabOid; /* partitioned table's oid */ + BlockNumber pages; /* all blocks, including all its partitions */ + double tuples; /* all tuples, including all its partitions */ + BlockNumber allVisiblePages; /* all visible pages */ + bool hasIndex; /* true, iff table has index */ + TransactionId frozenXid; /* frozen Xid */ +} UpdatePartitionedTableData; + +/* Identify create temp table for attribute or table. */ +typedef enum { TempSmpleTblType_Table, TempSmpleTblType_Attrbute } TempSmpleTblType; + +/* The stage for datanode send sample to coordinator under debugging. */ +typedef enum { DebugStage_Begin, DebugStage_Execute, DebugStage_End } AnalyzeTempTblDebugStage; + +/* Each sample of distinct value. */ +typedef struct { + Datum value; /* a sample value */ + int64 count; /* how many duplicate values */ +} SampleItem; + +/* Mcv list for compute statistic.*/ +typedef struct { + int stattarget; /* how many most common values we should save. */ + int64 rows_mcv; /* sum of rows of all the most common values */ + int num_mcv; /* num of mcv for the current saved */ +} McvInfo; + +/* Histgram list for compute statistic.*/ +typedef struct { + bool is_last_value; /* indentify the value is the last value. */ + int stattarget; /* how many histgrams we should save. */ + int num_hist; /* num of histgram for the current saved. */ + int64 rows_hist; /* sum of rows of all the histgrams. */ + int64 bucketSize; /* the step length for histogram bound. */ + int64 sum_count; /* sum of the count for saved histogram value. */ + int64 cur_mcv_idx; + int64 start_value_count; /* how many duplicate values */ + Datum start_value; /* a sample value */ + SampleItem* histitem; /* item of histgram */ +} HistgramInfo; + +/* The sample info of special attribute for compute statistic */ +typedef struct { + bool is_varwidth; /* the width of attribute is variable-length type or not. */ + double totalrows; /* total rows for the table. */ + int64 samplerows; /* how many sample rows for the table. */ + double ndistinct; /* # distinct values */ + int64 nmultiple; /* duplicate num of distinct values more than 1. */ + int64 null_cnt; /* count of null value */ + int64 nonnull_cnt; /* count of non-null values for all samples. */ + McvInfo mcv_list; /* mcv list for compute stats.*/ + HistgramInfo hist_list; /* histgram list for compute stats.*/ + char** v_alias; /* alias for column v in temp table. */ + VacAttrStats* stats; /* the statistics of attribute for update to pg_staitsitc. */ +} AnalyzeSampleTableSpecInfo; + +/* + * data and functions for delta merge + */ +typedef struct { + StringInfo row_count_sql; + StringInfo merge_sql; + StringInfo vacuum_sql; + uint64 max_row; + + /* original info */ + Oid oid; + StringInfo relname; + StringInfo schemaname; + bool is_hdfs; + +} MergeInfo; + +#define vacuumRelation(flag) (((flag)&VACFLG_SIMPLE_HEAP) == VACFLG_SIMPLE_HEAP) + +#define vacuumMainPartition(flag) (((flag)&VACFLG_MAIN_PARTITION) == VACFLG_MAIN_PARTITION) + +#define vacuumPartition(flag) (((flag)&VACFLG_SUB_PARTITION) == VACFLG_SUB_PARTITION) + +#define hdfsVcuumAction(flag) (((flag)&VACOPT_HDFSDIRECTORY) || ((flag)&VACOPT_COMPACT) || ((flag)&VACOPT_MERGE)) + +/* We need estimate total rows on datanode only sample rate is -1. */ +#define NEED_EST_TOTAL_ROWS_DN(vacstmt) \ + (IS_PGXC_DATANODE && IsConnFromCoord() && (vacstmt)->pstGlobalStatEx[(vacstmt)->tableidx].sampleRate < 0) + +/* + * remote analyze user-defined table + * 1. for system catalog, do local analyze + * 2. for user-define table, local coordinator broadcast statistics + */ +#define udtRemoteAnalyze(relid) (FirstNormalObjectId < (relid) && IS_PGXC_COORDINATOR && IsConnFromCoord()) + +typedef bool (*EqualFunc)(const void*, const void*); + +/* GUC parameters */ +extern THR_LOCAL PGDLLIMPORT int default_statistics_target; /* PGDLLIMPORT for + * PostGIS */ + +#define DEBUG_START_TIMER \ + struct timeval stStartTime; \ + struct timeval stStopTime; \ + double dTotalElapsTime; \ + if (log_min_messages <= DEBUG1) { \ + (void)gettimeofday(&stStartTime, NULL); \ + dTotalElapsTime = 0; \ + } + +#define DEBUG_RESET_TIMER \ + do { \ + dTotalElapsTime = 0; \ + if (log_min_messages <= DEBUG1) \ + (void)gettimeofday(&stStartTime, NULL); \ + } while (0) + +#define DEBUG_STOP_TIMER(fmt, ...) \ + do { \ + if (log_min_messages <= DEBUG1) { \ + StringInfoData str1; \ + initStringInfo(&str1); \ + (void)gettimeofday(&stStopTime, NULL); \ + dTotalElapsTime = \ + (stStopTime.tv_sec - stStartTime.tv_sec) + (stStopTime.tv_usec - stStartTime.tv_usec) * 0.000001; \ + appendStringInfo(&str1, fmt, ##__VA_ARGS__); \ + elog(DEBUG1, \ + "%s for queryid[%lu]: %s --- elapse time: [%9.3lfs] \n", \ + g_instance.attr.attr_common.PGXCNodeName, \ + u_sess->debug_query_id, \ + str1.data, \ + dTotalElapsTime); \ + pfree(str1.data); \ + } \ + } while (0) + +#define allow_debug(MOD) (log_min_messages <= DEBUG2 && module_logging_is_on(MOD)) + +#define DEBUG_MOD_START_TIMER(MOD) \ + struct timeval stStartTime; \ + double dTotalElapsTime; \ + if (allow_debug(MOD)) { \ + (void)gettimeofday(&stStartTime, NULL); \ + dTotalElapsTime = 0; \ + } + +#define DEBUG_MOD_STOP_TIMER(MOD, fmt, ...) \ + do { \ + if (allow_debug(MOD)) { \ + StringInfoData str1; \ + initStringInfo(&str1); \ + struct timeval stStopTime; \ + (void)gettimeofday(&stStopTime, NULL); \ + dTotalElapsTime = \ + (stStopTime.tv_sec - stStartTime.tv_sec) + (stStopTime.tv_usec - stStartTime.tv_usec) * 0.000001; \ + appendStringInfo(&str1, fmt, ##__VA_ARGS__); \ + ereport(DEBUG2, \ + (errmodule(MOD), \ + errmsg("%s for queryid[%lu]: %s --- elapse time: [%9.6lfs] \n", \ + g_instance.attr.attr_common.PGXCNodeName, \ + u_sess->debug_query_id, \ + str1.data, \ + dTotalElapsTime))); \ + dTotalElapsTime = 0; \ + (void)gettimeofday(&stStartTime, NULL); \ + pfree(str1.data); \ + } \ + } while (0) + +/* Time elapse stats end */ + +/* in commands/vacuum.c */ +extern void vacuum(VacuumStmt* vacstmt, Oid relid, bool do_toast, BufferAccessStrategy bstrategy, bool isTopLevel); +extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int* nindexes, Relation** Irel); +extern void vac_close_indexes(int nindexes, Relation* Irel, LOCKMODE lockmode); +extern double vac_estimate_reltuples( + Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples); +extern void vac_update_relstats(Relation relation, Relation classRel, RelPageType num_pages, double num_tuples, + BlockNumber num_all_visible_pages, bool hasindex, TransactionId frozenxid); +extern void vacuum_set_xid_limits(Relation rel, int64 freeze_min_age, int64 freeze_table_age, TransactionId* oldestXmin, + TransactionId* freezeLimit, TransactionId* freezeTableLimit); +extern void vac_update_datfrozenxid(void); +extern void vacuum_delay_point(void); + +/* in commands/vacuumlazy.c */ +extern void lazy_vacuum_rel(Relation onerel, VacuumStmt* vacstmt, BufferAccessStrategy bstrategy); + +/* in commands/analyze.c */ +extern void analyze_rel(Oid relid, VacuumStmt* vacstmt, BufferAccessStrategy bstrategy); +extern char* buildTempSampleTable(Oid relid, Oid mian_relid, TempSmpleTblType type, + AnalyzeMode analyzemode = ANALYZENORMAL, bool inh = false, VacuumStmt* vacstmt = NULL, + AnalyzeSampleTableSpecInfo* spec = NULL); +extern void dropSampleTable(const char* tableName); +extern const char* get_sample_tblname(AnalyzeMode analyzemode, List* tmpSampleTblNameList); +extern VacAttrStats* examine_attribute(Relation onerel, Bitmapset* bms_attnums, bool isLog); +extern void update_attstats( + Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats, char relpersistence); +extern void update_attstats(Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats); +/* we should delete all records in pg_statistic when the data is dirty and current totalrows is null. */ +extern void delete_attstats(Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats, + unsigned int delete_stats_option = DELETE_STATS_SINGLE); + +/* get one relation by relid before do analyze */ +extern Relation analyze_get_relation(Oid relid, VacuumStmt* vacstmt); +extern bool std_typanalyze(VacAttrStats* stats); +extern double anl_random_fract(void); +extern double anl_init_selection_state(int n); +extern double anl_get_next_S(double t, int n, double* stateptr); +extern int compute_sample_size( + VacuumStmt* vacstmt, int num_samples, bool** require_samp, Oid relid = 0, int tableidx = 0); +extern void set_complex_sample(VacuumStmt* pStmt); +extern void delete_attstats_replication(Oid relid, VacuumStmt* stmt); +extern int compute_attr_target(Form_pg_attribute attr); + +extern void vac_update_partstats(Partition part, BlockNumber num_pages, double num_tuples, + BlockNumber num_all_visible_pages, TransactionId frozenxid); +extern void vac_open_part_indexes(VacuumStmt* vacstmt, LOCKMODE lockmode, int* nindexes, int* nindexesGlobal, + Relation** Irel, Relation** indexrel, Partition** indexpart); +extern void vac_close_part_indexes( + int nindexes, int nindexesGlobal, Relation* Irel, Relation* indexrel, Partition* indexpart, LOCKMODE lockmode); +extern void vac_update_pgclass_partitioned_table(Relation partitionRel, bool hasIndex, TransactionId newFrozenXid); + +extern void CStoreVacUpdateNormalRelStats(Oid relid, TransactionId frozenxid, Relation pgclassRel); +extern void CStoreVacUpdatePartitionRelStats(Relation partitionRel, TransactionId newFrozenXid); +extern void CStoreVacUpdatePartitionStats(Oid relid, TransactionId frozenxid); +extern void CalculatePartitionedRelStats(_in_ Relation partitionRel, _in_ Relation pgPartitionRel, + _out_ BlockNumber* totalPages, _out_ BlockNumber* totalVisiblePages, _out_ double* totalTuples, + _out_ TransactionId* minFrozenXid); + +extern bool IsToastRelationbyOid(Oid relid); +extern Oid pg_toast_get_baseid(Oid relOid, bool* isPartToast); +extern void elogVacuumInfo(Relation rel, HeapTuple tuple, char* funcName, TransactionId oldestxmin); + +typedef Datum (*GetValFunc[2])(CU* cuPtr, int rowIdx); +extern void InitGetValFunc(int attlen, GetValFunc* getValFuncPtr, int col); + +extern void DfsVacuumFull(Oid relid, VacuumStmt* vacstmt); +extern void RemoveGarbageFiles(Relation rel, DFSDescHandler* handler); + +extern bool equal_string(const void* _str1, const void* _str2); +extern List* GetDifference(const List* list1, const List* list2, EqualFunc fn); + +extern void merge_one_relation(void* _info); +extern void merge_cu_relation(void* info, VacuumStmt* stmt); + +extern List* get_rel_oids(Oid relid, VacuumStmt* vacstmt); + +extern char* get_nsp_relname(Oid relid); + +// obs foreign table options totalrows +extern void updateTotalRows(Oid relid, double n); + +extern void analyze_concurrency_process(Oid relid, int16 attnum, MemoryContext oldcontext, const char* funcname); + +extern int GetOneTupleSize(VacuumStmt* stmt, Relation rel); + +#endif /* VACUUM_H */ diff -uprN postgresql-hll-2.14_old/include/commands/variable.h postgresql-hll-2.14/include/commands/variable.h --- postgresql-hll-2.14_old/include/commands/variable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/variable.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,41 @@ +/* + * variable.h + * Routines for handling specialized SET variables. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/variable.h + */ +#ifndef VARIABLE_H +#define VARIABLE_H + +#include "utils/guc.h" + +extern bool check_datestyle(char** newval, void** extra, GucSource source); +extern void assign_datestyle(const char* newval, void* extra); +extern bool check_timezone(char** newval, void** extra, GucSource source); +extern void assign_timezone(const char* newval, void* extra); +extern const char* show_timezone(void); +extern bool check_log_timezone(char** newval, void** extra, GucSource source); +extern void assign_log_timezone(const char* newval, void* extra); +extern const char* show_log_timezone(void); +extern bool check_transaction_read_only(bool* newval, void** extra, GucSource source); +extern bool check_default_transaction_read_only(bool* newval, void** extra, GucSource source); +extern bool check_XactIsoLevel(char** newval, void** extra, GucSource source); +extern void assign_XactIsoLevel(const char* newval, void* extra); +extern const char* show_XactIsoLevel(void); +extern bool check_transaction_deferrable(bool* newval, void** extra, GucSource source); +extern bool check_random_seed(double* newval, void** extra, GucSource source); +extern void assign_random_seed(double newval, void* extra); +extern const char* show_random_seed(void); +extern bool check_client_encoding(char** newval, void** extra, GucSource source); +extern void assign_client_encoding(const char* newval, void* extra); +extern bool check_mix_replication_param(bool* newval, void** extra, GucSource source); +extern bool check_session_authorization(char** newval, void** extra, GucSource source); +extern void assign_session_authorization(const char* newval, void* extra); +extern bool check_role(char** newval, void** extra, GucSource source); +extern void assign_role(const char* newval, void* extra); +extern const char* show_role(void); + +#endif /* VARIABLE_H */ diff -uprN postgresql-hll-2.14_old/include/commands/verify.h postgresql-hll-2.14/include/commands/verify.h --- postgresql-hll-2.14_old/include/commands/verify.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/verify.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,56 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * verify.h + * header file for anlayse verify commands to check the datafile. + * + * + * IDENTIFICATION + * src/include/commands/verify.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VERIFY_H +#define VERIFY_H + +#include "pgxc/pgxcnode.h" +#include "tcop/tcopprot.h" +#include "dfsdesc.h" +#include "access/htup.h" +#include "catalog/pg_authid.h" +#include "catalog/pg_auth_members.h" +#include "catalog/namespace.h" +#include "catalog/pg_database.h" +#include "catalog/pg_namespace.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_partition_fn.h" +#include "catalog/pg_statistic.h" +#include "catalog/pg_user_status.h" +#include "catalog/pg_tablespace.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/cu.h" +#include "storage/lock.h" +#include "storage/remote_read.h" +#include "utils/relcache.h" + +extern void DoGlobalVerifyMppTable(VacuumStmt* stmt, const char* queryString, bool sentToRemote); +extern void DoGlobalVerifyDatabase(VacuumStmt* stmt, const char* queryString, bool sentToRemote); +extern void DoVerifyTableOtherNode(VacuumStmt* stmt, bool sentToRemote); +extern void VerifyAbortBufferIO(void); + +#endif /* VERIFY_H */ diff -uprN postgresql-hll-2.14_old/include/commands/view.h postgresql-hll-2.14/include/commands/view.h --- postgresql-hll-2.14_old/include/commands/view.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/commands/view.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * view.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/view.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VIEW_H +#define VIEW_H + +#include "nodes/parsenodes.h" + +extern Oid DefineView(ViewStmt* stmt, const char* queryString, bool send_remote = true, bool isFirstNode = true); +extern bool IsViewTemp(ViewStmt* stmt, const char* queryString); +extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace); + +#endif /* VIEW_H */ diff -uprN postgresql-hll-2.14_old/include/common/build_query/build_query.h postgresql-hll-2.14/include/common/build_query/build_query.h --- postgresql-hll-2.14_old/include/common/build_query/build_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/common/build_query/build_query.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * build_query.h + * interfaces used by cm_ctl and gs_ctl to display build progress + * + * Portions Copyright (c) 2012-2015, Huawei Tech. Co., Ltd. + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/common/build_query/build_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BUILD_QUERY_H +#define BUILD_QUERY_H + +#include "c.h" +#include "replication/replicainternal.h" + +#define KB_PER_MB (1024) +#define KB_PER_GB (1024 * 1024) +#define KB_PER_TB (1024 * 1024 * 1024) + +#define S_PER_MIN 60 +#define S_PER_H (60 * 60) + +#define REPORT_TIMEOUT 30 /* report and calculate sync speed every 30s */ +#define CACULATE_MIN_TIME 2 /* calculate sync speed at least every 2s */ + +extern char* show_estimated_time(int time); +extern char* show_datasize(uint64 size); +extern void UpdateDBStateFile(char* path, GaussState* state); + +#endif diff -uprN postgresql-hll-2.14_old/include/common/config/cm_config.h postgresql-hll-2.14/include/common/config/cm_config.h --- postgresql-hll-2.14_old/include/common/config/cm_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/common/config/cm_config.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,416 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_config.h + * + * + * + * IDENTIFICATION + * src/include/common/config/cm_config.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_CONFIG_H +#define CM_CONFIG_H + +#include "c.h" + +#define CM_NODE_NAME 65 +#define CM_AZ_NAME 65 +#define CM_QUORUM_NAME 65 +#define CM_LOGIC_CLUSTER_NAME_LEN 64 +#define LOGIC_CLUSTER_NUMBER (32 + 1) // max 32 logic + 1 elastic group +#define MAX_PATH_LEN 1024 +#define CM_IP_NUM 3 +#define GTM_IP_PORT 64 +#define CM_IP_LENGTH 128 +#define CM_IP_ALL_NUM_LENGTH (CM_IP_NUM * CM_IP_LENGTH) +#define CM_PATH_LENGTH 1024 +#define CM_NODE_MAXNUM 1024 +#define CM_MAX_DATANODE_PER_NODE 160 +#define CM_MAX_INSTANCE_PER_NODE 192 +#define INVALID_NODE_NUM (CM_NODE_MAXNUM + 1) +#define INVALID_INSTACNE_NUM (0xFFFFFFFF) +#define CM_MAX_INSTANCE_GROUP_NUM (CM_NODE_MAXNUM * CM_MAX_INSTANCE_PER_NODE) +#define AGLINMENT_SIZE (1024 * 8) +#define CM_MAX_COMMAND_LEN 1024 +#define CM_MAX_COMMAND_LONG_LEN 2048 +#define CONNSTR_LEN 256 + +// A logic datanode number in a node, The logic datanode can be include the primary, standby and dummystandby DN. +#define LOGIC_DN_PER_NODE 32 +#define MAX_LOGIC_DATANODE (CM_NODE_MAXNUM * LOGIC_DN_PER_NODE) + +#define CM_PRIMARY_STANDBY_NUM (8) // supprot one primary and multi standby +#define CM_MAX_CMSERVER_STANDBY_NUM (7) +#define CM_MAX_DATANODE_STANDBY_NUM 7 +#define CM_MAX_GTM_STANDBY_NUM (7) +#define MAX_CN_NUM 256 +#define CM_MAX_SQL_COMMAND_LEN 2048 + +#define HAVE_GTM 1 +#define NONE_GTM 0 +#define PRIMARY_GTM 0 +#define STANDBY_GTM 1 + +// consist with OM +#define PRIMARY_DN 0 +#define STANDBY_DN 1 +#define DUMMY_STANDBY_DN 2 + +#define CM_DATANODE 1 +#define CM_COORDINATENODE 2 +#define CM_GTM 3 + +#define CM_AGENT 7 +#define CM_CTL 8 +#define CM_SERVER 9 + +#define GROUP_NAME_VERSION1 "group_version1" +#define GROUP_NAME_VERSION2 "group_version2" + +#define OPEN_FILE_ERROR -1 +#define OUT_OF_MEMORY -2 +#define READ_FILE_ERROR -3 + +#define CLUSTER_STATUS_QUERY 0 +#define CLUSTER_DETAIL_STATUS_QUERY 1 +#define CLUSTER_COUPLE_STATUS_QUERY 2 +#define CLUSTER_COUPLE_DETAIL_STATUS_QUERY 3 +#define CLUSTER_BALANCE_COUPLE_DETAIL_STATUS_QUERY 4 +#define CLUSTER_LOGIC_COUPLE_DETAIL_STATUS_QUERY 5 +#define CLUSTER_PARALLEL_REDO_REPLAY_STATUS_QUERY 6 +#define CLUSTER_PARALLEL_REDO_REPLAY_DETAIL_STATUS_QUERY 7 +#define CLUSTER_ABNORMAL_COUPLE_DETAIL_STATUS_QUERY 8 +#define CLUSTER_ABNORMAL_BALANCE_COUPLE_DETAIL_STATUS_QUERY 9 +#define CLUSTER_START_STATUS_QUERY 10 + +#define DYNAMC_CONFIG_FILE "cluster_dynamic_config" + +#define PROCESS_UNKNOWN -1 +#define PROCESS_NOT_EXIST 0 +#define PROCESS_CORPSE 1 +#define PROCESS_RUNNING 2 +#define PROCESS_PHONY_DEAD_T 3 +#define PROCESS_PHONY_DEAD_D 4 +#define PROCESS_PHONY_DEAD_Z 5 +/***/ +#define PROCESS_WAIT_STOP 3 +#define PROCESS_WAIT_START 4 + +#define PROCESS_ETCD 0 +#define PROCESS_CMSERVER 1 + +#define QUERY_STATUS_CMSERVER_STEP 0 +#define QUERY_STATUS_CMSERVER_SETP_ACK 1 +#define QUERY_STATUS_CMAGENT_STEP 2 +#define QUERY_STATUS_CMAGENT_STEP_ACK 3 + +#define AZ_START_STOP_INTERVEL 2 +#define AZ_STOP_DELAY 2 + +#define ETCD_KEY_LENGTH 1024 +#define ETCD_VLAUE_LENGTH 1024 + +/* az_Priorities, only init the values when load config file */ +const uint32 g_az_invalid = 0; +extern uint32 g_az_master; +extern uint32 g_az_slave; +extern uint32 g_az_arbiter; + +typedef enum AZRole { AZMaster, AZSlave, AZArbiter } AZRole; + +typedef struct az_role_string { + const char* role_string; + uint32 role_val; +} az_role_string; + +typedef enum cmServerLevel { + CM_SERVER_NONE = 0, // no cm_server + CM_SERVER_LEVEL_1 = 1 +} cmServerLevel; + +typedef struct staticConfigHeader { + uint32 crc; + uint32 len; + uint32 version; + int64 time; + uint32 nodeCount; + uint32 node; +} staticConfigHeader; + +typedef struct peerDatanodeInfo { + char datanodePeerDataPath[CM_PATH_LENGTH]; + uint32 datanodePeerHAListenCount; + char datanodePeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeerHAPort; + uint32 datanodePeerRole; +} peerDatanodeInfo; + +typedef struct dataNodeInfo { + uint32 datanodeId; + uint32 datanodeMirrorId; + char datanodeLocalDataPath[CM_PATH_LENGTH]; + char datanodeXlogPath[CM_PATH_LENGTH]; + char datanodeSSDDataPath[CM_PATH_LENGTH]; + uint32 datanodeListenCount; + char datanodeListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePort; + + uint32 datanodeRole; + + uint32 datanodeLocalHAListenCount; + char datanodeLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodeLocalHAPort; + + char datanodePeerDataPath[CM_PATH_LENGTH]; + uint32 datanodePeerHAListenCount; + char datanodePeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeerHAPort; + uint32 datanodePeerRole; + + char datanodePeer2DataPath[CM_PATH_LENGTH]; + uint32 datanodePeer2HAListenCount; + char datanodePeer2HAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeer2HAPort; + uint32 datanodePeer2Role; + + char LogicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + + // multi available zone: single primary and multi standby datanodes + peerDatanodeInfo peerDatanodes[CM_MAX_DATANODE_STANDBY_NUM]; +} dataNodeInfo; + +typedef struct peerCmServerInfo { + uint32 cmServerPeerHAListenCount; + char cmServerPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerPeerHAPort; +} peerCmServerInfo; + +typedef struct peerGtmInfo { + uint32 gtmPeerHAListenCount; + char gtmPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmPeerHAPort; +} peerGtmInfo; + +typedef struct staticNodeConfig { + uint32 crc; + + char azName[CM_AZ_NAME]; + uint32 azPriority; + + uint32 node; + char nodeName[CM_NODE_NAME]; + + uint32 sshCount; + char sshChannel[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 backIpCount; + char backIps[CM_IP_NUM][CM_IP_LENGTH]; + + /**/ + uint32 cmServerId; + uint32 cmServerMirrorId; + char cmDataPath[CM_PATH_LENGTH]; + uint32 cmServerLevel; + char cmServerFloatIP[CM_IP_LENGTH]; + + uint32 cmServerListenCount; + char cmServer[CM_IP_NUM][CM_IP_LENGTH]; + uint32 port; + /**/ + uint32 cmServerLocalHAListenCount; + char cmServerLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerLocalHAPort; + + int32 cmServerRole; + /**/ + uint32 cmServerPeerHAListenCount; + char cmServerPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerPeerHAPort; + + peerCmServerInfo peerCmServers[CM_MAX_CMSERVER_STANDBY_NUM]; + + /**/ + uint32 gtmAgentId; + uint32 cmAgentMirrorId; + uint32 cmAgentListenCount; + char cmAgentIP[CM_IP_NUM][CM_IP_LENGTH]; + + /**/ + uint32 gtmId; + uint32 gtmMirrorId; + uint32 gtm; + char gtmLocalDataPath[CM_PATH_LENGTH]; + uint32 gtmLocalListenCount; + char gtmLocalListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmLocalport; + + uint32 gtmRole; + + uint32 gtmLocalHAListenCount; + char gtmLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmLocalHAPort; + + char gtmPeerDataPath[CM_PATH_LENGTH]; + uint32 gtmPeerHAListenCount; + char gtmPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmPeerHAPort; + + peerGtmInfo peerGtms[CM_MAX_CMSERVER_STANDBY_NUM]; + + /*****/ + uint32 gtmProxyId; + uint32 gtmProxyMirrorId; + uint32 gtmProxy; + uint32 gtmProxyListenCount; + char gtmProxyListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmProxyPort; + + /*****/ + uint32 coordinateId; + uint32 coordinateMirrorId; + uint32 coordinate; + char DataPath[CM_PATH_LENGTH]; + char SSDDataPath[CM_PATH_LENGTH]; + uint32 coordinateListenCount; + char coordinateListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 coordinatePort; + uint32 coordinateHAPort; + + /*****/ + uint32 datanodeCount; + dataNodeInfo datanode[CM_MAX_DATANODE_PER_NODE]; + + uint32 etcd; + uint32 etcdId; + uint32 etcdMirrorId; + char etcdName[CM_NODE_NAME]; + char etcdDataPath[CM_PATH_LENGTH]; + uint32 etcdClientListenIPCount; + char etcdClientListenIPs[CM_IP_NUM][CM_IP_LENGTH]; + uint32 etcdClientListenPort; + uint32 etcdHAListenIPCount; + char etcdHAListenIPs[CM_IP_NUM][CM_IP_LENGTH]; + uint32 etcdHAListenPort; + + uint32 sctpBeginPort; + uint32 sctpEndPort; + +} staticNodeConfig; + +typedef struct dynamicConfigHeader { + uint32 crc; + uint32 len; + uint32 version; + int64 time; + uint32 nodeCount; /* physicalNodeNum,same as staic config file head. */ + uint32 relationCount; + uint32 term; +} dynamicConfigHeader; + +typedef struct dynamic_cms_timeline { + long int timeline; // Record current time at the CMS instance is upgraded to the primary instance. +} dynamic_cms_timeline; + +typedef struct dynamicRelationConfig { + uint32 crc; + uint32 currentPrimary; + uint32 node[CM_PRIMARY_STANDBY_NUM]; + char dataPath[CM_PRIMARY_STANDBY_NUM][CM_PATH_LENGTH]; +} dynamicRelationConfig; + +typedef struct staticLogicNodeConfig { + + uint32 crc; + uint32 node; + char nodeName[CM_NODE_NAME]; + + uint32 sshCount; + char sshChannel[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 backIpCount; + char backIps[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 sctpBeginPort; + uint32 sctpEndPort; + + uint32 datanodeCount; + uint32 datanodeId[CM_MAX_DATANODE_PER_NODE]; +} staticLogicNodeConfig; + +typedef struct logicClusterStaticConfig { + char LogicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + uint32 LogicClusterStatus; + uint32 isLogicClusterBalanced; + uint32 isRedistribution; + staticConfigHeader logicClusterNodeHeader; + staticLogicNodeConfig* logicClusterNode; +} logicClusterStaticConfig; + +typedef struct logicClusterInfo { + uint32 logicClusterId; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; +} logicClusterInfo; + +typedef struct logicClusterList { + uint32 logicClusterCount; + logicClusterInfo lcInfoArray[LOGIC_CLUSTER_NUMBER]; +} logicClusterList; + +extern staticConfigHeader g_nodeHeader; +extern staticNodeConfig* g_node; +extern staticNodeConfig* g_currentNode; +extern bool g_single_node_cluster; +extern bool g_multi_az_cluster; +extern bool g_one_master_multi_slave; +extern bool g_only_dn_cluster; +extern uint32 g_node_num; +extern uint32 g_cluster_total_instance_group_num; +extern uint32 g_etcd_num; +extern uint32 g_cm_server_num; +extern uint32 g_dn_replication_num; +extern uint32 g_gtm_num; +extern uint32 g_coordinator_num; +extern uint32 max_node_name_len; +extern uint32 max_az_name_len; +extern uint32 max_datapath_len; +extern uint32 max_cnpath_len; +extern uint32 max_gtmpath_len; +extern uint32 max_etcdpath_len; +extern uint32 max_cmpath_len; +extern logicClusterStaticConfig g_logicClusterStaticConfig[LOGIC_CLUSTER_NUMBER]; +extern uint32 g_logic_cluster_count; +extern uint32 max_logic_cluster_state_len; +extern uint32 max_logic_cluster_name_len; +extern bool logic_cluster_query; +extern bool logic_cluster_restart; +extern uint32 g_datanodeid; +extern char* g_logicClusterName; + +extern int read_single_file(const char *file_path, int *err_no, uint32 nodeId, const char *dataPath); +extern int read_config_file(const char* file_path, int* err_no); +extern int read_logic_cluster_name(const char* file_path, logicClusterList& lcList, int* err_no); +extern int read_logic_cluster_config_files(const char* file_path, int* err_no); +extern int read_lc_config_file(const char* file_path, int* err_no); +extern int find_node_index_by_nodeid(uint32 nodeId, uint32* node_index); +extern int find_current_node_by_nodeid(uint32 nodeId); +extern int node_index_Comparator(const void* arg1, const void* arg2); +extern void set_cm_read_flag(bool falg); +extern char* getAZNamebyPriority(uint32 azPriority); +extern int cmconfig_getenv(const char* env_var, char* output_env_value, uint32 env_value_len); + +#endif diff -uprN postgresql-hll-2.14_old/include/common/fe_memutils.h postgresql-hll-2.14/include/common/fe_memutils.h --- postgresql-hll-2.14_old/include/common/fe_memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/common/fe_memutils.h 2020-12-12 17:06:43.107346232 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * fe_memutils.h + * memory management support for frontend code + * + * Copyright (c) 2003-2015, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/common/fe_memutils.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FE_MEMUTILS_H +#define FE_MEMUTILS_H + +/* + * Flags for pg_malloc_extended and palloc_extended, deliberately named + * the same as the backend flags. + */ +#define MCXT_ALLOC_HUGE \ + 0x01 /* allow huge allocation (> 1 GB) not \ + * actually used for frontends */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +#include "c.h" + +/* + * "Safe" memory allocation functions --- these exit(1) on failure + * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM) + */ +extern char* pg_strdup(const char* in); +extern void* pg_malloc(size_t size); +extern void* pg_malloc0(size_t size); +extern void* pg_malloc_extended(size_t size, int flags); +extern void* pg_realloc(void* pointer, size_t size); +extern void pg_free(void* pointer); + +/* Equivalent functions, deliberately named the same as backend functions */ +extern void* palloc(Size size); +extern void* palloc_extended(Size size, int flags); +extern void pfree(void* pointer); + +#endif /* FE_MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/common/int.h postgresql-hll-2.14/include/common/int.h --- postgresql-hll-2.14_old/include/common/int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/common/int.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,262 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * int.h + * Routines to perform integer math, while checking for overflows. + * + * The routines in this file are intended to be well defined C, without + * relying on compiler flags like -fwrapv. + * + * To reduce the overhead of these routines try to use compiler intrinsics + * where available. That's not that important for the 16, 32 bit cases, but + * the 64 bit cases can be considerably faster with intrinsics. In case no + * intrinsics are available 128 bit math is used where available. + * + * Copyright (c) 2017-2019, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/common/int.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMMON_INT_H +#define COMMON_INT_H + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#else + int32 res = (int32)a + (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#else + int32 res = (int32)a - (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#else + int32 res = (int32)a * (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#else + int64 res = (int64)a + (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#else + int64 res = (int64)a - (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#else + int64 res = (int64)a * (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a + (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + if ((a > 0 && b > 0 && a > PG_INT64_MAX - b) || (a < 0 && b < 0 && a < PG_INT64_MIN - b)) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a + b; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a - (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + if ((a < 0 && b > 0 && a < PG_INT64_MIN + b) || (a > 0 && b < 0 && a > PG_INT64_MAX + b)) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a - b; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a * (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + /* + * Overflow can only happen if at least one value is outside the range + * sqrt(min)..sqrt(max) so check that first as the division can be quite a + * bit more expensive than the multiplication. + * + * Multiplying by 0 or 1 can't overflow of course and checking for 0 + * separately avoids any risk of dividing by 0. Be careful about dividing + * INT_MIN by -1 also, note reversing the a and b to ensure we're always + * dividing it by a positive value. + * + */ + if ((a > PG_INT32_MAX || a < PG_INT32_MIN || b > PG_INT32_MAX || b < PG_INT32_MIN) && a != 0 && a != 1 && b != 0 && + b != 1 && + ((a > 0 && b > 0 && a > PG_INT64_MAX / b) || (a > 0 && b < 0 && b < PG_INT64_MIN / a) || + (a < 0 && b > 0 && a < PG_INT64_MIN / b) || (a < 0 && b < 0 && a < PG_INT64_MAX / b))) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a * b; + return false; +#endif +} + +#endif /* COMMON_INT_H */ diff -uprN postgresql-hll-2.14_old/include/connector.h postgresql-hll-2.14/include/connector.h --- postgresql-hll-2.14_old/include/connector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/connector.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * connector.h + * Definitions for c-function interface of the module + * + * + * IDENTIFICATION + * src/include/connector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CONNECTOR_H +#define CONNECTOR_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +/* + * External declarations + */ +extern Datum exec_hadoop_sql(PG_FUNCTION_ARGS); +extern Datum exec_on_extension(PG_FUNCTION_ARGS); + +enum EC_Status { EC_STATUS_INIT = 0, EC_STATUS_CONNECTED, EC_STATUS_EXECUTED, EC_STATUS_FETCHING, EC_STATUS_END }; + +#define NOT_EC_OPERATOR 0 +#define IS_EC_OPERATOR 1 +#define EC_LIBODBC_TYPE_ONE 1 /* libodbc.so.1 */ +#define EC_LIBODBC_TYPE_TWO 2 /* libodbc.so.2 */ + +#endif /* CONNECTOR_H */ diff -uprN postgresql-hll-2.14_old/include/cstore.h postgresql-hll-2.14/include/cstore.h --- postgresql-hll-2.14_old/include/cstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/cstore.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,132 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore.h + * Common head file to support ColStore + * + * + * IDENTIFICATION + * src/include/cstore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_H +#define CSTORE_H + +#include "storage/relfilenode.h" +#include "vecexecutor/vectorbatch.h" + +/* 0~FirstCUID is reserved for page id of delta table + * We want to keep delta table small + */ +const int FirstCUID = 1000; +/* + * The size of full CU by default + */ +#define DefaultFullCUSize ((int)BatchMaxSize * 60) + +/* + * Invalid CU ID + */ +const uint32 InValidCUID = 0xffffffff; + +/* + * Dictionary virtual CU Id + */ +const uint32 DicVirtualCUID = 0xfffffffe; + +/* Warning threshold of CUID */ +const uint32 CUIDWarningThreshold = 0xfff00000; + +/* Max CUID */ +const uint32 MaxCUID = 0xfffffff0; + +/* The ID of system-defined attributes have used from -1 to -9. + * look up system-define attributes. you can refer to file sysattr.h + */ +const int VitrualDelColID = -10; + +const int VirtualSpaceCacheColID = -11; + +/* The attribute number of CUDesc table */ +const int CUDescColIDAttr = 1; +const int CUDescCUIDAttr = 2; +const int CUDescMinAttr = 3; +const int CUDescMaxAttr = 4; +const int CUDescRowCountAttr = 5; +const int CUDescCUModeAttr = 6; +const int CUDescSizeAttr = 7; +const int CUDescCUPointerAttr = 8; +const int CUDescCUMagicAttr = 9; +const int CUDescCUExtraAttr = 10; + +// The column number of CUDesc table. +// If that table schema change, we should change this const variable +// +#define CUDescMaxAttrNum 10 + +typedef uint64 CUPointer; + +/* + * Judge whether valid CUID + */ +#define IsValidCUID(CUId) ((CUId) != InValidCUID) + +/* + * Judge whether dictionary CUID + */ +#define IsDicVCU(CUId) ((CUId) == DicVirtualCUID) + +/* + * File node of GsCStore. It includes file type. + */ +typedef struct CFileNode : public BaseObject { + RelFileNode m_rnode; + ForkNumber m_forkNum; + int m_attid; + + CFileNode(RelFileNode rnode, ForkNumber forkNum = MAIN_FORKNUM) + { + m_rnode = rnode; + m_rnode.bucketNode = -1; + m_forkNum = forkNum; + m_attid = -1; + } + + CFileNode(RelFileNode rnode, int attid, ForkNumber forkNum = MAIN_FORKNUM) + { + m_rnode = rnode; + m_rnode.bucketNode = -1; + m_forkNum = forkNum; + m_attid = attid; + } + + CFileNode(const CFileNode& cFilenode) + { + m_rnode = cFilenode.m_rnode; + m_rnode.bucketNode = -1; + m_forkNum = cFilenode.m_forkNum; + m_attid = cFilenode.m_attid; + } +} CFileNode; + +/* + * CStorage allocate strategy. + */ +typedef enum { APPEND_ONLY, USING_FREE_SPACE } CStoreAllocateStrategy; + +#endif + diff -uprN postgresql-hll-2.14_old/include/datasource/datasource.h postgresql-hll-2.14/include/datasource/datasource.h --- postgresql-hll-2.14_old/include/datasource/datasource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/datasource/datasource.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasource.h + * support for data source + * + * + * IDENTIFICATION + * src/include/datasource/datasource.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATASOURCE_H +#define DATASOURCE_H + +#include "nodes/parsenodes.h" + +typedef struct DataSource { + Oid sourceid; /* source Oid */ + Oid owner; /* source owner user Oid */ + char* srcname; /* name of the source */ + char* srctype; /* source type, optional */ + char* srcversion; /* source version, optional */ + List* options; /* source options as DefElem list */ +} DataSource; + +extern Oid get_data_source_oid(const char* sourcename, bool missing_ok); +extern DataSource* GetDataSource(Oid sourceid); +extern DataSource* GetDataSourceByName(const char* sourcename, bool missing_ok); + +#define EC_CIPHER_TEXT_LENGTH 1024 + +#endif /* DATASOURCE_H */ diff -uprN postgresql-hll-2.14_old/include/datatype/timestamp.h postgresql-hll-2.14/include/datatype/timestamp.h --- postgresql-hll-2.14_old/include/datatype/timestamp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/datatype/timestamp.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,233 @@ +/* ------------------------------------------------------------------------- + * + * timestamp.h + * Timestamp and Interval typedefs and related macros. + * + * Note: this file must be includable in both frontend and backend contexts. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/datatype/timestamp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATATYPE_TIMESTAMP_H +#define DATATYPE_TIMESTAMP_H + +#include +#include +#include + +/* + * Timestamp represents absolute time. + * + * Interval represents delta time. Keep track of months (and years), days, + * and hours/minutes/seconds separately since the elapsed time spanned is + * unknown until instantiated relative to an absolute time. + * + * Note that Postgres uses "time interval" to mean a bounded interval, + * consisting of a beginning and ending time, not a time span - thomas 97/03/20 + * + * We have two implementations, one that uses int64 values with units of + * microseconds, and one that uses double values with units of seconds. + * + * TimeOffset and fsec_t are convenience typedefs for temporary variables + * that are of different types in the two cases. Do not use fsec_t in values + * stored on-disk, since it is not the same size in both implementations. + * Also, fsec_t is only meant for *fractional* seconds; beware of overflow + * if the value you need to store could be many seconds. + */ + +#ifdef HAVE_INT64_TIMESTAMP + +typedef int64 Timestamp; +typedef int64 TimestampTz; +typedef int64 TimeOffset; +typedef int32 fsec_t; /* fractional seconds (in microseconds) */ +#else + +typedef double Timestamp; +typedef double TimestampTz; +typedef double TimeOffset; +typedef double fsec_t; /* fractional seconds (in seconds) */ +#endif + +typedef struct { + TimeOffset time; /* all time units other than days, months and + * years */ + int32 day; /* days, after time for alignment */ + int32 month; /* months and years, after time for alignment */ +} Interval; + +/* + * Convert an Interval to an approximate equivalent number of usec + */ +#define INTERVAL_TO_USEC(ivp) \ + ((ivp->month * DAYS_PER_MONTH * USECS_PER_DAY) + (ivp->day * USECS_PER_DAY) + ivp->time) + +#define MAX_TIMESTAMP_PRECISION 6 +#define MAX_INTERVAL_PRECISION 6 + +/* + * Round off to MAX_TIMESTAMP_PRECISION decimal places. + * Note: this is also used for rounding off intervals. + */ +#define TS_PREC_INV 1000000.0 +#define TSROUND(j) (rint(((double)(j)) * TS_PREC_INV) / TS_PREC_INV) + +/* + * Assorted constants for datetime-related calculations + */ + +#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */ +#define DAYS_PER_NYEAR 365 +#define MONTHS_PER_YEAR 12 +/* + * DAYS_PER_MONTH is very imprecise. The more accurate value is + * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only + * return an integral number of days, but someday perhaps we should + * also return a 'time' value to be used as well. ISO 8601 suggests + * 30 days. + */ +#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ +#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ + +/* + * This doesn't adjust for uneven daylight savings time intervals or leap + * seconds, and it crudely estimates leap years. A more accurate value + * for days per years is 365.2422. + */ +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 +#define SECS_PER_HOUR 3600 +#define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 +#define MINS_PER_DAY (HOURS_PER_DAY * MINS_PER_HOUR) + +#define USECS_PER_DAY INT64CONST(86400000000) +#define USECS_PER_HOUR INT64CONST(3600000000) +#define USECS_PER_MINUTE INT64CONST(60000000) +#define USECS_PER_SEC INT64CONST(1000000) + +#define USECS_PER_MSEC 1000 +#define MSECS_PER_SEC 1000 +#define MSECS_PER_MIN (SECS_PER_MINUTE * MSECS_PER_SEC) + +/* + * We allow numeric timezone offsets up to 15:59:59 either way from Greenwich. + * Currently, the record holders for wackiest offsets in actual use are zones + * Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42 + * until 1867. If we were to reject such values we would fail to dump and + * restore old timestamptz values with these zone settings. + */ +#define MAX_TZDISP_HOUR 15 /* maximum allowed hour part */ +#define TZDISP_LIMIT ((MAX_TZDISP_HOUR + 1) * SECS_PER_HOUR) + +/* + * DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity + */ +#ifdef HAVE_INT64_TIMESTAMP +#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1) +#define DT_NOEND (INT64CONST(0x7fffffffffffffff)) +#else /* !HAVE_INT64_TIMESTAMP */ +#ifdef HUGE_VAL +#define DT_NOBEGIN (-HUGE_VAL) +#define DT_NOEND (HUGE_VAL) +#else +#define DT_NOBEGIN (-DBL_MAX) +#define DT_NOEND (DBL_MAX) +#endif +#endif /* HAVE_INT64_TIMESTAMP */ + +#define TIMESTAMP_NOBEGIN(j) \ + do { \ + (j) = DT_NOBEGIN; \ + } while (0) + +#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN) + +#define TIMESTAMP_NOEND(j) \ + do { \ + (j) = DT_NOEND; \ + } while (0) + +#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND) + +#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) + +/* + * Julian date support. + * + * IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy + * about the maximum, since it's far enough out to not be especially + * interesting. + */ + +#define JULIAN_MINYEAR (-4713) +#define JULIAN_MINMONTH (11) +#define JULIAN_MINDAY (24) +#define JULIAN_MAXYEAR (5874898) + +#define IS_VALID_JULIAN(y, m, d) \ + (((y) > JULIAN_MINYEAR || \ + ((y) == JULIAN_MINYEAR && ((m) > JULIAN_MINMONTH || ((m) == JULIAN_MINMONTH && (d) >= JULIAN_MINDAY)))) && \ + (y) < JULIAN_MAXYEAR) + +#define JULIAN_MAX (2147483494) /* == date2j(JULIAN_MAXYEAR, 1, 1) */ + +/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */ +#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */ +#define POSTGRES_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */ + +#define MAX_VALUE_12_CLOCK (HOURS_PER_DAY / 2) +#define MIN_VALUE_12_CLOCK 1 + +#define MAX_VALUE_24_CLOCK (HOURS_PER_DAY) +#define MIN_VALUE_24_CLOCK 0 + +#define MAX_VALUE_MI (MINS_PER_HOUR) +#define MIN_VALUE_MI 0 + +#define MAX_VALUE_SS (SECS_PER_MINUTE) +#define MIN_VALUE_SS 0 + +#define MAX_VALUE_SSSSS 86400 +#define MIN_VALUE_SSSSS 0 + +#define MAX_VALUE_D 7 +#define MIN_VALUE_D 1 + +#define MAX_VALUE_DD 31 +#define MIN_VALUE_DD 1 + +#define MAX_VALUE_DDD 366 +#define MIN_VALUE_DDD 1 + +#define MAX_VALUE_MM 12 +#define MIN_VALUE_MM 1 + +#define MAX_VALUE_MS 999 +#define MIN_VALUE_MS 0 + +#define MIN_VALUE_YEAR -4712 +#define MAX_VALUE_YEAR 9999 + +#define MAX_VALUE_WW 53 +#define MIN_VALUE_WW 1 + +#define MAX_VALUE_W 5 +#define MIN_VALUE_W 1 + +/* to meet MAX_VALUE_YEAR */ +#define MAX_VALUE_J 5373484 +#define MIN_VALUE_J 1 + +#define MAX_VALUE_US 999999 +#define MIN_VALUE_US 0 + +#define MIN_VALUE_RR 0 +#define MID_VALUE_RR 49 +#define MAX_VALUE_RR 99 + +#endif /* DATATYPE_TIMESTAMP_H */ diff -uprN postgresql-hll-2.14_old/include/datatypes.h postgresql-hll-2.14/include/datatypes.h --- postgresql-hll-2.14_old/include/datatypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/datatypes.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * datatypes.h + * + * IDENTIFICATION + * src\include\datatypes.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +typedef unsigned int Oid; +typedef uintptr_t Datum; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef int32_t int32; diff -uprN postgresql-hll-2.14_old/include/dbmind/hypopg_index.h postgresql-hll-2.14/include/dbmind/hypopg_index.h --- postgresql-hll-2.14_old/include/dbmind/hypopg_index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/dbmind/hypopg_index.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * hypopg_index.h: Implementation of hypothetical indexes for PostgreSQL + * + * This file contains all includes for the internal code related to + * hypothetical indexes support. + * + * This program is open source, licensed under the PostgreSQL license. + * For license terms, see the LICENSE file. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Copyright (C) 2015-2018: Julien Rouhaud + * + * + * IDENTIFICATION + * src/include/dbmind/hypopg_index.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _HYPOPG_INDEX_H_ +#define _HYPOPG_INDEX_H_ + +/* -------------------------------------------------------- + * Hypothetical index storage, pretty much an IndexOptInfo + * Some dynamic informations such as pages and lines are not stored but + * computed when the hypothetical index is used. + */ +typedef struct hypoIndex { + Oid oid; /* hypothetical index unique identifier */ + Oid relid; /* related relation Oid */ + Oid reltablespace; /* tablespace of the index, if set */ + char *indexname; /* hypothetical index name */ + + BlockNumber pages; /* number of estimated disk pages for the + * index */ + double tuples; /* number of estimated tuples in the index */ + + /* index descriptor informations */ + int ncolumns; /* number of columns, only 1 for now */ + int nkeycolumns; /* number of key columns */ + short int *indexkeys; /* attnums */ + Oid *indexcollations; /* OIDs of collations of index columns */ + Oid *opfamily; /* OIDs of operator families for columns */ + Oid *opclass; /* OIDs of opclass data types */ + Oid *opcintype; /* OIDs of opclass declared input data types */ + Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */ + bool *reverse_sort; /* is sort order descending? */ + bool *nulls_first; /* do NULLs come first in the sort order? */ + Oid relam; /* OID of the access method (in pg_am) */ + + RegProcedure amcostestimate; /* OID of the access method's cost fcn */ + RegProcedure amcanreturn; /* OID of the access method's canreturn fcn */ + + List *indexprs; /* expressions for non-simple index columns */ + List *indpred; /* predicate if a partial index, else NIL */ + + bool predOK; /* true if predicate matches query */ + bool unique; /* true if a unique index */ + bool immediate; /* is uniqueness enforced immediately? */ + bool canreturn; /* can index return IndexTuples? */ + + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amhasgettuple; /* does AM have amgettuple interface? */ + bool amhasgetbitmap; /* does AM have amgetbitmap interface? */ + bool amcanunique; /* does AM support UNIQUE indexes? */ + bool amcanmulticol; /* does AM support multi-column indexes? */ + + /* store some informations usually saved in catalogs */ + List *options; /* WITH clause options: a list of DefElem */ + bool amcanorder; /* does AM support order by column value? */ +} hypoIndex; + +void InitHypopg(); +void hypopg_register_hook(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/dfs_adaptor.h postgresql-hll-2.14/include/dfs_adaptor.h --- postgresql-hll-2.14_old/include/dfs_adaptor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/dfs_adaptor.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_adaptor.h + * Define macros of the same function for different platform. + * + * + * IDENTIFICATION + * src/include/dfs_adaptor.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ADAPTER_HH +#define ADAPTER_HH + +#include "dfs_config.h" + +#ifndef DFS_CXX_HAS_NOEXCEPT +#define noexcept DFS_NOEXCEPT +#endif + +#ifndef DFS_CXX_HAS_OVERRIDE +#define override DFS_OVERRIDE +#endif + +#ifdef HAS_DIAGNOSTIC_PUSH +#ifdef __clang__ +#define DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") +#define DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +#define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +#define DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#else +#error("Unknown compiler") +#endif +#else +#define DIAGNOSTIC_PUSH +#define DIAGNOSTIC_POP +#endif + +#define PRAGMA(TXT) _Pragma(#TXT) + +#ifdef __clang__ +#define DIAGNOSTIC_IGNORE(XXX) PRAGMA(clang diagnostic ignored XXX) +#elif defined(__GNUC__) +#define DIAGNOSTIC_IGNORE(XXX) PRAGMA(GCC diagnostic ignored XXX) +#else +#define DIAGNOSTIC_IGNORE(XXX) +#endif + +#ifndef DFS_CXX_HAS_UNIQUE_PTR +#define unique_ptr auto_ptr +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff +#endif + +#define GTEST_LANG_CXX11 0 + +#endif /* ADAPTER_H */ diff -uprN postgresql-hll-2.14_old/include/dfs_config.h postgresql-hll-2.14/include/dfs_config.h --- postgresql-hll-2.14_old/include/dfs_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/dfs_config.h 2020-12-12 17:06:43.108346245 +0800 @@ -0,0 +1,93 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_config.h + * + * + * + * IDENTIFICATION + * src/include/dfs_config.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_UNIQUE_H +#define DFS_UNIQUE_H + +#define DFS_CXX_HAS_CSTDINT +#define DFS_CXX_HAS_INITIALIZER_LIST +#define DFS_CXX_HAS_NOEXCEPT +#define DFS_CXX_HAS_NULLPTR +#define DFS_CXX_HAS_OVERRIDE +#define DFS_CXX_HAS_UNIQUE_PTR + +#ifdef DFS_CXX_HAS_CSTDINT +#include +#else +#include +#endif + +#ifdef DFS_CXX_HAS_NOEXCEPT +#define DFS_NOEXCEPT noexcept +#else +#define DFS_NOEXCEPT throw() +#endif + +#ifdef DFS_CXX_HAS_NULLPTR +#define DFS_NULLPTR nullptr +#else +namespace dfs { +class nullptr_t { +public: + template + operator T *() const + { + return 0; + } + + template + operator T C::*() const + { + return 0; + } + +private: + void operator&() const; // whose address can't be taken +}; +const nullptr_t nullPtr = {}; +} // namespace dfs +#define DFS_NULLPTR dfs::nullPtr +#endif + +#ifdef DFS_CXX_HAS_OVERRIDE +#define DFS_OVERRIDE override +#else +#define DFS_OVERRIDE +#endif + +#ifdef DFS_CXX_HAS_UNIQUE_PTR +#define DFS_UNIQUE_PTR std::unique_ptr +#else +#define DFS_UNIQUE_PTR std::auto_ptr +namespace dfs { +template +inline T move(T &x) +{ + return x; +} +} // namespace dfs +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/dfsdesc.h postgresql-hll-2.14/include/dfsdesc.h --- postgresql-hll-2.14_old/include/dfsdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/dfsdesc.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,634 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfsdesc.h + * classes & routines to support dfsdesc + * + * + * IDENTIFICATION + * src/include/dfsdesc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFSDESC_H +#define DFSDESC_H + +#include "securec.h" +#include "securec_check.h" +#include "nodes/pg_list.h" +#include "utils/snapshot.h" +#include "access/htup.h" +#include "access/tupdesc.h" + +#define DfsDescMaxAttrNum 11 + +#define Anum_pg_dfsdesc_duid 1 +#define Anum_pg_dfsdesc_partid 2 +#define Anum_pg_dfsdesc_rowcount 3 +#define Anum_pg_dfsdesc_magic 4 +#define Anum_pg_dfsdesc_min 5 +#define Anum_pg_dfsdesc_max 6 +#define Anum_pg_dfsdesc_deletemap 7 +#define Anum_pg_dfsdesc_relativelyfilename 8 +#define Anum_pg_dfsdesc_extra 9 +#define Anum_pg_dfsdesc_columnmap 10 +#define Anum_pg_dfsdesc_filesize 11 + +#define MAX_LOADED_DFSDESC 100 +#define MAX_DFS_FILE_NAME_SIZE 256 + +#define MIN_MAX_SIZE 32 +#define BITS_IN_BYTE 8 +#define MEGA_SHIFT 20 + +#define DFSDESC_MAX_COL DfsDescMaxAttrNum +#define NON_PARTITION_TALBE_PART_NUM 0xFFFF +#define NULL_MAGIC 255 + +#define DfsDescIndexMaxAttrNum 1 + +/* + * Since the attno starts at 1, so the first bit of the map is never used. + * so we need add 1 here to avoid memory overflow. + */ +#define GET_COLMAP_LENGTH(nCols) (((uint32)(int32)(nCols) >> 3) + 1) + +/* + * we need to get the delete map, column map, min value, max value from + * Desc table. the logic of getting delete map is same to the logic of + * getting column. Between the logic of getting min value and logic of + * getting max value are same. + * So build a enum for function parameter. + */ +typedef enum { DELETE_MAP_ATTR = 0, COLUMN_MAP_ATTR, MIN_COLUMN_ATTR, MAX_COLUMN_ATTR } ColumnEnum; + +typedef struct { + int Len; + char szContent[MIN_MAX_SIZE]; + +} stMinMax; + +class DFSDesc : public BaseObject { +public: + DFSDesc(); + DFSDesc(uint32 PartId, uint32 DescId, uint32 ColCnt); + + void Destroy(); + virtual ~DFSDesc(); + +public: + /* + * get column count + */ + uint32 GetColCnt() const + { + return m_ColCnt; + } + /* + * set column count + */ + void SetColCnt(uint32 ColCnt) + { + m_ColCnt = ColCnt; + } + + /* + * get transaction Id that alway is tuple xmin if has set + */ + uint32 GetXId() const + { + return m_Xmin; + } + + /* + * set transaction Id (tuple xmin) + */ + void SetXId(uint32 XId) + { + m_Xmin = XId; + } + + /* + * get the descriptor Id + */ + uint32 GetDescId() const + { + return m_DescId; + } + + /* + * set the descriptor Id + */ + void SetDescId(uint32 DescId) + { + m_DescId = DescId; + } + + /* + * get the row count include those deleted + */ + uint32 GetRowCnt() const + { + return m_RowCnt; + } + + /* + * get the row count include those deleted + */ + void SetRowCnt(uint32 RowCnt) + { + m_RowCnt = RowCnt; + } + + /* get the size of hdfs file */ + int64 GetFileSize() const + { + return m_FileSize; + } + + /* set the size of hdfs file */ + void SetFileSize(int64 FileSize) + { + m_FileSize = FileSize; + } + + /* + * get the magic that may be the current transaction Id(cu use that) + */ + uint32 GetMagic() const + { + return m_Magic; + } + + /* + * set the magic that may be the current transaction Id(cu use that) + */ + void SetMagic(uint32 Magic) + { + m_Magic = Magic; + } + + /* + * get file name + */ + const char* GetFileName() const + { + return m_FileName; + } + + /* + * set file name + */ + void SetFileName(const char* pFileName) + { + if (pFileName != NULL) { + size_t len = strlen(pFileName); + if (0 == m_name_len) { + m_FileName = (char*)palloc(len + 1); + m_name_len = len + 1; + } + + if ((len + 1) > m_name_len) { + m_FileName = (char*)repalloc(m_FileName, len + 1); + m_name_len = len + 1; + } + + errno_t rc = strcpy_s(m_FileName, m_name_len, pFileName); + securec_check(rc, "", ""); + } + + return; + } + + /** + * @Description: Set the column map. + * @in colMap, The column map string. + * @in length, The length of colMap string. + * @return None. + */ + void setColMap(const char* colMap, int length) + { + if (colMap != NULL) { + errno_t rc = EOK; + m_colMap = (char*)palloc0(length + 1); + rc = memcpy_s(m_colMap, length + 1, colMap, length); + securec_check(rc, "", ""); + m_colMapLen = length; + } else { + /* + * Never occur here. + */ + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("The table has no column."))); + } + } + + /** + * @Description: Get the column map. + * @return return the column map. + */ + const char* getColMap() + { + return m_colMap; + } + + /** + * @Description: Get the length of column map binary. + * @return the length. + */ + uint32 getColMapLength() + { + return m_colMapLen; + } + + /** + * @Description: Whether the column is default column. The default column means + * that the column value is stored in pg_attribute. + * @in attNo, The attribute number of the column. It starts from 1. + * @return If the column is default column, return true, otherwise retuen false. + */ + bool isDefaultColumn(uint32 attNo) + { + Assert(NULL != m_colMap); + bool defaultCol = true; + if ((attNo >> 3) > m_colMapLen) { + defaultCol = true; + } else if ((unsigned char)m_colMap[attNo >> 3] & (1 << (attNo % BITS_IN_BYTE))) { + defaultCol = false; + } + return defaultCol; + } + + /* + * get the table partition id + */ + uint32 GetPartId() const + { + return m_PartId; + } + + /* + * set the table partition id + */ + void SetPartId(uint32 PartId) + { + m_PartId = PartId; + } + + /* + * @Description: get the min value according to the column number + * @IN Col: the column number + * @Return: the min value or NULL + * @See also: + */ + stMinMax* GetMinVal(uint32 Col) const + { + if ((Col >= m_ColCnt) || (m_MinVal == NULL)) { + return NULL; + } + + return m_MinVal[Col]; + } + + /* + * @Description: set the min value + * @IN Col: column id + * @IN pMinVal: the string of min value + * @IN Size: the size of string + * @Return: 0 if success, 1 if fail + * @See also: + */ + int SetMinVal(uint32 Col, const char* pMinVal, uint32 Size); + + /* + * @Description: get the max value according to the column number + * @IN Col: the column number + * @Return: the max value or NULL + * @See also: + */ + stMinMax* GetMaxVal(uint32 Col) const + { + if ((Col >= m_ColCnt) || (m_MinVal == NULL)) { + return NULL; + } + + return m_MaxVal[Col]; + } + + /* + * @Description: set the max value + * @IN Col: column id + * @IN pMinVal: the string of max value + * @IN Size: the size of string + * @Return: 0 if success, 1 if fail + * @See also: + */ + int SetMaxVal(uint32 Col, const char* pMaxVal, uint32 Size); + + /* + * set the delete map value,Just copy + */ + int MaskDelMap(const char* pDelMap, uint32 Size, bool ChkDelHasDone = true); + + /* + * get the delete map value + */ + const char* GetDelMap() const + { + return m_DelMap; + } + + /*tell whether is deleted by row number*/ + bool IsDeleted(uint32 Row) + { + bool Ret = false; + + /*not set delmap means none was deleted. exceed row scope also tell false*/ + if ((m_DelMap == NULL) || (Row >= m_RowCnt)) { + Ret = false; + } else { + if ((unsigned char)m_DelMap[Row >> 3] & (1 << (Row % 8))) { + Ret = true; + } + } + + return Ret; + } + + void Reset(); + + /* tid for this desc tuple */ + ItemPointerData tid; + +private: + int AllocMinMax(); + void DeallocMinMax(); + int AllocDelMap(); + void DeallocDelMap(); + +private: + /* + * DfsDesc Id + */ + uint32 m_DescId; + + /* + * row count include those deleted + */ + uint32 m_RowCnt; + + /* file size */ + int64 m_FileSize; + + /* + * column count of the table that described + */ + uint32 m_ColCnt; + + /* + *delete map buffer size in bytes + */ + uint32 m_DelMapBaseSize; + /* + *min&max buffer size in bytes (one column) + */ + uint32 m_MinMaxBaseSize; + + /* + *partition id of the table that described + */ + uint32 m_PartId; + + /* + * magic id + */ + uint32 m_Magic; + + /* + * transation id + */ + uint32 m_Xmin; + + /* + * Orc file name + */ + char* m_FileName; + size_t m_name_len; + +public: + /* + * Min values array + * the column min value format is (head byte - total length + other bytes - actual min value) + for example the column is INT type and the min value is 1 + then the head byte store the length is 5, and next 4 bytes is the 1 values + + */ + stMinMax** m_MinVal; + + /* + * Max values array + * the column max value format is (head byte - length + other bytes - actual max value) + for example the column is INT type and the max value is 1 + then the head byte store the length is 5 and next 4 bytes is the 1 values + */ + stMinMax** m_MaxVal; + +private: + /* + * delete map values + */ + char* m_DelMap; + + /** + * It stores the columns by bitmap method. When read data, the m_colMap stores + * the columns which is included in the corresponding file. When insert data, + * the m_colMap stores all columns, but it excludeds dropped columns. + */ + char* m_colMap; + uint32 m_colMapLen; +}; + +class DFSDescHandler : public BaseObject { + +public: + /** + * @Description: The construct function. + * @in MaxBatCnt, Max load count in one batch. + * @in SrcRelCols, The column count of described table. + * @in mainRel, The main table. + * @return None. + */ + DFSDescHandler(uint32 MaxBatCnt, int SrcRelCols, Relation mainRel); + + /* + * deconstruction + */ + virtual ~DFSDescHandler(); + +public: + /* + * load dfs descriptors in rows + * pDFSDescArray [in/out] - DFSDesc array to Contain descriptors + * Size[in] -size of DFSDesc array + * Partid[in] - which table partition to load (partition table use it actual id, + * non-partition table use NON_PARTITION_TALBE_PART_NUM) + * StartDescId [in]- the descriptor id to start load + * SnapShot [in] - which snapshot, fill NULL is to use GetActiveSnapshot + * pLoadCnt [out] - contain the number of exact loaded + * pLastId[out] - the last descriptor id loaded + * + * return 0 if success + */ + int Load(DFSDesc* pDFSDescArray, uint32 Size, uint32 PartId, uint32 StartDescId, Snapshot SnapShot, + uint32* pLoadCnt, uint32* pLastId); + + /* + * We always generate xlog for dfsdesc tuple + */ + /* + * add dfs descriptors in rows + * pDFSDescArray [in] - DFSDesc array to append + * Size[in] -size of DFSDesc array + * CmdId[in] - the command id + * options [in]- the options heap_insert, (advice generate xlog for dfsdesc tuple) + * + * return 0 if success + */ + int Add(DFSDesc* pDFSDescArray, uint32 Cnt, CommandId CmdId, int Options); + + /* + * delete rows by mask the delete map buffer + * Tid [in] - file id & row offset + * return none + */ + uint32 SetDelMap(ItemPointer Tid, bool reportError); + + /* + * flush the delete map buffer to descriptor + * return none + */ + void FlushDelMap(); + + /* + * get how many rows not deleted + */ + uint64 GetLivedRowNumbers(int64* deadrows); + + /* + * dfsdesc to tuple + * pDFSDesc[in] - which descriptor to handle + * pTupVals[in/out] - the values of columns + * pTupNulls[in/out] - mark which column is NULL + * DfsDescTupDesc[in] - description of the heap tuple + * return the heap tuple + */ + HeapTuple DfsDescToTuple(DFSDesc* pDFSDesc, Datum* pTupVals, bool* pTupNulls, TupleDesc DfsDescTupDesc); + + /* + * dfsdesc to tuple + * HeapTuple [in]- which heap tuple to handle + * DfsDescTupDesc[in] - description of the heap tuple + * pDFSDesc[out] - the DFSDesc changed from heap tuple + */ + void TupleToDfsDesc(HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc); + + /* + * get list of desc tuples in which some row(s) was deleted + */ + List* GetDescsToBeMerged(Snapshot _snapshot); + + /* + * get all desc tuples + */ + List* GetAllDescs(Snapshot _snapshot); + + /* + * test whether row is deleted in one desc tuple + */ + bool ContainDeleteRow(const char* all_valid_bitmap, int bitmap_length, const char* delmap, int rows) const; + + /* + * delete one desc tuple + */ + void DeleteDesc(DFSDesc* desc) const; + +private: + /* + * get list of desc tuples in which some row(s) was deleted or not + */ + List* GetDescTuples(Snapshot _snapshot, bool only_tuples_with_invalid_data); + + /** + * @Description: Set minimum/maximun value of the each column in current file from Desc table. + * @in pCudescTup, The HeapTuple struct. + * @in DfsDescTupDesc, The TupleDesc struct. + * @out DFSDesc, The DFSDesc struct. + * @out columnAttr, the column to be got value, the column is min value column + * or max value column. So value of the columnAttr only is MIN_COLUMN_ATTR or + * MAX_COLUMN_ATTR. + * @return + */ + void setMinMaxByHeapTuple(HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc, ColumnEnum columnAttr); + + /** + * @Description: Set map value in current file from Desc table. The map has two + * kind types, one is delete map, the other one is column map. + * @in pCudescTup, The HeapTuple struct. + * @in DfsDescTupDesc, The TupleDesc struct. + * @out DFSDesc, The DFSDesc struct. + * @out columnAttr, the column to be got value, the column is deletemap column + * or colmap column. So value of the columnAttr only is DELETE_MAP_ATTR or + * COLUMN_MAP_ATTR. + * @return + */ + void setMapColumnByHeapTuple( + HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc, ColumnEnum columnAttr); + /* + * dfs descriptor table id + */ + Oid m_TableOid; + + /* + * dfs descriptor index table id(the index by partition id and desc id) + */ + Oid m_IndexOid; + /* + * The main relation. + */ + Relation m_mainRel; + + /* + * the column count of described table + */ + uint32 m_SrcRelCols; + + /* + * max batch rows + */ + uint32 m_MaxBatCnt; + + /*the file id to set delmap*/ + int32 m_DelMapFileId; + + /*the delmap cache for a fileid*/ + char* m_pDelMap; + + /*the delmap cache size*/ + uint32 m_DelMapSize; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamConsumer.h postgresql-hll-2.14/include/distributelayer/streamConsumer.h --- postgresql-hll-2.14_old/include/distributelayer/streamConsumer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamConsumer.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,116 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamConsumer.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamConsumer.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ + +#include "distributelayer/streamCore.h" + +class StreamConsumer; +typedef struct { + StreamConsumer* consumer; + int connNum; + int connInfoSize; + StreamConnInfo* connInfo; +} StreamValue; + +/* Element in stream information table. */ +typedef struct { + StreamKey key; + StreamValue* value; +} StreamElement; + +class StreamConsumer : public StreamObj { +public: + StreamConsumer(MemoryContext context); + + ~StreamConsumer(); + + /* Init the consumer object. */ + void init(StreamKey key, List* execProducerNodes, ParallelDesc desc, StreamTransType transType, + StreamSharedContext* sharedContext); + + /* Deinit the consumer. */ + void deInit(); + + /* Waiting for the producer is ready. */ + void waitProducerReady(); + + /* Find un connect producer. */ + void findUnconnectProducer(StringInfo str); + + /* Get nodeIdx of producer which is waited for. */ + int getFirstUnconnectedProducerNodeIdx(); + + /* Wake up consumer and let it work. */ + static bool wakeUpConsumerCallBack(CommStreamKey commKey, StreamConnInfo connInfo); + + /* Release comm mode stream. */ + void releaseCommStream(); + + /* Get nodeIdx of producer by nodename. */ + int getNodeIdx(const char* nodename); + + /* Get shared context for local stream. */ + inline StreamSharedContext* getSharedContext() + { + return m_sharedContext; + } + + /* + * Record the orign node list in case of DN pruned in with-recursive execution + * mode, store the corresponding producer connection list from which the + * ExecStream will get + */ + List* m_originProducerNodeList; + +private: + + /* Update the stream info. */ + bool updateStreamCommInfo(StreamConnInfo* connInfo); + + /* Update the transport info. */ + void updateTransportInfo(StreamValue* val); + +private: + /* Current producer number. */ + int m_currentProducerNum; + + /* All producer is ready or not. */ + bool m_ready; + + /* Expected producer info. */ + StreamConnInfo* m_expectProducer; + + /* Mutex and condition waiting for producer is ready. */ + pthread_mutex_t m_mutex; + + pthread_cond_t m_cond; + + StreamSharedContext* m_sharedContext; +}; + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ */ diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamCore.h postgresql-hll-2.14/include/distributelayer/streamCore.h --- postgresql-hll-2.14_old/include/distributelayer/streamCore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamCore.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,498 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamCore.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamCore.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ + +#include + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "pgxc/execRemote.h" +#include "optimizer/planner.h" +#include "optimizer/streamplan.h" +#include "libcomm/libcomm.h" +#include "libpq/libpq-be.h" +#include "libpq/pqformat.h" +#include "access/xact.h" +#include "utils/distribute_test.h" +#include +#include "storage/spin.h" +#include "workload/workload.h" +#include "pgstat.h" +#include "distributelayer/streamTransportCore.h" + +/* The max stream thread in one node. */ +#define MAX_STREAM_PER_PLAN 128 + +/* The max number of nodes that stream can connect. */ +#define INIT_STREAMINFO_SIZE 64 + +#define STREAM_BUF_INIT_SIZE 16 * 1024 + +#define PRINTTRUE(A) (((A) == true) ? "true" : "false") + +#define TupleVectorMaxSize 100 + +struct StreamState; +class StreamObj; +class StreamNodeGroup; +struct SyncController; + +typedef bool (*scanStreamFun)(StreamState* node); +typedef bool (*deserializeStreamFun)(StreamState* node); + +typedef struct { + uint64 queryId; /* u_sess->debug_query_id */ + unsigned int planNodeId; + unsigned int smpIdentifier; +} StreamKey; + +typedef union { + struct { + int fd; + } tcpLayer; + + struct { + gsocket gsock; /* libcomm logic socket */ + } libcomm_layer; +} StreamIdentity; + +typedef struct StreamConnInfo { + StreamIdentity port; + char nodeName[NAMEDATALEN]; + Oid nodeoid; + int nodeIdx; /* datanode index, like PGXCNodeId */ + unsigned int producerSmpId; /* For SCTP, mark connect which producer */ +} StreamConnInfo; + +typedef struct { + ThreadId key; + StreamNodeGroup* value; +} StreamNodeElement; + +typedef struct { + uint64 key; +} StreamConnectSyncElement; + +enum StreamObjType { + STREAM_PRODUCER, + STREAM_CONSUMER, +}; + +enum StreamObjStatus { + STREAM_UNDEFINED, + STREAM_INPROGRESS, + STREAM_COMPLETE, + STREAM_ERROR, +}; + +typedef struct { + StreamObj* streamObj; /* A stream Node has only one or null producer object. */ + List* consumerList; /* A stream Node may contain many consumer. */ + StreamObjStatus status; + bool* stopFlag; +} StreamNode; + +typedef struct { + StreamKey key; + List* producerList; /* corresponding producer. */ + List* consumerList; /* corresponding consumer. */ + int expectThreadNum; /* producer thread sub thread number. */ + int createThreadNum; +} StreamPair; + +enum DataStatus { + DATA_EMPTY, + DATA_PREPARE, + DATA_READY, + CONN_ERR, +}; + +enum EdataWriteStatus { + EDATA_WRITE_ENABLE, + EDATA_WRITE_START, + EDATA_WRITE_FINISH, + ERROR_READ_FINISH, +}; + +typedef struct TupleVector { + TupleTableSlot** tupleVector; + int tuplePointer; +} TupleVector; + +typedef struct StreamSharedContext { + MemoryContext localStreamMemoryCtx; /**/ + VectorBatch*** sharedBatches; + TupleVector*** sharedTuples; + StringInfo** messages; + DataStatus** dataStatus; + bool** is_connect_end; + int* scanLoc; + TcpStreamKey key_s; + bool vectorized; + struct hash_entry** poll_entrys; + struct hash_entry*** quota_entrys; +} StreamSharedContext; + +typedef struct StreamSyncParam { + Oid TempNamespace; + Oid TempToastNamespace; + bool IsBinaryUpgrade; + bool CommIpcLog; +} StreamSyncParam; + +class StreamObj : public BaseObject { +public: + StreamObj(MemoryContext context, StreamObjType type); + ~StreamObj(); + + /* Initiliaze the stream environment. */ + static void startUp(); + + /* Get the node group. */ + StreamNodeGroup* getNodeGroup(); + + /* Set stream thread id. */ + void setThreadId(ThreadId pid); + + /* Set stream pair. */ + void setPair(StreamPair* pair); + + /* Get the stream key. */ + StreamKey getKey(); + + /* Get the stream type. */ + StreamObjType getType(); + + /* Get parallel description. */ + ParallelDesc getParallelDesc(); + + /* Get stream thread id. */ + ThreadId getThreadId(); + + /* Get the pgxc data node id. */ + int getPgxcNodeId(); + + /* Get the index itself in the group. */ + int getNodeGroupIdx(); + + /* Get the stream pair. */ + StreamPair* getPair(); + + /* Get the stream plan node. */ + Stream* getStream(); + + /* Get stream transport. */ + StreamTransport** getTransport(); + + /* Get connection number. */ + int getConnNum(); + + /* Release net port. */ + void releaseNetPort(); + + /* Release net port in hash table. */ + static void releaseNetPortInHashTable(); + + /* Stream node group belongs to. */ + StreamNodeGroup* m_nodeGroup; + + /* Stream transport array. */ + StreamTransport** m_transport; + + /* Stream pair. */ + StreamPair* m_pair; + +protected: + /* Stream type. */ + StreamObjType m_type; + + /* Stream key. */ + StreamKey m_key; + + /* Memory context the stream object use. */ + MemoryContext m_memoryCxt; + + /* Stream transportation type. */ + StreamTransType m_transtype; + + /* Expected socket number. */ + int m_connNum; + + /* Stream node. */ + Stream* m_streamNode; + + /* Identify itself in the group. */ + int m_nodeGroupIdx; + + /* The thread id that take the stream object. */ + ThreadId m_threadId; + + /* The node id that the stream thread is running on. */ + int m_nodeId; + + /* Stream object is init or not. */ + bool m_init; + + /* Stream sync object is init or not. */ + bool m_threadSyncObjInit; + + /* Stream object status. */ + StreamObjStatus m_status; + + /* Parallel description. */ + ParallelDesc m_parallel_desc; + +protected: + /* Global context stream object using. */ + static MemoryContext m_memoryGlobalCxt; + + /* Hash table for stream information, mainly for stream connect. */ + static HTAB* m_streamInfoTbl; + +public: + /* Mutex for stream info table. */ + static pthread_mutex_t m_streamInfoLock; +}; + +/* Stream node group is book keeper for stream object. */ +class StreamNodeGroup : public BaseObject { +public: + StreamNodeGroup(); + + ~StreamNodeGroup(); + + /* Init stream node group. */ + void Init(int threadNum); + + /* Init some static member. */ + static void StartUp(); + + /* Stop all register stream thread in the node group. */ + static void stopAllThreadInNodeGroup(ThreadId pid, uint64 query_id); + + /* Destory a stream Node group, clean some status. */ + static void destroy(StreamObjStatus status); + + /* Synchronize quit. */ + static void syncQuit(StreamObjStatus status); + + /* Grant stream connect permission. */ + static void grantStreamConnectPermission(); + + /* Revoke stream connect permission. */ + static void revokeStreamConnectPermission(); + + /* Check if can accept connection. */ + static bool checkStreamConnectPermission(uint64 query_id); + + /* Clear the stream node group. */ + void deInit(StreamObjStatus status); + + /* Register the object in stream node group. */ + int registerStream(StreamObj* obj); + + /* Unregister the stream object represented in group idx with status. */ + void unregisterStream(int groupIdx, StreamObjStatus status); + + /* Send signal to all stream thread registered in node group. */ + void signalStreamThreadInNodeGroup(int signo); + + /* Cancel all stream thread registered in node group. */ + static void cancelStreamThread(); + + /* Set the stop flag. */ + void setStopFlagPoint(int groupIdx, bool* stopFlag); + + /* Set the node status. */ + void setNodeStatus(int groupIdx, StreamObjStatus status); + + /* Wait all thread in the node group to quit. */ + void quitSyncPoint(); + + /* Push a stream pair. */ + StreamPair* pushStreamPair(StreamKey key, List* producer, List* consumer); + + /* Pop a stream pair according to key. */ + StreamPair* popStreamPair(StreamKey key); + + /* Get stream pair list */ + List* getStreamPairList(); + + /* Start a stream thread. */ + void initStreamThread(StreamProducer* producer, uint8 smpIdentifier, StreamPair* pair); + + /* In the same node group? */ + bool inNodeGroup(ThreadId pid1, ThreadId pid2); + + /* Restore stream enter. */ + void restoreStreamEnter(); + + /* Set need clean flag. */ + void setNeedClean(bool flag); + + /* Check if query already canceled. */ + bool isQueryCanceled() + { + return m_canceled; + } + + /* Save the first error data of producer */ + void saveProducerEdata(); + + /* Get the saved error data of producer */ + ErrorData* getProducerEdata(); + + /* Stream Consumer List. */ + List* m_streamConsumerList; + + /* Stream Producer List. */ + List* m_streamProducerList; + + /* Controller list for recursive */ + List* m_syncControllers; + + MemoryContext m_streamRuntimeContext; + + /* Save the first error data of producer thread */ + ErrorData* m_producerEdata; + + /* MPP with-recursive support */ + static void SyncConsumerNextPlanStep(int controller_plannodeid, int step); + static void SyncProducerNextPlanStep(int controller_plannodeid, int producer_plannodeid, int step, int tuple_count, + bool* need_rescan, int target_iteration); + + void ConsumerNodeStreamMessage(StreamState* node); + void ConsumerGetSyncUpMessage(RecursiveUnionController* controller, int step, StreamState* node, char msg_type); + void ConsumerMarkRUStepStatus(RecursiveUnionController* controller, int step, int iteration, StreamState* node, + int pgxc_nodeid, int producer_plannodeid, int tuple_processed); + void ProducerSendSyncMessage( + RecursiveUnionController* controller, int producer_plannodeid, int step, int tuple_count, char msg_type); + void ProducerFinishRUIteration(int step); + static bool IsRecursiveUnionDone(RecursiveUnionState* state); + static bool IsRUCoordNode(); + static bool IsRUSyncProducer(); + void AddSyncController(SyncController* controller); + SyncController* GetSyncController(int controller_plannodeid); + void MarkSyncControllerStopFlagAll(); + + inline pthread_mutex_t* GetStreamMutext() + { + return &m_mutex; + }; + + inline pthread_mutex_t* GetRecursiveMutex() + { + return &m_recursiveMutex; + }; + + inline uint64 GetQueryId(); + + inline void SetRecursiveVfdInvalid() + { + m_recursiveVfdInvalid = true; + } + + inline bool GetRecursiveVfdInvalid() + { + return m_recursiveVfdInvalid; + } + + /* Mark recursive vfd is invalid before aborting transaction. */ + static void MarkRecursiveVfdInvalid(); + +private: + /* Set the executor stop flag to true. */ + void stopThread(); + + /* Top consumer pid also the node group creator pid. */ + ThreadId m_pid; + + /* How many stream object can hold. */ + int m_size; + + /* How many stream object currently hold. */ + int m_streamNum; + + /* Stream Object Node Container. */ + StreamNode* m_streamArray; + + /* Stream Pair list. */ + List* m_streamPairList; + + /* A counter that't signal the stream thread group can destroy. */ + volatile int m_quitWaitCond; + + /* A counter remeber the already created thread number. */ + volatile int m_createThreadNum; + + /* A flag to indicate stream enter the quit point. */ + volatile int m_streamEnter; + + /* Mutex and condition waiting for all thread in the node group is complete. */ + pthread_mutex_t m_mutex; + + pthread_cond_t m_cond; + + /* Mark if query already canceled. */ + bool m_canceled; + + /* Mark if need clean stream info hash table. */ + bool m_needClean; + + /* First error data write protect */ + int m_edataWriteProtect; + + /* Mark if query failed. */ + bool m_errorStop; + + /* Mark if VFD of recursive is invalid. */ + bool m_recursiveVfdInvalid; + + /* Mutex for sync controller and vfd operation. */ + pthread_mutex_t m_recursiveMutex; + + /* Global context stream object using. */ + static MemoryContext m_memoryGlobalCxt; + + /* Hash table for stream node group. */ + static HTAB* m_streamNodeGroupTbl; + + /* Mutex for stream node group. */ + static pthread_mutex_t m_streamNodeGroupLock; + + /* Hash table for stream connect sync. */ + static HTAB* m_streamConnectSyncTbl; + + /* Mutex for stream connect sync. */ + static pthread_mutex_t m_streamConnectSyncLock; +}; + +extern bool IsThreadProcessStreamRecursive(); + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ */ diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamMain.h postgresql-hll-2.14/include/distributelayer/streamMain.h --- postgresql-hll-2.14_old/include/distributelayer/streamMain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamMain.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- +* +* streamMain.h +* stream main Interface +* +* Portions Copyright (c) 2020 Huawei +* IDENTIFICATION +* src/include/distributelayer/streamMain.h +* +* NOTES +* Main interface for stream thread +* +* ------------------------------------------------------------------------- +*/ + +#ifndef STREAM_MAIN_H +#define STREAM_MAIN_H + +extern int StreamMain(); +extern void SetStreamWorkerInfo(class StreamProducer* proObj); +extern void ResetStreamEnv(); +extern void ExtractProduerInfo(); +extern ThreadId ApplyStreamThread(StreamProducer *producer); +extern void RestoreStream(); +extern void StreamExit(); +extern void RestoreStreamSyncParam(struct StreamSyncParam *syncParam); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamProducer.h postgresql-hll-2.14/include/distributelayer/streamProducer.h --- postgresql-hll-2.14_old/include/distributelayer/streamProducer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamProducer.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,506 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamProducer.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamProducer.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ + +#include "distributelayer/streamCore.h" + +#define VALUE_TYPE 0 +#define NUMERIC_TYPE 1 +#define VARLENA_TYPE 2 +#define CSTRING_TYPE 3 +#define TID_TYPE 4 +#define FIXED_TYPE 5 + +class StreamProducer : public StreamObj { +public: + StreamProducer(StreamKey key, PlannedStmt* pstmt, Stream* streamNode, MemoryContext context, int socketNum, + StreamTransType type); + + ~StreamProducer(); + + /* Init the stream producer. */ + void init(TupleDesc desc, StreamTxnContext txnCxt, ParamListInfo params, int parentPlanNodeId); + + /* Init stream key */ + void initStreamKey(); + + /* Init dataskew info. */ + void initSkewState(); + + typedef void (StreamProducer::*criticalSectionFunc)(void); + + /* Connect consumer. */ + void connectConsumer(libcomm_addrinfo** consumerAddr, int& count, int totalNum); + + /* Enter critical section for net protect purpose. */ + void enterCriticalSection(criticalSectionFunc func); + + /* Deinit the producer. */ + void deInit(StreamObjStatus status); + + /* Init the net environment. */ + void netInit(); + + /* Init the net port. */ + void netPortInit(); + + /* Release net port with protect. */ + void releaseUninitializeResourceWithProtect(); + + /* Release net port of sub consumers. */ + void releaseSubConsumerList(); + + /* Release net port if net is not init yet. */ + void releaseUninitializeResource(); + + /* Register producer thread into thread node group, it should be call in the stream thread. */ + void registerGroup(); + + /* Switch the send direction to the nth channel. */ + bool netSwitchDest(int nthChannel); + + /* Save some network status for next sending. */ + void netStatusSave(int nthChannel); + + /*======== Data stream function for tuple ============*/ + /* Broadcast the tuple. */ + void broadCastStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local broadcast the tuple through memory. */ + void localBroadCastStream(TupleTableSlot* tuple); + + /* Redistribute the tuple. */ + void redistributeStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local redistribute the tuple through memory. */ + void localRedistributeStream(TupleTableSlot* tuple); + + void redistributeSkewStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Send tuple with Roundrobin. */ + void roundRobinStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local roundrobin the tuple through memory. */ + void localRoundRobinStream(TupleTableSlot* tuple); + + /* Hybrid Stream Type. */ + void hybridStream(TupleTableSlot* tuple, DestReceiver* self); + + /*======== Data stream function for batch ============*/ + /* Broadcast the batch without compress. */ + void broadCastStream(VectorBatch* batch); + + /* Broadcast the batch with compress. */ + void broadCastStreamCompress(VectorBatch* batch); + + /* Local broadcast the batch throug memory. */ + void localBroadCastStream(VectorBatch* batch); + + /* Redistribute the batch. */ + void redistributeStream(VectorBatch* batch); + + /* Mark the data type of each column of a batch. */ + void serializeStreamTypeInit(); + + /*Serialize the given row of the batch into the buffer */ + void serializeStream(VectorBatch* batch, int index); + + /* Local redistribute the batch through memory. */ + void localRedistributeStream(VectorBatch* batch); + + /* Send tuple batch Roundrobin. */ + template + void roundRobinBatch(VectorBatch* batch); + + /* Local roundrobin the batch through memory. */ + void localRoundRobinStream(VectorBatch* batch); + + /* Hybrid Stream Type. */ + void hybridStream(VectorBatch* batch, DestReceiver* self); + + /* Flush the tuple buffer to the destination. */ + void sendByteStream(int nthChannel); + + /* Copy the batch/tuple to shared memory. */ + void sendByMemory(TupleTableSlot* tuple, VectorBatch* batchSrc, int nthChannel, int nthRow = -1); + + /* Mark local stream as finished. */ + void finalizeLocalStream(); + + /* Init data buffer in shared context. */ + void initSharedContext(); + + /* Flush the data in the buffer. */ + void flushStream(); + + /* Set up the write transaction status for the stream thread. */ + void setUpStreamTxnEnvironment(); + + /* Report error to consumer node. */ + void reportError(); + + /* Report notice to consumer node. */ + void reportNotice(); + + /* Get the dummy attribute. */ + bool isDummy(); + + /* Get the stream smp distriType. */ + bool isLocalStream(); + + /* Copy snapshot. */ + void copySnapShot(); + + /* Wait thread ID ready. */ + void waitThreadIdReady(); + +public: + /* All get function. */ + + /* Get database name. */ + char* getDbName(); + + /* Get user name. */ + char* getUserName(); + + /* Get the wlm params. */ + WLMGeneralParam getWlmParams(); + + uint32 getExplainThreadid(); + + unsigned char getExplainTrack(); + + /* Get the serialize plan. */ + PlannedStmt* getPlan(); + + /* Get the snap shot data. */ + Snapshot getSnapShot(); + + /* Get the params. */ + ParamListInfo getParams(); + + /* Get the command dest. */ + CommandDest getDest(); + + /* Get the instrumentation stream. */ + StreamInstrumentation* getStreamInstrumentation(); + + /* Get the OBS instrumentation. */ + OBSInstrumentation* getOBSInstrumentation(); + + /* Get the Session Memory structure. */ + SessionLevelMemory* getSessionMemory(); + + /* Get child slot. */ + int getChildSlot(); + + /* Get parent session id. */ + uint64 getParentSessionid(); + + /* Get parent Plannode id. */ + int getParentPlanNodeId(); + + /* Get sub producer list. */ + List* getSubProducerList(); + + /* Get the value of sync_guc_variables. */ + struct config_generic** get_sync_guc_variables(); + + /* Get the memory shared context. */ + StreamSharedContext* getSharedContext(); + + int getNth(); + + /* Get thread init flag. */ + bool getThreadInit() + { + return m_threadInit; + } + + void getUniqueSQLKey(uint64* unique_id, Oid* user_id, uint32* cn_id); + + /* All set function. */ + + /* Get/set postmaster child slot. */ + void setChildSlot(int childSlot); + + /* Set sub producer list. */ + void setSubProducerList(List* subProducerList); + + /* Set sub consumer list. */ + void setSubConsumerList(List* subProducerList); + + /* Set parent session id. */ + void setParentSessionid(uint64 sessionid); + + /* Set the Session Memory structure. */ + void setSessionMemory(SessionLevelMemory* sessionMemory); + + /* Set shared context for in-memory data exchange. */ + void setSharedContext(StreamSharedContext* sharedContext); + + /* Set thread init flag. */ + void setThreadInit(bool flag) + { + m_threadInit = flag; + } + + void setUniqueSQLKey(uint64 unique_sql_id, Oid unique_user_id, uint32 unique_cn_id); + + /* The plan the producer thread will run. */ + PlannedStmt* m_plan; + + /* Database name. */ + char* m_databaseName; + + /* User name. */ + char* m_userName; + + /* Session memory. */ + SessionLevelMemory* m_sessionMemory; + + /* A list to remember the sub producer. */ + List* m_subProducerList; + + /* Transaction context the producer thread will hold. */ + StreamTxnContext m_streamTxnCxt; + + /* Instrumentation data. */ + StreamInstrumentation* m_instrStream; + + /* OBS Instrumentation data */ + OBSInstrumentation* m_obsinstr; + + /* Carry the sync_guc_variables to stream thread. */ + struct config_generic** m_sync_guc_variables; + + ParamListInfo m_params; + + StreamSharedContext* m_sharedContext; + + /* + * MPP recursive execution support + * + * Record the orign nodelist in case of DN pruned in with-recursive execution + * mode, because the global plan step synchronization we need each datanode's + * produer start up without short-cut at its execution time. + */ + /* + * Store the original corresponding consumer side's nodelist, normally used to + * send redis/broacast target + */ + List* m_originConsumerNodeList; + + /* + * Store the original corresponding consumer side's nodelist, norammly used to + * respecify the execution stop flag + */ + List* m_originProducerExecNodeList; + + StreamSyncParam m_syncParam; + +private: + /* Set distribute Idx. */ + void setDistributeIdx(); + + /* Set distribute info. */ + void setDistributeInfo(); + + /* Two different major redistribute function for tuple. */ + void (StreamProducer::*m_channelCalFun)(TupleTableSlot* tuple); + + /* Vector redistribute function for batch. */ + void (StreamProducer::*m_channelCalVecFun)(VectorBatch* batch); + + /* Choose which node to send by hash value. */ + inline uint2 NodeLocalizer(ScalarValue hashValue); + + /* Choose which thread to send by hash value. */ + inline int ThreadLocalizer(ScalarValue hashValue, int dop); + + template + void redistributeBatchChannel(VectorBatch* batch); + + template + void redistributeTupleChannel(TupleTableSlot* tuple); + + /* Choose which channel to send by hash value. */ + template + inline int ChannelLocalizer(ScalarValue hashValue, int Dop, int nodeSize); + + /* Building binding function. */ + template + void BindingRedisFunction(); + + /* Dispatch batch sending function. */ + void DispatchBatchRedistrFunction(int len); + + /* Dispatch tuple sending function. */ + void DispatchRowRedistrFunction(int len); + + /* Dispatch batch sending function by redistribute type. */ + template + void DispatchBatchRedistrFunctionByRedisType(); + + /* Dispatch tuple sending function by redistribute type. */ + template + void DispatchRowRedistrFunctionByRedisType(); + + typedef Datum (*hashFun)(Datum value); + + void AddCheckInfo(int nthChannel); + + int findLocalChannel(); + + inline uint2 NodeLocalizerForSlice(Const **distValues); + + inline int ThreadLocalizerForSlice(ScalarValue hashValue, int dop) const; + + template + int ChannelLocalizerForSlice(ScalarValue hashValue, Const **distValues, int dop); + + template + void redistributeTupleChannelForSlice(TupleTableSlot *tuple); + + void DispatchRowRedistrFunctionForSlice(); + + template + void redistributeBatchChannelForSlice(VectorBatch* batch); + + void DispatchBatchRedistrFunctionForSlice(); + +private: + /* Hash function for redistribute. */ + hashFun* m_hashFun; + + /* Wlm params. */ + WLMGeneralParam m_wlmParams; + + uint32 m_explain_thread_id; + + bool m_explain_track; + + /* + * Producer is dummy means it will + * do very little thing + * 1) init the child stream thread + * 2) will end as quick as possible, send nothing outside. + */ + bool m_isDummy; + + /* A list to remember the sub consumer */ + List* m_subConsumerList; + + /* Postmaster child slot. */ + int m_postMasterChildSlot; + + /* A unique query id for debug purpose. */ + uint64 m_queryId; + + /* Null flag length of redistribute serialization */ + uint32 m_bitNullLen; + + /* Numeric flag length of redistribute serialization */ + uint32 m_bitNumericLen; + + /* temp buffer for redistribute */ + char* m_tempBuffer; + + /* Mark the data type of each column of a batch. */ + uint32* m_colsType; + + /* Parent session ID. */ + uint64 m_parentSessionid; + + /* Parent planNode ID*/ + int m_parentPlanNodeId; + + /* The tuple description for the output data. */ + TupleDesc m_desc; + + /* The consumer nodes information. */ + ExecNodes* m_consumerNodes; + + /* The stream type. */ + StreamType m_streamType; + + /* The dest type the producer thread will follow. */ + CommandDest m_dest; + + /* The bucket map for redistribute. */ + uint2* m_bucketMap; + + /* boundary extracted from ExecNodes if redistribute by range/list */ + ExecBoundary* m_sliceBoundary; + + /* A quick node index for distribute. */ + uint2** m_disQuickLocator; + + /* A tuple buffer for send message. */ + StringInfoData m_tupleBuffer; + + /* A tuple buffer for send message and check info . */ + StringInfoData m_tupleBufferWithCheck; + + /* The distribute key information. */ + List* m_distributeKey; + + /* Extract from key, as we can have multicolumn keys culrrently, hold the attribute number for convenient. */ + AttrNumber* m_distributeIdx; + + /* Net is init? */ + volatile bool m_netInit; + + /* Use this to protect the net init flag, we can't use spinlock as it may hit the stuck problem. */ + volatile sig_atomic_t m_netProtect; + + int m_roundRobinIdx; + + int m_locator[BatchMaxSize]; + + /* The send dest for local stream to send error message. */ + int m_nth; + + bool m_sharedContextInit; + int64 m_broadcastSize; + + void* m_skewState; + + int m_skewMatch[BatchMaxSize]; + + /* If thread already inited*/ + bool m_threadInit; + + /* instrumentation: */ + uint64 m_uniqueSQLId; + Oid m_uniqueSQLUserId; + uint32 m_uniqueSQLCNId; +}; + +extern THR_LOCAL StreamProducer* streamProducer; + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ */ diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamTransportComm.h postgresql-hll-2.14/include/distributelayer/streamTransportComm.h --- postgresql-hll-2.14_old/include/distributelayer/streamTransportComm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamTransportComm.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamTransportComm.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamTransportComm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMTRANSPORTCOMM_H_ +#define STREAMTRANSPORTCOMM_H_ + +class StreamCOMM : public StreamTransport { +public: + StreamCOMM(libcommaddrinfo* addr, bool flag); + ~StreamCOMM(); + + /* Send a normal message. */ + int send(char msgtype, const char* msg, size_t len); + + /* Flush pending output. */ + void flush(); + + /* Close stream. */ + void release(); + + /* Init stream port. */ + void init(char* dbname, char* usrname); + + /* Is stream closed? */ + bool isClosed(); + + /* Allocate net buffer for stream port. */ + void allocNetBuffer(); + + /* Set send buffer active. */ + bool setActive(); + + /* Set send buffer inactive. */ + void setInActive(); + + /* Update connection info. */ + void updateInfo(StreamConnInfo* connInfo); + +public: + /* address array. */ + libcommaddrinfo* m_addr; +}; + +#endif /* STREAMTRANSPORTCOMM_H_ */ diff -uprN postgresql-hll-2.14_old/include/distributelayer/streamTransportCore.h postgresql-hll-2.14/include/distributelayer/streamTransportCore.h --- postgresql-hll-2.14_old/include/distributelayer/streamTransportCore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/distributelayer/streamTransportCore.h 2020-12-12 17:06:43.109346258 +0800 @@ -0,0 +1,107 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamTransportCore.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamTransportCore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMTRANSPORTCORE_H_ +#define STREAMTRANSPORTCORE_H_ + +enum StreamTransType { STREAM_COMM, STREAM_MEM }; + +class StreamTransport : public BaseObject { +public: + StreamTransport() + {} + + virtual ~StreamTransport() + {} + + virtual int send(char msgtype, const char* msg, size_t len) + { + Assert(false); + return 0; + } + + virtual void flush() + { + Assert(false); + } + + virtual void release() + { + Assert(false); + } + + virtual bool isClosed() + { + Assert(false); + return false; + } + + virtual void init(char* dbname, char* usrname) + { + Assert(false); + } + + virtual void allocNetBuffer() + { + Assert(false); + } + + virtual bool setActive() + { + Assert(false); + return false; + } + + virtual void setInActive() + { + Assert(false); + } + + virtual void updateInfo(StreamConnInfo* connInfo) + { + Assert(false); + } + +public: + /* Node name of data node sending data, only for consumer currently. */ + char m_nodeName[NAMEDATALEN]; + + /* Oid of data node sending data, only for consumer currently. */ + Oid m_nodeoid; + + /* Transport type. */ + StreamTransType m_type; + + /* Mark if transport is for producer */ + bool m_sendSide; + + /* Communication port. */ + Port* m_port; + + /* Stream buffer. */ + StreamBuffer* m_buffer; +}; + +#endif /* STREAMTRANSPORTCORE_H_ */ diff -uprN postgresql-hll-2.14_old/include/eSDKOBS.h postgresql-hll-2.14/include/eSDKOBS.h --- postgresql-hll-2.14_old/include/eSDKOBS.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/eSDKOBS.h 2020-12-12 17:06:43.110346271 +0800 @@ -0,0 +1,1454 @@ +/********************************************************************************* +* Copyright 2019 Huawei Technologies Co.,Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); you may not use +* this file except in compliance with the License. You may obtain a copy of the +* License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software distributed +* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +* CONDITIONS OF ANY KIND, either express or implied. See the License for the +* specific language governing permissions and limitations under the License. +********************************************************************************** +*/ +#ifndef ESDKOBS_H +#define ESDKOBS_H + +#include +#if defined __GNUC__ || defined LINUX +#include +#else +#include +#endif + +#ifdef WIN32 +#ifdef OBS_EXPORTS +#define eSDK_OBS_API __declspec(dllexport) +#else +#define eSDK_OBS_API __declspec(dllimport) +#endif +#else +#define eSDK_OBS_API __attribute__((__visibility__("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define OBS_INIT_WINSOCK 1 +#define OBS_INIT_ALL (OBS_INIT_WINSOCK) +#define OBS_MAX_DELETE_OBJECT_NUMBER 1000 +#define OBS_MAX_DELETE_OBJECT_DOC 1024000 + + +typedef enum +{ + OBS_STATUS_OK = 0, + OBS_STATUS_InitCurlFailed, + OBS_STATUS_InternalError, + OBS_STATUS_OutOfMemory, + OBS_STATUS_Interrupted, + OBS_STATUS_QueryParamsTooLong, + OBS_STATUS_FailedToIInitializeRequest, + OBS_STATUS_MetadataHeadersTooLong, + OBS_STATUS_BadContentType, + OBS_STATUS_ContentTypeTooLong, + OBS_STATUS_BadMd5, + OBS_STATUS_Md5TooLong, + OBS_STATUS_BadCacheControl, + OBS_STATUS_CacheControlTooLong, + OBS_STATUS_BadContentDispositionFilename, + OBS_STATUS_ContentDispositionFilenameTooLong, + OBS_STATUS_BadContentEncoding, + OBS_STATUS_ContentEncodingTooLong, + OBS_STATUS_BadIfMatchEtag, + OBS_STATUS_IfMatchEtagTooLong, + OBS_STATUS_BadIfNotMatchEtag, + OBS_STATUS_IfNotMatchEtagTooLong, + OBS_STATUS_UriTooLong, + OBS_STATUS_XmlParseFailure, + OBS_STATUS_UserIdTooLong, + OBS_STATUS_UserDisplayNameTooLong, + OBS_STATUS_EmailAddressTooLong, + OBS_STATUS_GroupUriTooLong, + OBS_STATUS_PermissionTooLong, + OBS_STATUS_TooManyGrants, + OBS_STATUS_BadGrantee, + OBS_STATUS_BadPermission, + OBS_STATUS_XmlDocumentTooLarge, + OBS_STATUS_NameLookupError, + OBS_STATUS_FailedToConnect, + OBS_STATUS_ServerFailedVerification, + OBS_STATUS_ConnectionFailed, + OBS_STATUS_AbortedByCallback, + OBS_STATUS_PartialFile, + OBS_STATUS_InvalidParameter, + OBS_STATUS_NoToken, + OBS_STATUS_OpenFileFailed, + OBS_STATUS_EmptyFile, + + /** + * Errors from the obs service + **/ + OBS_STATUS_AccessDenied, + OBS_STATUS_AccountProblem, + OBS_STATUS_AmbiguousGrantByEmailAddress, + OBS_STATUS_BadDigest, + OBS_STATUS_BucketAlreadyExists, + OBS_STATUS_BucketAlreadyOwnedByYou, + OBS_STATUS_BucketNotEmpty, + OBS_STATUS_CredentialsNotSupported, + OBS_STATUS_CrossLocationLoggingProhibited, + OBS_STATUS_EntityTooSmall, + OBS_STATUS_EntityTooLarge, + OBS_STATUS_ExpiredToken, + OBS_STATUS_IllegalVersioningConfigurationException, + OBS_STATUS_IncompleteBody, + OBS_STATUS_IncorrectNumberOfFilesInPostRequest, + OBS_STATUS_InlineDataTooLarge, + OBS_STATUS_InvalidAccessKeyId, + OBS_STATUS_InvalidAddressingHeader, + OBS_STATUS_InvalidArgument, + OBS_STATUS_InvalidBucketName, + OBS_STATUS_InvalidKey, + OBS_STATUS_InvalidBucketState, + OBS_STATUS_InvalidDigest, + OBS_STATUS_InvalidLocationConstraint, + OBS_STATUS_InvalidObjectState, + OBS_STATUS_InvalidPart, + OBS_STATUS_InvalidPartOrder, + OBS_STATUS_InvalidPayer, + OBS_STATUS_InvalidPolicyDocument, + OBS_STATUS_InvalidRange, + OBS_STATUS_InvalidRedirectLocation, + OBS_STATUS_InvalidRequest, + OBS_STATUS_InvalidSecurity, + OBS_STATUS_InvalidSOAPRequest, + OBS_STATUS_InvalidStorageClass, + OBS_STATUS_InvalidTargetBucketForLogging, + OBS_STATUS_InvalidToken, + OBS_STATUS_InvalidURI, + OBS_STATUS_MalformedACLError, + OBS_STATUS_MalformedPolicy, + OBS_STATUS_MalformedPOSTRequest, + OBS_STATUS_MalformedXML, + OBS_STATUS_MaxMessageLengthExceeded, + OBS_STATUS_MaxPostPreDataLengthExceededError, + OBS_STATUS_MetadataTooLarge, + OBS_STATUS_MethodNotAllowed, + OBS_STATUS_MissingAttachment, + OBS_STATUS_MissingContentLength, + OBS_STATUS_MissingRequestBodyError, + OBS_STATUS_MissingSecurityElement, + OBS_STATUS_MissingSecurityHeader, + OBS_STATUS_NoLoggingStatusForKey, + OBS_STATUS_NoSuchBucket, + OBS_STATUS_NoSuchKey, + OBS_STATUS_NoSuchLifecycleConfiguration, + OBS_STATUS_NoSuchUpload, + OBS_STATUS_NoSuchVersion, + OBS_STATUS_NotImplemented, + OBS_STATUS_NotSignedUp, + OBS_STATUS_NotSuchBucketPolicy, + OBS_STATUS_OperationAborted, + OBS_STATUS_PermanentRedirect, + OBS_STATUS_PreconditionFailed, + OBS_STATUS_Redirect, + OBS_STATUS_RestoreAlreadyInProgress, + OBS_STATUS_RequestIsNotMultiPartContent, + OBS_STATUS_RequestTimeout, + OBS_STATUS_RequestTimeTooSkewed, + OBS_STATUS_RequestTorrentOfBucketError, + OBS_STATUS_SignatureDoesNotMatch, + OBS_STATUS_ServiceUnavailable, + OBS_STATUS_SlowDown, + OBS_STATUS_TemporaryRedirect, + OBS_STATUS_TokenRefreshRequired, + OBS_STATUS_TooManyBuckets, + OBS_STATUS_UnexpectedContent, + OBS_STATUS_UnresolvableGrantByEmailAddress, + OBS_STATUS_UserKeyMustBeSpecified, + OBS_STATUS_InsufficientStorageSpace, + OBS_STATUS_NoSuchWebsiteConfiguration, + OBS_STATUS_NoSuchBucketPolicy, + OBS_STATUS_NoSuchCORSConfiguration, + OBS_STATUS_InArrearOrInsufficientBalance, + OBS_STATUS_NoSuchTagSet, + OBS_STATUS_ErrorUnknown, + /* + * The following are HTTP errors returned by obs without enough detail to + * distinguish any of the above OBS_STATUS_error conditions + */ + OBS_STATUS_HttpErrorMovedTemporarily, + OBS_STATUS_HttpErrorBadRequest, + OBS_STATUS_HttpErrorForbidden, + OBS_STATUS_HttpErrorNotFound, + OBS_STATUS_HttpErrorConflict, + OBS_STATUS_HttpErrorUnknown, + + /* + * posix new add errors + */ + OBS_STATUS_QuotaTooSmall, + + /* + * obs-meta errors + */ + OBS_STATUS_MetadataNameDuplicate, + + + OBS_STATUS_BUTT +} obs_status; + + +typedef enum +{ + OBS_URI_STYLE_VIRTUALHOST = 0, + OBS_URI_STYLE_PATH = 1 +} obs_uri_style; + +typedef enum +{ + OBS_PROTOCOL_HTTPS = 0, + OBS_PROTOCOL_HTTP = 1 +} obs_protocol; + +typedef enum +{ + OBS_STORAGE_CLASS_STANDARD = 0, /* STANDARD */ + OBS_STORAGE_CLASS_STANDARD_IA = 1, /* STANDARD_IA */ + OBS_STORAGE_CLASS_GLACIER = 2, /* GLACIER */ + OBS_STORAGE_CLASS_BUTT +} obs_storage_class; + +typedef enum image_process_mode +{ + obs_image_process_invalid_mode, + obs_image_process_cmd, + obs_image_process_style +}image_process_mode; + +typedef enum +{ + OBS_CANNED_ACL_PRIVATE = 0, //used by s3 and obs api + OBS_CANNED_ACL_PUBLIC_READ = 1, //used by s3 and obs api + OBS_CANNED_ACL_PUBLIC_READ_WRITE = 2, //used by s3 and obs api + OBS_CANNED_ACL_AUTHENTICATED_READ = 3, //only used by s3 api + OBS_CANNED_ACL_BUCKET_OWNER_READ = 4, //only used by s3 api + OBS_CANNED_ACL_BUCKET_OWNER_FULL_CONTROL = 5, //only used by s3 api + OBS_CANNED_ACL_LOG_DELIVERY_WRITE = 6, //only used by s3 api + OBS_CANNED_ACL_PUBLIC_READ_DELIVERED = 7, //only used by obs api + OBS_CANNED_ACL_PUBLIC_READ_WRITE_DELIVERED = 8, //only used by obs api + OBS_CANNED_ACL_BUTT +} obs_canned_acl; + +typedef enum +{ + OBS_REDUNDANCY_1AZ = 0, + OBS_REDUNDANCY_3AZ = 1, //only used by obs api + OBS_REDUNDANCY_BUTT +} obs_az_redundancy; + + +typedef enum +{ + OBS_GRANT_READ = 0, + OBS_GRANT_WRITE = 1, + OBS_GRANT_READ_ACP = 2, + OBS_GRANT_WRITE_ACP = 3, + OBS_GRANT_FULL_CONTROL = 4, + OBS_GRANT_READ_DELIVERED = 5, + OBS_GRANT_FULL_CONTROL_DELIVERED = 6, + OBS_GRANT_BUTT +} obs_grant_domain; + + +typedef enum +{ + OBS_GRANTEE_TYPE_HUAWEI_CUSTOMER_BYEMAIL = 0, // only used by s3 api + OBS_GRANTEE_TYPE_CANONICAL_USER = 1, // used by both of s3 and obs api + OBS_GRANTEE_TYPE_ALL_OBS_USERS = 2, // only used by s3 api + OBS_GRANTEE_TYPE_ALL_USERS = 3, // used by both of s3 and obs api + OBS_GRANTEE_TYPE_LOG_DELIVERY = 4, // only used by s3 api + OBS_GRANTEE_TYPE_BUTT +} obs_grantee_type; + +typedef enum +{ + OBS_PERMISSION_READ = 0, + OBS_PERMISSION_WRITE = 1, + OBS_PERMISSION_READ_ACP = 2, + OBS_PERMISSION_WRITE_ACP = 3, + OBS_PERMISSION_FULL_CONTROL = 4, + OBS_PERMISSION_BUTT +} obs_permission; + +typedef enum +{ + OBS_TIER_NULL = 0, + OBS_TIER_STANDARD, + OBS_TIER_EXPEDITED, + OBS_TIER_BULK, +} obs_tier; + +typedef enum +{ + UPLOAD_NOTSTART, + UPLOADING, + UPLOAD_FAILED, + UPLOAD_SUCCESS, + STATUS_BUTT +}part_upload_status; + +typedef enum +{ + OBS_SMN_FILTER_NULL = 0, + OBS_SMN_FILTER_PREFIX, + OBS_SMN_FILTER_SUFFIX +}obs_smn_filter_rule_enum; + +typedef enum +{ + SMN_EVENT_NULL = 0, + SMN_EVENT_OBJECT_CREATED_ALL, + SMN_EVENT_OBJECT_CREATED_PUT, + SMN_EVENT_OBJECT_CREATED_POST, + SMN_EVENT_OBJECT_CREATED_COPY, + SMN_EVENT_OBJECT_CREATED_COMPLETE_MULTIPART_UPLOAD, + SMN_EVENT_OBJECT_REMOVED_ALL, + SMN_EVENT_OBJECT_REMOVED_DELETE, + SMN_EVENT_OBJECT_REMOVED_DELETE_MARKER_CREATED, + SMN_EVENT_REDUCED_REDUNDANCY_LOST_OBJECT +}obs_smn_event_enum; + +typedef enum +{ + DOWNLOAD_NOTSTART, + DOWNLOADING, + DOWNLOAD_FAILED, + DOWNLOAD_SUCCESS, + COMBINE_SUCCESS, + DOWN_STATUS_BUTT +}download_status; + +typedef enum +{ + OBS_USE_API_S3 = 0, + OBS_USE_API_OBS = 1 +}obs_use_api; + +typedef enum +{ + OBS_NO_CERTIFICATE, + OBS_DEFAULT_CERTIFICATE, + OBS_DEFINED_CERTIFICATE +}obs_certificate_conf; + +typedef enum +{ + OBS_ENCRYPTION_KMS, + OBS_ENCRYPTION_SSEC +}obs_encryption_type; + +typedef enum +{ + OBJECT_DELIVERED_TRUE = 0, // Default value is true. + OBJECT_DELIVERED_FALSE = 1 +}obs_object_delivered; + +typedef enum +{ + BUCKET_DELIVERED_FALSE = 0, // Default value is false. + BUCKET_DELIVERED_TRUE = 1 +}obs_bucket_delivered; + + +typedef enum +{ + OBS_BUCKET_OBJECT = 0, //object bucket + OBS_BUCKET_PFS = 1 //pfs bucket +}obs_bucket_type; + +typedef enum +{ + OBS_BUCKET_LIST_ALL = 0, //list all type bucket + OBS_BUCKET_LIST_OBJECT = 1, //list object bucket + OBS_BUCKET_LIST_PFS = 2 //list pfs bucket +}obs_bucket_list_type; + +#define OBS_COMMON_LEN_256 256 + +#define OBS_MAX_ACL_GRANT_COUNT 100 + +#define OBS_MAX_GRANTEE_EMAIL_ADDRESS_SIZE 128 + +#define OBS_MAX_GRANTEE_USER_ID_SIZE 128 + +#define OBS_MAX_GRANTEE_DISPLAY_NAME_SIZE 128 + +#define OBS_MAX_HOSTNAME_SIZE 255 + +#define OBS_MAX_KEY_SIZE 1024 + +#define OBS_MAX_METADATA_SIZE 4096 + +#define OBS_METADATA_HEADER_NAME_PREFIX "x-amz-meta-" + +#define OBS_VERSION_STATUS_ENABLED "Enabled" + +#define OBS_VERSION_STATUS_SUSPENDED "Suspended" + +#define OBS_MAX_METADATA_COUNT \ + (OBS_MAX_METADATA_SIZE / (sizeof(OBS_METADATA_HEADER_NAME_PREFIX "nv") - 1)) + + +typedef struct obs_request_context obs_request_context; + +typedef struct tag_obs_create_bucket_params +{ + obs_canned_acl canned_acl; + obs_az_redundancy az_redundancy; + const char *location_constraint; +} obs_create_bucket_params; + + +typedef struct obs_acl_grant +{ + obs_grantee_type grantee_type; + union + { + struct + { + char email_address[OBS_MAX_GRANTEE_EMAIL_ADDRESS_SIZE]; + } huawei_customer_by_email; // only used by s3 api + struct + { + char id[OBS_MAX_GRANTEE_USER_ID_SIZE]; + char display_name[OBS_MAX_GRANTEE_DISPLAY_NAME_SIZE]; // only used by s3 api + } canonical_user; + } grantee; + obs_permission permission; + obs_bucket_delivered bucket_delivered; // only used by obs api +}obs_acl_grant; + +typedef struct obs_acl_group +{ + int acl_grant_count; + obs_acl_grant *acl_grants; +}obs_acl_group; + +typedef struct obs_object_info +{ + char* key; + char* version_id; +}obs_object_info; + +typedef struct obs_delete_object_info +{ + unsigned int keys_number; + int quiet; +}obs_delete_object_info; + +typedef struct manager_acl_info +{ + obs_object_info object_info; + char *owner_id; + char *owner_display_name; + int *acl_grant_count_return; + obs_object_delivered object_delivered; // only used by obs api + obs_acl_grant *acl_grants; +}manager_acl_info; + + +typedef struct obs_upload_part_info +{ + unsigned int part_number; + char *upload_id; +}obs_upload_part_info; + +typedef struct obs_complete_upload_Info +{ + unsigned int part_number; + char *etag; +}obs_complete_upload_Info; + +typedef struct list_part_info +{ + char *upload_id; + unsigned int max_parts; + unsigned int part_number_marker; +}list_part_info; + + +typedef struct obs_name_value +{ + char *name; + char *value; +} obs_name_value; + +typedef struct obs_error_details +{ + const char *message; + + const char *resource; + + const char *further_details; + + int extra_details_count; + + obs_name_value *extra_details; +} obs_error_details; + +typedef struct obs_response_properties +{ + const char *request_id; + + const char *request_id2; + + const char *content_type; + + uint64_t content_length; + + const char *server; + + const char *etag; + + const char *expiration; + + const char *website_redirect_location; + + const char *version_id; + + int64_t last_modified; + + int meta_data_count; + + const obs_name_value *meta_data; + + char use_server_side_encryption; + + const char *allow_origin; + + const char *allow_headers; + + const char *max_age; + + const char *allow_methods; + + const char *expose_headers; + + const char *storage_class; + + const char *server_side_encryption; + + const char *kms_key_id; + + const char *customer_algorithm; + + const char *customer_key_md5; + + const char *bucket_location; + + const char *obs_version; + + const char *restore; + + const char *obs_object_type; + + const char *obs_next_append_position; + + const char *obs_head_epid; + + const char *reserved_indicator; +} obs_response_properties; + +typedef struct obs_list_objects_content +{ + const char *key; + int64_t last_modified; + const char *etag; + uint64_t size; + const char *owner_id; + const char *owner_display_name; + const char *storage_class; + const char *type; +} obs_list_objects_content; + +typedef struct obs_version +{ + + const char *key; + const char *version_id; + const char *is_latest; + int64_t last_modified; + const char *etag; + uint64_t size; + const char *owner_id; + const char *owner_display_name; + const char *storage_class; + const char *is_delete; +} obs_version; + +typedef struct obs_list_versions +{ + const char* bucket_name; + const char* prefix; + const char* key_marker; + const char* delimiter; + const char* max_keys; + obs_version* versions; + int versions_count; + const char** common_prefixes; + int common_prefixes_count; +} obs_list_versions; + + +typedef struct obs_list_parts +{ + unsigned int part_number; + int64_t last_modified; + const char *etag; + uint64_t size; + const char *storage_class; +}obs_list_parts; + +typedef struct obs_list_multipart_upload +{ + const char *key; + const char *upload_id; + const char *initiator_id; + const char *initiator_display_name; + const char *owner_id; + const char *owner_display_name; + const char *storage_class; + int64_t initiated; +} obs_list_multipart_upload; + +typedef struct obs_lifecycle_transtion +{ + const char *date; + const char *days; + obs_storage_class storage_class; +}obs_lifecycle_transtion; + +typedef struct obs_lifecycle_noncurrent_transtion +{ + const char *noncurrent_version_days; + obs_storage_class storage_class; +}obs_lifecycle_noncurrent_transtion; + +typedef struct obs_lifecycle_conf +{ + const char *date; + const char *days; + const char *id; + const char *prefix; + const char *status; + const char *noncurrent_version_days; + obs_lifecycle_transtion * transition; + unsigned int transition_num; + obs_lifecycle_noncurrent_transtion * noncurrent_version_transition; + unsigned int noncurrent_version_transition_num; + +}obs_lifecycle_conf; + +typedef struct obs_bucket_cors_conf +{ + const char *id; + const char **allowed_method; + unsigned int allowed_method_number; + const char **allowed_origin; + unsigned int allowed_origin_number; + const char **allowed_header; + unsigned int allowed_header_number; + const char *max_age_seconds; + const char **expose_header; + unsigned int expose_header_number; +}obs_bucket_cors_conf; + +typedef struct obs_uploaded_parts_total_info +{ + int is_truncated; + unsigned int nextpart_number_marker; + char *initiator_id; + char *initiator_display_name; + char *owner_id; + char *owner_display_name; + char *sorage_class; + int parts_count; +}obs_uploaded_parts_total_info; + +typedef struct obs_copy_destination_object_info +{ + char *destination_bucket; + char *destination_key; + char *version_id; + int64_t *last_modified_return; + int etag_return_size; + char *etag_return; +}obs_copy_destination_object_info; + +typedef struct _obs_upload_file_configuration +{ + char *upload_file; + uint64_t part_size; + char * check_point_file; + int enable_check_point; + int task_num; +}obs_upload_file_configuration; + +typedef struct _obs_download_file_configuration +{ + char * downLoad_file; + uint64_t part_size; + char * check_point_file; + int enable_check_point; + int task_num; +}obs_download_file_configuration; + +typedef struct _obs_upload_file_part_info +{ + int part_num; + uint64_t start_byte; + uint64_t part_size; + part_upload_status status_return; +}obs_upload_file_part_info; + +typedef struct _obs_download_file_part_info +{ + int part_num; + uint64_t start_byte; + uint64_t part_size; + download_status status_return; +}obs_download_file_part_info; +typedef struct obs_set_bucket_redirect_all_conf +{ + const char *host_name; + const char *protocol; +}obs_set_bucket_redirect_all_conf; + +typedef struct obs_delete_objects +{ + const char *key; + const char *code; + const char *message; + const char *delete_marker; + const char *delete_marker_version_id; +} obs_delete_objects; + +typedef struct bucket_website_routingrule +{ + const char *key_prefix_equals; + const char *http_errorcode_returned_equals; + const char *protocol; + const char *host_name; + const char *replace_key_prefix_with; + const char *replace_key_with; + const char *http_redirect_code; +}bucket_website_routingrule; + +typedef struct obs_set_bucket_website_conf +{ + const char *suffix; + const char *key; + bucket_website_routingrule *routingrule_info; + int routingrule_count; +}obs_set_bucket_website_conf; + +typedef struct obs_smn_filter_rule +{ + obs_smn_filter_rule_enum name; + char* value; +}obs_smn_filter_rule; + + +typedef struct obs_smn_topic_configuration +{ + char* topic; + char* id; + obs_smn_filter_rule* filter_rule; + unsigned int filter_rule_num; + obs_smn_event_enum* event; + unsigned int event_num; +}obs_smn_topic_configuration; + + +typedef struct obs_smn_notification_configuration +{ + obs_smn_topic_configuration* topic_conf; + unsigned int topic_conf_num; +}obs_smn_notification_configuration; + + +/***************************response handle function*******************************************/ +typedef obs_status (obs_response_properties_callback)(const obs_response_properties *properties, + void *callback_data); + +typedef void (obs_response_complete_callback)(obs_status status, + const obs_error_details *error_details, void *callback_data); + +typedef int (obs_put_object_data_callback)(int buffer_size, char *buffer, + void *callback_data); + +typedef int (obs_append_object_data_callback)(int buffer_size, char *buffer, + void *callback_data); +typedef int (obs_modify_object_data_callback)(int buffer_size, char *buffer, + void *callback_data); + +typedef obs_status (obs_get_object_data_callback)(int buffer_size, const char *buffer, + void *callback_data); + +typedef obs_status (obs_list_service_callback)(const char *owner_id, + const char *owner_display_name, + const char *bucket_name, + int64_t creation_date_seconds, + void *callback_data); + +typedef obs_status (obs_list_service_obs_callback)(const char *owner_id, + const char *bucket_name, + int64_t creation_date_seconds, + const char *location, + void *callback_data); + +typedef obs_status (obs_get_bucket_storage_policy)(const char * storage_class_policy, + void *callback_data); + +typedef obs_status (obs_get_bucket_websiteconf_callback) (const char *hostname, const char *protocol, + const char *suffix,const char *key, const bucket_website_routingrule *routingrule, + int webdatacount, void *callback_data); + + +typedef int (obs_upload_data_callback)(int buffer_size, char *buffer, void *callback_data); + +typedef obs_status (obs_complete_multi_part_upload_callback)(const char *location, + const char *bucket, + const char *key, + const char* etag, + void *callback_data); + +typedef obs_status (obs_list_parts_callback_ex)(obs_uploaded_parts_total_info* uploaded_parts, + obs_list_parts *parts, void *callback_data); +typedef void (obs_upload_file_callback)(obs_status status, char *result_message, int part_count_return, + obs_upload_file_part_info * upload_info_list, void *callback_data); + +typedef obs_status (obs_list_objects_callback)(int is_truncated, const char *next_marker, + int contents_count, const obs_list_objects_content *contents, + int common_prefixes_count, const char **common_prefixes, + void *callback_data); + + +typedef obs_status (obs_list_multipart_uploads_callback)(int is_truncated, const char *next_marker, + const char *next_uploadId_marker, int uploads_count, + const obs_list_multipart_upload *uploads, int common_prefixes_count, + const char **common_prefixes, void *callback_data); + +typedef obs_status (obs_list_versions_callback)(int is_truncated, const char *next_key_marker, + const char *next_versionid_marker, const obs_list_versions *versions, + void *callback_data); + +typedef obs_status (get_lifecycle_configuration_callback) (obs_lifecycle_conf* bucket_lifecycle_conf, + unsigned int blcc_number, void *callback_data); + +typedef void (obs_download_file_callback)(obs_status status, char *result_message, + int part_count_return, obs_download_file_part_info * download_info_list, + void *callback_data); + +typedef obs_status (get_cors_configuration_callback)(obs_bucket_cors_conf* bucket_cors_conf, + unsigned int bcc_number, void *callback_data); + +typedef obs_status (obs_delete_object_data_callback)(int contents_count, + obs_delete_objects *contents, void *callback_data); + +typedef obs_status (obs_smn_callback)(obs_smn_notification_configuration* notification_conf, + void *callback_data); + + +/**************************response handler struct**********************************************/ + +typedef struct obs_response_handler +{ + obs_response_properties_callback *properties_callback; + obs_response_complete_callback *complete_callback; +} obs_response_handler; + +typedef struct obs_list_objects_handler +{ + obs_response_handler response_handler; + obs_list_objects_callback *list_Objects_callback; +} obs_list_objects_handler; + +typedef struct obs_list_versions_handler +{ + obs_response_handler response_handler; + obs_list_versions_callback *list_versions_callback; +} obs_list_versions_handler; + +typedef struct obs_list_multipart_uploads_handler +{ + obs_response_handler response_handler; + obs_list_multipart_uploads_callback *list_mulpu_callback; +} obs_list_multipart_uploads_handler; + +typedef struct obs_put_object_handler +{ + obs_response_handler response_handler; + obs_put_object_data_callback *put_object_data_callback; +} obs_put_object_handler; +typedef struct obs_append_object_handler +{ + obs_response_handler response_handler; + obs_append_object_data_callback *append_object_data_callback; +} obs_append_object_handler; + +typedef struct obs_modify_object_handler +{ + obs_response_handler response_handler; + obs_modify_object_data_callback *modify_object_data_callback; +} obs_modify_object_handler; + + +typedef struct obs_get_object_handler +{ + obs_response_handler response_handler; + obs_get_object_data_callback *get_object_data_callback; +} obs_get_object_handler; + +typedef struct obs_lifecycle_handler +{ + obs_response_handler response_handler; + get_lifecycle_configuration_callback *get_lifecycle_callback; +} obs_lifecycle_handler; + +typedef struct obs_cors_handler +{ + obs_response_handler response_handler; + get_cors_configuration_callback *get_cors_callback; +} obs_cors_handler; + + +typedef struct obs_upload_handler +{ + obs_response_handler response_handler; + obs_upload_data_callback *upload_data_callback; +} obs_upload_handler; + +typedef struct obs_complete_multi_part_upload_handler +{ + obs_response_handler response_handler; + obs_complete_multi_part_upload_callback *complete_multipart_upload_callback; +} obs_complete_multi_part_upload_handler; + +typedef struct obs_list_parts_handler +{ + obs_response_handler response_handler; + obs_list_parts_callback_ex *list_parts_callback_ex; +} obs_list_parts_handler; + +typedef struct obs_upload_file_response_handler +{ + obs_response_handler response_handler; + obs_upload_file_callback *upload_file_callback; +} obs_upload_file_response_handler; +typedef struct __obs_download_file_response_handler +{ + obs_response_handler response_handler; + obs_download_file_callback *download_file_callback; +}obs_download_file_response_handler; + +typedef struct obs_delete_object_handler +{ + obs_response_handler response_handler; + obs_delete_object_data_callback *delete_object_data_callback; +} obs_delete_object_handler; + +typedef struct obs_get_bucket_websiteconf_handler +{ + obs_response_handler response_handler; + obs_get_bucket_websiteconf_callback *get_bucket_website_conf_callback; +} obs_get_bucket_websiteconf_handler; + +typedef struct obs_smn_handler +{ + obs_response_handler response_handler; + obs_smn_callback *get_smn_callback_func; +}obs_smn_handler; + + +/**************************return struct*******************************************/ +typedef struct obs_bucket_context +{ + char *host_name; + char *bucket_name; + obs_protocol protocol; + obs_uri_style uri_style; + char *access_key; + char *secret_access_key; + char *certificate_info; + obs_storage_class storage_class; + char * token; + char * epid; + obs_bucket_type bucket_type; + obs_bucket_list_type bucket_list_type; +} obs_bucket_context; + +typedef enum +{ + OBS_HTTP2_OPEN = 0, + OBS_HTTP2_CLOSE = 1 +} obs_http2_switch; + +typedef enum +{ + OBS_BBR_OPEN = 0, + OBS_BBR_CLOSE = 1 +} obs_bbr_switch; + +typedef enum +{ + OBS_OPENSSL_CLOSE =0, + OBS_OPENSSL_OPEN = 1 +} obs_openssl_switch; + +typedef enum +{ + OBS_NEGOTIATION_TYPE =0, + OBS_OBS_TYPE =1, + OBS_S3_TYPE =2 +}obs_auth_switch; + +typedef enum +{ + OBS_NO_METADATA_ACTION =0, + OBS_REPLACE =1, + OBS_REPLACE_NEW =2 +}metadata_action_indicator; + +typedef struct obs_http_request_option +{ + int speed_limit; + int speed_time; + int connect_time; + int max_connected_time; + char *proxy_host; + char *proxy_auth; + char *ssl_cipher_list; + obs_http2_switch http2_switch; + obs_bbr_switch bbr_switch; + obs_auth_switch auth_switch; + long buffer_size; +} obs_http_request_option; + +typedef struct temp_auth_configure +{ + long long int expires; + void (* temp_auth_callback)(char * temp_auth_url,char * temp_auth_headers,void *callback_data); + void * callback_data; +}temp_auth_configure; + +typedef struct obs_options +{ + obs_bucket_context bucket_options; + obs_http_request_option request_options; + temp_auth_configure *temp_auth; +} obs_options; + +typedef struct image_process_configure +{ + image_process_mode image_process_mode; + char * cmds_stylename; +}image_process_configure; + +typedef struct obs_get_conditions +{ + uint64_t start_byte; + uint64_t byte_count; + int64_t if_modified_since; + int64_t if_not_modified_since; + char *if_match_etag; + char *if_not_match_etag; + image_process_configure * image_process_config; +} obs_get_conditions; + +typedef struct file_object_config +{ + int auto_split; + char * file_name; + void (*print_process_callback)(uint64_t remain_bytes, int progress_rate); +}file_object_config; + +typedef struct grant_domain_config +{ + char *domain; + obs_grant_domain grant_domain; +}grant_domain_config; + + + +typedef struct obs_put_properties +{ + char *content_type; + char *md5; + char *cache_control; + char *content_disposition_filename; + char *content_encoding; + char *website_redirect_location; + obs_get_conditions *get_conditions; + uint64_t start_byte; + uint64_t byte_count; + int64_t expires; + obs_canned_acl canned_acl; + obs_az_redundancy az_redundancy; + grant_domain_config *domain_config; + int meta_data_count; + obs_name_value *meta_data; + file_object_config * file_object_config; + metadata_action_indicator metadata_action; +} obs_put_properties; + +typedef struct server_side_encryption_params +{ + obs_encryption_type encryption_type; + char *kms_server_side_encryption; + char *kms_key_id; + char *ssec_customer_algorithm; + char *ssec_customer_key; + char *des_ssec_customer_algorithm; + char *des_ssec_customer_key; +}server_side_encryption_params; + +typedef obs_status (obs_get_bucket_storage_policy_callback)(const char * storage_class_policy, + void *callback_data); + +typedef struct obs_get_bucket_storage_class_handler +{ + obs_response_handler response_handler; + obs_get_bucket_storage_policy_callback *get_bucket_sorage_class_callback; +}obs_get_bucket_storage_class_handler; + +typedef obs_status (obs_get_bucket_tagging_callback)(int tagging_count, + obs_name_value *tagging_list, void *callback_data); + +typedef struct obs_get_bucket_tagging_handler +{ + obs_response_handler response_handler; + obs_get_bucket_tagging_callback *get_bucket_tagging_callback; +}obs_get_bucket_tagging_handler; + +typedef struct obs_list_service_handler +{ + obs_response_handler response_handler; + obs_list_service_callback *listServiceCallback; +} obs_list_service_handler; + +typedef struct obs_list_service_obs_handler +{ + obs_response_handler response_handler; + obs_list_service_obs_callback *listServiceCallback; +} obs_list_service_obs_handler; + +typedef struct bucket_logging_message +{ + char *target_bucket; + int target_bucket_size; + char *target_prefix; + int target_prefix_size; + obs_acl_grant *acl_grants; + int *acl_grant_count; + char *agency; + int agency_size; +}bucket_logging_message; + +/****************************init handle *****************************************************/ +eSDK_OBS_API obs_status obs_initialize(int win32_flags); + +eSDK_OBS_API void obs_deinitialize(); + +eSDK_OBS_API void init_obs_options(obs_options * options); + +eSDK_OBS_API int obs_status_is_retryable(obs_status status); + +eSDK_OBS_API obs_status set_online_request_max_count(uint32_t online_request_max); + +eSDK_OBS_API obs_status init_certificate_by_path(obs_protocol protocol, + obs_certificate_conf ca_conf, const char *path, int path_length); + +eSDK_OBS_API obs_status init_certificate_by_buffer(const char *buffer, int buffer_length); + +/*************************************bucket handle**************************************/ + +eSDK_OBS_API void create_bucket(const obs_options *options, obs_canned_acl canned_acl, + const char *location_constraint, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void create_bucket_with_params(const obs_options *options, const obs_create_bucket_params *param, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void create_pfs_bucket(const obs_options *options, obs_canned_acl canned_acl, + const char *location_constraint, obs_response_handler *handler, + void *callback_data); + +eSDK_OBS_API void list_bucket(const obs_options *options, obs_list_service_handler *handler, + void *callback_data); + +eSDK_OBS_API void list_bucket_obs(const obs_options *options, obs_list_service_obs_handler *handler, + void *callback_data); + +eSDK_OBS_API void delete_bucket(const obs_options *options, obs_response_handler *handler, void *callback_data); + + +eSDK_OBS_API void list_bucket_objects(const obs_options *options, const char *prefix, const char *marker, const char *delimiter, + int maxkeys, obs_list_objects_handler *handler, void *callback_data); + +// only object bucket can use +eSDK_OBS_API void list_versions(const obs_options *options, const char *prefix, const char *key_marker, const char *delimiter, + int maxkeys, const char *version_id_marker, obs_list_versions_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_quota(const obs_options *options, uint64_t storage_quota, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_quota(const obs_options *options, uint64_t *storagequota_return, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_policy(const obs_options *options, const char *policy, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_policy(const obs_options *options, int policy_return_size, + char *policy_return, obs_response_handler *handler, + void *callback_data); + +eSDK_OBS_API void delete_bucket_policy(const obs_options *options, obs_response_handler *handler, + void *callback_data); + +eSDK_OBS_API void set_bucket_version_configuration(const obs_options *options, const char *version_status, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_version_configuration(const obs_options *options, int status_return_size, + char *status_return, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_storage_class_policy(const obs_options *options, + obs_storage_class storage_class_policy, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_storage_class_policy(const obs_options *options, + obs_get_bucket_storage_class_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_tagging(const obs_options *options,obs_name_value * tagging_list, + unsigned int number, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_tagging(const obs_options *options, obs_get_bucket_tagging_handler *handler, + void *callback_data); + +eSDK_OBS_API void delete_bucket_tagging(const obs_options *options, obs_response_handler *handler, + void *callback_data); + + +eSDK_OBS_API void set_bucket_logging_configuration(const obs_options *options, char *target_bucket, char *target_prefix, + obs_acl_group *acl_group, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_logging_configuration_obs(const obs_options *options, char *target_bucket, char *target_prefix, char *agency, + obs_acl_group *acl_group, obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_logging_configuration(const obs_options *options, obs_response_handler *handler, + bucket_logging_message *logging_message_data, void *callback_data); + +// only object bucket can use +eSDK_OBS_API void set_bucket_website_configuration(const obs_options *options, + obs_set_bucket_redirect_all_conf *set_bucket_redirect_all, + obs_set_bucket_website_conf *set_bucket_website_conf, + obs_response_handler *handler, void *callback_data); +// only object bucket can use +eSDK_OBS_API void get_bucket_website_configuration(const obs_options *options, + obs_get_bucket_websiteconf_handler *handler, + void *callback_data); +// only object bucket can use +eSDK_OBS_API void delete_bucket_website_configuration(const obs_options *options, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_storage_info(const obs_options *options, int capacity_length, char *capacity, + int object_number_length, char *object_number, + obs_response_handler *handler, void *callback_data); + + eSDK_OBS_API void list_multipart_uploads(const obs_options *options, const char *prefix, const char *marker, const char *delimiter, + const char* uploadid_marke, int max_uploads, obs_list_multipart_uploads_handler *handler, + void *callback_data); + +eSDK_OBS_API void set_bucket_lifecycle_configuration(const obs_options *options, + obs_lifecycle_conf* bucket_lifecycle_conf, unsigned int blcc_number, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_lifecycle_configuration(const obs_options *options, + obs_lifecycle_handler *handler, void *callback_data); + +eSDK_OBS_API void delete_bucket_lifecycle_configuration(const obs_options *options, + obs_response_handler *handler, void *callback_data); + +// only object bucket can use +eSDK_OBS_API void set_bucket_cors_configuration(const obs_options *options, obs_bucket_cors_conf *obs_cors_conf_info, + unsigned int conf_num, obs_response_handler *handler, void *callback_data); + +// only object bucket can use +eSDK_OBS_API void get_bucket_cors_configuration(const obs_options *options, obs_cors_handler *handler, + void *callback_data); +// only object bucket can use +eSDK_OBS_API void delete_bucket_cors_configuration(const obs_options *options, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_notification_configuration(const obs_options *options, + obs_smn_notification_configuration* notification_conf, obs_response_handler *handler, + void *callback_data); + + +eSDK_OBS_API void get_notification_configuration(const obs_options *options, + obs_smn_handler *handler, void *callback_data); + +eSDK_OBS_API void set_bucket_acl(const obs_options * options, manager_acl_info * aclinfo, + obs_response_handler * handler, void *callback_data); + + +eSDK_OBS_API void set_bucket_acl_by_head(const obs_options * options, obs_canned_acl canned_acl, + obs_response_handler * handler, void *callback_data); + +eSDK_OBS_API void get_bucket_acl(const obs_options * options, manager_acl_info * aclinfo, + obs_response_handler * handler, void *callback_data); + +eSDK_OBS_API void obs_options_bucket(const obs_options *options, char* origin, + char (*request_method)[OBS_COMMON_LEN_256], unsigned int method_number, + char (*request_header)[OBS_COMMON_LEN_256], unsigned int header_number, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void get_bucket_metadata_with_corsconf(const obs_options *options, char *origin, + char (*requestHeader)[OBS_COMMON_LEN_256], unsigned int number, + obs_response_handler *handler); + +eSDK_OBS_API void obs_head_bucket(const obs_options *options, obs_response_handler *handler, + void *callback_data); + + +/*************************************object handle*************************************/ + +eSDK_OBS_API void get_object_metadata(const obs_options *options, obs_object_info *object_info, + server_side_encryption_params *encryption_params, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_object_metadata(const obs_options *options, obs_object_info *object_info, + obs_put_properties *put_properties, + server_side_encryption_params *encryption_params, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void put_object(const obs_options *options, char *key, uint64_t content_length, + obs_put_properties *put_properties, + server_side_encryption_params *encryption_params, + obs_put_object_handler *handler, void *callback_data); + +eSDK_OBS_API void init_get_properties(obs_get_conditions *get_conditions); + +eSDK_OBS_API void get_object(const obs_options *options, obs_object_info *object_info, + obs_get_conditions *get_conditions, + server_side_encryption_params *encryption_params, + obs_get_object_handler *handler, void *callback_data); + +eSDK_OBS_API void delete_object(const obs_options *options, obs_object_info *object_info, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API const char *obs_get_status_name(obs_status status); + +eSDK_OBS_API obs_status obs_create_request_context(obs_request_context **request_context_return); + +eSDK_OBS_API void obs_destroy_request_context(obs_request_context *request_context); + +eSDK_OBS_API obs_status obs_runall_request_context(obs_request_context *request_context); + +eSDK_OBS_API void obs_head_object(const obs_options *options, char *key, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void init_put_properties(obs_put_properties *put_properties); + +eSDK_OBS_API void upload_part(const obs_options *options, char *key, obs_upload_part_info *upload_part_info, + uint64_t content_length, obs_put_properties *put_properties, + server_side_encryption_params *encryption_params, + obs_upload_handler *handler, void *callback_data); + +eSDK_OBS_API void initiate_multi_part_upload(const obs_options *options, char *key,int upload_id_return_size, + char *upload_id_return, obs_put_properties *put_properties, + server_side_encryption_params *encryption_params, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void complete_multi_part_upload(const obs_options *options, char *key, const char *upload_id, unsigned int part_number, + obs_complete_upload_Info *complete_upload_Info,obs_put_properties *put_properties, + obs_complete_multi_part_upload_handler *handler, void *callback_data); + +eSDK_OBS_API void list_parts (const obs_options *options, char *key, list_part_info *listpart, + obs_list_parts_handler *handler, void *callback_data); + +eSDK_OBS_API void abort_multi_part_upload(const obs_options *options, char *key, const char *upload_id, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void copy_object(const obs_options *options, char *key, const char *version_id, obs_copy_destination_object_info *object_info, + unsigned int is_copy, obs_put_properties *put_properties, server_side_encryption_params *encryption_params, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void copy_part(const obs_options *options, char *key, obs_copy_destination_object_info *object_info, + obs_upload_part_info *copypart, obs_put_properties *put_properties, + server_side_encryption_params *encryption_params,obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void restore_object(const obs_options *options, obs_object_info *object_info, const char *days, + obs_tier tier,const obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void obs_options_object(const obs_options *options, char* key, char* origin, + char (*request_method)[OBS_COMMON_LEN_256], unsigned int method_number, + char (*request_header)[OBS_COMMON_LEN_256], unsigned int header_number, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void initialize_break_point_lock(); + +eSDK_OBS_API void deinitialize_break_point_lock(); + +eSDK_OBS_API void upload_file(const obs_options *options, char *key, server_side_encryption_params *encryption_params, + obs_upload_file_configuration *upload_file_config, obs_upload_file_response_handler *handler, + void *callback_data); + +eSDK_OBS_API void download_file(const obs_options *options, char *key, char* version_id, obs_get_conditions *get_conditions, + server_side_encryption_params *encryption_params, + obs_download_file_configuration * download_file_config, + obs_download_file_response_handler *handler, void *callback_data); + +eSDK_OBS_API void batch_delete_objects(const obs_options *options, obs_object_info *object_info,obs_delete_object_info *delobj, + obs_put_properties *put_properties, obs_delete_object_handler *handler, void *callback_data); + +eSDK_OBS_API void get_object_acl(const obs_options *options, manager_acl_info *aclinfo, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_object_acl(const obs_options *options, manager_acl_info *aclinfo, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void set_object_acl_by_head(const obs_options *options, obs_object_info *object_info, obs_canned_acl canned_acl, + obs_response_handler *handler, void *callback_data); +// only object bucket can use Modify_object +eSDK_OBS_API void append_object(const obs_options *options, char *key, uint64_t content_length, const char * position, + obs_put_properties *put_properties,server_side_encryption_params *encryption_params, + obs_append_object_handler *handler, void *callback_data); +// only pfs bucket can use Modify_object +eSDK_OBS_API void modify_object(const obs_options *options, char *key, uint64_t content_length, uint64_t position, + obs_put_properties *put_properties,server_side_encryption_params *encryption_params, + obs_modify_object_handler *handler, void *callback_data); +// only pfs bucket can use truncate_object +eSDK_OBS_API void truncate_object(const obs_options *options, char *key, uint64_t object_length, + obs_response_handler *handler, void *callback_data); +// only pfs bucket can use rename_object +eSDK_OBS_API void rename_object(const obs_options *options, char *key, char *new_object_name, + obs_response_handler *handler, void *callback_data); + +eSDK_OBS_API void compute_md5(const char *buffer, int64_t buffer_size, char *outbuffer); + +eSDK_OBS_API int set_obs_log_path(const char *log_path); + +eSDK_OBS_API void set_openssl_callback(obs_openssl_switch switch_flag); + + +#ifdef __cplusplus +} +#endif + +#endif /* LIBOBS_H */ + + + diff -uprN postgresql-hll-2.14_old/include/executor/execdebug.h postgresql-hll-2.14/include/executor/execdebug.h --- postgresql-hll-2.14_old/include/executor/execdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/execdebug.h 2020-12-12 17:06:43.110346271 +0800 @@ -0,0 +1,145 @@ +/* ------------------------------------------------------------------------- + * + * execdebug.h + * #defines governing debugging behaviour in the executor + * + * XXX this is all pretty old and crufty. Newer code tends to use elog() + * for debug printouts, because that's more flexible than printf(). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/execdebug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECDEBUG_H +#define EXECDEBUG_H + +#include "executor/executor.h" +#include "nodes/print.h" + +/* ---------------------------------------------------------------- + * debugging defines. + * + * If you want certain debugging behaviour, then #define + * the variable to 1. No need to explicitly #undef by default, + * since we can use -D compiler options to enable features. + * - thomas 1999-02-20 + * ---------------------------------------------------------------- + */ + +/* ---------------- + * EXEC_NESTLOOPDEBUG is a flag which turns on debugging of the + * nest loop node by NL_printf() and ENL_printf() in nodeNestloop.c + * ---------------- +#undef EXEC_NESTLOOPDEBUG + */ + +/* ---------------- + * EXEC_EVALDEBUG is a flag which turns on debugging of + * ExecEval and ExecTargetList() stuff by EV_printf() in execQual.c + * ---------------- +#undef EXEC_EVALDEBUG + */ + +/* ---------------- + * EXEC_SORTDEBUG is a flag which turns on debugging of + * the ExecSort() stuff by SO_printf() in nodeSort.c + * ---------------- +#undef EXEC_SORTDEBUG + */ + +/* ---------------- + * EXEC_MERGEJOINDEBUG is a flag which turns on debugging of + * the ExecMergeJoin() stuff by MJ_printf() in nodeMergejoin.c + * ---------------- +#undef EXEC_MERGEJOINDEBUG + */ + +/* ---------------------------------------------------------------- + * #defines controlled by above definitions + * + * Note: most of these are "incomplete" because I didn't + * need the ones not defined. More should be added + * only as necessary -cim 10/26/89 + * ---------------------------------------------------------------- + */ +#define T_OR_F(b) ((b) ? "true" : "false") +#define NULL_OR_TUPLE(slot) (TupIsNull(slot) ? "null" : "a tuple") + +/* ---------------- + * nest loop debugging defines + * ---------------- + */ +#ifdef EXEC_NESTLOOPDEBUG +#define NL_nodeDisplay(l) nodeDisplay(l) +#define NL_printf(s) printf(s) +#define NL1_printf(s, a) printf(s, a) +#define ENL1_printf(message) printf("ExecNestLoop: %s\n", message) +#else +#define NL_nodeDisplay(l) +#define NL_printf(s) +#define NL1_printf(s, a) +#define ENL1_printf(message) +#endif /* EXEC_NESTLOOPDEBUG */ + +/* ---------------- + * exec eval / target list debugging defines + * ---------------- + */ +#ifdef EXEC_EVALDEBUG +#define EV_nodeDisplay(l) nodeDisplay(l) +#define EV_printf(s) printf(s) +#define EV1_printf(s, a) printf(s, a) +#else +#define EV_nodeDisplay(l) +#define EV_printf(s) +#define EV1_printf(s, a) +#endif /* EXEC_EVALDEBUG */ + +/* ---------------- + * sort node debugging defines + * ---------------- + */ +#ifdef EXEC_SORTDEBUG +#define SO_nodeDisplay(l) nodeDisplay(l) +#define SO_printf(s) printf(s) +#define SO1_printf(s, p) printf(s, p) +#else +#define SO_nodeDisplay(l) +#define SO_printf(s) +#define SO1_printf(s, p) +#endif /* EXEC_SORTDEBUG */ + +/* ---------------- + * merge join debugging defines + * ---------------- + */ +#ifdef EXEC_MERGEJOINDEBUG + +#define MJ_nodeDisplay(l) nodeDisplay(l) +#define MJ_printf(s) printf(s) +#define MJ1_printf(s, p) printf(s, p) +#define MJ2_printf(s, p1, p2) printf(s, p1, p2) +#define MJ_debugtup(slot) debugtup(slot, NULL) +#define MJ_dump(state) ExecMergeTupleDump(state) +#define MJ_DEBUG_COMPARE(res) MJ1_printf(" MJCompare() returns %d\n", (res)) +#define MJ_DEBUG_QUAL(clause, res) MJ2_printf(" ExecQual(%s, econtext) returns %s\n", CppAsString(clause), T_OR_F(res)) +#define MJ_DEBUG_PROC_NODE(slot) \ + MJ2_printf(" %s = ExecProcNode(...) returns %s\n", CppAsString(slot), NULL_OR_TUPLE(slot)) +#else + +#define MJ_nodeDisplay(l) +#define MJ_printf(s) +#define MJ1_printf(s, p) +#define MJ2_printf(s, p1, p2) +#define MJ_debugtup(slot) +#define MJ_dump(state) +#define MJ_DEBUG_COMPARE(res) +#define MJ_DEBUG_QUAL(clause, res) +#define MJ_DEBUG_PROC_NODE(slot) +#endif /* EXEC_MERGEJOINDEBUG */ + +#endif /* ExecDebugIncluded */ diff -uprN postgresql-hll-2.14_old/include/executor/execdesc.h postgresql-hll-2.14/include/executor/execdesc.h --- postgresql-hll-2.14_old/include/executor/execdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/execdesc.h 2020-12-12 17:06:43.110346271 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * execdesc.h + * plan and query descriptor accessor macros used by the executor + * and related modules. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/execdesc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECDESC_H +#define EXECDESC_H + +#include "nodes/execnodes.h" +#include "tcop/dest.h" + +#ifdef ENABLE_MOT +// forward declaration +namespace JitExec +{ + struct JitContext; +} +#endif + +/* ---------------- + * query descriptor: + * + * a QueryDesc encapsulates everything that the executor + * needs to execute the query. + * + * For the convenience of SQL-language functions, we also support QueryDescs + * containing utility statements; these must not be passed to the executor + * however. + * --------------------- + */ +typedef struct QueryDesc { + /* These fields are provided by CreateQueryDesc */ + CmdType operation; /* CMD_SELECT, CMD_UPDATE, etc. */ + PlannedStmt* plannedstmt; /* planner's output, or null if utility */ + Node* utilitystmt; /* utility statement, or null */ + const char* sourceText; /* source text of the query */ + Snapshot snapshot; /* snapshot to use for query */ + Snapshot crosscheck_snapshot; /* crosscheck for RI update/delete */ + DestReceiver* dest; /* the destination for tuple output */ + ParamListInfo params; /* param values being passed in */ + int instrument_options; /* OR of InstrumentOption flags */ + + /* These fields are set by ExecutorStart */ + TupleDesc tupDesc; /* descriptor for result tuples */ + EState* estate; /* executor's query-wide state */ + PlanState* planstate; /* tree of per-plan-node state */ + + /* This is always set NULL by the core system, but plugins can change it */ + struct Instrumentation* totaltime; /* total time spent in ExecutorRun */ + bool executed; /* if the query already executed */ +#ifdef ENABLE_MOT + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif +} QueryDesc; + +/* in pquery.c */ +#ifdef ENABLE_MOT +extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot, + Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options, + JitExec::JitContext* mot_jit_context = nullptr); +#else +extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot, + Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options); +#endif + +extern QueryDesc* CreateUtilityQueryDesc( + Node* utilitystmt, const char* sourceText, Snapshot snapshot, DestReceiver* dest, ParamListInfo params); + +extern void FreeQueryDesc(QueryDesc* qdesc); + +#endif /* EXECDESC_H */ diff -uprN postgresql-hll-2.14_old/include/executor/execMerge.h postgresql-hll-2.14/include/executor/execMerge.h --- postgresql-hll-2.14_old/include/executor/execMerge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/execMerge.h 2020-12-12 17:06:43.110346271 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * execMerge.h + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/executor/execMerge.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef EXECMERGE_H +#define EXECMERGE_H + +#include "nodes/execnodes.h" + +/* flags for mt_merge_subcommands */ +#define MERGE_INSERT 0x01 +#define MERGE_UPDATE 0x02 + +struct VecModifyTableState; + +extern void ExecMerge(ModifyTableState* mtstate, EState* estate, TupleTableSlot* slot, JunkFilter* junkfilter, + ResultRelInfo* resultRelInfo); + +extern void ExecInitMerge(ModifyTableState* mtstate, EState* estate, ResultRelInfo* resultRelInfo); + +extern TupleTableSlot* ExtractScanTuple(ModifyTableState* mtstate, TupleTableSlot* slot, TupleDesc tupDesc); + +extern TupleTableSlot* ExecMergeProjQual(ModifyTableState* mtstate, List* mergeMatchedActionStates, + ExprContext* econtext, TupleTableSlot* originSlot, TupleTableSlot* result_slot, EState* estate); + +#endif /* NODEMERGE_H */ diff -uprN postgresql-hll-2.14_old/include/executor/execStream.h postgresql-hll-2.14/include/executor/execStream.h --- postgresql-hll-2.14_old/include/executor/execStream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/execStream.h 2020-12-12 17:06:43.110346271 +0800 @@ -0,0 +1,150 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * execStream.h + * Support routines for datanodes exchange. + * + * + * IDENTIFICATION + * src/include/executor/execStream.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXECSTREAM_H +#define EXECSTREAM_H + +#include "pgxc/execRemote.h" +#include "optimizer/planner.h" +#include "optimizer/streamplan.h" +#include "libcomm/libcomm.h" +#include "libpq/libpq-be.h" +#include "access/xact.h" +#include "utils/distribute_test.h" +#include +#include "storage/spin.h" +#include "workload/workload.h" +#include "pgstat.h" +#include "distributelayer/streamConsumer.h" +#include "distributelayer/streamProducer.h" + +typedef struct StreamDataBuf { + char* msg; + int size; + int len; +} StreamDataBuf; + +#define SetCheckInfo(checkInfo, plan) \ + do { \ + *(checkInfo.parentProducerExecNodeList) = plan->exec_nodes->nodeList; \ + *(checkInfo.parentPlanNodeId) = plan->plan_node_id; \ + *(checkInfo.parentProducerDop) = plan->dop; \ + } while (0) + +typedef struct StreamFlowCheckInfo { + List* parentProducerExecNodeList; /* Producer exec_nodes of parent stream node. */ + int parentPlanNodeId; /* plan node id of parent node. */ + int parentProducerDop; /* Dop of parent producer. */ +} StreamFlowCheckInfo; + +typedef struct StreamFlowCtl { + PlannedStmt* pstmt; /* PlannedStmt node, output of planner, + holds the "one time" information needed by the executor. */ + Plan* plan; /* Top node of plan tree. */ + List** allConsumerList; /* All consumer object list. */ + List** allProducerList; /* All producer object list. */ + List** subProducerList; /* All sub producer object list. */ + List** subConsumerList; /* All sub consumer object list. */ + int* threadNum; /* The number of stream thread. */ + bool dummyThread; /* If it's a dummy stream node? */ + StreamFlowCheckInfo checkInfo; /* Check if consumer match producer between stream node. */ +} StreamFlowCtl; + +typedef union { + struct { + struct pollfd* ufds; /* tcp poll fds. */ + int* poll2conn; /* poll idx to connection idx. */ + } tcpLayer; + + struct { + int* datamarks; /* producer number triggers poll. */ + int* poll2conn; /* poll idx to connection idx. */ + gsocket* gs_sock; + } sctpLayer; + +} StreamNetCtlLayer; + +typedef struct StreamNetCtl { + StreamNetCtlLayer layer; /* stream net controller layer. */ +} StreamNetCtl; + +typedef struct StreamState { + ScanState ss; /* its first field is NodeTag */ + PGXCNodeHandle** connections; /* Datanode connections */ + int conn_count; /* count of active connections */ + int last_conn_idx; /* last connection index */ + bool isReady; /* is ready for scan from socket fd*/ + bool need_fresh_data; /* need retrieve data from connection */ + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + bool vector_output; /* is vector format output */ + StreamDataBuf buf; /* data buffer for stream data */ + StreamConsumer* consumer; /* the stream consumer object which control the stream node*/ + scanStreamFun StreamScan; /* scan function for tuple stream */ + deserializeStreamFun StreamDeserialize; /* stream deserialize for tuple */ + RemoteErrorData remoteErrData; /* error data from remote */ + int64 recvDataLen; /* network data length for performance info of stream node. */ + StreamNetCtl netctl; /* stream net controller for node receiving. */ + StreamSharedContext* sharedContext; /* Shared context for local stream. */ + TupleVector* tempTupleVec; + StreamType type; /* indicate it's Redistribute/Broadcast. */ + int64* spill_size; + void* sortstate; /* merge sort for stream */ + bool receive_message; /* The stream consumer has receive message from then producer */ +} StreamState; + +extern StreamState* ExecInitStream(Stream* node, EState* estate, int eflags); +extern TupleTableSlot* ExecStream(StreamState* node); +extern void ExecEndStream(StreamState* node); +extern int HandleStreamResponse(PGXCNodeHandle* conn, StreamState* node); +extern void StreamPrepareRequest(StreamState* node); +extern void StreamPrepareRequestForRecursive(StreamState* node, bool stepsync); +extern void StreamReportError(StreamState* node); +extern void ExecEarlyDeinitConsumer(PlanState* node); +extern void SetupStreamRuntime(StreamState* node); +extern bool ScanStreamByLibcomm(StreamState* node); +extern void InitStreamContext(); +extern void DeinitStreamContext(); +extern void gs_memory_init_entry(StreamSharedContext* sharedContext, int consumerNum, int producerNum); +extern bool ScanMemoryStream(StreamState* node); +extern bool gs_memory_recv(StreamState* node); +extern void gs_memory_send( + TupleTableSlot* tuple, VectorBatch* batchsrc, StreamSharedContext* sharedContext, int nthChannel, int nthRow); +extern void gs_memory_disconnect(StreamSharedContext* sharedContext, int nthChannel); +extern void gs_message_by_memory(StringInfo buf, StreamSharedContext* sharedContext, int nthChannel); +extern void gs_memory_send_finish(StreamSharedContext* sharedContext, int connNum); +extern void gs_memory_close_conn(StreamSharedContext* sharedContext, int connNum, int smpId); +extern void HandleStreamNotice(StreamState* node, char* msg_body, size_t len); +extern void HandleStreamError(StreamState* node, char* msg_body, int len); +extern const char* GetStreamType(Stream* node); +extern bool ThreadIsDummy(Plan* plan_tree); +extern void AddCheckMessage(StringInfo msg_new, StringInfo msg_org, bool is_stream, unsigned int planNodeId = 0); +extern void CheckMessages(uint64 query_id, uint32 plan_node_id, char* msg, int msg_len, bool is_stream); +extern bool IsThreadProcessStreamRecursive(); +extern void ExecReSetStream(StreamState* node); + +#endif diff -uprN postgresql-hll-2.14_old/include/executor/executor.h postgresql-hll-2.14/include/executor/executor.h --- postgresql-hll-2.14_old/include/executor/executor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/executor.h 2020-12-12 17:06:43.111346283 +0800 @@ -0,0 +1,480 @@ +/* ------------------------------------------------------------------------- + * + * executor.h + * support for the POSTGRES executor module + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/executor.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECUTOR_H +#define EXECUTOR_H + +#include "executor/execdesc.h" +#include "nodes/parsenodes.h" +#include "nodes/params.h" +#include "pgxc/pgxc.h" +#include "utils/memprot.h" +#include "utils/memutils.h" +#include "utils/resowner.h" +#include "utils/partitionmap_gs.h" +#include "utils/plpgsql.h" + +/* + * The "eflags" argument to ExecutorStart and the various ExecInitNode + * routines is a bitwise OR of the following flag bits, which tell the + * called plan node what to expect. Note that the flags will get modified + * as they are passed down the plan tree, since an upper node may require + * functionality in its subnode not demanded of the plan as a whole + * (example: MergeJoin requires mark/restore capability in its inner input), + * or an upper node may shield its input from some functionality requirement + * (example: Materialize shields its input from needing to do backward scan). + * + * EXPLAIN_ONLY indicates that the plan tree is being initialized just so + * EXPLAIN can print it out; it will not be run. Hence, no side-effects + * of startup should occur. However, error checks (such as permission checks) + * should be performed. + * + * REWIND indicates that the plan node should try to efficiently support + * rescans without parameter changes. (Nodes must support ExecReScan calls + * in any case, but if this flag was not given, they are at liberty to do it + * through complete recalculation. Note that a parameter change forces a + * full recalculation in any case.) + * + * BACKWARD indicates that the plan node must respect the es_direction flag. + * When this is not passed, the plan node will only be run forwards. + * + * MARK indicates that the plan node must support Mark/Restore calls. + * When this is not passed, no Mark/Restore will occur. + * + * SKIP_TRIGGERS tells ExecutorStart/ExecutorFinish to skip calling + * AfterTriggerBeginQuery/AfterTriggerEndQuery. This does not necessarily + * mean that the plan can't queue any AFTER triggers; just that the caller + * is responsible for there being a trigger context for them to be queued in. + * + * WITH/WITHOUT_OIDS tell the executor to emit tuples with or without space + * for OIDs, respectively. These are currently used only for CREATE TABLE AS. + * If neither is set, the plan may or may not produce tuples including OIDs. + */ +#define EXEC_FLAG_EXPLAIN_ONLY 0x0001 /* EXPLAIN, no ANALYZE */ +#define EXEC_FLAG_REWIND 0x0002 /* need efficient rescan */ +#define EXEC_FLAG_BACKWARD 0x0004 /* need backward scan */ +#define EXEC_FLAG_MARK 0x0008 /* need mark/restore */ +#define EXEC_FLAG_SKIP_TRIGGERS 0x0010 /* skip AfterTrigger calls */ +#define EXEC_FLAG_WITH_OIDS 0x0020 /* force OIDs in returned tuples */ +#define EXEC_FLAG_WITHOUT_OIDS 0x0040 /* force no OIDs in returned tuples */ +#define EXEC_FLAG_WITH_NO_DATA 0x0080 /* rel scannability doesn't matter */ + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); + +#define STREAM_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_STREAM)) { \ + ereport(level, (errmodule(MOD_STREAM), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#define MEMCTL_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_MEM)) { \ + ereport(level, (errmodule(MOD_MEM), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#ifdef USE_ASSERT_CHECKING +#define EARLY_FREE_LOG(A) +#else +#define EARLY_FREE_LOG(A) +#endif + +#ifdef USE_ASSERT_CHECKING +#define RECURSIVE_LOG(level, format, ...) \ + do { \ + ereport(level, (errmsg(format, ##__VA_ARGS__))); \ + } while (0) +#else +#define RECURSIVE_LOG(level, format, ...) \ + do { \ + ereport(DEBUG1, (errmsg(format, ##__VA_ARGS__))); \ + } while (0) +#endif + +#define SET_DOP(dop) (dop > 1 ? dop : 1) +/* + * Calculate the memory restriction in each thread. + * And the memeory in each thread must be larger than 64K. + */ +#define SET_NODEMEM(opmem, dop) \ + ((opmem > 0 ? opmem : u_sess->attr.attr_memory.work_mem) / \ + ((opmem > 0 ? opmem : u_sess->attr.attr_memory.work_mem) > (SET_DOP(dop) * 64) ? SET_DOP(dop) : 1)) + +#define SET_NUMGROUPS(node) \ + (node->numGroups / SET_DOP(node->plan.dop) > 0 ? node->numGroups / SET_DOP(node->plan.dop) : 1) + +#define HAS_INSTR(node, dnonly) \ + (!dnonly || IS_PGXC_DATANODE) && u_sess->instr_cxt.global_instr != NULL && (node)->ps.instrument != NULL + +/* + * ExecEvalExpr was formerly a function containing a switch statement; + * now it's just a macro invoking the function pointed to by an ExprState + * node. Beware of double evaluation of the ExprState argument! + */ +#define ExecEvalExpr(expr, econtext, isNull, isDone) ((*(expr)->evalfunc)(expr, econtext, isNull, isDone)) + +/* + * recursive union macro + */ +#define INVALID_RU_PLANNODE_ID 0 +#define EXEC_IN_RECURSIVE_MODE(x) (((Plan*)x)->recursive_union_plan_nodeid != INVALID_RU_PLANNODE_ID) + +/* Hook for plugins to get control in ExecutorStart() */ +typedef void (*ExecutorStart_hook_type)(QueryDesc* queryDesc, int eflags); +extern THR_LOCAL PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook; + +/* Hook for plugins to get control in ExecutorRun() */ +typedef void (*ExecutorRun_hook_type)(QueryDesc* queryDesc, ScanDirection direction, long count); +extern THR_LOCAL PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook; + +/* Hook for plugins to get control in ExecutorFinish() */ +typedef void (*ExecutorFinish_hook_type)(QueryDesc* queryDesc); +extern THR_LOCAL PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook; + +/* Hook for plugins to get control in ExecutorEnd() */ +typedef void (*ExecutorEnd_hook_type)(QueryDesc* queryDesc); +extern THR_LOCAL PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook; + +/* Hook for plugins to get control in ExecCheckRTPerms() */ +typedef bool (*ExecutorCheckPerms_hook_type)(List*, bool); +extern THR_LOCAL PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook; + +/* + * prototypes from functions in execAmi.c + */ +extern void ExecReScan(PlanState* node); +extern void ExecMarkPos(PlanState* node); +extern void ExecRestrPos(PlanState* node); +extern bool ExecSupportsMarkRestore(NodeTag plantype); +extern bool ExecSupportsBackwardScan(Plan* node); +extern bool ExecMaterializesOutput(NodeTag plantype); + +/* + * prototypes from functions in execCurrent.c + */ +extern bool execCurrentOf(CurrentOfExpr* cexpr, ExprContext* econtext, Relation relation, ItemPointer current_tid, + RelationPtr partitionOfCursor_tid); +#ifdef PGXC +ScanState* search_plan_tree(PlanState* node, Oid table_oid); +#endif + +/* + * prototypes from functions in execGrouping.c + */ +extern bool execTuplesMatch(TupleTableSlot* slot1, TupleTableSlot* slot2, int numCols, AttrNumber* matchColIdx, + FmgrInfo* eqfunctions, MemoryContext evalContext); +extern bool execTuplesUnequal(TupleTableSlot* slot1, TupleTableSlot* slot2, int numCols, AttrNumber* matchColIdx, + FmgrInfo* eqfunctions, MemoryContext evalContext); +extern FmgrInfo* execTuplesMatchPrepare(int numCols, Oid* eqOperators); +extern void execTuplesHashPrepare(int numCols, Oid* eqOperators, FmgrInfo** eqFunctions, FmgrInfo** hashFunctions); +extern TupleHashTable BuildTupleHashTable(int numCols, AttrNumber* keyColIdx, FmgrInfo* eqfunctions, + FmgrInfo* hashfunctions, long nbuckets, Size entrysize, MemoryContext tablecxt, MemoryContext tempcxt, int workMem); +extern TupleHashEntry LookupTupleHashEntry( + TupleHashTable hashtable, TupleTableSlot* slot, bool* isnew, bool isinserthashtbl = true); +extern TupleHashEntry FindTupleHashEntry( + TupleHashTable hashtable, TupleTableSlot* slot, FmgrInfo* eqfunctions, FmgrInfo* hashfunctions); + +/* + * prototypes from functions in execJunk.c + */ +extern JunkFilter* ExecInitJunkFilter(List* targetList, bool hasoid, TupleTableSlot* slot, TableAmType tam = TAM_HEAP); +extern JunkFilter* ExecInitJunkFilterConversion(List* targetList, TupleDesc cleanTupType, TupleTableSlot* slot); +extern AttrNumber ExecFindJunkAttribute(JunkFilter* junkfilter, const char* attrName); +extern AttrNumber ExecFindJunkAttributeInTlist(List* targetlist, const char* attrName); +extern Datum ExecGetJunkAttribute(TupleTableSlot* slot, AttrNumber attno, bool* isNull); +extern TupleTableSlot* ExecFilterJunk(JunkFilter* junkfilter, TupleTableSlot* slot); +extern void ExecSetjunkFilteDescriptor(JunkFilter* junkfilter, TupleDesc tupdesc); + +#ifdef PGXC +extern List* ExecFindJunkPrimaryKeys(List* targetlist); +#endif +extern VectorBatch* BatchExecFilterJunk(JunkFilter* junkfilter, VectorBatch* batch); +extern void BatchCheckNodeIdentifier(JunkFilter* junkfilter, VectorBatch* batch); +extern int ExecGetPlanNodeid(void); + +/* + * prototypes from functions in execMain.c + */ +extern void ExecutorStart(QueryDesc* queryDesc, int eflags); +extern void standard_ExecutorStart(QueryDesc* queryDesc, int eflags); +extern void ExecutorRun(QueryDesc* queryDesc, ScanDirection direction, long count); +extern void standard_ExecutorRun(QueryDesc* queryDesc, ScanDirection direction, long count); +extern void ExecutorFinish(QueryDesc* queryDesc); +extern void standard_ExecutorFinish(QueryDesc* queryDesc); +extern void ExecutorEnd(QueryDesc* queryDesc); +extern void standard_ExecutorEnd(QueryDesc* queryDesc); +extern void ExecutorRewind(QueryDesc* queryDesc); +extern bool ExecCheckRTPerms(List* rangeTable, bool ereport_on_violation); +extern void CheckValidResultRel(Relation resultRel, CmdType operation); +extern void InitResultRelInfo( + ResultRelInfo* resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, int instrument_options); +extern ResultRelInfo* ExecGetTriggerResultRel(EState* estate, Oid relid); +extern bool ExecContextForcesOids(PlanState* planstate, bool* hasoids); +extern void ExecConstraints(ResultRelInfo* resultRelInfo, TupleTableSlot* slot, EState* estate); +extern ExecRowMark* ExecFindRowMark(EState* estate, Index rti); +extern ExecAuxRowMark* ExecBuildAuxRowMark(ExecRowMark* erm, List* targetlist); +extern TupleTableSlot* EvalPlanQual( + EState* estate, EPQState* epqstate, Relation relation, Index rti, ItemPointer tid, TransactionId priorXmax); +extern HeapTuple heap_lock_updated( + CommandId cid, Relation relation, int lockmode, ItemPointer tid, TransactionId priorXmax); +extern void EvalPlanQualInit(EPQState* epqstate, EState* estate, Plan* subplan, List* auxrowmarks, int epqParam); +extern void EvalPlanQualSetPlan(EPQState* epqstate, Plan* subplan, List* auxrowmarks); +extern void EvalPlanQualSetTuple(EPQState* epqstate, Index rti, HeapTuple tuple); +extern HeapTuple EvalPlanQualGetTuple(EPQState* epqstate, Index rti); + +#define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot)) +extern void EvalPlanQualFetchRowMarks(EPQState* epqstate); +extern TupleTableSlot* EvalPlanQualNext(EPQState* epqstate); +extern void EvalPlanQualBegin(EPQState* epqstate, EState* parentestate); +extern void EvalPlanQualEnd(EPQState* epqstate); + +/* + * prototypes from functions in execProcnode.c + */ +extern PlanState* ExecInitNode(Plan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecProcNode(PlanState* node); +extern Node* MultiExecProcNode(PlanState* node); +extern void ExecEndNode(PlanState* node); + +extern long ExecGetPlanMemCost(Plan* node); + +/* + * prototypes from functions in execQual.c + */ +extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno, bool* isNull); +extern Datum GetAttributeByName(HeapTupleHeader tuple, const char* attname, bool* isNull); +extern Tuplestorestate* ExecMakeTableFunctionResult( + ExprState* funcexpr, ExprContext* econtext, TupleDesc expectedDesc, bool randomAccess, FunctionScanState* node); +extern Datum ExecEvalExprSwitchContext( + ExprState* expression, ExprContext* econtext, bool* isNull, ExprDoneCond* isDone); +extern ExprState* ExecInitExpr(Expr* node, PlanState* parent); +extern ExprState* ExecPrepareExpr(Expr* node, EState* estate); +extern bool ExecQual(List* qual, ExprContext* econtext, bool resultForNull); +extern int ExecTargetListLength(List* targetlist); +extern int ExecCleanTargetListLength(List* targetlist); +extern TupleTableSlot* ExecProject(ProjectionInfo* projInfo, ExprDoneCond* isDone); + +extern TupleTableSlot* ExecScan(ScanState* node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd); +extern void ExecAssignScanProjectionInfo(ScanState* node); +extern void ExecScanReScan(ScanState* node); + +/* + * prototypes from functions in execTuples.c + */ +extern void ExecInitResultTupleSlot(EState* estate, PlanState* planstate, TableAmType tam = TAM_HEAP); +extern void ExecInitScanTupleSlot(EState* estate, ScanState* scanstate, TableAmType tam = TAM_HEAP); +extern TupleTableSlot* ExecInitExtraTupleSlot(EState* estate, TableAmType tam = TAM_HEAP); +extern TupleTableSlot* ExecInitNullTupleSlot(EState* estate, TupleDesc tupType); +extern TupleDesc ExecTypeFromTL(List* targetList, bool hasoid, bool markdropped = false, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecCleanTypeFromTL(List* targetList, bool hasoid, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecTypeFromExprList(List* exprList, List* namesList, TableAmType tam = TAM_HEAP); +extern void UpdateChangedParamSet(PlanState* node, Bitmapset* newchg); + +typedef struct TupOutputState { + TupleTableSlot* slot; + DestReceiver* dest; +} TupOutputState; + +extern TupOutputState* begin_tup_output_tupdesc(DestReceiver* dest, TupleDesc tupdesc); +extern void do_tup_output( + TupOutputState* tstate, Datum* values, size_t values_len, const bool* isnull, size_t isnull_len); +extern int do_text_output_multiline(TupOutputState* tstate, char* text); +extern void end_tup_output(TupOutputState* tstate); + +/* + * Write a single line of text given as a C string. + * + * Should only be used with a single-TEXT-attribute tupdesc. + */ +#define do_text_output_oneline(tstate, str_to_emit) \ + do { \ + Datum values_[1]; \ + bool isnull_[1]; \ + values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \ + isnull_[0] = false; \ + do_tup_output(tstate, values_, 1, isnull_, 1); \ + pfree(DatumGetPointer(values_[0])); \ + } while (0) + +/* + * prototypes from functions in execUtils.c + */ +extern EState* CreateExecutorState(void); +extern void FreeExecutorState(EState* estate); +extern ExprContext* CreateExprContext(EState* estate); +extern ExprContext* CreateStandaloneExprContext(void); +extern void FreeExprContext(ExprContext* econtext, bool isCommit); +extern void ReScanExprContext(ExprContext* econtext); + +#define ResetExprContext(econtext) MemoryContextReset((econtext)->ecxt_per_tuple_memory) + +extern ExprContext* MakePerTupleExprContext(EState* estate); + +#define RuntimeBinding(func, strategy) (this->*func[strategy]) +#define InvokeFp(func) (this->*func) + +/* Get an EState's per-output-tuple exprcontext, making it if first use */ +#define GetPerTupleExprContext(estate) \ + ((estate)->es_per_tuple_exprcontext ? (estate)->es_per_tuple_exprcontext : MakePerTupleExprContext(estate)) + +#define GetPerTupleMemoryContext(estate) (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory) + +/* Reset an EState's per-output-tuple exprcontext, if one's been created */ +#define ResetPerTupleExprContext(estate) \ + do { \ + if ((estate)->es_per_tuple_exprcontext) \ + ResetExprContext((estate)->es_per_tuple_exprcontext); \ + } while (0) + +/* Reset an Slot's per-output-tuple context, if one's been created */ +#define ResetSlotPerTupleContext(slot) \ + do { \ + if ((slot) && (slot)->tts_per_tuple_mcxt) \ + MemoryContextReset((slot)->tts_per_tuple_mcxt); \ + } while (0) + +extern void ExecAssignExprContext(EState* estate, PlanState* planstate); +extern void ExecAssignResultType(PlanState* planstate, TupleDesc tupDesc); +extern void ExecAssignResultTypeFromTL(PlanState* planstate, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecGetResultType(PlanState* planstate); +extern void ExecAssignVectorForExprEval(ExprContext* econtext); +extern ProjectionInfo* ExecBuildProjectionInfo( + List* targetList, ExprContext* econtext, TupleTableSlot* slot, TupleDesc inputDesc); +extern void ExecAssignProjectionInfo(PlanState* planstate, TupleDesc inputDesc); +extern void ExecAssignScanProjectionInfoWithVarno(ScanState* node, Index varno); +extern void ExecFreeExprContext(PlanState* planstate); +extern TupleDesc ExecGetScanType(ScanState* scanstate); +extern void ExecAssignScanType(ScanState* scanstate, TupleDesc tupDesc); +extern void ExecAssignScanTypeFromOuterPlan(ScanState* scanstate); + +extern bool ExecRelationIsTargetRelation(EState* estate, Index scanrelid); + +extern Relation ExecOpenScanRelation(EState* estate, Index scanrelid); +extern void ExecCloseScanRelation(Relation scanrel); + +extern Partition ExecOpenScanParitition( + EState* estate, Relation parent, PartitionIdentifier* partID, LOCKMODE lockmode); + +extern void ExecOpenIndices(ResultRelInfo* resultRelInfo, bool speculative); +extern void ExecCloseIndices(ResultRelInfo* resultRelInfo); +extern List* ExecInsertIndexTuples( + TupleTableSlot* slot, ItemPointer tupleid, EState* estate, Relation targetPartRel, Partition p, int2 bucketId, bool* conflict); +extern bool ExecCheckIndexConstraints(TupleTableSlot* slot, EState* estate, + Relation targetRel, Partition p, int2 bucketId, ItemPointer conflictTid); +extern bool check_exclusion_constraint(Relation heap, Relation index, IndexInfo* indexInfo, ItemPointer tupleid, + Datum* values, const bool* isnull, EState* estate, bool newIndex, bool errorOK); +extern void RegisterExprContextCallback(ExprContext* econtext, ExprContextCallbackFunction function, Datum arg); +extern void UnregisterExprContextCallback(ExprContext* econtext, ExprContextCallbackFunction function, Datum arg); +extern List* GetAccessedVarnoList(List* targetList, List* qual); +extern ProjectionInfo* ExecBuildVecProjectionInfo( + List* targetList, List* nt_qual, ExprContext* econtext, TupleTableSlot* slot, TupleDesc inputDesc); +extern bool tlist_matches_tupdesc(PlanState* ps, List* tlist, Index varno, TupleDesc tupdesc); + +extern int PthreadMutexLock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); +extern int PthreadMutexTryLock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); +extern int PthreadMutexUnlock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); + +extern bool executorEarlyStop(); +extern void ExecEarlyFree(PlanState* node); +extern void ExecEarlyFreeBody(PlanState* node); +extern void ExecReSetRecursivePlanTree(PlanState* node); + +extern void ExplainNodePending(PlanState* result_plan); +extern void ExplainNodeFinish(PlanState* result_plan, TimestampTz current_time, bool is_pending); + +extern void ExecCopyDataFromDatum(PLpgSQL_datum** datums, int dno, Cursor_Data* target_cursor); +extern void ExecCopyDataToDatum(PLpgSQL_datum** datums, int dno, Cursor_Data* target_cursor); + +// AutoMutexLock +// Auto object for non-recursive pthread_mutex_t lock +// +class AutoMutexLock { +public: + AutoMutexLock(pthread_mutex_t* mutex, bool trace = true) + : m_mutex(mutex), m_fLocked(false), m_trace(trace), m_owner(t_thrd.utils_cxt.CurrentResourceOwner) + {} + + ~AutoMutexLock() + { + unLock(); + } + + inline void lock() + { + // Guard against recursive lock + // + if (!m_fLocked) { + int ret = 0; + + ret = PthreadMutexLock(m_owner, m_mutex, m_trace); + m_fLocked = (ret == 0 ? true : false); + if (!m_fLocked) { + /* this should never happen, system may be completely in a mess */ + if (ErrorContext == NULL) { + write_stderr(_("ERROR: pthread mutex lock failed, query id %lu: %s\n"), + u_sess->debug_query_id, + strerror(ret)); + abort(); + } else + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("pthread mutex lock failed: %s", strerror(ret)))); + } + } + } + + inline bool TryLock() + { + // Guard against recursive lock + // + if (!m_fLocked) { + m_fLocked = (PthreadMutexTryLock(m_owner, m_mutex, m_trace) == 0 ? true : false); + return m_fLocked; + } + + return false; + } + + inline void unLock() + { + if (m_fLocked) { + int ret = 0; + + if (t_thrd.utils_cxt.CurrentResourceOwner == NULL) + m_owner = NULL; + + ret = PthreadMutexUnlock(m_owner, m_mutex, m_trace); + m_fLocked = (ret == 0 ? false : true); + if (m_fLocked) { + /* this should never happen, system may be completely in a mess */ + if (ErrorContext == NULL) { + write_stderr(_("ERROR: pthread mutex unlock failed, query id %lu: %s\n"), + u_sess->debug_query_id, + strerror(ret)); + abort(); + } else + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("pthread mutex unlock failed: %s", strerror(ret)))); + } + } + } + +private: + pthread_mutex_t* m_mutex; + bool m_fLocked; + bool m_trace; + ResourceOwner m_owner; +}; + +#endif /* EXECUTOR_H */ diff -uprN postgresql-hll-2.14_old/include/executor/functions.h postgresql-hll-2.14/include/executor/functions.h --- postgresql-hll-2.14_old/include/executor/functions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/functions.h 2020-12-12 17:06:43.111346283 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * functions.h + * Declarations for execution of SQL-language functions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/functions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FUNCTIONS_H +#define FUNCTIONS_H + +#include "nodes/execnodes.h" +#include "tcop/dest.h" + +/* This struct is known only within executor/functions.c */ +typedef struct SQLFunctionParseInfo* SQLFunctionParseInfoPtr; + +extern Datum fmgr_sql(PG_FUNCTION_ARGS); + +extern SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node* call_expr, Oid inputCollation); + +extern void sql_fn_parser_setup(struct ParseState* pstate, SQLFunctionParseInfoPtr pinfo); + +extern bool check_sql_fn_retval( + Oid func_id, Oid rettype, List* queryTreeList, bool* modifyTargetList, JunkFilter** junkFilter); + +extern DestReceiver* CreateSQLFunctionDestReceiver(void); + +#endif /* FUNCTIONS_H */ diff -uprN postgresql-hll-2.14_old/include/executor/hashjoin.h postgresql-hll-2.14/include/executor/hashjoin.h --- postgresql-hll-2.14_old/include/executor/hashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/hashjoin.h 2020-12-12 17:06:43.111346283 +0800 @@ -0,0 +1,184 @@ +/* ------------------------------------------------------------------------- + * + * hashjoin.h + * internal structures for hash joins + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/hashjoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HASHJOIN_H +#define HASHJOIN_H + +#include "nodes/execnodes.h" +#include "storage/buffile.h" + +/* ---------------------------------------------------------------- + * hash-join hash table structures + * + * Each active hashjoin has a HashJoinTable control block, which is + * palloc'd in the executor's per-query context. All other storage needed + * for the hashjoin is kept in private memory contexts, two for each hashjoin. + * This makes it easy and fast to release the storage when we don't need it + * anymore. (Exception: data associated with the temp files lives in the + * per-query context too, since we always call buffile.c in that context.) + * + * The hashtable contexts are made children of the per-query context, ensuring + * that they will be discarded at end of statement even if the join is + * aborted early by an error. (Likewise, any temporary files we make will + * be cleaned up by the virtual file manager in event of an error.) + * + * Storage that should live through the entire join is allocated from the + * "hashCxt", while storage that is only wanted for the current batch is + * allocated in the "batchCxt". By resetting the batchCxt at the end of + * each batch, we free all the per-batch storage reliably and without tedium. + * + * During first scan of inner relation, we get its tuples from executor. + * If nbatch > 1 then tuples that don't belong in first batch get saved + * into inner-batch temp files. The same statements apply for the + * first scan of the outer relation, except we write tuples to outer-batch + * temp files. After finishing the first scan, we do the following for + * each remaining batch: + * 1. Read tuples from inner batch file, load into hash buckets. + * 2. Read tuples from outer batch file, match to hash buckets and output. + * + * It is possible to increase nbatch on the fly if the in-memory hash table + * gets too big. The hash-value-to-batch computation is arranged so that this + * can only cause a tuple to go into a later batch than previously thought, + * never into an earlier batch. When we increase nbatch, we rescan the hash + * table and dump out any tuples that are now of a later batch to the correct + * inner batch file. Subsequently, while reading either inner or outer batch + * files, we might find tuples that no longer belong to the current batch; + * if so, we just dump them out to the correct batch file. + * ---------------------------------------------------------------- + */ + +/* these are in nodes/execnodes.h: */ +/* typedef struct HashJoinTupleData *HashJoinTuple; */ +/* typedef struct HashJoinTableData *HashJoinTable; */ + +typedef struct HashJoinTupleData { + struct HashJoinTupleData* next; /* link to next tuple in same bucket */ + uint32 hashvalue; /* tuple's hash code */ + /* Tuple data, in MinimalTuple format, follows on a MAXALIGN boundary */ +} HashJoinTupleData; + +#define HJTUPLE_OVERHEAD MAXALIGN(sizeof(HashJoinTupleData)) +#define HJTUPLE_MINTUPLE(hjtup) ((MinimalTuple)((char*)(hjtup) + HJTUPLE_OVERHEAD)) + +/* + * If the outer relation's distribution is sufficiently nonuniform, we attempt + * to optimize the join by treating the hash values corresponding to the outer + * relation's MCVs specially. Inner relation tuples matching these hash + * values go into the "skew" hashtable instead of the main hashtable, and + * outer relation tuples with these hash values are matched against that + * table instead of the main one. Thus, tuples with these hash values are + * effectively handled as part of the first batch and will never go to disk. + * The skew hashtable is limited to SKEW_WORK_MEM_PERCENT of the total memory + * allowed for the join; while building the hashtables, we decrease the number + * of MCVs being specially treated if needed to stay under this limit. + * + * Note: you might wonder why we look at the outer relation stats for this, + * rather than the inner. One reason is that the outer relation is typically + * bigger, so we get more I/O savings by optimizing for its most common values. + * Also, for similarly-sized relations, the planner prefers to put the more + * uniformly distributed relation on the inside, so we're more likely to find + * interesting skew in the outer relation. + */ +typedef struct HashSkewBucket { + uint32 hashvalue; /* common hash value */ + HashJoinTuple tuples; /* linked list of inner-relation tuples */ +} HashSkewBucket; + +#define SKEW_BUCKET_OVERHEAD MAXALIGN(sizeof(HashSkewBucket)) +#define INVALID_SKEW_BUCKET_NO (-1) +#define SKEW_WORK_MEM_PERCENT 2 +#define SKEW_MIN_OUTER_FRACTION 0.01 + +/* + * To reduce palloc overhead, the HashJoinTuples for the current batch are + * packed in 32kB buffers instead of pallocing each tuple individually. + */ +typedef struct HashMemoryChunkData { + int ntuples; /* number of tuples stored in this chunk */ + size_t maxlen; /* size of the buffer holding the tuples */ + size_t used; /* number of buffer bytes already used */ + + struct HashMemoryChunkData* next; /* pointer to the next chunk (linked list) */ + + char data[FLEXIBLE_ARRAY_MEMBER]; /* buffer allocated at the end */ +} HashMemoryChunkData; + +typedef struct HashMemoryChunkData* HashMemoryChunk; + +#define HASH_CHUNK_SIZE (32 * 1024L) +#define HASH_CHUNK_THRESHOLD (HASH_CHUNK_SIZE / 4) + +typedef struct HashJoinTableData { + int nbuckets; /* # buckets in the in-memory hash table */ + int log2_nbuckets; /* its log2 (nbuckets must be a power of 2) */ + + /* buckets[i] is head of list of tuples in i'th in-memory bucket */ + struct HashJoinTupleData** buckets; + /* buckets array is per-batch storage, as are all the tuples */ + + bool keepNulls; /* true to store unmatchable NULL tuples */ + + bool skewEnabled; /* are we using skew optimization? */ + HashSkewBucket** skewBucket; /* hashtable of skew buckets */ + int skewBucketLen; /* size of skewBucket array (a power of 2!) */ + int nSkewBuckets; /* number of active skew buckets */ + int* skewBucketNums; /* array indexes of active skew buckets */ + + int nbatch; /* number of batches */ + int curbatch; /* current batch #; 0 during 1st pass */ + + int nbatch_original; /* nbatch when we started inner scan */ + int nbatch_outstart; /* nbatch when we started outer scan */ + + bool growEnabled; /* flag to shut off nbatch increases */ + + double totalTuples; /* # tuples obtained from inner plan */ + + /* + * These arrays are allocated for the life of the hash join, but only if + * nbatch > 1. A file is opened only when we first write a tuple into it + * (otherwise its pointer remains NULL). Note that the zero'th array + * elements never get used, since we will process rather than dump out any + * tuples of batch zero. + */ + BufFile** innerBatchFile; /* buffered virtual temp file per batch */ + BufFile** outerBatchFile; /* buffered virtual temp file per batch */ + + /* + * Info about the datatype-specific hash functions for the datatypes being + * hashed. These are arrays of the same length as the number of hash join + * clauses (hash keys). + */ + FmgrInfo* outer_hashfunctions; /* lookup data for hash functions */ + FmgrInfo* inner_hashfunctions; /* lookup data for hash functions */ + bool* hashStrict; /* is each hash join operator strict? */ + + int64 spaceUsed; /* memory space currently used by tuples */ + int64 spaceAllowed; /* upper limit for space used */ + int64 spacePeak; /* peak space used */ + int64 spaceUsedSkew; /* skew hash table's current space usage */ + int64 spaceAllowedSkew; /* upper limit for skew hashtable */ + + MemoryContext hashCxt; /* context for whole-hash-join storage */ + MemoryContext batchCxt; /* context for this-batch-only storage */ + + /* used for dense allocation of tuples (into linked chunks) */ + HashMemoryChunk chunks; /* one list for the whole batch */ + int64 width[2]; /* first records tuple count, second records total width */ + bool causedBySysRes; /* the batch increase caused by system resources limit? */ + int64 maxMem; /* batch auto spread mem */ + int spreadNum; /* auto spread times */ + int64* spill_size; +} HashJoinTableData; + +#endif /* HASHJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/instrument.h postgresql-hll-2.14/include/executor/instrument.h --- postgresql-hll-2.14_old/include/executor/instrument.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/instrument.h 2020-12-12 17:06:43.111346283 +0800 @@ -0,0 +1,1032 @@ +/* ------------------------------------------------------------------------- + * + * instrument.h + * definitions for run-time statistics collection + * + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/executor/instrument.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTRUMENT_H +#define INSTRUMENT_H + +#include "portability/instr_time.h" +#include "nodes/pg_list.h" +#include "nodes/plannodes.h" +#include "lib/stringinfo.h" +#include "miscadmin.h" +#include "utils/anls_opt.h" +#include +#include "datatype/timestamp.h" +#include "storage/lwlock.h" + +class ThreadInstrumentation; +class StreamInstrumentation; + +extern THR_LOCAL ThreadInstrumentation* runtimeThreadInstr; + +#define trackpoint_number 10 +#define DN_NUM_STREAMS_IN_CN(num_streams, gather_count, query_dop) ((num_streams + gather_count) * query_dop) + +#define ECQUERYDATALEN 1024 + +#define TRACK_START(nodeid, id) \ + do { \ + StreamInstrumentation::TrackStartTime(nodeid, id); \ + } while (0); + +#define TRACK_END(nodeid, id) \ + do { \ + StreamInstrumentation::TrackEndTime(nodeid, id); \ + } while (0); + +typedef struct BufferUsage { + long shared_blks_hit; /* # of shared buffer hits */ + long shared_blks_read; /* # of shared disk blocks read */ + long shared_blks_dirtied; /* # of shared blocks dirtied */ + long shared_blks_written; /* # of shared disk blocks written */ + long local_blks_hit; /* # of local buffer hits */ + long local_blks_read; /* # of local disk blocks read */ + long local_blks_dirtied; /* # of shared blocks dirtied */ + long local_blks_written; /* # of local disk blocks written */ + long temp_blks_read; /* # of temp blocks read */ + long temp_blks_written; /* # of temp blocks written */ + instr_time blk_read_time; /* time spent reading */ + instr_time blk_write_time; /* time spent writing */ +} BufferUsage; + +typedef struct CPUUsage { + double m_cycles; /* number of cycles */ +} CPUUsage; + +/* Flag bits included in InstrAlloc's instrument_options bitmask */ +typedef enum InstrumentOption { + INSTRUMENT_NONE = 0, + INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */ + INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */ + INSTRUMENT_ROWS = 1 << 2, /* needs row count */ + INSTRUMENT_ALL = 0x7FFFFFFF +} InstrumentOption; + +/* Mark the DFS storage system type */ +typedef enum DFSType { + DFS_HDFS = 1, /* Hadoop HDFS storage system */ + DFS_OBS = 2, /* OBS key-value storage system */ + DFS_DFV = 3 /* DFV p-log based storage system */ + , + TYPE_LOG_FT /* foreign table type, log data */ +} DFSType; + +#define SORT_IN_DISK 0x00000001 /* space type Disk */ +#define SORT_IN_MEMORY 0x00000002 /* space type Memory */ + +enum sortMethodId { + /* sort Method */ + HEAPSORT, + QUICKSORT, + EXTERNALSORT, + EXTERNALMERGE, + STILLINPROGRESS +}; + +struct sortMessage { + sortMethodId TypeId; + char* sortName; +}; + +typedef struct SortHashInfo { + int sortMethodId; + int spaceTypeId; + long spaceUsed; + int nbatch; + int nbatch_original; + int nbuckets; + Size spacePeak; + int64 hash_FileNum; + int64 hash_innerFileNum; /* number of files to store build side data */ + int64 hash_outerFileNum; /* number of files to store probe side data */ + bool hash_writefile; + int hash_spillNum; + int hashtable_expand_times; + double hashbuild_time; + double hashagg_time; + long spill_size; /* Totoal disk IO */ + long spill_innerSize; /* disk IO of build side data that are spilt to disk */ + long spill_innerSizePartMax; + long spill_innerSizePartMin; + long spill_outerSize; /* disk IO of probe side data that are spilt to disk */ + long spill_outerSizePartMax; + long spill_outerSizePartMin; + int spill_innerPartNum; /* number of inner partitions that are spilt to disk */ + int spill_outerPartNum; /* number of outer partitions that are spilt to disk */ + int hash_partNum; /* partition number of either build or probe side */ +} SortHashInfo; + +typedef struct StreamTime { + bool need_timer; + bool running; + instr_time starttime; + instr_time counter; + double firsttuple; + double tuplecount; + double startup; /* Total startup time (in seconds) */ + double total; /* Total total time (in seconds) */ + double ntuples; /* Total tuples produced */ + double nloops; /* # of run cycles for this node */ + +} StreamTime; + +typedef struct AccumCounters { + int64 accumCounters[3]; + int64 tempCounters[3]; +} AccumCounters; + +typedef struct Track { + int node_id; + bool is_datanode; /* mark current plan node is datanode or not */ + ThreadId track_threadId; + int registerTrackId; + StreamTime track_time; + AccumCounters accumCounters; + bool active; /* track.active == true means track is effective */ +} Track; + +typedef struct RoughCheckInfo { + uint64 m_CUFull; + uint64 m_CUNone; + uint64 m_CUSome; + + inline void IncFullCUNum() + { + ++m_CUFull; + } + inline void IncNoneCUNum() + { + ++m_CUNone; + } + inline void IncSomeCUNum() + { + ++m_CUSome; + } + +} RCInfo; + +typedef struct NetWorkPerfData { + int64 network_size; + instr_time start_poll_time; + instr_time start_deserialize_time; + instr_time start_copy_time; + instr_time network_poll_time; + instr_time network_deserialize_time; + instr_time network_copy_time; + double total_poll_time; + double total_deserialize_time; + double total_copy_time; +} NetWorkPerfData; + +/* For stream thread sending time */ +typedef struct StreamSendData { + instr_time start_send_time; + instr_time start_wait_quota_time; + instr_time start_OS_send_time; + instr_time start_serialize_time; + instr_time start_copy_time; + instr_time stream_send_time; + instr_time stream_wait_quota_time; + instr_time stream_OS_send_time; + instr_time stream_serialize_time; + instr_time stream_copy_time; + double total_send_time; + double total_wait_quota_time; + double total_os_send_time; + double total_serialize_time; + double total_copy_time; + bool loops; +} StreamSendData; + +typedef struct MemoryInfo { + int64 peakOpMemory; /* Peak Memory usage for per operator */ + int64 peakControlMemory; /* Peak Control Memory */ + int64 peakNodeMemory; /* Peak Memory usage for per query */ + int32 operatorMemory; /* Operator Memory for intensive operator */ + MemoryContext nodeContext; /* node context */ + List* controlContextList; /* control list of memory contexts */ +} MemoryInfo; + +/* + * max non-iteration and iteration times performance can support + */ +#define RECUSIVE_MAX_ITER_NUM 201 + +typedef struct RecursiveInfo { + int niters; /* iteration number */ + uint64 iter_ntuples[RECUSIVE_MAX_ITER_NUM]; + bool has_reach_limit; +} RecursiveInfo; + +typedef struct Instrumentation { + /* Parameters set at node creation: */ + bool need_timer; /* TRUE if we need timer data */ + bool need_bufusage; /* TRUE if we need buffer usage data */ + bool needRCInfo; + /* Info about current plan cycle: */ + bool running; /* TRUE if we've completed first tuple */ + instr_time starttime; /* Start time of current iteration of node */ + instr_time counter; /* Accumulated runtime for this node */ + double firsttuple; /* Time for first tuple of this cycle */ + double tuplecount; /* Tuples emitted so far this cycle */ + BufferUsage bufusage_start; /* Buffer usage at start */ + /* Accumulated statistics across all completed cycles: */ + double startup; /* Total startup time (in seconds) */ + double total; /* Total total time (in seconds) */ + double ntuples; /* Total tuples produced */ + double nloops; /* # of run cycles for this node */ + double nfiltered1; /* # tuples removed by scanqual or joinqual */ + double nfiltered2; /* # tuples removed by "other" quals OR + * # tuples updated by MERGE */ + BufferUsage bufusage; /* Total buffer usage */ + CPUUsage cpuusage_start; /* CPU usage at start */ + CPUUsage cpuusage; /* Total CPU usage */ + SortHashInfo sorthashinfo; /* Sort/hash operator perf data*/ + NetWorkPerfData network_perfdata; /* Network performance data */ + StreamSendData stream_senddata; /* Stream send time */ + RCInfo rcInfo; /* Cu filter performance data */ + MemoryInfo memoryinfo; /* Peak Memory data */ + /* Count up the number of files which are pruned dynamically. */ + uint64 dynamicPrunFiles; + /* Count up the number of files which are pruned static */ + uint64 staticPruneFiles; + /* Count up the number of rows which are filtered by the bloom filter. */ + uint64 bloomFilterRows; + /* Count up the number of strides which are filtered by the bloom filter. */ + uint64 bloomFilterBlocks; + /* Count up the number of rows which are filtered by the min/max. */ + uint64 minmaxFilterRows; + double init_time; /* executor start time */ + double end_time; /* executor end time */ + double run_time; /* executor run time */ + /* Count up the number of hdfs local block read. */ + double localBlock; + /* Count up the number of hdfs remote blocks read. */ + double remoteBlock; + uint32 warning; + /* Count the number of intersections with dfs namenode/datanode. */ + uint64 nnCalls; + uint64 dnCalls; + /* Count up the number of files to access */ + uint64 minmaxCheckFiles; + /* Count up the number of filtered files */ + uint64 minmaxFilterFiles; + /* Count up the number of stripe to access */ + uint64 minmaxCheckStripe; + /* Count up the number of filtered stripe */ + uint64 minmaxFilterStripe; + /* Count up the number of stride to access */ + uint64 minmaxCheckStride; + /* Count up the number of filtered stride */ + uint64 minmaxFilterStride; + /* Count up the number of cache hint of orc data */ + uint64 orcDataCacheBlockCount; + uint64 orcDataCacheBlockSize; + /* Count up the number of load of orc data */ + uint64 orcDataLoadBlockCount; + uint64 orcDataLoadBlockSize; + /* Count up the number of cache hint of orc meta data*/ + uint64 orcMetaCacheBlockCount; + uint64 orcMetaCacheBlockSize; + /* Count up the number of oad of orc meta data */ + uint64 orcMetaLoadBlockCount; + uint64 orcMetaLoadBlockSize; + bool isLlvmOpt; /* Optimize plan by using llvm. */ + int dfsType; /* Indicate the storage file system type */ + int width; /* avg width for the in memory tuples */ + bool sysBusy; /* if disk spill caused by system busy */ + int spreadNum; /* auto spread num */ + bool status; + bool first_time; + int dop; + TimestampTz enter_time; + + int ec_operator; /* is ec operator */ + int ec_status; /* ec task status */ + char ec_execute_datanode[NAMEDATALEN + 1]; /* ec execute datanode name*/ + char ec_dsn[NAMEDATALEN + 1]; /* ec dsn*/ + char ec_username[NAMEDATALEN + 1]; /* ec username*/ + char ec_query[ECQUERYDATALEN + 1]; /* ec execute query*/ + int ec_libodbc_type; /* ec execute libodbc_type*/ + int64 ec_fetch_count; /* ec fetch count*/ + RecursiveInfo recursiveInfo; +} Instrumentation; + +/* instrumentation data */ +typedef struct InstrStreamPlanData { + /* whether the plannode is valid */ + bool isValid; + bool isExecute; + bool isSend; + Instrumentation instruPlanData; +} InstrStreamPlanData; + +/* every plannode has a nodeInstr */ +struct NodeInstr { + /* Instrument data */ + InstrStreamPlanData instr; + int planNodeId; + int planParentId; + /* plan type for writing csv */ + int planType; + /* plantypestridx correspond to plantype for writing csv */ + uint planTypeStrIdx; + /* plan node name */ + char* name; + Track* tracks; + double ntime; +}; + +/* threadTrack is correspond to trackId in trackdesc */ +enum ThreadTrack { + /* general track */ + RECV_PLAN = 0, + START_EXEC, + FINISH_EXEC, + REPORT_FINISH, + PASS_WLM, + STREAMNET_INIT, + + /* node track */ + LOAD_CU_DESC, + MIN_MAX_CHECK, + FILL_BATCH, + GET_CU_DATA, + UNCOMPRESS_CU, + CSTORE_PROJECT, + LLVM_COMPILE_TIME, + CNNET_INIT, + CN_CHECK_AND_UPDATE_NODEDEF, + CN_SERIALIZE_PLAN, + CN_SEND_QUERYID_WITH_SYNC, + CN_SEND_BEGIN_COMMAND, + CN_START_COMMAND, + DN_STREAM_THREAD_INIT, + FILL_LATER_BATCH, + GET_CU_DATA_LATER_READ, + GET_CU_SIZE, + GET_CU_DATA_FROM_CACHE, + FILL_VECTOR_BATCH_BY_TID, + SCAN_BY_TID, + PREFETCH_CU_LIST, + GET_COMPUTE_DATANODE_CONNECTION, + GET_COMPUTE_POOL_CONNECTION, + GET_PG_LOG_TUPLES, + GET_GS_PROFILE_TUPLES, + TSSTORE_PROJECT, + TSSTORE_SEARCH, + TSSTORE_SEARCH_TAGID, + + TRACK_NUM +}; + +/* planType */ +#define HASHJOIN_OP 0x00000001 /* hashjoin */ +#define IO_OP 0x00000002 /* scan */ +#define JOIN_OP 0x00000004 /* join */ +#define SORT_OP 0x00000008 /* sort */ +#define NET_OP 0x00000010 /* net */ +#define UTILITY_OP 0x00000020 /* utility */ +#define HASHAGG_OP 0x00000040 /* hashagg */ + +/* trackType */ +#define TRACK_TIMESTAMP 0x00000001 +#define TRACK_TIME 0x00000002 +#define TRACK_COUNT 0x00000004 +#define TRACK_VALUE 0x00000008 +#define TRACK_VALUE_COUNT 0x00000010 + +/* track information */ +struct TrackDesc { + /* trackId in ThreadTrack */ + ThreadTrack trackId; + + /* trackName correspond to trackId */ + char* trackName; + + /* nodeBind is false means general track, true means node track */ + bool nodeBind; + + /* track type includes TRACK_COUNT, TRACK_TIME ,TRACK_TIMESTAMP */ + int trackType; +}; + +/* + * threadInstrInfo is obtained from getstreamInfo. + * threadInstrInfo in CN larger than threadInstrInfo in DN + * because of GATHER in CN. + */ +typedef struct ThreadInstrInfo { + /* head node id. */ + int segmentId; + + /* num of nodes in this stream. */ + int numOfNodes; + + /* base offset by the node instr array. */ + int offset; + +} ThreadInstrInfo; + +struct Plan; + +/* + * thread instrumentation + * is allocated in globalstreaminstrumentation according to needs. + * nodeInstr include instrumentation and nodetrack info in a plannodeid. + * generaltrack record the generaltrack info in every thread. + */ +class ThreadInstrumentation : public BaseObject { +public: + /* init in every thread */ + ThreadInstrumentation(uint64 queryId, int segmentId, int nodesInThread, int nodesInSql); + + ~ThreadInstrumentation(); + + /* return allocated slot for planNodeId */ + Instrumentation* allocInstrSlot(int planNodeId, int parentPlanId, Plan* plan, struct EState* estate); + + /* thread track time */ + void startTrack(int planId, ThreadTrack instrIdx); + + void endTrack(int planId, ThreadTrack instrIdx); + + int getSegmentId() + { + return m_segmentId; + } + + void setQueryString(char* qstr); + + int* get_instrArrayMap() + { + return m_instrArrayMap; + } + + Track* get_tracks(int planNodeId) + { + if (m_instrArrayMap[planNodeId - 1] == -1) + return NULL; + else { + Assert(m_instrArrayMap[planNodeId - 1] != -1); + return m_instrArray[m_instrArrayMap[planNodeId - 1]].tracks; + } + } + + int get_tracknum() + { + return m_nodeTrackNum; + } + + int getgeneraltracknum() + { + return m_generalTrackNum; + } + + int get_generaltracknum() + { + return m_generalTrackNum; + } + + int get_instrArrayLen() + { + return m_instrArrayLen; + } + +public: + uint64 m_queryId; + + /* stream top plan_node_id */ + int m_segmentId; + + /* the allocate instr array. */ + NodeInstr* m_instrArray; + + /* instr array length. */ + int m_instrArrayLen; + + /* node id to the offset of the instr array map. */ + int* m_instrArrayMap; + + /* map array length has all nodes. */ + int m_instrArrayMapLen; + + int m_instrArrayAllocIndx; + + int m_generalTrackNum; + + /* track which do not belong to any plan_node_id */ + Track* m_generalTrackArray; + + int m_nodeTrackNum; + + char* m_queryString; +}; + +/* + * GlobalStreamInstrumentation + * Instrumentation information for distributed query. + * allocated in topconsumer of DN and CN. + */ +class StreamInstrumentation : public BaseObject { +public: + /* construnctor */ + StreamInstrumentation(int size, int num_streams, int gather_count, int query_dop, int plan_size, int start_node_id, + int option, bool trackoption); + + /* deconstructor */ + ~StreamInstrumentation(); + + static StreamInstrumentation* InitOnDn(void* desc, int dop); + + static StreamInstrumentation* InitOnCn(void* desc, int dop); + + /* init globalstreaminstrumentation and threadinstrumentation in compute pool */ + static StreamInstrumentation* InitOnCP(void* desc, int dop); + + /* get the toplogy of this stream query. */ + void getStreamInfo(Plan* result_plan, PlannedStmt* planned_stmt, int dop, ThreadInstrInfo* info, int offset); + + void allocateAllThreadInstrOnDN(bool in_compute_pool); + + void allocateAllThreadInstrOnCN(); + + /* register thread in compute pool */ + void allocateAllThreadInstrOnCP(int dop); + + /* serialize the specific instrument data to remote */ + void serializeSend(); + + /* deserialize the data, and put in the specific slot. -1 means on DWS CN, else on DWS DN */ + void deserialize(int idx, char* msg, size_t len, bool operator_statitics, int cur_smp_id = -1); + + /* serialize the track data to remote. */ + void serializeSendTrack(); + + /* deserialize the track data. */ + void deserializeTrack(int idx, char* msg, size_t len); + + /* return the instrumentation related node number. */ + int getInstruNodeNum() + { + return m_nodes_num; + } + + int getInstruPlanSize() + { + return m_plannodes_num; + } + + int getInstruStartId() + { + return m_start_node_id; + } + + int getInstruThreadNum() + { + return m_num_streams; + } + + int get_gather_num() + { + return m_gather_count; + } + + int get_threadInstrArrayLen() + { + return m_threadInstrArrayLen; + } + + /* allocate slot for a node. */ + Instrumentation* allocInstrSlot(int planNodeId); + + /* return a slot in specific idx,plannodeid */ + Instrumentation* getInstrSlot(int idx, int planNodeId); + + /* Return a slot by specific idx, plannodeid and smpid. */ + Instrumentation* getInstrSlot(int idx, int planNodeId, int smpId); + + /* if this plan node run in the data node. */ + bool isFromDataNode(int planNodeId); + + bool isTrack(); + + bool needTrack() + { + return m_trackoption; + } + + void set_size(int plan_size) + { + m_nodes_num = plan_size; + m_option = 1; + } + + void SetStreamSend(int planNodeId, bool send); + bool IsSend(int idx, int plan_id, int smp_id); + + /* Get dop by plan node id. */ + int getNodeDop(int planNodeId) + { + Assert(planNodeId >= 1 && planNodeId <= m_plannodes_num); + return m_node_dops[planNodeId - 1]; + } + + int get_option() + { + return m_option; + } + + int get_query_dop() + { + return m_query_dop; + } + + MemoryContext getInstrDataContext() + { + return m_instrDataContext; + } + + int* get_planIdOffsetArray() + { + return m_planIdOffsetArray; + } + + // track time + static void TrackStartTime(int planNodeId, int trackId); + static void TrackEndTime(int planNodeId, int trackId); + + /* context for CN instrData */ + MemoryContext m_instrDataContext; + + void SetNetWork(int planNodeId, int64 buf_len); + void SetPeakNodeMemory(int planNodeId, int64 memory_size); + + ThreadInstrumentation* allocThreadInstrumentation(int SegmentId); + + /* just called by the CN of the compute pool */ + void aggregate(int plannode_num); + + /*thread instrumenation array.*/ + ThreadInstrumentation** m_threadInstrArray; + + /* every node has a offset. */ + int* m_planIdOffsetArray; + + /* get ThreadInstrumentation of TOPconsumer */ + ThreadInstrumentation* getThreadInstrumentationCN(int idx) + { + int dn_num_streams = DN_NUM_STREAMS_IN_CN(m_num_streams, m_gather_count, m_query_dop); + return m_threadInstrArray[1 + idx * dn_num_streams]; + } + + /* get threadinstrArray in idx(DN) and planNodeId */ + ThreadInstrumentation* getThreadInstrumentationCN(int idx, int planNodeId, int smp) + { + int offset = + (m_planIdOffsetArray[planNodeId - 1] == 0) ? -1 : (m_planIdOffsetArray[planNodeId - 1] - 1) * m_query_dop; + int dn_num_streams = DN_NUM_STREAMS_IN_CN(m_num_streams, m_gather_count, m_query_dop); + + Assert(planNodeId >= 1 && planNodeId <= m_plannodes_num); + + if (offset == -1) + return m_threadInstrArray[0]; + else + return m_threadInstrArray[1 + idx * dn_num_streams + offset + smp]; + } + + /* get ThreadInstrumentation in DN */ + ThreadInstrumentation* getThreadInstrumentationDN(int planNodeId) + { + return m_threadInstrArray[m_planIdOffsetArray[planNodeId - 1] * m_query_dop]; + } + + /* get threadinstrumentation of current CN */ + ThreadInstrumentation* get_cnthreadinstrumentation(int index) + { + Assert(index >= 0 && index <= m_threadInstrArrayLen); + + return m_threadInstrArray[index]; + } + + int get_startnodeid() + { + /* get start_node_id of DN*/ + for (int i = 1; i < m_plannodes_num + 1; i++) { + if (m_planIdOffsetArray[i - 1] == 1) { + return i; + } + } + + return 1; + } + +private: + /* number of data nodes. */ + int m_nodes_num; + + /* number of stream nodes. */ + int m_num_streams; + + /* gather operator count */ + int m_gather_count; + + /* query dop. */ + int m_query_dop; + + /* number of plan nodes. */ + int m_plannodes_num; + + // the query id of the global instrumentation. + uint64 m_query_id; + + /* start node id of plan. */ + int m_start_node_id; + + /* dop of each plan nodes. */ + int* m_node_dops; + + /* how many thread instrumentation */ + int m_threadInstrArrayLen; + + /* thread info for this query*/ + ThreadInstrInfo* m_streamInfo; + + int m_streamInfoIdx; + + /* instrumentation flag. */ + int m_option; + + /* track flag */ + bool m_trackoption; +}; + +// Maximal number of counters support +// +#define MAX_CPU_COUNTERS 3 + +// Predefined PMU counter groups +// +typedef enum CPUMonGroupID { + CMON_GENERAL = 0, +} CPUMonGroupID; + +// For view of gs_wlm_operator_history +// +typedef enum WlmOperatorstatus { + Operator_Normal = 0, + Operator_Pending, + Operator_Invalid, +} WlmOperatorstatus; + +typedef struct CPUMonGroup { + // group identifier + // + CPUMonGroupID m_id; + // list of counters + // + int m_cCounters; + int m_counters[MAX_CPU_COUNTERS]; +} CPUMonGroup; + +// Core class implementing PMU counters monitoring +// +class CPUMon { +public: + static THR_LOCAL bool m_has_perf; + static THR_LOCAL bool m_has_initialize; + +private: + // Number of counters in the group + // + static THR_LOCAL int m_cCounters; + + // File descriptor for each counter + // + static THR_LOCAL int m_fd[MAX_CPU_COUNTERS]; + +private: + FORCE_INLINE static void validCounter(_in_ int i) + { + DBG_ASSERT(i >= 0 && i < m_cCounters); + } + +public: + static void Initialize(_in_ CPUMonGroupID id); + static void Shutdown(); + static int64 ReadCounter(_in_ int i); + static int ReadCounters(_out_ int64* pCounters); + static int ResetCounters(_out_ int64* pCounters); + static int RestartCounters(_out_ int64* pCounters, _out_ int64* pAccumCounters); + static int AccumCounters(__inout int64* pCounters, __inout int64* pAccumCounters); + static bool get_perf(); +}; + +typedef struct OBSRuntimeInfo { + NameData relname; + int32 file_scanned; + int64 data_size; + double actual_time; + int32 format; +} OBSRuntimeInfo; + +/* class to collect the OBS runtime info. */ +class OBSInstrumentation : public BaseObject { +public: + // construnctor + OBSInstrumentation(); + + // deconstructor + ~OBSInstrumentation(); + + /* called by HdfsEndForeignScan to collect node data */ + void save(const char* relname, int file_scanned, int64 data_size, double actual_time, int32 format); + + /* send the obs runimte info to uppler node. */ + void serializeSend(); + + /* receive data from lower node. */ + void deserialize(char* msg, size_t len); + + /* insert obs runtime data to pg_obsscaninfo. */ + void insertData(uint64 queryid); + + bool* m_p_globalOBSInstrument_valid; + +private: + List* m_rels; + MemoryContext m_ctx; +}; + +typedef struct Qpid { + Oid procId; /* cn thread id for the statement */ + uint64 queryId; /* debug query id for statement */ + int plannodeid; +} Qpid; + +typedef struct OperatorProfileTable { + int max_realtime_num; /* max session info num in the hash table */ + int max_collectinfo_num; /* max collect info num in list */ + + HTAB* explain_info_hashtbl; /* collect information hash table */ + HTAB* collected_info_hashtbl; /* collect information hash table */ +} OperatorProfileTable; + +typedef struct OperatorInfo { + int64 total_tuples; /* Total tuples produced */ + int64 peak_memory; + int64 spill_size; + TimestampTz enter_time; + int64 execute_time; + uint status; + uint warning; + + int ec_operator; + int ec_status; + char* ec_execute_datanode; + char* ec_dsn; + char* ec_username; + char* ec_query; + int ec_libodbc_type; + int64 ec_fetch_count; +} OperatorInfo; + +typedef struct ExplainDNodeInfo { + Qpid qid; /* id for statement on dn */ + Oid userid; /* user id */ + bool execute_on_datanode; /* execute on datanode */ + bool can_record_to_table; /* flag for whether to record the information table */ + WlmOperatorstatus status; /* the status for this operator */ + char* plan_name; /* plan node name */ + int query_dop; /* query dop */ + int64 estimated_rows; /* plan estimated rows */ + void* explain_entry; /* session instrumentation entry */ + OperatorInfo geninfo; /* general info for the dnode collect info */ + TimestampTz exptime; /* record expire time */ +} ExplainDNodeInfo; + +typedef struct ExplainGeneralInfo { + ThreadId tid; /* thread id for statement */ + uint64 query_id; /* debug query id */ + int plan_node_id; /* plan node id */ + char* plan_node_name; /* plan node name */ + TimestampTz start_time; /* start execute time for operator */ + double duration_time; /* max execute time */ + int query_dop; /* query dop */ + int64 estimate_rows; /* plan estimated rows */ + int64 tuple_processed; /* plan processed rows */ + int32 min_peak_memory; /* min peak memory for each datanode */ + int32 max_peak_memory; /* max peak memory for each datanode */ + int32 avg_peak_memory; /* average peak memory for each datanode */ + int memory_skewed; /* peak memory skew for each datanode */ + int32 min_spill_size; /* min spill size for each datanode */ + int32 max_spill_size; /* max spill size for each datanode */ + int32 avg_spill_size; /* average spill size for each datanode */ + int i_o_skew; /* spill size skew for each datanode */ + int64 min_cpu_time; /* min execute time for each datanode */ + int64 max_cpu_time; /* max execute time for each datanode */ + int64 total_cpu_time; /* total execute time for each datanode */ + int cpu_skew; /* execute time skew for each datanode */ + int warn_prof_info; /* warning info */ + bool status; /* execute status */ + bool execute_on_datanode; /* execute on datanode */ + bool remove; /* remove info from hash table */ + + int ec_operator; /* is ec operator */ + int ec_status; /* ec task status */ + char* ec_execute_datanode; /* ec execute datanode name*/ + char* ec_dsn; /* ec dsn*/ + char* ec_username; /* ec username*/ + char* ec_query; /* ec execute query*/ + int ec_libodbc_type; /* ec execute libodbc_type*/ + int64 ec_fetch_count; /* ec fetch count*/ +} ExplainGeneralInfo; + +typedef struct size_info { + int64 total_tuple; + int64 total_memory; + int64 total_spill_size; + int64 total_cpu_time; + int64 max_peak_memory; + int64 min_peak_memory; + int64 max_spill_size; + int64 min_spill_size; + int64 min_cpu_time; + int64 max_cpu_time; + TimestampTz start_time; + double duration_time; /* max execute time */ + char* plan_node_name; + uint warn_prof_info; + uint status; + bool has_data; + int dn_count; + + int ec_operator; + int ec_status; + char* ec_execute_datanode; + char* ec_dsn; + char* ec_username; + char* ec_query; + int ec_libodbc_type; + int64 ec_fetch_count; +} size_info; + +extern OperatorProfileTable g_operator_table; + +extern Instrumentation* InstrAlloc(int n, int instrument_options); +extern void InstrStartNode(Instrumentation* instr); +extern void InstrStopNode(Instrumentation* instr, double nTuples); +extern void InstrEndLoop(Instrumentation* instr); +extern void StreamEndLoop(StreamTime* instr); +extern void AddControlMemoryContext(Instrumentation* instr, MemoryContext context); +extern void CalculateContextSize(MemoryContext ctx, int64* memorySize); +extern void NetWorkTimePollStart(Instrumentation* instr); +extern void NetWorkTimePollEnd(Instrumentation* instr); +extern void NetWorkTimeDeserializeStart(Instrumentation* instr); +extern void NetWorkTimeDeserializeEnd(Instrumentation* instr); +extern void NetWorkTimeCopyStart(Instrumentation* instr); +extern void NetWorkTimeCopyEnd(Instrumentation* instr); +extern void SetInstrNull(); + +extern void StreamTimeSendStart(Instrumentation* instr); +extern void StreamTimeSendEnd(Instrumentation* instr); +extern void StreamTimeWaitQuotaStart(Instrumentation* instr); +extern void StreamTimeWaitQuotaEnd(Instrumentation* instr); +extern void StreamTimeOSSendStart(Instrumentation* instr); +extern void StreamTimeOSSendEnd(Instrumentation* instr); +extern void StreamTimeSerilizeStart(Instrumentation* instr); +extern void StreamTimeSerilizeEnd(Instrumentation* instr); +extern void StreamTimeCopyStart(Instrumentation* instr); +extern void StreamTimeCopyEnd(Instrumentation* instr); + +extern LWLock* LockOperRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockOperHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockOperRealTHashPartition(uint32 hashCode); +extern void UnLockOperHistHashPartition(uint32 hashCode); +extern void ExplainCreateDNodeInfoOnDN( + Qpid* qid, Instrumentation* instr, bool on_dn, const char* plan_name, int dop, int64 estimated_rows); +extern uint32 GetHashPlanCode(const void* key1, Size keysize); +extern void InitOperStatProfile(void); +extern void* ExplainGetSessionStatistics(int* num); +extern void ExplainSetSessionInfo(int plan_node_id, Instrumentation* instr, bool on_datanode, const char* plan_name, + int dop, int64 estimated_rows, TimestampTz current_time); +extern void* ExplainGetSessionInfo(const Qpid* qid, int removed, int* num); +extern void releaseExplainTable(); +extern bool IsQpidInvalid(const Qpid* qid); +extern void sendExplainInfo(OperatorInfo* sessionMemory); +extern void ExplainStartToGetStatistics(void); +extern void removeExplainInfo(int plan_node_id); +extern void OperatorStrategyFunc4SessionInfo(StringInfo msg, void* suminfo, int size); +extern void setOperatorInfo(OperatorInfo* operatorMemory, Instrumentation* InstrMemory); +extern int64 e_rows_convert_to_int64(double plan_rows); +extern void releaseOperatorInfoEC(OperatorInfo* sessionMemory); +#endif /* INSTRUMENT_H */ diff -uprN postgresql-hll-2.14_old/include/executor/lightProxy.h postgresql-hll-2.14/include/executor/lightProxy.h --- postgresql-hll-2.14_old/include/executor/lightProxy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/lightProxy.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,206 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lightProxy.h + * + * + * + * IDENTIFICATION + * src/include/executor/lightProxy.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ +#define SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ + +#include "commands/prepare.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/plancache.h" + +#define BIND_MESSAGE 1 +#define DESC_MESSAGE 2 +#define EXEC_MESSAGE 3 + +#ifdef USE_ASSERT_CHECKING +#ifndef LPROXY_DEBUG +#define LPROXY_DEBUG(A) A +#endif +#else +#ifndef LPROXY_DEBUG +#define LPROXY_DEBUG(A) /* A */ +#endif +#endif + +/* check whether query executed through light proxy or not*/ +extern bool IsLightProxyOn(void); +extern void GPCDropLPIfNecessary(const char *stmt_name, bool need_drop_dnstmt, + bool need_del, CachedPlanSource *reset_plan); +void GPCFillMsgForLp(CachedPlanSource* psrc); + +CmdType set_command_type_by_commandTag(const char* commandTag); + +typedef enum LightUnSupportType { + CTRL_DISABLE = 0, + ENCODE_UNSUPPORT, + CURSOR_UNSUPPORT, + REMOTE_UNSUPPORT, + CMD_UNSUPPORT, + FOREIGN_UNSUPPORT, + STATEMENT_UNSUPPORT, + USERTYPE_UNSUPPORT, + MAX_UNSUPPORT_TYPE +} LightUnSupportType; + +/* like in RemoteQueryState */ +struct lightProxyErrData { + bool hasError; /* indicate whether some error occurs */ + + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + bool is_fatal_error; /* mark if it is a FATAL error */ + RemoteErrorData remoteErrData; /* error data from remote */ +}; + +struct lightProxyMsgCtl { + bool cnMsg; + bool sendDMsg; + bool hasResult; + lightProxyErrData* errData; + + int* process_count; + +#ifdef LPROXY_DEBUG + char* stmt_name; + const char* query_string; +#endif +}; + +typedef struct stmtLpObj { + char stmtname[NAMEDATALEN]; + lightProxy *proxy; +} stmtLpObj; + +typedef struct lightProxyNamedObj { + char portalname[NAMEDATALEN]; + lightProxy *proxy; +} lightProxyNamedObj; + +class lightProxy : public BaseObject { +public: + // constructor. + lightProxy(MemoryContext context, CachedPlanSource *psrc, const char *portalname, const char *stmtname); + + lightProxy(Query *query); + + ~lightProxy(); + + static ExecNodes *checkLightQuery(Query *query); + + // check if enable router for lightproxy + static ExecNodes *checkRouterQuery(Query *query); + + // after bind we need to set this for discrible and execute + static void setCurrentProxy(lightProxy *proxy); + + // process B/D/E message + static bool processMsg(int msgType, StringInfo msg); + + static void initStmtHtab(); + + static void initlightProxyTable(); + + static lightProxy *locateLpByStmtName(const char *stmtname); + + static lightProxy *locateLightProxy(const char *portalname); + + static lightProxy *tryLocateLightProxy(StringInfo msg); + // run with simple query message + void runSimpleQuery(StringInfo exec_message); + + // run with batch message + int runBatchMsg(StringInfo batch_message, bool sendDMsg, int batch_count); + + static void tearDown(lightProxy *proxy); + + void storeLpByStmtName(const char *stmtname); + + void storeLightProxy(const char *portalname); + + void removeLpByStmtName(const char *stmtname); + + static void removeLightProxy(const char* portalname); + + static bool isDeleteLimit(const Query *query); + +public: + CachedPlanSource *m_cplan; + + int m_nodeIdx; + + MemoryContext m_context; + + /* whether row trigger can shippable. */ + bool m_isRowTriggerShippable; + + const char *m_stmtName; + + const char *m_portalName; + + int16 *m_formats; + +protected: + // saveMsg + void saveMsg(int msgType, StringInfo msg); + // get result format from msg + void getResultFormat(StringInfo message); + + void assemableMsg(char msgtype, StringInfo msgBuf, bool trigger_ship = false); + + // run with execute message + void runMsg(StringInfo exec_message); + + void connect(); + + void handleResponse(); + + void sendParseIfNecessary(); + + void proxyNodeBegin(bool is_read_only); + + CmdType m_cmdType; + CmdType queryType; + +private: + Query *m_query; + + PGXCNodeHandle *m_handle; + + StringInfoData m_bindMessage; + + StringInfoData m_describeMessage; + + lightProxyMsgCtl *m_msgctl; + + DatanodeStatement *m_entry; +}; + +extern bool exec_query_through_light_proxy(List* querytree_list, Node* parsetree, bool snapshot_set, StringInfo msg, + MemoryContext OptimizerContext); + +#endif /* SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeAgg.h postgresql-hll-2.14/include/executor/nodeAgg.h --- postgresql-hll-2.14_old/include/executor/nodeAgg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeAgg.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,288 @@ +/* ------------------------------------------------------------------------- + * + * nodeAgg.h + * prototypes for nodeAgg.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeAgg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEAGG_H +#define NODEAGG_H + +#include "nodes/execnodes.h" +#include "catalog/pg_aggregate.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" +#include "executor/executor.h" +#include "executor/nodeAgg.h" +#include "miscadmin.h" +#include "nodes/nodeFuncs.h" +#include "optimizer/clauses.h" +#include "optimizer/tlist.h" +#include "parser/parse_agg.h" +#include "parser/parse_coerce.h" +#include "utils/acl.h" +#include "utils/builtins.h" +#include "utils/lsyscache.h" +#include "utils/memutils.h" +#include "utils/syscache.h" +#include "utils/tuplesort.h" +#include "utils/datum.h" +#include "vecexecutor/vechashtable.h" + +// hash strategy +#define MEMORY_HASHAGG 0 +#define DIST_HASHAGG 1 + +#define HASHAGG_PREPARE 0 +#define HASHAGG_FETCH 1 + +#define HASH_MIN_FILENUMBER 48 +#define HASH_MAX_FILENUMBER 512 + +typedef struct AggWriteFileControl { + bool spillToDisk; /*whether data write to temp file*/ + bool finishwrite; + int strategy; + int runState; + int64 useMem; /* useful memory, in bytes */ + int64 totalMem; /*total memory, in bytes*/ + int64 inmemoryRownum; + hashSource* m_hashAggSource; + hashFileSource* filesource; + int filenum; + int curfile; + int64 maxMem; /* mem spread memory, in bytes */ + int spreadNum; /* dynamic spread time */ +} AggWriteFileControl; + +/* + * AggStatePerAggData - per-aggregate working state for the Agg scan + */ +typedef struct AggStatePerAggData { + /* + * These values are set up during ExecInitAgg() and do not change + * thereafter: + */ + + /* Links to Aggref expr and state nodes this working state is for */ + AggrefExprState* aggrefstate; + Aggref* aggref; + + /* number of input arguments for aggregate function proper */ + int numArguments; + + /* number of inputs including ORDER BY expressions */ + int numInputs; + + bool is_avg; + + /* + * Number of aggregated input columns to pass to the transfn. This + * includes the ORDER BY columns for ordered-set aggs, but not for plain + * aggs. (This doesn't count the transition state value!) + */ + int numTransInputs; + + /* Oids of transfer functions */ + Oid transfn_oid; + Oid finalfn_oid; /* may be InvalidOid */ +#ifdef PGXC + Oid collectfn_oid; /* may be InvalidOid */ +#endif /* PGXC */ + + /* + * fmgr lookup data for transfer functions --- only valid when + * corresponding oid is not InvalidOid. Note in particular that fn_strict + * flags are kept here. + */ + FmgrInfo transfn; + FmgrInfo finalfn; +#ifdef PGXC + FmgrInfo collectfn; +#endif /* PGXC */ + + /* Input collation derived for aggregate */ + Oid aggCollation; + + /* number of sorting columns */ + int numSortCols; + + /* number of sorting columns to consider in DISTINCT comparisons */ + /* (this is either zero or the same as numSortCols) */ + int numDistinctCols; + + /* deconstructed sorting information (arrays of length numSortCols) */ + AttrNumber* sortColIdx; + Oid* sortOperators; + Oid* sortCollations; + bool* sortNullsFirst; + + /* + * fmgr lookup data for input columns' equality operators --- only + * set/used when aggregate has DISTINCT flag. Note that these are in + * order of sort column index, not parameter index. + */ + FmgrInfo* equalfns; /* array of length numDistinctCols */ + + /* + * initial value from pg_aggregate entry + */ + Datum initValue; + bool initValueIsNull; +#ifdef PGXC + Datum initCollectValue; + bool initCollectValueIsNull; +#endif /* PGXC */ + + /* + * We need the len and byval info for the agg's input, result, and + * transition data types in order to know how to copy/delete values. + * + * Note that the info for the input type is used only when handling + * DISTINCT aggs with just one argument, so there is only one input type. + */ + int16 inputtypeLen, resulttypeLen, transtypeLen; + bool inputtypeByVal, resulttypeByVal, transtypeByVal; + + /* + * Stuff for evaluation of inputs. We used to just use ExecEvalExpr, but + * with the addition of ORDER BY we now need at least a slot for passing + * data to the sort object, which requires a tupledesc, so we might as + * well go whole hog and use ExecProject too. + */ + TupleDesc evaldesc; /* descriptor of input tuples */ + ProjectionInfo* evalproj; /* projection machinery */ + + /* + * Slots for holding the evaluated input arguments. These are set up + * during ExecInitAgg() and then used for each input row. + */ + TupleTableSlot* evalslot; /* current input tuple */ + TupleTableSlot* uniqslot; /* used for multi-column DISTINCT */ + + /* + * These values are working state that is initialized at the start of an + * input tuple group and updated for each input tuple. + * + * For a simple (non DISTINCT/ORDER BY) aggregate, we just feed the input + * values straight to the transition function. If it's DISTINCT or + * requires ORDER BY, we pass the input values into a Tuplesort object; + * then at completion of the input tuple group, we scan the sorted values, + * eliminate duplicates if needed, and run the transition function on the + * rest. + */ + + Tuplesortstate** sortstates; /* sort object, if DISTINCT or ORDER BY */ + Tuplesortstate* sortstate; /* sort object, if DISTINCT or ORDER BY */ + + /* + * This field is a pre-initialized FunctionCallInfo struct used for + * calling this aggregate's transfn. We save a few cycles per row by not + * re-initializing the unchanging fields; which isn't much, but it seems + * worth the extra space consumption. + */ + FunctionCallInfoData transfn_fcinfo; +} AggStatePerAggData; + +/* + * AggStatePerPhaseData - per-grouping-set-phase state + * + * Grouping sets are divided into "phases", where a single phase can be + * processed in one pass over the input. If there is more than one phase, then + * at the end of input from the current phase, state is reset and another pass + * taken over the data which has been re-sorted in the mean time. + * + * Accordingly, each phase specifies a list of grouping sets and group clause + * information, plus each phase after the first also has a sort order. + */ +typedef struct AggStatePerPhaseData { + int numsets; /* number of grouping sets (or 0) */ + int* gset_lengths; /* lengths of grouping sets */ + Bitmapset** grouped_cols; /* column groupings for rollup */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + Agg* aggnode; /* Agg node for phase data */ + Sort* sortnode; /* Sort node for input ordering for phase */ +} AggStatePerPhaseData; + +/* + * AggStatePerGroupData - per-aggregate-per-group working state + * + * These values are working state that is initialized at the start of + * an input tuple group and updated for each input tuple. + * + * In AGG_PLAIN and AGG_SORTED modes, we have a single array of these + * structs (pointed to by aggstate->pergroup); we re-use the array for + * each input group, if it's AGG_SORTED mode. In AGG_HASHED mode, the + * hash table contains an array of these structs for each tuple group. + * + * Logically, the sortstate field belongs in this struct, but we do not + * keep it here for space reasons: we don't support DISTINCT aggregates + * in AGG_HASHED mode, so there's no reason to use up a pointer field + * in every entry of the hashtable. + */ +typedef struct AggStatePerGroupData { + Datum transValue; /* current transition value */ + Datum collectValue; /* current collection value */ + bool transValueIsNull; + + bool noTransValue; /* true if transValue not set yet */ + bool collectValueIsNull; + bool noCollectValue; /* true if the collectValue not set yet */ + + /* + * Note: noTransValue initially has the same value as transValueIsNull, + * and if true both are cleared to false at the same time. They are not + * the same though: if transfn later returns a NULL, we want to keep that + * NULL and not auto-replace it with a later input value. Only the first + * non-NULL input will be auto-substituted. + */ +#ifdef PGXC + /*collectValue, collectValueIsNull and noCollectValue are added by PGXC*/ + /* + * We should be able to reuse the fields above, rather than having + * separate fields here, that can be done once we get rid of different + * collection and transition result types in pg_aggregate.h. Collection at + * Coordinator is equivalent to the transition at non-XC PG. + */ +#endif /* PGXC */ +} AggStatePerGroupData; + +/* + * To implement hashed aggregation, we need a hashtable that stores a + * representative tuple and an array of AggStatePerGroup structs for each + * distinct set of GROUP BY column values. We compute the hash key from + * the GROUP BY columns. + */ +typedef struct AggHashEntryData* AggHashEntry; + +typedef struct AggHashEntryData { + TupleHashEntryData shared; /* common header for hash table entries */ + /* per-aggregate transition status array - must be last! */ + AggStatePerGroupData pergroup[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} AggHashEntryData; /* VARIABLE LENGTH STRUCT */ + +extern AggState* ExecInitAgg(Agg* node, EState* estate, int eflags); +extern TupleTableSlot* ExecAgg(AggState* node); +extern void ExecEndAgg(AggState* node); +extern void ExecReScanAgg(AggState* node); +extern Datum GetAggInitVal(Datum textInitVal, Oid transtype); +extern Size hash_agg_entry_size(int numAggs); + +extern Datum aggregate_dummy(PG_FUNCTION_ARGS); +extern long ExecGetMemCostAgg(Agg*); +extern void initialize_phase(AggState* aggstate, int newphase); +extern List* find_hash_columns(AggState* aggstate); +extern uint32 ComputeHashValue(TupleHashTable hashtbl); +extern int getPower2Num(int num); +extern void agg_spill_to_disk(AggWriteFileControl* TempFileControl, TupleHashTable hashtable, TupleTableSlot* hashslot, + int numGroups, bool isAgg, int planId, int dop, Instrumentation* intrument = NULL); +extern void ExecEarlyFreeAggregation(AggState* node); +extern void ExecReSetAgg(AggState* node); + +#endif /* NODEAGG_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeAppend.h postgresql-hll-2.14/include/executor/nodeAppend.h --- postgresql-hll-2.14_old/include/executor/nodeAppend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeAppend.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeAppend.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeAppend.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEAPPEND_H +#define NODEAPPEND_H + +#include "nodes/execnodes.h" + +extern AppendState* ExecInitAppend(Append* node, EState* estate, int eflags); +extern TupleTableSlot* ExecAppend(AppendState* node); +extern void ExecEndAppend(AppendState* node); +extern void ExecReScanAppend(AppendState* node); +extern bool exec_append_initialize_next(AppendState* appendstate); + +#endif /* NODEAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeBitmapAnd.h postgresql-hll-2.14/include/executor/nodeBitmapAnd.h --- postgresql-hll-2.14_old/include/executor/nodeBitmapAnd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeBitmapAnd.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapAnd.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapAnd.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPAND_H +#define NODEBITMAPAND_H + +#include "nodes/execnodes.h" + +extern BitmapAndState* ExecInitBitmapAnd(BitmapAnd* node, EState* estate, int eflags); +extern Node* MultiExecBitmapAnd(BitmapAndState* node); +extern void ExecEndBitmapAnd(BitmapAndState* node); +extern void ExecReScanBitmapAnd(BitmapAndState* node); + +#endif /* NODEBITMAPAND_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeBitmapHeapscan.h postgresql-hll-2.14/include/executor/nodeBitmapHeapscan.h --- postgresql-hll-2.14_old/include/executor/nodeBitmapHeapscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeBitmapHeapscan.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapHeapscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapHeapscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPHEAPSCAN_H +#define NODEBITMAPHEAPSCAN_H + +#include "nodes/execnodes.h" + +extern BitmapHeapScanState* ExecInitBitmapHeapScan(BitmapHeapScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecBitmapHeapScan(BitmapHeapScanState* node); +extern void ExecEndBitmapHeapScan(BitmapHeapScanState* node); +extern void ExecReScanBitmapHeapScan(BitmapHeapScanState* node); + +#endif /* NODEBITMAPHEAPSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeBitmapIndexscan.h postgresql-hll-2.14/include/executor/nodeBitmapIndexscan.h --- postgresql-hll-2.14_old/include/executor/nodeBitmapIndexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeBitmapIndexscan.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapIndexscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapIndexscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPINDEXSCAN_H +#define NODEBITMAPINDEXSCAN_H + +#include "nodes/execnodes.h" + +extern BitmapIndexScanState* ExecInitBitmapIndexScan(BitmapIndexScan* node, EState* estate, int eflags); +extern Node* MultiExecBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecEndBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecReScanBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecInitPartitionForBitmapIndexScan(BitmapIndexScanState* indexstate, EState* estate, Relation rel); + +#endif /* NODEBITMAPINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeBitmapOr.h postgresql-hll-2.14/include/executor/nodeBitmapOr.h --- postgresql-hll-2.14_old/include/executor/nodeBitmapOr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeBitmapOr.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapOr.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapOr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPOR_H +#define NODEBITMAPOR_H + +#include "nodes/execnodes.h" + +extern BitmapOrState* ExecInitBitmapOr(BitmapOr* node, EState* estate, int eflags); +extern Node* MultiExecBitmapOr(BitmapOrState* node); +extern void ExecEndBitmapOr(BitmapOrState* node); +extern void ExecReScanBitmapOr(BitmapOrState* node); + +#endif /* NODEBITMAPOR_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeCtescan.h postgresql-hll-2.14/include/executor/nodeCtescan.h --- postgresql-hll-2.14_old/include/executor/nodeCtescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeCtescan.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeCtescan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeCtescan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODECTESCAN_H +#define NODECTESCAN_H + +#include "nodes/execnodes.h" + +extern CteScanState* ExecInitCteScan(CteScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecCteScan(CteScanState* node); +extern void ExecEndCteScan(CteScanState* node); +extern void ExecReScanCteScan(CteScanState* node); + +#endif /* NODECTESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeExtensible.h postgresql-hll-2.14/include/executor/nodeExtensible.h --- postgresql-hll-2.14_old/include/executor/nodeExtensible.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeExtensible.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeExtensible.h + * the structure of extensible plan node + * + * + * IDENTIFICATION + * src/include/executor/nodeExtensible.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODEEXTENSIBLE_H +#define NODEEXTENSIBLE_H + +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" +/* + * General executor code + */ +extern ExtensiblePlanState* ExecInitExtensiblePlan(ExtensiblePlan* eplan, EState* estate, int eflags); +extern TupleTableSlot* ExecExtensiblePlan(ExtensiblePlanState* node); +extern void ExecEndExtensiblePlan(ExtensiblePlanState* node); + +extern void ExecReScanExtensiblePlan(ExtensiblePlanState* node); +extern ExtensiblePlanMethods* GetExtensiblePlanMethods(const char* ExtensibleName, bool missing_ok); + +#ifdef ENABLE_MULTIPLE_NODES +extern void InitExtensiblePlanMethodsHashTable(); +#endif + +#endif /* NODEEXTENSIBLE_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeForeignscan.h postgresql-hll-2.14/include/executor/nodeForeignscan.h --- postgresql-hll-2.14_old/include/executor/nodeForeignscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeForeignscan.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeForeignscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeForeignscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFOREIGNSCAN_H +#define NODEFOREIGNSCAN_H + +#include "nodes/execnodes.h" + +extern ForeignScanState* ExecInitForeignScan(ForeignScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecForeignScan(ForeignScanState* node); +extern void ExecEndForeignScan(ForeignScanState* node); +extern void ExecReScanForeignScan(ForeignScanState* node); + +#endif /* NODEFOREIGNSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeFunctionscan.h postgresql-hll-2.14/include/executor/nodeFunctionscan.h --- postgresql-hll-2.14_old/include/executor/nodeFunctionscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeFunctionscan.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeFunctionscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeFunctionscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFUNCTIONSCAN_H +#define NODEFUNCTIONSCAN_H + +#include "nodes/execnodes.h" + +extern FunctionScanState* ExecInitFunctionScan(FunctionScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecFunctionScan(FunctionScanState* node); +extern void ExecEndFunctionScan(FunctionScanState* node); +extern void ExecReScanFunctionScan(FunctionScanState* node); + +#endif /* NODEFUNCTIONSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeGroup.h postgresql-hll-2.14/include/executor/nodeGroup.h --- postgresql-hll-2.14_old/include/executor/nodeGroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeGroup.h 2020-12-12 17:06:43.112346296 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeGroup.h + * prototypes for nodeGroup.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeGroup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEGROUP_H +#define NODEGROUP_H + +#include "nodes/execnodes.h" + +extern GroupState* ExecInitGroup(Group* node, EState* estate, int eflags); +extern TupleTableSlot* ExecGroup(GroupState* node); +extern void ExecEndGroup(GroupState* node); +extern void ExecReScanGroup(GroupState* node); + +#endif /* NODEGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeHash.h postgresql-hll-2.14/include/executor/nodeHash.h --- postgresql-hll-2.14_old/include/executor/nodeHash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeHash.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * nodeHash.h + * prototypes for nodeHash.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeHash.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEHASH_H +#define NODEHASH_H + +#include "nodes/execnodes.h" +#include "nodes/relation.h" + +#define MIN_HASH_BUCKET_SIZE 32768 /* min bucketsize for hash join */ +#define BUCKET_OVERHEAD 8 + +extern HashState* ExecInitHash(Hash* node, EState* estate, int eflags); +extern TupleTableSlot* ExecHash(void); +extern Node* MultiExecHash(HashState* node); +extern void ExecEndHash(HashState* node); +extern void ExecReScanHash(HashState* node); + +extern HashJoinTable ExecHashTableCreate(Hash* node, List* hashOperators, bool keepNulls); +extern void ExecHashTableDestroy(HashJoinTable hashtable); +extern void ExecHashTableInsert(HashJoinTable hashtable, TupleTableSlot* slot, uint32 hashvalue, int planid, int dop, + Instrumentation* instrument = NULL); +extern bool ExecHashGetHashValue(HashJoinTable hashtable, ExprContext* econtext, List* hashkeys, bool outer_tuple, + bool keep_nulls, uint32* hashvalue); +extern void ExecHashGetBucketAndBatch(HashJoinTable hashtable, uint32 hashvalue, int* bucketno, int* batchno); +extern bool ExecScanHashBucket(HashJoinState* hjstate, ExprContext* econtext); +extern void ExecPrepHashTableForUnmatched(HashJoinState* hjstate); +extern bool ExecScanHashTableForUnmatched(HashJoinState* hjstate, ExprContext* econtext); +extern void ExecHashTableReset(HashJoinTable hashtable); +extern void ExecHashTableResetMatchFlags(HashJoinTable hashtable); +extern void ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew, int* numbuckets, int* numbatches, + int* num_skew_mcvs, int4 localWorkMem, bool vectorized = false, OpMemInfo* memInfo = NULL); +extern double ExecChooseHashTableMaxTuples(int tupwidth, bool useskew, bool vectorized, double hash_table_bytes); +extern int ExecHashGetSkewBucket(HashJoinTable hashtable, uint32 hashvalue); +extern void ExecHashTableStats(HashJoinTable hashtable, int planid); +extern int ExecSonicHashGetAtomTypeSize(Oid typeOid, int typeMod, bool isHashKey); +extern int64 ExecSonicHashGetAtomArrayBytes( + double ntuples, int m_arrSize, int m_atomSize, int64 atomTypeSize, bool hasNullFlag); +extern void ExecChooseSonicHashTableSize(Path* inner_path, List* hashclauses, int* inner_width, + bool isComplicateHashKey, int* numbuckets, int* numbatches, int4 localWorkMem, OpMemInfo* memInfo, int dop); +extern uint8 EstimateBucketTypeSize(int nbuckets); + +#endif /* NODEHASH_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeHashjoin.h postgresql-hll-2.14/include/executor/nodeHashjoin.h --- postgresql-hll-2.14_old/include/executor/nodeHashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeHashjoin.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * nodeHashjoin.h + * prototypes for nodeHashjoin.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeHashjoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEHASHJOIN_H +#define NODEHASHJOIN_H + +#include "nodes/execnodes.h" +#include "storage/buffile.h" +#include "optimizer/planmem_walker.h" + +extern HashJoinState* ExecInitHashJoin(HashJoin* node, EState* estate, int eflags); +extern TupleTableSlot* ExecHashJoin(HashJoinState* node); +extern void ExecEndHashJoin(HashJoinState* node); +extern void ExecReScanHashJoin(HashJoinState* node); +extern void ExecHashJoinSaveTuple(MinimalTuple tuple, uint32 hashvalue, BufFile** fileptr); +extern void ExecEarlyFreeHashJoin(HashJoinState* node); +extern void ExecReSetHashJoin(HashJoinState* node); +extern bool FindParam(Node* node_plan, void* context); +extern bool CheckParamWalker(PlanState* plan_stat); + +#endif /* NODEHASHJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeIndexonlyscan.h postgresql-hll-2.14/include/executor/nodeIndexonlyscan.h --- postgresql-hll-2.14_old/include/executor/nodeIndexonlyscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeIndexonlyscan.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeIndexonlyscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeIndexonlyscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEINDEXONLYSCAN_H +#define NODEINDEXONLYSCAN_H + +#include "nodes/execnodes.h" + +extern IndexOnlyScanState* ExecInitIndexOnlyScan(IndexOnlyScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecIndexOnlyScan(IndexOnlyScanState* node); +extern void ExecEndIndexOnlyScan(IndexOnlyScanState* node); +extern void ExecIndexOnlyMarkPos(IndexOnlyScanState* node); +extern void ExecIndexOnlyRestrPos(IndexOnlyScanState* node); +extern void ExecReScanIndexOnlyScan(IndexOnlyScanState* node); +extern void StoreIndexTuple(TupleTableSlot* slot, IndexTuple itup, TupleDesc itupdesc); +#endif /* NODEINDEXONLYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeIndexscan.h postgresql-hll-2.14/include/executor/nodeIndexscan.h --- postgresql-hll-2.14_old/include/executor/nodeIndexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeIndexscan.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * nodeIndexscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeIndexscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEINDEXSCAN_H +#define NODEINDEXSCAN_H + +#include "nodes/execnodes.h" + +extern IndexScanState* ExecInitIndexScan(IndexScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecIndexScan(IndexScanState* node); +extern void ExecEndIndexScan(IndexScanState* node); +extern void ExecIndexMarkPos(IndexScanState* node); +extern void ExecIndexRestrPos(IndexScanState* node); +extern void ExecReScanIndexScan(IndexScanState* node); + +/* + * These routines are exported to share code with nodeIndexonlyscan.c and + * nodeBitmapIndexscan.c + */ +extern void ExecIndexBuildScanKeys(PlanState* planstate, Relation index, List* quals, bool isorderby, ScanKey* scanKeys, + int* numScanKeys, IndexRuntimeKeyInfo** runtimeKeys, int* numRuntimeKeys, IndexArrayKeyInfo** arrayKeys, + int* numArrayKeys); +extern void ExecIndexEvalRuntimeKeys(ExprContext* econtext, IndexRuntimeKeyInfo* runtimeKeys, int numRuntimeKeys); +extern bool ExecIndexEvalArrayKeys(ExprContext* econtext, IndexArrayKeyInfo* arrayKeys, int numArrayKeys); +extern bool ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo* arrayKeys, int numArrayKeys); +extern void ExecInitPartitionForIndexScan(IndexScanState* indexstate, EState* estate); +extern void ExecInitPartitionForIndexOnlyScan(IndexOnlyScanState* indexstate, EState* estate); + +#endif /* NODEINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeLimit.h postgresql-hll-2.14/include/executor/nodeLimit.h --- postgresql-hll-2.14_old/include/executor/nodeLimit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeLimit.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeLimit.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeLimit.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODELIMIT_H +#define NODELIMIT_H + +#include "nodes/execnodes.h" + +extern LimitState* ExecInitLimit(Limit* node, EState* estate, int eflags); +extern TupleTableSlot* ExecLimit(LimitState* node); +extern void ExecEndLimit(LimitState* node); +extern void ExecReScanLimit(LimitState* node); +extern void recompute_limits(LimitState* node); + +#endif /* NODELIMIT_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeLockRows.h postgresql-hll-2.14/include/executor/nodeLockRows.h --- postgresql-hll-2.14_old/include/executor/nodeLockRows.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeLockRows.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeLockRows.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeLockRows.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODELOCKROWS_H +#define NODELOCKROWS_H + +#include "nodes/execnodes.h" + +extern LockRowsState* ExecInitLockRows(LockRows* node, EState* estate, int eflags); +extern TupleTableSlot* ExecLockRows(LockRowsState* node); +extern void ExecEndLockRows(LockRowsState* node); +extern void ExecReScanLockRows(LockRowsState* node); + +#endif /* NODELOCKROWS_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeMaterial.h postgresql-hll-2.14/include/executor/nodeMaterial.h --- postgresql-hll-2.14_old/include/executor/nodeMaterial.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeMaterial.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * nodeMaterial.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMaterial.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMATERIAL_H +#define NODEMATERIAL_H + +#include "nodes/execnodes.h" + +extern MaterialState* ExecInitMaterial(Material* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMaterial(MaterialState* node); +extern void ExecEndMaterial(MaterialState* node); +extern void ExecMaterialMarkPos(MaterialState* node); +extern void ExecMaterialRestrPos(MaterialState* node); +extern void ExecReScanMaterial(MaterialState* node); +extern void ExecEarlyFreeMaterial(MaterialState* node); +extern void ExecReSetMaterial(MaterialState* node); + +#endif /* NODEMATERIAL_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeMergeAppend.h postgresql-hll-2.14/include/executor/nodeMergeAppend.h --- postgresql-hll-2.14_old/include/executor/nodeMergeAppend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeMergeAppend.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeMergeAppend.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMergeAppend.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMERGEAPPEND_H +#define NODEMERGEAPPEND_H + +#include "nodes/execnodes.h" + +extern MergeAppendState* ExecInitMergeAppend(MergeAppend* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMergeAppend(MergeAppendState* node); +extern void ExecEndMergeAppend(MergeAppendState* node); +extern void ExecReScanMergeAppend(MergeAppendState* node); + +#endif /* NODEMERGEAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeMergejoin.h postgresql-hll-2.14/include/executor/nodeMergejoin.h --- postgresql-hll-2.14_old/include/executor/nodeMergejoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeMergejoin.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * nodeMergejoin.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMergejoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMERGEJOIN_H +#define NODEMERGEJOIN_H + +#include "nodes/execnodes.h" + +extern MergeJoinState* ExecInitMergeJoin(MergeJoin* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMergeJoin(MergeJoinState* node); +extern void ExecEndMergeJoin(MergeJoinState* node); +extern void ExecReScanMergeJoin(MergeJoinState* node); + +/* + * States of the ExecMergeJoin state machine + */ +#define EXEC_MJ_INITIALIZE_OUTER 1 +#define EXEC_MJ_INITIALIZE_INNER 2 +#define EXEC_MJ_JOINTUPLES 3 +#define EXEC_MJ_NEXTOUTER 4 +#define EXEC_MJ_TESTOUTER 5 +#define EXEC_MJ_NEXTINNER 6 +#define EXEC_MJ_SKIP_TEST 7 +#define EXEC_MJ_SKIPOUTER_ADVANCE 8 +#define EXEC_MJ_SKIPINNER_ADVANCE 9 +#define EXEC_MJ_ENDOUTER 10 +#define EXEC_MJ_ENDINNER 11 + +extern bool check_constant_qual(List* qual, bool* is_const_false); + +#endif /* NODEMERGEJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeModifyTable.h postgresql-hll-2.14/include/executor/nodeModifyTable.h --- postgresql-hll-2.14_old/include/executor/nodeModifyTable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeModifyTable.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * nodeModifyTable.h + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeModifyTable.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMODIFYTABLE_H +#define NODEMODIFYTABLE_H + +#include "nodes/execnodes.h" +#include "storage/lock.h" + +typedef TupleTableSlot* (*ExecInsertMtd)(ModifyTableState* state,TupleTableSlot*, + TupleTableSlot*, EState*, bool, int, List**); +typedef TupleTableSlot* (*ExecUpdateMtd)(ItemPointer, Oid, Oid, HeapTupleHeader, TupleTableSlot*, + TupleTableSlot*, EPQState*, ModifyTableState*, bool, bool); + +extern ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int eflags); +extern TupleTableSlot* ExecModifyTable(ModifyTableState* node); +extern void ExecEndModifyTable(ModifyTableState* node); +extern void ExecReScanModifyTable(ModifyTableState* node); +extern void RecordDeletedTuple(Oid relid, int2 bucketid, const ItemPointer tupleid, const Relation deldelta_rel); + +/* May move all resizing declaration to appropriate postion sometime. */ +extern bool RelationInClusterResizing(const Relation rel); +extern bool RelationInClusterResizingReadOnly(const Relation rel); +extern bool CheckRangeVarInRedistribution(const RangeVar* range_var); +extern bool RelationIsDeleteDeltaTable(char* delete_delta_name); +extern Relation GetAndOpenDeleteDeltaRel(const Relation rel, LOCKMODE lockmode, bool isMultiCatchup); +extern Relation GetAndOpenNewTableRel(const Relation rel, LOCKMODE lockmode); +extern bool redis_func_dnstable(Oid funcid); +extern List* eval_ctid_funcs(Relation rel, List* original_quals, RangeScanInRedis *rangeScanInRedis); +extern char* nodeTagToString(NodeTag type); +extern bool ClusterResizingInProgress(); +extern void RelationGetNewTableName(Relation rel, char* newtable_name); + +extern TupleTableSlot* ExecDelete(ItemPointer tupleid, Oid deletePartitionOid, int2 bucketid, HeapTupleHeader oldtuple, + TupleTableSlot* planSlot, EPQState* epqstate, ModifyTableState* node, bool canSetTag); + +extern TupleTableSlot* ExecUpdate(ItemPointer tupleid, Oid oldPartitionOid, int2 bucketid, HeapTupleHeader oldtuple, + TupleTableSlot* slot, TupleTableSlot* planSlot, EPQState* epqstate, ModifyTableState* node, bool canSetTag, + bool partKeyUpdate); + +template +extern TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, TupleTableSlot* planSlot, + EState* estate, bool canSetTag, int options, List** partitionList); +template +extern TupleTableSlot * +ExecHBucketInsertT(ModifyTableState* state, TupleTableSlot *slot, + TupleTableSlot *planSlot, + EState *estate, + bool canSetTag, + int options, + List** partition_list); + +extern void ExecCheckPlanOutput(Relation resultRel, List* targetList); + +#endif /* NODEMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeNestloop.h postgresql-hll-2.14/include/executor/nodeNestloop.h --- postgresql-hll-2.14_old/include/executor/nodeNestloop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeNestloop.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeNestloop.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeNestloop.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODENESTLOOP_H +#define NODENESTLOOP_H + +#include "nodes/execnodes.h" + +extern NestLoopState* ExecInitNestLoop(NestLoop* node, EState* estate, int eflags); +extern TupleTableSlot* ExecNestLoop(NestLoopState* node); +extern void ExecEndNestLoop(NestLoopState* node); +extern void ExecReScanNestLoop(NestLoopState* node); + +#endif /* NODENESTLOOP_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodePartIterator.h postgresql-hll-2.14/include/executor/nodePartIterator.h --- postgresql-hll-2.14_old/include/executor/nodePartIterator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodePartIterator.h 2020-12-12 17:06:43.113346309 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodePartIterator.h + * + * + * + * IDENTIFICATION + * src/include/executor/nodePartIterator.h + * + * NOTE + * Partition Iterator is a new execution operator for partition wise join. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODEPARTITERATOR_H +#define NODEPARTITERATOR_H + +#include "nodes/execnodes.h" + +extern PartIteratorState* ExecInitPartIterator(PartIterator* node, EState* estate, int eflags); +extern TupleTableSlot* ExecPartIterator(PartIteratorState* node); +extern void ExecEndPartIterator(PartIteratorState* node); +extern void ExecReScanPartIterator(PartIteratorState* node); + +#endif /* NODEPARTITERATOR_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeRecursiveunion.h postgresql-hll-2.14/include/executor/nodeRecursiveunion.h --- postgresql-hll-2.14_old/include/executor/nodeRecursiveunion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeRecursiveunion.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,259 @@ +/* ------------------------------------------------------------------------- + * + * nodeRecursiveunion.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeRecursiveunion.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODERECURSIVEUNION_H +#define NODERECURSIVEUNION_H + +#include "executor/execStream.h" +#include "nodes/execnodes.h" +#include "storage/fd.h" +#include "storage/vfd.h" +/* + * -------------------------------------------------------------------------------------- + * MPPDB Distributed RecursiveUnion Support (with-recursive) + * -------------------------------------------------------------------------------------- + */ + +extern THR_LOCAL char* producer_top_plannode_str; +extern THR_LOCAL bool is_syncup_producer; + +extern char* nodeTagToString(NodeTag type); + +/* Cluster-wide sync up each datanodes that none-recursive part has finished */ +#define WITH_RECURSIVE_SYNC_NONERQ 1 + +/* Cluster-wide sync up each datanodes that one iteration is done */ +#define WITH_RECURSIVE_SYNC_RQSTEP 2 + +/* Cluster-wide sync up each datanodes that all iteration steps are done */ +#define WITH_RECURSIVE_SYNC_DONE 3 + +/* + * Recursive Union message types + * - 'R' indicates datanode STEP finsih the iteration (W->C) + * - 'F' indicates cluster STEP finsih the iteration (C->W) + */ +#define RUSYNC_MSGTYPE_NODE_FINISH 'R' + +/* + * Base class for syncup controller + */ +typedef struct SyncController { + /* type of controller*/ + NodeTag controller_type; + + /* controller plan node id */ + int controller_plannodeid; + + /* control-node xc_node_id */ + int controlnode_xcnodeid; + + /* controler plan state desc */ + PlanState* controller_planstate; + + /* indicate the controller side is showdown */ + bool executor_stop; +} SyncController; + +/* + * SubClass inheriented from SyncController for Stream Operator + */ +typedef struct StreamController { + SyncController controller; + int iteration; + bool iteration_finished; + int total_tuples; + bool stream_finish; +} StreamController; + +typedef struct RecursiveVfd { + /* Reference to Consumer thread's VfdCache' address */ + Vfd** recursive_VfdCache; + + /* Reference to Consumer thread's SizeVfdCache */ + Size* recursive_SizeVfdCache; +} RecursiveVfd; + +/* + * SubClass inheriented from SyncController for RecursiveUnion Operator + */ +typedef struct RecursiveUnionController { + /* base controller information */ + SyncController controller; + + /* will move to base */ + int total_execution_datanodes; + List* streamlist; + StreamState* syncup_streamnode; + int stepno; + int ru_coordnodeid; + + /* RecursiveUnion specific control information */ + int recursiveunion_stepno; + + /* none-recursive desc */ + int* none_recursive_tuples; + bool none_recursive_finished; + int total_step1_rows; + + /* recursive desc */ + int* recursive_tuples; + bool recursive_finished; + int iteration; + int total_step2_substep_rows; + int total_step2_rows; + + /* overall desc */ + int total_step_rows; + bool recursive_union_finish; + + RecursiveVfd recursive_vfd; +} RecursiveUnionController; + +/* + * *********************************************************************************** + * Synchronization functions for each controller + * *********************************************************************************** + */ + +/* For RecursoveUnion's Producer/Consumer functions */ +extern void ExecSyncRecursiveUnionConsumer(RecursiveUnionController* controller, int stepno); +extern void ExecSyncRecursiveUnionProducer(RecursiveUnionController* controller, int producer_plannodeid, int step, + int tuple_count, bool* need_rescan, int target_iteration); + +/* + * For Stream's Producer/Consumer functions + */ +extern void ExecSyncStreamProducer(StreamController* controller, bool* need_rescan, int target_iteration); +extern void ExecSyncStreamConsumer(StreamController* controller); + +extern bool ExecutePlanSyncProducer( + PlanState* planstate, int step, bool* recursive_early_stop, long* current_tuple_count); + +/* + * SyncController-Creator for each supported operator + * SyncController-Destructor for each supported oeprator + */ +extern void ExecSyncControllerCreate(Plan* node); +extern void ExecSyncControllerDelete(SyncController* controller); + +/* + * Producer thread reset function for each operator + */ +extern void ExecSetStreamFinish(PlanState* state); + +/* + * working-horse marocs for sync-up relevant operations + */ +#define GET_PLAN_NODEID(x) ((Plan*)x)->plan_node_id +#define GET_RECURSIVE_UNION_PLAN_NODEID(x) ((Plan*)x)->recursive_union_plan_nodeid +#define GET_CONTROL_PLAN_NODEID(x) ((Plan*)x)->control_plan_nodeid + +/* + * Plan Step sync-up check functions + * [1]. NeedSyncUpRecursiveUnionStep() invoked in ExecRecursiveUnion to set up sync-up point + * [2]. NeedSetupSyncUpController() Invoked in init-node to set up controller + * [3]. NeedSyncUpProducerStep() invoked in producer side to do sync-up point + */ +extern bool NeedSyncUpRecursiveUnionStep(Plan* plan); +extern bool NeedSetupSyncUpController(Plan* plan); +extern bool NeedSyncUpProducerStep(Plan* top_plan); + +typedef struct TryStreamRecursivePlanContext { + bool stream_plan; +} TryStreamRecursivePlanContext; + +extern void mark_stream_recursiveunion_plan( + RecursiveUnion* runode, Plan* node, bool recursive_branch, List* subplans, List** initplans); + +/* + * Helper functions to identify the thread or consumer node is the sync-up thread + */ +extern bool IsSyncUpProducerThread(); +extern bool IsSyncUpConsumerStreamNode(const Stream* node); + +/* + * Iteration context structure to support distributed RecursiveUnion plan generation + */ +typedef struct RecursiveRefContext { + /* field to store recursive union plan node */ + const RecursiveUnion* ru_plan; + + /* + * store the current control plan node if current runing-plan need controlled when + * iterating the plan tree. + */ + Plan* control_plan; + + /* depth of current stream operation depths */ + int nested_stream_depth; + + /* indicate if we need set control_plan_id for current iterating plan node */ + bool set_control_plan_nodeid; + + /* flag to indicate whether the sync up producer is specified (for multi-stream case) */ + bool is_syncup_producer_specified; + + /* join type of most close upper layer join type */ + NodeTag join_type; + + List* initplans; /* Plans for initplan nodes */ + List* subplans; /* Plans for SubPlan nodes */ +} RecursiveRefContext; + +/* Function to generate control plannode for recursvie-union's underlying plantree */ +extern void set_recursive_cteplan_ref(Plan* node, RecursiveRefContext* context); + +extern RecursiveUnionState* ExecInitRecursiveUnion(RecursiveUnion* node, EState* estate, int eflags); +extern TupleTableSlot* ExecRecursiveUnion(RecursiveUnionState* node); +extern void ExecEndRecursiveUnion(RecursiveUnionState* node); +extern void ExecReScanRecursiveUnion(RecursiveUnionState* node); +extern bool IsFirstLevelStreamStateNode(StreamState* node); +extern void ExecReScanRecursivePlanTree(PlanState* ps); + +/* + * @Function: recursive_union_sleep() **INLINE** + * + * @Brief: wrapper sleep() function for recursive union use, compare with regular + * pg_usleep(), we check interrupt as well + * + * @Input usec: time-unit(micro) that going to sleep + * + * @Return: void + */ +static inline void recursive_union_sleep(long usec) +{ + /* setup interrupt check */ + CHECK_FOR_INTERRUPTS(); + + /* wait for given length */ + pg_usleep(usec); + + return; +} + +/* default check interval for iteration finish */ +#define CHECK_INTERVAL 500L + +/* check interval macro */ +#define WITH_RECURSIVE_SYNCPOINT_WAIT_INTERVAL \ + { \ + recursive_union_sleep(CHECK_INTERVAL); \ + \ + /* Check if current thread is required to exit from top consumer*/ \ + if (u_sess->exec_cxt.executor_stop_flag) { \ + break; \ + } \ + } + +#endif /* NODERECURSIVEUNION_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeResult.h postgresql-hll-2.14/include/executor/nodeResult.h --- postgresql-hll-2.14_old/include/executor/nodeResult.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeResult.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeResult.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeResult.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODERESULT_H +#define NODERESULT_H + +#include "nodes/execnodes.h" + +extern ResultState* ExecInitResult(BaseResult* node, EState* estate, int eflags); +extern TupleTableSlot* ExecResult(ResultState* node); +extern void ExecEndResult(ResultState* node); +extern void ExecResultMarkPos(ResultState* node); +extern void ExecResultRestrPos(ResultState* node); +extern void ExecReScanResult(ResultState* node); + +#endif /* NODERESULT_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeSamplescan.h postgresql-hll-2.14/include/executor/nodeSamplescan.h --- postgresql-hll-2.14_old/include/executor/nodeSamplescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSamplescan.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,112 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeSamplescan.h + * Table Sample Scan header file, include class and class member declaration. + * + * + * IDENTIFICATION + * src/include/executor/nodeSamplescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODESAMPLESCAN_H +#define NODESAMPLESCAN_H + +#include "access/relscan.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +#define NEWBLOCK 0 /* Identify we have got a new block. */ +#define NONEWBLOCK 1 /* Identify we are under scanning tuple in old block. */ + +#define MIN_PERCENT_ARG 0 /* Minimum value of percent. */ +#define MAX_PERCENT_ARG 100 /* Maxmum value of percent. */ + +/* The flag identify the tuple or block is valid or not for sample scan. */ +typedef enum { VALIDDATA, NEXTDATA, INVALIDBLOCKNO, INVALIDOFFSET } ScanValid; + +/* The flag identify the sample scan state. */ +typedef enum { GETMAXBLOCK, GETBLOCKNO, GETMAXOFFSET, GETOFFSET, GETDATA } SampleScanFlag; + +/* Table sample scan base class.*/ +class BaseTableSample : public BaseObject { +public: + BaseTableSample(void* scanstate); + virtual ~BaseTableSample(); + void resetSampleScan(); + +public: + ScanState* sampleScanState; + CStoreScanState* vecsampleScanState; + int runState; + int scanTupState; + uint32 seed; + double* percent; + BlockNumber totalBlockNum; + /* current block to consider sampling. To system table, next blosk need be chosen.*/ + BlockNumber currentBlock; + /* last tuple returned from current block.*/ + OffsetNumber currentOffset; + /* how many tuples in current page. */ + OffsetNumber curBlockMaxoffset; + bool finished; + void (BaseTableSample::*nextSampleBlock_function)(); + void (BaseTableSample::*nextSampleTuple_function)(); + +private: + void getSeed(); + void getPercent(); + void system_nextsampleblock(); + void system_nextsampletuple(); + void bernoulli_nextsampleblock(); + void bernoulli_nextsampletuple(); +}; + +/* Row table sample scan.*/ +class RowTableSample : public BaseTableSample { +public: + RowTableSample(ScanState* scanstate); + virtual ~RowTableSample(); + ScanValid scanTup(); + HeapTuple scanSample(); + void getMaxOffset(); +}; + +/* Column table sample scan.*/ +class ColumnTableSample : public BaseTableSample { +private: + uint16* offsetIds; + uint32 currentCuId; + int batchRowCount; + VectorBatch* tids; + +public: + ColumnTableSample(CStoreScanState* scanstate); + virtual ~ColumnTableSample(); + void resetVecSampleScan(); + void getBatchBySamples(VectorBatch* vbout); + ScanValid scanBatch(VectorBatch* batch); + void scanVecSample(VectorBatch* batch); + void getMaxOffset(); +}; + +extern TableScanDesc InitSampleScanDesc(ScanState *scanstate, Relation currentRelation); +extern TupleTableSlot* SeqSampleNext(SeqScanState *node); +extern TupleTableSlot* HbktSeqSampleNext(SeqScanState *node); + +#endif /* NODESAMPLESCAN_H */ + diff -uprN postgresql-hll-2.14_old/include/executor/nodeSeqscan.h postgresql-hll-2.14/include/executor/nodeSeqscan.h --- postgresql-hll-2.14_old/include/executor/nodeSeqscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSeqscan.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * nodeSeqscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSeqscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESEQSCAN_H +#define NODESEQSCAN_H + +#include "nodes/execnodes.h" + +extern SeqScanState* ExecInitSeqScan(SeqScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSeqScan(SeqScanState* node); +extern void ExecEndSeqScan(SeqScanState* node); +extern void ExecSeqMarkPos(SeqScanState* node); +extern void ExecSeqRestrPos(SeqScanState* node); +extern void ExecReScanSeqScan(SeqScanState* node); +extern void InitScanRelation(SeqScanState* node, EState* estate); + +#endif /* NODESEQSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeSetOp.h postgresql-hll-2.14/include/executor/nodeSetOp.h --- postgresql-hll-2.14_old/include/executor/nodeSetOp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSetOp.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * nodeSetOp.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSetOp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESETOP_H +#define NODESETOP_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vechashtable.h" +#include "executor/nodeAgg.h" + +// hash strategy +#define MEMORY_HASHSETOP 0 +#define DIST_HASHSETOP 1 + +#define HASHSETOP_PREPARE 0 +#define HASHSETOP_FETCH 1 + +typedef struct SetopWriteFileControl : public AggWriteFileControl { +} SetopWriteFileControl; + +extern SetOpState* ExecInitSetOp(SetOp* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSetOp(SetOpState* node); +extern void ExecEndSetOp(SetOpState* node); +extern void ExecReScanSetOp(SetOpState* node); +extern void ExecEarlyFreeHashedSetop(SetOpState* node); +extern void ExecReSetSetOp(SetOpState* node); + +#endif /* NODESETOP_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeSort.h postgresql-hll-2.14/include/executor/nodeSort.h --- postgresql-hll-2.14_old/include/executor/nodeSort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSort.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * nodeSort.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSort.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESORT_H +#define NODESORT_H + +#include "nodes/execnodes.h" + +extern SortState* ExecInitSort(Sort* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSort(SortState* node); +extern void ExecEndSort(SortState* node); +extern void ExecSortMarkPos(SortState* node); +extern void ExecSortRestrPos(SortState* node); +extern void ExecReScanSort(SortState* node); +extern long ExecGetMemCostSort(Sort* node); +extern void ExecEarlyFreeSort(SortState* node); +extern void ExecReSetSort(SortState* node); + +#endif /* NODESORT_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeStub.h postgresql-hll-2.14/include/executor/nodeStub.h --- postgresql-hll-2.14_old/include/executor/nodeStub.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeStub.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeStub.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/executor/nodeStub.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODESTUB_H +#define NODESTUB_H + +#include "nodes/execnodes.h" + +/* nodegroup */ +extern PlanState *ExecInitNodeStubNorm(Plan *node, EState *estate, int eflags); +extern TupleTableSlot *ExecProcNodeStub(PlanState *node); +extern void ExecEndNodeStub(PlanState *node); + +#endif /* NODESTUB_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeSubplan.h postgresql-hll-2.14/include/executor/nodeSubplan.h --- postgresql-hll-2.14_old/include/executor/nodeSubplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSubplan.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,32 @@ +/* ------------------------------------------------------------------------- + * + * nodeSubplan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSubplan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESUBPLAN_H +#define NODESUBPLAN_H + +#include "nodes/execnodes.h" + +extern SubPlanState* ExecInitSubPlan(SubPlan* subplan, PlanState* parent); + +extern AlternativeSubPlanState* ExecInitAlternativeSubPlan(AlternativeSubPlan* asplan, PlanState* parent); + +extern void ExecReScanSetParamPlan(SubPlanState* node, PlanState* parent); + +extern void ExecSetParamPlan(SubPlanState* node, ExprContext* econtext); +extern void buildSubPlanHash(SubPlanState* node, ExprContext* econtext); +extern bool slotAllNulls(TupleTableSlot* slot); +extern bool slotNoNulls(TupleTableSlot* slot); + +extern bool findPartialMatch(TupleHashTable hashtable, TupleTableSlot* slot, FmgrInfo* eqfunctions); + +#endif /* NODESUBPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeSubqueryscan.h postgresql-hll-2.14/include/executor/nodeSubqueryscan.h --- postgresql-hll-2.14_old/include/executor/nodeSubqueryscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeSubqueryscan.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeSubqueryscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSubqueryscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESUBQUERYSCAN_H +#define NODESUBQUERYSCAN_H + +#include "nodes/execnodes.h" + +extern SubqueryScanState* ExecInitSubqueryScan(SubqueryScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSubqueryScan(SubqueryScanState* node); +extern void ExecEndSubqueryScan(SubqueryScanState* node); +extern void ExecReScanSubqueryScan(SubqueryScanState* node); + +#endif /* NODESUBQUERYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeTidscan.h postgresql-hll-2.14/include/executor/nodeTidscan.h --- postgresql-hll-2.14_old/include/executor/nodeTidscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeTidscan.h 2020-12-12 17:06:43.114346322 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeTidscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeTidscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODETIDSCAN_H +#define NODETIDSCAN_H + +#include "nodes/execnodes.h" + +extern TidScanState* ExecInitTidScan(TidScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecTidScan(TidScanState* node); +extern void ExecEndTidScan(TidScanState* node); +extern void ExecTidMarkPos(TidScanState* node); +extern void ExecTidRestrPos(TidScanState* node); +extern void ExecReScanTidScan(TidScanState* node); + +#endif /* NODETIDSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeUnique.h postgresql-hll-2.14/include/executor/nodeUnique.h --- postgresql-hll-2.14_old/include/executor/nodeUnique.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeUnique.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeUnique.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeUnique.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEUNIQUE_H +#define NODEUNIQUE_H + +#include "nodes/execnodes.h" + +extern UniqueState* ExecInitUnique(Unique* node, EState* estate, int eflags); +extern TupleTableSlot* ExecUnique(UniqueState* node); +extern void ExecEndUnique(UniqueState* node); +extern void ExecReScanUnique(UniqueState* node); + +#endif /* NODEUNIQUE_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeValuesscan.h postgresql-hll-2.14/include/executor/nodeValuesscan.h --- postgresql-hll-2.14_old/include/executor/nodeValuesscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeValuesscan.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeValuesscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeValuesscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEVALUESSCAN_H +#define NODEVALUESSCAN_H + +#include "nodes/execnodes.h" + +extern ValuesScanState* ExecInitValuesScan(ValuesScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecValuesScan(ValuesScanState* node); +extern void ExecEndValuesScan(ValuesScanState* node); +extern void ExecValuesMarkPos(ValuesScanState* node); +extern void ExecValuesRestrPos(ValuesScanState* node); +extern void ExecReScanValuesScan(ValuesScanState* node); + +#endif /* NODEVALUESSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeWindowAgg.h postgresql-hll-2.14/include/executor/nodeWindowAgg.h --- postgresql-hll-2.14_old/include/executor/nodeWindowAgg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeWindowAgg.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeWindowAgg.h + * prototypes for nodeWindowAgg.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeWindowAgg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEWINDOWAGG_H +#define NODEWINDOWAGG_H + +#include "nodes/execnodes.h" + +extern WindowAggState* ExecInitWindowAgg(WindowAgg* node, EState* estate, int eflags); +extern TupleTableSlot* ExecWindowAgg(WindowAggState* node); +extern void ExecEndWindowAgg(WindowAggState* node); +extern void ExecReScanWindowAgg(WindowAggState* node); + +#endif /* NODEWINDOWAGG_H */ diff -uprN postgresql-hll-2.14_old/include/executor/nodeWorktablescan.h postgresql-hll-2.14/include/executor/nodeWorktablescan.h --- postgresql-hll-2.14_old/include/executor/nodeWorktablescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/nodeWorktablescan.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeWorktablescan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeWorktablescan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEWORKTABLESCAN_H +#define NODEWORKTABLESCAN_H + +#include "nodes/execnodes.h" + +extern WorkTableScanState* ExecInitWorkTableScan(WorkTableScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecWorkTableScan(WorkTableScanState* node); +extern void ExecEndWorkTableScan(WorkTableScanState* node); +extern void ExecReScanWorkTableScan(WorkTableScanState* node); + +#endif /* NODEWORKTABLESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/executor/spi.h postgresql-hll-2.14/include/executor/spi.h --- postgresql-hll-2.14_old/include/executor/spi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/spi.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------------- + * + * spi.h + * Server Programming Interface public declarations + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/spi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPI_H +#define SPI_H + +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "utils/resowner.h" +#include "utils/portal.h" + +typedef struct SPITupleTable { + MemoryContext tuptabcxt; /* memory context of result table */ + uint32 alloced; /* # of alloced vals */ + uint32 free; /* # of free vals */ + TupleDesc tupdesc; /* tuple descriptor */ + HeapTuple* vals; /* tuples */ +} SPITupleTable; + +/* Plans are opaque structs for standard users of SPI */ +typedef struct _SPI_plan* SPIPlanPtr; + +#define SPI_ERROR_CONNECT (-1) +#define SPI_ERROR_COPY (-2) +#define SPI_ERROR_OPUNKNOWN (-3) +#define SPI_ERROR_UNCONNECTED (-4) +#define SPI_ERROR_CURSOR (-5) /* not used anymore */ +#define SPI_ERROR_ARGUMENT (-6) +#define SPI_ERROR_PARAM (-7) +#define SPI_ERROR_TRANSACTION (-8) +#define SPI_ERROR_NOATTRIBUTE (-9) +#define SPI_ERROR_NOOUTFUNC (-10) +#define SPI_ERROR_TYPUNKNOWN (-11) + +#define SPI_OK_CONNECT 1 +#define SPI_OK_FINISH 2 +#define SPI_OK_FETCH 3 +#define SPI_OK_UTILITY 4 +#define SPI_OK_SELECT 5 +#define SPI_OK_SELINTO 6 +#define SPI_OK_INSERT 7 +#define SPI_OK_DELETE 8 +#define SPI_OK_UPDATE 9 +#define SPI_OK_CURSOR 10 +#define SPI_OK_INSERT_RETURNING 11 +#define SPI_OK_DELETE_RETURNING 12 +#define SPI_OK_UPDATE_RETURNING 13 +#define SPI_OK_REWRITTEN 14 +#define SPI_OK_MERGE 15 +#define SPI_OPT_NONATOMIC (1 << 0) + +extern THR_LOCAL PGDLLIMPORT uint32 SPI_processed; +extern THR_LOCAL PGDLLIMPORT SPITupleTable* SPI_tuptable; +extern THR_LOCAL PGDLLIMPORT int SPI_result; + +extern int SPI_connect(CommandDest dest = DestSPI, void (*spiCallbackfn)(void*) = NULL, void* clientData = NULL); +extern int SPI_connect_ext(CommandDest dest = DestSPI, void (*spiCallbackfn)(void *) = NULL, void *clientData = NULL, + int options = 0, Oid func_oid = InvalidOid); +extern int SPI_finish(void); +extern void SPI_push(void); +extern void SPI_pop(void); +extern bool SPI_push_conditional(void); +extern void SPI_pop_conditional(bool pushed); +extern void SPI_restore_connection(void); +extern int SPI_execute(const char* src, bool read_only, long tcount); +extern int SPI_execute_plan(SPIPlanPtr plan, Datum* Values, const char* Nulls, bool read_only, long tcount); +extern int SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params, bool read_only, long tcount); +extern int SPI_exec(const char* src, long tcount); +extern int SPI_execp(SPIPlanPtr plan, Datum* Values, const char* Nulls, long tcount); +extern int SPI_execute_snapshot(SPIPlanPtr plan, Datum* Values, const char* Nulls, Snapshot snapshot, + Snapshot crosscheck_snapshot, bool read_only, bool fire_triggers, long tcount); +extern int SPI_execute_with_args(const char* src, int nargs, Oid* argtypes, Datum* Values, const char* Nulls, + bool read_only, long tcount, Cursor_Data* cursor_data); +extern SPIPlanPtr SPI_prepare(const char* src, int nargs, Oid* argtypes); +extern SPIPlanPtr SPI_prepare_cursor(const char* src, int nargs, Oid* argtypes, int cursorOptions); +extern SPIPlanPtr SPI_prepare_params( + const char* src, ParserSetupHook parserSetup, void* parserSetupArg, int cursorOptions); +extern int SPI_keepplan(SPIPlanPtr plan); +extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan); +extern int SPI_freeplan(SPIPlanPtr plan); + +extern Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex); +extern int SPI_getargcount(SPIPlanPtr plan); +extern bool SPI_is_cursor_plan(SPIPlanPtr plan, ParamListInfo paramLI); +extern bool SPI_plan_is_valid(SPIPlanPtr plan); +extern const char* SPI_result_code_string(int code); + +extern List* SPI_plan_get_plan_sources(SPIPlanPtr plan); +extern CachedPlan* SPI_plan_get_cached_plan(SPIPlanPtr plan); + +extern HeapTuple SPI_copytuple(HeapTuple tuple); +extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc); +extern HeapTuple SPI_modifytuple( + Relation rel, HeapTuple tuple, int natts, int* attnum, Datum* Values, const char* Nulls); +extern int SPI_fnumber(TupleDesc tupdesc, const char* fname); +extern char* SPI_fname(TupleDesc tupdesc, int fnumber); +extern char* SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber); +extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool* isnull); +extern char* SPI_gettype(TupleDesc tupdesc, int fnumber); +extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber); +extern char* SPI_getrelname(Relation rel); +extern char* SPI_getnspname(Relation rel); +extern void* SPI_palloc(Size size); +extern void* SPI_repalloc(void* pointer, Size size); +extern void SPI_pfree(void* pointer); +extern void SPI_freetuple(HeapTuple pointer); +extern void SPI_freetuptable(SPITupleTable* tuptable); + +extern Portal SPI_cursor_open(const char* name, SPIPlanPtr plan, Datum* Values, const char* Nulls, bool read_only); +extern Portal SPI_cursor_open_with_args(const char* name, const char* src, int nargs, Oid* argtypes, Datum* Values, + const char* Nulls, bool read_only, int cursorOptions); +extern Portal SPI_cursor_open_with_paramlist(const char* name, SPIPlanPtr plan, ParamListInfo params, bool read_only); +extern Portal SPI_cursor_find(const char* name); +extern void SPI_cursor_fetch(Portal portal, bool forward, long count); +extern void SPI_cursor_move(Portal portal, bool forward, long count); +extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count); +extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count); +extern void SPI_cursor_close(Portal portal); +extern void SPI_start_transaction(void); +extern void SPI_stp_transaction_check(bool read_only); +extern void SPI_commit(); +extern void SPI_rollback(); +extern void SPI_save_current_stp_transaction_state(); +extern void SPI_restore_current_stp_transaction_state(); +extern TransactionId SPI_get_top_transaction_id(); + +extern void SPICleanup(void); +extern void AtEOXact_SPI(bool isCommit, bool STP_rollback, bool STP_commit); +extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid, bool STP_rollback, bool STP_commit); +extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid); +extern DestReceiver* createAnalyzeSPIDestReceiver(CommandDest dest); +/* SPI execution helpers */ +extern void spi_exec_with_callback(CommandDest dest, const char* src, bool read_only, long tcount, bool direct_call, + void (*callbackFn)(void*), void* clientData); + +extern void _SPI_error_callback(void *arg); + +#ifdef PGXC +extern int SPI_execute_direct(const char* src, char* nodename); +#endif +extern int _SPI_end_call(bool procmem); +extern void _SPI_hold_cursor(); +#endif /* SPI_H */ diff -uprN postgresql-hll-2.14_old/include/executor/spi_priv.h postgresql-hll-2.14/include/executor/spi_priv.h --- postgresql-hll-2.14_old/include/executor/spi_priv.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/spi_priv.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * spi_priv.h + * Server Programming Interface private declarations + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/spi_priv.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPI_PRIV_H +#define SPI_PRIV_H + +#include "executor/spi.h" + +#define _SPI_PLAN_MAGIC 569278163 +#define INVALID_SPI_KEY (uint32)(-1) +typedef struct _SPI_connection { + /* current results */ + uint64 processed; /* by Executor */ + Oid lastoid; + SPITupleTable* tuptable; + + MemoryContext procCxt; /* procedure context */ + MemoryContext execCxt; /* executor context */ + MemoryContext savedcxt; /* context of SPI_connect's caller */ + SubTransactionId connectSubid; /* ID of connecting subtransaction */ + CommandDest dest; /* identify which is the orientated caller of spi interface, analyze or normal */ + + /* transaction management support */ + bool atomic; /* atomic execution context, does not allow transactions */ + bool internal_xact; /* SPI-managed transaction boundary, skip cleanup */ + + void* clientData; /* argument to call back function */ + void (*spiCallback)(void*); /* callback for process received data. */ + Oid func_oid; /* corresponding oid */ + uint32 spi_hash_key; /* corresponding oid */ + uint32 visit_id; /* visit count */ + int plan_id; +} _SPI_connection; + +/* + * SPI plans have three states: saved, unsaved, or temporary. + * + * Ordinarily, the _SPI_plan struct itself as well as the argtypes array + * are in a dedicated memory context identified by plancxt (which can be + * really small). All the other subsidiary state is in plancache entries + * identified by plancache_list (note: the list cells themselves are in + * plancxt). + * + * In an unsaved plan, the plancxt as well as the plancache entries' contexts + * are children of the SPI procedure context, so they'll all disappear at + * function exit. plancache.c also knows that the plancache entries are + * "unsaved", so it doesn't link them into its global list; hence they do + * not respond to inval events. This is OK since we are presumably holding + * adequate locks to prevent other backends from messing with the tables. + * + * For a saved plan, the plancxt is made a child of t_thrd.mem_cxt.cache_mem_cxt + * since it should persist until explicitly destroyed. Likewise, the + * plancache entries will be under t_thrd.mem_cxt.cache_mem_cxt since we tell + * plancache.c to save them. We rely on plancache.c to keep the cache + * entries up-to-date as needed in the face of invalidation events. + * + * There are also "temporary" SPI plans, in which the _SPI_plan struct is + * not even palloc'd but just exists in some function's local variable. + * The plancache entries are unsaved and exist under the SPI executor context, + * while additional data such as argtypes and list cells is loose in the SPI + * executor context. Such plans can be identified by having plancxt == NULL. + * + * We can also have "one-shot" SPI plans (which are typically temporary, + * as described above). These are meant to be executed once and discarded, + * and various optimizations are made on the assumption of single use. + * Note in particular that the CachedPlanSources within such an SPI plan + * are not "complete" until execution. + * + * Note: if the original query string contained only whitespace and comments, + * the plancache_list will be NIL and so there is no place to store the + * query string. We don't care about that, but we do care about the + * argument type array, which is why it's seemingly-redundantly stored. + */ +typedef struct _SPI_plan { + int magic; /* should equal _SPI_PLAN_MAGIC */ + bool saved; /* saved or unsaved plan? */ + bool oneshot; /* one-shot plan? */ + List* plancache_list; /* one CachedPlanSource per parsetree */ + MemoryContext plancxt; /* Context containing _SPI_plan and data */ + int cursor_options; /* Cursor options used for planning */ + int nargs; /* number of plan arguments */ + Oid* argtypes; /* Argument types (NULL if nargs is 0) */ + ParserSetupHook parserSetup; /* alternative parameter spec method */ + void* parserSetupArg; + uint32 id; /* SPIplan id in a function */ + uint32 spi_key; /* key in SPICacheTable */ +} _SPI_plan; + +#endif /* SPI_PRIV_H */ diff -uprN postgresql-hll-2.14_old/include/executor/tstoreReceiver.h postgresql-hll-2.14/include/executor/tstoreReceiver.h --- postgresql-hll-2.14_old/include/executor/tstoreReceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/tstoreReceiver.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * tstoreReceiver.h + * prototypes for tstoreReceiver.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/tstoreReceiver.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSTORE_RECEIVER_H +#define TSTORE_RECEIVER_H + +#include "tcop/dest.h" +#include "utils/tuplestore.h" + +extern DestReceiver* CreateTuplestoreDestReceiver(void); + +extern void SetTuplestoreDestReceiverParams( + DestReceiver* self, Tuplestorestate* tStore, MemoryContext tContext, bool detoast); + +#endif /* TSTORE_RECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/executor/tuptable.h postgresql-hll-2.14/include/executor/tuptable.h --- postgresql-hll-2.14_old/include/executor/tuptable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/executor/tuptable.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,195 @@ +/* ------------------------------------------------------------------------- + * + * tuptable.h + * tuple table support stuff + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/tuptable.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPTABLE_H +#define TUPTABLE_H + +#include "access/htup.h" +#include "storage/buf.h" + +#ifndef FRONTEND_PARSER +/* ---------- + * The executor stores tuples in a "tuple table" which is a List of + * independent TupleTableSlots. There are several cases we need to handle: + * 1. physical tuple in a disk buffer page + * 2. physical tuple constructed in palloc'ed memory + * 3. "minimal" physical tuple constructed in palloc'ed memory + * 4. "virtual" tuple consisting of Datum/isnull arrays + * + * The first two cases are similar in that they both deal with "materialized" + * tuples, but resource management is different. For a tuple in a disk page + * we need to hold a pin on the buffer until the TupleTableSlot's reference + * to the tuple is dropped; while for a palloc'd tuple we usually want the + * tuple pfree'd when the TupleTableSlot's reference is dropped. + * + * A "minimal" tuple is handled similarly to a palloc'd regular tuple. + * At present, minimal tuples never are stored in buffers, so there is no + * parallel to case 1. Note that a minimal tuple has no "system columns". + * (Actually, it could have an OID, but we have no need to access the OID.) + * + * A "virtual" tuple is an optimization used to minimize physical data + * copying in a nest of plan nodes. Any pass-by-reference Datums in the + * tuple point to storage that is not directly associated with the + * TupleTableSlot; generally they will point to part of a tuple stored in + * a lower plan node's output TupleTableSlot, or to a function result + * constructed in a plan node's per-tuple econtext. It is the responsibility + * of the generating plan node to be sure these resources are not released + * for as long as the virtual tuple needs to be valid. We only use virtual + * tuples in the result slots of plan nodes --- tuples to be copied anywhere + * else need to be "materialized" into physical tuples. Note also that a + * virtual tuple does not have any "system columns". + * + * It is also possible for a TupleTableSlot to hold both physical and minimal + * copies of a tuple. This is done when the slot is requested to provide + * the format other than the one it currently holds. (Originally we attempted + * to handle such requests by replacing one format with the other, but that + * had the fatal defect of invalidating any pass-by-reference Datums pointing + * into the existing slot contents.) Both copies must contain identical data + * payloads when this is the case. + * + * The Datum/isnull arrays of a TupleTableSlot serve double duty. When the + * slot contains a virtual tuple, they are the authoritative data. When the + * slot contains a physical tuple, the arrays contain data extracted from + * the tuple. (In this state, any pass-by-reference Datums point into + * the physical tuple.) The extracted information is built "lazily", + * ie, only as needed. This serves to avoid repeated extraction of data + * from the physical tuple. + * + * A TupleTableSlot can also be "empty", holding no valid data. This is + * the only valid state for a freshly-created slot that has not yet had a + * tuple descriptor assigned to it. In this state, tts_isempty must be + * TRUE, tts_shouldFree FALSE, tts_tuple NULL, tts_buffer InvalidBuffer, + * and tts_nvalid zero. + * + * The tupleDescriptor is simply referenced, not copied, by the TupleTableSlot + * code. The caller of ExecSetSlotDescriptor() is responsible for providing + * a descriptor that will live as long as the slot does. (Typically, both + * slots and descriptors are in per-query memory and are freed by memory + * context deallocation at query end; so it's not worth providing any extra + * mechanism to do more. However, the slot will increment the tupdesc + * reference count if a reference-counted tupdesc is supplied.) + * + * When tts_shouldFree is true, the physical tuple is "owned" by the slot + * and should be freed when the slot's reference to the tuple is dropped. + * + * If tts_buffer is not InvalidBuffer, then the slot is holding a pin + * on the indicated buffer page; drop the pin when we release the + * slot's reference to that buffer. (tts_shouldFree should always be + * false in such a case, since presumably tts_tuple is pointing at the + * buffer page.) + * + * tts_nvalid indicates the number of valid columns in the tts_values/isnull + * arrays. When the slot is holding a "virtual" tuple this must be equal + * to the descriptor's natts. When the slot is holding a physical tuple + * this is equal to the number of columns we have extracted (we always + * extract columns from left to right, so there are no holes). + * + * tts_values/tts_isnull are allocated when a descriptor is assigned to the + * slot; they are of length equal to the descriptor's natts. + * + * tts_mintuple must always be NULL if the slot does not hold a "minimal" + * tuple. When it does, tts_mintuple points to the actual MinimalTupleData + * object (the thing to be pfree'd if tts_shouldFreeMin is true). If the slot + * has only a minimal and not also a regular physical tuple, then tts_tuple + * points at tts_minhdr and the fields of that struct are set correctly + * for access to the minimal tuple; in particular, tts_minhdr.t_data points + * MINIMAL_TUPLE_OFFSET bytes before tts_mintuple. This allows column + * extraction to treat the case identically to regular physical tuples. + * + * tts_slow/tts_off are saved state for slot_deform_tuple, and should not + * be touched by any other code. + * ---------- + */ +typedef struct TupleTableSlot { + NodeTag type; + bool tts_isempty; /* true = slot is empty */ + bool tts_shouldFree; /* should pfree tts_tuple? */ + bool tts_shouldFreeMin; /* should pfree tts_mintuple? */ + bool tts_slow; /* saved state for slot_deform_tuple */ + + //XXXTAM: remove tts_utuple later. + + Tuple tts_tuple; /* physical tuple, or NULL if virtual */ + +#ifdef PGXC + /* + * PGXC extension to support tuples sent from remote Datanode. + */ + char* tts_dataRow; /* Tuple data in DataRow format */ + int tts_dataLen; /* Actual length of the data row */ + bool tts_shouldFreeRow; /* should pfree tts_dataRow? */ + struct AttInMetadata* tts_attinmeta; /* store here info to extract values from the DataRow */ + Oid tts_xcnodeoid; /* Oid of node from where the datarow is fetched */ + MemoryContext tts_per_tuple_mcxt; +#endif + TupleDesc tts_tupleDescriptor; /* slot's tuple descriptor */ + MemoryContext tts_mcxt; /* slot itself is in this context */ + Buffer tts_buffer; /* tuple's buffer, or InvalidBuffer */ + int tts_nvalid; /* # of valid values in tts_values */ + Datum* tts_values; /* current per-attribute values */ + bool* tts_isnull; /* current per-attribute isnull flags */ + MinimalTuple tts_mintuple; /* minimal tuple, or NULL if none */ + HeapTupleData tts_minhdr; /* workspace for minimal-tuple-only case */ + long tts_off; /* saved state for slot_deform_tuple */ + long tts_meta_off; /* saved state for slot_deform_cmpr_tuple */ + TableAmType tts_tupslotTableAm; /* slots's tuple table type */ +} TupleTableSlot; + +#define TTS_HAS_PHYSICAL_TUPLE(slot) ((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr)) + +/* + * TupIsNull -- is a TupleTableSlot empty? + */ +#define TupIsNull(slot) ((slot) == NULL || (slot)->tts_isempty) + +/* in executor/execTuples.c */ +extern TupleTableSlot* MakeTupleTableSlot(bool has_tuple_mcxt = true, TableAmType tupslotTableAm = TAM_HEAP); +extern TupleTableSlot* ExecAllocTableSlot(List** tupleTable, TableAmType tupslotTableAm = TAM_HEAP); +extern void ExecResetTupleTable(List* tupleTable, bool shouldFree); +extern TupleTableSlot* MakeSingleTupleTableSlot(TupleDesc tupdesc, bool allocSlotCxt = false, TableAmType tupslotTableAm = TAM_HEAP); +extern void ExecDropSingleTupleTableSlot(TupleTableSlot* slot); +extern void ExecSetSlotDescriptor(TupleTableSlot* slot, TupleDesc tupdesc); +extern TupleTableSlot* ExecStoreTuple(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool shouldFree); +extern TupleTableSlot* ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot* slot, bool shouldFree); +#ifdef PGXC +extern TupleTableSlot* ExecStoreDataRowTuple( + char* msg, size_t len, Oid msgnode_oid, TupleTableSlot* slot, bool shouldFree); +#endif +extern TupleTableSlot* ExecClearTuple(TupleTableSlot* slot); +extern TupleTableSlot* ExecStoreVirtualTuple(TupleTableSlot* slot); +extern TupleTableSlot* ExecStoreAllNullTuple(TupleTableSlot* slot); +extern HeapTuple ExecCopySlotTuple(TupleTableSlot* slot); +extern MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot* slot, bool need_transform_anyarray = false); +extern HeapTuple ExecFetchSlotTuple(TupleTableSlot* slot); +extern MinimalTuple ExecFetchSlotMinimalTuple(TupleTableSlot* slot); +extern Datum ExecFetchSlotTupleDatum(TupleTableSlot* slot); +extern HeapTuple ExecMaterializeSlot(TupleTableSlot* slot); +extern TupleTableSlot* ExecCopySlot(TupleTableSlot* dstslot, TupleTableSlot* srcslot); + +/* heap table specific slot/tuple operations*/ +/* definitions are found in access/common/heaptuple.c */ +extern void heap_slot_clear(TupleTableSlot* slot); +extern void heap_slot_materialize(TupleTableSlot* slot); +extern MinimalTuple heap_slot_get_minimal_tuple(TupleTableSlot *slot); +extern MinimalTuple heap_slot_copy_minimal_tuple(TupleTableSlot *slot); +extern void heap_slot_store_minimal_tuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree); +extern HeapTuple heap_slot_get_heap_tuple (TupleTableSlot* slot); +extern HeapTuple heap_slot_copy_heap_tuple (TupleTableSlot *slot); +extern void heap_slot_store_heap_tuple(HeapTuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free); +extern Datum heap_slot_getattr(TupleTableSlot* slot, int attnum, bool* isnull, bool need_transform_anyarray = false); +extern void heap_slot_getallattrs(TupleTableSlot* slot, bool need_transform_anyarray = false); +extern void heap_slot_getsomeattrs(TupleTableSlot* slot, int attnum); +extern bool heap_slot_attisnull(TupleTableSlot* slot, int attnum); + +#endif /* !FRONTEND_PARSER */ +#endif /* TUPTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/flock.h postgresql-hll-2.14/include/flock.h --- postgresql-hll-2.14_old/include/flock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/flock.h 2020-12-12 17:06:43.115346335 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * flock.h + * + * + * + * IDENTIFICATION + * src/include/flock.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FLOCK_H +#define FLOCK_H + +/* + * flock ports + */ +#ifndef LOCK_EX + +#undef LOCK_SH +#undef LOCK_EX +#undef LOCK_UN +#undef LOCK_NB + +#define LOCK_SH 1 /* Shared lock. */ +#define LOCK_EX 2 /* Exclusive lock. */ +#define LOCK_UN 8 /* Unlock. */ +#define LOCK_NB 4 /* Don't block when locking. */ +#endif + +#define START_LOCATION 1 +#define CURRENT_LOCATION 2 +#define END_LOCATION 4 + +extern int pgut_flock(int fd, int operation, int64 offset, int location, int64 len); +#define flock pgut_flock + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/fmgr.h postgresql-hll-2.14/include/fmgr.h --- postgresql-hll-2.14_old/include/fmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/fmgr.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,968 @@ +/* ------------------------------------------------------------------------- + * + * fmgr.h + * Definitions for the Postgres function manager and function-call + * interface. + * + * This file must be included by all Postgres modules that either define + * or call fmgr-callable functions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/fmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FMGR_H +#define FMGR_H + +#if defined(FRONTEND_PARSER) +#include "postgres_fe.h" +#else +#include "postgres.h" +#endif // FRONTEND_PARSER +#include "lib/stringinfo.h" + +/* We don't want to include primnodes.h here, so make a stub reference */ +typedef struct Node* fmNodePtr; +class ScalarVector; + +/* Likewise, avoid including stringinfo.h here */ +typedef struct StringInfoData* fmStringInfo; + +struct FunctionCallInfoData; + +struct Cursor_Data; + +typedef Datum (*UDFArgsFuncType)(FunctionCallInfoData* fcinfo, int idx, Datum val); + +/* + * All functions that can be called directly by fmgr must have this signature. + * (Other functions can be called by using a handler that does have this + * signature.) + */ + +typedef struct FunctionCallInfoData* FunctionCallInfo; + +#ifndef FRONTEND_PARSER + +typedef Datum (*PGFunction)(FunctionCallInfo fcinfo); + +typedef ScalarVector* (*VectorFunction)(FunctionCallInfo fcinfo); +typedef Datum (*GenericArgExtract)(Datum* data); + +extern void InitFuncCallUDFInfo(FunctionCallInfoData* fcinfo, int argN, bool setFuncPtr); +extern void InitFunctionCallUDFArgs(FunctionCallInfoData* fcinfo, int argN, int batchRows); +extern void FreeFuncCallUDFInfo(FunctionCallInfoData* Fcinfo); + +#define VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS 32 +#define VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS 10 + +struct GenericFunRuntimeArg { + ScalarVector** arg; + Oid argType; + GenericArgExtract getArgFun; +}; + +struct GenericFunRuntime { + /* maxium number of the arguements can be stored */ + uint16 compacity; + + /* pointer to the address of the real arg */ + GenericFunRuntimeArg* args; + Datum* inputargs; + bool* nulls; + + bool restrictFlag[BatchMaxSize]; + FunctionCallInfoData* internalFinfo; +}; +/* + * This struct holds the system-catalog information that must be looked up + * before a function can be called through fmgr. If the same function is + * to be called multiple times, the lookup need be done only once and the + * info struct saved for re-use. + * + * Note that fn_expr really is parse-time-determined information about the + * arguments, rather than about the function itself. But it's convenient + * to store it here rather than in FunctionCallInfoData, where it might more + * logically belong. + */ +typedef struct FmgrInfo { + PGFunction fn_addr; /* pointer to function or handler to be called */ + Oid fn_oid; /* OID of function (NOT of handler, if any) */ + short fn_nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable arg + * count */ + bool fn_strict; /* function is "strict" (NULL in => NULL out) */ + bool fn_retset; /* function returns a set */ + unsigned char fn_stats; /* collect stats if track_functions > this */ + void* fn_extra; /* extra space for use by handler */ + MemoryContext fn_mcxt; /* memory context to store fn_extra in */ + fmNodePtr fn_expr; /* expression parse tree for call, or NULL */ + Oid fn_rettype; // Oid of function return type + char fnName[NAMEDATALEN]; /* function name */ + char* fnLibPath; /* library path for c-udf + * package.class.method(args) for java-udf */ + bool fn_fenced; + Oid fn_languageId; /* function language id*/ + char fn_volatile; /* procvolatile */ + // Vector Function + VectorFunction vec_fn_addr; + VectorFunction* vec_fn_cache; + GenericFunRuntime* genericRuntime; +} FmgrInfo; + +/* + * number of prealloced arguments to a function. + * In deepsql (SVM and elastic_net), we cannot explicitly set all elements to false. + */ +#define FUNC_PREALLOCED_ARGS 20 + +typedef struct UDFInfoType { + UDFArgsFuncType* UDFArgsHandlerPtr; /* UDF send/recv argument function */ + UDFArgsFuncType UDFResultHandlerPtr; + StringInfo udfMsgBuf; + char* msgReadPtr; + int argBatchRows; + int allocRows; + Datum** arg; + bool** null; + Datum* result; + bool* resultIsNull; + bool valid_UDFArgsHandlerPtr; /* True if funcUDFArgs are filled ok */ + + UDFInfoType() + { + udfMsgBuf = NULL; + msgReadPtr = NULL; + arg = NULL; + null = NULL; + result = NULL; + resultIsNull = NULL; + UDFArgsHandlerPtr = NULL; + UDFResultHandlerPtr = NULL; + valid_UDFArgsHandlerPtr = false; + allocRows = 0; + argBatchRows = 0; + } +} UDFInfoType; + +typedef struct RefcusorInfoData { + Cursor_Data* argCursor; + Cursor_Data* returnCursor; + int return_number; +} RefcusorInfoData; + +/* + * This struct is the data actually passed to an fmgr-called function. + */ +typedef struct FunctionCallInfoData { + FmgrInfo* flinfo; /* ptr to lookup info used for this call */ + fmNodePtr context; /* pass info about context of call */ + fmNodePtr resultinfo; /* pass or return extra info about result */ + Oid fncollation; /* collation for function to use */ + bool isnull; /* function must set true if result is NULL */ + short nargs; /* # arguments actually passed */ + Datum* arg; /* Arguments passed to function */ + bool* argnull; /* T if arg[i] is actually NULL */ + Oid* argTypes; /* Argument type */ + Datum prealloc_arg[FUNC_PREALLOCED_ARGS]; /* prealloced arguments.*/ + bool prealloc_argnull[FUNC_PREALLOCED_ARGS]; /* prealloced argument null flags.*/ + Oid prealloc_argTypes[FUNC_PREALLOCED_ARGS]; /* prealloced argument type */ + ScalarVector* argVector; /*Scalar Vector */ + RefcusorInfoData refcursor_data; + UDFInfoType udfInfo; + + FunctionCallInfoData() + { + flinfo = NULL; + arg = NULL; + argnull = NULL; + argTypes = NULL; + argVector = NULL; + fncollation = 0; + context = NULL; + resultinfo = NULL; + nargs = 0; + isnull = false; + } +} FunctionCallInfoData; + +/* + * List of dynamically loaded files (kept in malloc'd memory). + */ + +typedef struct df_files { + struct df_files* next; /* List link */ + dev_t device; /* Device file is on */ +#ifndef WIN32 /* ensures we never again depend on this under \ + * win32 */ + ino_t inode; /* Inode number of file */ +#endif + void* handle; /* a handle for pg_dl* functions */ + char filename[FLEXIBLE_ARRAY_MEMBER]; /* Full pathname of file */ + + /* + * we allocate the block big enough for actual length of pathname. + * filename[] must be last item in struct! + */ +} DynamicFileList; + +/*Introduced to judge whether PG_init has done or not*/ +typedef struct df_files_init { + struct df_files_init* next; /*List Link*/ + DynamicFileList* file_list; /*restore file_list in the linked list*/ +} FileListInit; + +extern DynamicFileList* file_list; +extern DynamicFileList* file_tail; + +#define EXTRA_NARGS 3 + +extern bool file_exists(const char* name); +/* + * This routine fills a FmgrInfo struct, given the OID + * of the function to be called. + */ +extern void fmgr_info(Oid functionId, FmgrInfo* finfo); + +/* + * Same, when the FmgrInfo struct is in a memory context longer-lived than + * CurrentMemoryContext. The specified context will be set as fn_mcxt + * and used to hold all subsidiary data of finfo. + */ +extern void fmgr_info_cxt(Oid functionId, FmgrInfo* finfo, MemoryContext mcxt); + +extern void InitVecFunctionCallInfoData( + FunctionCallInfoData* Fcinfo, FmgrInfo* Flinfo, int Nargs, Oid Collation, fmNodePtr Context, fmNodePtr Resultinfo); + +/* Convenience macro for setting the fn_expr field */ +#define fmgr_info_set_expr(expr, finfo) ((finfo)->fn_expr = (expr)) + +/* + * Copy an FmgrInfo struct + */ +extern void fmgr_info_copy(FmgrInfo* dstinfo, FmgrInfo* srcinfo, MemoryContext destcxt); + +/* + * This macro initializes all the fields of a GenericFunRuntime except + * for the all the prealloc arrays. Performance testing has shown that + * the fastest way to set up static arrays for small numbers of arguments is to + * explicitly set each required element to false, so we don't try to zero + * out the static prealloc array in the macro. + */ + +#define InitGenericFunRuntimeInfo(GenericRuntime, Nargs) \ + do { \ + (GenericRuntime).compacity = VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS; \ + if (unlikely((Nargs) > VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS)) { \ + (GenericRuntime).compacity += \ + (((Nargs)-VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS - 1) / VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS + \ + 1) * \ + VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS; \ + } \ + (GenericRuntime).args = \ + (GenericFunRuntimeArg*)palloc0(sizeof(GenericFunRuntimeArg) * (GenericRuntime).compacity); \ + (GenericRuntime).inputargs = (Datum*)palloc0(sizeof(Datum) * (GenericRuntime).compacity); \ + (GenericRuntime).nulls = (bool*)palloc0(sizeof(bool) * (GenericRuntime).compacity); \ + } while (0) + +#define FreeGenericFunRuntimeInfo(GenericRuntime) \ + do { \ + pfree_ext((GenericRuntime).args); \ + pfree_ext((GenericRuntime).inputargs); \ + pfree_ext((GenericRuntime).nulls); \ + if (unlikely((GenericRuntime).internalFinfo != NULL)) \ + FreeFunctionCallInfoData(*((GenericRuntime).internalFinfo)); \ + (GenericRuntime).compacity = 0; \ + } while (0) + +/* + * This macro initializes all the fields of a FunctionCallInfoData except + * for the arg[] and argnull[] arrays. Performance testing has shown that + * the fastest way to set up argnull[] for small numbers of arguments is to + * explicitly set each required element to false, so we don't try to zero + * out the argnull[] array in the macro. + */ +#define InitFunctionCallInfoArgs(Fcinfo, Nargs, batchRow) \ + do { \ + (Fcinfo).nargs = (Nargs); \ + if ((Nargs) > FUNC_PREALLOCED_ARGS) { \ + (Fcinfo).arg = (Datum*)palloc0((Nargs) * sizeof(Datum)); \ + (Fcinfo).argnull = (bool*)palloc0(Nargs * sizeof(bool)); \ + (Fcinfo).argTypes = (Oid*)palloc0((Nargs) * sizeof(Oid)); \ + } else { \ + (Fcinfo).arg = (Fcinfo).prealloc_arg; \ + (Fcinfo).argnull = (Fcinfo).prealloc_argnull; \ + (Fcinfo).argTypes = (Fcinfo).prealloc_argTypes; \ + } \ + if (unlikely((Fcinfo).flinfo && (Fcinfo).flinfo->fn_fenced)) \ + InitFunctionCallUDFArgs(&(Fcinfo), (Nargs), (batchRow)); \ + } while (0) + +#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo) \ + do { \ + (Fcinfo).flinfo = (Flinfo); \ + (Fcinfo).context = (Context); \ + (Fcinfo).resultinfo = (Resultinfo); \ + (Fcinfo).fncollation = (Collation); \ + (Fcinfo).isnull = false; \ + (Fcinfo).nargs = (Nargs); \ + if ((Nargs) > FUNC_PREALLOCED_ARGS) { \ + (Fcinfo).arg = (Datum*)palloc0((Nargs) * sizeof(Datum)); \ + (Fcinfo).argnull = (bool*)palloc0((Nargs) * sizeof(bool)); \ + (Fcinfo).argTypes = (Oid*)palloc0((Nargs) * sizeof(Oid)); \ + } else { \ + (Fcinfo).arg = (Fcinfo).prealloc_arg; \ + (Fcinfo).argnull = (Fcinfo).prealloc_argnull; \ + (Fcinfo).argTypes = (Fcinfo).prealloc_argTypes; \ + } \ + if (unlikely((Flinfo) != NULL && (Fcinfo).flinfo->fn_fenced)) \ + InitFuncCallUDFInfo(&(Fcinfo), (Nargs), false); \ + (Fcinfo).refcursor_data.argCursor = NULL; \ + (Fcinfo).refcursor_data.returnCursor = NULL; \ + (Fcinfo).refcursor_data.return_number = 0; \ + } while (0) + +#define FreeFunctionCallInfoData(Fcinfo) \ + do { \ + if ((Fcinfo).nargs > FUNC_PREALLOCED_ARGS) { \ + pfree((Fcinfo).arg); \ + pfree((Fcinfo).argnull); \ + pfree((Fcinfo).argTypes); \ + (Fcinfo).argTypes = NULL; \ + (Fcinfo).arg = NULL; \ + (Fcinfo).argnull = NULL; \ + } \ + FreeFuncCallUDFInfo(&(Fcinfo)); \ + } while (0) +/* + * This macro invokes a function given a filled-in FunctionCallInfoData + * struct. The macro result is the returned Datum --- but note that + * caller must still check fcinfo->isnull! Also, if function is strict, + * it is caller's responsibility to verify that no null arguments are present + * before calling. + */ +#define FunctionCallInvoke(fcinfo) ((*(fcinfo)->flinfo->fn_addr)(fcinfo)) + +#define VecFunctionCallInvoke(fcinfo) ((*(fcinfo)->flinfo->vec_fn_addr)(fcinfo)) + +#endif /* FRONTEND_PARSER */ +/* ------------------------------------------------------------------------- + * Support macros to ease writing fmgr-compatible functions + * + * A C-coded fmgr-compatible function should be declared as + * + * Datum + * function_name(PG_FUNCTION_ARGS) + * { + * ... + * } + * + * It should access its arguments using appropriate PG_GETARG_xxx macros + * and should return its result using PG_RETURN_xxx. + * + * ------------------------------------------------------------------------- + */ + +/* Standard parameter list for fmgr-compatible functions */ +#define PG_FUNCTION_ARGS FunctionCallInfo fcinfo + +/* + * Get collation function should use. + */ +#define PG_GET_COLLATION() (fcinfo->fncollation) + +/* + * Get number of arguments passed to function. + */ +#define PG_NARGS() (fcinfo->nargs) + +/* + * If function is not marked "proisstrict" in pg_proc, it must check for + * null arguments using this macro. Do not try to GETARG a null argument! + */ +#define PG_ARGISNULL(n) (fcinfo->argnull[n]) + +#ifndef FRONTEND_PARSER +/* + * Support for fetching detoasted copies of toastable datatypes (all of + * which are varlena types). pg_detoast_datum() gives you either the input + * datum (if not toasted) or a detoasted copy allocated with palloc(). + * pg_detoast_datum_copy() always gives you a palloc'd copy --- use it + * if you need a modifiable copy of the input. Caller is expected to have + * checked for null inputs first, if necessary. + * + * pg_detoast_datum_packed() will return packed (1-byte header) datums + * unmodified. It will still expand an externally toasted or compressed datum. + * The resulting datum can be accessed using VARSIZE_ANY() and VARDATA_ANY() + * (beware of multiple evaluations in those macros!) + * + * WARNING: It is only safe to use pg_detoast_datum_packed() and + * VARDATA_ANY() if you really don't care about the alignment. Either because + * you're working with something like text where the alignment doesn't matter + * or because you're not going to access its constituent parts and just use + * things like memcpy on it anyways. + * + * Note: it'd be nice if these could be macros, but I see no way to do that + * without evaluating the arguments multiple times, which is NOT acceptable. + */ +extern struct varlena* pg_detoast_datum(struct varlena* datum); +extern struct varlena* pg_detoast_datum_copy(struct varlena* datum); +extern struct varlena* pg_detoast_datum_slice(struct varlena* datum, int32 first, int32 count); +extern struct varlena* pg_detoast_datum_packed(struct varlena* datum); + +#define PG_DETOAST_DATUM(datum) pg_detoast_datum((struct varlena*)DatumGetPointer(datum)) +#define PG_DETOAST_DATUM_COPY(datum) pg_detoast_datum_copy((struct varlena*)DatumGetPointer(datum)) +#define PG_DETOAST_DATUM_SLICE(datum, f, c) \ + pg_detoast_datum_slice((struct varlena*)DatumGetPointer(datum), (int32)(f), (int32)(c)) +/* WARNING -- unaligned pointer */ +#define PG_DETOAST_DATUM_PACKED(datum) pg_detoast_datum_packed((struct varlena*)DatumGetPointer(datum)) + +/* + * Support for cleaning up detoasted copies of inputs. This must only + * be used for pass-by-ref datatypes, and normally would only be used + * for toastable types. If the given pointer is different from the + * original argument, assume it's a palloc'd detoasted copy, and pfree it. + * NOTE: most functions on toastable types do not have to worry about this, + * but we currently require that support functions for indexes not leak + * memory. + */ +#define PG_FREE_IF_COPY(ptr, n) \ + do { \ + if ((Pointer)(ptr) != PG_GETARG_POINTER(n)) \ + pfree(ptr); \ + } while (0) + +/* Macros for fetching arguments of standard types */ + +#define PG_GETARG_DATUM(n) (fcinfo->arg[n]) +#define PG_GETARG_INT32(n) DatumGetInt32(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT32(n) DatumGetUInt32(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT16(n) DatumGetInt16(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT16(n) DatumGetUInt16(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT8(n) DatumGetInt8(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT8(n) DatumGetUInt8(PG_GETARG_DATUM(n)) +#define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n)) +#define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n)) +#define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n)) +#define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n)) +#define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n)) +#define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n)) +/* these macros hide the pass-by-reference-ness of the datatype: */ +#define PG_GETARG_FLOAT4(n) DatumGetFloat4(PG_GETARG_DATUM(n)) +#define PG_GETARG_FLOAT8(n) DatumGetFloat8(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT64(n) DatumGetInt64(PG_GETARG_DATUM(n)) +#define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n)) +#define PG_GETARG_SHORTTRANSACTIONID(n) DatumGetShortTransactionId(PG_GETARG_DATUM(n)) +/* use this if you want the raw, possibly-toasted input datum: */ +#define PG_GETARG_RAW_VARLENA_P(n) ((struct varlena*)PG_GETARG_POINTER(n)) +/* use this if you want the input datum de-toasted: */ +#define PG_GETARG_VARLENA_P(n) PG_DETOAST_DATUM(PG_GETARG_DATUM(n)) +/* and this if you can handle 1-byte-header datums: */ +#define PG_GETARG_VARLENA_PP(n) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(n)) +/* DatumGetFoo macros for varlena types will typically look like this: */ +#define DatumGetByteaP(X) ((bytea*)PG_DETOAST_DATUM(X)) +#define DatumGetByteaPP(X) ((bytea*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetTextP(X) ((text*)PG_DETOAST_DATUM(X)) +#define DatumGetTextPP(X) ((text*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetBpCharP(X) ((BpChar*)PG_DETOAST_DATUM(X)) +#define DatumGetBpCharPP(X) ((BpChar*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetVarCharP(X) ((VarChar*)PG_DETOAST_DATUM(X)) +#define DatumGetVarCharPP(X) ((VarChar*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetNVarChar2PP(X) ((NVarChar2*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetHeapTupleHeader(X) ((HeapTupleHeader)PG_DETOAST_DATUM(X)) +#define DatumGetEncryptedcolP(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM(X)) +#define DatumGetEncryptedcolPP(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM_PACKED(X)) +/* And we also offer variants that return an OK-to-write copy */ +#define DatumGetByteaPCopy(X) ((bytea*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetEncryptedcolPCopy(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM_COPY(X)) +#define DatumGetTextPCopy(X) ((text*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetBpCharPCopy(X) ((BpChar*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetVarCharPCopy(X) ((VarChar*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetHeapTupleHeaderCopy(X) ((HeapTupleHeader)PG_DETOAST_DATUM_COPY(X)) +/* Variants which return n bytes starting at pos. m */ +#define DatumGetByteaPSlice(X, m, n) ((bytea*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetTextPSlice(X, m, n) ((text*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetBpCharPSlice(X, m, n) ((BpChar*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetVarCharPSlice(X, m, n) ((VarChar*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetEncryptedcolPSlice(X, m, n) ((byteawithoutorderwithequalcol *)PG_DETOAST_DATUM_SLICE(X, m, n)) +/* GETARG macros for varlena types will typically look like this: */ +#define PG_GETARG_BYTEA_P(n) DatumGetByteaP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BYTEA_PP(n) DatumGetByteaPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_P(n) DatumGetTextP(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_PP(n) DatumGetTextPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_P(n) DatumGetBpCharP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_PP(n) DatumGetBpCharPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_P(n) DatumGetVarCharP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_PP(n) DatumGetVarCharPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_NVARCHAR2_PP(n) DatumGetNVarChar2PP(PG_GETARG_DATUM(n)) +#define PG_GETARG_HEAPTUPLEHEADER(n) DatumGetHeapTupleHeader(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_P(n) DatumGetEncryptedcolP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_PP(n) DatumGetEncryptedcolPP(PG_GETARG_DATUM(n)) +/* And we also offer variants that return an OK-to-write copy */ +#define PG_GETARG_BYTEA_P_COPY(n) DatumGetByteaPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_P_COPY(n) DatumGetTextPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_P_COPY(n) DatumGetBpCharPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_P_COPY(n) DatumGetVarCharPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_HEAPTUPLEHEADER_COPY(n) DatumGetHeapTupleHeaderCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_P_COPY(n) DatumGetEncryptedcolPCopy(PG_GETARG_DATUM(n)) +/* And a b-byte slice from position a -also OK to write */ +#define PG_GETARG_BYTEA_P_SLICE(n, a, b) DatumGetByteaPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_ENCRYPTEDCOL_P_SLICE(n, a, b) DatumGetEncryptedcolPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_TEXT_P_SLICE(n, a, b) DatumGetTextPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_BPCHAR_P_SLICE(n, a, b) DatumGetBpCharPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_VARCHAR_P_SLICE(n, a, b) DatumGetVarCharPSlice(PG_GETARG_DATUM(n), a, b) + +// Vectorized getters +// +#define PG_GETARG_VECTOR(n) ((ScalarVector*)(PG_GETARG_DATUM(n))) +#define PG_GETARG_SELECTION(n) ((bool*)(PG_GETARG_DATUM(n))) +#define PG_GETARG_VECVAL(n) ((ScalarValue*)(PG_GETARG_VECTOR(n)->m_vals)) + +/* To return a NULL do this: */ +#define PG_RETURN_NULL() \ + do { \ + fcinfo->isnull = true; \ + return (Datum)0; \ + } while (0) + +/* A few internal functions return void (which is not the same as NULL!) */ +#define PG_RETURN_VOID() return (Datum)0 + +/* Macros for returning results of standard types */ + +#define PG_RETURN_DATUM(x) return (x) +#define PG_RETURN_INT32(x) return Int32GetDatum(x) +#define PG_RETURN_UINT32(x) return UInt32GetDatum(x) +#define PG_RETURN_INT16(x) return Int16GetDatum(x) +#define PG_RETURN_UINT16(x) return UInt16GetDatum(x) +#define PG_RETURN_UINT8(x) return UInt8GetDatum(x) +#define PG_RETURN_CHAR(x) return CharGetDatum(x) +#define PG_RETURN_BOOL(x) return BoolGetDatum(x) +#define PG_RETURN_OID(x) return ObjectIdGetDatum(x) +#define PG_RETURN_POINTER(x) return PointerGetDatum(x) +#define PG_RETURN_CSTRING(x) return CStringGetDatum(x) +#define PG_RETURN_NAME(x) return NameGetDatum(x) +/* these macros hide the pass-by-reference-ness of the datatype: */ +#define PG_RETURN_FLOAT4(x) return Float4GetDatum(x) +#define PG_RETURN_FLOAT8(x) return Float8GetDatum(x) +#define PG_RETURN_INT64(x) return Int64GetDatum(x) +#define PG_RETURN_TRANSACTIONID(x) return TransactionIdGetDatum(x) +#define PG_RETURN_SHORTTRANSACTIONID(x) return ShortTransactionIdGetDatum(x) +/* RETURN macros for other pass-by-ref types will typically look like this: */ +#define PG_RETURN_BYTEA_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_ENCRYPTEDCOL_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_TEXT_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_BPCHAR_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_VARCHAR_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_HEAPTUPLEHEADER(x) PG_RETURN_POINTER(x) +#define PG_RETURN_NVARCHAR2_P(x) PG_RETURN_POINTER(x) + +typedef enum COMM_ARG_IDX { + ARG_0, + ARG_1, + ARG_2, + ARG_3, + ARG_4, + ARG_5, + ARG_6, + ARG_7, + ARG_8, + ARG_9, + ARG_10, + ARG_11, + ARG_12, + ARG_13, + ARG_14, + ARG_15, + ARG_16, + ARG_17, + ARG_18, + ARG_19, + ARG_20, + ARG_END +} COMM_ARG_IDX; + +typedef enum COMM_ARR_IDX { + ARR_0, + ARR_1, + ARR_2, + ARR_3, + ARR_4, + ARR_5, + ARR_6, + ARR_7, + ARR_8, + ARR_9, + ARR_10, + ARR_11, + ARR_12, + ARR_13, + ARR_14, + ARR_15, + ARR_16, + ARR_17, + ARR_18, + ARR_19, + ARR_20, + ARR_END +} COMM_ARR_IDX; + +/* ------------------------------------------------------------------------- + * Support for detecting call convention of dynamically-loaded functions + * + * Dynamically loaded functions may use either the version-1 ("new style") + * or version-0 ("old style") calling convention. Version 1 is the call + * convention defined in this header file; version 0 is the old "plain C" + * convention. A version-1 function must be accompanied by the macro call + * + * PG_FUNCTION_INFO_V1(function_name); + * + * Note that internal functions do not need this decoration since they are + * assumed to be version-1. + * + * ------------------------------------------------------------------------- + */ + +typedef struct { + int api_version; /* specifies call convention version number */ + /* More fields may be added later, for version numbers > 1. */ +} Pg_finfo_record; + +/* Expected signature of an info function */ +typedef const Pg_finfo_record* (*PGFInfoFunction)(void); + +/* + * Macro to build an info function associated with the given function name. + * Win32 loadable functions usually link with 'dlltool --export-all', but it + * doesn't hurt to add PGDLLIMPORT in case they don't. + */ +#define PG_FUNCTION_INFO_V1(funcname) \ + extern "C" PGDLLEXPORT const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void); \ + const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void) \ + { \ + static const Pg_finfo_record my_finfo = {1}; \ + return &my_finfo; \ + } \ + extern int no_such_variable + +/* ------------------------------------------------------------------------- + * Support for verifying backend compatibility of loaded modules + * + * We require dynamically-loaded modules to include the macro call + * PG_MODULE_MAGIC; + * so that we can check for obvious incompatibility, such as being compiled + * for a different major PostgreSQL version. + * + * To compile with versions of PostgreSQL that do not support this, + * you may put an #ifdef/#endif test around it. Note that in a multiple- + * source-file module, the macro call should only appear once. + * + * The specific items included in the magic block are intended to be ones that + * are custom-configurable and especially likely to break dynamically loaded + * modules if they were compiled with other values. Also, the length field + * can be used to detect definition changes. + * + * Note: we compare magic blocks with memcmp(), so there had better not be + * any alignment pad bytes in them. + * + * Note: when changing the contents of magic blocks, be sure to adjust the + * incompatible_module_error() function in dfmgr.c. + * ------------------------------------------------------------------------- + */ + +/* Definition of the magic block structure */ +typedef struct { + int len; /* sizeof(this struct) */ + int version; /* PostgreSQL major version */ + int funcmaxargs; /* FUNC_MAX_ARGS */ + int indexmaxkeys; /* INDEX_MAX_KEYS */ + int namedatalen; /* NAMEDATALEN */ + int float4byval; /* FLOAT4PASSBYVAL */ + int float8byval; /* FLOAT8PASSBYVAL */ +} Pg_magic_struct; + +/* The actual data block contents */ +#define PG_MODULE_MAGIC_DATA \ + { \ + sizeof(Pg_magic_struct), PG_VERSION_NUM / 100, FUNC_MAX_ARGS, INDEX_MAX_KEYS, NAMEDATALEN, FLOAT4PASSBYVAL, \ + FLOAT8PASSBYVAL \ + } + +/* + * Declare the module magic function. It needs to be a function as the dlsym + * in the backend is only guaranteed to work on functions, not data + */ +typedef const Pg_magic_struct* (*PGModuleMagicFunction)(void); + +#define PG_MAGIC_FUNCTION_NAME Pg_magic_func +#define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func" + +#define PG_MODULE_MAGIC \ + extern "C" PGDLLEXPORT const Pg_magic_struct* PG_MAGIC_FUNCTION_NAME(void); \ + const Pg_magic_struct* PG_MAGIC_FUNCTION_NAME(void) \ + { \ + static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \ + return &Pg_magic_data; \ + } \ + extern int no_such_variable + +/* ------------------------------------------------------------------------- + * Support routines and macros for callers of fmgr-compatible functions + * ------------------------------------------------------------------------- + */ + +/* These are for invocation of a specifically named function with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. + */ +extern Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1); +extern Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2); +extern Datum DirectFunctionCall3Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum DirectFunctionCall4Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum DirectFunctionCall5Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum DirectFunctionCall6Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum DirectFunctionCall7Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7); +extern Datum DirectFunctionCall8Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum DirectFunctionCall9Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These are for invocation of a previously-looked-up function with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. + */ +extern Datum FunctionCall1Coll(FmgrInfo* flinfo, Oid collation, Datum arg1); +extern Datum FunctionCall2Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2); +extern Datum FunctionCall3Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum FunctionCall4Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum FunctionCall5Coll( + FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum FunctionCall6Coll( + FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum FunctionCall7Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7); +extern Datum FunctionCall8Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum FunctionCall9Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These are for invocation of a function identified by OID with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. These are essentially FunctionLookup() followed + * by FunctionCallN(). If the same function is to be invoked repeatedly, + * do the FunctionLookup() once and then use FunctionCallN(). + */ +extern Datum OidFunctionCall0Coll(Oid functionId, Oid collation); +extern Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1); +extern Datum OidFunctionCall2Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2); +extern Datum OidFunctionCall3Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum OidFunctionCall4Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum OidFunctionCall5Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum OidFunctionCall6Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum OidFunctionCall7Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7); +extern Datum OidFunctionCall8Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum OidFunctionCall9Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These macros allow the collation argument to be omitted (with a default of + * InvalidOid, ie, no collation). They exist mostly for backwards + * compatibility of source code. + */ +#define DirectFunctionCall1(func, arg1) DirectFunctionCall1Coll(func, InvalidOid, arg1) +#define DirectFunctionCall2(func, arg1, arg2) DirectFunctionCall2Coll(func, InvalidOid, arg1, arg2) +#define DirectFunctionCall3(func, arg1, arg2, arg3) DirectFunctionCall3Coll(func, InvalidOid, arg1, arg2, arg3) +#define DirectFunctionCall4(func, arg1, arg2, arg3, arg4) \ + DirectFunctionCall4Coll(func, InvalidOid, arg1, arg2, arg3, arg4) +#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5) \ + DirectFunctionCall5Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define DirectFunctionCall6(func, arg1, arg2, arg3, arg4, arg5, arg6) \ + DirectFunctionCall6Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define DirectFunctionCall7(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + DirectFunctionCall7Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define DirectFunctionCall8(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + DirectFunctionCall8Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define DirectFunctionCall9(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + DirectFunctionCall9Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +#define FunctionCall1(flinfo, arg1) FunctionCall1Coll(flinfo, InvalidOid, arg1) +#define FunctionCall2(flinfo, arg1, arg2) FunctionCall2Coll(flinfo, InvalidOid, arg1, arg2) +#define FunctionCall3(flinfo, arg1, arg2, arg3) FunctionCall3Coll(flinfo, InvalidOid, arg1, arg2, arg3) +#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4) FunctionCall4Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4) +#define FunctionCall5(flinfo, arg1, arg2, arg3, arg4, arg5) \ + FunctionCall5Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define FunctionCall6(flinfo, arg1, arg2, arg3, arg4, arg5, arg6) \ + FunctionCall6Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define FunctionCall7(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + FunctionCall7Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define FunctionCall8(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + FunctionCall8Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define FunctionCall9(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + FunctionCall9Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +#define OidFunctionCall0(functionId) OidFunctionCall0Coll(functionId, InvalidOid) +#define OidFunctionCall1(functionId, arg1) OidFunctionCall1Coll(functionId, InvalidOid, arg1) +#define OidFunctionCall2(functionId, arg1, arg2) OidFunctionCall2Coll(functionId, InvalidOid, arg1, arg2) +#define OidFunctionCall3(functionId, arg1, arg2, arg3) OidFunctionCall3Coll(functionId, InvalidOid, arg1, arg2, arg3) +#define OidFunctionCall4(functionId, arg1, arg2, arg3, arg4) \ + OidFunctionCall4Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4) +#define OidFunctionCall5(functionId, arg1, arg2, arg3, arg4, arg5) \ + OidFunctionCall5Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define OidFunctionCall6(functionId, arg1, arg2, arg3, arg4, arg5, arg6) \ + OidFunctionCall6Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define OidFunctionCall7(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + OidFunctionCall7Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define OidFunctionCall8(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + OidFunctionCall8Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define OidFunctionCall9(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + OidFunctionCall9Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + +typedef struct { + PGFunction user_fn; /* the function's address */ + const Pg_finfo_record* inforec; /* address of its info record */ +} CFunInfo; + +/* Special cases for convenient invocation of datatype I/O functions. */ +extern Datum InputFunctionCall(FmgrInfo* flinfo, char* str, Oid typioparam, int32 typmod); +extern Datum InputFunctionCallForDateType( + FmgrInfo* flinfo, char* str, Oid typioparam, int32 typmod, char* date_time_fmt); +extern Datum OidInputFunctionCall(Oid functionId, char* str, Oid typioparam, int32 typmod); +extern char* OutputFunctionCall(FmgrInfo* flinfo, Datum val); +extern char* OidOutputFunctionCall(Oid functionId, Datum val); +extern Datum ReceiveFunctionCall(FmgrInfo* flinfo, fmStringInfo buf, Oid typioparam, int32 typmod); +extern Datum OidReceiveFunctionCall(Oid functionId, fmStringInfo buf, Oid typioparam, int32 typmod); +extern bytea* SendFunctionCall(FmgrInfo* flinfo, Datum val); +extern bytea* OidSendFunctionCall(Oid functionId, Datum val); + +/* + * Routines in fmgr.c + */ +extern const Pg_finfo_record* fetch_finfo_record(void* filehandle, char* funcname, bool isValidate); +extern void clear_external_function_hash(void* filehandle); +extern Oid fmgr_internal_function(const char* proname); +extern Oid get_fn_expr_rettype(FmgrInfo* flinfo); +extern Oid get_fn_expr_argtype(FmgrInfo* flinfo, int argnum); +extern Oid get_call_expr_argtype(fmNodePtr expr, int argnum); +extern bool get_fn_expr_arg_stable(FmgrInfo* flinfo, int argnum); +extern bool get_call_expr_arg_stable(fmNodePtr expr, int argnum); +extern bool get_fn_expr_variadic(FmgrInfo* flinfo); +extern bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid); + +extern void check_external_function(const char* filepath, const char* filename, const char* funcname); +extern CFunInfo load_external_function(const char* filename, char* funcname, bool signalNotFound, bool isValidate); +extern char* expand_dynamic_library_name(const char* name); +extern PGFunction lookup_external_function(void* filehandle, const char* funcname); +extern void load_file(const char* filename, bool restricted); +extern void** find_rendezvous_variable(const char* varName); + +/* + * Support for aggregate functions + * + * This is actually in executor/nodeAgg.c, but we declare it here since the + * whole point is for callers of it to not be overly friendly with nodeAgg. + */ + +/* AggCheckCallContext can return one of the following codes, or 0: */ +#define AGG_CONTEXT_AGGREGATE 1 /* regular aggregate */ +#define AGG_CONTEXT_WINDOW 2 /* window function */ + +extern int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext* aggcontext); + +/* + * We allow plugin modules to hook function entry/exit. This is intended + * as support for loadable security policy modules, which may want to + * perform additional privilege checks on function entry or exit, or to do + * other internal bookkeeping. To make this possible, such modules must be + * able not only to support normal function entry and exit, but also to trap + * the case where we bail out due to an error; and they must also be able to + * prevent inlining. + */ +typedef enum FmgrHookEventType { FHET_START, FHET_END, FHET_ABORT } FmgrHookEventType; + +typedef bool (*needs_fmgr_hook_type)(Oid fn_oid); + +typedef void (*fmgr_hook_type)(FmgrHookEventType event, FmgrInfo* flinfo, Datum* arg); + +extern THR_LOCAL PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook; +extern THR_LOCAL PGDLLIMPORT fmgr_hook_type fmgr_hook; + +#define FmgrHookIsNeeded(fn_oid) (!needs_fmgr_hook ? false : (*needs_fmgr_hook)(fn_oid)) + +// Define common stuff for vectorized expression // +typedef enum SimpleOp { + SOP_EQ, // = + SOP_NEQ, // != + SOP_LE, // <= + SOP_LT, // < + SOP_GE, // >= + SOP_GT, // > +} SimpleOp; + +template +inline bool eval_simple_op(Datatype dataVal1, Datatype dataVal2) +{ + if (sop == SOP_EQ) + return ((dataVal1) == (dataVal2)); + if (sop == SOP_NEQ) + return ((dataVal1) != (dataVal2)); + if (sop == SOP_LE) + return ((dataVal1) <= (dataVal2)); + if (sop == SOP_LT) + return ((dataVal1) < (dataVal2)); + if (sop == SOP_GE) + return ((dataVal1) >= (dataVal2)); + if (sop == SOP_GT) + return ((dataVal1) > (dataVal2)); + return false; +} + +/* + * !!! OLD INTERFACE !!! + * + * fmgr() is the only remaining vestige of the old-style caller support + * functions. It's no longer used anywhere in the Postgres distribution, + * but we should leave it around for a release or two to ease the transition + * for user-supplied C functions. OidFunctionCallN() replaces it for new + * code. + */ + +/* + * DEPRECATED, DO NOT USE IN NEW CODE + */ +extern char* fmgr(Oid procedureId, ...); + +extern Datum DirectCall0(bool* isRetNull, PGFunction func, Oid collation); +extern Datum DirectCall1(bool* isRetNull, PGFunction func, Oid collation, Datum arg1); +extern Datum DirectCall2(bool* isRetNull, PGFunction func, Oid collation, Datum arg1, Datum arg2); +extern Datum DirectCall3(bool* isRetNull, PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum interval_in(PG_FUNCTION_ARGS); + +#define CHECK_RETNULL_RETURN_DATUM(x) \ + do { \ + _datum = (x); \ + if (_isRetNull) \ + PG_RETURN_NULL(); \ + else \ + return _datum; \ + } while (0) +#define CHECK_RETNULL_CALL0(func, collation) DirectCall0(&_isRetNull, func, collation) +#define CHECK_RETNULL_CALL1(func, collation, arg1) DirectCall1(&_isRetNull, func, collation, arg1) +#define CHECK_RETNULL_CALL2(func, collation, arg1, arg2) DirectCall2(&_isRetNull, func, collation, arg1, arg2) +#define CHECK_RETNULL_CALL3(func, collation, arg1, arg2, arg3) \ + DirectCall3(&_isRetNull, func, collation, arg1, arg2, arg3) +#define CHECK_RETNULL_INIT() \ + Datum _datum; \ + bool _isRetNull = false + +#endif /* !FRONTEND_PARSER */ + +extern void CopyCursorInfoData(Cursor_Data* target_data, Cursor_Data* source_data); + +#endif /* FMGR_H */ diff -uprN postgresql-hll-2.14_old/include/foreign/dummyserver.h postgresql-hll-2.14/include/foreign/dummyserver.h --- postgresql-hll-2.14_old/include/foreign/dummyserver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/foreign/dummyserver.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dummyserver.h + * support for computing pool. The dummy server is used to store the + * connection information of computing pool. + * + * + * IDENTIFICATION + * src/include/foreign/dummyserver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_DUMMYSERVER_H +#define GAUSSDB_FOREIGN_DUMMYSERVER_H + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "utils/hsearch.h" + +#ifndef DUMMY_SERVER +#define DUMMY_SERVER "dummy" +#endif + +/* user name for logging in computing pool. */ +#define OPTION_NAME_USER_NAME "username" +/* password for logging in computing pool. */ +#define OPTION_NAME_PASSWD "password" + +char* getOptionValueFromOptionList(List* optionList, const char* optionName); + +/* + * Store computing pool information in order to connect + * computing pool. + */ +typedef struct DummyServerOptions { + /* the given dummy server oid. it is used to be hash key also. + the server information will store in cache. */ + Oid serverOid; + /*user name of connect computing pool. */ + char* userName; + /* user password of connect computing pool. */ + char* passWord; + char* address; + char* dbname; + char* remoteservername; +} DummyServerOptions; + +/** + * @Description: Get the dummy server options. Currently, only dummy server + * exist in database. + * @return return server options if found it, otherwise return NULL. + */ +DummyServerOptions* getDummyServerOption(); + +/** + * @Description: Init dummy server cache. + * @return none. + */ +void InitDummyServrCache(); + +/** + * @Description: Drop cache when we operator alter server + * or drop server. + * @in serverOid, the server oid to be deleted. + * @return none. + */ +void InvalidDummyServerCache(Oid serverOid); + +/** + * @Description: get dummy server oid from catalog. + * @return return server oid if find one server oid, otherwise return InvalidOid. + */ +Oid getDummyServerOid(); + +/** + * @Description: if the optionList belong to dummy server, we need check the entire + * database. if exists one dummy server, throw error, otherwise do nothing. + * @in optionList, the option list to be checked. + * @return if exists one dummy server in current database, + * throw error, otherwise do nothing. + */ + +void checkExistDummyServer(List* optionList); + +/** + * @Description: jugde a dummy server type by checking server option list. + * @in optionList, the option list to be checked. + * @return + */ +bool isDummyServerByOptions(List* optionList); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/foreign/fdwapi.h postgresql-hll-2.14/include/foreign/fdwapi.h --- postgresql-hll-2.14_old/include/foreign/fdwapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/foreign/fdwapi.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------------- + * + * fdwapi.h + * API for foreign-data wrappers + * + * Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/foreign/fdwapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FDWAPI_H +#define FDWAPI_H + +#include "nodes/execnodes.h" +#include "nodes/relation.h" +#include "vecexecutor/vectorbatch.h" +#include "vecexecutor/vecnodes.h" +#include "pgstat.h" + +/* To avoid including explain.h here, reference ExplainState thus: */ +struct ExplainState; + +/* + * Callback function signatures --- see fdwhandler.sgml for more info. + */ + +typedef void (*GetForeignRelSize_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); + +typedef void (*GetForeignPaths_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); + +typedef ForeignScan* (*GetForeignPlan_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid, + ForeignPath* best_path, List* tlist, List* scan_clauses); + +typedef void (*BeginForeignScan_function)(ForeignScanState* node, int eflags); + +typedef TupleTableSlot* (*IterateForeignScan_function)(ForeignScanState* node); + +typedef void (*ReScanForeignScan_function)(ForeignScanState* node); + +typedef void (*EndForeignScan_function)(ForeignScanState* node); + +typedef void (*AddForeignUpdateTargets_function)(Query* parsetree, RangeTblEntry* target_rte, Relation target_relation); + +typedef List* (*PlanForeignModify_function)( + PlannerInfo* root, ModifyTable* plan, Index resultRelation, int subplan_index); + +typedef void (*BeginForeignModify_function)( + ModifyTableState* mtstate, ResultRelInfo* rinfo, List* fdw_private, int subplan_index, int eflags); + +typedef TupleTableSlot* (*ExecForeignInsert_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef TupleTableSlot* (*ExecForeignUpdate_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef TupleTableSlot* (*ExecForeignDelete_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef void (*EndForeignModify_function)(EState* estate, ResultRelInfo* rinfo); + +typedef int (*IsForeignRelUpdatable_function)(Relation rel); + +typedef void (*ExplainForeignScan_function)(ForeignScanState* node, struct ExplainState* es); + +typedef void (*ExplainForeignModify_function)( + ModifyTableState* mtstate, ResultRelInfo* rinfo, List* fdw_private, int subplan_index, struct ExplainState* es); + +typedef int (*AcquireSampleRowsFunc)(Relation relation, /* relation to be sampled */ + int elevel, /* log level */ + HeapTuple* rows, /* store sampled data */ + int targrows, /* the count of tuples we want to sample */ + double* totalrows, /* the actual count of tuples we sampled */ + double* totaldeadrows, /* totaldeadrows is no means for DFS table */ + void* additionalData, /* We use this parameter to pass data */ + bool estimate_table_rownum); /* wether get sample rows */ + +typedef bool (*AnalyzeForeignTable_function)(Relation relation, /* relation to be analzyed */ + AcquireSampleRowsFunc* func, /* foreign table sampling fucntion point */ + BlockNumber* totalpages, /* total pages in relation, will be set in analzyeforeigntable_function*/ + void* additionalData, /* pass data used by AnalyzeForeignTable function */ + bool estimate_table_rownum); /* wether get sample rows */ + +typedef VectorBatch* (*VecIterateForeignScan_function)(VecForeignScanState* node); + +/* + * @hdfs + * + * GetFdwType_function + * This function is used to return the type of FDW. + * Return value "hdfs_orc" for hdfs orc file. + */ +typedef int (*GetFdwType_function)(); + +typedef void (*ValidateTableDef_function)(Node* Obj); + +typedef void (*TruncateForeignTable_function)(TruncateStmt* stmt, Relation rel); +typedef void (*VacuumForeignTable_function)(VacuumStmt* stmt, Relation rel); +typedef uint64_t (*GetForeignRelationMemSize_function)(Oid reloid, Oid ixoid); +typedef MotMemoryDetail* (*GetForeignMemSize_function)(uint32* nodeCount, bool isGlobal); +typedef MotSessionMemoryDetail* (*GetForeignSessionMemSize_function)(uint32* sessionCount); +typedef void (*NotifyForeignConfigChange_function)(); + +typedef enum { + HDFS_DROP_PARTITIONED_FOREIGNTBL, + HDFS_CREATE_PARTITIONED_FOREIGNTBL, + HDFS_ALTER_PARTITIONED_FOREIGNTBL +} HDFS_PARTTBL_OPERATOR; +typedef void (*PartitionTblProcess_function)(Node* Obj, Oid relid, HDFS_PARTTBL_OPERATOR op); + +typedef enum { + HDFS_BLOOM_FILTER +} HDFS_RUNTIME_PREDICATE; +typedef void (*BuildRuntimePredicate_function)( + ForeignScanState* node, void* value, int colIdx, HDFS_RUNTIME_PREDICATE type); + +/* + * FdwRoutine is the struct returned by a foreign-data wrapper's handler + * function. It provides pointers to the callback functions needed by the + * planner and executor. + * + * More function pointers are likely to be added in the future. Therefore + * it's recommended that the handler initialize the struct with + * makeNode(FdwRoutine) so that all fields are set to NULL. This will + * ensure that no fields are accidentally left undefined. + */ +typedef struct FdwRoutine { + NodeTag type; + + /* Functions for scanning foreign tables */ + GetForeignRelSize_function GetForeignRelSize; + GetForeignPaths_function GetForeignPaths; + GetForeignPlan_function GetForeignPlan; + BeginForeignScan_function BeginForeignScan; + IterateForeignScan_function IterateForeignScan; + ReScanForeignScan_function ReScanForeignScan; + EndForeignScan_function EndForeignScan; + + /* + * These functions are optional. Set the pointer to NULL for any that are + * not provided. + */ + + /* Functions for updating foreign tables */ + AddForeignUpdateTargets_function AddForeignUpdateTargets; + PlanForeignModify_function PlanForeignModify; + BeginForeignModify_function BeginForeignModify; + ExecForeignInsert_function ExecForeignInsert; + ExecForeignUpdate_function ExecForeignUpdate; + ExecForeignDelete_function ExecForeignDelete; + EndForeignModify_function EndForeignModify; + IsForeignRelUpdatable_function IsForeignRelUpdatable; + + /* Support functions for EXPLAIN */ + ExplainForeignScan_function ExplainForeignScan; + ExplainForeignModify_function ExplainForeignModify; + + /* @hdfs Support functions for ANALYZE */ + AnalyzeForeignTable_function AnalyzeForeignTable; + + /* @hdfs Support function for sampling */ + AcquireSampleRowsFunc AcquireSampleRows; + + /* @hdfs Support Vector Interface */ + VecIterateForeignScan_function VecIterateForeignScan; + + /* @hdfs This function is uesed to return the type of FDW */ + GetFdwType_function GetFdwType; + + /* @hdfs Validate table definition */ + ValidateTableDef_function ValidateTableDef; + + /* @hdfs + * Partition foreign table process: create/drop + */ + PartitionTblProcess_function PartitionTblProcess; + + /* @hdfs Runtime dynamic predicate push down like bloom filter. */ + BuildRuntimePredicate_function BuildRuntimePredicate; + + /* Support truncate for foreign table */ + TruncateForeignTable_function TruncateForeignTable; + + /* Support vacuum */ + VacuumForeignTable_function VacuumForeignTable; + + /* Get table/index memory size */ + GetForeignRelationMemSize_function GetForeignRelationMemSize; + + /* Get memory size */ + GetForeignMemSize_function GetForeignMemSize; + + /* Get all session memory size */ + GetForeignSessionMemSize_function GetForeignSessionMemSize; + + /* Notify engine that envelope configuration changed */ + NotifyForeignConfigChange_function NotifyForeignConfigChange; +} FdwRoutine; + +/* Functions in foreign/foreign.c */ +extern FdwRoutine* GetFdwRoutine(Oid fdwhandler); +extern FdwRoutine* GetFdwRoutineByRelId(Oid relid); +extern FdwRoutine* GetFdwRoutineByServerId(Oid serverid); +extern FdwRoutine* GetFdwRoutineForRelation(Relation relation, bool makecopy); + +#endif /* FDWAPI_H */ diff -uprN postgresql-hll-2.14_old/include/foreign/foreign.h postgresql-hll-2.14/include/foreign/foreign.h --- postgresql-hll-2.14_old/include/foreign/foreign.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/foreign/foreign.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,336 @@ +/* ------------------------------------------------------------------------- + * + * foreign.h + * support for foreign-data wrappers, servers and user mappings. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/foreign/foreign.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FOREIGN_H +#define FOREIGN_H + +#include "access/obs/obs_am.h" +#include "commands/defrem.h" +#include "nodes/parsenodes.h" + +#ifndef OBS_SERVER +#define OBS_SERVER "obs" +#endif +#ifndef HDFS_SERVER +#define HDFS_SERVER "hdfs" +#endif + +#define OBS_BUCKET_URL_FORMAT_FLAG ".obs." +#define OBS_PREFIX "obs://" +#define OBS_PREfIX_LEN strlen(OBS_PREFIX) + +/* Defines for valid option names. */ +/* The followings are foreign table options. */ +#define OPTION_NAME_LOCATION "location" +#define OPTION_NAME_FORMAT "format" +#define OPTION_NAME_HEADER "header" +#define OPTION_NAME_DELIMITER "delimiter" +#define OPTION_NAME_QUOTE "quote" +#define OPTION_NAME_ESCAPE "escape" +#define OPTION_NAME_NULL "null" +#define OPTION_NAME_NOESCAPING "noescaping" +#define OPTION_NAME_ENCODING "encoding" +#define OPTION_NAME_FILL_MISSING_FIELDS "fill_missing_fields" +#define OPTION_NAME_IGNORE_EXTRA_DATA "ignore_extra_data" +#define OPTION_NAME_DATE_FORMAT "date_format" +#define OPTION_NAME_TIME_FORMAT "time_format" +#define OPTION_NAME_TIMESTAMP_FORMAT "timestamp_format" +#define OPTION_NAME_SMALLDATETIME_FORMAT "smalldatetime_format" +#define OPTION_NAME_CHUNK_SIZE "chunksize" + +#define OPTION_NAME_FILENAMES "filenames" +#define OPTION_NAME_FOLDERNAME "foldername" +#define OPTION_NAME_CHECK_ENCODING "checkencoding" +#define OPTION_NAME_TOTALROWS "totalrows" + +/* The followings are foreign server options. */ +#define OPTION_NAME_REGION "region" +#define OPTION_NAME_ADDRESS "address" +#define OPTION_NAME_CFGPATH "hdfscfgpath" +#define OPTION_NAME_SERVER_ENCRYPT "encrypt" +#define OPTION_NAME_SERVER_AK "access_key" +#define OPTION_NAME_SERVER_SAK "secret_access_key" +#define OPTION_NAME_SERVER_TYPE "type" +#define OPTION_NAME_DBNAME "dbname" +#define OPTION_NAME_REMOTESERVERNAME "remoteservername" +#define OPTION_NAME_OBSKEY "obskey" + +/* The followings are foreign table option values */ +#define MAX_TOTALROWS LONG_MAX +#define MIN_TOTALROWS 1 + +/* Helper for obtaining username for user mapping */ +#define MappingUserName(userid) (OidIsValid(userid) ? GetUserNameFromId(userid) : "public") + +#define DFS_FORMAT_TEXT "text" +#define DFS_FORMAT_CSV "csv" +#define DFS_FORMAT_ORC "orc" +#define DFS_FORMAT_PARQUET "parquet" +#define DFS_FORMAT_CARBONDATA "carbondata" + +typedef enum DFSFileType { + DFS_INVALID = -1, + DFS_ORC = 0, + DFS_PARQUET = 1, + DFS_TEXT = 2, + DFS_CSV = 3, + DFS_CARBONDATA = 4 +} DFSFileType; + +/* + * Generic option types for validation. + * NB! Thes are treated as flags, so use only powers of two here. + */ +typedef enum { + ServerOpt = 1, /* options applicable to SERVER */ + UserMappingOpt = 2, /* options for USER MAPPING */ + FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */ +} GenericOptionFlags; + +typedef struct ForeignDataWrapper { + Oid fdwid; /* FDW Oid */ + Oid owner; /* FDW owner user Oid */ + char* fdwname; /* Name of the FDW */ + Oid fdwhandler; /* Oid of handler function, or 0 */ + Oid fdwvalidator; /* Oid of validator function, or 0 */ + List* options; /* fdwoptions as DefElem list */ +} ForeignDataWrapper; + +typedef struct ForeignServer { + Oid serverid; /* server Oid */ + Oid fdwid; /* foreign-data wrapper */ + Oid owner; /* server owner user Oid */ + char* servername; /* name of the server */ + char* servertype; /* server type, optional */ + char* serverversion; /* server version, optional */ + List* options; /* srvoptions as DefElem list */ +} ForeignServer; + +typedef struct UserMapping { + Oid userid; /* local user Oid */ + Oid serverid; /* server Oid */ + List* options; /* useoptions as DefElem list */ +} UserMapping; + +typedef struct ForeignTable { + Oid relid; /* relation Oid */ + Oid serverid; /* server Oid */ + List* options; /* ftoptions as DefElem list */ + bool write_only; /* is relation updatable ? */ +} ForeignTable; + +/* + *HdfsServerAddress keeps foreign server ip and port + */ +typedef struct HdfsServerAddress { + char* HdfsIp; + char* HdfsPort; +} HdfsServerAddress; + +/* Define the server type enum in order to realize some function interface. */ +typedef enum ServerTypeOption { + T_INVALID = 0, + T_OBS_SERVER, + T_HDFS_SERVER, + T_MOT_SERVER, + T_DUMMY_SERVER, + T_TXT_CSV_OBS_SERVER, /* mark the txt/csv foramt OBS foreign server. the fdw + is dist_fdw. */ + T_PGFDW_SERVER +} ServerTypeOption; + +/* + * This struct store the foreign table options for computing pool. + */ +typedef struct ForeignOptions { + NodeTag type; + + ServerTypeOption stype; + + /* it store the all foreign options. */ + List* fOptions; +} ForeignOptions; + +/* + * HdfsFdwOptions holds the option values to be used when reading and parsing + * the orc file. To resolve these values, we first check foreign table's + * options, and if not present, we then fall back to the default values + * specified above. + */ +typedef struct HdfsFdwOptions { + char* foldername; + char* filename; + char* address; + int port; + char* location; +} HdfsFdwOptions; + +typedef struct HdfsOptions { + char* servername; + char* format; +} HdfsOptions; + +extern int find_Nth(const char* str, unsigned N, const char* find); + +extern ForeignServer* GetForeignServer(Oid serverid); +extern ForeignServer* GetForeignServerByName(const char* name, bool missing_ok); +extern UserMapping* GetUserMapping(Oid userid, Oid serverid); +extern ForeignDataWrapper* GetForeignDataWrapper(Oid fdwid); +extern ForeignDataWrapper* GetForeignDataWrapperByName(const char* name, bool missing_ok); +extern ForeignTable* GetForeignTable(Oid relid); + +extern List* GetForeignColumnOptions(Oid relid, AttrNumber attnum); + +extern Oid get_foreign_data_wrapper_oid(const char* fdwname, bool missing_ok); +extern Oid get_foreign_server_oid(const char* servername, bool missing_ok); + +extern DefElem* GetForeignTableOptionByName(Oid reloid, const char* optname); +extern bool IsSpecifiedFDW(const char* ServerName, const char* SepcifiedType); +extern char* getServerOptionValue(Oid srvOid, const char* optionName); + +// foreign table option values +DefElem* HdfsGetOptionDefElem(Oid foreignTableId, const char* optionName); + +extern char* getFTOptionValue(List* option_list, const char* option_name); +extern DefElemAction getFTAlterAction(List* option_list, const char* option_name); + +extern DefElem* getFTOptionDefElemFromList(List* optionList, const char* optionName); + +extern double convertFTOptionValue(const char* s); +extern char* GetForeignServerName(Oid serverid); +extern ColumnDef* makeColumnDef(const char* colname, char* coltype); + +/** + * @Description: Jude whether type of the foreign table equal to the specified type or not. + * @in relId: The foreign table Oid. + * @in SepcifiedType: The given type of foreign table. + * @return If the relation type equal to the given type of foreign table, return true, + * otherwise return false. + */ +extern bool IsSpecifiedFDWFromRelid(Oid relId, const char* SepcifiedType); + +/** + * @Description: Jude whether type of the foreign table support SELECT/INSERT/UPDATE/DELETE/COPY + * @in relId: The foreign table Oid. + * @return Rreturn true if the foreign table support those DML. + */ +extern bool CheckSupportedFDWType(Oid relId); + +/** + * @Description: Get the all options for the OBS foreign table. + * we store the option into ObsOptions. + * @in foreignTable, the foreign table oid. + * @return return all options. + */ +extern ObsOptions* getObsOptions(Oid foreignTableId); + +/* + * brief: Creates and returns the option values to be used. + * input param @foreignTableId: Oid of the foreign tableId. + */ +HdfsFdwOptions* HdfsGetOptions(Oid foreignTableId); + +bool isSpecifiedSrvTypeFromRelId(Oid relId, const char* SepcifiedType); +bool isSpecifiedSrvTypeFromSrvName(const char* srvName, const char* SepcifiedType); + +/** + * @Description: Currently, two OBS location format support in database. + * one format is "gsobs:://obsdomain/bucket/prefix", another is "gsobs:://bucket.obsdomain/prefix". + * we adjust second format to the first format, we only deal with the first format in parse phase. + * @in optionsList, if the list include location option, we will adjust format. + * @return return new optionsList. + */ +List* regularizeObsLocationInfo(List* optionsList); + +char* rebuildAllLocationOptions(char* regionCode, char* location); + +/** + * @Description: If using the region option, we must to reset location option + * with region string, eg. obs://bucket/prefix ->obs://URL/prefix/bucket. + * @in option List tobe given. + * @return return the modified option. + */ +List* adaptOBSURL(List* list); + +/** + * @Description: Currently, two OBS location format support in database. + * one format is "gsobs:://obsdomain/bucket/prefix", another is "gsobs:://bucket.obsdomain/prefix". + * we adjust second format to the first format, we only deal with the first format in parse phase. + * @in sourceStr, if the list include location option, we will adjust format. + * @return return new location string. + */ +char* adjustObsLocationInfoOrder(char* sourceStr); + +/* + * brief: Get the value of the given option name by traversing + * foreign table and foreign server options. Return the + * value of the given option, if found. Otherwise, return NULL; + * input param @foreignTableId: Oid of the foreign tableId; + * input param @optionName: name of the option. + */ +char* HdfsGetOptionValue(Oid foreignTableId, const char* optionName); +ServerTypeOption getServerType(Oid foreignTableId); +List* getFdwOptions(Oid foreignTableId); +int getSpecialCharCnt(const char* path, const char specialChar); +ObsOptions* setObsSrvOptions(ForeignOptions* fOptions); +HdfsOptions* setHdfsSrvOptions(ForeignOptions* fOptions); + +bool isWriteOnlyFt(Oid relid); + +#define isObsOrHdfsTableFormTblOid(relId) \ + (isSpecifiedSrvTypeFromRelId(relId, HDFS) || isSpecifiedSrvTypeFromRelId(relId, OBS)) + +#define isMOTFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, MOT_FDW)) + +#define isObsOrHdfsTableFormSrvName(srvName) \ + (isSpecifiedSrvTypeFromSrvName(srvName, HDFS) || isSpecifiedSrvTypeFromSrvName(srvName, OBS)) + +#define isMOTTableFromSrvName(srvName) \ + (IsSpecifiedFDW(srvName, MOT_FDW)) + +#define isPostgresFDWFromSrvName(srvName) \ + (IsSpecifiedFDW(srvName, POSTGRES_FDW)) + +#define isMysqlFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, MYSQL_FDW)) + +#define isOracleFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, ORACLE_FDW)) + +#define isPostgresFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, POSTGRES_FDW)) + +#define IS_OBS_CSV_TXT_FOREIGN_TABLE(relId) \ + (IsSpecifiedFDWFromRelid(relId, DIST_FDW) && (is_obs_protocol(HdfsGetOptionValue(relId, optLocation)))) + +#define CAN_BUILD_INFORMATIONAL_CONSTRAINT_BY_RELID(relId) \ + (isObsOrHdfsTableFormTblOid(relId) || IS_OBS_CSV_TXT_FOREIGN_TABLE(relId)) + +#define CAN_BUILD_INFORMATIONAL_CONSTRAINT_BY_STMT(stmt) \ + (isObsOrHdfsTableFormSrvName(stmt->servername) || \ + (NULL == getFTOptionValue(stmt->options, optLocation) \ + ? false \ + : is_obs_protocol(getFTOptionValue(stmt->options, optLocation)))) + +#define IS_LOGFDW_FOREIGN_TABLE(relId) (IsSpecifiedFDWFromRelid(relId, LOG_FDW)) + +#define IS_POSTGRESFDW_FOREIGN_TABLE(relId) (IsSpecifiedFDWFromRelid(relId, GC_FDW)) + +#define ENCRYPT_STR_PREFIX "encryptstr" +#define MIN_ENCRYPTED_PASSWORD_LENGTH 54 + +#define isEncryptedPassword(passwd) \ + (strncmp(passwd, ENCRYPT_STR_PREFIX, strlen(ENCRYPT_STR_PREFIX)) == 0 && \ + strlen(passwd) >= MIN_ENCRYPTED_PASSWORD_LENGTH) + +#endif /* FOREIGN_H */ diff -uprN postgresql-hll-2.14_old/include/foreign/metainformation.h postgresql-hll-2.14/include/foreign/metainformation.h --- postgresql-hll-2.14_old/include/foreign/metainformation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/foreign/metainformation.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * metainformation.h + * support interface for pushdown metainformation. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/foreign/metainformation.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_METAINFORMATION +#define GAUSSDB_FOREIGN_METAINFORMATION + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "foreign/foreign.h" +#include "utils/hsearch.h" + +ForeignOptions* setForeignOptions(Oid relid); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/foreign/regioninfo.h postgresql-hll-2.14/include/foreign/regioninfo.h --- postgresql-hll-2.14_old/include/foreign/regioninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/foreign/regioninfo.h 2020-12-12 17:06:43.116346348 +0800 @@ -0,0 +1,24 @@ +/* --------------------------------------------------------------------------------------- + * + * regioninfo.h + * support the obs foreign table, we get the region info from + * the region_map file, and clean the region info in database. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/foreign/regioninfo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_REGIION_INFO +#define GAUSSDB_FOREIGN_REGIION_INFO + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "commands/defrem.h" +#include "nodes/parsenodes.h" + +char* readDataFromJsonFile(char* region); + +#endif diff -uprN postgresql-hll-2.14_old/include/funcapi.h postgresql-hll-2.14/include/funcapi.h --- postgresql-hll-2.14_old/include/funcapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/funcapi.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,286 @@ +/* ------------------------------------------------------------------------- + * + * funcapi.h + * Definitions for functions which return composite type and/or sets + * + * This file must be included by all Postgres modules that either define + * or call FUNCAPI-callable functions or macros. + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/funcapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FUNCAPI_H +#define FUNCAPI_H + +#include "fmgr.h" +#include "access/tupdesc.h" +#include "executor/executor.h" +#include "executor/tuptable.h" + +/* ------------------------------------------------------------------------- + * Support to ease writing Functions returning composite types + * ------------------------------------------------------------------------- + * + * This struct holds arrays of individual attribute information + * needed to create a tuple from raw C strings. It also requires + * a copy of the TupleDesc. The information carried here + * is derived from the TupleDesc, but it is stored here to + * avoid redundant cpu cycles on each call to an SRF. + */ +typedef struct AttInMetadata { + /* full TupleDesc */ + TupleDesc tupdesc; + + /* array of attribute type input function finfo */ + FmgrInfo* attinfuncs; + + /* array of attribute type i/o parameter OIDs */ + Oid* attioparams; + + /* array of attribute typmod */ + int32* atttypmods; +} AttInMetadata; + +/* ------------------------------------------------------------------------- + * Support struct to ease writing Set Returning Functions (SRFs) + * ------------------------------------------------------------------------- + * + * This struct holds function context for Set Returning Functions. + * Use fn_extra to hold a pointer to it across calls + */ +typedef struct FuncCallContext { + /* + * Number of times we've been called before + * + * call_cntr is initialized to 0 for you by SRF_FIRSTCALL_INIT(), and + * incremented for you every time SRF_RETURN_NEXT() is called. + */ + uint32 call_cntr; + + /* + * OPTIONAL maximum number of calls + * + * max_calls is here for convenience only and setting it is optional. If + * not set, you must provide alternative means to know when the function + * is done. + */ + uint32 max_calls; + + /* + * OPTIONAL pointer to result slot + * + * This is obsolete and only present for backwards compatibility, viz, + * user-defined SRFs that use the deprecated TupleDescGetSlot(). + */ + TupleTableSlot* slot; + + /* + * OPTIONAL pointer to miscellaneous user-provided context information + * + * user_fctx is for use as a pointer to your own struct to retain + * arbitrary context information between calls of your function. + */ + void* user_fctx; + + /* + * OPTIONAL pointer to struct containing attribute type input metadata + * + * attinmeta is for use when returning tuples (i.e. composite data types) + * and is not used when returning base data types. It is only needed if + * you intend to use BuildTupleFromCStrings() to create the return tuple. + */ + AttInMetadata* attinmeta; + + /* + * memory context used for structures that must live for multiple calls + * + * multi_call_memory_ctx is set by SRF_FIRSTCALL_INIT() for you, and used + * by SRF_RETURN_DONE() for cleanup. It is the most appropriate memory + * context for any memory that is to be reused across multiple calls of + * the SRF. + */ + MemoryContext multi_call_memory_ctx; + + /* + * OPTIONAL pointer to struct containing tuple description + * + * tuple_desc is for use when returning tuples (i.e. composite data types) + * and is only needed if you are going to build the tuples with + * heap_form_tuple() rather than with BuildTupleFromCStrings(). Note that + * the TupleDesc pointer stored here should usually have been run through + * BlessTupleDesc() first. + */ + TupleDesc tuple_desc; + +} FuncCallContext; + +/* ---------- + * Support to ease writing functions returning composite types + * + * External declarations: + * get_call_result_type: + * Given a function's call info record, determine the kind of datatype + * it is supposed to return. If resultTypeId isn't NULL, *resultTypeId + * receives the actual datatype OID (this is mainly useful for scalar + * result types). If resultTupleDesc isn't NULL, *resultTupleDesc + * receives a pointer to a TupleDesc when the result is of a composite + * type, or NULL when it's a scalar result or the rowtype could not be + * determined. NB: the tupledesc should be copied if it is to be + * accessed over a long period. + * get_expr_result_type: + * Given an expression node, return the same info as for + * get_call_result_type. Note: the cases in which rowtypes cannot be + * determined are different from the cases for get_call_result_type. + * get_func_result_type: + * Given only a function's OID, return the same info as for + * get_call_result_type. Note: the cases in which rowtypes cannot be + * determined are different from the cases for get_call_result_type. + * Do *not* use this if you can use one of the others. + * ---------- + */ + +/* Type categories for get_call_result_type and siblings */ +typedef enum TypeFuncClass { + TYPEFUNC_SCALAR, /* scalar result type */ + TYPEFUNC_COMPOSITE, /* determinable rowtype result */ + TYPEFUNC_RECORD, /* indeterminate rowtype result */ + TYPEFUNC_OTHER /* bogus type, eg pseudotype */ +} TypeFuncClass; + +extern TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid* resultTypeId, TupleDesc* resultTupleDesc); +extern TypeFuncClass get_expr_result_type(Node* expr, Oid* resultTypeId, TupleDesc* resultTupleDesc); +extern TypeFuncClass get_func_result_type(Oid functionId, Oid* resultTypeId, TupleDesc* resultTupleDesc); + +extern bool resolve_polymorphic_argtypes(int numargs, Oid* argtypes, const char* argmodes, Node* call_expr); + +extern int get_func_arg_info(HeapTuple procTup, Oid** p_argtypes, char*** p_argnames, char** p_argmodes); + +extern int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char*** arg_names); + +extern char* get_func_result_name(Oid functionId); + +extern TupleDesc build_function_result_tupdesc_d(Datum proallargtypes, Datum proargmodes, Datum proargnames); +extern TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple); + +/* ---------- + * Support to ease writing functions returning composite types + * + * External declarations: + * TupleDesc BlessTupleDesc(TupleDesc tupdesc) - "Bless" a completed tuple + * descriptor so that it can be used to return properly labeled tuples. + * You need to call this if you are going to use heap_form_tuple directly. + * TupleDescGetAttInMetadata does it for you, however, so no need to call + * it if you call TupleDescGetAttInMetadata. + * AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc) - Build an + * AttInMetadata struct based on the given TupleDesc. AttInMetadata can + * be used in conjunction with C strings to produce a properly formed + * tuple. + * HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) - + * build a HeapTuple given user data in C string form. values is an array + * of C strings, one for each attribute of the return tuple. + * + * Macro declarations: + * HeapTupleGetDatum(HeapTuple tuple) - convert a HeapTuple to a Datum. + * + * Obsolete routines and macros: + * TupleDesc RelationNameGetTupleDesc(const char *relname) - Use to get a + * TupleDesc based on a named relation. + * TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases) - Use to get a + * TupleDesc based on a type OID. + * TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc) - Builds a + * TupleTableSlot, which is not needed anymore. + * TupleGetDatum(TupleTableSlot *slot, HeapTuple tuple) - get a Datum + * given a tuple and a slot. + * ---------- + */ + +#define HeapTupleGetDatum(_tuple) PointerGetDatum((_tuple)->t_data) +/* obsolete version of above */ +#define TupleGetDatum(_slot, _tuple) PointerGetDatum((_tuple)->t_data) + +extern TupleDesc RelationNameGetTupleDesc(const char* relname); +extern TupleDesc TypeGetTupleDesc(Oid typeoid, List* colaliases); + +/* from execTuples.c */ +extern TupleDesc BlessTupleDesc(TupleDesc tupdesc); +extern AttInMetadata* TupleDescGetAttInMetadata(TupleDesc tupdesc); +extern HeapTuple BuildTupleFromCStrings(AttInMetadata* attinmeta, char** values); +extern TupleTableSlot* TupleDescGetSlot(TupleDesc tupdesc); + +/* ---------- + * Support for Set Returning Functions (SRFs) + * + * The basic API for SRFs looks something like: + * + * Datum + * my_Set_Returning_Function(PG_FUNCTION_ARGS) + * { + * FuncCallContext *funcctx; + * Datum result; + * MemoryContext oldcontext; + * + * + * if (SRF_IS_FIRSTCALL()) + * { + * funcctx = SRF_FIRSTCALL_INIT(); + * // switch context when allocating stuff to be used in later calls + * oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + * + * + * + * + * + * // return to original context when allocating transient memory + * MemoryContextSwitchTo(oldcontext); + * } + * + * funcctx = SRF_PERCALL_SETUP(); + * + * + * if (funcctx->call_cntr < funcctx->max_calls) + * { + * + * + * SRF_RETURN_NEXT(funcctx, result); + * } + * else + * SRF_RETURN_DONE(funcctx); + * } + * + * ---------- + */ + +/* from funcapi.c */ +extern FuncCallContext* init_MultiFuncCall(PG_FUNCTION_ARGS); +extern FuncCallContext* per_MultiFuncCall(PG_FUNCTION_ARGS); +extern void end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext* funcctx); + +#define SRF_IS_FIRSTCALL() (fcinfo->flinfo->fn_extra == NULL) + +#define SRF_FIRSTCALL_INIT() init_MultiFuncCall(fcinfo) + +#define SRF_PERCALL_SETUP() per_MultiFuncCall(fcinfo) + +#define SRF_RETURN_NEXT(_funcctx, _result) \ + do { \ + ReturnSetInfo* rsi; \ + (_funcctx)->call_cntr++; \ + rsi = (ReturnSetInfo*)fcinfo->resultinfo; \ + rsi->isDone = ExprMultipleResult; \ + PG_RETURN_DATUM(_result); \ + } while (0) + +#define SRF_RETURN_DONE(_funcctx) \ + do { \ + ReturnSetInfo* rsi; \ + end_MultiFuncCall(fcinfo, _funcctx); \ + rsi = (ReturnSetInfo*)fcinfo->resultinfo; \ + rsi->isDone = ExprEndResult; \ + PG_RETURN_NULL(); \ + } while (0) + +#endif /* FUNCAPI_H */ diff -uprN postgresql-hll-2.14_old/include/gaussdb_version.h postgresql-hll-2.14/include/gaussdb_version.h --- postgresql-hll-2.14_old/include/gaussdb_version.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gaussdb_version.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,65 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gaussdb_version.h + * Definitions for the Gaussdb features check + * + * + * IDENTIFICATION + * src/include/gaussdb_version.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GAUSSDB_VERSION_H_INCLUDED +#define GAUSSDB_VERSION_H_INCLUDED + +typedef enum { + MULTI_VALUE_COLUMN = 0, + JSON, + XML, + DATA_STORAGE_FORMAT, + GTM_FREE, + DOUBLE_LIVE_DISASTER_RECOVERY_IN_THE_SAME_CITY, + DISASTER_RECOVERY_IN_TWO_PLACES_AND_THREE_CENTRES, + GPU_ACCELERATION_IN_MULTIDIMENSIONAL_COLLISION_ANALYSIS, + FULL_TEXT_INDEX, + EXTENSION_CONNECTOR, + SQL_ON_HDFS, + SQL_ON_OBS, + EXPRESS_CLUSTER, + CROSS_DC_COLLABORATION, + GRAPH_COMPUTING_ENGINE, + SEQUENTIAL_DATA_ENGINE, + POSTGIS_DOCKING, + HA_SINGLE_PRIMARY_MULTI_STANDBY, + ROW_LEVEL_SECURITY, + TRANSPARENT_ENCRYPTION, + PRIVATE_TABLE, + FEATURE_NAME_MAX_VALUE // Must be the last one +} feature_name; + +/* Product version number is unknown. */ +#define PRODUCT_VERSION_UNKNOWN ((uint32)0) +/* GaussDB 200 product version number. */ +#define PRODUCT_VERSION_GAUSSDB200 ((uint32)2) +/* GaussDB 300 product version number. */ +#define PRODUCT_VERSION_GAUSSDB300 ((uint32)3) + +extern void initialize_feature_flags(); +extern bool is_feature_disabled(feature_name); +extern void signalReloadLicenseHandler(int sig); +extern uint32 get_product_version(); +#endif // GAUSSDB_VERSION_H_INCLUDED diff -uprN postgresql-hll-2.14_old/include/gen_alloc.h postgresql-hll-2.14/include/gen_alloc.h --- postgresql-hll-2.14_old/include/gen_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gen_alloc.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * gen_alloc.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gen_alloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GEN_ALLOC_H +#define GEN_ALLOC_H + +/* + * Common memory allocation binary interface both for Postgres and GTM processes. + * Especially needed by gtm_serialize.c and gtm_serialize_debug.c + */ +typedef struct Gen_Alloc { + void* (*alloc)(void*, size_t); + void* (*alloc0)(void*, size_t); + void* (*realloc)(void*, size_t); + void (*free)(void*); + void* (*current_memcontext)(void); + void* (*allocTop)(size_t); +} Gen_Alloc; + +extern Gen_Alloc genAlloc_class; + +#define genAlloc(x) genAlloc_class.alloc(genAlloc_class.current_memcontext(), x) +#define genRealloc(x, y) genAlloc_class.realloc(x, y) +#define genFree(x) genAlloc_class.free(x) +#define genAlloc0(x) genAlloc_class.alloc0(genAlloc_class.current_memcontext(), x) +#define genAllocTop(x) genAlloc_class.allocTop(x) + +#endif /* GEN_ALLOC_H */ + diff -uprN postgresql-hll-2.14_old/include/getaddrinfo.h postgresql-hll-2.14/include/getaddrinfo.h --- postgresql-hll-2.14_old/include/getaddrinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/getaddrinfo.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------------- + * + * getaddrinfo.h + * Support getaddrinfo() on platforms that don't have it. + * + * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO, + * whether or not the library routine getaddrinfo() can be found. This + * policy is needed because on some platforms a manually installed libbind.a + * may provide getaddrinfo(), yet the system headers may not provide the + * struct definitions needed to call it. To avoid conflict with the libbind + * definition in such cases, we rename our routines to pg_xxx() via macros. + * + * This code will also work on platforms where struct addrinfo is defined + * in the system headers but no getaddrinfo() can be located. + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/getaddrinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GETADDRINFO_H +#define GETADDRINFO_H + +#include +#include + +/* Various macros that ought to be in , but might not be */ + +#ifndef EAI_FAIL +#ifndef WIN32 +#define EAI_BADFLAGS (-1) +#define EAI_NONAME (-2) +#define EAI_AGAIN (-3) +#define EAI_FAIL (-4) +#define EAI_FAMILY (-6) +#define EAI_SOCKTYPE (-7) +#define EAI_SERVICE (-8) +#define EAI_MEMORY (-10) +#define EAI_SYSTEM (-11) +#else /* WIN32 */ +#ifdef WIN32_ONLY_COMPILER +#ifndef WSA_NOT_ENOUGH_MEMORY +#define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS) +#endif +#ifndef __BORLANDC__ +#define WSATYPE_NOT_FOUND (WSABASEERR + 109) +#endif +#endif +#define EAI_AGAIN WSATRY_AGAIN +#define EAI_BADFLAGS WSAEINVAL +#define EAI_FAIL WSANO_RECOVERY +#define EAI_FAMILY WSAEAFNOSUPPORT +#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY +#define EAI_NODATA WSANO_DATA +#define EAI_NONAME WSAHOST_NOT_FOUND +#define EAI_SERVICE WSATYPE_NOT_FOUND +#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT +#endif /* !WIN32 */ +#endif /* !EAI_FAIL */ + +#ifndef AI_PASSIVE +#define AI_PASSIVE 0x0001 +#endif + +#ifndef AI_NUMERICHOST +/* + * some platforms don't support AI_NUMERICHOST; define as zero if using + * the system version of getaddrinfo... + */ +#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) +#define AI_NUMERICHOST 0 +#else +#define AI_NUMERICHOST 0x0004 +#endif +#endif + +#ifndef NI_NUMERICHOST +#define NI_NUMERICHOST 1 +#endif +#ifndef NI_NUMERICSERV +#define NI_NUMERICSERV 2 +#endif + +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif + +#ifndef NI_MAXSERV +#define NI_MAXSERV 32 +#endif + +#ifndef HAVE_STRUCT_ADDRINFO + +#ifndef WIN32 +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr* ai_addr; + char* ai_canonname; + struct addrinfo* ai_next; +}; +#else +/* + * The order of the structure elements on Win32 doesn't match the + * order specified in the standard, but we have to match it for + * IPv6 to work. + */ +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + char* ai_canonname; + struct sockaddr* ai_addr; + struct addrinfo* ai_next; +}; +#endif +#endif /* HAVE_STRUCT_ADDRINFO */ + +#ifndef HAVE_GETADDRINFO + +/* Rename private copies per comments above */ +#ifdef getaddrinfo +#undef getaddrinfo +#endif +#define getaddrinfo pg_getaddrinfo + +#ifdef freeaddrinfo +#undef freeaddrinfo +#endif +#define freeaddrinfo pg_freeaddrinfo + +#ifdef gai_strerror +#undef gai_strerror +#endif +#define gai_strerror pg_gai_strerror + +#ifdef getnameinfo +#undef getnameinfo +#endif +#define getnameinfo pg_getnameinfo + +extern int getaddrinfo(const char* node, const char* service, const struct addrinfo* hints, struct addrinfo** res); +extern void freeaddrinfo(struct addrinfo* res); +extern const char* gai_strerror(int errcode); +extern int getnameinfo( + const struct sockaddr* sa, int salen, char* node, int nodelen, char* service, int servicelen, int flags); +#endif /* HAVE_GETADDRINFO */ + +#endif /* GETADDRINFO_H */ diff -uprN postgresql-hll-2.14_old/include/getopt_long.h postgresql-hll-2.14/include/getopt_long.h --- postgresql-hll-2.14_old/include/getopt_long.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/getopt_long.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,41 @@ +/* + * Portions Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Portions Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/getopt_long.h + */ +#ifndef GETOPT_LONG_H +#define GETOPT_LONG_H + +#ifdef HAVE_GETOPT_H +#include +#endif + +/* These are picked up from the system's getopt() facility. */ +extern int opterr; +extern int optind; +extern int optopt; +extern char* optarg; + +#ifndef HAVE_STRUCT_OPTION + +struct option { + const char* name; + int has_arg; + int* flag; + int val; +}; + +#define no_argument 0 +#define required_argument 1 +#endif + +#ifndef HAVE_GETOPT_LONG + +extern int getopt_long( + int argc, char* const argv[], const char* optstring, const struct option* longopts, int* longindex); +#endif + +#endif /* GETOPT_LONG_H */ diff -uprN postgresql-hll-2.14_old/include/gs_bbox.h postgresql-hll-2.14/include/gs_bbox.h --- postgresql-hll-2.14_old/include/gs_bbox.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_bbox.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,128 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_bbox.h + * + * IDENTIFICATION + * src/include/gs_bbox.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_BBOX_H__ +#define __GS_BBOX_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "utils/guc.h" + +/* + * all kinds of blacklist items. + * + * NOTE: at most 64 different blacklist items are supported now. We can enlarge this upper limits + * by changing g_instance.attr.attr_common.bbox_blacklist_mask from uint64 to Bitmap. + */ +typedef enum { + SHARED_BUFFER = 0, + XLOG_BUFFER, + DW_BUFFER, + XLOG_MESSAGE_SEND, + DATA_MESSAGE_SEND, + WALRECIVER_CTL_BLOCK, + DATA_WRITER_QUEUE +} BlacklistIndex; + +/* blacklist item */ +typedef struct { + /* blacklist item's ID */ + BlacklistIndex blacklist_ID; + + /* blacklist item's name */ + char *blacklist_name; + + /* whether or not only added by postmaster. */ + bool pm_only; +} BlacklistItem; + +/* all information about blacklist items. */ +extern BlacklistItem g_blacklist_items[]; + +/* whether or not bbox is enabled. */ +#define BBOX_ENABLED (u_sess->attr.attr_common.enable_bbox_dump) + +/* fetch instance's blacklist items' mask. */ +#define BBOX_BLACKLIST (g_instance.attr.attr_common.bbox_blacklist_mask) + +/* fetch one blacklist item's bits mask by ID (internal) */ +#define BLACKLIST_ITEM_MASK(blacklist_ID) ((uint64)1 << (unsigned int)(blacklist_ID)) + +/* t_thrd.storage_cxt.BufferBlocks */ +#define BBOX_BLACKLIST_SHARE_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(SHARED_BUFFER))) + +/* t_thrd.shemem_ptr_cxt.XLogCtl->pages */ +#define BBOX_BLACKLIST_XLOG_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(XLOG_BUFFER))) + +/* g_instance.dw_batch_cxt.buf */ +#define BBOX_BLACKLIST_DW_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DW_BUFFER))) + +/* t_thrd.walsender_cxt.output_xlog_message*/ +#define BBOX_BLACKLIST_XLOG_MESSAGE_SEND (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(XLOG_MESSAGE_SEND))) + +/* t_thrd.datasender_cxt.output_message */ +#define BBOX_BLACKLIST_DATA_MESSAGE_SEND (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DATA_MESSAGE_SEND))) + +/* t_thrd.walreceiver_cxt.walRcvCtlBlock */ +#define BBOX_BLACKLIST_WALREC_CTL_BLOCK (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(WALRECIVER_CTL_BLOCK))) + +/*t_thrd.dataqueue_cxt.DataWriterQueue*/ +#define BBOX_BLACKLIST_DATA_WRITER_QUEUE (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DATA_WRITER_QUEUE))) + +// t_thrd.walsender_cxt.output_data_message, LogicalDecodingContext + +// t_thrd.libwalreceiver_cxt.recvBuf (malloc each time) +// t_thrd.datareceiver_cxt.recvBuf +// XLogReaderState->readbuf + +#ifdef ENABLE_UT +#include "../gausskernel/cbb/bbox/bbox.h" +extern int bbox_handler_exit; +extern void bbox_handler(SIGNAL_ARGS); +extern s32 BBOX_CreateCoredump(char* file_name); +#endif + +/* do initilaization for dumping core file */ +extern void bbox_initialize(); + +/* add an blacklist item to exclude it from core file. */ +extern void bbox_blacklist_add(BlacklistIndex item, void *addr, uint64 size); + +/* remove an blacklist item. */ +extern void bbox_blacklist_remove(BlacklistIndex item, void *addr); + +/* for GUC parameter - bbox_dump_path */ +extern bool check_bbox_corepath(char** newval, void** extra, GucSource source); +extern void assign_bbox_corepath(const char* newval, void* extra); +extern const char* show_bbox_dump_path(void); + +/* for GUC parameter - bbox_blanklist_items */ +extern bool check_bbox_blacklist(char** newval, void** extra, GucSource source); +extern void assign_bbox_blacklist(const char* newval, void* extra); +extern const char* show_bbox_blacklist(); + +/* for GUC parameter - enable_bbox_dump */ +extern void assign_bbox_coredump(const bool newval, void* extra); +extern int CheckFilenameValid(const char* inputEnvValue); +#endif + diff -uprN postgresql-hll-2.14_old/include/gs_ktool/kt_interface.h postgresql-hll-2.14/include/gs_ktool/kt_interface.h --- postgresql-hll-2.14_old/include/gs_ktool/kt_interface.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_ktool/kt_interface.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + *------------------------------------------------------------------------- + * + * kt_interface.cpp + * APIs for Encrypted Database. + * + * IDENTIFICATION + * src/bin/gs_ktool/kt_interface.cpp + * + *------------------------------------------------------------------------- + */ + +#ifndef KT_INTERFACE_H +#define KT_INTERFACE_H + +#include +#include +#include + +extern bool get_cmk_len(unsigned int cmk_id, unsigned int *cmk_len); +extern bool get_cmk_plain(unsigned int cmk_id, unsigned char *cmk_plain_buffer, unsigned int *cmk_len); + +#endif diff -uprN postgresql-hll-2.14_old/include/gs_policy/curl_utils.h postgresql-hll-2.14/include/gs_policy/curl_utils.h --- postgresql-hll-2.14_old/include/gs_policy/curl_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/curl_utils.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * CurlUtils.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/gs_policy/CurlUtils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SRC_LIBS_LIBCURL_CURLUTILS_H_ +#define SRC_LIBS_LIBCURL_CURLUTILS_H_ + +#include +#include +#include "curl/curl.h" + +class CurlUtils +{ +public: + CurlUtils(); + ~CurlUtils(); + void initialize(bool withSSL, const std::string certificate, const std::string user, const std::string password); + bool http_post_file_request(const std::string url, const std::string fileName, bool connection_testing = false); +private: + bool m_withSSL; + std::string m_certificate; + std::string m_user; + std::string m_password; + CURL* m_curlForPost; +}; + +#endif /* SRC_LIBS_LIBCURL_CURLUTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/gs_policy_audit.h postgresql-hll-2.14/include/gs_policy/gs_policy_audit.h --- postgresql-hll-2.14_old/include/gs_policy/gs_policy_audit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/gs_policy_audit.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,54 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Main enterance for Auditing Policy + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy_audit.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_POLICY_AUDIT_H +#define GS_POLICY_AUDIT_H + +#include "access/xact.h" +#include "access/heapam.h" +#include "access/genam.h" +#include "access/sysattr.h" +#include "catalog/pg_proc.h" +#include "catalog/indexing.h" + +#include "gs_policy/gs_string.h" +#include "gs_policy/policy_set.h" +#include "nodes/parsenodes.h" +#include "postgres.h" +#include "storage/lock.h" +#include "utils/builtins.h" +#include "utils/timestamp.h" +#include "utils/fmgroids.h" +#include "utils/snapmgr.h" +#include "utils/lsyscache.h" +#include "utils/syscache.h" + +extern void create_audit_policy(CreateAuditPolicyStmt *stmt); +extern void alter_audit_policy(AlterAuditPolicyStmt *stmt); +extern void drop_audit_policy(DropAuditPolicyStmt *stmt); +void construct_resource_name(const RangeVar *rel, gs_stl::gs_string *target_name_s); + +#endif + diff -uprN postgresql-hll-2.14_old/include/gs_policy/gs_policy_masking.h postgresql-hll-2.14/include/gs_policy/gs_policy_masking.h --- postgresql-hll-2.14_old/include/gs_policy/gs_policy_masking.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/gs_policy_masking.h 2020-12-12 17:06:43.117346361 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_policy_masking.h + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy_masking.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_POLICY_MASKING_H +#define _PG_POLICY_MASKING_H + +#include "postgres.h" +#include "nodes/parsenodes.h" + +extern void create_masking_policy(CreateMaskingPolicyStmt *stmt); + +extern void alter_masking_policy(AlterMaskingPolicyStmt *stmt); + +extern void drop_masking_policy(DropMaskingPolicyStmt *stmt); + +extern bool is_masked_relation(Oid relid); + +#endif + diff -uprN postgresql-hll-2.14_old/include/gs_policy/gs_policy_utils.h postgresql-hll-2.14/include/gs_policy/gs_policy_utils.h --- postgresql-hll-2.14_old/include/gs_policy/gs_policy_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/gs_policy_utils.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,332 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Declaration of functions for dealing with policy records + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _GS_POLICY_UTILS_H +#define _GS_POLICY_UTILS_H + +#include "access/heapam.h" +#include "access/tableam.h" +#include "nodes/parsenodes.h" +#include "policy_common.h" +#include "policy_set.h" +#include "gs_vector.h" +#include "policy_map.h" +#include "postgres.h" +#include "pgaudit.h" +#include "utils/snapmgr.h" + +#define MAX_POLICIES_NUM 98 +#define MAX_IP_LEN 129 + +enum {POLICY_OPT_UNKNOWN, POLICY_OPT_PRIVILEGES, POLICY_OPT_ACCESS, POLICY_OPT_FILTER, POLICY_OPT_BLOCK}; + +static inline int get_option_type(const char *option_type) +{ + if (!strcasecmp(option_type, "privileges")) { + return POLICY_OPT_PRIVILEGES; + } + if (!strcasecmp(option_type, "access")) + return POLICY_OPT_ACCESS; + if (!strcasecmp(option_type, "filter")) + return POLICY_OPT_FILTER; + + return POLICY_OPT_UNKNOWN; +} + +enum {POLICY_CMD_UNKNOWN, POLICY_CMD_ADD, POLICY_CMD_REMOVE, POLICY_CMD_MODIFY, POLICY_CMD_DROP_FILTER}; + +static inline int get_policy_command_type(const char *command) +{ + if (!strcasecmp(command, "add")) { + return POLICY_CMD_ADD; + } + if (!strcasecmp(command, "remove")) { + return POLICY_CMD_REMOVE; + } + if (!strcasecmp(command, "modify")) { + return POLICY_CMD_MODIFY; + } + if (!strcasecmp(command, "drop_filter")) { + return POLICY_CMD_DROP_FILTER; + } + return POLICY_CMD_UNKNOWN; +} + +struct GsPolicyStruct { + GsPolicyStruct(const gs_stl::gs_string name = ""):m_id(0), m_name(name), m_enabled(false){} + bool operator < (const GsPolicyStruct arg) const; + long long m_id; + gs_stl::gs_string m_name; + gs_stl::gs_string m_comments; + bool m_enabled; +}; + +/* set of existing policies keyed by name */ +typedef policy_memory::pg_set policies_set; + +struct PgPolicyFiltersStruct { + bool operator < (const PgPolicyFiltersStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_label_name; + gs_stl::gs_string m_tree_string; + long long m_policy_oid; +}; + +/* set of existing filters keyed by type & label name */ +typedef policy_memory::pg_set filters_set; + +struct PgPolicyMaskingActionStruct { + bool operator < (const PgPolicyMaskingActionStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_params; + gs_stl::gs_string m_label_name; + long long m_policy_oid; +}; +typedef policy_memory::pg_set masking_actions_set; + +struct PgPolicyPrivilegesAccessStruct { + PgPolicyPrivilegesAccessStruct() : m_id(0), m_type(""), m_label_name(""), m_policy_oid(0) {} + bool operator < (const PgPolicyPrivilegesAccessStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_label_name; + long long m_policy_oid; +}; + +/* set of existing privileges keyed by type & label name */ +typedef policy_memory::pg_set + privileges_access_set; + +template +extern void load_existing_policies(Relation rel, policies_set *existing_policies) +{ + if (rel == nullptr) + return; + HeapTuple rtup; + T rel_data; + GsPolicyStruct item; + TableScanDesc scan = tableam_scan_begin(rel, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + item.m_id = HeapTupleGetOid(rtup); + item.m_name = rel_data->polname.data; + item.m_enabled = rel_data->polenabled; + existing_policies->insert(item); + } + tableam_scan_end(scan); +} + +template +extern size_t get_num_of_existing_policies(Relation rel) +{ + size_t amount = 0; + if (rel == nullptr) + return amount; + HeapTuple rtup; + T rel_data; + TableScanDesc scan = heap_beginscan(rel, SnapshotNow, 0, NULL); + while (scan && (rtup = heap_getnext(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + amount++; + } + heap_endscan(scan); + return amount; +} + +template +void drop_policy_by_name(unsigned int rel_oid, const char *polname, + policy_memory::pg_set *ids) +{ + Relation relation = heap_open(rel_oid, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + T rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + if (!strcasecmp(polname, rel_data->polname.data)) { + ids->insert(HeapTupleGetOid(rtup)); + simple_heap_delete(relation, &rtup->t_self); + } + } + tableam_scan_end(scan); + + heap_close(relation, RowExclusiveLock); +} + +template +void drop_policy_reference(unsigned int rel_oid, long long policy_oid) +{ + Relation relation = heap_open(rel_oid, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + T rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + if ((long long)rel_data->policyoid == policy_oid) { + simple_heap_delete(relation, &rtup->t_self); + } + } + tableam_scan_end(scan); + + heap_close(relation, RowExclusiveLock); +} + +template +void load_existing_filters(Relation relation, filters_set *fltrs, long long policy_oid = 0) +{ + if (!relation) + return; + HeapTuple rtup; + T rel_data; + PgPolicyFiltersStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->filtertype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* when policy_oid is zero - load all privileges + * when policy_oid greater than zero, load only matching + */ + if ((policy_oid == 0) || ((policy_oid > 0) && (item.m_policy_oid == policy_oid))) + fltrs->insert(item); + } + tableam_scan_end(scan); +} + +template +void load_existing_privileges(int relationId, privileges_access_set *privs, long long policy_oid = 0) +{ + Relation relation = heap_open(relationId, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + T rel_data; + PgPolicyPrivilegesAccessStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->privilegetype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* load only matching privileges to policy id */ + if (item.m_policy_oid == policy_oid) { + privs->insert(item); + } + } + tableam_scan_end(scan); + heap_close(relation, RowExclusiveLock); +} + +template +void load_existing_access(int relationId, privileges_access_set *acc, long long policy_oid = 0) +{ + Relation relation = heap_open(relationId, RowExclusiveLock); + if (!relation) { + return; + } + HeapTuple rtup; + T rel_data; + PgPolicyPrivilegesAccessStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->accesstype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* load only matching access to policy id */ + if (item.m_policy_oid == policy_oid) { + acc->insert(item); + } + } + tableam_scan_end(scan); + heap_close(relation, RowExclusiveLock); +} + +/* Process new filters from parser tree and tranform them into string */ +extern bool process_new_filters(const List *policy_filters, gs_stl::gs_string *flat_tree); + +extern bool verify_ip_role_app(const char *obj_type, const char *obj_value, gs_stl::gs_string *return_value); + +/* Parses & validates (recursively) polish-notation format string into logical tree; on error uses ereport() */ +extern bool validate_logical_expression(const gs_stl::gs_string logical_expr_str, int *offset); + +extern bool scan_to_delete_from_relation(long long row_id, Relation relation, unsigned int index_id); + +extern bool remove_filters(const filters_set filters_to_remove, Relation relation, filters_set *existing_filters, + unsigned int index_id, gs_stl::gs_string *err_msg); + +extern bool remove_filters(const filters_set filters_to_remove, unsigned int relation_id, unsigned int index_id, + gs_stl::gs_string *err_msg); + +extern void construct_resource_name(const RangeVar *rel, gs_stl::gs_string *target_name_s); + +bool handle_target(ListCell *target, + int opt_type, + bool is_add, + gs_stl::gs_string *err_msg, + privileges_access_set *access_to_add, privileges_access_set *access_to_remove, + privileges_access_set *privs_to_add, privileges_access_set *privs_to_remove, + const policy_labels_map *existing_labels, + const GsPolicyStruct *policy, const char *acc_action_type); + +void save_manage_message(const char *message); +void send_manage_message(AuditResult result_type); + +extern void get_session_ip(char *session_ip, int len); +extern void get_client_ip(const struct sockaddr* remote_addr, char *ip_str); + +bool is_database_valid(const char* dbname); + +/* create and release temp resource owner should use together to solve the empty owner of table */ +ResourceOwnerData* create_temp_resourceowner(); +void release_temp_resourceowner(ResourceOwnerData* resource_owner); + +#endif diff -uprN postgresql-hll-2.14_old/include/gs_policy/gs_string.h postgresql-hll-2.14/include/gs_policy/gs_string.h --- postgresql-hll-2.14_old/include/gs_policy/gs_string.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/gs_string.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_string.h + * Containers common parts and string declare + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_string.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INCLUDE_UTILS_GS_STRING_H_ +#define INCLUDE_UTILS_GS_STRING_H_ + +#include "c.h" +#include "utils/palloc.h" +#include "utils/memutils.h" +#include + +namespace gs_stl { + /* vector memory */ + MemoryContext GetVectorMemory(); + void DeleteVectorMemory(); + /* string memory */ + void DeleteStringMemory(); + + class gs_string { + public: + static const size_t npos = -1; + gs_string(const char *str = "", size_t len = 0); + ~gs_string(); + gs_string(const gs_string &arg); + gs_string &operator =(const gs_string &arg); + bool operator ==(const gs_string &arg) const; + bool operator <(const gs_string &arg) const; + const char *c_str() const + { + return m_buff; + } + size_t size() const + { + return m_len; + } + size_t capacity() const + { + return m_capacity; + } + bool empty() const + { + return !size(); + } + gs_string &append(const char *str, size_t len = 0); + gs_string &append(const gs_string &str); + void push_back(char ch); + void pop_back(); + char operator[](int idx) const; + void clear(); + size_t find(char arg, size_t start = 0) const; + char back() const; + gs_string substr(size_t pos, size_t len) const; + gs_string &replace(size_t pos, size_t len, const char *s); + void erase(size_t pos, size_t len); + private: + inline char *AllocFunc(size_t _size) const; + inline char *ReallocFunc(size_t _size); + inline bool InitBuff(const char *str, size_t len = 0); + char *m_buff; + size_t m_len; + size_t m_capacity; + }; +} + +#endif /* INCLUDE_UTILS_GS_STRING_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/gs_vector.h postgresql-hll-2.14/include/gs_policy/gs_vector.h --- postgresql-hll-2.14_old/include/gs_policy/gs_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/gs_vector.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,329 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_vector.h + * vector declare and implementation. + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INCLUDE_UTILS_GS_VECTOR_H_ +#define INCLUDE_UTILS_GS_VECTOR_H_ + +#include "gs_string.h" + + +namespace gs_stl { +#define MIN_VECTOR_CAPACITY 16 + template + class gs_vector { + public: + typedef T *iterator; + typedef const T * const_iterator; + + gs_vector(size_t size = 1):m_buff(nullptr), m_len(0), m_capacity(0) + { + m_capacity = Max(size, MIN_VECTOR_CAPACITY); + InitBuff(); + } + + ~gs_vector() + { + if ((m_buff) != NULL && (t_thrd.port_cxt.thread_is_exiting == false)) { + Assert(t_thrd.top_mem_cxt != NULL); + for (size_t i = 0; i < m_len; ++i) { + m_buff[i].~T(); + } + pfree(m_buff); + m_buff = nullptr; + } + } + + gs_vector(const gs_vector &arg):m_buff(nullptr), m_len(0), m_capacity(0) + { + operator =(arg); + } + + gs_vector &operator =(const gs_vector &arg) + { + if (arg.size() > 0) { + if (m_buff != NULL) { + clear(); + pfree(m_buff); + } + m_len = m_capacity = arg.size(); + m_buff = (T*)AllocFunc(sizeof(T) * m_capacity); + for (size_t i = 0; i < m_len; ++i) { + m_buff[i] = arg.m_buff[i]; + } + } else if (m_buff == NULL) { + m_len = 0; + m_capacity = MIN_VECTOR_CAPACITY; + InitBuff(); + } + return *this; + } + + size_t size() const + { + return m_len; + } + + size_t capacity() const + { + return m_capacity; + } + + bool empty() const + { + return !size(); + } + + void insert(iterator it, const T &arg) + { + if ((m_len + 1) >= m_capacity) { + ReallocFunc(); + } + size_t moved_len = m_len - (it - begin()); + size_t remain_len = m_capacity - (it - begin()) - 1; + errno_t rc = memmove_s((void*)(it + 1), remain_len * sizeof(T), (const void*)it, moved_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + new(static_cast(it))T(arg); + ++m_len; + } + + void insert(const_iterator it, const_iterator eit) + { + for (; it != eit; ++it) { + push_back(*it); + } + } + + /* add an element into the vector (at end) */ + void push_back(const T& arg) + { + if ((m_len + 1) >= m_capacity) { + ReallocFunc(); + } + if (is_sorted) { + if (find(arg) != end()) { + return; + } + for (size_t i = 0; i < m_len; ++i) { + if (m_buff[i] < arg) { + iterator it(m_buff + i); + errno_t rc = memmove_s((void*)(it + 1), (m_capacity - i - 1) * sizeof(T), + (const void*)it, (m_len - i) * sizeof(T)); + securec_check(rc, "\0", "\0"); + new(static_cast(m_buff + i))T(arg); + ++m_len; + return; + } + } + } + + new(static_cast(m_buff + m_len))T(arg); + ++m_len; + } + + /* Return the first item */ + T &front() + { + return m_buff[0]; + } + + /* return the last item */ + T &back() + { + if (m_len > 0) { + return m_buff[m_len - 1]; + } + return m_buff[0]; + } + + const_iterator find(const T &arg) const + { + if (is_sorted) { + if (m_len < 10) { + for (size_t i = 0; i < m_len; ++i) { + if (m_buff[i] < arg) { + return end(); + } + if (arg < m_buff[i]) { + continue; + } + return const_iterator(m_buff + i); + } + } else { + return binary_search(arg); + } + } else { + Assert(false); + } + return end(); + } + + bool has_intersect(const gs_vector &arg) const + { + iterator it = begin(); + iterator eit = end(); + for (; it != eit; ++it) { + if (arg.find(*it) != arg.end()) { + return true; + } + } + return false; + } + + void pop_front() + { + if (m_len > 0) { + --m_len; + m_buff[0].~T(); + if (m_len > 0) { + errno_t rc = memmove_s((void*)m_buff, m_capacity * sizeof(T), + (const void*)(m_buff + 1), m_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + } + } + } + + void pop_back() + { + if (m_len > 0) { + --m_len; + m_buff[m_len].~T(); + } + } + + T &operator[](size_t idx) + { + if (idx < m_len) { + return m_buff[idx]; + } + Assert(false); + return m_buff[0]; + } + + const T &operator[](size_t idx) const + { + if (idx < m_len) { + return m_buff[idx]; + } + Assert(false); + return m_buff[0]; + } + + void clear() + { + for (size_t i = 0; i < m_len; ++i) { + m_buff[i].~T(); + } + m_len = 0; + } + + void swap(gs_vector& arg) + { + m_len = arg.size(); + m_capacity = arg.capacity(); + std::swap(arg.m_buff, m_buff); + } + + iterator begin() + { + return iterator(m_buff); + } + + iterator end() + { + return iterator(m_buff + m_len); + } + + const iterator begin() const + { + return iterator(m_buff); + } + + const iterator end() const + { + return iterator(m_buff + m_len); + } + private: + + const_iterator binary_search(const T& arg) const + { + size_t start = 0; + size_t mid = m_len / 2; + size_t up = m_len; + while (start < up) { + if (m_buff[start] < arg) { + return end(); + } + if (arg < m_buff[start]) { + ++start; + if (start == m_len) { + return end(); + } + if (m_buff[mid] < arg) { + start = mid + 1; + mid = (up - start) / 2; + } else if (arg < m_buff[mid]) { + up = mid - 1; + mid = (up - start) / 2; + } else { + return const_iterator(m_buff + mid); + } + } else { + return const_iterator(m_buff + start); + } + } + return end(); + } + + inline bool InitBuff() + { + if (m_buff == NULL && m_capacity > 0) { + m_buff = (T*)AllocFunc(sizeof(T) * m_capacity); + return true; + } + return false; + } + inline void *AllocFunc(size_t _size) + { + return MemoryContextAllocZero(GetVectorMemory(), _size); + } + + inline void ReallocFunc() + { + m_capacity += MIN_VECTOR_CAPACITY; + /* allocate a new array */ + T *buff = (T*)AllocFunc(sizeof(T) * m_capacity); + /* copy old data */ + errno_t rc = memcpy_s((void*)buff, sizeof(T) * m_capacity, (void*)m_buff, m_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + pfree(m_buff); + m_buff = buff; + } + T *m_buff; + size_t m_len; + size_t m_capacity; + }; +} + +#endif /* INCLUDE_UTILS_GS_VECTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/policy_common.h postgresql-hll-2.14/include/gs_policy/policy_common.h --- postgresql-hll-2.14_old/include/gs_policy/policy_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/policy_common.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_common.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_common.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _GS_POLICY_COMMON_H +#define _GS_POLICY_COMMON_H +#include "nodes/parsenodes.h" + +#include "postgres.h" +#include "policy_map.h" +#include "gs_vector.h" +#include "pgaudit.h" + +struct GsPolicyFQDN { + GsPolicyFQDN():m_value_schema(0), m_value_object(0), is_function(false){} + Oid m_value_schema; /* schema */ + Oid m_value_object; /* table */ + gs_stl::gs_string m_value_object_attrib; /* column */ + bool is_function; +}; + +struct GsPolicyLabel { + bool operator < (const GsPolicyLabel& arg) const; + long long m_id; + gs_stl::gs_string m_name; + gs_stl::gs_string m_type; + gs_stl::gs_string m_data_value; + GsPolicyFQDN m_data_value_fqdn; + gs_stl::gs_string m_data_type; +}; + +struct GsPolicyLabelKey { + gs_stl::gs_string m_name; + gs_stl::gs_string m_type; +}; + +typedef policy_memory::pg_set policy_labelname_set; +typedef policy_memory::pg_unordered_set policy_oid_set; + +/* set of existing labels keyed by data type and data value */ +typedef policy_memory::pg_set policy_labels_set; +/* map of existing labels - key: label name, value: set of labels keyed by resource type & name. */ +typedef policy_memory::pg_unordered_map policy_labels_map; +/* set of tables fqdn contained in label */ +typedef policy_memory::pg_unordered_set policy_label_tables_set; + +extern void create_policy_label(CreatePolicyLabelStmt *stmt); +extern void load_existing_labels(Relation rel, policy_labels_map *existing_labels); +extern void alter_policy_label(AlterPolicyLabelStmt *stmt); +extern void drop_policy_label(DropPolicyLabelStmt *stmt); +extern bool VerifyLabelHasColumn(RangeVar *rel, GsPolicyFQDN *fqdn, + const policy_memory::pg_set *labels); + +typedef bool(*ValidateBehaviourPtr)(const char *func_name); +extern PGDLLIMPORT ValidateBehaviourPtr validate_masking_behaviour_hook; + +typedef bool (*LoadLabelsPtr)(bool); +extern PGDLLIMPORT LoadLabelsPtr load_labels_hook; + +typedef bool (*IsLabelsHasBoundObjectPtr)(const GsPolicyFQDN*, + const policy_memory::pg_set*, + bool (*CheckLabelBoundPolicy)(bool, const gs_stl::gs_string)); +extern PGDLLIMPORT IsLabelsHasBoundObjectPtr check_labels_has_object_hook; + +typedef void (*RelationBuildPtr)(Relation); +extern PGDLLIMPORT RelationBuildPtr RelationBuildRlsPolicies_hook; + +typedef void(*GetRlsPoliciesPtr)(const Query *query, const RangeTblEntry *rte, + const Relation relation, List *&rlsQuals, List *&withCheckOptions, + int rtIndex, bool &hasRowSecurity, bool &hasSubLink); +extern PGDLLIMPORT GetRlsPoliciesPtr get_rls_policies_hook; + +typedef bool (*GetLabelTablesPtr)(const gs_stl::gs_string&, policy_label_tables_set&); +extern PGDLLIMPORT GetLabelTablesPtr get_label_tables_hook; + +typedef void (*ReseThreadValuesPtr)(); +extern THR_LOCAL PGDLLIMPORT ReseThreadValuesPtr reset_policy_thr_hook; + +typedef bool (*LoadPoliciesPtr)(bool); +extern PGDLLIMPORT LoadPoliciesPtr load_rls_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_audit_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_masking_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_security_policies_hook; + +typedef void (*LightUnifiedAuditExecutorPtr)(const Query *query); +extern THR_LOCAL PGDLLIMPORT LightUnifiedAuditExecutorPtr light_unified_audit_executor_hook; + +typedef bool (*LoadPolicyAccessPtr)(bool); +extern PGDLLIMPORT LoadPolicyAccessPtr load_policy_access_hook; +extern PGDLLIMPORT LoadPolicyAccessPtr load_masking_policy_actions_hook; +extern PGDLLIMPORT LoadPolicyAccessPtr load_security_access_hook; + +typedef bool (*LoadPolicyPrivilegesPtr)(bool); +extern PGDLLIMPORT LoadPolicyPrivilegesPtr load_policy_privileges_hook; +extern PGDLLIMPORT LoadPolicyPrivilegesPtr load_security_privileges_hook; + +typedef bool (*LoadPolicyFilterPtr)(bool); +extern PGDLLIMPORT LoadPolicyFilterPtr load_policy_filter_hook; +extern PGDLLIMPORT LoadPolicyFilterPtr load_masking_policy_filter_hook; +extern PGDLLIMPORT LoadPolicyFilterPtr load_security_filter_hook; + +typedef bool (*IsMaskingHasObjPtr)(bool, const gs_stl::gs_string); +extern PGDLLIMPORT IsMaskingHasObjPtr isMaskingHasObj_hook; + +typedef bool (*CheckPolicyPrivilegesForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyPrivilegesForLabelPtr check_audit_policy_privileges_for_label_hook; + +typedef bool (*CheckPolicyAccessForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyAccessForLabelPtr check_audit_policy_access_for_label_hook; + +typedef bool (*CheckPolicyActionsForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyActionsForLabelPtr check_masking_policy_actions_for_label_hook; +extern PGDLLIMPORT CheckPolicyActionsForLabelPtr check_rls_policy_actions_for_label_hook; + +typedef void (*LoginUserPtr)(const char* /* db name */, const char* /* user */, bool /* sucess */, bool /* login */); +extern THR_LOCAL PGDLLIMPORT LoginUserPtr user_login_hook; + +typedef bool (*VerifyCopyCommandIsReparsed)(List*, const char*, gs_stl::gs_string&); +extern THR_LOCAL PGDLLIMPORT VerifyCopyCommandIsReparsed copy_need_to_be_reparse; + +typedef bool (*IsRecompilePrepareStmtPtr)(const char *stmt_name); +extern PGDLLIMPORT IsRecompilePrepareStmtPtr recompile_prepare_stmt_hook; + +typedef void (*IsInsidePrepareStmtPtr)(const char *stmt_name); +extern PGDLLIMPORT IsInsidePrepareStmtPtr prepare_stmt_state_hook; + +typedef bool (*IsLabelExistPtr)(const char *label_name); +extern PGDLLIMPORT IsLabelExistPtr verify_label_hook; + +typedef void (*InSideView)(bool); +extern PGDLLIMPORT InSideView query_from_view_hook; + +typedef void (*GsSaveManagementEvent)(const char *message); +extern PGDLLIMPORT GsSaveManagementEvent gs_save_mng_event_hook; + +typedef void (*GsSendManagementEvent)(AuditResult result_type); +extern PGDLLIMPORT GsSendManagementEvent gs_send_mng_event_hook; + +typedef bool (*VerifyLabelsByPolicy)(const char* filter_tree, const policy_labelname_set *policy_labels, + Oid policyOid, gs_stl::gs_string *polname); +extern PGDLLIMPORT VerifyLabelsByPolicy gs_verify_labels_by_policy_hook; + +bool get_files_list(const char *dir,std::vector& files,const char *ext, int queue_size); +bool is_policy_enabled(); +bool is_security_policy_relation(Oid table_oid); + +#endif /* _GS_POLICY_COMMON_H */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/policy_map.h postgresql-hll-2.14/include/gs_policy/policy_map.h --- postgresql-hll-2.14_old/include/gs_policy/policy_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/policy_map.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_map.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_map.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_MAP_H_ +#define GS_POLICY_MAP_H_ + +#include +#include "policy_memory_alloc.h" +#include "policy_set.h" +#include + +namespace policy_memory +{ + template, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator, type> > + class pg_map + : public std::map<_Key, _Ty, _Pr, _Alloc> { + public: + using std::map<_Key, _Ty, _Pr, _Alloc>::map; + }; + + /* + replace standard dynamic memory allocation (on heap) to local thread memory usage (preallocated memory on thread) + support for sdt::unordered_set + */ + template, + class _Pred = policy_memory::PgMemoryEqualTo<_Key>, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator, type> > + class pg_unordered_map + : public std::unordered_map<_Key, _T, _Hash, _Pred, _Alloc> { + public: + using std::unordered_map<_Key, _T, _Hash, _Pred, _Alloc>::unordered_map; + }; +} + +#endif /* GS_POLICY_MAP_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/policy_memory_alloc.h postgresql-hll-2.14/include/gs_policy/policy_memory_alloc.h --- postgresql-hll-2.14_old/include/gs_policy/policy_memory_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/policy_memory_alloc.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,115 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_memory_alloc.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_memory_alloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_MEMORY_ALLOC_H_ +#define GS_POLICY_MEMORY_ALLOC_H_ + +#include +#include "knl/knl_instance.h" +#include +#include "postgres.h" +#include +#include +#include "utils/palloc.h" + +namespace Memory_allocator +{ + typedef enum MemoryContextType { + MemoryCxt_Audit, + MemoryCxt_Mask, + MemoryCxt_RLS, + MemoryCxt_policy_instance + } MemoryContextType; + + template + class MemoryContextAdapterAllocator { + public: + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef T value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + MemoryContextAdapterAllocator () {} + ~MemoryContextAdapterAllocator () {} + template MemoryContextAdapterAllocator (const MemoryContextAdapterAllocator&) {} + template + struct rebind { typedef MemoryContextAdapterAllocator other; }; + pointer address(reference node) const {return &node;} + const_pointer address(const_reference node) const {return &node;} + + static bool has_free_memory(size_t size) + { + return true; + } + + pointer allocate(size_type n, const_pointer hint = 0) + { + switch (type) { + case MemoryCxt_Audit: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_audit_context, n * sizeof(T))); + case MemoryCxt_Mask: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_mask_context, n * sizeof(T))); + case MemoryCxt_RLS: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_rls_context, n * sizeof(T))); + default: + return static_cast( + MemoryContextAlloc(g_instance.policy_cxt.policy_instance_cxt, n * sizeof(T))); + } + } + + void deallocate(pointer p, size_type n) + { + pfree(p); + } + + void construct(pointer p, const T& val) + { + new(static_cast(p)) T(val); + } + + void construct(pointer p) + { + new(static_cast(p)) T(); + } + + void destroy(pointer p) + { + p->~T(); + } + }; + + template + inline bool operator == (const MemoryContextAdapterAllocator&, + const MemoryContextAdapterAllocator&){return true;} + + template + inline bool operator != (const MemoryContextAdapterAllocator&, + const MemoryContextAdapterAllocator&){return false;} +} + +#endif /* GS_POLICY_MEMORY_ALLOC_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_policy/policy_set.h postgresql-hll-2.14/include/gs_policy/policy_set.h --- postgresql-hll-2.14_old/include/gs_policy/policy_set.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_policy/policy_set.h 2020-12-12 17:06:43.118346374 +0800 @@ -0,0 +1,78 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_set.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_set.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_SET_H_ +#define GS_POLICY_SET_H_ + +#include "policy_memory_alloc.h" +#include "gs_string.h" +#include +#include + +namespace policy_memory +{ + template + struct PgMemoryKeyHash : std::hash<_Key> {}; + + template<> + struct PgMemoryKeyHash { + size_t operator()(const gs_stl::gs_string& k) const + { + return std::hash{}(k.c_str()); + } + }; + + template + struct PgMemoryEqualTo : std::equal_to<_Key> {}; + + template<> + struct PgMemoryEqualTo { + bool operator()(const gs_stl::gs_string& l, const gs_stl::gs_string& r) const + { + return l == r; + } + }; + + template, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator<_Key, type> > + class pg_set + : public std::set<_Key, _Pr, _Alloc> {}; + + /* + replace standard dynamic memory allocation (on heap) to local thread memory usage (preallocated memory on thread) + support for sdt::unordered_set + */ + template, + class _Pred = policy_memory::PgMemoryEqualTo<_Key>, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator<_Key, type> > + class pg_unordered_set + : public std::unordered_set<_Key, _Hash, _Pred, _Alloc> { + public: + using std::unordered_set<_Key, _Hash, _Pred, _Alloc>::unordered_set; + }; +} + +#endif /* GS_POLICY_SET_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_register/gs_malloc.h postgresql-hll-2.14/include/gs_register/gs_malloc.h --- postgresql-hll-2.14_old/include/gs_register/gs_malloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_register/gs_malloc.h 2020-12-12 17:06:43.119346387 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_malloc.h + * + * + * IDENTIFICATION + * src/include/gs_register/gs_malloc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GS_MALLOC_H +#define GS_MALLOC_H + +#include +#include +#include +#include +#include +#include "gssignal/gs_signal.h" +#include "gs_threadlocal.h" + +/* these memory apply macro is used only for memory context */ +#define gs_free(local_register_ptr, local_register_size) \ + do { \ + if ((local_register_size) < mmap_threshold) { \ + free((void*)(local_register_ptr)); \ + } else { \ + (void)munmap(local_register_ptr, (local_register_size)); \ + } \ + } while (0) + +#define gs_calloc(local_register_nmemb, local_register_size, local_register_ptr, local_register_type) \ + do { \ + Size gSize = (local_register_nmemb) * (local_register_size); \ + if (gSize < mmap_threshold) { \ + (local_register_ptr) = \ + (local_register_type)calloc((size_t)(local_register_nmemb), (size_t)(local_register_size)); \ + } else { \ + (local_register_ptr) = \ + (local_register_type)mmap(NULL, gSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + } \ + } while (0) + +#define gs_malloc(local_register_size, local_register_ptr, local_register_type) \ + do { \ + if ((local_register_size) < mmap_threshold) { \ + (local_register_ptr) = (local_register_type)malloc((size_t)(local_register_size)); \ + } else { \ + (local_register_ptr) = (local_register_type)mmap( \ + NULL, (local_register_size), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + } \ + } while (0) + +#define gs_realloc(local_register_old_ptr, \ + local_register_old_size, \ + local_register_new_ptr, \ + local_register_new_size, \ + local_register_type) \ + do { \ + if ((local_register_new_size) < mmap_threshold) { \ + (local_register_new_ptr) = \ + (local_register_type)realloc((local_register_old_ptr), (local_register_new_size)); \ + } else { \ + (local_register_new_ptr) = (local_register_type)mmap( \ + NULL, (local_register_new_size), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + if (NULL == (local_register_new_ptr)) { \ + break; \ + } else { \ + errno_t rc = EOK; \ + rc = memmove_s(local_register_new_ptr, \ + local_register_new_size, \ + local_register_old_ptr, \ + (local_register_old_size)); \ + securec_check(rc, "\0", "\0"); \ + gs_free(local_register_old_ptr, local_register_old_size); \ + } \ + } \ + } while (0) + +#define gs_strdup(local_register_str, local_register_new_str) \ + do { \ + Size gSize = strlen(local_register_str) + 1; \ + if (gSize < mmap_threshold) { \ + (local_register_new_str) = strdup((local_register_str)); \ + } else { \ + (local_register_new_str) = \ + (char*)mmap(NULL, gSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + if (NULL == (local_register_new_str)) { \ + break; \ + } else { \ + errno_t rc = EOK; \ + rc = strncpy_s(local_register_new_str, gSize, local_register_str, gSize - 1); \ + securec_check(rc, "\0", "\0"); \ + local_register_new_str[gSize - 1] = '\0'; \ + } \ + } \ + } while (0) + +#endif + diff -uprN postgresql-hll-2.14_old/include/gssapi/gssapi_ext.h postgresql-hll-2.14/include/gssapi/gssapi_ext.h --- postgresql-hll-2.14_old/include/gssapi/gssapi_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssapi/gssapi_ext.h 2020-12-12 17:06:43.119346387 +0800 @@ -0,0 +1,596 @@ +/* + * Copyright 2008 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef GSSAPI_EXT_H_ +#define GSSAPI_EXT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Solaris extensions + */ +#ifndef _WIN32 +OM_uint32 KRB5_CALLCONV +gss_pname_to_uid + (OM_uint32 *minor, + const gss_name_t name, + const gss_OID mech_type, + uid_t *uidOut); +#endif + +/** + * Provides a platform-specific name for a GSSAPI name as interpreted by a + * given mechanism. + * + * @param [out] minor Minor status code + * @param [in] name The gss name resulting from accept_sec_context + * @param [in] mech_type The mechanism that will be asked to map @a name to a + * local name + * @param [out] localname Caller-allocated buffer to be filled in with the + * local name on success + */ +OM_uint32 KRB5_CALLCONV +gss_localname + (OM_uint32 *minor, + const gss_name_t name, + gss_const_OID mech_type, + gss_buffer_t localname); + +/** + * Determine whether a mechanism name is authorized to act as a username. + * + * @param [in] name Mechanism name + * @param [in] username System username + * + * This is a simple wrapper around gss_authorize_localname(). It only supports + * system usernames as local names, and cannot distinguish between lack of + * authorization and other errors. + * + * @retval 1 @a name is authorized to act as @a username + * @retval 0 @a name is not authorized or an error occurred + */ +int KRB5_CALLCONV +gss_userok(const gss_name_t name, + const char *username); + +/** + * Determine whether a mechanism name is authorized to act as a local name. + * + * @param [out] minor Minor status code + * @param [in] name Mechanism name + * @param [in] user Local name + * + * @a name is a mechanism name, typically the result of a completed + * gss_accept_sec_context(). @a user is an internal name representing a local + * name, such as a name imported by gss_import_name() with an @a + * input_name_type of @c GSS_C_NT_USER_NAME. + * + * @return Return GSS_S_COMPLETE if @a name is authorized to act as @a user, + * GSS_S_UNAUTHORIZED if not, or an appropriate GSS error code if an error + * occured. + * + * @sa gss_userok + */ +OM_uint32 KRB5_CALLCONV +gss_authorize_localname(OM_uint32 *minor, + const gss_name_t name, + const gss_name_t user); + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_with_password( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* desired_name */ + const gss_buffer_t, /* password */ + OM_uint32, /* time_req */ + const gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_with_password( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t,/* input_cred_handle */ + const gss_name_t, /* desired_name */ + const gss_OID, /* desired_mech */ + const gss_buffer_t, /* password */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* + * GGF extensions + */ +typedef struct gss_buffer_set_desc_struct { + size_t count; + gss_buffer_desc *elements; +} gss_buffer_set_desc, *gss_buffer_set_t; + +#define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t) 0) + +OM_uint32 KRB5_CALLCONV gss_create_empty_buffer_set + (OM_uint32 * /*minor_status*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_add_buffer_set_member + (OM_uint32 * /*minor_status*/, + const gss_buffer_t /*member_buffer*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_release_buffer_set + (OM_uint32 * /*minor_status*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_inquire_sec_context_by_oid + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + const gss_OID /*desired_object*/, + gss_buffer_set_t * /*data_set*/); + +OM_uint32 KRB5_CALLCONV gss_inquire_cred_by_oid + (OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*cred_handle*/, + const gss_OID /*desired_object*/, + gss_buffer_set_t * /*data_set*/); + +OM_uint32 KRB5_CALLCONV gss_set_sec_context_option + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t * /*cred_handle*/, + const gss_OID /*desired_object*/, + const gss_buffer_t /*value*/); + +/* + * Export import cred extensions from GGF, but using Heimdal's signatures + */ +OM_uint32 KRB5_CALLCONV gss_export_cred + (OM_uint32 * /* minor_status */, + gss_cred_id_t /* cred_handle */, + gss_buffer_t /* token */); + +OM_uint32 KRB5_CALLCONV gss_import_cred + (OM_uint32 * /* minor_status */, + gss_buffer_t /* token */, + gss_cred_id_t * /* cred_handle */); + +/* + * Heimdal extension + */ +OM_uint32 KRB5_CALLCONV gss_set_cred_option + (OM_uint32 * /*minor_status*/, + gss_cred_id_t * /*cred*/, + const gss_OID /*desired_object*/, + const gss_buffer_t /*value*/); + +/* + * Call the given method on the given mechanism + */ +OM_uint32 KRB5_CALLCONV gssspi_mech_invoke + (OM_uint32 * /*minor_status*/, + const gss_OID /*desired_mech*/, + const gss_OID /*desired_object*/, + gss_buffer_t /*value*/); + +/* + * AEAD extensions + */ + +OM_uint32 KRB5_CALLCONV gss_wrap_aead + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + int /*conf_req_flag*/, + gss_qop_t /*qop_req*/, + gss_buffer_t /*input_assoc_buffer*/, + gss_buffer_t /*input_payload_buffer*/, + int * /*conf_state*/, + gss_buffer_t /*output_message_buffer*/); + +OM_uint32 KRB5_CALLCONV gss_unwrap_aead + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + gss_buffer_t /*input_message_buffer*/, + gss_buffer_t /*input_assoc_buffer*/, + gss_buffer_t /*output_payload_buffer*/, + int * /*conf_state*/, + gss_qop_t * /*qop_state*/); + +/* + * SSPI extensions + */ +#define GSS_C_DCE_STYLE 0x1000 +#define GSS_C_IDENTIFY_FLAG 0x2000 +#define GSS_C_EXTENDED_ERROR_FLAG 0x4000 + +/* + * Returns a buffer set with the first member containing the + * session key for SSPI compatibility. The optional second + * member contains an OID identifying the session key type. + */ +GSS_DLLIMP extern gss_OID GSS_C_INQ_SSPI_SESSION_KEY; + +OM_uint32 KRB5_CALLCONV gss_complete_auth_token + (OM_uint32 *minor_status, + const gss_ctx_id_t context_handle, + gss_buffer_t input_message_buffer); + +typedef struct gss_iov_buffer_desc_struct { + OM_uint32 type; + gss_buffer_desc buffer; +} gss_iov_buffer_desc, *gss_iov_buffer_t; + +#define GSS_C_NO_IOV_BUFFER ((gss_iov_buffer_t)0) + +#define GSS_IOV_BUFFER_TYPE_EMPTY 0 +#define GSS_IOV_BUFFER_TYPE_DATA 1 /* Packet data */ +#define GSS_IOV_BUFFER_TYPE_HEADER 2 /* Mechanism header */ +#define GSS_IOV_BUFFER_TYPE_MECH_PARAMS 3 /* Mechanism specific parameters */ +#define GSS_IOV_BUFFER_TYPE_TRAILER 7 /* Mechanism trailer */ +#define GSS_IOV_BUFFER_TYPE_PADDING 9 /* Padding */ +#define GSS_IOV_BUFFER_TYPE_STREAM 10 /* Complete wrap token */ +#define GSS_IOV_BUFFER_TYPE_SIGN_ONLY 11 /* Sign only packet data */ +#define GSS_IOV_BUFFER_TYPE_MIC_TOKEN 12 /* MIC token destination */ + +#define GSS_IOV_BUFFER_FLAG_MASK 0xFFFF0000 +#define GSS_IOV_BUFFER_FLAG_ALLOCATE 0x00010000 /* indicates GSS should allocate */ +#define GSS_IOV_BUFFER_FLAG_ALLOCATED 0x00020000 /* indicates caller should free */ + +#define GSS_IOV_BUFFER_TYPE(_type) ((_type) & ~(GSS_IOV_BUFFER_FLAG_MASK)) +#define GSS_IOV_BUFFER_FLAGS(_type) ((_type) & GSS_IOV_BUFFER_FLAG_MASK) + +/* + * Sign and optionally encrypt a sequence of buffers. The buffers + * shall be ordered HEADER | DATA | PADDING | TRAILER. Suitable + * space for the header, padding and trailer should be provided + * by calling gss_wrap_iov_length(), or the ALLOCATE flag should + * be set on those buffers. + * + * Encryption is in-place. SIGN_ONLY buffers are untouched. Only + * a single PADDING buffer should be provided. The order of the + * buffers in memory does not matter. Buffers in the IOV should + * be arranged in the order above, and in the case of multiple + * DATA buffers the sender and receiver should agree on the + * order. + * + * With GSS_C_DCE_STYLE it is acceptable to not provide PADDING + * and TRAILER, but the caller must guarantee the plaintext data + * being encrypted is correctly padded, otherwise an error will + * be returned. + * + * While applications that have knowledge of the underlying + * cryptosystem may request a specific configuration of data + * buffers, the only generally supported configurations are: + * + * HEADER | DATA | PADDING | TRAILER + * + * which will emit GSS_Wrap() compatible tokens, and: + * + * HEADER | SIGN_ONLY | DATA | PADDING | TRAILER + * + * for AEAD. + * + * The typical (special cased) usage for DCE is as follows: + * + * SIGN_ONLY_1 | DATA | SIGN_ONLY_2 | HEADER + */ +OM_uint32 KRB5_CALLCONV gss_wrap_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + int *, /* conf_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Verify and optionally decrypt a sequence of buffers. To process + * a GSS-API message without separate buffer, pass STREAM | DATA. + * Upon return DATA will contain the decrypted or integrity + * protected message. Only a single DATA buffer may be provided + * with this usage. DATA by default will point into STREAM, but if + * the ALLOCATE flag is set a copy will be returned. + * + * Otherwise, decryption is in-place. SIGN_ONLY buffers are + * untouched. + */ +OM_uint32 KRB5_CALLCONV gss_unwrap_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int *, /* conf_state */ + gss_qop_t *, /* qop_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Query HEADER, PADDING and TRAILER buffer lengths. DATA buffers + * should be provided so the correct padding length can be determined. + */ +OM_uint32 KRB5_CALLCONV gss_wrap_iov_length +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + int *, /* conf_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Produce a GSSAPI MIC token for a sequence of buffers. All SIGN_ONLY and + * DATA buffers will be signed, in the order they appear. One MIC_TOKEN buffer + * must be included for the result. Suitable space should be provided for the + * MIC_TOKEN buffer by calling gss_get_mic_iov_length, or the ALLOCATE flag + * should be set on that buffer. If the ALLOCATE flag is used, use + * gss_release_iov_buffer to free the allocated buffer within the iov list when + * it is no longer needed. + */ +OM_uint32 KRB5_CALLCONV gss_get_mic_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Query the MIC_TOKEN buffer length within the iov list. + */ +OM_uint32 KRB5_CALLCONV gss_get_mic_iov_length( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Verify the MIC_TOKEN buffer within the iov list against the SIGN_ONLY and + * DATA buffers in the order they appear. Return values are the same as for + * gss_verify_mic. + */ +OM_uint32 KRB5_CALLCONV gss_verify_mic_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t *, /* qop_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Release buffers that have the ALLOCATED flag set. + */ +OM_uint32 KRB5_CALLCONV gss_release_iov_buffer +( + OM_uint32 *, /* minor_status */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Protocol transition + */ +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_impersonate_name( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* impersonator_cred_handle */ + const gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + const gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_impersonate_name( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + const gss_cred_id_t, /* impersonator_cred_handle */ + const gss_name_t, /* desired_name */ + const gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* + * Naming extensions + */ +GSS_DLLIMP extern gss_buffer_t GSS_C_ATTR_LOCAL_LOGIN_USER; +GSS_DLLIMP extern gss_OID GSS_C_NT_COMPOSITE_EXPORT; + +OM_uint32 KRB5_CALLCONV gss_display_name_ext +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_OID, /* display_as_name_type */ + gss_buffer_t /* display_name */ +); + +OM_uint32 KRB5_CALLCONV gss_inquire_name +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int *, /* name_is_MN */ + gss_OID *, /* MN_mech */ + gss_buffer_set_t * /* attrs */ +); + +OM_uint32 KRB5_CALLCONV gss_get_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t, /* attr */ + int *, /* authenticated */ + int *, /* complete */ + gss_buffer_t, /* value */ + gss_buffer_t, /* display_value */ + int * /* more */ +); + +OM_uint32 KRB5_CALLCONV gss_set_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int, /* complete */ + gss_buffer_t, /* attr */ + gss_buffer_t /* value */ +); + +OM_uint32 KRB5_CALLCONV gss_delete_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t /* attr */ +); + +OM_uint32 KRB5_CALLCONV gss_export_name_composite +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t /* exp_composite_name */ +); + +typedef struct gss_any *gss_any_t; + +OM_uint32 KRB5_CALLCONV gss_map_name_to_any +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int, /* authenticated */ + gss_buffer_t, /* type_id */ + gss_any_t * /* output */ +); + +OM_uint32 KRB5_CALLCONV gss_release_any_name_mapping +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t, /* type_id */ + gss_any_t * /* input */ +); + +/* draft-josefsson-gss-capsulate */ +OM_uint32 KRB5_CALLCONV gss_encapsulate_token +( + gss_const_buffer_t, /* input_token */ + gss_const_OID, /* token_oid */ + gss_buffer_t /* output_token */ +); + +OM_uint32 KRB5_CALLCONV gss_decapsulate_token +( + gss_const_buffer_t, /* input_token */ + gss_const_OID, /* token_oid */ + gss_buffer_t /* output_token */ +); + +int KRB5_CALLCONV gss_oid_equal +( + gss_const_OID, /* first_oid */ + gss_const_OID /* second_oid */ +); + +/* Credential store extensions */ + +struct gss_key_value_element_struct { + const char *key; + const char *value; +}; +typedef struct gss_key_value_element_struct gss_key_value_element_desc; + +struct gss_key_value_set_struct { + OM_uint32 count; + gss_key_value_element_desc *elements; +}; +typedef struct gss_key_value_set_struct gss_key_value_set_desc; +typedef const gss_key_value_set_desc *gss_const_key_value_set_t; + +#define GSS_C_NO_CRED_STORE ((gss_const_key_value_set_t) 0) + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_from( + OM_uint32 *, /* minor_status */ + gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_const_key_value_set_t, /* cred_store */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_from( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_name_t, /* desired_name */ + gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_const_key_value_set_t, /* cred_store */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_store_cred_into( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_cred_usage_t, /* input_usage */ + gss_OID, /* desired_mech */ + OM_uint32, /* overwrite_cred */ + OM_uint32, /* default_cred */ + gss_const_key_value_set_t, /* cred_store */ + gss_OID_set *, /* elements_stored */ + gss_cred_usage_t *); /* cred_usage_stored */ + +#ifdef __cplusplus +} +#endif + +/* + * When used with gss_inquire_sec_context_by_oid(), return a buffer set with + * the first member containing an unsigned 32-bit integer in network byte + * order. This is the Security Strength Factor (SSF) associated with the + * secure channel established by the security context. NOTE: This value is + * made available solely as an indication for use by APIs like Cyrus SASL that + * classify the strength of a secure channel via this number. The strength of + * a channel cannot necessarily be represented by a simple number. + */ +GSS_DLLIMP extern gss_OID GSS_C_SEC_CONTEXT_SASL_SSF; + +#endif /* GSSAPI_EXT_H_ */ diff -uprN postgresql-hll-2.14_old/include/gssapi/gssapi_generic.h postgresql-hll-2.14/include/gssapi/gssapi_generic.h --- postgresql-hll-2.14_old/include/gssapi/gssapi_generic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssapi/gssapi_generic.h 2020-12-12 17:06:43.119346387 +0800 @@ -0,0 +1,59 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_GENERIC_H_ +#define _GSSAPI_GENERIC_H_ + +/* + * $Id$ + */ + +#include + +#if defined(__cplusplus) && !defined(GSSAPIGENERIC_BEGIN_DECLS) +#define GSSAPIGENERIC_BEGIN_DECLS extern "C" { +#define GSSAPIGENERIC_END_DECLS } +#else +#define GSSAPIGENERIC_BEGIN_DECLS +#define GSSAPIGENERIC_END_DECLS +#endif + +#define GSS_EMPTY_BUFFER(buf) ((buf) == NULL || \ + (buf)->value == NULL || (buf)->length == 0) + +GSSAPIGENERIC_BEGIN_DECLS + +/* Deprecated MIT krb5 oid names provided for compatibility. + * The correct oids (GSS_C_NT_USER_NAME, etc) from rfc 2744 + * are defined in gssapi.h. */ + +GSS_DLLIMP extern gss_OID gss_nt_user_name; +GSS_DLLIMP extern gss_OID gss_nt_machine_uid_name; +GSS_DLLIMP extern gss_OID gss_nt_string_uid_name; +extern gss_OID gss_nt_service_name_v2; +GSS_DLLIMP extern gss_OID gss_nt_service_name; +extern gss_OID gss_nt_exported_name; + +GSSAPIGENERIC_END_DECLS + +#endif /* _GSSAPI_GENERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/gssapi/gssapi.h postgresql-hll-2.14/include/gssapi/gssapi.h --- postgresql-hll-2.14_old/include/gssapi/gssapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssapi/gssapi.h 2020-12-12 17:06:43.119346387 +0800 @@ -0,0 +1,923 @@ +/* This is the gssapi.h prologue. */ +/* no xom.h */ +/* End of gssapi.h prologue. */ +/* -*- mode: c; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_H_ +#define _GSSAPI_H_ + +/* + * Determine platform-dependent configuration. + */ + +#if defined(__MACH__) && defined(__APPLE__) +# include +# if TARGET_RT_MAC_CFM +# error "Use KfM 4.0 SDK headers for CFM compilation." +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(push,2) +#endif + +#if defined(_MSDOS) || defined(_WIN32) +#include +#endif + +#ifndef KRB5_CALLCONV +#define KRB5_CALLCONV +#define KRB5_CALLCONV_C +#endif + +#include + +/* + * First, include stddef.h to get size_t defined. + */ +#include + +/* + * POSIX says that sys/types.h is where size_t is defined. + */ +#include + +/* + * $Id$ + */ + +/* + * First, define the three platform-dependent pointer types. + */ + +struct gss_name_struct; +typedef struct gss_name_struct * gss_name_t; + +struct gss_cred_id_struct; +typedef struct gss_cred_id_struct * gss_cred_id_t; + +struct gss_ctx_id_struct; +typedef struct gss_ctx_id_struct * gss_ctx_id_t; + +/* + * The following type must be defined as the smallest natural unsigned integer + * supported by the platform that has at least 32 bits of precision. + */ +typedef uint32_t gss_uint32; +typedef int32_t gss_int32; + +#ifdef OM_STRING +/* + * We have included the xom.h header file. Use the definition for + * OM_object identifier. + */ +typedef OM_object_identifier gss_OID_desc, *gss_OID; +#else /* OM_STRING */ +/* + * We can't use X/Open definitions, so roll our own. + */ +typedef gss_uint32 OM_uint32; + +typedef struct gss_OID_desc_struct { + OM_uint32 length; + void *elements; +} gss_OID_desc, *gss_OID; +#endif /* OM_STRING */ + +typedef struct gss_OID_set_desc_struct { + size_t count; + gss_OID elements; +} gss_OID_set_desc, *gss_OID_set; + +typedef struct gss_buffer_desc_struct { + size_t length; + void *value; +} gss_buffer_desc, *gss_buffer_t; + +typedef struct gss_channel_bindings_struct { + OM_uint32 initiator_addrtype; + gss_buffer_desc initiator_address; + OM_uint32 acceptor_addrtype; + gss_buffer_desc acceptor_address; + gss_buffer_desc application_data; +} *gss_channel_bindings_t; + +/* + * For now, define a QOP-type as an OM_uint32 (pending resolution of ongoing + * discussions). + */ +typedef OM_uint32 gss_qop_t; +typedef int gss_cred_usage_t; + +/* + * Flag bits for context-level services. + */ +#define GSS_C_DELEG_FLAG 1 +#define GSS_C_MUTUAL_FLAG 2 +#define GSS_C_REPLAY_FLAG 4 +#define GSS_C_SEQUENCE_FLAG 8 +#define GSS_C_CONF_FLAG 16 +#define GSS_C_INTEG_FLAG 32 +#define GSS_C_ANON_FLAG 64 +#define GSS_C_PROT_READY_FLAG 128 +#define GSS_C_TRANS_FLAG 256 +#define GSS_C_DELEG_POLICY_FLAG 32768 + +/* + * Credential usage options + */ +#define GSS_C_BOTH 0 +#define GSS_C_INITIATE 1 +#define GSS_C_ACCEPT 2 + +/* + * Status code types for gss_display_status + */ +#define GSS_C_GSS_CODE 1 +#define GSS_C_MECH_CODE 2 + +/* + * The constant definitions for channel-bindings address families + */ +#define GSS_C_AF_UNSPEC 0 +#define GSS_C_AF_LOCAL 1 +#define GSS_C_AF_INET 2 +#define GSS_C_AF_IMPLINK 3 +#define GSS_C_AF_PUP 4 +#define GSS_C_AF_CHAOS 5 +#define GSS_C_AF_NS 6 +#define GSS_C_AF_NBS 7 +#define GSS_C_AF_ECMA 8 +#define GSS_C_AF_DATAKIT 9 +#define GSS_C_AF_CCITT 10 +#define GSS_C_AF_SNA 11 +#define GSS_C_AF_DECnet 12 +#define GSS_C_AF_DLI 13 +#define GSS_C_AF_LAT 14 +#define GSS_C_AF_HYLINK 15 +#define GSS_C_AF_APPLETALK 16 +#define GSS_C_AF_BSC 17 +#define GSS_C_AF_DSS 18 +#define GSS_C_AF_OSI 19 +#define GSS_C_AF_NETBIOS 20 +#define GSS_C_AF_X25 21 + +#define GSS_C_AF_NULLADDR 255 + +/* + * Various Null values. + */ +#define GSS_C_NO_NAME ((gss_name_t) 0) +#define GSS_C_NO_BUFFER ((gss_buffer_t) 0) +#define GSS_C_NO_OID ((gss_OID) 0) +#define GSS_C_NO_OID_SET ((gss_OID_set) 0) +#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0) +#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0) +#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0) +#define GSS_C_EMPTY_BUFFER {0, NULL} + +/* + * Some alternate names for a couple of the above values. These are defined + * for V1 compatibility. + */ +#define GSS_C_NULL_OID GSS_C_NO_OID +#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET + +/* + * Define the default Quality of Protection for per-message services. Note + * that an implementation that offers multiple levels of QOP may either reserve + * a value (for example zero, as assumed here) to mean "default protection", or + * alternatively may simply equate GSS_C_QOP_DEFAULT to a specific explicit + * QOP value. However a value of 0 should always be interpreted by a GSSAPI + * implementation as a request for the default protection level. + */ +#define GSS_C_QOP_DEFAULT 0 + +/* + * Expiration time of 2^32-1 seconds means infinite lifetime for a + * credential or security context + */ +#define GSS_C_INDEFINITE ((OM_uint32) 0xfffffffful) + + +/* Major status codes */ + +#define GSS_S_COMPLETE 0 + +/* + * Some "helper" definitions to make the status code macros obvious. + */ +#define GSS_C_CALLING_ERROR_OFFSET 24 +#define GSS_C_ROUTINE_ERROR_OFFSET 16 +#define GSS_C_SUPPLEMENTARY_OFFSET 0 +#define GSS_C_CALLING_ERROR_MASK ((OM_uint32) 0377ul) +#define GSS_C_ROUTINE_ERROR_MASK ((OM_uint32) 0377ul) +#define GSS_C_SUPPLEMENTARY_MASK ((OM_uint32) 0177777ul) + +/* + * The macros that test status codes for error conditions. Note that the + * GSS_ERROR() macro has changed slightly from the V1 GSSAPI so that it now + * evaluates its argument only once. + */ +#define GSS_CALLING_ERROR(x) \ + ((x) & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET)) +#define GSS_ROUTINE_ERROR(x) \ + ((x) & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)) +#define GSS_SUPPLEMENTARY_INFO(x) \ + ((x) & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET)) +#define GSS_ERROR(x) \ + ((x) & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \ + (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))) + +/* + * Now the actual status code definitions + */ + +/* + * Calling errors: + */ +#define GSS_S_CALL_INACCESSIBLE_READ \ + (((OM_uint32) 1ul) << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_INACCESSIBLE_WRITE \ + (((OM_uint32) 2ul) << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_BAD_STRUCTURE \ + (((OM_uint32) 3ul) << GSS_C_CALLING_ERROR_OFFSET) + +/* + * Routine errors: + */ +#define GSS_S_BAD_MECH (((OM_uint32) 1ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAME (((OM_uint32) 2ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAMETYPE (((OM_uint32) 3ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_BINDINGS (((OM_uint32) 4ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_STATUS (((OM_uint32) 5ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_SIG (((OM_uint32) 6ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MIC GSS_S_BAD_SIG +#define GSS_S_NO_CRED (((OM_uint32) 7ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NO_CONTEXT (((OM_uint32) 8ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_TOKEN (((OM_uint32) 9ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_CREDENTIAL \ + (((OM_uint32) 10ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CREDENTIALS_EXPIRED \ + (((OM_uint32) 11ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CONTEXT_EXPIRED \ + (((OM_uint32) 12ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_FAILURE (((OM_uint32) 13ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_QOP (((OM_uint32) 14ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAUTHORIZED (((OM_uint32) 15ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAVAILABLE (((OM_uint32) 16ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DUPLICATE_ELEMENT \ + (((OM_uint32) 17ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NAME_NOT_MN \ + (((OM_uint32) 18ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MECH_ATTR \ + (((OM_uint32) 19ul) << GSS_C_ROUTINE_ERROR_OFFSET) + +/* + * Supplementary info bits: + */ +#define GSS_S_CONTINUE_NEEDED (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 0)) +#define GSS_S_DUPLICATE_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 1)) +#define GSS_S_OLD_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 2)) +#define GSS_S_UNSEQ_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 3)) +#define GSS_S_GAP_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 4)) + + +/* + * Finally, function prototypes for the GSSAPI routines. + */ + +#if defined (_WIN32) && defined (_MSC_VER) +# ifdef GSS_DLL_FILE +# define GSS_DLLIMP __declspec(dllexport) +# else +# define GSS_DLLIMP __declspec(dllimport) +# endif +#else +# define GSS_DLLIMP +#endif + +/* Reserved static storage for GSS_oids. Comments are quotes from RFC 2744. + * + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_USER_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_MACHINE_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_STRING_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + * corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x04"}, corresponding to an + * object-identifier value of {iso(1) member-body(2) + * Unites States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The constant + * GSS_C_NT_HOSTBASED_SERVICE should be initialized + * to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + * corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_ANONYMOUS; + + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + * corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_EXPORT_NAME; + +/* Function Prototypes */ + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred( + OM_uint32 *, /* minor_status */ + gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_release_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t *); /* cred_handle */ + +OM_uint32 KRB5_CALLCONV +gss_init_sec_context( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* claimant_cred_handle */ + gss_ctx_id_t *, /* context_handle */ + gss_name_t, /* target_name */ + gss_OID, /* mech_type (used to be const) */ + OM_uint32, /* req_flags */ + OM_uint32, /* time_req */ + gss_channel_bindings_t, /* input_chan_bindings */ + gss_buffer_t, /* input_token */ + gss_OID *, /* actual_mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_accept_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_cred_id_t, /* acceptor_cred_handle */ + gss_buffer_t, /* input_token_buffer */ + gss_channel_bindings_t, /* input_chan_bindings */ + gss_name_t *, /* src_name */ + gss_OID *, /* mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 *, /* time_rec */ + gss_cred_id_t *); /* delegated_cred_handle */ + +OM_uint32 KRB5_CALLCONV +gss_process_context_token( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t); /* token_buffer */ + + +OM_uint32 KRB5_CALLCONV +gss_delete_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t); /* output_token */ + + +OM_uint32 KRB5_CALLCONV +gss_context_time( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + OM_uint32 *); /* time_rec */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_get_mic( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t); /* message_token */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_verify_mic(OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t, /* message_token */ + gss_qop_t * /* qop_state */ +); + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_wrap( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t); /* output_message_buffer */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_unwrap( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + gss_qop_t *); /* qop_state */ + + +OM_uint32 KRB5_CALLCONV +gss_display_status( + OM_uint32 *, /* minor_status */ + OM_uint32, /* status_value */ + int, /* status_type */ + gss_OID, /* mech_type (used to be const) */ + OM_uint32 *, /* message_context */ + gss_buffer_t); /* status_string */ + + +OM_uint32 KRB5_CALLCONV +gss_indicate_mechs( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* mech_set */ + + +OM_uint32 KRB5_CALLCONV +gss_compare_name( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name1 */ + gss_name_t, /* name2 */ + int *); /* name_equal */ + + +OM_uint32 KRB5_CALLCONV +gss_display_name( + OM_uint32 *, /* minor_status */ + gss_name_t, /* input_name */ + gss_buffer_t, /* output_name_buffer */ + gss_OID *); /* output_name_type */ + + +OM_uint32 KRB5_CALLCONV +gss_import_name( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* input_name_buffer */ + gss_OID, /* input_name_type(used to be const) */ + gss_name_t *); /* output_name */ + +OM_uint32 KRB5_CALLCONV +gss_release_name( + OM_uint32 *, /* minor_status */ + gss_name_t *); /* input_name */ + +OM_uint32 KRB5_CALLCONV +gss_release_buffer( + OM_uint32 *, /* minor_status */ + gss_buffer_t); /* buffer */ + +OM_uint32 KRB5_CALLCONV +gss_release_oid_set( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* set */ + +OM_uint32 KRB5_CALLCONV +gss_inquire_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + gss_name_t *, /* name */ + OM_uint32 *, /* lifetime */ + gss_cred_usage_t *, /* cred_usage */ + gss_OID_set *); /* mechanisms */ + +/* Last argument new for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_name_t *, /* src_name */ + gss_name_t *, /* targ_name */ + OM_uint32 *, /* lifetime_rec */ + gss_OID *, /* mech_type */ + OM_uint32 *, /* ctx_flags */ + int *, /* locally_initiated */ + int *); /* open */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_wrap_size_limit( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + OM_uint32, /* req_output_size */ + OM_uint32 *); /* max_input_size */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_import_name_object( + OM_uint32 *, /* minor_status */ + void *, /* input_name */ + gss_OID, /* input_name_type */ + gss_name_t *); /* output_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_name_object( + OM_uint32 *, /* minor_status */ + gss_name_t, /* input_name */ + gss_OID, /* desired_name_type */ + void **); /* output_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_add_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_name_t, /* desired_name */ + gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_cred_by_mech( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + gss_OID, /* mech_type */ + gss_name_t *, /* name */ + OM_uint32 *, /* initiator_lifetime */ + OM_uint32 *, /* acceptor_lifetime */ + gss_cred_usage_t *); /* cred_usage */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t); /* interprocess_token */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_import_sec_context( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* interprocess_token */ + gss_ctx_id_t *); /* context_handle */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_release_oid( + OM_uint32 *, /* minor_status */ + gss_OID *); /* oid */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_create_empty_oid_set( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* oid_set */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_add_oid_set_member( + OM_uint32 *, /* minor_status */ + gss_OID, /* member_oid */ + gss_OID_set *); /* oid_set */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_test_oid_set_member( + OM_uint32 *, /* minor_status */ + gss_OID, /* member */ + gss_OID_set, /* set */ + int *); /* present */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_str_to_oid( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* oid_str */ + gss_OID *); /* oid */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_oid_to_str( + OM_uint32 *, /* minor_status */ + gss_OID, /* oid */ + gss_buffer_t); /* oid_str */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_names_for_mech( + OM_uint32 *, /* minor_status */ + gss_OID, /* mechanism */ + gss_OID_set *); /* name_types */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_mechs_for_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_OID_set *); /* mech_types */ + +/* + * The following routines are obsolete variants of gss_get_mic, gss_wrap, + * gss_verify_mic and gss_unwrap. They should be provided by GSSAPI V2 + * implementations for backwards compatibility with V1 applications. Distinct + * entrypoints (as opposed to #defines) should be provided, to allow GSSAPI + * V1 applications to link against GSSAPI V2 implementations. + */ +OM_uint32 KRB5_CALLCONV +gss_sign( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* qop_req */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t); /* message_token */ + +OM_uint32 KRB5_CALLCONV +gss_verify( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t, /* token_buffer */ + int *); /* qop_state */ + +OM_uint32 KRB5_CALLCONV +gss_seal( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + int, /* qop_req */ + gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t); /* output_message_buffer */ + +OM_uint32 KRB5_CALLCONV +gss_unseal( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + int *); /* qop_state */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_buffer_t); /* exported_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_duplicate_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_name_t *); /* dest_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_canonicalize_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + const gss_OID, /* mech_type */ + gss_name_t *); /* output_name */ + +/* RFC 4401 */ + +#define GSS_C_PRF_KEY_FULL 0 +#define GSS_C_PRF_KEY_PARTIAL 1 + +OM_uint32 KRB5_CALLCONV +gss_pseudo_random( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context */ + int, /* prf_key */ + const gss_buffer_t, /* prf_in */ + ssize_t, /* desired_output_len */ + gss_buffer_t); /* prf_out */ + +OM_uint32 KRB5_CALLCONV +gss_store_cred( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t,/* input_cred_handle */ + gss_cred_usage_t, /* input_usage */ + const gss_OID, /* desired_mech */ + OM_uint32, /* overwrite_cred */ + OM_uint32, /* default_cred */ + gss_OID_set *, /* elements_stored */ + gss_cred_usage_t *);/* cred_usage_stored */ + +OM_uint32 KRB5_CALLCONV +gss_set_neg_mechs( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + const gss_OID_set); /* mech_set */ + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif + +/* XXXX these are not part of the GSSAPI C bindings! (but should be) */ + +#define GSS_CALLING_ERROR_FIELD(x) \ + (((x) >> GSS_C_CALLING_ERROR_OFFSET) & GSS_C_CALLING_ERROR_MASK) +#define GSS_ROUTINE_ERROR_FIELD(x) \ + (((x) >> GSS_C_ROUTINE_ERROR_OFFSET) & GSS_C_ROUTINE_ERROR_MASK) +#define GSS_SUPPLEMENTARY_INFO_FIELD(x) \ + (((x) >> GSS_C_SUPPLEMENTARY_OFFSET) & GSS_C_SUPPLEMENTARY_MASK) + +/* XXXX This is a necessary evil until the spec is fixed */ +#define GSS_S_CRED_UNAVAIL GSS_S_FAILURE + +/* + * RFC 5587 + */ +typedef const gss_buffer_desc *gss_const_buffer_t; +typedef const struct gss_channel_bindings_struct *gss_const_channel_bindings_t; +typedef const struct gss_ctx_id_struct *gss_const_ctx_id_t; +typedef const struct gss_cred_id_struct *gss_const_cred_id_t; +typedef const struct gss_name_struct *gss_const_name_t; +typedef const gss_OID_desc *gss_const_OID; +typedef const gss_OID_set_desc *gss_const_OID_set; + +OM_uint32 KRB5_CALLCONV +gss_indicate_mechs_by_attrs( + OM_uint32 *, /* minor_status */ + gss_const_OID_set, /* desired_mech_attrs */ + gss_const_OID_set, /* except_mech_attrs */ + gss_const_OID_set, /* critical_mech_attrs */ + gss_OID_set *); /* mechs */ + +OM_uint32 KRB5_CALLCONV +gss_inquire_attrs_for_mech( + OM_uint32 *, /* minor_status */ + gss_const_OID, /* mech */ + gss_OID_set *, /* mech_attrs */ + gss_OID_set *); /* known_mech_attrs */ + +OM_uint32 KRB5_CALLCONV +gss_display_mech_attr( + OM_uint32 *, /* minor_status */ + gss_const_OID, /* mech_attr */ + gss_buffer_t, /* name */ + gss_buffer_t, /* short_desc */ + gss_buffer_t); /* long_desc */ + +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_CONCRETE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_PSEUDO; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_COMPOSITE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_NEGO; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_GLUE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_NOT_MECH; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_DEPRECATED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_NOT_DFLT_MECH; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_ITOK_FRAMED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT_ANON; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG_ANON; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_DELEG_CRED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_INTEG_PROT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CONF_PROT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MIC; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_WRAP; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_PROT_READY; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_REPLAY_DET; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_OOS_DET; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CBINDINGS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_PFS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_COMPRESS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CTX_TRANS; + +/* + * RFC 5801 + */ +OM_uint32 KRB5_CALLCONV +gss_inquire_saslname_for_mech( + OM_uint32 *, /* minor_status */ + const gss_OID, /* desired_mech */ + gss_buffer_t, /* sasl_mech_name */ + gss_buffer_t, /* mech_name */ + gss_buffer_t /* mech_description */ +); + +OM_uint32 KRB5_CALLCONV +gss_inquire_mech_for_saslname( + OM_uint32 *, /* minor_status */ + const gss_buffer_t, /* sasl_mech_name */ + gss_OID * /* mech_type */ +); + +#endif /* _GSSAPI_H_ */ diff -uprN postgresql-hll-2.14_old/include/gssapi/gssapi_krb5.h postgresql-hll-2.14/include/gssapi/gssapi_krb5.h --- postgresql-hll-2.14_old/include/gssapi/gssapi_krb5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssapi/gssapi_krb5.h 2020-12-12 17:06:43.119346387 +0800 @@ -0,0 +1,300 @@ +/* -*- mode: c; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_KRB5_H_ +#define _GSSAPI_KRB5_H_ + +#include +#include +#include +#include + +/* C++ friendlyness */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Reserved static storage for GSS_oids. See rfc 1964 for more details. */ + +/* 2.1.1. Kerberos Principal Name Form: */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_NT_PRINCIPAL_NAME; +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5_name(1)}. The recommended symbolic name for this type + * is "GSS_KRB5_NT_PRINCIPAL_NAME". */ + +/* 2.1.2. Host-Based Service Name Form */ +#define GSS_KRB5_NT_HOSTBASED_SERVICE_NAME GSS_C_NT_HOSTBASED_SERVICE +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The previously recommended symbolic + * name for this type is "GSS_KRB5_NT_HOSTBASED_SERVICE_NAME". The + * currently preferred symbolic name for this type is + * "GSS_C_NT_HOSTBASED_SERVICE". */ + +/* 2.2.1. User Name Form */ +#define GSS_KRB5_NT_USER_NAME GSS_C_NT_USER_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) user_name(1)}. The recommended symbolic name for this + * type is "GSS_KRB5_NT_USER_NAME". */ + +/* 2.2.2. Machine UID Form */ +#define GSS_KRB5_NT_MACHINE_UID_NAME GSS_C_NT_MACHINE_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) machine_uid_name(2)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_MACHINE_UID_NAME". */ + +/* 2.2.3. String UID Form */ +#define GSS_KRB5_NT_STRING_UID_NAME GSS_C_NT_STRING_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) string_uid_name(3)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_STRING_UID_NAME". */ + +/* Kerberos Enterprise Name Form (see RFC 6806 section 5): */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_NT_ENTERPRISE_NAME; +/* {iso(1) member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5-enterprise-name(6)}. */ + +GSS_DLLIMP extern const gss_OID gss_mech_krb5; +GSS_DLLIMP extern const gss_OID gss_mech_krb5_old; +GSS_DLLIMP extern const gss_OID gss_mech_krb5_wrong; +GSS_DLLIMP extern const gss_OID gss_mech_iakerb; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5_old; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5_both; + +GSS_DLLIMP extern const gss_OID gss_nt_krb5_name; +GSS_DLLIMP extern const gss_OID gss_nt_krb5_principal; + +GSS_DLLIMP extern const gss_OID_desc krb5_gss_oid_array[]; + +/* + * This OID can be used with gss_set_cred_option() to suppress the + * confidentiality and integrity flags from being asserted in initial context + * tokens. + * + * iso(1) member-body(2) Sweden(752) Stockholm University(43) Heimdal GSS-API + * Extensions(13) no_ci_flags(29) + */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X; + +/* + * This OID can be used with gss_inquire_cred_by_oid(0 to retrieve the + * impersonator name (if any). + * + * iso(1) member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5-gssapi-ext(5) get-cred-impersonator(14) + */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_GET_CRED_IMPERSONATOR; + +#define gss_krb5_nt_general_name gss_nt_krb5_name +#define gss_krb5_nt_principal gss_nt_krb5_principal +#define gss_krb5_nt_service_name gss_nt_service_name +#define gss_krb5_nt_user_name gss_nt_user_name +#define gss_krb5_nt_machine_uid_name gss_nt_machine_uid_name +#define gss_krb5_nt_string_uid_name gss_nt_string_uid_name + +typedef struct gss_krb5_lucid_key { + OM_uint32 type; /* key encryption type */ + OM_uint32 length; /* length of key data */ + void * data; /* actual key data */ +} gss_krb5_lucid_key_t; + +typedef struct gss_krb5_rfc1964_keydata { + OM_uint32 sign_alg; /* signing algorthm */ + OM_uint32 seal_alg; /* seal/encrypt algorithm */ + gss_krb5_lucid_key_t ctx_key; + /* Context key + (Kerberos session key or subkey) */ +} gss_krb5_rfc1964_keydata_t; + +typedef struct gss_krb5_cfx_keydata { + OM_uint32 have_acceptor_subkey; + /* 1 if there is an acceptor_subkey + present, 0 otherwise */ + gss_krb5_lucid_key_t ctx_key; + /* Context key + (Kerberos session key or subkey) */ + gss_krb5_lucid_key_t acceptor_subkey; + /* acceptor-asserted subkey or + 0's if no acceptor subkey */ +} gss_krb5_cfx_keydata_t; + +typedef struct gss_krb5_lucid_context_v1 { + OM_uint32 version; /* Structure version number (1) + MUST be at beginning of struct! */ + OM_uint32 initiate; /* Are we the initiator? */ + OM_uint32 endtime; /* expiration time of context */ + uint64_t send_seq; /* sender sequence number */ + uint64_t recv_seq; /* receive sequence number */ + OM_uint32 protocol; /* 0: rfc1964, + 1: draft-ietf-krb-wg-gssapi-cfx-07 */ + /* + * if (protocol == 0) rfc1964_kd should be used + * and cfx_kd contents are invalid and should be zero + * if (protocol == 1) cfx_kd should be used + * and rfc1964_kd contents are invalid and should be zero + */ + gss_krb5_rfc1964_keydata_t rfc1964_kd; + gss_krb5_cfx_keydata_t cfx_kd; +} gss_krb5_lucid_context_v1_t; + +/* + * Mask for determining the version of a lucid context structure. Callers + * should not require this. + */ +typedef struct gss_krb5_lucid_context_version { + OM_uint32 version; /* Structure version number */ +} gss_krb5_lucid_context_version_t; + + + + +/* Alias for Heimdal compat. */ +#define gsskrb5_register_acceptor_identity krb5_gss_register_acceptor_identity + +OM_uint32 KRB5_CALLCONV krb5_gss_register_acceptor_identity(const char *); + +OM_uint32 KRB5_CALLCONV gss_krb5_get_tkt_flags( + OM_uint32 *minor_status, + gss_ctx_id_t context_handle, + krb5_flags *ticket_flags); + +/* + * Copy krb5 creds from cred_handle into out_ccache, which must already be + * initialized. Use gss_store_cred_into() (new in krb5 1.11) instead, if + * possible. + */ +OM_uint32 KRB5_CALLCONV gss_krb5_copy_ccache( + OM_uint32 *minor_status, + gss_cred_id_t cred_handle, + krb5_ccache out_ccache); + +OM_uint32 KRB5_CALLCONV gss_krb5_ccache_name( + OM_uint32 *minor_status, const char *name, + const char **out_name); + +/* + * gss_krb5_set_allowable_enctypes + * + * This function may be called by a context initiator after calling + * gss_acquire_cred(), but before calling gss_init_sec_context(), + * to restrict the set of enctypes which will be negotiated during + * context establishment to those in the provided array. + * + * 'cred' must be a valid credential handle obtained via + * gss_acquire_cred(). It may not be GSS_C_NO_CREDENTIAL. + * gss_acquire_cred() may have been called to get a handle to + * the default credential. + * + * The purpose of this function is to limit the keys that may + * be exported via gss_krb5_export_lucid_sec_context(); thus it + * should limit the enctypes of all keys that will be needed + * after the security context has been established. + * (i.e. context establishment may use a session key with a + * stronger enctype than in the provided array, however a + * subkey must be established within the enctype limits + * established by this function.) + * + */ +OM_uint32 KRB5_CALLCONV +gss_krb5_set_allowable_enctypes(OM_uint32 *minor_status, + gss_cred_id_t cred, + OM_uint32 num_ktypes, + krb5_enctype *ktypes); + +/* + * Returns a non-opaque (lucid) version of the internal context + * information. + * + * Note that context_handle must not be used again by the caller + * after this call. The GSS implementation is free to release any + * resources associated with the original context. It is up to the + * GSS implementation whether it returns pointers to existing data, + * or copies of the data. The caller should treat the returned + * lucid context as read-only. + * + * The caller must call gss_krb5_free_lucid_context() to free + * the context and allocated resources when it is finished with it. + * + * 'version' is an integer indicating the requested version of the lucid + * context. If the implementation does not understand the requested version, + * it will return an error. + * + * For example: + * void *return_ctx; + * gss_krb5_lucid_context_v1_t *ctx; + * OM_uint32 min_stat, maj_stat; + * OM_uint32 vers; + * gss_ctx_id_t *ctx_handle; + * + * maj_stat = gss_krb5_export_lucid_sec_context(&min_stat, + * ctx_handle, 1, &return_ctx); + * // Verify success + * ctx = (gss_krb5_lucid_context_v1_t *) return_ctx; + */ + +OM_uint32 KRB5_CALLCONV +gss_krb5_export_lucid_sec_context(OM_uint32 *minor_status, + gss_ctx_id_t *context_handle, + OM_uint32 version, + void **kctx); + +/* + * Frees the allocated storage associated with an + * exported struct gss_krb5_lucid_context. + */ +OM_uint32 KRB5_CALLCONV +gss_krb5_free_lucid_sec_context(OM_uint32 *minor_status, + void *kctx); + + +OM_uint32 KRB5_CALLCONV +gsskrb5_extract_authz_data_from_sec_context(OM_uint32 *minor_status, + const gss_ctx_id_t context_handle, + int ad_type, + gss_buffer_t ad_data); + +OM_uint32 KRB5_CALLCONV +gss_krb5_set_cred_rcache(OM_uint32 *minor_status, + gss_cred_id_t cred, + krb5_rcache rcache); + +OM_uint32 KRB5_CALLCONV +gsskrb5_extract_authtime_from_sec_context(OM_uint32 *, gss_ctx_id_t, krb5_timestamp *); + +OM_uint32 KRB5_CALLCONV +gss_krb5_import_cred(OM_uint32 *minor_status, + krb5_ccache id, + krb5_principal keytab_principal, + krb5_keytab keytab, + gss_cred_id_t *cred); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _GSSAPI_KRB5_H_ */ diff -uprN postgresql-hll-2.14_old/include/gssapi/mechglue.h postgresql-hll-2.14/include/gssapi/mechglue.h --- postgresql-hll-2.14_old/include/gssapi/mechglue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssapi/mechglue.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,42 @@ +/* #ident "@(#)mechglue.h 1.13 95/08/07 SMI" */ + +/* + * Copyright 1996 by Sun Microsystems, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of Sun Microsystems not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. Sun Microsystems makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * This header contains the mechglue definitions. + */ + +#ifndef _GSS_MECHGLUE_H +#define _GSS_MECHGLUE_H + +#include + +/********************************************************/ +/* GSSAPI Extension functions -- these functions aren't */ +/* in the GSSAPI, but they are provided in this library */ + +#include + +void KRB5_CALLCONV gss_initialize(void); + +#endif /* _GSS_MECHGLUE_H */ diff -uprN postgresql-hll-2.14_old/include/gssignal/gs_signal.h postgresql-hll-2.14/include/gssignal/gs_signal.h --- postgresql-hll-2.14_old/include/gssignal/gs_signal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gssignal/gs_signal.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,149 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_signal.h + * + * + * + * IDENTIFICATION + * src/include/gssignal/gs_signal.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_SIGNAL_H_ +#define GS_SIGNAL_H_ + +#include "gs_thread.h" +#include +#include "storage/s_lock.h" +#include + +#define GS_SIGNAL_COUNT 32 + +typedef void (*gs_sigfunc)(int); + +typedef enum GsSignalCheckType { + SIGNAL_CHECK_NONE, + SIGNAL_CHECK_EXECUTOR_STOP, + SIGNAL_CHECK_STREAM_STOP, + SIGNAL_CHECK_SESS_KEY +} GsSignalCheckType; + +/* the struct of signal check */ +typedef struct GsSignalCheck { + GsSignalCheckType check_type; + uint64 debug_query_id; + uint64 session_id; +} GsSignalCheck; + +/* the struct of signal to be handled and the signal sender's thread id */ +typedef struct GsSndSignal { + unsigned int signo; /* the signal to be handled */ + gs_thread_t thread; /* the signal sender's thread id */ + GsSignalCheck check; /* the signal sender's check information if need check */ +} GsSndSignal; + +/* the list struct of GsSndSignal */ +typedef struct GsNode { + GsSndSignal sig_data; + struct GsNode* next; +} GsNode; + +/* + * Each thread has a signal pool, which contains the used signal list and free signal list. + * free signal list keeps the free signal slots for this thread. + * used signal list keeps the signal which will be handled for this thread. + * When a analog signal arrives, it will search a free signal slot, fill the sig_data + * then put it info the used list; after a signal handled, the used slot will be put + * back to the free list. + */ +typedef struct SignalPool { + GsNode* free_head; /* the head of free signal list */ + GsNode* free_tail; /* the tail of free signal list */ + GsNode* used_head; /* the head of used signal list */ + GsNode* used_tail; /* the tail of used signal list */ + int pool_size; /* the size of the array list */ + pthread_mutex_t sigpool_lock; +} SignalPool; + +/* the struct keeps signal handle function array and signal pool for each thread */ +typedef struct GsSignal { + gs_sigfunc handlerList[GS_SIGNAL_COUNT]; + sigset_t masksignal; + SignalPool sig_pool; + volatile unsigned int bitmapSigProtectFun; +} GsSignal; + +/* each thread has a GsSignalSlot to keep their thread id, thread name, signals and signal handles */ +typedef struct GsSignalSlot { + ThreadId thread_id; + char* thread_name; + GsSignal* gssignal; +} GsSignalSlot; + +typedef volatile int gs_atomic_t; + +extern sigset_t gs_signal_unblock_sigusr2(void); + +extern sigset_t gs_signal_block_sigusr2(void); + +extern void gs_signal_recover_mask(sigset_t mask); + +typedef void (*gs_sigaction_func)(int, siginfo_t*, void*); + +/* global GsSignalSlot manager, keeps all threads' GsSignalSlot */ +typedef struct GsSignalBase { + GsSignalSlot* slots; + unsigned int slots_size; + pthread_mutex_t slots_lock; +} GsSignalBase; + +extern gs_sigfunc gspqsignal(int signo, gs_sigfunc func); + +extern void gs_signal_setmask(sigset_t* mask, sigset_t* old_mask); + +/* + * initialize signal slots + */ +extern void gs_signal_slots_init(unsigned long size); + +extern GsSignalSlot* gs_signal_slot_release(ThreadId thread_id); + +/*gs send signal to thread*/ +extern int gs_signal_send(ThreadId thread_id, int signo, int nowait = 0); +extern int gs_signal_send(ThreadId thread_id, int signo, bool is_thread_pool); + +extern void gs_signal_startup_siginfo(char* thread_name); + +extern int gs_thread_kill(ThreadId tid, int sig); + +extern void gs_signal_handle(void); + +/* Create timer support for current thread */ +extern int gs_signal_createtimer(void); + +/* A thread-safe version replacement of setitimer () call. */ +extern int gs_signal_settimer(struct itimerval* interval); + +/* A thread-safe version replacement of CancelTimer (0) call. */ +extern int gs_signal_canceltimer(void); + +/* A thread-safe version replacement of delteitimer (0) call. */ +extern int gs_signal_deletetimer(void); + +extern void gs_signal_monitor_startup(void); + +#endif /* GS_SIGNAL_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_thread.h postgresql-hll-2.14/include/gs_thread.h --- postgresql-hll-2.14_old/include/gs_thread.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_thread.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,195 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_thread.h + * Exports from src/port/gs_thread.c. + * + * + * IDENTIFICATION + * src/include/gs_thread.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_THREAD_H_ +#define GS_THREAD_H_ + +#include "gs_threadlocal.h" + +#ifdef WIN32 +#include +#include +#else +#include +#endif + +#define gs_thread_id(_t) ((_t).thid) + +#ifdef WIN32 +#define gs_thread_handle(_t) ((HANDLE)(_t).os_handle) +typedef unsigned ThreadId; +typedef struct gs_thread_t { + ThreadId thid; + HANDLE os_handle; +} gs_thread_t; +#else + +typedef pthread_t ThreadId; +typedef struct gs_thread_t { + ThreadId thid; +} gs_thread_t; +#endif + +typedef enum knl_thread_role { + MASTER_THREAD = 0, + WORKER = 1, + THREADPOOL_WORKER = 2, + THREADPOOL_LISTENER, + THREADPOOL_SCHEDULER, + THREADPOOL_STREAM, + STREAM_WORKER, + AUTOVACUUM_LAUNCHER, + AUTOVACUUM_WORKER, + JOB_SCHEDULER, + JOB_WORKER, + WLM_WORKER, + WLM_MONITOR, + WLM_ARBITER, + WLM_CPMONITOR, + AUDITOR, + PGSTAT, + SYSLOGGER, + RPC_WORKER, + RPC_SERVICE, + CATCHUP, + ARCH, + ALARMCHECK, + REAPER, + PAGEREDO, + TWOPASECLEANER, + STARTUP, + FAULTMONITOR, + BGWRITER, + PERCENTILE_WORKER, + SNAPSHOT_WORKER, + ASH_WORKER, + STATEMENT_WORKER, + CHECKPOINT_THREAD, + WALWRITER, + WALWRITERAUXILIARY, + WALRECEIVER, + WALRECWRITE, + DATARECIVER, + DATARECWRITER, + CBMWRITER, + PAGEWRITER_THREAD, + HEARTBEAT, + COMM_SENDERFLOWER, + COMM_RECEIVERFLOWER, + COMM_RECEIVER, + COMM_AUXILIARY, + COMM_POOLER_CLEAN, + CSNMIN_SYNC, + TS_COMPACTION, + TS_COMPACTION_CONSUMER, + TS_COMPACTION_AUXILIAY, + STREAMING_BACKEND, + STREAMING_ROUTER_BACKEND, + STREAMING_WORKER_BACKEND, + STREAMING_COLLECTOR_BACKEND, + STREAMING_QUEUE_BACKEND, + STREAMING_REAPER_BACKEND, + /* should be last valid thread. */ + THREAD_ENTRY_BOUND, + + NO_SUBROLE, + REDISTRIBUTION_WORKER, + WAL_NORMAL_SENDER, + WAL_STANDBY_SENDER, /* Am I cascading WAL to another standby ? */ + WAL_DB_SENDER, + TOP_CONSUMER, +} knl_thread_role; + +/* + * It is an 64bit identifier in Linux x64 system. There are many legacy + * code assumes the original pid is 32 bit where we replace with threadId. + * If printf this number, we use %lu within the server. When compare valid + * ThreadIds, use PtThread::Equal() function. + */ +#define INVALID_NEXT_ADDR (void*)((unsigned long)(-1)) + +typedef struct knl_thread_arg { + knl_thread_role role; + char* save_para; + void* payload; + void* t_thrd; + union { + struct syslog_thread { + int syslog_handle; + } log_thread; + } extra_payload; +} knl_thread_arg; + +typedef int (*GaussdbThreadEntry)(knl_thread_arg* arg); + +typedef struct ThreadMetaData { + GaussdbThreadEntry func; + knl_thread_role role; + const char* thr_name; /* keep strlen(thr_name) < 16 */ + const char* thr_long_name; +} ThreadMetaData; + +/* + * A generic holder to keep all necessary arguments passed to generic + * ThreadStarterFunc() function. + */ +typedef struct ThreadArg { + void* (*m_taskRoutine)(void*); /* Task function caller passed in by the caller. */ + struct ThreadArg* next; /* if next is INVALID_NEXT_ID, the ThreadArg is malloc when create a thread */ + knl_thread_arg m_thd_arg; +} ThreadArg; + +#define InvalidTid ((ThreadId)(-1)) /* An invalid thread identifier */ + +#ifdef WIN32 +extern HANDLE gs_thread_get_handle(unsigned ThreadId); +#endif + +extern gs_thread_t gs_thread_get_cur_thread(void); + +extern ThreadId gs_thread_self(void); + +extern void gs_thread_exit(int code); +extern void gs_thread_args_free(void); + +extern int gs_thread_create(gs_thread_t* thread, void* (*taskRoutine)(void*), int argc, void* argv); + +extern int gs_thread_join(gs_thread_t thread, void** value_ptr); + +extern void gs_thread_args_pool_init(unsigned long pool_size, unsigned long backend_para_size); + +extern void gs_thread_release_args_slot(ThreadArg* thrArg); + +extern ThreadArg* gs_thread_get_args_slot(void); + +extern void gs_thread_get_name(char** name_thread, char** argv, int argc); + +extern void ThreadExitCXX(int code); +extern int ShowThreadName(const char* name); + +typedef void (*uuid_struct_destroy_hook_type)(int which); +extern THR_LOCAL uuid_struct_destroy_hook_type uuid_struct_destroy_hook; + +#endif /*GS_THREAD_H_ */ diff -uprN postgresql-hll-2.14_old/include/gs_threadlocal.h postgresql-hll-2.14/include/gs_threadlocal.h --- postgresql-hll-2.14_old/include/gs_threadlocal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gs_threadlocal.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_threadlocal.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gs_threadlocal.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_THREADLOCAL_H_ +#define GS_THREADLOCAL_H_ + +/*PClint*/ +#ifdef PC_LINT +#define THR_LOCAL +#endif + +#ifndef THR_LOCAL +#ifndef WIN32 +#define THR_LOCAL __thread +#else +#define THR_LOCAL __declspec(thread) +#endif +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/gstrace/access_gstrace.h postgresql-hll-2.14/include/gstrace/access_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/access_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/access_gstrace.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,121 @@ +// This is a generated file + +#ifndef _ACCESS_GSTRACE_H +#define _ACCESS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_heap_compute_data_size GS_TRC_ID_PACK(COMP_ACCESS, 1) +#define GS_TRC_ID_heap_fill_tuple GS_TRC_ID_PACK(COMP_ACCESS, 2) +#define GS_TRC_ID_heap_attisnull GS_TRC_ID_PACK(COMP_ACCESS, 3) +#define GS_TRC_ID_nocache_cmprs_get_attr GS_TRC_ID_PACK(COMP_ACCESS, 4) +#define GS_TRC_ID_nocachegetattr GS_TRC_ID_PACK(COMP_ACCESS, 5) +#define GS_TRC_ID_heap_getsysattr GS_TRC_ID_PACK(COMP_ACCESS, 6) +#define GS_TRC_ID_heap_copytuple GS_TRC_ID_PACK(COMP_ACCESS, 7) +#define GS_TRC_ID_heapCopyCompressedTuple GS_TRC_ID_PACK(COMP_ACCESS, 8) +#define GS_TRC_ID_heapCopyTuple GS_TRC_ID_PACK(COMP_ACCESS, 9) +#define GS_TRC_ID_heap_copytuple_with_tuple GS_TRC_ID_PACK(COMP_ACCESS, 10) +#define GS_TRC_ID_heap_form_tuple GS_TRC_ID_PACK(COMP_ACCESS, 11) +#define GS_TRC_ID_heap_form_cmprs_tuple GS_TRC_ID_PACK(COMP_ACCESS, 12) +#define GS_TRC_ID_heap_modify_tuple GS_TRC_ID_PACK(COMP_ACCESS, 13) +#define GS_TRC_ID_heap_deform_cmprs_tuple GS_TRC_ID_PACK(COMP_ACCESS, 14) +#define GS_TRC_ID_heap_deform_tuple GS_TRC_ID_PACK(COMP_ACCESS, 15) +#define GS_TRC_ID_heap_deform_tuple2 GS_TRC_ID_PACK(COMP_ACCESS, 16) +#define GS_TRC_ID_heap_deform_tuple3 GS_TRC_ID_PACK(COMP_ACCESS, 17) +#define GS_TRC_ID_heap_formtuple GS_TRC_ID_PACK(COMP_ACCESS, 18) +#define GS_TRC_ID_heap_modifytuple GS_TRC_ID_PACK(COMP_ACCESS, 19) +#define GS_TRC_ID_heap_deformtuple GS_TRC_ID_PACK(COMP_ACCESS, 20) +#define GS_TRC_ID_heap_freetuple GS_TRC_ID_PACK(COMP_ACCESS, 21) +#define GS_TRC_ID_heap_form_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 22) +#define GS_TRC_ID_heap_free_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 23) +#define GS_TRC_ID_heap_copy_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 24) +#define GS_TRC_ID_heap_tuple_from_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 25) +#define GS_TRC_ID_minimal_tuple_from_heap_tuple GS_TRC_ID_PACK(COMP_ACCESS, 26) +#define GS_TRC_ID_heapGetInitDefVal GS_TRC_ID_PACK(COMP_ACCESS, 27) +#define GS_TRC_ID_relationAttIsNull GS_TRC_ID_PACK(COMP_ACCESS, 28) +#define GS_TRC_ID_heapFormMinimalTuple GS_TRC_ID_PACK(COMP_ACCESS, 29) +#define GS_TRC_ID_XLogInsertRecord GS_TRC_ID_PACK(COMP_ACCESS, 30) +#define GS_TRC_ID_XLogFlush GS_TRC_ID_PACK(COMP_ACCESS, 31) +#define GS_TRC_ID_XLogBackgroundFlush GS_TRC_ID_PACK(COMP_ACCESS, 32) +#define GS_TRC_ID_XLogNeedsFlush GS_TRC_ID_PACK(COMP_ACCESS, 33) +#define GS_TRC_ID_XLogFileInit GS_TRC_ID_PACK(COMP_ACCESS, 34) +#define GS_TRC_ID_XLogFileOpen GS_TRC_ID_PACK(COMP_ACCESS, 35) +#define GS_TRC_ID_CheckXLogRemoved GS_TRC_ID_PACK(COMP_ACCESS, 36) +#define GS_TRC_ID_XLogSetAsyncXactLSN GS_TRC_ID_PACK(COMP_ACCESS, 37) +#define GS_TRC_ID_XLogSetReplicationSlotMinimumLSN GS_TRC_ID_PACK(COMP_ACCESS, 38) +#define GS_TRC_ID_XLogSetReplicationSlotMaximumLSN GS_TRC_ID_PACK(COMP_ACCESS, 39) +#define GS_TRC_ID_XLogGetReplicationSlotMaximumLSN GS_TRC_ID_PACK(COMP_ACCESS, 40) +#define GS_TRC_ID_xlog_redo GS_TRC_ID_PACK(COMP_ACCESS, 41) +#define GS_TRC_ID_xlog_desc GS_TRC_ID_PACK(COMP_ACCESS, 42) +#define GS_TRC_ID_issue_xlog_fsync GS_TRC_ID_PACK(COMP_ACCESS, 43) +#define GS_TRC_ID_RecoveryInProgress GS_TRC_ID_PACK(COMP_ACCESS, 44) +#define GS_TRC_ID_HotStandbyActive GS_TRC_ID_PACK(COMP_ACCESS, 45) +#define GS_TRC_ID_HotStandbyActiveInReplay GS_TRC_ID_PACK(COMP_ACCESS, 46) +#define GS_TRC_ID_XLogInsertAllowed GS_TRC_ID_PACK(COMP_ACCESS, 47) +#define GS_TRC_ID_GetXLogReceiptTime GS_TRC_ID_PACK(COMP_ACCESS, 48) +#define GS_TRC_ID_GetXLogReplayRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 49) +#define GS_TRC_ID_GetXLogReplayRecPtrInPending GS_TRC_ID_PACK(COMP_ACCESS, 50) +#define GS_TRC_ID_GetStandbyFlushRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 51) +#define GS_TRC_ID_GetXLogInsertRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 52) +#define GS_TRC_ID_GetXLogWriteRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 53) +#define GS_TRC_ID_RecoveryIsPaused GS_TRC_ID_PACK(COMP_ACCESS, 54) +#define GS_TRC_ID_SetRecoveryPause GS_TRC_ID_PACK(COMP_ACCESS, 55) +#define GS_TRC_ID_GetLatestXTime GS_TRC_ID_PACK(COMP_ACCESS, 56) +#define GS_TRC_ID_GetCurrentChunkReplayStartTime GS_TRC_ID_PACK(COMP_ACCESS, 57) +#define GS_TRC_ID_GetXlogRecordCrc GS_TRC_ID_PACK(COMP_ACCESS, 58) +#define GS_TRC_ID_UpdateControlFile GS_TRC_ID_PACK(COMP_ACCESS, 59) +#define GS_TRC_ID_GetSystemIdentifier GS_TRC_ID_PACK(COMP_ACCESS, 60) +#define GS_TRC_ID_SetSystemIdentifier GS_TRC_ID_PACK(COMP_ACCESS, 61) +#define GS_TRC_ID_GetThisTimeID GS_TRC_ID_PACK(COMP_ACCESS, 62) +#define GS_TRC_ID_SetThisTimeID GS_TRC_ID_PACK(COMP_ACCESS, 63) +#define GS_TRC_ID_XLOGShmemSize GS_TRC_ID_PACK(COMP_ACCESS, 64) +#define GS_TRC_ID_XLOGShmemInit GS_TRC_ID_PACK(COMP_ACCESS, 65) +#define GS_TRC_ID_BootStrapXLOG GS_TRC_ID_PACK(COMP_ACCESS, 66) +#define GS_TRC_ID_StartupXLOG GS_TRC_ID_PACK(COMP_ACCESS, 67) +#define GS_TRC_ID_ShutdownXLOG GS_TRC_ID_PACK(COMP_ACCESS, 68) +#define GS_TRC_ID_InitXLOGAccess GS_TRC_ID_PACK(COMP_ACCESS, 69) +#define GS_TRC_ID_StartupDummyStandby GS_TRC_ID_PACK(COMP_ACCESS, 70) +#define GS_TRC_ID_CreateCheckPoint GS_TRC_ID_PACK(COMP_ACCESS, 71) +#define GS_TRC_ID_CreateRestartPoint GS_TRC_ID_PACK(COMP_ACCESS, 72) +#define GS_TRC_ID_CheckPointGuts GS_TRC_ID_PACK(COMP_ACCESS, 73) +#define GS_TRC_ID_XLogPutNextOid GS_TRC_ID_PACK(COMP_ACCESS, 74) +#define GS_TRC_ID_XLogRestorePoint GS_TRC_ID_PACK(COMP_ACCESS, 75) +#define GS_TRC_ID_UpdateFullPageWrites GS_TRC_ID_PACK(COMP_ACCESS, 76) +#define GS_TRC_ID_GetFullPageWriteInfo GS_TRC_ID_PACK(COMP_ACCESS, 77) +#define GS_TRC_ID_GetRedoRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 78) +#define GS_TRC_ID_GetInsertRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 79) +#define GS_TRC_ID_GetFlushRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 80) +#define GS_TRC_ID_GetNextXidAndEpoch GS_TRC_ID_PACK(COMP_ACCESS, 81) +#define GS_TRC_ID_GetRecoveryTargetTLI GS_TRC_ID_PACK(COMP_ACCESS, 82) +#define GS_TRC_ID_DummyStandbySetRecoveryTargetTLI GS_TRC_ID_PACK(COMP_ACCESS, 83) +#define GS_TRC_ID_CheckPromoteSignal GS_TRC_ID_PACK(COMP_ACCESS, 84) +#define GS_TRC_ID_CheckPrimarySignal GS_TRC_ID_PACK(COMP_ACCESS, 85) +#define GS_TRC_ID_CheckStandbySignal GS_TRC_ID_PACK(COMP_ACCESS, 86) +#define GS_TRC_ID_CheckSwitchoverSignal GS_TRC_ID_PACK(COMP_ACCESS, 87) +#define GS_TRC_ID_ReadLsnXlogFlushChkFile GS_TRC_ID_PACK(COMP_ACCESS, 88) +#define GS_TRC_ID_WakeupRecovery GS_TRC_ID_PACK(COMP_ACCESS, 89) +#define GS_TRC_ID_WakeupDataRecovery GS_TRC_ID_PACK(COMP_ACCESS, 90) +#define GS_TRC_ID_SetWalWriterSleeping GS_TRC_ID_PACK(COMP_ACCESS, 91) +#define GS_TRC_ID_CheckFpwBeforeFirstCkpt GS_TRC_ID_PACK(COMP_ACCESS, 92) +#define GS_TRC_ID_DisableFpwBeforeFirstCkpt GS_TRC_ID_PACK(COMP_ACCESS, 93) +#define GS_TRC_ID_UpdateLsnXlogFlushChkFile GS_TRC_ID_PACK(COMP_ACCESS, 94) +#define GS_TRC_ID_LsnXlogFlushChkShmemSize GS_TRC_ID_PACK(COMP_ACCESS, 95) +#define GS_TRC_ID_LsnXlogFlushChkShmInit GS_TRC_ID_PACK(COMP_ACCESS, 96) +#define GS_TRC_ID_IfLsnXlogFlushChkFileExist GS_TRC_ID_PACK(COMP_ACCESS, 97) +#define GS_TRC_ID_heap_xlog_logical_new_page GS_TRC_ID_PACK(COMP_ACCESS, 98) +#define GS_TRC_ID_StartTransaction GS_TRC_ID_PACK(COMP_ACCESS, 99) +#define GS_TRC_ID_KeepLogSeg GS_TRC_ID_PACK(COMP_ACCESS, 100) +#define GS_TRC_ID_RemoveOldXlogFiles GS_TRC_ID_PACK(COMP_ACCESS, 101) +#define GS_TRC_ID_dw_truncate GS_TRC_ID_PACK(COMP_ACCESS, 102) +#define GS_TRC_ID_heap_change_xidbase_after_freeze GS_TRC_ID_PACK(COMP_ACCESS, 103) +#define GS_TRC_ID_heap_page_prepare_for_xid GS_TRC_ID_PACK(COMP_ACCESS, 104) +#define GS_TRC_ID_ExtendCSNLOG GS_TRC_ID_PACK(COMP_ACCESS, 105) +#define GS_TRC_ID_freeze_single_heap_page GS_TRC_ID_PACK(COMP_ACCESS, 106) +#define GS_TRC_ID_heap_page_prune GS_TRC_ID_PACK(COMP_ACCESS, 107) +#define GS_TRC_ID_heap_prune_chain GS_TRC_ID_PACK(COMP_ACCESS, 108) +#define GS_TRC_ID_PreallocXlogFiles GS_TRC_ID_PACK(COMP_ACCESS, 109) +#define GS_TRC_ID_do_pg_stop_backup GS_TRC_ID_PACK(COMP_ACCESS, 110) +#define GS_TRC_ID_do_pg_start_backup GS_TRC_ID_PACK(COMP_ACCESS, 111) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/bootstrap_gstrace.h postgresql-hll-2.14/include/gstrace/bootstrap_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/bootstrap_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/bootstrap_gstrace.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,25 @@ +// This is a generated file + +#ifndef _BOOTSTRAP_GSTRACE_H +#define _BOOTSTRAP_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_AuxiliaryProcessMain GS_TRC_ID_PACK(COMP_BOOTSTRAP, 1) +#define GS_TRC_ID_err_out GS_TRC_ID_PACK(COMP_BOOTSTRAP, 2) +#define GS_TRC_ID_closerel GS_TRC_ID_PACK(COMP_BOOTSTRAP, 3) +#define GS_TRC_ID_boot_openrel GS_TRC_ID_PACK(COMP_BOOTSTRAP, 4) +#define GS_TRC_ID_DefineAttr GS_TRC_ID_PACK(COMP_BOOTSTRAP, 5) +#define GS_TRC_ID_InsertOneTuple GS_TRC_ID_PACK(COMP_BOOTSTRAP, 6) +#define GS_TRC_ID_InsertOneValue GS_TRC_ID_PACK(COMP_BOOTSTRAP, 7) +#define GS_TRC_ID_InsertOneNull GS_TRC_ID_PACK(COMP_BOOTSTRAP, 8) +#define GS_TRC_ID_MapArrayTypeName GS_TRC_ID_PACK(COMP_BOOTSTRAP, 9) +#define GS_TRC_ID_index_register GS_TRC_ID_PACK(COMP_BOOTSTRAP, 10) +#define GS_TRC_ID_build_indices GS_TRC_ID_PACK(COMP_BOOTSTRAP, 11) +#define GS_TRC_ID_boot_get_type_io_data GS_TRC_ID_PACK(COMP_BOOTSTRAP, 12) +#define GS_TRC_ID_boot_yyparse GS_TRC_ID_PACK(COMP_BOOTSTRAP, 13) +#define GS_TRC_ID_boot_yylex GS_TRC_ID_PACK(COMP_BOOTSTRAP, 14) +#define GS_TRC_ID_boot_yyerror GS_TRC_ID_PACK(COMP_BOOTSTRAP, 15) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/catalog_gstrace.h postgresql-hll-2.14/include/gstrace/catalog_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/catalog_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/catalog_gstrace.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,54 @@ +// This is a generated file + +#ifndef _CATALOG_GSTRACE_H +#define _CATALOG_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_forkname_to_number GS_TRC_ID_PACK(COMP_CATALOG, 1) +#define GS_TRC_ID_forkname_chars GS_TRC_ID_PACK(COMP_CATALOG, 2) +#define GS_TRC_ID_relpathbackend GS_TRC_ID_PACK(COMP_CATALOG, 3) +#define GS_TRC_ID_GetDatabasePath GS_TRC_ID_PACK(COMP_CATALOG, 4) +#define GS_TRC_ID_relpath_to_filenode GS_TRC_ID_PACK(COMP_CATALOG, 5) +#define GS_TRC_ID_IsSystemRelation GS_TRC_ID_PACK(COMP_CATALOG, 6) +#define GS_TRC_ID_IsToastRelation GS_TRC_ID_PACK(COMP_CATALOG, 7) +#define GS_TRC_ID_IsSystemClass GS_TRC_ID_PACK(COMP_CATALOG, 8) +#define GS_TRC_ID_IsToastClass GS_TRC_ID_PACK(COMP_CATALOG, 9) +#define GS_TRC_ID_IsSystemNamespace GS_TRC_ID_PACK(COMP_CATALOG, 10) +#define GS_TRC_ID_IsToastNamespace GS_TRC_ID_PACK(COMP_CATALOG, 11) +#define GS_TRC_ID_IsCStoreNamespace GS_TRC_ID_PACK(COMP_CATALOG, 12) +#define GS_TRC_ID_IsReservedName GS_TRC_ID_PACK(COMP_CATALOG, 13) +#define GS_TRC_ID_IsSharedRelation GS_TRC_ID_PACK(COMP_CATALOG, 14) +#define GS_TRC_ID_GetNewOid GS_TRC_ID_PACK(COMP_CATALOG, 15) +#define GS_TRC_ID_GetNewOidWithIndex GS_TRC_ID_PACK(COMP_CATALOG, 16) +#define GS_TRC_ID_GetNewRelFileNode GS_TRC_ID_PACK(COMP_CATALOG, 17) +#define GS_TRC_ID_heap_truncate GS_TRC_ID_PACK(COMP_CATALOG, 18) +#define GS_TRC_ID_heap_truncate_one_rel GS_TRC_ID_PACK(COMP_CATALOG, 19) +#define GS_TRC_ID_heap_truncate_check_FKs GS_TRC_ID_PACK(COMP_CATALOG, 20) +#define GS_TRC_ID_heap_truncate_find_FKs GS_TRC_ID_PACK(COMP_CATALOG, 21) +#define GS_TRC_ID_InsertPgAttributeTuple GS_TRC_ID_PACK(COMP_CATALOG, 22) +#define GS_TRC_ID_InsertPgClassTuple GS_TRC_ID_PACK(COMP_CATALOG, 23) +#define GS_TRC_ID_AddRelationNewConstraints GS_TRC_ID_PACK(COMP_CATALOG, 24) +#define GS_TRC_ID_AddRelClusterConstraints GS_TRC_ID_PACK(COMP_CATALOG, 25) +#define GS_TRC_ID_StoreAttrDefault GS_TRC_ID_PACK(COMP_CATALOG, 26) +#define GS_TRC_ID_cookDefault GS_TRC_ID_PACK(COMP_CATALOG, 27) +#define GS_TRC_ID_DeleteRelationTuple GS_TRC_ID_PACK(COMP_CATALOG, 28) +#define GS_TRC_ID_DeleteAttributeTuples GS_TRC_ID_PACK(COMP_CATALOG, 29) +#define GS_TRC_ID_DeleteSystemAttributeTuples GS_TRC_ID_PACK(COMP_CATALOG, 30) +#define GS_TRC_ID_RemoveAttributeById GS_TRC_ID_PACK(COMP_CATALOG, 31) +#define GS_TRC_ID_RemoveAttrDefault GS_TRC_ID_PACK(COMP_CATALOG, 32) +#define GS_TRC_ID_RemoveAttrDefaultById GS_TRC_ID_PACK(COMP_CATALOG, 33) +#define GS_TRC_ID_RemoveStatistics GS_TRC_ID_PACK(COMP_CATALOG, 34) +#define GS_TRC_ID_SystemAttributeDefinition GS_TRC_ID_PACK(COMP_CATALOG, 35) +#define GS_TRC_ID_SystemAttributeByName GS_TRC_ID_PACK(COMP_CATALOG, 36) +#define GS_TRC_ID_CheckAttributeNamesTypes GS_TRC_ID_PACK(COMP_CATALOG, 37) +#define GS_TRC_ID_CheckAttributeType GS_TRC_ID_PACK(COMP_CATALOG, 38) +#define GS_TRC_ID_AddRelationDistribution GS_TRC_ID_PACK(COMP_CATALOG, 39) +#define GS_TRC_ID_GetRelationDistributionItems GS_TRC_ID_PACK(COMP_CATALOG, 40) +#define GS_TRC_ID_GetRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 41) +#define GS_TRC_ID_BuildRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 42) +#define GS_TRC_ID_SortRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 43) +#define GS_TRC_ID_SetRelHasClusterKey GS_TRC_ID_PACK(COMP_CATALOG, 44) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/commands_gstrace.h postgresql-hll-2.14/include/gstrace/commands_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/commands_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/commands_gstrace.h 2020-12-12 17:06:43.120346400 +0800 @@ -0,0 +1,53 @@ +// This is a generated file + +#ifndef _COMMANDS_GSTRACE_H +#define _COMMANDS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_createdb GS_TRC_ID_PACK(COMP_COMMANDS, 1) +#define GS_TRC_ID_dropdb GS_TRC_ID_PACK(COMP_COMMANDS, 2) +#define GS_TRC_ID_RenameDatabase GS_TRC_ID_PACK(COMP_COMMANDS, 3) +#define GS_TRC_ID_AlterDatabase GS_TRC_ID_PACK(COMP_COMMANDS, 4) +#define GS_TRC_ID_AlterDatabaseSet GS_TRC_ID_PACK(COMP_COMMANDS, 5) +#define GS_TRC_ID_AlterDatabaseOwner GS_TRC_ID_PACK(COMP_COMMANDS, 6) +#define GS_TRC_ID_get_database_oid GS_TRC_ID_PACK(COMP_COMMANDS, 7) +#define GS_TRC_ID_get_database_name GS_TRC_ID_PACK(COMP_COMMANDS, 8) +#define GS_TRC_ID_dbase_redo GS_TRC_ID_PACK(COMP_COMMANDS, 9) +#define GS_TRC_ID_dbase_desc GS_TRC_ID_PACK(COMP_COMMANDS, 10) +#define GS_TRC_ID_check_encoding_locale_matches GS_TRC_ID_PACK(COMP_COMMANDS, 11) +#define GS_TRC_ID_IsSetTableSpace GS_TRC_ID_PACK(COMP_COMMANDS, 12) +#define GS_TRC_ID_errdetail_busy_db GS_TRC_ID_PACK(COMP_COMMANDS, 13) +#define GS_TRC_ID_PreCleanAndCheckConns GS_TRC_ID_PACK(COMP_COMMANDS, 14) +#define GS_TRC_ID_vacuum GS_TRC_ID_PACK(COMP_COMMANDS, 15) +#define GS_TRC_ID_vac_open_indexes GS_TRC_ID_PACK(COMP_COMMANDS, 16) +#define GS_TRC_ID_vac_close_indexes GS_TRC_ID_PACK(COMP_COMMANDS, 17) +#define GS_TRC_ID_vac_estimate_reltuples GS_TRC_ID_PACK(COMP_COMMANDS, 18) +#define GS_TRC_ID_vac_update_relstats GS_TRC_ID_PACK(COMP_COMMANDS, 19) +#define GS_TRC_ID_vacuum_set_xid_limits GS_TRC_ID_PACK(COMP_COMMANDS, 20) +#define GS_TRC_ID_vac_update_datfrozenxid GS_TRC_ID_PACK(COMP_COMMANDS, 21) +#define GS_TRC_ID_vacuum_delay_point GS_TRC_ID_PACK(COMP_COMMANDS, 22) +#define GS_TRC_ID_analyze_rel GS_TRC_ID_PACK(COMP_COMMANDS, 23) +#define GS_TRC_ID_buildTempSampleTable GS_TRC_ID_PACK(COMP_COMMANDS, 24) +#define GS_TRC_ID_dropSampleTable GS_TRC_ID_PACK(COMP_COMMANDS, 25) +#define GS_TRC_ID_DefineRelation GS_TRC_ID_PACK(COMP_COMMANDS, 26) +#define GS_TRC_ID_RemoveRelations GS_TRC_ID_PACK(COMP_COMMANDS, 27) +#define GS_TRC_ID_AlterTableLookupRelation GS_TRC_ID_PACK(COMP_COMMANDS, 28) +#define GS_TRC_ID_AlterTable GS_TRC_ID_PACK(COMP_COMMANDS, 29) +#define GS_TRC_ID_AlterTableGetLockLevel GS_TRC_ID_PACK(COMP_COMMANDS, 30) +#define GS_TRC_ID_ATExecChangeOwner GS_TRC_ID_PACK(COMP_COMMANDS, 31) +#define GS_TRC_ID_AlterTableInternal GS_TRC_ID_PACK(COMP_COMMANDS, 32) +#define GS_TRC_ID_AlterTableNamespace GS_TRC_ID_PACK(COMP_COMMANDS, 33) +#define GS_TRC_ID_AlterTableNamespaceInternal GS_TRC_ID_PACK(COMP_COMMANDS, 34) +#define GS_TRC_ID_AlterRelationNamespaceInternal GS_TRC_ID_PACK(COMP_COMMANDS, 35) +#define GS_TRC_ID_vacuum_rel GS_TRC_ID_PACK(COMP_COMMANDS, 36) +#define GS_TRC_ID_cluster_rel GS_TRC_ID_PACK(COMP_COMMANDS, 37) +#define GS_TRC_ID_lazy_scan_heap GS_TRC_ID_PACK(COMP_COMMANDS, 38) +#define GS_TRC_ID_lazy_vacuum_rel GS_TRC_ID_PACK(COMP_COMMANDS, 39) +#define GS_TRC_ID_lazy_vacuum_index GS_TRC_ID_PACK(COMP_COMMANDS, 40) +#define GS_TRC_ID_lazy_vacuum_heap GS_TRC_ID_PACK(COMP_COMMANDS, 41) +#define GS_TRC_ID_lazy_truncate_heap GS_TRC_ID_PACK(COMP_COMMANDS, 42) +#define GS_TRC_ID_lazy_cleanup_index GS_TRC_ID_PACK(COMP_COMMANDS, 43) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/common_gstrace.h postgresql-hll-2.14/include/gstrace/common_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/common_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/common_gstrace.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,13 @@ +// This is a generated file + +#ifndef _COMMON_GSTRACE_H +#define _COMMON_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_charshow_estimated_time GS_TRC_ID_PACK(COMP_COMMON, 1) +#define GS_TRC_ID_charshow_datasize GS_TRC_ID_PACK(COMP_COMMON, 2) +#define GS_TRC_ID_UpdateDBStateFile GS_TRC_ID_PACK(COMP_COMMON, 3) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/comps.h postgresql-hll-2.14/include/gstrace/comps.h --- postgresql-hll-2.14_old/include/gstrace/comps.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/comps.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,28 @@ +// This is a generated file + +#ifndef _COMPS_H +#define _COMPS_H + +#define COMP_COMMON 1 +#define COMP_LIBPQ 2 +#define COMP_PG_CTL 3 +#define COMP_ACCESS 4 +#define COMP_BOOTSTRAP 5 +#define COMP_CATALOG 6 +#define COMP_PARSER 7 +#define COMP_COMMANDS 8 +#define COMP_EXECUTER 9 +#define COMP_VECEXECUTOR 10 +#define COMP_OPTIMIZER 11 +#define COMP_POSTMASTER 12 +#define COMP_REPLICATION 13 +#define COMP_REWRITE 14 +#define COMP_STORAGE 15 +#define COMP_TCOP 16 +#define COMP_TSEARCH 17 +#define COMP_UTILS 18 +#define COMP_WLM 19 +#define COMP_SYSTEM 20 +#define COMP_MAX 21 + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/executer_gstrace.h postgresql-hll-2.14/include/gstrace/executer_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/executer_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/executer_gstrace.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,89 @@ +// This is a generated file + +#ifndef _EXECUTER_GSTRACE_H +#define _EXECUTER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_execTuplesMatch GS_TRC_ID_PACK(COMP_EXECUTER, 1) +#define GS_TRC_ID_execTuplesUnequal GS_TRC_ID_PACK(COMP_EXECUTER, 2) +#define GS_TRC_ID_execTuplesMatchPrepare GS_TRC_ID_PACK(COMP_EXECUTER, 3) +#define GS_TRC_ID_execTuplesHashPrepare GS_TRC_ID_PACK(COMP_EXECUTER, 4) +#define GS_TRC_ID_BuildTupleHashTable GS_TRC_ID_PACK(COMP_EXECUTER, 5) +#define GS_TRC_ID_LookupTupleHashEntry GS_TRC_ID_PACK(COMP_EXECUTER, 6) +#define GS_TRC_ID_FindTupleHashEntry GS_TRC_ID_PACK(COMP_EXECUTER, 7) +#define GS_TRC_ID_ExecInitJunkFilter GS_TRC_ID_PACK(COMP_EXECUTER, 8) +#define GS_TRC_ID_ExecInitJunkFilterConversion GS_TRC_ID_PACK(COMP_EXECUTER, 9) +#define GS_TRC_ID_ExecFindJunkAttribute GS_TRC_ID_PACK(COMP_EXECUTER, 10) +#define GS_TRC_ID_ExecFindJunkAttributeInTlist GS_TRC_ID_PACK(COMP_EXECUTER, 11) +#define GS_TRC_ID_ExecGetJunkAttribute GS_TRC_ID_PACK(COMP_EXECUTER, 12) +#define GS_TRC_ID_ExecFilterJunk GS_TRC_ID_PACK(COMP_EXECUTER, 13) +#define GS_TRC_ID_ExecSetjunkFilteDescriptor GS_TRC_ID_PACK(COMP_EXECUTER, 14) +#define GS_TRC_ID_ExecFindJunkPrimaryKeys GS_TRC_ID_PACK(COMP_EXECUTER, 15) +#define GS_TRC_ID_BatchExecFilterJunk GS_TRC_ID_PACK(COMP_EXECUTER, 16) +#define GS_TRC_ID_BatchCheckNodeIdentifier GS_TRC_ID_PACK(COMP_EXECUTER, 17) +#define GS_TRC_ID_ExecGetPlanNodeid GS_TRC_ID_PACK(COMP_EXECUTER, 18) +#define GS_TRC_ID_ExecutorStart GS_TRC_ID_PACK(COMP_EXECUTER, 19) +#define GS_TRC_ID_standard_ExecutorStart GS_TRC_ID_PACK(COMP_EXECUTER, 20) +#define GS_TRC_ID_ExecutorRun GS_TRC_ID_PACK(COMP_EXECUTER, 21) +#define GS_TRC_ID_standard_ExecutorRun GS_TRC_ID_PACK(COMP_EXECUTER, 22) +#define GS_TRC_ID_ExecutorFinish GS_TRC_ID_PACK(COMP_EXECUTER, 23) +#define GS_TRC_ID_standard_ExecutorFinish GS_TRC_ID_PACK(COMP_EXECUTER, 24) +#define GS_TRC_ID_ExecutorEnd GS_TRC_ID_PACK(COMP_EXECUTER, 25) +#define GS_TRC_ID_standard_ExecutorEnd GS_TRC_ID_PACK(COMP_EXECUTER, 26) +#define GS_TRC_ID_ExecutorRewind GS_TRC_ID_PACK(COMP_EXECUTER, 27) +#define GS_TRC_ID_ExecCheckRTPerms GS_TRC_ID_PACK(COMP_EXECUTER, 28) +#define GS_TRC_ID_CheckValidResultRel GS_TRC_ID_PACK(COMP_EXECUTER, 29) +#define GS_TRC_ID_InitResultRelInfo GS_TRC_ID_PACK(COMP_EXECUTER, 30) +#define GS_TRC_ID_ExecGetTriggerResultRel GS_TRC_ID_PACK(COMP_EXECUTER, 31) +#define GS_TRC_ID_ExecContextForcesOids GS_TRC_ID_PACK(COMP_EXECUTER, 32) +#define GS_TRC_ID_ExecConstraints GS_TRC_ID_PACK(COMP_EXECUTER, 33) +#define GS_TRC_ID_ExecFindRowMark GS_TRC_ID_PACK(COMP_EXECUTER, 34) +#define GS_TRC_ID_ExecBuildAuxRowMark GS_TRC_ID_PACK(COMP_EXECUTER, 35) +#define GS_TRC_ID_EvalPlanQual GS_TRC_ID_PACK(COMP_EXECUTER, 36) +#define GS_TRC_ID_EvalPlanQualFetch GS_TRC_ID_PACK(COMP_EXECUTER, 37) +#define GS_TRC_ID_EvalPlanQualInit GS_TRC_ID_PACK(COMP_EXECUTER, 38) +#define GS_TRC_ID_EvalPlanQualSetPlan GS_TRC_ID_PACK(COMP_EXECUTER, 39) +#define GS_TRC_ID_EvalPlanQualSetTuple GS_TRC_ID_PACK(COMP_EXECUTER, 40) +#define GS_TRC_ID_EvalPlanQualGetTuple GS_TRC_ID_PACK(COMP_EXECUTER, 41) +#define GS_TRC_ID_EvalPlanQualFetchRowMarks GS_TRC_ID_PACK(COMP_EXECUTER, 42) +#define GS_TRC_ID_EvalPlanQualNext GS_TRC_ID_PACK(COMP_EXECUTER, 43) +#define GS_TRC_ID_EvalPlanQualBegin GS_TRC_ID_PACK(COMP_EXECUTER, 44) +#define GS_TRC_ID_EvalPlanQualEnd GS_TRC_ID_PACK(COMP_EXECUTER, 45) +#define GS_TRC_ID_ExecInitNode GS_TRC_ID_PACK(COMP_EXECUTER, 46) +#define GS_TRC_ID_ExecProcNode GS_TRC_ID_PACK(COMP_EXECUTER, 47) +#define GS_TRC_ID_MultiExecProcNode GS_TRC_ID_PACK(COMP_EXECUTER, 48) +#define GS_TRC_ID_ExecEndNode GS_TRC_ID_PACK(COMP_EXECUTER, 49) +#define GS_TRC_ID_ExecGetPlanMemCost GS_TRC_ID_PACK(COMP_EXECUTER, 50) +#define GS_TRC_ID_GetAttributeByNum GS_TRC_ID_PACK(COMP_EXECUTER, 51) +#define GS_TRC_ID_GetAttributeByName GS_TRC_ID_PACK(COMP_EXECUTER, 52) +#define GS_TRC_ID_ExecMakeTableFunctionResult GS_TRC_ID_PACK(COMP_EXECUTER, 53) +#define GS_TRC_ID_ExecEvalExprSwitchContext GS_TRC_ID_PACK(COMP_EXECUTER, 54) +#define GS_TRC_ID_ExecInitExpr GS_TRC_ID_PACK(COMP_EXECUTER, 55) +#define GS_TRC_ID_ExecPrepareExpr GS_TRC_ID_PACK(COMP_EXECUTER, 56) +#define GS_TRC_ID_ExecQual GS_TRC_ID_PACK(COMP_EXECUTER, 57) +#define GS_TRC_ID_ExecTargetListLength GS_TRC_ID_PACK(COMP_EXECUTER, 58) +#define GS_TRC_ID_ExecCleanTargetListLength GS_TRC_ID_PACK(COMP_EXECUTER, 59) +#define GS_TRC_ID_ExecProject GS_TRC_ID_PACK(COMP_EXECUTER, 60) +#define GS_TRC_ID_ExecScan GS_TRC_ID_PACK(COMP_EXECUTER, 61) +#define GS_TRC_ID_ExecAssignScanProjectionInfo GS_TRC_ID_PACK(COMP_EXECUTER, 62) +#define GS_TRC_ID_ExecScanReScan GS_TRC_ID_PACK(COMP_EXECUTER, 63) +#define GS_TRC_ID_ExecInitResultTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 64) +#define GS_TRC_ID_ExecInitScanTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 65) +#define GS_TRC_ID_ExecInitExtraTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 66) +#define GS_TRC_ID_ExecInitNullTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 67) +#define GS_TRC_ID_ExecTypeFromTL GS_TRC_ID_PACK(COMP_EXECUTER, 68) +#define GS_TRC_ID_ExecCleanTypeFromTL GS_TRC_ID_PACK(COMP_EXECUTER, 69) +#define GS_TRC_ID_ExecTypeFromExprList GS_TRC_ID_PACK(COMP_EXECUTER, 70) +#define GS_TRC_ID_UpdateChangedParamSet GS_TRC_ID_PACK(COMP_EXECUTER, 71) +#define GS_TRC_ID_begin_tup_output_tupdesc GS_TRC_ID_PACK(COMP_EXECUTER, 72) +#define GS_TRC_ID_do_tup_output GS_TRC_ID_PACK(COMP_EXECUTER, 73) +#define GS_TRC_ID_do_text_output_multiline GS_TRC_ID_PACK(COMP_EXECUTER, 74) +#define GS_TRC_ID_end_tup_output GS_TRC_ID_PACK(COMP_EXECUTER, 75) +#define GS_TRC_ID_InitPlan GS_TRC_ID_PACK(COMP_EXECUTER, 76) +#define GS_TRC_ID_ExecCheckRTEPerms GS_TRC_ID_PACK(COMP_EXECUTER, 77) +#define GS_TRC_ID_ExecInitIndexScan GS_TRC_ID_PACK(COMP_EXECUTER, 78) +#define GS_TRC_ID_BypassExecutor GS_TRC_ID_PACK(COMP_EXECUTER, 79) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/funcs.comps.h postgresql-hll-2.14/include/gstrace/funcs.comps.h --- postgresql-hll-2.14_old/include/gstrace/funcs.comps.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/funcs.comps.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,921 @@ +// This is a generated file + +#include "comps.h" + +#ifndef _FUNCSCOMPS_H +#define _FUNCSCOMPS_H + +#define HASH_TRACE_CONFIG "588172a1f3a60b449ac8796c2361709035e6ddebcc8e9a2f2c7c43740096eafd" + +struct comp_func { + uint32_t comp; + uint32_t func_num; + const char **func_names; +}; + +struct comp_name { + uint32_t comp; + const char *compName; +}; + + +static const char* GS_TRC_COMMANDS_FUNC_NAMES[] = +{ + "", + "createdb", + "dropdb", + "RenameDatabase", + "AlterDatabase", + "AlterDatabaseSet", + "AlterDatabaseOwner", + "get_database_oid", + "get_database_name", + "dbase_redo", + "dbase_desc", + "check_encoding_locale_matches", + "IsSetTableSpace", + "errdetail_busy_db", + "PreCleanAndCheckConns", + "vacuum", + "vac_open_indexes", + "vac_close_indexes", + "vac_estimate_reltuples", + "vac_update_relstats", + "vacuum_set_xid_limits", + "vac_update_datfrozenxid", + "vacuum_delay_point", + "analyze_rel", + "buildTempSampleTable", + "dropSampleTable", + "DefineRelation", + "RemoveRelations", + "AlterTableLookupRelation", + "AlterTable", + "AlterTableGetLockLevel", + "ATExecChangeOwner", + "AlterTableInternal", + "AlterTableNamespace", + "AlterTableNamespaceInternal", + "AlterRelationNamespaceInternal", + "vacuum_rel", + "cluster_rel", + "lazy_scan_heap", + "lazy_vacuum_rel", + "lazy_vacuum_index", + "lazy_vacuum_heap", + "lazy_truncate_heap", + "lazy_cleanup_index" +}; + +static const char* GS_TRC_PARSER_FUNC_NAMES[] = +{ + "", + "make_parsestate", + "free_parsestate", + "parser_errposition", + "setup_parser_errposition_callback", + "cancel_parser_errposition_callback", + "make_var", + "transformArrayType", + "transformArraySubscripts", + "make_const", + "scanner_init", + "scanner_finish", + "core_yylex", + "scanner_errposition", + "scanner_yyerror" +}; + +static const char* GS_TRC_OPTIMIZER_FUNC_NAMES[] = +{ + "", + "clauselist_selectivity", + "clause_selectivity", + "set_rel_width", + "restore_hashjoin_cost", + "finalize_dml_cost", + "copy_mem_info", + "columnar_get_col_width", + "get_path_actual_total_width", + "query_planner", + "preprocess_minmax_aggregates", + "optimize_minmax_aggregates", + "set_plan_rows", + "create_plan", + "disuse_physical_tlist", + "copy_plan_costsize", + "make_subqueryscan", + "make_foreignscan", + "make_append", + "make_recursive_union", + "make_sort_from_pathkeys", + "make_sort_from_sortclauses", + "make_sort_from_groupcols", + "make_sort_from_targetlist", + "make_sort", + "make_agg", + "make_windowagg", + "make_group", + "materialize_finished_plan", + "make_unique", + "make_lockrows", + "make_limit", + "make_stream_limit", + "compare_path_costs", + "compare_fractional_path_costs", + "set_cheapest", + "get_cheapest_path", + "find_hinted_path", + "add_path", + "add_path_precheck", + "create_seqscan_path", + "create_cstorescan_path", + "create_index_path", + "build_seqScanPath_by_indexScanPath", + "check_bitmap_heap_path_index_unusable", + "is_partitionIndex_Subpath", + "is_pwj_path", + "create_bitmap_heap_path" +}; + +static const char* GS_TRC_REWRITE_FUNC_NAMES[] = +{ + "", + "OffsetVarNodes", + "ChangeVarNodes", + "IncrementVarSublevelsUp", + "IncrementVarSublevelsUp_rtable", + "rangeTableEntry_used", + "attribute_used", + "getInsertSelectQuery", + "AddQual", + "AddInvertedQual", + "contain_aggs_of_level", + "checkExprHasAggs", + "checkExprHasWindowFuncs", + "checkExprHasSubLink" +}; + +static const char* GS_TRC_LIBPQ_FUNC_NAMES[] = +{ + "", + "StreamServerPort", + "StreamConnection", + "StreamClose", + "TouchSocketFile", + "pq_init", + "pq_comm_reset", + "pq_getbytes", + "pq_getstring", + "pq_getmessage", + "pq_getbyte", + "pq_peekbyte", + "pq_getbyte_if_available", + "pq_putbytes", + "pq_flush", + "pq_flush_if_writable", + "pq_flush_timedwait", + "pq_is_send_pending", + "pq_putmessage", + "pq_putmessage_noblock", + "pq_startcopyout", + "pq_endcopyout", + "pq_select" +}; + +static const char* GS_TRC_UTILS_FUNC_NAMES[] = +{ + "", + "has_any_column_privilege_name_name", + "has_any_column_privilege_name_id", + "has_any_column_privilege_id_name", + "has_any_column_privilege_id_id", + "has_any_column_privilege_name", + "has_any_column_privilege_id", + "has_column_privilege_name_name_name", + "has_column_privilege_name_name_attnum", + "has_column_privilege_name_id_name", + "has_column_privilege_name_id_attnum", + "has_column_privilege_id_name_name", + "has_column_privilege_id_name_attnum", + "has_column_privilege_id_id_name", + "has_column_privilege_id_id_attnum", + "has_column_privilege_name_name", + "has_column_privilege_name_attnum", + "has_column_privilege_id_name", + "has_column_privilege_id_attnum", + "has_table_privilege_name_name", + "has_table_privilege_name_id", + "has_table_privilege_id_name", + "has_table_privilege_id_id", + "has_table_privilege_name", + "has_table_privilege_id", + "has_sequence_privilege_name_name", + "has_sequence_privilege_name_id", + "has_sequence_privilege_id_name", + "has_sequence_privilege_id_id", + "has_sequence_privilege_name", + "has_sequence_privilege_id", + "has_database_privilege_name_name", + "has_database_privilege_name_id", + "has_database_privilege_id_name", + "has_database_privilege_id_id", + "has_database_privilege_name", + "has_database_privilege_id", + "has_foreign_data_wrapper_privilege_name_name", + "has_foreign_data_wrapper_privilege_name_id", + "has_foreign_data_wrapper_privilege_id_name", + "has_foreign_data_wrapper_privilege_id_id", + "has_foreign_data_wrapper_privilege_name", + "has_foreign_data_wrapper_privilege_id", + "has_function_privilege_name_name", + "has_function_privilege_name_id", + "has_function_privilege_id_name", + "has_function_privilege_id_id", + "has_function_privilege_name", + "has_function_privilege_id", + "has_language_privilege_name_name", + "has_language_privilege_name_id", + "has_language_privilege_id_name", + "has_language_privilege_id_id", + "has_language_privilege_name", + "has_language_privilege_id", + "has_nodegroup_privilege_name_name", + "has_nodegroup_privilege_name_id", + "has_nodegroup_privilege_id_name", + "has_nodegroup_privilege_id_id", + "has_nodegroup_privilege_name", + "has_nodegroup_privilege_id", + "has_schema_privilege_name_name", + "has_schema_privilege_name_id", + "has_schema_privilege_id_name", + "has_schema_privilege_id_id", + "has_schema_privilege_name", + "has_schema_privilege_id", + "has_server_privilege_name_name", + "has_server_privilege_name_id", + "has_server_privilege_id_name", + "has_server_privilege_id_id", + "has_server_privilege_name", + "has_server_privilege_id", + "has_tablespace_privilege_name_name", + "has_tablespace_privilege_name_id", + "has_tablespace_privilege_id_name", + "has_tablespace_privilege_id_id", + "has_tablespace_privilege_name", + "has_tablespace_privilege_id", + "has_type_privilege_name_name", + "has_type_privilege_name_id", + "has_type_privilege_id_name", + "has_type_privilege_id_id", + "has_type_privilege_name", + "has_type_privilege_id", + "pg_has_role_name_name", + "pg_has_role_name_id", + "pg_has_role_id_name", + "pg_has_role_id_id", + "pg_has_role_name", + "pg_has_role_id", + "GetConfigOption", + "GetConfigOptionResetString", + "ProcessConfigFile", + "InitializeGUCOptions", + "init_sync_guc_variables", + "repair_guc_variables", + "SelectConfigFiles", + "ResetAllOptions", + "AtStart_GUC", + "NewGUCNestLevel", + "AtEOXact_GUC", + "BeginReportingGUCOptions", + "ParseLongOption", + "set_config_option", + "GetConfigOptionByName", + "GetConfigOptionByNum", + "GetNumConfigOptions", + "SetPGVariable", + "GetPGVariable", + "GetPGVariableResultDesc", + "RewriteBeginQuery", + "ExecSetVariableStmt", + "ExtractSetVariableArgs", + "RelationIdGetRelation", + "RelationClose", + "PartitionGetPartIndexList", + "RelationGetIndexList", + "RelationGetIndexNum", + "RelationGetOidIndex", + "RelationGetIndexExpressions", + "RelationGetIndexPredicate", + "RelationGetIndexAttrBitmap", + "RelationGetExclusionInfo" +}; + +static const char* GS_TRC_BOOTSTRAP_FUNC_NAMES[] = +{ + "", + "AuxiliaryProcessMain", + "err_out", + "closerel", + "boot_openrel", + "DefineAttr", + "InsertOneTuple", + "InsertOneValue", + "InsertOneNull", + "MapArrayTypeName", + "index_register", + "build_indices", + "boot_get_type_io_data", + "boot_yyparse", + "boot_yylex", + "boot_yyerror" +}; + +static const char* GS_TRC_STORAGE_FUNC_NAMES[] = +{ + "", + "InitBufferPool", + "InitBufferPoolAccess", + "InitBufferPoolBackend", + "AtEOXact_Buffers", + "PrintBufferLeakWarning", + "CheckPointBuffers", + "RelationGetNumberOfBlocksInFork", + "FlushRelationBuffers", + "FlushDatabaseBuffers", + "DropRelFileNodeBuffers", + "DropRelFileNodeAllBuffers", + "DropDatabaseBuffers", + "ProcArrayShmemSize", + "ProcArrayAdd", + "ProcArrayRemove", + "ProcArrayEndTransaction", + "ProcArrayClearTransaction", + "SetGlobalSnapshotData", + "UnsetGlobalSnapshotData", + "ReloadConnInfoOnBackends", + "DumpMemoryCtxOnBackend", + "ProcArrayInitRecovery", + "ProcArrayApplyRecoveryInfo", + "ProcArrayApplyXidAssignment", + "RecordKnownAssignedTransactionIds", + "ExpireTreeKnownAssignedTransactionIds", + "ExpireAllKnownAssignedTransactionIds", + "ExpireOldKnownAssignedTransactionIds", + "GetMaxSnapshotXidCount", + "GetMaxSnapshotSubxidCount", + "smgrinit", + "smgropen", + "smgrexists", + "smgrsetowner", + "smgrclearowner", + "smgrclose", + "smgrcloseall", + "smgrclosenode", + "smgrcreate", + "smgrdounlink", + "smgrdounlinkfork", + "smgrextend", + "smgrprefetch", + "smgrread", + "smgrwrite", + "smgrwriteback", + "smgrnblocks", + "smgrtruncate", + "smgrimmedsync", + "smgrpreckpt", + "smgrsync", + "smgrpostckpt", + "AtEOXact_SMgr", + "BufferAlloc", + "SyncLocalXidWait", + "BufferSync", + "BgBufferSync", + "fsm_vacuum_page", + "fsm_search", + "fsm_set_and_search" +}; + +static const char* GS_TRC_POSTMASTER_FUNC_NAMES[] = +{ + "", + "PostmasterMain", + "ClosePostmasterPorts", + "MaxLivePostmasterChildren", + "HaShmemSize", + "HaShmemInit", + "postmaster_forkexec", + "stream_forkexec", + "WLMProcessForkExec", + "SubPostmasterMain", + "ShmemBackendArraySize", + "ShmemBackendArrayAllocation", + "SysLogger_Start", + "SysLoggerClose", + "write_syslogger_file", + "AioCompltrMain", + "AioCompltrStop", + "AioCompltrStart", + "AioCompltrIsReady", + "CompltrContext", + "CompltrPriority", + "AutoVacuumingActive", + "IsAutoVacuumLauncherProcess", + "IsAutoVacuumWorkerProcess", + "autovac_init", + "StartAutoVacLauncher", + "StartAutoVacWorker", + "AutoVacWorkerFailed", + "AutoVacuumUpdateDelay", + "AutoVacLauncherMain", + "AutoVacWorkerMain", + "AutovacuumWorkerIAm", + "AutovacuumLauncherIAm", + "HandleStartupProcInterrupts", + "StartupProcessMain", + "PreRestoreCommand", + "PostRestoreCommand", + "IsFailoverTriggered", + "IsSwitchoverTriggered", + "IsPrimaryTriggered", + "ResetSwitchoverTriggered", + "ResetFailoverTriggered", + "ResetPrimaryTriggered", + "NotifySignalShmemSize", + "NotifySignalShmemInit", + "SendNotifySignal", + "CheckNotifySignal", + "BackgroundWriterMain", + "CheckpointerMain", + "RequestCheckpoint", + "CheckpointWriteDelay", + "ForwardFsyncRequest", + "AbsorbFsyncRequests", + "CheckpointerShmemSize", + "CheckpointerShmemInit", + "FirstCallSinceLastCheckpoint", + "IsBgwriterProcess", + "isDirExist", + "startAlarmChecker", + "AlarmCheckerMain", + "fork_process", + "WalWriterMain", + "ckpt_try_prune_dirty_page_queue" +}; + +static const char* GS_TRC_SYSTEM_FUNC_NAMES[] = +{ + "", + "TRY_CATCH" +}; + +static const char* GS_TRC_ACCESS_FUNC_NAMES[] = +{ + "", + "heap_compute_data_size", + "heap_fill_tuple", + "heap_attisnull", + "nocache_cmprs_get_attr", + "nocachegetattr", + "heap_getsysattr", + "heap_copytuple", + "heapCopyCompressedTuple", + "heapCopyTuple", + "heap_copytuple_with_tuple", + "heap_form_tuple", + "heap_form_cmprs_tuple", + "heap_modify_tuple", + "heap_deform_cmprs_tuple", + "heap_deform_tuple", + "heap_deform_tuple2", + "heap_deform_tuple3", + "heap_formtuple", + "heap_modifytuple", + "heap_deformtuple", + "heap_freetuple", + "heap_form_minimal_tuple", + "heap_free_minimal_tuple", + "heap_copy_minimal_tuple", + "heap_tuple_from_minimal_tuple", + "minimal_tuple_from_heap_tuple", + "heapGetInitDefVal", + "relationAttIsNull", + "heapFormMinimalTuple", + "XLogInsertRecord", + "XLogFlush", + "XLogBackgroundFlush", + "XLogNeedsFlush", + "XLogFileInit", + "XLogFileOpen", + "CheckXLogRemoved", + "XLogSetAsyncXactLSN", + "XLogSetReplicationSlotMinimumLSN", + "XLogSetReplicationSlotMaximumLSN", + "XLogGetReplicationSlotMaximumLSN", + "xlog_redo", + "xlog_desc", + "issue_xlog_fsync", + "RecoveryInProgress", + "HotStandbyActive", + "HotStandbyActiveInReplay", + "XLogInsertAllowed", + "GetXLogReceiptTime", + "GetXLogReplayRecPtr", + "GetXLogReplayRecPtrInPending", + "GetStandbyFlushRecPtr", + "GetXLogInsertRecPtr", + "GetXLogWriteRecPtr", + "RecoveryIsPaused", + "SetRecoveryPause", + "GetLatestXTime", + "GetCurrentChunkReplayStartTime", + "GetXlogRecordCrc", + "UpdateControlFile", + "GetSystemIdentifier", + "SetSystemIdentifier", + "GetThisTimeID", + "SetThisTimeID", + "XLOGShmemSize", + "XLOGShmemInit", + "BootStrapXLOG", + "StartupXLOG", + "ShutdownXLOG", + "InitXLOGAccess", + "StartupDummyStandby", + "CreateCheckPoint", + "CreateRestartPoint", + "CheckPointGuts", + "XLogPutNextOid", + "XLogRestorePoint", + "UpdateFullPageWrites", + "GetFullPageWriteInfo", + "GetRedoRecPtr", + "GetInsertRecPtr", + "GetFlushRecPtr", + "GetNextXidAndEpoch", + "GetRecoveryTargetTLI", + "DummyStandbySetRecoveryTargetTLI", + "CheckPromoteSignal", + "CheckPrimarySignal", + "CheckStandbySignal", + "CheckSwitchoverSignal", + "ReadLsnXlogFlushChkFile", + "WakeupRecovery", + "WakeupDataRecovery", + "SetWalWriterSleeping", + "CheckFpwBeforeFirstCkpt", + "DisableFpwBeforeFirstCkpt", + "UpdateLsnXlogFlushChkFile", + "LsnXlogFlushChkShmemSize", + "LsnXlogFlushChkShmInit", + "IfLsnXlogFlushChkFileExist", + "heap_xlog_logical_new_page", + "StartTransaction", + "KeepLogSeg", + "RemoveOldXlogFiles", + "dw_truncate", + "heap_change_xidbase_after_freeze", + "heap_page_prepare_for_xid", + "ExtendCSNLOG", + "freeze_single_heap_page", + "heap_page_prune", + "heap_prune_chain", + "PreallocXlogFiles", + "do_pg_stop_backup", + "do_pg_start_backup" +}; + +static const char* GS_TRC_REPLICATION_FUNC_NAMES[] = +{ + "", + "WalReceiverMain", + "walrcvWriterMain", + "WalRcvShmemSize", + "WalRcvShmemInit", + "ShutdownWalRcv", + "WalRcvInProgress", + "connect_dn_str", + "RequestXLogStreaming", + "get_rcv_slot_name", + "GetWalRcvWriteRecPtr", + "GetReplicationApplyDelay", + "GetReplicationTransferLatency", + "GetWalRcvDummyStandbySyncPercent", + "SetWalRcvDummyStandbySyncPercent", + "getCurrentWalRcvCtlBlock", + "walRcvWrite", + "WalRcvXLogClose", + "WalRcvIsShutdown", + "ProcessRmXLog", + "SetWalRcvWriterPID", + "WalRcvWriterInProgress", + "walRcvCtlBlockIsEmpty", + "GetRepConnArray", + "get_sync_percent", + "wal_get_role_string", + "pg_stat_get_stream_replications", + "DataReceiverMain", + "DataRcvShmemSize", + "DataRcvShmemInit", + "DataRcvInProgress", + "ShutdownDataRcv", + "StartupDataStreaming", + "RequestDataStreaming", + "InitDummyDataNum", + "WakeupDataRcvWriter", + "DataRcvWriterInProgress", + "DataRcvDataCleanup", + "DataRcvWriterMain", + "DataRcvWrite", + "SetDataRcvDummyStandbySyncPercent", + "GetDataRcvDummyStandbySyncPercent", + "SetDataRcvWriterPID", + "ProcessDataRcvInterrupts", + "CloseDataFile", + "WalSenderMain", + "WalSndSignals", + "WalSndShmemSize", + "WalSndShmemInit", + "WalSndWakeup", + "WalSndRqstFileReload", + "WalSndInProgress", + "StandbyOrSecondaryIsAlive" +}; + +static const char* GS_TRC_CATALOG_FUNC_NAMES[] = +{ + "", + "forkname_to_number", + "forkname_chars", + "relpathbackend", + "GetDatabasePath", + "relpath_to_filenode", + "IsSystemRelation", + "IsToastRelation", + "IsSystemClass", + "IsToastClass", + "IsSystemNamespace", + "IsToastNamespace", + "IsCStoreNamespace", + "IsReservedName", + "IsSharedRelation", + "GetNewOid", + "GetNewOidWithIndex", + "GetNewRelFileNode", + "heap_truncate", + "heap_truncate_one_rel", + "heap_truncate_check_FKs", + "heap_truncate_find_FKs", + "InsertPgAttributeTuple", + "InsertPgClassTuple", + "AddRelationNewConstraints", + "AddRelClusterConstraints", + "StoreAttrDefault", + "cookDefault", + "DeleteRelationTuple", + "DeleteAttributeTuples", + "DeleteSystemAttributeTuples", + "RemoveAttributeById", + "RemoveAttrDefault", + "RemoveAttrDefaultById", + "RemoveStatistics", + "SystemAttributeDefinition", + "SystemAttributeByName", + "CheckAttributeNamesTypes", + "CheckAttributeType", + "AddRelationDistribution", + "GetRelationDistributionItems", + "GetRelationDistributionNodes", + "BuildRelationDistributionNodes", + "SortRelationDistributionNodes", + "SetRelHasClusterKey" +}; + +static const char* GS_TRC_PG_CTL_FUNC_NAMES[] = +{ + "", + "ReceiveXlogStream", + "get_replconn_number", + "ParseReplConnInfo" +}; + +static const char* GS_TRC_COMMON_FUNC_NAMES[] = +{ + "", + "charshow_estimated_time", + "charshow_datasize", + "UpdateDBStateFile" +}; + +static const char* GS_TRC_TSEARCH_FUNC_NAMES[] = +{ + "", + "init_tsvector_parser", + "reset_tsvector_parser", + "gettoken_tsvector", + "close_tsvector_parser" +}; + +static const char* GS_TRC_TCOP_FUNC_NAMES[] = +{ + "", + "BeginCommand", + "CreateDestReceiver", + "CreateReceiverForMerge", + "EndCommand", + "EndCommand_noblock", + "ProcessUtility", + "standard_ProcessUtility", + "UtilityReturnsTuples", + "UtilityTupleDescriptor", + "UtilityContainsQuery", + "CreateCommandTag", + "GetCommandLogLevel", + "CommandIsReadOnly", + "CheckRelationOwnership", + "pg_parse_query", + "pg_analyze_and_rewrite", + "pg_analyze_and_rewrite_params", + "pg_plan_query", + "pg_plan_queries", + "check_max_stack_depth", + "assign_max_stack_depth", + "die", + "quickdie", + "StatementCancelHandler", + "FloatExceptionHandler", + "RecoveryConflictInterrupt", + "prepare_for_client_read", + "client_read_ended", + "prepare_for_logic_conn_read", + "logic_conn_read_check_ended", + "process_postgres_switches", + "PostgresMain", + "StreamMain", + "get_stack_depth_rlimit", + "ResetUsage", + "ShowUsage", + "check_log_duration", + "set_debug_options", + "set_plan_disabling_options", + "get_stats_option_name", + "exec_parse_message", + "exec_bind_message", + "exec_execute_message", + "PortalStart", + "PortalRun" +}; + +static const char* GS_TRC_VECEXECUTOR_FUNC_NAMES[] = +{ + "", + "VectorEngine", + "ExecVecProject", + "ExecInitVecExpr", + "ExecAssignVecScanProjectionInfo", + "ExecVecMarkPos", + "ExecVecRestrPos", + "VecExecReScan" +}; + +static const char* GS_TRC_WLM_FUNC_NAMES[] = +{ + "", + "WLMIsSimpleQuery" +}; + +static const char* GS_TRC_EXECUTER_FUNC_NAMES[] = +{ + "", + "execTuplesMatch", + "execTuplesUnequal", + "execTuplesMatchPrepare", + "execTuplesHashPrepare", + "BuildTupleHashTable", + "LookupTupleHashEntry", + "FindTupleHashEntry", + "ExecInitJunkFilter", + "ExecInitJunkFilterConversion", + "ExecFindJunkAttribute", + "ExecFindJunkAttributeInTlist", + "ExecGetJunkAttribute", + "ExecFilterJunk", + "ExecSetjunkFilteDescriptor", + "ExecFindJunkPrimaryKeys", + "BatchExecFilterJunk", + "BatchCheckNodeIdentifier", + "ExecGetPlanNodeid", + "ExecutorStart", + "standard_ExecutorStart", + "ExecutorRun", + "standard_ExecutorRun", + "ExecutorFinish", + "standard_ExecutorFinish", + "ExecutorEnd", + "standard_ExecutorEnd", + "ExecutorRewind", + "ExecCheckRTPerms", + "CheckValidResultRel", + "InitResultRelInfo", + "ExecGetTriggerResultRel", + "ExecContextForcesOids", + "ExecConstraints", + "ExecFindRowMark", + "ExecBuildAuxRowMark", + "EvalPlanQual", + "EvalPlanQualFetch", + "EvalPlanQualInit", + "EvalPlanQualSetPlan", + "EvalPlanQualSetTuple", + "EvalPlanQualGetTuple", + "EvalPlanQualFetchRowMarks", + "EvalPlanQualNext", + "EvalPlanQualBegin", + "EvalPlanQualEnd", + "ExecInitNode", + "ExecProcNode", + "MultiExecProcNode", + "ExecEndNode", + "ExecGetPlanMemCost", + "GetAttributeByNum", + "GetAttributeByName", + "ExecMakeTableFunctionResult", + "ExecEvalExprSwitchContext", + "ExecInitExpr", + "ExecPrepareExpr", + "ExecQual", + "ExecTargetListLength", + "ExecCleanTargetListLength", + "ExecProject", + "ExecScan", + "ExecAssignScanProjectionInfo", + "ExecScanReScan", + "ExecInitResultTupleSlot", + "ExecInitScanTupleSlot", + "ExecInitExtraTupleSlot", + "ExecInitNullTupleSlot", + "ExecTypeFromTL", + "ExecCleanTypeFromTL", + "ExecTypeFromExprList", + "UpdateChangedParamSet", + "begin_tup_output_tupdesc", + "do_tup_output", + "do_text_output_multiline", + "end_tup_output", + "InitPlan", + "ExecCheckRTEPerms", + "ExecInitIndexScan", + "BypassExecutor" +}; + +static struct comp_func GS_TRC_FUNC_NAMES_BY_COMP[] = +{ + {0, 0, NULL}, + {COMP_COMMON, 4, GS_TRC_COMMON_FUNC_NAMES}, + {COMP_LIBPQ, 23, GS_TRC_LIBPQ_FUNC_NAMES}, + {COMP_PG_CTL, 4, GS_TRC_PG_CTL_FUNC_NAMES}, + {COMP_ACCESS, 112, GS_TRC_ACCESS_FUNC_NAMES}, + {COMP_BOOTSTRAP, 16, GS_TRC_BOOTSTRAP_FUNC_NAMES}, + {COMP_CATALOG, 45, GS_TRC_CATALOG_FUNC_NAMES}, + {COMP_PARSER, 15, GS_TRC_PARSER_FUNC_NAMES}, + {COMP_COMMANDS, 44, GS_TRC_COMMANDS_FUNC_NAMES}, + {COMP_EXECUTER, 80, GS_TRC_EXECUTER_FUNC_NAMES}, + {COMP_VECEXECUTOR, 8, GS_TRC_VECEXECUTOR_FUNC_NAMES}, + {COMP_OPTIMIZER, 48, GS_TRC_OPTIMIZER_FUNC_NAMES}, + {COMP_POSTMASTER, 63, GS_TRC_POSTMASTER_FUNC_NAMES}, + {COMP_REPLICATION, 53, GS_TRC_REPLICATION_FUNC_NAMES}, + {COMP_REWRITE, 14, GS_TRC_REWRITE_FUNC_NAMES}, + {COMP_STORAGE, 61, GS_TRC_STORAGE_FUNC_NAMES}, + {COMP_TCOP, 46, GS_TRC_TCOP_FUNC_NAMES}, + {COMP_TSEARCH, 5, GS_TRC_TSEARCH_FUNC_NAMES}, + {COMP_UTILS, 124, GS_TRC_UTILS_FUNC_NAMES}, + {COMP_WLM, 2, GS_TRC_WLM_FUNC_NAMES}, + {COMP_SYSTEM, 2, GS_TRC_SYSTEM_FUNC_NAMES} +}; + +static struct comp_name GS_TRC_COMP_NAMES_BY_COMP[] = +{ + {0, NULL}, + {COMP_COMMON, "common"}, + {COMP_LIBPQ, "libpq"}, + {COMP_PG_CTL, "pg_ctl"}, + {COMP_ACCESS, "access"}, + {COMP_BOOTSTRAP, "bootstrap"}, + {COMP_CATALOG, "catalog"}, + {COMP_PARSER, "parser"}, + {COMP_COMMANDS, "commands"}, + {COMP_EXECUTER, "executer"}, + {COMP_VECEXECUTOR, "vecexecutor"}, + {COMP_OPTIMIZER, "optimizer"}, + {COMP_POSTMASTER, "postmaster"}, + {COMP_REPLICATION, "replication"}, + {COMP_REWRITE, "rewrite"}, + {COMP_STORAGE, "storage"}, + {COMP_TCOP, "tcop"}, + {COMP_TSEARCH, "tsearch"}, + {COMP_UTILS, "utils"}, + {COMP_WLM, "wlm"}, + {COMP_SYSTEM, "system"} +}; + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/gstrace_infra.h postgresql-hll-2.14/include/gstrace/gstrace_infra.h --- postgresql-hll-2.14_old/include/gstrace/gstrace_infra.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/gstrace_infra.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_infra.h + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_infra.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TRACE_INFRA_H_ +#define TRACE_INFRA_H_ + +/* use low 16 bits for function name */ +#define GS_TRC_COMP_SHIFT 16 +#define GS_TRC_FUNC_SHIFT 0 +#define GS_TRC_ID_PACK(comp, func) (func | (comp) << GS_TRC_COMP_SHIFT) + +/* used for gstrace_data() to inform tool how to decode its probe data. */ +typedef enum trace_data_fmt { + TRC_DATA_FMT_NONE, /* no data in this trace record */ + TRC_DATA_FMT_DFLT, /* data is stored with HEX format */ + TRC_DATA_FMT_UINT32 /* data is stored as uint32 */ +} trace_data_fmt; + +#ifdef ENABLE_GSTRACE + +/* Initialize context during startup process. */ +extern int gstrace_init(int key); +extern void gstrace_destory(int code, uintptr_t arg); + +/* write one ENTRY trace record */ +extern void gstrace_entry(const uint32_t rec_id); + +/* write one EXIT trace record */ +extern void gstrace_exit(const uint32_t rec_id); + +/* write on DATA trace record. If data_len is greater than 1920, no data is traced. */ +extern void gstrace_data( + const uint32_t probe, const uint32_t rec_id, const trace_data_fmt fmt_type, const char* pData, size_t data_len); + +extern int* gstrace_tryblock_entry(int* newTryCounter); +extern void gstrace_tryblock_exit(bool inCatch, int* oldTryCounter); + +#else + +#define gstrace_init(key) (1) +#define gstrace_destory (NULL) +#define gstrace_entry(rec_id) +#define gstrace_exit(rec_id) +#define gstrace_data(probe, rec_id, fmt_type, pData, data_len) +#define gstrace_tryblock_entry(curTryCounter) (curTryCounter) +#define gstrace_tryblock_exit(inCatch, oldTryCounter) + +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/gstrace/gstrace_infra_int.h postgresql-hll-2.14/include/gstrace/gstrace_infra_int.h --- postgresql-hll-2.14_old/include/gstrace/gstrace_infra_int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/gstrace_infra_int.h 2020-12-12 17:06:43.121346413 +0800 @@ -0,0 +1,260 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_infra_int.h + * + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_infra_int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TRACE_INFRA_INT_H_ +#define TRACE_INFRA_INT_H_ + +#include +#include "gstrace/gstrace_infra.h" +#include "gstrace/system_gstrace.h" +// ----------------------------------------------------------------------------- +// Global #defines +// ----------------------------------------------------------------------------- +#define SLOT_SIZE 64 +#define MAX_TRC_RC_SZ 2048 // 2^11 +#define MAX_TRC_SLOTS (MAX_TRC_RC_SZ / SLOT_SIZE) +#define MAX_PATH_LEN 1024 +#define LENGTH_TRACE_CONFIG_HASH (64) + +#define TRACE_VERSION (0x1) +#define SLOT_AREAD_HEADER_MAGIC_NO 0xBCD7BCD7 +#define GS_TRC_CFG_MAGIC_N 0xABCDABCE + +#define MIN_BUF_SIZE 128 // The buffer size when it's tracing to file +#define DFT_BUF_SIZE 1073741824 // Default trace buffer size. 1GB. must be a power of 2 + +#define CACHE_LINE_SIZE 64 + +#define USECS_PER_SEC ((uint64_t)(1000000)) + +/* some mask related functions */ +#define GS_TRC_COMP_MASK 0x0FF0000 +#define GS_TRC_FUNC_MASK 0x000FFFF +#define GS_TRC_NUM_BITS 8 +#define GS_TRC_COMP_MAX 256 +#define GS_TRC_COMP_MASK_SZ (GS_TRC_COMP_MAX / GS_TRC_NUM_BITS) // 32 +#define GS_TRC_FUNC_MAX 65536 +#define GS_TRC_FUNC_MASK_SZ (GS_TRC_FUNC_MAX / GS_TRC_NUM_BITS) // 8192 + +#define TRACE_COMMON_ERROR (-1) + +typedef enum trace_msg_code { + TRACE_OK, + TRACE_ALREADY_START, + TRACE_ALREADY_STOP, + TRACE_PARAMETER_ERR, + TRACE_BUFFER_SIZE_ERR, + TRACE_ATTACH_CFG_SHARE_MEMORY_ERR, + TRACE_ATTACH_BUFFER_SHARE_MEMORY_ERR, + TRACE_OPEN_SHARE_MEMORY_ERR, + TRACE_TRUNCATE_ERR, + TRACE_MMAP_ERR, + TRACE_MUNMAP_ERR, + TRACE_UNLINK_SHARE_MEMORY_ERR, + TRACE_DISABLE_ERR, + TRACE_OPEN_OUTPUT_FILE_ERR, + TRACE_OPEN_INPUT_FILE_ERR, + TRACE_WRITE_BUFFER_HEADER_ERR, + TRACE_WRITE_CFG_HEADER_ERR, + TRACE_WRITE_BUFFER_ERR, + TRACE_READ_CFG_FROM_FILE_ERR, + TRACE_BUFFER_SIZE_FROM_FILE_ERR, + TRACE_MAGIC_FROM_FILE_ERR, + TRACE_READ_INFRA_FROM_FILE_ERR, + TRACE_NO_RECORDS_ERR, + TRACE_READ_SLOT_HEADER_ERR, + TRACE_NUM_SLOT_ERR, + TRACE_SLOT_MAGIC_ERR, + TRACE_READ_SLOT_DATA_ERR, + TRACE_WRITE_FORMATTED_RECORD_ERR, + TRACE_STATR_SLOT_ERR, + TRACE_TAIL_OFFSET_ERR, + TRACE_SEQ_ERR, + TRACE_VERSION_ERR, + TRACE_CONFIG_SIZE_ERR, + TRACE_MSG_MAX, +} trace_msg_code; + +typedef struct trace_msg { + trace_msg_code msg_code; + const char* msg_string; +} trace_msg_t; + + +#define securec_check(errno, charList, ...) \ + do { \ + if (errno != EOK) { \ + freeSecurityFuncSpace_c(charList, ##__VA_ARGS__); \ + printf("ERROR at %s : %d : The destination buffer or format is " \ + "a NULL pointer or the invalid parameter handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) + +/* White list for trace Id */ +typedef struct trace_mask { + /* while component's traceId is active */ + uint8_t comp_bitmap[GS_TRC_COMP_MASK_SZ]; + + /* while function's traceId is active */ + uint8_t func_bitmap[GS_TRC_FUNC_MASK_SZ]; +} trace_mask; + +typedef enum trace_status { + TRACE_STATUS_END_STOP = 0, + TRACE_STATUS_RECORDING, + TRACE_STATUS_PREPARE_STOP, + TRACE_STATUS_BEGIN_STOP +} trace_status; + +typedef enum trace_type { TRACE_ENTRY, TRACE_EXIT, TRACE_DATA } trace_type; + +/* + * Trace Buffer Header + * The writable buffer will start right after this struct. + */ +typedef struct trace_infra { + /* the number of trace records since startup */ + volatile uint64_t g_Counter; + + /* ensure the previous one field in an sepreate cacheline */ + char pad[CACHE_LINE_SIZE - sizeof(uint64_t)]; + + /* buffer size + size of this struct */ + uint64_t total_size; + + /* the number of trace slots in writable region */ + uint64_t num_slots; + + /* Used to calculate slot index in an efficient manner */ + uint64_t slot_index_mask; + + /* ensure the previous three fields in an sepreate cacheline */ + char pad2[CACHE_LINE_SIZE - 3 * sizeof(uint64_t)]; +} trace_infra; + +typedef struct trace_config { + /* a magic number for validation */ + uint32_t trc_cfg_magic_no; + + /* mark which process are traced */ + uint32_t key; + + /* whether or not trace is activated */ + volatile bool bEnabled; + + /* record trace into disk file or memory mapping file */ + bool bTrcToFile; + + /* Trace buffer size */ + uint64_t size; + + /* additional options, such as traceId white list */ + uint64_t options; + + /* if bTrcToFile is true, records are write down this file */ + char filePath[MAX_PATH_LEN]; + + volatile int status; + volatile int status_counter; + + /* trace ids white list */ + trace_mask gs_trc_mask; + /* gstrace version. default value is TRACE_VERSION. + * if change struct trace_config or trace_infra, should add 1 on TRACE_VERSION */ + uint32_t version; + /* hash sum value of trace config files in gstrace/config. sha256(sha256(access.in) + sha256(bootstrap.in)+..) + * default value is HASH_TRACE_CONFIG which auto generate by trc_gen.py. */ + char hash_trace_config_file[LENGTH_TRACE_CONFIG_HASH]; +} trace_config; + +typedef struct trace_context { + /* address of trace infra struct in shared mem */ + trace_infra* pTrcInfra; + + /* address of trace config buffer in shared mem */ + trace_config* pTrcCfg; +} trace_context; + +// slot area header is 16 bytes +// slot aread tail is 8 bytes +// trace record ( payload of the first slot ) is 28 bytes +// that leaves us with 12 free bytes ( 64 - 52 ) in the first slot +// we can us them for rc or code path value +typedef struct trace_slot_head { + uint64_t hdr_sequence; + uint32_t hdr_magic_number; + uint32_t num_slots_in_area; +} trace_slot_head; + +typedef struct trace_slot_tail { + uint64_t tail_sequence; +} trace_slot_tail; + +// total size of trace record is 40 bytes +// and we have 16 bytes for slot header and 8 for tail +// that makes up 64 bytes which just fits in on slot!! +// ---------------------------------------------------- +typedef struct trace_record { + uint64_t timestamp; + pid_t pid; + pid_t tid; + trace_type type; // entry, exit or data + uint32_t probe; // probe point in function + uint32_t rec_id; // traceId that contains info on function and component etc. + uint32_t rc; + uint32_t un_used; // the compiler will reserve 40 bytes for the whole structre any way, + // due to alignment, may as well use it explicitly + uint32_t user_data_len; +} trace_record; + +extern trace_msg_code gstrace_start(int pid, const char* mask, uint64_t bufferSize, const char* trcFile); +extern trace_msg_code gstrace_stop(int pid); +extern trace_msg_code gstrace_dump(int pid, const char* outPath); +extern trace_msg_code gstrace_config(int pid); +extern bool isNumeric(const char* str); + +extern uint32_t getFunctionIdxByName(const char* funcName, uint32_t* comp); +extern uint32_t getCompIdxByName(const char* compName); +extern const char* getCompNameById(uint32_t trc_id); +extern const char* getTraceConfigHash(void); +extern const char* getTraceFunctionName(uint32_t trc_id); +extern const char* getTraceTypeString(trace_type type); + +// Will round up i to the nearest multiple of +// X. X must be a power of 2 +inline uint32_t gsAlign(uint32_t i, uint32_t X) +{ + return ((i + (X - 1)) & ~(uint32_t)(X - 1)); +} + +extern FILE* trace_fopen(const char* file_name, const char* mode); +extern int trace_fclose(FILE* stream); +extern int trace_open_filedesc(const char* file_name, int oflag, int mode); +extern int trace_close_filedesc(int fd); + +#endif /* TRACE_INFRA_INT_H_ */ diff -uprN postgresql-hll-2.14_old/include/gstrace/gstrace_tool.h postgresql-hll-2.14/include/gstrace/gstrace_tool.h --- postgresql-hll-2.14_old/include/gstrace/gstrace_tool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/gstrace_tool.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,186 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_tool.h + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_tool.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TRACE_TOOL_H_ +#define TRACE_TOOL_H_ + +#include +#include + +#define HEX_DUMP_ADDR_SZ (sizeof("0xffffffffffff") + 2) +#define HEX_DUMP_PER_LINE 16 + +// 2 bytes for each plus space in between each 2 +#define HEX_DUMP_LEN (HEX_DUMP_PER_LINE * 2 + HEX_DUMP_PER_LINE / 2) +#define HEX_DUMP_SPC 2 +#define HEX_DUMP_ASCII_START (HEX_DUMP_LEN + HEX_DUMP_SPC) + +#define HEX_DUMP_BUF_SZ (HEX_DUMP_ADDR_SZ + HEX_DUMP_ASCII_START + HEX_DUMP_PER_LINE + sizeof("\n")) + +#define HEX_DUMP_INCLUDE_ADDRESS (1 << 0) +#define HEX_DUMP_INCLUDE_ASCII (1 << 1) + +typedef struct trace_func_stat { + pid_t max_pid; + pid_t max_tid; + uint32_t max_seq; + pid_t min_pid; + pid_t min_tid; + uint32_t min_seq; + uint32_t counter; + double total_time; + double max_elapsed_time; + double min_elapsed_time; + double average_elapsed_time; +} trace_func_stat; + +typedef std::map func_stat; + +// Class: ThreadFlow +// Using a stack to construct a control flow for each thread. +// ------------------------------------------------------------------------------------------- +class ThreadFlow { +public: + ThreadFlow(pid_t pid, pid_t tid, bool analyze, int stepSize, FILE* fpStepOut); + ~ThreadFlow(); + void flush(); + void handleEntry(trace_record* pRec, uint32_t seqNum); + void handleExit(trace_record* pRec, uint32_t seqNum, func_stat* func_flow, func_stat* func_flow_step, + uint64_t* stepStartTime, uint32_t* stepCounter); + void handleData(trace_record* pRec, void* pData, size_t len, uint32_t seqNum); + void refreshStats(trace_record* entry_rec, double elaps_time, trace_func_stat* funcInfo, uint32_t seqNum); + void writeToFile(trace_record* rec, double elapse_time, uint32_t indentation, uint32_t seqNum); + void flushStepStatsToFile(func_stat* func_stats, uint32_t stepCounter); + double getElapsetime(trace_record* entry_rec, trace_record* exit_rec); + void refreshAnalyzeData(trace_record* topRec, trace_record* pRec, func_stat* func_flow, func_stat* func_flow_step, + uint64_t* stepStartTime, double elapse_time, uint32_t seqNum, uint32_t* stepCounter); + +private: + pid_t m_Pid; + pid_t m_Tid; + bool m_analyze; + int m_stepSize; + std::stack m_GsFlowStack; + FILE* fpOut; /* output file */ + FILE* fpStepOut; /* step analyze file */ + const int max_step_analyze_line_size = 2048; +}; + +typedef std::map map_flow; + +// Class: DumpFileVisitor +// Define the interface for any kind of visitors. To decouple the parser +// and the logic how you want to use the data parsed from dmp file. +// e.g. For trace to flow, can create a concrete class named DumpFileFlowVisitor +// and implement visitEntry, visitExit and visitData respectively. +// +// For formatting, can create another concrete class named FormatVisitor, +// and implement each visitXXX method to append each records in order to the fmt file. +// ------------------------------------------------------------------------------------------- +class DumpFileVisitor { +public: + // dataOrRec: + // 0 - data + // 1 - rec + DumpFileVisitor() + {} + virtual ~DumpFileVisitor() + {} + + // Check the type of the record and call different methods for different types + void visit(trace_record* pRec, void* pData, size_t len); + virtual void visitEntry(trace_record* pRec){}; + virtual void visitExit(trace_record* pRec){}; + virtual void visitData(trace_record* pRec, void* pData, size_t len){}; + virtual void outputStat(FILE* fp){}; + +protected: + uint32_t m_Counter = 1; + bool m_analyze = false; + int m_stepSize = 0; + char m_stepOutputFile[MAX_PATH_LEN] = {0}; + size_t m_stepOutputFileLen = 0; + FILE* fpStepOut = NULL; /* step analyze file */ +}; + +// Class: DumpFileFlowVisitor +// Extend the DumpFileVisitor, and implement visitEntry, visitExit and visitData. +// It's used for taking records in order and create a control flow for each thread. +// ------------------------------------------------------------------------------------------- +class DumpFileFlowVisitor : public DumpFileVisitor { +public: + DumpFileFlowVisitor(bool analyze, int stepSize = 0, const char* outputFile = "", size_t output_len = 0); + ~DumpFileFlowVisitor(); + void visitEntry(trace_record* pRec) override; + void visitExit(trace_record* pRec) override; + void visitData(trace_record* pRec, void* pData, size_t len) override; + void outputStat(FILE* fp) override; + void putIfUnexisted(pid_t pid, pid_t tid); + void putFuncStatIfUnexisted(uint32_t func_id, func_stat* func_stat_map); + void mergeFiles(const char* outPath, size_t len); + void flushThreadFlows(); + +private: + map_flow mapFlows; + func_stat funcFlows; + func_stat funcFlowsStep; + uint64_t stepStartTime; + uint32_t stepCounter; + const int max_analyze_line_size = 2048; + const int microsecond = 1000000; +}; + +// Dump File Parser +// ----------------------------------------------------------- +class DumpFileParser { +public: + DumpFileParser(const char* inputFile, size_t len); + ~DumpFileParser(); + + // get header (the first slot) + // so the first slot contains header or the record + trace_msg_code parseHeader(void* pSlotHeader, size_t hdr_len); + trace_msg_code parseData(void* pData, size_t data_len); + trace_msg_code parseCfg(trace_config* pCfg); + trace_msg_code parseInfra(trace_infra* pInfra); + + trace_msg_code readAndParseDump(uint64_t counter, uint64_t* totNumRecsFormatted); + // Parse the whole dmp file. + trace_msg_code parse(); + + // Dynamically accept a visitor as the logic used for processing records + // during parsing. + void acceptVisitor(DumpFileVisitor* visitor); + trace_msg_code parseOneRecord(const char rec_tmp_buf[MAX_TRC_RC_SZ], size_t bufSize, bool hasdata); + trace_msg_code readAndParseOneRecord(void); + uint64_t findStartSlot(uint64_t maxSeq, uint64_t maxSlots, off_t* firstRecordOffset); + +private: + int fdInput; + DumpFileVisitor* pVisitor = NULL; + uint64_t firstTimestamp = 0; + uint64_t lenFirstNotOverlaped = 0; + bool processForOverlap = false; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/gstrace/libpq_gstrace.h postgresql-hll-2.14/include/gstrace/libpq_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/libpq_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/libpq_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,32 @@ +// This is a generated file + +#ifndef _LIBPQ_GSTRACE_H +#define _LIBPQ_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_StreamServerPort GS_TRC_ID_PACK(COMP_LIBPQ, 1) +#define GS_TRC_ID_StreamConnection GS_TRC_ID_PACK(COMP_LIBPQ, 2) +#define GS_TRC_ID_StreamClose GS_TRC_ID_PACK(COMP_LIBPQ, 3) +#define GS_TRC_ID_TouchSocketFile GS_TRC_ID_PACK(COMP_LIBPQ, 4) +#define GS_TRC_ID_pq_init GS_TRC_ID_PACK(COMP_LIBPQ, 5) +#define GS_TRC_ID_pq_comm_reset GS_TRC_ID_PACK(COMP_LIBPQ, 6) +#define GS_TRC_ID_pq_getbytes GS_TRC_ID_PACK(COMP_LIBPQ, 7) +#define GS_TRC_ID_pq_getstring GS_TRC_ID_PACK(COMP_LIBPQ, 8) +#define GS_TRC_ID_pq_getmessage GS_TRC_ID_PACK(COMP_LIBPQ, 9) +#define GS_TRC_ID_pq_getbyte GS_TRC_ID_PACK(COMP_LIBPQ, 10) +#define GS_TRC_ID_pq_peekbyte GS_TRC_ID_PACK(COMP_LIBPQ, 11) +#define GS_TRC_ID_pq_getbyte_if_available GS_TRC_ID_PACK(COMP_LIBPQ, 12) +#define GS_TRC_ID_pq_putbytes GS_TRC_ID_PACK(COMP_LIBPQ, 13) +#define GS_TRC_ID_pq_flush GS_TRC_ID_PACK(COMP_LIBPQ, 14) +#define GS_TRC_ID_pq_flush_if_writable GS_TRC_ID_PACK(COMP_LIBPQ, 15) +#define GS_TRC_ID_pq_flush_timedwait GS_TRC_ID_PACK(COMP_LIBPQ, 16) +#define GS_TRC_ID_pq_is_send_pending GS_TRC_ID_PACK(COMP_LIBPQ, 17) +#define GS_TRC_ID_pq_putmessage GS_TRC_ID_PACK(COMP_LIBPQ, 18) +#define GS_TRC_ID_pq_putmessage_noblock GS_TRC_ID_PACK(COMP_LIBPQ, 19) +#define GS_TRC_ID_pq_startcopyout GS_TRC_ID_PACK(COMP_LIBPQ, 20) +#define GS_TRC_ID_pq_endcopyout GS_TRC_ID_PACK(COMP_LIBPQ, 21) +#define GS_TRC_ID_pq_select GS_TRC_ID_PACK(COMP_LIBPQ, 22) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/optimizer_gstrace.h postgresql-hll-2.14/include/gstrace/optimizer_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/optimizer_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/optimizer_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,57 @@ +// This is a generated file + +#ifndef _OPTIMIZER_GSTRACE_H +#define _OPTIMIZER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_clauselist_selectivity GS_TRC_ID_PACK(COMP_OPTIMIZER, 1) +#define GS_TRC_ID_clause_selectivity GS_TRC_ID_PACK(COMP_OPTIMIZER, 2) +#define GS_TRC_ID_set_rel_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 3) +#define GS_TRC_ID_restore_hashjoin_cost GS_TRC_ID_PACK(COMP_OPTIMIZER, 4) +#define GS_TRC_ID_finalize_dml_cost GS_TRC_ID_PACK(COMP_OPTIMIZER, 5) +#define GS_TRC_ID_copy_mem_info GS_TRC_ID_PACK(COMP_OPTIMIZER, 6) +#define GS_TRC_ID_columnar_get_col_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 7) +#define GS_TRC_ID_get_path_actual_total_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 8) +#define GS_TRC_ID_query_planner GS_TRC_ID_PACK(COMP_OPTIMIZER, 9) +#define GS_TRC_ID_preprocess_minmax_aggregates GS_TRC_ID_PACK(COMP_OPTIMIZER, 10) +#define GS_TRC_ID_optimize_minmax_aggregates GS_TRC_ID_PACK(COMP_OPTIMIZER, 11) +#define GS_TRC_ID_set_plan_rows GS_TRC_ID_PACK(COMP_OPTIMIZER, 12) +#define GS_TRC_ID_create_plan GS_TRC_ID_PACK(COMP_OPTIMIZER, 13) +#define GS_TRC_ID_disuse_physical_tlist GS_TRC_ID_PACK(COMP_OPTIMIZER, 14) +#define GS_TRC_ID_copy_plan_costsize GS_TRC_ID_PACK(COMP_OPTIMIZER, 15) +#define GS_TRC_ID_make_subqueryscan GS_TRC_ID_PACK(COMP_OPTIMIZER, 16) +#define GS_TRC_ID_make_foreignscan GS_TRC_ID_PACK(COMP_OPTIMIZER, 17) +#define GS_TRC_ID_make_append GS_TRC_ID_PACK(COMP_OPTIMIZER, 18) +#define GS_TRC_ID_make_recursive_union GS_TRC_ID_PACK(COMP_OPTIMIZER, 19) +#define GS_TRC_ID_make_sort_from_pathkeys GS_TRC_ID_PACK(COMP_OPTIMIZER, 20) +#define GS_TRC_ID_make_sort_from_sortclauses GS_TRC_ID_PACK(COMP_OPTIMIZER, 21) +#define GS_TRC_ID_make_sort_from_groupcols GS_TRC_ID_PACK(COMP_OPTIMIZER, 22) +#define GS_TRC_ID_make_sort_from_targetlist GS_TRC_ID_PACK(COMP_OPTIMIZER, 23) +#define GS_TRC_ID_make_sort GS_TRC_ID_PACK(COMP_OPTIMIZER, 24) +#define GS_TRC_ID_make_agg GS_TRC_ID_PACK(COMP_OPTIMIZER, 25) +#define GS_TRC_ID_make_windowagg GS_TRC_ID_PACK(COMP_OPTIMIZER, 26) +#define GS_TRC_ID_make_group GS_TRC_ID_PACK(COMP_OPTIMIZER, 27) +#define GS_TRC_ID_materialize_finished_plan GS_TRC_ID_PACK(COMP_OPTIMIZER, 28) +#define GS_TRC_ID_make_unique GS_TRC_ID_PACK(COMP_OPTIMIZER, 29) +#define GS_TRC_ID_make_lockrows GS_TRC_ID_PACK(COMP_OPTIMIZER, 30) +#define GS_TRC_ID_make_limit GS_TRC_ID_PACK(COMP_OPTIMIZER, 31) +#define GS_TRC_ID_make_stream_limit GS_TRC_ID_PACK(COMP_OPTIMIZER, 32) +#define GS_TRC_ID_compare_path_costs GS_TRC_ID_PACK(COMP_OPTIMIZER, 33) +#define GS_TRC_ID_compare_fractional_path_costs GS_TRC_ID_PACK(COMP_OPTIMIZER, 34) +#define GS_TRC_ID_set_cheapest GS_TRC_ID_PACK(COMP_OPTIMIZER, 35) +#define GS_TRC_ID_get_cheapest_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 36) +#define GS_TRC_ID_find_hinted_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 37) +#define GS_TRC_ID_add_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 38) +#define GS_TRC_ID_add_path_precheck GS_TRC_ID_PACK(COMP_OPTIMIZER, 39) +#define GS_TRC_ID_create_seqscan_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 40) +#define GS_TRC_ID_create_cstorescan_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 41) +#define GS_TRC_ID_create_index_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 42) +#define GS_TRC_ID_build_seqScanPath_by_indexScanPath GS_TRC_ID_PACK(COMP_OPTIMIZER, 43) +#define GS_TRC_ID_check_bitmap_heap_path_index_unusable GS_TRC_ID_PACK(COMP_OPTIMIZER, 44) +#define GS_TRC_ID_is_partitionIndex_Subpath GS_TRC_ID_PACK(COMP_OPTIMIZER, 45) +#define GS_TRC_ID_is_pwj_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 46) +#define GS_TRC_ID_create_bitmap_heap_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 47) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/parser_gstrace.h postgresql-hll-2.14/include/gstrace/parser_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/parser_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/parser_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,24 @@ +// This is a generated file + +#ifndef _PARSER_GSTRACE_H +#define _PARSER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_make_parsestate GS_TRC_ID_PACK(COMP_PARSER, 1) +#define GS_TRC_ID_free_parsestate GS_TRC_ID_PACK(COMP_PARSER, 2) +#define GS_TRC_ID_parser_errposition GS_TRC_ID_PACK(COMP_PARSER, 3) +#define GS_TRC_ID_setup_parser_errposition_callback GS_TRC_ID_PACK(COMP_PARSER, 4) +#define GS_TRC_ID_cancel_parser_errposition_callback GS_TRC_ID_PACK(COMP_PARSER, 5) +#define GS_TRC_ID_make_var GS_TRC_ID_PACK(COMP_PARSER, 6) +#define GS_TRC_ID_transformArrayType GS_TRC_ID_PACK(COMP_PARSER, 7) +#define GS_TRC_ID_transformArraySubscripts GS_TRC_ID_PACK(COMP_PARSER, 8) +#define GS_TRC_ID_make_const GS_TRC_ID_PACK(COMP_PARSER, 9) +#define GS_TRC_ID_scanner_init GS_TRC_ID_PACK(COMP_PARSER, 10) +#define GS_TRC_ID_scanner_finish GS_TRC_ID_PACK(COMP_PARSER, 11) +#define GS_TRC_ID_core_yylex GS_TRC_ID_PACK(COMP_PARSER, 12) +#define GS_TRC_ID_scanner_errposition GS_TRC_ID_PACK(COMP_PARSER, 13) +#define GS_TRC_ID_scanner_yyerror GS_TRC_ID_PACK(COMP_PARSER, 14) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/pg_ctl_gstrace.h postgresql-hll-2.14/include/gstrace/pg_ctl_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/pg_ctl_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/pg_ctl_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,13 @@ +// This is a generated file + +#ifndef _PG_CTL_GSTRACE_H +#define _PG_CTL_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_ReceiveXlogStream GS_TRC_ID_PACK(COMP_PG_CTL, 1) +#define GS_TRC_ID_get_replconn_number GS_TRC_ID_PACK(COMP_PG_CTL, 2) +#define GS_TRC_ID_ParseReplConnInfo GS_TRC_ID_PACK(COMP_PG_CTL, 3) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/postmaster_gstrace.h postgresql-hll-2.14/include/gstrace/postmaster_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/postmaster_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/postmaster_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,72 @@ +// This is a generated file + +#ifndef _POSTMASTER_GSTRACE_H +#define _POSTMASTER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_PostmasterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 1) +#define GS_TRC_ID_ClosePostmasterPorts GS_TRC_ID_PACK(COMP_POSTMASTER, 2) +#define GS_TRC_ID_MaxLivePostmasterChildren GS_TRC_ID_PACK(COMP_POSTMASTER, 3) +#define GS_TRC_ID_HaShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 4) +#define GS_TRC_ID_HaShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 5) +#define GS_TRC_ID_postmaster_forkexec GS_TRC_ID_PACK(COMP_POSTMASTER, 6) +#define GS_TRC_ID_stream_forkexec GS_TRC_ID_PACK(COMP_POSTMASTER, 7) +#define GS_TRC_ID_WLMProcessForkExec GS_TRC_ID_PACK(COMP_POSTMASTER, 8) +#define GS_TRC_ID_SubPostmasterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 9) +#define GS_TRC_ID_ShmemBackendArraySize GS_TRC_ID_PACK(COMP_POSTMASTER, 10) +#define GS_TRC_ID_ShmemBackendArrayAllocation GS_TRC_ID_PACK(COMP_POSTMASTER, 11) +#define GS_TRC_ID_SysLogger_Start GS_TRC_ID_PACK(COMP_POSTMASTER, 12) +#define GS_TRC_ID_SysLoggerClose GS_TRC_ID_PACK(COMP_POSTMASTER, 13) +#define GS_TRC_ID_write_syslogger_file GS_TRC_ID_PACK(COMP_POSTMASTER, 14) +#define GS_TRC_ID_AioCompltrMain GS_TRC_ID_PACK(COMP_POSTMASTER, 15) +#define GS_TRC_ID_AioCompltrStop GS_TRC_ID_PACK(COMP_POSTMASTER, 16) +#define GS_TRC_ID_AioCompltrStart GS_TRC_ID_PACK(COMP_POSTMASTER, 17) +#define GS_TRC_ID_AioCompltrIsReady GS_TRC_ID_PACK(COMP_POSTMASTER, 18) +#define GS_TRC_ID_CompltrContext GS_TRC_ID_PACK(COMP_POSTMASTER, 19) +#define GS_TRC_ID_CompltrPriority GS_TRC_ID_PACK(COMP_POSTMASTER, 20) +#define GS_TRC_ID_AutoVacuumingActive GS_TRC_ID_PACK(COMP_POSTMASTER, 21) +#define GS_TRC_ID_IsAutoVacuumLauncherProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 22) +#define GS_TRC_ID_IsAutoVacuumWorkerProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 23) +#define GS_TRC_ID_autovac_init GS_TRC_ID_PACK(COMP_POSTMASTER, 24) +#define GS_TRC_ID_StartAutoVacLauncher GS_TRC_ID_PACK(COMP_POSTMASTER, 25) +#define GS_TRC_ID_StartAutoVacWorker GS_TRC_ID_PACK(COMP_POSTMASTER, 26) +#define GS_TRC_ID_AutoVacWorkerFailed GS_TRC_ID_PACK(COMP_POSTMASTER, 27) +#define GS_TRC_ID_AutoVacuumUpdateDelay GS_TRC_ID_PACK(COMP_POSTMASTER, 28) +#define GS_TRC_ID_AutoVacLauncherMain GS_TRC_ID_PACK(COMP_POSTMASTER, 29) +#define GS_TRC_ID_AutoVacWorkerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 30) +#define GS_TRC_ID_AutovacuumWorkerIAm GS_TRC_ID_PACK(COMP_POSTMASTER, 31) +#define GS_TRC_ID_AutovacuumLauncherIAm GS_TRC_ID_PACK(COMP_POSTMASTER, 32) +#define GS_TRC_ID_HandleStartupProcInterrupts GS_TRC_ID_PACK(COMP_POSTMASTER, 33) +#define GS_TRC_ID_StartupProcessMain GS_TRC_ID_PACK(COMP_POSTMASTER, 34) +#define GS_TRC_ID_PreRestoreCommand GS_TRC_ID_PACK(COMP_POSTMASTER, 35) +#define GS_TRC_ID_PostRestoreCommand GS_TRC_ID_PACK(COMP_POSTMASTER, 36) +#define GS_TRC_ID_IsFailoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 37) +#define GS_TRC_ID_IsSwitchoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 38) +#define GS_TRC_ID_IsPrimaryTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 39) +#define GS_TRC_ID_ResetSwitchoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 40) +#define GS_TRC_ID_ResetFailoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 41) +#define GS_TRC_ID_ResetPrimaryTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 42) +#define GS_TRC_ID_NotifySignalShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 43) +#define GS_TRC_ID_NotifySignalShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 44) +#define GS_TRC_ID_SendNotifySignal GS_TRC_ID_PACK(COMP_POSTMASTER, 45) +#define GS_TRC_ID_CheckNotifySignal GS_TRC_ID_PACK(COMP_POSTMASTER, 46) +#define GS_TRC_ID_BackgroundWriterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 47) +#define GS_TRC_ID_CheckpointerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 48) +#define GS_TRC_ID_RequestCheckpoint GS_TRC_ID_PACK(COMP_POSTMASTER, 49) +#define GS_TRC_ID_CheckpointWriteDelay GS_TRC_ID_PACK(COMP_POSTMASTER, 50) +#define GS_TRC_ID_ForwardFsyncRequest GS_TRC_ID_PACK(COMP_POSTMASTER, 51) +#define GS_TRC_ID_AbsorbFsyncRequests GS_TRC_ID_PACK(COMP_POSTMASTER, 52) +#define GS_TRC_ID_CheckpointerShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 53) +#define GS_TRC_ID_CheckpointerShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 54) +#define GS_TRC_ID_FirstCallSinceLastCheckpoint GS_TRC_ID_PACK(COMP_POSTMASTER, 55) +#define GS_TRC_ID_IsBgwriterProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 56) +#define GS_TRC_ID_isDirExist GS_TRC_ID_PACK(COMP_POSTMASTER, 57) +#define GS_TRC_ID_startAlarmChecker GS_TRC_ID_PACK(COMP_POSTMASTER, 58) +#define GS_TRC_ID_AlarmCheckerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 59) +#define GS_TRC_ID_fork_process GS_TRC_ID_PACK(COMP_POSTMASTER, 60) +#define GS_TRC_ID_WalWriterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 61) +#define GS_TRC_ID_ckpt_try_prune_dirty_page_queue GS_TRC_ID_PACK(COMP_POSTMASTER, 62) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/replication_gstrace.h postgresql-hll-2.14/include/gstrace/replication_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/replication_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/replication_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,62 @@ +// This is a generated file + +#ifndef _REPLICATION_GSTRACE_H +#define _REPLICATION_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_WalReceiverMain GS_TRC_ID_PACK(COMP_REPLICATION, 1) +#define GS_TRC_ID_walrcvWriterMain GS_TRC_ID_PACK(COMP_REPLICATION, 2) +#define GS_TRC_ID_WalRcvShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 3) +#define GS_TRC_ID_WalRcvShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 4) +#define GS_TRC_ID_ShutdownWalRcv GS_TRC_ID_PACK(COMP_REPLICATION, 5) +#define GS_TRC_ID_WalRcvInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 6) +#define GS_TRC_ID_connect_dn_str GS_TRC_ID_PACK(COMP_REPLICATION, 7) +#define GS_TRC_ID_RequestXLogStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 8) +#define GS_TRC_ID_get_rcv_slot_name GS_TRC_ID_PACK(COMP_REPLICATION, 9) +#define GS_TRC_ID_GetWalRcvWriteRecPtr GS_TRC_ID_PACK(COMP_REPLICATION, 10) +#define GS_TRC_ID_GetReplicationApplyDelay GS_TRC_ID_PACK(COMP_REPLICATION, 11) +#define GS_TRC_ID_GetReplicationTransferLatency GS_TRC_ID_PACK(COMP_REPLICATION, 12) +#define GS_TRC_ID_GetWalRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 13) +#define GS_TRC_ID_SetWalRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 14) +#define GS_TRC_ID_getCurrentWalRcvCtlBlock GS_TRC_ID_PACK(COMP_REPLICATION, 15) +#define GS_TRC_ID_walRcvWrite GS_TRC_ID_PACK(COMP_REPLICATION, 16) +#define GS_TRC_ID_WalRcvXLogClose GS_TRC_ID_PACK(COMP_REPLICATION, 17) +#define GS_TRC_ID_WalRcvIsShutdown GS_TRC_ID_PACK(COMP_REPLICATION, 18) +#define GS_TRC_ID_ProcessRmXLog GS_TRC_ID_PACK(COMP_REPLICATION, 19) +#define GS_TRC_ID_SetWalRcvWriterPID GS_TRC_ID_PACK(COMP_REPLICATION, 20) +#define GS_TRC_ID_WalRcvWriterInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 21) +#define GS_TRC_ID_walRcvCtlBlockIsEmpty GS_TRC_ID_PACK(COMP_REPLICATION, 22) +#define GS_TRC_ID_GetRepConnArray GS_TRC_ID_PACK(COMP_REPLICATION, 23) +#define GS_TRC_ID_get_sync_percent GS_TRC_ID_PACK(COMP_REPLICATION, 24) +#define GS_TRC_ID_wal_get_role_string GS_TRC_ID_PACK(COMP_REPLICATION, 25) +#define GS_TRC_ID_pg_stat_get_stream_replications GS_TRC_ID_PACK(COMP_REPLICATION, 26) +#define GS_TRC_ID_DataReceiverMain GS_TRC_ID_PACK(COMP_REPLICATION, 27) +#define GS_TRC_ID_DataRcvShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 28) +#define GS_TRC_ID_DataRcvShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 29) +#define GS_TRC_ID_DataRcvInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 30) +#define GS_TRC_ID_ShutdownDataRcv GS_TRC_ID_PACK(COMP_REPLICATION, 31) +#define GS_TRC_ID_StartupDataStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 32) +#define GS_TRC_ID_RequestDataStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 33) +#define GS_TRC_ID_InitDummyDataNum GS_TRC_ID_PACK(COMP_REPLICATION, 34) +#define GS_TRC_ID_WakeupDataRcvWriter GS_TRC_ID_PACK(COMP_REPLICATION, 35) +#define GS_TRC_ID_DataRcvWriterInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 36) +#define GS_TRC_ID_DataRcvDataCleanup GS_TRC_ID_PACK(COMP_REPLICATION, 37) +#define GS_TRC_ID_DataRcvWriterMain GS_TRC_ID_PACK(COMP_REPLICATION, 38) +#define GS_TRC_ID_DataRcvWrite GS_TRC_ID_PACK(COMP_REPLICATION, 39) +#define GS_TRC_ID_SetDataRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 40) +#define GS_TRC_ID_GetDataRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 41) +#define GS_TRC_ID_SetDataRcvWriterPID GS_TRC_ID_PACK(COMP_REPLICATION, 42) +#define GS_TRC_ID_ProcessDataRcvInterrupts GS_TRC_ID_PACK(COMP_REPLICATION, 43) +#define GS_TRC_ID_CloseDataFile GS_TRC_ID_PACK(COMP_REPLICATION, 44) +#define GS_TRC_ID_WalSenderMain GS_TRC_ID_PACK(COMP_REPLICATION, 45) +#define GS_TRC_ID_WalSndSignals GS_TRC_ID_PACK(COMP_REPLICATION, 46) +#define GS_TRC_ID_WalSndShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 47) +#define GS_TRC_ID_WalSndShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 48) +#define GS_TRC_ID_WalSndWakeup GS_TRC_ID_PACK(COMP_REPLICATION, 49) +#define GS_TRC_ID_WalSndRqstFileReload GS_TRC_ID_PACK(COMP_REPLICATION, 50) +#define GS_TRC_ID_WalSndInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 51) +#define GS_TRC_ID_StandbyOrSecondaryIsAlive GS_TRC_ID_PACK(COMP_REPLICATION, 52) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/rewrite_gstrace.h postgresql-hll-2.14/include/gstrace/rewrite_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/rewrite_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/rewrite_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,23 @@ +// This is a generated file + +#ifndef _REWRITE_GSTRACE_H +#define _REWRITE_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_OffsetVarNodes GS_TRC_ID_PACK(COMP_REWRITE, 1) +#define GS_TRC_ID_ChangeVarNodes GS_TRC_ID_PACK(COMP_REWRITE, 2) +#define GS_TRC_ID_IncrementVarSublevelsUp GS_TRC_ID_PACK(COMP_REWRITE, 3) +#define GS_TRC_ID_IncrementVarSublevelsUp_rtable GS_TRC_ID_PACK(COMP_REWRITE, 4) +#define GS_TRC_ID_rangeTableEntry_used GS_TRC_ID_PACK(COMP_REWRITE, 5) +#define GS_TRC_ID_attribute_used GS_TRC_ID_PACK(COMP_REWRITE, 6) +#define GS_TRC_ID_getInsertSelectQuery GS_TRC_ID_PACK(COMP_REWRITE, 7) +#define GS_TRC_ID_AddQual GS_TRC_ID_PACK(COMP_REWRITE, 8) +#define GS_TRC_ID_AddInvertedQual GS_TRC_ID_PACK(COMP_REWRITE, 9) +#define GS_TRC_ID_contain_aggs_of_level GS_TRC_ID_PACK(COMP_REWRITE, 10) +#define GS_TRC_ID_checkExprHasAggs GS_TRC_ID_PACK(COMP_REWRITE, 11) +#define GS_TRC_ID_checkExprHasWindowFuncs GS_TRC_ID_PACK(COMP_REWRITE, 12) +#define GS_TRC_ID_checkExprHasSubLink GS_TRC_ID_PACK(COMP_REWRITE, 13) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/storage_gstrace.h postgresql-hll-2.14/include/gstrace/storage_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/storage_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/storage_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,70 @@ +// This is a generated file + +#ifndef _STORAGE_GSTRACE_H +#define _STORAGE_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_InitBufferPool GS_TRC_ID_PACK(COMP_STORAGE, 1) +#define GS_TRC_ID_InitBufferPoolAccess GS_TRC_ID_PACK(COMP_STORAGE, 2) +#define GS_TRC_ID_InitBufferPoolBackend GS_TRC_ID_PACK(COMP_STORAGE, 3) +#define GS_TRC_ID_AtEOXact_Buffers GS_TRC_ID_PACK(COMP_STORAGE, 4) +#define GS_TRC_ID_PrintBufferLeakWarning GS_TRC_ID_PACK(COMP_STORAGE, 5) +#define GS_TRC_ID_CheckPointBuffers GS_TRC_ID_PACK(COMP_STORAGE, 6) +#define GS_TRC_ID_RelationGetNumberOfBlocksInFork GS_TRC_ID_PACK(COMP_STORAGE, 7) +#define GS_TRC_ID_FlushRelationBuffers GS_TRC_ID_PACK(COMP_STORAGE, 8) +#define GS_TRC_ID_FlushDatabaseBuffers GS_TRC_ID_PACK(COMP_STORAGE, 9) +#define GS_TRC_ID_DropRelFileNodeBuffers GS_TRC_ID_PACK(COMP_STORAGE, 10) +#define GS_TRC_ID_DropRelFileNodeAllBuffers GS_TRC_ID_PACK(COMP_STORAGE, 11) +#define GS_TRC_ID_DropDatabaseBuffers GS_TRC_ID_PACK(COMP_STORAGE, 12) +#define GS_TRC_ID_ProcArrayShmemSize GS_TRC_ID_PACK(COMP_STORAGE, 13) +#define GS_TRC_ID_ProcArrayAdd GS_TRC_ID_PACK(COMP_STORAGE, 14) +#define GS_TRC_ID_ProcArrayRemove GS_TRC_ID_PACK(COMP_STORAGE, 15) +#define GS_TRC_ID_ProcArrayEndTransaction GS_TRC_ID_PACK(COMP_STORAGE, 16) +#define GS_TRC_ID_ProcArrayClearTransaction GS_TRC_ID_PACK(COMP_STORAGE, 17) +#define GS_TRC_ID_SetGlobalSnapshotData GS_TRC_ID_PACK(COMP_STORAGE, 18) +#define GS_TRC_ID_UnsetGlobalSnapshotData GS_TRC_ID_PACK(COMP_STORAGE, 19) +#define GS_TRC_ID_ReloadConnInfoOnBackends GS_TRC_ID_PACK(COMP_STORAGE, 20) +#define GS_TRC_ID_DumpMemoryCtxOnBackend GS_TRC_ID_PACK(COMP_STORAGE, 21) +#define GS_TRC_ID_ProcArrayInitRecovery GS_TRC_ID_PACK(COMP_STORAGE, 22) +#define GS_TRC_ID_ProcArrayApplyRecoveryInfo GS_TRC_ID_PACK(COMP_STORAGE, 23) +#define GS_TRC_ID_ProcArrayApplyXidAssignment GS_TRC_ID_PACK(COMP_STORAGE, 24) +#define GS_TRC_ID_RecordKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 25) +#define GS_TRC_ID_ExpireTreeKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 26) +#define GS_TRC_ID_ExpireAllKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 27) +#define GS_TRC_ID_ExpireOldKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 28) +#define GS_TRC_ID_GetMaxSnapshotXidCount GS_TRC_ID_PACK(COMP_STORAGE, 29) +#define GS_TRC_ID_GetMaxSnapshotSubxidCount GS_TRC_ID_PACK(COMP_STORAGE, 30) +#define GS_TRC_ID_smgrinit GS_TRC_ID_PACK(COMP_STORAGE, 31) +#define GS_TRC_ID_smgropen GS_TRC_ID_PACK(COMP_STORAGE, 32) +#define GS_TRC_ID_smgrexists GS_TRC_ID_PACK(COMP_STORAGE, 33) +#define GS_TRC_ID_smgrsetowner GS_TRC_ID_PACK(COMP_STORAGE, 34) +#define GS_TRC_ID_smgrclearowner GS_TRC_ID_PACK(COMP_STORAGE, 35) +#define GS_TRC_ID_smgrclose GS_TRC_ID_PACK(COMP_STORAGE, 36) +#define GS_TRC_ID_smgrcloseall GS_TRC_ID_PACK(COMP_STORAGE, 37) +#define GS_TRC_ID_smgrclosenode GS_TRC_ID_PACK(COMP_STORAGE, 38) +#define GS_TRC_ID_smgrcreate GS_TRC_ID_PACK(COMP_STORAGE, 39) +#define GS_TRC_ID_smgrdounlink GS_TRC_ID_PACK(COMP_STORAGE, 40) +#define GS_TRC_ID_smgrdounlinkfork GS_TRC_ID_PACK(COMP_STORAGE, 41) +#define GS_TRC_ID_smgrextend GS_TRC_ID_PACK(COMP_STORAGE, 42) +#define GS_TRC_ID_smgrprefetch GS_TRC_ID_PACK(COMP_STORAGE, 43) +#define GS_TRC_ID_smgrread GS_TRC_ID_PACK(COMP_STORAGE, 44) +#define GS_TRC_ID_smgrwrite GS_TRC_ID_PACK(COMP_STORAGE, 45) +#define GS_TRC_ID_smgrwriteback GS_TRC_ID_PACK(COMP_STORAGE, 46) +#define GS_TRC_ID_smgrnblocks GS_TRC_ID_PACK(COMP_STORAGE, 47) +#define GS_TRC_ID_smgrtruncate GS_TRC_ID_PACK(COMP_STORAGE, 48) +#define GS_TRC_ID_smgrimmedsync GS_TRC_ID_PACK(COMP_STORAGE, 49) +#define GS_TRC_ID_smgrpreckpt GS_TRC_ID_PACK(COMP_STORAGE, 50) +#define GS_TRC_ID_smgrsync GS_TRC_ID_PACK(COMP_STORAGE, 51) +#define GS_TRC_ID_smgrpostckpt GS_TRC_ID_PACK(COMP_STORAGE, 52) +#define GS_TRC_ID_AtEOXact_SMgr GS_TRC_ID_PACK(COMP_STORAGE, 53) +#define GS_TRC_ID_BufferAlloc GS_TRC_ID_PACK(COMP_STORAGE, 54) +#define GS_TRC_ID_SyncLocalXidWait GS_TRC_ID_PACK(COMP_STORAGE, 55) +#define GS_TRC_ID_BufferSync GS_TRC_ID_PACK(COMP_STORAGE, 56) +#define GS_TRC_ID_BgBufferSync GS_TRC_ID_PACK(COMP_STORAGE, 57) +#define GS_TRC_ID_fsm_vacuum_page GS_TRC_ID_PACK(COMP_STORAGE, 58) +#define GS_TRC_ID_fsm_search GS_TRC_ID_PACK(COMP_STORAGE, 59) +#define GS_TRC_ID_fsm_set_and_search GS_TRC_ID_PACK(COMP_STORAGE, 60) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/system_gstrace.h postgresql-hll-2.14/include/gstrace/system_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/system_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/system_gstrace.h 2020-12-12 17:06:43.122346425 +0800 @@ -0,0 +1,11 @@ +// This is a generated file + +#ifndef _SYSTEM_GSTRACE_H +#define _SYSTEM_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_TRY_CATCH GS_TRC_ID_PACK(COMP_SYSTEM, 1) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/tcop_gstrace.h postgresql-hll-2.14/include/gstrace/tcop_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/tcop_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/tcop_gstrace.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,55 @@ +// This is a generated file + +#ifndef _TCOP_GSTRACE_H +#define _TCOP_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_BeginCommand GS_TRC_ID_PACK(COMP_TCOP, 1) +#define GS_TRC_ID_CreateDestReceiver GS_TRC_ID_PACK(COMP_TCOP, 2) +#define GS_TRC_ID_CreateReceiverForMerge GS_TRC_ID_PACK(COMP_TCOP, 3) +#define GS_TRC_ID_EndCommand GS_TRC_ID_PACK(COMP_TCOP, 4) +#define GS_TRC_ID_EndCommand_noblock GS_TRC_ID_PACK(COMP_TCOP, 5) +#define GS_TRC_ID_ProcessUtility GS_TRC_ID_PACK(COMP_TCOP, 6) +#define GS_TRC_ID_standard_ProcessUtility GS_TRC_ID_PACK(COMP_TCOP, 7) +#define GS_TRC_ID_UtilityReturnsTuples GS_TRC_ID_PACK(COMP_TCOP, 8) +#define GS_TRC_ID_UtilityTupleDescriptor GS_TRC_ID_PACK(COMP_TCOP, 9) +#define GS_TRC_ID_UtilityContainsQuery GS_TRC_ID_PACK(COMP_TCOP, 10) +#define GS_TRC_ID_CreateCommandTag GS_TRC_ID_PACK(COMP_TCOP, 11) +#define GS_TRC_ID_GetCommandLogLevel GS_TRC_ID_PACK(COMP_TCOP, 12) +#define GS_TRC_ID_CommandIsReadOnly GS_TRC_ID_PACK(COMP_TCOP, 13) +#define GS_TRC_ID_CheckRelationOwnership GS_TRC_ID_PACK(COMP_TCOP, 14) +#define GS_TRC_ID_pg_parse_query GS_TRC_ID_PACK(COMP_TCOP, 15) +#define GS_TRC_ID_pg_analyze_and_rewrite GS_TRC_ID_PACK(COMP_TCOP, 16) +#define GS_TRC_ID_pg_analyze_and_rewrite_params GS_TRC_ID_PACK(COMP_TCOP, 17) +#define GS_TRC_ID_pg_plan_query GS_TRC_ID_PACK(COMP_TCOP, 18) +#define GS_TRC_ID_pg_plan_queries GS_TRC_ID_PACK(COMP_TCOP, 19) +#define GS_TRC_ID_check_max_stack_depth GS_TRC_ID_PACK(COMP_TCOP, 20) +#define GS_TRC_ID_assign_max_stack_depth GS_TRC_ID_PACK(COMP_TCOP, 21) +#define GS_TRC_ID_die GS_TRC_ID_PACK(COMP_TCOP, 22) +#define GS_TRC_ID_quickdie GS_TRC_ID_PACK(COMP_TCOP, 23) +#define GS_TRC_ID_StatementCancelHandler GS_TRC_ID_PACK(COMP_TCOP, 24) +#define GS_TRC_ID_FloatExceptionHandler GS_TRC_ID_PACK(COMP_TCOP, 25) +#define GS_TRC_ID_RecoveryConflictInterrupt GS_TRC_ID_PACK(COMP_TCOP, 26) +#define GS_TRC_ID_prepare_for_client_read GS_TRC_ID_PACK(COMP_TCOP, 27) +#define GS_TRC_ID_client_read_ended GS_TRC_ID_PACK(COMP_TCOP, 28) +#define GS_TRC_ID_prepare_for_logic_conn_read GS_TRC_ID_PACK(COMP_TCOP, 29) +#define GS_TRC_ID_logic_conn_read_check_ended GS_TRC_ID_PACK(COMP_TCOP, 30) +#define GS_TRC_ID_process_postgres_switches GS_TRC_ID_PACK(COMP_TCOP, 31) +#define GS_TRC_ID_PostgresMain GS_TRC_ID_PACK(COMP_TCOP, 32) +#define GS_TRC_ID_StreamMain GS_TRC_ID_PACK(COMP_TCOP, 33) +#define GS_TRC_ID_get_stack_depth_rlimit GS_TRC_ID_PACK(COMP_TCOP, 34) +#define GS_TRC_ID_ResetUsage GS_TRC_ID_PACK(COMP_TCOP, 35) +#define GS_TRC_ID_ShowUsage GS_TRC_ID_PACK(COMP_TCOP, 36) +#define GS_TRC_ID_check_log_duration GS_TRC_ID_PACK(COMP_TCOP, 37) +#define GS_TRC_ID_set_debug_options GS_TRC_ID_PACK(COMP_TCOP, 38) +#define GS_TRC_ID_set_plan_disabling_options GS_TRC_ID_PACK(COMP_TCOP, 39) +#define GS_TRC_ID_get_stats_option_name GS_TRC_ID_PACK(COMP_TCOP, 40) +#define GS_TRC_ID_exec_parse_message GS_TRC_ID_PACK(COMP_TCOP, 41) +#define GS_TRC_ID_exec_bind_message GS_TRC_ID_PACK(COMP_TCOP, 42) +#define GS_TRC_ID_exec_execute_message GS_TRC_ID_PACK(COMP_TCOP, 43) +#define GS_TRC_ID_PortalStart GS_TRC_ID_PACK(COMP_TCOP, 44) +#define GS_TRC_ID_PortalRun GS_TRC_ID_PACK(COMP_TCOP, 45) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/tsearch_gstrace.h postgresql-hll-2.14/include/gstrace/tsearch_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/tsearch_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/tsearch_gstrace.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,14 @@ +// This is a generated file + +#ifndef _TSEARCH_GSTRACE_H +#define _TSEARCH_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_init_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 1) +#define GS_TRC_ID_reset_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 2) +#define GS_TRC_ID_gettoken_tsvector GS_TRC_ID_PACK(COMP_TSEARCH, 3) +#define GS_TRC_ID_close_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 4) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/utils_gstrace.h postgresql-hll-2.14/include/gstrace/utils_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/utils_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/utils_gstrace.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,133 @@ +// This is a generated file + +#ifndef _UTILS_GSTRACE_H +#define _UTILS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_has_any_column_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 1) +#define GS_TRC_ID_has_any_column_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 2) +#define GS_TRC_ID_has_any_column_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 3) +#define GS_TRC_ID_has_any_column_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 4) +#define GS_TRC_ID_has_any_column_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 5) +#define GS_TRC_ID_has_any_column_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 6) +#define GS_TRC_ID_has_column_privilege_name_name_name GS_TRC_ID_PACK(COMP_UTILS, 7) +#define GS_TRC_ID_has_column_privilege_name_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 8) +#define GS_TRC_ID_has_column_privilege_name_id_name GS_TRC_ID_PACK(COMP_UTILS, 9) +#define GS_TRC_ID_has_column_privilege_name_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 10) +#define GS_TRC_ID_has_column_privilege_id_name_name GS_TRC_ID_PACK(COMP_UTILS, 11) +#define GS_TRC_ID_has_column_privilege_id_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 12) +#define GS_TRC_ID_has_column_privilege_id_id_name GS_TRC_ID_PACK(COMP_UTILS, 13) +#define GS_TRC_ID_has_column_privilege_id_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 14) +#define GS_TRC_ID_has_column_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 15) +#define GS_TRC_ID_has_column_privilege_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 16) +#define GS_TRC_ID_has_column_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 17) +#define GS_TRC_ID_has_column_privilege_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 18) +#define GS_TRC_ID_has_table_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 19) +#define GS_TRC_ID_has_table_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 20) +#define GS_TRC_ID_has_table_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 21) +#define GS_TRC_ID_has_table_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 22) +#define GS_TRC_ID_has_table_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 23) +#define GS_TRC_ID_has_table_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 24) +#define GS_TRC_ID_has_sequence_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 25) +#define GS_TRC_ID_has_sequence_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 26) +#define GS_TRC_ID_has_sequence_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 27) +#define GS_TRC_ID_has_sequence_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 28) +#define GS_TRC_ID_has_sequence_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 29) +#define GS_TRC_ID_has_sequence_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 30) +#define GS_TRC_ID_has_database_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 31) +#define GS_TRC_ID_has_database_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 32) +#define GS_TRC_ID_has_database_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 33) +#define GS_TRC_ID_has_database_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 34) +#define GS_TRC_ID_has_database_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 35) +#define GS_TRC_ID_has_database_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 36) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 37) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 38) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 39) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 40) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 41) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 42) +#define GS_TRC_ID_has_function_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 43) +#define GS_TRC_ID_has_function_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 44) +#define GS_TRC_ID_has_function_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 45) +#define GS_TRC_ID_has_function_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 46) +#define GS_TRC_ID_has_function_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 47) +#define GS_TRC_ID_has_function_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 48) +#define GS_TRC_ID_has_language_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 49) +#define GS_TRC_ID_has_language_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 50) +#define GS_TRC_ID_has_language_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 51) +#define GS_TRC_ID_has_language_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 52) +#define GS_TRC_ID_has_language_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 53) +#define GS_TRC_ID_has_language_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 54) +#define GS_TRC_ID_has_nodegroup_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 55) +#define GS_TRC_ID_has_nodegroup_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 56) +#define GS_TRC_ID_has_nodegroup_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 57) +#define GS_TRC_ID_has_nodegroup_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 58) +#define GS_TRC_ID_has_nodegroup_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 59) +#define GS_TRC_ID_has_nodegroup_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 60) +#define GS_TRC_ID_has_schema_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 61) +#define GS_TRC_ID_has_schema_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 62) +#define GS_TRC_ID_has_schema_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 63) +#define GS_TRC_ID_has_schema_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 64) +#define GS_TRC_ID_has_schema_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 65) +#define GS_TRC_ID_has_schema_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 66) +#define GS_TRC_ID_has_server_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 67) +#define GS_TRC_ID_has_server_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 68) +#define GS_TRC_ID_has_server_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 69) +#define GS_TRC_ID_has_server_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 70) +#define GS_TRC_ID_has_server_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 71) +#define GS_TRC_ID_has_server_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 72) +#define GS_TRC_ID_has_tablespace_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 73) +#define GS_TRC_ID_has_tablespace_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 74) +#define GS_TRC_ID_has_tablespace_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 75) +#define GS_TRC_ID_has_tablespace_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 76) +#define GS_TRC_ID_has_tablespace_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 77) +#define GS_TRC_ID_has_tablespace_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 78) +#define GS_TRC_ID_has_type_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 79) +#define GS_TRC_ID_has_type_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 80) +#define GS_TRC_ID_has_type_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 81) +#define GS_TRC_ID_has_type_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 82) +#define GS_TRC_ID_has_type_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 83) +#define GS_TRC_ID_has_type_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 84) +#define GS_TRC_ID_pg_has_role_name_name GS_TRC_ID_PACK(COMP_UTILS, 85) +#define GS_TRC_ID_pg_has_role_name_id GS_TRC_ID_PACK(COMP_UTILS, 86) +#define GS_TRC_ID_pg_has_role_id_name GS_TRC_ID_PACK(COMP_UTILS, 87) +#define GS_TRC_ID_pg_has_role_id_id GS_TRC_ID_PACK(COMP_UTILS, 88) +#define GS_TRC_ID_pg_has_role_name GS_TRC_ID_PACK(COMP_UTILS, 89) +#define GS_TRC_ID_pg_has_role_id GS_TRC_ID_PACK(COMP_UTILS, 90) +#define GS_TRC_ID_GetConfigOption GS_TRC_ID_PACK(COMP_UTILS, 91) +#define GS_TRC_ID_GetConfigOptionResetString GS_TRC_ID_PACK(COMP_UTILS, 92) +#define GS_TRC_ID_ProcessConfigFile GS_TRC_ID_PACK(COMP_UTILS, 93) +#define GS_TRC_ID_InitializeGUCOptions GS_TRC_ID_PACK(COMP_UTILS, 94) +#define GS_TRC_ID_init_sync_guc_variables GS_TRC_ID_PACK(COMP_UTILS, 95) +#define GS_TRC_ID_repair_guc_variables GS_TRC_ID_PACK(COMP_UTILS, 96) +#define GS_TRC_ID_SelectConfigFiles GS_TRC_ID_PACK(COMP_UTILS, 97) +#define GS_TRC_ID_ResetAllOptions GS_TRC_ID_PACK(COMP_UTILS, 98) +#define GS_TRC_ID_AtStart_GUC GS_TRC_ID_PACK(COMP_UTILS, 99) +#define GS_TRC_ID_NewGUCNestLevel GS_TRC_ID_PACK(COMP_UTILS, 100) +#define GS_TRC_ID_AtEOXact_GUC GS_TRC_ID_PACK(COMP_UTILS, 101) +#define GS_TRC_ID_BeginReportingGUCOptions GS_TRC_ID_PACK(COMP_UTILS, 102) +#define GS_TRC_ID_ParseLongOption GS_TRC_ID_PACK(COMP_UTILS, 103) +#define GS_TRC_ID_set_config_option GS_TRC_ID_PACK(COMP_UTILS, 104) +#define GS_TRC_ID_GetConfigOptionByName GS_TRC_ID_PACK(COMP_UTILS, 105) +#define GS_TRC_ID_GetConfigOptionByNum GS_TRC_ID_PACK(COMP_UTILS, 106) +#define GS_TRC_ID_GetNumConfigOptions GS_TRC_ID_PACK(COMP_UTILS, 107) +#define GS_TRC_ID_SetPGVariable GS_TRC_ID_PACK(COMP_UTILS, 108) +#define GS_TRC_ID_GetPGVariable GS_TRC_ID_PACK(COMP_UTILS, 109) +#define GS_TRC_ID_GetPGVariableResultDesc GS_TRC_ID_PACK(COMP_UTILS, 110) +#define GS_TRC_ID_RewriteBeginQuery GS_TRC_ID_PACK(COMP_UTILS, 111) +#define GS_TRC_ID_ExecSetVariableStmt GS_TRC_ID_PACK(COMP_UTILS, 112) +#define GS_TRC_ID_ExtractSetVariableArgs GS_TRC_ID_PACK(COMP_UTILS, 113) +#define GS_TRC_ID_RelationIdGetRelation GS_TRC_ID_PACK(COMP_UTILS, 114) +#define GS_TRC_ID_RelationClose GS_TRC_ID_PACK(COMP_UTILS, 115) +#define GS_TRC_ID_PartitionGetPartIndexList GS_TRC_ID_PACK(COMP_UTILS, 116) +#define GS_TRC_ID_RelationGetIndexList GS_TRC_ID_PACK(COMP_UTILS, 117) +#define GS_TRC_ID_RelationGetIndexNum GS_TRC_ID_PACK(COMP_UTILS, 118) +#define GS_TRC_ID_RelationGetOidIndex GS_TRC_ID_PACK(COMP_UTILS, 119) +#define GS_TRC_ID_RelationGetIndexExpressions GS_TRC_ID_PACK(COMP_UTILS, 120) +#define GS_TRC_ID_RelationGetIndexPredicate GS_TRC_ID_PACK(COMP_UTILS, 121) +#define GS_TRC_ID_RelationGetIndexAttrBitmap GS_TRC_ID_PACK(COMP_UTILS, 122) +#define GS_TRC_ID_RelationGetExclusionInfo GS_TRC_ID_PACK(COMP_UTILS, 123) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/vecexecutor_gstrace.h postgresql-hll-2.14/include/gstrace/vecexecutor_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/vecexecutor_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/vecexecutor_gstrace.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,17 @@ +// This is a generated file + +#ifndef _VECEXECUTOR_GSTRACE_H +#define _VECEXECUTOR_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_VectorEngine GS_TRC_ID_PACK(COMP_VECEXECUTOR, 1) +#define GS_TRC_ID_ExecVecProject GS_TRC_ID_PACK(COMP_VECEXECUTOR, 2) +#define GS_TRC_ID_ExecInitVecExpr GS_TRC_ID_PACK(COMP_VECEXECUTOR, 3) +#define GS_TRC_ID_ExecAssignVecScanProjectionInfo GS_TRC_ID_PACK(COMP_VECEXECUTOR, 4) +#define GS_TRC_ID_ExecVecMarkPos GS_TRC_ID_PACK(COMP_VECEXECUTOR, 5) +#define GS_TRC_ID_ExecVecRestrPos GS_TRC_ID_PACK(COMP_VECEXECUTOR, 6) +#define GS_TRC_ID_VecExecReScan GS_TRC_ID_PACK(COMP_VECEXECUTOR, 7) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gstrace/wlm_gstrace.h postgresql-hll-2.14/include/gstrace/wlm_gstrace.h --- postgresql-hll-2.14_old/include/gstrace/wlm_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gstrace/wlm_gstrace.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,11 @@ +// This is a generated file + +#ifndef _WLM_GSTRACE_H +#define _WLM_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_WLMIsSimpleQuery GS_TRC_ID_PACK(COMP_WLM, 1) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_alarm.h postgresql-hll-2.14/include/gtm/gtm_alarm.h --- postgresql-hll-2.14_old/include/gtm/gtm_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_alarm.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,22 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_alarm.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_alarm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GTM_ALARM_H +#define GTM_ALARM_H + +extern bool enable_alarm; + +extern int GTMAddAlarmCheckerThread(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_atomic.h postgresql-hll-2.14/include/gtm/gtm_atomic.h --- postgresql-hll-2.14_old/include/gtm/gtm_atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_atomic.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,187 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_atomic.h + * + * + * + * IDENTIFICATION + * src/include/gtm/gtm_atomic.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ +#define CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ + +template +struct GTM_AtomicStride { + /* increment value when add it. */ + static const unsigned int unitSize = 1; +}; +template +struct GTM_AtomicStride { + /* increment value when add it. */ + static const unsigned int unitSize = sizeof(T); +}; + +/** + * atomic operations used in gtm + */ +template +class GTM_Atomic { +public: + /** + * Construct an GTM_Atomic use initial value + */ + explicit GTM_Atomic(const ValueType value = 0) : m_value(value) + { + } + ~GTM_Atomic(){}; + + /** + * atomic increment + */ + void add(int64_t increment) + { + __sync_fetch_and_add(&m_value, increment); + } + + /** + * atomic compare exchange + */ + ValueType compareExchange(ValueType tmpValue, ValueType newValue) + { + tmpValue = __sync_val_compare_and_swap(&m_value, tmpValue, newValue); + return tmpValue; + } + + /** + * atomic exchange + */ + ValueType exchange(ValueType newValue) + { + newValue = __sync_lock_test_and_set(&m_value, newValue); + return newValue; + } + + /** + * atomic increment + */ + void inc() + { + add(1); + } + + /** + * Return the current value. + */ + ValueType load() + { + return m_value; + } + + /** + * overload operator = + */ + GTM_Atomic& operator=(ValueType newValue) + { + store(newValue); + return *this; + } + + /** + * Return the current value. + */ + operator ValueType() + { + return load(); + } + + /** + * overload operator ++ + */ + const GTM_Atomic& operator++() + { + inc(); + return *this; + } + const GTM_Atomic operator++(int) + { + GTM_Atomic tmp = *this; + inc(); + return tmp; + } + + /** + * overload operator -- + */ + const GTM_Atomic& operator--() + { + add(-1); + return *this; + } + const GTM_Atomic operator--(int) + { + GTM_Atomic tmp = *this; + add(-1); + return tmp; + } + + /** + * set value + */ + void store(ValueType newValue) + { + m_value = newValue; + } + +protected: + /* The value on which the atomic operations operate. */ + volatile ValueType m_value; +}; + +/** + * This method provides appropriate fencing for the end of a critical + * section. It guarantees the following: + * - Loads coming from code preceding this method will complete before the + * method returns, so they will not see any changes made to memory by other + * threads after the method is invoked. + * - Stores coming from code preceding this method will be reflected + * in memory before the method returns, so when the next thread enters + * the critical section it is guaranteed to see any changes made in the + * current critical section. + */ +static inline void GTM_loadStoreFence() +{ +#ifdef __aarch64__ + + __asm__ __volatile__("DMB ish" ::: "memory"); +#else + __asm__ __volatile__("lfence" ::: "memory"); + __asm__ __volatile__("sfence" ::: "memory"); +#endif +} + +static inline void GTM_loadFence() +{ + __asm__ __volatile__("lfence" ::: "memory"); +} + +static inline void GTM_StoreFence() +{ + __asm__ __volatile__("sfence" ::: "memory"); +} +#endif /* CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_auth.h postgresql-hll-2.14/include/gtm/gtm_auth.h --- postgresql-hll-2.14_old/include/gtm/gtm_auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_auth.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_auth.h + * GTM server authentication module. + * Variables and function commands used for handling authentication between gtm client and gtm server. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_auth.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GTM_AUTH_H +#define GTM_AUTH_H +#include "gtm/gtm_opt.h" + +/* Gtm guc parameter name */ +#define GTM_OPTNAME_AUTHENTICATION_TYPE "gtm_authentication_type" +#define GTM_OPTNAME_KRB_SERVER_KEYFILE "gtm_krb_server_keyfile" + +/* define gtm server autnentication method */ +#define GTM_AUTH_REJECT (0) +#define GTM_AUTH_TRUST (1) +#define GTM_AUTH_GSS (2) + +extern int gtm_auth_method; +extern char* gtm_krb_server_keyfile; +extern const struct config_enum_entry gtm_auth_options[]; + +extern bool CheckGtmKrbKeyFilePath(char** newval, void** extra, GtmOptSource source); +extern bool CheckGtmAuthMethod(int* newval, void** extra, GtmOptSource source); +extern void GtmPerformAuthentication(GTM_ThreadInfo* thrinfo); +extern void GtmAuthCleanup(); +#endif /* GTM_AUTH_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_backup.h postgresql-hll-2.14/include/gtm/gtm_backup.h --- postgresql-hll-2.14_old/include/gtm/gtm_backup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_backup.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * gtm_backup.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2013 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_BACKUP_H +#define _GTM_BACKUP_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_seq.h" + +extern GTM_RWLock gtm_bkup_lock; +extern GTM_RWLock seq_bkup_lock; +extern uint32 GTMWorkingGrandVersionNum; + +#define SeqRestoreDuration 20000 + +extern void GTM_ReadRestorePoint(GlobalTransactionId next_gxid); +extern void GTM_ReadTimeLineAndTxactLen(GlobalTransactionId next_gxid); +extern void GTM_ReadRestoreSequence(void); +extern void GTM_WriteRestoreControlPoint(bool xid_restore); +extern void GTM_WriteRestoreSequencePoint(GTM_UUID* seq_id, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteRestorePoint(GTM_UUID* seq_id, bool xid_restore, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteControlFile(bool saveinfo, bool xid_restore); +extern void GTM_WriteSequenceFile(bool saveinfo, GTM_UUID* seq_uuid, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteXidToFile(bool saveinfo, bool xid_restore); +extern void GTM_MakeBackup(char* path); +extern void GTM_SetNeedBackup(void); +extern bool GTM_NeedBackup(void); +extern void GTM_SetXidAndTxnBackup(void); +extern void GTM_SetSequenceBackup(void); +extern bool GTM_SequenceBackup(void); +extern void GTM_WriteBarrierBackup(const char* barrier_id); + +#endif /* GTM_BACKUP_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_cgroup.h postgresql-hll-2.14/include/gtm/gtm_cgroup.h --- postgresql-hll-2.14_old/include/gtm/gtm_cgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_cgroup.h 2020-12-12 17:06:43.123346438 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_cgroup.h + * get the gaussdb cgroup relpath and initialize cgroup. + * Please note,caller should free the return value. + * + * IDENTIFICATION + * src/include/gtm/gtm_cgroup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_GTM_GTM_CGROUP_H +#define SRC_INCLUDE_GTM_GTM_CGROUP_H +extern char* gscgroup_gtm_init(); + +/* make the current thread attach to gaussdb cgroup */ +extern void gscgroup_gtm_attach_task(const char* relpath); +/* just an unused function, reserving this function for future. */ +extern void gscgroup_gtm_attach_task_pid(const char* relpath, pid_t tid); + +#endif // SRC_INCLUDE_GTM_GTM_CGROUP_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_c.h postgresql-hll-2.14/include/gtm/gtm_c.h --- postgresql-hll-2.14_old/include/gtm/gtm_c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_c.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,287 @@ +/* ------------------------------------------------------------------------- + * + * gtm_c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/c.h,v 1.234 2009/01/01 17:23:55 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_C_H +#define GTM_C_H + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#include + +#include +#include +#include "c.h" +#include "cm/etcdapi.h" + +typedef uint64 GlobalTransactionId; /* 64-bit global transaction ids */ +typedef int16 GTMProxy_ConnID; +typedef uint32 GTM_StrLen; + +#define InvalidGTMProxyConnID -1 + +typedef pthread_t GTM_ThreadID; + +typedef uint32 GTM_PGXCNodeId; +typedef uint32 GTM_PGXCNodePort; + +/* Possible type of nodes for registration */ +typedef enum GTM_PGXCNodeType { + GTM_NODE_ALL = 0, /* For pgxcnode_find_by_type, pass this value means to get all type node */ + GTM_NODE_GTM_PROXY = 1, + GTM_NODE_GTM_PROXY_POSTMASTER = 2, + /* Used by Proxy to communicate with GTM and not use Proxy headers */ + GTM_NODE_COORDINATOR = 3, + GTM_NODE_DATANODE = 4, + GTM_NODE_GTM_PRIMARY = 5, + GTM_NODE_GTM_STANDBY = 6, + GTM_NODE_GTM_CLIENT = 7, + GTM_NODE_DEFAULT = 8 /* In case nothing is associated to connection */ +} GTM_PGXCNodeType; + +typedef enum GTM_SnapshotType { + GTM_SNAPSHOT_TYPE_UNDEFINED, + GTM_SNAPSHOT_TYPE_LOCAL, + GTM_SNAPSHOT_TYPE_GLOBAL, + GTM_SNAPSHOT_TYPE_AUTOVACUUM +} GTM_SnapshotType; + +/* + * A unique handle to identify transaction at the GTM. It could just be + * an index in an array or a pointer to the structure + * + * Note: If we get rid of BEGIN transaction at the GTM, we can use GXID + * as a handle because we would never have a transaction state at the + * GTM without assigned GXID. + */ +typedef int32 GTM_TransactionHandle; +typedef uint32 GTM_Timeline; + +/* GTM_TransactionKey used to identify a transaction + * it is composed by handle and timeline + */ +typedef struct GTM_TransactionKey { + GTM_TransactionHandle txnHandle; /* txn handle in GTM */ + GTM_Timeline txnTimeline; /* txn timeline in GTM */ +} GTM_TransactionKey; + +typedef struct GTM_TransactionKey GTM_TransactionKey; + +extern GTM_Timeline gtmTimeline; +extern uint32 gtmTransactionsLenWhenExit; +extern bool write_fake_TransLen; + +extern uint32 snapshot_num; +extern uint32 snapshot_num_now; +extern uint64 snapshot_totalsize; +extern uint64 snapshot_totalsize_now; +extern uint32 MaxNumThreadActive; + +#define InvalidTransactionHandle -1 +#define InvalidTransactionTimeline 0 + +#define GlobalTransactionHandleIsValid(handle) (((GTM_TransactionHandle)(handle)) != InvalidTransactionHandle) +#define GlobalTransactionTimelineIsValid(timeline) (((GTM_Timeline)(timeline)) != InvalidTransactionTimeline) + +/* + * As GTM and Postgres-XC packages are separated, GTM and XC's API + * use different type names for timestamps and sequences, but they have to be the same! + */ +typedef int64 GTM_Timestamp; /* timestamp data is 64-bit based */ + +typedef int64 GTM_Sequence; /* a 64-bit sequence */ + +typedef int64 GTM_UUID; /* a 64-bit UUID */ + +extern EtcdSession g_etcdSession; + +/* Type of sequence name used when dropping it */ +typedef enum GTM_SequenceKeyType { + GTM_SEQ_FULL_NAME, /* Full sequence key */ + GTM_SEQ_DB_NAME, /* DB name part of sequence key */ + GTM_SEQ_DB_SCHEMA_NAME /* Part of sequence key: dbname.schemaname */ +} GTM_SequenceKeyType; + +typedef struct GTM_SequenceKeyData { + uint32 gsk_keylen; + char* gsk_key; + GTM_SequenceKeyType gsk_type; /* see constants below */ +} GTM_SequenceKeyData; /* Counter key, set by the client */ + +typedef GTM_SequenceKeyData* GTM_SequenceKey; + +typedef struct GTM_DBNameData { + uint32 gsd_dblen; + char* gsd_db; +} GTM_DBNameData; /* database that sequence belongs to */ + +typedef GTM_DBNameData* GTM_DBName; + +#define GTM_MAX_SEQKEY_LENGTH 1024 + +#define InvalidSequenceValue 0x7fffffffffffffffLL +#define SEQVAL_IS_VALID(v) ((v) != InvalidSequenceValue) + +#define MaxSequenceValue 0x7fffffffffffffffLL +#define InvalidUUID ((GTM_UUID)0) +#define InitialUUIDValue_Default ((GTM_UUID)1000000) +#define MaxSequenceUUID 0x7fffffffffffffffLL + +#define GTM_MAX_GLOBAL_TRANSACTIONS 16384 + +#define GTM_MAX_ERROR_LENGTH 1024 + +#define GTM_HOST_FLAG_BASE 100 +#define HOST2FLAG(h) ((uint32)((h) + GTM_HOST_FLAG_BASE)) +#define FLAG2HOST(f) ((GtmHostIndex)((f) - GTM_HOST_FLAG_BASE)) + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) do { \ + if (NULL != (ptr)) { \ + pfree(ptr); \ + (ptr) = NULL; \ + } \ +} while (0) +#endif + +typedef enum GTM_IsolationLevel { + GTM_ISOLATION_SERIALIZABLE, /* serializable txn */ + GTM_ISOLATION_RC /* read-committed txn */ +} GTM_IsolationLevel; + +typedef struct GTM_SnapshotData { + GlobalTransactionId sn_xmin; + GlobalTransactionId sn_xmax; + GlobalTransactionId sn_recent_global_xmin; + uint64 csn; +} GTM_SnapshotData; + +typedef GTM_SnapshotData* GTM_Snapshot; + +typedef struct GTM_SnapshotStatusData { + GlobalTransactionId xmin; + GlobalTransactionId xmax; + uint64 csn; + GlobalTransactionId recent_global_xmin; + GlobalTransactionId next_xid; + GTM_Timeline timeline; + uint32 active_thread_num; + uint32 max_thread_num; + uint32 snapshot_num; + Size snapshot_totalsize; +} GTM_SnapshotStatusData; + +typedef GTM_SnapshotStatusData* GTM_SnapshotStatus; + +/* A struct providing some info of gtm for views */ +typedef struct GTMLite_StatusData { + GlobalTransactionId backup_xid; + uint64 csn; +} GTMLite_StatusData; + +typedef GTMLite_StatusData* GTMLite_Status; + +/* Define max size of node name in start up packet */ +#define SP_NODE_NAME 64 + +typedef struct GTM_StartupPacket { + char sp_node_name[SP_NODE_NAME]; + GTM_PGXCNodeType sp_remotetype; + bool sp_ispostmaster; + pthread_t sp_remote_thdpid; +} GTM_StartupPacket; + +typedef enum GTM_PortLastCall { + GTM_LastCall_NONE = 0, + GTM_LastCall_SEND, + GTM_LastCall_RECV, + GTM_LastCall_READ, + GTM_LastCall_WRITE +} GTM_PortLastCall; + +#define InvalidGlobalTransactionId ((GlobalTransactionId)0) + +typedef enum GTMServerMode { + GTMServer_Unknown = 0, + GTMServer_PrimaryMode, + GTMServer_StandbyMode, + GTMServer_PendingMode +} GTMServerMode; + +typedef enum GTMConnectionStatus { + GTMConnection_Unknown = 0, + GTMConnection_bad, + GTMConnection_ok +} GTMConnectionStatus; + +typedef enum GTMSyncStatus { + GTMSync_Unknown = 0, + GTMSync_PrimaryMode, + GTMSync_StandbyMode +} GTMSyncStatus; + +typedef struct tagGtmHostIP { + char acHostIP[128]; +} GTM_HOST_IP; + +/* ---------- + * GTM connection states + * + * Traditionally, gtm_host_0 stands for primary while + * gtm_host_1 stands for (promoted) standby. + * ---------- + */ +typedef enum GtmHostIndex { + GTM_HOST_INVAILD = 0, + GTM_HOST_0, + GTM_HOST_1, + GTM_HOST_2, + GTM_HOST_3, + GTM_HOST_4, + GTM_HOST_5, + GTM_HOST_6, + GTM_HOST_7, +} GtmHostIndex; + +extern int gtm_max_trans; + +extern int gtm_num_threads; + +/* + * Initial GXID value to start with, when -x option is not specified at the first run. + * + * This value is supposed to be safe enough. If initdb involves huge amount of initial + * statements/transactions, users should consider to tweak this value with explicit + * -x option. + */ +#define InitialGXIDValue_Default ((GlobalTransactionId)10000) + +#define GlobalTransactionIdIsValid(gxid) (((GlobalTransactionId)(gxid)) != InvalidGlobalTransactionId) + +#ifdef ENABLE_UT +extern void GTM_CopySnapshot(GTM_Snapshot dst, GTM_Snapshot src); +#endif + +extern const char *transfer_snapshot_type(GTM_SnapshotType gtm_snap_type); +#endif /* GTM_C_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_client.h postgresql-hll-2.14/include/gtm/gtm_client.h --- postgresql-hll-2.14_old/include/gtm/gtm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_client.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,337 @@ +/* ------------------------------------------------------------------------- + * + * gtm_client.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_CLIENT_H +#define GTM_CLIENT_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_seq.h" +#include "gtm/gtm_txn.h" +#include "gtm/gtm_msg.h" +#include "gtm/utils/register.h" +#include "gtm/utils/libpq-fe.h" + +/* DFX: client error code for connecting to GTM */ +typedef enum GTMClientErrCode { + GTMC_OK = 0, + GTMC_SEND_ERROR, + GTMC_RECV_ERROR +} GTMClientErrCode; + +typedef enum GTM_CONN_ERR { + GTM_OK, + GTM_UNCONNECTED = 0xE, + GTM_START_ERROR, + GTM_SEND_ERROR, + GTM_SEND_END_ERROR, + GTM_FLUSH_ERROR, + GTM_RECEIVE_ERROR, +} GTM_CONN_ERR_T; + +typedef union GTM_ResultData { + GTM_TransactionHandle grd_txnhandle; /* TXN_BEGIN */ + + struct { + GlobalTransactionId gxid; + GTM_Timestamp timestamp; + } grd_gxid_tp; /* TXN_BEGIN_GETGXID */ + + GlobalTransactionId grd_gxid; /* TXN_PREPARE + * TXN_START_PREPARED + * TXN_GET_GLOBAL_XMIN_RESULT + */ + struct { + GlobalTransactionId gxid; + int status; + } grd_txn_rc; /* + * TXN_COMMIT + * TXN_COMMIT_PREPARED + * TXN_ROLLBACK + */ + + GlobalTransactionId grd_next_gxid; + + struct { + GTM_TransactionHandle txnhandle; + GlobalTransactionId gxid; + } grd_txn; /* TXN_GET_GXID */ + + GTM_SequenceKeyData grd_seqkey; /* SEQUENCE_INIT + * SEQUENCE_RESET + * SEQUENCE_CLOSE */ + + GTM_DBNameData grd_seqdb; /* SEQUENCE_RENAME */ + + struct { + GTM_UUID seq_uuid; + } grd_uuid; /* SEQUENCE_GET_UUID */ + + struct { + GTM_UUID seq_uuid; + GTM_Sequence seqval; + GTM_Sequence rangemax; + } grd_seq; /* SEQUENCE_GET_NEXT */ + + struct { + int seq_count; + GTM_SeqInfo* seq; + } grd_seq_list; /* SEQUENCE_GET_LIST */ + + struct { + int txn_count; /* TXN_BEGIN_GETGXID_MULTI */ + GlobalTransactionId start_gxid; + GTM_Timestamp timestamp; + } grd_txn_get_multi; + + struct { + int txn_count; /* TXN_COMMIT_MULTI */ + int status[GTM_MAX_GLOBAL_TRANSACTIONS]; + } grd_txn_rc_multi; + + struct { + GTM_TransactionHandle txnhandle; /* SNAPSHOT_GXID_GET */ + GlobalTransactionId gxid; /* SNAPSHOT_GET */ + int txn_count; /* SNAPSHOT_GET_MULTI */ + int status[GTM_MAX_GLOBAL_TRANSACTIONS]; + } grd_txn_snap_multi; + + struct { + GlobalTransactionId gxid; + GlobalTransactionId prepared_gxid; + int nodelen; + char* nodestring; + } grd_txn_get_gid_data; /* TXN_GET_GID_DATA_RESULT */ + + struct { + char* ptr; + size_t len; + } grd_txn_gid_list; /* TXN_GXID_LIST_RESULT */ + + struct { + GTM_PGXCNodeType type; /* NODE_REGISTER */ + size_t len; + char* node_name; /* NODE_UNREGISTER */ + } grd_node; + + struct { + int num_node; + GTM_PGXCNodeInfo* nodeinfo[MAX_NODES]; + } grd_node_list; + + struct { + int server_mode; + int connection_status; + GlobalTransactionId xid; + long send_count; + long receive_count; + int sync_mode; + } grd_query_gtm_status; /*MSG_QUREY_GTM_STATUS*/ + + int grd_gtm_sync_mode_result; + + int32 grd_check_standby_role_result; /*MSG_CHECK_STANDBY_ROLE*/ + + int32 grd_sync_file_result; /*MSG_SYNC_FILE*/ + + int32 grd_check_next_gxid_result; /*MSG_SYNC_FILE*/ + + struct { + int max_server_memory; + double query_memory_limit; + } grd_workload_manager_init_result; /*MSG_TXN_WORKLOAD_INIT*/ + + int32 grd_create_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_CREATE*/ + int32 grd_update_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_UPDATE*/ + int32 grd_delete_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_DELETE*/ + int32 grd_init_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_INIT*/ + + struct { + int32 length; + char* result; + } gtm_hotpatch_result; + /* + * TXN_GET_STATUS + * TXN_GET_ALL_PREPARED + */ +} GTM_ResultData; + +#define GTM_RESULT_COMM_ERROR (-2) /* Communication error */ +#define GTM_RESULT_ERROR (-1) +#define GTM_RESULT_OK (0) +/* + * This error is used ion the case where allocated buffer is not large + * enough to store the errors. It may happen of an allocation failed + * so it's status is considered as unknown. + */ +#define GTM_RESULT_UNKNOWN (1) + +typedef struct GTM_Result { + GTM_ResultType gr_type; + int gr_msglen; + int gr_status; + GTM_ProxyMsgHeader gr_proxyhdr; + GTM_ResultData gr_resdata; + GTM_Timeline gr_timeline; /*GTM start status, now mean restart times*/ + uint64 csn; /* snapshot csn or commit csn */ + /* + * We keep these two items outside the union to avoid repeated malloc/free + * of the xip array. If these items are pushed inside the union, they may + * get overwritten by other members in the union + */ + int gr_xip_size; + GTM_SnapshotData gr_snapshot; + GTM_SnapshotStatusData gr_snapshot_status; + GTMLite_StatusData gr_gtm_lite_status; + + /* + * Similarly, keep the buffer for proxying data outside the union + */ + char* gr_proxy_data; + int gr_proxy_datalen; +} GTM_Result; + +/* + * Connection Management API + */ +GTM_Conn* connect_gtm(const char* connect_string); + +int get_node_list(GTM_Conn*, GTM_PGXCNodeInfo*, size_t); +GlobalTransactionId get_next_gxid(GTM_Conn*); +CommitSeqNo get_next_csn(GTM_Conn* conn, bool is_gtm_lite); +TransactionId get_global_xmin(GTM_Conn* conn); +GTM_Timeline get_gtm_timeline(GTM_Conn* conn); +int32 get_txn_gxid_list(GTM_Conn*, GTM_Transactions*); +int get_sequence_list(GTM_Conn*, GTM_SeqInfo**); + +/* + * Transaction Management API + */ +int reset_gtm_handle_xmin(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_TransactionKey txnKey); +int set_gtm_vaccum_flag(GTM_Conn* conn, bool is_vaccum, GTM_TransactionKey txnKey); +GTM_TransactionKey begin_transaction(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_Timestamp* timestamp); +GlobalTransactionId begin_get_gxid(GTM_Conn* conn, GTM_TransactionKey txn, bool is_sub_xact, GTMClientErrCode* err); + +GlobalTransactionId begin_transaction_gxid(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_Timestamp* timestamp); + +int bkup_gtm_control_file_gxid(GTM_Conn* conn, GlobalTransactionId gxid); +int bkup_gtm_control_file_timeline(GTM_Conn* conn, GTM_Timeline timeline); + +GlobalTransactionId begin_transaction_autovacuum(GTM_Conn* conn, GTM_IsolationLevel isolevel); + +int commit_transaction(GTM_Conn *conn, GlobalTransactionId gxid, GlobalTransactionId *childXids, int nChildXids, + uint64 *commit_csn = NULL); +int commit_transaction_handle(GTM_Conn *conn, GTM_TransactionKey txnKey, GlobalTransactionId *gxid, bool is_backup, + uint64 *commit_csn); +int bkup_commit_transaction(GTM_Conn *conn, GlobalTransactionId gxid); + +int commit_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); +int bkup_commit_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); +int abort_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId* childXids, int nChildXids); +int abort_transaction_handle(GTM_Conn* conn, GTM_TransactionKey txnKey, GlobalTransactionId* gxid, bool is_backup); +int bkup_abort_transaction(GTM_Conn* conn, GlobalTransactionId gxid); + +int start_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, const char* gid, const char* nodestring); +int prepare_transaction(GTM_Conn* conn, GlobalTransactionId gxid); +int bkup_prepare_transaction(GTM_Conn* conn, GlobalTransactionId gxid); +int get_gid_data(GTM_Conn* conn, GTM_IsolationLevel isolevel, const char* gid, GlobalTransactionId* gxid, + GlobalTransactionId* prepared_gxid, char** nodestring); + +/* + * Snapshot Management API + */ +GTM_SnapshotData *get_snapshot(GTM_Conn *conn, GTM_TransactionKey txnKey, GlobalTransactionId gxid, bool canbe_grouped, + bool is_vacuum); +GTM_SnapshotData *get_snapshot_gtm_lite(GTM_Conn *conn); +GTMLite_StatusData *get_status_gtm_lite(GTM_Conn *conn); + + +GTM_SnapshotStatusData* get_snapshot_status(GTM_Conn* conn, GTM_TransactionKey key); + +/* + * Node Registering management API + */ +int node_register(GTM_Conn *conn, GTM_PGXCNodeType type, GTM_PGXCNodePort port, char *node_name, char *datafolder, + uint32 timeline); + +int node_register_internal(GTM_Conn* conn, GTM_PGXCNodeType type, const char* host, GTM_PGXCNodePort port, + const char* node_name, const char* datafolder, GTM_PGXCNodeStatus status); +int bkup_node_register_internal(GTM_Conn* conn, GTM_PGXCNodeType type, const char* host, GTM_PGXCNodePort port, + const char* node_name, const char* datafolder, GTM_PGXCNodeStatus status); +int node_unregister(GTM_Conn* conn, GTM_PGXCNodeType type, const char* node_name); +int bkup_node_unregister(GTM_Conn* conn, GTM_PGXCNodeType type, const char* node_name); +int backend_disconnect(GTM_Conn* conn, bool is_postmaster, GTM_PGXCNodeType type, const char* node_name); + +/* + * Sequence Management API + */ +GTM_UUID get_next_sequuid(GTM_Conn* conn); +int get_uuid(GTM_Conn* conn, GTM_UUID* result, GTMClientErrCode* err); +int bkup_seq_uuid(GTM_Conn* conn, GTM_UUID seq_uuid); + +int open_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, GTMClientErrCode *err = NULL); +int bkup_open_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, + GTMClientErrCode *err); +int alter_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +int bkup_alter_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +int close_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int bkup_close_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int rename_sequence(GTM_Conn *conn, GTM_DBName dbName, GTM_DBName newdbName); +int bkup_rename_sequence(GTM_Conn *conn, GTM_DBName dbName, GTM_DBName newdbName); + +int get_next(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence* result, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence range, GTM_Sequence* rangemax, bool cycle); +int bkup_get_next(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence* result, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence range, GTM_Sequence* rangemax, bool cycle); +int set_val(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence nextval, bool is_called); +int bkup_set_val(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence nextval, GTM_Sequence range, bool is_called); +int reset_sequence(GTM_Conn* conn, GTM_UUID seq_uuid); +int bkup_reset_sequence(GTM_Conn* conn, GTM_UUID seq_uuid); + +/* + * Barrier + */ +int report_barrier(GTM_Conn* conn, const char* barier_id); +int bkup_report_barrier(GTM_Conn* conn, const char* barrier_id); + +/* + * GTM-Standby + */ +int set_begin_end_backup(GTM_Conn* conn, bool begin); +int gtm_sync_standby(GTM_Conn* conn, bool autosync); +int set_begin_end_switchover(GTM_Conn* conn, bool begin); +int gtm_check_remote_role(GTM_Conn* conn, int32 port, int32* result); +int sync_files_to_standby(GTM_Conn* conn, int filetype, const char* files, int len); + +/* + * * workload management API + * */ +int bkup_initialize_workload_manager(GTM_Conn* conn, int initServerMem); +int initialize_workload_manager(GTM_Conn* conn, int* max_server_memory, double* query_memory_limit); +int bkup_reserve_memory_wlm(GTM_Conn* conn, int memoryCost, const char*, int); +int reserve_memory_wlm(GTM_Conn* conn, int memoryCost, const char*, int); +int bkup_release_memory_wlm(GTM_Conn* conn, int memoryReserve, const char*, int); +int release_memory_wlm(GTM_Conn* conn, int memoryReserve, const char*, int); + +int CreateUpdateResourcePool(GTM_Conn* conn, bool create, char* rpName, int rpId, int memPercentage); +int DeleteResourcePool(GTM_Conn* conn, char* rpName, int rpId); +int InitResourcePool(GTM_Conn* conn, int rp_count, int buf_len, char* buf); + +/* Set parameter API */ +void set_gtm_client_rw_timeout(int timeout); +extern void process_for_gtm_connection_failed(GTM_Conn* conn); +extern THR_LOCAL bool need_reset_xmin; +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_conn.h postgresql-hll-2.14/include/gtm/gtm_conn.h --- postgresql-hll-2.14_old/include/gtm/gtm_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_conn.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,43 @@ +/* ------------------------------------------------------------------------- + * + * gtm_conn.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_CONN_H +#define GTM_CONN_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/utils/libpq-fe.h" +#include "gtm/utils/libpq-int.h" + +struct GTM_ThreadInfo; + +typedef struct GTM_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + struct GTM_ThreadInfo* con_thrinfo; + bool con_authenticated; + + /* a connection object to the standby */ + GTM_Conn* standby; + + /* times of receiving illegal message */ + int illegal_message_count; +} GTM_ConnectionInfo; + +typedef struct GTM_Connections { + uint32 gc_conn_count; + uint32 gc_array_size; + GTM_ConnectionInfo* gc_connections; + GTM_RWLock gc_lock; +} GTM_Connections; + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_csnsync.h postgresql-hll-2.14/include/gtm/gtm_csnsync.h --- postgresql-hll-2.14_old/include/gtm/gtm_csnsync.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_csnsync.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_csnsync.h + * GTM csn sync thread head file. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_csnsync.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GTM_CSNSYNC_H +#define GTM_CSNSYNC_H +extern int GTMAddCsnSyncThread(void); +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_dynahash.h postgresql-hll-2.14/include/gtm/gtm_dynahash.h --- postgresql-hll-2.14_old/include/gtm/gtm_dynahash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_dynahash.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,122 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_dynahash.h + * POSTGRES dynahash.h file definitions + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_dynahash.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DYNAHASH_H +#define DYNAHASH_H + +#include "gtm_spinlock.h" +#include "gtm_hsearch.h" + +/* Number of freelists to be used for a partitioned hash table. */ +#define NUM_FREELISTS 32 + +/* A hash bucket is a linked list of HASHELEMENTs */ +typedef HASHELEMENT* HASHBUCKET; + +/* A hash segment is an array of bucket headers */ +typedef HASHBUCKET* HASHSEGMENT; + +/* + * Using array of FreeListData instead of separate arrays of mutexes, nentries + * and freeLists prevents, at least partially, sharing one cache line between + * different mutexes (see below). + */ +typedef struct { + slock_t mutex; /* spinlock */ + long nentries; /* number of entries */ + HASHELEMENT* freeList; /* list of free elements */ +} FreeListData; + +/* + * Header structure for a hash table --- contains all changeable info + * + * In a shared-memory hash table, the HASHHDR is in shared memory, while + * each backend has a local HTAB struct. For a non-shared table, there isn't + * any functional difference between HASHHDR and HTAB, but we separate them + * anyway to share code between shared and non-shared tables. + */ +struct HASHHDR { + /* + * The freelist can become a point of contention on high-concurrency hash + * tables, so we use an array of freelist, each with its own mutex and + * nentries count, instead of just a single one. + * + * If hash table is not partitioned only freeList[0] is used and spinlocks + * are not used at all. + */ + FreeListData freeList[NUM_FREELISTS]; + + /* These fields can change, but not in a partitioned table */ + /* Also, dsize can't change in a shared table, even if unpartitioned */ + long dsize; /* directory size */ + long nsegs; /* number of allocated segments (<= dsize) */ + uint32 max_bucket; /* ID of maximum bucket in use */ + uint32 high_mask; /* mask to modulo into entire table */ + uint32 low_mask; /* mask to modulo into lower half of table */ + + /* These fields are fixed at hashtable creation */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + long num_partitions; /* # partitions (must be power of 2), or 0 */ + long ffactor; /* target fill factor */ + long max_dsize; /* 'dsize' limit if directory is fixed size */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ + int nelem_alloc; /* number of entries to allocate at once */ + +#ifdef HASH_STATISTICS + + /* + * Count statistics here. NB: stats code doesn't bother with mutex, so + * counts could be corrupted a bit in a partitioned table. + */ + long accesses; + long collisions; +#endif +}; + +/* the offset of the last padding if exists*/ +#define HTAB_PAD_OFFSET 104 + +/* + * Top control structure for a hashtable --- in a shared table, each backend + * has its own copy (OK since no fields change at runtime) + */ +struct HTAB { + HASHHDR* hctl; /* => shared control information */ + HASHSEGMENT* dir; /* directory of segment starts */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context if default allocator used */ + char* tabname; /* table name (for error messages) */ + bool isshared; /* true if table is in shared memory */ + bool isfixed; /* if true, don't enlarge */ + + /* freezing a shared table isn't allowed, so we can keep state here */ + bool frozen; /* true = no more inserts allowed */ + + /* We keep local copies of these fixed values to reduce contention */ + Size keysize; /* hash key length in bytes */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - HTAB_PAD_OFFSET]; +#endif +}; + +extern int my_log2(long num); + +#endif /* DYNAHASH_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_event.h postgresql-hll-2.14/include/gtm/gtm_event.h --- postgresql-hll-2.14_old/include/gtm/gtm_event.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_event.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,109 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_event.h + * GTM event header file + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/gtm/gtm_event.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GTM_EVENT_H +#define GTM_EVENT_H + +#include "gtm/utils/event_engine.h" + +/* + * states of a connection + */ +enum gs_gtm_conn_states { + GS_GTM_CONN_LISTENING, + GS_GTM_CONN_ACCEPTED, + GS_GTM_CONN_WAIT_DATA_RECEIVE, + GS_GTM_CONN_PROCESS, + GS_GTM_CONN_CLOSE, + GS_GTM_CONN_MAX_STATE +}; + +const char* const gs_gtm_state_name[] = { + "GS_GTM_CONN_LISTENING", + "GS_GTM_CONN_ACCEPTED", + "GS_GTM_CONN_WAIT_DATA_RECEIVE", + "GS_GTM_CONN_PROCESS", + "GS_GTM_CONN_CLOSE", + "GS_GTM_CONN_MAX_STATE" +}; + +enum gs_gtm_conn_substates { + GS_GTM_CONN_PROCESS_BEGIN, + GS_GTM_CONN_PROCESS_PROGRESSING, + GS_GTM_CONN_PROCESS_END +}; + +typedef struct gs_gtm_conn gs_gtm_conn_t; +typedef struct gs_gtm_conn_queue gs_gtm_cq_t; +typedef struct gs_gtm_conn_queue_item gs_gtm_cqi_t; +typedef struct gs_gtm_event_thread gs_gtm_event_thread_t; + +struct gs_gtm_conn_queue_item { + int sfd; + SockAddr sa; + enum gs_gtm_conn_states init_state; + unsigned short event_flags; + struct gs_gtm_conn_queue_item *next; +}; + +/* A connection queue. */ +struct gs_gtm_conn_queue { + gs_gtm_cqi_t *head; + gs_gtm_cqi_t *tail; + pthread_mutex_t lock; +}; + +struct gs_gtm_event_thread { + pthread_t thread_id; /* unique ID of this thread */ + int tid; /* thread index in the global thread array */ + struct event_base *base; /* event engine handle this thread uses */ + struct event notify_event; /* listen event for notify pipe */ + int notify_receive_fd; /* receiving end of notify pipe */ + int notify_send_fd; /* sending end of notify pipe */ + gs_gtm_cq_t *new_conn_queue; /* queue of new connections to handle */ + GTM_ThreadInfo *thrinfo; + pg_atomic_int32 status; +}; + +struct gs_gtm_conn { + int sfd; + pg_atomic_int32 refcount; + GTM_ConnectionInfo *gtm_conninfo; + enum gs_gtm_conn_states state; + enum gs_gtm_conn_substates conn_process_substate; + struct event event; + unsigned short ev_flags; + unsigned short which; + bool is_switchover_processing; + gs_gtm_event_thread_t *thread; + struct gs_gtm_conn *next; +}; + +extern int gs_gtm_max_conns_per_event; +extern int gtm_num_threads; +extern int gs_gtm_max_conns; +extern gs_gtm_conn_t **gs_gtm_conns; +extern pthread_t gs_gtm_start_workers_requester; + +extern int gs_gtm_conn_pool_init(); +extern void gs_gtm_thread_pool_init(int nthreads); +extern int gs_gtm_listen_conns_init(const int listen_sockets[], int nsockets, struct event_base *main_base); +extern void gs_gtm_listen_conns_refresh(const int listen_sockets[], int nsockets, struct event_base *main_base); +extern void gs_gtm_start_workers(); +extern void gs_gtm_quit_workers(); +extern void gs_gtm_signal_start_workers(); +extern void gs_gtm_check_restart_worker(); +extern void gs_gtm_set_worker_exit(gs_gtm_event_thread_t *thread); +extern void gs_gtm_conn_closesocket(int sfd); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_ext.h postgresql-hll-2.14/include/gtm/gtm_ext.h --- postgresql-hll-2.14_old/include/gtm/gtm_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_ext.h 2020-12-12 17:06:43.124346451 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * gtm_ext.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_EXT_H +#define GTM_EXT_H + +/* + * Identifiers of error message fields. Kept here to keep common + * between frontend and backend, and also to export them to libpq + * applications. + */ +#define PG_DIAG_SEVERITY 'S' +#define PG_DIAG_MESSAGE_PRIMARY 'M' +#define PG_DIAG_MESSAGE_DETAIL 'D' +#define PG_DIAG_MESSAGE_HINT 'H' +#define PG_DIAG_SOURCE_FILE 'F' +#define PG_DIAG_SOURCE_LINE 'L' +#define PG_DIAG_SOURCE_FUNCTION 'R' + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm.h postgresql-hll-2.14/include/gtm/gtm.h --- postgresql-hll-2.14_old/include/gtm/gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,286 @@ +/* ------------------------------------------------------------------------- + * + * gtm.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_H +#define _GTM_H + +#include + +#include "common/config/cm_config.h" +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_conn.h" +#include "gtm/utils/elog.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_semaphore.h" + +extern char* GTMLogFileName; +extern FILE* gtmlogFile; + +extern volatile long int NumThreadAdded; +extern volatile long int NumThreadRemoved; + +extern char* Log_directory; +extern GTM_RWLock gtmlogFileLock; + +#define MAXLISTEN 64 + +#define MAX_IPADDR_LEN 32 +#define MAX_IPSTR_LEN 64 + +#define ETCD_AVA() (g_etcd_num > 0) + +typedef struct GTM_ListenEntry { + char ipaddr[MAX_IPADDR_LEN]; + int portnum; + bool needcreate; +} GTM_ListenEntry; + +typedef struct GTM_ListenAddress { + int usedNum; + GTM_ListenEntry listenArray[MAXLISTEN]; +} GTM_ListenAddress; + +/* gtm synchronous level */ +#define SYNC_GTM_OFF (0) /* asynchronous transmission between gtm and standby */ +#define SYNC_GTM_ON (1) /* synchronous transmission between gtm and standby */ +#define SYNC_GTM_AUTO (2) /* available sync mode switch sync to async */ + +typedef enum GTM_ThreadStatus { + GTM_THREAD_STARTING, + GTM_THREAD_RUNNING, + GTM_THREAD_EXITING, + GTM_THREAD_BACKUP, /* Backup to standby is in progress */ + GTM_THREAD_SWITCHOVER, + /* Must be the last */ + GTM_THREAD_INVALID +} GTM_ThreadStatus; + +typedef volatile uint32 pg_atomic_uint32; + +struct GTM_ConnectionInfo; + +#define ERRORDATA_STACK_SIZE 20 + +#define GTM_MAX_PATH 1024 +#define INVALID_GROUP_NEXT (0x7FFFFFFF) /* int32 max value*/ + +/* + * This struct is for counting messages send and receive of gtm thread between primary and standby + * Notice: current counter type is uint32. When the message count is too big than the max value of + * uint32(overflow uint32), this may have problem, some thread counter will be started from zero again. + */ +typedef struct GTM_ThreadStat { + uint32 thr_send_count; /*current thread send message count */ + uint32 thr_receive_count; /*current thread receive message count */ + uint32 thr_localid; /*the location of current thread in global thread stat array */ + bool thr_used; /*mark this thread stat slot is used or not. */ +} GTM_ThreadStat; + +typedef struct GTM_ThreadInfo { + /* + * Thread specific information such as connection(s) served by it + */ + GTM_ThreadID thr_id; + uint32 thr_localid; + bool is_main_thread; + void* (*thr_startroutine)(void*); + void (*thr_cleanuproutine)(void*); + + MemoryContext thr_thread_context; + MemoryContext thr_message_context; + MemoryContext thr_current_context; + MemoryContext thr_error_context; + MemoryContext thr_parent_context; + + sigjmp_buf* thr_sigjmp_buf; + + ErrorData thr_error_data[ERRORDATA_STACK_SIZE]; + int thr_error_stack_depth; + int thr_error_recursion_depth; + int thr_criticalsec_count; + + GTM_ThreadStatus thr_status; + GTM_ConnectionInfo* thr_conn; + /* unique client identifier */ + uint32 thr_client_id; + bool thr_need_bkup; + bool thr_seq_bkup; + bool thr_thread_over; + + GTM_RWLock thr_lock; + gtm_List* thr_cached_txninfo; + + /* main thread set other thread sema_key. */ + int sema_key; + /* when this thread want to one sema, create it. */ + PGSemaphoreData sema; + + /* store the next thread index for group sequence. */ + pg_atomic_uint32 group_next; + /* the end thread in group. */ + pg_atomic_uint32 group_end_index; + + /* + * if it's INVALID_GROUP_NEXT, that means it's not in blocked list of sequence info. + * otherwise it's blocked until the sequence is synced to standby/etcd successfully. + */ + pg_atomic_uint32 next_blocked_thread; + + /* + * store the sequence infomation, in order to transfer + * seq info for threads of thread group. + */ + GTM_ThreadSeqInfo seq_info_set; + + bool success_get_seq; +} GTM_ThreadInfo; + +typedef struct GTM_Threads { + uint32 gt_thread_count; + uint32 gt_array_size; + bool gt_standby_ready; + GTM_ThreadInfo** gt_threads; + GTM_RWLock gt_lock; + pg_atomic_uint32 thread_group_first; +} GTM_Threads; + +extern volatile GTM_Threads* GTMThreads; +extern int get_gtm_port(); + +GTM_ThreadStat* GTM_GetThreadStatSlot(uint32 localid); +int GTM_ThreadAdd(GTM_ThreadInfo* thrinfo); +int GTM_ThreadRemove(GTM_ThreadInfo* thrinfo); +int GTM_ThreadJoin(GTM_ThreadInfo* thrinfo); +void GTM_ThreadExit(void); +void ConnFree(Port* port); +void GTM_LockAllOtherThreads(void); +void GTM_UnlockAllOtherThreads(void); +void GTM_DoForAllOtherThreads(void (*process_routine)(GTM_ThreadInfo*)); +void FlushPort(Port* myport); +void CollectGTMStatus(Port* myport, bool is_backup); + +extern GTM_ThreadInfo* GTM_ThreadCreate( + GTM_ConnectionInfo* conninfo, bool normal_thread, void* (*startroutine)(void*), void (*cleanuproutine)(void* argp)); +extern GTM_ThreadInfo *GTM_ThreadCreateNoBlock(bool normal_thread, pthread_attr_t *pThreadAttr, + void* (*startroutine)(void*), void (*cleanuproutine)(void* argp)); +extern void GTM_ThreadCleanup(void* argp); +extern void GTM_CsnSyncCleanup(void *argp); +extern void GTM_AlarmCheckerCleanup(void* argp); + +GTM_ThreadInfo* GTM_GetThreadInfo(GTM_ThreadID thrid); + +extern void DestroyConnectControlTable(void); +extern void RebuildConnectControlTable(void); + +/* + * pthread keys to get thread specific information + */ +extern pthread_key_t threadinfo_key; +extern MemoryContext TopMostMemoryContext; +extern GTM_ThreadID TopMostThreadID; + +extern char* ListenAddresses; +extern int GTMPortNumber; +extern GTM_HOST_IP* ListenArray; +extern int ListenLength; + +extern char* active_addr; +extern int active_port; +extern GTM_HOST_IP* ActAddressArray; +extern int ActAddressLength; +extern int standby_connection_timeout; + +extern char* HALocalHost; +extern int HALocalPort; +extern GTM_HOST_IP* HaAddressArray; +extern int HaAddressLength; +extern bool LocalAddressChanged; +extern bool LocalPortChanged; +extern bool EnableConnectControl; +#define GTMOPTION_GTM 0 +#define GTMOPTION_GTMLITE 1 +#define GTMOPTION_GTMFREE 2 +extern int gtm_option; +extern int CsnSyncInterval; +extern int RestoreDuration; + +extern volatile int Backup_synchronously; +extern int guc_standby_only; + +extern char* NodeName; +extern char GTMControlFile[GTM_MAX_PATH]; +extern char GTMSequenceFile[GTM_MAX_PATH]; +extern volatile bool GTMPreAbortPending; +extern volatile bool primary_switchover_processing; +extern bool switchover_processing; + +extern GTM_RWLock* mainThreadLock; + +#define SetMyThreadInfo(thrinfo) pthread_setspecific(threadinfo_key, (thrinfo)) +#define GetMyThreadInfo ((GTM_ThreadInfo*)pthread_getspecific(threadinfo_key)) + +#define TopMemoryContext (GetMyThreadInfo->thr_thread_context) +#define ThreadTopContext (GetMyThreadInfo->thr_thread_context) +#define MessageContext (GetMyThreadInfo->thr_message_context) +#define CurrentMemoryContext (GetMyThreadInfo->thr_current_context) +#define ErrorContext (GetMyThreadInfo->thr_error_context) +#define errordata (GetMyThreadInfo->thr_error_data) +#define recursion_depth (GetMyThreadInfo->thr_error_recursion_depth) +#define errordata_stack_depth (GetMyThreadInfo->thr_error_stack_depth) +#define CritSectionCount (GetMyThreadInfo->thr_criticalsec_count) +#define gtm_need_bkup (GetMyThreadInfo->thr_need_bkup) +#define seq_need_bkup (GetMyThreadInfo->thr_seq_bkup) + +#define PG_exception_stack (GetMyThreadInfo->thr_sigjmp_buf) +#define MyConnection (GetMyThreadInfo->thr_conn) +#define MyPort ((GetMyThreadInfo->thr_conn != NULL) ? GetMyThreadInfo->thr_conn->con_port : NULL) +#define MyThreadID (GetMyThreadInfo->thr_id) +#define IsMainThread() (GetMyThreadInfo->thr_id == TopMostThreadID) + +#define GTM_CachedTransInfo (GetMyThreadInfo->thr_cached_txninfo) +#define GTM_HaveFreeCachedTransInfo() (gtm_list_length(GTM_CachedTransInfo)) + +#define GTM_MAX_CACHED_TRANSINFO 0 +#define GTM_HaveEnoughCachedTransInfo() (gtm_list_length(GTM_CachedTransInfo) >= GTM_MAX_CACHED_TRANSINFO) + +#define START_CRIT_SECTION() (CritSectionCount++) + +#define END_CRIT_SECTION() do { \ + Assert(CritSectionCount > 0); \ + CritSectionCount--; \ +} while (0) + +typedef enum GtmHaMode { + GHM_NO_HA, /* used for normal. */ + GHM_SINGLE_STANDBY, /* used for mode without etcd. */ + GHM_MULT_STANDBY, /* used for mode under multistandbys, only sync data with etcd. */ + GHM_MIXED /* used for version commpatible, one primary & one standby. */ +} GtmHaMode; + +extern volatile GtmHaMode gtm_ha_mode; +#define IS_SINGLE_STANBY_HA_MODE() (gtm_ha_mode == GHM_SINGLE_STANDBY) +#define IS_MULT_STANDBY_HA_MODE() (gtm_ha_mode == GHM_MULT_STANDBY) +#define IS_MIXED_HA_MODE() (gtm_ha_mode == GHM_MIXED) +#define MINORITY_MODE() (Backup_synchronously == SYNC_GTM_OFF && IS_MULT_STANDBY_HA_MODE()) +#define ETCD_MODE() (IS_MULT_STANDBY_HA_MODE() || (!IS_MULT_STANDBY_HA_MODE() && ETCD_AVA())) + +#define ETCD_MODE_ACTIVE_PORT 0 + +#define SET_GTM_HAMODE(mode) do { \ + Assert((mode) >= GHM_SINGLE_STANDBY && (mode) <= GHM_MIXED); \ + gtm_ha_mode = (mode); \ +} while (0) + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_hsearch.h postgresql-hll-2.14/include/gtm/gtm_hsearch.h --- postgresql-hll-2.14_old/include/gtm/gtm_hsearch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_hsearch.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,156 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_hsearch.h + * exported definitions for utils/hash/dynahash.c; see notes therein + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_hsearch.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef HSEARCH_H +#define HSEARCH_H + +/* + * Hash functions must have this signature. + */ +typedef uint32 (*HashValueFunc)(const void* key, Size keysize); + +/* + * Key comparison functions must have this signature. Comparison functions + * return zero for match, nonzero for no match. (The comparison function + * definition is designed to allow memcmp() and strncmp() to be used directly + * as key comparison functions.) + */ +typedef int (*HashCompareFunc)(const void* key1, const void* key2, Size keysize); + +/* + * Key copying functions must have this signature. The return value is not + * used. (The definition is set up to allow memcpy() and strncpy() to be + * used directly.) + */ +typedef void* (*HashCopyFunc)(void* dest, const void* src, Size keysize); + +/* + * Space allocation function for a hashtable --- designed to match malloc(). + * Note: there is no free function API; can't destroy a hashtable unless you + * use the default allocator. + */ +typedef void* (*HashAllocFunc)(Size request); + +/* + * Space deallocation function for a hashtable --- designed to match allocator(). + * Note: it's a free function API; you must use it with allocator you defined. + */ +typedef void (*HashDeallocFunc)(void* pointer); + +/* + * HASHELEMENT is the private part of a hashtable entry. The caller's data + * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key + * is expected to be at the start of the caller's hash entry data structure. + */ +typedef struct HASHELEMENT { + struct HASHELEMENT* link; /* link to next entry in same bucket */ + uint32 hashvalue; /* hash function result for this entry */ +} HASHELEMENT; + +/* Hash table header struct is an opaque type known only within dynahash.c */ +typedef struct HASHHDR HASHHDR; + +/* Hash table control struct is an opaque type known only within dynahash.c */ +typedef struct HTAB HTAB; + +/* Parameter data structure for hash_create */ +/* Only those fields indicated by hash_flags need be set */ +typedef struct HASHCTL { + long num_partitions; /* # partitions (must be power of 2) */ + long ssize; /* segment size */ + long dsize; /* (initial) directory size */ + long max_dsize; /* limit to dsize if dir size is limited */ + long ffactor; /* fill factor */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context to use for allocations */ + HASHHDR* hctl; /* location of header in shared mem */ +} HASHCTL; + +/* Flags to indicate which parameters are supplied */ +#define HASH_PARTITION 0x001 /* Hashtable is used w/partitioned locking */ +#define HASH_SEGMENT 0x002 /* Set segment size */ +#define HASH_DIRSIZE 0x004 /* Set directory size (initial and max) */ +#define HASH_FFACTOR 0x008 /* Set fill factor */ +#define HASH_FUNCTION 0x010 /* Set user defined hash function */ +#define HASH_ELEM 0x020 /* Set keysize and entrysize */ +#define HASH_SHARED_MEM 0x040 /* Hashtable is in shared memory */ +#define HASH_ATTACH 0x080 /* Do not initialize hctl */ +#define HASH_ALLOC 0x100 /* Set memory allocator */ +#define HASH_CONTEXT 0x200 /* Set memory allocation context */ +#define HASH_COMPARE 0x400 /* Set user defined comparison function */ +#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */ +#define HASH_FIXED_SIZE 0x1000 /* Initial size is a hard limit */ +#define HASH_HEAP_MEM 0x2000 /* Hashtable is in heap memory */ +#define HASH_EXTERN_CONTEXT 0x4000 /* use extern context directly */ +#define HASH_SHRCTX 0x8000 /* Set shared memory allocation context */ +#define HASH_DEALLOC 0x10000 /* Set memory deallocator */ +#define HASH_BLOBS 0x20000 /* Select support functions for binary keys */ +#define HASH_NOEXCEPT 0x40000 /* Do not throw exception when malloc memory */ + +/* max_dsize value to indicate expansible directory */ +#define NO_MAX_DSIZE (-1) + +/* hash_search operations */ +typedef enum { + HASH_FIND, + HASH_ENTER, + HASH_REMOVE, + HASH_ENTER_NULL +} HASHACTION; + +/* hash_seq status (should be considered an opaque type by callers) */ +typedef struct { + HTAB* hashp; + uint32 curBucket; /* index of current bucket */ + HASHELEMENT* curEntry; /* current entry in bucket */ +} HASH_SEQ_STATUS; + +/* + * prototypes for functions in dynahash.c + */ +extern HTAB *hash_create(const char *tabname, long nelem, HASHCTL *info, int flags); +extern void hash_destroy(HTAB *hashp); +extern void hash_remove(HTAB *hashp); +extern void hash_stats(const char *where, HTAB *hashp); +extern void *hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr); +extern uint32 get_hash_value(HTAB *hashp, const void *keyPtr); +extern void *hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, + bool *foundPtr); +extern long hash_get_num_entries(HTAB *hashp); +extern void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp); +extern void *hash_seq_search(HASH_SEQ_STATUS *status); +extern void hash_seq_term(HASH_SEQ_STATUS *status); +extern void hash_freeze(HTAB *hashp); +extern Size hash_estimate_size(long num_entries, Size entrysize); +extern long hash_select_dirsize(long num_entries); +extern Size hash_get_shared_size(HASHCTL* info, int flags); +extern int hash_get_seq_num(); +extern void release_all_seq_scan(); +extern MemoryContext hash_get_current_dynacxt(void); + +/* + * prototypes for functions in hashfn.c + */ +extern uint32 string_hash(const void* key, Size keysize); +extern uint32 tag_hash(const void* key, Size keysize); +extern uint32 oid_hash(const void* key, Size keysize); +extern uint32 bitmap_hash(const void* key, Size keysize); +extern int bitmap_match(const void* key1, const void* key2, Size keysize); + +#endif /* HSEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_ip.h postgresql-hll-2.14/include/gtm/gtm_ip.h --- postgresql-hll-2.14_old/include/gtm/gtm_ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_ip.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * gtm_ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.20 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_IP_H +#define GTM_IP_H + +#include "gtm/utils/pqcomm.h" + +extern int gtm_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, + struct addrinfo **result); +extern void gtm_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai); + +extern int gtm_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, + int servicelen, int flags); + +extern int gtm_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int gtm_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void gtm_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void gtm_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* GTM_IP_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_list.h postgresql-hll-2.14/include/gtm/gtm_list.h --- postgresql-hll-2.14_old/include/gtm/gtm_list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_list.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,270 @@ +/* ------------------------------------------------------------------------- + * + * gtm_list.h + * interface for PostgreSQL generic linked list package + * + * This package implements singly-linked homogeneous lists. + * + * It is important to have constant-time length, append, and prepend + * operations. To achieve this, we deal with two distinct data + * structures: + * + * 1. A set of "list cells": each cell contains a data field and + * a link to the next cell in the list or NULL. + * 2. A single structure containing metadata about the list: the + * type of the list, pointers to the head and tail cells, and + * the length of the list. + * + * We support three types of lists: + * + * T_List: lists of pointers + * (in practice usually pointers to Nodes, but not always; + * declared as "void *" to minimize casting annoyances) + * T_IntList: lists of integers + * T_OidList: lists of Oids + * + * (At the moment, ints and Oids are the same size, but they may not + * always be so; try to be careful to maintain the distinction.) + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.59 2008/08/14 18:48:00 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_LIST_H +#define GTM_LIST_H + +typedef struct gtm_ListCell gtm_ListCell; + +typedef struct gtm_List { + int length; + gtm_ListCell* head; + gtm_ListCell* tail; +} gtm_List; + +struct gtm_ListCell { + union { + void* ptr_value; + int int_value; + } data; + gtm_ListCell* next; +}; + +/* + * The *only* valid representation of an empty list is gtm_NIL; in other + * words, a non-gtm_NIL list is guaranteed to have length >= 1 and + * head/tail != NULL + */ +#define gtm_NIL ((gtm_List*)NULL) + +/* + * These routines are used frequently. However, we can't implement + * them as macros, since we want to avoid double-evaluation of macro + * arguments. Therefore, we implement them using GCC inline functions, + * and as regular functions with non-GCC compilers. + */ +#ifdef __GNUC__ + +static __inline__ gtm_ListCell* gtm_list_head(gtm_List* l) +{ + return l ? l->head : NULL; +} + +static __inline__ gtm_ListCell* gtm_list_tail(gtm_List* l) +{ + return l ? l->tail : NULL; +} + +static __inline__ int gtm_list_length(gtm_List* l) +{ + return l ? l->length : 0; +} +#else + +extern gtm_ListCell* gtm_list_head(gtm_List* l); +extern gtm_ListCell* gtm_list_tail(gtm_List* l); +extern int gtm_list_length(gtm_List* l); +#endif /* __GNUC__ */ + +/* + * NB: There is an unfortunate legacy from a previous incarnation of + * the gtm_List API: the macro gtm_lfirst() was used to mean "the data in this + * cons cell". To avoid changing every usage of gtm_lfirst(), that meaning + * has been kept. As a result, gtm_lfirst() takes a gtm_ListCell and returns + * the data it contains; to get the data in the first cell of a + * gtm_List, use gtm_linitial(). Worse, gtm_lsecond() is more closely related to + * gtm_linitial() than gtm_lfirst(): given a gtm_List, gtm_lsecond() returns the data + * in the second cons cell. + */ + +#define gtm_lnext(lc) ((lc)->next) +#define gtm_lfirst(lc) ((lc)->data.ptr_value) +#define gtm_lfirst_int(lc) ((lc)->data.int_value) + +#define gtm_linitial(l) gtm_lfirst(gtm_list_head(l)) +#define gtm_linitial_int(l) gtm_lfirst_int(gtm_list_head(l)) + +#define gtm_lsecond(l) gtm_lfirst(gtm_lnext(gtm_list_head(l))) +#define gtm_lsecond_int(l) gtm_lfirst_int(gtm_lnext(gtm_list_head(l))) + +#define gtm_lthird(l) gtm_lfirst(gtm_lnext(gtm_lnext(gtm_list_head(l)))) +#define gtm_lthird_int(l) gtm_lfirst_int(gtm_lnext(gtm_lnext(gtm_list_head(l)))) + +#define gtm_lfourth(l) gtm_lfirst(gtm_lnext(gtm_lnext(gtm_lnext(gtm_list_head(l))))) +#define gtm_lfourth_int(l) gtm_lfirst_int(gtm_lnext(gtm_lnext(gtm_lnext(gtm_list_head(l))))) + +#define gtm_llast(l) gtm_lfirst(gtm_list_tail(l)) +#define gtm_llast_int(l) gtm_lfirst_int(gtm_list_tail(l)) + +/* + * Convenience macros for building fixed-length lists + */ +#define gtm_list_make1(x1) gtm_lcons(x1, gtm_NIL) +#define gtm_list_make2(x1, x2) gtm_lcons(x1, gtm_list_make1(x2)) +#define gtm_list_make3(x1, x2, x3) gtm_lcons(x1, gtm_list_make2(x2, x3)) +#define gtm_list_make4(x1, x2, x3, x4) gtm_lcons(x1, gtm_list_make3(x2, x3, x4)) + +#define gtm_list_make1_int(x1) gtm_lcons_int(x1, gtm_NIL) +#define gtm_list_make2_int(x1, x2) gtm_lcons_int(x1, gtm_list_make1_int(x2)) +#define gtm_list_make3_int(x1, x2, x3) gtm_lcons_int(x1, gtm_list_make2_int(x2, x3)) +#define gtm_list_make4_int(x1, x2, x3, x4) gtm_lcons_int(x1, gtm_list_make3_int(x2, x3, x4)) + +/* + * gtm_foreach - + * a convenience macro which loops through the list + */ +#define gtm_foreach(cell, l) for ((cell) = gtm_list_head(l); (cell) != NULL; (cell) = gtm_lnext(cell)) + +/* + * gtm_for_each_cell - + * a convenience macro which loops through a list starting from a + * specified cell + */ +#define gtm_for_each_cell(cell, initcell) for ((cell) = (initcell); (cell) != NULL; (cell) = gtm_lnext(cell)) + +/* + * gtm_forboth - + * a convenience macro for advancing through two linked lists + * simultaneously. This macro loops through both lists at the same + * time, stopping when either list runs out of elements. Depending + * on the requirements of the call site, it may also be wise to + * assert that the lengths of the two lists are gtm_equal. + */ +#define gtm_forboth(cell1, list1, cell2, list2) \ + for ((cell1) = gtm_list_head(list1), (cell2) = gtm_list_head(list2); (cell1) != NULL && (cell2) != NULL; \ + (cell1) = gtm_lnext(cell1), (cell2) = gtm_lnext(cell2)) + +extern gtm_List* gtm_lappend(gtm_List* list, void* datum); +extern gtm_List* gtm_lappend_int(gtm_List* list, int datum); + +extern gtm_ListCell* gtm_lappend_cell(gtm_List* list, gtm_ListCell* prev, void* datum); +extern gtm_ListCell* gtm_lappend_cell_int(gtm_List* list, gtm_ListCell* prev, int datum); + +extern gtm_List* gtm_lcons(void* datum, gtm_List* list); +extern gtm_List* gtm_lcons_int(int datum, gtm_List* list); + +extern gtm_List* gtm_list_concat(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_truncate(gtm_List* list, int new_size); + +extern void* gtm_list_nth(gtm_List* list, int n); +extern int gtm_list_nth_int(gtm_List* list, int n); + +extern bool gtm_list_member(gtm_List* list, const void* datum); +extern bool gtm_list_member_ptr(gtm_List* list, const void* datum); +extern bool gtm_list_member_int(gtm_List* list, int datum); + +extern gtm_List* gtm_list_delete(gtm_List* list, const void* datum); +extern gtm_List* gtm_list_delete_ptr(gtm_List* list, const void* datum); +extern gtm_List* gtm_list_delete_int(gtm_List* list, int datum); +extern gtm_List* gtm_list_delete_first(gtm_List* list); +extern gtm_List* gtm_list_delete_cell(gtm_List* list, gtm_ListCell* cell, gtm_ListCell* prev); + +extern gtm_List* gtm_list_union(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_union_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_union_int(gtm_List* list1, gtm_List* list2); + +extern gtm_List* gtm_list_intersection(gtm_List* list1, gtm_List* list2); +/* currently, there's no need for list_intersection_int etc */ + +extern gtm_List* gtm_list_difference(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_difference_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_difference_int(gtm_List* list1, gtm_List* list2); + +extern gtm_List* gtm_list_append_unique(gtm_List* list, void* datum); +extern gtm_List* gtm_list_append_unique_ptr(gtm_List* list, void* datum); +extern gtm_List* gtm_list_append_unique_int(gtm_List* list, int datum); + +extern gtm_List* gtm_list_concat_unique(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_concat_unique_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_concat_unique_int(gtm_List* list1, gtm_List* list2); + +extern void gtm_list_free(gtm_List* list); +extern void gtm_list_free_deep(gtm_List* list); + +extern gtm_List* gtm_list_copy(gtm_List* list); +extern gtm_List* gtm_list_copy_tail(gtm_List* list, int nskip); + +/* + * To ease migration to the new list API, a set of compatibility + * macros are provided that reduce the impact of the list API changes + * as far as possible. Until client code has been rewritten to use the + * new list API, the ENABLE_LIST_COMPAT symbol can be defined before + * including pg_list.h + */ +#ifdef ENABLE_LIST_COMPAT + +#define gtm_lfirsti(lc) gtm_lfirst_int(lc) + +#define gtm_makeList1(x1) gtm_list_make1(x1) +#define gtm_makeList2(x1, x2) gtm_list_make2(x1, x2) +#define gtm_makeList3(x1, x2, x3) gtm_list_make3(x1, x2, x3) +#define gtm_makeList4(x1, x2, x3, x4) gtm_list_make4(x1, x2, x3, x4) + +#define gtm_makeListi1(x1) gtm_list_make1_int(x1) +#define gtm_makeListi2(x1, x2) gtm_list_make2_int(x1, x2) + +#define gtm_lconsi(datum, list) gtm_lcons_int(datum, list) + +#define gtm_lappendi(list, datum) gtm_lappend_int(list, datum) + +#define gtm_nconc(l1, l2) gtm_list_concat(l1, l2) + +#define gtm_nth(n, list) gtm_list_nth(list, n) + +#define gtm_member(datum, list) gtm_list_member(list, datum) +#define gtm_ptrMember(datum, list) gtm_list_member_ptr(list, datum) +#define gtm_intMember(datum, list) gtm_list_member_int(list, datum) + +/* + * Note that the old gtm_lremove() determined equality via pointer + * comparison, whereas the new gtm_list_delete() uses gtm_equal(); in order to + * keep the same behavior, we therefore need to map gtm_lremove() calls to + * gtm_list_delete_ptr() rather than gtm_list_delete() + */ +#define gtm_lremove(elem, list) gtm_list_delete_ptr(list, elem) +#define gtm_LispRemove(elem, list) gtm_list_delete(list, elem) +#define gtm_lremovei(elem, list) gtm_list_delete_int(list, elem) + +#define gtm_ltruncate(n, list) gtm_list_truncate(list, n) + +#define gtm_set_union(l1, l2) gtm_list_union(l1, l2) +#define gtm_set_ptrUnion(l1, l2) gtm_list_union_ptr(l1, l2) + +#define gtm_set_difference(l1, l2) gtm_list_difference(l1, l2) +#define gtm_set_ptrDifference(l1, l2) gtm_list_difference_ptr(l1, l2) + +#define gtm_equali(l1, l2) gtm_equal(l1, l2) +#define gtm_equalo(l1, l2) gtm_equal(l1, l2) + +#define gtm_freeList(list) gtm_list_free(list) + +#define gtm_listCopy(list) gtm_list_copy(list) + +extern int gtm_length(gtm_List* list); +#endif /* ENABLE_LIST_COMPAT */ + +#endif /* GTM_LIST_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_lock.h postgresql-hll-2.14/include/gtm/gtm_lock.h --- postgresql-hll-2.14_old/include/gtm/gtm_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_lock.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,93 @@ +/* ------------------------------------------------------------------------- + * + * gtm_lock.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_LOCK_H +#define GTM_LOCK_H + +#include + +typedef struct GTM_RWLock { + pthread_rwlock_t lk_lock; +} GTM_RWLock; + +typedef struct GTM_MutexLock { + pthread_mutex_t lk_lock; +} GTM_MutexLock; + +typedef enum GTM_LockMode { + GTM_LOCKMODE_WRITE, + GTM_LOCKMODE_READ +} GTM_LockMode; + +typedef struct GTM_CV { + pthread_cond_t cv_condvar; +} GTM_CV; + +extern void GTM_RWLockAcquire(GTM_RWLock* lock, GTM_LockMode mode); +extern void GTM_RWLockRelease(GTM_RWLock* lock); +extern void GTM_RWLockInit(GTM_RWLock* lock); +extern void GTM_RWLockDestroy(GTM_RWLock* lock); +extern bool GTM_RWLockConditionalAcquire(GTM_RWLock* lock, GTM_LockMode mode); + +extern void GTM_MutexLockAcquire(GTM_MutexLock* lock); +extern void GTM_MutexLockRelease(GTM_MutexLock* lock); +extern void GTM_MutexLockInit(GTM_MutexLock* lock); +extern void GTM_MutexLockDestroy(GTM_MutexLock* lock); +extern void GTM_MutexLockConditionalAcquire(GTM_MutexLock* lock); + +extern int GTM_CVInit(GTM_CV* cv); +extern int GTM_CVDestroy(GTM_CV* cv); +extern int GTM_CVSignal(GTM_CV* cv); +extern int GTM_CVBcast(GTM_CV* cv); +extern int GTM_CVWait(GTM_CV* cv, GTM_MutexLock* lock); + +// AutoGTMRWLock +// Auto object for GTM reader-writer lock +// +class AutoGTMRWLock { +public: + AutoGTMRWLock(_in_ volatile GTM_RWLock* glock) + { + m_glock = (GTM_RWLock*)glock; + } + + ~AutoGTMRWLock() + { + LockRelease(); + } + + inline void LockAcquire(_in_ GTM_LockMode mode) + { + GTM_RWLockAcquire(m_glock, mode); + } + + inline bool LockConditionalAcquire(_in_ GTM_LockMode mode) + { + return GTM_RWLockConditionalAcquire(m_glock, mode); + } + + inline void LockRelease() + { + if (m_glock != NULL) { + GTM_RWLockRelease(m_glock); + m_glock = NULL; + } + } + +private: + // Point to an existing GTM_RWLock object + // + GTM_RWLock* m_glock; +}; +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_msg.h postgresql-hll-2.14/include/gtm/gtm_msg.h --- postgresql-hll-2.14_old/include/gtm/gtm_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_msg.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,218 @@ +/* ------------------------------------------------------------------------- + * + * gtm_msg.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_MSG_H +#define GTM_MSG_H + +/* + * The following enum symbols are also used in message_name_tab structure + * in gtm_utils.c. Modification of the following enum should reflect + * changes to message_name_tab structure as well. + */ +typedef enum GTM_MessageType { + MSG_TYPE_INVALID, + MSG_SYNC_STANDBY, /* Message to sync woth GTM-Standby */ + MSG_NODE_REGISTER, /* Register a PGXC Node with GTM */ + MSG_BKUP_NODE_REGISTER, /* Backup of MSG_NODE_REGISTER */ + MSG_NODE_UNREGISTER, /* Unregister a PGXC Node with GTM */ + MSG_BKUP_NODE_UNREGISTER, /* Backup of MSG_NODE_UNREGISTER */ + MSG_NODE_LIST, /* Get node list */ + MSG_NODE_BEGIN_REPLICATION_INIT, /* deprecated message for upgrade compatibility */ + MSG_NODE_END_REPLICATION_INIT, /* deprecated message for upgrade compatibility */ + MSG_BEGIN_BACKUP, /* Start backup by Standby */ + + MSG_END_BACKUP, /* End backup preparation by Standby */ + MSG_TXN_XMINRESET, /* reset handle xmin when isolation is RC */ + MSG_TXN_BEGIN, /* Start a new transaction */ + MSG_BKUP_TXN_BEGIN, /* Backup of MSG_TXN_BEGIN */ + MSG_TXN_BEGIN_GETGXID, /* Start a new transaction and get GXID */ + MSG_BKUP_TXN_BEGIN_GETGXID, /* Backup of MSG_TXN_BEGIN_GETGXID */ + MSG_BKUP_GTM_CONTROL_FILE_GXID, /*Backup of gtm control file gxid */ + MSG_BKUP_GTM_CONTROL_FILE_TIMELINE, /*Backup of gtm control file timeline */ + MSG_TXN_BEGIN_GETGXID_MULTI, /* Start multiple new transactions and get GXIDs */ + MSG_BKUP_TXN_BEGIN_GETGXID_MULTI, /* Backup of MSG_TXN_BEGIN_GETGXID_MULTI */ + MSG_TXN_START_PREPARED, /* Begins to prepare a transation for commit */ + MSG_BKUP_TXN_START_PREPARED, /* Backup of MSG_TXN_START_PREPARED */ + + MSG_TXN_COMMIT, /* Commit a running or prepared transaction */ + MSG_BKUP_TXN_COMMIT, /* Backup of MSG_TXN_COMMIT */ + MSG_TXN_COMMIT_MULTI, /* Commit multiple running or prepared transactions */ + MSG_BKUP_TXN_COMMIT_MULTI, /* Bacukp of MSG_TXN_COMMIT_MULTI */ + MSG_TXN_COMMIT_PREPARED, /* Commit a prepared transaction */ + MSG_BKUP_TXN_COMMIT_PREPARED, /* Backup of MSG_TXN_COMMIT_PREPARED */ + MSG_TXN_PREPARE, /* Finish preparing a transaction */ + MSG_BKUP_TXN_PREPARE, /* Backup of MSG_TXN_PREPARE */ + MSG_TXN_ROLLBACK, /* Rollback a transaction */ + MSG_BKUP_TXN_ROLLBACK, /* Backup of MSG_TXN_ROLLBACK */ + + MSG_TXN_ROLLBACK_MULTI, /* Rollback multiple transactions */ + MSG_BKUP_TXN_ROLLBACK_MULTI, /* Backup of MSG_TXN_ROLLBACK_MULTI */ + MSG_TXN_GET_GID_DATA, /* Get info associated with a GID, and get a GXID */ + MSG_TXN_GET_GXID, /* Get a GXID for a transaction */ + MSG_SUB_TXN_GET_GXID, /* Get a GXID for a sub transaction */ + MSG_BKUP_TXN_GET_GXID, + MSG_TXN_GET_NEXT_GXID, /* Get next GXID */ + MSG_TXN_GET_NEXT_CSN, /* Get next CSN without commit */ + MSG_TXN_GET_TIMELINE, /* Get gtm timeline*/ + MSG_TXN_GET_GLOBAL_XMIN, /* Get global xmin */ + MSG_TXN_GXID_LIST, + MSG_SET_VACUUM_FLAG, + MSG_SNAPSHOT_GET, /* Get a global snapshot */ + MSG_SNAPSHOT_GET_MULTI, /* Get multiple global snapshots */ + MSG_SNAPSHOT_STATUS_GET, /* Get snapshot status */ + + MSG_SNAPSHOT_GXID_GET, /* Get GXID and snapshot together */ + MSG_SEQUENCE_GET_NEXT_UUID, /* Get sequuid for issuring sequence */ + MSG_SEQUENCE_UUID, /* Create UUID matched with seqKey */ + MSG_BKUP_SEQUENCE_UUID, /* Backup of MSG_SEQUENCE_UUID */ + MSG_BKUP_GTM_UUID, /* Backup of gtm control file seq_uuid*/ + MSG_SEQUENCE_INIT, /* Initialize a new global sequence =41*/ + MSG_BKUP_SEQUENCE_INIT, /* Backup of MSG_SEQUENCE_INIT */ + MSG_SEQUENCE_GET_NEXT, /* Get the next sequence value of sequence */ + MSG_BKUP_SEQUENCE_GET_NEXT, /* Backup of MSG_SEQUENCE_GET_NEXT */ + MSG_SEQUENCE_GET_LAST, /* Get the last sequence value of sequence */ + MSG_SEQUENCE_SET_VAL, /* Set values for sequence */ + MSG_BKUP_SEQUENCE_SET_VAL, /* Backup of MSG_SEQUENCE_SET_VAL */ + MSG_SEQUENCE_RESET, /* Reset the sequence */ + MSG_BKUP_SEQUENCE_RESET, /* Backup of MSG_SEQUENCE_RESET */ + + MSG_SEQUENCE_CLOSE, /* Close a previously inited sequence 50*/ + MSG_BKUP_SEQUENCE_CLOSE, /* Backup of MSG_SEQUENCE_CLOSE */ + MSG_SEQUENCE_RENAME, /* Rename a sequence */ + MSG_BKUP_SEQUENCE_RENAME, /* Backup of MSG_SEQUENCE_RENAME */ + MSG_SEQUENCE_ALTER, /* Alter a sequence */ + MSG_BKUP_SEQUENCE_ALTER, /* Backup of MSG_SEQUENCE_ALTER */ + MSG_SEQUENCE_LIST, /* Get a list of sequences */ + MSG_TXN_GET_STATUS, /* Get status of a given transaction */ + MSG_TXN_GET_ALL_PREPARED, /* Get information about all outstanding + * prepared transactions */ + MSG_TXN_BEGIN_GETGXID_AUTOVACUUM, /* Start a new transaction and get GXID for autovacuum */ + MSG_BKUP_TXN_BEGIN_GETGXID_AUTOVACUUM, /* Backup of MSG_TXN_BEGIN_GETGXID_AUTOVACUUM */ + MSG_DATA_FLUSH, /* flush pending data */ + MSG_BACKEND_DISCONNECT, /* tell GTM that the backend diconnected from the proxy */ + MSG_BARRIER, /* Tell the barrier was issued */ + MSG_BKUP_BARRIER, /* Backup barrier to standby */ + MSG_BEGIN_SWITCHOVER, /*Tell primary GTM to do switchover*/ + MSG_END_SWITCHOVER, /*Tell primary GTM to do switchover*/ + MSG_QUERY_GTM_STATUS, + MSG_SET_GTM_SYNCMODE, + MSG_CHECK_REMOTE_ROLE, + MSG_SYNC_FILE, + MSG_TXN_WORKLOAD_INIT, /* Initialize the workload manager bookkeeper */ + MSG_BKUP_TXN_WORKLOAD_INIT, /* Backup of MSG_TXN_WORKLOAD_INIT */ + MSG_TXN_WORKLOAD_RESERVE_MEM, /* Workload management: reserve memory if there is enough */ + MSG_BKUP_TXN_WORKLOAD_RESERVE_MEM, /* Backup of MSG_TXN_WORKLOAD_RESERVE_MEM */ + MSG_TXN_WORKLOAD_RELEASE_MEM, /* return to WLM the memory reserved after execution is done */ + MSG_BKUP_TXN_WORKLOAD_RELEASE_MEM, /* Backup of MSG_TXN_WORKLOAD_RELEASE_MEM */ + MSG_WLM_RESOURCEPOOL_CREATE, /*create resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_UPDATE, /*update resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_DELETE, /*delete resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_INIT, /*initialize resource pool list on gtm*/ + MSG_CHECK_NEXT_GXID, + MSG_BKUP_GTM_CONTROL_FILE_SEQUENCE, /*Backup of gtm control file sequence*/ + + MSG_HOTPATCH, + + MSG_TXN_GET_NEXT_CSN_LITE, /* gtm-lite commit csn */ + MSG_SNAPSHOT_GET_LITE, /* Get a GTMLite global snapshot */ + MSG_GET_GTM_LITE_STATUS, /* Get the status of gtm lite */ + /* + * Must be at the end + */ + MSG_TYPE_COUNT /* A dummmy entry just to count the message types */ +} GTM_MessageType; + +/* + * Symbols in the following enum are usd in result_name_tab defined in gtm_utils.c. + * Modifictaion to the following enum should be reflected to result_name_tab as well. + */ +typedef enum GTM_ResultType { + SYNC_STANDBY_RESULT, + NODE_REGISTER_RESULT, + NODE_UNREGISTER_RESULT, + NODE_LIST_RESULT, + NODE_BEGIN_REPLICATION_INIT_RESULT, /* deprecated return type for upgrade compatibility */ + NODE_END_REPLICATION_INIT_RESULT, /* deprecated return type for upgrade compatibility */ + BEGIN_BACKUP_RESULT, + END_BACKUP_RESULT, + TXN_XMINRESET_RESULT, + TXN_SETVACUUM_RESULT, + TXN_BEGIN_RESULT, + TXN_BEGIN_GETGXID_RESULT, + TXN_BEGIN_GETGXID_MULTI_RESULT, + TXN_PREPARE_RESULT, + TXN_START_PREPARED_RESULT, + TXN_COMMIT_PREPARED_RESULT, + TXN_COMMIT_RESULT, + TXN_COMMIT_MULTI_RESULT, + TXN_ROLLBACK_RESULT, + TXN_ROLLBACK_MULTI_RESULT, + TXN_GET_GID_DATA_RESULT, + TXN_GET_GXID_RESULT, + TXN_GET_NEXT_GXID_RESULT, + TXN_GET_NEXT_CSN_RESULT, + TXN_GET_TIMELINE_RESULT, + TXN_GET_GLOBAL_XMIN_RESULT, + TXN_WORKLOAD_INIT_RESULT, + TXN_WORKLOAD_RESERVE_MEM_RESULT, + TXN_WORKLOAD_RELEASE_MEM_RESULT, + WLM_RESOURCEPOOL_CREATE_RESULT, /*create resource pool on gtm*/ + WLM_RESOURCEPOOL_UPDATE_RESULT, /*update resource pool on gtm*/ + WLM_RESOURCEPOOL_DELETE_RESULT, /*delete resource pool on gtm*/ + WLM_RESOURCEPOOL_INIT_RESULT, /*initialize resource pool list on gtm*/ + + TXN_GXID_LIST_RESULT, + SNAPSHOT_GET_RESULT, + SNAPSHOT_GET_MULTI_RESULT, + SNAPSHOT_GXID_GET_RESULT, + SNAPSHOT_STATUS_GET_RESULT, + SEQUENCE_GET_NEXT_UUID_RESULT, + SEQUENCE_GET_UUID_RESULT, + SEQUENCE_INIT_RESULT, + SEQUENCE_GET_NEXT_RESULT, + SEQUENCE_GET_LAST_RESULT, + SEQUENCE_SET_VAL_RESULT, + SEQUENCE_RESET_RESULT, + SEQUENCE_CLOSE_RESULT, + SEQUENCE_RENAME_RESULT, + SEQUENCE_ALTER_RESULT, + SEQUENCE_LIST_RESULT, + TXN_GET_STATUS_RESULT, + TXN_GET_ALL_PREPARED_RESULT, + TXN_BEGIN_GETGXID_AUTOVACUUM_RESULT, + BARRIER_RESULT, + BEGIN_SWITCHOVER_RESULT, + END_SWITCHOVER_RESULT, + QUERY_GTM_STATUS_RESULT, + CHECK_STANDBY_ROLE_RESULT, + SYNC_FILE_RESUTL, + GTM_SETSYNCMODE_RESULT, + CHECK_SYNC_NEXT_GXID_RESULT, + GTM_HOTPATCH_RESULT, + SNAPSHOT_GET_RESULT_LITE, + GTM_LITE_STATUS_RESULT, + RESULT_TYPE_COUNT +} GTM_ResultType; + +/* + * Special message header for the messgaes exchanged between the GTM server and + * the proxy. + * + * ph_conid: connection identifier which is used to route + * the messages to the right backend. + */ +typedef struct GTM_ProxyMsgHeader { + GTMProxy_ConnID ph_conid; +} GTM_ProxyMsgHeader; + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_opt.h postgresql-hll-2.14/include/gtm/gtm_opt.h --- postgresql-hll-2.14_old/include/gtm/gtm_opt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_opt.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,368 @@ +/* -------------------------------------------------------------------- + * gtm_opt.h + * + * External declarations pertaining to gtm/main/gtm_opt.c, gtm/proxy/gtm_proxy_opt.c and + * gtm/common/gtm_opt_file.l + * + * Portions Copyright (c) 2011, Postgres-XC Development Group + * Portions Copyright (c) 2000-2011, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * Modified by Koichi Suzuki + * + * src/include/gtm/gtm_opt.h + * -------------------------------------------------------------------- + */ +#ifndef GTM_OPT_H +#define GTM_OPT_H + +/* + * Certain options can only be set at certain times. The rules are + * like this: + * + * INTERNAL options cannot be set by the user at all, but only through + * internal processes ("server_version" is an example). These are GUC + * variables only so they can be shown by SHOW, etc. + * + * POSTMASTER options can only be set when the postmaster starts, + * either from the configuration file or the command line. + * + * SIGHUP options can only be set at postmaster startup or by changing + * the configuration file and sending the HUP signal to the postmaster + * or a backend process. (Notice that the signal receipt will not be + * evaluated immediately. The postmaster and the backend check it at a + * certain point in their main loop. It's safer to wait than to read a + * file asynchronously.) + * + * BACKEND options can only be set at postmaster startup, from the + * configuration file, or by client request in the connection startup + * packet (e.g., from libpq's PGOPTIONS variable). Furthermore, an + * already-started backend will ignore changes to such an option in the + * configuration file. The idea is that these options are fixed for a + * given backend once it's started, but they can vary across backends. + * + * SUSET options can be set at postmaster startup, with the SIGHUP + * mechanism, or from SQL if you're a superuser. + * + * USERSET options can be set by anyone any time. + */ +typedef enum { + GTMC_DEFAULT, + GTMC_STARTUP, + GTMC_SIGHUP, + GTMC_USERSET +} GtmOptContext; + +/* + * The following type records the source of the current setting. A + * new setting can only take effect if the previous setting had the + * same or lower level. (E.g, changing the config file doesn't + * override the postmaster command line.) Tracking the source allows us + * to process sources in any convenient order without affecting results. + * Sources <= GTMC_S_OVERRIDE will set the default used by RESET, as well + * as the current value. Note that source == GTMC_S_OVERRIDE should be + * used when setting a GTMC_INTERNAL option. + * + * GTMC_S_INTERACTIVE isn't actually a source value, but is the + * dividing line between "interactive" and "non-interactive" sources for + * error reporting purposes. + * + * GTMC_S_TEST is used when testing values to be stored as per-database or + * per-user defaults ("doit" will always be false, so this never gets stored + * as the actual source of any value). This is an interactive case, but + * it needs its own source value because some assign hooks need to make + * different validity checks in this case. + * + * NB: see GtmOptSource_Names in gtm_opt.c and gtm_proxy_opt.c if you change this. + */ +typedef enum { + GTMC_S_DEFAULT, /* hard-wired default ("boot_val") */ + GTMC_S_DYNAMIC_DEFAULT, /* default computed during initialization */ + GTMC_S_ENV_VAR, + /* postmaster environment variable */ /* Not used in GTM */ + GTMC_S_FILE, /* gtm.conf or gtm_proxy.conf */ + GTMC_S_ARGV, /* postmaster command line */ + GTMC_S_DATABASE, + /* per-database setting */ /* Not used in GTM */ + GTMC_S_USER, + /* per-user setting */ /* Not used in GTM */ + GTMC_S_DATABASE_USER, + /* per-user-and-database setting */ /* Not used in GTM */ + GTMC_S_CLIENT, + /* from client connection request */ /* Not used in GTM */ + GTMC_S_OVERRIDE, + /* special case to forcibly set default */ /* Not used in GTM */ + GTMC_S_INTERACTIVE, + /* dividing line for error reporting */ /* Not used in GTM */ + GTMC_S_TEST, + /* test per-database or per-user setting */ /* Not used in GTM */ + GTMC_S_SESSION /* SET command */ /* Not used in GTM */ +} GtmOptSource; + +/* + * Parsing the configuration file will return a list of name-value pairs + * with source location info. + */ +typedef struct ConfigVariable { + char* name; + char* value; + char* filename; + int sourceline; + struct ConfigVariable* next; +} ConfigVariable; + +extern bool ParseConfigFile(const char *config_file, const char *calling_file, int depth, int elevel, + ConfigVariable **head_p, ConfigVariable **tail_p); +extern bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, + ConfigVariable **tail_p); +extern void FreeConfigVariables(ConfigVariable *list); + +/* + * The possible values of an enum variable are specified by an array of + * name-value pairs. The "hidden" flag means the value is accepted but + * won't be displayed when guc.c is asked for a list of acceptable values. + */ +struct config_enum_entry { + const char* name; + int val; + bool hidden; +}; + +/* + * Signatures for per-variable check/assign hook functions + */ +typedef bool (*GtmOptBoolCheckHook)(bool* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptIntCheckHook)(int* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptRealCheckHook)(double* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptStringCheckHook)(char** newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptEnumCheckHook)(int* newval, void** extra, GtmOptSource source); + +typedef void (*GtmOptBoolAssignHook)(bool newval, void* extra); +typedef void (*GtmOptIntAssignHook)(int newval, void* extra); +typedef void (*GtmOptRealAssignHook)(double newval, void* extra); +typedef void (*GtmOptStringAssignHook)(const char* newval, void* extra); +typedef void (*GtmOptEnumAssignHook)(int newval, void* extra); + +/* + * Miscellaneous + */ +/* + * GTM does not have SET command so it is not used in GTM. It's a dummy. + */ +typedef enum { + /* Types of set_config_option actions */ + GTMOPT_ACTION_SET, /* regular SET command */ + GTMOPT_ACTION_LOCAL, /* SET LOCAL command */ + GTMOPT_ACTION_SAVE /* function SET option */ +} GtmOptAction; + +#define GTMOPT_QUALIFIER_SEPARATOR '.' + +/* + * bit values in "flags" of a GUC variable + */ +#define GTMOPT_LIST_INPUT 0x0001 /* input can be list format */ +#define GTMOPT_LIST_QUOTE 0x0002 /* double-quote list elements */ +#define GTMOPT_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */ +#define GTMOPT_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */ +#define GTMOPT_REPORT 0x0010 /* auto-report changes to client */ +#define GTMOPT_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */ +#define GTMOPT_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */ +#define GTMOPT_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */ +#define GTMOPT_SUPERUSER_ONLY 0x0100 /* show only to superusers */ +#define GTMOPT_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */ + +#define GTMOPT_UNIT_KB 0x0400 /* value is in kilobytes */ +#define GTMOPT_UNIT_BLOCKS 0x0800 /* value is in blocks */ +#define GTMOPT_UNIT_XBLOCKS 0x0C00 /* value is in xlog blocks */ +#define GTMOPT_UNIT_MEMORY 0x0C00 /* mask for KB, BLOCKS, XBLOCKS */ + +#define GTMOPT_UNIT_MS 0x1000 /* value is in milliseconds */ +#define GTMOPT_UNIT_S 0x2000 /* value is in seconds */ +#define GTMOPT_UNIT_MIN 0x4000 /* value is in minutes */ +#define GTMOPT_UNIT_TIME 0x7000 /* mask for MS, S, MIN */ + +#define GTMOPT_NOT_WHILE_SEC_REST 0x8000 /* can't set if security restricted */ + +/* + * Functions exported by gtm_opt.c + */ +extern void SetConfigOption(const char* name, const char* value, GtmOptContext context, GtmOptSource source); + +extern void EmitWarningsOnPlaceholders(const char* className); + +extern const char* GetConfigOption(const char* name, bool restrict_superuser); +extern const char* GetConfigOptionResetString(const char* name); +extern void ProcessConfigFile(GtmOptContext context); +extern void InitializeGTMOptions(void); +extern bool SelectConfigFiles(const char* userDoption, const char* progname); +extern void ResetAllOptions(void); +extern int NewGTMNestLevel(void); +extern bool parse_int(const char *value, int *result, int flags, const char **hintmsg); +extern bool parse_real(const char *value, double *result); +extern bool set_config_option(const char *name, const char *value, GtmOptContext context, GtmOptSource source, + bool changeVal); + +extern char* GetConfigOptionByName(const char* name, const char** varname); +extern void GetConfigOptionByNum(int varnum, const char** values, bool* noshow); +extern int GetNumConfigOptions(void); +extern void ParseLongOption(const char* string, char** name, char** value); + +#ifndef PG_KRB_SRVTAB +#define PG_KRB_SRVTAB "" +#endif +#ifndef PG_KRB_SRVNAM +#define PG_KRB_SRVNAM "" +#endif + +/* upper limit for GUC variables measured in kilobytes of memory */ +/* note that various places assume the byte size fits in a "long" variable */ +#if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4 +#define MAX_KILOBYTES INT_MAX +#else +#define MAX_KILOBYTES (INT_MAX / 1024) +#endif + +#ifdef TRACE_SORT +extern THR_LOCAL bool trace_sort; +#endif +#ifdef TRACE_SYNCSCAN +extern bool trace_syncscan; +#endif +#ifdef DEBUG_BOUNDED_SORT +extern bool optimize_bounded_sort; +#endif + +/* + * Log_min_messages ENUM strings + */ +#define Server_Message_Level_Options() \ + static const struct config_enum_entry server_message_level_options[] = {{"debug", DEBUG2, true}, \ + {"debug5", DEBUG5, false}, \ + {"debug4", DEBUG4, false}, \ + {"debug3", DEBUG3, false}, \ + {"debug2", DEBUG2, false}, \ + {"debug1", DEBUG1, false}, \ + {"info", INFO, false}, \ + {"notice", NOTICE, false}, \ + {"warning", WARNING, false}, \ + {"error", ERROR, false}, \ + {"log", LOG, false}, \ + {"fatal", FATAL, false}, \ + {"panic", PANIC, false}, \ + {NULL, 0, false}} + +/* + * Server Startup Option ENUM strings + */ +#define Gtm_Startup_Mode_Options() \ + static const struct config_enum_entry gtm_startup_mode_options[] = { \ + {"act", GTM_ACT_MODE, false}, {"standby", GTM_STANDBY_MODE, false}, {NULL, 0, false}} + +/* + * Gtm Synchronous Option ENUM strings + */ +#define Gtm_Sync_Options() \ + static const struct config_enum_entry gtm_sync_options[] = {{"off", SYNC_GTM_OFF, false}, \ + {"on", SYNC_GTM_ON, false}, \ + {"auto", SYNC_GTM_AUTO, false}, \ + {"true", SYNC_GTM_ON, true}, \ + {"false", SYNC_GTM_OFF, true}, \ + {"yes", SYNC_GTM_ON, true}, \ + {"no", SYNC_GTM_OFF, true}, \ + {"1", SYNC_GTM_ON, true}, \ + {"0", SYNC_GTM_OFF, true}, \ + {NULL, 0, false}} + +/* + * Gtm Authentication Type ENUM strings + */ +#define Gtm_Authentication_Options() \ + static const struct config_enum_entry gtm_authentication_options[] = { \ + {"trust", GTM_AUTH_TRUST, false}, {"gss", GTM_AUTH_GSS, false}, {NULL, 0, false}} + +/* + * Displayable names for context types (enum GtmContext) + * + * Note: these strings are deliberately not localized. + */ +#define gtmOptContext_Names() \ + const char* const GtmOptContext_Names[] = {/* GTMC_STGARTUP */ "startup", /* GTMC_SIGHUP */ "sighup"} + +/* + * Displayable names for source types (enum GtmSource) + * + * Note: these strings are deliberately not localized. + */ +#define gtmOptSource_Names() \ + const char* const GtmOptSource_Names[] = {/* GTMC_S_DEFAULT */ "default", \ + /* GTMC_S_DYNAMIC_DEFAULT */ "default", \ + /* GTMC_S_ENV_VAR */ "environment variable", \ + /* GTMC_S_FILE */ "configuration file", \ + /* GTMC_S_ARGV */ "command line", \ + /* GTMC_S_DATABASE */ "database", \ + /* GTMC_S_USER */ "user", \ + /* GTMC_S_DATABASE_USER */ "database user", \ + /* GTMC_S_CLIENT */ "client", \ + /* GTMC_S_OVERRIDE */ "override", \ + /* GTMC_S_INTERACTIVE */ "interactive", \ + /* GTMC_S_TEST */ "test", \ + /* GTMC_S_SESSION */ "session"} + +/* + * Displayable names for GTM variable types (enum config_type) + * + * Note: these strings are deliberately not localized. + */ +#define Config_Type_Names() \ + const char *const config_type_names[] = { /* GTMC_BOOL */ "bool", /* GTMC_INT */ "integer", \ + /* GTMC_REAL */ "real", /* GTMC_STRING */ "string", \ + /* GTMC_ENUM */ "enum" } + +/* + * Option name defintion --- common to gtm.conf and gtm_proxy.conf + * + * This will be used both in *.conf and command line option override. + * Add local_host and local_port for ha to get connect to standby + */ + +#define GTM_OPTNAME_LOCAL_HOST "local_host" +#define GTM_OPTNAME_LOCAL_PORT "local_port" +#define GTM_OPTNAME_ACTIVE_HOST "active_host" +#define GTM_OPTNAME_ACTIVE_PORT "active_port" +#define GTM_OPTNAME_STANDBY_CONNECT_TIMEOUT "standby_connection_timeout" +#define GTM_OPTNAME_CONFIG_FILE "config_file" +#define GTM_OPTNAME_DATA_DIR "data_dir" +#define GTM_OPTNAME_CONNECT_RETRY_INTERVAL "gtm_connect_retry_interval" +#define GTM_OPTNAME_GTM_HOST "gtm_host" +#define GTM_OPTNAME_GTM_PORT "gtm_port" +#define GTM_OPTNAME_KEEPALIVES_IDLE "keepalives_idle" +#define GTM_OPTNAME_KEEPALIVES_INTERVAL "keepalives_interval" +#define GTM_OPTNAME_KEEPALIVES_COUNT "keepalives_count" +#define GTM_OPTNAME_LISTEN_ADDRESSES "listen_addresses" +#define GTM_OPTNAME_LOG_FILE "log_file" +#define GTM_OPTNAME_LOG_DIRECTORY "log_directory" +#define GTM_OPTNAME_LOG_MIN_MESSAGES "log_min_messages" +#define GTM_OPTNAME_NODENAME "nodename" +#define GTM_OPTNAME_PORT "port" +#define GTM_OPTNAME_SYNCHRONOUS_BACKUP "synchronous_backup" +#define GTM_OPTNAME_WORKER_THREADS "worker_threads" +#define GTM_OPTNAME_ALARM_COMPONENT "alarm_component" +#define GTM_OPTNAME_ALARM_REPORT_INTERVAL "alarm_report_interval" + +#define GTM_OPTNAME_ENABLE_ALARM "enable_alarm" +#define GTM_OPTNAME_ACCESS_CONTROL "enable_connect_control" +#define GTM_OPTNAME_ENABLE_THREADPOOL "gtm_enable_threadpool" + +#define GTM_OPTNAME_WRM_MAX_SERVER_MEMORY "wlm_max_mem" +#define GTM_OPTNAME_WRM_QUERY_MEMORY_LIMIT "query_memory_limit" +#define GTM_OPTNAME_MAX_TRANS "gtm_max_trans" +#define GTM_OPTNAME_THREAD_NUMBER "gtm_num_threads" + +#define GTM_OPTNAME_STANDBY_ONLY "standby_only" +#define GTM_OPTION "gtm_option" +#define GTM_RESTORE_DURATION "restore_duration" +#define GTM_CSN_SYNC_INTERVAL "csn_sync_interval" + +#define GTM_DISTRIBUTE_TEST_PARAM "distribute_test_param" + +#endif /* GTM_OPT_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_opt_tables.h postgresql-hll-2.14/include/gtm/gtm_opt_tables.h --- postgresql-hll-2.14_old/include/gtm/gtm_opt_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_opt_tables.h 2020-12-12 17:06:43.125346464 +0800 @@ -0,0 +1,190 @@ +/* ------------------------------------------------------------------------- + * + * gtm_opt_tables.h + * Declarations of tables used by GTM configuration file. + * + * Portions Copyright (c) 2011, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * src/include/gtm/gtm_opt_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_OPT_TABLES_H +#define GTM_OPT_TABLES_H + +#include "gtm/gtm_opt.h" + +/* + * GUC supports these types of variables: + */ +enum config_type { + GTMC_BOOL, + GTMC_INT, + GTMC_REAL, + GTMC_STRING, + GTMC_ENUM +}; + +union config_var_val { + bool boolval; + int intval; + double realval; + char* stringval; + int enumval; +}; + +/* + * The actual value of a GUC variable can include a malloc'd opaque struct + * "extra", which is created by its check_hook and used by its assign_hook. + */ +typedef struct config_var_value { + union config_var_val val; + void* extra; +} config_var_value; + +/* + * Stack entry for saving the state a variable had prior to an uncommitted + * transactional change. In GTM, only chance to update options is SIGINT. + */ +typedef enum { + /* This is almost GtmOptAction, but we need a fourth state for SET+LOCAL */ + GTMOPT_SAVE, /* entry caused by function SET option */ + GTMOPT_SET, /* entry caused by plain SET command */ + GTMOPT_LOCAL, /* entry caused by SET LOCAL command */ + GTMOPT_SET_LOCAL /* entry caused by SET then SET LOCAL */ +} GtmOptStackState; + +typedef struct guc_stack { + struct guc_stack* prev; /* previous stack item, if any */ + int nest_level; /* nesting depth at which we made entry */ + GtmOptStackState state; /* see enum above */ + GtmOptSource source; /* source of the prior value */ + config_var_value prior; /* previous value of variable */ + config_var_value masked; /* SET value in a GTMOPT_SET_LOCAL entry */ + /* masked value's source must be GTMC_S_SESSION, so no need to store it */ +} GtmOptStack; + +/* + * Generic fields applicable to all types of variables + * + * The short description should be less than 80 chars in length. Some + * applications may use the long description as well, and will append + * it to the short description. (separated by a newline or '. ') + * + * Note that sourcefile/sourceline are kept here, and not pushed into stacked + * values, although in principle they belong with some stacked value if the + * active value is session- or transaction-local. This is to avoid bloating + * stack entries. We know they are only relevant when source == GTMC_S_FILE. + */ +struct config_generic { + /* constant fields, must be set correctly in initial value: */ + const char* name; /* name of variable - MUST BE FIRST */ + GtmOptContext context; /* context required to set the variable */ + const char* short_desc; /* short desc. of this variable's purpose */ + const char* long_desc; /* long desc. of this variable's purpose */ + int flags; /* flag bits, see below */ + /* variable fields, initialized at runtime: */ + enum config_type vartype; /* type of variable (set only at startup) */ + int status; /* status bits, see below */ + GtmOptSource reset_source; /* source of the reset_value */ + GtmOptSource source; /* source of the current actual value */ + GtmOptStack* stack; /* stacked prior values */ + void* extra; /* "extra" pointer for current actual value */ + char* sourcefile; /* file current setting is from (NULL if not + * file) */ + int sourceline; /* line in source file */ +}; + +/* bit values in flags field are defined in guc.h */ + +/* bit values in status field */ +#define GTMOPT_IS_IN_FILE 0x0001 /* found it in config file */ +/* + * Caution: the GTMOPT_IS_IN_FILE bit is transient state for ProcessConfigFile. + * Do not assume that its value represents useful information elsewhere. + */ + +/* GUC records for specific variable types */ + +struct config_bool { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + bool* variable; + bool boot_val; + GtmOptBoolCheckHook check_hook; + GtmOptBoolAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + bool reset_val; + void* reset_extra; +}; + +struct config_int { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + int min; + int max; + GtmOptIntCheckHook check_hook; + GtmOptIntAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +struct config_real { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + double* variable; + double boot_val; + double min; + double max; + GtmOptRealCheckHook check_hook; + GtmOptRealAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + double reset_val; + void* reset_extra; +}; + +struct config_string { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + char** variable; + const char* boot_val; + GtmOptStringCheckHook check_hook; + GtmOptStringAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + char* reset_val; + void* reset_extra; +}; + +struct config_enum { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + const struct config_enum_entry* options; + GtmOptEnumCheckHook check_hook; + GtmOptEnumAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +/* constant tables corresponding to enums above and in guc.h */ +extern const char* const config_group_names[]; +extern const char* const config_type_names[]; +extern const char* const GtmOptContext_Names[]; +extern const char* const GtmOptSource_Names[]; + +/* get the current set of variables */ +extern struct config_generic** get_guc_variables(void); + +extern void build_guc_variables(void); + +/* search in enum options */ +extern const char* config_enum_lookup_by_value(struct config_enum* record, int val); +extern bool config_enum_lookup_by_name(struct config_enum* record, const char* value, int* retval); + +#endif /* GTM_OPT_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_proxy.h postgresql-hll-2.14/include/gtm/gtm_proxy.h --- postgresql-hll-2.14_old/include/gtm/gtm_proxy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_proxy.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,254 @@ +/* ------------------------------------------------------------------------- + * + * gtm_proxy.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_PROXY_H +#define _GTM_PROXY_H + +#include +#include + +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_conn.h" +#include "gtm/utils/elog.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_msg.h" +#include "gtm/utils/libpq-fe.h" + +extern char* GTMProxyLogFile; + +typedef enum GTMProxy_ThreadStatus { + GTM_PROXY_THREAD_STARTING, + GTM_PROXY_THREAD_RUNNING, + GTM_PROXY_THREAD_EXITING, + /* Must be the last */ + GTM_PROXY_THREAD_INVALID +} GTMProxy_ThreadStatus; + +typedef struct GTMProxy_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + struct GTMProxy_ThreadInfo* con_thrinfo; + bool con_authenticated; + bool con_disconnected; + GTMProxy_ConnID con_id; + + GTM_MessageType con_pending_msg; + GlobalTransactionId con_txid; + GTM_TransactionHandle con_handle; +} GTMProxy_ConnectionInfo; + +typedef struct GTMProxy_Connections { + uint32 gc_conn_count; + uint32 gc_array_size; + GTMProxy_ConnectionInfo* gc_connections; + GTM_RWLock gc_lock; +} GTMProxy_Connections; + +#define ERRORDATA_STACK_SIZE 20 +#define GTM_PROXY_MAX_CONNECTIONS 1024 + +typedef struct GTMProxy_ThreadInfo { + /* + * Thread specific information such as connection(s) served by it + */ + GTM_ThreadID thr_id; + uint32 thr_localid; + bool is_main_thread; + void* (*thr_startroutine)(void*); + + MemoryContext thr_thread_context; + MemoryContext thr_message_context; + MemoryContext thr_current_context; + MemoryContext thr_error_context; + MemoryContext thr_parent_context; + + sigjmp_buf* thr_sigjmp_buf; + + ErrorData thr_error_data[ERRORDATA_STACK_SIZE]; + int thr_error_stack_depth; + int thr_error_recursion_depth; + int thr_criticalsec_count; + + GTMProxy_ThreadStatus thr_status; + GTMProxy_ConnectionInfo* thr_conn; /* Current set of connections from clients */ + uint32 thr_conn_count; /* number of connections served by this thread */ + + /* + * The structure member type/sequence upto this point must match the + * GTM_ThreadInfo structure in gtm.h since they are shared in some common + * library routines such as elog.c. Keeping them in sync helps us use the + * same library for the proxy as well as the server. + */ + GTM_MutexLock thr_lock; + GTM_CV thr_cv; + + /* + * We use a sequence number to track the state of connection/fd array. + * Whenever a new connection is added or an existing connection is deleted + * from the connection array, the sequence number is incremented. The + * thread main routine can then reconstruct the fd array again. + */ + int32 thr_seqno; + + /* connection array */ + GTMProxy_ConnectionInfo* thr_all_conns[GTM_PROXY_MAX_CONNECTIONS]; + struct pollfd thr_poll_fds[GTM_PROXY_MAX_CONNECTIONS]; + + /* Command backup */ + short thr_any_backup[GTM_PROXY_MAX_CONNECTIONS]; + int thr_qtype[GTM_PROXY_MAX_CONNECTIONS]; + StringInfoData thr_inBufData[GTM_PROXY_MAX_CONNECTIONS]; + + gtm_List* thr_processed_commands; + gtm_List* thr_pending_commands[MSG_TYPE_COUNT]; + + GTM_Conn* thr_gtm_conn; /* Connection to GTM */ + + /* Reconnect Info */ + int can_accept_SIGUSR2; + int reconnect_issued; + int can_longjmp; + sigjmp_buf longjmp_env; + +} GTMProxy_ThreadInfo; + +typedef struct GTMProxy_Threads { + uint32 gt_thread_count; + uint32 gt_array_size; + uint32 gt_next_worker; + GTMProxy_ThreadInfo** gt_threads; + GTM_RWLock gt_lock; +} GTMProxy_Threads; + +extern GTMProxy_Threads* GTMProxyThreads; + +int GTMProxy_ThreadAdd(GTMProxy_ThreadInfo* thrinfo); +int GTMProxy_ThreadRemove(GTMProxy_ThreadInfo* thrinfo); +int GTMProxy_ThreadJoin(GTMProxy_ThreadInfo* thrinfo); +void GTMProxy_ThreadExit(void); + +extern GTMProxy_ThreadInfo* GTMProxy_ThreadCreate(void* (*startroutine)(void*), int idx); +extern GTMProxy_ThreadInfo* GTMProxy_GetThreadInfo(GTM_ThreadID thrid); +extern GTMProxy_ThreadInfo* GTMProxy_ThreadAddConnection(GTMProxy_ConnectionInfo* conninfo); +extern int GTMProxy_ThreadRemoveConnection(GTMProxy_ThreadInfo* thrinfo, GTMProxy_ConnectionInfo* conninfo); + +/* + * Command data - the only relevant information right now is the XID + * and data necessary for registering (modification of Proxy number registered) + */ +typedef union GTMProxy_CommandData { + struct { + bool rdonly; + GTM_IsolationLevel iso_level; + } cd_beg; + + struct { + bool isgxid; + GlobalTransactionId gxid; + GTM_TransactionHandle handle; + } cd_rc; + + struct { + bool isgxid; + GlobalTransactionId gxid; + GTM_TransactionHandle handle; + } cd_snap; + + struct { + GTM_PGXCNodeType type; + char* nodename; + GTM_PGXCNodePort port; + char* gtm_proxy_nodename; + char* datafolder; + char* ipaddress; + uint32 timeline; + GTM_PGXCNodeStatus status; + } cd_reg; +} GTMProxy_CommandData; + +/* + * Structures to be used for message proxing. There will be one such entry for + * each pending command from a backend. To keep it simple, we have a separate + * entry even if the commands are grouped together. + * + * An array of these entries is maintained which is sorted by the order in + * which the commands are sent to the GTM server. We expect the GTM server to + * respond back in the same order and the sorted array helps us in + * matching/confirming the responses. + */ +typedef struct GTMProxy_CommandInfo { + GTM_MessageType ci_mtype; + int ci_res_index; + GTMProxy_CommandData ci_data; + GTMProxy_ConnectionInfo* ci_conn; +} GTMProxy_CommandInfo; + +/* + * pthread keys to get thread specific information + */ +extern pthread_key_t threadinfo_key; +extern MemoryContext TopMostMemoryContext; +extern char* GTMLogFileName; +extern char* Log_directory; +extern GTM_RWLock gtmlogFileLock; +extern GTM_ThreadID TopMostThreadID; + +#define SetMyThreadInfo(thrinfo) pthread_setspecific(threadinfo_key, (thrinfo)) +#define GetMyThreadInfo ((GTMProxy_ThreadInfo*)pthread_getspecific(threadinfo_key)) + +#define TopMemoryContext (GetMyThreadInfo->thr_thread_context) +#define ThreadTopContext (GetMyThreadInfo->thr_thread_context) +#define MessageContext (GetMyThreadInfo->thr_message_context) +#define CurrentMemoryContext (GetMyThreadInfo->thr_current_context) +#define ErrorContext (GetMyThreadInfo->thr_error_context) +#define errordata (GetMyThreadInfo->thr_error_data) +#define recursion_depth (GetMyThreadInfo->thr_error_recursion_depth) +#define errordata_stack_depth (GetMyThreadInfo->thr_error_stack_depth) +#define CritSectionCount (GetMyThreadInfo->thr_criticalsec_count) + +#define PG_exception_stack (GetMyThreadInfo->thr_sigjmp_buf) +#define MyConnection (GetMyThreadInfo->thr_conn) +#define MyPort ((GetMyThreadInfo->thr_conn != NULL) ? GetMyThreadInfo->thr_conn->con_port : NULL) +#define MyThreadID (GetMyThreadInfo->thr_id) + +#define START_CRIT_SECTION() (t_thrd.int_cxt.CritSectionCount++) + +#define END_CRIT_SECTION() do { \ + Assert(t_thrd.int_cxt.CritSectionCount > 0); \ + t_thrd.int_cxt.CritSectionCount--; \ +} while (0) + +/* Signal Handler controller */ +#define SIGUSR2DETECTED() (GetMyThreadInfo->reconnect_issued == TRUE) +#define RECONNECT_LONGJMP() do { \ + longjmp(GetMyThreadInfo->longjmp_env, 1); \ +} while (0) +#if 1 +#define Disable_Longjmp() do { \ + GetMyThreadInfo->can_longjmp = FALSE; \ +} while (0) +#define Enable_Longjmp() do { \ + if (SIGUSR2DETECTED()) { \ + RECONNECT_LONGJMP(); \ + } else { \ + GetMyThreadInfo->can_longjmp = TRUE; \ + } \ +} while (0) +#else +#define Disable_Longjmp() +#define Enable_Longjmp() +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_semaphore.h postgresql-hll-2.14/include/gtm/gtm_semaphore.h --- postgresql-hll-2.14_old/include/gtm/gtm_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_semaphore.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,126 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_semaphore.h + * Wrapper semaphore for the sysv sema. Currently the database only use the + * sysv sema. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _GTM_SEMA_H +#define _GTM_SEMA_H + +#include +#include + +typedef struct PGSemaphoreData { + int semId; /* semaphore set identifier */ + int semNum; /* semaphore number within set */ +} PGSemaphoreData; + +typedef PGSemaphoreData* PGSemaphore; + +/* key_t is the int type */ +typedef key_t IpcSemaphoreKey; /* semaphore key passed to semget */ +typedef int IpcSemaphoreId; /* semaphore ID returned by semget */ + +#define GTM_MAX_SEMASET (GTM_MAX_GLOBAL_TRANSACTIONS * 2) + +/* + * it is used to assign sema key. if the is_used[index] is true, + * it means that the index key is used. + */ +typedef struct GlobalSemaKeySet { + bool is_used[GTM_MAX_SEMASET]; + int current_key; /* current used sema key, default value is invalid. */ +} GlobalSemaKeySet; + +/* + * the number of sema sets. when create one sema set, + * must set the sema number. the valid sema number is SEMA_SET_NUM. + * when we create the sema set, we assign the sema num is SEMA_SET_NUM + 1, + * it stat from 0. the SEMA_SET_NUM sema is setted to PGSemaMagic, PGSemaMagic + * represents the sema set is create by GTM Thread. + */ +#define SEMA_SET_NUM 1 + +/** + * @Description: init glocal sema key. set current sema key is invalid. + * and init the lock. Only the main thread can call this function. + * destory the lock also is called by main thread only. + * @return none. + */ +void init_global_sema_key(); + +/** + * @Description: destroy sema_key lock + * @return none. + */ +void destory_sema_key_lock(); + +/** + * @Description: get the global seme key for creating the sema. + * If could not get the sema key. report the error. + * @return return the sema key. + */ +int get_next_sema_key(); + +/** + * @Description: the thread will exit, we must reset the global sema in + * order to be used by other new thread. + * @in seme_key, the given key to be reset. + * @return none. + */ +void reset_sema_key(int sema_key); + +/** + * @Description: create sema and init the sema by the given value. + * we store the sema id in seme->semId. seme->semNum keeps the index of this + * sema set array. + * @in key, the given key for sema. + * @in value, the given initial value. + * @return none + */ +void create_sema(PGSemaphore sema, IpcSemaphoreKey& key, int value); + +/** + * @Description: Lock a semaphore (decrement count), blocking if + * count would be < 0. + * @return none. + */ +void sema_lock(PGSemaphore sema); + +/** + * @Description: Unlock a semaphore (increment count) + * @return none. + */ +void sema_unlock(PGSemaphore sema); + +/** + * @Description: release the sema when current thread exit. + * @in sema, it keeps the sema id info. + * do the following things: + * 1. release the sema from the system kenel. + * 2. release the sema memory. + * 3. set the is_used of GlobalSemaKeySet to false. + * @return none + */ +void release_sema(PGSemaphore sema); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_seq.h postgresql-hll-2.14/include/gtm/gtm_seq.h --- postgresql-hll-2.14_old/include/gtm/gtm_seq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_seq.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,167 @@ +/* ------------------------------------------------------------------------- + * + * gtm_seq.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_SEQ_H +#define GTM_SEQ_H + +#include "gtm/utils/stringinfo.h" +#include "gtm/gtm_lock.h" +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_msg.h" + +typedef volatile int32 pg_atomic_int32; +typedef volatile uint32 pg_atomic_uint32; + +/* Global sequence related structures */ +typedef struct GTM_SeqUUID { + GTM_UUID uuid_nextId; + GTM_UUID uuid_backUpId; + GTM_RWLock uuid_seqLock; +} GTM_SeqUUID; + +extern GTM_SeqUUID GTMSeqUUID; + +typedef struct GTM_SeqInfo { + GTM_SequenceKey gs_key; + GTM_UUID gs_seqId; + GTM_Sequence gs_value; + GTM_Sequence gs_backedUpValue; + GTM_Sequence gs_init_value; + GTM_Sequence gs_last_value; + GTM_Sequence gs_increment_by; + GTM_Sequence gs_min_value; + GTM_Sequence gs_max_value; + GTM_Sequence gs_range; /* cache in client */ + + /* + * the blocked list for the same sequence, wait until gs_backedUpValue is synced + * to standby/etcd successfully. + * thread index will be remmebered, see also GTM_ThreadInfo::next_blocked_thread. + */ + pg_atomic_uint32 gs_blocked_head; + + pg_atomic_int32 gs_ref_count; + int32 gs_state; + GTM_RWLock gs_lock; + GTM_DBName gs_database; + + /* true if need to backup. reset false after backup finish. */ + bool gs_need_backup; + bool gs_called_after_startup; + bool gs_cycle; + bool gs_called; +} GTM_SeqInfo; + +typedef struct { + GTM_UUID seq_uuid; + GTM_Sequence increment; + GTM_Sequence minval; + GTM_Sequence maxval; + GTM_Sequence startval; + GTM_Sequence lastval; + GTM_Sequence range; + bool cycle; + bool is_standby; + bool is_restart; +} GTM_SeqMsgData; + +typedef struct GTM_ThreadSeqInfo { + GTM_SeqInfo* seqinfo; + GTM_Sequence range; + GTM_Sequence* rangemax; + bool backup; + GTM_Sequence seq_value; +} GTM_ThreadSeqInfo; + +#define SEQ_STATE_ACTIVE 1 +#define SEQ_STATE_DELETED 2 + +#define SEQ_IS_ASCENDING(s) ((s)->gs_increment_by > 0) +#define SEQ_IS_CYCLE(s) ((s)->gs_cycle) +#define SEQ_IS_CALLED(s) ((s)->gs_called) + +#define SEQ_DEF_MAX_SEQVAL_ASCEND 0x7ffffffffffffffeLL +#define SEQ_DEF_MIN_SEQVAL_ASCEND 0x1 + +#define SEQ_DEF_MAX_SEQVAL_DESCEND -0x1 +#define SEQ_DEF_MIN_SEQVAL_DESCEND -0x7ffffffffffffffeLL + +#define MaxGlobalUUId ((GTM_UUID)0x7fffffffffffffffLL) + +#define SEQ_MAX_REFCOUNT 1024 + +/* SEQUENCE Management */ +void GTM_InitSeqManager(void); +int GTM_SeqOpen(GTM_UUID seq_uuid, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, bool is_backup); +int GTM_SeqAlter(GTM_SeqMsgData* msg); +int GTM_SeqClose(GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int GTM_SeqDBRename(GTM_DBName dbName, GTM_DBName newdbName); +GTM_Sequence GTM_SeqGetNext(GTM_SeqMsgData* msg, GTM_Sequence* rangemax); +int GTM_SeqSetVal(GTM_UUID seq_uuid, GTM_Sequence nextval, GTM_Sequence range, bool iscalled); +int GTM_SeqReset(GTM_UUID seq_uuid); +void GTM_SyncSequence(GTM_MessageType mtype, GTM_UUID seq_uuid, GTM_SeqInfo *thisSeq, GTM_DBName dbName = NULL, + GTM_DBName newdbName = NULL); +bool GTM_SyncSequenceToStandby(GTM_MessageType mtype, GTM_UUID seq_uuid, GTM_SeqInfo *thisSeq, GTM_DBName dbName, + GTM_DBName newdbName = NULL); + +void GTM_SyncUUID(GTM_UUID seq_uuid); +void GTM_GetSyncUUIDFromEtcd(); +bool GTM_GetUUIDFromEtcd(GTM_UUID& seq_uuid, bool force); +bool GTM_SyncUUIDToStandby(GTM_UUID seq_uuid); + +void ProcessSequenceGetUUIDCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceInitCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceGetNextCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceSetValCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceResetCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceCloseCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceDBRenameCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceAlterCommand(Port* myport, StringInfo message, bool is_backup); + +void ProcessSequenceListCommand(Port* myport, StringInfo message); +void ProcessBkupGTMSequenceFileUUIDCommand(Port* myport, StringInfo message); +void ProcessGetNextSeqUUIDTransactionCommand(Port* myport, StringInfo message); + +void GTM_SaveSeqInfo(FILE* ctlf); +void GTM_RestoreSeqUUIDInfo(FILE* ctlf); +int GTM_SeqRestore(GTM_SequenceKey seqkey, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence curval, int32 state, bool cycle, bool called); +int GTM_SeqUUIDRestore(GTM_UUID seq_uuid, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence curval, GTM_Sequence range, int32 state, bool cycle, + bool called, GTM_DBName seq_dbName); + +void GTM_RestoreUUIDInfo(FILE* seqf, GTM_UUID seq_uuid); +void SetNextGlobalUUID(GTM_UUID seq_uuid); +bool GlobalUUIDIsValid(GTM_UUID seq_uuid); +bool GTM_NeedUUIDRestoreUpdate(void); + +bool GTM_NeedSeqRestoreUpdate(GTM_UUID seq_uuid); +void GTM_WriteRestorePointSeq(FILE* ctlf, GTM_UUID* seqId, bool all_seq_restore); + +void RemoveGTMSeqs(void); + +void GTM_WriteRestorePointUUID(FILE* file, bool uuid_restore); + +void GTM_SaveUUIDInfo(FILE* file); +GTM_UUID ReadNewGlobalUUId(); + +bool GTM_SetSeqToEtcd(GTM_MessageType mtype, GTM_SeqInfo* thisSeq, bool isBackup, GTM_UUID seq_uuid); +extern void release_group_seq_lock(); +void handleGetSeqException(); + +bool GTM_SetUUIDToEtcd(GTM_UUID seq_uuid, bool save); +bool GTMSyncUUIDToEtcdInternal(GTM_UUID seq_uuid, bool force); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_serialize_debug.h postgresql-hll-2.14/include/gtm/gtm_serialize_debug.h --- postgresql-hll-2.14_old/include/gtm/gtm_serialize_debug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_serialize_debug.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * gtm_serialize_debug.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_serialize_debug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_SERIALIZE_DEBUG_H +#define GTM_SERIALIZE_DEBUG_H + +#include + +#include "gtm/gtm_txn.h" + +void dump_transactions_elog(GTM_Transactions*, int); +void dump_transactioninfo_elog(GTM_TransactionInfo*); + +#endif /* GTM_SERIALIZE_DEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_serialize.h postgresql-hll-2.14/include/gtm/gtm_serialize.h --- postgresql-hll-2.14_old/include/gtm/gtm_serialize.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_serialize.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * gtm_serialize.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_serialize.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_SERIALIZE_H +#define GTM_SERIALIZE_H + +#include + +#include "gtm/gtm_c.h" +#include "gtm/gtm_txn.h" +#include "gtm/utils/register.h" +#include "gtm/gtm_seq.h" + +size_t gtm_get_snapshotdata_size(GTM_SnapshotData*); +size_t gtm_serialize_snapshotdata(GTM_SnapshotData*, char*, size_t); +size_t gtm_deserialize_snapshotdata(GTM_SnapshotData*, const char*, size_t); + +size_t gtm_get_transactioninfo_size(GTM_TransactionInfo*); +size_t gtm_serialize_transactioninfo(GTM_TransactionInfo*, char*, size_t); +size_t gtm_deserialize_transactioninfo(GTM_TransactionInfo*, const char*, size_t); + +size_t gtm_get_transactions_size(GTM_Transactions*); +size_t gtm_serialize_transactions(GTM_Transactions*, char*, size_t); +size_t gtm_deserialize_transactions(GTM_Transactions*, const char*, size_t); + +size_t gtm_get_pgxcnodeinfo_size(GTM_PGXCNodeInfo*); +size_t gtm_serialize_pgxcnodeinfo(GTM_PGXCNodeInfo*, char*, size_t); +size_t gtm_deserialize_pgxcnodeinfo(GTM_PGXCNodeInfo*, const char*, size_t); + +size_t gtm_get_sequence_size(GTM_SeqInfo*); +size_t gtm_serialize_sequence(GTM_SeqInfo*, char*, size_t); +size_t gtm_deserialize_sequence(GTM_SeqInfo* seq, const char*, size_t); + +void dump_transactions_elog(GTM_Transactions*, int); +void dump_transactioninfo_elog(GTM_TransactionInfo*); + +#endif /* GTM_SERIALIZE_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_slock.h postgresql-hll-2.14/include/gtm/gtm_slock.h --- postgresql-hll-2.14_old/include/gtm/gtm_slock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_slock.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,1108 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_slock.h + * Hardware-dependent implementation of spinlocks. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_slock.h + * + * NOTE: none of the macros in this file are intended to be called directly. + * Call them through the hardware-independent macros in spin.h. + * + * The following hardware-dependent macros must be provided for each + * supported platform: + * + * void S_INIT_LOCK(slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void S_LOCK(slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void S_UNLOCK(slock_t *lock) + * Unlock a previously acquired lock. + * + * bool S_LOCK_FREE(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * void SPIN_DELAY(void) + * Delay operation to occur inside spinlock wait loop. + * + * Note to implementors: there are default implementations for all these + * macros at the bottom of the file. Check if your platform can use + * these or needs to override them. + * + * Usually, S_LOCK() is implemented in terms of even lower-level macros + * TAS() and TAS_SPIN(): + * + * int TAS(slock_t *lock) + * Atomic test-and-set instruction. Attempt to acquire the lock, + * but do *not* wait. Returns 0 if successful, nonzero if unable + * to acquire the lock. + * + * int TAS_SPIN(slock_t *lock) + * Like TAS(), but this version is used when waiting for a lock + * previously found to be contended. By default, this is the + * same as TAS(), but on some architectures it's better to poll a + * contended lock using an unlocked instruction and retry the + * atomic test-and-set only when it appears free. + * + * TAS() and TAS_SPIN() are NOT part of the API, and should never be called + * directly. + * + * CAUTION: on some platforms TAS() and/or TAS_SPIN() may sometimes report + * failure to acquire a lock even when the lock is not locked. For example, + * on Alpha TAS() will "fail" if interrupted. Therefore a retry loop must + * always be used, even if you are certain the lock is free. + * + * It is the responsibility of these macros to make sure that the compiler + * does not re-order accesses to shared memory to precede the actual lock + * acquisition, or follow the lock release. Prior to PostgreSQL 9.5, this + * was the caller's responsibility, which meant that callers had to use + * volatile-qualified pointers to refer to both the spinlock itself and the + * shared data being accessed within the spinlocked critical section. This + * was notationally awkward, easy to forget (and thus error-prone), and + * prevented some useful compiler optimizations. For these reasons, we + * now require that the macros themselves prevent compiler re-ordering, + * so that the caller doesn't need to take special precautions. + * + * On platforms with weak memory ordering, the TAS(), TAS_SPIN(), and + * S_UNLOCK() macros must further include hardware-level memory fence + * instructions to prevent similar re-ordering at the hardware level. + * TAS() and TAS_SPIN() must guarantee that loads and stores issued after + * the macro are not executed until the lock has been obtained. Conversely, + * S_UNLOCK() must guarantee that loads and stores issued before the macro + * have been executed before the lock is released. + * + * On most supported platforms, TAS() uses a tas() function written + * in assembly language to execute a hardware atomic-test-and-set + * instruction. Equivalent OS-supplied mutex routines could be used too. + * + * If no system-specific TAS() is available (ie, HAVE_SPINLOCKS is not + * defined), then we fall back on an emulation that uses SysV semaphores + * (see spin.c). This emulation will be MUCH MUCH slower than a proper TAS() + * implementation, because of the cost of a kernel call per lock or unlock. + * An old report is that Postgres spends around 40% of its time in semop(2) + * when using the SysV semaphore code. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef S_LOCK_H +#define S_LOCK_H + +#include "gtm/gtm_semaphore.h" + +#ifndef ENABLE_THREAD_CHECK +#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +/************************************************************************* + * All the gcc inlines + * Gcc consistently defines the CPU as __cpu__. + * Other compilers use __cpu or __cpu__ so we test for both in those cases. + */ + +/*---------- + * Standard gcc asm format (assuming "volatile slock_t *lock"): + + __asm__ __volatile__( + " instruction \n" + " instruction \n" + " instruction \n" +: "=r"(_res), "+m"(*lock) // return register, in/out lock value +: "r"(lock) // lock pointer, in input register +: "memory", "cc"); // show clobbered registers here + + * The output-operands list (after first colon) should always include + * "+m"(*lock), whether or not the asm code actually refers to this + * operand directly. This ensures that gcc believes the value in the + * lock variable is used and set by the asm code. Also, the clobbers + * list (after third colon) should always include "memory"; this prevents + * gcc from thinking it can cache the values of shared-memory fields + * across the asm code. Add "cc" if your asm code changes the condition + * code register, and also list any temp registers the code uses. + *---------- + */ + +#ifdef __i386__ /* 32-bit i386 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * Use a non-locking test before asserting the bus lock. Note that the + * extra test appears to be a small loss on some x86 platforms and a small + * win on others; it's by no means clear that we should keep it. + */ + __asm__ __volatile__(" cmpb $0,%1 \n" + " jne 1f \n" + " lock \n" + " xchgb %0,%1 \n" + "1: \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * This sequence is equivalent to the PAUSE instruction ("rep" is + * ignored by old IA32 processors if the following instruction is + * not a string operation); the IA-32 Architecture Software + * Developer's Manual, Vol. 3, Section 7.7.2 describes why using + * PAUSE in the inner loop of a spin lock is necessary for good + * performance: + * + * The PAUSE instruction improves the performance of IA-32 + * processors supporting Hyper-Threading Technology when + * executing spin-wait loops and other routines where one + * thread is accessing a shared lock or semaphore in a tight + * polling loop. When executing a spin-wait loop, the + * processor can suffer a severe performance penalty when + * exiting the loop because it detects a possible memory order + * violation and flushes the core processor's pipeline. The + * PAUSE instruction provides a hint to the processor that the + * code sequence is a spin-wait loop. The processor uses this + * hint to avoid the memory order violation and prevent the + * pipeline flush. In addition, the PAUSE instruction + * de-pipelines the spin-wait loop to prevent it from + * consuming execution resources excessively. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __i386__ */ + +#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * On Opteron, using a non-locking test before the locking instruction + * is a huge loss. On EM64T, it appears to be a wash or small loss, + * so we needn't bother to try to distinguish the sub-architectures. + */ + __asm__ __volatile__(" lock \n" + " xchgb %0,%1 \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * Adding a PAUSE in the spin delay loop is demonstrably a no-op on + * Opteron, but it may be of some use on EM64T, so we keep it. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __x86_64__ */ + +#if defined(__ia64__) || defined(__ia64) +/* + * Intel Itanium, gcc or Intel's compiler. + * + * Itanium has weak memory ordering, but we rely on the compiler to enforce + * strict ordering of accesses to volatile data. In particular, while the + * xchg instruction implicitly acts as a memory barrier with 'acquire' + * semantics, we do not have an explicit memory fence instruction in the + * S_UNLOCK macro. We use a regular assignment to clear the spinlock, and + * trust that the compiler marks the generated store instruction with the + * ".rel" opcode. + * + * Testing shows that assumption to hold on gcc, although I could not find + * any explicit statement on that in the gcc manual. In Intel's compiler, + * the -m[no-]serialize-volatile option controls that, and testing shows that + * it is enabled by default. + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +#ifndef __INTEL_COMPILER + +static __inline__ int tas(volatile slock_t* lock) +{ + long int ret; + + __asm__ __volatile__(" xchg4 %0=%1,%2 \n" : "=r"(ret), "+m"(*lock) : "r"(1) : "memory"); + return (int)ret; +} + +#else /* __INTEL_COMPILER */ + +static __inline__ int tas(volatile slock_t* lock) +{ + int ret; + + ret = _InterlockedExchange(lock, 1); /* this is a xchg asm macro */ + + return ret; +} + +#endif /* __INTEL_COMPILER */ +#endif /* __ia64__ || __ia64 */ + +/* + * On ARM64, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ + +#if defined(__aarch64__) || defined(__aarch64) + +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int + + tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile register slock_t* ulAddr = lock; + register slock_t _res = 1; + unsigned int tmp = 0; + + __asm__ volatile("// __xchg4\n" + "1: ldaxr %w0, %2\n" + " stlxr %w1, %w3, %2\n" + " cbnz %w1, 1b\n" + : "=&r"(_res), "=&r"(tmp), "+Q"(*ulAddr) + : "r"(_res) + : "cc", "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __aarch64__ */ + +/* + * On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ +#if defined(__arm__) || defined(__arm) +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned char slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + __asm__ __volatile__(" swpb %0, %0, [%2] \n" : "+r"(_res), "+m"(*lock) : "r"(lock) : "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __arm__ */ + +/* S/390 and S/390x Linux (32- and 64-bit zSeries) */ +#if defined(__s390__) || defined(__s390x__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + int _res = 0; + + __asm__ __volatile__(" cs %0,%3,0(%2) \n" : "+d"(_res), "+m"(*lock) : "a"(lock), "d"(1) : "memory", "cc"); + return _res; +} + +#endif /* __s390__ || __s390x__ */ + +#if defined(__sparc__) /* Sparc */ +/* + * Solaris has always run sparc processors in TSO (total store) mode, but + * linux didn't use to and the *BSDs still don't. So, be careful about + * acquire/release semantics. The CPU will treat superflous membars as NOPs, + * so it's just code space. + */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + /* + * See comment in /pg/backend/port/tas/solaris_sparc.s for why this + * uses "ldstub", and that file uses "cas". gcc currently generates + * sparcv7-targeted binaries, so "cas" use isn't possible. + */ + __asm__ __volatile__(" ldstub [%2], %0 \n" : "=r"(_res), "+m"(*lock) : "r"(lock) : "memory"); +#if defined(__sparcv7) + /* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. + */ +#elif defined(__sparcv8) + /* stbar is available (and required for both PSO, RMO), membar isn't */ + __asm__ __volatile__("stbar \n" ::: "memory"); +#else + /* + * #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire + * barrier for sparcv8+ upwards. + */ + __asm__ __volatile__("membar #LoadStore | #LoadLoad \n" ::: "memory"); +#endif + return (int)_res; +} + +#if defined(__sparcv7) +/* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. We fall through to the default gcc definition of + * S_UNLOCK in this case. + */ +#elif defined(__sparcv8) +/* stbar is available (and required for both PSO, RMO), membar isn't */ +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("stbar \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#else +/* + * #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate + * release barrier for sparcv8+ upwards. + */ +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("membar #LoadStore | #StoreStore \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#endif + +#endif /* __sparc__ */ + +/* PowerPC */ +#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On PPC, it's a win to use a non-locking test before the lwarx */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +/* + * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002, + * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop. + * On newer machines, we can use lwsync instead for better performance. + */ +static __inline__ int tas(volatile slock_t* lock) +{ + slock_t _t; + int _res; + + __asm__ __volatile__( +#ifdef USE_PPC_LWARX_MUTEX_HINT + " lwarx %0,0,%3,1 \n" +#else + " lwarx %0,0,%3 \n" +#endif + " cmpwi %0,0 \n" + " bne 1f \n" + " addi %0,%0,1 \n" + " stwcx. %0,0,%3 \n" + " beq 2f \n" + "1: li %1,1 \n" + " b 3f \n" + "2: \n" +#ifdef USE_PPC_LWSYNC + " lwsync \n" +#else + " isync \n" +#endif + " li %1,0 \n" + "3: \n" + + : "=&r"(_t), "=r"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "cc"); + return _res; +} + +/* + * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction. + * On newer machines, we can use lwsync instead for better performance. + */ +#ifdef USE_PPC_LWSYNC +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" lwsync \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#else +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" sync \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#endif /* USE_PPC_LWSYNC */ + +#endif /* powerpc */ + +/* Linux Motorola 68k */ +#if (defined(__mc68000__) || defined(__m68k__)) && defined(__linux__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int rv; + + __asm__ __volatile__(" clrl %0 \n" + " tas %1 \n" + " sne %0 \n" + : "=d"(rv), "+m"(*lock) + : + : "memory", "cc"); + return rv; +} + +#endif /* (__mc68000__ || __m68k__) && __linux__ */ + +/* + * VAXen -- even multiprocessor ones + * (thanks to Tom Ivar Helbekkmo) + */ +#if defined(__vax__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" movl $1, %0 \n" + " bbssi $0, (%2), 1f \n" + " clrl %0 \n" + "1: \n" + : "=&r"(_res), "+m"(*lock) + : "r"(lock) + : "memory"); + return _res; +} + +#endif /* __vax__ */ + +#if defined(__ns32k__) /* National Semiconductor 32K */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" sbitb 0, %1 \n" + " sfsd %0 \n" + : "=r"(_res), "+m"(*lock) + : + : "memory"); + return _res; +} + +#endif /* __ns32k__ */ + +#if defined(__alpha) || defined(__alpha__) /* Alpha */ +/* + * Correct multi-processor locking methods are explained in section 5.5.3 + * of the Alpha AXP Architecture Handbook, which at this writing can be + * found at ftp://ftp.netbsd.org/pub/NetBSD/misc/dec-docs/index.html. + * For gcc we implement the handbook's code directly with inline assembler. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + __asm__ __volatile__(" ldq $0, %1 \n" + " bne $0, 2f \n" + " ldq_l %0, %1 \n" + " bne %0, 2f \n" + " mov 1, $0 \n" + " stq_c $0, %1 \n" + " beq $0, 2f \n" + " mb \n" + " br 3f \n" + "2: mov 1, %0 \n" + "3: \n" + : "=&r"(_res), "+m"(*lock) + : + : "memory", "0"); + return (int)_res; +} + +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" mb \n"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) + +#endif /* __alpha || __alpha__ */ + +#if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ +/* Note: on SGI we use the OS' mutex ABI, see below */ +/* Note: R10000 processors require a separate SYNC */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register volatile slock_t* _l = lock; + register int _res; + register int _tmp; + + __asm__ __volatile__(" .set push \n" + " .set mips2 \n" + " .set noreorder \n" + " .set nomacro \n" + " ll %0, %2 \n" + " or %1, %0, 1 \n" + " sc %1, %2 \n" + " xori %1, 1 \n" + " or %0, %0, %1 \n" + " sync \n" + " .set pop " + : "=&r"(_res), "=&r"(_tmp), "+R"(*_l) + : + : "memory"); + return _res; +} + +/* MIPS S_UNLOCK is almost standard but requires a "sync" instruction */ +#define S_UNLOCK(lock) do { \ +__asm__ __volatile__( \ + " .set push \n" \ + " .set mips2 \n" \ + " .set noreorder \n" \ + " .set nomacro \n" \ + " sync \n" \ + " .set pop " +: +: "memory"); +*((volatile slock_t*)(lock)) = 0; +} +while (0) + +#endif /* __mips__ && !__sgi */ + +#if defined(__m32r__) && defined(HAVE_SYS_TAS_H) /* Renesas' M32R */ +#define HAS_TEST_AND_SET + +#include + + typedef int slock_t; + +#define TAS(lock) tas(lock) + +#endif /* __m32r__ */ + +#if defined(__sh__) /* Renesas' SuperH */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + /* + * This asm is coded as if %0 could be any register, but actually SuperH + * restricts the target of xor-immediate to be R0. That's handled by + * the "z" constraint on _res. + */ + __asm__ __volatile__(" tas.b @%2 \n" + " movt %0 \n" + " xor #1,%0 \n" + : "=z"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "t"); + return _res; +} + +#endif /* __sh__ */ + +/* These live in s_lock.c, but only for gcc */ + +#if defined(__m68k__) && !defined(__linux__) /* non-Linux Motorola 68k */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +/* + * Note that this implementation is unsafe for any platform that can speculate + * a memory access (either load or store) after a following store. That + * happens not to be possible x86 and most legacy architectures (some are + * single-processor!), but many modern systems have weaker memory ordering. + * Those that do must define their own version S_UNLOCK() rather than relying + * on this one. + */ +#if !defined(S_UNLOCK) +#if defined(__INTEL_COMPILER) +#define S_UNLOCK(lock) do { \ + __memory_barrier(); \ + *(lock) = 0; \ +} while (0) +#else +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("" : : : "memory"); \ + *(lock) = 0; \ +} while (0) +#endif +#endif + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +/* + * --------------------------------------------------------------------- + * Platforms that use non-gcc inline assembly: + * --------------------------------------------------------------------- + */ + +#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ + +#if defined(USE_UNIVEL_CC) /* Unixware compiler */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +asm int tas(volatile slock_t* s_lock) +{ + /* UNIVEL wants %mem in column 1, so we don't pg_indent this file */ + % mem s_lock pushl % ebx movl s_lock, % ebx movl $255, % eax lock xchgb % al, (% ebx) popl % ebx +} + +#endif /* defined(USE_UNIVEL_CC) */ + +#if defined(__alpha) || defined(__alpha__) /* Tru64 Unix Alpha compiler */ +/* + * The Tru64 compiler doesn't support gcc-style inline asm, but it does + * have some builtin functions that accomplish much the same results. + * For simplicity, slock_t is defined as long (ie, quadword) on Alpha + * regardless of the compiler in use. LOCK_LONG and UNLOCK_LONG only + * operate on an int (ie, longword), but that's OK as long as we define + * S_INIT_LOCK to zero out the whole quadword. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include +#define S_INIT_LOCK(lock) (*(lock) = 0) +#define TAS(lock) (__LOCK_LONG_RETRY((lock), 1) == 0) +#define S_UNLOCK(lock) __UNLOCK_LONG(lock) + +#endif /* __alpha || __alpha__ */ + +#if defined(__hppa) || defined(__hppa__) /* HP PA-RISC, GCC and HP compilers */ +/* + * HP's PA-RISC + * + * See src/backend/port/hpux/tas.c.template for details about LDCWX. Because + * LDCWX requires a 16-byte-aligned address, we declare slock_t as a 16-byte + * struct. The active word in the struct is whichever has the aligned address; + * the other three words just sit at -1. + * + * When using gcc, we can inline the required assembly code. + */ +#define HAS_TEST_AND_SET + +typedef struct { + int sema[4]; +} slock_t; + +#define TAS_ACTIVE_WORD(lock) ((volatile int*)(((uintptr_t)(lock) + 15) & ~15)) + +#if defined(__GNUC__) + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile int* lockword = TAS_ACTIVE_WORD(lock); + register int lockval; + + __asm__ __volatile__(" ldcwx 0(0,%2),%0 \n" : "=r"(lockval), "+m"(*lockword) : "r"(lockword) : "memory"); + return (lockval == 0); +} + +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("" : : : "memory"); \ + *TAS_ACTIVE_WORD(lock) = -1; \ +} while (0) + +#endif /* __GNUC__ */ + +#define S_INIT_LOCK(lock) do { \ + volatile slock_t *lock_ = (lock); \ + lock_->sema[0] = -1; \ + lock_->sema[1] = -1; \ + lock_->sema[2] = -1; \ + lock_->sema[3] = -1; \ +} while (0) + +#define S_LOCK_FREE(lock) (*TAS_ACTIVE_WORD(lock) != 0) + +#endif /* __hppa || __hppa__ */ + +#if defined(__hpux) && defined(__ia64) && !defined(__GNUC__) +/* + * HP-UX on Itanium, non-gcc compiler + * + * We assume that the compiler enforces strict ordering of loads/stores on + * volatile data (see comments on the gcc-version earlier in this file). + * Note that this assumption does *not* hold if you use the + * +Ovolatile=__unordered option on the HP-UX compiler, so don't do that. + * + * See also Implementing Spinlocks on the Intel Itanium Architecture and + * PA-RISC, by Tor Ekqvist and David Graves, for more information. As of + * this writing, version 1.0 of the manual is available at: + * http://h21007.www2.hp.com/portal/download/files/unprot/itanium/spinlocks.pdf + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#include +#define TAS(lock) _Asm_xchg(_SZ_W, lock, 1, _LDHINT_NONE) +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) +#define S_UNLOCK(lock) do { \ + _Asm_sched_fence(); (*(lock)) = 0); \ +} while (0) + +#endif /* HPUX on IA64, non gcc */ + +#if defined(__sgi) /* SGI compiler */ +/* + * SGI IRIX 5 + * slock_t is defined as a unsigned long. We use the standard SGI + * mutex API. + * + * The following comment is left for historical reasons, but is probably + * not a good idea since the mutex ABI is supported. + * + * This stuff may be supplemented in the future with Masato Kataoka's MIPS-II + * assembly from his NECEWS SVR4 port, but we probably ought to retain this + * for the R3000 chips out there. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include "mutex.h" +#define TAS(lock) (test_and_set(lock, 1)) +#define S_UNLOCK(lock) (test_then_and(lock, 0)) +#define S_INIT_LOCK(lock) (test_then_and(lock, 0)) +#define S_LOCK_FREE(lock) (test_then_add(lock, 0) == 0) +#endif /* __sgi */ + +#if defined(sinix) /* Sinix */ +/* + * SINIX / Reliant UNIX + * slock_t is defined as a struct abilock_t, which has a single unsigned long + * member. (Basically same as SGI) + */ +#define HAS_TEST_AND_SET + +#include "abi_mutex.h" +typedef abilock_t slock_t; + +#define TAS(lock) (!acquire_lock(lock)) +#define S_UNLOCK(lock) release_lock(lock) +#define S_INIT_LOCK(lock) init_lock(lock) +#define S_LOCK_FREE(lock) (stat_lock(lock) == UNLOCKED) +#endif /* sinix */ + +#if defined(_AIX) /* AIX */ +/* + * AIX (POWER) + */ +#define HAS_TEST_AND_SET + +#include + +typedef int slock_t; + +#define TAS(lock) _check_lock((slock_t*)(lock), 0, 1) +#define S_UNLOCK(lock) _clear_lock((slock_t*)(lock), 0) +#endif /* _AIX */ + +/* These are in s_lock.c */ + +#if defined(sun3) /* Sun3 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +#if defined(__SUNPRO_C) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) +#define HAS_TEST_AND_SET + +#if defined(__i386) || defined(__x86_64__) || defined(__sparcv9) || defined(__sparcv8plus) +typedef unsigned int slock_t; +#else +typedef unsigned char slock_t; +#endif + +extern slock_t pg_atomic_cas(volatile slock_t* lock, slock_t with, slock_t cmp); + +#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0) +#endif + +#ifdef WIN32_ONLY_COMPILER +typedef LONG slock_t; + +#define HAS_TEST_AND_SET +#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) + +#define SPIN_DELAY() spin_delay() + +/* If using Visual C++ on Win64, inline assembly is unavailable. + * Use a _mm_pause instrinsic instead of rep nop. + */ +#if defined(_WIN64) +static __forceinline void spin_delay(void) +{ + _mm_pause(); +} +#else +static __forceinline void spin_delay(void) +{ + /* See comment for gcc code. Same code, MASM syntax */ + __asm rep nop; +} +#endif + +#include +#pragma intrinsic(_ReadWriteBarrier) + +#define S_UNLOCK(lock) do { \ + _ReadWriteBarrier(); \ + (*(lock)) = 0; \ +} while (0) + +#endif + +#endif /* !defined(HAS_TEST_AND_SET) */ + +/* Blow up if we didn't have any way to do spinlocks */ +#ifndef HAS_TEST_AND_SET +#error PostgreSQL does not have native spinlock support on this platform. To continue the compilation, rerun configure using --disable-spinlocks. However, performance will be poor. Please report this to pgsql-bugs@postgresql.org. +#endif + +#else /* !HAVE_SPINLOCKS */ + +/* + * Fake spinlock implementation using semaphores --- slow and prone + * to fall foul of kernel limits on number of semaphores, so don't use this + * unless you must! The subroutines appear in spin.c. + */ +typedef PGSemaphoreData slock_t; + +extern bool s_lock_free_sema(volatile slock_t* lock); +extern void s_unlock_sema(volatile slock_t* lock); +extern void s_init_lock_sema(volatile slock_t* lock); +extern int tas_sema(volatile slock_t* lock); + +#define S_LOCK_FREE(lock) s_lock_free_sema(lock) +#define S_UNLOCK(lock) s_unlock_sema(lock) +#define S_INIT_LOCK(lock) s_init_lock_sema(lock) +#define TAS(lock) tas_sema(lock) + +#endif /* HAVE_SPINLOCKS */ + +/* + * Default Definitions - override these above as needed. + */ + +#if !defined(S_LOCK) +#define S_LOCK(lock) do { \ + if (TAS(lock)) \ + s_lock((lock), __FILE__, __LINE__); \ +} while (0) +#endif /* S_LOCK */ + +#if !defined(S_LOCK_FREE) +#define S_LOCK_FREE(lock) (*(lock) == 0) +#endif /* S_LOCK_FREE */ + +#if !defined(S_UNLOCK) +/* + * Our default implementation of S_UNLOCK is essentially *(lock) = 0. This + * is unsafe if the platform can speculate a memory access (either load or + * store) after a following store; platforms where this is possible must + * define their own S_UNLOCK. But CPU reordering is not the only concern: + * if we simply defined S_UNLOCK() as an inline macro, the compiler might + * reorder instructions from inside the critical section to occur after the + * lock release. Since the compiler probably can't know what the external + * function s_unlock is doing, putting the same logic there should be adequate. + * A sufficiently-smart globally optimizing compiler could break that + * assumption, though, and the cost of a function call for every spinlock + * release may hurt performance significantly, so we use this implementation + * only for platforms where we don't know of a suitable intrinsic. For the + * most part, those are relatively obscure platform/compiler combinations to + * which the PostgreSQL project does not have access. + */ +#define USE_DEFAULT_S_UNLOCK +extern void s_unlock(volatile slock_t* lock); +#define S_UNLOCK(lock) s_unlock(lock) +#endif /* S_UNLOCK */ + +#if !defined(S_INIT_LOCK) +#define S_INIT_LOCK(lock) S_UNLOCK(lock) +#endif /* S_INIT_LOCK */ + +#if !defined(SPIN_DELAY) +#define SPIN_DELAY() ((void)0) +#endif /* SPIN_DELAY */ + +#if !defined(TAS) +extern int tas(volatile slock_t* lock); /* in port/.../tas.s, or + * s_lock.c */ + +#define TAS(lock) tas(lock) +#endif /* TAS */ + +#if !defined(TAS_SPIN) +#define TAS_SPIN(lock) TAS(lock) +#endif /* TAS_SPIN */ + +#endif /* ENABLE_THREAD_CHECK */ + +#ifdef ENABLE_THREAD_CHECK + +#include +typedef pthread_mutex_t slock_t; +#define SPIN_DELAY() ((void)0) +#define TAS_SPIN(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_INIT_LOCK(lock) pthread_mutex_init((pthread_mutex_t*)lock, NULL) +#define S_LOCK(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_UNLOCK(lock) pthread_mutex_unlock((pthread_mutex_t*)lock) +#define S_LOCK_FREE(lock) pthread_mutex_destroy((pthread_mutex_t*)lock) + +#endif +/* + * Platform-independent out-of-line support routines + */ +extern int s_lock(volatile slock_t* lock, const char* file, int line); + +/* Support for dynamic adjustment of spins_per_delay */ +#define DEFAULT_SPINS_PER_DELAY 100 + +extern void set_spins_per_delay(int shared_spins_per_delay); +extern int update_spins_per_delay(int shared_spins_per_delay); + +/* + * Support for spin delay which is useful in various places where + * spinlock-like procedures take place. + */ +typedef struct { + int spins; + int delays; + int cur_delay; + void* ptr; + const char* file; + int line; +} SpinDelayStatus; + +#define init_spin_delay(ptr) \ + { \ + 0, 0, 0, (ptr), __FILE__, __LINE__ \ + } +void perform_spin_delay(SpinDelayStatus* status); +void finish_spin_delay(SpinDelayStatus* status); + +#endif /* S_LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_spinlock.h postgresql-hll-2.14/include/gtm/gtm_spinlock.h --- postgresql-hll-2.14_old/include/gtm/gtm_spinlock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_spinlock.h 2020-12-12 17:06:43.126346477 +0800 @@ -0,0 +1,73 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_spinlock.h + * Hardware-independent implementation of spinlocks. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_spinlock.h + * + * NOTE + * The hardware-independent interface to spinlocks is defined by the + * typedef "slock_t" and these macros: + * + * void SpinLockInit(volatile slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void SpinLockAcquire(volatile slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void SpinLockRelease(volatile slock_t *lock) + * Unlock a previously acquired lock. + * + * bool SpinLockFree(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * Callers must beware that the macro argument may be evaluated multiple + * times! + * + * CAUTION: Care must be taken to ensure that loads and stores of + * shared memory values are not rearranged around spinlock acquire + * and release. This is done using the "volatile" qualifier: the C + * standard states that loads and stores of volatile objects cannot + * be rearranged *with respect to other volatile objects*. The + * spinlock is always written through a volatile pointer by the + * spinlock macros, but this is not sufficient by itself: code that + * protects shared data with a spinlock MUST reference that shared + * data through a volatile pointer. + * + * Keep in mind the coding rule that spinlocks must not be held for more + * than a few instructions. In particular, we assume it is not possible + * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so + * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros. + * + * These macros are implemented in terms of hardware-dependent macros + * supplied by s_lock.h. There is not currently any extra functionality + * added by this header, but there has been in the past and may someday + * be again. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SPIN_H +#define SPIN_H + +#include "gtm/gtm_slock.h" + +#define SpinLockInit(lock) S_INIT_LOCK(lock) + +#define SpinLockAcquire(lock) S_LOCK(lock) + +#define SpinLockRelease(lock) S_UNLOCK(lock) + +#define SpinLockFree(lock) S_LOCK_FREE(lock) + +extern int SpinlockSemas(void); + +#endif /* SPIN_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_standby.h postgresql-hll-2.14/include/gtm/gtm_standby.h --- postgresql-hll-2.14_old/include/gtm/gtm_standby.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_standby.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,97 @@ +/* ------------------------------------------------------------------------- + * + * gtm_standby.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_standby.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_STANDBY_H +#define GTM_STANDBY_H + +#include "c.h" +#include "gtm/gtm_c.h" +#include "gtm/utils/libpq-fe.h" +#include "gtm/utils/register.h" +#include "alarm/alarm.h" + +/* + * Variables to interact with GTM active under GTM standby mode. + */ +bool gtm_is_standby(void); +void gtm_set_standby(bool standby); +void gtm_set_active_conninfo(const char* addr, int port); + +int gtm_standby_start_startup(void); +int gtm_standby_finish_startup(void); + +int gtm_standby_restore_next_gxid(void); +int gtm_standby_restore_timeline(void); +int gtm_standby_restore_next_sequuid(void); +int gtm_standby_restore_sequence(void); +int gtm_standby_restore_node(void); + +int gtm_standby_activate_self(void); + +GTM_Conn* gtm_standby_connect_to_standby(void); +void gtm_standby_disconnect_from_standby(GTM_Conn* conn); +GTM_Conn* gtm_standby_reconnect_to_standby(GTM_Conn* old_conn, int retry_max); +bool gtm_standby_check_communication_error(int* retry_count, GTM_Conn* oldconn); + +GTM_PGXCNodeInfo* find_standby_node_info(void); + +int gtm_standby_begin_backup(void); +int gtm_standby_end_backup(void); +void gtm_standby_closeActiveConn(void); +void gtm_standby_finishActiveConn(void); + +/* Functions to process backup */ +void ProcessGTMBeginBackup(Port* myport, StringInfo message); +void ProcessGTMEndBackup(Port* myport, StringInfo message); +int gtm_standby_begin_switchover(void); +int gtm_standby_end_switchover(void); +void ProcessGTMBeginSwitchover(Port* myport, StringInfo message, bool noblock); +void ProcessGTMEndSwitchover(Port* myport, StringInfo message, bool noblock); +void RemoveGTMXids(void); +GTMConnStatusType GetConnectionStatus(void); +bool SendBackupFileToStandby(void); +void WriteTempFile(const char* buf, char* temppath, int size); + +#define invalid_file -1 +#define register_node_file 0 +#define gtm_control_file 1 +#define gtm_sequence_file 2 + +extern AlarmCheckResult GTMStandbyNotAliveChecker(Alarm* alarm, char* buffer); +extern AlarmCheckResult GTMNotInSyncStatusChecker(Alarm* alarm, char* buffer); + +/* + * Startup mode + */ +#define GTM_ACT_MODE 0 +#define GTM_STANDBY_MODE 1 + +typedef enum CheckStandbyRoleResult { + SRR_Unknown = 0, + SRR_Success, + SRR_InetError, + SRR_NotAStandby, + SRR_ConfigureError, +} CheckStandbyRoleResult; + +void QuerySyncStatus(long* sendCount, long* receiveCount); +void PrimaryASyncStandby(void); +void AdvanceStandbyASyncCounter(void); +void PrimarySyncStandby(GTM_Conn* conn, bool autosync); + +void gtm_primary_sync_standby(GTM_Conn* conn); +bool gtm_sync_primary_info_to_etcd(const char* host, int port); +char* gtm_get_primary_info_from_etcd(bool force); + +#endif /* GTM_STANDBY_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_test_framework.h postgresql-hll-2.14/include/gtm/gtm_test_framework.h --- postgresql-hll-2.14_old/include/gtm/gtm_test_framework.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_test_framework.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_test_framework.h + * Routines for gtm distributed test framework. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_test_framework.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DISTRIBUTE_TEST_H +#define DISTRIBUTE_TEST_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_opt.h" +#include "gtm/utils/elog.h" + +#ifdef USE_ASSERT_CHECKING +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_DISTRIBUTE_TEST +#endif + +#define MAX_GID_STR_LEN (1024) +#define MAX_NAME_STR_LEN (256) + +/* white-box log handle */ +#define ereport_whitebox_domain(elevel, file, line, func, domain, rest) \ + (errstart(elevel, file, line, func, domain) ? (errfinish rest) : (void)0) + +#define ereport_whitebox(elevel, file, line, func, rest) \ + ereport_whitebox_domain(elevel, file, line, func, TEXTDOMAIN, rest) + +#define WHITEBOX_LOC __FILE__, __LINE__, PG_FUNCNAME_MACRO + +typedef struct GtmDistributeTestParam { + /* use as the guc-control white-box-fault probability + * range [0, 100000], probability 0, 1/100000 -> 1 + */ + int guc_probability; + + /* fault level, support ERROR and PANIC */ + int elevel; + + /* when white-box fault is WHITEBOX_WAIT, guc can provide "sleep_time" + * for sleep time control, if guc not contain this field, use the default value 30s + */ + int sleep_time; +} GtmDistributeTestParam; + +/* GTM white-box failure injection type definition */ +typedef enum GtmWhiteboxFaillueType { + GTM_WHITEBOX_DEFAULT = 0, + GTM_WHITEBOX_WAIT, + GTM_WHITEBOX_REPEAT, + GTM_WHITEBOX_USERDEFINE, + GTM_WHITEBOX_BUTT +} GtmWhiteboxFaillueType; + +/* struct created for white-box tesing, support expansion */ +typedef struct GtmWhiteBoxInjectStruct { + /* test location record */ + char filename[MAX_NAME_STR_LEN]; + int lineno; + char funcname[MAX_NAME_STR_LEN]; + + /* failure type, defined above */ + int failureType; + + /* trigger as the probability, 0 -1, if set as 1, definitely trigger */ + double triggerProbability; + + /* white box test info needed */ + GlobalTransactionId currentXid; + GTM_TransactionHandle handle; +} GtmWhiteBoxInjectStruct; + +typedef void (*on_whitebox_callback)(GtmWhiteBoxInjectStruct* wbinfo); + +extern GtmDistributeTestParam* gtmDistributeTestParam; + +extern void gtm_default_whitebox_emit(GtmWhiteBoxInjectStruct* wbinfo); +extern bool gtm_check_distribute_test_param(char** newval, void** extra, GtmOptSource source); +extern void gtm_assign_distribute_test_param(const char* newval, void* extra); +extern bool gtm_execute_whitebox(const char* filename, int lineno, const char* funcname, GlobalTransactionId xid, + GTM_TransactionHandle handle, int failureType, double probability); + +/*GTM exception scenes*/ + +#endif + +#endif /* DISTRIBUTE_TEST_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_time.h postgresql-hll-2.14/include/gtm/gtm_time.h --- postgresql-hll-2.14_old/include/gtm/gtm_time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_time.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * gtm_time.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_TIME_H +#define GTM_TIME_H + +/* Julian-date equivalents of Day 0 in Unix and GTM reckoning */ +#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */ +#define GTM_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */ + +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 +#define SECS_PER_HOUR 3600 +#define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 + +#ifdef HAVE_INT64_TIMESTAMP +#define USECS_PER_DAY INT64CONST(86400000000) +#define USECS_PER_HOUR INT64CONST(3600000000) +#define USECS_PER_MINUTE INT64CONST(60000000) +#define USECS_PER_SEC INT64CONST(1000000) +#endif + +GTM_Timestamp GTM_TimestampGetCurrent(void); + +bool GTM_TimestampDifferenceExceeds(GTM_Timestamp start_time, GTM_Timestamp stop_time, int msec); +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_txn.h postgresql-hll-2.14/include/gtm/gtm_txn.h --- postgresql-hll-2.14_old/include/gtm/gtm_txn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_txn.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,360 @@ +/* ------------------------------------------------------------------------- + * + * gtm_txn.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_TXN_H +#define _GTM_TXN_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_list.h" +#include "gtm/utils/stringinfo.h" +#include "gtm/gtm_msg.h" +#include "gtm/gtm_atomic.h" + +typedef struct MemoryContextData* MemoryContext; + +/* ---------------- + * Special transaction ID values + * + * BootstrapGlobalTransactionId is the XID for "bootstrap" operations, and + * FrozenGlobalTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalGlobalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define BootstrapGlobalTransactionId ((GlobalTransactionId)1) +#define FrozenGlobalTransactionId ((GlobalTransactionId)2) +#define FirstNormalGlobalTransactionId ((GlobalTransactionId)3) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define GlobalTransactionIdIsNormal(xid) ((xid) >= FirstNormalGlobalTransactionId) +#define GlobalTransactionIdEquals(id1, id2) ((id1) == (id2)) +#define GlobalTransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidGlobalTransactionId(dest) (*(dest) = InvalidGlobalTransactionId) + +/* advance a transaction ID variable */ +#define GlobalTransactionIdAdvance(dest) do { \ + (dest)++; \ + if ((dest) < FirstNormalGlobalTransactionId) \ + (dest) = FirstNormalGlobalTransactionId; \ +} while (0) + +typedef int XidStatus; + +#define TRANSACTION_STATUS_IN_PROGRESS 0x00 +#define TRANSACTION_STATUS_COMMITTED 0x01 +#define TRANSACTION_STATUS_ABORTED 0x02 + +#define XACT_RESFILE "pgxc_running_xact.ready" +#define XACT_DONEFILE "pgxc_running_xact.done" + +#define ECTD_RETRY_TIMES 10 +#define ETCD_RETRY_TIMEOUT 12 /* assume etcd RTO is 10s */ + +/* + * check whether etcd retry limit exceeded + */ +extern bool etcd_retry_exceeded(time_t start_time, int count); + +/* + * prototypes for functions in transam/transam.c + */ +extern bool GlobalTransactionIdDidCommit(GlobalTransactionId transactionId); +extern bool GlobalTransactionIdDidAbort(GlobalTransactionId transactionId); +extern void GlobalTransactionIdAbort(GlobalTransactionId transactionId); + +/* + * GlobalTransactionIdPrecedes --- is id1 < id2? + */ +#define GlobalTransactionIdPrecedes(id1, id2) ((id1) < (id2)) + +/* + * GlobalTransactionIdPrecedesOrEquals --- is id1 <= id2? + */ +#define GlobalTransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) + +/* + * GlobalTransactionIdFollows --- is id1 > id2? + */ +#define GlobalTransactionIdFollows(id1, id2) ((id1) > (id2)) + +/* + * GlobalTransactionIdFollowsOrEquals --- is id1 >= id2? + */ +#define GlobalTransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +extern void GTM_CalculateLatestSnapshot(bool calc_xmin); + +/* in transam/varsup.c */ +extern bool GTM_SetDoVacuum(GTM_TransactionHandle handle); +extern GlobalTransactionId GTM_GetGlobalTransactionId(GTM_TransactionHandle handle, bool is_sub_xact); +extern GlobalTransactionId GTM_GetGlobalTransactionIdMulti(GTM_TransactionHandle handle[], int txn_count, + bool is_sub_xact); +extern GlobalTransactionId ReadNewGlobalTransactionId(void); +extern void SetGlobalTransactionIdLimit(GlobalTransactionId oldest_datfrozenxid); +extern void SetNextGlobalTransactionId(GlobalTransactionId gxid); +extern void GTM_SetShuttingDown(void); + +/* For restoration point backup */ +extern bool GTM_NeedXidRestoreUpdate(void); +extern bool GTM_NeedCsnRestoreUpdate(void); +extern void GTM_WriteRestorePointXid(FILE* f, bool xid_restore); +extern void GTM_WriteRestorePointCSN(FILE* f); +extern void GTM_WriteTimeline(FILE* f); +extern void GTM_WriteTransactionLength(FILE* f); + +typedef enum GTM_States { + GTM_STARTING, + GTM_RUNNING, + GTM_SHUTTING_DOWN +} GTM_States; + +/* Global transaction states at the GTM */ +typedef enum GTM_TransactionStates { + GTM_TXN_STARTING, + GTM_TXN_IN_PROGRESS, + GTM_TXN_PREPARE_IN_PROGRESS, + GTM_TXN_PREPARED, + GTM_TXN_COMMIT_IN_PROGRESS, + GTM_TXN_COMMITTED, + GTM_TXN_ABORT_IN_PROGRESS, + GTM_TXN_ABORTED +} GTM_TransactionStates; + +typedef struct GTM_TransactionInfo { + GTM_TransactionHandle gti_handle; + GTM_ThreadID gti_thread_id; + uint32 gti_client_id; + + GTM_Atomic gti_in_use; + GlobalTransactionId gti_gxid; + GTM_TransactionStates gti_state; + char* gti_coordname; + GlobalTransactionId gti_xmin; + GlobalTransactionId gti_xmax; /* The max gxid of the current txn_slot(including sub xacts) */ + GTM_IsolationLevel gti_isolevel; + bool gti_readonly; + GTMProxy_ConnID gti_backend_id; + char* nodestring; /* List of nodes prepared */ + char* gti_gid; + + GTM_SnapshotData gti_current_snapshot; + bool gti_snapshot_set; + + volatile bool gti_vacuum; + uint32 gti_timeline; + GTM_RWLock gti_lock; +} GTM_TransactionInfo; + +struct MemReservation { + pthread_cond_t mem_Reserve_cond; + int4 mem_to_reserve; + char* rp_name; + + bool is_invalid; +}; + +/* By default a GID length is limited to 256 bits in PostgreSQL */ +#define GTM_MAX_GID_LEN 256 +#define GTM_CheckTransactionHandle(x) ((x) >= 0 && (x) < gtm_max_trans) +#define GTM_IsTransSerializable(x) ((x)->gti_isolevel == GTM_ISOLATION_SERIALIZABLE) + +typedef struct GTM_Transactions { + uint32 gt_txn_count; + GTM_States gt_gtm_state; + + GTM_RWLock gt_XidGenLock; + + /* + * These fields are protected by XidGenLock + */ + GlobalTransactionId gt_nextXid; /* next XID to assign */ + volatile GlobalTransactionId gt_backedUpXid; /* backed up, restoration point */ + + volatile uint64 gt_csn; /* current commit sequence number */ + GlobalTransactionId gt_oldestXid; /* cluster-wide minimum datfrozenxid */ + + /* + * These fields are protected by TransArrayLock. + */ + GlobalTransactionId gt_latestCompletedXid; /* newest XID that has committed or + * aborted */ + + GlobalTransactionId gt_xmin; + GlobalTransactionId gt_recent_global_xmin; + + int32 gt_lastslot; + GTM_TransactionInfo* gt_transactions_array; + + GTM_MutexLock gt_TransArrayLock; + + /* + * These fields are for lock-free snapshot management + */ + MemoryContext gt_SnapCalcCtx; + GTM_Snapshot gt_snapArray; + volatile uint32_t gt_currentSnap; + volatile uint32_t gt_nextSnap; + uint32_t gt_numVersions; + GTM_Atomic* gt_rcArray; + GTM_Atomic gt_concurrentTransactions; + uint32_t gt_snapshotPendingCnt; +} GTM_Transactions; + +extern GTM_Transactions GTMTransactions; + +/* + * When gtm restart as primary or restart as pending->primary, its xid will increase 2000. + * Then we should sync the new xid to standby, so we make the GTM_SyncGXIDFlag to true. + * When a gtm client get a new xid from gtm primary, if the GTM_SyncGXIDFlag is true, it + * will sync the new xid to stanby. + */ +extern volatile bool GTM_SyncGXIDFlag; + +/* + * This macro should be used with READ lock held on gt_TransArrayLock as the + * number of open transactions might change when counting open transactions + * if a lock is not hold. + */ +#define GTM_CountOpenTransactions() (GTMTransactions.gt_concurrentTransactions) + +/* + * Two hash tables will be maintained to quickly find the + * GTM_TransactionInfo block given either the GXID or the GTM_TransactionHandle. + */ +GlobalTransactionId GTM_HandleToTransactionId(GTM_TransactionHandle handle); +GTM_TransactionInfo* GTM_HandleToTransactionInfo(GTM_TransactionHandle handle); +GTM_TransactionHandle GTM_GXIDToHandle(GlobalTransactionId gxid); +GTM_TransactionHandle GTM_GIDToHandle(const char* gid); + +/* Transaction Control */ +void GTM_InitTxnManager(void); +GTM_TransactionHandle GTM_BeginTransaction(const char* coord_name, GTM_IsolationLevel isolevel, bool readonly); +int GTM_BeginTransactionMulti(const char* coord_name, GTM_IsolationLevel isolevel[], const bool readonly[], + GTMProxy_ConnID connid[], int txn_count, GTM_TransactionHandle txns[]); +bool GTM_FillTransactionInfo(const char* coord_name, GTM_TransactionHandle handle, GlobalTransactionId gxid, + GTM_TransactionStates state, GlobalTransactionId xmin, bool vacuum, uint32 timeline); + +int GTM_RollbackTransaction(GTM_TransactionHandle txn, bool isTimelineOK); +int GTM_RollbackTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[], bool isTimelineOK); +int GTM_RollbackTransactionGXID(GlobalTransactionId gxid); +int GTM_CommitTransaction(GTM_TransactionHandle txn, bool isTimelineOK, uint64 *csn); +int GTM_CommitTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[], bool isTimelineOK, + uint64 *csn); + +int GTM_PrepareTransaction(GTM_TransactionHandle txn); +int GTM_StartPreparedTransaction(GTM_TransactionHandle txn, const char* gid, const char* nodestring); +int GTM_StartPreparedTransactionGXID(GlobalTransactionId gxid, const char* gid, const char* nodestring); +int GTM_GetGIDData(GTM_TransactionHandle prepared_txn, GlobalTransactionId* prepared_gxid, char** nodestring); +uint32 GTM_GetAllPrepared(GlobalTransactionId gxids[], uint32 gxidcnt); +GTM_TransactionStates GTM_GetStatus(GTM_TransactionHandle txn); +GTM_TransactionStates GTM_GetStatusGXID(GlobalTransactionId gxid); +int GTM_GetAllTransactions(GTM_TransactionInfo txninfo[], uint32 txncnt); +void GTM_RemoveAllTransInfos(int backend_id); +void GTM_RemoveAllTransInfosForClient(uint32 client_id, int backend_id); +void GTM_RemoveAllTransInfosOutofTimeline(char* nodename, uint32 timeline); + +GTM_Snapshot GTM_GetSnapshotData(GTM_TransactionInfo* my_txninfo, GTM_Snapshot snapshot); +GTM_Snapshot GTM_GetTransactionSnapshot(GTM_TransactionHandle handle[], int txn_count, int* status); +void GTM_FreeCachedTransInfo(void); + +void ProcessResetTrasactionXminCommand(Port* myport, StringInfo message); +void ProcessSetVacuumCommand(Port* myport, StringInfo message); +void ProcessBeginTransactionCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionCommandMulti(Port* myport, StringInfo message); +void ProcessBeginTransactionGetGXIDCommand(Port* myport, StringInfo message); +void ProcessCommitTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessCommitPreparedTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessRollbackTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessPrepareTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessGetGIDDataTransactionCommand(Port* myport, StringInfo message); + +void ProcessGetGXIDTransactionCommand(Port* myport, StringInfo message, bool is_sub_xact); + +void ProcessGXIDListCommand(Port* myport, StringInfo message); +void ProcessGetNextGXIDTransactionCommand(Port* myport, StringInfo message); +void ProcessGetNextCSNTransactionCommand(Port* myport, StringInfo message); +void ProcessGetNextCSNTransactionLiteCommand(Port* myport, StringInfo message); +void ProcessGetGlobalXminTransactionCommand(Port* myport, StringInfo message); +void ProcessGetTimelineTransactionCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionGetGXIDAutovacuumCommand(Port* myport, StringInfo message); + +/* + * * workload manager + * */ +struct GTM_WorkloadManager { + int free_server_mem; + pthread_mutex_t workldmgr_mem_mutex; +}; + +void ProcessWorkloadManagerInitCommand(Port* myport, StringInfo message); +void ProcessWorkloadManagerReserveMemCommand(Port* myport, StringInfo message); +void ProcessWorkloadManagerReleaseMemCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionGetGXIDCommandMulti(Port* myport, StringInfo message); +void ProcessCommitTransactionCommandMulti(Port* myport, StringInfo message, bool is_backup); +void ProcessRollbackTransactionCommandMulti(Port* myport, StringInfo message, bool is_backup); + +void GTM_SaveTxnInfo(FILE* ctlf); +void GTM_SaveTimelineInfo(FILE* ctlf); +void GTM_SaveTransactionLength(FILE* ctlf); + +void GTM_RestoreTxnInfo(FILE* ctlf, GlobalTransactionId next_gxid); +void GTM_RestoreTimelineInfo(FILE* ctlf, GTM_Timeline* timeline); +void GTM_RestoreTransactionsLen(FILE* ctlf, uint32* len); + +void ProcessBkupGtmControlFileGXIDCommand(Port* myport, StringInfo message); +void ProcessBkupGtmControlFileTIMELINECommand(Port* myport, StringInfo message); + +void GTM_SyncGXID(GlobalTransactionId xid, int txn_count = 0); +bool GTM_SyncXidToStandby(GlobalTransactionId xid); +bool GTM_SetXidToEtcd(GlobalTransactionId xid, bool save, GlobalTransactionId etcd_xid = InvalidGlobalTransactionId); +bool GTMSyncXidToEtcdInternal(GlobalTransactionId xid, bool force, + GlobalTransactionId etcd_xid = InvalidGlobalTransactionId); +bool GTM_SetGlobalMaxXidToEtcd(GlobalTransactionId xid, bool save, int txn_count = 0); +bool GTM_GetXidFromEtcd(GlobalTransactionId& xid, bool force, bool need_retry = false); +void GTM_GetSyncXidFromEtcd(const char* errString); + +void GTM_SyncTimeline(GTM_Timeline timeline); +bool GTM_SyncTimelineToStandby(GTM_Timeline timeline); +bool GTM_SetTimelineToEtcd(GTM_Timeline timeline); +bool GTM_GetTimelineFromEtcd(GTM_Timeline& timeline); + +void ProcessWorkloadManagerInitCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerReserveMemCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerReleaseMemCommand(Port* myport, StringInfo message, bool is_backup); + +extern void initialize_resource_pool(void); +int CheckInitialization(Port* myport, StringInfo message, GTM_MessageType mtype); +void ProcessWorkloadManagerInitializeResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerCreateResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerUpdateResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerDeleteResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); + +/* + * In gtm_snap.c + */ +void ProcessGetSnapshotCommand(Port* myport, StringInfo message, bool get_gxid); +void ProcessGetSnapshotLiteCommand(Port* myport, StringInfo message); +void ProcessGetSnapshotStatusCommand(Port* myport, StringInfo message); +void ProcessGetGTMLiteStatusCommand(Port* myport, StringInfo message); +void GTM_FreeSnapshotData(GTM_Snapshot snapshot); +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/gtm_utils.h postgresql-hll-2.14/include/gtm/gtm_utils.h --- postgresql-hll-2.14_old/include/gtm/gtm_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/gtm_utils.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,89 @@ +/* ------------------------------------------------------------------------- + * + * gtm_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_utils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_UTILS_H +#define GTM_UTILS_H + +#include "gtm/utils/libpq-int.h" +#include "gtm/gtm_msg.h" + +#ifndef WIN32 + +#include + +/* GTMS --> GTM Server */ +typedef struct timeval gtms_time; + +#define GTMS_TIME_IS_ZERO(t) ((t).tv_usec == 0 && (t).tv_sec == 0) + +#define GTMS_TIME_IS_INTMAX(t) ((t).tv_usec == LONG_MAX && (t).tv_sec == LONG_MAX) + +#define GTMS_TIME_INITIAL_MIN(t) ((t).tv_usec = LONG_MAX, (t).tv_sec = LONG_MAX) + +#define GTMS_TIME_IS_BIGGER(x, y) ((x).tv_sec >= (y).tv_sec && (x).tv_usec >= (y).tv_usec) + +#define GTMS_TIME_SET_ZERO(t) ((t).tv_sec = 0, (t).tv_usec = 0) + +#define GTMS_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) + +#define GTMS_TIME_ADD(x, y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define GTMS_TIME_SUBTRACT(x, y) \ + do { \ + (x).tv_sec -= (y).tv_sec; \ + (x).tv_usec -= (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + } while (0) + +#define GTMS_TIME_ACCUM_DIFF(x, y, z) \ + do { \ + (x).tv_sec += (y).tv_sec - (z).tv_sec; \ + (x).tv_usec += (y).tv_usec - (z).tv_usec; \ + /* Normalize after each add to avoid overflow/underflow of tv_usec */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define GTMS_TIME_GET_DOUBLE(t) (((double)(t).tv_sec) + ((double)(t).tv_usec) / 1000000.0) + +#define GTMS_TIME_GET_MILLISEC(t) (((double)(t).tv_sec * 1000.0) + ((double)(t).tv_usec) / 1000.0) + +#define GTMS_TIME_GET_MICROSEC(t) (((uint64)(t).tv_sec * (uint64)1000000) + (uint64)(t).tv_usec) + +#endif /* WIN32 */ + +void gtm_util_init_nametabs(void); +char* gtm_util_message_name(GTM_MessageType type); +char* gtm_util_result_name(GTM_ResultType type); + +extern void gtm_usleep(long microsec); +#endif /* GTM_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/assert.h postgresql-hll-2.14/include/gtm/utils/assert.h --- postgresql-hll-2.14_old/include/gtm/utils/assert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/assert.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * assert.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_ASSERT_H +#define GTM_ASSERT_H + +#include "c.h" + +extern THR_LOCAL bool assert_enabled; + +/* + * USE_ASSERT_CHECKING, if defined, turns on all the assertions. + * - plai 9/5/90 + * + * It should _NOT_ be defined in releases or in benchmark copies + */ + +/* + * Trap + * Generates an exception if the given condition is true. + */ +#define Trap(condition, errorType) \ + do { \ + if ((assert_enabled) && (condition)) \ + ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__); \ + } while (0) + +/* + * TrapMacro is the same as Trap but it's intended for use in macros: + * + * #define foo(x) (AssertMacro(x != 0) && bar(x)) + * + * Isn't CPP fun? + */ +#define TrapMacro(condition, errorType) \ + ((bool)((!assert_enabled) || !(condition) || \ + (ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__)))) +#ifdef PC_LINT +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#define AssertMacro Assert +#define AssertArg Assert +#define DBG_ASSERT Assert +#define AssertState Assert +#else + +#ifndef USE_ASSERT_CHECKING +#define Assert(condition) +#define AssertMacro(condition) ((void)true) +#define AssertArg(condition) +#define AssertState(condition) +#else +#define Assert(condition) Trap(!(condition), "FailedAssertion") + +#define AssertMacro(condition) ((void)TrapMacro(!(condition), "FailedAssertion")) + +#define AssertArg(condition) Trap(!(condition), "BadArgument") + +#define AssertState(condition) Trap(!(condition), "BadState") +#endif /* USE_ASSERT_CHECKING */ +#endif // PC_LINT +extern int ExceptionalCondition(const char* conditionName, const char* errorType, const char* fileName, int lineNumber); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/utils/atomic.h postgresql-hll-2.14/include/gtm/utils/atomic.h --- postgresql-hll-2.14_old/include/gtm/utils/atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/atomic.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * atomic.h + * Header file for atomic operations. + * + * + * IDENTIFICATION + * src/include/gtm/atomic.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_GTM_ATOMIC_H +#define SRC_INCLUDE_GTM_ATOMIC_H + +extern int32 gs_atomic_add_32(volatile int32* ptr, int32 inc); +extern int64 gs_atomic_add_64(int64* ptr, int64 inc); + +extern int32 gs_lock_test_and_set(volatile int32* ptr, int32 val); +extern int64 gs_lock_test_and_set_64(volatile int64* ptr, int64 val); + +extern bool gs_compare_and_swap_32(volatile int32* dest, int32 oldval, int32 newval); +extern bool gs_compare_and_swap_64(int64* dest, int64 oldval, int64 newval); + +extern void pg_atomic_init_u32(volatile uint32* ptr, uint32 val); +extern uint32 pg_atomic_read_u32(volatile uint32* ptr); +extern uint32 pg_atomic_fetch_or_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_and_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_add_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_add_fetch_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_sub_u32(volatile uint32* ptr, int32 inc); +extern uint32 pg_atomic_sub_fetch_u32(volatile uint32* ptr, int32 inc); +extern bool pg_atomic_compare_exchange_u32(volatile uint32* ptr, uint32* expected, uint32 newval); +extern void pg_atomic_write_u32(volatile uint32* ptr, uint32 val); +extern uint32 pg_atomic_exchange_u32(volatile uint32* ptr, uint32 newval); + +extern void pg_atomic_init_u64(volatile uint64* ptr, uint64 val); +extern uint64 pg_atomic_read_u64(volatile uint64* ptr); +extern uint64 pg_atomic_fetch_or_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_and_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_add_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_add_fetch_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_sub_u64(volatile uint64* ptr, int64 inc); +extern uint64 pg_atomic_sub_fetch_u64(volatile uint64* ptr, int64 inc); +extern bool pg_atomic_compare_exchange_u64(volatile uint64* ptr, uint64* expected, uint64 newval); +extern void pg_atomic_write_u64(volatile uint64* ptr, uint64 val); +extern uint64 pg_atomic_exchange_u64(volatile uint64* ptr, uint64 newval); + +#endif // SRC_INCLUDE_GTM_ATOMIC_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/gtm/utils/barrier.h postgresql-hll-2.14/include/gtm/utils/barrier.h --- postgresql-hll-2.14_old/include/gtm/utils/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/barrier.h 2020-12-12 17:06:43.127346490 +0800 @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * Memory barrier operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/gtm/utils/barrier.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTMBARRIER_H +#define GTMBARRIER_H + +#include "gtm/gtm_slock.h" + +/* + * A compiler barrier need not (and preferably should not) emit any actual + * machine code, but must act as an optimization fence: the compiler must not + * reorder loads or stores to main memory around the barrier. However, the + * CPU may still reorder loads or stores at runtime, if the architecture's + * memory model permits this. + * + * A memory barrier must act as a compiler barrier, and in addition must + * guarantee that all loads and stores issued prior to the barrier are + * completed before any loads or stores issued after the barrier. Unless + * loads and stores are totally ordered (which is not the case on most + * architectures) this requires issuing some sort of memory fencing + * instruction. + * + * A read barrier must act as a compiler barrier, and in addition must + * guarantee that any loads issued prior to the barrier are completed before + * any loads issued after the barrier. Similarly, a write barrier acts + * as a compiler barrier, and also orders stores. Read and write barriers + * are thus weaker than a full memory barrier, but stronger than a compiler + * barrier. In practice, on machines with strong memory ordering, read and + * write barriers may require nothing more than a compiler barrier. + * + * For an introduction to using memory barriers within the PostgreSQL backend, + * see src/backend/storage/lmgr/README.barrier + */ + +#if defined(DISABLE_BARRIERS) + +/* + * Fall through to the spinlock-based implementation. + */ +#elif defined(__INTEL_COMPILER) + +/* + * icc defines __GNUC__, but doesn't support gcc's inline asm syntax + */ +#define pg_memory_barrier() _mm_mfence() +#define pg_compiler_barrier() __memory_barrier() +#elif defined(__GNUC__) + +/* This works on any architecture, since it's only talking to GCC itself. */ +#define pg_compiler_barrier() __asm__ __volatile__("" : : : "memory") + +#if defined(__i386__) + +/* + * i386 does not allow loads to be reordered with other loads, or stores to be + * reordered with other stores, but a load can be performed before a subsequent + * store. + * + * "lock; addl" has worked for longer than "mfence". + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__x86_64__) /* 64 bit x86 */ + +/* + * x86_64 has similar ordering characteristics to i386. + * + * Technically, some x86-ish chips support uncached memory access and/or + * special instructions that are weakly ordered. In those cases we'd need + * the read and write barriers to be lfence and sfence. But since we don't + * do those things, a compiler barrier should be enough. + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%rsp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__aarch64__) +/* + * aarch64 architecure memory barrier. In order to minimize the impact on + * performance, here use dmb memory barrier. + */ +#define pg_memory_barrier_dsb(opt) __asm__ __volatile__("DMB " #opt::: "memory") + +#ifndef ENABLE_THREAD_CHECK + +#define pg_memory_barrier() pg_memory_barrier_dsb(ish) +#define pg_read_barrier() pg_memory_barrier_dsb(ishld) +#define pg_write_barrier() pg_memory_barrier_dsb(ishst) + +#else + +#include "tsan_annotation.h" + +#define pg_memory_barrier() do { \ + TsAnnotateReadBarrier(); \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ish); \ +} while (0) + +#define pg_read_barrier() do { \ + TsAnnotateReadBarrier(); \ + pg_memory_barrier_dsb(ishld); \ +} while (0) + +#define pg_write_barrier() do { \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ishst); \ +} while (0) + +#endif +#elif defined(__ia64__) || defined(__ia64) + +/* + * Itanium is weakly ordered, so read and write barriers require a full + * fence. + */ +#define pg_memory_barrier() __asm__ __volatile__("mf" : : : "memory") +#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) + +/* + * lwsync orders loads with respect to each other, and similarly with stores. + * But a load can be performed before a subsequent store, so sync must be used + * for a full memory barrier. + */ +#define pg_memory_barrier() __asm__ __volatile__("sync" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#elif defined(__alpha) || defined(__alpha__) /* Alpha */ + +/* + * Unlike all other known architectures, Alpha allows dependent reads to be + * reordered, but we don't currently find it necessary to provide a conditional + * read barrier to cover that case. We might need to add that later. + */ +#define pg_memory_barrier() __asm__ __volatile__("mb" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("rmb" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("wmb" : : : "memory") +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) + +/* + * If we're on GCC 4.1.0 or higher, we should be able to get a memory + * barrier out of this compiler built-in. But we prefer to rely on our + * own definitions where possible, and use this only as a fallback. + */ +#define pg_memory_barrier() __sync_synchronize() +#endif +#elif defined(__ia64__) || defined(__ia64) + +#define pg_compiler_barrier() _Asm_sched_fence() +#define pg_memory_barrier() _Asm_mf() +#elif defined(WIN32_ONLY_COMPILER) + +/* Should work on both MSVC and Borland. */ +#include +#pragma intrinsic(_ReadWriteBarrier) +#define pg_compiler_barrier() _ReadWriteBarrier() +#define pg_memory_barrier() MemoryBarrier() +#endif + +/* + * If we have no memory barrier implementation for this architecture, we + * fall back to acquiring and releasing a spinlock. This might, in turn, + * fall back to the semaphore-based spinlock implementation, which will be + * amazingly slow. + * + * It's not self-evident that every possible legal implementation of a + * spinlock acquire-and-release would be equivalent to a full memory barrier. + * For example, I'm not sure that Itanium's acq and rel add up to a full + * fence. But all of our actual implementations seem OK in this regard. + */ + +#if !defined(pg_memory_barrier) +#define pg_memory_barrier(x) \ + do { \ + S_LOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + S_UNLOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + } while (0) +#endif +/* + * If read or write barriers are undefined, we upgrade them to full memory + * barriers. + * + * If a compiler barrier is unavailable, you probably don't want a full + * memory barrier instead, so if you have a use case for a compiler barrier, + * you'd better use #ifdef. + */ +#if !defined(pg_read_barrier) +#define pg_read_barrier() pg_memory_barrier() +#endif +#if !defined(pg_write_barrier) +#define pg_write_barrier() pg_memory_barrier() +#endif + +#endif /* GTMBARRIER_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/elog.h postgresql-hll-2.14/include/gtm/utils/elog.h --- postgresql-hll-2.14_old/include/gtm/utils/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/elog.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,314 @@ +/* ------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.98 2009/01/01 17:24:02 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include "c.h" +#include "securec.h" +#include "securec_check.h" + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ +#define DEBUG4 11 +#define DEBUG3 12 +#define DEBUG2 13 +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ +#define COMMERROR \ + 16 /* Client communication problems; same as LOG \ + * for server reporting, but never sent to \ + * client. */ +#define INFO \ + 17 /* Messages specifically requested by user \ + * (eg VACUUM VERBOSE output); always sent to \ + * client regardless of client_min_messages, \ + * but by default not sent to server log. */ +#define NOTICE \ + 18 /* Helpful messages to users about query \ + * operation; sent to client and server log \ + * by default. */ +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define ERROR2 \ + 21 /* user error - only send error message to the \ + * client */ +#define FATAL 22 /* fatal error - abort process */ +#define PANIC 23 /* take down the other backends with me */ + +/* Which __func__ symbol do we have, if any? */ +#ifdef HAVE_FUNCNAME__FUNC +#define PG_FUNCNAME_MACRO __func__ +#else +#ifdef HAVE_FUNCNAME__FUNCTION +#define PG_FUNCNAME_MACRO __FUNCTION__ +#else +#define PG_FUNCNAME_MACRO NULL +#endif +#endif + +#define securec_check(errno, charList, ...) \ + { \ + if (unlikely(EOK != errno)) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + switch (errno) { \ + case EINVAL: \ + elog(ERROR, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(ERROR, "%s : %d : The source buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(ERROR, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } + +/* Only used in sprintf_s or scanf_s cluster function */ +#define securec_check_ss(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + elog(ERROR, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } + +/* + * ErrorData holds the data accumulated during any one ereport() cycle. + * Any non-NULL pointers must point to palloc'd data. + * (The const pointers are an exception; we assume they point at non-freeable + * constant strings.) + */ +typedef struct ErrorData { + int elevel; /* error level */ + bool output_to_server; /* will report to server log? */ + bool output_to_client; /* will report to client? */ + bool show_funcname; /* true to force funcname inclusion */ + const char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + const char* funcname; /* __func__ of ereport() call */ + const char* domain; /* message domain */ + char* message; /* primary error message */ + char* detail; /* detail error message */ + char* detail_log; /* detail error message for server log only */ + char* hint; /* hint message */ + char* context; /* context message */ + int saved_errno; /* errno at entry */ +} ErrorData; + +/* ---------- + * New-style error reporting API: to be used in this way: + * ereport(ERROR, + * (errcode(ERRCODE_UNDEFINED_CURSOR), + * errmsg("portal \"%s\" not found", stmt->portalname), + * ... other errxxx() fields as needed ...)); + * + * The error level is required, and so is a primary error message (errmsg + * or errmsg_internal). All else is optional. errcode() defaults to + * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING + * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is + * NOTICE or below. + * + * ereport_domain() allows a message domain to be specified, for modules that + * wish to use a different message catalog from the backend's. To avoid having + * one copy of the default text domain per .o file, we define it as NULL here + * and have errstart insert the default text domain. Modules can either use + * ereport_domain() directly, or preferably they can override the TEXTDOMAIN + * macro. + * ---------- + */ +#define TEXTDOMAIN "GTM" + +#define ereport_domain(elevel, domain, rest) \ + (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? (errfinish rest) : (void)0) + +#define ereport(elevel, rest) ereport_domain(elevel, TEXTDOMAIN, rest) + +#define PG_RE_THROW() pg_re_throw() + +extern bool errstart(int elevel, const char* filename, int lineno, const char* funcname, const char* domain); +extern void errfinish(int dummy, ...); + +extern int errmsg(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errmsg_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errdetail(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errdetail_log(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errhint(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +/* ---------- + * Old-style error reporting API: to be used in this way: + * elog(ERROR, "portal \"%s\" not found", stmt->portalname); + * ---------- + */ + +#ifdef PC_LINT +#define elog(level, ...) \ + do { \ + if (level >= ERROR) \ + exit(0); \ + } while (0) +#else +#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish +#endif /* PCLINT_CHECK */ + +extern void elog_start(const char* filename, int lineno, const char* funcname); +extern void elog_finish(int elevel, const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 2, 3))); + +/* ---------- + * API for catching ereport(ERROR) exits. Use these macros like so: + * + * PG_TRY(); + * { + * ... code that might throw ereport(ERROR) ... + * } + * PG_CATCH(); + * { + * ... error recovery code ... + * } + * PG_END_TRY(); + * + * (The braces are not actually necessary, but are recommended so that + * pg_indent will indent the construct nicely.) The error recovery code + * can optionally do PG_RE_THROW() to propagate the same error outwards. + * + * Note: while the system will correctly propagate any new ereport(ERROR) + * occurring in the recovery section, there is a small limit on the number + * of levels this will work for. It's best to keep the error recovery + * section simple enough that it can't generate any new errors, at least + * not before popping the error stack. + * + * Note: an ereport(FATAL) will not be caught by this construct; control will + * exit straight through proc_exit(). Therefore, do NOT put any cleanup + * of non-process-local resources into the error recovery section, at least + * not without taking thought for what will happen during ereport(FATAL). + * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be + * helpful in such cases. + * ---------- + */ +#define PG_TRY() \ + do { \ + sigjmp_buf* save_exception_stack = PG_exception_stack; \ + sigjmp_buf local_sigjmp_buf; \ + if (sigsetjmp(local_sigjmp_buf, 0) == 0) { \ + PG_exception_stack = &local_sigjmp_buf + +#define PG_CATCH() \ + } \ + else \ + { \ + PG_exception_stack = save_exception_stack; + +#define PG_END_TRY() \ + } \ + PG_exception_stack = save_exception_stack; \ + } \ + while (0) + +int errfunction(const char* funcname); + +extern void EmitErrorReport(void* port); + +/* GUC-configurable parameters */ + +typedef enum { + PGERROR_TERSE, /* single-line error messages */ + PGERROR_DEFAULT, /* recommended style */ + PGERROR_VERBOSE /* all the facts, ma'am */ +} PGErrorVerbosity; + +/* Log destination bitmap */ +#define LOG_DESTINATION_STDERR 1 +#define LOG_DESTINATION_SYSLOG 2 +#define LOG_DESTINATION_EVENTLOG 4 +#define LOG_DESTINATION_CSVLOG 8 + +/* Other exported functions */ +extern void pg_re_throw(void); +extern void DebugFileOpen(void); +extern void FlushErrorState(void); + +void freeSecurityFuncSpace(char* charList, ...); + +/* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used + * safely (memory context, GUC load etc) + */ +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); +extern void check_gtm_env(const char* input_env_value); +#endif /* GTM_ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/event_engine.h postgresql-hll-2.14/include/gtm/utils/event_engine.h --- postgresql-hll-2.14_old/include/gtm/utils/event_engine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/event_engine.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,101 @@ +/* --------------------------------------------------------------------------------------- + * + * event_engine.h + * event engine header file + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/gtm/event_engine.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EVENT_ENGINE_H +#define EVENT_ENGINE_H + +#include +#include "c.h" + +/* wait for a socket or FD to become readable */ +#define EV_READ 0x02 + +/* wait for a socket or FD to become writeable */ +#define EV_WRITE 0x04 + +/* persistent event */ +#define EV_PERSIST 0x10 + +/* select edge-triggered behavior, if supported by the backend */ +#define EV_ET 0x20 + +/* connection close event */ +#define EV_CLOSED 0x80 + +typedef struct event_config event_config_t; +typedef struct epoll_info epoll_info_t; +typedef struct event event_t; +typedef struct event_iomap event_iomap_t; +typedef struct event_base event_base_t; +typedef struct event_callback event_callback_t; + +struct event_config { + int max_dispatch_callbacks; +}; + +struct epoll_info { + int epfd; + int nevents; + struct epoll_event *epevs; +}; + +struct event { + event_base_t *ev_base; + int ev_fd; + int ev_state; + unsigned short ev_events; + unsigned short ev_res; /* result passed to event callback */ + void (*ev_cb)(int, unsigned short, void *); + void *ev_cb_arg; +}; + +struct event_iomap { + event_t **entries; + int nentries; +}; + +struct event_base { + epoll_info_t *epi; + event_iomap_t iomap; + /* number of total events added to this event_base */ + int event_count; + /* number of total active events in this event_base */ + int event_count_active; + /* set if we should terminate the loop immediately */ + bool event_break; + bool event_exit; + bool interruptable; + bool loop_one_shot; + /* set to prevent reentrant invocation */ + bool running_loop; + struct timeval timeout; + int max_dispatch_callbacks; +}; + +extern event_config_t *event_config_new(); +extern void event_config_free(event_config_t *cfg); +extern event_base_t *event_base_new(const event_config_t *cfg); +extern int event_assign(event_t *ev, event_base_t *base, int fd, unsigned short events, + void (*callback)(int, unsigned short, void *), void *arg); +extern int event_add(event_t *ev, const struct timeval *tv); +extern int event_del(event_t *ev); +extern int event_base_dispatch(event_base_t *event_base); +extern int event_base_loop(event_base_t *base, int flags); +extern int event_base_loopbreak(event_base_t *event_base); +extern int event_base_loopexit(event_base_t *event_base); +extern void event_base_free(event_base_t *base); +extern int event_get_max(); +extern bool event_exceed_limit(const event_base_t *base); +extern int event_base_retrieve_fds(event_base_t *base, int *fds, int len); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/utils/ip.h postgresql-hll-2.14/include/gtm/utils/ip.h --- postgresql-hll-2.14_old/include/gtm/utils/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/ip.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.20 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "gtm/utils/pqcomm.h" + +extern int pg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void pg_freeaddrinfo_all(struct addrinfo* ai); + +extern int pg_getnameinfo_all( + const struct sockaddr_storage* addr, int salen, char* node, int nodelen, char* service, int servicelen, int flags); + +extern int pg_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int pg_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/libpq-be.h postgresql-hll-2.14/include/gtm/utils/libpq-be.h --- postgresql-hll-2.14_old/include/gtm/utils/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/libpq-be.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,113 @@ +/* ------------------------------------------------------------------------- + * + * libpq_be.h + * This file contains definitions for structures and externs used + * by the postmaster during client authentication. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.69 2009/01/01 17:23:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_BE_H +#define LIBPQ_BE_H + +#include "gtm/utils/pqcomm.h" +#include "gtm/gtm_c.h" +#include "libpq/sha2.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * This is used by the postmaster in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMostMemoryContext, + * so that it survives into GTM_ThreadMain execution! + */ + +typedef struct Port { + int sock; /* File descriptor */ + SockAddr laddr; /* local addr (postmaster) */ + SockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_port; /* text rep of remote port */ + GTM_PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ + + GTMProxy_ConnID conn_id; /* RequestID of this command */ + + GTM_PGXCNodeType remote_type; /* Type of remote connection */ + char* node_name; + bool is_postmaster; /* Is remote a node postmaster? */ + pthread_t remote_thdpid; /* remote connection thread pid */ +#define PQ_BUFFER_SIZE 8192 + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + + /* + * GTM communication error handling. See libpq-int.h for details. + */ + int connErr_WaitOpt; + int connErr_WaitInterval; + int connErr_WaitCount; + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token buffer */ +#endif + +} Port; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +typedef enum { GTM_UNUSED_LISTEN_SOCKET = 0, GTM_SERVICE_LISTEN_SOCKET, GTM_HA_LISTEN_SOCKET } GTM_ListenSocketType; + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/libpq-fe.h postgresql-hll-2.14/include/gtm/utils/libpq-fe.h --- postgresql-hll-2.14_old/include/gtm/utils/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/libpq-fe.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,135 @@ +/* ------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.145 2009/01/01 17:24:03 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_LIBPQ_FE_H +#define GTM_LIBPQ_FE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * postgres_ext.h defines the backend's externally visible types, + * such as Oid. + */ +#include "gtm/gtm_ext.h" + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +/* Application-visible enum types */ + +typedef enum { + /* + * Although it is okay to add to this list, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} GTMConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} GTMClientPollingStatusType; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or GTMPQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. GTMPQconninfoFree() + * will release both the val strings and the GTMPQconninfoOption array itself. + * ---------------- + */ +typedef struct _GTMPQconninfoOption { + char* keyword; /* The keyword of the option */ + char* val; /* Option's current value, or NULL */ +} GTMPQconninfoOption; + +typedef struct gtm_conn GTM_Conn; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern GTM_Conn* PQconnectGTMStart(const char* conninfo); +extern GTMClientPollingStatusType GTMPQconnectPoll(GTM_Conn* conn); + +/* Synchronous (blocking) */ +extern GTM_Conn* PQconnectGTM(const char* conninfo); + +/* close the current connection and free the GTM_Conn data structure */ +extern void GTMPQfinish(GTM_Conn* conn); + +/* parse connection options in same way as PQconnectGTM */ +extern GTMPQconninfoOption* GTMPQconninfoParse(const char* conninfo, char** errmsg); + +/* free the data structure returned by PQconndefaults() or GTMPQconninfoParse() */ +extern void GTMPQconninfoFree(GTMPQconninfoOption* connOptions); + +extern char* GTMPQhost(const GTM_Conn* conn); +extern char* GTMPQport(const GTM_Conn* conn); +extern GTMConnStatusType GTMPQstatus(const GTM_Conn* conn); +extern int GTMPQispostmaster(const GTM_Conn* conn); +extern char* GTMPQerrorMessage(const GTM_Conn* conn); +extern int GTMPQsocket(const GTM_Conn* conn); + +/* Enable/disable tracing */ +extern void GTMPQtrace(GTM_Conn* conn, FILE* debug_port); +extern void GTMPQuntrace(GTM_Conn* conn); + +/* Force the write buffer to be written (or at least try) */ +extern int PQflush(GTM_Conn* conn); + +#define libpq_gettext(x) x + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/libpq.h postgresql-hll-2.14/include/gtm/utils/libpq.h --- postgresql-hll-2.14_old/include/gtm/utils/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/libpq.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.70 2008/11/20 09:29:36 mha Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_H +#define LIBPQ_H + +#include +#include + +#include "gtm/utils/stringinfo.h" +#include "gtm/utils/libpq-be.h" + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], + GTM_ListenSocketType listenSocketType[], int MaxListen, bool isServiceSocket, bool noblock); +extern int StreamConnection(int sfd, Port* port, SockAddr *sa, bool noblock); +extern void StreamClose(int sock); +extern void TouchSocketFile(void); +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len); +extern int pq_getstring(Port* myport, StringInfo s); +extern int pq_getmessage(Port* myport, StringInfo s, int maxlen); +extern int pq_getbyte(Port* myport); +extern int pq_peekbyte(Port* myport); +extern int pq_putbytes(Port* myport, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/libpq-int.h postgresql-hll-2.14/include/gtm/utils/libpq-int.h --- postgresql-hll-2.14_old/include/gtm/utils/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/libpq-int.h 2020-12-12 17:06:43.128346503 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.139 2009/01/01 17:24:03 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_INT_H +#define LIBPQ_INT_H + +#include +#include +#include +#include "gtm/utils/pqcomm.h" +#include "gtm/utils/pqexpbuffer.h" +#include "gtm/gtm_client.h" +#include "gtm/gtm_c.h" +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif +/* + * GTM_Conn stores all the state data associated with a single connection + * to a backend. + */ +struct gtm_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the IPv4 address of the machine on which + * the server is running, in IPv4 + * numbers-and-dots notation. Takes precedence + * over above. */ + char* gtmlocalhost; /* for gtm HA to connect to standby */ + char* gtmlocalport; /* for gtm HA to connect to standby */ + char* pgport; /* the server's communication port */ + char* connect_timeout; /* connection timeout (numeric string) */ + char* gc_node_name; /* PGXC Node Name */ + int remote_type; /* is this a connection to/from a proxy ? */ + int is_postmaster; /* is this connection to/from a postmaster instance */ + pthread_t remote_thdpid; /* remote node thread pid */ + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Status indicators */ + GTMConnStatusType status; + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + SockAddr laddr; /* Local address */ + SockAddr raddr; /* Remote address */ + + /* Error info for GTM communication */ + GTM_PortLastCall last_call; /* Last syscall to this sock. */ + int last_errno; /* Last errno. zero if the last call succeeds. */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + + /* Pointer to the result of last operation */ + GTM_Result* result; + + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_name_t gss_targ_nam; /* GSS target name */ + gss_buffer_desc gss_inbuf; /* GSS input token */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +#endif +}; + +/* === in fe-misc.c === */ +extern THR_LOCAL bool g_gtm_interrupt_happened; + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int gtmpqCheckOutBufferSpace(size_t bytes_needed, GTM_Conn* conn); +extern int gtmpqCheckInBufferSpace(size_t bytes_needed, GTM_Conn* conn); +extern int gtmpqGetc(char* result, GTM_Conn* conn); +extern int gtmpqPutc(char c, GTM_Conn* conn); +extern int gtmpqGets(PQExpBuffer buf, GTM_Conn* conn); +extern int gtmpqGets_append(PQExpBuffer buf, GTM_Conn* conn); +extern int gtmpqPuts(const char* s, GTM_Conn* conn); +extern int gtmpqGetnchar(char* s, size_t len, GTM_Conn* conn); +extern int gtmpqPutnchar(const char* s, size_t len, GTM_Conn* conn); +extern int gtmpqGetInt(int* result, size_t bytes, GTM_Conn* conn); +extern int64 gtmpqGetInt64(uint64* result, GTM_Conn* conn); +extern int gtmpqPutInt(int value, size_t bytes, GTM_Conn* conn); +extern int gtmpqPutInt64(uint64 value, GTM_Conn* conn); +extern int gtmpqPutMsgStart(char msg_type, bool force_len, GTM_Conn* conn); +extern int gtmpqPutMsgEnd(GTM_Conn* conn); +extern int gtmpqReadData(GTM_Conn* conn); +extern int gtmpqFlush(GTM_Conn* conn); +extern int gtmpqWait(int forRead, int forWrite, GTM_Conn* conn); +extern int gtmpqWaitTimed(int forRead, int forWrite, GTM_Conn* conn, time_t finish_time); +extern int gtmpqReadReady(GTM_Conn* conn); +extern int gtmpqWriteReady(GTM_Conn* conn); + +/* + * In fe-protocol.c + */ +GTM_Result* GTMPQgetResult(GTM_Conn* conn); +extern int gtmpqGetError(GTM_Conn* conn, GTM_Result* result); +void gtmpqFreeResultData(GTM_Result* result, GTM_PGXCNodeType remote_type); + +// In gtmctl-protocol.c +GTM_Result* GTMCTLPQgetResult(GTM_Conn* conn); +int gtmpqPutMsgBytes(const void* buf, size_t len, GTM_Conn* conn); + +#define SOCK_ERRNO errno +#define SOCK_ERRNO_SET(e) (errno = (e)) + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/memnodes.h postgresql-hll-2.14/include/gtm/utils/memnodes.h --- postgresql-hll-2.14_old/include/gtm/utils/memnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/memnodes.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * memnodes.h + * POSTGRES memory context node definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.34 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMNODES_H +#define MEMNODES_H + +#include "gtm/gtm_lock.h" + +/* + * MemoryContext + * A logical context in which memory allocations occur. + * + * MemoryContext itself is an abstract type that can have multiple + * implementations, though for now we have only AllocSetContext. + * The function pointers in MemoryContextMethods define one specific + * implementation of MemoryContext --- they are a virtual function table + * in C++ terms. + * + * Note: for largely historical reasons, typedef MemoryContext is a pointer + * to the context struct rather than the struct type itself. + */ + +typedef struct MemoryContextMethods { + void* (*alloc)(MemoryContext context, Size size); + /* call this free_p in case someone #define's free() */ + void (*free_p)(MemoryContext context, void* pointer); + void* (*realloc)(MemoryContext context, void* pointer, Size size); + void (*init)(MemoryContext context); + void (*reset)(MemoryContext context); + void (*delete_context)(MemoryContext context); + Size (*get_chunk_space)(MemoryContext context, void* pointer); + bool (*is_empty)(MemoryContext context); + void (*stats)(MemoryContext context, int level); +#ifdef MEMORY_CONTEXT_CHECKING + void (*check)(MemoryContext context); +#endif +} MemoryContextMethods; + +typedef struct MemoryContextData { + MemoryContextMethods* methods; /* virtual function table */ + MemoryContext parent; /* NULL if no parent (toplevel context) */ + MemoryContext firstchild; /* head of linked list of children */ + MemoryContext nextchild; /* next child of same parent */ + char* name; /* context name (just for debugging) */ + bool is_shared; /* context is shared by threads */ + GTM_RWLock lock; /* lock to protect members if the context is shared */ +} MemoryContextData; + +#define MemoryContextIsShared(context) (((MemoryContextData*)(context))->is_shared) + +#define MemoryContextLock(context) (GTM_RWLockAcquire(&((MemoryContextData*)(context))->lock, GTM_LOCKMODE_WRITE)) +#define MemoryContextUnlock(context) (GTM_RWLockRelease(&((MemoryContextData*)(context))->lock)) +/* + * MemoryContextIsValid + * True iff memory context is valid. + * + * Add new context types to the set accepted by this macro. + */ +#define MemoryContextIsValid(context) ((context) != NULL) + +#endif /* MEMNODES_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/memutils.h postgresql-hll-2.14/include/gtm/utils/memutils.h --- postgresql-hll-2.14_old/include/gtm/utils/memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/memutils.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,121 @@ +/* ------------------------------------------------------------------------- + * + * memutils.h + * This file contains declarations for memory allocation utility + * functions. These are functions that are not quite widely used + * enough to justify going in utils/palloc.h, but are still part + * of the API of the memory management subsystem. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.64 2008/01/01 19:45:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMUTILS_H +#define MEMUTILS_H + +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/utils/memnodes.h" + +enum GTMMemoryContextType { + STANDARD_CONTEXT /* postgres orignal context */ + , + SHARED_CONTEXT /* shared context used by different threads */ +}; + +/* + * MaxAllocSize + * Quasi-arbitrary limit on size of allocations. + * + * Note: + * There is no guarantee that allocations smaller than MaxAllocSize + * will succeed. Allocation requests larger than MaxAllocSize will + * be summarily denied. + * + * XXX This is deliberately chosen to correspond to the limiting size + * of varlena objects under TOAST. See VARATT_MASK_SIZE in postgres.h. + * + * XXX Also, various places in aset.c assume they can compute twice an + * allocation's size without overflow, so beware of raising this. + */ +#define MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define AllocSizeIsValid(size) ((Size)(size) <= MaxAllocSize) + +/* + * All chunks allocated by any memory context manager are required to be + * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. + * A currently-allocated chunk must contain a backpointer to its owning + * context as well as the allocated size of the chunk. The backpointer is + * used by pfree() and repalloc() to find the context to call. The allocated + * size is not absolutely essential, but it's expected to be needed by any + * reasonable implementation. + */ +typedef struct StandardChunkHeader { + MemoryContext context; /* owning context */ + Size size; /* size of data space allocated in chunk */ +#ifdef MEMORY_CONTEXT_CHECKING + /* when debugging memory usage, also store actual requested size */ + Size requested_size; +#endif +} StandardChunkHeader; + +#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader)) + +/* + * Memory-context-type-independent functions in mcxt.c + */ +extern void MemoryContextInit(void); +extern void MemoryContextReset(MemoryContext context); +extern void MemoryContextDelete(MemoryContext context); +extern void MemoryContextResetChildren(MemoryContext context); +extern void MemoryContextDeleteChildren(MemoryContext context); +extern void MemoryContextResetAndDeleteChildren(MemoryContext context); +extern Size GetMemoryChunkSpace(void* pointer); +extern MemoryContext GetMemoryChunkContext(void* pointer); +extern bool MemoryContextIsEmpty(MemoryContext context); +extern void MemoryContextStats(MemoryContext context); + +#ifdef MEMORY_CONTEXT_CHECKING +extern void MemoryContextCheck(MemoryContext context); +#endif +extern bool MemoryContextContains(MemoryContext context, void* pointer); + +/* + * This routine handles the context-type-independent part of memory + * context creation. It's intended to be called from context-type- + * specific creation routines, and noplace else. + */ +extern MemoryContext MemoryContextCreate( + Size size, MemoryContextMethods* methods, MemoryContext parent, const char* name); + +/* + * Memory-context-type-specific functions + */ + +/* aset.c */ +extern MemoryContext AllocSetContextCreate( + MemoryContext parent, const char* name, Size minContextSize, Size initBlockSize, Size maxBlockSize, bool isShared); + +/* + * Recommended default alloc parameters, suitable for "ordinary" contexts + * that might hold quite a lot of data. + */ +#define ALLOCSET_DEFAULT_MINSIZE 0 +#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024) +#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024) + +/* + * Recommended alloc parameters for "small" contexts that are not expected + * to contain much data (for example, a context to contain a query plan). + */ +#define ALLOCSET_SMALL_MINSIZE 0 +#define ALLOCSET_SMALL_INITSIZE (1 * 1024) +#define ALLOCSET_SMALL_MAXSIZE (8 * 1024) + +#endif /* MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/palloc.h postgresql-hll-2.14/include/gtm/utils/palloc.h --- postgresql-hll-2.14_old/include/gtm/utils/palloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/palloc.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------------- + * + * palloc.h + * POSTGRES memory allocator definitions. + * + * This file contains the basic memory allocation interface that is + * needed by almost every backend module. It is included directly by + * postgres.h, so the definitions here are automatically available + * everywhere. Keep it lean! + * + * Memory allocation occurs within "contexts". Every chunk obtained from + * palloc()/MemoryContextAlloc() is allocated within a specific context. + * The entire contents of a context can be freed easily and quickly by + * resetting or deleting the context --- this is both faster and less + * prone to memory-leakage bugs than releasing chunks individually. + * We organize contexts into context trees to allow fine-grain control + * over chunk lifetime while preserving the certainty that we will free + * everything that should be freed. See utils/mmgr/README for more info. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.40 2008/06/28 16:45:22 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PALLOC_H +#define PALLOC_H + +/* + * Flags for MemoryContextAllocExtended. + */ +#define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +/* + * Type MemoryContextData is declared in nodes/memnodes.h. Most users + * of memory allocation should just treat it as an abstract type, so we + * do not provide the struct contents here. + */ +typedef struct MemoryContextData* MemoryContext; + +/* + * Fundamental memory-allocation operations (more are in utils/memutils.h) + */ +extern void* MemoryContextAlloc(MemoryContext context, Size size); +extern void* MemoryContextAllocZero(MemoryContext context, Size size); +extern void* MemoryContextAllocZeroAligned(MemoryContext context, Size size); + +#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz)) + +#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz)) + +/* + * The result of palloc() is always word-aligned, so we can skip testing + * alignment of the pointer when deciding which MemSet variant to use. + * Note that this variant does not offer any advantage, and should not be + * used, unless its "sz" argument is a compile-time constant; therefore, the + * issue that it evaluates the argument multiple times isn't a problem in + * practice. + */ +#define palloc0fast(sz) \ + (MemSetTest(0, sz) ? MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) \ + : MemoryContextAllocZero(CurrentMemoryContext, sz)) + +extern void pfree(void* pointer); + +extern void* repalloc(void* pointer, Size size); + +/* + * MemoryContextSwitchTo can't be a macro in standard C compilers. + * But we can make it an inline function when using GCC. + */ + +extern MemoryContext MemoryContextSwitchTo(MemoryContext context); + +/* + * These are like standard strdup() except the copied string is + * allocated in a context, not with malloc(). + */ +extern char* MemoryContextStrdup(MemoryContext context, const char* string); + +#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str)) + +extern char* pnstrdup(const char* in, Size len); + +#if defined(WIN32) || defined(__CYGWIN__) +extern void* pgport_palloc(Size sz); +extern char* pgport_pstrdup(const char* str); +extern void pgport_pfree(void* pointer); +#endif + +#ifdef PGXC +/* + * The following part provides common palloc binary interface. This + * is needed especially for gtm_serialize.c and gtm_serialize_debug.c. + */ +#include "gen_alloc.h" +#endif + +#endif /* PALLOC_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/path.h postgresql-hll-2.14/include/gtm/utils/path.h --- postgresql-hll-2.14_old/include/gtm/utils/path.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/path.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * path.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _PATH_H +#define _PATH_H + +#include "gtm/gtm_c.h" + +extern void canonicalize_path(char* path); +extern char* make_absolute_path(const char* path); +extern void get_parent_directory(char* path); +extern void join_path_components(char* ret_path, const char* head, const char* tail); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/utils/pqcomm.h postgresql-hll-2.14/include/gtm/utils/pqcomm.h --- postgresql-hll-2.14_old/include/gtm/utils/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/pqcomm.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqcomm.h,v 1.109 2008/10/28 12:10:44 mha Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQCOMM_H +#define PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} SockAddr; + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 +/* These are the authentication request codes sent by gtm server. */ +#define GTM_AUTH_REQ_OK 0 /* User is authenticated */ +#define GTM_AUTH_REQ_GSS 1 /* GSSAPI without wrap() */ +#define GTM_AUTH_REQ_GSS_CONT 2 /* Continue GSS exchange */ + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/pqexpbuffer.h postgresql-hll-2.14/include/gtm/utils/pqexpbuffer.h --- postgresql-hll-2.14_old/include/gtm/utils/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/pqexpbuffer.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/pqexpbuffer.h,v 1.21 2008/11/26 16:23:11 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H + +/* ------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + * ------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/* ------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + * ------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/* ------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + * ------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/* ------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + * ------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/* ------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createGTMPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initGTMPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + * ------------------------- + */ + +/* ------------------------ + * createGTMPQExpBuffer + * Create an empty 'PQExpBufferData' & return a pointer to it. + */ +extern PQExpBuffer createGTMPQExpBuffer(void); + +/* ------------------------ + * initGTMPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyGTMPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createGTMPQExpBuffer(). + * + * termGTMPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initGTMPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void destroyGTMPQExpBuffer(PQExpBuffer str); +extern void termGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * resetGTMPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * enlargeGTMPQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargeGTMPQExpBuffer(PQExpBuffer str, size_t needed); + +/* ------------------------ + * printfGTMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetGTMPQExpBuffer() followed by appendGTMPQExpBuffer(). + */ +extern void printfGTMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendGTMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendGTMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendGTMPQExpBufferStr + * Append the given string to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendGTMPQExpBufferStr(PQExpBuffer str, const char* data); + +/* ------------------------ + * appendGTMPQExpBufferChar + * Append a single byte to str. + * Like appendGTMPQExpBuffer(str, "%c", ch) but much faster. + */ +extern void appendGTMPQExpBufferChar(PQExpBuffer str, char ch); + +/* ------------------------ + * appendBinaryGTMPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryGTMPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/pqformat.h postgresql-hll-2.14/include/gtm/utils/pqformat.h --- postgresql-hll-2.14_old/include/gtm/utils/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/pqformat.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqformat.h,v 1.27 2009/01/01 17:23:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "gtm/utils/stringinfo.h" + +extern void pq_beginmessage(StringInfo buf, char msgtype); +extern void pq_sendbyte(StringInfo buf, int byt); +extern void pq_sendbytes(StringInfo buf, const char* data, int datalen); +extern void pq_sendcountedtext(StringInfo buf, const char* str, int slen, bool countincludesself); +extern void pq_sendtext(StringInfo buf, const char* str, int slen); +extern void pq_sendstring(StringInfo buf, const char* str); +extern void pq_send_ascii_string(StringInfo buf, const char* str); +extern void pq_sendint(StringInfo buf, int i, int b); +extern void pq_sendint64(StringInfo buf, int64 i); +extern void pq_sendfloat4(StringInfo buf, float4 f); +extern void pq_sendfloat8(StringInfo buf, float8 f); +extern void pq_endmessage(Port* myport, StringInfo buf); + +extern void pq_puttextmessage(Port* myport, char msgtype, const char* str); +extern void pq_putemptymessage(Port* myport, char msgtype); + +extern int pq_getmsgbyte(StringInfo msg); +extern unsigned int pq_getmsgint(StringInfo msg, int b); +extern int64 pq_getmsgint64(StringInfo msg); +extern float4 pq_getmsgfloat4(StringInfo msg); +extern float8 pq_getmsgfloat8(StringInfo msg); +extern const char* pq_getmsgbytes(StringInfo msg, int datalen); +extern void pq_copymsgbytes(StringInfo msg, char* buf, int datalen); +extern char* pq_getmsgtext(StringInfo msg, int rawbytes, int* nbytes); +extern const char* pq_getmsgstring(StringInfo msg); +extern void pq_getmsgend(StringInfo msg); +extern int pq_getmsgunreadlen(StringInfo msg); + +#endif /* PQFORMAT_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/pqsignal.h postgresql-hll-2.14/include/gtm/utils/pqsignal.h --- postgresql-hll-2.14_old/include/gtm/utils/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/pqsignal.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqsignal.h,v 1.32 2008/01/01 19:45:58 momjian Exp $ + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * ------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +#ifdef HAVE_SIGPROCMASK +extern THR_LOCAL sigset_t UnBlockSig, BlockSig, AuthBlockSig; + +#define PG_SETMASK(mask) pthread_sigmask(SIG_SETMASK, mask, NULL) +#else +extern THR_LOCAL int UnBlockSig, BlockSig, AuthBlockSig; + +#ifndef WIN32 +#define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) +#else +#define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) +int pqsigsetmask(int mask); +#endif +#endif + +typedef void (*pqsigfunc)(int); + +extern void pqinitmask(void); + +extern pqsigfunc pqsignal(int signo, pqsigfunc func); + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/proxy_utils.h postgresql-hll-2.14/include/gtm/utils/proxy_utils.h --- postgresql-hll-2.14_old/include/gtm/utils/proxy_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/proxy_utils.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * proxy_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/proxy_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PROXY_UTILS_H +#define PROXY_UTILS_H + +#include "gtm/utils/libpq-int.h" + +bool gtm_standby_check_communication_error(int*, GTM_Conn*); + +#endif /* PROXY_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/register.h postgresql-hll-2.14/include/gtm/utils/register.h --- postgresql-hll-2.14_old/include/gtm/utils/register.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/register.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * register.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_REGISTER_H +#define GTM_REGISTER_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_list.h" +#include "gtm/utils/stringinfo.h" + +/* + * This structure represents the data that is saved each time a Postgres-XC node + * registered on GTM. + * It contains: + * - Type of the Node: Proxy, Coordinator, Datanode + * - Node number + * - Proxy number: This ID number is set at 0 if node does not go through a Proxy + * or if Node Type is Proxy + * - PostgreSQL port the node uses to communicate + * - IP visible to GTM + * - Data folder of the node + */ + +typedef enum GTM_PGXCNodeStatus { NODE_CONNECTED, NODE_DISCONNECTED } GTM_PGXCNodeStatus; + +typedef struct GTM_PGXCNodeInfo { + GTM_PGXCNodeType type; /* Type of node */ + char* nodename; /* Node Name */ + char* proxyname; /* Proxy name the node goes through */ + GTM_PGXCNodePort port; /* Port number of the node */ + char* ipaddress; /* IP address of the nodes */ + char* datafolder; /* Data folder of the node */ + GTM_PGXCNodeStatus status; /* Node status */ + GTM_RWLock node_lock; /* Lock on this structure */ + int socket; /* socket number used for registration */ + uint32 timeline; /* Timeline for node (restart times) */ +} GTM_PGXCNodeInfo; + +/* Maximum number of nodes that can be registered */ +#define MAX_NODES 1024 + +size_t pgxcnode_find_by_type(GTM_PGXCNodeType type, GTM_PGXCNodeInfo** data, size_t maxlen); + +int Recovery_PGXCNodeRegister(GTM_PGXCNodeType type, char* nodename, GTM_PGXCNodePort port, char* proxyname, + GTM_PGXCNodeStatus status, char* ipaddress, char* datafolder, bool in_recovery, int socket, uint32 timeline); +int Recovery_PGXCNodeUnregister(GTM_PGXCNodeType type, const char* node_name, bool in_recovery, int socket); +int Recovery_PGXCNodeBackendDisconnect(GTM_PGXCNodeType type, const char* nodename, int socket); + +void Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo* nodeinfo, bool is_register); +void Recovery_SaveRegisterInfo(void); +void Recovery_PGXCNodeDisconnect(Port* myport); +void Recovery_SaveRegisterFileName(const char* dir); + +void ProcessPGXCNodeRegister(Port* myport, StringInfo message, bool is_backup); +void ProcessPGXCNodeUnregister(Port* myport, StringInfo message, bool is_backup); +void ProcessPGXCNodeBackendDisconnect(Port* myport, StringInfo message); +void ProcessPGXCNodeList(Port* myport, StringInfo message); + +void ProcessGTMBeginBackup(Port* myport, StringInfo message); +void ProcessGTMEndBackup(Port* myport, StringInfo message); + +void RemoveGTMNodes(void); +char* Recovery_GetRegisterFileName(void); +void Recovery_RegisterFileLock(void); + +#endif /* GTM_NODE_H */ diff -uprN postgresql-hll-2.14_old/include/gtm/utils/standby_utils.h postgresql-hll-2.14/include/gtm/utils/standby_utils.h --- postgresql-hll-2.14_old/include/gtm/utils/standby_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/standby_utils.h 2020-12-12 17:06:43.129346516 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * standby_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/standby_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef STANDBY_UTILS_H +#define STANDBY_UTILS_H + +#include "gtm/gtm_c.h" + +bool Recovery_IsPrimary(void); +bool Recovery_IsStandby(void); +bool Recovery_IsPending(void); +bool Recovery_InProgress(void); +GTMServerMode Recovery_Mode(void); + +void Recovery_StandbySetStandby(GTMServerMode mode); +void Recovery_InitStandbyLock(void); +void Recovery_SetPosition(int HA, int local); +void Recovery_GetPosition(int* HA, int* local); + +#endif diff -uprN postgresql-hll-2.14_old/include/gtm/utils/stringinfo.h postgresql-hll-2.14/include/gtm/utils/stringinfo.h --- postgresql-hll-2.14_old/include/gtm/utils/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/gtm/utils/stringinfo.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,157 @@ +/* ------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.35 2008/01/01 19:45:57 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef STRINGINFO_H +#define STRINGINFO_H + +/* ------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + * ------------------------- + */ +typedef struct StringInfoData { + char* data; + int len; + int maxlen; + int cursor; +} StringInfoData; + +typedef StringInfoData* StringInfo; + +/* ------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + * ------------------------- + */ + +/* ------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern StringInfo makeStringInfo(void); + +/* ------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initStringInfo(StringInfo str); + +/* ------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void resetStringInfo(StringInfo str); + +/* ------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendStringInfo(StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool appendStringInfoVA(StringInfo str, const char* fmt, va_list args) __attribute__((format(printf, 2, 0))); + +/* ------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void appendStringInfoString(StringInfo str, const char* s); + +/* ------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void appendStringInfoChar(StringInfo str, char ch); + +/* ------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/* ------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void appendBinaryStringInfo(StringInfo str, const char* data, int datalen); + +/* ------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern void enlargeStringInfo(StringInfo str, int needed); + +/* ----------------------- + * dupStringInfo + * Get new StringInfo and copy the original to it. + */ +extern StringInfo dupStringInfo(StringInfo orig); + +/* ------------------------ + * copyStringInfo + * Copy StringInfo. Deep copy: Data will be copied too. + * cursor of "to" will be initialized to zero. + */ +extern void copyStringInfo(StringInfo to, StringInfo from); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/hotpatch/hotpatch_backend.h postgresql-hll-2.14/include/hotpatch/hotpatch_backend.h --- postgresql-hll-2.14_old/include/hotpatch/hotpatch_backend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/hotpatch/hotpatch_backend.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_backend.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_backend.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_BACKEND_H +#define HOTPATCH_BACKEND_H + +typedef struct knl_hotpatch_context { + bool under_patching; +} knl_hotpatch_context_t; + +void check_and_process_hotpatch(void); +int hotpatch_remove_signal_file(const char* data_dir); +#endif diff -uprN postgresql-hll-2.14_old/include/hotpatch/hotpatch_client.h postgresql-hll-2.14/include/hotpatch/hotpatch_client.h --- postgresql-hll-2.14_old/include/hotpatch/hotpatch_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/hotpatch/hotpatch_client.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_client.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_CLIENT_H +#define HOTPATCH_CLIENT_H + +const int g_millisecond = 1000; +const int g_hotpatch_wait_counter = 2000; + +typedef void (*LogFunc)(const char*, ...) __attribute__((format(printf, 1, 2))); + +void hotpatch_patch_state_to_string(unsigned int state, char* state_string, int length_state_string); +extern int hotpatch_check(const char* path, const char* command, bool* is_list); +extern void hotpatch_process_list(const char* return_string, int string_length, const char* data_dir, size_t dir_length, + void (*canonicalize_path)(char*), LogFunc log_func); +#endif diff -uprN postgresql-hll-2.14_old/include/hotpatch/hotpatch.h postgresql-hll-2.14/include/hotpatch/hotpatch.h --- postgresql-hll-2.14_old/include/hotpatch/hotpatch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/hotpatch/hotpatch.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,130 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_H +#define HOTPATCH_H + +#define HP_OK (0) +#define HP_ERR (-1) +const int g_max_length_time = 64; +const int g_max_length_act = 16; +const int g_max_length_path = 512; +const int g_max_length_std_path = 4096; +const int g_first_err = 0x1000; +const int g_lock_file_size = 1024; +const int g_length_statstr = 50; +const int g_max_number_patch = 1000; +const int g_length_okstr = 15; +const int g_length_list = 4; +const int g_max_length_line = 128; +const int g_rev_bytes_info = 3; + +#define MAX_LENGTH_RETURN_STRING (1024) + +typedef enum HP_STATE { + HP_STATE_UNKNOW, + HP_STATE_UNLOAD, + HP_STATE_DEACTIVE, + HP_STATE_ACTIVED, +} HP_STATE_T; + +typedef enum HP_ERROR_CODE { + HP_ERROR_NAME_NUMBER = g_first_err, + HP_ERROR_INSUFFICIENT_MEM, + HP_ERROR_SUFFIX_INCORRECT, + HP_ERROR_UNKNOWN_NAME, + HP_ERROR_EMPTY_NAME, + HP_ERROR_EMPTY_COMMAND, + HP_ERROR_LOADED_BEFORE, + HP_ERROR_CANNOT_UNLOAD, + HP_ERROR_CANNOT_ACTIVE, + HP_ERROR_CANNOT_DEACTIVE, + HP_ERROR_RANGE, + HP_ERROR_NO_PATCH_LOADED, + HP_ERROR_EMPTY_PARAMETER, + HP_ERROR_INITED_BEFORE, + HP_ERROR_LIB_INIT_ERROR, + HP_ERROR_NOT_INIT, + HP_ERROR_UNKNOWN_ACTION, + HP_ERROR_FETCH_ERROR, + HP_ERROR_VERSION, + HP_ERROR_GTM_UNCONNECTED, + HP_ERROR_GTM_START_ERROR, + HP_ERROR_GTM_SEND_ERROR, + HP_ERROR_GTM_SEND_END_ERROR, + HP_ERROR_GTM_FLUSH_ERROR, + HP_ERROR_GTM_RECEIVE_ERROR, + HP_ERROR_OPERATION_LOG_ERR, + HP_ERROR_COMMUNICATION_ERR, + HP_ERROR_UNDER_PATCHING, + HP_ERROR_SYSTEM_ERROR, + HP_ERROR_FILE_SEEK_ERROR, + HP_ERROR_FILE_WRITE_ERROR, + HP_ERROR_FILE_READ_ERROR, + HP_ERROR_FILE_OPEN_ERROR, + HP_ERROR_FILE_SYNC_ERROR, + HP_ERROR_FILE_LOCK_ERROR, + HP_ERROR_FILE_RENAME_ERROR, + HP_ERROR_FILE_PATH_ERROR, + HP_ERROR_PATCH_NUMBER_ERROR, + HP_ERROR_PATCH_INFO_ERROR, + HP_ERROR_CM_DATADIR_NULL, + HP_ERROR_REG_LOG_CALLBACK_ERROR, + HP_ERROR_REG_PAGESIZE_CALLBACK_ERROR, + HP_ERROR_COMMON_ERROR_MAX, +} HP_ERROR_CODE_T; + +typedef enum HP_INFO_STATE { + HP_INFO_NOT_EXIST, + HP_INFO_EXIST, + HP_INFO_NEED_RFRESH, +} HP_INFO_STATE_T; + +typedef struct PATCH_LOG { + char time_stamp[g_max_length_time]; + char operation[g_max_length_act]; + char patch_name[g_max_length_path]; + char rev[16]; +} PATCH_LOG_T; + +typedef struct PATCH_INFO_HEADER { + int max_patch_number; // record how many patchs has been loaded + int rev; +} PATCH_INFO_HEADER_T; + +typedef struct PATCH_INFO { + int patch_number; + char patch_state; + char rev[g_rev_bytes_info]; + char patch_name[g_max_length_path]; +} PATCH_INFO_T; + +typedef void (*HOTPATCH_LOG_FUNC)(unsigned int level, const char* fmt); + +extern int hotpatch_init(const char* default_dir, HOTPATCH_LOG_FUNC log_func); +extern int exec_hotpatch_command(const char* filename, const char* action, char* output_string, size_t string_length); +void patch_err_info_handler(int error_code, char* out_string, size_t string_length); +char* strip_path_from_pathname(const char* name_withpath); +#endif diff -uprN postgresql-hll-2.14_old/include/hotpatch/hotpatch_inner.h postgresql-hll-2.14/include/hotpatch/hotpatch_inner.h --- postgresql-hll-2.14_old/include/hotpatch/hotpatch_inner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/hotpatch/hotpatch_inner.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_inner.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_inner.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_INNER_H +#define HOTPATCH_INNER_H + +#define hp_check_intval(errno, express, file, line) \ + do { \ + if (errno < 0) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.errno is 0x%x\n", \ + file, \ + line, \ + errno); \ + express; \ + } \ + } while (0) + +#define securec_check_hp(errno, express) hp_check_intval(errno, express, __FILE__, __LINE__) + +typedef enum TIME_USAGE { + TIME_STRING_FOR_FILE_NAME, + TIME_STRING_FOR_DISPLAY, +} TIME_USAGE_T; +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/attnum.h postgresql-hll-2.14/include/include/access/attnum.h --- postgresql-hll-2.14_old/include/include/access/attnum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/attnum.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * attnum.h + * POSTGRES attribute number definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/attnum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATTNUM_H +#define ATTNUM_H + +#include "c.h" + +/* + * user defined attribute numbers start at 1. -ay 2/95 + */ +typedef int16 AttrNumber; + +#define InvalidAttrNumber 0 +#define MaxAttrNumber 32767 + +/* ---------------- + * support macros + * ---------------- + */ +/* + * AttributeNumberIsValid + * True iff the attribute number is valid. + */ +#define AttributeNumberIsValid(attributeNumber) ((bool)((attributeNumber) != InvalidAttrNumber)) + +/* + * AttrNumberIsForUserDefinedAttr + * True iff the attribute number corresponds to an user defined attribute. + */ +#define AttrNumberIsForUserDefinedAttr(attributeNumber) ((bool)((attributeNumber) > 0)) + +/* + * AttrNumberGetAttrOffset + * Returns the attribute offset for an attribute number. + * + * Note: + * Assumes the attribute number is for an user defined attribute. + */ +#define AttrNumberGetAttrOffset(attNum) (AssertMacro(AttrNumberIsForUserDefinedAttr(attNum)), ((attNum)-1)) + +/* + * AttributeOffsetGetAttributeNumber + * Returns the attribute number for an attribute offset. + */ +#define AttrOffsetGetAttrNumber(attributeOffset) ((AttrNumber)(1 + (attributeOffset))) + +#endif /* ATTNUM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/cbmparsexlog.h postgresql-hll-2.14/include/include/access/cbmparsexlog.h --- postgresql-hll-2.14_old/include/include/access/cbmparsexlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cbmparsexlog.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,289 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbmparsexlog.h + * Definitions for cbm-parsing-xlog facility + * + * + * IDENTIFICATION + * src/include/access/cbmparsexlog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CBMPARSEXLOG_H +#define CBMPARSEXLOG_H + +#include "access/xlogrecord.h" +#include "c.h" +#include "lib/dllist.h" +#include "port/pg_crc32c.h" +#include "securec_check.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/hsearch.h" + +/* Struct for single bitmap file information */ +typedef struct BitmapFileStruct { + char name[MAXPGPATH]; /* Name with full path */ + int fd; /* Handle to opened file */ + uint64 size; /* Size of the file */ + off_t offset; /* Offset of the next read */ +} BitmapFile; + +#define CBMDIR "pg_cbm/" +#define MAX_CBM_FILENAME_LENGTH 66 + +/* CBM xlog read structure */ +typedef struct CBMXlogReadStruct { + int fd; + XLogSegNo logSegNo; + char filePath[MAXPGPATH]; +} CBMXlogRead; + +/* Xlog parsing and bitmap output data structure */ +typedef struct XlogBitmapStruct { + char cbmFileHome[MAXPGPATH]; /* directory for bitmap files */ + BitmapFile out; /* The current bitmap file */ + uint64 outSeqNum; /* the bitmap file sequence number */ + XLogRecPtr startLSN; /* the LSN of the next unparsed + record and the start of the next LSN + interval to be parsed. */ + XLogRecPtr endLSN; /* the end of the LSN interval to be + parsed, equal to the next checkpoint + LSN at the time of parse */ + HTAB* cbmPageHash; /* the current modified page set, + organized as htab with the keys of + (rNode, forkNum) pairs */ + Dllist pageFreeList; /* doublely-linked list of freed CBM pages */ + uint64 totalPageNum; /* total cbm page number during one parse cycle */ + CBMXlogRead xlogRead; /* file information of xlog files to be parsed */ + bool xlogParseFailed; /* true if failed during last xlog parse */ + bool needReset; /* true if failed during last CBMFollowXlog */ + bool firstCPCreated; /* if first checkpoint has been created after recovery */ +} XlogBitmap; + +typedef struct cbmpageheader { + pg_crc32c pageCrc; + bool isLastBlock; + uint8 pageType; + XLogRecPtr pageStartLsn; + XLogRecPtr pageEndLsn; + RelFileNode rNode; + ForkNumber forkNum; + BlockNumber firstBlkNo; + BlockNumber truncBlkNo; +} CbmPageHeader; + +typedef struct XLogPageReadPrivateCbm { + const char* datadir; + TimeLineID tli; +} XLogPageReadPrivateCBM; + +#define PAGETYPE_DROP 0x04 +#define PAGETYPE_CREATE 0x02 +#define PAGETYPE_TRUNCATE 0x01 +#define PAGETYPE_MODIFY 0x00 + +/* a segment of data file shared a list */ +#define BLOCK_NUM_PER_CBMLIST 131072 + +#define GET_SEG_INDEX_FROM_BLOCK_NUM(block_num) ((block_num)/(BLOCK_NUM_PER_CBMLIST)) + +/* Max size of each bitmap file, in bytes. */ +#define MAXCBMFILESIZE (128 * 1024 * 1024) + +/* Size of the bitmap page, in bytes. */ +#define CBMPAGESIZE 512 + +/* Size of the bitmap on each cbm map page, in bytes. */ +#define CBMMAPSIZE (CBMPAGESIZE - MAXALIGN(sizeof(CbmPageHeader))) + +/* Max total size of all reserved free pages, in bytes. */ +#define MAXCBMFREEPAGESIZE (64 * 1024 * 1024) + +/* Max total number of all reserved free pages. */ +#define MAXCBMFREEPAGENUM (MAXCBMFREEPAGESIZE / CBMPAGESIZE) + +/* Number of bits allocated for each heap block. */ +#define CBM_BITS_PER_BLOCK 1 + +/* Number of heap blocks we can represent in one byte. */ +#define CBM_BLOCKS_PER_BYTE 8 + +/* Number of blocks we can represent in one cbm map page. */ +#define CBM_BLOCKS_PER_PAGE (CBMMAPSIZE * CBM_BLOCKS_PER_BYTE) + +#define BLKNO_TO_CBM_PAGEFIRSTBOCK(x) (BlockNumberIsValid(x) ? ((x) - ((x) % CBM_BLOCKS_PER_PAGE)) : InvalidBlockNumber) +#define BLKNO_TO_CBMBYTEOFPAGE(x) (((x) % CBM_BLOCKS_PER_PAGE) / CBM_BLOCKS_PER_BYTE) +#define BLKNO_TO_CBMBITOFBYTE(x) ((x) % CBM_BLOCKS_PER_BYTE) + +#define CBM_PAGE_NOT_CHANGED 0 +#define CBM_PAGE_CHANGED ((uint32)1) + +#define CBM_PAGE_BITMASK ((uint32)1) + +#define SET_CBM_PAGE_BITMAP(byte, bit, status) \ + do { \ + char byteval = byte; \ + byteval &= ~(CBM_PAGE_BITMASK << bit); \ + byteval |= (status << bit); \ + byte = byteval; \ + } while (0) + +#define CLEAR_CBM_PAGE_BITMAP(byte, bit) (byte) &= ~(CBM_PAGE_BITMASK << (bit)) + +#define CBM_BLOCKNO_CMP(a, b) \ + ((a) == (b) ? 0 : ((a) == InvalidBlockNumber ? -1 : ((b) == InvalidBlockNumber ? 1 : ((a) < (b) ? -1 : 1)))) + +/* + * Note: if there are any pad bytes in the struct, INIT_CBMPAGETAG have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct cbmpagetag { + RelFileNode rNode; + ForkNumber forkNum; +} CBMPageTag; + +#define INIT_CBMPAGETAG(a, xx_rnode, xx_forkNum) ((a).rNode = (xx_rnode), (a).forkNum = (xx_forkNum)) + +#define InvalidRelFileNode ((RelFileNode){0, 0, 0, -1}) + +#define INIT_DUMMYCBMPAGETAG(a) ((a).rNode = InvalidRelFileNode, (a).forkNum = InvalidForkNumber) + +#define CBMPAGETAG_EQUAL(a, b) (RelFileNodeEquals((a).rNode, (b).rNode) && (a).forkNum == (b).forkNum) + +typedef struct cbmhashentry { + CBMPageTag cbmTag; + Dllist cbmSegPageList; + int pageNum; +} CbmHashEntry; + +typedef struct cbmsegpagelist { + int segIndex; + Dllist pageDllist; +} CbmSegPageList; + +#define INIT_CBMPAGEENTRY(a) \ + do { \ + (a)->pageNum = 0; \ + DLInitList(&((a)->cbmSegPageList)); \ + } while (0) + +#define INIT_CBMPAGEHEADER(a, xx_pagetag, xx_firstblkno) \ + ((a)->rNode = (xx_pagetag.rNode), \ + (a)->forkNum = (xx_pagetag.forkNum), \ + (a)->firstBlkNo = (xx_firstblkno), \ + (a)->pageType = PAGETYPE_MODIFY, \ + (a)->truncBlkNo = InvalidBlockNumber) + +#define CBM_PAGE_IS_DUMMY(a) ((RelFileNodeEquals((a)->rNode, InvalidRelFileNode)) && ((a)->forkNum == InvalidForkNumber)) + +#define INITCBMPAGEHASHSIZE 400 + +/* Struct for cbm filename information */ +typedef struct cbmfilename { + char* name; /* file name pointer */ + uint64 seqNum; /* file sequence number */ + XLogRecPtr startLSN; /* file start lsn */ + XLogRecPtr endLSN; /* file end lsn */ +} CbmFileName; + +#define INIT_CBMFILENAME(a, xx_name, xx_seqnum, xx_startlsn, xx_endlsn) \ + do { \ + (a)->name = pstrdup(xx_name); \ + (a)->seqNum = xx_seqnum; \ + (a)->startLSN = xx_startlsn; \ + (a)->endLSN = xx_endlsn; \ + } while (0) + +typedef struct cbmpageiterator { + FILE* file; + off_t readOffset; + char* buffer; + XLogRecPtr pageStartLsn; + XLogRecPtr pageEndLsn; + bool isLastBlock; + bool checksumOk; + XLogRecPtr prevStartLsn; + XLogRecPtr prevEndLsn; + bool isPrevLastBlock; +} cbmPageIterator; + +#define INIT_CBMPAGEITERATOR(a, xx_file, xx_buffer) \ + ((a).file = (xx_file), \ + (a).readOffset = (off_t)0, \ + (a).buffer = (xx_buffer), \ + (a).pageStartLsn = InvalidXLogRecPtr, \ + (a).pageEndLsn = InvalidXLogRecPtr, \ + (a).checksumOk = false, \ + (a).isLastBlock = false, \ + (a).prevStartLsn = InvalidXLogRecPtr, \ + (a).prevEndLsn = InvalidXLogRecPtr, \ + (a).isPrevLastBlock = false) + +typedef struct cbmarrayentry { + CBMPageTag cbmTag; + uint8 changeType; + BlockNumber truncBlockNum; + uint32 totalBlockNum; + uint32 maxSize; + BlockNumber* changedBlock; +} CBMArrayEntry; + +#define INIT_CBMARRAYENTRY(a, xx_cbmTag) \ + do { \ + (a)->cbmTag = (xx_cbmTag); \ + (a)->changeType = PAGETYPE_MODIFY; \ + (a)->truncBlockNum = InvalidBlockNumber; \ + (a)->totalBlockNum = 0; \ + InitCBMArrayEntryBlockArray(a); \ + } while (0) + +typedef struct cbmarray { + XLogRecPtr startLSN; + XLogRecPtr endLSN; + long arrayLength; + CBMArrayEntry* arrayEntry; +} CBMArray; + +#define INITBLOCKARRAYSIZE 16 + +typedef struct cbmbitmapiterator { + char* bitmap; + BlockNumber nextBlkNo; + BlockNumber startBlkNo; + BlockNumber endBlkNo; +} CBMBitmapIterator; + +/* for block number printed in tuple */ +#define MAX_STRLEN_PER_BLOCKNO 12 +#define MAX_BLOCKNO_PER_TUPLE ((MaxAllocSize - 1) / MAX_STRLEN_PER_BLOCKNO) + +#define INIT_CBMBITMAPITERATOR(a, xx_bitmap, xx_start, xx_end) \ + ((a).bitmap = (xx_bitmap), (a).nextBlkNo = (xx_start), (a).startBlkNo = (xx_start), (a).endBlkNo = (xx_end)) + +extern void InitXlogCbmSys(void); +extern void CBMTrackInit(bool startupXlog, XLogRecPtr startupCPRedo); +extern void CBMFollowXlog(void); +extern void CBMGetMergedFile(XLogRecPtr startLSN, XLogRecPtr endLSN, char* mergedFileName); +extern CBMArray* CBMGetMergedArray(XLogRecPtr startLSN, XLogRecPtr endLSN); +extern void FreeCBMArray(CBMArray* cbmArray); +extern CBMArray *SplitCBMArray(CBMArray **orgCBMArrayPtr); +extern void CBMRecycleFile(XLogRecPtr targetLSN, XLogRecPtr* endLSN); +extern XLogRecPtr ForceTrackCBMOnce(XLogRecPtr targetLSN, int timeOut, bool wait, bool lockHeld, bool isRecEnd = true); +extern void advanceXlogPtrToNextPageIfNeeded(XLogRecPtr* recPtr); +extern void cbm_rotate_file(XLogRecPtr rotateLsn); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cbtree.h postgresql-hll-2.14/include/include/access/cbtree.h --- postgresql-hll-2.14_old/include/include/access/cbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cbtree.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbtree.h + * + * + * + * IDENTIFICATION + * src/include/access/cbtree.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CTREE_H +#define CTREE_H + +#include "fmgr.h" + +Datum cbtreebuild(PG_FUNCTION_ARGS); +Datum cbtreeoptions(PG_FUNCTION_ARGS); +Datum cbtreegettuple(PG_FUNCTION_ARGS); +Datum cbtreecanreturn(PG_FUNCTION_ARGS); + +#endif /* CBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/clog.h postgresql-hll-2.14/include/include/access/clog.h --- postgresql-hll-2.14_old/include/include/access/clog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/clog.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,106 @@ +/* + * clog.h + * + * PostgreSQL transaction-commit-log manager + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/clog.h + */ +#ifndef CLOG_H +#define CLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* + * Defines for CLOG page sizes. A page is the same BLCKSZ as is used + * everywhere else in Postgres. + * + * Note: because TransactionIds are 32 bits and wrap around at 0xFFFFFFFF, + * CLOG page numbering also wraps around at 0xFFFFFFFF/CLOG_XACTS_PER_PAGE, + * and CLOG segment numbering at + * 0xFFFFFFFF/CLOG_XACTS_PER_PAGE/SLRU_PAGES_PER_SEGMENT. We need take no + * explicit notice of that fact in this module, except when comparing segment + * and page numbers in TruncateCLOG (see CLOGPagePrecedes). + */ + +/* We need two bits per xact, so four xacts fit in a byte */ +#define CLOG_BITS_PER_XACT 2 +#define CLOG_XACTS_PER_BYTE 4 +#define CLOG_XACTS_PER_PAGE (BLCKSZ * CLOG_XACTS_PER_BYTE) +#define CLOG_XACT_BITMASK ((1 << CLOG_BITS_PER_XACT) - 1) + +#define TransactionIdToPage(xid) ((xid) / (TransactionId)CLOG_XACTS_PER_PAGE) +#define TransactionIdToPgIndex(xid) ((xid) % (TransactionId)CLOG_XACTS_PER_PAGE) +#define TransactionIdToByte(xid) (TransactionIdToPgIndex(xid) / CLOG_XACTS_PER_BYTE) +#define TransactionIdToBIndex(xid) ((xid) % (TransactionId)CLOG_XACTS_PER_BYTE) + +#define CLogPageNoToStartXactId(pageno) ((pageno > 0)?((pageno -1) * CLOG_XACTS_PER_PAGE): 0) +/* CLog lwlock partition*/ +#define CBufHashPartition(hashcode) \ + ((hashcode) % NUM_CLOG_PARTITIONS) +#define CBufMappingPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCBufMappingLock + CBufHashPartition(hashcode)].lock) +#define CBufMappingPartitionLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCBufMappingLock + i].lock) + +/* + * Possible transaction statuses --- note that all-zeroes is the initial + * state. + * + */ +typedef int CLogXidStatus; + +#define CLOG_XID_STATUS_IN_PROGRESS 0x00 +#define CLOG_XID_STATUS_COMMITTED 0x01 +#define CLOG_XID_STATUS_ABORTED 0x02 + +/* + * A "subcommitted" transaction is a committed subtransaction whose parent + * hasn't committed or aborted yet. + */ +#define CLOG_XID_STATUS_SUB_COMMITTED 0x03 + +extern void CLogSetTreeStatus( + TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status, XLogRecPtr lsn); +extern CLogXidStatus CLogGetStatus(TransactionId xid, XLogRecPtr* lsn); +extern Size CLOGShmemBuffers(void); +extern Size CLOGShmemSize(void); +extern void CLOGShmemInit(void); +extern void BootStrapCLOG(void); +extern void StartupCLOG(void); +extern void TrimCLOG(void); +extern void ShutdownCLOG(void); +extern void CheckPointCLOG(void); +extern void ExtendCLOG(TransactionId newestXact, bool allowXlog = true); +extern void TruncateCLOG(TransactionId oldestXact); +extern bool IsCLogTruncate(XLogReaderState* record); + +/* XLOG stuff */ +#define CLOG_ZEROPAGE 0x00 +#define CLOG_TRUNCATE 0x10 + +extern void clog_redo(XLogReaderState* record); +extern void clog_desc(StringInfo buf, XLogReaderState* record); + +#ifdef USE_ASSERT_CHECKING + +typedef enum { FIT_CLOG_EXTEND_PAGE = 0, FIT_CLOG_READ_PAGE, FIT_LWLOCK_DEADLOCK, FIT_MAX_TYPE } FIT_type; + +#endif /* FAULT_INJECTION_TEST */ + +#include "fmgr.h" +extern Datum gs_fault_inject(PG_FUNCTION_ARGS); + +#endif /* CLOG_H */ + +#ifdef ENABLE_UT +extern void set_status_by_pages(int nsubxids, TransactionId* subxids, CLogXidStatus status, XLogRecPtr lsn); + +extern void CLogSetPageStatus(TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status, + XLogRecPtr lsn, int64 pageno, bool all_xact_same_page); +extern int FIT_lw_deadlock(int n_edges); +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/csnlog.h postgresql-hll-2.14/include/include/access/csnlog.h --- postgresql-hll-2.14_old/include/include/access/csnlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/csnlog.h 2020-12-12 17:06:43.130346529 +0800 @@ -0,0 +1,40 @@ +/* --------------------------------------------------------------------------------------- + * + * csnlog.h + * Commit-Sequence-Number log. + * + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/csnlog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSNLOG_H +#define CSNLOG_H + +#include "access/xlog.h" + +#define CSNBufHashPartition(hashcode) ((hashcode) % NUM_CSNLOG_PARTITIONS) +#define CSNBufMappingPartitionLock(hashcode) (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCSNBufMappingLock + CSNBufHashPartition(hashcode)].lock) +#define CSNBufMappingPartitionLockByIndex(i) (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstCSNBufMappingLock + i].lock) + +extern void CSNLogSetCommitSeqNo(TransactionId xid, int nsubxids, TransactionId* subxids, CommitSeqNo csn); +extern CommitSeqNo CSNLogGetCommitSeqNo(TransactionId xid); +extern CommitSeqNo CSNLogGetNestCommitSeqNo(TransactionId xid); +extern TransactionId CSNLogGetNextInProgressXid(TransactionId start, TransactionId end); + +extern Size CSNLOGShmemBuffers(void); +extern Size CSNLOGShmemSize(void); +extern void CSNLOGShmemInit(void); +extern void BootStrapCSNLOG(void); +extern void StartupCSNLOG(bool isUpgrade); +extern void TrimCSNLOG(void); +extern void ShutdownCSNLOG(void); +extern void CheckPointCSNLOG(void); +extern void ExtendCSNLOG(TransactionId newestXact); +extern void TruncateCSNLOG(TransactionId oldestXact); + +#endif /* CSNLOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_am.h postgresql-hll-2.14/include/include/access/cstore_am.h --- postgresql-hll-2.14_old/include/include/access/cstore_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_am.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,428 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_am.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_am.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTOREAM_H +#define CSTOREAM_H + +#include "access/cstore_roughcheck_func.h" +#include "access/cstore_minmax_func.h" +#include "cstore.h" +#include "storage/cu.h" +#include "storage/custorage.h" +#include "storage/cucache_mgr.h" +#include "utils/snapshot.h" + +#define MAX_CU_PREFETCH_REQSIZ (64) + +#define MaxDelBitmapSize ((int)DefaultFullCUSize / 8 + 1) + +class BatchCUData; + +// If we load all CUDesc, the memory will be huge, +// So we define this data structure defining the load CUDesc information +// +struct LoadCUDescCtl : public BaseObject { + uint32 curLoadNum; + uint32 lastLoadNum; + uint32 nextCUID; + CUDesc* cuDescArray; + + LoadCUDescCtl(uint32 startCUID) + { + Reset(startCUID); + cuDescArray = (CUDesc*)palloc0(sizeof(CUDesc) * u_sess->attr.attr_storage.max_loaded_cudesc); + } + + virtual ~LoadCUDescCtl() + { + } + + virtual void Destroy() + { + if (cuDescArray != NULL) { + pfree(cuDescArray); + cuDescArray = NULL; + } + } + + inline bool HasFreeSlot() + { + return curLoadNum < (uint32)u_sess->attr.attr_storage.max_loaded_cudesc; + } + + inline void Reset(uint32 startCUID) + { + curLoadNum = 0; + lastLoadNum = 0; + nextCUID = startCUID; + } +}; + +struct CStoreScanState; +typedef CStoreScanState *CStoreScanDesc; + +struct CStoreIndexScanState; + +/* + * CStore include a set of common API for ColStore. + * In future, we can add more API. + */ +class CStore : public BaseObject { + // public static area +public: + // create data files + static void CreateStorage(Relation rel, Oid newRelFileNode = InvalidOid); + + // unlink data files + static void UnlinkColDataFile(const RelFileNode &rnode, AttrNumber attrnum, bool bcmIncluded); + static void InvalidRelSpaceCache(RelFileNode *rnode); + + // trunccate data files which relation CREATE and TRUNCATE in same XACT block + static void TruncateStorageInSameXact(Relation rel); + + // form and deform CU Desc tuple + static HeapTuple FormCudescTuple(_in_ CUDesc *pCudesc, _in_ TupleDesc pCudescTupDesc, + _in_ Datum values[CUDescMaxAttrNum], _in_ bool nulls[CUDescMaxAttrNum], + _in_ Form_pg_attribute pColAttr); + + static void DeformCudescTuple(_in_ HeapTuple pCudescTup, _in_ TupleDesc pCudescTupDesc, + _in_ Form_pg_attribute pColAttr, _out_ CUDesc *pCudesc); + + // Save CU description information into CUDesc table + static void SaveCUDesc(_in_ Relation rel, _in_ CUDesc *cuDescPtr, _in_ int col, _in_ int options); + + // form and deform VC CU Desc tuple. + // We add a virtual column for marking deleted rows. + // The VC is divided into CUs. + static HeapTuple FormVCCUDescTup(_in_ TupleDesc cudesc, _in_ const char *delMask, _in_ uint32 cuId, + _in_ int32 rowCount, _in_ uint32 magic); + + static void SaveVCCUDesc(_in_ Oid cudescOid, _in_ uint32 cuId, _in_ int rowCount, _in_ uint32 magic, + _in_ int options, _in_ const char *delBitmap = NULL); + + static bool IsTheWholeCuDeleted(_in_ char *delBitmap, _in_ int rowsInCu); + bool IsTheWholeCuDeleted(_in_ int rowsInCu); + + // get Min/Max value from given *pCudesc*. + // *min* = true, return the Min value. + // *min* = false, return the Max value. + static Datum CudescTupGetMinMaxDatum(_in_ CUDesc *pCudesc, _in_ Form_pg_attribute pColAttr, _in_ bool min, + _out_ bool *shouldFree); + + static bool SetCudescModeForMinMaxVal(_in_ bool fullNulls, _in_ bool hasMinMaxFunc, _in_ bool hasNull, + _in_ int maxVarStrLen, _in_ int attlen, __inout CUDesc *cuDescPtr); + + static bool SetCudescModeForTheSameVal(_in_ bool fullNulls, _in_ FuncSetMinMax SetMinMaxFunc, _in_ int attlen, + _in_ Datum attVal, __inout CUDesc *cuDescPtr); + + static uint32 GetMaxCUID(_in_ Oid cudescHeap, _in_ TupleDesc cstoreRelTupDesc, _in_ Snapshot snapshotArg = NULL); + static uint32 GetMaxIndexCUID(_in_ Relation heapRel, _in_ List *btreeIndex); + + static CUPointer GetMaxCUPointerFromDesc(_in_ int attrno, _in_ Oid cudescHeap); + + static CUPointer GetMaxCUPointer(_in_ int attrno, _in_ Relation rel); + +public: + CStore(); + virtual ~CStore(); + virtual void Destroy(); + + // Scan APIs + void InitScan(CStoreScanState *state, Snapshot snapshot = NULL); + void InitReScan(); + void InitPartReScan(Relation rel); + bool IsEndScan() const; + + // late read APIs + bool IsLateRead(int id) const; + void ResetLateRead(); + + // update cstore scan timing flag + void SetTiming(CStoreScanState *state); + + // CStore scan : pass vector to VE. + void ScanByTids(_in_ CStoreIndexScanState *state, _in_ VectorBatch *idxOut, _out_ VectorBatch *vbout); + void CStoreScanWithCU(_in_ CStoreScanState *state, BatchCUData *tmpCUData, _in_ bool isVerify = false); + + // Load CUDesc information of column according to loadInfoPtr + // LoadCUDescCtrl include maxCUDescNum for this load, because if we load all + // it need big memory to hold + // + bool LoadCUDesc(_in_ int col, __inout LoadCUDescCtl *loadInfoPtr, _in_ bool prefetch_control, + _in_ Snapshot snapShot = NULL); + + // Get CU description information from CUDesc table + bool GetCUDesc(_in_ int col, _in_ uint32 cuid, _out_ CUDesc *cuDescPtr, _in_ Snapshot snapShot = NULL); + + // Get tuple deleted information from VC CU description. + void GetCUDeleteMaskIfNeed(_in_ uint32 cuid, _in_ Snapshot snapShot); + + bool GetCURowCount(_in_ int col, __inout LoadCUDescCtl *loadCUDescInfoPtr, _in_ Snapshot snapShot); + // Get live row numbers. + int64 GetLivedRowNumbers(int64 *deadrows); + + // Get CU data. + // Note that the CU is pinned + CU *GetCUData(_in_ CUDesc *cuDescPtr, _in_ int colIdx, _in_ int valSize, _out_ int &slotId); + + CU *GetUnCompressCUData(Relation rel, int col, uint32 cuid, _out_ int &slotId, ForkNumber forkNum = MAIN_FORKNUM, + bool enterCache = true) const; + + // Fill Vector APIs + int FillVecBatch(_out_ VectorBatch *vecBatchOut); + + // Fill Vector of column + template + int FillVector(_in_ int colIdx, _in_ CUDesc *cu_desc_ptr, _out_ ScalarVector *vec); + + template + void FillVectorByTids(_in_ int colIdx, _in_ ScalarVector *tids, _out_ ScalarVector *vec); + + template + void FillVectorLateRead(_in_ int seq, _in_ ScalarVector *tids, _in_ CUDesc *cuDescPtr, _out_ ScalarVector *vec); + + void FillVectorByIndex(_in_ int colIdx, _in_ ScalarVector *tids, _in_ ScalarVector *srcVec, + _out_ ScalarVector *destVec); + + // Fill system column into ScalarVector + int FillSysColVector(_in_ int colIdx, _in_ CUDesc *cu_desc_ptr, _out_ ScalarVector *vec); + + template + void FillSysVecByTid(_in_ ScalarVector *tids, _out_ ScalarVector *destVec); + + template + int FillTidForLateRead(_in_ CUDesc *cuDescPtr, _out_ ScalarVector *vec); + + void FillScanBatchLateIfNeed(__inout VectorBatch *vecBatch); + + /* Set CU range for scan in redistribute. */ + void SetScanRange(); + + // Judge whether dead row + bool IsDeadRow(uint32 cuid, uint32 row) const; + + void CUListPrefetch(); + void CUPrefetch(CUDesc *cudesc, int col, AioDispatchCUDesc_t **dList, int &count, File *vfdList); + + /* Point to scan function */ + typedef void (CStore::*ScanFuncPtr)(_in_ CStoreScanState *state, _out_ VectorBatch *vecBatchOut); + void RunScan(_in_ CStoreScanState *state, _out_ VectorBatch *vecBatchOut); + + int GetLateReadCtid() const; + void IncLoadCuDescCursor(); + +public: // public vars + // Inserted/Scan Relation + Relation m_relation; + +private: // private methods. + // CStore scan : pass vector to VE. + void CStoreScan(CStoreScanState *state, VectorBatch *vecBatchOut); + void CStoreMinMaxScan(CStoreScanState *state, VectorBatch *vecBatchOut); + + // The number of holding CUDesc is max_loaded_cudesc + // if we load all CUDesc once, the memory will not enough. + // So we load CUdesc once for max_loaded_cudesc + void LoadCUDescIfNeed(); + + // Do RoughCheck if need + // elimiate CU by min/max value of CU. + void RoughCheckIfNeed(_in_ CStoreScanState *state); + + // Refresh cursor + void RefreshCursor(int row, int deadRows); + + void InitRoughCheckEnv(CStoreScanState *state); + + void BindingFp(CStoreScanState *state); + void InitFillVecEnv(CStoreScanState *state); + + // indicate whether only accessing system column or const column. + // true, means that m_virtualCUDescInfo is a new and single object. + // false, means that m_virtualCUDescInfo just a pointer to m_CUDescInfo[0]. + // + inline bool OnlySysOrConstCol(void) + { + return ((m_colNum == 0 && m_sysColNum != 0) || m_onlyConstCol); + } + + int LoadCudescMinus(int start, int end) const; + bool HasEnoughCuDescSlot(int start, int end) const; + bool NeedLoadCUDesc(int32 &cudesc_idx); + void IncLoadCuDescIdx(int &idx) const; + bool RoughCheck(CStoreScanKey scanKey, int nkeys, int cuDescIdx); + + void FillColMinMax(CUDesc *cuDescPtr, ScalarVector *vec, int pos); + + inline TransactionId GetCUXmin(uint32 cuid); + + // only called by GetCUData() + CUUncompressedRetCode GetCUDataFromRemote(CUDesc *cuDescPtr, CU *cuPtr, int colIdx, int valSize, const int &slotId); + + /* defence functions */ + void CheckConsistenceOfCUDescCtl(void); + void CheckConsistenceOfCUDesc(int cudescIdx) const; + void CheckConsistenceOfCUData(CUDesc *cuDescPtr, CU *cu, AttrNumber col) const; + +private: + // control private memory used locally. + // m_scanMemContext: for objects alive during the whole cstore-scan + // m_perScanMemCnxt: for memory per heap table scan and temp space + // during decompression. + MemoryContext m_scanMemContext; + MemoryContext m_perScanMemCnxt; + + // current snapshot to use. + Snapshot m_snapshot; + + // 1. Accessed user column id + // 2. Accessed system column id + // 3. flags for late read + // 4. each CU storage fro each user column. + int *m_colId; + int *m_sysColId; + bool *m_lateRead; + CUStorage **m_cuStorage; + + // 1. The CUDesc info of accessed columns + // 2. virtual CUDesc for sys or const columns + LoadCUDescCtl **m_CUDescInfo; + LoadCUDescCtl *m_virtualCUDescInfo; + + // Accessed CUDesc index array + // After RoughCheck, which CU will be accessed + // + int *m_CUDescIdx; + + // adio param + int m_lastNumCUDescIdx; + int m_prefetch_quantity; + int m_prefetch_threshold; + bool m_load_finish; + + // Current scan position inside CU + // + int *m_scanPosInCU; + + // Rough Check Functions + // + RoughCheckFunc *m_RCFuncs; + + typedef int (CStore::*m_colFillFun)(int seq, CUDesc *cuDescPtr, ScalarVector *vec); + + typedef struct { + m_colFillFun colFillFun[2]; + } colFillArray; + + typedef void (CStore::*FillVectorByTidsFun)(_in_ int colIdx, _in_ ScalarVector *tids, _out_ ScalarVector *vec); + + typedef void (CStore::*FillVectorLateReadFun)(_in_ int seq, _in_ ScalarVector *tids, _in_ CUDesc *cuDescPtr, + _out_ ScalarVector *vec); + + FillVectorByTidsFun *m_fillVectorByTids; + FillVectorLateReadFun *m_fillVectorLateRead; + colFillArray *m_colFillFunArrary; + + typedef void (CStore::*fillMinMaxFuncPtr)(CUDesc *cuDescPtr, ScalarVector *vec, int pos); + fillMinMaxFuncPtr *m_fillMinMaxFunc; + + ScanFuncPtr m_scanFunc; // cstore scan function ptr + + // node id of this plan + int m_plan_node_id; + + // 1. Number of accessed user columns + // 2. Number of accessed system columns. + int m_colNum; + int m_sysColNum; + + // 1. length of loaded CUDesc info or virtual CUDesc info + // 2. length of m_CUDescIdx + int m_NumLoadCUDesc; + int m_NumCUDescIdx; + + // 1. CU id of current deleted mask. + // 2. Current access cursor in m_CUDescIdx + // 3. Current access row cursor inside CU + uint32 m_delMaskCUId; + int m_cursor; + int m_rowCursorInCU; + + uint32 m_startCUID; /* scan start CU ID. */ + uint32 m_endCUID; /* scan end CU ID. */ + + unsigned char m_cuDelMask[MaxDelBitmapSize]; + + // whether dead rows exist + bool m_hasDeadRow; + // Is need do rough check + bool m_needRCheck; + // Only access const column + bool m_onlyConstCol; + + bool m_timing_on; /* timing CStoreScan steps */ + + RangeScanInRedis m_rangeScanInRedis; /* if it is a range scan at redistribution time */ + + // cbtree index flag + bool m_useBtreeIndex; + + // the first column index, start from 0 + int m_firstColIdx; + + // for late read + // the cuDesc id of batch in the cuDescArray. + int m_cuDescIdx; + + // for late read + // the first late read column idx which is filled with ctid. + int m_laterReadCtidColIdx; +}; + +// CStore Scan interface for sequential scan +// +extern void InitScanDeltaRelation(CStoreScanState *node, Snapshot snapshot); +extern void ScanDeltaStore(CStoreScanState *node, VectorBatch *outBatch, List *indexqual); +extern void EndScanDeltaRelation(CStoreScanState *node); +extern CStoreScanDesc CStoreBeginScan(Relation relation, int colNum, int16 *colIdx, Snapshot snapshot, bool scanDelta); +extern VectorBatch *CStoreGetNextBatch(CStoreScanDesc cstoreScanState); +extern bool CStoreIsEndScan(CStoreScanDesc cstoreScanState); +extern void CStoreEndScan(CStoreScanDesc cstoreScanState); + +extern void CStoreScanNextTrunkOfCU(_in_ CStoreScanDesc cstoreScanState, __inout BatchCUData *tmpCUData); + +// CStoreRelGetCUNum +// Get CU numbers of relation by now +// +extern uint32 CStoreRelGetCUNumByNow(CStoreScanDesc cstoreScanState); +// Delete the info of the dropped column from the cudesc for a cstore table +extern void CStoreDropColumnInCuDesc(Relation rel, AttrNumber attrnum); +/* CStoreGet1stUndroppedColIdx get the first colum index that is not dropped */ +extern int CStoreGetfstColIdx(Relation rel); + +void CStoreAbortCU(); +void VerifyAbortCU(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_delete.h postgresql-hll-2.14/include/include/access/cstore_delete.h --- postgresql-hll-2.14_old/include/include/access/cstore_delete.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_delete.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,95 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_delete.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_delete.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORE_DELETE_H +#define CSTORE_DELETE_H + +#include "access/cstore_am.h" +#include "utils/batchsort.h" +#include "access/cstore_vector.h" + +class CStoreDelete : public BaseObject { +public: + CStoreDelete(_in_ Relation rel, _in_ EState *estate, _in_ bool is_update_cu, _in_ Plan *plan, + _in_ MemInfoArg *ArgmemInfo); + virtual ~CStoreDelete(); + virtual void Destroy(); + void InitDeleteMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + void ExecDelete(_in_ Relation rel, _in_ ScalarVector *vecRowId, _in_ Snapshot snapshot, _in_ Oid tableOid); + void InitSortState(); + void InitSortState(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void PutDeleteBatch(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 ExecDelete(); + void setReportErrorForUpdate(bool isEnable) + { + m_isRptRepeatTupErrForUpdate = isEnable; + }; + /* record memory auto spread info for delete sort. */ + MemInfoArg *m_DelMemInfo; + +protected: + void CollectPartDeltaOids(); + void UpdateVCBitmap(_in_ Relation rel, _in_ uint32 cuid, _in_ const int *rowoffset, _in_ int updateRowNum, + _in_ Snapshot snapshot); + void InitDeleteSortStateForTable(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void InitDeleteSortStateForPartition(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, _in_ int ctidAttNo); + void PutDeleteBatchForTable(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + void PutDeleteBatchForPartition(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + void PutDeleteBatchForUpdate(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 ExecDeleteForTable(); + uint64 ExecDeleteForPartition(); + bool IsFull() const; + void ResetSortState(); + + Relation m_relation; + Relation m_deltaRealtion; + List *m_partDeltaOids; + + bool m_isUpdate; + + EState *m_estate; + + TupleDesc m_sortTupDesc; + Batchsortstate *m_deleteSortState; + int m_partidIdx; + int m_ctidIdx; + bool m_isTupDescCreateBySelf; + + VectorBatch *m_sortBatch; + int *m_rowOffset; + + int m_maxSortNum; + int m_curSortedNum; + uint64 m_totalDeleteNum; + + // report repeat delete tuple error for update + bool m_isRptRepeatTupErrForUpdate; + + void (CStoreDelete::*m_InitDeleteSortStatePtr)(_in_ TupleDesc sortTupDesc, _in_ int partidAttNo, + _in_ int ctidAttNo); + void (CStoreDelete::*m_PutDeleteBatchPtr)(_in_ VectorBatch *batch, _in_ JunkFilter *junkfilter); + uint64 (CStoreDelete::*m_ExecDeletePtr)(); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_insert.h postgresql-hll-2.14/include/include/access/cstore_insert.h --- postgresql-hll-2.14_old/include/include/access/cstore_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_insert.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,419 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_insert.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_insert.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_INSERT_H +#define CSTORE_INSERT_H + +#include "access/cstore_am.h" +#include "access/cstore_psort.h" +#include "access/cstore_vector.h" +#include "access/cstore_minmax_func.h" +#include "storage/cstore_compress.h" +#include "storage/spin.h" + +struct InsertArg { + /* map to CStoreInsert::m_tmpBatchRows. + * + * because it's a temp batchrows, so + * 1. it's used by each batch inserter when PCK exists, or + * 2. it's shared by each partition when inserting into partitioned table, + */ + bulkload_rows *tmpBatchRows; + + /* map to CStoreInsert::m_idxBatchRow + * + * because it's a temp batchrows, so + * 1. it's shared by each index inserter when inserting into ordinary table, or + * 2. it's shared by each index inserter of each partition when inserting into + * partitioned table. + */ + bulkload_rows *idxBatchRow; + + ResultRelInfo *es_result_relations; + + /* sort type: tuple sorting or batch sorting */ + int sortType; + + /* which function will be called, + * 1. false => void CStoreInsert::BatchInsert(bulkload_rows *batchRowPtr, int options) + * 2. true => void CStoreInsert::BatchInsert(VectorBatch *pBatch, int options) + * this value must be defined explicitly. + */ + bool using_vectorbatch; + + InsertArg() + { + tmpBatchRows = NULL; + idxBatchRow = NULL; + es_result_relations = NULL; + sortType = TUPLE_SORT; /* default psort type */ + using_vectorbatch = true; /* caller should specify the right way */ + } +}; + +/* + * This class provides some API for batch insert in ColStore. + * In future, we can add more API. + */ +class CStoreInsert : public BaseObject { +public: + CStoreInsert(_in_ Relation relation, _in_ const InsertArg &args, _in_ bool is_update_cu, _in_ Plan *plan, + _in_ MemInfoArg *ArgmemInfo); + + virtual ~CStoreInsert(); + virtual void Destroy(); + + void BeginBatchInsert(const InsertArg &args); + void EndBatchInsert(); + + /* + * Batch insert interface + */ + void BatchInsert(bulkload_rows *batchRowPtr, int options); + void BatchInsert(VectorBatch *pVec, int options); + void BatchInsertCommon(bulkload_rows *batchRowPtr, int options); + void FlashData(int options); + + void CUInsert(_in_ BatchCUData *CUData, _in_ int options); + + void SetEndFlag(); + + inline bool IsEnd() + { + return m_insert_end_flag; + } + + static void InitInsertArg(Relation rel, ResultRelInfo *resultRelInfo, bool using_vectorbatch, InsertArg &args); + static void DeInitInsertArg(InsertArg &args); + static void InitIndexInsertArg(Relation heap_rel, const int *keys_map, int nkeys, InsertArg &args); + void InitInsertMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + Relation m_relation; + CU ***m_aio_cu_PPtr; + AioDispatchCUDesc_t ***m_aio_dispath_cudesc; + int *m_aio_dispath_idx; + + /* memory info for memory adjustment */ + MemInfoArg *m_cstorInsertMem; + +private: + void FreeMemAllocateByAdio(); + // Whether need partial clustering when load + // + inline bool NeedPartialSort(void) const; + + // Write CU data and CUDesc + // + void SaveAll(int options, const char *delBitmap = NULL); + + void CUListFlushAll(int attno); + void CUListWriteCompeleteIO(int col, int count); + + void CUWrite(int attno, int col); + void CUListWrite(); + + // Compress batch rows into CU + // Get min/max of CU + // + CU *FormCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr); + Size FormCUTInitMem(CU *cuPtr, bulkload_rows *batchRowPtr, int col, bool hasNull); + void FormCUTCopyMem(CU *cuPtr, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, Size dtSize, int col, bool hasNull); + template + void FormCUT(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + template + void FormCUTNumeric(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + template + void FormCUTNumString(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + + template + bool FormNumberStringCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr); + + template + bool TryFormNumberStringCU(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr, uint32 atttypid); + + void InitIndexColId(int which_index); + + void InitIndexInfo(); + + void InitDeltaInfo(); + + // Insert delta table + void InsertDeltaTable(bulkload_rows *batchRowPtr, int options); + + // Insert index table + // + void InsertIdxTableIfNeed(bulkload_rows *batchRowPtr, uint32 cuId); + + void InsertNotPsortIdx(int indice); + + void FlushIndexDataIfNeed(); + + void InitFuncPtr(); + + void InitColSpaceAlloc(); + + bool TryEncodeNumeric(int col, bulkload_rows *batchRowPtr, CUDesc *cuDescPtr, CU *cuPtr, bool hasNull); + void DoBatchInsert(int options); + typedef void (CStoreInsert::*m_formCUFunc)(int, bulkload_rows *, CUDesc *, CU *); + struct FormCUFuncArray { + m_formCUFunc colFormCU[2]; + }; + inline void SetFormCUFuncArray(Form_pg_attribute attr, int col); + + bool m_isUpdate; + /* Function Pointer Array Area */ + FuncSetMinMax *m_setMinMaxFuncs; /* min/max value function */ + FormCUFuncArray *m_formCUFuncArray; /* Form CU function pointer */ + + /* If relation has cluster key, it will work for partial sort */ + CStorePSort *m_sorter; + + CUDesc **m_cuDescPPtr; /* The cudesc of all columns of m_relation */ + CU **m_cuPPtr; /* The CU of all columns of m_relation; */ + CUStorage **m_cuStorage; /* CU storage */ + compression_options *m_cuCmprsOptions; /* compression filter */ + cu_tmp_compress_info m_cuTempInfo; /* temp info for CU compression */ + + /* buffered batchrows for many VectorBatch values */ + bulkload_rows *m_bufferedBatchRows; + + /* temp batchrows for fetching values from sort processor */ + bulkload_rows *m_tmpBatchRows; + + /* memory context for avoiding memory leaks during bulk-insert */ + MemoryContext m_tmpMemCnxt; + MemoryContext m_batchInsertCnxt; + + /* work for delta insert */ + Relation m_delta_relation; + TupleDesc m_delta_desc; + bool m_append_only; /* don't insert into delta when true */ + + /* work for Index insert */ + ResultRelInfo *m_resultRelInfo; /* contain index meta info */ + + Relation *m_idxRelation; /* index relations */ + InsertArg *m_idxInsertArgs; /* index inserting arguments */ + CStoreInsert **m_idxInsert; /* index inserter */ + int **m_idxKeyAttr; /* index keys */ + int *m_idxKeyNum; /* index keys' number */ + bulkload_rows *m_idxBatchRow; /* shallow copy for index insert */ + EState *m_estate; /* estate information */ + ExprContext *m_econtext; /* curr context for expr eval */ + Datum *m_fake_values; /* value array to form fake heap tuple */ + bool *m_fake_isnull; /* null array to from fake heap tuple */ + + /* ADIO info */ + MemoryContext m_aio_memcnxt; + int32 *m_aio_cache_write_threshold; + File **m_vfdList; + + /* the max number of values within one CU */ + int m_fullCUSize; + + /* the number delta threshold */ + int m_delta_rows_threshold; + + /* compression options. */ + int16 m_compress_modes; + + /* indicate the end of insert or not */ + bool m_insert_end_flag; +}; + +enum PartitionCacheStrategy { + CACHE_EACH_PARTITION_AS_POSSIBLE = 0, // cache every partition as much as possible, default strategy + FLASH_WHEN_SWICH_PARTITION // flash cached data when switch partition +}; + +class PartitionValueCache : public BaseObject { +public: + PartitionValueCache(Relation rel); + + virtual ~PartitionValueCache(); + virtual void Destroy(); + + // Serialize row value to partition value cache + Size WriteRow(Datum *values, const bool *nulls); + + // Deserialize values from partition value cache + int ReadBatchRow(bulkload_rows *batch, Datum *values, bool *nulls); + + void Reset(); + + void EndWrite() + { + FlushData(); + } + + int m_rows; + +private: + int ReadRow(_out_ Datum *values, _out_ bool *nulls); + + int InternalRead(char *buf, int len); + + int InternalWrite(const char *buf, int len); + + FORCE_INLINE int InternalWriteInt(int data) + { + return InternalWrite((char *)&data, sizeof(data)); + } + + int FillBuffer(); + + void FlushData(); + + Relation m_rel; + char *m_buffer; + uint64 m_writeOffset; + File m_fd; + int m_bufCursor; + int m_dataLen; + uint64 m_readOffset; + + const static int MAX_BUFFER_SIZE = 32768; +}; + +// Work for loading partition table +// Do real batch insert using CStoreInsert objection for each partition +// Note that we should control memory size for each partition +// +class CStorePartitionInsert : public CStore { +public: + CStorePartitionInsert(_in_ Relation relation, _in_ ResultRelInfo *es_result_relations, _in_ int type, + _in_ bool is_update_cu, _in_ Plan *plan, _in_ MemInfoArg *ArgmemInfo); + virtual ~CStorePartitionInsert(); + virtual void Destroy(); + void BatchInsert(_in_ Datum *values, _in_ const bool *nulls, _in_ int options); + void BatchInsert(VectorBatch *batch, int hi_options); + + void EndBatchInsert(); + void SetEndFlag() + { + } + + void SetPartitionCacheStrategy(int partition_cache_strategy); + bool hasEnoughMem(int partitionidx, int64 memsize_used); + int findBiggestPartition() const; + void InitInsertPartMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + /* record memory auto spread info. bulkload memory */ + MemInfoArg *m_memInfo; + +private: + void InitValueCache(); + + void DeInitValueCache(); + + bool CacheValues(Datum *values, const bool *nulls, int partitionidx); + + void SaveCacheValues(int partitionidx, bool doFlush, int options); + + void MoveBatchRowToPartitionValueCache(int partitionidx); + + // Try to get a batchrow from free list + // + bulkload_rows *GetBatchRow(int partitionIdx); + + // Return the batchrow held by the partition to the free list + // + void ReleaseBatchRow(int partitionIdx); + + /* + * @Description: is insert value switch partition + * @IN partitionIdx: current partition number + * @Return: true switch partiton, false not switch + */ + inline bool IsSwitchPartition(int partitionIdx) + { + return (m_last_insert_partition != -1) && (m_last_insert_partition != partitionIdx); + }; + + inline Relation GetPartFakeRelation(int partitionIdx) + { + AutoContextSwitch contextSwitcher(m_cstorePartMemContext); + + Relation partitionRelation = m_storePartFakeRelation[partitionIdx]; + if (NULL == partitionRelation) { + Assert(m_relation->partMap->type == PART_TYPE_RANGE); + + PartitionIdentifier partitionIdentifier; + partitionIdentifier.partSeq = partitionIdx; + partitionIdentifier.partArea = PART_AREA_RANGE; + Oid partoid = partIDGetPartOid(m_relation, &partitionIdentifier); + Partition partition = partitionOpen(m_relation, partoid, RowExclusiveLock); + partitionRelation = partitionGetRelation(m_relation, partition); + m_storePartFakeRelation[partitionIdx] = partitionRelation; + partitionClose(m_relation, partition, NoLock); + } + + return partitionRelation; + }; + + // CStoreInsert object for each partition + // + CStoreInsert **m_insert; + + Relation *m_storePartFakeRelation; + int m_partitionNum; + InsertArg m_insertArgs; + + bool m_isUpdate; + /* disk cache objects for each partition */ + PartitionValueCache **m_partValCache; + /* flag to use disk cache */ + bool *m_partUseCahce; + List *m_batchFreeList; + + /* batchrows for each partition */ + bulkload_rows **m_partRelBatchRows; + /* temp batchrows for disk cache */ + bulkload_rows *m_partTmpBatch; + + /* temp memory context to avoid space leaks during disk cache inserting */ + MemoryContext m_tmpMemCnxt; + /* memory context for all objects alive during partitioned table inserting */ + MemoryContext m_cstorePartMemContext; + + /* partition cache strategy */ + int m_cache_strategy; + + /* last insert partition number */ + int m_last_insert_partition; + + /* all partition relation keep the same value to the one of their parent + * relation. so we can share this var between all the partition relations. + */ + int m_fullCUSize; + Datum *m_val; + bool *m_null; + Datum *m_tmp_val; + bool *m_tmp_null; + + Size *m_diskFileSize; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_minmax_func.h postgresql-hll-2.14/include/include/access/cstore_minmax_func.h --- postgresql-hll-2.14_old/include/include/access/cstore_minmax_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_minmax_func.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_minmax_func.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_minmax_func.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_MINMAX_FUNC_H +#define CSTORE_MINMAX_FUNC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/cu.h" + +typedef void (*FuncSetMinMax)(Datum v, CUDesc *cuDescPtr, bool *); +typedef void (*CompareDatum)(char *minval, char *maxval, Datum v, bool *first, int *varstr_maxlen); +typedef void (*FinishCompareDatum)(const char *minval, const char *maxval, CUDesc *cuDescPtr); + +extern FuncSetMinMax GetMinMaxFunc(Oid typeOid); + +extern CompareDatum GetCompareDatumFunc(Oid typeOid); +extern FinishCompareDatum GetFinishCompareDatum(Oid typeOid); +extern bool IsCompareDatumDummyFunc(CompareDatum f); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_psort.h postgresql-hll-2.14/include/include/access/cstore_psort.h --- postgresql-hll-2.14_old/include/include/access/cstore_psort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_psort.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_psort.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_psort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTOREPSORT_H +#define CSTOREPSORT_H + +#include "access/cstore_vector.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/batchsort.h" +#include "utils/tuplesort.h" +#include "utils/rel.h" +#include "utils/relcache.h" +#include "storage/cu.h" + +enum PSORT_TYPE { + TUPLE_SORT = 0, + BATCH_SORT +}; +extern THR_LOCAL int psort_work_mem; + +#define InvalidBathCursor (-1) +#define BathCursorIsValid(_c) ((_c) > InvalidBathCursor) + +class CStorePSort : public BaseObject { +public: + CStorePSort(Relation rel, AttrNumber *sortKeys, int keyNum, int type, MemInfoArg *m_memInfo = NULL); + + virtual ~CStorePSort(); + + virtual void Destroy(); + void InitPsortMemArg(MemInfoArg *ArgmemInfo); + + void PutVecBatch(Relation rel, VectorBatch *pVecBatch); + + void PutBatchValues(bulkload_rows *batchRowPtr); + + void PutTuple(_in_ Datum *values, _in_ bool *nulls); + + void PutSingleTuple(Datum *values, bool *nulls); + + void RunSort(); + + void GetBatchValue(bulkload_rows *batchRowsPtr); + + VectorBatch *GetVectorBatch(); + + TupleTableSlot *GetTuple(); + + void Reset(bool endFlag); + + bool IsFull() const; + + int GetRowNum() const; + + void ResetTupleSortState(bool endFlag); + + void ResetBatchSortState(bool endFlag); + + void GetBatchValueFromTupleSort(bulkload_rows *batchRowsPtr); + + void GetBatchValueFromBatchSort(bulkload_rows *batchRowsPtr); + + Tuplesortstate *m_tupleSortState; + Batchsortstate *m_batchSortState; + VectorBatch *m_vecBatch; + TupleTableSlot *m_tupleSlot; + +private: +#ifdef USE_ASSERT_CHECKING + void AssertCheck(void); +#endif + int m_type; + + Relation m_rel; + AttrNumber *m_sortKeys; + int m_keyNum; + + Oid *m_sortOperators; + Oid *m_sortCollations; + bool *m_nullsFirst; + + TupleDesc m_tupDesc; + + int m_curSortedRowNum; + int m_partialClusterRowNum; + int m_fullCUSize; + // current index of tuple to fetch. + int m_vecBatchCursor; + + MemoryContext m_psortMemContext; + + Datum *m_val; + + bool *m_null; + + MemInfoArg *m_psortMemInfo; + + void (CStorePSort::*m_funcGetBatchValue)(bulkload_rows *batchRowsPtr); + + void (CStorePSort::*m_funcReset)(bool endFlag); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_rewrite.h postgresql-hll-2.14/include/include/access/cstore_rewrite.h --- postgresql-hll-2.14_old/include/include/access/cstore_rewrite.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_rewrite.h 2020-12-12 17:06:43.131346542 +0800 @@ -0,0 +1,332 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_rewrite.h + * routinues to support Column Store Rewrite + * + * + * IDENTIFICATION + * src/include/access/cstore_rewrite.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_REWRITE_H +#define CSTORE_REWRITE_H + +#include "c.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/cstore_am.h" +#include "access/cstore_minmax_func.h" +#include "access/reloptions.h" +#include "access/transam.h" +#include "access/tupdesc.h" +#include "access/xact.h" +#include "access/xlogutils.h" +#include "catalog/storage.h" +#include "commands/cluster.h" +#include "commands/vacuum.h" +#include "executor/executor.h" +#include "nodes/execnodes.h" +#include "storage/cstore_compress.h" +#include "storage/custorage.h" +#include "utils/fmgroids.h" +#include "utils/memutils.h" +#include "access/heapam.h" + +#define MAX_CSTORE_MERGE_PARTITIONS 31 + +typedef enum CStoreRewriteType { + CSRT_ADD_COL = 0, // --> ADD COLUMN + CSRT_SET_DATA_TYPE, // --> ALTER COLUMN SET DATA TYPE + CSRT_NUM // add new type above please. +} CStoreRewriteType; + +typedef struct ColumnNewValue { + Expr *expr; // expression to compute + ExprState *exprstate; // execution state +} ColumnNewValue; + +typedef struct CStoreRewriteColumn { + AttrNumber attrno; + bool isDropped; + bool isAdded; + bool notNull; + ColumnNewValue *newValue; + + static CStoreRewriteColumn *CreateForAddColumn(AttrNumber attNo); + static CStoreRewriteColumn *CreateForSetDataType(AttrNumber attNo); + static void Destroy(CStoreRewriteColumn **rewriteInfo); +} CStoreRewriteColumn; + +// Bulk Insert For Heap Relation +// +// Notice: we just bulk-insert heap tuples for this heap relation, without +// handling its indexes and triggers, etc. +// +class HeapBulkInsert : public BaseObject { +public: + HeapBulkInsert(Relation cudescHeapRel); + virtual ~HeapBulkInsert(){}; + virtual void Destroy(); + + // interfaces for bulk-insert heap tuples. + // BulkInsertCopy() will copy this tuple before appending, + // but BulkInsert() will not. so call the pair of EnterBulkMemCnxt() + // and LeaveBulkMemCnxt() before BulkInsert() is invoked. + // + void BulkInsert(HeapTuple tuple); + void BulkInsertCopy(HeapTuple tuple); + void Finish(); + + FORCE_INLINE void EnterBulkMemCnxt() + { + m_OldMemCnxt = MemoryContextSwitchTo(m_MemCnxt); + Assert(m_OldMemCnxt != NULL); + } + + FORCE_INLINE void LeaveBulkMemCnxt() + { + Assert(m_OldMemCnxt != NULL); + (void)MemoryContextSwitchTo(m_OldMemCnxt); + m_OldMemCnxt = NULL; + } + + // limit private memory context' upmost resource to use. + static const int MaxBufferedTupNum = 10000; + static const Size MaxBufferedTupSize = 8192 * 128; + +private: + MemoryContext m_OldMemCnxt; + MemoryContext m_MemCnxt; + HeapTuple *m_BufferedTups; + Size m_BufferedTupsSize; + int m_BufferedTupsNum; + + Relation m_HeapRel; + BulkInsertState m_BIState; + CommandId m_CmdId; + int m_InsertOpt; + + template + void Append(HeapTuple tuple); + + FORCE_INLINE void Flush(); + FORCE_INLINE bool Full() const; +}; + +class LoadSingleCu : public BaseObject { +public: + // load data for single cu. + // caller should delete CU object returned. + static CU *LoadSingleCuData(_in_ CUDesc *pCuDesc, _in_ int colIdx, _in_ int colAttrLen, _in_ int colTypeMode, + _in_ uint32 colAtttyPid, _in_ Relation rel, __inout CUStorage *pCuStorage); +}; + +// remember those relation oids +// which ALTER TABLE SET DATATYPE is exec on. +class CStoreAlterRegister : public BaseObject { +public: + CStoreAlterRegister() : m_Oids(NULL), m_used(0), m_maxs(0) + { + } + virtual ~CStoreAlterRegister() + { + } + virtual void Destroy(); + + void Add(Oid relid); + bool Find(Oid relid) const; + +private: + Oid *m_Oids; // Oid array + int m_used; // Oid used number + int m_maxs; // Oid array max number + + bool DynSearch(Oid relid, int *pos) const; +}; + +// GetCstoreAlterReg(): get the global instance, and create it the first time. +// DestroyCstoreAlterReg(): destroy the global instance in COMMIT or ROLLBACK. +extern CStoreAlterRegister *GetCstoreAlterReg(); +extern void DestroyCstoreAlterReg(); + +class CStoreRewriter : public BaseObject { +public: + CStoreRewriter(Relation oldHeapRel, TupleDesc oldTupDesc, TupleDesc newTupDesc); + virtual ~CStoreRewriter(){}; + virtual void Destroy(); + + void ChangeTableSpace(Relation CUReplicationRel); + void BeginRewriteCols(_in_ int nRewriteCols, _in_ CStoreRewriteColumn **pRewriteCols, + _in_ const int *rewriteColsNum, _in_ bool *rewriteFlags); + void RewriteColsData(); + void EndRewriteCols(); + +public: + template + void HandleCuWithSameValue(_in_ Relation rel, _in_ Form_pg_attribute newColAttr, _in_ Datum newColVal, + _in_ bool newColValIsNull, _in_ FuncSetMinMax func, _in_ CUStorage *colStorage, + __inout CUDesc *newColCudesc, __inout CUPointer *pOffset); + + static void FormCuDataForTheSameVal(__inout CU *cuPtr, _in_ int rowsCntInCu, _in_ Datum newColVal, + _in_ Form_pg_attribute newColAttr); + + static void CompressCuData(CU *cuPtr, CUDesc *cuDesc, Form_pg_attribute newColAttr, int16 compressing_modes); + + FORCE_INLINE + static void SaveCuData(_in_ CU *cuPtr, _in_ CUDesc *cuDesc, _in_ CUStorage *cuStorage); + +private: + FORCE_INLINE bool NeedRewrite() const; + + void AddColumns(_in_ uint32 cuId, _in_ int rowsCntInCu, _in_ bool wholeCuIsDeleted); + void AddColumnInitPhrase1(); + void AddColumnInitPhrase2(_in_ CStoreRewriteColumn *addColInfo, _in_ int idx); + void AddColumnDestroy(); + + void SetDataType(_in_ uint32 cuId, _in_ HeapTuple *cudescTup, _in_ TupleDesc oldCudescTupDesc, + _in_ const char *delMaskDataPtr, _in_ int rowsCntInCu, _in_ bool wholeCuIsDeleted); + void SetDataTypeInitPhase1(); + void SetDataTypeInitPhase2(_in_ CStoreRewriteColumn *sdtColInfo, _in_ int idx); + void SetDataTypeDestroy(); + + FORCE_INLINE + void SetDataTypeHandleFullNullCu(_in_ CUDesc *oldColCudesc, _out_ CUDesc *newColCudesc); + + void SetDataTypeHandleSameValCu(_in_ int sdtIndex, _in_ CUDesc *oldColCudesc, _out_ CUDesc *newColCudesc); + + void SetDataTypeHandleNormalCu(_in_ int sdtIndex, _in_ const char *delMaskDataPtr, _in_ CUDesc *oldColCudesc, + _out_ CUDesc *newColCudesc); + + void FetchCudescFrozenXid(Relation oldCudescHeap); + + void InsertNewCudescTup(_in_ CUDesc *pCudesc, _in_ TupleDesc pCudescTupDesc, _in_ Form_pg_attribute pColNewAttr); + + void HandleWholeDeletedCu(_in_ uint32 cuId, _in_ int rowsCntInCu, _in_ int nRewriteCols, + _in_ CStoreRewriteColumn **rewriteColsInfo); + + void FlushAllCUData() const; + +private: + Relation m_OldHeapRel; + TupleDesc m_OldTupDesc; + TupleDesc m_NewTupDesc; + + Oid m_NewCuDescHeap; + bool *m_ColsRewriteFlag; + + // Set New Tablespace + bool m_TblspcChanged; + Oid m_TargetTblspc; + Oid m_TargetRelFileNode; + /* user a new relation for CU Replication + * if tablespace is changed, we used a spicail CU Replication relation for new relfilenode. + * else heap relation is also available. + */ + Relation m_CUReplicationRel; + CUPointer *m_SDTColAppendOffset; + + // ADD COLUMN + int m_AddColsNum; + CStoreRewriteColumn **m_AddColsInfo; + CUStorage **m_AddColsStorage; + FuncSetMinMax *m_AddColsMinMaxFunc; + CUPointer *m_AddColsAppendOffset; + + // SET DATA TYPE + int m_SDTColsNum; + CStoreRewriteColumn **m_SDTColsInfo; + CUStorage **m_SDTColsReader; + FuncSetMinMax *m_SDTColsMinMaxFunc; + CUStorage **m_SDTColsWriter; + Datum *m_SDTColValues; + bool *m_SDTColIsNull; + + // new cudesc relation's + Relation m_NewCudescRel; + HeapBulkInsert *m_NewCudescBulkInsert; + TransactionId m_NewCudescFrozenXid; + + // m_estate is used during rewriting table data. + // so it cannot be freed or reset before RewriteColsData() is end. + // m_econtext is the same , but its ecxt_per_tuple_memory + // must be reset after each data is handled successfully. + EState *m_estate; + ExprContext *m_econtext; +}; + +class BatchCUData : public BaseObject { +public: + CUDesc **CUDescData; + CU **CUptrData; + char *bitmap; // The delete bitmap that we would keep for the CU that's been moved + int colNum; + bool hasValue; + + BatchCUData() + { + CUDescData = NULL; + CUptrData = NULL; + bitmap = NULL; + colNum = 0; + hasValue = false; + } + + virtual ~BatchCUData() + { + } + + void Init(const int &relColNum) + { + colNum = relColNum; + CUDescData = (CUDesc **)palloc0(colNum * sizeof(CUDesc *)); + CUptrData = (CU **)palloc0(colNum * sizeof(CU *)); + for (int i = 0; i < colNum; ++i) { + CUDescData[i] = New(CurrentMemoryContext) CUDesc; + } + } + + void CopyDelMask(unsigned char *cuDelMask) + { + bitmap = (char *)cuDelMask; + } + + bool batchCUIsNULL() + { + return !hasValue; + } + + void reset() + { + hasValue = false; + } + virtual void Destroy() + { + for (int i = 0; i < colNum; ++i) { + DELETE_EX(CUDescData[i]); + } + pfree_ext(CUDescData); + pfree_ext(CUptrData); + } +}; + +extern void CStoreCopyColumnData(Relation CUReplicationRel, Relation rel, AttrNumber attrnum); +extern void CStoreCopyColumnDataEnd(Relation colRel, Oid targetTableSpace, Oid newrelfilenode); +extern Oid CStoreSetTableSpaceForColumnData(Relation colRel, Oid targetTableSpace); +extern void ATExecCStoreMergePartition(Relation partTableRel, AlterTableCmd *cmd); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_roughcheck_func.h postgresql-hll-2.14/include/include/access/cstore_roughcheck_func.h --- postgresql-hll-2.14_old/include/include/access/cstore_roughcheck_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_roughcheck_func.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_roughcheck_func.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_roughcheck_func.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_ROUGHCHECK_FUNC_H +#define CSTORE_ROUGHCHECK_FUNC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/cstoreskey.h" +#include "storage/cu.h" + +typedef bool (*RoughCheckFunc)(CUDesc *cudesc, Datum arg); + +RoughCheckFunc GetRoughCheckFunc(Oid typeOid, int strategy, Oid collation); + +#endif /* CSTORE_ROUGHCHECK_FUNC_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/cstoreskey.h postgresql-hll-2.14/include/include/access/cstoreskey.h --- postgresql-hll-2.14_old/include/include/access/cstoreskey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstoreskey.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,64 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstoreskey.h + * POSTGRES column store scan key definitions. + * + * + * IDENTIFICATION + * src/include/access/cstoreskey.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORESKEY_H +#define CSTORESKEY_H + +#include "access/attnum.h" +#include "fmgr.h" + +/* + * Strategy numbers identify the semantics that particular operators have. + */ +typedef uint16 CStoreStrategyNumber; + +#define InvalidCStoreStrategy ((CStoreStrategyNumber)0) + +/* + * define the strategy numbers for cstore scan. + */ +const CStoreStrategyNumber CStoreLessStrategyNumber = 1; +const CStoreStrategyNumber CStoreLessEqualStrategyNumber = 2; +const CStoreStrategyNumber CStoreEqualStrategyNumber = 3; +const CStoreStrategyNumber CStoreGreaterEqualStrategyNumber = 4; +const CStoreStrategyNumber CStoreGreaterStrategyNumber = 5; + +const CStoreStrategyNumber CStoreMaxStrategyNumber = 5; + +typedef struct CStoreScanKeyData { + uint16 cs_flags; // no use. + AttrNumber cs_attno; // a sequence column numbers, begin with 0 + CStoreStrategyNumber cs_strategy; // operator strategy number + Oid cs_collation; // collation to use, if needed + FmgrInfo cs_func; // op func + Datum cs_argument; // op args. + Oid cs_left_type; // op left type +} CStoreScanKeyData; + +typedef CStoreScanKeyData *CStoreScanKey; + +void CStoreScanKeyInit(CStoreScanKey entry, uint16 flags, AttrNumber attributeNumber, CStoreStrategyNumber strategy, + Oid collation, RegProcedure procedure, Datum argument, Oid left_type); + +#endif /* CSTORESKEY_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_update.h postgresql-hll-2.14/include/include/access/cstore_update.h --- postgresql-hll-2.14_old/include/include/access/cstore_update.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_update.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_update.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/access/cstore_update.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_UPDATE_H +#define CSTORE_UPDATE_H + +#include "access/cstore_am.h" +#include "access/cstore_delete.h" +#include "access/cstore_insert.h" + +class CStoreUpdate : public BaseObject { +public: + CStoreUpdate(_in_ Relation rel, _in_ EState *estate, _in_ Plan *plan); + virtual ~CStoreUpdate(); + virtual void Destroy(); + void InitSortState(TupleDesc sortTupDesc); + uint64 ExecUpdate(_in_ VectorBatch *batch, _in_ int options); + void EndUpdate(_in_ int options); + void InitUpdateMemArg(Plan *plan); + MemInfoArg *m_delMemInfo; + MemInfoArg *m_insMemInfo; + +private: + Relation m_relation; + + CStoreDelete *m_delete; + CStoreInsert *m_insert; + CStorePartitionInsert *m_partionInsert; + + ResultRelInfo *m_resultRelInfo; + EState *m_estate; + bool m_isPartition; + static int BATCHROW_TIMES; + + InsertArg m_insert_args; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/cstore_vector.h postgresql-hll-2.14/include/include/access/cstore_vector.h --- postgresql-hll-2.14_old/include/include/access/cstore_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/cstore_vector.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,335 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_vector.h + * batch buffer for bulk-loading, including + * 1. bulkload_block + * 2. bulkload_block_list + * 3. bulkload_minmax + * 4. bulkload_vector + * 5. bulkload_vector_iter + * 6. bulkload_rows + * 7. bulkload_rows_iter + * + * + * IDENTIFICATION + * src/include/access/cstore_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H +#define GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H + +#include "access/cstore_minmax_func.h" +#include "catalog/pg_attribute.h" +#include "vecexecutor/vectorbatch.h" + +extern bool bulkload_memsize_reach_limitation(void); + +/* Limitation about the total memory size of using blocks of one bulkload_rows object */ +#define BULKLOAD_MAX_MEMSIZE (1024 * 1024 * 1024LL) + +/* type declaration */ +struct bulkload_block; +struct bulkload_block_list; +struct bulkload_minmax; +struct bulkload_datums; +struct bulkload_vector; +struct bulkload_vector_iter; +struct bulkload_rows; + +struct MemInfoArg { + /* record memory auto spread info. bulkload memory */ + int canSpreadmaxMem; + int MemInsert; + int MemSort; + int spreadNum; + int partitionNum; + + MemInfoArg() + { + canSpreadmaxMem = 0; + MemInsert = 0; + MemSort = 0; + spreadNum = 0; + partitionNum = 0; + } +}; + +/* bulkload_block + * memory block for bulk loading. + */ +struct bulkload_block { + struct bulkload_block *next; /* next bulkload_block */ + char *buff; /* memory buffer */ + int used; /* used space by bytes */ + int total; /* total space by bytes */ + + /* *data_unit* see data_unit() function */ + static bulkload_block *create(int block_size, int data_unit); +}; + +/* bulkload_block_list + * memory block list for bulk loading. + */ +struct bulkload_block_list { + bulkload_block *m_head; /* the first block */ + bulkload_block *m_current; /* the m_current block */ + int m_block_num; /* block number */ + + /* + * for fixed length data type, all the blocks have the same block size; + * for varied length data type, not all the block sizes are the same, + * but we remember the minimum block size in m_block_size. if data size if + * larger than m_block_size, the block to hold the data will adopt the block + * size which is equal to data size. + */ + int m_block_size; + + void init(Form_pg_attribute attr); + void destroy(); + void expand(void); + void expand(int needed); + void reset(bool reuse_blocks); + void configure(int attlen); + +private: + template + void reset_inner(void); +}; + +/* bulkload_minmax + * min/max info during bulk loading. + */ +struct bulkload_minmax { + CompareDatum m_compare; /* datum compare function */ + FinishCompareDatum m_finish_compare; /* datum compare finishing function */ + + /* make min/max buffer address be 8 aligned, + * because the first 8 bytes will be accessed as Datum pointer. + * so place the two after function pointers, and MIN_MAX_LEN = 8*N . + */ + char m_min_buf[MIN_MAX_LEN]; /* buffer for min value */ + char m_max_buf[MIN_MAX_LEN]; /* buffer for max value */ + + int m_varstr_maxlen; /* max length of variable length column */ + bool m_first_compare; /* indicate the first comparing action */ + + void init(Oid atttypid); + void reset(void); + void configure(Oid atttypid); +}; + +/* bulkload_datums + * values/nulls info during bulk loading. + */ +struct bulkload_datums { + Datum *m_vals_points; /* only for attlen > 8 or attlen < 0 */ + char *m_null_bitmap; /* NULLs bitmap */ + int m_vals_num; /* current number of values in m_vals_points including NULLs */ + bool m_has_null; /* indicate at least one NULL exists */ + bool m_all_null; /* indicate all are NULL */ + + void init(Form_pg_attribute attr, int max_num); + void destroy(); + void reset(int max_num); + bool is_null(int which); + void set_null(int which); + Datum get_datum(int which) const; +}; + +/* bulkload_vector + * a batch of values for one column. + */ +struct bulkload_vector : public BaseObject { + /* memory block info && m_append api */ + bulkload_block_list m_blocks; + int m_attlen; + + /* function pointer */ + Datum (bulkload_vector::*m_decode)(ScalarVector *, int) const; + Datum (bulkload_vector::*m_append)(bulkload_rows *, Datum, int); + + /* Values/Nulls info */ + bulkload_datums m_values_nulls; + + /* Min/Max info */ + bulkload_minmax m_minmax; + + /* ====== bulkload_vector API ====== */ + void init(Form_pg_attribute attr, int max_values); + void configure(Form_pg_attribute attr); + void reset(int max_values, bool reuse_blocks); + void destroy(void); + + Size data_size(void); + void data_copy(char *outbuf); + + void new_fixedsize_block(int data_unit); + void choose_fixedsize_block(bulkload_rows *batch_rows, int data_unit); + + void new_varsize_block(int data_len); + void choose_varsize_block(bulkload_rows *batch_rows, int data_len); + +private: + /* append functions for all datatype */ + Datum append_int8(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int16(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int32(bulkload_rows *batch_rows, Datum v, int len); + Datum append_int64(bulkload_rows *batch_rows, Datum v, int len); + Datum append_fixed_length(bulkload_rows *batch_rows, Datum v, int len); + template + Datum append_var_length(bulkload_rows *batch_rows, Datum v, int len); + + /* decode functions for all datatype */ + Datum decode_integer(ScalarVector *pvector, int rowIdx) const; + Datum decode_fixed_length(ScalarVector *pvector, int rowIdx) const; + Datum decode_var_length(ScalarVector *pvector, int rowIdx) const; +}; + +/* Vector Itor */ +struct bulkload_vector_iter { + void begin(bulkload_vector *vect, int max_values); + void next(Datum *value, bool *null); + bool not_end(void) const; + +private: + bulkload_vector *m_vector; /* current accessing vector */ + bulkload_block *m_block; /* current accessing block */ + int m_block_pos; /* position of current block */ + int m_cur_num; /* current number of accessed values */ + int m_max_num; /* max number of accessed values */ + + /* next function point */ + void (bulkload_vector_iter::*m_next)(Datum *, bool *); + + /* next function */ + void next_int8(Datum *value, bool *null); + void next_int16(Datum *value, bool *null); + void next_int32(Datum *value, bool *null); + void next_int64(Datum *value, bool *null); + void next_var_length(Datum *value, bool *null); +}; + +/* batch rows for bulk loading */ +struct bulkload_rows : public BaseObject { + /* make all the used memory within m_context */ + MemoryContext m_context; + + /* we must control total memory size used by this object, + * so m_using_blocks_total_rawsize will remember using memory size. + */ + Size m_using_blocks_total_rawsize; + Size m_using_blocks_init_rawsize; + + /* values vectors for each attribute/field */ + bulkload_vector *m_vectors; + int m_attr_num; + + /* the current and max number of values to hold within each vector */ + int m_rows_maxnum; + int m_rows_curnum; + + /* becuase buffer is lazy-created, so we can + * 1. create all buffers if needed, + * 2. re-create all buffers and reuse after the previous destroy. + */ + bool m_inited; + + typedef bool (bulkload_rows::*FormAppendColumnFuncType)(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + FormAppendColumnFuncType m_form_append_column_func; + + typedef Size (bulkload_rows::*FormSampleTupleSizeFuncType)(TupleDesc tup_desc, VectorBatch *p_batch, + int idx_sample); + FormSampleTupleSizeFuncType m_form_sample_tuple_size_func; + + bool m_has_dropped_column; + + /* constructor and deconstructor */ + bulkload_rows(TupleDesc tuple_desc, int rows_maxnum, bool to_init = true); + ~bulkload_rows() + { + } + + /* important: + * Destroy is the common funtion to release all resources, + * so don't change this function name. + */ + void Destroy(void) + { + destroy(); + } + + void init(TupleDesc tup_desc, int rows_maxnum); + void reset(bool reuse_blocks); + bool append_one_vector(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx, MemInfoArg *m_memInfo = NULL); + bool append_one_tuple(Datum *values, const bool *isnull, TupleDesc tup_desc); + void append_one_column(Datum *values, const bool *isnull, int rows, TupleDesc tup_desc, int dest_idx); + + Size total_memory_size(void) const; + + /* + * @Description: check whether row number reaches limitation. + * @Return: true if row number reaches limitation; otherwise false. + * @See also: + */ + inline bool full_rownum(void) + { + return (m_rows_curnum == m_rows_maxnum); + } + + /* + * @Description: check whether rows size reaches limitation. + * @Return: true if rows size reaches limitation; otherwise false. + * @See also: + */ + inline bool full_rowsize(void) + { + return (m_using_blocks_total_rawsize >= BULKLOAD_MAX_MEMSIZE); + } + + Size calculate_tuple_size(TupleDesc tup_desc, Datum *tup_values, const bool *tup_nulls) const; + +private: + template + bool append_in_column_orientation(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + bool append_in_row_orientation(TupleDesc tup_desc, VectorBatch *p_batch, int *start_idx); + template + Size sample_tuple_size(TupleDesc tup_desc, VectorBatch *p_batch, int start_idx); + void destroy(void); +}; + +/* itor for bulkload_rows */ +struct bulkload_rows_iter { + void begin(bulkload_rows *batch_rows); + void next(Datum *values, bool *nulls); + bool not_end(void) const; + void end(void); + +private: + bulkload_rows *m_batch; + bulkload_vector_iter *m_vec_iters; +}; + +extern void init_tid_attinfo(FormData_pg_attribute *tid_attr); +extern void init_tid_vector(bulkload_vector *vect, int max_values); +extern bulkload_rows *bulkload_indexbatch_init(int max_key_num, int max_values); +extern void bulkload_indexbatch_set_tids(bulkload_rows *index_batch, uint32 cuid, int copy_num); +extern void bulkload_indexbatch_copy(bulkload_rows *index_batch, int dest_idx, bulkload_rows *src, int src_idx); +extern void bulkload_indexbatch_copy_tids(bulkload_rows *index_batch, int dest_idx); +extern void bulkload_indexbatch_deinit(bulkload_rows *index_batch); + +#endif /* GAUSS_CODE_SRC_INCLUDE_ACCESS_CSTORE_VECTOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/carbondata_index_reader.h postgresql-hll-2.14/include/include/access/dfs/carbondata_index_reader.h --- postgresql-hll-2.14_old/include/include/access/dfs/carbondata_index_reader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/carbondata_index_reader.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,231 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * carbondata_index_reader.h + * + * IDENTIFICATION + * src/include/access/dfs/carbondata_index_reader.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CARBONDATA_INDEX_READER_H_ +#define CARBONDATA_INDEX_READER_H_ + +#include +#include +#include +#include + +#include "carbondata/format/carbondata_types.h" +#include "carbondata/format/carbondata_index_types.h" +#include "carbondata/format/schema_types.h" +#include "carbondata/index_file_reader.h" +#include "carbondata/inputstream.h" +#include "carbondata/memory.h" +#include "carbondata/thrift_adapter.h" + +#include "postgres.h" + +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_stream.h" +#include "nodes/pg_list.h" +#include "pgxc/locator.h" + +extern THR_LOCAL char* PGXCNodeName; + +namespace dfs { +#define CARBONDATA_FILENUMBER 1024 +#define OBS_OBJECT_NAME_MAXSIZE 1024 + +#define CARBONDATA_INDEX ".carbonindex" +#define CARBONDATA_DATA ".carbondata" + +/* + * get file name from path + * @IN FilePath + * @return: file name + */ +extern const char* FileNameFromPath(const char* filePath); + +/* + * filter file name to filetype + * @IN fileList + * @IN fileType + * @return: fileList after filter + */ +extern List* CarbonFileFilter(List* fileList, const char* fileType); + +/* + * Get the data filename list after match obs filelist. + * @IN fileList: obs data fileList + * @IN dataFileList: carbonindex analysis data fileList + * @return filename list: data filename need to be schedule. + */ +extern List* CarbonDataFileMatch(List* fileList, List* dataFileList); + +namespace reader { + +class CarbondataIndexReader : public BaseObject { +public: + CarbondataIndexReader( + List* allColumnList, List* queryRestrictionList, bool* restrictRequired, bool* readRequired, int16 attrNum); + + ~CarbondataIndexReader() + {} + + /* Initialization */ + void init(std::unique_ptr gsInputStream); + + /* read index file */ + void readIndex(); + + /* Clear the memory and resource. */ + void Destroy(); + + /* + * Get the data filename list from carbonindex file. + * @return filename list: data filename list. + */ + List* getDataFileList(); + + /* + * Get the data filepath list from carbonindex file. + * @return filepath list: data filepath list. + */ + List* getDataFilePathList(); + + /* + * Get the not repeat data filename list from carbonindex file. + * @return filename list: data filename list only. + */ + List* getDataFileDeduplication(); + +private: + /* + * Min-max filter, try to skip carbondata blocklet. + * @IN currentBlocklet: current blocklet index + * @Out bool: true : skip current blocklet; + * false: not skip current blocklet. + */ + bool tryToSkipCurrentBlocklet(uint64 currentBlocklet); + + bool checkPredicateOnCurrentBlocklet(uint64 currentBlocklet); + + List* buildRestriction(uint64 rowGroupIndex); + + Node* buildColRestriction(int32 columnIndex, uint64 blockletIndex); + + int32_t GetBlockletMinMax( + int32 columnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxString(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxVarchar(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxBoolean(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxByte(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxShort(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxInt(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxLong(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxFloat(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDouble(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxTimestamp(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDate(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + int32_t GetBlockletMinMaxDecimal(carbondata::format::BlockletMinMaxIndex& blockMinMaxIndex, + int32 realColumnIndex, uint64 blockletIndex, bool* hasMinMax, Datum* minDatum, Datum* maxDatum); + + /* + * filepath cut to path and name + * @IN FilePath: filePath need to be cut + * @OUT Path: path + * @OUT Name: Name + */ + void FilePathCut(char*& path, char*& name, const char* filePath); + + /* + * path and name joint to filepath + * @IN name: file name + * @IN path: file path + * @OUT filePath: filepath + */ + void FilePathJoint(char*& filePath, const char* name, const char* path); + + inline bool isColumnRequiredToRead(int32 columnIndexInRead) + { + return m_readRequired != NULL ? m_readRequired[columnIndexInRead] : false; + } + + inline bool hasRestriction() + { + return m_queryRestrictionList != NULL; + } + + inline int32 getSchemaOrdinal(int32 columnIndex) + { + return m_schemaOrdinalList[columnIndex]; + } + +private: + HTAB* m_dataname_hashtbl; + + char* m_filePath; + char* m_fileName; + uint64 m_block_size; + + const Var* m_var; + OpExpr* m_lessThanExpr; + OpExpr* m_greaterThanExpr; + + List* m_allColumnList; + List* m_queryRestrictionList; + + bool* m_restrictRequired; + bool* m_readRequired; + + /* carbondata columns schema ordinal list. */ + int32* m_schemaOrdinalList; + + int32 m_relAttrNum; + + carbondata::IndexFileReader m_indexfile_reader; + + carbondata::format::IndexHeader m_indexheader; + + std::vector m_vec_blockindex; +}; +} // namespace reader +} // namespace dfs +#endif /* CARBONDATA_INDEX_READER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_am.h postgresql-hll-2.14/include/include/access/dfs/dfs_am.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_am.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,506 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_am.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_am.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_AM_H +#define DFS_AM_H + +#include "storage/dfs/dfs_connector.h" +#include "dfsdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "utils/bloom_filter.h" +#include "vecexecutor/vectorbatch.h" +#include "pgxc/locator.h" + +#define INVALID_ENCODING (-1) /* For hdfs table, there is no encoding */ + +extern void CleanupDfsHandlers(bool isTop); +extern void ResetDfsHandlerPtrs(void); +extern void RemoveDfsReadHandler(const void *handler); +extern void RemoveDfsWriteHandler(const void *handler); + +struct IndexInsertInfo; + +extern char *HdfsGetOptionValue(Oid foreignTableId, const char *optionName); +extern DefElem *HdfsGetOptionDefElem(Oid foreignTableId, const char *optionName); + +struct DfsScanState; +namespace dfs { +typedef uint64 uint64_t; +typedef int64 int64_t; + +/* The type of file to be read, there is only ORC currently. */ +enum FileType { + ORC = 0, + PARQUET = 1, + TEXT = 2, + CSV = 3, + CARBONDATA = 4 +}; + +namespace reader { + +typedef struct FileOffset { + uint32 rowIndexInFile[BatchMaxSize]; + uint32 numelements; +} FileOffset; + +/* + * The interface which provides some basic functions. + */ +class Reader : public BaseObject { +public: + virtual ~Reader() + { + } + + /* + * The reserved interface to add finish work when there is no rows + * to read. + */ + virtual void Destroy() = 0; + + /* + * Fetch the next one tuple. + * @_in_out_param tuple: The tuple to be filled by the reader. + */ + virtual void nextTuple(TupleTableSlot *tuple) = 0; + + /* + * Fetch the next 1000 or less rows in a vector batch. + * @_in_out_param batch: The vector batch to be filled by the reader. + */ + virtual void nextBatch(VectorBatch *batch) = 0; + + /* + * @Description: Fetch the next batch according to the tid vector batch. + * @IN/OUT batch: vector batch + * @IN tids: tid vector batch + * @See also: + */ + virtual void nextBatchByTids(VectorBatch *batch, VectorBatch *tidBatch) = 0; + + /* + * Fetch the next batch according to the tid vector batch which includes all the columns we need. + * @OUT batch: the target vector batch + * @IN tidBatch: the tid vector batch + * @IN prepareCols: the prepared cols list in the tid vector batch + */ + virtual void nextBatchByTidsForIndexOnly(VectorBatch *batch, VectorBatch *tidBatch, List *prepareCols) = 0; + + /* + * Add a bloom filter into the reader. + * @_in_param bloomFilter: The bloom filter to be added. + * @_in_param colIdx: The index of the column on which to add the bloom filter. + * @_in_param is_runtime: Is between runtime or not. + */ + virtual void addBloomFilter(filter::BloomFilter *bloomFilter, int colIdx, bool is_runtime) = 0; + + /* + * Copy bloomFilter to runTimeBloomFilter + */ + virtual void copyBloomFilter() = 0; + + /* + * The reserved interface to add prepared processes before calling + * @_in_param conn: The connector handler to hdfs. + * @_in_param type: The type of the file to read. + * the nextBatch. + */ + virtual void begin(dfs::DFSConnector *conn, FileType type) = 0; + + /* + * Handle the tailing works which are not destroyers. + */ + virtual void end() = 0; + + /* Get DFS table name */ + virtual const char *getRelName() = 0; + + /* Get the current reader's transaction ID. */ + virtual const int getCurrentTransactionLevel() = 0; + + /* Just before the first execution iterator, we assign splits for current worker. */ + virtual void dynamicAssignSplits() = 0; +}; + +/* + * Includes all the params which are used during reading. + */ +typedef struct ReaderState { + /* DFS storage type */ + int dfsType; + + /* The number of the columns defined in the relation. */ + uint32_t relAttrNum; + + /* The number of parition columns. */ + uint32_t partNum; + + /* + * The mapping array from mpp column index to file column index, this + * has been adjusted for partition and default columns. + */ + uint32_t *readColIDs; + + /* + * When create ReaderImpl object, initialize the globalColIds, It represnets + * a possible column order in file. The partition column index has any meaning. + * The globalColIds must used in conjunction with globalReadRequired. + * It starts from 0. + */ + uint32_t *globalColIds; + + /* + * The mapping array from the column id defined in relation to column id + * stored in file, this start at 1 and will be null for non-partition table. + */ + uint32_t *colNoMapArr; + + /* + * The ordered column id according to the selectivity. Use the + * column id defined in relation to visit it. + */ + uint32_t *orderedCols; + + /* Count up the number of files wich are static pruned */ + uint64_t staticPruneFiles; + + /* Count up the number of files which are pruned dynamically. */ + uint64_t dynamicPrunFiles; + + /* Count up the number of rows which are filtered by the bloom filter. */ + uint64_t bloomFilterRows; + + /* Count up the number of strides which are filtered by the bloom filter. */ + uint64_t bloomFilterBlocks; + + /* Count up the number of rows which are filtered by the min/max. */ + uint64_t minmaxFilterRows; + + /* min/max filtering data */ + uint64_t minmaxCheckFiles; /* the number of checking files totally */ + uint64_t minmaxFilterFiles; /* the number of filtered files */ + uint64_t minmaxCheckStripe; /* the number of checking stripes totally */ + uint64_t minmaxFilterStripe; /* the number of filtered stripes, orc is stripe and parquet is row group */ + uint64_t minmaxCheckStride; /* the number of checking strides totally */ + uint64_t minmaxFilterStride; /* the number of filtered strides, orc is stride and parquet is chunk page */ + + /* Count up the number of cache hint of orc data */ + uint64 orcDataCacheBlockCount; + uint64 orcDataCacheBlockSize; + /* Count up the number of load of orc data */ + uint64 orcDataLoadBlockCount; + uint64 orcDataLoadBlockSize; + /* Count up the number of cache hint of orc meta data */ + uint64 orcMetaCacheBlockCount; + uint64 orcMetaCacheBlockSize; + /* Count up the number of oad of orc meta data */ + uint64 orcMetaLoadBlockCount; + uint64 orcMetaLoadBlockSize; + + /* + * The array stores the the columns which is required by the query + * and includes the satisfied partition columns. + */ + bool *isRequired; + + /* + * The array to indicate which columns need to be send back + * and includes the satisfied partition columns. + */ + bool *targetRequired; + + /* + * The array to indicate which columns have restrictions. Normally we ignore the + * partition columns unless the restriction comes from the run time predicate. + */ + bool *restrictRequired; + + /* + * The array to indicate which columns need to be read from the file + * and excludes the partition columns with the non-exist columns. + */ + bool *readRequired; + /* + * When create ReaderImpl object, initialize the globalReadRequired. it represents + * which column may be read from file. not include partition column. + */ + bool *globalReadRequired; + + /* The list of files to be read. */ + List *splitList; + + /* The list of the required columns including the partition columns. */ + List *allColumnList; + + /* The list of partition columns. */ + List *partList; + + /* The list of restrictions for block skip. */ + List *queryRestrictionList; + List *runtimeRestrictionList; + + /* + * The list array stores the predicates upon each column. Use the + * column id stored in file to visit it. + */ + List **hdfsScanPredicateArr; + + /* + * The array of string stores value of partition column for each file. + * Use the column id defined in relation to visit it. + */ + char **partitionColValueArr; + + /* The array of bloom filters on each column. */ + filter::BloomFilter **bloomFilters; + + /* The current file to be read. */ + SplitInfo *currentSplit; + + /* + * The pointer to the file reader which need to be cleared when error occurs, + * So i add it here to avoid resource leak. + */ + Reader *fileReader; + + /* hdfs table <= 0, forigen table < 0(-1) */ + int currentFileID; + + /* The size of the current file, this is 0 for foreign table. */ + int64_t currentFileSize; + + /* The memory context to store the persist state when reading the file. */ + MemoryContext persistCtx; + + /* The memory contex which will be reset when rescaning. */ + MemoryContext rescanCtx; + + /* Scan state. */ + ScanState *scanstate; + + /* The snapshot used while reading. */ + Snapshot snapshot; + + /* Count up the number of hdfs local/remote block read by dn. */ + uint64_t localBlock; + uint64_t remoteBlock; + + /* Count the number of intersections with dfs namenode/datanode. */ + uint64_t nnCalls; + uint64_t dnCalls; + + /* Encoding type for the dfs foreign table. */ + int fdwEncoding; + + /* The level of encoding check,2 = high, 1 = low, 0 = no check */ + int checkEncodingLevel; + + /* Count how many elements are invalid for the encoding and are converted to ? automatically. */ + int incompatibleCount; + int dealWithCount; + + /* special case for obs scan time */ + instr_time obsScanTime; +} ReaderState; + +/* + * @Description: The factory function to create a reader for ORC file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createOrcReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for Parquet file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createParquetReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for Carbondata file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader* createCarbondataReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for TEXT file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createTextReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: The factory function to create a reader for CSV file. + * @IN readerState: the state information for reading + * @IN conn: the connector to dfs + * @IN skipSysCol: skip reading system columns if true + * @Return: the reader pointer + * @See also: + */ +Reader *createCsvReader(ReaderState *readerState, dfs::DFSConnector *conn, bool skipSysCol); + +/* + * @Description: Initialize the neccessary variables for analyze or copy to on dfs table(not foreign table). + * @IN rel: The relation to scan. + * @IN splitList: The list of file to scan. + * @IN colNum: The number of the columns for scanning, set it 0 if colIdx is null. + * @IN colIdx: The target column list((with system column at tail)1,2,..,-1) for scanning, scan all the columns if this + * is null. + * @IN snapshot: The snapshot(NULL, mvcc or snapshotNow). + * @Return: the DfsScanState which is build inside the function. + * @See also: + */ +DfsScanState *DFSBeginScan(Relation rel, List *splitList, int colNum, int16 *colIdx, Snapshot snapshot = NULL); + +/* + * Fetch the next vector batch for analyze or copy to on dfs table(not foreign table). + * _in_param scanState: The state for scaning which is returned by DFSBeginScan. + * @return the vector batch. + */ +VectorBatch *DFSGetNextBatch(DfsScanState *scanState); + +/* + * Fetch the next tuple of dfs table for analyze operator. The table to be scanned is not + * foreign HDFS table. + * _in_param scanState: The state for scaning which is returned by DFSBeginScan. + * _out_param scanTupleSlot: The TupleTableSlot struct in which the scanned tuple is filled. + * @return None. + */ +void DFSGetNextTuple(DfsScanState *scanState, TupleTableSlot *scanTupleSlot); + +/* + * Destroy the neccessary variables when the scan is over. + * @_in_param scanState: The state for scaning which is returned by DFSBeginScan. + */ +void DFSEndScan(DfsScanState *scanState); + +} // namespace reader + +namespace writer { + +class Writer : public BaseObject { +public: + virtual ~Writer() + { + } + + /* Initialize the class member, this must be called just after construct a new object. */ + virtual void init(IndexInsertInfo *indexInsertInfo) = 0; + + /* Add a batch into the buffer. */ + virtual void appendBatch(const VectorBatch *batch) = 0; + + /* Add a tuple into the buffer. */ + virtual void appendTuple(Datum *values, bool *nulls) = 0; + + /* Check if the buffer is available to hold special number of rows. */ + virtual bool canAppend(uint64 size) = 0; + + /* Spill the buffer into the current file. */ + virtual int spillToCurFile() = 0; + + /* Spill the buffer into a new file. */ + virtual int spillToNewFile(const char *filePath) = 0; + + /* Spill the buffer into delta table. */ + virtual void deltaInsert(int option) = 0; + + /* Set the file ID of the current writer. */ + virtual void setFileID(uint64 fileID) = 0; + + /* Get the file ID of the current writer. */ + virtual uint64 getFileID() = 0; + + /* Get the rows in the hdfs file, this function must be called after the m_orcWriter is closed. */ + virtual uint64 getTotalRows() = 0; + + /* Get the totoal number of serialized rows of the current writer. */ + virtual uint64 getSerializedRows() = 0; + + /* Get the totoal number of buffer rows of the current writer. */ + virtual uint64 getBufferRows() = 0; + + /* + * @Description: Acquire the min max value of the column. Return false when there is no min/max. + * @IN colId: the column id + * @OUT minStr: the string of min value if exist + * @OUT maxStr: the string of max value if exist + * @OUT hasMin: whether the min value exist + * @OUT hasMax: whether the max value exist + * @Return: false if there is no min or max value of the column, else return true. + * @See also: + */ + virtual bool getMinMax(uint32 colId, char *&minstr, char *&maxstr, bool &hasMin, bool &hasMax) = 0; + + /* Close the current writer and flush the data and return the file size. */ + virtual int64 closeCurWriter(char *filePath) = 0; + + /* Clean the class member. */ + virtual void Destroy() = 0; + + /* Get DFS table name */ + virtual const char *getRelName() = 0; + + /* Deal the clean works on dfs writer. */ + virtual void handleTail() = 0; + + /* Get the current writer's transaction ID. */ + virtual const int getCurrentTransactionLevel() = 0; +}; + +/* + * @Description: Create an instance of orc writer + * @IN context: memory context + * @IN rel: the current relation + * @IN DestRel: the dest relation(used for vacuum) + * @IN IndexInsertInfo: includes index information + * @IN parsig: dirctory information which is used for value partition table + * @Return: writer pointer + * @See also: + */ +Writer *createOrcWriter(MemoryContext context, Relation rel, Relation DestRel, IndexInsertInfo *indexInsertInfo, + const char *parsig); + +} // namespace writer +} // namespace dfs + +List *BuildSplitList(Relation rel, StringInfo RootDir, Snapshot snapshot = NULL); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_common.h postgresql-hll-2.14/include/include/access/dfs/dfs_common.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_common.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,178 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_common.h + * + * IDENTIFICATION + * src/include/access/dfs/dfs_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_COMMON_H +#define DFS_COMMON_H + +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +#ifndef MIN +#define MIN(A, B) ((B) < (A) ? (B) : (A)) +#endif + +#define DFS_PRIVATE_ITEM "DfsPrivateItem" +#define DFS_NUMERIC64_MAX_PRECISION 18 + +/* MACROS which help to catch and print the exception. */ +#define DFS_TRY() \ + bool saveStatus = t_thrd.int_cxt.ImmediateInterruptOK; \ + t_thrd.int_cxt.ImmediateInterruptOK = false; \ + bool errOccur = false; \ + int errNo = ERRCODE_SYSTEM_ERROR; \ + StringInfo errMsg = makeStringInfo(); \ + StringInfo errDetail = makeStringInfo(); \ + try +#define DFS_CATCH() \ + catch (abi::__forced_unwind &) \ + { \ + throw; \ + } \ + catch (orc::OrcException & ex) \ + { \ + errOccur = true; \ + errNo = ex.getErrNo(); \ + try { \ + appendStringInfo(errMsg, "%s", ex.what()); \ + appendStringInfo(errDetail, "%s", ex.msg().c_str()); \ + } catch (abi::__forced_unwind &) { \ + throw; \ + } catch (...) { \ + } \ + } \ + catch (std::exception & ex) \ + { \ + errOccur = true; \ + try { \ + appendStringInfo(errMsg, "%s", ex.what()); \ + } catch (abi::__forced_unwind &) { \ + throw; \ + } catch (...) { \ + } \ + } \ + catch (...) \ + { \ + errOccur = true; \ + } \ + t_thrd.int_cxt.ImmediateInterruptOK = saveStatus; \ + saveStatus = InterruptPending; \ + InterruptPending = false; \ + if (errOccur && errDetail->len > 0) { \ + ereport(LOG, (errmodule(MOD_DFS), errmsg("Caught exceptiion for: %s.", errDetail->data))); \ + } \ + InterruptPending = saveStatus; \ + pfree_ext(errDetail->data); \ + pfree_ext(errDetail); + +#define DFS_ERRREPORT(msg, module) \ + if (errOccur) { \ + destroy(); \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + +#define DFS_ERRREPORT_WITHARGS(msg, module, ...) \ + if (errOccur) { \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, __VA_ARGS__, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + +#define DFS_ERRREPORT_WITHOUTARGS(msg, module) \ + if (errOccur) { \ + ereport(ERROR, (errcode(errNo), errmodule(module), \ + errmsg(msg, errMsg->data, g_instance.attr.attr_common.PGXCNodeName))); \ + } \ + pfree_ext(errMsg->data); \ + pfree_ext(errMsg); + + +#define DEFAULT_HIVE_NULL "__HIVE_DEFAULT_PARTITION__" +#define DEFAULT_HIVE_NULL_LENGTH 26 + +/* + * Check partition signature creation exception in case of the content exceeding + * max allowed partition length + */ +#define partition_err_msg \ + "The length of the partition directory exceeds the current value(%d) of the option " \ + "\"dfs_partition_directory_length\", change the option to the greater value." +#define CHECK_PARTITION_SIGNATURE(rc, dirname) do { \ + if (rc != 0) { \ + ereport(ERROR, (errcode(ERRCODE_DATA_EXCEPTION), errmodule(MOD_DFS), \ + errmsg(partition_err_msg, u_sess->attr.attr_storage.dfs_max_parsig_length), \ + errdetail("the path name is \"%s\".", dirname))); \ + } \ + securec_check(rc, "\0", "\0"); \ +} while (0) + +#define strpos(p, s) (strstr(p, s) != NULL ? strstr(p, s) - p : -1) +#define basename_len(p, s) (strrchr(p, s) != NULL ? strrchr(p, s) - p : -1) + +#define INT_CMP_HDFS(arg1, arg2, compare) do { \ + if ((arg1) < (arg2)) { \ + compare = -1; \ + } else if ((arg1) > (arg2)) { \ + compare = 1; \ + } else { \ + compare = 0; \ + } \ +} while (0) + +/* + * 1. NAN = NAN + * 2. NAN > non-NAN + * 3. non-NAN < NAN + * 4. non-NAN cmp non-NAN + * 5. arg2 will never be NAN here + */ +#define FLOAT_CMP_HDFS(arg1, arg2, compare) do { \ + if (isnan(arg1)) { \ + compare = 1; \ + } else { \ + if ((arg1) > (arg2)) { \ + compare = 1; \ + } else if ((arg1) < (arg2)) { \ + compare = -1; \ + } else { \ + compare = 0; \ + } \ + } \ +} while (0) + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_delete.h postgresql-hll-2.14/include/include/access/dfs/dfs_delete.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_delete.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_delete.h 2020-12-12 17:06:43.132346554 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_delete.h + * routines to support DFS(such as HDFS, DFS,...) + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_delete.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_DELETE_H +#define DFS_DELETE_H + +#include "access/cstore_delete.h" +#include "dfsdesc.h" + +class DfsDelete : public CStoreDelete { +public: + DfsDelete(Relation, EState *, bool is_update = false, Plan *plan = NULL, MemInfoArg *m_dfsInsertMemInfo = NULL); + virtual ~DfsDelete(); + + /* + * save batch to sort cache + */ + void PutDeleteBatch(VectorBatch *, JunkFilter *); + + /* + * called on deinitialization, make sure that tids in sort cache can be + * deleted. + */ + uint64 ExecDelete(); + + /* + * do "delete" job really with tids in sort cache, and return the number of + * deleted rows. + */ + uint64 ExecDeleteForTable(); + +protected: + /* + * used to handle desc table, such as mark deletemap, ... + */ + DFSDescHandler *m_handler; +}; + +#endif /* DFS_DELETE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_insert.h postgresql-hll-2.14/include/include/access/dfs/dfs_insert.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_insert.h 2020-12-12 17:06:43.133346567 +0800 @@ -0,0 +1,459 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_insert.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_insert.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_INSERT_H +#define DFS_INSERT_H + +#include "access/dfs/dfs_am.h" +#include "access/cstore_insert.h" +#include "access/cstore_psort.h" +#include "access/cstore_vector.h" +#include "catalog/heap.h" +#include "catalog/pg_partition.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "vecexecutor/vectorbatch.h" + +class DfsInsertInter; + +/* + * ScalarValue => Datum, Datum should point to data without length header + * for varing length data type. + */ +extern Datum convertScalarToDatum(Oid typid, ScalarValue val); + +/* + * Create the insertion object for dfs table. + */ +extern DfsInsertInter *CreateDfsInsert(Relation rel, bool is_update, Relation dataDestRel = NULL, Plan *plan = NULL, + MemInfoArg *m_dfsInsertMemInfo = NULL); + +/* The globle variable which contains the insert files' info. */ +extern HTAB *g_dfsSpaceCache; + +typedef void (*InsertPendingFunc)(const char *, Oid, uint64); + +/* options for cstore_insert_mode */ +#define TO_AUTO 1 /* means enable_delta_store = true, tail data to delta table */ +#define TO_MAIN 2 /* means enable_delta_store = false, all data to hdfs store */ +#define TO_DELTA 3 /* new option, all data to delta table */ + +#define MAX_PARSIG_LENGTH (u_sess->attr.attr_storage.dfs_max_parsig_length + 1) +#define MAX_PARSIGS_LENGTH (VALUE_PARTKEYMAXNUM * u_sess->attr.attr_storage.dfs_max_parsig_length + 1) + +#define MAX_ACTIVE_PARNUM ((u_sess->attr.attr_storage.partition_max_cache_size * 1024L) / (64 * 1024 * 1024)) + +typedef struct IndexInsertInfo { + /* psort index need */ + Relation *idxRelation; + int *idxKeyNum; + InsertArg *idxInsertArgs; /* index inserting arguments */ + CStoreInsert **idxInsert; + int **idxKeyAttr; + int maxKeyNum; + int indexNum; +} IndexInsertInfo; + +/* Construct the struct of index insert information. */ +extern IndexInsertInfo *BuildIndexInsertInfo(Relation rel, ResultRelInfo *resultRelInfo); + +/* + * The Dfs table insert handler, it provides basic interface for Dfs insert protocol + * > BeginBatchInsert() + * > BatchInsert()/TupleInsert() + * > SetEnd() + * > Destroy() + * + * Which is exposed to executor/vecexcetutor level + */ +class DfsInsertInter : public BaseObject { +public: + virtual ~DfsInsertInter(){}; + + /* Prepare the members which are needed while inserting. */ + virtual void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL) = 0; + + /* Insert a vector batch into DFS. */ + virtual void BatchInsert(VectorBatch *batch, int option) = 0; + + /* Insert a tuple into DFS. */ + virtual void TupleInsert(Datum *values, bool *nulls, int option) = 0; + + /* Clean the member. */ + virtual void Destroy() = 0; + + /* empty function, just for FLUSH_DATA */ + virtual void EndBatchInsert() = 0; + + /* Set the end flag. */ + inline void SetEndFlag() + { + m_end = true; + }; + + /* Get the end flag */ + inline bool isEnd() + { + return m_end; + }; + + /* data redistribution for DFS table. */ + /* Set dataDestRel. */ + inline void setDataDestRel(Relation dataDestRel) + { + m_dataDestRelation = dataDestRel; + }; + + /* Set the index insert object. */ + inline void setIndexInsertInfo(IndexInsertInfo *indexInsertInfo) + { + m_indexInsertInfo = indexInsertInfo; + m_indexInfoOuterDestroy = true; + } + + /* Get dataDestRel. */ + inline Relation getDataDestRel() + { + return m_dataDestRelation; + }; + + /* register function which can insert new file name to pendingDfsDelete */ + inline void RegisterInsertPendingFunc(InsertPendingFunc fn) + { + m_insert_fn = fn; + } + + /* Clean the object of index insert if it is not set outer. */ + inline void clearIndexInsert() + { + if (NULL != m_indexInsertInfo && !m_indexInfoOuterDestroy) { + for (int i = 0; i < m_indexInsertInfo->indexNum; ++i) { + if (m_indexInsertInfo->idxInsert[i] != NULL) { + m_indexInsertInfo->idxInsert[i]->SetEndFlag(); + m_indexInsertInfo->idxInsert[i]->BatchInsert((bulkload_rows *)NULL, 0); + DELETE_EX(m_indexInsertInfo->idxInsert[i]); + CStoreInsert::DeInitInsertArg(m_indexInsertInfo->idxInsertArgs[i]); + } + relation_close(m_indexInsertInfo->idxRelation[i], RowExclusiveLock); + } + } + } + +public: + /* + * The m_dataDestRelation keeps the data path destination when execute insert operation. + * If the m_dataDestRelation is NULL, the data path destination would be acquired from + * m_relation. + * In the process of data redistribution, when execute the following command + * "insert into dataDestRelation select * form redistribution_table",there are two + * file lists in HDFS directory of redistribution table. The new files that + * are produced by the above command will be existed in HDFS directory of + * redistribution table. The old files is data of redistribution table. + * The two file lists must keep it until finish commit or abort transaction. + * If commit, delete the old file(file of redistribution table), + * otherwise delete new file. + */ + Relation m_dataDestRelation; + +protected: + /* The end flag which must be set outside. */ + bool m_end; + + /* + * The columns bitmap, it excludes dropped columns. + * When insert data to new file, must insert column bitmap to DESC table. + * Every file has different columns, only get the real columns by colmap of DESC table. + */ + char *m_colMap; + + /* used to insert new orc file name to pendingDfsDelete */ + InsertPendingFunc m_insert_fn; + + /* Index cstore insert info */ + IndexInsertInfo *m_indexInsertInfo; + bool m_indexInfoOuterDestroy; +}; + +class DfsInsert : public DfsInsertInter { +public: + DfsInsert(Relation relation, bool is_update, const char *parsigs = NULL, Plan *plan = NULL, + MemInfoArg *ArgmemInfo = NULL); + virtual ~DfsInsert(){}; + + /* prepare the memory for insert and sort to use. plan is for insert condition, ArgmemInfo is for update condition. */ + void InitInsertMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + + /* Prepare the members which are needed while inserting. */ + void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL); + + /* Insert a vector batch into DFS. */ + void BatchInsert(VectorBatch *batch, int option); + + /* Insert a tuple into DFS. */ + void TupleInsert(Datum *values, bool *nulls, int option); + + /** + * @Description: Set the column map for DFS table. Get the all columns + * from pg_attribute, but excludes dropped columns. + * @return None. + */ + void setColMap(); + + /** + * @Description: Get the column map for DFS table. + * @return Node. + */ + const char *getColMap() + { + Assert(NULL != m_colMap); + return m_colMap; + } + + /* Initialize the dfs space cache. */ + static void InitDfsSpaceCache(); + + /* Remove the file space alloc cache. */ + static void InvalidSpaceAllocCache(Oid relid); + + /* Remove all the elements in the space cache. */ + static void ResetDfsSpaceCache(void); + + /* Clean the member. */ + virtual void Destroy(); + + /* empty function, just for FLUSH_DATA */ + void EndBatchInsert(){}; + +private: + /* The internal entry for batch insert. */ + void batchInsertInternal(VectorBatch *batch, int option, bool isEnd); + + /* THe internal entry for tuple insert. */ + void tupleInsertInternal(Datum *values, bool *nulls, int option, bool isEnd); + + /* Initialze the fixed prefix of file path. */ + void initPathPrefix(); + + /* Acquire the absolute path according to the file id. */ + char *getFilePath(uint64 offset) const; + + /* Acquire the file name of the path according to the file id. */ + char *getFileName(uint64 offset) const; + + /* Get the max file ID stored in btree index. */ + uint32 GetMaxIndexFileID(Relation heapRel); + + /* Acquire the max file id stored in space cache for rel. */ + uint64 getMaxFileID(Relation rel) const; + + /* Check if the space cache already exist. */ + bool dfsSpaceCacheExist(Oid relOid) const; + + /* Build the space cache according to maxFileID with entry "relid". */ + void buildSpaceAllocCache(Oid relid, uint64 maxFileID) const; + + /* + * Initialize the file space alloc cache to provide unique file id + * according to desc table of rel concurrently. + */ + void initSpaceAllocCache(Relation rel); + + /* Get the next file id which must be unique from global hashtable with entry "relOid". */ + uint64 allocNextSpace(Oid relOid) const; + + /* Spill the buffer into DFS. */ + void spillOut(int option); + + /* Deal with the tail data when the insert process ends. */ + void handleTailData(int option); + + /* Insert a record into desc table. */ + void descInsert(int option); + + inline bool NeedPartialSort() + { + return m_sorter != NULL; + } + +private: + Relation m_relation; + bool m_isUpdate; + TupleDesc m_desc; + + /* The common prefix of all the file path. */ + StringInfo m_filePathPrefix; + + /* The writer to store the buffer and save the file. */ + dfs::writer::Writer *m_writer; + + /* If relation has cluster key, it will work for partial sort. */ + CStorePSort *m_sorter; + + /* The memory context which will be cleaned for each insert iteration. */ + MemoryContext m_iterContext; + + /* The flag which indicates whether we need to create a new file while spilling in the next time. */ + bool m_nextFile; + + /* valid iff TO_DELTA == cstore_insert_mode */ + Relation m_delta; + Datum *m_values; + bool *m_nulls; + + /* dfs insert partition memory info. */ + MemInfoArg *m_dfsInsertMemInfo; + +public: + /* partitioned ONLY */ + StringInfo m_parsigs; +}; + +typedef struct PartitionStagingFile { + StringInfo parsig; + BufFile *sfile; +} PartitionStagingFile; + +class DfsPartitionInsert : public DfsInsertInter { +public: + DfsPartitionInsert(Relation relation, bool is_update, Plan *plan = NULL, MemInfoArg *ArgmemInfo = NULL); + virtual ~DfsPartitionInsert(){}; + + /* Prepare the members which are needed while inserting. */ + void BeginBatchInsert(int type, ResultRelInfo *resultRelInfo = NULL); + + /* empty function, just for FLUSH_DATA */ + void EndBatchInsert(){}; + + /* Insert a vector batch into DFS. */ + void BatchInsert(VectorBatch *batch, int option); + + /* Insert a tuple into DFS. */ + void TupleInsert(Datum *values, bool *nulls, int option); + + /* Clean the member. */ + virtual void Destroy(); + + /* init insert memory info. */ + void InitInsertPartMemArg(Plan *plan, MemInfoArg *ArgmemInfo); + +private: + /* + * Get One partition's DfsInsert by scanning p_pWriters[], if there is no writer slot + * available in current DfsPartitionInsert, return NULL to let caller to proper + * do action like swap tuple content to disk as temp files + */ + inline DfsInsert *GetDfsInsert(const char *parsig); + + /* + * Form a partition signature targeting to identify a parition directory for + * real data file layout. e.g c1=1/c2=1/c3=5/ + * + * Note: Per-Tuple invoking so INLINE defined + */ + inline void GetCStringFromDatum(Oid typeOid, int typeMode, Datum value, const char *attname, char *buf) const; + + /* + * Create a partition signature with current tuple(values/nulls) + */ + inline char *FormPartitionSignature(Datum *values, const bool *nulls); + + /* + * Flush buffer tuples into ORCfile or delta table also including those swapped + * in staging file + */ + void HandleTailData(int option); + + /* + * ------- member values ------------------------------- + * Pre-allocated partition-signatures to buffer the content of which is 'c1=1/c2=1/c3=1/', + * allocated at DfsPartitionInsert constructor + */ + char *m_parsigs; + + /* The relation of the partition table. */ + Relation m_relation; + bool m_isUpdate; + + /* The tuple description of the m_relation. */ + TupleDesc m_desc; + + /* The information of index. */ + ResultRelInfo *m_resultRelInfo; + + /* + * The common prefix of all the file path. + * e.g /user/tzhong/30_tzhong_mppdb.db/postgres/public.t1p/ + */ + StringInfo m_tableDirPath; + + /* + * Temp files hold tuples whose DfsInsert is not in active list when number of + * partition exceeds MAX allowed partitions. + */ + PartitionStagingFile **m_partitionStagingFiles; + + /* The context for partition buffer files. */ + MemoryContext m_partitionCtx; + + /* cache of for spilled partitions */ + HTAB *m_SpilledPartitionSearchCache; + + /* cache of for active partitions */ + HTAB *m_ActivePartitionSearchCache; + + /* TUPLE_SORT or BATCH_SORT */ + int m_type; + + /* + * Array length of m_parttitionStagingFiles + */ + int m_numPartitionStagingFiles; + + /* + * Get paritition staging file handler with given partition signature + */ + PartitionStagingFile *GetPartitionStagingFile(const char *parsig); + + /* valid iff TO_DELTA == cstore_insert_mode */ + Relation m_delta; + + /* Array for values and null flags. */ + Datum *m_values; + bool *m_nulls; + + /* + * Active 'patition writer' which is used to do TupleInsert() + */ + DfsInsert **m_pDfsInserts; + + /* The max number of writers which can be used for one partition writer */ + int m_maxPartitionWriters; + + /* The number of active writers for partition table currently. */ + int m_activePartitionWriters; + + /* dfs insert partition memory info. */ + MemInfoArg *dfsPartMemInfo; +}; +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_query_check.h postgresql-hll-2.14/include/include/access/dfs/dfs_query_check.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_query_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_query_check.h 2020-12-12 17:06:43.133346567 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query_check.h + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query_check.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_QUERY_CHECK_H +#define DFS_QUERY_CHECK_H + +#include "access/dfs/dfs_wrapper.h" +/* + * Function to check if a value of basic type can match the clauses list pushed down. Here we do not + * check the length of scanClauses, and the caller need ensure it. + * + * @_in param value: The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * @_in param scanClauses: Clauses which can be pushed down to orc reader. + * + * @return True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + */ +template +bool HdfsPredicateCheckValue(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNULL == predicate->m_strategy) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + + return true; +} + +/* + * Function to check if a null value can match the clauses list pushed down. + * + * @_in param scanClauses: Clauses which can be pushed down for the partition and orc reader. + * + * @return True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + */ +template +bool HdfsPredicateCheckNull(List *scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + if (0 == list_length(scanClauses)) + return true; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + if (true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNULL == predicate->m_strategy) { + continue; + } else { + return false; + } + } + + return true; +} + +/* + * @Description: Check the column value by predicates. + * @in isNull, Whether the column is null value. + * @in value, If the column is not null, it presents the column value. + * @in predicateList, The pushdown predicates on this column. + * @return If the column value satisfies the predicates, return true, otherwise + * return false. + */ +template +bool HdfsPredicateCheck(bool isNull, baseType value, List *predicateList) +{ + bool filtered = false; + if (isNull) { + filtered = HdfsPredicateCheckNull(predicateList); + } else { + filtered = HdfsPredicateCheckValue(value, predicateList); + } + + return filtered; +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_query.h postgresql-hll-2.14/include/include/access/dfs/dfs_query.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_query.h 2020-12-12 17:06:43.133346567 +0800 @@ -0,0 +1,583 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_QUERY_H +#define DFS_QUERY_H + +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +#define DFS_PRIVATE_ITEM "DfsPrivateItem" +#define DFS_NUMERIC64_MAX_PRECISION 18 + +#ifdef ENABLE_LLVM_COMPILE +extern bool CodeGenThreadObjectReady(); +extern bool ForeignScanExprCodeGen(Expr *expr, PlanState *parent, void **jittedFunc); + +/* + * Declare the function pointers for LLVM machine code address. + */ +typedef bool (*evaPredicateDouble)(double value); +typedef bool (*evaPredicateInt)(int64_t value); +#endif + +/* + * define the strategy numbers for hdfs foriegn scan. -1 is invalid, + * 0-6 stand for op strategy, 11-12 stand for isnull/is not null. + */ +typedef enum { + HDFS_QUERY_INVALID = -1, + + /* + * 0-6 stand for OpExpr strategy, + * HDFS_QUERY_EQ: '=' + * HDFS_QUERY_LT: '<' + * HDFS_QUERY_GT: '>' + * HDFS_QUERY_LTE: '<=' + * HDFS_QUERY_GTE: '>=' + * HDFS_QUERY_NE1: '<>' + * HDFS_QUERY_NE2: '!=' + */ + HDFS_QUERY_EQ = 0, + HDFS_QUERY_LT = 1, + HDFS_QUERY_GT = 2, + HDFS_QUERY_LTE = 3, + HDFS_QUERY_GTE = 4, + HDFS_QUERY_NE1 = 5, + HDFS_QUERY_NE2 = 6, + + /* 11-12 stand for isnull/is not null */ + HDFS_QUERY_ISNULL = 11, + HDFS_QUERY_ISNOTNULL = 12, +} HdfsQueryOperator; + +typedef enum { + NO_ENCODING_CHECK = 0, + LOW_ENCODING_CHECK = 1, + HIGH_ENCODING_CHECK = 2 +} EncodingLevel; + +/* + * A template class which stores the info from the expression. This predicate will be pushed down to orc reader and + * check it before the conversion to datum. + */ +template +class HdfsScanPredicate : public BaseObject { +public: + AttrNumber m_attno; // column no + Oid m_attType; // column data type + int32 m_varTypMod; // the var type of the value + HdfsQueryOperator m_strategy; // the number of strategy + Oid m_collation; // collation to use, if needed + bool m_keepFalse; // the check result keeps false if it is true + T *m_argument; // store value +#ifdef ENABLE_LLVM_COMPILE + char *m_predFunc; /* IR function pointer */ + bool m_isPredJitted; /* whether use LLVM optimization or not. if the m_isPredJitted is true, use it */ + void *m_jittedFunc; /* machine code address pointer. */ +#endif + +public: + /* + * Construct function of template class HdfsScanPredicate + * + * @_in param attNo: the index no of the column in the relation defination. + * @_in param attType: the data type oid of the current var. + * @_in param strategy: the HdfsQueryOperator(=,<,>,<=,>=,<>,!=,is null,is not null) + */ + HdfsScanPredicate(AttrNumber attNo, Oid attType, HdfsQueryOperator strategy, Oid collation, int32 varTypMod) + : m_attno(attNo), + m_attType(attType), + m_varTypMod(varTypMod), + m_strategy(strategy), + m_collation(collation), + m_keepFalse(false) + { + m_argument = New(CurrentMemoryContext) T(strategy); +#ifdef ENABLE_LLVM_COMPILE + m_predFunc = NULL; + m_isPredJitted = false; + m_jittedFunc = NULL; +#endif + } + + ~HdfsScanPredicate() + { + delete (m_argument); + m_argument = NULL; + } + + /* + * Initialize the m_argument of HdfsScanPredicate by datumValue if it is a operation predicate. + * + * @_in param datumValue: Just as the name says, it is a value of datum. + * @_in param datumType: THe data type of the datum. + */ + inline void Init(Datum datumValue, Oid datumType, int32 typeMod) + { + if (m_strategy >= HDFS_QUERY_EQ && m_strategy <= HDFS_QUERY_NE2) { + m_argument->SetValueFromDatum(datumValue, datumType, typeMod); + } + } + + /* + * Set the keepFalse flag. + * + * @_in param keepFalse: flag indicates whether the check result keeps false. + */ + inline void setKeepFalse(bool keepFalse) + { + m_keepFalse = keepFalse; + } + + /* + * Build HdfsScanPredicate which will be pushed down to orc_reader according to the filtered and-clauses, we + * can not push down the or-clauses now. + * + * @_in param expr: Expression which has been filtered by the optimizer. + * @_in param state: PlanState is used when the expr is extern_param or exec_param to afford information. + * @_in param scanstate: ScanState is used when init rumtime predicate. + * @_in param varNoPos: An order number of var in the hdfsScanPredicateArr. + * @_in param predicateArrPos: The parameter predicate position in *hdfsScanPredicateArr. + * @return True: has init predicate; False, do not init predicate, need init dynamicly on running time phase. + */ + bool BuildHdfsScanPredicateFromClause(Expr *expr, PlanState *ps, ScanState *scanstate, AttrNumber varNoPos, + int predicateArrPos); + + /* + * Check the value by the predicate. + * + * @_in param value: The value to be checked, it is of basic type like int64 or char*. + * @return True: match and not filtered; False: filtered and set isSelected to false. + */ + inline bool HdfsPredicateCheckOne(baseType value) + { + return m_argument->CheckPredicate(value, m_collation); + } +}; + +#ifdef ENABLE_LLVM_COMPILE +/* + * Brief : Function to check if a value of basic type can match the clauses list pushed + * down. Here we do not check the length of scanClauses, and the caller need ensure it. + * Description : + * Input : value, The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * scanClauses, Clauses which can be pushed down to orc reader. + * Output : None. + * Return Value : True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + * Notes : If the predicate->m_isPredJitted is true, we choose LLVM optimization to check scanclauses. + */ +template +bool HdfsPredicateCheckValueIntForLlvm(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (NULL != predicate->m_jittedFunc) { + if (!((evaPredicateInt)(predicate->m_jittedFunc))(value)) { + return false; + } + + } else { + if (HDFS_QUERY_ISNULL == predicate->m_strategy || true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + } + + return true; +} + +/* + * Brief : Function to check if a value of basic type can match the clauses list pushed + * down. Here we do not check the length of scanClauses, and the caller need ensure it. + * Description : + * Input : value, The value to be checked, can not be NULL (it will handled by HdfsPredicateCheckNull). + * scanClauses, Clauses which can be pushed down to orc reader. + * Output : None. + * Return Value : True: means the value match the predicate pushed down, so we can not prunning it, + * False: means the value does not match the predicate pushed down, so skip it. + * Notes : If the predicate->m_isPredJitted is true, we choose LLVM optimization to check scanclauses. + */ +template +bool HdfsPredicateCheckValueDoubleForLlvm(baseType &value, List *&scanClauses) +{ + ListCell *lc = NULL; + HdfsScanPredicate *predicate = NULL; + + foreach (lc, scanClauses) { + predicate = (HdfsScanPredicate *)lfirst(lc); + + if (NULL != predicate->m_jittedFunc) { + if (!((evaPredicateDouble)(predicate->m_jittedFunc))((double)value)) { + return false; + } + + } else { + if (HDFS_QUERY_ISNULL == predicate->m_strategy || true == predicate->m_keepFalse) { + return false; + } else if (HDFS_QUERY_ISNOTNULL == predicate->m_strategy) { + continue; + } else if (!predicate->HdfsPredicateCheckOne(value)) { + return false; + } + } + } + + return true; +} +#endif + + +/** + * @Description: Identify the qual which could be pushed down to + * file level(e.g. ORC reader level). + * @out hdfsPushDownQual: List to store all the clauses to push down. + * @in/out primitiveQual: As a input parameter, it represents all expression + * restrictions. As a output parameter, it represents actual expression + * restrictions for bottom scan(.e.g. dfs scan, foreign scan). + * @return Return the list of the column no which maps the pushdown qual. + */ +List *fix_pushdown_qual(List **hdfsPushDownQual, List **primitiveQual, const List *part_list); + +/* + * Convert a char* to Datum according to the data type oid. + * + * @_in param typeOid: The oid of the type in pg_type catalog. + * @_in param typeMod: The mod of data type. + * @_in param value: The string value which need to be converted to datum. + * @return Return the datum converted from String. + */ +Datum GetDatumFromString(Oid typeOid, int4 typeMod, char *value); + +void GetStringFromDatum(Oid typeOid, int4 typeMod, Datum data, StringInfo string); + +/* + * Initialize a folder split by the folder name, filename(both folder name and filename comprise the absolute file + * path), columnNo list of partition and column value list of partition. + * + * @_in param fileName: name of the file. + * @_in param partContentList: the list of value in partition column. + * @_in param objectSize: the size of the current object + * @return Return the constructed split. + */ +SplitInfo *InitFolderSplit(char *fileName, List *partContentList, int64 objectSize); + +/* + * Initialize a file split by the file path, columnNo list of partition and column value list of partition. This is + * different from InitFolderSplit for it use the absolute file path as the param and has no file name which is used for + * partition only. + * + * @_in param filePath: the absolute path of the split file. + * @_in param partContentList: the list of value in partition column. + * @_in param fileSize: the size of the current object + * @return Return the constructed split. + */ +SplitInfo *InitFileSplit(char *filePath, List *partContentList, int64 fileSize); + +/* + * Destroy all the structors in the split. + * @_in param split: The split need to to clean and is not used any more. + */ +void DestroySplit(SplitInfo *split); + +/* + * Build a basic Operator expression. + * @_in param variable: The var according to whose type we build the base constraint. + * @return Return and OpExpression. + */ +Node *MakeBaseConstraint(Var *variable, Datum minValue, Datum maxValue, bool hasMinimum, bool hasMaximum); + +Node *MakeBaseConstraintWithExpr(OpExpr *lessThanExpr, OpExpr *greaterThanExpr, Datum minValue, Datum maxValue, + bool hasMinimum, bool hasMaximum); + +OpExpr *MakeOperatorExpression(Var *variable, int16 strategyNumber); + +/* + * Build a new null test expr with the given type. + * + * @_in param variable: The value based on which we build a NullTest expression. + * @_in param type: is null or is not null. + * @return Return the NullTest expression we build here. + */ +Node *BuildNullTestConstraint(Var *variable, NullTestType type); + +/* + * Fill the expression with the const value. + * @_in param equalExpr: the expression of the constraint. + * @_in param value: Value to be filled for the right op. + * @_in param isNull: Whether the value is null. + * @return Return the constraint. + */ +void BuildConstraintConst(Expr *equalExpr, Datum value, bool isNull); + +/* + * Fetch the Var according to the column no from the columnList, used in partition filter. + * + * @_in param columnList: The column list from which we find the var. + * @_in param colNo: The column index by which we find the var. + * @return Return null: we don't find the var in the list with the colno; not null: we find the var and return it. + */ +Var *GetVarFromColumnList(List *columnList, int colNo); + +/* + * Return the digits of a int value. like 0 return 1, 10 return 2. + */ +uint64 GetDigitOfInt(uint64 x); + +/* + * Encode the uri char. Like "#" -> "%23", used in partition filter. + * + * @_in param pSrc: The uri format string to be encoded. + * @return Return the encoded string. + */ +char *UriEncode(const char *pSrc); + +/* + * Decode the uri char. Like "%23" -> "#", used in partition filter. + * + * @_in param pSrc: The uri format string to be decoded. + * @return Return the decoded string. + */ +char *UriDecode(const char *pSrc); + +/* + * Construct a node of DfsPrivateItem. + */ +DfsPrivateItem *MakeDfsPrivateItem(List *columnList, List *targetList, List *restrictColList, List *opExpressionList, + List *dnTask, List *hdfsQual, double *selectivity, int colNum, List *partList); + +/* + * Parse the fileNames string from the split List. + * @_in_out param splitList: point to the original split List, which may contain multiple files. + * @_in param currentFileName: point to the first file or the only file '/user/demai/file1.orc' (new buffer). + * @return Return the split parsed from the list. + */ +SplitInfo *ParseFileSplitList(List **splitList, char **currentFileName); + +/* + * @Description: find a split from the split list by file ID + * @IN splitList: the list of all splits + * @IN fileID: the file id + * @Return: the split if found, or return NULL + * @See also: + */ +SplitInfo *FindFileSplitByID(List *splitList, int fileID); + +/** + * @Description: Set all the rows of current ScalarVector with the same value transfered. + * The value can be null. + * @in vec, The scalar vector to which we set the value. + * @in rowsToRead, The number of rows to set. + * @in value: The fixed value to set all the rows. + * @in isNull, Whether the column value is null. + * @return None. + */ +void SetAllValue(ScalarVector *vec, int rows, Datum value, bool isNull); + +/* Brief: Acquires column information needed for this foreign table from the restriction. + * Returns them in a new list. + * input param @rel: relation information struct pointer. + */ +List *GetRestrictColumns(List *neededList, int count); + +/* + * Merge two list and kick out the repeated one. + * _in_param targetList: The list of the target columns. + * _in_param restrictList: The list of the restriction columns. + * _in_param count: The length of the result list. + * @return the merged and de-duplicated list. + */ +List *MergeList(List *targetList, List *restrictList, int count); + +/* + * @Description: build the columns list for dfsscan, which comes from reltargetlist + * and exclude the index columns. + * @IN reltargetlist: the primitive target list + * @IN excludedColList: the columns which should be abandoned. + * @Return: the final reader list for dfs scan + * @See also: + */ +List *build_dfs_reader_tlist(List *reltargetlist, List *excludedColList); + +/* + * Calculate the predicate selectivity of each column. + */ +void CalculateWeightByColumns(PlannerInfo *root, List *hdfsQualColumn, List *hdfsQual, double *selectivity, int colNum); + +/* + *brief: Check column data type for orc table. + *input param @ColType: Oid of column data type; + *input param @ColName: column name. + */ +void DFSCheckDataType(TypeName *typName, char* ColName, int format); + +/* + * brief: Check foldername, filenames, hdfscfgpath format. The rules are the followings: + * 1. The space do not allow appear in the entrie OptStr, but '\ ' is needed + * 2. The comma do not appera in beignning and ending of OptStr + * 3. The comma as a separator exists if OptStr have many filenames path + * 4. Only a foldername path exists for foldername option and hdfscfgpath + * 5. The OptStr do not be empty + * input param @OptStr: the foldername path or file names or hdfscfgpath string + * input param @OptType: a foldername, a filenames or a hdfscfgpath type + */ +void CheckFoldernameOrFilenamesOrCfgPtah(const char *OptStr, char *OptType); + +/* + * brief: Check or get port and ip of foreign server(Only support ipv4 format), + * the rules are the followings: + * 1. The space do not allow appear in the entrie Address + * 2. The comma do not appera in beignning and ending of Address + * 3. The comma as a separator exists if OptStr have many address + * 4. The Address do not be empty + * input param @Address: address option of foreign server + * output param @AddrList: return List included port and ip + * input param @IsCheck: if IsCheck is true, only check, else get port and ip + */ +void CheckGetServerIpAndPort(const char *Address, List **AddrList, bool IsCheck, int real_addr_max); + +/* + * brief: Build internal executor parameter predicate for pushdown of dfs scan + * when excute plan. + * input param @readerState: Includes all the params which are used during reading. + */ +void BuildRunTimePredicates(dfs::reader::ReaderState *readerState); + +/** + * @Description: Get the int64 data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. As for decimal data, the + * precision store here. + * @return return the transformed data. + */ +int64_t datumGetInt64ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the int128 data according to the column type. Currently, + * only the decimal may be converted to int128 data. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. As for decimal data, the + * precision store here. + * @return return the transformed data. + */ +__int128 datumGetInt128ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the float8 data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. + * @return return the transformed data. + */ +double datumGetFloat8ByVar(Datum datumValue, Var *colVar); + +/** + * @Description: Get the string data according to the column type. + * @in datumValue, the datum value. + * @in colVar, The Var struct. It keeps data type. + * @return return the transformed data. + */ +char *datumGetStringByVar(Datum datumValue, Var *colVar); + +/* + * + * brief: Generate column list. + * input param @attributes: information of pg_attribure; + * input param @columnCount: the count of column. + * input param @colIdx: The column idx array. + */ +List *CreateColList(Form_pg_attribute *attributes, const int columnCount, const int16 *colIdx = NULL); + +/* + * @Description: remove the elements of the 'del' list in the 'src' list + */ +void list_delete_list(List **src, List *del); + +/** + * @Description: Check the given file encoding. + * @in optionDef: The envoding string. + * @return None. + */ +void checkEncoding(DefElem *optionDef); + +int FindLastCharPos(char seperator, const char *srcString); + +bool IsVarNode(Node *node); + +/** + * @Description: The default column value satisfies whether predicates. + * @in isNull, The default column whether is null. + * @in value, The default column value. + * @in colVar, The Var sturct of default column. + * @in predicateList, The default column predicates. + * @return If the default column value satisfies the default column predicates, + * return true, otherwise return false. + * @Notes: Only the column of the pushed down data type can reach here. + */ +bool defColSatisfyPredicates(bool isNull, Datum value, Var *col_var, List *predicate_list); +bool IsParamConst(Node *node); + +/** + * @Description: Convert the string according to the database encoding and original encoding. + * @in src: the input string. + * @in length: the length of the input string. + * @in encoding: the original encoding. + * @return the converted string. + */ +char *pg_to_server_withfailure(char *src, int64 length, int32 encoding, int32 checkEncodingLevel, bool &meetError); + +BlockNumber getPageCountForFt(void *additionalData); + +#define QUERY_NOT_SUPPORT(foreignTableId, msg) do { \ + Relation relation = RelationIdGetRelation(foreignTableId); \ + if (RelationIsValid(relation)) \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), \ + errmsg(msg, RelationGetRelationName(relation)))); \ + else \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), \ + errmsg("could not open relation with OID %u", foreignTableId))); \ +} while (0) + +#endif /* DFS_QUERY_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_query_reader.h postgresql-hll-2.14/include/include/access/dfs/dfs_query_reader.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_query_reader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_query_reader.h 2020-12-12 17:06:43.133346567 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_query_reader.h + * + * IDENTIFICATION + * src/include/access/dfs/dfs_query_reader.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_QUERY_READER_H +#define DFS_QUERY_READER_H +extern HdfsQueryOperator HdfsGetQueryOperator(const char *operatorName); +/* + * Fill up the structure: readerState which can not be NULL. + */ +extern void FillReaderState(dfs::reader::ReaderState *readerState, ScanState *ss, + DfsPrivateItem *item, Snapshot snapshot = NULL); +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_stream_factory.h postgresql-hll-2.14/include/include/access/dfs/dfs_stream_factory.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_stream_factory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_stream_factory.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_stream_factory.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_stream_factory.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_STREAM_FACTORY_H +#define DFS_STREAM_FACTORY_H + +#include + +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_stream.h" + +namespace dfs { + +DFS_UNIQUE_PTR InputStreamFactory(dfs::DFSConnector *conn, const std::string &path, + dfs::reader::ReaderState *readerState, bool use_cache); +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_stream.h postgresql-hll-2.14/include/include/access/dfs/dfs_stream.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_stream.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_stream.h + * + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_STREAM_H +#define DFS_STREAM_H + +#include +#include +#include + +#include "dfs_config.h" // for DFS_UNIQUE_PTR + +namespace dfs { + +class GSInputStream { +public: + virtual ~GSInputStream(){}; + + /* + * Get the total length of the file in bytes. + */ + virtual uint64_t getLength() const = 0; + + /* + * Get the natural size for reads. + * @return the number of bytes that should be read at once + */ + virtual uint64_t getNaturalReadSize() const = 0; + + /* + * Read length bytes from the file starting at offset into + * the buffer starting at buf. + * @param buf the starting position of a buffer. + * @param length the number of bytes to read. + * @param offset the position in the stream to read from. + */ + virtual void read(void *buf, uint64_t length, uint64_t offset) = 0; + + /* + * Get the name of the stream for error messages. + */ + virtual const std::string &getName() const = 0; + + virtual void getStat(uint64_t *localBlock, uint64_t *remoteBlock, uint64_t *nnCalls, uint64_t *dnCalls) = 0; + + virtual void getLocalRemoteReadCnt(uint64_t *localReadCnt, uint64_t *remoteReadCnt) = 0; + + virtual DFS_UNIQUE_PTR copy() = 0; +}; + +} // namespace dfs + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_update.h postgresql-hll-2.14/include/include/access/dfs/dfs_update.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_update.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_update.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,84 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_update.h + * routines to support dfs + * + * + * IDENTIFICATION + * src/include/access/dfs/dfs_update.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_UPDATE_H +#define DFS_UPDATE_H + +#include "access/cstore_update.h" +#include "access/dfs/dfs_insert.h" +#include "access/dfs/dfs_delete.h" + +class DfsUpdate : public BaseObject { +public: + DfsUpdate(Relation, EState *, Plan *plan = NULL); + virtual ~DfsUpdate(); + + virtual void Destroy(); + + /* initialize the memory info */ + void InitUpdateMemArg(Plan *plan = NULL); + + /* + * initialize sort cache with tuple descriptor. + */ + void InitSortState(TupleDesc sortTupDesc); + + /* + * do "update" job really, and return the number of updated rows. + */ + uint64 ExecUpdate(VectorBatch *batch, int options); + + /* + * called at last step, make sure that data in cache can be deleted and new + * data can be inserted. + */ + void EndUpdate(int options); + +private: + /* + * target relation to be updated + */ + Relation m_relation; + + /* + * objects used to implement "delete" and "insert" + */ + DfsDelete *m_delete; + DfsInsertInter *m_insert; + + /* + * state data used on update + */ + ResultRelInfo *m_resultRelInfo; + EState *m_estate; + + /* + * the memory info to "delete" and "insert" + */ + MemInfoArg *m_dfsUpDelMemInfo; + MemInfoArg *m_dfsUpInsMemInfo; +}; + +#endif /* DFS_UPDATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/dfs/dfs_wrapper.h postgresql-hll-2.14/include/include/access/dfs/dfs_wrapper.h --- postgresql-hll-2.14_old/include/include/access/dfs/dfs_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/dfs/dfs_wrapper.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,482 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_wrapper.h + * + * IDENTIFICATION + * src/include/access/dfs/dfs_wrapper.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_WRAPPER_H +#define DFS_WRAPPER_H +#include "orc/Exceptions.hh" +#include "access/dfs/dfs_am.h" +#include "access/dfs/dfs_common.h" +#include "catalog/pg_collation.h" +#include "nodes/execnodes.h" +#include "nodes/pg_list.h" +#include "optimizer/clauses.h" +#include "optimizer/subselect.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/dfs_vector.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/lsyscache.h" + +/* + * The base template class for all the data type wrapper to inherit. + */ +template +class HdfsCheckWrapper : public BaseObject { +public: + virtual ~HdfsCheckWrapper() + { + } + /* + * Abstract function to compare the argument and velue. + * @_in param argument: The target to be compared with the member value. + * @_in param collation: the collation of the var, it is used in function varstr_cmp. + * @return Return 1=eq, -1=lt, 1=gt. + */ + virtual int compareT(T argument, Oid collation) = 0; + + /* + * Set the value in the class which is converted from datum. + * @_in param datumValue: the datum value to be set. + * @_in param datumType: the data type oid of the datum. + * @_in param typeMod: the mod of the datum type. + */ + virtual void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) = 0; + + /* + * A template function to check if the argument transfered in can be filtered. All the non-string + * wrapper will inherit this function for call. + * + * @_in param argument: the value transfered in to be checked + * @_in param strategy: the strategy used in the predicate. + * @_in param collation: the collation of the var, it is used in function varstr_cmp. + * @return True: match and not filtered; False: filtered and set isSelected to false. + */ + inline bool CheckPredicate(T argument, Oid collation) + { + int cmpResult = compareT(argument, collation); + return HdfsCheckCompareResult(cmpResult); + } + + /* + * Get the value of the wrapper. + * @return Return the value in the class. + */ + inline const T getValue() + { + return value; + } + + /* + * Get the datum of the wrapper. + * @return the datum value. + */ + inline Datum getDatum() + { + return dValue; + } + +private: + /* + * Check the compare result depending on the strategy of the predicate pushed down. + * + * @_in param cmpResult: The result of comparision, (o=eq, -1=lt, 1=gt) + * + * @return True: indicates the value of the row and column match the preidcate pushed down; False: + * indicates the value does not match the predicate and need to be filtered. + */ + bool HdfsCheckCompareResult(int cmpResult); + +protected: + /* Store the real value of the wrapper with type T. */ + T value; + Datum dValue; + + /* + * The strategy of the predicate's operator, which must between HDFS_QUERY_EQ + * and HDFS_QUERY_NE2. + */ + HdfsQueryOperator strategy; + int32 typeMod; + Oid datumType; +}; + +/* + * Check the result of comparation according to the strategy. + */ +template +inline bool HdfsCheckWrapper::HdfsCheckCompareResult(int cmpResult) +{ + bool result = false; + switch (strategy) { + case HDFS_QUERY_LT: { + if (0 > cmpResult) + result = true; + break; + } + case HDFS_QUERY_LTE: { + if (0 >= cmpResult) + result = true; + break; + } + case HDFS_QUERY_EQ: { + if (0 == cmpResult) + result = true; + break; + } + case HDFS_QUERY_GTE: { + if (0 <= cmpResult) + result = true; + break; + } + case HDFS_QUERY_GT: { + if (0 < cmpResult) + result = true; + break; + } + case HDFS_QUERY_NE1: + case HDFS_QUERY_NE2: { + if (0 != cmpResult) + result = true; + break; + } + case HDFS_QUERY_INVALID: + default: { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_DFS), + errmsg("Find unsupported strategy %d!", strategy))); + } + } + + return result; +} + +/* + * A wrapper class of int64 type, inherit HdfsCheckWrapper. Here we do not seperate + * int16, int 32 and int64 wrapper just because what we read from orc file directly for int16,int32 and int64 + * is int64, then it will convert to int16,int32 or int64 datum. Since the predicate need to be checked before + * the conversion from basic type to datum, so we will compare the int64 value directly and needn't + * Int32Wrapper and Int16Wrapper. + */ +class Int64Wrapper : public HdfsCheckWrapper { +public: + Int64Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Int64Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + + if (INT1OID == datumType) { + value = DatumGetChar(datumValue); + } else if (INT2OID == datumType) { + value = DatumGetInt16(datumValue); + } else if (INT4OID == datumType) { + value = DatumGetInt32(datumValue); + } else if (NUMERICOID == datumType) { + int dscale = (unsigned int)(typeMod - VARHDRSZ) & 0xffff; + Numeric n = DatumGetNumeric(datumValue); + if (NUMERIC_IS_BI(n)) { + Assert(dscale == NUMERIC_BI_SCALE(n)); + Assert(NUMERIC_IS_BI64(n)); + + value = NUMERIC_64VALUE(n); + } else + value = convert_short_numeric_to_int64_byscale(n, dscale); + } else { + value = DatumGetInt64(datumValue); + } + } + +private: + inline int compareT(int64 argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* just for decimal128, 18 < p <= 38 */ +class Int128Wrapper : public HdfsCheckWrapper { +public: + Int128Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Int128Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + int dscale = (unsigned int)(typeMod - VARHDRSZ) & 0xffff; + + dValue = datumValue; + Numeric n = DatumGetNumeric(datumValue); + if (NUMERIC_IS_BI(n)) { + Assert(dscale == NUMERIC_BI_SCALE(n)); + + if (NUMERIC_IS_BI128(n)) { + errno_t rc = EOK; + rc = memcpy_s(&value, sizeof(int128), (n)->choice.n_bi.n_data, sizeof(int128)); + securec_check(rc, "\0", "\0"); + } else + value = NUMERIC_64VALUE(n); + } else + convert_short_numeric_to_int128_byscale(n, dscale, value); + } + +private: + inline int compareT(int128 argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of bool type, inherit HdfsCheckWrapper. The actual value stored is a char here. + */ +class BoolWrapper : public HdfsCheckWrapper { +public: + BoolWrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~BoolWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + value = DatumGetBool(datumValue); + } + +private: + inline int compareT(char argument, Oid collation) + { + int cmp = 0; + INT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of float8 type, inherit HdfsCheckWrapper. + */ +class Float8Wrapper : public HdfsCheckWrapper { +public: + Float8Wrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~Float8Wrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid _datumType, int32 typeMod) + { + datumType = _datumType; + /* + * For float4/8, there may be data convertion of the const value, so we + * need to process seperately here. + */ + if (FLOAT4OID == datumType) { + value = (float8)DatumGetFloat4(datumValue); + dValue = Float8GetDatum(value); + } else // float8 + { + value = DatumGetFloat8(datumValue); + dValue = datumValue; + } + } + +private: + inline int compareT(float8 argument, Oid collation) + { + int cmp = 0; + FLOAT_CMP_HDFS(argument, value, cmp); + return cmp; + } +}; + +/* + * A wrapper class of Timestamp type, inherit HdfsCheckWrapper. Since there is not actual Date type + * in PG, we just need the wrapper for Timestamp here, and convert the hive date to timestamp before + * the comparasion with predicate. + */ +class TimestampWrapper : public HdfsCheckWrapper { +public: + TimestampWrapper(HdfsQueryOperator _strategy) + { + value = 0; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~TimestampWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid datumType, int32 typeMod) + { + dValue = datumValue; + + /* + * For different time types, we use different ways to convert to timestamp. + */ + if (DATEOID == datumType) { + value = date2timestamp(DatumGetDateADT(datumValue)); + } else if (TIMESTAMPTZOID == datumType) { + Datum out = DirectFunctionCall1(timestamptz_out, datumValue); + Datum in = DirectFunctionCall3(timestamp_in, out, ObjectIdGetDatum(InvalidOid), Int32GetDatum(typeMod)); + value = DatumGetTimestamp(in); + } else { + value = DatumGetTimestamp(datumValue); + } + } + +private: + inline int compareT(Timestamp argument, Oid collation) + { + int cmp = 0; +#ifdef HAVE_INT64_TIMESTAMP + INT_CMP_HDFS(argument, value, cmp); +#else + FLOAT_CMP_HDFS(argument, value, cmp); +#endif + return cmp; + } +}; + +/* + * Since we only care about equality or not-equality, we can avoid all the + * expense of strcoll() here, and just do bitwise comparison. + * The caller must ensure that both src1 and src2 are valid strings with '\0' at end. + * return 0 if the two strings are equal. + */ +static int stringEQ(const char *src1, const char *src2) +{ + int result = 0; + int len1 = strlen(src1); + int len2 = strlen(src2); + if (len1 != len2) { + result = 1; + } else { + result = memcmp(src1, src2, len1); + } + return result; +} + +/* + * A wrapper class of string type includes varchar,bpchar,text because these types is actually the same for hive. + */ +class StringWrapper : public HdfsCheckWrapper { +public: + StringWrapper(HdfsQueryOperator _strategy) + { + value = NULL; + dValue = PointerGetDatum(NULL); + strategy = _strategy; + typeMod = 0; + datumType = InvalidOid; + } + virtual ~StringWrapper() + { + } + inline void SetValueFromDatum(Datum datumValue, Oid _datumType, int32 typeMod) + { + dValue = datumValue; + datumType = _datumType; + + if (BPCHAROID == datumType) { + int varLen = 0; + char *str = TextDatumGetCString(datumValue); + int strLen = strlen(str); + + /* variable length */ + if (typeMod < (int32)VARHDRSZ) { + varLen = strLen; + } else /* fixed length */ + { + varLen = typeMod - VARHDRSZ; + } + + /* + * When the length of the var is larger than the const string's length, it needs to + * add some blanks in the tail. + */ + if (varLen >= strLen) { + Datum bpchar = DirectFunctionCall3(bpcharin, CStringGetDatum(str), ObjectIdGetDatum(InvalidOid), + Int32GetDatum(typeMod)); + value = TextDatumGetCString(bpchar); + } else { + value = str; + } + } else { + value = TextDatumGetCString(datumValue); + } + } + +private: + inline int compareT(char *argument, Oid collation) + { + int cmp = 0; + if (HDFS_QUERY_EQ == strategy || HDFS_QUERY_NE1 == strategy || HDFS_QUERY_NE2 == strategy) { + cmp = stringEQ(argument, value); + } else { + cmp = varstr_cmp(argument, strlen(argument), value, strlen(value), collation); + } + return cmp; + } +}; + +/* + * This wrapper is only used for HdfsPredicateCheckNull, and there is need to store any value here. We don't + * remove it because Null check is processed specially and keeping a special empty wrapper for null can + * make it less confused. + */ +class NullWrapper { +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/double_write_basic.h postgresql-hll-2.14/include/include/access/double_write_basic.h --- postgresql-hll-2.14_old/include/include/access/double_write_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/double_write_basic.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,152 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * double_write_basic.h + * Define some basic structs of double write which is needed in knl_instance.h + * + * + * IDENTIFICATION + * src/include/access/double_write_basic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DOUBLE_WRITE_BASIC_H +#define DOUBLE_WRITE_BASIC_H + +#include /* need open() flags */ +#include "c.h" +#include "knl/knl_thread.h" +#include "utils/palloc.h" + +static const uint32 HALF_K = 512; + +static const char DW_FILE_NAME[] = "global/pg_dw"; +static const char SINGLE_DW_FILE_NAME[] = "global/pg_dw_single"; +static const char DW_BUILD_FILE_NAME[] = "global/pg_dw.build"; + +static const uint32 DW_TRY_WRITE_TIMES = 8; +#ifndef WIN32 +static const int DW_FILE_FLAG = (O_RDWR | O_SYNC | O_DIRECT | PG_BINARY); +#endif +static const mode_t DW_FILE_PERM = (S_IRUSR | S_IWUSR); + +static const int DW_FILE_EXTEND_SIZE = (BLCKSZ * HALF_K); + +/* 32k pages, 8k each, file size 256M in total */ +static const uint16 DW_FILE_PAGE = 32768; + +static const int64 DW_FILE_SIZE = (DW_FILE_PAGE * BLCKSZ); + +/* make file head size to 512 bytes in total, 12 bytes including head and tail, 500 bytes alignment */ +static const uint32 DW_FILE_HEAD_ALIGN_BYTES = 500; + +/** + * | file_head | batch head | data pages | batch tail/next batch head | ... | + * | 0 | 1 | 409 at most | 1 | ... | + */ +static const uint16 DW_BATCH_FILE_START = 1; + +#define REDUCE_CKS2UINT16(cks) (((cks) >> 16) ^ ((cks)&0xFFFF)) + +typedef struct st_dw_page_head { + uint16 page_id; /* page_id in file */ + uint16 dwn; /* double write number, updated when file header changed */ +} dw_page_head_t; + +typedef struct st_dw_page_tail { + uint16 checksum; + uint16 dwn; /* double write number, updated when file header changed */ +} dw_page_tail_t; + +typedef struct st_dw_file_head { + dw_page_head_t head; + uint16 start; + uint16 buftag_version; + uint8 unused[DW_FILE_HEAD_ALIGN_BYTES]; /* 512 bytes total, one sector for most disks */ + dw_page_tail_t tail; +} dw_file_head_t; + +static const uint32 DW_FILE_HEAD_ID_NUM = 3; + +/* write file head 3 times, distributed in start, middle, end of the first page of dw file */ +static const uint16 g_dw_file_head_ids[DW_FILE_HEAD_ID_NUM] = {0, 8, 15}; + +const static uint64 DW_SLEEP_US = 1000L; + +const static uint16 DW_WRITE_STAT_LOWER_LIMIT = 16; + +const static int DW_VIEW_COL_NUM = 11; +const static int DW_SINGLE_VIEW_COL_NUM = 6; + +const static uint32 DW_VIEW_COL_NAME_LEN = 32; + +#define DW_PAGE_TAIL(page) ((dw_page_tail_t*)((char*)(page) + (BLCKSZ - sizeof(dw_page_tail_t)))) + +#define DW_PAGE_CHECKSUM(page) (DW_PAGE_TAIL(page)->checksum) + +#ifdef DW_DEBUG +#define DW_LOG_LEVEL LOG +#else +#define DW_LOG_LEVEL DEBUG1 +#endif + +typedef Datum (*dw_view_get_data_func)(); + +typedef struct st_dw_view_col { + char name[DW_VIEW_COL_NAME_LEN]; + Oid data_type; + dw_view_get_data_func get_data; +} dw_view_col_t; + +typedef struct st_dw_read_asst { + int fd; + uint16 file_start; /* reading start page id in file */ + uint16 file_capacity; /* max pages of the file */ + uint16 buf_start; /* start page of the buf */ + uint16 buf_end; /* end page of the buf */ + uint16 buf_capacity; /* max pages the buf can hold */ + char* buf; +} dw_read_asst_t; + +typedef struct dw_stat_info_batch { + volatile uint64 file_trunc_num; /* truncate file */ + volatile uint64 file_reset_num; /* file full and restart from beginning */ + volatile uint64 total_writes; /* total double write */ + volatile uint64 low_threshold_writes; /* less than 16 pages */ + volatile uint64 high_threshold_writes; /* more than one full batch (409 pages) */ + volatile uint64 total_pages; /* pages total */ + volatile uint64 low_threshold_pages; /* less than 16 pages total */ + volatile uint64 high_threshold_pages; /* more than one full batch (409 pages) total */ +} dw_stat_info_batch; + +typedef struct dw_stat_info_single { + volatile uint64 file_trunc_num; /* truncate file */ + volatile uint64 file_reset_num; /* file full and restart from beginning */ + volatile uint64 total_writes; /* total double write */ +} dw_stat_info_single; + +typedef struct single_slot_pos { + LWLock* write_lock; /* The dw write lock corresponding to the slot */ + uint16 actual_pos; /* correspond to the actual double write file slot */ +}single_slot_pos; + +typedef struct single_slot_state { + bool data_flush; /* The buffer corresponding to the slot finish data file flush */ +}single_slot_state; + +extern const dw_view_col_t g_dw_view_col_arr[DW_VIEW_COL_NUM]; +extern const dw_view_col_t g_dw_single_view[DW_SINGLE_VIEW_COL_NUM]; + +#endif /* DOUBLE_WRITE_BASIC_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/double_write.h postgresql-hll-2.14/include/include/access/double_write.h --- postgresql-hll-2.14_old/include/include/access/double_write.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/double_write.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,282 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * double_write.h + * Define some inline function of double write and export some interfaces. + * + * + * IDENTIFICATION + * src/include/access/double_write.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DOUBLE_WRITE_H +#define DOUBLE_WRITE_H + +#include "double_write_basic.h" +#include "storage/buf_internals.h" +#include "storage/checksum_impl.h" + +typedef enum BufTagVer { + ORIGIN_TAG = 0, + HASHBUCKET_TAG +} BufTagVer; + +typedef struct st_dw_batch { + dw_page_head_t head; + uint16 page_num; /* for batch head, number of data pages */ + uint16 buftag_ver; + BufferTag buf_tag[0]; /* to locate the data pages in batch */ +} dw_batch_t; + +typedef struct st_dw_batch_nohbkt { + dw_page_head_t head; + uint16 page_num; /* for batch head, number of data pages */ + uint16 buftag_ver; + BufferTagFirstVer buf_tag[0]; /* to locate the data pages in batch */ +} dw_batch_first_ver; + +typedef struct dw_single_flush_item { + uint16 data_page_idx; /* from zero start, indicates the slot of the data page. */ + uint16 dwn; /* double write number, updated when file header changed */ + BufferTag buf_tag; + pg_crc32c crc; /* CRC of all above ... MUST BE LAST! */ +}dw_single_flush_item; + +/* Used by double_write to mark the buffers which are not flushed in the given buf_id array. */ +static const int DW_INVALID_BUFFER_ID = -1; +/* steal high bit from pagenum as the flag of hashbucket */ +#define IS_HASH_BKT_MASK (0x8000) +#define GET_REL_PGAENUM(pagenum) (pagenum & ~IS_HASH_BKT_MASK) + +/** + * Dirty data pages in one batch + * The number of data pages depends on the number of BufferTag one page can hold + */ +static const uint16 DW_BATCH_DATA_PAGE_MAX = + (uint16)((BLCKSZ - sizeof(dw_batch_t) - sizeof(dw_page_tail_t)) / sizeof(BufferTag)); + +static const uint16 DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK = + (uint16)((BLCKSZ - sizeof(dw_batch_first_ver) - sizeof(dw_page_tail_t)) / sizeof(BufferTagFirstVer)); + + +/* 1 head + data + 1 tail */ +static const uint16 DW_EXTRA_FOR_ONE_BATCH = 2; + +/* 1 head + data + [1 tail, 2 head] + data + 2 tail */ +static const uint16 DW_EXTRA_FOR_TWO_BATCH = 3; + +static const uint16 DW_BATCH_MIN = (1 + DW_EXTRA_FOR_ONE_BATCH); + +static const uint16 DW_BATCH_MAX = (DW_BATCH_DATA_PAGE_MAX + DW_EXTRA_FOR_ONE_BATCH); + +/* 2 batches at most for one perform */ +static const uint16 DW_DIRTY_PAGE_MAX = (DW_BATCH_DATA_PAGE_MAX + DW_BATCH_DATA_PAGE_MAX); + +static const uint16 DW_BUF_MAX = (DW_DIRTY_PAGE_MAX + DW_EXTRA_FOR_TWO_BATCH); + +static const uint16 DW_BATCH_MAX_FOR_NOHBK = (DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK + DW_EXTRA_FOR_ONE_BATCH); + +/* 2 batches at most for one perform */ +static const uint16 DW_DIRTY_PAGE_MAX_FOR_NOHBK = (DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK + DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK); + +static const uint16 DW_BUF_MAX_FOR_NOHBK = (DW_DIRTY_PAGE_MAX_FOR_NOHBK + DW_EXTRA_FOR_TWO_BATCH); + + +#define GET_DW_BATCH_DATA_PAGE_MAX(contain_hashbucket) (!contain_hashbucket ? DW_BATCH_DATA_PAGE_MAX_FOR_NOHBK : DW_BATCH_DATA_PAGE_MAX) + +#define GET_DW_BATCH_MAX(contain_hashbucket) (!contain_hashbucket ? DW_BATCH_MAX_FOR_NOHBK : DW_BATCH_MAX) + + +#define GET_DW_DIRTY_PAGE_MAX(contain_hashbucket) (!contain_hashbucket ? DW_DIRTY_PAGE_MAX_FOR_NOHBK : DW_DIRTY_PAGE_MAX) + +#define GET_DW_MEM_CTX_MAX_BLOCK_SIZE(contain_hashbucket) (!contain_hashbucket ? DW_MEM_CTX_MAX_BLOCK_SIZE_FOR_NOHBK : DW_MEM_CTX_MAX_BLOCK_SIZE) + +/* + * 1 block for alignment, 1 for file_head, 1 for reading data_page during recovery + * and DW_BUF_MAX for double_write buffer. + */ +static const uint32 DW_MEM_CTX_MAX_BLOCK_SIZE = ((1 + 1 + 1 + DW_BUF_MAX) * BLCKSZ); + +static const uint32 DW_MEM_CTX_MAX_BLOCK_SIZE_FOR_NOHBK = ((1 + 1 + 1 + DW_BUF_MAX_FOR_NOHBK) * BLCKSZ); + +const uint16 SINGLE_BLOCK_TAG_NUM = BLCKSZ / sizeof(dw_single_flush_item); + +static const uint32 DW_BOOTSTRAP_VERSION = 91261; +const uint32 DW_SUPPORT_SINGLE_FLUSH_VERSION = 92266; + +/* dw single flush file information */ +/* file head + storage buffer tag page + data page */ +const int DW_SINGLE_FILE_SIZE = (1 + 161 + 32768) * 8192; + +/* Reserve 8 bytes for bufferTag upgrade. now usepage num is 32768 * sizeof(dw_single_flush_item) / 8192 */ +const int DW_SINGLE_BUFTAG_PAGE_NUM = 161; +const int DW_SINGLE_DIRTY_PAGE_NUM = 32768; + +inline bool dw_buf_valid_dirty(uint32 buf_state) +{ + return ((buf_state & (BM_VALID | BM_DIRTY)) == (BM_VALID | BM_DIRTY)); +} + +inline bool dw_buf_ckpt_needed(uint32 buf_state) +{ + return ((buf_state & (BM_VALID | BM_DIRTY | BM_CHECKPOINT_NEEDED)) == (BM_VALID | BM_DIRTY | BM_CHECKPOINT_NEEDED)); +} + +inline bool dw_verify_file_head_checksum(dw_file_head_t* file_head) +{ + uint32 checksum; + uint16 org_cks = file_head->tail.checksum; + + file_head->tail.checksum = 0; + checksum = pg_checksum_block((char*)file_head, sizeof(dw_file_head_t)); + file_head->tail.checksum = org_cks; + + return (org_cks == REDUCE_CKS2UINT16(checksum)); +} + +inline bool dw_verify_file_head(dw_file_head_t* file_head) +{ + return file_head->head.dwn == file_head->tail.dwn && dw_verify_file_head_checksum(file_head); +} + +inline void dw_calc_file_head_checksum(dw_file_head_t* file_head) +{ + uint32 checksum; + file_head->tail.checksum = 0; + checksum = pg_checksum_block((char*)file_head, sizeof(dw_file_head_t)); + file_head->tail.checksum = REDUCE_CKS2UINT16(checksum); +} + +inline bool dw_verify_batch_checksum(dw_batch_t* batch) +{ + uint32 checksum; + uint16 org_cks = DW_PAGE_CHECKSUM(batch); + + DW_PAGE_CHECKSUM(batch) = 0; + checksum = pg_checksum_block((char*)batch, BLCKSZ); + DW_PAGE_CHECKSUM(batch) = org_cks; + + return (org_cks == REDUCE_CKS2UINT16(checksum)); +} + +inline bool dw_verify_page(dw_batch_t* page) +{ + return (page)->head.dwn == DW_PAGE_TAIL(page)->dwn && dw_verify_batch_checksum(page); +} + +inline void dw_calc_batch_checksum(dw_batch_t* batch) +{ + uint32 checksum; + + DW_PAGE_CHECKSUM(batch) = 0; + checksum = pg_checksum_block((char*)batch, BLCKSZ); + DW_PAGE_CHECKSUM(batch) = REDUCE_CKS2UINT16(checksum); +} + +inline dw_batch_t* dw_batch_tail_page(dw_batch_t* head_page) +{ + return (dw_batch_t*)((char*)head_page + BLCKSZ * (GET_REL_PGAENUM(head_page->page_num) + 1)); +} + +/** + * verify the batch head and tail page, including dwn and checksum + * @param head_page batch head + * @param dwn double write number + * @return true dwn and checksum match + */ +inline bool dw_verify_batch(dw_batch_t* head_page, uint16 dwn) +{ + if (head_page->head.dwn == dwn && dw_verify_page(head_page)) { + dw_batch_t* tail_page = dw_batch_tail_page(head_page); + return tail_page->head.dwn == dwn && dw_verify_page(tail_page); + } + + return false; +} + +inline uint64 dw_page_distance(void* left, void* right) +{ + return ((char*)right - (char*)left) / BLCKSZ; +} + +int64 dw_seek_file(int fd, int64 offset, int32 origin); + +void dw_pread_file(int fd, void* buf, int size, int64 offset); + +void dw_pwrite_file(int fd, const void* buf, int size, int64 offset); + +/** + * generate the file for the database first boot + */ +void dw_bootstrap(); + +/** + * do the memory allocate, spin_lock init, LWLock assign and double write recovery + * all the half-written pages should be recovered after this + * it should be finished before XLOG module start which may replay redo log + */ +void dw_init(bool shutdown); + +/** + * double write only work when incremental checkpoint enabled and double write enabled + * @return true if both enabled + */ +inline bool dw_enabled() +{ + return ( + g_instance.attr.attr_storage.enableIncrementalCheckpoint && g_instance.attr.attr_storage.enable_double_write); +} + +/** + * flush the buffers identified by the buf_id in buf_id_arr to double write file + * a token_id is returned, thus double write wish the caller to return it after the + * caller finish flushing the buffers to data file and forwarding the fsync request + * @param buf_id_arr the buffer id array which is used to get page from global buffer + * @param size the array size + */ +void dw_perform_batch_flush(uint32 size, CkptSortItem *dirty_buf_list, ThrdDwCxt* thrd_dw_cxt); + +/** + * truncate the pages in double write file after ckpt or before exit + * wait for tokens, thus all the relative data file flush and fsync request forwarded + * then its safe to call fsync to make sure pages on data file + * and then safe to discard those pages on double write file + */ +void dw_truncate(); + +/** + * double write exit after XLOG exit. + * data file flushing, page writer and checkpointer thread may still running. wait for them. + */ +void dw_exit(bool single); + +/** + * If double write is enabled and pagewriter is running, + * the dirty pages should only be flushed by pagewriter. + */ +inline bool dw_page_writer_running() +{ + return (dw_enabled() && pg_atomic_read_u32(&g_instance.ckpt_cxt_ctl->current_page_writer_count) > 0); +} + +extern uint16 dw_single_flush(BufferDesc *buf_desc); +extern bool dw_single_file_recycle(bool trunc_file); +extern bool backend_can_flush_dirty_page(); +extern void dw_force_reset_single_file(); +extern void reset_dw_pos_flag(); +extern void clean_proc_dw_buf(); +extern void init_proc_dw_buf(); +#endif /* DOUBLE_WRITE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/batch_redo.h postgresql-hll-2.14/include/include/access/extreme_rto/batch_redo.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/batch_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/batch_redo.h 2020-12-12 17:06:43.134346580 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * batch_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/batch_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BATCH_REDO_H +#define BATCH_REDO_H + +#include "c.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "lib/dllist.h" +#include "utils/hsearch.h" +#include "access/xlogproc.h" +#include "access/xlogutils.h" + +namespace extreme_rto { + +#define PAGETYPE_DROP 0x04 +#define PAGETYPE_CREATE 0x02 +#define PAGETYPE_TRUNCATE 0x01 +#define PAGETYPE_MODIFY 0x00 + +#define INITredoItemHashSIZE 1024 + +#define INIT_REDO_ITEM_TAG(a, xx_rnode, xx_forkNum, xx_blockNum) \ + ((a).rNode = (xx_rnode), (a).forkNum = (xx_forkNum), (a).blockNum = (xx_blockNum)) + +#define InvalidRelFileNode ((RelFileNode){ 0, 0, 0 }) + +/* + * Note: if there are any pad bytes in the struct, INIT_RedoItemTag have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct redoitemtag { + RelFileNode rNode; + ForkNumber forkNum; + BlockNumber blockNum; +} RedoItemTag; + +typedef struct redoitemhashentry { + RedoItemTag redoItemTag; + XLogRecParseState *head; + XLogRecParseState *tail; + int redoItemNum; +} RedoItemHashEntry; + +extern void PRPrintRedoItemHashTab(HTAB *redoItemHash); +extern HTAB *PRRedoItemHashInitialize(MemoryContext context); +extern void PRTrackClearBlock(XLogRecParseState *recordBlockState, HTAB *redoItemHash); +extern void PRTrackAddBlock(XLogRecParseState *recordBlockState, HTAB *redoItemHash); + +} // namespace extreme_rto +#endif /* BATCH_REDO_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/dispatcher.h postgresql-hll-2.14/include/include/access/extreme_rto/dispatcher.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/dispatcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/dispatcher.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,253 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dispatcher.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/dispatcher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_DISPATCHER_H +#define EXTREME_RTO_DISPATCHER_H + +#include "gs_thread.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" +#include "access/redo_statistic.h" +#include "access/extreme_rto/redo_item.h" +#include "access/extreme_rto/page_redo.h" +#include "access/extreme_rto/txn_redo.h" + +namespace extreme_rto { + +typedef struct { + PageRedoWorker *batchThd; /* BatchRedoThread */ + PageRedoWorker *managerThd; /* PageRedoManager */ + PageRedoWorker **redoThd; /* RedoThreadPool */ + uint32 redoThdNum; + uint32 *chosedRTIds; /* chosedRedoThdIds */ + uint32 chosedRTCnt; /* chosedRedoThdCount */ +} PageRedoPipeline; + +typedef struct { + PageRedoWorker *managerThd; /* TrxnRedoManager */ + PageRedoWorker *redoThd; /* TrxnRedoWorker */ +} TrxnRedoPipeline; + +typedef struct ReadPipeline { + PageRedoWorker *managerThd; /* readthrd */ + PageRedoWorker *readPageThd; /* readthrd */ + PageRedoWorker *readThd; /* readthrd */ +} ReadPipeline; + +#define MAX_XLOG_READ_BUFFER (0xFFFFF) /* 8k uint */ + +#define MAX_ALLOC_SEGNUM (4) /* 16* 4 */ + +typedef enum { + WORKER_STATE_STOP = 0, + WORKER_STATE_RUN, + WORKER_STATE_STOPPING, + WORKER_STATE_EXIT, + WORKER_STATE_EXITING, +} ReadWorkersState; + +typedef enum { + TRIGGER_NORMAL = 0, + TRIGGER_PRIMARY, + TRIGGER_STADNBY, + TRIGGER_FAILOVER, + TRIGGER_SWITCHOVER, + TRIGGER_SMARTSHUTDOWN, +} Enum_TriggeredState; + +typedef enum { + NONE, + APPLYING, + APPLIED, +} ReadBufState; + +typedef enum { + READ_MANAGER_STOP, + READ_MANAGER_RUN, +} XLogReadManagerState; + +typedef struct RecordBufferAarray { + XLogSegNo segno; + XLogRecPtr segoffset; + uint32 readlen; + char *readsegbuf; + uint32 bufState; +} RecordBufferAarray; + +#ifdef USE_ASSERT_CHECKING +#define LSN_CHECK_BUF_SIZE (128*1024*1024) +typedef struct { + uint64 curPosition; + XLogRecPtr curLsn; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + uint32 lsnCheckBuf[LSN_CHECK_BUF_SIZE]; +}LsnCheckCtl; + +#endif + +typedef struct RecordBufferState { + XLogReaderState *initreader; + uint32 readWorkerState; + uint32 readPageWorkerState; + uint32 readSource; + uint32 failSource; + uint32 xlogReadManagerState; + uint32 applyindex; + uint32 readindex; + RecordBufferAarray xlogsegarray[MAX_ALLOC_SEGNUM]; + char *readsegbuf; + char *readBuf; + char *errormsg_buf; + void *readprivate; + XLogRecPtr targetRecPtr; + XLogRecPtr expectLsn; +} RecordBufferState; + +typedef struct { + MemoryContext oldCtx; + PageRedoPipeline *pageLines; + uint32 pageLineNum; /* PageLineNum */ + uint32 *chosedPageLineIds; /* chosedPageLineIds */ + uint32 chosedPLCnt; /* chosedPageLineCount */ + TrxnRedoPipeline trxnLine; + ReadPipeline readLine; + RecordBufferState rtoXlogBufState; + PageRedoWorker **allWorkers; /* Array of page redo workers. */ + uint32 allWorkersCnt; + RedoItem *freeHead; /* Head of freed-item list. */ + RedoItem *freeStateHead; + RedoItem *allocatedRedoItem; + int exitCode; /* Thread exit code. */ + uint64 totalCostTime; + uint64 txnCostTime; /* txn cost time */ + uint64 pprCostTime; + uint32 maxItemNum; + uint32 curItemNum; + + uint32 syncEnterCount; + uint32 syncExitCount; + + pg_atomic_uint32 standbyState; /* sync standbyState from trxn worker to startup */ + + bool needImmediateCheckpoint; + bool needFullSyncCheckpoint; + volatile sig_atomic_t smartShutdown; +#ifdef USE_ASSERT_CHECKING + void *originLsnCheckAddr; + LsnCheckCtl *lsnCheckCtl; +#endif + RedoInterruptCallBackFunc oldStartupIntrruptFunc; +} LogDispatcher; + +typedef struct { + bool (*rm_dispatch)(XLogReaderState *record, List *expectedTLIs, TimestampTz recordXTime); + bool (*rm_loginfovalid)(XLogReaderState *record, uint8 minInfo, uint8 maxInfo); + RmgrId rm_id; + uint8 rm_mininfo; + uint8 rm_maxinfo; +} RmgrDispatchData; + +extern LogDispatcher *g_dispatcher; +extern RedoItem g_GlobalLsnForwarder; +extern RedoItem g_cleanupMark; +extern THR_LOCAL RecordBufferState *g_recordbuffer; + +const static uint64 OUTPUT_WAIT_COUNT = 0x7FFFFFF; +const static uint64 PRINT_ALL_WAIT_COUNT = 0x7FFFFFFFF; +extern RedoItem g_redoEndMark; +extern uint32 g_startupTriggerState; +extern uint32 g_readManagerTriggerFlag; + +inline int get_batch_redo_num() +{ + return g_instance.attr.attr_storage.batch_redo_num; +} + +inline int get_page_redo_worker_num_per_manager() +{ + return g_instance.attr.attr_storage.recovery_redo_workers_per_paser_worker; +} + +inline int get_trxn_redo_manager_num() +{ + return TRXN_REDO_MANAGER_NUM; +} + +inline int get_trxn_redo_worker_num() +{ + return TRXN_REDO_WORKER_NUM; +} + +void StartRecoveryWorkers(XLogReaderState *xlogreader, uint32 privateLen); + +/* RedoItem lifecycle. */ +void DispatchRedoRecordToFile(XLogReaderState *record, List *expectedTLIs, TimestampTz recordXTime); +void ProcessPendingRecords(bool fullSync = false); +void FreeRedoItem(RedoItem *item); + +/* Dispatcher phases. */ +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); + +/* Dispatcher states. */ +int GetDispatcherExitCode(); +bool DispatchPtrIsNull(); +uint32 GetBatchCount(); +uint32 GetAllWorkerCount(); +bool OnHotStandBy(); +PGPROC *StartupPidGetProc(ThreadId pid); +extern void SetStartupBufferPinWaitBufId(int bufid); +extern void GetStartupBufferPinWaitBufId(int *bufids, uint32 len); +void UpdateStandbyState(HotStandbyState newState); + +/* Redo end state saved by each page worker. */ +void **GetXLogInvalidPagesFromWorkers(); + +/* Other utility functions. */ +uint32 GetSlotId(const RelFileNode node, BlockNumber block, ForkNumber forkNum, uint32 workerCount); +bool XactWillRemoveRelFiles(XLogReaderState *record); +XLogReaderState *NewReaderState(XLogReaderState *readerState, bool bCopyState = false); +void FreeAllocatedRedoItem(); +void DiagLogRedoRecord(XLogReaderState *record, const char *funcName); +List *CheckImcompleteAction(List *imcompleteActionList); +void SetPageWorkStateByThreadId(uint32 threadState); +void UpdateDispatcherStandbyState(HotStandbyState *state); +void GetReplayedRecPtr(XLogRecPtr *startPtr, XLogRecPtr *endPtr); +void StartupSendFowarder(RedoItem *item); +XLogRecPtr GetSafeMinCheckPoint(); +RedoWaitInfo redo_get_io_event(int32 event_id); +void redo_get_wroker_statistic(uint32 *realNum, RedoWorkerStatsData *worker, uint32 workerLen); + +} // namespace extreme_rto + +extreme_rto::Enum_TriggeredState CheckForSatartupStatus(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/page_redo.h postgresql-hll-2.14/include/include/access/extreme_rto/page_redo.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/page_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/page_redo.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,224 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * page_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/page_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_PAGE_REDO_H +#define EXTREME_RTO_PAGE_REDO_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/extreme_rto/redo_item.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/extreme_rto/posix_semaphore.h" +#include "access/extreme_rto/spsc_blocking_queue.h" +#include "access/xlogproc.h" + +namespace extreme_rto { + +static const uint32 PAGE_WORK_QUEUE_SIZE = 4096; + +static const uint32 EXTREME_RTO_ALIGN_LEN = 16; /* need 128-bit aligned */ + + +typedef enum { + REDO_BATCH, + REDO_PAGE_MNG, + REDO_PAGE_WORKER, + REDO_TRXN_MNG, + REDO_TRXN_WORKER, + REDO_READ_WORKER, + REDO_READ_PAGE_WORKER, + REDO_READ_MNG, + REDO_ROLE_NUM, +} RedoRole; + +struct PageRedoWorker { + /* + * The last successfully applied log record's end position + 1 as an + * atomic uint64. The type of a log record's position is XLogRecPtr. + * Here the position is stored as an uint64 so it can be read and + * written atomically. + */ + XLogRecPtr lastReplayedReadRecPtr; + XLogRecPtr lastReplayedEndRecPtr; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + PageRedoWorker *selfOrinAddr; + /* Worker id. */ + uint32 id; + int index; + /* Thread id */ + gs_thread_t tid; + /* The proc struct of this worker thread. */ + PGPROC *proc; + RedoRole role; + uint32 slotId; + /* --------------------------------------------- + * Initial context + * + * Global variable values at worker creation time. + */ + + /* Initial server mode from the dispatcher. */ + ServerMode initialServerMode; + /* Initial timeline ID from the dispatcher. */ + TimeLineID initialTimeLineID; + List *expectedTLIs; + /* --------------------------------------------- + * Redo item queue. + * + * Redo items are provided by the dispatcher and consumed by each + * worker. See AddPageRedoItem() for the use of the additional + * pending list. + */ + + /* The head of the pending item list. */ + RedoItem *pendingHead; + /* The tail of the pending item list. */ + RedoItem *pendingTail; + /* To-be-replayed log-record-list queue. */ + SPSCBlockingQueue *queue; + + /* + * The last recovery restart point seen by the txn worker. Restart + * points before this is useless and can be removed. + */ + XLogRecPtr lastCheckedRestartPoint; + /* min recovery point */ + XLogRecPtr minRecoveryPoint; + /* --------------------------------------------- + * Per-worker run-time context + * + * States maintained by each individual page-redo worker during + * log replay. These are read by the txn-redo worker. + */ + + /* --------------------------------------------- + * Global run-time context + * + * States maintained outside page-redo worker during log replay. + * Updates to these states must be synchronized to all page-redo workers. + */ + + /* + * Global standbyState set by the txn worker. + */ + HotStandbyState standbyState; + TransactionId latestObservedXid; + bool StandbyMode; + char *DataDir; + + TransactionId RecentXmin; + /* --------------------------------------------- + * Redo end context + * + * Thread-local variable values saved after log replay has completed. + * These values are collected by each redo worker at redo end and + * are used by the dispatcher. + */ + /* XLog invalid pages. */ + void *xlogInvalidPages; + + /* --------------------------------------------- + * Phase barrier. + * + * A barrier for synchronizing the dispatcher and page redo worker + * between different phases. + */ + + /* Semaphore marking the completion of the current phase. */ + PosixSemaphore phaseMarker; + MemoryContext oldCtx; + + HTAB *redoItemHash; + TimeLineID recoveryTargetTLI; + bool ArchiveRecoveryRequested; + bool StandbyModeRequested; + bool InArchiveRecovery; + bool ArchiveRestoreRequested; + bool InRecovery; + + uint32 fullSyncFlag; + RedoParseManager parseManager; + RedoBufferManager bufferManager; +}; + +extern THR_LOCAL PageRedoWorker *g_redoWorker; + +/* Worker lifecycle. */ +PageRedoWorker *StartPageRedoWorker(PageRedoWorker *worker); +void DestroyPageRedoWorker(PageRedoWorker *worker); + +/* Thread creation utility functions. */ +bool IsPageRedoWorkerProcess(int argc, char *argv[]); +void AdaptArgvForPageRedoWorker(char *argv[]); +void GetThreadNameIfPageRedoWorker(int argc, char *argv[], char **threadNamePtr); + +uint32 GetMyPageRedoWorkerIdWithLock(); +PGPROC *GetPageRedoWorkerProc(PageRedoWorker *worker); + +/* Worker main function. */ +void ParallelRedoThreadRegister(); +void ParallelRedoThreadMain(); + +/* Dispatcher phases. */ +bool SendPageRedoEndMark(PageRedoWorker *worker); +void WaitPageRedoWorkerReachLastMark(PageRedoWorker *worker); + +/* Redo processing. */ +void AddPageRedoItem(PageRedoWorker *worker, void *item); + +/* Run-time worker states. */ +uint64 GetCompletedRecPtr(PageRedoWorker *worker); +void SetWorkerRestartPoint(PageRedoWorker *worker, XLogRecPtr restartPoint); + +void UpdatePageRedoWorkerStandbyState(PageRedoWorker *worker, HotStandbyState newState); + +/* Redo end states. */ +void ClearBTreeIncompleteActions(PageRedoWorker *worker); +void *GetXLogInvalidPages(PageRedoWorker *worker); +bool RedoWorkerIsIdle(PageRedoWorker *worker); +void PageRedoSetAffinity(uint32 id); + +void DumpPageRedoWorker(PageRedoWorker *worker); +PageRedoWorker *CreateWorker(uint32 id); +extern void UpdateRecordGlobals(RedoItem *item, HotStandbyState standbyState); +void ReferenceRedoItem(void *item); +void DereferenceRedoItem(void *item); +void PushToWorkerLsn(bool force); +void GetCompletedReadEndPtr(PageRedoWorker *worker, XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void SetReadBufferForExtRto(XLogReaderState *state, XLogRecPtr pageptr, int reqLen); +void DumpExtremeRtoReadBuf(); +void PutRecordToReadQueue(XLogReaderState *recordreader); +bool LsnUpdate(); +void ResetRtoXlogReadBuf(XLogRecPtr targetPagePtr); +bool XLogPageReadForExtRto(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen); + +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/posix_semaphore.h postgresql-hll-2.14/include/include/access/extreme_rto/posix_semaphore.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/posix_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/posix_semaphore.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * posix_semaphore.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/posix_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_POSIX_SEMAPHORE_H +#define EXTREME_RTO_POSIX_SEMAPHORE_H + +#include +namespace extreme_rto { + +typedef struct { + sem_t semaphore; + bool initialized; +} PosixSemaphore; + +void PosixSemaphoreInit(PosixSemaphore *sem, unsigned int initValue); +void PosixSemaphoreDestroy(PosixSemaphore *sem); +void PosixSemaphoreWait(PosixSemaphore *sem); +void PosixSemaphorePost(PosixSemaphore *sem); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/redo_item.h postgresql-hll-2.14/include/include/access/extreme_rto/redo_item.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/redo_item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/redo_item.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_item.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/redo_item.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_REDO_ITEM_H +#define EXTREME_RTO_REDO_ITEM_H + +#include "access/xlogreader.h" +#include "datatype/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/atomic.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "access/extreme_rto/posix_semaphore.h" +#include "replication/replicainternal.h" + +namespace extreme_rto { + +typedef struct RedoItem_s { + /* Old version. */ + bool oldVersion; + bool needImmediateCheckpoint; + bool needFullSyncCheckpoint; + /* Number of workers sharing this item. */ + uint32 shareCount; + /* Id of the worker designated to apply this item. */ + uint32 designatedWorker; + /* The expected timelines for this record. */ + List *expectedTLIs; + /* The timestamp of the log record if it is a transaction record. */ + TimestampTz recordXTime; + /* Next item on the free list. */ + struct RedoItem_s *freeNext; + /* Number of workers holding a reference to this item. */ + pg_atomic_uint32 refCount; + /* If this item has been replayed. */ + pg_atomic_uint32 replayed; + /* A "deep" copy of the log record. */ + XLogReaderState record; + /* Used for really free */ + struct RedoItem_s *allocatedNext; + TimestampTz syncXLogReceiptTime; + int syncXLogReceiptSource; + TransactionId RecentXmin; + ServerMode syncServerMode; + + /* temp variable indicate number of redo items with same block number */ + pg_atomic_uint32 blkShareCount; + + bool isForceAll; + pg_atomic_uint32 distributeCount; +} RedoItem; + +static const int32 ANY_BLOCK_ID = -1; +static const uint32 ANY_WORKER = (uint32)-1; +static const uint32 TRXN_WORKER = (uint32)-2; +static const uint32 ALL_WORKER = (uint32)-3; + +static inline RedoItem *GetRedoItemPtr(XLogReaderState *record) +{ + return (RedoItem *)(((char *)record) - offsetof(RedoItem, record)); +} + +RedoItem *CreateRedoItem(XLogReaderState *record, uint32 shareCount, uint32 designatedWorker, List *expectedTLIs, + TimestampTz recordXTime, bool buseoriginal, bool isForceAll = false); + +void ApplyRedoRecord(XLogReaderState *record, bool bOld); +} // namespace extreme_rto + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/spsc_blocking_queue.h postgresql-hll-2.14/include/include/access/extreme_rto/spsc_blocking_queue.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/spsc_blocking_queue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/spsc_blocking_queue.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * spsc_blocking_queue.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/spsc_blocking_queue.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_SPSC_BLOCKING_QUEUE_H +#define EXTREME_RTO_SPSC_BLOCKING_QUEUE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/parallel_recovery/posix_semaphore.h" + + +namespace extreme_rto { +typedef void (*CallBackFunc)(); + +struct SPSCBlockingQueue { + pg_atomic_uint32 writeHead; /* Array index for the next write. */ + pg_atomic_uint32 readTail; /* Array index for the next read. */ + uint32 capacity; /* Queue capacity, must be power of 2. */ + uint32 mask; /* Bit mask for computing index. */ + pg_atomic_uint32 maxUsage; + pg_atomic_uint64 totalCnt; + CallBackFunc callBackFunc; + void *buffer[1]; /* Queue buffer, the actual size is capacity. */ +}; + +SPSCBlockingQueue *SPSCBlockingQueueCreate(uint32 capacity, CallBackFunc func = NULL); +void SPSCBlockingQueueDestroy(SPSCBlockingQueue *queue); + +bool SPSCBlockingQueuePut(SPSCBlockingQueue *queue, void *element); +void *SPSCBlockingQueueTake(SPSCBlockingQueue *queue); +bool SPSCBlockingQueueIsEmpty(SPSCBlockingQueue *queue); +void *SPSCBlockingQueueTop(SPSCBlockingQueue *queue); +void SPSCBlockingQueuePop(SPSCBlockingQueue *queue); +void DumpQueue(const SPSCBlockingQueue *queue); +uint32 SPSCGetQueueCount(SPSCBlockingQueue *queue); +bool SPSCBlockingQueueGetAll(SPSCBlockingQueue *queue, void ***eleArry, uint32 *eleNum); +void SPSCBlockingQueuePopN(SPSCBlockingQueue *queue, uint32 n); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/extreme_rto/txn_redo.h postgresql-hll-2.14/include/include/access/extreme_rto/txn_redo.h --- postgresql-hll-2.14_old/include/include/access/extreme_rto/txn_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/extreme_rto/txn_redo.h 2020-12-12 17:06:43.135346593 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * txn_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/extreme_rto/txn_redo.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXTREME_RTO_TXN_REDO_H +#define EXTREME_RTO_TXN_REDO_H + +#include "access/parallel_recovery/redo_item.h" + +namespace extreme_rto { +void AddTxnRedoItem(PageRedoWorker *worker, void *item); +void TrxnMngProc(RedoItem *item, PageRedoWorker *wk); +void TrxnWorkerProc(RedoItem *item); +} // namespace extreme_rto +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/genam.h postgresql-hll-2.14/include/include/access/genam.h --- postgresql-hll-2.14_old/include/include/access/genam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/genam.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,204 @@ +/* ------------------------------------------------------------------------- + * + * genam.h + * POSTGRES generalized index access method definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/genam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GENAM_H +#define GENAM_H + +#include "access/sdir.h" +#include "access/skey.h" +#include "nodes/tidbitmap.h" +#include "storage/lock.h" +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "vecexecutor/vectorbatch.h" + +// EB: +// removed execnodes.h + +/* + * Struct for statistics returned by ambuild + */ +typedef struct IndexBuildResult { + double heap_tuples; /* # of tuples seen in parent table */ + double index_tuples; /* # of tuples inserted into index */ + double* all_part_tuples; +} IndexBuildResult; + +/* + * Struct for input arguments passed to ambulkdelete and amvacuumcleanup + * + * num_heap_tuples is accurate only when estimated_count is false; + * otherwise it's just an estimate (currently, the estimate is the + * prior value of the relation's pg_class.reltuples field). It will + * always just be an estimate during ambulkdelete. + */ +typedef struct IndexVacuumInfo { + Relation index; /* the index being vacuumed */ + bool analyze_only; /* ANALYZE (without any actual vacuum) */ + bool estimated_count; /* num_heap_tuples is an estimate */ + int message_level; /* ereport level for progress messages */ + double num_heap_tuples; /* tuples remaining in heap */ + BufferAccessStrategy strategy; /* access strategy for reads */ +} IndexVacuumInfo; + +/* + * Struct for statistics returned by ambulkdelete and amvacuumcleanup + * + * This struct is normally allocated by the first ambulkdelete call and then + * passed along through subsequent ones until amvacuumcleanup; however, + * amvacuumcleanup must be prepared to allocate it in the case where no + * ambulkdelete calls were made (because no tuples needed deletion). + * Note that an index AM could choose to return a larger struct + * of which this is just the first field; this provides a way for ambulkdelete + * to communicate additional private data to amvacuumcleanup. + * + * Note: pages_removed is the amount by which the index physically shrank, + * if any (ie the change in its total size on disk). pages_deleted and + * pages_free refer to free space within the index file. Some index AMs + * may compute num_index_tuples by reference to num_heap_tuples, in which + * case they should copy the estimated_count field from IndexVacuumInfo. + */ +typedef struct IndexBulkDeleteResult { + BlockNumber num_pages; /* pages remaining in index */ + BlockNumber pages_removed; /* # removed during vacuum operation */ + bool estimated_count; /* num_index_tuples is an estimate */ + double num_index_tuples; /* tuples remaining */ + double tuples_removed; /* # removed during vacuum operation */ + BlockNumber pages_deleted; /* # unused pages in index */ + BlockNumber pages_free; /* # pages available for reuse */ +} IndexBulkDeleteResult; + +/* Typedef for callback function to determine if a tuple is bulk-deletable */ +typedef bool (*IndexBulkDeleteCallback)(ItemPointer itemptr, void* state, Oid partOid); + +/* struct definitions appear in relscan.h */ +typedef struct IndexScanDescData* IndexScanDesc; +typedef struct SysScanDescData* SysScanDesc; +struct ScanState; + +/* + * Enumeration specifying the type of uniqueness check to perform in + * index_insert(). + * + * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly + * blocking to see if a conflicting transaction commits. + * + * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at + * insertion time. The index AM should test if the tuple is unique, but + * should not throw error, block, or prevent the insertion if the tuple + * appears not to be unique. We'll recheck later when it is time for the + * constraint to be enforced. The AM must return true if the tuple is + * known unique, false if it is possibly non-unique. In the "true" case + * it is safe to omit the later recheck. + * + * When it is time to recheck the deferred constraint, a pseudo-insertion + * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the + * index in this case, so it should not be inserted again. Rather, just + * check for conflicting live tuples (possibly blocking). + */ +typedef enum IndexUniqueCheck { + UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */ + UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */ + UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */ + UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */ +} IndexUniqueCheck; + +/* + * generalized index_ interface routines (in indexam.c) + */ + +/* + * IndexScanIsValid + * True iff the index scan is valid. + */ +#define IndexScanIsValid(scan) PointerIsValid(scan) + +extern Relation index_open(Oid relationId, LOCKMODE lockmode, int2 bucketId=-1); +extern void index_close(Relation relation, LOCKMODE lockmode); + +extern bool index_insert(Relation indexRelation, Datum* values, const bool* isnull, ItemPointer heap_t_ctid, + Relation heapRelation, IndexUniqueCheck checkUnique); + +extern IndexScanDesc index_beginscan( + Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys, ScanState* scan_state=NULL); +extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, int nkeys, ScanState* scan_state=NULL); +extern void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys); +extern void index_endscan(IndexScanDesc scan); +extern void index_markpos(IndexScanDesc scan); +extern void index_restrpos(IndexScanDesc scan); +extern ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction); +extern HeapTuple index_fetch_heap(IndexScanDesc scan); +extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction); +extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap* bitmap); +extern int64 index_column_getbitmap(IndexScanDesc scandesc, const void* sort, VectorBatch* tids); + +extern IndexBulkDeleteResult* index_bulk_delete( + IndexVacuumInfo* info, IndexBulkDeleteResult* stats, IndexBulkDeleteCallback callback, const void* callback_state); +extern IndexBulkDeleteResult* index_vacuum_cleanup(IndexVacuumInfo* info, IndexBulkDeleteResult* stats); +extern bool index_can_return(Relation indexRelation); +extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum); +extern FmgrInfo* index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum); + +/* + * index access method support routines (in genam.c) + */ +extern IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys); +extern void IndexScanEnd(IndexScanDesc scan); +extern char* BuildIndexValueDescription(Relation indexRelation, Datum* values, const bool* isnull); + +/* + * heap-or-index access to system catalogs (in genam.c) + */ +extern SysScanDesc systable_beginscan( + Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapTuple systable_getnext(SysScanDesc sysscan); +extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup); +extern void systable_endscan(SysScanDesc sysscan); +extern SysScanDesc systable_beginscan_ordered( + Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key); +extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction); +extern void systable_endscan_ordered(SysScanDesc sysscan); + +HeapTuple systable_getnext_back(SysScanDesc sysscan); + +/* + * global partition index access method support routines (in genam.c) + */ +typedef struct GPIScanDescData { + HTAB* fakeRelationTable; /* fake partition relation and partition hash table */ + Bitmapset* invisiblePartMap; /* cache invisible partition oid in GPI */ + Relation parentRelation; /* parent relation of partition */ + Relation fakePartRelation; /* fake-relation using partition */ + Partition partition; /* partition use to fake partition rel */ + Oid currPartOid; /* current partition oid in GPI */ +} GPIScanDescData; + +typedef GPIScanDescData* GPIScanDesc; + +/* Check input partition oid is same as global-partition-index current work partition oid */ +inline bool GPIScanCheckPartOid(GPIScanDesc gpiScan, Oid currScanPartOid) +{ + if (!PointerIsValid(gpiScan)) { + return false; + } + + return gpiScan->currPartOid != currScanPartOid; +} +extern void GPIScanInit(GPIScanDesc* gpiScan); +extern void GPIScanEnd(GPIScanDesc gpiScan); +extern bool GPIGetNextPartRelation(GPIScanDesc gpiScan, MemoryContext cxt, LOCKMODE lmode); +extern void GPISetCurrPartOid(GPIScanDesc gpiScan, Oid partOid); +extern Oid GPIGetCurrPartOid(const GPIScanDesc gpiScan); + +#endif /* GENAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gin.h postgresql-hll-2.14/include/include/access/gin.h --- postgresql-hll-2.14_old/include/include/access/gin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gin.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,78 @@ +/* -------------------------------------------------------------------------- + * gin.h + * Public header file for Generalized Inverted Index access method. + * + * Copyright (c) 2006-2014, PostgreSQL Global Development Group + * + * src/include/access/gin.h + * -------------------------------------------------------------------------- + */ +#ifndef GIN_H +#define GIN_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/block.h" +#include "utils/relcache.h" + +/* + * amproc indexes for inverted indexes. + */ +#define GIN_COMPARE_PROC 1 +#define GIN_EXTRACTVALUE_PROC 2 +#define GIN_EXTRACTQUERY_PROC 3 +#define GIN_CONSISTENT_PROC 4 +#define GIN_COMPARE_PARTIAL_PROC 5 +#define GIN_TRICONSISTENT_PROC 6 +#define GINNProcs 6 + +/* + * searchMode settings for extractQueryFn. + */ +#define GIN_SEARCH_MODE_DEFAULT 0 +#define GIN_SEARCH_MODE_INCLUDE_EMPTY 1 +#define GIN_SEARCH_MODE_ALL 2 +#define GIN_SEARCH_MODE_EVERYTHING 3 /* for internal use only */ + +/* + * GinStatsData represents stats data for planner use + */ +typedef struct GinStatsData { + BlockNumber nPendingPages; + BlockNumber nTotalPages; + BlockNumber nEntryPages; + BlockNumber nDataPages; + int64 nEntries; + int32 ginVersion; +} GinStatsData; + +/* + * A ternary value used by tri-consistent functions. + * + * For convenience, this is compatible with booleans. A boolean can be + * safely cast to a GinTernaryValue. + */ +typedef char GinTernaryValue; + +#define GIN_FALSE 0 /* item is not present / does not match */ +#define GIN_TRUE 1 /* item is present / matches */ +#define GIN_MAYBE \ + 2 /* don't know if item is present / don't know \ + * if matches */ + +#define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X)) +#define GinTernaryValueGetDatum(X) ((Datum)(X)) +#define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x) + +/* ginutil.c */ +extern void ginGetStats(Relation index, GinStatsData *stats); +extern void ginUpdateStats(Relation index, const GinStatsData *stats); + +/* ginxlog.c */ +extern void gin_redo(XLogReaderState *record); +extern void gin_desc(StringInfo buf, XLogReaderState *record); +extern void gin_xlog_startup(void); +extern void gin_xlog_cleanup(void); +extern bool IsGinVacuumPages(XLogReaderState *record); + +#endif /* GIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gin_private.h postgresql-hll-2.14/include/include/access/gin_private.h --- postgresql-hll-2.14_old/include/include/access/gin_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gin_private.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,927 @@ +/* -------------------------------------------------------------------------- + * gin_private.h + * header file for postgres inverted index access method implementation. + * + * Copyright (c) 2006-2014, PostgreSQL Global Development Group + * + * src/include/access/gin_private.h + * -------------------------------------------------------------------------- + */ +#ifndef GIN_PRIVATE_H +#define GIN_PRIVATE_H + +#include "access/genam.h" +#include "access/gin.h" +#include "access/itup.h" +#include "fmgr.h" +#include "storage/bufmgr.h" +#include "utils/rbtree.h" + +/* + * Page opaque data in an inverted index page. + * + * Note: GIN does not include a page ID word as do the other index types. + * This is OK because the opaque data is only 8 bytes and so can be reliably + * distinguished by size. Revisit this if the size ever increases. + * Further note: as of 9.2, SP-GiST also uses 8-byte special space. This is + * still OK, as long as GIN isn't using all of the high-order bits in its + * flags word, because that way the flags word cannot match the page ID used + * by SP-GiST. + */ +typedef struct GinPageOpaqueData { + BlockNumber rightlink; /* next page if any */ + OffsetNumber maxoff; /* number of PostingItems on GIN_DATA & + * ~GIN_LEAF page. On GIN_LIST page, number of + * heap tuples. */ + uint16 flags; /* see bit definitions below */ +} GinPageOpaqueData; + +typedef GinPageOpaqueData *GinPageOpaque; + +#define GIN_DATA (1 << 0) +#define GIN_LEAF (1 << 1) +#define GIN_DELETED (1 << 2) +#define GIN_META (1 << 3) +#define GIN_LIST (1 << 4) +#define GIN_LIST_FULLROW (1 << 5) /* makes sense only on GIN_LIST page */ +#define GIN_INCOMPLETE_SPLIT \ + (1 << 6) /* page was split, but parent not \ + * updated */ +#define GIN_COMPRESSED (1 << 7) + +/* Page numbers of fixed-location pages */ +#define GIN_METAPAGE_BLKNO (0) +#define GIN_ROOT_BLKNO (1) + +typedef struct GinMetaPageData { + /* + * Pointers to head and tail of pending list, which consists of GIN_LIST + * pages. These store fast-inserted entries that haven't yet been moved + * into the regular GIN structure. + */ + BlockNumber head; + BlockNumber tail; + + /* + * Free space in bytes in the pending list's tail page. + */ + uint32 tailFreeSize; + + /* + * We store both number of pages and number of heap tuples that are in the + * pending list. + */ + BlockNumber nPendingPages; + int64 nPendingHeapTuples; + + /* + * Statistics for planner use (accurate as of last VACUUM) + */ + BlockNumber nTotalPages; + BlockNumber nEntryPages; + BlockNumber nDataPages; + int64 nEntries; + + /* + * GIN version number (ideally this should have been at the front, but too + * late now. Don't move it!) + * + * Currently 2 (for indexes initialized in 9.4 or later) + * + * Version 1 (indexes initialized in version 9.1, 9.2 or 9.3), is + * compatible, but may contain uncompressed posting tree (leaf) pages and + * posting lists. They will be converted to compressed format when + * modified. + * + * Version 0 (indexes initialized in 9.0 or before) is compatible but may + * be missing null entries, including both null keys and placeholders. + * Reject full-index-scan attempts on such indexes. + */ + int32 ginVersion; +} GinMetaPageData; + +#define GIN_CURRENT_VERSION 2 + +#define GinPageGetMeta(p) ((GinMetaPageData *)PageGetContents(p)) + +/* + * Macros for accessing a GIN index page's opaque data + */ +#define GinPageGetOpaque(page) ((GinPageOpaque)PageGetSpecialPointer(page)) + +#define GinPageIsLeaf(page) (GinPageGetOpaque(page)->flags & GIN_LEAF) +#define GinPageSetLeaf(page) (GinPageGetOpaque(page)->flags |= GIN_LEAF) +#define GinPageSetNonLeaf(page) (GinPageGetOpaque(page)->flags &= ~GIN_LEAF) +#define GinPageIsData(page) (GinPageGetOpaque(page)->flags & GIN_DATA) +#define GinPageSetData(page) (GinPageGetOpaque(page)->flags |= GIN_DATA) +#define GinPageIsList(page) (GinPageGetOpaque(page)->flags & GIN_LIST) +#define GinPageSetList(page) (GinPageGetOpaque(page)->flags |= GIN_LIST) +#define GinPageHasFullRow(page) (GinPageGetOpaque(page)->flags & GIN_LIST_FULLROW) +#define GinPageSetFullRow(page) (GinPageGetOpaque(page)->flags |= GIN_LIST_FULLROW) +#define GinPageIsCompressed(page) (GinPageGetOpaque(page)->flags & GIN_COMPRESSED) +#define GinPageSetCompressed(page) (GinPageGetOpaque(page)->flags |= GIN_COMPRESSED) + +#define GinPageIsDeleted(page) (GinPageGetOpaque(page)->flags & GIN_DELETED) +#define GinPageSetDeleted(page) (GinPageGetOpaque(page)->flags |= GIN_DELETED) +#define GinPageSetNonDeleted(page) (GinPageGetOpaque(page)->flags &= ~GIN_DELETED) +#define GinPageIsIncompleteSplit(page) (GinPageGetOpaque(page)->flags & GIN_INCOMPLETE_SPLIT) + +#define GinPageRightMost(page) (GinPageGetOpaque(page)->rightlink == InvalidBlockNumber) + +/* + * We use our own ItemPointerGet(BlockNumber|OffsetNumber) + * to avoid Asserts, since sometimes the ip_posid isn't "valid" + */ +#define GinItemPointerGetBlockNumber(pointer) BlockIdGetBlockNumber(&(pointer)->ip_blkid) + +#define GinItemPointerGetOffsetNumber(pointer) ((pointer)->ip_posid) + +/* + * Special-case item pointer values needed by the GIN search logic. + * MIN: sorts less than any valid item pointer + * MAX: sorts greater than any valid item pointer + * LOSSY PAGE: indicates a whole heap page, sorts after normal item + * pointers for that page + * Note that these are all distinguishable from an "invalid" item pointer + * (which is InvalidBlockNumber/0) as well as from all normal item + * pointers (which have item numbers in the range 1..MaxHeapTuplesPerPage). + */ +#define ItemPointerSetMin(p) ItemPointerZero(p) +#define ItemPointerIsMin(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0 && GinItemPointerGetBlockNumber(p) == (BlockNumber)0) +#define ItemPointerSetMax(p) ItemPointerSet((p), InvalidBlockNumber, (OffsetNumber)0xffff) +#define ItemPointerIsMax(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && GinItemPointerGetBlockNumber(p) == InvalidBlockNumber) +#define ItemPointerSetLossyPage(p, b) ItemPointerSet((p), (b), (OffsetNumber)0xffff) +#define ItemPointerIsLossyPage(p) \ + (GinItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && GinItemPointerGetBlockNumber(p) != InvalidBlockNumber) + +/* + * Posting item in a non-leaf posting-tree page + */ +typedef struct { + /* We use BlockIdData not BlockNumber to avoid padding space wastage */ + BlockIdData child_blkno; + ItemPointerData key; +} PostingItem; + +#define PostingItemGetBlockNumber(pointer) BlockIdGetBlockNumber(&(pointer)->child_blkno) + +#define PostingItemSetBlockNumber(pointer, blockNumber) BlockIdSet(&((pointer)->child_blkno), (blockNumber)) + +/* + * Category codes to distinguish placeholder nulls from ordinary NULL keys. + * Note that the datatype size and the first two code values are chosen to be + * compatible with the usual usage of bool isNull flags. + * + * GIN_CAT_EMPTY_QUERY is never stored in the index; and notice that it is + * chosen to sort before not after regular key values. + */ +typedef signed char GinNullCategory; + +#define GIN_CAT_NORM_KEY 0 /* normal, non-null key value */ +#define GIN_CAT_NULL_KEY 1 /* null key value */ +#define GIN_CAT_EMPTY_ITEM 2 /* placeholder for zero-key item */ +#define GIN_CAT_NULL_ITEM 3 /* placeholder for null item */ +#define GIN_CAT_EMPTY_QUERY (-1) /* placeholder for full-scan query */ + +/* + * Access macros for null category byte in entry tuples + */ +#define GinCategoryOffset(itup, ginstate) \ + (IndexInfoFindDataOffset((itup)->t_info) + ((ginstate)->oneCol ? 0 : sizeof(int16))) +#define GinGetNullCategory(itup, ginstate) (*((GinNullCategory *)((char *)(itup) + GinCategoryOffset(itup, ginstate)))) +#define GinSetNullCategory(itup, ginstate, c) \ + (*((GinNullCategory *)((char *)(itup) + GinCategoryOffset(itup, ginstate))) = (c)) + +/* + * Access macros for leaf-page entry tuples (see discussion in README) + */ +#define GinGetNPosting(itup) GinItemPointerGetOffsetNumber(&(itup)->t_tid) +#define GinSetNPosting(itup, n) ItemPointerSetOffsetNumber(&(itup)->t_tid, n) +#define GIN_TREE_POSTING ((OffsetNumber)0xffff) +#define GinIsPostingTree(itup) (GinGetNPosting(itup) == GIN_TREE_POSTING) +#define GinSetPostingTree(itup, blkno) do { \ + GinSetNPosting((itup), GIN_TREE_POSTING); \ + ItemPointerSetBlockNumber(&(itup)->t_tid, blkno); \ +} while (0) + +#define GinGetPostingTree(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid) + +#define GIN_ITUP_COMPRESSED ((uint32)1 << 31) +#define GinGetPostingOffset(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & (~GIN_ITUP_COMPRESSED)) +#define GinSetPostingOffset(itup, n) ItemPointerSetBlockNumber(&(itup)->t_tid, (n) | GIN_ITUP_COMPRESSED) +#define GinGetPosting(itup) ((Pointer)((char *)(itup) + GinGetPostingOffset(itup))) +#define GinItupIsCompressed(itup) (GinItemPointerGetBlockNumber(&(itup)->t_tid) & GIN_ITUP_COMPRESSED) + +/* + * Maximum size of an item on entry tree page. Make sure that we fit at least + * three items on each page. (On regular B-tree indexes, we must fit at least + * three items: two data items and the "high key". In GIN entry tree, we don't + * currently store the high key explicitly, we just use the rightmost item on + * the page, so it would actually be enough to fit two items.) + */ +#define GinMaxItemSize \ + Min(INDEX_SIZE_MASK, MAXALIGN_DOWN(((BLCKSZ - MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \ + MAXALIGN(sizeof(GinPageOpaqueData))) / \ + 3))) + +/* + * Access macros for non-leaf entry tuples + */ +#define GinGetDownlink(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid) +#define GinSetDownlink(itup, blkno) ItemPointerSet(&(itup)->t_tid, blkno, InvalidOffsetNumber) + +/* + * Data (posting tree) pages + * + * Posting tree pages don't store regular tuples. Non-leaf pages contain + * PostingItems, which are pairs of ItemPointers and child block numbers. + * Leaf pages contain GinPostingLists and an uncompressed array of item + * pointers. + * + * In a leaf page, the compressed posting lists are stored after the regular + * page header, one after each other. Although we don't store regular tuples, + * pd_lower is used to indicate the end of the posting lists. After that, free + * space follows. This layout is compatible with the "standard" heap and + * index page layout described in bufpage.h, so that we can e.g set buffer_std + * when writing WAL records. + * + * In the special space is the GinPageOpaque struct. + */ +#define GinDataLeafPageGetPostingList(page) \ + (GinPostingList *)((PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData)))) +#define GinDataLeafPageGetPostingListSize(page) \ + (((PageHeader)page)->pd_lower - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(ItemPointerData))) + +#define GinDataLeafPageIsEmpty(page) \ + (GinPageIsCompressed(page) ? (GinDataLeafPageGetPostingListSize(page) == 0) \ + : (GinPageGetOpaque(page)->maxoff < FirstOffsetNumber)) + +#define GinDataLeafPageGetFreeSpace(page) PageGetExactFreeSpace(page) + +#define GinDataPageGetRightBound(page) ((ItemPointer)PageGetContents(page)) +/* + * Pointer to the data portion of a posting tree page. For internal pages, + * that's the beginning of the array of PostingItems. For compressed leaf + * pages, the first compressed posting list. For uncompressed (pre-9.4) leaf + * pages, it's the beginning of the ItemPointer array. + */ +#define GinDataPageGetData(page) (PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData))) +/* non-leaf pages contain PostingItems */ +#define GinDataPageGetPostingItem(page, i) ((PostingItem *)(GinDataPageGetData(page) + ((i)-1) * sizeof(PostingItem))) + +/* + * Note: there is no GinDataPageGetDataSize macro, because before version + * 9.4, we didn't set pd_lower on data pages. There can be pages in the index + * that were binary-upgraded from earlier versions and still have an invalid + * pd_lower, so we cannot trust it in general. Compressed posting tree leaf + * pages are new in 9.4, however, so we can trust them; see + * GinDataLeafPageGetPostingListSize. + */ +#define GinDataPageSetDataSize(page, size) do { \ + Assert((uintptr_t)size <= GinDataPageMaxDataSize); \ + ((PageHeader)page)->pd_lower = (size) + MAXALIGN(SizeOfPageHeaderData) + MAXALIGN(sizeof(ItemPointerData)); \ +} while (0) + +#define GinNonLeafDataPageGetFreeSpace(page) \ + (GinDataPageMaxDataSize - GinPageGetOpaque(page)->maxoff * sizeof(PostingItem)) + +#define GinDataPageMaxDataSize \ + (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - MAXALIGN(sizeof(ItemPointerData)) - MAXALIGN(sizeof(GinPageOpaqueData))) + +/* + * List pages + */ +#define GinListPageSize (BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GinPageOpaqueData))) + +/* + * Storage type for GIN's reloptions + */ +typedef struct GinOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + bool useFastUpdate; /* use fast updates? */ + int pendingListCleanupSize; /* maximum size of pending list */ +} GinOptions; + +#define GIN_DEFAULT_USE_FASTUPDATE true +#define GinGetUseFastUpdate(relation) \ + ((relation)->rd_options ? ((GinOptions *)(relation)->rd_options)->useFastUpdate : GIN_DEFAULT_USE_FASTUPDATE) +#define GinGetPendingListCleanupSize(relation) \ + ((relation)->rd_options && ((GinOptions *)(relation)->rd_options)->pendingListCleanupSize != -1 \ + ? ((GinOptions *)(relation)->rd_options)->pendingListCleanupSize \ + : u_sess->attr.attr_storage.gin_pending_list_limit) + +/* Macros for buffer lock/unlock operations */ +#define GIN_UNLOCK BUFFER_LOCK_UNLOCK +#define GIN_SHARE BUFFER_LOCK_SHARE +#define GIN_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE + +/* + * GinState: working data structure describing the index being worked on + */ +typedef struct GinState { + Relation index; + bool oneCol; /* true if single-column index */ + + /* + * origTupDesc is the nominal tuple descriptor of the index, ie, the i'th + * attribute shows the key type (not the input data type!) of the i'th + * index column. In a single-column index this describes the actual leaf + * index tuples. In a multi-column index, the actual leaf tuples contain + * a smallint column number followed by a key datum of the appropriate + * type for that column. We set up tupdesc[i] to describe the actual + * rowtype of the index tuples for the i'th column, ie, (int2, keytype). + * Note that in any case, leaf tuples contain more data than is known to + * the TupleDesc; see access/gin/README for details. + */ + TupleDesc origTupdesc; + TupleDesc tupdesc[INDEX_MAX_KEYS]; + + /* + * Per-index-column opclass support functions + */ + FmgrInfo compareFn[INDEX_MAX_KEYS]; + FmgrInfo extractValueFn[INDEX_MAX_KEYS]; + FmgrInfo extractQueryFn[INDEX_MAX_KEYS]; + FmgrInfo consistentFn[INDEX_MAX_KEYS]; + FmgrInfo triConsistentFn[INDEX_MAX_KEYS]; + FmgrInfo comparePartialFn[INDEX_MAX_KEYS]; /* optional method */ + /* canPartialMatch[i] is true if comparePartialFn[i] is valid */ + bool canPartialMatch[INDEX_MAX_KEYS]; + /* Collations to pass to the support functions */ + Oid supportCollation[INDEX_MAX_KEYS]; +} GinState; + +typedef enum { + ROW_STORE_TYPE = 0, + COL_STORE_TYPE = 1, +} GinPostingListType; + +/* + * A compressed posting list. + * + * Note: This requires 2-byte alignment. + */ +typedef struct { + GinPostingListType type; /* posting list type for row or column cstore */ + ItemPointerData first; /* first item in this posting list (unpacked) */ + uint16 nbytes; /* number of bytes that follow */ + unsigned char bytes[FLEXIBLE_ARRAY_MEMBER]; /* varbyte encoded items (variable length) */ +} GinPostingList; + +#define SizeOfGinPostingList(plist) (offsetof(GinPostingList, bytes) + SHORTALIGN((plist)->nbytes)) +#define GinNextPostingListSegment(cur) ((GinPostingList *)(((char *)(cur)) + SizeOfGinPostingList((cur)))) + +/* XLog stuff */ +#define XLOG_GIN_CREATE_INDEX 0x00 +#define XLOG_GIN_CREATE_PTREE 0x10 + +typedef struct ginxlogCreatePostingTree { + uint32 size; + /* A compressed posting list follows */ +} ginxlogCreatePostingTree; + +/* + * The format of the insertion record varies depending on the page type. + * ginxlogInsert is the common part between all variants. + * + * Backup Blk 0: target page + * Backup Blk 1: left child, if this insertion finishes an incomplete split + */ +#define XLOG_GIN_INSERT 0x20 + +typedef struct { + uint16 flags; /* GIN_INSERT_ISLEAF and/or GIN_INSERT_ISDATA */ + + /* + * FOLLOWS: + * + * 1. if not leaf page, block numbers of the left and right child pages + * whose split this insertion finishes, as BlockIdData[2] (beware of + * adding fields in this struct that would make them not 16-bit aligned) + * + * 2. a ginxlogInsertEntry or ginxlogRecompressDataLeaf struct, depending + * on tree type. + * + * NB: the below structs are only 16-bit aligned when appended to a + * ginxlogInsert struct! Beware of adding fields to them that require + * stricter alignment. + */ +} ginxlogInsert; + +typedef struct ginxlogInsertEntry { + OffsetNumber offset; + bool isDelete; + IndexTupleData tuple; /* variable length */ +} ginxlogInsertEntry; + +typedef struct { + uint16 nactions; + + /* Variable number of 'actions' follow */ +} ginxlogRecompressDataLeaf; + +/* + * Note: this struct is currently not used in code, and only acts as + * documentation. The WAL record format is as specified here, but the code + * uses straight access through a Pointer and memcpy to read/write these. + */ +typedef struct { + uint8 segno; /* segment this action applies to */ + char type; /* action type (see below) */ + + /* + * Action-specific data follows. For INSERT and REPLACE actions that is a + * GinPostingList struct. For ADDITEMS, a uint16 for the number of items + * added, followed by the items themselves as ItemPointers. DELETE actions + * have no further data. + */ +} ginxlogSegmentAction; + +/* Action types */ +#define GIN_SEGMENT_UNMODIFIED 0 /* no action (not used in WAL records) */ +#define GIN_SEGMENT_DELETE 1 /* a whole segment is removed */ +#define GIN_SEGMENT_INSERT 2 /* a whole segment is added */ +#define GIN_SEGMENT_REPLACE 3 /* a segment is replaced */ +#define GIN_SEGMENT_ADDITEMS 4 /* items are added to existing segment */ + +typedef struct ginxlogInsertDataInternal { + OffsetNumber offset; + PostingItem newitem; +} ginxlogInsertDataInternal; + +/* + * Backup Blk 0: new left page (= original page, if not root split) + * Backup Blk 1: new right page + * Backup Blk 2: original page / new root page, if root split + * Backup Blk 3: left child, if this insertion completes an earlier split + */ +#define XLOG_GIN_SPLIT 0x30 + +typedef struct ginxlogSplit { + RelFileNode node; + BlockNumber rrlink; /* right link, or root's blocknumber if root + * split */ + BlockNumber leftChildBlkno; /* valid on a non-leaf split */ + BlockNumber rightChildBlkno; + uint16 flags; /* see below */ +} ginxlogSplit; + +/* + * Flags used in ginxlogInsert and ginxlogSplit records + */ +#define GIN_INSERT_ISDATA 0x01 /* for both insert and split records */ +#define GIN_INSERT_ISLEAF 0x02 /* ditto */ +#define GIN_SPLIT_ROOT 0x04 /* only for split records */ + +typedef struct { + OffsetNumber separator; + OffsetNumber nitem; + + /* FOLLOWS: IndexTuples */ +} ginxlogSplitEntry; + +typedef struct { + uint16 lsize; + uint16 rsize; + ItemPointerData lrightbound; /* new right bound of left page */ + ItemPointerData rrightbound; /* new right bound of right page */ + + /* FOLLOWS: new compressed posting lists of left and right page */ + char newdata[1]; +} ginxlogSplitDataLeaf; + +typedef struct { + OffsetNumber separator; + OffsetNumber nitem; + ItemPointerData rightbound; + + /* FOLLOWS: array of PostingItems */ +} ginxlogSplitDataInternal; + +/* + * Vacuum simply WAL-logs the whole page, when anything is modified. This + * is functionally identical to heap_newpage records, but is kept separate for + * debugging purposes. (When inspecting the WAL stream, it's easier to see + * what's going on when GIN vacuum records are marked as such, not as heap + * records.) This is currently only used for entry tree leaf pages. + */ +#define XLOG_GIN_VACUUM_PAGE 0x40 + +/* + * Vacuuming posting tree leaf page is WAL-logged like recompression caused + * by insertion. + */ +#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE 0x90 + +typedef struct ginxlogVacuumDataLeafPage { + ginxlogRecompressDataLeaf data; +} ginxlogVacuumDataLeafPage; + +/* + * Backup Blk 0: deleted page + * Backup Blk 1: parent + * Backup Blk 2: left sibling + */ +#define XLOG_GIN_DELETE_PAGE 0x50 + +typedef struct ginxlogDeletePage { + OffsetNumber parentOffset; + BlockNumber rightLink; +} ginxlogDeletePage; + +#define XLOG_GIN_UPDATE_META_PAGE 0x60 + +/* + * Backup Blk 0: metapage + * Backup Blk 1: tail page + */ +typedef struct ginxlogUpdateMeta { + RelFileNode node; + GinMetaPageData metadata; + BlockNumber prevTail; + BlockNumber newRightlink; + int32 ntuples; /* if ntuples > 0 then metadata.tail was + * updated with that many tuples; else new sub + * list was inserted */ + /* array of inserted tuples follows */ +} ginxlogUpdateMeta; + +#define XLOG_GIN_INSERT_LISTPAGE 0x70 + +typedef struct ginxlogInsertListPage { + BlockNumber rightlink; + int32 ntuples; + /* array of inserted tuples follows */ +} ginxlogInsertListPage; +/* + * Backup Blk 0: metapage + * Backup Blk 1 to (ndeleted + 1): deleted pages + */ +#define XLOG_GIN_DELETE_LISTPAGE 0x80 + +/* + * The WAL record for deleting list pages must contain a block reference to + * all the deleted pages, so the number of pages that can be deleted in one + * record is limited by XLR_MAX_BLOCK_ID. (block_id 0 is used for the + * metapage.) + */ +#define GIN_NDELETE_AT_ONCE Min(16, XLR_MAX_BLOCK_ID - 1) +typedef struct ginxlogDeleteListPages { + GinMetaPageData metadata; + int32 ndeleted; +} ginxlogDeleteListPages; + +/* ginutil.c */ +extern Datum ginoptions(PG_FUNCTION_ARGS); +extern void initGinState(GinState *state, Relation index); +extern Buffer GinNewBuffer(Relation index); +extern void GinInitBuffer(Buffer b, uint32 f); +extern void GinInitPage(Page page, uint32 f, Size pageSize); +extern void GinInitMetabuffer(Buffer b); +extern void GinInitMetaPage(Page page, Size pageSize); +extern int ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, GinNullCategory categorya, Datum b, + GinNullCategory categoryb); +extern int ginCompareAttEntries(GinState *ginstate, OffsetNumber attnuma, Datum a, GinNullCategory categorya, + OffsetNumber attnumb, Datum b, GinNullCategory categoryb); +extern Datum *ginExtractEntries(GinState *ginstate, OffsetNumber attnum, Datum value, bool isNull, int32 *nentries, + GinNullCategory **categories); + +extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple); +extern Datum gintuple_get_key(GinState *ginstate, IndexTuple tuple, GinNullCategory *category); + +/* gininsert.c */ +extern Datum ginmerge(PG_FUNCTION_ARGS); +extern Datum ginbuild(PG_FUNCTION_ARGS); +extern Datum ginbuildempty(PG_FUNCTION_ARGS); +extern Datum gininsert(PG_FUNCTION_ARGS); +extern void ginEntryInsert(GinState *ginstate, OffsetNumber attnum, Datum key, GinNullCategory category, + ItemPointerData *items, uint32 nitem, GinStatsData *buildStats); +extern Datum cginbuild(PG_FUNCTION_ARGS); + +/* ginbtree.c */ +typedef struct GinBtreeStack { + BlockNumber blkno; + Buffer buffer; + OffsetNumber off; + ItemPointerData iptr; + /* predictNumber contains predicted number of pages on current level */ + uint32 predictNumber; + struct GinBtreeStack *parent; +} GinBtreeStack; + +typedef struct GinBtreeData *GinBtree; + +/* Return codes for GinBtreeData.beginPlaceToPage method */ +typedef enum { + GPTP_NO_WORK, + GPTP_INSERT, + GPTP_SPLIT +} GinPlaceToPageRC; + +typedef struct GinBtreeData { + /* search methods */ + BlockNumber (*findChildPage)(GinBtree, GinBtreeStack *); + BlockNumber (*getLeftMostChild)(GinBtree, Page); + bool (*isMoveRight)(GinBtree, Page); + bool (*findItem)(GinBtree, GinBtreeStack *); + + /* insert methods */ + OffsetNumber (*findChildPtr)(GinBtree, Page, BlockNumber, OffsetNumber); + GinPlaceToPageRC (*beginPlaceToPage)(GinBtree, Buffer, GinBtreeStack *, void *, BlockNumber, void **, Page *, + Page *); + void (*execPlaceToPage)(GinBtree, Buffer, GinBtreeStack *, void *, BlockNumber, void *); + void *(*prepareDownlink)(GinBtree, Buffer); + void (*fillRoot)(GinBtree, Page, BlockNumber, Page, BlockNumber, Page); + + bool isData; + + Relation index; + BlockNumber rootBlkno; + GinState *ginstate; /* not valid in a data scan */ + bool fullScan; + bool isBuild; + + /* Search key for Entry tree */ + OffsetNumber entryAttnum; + Datum entryKey; + GinNullCategory entryCategory; + + /* Search key for data tree (posting tree) */ + ItemPointerData itemptr; +} GinBtreeData; + +/* This represents a tuple to be inserted to entry tree. */ +typedef struct { + IndexTuple entry; /* tuple to insert */ + bool isDelete; /* delete old tuple at same offset? */ +} GinBtreeEntryInsertData; + +/* + * This represents an itempointer, or many itempointers, to be inserted to + * a data (posting tree) leaf page + */ +typedef struct { + ItemPointerData *items; + uint32 nitem; + uint32 curitem; +} GinBtreeDataLeafInsertData; + +/* + * For internal data (posting tree) pages, the insertion payload is a + * PostingItem + */ +extern GinBtreeStack *ginFindLeafPage(GinBtree btree, bool searchMode); +extern Buffer ginStepRight(Buffer buffer, Relation index, int lockmode); +extern void freeGinBtreeStack(GinBtreeStack *stack); +extern void ginInsertValue(GinBtree btree, GinBtreeStack *stack, void *insertdata, GinStatsData *buildStats); + +/* ginentrypage.c */ +extern IndexTuple GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key, GinNullCategory category, + Pointer data, Size dataSize, int nipd, bool errorTooBig); +extern void ginPrepareEntryScan(GinBtree btree, OffsetNumber attnum, Datum key, GinNullCategory category, + GinState *ginstate); +extern void ginEntryFillRoot(GinBtree btree, Page root, BlockNumber lblkno, Page lpage, BlockNumber rblkno, Page rpage); +extern ItemPointer ginReadTuple(GinState *ginstate, OffsetNumber attnum, IndexTuple itup, int *nitems); + +/* gindatapage.c */ +extern ItemPointer GinDataLeafPageGetItems(Page page, int *nitems, ItemPointerData advancePast); +extern int GinDataLeafPageGetItemsToTbm(Page page, TIDBitmap *tbm); +extern BlockNumber createPostingTree(Relation index, ItemPointerData *items, uint32 nitems, GinStatsData *buildStats); +extern void GinDataPageAddPostingItem(Page page, PostingItem *data, OffsetNumber offset); +extern void GinPageDeletePostingItem(Page page, OffsetNumber offset); +extern void ginInsertItemPointers(Relation index, BlockNumber rootBlkno, ItemPointerData *items, uint32 nitem, + GinStatsData *buildStats); +extern GinBtreeStack *ginScanBeginPostingTree(GinBtree btree, Relation index, BlockNumber rootBlkno); +extern void ginDataFillRoot(GinBtree btree, Page root, BlockNumber lblkno, Page lpage, BlockNumber rblkno, Page rpage); +extern void ginPrepareDataScan(GinBtree btree, Relation index, BlockNumber rootBlkno); + +/* + * This is declared in ginvacuum.c, but is passed between ginVacuumItemPointers + * and ginVacuumPostingTreeLeaf and as an opaque struct, so we need a forward + * declaration for it. + */ +typedef struct GinVacuumState GinVacuumState; + +extern void ginVacuumPostingTreeLeaf(Relation rel, Buffer buf, GinVacuumState *gvs); + +/* ginscan.c */ +/* + * GinScanKeyData describes a single GIN index qualifier expression. + * + * From each qual expression, we extract one or more specific index search + * conditions, which are represented by GinScanEntryData. It's quite + * possible for identical search conditions to be requested by more than + * one qual expression, in which case we merge such conditions to have just + * one unique GinScanEntry --- this is particularly important for efficiency + * when dealing with full-index-scan entries. So there can be multiple + * GinScanKeyData.scanEntry pointers to the same GinScanEntryData. + * + * In each GinScanKeyData, nentries is the true number of entries, while + * nuserentries is the number that extractQueryFn returned (which is what + * we report to consistentFn). The "user" entries must come first. + */ +typedef struct GinScanKeyData *GinScanKey; + +typedef struct GinScanEntryData *GinScanEntry; + +typedef struct GinScanKeyData { + /* Real number of entries in scanEntry[] (always > 0) */ + uint32 nentries; + /* Number of entries that extractQueryFn and consistentFn know about */ + uint32 nuserentries; + + /* array of GinScanEntry pointers, one per extracted search condition */ + GinScanEntry *scanEntry; + + /* + * At least one of the entries in requiredEntries must be present for a + * tuple to match the overall qual. + * + * additionalEntries contains entries that are needed by the consistent + * function to decide if an item matches, but are not sufficient to + * satisfy the qual without entries from requiredEntries. + */ + GinScanEntry *requiredEntries; + int nrequired; + GinScanEntry *additionalEntries; + int nadditional; + + /* array of check flags, reported to consistentFn */ + GinTernaryValue *entryRes; + bool (*boolConsistentFn)(GinScanKey key); + GinTernaryValue (*triConsistentFn)(GinScanKey key); + FmgrInfo *consistentFmgrInfo; + FmgrInfo *triConsistentFmgrInfo; + Oid collation; + + /* other data needed for calling consistentFn */ + Datum query; + /* NB: these three arrays have only nuserentries elements! */ + Datum *queryValues; + GinNullCategory *queryCategories; + Pointer *extra_data; + StrategyNumber strategy; + int32 searchMode; + OffsetNumber attnum; + + /* + * Match status data. curItem is the TID most recently tested (could be a + * lossy-page pointer). curItemMatches is TRUE if it passes the + * consistentFn test; if so, recheckCurItem is the recheck flag. + * isFinished means that all the input entry streams are finished, so this + * key cannot succeed for any later TIDs. + */ + ItemPointerData curItem; + bool curItemMatches; + bool recheckCurItem; + bool isFinished; +} GinScanKeyData; + +typedef struct GinScanEntryData { + /* query key and other information from extractQueryFn */ + Datum queryKey; + GinNullCategory queryCategory; + bool isPartialMatch; + Pointer extra_data; + StrategyNumber strategy; + int32 searchMode; + OffsetNumber attnum; + + /* Current page in posting tree */ + Buffer buffer; + + /* current ItemPointer to heap */ + ItemPointerData curItem; + + /* for a partial-match or full-scan query, we accumulate all TIDs here */ + TIDBitmap *matchBitmap; + TBMIterator *matchIterator; + TBMIterateResult *matchResult; + + ItemPointerData *matchList; + int matchNum; + + /* used for Posting list and one page in Posting tree */ + ItemPointerData *list; + int nlist; + int offset; + + bool isFinished; + bool reduceResult; + uint32 predictNumberResult; + GinBtreeData btree; +} GinScanEntryData; + +typedef struct GinScanOpaqueData { + MemoryContext tempCtx; + GinState ginstate; + + GinScanKey keys; /* one per scan qualifier expr */ + uint32 nkeys; + + GinScanEntry *entries; /* one per index search condition */ + uint32 totalentries; + uint32 allocentries; /* allocated length of entries[] */ + + MemoryContext keyCtx; /* used to hold key and entry data */ + + bool isVoidRes; /* true if query is unsatisfiable */ +} GinScanOpaqueData; + +typedef GinScanOpaqueData *GinScanOpaque; + +extern Datum ginbeginscan(PG_FUNCTION_ARGS); +extern Datum ginendscan(PG_FUNCTION_ARGS); +extern Datum ginrescan(PG_FUNCTION_ARGS); +extern Datum ginmarkpos(PG_FUNCTION_ARGS); +extern Datum ginrestrpos(PG_FUNCTION_ARGS); +extern void ginNewScanKey(IndexScanDesc scan); +extern void ginFreeScanKeys(GinScanOpaque so); + +/* ginget.c */ +extern Datum gingetbitmap(PG_FUNCTION_ARGS); +extern Datum cgingetbitmap(PG_FUNCTION_ARGS); + +/* ginfast.c */ +extern Datum gin_clean_pending_list(PG_FUNCTION_ARGS); + +/* ginlogic.c */ +extern void ginInitConsistentFunction(GinState *ginstate, GinScanKey key); + +/* ginvacuum.c */ +extern Datum ginbulkdelete(PG_FUNCTION_ARGS); +extern Datum ginvacuumcleanup(PG_FUNCTION_ARGS); +extern ItemPointer ginVacuumItemPointers(GinVacuumState *gvs, ItemPointerData *items, int nitem, int *nremaining); + +/* ginbulk.c */ +typedef struct GinEntryAccumulator { + RBNode rbnode; + Datum key; + GinNullCategory category; + OffsetNumber attnum; + bool shouldSort; + ItemPointerData *list; + uint32 maxcount; /* allocated size of list[] */ + uint32 count; /* current number of list[] entries */ +} GinEntryAccumulator; + +typedef struct { + GinState *ginstate; + Size allocatedMemory; + GinEntryAccumulator *entryallocator; + uint32 eas_used; + RBTree *tree; +} BuildAccumulator; + +extern void ginInitBA(BuildAccumulator *accum); +extern void ginInsertBAEntries(BuildAccumulator *accum, ItemPointer heapptr, OffsetNumber attnum, Datum *entries, + GinNullCategory *categories, int32 nentries); +extern void ginBeginBAScan(BuildAccumulator *accum); +extern ItemPointerData *ginGetBAEntry(BuildAccumulator *accum, OffsetNumber *attnum, Datum *key, + GinNullCategory *category, uint32 *n); + +/* ginfast.c */ +typedef struct GinTupleCollector { + IndexTuple *tuples; + uint32 ntuples; + uint32 lentuples; + uint32 sumsize; +} GinTupleCollector; + +extern void ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector); +extern void ginHeapTupleFastCollect(GinState *ginstate, GinTupleCollector *collector, OffsetNumber attnum, Datum value, + bool isNull, ItemPointer ht_ctid); +extern void ginInsertCleanup(GinState* ginstate, bool full_clean, bool fill_fsm, bool forceCleanup, + IndexBulkDeleteResult* stats); + +/* ginpostinglist.c */ +extern GinPostingList *ginCompressPostingList(const ItemPointer ptrs, int nptrs, int maxsize, int *nwritten, + bool isColStore); +extern int ginPostingListDecodeAllSegmentsToTbm(GinPostingList *ptr, int totalsize, TIDBitmap *tbm); + +extern ItemPointer ginPostingListDecodeAllSegments(GinPostingList *ptr, int len, int *ndecoded); +extern ItemPointer ginPostingListDecode(GinPostingList *ptr, int *ndecoded); +extern ItemPointer ginMergeItemPointers(ItemPointerData *a, uint32 na, ItemPointerData *b, uint32 nb, int *nmerged); +extern void GinRedoRecompress(Page page, ginxlogRecompressDataLeaf* data); +/* + * Merging the results of several gin scans compares item pointers a lot, + * so we want this to be inlined. But if the compiler doesn't support that, + * fall back on the non-inline version from itemptr.c. See STATIC_IF_INLINE in + * c.h. + */ +static inline int ginCompareItemPointers(ItemPointer a, ItemPointer b) +{ + uint64 ia = ((uint64)a->ip_blkid.bi_hi << 32) | ((uint64)a->ip_blkid.bi_lo << 16) | a->ip_posid; + uint64 ib = ((uint64)b->ip_blkid.bi_hi << 32) | ((uint64)b->ip_blkid.bi_lo << 16) | b->ip_posid; + + if (ia == ib) + return 0; + else if (ia > ib) + return 1; + else + return -1; +} + +#endif /* GIN_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gist.h postgresql-hll-2.14/include/include/access/gist.h --- postgresql-hll-2.14_old/include/include/access/gist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gist.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,179 @@ +/* ------------------------------------------------------------------------- + * + * gist.h + * The public API for GiST indexes. This API is exposed to + * individuals implementing GiST indexes, so backward-incompatible + * changes should be made with care. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GIST_H +#define GIST_H + +#include "access/xlog.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/bufpage.h" +#include "utils/relcache.h" + +/* + * amproc indexes for GiST indexes. + */ +#define GIST_CONSISTENT_PROC 1 +#define GIST_UNION_PROC 2 +#define GIST_COMPRESS_PROC 3 +#define GIST_DECOMPRESS_PROC 4 +#define GIST_PENALTY_PROC 5 +#define GIST_PICKSPLIT_PROC 6 +#define GIST_EQUAL_PROC 7 +#define GIST_DISTANCE_PROC 8 +#define GISTNProcs 8 + +/* + * strategy numbers for GiST opclasses that want to implement the old + * RTREE behavior. + */ +#define RTLeftStrategyNumber 1 +#define RTOverLeftStrategyNumber 2 +#define RTOverlapStrategyNumber 3 +#define RTOverRightStrategyNumber 4 +#define RTRightStrategyNumber 5 +#define RTSameStrategyNumber 6 +#define RTContainsStrategyNumber 7 /* for @> */ +#define RTContainedByStrategyNumber 8 /* for <@ */ +#define RTOverBelowStrategyNumber 9 +#define RTBelowStrategyNumber 10 +#define RTAboveStrategyNumber 11 +#define RTOverAboveStrategyNumber 12 +#define RTOldContainsStrategyNumber 13 /* for old spelling of @> */ +#define RTOldContainedByStrategyNumber 14 /* for old spelling of <@ */ +#define RTKNNSearchStrategyNumber 15 + +/* + * Page opaque data in a GiST index page. + */ +#define F_LEAF (1 << 0) /* leaf page */ +#define F_DELETED (1 << 1) /* the page has been deleted */ +#define F_TUPLES_DELETED (1 << 2) /* some tuples on the page are dead */ +#define F_FOLLOW_RIGHT (1 << 3) /* page to the right has no downlink */ + +typedef XLogRecPtr GistNSN; + +typedef struct GISTPageOpaqueData { + GistNSN nsn; /* this value must change on page split */ + BlockNumber rightlink; /* next page if any */ + uint16 flags; /* see bit definitions above */ + uint16 gist_page_id; /* for identification of GiST indexes */ +} GISTPageOpaqueData; + +typedef GISTPageOpaqueData *GISTPageOpaque; + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define GIST_PAGE_ID 0xFF81 + +/* + * This is the Split Vector to be returned by the PickSplit method. + * PickSplit should fill the indexes of tuples to go to the left side into + * spl_left[], and those to go to the right into spl_right[] (note the method + * is responsible for palloc'ing both of these arrays!). The tuple counts + * go into spl_nleft/spl_nright, and spl_ldatum/spl_rdatum must be set to + * the union keys for each side. + * + * If spl_ldatum_exists and spl_rdatum_exists are true, then we are performing + * a "secondary split" using a non-first index column. In this case some + * decisions have already been made about a page split, and the set of tuples + * being passed to PickSplit is just the tuples about which we are undecided. + * spl_ldatum/spl_rdatum then contain the union keys for the tuples already + * chosen to go left or right. Ideally the PickSplit method should take those + * keys into account while deciding what to do with the remaining tuples, ie + * it should try to "build out" from those unions so as to minimally expand + * them. If it does so, it should union the given tuples' keys into the + * existing spl_ldatum/spl_rdatum values rather than just setting those values + * from scratch, and then set spl_ldatum_exists/spl_rdatum_exists to false to + * show it has done this. + * + * If the PickSplit method fails to clear spl_ldatum_exists/spl_rdatum_exists, + * the core GiST code will make its own decision about how to merge the + * secondary-split results with the previously-chosen tuples, and will then + * recompute the union keys from scratch. This is a workable though often not + * optimal approach. + */ +typedef struct GIST_SPLITVEC { + OffsetNumber *spl_left; /* array of entries that go left */ + int spl_nleft; /* size of this array */ + Datum spl_ldatum; /* Union of keys in spl_left */ + bool spl_ldatum_exists; /* true, if spl_ldatum already exists. */ + + OffsetNumber *spl_right; /* array of entries that go right */ + int spl_nright; /* size of the array */ + Datum spl_rdatum; /* Union of keys in spl_right */ + bool spl_rdatum_exists; /* true, if spl_rdatum already exists. */ +} GIST_SPLITVEC; + +/* + * An entry on a GiST node. Contains the key, as well as its own + * location (rel,page,offset) which can supply the matching pointer. + * leafkey is a flag to tell us if the entry is in a leaf node. + */ +typedef struct GISTENTRY { + Datum key; + Relation rel; + Page page; + OffsetNumber offset; + bool leafkey; +} GISTENTRY; + +#define GistPageGetOpaque(page) ((GISTPageOpaque)PageGetSpecialPointer(page)) + +#define GistPageIsLeaf(page) (GistPageGetOpaque(page)->flags & F_LEAF) +#define GIST_LEAF(entry) (GistPageIsLeaf((entry)->page)) +#define GistPageSetLeaf(page) (GistPageGetOpaque(page)->flags |= F_LEAF) +#define GistPageSetNonLeaf(page) (GistPageGetOpaque(page)->flags &= ~F_LEAF) + +#define GistPageIsDeleted(page) (GistPageGetOpaque(page)->flags & F_DELETED) +#define GistPageSetDeleted(page) (GistPageGetOpaque(page)->flags |= F_DELETED) +#define GistPageSetNonDeleted(page) (GistPageGetOpaque(page)->flags &= ~F_DELETED) + +#define GistTuplesDeleted(page) (GistPageGetOpaque(page)->flags & F_TUPLES_DELETED) +#define GistMarkTuplesDeleted(page) (GistPageGetOpaque(page)->flags |= F_TUPLES_DELETED) +#define GistClearTuplesDeleted(page) (GistPageGetOpaque(page)->flags &= ~F_TUPLES_DELETED) + +#define GistFollowRight(page) (GistPageGetOpaque(page)->flags & F_FOLLOW_RIGHT) +#define GistMarkFollowRight(page) (GistPageGetOpaque(page)->flags |= F_FOLLOW_RIGHT) +#define GistClearFollowRight(page) (GistPageGetOpaque(page)->flags &= ~F_FOLLOW_RIGHT) + +/* + * Vector of GISTENTRY structs; user-defined methods union and picksplit + * take it as one of their arguments + */ +typedef struct { + int32 n; /* number of elements */ + GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]; +} GistEntryVector; + +#define GEVHDRSZ (offsetof(GistEntryVector, vector)) + +/* + * macro to initialize a GISTENTRY + */ +#define gistentryinit(e, k, r, pg, o, l) do { \ + (e).key = (k); \ + (e).rel = (r); \ + (e).page = (pg); \ + (e).offset = (o); \ + (e).leafkey = (l); \ +} while (0) + +#endif /* GIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gist_private.h postgresql-hll-2.14/include/include/access/gist_private.h --- postgresql-hll-2.14_old/include/include/access/gist_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gist_private.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,500 @@ +/* ------------------------------------------------------------------------- + * + * gist_private.h + * private declarations for GiST -- declarations related to the + * internal implementation of GiST, not the public API + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gist_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GIST_PRIVATE_H +#define GIST_PRIVATE_H + +#include "access/gist.h" +#include "access/itup.h" +#include "access/xlogreader.h" +#include "fmgr.h" +#include "storage/bufmgr.h" +#include "storage/buffile.h" +#include "utils/rbtree.h" +#include "utils/hsearch.h" + +/* + * Maximum number of "halves" a page can be split into in one operation. + * Typically a split produces 2 halves, but can be more if keys have very + * different lengths, or when inserting multiple keys in one operation (as + * when inserting downlinks to an internal node). There is no theoretical + * limit on this, but in practice if you get more than a handful page halves + * in one split, there's something wrong with the opclass implementation. + * GIST_MAX_SPLIT_PAGES is an arbitrary limit on that, used to size some + * local arrays used during split. Note that there is also a limit on the + * number of buffers that can be held locked at a time, MAX_SIMUL_LWLOCKS, + * so if you raise this higher than that limit, you'll just get a different + * error. + */ +#define GIST_MAX_SPLIT_PAGES 75 + +/* Buffer lock modes */ +#define GIST_SHARE BUFFER_LOCK_SHARE +#define GIST_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE +#define GIST_UNLOCK BUFFER_LOCK_UNLOCK + +typedef struct { + BlockNumber prev; + uint32 freespace; + char tupledata[1]; +} GISTNodeBufferPage; + +#define BUFFER_PAGE_DATA_OFFSET MAXALIGN(offsetof(GISTNodeBufferPage, tupledata)) +/* Returns free space in node buffer page */ +#define PAGE_FREE_SPACE(nbp) (nbp->freespace) +/* Checks if node buffer page is empty */ +#define PAGE_IS_EMPTY(nbp) (nbp->freespace == BLCKSZ - BUFFER_PAGE_DATA_OFFSET) +/* Checks if node buffers page don't contain sufficient space for index tuple */ +#define PAGE_NO_SPACE(nbp, itup) (PAGE_FREE_SPACE(nbp) < MAXALIGN(IndexTupleSize(itup))) + +/* + * GISTSTATE: information needed for any GiST index operation + * + * This struct retains call info for the index's opclass-specific support + * functions (per index column), plus the index's tuple descriptor. + * + * scanCxt holds the GISTSTATE itself as well as any data that lives for the + * lifetime of the index operation. We pass this to the support functions + * via fn_mcxt, so that they can store scan-lifespan data in it. The + * functions are invoked in tempCxt, which is typically short-lifespan + * (that is, it's reset after each tuple). However, tempCxt can be the same + * as scanCxt if we're not bothering with per-tuple context resets. + */ +typedef struct GISTSTATE { + MemoryContext scanCxt; /* context for scan-lifespan data */ + MemoryContext tempCxt; /* short-term context for calling functions */ + + TupleDesc tupdesc; /* index's tuple descriptor */ + + FmgrInfo consistentFn[INDEX_MAX_KEYS]; + FmgrInfo unionFn[INDEX_MAX_KEYS]; + FmgrInfo compressFn[INDEX_MAX_KEYS]; + FmgrInfo decompressFn[INDEX_MAX_KEYS]; + FmgrInfo penaltyFn[INDEX_MAX_KEYS]; + FmgrInfo picksplitFn[INDEX_MAX_KEYS]; + FmgrInfo equalFn[INDEX_MAX_KEYS]; + FmgrInfo distanceFn[INDEX_MAX_KEYS]; + + /* Collations to pass to the support functions */ + Oid supportCollation[INDEX_MAX_KEYS]; +} GISTSTATE; + +/* + * During a GiST index search, we must maintain a queue of unvisited items, + * which can be either individual heap tuples or whole index pages. If it + * is an ordered search, the unvisited items should be visited in distance + * order. Unvisited items at the same distance should be visited in + * depth-first order, that is heap items first, then lower index pages, then + * upper index pages; this rule avoids doing extra work during a search that + * ends early due to LIMIT. + * + * To perform an ordered search, we use an RBTree to manage the distance-order + * queue. Each GISTSearchTreeItem stores all unvisited items of the same + * distance; they are GISTSearchItems chained together via their next fields. + * + * In a non-ordered search (no order-by operators), the RBTree degenerates + * to a single item, which we use as a queue of unvisited index pages only. + * In this case matched heap items from the current index leaf page are + * remembered in GISTScanOpaqueData.pageData[] and returned directly from + * there, instead of building a separate GISTSearchItem for each one. + */ + +/* Individual heap tuple to be visited */ +typedef struct GISTSearchHeapItem { + ItemPointerData heapPtr; + bool recheck; /* T if quals must be rechecked */ +} GISTSearchHeapItem; + +/* Unvisited item, either index page or heap tuple */ +typedef struct GISTSearchItem { + struct GISTSearchItem *next; /* list link */ + BlockNumber blkno; /* index page number, or InvalidBlockNumber */ + union { + GistNSN parentlsn; /* parent page's LSN, if index page */ + /* we must store parentlsn to detect whether a split occurred */ + GISTSearchHeapItem heap; /* heap info, if heap tuple */ + } data; +} GISTSearchItem; + +#define GISTSearchItemIsHeap(item) ((item).blkno == InvalidBlockNumber) + +/* + * Within a GISTSearchTreeItem's chain, heap items always appear before + * index-page items, since we want to visit heap items first. lastHeap points + * to the last heap item in the chain, or is NULL if there are none. + */ +typedef struct GISTSearchTreeItem { + RBNode rbnode; /* this is an RBTree item */ + GISTSearchItem *head; /* first chain member */ + GISTSearchItem *lastHeap; /* last heap-tuple member, if any */ + double distances[FLEXIBLE_ARRAY_MEMBER]; /* array with numberOfOrderBys entries */ +} GISTSearchTreeItem; + +#define GSTIHDRSZ offsetof(GISTSearchTreeItem, distances) + +/* + * GISTScanOpaqueData: private state for a scan of a GiST index + */ +typedef struct GISTScanOpaqueData { + GISTSTATE *giststate; /* index information, see above */ + RBTree *queue; /* queue of unvisited items */ + MemoryContext queueCxt; /* context holding the queue */ + bool qual_ok; /* false if qual can never be satisfied */ + bool firstCall; /* true until first gistgettuple call */ + + GISTSearchTreeItem *curTreeItem; /* current queue item, if any */ + + /* pre-allocated workspace arrays */ + GISTSearchTreeItem *tmpTreeItem; /* workspace to pass to rb_insert */ + double *distances; /* output area for gistindex_keytest */ + + /* In a non-ordered search, returnable heap items are stored here: */ + GISTSearchHeapItem pageData[BLCKSZ / sizeof(IndexTupleData)]; + OffsetNumber nPageData; /* number of valid items in array */ + OffsetNumber curPageData; /* next item to return */ +} GISTScanOpaqueData; + +typedef GISTScanOpaqueData *GISTScanOpaque; + +/* XLog stuff */ +#define XLOG_GIST_PAGE_UPDATE 0x00 +#define XLOG_GIST_PAGE_SPLIT 0x30 +#define XLOG_GIST_CREATE_INDEX 0x50 +#define XLOG_GIST_PAGE_DELETE 0x60 + +/* + * Backup Blk 0: updated page. + * Backup Blk 1: If this operation completes a page split, by inserting a + * downlink for the split page, the left half of the split + */ +typedef struct gistxlogPageUpdate { + /* number of deleted offsets */ + uint16 ntodelete; + uint16 ntoinsert; + + /* + * In payload of blk 0 : 1. todelete OffsetNumbers 2. tuples to insert + */ +} gistxlogPageUpdate; + +/* + * Backup Blk 0: If this operation completes a page split, by inserting a + * downlink for the split page, the left half of the split + * Backup Blk 1 - npage: split pages (1 is the original page) + */ +typedef struct gistxlogPageSplit { + BlockNumber origrlink; /* rightlink of the page before split */ + GistNSN orignsn; /* NSN of the page before split */ + bool origleaf; /* was splitted page a leaf page? */ + + uint16 npage; /* # of pages in the split */ + bool markfollowright; /* set F_FOLLOW_RIGHT flags */ + + /* + * follow: 1. gistxlogPage and array of IndexTupleData per page + */ +} gistxlogPageSplit; + +typedef struct gistxlogPage { + BlockNumber blkno; + int num; /* number of index tuples following */ +} gistxlogPage; + +typedef struct gistxlogPageDelete { + RelFileNode node; + BlockNumber blkno; +} gistxlogPageDelete; + +/* SplitedPageLayout - gistSplit function result */ +typedef struct SplitedPageLayout { + gistxlogPage block; + IndexTupleData *list; + int lenlist; + IndexTuple itup; /* union key for page */ + Page page; /* to operate */ + Buffer buffer; /* to write after all proceed */ + + struct SplitedPageLayout *next; +} SplitedPageLayout; + +/* + * GISTInsertStack used for locking buffers and transfer arguments during + * insertion + */ +typedef struct GISTInsertStack { + /* current page */ + BlockNumber blkno; + Buffer buffer; + Page page; + + /* + * log sequence number from page->lsn to recognize page update and compare + * it with page's nsn to recognize page split + */ + GistNSN lsn; + + /* offset of the downlink in the parent page, that points to this page */ + OffsetNumber downlinkoffnum; + + /* pointer to parent */ + struct GISTInsertStack *parent; +} GISTInsertStack; + +/* Working state and results for multi-column split logic in gistsplit.c */ +typedef struct GistSplitVector { + GIST_SPLITVEC splitVector; /* passed to/from user PickSplit method */ + + Datum spl_lattr[INDEX_MAX_KEYS]; /* Union of subkeys in + * splitVector.spl_left */ + bool spl_lisnull[INDEX_MAX_KEYS]; + + Datum spl_rattr[INDEX_MAX_KEYS]; /* Union of subkeys in + * splitVector.spl_right */ + bool spl_risnull[INDEX_MAX_KEYS]; + + bool *spl_dontcare; /* flags tuples which could go to either side + * of the split for zero penalty */ +} GistSplitVector; + +typedef struct { + Relation r; + Size freespace; /* free space to be left */ + + GISTInsertStack *stack; +} GISTInsertState; + +/* root page of a gist index */ +#define GIST_ROOT_BLKNO 0 + +/* + * Before PostgreSQL 9.1, we used rely on so-called "invalid tuples" on inner + * pages to finish crash recovery of incomplete page splits. If a crash + * happened in the middle of a page split, so that the downlink pointers were + * not yet inserted, crash recovery inserted a special downlink pointer. The + * semantics of an invalid tuple was that it if you encounter one in a scan, + * it must always be followed, because we don't know if the tuples on the + * child page match or not. + * + * We no longer create such invalid tuples, we now mark the left-half of such + * an incomplete split with the F_FOLLOW_RIGHT flag instead, and finish the + * split properly the next time we need to insert on that page. To retain + * on-disk compatibility for the sake of pg_upgrade, we still store 0xffff as + * the offset number of all inner tuples. If we encounter any invalid tuples + * with 0xfffe during insertion, we throw an error, though scans still handle + * them. You should only encounter invalid tuples if you pg_upgrade a pre-9.1 + * gist index which already has invalid tuples in it because of a crash. That + * should be rare, and you are recommended to REINDEX anyway if you have any + * invalid tuples in an index, so throwing an error is as far as we go with + * supporting that. + */ +#define TUPLE_IS_VALID 0xffff +#define TUPLE_IS_INVALID 0xfffe + +#define GistTupleIsInvalid(itup) (ItemPointerGetOffsetNumber(&((itup)->t_tid)) == TUPLE_IS_INVALID) +#define GistTupleSetValid(itup) ItemPointerSetOffsetNumber(&((itup)->t_tid), TUPLE_IS_VALID) + +/* + * A buffer attached to an internal node, used when building an index in + * buffering mode. + */ +typedef struct { + BlockNumber nodeBlocknum; /* index block # this buffer is for */ + int32 blocksCount; /* current # of blocks occupied by buffer */ + + BlockNumber pageBlocknum; /* temporary file block # */ + GISTNodeBufferPage *pageBuffer; /* in-memory buffer page */ + + /* is this buffer queued for emptying? */ + bool queuedForEmptying; + + /* is this a temporary copy, not in the hash table? */ + bool isTemp; + + int level; /* 0 == leaf */ +} GISTNodeBuffer; + +/* + * Does specified level have buffers? (Beware of multiple evaluation of + * arguments.) + */ +#define LEVEL_HAS_BUFFERS(nlevel, gfbb) \ + ((nlevel) != 0 && (nlevel) % (gfbb)->levelStep == 0 && (nlevel) != (gfbb)->rootlevel) + +/* Is specified buffer at least half-filled (should be queued for emptying)? */ +#define BUFFER_HALF_FILLED(nodeBuffer, gfbb) ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer / 2) + +/* + * Is specified buffer full? Our buffers can actually grow indefinitely, + * beyond the "maximum" size, so this just means whether the buffer has grown + * beyond the nominal maximum size. + */ +#define BUFFER_OVERFLOWED(nodeBuffer, gfbb) ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer) + +/* + * Data structure with general information about build buffers. + */ +typedef struct GISTBuildBuffers { + /* Persistent memory context for the buffers and metadata. */ + MemoryContext context; + + BufFile *pfile; /* Temporary file to store buffers in */ + long nFileBlocks; /* Current size of the temporary file */ + + /* + * resizable array of free blocks. + */ + long *freeBlocks; + int nFreeBlocks; /* # of currently free blocks in the array */ + int freeBlocksLen; /* current allocated length of the array */ + + /* Hash for buffers by block number */ + HTAB *nodeBuffersTab; + + /* List of buffers scheduled for emptying */ + List *bufferEmptyingQueue; + + /* + * Parameters to the buffering build algorithm. levelStep determines which + * levels in the tree have buffers, and pagesPerBuffer determines how + * large each buffer is. + */ + int levelStep; + int pagesPerBuffer; + + /* Array of lists of buffers on each level, for final emptying */ + List **buffersOnLevels; + int buffersOnLevelsLen; + + /* + * Dynamically-sized array of buffers that currently have their last page + * loaded in main memory. + */ + GISTNodeBuffer **loadedBuffers; + int loadedBuffersCount; /* # of entries in loadedBuffers */ + int loadedBuffersLen; /* allocated size of loadedBuffers */ + + /* Level of the current root node (= height of the index tree - 1) */ + int rootlevel; +} GISTBuildBuffers; + +/* + * Storage type for GiST's reloptions + */ +typedef struct GiSTOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int fillfactor; /* page fill factor in percent (0..100) */ + int bufferingModeOffset; /* use buffering build? */ +} GiSTOptions; + +/* gist.c */ +extern Datum gistbuildempty(PG_FUNCTION_ARGS); +extern Datum gistinsert(PG_FUNCTION_ARGS); +extern MemoryContext createTempGistContext(void); +extern GISTSTATE *initGISTstate(Relation index); +extern void freeGISTstate(GISTSTATE *giststate); +extern void gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *GISTstate); + +/* A List of these is returned from gistplacetopage() in *splitinfo */ +typedef struct { + Buffer buf; /* the split page "half" */ + IndexTuple downlink; /* downlink for this half. */ +} GISTPageSplitInfo; + +extern bool gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, Buffer buffer, IndexTuple *itup, + int ntup, OffsetNumber oldoffnum, BlockNumber *newblkno, Buffer leftchildbuf, + List **splitinfo, bool markleftchild); + +extern SplitedPageLayout *gistSplit(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate); + +/* gistxlog.c */ +extern void gist_redo(XLogReaderState *record); +extern void gist_desc(StringInfo buf, XLogReaderState *record); +extern void gist_xlog_startup(void); +extern void gist_xlog_cleanup(void); + +extern XLogRecPtr gistXLogUpdate(Buffer buffer, OffsetNumber *todelete, int ntodelete, IndexTuple *itup, int ntup, + Buffer leftchild); + +extern XLogRecPtr gistXLogSplit(bool page_is_leaf, SplitedPageLayout *dist, BlockNumber origrlink, GistNSN oldnsn, + Buffer leftchild, bool markfollowright); + +/* gistget.c */ +extern Datum gistgettuple(PG_FUNCTION_ARGS); +extern Datum gistgetbitmap(PG_FUNCTION_ARGS); + +/* gistutil.c */ +#define GiSTPageSize (BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GISTPageOpaqueData))) + +#define GIST_MIN_FILLFACTOR 10 +#define GIST_DEFAULT_FILLFACTOR 90 + +extern Datum gistoptions(PG_FUNCTION_ARGS); +extern bool gistfitpage(IndexTuple *itvec, int len); +extern bool gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace); +extern void gistcheckpage(Relation rel, Buffer buf); +extern Buffer gistNewBuffer(Relation r); +extern void gistfillbuffer(Page page, IndexTuple *itup, int len, OffsetNumber off); +extern IndexTuple *gistextractpage(Page page, int *len /* out */); +extern IndexTuple *gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen); +extern IndexTupleData *gistfillitupvec(IndexTuple *vec, int veclen, int *memlen); + +extern IndexTuple gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate); +extern IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate); +extern IndexTuple gistFormTuple(GISTSTATE *giststate, Relation r, Datum *attdata, const bool *isnull, bool newValues); + +extern OffsetNumber gistchoose(Relation r, Page p, IndexTuple it, GISTSTATE *giststate); +extern void gistcentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, + bool l, bool isNull); + +extern void GISTInitBuffer(Buffer b, uint32 f); +extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, Datum k, Relation r, Page pg, OffsetNumber o, + bool l, bool isNull); + +extern float gistpenalty(GISTSTATE *giststate, int attno, GISTENTRY *key1, bool isNull1, GISTENTRY *key2, bool isNull2); +extern void gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, Datum *attr, bool *isnull); +extern bool gistKeyIsEQ(GISTSTATE *giststate, int attno, Datum a, Datum b); +extern void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, OffsetNumber o, + GISTENTRY *attdata, bool *isnull); + +extern void gistMakeUnionKey(GISTSTATE *giststate, int attno, GISTENTRY *entry1, bool isnull1, GISTENTRY *entry2, + bool isnull2, Datum *dst, bool *dstisnull); + +extern XLogRecPtr GetXLogRecPtrForTemp(void); + +/* gistvacuum.c */ +extern Datum gistbulkdelete(PG_FUNCTION_ARGS); +extern Datum gistvacuumcleanup(PG_FUNCTION_ARGS); + +/* gistsplit.c */ +extern void gistSplitByKey(Relation r, Page page, IndexTuple *itup, int len, GISTSTATE *giststate, GistSplitVector *v, + int attno); + +/* gistbuild.c */ +extern Datum gistmerge(PG_FUNCTION_ARGS); +extern Datum gistbuild(PG_FUNCTION_ARGS); +extern void gistValidateBufferingOption(const char *value); + +/* gistbuildbuffers.c */ +extern GISTBuildBuffers *gistInitBuildBuffers(int pagesPerBuffer, int levelStep, int maxLevel); +extern GISTNodeBuffer *gistGetNodeBuffer(GISTBuildBuffers *gfbb, GISTSTATE *giststate, BlockNumber blkno, int level); +extern void gistPushItupToNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple item); +extern bool gistPopItupFromNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple *item); +extern void gistFreeBuildBuffers(GISTBuildBuffers *gfbb); +extern void gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate, Relation r, int level, + Buffer buffer, List *splitinfo); +extern void gistUnloadNodeBuffers(GISTBuildBuffers *gfbb); +extern bool IsGistPageUpdate(XLogReaderState *record); +extern void GISTInitPage(Page page, uint32 f, Size pageSize); +extern IndexTuple *decodePageSplitRecord(char *begin, int len, int *n); + +#endif /* GIST_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gistscan.h postgresql-hll-2.14/include/include/access/gistscan.h --- postgresql-hll-2.14_old/include/include/access/gistscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gistscan.h 2020-12-12 17:06:43.136346606 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * gistscan.h + * routines defined in access/gist/gistscan.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/gistscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GISTSCAN_H +#define GISTSCAN_H + +#include "fmgr.h" + +extern Datum gistbeginscan(PG_FUNCTION_ARGS); +extern Datum gistrescan(PG_FUNCTION_ARGS); +extern Datum gistmarkpos(PG_FUNCTION_ARGS); +extern Datum gistrestrpos(PG_FUNCTION_ARGS); +extern Datum gistendscan(PG_FUNCTION_ARGS); + +#endif /* GISTSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/gtm.h postgresql-hll-2.14/include/include/access/gtm.h --- postgresql-hll-2.14_old/include/include/access/gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/gtm.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * 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. + * ------------------------------------------------------------------------- + * + * gtm.h + * Module interfacing with GTM definitions + * + * IDENTIFICATION + * src/include/access/gtm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ACCESS_GTM_H +#define ACCESS_GTM_H + +#include "gtm/gtm_c.h" +#include "workload/workload.h" +#include "commands/sequence.h" + +extern bool IsGTMConnected(void); +extern GtmHostIndex InitGTM(void); +extern void CloseGTM(void); +extern void ResetGtmHandleXmin(GTM_TransactionKey txnKey); +extern int SetGTMVacuumFlag(GTM_TransactionKey txnKey, bool is_vacuum); + +extern GTM_TransactionKey BeginTranGTM(GTM_Timestamp *timestamp); +extern GlobalTransactionId GetGxidGTM(GTM_TransactionKey txnKey, bool is_sub_xact); +extern CommitSeqNo GetCSNGTM(); +extern CommitSeqNo CommitCSNGTM(bool need_clean); +extern TransactionId GetGTMGlobalXmin(); +extern GlobalTransactionId BeginTranAutovacuumGTM(void); +extern int CommitTranGTM(GlobalTransactionId gxid, TransactionId *childXids, int nChildXids); +extern int CommitTranHandleGTM(GTM_TransactionKey txnKey, GlobalTransactionId transactionId, + GlobalTransactionId &outgxid); +extern int RollbackTranGTM(GlobalTransactionId gxid, GlobalTransactionId *childXids, int nChildXids); +extern int RollbackTranHandleGTM(GTM_TransactionKey txnKey, GlobalTransactionId &outgxid); +extern int StartPreparedTranGTM(GlobalTransactionId gxid, const char *gid, const char *nodestring); +extern int PrepareTranGTM(GlobalTransactionId gxid); +extern int GetGIDDataGTM(const char *gid, GlobalTransactionId *gxid, GlobalTransactionId *prepared_gxid, + char **nodestring); +extern int CommitPreparedTranGTM(GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); + +extern GTM_Snapshot GetSnapshotGTM(GTM_TransactionKey txnKey, GlobalTransactionId gxid, bool canbe_grouped, + bool is_vacuum); +extern GTM_Snapshot GetSnapshotGTMLite(void); +extern GTM_SnapshotStatus GetGTMSnapshotStatus(GTM_TransactionKey txnKey); +extern GTMLite_Status GetGTMLiteStatus(void); + +/* Sequence interface APIs with GTM */ +extern GTM_UUID GetSeqUUIDGTM(); +extern int CreateSequenceWithUUIDGTM(FormData_pg_sequence seq, GTM_UUID uuid); +extern GTM_Sequence GetNextValGTM(Form_pg_sequence seq, GTM_Sequence range, GTM_Sequence *rangemax, GTM_UUID uuid); +extern int SetValGTM(GTM_UUID seq_uuid, GTM_Sequence nextval, bool iscalled); + +extern int AlterSequenceGTM(GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +extern int DropSequenceGTM(GTM_UUID seq_uuid, const char *dbname = NULL); +extern int RenameSequenceGTM(char *seqname, char *newseqname, GTM_SequenceKeyType keytype = GTM_SEQ_FULL_NAME); +/* Barrier */ +extern int ReportBarrierGTM(const char *barrier_id); +/* Set gtm rw timeout */ +extern void SetGTMrwTimeout(int timeout); +/* Initiate GTM connection and report connected GTM host timeline to MyBEEntry */ +extern void InitGTM_Reporttimeline(void); +extern void SetGTMInterruptFlag(); +extern bool PingGTM(struct gtm_conn* conn); + +#endif /* ACCESS_GTM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/hash.h postgresql-hll-2.14/include/include/access/hash.h --- postgresql-hll-2.14_old/include/include/access/hash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/hash.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,370 @@ +/* ------------------------------------------------------------------------- + * + * hash.h + * header file for postgres hash access method implementation + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hash.h + * + * NOTES + * modeled after Margo Seltzer's hash implementation for unix. + * + * ------------------------------------------------------------------------- + */ +#ifndef HASH_H +#define HASH_H + +#include "access/genam.h" +#include "access/itup.h" +#include "access/sdir.h" +#include "access/xlogreader.h" +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "storage/bufmgr.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +/* + * Mapping from hash bucket number to physical block number of bucket's + * starting page. Beware of multiple evaluations of argument! + */ +typedef uint32 Bucket; + +#define INVALID_BUCKET_NUM (0xFFFFFFFF) +#define BUCKET_TO_BLKNO(metap, B) ((BlockNumber)((B) + ((B) ? (metap)->hashm_spares[_hash_log2((B) + 1) - 1] : 0)) + 1) + +/* + * Special space for hash index pages. + * + * hasho_flag tells us which type of page we're looking at. For + * example, knowing overflow pages from bucket pages is necessary + * information when you're deleting tuples from a page. If all the + * tuples are deleted from an overflow page, the overflow is made + * available to other buckets by calling _hash_freeovflpage(). If all + * the tuples are deleted from a bucket page, no additional action is + * necessary. + */ +#define LH_UNUSED_PAGE (0) +#define LH_OVERFLOW_PAGE (1 << 0) +#define LH_BUCKET_PAGE (1 << 1) +#define LH_BITMAP_PAGE (1 << 2) +#define LH_META_PAGE (1 << 3) + +typedef struct HashPageOpaqueData { + BlockNumber hasho_prevblkno; /* previous ovfl (or bucket) blkno */ + BlockNumber hasho_nextblkno; /* next ovfl blkno */ + Bucket hasho_bucket; /* bucket number this pg belongs to */ + uint16 hasho_flag; /* page type code, see above */ + uint16 hasho_page_id; /* for identification of hash indexes */ +} HashPageOpaqueData; + +typedef HashPageOpaqueData* HashPageOpaque; + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define HASHO_PAGE_ID 0xFF80 + +/* + * HashScanOpaqueData is private state for a hash index scan. + */ +typedef struct HashScanOpaqueData { + /* Hash value of the scan key, ie, the hash key we seek */ + uint32 hashso_sk_hash; + + /* + * By definition, a hash scan should be examining only one bucket. We + * record the bucket number here as soon as it is known. + */ + Bucket hashso_bucket; + bool hashso_bucket_valid; + + /* + * If we have a share lock on the bucket, we record it here. When + * hashso_bucket_blkno is zero, we have no such lock. + */ + BlockNumber hashso_bucket_blkno; + + /* + * We also want to remember which buffer we're currently examining in the + * scan. We keep the buffer pinned (but not locked) across hashgettuple + * calls, in order to avoid doing a ReadBuffer() for every tuple in the + * index. + */ + Buffer hashso_curbuf; + + /* Current position of the scan, as an index TID */ + ItemPointerData hashso_curpos; + + /* Current position of the scan, as a heap TID */ + ItemPointerData hashso_heappos; +} HashScanOpaqueData; + +typedef HashScanOpaqueData* HashScanOpaque; + +/* + * Definitions for metapage. + */ + +#define HASH_METAPAGE 0 /* metapage is always block 0 */ + +#define HASH_MAGIC 0x6440640 +#define HASH_VERSION 2 /* 2 signifies only hash key value is stored */ + +/* + * Spares[] holds the number of overflow pages currently allocated at or + * before a certain splitpoint. For example, if spares[3] = 7 then there are + * 7 ovflpages before splitpoint 3 (compare BUCKET_TO_BLKNO macro). The + * value in spares[ovflpoint] increases as overflow pages are added at the + * end of the index. Once ovflpoint increases (ie, we have actually allocated + * the bucket pages belonging to that splitpoint) the number of spares at the + * prior splitpoint cannot change anymore. + * + * ovflpages that have been recycled for reuse can be found by looking at + * bitmaps that are stored within ovflpages dedicated for the purpose. + * The blknos of these bitmap pages are kept in bitmaps[]; nmaps is the + * number of currently existing bitmaps. + * + * The limitation on the size of spares[] comes from the fact that there's + * no point in having more than 2^32 buckets with only uint32 hashcodes. + * There is no particular upper limit on the size of mapp[], other than + * needing to fit into the metapage. (With 8K block size, 128 bitmaps + * limit us to 64 Gb of overflow space...) + */ +#define HASH_MAX_SPLITPOINTS 32 +#define HASH_MAX_BITMAPS 128 + +typedef struct HashMetaPageData { + uint32 hashm_magic; /* magic no. for hash tables */ + uint32 hashm_version; /* version ID */ + double hashm_ntuples; /* number of tuples stored in the table */ + uint16 hashm_ffactor; /* target fill factor (tuples/bucket) */ + uint16 hashm_bsize; /* index page size (bytes) */ + uint16 hashm_bmsize; /* bitmap array size (bytes) - must be a power + * of 2 */ + uint16 hashm_bmshift; /* log2(bitmap array size in BITS) */ + uint32 hashm_maxbucket; /* ID of maximum bucket in use */ + uint32 hashm_highmask; /* mask to modulo into entire table */ + uint32 hashm_lowmask; /* mask to modulo into lower half of table */ + uint32 hashm_ovflpoint; /* splitpoint from which ovflpgs being + * allocated */ + uint32 hashm_firstfree; /* lowest-number free ovflpage (bit#) */ + uint32 hashm_nmaps; /* number of bitmap pages */ + RegProcedure hashm_procid; /* hash procedure id from pg_proc */ + uint32 hashm_spares[HASH_MAX_SPLITPOINTS]; /* spare pages before + * each splitpoint */ + BlockNumber hashm_mapp[HASH_MAX_BITMAPS]; /* blknos of ovfl bitmaps */ +} HashMetaPageData; + +typedef HashMetaPageData* HashMetaPage; + +/* + * Maximum size of a hash index item (it's okay to have only one per page) + */ +#define HashMaxItemSize(page) \ + MAXALIGN_DOWN( \ + PageGetPageSize(page) - SizeOfPageHeaderData - sizeof(ItemIdData) - MAXALIGN(sizeof(HashPageOpaqueData))) + +#define INDEX_MOVED_BY_SPLIT_MASK INDEX_AM_RESERVED_BIT + +#define HASH_MIN_FILLFACTOR 10 +#define HASH_DEFAULT_FILLFACTOR 75 + +/* + * Constants + */ +#define BYTE_TO_BIT 3 /* 2^3 bits/byte */ +#define ALL_SET ((uint32)~0) + +/* + * Bitmap pages do not contain tuples. They do contain the standard + * page headers and trailers; however, everything in between is a + * giant bit array. The number of bits that fit on a page obviously + * depends on the page size and the header/trailer overhead. We require + * the number of bits per page to be a power of 2. + */ +#define BMPGSZ_BYTE(metap) ((metap)->hashm_bmsize) +#define BMPGSZ_BIT(metap) ((metap)->hashm_bmsize << BYTE_TO_BIT) +#define BMPG_SHIFT(metap) ((metap)->hashm_bmshift) +#define BMPG_MASK(metap) (BMPGSZ_BIT(metap) - 1) + +#define HashPageGetBitmap(page) ((uint32*)PageGetContents(page)) + +#define HashGetMaxBitmapSize(page) \ + (PageGetPageSize((Page)page) - (MAXALIGN(SizeOfPageHeaderData) + MAXALIGN(sizeof(HashPageOpaqueData)))) + +#define HashPageGetMeta(page) ((HashMetaPage)PageGetContents(page)) + +/* + * The number of bits in an ovflpage bitmap word. + */ +#define BITS_PER_MAP 32 /* Number of bits in uint32 */ + +/* Given the address of the beginning of a bit map, clear/set the nth bit */ +#define CLRBIT(A, N) ((A)[(N) / BITS_PER_MAP] &= ~(1U << ((N) % BITS_PER_MAP))) +#define SETBIT(A, N) ((A)[(N) / BITS_PER_MAP] |= (1 << ((N) % BITS_PER_MAP))) +#define ISSET(A, N) ((A)[(N) / BITS_PER_MAP] & (1 << ((N) % BITS_PER_MAP))) + +/* + * page-level and high-level locking modes (see README) + */ +#define HASH_READ BUFFER_LOCK_SHARE +#define HASH_WRITE BUFFER_LOCK_EXCLUSIVE +#define HASH_NOLOCK (-1) + +#define HASH_SHARE ShareLock +#define HASH_EXCLUSIVE ExclusiveLock + +/* + * Strategy number. There's only one valid strategy for hashing: equality. + */ +#define HTEqualStrategyNumber 1 +#define HTMaxStrategyNumber 1 + +/* + * When a new operator class is declared, we require that the user supply + * us with an amproc procudure for hashing a key of the new type. + * Since we only have one such proc in amproc, it's number 1. + */ +#define HASHPROC 1 + +/* public routines */ +extern Datum hashmerge(PG_FUNCTION_ARGS); +extern Datum hashbuild(PG_FUNCTION_ARGS); +extern Datum hashbuildempty(PG_FUNCTION_ARGS); +extern Datum hashinsert(PG_FUNCTION_ARGS); +extern Datum hashbeginscan(PG_FUNCTION_ARGS); +extern Datum hashgettuple(PG_FUNCTION_ARGS); +extern Datum hashgetbitmap(PG_FUNCTION_ARGS); +extern Datum hashrescan(PG_FUNCTION_ARGS); +extern Datum hashendscan(PG_FUNCTION_ARGS); +extern Datum hashmarkpos(PG_FUNCTION_ARGS); +extern Datum hashrestrpos(PG_FUNCTION_ARGS); +extern Datum hashbulkdelete(PG_FUNCTION_ARGS); +extern Datum hashvacuumcleanup(PG_FUNCTION_ARGS); +extern Datum hashoptions(PG_FUNCTION_ARGS); + +/* + * Datatype-specific hash functions in hashfunc.c. + * + * These support both hash indexes and hash joins. + * + * NOTE: some of these are also used by catcache operations, without + * any direct connection to hash indexes. Also, the common hash_any + * routine is also used by dynahash tables. + */ +extern Datum hashchar(PG_FUNCTION_ARGS); +extern Datum hashint1(PG_FUNCTION_ARGS); +extern Datum hashint2(PG_FUNCTION_ARGS); +extern Datum hashint4(PG_FUNCTION_ARGS); +extern Datum hashint8(PG_FUNCTION_ARGS); +extern Datum hashoid(PG_FUNCTION_ARGS); +extern Datum hashenum(PG_FUNCTION_ARGS); +extern Datum hashfloat4(PG_FUNCTION_ARGS); +extern Datum hashfloat8(PG_FUNCTION_ARGS); +extern Datum hashoidvector(PG_FUNCTION_ARGS); +extern Datum hashint2vector(PG_FUNCTION_ARGS); +extern Datum hashname(PG_FUNCTION_ARGS); +extern Datum hashtext(PG_FUNCTION_ARGS); +extern Datum hashvarlena(PG_FUNCTION_ARGS); +extern Datum hash_any(register const unsigned char* k, register int keylen); +extern Datum hash_uint32(uint32 k); +extern Datum hash_new_uint32(uint32 k); + +/* private routines */ + +/* hashinsert.c */ +extern void _hash_doinsert(Relation rel, IndexTuple itup); +extern OffsetNumber _hash_pgaddtup(Relation rel, Buffer buf, Size itemsize, IndexTuple itup); + +/* hashovfl.c */ +extern Buffer _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf); +extern BlockNumber _hash_freeovflpage(Relation rel, Buffer ovflbuf, BufferAccessStrategy bstrategy); +extern void _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno, ForkNumber forkNum); +extern void _hash_squeezebucket(Relation rel, Bucket bucket, BlockNumber bucket_blkno, BufferAccessStrategy bstrategy); + +/* hashpage.c */ +extern void _hash_getlock(Relation rel, BlockNumber whichlock, int access); +extern bool _hash_try_getlock(Relation rel, BlockNumber whichlock, int access); +extern void _hash_droplock(Relation rel, BlockNumber whichlock, int access); +extern Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags); +extern Buffer _hash_getinitbuf(Relation rel, BlockNumber blkno); +extern Buffer _hash_getnewbuf(Relation rel, BlockNumber blkno, ForkNumber forkNum); +extern Buffer _hash_getbuf_with_strategy( + Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy); +extern void _hash_relbuf(Relation rel, Buffer buf); +extern void _hash_dropbuf(Relation rel, Buffer buf); +extern void _hash_wrtbuf(Relation rel, Buffer buf); +extern void _hash_chgbufaccess(Relation rel, Buffer buf, int from_access, int to_access); +extern uint32 _hash_metapinit(Relation rel, double num_tuples, ForkNumber forkNum); +extern void _hash_pageinit(Page page, Size size); +extern void _hash_expandtable(Relation rel, Buffer metabuf); + +/* hashscan.c */ +extern void _hash_regscan(IndexScanDesc scan); +extern void _hash_dropscan(IndexScanDesc scan); +extern bool _hash_has_active_scan(Relation rel, Bucket bucket); +extern void ReleaseResources_hash(void); + +/* hashsearch.c */ +extern bool _hash_next(IndexScanDesc scan, ScanDirection dir); +extern bool _hash_first(IndexScanDesc scan, ScanDirection dir); +extern bool _hash_step(IndexScanDesc scan, Buffer* bufP, ScanDirection dir); + +/* hashsort.c */ +typedef struct HSpool HSpool; /* opaque struct in hashsort.c */ + +extern HSpool* _h_spoolinit(Relation index, uint32 num_buckets, void* meminfo); +extern void _h_spooldestroy(HSpool* hspool); +extern void _h_spool(HSpool* hspool, ItemPointer self, Datum* values, const bool* isnull); +extern void _h_indexbuild(HSpool* hspool); + +/* hashutil.c */ +extern bool _hash_checkqual(IndexScanDesc scan, IndexTuple itup); +extern uint32 _hash_datum2hashkey(Relation rel, Datum key); +extern uint32 _hash_datum2hashkey_type(Relation rel, Datum key, Oid keytype); +extern Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket, uint32 highmask, uint32 lowmask); +extern uint32 _hash_log2(uint32 num); +extern void _hash_checkpage(Relation rel, Buffer buf, int flags); +extern uint32 _hash_get_indextuple_hashkey(IndexTuple itup); +extern IndexTuple _hash_form_tuple(Relation index, Datum* values, const bool* isnull); +extern OffsetNumber _hash_binsearch(Page page, uint32 hash_value); +extern OffsetNumber _hash_binsearch_last(Page page, uint32 hash_value); + +/* hash.c */ +extern void hash_redo(XLogReaderState* record); +extern void hash_desc(StringInfo buf, XLogReaderState* record); + +#ifdef PGXC +extern Datum compute_hash(Oid type, Datum value, char locator); +extern uint32 hashValueCombination(uint32 hashValue, Oid colType, Datum val, bool allIsNull, char locatorType = 'H'); +extern char* get_compute_hash_function(Oid type, char locator); +extern Datum getbucket(PG_FUNCTION_ARGS); +extern ScalarVector* vgetbucket(PG_FUNCTION_ARGS); +extern ScalarVector* vtable_data_skewness(PG_FUNCTION_ARGS); +// template function implementation +// +#include "hash.inl" +#endif + +typedef struct MultiHashKey +{ + uint32 keyNum; + Oid* keyTypes; + Datum* keyValues; + bool* isNulls; + char locatorType; /* see LOCATOR_TYPE_?, e.g., LOCATOR_TYPE_HASH, LOCATOR_TYPE_NONE */ +} MultiHashKey; + +/* compute the hash value of mulitily keys */ +extern uint32 hash_multikey(MultiHashKey* mkeys); + +#define GetBucketID(hashval) (compute_modulo(abs((int)hashval), BUCKETDATALEN)) + +#endif /* HASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/hash.inl postgresql-hll-2.14/include/include/access/hash.inl --- postgresql-hll-2.14_old/include/include/access/hash.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/hash.inl 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,158 @@ +/*------------------------------------------------------------------------- + * + * hash.inl + * header file for hash template implementation + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hash.inl + * + * + *------------------------------------------------------------------------- + */ + +#ifndef HASHTEMPLATE_INL +#define HASHTEMPLATE_INL + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/hash.h" + +#ifdef PGXC +#include "catalog/pg_type.h" +#include "utils/builtins.h" +#include "utils/timestamp.h" +#include "utils/date.h" +#include "utils/nabstime.h" +#endif + +template +Datum +computeHashT(Datum value) +{ + uint8 tmp8; + int16 tmp16; + int32 tmp32; + int64 tmp64; + Oid tmpoid; + char tmpch; + + switch (type) + { + case INT8OID: + /* This gives added advantage that + * a = 8446744073709551359 + * and a = 8446744073709551359::int8 both work*/ + tmp64 = DatumGetInt64(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint8, value); + return tmp64; + case INT1OID: + tmp8 = DatumGetUInt8(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint1, tmp8); + return tmp8; + case INT2OID: + tmp16 = DatumGetInt16(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint2, tmp16); + return tmp16; + case OIDOID: + tmpoid = DatumGetObjectId(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashoid, tmpoid); + return tmpoid; + case INT4OID: + tmp32 = DatumGetInt32(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case BOOLOID: + tmpch = DatumGetBool(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashchar, tmpch); + return tmpch; + + case CHAROID: + return DirectFunctionCall1(hashchar, value); + case NAMEOID: + return DirectFunctionCall1(hashname, value); + case INT2VECTOROID: + return DirectFunctionCall1(hashint2vector, value); + + case CLOBOID: + case NVARCHAR2OID: + case VARCHAROID: + case TEXTOID: + return DirectFunctionCall1(hashtext, value); + + case OIDVECTOROID: + return DirectFunctionCall1(hashoidvector, value); + case FLOAT4OID: + return DirectFunctionCall1(hashfloat4, value); + case FLOAT8OID: + return DirectFunctionCall1(hashfloat8, value); + + case ABSTIMEOID: + tmp32 = DatumGetAbsoluteTime(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case RELTIMEOID: + tmp32 = DatumGetRelativeTime(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case CASHOID: + return DirectFunctionCall1(hashint8, value); + + case BPCHAROID: + return DirectFunctionCall1(hashbpchar, value); + case BYTEAWITHOUTORDERWITHEQUALCOLOID: + case BYTEAWITHOUTORDERCOLOID: + case RAWOID: + case BYTEAOID: + return DirectFunctionCall1(hashvarlena, value); + + case DATEOID: + tmp32 = DatumGetDateADT(value); + if (locator == LOCATOR_TYPE_HASH) + return DirectFunctionCall1(hashint4, tmp32); + return tmp32; + case TIMEOID: + return DirectFunctionCall1(time_hash, value); + case TIMESTAMPOID: + return DirectFunctionCall1(timestamp_hash, value); + case TIMESTAMPTZOID: + return DirectFunctionCall1(timestamp_hash, value); + case INTERVALOID: + if (ifCol) + value = PointerGetDatum((char*)value + VARHDRSZ_SHORT); + return DirectFunctionCall1(interval_hash, value); + case TIMETZOID: + if (ifCol) + value = PointerGetDatum((char*)value + VARHDRSZ_SHORT); + return DirectFunctionCall1(timetz_hash, value); + case SMALLDATETIMEOID: + return DirectFunctionCall1(timestamp_hash, value); + + case NUMERICOID: + return DirectFunctionCall1(hash_numeric, value); + case UUIDOID: + return DirectFunctionCall1(uuid_hash, value); + default: + ereport(ERROR,(errcode(ERRCODE_INDETERMINATE_DATATYPE), + errmsg("Unhandled datatype for modulo or hash distribution\n"))); + } + /* Control should not come here. */ + ereport(ERROR,(errcode(ERRCODE_INDETERMINATE_DATATYPE), + errmsg("Unhandled datatype for modulo or hash distribution\n"))); + /* Keep compiler silent */ + return (Datum)0; +} + +#endif /* HASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/hbindex_am.h postgresql-hll-2.14/include/include/access/hbindex_am.h --- postgresql-hll-2.14_old/include/include/access/hbindex_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/hbindex_am.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hbindex_am.h + * hash bucket index access method definitions. + + * + * + * IDENTIFICATION + * src/include/access/hbindex_am.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef HBINDEX_AM_H +#define HBINDEX_AM_H + +#include "access/relscan.h" +#include "access/heapam.h" +#include "utils/relcache.h" +#include "optimizer/bucketinfo.h" +#include "utils/rel_gs.h" + + +static inline bool hbkt_idx_need_switch_bkt(IndexScanDesc scan, int targetSlot) +{ + if (RELATION_OWN_BUCKET(scan->indexRelation)) { + HBktIdxScanDesc hbScan = (HBktIdxScanDesc)scan; + return targetSlot < list_length(hbScan->hBktList) && targetSlot != hbScan->curr_slot; + } else { + return false; + } +} + +extern bool hbkt_idx_bitmapscan_switch_bucket(IndexScanDesc scan, int target_slot); + +extern bool hbkt_idx_bitmapscan_switch_bucket(IndexScanDesc scan, int targetSlot); +extern IndexScanDesc scan_handler_idx_beginscan(Relation heap_relation, Relation index_relation, Snapshot snapshot, int nkeys, int norderbys, ScanState* scan_state); +extern IndexScanDesc scan_handler_idx_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, int nkeys, ScanState* scan_state); +extern void scan_handler_idx_rescan(IndexScanDesc scan, ScanKey key, int nkeys, ScanKey orderbys, int norderbys); +extern void scan_handler_idx_rescan_local(IndexScanDesc scan, ScanKey key, int nkeys, ScanKey orderbys, int norderbys); +extern void scan_handler_idx_endscan(IndexScanDesc scan); +extern void scan_handler_idx_markpos(IndexScanDesc scan); +extern void scan_handler_idx_restrpos(IndexScanDesc scan); +extern HeapTuple scan_handler_idx_fetch_heap(IndexScanDesc scan); +extern HeapTuple scan_handler_idx_getnext(IndexScanDesc scan, ScanDirection direction); +extern ItemPointer scan_handler_idx_getnext_tid(IndexScanDesc scan, ScanDirection direction); +extern int64 scan_handler_idx_getbitmap(IndexScanDesc scan, TIDBitmap* bitmap); + +#endif /* HBINDEX_AM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/hbucket_am.h postgresql-hll-2.14/include/include/access/hbucket_am.h --- postgresql-hll-2.14_old/include/include/access/hbucket_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/hbucket_am.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,78 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hbucket_am.h + * hash bucket table access method definitions. + * + * + * IDENTIFICATION + * src/include/access/hbucket_am.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HASHPART_AM_H +#define HASHPART_AM_H + +#include "access/relscan.h" +#include "access/heapam.h" +#include "utils/relcache.h" +#include "optimizer/bucketinfo.h" +#include "access/tableam.h" + +/* +* redis need merge item +*/ +typedef struct RedisMergeItem { + int2 bktid; + uint64 start; + uint64 end; +}RedisMergeItem; + +typedef struct RedisMergeItemOrderArray { + RedisMergeItem *itemarray; + int length; +}RedisMergeItemOrderArray; + +extern RedisMergeItem *hbkt_get_merge_item_from_str(char *merge_list, int merge_list_length, int2 bucketid); + +extern TableScanDesc GetHeapScanDesc(TableScanDesc scan, Relation rel); +extern IndexScanDesc GetIndexScanDesc(IndexScanDesc scan); +extern List* hbkt_load_buckets(Relation relation, BucketInfo* bkt_info); + +extern RedisMergeItemOrderArray *hbkt_get_merge_list_from_str(char* merge_list, int merge_list_length); + +void hbkt_set_merge_list_to_pgxc_class_option(Oid pcrelid, RedisMergeItemOrderArray* merge_items, bool first_set); + +extern RedisMergeItem *search_redis_merge_item(const RedisMergeItemOrderArray *merge_items, const int2 bucketid); +extern void freeRedisMergeItemOrderArray(RedisMergeItemOrderArray *merge_items); + +extern bool hbkt_sampling_scan_nextbucket(TableScanDesc hpScan); +extern bool hbkt_bitmapheap_scan_nextbucket(HBktTblScanDesc hpScan); +extern bool hbkt_tbl_tid_nextbucket(HBktTblScanDesc hpScan); + +extern TableScanDesc scan_handler_tbl_beginscan(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, ScanState* sstate = NULL); +extern TableScanDesc scan_handler_tbl_begin_tidscan(Relation relation, ScanState* state); +extern void scan_handler_tbl_end_tidscan(TableScanDesc scan); +extern void scan_handler_tbl_markpos(TableScanDesc scan); +extern void scan_handler_tbl_restrpos(TableScanDesc scan); +extern TableScanDesc scan_handler_tbl_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, ScanState* sstate); +extern TableScanDesc scan_handler_tbl_beginscan_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync, ScanState* sstate); +extern Tuple scan_handler_tbl_getnext(TableScanDesc scan, ScanDirection direction, Relation rel); +extern void scan_handler_tbl_endscan(TableScanDesc scan, Relation rel); +extern void scan_handler_tbl_rescan(TableScanDesc scan, struct ScanKeyData* key, Relation rel); +#define NOT_EXIST_MERGE_LIST "not_exist_merge_list" + +#endif /* HASHPART_AM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/heapam.h postgresql-hll-2.14/include/include/access/heapam.h --- postgresql-hll-2.14_old/include/include/access/heapam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/heapam.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,347 @@ +/* ------------------------------------------------------------------------- + * + * heapam.h + * POSTGRES heap access method definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/heapam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HEAPAM_H +#define HEAPAM_H + +#include "access/sdir.h" +#include "access/skey.h" +#include "access/xlogrecord.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "storage/pagecompress.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/snapshot.h" +#include "replication/bcm.h" + +/* "options" flag bits for heap_insert */ +#define HEAP_INSERT_SKIP_WAL 0x0001 +#define HEAP_INSERT_SKIP_FSM 0x0002 +#define HEAP_INSERT_FROZEN 0x0004 +#define HEAP_INSERT_SPECULATIVE 0x0008 +#define HEAP_INSERT_SKIP_ERROR 0x0010 + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ +typedef struct SeqScanAccessor { + BlockNumber sa_last_prefbf; /* last prefetch block number */ + BlockNumber sa_pref_trigbf; /* last triggle block number */ + uint32 sa_prefetch_quantity; /* preftch quantity*/ + uint32 sa_prefetch_trigger; /* the prefetch-trigger distance bewteen last prefetched buffer and currently accessed buffer */ +} SeqScanAccessor; + +typedef struct RangeScanInRedis{ + uint8 isRangeScanInRedis; + uint8 sliceTotal; + uint8 sliceIndex; +} RangeScanInRedis; + +/* + * Generic descriptor for table scans. This is the base-class for table scans, + * which needs to be embedded in the scans of individual AMs. + */ +typedef struct TableScanDescData +{ + /* scan parameters */ + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; /* heap relation descriptor */ + Snapshot rs_snapshot; /* snapshot to see */ + int rs_nkeys; /* number of scan keys */ + ScanKey rs_key; /* array of scan key descriptors */ + bool rs_pageatatime; /* verify visibility page-at-a-time? */ + + /* + * Information about type and behaviour of the scan, a bitmask of members + * of the ScanOptions enum (see tableam.h). + */ + uint32 rs_flags; + + /* state set up at initscan time */ + BlockNumber rs_nblocks; /* number of blocks to scan */ + BlockNumber rs_startblock; /* block # to start at */ + BufferAccessStrategy rs_strategy; /* access strategy for reads */ + bool rs_syncscan; /* report location to syncscan logic? */ + + /* scan current state */ + bool rs_inited; /* false = scan not init'd yet */ + BlockNumber rs_cblock; /* current block # in scan, if any */ + Buffer rs_cbuf; /* current buffer in scan, if any */ + + /* these fields only used in page-at-a-time mode and for bitmap scans */ + int rs_cindex; /* current tuple's index in vistuples */ + int rs_ntuples; /* number of visible tuples on page */ + OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]; /* their offsets */ + SeqScanAccessor* rs_ss_accessor; /* adio use it to init prefetch quantity and trigger */ + + /* state set up at initscan time */ + RangeScanInRedis rs_rangeScanInRedis; /* if it is a range scan in redistribution */ +} TableScanDescData; + +/* struct definition appears in relscan.h */ +typedef struct TableScanDescData *TableScanDesc; +typedef struct HeapScanDescData* HeapScanDesc; +typedef struct IndexScanDescData* IndexScanDesc; + +/* + * Base class for fetches from a table via an index. This is the base-class + * for such scans, which needs to be embedded in the respective struct for + * individual AMs. + */ +typedef struct IndexFetchTableData +{ + Relation rel; +} IndexFetchTableData; + +/* + * Descriptor for fetches from heap via an index. + */ +typedef struct IndexFetchHeapData +{ + IndexFetchTableData xs_base; /* AM independent part of the descriptor */ + + /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ +} IndexFetchHeapData; + +struct ScanState; + +typedef struct BulkInsertStateData* BulkInsertState; + +typedef enum { LockTupleShared, LockTupleExclusive } LockTupleMode; + +/* the last arguments info for heap_multi_insert() */ +typedef struct { + /* compression info: dictionary buffer and its size */ + const char* dictData; + int dictSize; + + /* forbid to use page replication */ + bool disablePageReplication; +} HeapMultiInsertExtraArgs; + +/* + * When tuple_update, tuple_delete, or tuple_lock fail because the target + * tuple is already outdated, they fill in this struct to provide information + * to the caller about what happened. + * + * ctid is the target's ctid link: it is the same as the target's TID if the + * target was deleted, or the location of the replacement tuple if the target + * was updated. + * + * xmax is the outdating transaction's XID. If the caller wants to visit the + * replacement tuple, it must check that this matches before believing the + * replacement is really a match. + * + * cmax is the outdating command's CID, but only when the failure code is + * HeapTupleSelfUpdated (i.e., something in the current transaction outdated the + * tuple); otherwise cmax is zero. (We make this restriction because + * HeapTupleHeaderGetCmax doesn't work for tuples outdated in other + * transactions.) + */ +typedef struct TM_FailureData +{ + ItemPointerData ctid; + TransactionId xmax; + TransactionId xmin; + CommandId cmax; +} TM_FailureData; + +#define enable_heap_bcm_data_replication() \ + (u_sess->attr.attr_storage.enable_data_replicate && !g_instance.attr.attr_storage.enable_mix_replication) + +/* ---------------- + * function prototypes for heap access method + * + * heap_create, heap_create_with_catalog, and heap_drop_with_catalog + * are declared in catalog/heap.h + * ---------------- + */ + +/* in heap/heapam.c */ +extern Relation relation_open(Oid relationId, LOCKMODE lockmode, int2 bucketId=-1); +extern Partition partitionOpenWithRetry(Relation relation, Oid partitionId, LOCKMODE lockmode, const char * stmt); +extern Partition partitionOpen(Relation relation, Oid partitionId, LOCKMODE lockmode, int2 bucketId=-1); +extern void partitionClose(Relation relation, Partition partition, LOCKMODE lockmode); +extern Partition tryPartitionOpen(Relation relation, Oid partitionId, LOCKMODE lockmode); +extern Relation try_relation_open(Oid relationId, LOCKMODE lockmode); +extern Relation relation_openrv(const RangeVar* relation, LOCKMODE lockmode); +extern Relation relation_openrv_extended(const RangeVar* relation, LOCKMODE lockmode, bool missing_ok, + bool isSupportSynonym = false, StringInfo detailInfo = NULL); +extern void relation_close(Relation relation, LOCKMODE lockmode); +#define bucketCloseRelation(bucket) releaseDummyRelation(&(bucket)) +extern Relation bucketGetRelation(Relation rel, Partition part, int2 bucketId); +extern Relation heap_open(Oid relationId, LOCKMODE lockmode, int2 bucketid=-1); +extern Relation heap_openrv(const RangeVar *relation, LOCKMODE lockmode); +extern Relation heap_openrv_extended(const RangeVar* relation, LOCKMODE lockmode, bool missing_ok, + bool isSupportSynonym = false, StringInfo detailInfo = NULL); +extern Partition bucketGetPartition(Partition part, int2 bucketid); +extern void bucketClosePartition(Partition bucket); + +#define heap_close(r,l) relation_close(r,l) + +/* struct definition appears in relscan.h */ +typedef struct HeapScanDescData* HeapScanDesc; + +/* + * HeapScanIsValid + * True iff the heap scan is valid. + */ +#define HeapScanIsValid(scan) PointerIsValid(scan) + +extern TableScanDesc heap_beginscan( + Relation relation, Snapshot snapshot, int nkeys, ScanKey key, RangeScanInRedis rangeScanInRedis = {false,0,0}); +extern TableScanDesc heap_beginscan_strat( + Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync); +extern TableScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key); +extern TableScanDesc heap_beginscan_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis); + +extern void heapgetpage(TableScanDesc scan, BlockNumber page); + +extern void heap_rescan(TableScanDesc sscan, ScanKey key); +extern void heap_endscan(TableScanDesc scan); +extern HeapTuple heap_getnext(TableScanDesc scan, ScanDirection direction); + +extern void heap_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir); + +extern HeapTuple heapGetNextForVerify(TableScanDesc scan, ScanDirection direction, bool& isValidRelationPage); +extern bool heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation); +extern bool heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, Snapshot snapshot, + HeapTuple heapTuple, HeapTupleHeaderData* uncompressTup, bool* all_dead, bool first_call); +extern bool heap_hot_search(ItemPointer tid, Relation relation, Snapshot snapshot, bool* all_dead); + +extern void heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid); + +extern void setLastTid(const ItemPointer tid); +extern void heap_get_max_tid(Relation rel, ItemPointer ctid); + +extern BulkInsertState GetBulkInsertState(void); +extern void FreeBulkInsertState(BulkInsertState); + +extern Oid heap_insert(Relation relation, HeapTuple tup, CommandId cid, int options, BulkInsertState bistate); +extern void heap_abort_speculative(Relation relation, HeapTuple tuple); +extern bool heap_page_prepare_for_xid( + Relation relation, Buffer buffer, TransactionId xid, bool multi, bool pageReplication = false); +extern bool heap_change_xidbase_after_freeze(Relation relation, Buffer buffer); + +extern bool rewrite_page_prepare_for_xid(Page page, TransactionId xid, bool multi); +extern int heap_multi_insert(Relation relation, Relation parent, HeapTuple* tuples, int ntuples, CommandId cid, int options, + BulkInsertState bistate, HeapMultiInsertExtraArgs* args); +extern TM_Result heap_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, + bool wait, TM_FailureData *tmfd, bool allow_delete_self = false); +extern TM_Result heap_update(Relation relation, Relation parentRelation, ItemPointer otid, HeapTuple newtup, + CommandId cid, Snapshot crosscheck, bool wait, TM_FailureData *tmfd, bool allow_delete_self = false); +extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer* buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, bool allow_lock_self = false); + +extern void heap_inplace_update(Relation relation, HeapTuple tuple); +extern bool heap_freeze_tuple(HeapTuple tuple, TransactionId cutoff_xid); +extern bool heap_tuple_needs_freeze(HeapTuple tuple, TransactionId cutoff_xid, Buffer buf); + +extern Oid simple_heap_insert(Relation relation, HeapTuple tup); +extern void simple_heap_delete(Relation relation, ItemPointer tid, int options = 0); +extern void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup); + +extern void heap_markpos(TableScanDesc scan); +extern void heap_restrpos(TableScanDesc scan); + +extern void heap_sync(Relation relation, LOCKMODE lockmode = RowExclusiveLock); + +extern void partition_sync(Relation rel, Oid partitionId, LOCKMODE toastLockmode); + +extern void heap_redo(XLogReaderState* rptr); +extern void heap_desc(StringInfo buf, XLogReaderState* record); +extern void heap2_redo(XLogReaderState* rptr); +extern void heap2_desc(StringInfo buf, XLogReaderState* record); +extern void heap3_redo(XLogReaderState* rptr); +extern void heap3_desc(StringInfo buf, XLogReaderState* record); +extern void heap_bcm_redo(xl_heap_bcm* xlrec, RelFileNode node, XLogRecPtr lsn); + +extern bool heap_page_upgrade(Relation relation, Buffer buffer); +extern void heap_page_upgrade_nocheck(Relation relation, Buffer buffer); + +extern XLogRecPtr log_heap_cleanup_info(const RelFileNode* rnode, TransactionId latestRemovedXid); +extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer, OffsetNumber* redirected, int nredirected, + OffsetNumber* nowdead, int ndead, OffsetNumber* nowunused, int nunused, TransactionId latestRemovedXid, + bool repair_fragmentation); +extern XLogRecPtr log_heap_freeze( + Relation reln, Buffer buffer, TransactionId cutoff_xid, OffsetNumber* offsets, int offcnt); +extern XLogRecPtr log_heap_visible(RelFileNode rnode, BlockNumber block, Buffer heap_buffer, Buffer vm_buffer, + TransactionId cutoff_xid, bool free_dict); +extern XLogRecPtr log_cu_bcm(const RelFileNode* rnode, int col, uint64 block, int status, int count); +extern XLogRecPtr log_heap_bcm(const RelFileNode* rnode, int col, uint64 block, int status); +extern XLogRecPtr log_newpage(RelFileNode* rnode, ForkNumber forkNum, BlockNumber blk, Page page, bool page_std); +extern XLogRecPtr log_logical_newpage( + RelFileNode* rnode, ForkNumber forkNum, BlockNumber blk, Page page, Buffer buffer); +extern XLogRecPtr log_logical_newcu( + RelFileNode* rnode, ForkNumber forkNum, int attid, Size offset, int size, char* cuData); +extern XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std); +/* in heap/pruneheap.c */ +extern void heap_page_prune_opt(Relation relation, Buffer buffer); +extern int heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, bool report_stats, + TransactionId* latestRemovedXid, bool repairFragmentation); +extern void heap_page_prune_execute(Page page, OffsetNumber* redirected, int nredirected, OffsetNumber* nowdead, + int ndead, OffsetNumber* nowunused, int nunused, bool repairFragmentation); +extern void heap_get_root_tuples(Page page, OffsetNumber* root_offsets); + +extern IndexFetchTableData * heapam_index_fetch_begin(Relation rel); +extern void heapam_index_fetch_reset(IndexFetchTableData *scan); +extern void heapam_index_fetch_end(IndexFetchTableData *scan); +extern HeapTuple heapam_index_fetch_tuple(IndexScanDesc scan, bool *all_dead); + +/* in heap/syncscan.c */ +extern void ss_report_location(Relation rel, BlockNumber location); +extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks); +extern void SyncScanShmemInit(void); +extern Size SyncScanShmemSize(void); + +extern void PushHeapPageToDataQueue(Buffer buffer); + +/* + * HeapTupleSatisfiesVisibility + * True iff heap tuple satisfies a time qual. + * + * Notes: + * Assumes heap tuple is valid. + * Beware of multiple evaluations of snapshot argument. + * Hint bits in the HeapTuple's t_infomask may be updated as a side effect; + * if so, the indicated buffer is marked dirty. + */ +extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot, Buffer buffer); + +/* Result codes for HeapTupleSatisfiesVacuum */ +typedef enum { + HEAPTUPLE_DEAD, /* tuple is dead and deletable */ + HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */ + HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */ + HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */ + HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */ +} HTSV_Result; + +/* Special "satisfies" routines with different APIs */ +extern TM_Result HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid, Buffer buffer, bool self_visible = false); +extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin, Buffer buffer, bool isAnalyzing = false); +extern bool HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin); +extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer, uint16 infomask, TransactionId xid); + +/* + * To avoid leaking to much knowledge about reorderbuffer implementation + * details this is implemented in reorderbuffer.c not tqual.c. + */ +extern bool ResolveCminCmaxDuringDecoding( + struct HTAB* tuplecid_data, Snapshot snapshot, HeapTuple htup, Buffer buffer, CommandId* cmin, CommandId* cmax); + +#endif /* HEAPAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/hio.h postgresql-hll-2.14/include/include/access/hio.h --- postgresql-hll-2.14_old/include/include/access/hio.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/hio.h 2020-12-12 17:06:43.137346619 +0800 @@ -0,0 +1,42 @@ +/* ------------------------------------------------------------------------- + * + * hio.h + * POSTGRES heap access method input/output definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/hio.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HIO_H +#define HIO_H + +#include "access/heapam.h" +#include "access/htup.h" +#include "utils/relcache.h" +#include "storage/buf.h" + +/* + * state for bulk inserts --- private to heapam.c and hio.c + * + * If current_buf isn't InvalidBuffer, then we are holding an extra pin + * on that buffer. + * + * "typedef struct BulkInsertStateData *BulkInsertState" is in heapam.h + */ +typedef struct BulkInsertStateData { + BufferAccessStrategy strategy; /* our BULKWRITE strategy object */ + Buffer current_buf; /* current insertion target page */ +} BulkInsertStateData; + +extern void RelationPutHeapTuple(Relation relation, Buffer buffer, HeapTuple tuple, TransactionId xid); +extern Buffer RelationGetBufferForTuple(Relation relation, Size len, Buffer otherBuffer, int options, + BulkInsertState bistate, Buffer* vmbuffer, Buffer* vmbuffer_other, BlockNumber end_rel_block); +extern Buffer RelationGetNewBufferForBulkInsert(Relation relation, Size len, Size dictSize, BulkInsertState bistate); +extern void RelationAddExtraBlocks(Relation relation, BulkInsertState bistate); + +#endif /* HIO_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/htup.h postgresql-hll-2.14/include/include/access/htup.h --- postgresql-hll-2.14_old/include/include/access/htup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/htup.h 2020-12-12 17:06:43.138346632 +0800 @@ -0,0 +1,1154 @@ +/* ------------------------------------------------------------------------- + * + * htup.h + * POSTGRES heap tuple definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/htup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HTUP_H +#define HTUP_H + +#include "access/tupdesc.h" +#include "access/tupmacs.h" +#include "access/xlogreader.h" +#include "storage/buf.h" +#include "storage/bufpage.h" +#include "storage/itemptr.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + + /* Number of internal columns added by Redis during scale-in/scale-out. */ +#define REDIS_NUM_INTERNAL_COLUMNS (4) + +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFFFFFFFFF) /* First four bits reserved */ +#define MaxShortTransactionId ((TransactionId)0xFFFFFFFF) + +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) + +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +#define ShortTransactionIdToNormal(base, xid) \ + (TransactionIdIsNormal(xid) ? (TransactionId)(xid) + (base) : (TransactionId)(xid)) +#define NormalTransactionIdToShort(base, xid) \ + (TransactionIdIsNormal(xid) ? (ShortTransactionId)(AssertMacro((xid) >= (base) + FirstNormalTransactionId), \ + AssertMacro((xid) <= (base) + MaxShortTransactionId), \ + (xid) - (base)) \ + : (ShortTransactionId)(xid)) + +/* + * MaxTupleAttributeNumber limits the number of (user) columns in a tuple. + * The key limit on this value is that the size of the fixed overhead for + * a tuple, plus the size of the null-values bitmap (at 1 bit per column), + * plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most + * machines the upper limit without making t_hoff wider would be a little + * over 1700. We use round numbers here and for MaxHeapAttributeNumber + * so that alterations in HeapTupleHeaderData layout won't change the + * supported max number of columns. + */ +#define MaxTupleAttributeNumber 1664 /* 8 * 208 */ + +/* + * MaxHeapAttributeNumber limits the number of (user) columns in a table. + * This should be somewhat less than MaxTupleAttributeNumber. It must be + * at least one less, else we will fail to do UPDATEs on a maximal-width + * table (because UPDATE has to form working tuples that include CTID). + * In practice we want some additional daylight so that we can gracefully + * support operations that add hidden "resjunk" columns, for example + * SELECT * FROM wide_table ORDER BY foo, bar, baz. + * In any case, depending on column data types you will likely be running + * into the disk-block-based limit on overall tuple size if you have more + * than a thousand or so columns. TOAST won't help. + */ +#define MaxHeapAttributeNumber 1600 /* 8 * 200 */ + +/* + * Heap tuple header. To avoid wasting space, the fields should be + * laid out in such a way as to avoid structure padding. + * + * Datums of composite types (row types) share the same general structure + * as on-disk tuples, so that the same routines can be used to build and + * examine them. However the requirements are slightly different: a Datum + * does not need any transaction visibility information, and it does need + * a length word and some embedded type information. We can achieve this + * by overlaying the xmin/cmin/xmax/cmax/xvac fields of a heap tuple + * with the fields needed in the Datum case. Typically, all tuples built + * in-memory will be initialized with the Datum fields; but when a tuple is + * about to be inserted in a table, the transaction fields will be filled, + * overwriting the datum fields. + * + * The overall structure of a heap tuple looks like: + * fixed fields (HeapTupleHeaderData struct) + * nulls bitmap (if HEAP_HASNULL is set in t_infomask) + * alignment padding (as needed to make user data MAXALIGN'd) + * object ID (if HEAP_HASOID is set in t_infomask) + * user data fields + * + * We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac in three + * physical fields. Xmin and Xmax are always really stored, but Cmin, Cmax + * and Xvac share a field. This works because we know that Cmin and Cmax + * are only interesting for the lifetime of the inserting and deleting + * transaction respectively. If a tuple is inserted and deleted in the same + * transaction, we store a "combo" command id that can be mapped to the real + * cmin and cmax, but only by use of local state within the originating + * backend. See combocid.c for more details. Meanwhile, Xvac is only set by + * old-style VACUUM FULL, which does not have any command sub-structure and so + * does not need either Cmin or Cmax. (This requires that old-style VACUUM + * FULL never try to move a tuple whose Cmin or Cmax is still interesting, + * ie, an insert-in-progress or delete-in-progress tuple.) + * + * A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid + * is initialized with its own TID (location). If the tuple is ever updated, + * its t_ctid is changed to point to the replacement version of the tuple. + * Thus, a tuple is the latest version of its row iff XMAX is invalid or + * t_ctid points to itself (in which case, if XMAX is valid, the tuple is + * either locked or deleted). One can follow the chain of t_ctid links + * to find the newest version of the row. Beware however that VACUUM might + * erase the pointed-to (newer) tuple before erasing the pointing (older) + * tuple. Hence, when following a t_ctid link, it is necessary to check + * to see if the referenced slot is empty or contains an unrelated tuple. + * Check that the referenced tuple has XMIN equal to the referencing tuple's + * XMAX to verify that it is actually the descendant version and not an + * unrelated tuple stored into a slot recently freed by VACUUM. If either + * check fails, one may assume that there is no live descendant version. + * + * Following the fixed header fields, the nulls bitmap is stored (beginning + * at t_bits). The bitmap is *not* stored if t_infomask shows that there + * are no nulls in the tuple. If an OID field is present (as indicated by + * t_infomask), then it is stored just before the user data, which begins at + * the offset shown by t_hoff. Note that t_hoff must be a multiple of + * MAXALIGN. + */ + +typedef struct HeapTupleFields { + ShortTransactionId t_xmin; /* inserting xact ID */ + ShortTransactionId t_xmax; /* deleting or locking xact ID */ + + union { + CommandId t_cid; /* inserting or deleting command ID, or both */ + ShortTransactionId t_xvac; /* old-style VACUUM FULL xact ID */ + } t_field3; +} HeapTupleFields; + +typedef struct DatumTupleFields { + int32 datum_len_; /* varlena header (do not touch directly!) */ + + int32 datum_typmod; /* -1, or identifier of a record type */ + + Oid datum_typeid; /* composite type OID, or RECORDOID */ + + /* + * Note: field ordering is chosen with thought that Oid might someday + * widen to 64 bits. + */ +} DatumTupleFields; + +typedef struct HeapTupleHeaderData { + union { + HeapTupleFields t_heap; + DatumTupleFields t_datum; + } t_choice; + + ItemPointerData t_ctid; /* current TID of this or newer tuple */ + + /* Fields below here must match MinimalTupleData! */ + + uint16 t_infomask2; /* number of attributes + various flags */ + + uint16 t_infomask; /* various flag bits, see below */ + + uint8 t_hoff; /* sizeof header incl. bitmap, padding */ + + /* ^ - 23 bytes - ^ */ + + bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs -- VARIABLE LENGTH */ + + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} HeapTupleHeaderData; +typedef HeapTupleHeaderData* HeapTupleHeader; + +#define SizeofMinimalTupleHeader offsetof(MinimalTupleData, t_bits) +#define SizeofHeapTupleHeader offsetof(HeapTupleHeaderData, t_bits) + +/* + * information stored in t_infomask: + */ +#define HEAP_HASNULL 0x0001 /* has null attribute(s) */ +#define HEAP_HASVARWIDTH 0x0002 /* has variable-width attribute(s) */ +#define HEAP_HASEXTERNAL 0x0004 /* has external stored attribute(s) */ +#define HEAP_HASOID 0x0008 /* has an object-id field */ +#define HEAP_COMPRESSED 0x0010 /* has compressed data */ +#define HEAP_COMBOCID 0x0020 /* t_cid is a combo cid */ +#define HEAP_XMAX_EXCL_LOCK 0x0040 /* xmax is exclusive locker */ +#define HEAP_XMAX_SHARED_LOCK 0x0080 /* xmax is shared locker */ +/* if either LOCK bit is set, xmax hasn't deleted the tuple, only locked it */ +#define HEAP_IS_LOCKED (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_SHARED_LOCK) +#define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */ +#define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */ +#define HEAP_XMIN_FROZEN (HEAP_XMIN_INVALID | HEAP_XMIN_COMMITTED) +#define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */ +#define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */ +#define HEAP_XMAX_IS_MULTI 0x1000 /* t_xmax is a MultiXactId */ +#define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */ +#define HEAP_MOVED_OFF \ + 0x4000 /* moved to another place by pre-9.0 \ + * VACUUM FULL; kept for binary \ + * upgrade support */ +#define HEAP_MOVED_IN \ + 0x8000 /* moved from another place by pre-9.0 \ + * VACUUM FULL; kept for binary \ + * upgrade support */ +#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN) + +#define HEAP_XACT_MASK 0xFFE0 /* visibility-related bits */ + +/* + * information stored in t_infomask2: + */ +#define HEAP_NATTS_MASK 0x07FF /* 11 bits for number of attributes */ +/* bits 0x1800 are available */ +#define HEAP_HAS_REDIS_COLUMNS 0x2000 /* tuple has hidden columns added by redis */ +#define HEAP_HOT_UPDATED 0x4000 /* tuple was HOT-updated */ +#define HEAP_ONLY_TUPLE 0x8000 /* this is heap-only tuple */ + +#define HEAP2_XACT_MASK 0xC000 /* visibility-related bits */ + +/* + * HEAP_TUPLE_HAS_MATCH is a temporary flag used during hash joins. It is + * only used in tuples that are in the hash table, and those don't need + * any visibility information, so we can overlay it on a visibility flag + * instead of using up a dedicated bit. + */ +#define HEAP_TUPLE_HAS_MATCH HEAP_ONLY_TUPLE /* tuple has a join match */ + +/* + * HeapTupleHeader accessor macros + * + * Note: beware of multiple evaluations of "tup" argument. But the Set + * macros evaluate their other argument only once. + */ +/* + * HeapTupleHeaderGetRawXmin returns the "raw" xmin field, which is the xid + * originally used to insert the tuple. However, the tuple might actually + * be frozen (via HeapTupleHeaderSetXminFrozen) in which case the tuple's xmin + * is visible to every snapshot. Prior to PostgreSQL 9.4, we actually changed + * the xmin to FrozenTransactionId, and that value may still be encountered + * on disk. + */ + +#define HeapTupleCopyBaseFromPage(tup, page) \ + { \ + if (PageIs8BXidHeapVersion(page)) { \ + (tup)->t_xid_base = ((HeapPageHeader)(page))->pd_xid_base; \ + (tup)->t_multi_base = ((HeapPageHeader)(page))->pd_multi_base; \ + } else { \ + (tup)->t_xid_base = 0; \ + (tup)->t_multi_base = 0; \ + } \ + } + +#define HeapTupleCopyBase(dest, src) \ + do { \ + (dest)->t_xid_base = (src)->t_xid_base; \ + (dest)->t_multi_base = (src)->t_multi_base; \ + } while (0) + +#define HeapTupleSetZeroBase(tup) \ + { \ + (tup)->t_xid_base = InvalidTransactionId; \ + (tup)->t_multi_base = InvalidTransactionId; \ + } +#define HeapTupleHeaderXminCommitted(tup) ((tup)->t_infomask & HEAP_XMIN_COMMITTED) + +#define HeapTupleHeaderXminInvalid(tup) \ + (((tup)->t_infomask & (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)) == HEAP_XMIN_INVALID) +#define HeapTupleHeaderGetXmin(page, tup) \ + (ShortTransactionIdToNormal( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, (tup)->t_choice.t_heap.t_xmin)) +#define HeapTupleHeaderGetRawXmax(page, tup) HeapTupleHeaderGetXmax(page, tup) +#define HeapTupleGetRawXmin(tup) (ShortTransactionIdToNormal((tup)->t_xid_base, (tup)->t_data->t_choice.t_heap.t_xmin)) + +#define HeapTupleHeaderXminInvalid(tup) \ + (((tup)->t_infomask & (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)) == HEAP_XMIN_INVALID) + +#define HeapTupleHeaderXminFrozen(tup) (((tup)->t_infomask & (HEAP_XMIN_FROZEN)) == HEAP_XMIN_FROZEN) + +#define HeapTupleHeaderSetXminCommitted(tup) \ + (AssertMacro(!HeapTupleHeaderXminInvalid(tup)), ((tup)->t_infomask |= HEAP_XMIN_COMMITTED)) + +#define HeapTupleHeaderSetXminInvalid(tup) \ + (AssertMacro(!HeapTupleHeaderXminCommitted(tup)), ((tup)->t_infomask |= HEAP_XMIN_INVALID)) + +#define HeapTupleHeaderSetXminFrozen(tup) \ + (AssertMacro(!HeapTupleHeaderXminInvalid(tup)), ((tup)->t_infomask |= HEAP_XMIN_FROZEN)) + +#define HeapTupleGetRawXmax(tup) \ + (ShortTransactionIdToNormal( \ + ((tup)->t_data->t_infomask & HEAP_XMAX_IS_MULTI ? (tup)->t_multi_base: (tup)->t_xid_base), \ + ((tup)->t_data->t_choice.t_heap.t_xmax) \ + )) + +#define HeapTupleHeaderGetXmax(page, tup) \ + (ShortTransactionIdToNormal(((tup)->t_infomask & HEAP_XMAX_IS_MULTI) \ + ? (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_multi_base : 0) \ + : (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0), \ + ((tup)->t_choice.t_heap.t_xmax))) + +#define HeapTupleHeaderSetXmax(page, tup, xid) \ + ((tup)->t_choice.t_heap.t_xmax = NormalTransactionIdToShort( \ + (((tup)->t_infomask & HEAP_XMAX_IS_MULTI) \ + ? (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_multi_base : 0) \ + : (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0)), \ + (xid))) +#define HeapTupleHeaderSetXmin(page, tup, xid) \ + ((tup)->t_choice.t_heap.t_xmin = NormalTransactionIdToShort( \ + (PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0), (xid))) + +#define HeapTupleSetXmax(tup, xid) \ + ((tup)->t_data->t_choice.t_heap.t_xmax = NormalTransactionIdToShort( \ + ((tup)->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ? tup->t_multi_base : tup->t_xid_base, (xid))) + +#define HeapTupleSetXmin(tup, xid) \ + ((tup)->t_data->t_choice.t_heap.t_xmin = NormalTransactionIdToShort(tup->t_xid_base, (xid))) + +/* + * HeapTupleHeaderGetRawCommandId will give you what's in the header whether + * it is useful or not. Most code should use HeapTupleHeaderGetCmin or + * HeapTupleHeaderGetCmax instead, but note that those Assert that you can + * get a legitimate result, ie you are in the originating transaction! + */ +#define HeapTupleHeaderGetRawCommandId(tup) ((tup)->t_choice.t_heap.t_field3.t_cid) + +/* SetCmin is reasonably simple since we never need a combo CID */ +#define HeapTupleHeaderSetCmin(tup, cid) \ + do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ + (tup)->t_infomask &= ~HEAP_COMBOCID; \ + } while (0) + +/* SetCmax must be used after HeapTupleHeaderAdjustCmax; see combocid.c */ +#define HeapTupleHeaderSetCmax(tup, cid, iscombo) \ + do { \ + Assert(!((tup)->t_infomask & HEAP_MOVED)); \ + (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ + if (iscombo) \ + (tup)->t_infomask |= HEAP_COMBOCID; \ + else \ + (tup)->t_infomask &= ~HEAP_COMBOCID; \ + } while (0) + +#define HeapTupleHeaderGetDatumLength(tup) VARSIZE(tup) + +#define HeapTupleHeaderSetDatumLength(tup, len) SET_VARSIZE(tup, len) + +#define HeapTupleHeaderGetTypeId(tup) ((tup)->t_choice.t_datum.datum_typeid) + +#define HeapTupleHeaderSetTypeId(tup, typeid) ((tup)->t_choice.t_datum.datum_typeid = (typeid)) + +#define HeapTupleHeaderGetTypMod(tup) ((tup)->t_choice.t_datum.datum_typmod) + +#define HeapTupleHeaderSetTypMod(tup, typmod) ((tup)->t_choice.t_datum.datum_typmod = (typmod)) + +#define HeapTupleHeaderGetOid(tup) \ + (((tup)->t_infomask & HEAP_HASOID) ? *((Oid*)((char*)(tup) + (tup)->t_hoff - sizeof(Oid))) : InvalidOid) + +#define HeapTupleHeaderSetOid(tup, oid) \ + do { \ + Assert((tup)->t_infomask& HEAP_HASOID); \ + *((Oid*)((char*)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid); \ + } while (0) + +#define HeapTupleHeaderHasOid(tup) (((tup)->t_infomask & HEAP_HASOID) != 0) + +/* + * Note that we stop considering a tuple HOT-updated as soon as it is known + * aborted or the would-be updating transaction is known aborted. For best + * efficiency, check tuple visibility before using this macro, so that the + * INVALID bits will be as up to date as possible. + */ +#define HeapTupleHeaderIsHotUpdated(tup) \ + (((tup)->t_infomask2 & HEAP_HOT_UPDATED) != 0 && ((tup)->t_infomask & HEAP_XMAX_INVALID) == 0 && \ + !HeapTupleHeaderXminInvalid(tup)) + +#define HeapTupleHeaderSetHotUpdated(tup) ((tup)->t_infomask2 |= HEAP_HOT_UPDATED) + +#define HeapTupleHeaderClearHotUpdated(tup) ((tup)->t_infomask2 &= ~HEAP_HOT_UPDATED) + +#define HeapTupleHeaderIsHeapOnly(tup) (((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0) + +#define HeapTupleHeaderSetHeapOnly(tup) ((tup)->t_infomask2 |= HEAP_ONLY_TUPLE) + +#define HeapTupleHeaderClearHeapOnly(tup) ((tup)->t_infomask2 &= ~HEAP_ONLY_TUPLE) + +#define HeapTupleHeaderHasRedisColumns(tup) (((tup)->t_infomask2 & HEAP_HAS_REDIS_COLUMNS) != 0) + +#define HeapTupleHeaderSetRedisColumns(tup) ((tup)->t_infomask2 |= HEAP_HAS_REDIS_COLUMNS) + +#define HeapTupleHeaderUnsetRedisColumns(tup) ((tup)->t_infomask2 &= ~HEAP_HAS_REDIS_COLUMNS) + +#define HeapTupleHeaderHasMatch(tup) (((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0) + +#define HeapTupleHeaderSetMatch(tup) ((tup)->t_infomask2 |= HEAP_TUPLE_HAS_MATCH) + +#define HeapTupleHeaderClearMatch(tup) ((tup)->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH) + +/* + * Tuple Descriptor is added to ignore the hidden columns added by redis (if any) + * from the tuple. + */ +static inline uint32 HeapTupleHeaderGetNatts(HeapTupleHeader tup, TupleDesc tup_desc) +{ + Assert(tup != NULL); + uint32 natts = (tup->t_infomask2 & HEAP_NATTS_MASK); + + /* + * If the tuple header has HEAP_HAS_REDIS_COLUMNS bit set, it means that the + * tuple has values for the REDIS_NUM_INTERNAL_COLUMNS added by redis. + * These column values are valid only for the duration of table redistribution. + * Once the table redistribution is completed (the relation is not + * REDIS_REL_DESTINATION anymore), these column values must be ignored from + * the tuple. + */ + if (HeapTupleHeaderHasRedisColumns(tup) && tup_desc && !tup_desc->tdisredistable) { + Assert(natts >= REDIS_NUM_INTERNAL_COLUMNS); + natts -= REDIS_NUM_INTERNAL_COLUMNS; + } + + return natts; +} + +#define HeapTupleHeaderSetNatts(tup, natts) ((tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts)) + +/* tuple' compression macro */ +#define HEAP_TUPLE_SET_COMPRESSED(tup) ((tup)->t_infomask |= HEAP_COMPRESSED) + +#define HEAP_TUPLE_IS_COMPRESSED(tup) (((tup)->t_infomask & HEAP_COMPRESSED) != 0) + +#define HEAP_TUPLE_CLEAR_COMPRESSED(tup) ((tup)->t_infomask &= ~HEAP_COMPRESSED) + +/* Struct for forming compressed tuple. + * + * compressed: comppressed flag for each attribute in one tuple. + * delta/prefix/dict values are mixed in values of heapFormTuple(desc, values, isnulls, void*) + * delta compression: --> char* delta, whose size is in valsize[] + * prefix compression: --> char* ended with '\0', whose size is in valsize[] + * dict compression: --> the index of dict item, whose size is in valsize[] + */ +typedef struct { + bool* isnulls; + bool* compressed; + Datum* values; + int* valsize; +} FormCmprTupleData; + +/* + * BITMAPLEN(NATTS) - + * Computes size of null bitmap given number of data columns. + */ +#define BITMAPLEN(NATTS) (((int)(NATTS) + 7) / 8) + +/* + * MaxHeapTupleSize is the maximum allowed size of a heap tuple, including + * header and MAXALIGN alignment padding. Basically it's BLCKSZ minus the + * other stuff that has to be on a disk page. Since heap pages use no + * "special space", there's no deduction for that. + * + * NOTE: we allow for the ItemId that must point to the tuple, ensuring that + * an otherwise-empty page can indeed hold a tuple of this size. Because + * ItemIds and tuples have different alignment requirements, don't assume that + * you can, say, fit 2 tuples of size MaxHeapTupleSize/2 on the same page. + */ +#define MaxHeapTupleSize (BLCKSZ - MAXALIGN(SizeOfHeapPageHeaderData + sizeof(ItemIdData))) +#define MinHeapTupleSize MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + +/* + * MaxHeapTuplesPerPage is an upper bound on the number of tuples that can + * fit on one heap page. (Note that indexes could have more, because they + * use a smaller tuple header.) We arrive at the divisor because each tuple + * must be maxaligned, and it must have an associated item pointer. + * + * Note: with HOT, there could theoretically be more line pointers (not actual + * tuples) than this on a heap page. However we constrain the number of line + * pointers to this anyway, to avoid excessive line-pointer bloat and not + * require increases in the size of work arrays. + */ +#define MaxHeapTuplesPerPage \ + ((int)((BLCKSZ - SizeOfHeapPageHeaderData) / \ + (MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData)))) + +/* + * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of + * data fields of char(n) and similar types. It need not have anything + * directly to do with the *actual* upper limit of varlena values, which + * is currently 1Gb (see TOAST structures in postgres.h). I've set it + * at 10Mb which seems like a reasonable number --- tgl 8/6/00. + */ +#define MaxAttrSize (10 * 1024 * 1024) + +/* + * MinimalTuple is an alternative representation that is used for transient + * tuples inside the executor, in places where transaction status information + * is not required, the tuple rowtype is known, and shaving off a few bytes + * is worthwhile because we need to store many tuples. The representation + * is chosen so that tuple access routines can work with either full or + * minimal tuples via a HeapTupleData pointer structure. The access routines + * see no difference, except that they must not access the transaction status + * or t_ctid fields because those aren't there. + * + * For the most part, MinimalTuples should be accessed via TupleTableSlot + * routines. These routines will prevent access to the "system columns" + * and thereby prevent accidental use of the nonexistent fields. + * + * MinimalTupleData contains a length word, some padding, and fields matching + * HeapTupleHeaderData beginning with t_infomask2. The padding is chosen so + * that offsetof(t_infomask2) is the same modulo MAXIMUM_ALIGNOF in both + * structs. This makes data alignment rules equivalent in both cases. + * + * When a minimal tuple is accessed via a HeapTupleData pointer, t_data is + * set to point MINIMAL_TUPLE_OFFSET bytes before the actual start of the + * minimal tuple --- that is, where a full tuple matching the minimal tuple's + * data would start. This trick is what makes the structs seem equivalent. + * + * Note that t_hoff is computed the same as in a full tuple, hence it includes + * the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however. + * + * MINIMAL_TUPLE_DATA_OFFSET is the offset to the first useful (non-pad) data + * other than the length word. tuplesort.c and tuplestore.c use this to avoid + * writing the padding to disk. + */ +#define MINIMAL_TUPLE_OFFSET \ + ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF) +#define MINIMAL_TUPLE_PADDING ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF) +#define MINIMAL_TUPLE_DATA_OFFSET offsetof(MinimalTupleData, t_infomask2) + +typedef struct MinimalTupleData { + uint32 t_len; /* actual length of minimal tuple */ + char mt_padding[MINIMAL_TUPLE_PADDING]; + + /* Fields below here must match HeapTupleHeaderData! */ + uint16 t_infomask2; /* number of attributes + various flags */ + + uint16 t_infomask; /* various flag bits, see below */ + + uint8 t_hoff; /* sizeof header incl. bitmap, padding */ + + /* ^ - 23 bytes - ^ */ + + bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs -- VARIABLE LENGTH */ + + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} MinimalTupleData; + +typedef MinimalTupleData* MinimalTuple; + +/* + * HeapTupleData is an in-memory data structure that points to a tuple. + * + * There are several ways in which this data structure is used: + * + * * Pointer to a tuple in a disk buffer: t_data points directly into the + * buffer (which the code had better be holding a pin on, but this is not + * reflected in HeapTupleData itself). + * + * * Pointer to nothing: t_data is NULL. This is used as a failure indication + * in some functions. + * + * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple + * form a single palloc'd chunk. t_data points to the memory location + * immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE). + * This is the output format of heap_form_tuple and related routines. + * + * * Separately allocated tuple: t_data points to a palloc'd chunk that + * is not adjacent to the HeapTupleData. (This case is deprecated since + * it's difficult to tell apart from case #1. It should be used only in + * limited contexts where the code knows that case #1 will never apply.) + * + * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET + * bytes before the start of a MinimalTuple. As with the previous case, + * this can't be told apart from case #1 by inspection; code setting up + * or destroying this representation has to know what it's doing. + * + * t_len should always be valid, except in the pointer-to-nothing case. + * t_self and t_tableOid should be valid if the HeapTupleData points to + * a disk buffer, or if it represents a copy of a tuple on disk. They + * should be explicitly set invalid in manufactured tuples. + */ +typedef struct HeapTupleData { + uint32 tupTableType = HEAP_TUPLE; + uint32 t_len; /* length of *t_data */ + ItemPointerData t_self; /* SelfItemPointer */ + Oid t_tableOid; /* table the tuple came from */ + TransactionId t_xid_base; + TransactionId t_multi_base; +#ifdef PGXC + uint32 t_xc_node_id; /* Data node the tuple came from */ +#endif + HeapTupleHeader t_data; /* -> tuple header and data */ + int2 t_bucketId; +} HeapTupleData; + +typedef HeapTupleData* HeapTuple; +typedef void* Tuple; + +inline HeapTuple heaptup_alloc(Size size) +{ + HeapTuple tup = (HeapTuple)palloc0(size); + tup->tupTableType = HEAP_TUPLE; + return tup; +} + +#define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData)) + +/* + * GETSTRUCT - given a HeapTuple pointer, return address of the user data + */ +#define GETSTRUCT(TUP) ((char*)((TUP)->t_data) + (TUP)->t_data->t_hoff) + +/* + * Accessor macros to be used with HeapTuple pointers. + */ +#define HeapTupleIsValid(tuple) PointerIsValid(tuple) + +#define HeapTupleHasNulls(tuple) (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0) + +#define HeapTupleNoNulls(tuple) (!((tuple)->t_data->t_infomask & HEAP_HASNULL)) + +#define HeapTupleHasVarWidth(tuple) (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0) + +#define HeapTupleAllFixed(tuple) (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH)) + +#define HeapTupleHasExternal(tuple) (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0) + +#define HeapTupleIsHotUpdated(tuple) HeapTupleHeaderIsHotUpdated((tuple)->t_data) + +#define HeapTupleSetHotUpdated(tuple) HeapTupleHeaderSetHotUpdated((tuple)->t_data) + +#define HeapTupleClearHotUpdated(tuple) HeapTupleHeaderClearHotUpdated((tuple)->t_data) + +#define HeapTupleIsHeapOnly(tuple) HeapTupleHeaderIsHeapOnly((tuple)->t_data) + +#define HeapTupleSetHeapOnly(tuple) HeapTupleHeaderSetHeapOnly((tuple)->t_data) + +#define HeapTupleClearHeapOnly(tuple) HeapTupleHeaderClearHeapOnly((tuple)->t_data) + +#define HeapTupleGetOid(tuple) HeapTupleHeaderGetOid((tuple)->t_data) + +#define HeapTupleSetOid(tuple, oid) HeapTupleHeaderSetOid((tuple)->t_data, (oid)) + +/* + * WAL record definitions for heapam.c's WAL operations + * + * XLOG allows to store some information in high 4 bits of log + * record xl_info field. We use 3 for opcode and one for init bit. + */ +#define XLOG_HEAP_INSERT 0x00 +#define XLOG_HEAP_DELETE 0x10 +#define XLOG_HEAP_UPDATE 0x20 +#define XLOG_HEAP_BASE_SHIFT 0x30 +#define XLOG_HEAP_HOT_UPDATE 0x40 +#define XLOG_HEAP_NEWPAGE 0x50 +#define XLOG_HEAP_LOCK 0x60 +#define XLOG_HEAP_INPLACE 0x70 + +#define XLOG_HEAP_OPMASK 0x70 +/* + * When we insert 1st item on new page in INSERT, UPDATE, HOT_UPDATE, + * or MULTI_INSERT, we can (and we do) restore entire page in redo + */ +#define XLOG_HEAP_INIT_PAGE 0x80 +/* + * We ran out of opcodes, so heapam.c now has a second RmgrId. These opcodes + * are associated with RM_HEAP2_ID, but are not logically different from + * the ones above associated with RM_HEAP_ID. XLOG_HEAP_OPMASK applies to + * these, too. + */ +#define XLOG_HEAP2_FREEZE 0x00 +#define XLOG_HEAP2_CLEAN 0x10 +/* 0x20 is free, was XLOG_HEAP2_CLEAN_MOVE */ +#define XLOG_HEAP2_PAGE_UPGRADE 0x20 +#define XLOG_HEAP2_CLEANUP_INFO 0x30 +#define XLOG_HEAP2_VISIBLE 0x40 +#define XLOG_HEAP2_MULTI_INSERT 0x50 +#define XLOG_HEAP2_BCM 0x60 + +#define XLOG_HEAP2_LOGICAL_NEWPAGE 0x70 + +/* + * When we prune page, sometimes not call PageRepairFragmentation (e.g freeze_single_heap_page), + * so need a flag to notify the standby DN the PageRepairFragmentation is not required. + */ +#define XLOG_HEAP2_NO_REPAIR_PAGE 0x80 + +/* XLOG_HEAP_NEW_CID with 0x30 in heap is XLOGHEAP2_NEW_CID with 0x70 in heap2 in PG9.4 */ +#define XLOG_HEAP3_NEW_CID 0x00 +#define XLOG_HEAP3_REWRITE 0x10 + +/* we used to put all xl_heap_* together, which made us run out of opcodes (quickly) + * when trying to add a DELETE_IS_SUPER operation. Thus we split the codes carefully + * for INSERT, UPDATE, DELETE individually. each has 8 bits available to use. + */ +/* + * xl_heap_insert/xl_heap_multi_insert flag values, 8 bits are available + */ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_INSERT_ALL_VISIBLE_CLEARED (1<<0) +#define XLH_INSERT_CONTAINS_NEW_TUPLE (1<<4) +#define XLH_INSERT_LAST_IN_MULTI (1<<7) + +/* + * xl_heap_update flag values, 8 bits are available. +*/ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_UPDATE_OLD_ALL_VISIBLE_CLEARED (1<<0) +/* PD_ALL_VISIBLE was cleared in the 2nd page */ +#define XLH_UPDATE_NEW_ALL_VISIBLE_CLEARED (1<<1) +#define XLH_UPDATE_CONTAINS_OLD_TUPLE (1<<2) +#define XLH_UPDATE_CONTAINS_OLD_KEY (1<<3) +#define XLH_UPDATE_CONTAINS_NEW_TUPLE (1<<4) +#define XLH_UPDATE_PREFIX_FROM_OLD (1<<5) +#define XLH_UPDATE_SUFFIX_FROM_OLD (1<<6) + +/* convenience macro for checking whether any form of old tuple was logged */ +#define XLH_UPDATE_CONTAINS_OLD \ + (XLH_UPDATE_CONTAINS_OLD_TUPLE | XLH_UPDATE_CONTAINS_OLD_KEY) + +/* +* xl_heap_delete flag values, 8 bits are available. +*/ +/* PD_ALL_VISIBLE was cleared */ +#define XLH_DELETE_ALL_VISIBLE_CLEARED (1<<0) +#define XLH_DELETE_IS_SUPER (1<<1) +#define XLH_DELETE_CONTAINS_OLD_TUPLE (1<<2) +#define XLH_DELETE_CONTAINS_OLD_KEY (1<<3) + +/* convenience macro for checking whether any form of old tuple was logged */ +#define XLH_DELETE_CONTAINS_OLD \ + (XLH_DELETE_CONTAINS_OLD_TUPLE | XLH_DELETE_CONTAINS_OLD_KEY) + +/* This is what we need to know about delete */ +typedef struct xl_heap_delete { + OffsetNumber offnum; /* deleted tuple's offset */ + uint8 flags; +} xl_heap_delete; + +#define SizeOfHeapDelete (offsetof(xl_heap_delete, flags) + sizeof(bool)) + +/* + * We don't store the whole fixed part (HeapTupleHeaderData) of an inserted + * or updated tuple in WAL; we can save a few bytes by reconstructing the + * fields that are available elsewhere in the WAL record, or perhaps just + * plain needn't be reconstructed. These are the fields we must store. + * NOTE: t_hoff could be recomputed, but we may as well store it because + * it will come for free due to alignment considerations. + */ +typedef struct xl_heap_header { + uint16 t_infomask2; + uint16 t_infomask; + uint8 t_hoff; +} xl_heap_header; + +#define SizeOfHeapHeader (offsetof(xl_heap_header, t_hoff) + sizeof(uint8)) + +/* This is what we need to know about insert */ +typedef struct xl_heap_insert { + OffsetNumber offnum; /* inserted tuple's offset */ + uint8 flags; + + /* xl_heap_header & TUPLE DATA in backup block 0 */ +} xl_heap_insert; + +#define SizeOfHeapInsert (offsetof(xl_heap_insert, flags) + sizeof(uint8)) + +/* + * This is what we need to know about a multi-insert. + * + * The main data of the record consists of this xl_heap_multi_insert header. + * 'offsets' array is omitted if the whole page is reinitialized + * (XLOG_HEAP_INIT_PAGE). + * + * If this block is compressed with dictionary, then this dictionary will follow + * header, but before tuples and + * tuples' data. indicates whether there is a dictionary. + * + * In block 0's data portion, there is an xl_multi_insert_tuple struct, + * followed by the tuple data for each tuple. There is padding to align + * each xl_multi_insert struct. + */ +typedef struct xl_heap_multi_insert { + uint8 flags; + bool isCompressed; + uint16 ntuples; + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} xl_heap_multi_insert; + +#define SizeOfHeapMultiInsert offsetof(xl_heap_multi_insert, offsets) + +typedef struct xl_multi_insert_tuple { + uint16 datalen; /* size of tuple data that follows */ + uint16 t_infomask2; + uint16 t_infomask; + uint8 t_hoff; + /* TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_multi_insert_tuple; + +#define SizeOfMultiInsertTuple (offsetof(xl_multi_insert_tuple, t_hoff) + sizeof(uint8)) + +/* + * This is what we need to know about update|hot_update + * + * Backup blk 0: new page + * + * If XLOG_HEAP_PREFIX_FROM_OLD or XLOG_HEAP_SUFFIX_FROM_OLD flags are set, + * the prefix and/or suffix come first, as one or two uint16s. + * + * After that, xl_heap_header and new tuple data follow. The new tuple + * data doesn't include the prefix and suffix, which are copied from the + * old tuple on replay. + * + * If HEAP_CONTAINS_NEW_TUPLE_DATA flag is given, the tuple data is + * included even if a full-page image was taken. + * + * Backup blk 1: old page, if different. (no data, just a reference to the blk) + */ +typedef struct xl_heap_update { + OffsetNumber old_offnum; /* old tuple's offset */ + OffsetNumber new_offnum; /* new tuple's offset */ + uint8 flags; /* NEW TUPLE xl_heap_header AND TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_heap_update; + +#define SizeOfHeapUpdate (offsetof(xl_heap_update, flags) + sizeof(uint8)) +/* + * This is what we need to know about vacuum page cleanup/redirect + * + * The array of OffsetNumbers following the fixed part of the record contains: + * * for each redirected item: the item offset, then the offset redirected to + * * for each now-dead item: the item offset + * * for each now-unused item: the item offset + * The total number of OffsetNumbers is therefore 2*nredirected+ndead+nunused. + * Note that nunused is not explicitly stored, but may be found by reference + * to the total record length. + */ +typedef struct xl_heap_clean { + TransactionId latestRemovedXid; + uint16 nredirected; + uint16 ndead; + /* OFFSET NUMBERS are in the block reference 0 */ +} xl_heap_clean; + +#define SizeOfHeapClean (offsetof(xl_heap_clean, ndead) + sizeof(uint16)) + +/* + * Cleanup_info is required in some cases during a lazy VACUUM. + * Used for reporting the results of HeapTupleHeaderAdvanceLatestRemovedXid() + * see vacuumlazy.c for full explanation + */ +typedef struct xl_heap_cleanup_info { + RelFileNodeOld node; + TransactionId latestRemovedXid; +} xl_heap_cleanup_info; + +#define SizeOfHeapCleanupInfo (sizeof(xl_heap_cleanup_info)) + +/* Logical xlog for multi_insert or new index when data replication store is row*/ +typedef struct xl_heap_logical_newpage { + RelFileNodeOld node; // relfilenode + BlockNumber blkno; // block number + ForkNumber forknum; + StorageEngine type; + bool hasdata; // flag of save cu xlog + int attid; // column id + Size offset; // CU offset + int32 blockSize; + /* Other infos?: offset datalen Row or column store */ +} xl_heap_logical_newpage; + +#define SizeOfHeapLogicalNewPage (offsetof(xl_heap_logical_newpage, blockSize) + sizeof(int32)) + +/* This is what we need to know about lock */ +typedef struct xl_heap_lock { + TransactionId locking_xid; /* might be a MultiXactId not xid */ + OffsetNumber offnum; /* locked tuple's offset on page */ + bool xid_is_mxact; /* is it? */ + bool shared_lock; /* shared or exclusive row lock? */ +} xl_heap_lock; + +#define SizeOfHeapLock (offsetof(xl_heap_lock, shared_lock) + sizeof(bool)) + +/* This is what we need to know about in-place update */ +typedef struct xl_heap_inplace { + OffsetNumber offnum; /* updated tuple's offset on page */ + /* TUPLE DATA FOLLOWS AT END OF STRUCT */ +} xl_heap_inplace; + +#define SizeOfHeapInplace (offsetof(xl_heap_inplace, offnum) + sizeof(OffsetNumber)) + +/* + * This is what we need to know about a block being frozen during vacuum + * + * Backup block 0's data contains an array of xl_heap_freeze structs, + * one for each tuple. + */ +typedef struct xl_heap_freeze { + TransactionId cutoff_xid; + /* TUPLE OFFSET NUMBERS FOLLOW AT THE END */ +} xl_heap_freeze; + +#define SizeOfHeapFreeze (offsetof(xl_heap_freeze, cutoff_xid) + sizeof(TransactionId)) + +typedef struct xl_heap_freeze_tuple { + TransactionId xmax; + OffsetNumber offset; + uint16 t_infomask2; + uint16 t_infomask; + uint8 frzflags; +} xl_heap_freeze_tuple; + +/* + * This is what we need to know about setting a visibility map bit + * + * Backup blk 0: visibility map buffer + * Backup blk 1: heap buffer if exists (except partition merge) + */ +typedef struct xl_heap_visible { + BlockNumber block; + TransactionId cutoff_xid; + bool free_dict; /* dick will be checked and freed when switching visibility. */ +} xl_heap_visible; + +#define SizeOfHeapVisible (offsetof(xl_heap_visible, free_dict) + sizeof(bool)) + +/* This is what we need to know about setting a bcm map bit */ +typedef struct xl_heap_bcm { + RelFileNodeOld node; + uint32 col; + uint64 block; + int count; + int status; +} xl_heap_bcm; + +#define SizeOfHeapBcm (offsetof(xl_heap_bcm, status) + sizeof(int)) + +/* shift the base of xids on heap page */ +typedef struct xl_heap_base_shift { + int64 delta; /* delta value to shift the base */ + bool multi; /* true to shift multixact base */ +} xl_heap_base_shift; + +#define SizeOfHeapBaseShift (offsetof(xl_heap_base_shift, multi) + sizeof(bool)) + +typedef struct xl_heap_new_cid { + /* + * store toplevel xid so we don't have to merge cids from different + * transactions + */ + TransactionId top_xid; + CommandId cmin; + CommandId cmax; + CommandId combocid; /* just for debugging */ + + /* + * Store the relfilenode/ctid pair to facilitate lookups. + */ + RelFileNodeOld target_node; + ItemPointerData target_tid; +} xl_heap_new_cid; + +#define SizeOfHeapNewCid (offsetof(xl_heap_new_cid, target_tid) + sizeof(ItemPointerData)) + +/* logical rewrite xlog record header */ +typedef struct xl_heap_rewrite_mapping { + TransactionId mapped_xid; /* xid that might need to see the row */ + Oid mapped_db; /* DbOid or InvalidOid for shared rels */ + Oid mapped_rel; /* Oid of the mapped relation */ + off_t offset; /* How far have we written so far */ + uint32 num_mappings; /* Number of in-memory mappings */ + XLogRecPtr start_lsn; /* Insert LSN at begin of rewrite */ +} xl_heap_rewrite_mapping; +extern void HeapTupleHeaderAdvanceLatestRemovedXid(HeapTuple tuple, TransactionId* latestRemovedXid); + +/* HeapTupleHeader functions implemented in utils/time/combocid.c */ +extern CommandId HeapTupleGetCmin(HeapTuple tup); +extern CommandId HeapTupleGetCmax(HeapTuple tup); +extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup, Page page); +extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup, Page page); +extern bool CheckStreamCombocid(HeapTupleHeader tup, CommandId current_cid, Page page); +extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup, CommandId* cmax, bool* iscombo, Buffer buffer); + +/* ---------------- + * fastgetattr && fastgetattr_with_dict + * + * Fetch a user attribute's value as a Datum (might be either a + * value, or a pointer into the data area of the tuple). + * + * This must not be used when a system attribute might be requested. + * Furthermore, the passed attnum MUST be valid. Use heap_getattr() + * instead, if in doubt. + * + * This gets called many times, so we macro the cacheable and NULL + * lookups, and call nocachegetattr() for the rest. + * ---------------- + */ + +#if !defined(DISABLE_COMPLEX_MACRO) + +#define fastgetattr(tup, attnum, tuple_desc, isnull) \ + (AssertMacro(!HEAP_TUPLE_IS_COMPRESSED((tup)->t_data)), \ + AssertMacro((attnum) > 0), \ + (*(isnull) = false), \ + HeapTupleNoNulls(tup) \ + ? ((tuple_desc)->attrs[(attnum)-1]->attcacheoff >= 0 \ + ? (fetchatt((tuple_desc)->attrs[(attnum)-1], \ + (char*)(tup)->t_data + (tup)->t_data->t_hoff + \ + (tuple_desc)->attrs[(attnum)-1]->attcacheoff)) \ + : nocachegetattr((tup), (attnum), (tuple_desc))) \ + : (att_isnull((attnum)-1, (tup)->t_data->t_bits) ? ((*(isnull) = true), (Datum)NULL) \ + : (nocachegetattr((tup), (attnum), (tuple_desc))))) + +#define fastgetattr_with_dict(tup, attnum, tuple_desc, isnull, page_dict) \ + (AssertMacro(HEAP_TUPLE_IS_COMPRESSED((tup)->t_data)), \ + AssertMacro((attnum) > 0), \ + (*(isnull) = false), \ + (HeapTupleHasNulls(tup) && att_isnull((attnum)-1, (tup)->t_data->t_bits)) \ + ? ((*(isnull) = true), (Datum)NULL) \ + : nocache_cmprs_get_attr(tup, attnum, tuple_desc, page_dict)) + +#else /* defined(DISABLE_COMPLEX_MACRO) */ + +extern Datum fastgetattr_with_dict(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool* isnull, char* pageDict); +extern Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool* isnull); +#endif /* defined(DISABLE_COMPLEX_MACRO) */ + +/* ---------------- + * heap_getattr + * + * Extract an attribute of a heap tuple and return it as a Datum. + * This works for either system or user attributes. The given attnum + * is properly range-checked. + * + * If the field in question has a NULL value, we return a zero Datum + * and set *isnull == true. Otherwise, we set *isnull == false. + * + * is the pointer to the heap tuple. is the attribute + * number of the column (field) caller wants. is a + * pointer to the structure describing the row and all its fields. + * ---------------- + */ +#define heap_getattr_with_dict(tup, attnum, tuple_desc, isnull, pagedict) \ + (((int)(attnum) > 0) ? (((int)(attnum) > (int)HeapTupleHeaderGetNatts((tup)->t_data, tuple_desc)) \ + ? (/* get init default value from tupleDesc.*/ \ + heapGetInitDefVal((attnum), (tuple_desc), (isnull))) \ + : (HEAP_TUPLE_IS_COMPRESSED((tup)->t_data) \ + ? (fastgetattr_with_dict((tup), (attnum), (tuple_desc), (isnull), (pagedict))) \ + : (fastgetattr((tup), (attnum), (tuple_desc), (isnull))))) \ + : heap_getsysattr((tup), (attnum), (tuple_desc), (isnull))) + +#define heap_getattr(tup, attnum, tuple_desc, isnull) heap_getattr_with_dict(tup, attnum, tuple_desc, isnull, NULL) + +/* prototypes for functions in common/heaptuple.c */ +extern Size heap_compute_data_size(TupleDesc tuple_desc, Datum* values, const bool* isnull); + +extern void heap_fill_tuple( + TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit); +extern bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tuple_desc); +extern Datum nocache_cmprs_get_attr(HeapTuple tuple, uint32 attnum, TupleDesc tuple_desc, char* page_dict); +extern Datum nocachegetattr(HeapTuple tup, uint32 attnum, TupleDesc att); +extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tuple_desc, bool* isnull); + +extern HeapTuple heap_copytuple(HeapTuple tuple); +extern HeapTuple heapCopyCompressedTuple(HeapTuple tuple, TupleDesc tup_desc, Page dict_page, HeapTuple dest = NULL); +extern HeapTuple heapCopyTuple(HeapTuple tuple, TupleDesc tup_desc, Page page); + +#define COPY_TUPLE_HEADERINFO(_dest_tup, _src_tup) \ + do { \ + (_dest_tup)->t_choice = (_src_tup)->t_choice; \ + (_dest_tup)->t_ctid = (_src_tup)->t_ctid; \ + (_dest_tup)->t_infomask2 = (_src_tup)->t_infomask2; \ + (_dest_tup)->t_infomask = (_src_tup)->t_infomask; \ + } while (0) + +#define COPY_TUPLE_HEADER_XACT_INFO(_dest_tuple, _src_tuple) \ + do { \ + HeapTupleHeader _dest = (_dest_tuple)->t_data; \ + HeapTupleHeader _src = (_src_tuple)->t_data; \ + (_dest)->t_choice = (_src)->t_choice; \ + (_dest)->t_ctid = (_src)->t_ctid; \ + (_dest)->t_infomask2 = (((_dest)->t_infomask2 & ~HEAP2_XACT_MASK) | ((_src)->t_infomask2 & HEAP2_XACT_MASK)); \ + (_dest)->t_infomask = (((_dest)->t_infomask & ~HEAP_XACT_MASK) | ((_src)->t_infomask & HEAP_XACT_MASK)); \ + } while (0) + +extern void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest); + +extern HeapTuple heap_form_tuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull); +extern HeapTuple heap_form_cmprs_tuple(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info); + +extern HeapTuple heap_modify_tuple( + HeapTuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace); + +extern void heap_deform_cmprs_tuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info); +extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull); +extern void heap_deform_tuple2(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, Buffer buffer); +extern void heap_deform_tuple3(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, Page page); + +/* these three are deprecated versions of the three above: */ +extern HeapTuple heap_formtuple(TupleDesc tuple_descriptor, Datum* values, const char* nulls); +extern HeapTuple heap_modifytuple( + HeapTuple tuple, TupleDesc tuple_desc, Datum* repl_values, const char* repl_nulls, const char* repl_actions); +extern void heap_deformtuple(HeapTuple tuple, TupleDesc tuple_desc, Datum* values, char* nulls); +extern void heap_freetuple(HeapTuple htup); + +#define heap_freetuple_ext(htup) \ + do { \ + if ((htup) != NULL) { \ + heap_freetuple(htup); \ + htup = NULL; \ + } \ + } while (0) + +extern MinimalTuple heap_form_minimal_tuple( + TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple = NULL); +extern void heap_free_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup); +extern HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup); +extern MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup); + +extern Datum heapGetInitDefVal(int att_num, TupleDesc tuple_desc, bool* is_null); +extern bool relationAttIsNull(HeapTuple tup, int att_num, TupleDesc tuple_desc); +extern MinimalTuple heapFormMinimalTuple(HeapTuple tuple, TupleDesc tuple_desc); + +extern MinimalTuple heapFormMinimalTuple(HeapTuple tuple, TupleDesc tuple_desc, Page page); + +/* for GPI clean up metadata */ +typedef bool (*KeepInvisbleTupleFunc)(Datum checkDatum); +typedef struct KeepInvisbleOpt { + Oid tableOid; + int checkAttnum; + KeepInvisbleTupleFunc checkKeepFunc; +} KeepInvisbleOpt; + +bool HeapKeepInvisbleTuple(HeapTuple tuple, TupleDesc tupleDesc, KeepInvisbleTupleFunc checkKeepFunc = NULL); + +// for ut test +extern HeapTuple test_HeapUncompressTup2(HeapTuple tuple, TupleDesc tuple_desc, Page dict_page); + +/* + * Prefix for delete delta table name used in redis. + * There is no other suitable common header file included in pg_redis.cpp, so defining it here. + */ +#define REDIS_DELETE_DELTA_TABLE_PREFIX "pg_delete_delta_" +#define REDIS_MULTI_CATCHUP_DELETE_DELTA_TABLE_PREFIX "pg_delete_delta_x_" + +#endif /* HTUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/itup.h postgresql-hll-2.14/include/include/access/itup.h --- postgresql-hll-2.14_old/include/include/access/itup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/itup.h 2020-12-12 17:06:43.138346632 +0800 @@ -0,0 +1,119 @@ +/* ------------------------------------------------------------------------- + * + * itup.h + * POSTGRES index tuple definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/itup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITUP_H +#define ITUP_H + +#include "access/tupdesc.h" +#include "access/tupmacs.h" +#include "storage/bufpage.h" +#include "storage/itemptr.h" + +/* + * Index tuple header structure + * + * All index tuples start with IndexTupleData. If the HasNulls bit is set, + * this is followed by an IndexAttributeBitMapData. The index attribute + * values follow, beginning at a MAXALIGN boundary. + * + * Note that the space allocated for the bitmap does not vary with the number + * of attributes; that is because we don't have room to store the number of + * attributes in the header. Given the MAXALIGN constraint there's no space + * savings to be had anyway, for usual values of INDEX_MAX_KEYS. + */ + +typedef struct IndexTupleData { + ItemPointerData t_tid; /* reference TID to heap tuple */ + + /* --------------- + * t_info is laid out in the following fashion: + * + * 15th (high) bit: has nulls + * 14th bit: has var-width attributes + * 13th bit: AM-defined meaning + * 12-0 bit: size of tuple + * --------------- + */ + + unsigned short t_info; /* various info about tuple */ + +} IndexTupleData; /* MORE DATA FOLLOWS AT END OF STRUCT */ + +typedef IndexTupleData* IndexTuple; + +typedef struct IndexAttributeBitMapData { + bits8 bits[(INDEX_MAX_KEYS + 8 - 1) / 8]; +} IndexAttributeBitMapData; + +typedef IndexAttributeBitMapData* IndexAttributeBitMap; + +/* + * t_info manipulation macros + */ +#define INDEX_SIZE_MASK 0x1FFF +#define INDEX_AM_RESERVED_BIT 0x2000 /* reserved for index-AM specific usage */ +#define INDEX_VAR_MASK 0x4000 +#define INDEX_NULL_MASK 0x8000 + +#define IndexTupleSize(itup) ((Size)(((IndexTuple)(itup))->t_info & INDEX_SIZE_MASK)) +#define IndexTupleDSize(itup) ((Size)((itup).t_info & INDEX_SIZE_MASK)) +#define IndexTupleHasNulls(itup) ((((IndexTuple)(itup))->t_info & INDEX_NULL_MASK)) +#define IndexTupleHasVarwidths(itup) ((((IndexTuple)(itup))->t_info & INDEX_VAR_MASK)) + +/* + * Takes an infomask as argument (primarily because this needs to be usable + * at index_form_tuple time so enough space is allocated). + */ +#define IndexInfoFindDataOffset(t_info) \ + ((!((t_info)&INDEX_NULL_MASK)) ? ((Size)MAXALIGN(sizeof(IndexTupleData))) \ + : ((Size)MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData)))) + +/* ---------------- + * index_getattr + * + * This gets called many times, so we macro the cacheable and NULL + * lookups, and call nocache_index_getattr() for the rest. + * + * ---------------- + */ +#define index_getattr(tup, attnum, tupleDesc, isnull) \ + (AssertMacro(PointerIsValid(isnull) && (attnum) > 0), \ + *(isnull) = false, \ + !IndexTupleHasNulls(tup) ? ((tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 \ + ? (fetchatt((tupleDesc)->attrs[(attnum)-1], \ + (char*)(tup) + IndexInfoFindDataOffset((tup)->t_info) + \ + (tupleDesc)->attrs[(attnum)-1]->attcacheoff)) \ + : nocache_index_getattr((tup), (attnum), (tupleDesc))) \ + : ((att_isnull((attnum)-1, (char*)(tup) + sizeof(IndexTupleData))) \ + ? (*(isnull) = true, (Datum)NULL) \ + : (nocache_index_getattr((tup), (attnum), (tupleDesc))))) + +/* + * MaxIndexTuplesPerPage is an upper bound on the number of tuples that can + * fit on one index page. An index tuple must have either data or a null + * bitmap, so we can safely assume it's at least 1 byte bigger than a bare + * IndexTupleData struct. We arrive at the divisor because each tuple + * must be maxaligned, and it must have an associated item pointer. + */ +#define MinIndexTupleSize MAXALIGN(sizeof(IndexTupleData) + 1) +#define MaxIndexTuplesPerPage \ + ((int)((BLCKSZ - SizeOfPageHeaderData) / (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData)))) + +/* routines in indextuple.c */ +extern IndexTuple index_form_tuple(TupleDesc tuple_descriptor, Datum* values, const bool* isnull); +extern Datum nocache_index_getattr(IndexTuple tup, uint32 attnum, TupleDesc tuple_desc); +extern void index_deform_tuple(IndexTuple tup, TupleDesc tuple_descriptor, Datum* values, bool* isnull); +extern IndexTuple index_truncate_tuple(TupleDesc tupleDescriptor, IndexTuple olditup, int new_indnatts); +extern IndexTuple CopyIndexTuple(IndexTuple source); + +#endif /* ITUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/multi_redo_api.h postgresql-hll-2.14/include/include/access/multi_redo_api.h --- postgresql-hll-2.14_old/include/include/access/multi_redo_api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/multi_redo_api.h 2020-12-12 17:06:43.138346632 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * multi_redo_api.h + * + * + * IDENTIFICATION + * src/include/access/multi_redo_api.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MULTI_REDO_API_H +#define MULTI_REDO_API_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" +#include "access/redo_statistic.h" + + + + +typedef enum { + NOT_PAGE_REDO_THREAD, + PAGE_REDO_THREAD_EXIT_NORMAL, + PAGE_REDO_THREAD_EXIT_ABNORMAL, +} PageRedoExitStatus; + +extern bool g_supportHotStandby; + +const static bool SUPPORT_FPAGE_DISPATCH = true; /* support file dispatch if true, else support page dispatche */ + +const static bool SUPPORT_DFS_BATCH = false; +const static bool SUPPORT_COLUMN_BATCH = true; /* don't support column batch redo */ + + + +static const uint32 PAGE_REDO_WORKER_INVALID = 0; +static const uint32 PAGE_REDO_WORKER_START = 1; +static const uint32 PAGE_REDO_WORKER_READY = 2; +static const uint32 PAGE_REDO_WORKER_EXIT = 3; + +static inline int get_real_recovery_parallelism() +{ + return g_instance.attr.attr_storage.real_recovery_parallelism; +} + +static inline bool IsExtremeRedo() +{ + return g_instance.comm_cxt.predo_cxt.redoType == EXTREME_REDO && (get_real_recovery_parallelism() > 1); +} + +static inline bool IsParallelRedo() +{ + return g_instance.comm_cxt.predo_cxt.redoType == PARALLEL_REDO && (get_real_recovery_parallelism() > 1); +} + + +static inline bool IsMultiThreadRedo() +{ + return (get_real_recovery_parallelism() > 1); +} + +uint32 GetRedoWorkerCount(); + +bool IsMultiThreadRedoRunning(); +bool IsExtremeRtoRunning(); +void DispatchRedoRecord(XLogReaderState* record, List* expectedTLIs, TimestampTz recordXTime); +void GetThreadNameIfMultiRedo(int argc, char* argv[], char** threadNamePtr); + +PGPROC* MultiRedoThreadPidGetProc(ThreadId pid); +void MultiRedoUpdateStandbyState(HotStandbyState newState); +uint32 MultiRedoGetWorkerId(); +bool IsAllPageWorkerExit(); +void SetPageRedoWorkerIndex(int index); +int GetPageRedoWorkerIndex(int index); +PageRedoExitStatus CheckExitPageWorkers(ThreadId pid); +void SetMyPageRedoWorker(knl_thread_arg* arg); +uint32 GetMyPageRedoWorkerId(); +void MultiRedoMain(); +void StartUpMultiRedo(XLogReaderState* xlogreader, uint32 privateLen); + +void ProcTxnWorkLoad(bool force); +void EndDispatcherContext(); +void SwitchToDispatcherContext(); + +void FreeAllocatedRedoItem(); +void** GetXLogInvalidPagesFromWorkers(); +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); +bool IsExtremeRtoReadWorkerRunning(); +RedoWaitInfo GetRedoIoEvent(int32 event_id); +void GetRedoWrokerStatistic(uint32* realNum, RedoWorkerStatsData* worker, uint32 workerLen); +bool IsExtremeRtoSmartShutdown(); +void ExtremeRtoRedoManagerSendEndToStartup(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/multi_redo_settings.h postgresql-hll-2.14/include/include/access/multi_redo_settings.h --- postgresql-hll-2.14_old/include/include/access/multi_redo_settings.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/multi_redo_settings.h 2020-12-12 17:06:43.138346632 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * multi_redo_settings.h + * + * + * IDENTIFICATION + * src/include/access/multi_redo_settings.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MULTI_REDO_SETTINGS_H +#define MULTI_REDO_SETTINGS_H + + +/* if you change MOST_FAST_RECOVERY_LIMIT, remember to change max_recovery_parallelism in cluster_guc.conf */ +static const int MOST_FAST_RECOVERY_LIMIT = 20; +static const int MAX_PARSE_WORKERS = 16; +static const int MAX_REDO_WORKERS_PER_PARSE = 8; + + + + +static const int TRXN_REDO_MANAGER_NUM = 1; +static const int TRXN_REDO_WORKER_NUM = 1; +static const int XLOG_READER_NUM = 3; + +static const int MAX_EXTREME_THREAD_NUM = MAX_PARSE_WORKERS * MAX_REDO_WORKERS_PER_PARSE + MAX_PARSE_WORKERS + + MAX_PARSE_WORKERS + TRXN_REDO_MANAGER_NUM + TRXN_REDO_WORKER_NUM + XLOG_READER_NUM; + +static const int MAX_RECOVERY_THREAD_NUM = (MAX_EXTREME_THREAD_NUM > MOST_FAST_RECOVERY_LIMIT) ? + MAX_EXTREME_THREAD_NUM : MOST_FAST_RECOVERY_LIMIT; + +void ConfigRecoveryParallelism(); + + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/multixact.h postgresql-hll-2.14/include/include/access/multixact.h --- postgresql-hll-2.14_old/include/include/access/multixact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/multixact.h 2020-12-12 17:06:43.138346632 +0800 @@ -0,0 +1,83 @@ +/* + * multixact.h + * + * PostgreSQL multi-transaction-log manager + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/multixact.h + */ +#ifndef MULTIXACT_H +#define MULTIXACT_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +#define InvalidMultiXactId UINT64CONST(0) +#define FirstMultiXactId UINT64CONST(1) +#define MaxMultiXactId UINT64CONST(0xFFFFFFFFFFFFFFFF) + +#define MultiXactIdIsValid(multi) ((multi) != InvalidMultiXactId) + +#define MaxMultiXactOffset UINT64CONST(0xFFFFFFFFFFFFFFFF) + +/* Number of SLRU buffers to use for multixact */ +#define NUM_MXACTOFFSET_BUFFERS 8 +#define NUM_MXACTMEMBER_BUFFERS 16 + +/* ---------------- + * multixact-related XLOG entries + * ---------------- + */ + +#define XLOG_MULTIXACT_ZERO_OFF_PAGE 0x00 +#define XLOG_MULTIXACT_ZERO_MEM_PAGE 0x10 +#define XLOG_MULTIXACT_CREATE_ID 0x20 + +#define XLOG_MULTIXACT_MASK 0x70 +#define XLOG_MULTIXACT_INT64_PAGENO 0x80 + + +typedef struct xl_multixact_create { + MultiXactId mid; /* new MultiXact's ID */ + MultiXactOffset moff; /* its starting offset in members file */ + int32 nxids; /* number of member XIDs */ + TransactionId xids[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_multixact_create; + +#define MinSizeOfMultiXactCreate offsetof(xl_multixact_create, xids) + +extern MultiXactId MultiXactIdCreate(TransactionId xid1, TransactionId xid2); +extern MultiXactId MultiXactIdExpand(MultiXactId multi, TransactionId xid); +extern bool MultiXactIdIsRunning(MultiXactId multi); +extern bool MultiXactIdIsCurrent(MultiXactId multi); +extern MultiXactId ReadNextMultiXactId(void); +extern void MultiXactIdWait(MultiXactId multi, bool allow_con_update = false); +extern bool ConditionalMultiXactIdWait(MultiXactId multi); +extern void MultiXactIdSetOldestMember(void); +extern int GetMultiXactIdMembers(MultiXactId multi, TransactionId** xids); + +extern void AtEOXact_MultiXact(void); +extern void AtPrepare_MultiXact(void); +extern void PostPrepare_MultiXact(TransactionId xid); + +extern Size MultiXactShmemSize(void); +extern void MultiXactShmemInit(void); +extern void BootStrapMultiXact(void); +extern void StartupMultiXact(void); +extern void ShutdownMultiXact(void); +extern void MultiXactGetCheckptMulti(bool is_shutdown, MultiXactId* nextMulti, MultiXactOffset* nextMultiOffset); +extern void CheckPointMultiXact(void); +extern void MultiXactSetNextMXact(MultiXactId nextMulti, MultiXactOffset nextMultiOffset); +extern void MultiXactAdvanceNextMXact(MultiXactId minMulti, MultiXactOffset minMultiOffset); + +extern void multixact_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void multixact_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void multixact_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern void multixact_redo(XLogReaderState* record); +extern void multixact_desc(StringInfo buf, XLogReaderState* record); + +#endif /* MULTIXACT_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/nbtree.h postgresql-hll-2.14/include/include/access/nbtree.h --- postgresql-hll-2.14_old/include/include/access/nbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/nbtree.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,926 @@ +/* ------------------------------------------------------------------------- + * + * nbtree.h + * header file for postgres btree access method implementation. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/nbtree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NBTREE_H +#define NBTREE_H + +#include "access/genam.h" +#include "access/itup.h" +#include "access/sdir.h" +#include "access/xlogreader.h" +#include "catalog/pg_index.h" +#include "lib/stringinfo.h" +#include "storage/bufmgr.h" + +/* There's room for a 16-bit vacuum cycle ID in BTPageOpaqueData */ +typedef uint16 BTCycleId; + +/* + * BTPageOpaqueData -- At the end of every page, we store a pointer + * to both siblings in the tree. This is used to do forward/backward + * index scans. The next-page link is also critical for recovery when + * a search has navigated to the wrong page due to concurrent page splits + * or deletions; see src/backend/access/nbtree/README for more info. + * + * In addition, we store the page's btree level (counting upwards from + * zero at a leaf page) as well as some flag bits indicating the page type + * and status. If the page is deleted, we replace the level with the + * next-transaction-ID value indicating when it is safe to reclaim the page. + * + * We also store a "vacuum cycle ID". When a page is split while VACUUM is + * processing the index, a nonzero value associated with the VACUUM run is + * stored into both halves of the split page. (If VACUUM is not running, + * both pages receive zero cycleids.) This allows VACUUM to detect whether + * a page was split since it started, with a small probability of false match + * if the page was last split some exact multiple of MAX_BT_CYCLE_ID VACUUMs + * ago. Also, during a split, the BTP_SPLIT_END flag is cleared in the left + * (original) page, and set in the right page, but only if the next page + * to its right has a different cycleid. + * + * NOTE: the BTP_LEAF flag bit is redundant since level==0 could be tested + * instead. + */ + +typedef struct BTPageOpaqueDataInternal { + BlockNumber btpo_prev; /* left sibling, or P_NONE if leftmost */ + BlockNumber btpo_next; /* right sibling, or P_NONE if rightmost */ + union { + uint32 level; /* tree level --- zero for leaf pages */ + ShortTransactionId xact_old; /* next transaction ID, if deleted */ + } btpo; + uint16 btpo_flags; /* flag bits, see below */ + BTCycleId btpo_cycleid; /* vacuum cycle ID of latest split */ +} BTPageOpaqueDataInternal; + +typedef BTPageOpaqueDataInternal* BTPageOpaqueInternal; + +typedef struct BTPageOpaqueData { + BTPageOpaqueDataInternal bt_internal; + TransactionId xact; /* next transaction ID, if deleted */ +} BTPageOpaqueData; + +typedef BTPageOpaqueData* BTPageOpaque; + +/* Bits defined in btpo_flags */ +#define BTP_LEAF (1 << 0) /* leaf page, i.e. not internal page */ +#define BTP_ROOT (1 << 1) /* root page (has no parent) */ +#define BTP_DELETED (1 << 2) /* page has been deleted from tree */ +#define BTP_META (1 << 3) /* meta-page */ +#define BTP_HALF_DEAD (1 << 4) /* empty, but still in tree */ +#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */ +#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */ +#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */ + +/* + * The max allowed value of a cycle ID is a bit less than 64K. This is + * for convenience of pg_filedump and similar utilities: we want to use + * the last 2 bytes of special space as an index type indicator, and + * restricting cycle ID lets btree use that space for vacuum cycle IDs + * while still allowing index type to be identified. + */ +#define MAX_BT_CYCLE_ID 0xFF7F + +/* + * The Meta page is always the first page in the btree index. + * Its primary purpose is to point to the location of the btree root page. + * We also point to the "fast" root, which is the current effective root; + * see README for discussion. + */ + +typedef struct BTMetaPageData { + uint32 btm_magic; /* should contain BTREE_MAGIC */ + uint32 btm_version; /* should contain BTREE_VERSION */ + BlockNumber btm_root; /* current root location */ + uint32 btm_level; /* tree level of the root page */ + BlockNumber btm_fastroot; /* current "fast" root location */ + uint32 btm_fastlevel; /* tree level of the "fast" root page */ +} BTMetaPageData; + +#define BTPageGetMeta(p) ((BTMetaPageData*)PageGetContents(p)) + +#define BTREE_METAPAGE 0 /* first page is meta */ +#define BTREE_MAGIC 0x053162 /* magic number of btree pages */ +#define BTREE_VERSION 2 /* current version number */ + +/* Upgrade support for btree split/delete optimization. */ +#define BTREE_SPLIT_DELETE_UPGRADE_VERSION 92136 +#define BTREE_SPLIT_UPGRADE_FLAG 0x01 +#define BTREE_DELETE_UPGRADE_FLAG 0x02 + +/* + * Maximum size of a btree index entry, including its tuple header. + * + * We actually need to be able to fit three items on every page, + * so restrict any one item to 1/3 the per-page available space. + */ +#define BTMaxItemSize(page) \ + MAXALIGN_DOWN((PageGetPageSize(page) - MAXALIGN(SizeOfPageHeaderData + 3 * sizeof(ItemIdData)) - \ + MAXALIGN(sizeof(BTPageOpaqueData))) / \ + 3) + +/* + * The leaf-page fillfactor defaults to 90% but is user-adjustable. + * For pages above the leaf level, we use a fixed 70% fillfactor. + * The fillfactor is applied during index build and when splitting + * a rightmost page; when splitting non-rightmost pages we try to + * divide the data equally. + */ +#define BTREE_MIN_FILLFACTOR 10 +#define BTREE_DEFAULT_FILLFACTOR 90 +#define BTREE_NONLEAF_FILLFACTOR 70 + +/* + * Test whether two btree entries are "the same". + * + * Old comments: + * In addition, we must guarantee that all tuples in the index are unique, + * in order to satisfy some assumptions in Lehman and Yao. The way that we + * do this is by generating a new OID for every insertion that we do in the + * tree. This adds eight bytes to the size of btree index tuples. Note + * that we do not use the OID as part of a composite key; the OID only + * serves as a unique identifier for a given index tuple (logical position + * within a page). + * + * New comments: + * actually, we must guarantee that all tuples in A LEVEL + * are unique, not in ALL INDEX. So, we can use the t_tid + * as unique identifier for a given index tuple (logical position + * within a level). - vadim 04/09/97 + */ +#define BTTidSame(i1, i2) \ + ((i1).ip_blkid.bi_hi == (i2).ip_blkid.bi_hi && (i1).ip_blkid.bi_lo == (i2).ip_blkid.bi_lo && \ + (i1).ip_posid == (i2).ip_posid) +#define BTEntrySame(i1, i2) BTTidSame((i1)->t_tid, (i2)->t_tid) + +/* + * In general, the btree code tries to localize its knowledge about + * page layout to a couple of routines. However, we need a special + * value to indicate "no page number" in those places where we expect + * page numbers. We can use zero for this because we never need to + * make a pointer to the metadata page. + */ + +#define P_NONE 0 + +/* + * Macros to test whether a page is leftmost or rightmost on its tree level, + * as well as other state info kept in the opaque data. + */ +#define P_LEFTMOST(opaque) ((opaque)->btpo_prev == P_NONE) +#define P_RIGHTMOST(opaque) ((opaque)->btpo_next == P_NONE) +#define P_ISLEAF(opaque) ((opaque)->btpo_flags & BTP_LEAF) +#define P_ISROOT(opaque) ((opaque)->btpo_flags & BTP_ROOT) +#define P_ISDELETED(opaque) ((opaque)->btpo_flags & BTP_DELETED) +#define P_ISHALFDEAD(opaque) ((opaque)->btpo_flags & BTP_HALF_DEAD) +#define P_IGNORE(opaque) ((opaque)->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD)) +#define P_HAS_GARBAGE(opaque) ((opaque)->btpo_flags & BTP_HAS_GARBAGE) +#define P_INCOMPLETE_SPLIT(opaque) ((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) + +/* + * Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost + * page. The high key is not a data key, but gives info about what range of + * keys is supposed to be on this page. The high key on a page is required + * to be greater than or equal to any data key that appears on the page. + * If we find ourselves trying to insert a key > high key, we know we need + * to move right (this should only happen if the page was split since we + * examined the parent page). + * + * Our insertion algorithm guarantees that we can use the initial least key + * on our right sibling as the high key. Once a page is created, its high + * key changes only if the page is split. + * + * On a non-rightmost page, the high key lives in item 1 and data items + * start in item 2. Rightmost pages have no high key, so we store data + * items beginning in item 1. + */ + +#define P_HIKEY ((OffsetNumber)1) +#define P_FIRSTKEY ((OffsetNumber)2) +#define P_FIRSTDATAKEY(opaque) (P_RIGHTMOST(opaque) ? P_HIKEY : P_FIRSTKEY) + +/* + * XLOG records for btree operations + * + * XLOG allows to store some information in high 4 bits of log + * record xl_info field + */ +#define XLOG_BTREE_INSERT_LEAF 0x00 /* add index tuple without split */ +#define XLOG_BTREE_INSERT_UPPER 0x10 /* same, on a non-leaf page */ +#define XLOG_BTREE_INSERT_META 0x20 /* same, plus update metapage */ +#define XLOG_BTREE_SPLIT_L 0x30 /* add index tuple with split */ +#define XLOG_BTREE_SPLIT_R 0x40 /* as above, new item on right */ +#define XLOG_BTREE_SPLIT_L_ROOT 0x50 /* add tuple with split of root */ +#define XLOG_BTREE_SPLIT_R_ROOT 0x60 /* as above, new item on right */ +#define XLOG_BTREE_DELETE 0x70 /* delete leaf index tuples for a page */ +#define XLOG_BTREE_UNLINK_PAGE 0x80 /* delete an entire page */ +#define XLOG_BTREE_UNLINK_PAGE_META 0x90 /* same, and update metapage */ +#define XLOG_BTREE_NEWROOT 0xA0 /* new root page */ +#define XLOG_BTREE_MARK_PAGE_HALFDEAD \ + 0xB0 /* page deletion that makes \ + * parent half-dead */ +#define XLOG_BTREE_VACUUM \ + 0xC0 /* delete entries on a page during \ + * vacuum */ +#define XLOG_BTREE_REUSE_PAGE \ + 0xD0 /* old page is about to be reused from \ + * FSM */ + + +enum { + BTREE_INSERT_ORIG_BLOCK_NUM = 0, + BTREE_INSERT_CHILD_BLOCK_NUM, + BTREE_INSERT_META_BLOCK_NUM, +}; + +enum { + BTREE_SPLIT_LEFT_BLOCK_NUM = 0, + BTREE_SPLIT_RIGHT_BLOCK_NUM, + BTREE_SPLIT_RIGHTNEXT_BLOCK_NUM, + BTREE_SPLIT_CHILD_BLOCK_NUM +}; + +enum { + BTREE_VACUUM_ORIG_BLOCK_NUM = 0, +}; + +enum { + BTREE_DELETE_ORIG_BLOCK_NUM = 0, +}; + +enum { + BTREE_HALF_DEAD_LEAF_PAGE_NUM = 0, + BTREE_HALF_DEAD_PARENT_PAGE_NUM, +}; + +enum { + BTREE_UNLINK_PAGE_CUR_PAGE_NUM = 0, + BTREE_UNLINK_PAGE_LEFT_NUM, + BTREE_UNLINK_PAGE_RIGHT_NUM, + BTREE_UNLINK_PAGE_CHILD_NUM, + BTREE_UNLINK_PAGE_META_NUM, +}; + + +enum { + BTREE_NEWROOT_ORIG_BLOCK_NUM = 0, + BTREE_NEWROOT_LEFT_BLOCK_NUM, + BTREE_NEWROOT_META_BLOCK_NUM +}; + +/* + * All that we need to regenerate the meta-data page + */ +typedef struct xl_btree_metadata { + BlockNumber root; + uint32 level; + BlockNumber fastroot; + uint32 fastlevel; +} xl_btree_metadata; + +/* + * This is what we need to know about simple (without split) insert. + * + * This data record is used for INSERT_LEAF, INSERT_UPPER, INSERT_META. + * Note that INSERT_META implies it's not a leaf page. + * + * Backup Blk 0: original page (data contains the inserted tuple) + * Backup Blk 1: xl_btree_metadata, if INSERT_META + */ +typedef struct xl_btree_insert { + OffsetNumber offnum; +} xl_btree_insert; + +#define SizeOfBtreeInsert (offsetof(xl_btree_insert, offnum) + sizeof(OffsetNumber)) + +/* + * On insert with split, we save all the items going into the right sibling + * so that we can restore it completely from the log record. This way takes + * less xlog space than the normal approach, because if we did it standardly, + * XLogInsert would almost always think the right page is new and store its + * whole page image. The left page, however, is handled in the normal + * incremental-update fashion. + * + * Note: the four XLOG_BTREE_SPLIT xl_info codes all use this data record. + * The _L and _R variants indicate whether the inserted tuple went into the + * left or right split page (and thus, whether newitemoff and the new item + * are stored or not). The _HIGHKEY variants indicate that we've logged + * explicitly left page high key value, otherwise redo should use right page + * leftmost key as a left page high key. _HIGHKEY is specified for internal + * pages where right page leftmost key is suppressed, and for leaf pages + * of covering indexes where high key have non-key attributes truncated. + * + * Backup Blk 0: original page / new left page + * + * The left page's data portion contains the new item, if it's the _L variant. + * (In the _R variants, the new item is one of the right page's tuples.) + * If level > 0, an IndexTuple representing the HIKEY of the left page + * follows. We don't need this on leaf pages, because it's the same as the + * leftmost key in the new right page. + * + * Backup Blk 1: new right page + * + * The right page's data portion contains the right page's tuples in the + * form used by _bt_restore_page. + * + * Backup Blk 2: next block (orig page's rightlink), if any + */ +typedef struct xl_btree_split { + uint32 level; /* tree level of page being split */ + OffsetNumber firstright; /* first item moved to right page */ + OffsetNumber newitemoff; /* new item's offset (if placed on left page) */ +} xl_btree_split; + +#define SizeOfBtreeSplit (offsetof(xl_btree_split, newitemoff) + sizeof(OffsetNumber)) + +/* + * This is what we need to know about delete of individual leaf index tuples. + * The WAL record can represent deletion of any number of index tuples on a + * single index page when *not* executed by VACUUM. + * + * Backup Blk 0: index page + */ +typedef struct xl_btree_delete { + RelFileNodeOld hnode; /* RelFileNode of the heap the index currently + * points at */ + int nitems; + + /* TARGET OFFSET NUMBERS FOLLOW AT THE END */ +} xl_btree_delete; + +#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nitems) + sizeof(int)) + +/* + * This is what we need to know about page reuse within btree. + */ +typedef struct xl_btree_reuse_page { + RelFileNodeOld node; + BlockNumber block; + TransactionId latestRemovedXid; +} xl_btree_reuse_page; + +#define SizeOfBtreeReusePage (sizeof(xl_btree_reuse_page)) + +/* + * This is what we need to know about vacuum of individual leaf index tuples. + * The WAL record can represent deletion of any number of index tuples on a + * single index page when executed by VACUUM. + * + * The correctness requirement for applying these changes during recovery is + * that we must do one of these two things for every block in the index: + * * lock the block for cleanup and apply any required changes + * * EnsureBlockUnpinned() + * The purpose of this is to ensure that no index scans started before we + * finish scanning the index are still running by the time we begin to remove + * heap tuples. + * + * Any changes to any one block are registered on just one WAL record. All + * blocks that we need to run EnsureBlockUnpinned() are listed as a block range + * starting from the last block vacuumed through until this one. Individual + * block numbers aren't given. + * + * Note that the *last* WAL record in any vacuum of an index is allowed to + * have a zero length array of offsets. Earlier records must have at least one. + */ +typedef struct xl_btree_vacuum { + BlockNumber lastBlockVacuumed; + + /* TARGET OFFSET NUMBERS FOLLOW */ +} xl_btree_vacuum; + +#define SizeOfBtreeVacuum (offsetof(xl_btree_vacuum, lastBlockVacuumed) + sizeof(BlockNumber)) + +/* + * This is what we need to know about deletion of a btree page. The target + * identifies the tuple removed from the parent page (note that we remove + * this tuple's downlink and the *following* tuple's key). Note we do not + * store any content for the deleted page --- it is just rewritten as empty + * during recovery, apart from resetting the btpo.xact. + * + * Backup Blk 0: target block being deleted + * Backup Blk 1: target block's left sibling, if any + * Backup Blk 2: target block's right sibling + * Backup Blk 3: target block's parent + * Backup Blk 4: metapage (if rightsib becomes new fast root) + */ +typedef struct xl_btree_delete_page { + OffsetNumber poffset; /* deleted tuple id in parent page */ + BlockNumber leftblk; /* child block's left sibling, if any */ + BlockNumber rightblk; /* child block's right sibling */ + TransactionId btpo_xact; /* value of btpo.xact for use in recovery */ + /* xl_btree_metadata FOLLOWS IF XLOG_BTREE_DELETE_PAGE_META */ +} xl_btree_delete_page; + +#define SizeOfBtreeDeletePage (offsetof(xl_btree_delete_page, btpo_xact) + sizeof(TransactionId)) + + +/* + * This is what we need to know about marking an empty branch for deletion. + * The target identifies the tuple removed from the parent page (note that we + * remove this tuple's downlink and the *following* tuple's key). Note that + * the leaf page is empty, so we don't need to store its content --- it is + * just reinitialized during recovery using the rest of the fields. + * + * Backup Blk 0: leaf block + * Backup Blk 1: top parent + */ +typedef struct xl_btree_mark_page_halfdead +{ + OffsetNumber poffset; /* deleted tuple id in parent page */ + + /* information needed to recreate the leaf page: */ + BlockNumber leafblk; /* leaf block ultimately being deleted */ + BlockNumber leftblk; /* leaf block's left sibling, if any */ + BlockNumber rightblk; /* leaf block's right sibling */ + BlockNumber topparent; /* topmost internal page in the branch */ +} xl_btree_mark_page_halfdead; + +#define SizeOfBtreeMarkPageHalfDead (offsetof(xl_btree_mark_page_halfdead, topparent) + sizeof(BlockNumber)) + +/* + * This is what we need to know about deletion of a btree page. Note we do + * not store any content for the deleted page --- it is just rewritten as empty + * during recovery, apart from resetting the btpo.xact. + * + * Backup Blk 0: target block being deleted + * Backup Blk 1: target block's left sibling, if any + * Backup Blk 2: target block's right sibling + * Backup Blk 3: leaf block (if different from target) + * Backup Blk 4: metapage (if rightsib becomes new fast root) + */ +typedef struct xl_btree_unlink_page +{ + BlockNumber leftsib; /* target block's left sibling, if any */ + BlockNumber rightsib; /* target block's right sibling */ + + /* + * Information needed to recreate the leaf page, when target is an + * internal page. + */ + BlockNumber leafleftsib; + BlockNumber leafrightsib; + BlockNumber topparent; /* next child down in the branch */ + + TransactionId btpo_xact; /* value of btpo.xact for use in recovery */ + /* xl_btree_metadata FOLLOWS IF XLOG_BTREE_UNLINK_PAGE_META */ +} xl_btree_unlink_page; + +#define SizeOfBtreeUnlinkPage (offsetof(xl_btree_unlink_page, btpo_xact) + sizeof(TransactionId)) + +/* + * New root log record. There are zero tuples if this is to establish an + * empty root, or two if it is the result of splitting an old root. + * + * Note that although this implies rewriting the metadata page, we don't need + * an xl_btree_metadata record --- the rootblk and level are sufficient. + * + * Backup Blk 0: new root page (2 tuples as payload, if splitting old root) + * Backup Blk 1: metapage + */ +typedef struct xl_btree_newroot { + BlockNumber rootblk; /* location of new root (redundant with blk 0) */ + uint32 level; /* its tree level */ + /* 0 or 2 INDEX TUPLES FOLLOW AT END OF STRUCT */ +} xl_btree_newroot; + +#define SizeOfBtreeNewroot (offsetof(xl_btree_newroot, level) + sizeof(uint32)) + +/* + * INCLUDE B-Tree indexes have non-key attributes. These are extra + * attributes that may be returned by index-only scans, but do not influence + * the order of items in the index (formally, non-key attributes are not + * considered to be part of the key space). Non-key attributes are only + * present in leaf index tuples whose item pointers actually point to heap + * tuples. All other types of index tuples (collectively, "pivot" tuples) + * only have key attributes, since pivot tuples only ever need to represent + * how the key space is separated. In general, any B-Tree index that has + * more than one level (i.e. any index that does not just consist of a + * metapage and a single leaf root page) must have some number of pivot + * tuples, since pivot tuples are used for traversing the tree. + * + * We store the number of attributes present inside pivot tuples by abusing + * their item pointer offset field, since pivot tuples never need to store a + * real offset (downlinks only need to store a block number). The offset + * field only stores the number of attributes when the INDEX_ALT_TID_MASK + * bit is set (we never assume that pivot tuples must explicitly store the + * number of attributes, and currently do not bother storing the number of + * attributes unless indnkeyatts actually differs from indnatts). + * INDEX_ALT_TID_MASK is only used for pivot tuples at present, though it's + * possible that it will be used within non-pivot tuples in the future. Do + * not assume that a tuple with INDEX_ALT_TID_MASK set must be a pivot + * tuple. + * + * The 12 least significant offset bits are used to represent the number of + * attributes in INDEX_ALT_TID_MASK tuples, leaving 4 bits that are reserved + * for future use (BT_RESERVED_OFFSET_MASK bits). BT_N_KEYS_OFFSET_MASK should + * be large enough to store any number <= INDEX_MAX_KEYS. + */ +#define INDEX_ALT_TID_MASK INDEX_AM_RESERVED_BIT +#define BT_RESERVED_OFFSET_MASK 0xF000 +#define BT_N_KEYS_OFFSET_MASK 0x0FFF + +/* Get/set downlink block number */ +#define BTreeInnerTupleGetDownLink(itup) ItemPointerGetBlockNumberNoCheck(&((itup)->t_tid)) +#define BTreeInnerTupleSetDownLink(itup, blkno) ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)) + +/* + * Get/set leaf page highkey's link. During the second phase of deletion, the + * target leaf page's high key may point to an ancestor page (at all other + * times, the leaf level high key's link is not used). See the nbtree README + * for full details. + */ +#define BTreeTupleGetTopParent(itup) ItemPointerGetBlockNumberNoCheck(&((itup)->t_tid)) +#define BTreeTupleSetTopParent(itup, blkno) \ + do { \ + ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)); \ + BTreeTupleSetNAtts((itup), 0); \ + } while (0) + +/* + * Get/set number of attributes within B-tree index tuple. Asserts should be + * removed when BT_RESERVED_OFFSET_MASK bits will be used. + */ +#define BTreeTupleGetNAtts(itup, rel) \ + ((itup)->t_info & INDEX_ALT_TID_MASK \ + ? (AssertMacro((ItemPointerGetOffsetNumberNoCheck(&(itup)->t_tid) & BT_RESERVED_OFFSET_MASK) == 0), \ + ItemPointerGetOffsetNumberNoCheck(&(itup)->t_tid) & BT_N_KEYS_OFFSET_MASK) \ + : IndexRelationGetNumberOfAttributes(rel)) + +#define BTreeTupleSetNAtts(itup, n) \ + do { \ + (itup)->t_info |= INDEX_ALT_TID_MASK; \ + Assert(((n) & BT_RESERVED_OFFSET_MASK) == 0); \ + ItemPointerSetOffsetNumber(&(itup)->t_tid, (n) & BT_N_KEYS_OFFSET_MASK); \ + } while (0) + +/* + * Operator strategy numbers for B-tree have been moved to access/skey.h, + * because many places need to use them in ScanKeyInit() calls. + * + * The strategy numbers are chosen so that we can commute them by + * subtraction, thus: + */ +#define BTCommuteStrategyNumber(strat) (BTMaxStrategyNumber + 1 - (strat)) + +/* + * When a new operator class is declared, we require that the user + * supply us with an amproc procedure (BTORDER_PROC) for determining + * whether, for two keys a and b, a < b, a = b, or a > b. This routine + * must return < 0, 0, > 0, respectively, in these three cases. (It must + * not return INT_MIN, since we may negate the result before using it.) + * + * To facilitate accelerated sorting, an operator class may choose to + * offer a second procedure (BTSORTSUPPORT_PROC). For full details, see + * src/include/utils/sortsupport.h. + */ + +#define BTORDER_PROC 1 +#define BTSORTSUPPORT_PROC 2 + +/* + * We need to be able to tell the difference between read and write + * requests for pages, in order to do locking correctly. + */ + +#define BT_READ BUFFER_LOCK_SHARE +#define BT_WRITE BUFFER_LOCK_EXCLUSIVE + +/* + * BTStackData -- As we descend a tree, we push the (location, downlink) + * pairs from internal pages onto a private stack. If we split a + * leaf, we use this stack to walk back up the tree and insert data + * into parent pages (and possibly to split them, too). Lehman and + * Yao's update algorithm guarantees that under no circumstances can + * our private stack give us an irredeemably bad picture up the tree. + * Again, see the paper for details. + */ + +typedef struct BTStackData { + BlockNumber bts_blkno; + OffsetNumber bts_offset; + BlockNumber bts_btentry; + struct BTStackData* bts_parent; +} BTStackData; + +typedef BTStackData* BTStack; + +/* + * BTScanOpaqueData is the btree-private state needed for an indexscan. + * This consists of preprocessed scan keys (see _bt_preprocess_keys() for + * details of the preprocessing), information about the current location + * of the scan, and information about the marked location, if any. (We use + * BTScanPosData to represent the data needed for each of current and marked + * locations.) In addition we can remember some known-killed index entries + * that must be marked before we can move off the current page. + * + * Index scans work a page at a time: we pin and read-lock the page, identify + * all the matching items on the page and save them in BTScanPosData, then + * release the read-lock while returning the items to the caller for + * processing. This approach minimizes lock/unlock traffic. Note that we + * keep the pin on the index page until the caller is done with all the items + * (this is needed for VACUUM synchronization, see nbtree/README). When we + * are ready to step to the next page, if the caller has told us any of the + * items were killed, we re-lock the page to mark them killed, then unlock. + * Finally we drop the pin and step to the next page in the appropriate + * direction. + * + * If we are doing an index-only scan, we save the entire IndexTuple for each + * matched item, otherwise only its heap TID and offset. The IndexTuples go + * into a separate workspace array; each BTScanPosItem stores its tuple's + * offset within that array. + */ + +typedef struct BTScanPosItem { /* what we remember about each match */ + ItemPointerData heapTid; /* TID of referenced heap item */ + OffsetNumber indexOffset; /* index item's location within page */ + LocationIndex tupleOffset; /* IndexTuple's offset in workspace, if any */ + Oid partitionOid; /* partition table oid in workspace, if any */ +} BTScanPosItem; + +typedef struct BTScanPosData { + Buffer buf; /* if valid, the buffer is pinned */ + + BlockNumber nextPage; /* page's right link when we scanned it */ + + /* + * moreLeft and moreRight track whether we think there may be matching + * index entries to the left and right of the current page, respectively. + * We can clear the appropriate one of these flags when _bt_checkkeys() + * returns continuescan = false. + */ + bool moreLeft; + bool moreRight; + + /* + * If we are doing an index-only scan, nextTupleOffset is the first free + * location in the associated tuple storage workspace. + */ + int nextTupleOffset; + + /* + * The items array is always ordered in index order (ie, increasing + * indexoffset). When scanning backwards it is convenient to fill the + * array back-to-front, so we start at the last slot and fill downwards. + * Hence we need both a first-valid-entry and a last-valid-entry counter. + * itemIndex is a cursor showing which entry was last returned to caller. + */ + int firstItem; /* first valid index in items[] */ + int lastItem; /* last valid index in items[] */ + int itemIndex; /* current index in items[] */ + + BTScanPosItem items[MaxIndexTuplesPerPage]; /* MUST BE LAST */ +} BTScanPosData; + +typedef BTScanPosData* BTScanPos; + +#define BTScanPosIsValid(scanpos) BufferIsValid((scanpos).buf) + +/* We need one of these for each equality-type SK_SEARCHARRAY scan key */ +typedef struct BTArrayKeyInfo { + int scan_key; /* index of associated key in arrayKeyData */ + int cur_elem; /* index of current element in elem_values */ + int mark_elem; /* index of marked element in elem_values */ + int num_elems; /* number of elems in current array value */ + Datum* elem_values; /* array of num_elems Datums */ +} BTArrayKeyInfo; + +typedef struct BTScanOpaqueData { + /* these fields are set by _bt_preprocess_keys(): */ + bool qual_ok; /* false if qual can never be satisfied */ + int numberOfKeys; /* number of preprocessed scan keys */ + ScanKey keyData; /* array of preprocessed scan keys */ + + /* workspace for SK_SEARCHARRAY support */ + ScanKey arrayKeyData; /* modified copy of scan->keyData */ + int numArrayKeys; /* number of equality-type array keys (-1 if + * there are any unsatisfiable array keys) */ + BTArrayKeyInfo* arrayKeys; /* info about each equality-type array key */ + MemoryContext arrayContext; /* scan-lifespan context for array data */ + + /* info about killed items if any (killedItems is NULL if never used) */ + int* killedItems; /* currPos.items indexes of killed items */ + int numKilled; /* number of currently stored items */ + + /* + * If we are doing an index-only scan, these are the tuple storage + * workspaces for the currPos and markPos respectively. Each is of size + * BLCKSZ, so it can hold as much as a full page's worth of tuples. + */ + char* currTuples; /* tuple storage for currPos */ + char* markTuples; /* tuple storage for markPos */ + + /* + * If the marked position is on the same page as current position, we + * don't use markPos, but just keep the marked itemIndex in markItemIndex + * (all the rest of currPos is valid for the mark position). Hence, to + * determine if there is a mark, first look at markItemIndex, then at + * markPos. + */ + int markItemIndex; /* itemIndex, or -1 if not valid */ + + /* keep these last in struct for efficiency */ + BTScanPosData currPos; /* current position data */ + BTScanPosData markPos; /* marked position, if any */ +} BTScanOpaqueData; + +typedef BTScanOpaqueData* BTScanOpaque; + +/* + * We use some private sk_flags bits in preprocessed scan keys. We're allowed + * to use bits 16-31 (see skey.h). The uppermost bits are copied from the + * index's indoption[] array entry for the index attribute. + */ +#define SK_BT_REQFWD 0x00010000 /* required to continue forward scan */ +#define SK_BT_REQBKWD 0x00020000 /* required to continue backward scan */ +#define SK_BT_INDOPTION_SHIFT 24 /* must clear the above bits */ +#define SK_BT_DESC (INDOPTION_DESC << SK_BT_INDOPTION_SHIFT) +#define SK_BT_NULLS_FIRST (INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT) + +// BTPageState and BTWriteState are moved here from nbtsort.cpp +/* + * Status record for a btree page being built. We have one of these + * for each active tree level. + * + * The reason we need to store a copy of the minimum key is that we'll + * need to propagate it to the parent node when this page is linked + * into its parent. However, if the page is not a leaf page, the first + * entry on the page doesn't need to contain a key, so we will not have + * stored the key itself on the page. (You might think we could skip + * copying the minimum key on leaf pages, but actually we must have a + * writable copy anyway because we'll poke the page's address into it + * before passing it up to the parent...) + */ +typedef struct BTPageState { + Page btps_page; /* workspace for page building */ + BlockNumber btps_blkno; /* block # to write this page at */ + IndexTuple btps_minkey; /* copy of minimum key (first item) on page */ + OffsetNumber btps_lastoff; /* last item offset loaded */ + uint32 btps_level; /* tree level (0 = leaf) */ + Size btps_full; /* "full" if less than this much free space */ + struct BTPageState* btps_next; /* link to parent level, if any */ +} BTPageState; + +/* + * Overall status record for index writing phase. + */ +typedef struct BTWriteState { + Relation index; + bool btws_use_wal; /* dump pages to WAL? */ + BlockNumber btws_pages_alloced; /* # pages allocated */ + BlockNumber btws_pages_written; /* # pages written out */ + Page btws_zeropage; /* workspace for filling zeroes */ +} BTWriteState; + +typedef struct BTOrderedIndexListElement { + IndexTuple itup; + BlockNumber heapModifiedOffset; + IndexScanDesc indexScanDesc; +} BTOrderedIndexListElement; + +/* + * prototypes for functions in nbtree.c (external entry points for btree) + */ +extern Datum btbuild(PG_FUNCTION_ARGS); +extern Datum btbuildempty(PG_FUNCTION_ARGS); +extern Datum btinsert(PG_FUNCTION_ARGS); +extern Datum btbeginscan(PG_FUNCTION_ARGS); +extern Datum btgettuple(PG_FUNCTION_ARGS); +extern Datum btgetbitmap(PG_FUNCTION_ARGS); +extern Datum cbtreegetbitmap(PG_FUNCTION_ARGS); +extern Datum btrescan(PG_FUNCTION_ARGS); +extern Datum btendscan(PG_FUNCTION_ARGS); +extern Datum btmarkpos(PG_FUNCTION_ARGS); +extern Datum btrestrpos(PG_FUNCTION_ARGS); +extern Datum btbulkdelete(PG_FUNCTION_ARGS); +extern Datum btvacuumcleanup(PG_FUNCTION_ARGS); +extern Datum btcanreturn(PG_FUNCTION_ARGS); +extern Datum btoptions(PG_FUNCTION_ARGS); +/* + * this is the interface of merge 2 or more index for btree index + * we also have similar interfaces for other kind of indexes, like hash/gist/gin + * thought, we are not going to implement them right now. + */ +extern Datum btmerge(PG_FUNCTION_ARGS); + +/* + * prototypes for functions in nbtinsert.c + */ +extern bool _bt_doinsert(Relation rel, IndexTuple itup, IndexUniqueCheck checkUnique, Relation heapRel); +extern Buffer _bt_getstackbuf(Relation rel, BTStack stack); +extern void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf, BTStack stack, bool is_root, bool is_only); +extern void _bt_finish_split(Relation rel, Buffer bbuf, BTStack stack); +extern IndexTuple _bt_nonkey_truncate(Relation idxrel, IndexTuple olditup); + +/* + * prototypes for functions in nbtpage.c + */ +extern void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level); +extern Buffer _bt_getroot(Relation rel, int access); +extern Buffer _bt_gettrueroot(Relation rel); +extern void _bt_checkpage(Relation rel, Buffer buf); +extern Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access); +extern Buffer _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access); +extern void _bt_relbuf(Relation rel, Buffer buf); +extern void _bt_pageinit(Page page, Size size); +extern bool _bt_page_recyclable(Page page); +extern void _bt_delitems_delete(Relation rel, Buffer buf, OffsetNumber* itemnos, int nitems, Relation heapRel); +extern void _bt_delitems_vacuum( + Relation rel, Buffer buf, OffsetNumber* itemnos, int nitems, BlockNumber lastBlockVacuumed); +extern int _bt_pagedel(Relation rel, Buffer buf, BTStack stack); +extern void _bt_page_localupgrade(Page page); +/* + * prototypes for functions in nbtsearch.c + */ +extern BTStack _bt_search( + Relation rel, int keysz, ScanKey scankey, bool nextkey, Buffer* bufP, int access, bool needStack = true); +extern Buffer _bt_moveright(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey, bool forupdate, BTStack stack, int access); +extern OffsetNumber _bt_binsrch(Relation rel, Buffer buf, int keysz, ScanKey scankey, bool nextkey); +extern int32 _bt_compare(Relation rel, int keysz, ScanKey scankey, Page page, OffsetNumber offnum); +extern bool _bt_first(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_next(IndexScanDesc scan, ScanDirection dir); +extern Buffer _bt_get_endpoint(Relation rel, uint32 level, bool rightmost); +extern bool _bt_gettuple_internal(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_check_natts(const Relation index, Page page, OffsetNumber offnum); + +/* + * prototypes for functions in nbtutils.c + */ +extern ScanKey _bt_mkscankey(Relation rel, IndexTuple itup); +extern ScanKey _bt_mkscankey_nodata(Relation rel); +extern void _bt_freeskey(ScanKey skey); +extern void _bt_freestack(BTStack stack); +extern int _bt_sort_array_elements( + IndexScanDesc scan, ScanKey skey, bool reverse, Datum* elems, int nelems); +extern void _bt_preprocess_array_keys(IndexScanDesc scan); +extern void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir); +extern bool _bt_advance_array_keys(IndexScanDesc scan, ScanDirection dir); +extern void _bt_mark_array_keys(IndexScanDesc scan); +extern void _bt_restore_array_keys(IndexScanDesc scan); +extern void _bt_preprocess_keys(IndexScanDesc scan); +extern IndexTuple _bt_checkkeys( + IndexScanDesc scan, Page page, OffsetNumber offnum, ScanDirection dir, bool* continuescan); +extern void _bt_killitems(IndexScanDesc scan, bool haveLock); +extern BTCycleId _bt_vacuum_cycleid(Relation rel); +extern BTCycleId _bt_start_vacuum(Relation rel); +extern void _bt_end_vacuum(Relation rel); +extern void _bt_end_vacuum_callback(int code, Datum arg); +extern Size BTreeShmemSize(void); +extern void BTreeShmemInit(void); + +/* + * prototypes for functions in nbtsort.c + */ +typedef struct BTSpool BTSpool; /* opaque type known only within nbtsort.c */ + +/* Working state for btbuild and its callback */ +typedef struct { + bool isUnique; + bool haveDead; + Relation heapRel; + BTSpool* spool; + + /* + * spool2 is needed only when the index is an unique index. Dead tuples + * are put into spool2 instead of spool in order to avoid uniqueness + * check. + */ + BTSpool* spool2; + double indtuples; +} BTBuildState; + +extern BTSpool* _bt_spoolinit(Relation index, bool isunique, bool isdead, void* meminfo); +extern void _bt_spooldestroy(BTSpool* btspool); +extern void _bt_spool(BTSpool* btspool, ItemPointer self, Datum* values, const bool* isnull); +extern void _bt_leafbuild(BTSpool* btspool, BTSpool* spool2); +// these 4 functions are move here from nbtsearch.cpp(static functions) +extern void _bt_buildadd(BTWriteState* wstate, BTPageState* state, IndexTuple itup); +extern void _bt_uppershutdown(BTWriteState* wstate, BTPageState* state); +BTPageState* _bt_pagestate(BTWriteState* wstate, uint32 level); +extern bool _index_tuple_compare(TupleDesc tupdes, ScanKey indexScanKey, int keysz, IndexTuple itup, IndexTuple itup2); +extern List* insert_ordered_index(List* list, TupleDesc tupdes, ScanKey indexScanKey, int keysz, IndexTuple itup, + BlockNumber heapModifiedOffset, IndexScanDesc srcIdxRelScan); +/* + * prototypes for functions in nbtxlog.c + */ +extern void btree_redo(XLogReaderState* record); +extern void btree_desc(StringInfo buf, XLogReaderState* record); +extern void btree_xlog_startup(void); +extern void btree_xlog_cleanup(void); +extern bool btree_safe_restartpoint(void); +extern void* btree_get_incomplete_actions(); +extern void btree_clear_imcompleteAction(); +extern bool IsBtreeVacuum(const XLogReaderState* record); +extern void _bt_restore_page(Page page, char* from, int len); +extern void DumpBtreeDeleteInfo(XLogRecPtr lsn, OffsetNumber offsetList[], uint64 offsetNum); + +#endif /* NBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/obs/obs_am.h postgresql-hll-2.14/include/include/access/obs/obs_am.h --- postgresql-hll-2.14_old/include/include/access/obs/obs_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/obs/obs_am.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,148 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * obs_am.h + * obs access method definitions. + * + * + * IDENTIFICATION + * src/include/access/obs/obs_am.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OBS_AM_H +#define OBS_AM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "nodes/pg_list.h" +#include "storage/buffile.h" +#include "eSDKOBS.h" + +/* OBS operation types */ +typedef enum { + OBS_UNKNOWN, + OBS_READ, + OBS_WRITE, + /* + * ... + * More supported option types added here + */ +} OBSHandlerType; + +/* OBS operation options */ +#define OBS_TRANSPORT_ENCRYPT 0x0001 + +typedef struct ObsOptions { + Oid serverOid; + char* address; + bool encrypt; + char* access_key; + char* secret_access_key; + char* bucket; + char* prefix; + uint32_t chunksize; +} ObsOptions; + +typedef struct ObsCopyOptions { + bool encrypt; + uint32_t chunksize; + char* access_key; + char* secret_access_key; +} ObsCopyOptions; + +typedef struct OBSReadWriteHandler { + char* m_url; + char* m_hostname; + char* m_bucket; + /* char *m_prefix; =>m_object_info.key */ + + ObsOptions* m_obs_options; + OBSHandlerType m_type; + bool in_computing; + /* size_t m_offset; =>get_cond.start_byte */ + /* obs_bucket_context m_bucketCtx; =>m_option.bucket_options */ + + obs_options m_option; + obs_object_info m_object_info; + + union { + obs_get_conditions get_cond; + obs_put_properties put_cond; + /* + * S3ListParts + * S3ListVersions + * ... + * More OBS operation properties added here + */ + } properties; +} OBSReadWriteHandler; + +typedef struct list_service_data { + int headerPrinted; + int allDetails; + obs_status ret_status; +} list_service_data; + +extern void SetObsMemoryContext(MemoryContext mctx); +extern MemoryContext GetObsMemoryContext(void); +extern void UnSetObsMemoryContext(void); + +extern OBSReadWriteHandler *CreateObsReadWriteHandler(const char *object_url, OBSHandlerType type, + ObsCopyOptions *options); +extern OBSReadWriteHandler *CreateObsReadWriteHandlerForQuery(ObsOptions *options); +extern void ObsReadWriteHandlerSetType(OBSReadWriteHandler *handler, OBSHandlerType type); +extern void DestroyObsReadWriteHandler(OBSReadWriteHandler *handler, bool obsQueryType); + +/* ---------------- + * function prototypes for obs access method + * ---------------- + */ +/* in obs/obs_am.cpp */ +extern List *list_obs_bucket_objects(const char *uri, bool encrypt, const char *access_key, + const char *secret_access_key); +extern List *list_bucket_objects_analyze(const char *uri, bool encrypt, const char *access_key, + const char *secret_access_key); +extern List *list_bucket_objects_for_query(OBSReadWriteHandler *handler, const char *bucket, char *prefix); +extern int writeObsTempFile(OBSReadWriteHandler *handler, const char *bufferData, int64 dataSize); +extern size_t read_bucket_object(OBSReadWriteHandler *handler, char *output_buffer, uint32_t len); +extern size_t write_bucket_object(OBSReadWriteHandler *handler, BufFile *buffile, uint32_t total_len); +extern void release_object_list(List *object_list); +extern void FetchUrlProperties(const char *url, char **hostname, char **bucket, char **prefix); +extern void FetchUrlPropertiesForQuery(const char *folderName, char **bucket, char **prefix); +extern int deleteOBSObject(OBSReadWriteHandler *handler); + +/* + * Function: initOBSCacheObjet + * Description: This function is called only by postmastermain to initialize OBS CA Info + * and secret key used to encrypt OBS access key and secret access key. + * input: none + * output: none + */ +extern void initOBSCacheObject(); + +extern int find_Nth(const char* str, unsigned N, const char* find); + +extern void checkOBSServerValidity(char* addres, char* ak, char* sk, bool encrypt); + +ObsOptions* copyObsOptions(ObsOptions* from); + +void freeObsOptions(ObsOptions* obsOptions, bool freeUseIpsiFree); + +extern bool is_ip_address_format(const char * addr); +extern void encryptKeyString(char* keyStr, char destplainStr[], uint32 destplainLength); +extern void decryptKeyString(const char *keyStr, char destplainStr[], uint32 destplainLength, const char *obskey); + +#endif /* OBS_AM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/dispatcher.h postgresql-hll-2.14/include/include/access/parallel_recovery/dispatcher.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/dispatcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/dispatcher.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dispatcher.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/dispatcher.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_DISPATCHER_H +#define PARALLEL_RECOVERY_DISPATCHER_H + +#include "gs_thread.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/parallel_recovery/redo_item.h" +#include "access/parallel_recovery/page_redo.h" +#include "access/parallel_recovery/txn_redo.h" +#include "access/redo_statistic.h" + +namespace parallel_recovery { + +typedef struct LogDispatcher { + MemoryContext oldCtx; + PageRedoWorker** pageWorkers; /* Array of page redo workers. */ + uint32 pageWorkerCount; /* Number of page redo workers that are ready to work. */ + uint32 totalWorkerCount; /* Number of page redo workers started. */ + TxnRedoWorker* txnWorker; /* Txn redo worker. */ + RedoItem* freeHead; /* Head of freed-item list. */ + RedoItem* freeStateHead; + RedoItem* allocatedRedoItem; + int32 pendingCount; /* Number of records pending. */ + int32 pendingMax; /* The max. pending count per batch. */ + int exitCode; /* Thread exit code. */ + uint64 totalCostTime; + uint64 txnCostTime; /* txn cost time */ + uint64 pprCostTime; + uint32 maxItemNum; + uint32 curItemNum; + + uint32* chosedWorkerIds; + uint32 chosedWorkerCount; + uint32 readyWorkerCnt; + bool checkpointNeedFullSync; +} LogDispatcher; + +extern LogDispatcher* g_dispatcher; + +#ifdef ENABLE_MULTIPLE_NODES +const static bool SUPPORT_HOT_STANDBY = false; /* don't support consistency view */ +#else +const static bool SUPPORT_HOT_STANDBY = true; +#endif +const static bool SUPPORT_FPAGE_DISPATCH = true; /* support file dispatch if true, else support page dispatche */ + +const static uint64 OUTPUT_WAIT_COUNT = 0x7FFFFFF; +const static uint64 PRINT_ALL_WAIT_COUNT = 0x7FFFFFFFF; + + +void StartRecoveryWorkers(); + +/* RedoItem lifecycle. */ +void DispatchRedoRecordToFile(XLogReaderState* record, List* expectedTLIs, TimestampTz recordXTime); +void ProcessPendingRecords(bool fullSync = false); +void ProcessTrxnRecords(bool fullSync = false); +void FreeRedoItem(RedoItem* item); + +/* Dispatcher phases. */ +void SendRecoveryEndMarkToWorkersAndWaitForFinish(int code); + +/* Dispatcher states. */ +int GetDispatcherExitCode(); +bool DispatchPtrIsNull(); +uint32 GetPageWorkerCount(); +bool OnHotStandBy(); +PGPROC* StartupPidGetProc(ThreadId pid); + +/* Run-time aggregated page worker states. */ +bool IsRecoveryRestartPointSafeForWorkers(XLogRecPtr restartPoint); + +void UpdateStandbyState(HotStandbyState newState); + +/* Redo end state saved by each page worker. */ +void** GetXLogInvalidPagesFromWorkers(); + +/* Other utility functions. */ +uint32 GetWorkerId(const RelFileNode& node, BlockNumber block, ForkNumber forkNum); +bool XactWillRemoveRelFiles(XLogReaderState* record); +XLogReaderState* NewReaderState(XLogReaderState* readerState, bool bCopyState = false); +void FreeAllocatedRedoItem(); +void GetReplayedRecPtrFromWorkers(XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void DiagLogRedoRecord(XLogReaderState* record, const char* funcName); +List* CheckImcompleteAction(List* imcompleteActionList); +void SetPageWorkStateByThreadId(uint32 threadState); +RedoWaitInfo redo_get_io_event(int32 event_id); +void redo_get_wroker_statistic(uint32* realNum, RedoWorkerStatsData* worker, uint32 workerLen); +extern void redo_dump_all_stats(); +void WaitRedoWorkerIdle(); +void SendClearMarkToAllWorkers(); +extern void SetStartupBufferPinWaitBufId(int bufid); +extern void GetStartupBufferPinWaitBufId(int *bufids, uint32 len); +extern uint32 GetStartupBufferPinWaitBufLen(); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/page_redo.h postgresql-hll-2.14/include/include/access/parallel_recovery/page_redo.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/page_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/page_redo.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,219 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * page_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/page_redo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_PAGE_REDO_H +#define PARALLEL_RECOVERY_PAGE_REDO_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/parallel_recovery/redo_item.h" +#include "nodes/pg_list.h" +#include "storage/proc.h" + +#include "access/parallel_recovery/posix_semaphore.h" +#include "access/parallel_recovery/spsc_blocking_queue.h" + +namespace parallel_recovery { + + +static const uint32 PAGE_WORK_QUEUE_SIZE = 1024; + +static const uint32 PAGE_REDO_WORKER_APPLY_ITEM = 0; +static const uint32 PAGE_REDO_WORKER_SKIP_ITEM = 1; + +struct SafeRestartPoint { + SafeRestartPoint* next; + XLogRecPtr restartPoint; +}; + +struct PageRedoWorker { + /* + * The last successfully applied log record's end position + 1 as an + * atomic uint64. The type of a log record's position is XLogRecPtr. + * Here the position is stored as an uint64 so it can be read and + * written atomically. + */ + XLogRecPtr lastReplayedReadRecPtr; + XLogRecPtr lastReplayedEndRecPtr; +#if (!defined __x86_64__) && (!defined __aarch64__) + /* protects lastReplayedReadRecPtr and lastReplayedEndRecPtr */ + slock_t ptrLck; +#endif + PageRedoWorker* selfOrinAddr; + /* Worker id. */ + uint32 id; + /* Worker id. */ + uint32 originId; + int index; + /* Thread id */ + gs_thread_t tid; + /* The proc struct of this worker thread. */ + PGPROC* proc; + + /* --------------------------------------------- + * Initial context + * + * Global variable values at worker creation time. + */ + + /* Initial server mode from the dispatcher. */ + ServerMode initialServerMode; + /* Initial timeline ID from the dispatcher. */ + TimeLineID initialTimeLineID; + + /* --------------------------------------------- + * Redo item queue. + * + * Redo items are provided by the dispatcher and consumed by each + * worker. See AddPageRedoItem() for the use of the additional + * pending list. + */ + + /* The head of the pending item list. */ + RedoItem* pendingHead; + /* The tail of the pending item list. */ + RedoItem* pendingTail; + /* To-be-replayed log-record-list queue. */ + SPSCBlockingQueue* queue; + + /* --------------------------------------------- + * Safe restart point handling. + */ + + /* + * A list of safe recovery restart point seen by this worker. + * The restart points are listed in reverse LSN order to ease the + * lock-free implementation. + */ + SafeRestartPoint* safePointHead; + /* + * The last recovery restart point seen by the txn worker. Restart + * points before this is useless and can be removed. + */ + XLogRecPtr lastCheckedRestartPoint; + + /* --------------------------------------------- + * Per-worker run-time context + * + * States maintained by each individual page-redo worker during + * log replay. These are read by the txn-redo worker. + */ + /* --------------------------------------------- + * Global run-time context + * + * States maintained outside page-redo worker during log replay. + * Updates to these states must be synchronized to all page-redo workers. + */ + + /* + * Global standbyState set by the txn worker. + */ + HotStandbyState standbyState; + + char* DataDir; + + TransactionId RecentXmin; + /* --------------------------------------------- + * Redo end context + * + * Thread-local variable values saved after log replay has completed. + * These values are collected by each redo worker at redo end and + * are used by the dispatcher. + */ + + /* B-Tree incomplete actions. */ + void* btreeIncompleteActions; + /* XLog invalid pages. */ + void* xlogInvalidPages; + + /* --------------------------------------------- + * Phase barrier. + * + * A barrier for synchronizing the dispatcher and page redo worker + * between different phases. + */ + + /* Semaphore marking the completion of the current phase. */ + PosixSemaphore phaseMarker; + + uint32 statMulpageCnt; + uint64 statWaitReach; + uint64 statWaitReplay; + pg_atomic_uint32 readyStatus; + pg_atomic_uint32 skipItemFlg; + MemoryContext oldCtx; + int bufferPinWaitBufId; +}; + +extern THR_LOCAL PageRedoWorker* g_redoWorker; + +/* Worker lifecycle. */ +PageRedoWorker* StartPageRedoWorker(uint32 id); +void DestroyPageRedoWorker(PageRedoWorker* worker); + +/* Thread creation utility functions. */ +bool IsPageRedoWorkerProcess(int argc, char* argv[]); +void AdaptArgvForPageRedoWorker(char* argv[]); +void GetThreadNameIfPageRedoWorker(int argc, char* argv[], char** threadNamePtr); + +uint32 GetMyPageRedoWorkerOrignId(); +PGPROC* GetPageRedoWorkerProc(PageRedoWorker* worker); + +/* Worker main function. */ +void PageRedoWorkerMain(); + +/* Dispatcher phases. */ +bool SendPageRedoEndMark(PageRedoWorker* worker); +bool SendPageRedoClearMark(PageRedoWorker* worker); +void WaitPageRedoWorkerReachLastMark(PageRedoWorker* worker); + +/* Redo processing. */ +void AddPageRedoItem(PageRedoWorker* worker, RedoItem* item); +bool ProcessPendingPageRedoItems(PageRedoWorker* worker); + +/* Run-time worker states. */ +uint64 GetCompletedRecPtr(PageRedoWorker* worker); +bool IsRecoveryRestartPointSafe(PageRedoWorker* worker, XLogRecPtr restartPoint); +void SetWorkerRestartPoint(PageRedoWorker* worker, XLogRecPtr restartPoint); + +void UpdatePageRedoWorkerStandbyState(PageRedoWorker* worker, HotStandbyState newState); + +/* Redo end states. */ +void* GetBTreeIncompleteActions(PageRedoWorker* worker); +void ClearBTreeIncompleteActions(PageRedoWorker* worker); +void* GetXLogInvalidPages(PageRedoWorker* worker); +bool RedoWorkerIsIdle(PageRedoWorker* worker); +void PageRedoSetAffinity(uint32 id); + +void DumpPageRedoWorker(PageRedoWorker* worker); +void SetPageRedoWorkerIndex(int index); +void OnlyFreeRedoItem(RedoItem* item); +void SetCompletedReadEndPtr(PageRedoWorker* worker, XLogRecPtr readPtr, XLogRecPtr endPtr); +void GetCompletedReadEndPtr(PageRedoWorker* worker, XLogRecPtr *readPtr, XLogRecPtr *endPtr); +void UpdateRecordGlobals(RedoItem* item, HotStandbyState standbyState); +void redo_dump_worker_queue_info(); + +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/posix_semaphore.h postgresql-hll-2.14/include/include/access/parallel_recovery/posix_semaphore.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/posix_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/posix_semaphore.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * posix_semaphore.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/posix_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_POSIX_SEMAPHORE_H +#define PARALLEL_RECOVERY_POSIX_SEMAPHORE_H + +#include +namespace parallel_recovery { + +typedef struct PosixSemaphore { + sem_t semaphore; + bool initialized; +} PosixSemaphore; + +void PosixSemaphoreInit(PosixSemaphore* sem, unsigned int initValue); +void PosixSemaphoreDestroy(PosixSemaphore* sem); +void PosixSemaphoreWait(PosixSemaphore* sem); +void PosixSemaphorePost(PosixSemaphore* sem); +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/redo_item.h postgresql-hll-2.14/include/include/access/parallel_recovery/redo_item.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/redo_item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/redo_item.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,155 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_item.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/redo_item.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_REDO_ITEM_H +#define PARALLEL_RECOVERY_REDO_ITEM_H + +#include "access/xlogreader.h" +#include "datatype/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/atomic.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "access/parallel_recovery/posix_semaphore.h" +#include "replication/replicainternal.h" + + +namespace parallel_recovery { + + +typedef struct BTreeIncompleteAction { + RelFileNode node; + BlockNumber block; + bool is_root; +} BTreeIncompleteAction; + +typedef struct XLogInvalidPage { + RelFileNode node; + ForkNumber fork; + BlockNumber minBlock; + Oid dbid; +} XLogInvalidPage; + +typedef union ContextUpdateData { + BTreeIncompleteAction btree; + XLogInvalidPage xlog; +} ContextUpdateData; + +typedef enum ContextUpdateType { + BTREE_FORGET_SPLIT, + BTREE_FORGET_DELETE, + XLOG_FORGET_PAGES, + XLOG_FORGET_PAGES_DB +} ContextUpdateType; + +typedef void (*ContextUpdateFunc)(const ContextUpdateData* data); + +/* + * Btree's incomplete_actions and XLog's invalid_page_tab need special + * treatment. Both use log_xxx() and forget_xxx() functions to maintain + * inconsistent states during log replay. Each of the log_xxx() functions + * remembers an inconsistent condition, and each of the forget_xxx() + * functions removes some inconsistent conditions. Because the two + * variables are thread local, the key to make it work under parallel log + * replay is to make sure the log_xxx() and the forget_xxx() for matching + * conditions are called in the same thread so they can correctly cancel + * each other. A ContextUpdateOp can be used to send a request to call + * log_xxx() or forget_xxx() from one worker to another worker. The + * protocol is to set up the ContextUpdateOp during the redo function, and + * after the record has been replayed each of the other workers checks + * the ContextUpdateOp and calls the ContextUpdateFunc if it is the + * ContextUpdateOp's designatedWorker. See comments on incomplete_actions + * and invalid_page_tab for detailed descriptions. + */ +typedef struct ContextUpdateOp { + /* The type of the operation. */ + ContextUpdateType type; + /* The data for the operation. */ + ContextUpdateData data; + /* The function that performs the operation. */ + ContextUpdateFunc func; + /* The id of the worker who needs to perform the operation. */ + uint32 designatedWorker; + /* If the operation is valid. */ + bool inUse; +} ContextUpdateOp; + +typedef struct RedoItem { + /* Old version. */ + bool oldVersion; + bool sharewithtrxn; /* if ture when designatedWorker is trxn or all and need sync with pageworker */ + bool blockbytrxn; /* if ture when designatedWorker is pagerworker and need sync with trxn */ + bool imcheckpoint; + /* Number of workers sharing this item. */ + uint32 shareCount; + /* Id of the worker designated to apply this item. */ + uint32 designatedWorker; + /* The expected timelines for this record. */ + List* expectedTLIs; + /* The timestamp of the log record if it is a transaction record. */ + TimestampTz recordXTime; + /* Next item on each worker's list. */ + RedoItem** nextByWorker; + /* Next item on the free list. */ + RedoItem* freeNext; + /* Operation to update thread-local variables after replay. */ + ContextUpdateOp contextUpdateOp; + /* Number of workers holding a reference to this item. */ + pg_atomic_uint32 refCount; + /* If this item has been replayed. */ + pg_atomic_uint32 replayed; + /* A "deep" copy of the log record. */ + XLogReaderState record; + /* Used for really free */ + RedoItem* allocatedNext; + TimestampTz syncXLogReceiptTime; + int syncXLogReceiptSource; + TransactionId RecentXmin; + ServerMode syncServerMode; + pg_atomic_uint32 freed; +} RedoItem; + +static const int32 ANY_BLOCK_ID = -1; +static const uint32 ANY_WORKER = (uint32)-1; +static const uint32 TRXN_WORKER = (uint32)-2; +static const uint32 ALL_WORKER = (uint32)-3; + +RedoItem* CreateRedoItem(XLogReaderState* record, uint32 shareCount, uint32 designatedWorker, List* expectedTLIs, + TimestampTz recordXTime, bool buseoriginal); +RedoItem* CreateLSNMarker(XLogReaderState* record, List* expectedTLIs, bool buseoriginal = false); + +bool IsLSNMarker(const RedoItem* item); + +void ApplyRedoRecord(XLogReaderState* record, bool bOld); + +static inline RedoItem* GetRedoItemPtr(XLogReaderState* record) +{ + return (RedoItem*)(((char*)record) - offsetof(RedoItem, record)); +} + + +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/spsc_blocking_queue.h postgresql-hll-2.14/include/include/access/parallel_recovery/spsc_blocking_queue.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/spsc_blocking_queue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/spsc_blocking_queue.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * spsc_blocking_queue.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/spsc_blocking_queue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_SPSC_BLOCKING_QUEUE_H +#define PARALLEL_RECOVERY_SPSC_BLOCKING_QUEUE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/parallel_recovery/posix_semaphore.h" + +namespace parallel_recovery { +typedef void (*CallBackFunc)(); + +struct SPSCBlockingQueue { + pg_atomic_uint32 writeHead; /* Array index for the next write. */ + pg_atomic_uint32 readTail; /* Array index for the next read. */ + uint32 capacity; /* Queue capacity, must be power of 2. */ + uint32 mask; /* Bit mask for computing index. */ + pg_atomic_uint32 maxUsage; + pg_atomic_uint64 totalCnt; + CallBackFunc callBackFunc; + void* buffer[1]; /* Queue buffer, the actual size is capacity. */ +}; + +SPSCBlockingQueue *SPSCBlockingQueueCreate(uint32 capacity, CallBackFunc func = NULL); +void SPSCBlockingQueueDestroy(SPSCBlockingQueue* queue); + +bool SPSCBlockingQueuePut(SPSCBlockingQueue* queue, void* element); +void* SPSCBlockingQueueTake(SPSCBlockingQueue* queue); +bool SPSCBlockingQueueIsEmpty(SPSCBlockingQueue* queue); +void* SPSCBlockingQueueTop(SPSCBlockingQueue* queue); +void SPSCBlockingQueuePop(SPSCBlockingQueue* queue); +void DumpQueue(SPSCBlockingQueue* queue); +uint32 SPSCGetQueueCount(SPSCBlockingQueue* queue); +void* SPSCTimeseriesQueueTop(SPSCBlockingQueue* queue); +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/parallel_recovery/txn_redo.h postgresql-hll-2.14/include/include/access/parallel_recovery/txn_redo.h --- postgresql-hll-2.14_old/include/include/access/parallel_recovery/txn_redo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/parallel_recovery/txn_redo.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * txn_redo.h + * + * + * + * IDENTIFICATION + * src/include/access/parallel_recovery/txn_redo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARALLEL_RECOVERY_TXN_REDO_H +#define PARALLEL_RECOVERY_TXN_REDO_H + +#include "access/parallel_recovery/redo_item.h" +namespace parallel_recovery { + +typedef struct TxnRedoWorker TxnRedoWorker; + +TxnRedoWorker* StartTxnRedoWorker(); +void DestroyTxnRedoWorker(TxnRedoWorker* worker); + +void AddTxnRedoItem(TxnRedoWorker* worker, RedoItem* item); +void ApplyReadyTxnLogRecords(TxnRedoWorker* worker, bool forceAll); +void MoveTxnItemToApplyQueue(TxnRedoWorker* worker); +void DumpTxnWorker(TxnRedoWorker* txnWorker); +bool IsTxnWorkerIdle(TxnRedoWorker* worker); +void FreeTxnItem(); +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/printtup.h postgresql-hll-2.14/include/include/access/printtup.h --- postgresql-hll-2.14_old/include/include/access/printtup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/printtup.h 2020-12-12 17:06:43.139346645 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * printtup.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/printtup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRINTTUP_H +#define PRINTTUP_H + +#include "utils/portal.h" +#include "distributelayer/streamProducer.h" + +extern DestReceiver* printtup_create_DR(CommandDest dest); +extern DestReceiver* createStreamDestReceiver(CommandDest dest); +extern void SetStreamReceiverParams(DestReceiver* self, StreamProducer* arg, Portal portal); +extern void SetRemoteDestReceiverParams(DestReceiver* self, Portal portal); + +extern void SendRowDescriptionMessage(StringInfo buf, TupleDesc typeinfo, List* targetlist, int16* formats); + +extern void debugStartup(DestReceiver* self, int operation, TupleDesc typeinfo); +extern void debugtup(TupleTableSlot* slot, DestReceiver* self); + +/* XXX these are really in executor/spi.c */ +extern void spi_dest_startup(DestReceiver* self, int operation, TupleDesc typeinfo); +extern void spi_printtup(TupleTableSlot* slot, DestReceiver* self); + +extern void printBatch(VectorBatch* batch, DestReceiver* self); +extern void printtup(TupleTableSlot* slot, DestReceiver* self); +extern void printbatchStream(VectorBatch* batch, DestReceiver* self); +extern void printtupStream(TupleTableSlot* slot, DestReceiver* self); +extern void assembleStreamMessage(TupleTableSlot* slot, DestReceiver* self, StringInfo buf); +extern void assembleStreamBatchMessage(BatchCompressType ctype, VectorBatch* batch, StringInfo buf); + +typedef struct { /* Per-attribute information */ + Oid typoutput; /* Oid for the type's text output fn */ + Oid typsend; /* Oid for the type's binary output fn */ + bool typisvarlena; /* is it varlena (ie possibly toastable)? */ + int16 format; /* format code for this column */ + FmgrInfo finfo; /* Precomputed call info for output fn */ +} PrinttupAttrInfo; + +typedef struct { + DestReceiver pub; /* publicly-known function pointers */ + StringInfoData buf; /* output buffer */ + Portal portal; /* the Portal we are printing from */ + bool sendDescrip; /* send RowDescription at startup? */ + TupleDesc attrinfo; /* The attr info we are set up for */ + int nattrs; + PrinttupAttrInfo* myinfo; /* Cached info about each attr */ + int16* formats; /* format code for each column */ +} DR_printtup; + +typedef struct { + DestReceiver pub; /* publicly-known function pointers */ + StringInfoData buf; /* output buffer */ + Portal portal; /* the Portal we are printing from */ + bool sendDescrip; /* send RowDescription at startup? */ + TupleDesc attrinfo; /* The attr info we are set up for */ + int nattrs; + PrinttupAttrInfo* myinfo; /* Cached info about each attr */ + StreamProducer* arg; +} streamReceiver; + +#endif /* PRINTTUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/psort.h postgresql-hll-2.14/include/include/access/psort.h --- postgresql-hll-2.14_old/include/include/access/psort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/psort.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * psort.h + * + * + * + * IDENTIFICATION + * src/include/access/psort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PSORT_H +#define PSORT_H + +#include "fmgr.h" + +Datum psortbuild(PG_FUNCTION_ARGS); +Datum psortoptions(PG_FUNCTION_ARGS); +Datum psortgettuple(PG_FUNCTION_ARGS); +Datum psortgetbitmap(PG_FUNCTION_ARGS); +Datum psortcanreturn(PG_FUNCTION_ARGS); + +#endif /* PSORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/redo_common.h postgresql-hll-2.14/include/include/access/redo_common.h --- postgresql-hll-2.14_old/include/include/access/redo_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/redo_common.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,48 @@ +/* + * redo_common.h + * + * Utilities for replaying WAL records. + * + * PostgreSQL transaction log manager utility routines + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/redo_common.h + */ +#ifndef REDO_COMMON_H +#define REDO_COMMON_H + +#ifdef BUILD_ALONE + +#define pfree(pointer) free(pointer) +#define palloc(sz) malloc(sz) + +#define module_logging_is_on(a) false + +#define securec_check(errno, charList, ...) \ + { \ + if (unlikely(EOK != errno)) { \ + elog(ERROR, "%s : %d : securec check error.", __FILE__, __LINE__); \ + } \ + } + +#define START_CRIT_SECTION() +#define END_CRIT_SECTION() + +#define elog(...) +#define elog_finish(a, b, ...) +#define elog_start(a, b, c) +#define errstart(...) +#define ereport(...) +#define errfinish(a, ...) +#define errmodule(a) +#define errmsg(c, ...) +#define errcode(a) + +extern THR_LOCAL bool assert_enabled; + +#endif + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/access/redo_statistic.h postgresql-hll-2.14/include/include/access/redo_statistic.h --- postgresql-hll-2.14_old/include/include/access/redo_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/redo_statistic.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_statistic.h + * + * + * + * IDENTIFICATION + * src/include/access/redo_statistic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REDO_STATISTIC_H +#define REDO_STATISTIC_H + +#include "gs_thread.h" +#include "knl/knl_instance.h" +#include "pgstat.h" +#include "access/redo_statistic_msg.h" + +typedef Datum (*GetViewDataFunc)(); + +typedef struct RedoStatsViewObj { + char name[VIEW_NAME_SIZE]; + Oid data_type; + GetViewDataFunc get_data; +} RedoStatsViewObj; + +typedef enum RedoWorkerWaitSyncStats { + WAIT_SYNC_AP_REF = 0, /* ApplyMultiPageRecord refCount*/ + WAIT_SYNC_AP_REP, /* ApplyMultiPageRecord replayed*/ + WAIT_SYNC_AMPSH, /* ApplyMultiPageShareWithTrxnRecord */ + WAIT_SYNC_AMPSY, /* ApplyMultiPageSyncWithTrxnRecord */ + WAIT_SYNC_ARAS, /* ApplyReadyAllShareLogRecords */ + WAIT_SYNC_ARTS, /* ApplyReadyTxnShareLogRecords */ + WAIT_SYNC_GXR, /* GetXlogReader */ + WAIT_SYNC_NUM +} RedoWorkerWaitSyncStats; + +/* Redo statistics */ +typedef struct RedoWorkerStatsData { + uint32 id; /* Worker id. */ + uint32 queue_usage; /* queue usage */ + uint32 queue_max_usage; /* the max usage of queue */ + /* XLogRecPtr head_ptr; do not try to get head_ptr and tail_ptr, */ + /* XLogRecPtr tail_ptr; because the memory of redoItem maybe be freed already */ + uint64 redo_rec_count; +} RedoWorkerStatsData; + +extern const RedoStatsViewObj g_redoViewArr[REDO_VIEW_COL_SIZE]; + +extern void redo_fill_redo_event(); +extern void redo_refresh_stats(uint64 speed); +extern void redo_unlink_stats_file(); + +static const uint64 US_TRANSFER_TO_S = (1000000); +static const uint64 BYTES_TRANSFER_KBYTES = (1024); + +WaitEventIO redo_get_event_type_by_wait_type(uint32 type); +char* redo_get_name_by_wait_type(uint32 type); + + +#endif /* DOUBLE_WRITE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/redo_statistic_msg.h postgresql-hll-2.14/include/include/access/redo_statistic_msg.h --- postgresql-hll-2.14_old/include/include/access/redo_statistic_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/redo_statistic_msg.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * redo_statistic_msg.h + * + * + * + * IDENTIFICATION + * src/include/access/redo_statistic_msg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REDO_STATISTIC_MSG_H +#define REDO_STATISTIC_MSG_H +#include "access/multi_redo_settings.h" + + +const static uint32 REDO_WORKER_INFO_BUFFER_SIZE = 64 * (1 + MOST_FAST_RECOVERY_LIMIT); +const static uint32 VIEW_NAME_SIZE = 32; +const static uint32 REDO_VIEW_COL_SIZE = 23; + +typedef struct RedoWaitInfo { + int64 total_duration; + int64 counter; +} RedoWaitInfo; + +typedef enum RedoWaitStats { + WAIT_READ_XLOG = 0, + WAIT_READ_DATA, + WAIT_WRITE_DATA, + WAIT_PROCESS_PENDING, + WAIT_APPLY, + WAIT_REDO_NUM +} RedoWaitStats; + +/* Redo statistics */ +typedef struct RedoStatsData { + XLogRecPtr redo_start_ptr; + int64 redo_start_time; + int64 redo_done_time; + int64 curr_time; + XLogRecPtr min_recovery_point; + XLogRecPtr read_ptr; + XLogRecPtr last_replayed_read_ptr; + XLogRecPtr recovery_done_ptr; + RedoWaitInfo wait_info[WAIT_REDO_NUM]; + uint32 speed_according_seg; + XLogRecPtr local_max_lsn; + uint32 worker_info_len; + char worker_info[REDO_WORKER_INFO_BUFFER_SIZE]; +} RedoStatsData; + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/access/reloptions.h postgresql-hll-2.14/include/include/access/reloptions.h --- postgresql-hll-2.14_old/include/include/access/reloptions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/reloptions.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,277 @@ +/* ------------------------------------------------------------------------- + * + * reloptions.h + * Core support for relation and tablespace options (pg_class.reloptions + * and pg_tablespace.spcoptions) + * + * Note: the functions dealing with text-array reloptions values declare + * them as Datum, not ArrayType *, to avoid needing to include array.h + * into a lot of low-level code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/reloptions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELOPTIONS_H +#define RELOPTIONS_H + +#include "access/htup.h" +#include "nodes/pg_list.h" +#include "nodes/primnodes.h" + +/* types supported by reloptions */ +typedef enum relopt_type { + RELOPT_TYPE_BOOL, + RELOPT_TYPE_INT, + RELOPT_TYPE_INT64, + RELOPT_TYPE_REAL, + RELOPT_TYPE_STRING +} relopt_type; + +/* kinds supported by reloptions */ +typedef enum relopt_kind { + RELOPT_KIND_HEAP = (1 << 0), + RELOPT_KIND_TOAST = (1 << 1), + RELOPT_KIND_BTREE = (1 << 2), + RELOPT_KIND_HASH = (1 << 3), + RELOPT_KIND_GIN = (1 << 4), + RELOPT_KIND_GIST = (1 << 5), + RELOPT_KIND_ATTRIBUTE = (1 << 6), + RELOPT_KIND_TABLESPACE = (1 << 7), + RELOPT_KIND_SPGIST = (1 << 8), + RELOPT_KIND_VIEW = (1 << 9), + RELOPT_KIND_PSORT = (1 << 10), + RELOPT_KIND_ZHPARSER = (1 << 11), /* text search configuration options defined by zhparser */ + RELOPT_KIND_NPARSER = (1 << 12), /* text search configuration options defined by ngram */ + RELOPT_KIND_CBTREE = (1 << 13), + RELOPT_KIND_PPARSER = (1 << 14), /* text search configuration options defined by pound */ + /* if you add a new kind, make sure you update "last_default" too */ + RELOPT_KIND_LAST_DEFAULT = RELOPT_KIND_PPARSER, + /* some compilers treat enums as signed ints, so we can't use 1 << 31 */ + RELOPT_KIND_MAX = (1 << 30) +} relopt_kind; + +/* reloption namespaces allowed for heaps -- currently only TOAST */ +#define HEAP_RELOPT_NAMESPACES \ + { \ + "toast", NULL \ + } + +/* generic struct to hold shared data */ +typedef struct relopt_gen { + const char* name; /* must be first (used as list termination + * marker) */ + const char* desc; + bits32 kinds; + int namelen; + relopt_type type; +} relopt_gen; + +/* holds a parsed value */ +typedef struct relopt_value { + relopt_gen* gen; + bool isset; + union { + bool bool_val; + int int_val; + int64 int64_val; + double real_val; + char* string_val; /* allocated separately */ + } values; +} relopt_value; + +/* reloptions records for specific variable types */ +typedef struct relopt_bool { + relopt_gen gen; + bool default_val; +} relopt_bool; + +typedef struct relopt_int { + relopt_gen gen; + int default_val; + int min; + int max; +} relopt_int; + +typedef struct relopt_int64 { + relopt_gen gen; + int64 default_val; + int64 min; + int64 max; +} relopt_int64; + +typedef struct relopt_real { + relopt_gen gen; + double default_val; + double min; + double max; +} relopt_real; + +/* validation routines for strings */ +typedef void (*validate_string_relopt)(const char* value); + +typedef struct relopt_string { + relopt_gen gen; + int default_len; + bool default_isnull; + validate_string_relopt validate_cb; + char* default_val; +} relopt_string; + +/* This is the table datatype for fillRelOptions */ +typedef struct { + const char* optname; /* option's name */ + relopt_type opttype; /* option's datatype */ + int offset; /* offset of field in result struct */ +} relopt_parse_elt; + +/* + * The following are the table append modes currently supported. + * on: mark the table on-line scaleout mode, when it is set, later data write by append mode. + * off:close on-line scaleout mode, when it is set, later date write by normal way. + * refresh:refresh start_ctid and end_ctid. + * read_only:off-line scaleout mode, when it is set, operators on table are not allowed. + * dest:the scaleout table can drop hidden columns when it's set. + */ +#define APPEND_MODE_ON "on" +#define APPEND_MODE_OFF "off" +#define APPEND_MODE_REFRESH "refresh" +#define APPEND_MODE_READ_ONLY "read_only" +#define APPEND_MODE_DEST "dest" + +/* + * These macros exist for the convenience of amoptions writers (but consider + * using fillRelOptions, which is a lot simpler). Beware of multiple + * evaluation of arguments! + * + * The last argument in the HANDLE_*_RELOPTION macros allows the caller to + * determine whether the option was set (true), or its value acquired from + * defaults (false); it can be passed as (char *) NULL if the caller does not + * need this information. + * + * optname is the option name (a string), var is the variable + * on which the value should be stored (e.g. StdRdOptions->fillfactor), and + * option is a relopt_value pointer. + * + * The normal way to use this is to loop on the relopt_value array returned by + * parseRelOptions: + * for (i = 0; options[i].gen->name; i++) + * { + * if (HAVE_RELOPTION("fillfactor", options[i]) + * { + * HANDLE_INT_RELOPTION("fillfactor", rdopts->fillfactor, options[i], &isset); + * continue; + * } + * if (HAVE_RELOPTION("default_row_acl", options[i]) + * { + * ... + * } + * ... + * if (validate) + * ereport(ERROR, + * (errmsg("unknown option"))); + * } + * + * Note that this is more or less the same that fillRelOptions does, so only + * use this if you need to do something non-standard within some option's + * code block. + */ +#define HAVE_RELOPTION(optname, option) (pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0) + +#define HANDLE_INT_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.int_val; \ + else \ + var = ((relopt_int*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.bool_val; \ + else \ + var = ((relopt_bool*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +#define HANDLE_REAL_RELOPTION(optname, var, option, wasset) \ + do { \ + if (option.isset) \ + var = option.values.real_val; \ + else \ + var = ((relopt_real*)option.gen)->default_val; \ + (wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \ + } while (0) + +/* + * For use during amoptions: get the strlen of a string option + * (either default or the user defined value) + */ +#define GET_STRING_RELOPTION_LEN(option) \ + ((option).isset ? strlen((option).values.string_val) : ((relopt_string*)(option).gen)->default_len) + +#define GET_STRING_RELOPTION_DATA(option) \ + ((option).isset ? ((option).values.string_val) : ((relopt_string*)(option).gen)->default_val) + +/* + * For use by code reading options already parsed: get a pointer to the string + * value itself. "optstruct" is the StdRdOption struct or equivalent, "member" + * is the struct member corresponding to the string option + */ +#define GET_STRING_RELOPTION(optstruct, member) \ + ((optstruct)->member == 0 ? NULL : (char*)(optstruct) + (optstruct)->member) + +extern relopt_kind add_reloption_kind(void); +extern void add_bool_reloption(bits32 kinds, const char* name, const char* desc, bool default_val); +extern void add_int_reloption( + bits32 kinds, const char* name, const char* desc, int default_val, int min_val, int max_val); +extern void add_int64_reloption( + bits32 kinds, const char* name, const char* desc, int64 default_val, int64 min_val, int64 max_val); +extern void add_real_reloption( + bits32 kinds, const char* name, const char* desc, double default_val, double min_val, double max_val); +extern void add_string_reloption( + bits32 kinds, const char* name, const char* desc, const char* default_val, validate_string_relopt validator); + +extern Datum transformRelOptions(Datum old_options, List* def_list, const char* namspace, const char* const validnsps[], + bool ignore_oids, bool is_reset); +extern List* untransformRelOptions(Datum options); +extern bytea* extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions); +extern relopt_value* parseRelOptions(Datum options, bool validate, relopt_kind kind, int* numrelopts); +extern void* allocateReloptStruct(Size base, relopt_value* options, int numoptions); +extern void fillRelOptions(void* rdopts, Size basesize, relopt_value* options, int numoptions, bool validate, + const relopt_parse_elt* elems, int nelems); + +extern bytea* default_reloptions(Datum reloptions, bool validate, relopt_kind kind); +extern bytea* heap_reloptions(char relkind, Datum reloptions, bool validate); +extern bytea* index_reloptions(RegProcedure amoptions, Datum reloptions, bool validate); +extern bytea* attribute_reloptions(Datum reloptions, bool validate); +extern bytea* tablespace_reloptions(Datum reloptions, bool validate); +extern bytea* tsearch_config_reloptions(Datum tsoptions, bool validate, Oid prsoid, bool missing_ok); +extern void heaprel_set_compressing_modes(Relation rel, int16* modes); +extern int8 heaprel_get_compresslevel_from_modes(int16 modes); +extern int8 heaprel_get_compression_from_modes(int16 modes); + +extern void CheckGetServerIpAndPort(const char* Address, List** AddrList, bool IsCheck, int real_addr_max); +extern void CheckFoldernameOrFilenamesOrCfgPtah(const char* OptStr, char* OptType); +extern void CheckWaitCleanGpi(const char* value); + +extern void ForbidToSetOptionsForPSort(List* options); +extern void ForbidOutUsersToSetInnerOptions(List* user_options); +extern void ForbidToSetOptionsForAttribute(List* options); +extern void ForbidUserToSetUnsupportedOptions( + List* options, const char* optnames[], int numoptnames, const char* detail); +extern void ForbidToSetOptionsForColTbl(List* options); +extern void ForbidToSetOptionsForRowTbl(List* options); +extern void ForbidUserToSetDefinedOptions(List* options); +extern bool CheckRelOptionValue(Datum options, const char* opt_name); +extern void forbid_to_set_options_for_timeseries_tbl(List* options); +extern List* RemoveRelOption(List* options, const char* optName, bool* removed); +void RowTblCheckCompressionOption(List *options); +#endif /* RELOPTIONS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/access/relscan.h postgresql-hll-2.14/include/include/access/relscan.h --- postgresql-hll-2.14_old/include/include/access/relscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/relscan.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,161 @@ +/* ------------------------------------------------------------------------- + * + * relscan.h + * POSTGRES relation scan descriptor definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/relscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELSCAN_H +#define RELSCAN_H + +#include "access/genam.h" +#include "access/heapam.h" +#include "access/itup.h" +#include "access/tupdesc.h" + +#define PARALLEL_SCAN_GAP 100 + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ +#define IsValidScanDesc(sd) (sd != NULL) + +typedef struct HeapScanDescData { + TableScanDescData rs_base; /* AM independent part of the descriptor */ + + /* scan parameters */ + bool rs_allow_strat; /* allow or disallow use of access strategy */ + + /* scan current state */ + TupleDesc rs_tupdesc; /* heap tuple descriptor for rs_ctup */ + /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ + ItemPointerData rs_mctid; /* marked scan position, if any */ + + /* these fields only used in page-at-a-time mode and for bitmap scans */ + int rs_mindex; /* marked tuple's saved index */ + int dop; /* scan parallel degree */ + /* put decompressed tuple data into rs_ctbuf be careful , when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr + */ + HeapTupleData rs_ctup; /* current tuple in scan, if any */ + HeapTupleHeaderData rs_ctbuf_hdr; +} HeapScanDescData; + +#define SizeofHeapScanDescData (offsetof(HeapScanDescData, rs_ctbuf_hdr) + SizeofHeapTupleHeader) + +struct ScanState; + +/* + * The ScanDescData for hash-bucket table + */ +typedef struct HBktTblScanDescData { + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; + + struct ScanState* scanState; + List* hBktList; /* hash bucket list that used to scan */ + int curr_slot; + Relation currBktRel; + TableScanDesc currBktScan; +} HBktTblScanDescData; + +typedef struct HBktTblScanDescData* HBktTblScanDesc; + +struct IndexFetchTableData; +/* + * We use the same IndexScanDescData structure for both amgettuple-based + * and amgetbitmap-based index scans. Some fields are only relevant in + * amgettuple-based scans. + */ +typedef struct IndexScanDescData { + /* scan parameters */ + // !! heapRelation MUST BE FIRST MEMBER !! + Relation heapRelation; /* heap relation descriptor, or NULL */ + + Relation indexRelation; /* index relation descriptor */ + GPIScanDesc xs_gpi_scan; /* global partition index scan use information */ + Snapshot xs_snapshot; /* snapshot to see */ + int numberOfKeys; /* number of index qualifier conditions */ + int numberOfOrderBys; /* number of ordering operators */ + ScanKey keyData; /* array of index qualifier descriptors */ + ScanKey orderByData; /* array of ordering op descriptors */ + bool xs_want_itup; /* caller requests index tuples */ + bool xs_want_ext_oid; /* global partition index need partition oid */ + + /* signaling to index AM about killing index tuples */ + bool kill_prior_tuple; /* last-returned tuple is dead */ + bool ignore_killed_tuples; /* do not return killed entries */ + bool xactStartedInRecovery; /* prevents killing/seeing killed + * tuples */ + + /* index access method's private state */ + void* opaque; /* access-method-specific info */ + + /* in an index-only scan, this is valid after a successful amgettuple */ + IndexTuple xs_itup; /* index tuple returned by AM */ + TupleDesc xs_itupdesc; /* rowtype descriptor of xs_itup */ + + /* xs_ctup/xs_cbuf/xs_recheck are valid after a successful index_getnext */ + HeapTupleData xs_ctup; /* current heap tuple, if any */ + Buffer xs_cbuf; /* current heap buffer in scan, if any */ + /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */ + bool xs_recheck; /* T means scan keys must be rechecked */ + + /* state data for traversing HOT chains in index_getnext */ + bool xs_continue_hot; /* T if must keep walking HOT chain */ + IndexFetchTableData *xs_heapfetch; + /* put decompressed heap tuple data into xs_ctbuf_hdr be careful! when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr + */ + HeapTupleHeaderData xs_ctbuf_hdr; + /* DO NOT add any other members here. xs_ctbuf_hdr must be the last one. */ +} IndexScanDescData; + +#define SizeofIndexScanDescData (offsetof(IndexScanDescData, xs_ctbuf_hdr) + SizeofHeapTupleHeader) + +/* Get partition heap oid for bitmap index scan */ +#define IndexScanGetPartHeapOid(scan) \ + ((scan)->indexRelation != NULL \ + ? (RelationIsPartition((scan)->indexRelation) ? (scan)->indexRelation->rd_partHeapOid : InvalidOid) \ + : InvalidOid) + +/* + * When the global partition index is used for index scanning, + * checks whether the partition table needs to be + * switched each time an indextuple is obtained. + */ +#define IndexScanNeedSwitchPartRel(scan) \ + ((scan)->xs_want_ext_oid && GPIScanCheckPartOid((scan)->xs_gpi_scan, (scan)->heapRelation->rd_id)) + +typedef struct HBktIdxScanDescData { + // !! rs_rd MUST BE FIRST MEMBER !! + Relation rs_rd; /* heap relation descriptor */ + + Relation idx_rd; /* index relation descriptor */ + struct ScanState* scanState; + List* hBktList; + int curr_slot; + Relation currBktHeapRel; + Relation currBktIdxRel; + IndexScanDescData* currBktIdxScan; +} HBktIdxScanDescData; + +typedef HBktIdxScanDescData* HBktIdxScanDesc; + +/* Struct for heap-or-index scans of system tables */ +typedef struct SysScanDescData { + Relation heap_rel; /* catalog being scanned */ + Relation irel; /* NULL if doing heap scan */ + HeapScanDesc scan; /* only valid in heap-scan case */ + IndexScanDesc iscan; /* only valid in index-scan case */ +} SysScanDescData; + +#endif /* RELSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/rewriteheap.h postgresql-hll-2.14/include/include/access/rewriteheap.h --- postgresql-hll-2.14_old/include/include/access/rewriteheap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/rewriteheap.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * rewriteheap.h + * Declarations for heap rewrite support functions + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/access/rewriteheap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITE_HEAP_H +#define REWRITE_HEAP_H + +#include "access/htup.h" +#include "storage/itemptr.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +/* struct definition is private to rewriteheap.c */ +typedef struct RewriteStateData* RewriteState; + +extern RewriteState begin_heap_rewrite( + Relation OldHeap, Relation NewHeap, TransactionId OldestXmin, TransactionId FreezeXid, bool use_wal); +extern void end_heap_rewrite(RewriteState state); +extern void rewrite_heap_tuple(RewriteState state, HeapTuple oldTuple, HeapTuple newTuple); +extern bool rewrite_heap_dead_tuple(RewriteState state, HeapTuple oldTuple); + +// private memory context must be used for forming new tuples and caching them +// +extern MemoryContext get_heap_rewrite_memcxt(RewriteState state); +extern bool use_heap_rewrite_memcxt(RewriteState state); +extern void RewriteAndCompressTup(RewriteState state, HeapTuple old_tuple, HeapTuple new_tuple); +/* + * On-Disk data format for an individual logical rewrite mapping. + */ +typedef struct LogicalRewriteMappingData { + RelFileNode old_node; + RelFileNode new_node; + ItemPointerData old_tid; + ItemPointerData new_tid; +} LogicalRewriteMappingData; + +/* --- + * The filename consists out of the following, dash separated, + * components: + * 1) database oid or InvalidOid for shared relations + * 2) the oid of the relation + * 3) xid we are mapping for + * 4) upper 32bit of the LSN at which a rewrite started + * 5) lower 32bit of the LSN at which a rewrite started + * 6) xid of the xact performing the mapping + * --- + */ +#define LOGICAL_REWRITE_FORMAT "map-%x-%x-%X_%X-%lx-%lx" +void CheckPointLogicalRewriteHeap(void); + +#endif /* REWRITE_HEAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/rmgr.h postgresql-hll-2.14/include/include/access/rmgr.h --- postgresql-hll-2.14_old/include/include/access/rmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/rmgr.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,31 @@ +/* + * rmgr.h + * + * Resource managers definition + * + * src/include/access/rmgr.h + */ +#ifndef RMGR_H +#define RMGR_H + +typedef uint8 RmgrId; + +/* + * Built-in resource managers + * + * The actual numerical values for each rmgr ID are defined by the order + * of entries in rmgrlist.h. + * + * Note: RM_MAX_ID must fit in RmgrId; widening that type will affect the XLOG + * file format. + */ +#define PG_RMGR(symname, name, redo, parse, startup, cleanup, restartpoint) symname, + +typedef enum RmgrIds { +#include "access/rmgrlist.h" + RM_NEXT_ID +} RmgrIds; + +#undef PG_RMGR +#define RM_MAX_ID (RM_NEXT_ID - 1) +#endif /* RMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/rmgrlist.h postgresql-hll-2.14/include/include/access/rmgrlist.h --- postgresql-hll-2.14_old/include/include/access/rmgrlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/rmgrlist.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,64 @@ +/* --------------------------------------------------------------------------------------- + * + * rmgrlist.h + * + * + * The resource manager list is kept in its own source file for possible + * use by automatic tools. The exact representation of a rmgr is determined + * by the PG_RMGR macro, which is not defined in this file; it can be + * defined by the caller for special purposes. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/rmgrlist.h + * + * --------------------------------------------------------------------------------------- + */ + +/* there is deliberately not an #ifndef RMGRLIST_H here + * The header file needs to be repeated in the rmgrdesc.cpp package for array initialization. + * An #ifndef RMGRLIST_H cannot be added. + */ + +/* + * List of resource manager entries. Note that order of entries defines the + * numerical values of each rmgr's ID, which is stored in WAL records. New + * entries should be added at the end, to avoid changing IDs of existing + * entries. + * + * Changes to this list possibly need an XLOG_PAGE_MAGIC bump. + */ + +/* symbol name, textual name, redo, desc, identify, startup, cleanup */ +PG_RMGR(RM_XLOG_ID, "XLOG", xlog_redo, xlog_desc, NULL, NULL, NULL) +PG_RMGR(RM_XACT_ID, "Transaction", xact_redo, xact_desc, NULL, NULL, NULL) +PG_RMGR(RM_SMGR_ID, "Storage", smgr_redo, smgr_desc, NULL, NULL, NULL) +PG_RMGR(RM_CLOG_ID, "CLOG", clog_redo, clog_desc, NULL, NULL, NULL) +PG_RMGR(RM_DBASE_ID, "Database", dbase_redo, dbase_desc, NULL, NULL, NULL) +PG_RMGR(RM_TBLSPC_ID, "Tablespace", tblspc_redo, tblspc_desc, NULL, NULL, NULL) +PG_RMGR(RM_MULTIXACT_ID, "MultiXact", multixact_redo, multixact_desc, NULL, NULL, NULL) +PG_RMGR(RM_RELMAP_ID, "RelMap", relmap_redo, relmap_desc, NULL, NULL, NULL) +#ifndef ENABLE_MULTIPLE_NODES +PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, StandbyXlogStartup, StandbyXlogCleanup, StandbySafeRestartpoint) +#else +PG_RMGR(RM_STANDBY_ID, "Standby", standby_redo, standby_desc, NULL, NULL, NULL) +#endif +PG_RMGR(RM_HEAP2_ID, "Heap2", heap2_redo, heap2_desc, NULL, NULL, NULL) +PG_RMGR(RM_HEAP_ID, "Heap", heap_redo, heap_desc, NULL, NULL, NULL) +PG_RMGR(RM_BTREE_ID, "Btree", btree_redo, btree_desc, btree_xlog_startup, btree_xlog_cleanup, btree_safe_restartpoint) +PG_RMGR(RM_HASH_ID, "Hash", hash_redo, hash_desc, NULL, NULL, NULL) +PG_RMGR(RM_GIN_ID, "Gin", gin_redo, gin_desc, gin_xlog_startup, gin_xlog_cleanup, NULL) +PG_RMGR(RM_GIST_ID, "Gist", gist_redo, gist_desc, gist_xlog_startup, gist_xlog_cleanup, NULL) +PG_RMGR(RM_SEQ_ID, "Sequence", seq_redo, seq_desc, NULL, NULL, NULL) +PG_RMGR(RM_SPGIST_ID, "SPGist", spg_redo, spg_desc, spg_xlog_startup, spg_xlog_cleanup, NULL) +PG_RMGR(RM_SLOT_ID, "Slot", slot_redo, slot_desc, NULL, NULL, NULL) +PG_RMGR(RM_HEAP3_ID, "Heap3", heap3_redo, heap3_desc, NULL, NULL, NULL) +#ifdef ENABLE_MULTIPLE_NODES +PG_RMGR(RM_BARRIER_ID, "Barrier", barrier_redo, barrier_desc, NULL, NULL, NULL) +#endif +#ifdef ENABLE_MOT +PG_RMGR(RM_MOT_ID, "MOT", MOTRedo, MOTDesc, NULL, NULL, NULL) +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/sdir.h postgresql-hll-2.14/include/include/access/sdir.h --- postgresql-hll-2.14_old/include/include/access/sdir.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/sdir.h 2020-12-12 17:06:43.140346658 +0800 @@ -0,0 +1,52 @@ +/* ------------------------------------------------------------------------- + * + * sdir.h + * POSTGRES scan direction definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/sdir.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SDIR_H +#define SDIR_H + +/* + * ScanDirection was an int8 for no apparent reason. I kept the original + * values because I'm not sure if I'll break anything otherwise. -ay 2/95 + */ +typedef enum ScanDirection { + BackwardScanDirection = -1, + NoMovementScanDirection = 0, + ForwardScanDirection = 1 +} ScanDirection; + +/* + * ScanDirectionIsValid + * True iff scan direction is valid. + */ +#define ScanDirectionIsValid(direction) \ + ((bool)(BackwardScanDirection <= (direction) && (direction) <= ForwardScanDirection)) + +/* + * ScanDirectionIsBackward + * True iff scan direction is backward. + */ +#define ScanDirectionIsBackward(direction) ((bool)((direction) == BackwardScanDirection)) + +/* + * ScanDirectionIsNoMovement + * True iff scan direction indicates no movement. + */ +#define ScanDirectionIsNoMovement(direction) ((bool)((direction) == NoMovementScanDirection)) + +/* + * ScanDirectionIsForward + * True iff scan direction is forward. + */ +#define ScanDirectionIsForward(direction) ((bool)((direction) == ForwardScanDirection)) + +#endif /* SDIR_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/skey.h postgresql-hll-2.14/include/include/access/skey.h --- postgresql-hll-2.14_old/include/include/access/skey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/skey.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,159 @@ +/* ------------------------------------------------------------------------- + * + * skey.h + * POSTGRES scan key definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/skey.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SKEY_H +#define SKEY_H + +#include "access/attnum.h" +#include "fmgr.h" + +/* + * Strategy numbers identify the semantics that particular operators have + * with respect to particular operator classes. In some cases a strategy + * subtype (an OID) is used as further information. + */ +typedef uint16 StrategyNumber; + +#define InvalidStrategy ((StrategyNumber)0) + +/* + * We define the strategy numbers for B-tree indexes here, to avoid having + * to import access/nbtree.h into a lot of places that shouldn't need it. + */ +#define BTLessStrategyNumber 1 +#define BTLessEqualStrategyNumber 2 +#define BTEqualStrategyNumber 3 +#define BTGreaterEqualStrategyNumber 4 +#define BTGreaterStrategyNumber 5 + +#define BTMaxStrategyNumber 5 + +#ifndef MADLIB +static_assert(BTMaxStrategyNumber == 5, "Strategy Number is not matched"); +#endif + +/* + * A ScanKey represents the application of a comparison operator between + * a table or index column and a constant. When it's part of an array of + * ScanKeys, the comparison conditions are implicitly ANDed. The index + * column is the left argument of the operator, if it's a binary operator. + * (The data structure can support unary indexable operators too; in that + * case sk_argument would go unused. This is not currently implemented.) + * + * For an index scan, sk_strategy and sk_subtype must be set correctly for + * the operator. When using a ScanKey in a heap scan, these fields are not + * used and may be set to InvalidStrategy/InvalidOid. + * + * If the operator is collation-sensitive, sk_collation must be set + * correctly as well. + * + * A ScanKey can also represent a ScalarArrayOpExpr, that is a condition + * "column op ANY(ARRAY[...])". This is signaled by the SK_SEARCHARRAY + * flag bit. The sk_argument is not a value of the operator's right-hand + * argument type, but rather an array of such values, and the per-element + * comparisons are to be ORed together. + * + * A ScanKey can also represent a condition "column IS NULL" or "column + * IS NOT NULL"; these cases are signaled by the SK_SEARCHNULL and + * SK_SEARCHNOTNULL flag bits respectively. The argument is always NULL, + * and the sk_strategy, sk_subtype, sk_collation, and sk_func fields are + * not used (unless set by the index AM). + * + * SK_SEARCHARRAY, SK_SEARCHNULL and SK_SEARCHNOTNULL are supported only + * for index scans, not heap scans; and not all index AMs support them, + * only those that set amsearcharray or amsearchnulls respectively. + * + * A ScanKey can also represent an ordering operator invocation, that is + * an ordering requirement "ORDER BY indexedcol op constant". This looks + * the same as a comparison operator, except that the operator doesn't + * (usually) yield boolean. We mark such ScanKeys with SK_ORDER_BY. + * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. + * + * Note: in some places, ScanKeys are used as a convenient representation + * for the invocation of an access method support procedure. In this case + * sk_strategy/sk_subtype are not meaningful (but sk_collation can be); and + * sk_func may refer to a function that returns something other than boolean. + */ +typedef struct ScanKeyData { + uint32 sk_flags; /* flags, see below */ + AttrNumber sk_attno; /* table or index column number */ + StrategyNumber sk_strategy; /* operator strategy number */ + Oid sk_subtype; /* strategy subtype */ + Oid sk_collation; /* collation to use, if needed */ + FmgrInfo sk_func; /* lookup info for function to call */ + Datum sk_argument; /* data to compare */ +} ScanKeyData; + +typedef ScanKeyData* ScanKey; + +/* + * About row comparisons: + * + * The ScanKey data structure also supports row comparisons, that is ordered + * tuple comparisons like (x, y) > (c1, c2), having the SQL-spec semantics + * "x > c1 OR (x = c1 AND y > c2)". Note that this is currently only + * implemented for btree index searches, not for heapscans or any other index + * type. A row comparison is represented by a "header" ScanKey entry plus + * a separate array of ScanKeys, one for each column of the row comparison. + * The header entry has these properties: + * sk_flags = SK_ROW_HEADER + * sk_attno = index column number for leading column of row comparison + * sk_strategy = btree strategy code for semantics of row comparison + * (ie, < <= > or >=) + * sk_subtype, sk_collation, sk_func: not used + * sk_argument: pointer to subsidiary ScanKey array + * If the header is part of a ScanKey array that's sorted by attno, it + * must be sorted according to the leading column number. + * + * The subsidiary ScanKey array appears in logical column order of the row + * comparison, which may be different from index column order. The array + * elements are like a normal ScanKey array except that: + * sk_flags must include SK_ROW_MEMBER, plus SK_ROW_END in the last + * element (needed since row header does not include a count) + * sk_func points to the btree comparison support function for the + * opclass, NOT the operator's implementation function. + * sk_strategy must be the same in all elements of the subsidiary array, + * that is, the same as in the header entry. + * SK_SEARCHARRAY, SK_SEARCHNULL, SK_SEARCHNOTNULL cannot be used here. + */ + +/* + * ScanKeyData sk_flags + * + * sk_flags bits 0-15 are reserved for system-wide use (symbols for those + * bits should be defined here). Bits 16-31 are reserved for use within + * individual index access methods. + */ +#define SK_ISNULL 0x0001 /* sk_argument is NULL */ +#define SK_UNARY 0x0002 /* unary operator (not supported!) */ +#define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */ +#define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */ +#define SK_ROW_END 0x0010 /* last row comparison member */ +#define SK_SEARCHARRAY 0x0020 /* scankey represents ScalarArrayOp */ +#define SK_SEARCHNULL 0x0040 /* scankey represents "col IS NULL" */ +#define SK_SEARCHNOTNULL \ + 0x0080 /* scankey represents "col IS NOT \ + * NULL" */ +#define SK_ORDER_BY 0x0100 /* scankey is for ORDER BY op */ + +/* + * prototypes for functions in access/common/scankey.c + */ +extern void ScanKeyInit( + ScanKey entry, AttrNumber attribute_number, StrategyNumber strategy, RegProcedure procedure, Datum argument); +extern void ScanKeyEntryInitialize(ScanKey entry, uint32 flags, AttrNumber attribute_number, StrategyNumber strategy, + Oid subtype, Oid collation, RegProcedure procedure, Datum argument); +extern void ScanKeyEntryInitializeWithInfo(ScanKey entry, uint32 flags, AttrNumber attribute_number, + StrategyNumber strategy, Oid subtype, Oid collation, FmgrInfo* finfo, Datum argument); + +#endif /* SKEY_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/slru.h postgresql-hll-2.14/include/include/access/slru.h --- postgresql-hll-2.14_old/include/include/access/slru.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/slru.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,175 @@ +/* ------------------------------------------------------------------------- + * + * slru.h + * Simple LRU buffering for transaction status logfiles + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/slru.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SLRU_H +#define SLRU_H + +#include "access/xlogdefs.h" +#include "storage/lwlock.h" + +/* + * Define SLRU segment size. A page is the same BLCKSZ as is used everywhere + * else in Postgres. The segment size can be chosen somewhat arbitrarily; + * we make it 2048 pages by default, or 16Mb, i.e. 64M transactions for CLOG + * or 2M transactions for SUBTRANS. + * + * Note: slru.c currently assumes that segment file names will be twelve hex + * digits. This sets a lower bound on the segment size ( 4M transactions + * for 64-bit TransactionIds). + */ +#define SLRU_PAGES_PER_SEGMENT 2048 + +/* Maximum length of an SLRU name */ +#define SLRU_MAX_NAME_LENGTH 64 + +/* + * Page status codes. Note that these do not include the "dirty" bit. + * page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states; + * in the latter case it implies that the page has been re-dirtied since + * the write started. + */ +typedef enum { + SLRU_PAGE_EMPTY, /* buffer is not in use */ + SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */ + SLRU_PAGE_VALID, /* page is valid and not being written */ + SLRU_PAGE_WRITE_IN_PROGRESS, /* page is being written out */ +} SlruPageStatus; + +/* Saved info for SlruReportIOError */ +typedef enum { + SLRU_OPEN_FAILED, + SLRU_SEEK_FAILED, + SLRU_READ_FAILED, + SLRU_WRITE_FAILED, + SLRU_FSYNC_FAILED, + SLRU_CLOSE_FAILED, + SLRU_MAX_FAILED // used to initialize slru_errcause +} SlruErrorCause; + +/* + * Shared-memory state + */ +typedef struct SlruSharedData { + LWLock* control_lock; + + /* Number of buffers managed by this SLRU structure */ + int num_slots; + + /* + * Arrays holding info for each buffer slot. Page number is undefined + * when status is EMPTY, as is page_lru_count. + */ + char** page_buffer; + SlruPageStatus* page_status; + bool* page_dirty; + int64* page_number; + int* page_lru_count; + LWLock** buffer_locks; + + /* + * Optional array of WAL flush LSNs associated with entries in the SLRU + * pages. If not zero/NULL, we must flush WAL before writing pages (true + * for pg_clog, false for multixact, pg_subtrans, pg_notify). group_lsn[] + * has lsn_groups_per_page entries per buffer slot, each containing the + * highest LSN known for a contiguous group of SLRU entries on that slot's + * page. + */ + XLogRecPtr* group_lsn; + int lsn_groups_per_page; + + /* ---------- + * We mark a page "most recently used" by setting + * page_lru_count[slotno] = ++cur_lru_count; + * The oldest page is therefore the one with the highest value of + * cur_lru_count - page_lru_count[slotno] + * The counts will eventually wrap around, but this calculation still + * works as long as no page's age exceeds INT_MAX counts. + * ---------- + */ + int cur_lru_count; + + /* + * latest_page_number is the page number of the current end of the log in PG, + * this is not critical data, since we use it only to avoid swapping out + * the latest page. But not in MPPDB. Older MPPDB version use it to keep the + * latest active page. The latest active page is same as the current end page + * of the log in PG, but keep in mind that these two might be different in MPPDB + * as the larger xid might occur in datanode before minor xid. + */ + int64 latest_page_number; + + /* + * In StartupCLOG or TrimCLOG during recovery, latest_page_number is determined + * by the computed ShmemVariableCache->nextXid after replaying all xlog records. + * If ShmemVariableCache->nextXid happens to be the first xid of a new clog page, + * extension of this page will not occur due to the shortcut mechanism of ExtendCLOG. + * We distinguish such scenario by setting force_check_first_xid true and bypass the shortcut + * in order not to miss the clog page extension. + */ + bool force_check_first_xid; + +} SlruSharedData; + +typedef SlruSharedData* SlruShared; + +/* + * SlruCtlData is an unshared structure that points to the active information + * in shared memory. + */ +typedef struct SlruCtlData { + SlruShared shared; + + /* + * This flag tells whether to fsync writes (true for pg_clog and multixact + * stuff, false for pg_subtrans and pg_notify). + */ + bool do_fsync; + + /* + * Dir is set during SimpleLruInit and does not change thereafter. Since + * it's always the same, it doesn't need to be in shared memory. + */ + char dir[64]; +} SlruCtlData; + +typedef SlruCtlData* SlruCtl; + +extern Size SimpleLruShmemSize(int nslots, int nlsns); +extern void SimpleLruInit( + SlruCtl ctl, const char* name, int trancheId, int nslots, int nlsns, LWLock* ctllock, const char* subdir, int index = 0); +extern int SimpleLruZeroPage(SlruCtl ctl, int64 pageno, bool* pbZeroPage = NULL); +extern int SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok, TransactionId xid); +extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid); +extern int SimpleLruReadPage_ReadOnly_Locked(SlruCtl ctl, int64 pageno, TransactionId xid); +extern void SimpleLruWritePage(SlruCtl ctl, int slotno); +extern int SimpleLruFlush(SlruCtl ctl, bool checkpoint); +extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage); + +typedef bool (*SlruScanCallback)(SlruCtl ctl, const char* filename, int64 segpage, const void* data); +extern bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, const void* data); + +/* SlruScanDirectory public callbacks */ +extern bool SlruScanDirCbReportPresence(SlruCtl ctl, const char* filename, int64 segpage, const void* data); +extern bool SlruScanDirCbDeleteAll(SlruCtl ctl, const char* filename, int64 segpage, const void* data); + +#ifdef ENABLE_UT + +extern void ut_SetErrCause(int errcause); +extern void ut_SlruReportIOError(SlruCtl ctl, int64 pageno, TransactionId xid); + +#endif + +extern void SimpleLruWaitIO(SlruCtl ctl, int slotno); +extern bool SlruScanDirCbDeleteCutoff(SlruCtl ctl, const char* filename, int64 segpage, const void* data); + +#endif /* SLRU_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/spgist.h postgresql-hll-2.14/include/include/access/spgist.h --- postgresql-hll-2.14_old/include/include/access/spgist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/spgist.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,193 @@ +/* ------------------------------------------------------------------------- + * + * spgist.h + * Public header file for SP-GiST access method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/spgist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPGIST_H +#define SPGIST_H + +#include "access/skey.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "fmgr.h" + +/* reloption parameters */ +#define SPGIST_MIN_FILLFACTOR 10 +#define SPGIST_DEFAULT_FILLFACTOR 80 + +/* SPGiST opclass support function numbers */ +#define SPGIST_CONFIG_PROC 1 +#define SPGIST_CHOOSE_PROC 2 +#define SPGIST_PICKSPLIT_PROC 3 +#define SPGIST_INNER_CONSISTENT_PROC 4 +#define SPGIST_LEAF_CONSISTENT_PROC 5 +#define SPGISTNProc 5 + +/* + * Argument structs for spg_config method + */ +typedef struct spgConfigIn { + Oid attType; /* Data type to be indexed */ +} spgConfigIn; + +typedef struct spgConfigOut { + Oid prefixType; /* Data type of inner-tuple prefixes */ + Oid labelType; /* Data type of inner-tuple node labels */ + bool canReturnData; /* Opclass can reconstruct original data */ + bool longValuesOK; /* Opclass can cope with values > 1 page */ +} spgConfigOut; + +/* + * Argument structs for spg_choose method + */ +typedef struct spgChooseIn { + Datum datum; /* original datum to be indexed */ + Datum leafDatum; /* current datum to be stored at leaf */ + int level; /* current level (counting from zero) */ + + /* Data from current inner tuple */ + bool allTheSame; /* tuple is marked all-the-same? */ + bool hasPrefix; /* tuple has a prefix? */ + Datum prefixDatum; /* if so, the prefix value */ + int nNodes; /* number of nodes in the inner tuple */ + Datum* nodeLabels; /* node label values (NULL if none) */ +} spgChooseIn; + +typedef enum spgChooseResultType { + spgMatchNode = 1, /* descend into existing node */ + spgAddNode, /* add a node to the inner tuple */ + spgSplitTuple /* split inner tuple (change its prefix) */ +} spgChooseResultType; + +typedef struct spgChooseOut { + spgChooseResultType resultType; /* action code, see above */ + union { + struct /* results for spgMatchNode */ + { + int nodeN; /* descend to this node (index from 0) */ + int levelAdd; /* increment level by this much */ + Datum restDatum; /* new leaf datum */ + } matchNode; + struct /* results for spgAddNode */ + { + Datum nodeLabel; /* new node's label */ + int nodeN; /* where to insert it (index from 0) */ + } addNode; + struct /* results for spgSplitTuple */ + { + /* Info to form new inner tuple with one node */ + bool prefixHasPrefix; /* tuple should have a prefix? */ + Datum prefixPrefixDatum; /* if so, its value */ + Datum nodeLabel; /* node's label */ + + /* Info to form new lower-level inner tuple with all old nodes */ + bool postfixHasPrefix; /* tuple should have a prefix? */ + Datum postfixPrefixDatum; /* if so, its value */ + } splitTuple; + } result; +} spgChooseOut; + +/* + * Argument structs for spg_picksplit method + */ +typedef struct spgPickSplitIn { + int nTuples; /* number of leaf tuples */ + Datum* datums; /* their datums (array of length nTuples) */ + int level; /* current level (counting from zero) */ +} spgPickSplitIn; + +typedef struct spgPickSplitOut { + bool hasPrefix; /* new inner tuple should have a prefix? */ + Datum prefixDatum; /* if so, its value */ + + int nNodes; /* number of nodes for new inner tuple */ + Datum* nodeLabels; /* their labels (or NULL for no labels) */ + + int* mapTuplesToNodes; /* node index for each leaf tuple */ + Datum* leafTupleDatums; /* datum to store in each new leaf tuple */ +} spgPickSplitOut; + +/* + * Argument structs for spg_inner_consistent method + */ +typedef struct spgInnerConsistentIn { + ScanKey scankeys; /* array of operators and comparison values */ + int nkeys; /* length of array */ + + Datum reconstructedValue; /* value reconstructed at parent */ + int level; /* current level (counting from zero) */ + bool returnData; /* original data must be returned? */ + + /* Data from current inner tuple */ + bool allTheSame; /* tuple is marked all-the-same? */ + bool hasPrefix; /* tuple has a prefix? */ + Datum prefixDatum; /* if so, the prefix value */ + int nNodes; /* number of nodes in the inner tuple */ + Datum* nodeLabels; /* node label values (NULL if none) */ +} spgInnerConsistentIn; + +typedef struct spgInnerConsistentOut { + int nNodes; /* number of child nodes to be visited */ + int* nodeNumbers; /* their indexes in the node array */ + int* levelAdds; /* increment level by this much for each */ + Datum* reconstructedValues; /* associated reconstructed values */ +} spgInnerConsistentOut; + +/* + * Argument structs for spg_leaf_consistent method + */ +typedef struct spgLeafConsistentIn { + ScanKey scankeys; /* array of operators and comparison values */ + int nkeys; /* length of array */ + + Datum reconstructedValue; /* value reconstructed at parent */ + int level; /* current level (counting from zero) */ + bool returnData; /* original data must be returned? */ + + Datum leafDatum; /* datum in leaf tuple */ +} spgLeafConsistentIn; + +typedef struct spgLeafConsistentOut { + Datum leafValue; /* reconstructed original data, if any */ + bool recheck; /* set true if operator must be rechecked */ +} spgLeafConsistentOut; + +/* spginsert.c */ +extern Datum spgmerge(PG_FUNCTION_ARGS); +extern Datum spgbuild(PG_FUNCTION_ARGS); +extern Datum spgbuildempty(PG_FUNCTION_ARGS); +extern Datum spginsert(PG_FUNCTION_ARGS); + +/* spgscan.c */ +extern Datum spgbeginscan(PG_FUNCTION_ARGS); +extern Datum spgendscan(PG_FUNCTION_ARGS); +extern Datum spgrescan(PG_FUNCTION_ARGS); +extern Datum spgmarkpos(PG_FUNCTION_ARGS); +extern Datum spgrestrpos(PG_FUNCTION_ARGS); +extern Datum spggetbitmap(PG_FUNCTION_ARGS); +extern Datum spggettuple(PG_FUNCTION_ARGS); +extern Datum spgcanreturn(PG_FUNCTION_ARGS); + +/* spgutils.c */ +extern Datum spgoptions(PG_FUNCTION_ARGS); + +/* spgvacuum.c */ +extern Datum spgbulkdelete(PG_FUNCTION_ARGS); +extern Datum spgvacuumcleanup(PG_FUNCTION_ARGS); + +/* spgxlog.c */ +extern void spg_redo(XLogReaderState* record); +extern void spg_desc(StringInfo buf, XLogReaderState* record); +extern void spg_xlog_startup(void); +extern void spg_xlog_cleanup(void); +extern bool IsSpgistVacuum(XLogReaderState* record); + +#endif /* SPGIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/spgist_private.h postgresql-hll-2.14/include/include/access/spgist_private.h --- postgresql-hll-2.14_old/include/include/access/spgist_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/spgist_private.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,610 @@ +/* ------------------------------------------------------------------------- + * + * spgist_private.h + * Private declarations for SP-GiST access method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/spgist_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPGIST_PRIVATE_H +#define SPGIST_PRIVATE_H + +#include "access/itup.h" +#include "access/spgist.h" +#include "nodes/tidbitmap.h" +#include "storage/buf.h" +#include "utils/rel.h" + +/* Page numbers of fixed-location pages */ +#define SPGIST_METAPAGE_BLKNO (0) /* metapage */ +#define SPGIST_ROOT_BLKNO (1) /* root for normal entries */ +#define SPGIST_NULL_BLKNO (2) /* root for null-value entries */ +#define SPGIST_LAST_FIXED_BLKNO SPGIST_NULL_BLKNO + +#define SpGistBlockIsRoot(blkno) ((blkno) == SPGIST_ROOT_BLKNO || (blkno) == SPGIST_NULL_BLKNO) +#define SpGistBlockIsFixed(blkno) ((BlockNumber)(blkno) <= (BlockNumber)SPGIST_LAST_FIXED_BLKNO) + +/* + * Contents of page special space on SPGiST index pages + */ +typedef struct SpGistPageOpaqueData { + uint16 flags; /* see bit definitions below */ + uint16 nRedirection; /* number of redirection tuples on page */ + uint16 nPlaceholder; /* number of placeholder tuples on page */ + /* note there's no count of either LIVE or DEAD tuples ... */ + uint16 spgist_page_id; /* for identification of SP-GiST indexes */ +} SpGistPageOpaqueData; + +typedef SpGistPageOpaqueData* SpGistPageOpaque; + +/* Flag bits in page special space */ +#define SPGIST_META (1 << 0) +#define SPGIST_DELETED (1 << 1) +#define SPGIST_LEAF (1 << 2) +#define SPGIST_NULLS (1 << 3) + +#define SpGistPageGetOpaque(page) ((SpGistPageOpaque)PageGetSpecialPointer(page)) +#define SpGistPageIsMeta(page) (SpGistPageGetOpaque(page)->flags & SPGIST_META) +#define SpGistPageIsDeleted(page) (SpGistPageGetOpaque(page)->flags & SPGIST_DELETED) +#define SpGistPageSetDeleted(page) (SpGistPageGetOpaque(page)->flags |= SPGIST_DELETED) +#define SpGistPageIsLeaf(page) (SpGistPageGetOpaque(page)->flags & SPGIST_LEAF) +#define SpGistPageStoresNulls(page) (SpGistPageGetOpaque(page)->flags & SPGIST_NULLS) + +/* + * The page ID is for the convenience of pg_filedump and similar utilities, + * which otherwise would have a hard time telling pages of different index + * types apart. It should be the last 2 bytes on the page. This is more or + * less "free" due to alignment considerations. + */ +#define SPGIST_PAGE_ID 0xFF82 + +/* + * Each backend keeps a cache of last-used page info in its index->rd_amcache + * area. This is initialized from, and occasionally written back to, + * shared storage in the index metapage. + */ +typedef struct SpGistLastUsedPage { + BlockNumber blkno; /* block number, or InvalidBlockNumber */ + int freeSpace; /* page's free space (could be obsolete!) */ +} SpGistLastUsedPage; + +/* Note: indexes in cachedPage[] match flag assignments for SpGistGetBuffer */ +#define SPGIST_CACHED_PAGES 8 + +typedef struct SpGistLUPCache { + SpGistLastUsedPage cachedPage[SPGIST_CACHED_PAGES]; +} SpGistLUPCache; + +/* + * metapage + */ +typedef struct SpGistMetaPageData { + uint32 magicNumber; /* for identity cross-check */ + SpGistLUPCache lastUsedPages; /* shared storage of last-used info */ +} SpGistMetaPageData; + +#define SPGIST_MAGIC_NUMBER (0xBA0BABEE) + +#define SpGistPageGetMeta(p) ((SpGistMetaPageData*)PageGetContents(p)) + +/* + * Private state of index AM. SpGistState is common to both insert and + * search code; SpGistScanOpaque is for searches only. + */ + +/* Per-datatype info needed in SpGistState */ +typedef struct SpGistTypeDesc { + Oid type; + bool attbyval; + int16 attlen; +} SpGistTypeDesc; + +typedef struct SpGistState { + spgConfigOut config; /* filled in by opclass config method */ + + SpGistTypeDesc attType; /* type of input data and leaf values */ + SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */ + SpGistTypeDesc attLabelType; /* type of node label values */ + + char* deadTupleStorage; /* workspace for spgFormDeadTuple */ + + TransactionId myXid; /* XID to use when creating a redirect tuple */ + bool isBuild; /* true if doing index build */ +} SpGistState; + +/* + * Private state of an index scan + */ +typedef struct SpGistScanOpaqueData { + SpGistState state; /* see above */ + MemoryContext tempCxt; /* short-lived memory context */ + + /* Control flags showing whether to search nulls and/or non-nulls */ + bool searchNulls; /* scan matches (all) null entries */ + bool searchNonNulls; /* scan matches (some) non-null entries */ + + /* Index quals to be passed to opclass (null-related quals removed) */ + int numberOfKeys; /* number of index qualifier conditions */ + ScanKey keyData; /* array of index qualifier descriptors */ + + /* Stack of yet-to-be-visited pages */ + List* scanStack; /* List of ScanStackEntrys */ + + /* These fields are only used in amgetbitmap scans: */ + TIDBitmap* tbm; /* bitmap being filled */ + int64 ntids; /* number of TIDs passed to bitmap */ + Oid partHeapOid; /* partition oid passed to bitmap */ + + /* These fields are only used in amgettuple scans: */ + bool want_itup; /* are we reconstructing tuples? */ + TupleDesc indexTupDesc; /* if so, tuple descriptor for them */ + int nPtrs; /* number of TIDs found on current page */ + int iPtr; /* index for scanning through same */ + ItemPointerData heapPtrs[MaxIndexTuplesPerPage]; /* TIDs from cur page */ + bool recheck[MaxIndexTuplesPerPage]; /* their recheck flags */ + IndexTuple indexTups[MaxIndexTuplesPerPage]; /* reconstructed tuples */ + + /* + * Note: using MaxIndexTuplesPerPage above is a bit hokey since + * SpGistLeafTuples aren't exactly IndexTuples; however, they are larger, + * so this is safe. + */ +} SpGistScanOpaqueData; + +typedef SpGistScanOpaqueData* SpGistScanOpaque; + +/* + * This struct is what we actually keep in index->rd_amcache. It includes + * static configuration information as well as the lastUsedPages cache. + */ +typedef struct SpGistCache { + spgConfigOut config; /* filled in by opclass config method */ + + SpGistTypeDesc attType; /* type of input data and leaf values */ + SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */ + SpGistTypeDesc attLabelType; /* type of node label values */ + + SpGistLUPCache lastUsedPages; /* local storage of last-used info */ +} SpGistCache; + +/* + * SPGiST tuple types. Note: inner, leaf, and dead tuple structs + * must have the same tupstate field in the same position! Real inner and + * leaf tuples always have tupstate = LIVE; if the state is something else, + * use the SpGistDeadTuple struct to inspect the tuple. + */ + +/* values of tupstate (see README for more info) */ +#define SPGIST_LIVE 0 /* normal live tuple (either inner or leaf) */ +#define SPGIST_REDIRECT 1 /* temporary redirection placeholder */ +#define SPGIST_DEAD 2 /* dead, cannot be removed because of links */ +#define SPGIST_PLACEHOLDER 3 /* placeholder, used to preserve offsets */ + +/* + * SPGiST inner tuple: list of "nodes" that subdivide a set of tuples + * + * Inner tuple layout: + * header/optional prefix/array of nodes, which are SpGistNodeTuples + * + * size and prefixSize must be multiples of MAXALIGN + */ +typedef struct SpGistInnerTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + allTheSame : 1, /* all nodes in tuple are equivalent */ + nNodes : 13, /* number of nodes within inner tuple */ + prefixSize : 16; /* size of prefix, or 0 if none */ + uint16 size; /* total size of inner tuple */ + /* On most machines there will be a couple of wasted bytes here */ + /* prefix datum follows, then nodes */ +} SpGistInnerTupleData; + +typedef SpGistInnerTupleData* SpGistInnerTuple; + +/* these must match largest values that fit in bit fields declared above */ +#define SGITMAXNNODES 0x1FFF +#define SGITMAXPREFIXSIZE 0xFFFF +#define SGITMAXSIZE 0xFFFF + +#define SGITHDRSZ MAXALIGN(sizeof(SpGistInnerTupleData)) +#define _SGITDATA(x) (((char*)(x)) + SGITHDRSZ) +#define SGITDATAPTR(x) ((x)->prefixSize ? _SGITDATA(x) : NULL) +#define SGITDATUM(x, s) \ + ((x)->prefixSize ? ((s)->attPrefixType.attbyval ? *(Datum*)_SGITDATA(x) : PointerGetDatum(_SGITDATA(x))) : (Datum)0) +#define SGITNODEPTR(x) ((SpGistNodeTuple)(_SGITDATA(x) + (x)->prefixSize)) + +/* Macro for iterating through the nodes of an inner tuple */ +#define SGITITERATE(x, i, nt) \ + for ((i) = 0, (nt) = SGITNODEPTR(x); (i) < (x)->nNodes; \ + (i)++, (nt) = (SpGistNodeTuple)(((char*)(nt)) + IndexTupleSize(nt))) + +/* + * SPGiST node tuple: one node within an inner tuple + * + * Node tuples use the same header as ordinary Postgres IndexTuples, but + * we do not use a null bitmap, because we know there is only one column + * so the INDEX_NULL_MASK bit suffices. Also, pass-by-value datums are + * stored as a full Datum, the same convention as for inner tuple prefixes + * and leaf tuple datums. + */ + +typedef IndexTupleData SpGistNodeTupleData; + +typedef SpGistNodeTupleData* SpGistNodeTuple; + +#define SGNTHDRSZ MAXALIGN(sizeof(SpGistNodeTupleData)) +#define SGNTDATAPTR(x) (((char*)(x)) + SGNTHDRSZ) +#define SGNTDATUM(x, s) ((s)->attLabelType.attbyval ? *(Datum*)SGNTDATAPTR(x) : PointerGetDatum(SGNTDATAPTR(x))) + +/* + * SPGiST leaf tuple: carries a datum and a heap tuple TID + * + * In the simplest case, the datum is the same as the indexed value; but + * it could also be a suffix or some other sort of delta that permits + * reconstruction given knowledge of the prefix path traversed to get here. + * + * The size field is wider than could possibly be needed for an on-disk leaf + * tuple, but this allows us to form leaf tuples even when the datum is too + * wide to be stored immediately, and it costs nothing because of alignment + * considerations. + * + * Normally, nextOffset links to the next tuple belonging to the same parent + * node (which must be on the same page). But when the root page is a leaf + * page, we don't chain its tuples, so nextOffset is always 0 on the root. + * + * size must be a multiple of MAXALIGN; also, it must be at least SGDTSIZE + * so that the tuple can be converted to REDIRECT status later. (This + * restriction only adds bytes for the null-datum case, otherwise alignment + * restrictions force it anyway.) + * + * In a leaf tuple for a NULL indexed value, there's no useful datum value; + * however, the SGDTSIZE limit ensures that's there's a Datum word there + * anyway, so SGLTDATUM can be applied safely as long as you don't do + * anything with the result. + */ +typedef struct SpGistLeafTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + size : 30; /* large enough for any palloc'able value */ + OffsetNumber nextOffset; /* next tuple in chain, or InvalidOffset */ + ItemPointerData heapPtr; /* TID of represented heap tuple */ + /* leaf datum follows */ +} SpGistLeafTupleData; + +typedef SpGistLeafTupleData* SpGistLeafTuple; + +#define SGLTHDRSZ MAXALIGN(sizeof(SpGistLeafTupleData)) +#define SGLTDATAPTR(x) (((char*)(x)) + SGLTHDRSZ) +#define SGLTDATUM(x, s) ((s)->attType.attbyval ? *(Datum*)SGLTDATAPTR(x) : PointerGetDatum(SGLTDATAPTR(x))) + +/* + * SPGiST dead tuple: declaration for examining non-live tuples + * + * The tupstate field of this struct must match those of regular inner and + * leaf tuples, and its size field must match a leaf tuple's. + * Also, the pointer field must be in the same place as a leaf tuple's heapPtr + * field, to satisfy some Asserts that we make when replacing a leaf tuple + * with a dead tuple. + * We don't use nextOffset, but it's needed to align the pointer field. + * pointer and xid are only valid when tupstate = REDIRECT. + */ +typedef struct SpGistDeadTupleData { + unsigned int tupstate : 2, /* LIVE/REDIRECT/DEAD/PLACEHOLDER */ + size : 30; + OffsetNumber nextOffset; /* not used in dead tuples */ + ItemPointerData pointer; /* redirection inside index */ + TransactionId xid; /* ID of xact that inserted this tuple */ +} SpGistDeadTupleData; + +typedef SpGistDeadTupleData* SpGistDeadTuple; + +#define SGDTSIZE MAXALIGN(sizeof(SpGistDeadTupleData)) + +/* + * Macros for doing free-space calculations. Note that when adding up the + * space needed for tuples, we always consider each tuple to need the tuple's + * size plus sizeof(ItemIdData) (for the line pointer). This works correctly + * so long as tuple sizes are always maxaligned. + */ + +/* Page capacity after allowing for fixed header and special space */ +#define SPGIST_PAGE_CAPACITY MAXALIGN_DOWN(BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(SpGistPageOpaqueData))) + +/* + * Compute free space on page, assuming that up to n placeholders can be + * recycled if present (n should be the number of tuples to be inserted) + */ +#define SpGistPageGetFreeSpace(p, n) \ + (PageGetExactFreeSpace(p) + Min(SpGistPageGetOpaque(p)->nPlaceholder, n) * (SGDTSIZE + sizeof(ItemIdData))) + +/* + * XLOG stuff + */ + +/* XLOG record types for SPGiST */ +#define XLOG_SPGIST_CREATE_INDEX 0x00 +#define XLOG_SPGIST_ADD_LEAF 0x10 +#define XLOG_SPGIST_MOVE_LEAFS 0x20 +#define XLOG_SPGIST_ADD_NODE 0x30 +#define XLOG_SPGIST_SPLIT_TUPLE 0x40 +#define XLOG_SPGIST_PICKSPLIT 0x50 +#define XLOG_SPGIST_VACUUM_LEAF 0x60 +#define XLOG_SPGIST_VACUUM_ROOT 0x70 +#define XLOG_SPGIST_VACUUM_REDIRECT 0x80 + +/* + * Some redo functions need an SpGistState, although only a few of its fields + * need to be valid. spgxlogState carries the required info in xlog records. + * (See fillFakeState in spgxlog.c for more comments.) + */ +typedef struct spgxlogState { + TransactionId myXid; + bool isBuild; +} spgxlogState; + +#define STORE_STATE(s, d) \ + do { \ + (d).myXid = (s)->myXid; \ + (d).isBuild = (s)->isBuild; \ + } while (0) + +/* + * Backup Blk 0: destination page for leaf tuple + * Backup Blk 1: parent page (if any) + */ +typedef struct spgxlogAddLeaf { + bool newPage; /* init dest page? */ + bool storesNulls; /* page is in the nulls tree? */ + OffsetNumber offnumLeaf; /* offset where leaf tuple gets placed */ + OffsetNumber offnumHeadLeaf; /* offset of head tuple in chain, if any */ + + OffsetNumber offnumParent; /* where the parent downlink is, if any */ + uint16 nodeI; + + /* + * new leaf tuple follows, on an intalign boundary (replay only needs to + * fetch its size field, so that should be enough alignment) + */ +} spgxlogAddLeaf; + +/* + * Backup Blk 0: source leaf page + * Backup Blk 1: destination leaf page + * Backup Blk 2: parent page + */ +typedef struct spgxlogMoveLeafs { + uint16 nMoves; /* number of tuples moved from source page */ + bool newPage; /* init dest page? */ + bool replaceDead; /* are we replacing a DEAD source tuple? */ + bool storesNulls; /* pages are in the nulls tree? */ + + /* where the parent downlink is */ + OffsetNumber offnumParent; + uint16 nodeI; + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * array of deleted tuple numbers, length nMoves + * array of inserted tuple numbers, length nMoves + 1 or 1 + * list of leaf tuples, length nMoves + 1 or 1 (must be maxaligned) + * the tuple number arrays are padded to maxalign boundaries so that the + * leaf tuples will be suitably aligned + * + * Note: if replaceDead is true then there is only one inserted tuple + * number and only one leaf tuple in the data, because we are not copying + * the dead tuple from the source + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogMoveLeafs; + +#define SizeOfSpgxlogMoveLeafs offsetof(spgxlogMoveLeafs, offsets) + +/* + * Backup Blk 0: original page + * Backup Blk 1: where new tuple goes, if not same place + * Backup Blk 2: where parent downlink is, if updated and different from + * the old and new + */ +typedef struct spgxlogAddNode { + /* + * Offset of the original inner tuple, in the original page (on backup + * block 0). + */ + OffsetNumber offnum; + + /* + * Offset of the new tuple, on the new page (on backup block 1). Invalid, + * if we overwrote the old tuple in the original page). + */ + OffsetNumber offnumNew; + bool newPage; /* init new page? */ + + /* ---- + * Where is the parent downlink? parentBlk indicates which page it's on, + * and offnumParent is the offset within the page. The possible values for + * parentBlk are: + * + * 0: parent == original page + * 1: parent == new page + * 2: parent == different page (blk ref 2) + * -1: parent not updated + * ---- + */ + char parentBlk; + OffsetNumber offnumParent; /* offset within the parent page */ + + uint16 nodeI; + + spgxlogState stateSrc; + + /* + * updated inner tuple follows, on an intalign boundary (replay only needs + * to fetch its size field, so that should be enough alignment) + */ +} spgxlogAddNode; + +/* + * Backup Blk 0: where the prefix tuple goes + * Backup Blk 1: where the postfix tuple goes (if different page) + */ +typedef struct spgxlogSplitTuple { + /* where the prefix tuple goes */ + OffsetNumber offnumPrefix; + + /* where the postfix tuple goes */ + OffsetNumber offnumPostfix; + bool newPage; /* need to init that page? */ + bool postfixBlkSame; /* was postfix tuple put on same page as + * prefix? */ + + /* + * new prefix inner tuple follows, then new postfix inner tuple, on + * intalign boundaries (replay only needs to fetch size fields, so that + * should be enough alignment) + */ +} spgxlogSplitTuple; + +/* + * Buffer references in the rdata array are: + * Backup Blk 0: Src page (only if not root) + * Backup Blk 1: Dest page (if used) + * Backup Blk 2: Inner page + * Backup Blk 3: Parent page (if any, and different from Inner) + */ +typedef struct spgxlogPickSplit { + bool isRootSplit; + + uint16 nDelete; /* n to delete from Src */ + uint16 nInsert; /* n to insert on Src and/or Dest */ + bool initSrc; /* re-init the Src page? */ + bool initDest; /* re-init the Dest page? */ + + /* where to put new inner tuple */ + OffsetNumber offnumInner; + bool initInner; /* re-init the Inner page? */ + + bool storesNulls; /* pages are in the nulls tree? */ + + /* where the parent downlink is, if any */ + bool innerIsParent; /* is parent the same as inner page? */ + OffsetNumber offnumParent; + uint16 nodeI; + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * new inner tuple (assumed to have a maxaligned length) + * array of deleted tuple numbers, length nDelete + * array of inserted tuple numbers, length nInsert + * array of page selector bytes for inserted tuples, length nInsert + * list of leaf tuples, length nInsert (must be maxaligned) + * the tuple number and page selector arrays are padded to maxalign + * boundaries so that the leaf tuples will be suitably aligned + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogPickSplit; + +#define SizeOfSpgxlogPickSplit offsetof(spgxlogPickSplit, offsets) + +typedef struct spgxlogVacuumLeaf { + uint16 nDead; /* number of tuples to become DEAD */ + uint16 nPlaceholder; /* number of tuples to become PLACEHOLDER */ + uint16 nMove; /* number of tuples to move */ + uint16 nChain; /* number of tuples to re-chain */ + + spgxlogState stateSrc; + + /* ---------- + * data follows: + * tuple numbers to become DEAD + * tuple numbers to become PLACEHOLDER + * tuple numbers to move from (and replace with PLACEHOLDER) + * tuple numbers to move to (replacing what is there) + * tuple numbers to update nextOffset links of + * tuple numbers to insert in nextOffset links + * ---------- + */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumLeaf; + +#define SizeOfSpgxlogVacuumLeaf offsetof(spgxlogVacuumLeaf, offsets) + +typedef struct spgxlogVacuumRoot { + /* vacuum a root page when it is also a leaf */ + uint16 nDelete; /* number of tuples to delete */ + + spgxlogState stateSrc; + + /* offsets of tuples to delete follow */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumRoot; + +#define SizeOfSpgxlogVacuumRoot offsetof(spgxlogVacuumRoot, offsets) + +typedef struct spgxlogVacuumRedirect { + uint16 nToPlaceholder; /* number of redirects to make placeholders */ + OffsetNumber firstPlaceholder; /* first placeholder tuple to remove */ + TransactionId newestRedirectXid; /* newest XID of removed redirects */ + + /* offsets of redirect tuples to make placeholders follow */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} spgxlogVacuumRedirect; + +#define SizeOfSpgxlogVacuumRedirect offsetof(spgxlogVacuumRedirect, offsets) + +/* + * The "flags" argument for SpGistGetBuffer should be either GBUF_LEAF to + * get a leaf page, or GBUF_INNER_PARITY(blockNumber) to get an inner + * page in the same triple-parity group as the specified block number. + * (Typically, this should be GBUF_INNER_PARITY(parentBlockNumber + 1) + * to follow the rule described in spgist/README.) + * In addition, GBUF_NULLS can be OR'd in to get a page for storage of + * null-valued tuples. + * + * Note: these flag values are used as indexes into lastUsedPages. + */ +#define GBUF_LEAF 0x03 +#define GBUF_INNER_PARITY(x) ((x) % 3) +#define GBUF_NULLS 0x04 + +#define GBUF_PARITY_MASK 0x03 +#define GBUF_REQ_LEAF(flags) (((flags)&GBUF_PARITY_MASK) == GBUF_LEAF) +#define GBUF_REQ_NULLS(flags) ((flags)&GBUF_NULLS) + +/* spgutils.c */ +extern SpGistCache* spgGetCache(Relation index); +extern void initSpGistState(SpGistState* state, Relation index); +extern Buffer SpGistNewBuffer(Relation index); +extern void SpGistUpdateMetaPage(Relation index); +extern Buffer SpGistGetBuffer(Relation index, int flags, int needSpace, bool* isNew); +extern void SpGistSetLastUsedPage(Relation index, Buffer buffer); +extern void SpGistInitPage(Page page, uint16 f); +extern void SpGistInitBuffer(Buffer b, uint16 f); +extern void SpGistInitMetapage(Page page); +extern unsigned int SpGistGetTypeSize(SpGistTypeDesc* att, Datum datum); +extern SpGistLeafTuple spgFormLeafTuple(SpGistState* state, ItemPointer heapPtr, Datum datum, bool isnull); +extern SpGistNodeTuple spgFormNodeTuple(SpGistState* state, Datum label, bool isnull); +extern SpGistInnerTuple spgFormInnerTuple( + SpGistState* state, bool hasPrefix, Datum prefix, int nNodes, SpGistNodeTuple* nodes); +extern SpGistDeadTuple spgFormDeadTuple(SpGistState* state, int tupstate, BlockNumber blkno, OffsetNumber offnum); +extern Datum* spgExtractNodeLabels(SpGistState* state, SpGistInnerTuple innerTuple); +extern OffsetNumber SpGistPageAddNewItem( + SpGistState* state, Page page, Item item, Size size, OffsetNumber* startOffset, bool errorOK); + +/* spgdoinsert.c */ +extern void spgUpdateNodeLink(SpGistInnerTuple tup, int nodeN, BlockNumber blkno, OffsetNumber offset); +extern void spgPageIndexMultiDelete(SpGistState* state, Page page, OffsetNumber* itemnos, int nitems, int firststate, + int reststate, BlockNumber blkno, OffsetNumber offnum); +extern void spgdoinsert(Relation index, SpGistState* state, ItemPointer heapPtr, Datum datum, bool isnull); +extern void addOrReplaceTuple(Page page, Item tuple, int size, OffsetNumber offset); +extern void fillFakeState(SpGistState* state, const spgxlogState& stateSrc); + +#endif /* SPGIST_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/subtrans.h postgresql-hll-2.14/include/include/access/subtrans.h --- postgresql-hll-2.14_old/include/include/access/subtrans.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/subtrans.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,20 @@ +/* + * subtrans.h + * + * PostgreSQL subtransaction-log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/subtrans.h + */ +#ifndef SUBTRANS_H +#define SUBTRANS_H + +#include "access/clog.h" + +extern void SubTransSetParent(TransactionId xid, TransactionId parent); +extern TransactionId SubTransGetParent(TransactionId xid, CLogXidStatus* status, bool force_wait_parent); +extern TransactionId SubTransGetTopmostTransaction(TransactionId xid); + +#endif /* SUBTRANS_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/sysattr.h postgresql-hll-2.14/include/include/access/sysattr.h --- postgresql-hll-2.14_old/include/include/access/sysattr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/sysattr.h 2020-12-12 17:06:43.141346671 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * sysattr.h + * POSTGRES system attribute definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/sysattr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SYSATTR_H +#define SYSATTR_H + +/* + * Attribute numbers for the system-defined attributes + */ +#define SelfItemPointerAttributeNumber (-1) +#define ObjectIdAttributeNumber (-2) +#define MinTransactionIdAttributeNumber (-3) +#define MinCommandIdAttributeNumber (-4) +#define MaxTransactionIdAttributeNumber (-5) +#define MaxCommandIdAttributeNumber (-6) +#define TableOidAttributeNumber (-7) +#ifdef PGXC + +#define XC_NodeIdAttributeNumber (-8) +#define BucketIdAttributeNumber (-9) +#define FirstLowInvalidHeapAttributeNumber (-10) + +#else +#define FirstLowInvalidHeapAttributeNumber (-8) +#endif + +#endif /* SYSATTR_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/tableam.h postgresql-hll-2.14/include/include/access/tableam.h --- postgresql-hll-2.14_old/include/include/access/tableam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/tableam.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,782 @@ +/*------------------------------------------------------------------------- + * + * tableam.h + * POSTGRES table access method definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tableam.h + * + * NOTES + * See tableam.sgml for higher level documentation. + * + *------------------------------------------------------------------------- + */ + +#ifndef TABLEAM_H +#define TABLEAM_H + +#include "access/hbindex_am.h" +#include "access/hbucket_am.h" +#include "access/relscan.h" +#include "access/sdir.h" +#include "catalog/index.h" +#include "executor/executor.h" +#include "optimizer/bucketinfo.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/snapshot.h" +#include "nodes/execnodes.h" + +/* + * * Bitmask values for the flags argument to the scan_begin callback. + * */ +typedef enum ScanOptions +{ + /* one of SO_TYPE_* may be specified */ + SO_TYPE_SEQSCAN = 1 << 0, + SO_TYPE_BITMAPSCAN = 1 << 1, + SO_TYPE_SAMPLESCAN = 1 << 2, + SO_TYPE_ANALYZE = 1 << 3, + SO_TYPE_TIDSCAN = 1 << 8, + + /* several of SO_ALLOW_* may be specified */ + /* allow or disallow use of access strategy */ + SO_ALLOW_STRAT = 1 << 4, + /* report location to syncscan logic? */ + SO_ALLOW_SYNC = 1 << 5, + /* verify visibility page-at-a-time? */ + SO_ALLOW_PAGEMODE = 1 << 6, + + /* unregister snapshot at scan end? */ + SO_TEMP_SNAPSHOT = 1 << 7 +} ScanOptions; + + +/* ------------------------------------------------------------------------ + * Table Access Method Layer + * ------------------------------------------------------------------------ + */ + +/* "options" flag bits for tuple_insert */ +#define TABLE_INSERT_SKIP_WAL 0x0001 +#define TABLE_INSERT_SKIP_FSM 0x0002 +#define TABLE_INSERT_FROZEN 0x0004 +#define TABLE_INSERT_SPECULATIVE 0x0008 + +extern RangeScanInRedis reset_scan_qual(Relation currHeapRel, ScanState * node); + +/* + * Macros on tuple assertions from tuple and typeType + * and retrieve the index for table type from tuple type. + */ +#define TUPLE_IS_HEAP_TUPLE(tup) (((HeapTuple)tup)->tupTableType == HEAP_TUPLE) +//#define TUPLE_IS_UHEAP_TUPLE(tup) (((UHeapTuple)tup)->tupTableType == UHEAP_TUPLE) +#define AssertValidTupleType(tupType) Assert(tupType == HEAP_TUPLE || tupType == UHEAP_TUPLE) +#define AssertValidTuple(tup) Assert(TUPLE_IS_HEAP_TUPLE(tup)) +#define GetTableAMIndex(tupType) tupType >> 1 +#define GetTabelAmIndexTuple(tup) GetTableAMIndex(((HeapTuple)tup)->tupTableType) + +/* + * Common interface for table AM. + * This abstracts away the accessor methods to different kinds of tables. + */ + +typedef struct TableAmRoutine +{ + /* ------------------------------------------------------------------------ + * TABLE SLOT AM APIs + * ------------------------------------------------------------------------ + */ + + /* + * Clear the contents of the slot. Only the contents are expected to be + * cleared and not the tuple descriptor. Typically an implementation of + * this callback should free the memory allocated for the tuple(minimal/physical/Datum and isnull array) + *contained in the slot. + */ + void (*tslot_clear) (TupleTableSlot *slot); + + /* + * Make the contents of the slot solely depend on the slot(make them a local copy), + * and not on underlying external resources like another memory context, buffers etc for HeapTable. + * or return a copy of HeapTuple from slots's content for other Tables. + * + * @pram slot: slot to be materialized. + */ + HeapTuple (*tslot_materialize) (TupleTableSlot *slot); + + /* + * Return a minimal tuple "owned" by the slot. It is slot's responsibility + * to free the memory consumed by the minimal tuple. If the slot can not + * "own" a minimal tuple, it should not implement this callback and should + * set it as NULL. + * + * @param slot: slot from minimal tuple to fetch. + * @return slot's minimal tuple. + * + */ + MinimalTuple (*tslot_get_minimal_tuple) (TupleTableSlot *slot); + + /* + * Return a copy of minimal tuple representing the contents of the slot. + * The copy needs to be palloc'd in the current memory context. The slot + * itself is expected to remain unaffected. It is *not* expected to have + * meaningful "system columns" in the copy. The copy is not be "owned" by + * the slot i.e. the caller has to take responsibility to free memory + * consumed by the slot. + * + * @param slot: slot from which minimal tuple to be copied. + * @return slot's tuple minimal tuple copy + */ + MinimalTuple (*tslot_copy_minimal_tuple) (TupleTableSlot *slot); + + /* + * Stores heaps minimal tuple in the TupleTableSlot. Release the current slots buffer and Free's any slot's + * minimal and heap tuple. + * + * @param mtup: minimal tuple to be stored. + * @param slot: slot to store tuple. + * @param: should_free true if clear the slot's tuple contents by pfree_ext() during ExecClearTuple. + */ + void (*tslot_store_minimal_tuple) (MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree); + + /* + * Returns a heap tuple "owned" by the slot. It is the slot's responsibility to free the memory + * associated with this tuple. If the slot cannot own the tuple constructed or returned, it should + * not implement this method, and should return NULL. + * + * @param slot: slot from tuple to fetch. + * @return slot's tuple. + */ + HeapTuple (*tslot_get_heap_tuple) (TupleTableSlot* slot); + + + /* + * Return a copy of heap tuple representing the contents of the slot. The + * copy needs to be palloc'd in the current memory context. The slot + * itself is expected to remain unaffected. It is *not* expected to have + * meaningful "system columns" in the copy. The copy is not be "owned" by + * the slot i.e. the caller has to take responsibility to free memory + * consumed by the slot. + * + * @param slot: slot from which tuple to be copied. + * @return slot's tuple copy + */ + HeapTuple (*tslot_copy_heap_tuple) (TupleTableSlot *slot); + + /* + * Stores the physical tuple into a slot. + * + * @param tuple: tuple to be stored. + * @param slot: slot to store tuple. + * @param: should_free true if clear the slot's tuple contents by pfree_ext() during ExecClearTuple + * @return: none + */ + void (*tslot_store_tuple)(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free); + + /* + * Fill up first natts entries of tts_values and tts_isnull arrays with + * values from the tuple contained in the slot. The function may be called + * with natts more than the number of attributes available in the tuple, + * in which case it should set tts_nvalid to the number of returned + * columns. + * + * @param slot:input Tuple Table slot from which attributes are extracted. + * @param attnum: index until which slots attributes are extracted. + */ + void (*tslot_getsomeattrs) (TupleTableSlot *slot, int natts); + + /* + * Fetches a given attribute from the slot's current tuple. + * attnums beyond the slot's tupdesc's last attribute will be considered NULL + * even when the physical tuple is longer than the tupdesc. + * + * @param slot: TableTuple slot from this attribute is extracted + * @param attnum: index of the atribute to be extracted. + * @param isnull: set to true, if the attribute is NULL. + */ + Datum (*tslot_getattr)(TupleTableSlot* slot, int attnum, bool* isnull); + + /* + * This function forces all the entries of slot's Datum/isnull array to be valid + * The caller may then extract data directly + * from those arrays instead of using getattr. + * + * @param slot: TableTuple slot from this attributes are extracted + */ + void (*tslot_getallattrs)(TupleTableSlot* slot); + + /* + * Detects if specified attribute is null without actually fetching it. + * + * @param slot: Tabletuple slot + * @para attnum: attribute index that should be checked for null value. + */ + bool (*tslot_attisnull)(TupleTableSlot* slot, int attnum); + + /* ------------------------------------------------------------------------ + * TABLE TUPLE AM APIs + * ------------------------------------------------------------------------ + */ + + /* + * Returns value of the given system attribute as a datum and sets isnull + * to false, if it's not NULL. Throws an error if the slot type does not + * support system attributes. + */ + Datum (*tops_getsysattr) (Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buf); + + /* + * form_minimal_tuple + * construct a MinimalTuple from the given values[] and isnull[] arrays, + * which are of the length indicated by tupleDescriptor->natts + * + * The result is allocated in the current memory context. + */ + MinimalTuple (*tops_form_minimal_tuple)(TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple); + + + /* + * form_tuple + * construct a tuple from the given values[] and isnull[] arrays, + * which are of the length indicated by tupleDescriptor->natts + * + * The result is allocated in the current memory context. + */ + Tuple (*tops_form_tuple)(TupleDesc tuple_descriptor, Datum* values, bool* isnull); + + /* + * form_cmprs_tuple + * construct a compressed tuple from the given cmprsInfo. + * + * The result is allocated in the current memory context. + */ + HeapTuple (*tops_form_cmprs_tuple)(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info); + + /* + * deform_tuple + * Given a tuple, extract data into values/isnull arrays; this is + * the inverse of heap_form_tuple. + */ + void (*tops_deform_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull); + + /* + * deform_cmprs_tuple + * Given a tuple, extract data into values/isnull arrays; this is + * the inverse of heap_form_cmprs_tuple. + */ + void (*tops_deform_cmprs_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info); + + /* + * compute_data_size + * Determine size of the data area of a tuple to be constructed + */ + Size (*tops_computedatasize_tuple)(TupleDesc tuple_desc, Datum* values, const bool* isnull, uint32 hoff); + + /* + * fill_tuple + * Load data portion of a tuple from values/isnull arrays + */ + void (*tops_fill_tuple)(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit); + + /* + * modify_tuple + * form a new tuple from an old tuple and a set of replacement values. + * + * The result is allocated in the current memory context. + */ + Tuple (*tops_modify_tuple)(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace); + + /* + * tuple_getattr + * Fetches the attribute for a given index.. + */ + Datum (*tops_tuple_getattr)(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null); + + /* + * tuple_attisnull + * Fetches if the attribute is null for a given index. + */ + bool (*tops_tuple_attisnull)(Tuple tup, int attnum, TupleDesc tuple_desc); + + /* + * tops_copy_tuple + * Returns a copy of the entire tuple + */ + Tuple (*tops_copy_tuple) (Tuple tuple); + + /* --------------------------------------------------------------------- + * SCAN AM API + * --------------------------------------------------------------------- + */ + + IndexFetchTableData * (*scan_index_fetch_begin) (Relation rel); + + void (*scan_index_fetch_reset) (IndexFetchTableData *scan); + + void (*scan_index_fetch_end) (IndexFetchTableData *scan); + + HeapTuple (*scan_index_fetch_tuple) (IndexScanDesc scan, bool *all_dead); + + /* + * begin relation scan + */ + TableScanDesc (*scan_begin) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key, RangeScanInRedis rangeScanInRedis); + + /* + * begin relation scan for bit map + */ + TableScanDesc (*scan_begin_bm) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key); + + /* + * begin relation scan for sampling + */ + TableScanDesc (*scan_begin_sampling) (Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis); + + /* + * Re scan + */ + void (*scan_rescan) (TableScanDesc sscan, ScanKey key); + + /* + * Restore scan position + */ + void (*scan_restrpos) (TableScanDesc sscan); + + /* + * Mark scan position + */ + void (*scan_markpos) (TableScanDesc sscan); + + /* + * init parallel seq scan + */ + void (*scan_init_parallel_seqscan) (TableScanDesc sscan, int32 dop, ScanDirection dir); + + /* + * Get next tuple + * Will return a Generic "Tuple" type + */ + Tuple (*scan_getnexttuple) (TableScanDesc sscan, ScanDirection direction); + + /* + * Get next page + */ + void (*scan_getpage) (TableScanDesc sscan, BlockNumber page); + + /* + * end relation scan + */ + void (*scan_end) (TableScanDesc sscan); + + + /* ------------------------------------------------------------------------ + * DQL AM APIs + * ------------------------------------------------------------------------ + */ + + bool (*tuple_fetch) (Relation relation, Snapshot snapshot, HeapTuple tuple, + Buffer *userbuf, bool keep_buf, Relation stats_relation); + + bool (*tuple_satisfies_snapshot) (Relation relation, HeapTuple tuple, + Snapshot snapshot, Buffer buffer); + + void (*tuple_get_latest_tid) (Relation relation, Snapshot snapshot, + ItemPointer tid); + + /* ------------------------------------------------------------------------ + * DML AM APIs + * ------------------------------------------------------------------------ + */ + Oid (*tuple_insert) (Relation relation, Tuple tup, CommandId cid, + int options, struct BulkInsertStateData *bistate); + + int (*tuple_multi_insert) (Relation relation, Relation parent, + Tuple* tuples, int ntuples, CommandId cid, + int options, struct BulkInsertStateData *bistate, + HeapMultiInsertExtraArgs *args); + + TM_Result (*tuple_delete) (Relation relation, ItemPointer tid, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool allow_delete_self); + + TM_Result (*tuple_update) (Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self); + + // XXXTAM: see of we can get rid of some uheap_lock_tuple() params + TM_Result (*tuple_lock) (Relation relation, Tuple tuple, Buffer *buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, + bool allow_lock_self, bool follow_updates, bool eval, Snapshot snapshot, + ItemPointer tid, bool isSelectForUpdate); + + HeapTuple (*tuple_lock_updated)(CommandId cid, Relation relation, + int lockmode, ItemPointer tid, TransactionId priorXmax); + + + /* ------------------------------------------------------------------------ + * DDL AM APIs + * ------------------------------------------------------------------------ + */ + + double (*index_build_scan) (Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, bool allow_sync, + IndexBuildCallback callback, void* callback_state); + + void (*index_validate_scan) (Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state); + + double (*relation_copy_for_cluster) (Relation OldHeap, Relation OldIndex, + Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, + bool use_sort, AdaptMem* memUsage, + TransactionId* ptrFreezeXid); + +} TableAmRoutine; + +extern const TableAmRoutine * const g_tableam_routines[]; + +static inline const TableAmRoutine *GetTableAmRoutine(TableAmType type) { + return g_tableam_routines[type]; +} + +/* + * Clears the contents of the table slot that contains heap table tuple data. + */ +static inline void tableam_tslot_clear(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_clear(slot); +} + +static inline HeapTuple tableam_tslot_materialize(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_materialize(slot); +} + +static inline MinimalTuple tableam_tslot_get_minimal_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_get_minimal_tuple(slot); +} + + +static inline MinimalTuple tableam_tslot_copy_minimal_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_copy_minimal_tuple(slot); +} + +static inline void tableam_tslot_store_minimal_tuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree) +{ + g_tableam_routines[slot->tts_tupslotTableAm]->tslot_store_minimal_tuple(mtup, slot, shouldFree); +} + +static inline HeapTuple tableam_tslot_get_heap_tuple(TupleTableSlot* slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_get_heap_tuple(slot); +} + +static inline HeapTuple tableam_tslot_copy_heap_tuple(TupleTableSlot *slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_copy_heap_tuple(slot); +} + +// XXXTAM +// WE have the tuple type in the tuple now, we can use it to select the right function! +static inline void tableam_tslot_store_tuple(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free) +{ + g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tslot_store_tuple(tuple, slot, buffer, should_free); +} + + +static inline void tableam_tslot_getsomeattrs(TupleTableSlot *slot, int natts) +{ + g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getsomeattrs(slot, natts); +} + +static inline Datum tableam_tslot_getattr(TupleTableSlot* slot, int attnum, bool* isnull) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getattr(slot, attnum, isnull); +} + +static inline void tableam_tslot_getallattrs(TupleTableSlot* slot) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_getallattrs(slot); +} + +static inline bool tableam_tslot_attisnull(TupleTableSlot* slot, int attnum) +{ + return g_tableam_routines[slot->tts_tupslotTableAm]->tslot_attisnull(slot, attnum); +} + +/* ------------------------------------------------------------------------ + * TABLE TUPLE AM APIs + * ------------------------------------------------------------------------ + */ + +static inline Datum tableam_tops_getsysattr(Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buf = InvalidBuffer) { + AssertValidTuple(tup); + return g_tableam_routines[GetTabelAmIndexTuple(tup)]->tops_getsysattr(tup, attnum, tuple_desc, isnull, buf); +} + +static inline MinimalTuple tableam_tops_form_minimal_tuple( + TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_minimal_tuple(tuple_descriptor, values, isnull, in_tuple); +} + +static inline Tuple tableam_tops_form_tuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_tuple(tuple_descriptor, values, isnull); +} + +static inline Tuple tableam_tops_form_cmprs_tuple(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_form_cmprs_tuple(tuple_descriptor, cmprs_info); +} + + +static inline void tableam_tops_deform_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_tuple(tuple, tuple_desc, values, isnull); +} + +static inline void tableam_tops_deform_cmprs_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_cmprs_tuple(tuple, tuple_desc, values, isnull, cmprs_info); +} + +static inline Size tableam_tops_computedatasize_tuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, uint32 hoff, uint32 tupTableType) +{ + AssertValidTupleType(tupTableType); + return g_tableam_routines[GetTableAMIndex(tupTableType)]->tops_computedatasize_tuple(tuple_desc, values, isnull, hoff); +} + +static inline void tableam_tops_fill_tuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit) +{ + return g_tableam_routines[tuple_desc->tdTableAmType]->tops_fill_tuple(tuple_desc, values, isnull, data, data_size, infomask, bit); +} + +// there is no uheapam_tops_modify_tuple +// but this is done for completeness +static inline Tuple tableam_tops_modify_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_modify_tuple(tuple, tuple_desc, repl_values, repl_isnull, do_replace); +} + +static inline void tableam_tops_free_tuple(HeapTuple &htup) +{ + heap_freetuple_ext(htup); +} + +static inline Datum tableam_tops_tuple_getattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_getattr(tuple, att_num, tuple_desc, is_null); +} + +static inline bool tableam_tops_tuple_attisnull(Tuple tuple, int attnum, TupleDesc tuple_desc) +{ + AssertValidTuple(tuple); + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_attisnull(tuple, attnum, tuple_desc); +} + +static inline Tuple tableam_tops_copy_tuple(Tuple tuple) +{ + AssertValidTuple(tuple); + + // TODO: assert tuple returned and tuple are same type + + return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_copy_tuple(tuple); + // return heap_copytuple(tuple); +} + +static inline MinimalTuple tableam_tops_copy_minimal_tuple(MinimalTuple mtup) +{ + return heap_copy_minimal_tuple(mtup); +} + +static inline void tableam_tops_free_minimal_tuple(MinimalTuple mtup) +{ + heap_free_minimal_tuple(mtup); +} + + +/* ------------------------------------------------------------------------ + * DQL AM APIs + * ------------------------------------------------------------------------ + */ +static inline bool tableam_tuple_fetch(Relation relation, Snapshot snapshot, + HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation) { + return g_tableam_routines[relation->rd_tam_type]->tuple_fetch(relation, snapshot, tuple, userbuf, keep_buf, stats_relation); +} + +static inline bool tableam_tuple_satisfies_snapshot(Relation relation, HeapTuple tuple, + Snapshot snapshot, Buffer buffer) { + return g_tableam_routines[relation->rd_tam_type]->tuple_satisfies_snapshot(relation, tuple, snapshot, buffer); +} + +static inline void tableam_tuple_get_latest_tid(Relation relation, Snapshot snapshot, + ItemPointer tid) { + return g_tableam_routines[relation->rd_tam_type]->tuple_get_latest_tid(relation, snapshot, tid); +} + +static inline Oid tableam_tuple_insert (Relation relation, Tuple tup, CommandId cid, + int options, struct BulkInsertStateData *bistate) { + return g_tableam_routines[relation->rd_tam_type]->tuple_insert(relation, tup, cid, options, bistate); +} + +static inline int tableam_tuple_multi_insert(Relation relation, Relation parent, + Tuple* tuples, int ntuples, CommandId cid, + int options, struct BulkInsertStateData *bistate, + HeapMultiInsertExtraArgs *args) { + return g_tableam_routines[relation->rd_tam_type]->tuple_multi_insert(relation, parent, tuples, ntuples, cid, options, bistate, args); +} + +static inline TM_Result tableam_tuple_delete(Relation relation, ItemPointer tid, + CommandId cid, Snapshot crosscheck, Snapshot snapshot, + bool wait, TM_FailureData *tmfd, bool allow_delete_self = false) { + return g_tableam_routines[relation->rd_tam_type]->tuple_delete(relation, tid, cid, crosscheck, snapshot, wait, tmfd, allow_delete_self); +} + + +static inline TM_Result tableam_tuple_update(Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self = false) { + return g_tableam_routines[relation->rd_tam_type]->tuple_update(relation, parentRelation, otid, newtup, cid, crosscheck, + snapshot, wait, tmfd, update_indexes, allow_update_self); +} + +static inline TM_Result tableam_tuple_lock(Relation relation, Tuple tuple, Buffer *buffer, + CommandId cid, LockTupleMode mode, bool nowait, TM_FailureData *tmfd, + bool allow_lock_self, bool follow_updates, bool eval, Snapshot snapshot, + ItemPointer tid, bool isSelectForUpdate) { + return g_tableam_routines[relation->rd_tam_type]->tuple_lock(relation, tuple, buffer, cid, mode, nowait, tmfd, + allow_lock_self, follow_updates, eval, snapshot, + tid, isSelectForUpdate); +} + +static inline HeapTuple tableam_tuple_lock_updated(CommandId cid, Relation relation, + int lockmode, ItemPointer tid, TransactionId priorXmax) { + return g_tableam_routines[relation->rd_tam_type]->tuple_lock_updated(cid, relation, lockmode, tid, priorXmax); +} + + +/* ----------------------------------------------------------------------- + * SCAN AM APIS FOR HEAP + * ------------------------------------------------------------------------ + */ + +extern IndexFetchTableData * heapam_scan_index_fetch_begin(Relation rel); +static inline IndexFetchTableData * tableam_scan_index_fetch_begin(Relation rel) +{ + return heapam_scan_index_fetch_begin(rel); +} + +extern void heapam_index_fetch_reset(IndexFetchTableData *scan); +static inline void tableam_scan_index_fetch_reset(IndexFetchTableData *scan) +{ + heapam_index_fetch_reset(scan); +} + +extern void heapam_scan_index_fetch_end(IndexFetchTableData *scan); +static inline void tableam_scan_index_fetch_end(IndexFetchTableData *scan) +{ + heapam_scan_index_fetch_end(scan); +} + +static inline HeapTuple tableam_scan_index_fetch_tuple(IndexScanDesc scan, bool *all_dead) +{ + return g_tableam_routines[scan->heapRelation->rd_tam_type]->scan_index_fetch_tuple(scan, all_dead); +} + +static inline TableScanDesc tableam_scan_begin(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + RangeScanInRedis rangeScanInRedis = {false, 0, 0}) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin(relation, snapshot, nkeys, key, rangeScanInRedis); +} + +static inline TableScanDesc tableam_scan_begin_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin_bm(relation, snapshot, nkeys, key); +} + +static inline TableScanDesc tableam_scan_begin_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, bool allow_strat, + bool allow_sync, RangeScanInRedis rangeScanInRedis = {false, 0, 0}) +{ + return g_tableam_routines[relation->rd_tam_type]->scan_begin_sampling(relation, snapshot, nkeys, key, allow_strat, allow_sync, rangeScanInRedis); +} + +static inline Tuple tableam_scan_getnexttuple(TableScanDesc sscan, ScanDirection direction) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getnexttuple(sscan, direction); +} + +static inline void tableam_scan_getpage(TableScanDesc sscan, BlockNumber page) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getpage(sscan, page); +} + +static inline void tableam_scan_end(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_end(sscan); +} + +static inline void tableam_scan_rescan(TableScanDesc sscan, ScanKey key) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_rescan(sscan, key); +} + +static inline void tableam_scan_restrpos(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_restrpos(sscan); +} + +static inline void tableam_scan_markpos(TableScanDesc sscan) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_markpos(sscan); +} + +static inline void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir) +{ + return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_init_parallel_seqscan(sscan, dop, dir); +} + +static inline double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, bool allow_sync, + IndexBuildCallback callback, void* callback_state) { + return g_tableam_routines[heapRelation->rd_tam_type]->index_build_scan(heapRelation, indexRelation, indexInfo, allow_sync, callback, callback_state); +} + + +static inline void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, + IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state) { + return g_tableam_routines[heapRelation->rd_tam_type]->index_validate_scan(heapRelation, indexRelation, indexInfo, snapshot, state); +} + +static inline double tableam_relation_copy_for_cluster(Relation OldHeap, Relation OldIndex, + Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, + bool use_sort, AdaptMem* memUsage, + TransactionId* ptrFreezeXid) { + return g_tableam_routines[OldHeap->rd_tam_type]->relation_copy_for_cluster(OldHeap, OldIndex, NewHeap, OldestXmin, FreezeXid, verbose, use_sort, memUsage, ptrFreezeXid); +} + + +//XXXTAM TEMPORARY +extern TM_Result heapam_tuple_update(Relation relation, Relation parentRelation, + ItemPointer otid, Tuple newtup, CommandId cid, + Snapshot crosscheck, Snapshot snapshot, bool wait, + TM_FailureData *tmfd, bool *update_indexes, bool allow_update_self = false); + +#endif /* TABLEAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/transam.h postgresql-hll-2.14/include/include/access/transam.h --- postgresql-hll-2.14_old/include/include/access/transam.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/transam.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,244 @@ +/* ------------------------------------------------------------------------- + * + * transam.h + * postgres transaction access method support code + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/access/transam.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TRANSAM_H +#define TRANSAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xact.h" +#include "access/xlogdefs.h" +#ifdef PGXC +#include "gtm/gtm_c.h" +#endif +#include "utils/atomic.h" + +/* ---------------- + * Special transaction ID values + * + * BootstrapTransactionId is the XID for "bootstrap" operations, and + * FrozenTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFFFFFFFFF) /* First four bits reserved */ +#define MaxShortTransactionId ((TransactionId)0xFFFFFFFF) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +#define ShortTransactionIdToNormal(base, xid) \ + (TransactionIdIsNormal(xid) ? (TransactionId)(xid) + (base) : (TransactionId)(xid)) +#define NormalTransactionIdToShort(base, xid) \ + (TransactionIdIsNormal(xid) ? (ShortTransactionId)(AssertMacro((xid) >= (base) + FirstNormalTransactionId), \ + AssertMacro((xid) <= (base) + MaxShortTransactionId), \ + (xid) - (base)) \ + : (ShortTransactionId)(xid)) + +/* advance a transaction ID variable */ +#define TransactionIdAdvance(dest) \ + do { \ + (dest)++; \ + Assert((dest) > FirstNormalTransactionId); \ + } while (0) + +/* back up a transaction ID variable */ +#define TransactionIdRetreat(dest) \ + do { \ + Assert((dest) > FirstNormalTransactionId); \ + (dest)--; \ + } while ((dest) < FirstNormalTransactionId) + +/* compare two XIDs already known to be normal; this is a macro for speed */ +#define NormalTransactionIdPrecedes(id1, id2) \ + (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), (int64)((id1) - (id2)) < 0) +/* compare two XIDs already known to be normal; this is a macro for speed */ +#define NormalTransactionIdFollows(id1, id2) \ + (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), (int32)((id1) - (id2)) > 0) +/* ---------- + * Object ID (OID) zero is InvalidOid. + * + * OIDs 1-9999 are reserved for manual assignment (see the files + * in src/include/catalog/). + * + * OIDS 10000-16383 are reserved for assignment during initdb + * using the OID generator. (We start the generator at 10000.) + * + * OIDs beginning at 16384 are assigned from the OID generator + * during normal multiuser operation. (We force the generator up to + * 16384 as soon as we are in normal operation.) + * + * The choices of 10000 and 16384 are completely arbitrary, and can be moved + * if we run low on OIDs in either category. Changing the macros below + * should be sufficient to do this. + * + * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383 + * and resume with 16384. This minimizes the odds of OID conflict, by not + * reassigning OIDs that might have been assigned during initdb. + * ---------- + */ +#define FirstBootstrapObjectId 10000 +#define FirstNormalObjectId 16384 + +#define IsSystemObjOid(id) ((OidIsValid(id)) && (id < FirstBootstrapObjectId)) +/* + * VariableCache is a data structure in shared memory that is used to track + * OID and XID assignment state. For largely historical reasons, there is + * just one struct with different fields that are protected by different + * LWLocks. + */ +typedef struct VariableCacheData { + /* + * These fields are protected by OidGenLock. + */ + Oid nextOid; /* next OID to assign */ + uint32 oidCount; /* OIDs available before must do XLOG work */ + + /* + * These fields are protected by XidGenLock. + */ + TransactionId nextXid; /* next XID to assign */ + + TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + TransactionId xidVacLimit; /* start forcing autovacuums here */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + int64 lastExtendCSNLogpage; /* last extend csnlog page number */ + + /* + * The page from which the last extending do, this will be reset when + * extend from recentGlobalXmin. + */ + int64 startExtendCSNLogpage; + + /* + * Fields related to MVCC snapshots. + * + * lastCommitSeqNo is the CSN assigned to last committed transaction. + * It is protected by CommitSeqNoLock. + * + * latestCompletedXid is the highest XID that has committed. Anything + * > this is seen by still in-progress by everyone. Use atomic ops to + * update. + * + * oldestActiveXid is the XID of the oldest transaction that's still + * in-progress. (Or rather, the oldest XID among all still in-progress + * transactions; it's not necessarily the one that started first). + * Must hold ProcArrayLock in shared mode, and use atomic ops, to update. + */ + CommitSeqNo nextCommitSeqNo; + TransactionId latestCompletedXid; /* newest XID that has committed or + * aborted */ + /* + * These fields only set in startup to normal + */ + TransactionId startupMaxXid; /* the latest xid in prev shut down */ + TransactionId xmin; + TransactionId recentLocalXmin; /* the lastest xmin in local node */ + pg_atomic_uint64 recentGlobalXmin; /* the lastest xmin in global */ + pg_atomic_uint32 CriticalCacheBuildLock; /* lock of create relcache init file */ + + pg_atomic_uint64 cutoff_csn_min; + TransactionId keep_xmin; /* quickly to calculate oldestxmin */ + CommitSeqNo keep_csn; /* quickly to calculate oldestxmin */ + CommitSeqNo local_csn_min; +} VariableCacheData; + +typedef VariableCacheData* VariableCache; + +/* ---------------- + * extern declarations + * ---------------- + */ + +/* in transam/xact.c */ +extern bool TransactionStartedDuringRecovery(void); + +/* + * prototypes for functions in transam/transam.c + */ +extern bool TransactionIdDidCommit(TransactionId transactionId); +extern bool TransactionIdDidAbort(TransactionId transactionId); + +#define COMMITSEQNO_INPROGRESS UINT64CONST(0x0) +#define COMMITSEQNO_ABORTED UINT64CONST(0x1) +#define COMMITSEQNO_FROZEN UINT64CONST(0x2) +#define COMMITSEQNO_FIRST_NORMAL UINT64CONST(0x3) + +#define COMMITSEQNO_COMMIT_INPROGRESS (UINT64CONST(1) << 62) +#define COMMITSEQNO_SUBTRANS_BIT (UINT64CONST(1) << 63) + +#define MAX_COMMITSEQNO UINT64CONST((UINT64CONST(1) << 60) - 1) /* First four bits reserved */ + +#define COMMITSEQNO_IS_INPROGRESS(csn) (((csn)&MAX_COMMITSEQNO) == COMMITSEQNO_INPROGRESS) +#define COMMITSEQNO_IS_ABORTED(csn) ((csn) == COMMITSEQNO_ABORTED) +#define COMMITSEQNO_IS_FROZEN(csn) ((csn) == COMMITSEQNO_FROZEN) +#define COMMITSEQNO_IS_COMMITTED(csn) \ + (((csn)&MAX_COMMITSEQNO) >= COMMITSEQNO_FROZEN && !COMMITSEQNO_IS_SUBTRANS(csn) && !COMMITSEQNO_IS_COMMITTING(csn)) +#define COMMITSEQNO_IS_COMMITTING(csn) (((csn)&COMMITSEQNO_COMMIT_INPROGRESS) == COMMITSEQNO_COMMIT_INPROGRESS) + +#define COMMITSEQNO_IS_SUBTRANS(csn) (((csn)&COMMITSEQNO_SUBTRANS_BIT) == COMMITSEQNO_SUBTRANS_BIT) + +#define GET_COMMITSEQNO(csn) ((csn)&MAX_COMMITSEQNO) +#define GET_PARENTXID(csn) ((csn)&MAX_COMMITSEQNO) + +typedef enum { XID_COMMITTED, XID_ABORTED, XID_INPROGRESS } TransactionIdStatus; + +extern void SetLatestFetchState(TransactionId transactionId, CommitSeqNo result); +extern CommitSeqNo TransactionIdGetCommitSeqNo(TransactionId xid, bool isCommit, bool isMvcc, bool isNest); +extern CommitSeqNo TransactionIdGetCommitSeqNoNCache( + TransactionId transactionId, bool isCommit, bool isMvcc, bool isNest); +extern void TransactionIdAbort(TransactionId transactionId); +extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId* xids, uint64 csn); +extern bool TransactionIdIsKnownCompleted(TransactionId transactionId); +extern void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId* xids, XLogRecPtr lsn, uint64 csn); +extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId* xids); +extern TransactionId TransactionIdLatest(TransactionId mainxid, int nxids, const TransactionId* xids); +extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid); +extern bool LatestFetchTransactionIdDidAbort(TransactionId transactionId); +extern bool LatestFetchCSNDidAbort(TransactionId transactionId); +extern bool TransactionIdLogicallyPrecedes(TransactionId id1, TransactionId id2); + +/* in transam/varsup.c */ +#ifdef PGXC /* PGXC_DATANODE */ +extern void SetNextTransactionId(TransactionId xid, bool updateLatestCompletedXid); +extern void SetForceXidFromGTM(bool value); +extern bool GetForceXidFromGTM(void); +extern TransactionId GetNewTransactionId(bool isSubXact, TransactionState s); +#else +extern TransactionId GetNewTransactionId(bool isSubXact); +#endif /* PGXC */ +extern TransactionId ReadNewTransactionId(void); +extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid); +extern bool ForceTransactionIdLimitUpdate(void); +extern Oid GetNewObjectId(bool IsToastRel = false); +extern TransactionId SubTransGetTopParentXidFromProcs(TransactionId xid); +extern TransactionIdStatus TransactionIdGetStatus(TransactionId transactionId); + +#endif /* TRAMSAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/tupconvert.h postgresql-hll-2.14/include/include/access/tupconvert.h --- postgresql-hll-2.14_old/include/include/access/tupconvert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/tupconvert.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * tupconvert.h + * Tuple conversion support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupconvert.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPCONVERT_H +#define TUPCONVERT_H + +#include "access/htup.h" + +typedef struct TupleConversionMap { + TupleDesc indesc; /* tupdesc for source rowtype */ + TupleDesc outdesc; /* tupdesc for result rowtype */ + AttrNumber* attrMap; /* indexes of input fields, or 0 for null */ + Datum* invalues; /* workspace for deconstructing source */ + bool* inisnull; + Datum* outvalues; /* workspace for constructing result */ + bool* outisnull; +} TupleConversionMap; + +extern TupleConversionMap* convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char* msg); + +extern TupleConversionMap* convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc, const char* msg); + +extern HeapTuple do_convert_tuple(HeapTuple tuple, TupleConversionMap* map); + +extern void free_conversion_map(TupleConversionMap* map); + +#endif /* TUPCONVERT_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/tupdesc.h postgresql-hll-2.14/include/include/access/tupdesc.h --- postgresql-hll-2.14_old/include/include/access/tupdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/tupdesc.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * + * tupdesc.h + * POSTGRES tuple descriptor definitions. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupdesc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPDESC_H +#define TUPDESC_H + +#ifndef FRONTEND_PARSER +#include "postgres.h" +#else +#include "postgres_fe.h" +#endif +#include "access/attnum.h" +#include "catalog/pg_attribute.h" +#include "nodes/pg_list.h" + +/* + * Total number of different Table Access Method types. + */ +const int NUM_TABLE_AM = 2; + +/* + * range based values to specify the indexes + * for different table types to map access methods in + * class TableAccessorMethods + */ +typedef enum tableAmType +{ + TAM_INVALID = -1, + TAM_HEAP = 0, + TAM_USTORE = 1, +} TableAmType; + +const static uint32 HEAP_TUPLE = 1; +const static uint32 UHEAP_TUPLE = 2; + +#define TableAMGetTupleType(tableamType) (tableamType + 1) + +typedef struct attrDefault { + AttrNumber adnum; + char* adbin; /* nodeToString representation of expr */ +} AttrDefault; + +typedef struct constrCheck { + char* ccname; + char* ccbin; /* nodeToString representation of expr */ + bool ccvalid; + bool ccnoinherit; /* this is a non-inheritable constraint */ +} ConstrCheck; + +/* This structure contains constraints of a tuple */ +typedef struct tupleConstr { + AttrDefault* defval; /* array */ + ConstrCheck* check; /* array */ + AttrNumber* clusterKeys; /* cluster keys */ + uint16 clusterKeyNum; + uint16 num_defval; + uint16 num_check; + bool has_not_null; +} TupleConstr; + +/* This structure contains initdefval of a tuple */ +typedef struct tupInitDefVal { + Datum* datum; + bool isNull; + uint16 dataLen; +} TupInitDefVal; + +/* + * @hdfs + * This strrcture constains the following informations about on + * informational constraint: + * 1. constrname records informational constaint name. + * 2. contype records the informational constraint type. + * 'p' represnets pirmary key constraint. 'u' represents unique + * constraint. + * 3. nonforced records the enforced or forced attributtes of informationanl constaint. + * 4. enableOpt records the enalbe or disbale query optimization attribute of informational constaint. + */ +typedef struct InformationalConstraint { + NodeTag type; + char* constrname; + char contype; + bool nonforced; + bool enableOpt; +} InformationalConstraint; + +/* + * This struct is passed around within the backend to describe the structure + * of tuples. For tuples coming from on-disk relations, the information is + * collected from the pg_attribute, pg_attrdef, and pg_constraint catalogs. + * Transient row types (such as the result of a join query) have anonymous + * TupleDesc structs that generally omit any constraint info; therefore the + * structure is designed to let the constraints be omitted efficiently. + * + * Note that only user attributes, not system attributes, are mentioned in + * TupleDesc; with the exception that tdhasoid indicates if OID is present. + * + * If the tupdesc is known to correspond to a named rowtype (such as a table's + * rowtype) then tdtypeid identifies that type and tdtypmod is -1. Otherwise + * tdtypeid is RECORDOID, and tdtypmod can be either -1 for a fully anonymous + * row type, or a value >= 0 to allow the rowtype to be looked up in the + * typcache.c type cache. + * + * Tuple descriptors that live in caches (relcache or typcache, at present) + * are reference-counted: they can be deleted when their reference count goes + * to zero. Tuple descriptors created by the executor need no reference + * counting, however: they are simply created in the appropriate memory + * context and go away when the context is freed. We set the tdrefcount + * field of such a descriptor to -1, while reference-counted descriptors + * always have tdrefcount >= 0. + */ +typedef struct tupleDesc { + int natts; /* number of attributes in the tuple */ + bool tdisredistable; /* temp table created for data redistribution by the redis tool */ + Form_pg_attribute* attrs; + /* attrs[N] is a pointer to the description of Attribute Number N+1 */ + TupleConstr* constr; /* constraints, or NULL if none */ + TupInitDefVal* initdefvals; /* init default value due to ADD COLUMN */ + Oid tdtypeid; /* composite type ID for tuple type */ + int32 tdtypmod; /* typmod for tuple type */ + bool tdhasoid; /* tuple has oid attribute in its header */ + int tdrefcount; /* reference count, or -1 if not counting */ + TableAmType tdTableAmType; /*index for accessing the Table Accessor methods on singleton TableAccessorMethods */ +} * TupleDesc; + +/* Accessor for the i'th attribute of tupdesc. */ +#define TupleDescAttr(tupdesc, i) (tupdesc->attrs[(i)]) + +extern TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid, TableAmType tam = TAM_HEAP); + +extern TupleDesc CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute* attrs, TableAmType tam = TAM_HEAP); + +extern TupleDesc CreateTupleDescCopy(TupleDesc tupdesc); + +extern TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc); + +extern void FreeTupleDesc(TupleDesc tupdesc); + +extern void IncrTupleDescRefCount(TupleDesc tupdesc); +extern void DecrTupleDescRefCount(TupleDesc tupdesc); + +#define PinTupleDesc(tupdesc) \ + do { \ + if ((tupdesc)->tdrefcount >= 0) \ + IncrTupleDescRefCount(tupdesc); \ + } while (0) + +#define ReleaseTupleDesc(tupdesc) \ + do { \ + if ((tupdesc)->tdrefcount >= 0) \ + DecrTupleDescRefCount(tupdesc); \ + } while (0) + +extern bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2); +extern bool equalDeltaTupleDescs(TupleDesc main_tupdesc, TupleDesc delta_tupdesc); + +extern void TupleDescInitEntry( + TupleDesc desc, AttrNumber attribute_number, const char* attribute_name, Oid oidtypeid, int32 typmod, int attdim); + +extern void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attribute_number, Oid collationid); + +extern void VerifyAttrCompressMode(int8 mode, int attlen, const char* attname); + +extern TupleDesc BuildDescForRelation(List* schema, Node* oriented_from, char relkind = '\0'); + +extern TupleDesc BuildDescFromLists(List* names, List* types, List* typmods, List* collations); + +extern bool tupledesc_have_pck(TupleConstr* constr); + +extern void copyDroppedAttribute(Form_pg_attribute target, Form_pg_attribute source); + +#endif /* TUPDESC_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/tupmacs.h postgresql-hll-2.14/include/include/access/tupmacs.h --- postgresql-hll-2.14_old/include/include/access/tupmacs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/tupmacs.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,188 @@ +/* ------------------------------------------------------------------------- + * + * tupmacs.h + * Tuple macros used by both index tuples and heap tuples. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/tupmacs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPMACS_H +#define TUPMACS_H + +/* + * check to see if the ATT'th bit of an array of 8-bit bytes is set. + */ +#define att_isnull(ATT, BITS) (!((BITS)[(uint32)(int32)(ATT) >> 3] & (1 << ((ATT)&0x07)))) + +/* + * Given a Form_pg_attribute and a pointer into a tuple's data area, + * return the correct value or pointer. + * + * We return a Datum value in all cases. If the attribute has "byval" false, + * we return the same pointer into the tuple data area that we're passed. + * Otherwise, we return the correct number of bytes fetched from the data + * area and extended to Datum form. + * + * On machines where Datum is 8 bytes, we support fetching 8-byte byval + * attributes; otherwise, only 1, 2, and 4-byte values are supported. + * + * Note that T must already be properly aligned for this to work correctly. + */ +#define fetchatt(A, T) fetch_att(T, (A)->attbyval, (A)->attlen) + +/* + * Same, but work from byval/len parameters rather than Form_pg_attribute. + */ +#if SIZEOF_DATUM == 8 + +#define fetch_att(T, attbyval, attlen) \ + ((attbyval) ? ((attlen) == (int)sizeof(Datum) \ + ? *((Datum*)(T)) \ + : ((attlen) == (int)sizeof(int32) \ + ? Int32GetDatum(*((int32*)(T))) \ + : ((attlen) == (int)sizeof(int16) \ + ? Int16GetDatum(*((int16*)(T))) \ + : (AssertMacro((attlen) == 1), CharGetDatum(*((char*)(T))))))) \ + : PointerGetDatum((char*)(T))) +#else /* SIZEOF_DATUM != 8 */ + +#define fetch_att(T, attbyval, attlen) \ + ((attbyval) \ + ? ((attlen) == (int)sizeof(int32) \ + ? Int32GetDatum(*((int32*)(T))) \ + : ((attlen) == (int)sizeof(int16) ? Int16GetDatum(*((int16*)(T))) \ + : (AssertMacro((attlen) == 1), CharGetDatum(*((char*)(T)))))) \ + : PointerGetDatum((char*)(T))) +#endif /* SIZEOF_DATUM == 8 */ + +/* + * att_align_datum aligns the given offset as needed for a datum of alignment + * requirement attalign and typlen attlen. attdatum is the Datum variable + * we intend to pack into a tuple (it's only accessed if we are dealing with + * a varlena type). Note that this assumes the Datum will be stored as-is; + * callers that are intending to convert non-short varlena datums to short + * format have to account for that themselves. + */ +#define att_align_datum(cur_offset, attalign, attlen, attdatum) \ + (((attlen) == -1 && VARATT_IS_SHORT(DatumGetPointer(attdatum))) ? (intptr_t)(cur_offset) \ + : att_align_nominal(cur_offset, attalign)) + +/* + * att_align_pointer performs the same calculation as att_align_datum, + * but is used when walking a tuple. attptr is the current actual data + * pointer; when accessing a varlena field we have to "peek" to see if we + * are looking at a pad byte or the first byte of a 1-byte-header datum. + * (A zero byte must be either a pad byte, or the first byte of a correctly + * aligned 4-byte length word; in either case we can align safely. A non-zero + * byte must be either a 1-byte length word, or the first byte of a correctly + * aligned 4-byte length word; in either case we need not align.) + * + * Note: some callers pass a "char *" pointer for cur_offset. This is + * a bit of a hack but should work all right as long as intptr_t is the + * correct width. + */ +#define att_align_pointer(cur_offset, attalign, attlen, attptr) \ + (((attlen) == -1 && VARATT_NOT_PAD_BYTE(attptr)) ? (intptr_t)(cur_offset) : att_align_nominal(cur_offset, attalign)) + +/* + * att_align_nominal aligns the given offset as needed for a datum of alignment + * requirement attalign, ignoring any consideration of packed varlena datums. + * There are three main use cases for using this macro directly: + * * we know that the att in question is not varlena (attlen != -1); + * in this case it is cheaper than the above macros and just as good. + * * we need to estimate alignment padding cost abstractly, ie without + * reference to a real tuple. We must assume the worst case that + * all varlenas are aligned. + * * within arrays, we unconditionally align varlenas (XXX this should be + * revisited, probably). + * + * The attalign cases are tested in what is hopefully something like their + * frequency of occurrence. + */ +#define att_align_nominal(cur_offset, attalign) \ + (((attalign) == 'i') \ + ? INTALIGN(cur_offset) \ + : (((attalign) == 'c') \ + ? (uintptr_t)(cur_offset) \ + : (((attalign) == 'd') ? DOUBLEALIGN(cur_offset) \ + : (AssertMacro((attalign) == 's'), SHORTALIGN(cur_offset))))) + +/* + * att_addlength_datum increments the given offset by the space needed for + * the given Datum variable. attdatum is only accessed if we are dealing + * with a variable-length attribute. + */ +#define att_addlength_datum(cur_offset, attlen, attdatum) \ + att_addlength_pointer(cur_offset, attlen, DatumGetPointer(attdatum)) + +/* + * att_addlength_pointer performs the same calculation as att_addlength_datum, + * but is used when walking a tuple --- attptr is the pointer to the field + * within the tuple. + * + * Note: some callers pass a "char *" pointer for cur_offset. This is + * actually perfectly OK, but probably should be cleaned up along with + * the same practice for att_align_pointer. + */ +#define att_addlength_pointer(cur_offset, attlen, attptr) \ + (((attlen) > 0) \ + ? ((cur_offset) + (attlen)) \ + : (((attlen) == -1) ? ((cur_offset) + VARSIZE_ANY(attptr)) \ + : (AssertMacro((attlen) == -2), (cur_offset) + (strlen((char*)(attptr)) + 1)))) + +/* + * store_att_byval is a partial inverse of fetch_att: store a given Datum + * value into a tuple data area at the specified address. However, it only + * handles the byval case, because in typical usage the caller needs to + * distinguish by-val and by-ref cases anyway, and so a do-it-all macro + * wouldn't be convenient. + */ +#if SIZEOF_DATUM == 8 + +#define store_att_byval(T, newdatum, attlen) \ + do { \ + switch (attlen) { \ + case sizeof(char): \ + *(char*)(T) = DatumGetChar(newdatum); \ + break; \ + case sizeof(int16): \ + *(int16*)(T) = DatumGetInt16(newdatum); \ + break; \ + case sizeof(int32): \ + *(int32*)(T) = DatumGetInt32(newdatum); \ + break; \ + case sizeof(Datum): \ + *(Datum*)(T) = (newdatum); \ + break; \ + default: \ + elog(ERROR, "unsupported byval length: %d", (int)(attlen)); \ + break; \ + } \ + } while (0) +#else /* SIZEOF_DATUM != 8 */ + +#define store_att_byval(T, newdatum, attlen) \ + do { \ + switch (attlen) { \ + case sizeof(char): \ + *(char*)(T) = DatumGetChar(newdatum); \ + break; \ + case sizeof(int16): \ + *(int16*)(T) = DatumGetInt16(newdatum); \ + break; \ + case sizeof(int32): \ + *(int32*)(T) = DatumGetInt32(newdatum); \ + break; \ + default: \ + elog(ERROR, "unsupported byval length: %d", (int)(attlen)); \ + break; \ + } \ + } while (0) +#endif /* SIZEOF_DATUM == 8 */ + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/tuptoaster.h postgresql-hll-2.14/include/include/access/tuptoaster.h --- postgresql-hll-2.14_old/include/include/access/tuptoaster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/tuptoaster.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,245 @@ +/* ------------------------------------------------------------------------- + * + * tuptoaster.h + * POSTGRES definitions for external and compressed storage + * of variable size attributes. + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * + * src/include/access/tuptoaster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPTOASTER_H +#define TUPTOASTER_H + +#include "access/htup.h" +#include "utils/relcache.h" + +/* + * This enables de-toasting of index entries. Needed until VACUUM is + * smart enough to rebuild indexes from scratch. + */ +#define TOAST_INDEX_HACK + +/* + * Find the maximum size of a tuple if there are to be N tuples per page. + */ +#define MaximumBytesPerTuple(tuplesPerPage) \ + MAXALIGN_DOWN((BLCKSZ - MAXALIGN(SizeOfPageHeaderData + (tuplesPerPage) * sizeof(ItemIdData))) / (tuplesPerPage)) + +/* + * These symbols control toaster activation. If a tuple is larger than + * TOAST_TUPLE_THRESHOLD, we will try to toast it down to no more than + * TOAST_TUPLE_TARGET bytes through compressing compressible fields and + * moving EXTENDED and EXTERNAL data out-of-line. + * + * The numbers need not be the same, though they currently are. It doesn't + * make sense for TARGET to exceed THRESHOLD, but it could be useful to make + * it be smaller. + * + * Currently we choose both values to match the largest tuple size for which + * TOAST_TUPLES_PER_PAGE tuples can fit on a heap page. + * + * XXX while these can be modified without initdb, some thought needs to be + * given to needs_toast_table() in toasting.c before unleashing random + * changes. Also see LOBLKSIZE in large_object.h, which can *not* be + * changed without initdb. + */ +#define TOAST_TUPLES_PER_PAGE 4 + +#define TOAST_TUPLE_THRESHOLD MaximumBytesPerTuple(TOAST_TUPLES_PER_PAGE) + +#define TOAST_TUPLE_TARGET TOAST_TUPLE_THRESHOLD + +/* + * The code will also consider moving MAIN data out-of-line, but only as a + * last resort if the previous steps haven't reached the target tuple size. + * In this phase we use a different target size, currently equal to the + * largest tuple that will fit on a heap page. This is reasonable since + * the user has told us to keep the data in-line if at all possible. + */ +#define TOAST_TUPLES_PER_PAGE_MAIN 1 + +#define TOAST_TUPLE_TARGET_MAIN MAXALIGN_DOWN(BLCKSZ - MAXALIGN(SizeOfHeapPageHeaderData + sizeof(ItemIdData))) + +/* + * If an index value is larger than TOAST_INDEX_TARGET, we will try to + * compress it (we can't move it out-of-line, however). Note that this + * number is per-datum, not per-tuple, for simplicity in index_form_tuple(). + */ +#define TOAST_INDEX_TARGET (MaxHeapTupleSize / 16) + +/* + * When we store an oversize datum externally, we divide it into chunks + * containing at most TOAST_MAX_CHUNK_SIZE data bytes. This number *must* + * be small enough that the completed toast-table tuple (including the + * ID and sequence fields and all overhead) will fit on a page. + * The coding here sets the size on the theory that we want to fit + * EXTERN_TUPLES_PER_PAGE tuples of maximum size onto a page. + * + * NB: Changing TOAST_MAX_CHUNK_SIZE requires an initdb. + */ +#define EXTERN_TUPLES_PER_PAGE 4 /* tweak only this */ + +#define EXTERN_TUPLE_MAX_SIZE MaximumBytesPerTuple(EXTERN_TUPLES_PER_PAGE) + +#define TOAST_MAX_CHUNK_SIZE \ + (EXTERN_TUPLE_MAX_SIZE - MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) - sizeof(Oid) - sizeof(int32) - VARHDRSZ) + +/* Size of an EXTERNAL datum that contains a standard TOAST pointer */ +#define TOAST_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(struct varatt_external)) + +/* Size of an indirect datum that contains a standard TOAST pointer */ +#define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(struct varatt_indirect)) +/* + * Testing whether an externally-stored value is compressed now requires + * comparing extsize (the actual length of the external data) to rawsize + * (the original uncompressed datum's size). The latter includes VARHDRSZ + * overhead, the former doesn't. We never use compression unless it actually + * saves space, so we expect either equality or less-than. + */ +#define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer) \ + ((toast_pointer).va_extsize < (toast_pointer).va_rawsize - VARHDRSZ) + +/* + * Macro to fetch the possibly-unaligned contents of an EXTERNAL datum + * into a local "struct varatt_external" toast pointer. This should be + * just a memcpy, but some versions of gcc seem to produce broken code + * that assumes the datum contents are aligned. Introducing an explicit + * intermediate "varattrib_1b_e *" variable seems to fix it. + */ +#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr) \ +do { \ + varattrib_1b_e *attre = (varattrib_1b_e *) (attr); \ + errno_t rcs; \ + Assert(VARATT_IS_EXTERNAL(attre)); \ + if (VARATT_IS_EXTERNAL_BUCKET(attre)) \ + { \ + Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL + sizeof(int2)); \ + }\ + else\ + { \ + Assert(VARSIZE_EXTERNAL(attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \ + }\ + rcs = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(attre), sizeof(toast_pointer)); \ + securec_check(rcs, "", ""); \ +} while (0) + + +#define VARATT_EXTERNAL_GET_POINTER_B(toast_pointer, attr, bucketid) \ +do { \ + varattrib_1b_e *_attre = (varattrib_1b_e *) (attr); \ + errno_t _rc; \ + Assert(VARATT_IS_EXTERNAL(_attre)); \ + if (VARATT_IS_EXTERNAL_BUCKET(_attre)) \ + { \ + Assert(VARSIZE_EXTERNAL(_attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL + sizeof(int2)); \ + _rc = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(_attre), sizeof(toast_pointer)); \ + securec_check(_rc, "", ""); \ + _rc= memcpy_s(&(bucketid), sizeof(int2), VARDATA_EXTERNAL(_attre)+sizeof(toast_pointer), sizeof(int2)); \ + securec_check(_rc, "", ""); \ + } \ + else \ + { \ + Assert(VARSIZE_EXTERNAL(_attre) == sizeof(toast_pointer) + VARHDRSZ_EXTERNAL); \ + _rc = memcpy_s(&(toast_pointer), sizeof(toast_pointer), VARDATA_EXTERNAL(_attre), sizeof(toast_pointer)); \ + securec_check(_rc, "", ""); \ + bucketid = -1; \ + } \ +} while (0) + + +/* ---------- + * toast_insert_or_update - + * + * Called by heap_insert() and heap_update(). + * ---------- + */ +extern HeapTuple toast_insert_or_update( + Relation rel, HeapTuple newtup, HeapTuple oldtup, int options, Page pageForOldTup); + +/* ---------- + * toast_delete - + * + * Called by heap_delete(). + * ---------- + */ +extern void toast_delete(Relation rel, HeapTuple oldtup, int options); + +/* ---------- + * heap_tuple_fetch_attr() - + * + * Fetches an external stored attribute from the toast + * relation. Does NOT decompress it, if stored external + * in compressed format. + * ---------- + */ +extern struct varlena* heap_tuple_fetch_attr(struct varlena* attr); + +/* ---------- + * heap_tuple_untoast_attr() - + * + * Fully detoasts one attribute, fetching and/or decompressing + * it as needed. + * ---------- + */ +extern struct varlena* heap_tuple_untoast_attr(struct varlena* attr); + +/* ---------- + * heap_tuple_untoast_attr_slice() - + * + * Fetches only the specified portion of an attribute. + * (Handles all cases for attribute storage) + * ---------- + */ +extern struct varlena* heap_tuple_untoast_attr_slice(struct varlena* attr, int32 sliceoffset, int32 slicelength); + +/* ---------- + * toast_flatten_tuple - + * + * "Flatten" a tuple to contain no out-of-line toasted fields. + * (This does not eliminate compressed or short-header datums.) + * ---------- + */ +extern HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc); + +/* ---------- + * toast_flatten_tuple_attribute - + * + * If a Datum is of composite type, "flatten" it to contain no toasted fields. + * This must be invoked on any potentially-composite field that is to be + * inserted into a tuple. Doing this preserves the invariant that toasting + * goes only one level deep in a tuple. + * ---------- + */ +extern Datum toast_flatten_tuple_attribute(Datum value, Oid typeId, int32 typeMod); + +/* ---------- + * toast_compress_datum - + * + * Create a compressed version of a varlena datum, if possible + * ---------- + */ +extern Datum toast_compress_datum(Datum value); + +/* ---------- + * toast_raw_datum_size - + * + * Return the raw (detoasted) size of a varlena datum + * ---------- + */ +extern Size toast_raw_datum_size(Datum value); + +/* ---------- + * toast_datum_size - + * + * Return the storage size of a varlena datum + * ---------- + */ +extern Size toast_datum_size(Datum value); + +extern bool toastrel_valueid_exists(Relation toastrel, Oid valueid); + +#endif /* TUPTOASTER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/access/twophase.h postgresql-hll-2.14/include/include/access/twophase.h --- postgresql-hll-2.14_old/include/include/access/twophase.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/twophase.h 2020-12-12 17:06:43.142346683 +0800 @@ -0,0 +1,180 @@ +/* ------------------------------------------------------------------------- + * + * twophase.h + * Two-phase-commit related declarations. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/twophase.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TWOPHASE_H +#define TWOPHASE_H + +#include "storage/proc.h" +#include "utils/snapshot.h" +#include "gtm/gtm_c.h" + +#define GIDSIZE 200 +#define MAX_PREP_XACT_VERSIONS 64 + +/* + * GlobalTransactionData is defined in twophase.c; other places have no + * business knowing the internal definition. + */ +typedef struct GlobalTransactionData* GlobalTransaction; +typedef struct recover_two_phase_file_key { + TransactionId xid; /* recover the prepared transaction */ +} recover_two_phase_file_key; + +typedef struct recover_two_phase_file { + recover_two_phase_file_key key; /* hash key ... must be first */ + XLogRecPtr prepare_start_lsn; /* XLOG offset of prepare record start */ + XLogRecPtr prepare_end_lsn; /* XLOG offset of prepare record end */ +} recover_two_phase_file; + +typedef struct GlobalTransactionData { + GlobalTransaction next; /* list link for free list */ + int pgprocno; /* ID of associated dummy PGPROC */ + BackendId dummyBackendId; /* similar to backend id for backends */ + TimestampTz prepared_at; /* time of preparation */ + + /* + * Note that we need to keep track of two LSNs for each GXACT. + * We keep track of the start LSN because this is the address we must + * use to read state data back from WAL when committing a prepared GXACT. + * We keep track of the end LSN because that is the LSN we need to wait + * for prior to commit. + */ + XLogRecPtr prepare_start_lsn; /* XLOG offset of prepare record start */ + XLogRecPtr prepare_end_lsn; /* XLOG offset of prepare record end */ + TransactionId xid; /* The GXACT id */ + + Oid owner; /* ID of user that executed the xact */ + BackendId locking_backend; /* backend currently working on the xact */ + bool valid; /* TRUE if PGPROC entry is in proc array */ + bool ondisk; /* TRUE if prepare state file is on disk */ + bool inredo; /* TRUE if entry was added via xlog_redo */ + char gid[GIDSIZE]; /* The GID assigned to the prepared xact */ +} GlobalTransactionData; + +/* + * 2PC state file format: + * + * 1. TwoPhaseFileHeader + * 2. TransactionId[] (subtransactions) + * 3. ColFileNode[] (files to be deleted at commit) + * 4. ColFileNode[] (files to be deleted at abort) + * 5. SharedInvalidationMessage[] (inval messages to be sent at commit) + * 6. TwoPhaseRecordOnDisk + * 7. ... + * 8. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID) + * 9. CRC32 + * + * Each segment except the final CRC32 is MAXALIGN'd. + */ +/* + * Header for a 2PC state file + */ +#define TWOPHASE_MAGIC 0x57F94532 /* format identifier */ + +typedef struct TwoPhaseFileHeader { + uint32 magic; /* format identifier */ + uint32 total_len; /* actual file length */ + TransactionId xid; /* original transaction XID */ + Oid database; /* OID of database it was in */ + TimestampTz prepared_at; /* time of preparation */ + Oid owner; /* user running the transaction */ + int32 nsubxacts; /* number of following subxact XIDs */ + int32 ncommitrels; /* number of delete-on-commit rels */ + int32 nabortrels; /* number of delete-on-abort rels */ + int32 ninvalmsgs; /* number of cache invalidation messages */ + bool initfileinval; /* does relcache init file need invalidation? */ + char gid[GIDSIZE]; /* GID for transaction */ + int32 ncommitlibrarys; /* number of delete-on-commit library file */ + int32 nabortlibrarys; /* number of delete-on-abort library file */ +} TwoPhaseFileHeader; + +typedef struct ValidPrepXidData +{ + volatile unsigned int refCount; + unsigned int numPrepXid; + bool isOverflow; + TransactionId *validPrepXid; +} ValidPrepXidData; + +typedef ValidPrepXidData *ValidPrepXid; + +/* + * Two Phase Commit shared state. Access to this struct is protected + * by TwoPhaseStateLock. + */ +typedef struct TwoPhaseStateData { + /* Head of linked list of free GlobalTransactionData structs */ + GlobalTransaction freeGXacts; + + /* Number of valid prepXacts entries. */ + int numPrepXacts; + + /* GTM-LITE preplist ring buffer */ + ValidPrepXidData validPrepXids[MAX_PREP_XACT_VERSIONS]; + volatile ValidPrepXid currPrepXid; + volatile ValidPrepXid nextPrepXid; + + /* + * There are max_prepared_xacts items in this array, but C wants a + * fixed-size array. + */ + GlobalTransaction prepXacts[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} TwoPhaseStateData; /* VARIABLE LENGTH STRUCT */ + +extern int PendingPreparedXactsCount; + +extern Size TwoPhaseShmemSize(void); +extern void TwoPhaseShmemInit(void); + +extern void AtAbort_Twophase(void); +extern void PostPrepare_Twophase(void); + +extern PGPROC* TwoPhaseGetDummyProc(TransactionId xid); +extern BackendId TwoPhaseGetDummyBackendId(TransactionId xid); + +extern GlobalTransaction MarkAsPreparing(GTM_TransactionHandle handle, TransactionId xid, const char* gid, + TimestampTz prepared_at, Oid owner, Oid databaseid); + +extern void EndPrepare(GlobalTransaction gxact); +extern void StartPrepare(GlobalTransaction gxact); +extern bool StandbyTransactionIdIsPrepared(TransactionId xid); + +extern TransactionId PrescanPreparedTransactions(TransactionId** xids_p, int* nxids_p); +extern void StandbyRecoverPreparedTransactions(void); +extern void RecoverPreparedTransactions(void); + +extern void CheckPointTwoPhase(XLogRecPtr redo_horizon); + +void DropBufferForDelRelinXlogUsingScan(ColFileNodeRel *delrels, int ndelrels); +void DropBufferForDelRelsinXlogUsingHash(ColFileNodeRel *delrels, int ndelrels); + +extern void FinishPreparedTransaction(const char* gid, bool isCommit); + +extern bool TransactionIdIsPrepared(TransactionId xid); + +extern bool IsTransactionIdMarkedPrepared(TransactionId xid); + +extern void SetLocalSnapshotPreparedArray(Snapshot snapshot); + +extern int GetPendingXactCount(void); + +extern void PrepareRedoAdd(char* buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn); +extern void PrepareRedoRemove(TransactionId xid, bool giveWarning); +extern void restoreTwoPhaseData(void); +extern void RemoveStaleTwophaseState(TransactionId xid); + +extern void RecoverPrepareTransactionCSNLog(char* buf); +extern int get_snapshot_defualt_prepared_num(void); + +#endif /* TWOPHASE_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/twophase_rmgr.h postgresql-hll-2.14/include/include/access/twophase_rmgr.h --- postgresql-hll-2.14_old/include/include/access/twophase_rmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/twophase_rmgr.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * twophase_rmgr.h + * Two-phase-commit resource managers definition + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/twophase_rmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TWOPHASE_RMGR_H +#define TWOPHASE_RMGR_H + +typedef void (*TwoPhaseCallback)(TransactionId xid, uint16 info, void* recdata, uint32 len); +typedef uint8 TwoPhaseRmgrId; + +/* + * Built-in resource managers + */ +#define TWOPHASE_RM_END_ID 0 +#define TWOPHASE_RM_LOCK_ID 1 +#define TWOPHASE_RM_PGSTAT_ID 2 +#define TWOPHASE_RM_MULTIXACT_ID 3 +#define TWOPHASE_RM_PREDICATELOCK_ID 4 +#define TWOPHASE_RM_MAX_ID TWOPHASE_RM_PREDICATELOCK_ID + +extern const TwoPhaseCallback g_twophase_recover_callbacks[]; +extern const TwoPhaseCallback g_twophase_postcommit_callbacks[]; +extern const TwoPhaseCallback g_twophase_postabort_callbacks[]; +extern const TwoPhaseCallback g_twophase_standby_recover_callbacks[]; + +extern void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void* data, uint32 len); + +#endif /* TWOPHASE_RMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/valid.h postgresql-hll-2.14/include/include/access/valid.h --- postgresql-hll-2.14_old/include/include/access/valid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/valid.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,56 @@ +/* ------------------------------------------------------------------------- + * + * valid.h + * POSTGRES tuple qualification validity definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/valid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VALID_H +#define VALID_H + +/* + * HeapKeyTest + * + * Test a heap tuple to see if it satisfies a scan key. + */ +#define HeapKeyTest(tuple, tupdesc, nkeys, keys, result) \ + do { \ + /* Use underscores to protect the variables passed in as parameters */ \ + int __cur_nkeys = (nkeys); \ + ScanKey __cur_keys = (keys); \ + \ + (result) = true; /* may change */ \ + for (; __cur_nkeys--; __cur_keys++) { \ + Datum __atp; \ + bool __isnull; \ + Datum __test; \ + \ + if (__cur_keys->sk_flags & SK_ISNULL) { \ + (result) = false; \ + break; \ + } \ + \ + __atp = heap_getattr((tuple), __cur_keys->sk_attno, (tupdesc), &__isnull); \ + \ + if (__isnull) { \ + (result) = false; \ + break; \ + } \ + \ + __test = \ + FunctionCall2Coll(&__cur_keys->sk_func, __cur_keys->sk_collation, __atp, __cur_keys->sk_argument); \ + \ + if (!DatumGetBool(__test)) { \ + (result) = false; \ + break; \ + } \ + } \ + } while (0) + +#endif /* VALID_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/visibilitymap.h postgresql-hll-2.14/include/include/access/visibilitymap.h --- postgresql-hll-2.14_old/include/include/access/visibilitymap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/visibilitymap.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * visibilitymap.h + * visibility map interface + * + * + * Portions Copyright (c) 2007-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/visibilitymap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VISIBILITYMAP_H +#define VISIBILITYMAP_H + +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "utils/relcache.h" + +/* + * Size of the bitmap on each visibility map page, in bytes. There's no + * extra headers, so the whole page minus the standard page header is + * used for the bitmap. + */ +#define MAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData)) + +/* Number of bits allocated for each heap block. */ +#define BITS_PER_HEAPBLOCK 1 + +/* Number of heap blocks we can represent in one byte. */ +#define HEAPBLOCKS_PER_BYTE 8 + +/* Number of heap blocks we can represent in one visibility map page. */ +#define HEAPBLOCKS_PER_PAGE (MAPSIZE * HEAPBLOCKS_PER_BYTE) + +/* Mapping from heap block number to the right bit in the visibility map */ +#define HEAPBLK_TO_MAPBLOCK(x) ((x) / HEAPBLOCKS_PER_PAGE) +#define HEAPBLK_TO_MAPBYTE(x) (((x) % HEAPBLOCKS_PER_PAGE) / HEAPBLOCKS_PER_BYTE) +#define HEAPBLK_TO_MAPBIT(x) ((x) % HEAPBLOCKS_PER_BYTE) + +extern void visibilitymap_clear(Relation rel, BlockNumber heapBlk, Buffer vmbuf); +extern bool visibilitymap_clear_page(Page mappage, BlockNumber heapBlk); + +extern void visibilitymap_pin(Relation rel, BlockNumber heapBlk, Buffer* vmbuf); +extern bool visibilitymap_pin_ok(BlockNumber heapBlk, Buffer vmbuf); + +extern void visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf, XLogRecPtr recptr, Buffer vmbuf, + TransactionId cutoff_xid, bool free_dict); +extern bool visibilitymap_test(Relation rel, BlockNumber heapBlk, Buffer* vmbuf); +extern BlockNumber visibilitymap_count(Relation rel, Partition part); + +extern void visibilitymap_truncate(Relation rel, BlockNumber nheapblocks); +extern BlockNumber VisibilityMapCalTruncBlkNo(BlockNumber relBlkNo); +extern bool visibilitymap_set_page(Page page, BlockNumber heapBlk); +extern void XLogBlockTruncateRelVM(Relation rel, BlockNumber nheapblocks); + +#endif /* VISIBILITYMAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xact.h postgresql-hll-2.14/include/include/access/xact.h --- postgresql-hll-2.14_old/include/include/access/xact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xact.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,436 @@ +/* ------------------------------------------------------------------------- + * + * xact.h + * postgres transaction system definitions + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/access/xact.h + * + * ------------------------------------------------------------------------- + */ +#ifndef XACT_H +#define XACT_H + +#include "access/cstore_am.h" +#include "access/xlogreader.h" +#ifdef PGXC +#include "gtm/gtm_c.h" +#endif +#include "nodes/pg_list.h" +#include "storage/relfilenode.h" +#include "utils/datetime.h" +#include "utils/hsearch.h" +#include "utils/snapshot.h" +#include "utils/plancache.h" +#include "threadpool/threadpool_worker.h" + +/* + * Xact isolation levels + */ +#define XACT_READ_UNCOMMITTED 0 +#define XACT_READ_COMMITTED 1 +#define XACT_REPEATABLE_READ 2 +#define XACT_SERIALIZABLE 3 + +#define SNAPSHOT_UPDATE_NEED_SYNC (1 << 0) +#define SNAPSHOT_NOW_NEED_SYNC (1 << 1) + +/* + * start- and end-of-transaction callbacks for dynamically loaded modules + */ +typedef enum { + XACT_EVENT_START, // For MOT, callback will notify us about new transaction. + XACT_EVENT_COMMIT, + XACT_EVENT_END_TRANSACTION, + XACT_EVENT_RECORD_COMMIT, // For MOT, to write redo and apply changes (after setCommitCsn). + XACT_EVENT_ABORT, + XACT_EVENT_PREPARE, + XACT_EVENT_COMMIT_PREPARED, + XACT_EVENT_ROLLBACK_PREPARED, + XACT_EVENT_PREROLLBACK_CLEANUP // For MOT, to cleanup some internal resources. +} XactEvent; + +typedef void (*XactCallback)(XactEvent event, void* arg); + +typedef enum { + SUBXACT_EVENT_START_SUB, + SUBXACT_EVENT_COMMIT_SUB, + SUBXACT_EVENT_ABORT_SUB +} SubXactEvent; + +typedef void (*SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void* arg); + +#ifdef PGXC +/* + * GTM callback events + */ +typedef enum { + GTM_EVENT_COMMIT, + GTM_EVENT_ABORT, + GTM_EVENT_PREPARE +} GTMEvent; + +typedef void (*GTMCallback)(GTMEvent event, void* arg); +#endif + +/* + * We implement three isolation levels internally. + * The two stronger ones use one snapshot per database transaction; + * the others use one snapshot per statement. + * Serializable uses predicate locks in addition to snapshots. + * These macros should be used to check which isolation level is selected. + */ +#define IsolationUsesXactSnapshot() (u_sess->utils_cxt.XactIsoLevel >= XACT_REPEATABLE_READ) +#define IsolationIsSerializable() (u_sess->utils_cxt.XactIsoLevel == XACT_SERIALIZABLE) + +extern THR_LOCAL bool TwoPhaseCommit; + +typedef enum { + SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */ + SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */ + SYNCHRONOUS_COMMIT_REMOTE_RECEIVE, /* wait for local flush and remote receive */ + SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote write */ + SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */ + SYNCHRONOUS_COMMIT_REMOTE_APPLY, /* wait for local and remote replay */ + SYNCHRONOUS_BAD +} SyncCommitLevel; + +/* Define the default setting for synchonous_commit */ +#define SYNCHRONOUS_COMMIT_ON SYNCHRONOUS_COMMIT_REMOTE_FLUSH + +/* Synchronous commit level */ +extern volatile int synchronous_commit; + +/* ---------------- + * transaction-related XLOG entries + * ---------------- + */ + +/* + * XLOG allows to store some information in high 4 bits of log + * record xl_info field + */ +#define XLOG_XACT_COMMIT 0x00 +#define XLOG_XACT_PREPARE 0x10 +#define XLOG_XACT_ABORT 0x20 +#define XLOG_XACT_COMMIT_PREPARED 0x30 +#define XLOG_XACT_ABORT_PREPARED 0x40 +#define XLOG_XACT_ASSIGNMENT 0x50 +#define XLOG_XACT_COMMIT_COMPACT 0x60 + +typedef struct xl_xact_assignment { + TransactionId xtop; /* assigned XID's top-level XID */ + int nsubxacts; /* number of subtransaction XIDs */ + TransactionId xsub[1]; /* assigned subxids */ +} xl_xact_assignment; + +#define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub) + +typedef struct xl_xact_commit_compact { + TimestampTz xact_time; /* time of commit */ + uint64 csn; /* commit sequence number */ + int nsubxacts; /* number of subtransaction XIDs */ + /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */ + TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_xact_commit_compact; + +#define MinSizeOfXactCommitCompact offsetof(xl_xact_commit_compact, subxacts) + +typedef struct xl_xact_commit { + TimestampTz xact_time; /* time of commit */ + uint64 csn; /* commit sequence number */ + uint64 xinfo; /* info flags */ + int nrels; /* number of RelFileNodes */ + int nsubxacts; /* number of subtransaction XIDs */ + int nmsgs; /* number of shared inval msgs */ + Oid dbId; /* u_sess->proc_cxt.MyDatabaseId */ + Oid tsId; /* u_sess->proc_cxt.MyDatabaseTableSpace */ + int nlibrary; /* number of library */ + /* Array of ColFileNode(s) to drop at commit */ + ColFileNodeRel xnodes[1]; /* VARIABLE LENGTH ARRAY */ + /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */ + /* ARRAY OF SHARED INVALIDATION MESSAGES FOLLOWS */ +} xl_xact_commit; + +#define MinSizeOfXactCommit offsetof(xl_xact_commit, xnodes) + +/* + * These flags are set in the xinfo fields of WAL commit records, + * indicating a variety of additional actions that need to occur + * when emulating transaction effects during recovery. + * They are named XactCompletion... to differentiate them from + * EOXact... routines which run at the end of the original + * transaction completion. + */ +#define XACT_COMPLETION_UPDATE_RELCACHE_FILE 0x01 +#define XACT_COMPLETION_FORCE_SYNC_COMMIT 0x02 +#define XACT_MOT_ENGINE_USED 0x04 + +/* Access macros for above flags */ +#define XactCompletionRelcacheInitFileInval(xinfo) (xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) +#define XactCompletionForceSyncCommit(xinfo) (xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) +#define XactMOTEngineUsed(xinfo) (xinfo & XACT_MOT_ENGINE_USED) + +typedef struct xl_xact_abort { + TimestampTz xact_time; /* time of abort */ + int nrels; /* number of RelFileNodes */ + int nsubxacts; /* number of subtransaction XIDs */ + int nlibrary; /* number of library */ + /* Array of ColFileNode(s) to drop at abort */ + ColFileNodeRel xnodes[1]; /* VARIABLE LENGTH ARRAY */ + /* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */ +} xl_xact_abort; + +/* Note the intentional lack of an invalidation message array c.f. commit */ + +#define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes) + +/* + * COMMIT_PREPARED and ABORT_PREPARED are identical to COMMIT/ABORT records + * except that we have to store the XID of the prepared transaction explicitly + * --- the XID in the record header will be for the transaction doing the + * COMMIT PREPARED or ABORT PREPARED command. + */ + +typedef struct xl_xact_commit_prepared { + TransactionId xid; /* XID of prepared xact */ + xl_xact_commit crec; /* COMMIT record */ + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} xl_xact_commit_prepared; + +#define MinSizeOfXactCommitPrepared offsetof(xl_xact_commit_prepared, crec.xnodes) + +typedef struct xl_xact_abort_prepared { + TransactionId xid; /* XID of prepared xact */ + xl_xact_abort arec; /* ABORT record */ + /* MORE DATA FOLLOWS AT END OF STRUCT */ +} xl_xact_abort_prepared; + +#define MinSizeOfXactAbortPrepared offsetof(xl_xact_abort_prepared, arec.xnodes) + +typedef struct TransactionStateData TransactionStateData; +typedef TransactionStateData* TransactionState; + +extern TransactionId NextXidAfterReovery; +extern TransactionId OldestXidAfterRecovery; +extern volatile bool IsPendingXactsRecoveryDone; + +typedef struct { + TransactionId txnId; + Snapshot snapshot; + + /* Combocid.c */ + HTAB* comboHash; + void* comboCids; /* ComboCidKey */ + int usedComboCids; + int sizeComboCids; + + /* xact.c */ + void* CurrentTransactionState; /* TransactionState */ + SubTransactionId subTransactionId; + SubTransactionId currentSubTransactionId; + CommandId currentCommandId; + TimestampTz xactStartTimestamp; + TimestampTz stmtStartTimestamp; + TimestampTz xactStopTimestamp; + TimestampTz GTMxactStartTimestamp; + TimestampTz stmtSystemTimestamp; + + /* snapmgr.c */ + TransactionId RecentGlobalXmin; + TransactionId TransactionXmin; + TransactionId RecentXmin; + + /* procarray.c */ + TransactionId* allDiffXids; /*different xids between GTM and the local */ + uint32 DiffXidsCount; /*number of different xids between GTM and the local*/ +} StreamTxnContext; + +#define STCSaveElem(dest, src) ((dest) = (src)) +#define STCRestoreElem(dest, src) ((src) = (dest)) + +#ifdef ENABLE_MOT +typedef void (*RedoCommitCallback)(TransactionId xid, void* arg); +void RegisterRedoCommitCallback(RedoCommitCallback callback, void* arg); +void CallRedoCommitCallback(TransactionId xid); +#endif + +typedef enum SavepointStmtType +{ + SUB_STMT_SAVEPOINT, + SUB_STMT_RELEASE, + SUB_STMT_ROLLBACK_TO +} SavepointStmtType; + +/* + * savepoint sent state structure + * It record whether the savepoint cmd has been sent to non-execution cn. + */ +typedef struct SavepointData +{ + char* cmd; + char* name; + bool hasSent; + SavepointStmtType stmtType; + GlobalTransactionId transactionId; +} SavepointData; + +/* ---------------- + * extern definitions + * ---------------- + */ +extern void InitTopTransactionState(void); +extern void InitCurrentTransactionState(void); +extern bool IsTransactionState(void); +extern bool IsAbortedTransactionBlockState(void); +extern void RemoveFromDnHashTable(void); +extern bool WorkerThreadCanSeekAnotherMission(ThreadStayReason* reason); +extern TransactionId GetTopTransactionId(void); +extern TransactionId GetTopTransactionIdIfAny(void); +extern TransactionId GetCurrentTransactionId(void); +extern TransactionId GetCurrentTransactionIdIfAny(void); +extern GTM_TransactionKey GetCurrentTransactionKey(void); +extern GTM_TransactionKey GetCurrentTransactionKeyIfAny(void); +extern GTM_TransactionHandle GetTransactionHandleIfAny(TransactionState s); +extern GTM_TransactionHandle GetCurrentTransactionHandleIfAny(void); +extern GTM_Timeline GetCurrentTransactionTimeline(void); +extern TransactionState GetCurrentTransactionState(void); +extern TransactionId GetParentTransactionIdIfAny(TransactionState s); +extern void ResetTransactionInfo(void); + +#ifdef PGXC /* PGXC_COORD */ +extern TransactionId GetNewGxidGTM(TransactionState s, bool is_sub_xact); +extern bool GetCurrentLocalParamStatus(void); +extern void SetCurrentLocalParamStatus(bool status); +extern GlobalTransactionId GetTopGlobalTransactionId(void); +extern void SetTopGlobalTransactionId(GlobalTransactionId gxid); +#endif +extern TransactionId GetTransactionIdFromGidStr(char* gid); +extern TransactionId GetStableLatestTransactionId(void); +extern SubTransactionId GetCurrentSubTransactionId(void); +extern bool SubTransactionIsActive(SubTransactionId subxid); +extern CommandId GetCurrentCommandId(bool used); +extern TimestampTz GetCurrentTransactionStartTimestamp(void); +extern TimestampTz GetCurrentStatementStartTimestamp(void); +extern TimestampTz GetCurrentStatementLocalStartTimestamp(void); +extern TimestampTz GetCurrentTransactionStopTimestamp(void); +extern void SetCurrentStatementStartTimestamp(); +extern void SetStatementStartTimestamp(TimestampTz timestamp); +#ifdef PGXC +extern TimestampTz GetCurrentGTMStartTimestamp(void); +extern TimestampTz GetCurrentStmtsysTimestamp(void); +extern void SetCurrentGTMTimestamp(TimestampTz timestamp); +extern void SetCurrentStmtTimestamp(TimestampTz timestamp); +void SetCurrentStmtTimestamp(); +extern void SetCurrentGTMDeltaTimestamp(void); +extern void SetStmtSysGTMDeltaTimestamp(void); +extern void CleanGTMDeltaTimeStamp(); +extern void CleanstmtSysGTMDeltaTimeStamp(); +#endif +extern int GetCurrentTransactionNestLevel(void); +extern void MarkCurrentTransactionIdLoggedIfAny(void); +extern void CopyTransactionIdLoggedIfAny(TransactionState state); +extern bool TransactionIdIsCurrentTransactionId(TransactionId xid); +extern void CommandCounterIncrement(void); +extern void ForceSyncCommit(void); +extern void StartTransactionCommand(bool STP_rollback = false); +extern void CommitTransactionCommand(bool STP_commit = false); +extern bool CommitSubTransactionExpectionCheck(void); +extern void SaveCurrentSTPTopTransactionState(); +extern void RestoreCurrentSTPTopTransactionState(); +extern bool IsStpInOuterSubTransaction(); +#ifdef PGXC +extern void AbortCurrentTransactionOnce(void); +#endif +extern void AbortCurrentTransaction(bool STP_rollback = false); +extern void AbortSubTransaction(bool STP_rollback = false); +extern void CleanupSubTransaction(void); +extern void BeginTransactionBlock(void); +extern bool EndTransactionBlock(void); +extern bool PrepareTransactionBlock(const char* gid); +extern void UserAbortTransactionBlock(void); +extern void ReleaseSavepoint(List* options); +extern void DefineSavepoint(const char* name); +extern void RollbackToSavepoint(List* options); +extern void BeginInternalSubTransaction(const char* name); +extern void ReleaseCurrentSubTransaction(void); +extern void RollbackAndReleaseCurrentSubTransaction(void); +extern bool IsSubTransaction(void); +extern void SetCurrentTransactionId(TransactionId tid); +extern bool IsTransactionBlock(void); +extern bool IsTransactionOrTransactionBlock(void); +extern char TransactionBlockStatusCode(void); +extern void AbortOutOfAnyTransaction(bool reserve_topxact_abort = false); +extern void PreventTransactionChain(bool isTopLevel, const char* stmtType); +extern void RequireTransactionChain(bool isTopLevel, const char* stmtType); +extern bool IsInTransactionChain(bool isTopLevel); +extern void RegisterXactCallback(XactCallback callback, void* arg); +extern void UnregisterXactCallback(XactCallback callback, const void* arg); +extern void RegisterSubXactCallback(SubXactCallback callback, void* arg); +extern void UnregisterSubXactCallback(SubXactCallback callback, const void* arg); +extern void CallXactCallbacks(XactEvent event); +extern bool AtEOXact_GlobalTxn(bool commit, bool is_write = false); + +#ifdef PGXC +extern void RegisterGTMCallback(GTMCallback callback, void* arg); +extern void RegisterSequenceCallback(GTMCallback callback, void* arg); +extern void UnregisterGTMCallback(GTMCallback callback, const void* arg); +extern void RegisterTransactionNodes(int count, void** connections, bool write); +extern void PrintRegisteredTransactionNodes(void); +extern void ForgetTransactionNodes(void); +extern void RegisterTransactionLocalNode(bool write); +extern bool IsTransactionLocalNode(bool write); +extern void ForgetTransactionLocalNode(void); +extern bool IsXidImplicit(const char* xid); +extern void SaveReceivedCommandId(CommandId cid); +extern void SetReceivedCommandId(CommandId cid); +extern CommandId GetReceivedCommandId(void); +extern void ReportCommandIdChange(CommandId cid); +extern void ReportTopXid(TransactionId local_top_xid); +extern bool IsSendCommandId(void); +extern void SetSendCommandId(bool status); +extern bool IsPGXCNodeXactReadOnly(void); +extern bool IsPGXCNodeXactDatanodeDirect(void); +#endif + +extern int xactGetCommittedChildren(TransactionId** ptr); + +extern void xact_redo(XLogReaderState* record); +extern void xact_desc(StringInfo buf, XLogReaderState* record); + +extern void xactApplyXLogDropRelation(XLogReaderState* record); + +extern void StreamTxnContextSaveXact(StreamTxnContext* stc); +extern void StreamTxnContextRestoreXact(StreamTxnContext* stc); +extern void StreamTxnContextSetTransactionState(StreamTxnContext* stc); +extern void StreamTxnContextSetSnapShot(void* snapshotPtr); +extern void StreamTxnContextSetMyPgXactXmin(TransactionId xmin); + +extern void WLMTxnContextSetTransactionState(); +extern void parseAndRemoveLibrary(char* library, int nlibrary); +extern bool IsInLiveSubtransaction(); +extern void ExtendCsnlogForSubtrans(TransactionId parent_xid, int nsub_xid, TransactionId* sub_xids); +extern CommitSeqNo SetXact2CommitInProgress(TransactionId xid, CommitSeqNo csn); +extern void XactGetRelFiles(XLogReaderState* record, ColFileNodeRel** xnodesPtr, int* nrelsPtr); +extern HTAB* relfilenode_hashtbl_create(); +extern CommitSeqNo getLocalNextCSN(); +#ifdef ENABLE_MOT +extern bool IsMOTEngineUsed(); +extern bool IsMOTEngineUsedInParentTransaction(); +extern bool IsPGEngineUsed(); +extern bool IsMixedEngineUsed(); +extern void SetCurrentTransactionStorageEngine(StorageEngineType storageEngineType); +#endif + +extern char* GetSavepointName(List* options); +extern void RecordSavepoint(const char* cmd, const char* name, bool hasSent, SavepointStmtType stmtType); +extern void SendSavepointToRemoteCoordinator(); +extern void HandleReleaseOrRollbackSavepoint(const char* cmd, const char* name, SavepointStmtType stmtType); +extern void FreeSavepointList(); + +#endif /* XACT_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlog_basic.h postgresql-hll-2.14/include/include/access/xlog_basic.h --- postgresql-hll-2.14_old/include/include/access/xlog_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlog_basic.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,397 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * 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. + * --------------------------------------------------------------------------------------- + * + * xlog_basic.h + * Some basic definations of xlog operation . + * + * + * IDENTIFICATION + * src/include/access/xlog_basic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOG_BASIC_H +#define XLOG_BASIC_H + +#include "c.h" +#include "access/xlogdefs.h" +#include "storage/relfilenode.h" +#include "access/rmgr.h" +#include "port/pg_crc32c.h" +#include "utils/pg_crc.h" +/* + * These macros encapsulate knowledge about the exact layout of XLog file + * names, timeline history file names, and archive-status file names. + */ +#define MAXFNAMELEN 64 + +/* size of the buffer allocated for error message. */ +#define MAX_ERRORMSG_LEN 1000 + +/* + * Each page of XLOG file has a header like this: + */ +#define XLOG_PAGE_MAGIC 0xD074 /* can be used as WAL version indicator */ +#define XLOG_PAGE_MAGIC_OLD 0xD073 /* can be used as WAL old version indicator */ + +/* + * The XLOG is split into WAL segments (physical files) of the size indicated + * by XLOG_SEG_SIZE. + */ +#define XLogSegSize ((uint32)XLOG_SEG_SIZE) +#define XLogSegmentsPerXLogId (UINT64CONST(0x100000000) / XLOG_SEG_SIZE) +#define XLogRecordMaxSize ((uint32)0x3fffffff) /* 1 gigabyte - 1 */ + +/* Compute XLogRecPtr with segment number and offset. */ +#define XLogSegNoOffsetToRecPtr(segno, offset, dest) (dest) = (segno)*XLOG_SEG_SIZE + (offset) + +/* + * Compute ID and segment from an XLogRecPtr. + * + * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg, + * a boundary byte is taken to be in the previous segment. This is suitable + * for deciding which segment to write given a pointer to a record end, + * for example. + */ +#define XLByteToSeg(xlrp, logSegNo) logSegNo = (xlrp) / XLogSegSize + +#define XLByteToPrevSeg(xlrp, logSegNo) logSegNo = ((xlrp)-1) / XLogSegSize + +/* + * Is an XLogRecPtr within a particular XLOG segment? + * + * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg, + * a boundary byte is taken to be in the previous segment. + */ +#define XLByteInSeg(xlrp, logSegNo) (((xlrp) / XLogSegSize) == (logSegNo)) + +#define XLByteInPrevSeg(xlrp, logSegNo) ((((xlrp)-1) / XLogSegSize) == (logSegNo)) + +/* Check if an XLogRecPtr value is in a plausible range */ +#define XRecOffIsValid(xlrp) ((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD) + +/* + * The XLog directory and control file (relative to $PGDATA) + */ +#define XLOGDIR "pg_xlog" +#define XLOG_CONTROL_FILE "global/pg_control" +#define XLOG_CONTROL_FILE_BAK "global/pg_control.backup" +#define MAX_PAGE_FLUSH_LSN_FILE "global/max_page_flush_lsn" + +#define PG_LSN_XLOG_FLUSH_CHK_FILE "global/pg_lsnxlogflushchk" +#define REDO_STATS_FILE "redo.state" +#define REDO_STATS_FILE_TMP "redo.state.tmp" + + +#define InvalidRepOriginId 0 + +/* + * Block IDs used to distinguish different kinds of record fragments. Block + * references are numbered from 0 to XLR_MAX_BLOCK_ID. A rmgr is free to use + * any ID number in that range (although you should stick to small numbers, + * because the WAL machinery is optimized for that case). A couple of ID + * numbers are reserved to denote the "main" data portion of the record. + * + * The maximum is currently set at 32, quite arbitrarily. Most records only + * need a handful of block references, but there are a few exceptions that + * need more. + */ +#define XLR_MAX_BLOCK_ID 32 + +#define XLR_BLOCK_ID_DATA_SHORT 255 +#define XLR_BLOCK_ID_DATA_LONG 254 +#define XLR_BLOCK_ID_ORIGIN 253 + +/* + * The fork number fits in the lower 4 bits in the fork_flags field. The upper + * bits are used for flags. + */ +#define BKPBLOCK_FORK_MASK 0x0F +#define BKPBLOCK_FLAG_MASK 0xF0 +#define BKPBLOCK_HAS_IMAGE 0x10 /* block data is an XLogRecordBlockImage */ +#define BKPBLOCK_HAS_DATA 0x20 +#define BKPBLOCK_WILL_INIT 0x40 /* redo will re-init the page */ +#define BKPBLOCK_SAME_REL 0x80 /* RelFileNode omitted, same as previous */ + +typedef struct XLogReaderState XLogReaderState; + +/* Function type definition for the read_page callback */ +typedef int (*XLogPageReadCB)(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* readBuf, TimeLineID* pageTLI); + +typedef struct { + /* Is this block ref in use? */ + bool in_use; + + /* Identify the block this refers to */ + RelFileNode rnode; + ForkNumber forknum; + BlockNumber blkno; + + /* copy of the fork_flags field from the XLogRecordBlockHeader */ + uint8 flags; + + /* Information on full-page image, if any */ + bool has_image; + char* bkp_image; + uint16 hole_offset; + uint16 hole_length; + + /* Buffer holding the rmgr-specific data associated with this block */ + bool has_data; + char* data; + uint16 data_len; + uint16 data_bufsz; + XLogRecPtr last_lsn; + uint16 extra_flag; +#ifdef USE_ASSERT_CHECKING + uint8 replayed; +#endif +} DecodedBkpBlock; + +/* + * The overall layout of an XLOG record is: + * Fixed-size header (XLogRecord struct) + * XLogRecordBlockHeader struct + * XLogRecordBlockHeader struct + * ... + * XLogRecordDataHeader[Short|Long] struct + * block data + * block data + * ... + * main data + * + * There can be zero or more XLogRecordBlockHeaders, and 0 or more bytes of + * rmgr-specific data not associated with a block. XLogRecord structs + * always start on MAXALIGN boundaries in the WAL files, but the rest of + * the fields are not aligned. + * + * The XLogRecordBlockHeader, XLogRecordDataHeaderShort and + * XLogRecordDataHeaderLong structs all begin with a single 'id' byte. It's + * used to distinguish between block references, and the main data structs. + */ +typedef struct XLogRecord { + uint32 xl_tot_len; /* total len of entire record */ + uint32 xl_term; + TransactionId xl_xid; /* xact id */ + XLogRecPtr xl_prev; /* ptr to previous record in log */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + int2 xl_bucket_id; + pg_crc32c xl_crc; /* CRC for this record */ + + /* XLogRecordBlockHeaders and XLogRecordDataHeader follow, no padding */ +} XLogRecord; + +typedef struct XLogRecordOld { + uint32 xl_tot_len; /* total len of entire record */ + ShortTransactionId xl_xid; /* xact id */ + XLogRecPtrOld xl_prev; /* ptr to previous record in log */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + /* 2 bytes of padding here, initialize to zero */ + pg_crc32 xl_crc; /* CRC for this record */ +} XLogRecordOld; + +struct XLogReaderState { + /* + * + * Public parameters + * + */ + + /* + * Data input callback (mandatory). + * + * This callback shall read at least reqLen valid bytes of the xlog page + * starting at targetPagePtr, and store them in readBuf. The callback + * shall return the number of bytes read (never more than XLOG_BLCKSZ), or + * -1 on failure. The callback shall sleep, if necessary, to wait for the + * requested bytes to become available. The callback will not be invoked + * again for the same page unless more than the returned number of bytes + * are needed. + * + * targetRecPtr is the position of the WAL record we're reading. Usually + * it is equal to targetPagePtr + reqLen, but sometimes xlogreader needs + * to read and verify the page or segment header, before it reads the + * actual WAL record it's interested in. In that case, targetRecPtr can + * be used to determine which timeline to read the page from. + * + * The callback shall set *pageTLI to the TLI of the file the page was + * read from. It is currently used only for error reporting purposes, to + * reconstruct the name of the WAL file where an error occurred. + */ + XLogPageReadCB read_page; + + /* + * System identifier of the xlog files we're about to read. Set to zero + * (the default value) if unknown or unimportant. + */ + uint64 system_identifier; + + /* + * Opaque data for callbacks to use. Not used by XLogReader. + */ + void* private_data; + + /* + * Start and end point of last record read. EndRecPtr is also used as the + * position to read next, if XLogReadRecord receives an invalid recptr. + */ + XLogRecPtr ReadRecPtr; /* start of last record read */ + XLogRecPtr EndRecPtr; /* end+1 of last record read */ + + RepOriginId record_origin; + + /* ---------------------------------------- + * Decoded representation of current record + * + * Use XLogRecGet* functions to investigate the record; these fields + * should not be accessed directly. + * ---------------------------------------- + */ + XLogRecord* decoded_record; /* currently decoded record */ + + char* main_data; /* record's main data portion */ + uint32 main_data_len; /* main data portion's length */ + uint32 main_data_bufsz; /* allocated size of the buffer */ + + /* information about blocks referenced by the record. */ + DecodedBkpBlock blocks[XLR_MAX_BLOCK_ID + 1]; + + int max_block_id; /* highest block_id in use (-1 if none) */ + + /* ---------------------------------------- + * private/internal state + * ---------------------------------------- + */ + + /* + * Buffer for currently read page (XLOG_BLCKSZ bytes, valid up to at least + * readLen bytes) + */ + char* readBuf; + uint32 readLen; + + /* last read segment, segment offset, TLI for data currently in readBuf */ + XLogSegNo readSegNo; + uint32 readOff; + TimeLineID readPageTLI; + + /* the current read segment, segment offset */ + XLogSegNo curReadSegNo; + uint32 curReadOff; + + /* + * Beginning of prior page read, and its TLI. Doesn't necessarily + * correspond to what's in readBuf; used for timeline sanity checks. + */ + XLogRecPtr latestPagePtr; + TimeLineID latestPageTLI; + + /* beginning of the WAL record being read. */ + XLogRecPtr currRecPtr; + + /* Buffer for current ReadRecord result (expandable) */ + char* readRecordBuf; + uint32 readRecordBufSize; + + /* Buffer to hold error message */ + char* errormsg_buf; + + /* add for batch redo */ + uint32 refcount; + // For parallel recovery + bool isPRProcess; + bool isDecode; + bool isFullSyncCheckpoint; +}; + +#define SizeOfXLogRecord (offsetof(XLogRecord, xl_crc) + sizeof(pg_crc32c)) +#define SizeOfXLogRecordOld (offsetof(XLogRecordOld, xl_crc) + sizeof(pg_crc32)) + +typedef struct XLogPageHeaderData { + uint16 xlp_magic; /* magic value for correctness checks */ + uint16 xlp_info; /* flag bits, see below */ + TimeLineID xlp_tli; /* TimeLineID of first record on page */ + XLogRecPtr xlp_pageaddr; /* XLOG address of this page */ + + /* + * When there is not enough space on current page for whole record, we + * continue on the next page. xlp_rem_len is the number of bytes + * remaining from a previous page. + * + * Note that xl_rem_len includes backup-block data; that is, it tracks + * xl_tot_len not xl_len in the initial header. Also note that the + * continuation data isn't necessarily aligned. + */ + uint32 xlp_rem_len; /* total len of remaining data for record */ +} XLogPageHeaderData; + +#define SizeOfXLogShortPHD MAXALIGN(sizeof(XLogPageHeaderData)) + +typedef XLogPageHeaderData* XLogPageHeader; + +/* + * When the XLP_LONG_HEADER flag is set, we store additional fields in the + * page header. (This is ordinarily done just in the first page of an + * XLOG file.) The additional fields serve to identify the file accurately. + */ +typedef struct XLogLongPageHeaderData { + XLogPageHeaderData std; /* standard header fields */ + uint64 xlp_sysid; /* system identifier from pg_control */ + uint32 xlp_seg_size; /* just as a cross-check */ + uint32 xlp_xlog_blcksz; /* just as a cross-check */ +} XLogLongPageHeaderData; +typedef struct PageLsnInfo +{ + XLogRecPtr max_page_flush_lsn; + pg_crc32c crc; +} PageLsnInfo; + +#define SizeOfXLogLongPHD MAXALIGN(sizeof(XLogLongPageHeaderData)) + +typedef XLogLongPageHeaderData* XLogLongPageHeader; + +/* When record crosses page boundary, set this flag in new page's header */ +#define XLP_FIRST_IS_CONTRECORD 0x0001 +/* This flag indicates a "long" page header */ +#define XLP_LONG_HEADER 0x0002 +/* This flag indicates backup blocks starting in this page are optional */ +#define XLP_BKP_REMOVABLE 0x0004 +/* All defined flag bits in xlp_info (used for validity checking of header) */ +#define XLP_ALL_FLAGS 0x0007 + +/* + * Macros for manipulating XLOG pointers + */ +#define XLogPageHeaderSize(hdr) (((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD) + +/* Align a record pointer to next page */ +#define NextLogPage(recptr) \ + do { \ + if ((recptr) % XLOG_BLCKSZ != 0) \ + XLByteAdvance(recptr, (XLOG_BLCKSZ - (recptr) % XLOG_BLCKSZ)); \ + } while (0) + +/* transform old version LSN into new version. */ +#define XLogRecPtrSwap(x) (((uint64)((x).xlogid)) << 32 | (x).xrecoff) + + + +#endif /* XLOG_BASIC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/access/xlogdefs.h postgresql-hll-2.14/include/include/access/xlogdefs.h --- postgresql-hll-2.14_old/include/include/access/xlogdefs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlogdefs.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,134 @@ +/* + * xlogdefs.h + * + * Postgres transaction log manager record pointer and + * timeline number definitions + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlogdefs.h + */ +#ifndef XLOG_DEFS_H +#define XLOG_DEFS_H + +#include /* need open() flags */ + +typedef struct XLogRecPtrOld { + uint32 xlogid; /* log file #, 0 based */ + uint32 xrecoff; /* byte offset of location in log file */ +} XLogRecPtrOld; + +#define InvalidXLogRecPtrOld \ + (XLogRecPtrOld) \ + { \ + 0, 0 \ + } + +/* + * Pointer to a location in the XLOG. These pointers are 64 bits wide, + * because we don't want them ever to overflow. + */ +typedef uint64 XLogRecPtr; + +/* + * Zero is used indicate an invalid pointer. Bootstrap skips the first possible + * WAL segment, initializing the first WAL page at XLOG_SEG_SIZE, so no XLOG + * record can begin at zero. + */ +#define InvalidXLogRecPtr (XLogRecPtr)0 +#define InvalidXLogSegPtr 0 +const uint32 g_InvalidTermDN = 0; + +#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr) + +/* + * XLogSegNo - physical log file sequence number. + */ +typedef uint64 XLogSegNo; + +/* + * Macros for comparing XLogRecPtrs + */ +#define XLByteLT(a, b) ((a) < (b)) +#define XLByteLE(a, b) ((a) <= (b)) +#define XLByteEQ(a, b) ((a) == (b)) +/* + * Macro for caculate the difference between two given record pointer. + */ +#define XLByteDifference(a, b) (a - b) + +/* + * Macro for advancing a record pointer by the specified number of bytes. + */ +#define XLByteAdvance(recptr, nbytes) (recptr) += nbytes + +/* + * TimeLineID (TLI) - identifies different database histories to prevent + * confusion after restoring a prior state of a database installation. + * TLI does not change in a normal stop/restart of the database (including + * crash-and-recover cases); but we must assign a new TLI after doing + * a recovery to a prior state, a/k/a point-in-time recovery. This makes + * the new WAL logfile sequence we generate distinguishable from the + * sequence that was generated in the previous incarnation. + */ +typedef uint32 TimeLineID; +#define DEFAULT_TIMELINE_ID 1 + +/* + * Replication origin id - this is located in this file to avoid having to + * include origin.h in a bunch of xlog related places. + */ +typedef int RepOriginId; + +/* + * Because O_DIRECT bypasses the kernel buffers, and because we never + * read those buffers except during crash recovery or if wal_level != minimal, + * it is a win to use it in all cases where we sync on each write(). We could + * allow O_DIRECT with fsync(), but it is unclear if fsync() could process + * writes not buffered in the kernel. Also, O_DIRECT is never enough to force + * data to the drives, it merely tries to bypass the kernel cache, so we still + * need O_SYNC/O_DSYNC. + */ +#ifdef O_DIRECT +#define PG_O_DIRECT O_DIRECT +#else +#define PG_O_DIRECT 0 +#endif + +/* + * This chunk of hackery attempts to determine which file sync methods + * are available on the current platform, and to choose an appropriate + * default method. We assume that fsync() is always available, and that + * configure determined whether fdatasync() is. + */ +#if defined(O_SYNC) +#define OPEN_SYNC_FLAG O_SYNC +#elif defined(O_FSYNC) +#define OPEN_SYNC_FLAG O_FSYNC +#endif + +#if defined(O_DSYNC) +#if defined(OPEN_SYNC_FLAG) +/* O_DSYNC is distinct? */ +#if O_DSYNC != OPEN_SYNC_FLAG +#define OPEN_DATASYNC_FLAG O_DSYNC +#endif +#else /* !defined(OPEN_SYNC_FLAG) */ +/* Win32 only has O_DSYNC */ +#define OPEN_DATASYNC_FLAG O_DSYNC +#endif +#endif + +#if defined(PLATFORM_DEFAULT_SYNC_METHOD) +#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD +#elif defined(OPEN_DATASYNC_FLAG) +#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN_DSYNC +#elif defined(HAVE_FDATASYNC) +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#else +#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC +#endif + +#endif /* XLOG_DEFS_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlog.h postgresql-hll-2.14/include/include/access/xlog.h --- postgresql-hll-2.14_old/include/include/access/xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlog.h 2020-12-12 17:06:43.143346696 +0800 @@ -0,0 +1,528 @@ +/* + * xlog.h + * + * PostgreSQL transaction log manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * src/include/access/xlog.h + */ +#ifndef XLOG_H +#define XLOG_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "access/xloginsert.h" +#include "access/xlogreader.h" +#include "catalog/pg_control.h" +#include "datatype/timestamp.h" +#include "lib/stringinfo.h" +#include "access/parallel_recovery/redo_item.h" +#include "knl/knl_instance.h" +#include "access/htup.h" +#include "storage/lwlock.h" + +#include + +/* Sync methods */ +#define SYNC_METHOD_FSYNC 0 +#define SYNC_METHOD_FDATASYNC 1 +#define SYNC_METHOD_OPEN 2 /* for O_SYNC */ +#define SYNC_METHOD_FSYNC_WRITETHROUGH 3 +#define SYNC_METHOD_OPEN_DSYNC 4 /* for O_DSYNC */ + +/* + * Like InRecovery, standbyState is only valid in the startup process. + * In all other processes it will have the value STANDBY_DISABLED (so + * InHotStandby will read as FALSE). + * + * In DISABLED state, we're performing crash recovery or hot standby was + * disabled in postgresql.conf. + * + * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but + * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record + * to initialize our master-transaction tracking system. + * + * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING + * state. The tracked information might still be incomplete, so we can't allow + * connections yet, but redo functions must update the in-memory state when + * appropriate. + * + * In SNAPSHOT_READY mode, we have full knowledge of transactions that are + * (or were) running in the master at the current WAL location. Snapshots + * can be taken, and read-only queries can be run. + */ +typedef enum { + STANDBY_DISABLED, + STANDBY_INITIALIZED, + STANDBY_SNAPSHOT_PENDING, + STANDBY_SNAPSHOT_READY +} HotStandbyState; + +#define InHotStandby (t_thrd.xlog_cxt.standbyState >= STANDBY_SNAPSHOT_PENDING) + +#define DUMMYSTANDBY_CONNECT_INTERVAL 3 // unit second +#define DUMMYSTANDBY_CHECK_INTERVAL 1 // unit second +#define SYNC_DUMMY_STANDBY_END 100 + +#define REP_CONN_ARRAY 2 // support 2 relp connection + +const static XLogRecPtr MAX_XLOG_REC_PTR = (XLogRecPtr)0xFFFFFFFFFFFFFFFF; +extern volatile uint64 sync_system_identifier; + +/* + * Codes indicating where we got a WAL file from during recovery, or where + * to attempt to get one. These are chosen so that they can be OR'd together + * in a bitmask state variable. + */ +#define XLOG_FROM_ARCHIVE (1 << 0) /* Restored using restore_command */ +#define XLOG_FROM_PG_XLOG (1 << 1) /* Existing file in pg_xlog */ +#define XLOG_FROM_STREAM (1 << 2) /* Streamed from master */ + +/* + * Recovery target type. + * Only set during a Point in Time recovery, not when standby_mode = on + */ +typedef enum { + RECOVERY_TARGET_UNSET, + RECOVERY_TARGET_XID, + RECOVERY_TARGET_TIME, + RECOVERY_TARGET_NAME, + RECOVERY_TARGET_LSN +#ifdef PGXC + , + RECOVERY_TARGET_BARRIER +#endif +} RecoveryTargetType; + +/* WAL levels */ +typedef enum WalLevel { + WAL_LEVEL_MINIMAL = 0, + WAL_LEVEL_ARCHIVE, + WAL_LEVEL_HOT_STANDBY, + WAL_LEVEL_LOGICAL +} WalLevel; + +#define XLogArchivingActive() \ + (u_sess->attr.attr_common.XLogArchiveMode && g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_ARCHIVE) +#define XLogArchiveCommandSet() (u_sess->attr.attr_storage.XLogArchiveCommand[0] != '\0') +#define XLogArchiveDestSet() (u_sess->attr.attr_storage.XLogArchiveDest[0] != '\0') + +/* + * Is WAL-logging necessary for archival or log-shipping, or can we skip + * WAL-logging if we fsync() the data before committing instead? + */ +#define XLogIsNeeded() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_ARCHIVE) + +/* + * Is a full-page image needed for hint bit updates? + * + * Normally, we don't WAL-log hint bit updates, but if checksums are enabled, + * we have to protect them against torn page writes. When you only set + * individual bits on a page, it's still consistent no matter what combination + * of the bits make it to disk, but the checksum wouldn't match. Also WAL-log + * them if forced by wal_log_hints=on. + */ +#define XLogHintBitIsNeeded() (g_instance.attr.attr_storage.wal_log_hints) + +/* Do we need to WAL-log information required only for Hot Standby and logical replication? */ +#define XLogStandbyInfoActive() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_HOT_STANDBY) +/* Do we need to WAL-log information required only for logical replication? */ +#define XLogLogicalInfoActive() (g_instance.attr.attr_storage.wal_level >= WAL_LEVEL_LOGICAL) +extern const char* DemoteModeDescs[]; +extern const int DemoteModeNum; + +#define DemoteModeDesc(mode) (((mode) > 0 && (mode) < DemoteModeNum) ? DemoteModeDescs[(mode)] : DemoteModeDescs[0]) + +extern bool XLogBackgroundFlush(void); + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALFlushWaitLock; + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALInitSegLock; + +typedef struct { + LWLock* lock; + PGSemaphoreData sem; +} WALBufferInitWaitLock; + +#define WAL_INSERT_STATUS_ENTRIES 4194304 +#define WAL_NOT_COPIED 0 +#define WAL_COPIED 1 +#define WAL_COPY_SUSPEND (-1) +#define WAL_SCANNED_LRC_INIT (-2) + +/* (ientry + 1) % WAL_INSERT_STATUS_ENTRIES */ +#define GET_NEXT_STATUS_ENTRY(ientry) ((ientry + 1) & (WAL_INSERT_STATUS_ENTRIES - 1)) + +#define GET_STATUS_ENTRY_INDEX(ientry) ientry + +struct WalInsertStatusEntry { + /* The end LSN of the record corresponding to this entry */ + uint64 endLSN; + + /* The log record counter of the record corresponding to this entry */ + int32 LRC; + + /* WAL copy status: "0" - not copied; "1" - copied */ + uint32 status; +}; + +struct WALFlushWaitLockPadded { + WALFlushWaitLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +struct WALBufferInitWaitLockPadded { + WALBufferInitWaitLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +struct WALInitSegLockPadded { + WALInitSegLock l; + char padding[PG_CACHE_LINE_SIZE]; +}; + +/* + * OR-able request flag bits for checkpoints. The "cause" bits are used only + * for logging purposes. Note: the flags must be defined so that it's + * sensible to OR together request flags arising from different requestors. + * + * Note: one exception is CHECKPOINT_FILE_SYNC, with which checkpointer + * will only do file sync operation. Since normal checkpointer process also + * includes file sync, this flag is unset while there are concurrent normal checkpoint + * requests. + */ + +/* These directly affect the behavior of CreateCheckPoint and subsidiaries */ +#define CHECKPOINT_IS_SHUTDOWN 0x0001 /* Checkpoint is for shutdown */ +#define CHECKPOINT_END_OF_RECOVERY \ + 0x0002 /* Like shutdown checkpoint, \ + * but issued at end of WAL \ + * recovery */ +#define CHECKPOINT_FILE_SYNC 0x0004 /* File sync */ +#define CHECKPOINT_IMMEDIATE 0x0008 /* Do it without delays */ +#define CHECKPOINT_FORCE 0x0010 /* Force even if no activity */ +/* These are important to RequestCheckpoint */ +#define CHECKPOINT_WAIT 0x0020 /* Wait for completion */ +/* These indicate the cause of a checkpoint request */ +#define CHECKPOINT_CAUSE_XLOG 0x0040 /* XLOG consumption */ +#define CHECKPOINT_CAUSE_TIME 0x0080 /* Elapsed time */ + +/* Passed to PageListBackWrite() */ +#define CHECKPOINT_BACKWRITE 0x0100 /* checkpoint request */ +#define STRATEGY_BACKWRITE 0x0200 /* strategy backwrite */ +#define LAZY_BACKWRITE 0x0400 /* lazy backwrite */ +#define PAGERANGE_BACKWRITE 0x0800 /* PageRangeBackWrite */ + +/* Checkpoint statistics */ +typedef struct CheckpointStatsData { + TimestampTz ckpt_start_t; /* start of checkpoint */ + TimestampTz ckpt_write_t; /* start of flushing buffers */ + TimestampTz ckpt_sync_t; /* start of fsyncs */ + TimestampTz ckpt_sync_end_t; /* end of fsyncs */ + TimestampTz ckpt_end_t; /* end of checkpoint */ + + int ckpt_bufs_written; /* # of buffers written */ + + int ckpt_segs_added; /* # of new xlog segments created */ + int ckpt_segs_removed; /* # of xlog segments deleted */ + int ckpt_segs_recycled; /* # of xlog segments recycled */ + + int ckpt_sync_rels; /* # of relations synced */ + uint64 ckpt_longest_sync; /* Longest sync for one relation */ + uint64 ckpt_agg_sync_time; /* The sum of all the individual sync + * times, which is not necessarily the + * same as the total elapsed time for + * the entire sync phase. */ +} CheckpointStatsData; + +/* + * Current full page write info we get. forcePageWrites here is different with + * forcePageWrites in XLogInsert, if forcePageWrites sets, we force to write + * the page regardless of the page lsn. + */ +typedef struct XLogFPWInfo { + XLogRecPtr redoRecPtr; + bool doPageWrites; + bool forcePageWrites; +} XLogFPWInfo; + +struct XLogRecData; + +/* + * Shared-memory data structures for XLOG control + * + * LogwrtRqst indicates a byte position that we need to write and/or fsync + * the log up to (all records before that point must be written or fsynced). + * LogwrtResult indicates the byte positions we have already written/fsynced. + * These structs are identical but are declared separately to indicate their + * slightly different functions. + * + * To read XLogCtl->LogwrtResult, you must hold either info_lck or + * WALWriteLock. To update it, you need to hold both locks. The point of + * this arrangement is that the value can be examined by code that already + * holds WALWriteLock without needing to grab info_lck as well. In addition + * to the shared variable, each backend has a private copy of LogwrtResult, + * which is updated when convenient. + * + * The request bookkeeping is simpler: there is a shared XLogCtl->LogwrtRqst + * (protected by info_lck), but we don't need to cache any copies of it. + * + * info_lck is only held long enough to read/update the protected variables, + * so it's a plain spinlock. The other locks are held longer (potentially + * over I/O operations), so we use LWLocks for them. These locks are: + * + * WALInsertLock: must be held to insert a record into the WAL buffers. + * + * WALWriteLock: must be held to write WAL buffers to disk (XLogWrite or + * XLogFlush). + * + * ControlFileLock: must be held to read/update control file or create + * new log file. + * + * CheckpointLock: must be held to do a checkpoint or restartpoint (ensures + * only one checkpointer at a time; currently, with all checkpoints done by + * the checkpointer, this is just pro forma). + * + * ---------- + */ + +typedef struct XLogwrtRqst { + XLogRecPtr Write; /* last byte + 1 to write out */ + XLogRecPtr Flush; /* last byte + 1 to flush */ +} XLogwrtRqst; + +typedef struct XLogwrtResult { + XLogRecPtr Write; /* last byte + 1 written out */ + XLogRecPtr Flush; /* last byte + 1 flushed */ +} XLogwrtResult; + +extern void XLogMultiFileInit(int advance_xlog_file_num); + +typedef struct TermFileData { + uint32 term; + bool finish_redo; +} TermFileData; + +extern void XLogMultiFileInit(int advance_xlog_file_num); +extern XLogRecPtr XLogInsertRecord(struct XLogRecData* rdata, XLogRecPtr fpw_lsn, bool isupgrade = false); +extern void XLogWaitFlush(XLogRecPtr recptr); +extern void XLogWaitBufferInit(XLogRecPtr recptr); +extern void UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force); +extern bool XLogBackgroundFlush(void); +extern bool XLogNeedsFlush(XLogRecPtr RecPtr); +extern int XLogFileInit(XLogSegNo segno, bool* use_existent, bool use_lock); +extern int XLogFileOpen(XLogSegNo segno); + +extern void CheckXLogRemoved(XLogSegNo segno, TimeLineID tli); +extern void XLogSetAsyncXactLSN(XLogRecPtr record); +extern void XLogSetReplicationSlotMinimumLSN(XLogRecPtr lsn); +extern void XLogSetReplicationSlotMaximumLSN(XLogRecPtr lsn); +extern XLogRecPtr XLogGetReplicationSlotMaximumLSN(void); +extern XLogRecPtr XLogGetReplicationSlotMinimumLSNByOther(void); + +extern XLogRecPtr XLogGetLastRemovedSegno(void); +extern void xlog_redo(XLogReaderState* record); +extern void xlog_desc(StringInfo buf, XLogReaderState* record); + +extern void issue_xlog_fsync(int fd, XLogSegNo segno); + +extern bool RecoveryInProgress(void); +extern bool HotStandbyActive(void); +extern bool HotStandbyActiveInReplay(void); +extern bool XLogInsertAllowed(void); +extern void GetXLogReceiptTime(TimestampTz* rtime, bool* fromStream); +extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID* targetTLI, XLogRecPtr* ReplayReadPtr = NULL); +extern void SetXLogReplayRecPtr(XLogRecPtr readRecPtr, XLogRecPtr endRecPtr); +extern void DumpXlogCtl(); + +extern void CheckRecoveryConsistency(void); + +extern XLogRecPtr GetXLogReplayRecPtrInPending(void); +extern XLogRecPtr GetStandbyFlushRecPtr(TimeLineID* targetTLI); +extern XLogRecPtr GetXLogInsertRecPtr(void); +extern XLogRecPtr GetXLogInsertEndRecPtr(void); +extern XLogRecPtr GetXLogWriteRecPtr(void); +extern bool RecoveryIsPaused(void); +extern void SetRecoveryPause(bool recoveryPause); +extern TimestampTz GetLatestXTime(void); +extern TimestampTz GetCurrentChunkReplayStartTime(void); +extern char* XLogFileNameP(TimeLineID tli, XLogSegNo segno); +extern pg_crc32 GetXlogRecordCrc(XLogRecPtr RecPtr, bool& crcvalid); +extern bool IsCheckPoint(XLogReaderState* record); +extern bool IsRestartPointSafe(const XLogRecPtr checkPoint); +extern bool HasTimelineUpdate(XLogReaderState* record, bool bOld); +extern void UpdateTimeline(CheckPoint* checkPoint); + +extern void UpdateControlFile(void); +extern uint64 GetSystemIdentifier(void); +extern void SetSystemIdentifier(uint64 system_identifier); +extern TimeLineID GetThisTimeID(void); +extern void SetThisTimeID(uint64 timelineID); +extern Size XLOGShmemSize(void); +extern void XLOGShmemInit(void); +extern void BootStrapXLOG(void); +extern int XLogSemas(void); +extern void InitWalSemaphores(void); +extern void StartupXLOG(void); +extern void ShutdownXLOG(int code, Datum arg); +extern void InitXLOGAccess(void); +extern void StartupDummyStandby(void); +extern void CreateCheckPoint(int flags); +extern bool CreateRestartPoint(int flags); +extern void XLogPutNextOid(Oid nextOid); +extern XLogRecPtr XLogRestorePoint(const char* rpName); +extern void UpdateFullPageWrites(void); +extern void GetFullPageWriteInfo(XLogFPWInfo* fpwInfo_p); +extern XLogRecPtr GetRedoRecPtr(void); +extern XLogRecPtr GetInsertRecPtr(void); +extern XLogRecPtr GetFlushRecPtr(void); +extern TimeLineID GetRecoveryTargetTLI(void); +extern void DummyStandbySetRecoveryTargetTLI(TimeLineID timeLineID); + +extern bool CheckFinishRedoSignal(void); +extern bool CheckPromoteSignal(void); +extern bool CheckPrimarySignal(void); +extern bool CheckStandbySignal(void); +extern bool CheckNormalSignal(void); +extern int CheckSwitchoverSignal(void); + +extern void WakeupRecovery(void); +extern void WakeupDataRecovery(void); +extern void SetWalWriterSleeping(bool sleeping); +extern uint64 XLogDiff(XLogRecPtr end, XLogRecPtr start); + +extern bool CheckFpwBeforeFirstCkpt(void); +extern void DisableFpwBeforeFirstCkpt(void); + +extern Size LsnXlogFlushChkShmemSize(void); +extern void LsnXlogFlushChkShmInit(void); +extern void heap_xlog_logical_new_page(XLogReaderState* record); +extern bool IsServerModeStandby(void); + +extern void SetCBMTrackedLSN(XLogRecPtr trackedLSN); +extern XLogRecPtr GetCBMTrackedLSN(void); +extern XLogRecPtr GetCBMRotateLsn(void); +void SetCBMRotateLsn(XLogRecPtr rotate_lsn); +extern void SetCBMFileStartLsn(XLogRecPtr currCbmNameStartLsn); +extern XLogRecPtr GetCBMFileStartLsn(void); + +extern void SetDelayXlogRecycle(bool toDelay, bool isRedo = false); +extern bool GetDelayXlogRecycle(void); +extern void SetDDLDelayStartPtr(XLogRecPtr ddlDelayStartPtr); +extern XLogRecPtr GetDDLDelayStartPtr(void); +extern void heap_xlog_bcm_new_page(xl_heap_logical_newpage* xlrec, RelFileNode node, char* cuData); + +/* + * Starting/stopping a base backup + */ +extern XLogRecPtr do_pg_start_backup(const char* backupidstr, bool fast, char** labelfile, DIR* tblspcdir, + char** tblspcmapfile, List** tablespaces, bool infotbssize, bool needtblspcmapfile); +extern void set_start_backup_flag(bool startFlag); +extern bool get_startBackup_flag(void); +extern bool check_roach_start_backup(const char *slotName); +extern bool GetDelayXlogRecycle(void); +extern XLogRecPtr GetDDLDelayStartPtr(void); +extern XLogRecPtr do_pg_stop_backup(char* labelfile, bool waitforarchive); +extern void do_pg_abort_backup(void); +extern void enable_delay_xlog_recycle(bool isRedo = false); +extern void disable_delay_xlog_recycle(bool isRedo = false); +extern void startupInitDelayXlog(void); +extern XLogRecPtr enable_delay_ddl_recycle(void); +extern char* getLastRewindTime(); +extern void disable_delay_ddl_recycle(XLogRecPtr barrierLSN, bool isForce, XLogRecPtr* startLSN, XLogRecPtr* endLSN); +extern void startupInitDelayDDL(void); +extern void execDelayedDDL(XLogRecPtr startLSN, XLogRecPtr endLSN, bool ignoreCBMErr); +extern bool IsRoachRestore(void); +extern XLogRecPtr do_roach_start_backup(const char *backupidstr); +extern XLogRecPtr do_roach_stop_backup(const char *backupidstr); +extern XLogRecPtr enable_delay_ddl_recycle_with_slot(const char* slotname); +extern void disable_delay_ddl_recycle_with_slot(const char* slotname, XLogRecPtr *startLSN, XLogRecPtr *endLSN); + +extern void CloseXlogFilesAtThreadExit(void); +extern void SetLatestXTime(TimestampTz xtime); +extern CheckPoint update_checkpoint(XLogReaderState* record); +XLogRecord* XLogParallelReadNextRecord(XLogReaderState* xlogreader); + +void ResourceManagerStartup(void); +void ResourceManagerStop(void); +void rm_redo_error_callback(void* arg); +extern void load_server_mode(void); +extern void WaitCheckpointSync(void); +extern void btree_clear_imcompleteAction(); +extern void update_max_page_flush_lsn(XLogRecPtr biggest_lsn, ThreadId thdId, bool is_force); +extern void set_global_max_page_flush_lsn(XLogRecPtr lsn); +XLogRecPtr get_global_max_page_flush_lsn(); +void GetRecoveryLatch(); +void ReLeaseRecoveryLatch(); +void ExtremRtoUpdateMinCheckpoint(); +bool IsRecoveryDone(); + +void CopyXlogForForceFinishRedo(XLogSegNo logSegNo, uint32 termId, XLogReaderState *xlogreader, + XLogRecPtr lastRplEndLsn); +void RenameXlogForForceFinishRedo(XLogSegNo beginSegNo, TimeLineID tli, uint32 termId); +void ReOpenXlog(XLogReaderState *xlogreader); +void SetSwitchHistoryFile(XLogRecPtr switchLsn, XLogRecPtr catchLsn, uint32 termId); +void CheckMaxPageFlushLSN(XLogRecPtr reqLsn); +bool CheckForForceFinishRedoTrigger(TermFileData *term_file); + +extern XLogRecPtr XlogRemoveSegPrimary; + +/* File path names (all relative to $PGDATA) */ +#define BACKUP_LABEL_FILE "backup_label" +#define DISABLE_CONN_FILE "disable_conn_file" +#define BACKUP_LABEL_OLD "backup_label.old" +#define BACKUP_LABEL_FILE_ROACH "backup_label.roach" +#define BACKUP_LABEL_FILE_ROACH_DONE "backup_label.roach.done" +#define DELAY_XLOG_RECYCLE_FILE "delay_xlog_recycle" +#define DELAY_DDL_RECYCLE_FILE "delay_ddl_recycle" +#define REWIND_LABLE_FILE "rewind_lable" + +typedef struct delayddlrange { + XLogRecPtr startLSN; + XLogRecPtr endLSN; +} DelayDDLRange; + +#define InvalidDelayRange \ + (DelayDDLRange) \ + { \ + InvalidXLogRecPtr, InvalidXLogRecPtr \ + } +#define DISABLE_DDL_DELAY_TIMEOUT 1800000 +#define ENABLE_DDL_DELAY_TIMEOUT 60000 + +#define TABLESPACE_MAP "tablespace_map" +#define TABLESPACE_MAP_OLD "tablespace_map.old" + +#define ROACH_BACKUP_PREFIX "gs_roach" +#define ROACH_FULL_BAK_PREFIX "gs_roach_full" +#define ROACH_INC_BAK_PREFIX "gs_roach_inc" + +static const uint64 INVALID_READ_OFF = 0xFFFFFFFF; + +inline bool force_finish_enabled() +{ + return (g_instance.attr.attr_storage.enable_update_max_page_flush_lsn != 0); +} + + + +#define TABLESPACE_MAP "tablespace_map" +#define TABLESPACE_MAP_OLD "tablespace_map.old" + +static inline void WakeupWalSemaphore(PGSemaphore sema) +{ + PGSemaphoreReset(sema); + PGSemaphoreUnlock(sema); +} + + +#endif /* XLOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xloginsert.h postgresql-hll-2.14/include/include/access/xloginsert.h --- postgresql-hll-2.14_old/include/include/access/xloginsert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xloginsert.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,60 @@ +/* --------------------------------------------------------------------------------------- + * + * xloginsert.h + * Functions for generating WAL records + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/xloginsert.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGINSERT_H +#define XLOGINSERT_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/relfilenode.h" + +/* + * The minimum size of the WAL construction working area. If you need to + * register more than XLR_NORMAL_MAX_BLOCK_ID block references or have more + * than XLR_NORMAL_RDATAS data chunks in a single WAL record, you must call + * XLogEnsureRecordSpace() first to allocate more working memory. + */ +#define XLR_NORMAL_MAX_BLOCK_ID 4 +#define XLR_NORMAL_RDATAS 20 + +/* flags for XLogRegisterBuffer */ +#define REGBUF_FORCE_IMAGE 0x01 /* force a full-page image */ +#define REGBUF_NO_IMAGE 0x02 /* don't take a full-page image */ +#define REGBUF_WILL_INIT \ + (0x04 | 0x02) /* page will be re-initialized at \ + * replay (implies NO_IMAGE) */ +#define REGBUF_STANDARD \ + 0x08 /* page follows "standard" page layout, \ + * (data between pd_lower and pd_upper \ + * will be skipped) */ +#define REGBUF_KEEP_DATA \ + 0x10 /* include data even if a full-page image \ + * is taken */ +/* prototypes for public functions in xloginsert.c: */ +extern void XLogBeginInsert(void); +extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, bool isupgrade = false, int bucket_id = InvalidBktId); +extern void XLogEnsureRecordSpace(int nbuffers, int ndatas); +extern void XLogRegisterData(char* data, int len); +extern void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags); +extern void XLogRegisterBlock( + uint8 block_id, RelFileNode* rnode, ForkNumber forknum, BlockNumber blknum, char* page, uint8 flags); +extern void XLogRegisterBufData(uint8 block_id, char* data, int len); +extern void XLogResetInsertion(void); +extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std); +extern void InitXLogInsert(void); +extern void XLogIncludeOrigin(void); + +#endif /* XLOGINSERT_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlog_internal.h postgresql-hll-2.14/include/include/access/xlog_internal.h --- postgresql-hll-2.14_old/include/include/access/xlog_internal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlog_internal.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,275 @@ +/* + * xlog_internal.h + * + * PostgreSQL transaction log internal declarations + * + * NOTE: this file is intended to contain declarations useful for + * manipulating the XLOG files directly, but it is not supposed to be + * needed by rmgr routines (redo support for individual record types). + * So the XLogRecord typedef and associated stuff appear in xlogrecord.h. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlog_internal.h + */ +#ifndef XLOG_INTERNAL_H +#define XLOG_INTERNAL_H + +#include "access/xlogdefs.h" +#include "access/xlogreader.h" +#include "access/xlog_basic.h" +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "pgtime.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/buf.h" + +/* + * if ValidateXlogRecord Failed in XLOG_FROM_STREAM source, the unexpected + * walreceiver shutdown will be caused. To avoid this, add retry for readrecord in xlog redo + */ +#define XLOG_STREAM_READREC_MAXTRY 10 +#define XLOG_STREAM_READREC_INTERVAL 100 * 1000L + +#ifndef FRONTEND +/* Compute the xlog filename with timelineId and segment number.*/ +#define XLogFileName(fname, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute xlog file path with timelineId and segment number. */ +#define XLogFilePath(path, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) +#else +#define XLOG_FNAME_LEN 24 +#define IsXLogFileName(fname) \ + (strlen(fname) == XLOG_FNAME_LEN && \ + strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN) + +#define IsPartialXLogFileName(fname) \ + (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") && \ + strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \ + strcmp((fname) + XLOG_FNAME_LEN, ".partial") == 0) + +#define IsTLHistoryFileName(fname) \ + (strlen(fname) == 8 + strlen(".history") && \ + strspn(fname, "0123456789ABCDEF") == 8 && \ + strcmp((fname) + 8, ".history") == 0) + +#define IsBackupHistoryFileName(fname) \ + (strlen(fname) > XLOG_FNAME_LEN && \ + strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \ + strcmp((fname) + strlen(fname) - strlen(".backup"), ".backup") == 0) + +#define XLogFileName(fname, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss_c(nRet, "\0", "\0"); \ + } while (0) + +#define XLogFilePath(path, tli, logSegNo) \ + do { \ + int nRet; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId)); \ + securec_check_ss_c(nRet, "\0", "\0"); \ + } while (0) +#endif + +/* compute the xlog segment number with xlog filename and timelineId. */ +#define XLogFromFileName(fname, tli, logSegNo) \ + do { \ + uint32 log; \ + uint32 seg; \ + int ret; \ + ret = sscanf_s(fname, "%08X%08X%08X", tli, &log, &seg); \ + securec_check_for_sscanf_s(ret, 3, "\0", "\0"); \ + *logSegNo = (uint64)log * XLogSegmentsPerXLogId + seg; \ + } while (0) + +/* compute history filename with timelineID. */ +#define TLHistoryFileName(fname, tli) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(fname, MAXFNAMELEN, MAXFNAMELEN - 1, "%08X.history", tli); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute history filepath with timelineID. */ +#define TLHistoryFilePath(path, tli) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, MAXPGPATH, MAXPGPATH - 1, XLOGDIR "/%08X.history", tli); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* compute status filePath with xlog name and suffix. */ +#define StatusFilePath(path, xlog, suffix) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, MAXPGPATH, MAXPGPATH - 1, XLOGDIR "/archive_status/%s%s", xlog, suffix); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/*compute backup history filename with timelineID, segment number and offset. */ +#define BackupHistoryFileName(fname, tli, logSegNo, offset) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(fname, \ + MAXFNAMELEN, \ + MAXFNAMELEN - 1, \ + "%08X%08X%08X.%08X.backup", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId), \ + offset); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/**/ +#define BackupHistoryFilePath(path, tli, logSegNo, offset) \ + do { \ + int nRet = 0; \ + nRet = snprintf_s(path, \ + MAXPGPATH, \ + MAXPGPATH - 1, \ + XLOGDIR "/%08X%08X%08X.%08X.backup", \ + tli, \ + (uint32)((logSegNo) / XLogSegmentsPerXLogId), \ + (uint32)((logSegNo) % XLogSegmentsPerXLogId), \ + offset); \ + securec_check_ss(nRet, "\0", "\0"); \ + } while (0) + +/* + * Information logged when we detect a change in one of the parameters + * important for Hot Standby. + */ +typedef struct xl_parameter_change { + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + int wal_level; +} xl_parameter_change; + +/* logs restore point */ +typedef struct xl_restore_point { + TimestampTz rp_time; + char rp_name[MAXFNAMELEN]; +} xl_restore_point; + +/* + * The functions in xloginsert.c construct a chain of XLogRecData structs + * to represent the final WAL record. + */ +typedef struct XLogRecData { + struct XLogRecData* next; /* next struct in chain, or NULL */ + char* data; /* start of rmgr data to include */ + uint32 len; /* length of rmgr data to include */ + Buffer buffer; /* buffer associated with data, if any */ +} XLogRecData; + +/* + * Method table for resource managers. + * + * This struct must be kept in sync with the PG_RMGR definition in + * rmgr.cpp. + * + * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). + */ +typedef struct RmgrData { + const char* rm_name; + void (*rm_redo)(XLogReaderState* record); + void (*rm_desc)(StringInfo buf, XLogReaderState* record); + void (*rm_startup)(void); + void (*rm_cleanup)(void); + bool (*rm_safe_restartpoint)(void); +} RmgrData; + +/* + * New XLogCtlInsert Structure. + */ +struct Combined128 { + uint64 currentBytePos; + uint32 byteSize; + int32 LRC; +}; +union Union128 { + uint128_u value; + struct Combined128 struct128; +}; + +extern const RmgrData RmgrTable[]; + +/* + * Exported to support xlog switching from checkpointer + */ +extern pg_time_t GetLastSegSwitchTime(void); +extern XLogRecPtr RequestXLogSwitch(void); + +/* + * Exported to support xlog archive status setting from WALReceiver + */ +extern void XLogArchiveForceDone(const char* xlog); + +/* + * These aren't in xlog.h because I'd rather not include fmgr.h there. + */ +extern Datum pg_start_backup(PG_FUNCTION_ARGS); +extern Datum pg_stop_backup(PG_FUNCTION_ARGS); +extern Datum gs_roach_stop_backup(PG_FUNCTION_ARGS); +extern Datum pg_switch_xlog(PG_FUNCTION_ARGS); +extern Datum gs_roach_switch_xlog(PG_FUNCTION_ARGS); +extern Datum pg_create_restore_point(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_location(PG_FUNCTION_ARGS); +extern Datum pg_current_xlog_insert_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_receive_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xlog_replay_location(PG_FUNCTION_ARGS); +extern Datum pg_last_xact_replay_timestamp(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name_offset(PG_FUNCTION_ARGS); +extern Datum pg_xlogfile_name(PG_FUNCTION_ARGS); +extern Datum pg_is_in_recovery(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_pause(PG_FUNCTION_ARGS); +extern Datum pg_xlog_replay_resume(PG_FUNCTION_ARGS); +extern Datum pg_is_xlog_replay_paused(PG_FUNCTION_ARGS); +extern Datum pg_xlog_location_diff(PG_FUNCTION_ARGS); + +int XLogPageRead(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, + char* readBuf, TimeLineID* readTLI); +bool XLogReadFromWriteBuffer(XLogRecPtr targetStartPtr, int reqLen, char* readBuf, uint32 *rereadlen); + +#endif /* XLOG_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlogproc.h postgresql-hll-2.14/include/include/access/xlogproc.h --- postgresql-hll-2.14_old/include/include/access/xlogproc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlogproc.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,920 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * xlogproc.h + * + * + * IDENTIFICATION + * src/include/access/xlogproc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef XLOG_PROC_H +#define XLOG_PROC_H +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "access/xlogreader.h" +#include "storage/bufmgr.h" +#include "access/xlog_basic.h" +#include "access/xlogutils.h" +#include "access/clog.h" + +#ifndef byte +#define byte unsigned char +#endif + +typedef void (*relasexlogreadstate)(void* record); +/* **************define for parse end******************************* */ +#define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a)) + +/* for common blockhead begin */ + +#define XLogBlockHeadGetInfo(blockhead) ((blockhead)->xl_info) +#define XLogBlockHeadGetXid(blockhead) ((blockhead)->xl_xid) +#define XLogBlockHeadGetRmid(blockhead) ((blockhead)->xl_rmid) + +#define XLogBlockHeadGetLSN(blockhead) ((blockhead)->end_ptr) +#define XLogBlockHeadGetRelNode(blockhead) ((blockhead)->relNode) +#define XLogBlockHeadGetSpcNode(blockhead) ((blockhead)->spcNode) +#define XLogBlockHeadGetDbNode(blockhead) ((blockhead)->dbNode) +#define XLogBlockHeadGetForkNum(blockhead) ((blockhead)->forknum) +#define XLogBlockHeadGetBlockNum(blockhead) ((blockhead)->blkno) +#define XLogBlockHeadGetBucketId(blockhead) ((blockhead)->bucketNode) +#define XLogBlockHeadGetValidInfo(blockhead) ((blockhead)->block_valid) + +/* for common blockhead end */ + +/* for block data beging */ +#define XLogBlockDataHasBlockImage(blockdata) ((blockdata)->blockhead.has_image) +#define XLogBlockDataHasBlockData(blockdata) ((blockdata)->blockhead.has_data) +#define XLogBlockDataGetLastBlockLSN(_blockdata) ((_blockdata)->blockdata.last_lsn) +#define XLogBlockDataGetBlockFlags(blockdata) ((blockdata)->blockhead.flags) + +#define XLogBlockDataGetBlockId(blockdata) ((blockdata)->blockhead.cur_block_id) +#define XLogBlockDataGetAuxiBlock1(blockdata) ((blockdata)->blockhead.auxiblk1) +#define XLogBlockDataGetAuxiBlock2(blockdata) ((blockdata)->blockhead.auxiblk2) +/* for block data end */ + +typedef struct { + RelFileNode rnode; + ForkNumber forknum; + BlockNumber blkno; +} RedoBufferTag; + +typedef struct { + Page page; // pagepointer + Size pagesize; +} RedoPageInfo; + +typedef struct { + XLogRecPtr lsn; /* block cur lsn */ + Buffer buf; + RedoBufferTag blockinfo; + RedoPageInfo pageinfo; + int dirtyflag; /* true if the buffer changed */ +} RedoBufferInfo; + +#define MakeRedoBufferDirty(bufferinfo) ((bufferinfo)->dirtyflag = true) +#define RedoBufferDirtyClear(bufferinfo) ((bufferinfo)->dirtyflag = false) +#define IsRedoBufferDirty(bufferinfo) ((bufferinfo)->dirtyflag == true) + +#define RedoMemIsValid(memctl, bufferid) (((bufferid) > InvalidBuffer) && ((bufferid) <= (memctl->totalblknum))) + +typedef struct { + RedoBufferTag blockinfo; + pg_atomic_uint32 state; +} RedoBufferDesc; + +typedef struct { + Buffer buff_id; + pg_atomic_uint32 state; +} ParseBufferDesc; + +#define RedoBufferSlotGetBuffer(bslot) ((bslot)->buf_id) + +#define EnalbeWalLsnCheck true + +#pragma pack(push, 1) + +#define INVALID_BLOCK_ID (XLR_MAX_BLOCK_ID + 2) + +#define LOW_BLOKNUMBER_BITS (32) +#define LOW_BLOKNUMBER_MASK (((uint64)1 << 32) - 1) + + +/* ********BLOCK COMMON HEADER BEGIN ***************** */ +typedef enum { + BLOCK_DATA_MAIN_DATA_TYPE = 0, /* BLOCK DATA */ + BLOCK_DATA_VM_TYPE, /* VM */ + BLOCK_DATA_FSM_TYPE, /* FSM */ + BLOCK_DATA_DDL_TYPE, /* DDL */ + BLOCK_DATA_BCM_TYPE, /* bcm */ + BLOCK_DATA_NEWCU_TYPE, /* cu newlog */ + BLOCK_DATA_CLOG_TYPE, /* CLog */ + BLOCK_DATA_MULITACT_OFF_TYPE, /* MultiXact */ + BLOCK_DATA_MULITACT_MEM_TYPE, + BLOCK_DATA_CSNLOG_TYPE, /* CSNLog */ + /* *****xact don't need sent to dfv */ + BLOCK_DATA_MULITACT_UPDATEOID_TYPE, + BLOCK_DATA_XACTDATA_TYPE, /* XACT */ + BLOCK_DATA_RELMAP_TYPE, /* RELMAP */ + BLOCK_DATA_SLOT_TYPE, + BLOCK_DATA_BARRIER_TYPE, + BLOCK_DATA_PREPARE_TYPE, /* prepare */ + BLOCK_DATA_INVALIDMSG_TYPE, /* INVALIDMSG */ + BLOCK_DATA_INCOMPLETE_TYPE, + BLOCK_DATA_VACUUM_PIN_TYPE, + BLOCK_DATA_XLOG_COMMON_TYPE, + BLOCK_DATA_CREATE_DATABASE_TYPE, + BLOCK_DATA_DROP_DATABASE_TYPE, + BLOCK_DATA_CREATE_TBLSPC_TYPE, + BLOCK_DATA_DROP_TBLSPC_TYPE, + BLOCK_DATA_DROP_SLICE_TYPE, +} XLogBlockParseEnum; + +/* ********BLOCK COMMON HEADER END ***************** */ + +/* **************define for parse begin ******************************* */ + +/* ********BLOCK DATE BEGIN ***************** */ + +typedef struct { + uint8 cur_block_id; /* blockid */ + uint8 flags; + uint8 has_image; + uint8 has_data; + BlockNumber auxiblk1; + BlockNumber auxiblk2; +} XLogBlocDatakHead; + +#define XLOG_BLOCK_DATAHEAD_LEN sizeof(XLogBlocDatakHead) + +typedef struct { + uint16 extra_flag; + uint16 hole_offset; + uint16 hole_length; /* image position */ + uint16 data_len; /* data length */ + XLogRecPtr last_lsn; + char* bkp_image; + char* data; +} XLogBlockData; + +#define XLOG_BLOCK_DATA_LEN sizeof(XLogBlockData) + +typedef struct { + XLogBlocDatakHead blockhead; + XLogBlockData blockdata; + uint32 main_data_len; /* main data portion's length */ + char* main_data; /* point to XLogReaderState's main_data */ +} XLogBlockDataParse; +/* ********BLOCK DATE END ***************** */ +#define XLOG_BLOCK_DATA_PARSE_LEN sizeof(XLogBlockDataParse) + +/* ********BLOCK DDL BEGIN ***************** */ +typedef enum { + BLOCK_DDL_TYPE_NONE = 0, + BLOCK_DDL_CREATE_RELNODE, + BLOCK_DDL_DROP_RELNODE, + BLOCK_DDL_EXTEND_RELNODE, + BLOCK_DDL_TRUNCATE_RELNODE, + BLOCK_DDL_CLOG_ZERO, + BLOCK_DDL_CLOG_TRUNCATE, + BLOCK_DDL_MULTIXACT_OFF_ZERO, + BLOCK_DDL_MULTIXACT_MEM_ZERO +} XLogBlockDdlInfoEnum; + +typedef struct { + uint32 blockddltype; + uint32 columnrel; + Oid ownerid; + char *mainData; +} XLogBlockDdlParse; + +/* ********BLOCK DDL END ***************** */ + +/* ********BLOCK CLOG BEGIN ***************** */ + +#define MAX_BLOCK_XID_NUMS (28) +typedef struct { + TransactionId topxid; + uint16 status; + uint16 xidnum; + uint16 xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockCLogParse; + +/* ********BLOCK CLOG END ***************** */ + +/* ********BLOCK CSNLOG BEGIN ***************** */ +typedef struct { + TransactionId topxid; + CommitSeqNo cslseq; + uint32 xidnum; + uint16 xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockCSNLogParse; + +/* ********BLOCK CSNLOG END ***************** */ + +/* ********BLOCK prepare BEGIN ***************** */ +struct TwoPhaseFileHeader; + +typedef struct { + TransactionId maxxid; + Size maindatalen; + char* maindata; +} XLogBlockPrepareParse; + +/* ********BLOCK prepare END ***************** */ + +/* ********BLOCK Bcm BEGIN ***************** */ +typedef struct { + uint64 startblock; + int count; + int status; +} XLogBlockBcmParse; + +/* ********BLOCK Bcm END ***************** */ + +/* ********BLOCK Vm BEGIN ***************** */ +typedef struct { + BlockNumber heapBlk; +} XLogBlockVmParse; + +#define XLOG_BLOCK_VM_PARSE_LEN sizeof(XLogBlockVmParse) +/* ********BLOCK Vm END ***************** */ + +/* ********BLOCK NewCu BEGIN ***************** */ +typedef struct { + uint32 main_data_len; /* main data portion's length */ + char* main_data; /* point to XLogReaderState's main_data */ +} XLogBlockNewCuParse; + + +/* ********BLOCK NewCu END ***************** */ + +/* ********BLOCK InvalidMsg BEGIN ***************** */ +typedef struct { + TransactionId cutoffxid; +} XLogBlockInvalidParse; + +/* ********BLOCK InvalidMsg END ***************** */ + +/* ********BLOCK Incomplete BEGIN ***************** */ + +typedef enum { + INCOMPLETE_ACTION_LOG = 0, + INCOMPLETE_ACTION_FORGET +} XLogBlockIncompleteEnum; + +typedef struct { + uint16 action; /* split or delete */ + bool issplit; + bool isroot; + BlockNumber downblk; + BlockNumber leftblk; + BlockNumber rightblk; +} XLogBlockIncompleteParse; + +/* ********BLOCK Incomplete END ***************** */ + +/* ********BLOCK VacuumPin BEGIN ***************** */ +typedef struct { + BlockNumber lastBlockVacuumed; +} XLogBlockVacuumPinParse; + +/* ********BLOCK XLOG Common BEGIN ***************** */ +typedef struct { + XLogRecPtr readrecptr; + Size maindatalen; + char* maindata; +} XLogBlockXLogComParse; + +/* ********BLOCK XLOG Common END ***************** */ + +/* ********BLOCK DataBase BEGIN ***************** */ +typedef struct { + Oid src_db_id; + Oid src_tablespace_id; +} XLogBlockDataBaseParse; + +/* ********BLOCK DataBase Common END ***************** */ + +/* ********BLOCK table spc BEGIN ***************** */ +typedef struct { + char* tblPath; + bool isRelativePath; +} XLogBlockTblSpcParse; + +/* ********BLOCK table spc END ***************** */ + +/* ********BLOCK Multi Xact Offset BEGIN ***************** */ +typedef struct { + MultiXactId multi; + MultiXactOffset moffset; +} XLogBlockMultiXactOffParse; + +/* ********BLOCK Multi Xact Offset END ***************** */ + +/* ********BLOCK Multi Xact Mem BEGIN ***************** */ +typedef struct { + MultiXactId multi; + MultiXactOffset startoffset; + uint64 xidnum; + TransactionId xidsarry[MAX_BLOCK_XID_NUMS]; +} XLogBlockMultiXactMemParse; +/* ********BLOCK Multi Xact Mem END ***************** */ + +/* ********BLOCK Multi Xact update oid BEGIN ***************** */ +typedef struct { + MultiXactId nextmulti; + MultiXactOffset nextoffset; + TransactionId maxxid; +} XLogBlockMultiUpdateParse; +/* ********BLOCK Multi Xact update oid END ***************** */ + +/* ********BLOCK rel map BEGIN ***************** */ +typedef struct { + Size maindatalen; + char* maindata; +} XLogBlockRelMapParse; +/* ********BLOCK rel map END ***************** */ + +typedef struct { + uint32 xl_term; +} XLogBlockRedoHead; + +#define XLogRecRedoHeadEncodeSize (offsetof(XLogBlockRedoHead, refrecord)) +typedef struct { + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; /* copy from XLogReaderState's EndRecPtr */ + BlockNumber blkno; + Oid relNode; /* relation */ + uint16 block_valid; /* block data validinfo see XLogBlockInfoEnum */ + uint8 xl_info; /* flag bits, see below */ + RmgrId xl_rmid; /* resource manager for this record */ + ForkNumber forknum; + TransactionId xl_xid; /* xact id */ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + int4 bucketNode; /* bucket */ +} XLogBlockHead; + +#define XLogBlockHeadEncodeSize (sizeof(XLogBlockHead)) + +#define BYTE_NUM_BITS (8) +#define BYTE_MASK (0xFF) +#define U64_BYTES_NUM (8) +#define U32_BYTES_NUM (4) +#define U16_BYTES_NUM (2) +#define U8_BYTES_NUM (1) + +#define U32_BITS_NUM (BYTE_NUM_BITS * U32_BYTES_NUM) + +extern uint64 XLog_Read_N_Bytes(char* buffer, Size buffersize, Size readbytes); + +#define XLog_Read_1_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U8_BYTES_NUM) +#define XLog_Read_2_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U16_BYTES_NUM) +#define XLog_Read_4_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U32_BYTES_NUM) +#define XLog_Read_8_Bytes(buffer, buffersize) XLog_Read_N_Bytes(buffer, buffersize, U64_BYTES_NUM) + +extern bool XLog_Write_N_bytes(uint64 values, Size writebytes, byte* buffer); + +#define XLog_Write_1_Bytes(values, buffer) XLog_Write_N_bytes(values, U8_BYTES_NUM, buffer) +#define XLog_Write_2_Bytes(values, buffer) XLog_Write_N_bytes(values, U16_BYTES_NUM, buffer) +#define XLog_Write_4_Bytes(values, buffer) XLog_Write_N_bytes(values, U32_BYTES_NUM, buffer) +#define XLog_Write_8_Bytes(values, buffer) XLog_Write_N_bytes(values, U64_BYTES_NUM, buffer) + +typedef struct XLogBlockEnCode { + bool (*xlog_encodefun)(byte* buffer, Size buffersize, Size* encodesize, void* xlogbody); + uint16 block_valid; +} XLogBlockEnCode; + +typedef struct XLogBlockRedoCode { + void (*xlog_redofun)(char* buffer, Size buffersize, XLogBlockHead* blockhead, XLogBlockRedoHead* redohead, + void* page, Size pagesize); + uint16 block_valid; +} XLogBlockRedoCode; + +#pragma pack(pop) + +/* ********BLOCK Xact BEGIN ***************** */ +typedef struct { + uint8 delayddlflag; + uint8 updateminrecovery; + uint16 committype; + int invalidmsgnum; + int nrels; /* delete rels */ + int nlibs; /* delete libs */ + uint64 xinfo; + TimestampTz xact_time; + TransactionId maxxid; + CommitSeqNo maxcommitseq; + void* invalidmsg; + void* xnodes; + void* libfilename; +} XLogBlockXactParse; + +typedef struct { + Size maindatalen; + char* maindata; +} XLogBlockSlotParse; +/* ********BLOCK slot END ***************** */ + +/* ********BLOCK barrier BEGIN ***************** */ +typedef struct { + XLogRecPtr startptr; + XLogRecPtr endptr; +} XLogBlockBarrierParse; + +/* ********BLOCK Xact END ***************** */ + +/* ********BLOCK VacuumPin END ***************** */ +typedef struct { + XLogBlockHead blockhead; + XLogBlockRedoHead redohead; + union { + XLogBlockDataParse blockdatarec; + XLogBlockVmParse blockvmrec; + XLogBlockDdlParse blockddlrec; + XLogBlockBcmParse blockbcmrec; + XLogBlockNewCuParse blocknewcu; + XLogBlockCLogParse blockclogrec; + XLogBlockCSNLogParse blockcsnlogrec; + XLogBlockXactParse blockxact; + XLogBlockPrepareParse blockprepare; + XLogBlockInvalidParse blockinvalidmsg; + // XLogBlockIncompleteParse blockincomplete; + XLogBlockVacuumPinParse blockvacuumpin; + XLogBlockXLogComParse blockxlogcommon; + XLogBlockDataBaseParse blockdatabase; + XLogBlockTblSpcParse blocktblspc; + XLogBlockMultiXactOffParse blockmultixactoff; + XLogBlockMultiXactMemParse blockmultixactmem; + XLogBlockMultiUpdateParse blockmultiupdate; + XLogBlockRelMapParse blockrelmap; + XLogBlockSlotParse blockslot; + XLogBlockBarrierParse blockbarrier; + } extra_rec; +} XLogBlockParse; + + +typedef struct +{ + Buffer buf_id; + Buffer freeNext; +} RedoMemSlot; + +typedef void (*InterruptFunc)(); + +typedef struct +{ + int totalblknum; /* total slot */ + int usedblknum; /* used slot */ + Size itemsize; + Buffer firstfreeslot; /* first free slot */ + Buffer firstreleaseslot; /* first release slot */ + RedoMemSlot *memslot; /* slot itme */ + bool isInit; + InterruptFunc doInterrupt; +}RedoMemManager; + +typedef void (*RefOperateFunc)(void *record); +#ifdef USE_ASSERT_CHECKING +typedef void (*RecordCheckFunc)(void *record, XLogRecPtr curPageLsn, uint32 blockId, bool replayed); +#endif + +typedef struct { + RefOperateFunc refCount; + RefOperateFunc DerefCount; +#ifdef USE_ASSERT_CHECKING + RecordCheckFunc checkFunc; +#endif +}RefOperate; + +typedef struct +{ + void *BufferBlockPointers; /* RedoBufferDesc + block */ + RedoMemManager memctl; + RefOperate *refOperate; +}RedoBufferManager; + + + +typedef struct +{ + void *parsebuffers; /* ParseBufferDesc + XLogRecParseState */ + RedoMemManager memctl; + RefOperate *refOperate; +}RedoParseManager; + + + +typedef struct { + void* nextrecord; + XLogBlockParse blockparse; /* block data */ + RedoParseManager* manager; + void* refrecord; /* origin dataptr, for mem release */ + uint64 batchcount; + bool isFullSyncCheckpoint; +} XLogRecParseState; + +typedef struct XLogBlockRedoExtreRto { + void (*xlog_redoextrto)(XLogBlockHead* blockhead, void* blockrecbody, RedoBufferInfo* bufferinfo); + uint16 block_valid; +} XLogBlockRedoExtreRto; + +typedef struct XLogParseBlock { + XLogRecParseState* (*xlog_parseblock)(XLogReaderState* record, uint32* blocknum); + RmgrId rmid; +} XLogParseBlock; + +typedef enum { + HEAP_INSERT_ORIG_BLOCK_NUM = 0 +} XLogHeapInsertBlockEnum; + +typedef enum { + HEAP_DELETE_ORIG_BLOCK_NUM = 0 +} XLogHeapDeleteBlockEnum; + +typedef enum { + HEAP_UPDATE_NEW_BLOCK_NUM = 0, + HEAP_UPDATE_OLD_BLOCK_NUM +} XLogHeapUpdateBlockEnum; + +typedef enum { + HEAP_BASESHIFT_ORIG_BLOCK_NUM = 0 +} XLogHeapBaeShiftBlockEnum; + +typedef enum { + HEAP_NEWPAGE_ORIG_BLOCK_NUM = 0 +} XLogHeapNewPageBlockEnum; + +typedef enum { + HEAP_LOCK_ORIG_BLOCK_NUM = 0 +} XLogHeapLockBlockEnum; + +typedef enum { + HEAP_INPLACE_ORIG_BLOCK_NUM = 0 +} XLogHeapInplaceBlockEnum; + +typedef enum { + HEAP_FREEZE_ORIG_BLOCK_NUM = 0 +} XLogHeapFreezeBlockEnum; + +typedef enum { + HEAP_CLEAN_ORIG_BLOCK_NUM = 0 +} XLogHeapCleanBlockEnum; + +typedef enum { + HEAP_VISIBLE_VM_BLOCK_NUM = 0, + HEAP_VISIBLE_DATA_BLOCK_NUM +} XLogHeapVisibleBlockEnum; + +typedef enum { + HEAP_MULTI_INSERT_ORIG_BLOCK_NUM = 0 +} XLogHeapMultiInsertBlockEnum; + +typedef enum { + HEAP_PAGE_UPDATE_ORIG_BLOCK_NUM = 0 +} XLogHeapPageUpdateBlockEnum; + +extern THR_LOCAL RedoParseManager* g_parseManager; +extern THR_LOCAL RedoBufferManager* g_bufferManager; + +extern void* XLogMemCtlInit(RedoMemManager* memctl, Size itemsize, int itemnum); +extern RedoMemSlot* XLogMemAlloc(RedoMemManager* memctl); +extern void XLogMemRelease(RedoMemManager* memctl, Buffer bufferid); + +extern void XLogRedoBufferInit(RedoBufferManager* buffermanager, int buffernum, RefOperate *refOperate, + InterruptFunc interruptOperte); +extern void XLogRedoBufferDestory(RedoBufferManager* buffermanager); +extern RedoMemSlot* XLogRedoBufferAlloc( + RedoBufferManager* buffermanager, RelFileNode relnode, ForkNumber forkNum, BlockNumber blockNum); +extern bool XLogRedoBufferIsValid(RedoBufferManager* buffermanager, Buffer bufferid); +extern void XLogRedoBufferRelease(RedoBufferManager* buffermanager, Buffer bufferid); +extern BlockNumber XLogRedoBufferGetBlkNumber(RedoBufferManager* buffermanager, Buffer bufferid); +extern Block XLogRedoBufferGetBlk(RedoBufferManager* buffermanager, RedoMemSlot* bufferslot); +extern Block XLogRedoBufferGetPage(RedoBufferManager* buffermanager, Buffer bufferid); +extern void XLogRedoBufferSetState(RedoBufferManager* buffermanager, RedoMemSlot* bufferslot, uint32 state); + +#define XLogRedoBufferInitFunc(bufferManager, buffernum, defOperate, interruptOperte) do { \ + XLogRedoBufferInit(bufferManager, buffernum, defOperate, interruptOperte); \ +} while (0) +#define XLogRedoBufferDestoryFunc(bufferManager) do { \ + XLogRedoBufferDestory(bufferManager); \ +} while (0) +#define XLogRedoBufferAllocFunc(relnode, forkNum, blockNum, bufferslot) do { \ + *bufferslot = XLogRedoBufferAlloc(g_bufferManager, relnode, forkNum, blockNum); \ +} while (0) +#define XLogRedoBufferIsValidFunc(bufferid, isvalid) do { \ + *isvalid = XLogRedoBufferIsValid(g_bufferManager, bufferid); \ +} while (0) +#define XLogRedoBufferReleaseFunc(bufferid) do { \ + XLogRedoBufferRelease(g_bufferManager, bufferid); \ +} while (0) + +#define XLogRedoBufferGetBlkNumberFunc(bufferid, blknumber) do { \ + *blknumber = XLogRedoBufferGetBlkNumber(g_bufferManager, bufferid); \ +} while (0) + +#define XLogRedoBufferGetBlkFunc(bufferslot, blockdata) do { \ + *blockdata = XLogRedoBufferGetBlk(g_bufferManager, bufferslot); \ +} while (0) + +#define XLogRedoBufferGetPageFunc(bufferid, blockdata) do { \ + *blockdata = (Page)XLogRedoBufferGetPage(g_bufferManager, bufferid); \ +} while (0) +#define XLogRedoBufferSetStateFunc(bufferslot, state) do { \ + XLogRedoBufferSetState(g_bufferManager, bufferslot, state); \ +} while (0) + +extern void XLogParseBufferInit(RedoParseManager* parsemanager, int buffernum, RefOperate *refOperate, + InterruptFunc interruptOperte); +extern void XLogParseBufferDestory(RedoParseManager* parsemanager); +extern void XLogParseBufferRelease(XLogRecParseState* recordstate); +extern XLogRecParseState* XLogParseBufferAllocList(RedoParseManager* parsemanager, XLogRecParseState* blkstatehead, void *record); +extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState* record, uint8 buffer_id, RedoBufferInfo* bufferinfo); +extern void XLogInitBufferForRedo(XLogReaderState* record, uint8 block_id, RedoBufferInfo* bufferinfo); +extern XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState* record, uint8 buffer_id, ReadBufferMode mode, + bool get_cleanup_lock, RedoBufferInfo* bufferinfo, ReadBufferMethod readmethod = WITH_NORMAL_CACHE); + +#define XLogParseBufferInitFunc(parseManager, buffernum, defOperate, interruptOperte) do { \ + XLogParseBufferInit(parseManager, buffernum, defOperate, interruptOperte); \ +} while (0) + +#define XLogParseBufferDestoryFunc(parseManager) do { \ + XLogParseBufferDestory(parseManager); \ +} while (0) + +#define XLogParseBufferReleaseFunc(recordstate) do { \ + XLogParseBufferRelease(recordstate); \ +} while (0) + +#define XLogParseBufferAllocListFunc(record, newblkstate, blkstatehead) do { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, blkstatehead, record); \ +} while (0) + +#define XLogParseBufferAllocListStateFunc(record, newblkstate, blkstatehead) do { \ + if (*blkstatehead == NULL) { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, NULL, record); \ + *blkstatehead = *newblkstate; \ + } else { \ + *newblkstate = XLogParseBufferAllocList(g_parseManager, *blkstatehead, record); \ + } \ +} while (0) + + + + +#ifdef EXTREME_RTO_DEBUG_AB +typedef void (*AbnormalProcFunc)(void); +typedef enum { + A_THREAD_EXIT, + ALLOC_FAIL, + OPEN_FILE_FAIL, + WAIT_LONG, + ABNORMAL_NUM, +}AbnormalType; +extern AbnormalProcFunc g_AbFunList[ABNORMAL_NUM]; + + +#define ADD_ABNORMAL_POSITION(pos) do { \ + static int __count##pos = 0; \ + __count##pos++; \ + if (g_instance.attr.attr_storage.extreme_rto_ab_pos == pos) { \ + if (g_instance.attr.attr_storage.extreme_rto_ab_count == __count##pos) { \ + ereport(LOG, (errmsg("extreme rto debug abnormal stop pos:%d, type:%d, count:%d", pos, \ + g_instance.attr.attr_storage.extreme_rto_ab_type, __count##pos))); \ + g_AbFunList[g_instance.attr.attr_storage.extreme_rto_ab_type % ABNORMAL_NUM](); \ + } \ + } \ +} while(0) +#else +#define ADD_ABNORMAL_POSITION(pos) +#endif + + + +void HeapXlogCleanOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen, Size* freespace, bool repairFragmentation); +void HeapXlogFreezeOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen); +void HeapXlogVisibleOperatorPage(RedoBufferInfo* buffer, void* recorddata); +void HeapXlogVisibleOperatorVmpage(RedoBufferInfo* vmbuffer, void* recorddata); +void HeapXlogDeleteOperatorPage(RedoBufferInfo* buffer, void* recorddata, TransactionId recordxid); +void HeapXlogInsertOperatorPage(RedoBufferInfo* buffer, void* recorddata, bool isinit, void* blkdata, Size datalen, + TransactionId recxid, Size* freespace); +void HeapXlogMultiInsertOperatorPage(RedoBufferInfo* buffer, void* recoreddata, bool isinit, void* blkdata, + Size len, TransactionId recordxid, Size* freespace); +void HeapXlogUpdateOperatorOldpage(RedoBufferInfo* buffer, void* recoreddata, bool hot_update, bool isnewinit, + BlockNumber newblk, TransactionId recordxid); +void HeapXlogUpdateOperatorNewpage(RedoBufferInfo* buffer, void* recorddata, bool isinit, void* blkdata, + Size datalen, TransactionId recordxid, Size* freespace); +void HeapXlogPageUpgradeOperatorPage(RedoBufferInfo* buffer); +void HeapXlogLockOperatorPage(RedoBufferInfo* buffer, void* recorddata); +void HeapXlogInplaceOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size newlen); +void HeapXlogBaseShiftOperatorPage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeRestoreMetaOperatorPage(RedoBufferInfo* metabuf, void* recorddata, Size datalen); +void BtreeXlogInsertOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* data, Size datalen); +void BtreeXlogSplitOperatorRightpage( + RedoBufferInfo* rbuf, void* recorddata, BlockNumber leftsib, BlockNumber rnext, void* blkdata, Size datalen); +void BtreeXlogSplitOperatorNextpage(RedoBufferInfo* buffer, BlockNumber rightsib); +void BtreeXlogSplitOperatorLeftpage( + RedoBufferInfo* lbuf, void* recorddata, BlockNumber rightsib, bool onleft, void* blkdata, Size datalen); +void BtreeXlogVacuumOperatorPage(RedoBufferInfo* redobuffer, void* recorddata, void* blkdata, Size len); +void BtreeXlogDeleteOperatorPage(RedoBufferInfo* buffer, void* recorddata, Size recorddatalen); +void btreeXlogDeletePageOperatorRightpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogDeletePageOperatorLeftpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogDeletePageOperatorCurrentpage(RedoBufferInfo* buffer, void* recorddata); + +void BtreeXlogNewrootOperatorPage(RedoBufferInfo* buffer, void* record, void* blkdata, Size len, BlockNumber* downlink); +void BtreeXlogHalfdeadPageOperatorParentpage( + RedoBufferInfo* pbuf, void* recorddata); +void BtreeXlogHalfdeadPageOperatorLeafpage( + RedoBufferInfo* lbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorRightpage(RedoBufferInfo* rbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorLeftpage(RedoBufferInfo* lbuf, void* recorddata); +void BtreeXlogUnlinkPageOperatorCurpage(RedoBufferInfo* buf, void* recorddata); +void BtreeXlogUnlinkPageOperatorChildpage(RedoBufferInfo* cbuf, void* recorddata); + +void BtreeXlogClearIncompleteSplit(RedoBufferInfo* buffer); + +void XLogRecSetBlockCommonState(XLogReaderState* record, XLogBlockParseEnum blockvalid, ForkNumber forknum, + BlockNumber blockknum, RelFileNode* relnode, XLogRecParseState* recordblockstate); + +void XLogRecSetBlockCLogState( + XLogBlockCLogParse* blockclogstate, TransactionId topxid, uint16 status, uint16 xidnum, uint16* xidsarry); + +void XLogRecSetBlockCSNLogState( + XLogBlockCSNLogParse* blockcsnlogstate, TransactionId topxid, CommitSeqNo csnseq, uint16 xidnum, uint16* xidsarry); +void XLogRecSetXactRecoveryState(XLogBlockXactParse* blockxactstate, TransactionId maxxid, CommitSeqNo maxcsnseq, + uint8 delayddlflag, uint8 updateminrecovery); +void XLogRecSetXactDdlState(XLogBlockXactParse* blockxactstate, int nrels, void* xnodes, int invalidmsgnum, + void* invalidmsg, int nlibs, void* libfilename); +void XLogRecSetXactCommonState( + XLogBlockXactParse* blockxactstate, uint16 committype, uint64 xinfo, TimestampTz xact_time); +void XLogRecSetBcmState(XLogBlockBcmParse* blockbcmrec, uint64 startblock, int count, int status); +void XLogRecSetNewCuState(XLogBlockNewCuParse* blockcudata, char* main_data, uint32 main_data_len); +void XLogRecSetInvalidMsgState(XLogBlockInvalidParse* blockinvalid, TransactionId cutoffxid); +void XLogRecSetIncompleteMsgState(XLogBlockIncompleteParse* blockincomplete, uint16 action, bool issplit, bool isroot, + BlockNumber downblk, BlockNumber leftblk, BlockNumber rightblk); +void XLogRecSetPinVacuumState(XLogBlockVacuumPinParse* blockvacuum, BlockNumber lastblknum); + +void XLogRecSetAuxiBlkNumState(XLogBlockDataParse* blockdatarec, BlockNumber auxilaryblkn1, BlockNumber auxilaryblkn2); +void XLogRecSetBlockDataState(XLogReaderState* record, uint32 blockid, XLogRecParseState* recordblockstate); +extern char* XLogBlockDataGetBlockData(XLogBlockDataParse* datadecode, Size* len); +void Heap2RedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void HeapRedoDataBlock( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void xlog_redo_data_block( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void XLogRecSetBlockDdlState(XLogBlockDdlParse* blockddlstate, uint32 blockddltype, uint32 columnrel, + char *mainData, Oid ownerid = InvalidOid); +XLogRedoAction XLogCheckBlockDataRedoAction(XLogBlockDataParse* datadecode, RedoBufferInfo* bufferinfo); +void BtreeRedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +XLogRecParseState* XactXlogCsnlogParseToBlock(XLogReaderState* record, uint32* blocknum, TransactionId xid, + int nsubxids, TransactionId* subxids, CommitSeqNo csn, XLogRecParseState* recordstatehead); +extern void XLogRecSetVmBlockState(XLogReaderState* record, uint32 blockid, XLogRecParseState* recordblockstate); +extern void DoLsnCheck(RedoBufferInfo* bufferinfo, bool willInit, XLogRecPtr lastLsn); +char* XLogBlockDataGetMainData(XLogBlockDataParse* datadecode, Size* len); +void HeapRedoVmBlock(XLogBlockHead* blockhead, XLogBlockVmParse* blockvmrec, RedoBufferInfo* bufferinfo); +void Heap2RedoVmBlock(XLogBlockHead* blockhead, XLogBlockVmParse* blockvmrec, RedoBufferInfo* bufferinfo); +XLogRecParseState* xlog_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* smgr_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* XactXlogClogParseToBlock(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId xid, int nsubxids, TransactionId* subxids, CLogXidStatus status); +XLogRecParseState* xact_xlog_commit_parse_to_block(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId maxxid, CommitSeqNo maxseqnum); +void visibilitymap_clear_buffer(RedoBufferInfo* bufferinfo, BlockNumber heapBlk); +XLogRecParseState* xact_xlog_abort_parse_to_block(XLogReaderState* record, XLogRecParseState* recordstatehead, + uint32* blocknum, TransactionId maxxid, CommitSeqNo maxseqnum); +XLogRecParseState* xact_xlog_prepare_parse_to_block( + XLogReaderState* record, XLogRecParseState* recordstatehead, uint32* blocknum, TransactionId maxxid); +XLogRecParseState* xact_xlog_parse_to_block(XLogReaderState* record, uint32* blocknum); +XLogRecParseState* ClogRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +XLogRecParseState* DbaseRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +XLogRecParseState* Heap2RedoParseIoBlock(XLogReaderState* record, uint32* blocknum); + +extern XLogRecParseState* HeapRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* BtreeRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* Heap3RedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern Size SalEncodeXLogBlock(void* recordblockstate, byte* buffer, void* sliceinfo); + +extern XLogRecParseState* XLogParseToBlockForDfv(XLogReaderState* record, uint32* blocknum); +extern Size getBlockSize(XLogRecParseState* recordblockstate); +extern XLogRecParseState* GistRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* GinRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern void GistRedoClearFollowRightOperatorPage(RedoBufferInfo* buffer); +extern void GistRedoPageUpdateOperatorPage(RedoBufferInfo* buffer, void* recorddata, void* blkdata, Size datalen); +extern void GistRedoPageSplitOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* data, Size datalen, bool Markflag, BlockNumber rightlink); +extern void GistRedoCreateIndexOperatorPage(RedoBufferInfo* buffer); + +extern void GinRedoCreateIndexOperatorMetaPage(RedoBufferInfo* MetaBuffer); +extern void GinRedoCreateIndexOperatorRootPage(RedoBufferInfo* RootBuffer); +extern void GinRedoCreatePTreeOperatorPage(RedoBufferInfo* buffer, void* recordData); +extern void GinRedoClearIncompleteSplitOperatorPage(RedoBufferInfo* buffer); +extern void GinRedoVacuumDataOperatorLeafPage(RedoBufferInfo* buffer, void* recorddata); +extern void GinRedoDeletePageOperatorCurPage(RedoBufferInfo* dbuffer); +extern void GinRedoDeletePageOperatorParentPage(RedoBufferInfo* pbuffer, void* recorddata); +extern void GinRedoDeletePageOperatorLeftPage(RedoBufferInfo* lbuffer, void* recorddata); +extern void GinRedoUpdateOperatorMetapage(RedoBufferInfo* metabuffer, void* recorddata); +extern void GinRedoUpdateOperatorTailPage(RedoBufferInfo* buffer, void* payload, Size totaltupsize, int32 ntuples); +extern void GinRedoInsertListPageOperatorPage( + RedoBufferInfo* buffer, void* recorddata, void* payload, Size totaltupsize); +extern void GinRedoUpdateAddNewTail(RedoBufferInfo* buffer, BlockNumber newRightlink); +extern void GinRedoInsertData(RedoBufferInfo* buffer, bool isLeaf, BlockNumber rightblkno, void* rdata); +extern void GinRedoInsertEntry(RedoBufferInfo* buffer, bool isLeaf, BlockNumber rightblkno, void* rdata); + +extern void GinRedoDeleteListPagesOperatorPage(RedoBufferInfo* metabuffer, const void* recorddata); +extern void GinRedoDeleteListPagesMarkDelete(RedoBufferInfo* buffer); + +extern void spgRedoCreateIndexOperatorMetaPage(RedoBufferInfo* buffer); +extern void spgRedoCreateIndexOperatorRootPage(RedoBufferInfo* buffer); +extern void spgRedoCreateIndexOperatorLeafPage(RedoBufferInfo* buffer); +extern void spgRedoAddLeafOperatorPage(RedoBufferInfo* bufferinfo, void* recorddata); +extern void spgRedoAddLeafOperatorParent(RedoBufferInfo* bufferinfo, void* recorddata, BlockNumber blknoLeaf); +extern void spgRedoMoveLeafsOpratorDstPage(RedoBufferInfo* buffer, void* recorddata, void* insertdata, void* tupledata); +extern void spgRedoMoveLeafsOpratorSrcPage( + RedoBufferInfo* buffer, void* recorddata, void* insertdata, void* deletedata, BlockNumber blknoDst, int nInsert); +extern void spgRedoMoveLeafsOpratorParentPage( + RedoBufferInfo* buffer, void* recorddata, void* insertdata, BlockNumber blknoDst, int nInsert); +extern void spgRedoAddNodeUpdateSrcPage(RedoBufferInfo* buffer, void* recorddata, void* tuple, void* tupleheader); +extern void spgRedoAddNodeOperatorSrcPage(RedoBufferInfo* buffer, void* recorddata, BlockNumber blknoNew); +extern void spgRedoAddNodeOperatorDestPage( + RedoBufferInfo* buffer, void* recorddata, void* tuple, void* tupleheader, BlockNumber blknoNew); +extern void spgRedoAddNodeOperatorParentPage(RedoBufferInfo* buffer, void* recorddata, BlockNumber blknoNew); +extern void spgRedoSplitTupleOperatorDestPage(RedoBufferInfo* buffer, void* recorddata, void* tuple); +extern void spgRedoSplitTupleOperatorSrcPage(RedoBufferInfo* buffer, void* recorddata, void* pretuple, void* posttuple); +extern void spgRedoPickSplitRestoreLeafTuples( + RedoBufferInfo* buffer, void* recorddata, bool destflag, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorSrcPage(RedoBufferInfo* srcBuffer, void* recorddata, void* deleteoffset, + BlockNumber blknoInner, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorDestPage( + RedoBufferInfo* destBuffer, void* recorddata, void* pageselect, void* insertdata); +extern void spgRedoPickSplitOperatorInnerPage( + RedoBufferInfo* innerBuffer, void* recorddata, void* tuple, void* tupleheader, BlockNumber blknoInner); +extern void spgRedoPickSplitOperatorParentPage(RedoBufferInfo* parentBuffer, void* recorddata, BlockNumber blknoInner); +extern void spgRedoVacuumLeafOperatorPage(RedoBufferInfo* buffer, void* recorddata); +extern void spgRedoVacuumRootOperatorPage(RedoBufferInfo* buffer, void* recorddata); +extern void spgRedoVacuumRedirectOperatorPage(RedoBufferInfo* buffer, void* recorddata); + +extern XLogRecParseState* SpgRedoParseToBlock(XLogReaderState* record, uint32* blocknum); + +extern void seqRedoOperatorPage(RedoBufferInfo* buffer, void* itmedata, Size itemsz); +extern void seq_redo_data_block(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); + +extern void Heap3RedoDataBlock( + XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); + +extern XLogRecParseState* xact_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); + +extern bool XLogBlockRedoForExtremeRTO(XLogRecParseState* redoblocktate, RedoBufferInfo *bufferinfo, + bool notfound); +void XLogBlockParseStateRelease_debug(XLogRecParseState* recordstate, const char *func, uint32 line); +#define XLogBlockParseStateRelease(recordstate) XLogBlockParseStateRelease_debug(recordstate, __FUNCTION__, __LINE__) +#ifdef USE_ASSERT_CHECKING +extern void DoRecordCheck(XLogRecParseState *recordstate, XLogRecPtr pageLsn, bool replayed); +#endif +extern XLogRecParseState* XLogParseBufferCopy(XLogRecParseState *srcState); +extern XLogRecParseState* XLogParseToBlockForExtermeRTO(XLogReaderState* record, uint32* blocknum); +extern XLogRedoAction XLogReadBufferForRedoBlockExtend(RedoBufferTag* redoblock, ReadBufferMode mode, bool get_cleanup_lock, + RedoBufferInfo* redobufferinfo, XLogRecPtr xloglsn, ReadBufferMethod readmethod); +extern XLogRecParseState* tblspc_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* relmap_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* HashRedoParseToBlock(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* seq_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern XLogRecParseState* slot_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +#ifdef ENABLE_MULTIPLE_NODES +extern XLogRecParseState* barrier_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +#endif +extern XLogRecParseState* multixact_redo_parse_to_block(XLogReaderState* record, uint32* blocknum); +extern void ExtremeRtoFlushBuffer(RedoBufferInfo *bufferinfo, bool updateFsm); +extern void XLogForgetDDLRedo(XLogRecParseState* redoblockstate); +extern void SyncOneBufferForExtremRto(RedoBufferInfo *bufferinfo); +extern void XLogBlockInitRedoBlockInfo(XLogBlockHead* blockhead, RedoBufferTag* blockinfo); +extern void XLogBlockDdlDoSmgrAction(XLogBlockHead* blockhead, void* blockrecbody, RedoBufferInfo* bufferinfo); +extern void GinRedoDataBlock(XLogBlockHead* blockhead, XLogBlockDataParse* blockdatarec, RedoBufferInfo* bufferinfo); +extern void GistRedoDataBlock(XLogBlockHead *blockhead, XLogBlockDataParse *blockdatarec, RedoBufferInfo *bufferinfo); +extern bool IsCheckPoint(const XLogRecParseState *parseState); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/access/xlogreader.h postgresql-hll-2.14/include/include/access/xlogreader.h --- postgresql-hll-2.14_old/include/include/access/xlogreader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlogreader.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,100 @@ +/* --------------------------------------------------------------------------------------- + * + * xlogreader.h + * Definitions for the generic XLog reading facility + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 2013-2015, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/access/xlogreader.h + * + * NOTES + * See the definition of the XLogReaderState struct for instructions on + * how to use the XLogReader infrastructure. + * + * The basic idea is to allocate an XLogReaderState via + * XLogReaderAllocate(), and call XLogReadRecord() until it returns NULL. + * + * After reading a record with XLogReadRecord(), it's decomposed into + * the per-block and main data parts, and the parts can be accessed + * with the XLogRec* macros and functions. You can also decode a + * record that's already constructed in memory, without reading from + * disk, by calling the DecodeXLogRecord() function. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGREADER_H +#define XLOGREADER_H + +#include "access/xlogrecord.h" +#include "securec_check.h" +#include "access/xlog_basic.h" + +#define offsetof_twoversion(type, typeold, field) (offsetof(type, field) - offsetof(typeold, field)) +#define XLOG_READER_MAX_MSGLENTH 1024 + +/* Get a new XLogReader */ +extern XLogReaderState* XLogReaderAllocate(XLogPageReadCB pagereadfunc, void* private_data); + +/* Free an XLogReader */ +extern void XLogReaderFree(XLogReaderState* state); +/* The function has the stronger ability to find the next xlog record with XLogReadRecord() deployed. */ +extern bool ValidateNextXLogRecordPtr(XLogReaderState* state, XLogRecPtr& cur_ptr, char** err_msg); +/* Adjust the start ptr of XlogRecoed for XlogReadRecord */ +extern void AlignXlogPtrToNextPageIfNeeded(XLogRecPtr* recPtr); +/* Read the next XLog record. Returns NULL on end-of-WAL or failure */ +extern struct XLogRecord* XLogReadRecord( + XLogReaderState* state, XLogRecPtr recptr, char** errormsg, bool readoldversion = false, bool doDecode = true); + +extern bool XLogRecGetBlockTag( + XLogReaderState* record, uint8 block_id, RelFileNode* rnode, ForkNumber* forknum, BlockNumber* blknum); +extern bool XLogRecGetBlockLastLsn(XLogReaderState* record, uint8 block_id, XLogRecPtr* lsn); +extern char* XLogRecGetBlockImage(XLogReaderState* record, uint8 block_id, uint16* hole_offset, uint16* hole_length); + +/* Invalidate read state */ +extern void XLogReaderInvalReadState(XLogReaderState* state); + +extern XLogRecPtr XLogFindNextRecord(XLogReaderState* state, XLogRecPtr RecPtr); +extern XLogRecPtr FindMaxLSN(char* workingpath, char* returnmsg, int msg_len, pg_crc32* maxLsnCrc); +extern void CloseXlogFile(void); +extern int SimpleXLogPageRead(XLogReaderState* xlogreader, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* readBuf, TimeLineID* pageTLI); +extern void CloseXlogFile(void); + +/* Functions for decoding an XLogRecord */ +extern bool DecodeXLogRecord(XLogReaderState* state, XLogRecord* record, char** errmsg, bool readoldversion); + +#define XLogRecGetTotalLen(decoder) ((decoder)->decoded_record->xl_tot_len) +#define XLogRecGetPrev(decoder) ((decoder)->decoded_record->xl_prev) +#define XLogRecGetInfo(decoder) ((decoder)->decoded_record->xl_info) +#define XLogRecGetRmid(decoder) ((decoder)->decoded_record->xl_rmid) +#define XLogRecGetXid(decoder) ((decoder)->decoded_record->xl_xid) +#define XLogRecGetTerm(decoder) ((decoder)->decoded_record->xl_term) +#define XLogRecGetBucketId(decoder) ((decoder)->decoded_record->xl_bucket_id - 1) +#define XLogRecGetCrc(decoder) ((decoder)->decoded_record->xl_crc) +#define XLogRecGetOrigin(decoder) ((decoder)->record_origin) +#define XLogRecGetData(decoder) ((decoder)->main_data) +#define XLogRecGetDataLen(decoder) ((decoder)->main_data_len) +#define XLogRecHasAnyBlockRefs(decoder) ((decoder)->max_block_id >= 0) +#define XLogRecHasBlockRef(decoder, block_id) ((decoder)->blocks[block_id].in_use) +#define XLogRecHasBlockImage(decoder, block_id) ((decoder)->blocks[block_id].has_image) + +extern void RestoreBlockImage(const char* bkp_image, uint16 hole_offset, uint16 hole_length, char* page); +extern char* XLogRecGetBlockData(XLogReaderState* record, uint8 block_id, Size* len); +extern bool allocate_recordbuf(XLogReaderState* state, uint32 reclength); +extern bool XlogFileIsExisted(const char* workingPath, XLogRecPtr inputLsn, TimeLineID timeLine); +extern void ResetDecoder(XLogReaderState* state); +bool ValidXLogPageHeader(XLogReaderState* state, XLogRecPtr recptr, XLogPageHeader hdr, bool readoldversion); +void report_invalid_record(XLogReaderState* state, const char* fmt, ...) + /* + * This extension allows gcc to check the format string for consistency with + * the supplied arguments. + */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +bool ValidXLogRecordHeader( + XLogReaderState* state, XLogRecPtr RecPtr, XLogRecPtr PrevRecPtr, XLogRecord* record, bool randAccess); +bool ValidXLogRecord(XLogReaderState* state, XLogRecord* record, XLogRecPtr recptr); + +#endif /* XLOGREADER_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlogrecord.h postgresql-hll-2.14/include/include/access/xlogrecord.h --- postgresql-hll-2.14_old/include/include/access/xlogrecord.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlogrecord.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,119 @@ +/* --------------------------------------------------------------------------------------- + * + * xlogrecord.h + * Definitions for the WAL record format. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/access/xlogrecord.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef XLOGRECORD_H +#define XLOGRECORD_H + +#include "access/rmgr.h" +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/pg_crc.h" +#include "port/pg_crc32c.h" + +/* + * The high 4 bits in xl_info may be used freely by rmgr. The + * XLR_SPECIAL_REL_UPDATE bit can be passed by XLogInsert caller. The rest + * are set internally by XLogInsert. + */ +#define XLR_INFO_MASK 0x0F +#define XLR_RMGR_INFO_MASK 0xF0 + +/* + * If a WAL record modifies any relation files, in ways not covered by the + * usual block references, this flag is set. This is not used for anything + * by PostgreSQL itself, but it allows external tools that read WAL and keep + * track of modified blocks to recognize such special record types. + */ +#define XLR_SPECIAL_REL_UPDATE 0x01 +/* If xlog record contains bucket node id */ +#define XLR_REL_HAS_BUCKET 0x02 + +/* + * Header info for block data appended to an XLOG record. + * + * Note that we don't attempt to align the XLogRecordBlockHeader struct! + * So, the struct must be copied to aligned local storage before use. + * 'data_length' is the length of the payload data associated with this, + * and includes the possible full-page image, and rmgr-specific data. It + * does not include the XLogRecordBlockHeader struct itself. + */ +typedef struct XLogRecordBlockHeader { + uint8 id; /* block reference ID */ + uint8 fork_flags; /* fork within the relation, and flags */ + uint16 data_length; /* number of payload bytes (not including page + * image) */ + + /* If BKPBLOCK_HAS_IMAGE, an XLogRecordBlockImageHeader struct follows */ + /* If !BKPBLOCK_SAME_REL is not set, a RelFileNode follows */ + /* BlockNumber follows */ +} XLogRecordBlockHeader; + +#define SizeOfXLogRecordBlockHeader (offsetof(XLogRecordBlockHeader, data_length) + sizeof(uint16)) + +/* + * We use the highest bit of XLogRecordBlockHeader->id for hash bucket table. + * The RelFileNode is for hash bucket tables, and RelFileNodeOld is for regular tables. + */ +#define BKID_HAS_BUCKET (0x80) +#define BKID_GET_BKID(id) (id & 0x7F) + +/* + * Additional header information when a full-page image is included + * (i.e. when BKPBLOCK_HAS_IMAGE is set). + * + * As a trivial form of data compression, the XLOG code is aware that + * PG data pages usually contain an unused "hole" in the middle, which + * contains only zero bytes. If hole_length > 0 then we have removed + * such a "hole" from the stored data (and it's not counted in the + * XLOG record's CRC, either). Hence, the amount of block data actually + * present is BLCKSZ - hole_length bytes. + */ +typedef struct XLogRecordBlockImageHeader { + uint16 hole_offset; /* number of bytes before "hole" */ + uint16 hole_length; /* number of bytes in "hole" */ +} XLogRecordBlockImageHeader; + +#define SizeOfXLogRecordBlockImageHeader sizeof(XLogRecordBlockImageHeader) + +/* + * Maximum size of the header for a block reference. This is used to size a + * temporary buffer for constructing the header. + */ +#define MaxSizeOfXLogRecordBlockHeader \ + (SizeOfXLogRecordBlockHeader + SizeOfXLogRecordBlockImageHeader + sizeof(RelFileNode) + sizeof(BlockNumber)) + +/* + * XLogRecordDataHeaderShort/Long are used for the "main data" portion of + * the record. If the length of the data is less than 256 bytes, the short + * form is used, with a single byte to hold the length. Otherwise the long + * form is used. + * + * (These structs are currently not used in the code, they are here just for + * documentation purposes). + */ +typedef struct XLogRecordDataHeaderShort { + uint8 id; /* XLR_BLOCK_ID_DATA_SHORT */ + uint8 data_length; /* number of payload bytes */ +} XLogRecordDataHeaderShort; + +#define SizeOfXLogRecordDataHeaderShort (sizeof(uint8) * 2) + +typedef struct XLogRecordDataHeaderLong { + uint8 id; /* XLR_BLOCK_ID_DATA_LONG */ + /* followed by uint32 data_length, unaligned */ +} XLogRecordDataHeaderLong; + +#define SizeOfXLogRecordDataHeaderLong (sizeof(uint8) + sizeof(uint32)) +#endif /* XLOGRECORD_H */ diff -uprN postgresql-hll-2.14_old/include/include/access/xlogutils.h postgresql-hll-2.14/include/include/access/xlogutils.h --- postgresql-hll-2.14_old/include/include/access/xlogutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/access/xlogutils.h 2020-12-12 17:06:43.144346709 +0800 @@ -0,0 +1,69 @@ +/* + * xlogutils.h + * + * Utilities for replaying WAL records. + * + * PostgreSQL transaction log manager utility routines + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/access/xlogutils.h + */ +#ifndef XLOG_UTILS_H +#define XLOG_UTILS_H + +#include "access/xlogreader.h" +#include "storage/bufmgr.h" + +/* Result codes for XLogReadBufferForRedo[Extended] */ +typedef enum { + BLK_NEEDS_REDO, /* changes from WAL record need to be applied */ + NO_BLK, /* ddl no need get block */ + BLK_DONE, /* block is already up-to-date */ + BLK_RESTORED, /* block was restored from a full-page image */ + BLK_NOTFOUND /* block was not found (and hence does not need to be + * replayed) */ +} XLogRedoAction; + +extern bool XLogHaveInvalidPages(void); +extern void* XLogGetInvalidPages(); + +extern void XLogCheckInvalidPages(void); + +extern void XLogDropRelation(const RelFileNode& rnode, ForkNumber forknum); +extern void XlogDropRowReation(RelFileNode rnode); +extern void XLogDropDatabase(Oid dbid); +extern void XLogTruncateRelation(XLogReaderState* record, const RelFileNode& rnode, ForkNumber forkNum, BlockNumber nblocks); +extern void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum, BlockNumber nblocks); + +extern Buffer XLogReadBufferExtended(const RelFileNode& rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern XLogRedoAction XLogReadBufferForRedo(XLogReaderState* record, uint8 buffer_id, Buffer* buf); +extern Relation CreateFakeRelcacheEntry(const RelFileNode& rnode); +extern Relation CreateCUReplicationRelation(const RelFileNode& rnode, int BackendId, char relpersistence, const char* relname); +extern void FreeFakeRelcacheEntry(Relation fakerel); +extern void log_invalid_page(const RelFileNode& node, ForkNumber forkno, BlockNumber blkno, bool present); +extern int read_local_xlog_page(XLogReaderState* state, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, + char* cur_page, TimeLineID* pageTLI); +extern void closeXLogRead(); +extern bool IsDataBaseDrop(XLogReaderState* record); +extern bool IsTableSpaceDrop(XLogReaderState* record); +extern bool IsTableSpaceCreate(XLogReaderState* record); +extern bool IsDataBaseCreate(XLogReaderState* record); + +extern Buffer XLogReadBufferExtendedWithoutBuffer( + RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern Buffer XLogReadBufferExtendedWithLocalBuffer( + RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode); + +extern void XlogUpdateFullPageWriteLsn(Page page, XLogRecPtr lsn); +void XLogSynAllBuffer(); +bool ParseStateUseShareBuf(); +bool ParseStateUseLocalBuf(); +bool ParseStateWithoutCache(); + + +#endif diff -uprN postgresql-hll-2.14_old/include/include/alarm/alarm.h postgresql-hll-2.14/include/include/alarm/alarm.h --- postgresql-hll-2.14_old/include/include/alarm/alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/alarm.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,208 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarm.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/alarm/alarm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ALARM_H +#define ALARM_H + +#include "c.h" + +/*GaussDB alarm module.*/ +typedef enum AlarmId { + ALM_AI_Unknown = 0, + + /*alarm on data instances(alarm checker)*/ + ALM_AI_MissingDataInstDataOrRedoDir = 0x404E0001, + ALM_AI_MissingDataInstWalSegmt = 0x404E0003, + ALM_AI_TooManyDataInstConn = 0x404F0001, + + /*alarm on monitor instances*/ + ALM_AI_AbnormalGTMInst = 0x404F0002, + ALM_AI_AbnormalDatanodeInst = 0x404F0004, + + ALM_AI_AbnormalGTMProcess = 0x404F0008, + ALM_AI_AbnormalCoordinatorProcess = 0x404F0009, + ALM_AI_AbnormalDatanodeProcess = 0x404F0010, + + ALM_AI_DatanodeSwitchOver = 0x404F0021, + ALM_AI_DatanodeFailOver = 0x404F0022, + + ALM_AI_GTMSwitchOver = 0x404F0023, + ALM_AI_GTMFailOver = 0x404F0024, + + ALM_AI_ForceFinishRedo = 0x404F0025, + + ALM_AI_AbnormalCMSProcess = 0x404F003B, + ALM_AI_UnbalancedCluster = 0x404F0038, + ALM_AI_AbnormalCMAProcess = 0x404F003A, + ALM_AI_AbnormalETCDProcess = 0x404F003E, + + /*alarm when occur errors*/ + ALM_AI_AbnormalDataHAInstListeningSocket = 0x404F0039, + ALM_AI_AbnormalGTMSocket = 0x404F003D, + ALM_AI_AbnormalDataInstConnToGTM = 0x404F003C, + ALM_AI_AbnormalDataInstConnAuthMethod = 0x404F0036, + ALM_AI_TooManyDatabaseConn = 0x404F0037, + ALM_AI_TooManyDbUserConn = 0x404F0033, + ALM_AI_DataInstLockFileExist = 0x404F0034, + ALM_AI_InsufficientDataInstFileDesc = 0x404F0031, + ALM_AI_AbnormalDataInstArch = 0x404F0032, + ALM_AI_AbnormalTableSkewness = 0x404F0035, + + ALM_AI_AbnormalTDEFile = 0x404F0041, + ALM_AI_AbnormalTDEValue = 0x404F0042, + ALM_AI_AbnormalConnToKMS = 0x404F0043, + + ALM_AI_AbnormalDataInstDisk = 0x404F0047, + + ALM_AI_AbnormalEtcdDown = 0x404F0048, + ALM_AI_AbnormalEtcdUnhealth = 0x404F0049, + + ALM_AI_AbnormalPhonyDead = 0x404F004A, + ALM_AI_AbnormalCmaConnFail = 0x404F004B, + ALM_AI_Build = 0x404F004C, + ALM_AI_AbnormalBuild = 0x404F004D, + ALM_AI_TransactionReadOnly = 0x404F0059, + ALM_AI_ServerSwitchOver = 0x404F005A, + + ALM_AI_AbnormalEtcdNearQuota = 0x404F005B, + + ALM_AI_StorageThresholdPreAlarm = 0x404F005C, + ALM_AI_StorageDilatationAlarmNotice = 0x404F005D, + ALM_AI_StorageDilatationAlarmMajor = 0x404F005E, + + ALM_AI_FeaturePermissionDenied = 0x404F0050, /* No permission to invoke specific features. */ + ALM_AI_BUTT = 0x7FFFFFFFFFFFFFFF /*force compiler to decide AlarmId as uint64*/ +} AlarmId; + +typedef struct AlarmName { + AlarmId id; + char nameEn[256]; + char nameCh[256]; + char alarmInfoEn[1024]; + char alarmInfoCh[1024]; + char alarmLevel[256]; +} AlarmName; + +typedef struct AlarmAdditionalParam { + char clusterName[256]; + char hostName[256]; + char hostIP[256]; + char instanceName[256]; + char databaseName[256]; + char dbUserName[128]; + char logicClusterName[128]; + char additionInfo[256]; +} AlarmAdditionalParam; + +/*total alarm types of alarm module.*/ +typedef enum AlarmType { ALM_AT_Fault = 0, ALM_AT_Resume = 2, ALM_AT_OPLog, ALM_AT_Event, ALM_AT_Delete } AlarmType; + +/*status of a specific alarm.*/ +typedef enum AlarmStat { ALM_AS_Normal, ALM_AS_Reported } AlarmStat; + +/*result types of alarm check functions.*/ +typedef enum AlarmCheckResult { + ALM_ACR_UnKnown = 0, + + ALM_ACR_Normal, + ALM_ACR_Abnormal +} AlarmCheckResult; + +typedef enum AlarmModule { + ALM_AM_NoModule = 0, + + ALM_AM_Coordinator, + ALM_AM_Datanode, + ALM_AM_GTM, + ALM_AM_CMServer +} AlarmModule; + +typedef struct Alarm { + AlarmId id; + AlarmStat stat; + time_t lastReportTime; + long startTimeStamp; + long endTimeStamp; + int reportCount; + char infoEn[256]; + char infoCh[256]; + + AlarmCheckResult (*checker)(Alarm* alarm, AlarmAdditionalParam* additionalParam); +} Alarm; + +typedef AlarmCheckResult (*CheckerFunc)(Alarm* alarm, AlarmAdditionalParam* additionalParam); + +/*common function to check*/ +extern void AlarmEnvInitialize(void); + +extern void AlarmItemInitialize(Alarm* alarmItem, AlarmId alarmId, AlarmStat alarmStat, CheckerFunc checkerFunc, + time_t reportTime = 0, int reportCount = 0); + +extern void AlarmCheckerLoop(Alarm* checkList, int checkListSize); + +extern void WriteAlarmAdditionalInfo(AlarmAdditionalParam* additionalParam, const char* instanceName, + const char* databaseName, const char* dbUserName, Alarm* alarmItem, AlarmType type, ...); + +extern void WriteAlarmAdditionalInfoForLC(AlarmAdditionalParam* additionalParam, const char* instanceName, + const char* databaseName, const char* dbUserName, const char* logicClusterName, Alarm* alarmItem, AlarmType type, + ...); + +extern void AlarmReporter(Alarm* alarmItem, AlarmType type, AlarmAdditionalParam* additionalParam); + +/*alarm module only log in two level.*/ +#define ALM_LOG 1 +#define ALM_DEBUG 2 +#define AlarmLogPrefix "[Alarm Module]" + +#define CLUSTER_NAME_LEN 64 + +extern void AlarmLog(int level, const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/*below things must be implemented by other modules(gaussdb, gtm, cmserver etc.).*/ + +/*declare the guc variable of alarm module*/ +extern char* Alarm_component; +extern THR_LOCAL int AlarmReportInterval; + +/*declare the global variable of alarm module*/ +extern int g_alarmReportInterval; +extern int g_alarmReportMaxCount; +extern char g_alarmComponentPath[MAXPGPATH]; + +/*alarm module memory alloc method maybe different in different module.*/ +extern void* AlarmAlloc(size_t size); +extern void AlarmFree(void* pointer); + +/*callback protype for get logic cluster name.*/ +typedef void (*cb_for_getlc)(char*); +/*set callback function for get logic cluster name*/ +void SetcbForGetLCName(cb_for_getlc get_lc_name); + +/*alarm log implementation.*/ +extern void AlarmLogImplementation(int level, const char* prefix, const char* logtext); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/alarm/alarm_log.h postgresql-hll-2.14/include/include/alarm/alarm_log.h --- postgresql-hll-2.14_old/include/include/alarm/alarm_log.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/alarm_log.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarm_log.h + * alarm logging and reporting + * + * + * IDENTIFICATION + * src/include/alarm/alarm_log.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ALARM_LOG_H +#define ALARM_LOG_H +#include "alarm/alarm.h" + +#define SYSQUOTE "\"" +#define SYSCOLON ":" +#define SYSCOMMA "," + +#define MAX_BUF_SIZE 1024 +extern char g_alarm_scope[MAX_BUF_SIZE]; + +void clean_system_alarm_log(const char* file_name, const char* sys_log_path); + +void create_system_alarm_log(const char* sys_log_path); + +void write_alarm(Alarm* alarmItem, const char* alarmName, const char* alarmLevel, AlarmType type, + AlarmAdditionalParam* additionalParam); + +void set_alarm_scope(const char* alarmScope); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/alarm/GaussAlarm_client.h postgresql-hll-2.14/include/include/alarm/GaussAlarm_client.h --- postgresql-hll-2.14_old/include/include/alarm/GaussAlarm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/GaussAlarm_client.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,88 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * GaussAlarm_client.h + * + * + * + * IDENTIFICATION + * src/include/alarm/GaussAlarm_client.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GAUSS_ALARM_CLENT_H__ +#define __GAUSS_ALARM_CLENT_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +#ifndef CM_ALARM_TYPE_MACRO +/* �澯���� */ +typedef enum tagCM_ALARM_TYPE { + ALM_ALARM_TYPE_FAULT = 0, /* ���� */ + // ALM_ALARM_TYPE_EVENT = 1, /* �¼� */ + ALM_ALARM_TYPE_RESUME = 2, /* �ָ� */ + ALM_ALARM_TYPE_OPLOG = 3, /* ������־ */ + ALM_ALARM_TYPE_EVENT = 4, /* �¼�--> ������־ */ + ALM_ALARM_TYPE_DELETE = 5, /* ɾ�� */ + +} CM_ALARM_TYPE; +#define CM_ALARM_TYPE_MACRO +#endif /* #ifndef CM_ALARM_TYPE_MACRO */ + +#ifndef CM_SUBSYSTEM_ID_MACRO +/* �澯ģ��ID���� */ +typedef enum tagCM_SUBSYSTEM_ID { + SUBSYSID_CM = 0, /* CM */ + SUBSYSID_PRO = 1, /* protocol */ + SUBSYSID_TS = 2, /* TSģ�� */ + SUBSYSID_CA = 3, /* CA */ + SUBSYSID_MDS = 4, /* MDS */ + SUBSYSID_DS = 5, /* DS*/ + SUBSYSID_DLM = 6, /* BASE DLM*/ + SUBSYSID_MONC = 7, /* MONC */ + SUBSYSID_TRNS = 8, /* TRNS */ + SUBSYSID_NVCACHE = 9, /* NVCACHE */ + SUBSYSID_PMA = 10, /* PMA */ + SUBSYSID_BASE = 11, /* BASE */ + SUBSYSID_MONS = 12, /* MONS */ + SUBSYSID_NOFS = 13, /* NOFS */ + + SUBSYSID_SQL = 20, /* ��˹���ݿ� */ + SUBSYSID_HD = 21, /* hadoop */ + SUBSYSID_MDM = 22, /* �ļ�ϵͳԪ���ݹ��� */ + + SUBSYSID_BUTT /* ���ֵ */ +} CM_SUBSYSTEM_ID; +#define CM_SUBSYSTEM_ID_MACRO +#endif /*# ifndef CM_SUBSYSTEM_ID_MACRO */ + +/** +���Ʒ���͸澯. +alarmMsg����󳤶�Ϊ1024���������ֻᱻ�ض� +����ֵ�� 0 �ɹ�����0 ʧ�� +*/ +int Gauss_alarm_report(int moduleID, long long alarmID, CM_ALARM_TYPE type, char* alarmMsg, int msgLength); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif //__GAUSS_ALARM_CLENT_H__ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/alarm/gauss_libpq_wrapper.h postgresql-hll-2.14/include/include/alarm/gauss_libpq_wrapper.h --- postgresql-hll-2.14_old/include/include/alarm/gauss_libpq_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gauss_libpq_wrapper.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gauss_libpq_wrapper.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gauss_libpq_wrapper.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_GAUSS_WRAPPER_H__ +#define __GS_GAUSS_WRAPPER_H__ + +#include "alarm/gs_config.h" +#include "alarm/gs_server.h" +#include "alarm/gt_threads.h" + +/* Table name to create and use. If you are changing, + also check for create table function */ +#define WARN_TABLENAME "gswarnings" +#define WARN_CREATE_TABLE_QRY \ + "CREATE TABLE IF NOT EXISTS " WARN_TABLENAME "(moduleid integer, " \ + "submoduleid integer, " \ + "alarmid bigint, " \ + "params varchar(512), " \ + "isresolved boolean, " \ + "warning_time timestamp, " \ + "resolve_time timestamp); " + +/* Have to bind module,submodule,alarm,param, ==> yet to add "warningtime" */ +#define WARN_INSERT_TABLE_QRY \ + "INSERT INTO " WARN_TABLENAME " (moduleid, submoduleid, alarmid, params) VALUES ($1, $2, $3, $4);" + +#define WARN_UPDATE_QRY \ + "UPDATE " WARN_TABLENAME " SET isresolved=true where moduleid=$1 and submoduleid=$2 " \ + "and alarmid=$3;" + +WARNERRCODE gaussConnection(LP_GS_CONFIG config, char* password, LP_GAUSS_CONN* conn); + +void gaussDisconnect(LP_GAUSS_CONN* conn); + +WARNERRCODE createWarningTableIfNotExits(LP_GAUSS_CONN conn); + +WARNERRCODE insertWarning(LP_GAUSS_CONN conn, LP_GS_ALARM alarm); + +WARNERRCODE isOpenWarningExists(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE isOpenWarningExists(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE isOpenWarningExistInLast3Mins(LP_GAUSS_CONN conn, LP_GS_ALARM alarm, bool* isExists); + +WARNERRCODE updateWarningStatusInDB(LP_GAUSS_CONN conn, LP_GS_ALARM alarm); + +#endif //__GS_GAUSS_WRAPPER_H__ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gs_config.h postgresql-hll-2.14/include/include/alarm/gs_config.h --- postgresql-hll-2.14_old/include/include/alarm/gs_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gs_config.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_config.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_config.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_CONFIG_H__ +#define __GS_CONFIG_H__ + +#include "alarm/gs_warn_common.h" + +#define WARN_MAX_NAME_LEN 64 +#define MAX_LEN_USERNAME WARN_MAX_NAME_LEN +#define MAX_LEN_CLUSTERNAME WARN_MAX_NAME_LEN + +typedef enum tagConfigType { + CONFIG_PORT, + CONFIG_GAUSS_HOST, + CONFIG_GAUSS_PORT, + CONFIG_GAUSS_DBNAME, + CONFIG_GAUSS_USERNAME, + CONFIG_GAUSS_PASSWORD, + CONFIG_LOG_FILENAME, + + CONFIG_BUTT = 0xffffffff +} CONFIG_TYPE; + +typedef struct tagGsConfig { + int32 portNum; + char dbHost[MAX_LEN_SERVADDR]; + int32 dbPort; + char username[MAX_LEN_USERNAME]; + char dbname[MAX_LEN_USERNAME]; + char clustername[MAX_LEN_CLUSTERNAME]; +} GS_CONFIG, *LP_GS_CONFIG; + +WARNERRCODE processConfiguration(int32 argc, char* argv[], char** password); +void fillDefaultGaussInfo(); + +#endif //__GS_CONFIG_H__ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gs_server.h postgresql-hll-2.14/include/include/alarm/gs_server.h --- postgresql-hll-2.14_old/include/include/alarm/gs_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gs_server.h 2020-12-12 17:06:43.145346722 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_server.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_WARN_SERVER_H__ +#define __GS_WARN_SERVER_H__ + +#include "alarm/gs_warn_common.h" +#include "libpq-fe.h" +#include "alarm/gt_threads.h" +#include "alarm/gs_config.h" + +#define MAX_THREAD_COUNT 128 + +typedef enum tagGaussConnState { + GAUSS_CONN_INIT, + GAUSS_CONN_CONNECTED, + GAUSS_CONN_CONNECT_FAILED, + GAUSS_CONN_EXECUTING, + GAUSS_CONN_ERROR, + + GAUSS_CONN_BUTT = 0xffffffff +} GAUSS_CONN_STATE; + +typedef struct tagGaussConn { + PGconn* connHandle; + THREAD_LOCK globalsLock; /* Global lock */ + GAUSS_CONN_STATE state; +} GAUSS_CONN, *LP_GAUSS_CONN; + +typedef enum tagServerStates { + SERVER_STATE_INIT, + SERVER_STATE_CONNECTED, + SERVER_STATE_LISTENING, + SERVER_STATE_EXITING, + + SERVER_STATE_BUTT = 0xffffffff +} GAUSS_SERVER_STATES; + +typedef struct tagWmpGlobals { + GT_SOCKET sock; /* Server socket */ + GS_CONFIG config; /* Configuration parameters */ + GAUSS_CONN gaussConn; +} WARN_GLOBALS, *LP_WARN_GLOBALS; + +typedef struct tagClientSession { + GT_SOCKET sock; + char* sendBuf; + char* recvBuf; +} GS_CLIENT_SESSION, *LP_GS_CLIENT_SESSION; + +/* Mock structure of Alarm. If one exits in Gauss then use that. */ +typedef struct tagGsAlarm { + uint64 alarmId; + uint32 moduleId; + uint32 submoduleId; + bool isResolved; + char alarmParam[MAX_ALARM_PARAM_LEN]; +} GS_ALARM, *LP_GS_ALARM; + +extern LP_WARN_GLOBALS globals; +extern bool gIsExit; + +void collectClientWarnings(LPGT_THREAD_S pstThread); +WARNERRCODE getNewThreadCtx(LPGT_THREAD_S* newthreadCtx); + +#endif //__GS_WARN_SERVER_H__ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gs_server_network.h postgresql-hll-2.14/include/include/alarm/gs_server_network.h --- postgresql-hll-2.14_old/include/include/alarm/gs_server_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gs_server_network.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_server_network.h + * + * + * + * IDENTIFICATION + * src/include/alarm/gs_server_network.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __GS_SERVER_NETWORK_H__ +#define __GS_SERVER_NETWORK_H__ + +#include "alarm/gs_warn_common.h" +#include "alarm/gs_server.h" + +WARNERRCODE initNetworkLayer(); + +WARNERRCODE acceptOnSocket(GT_SOCKET listernSock, GT_SOCKET* iClientSock, char* ipAddr, uint16* psPort); + +WARNERRCODE recvData(GT_SOCKET Sock, char* buf, int32 bufSize, int32* dataRecvSize); + +WARNERRCODE sendPacketToClient(GT_SOCKET sock, char* pucBuf, int32 iSize); + +WARNERRCODE sendAck(GT_SOCKET sock, char* sendBuf, int32 errCode); + +void disconnectClient(GT_SOCKET sock); + +WARNERRCODE retrySendAck(LP_GS_CLIENT_SESSION session, int32 errCode); + +WARNERRCODE validateClientPacket(LPGT_PACKET_HEAD header); + +#endif //__GS_SERVER_NETWORK_H__ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gs_utils.h postgresql-hll-2.14/include/include/alarm/gs_utils.h --- postgresql-hll-2.14_old/include/include/alarm/gs_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gs_utils.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_utils.h + * Header file for Gauss warning module utility functions. + * + * + * IDENTIFICATION + * src/include/alarm/gs_utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_UTILS_H__ +#define __GS_UTILS_H__ + +#include "alarm/gs_warn_common.h" + +#define BASE_DECIMAL 10 + +#define MAX_STR_LEN_OF_UINT32 11 + +#define MAX_STR_LEN_OF_UINT64 22 + +WARNERRCODE stringToLong(char* str, int32 base, long* value); + +WARNERRCODE validateIPAddress(char* pucIp, char* key, uint32 slLen); + +WARNERRCODE validatePort(char* str, char* key, int32* port); + +void stringCopy(char* dest, char* src, uint32 iMaxLen); + +bool compareString(char* str1, char* str2); + +void uint32ToStr(uint32 intVal, char* strVal); + +void uint64ToStr(uint64 longVal, char* strVal); + +void writeUIntToBuffer(char* buf, uint32 value, int32* iBufPos); + +void writeULongToBuffer(char* buf, uint64 value, int32* iBufPos); + +void writeNULLToBuffer(char* buf, int32* iBufPos); + +void writeStringToBuffer(char* buf, char* str, int32* iBufPos); + +#endif //__GS_UTILS_H__ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gs_warn_common.h postgresql-hll-2.14/include/include/alarm/gs_warn_common.h --- postgresql-hll-2.14_old/include/include/alarm/gs_warn_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gs_warn_common.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,145 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_warn_common.h + * Warning module common header file. + * + * + * IDENTIFICATION + * src/include/alarm/gs_warn_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GT_WARN_COMMON_H__ +#define __GT_WARN_COMMON_H__ + +#include "c.h" +#include "alarm/GaussAlarm_client.h" + +#define GT_FALSE 0 +#define GT_TRUE 1 +#define GT_NULL_POINTER NULL +#define GT_SOCKET int32 +#define MAX_PORT_CHAR_SIZE 6 +#define LOCALHOST "127.0.0.1" +#define SOCKET_OPT_IS_REUSE_ADDR 1 +#define SOCKET_OPT_IS_KEEP_ALIVE 1 +#define GT_MAGIC_NUMBER 0xabcdef87 +#define GT_PROTOCOL_VERSION 0x0001 +#define MAX_ALARM_PARAM_LEN 1024 // Alarm params length +#define MAX_SEND_RETRY_COUNT 3 +#define MAX_RECV_RETRY_COUNT 3 + +#define GT_NETWORK_BYTE_ORDER 0 +#define GT_NON_NETWORK_BYTE_ORDER 1 +#define SYS_BYTE_ORDER \ + ((0x01020304 == *(int32*)(void*)"\x1\x2\x3\x4") ? GT_NETWORK_BYTE_ORDER : GT_NON_NETWORK_BYTE_ORDER) + +/* Packet header size */ +#define GT_PACKET_HEADER_SIZE sizeof(GT_PACKET_HEAD) +#define GT_PACKET_MAX_PAYLOAD_SIZE (GT_SEND_BUFFER_SIZE - GT_PACKET_HEADER_SIZE) + +#define GT_SEND_BUFFER_SIZE 4096 /* 4K */ +#define GT_RECV_BUFFER_SIZE 4096 /* 4K */ +/* The max length of address consisting of IP */ +#define MAX_LEN_SERVADDR 32 + +/* Mapping system function to own functions, to enable future changes */ +#define GT_MALLOC malloc +#define GT_FREE(mem) \ + if (GT_NULL_POINTER != mem) { \ + free(mem); \ + } +#define GTLOG(...) printf(__VA_ARGS__) +#define GTCONSOLELOG(...) printf(__VA_ARGS__) + +/* Error codes - to be integrated with Gauss */ +typedef enum tagWarnErrorCodes { + GT_SUCCESS = 0, + GTERR_END_OF_WARNINGS, + + GTERR_MEMORY_ALLOC_FAILED = 0x00001100, + GTERR_THREAD_INIT_FAILED, + GTERR_THREAD_CREATE_FAILED, + GTERR_THREAD_DESTROY_FAILED, + GTERR_THREAD_ACQUIRE_LOCK_FAILED, + GTERR_THREAD_RELEASE_LOCK_FAILED, + + GTERR_SOCKET_CONNECT_FAILED, + GTERR_SOCKET_WRITE_FAILED, + GTERR_SOCKET_READ_FAILED, + GTERR_SOCKET_CLOSED, + + GTERR_INTEGER_OVERFLOW, + GTERR_INVALID_VALUE, + + GTERR_LISTENER_START_FAILED, + GTERR_INSUFFICIENT_CONFIGS, + GTERR_INVALID_CONFIG_VALUE, + + GTERR_SHUTDOWN_INPROGRESS, + GTERR_CONNECT_TO_WMP_FAILED, + GTERR_INVALID_PACKET, + GTERR_COMMAND_SEND_TIMEDOUT, + GTERR_RESEND_WARNING, + + GTERR_GAUSS_CONN_FAILED, + GTERR_GAUSS_CONNECTION_LOST, + GTERR_GAUSS_DATA_FETCH_FAILED, + + GTERR_BUTT = 0xffffffff +} WARNERRCODE; + +/*** + * List of commands understood by Client - Server network layer. + ***/ +typedef enum tagGTPacketHeadCmds { + GT_PKT_WARNING = 0x00022001, + GT_PKT_END_OF_WARNINGS, + GT_PKT_SERVER_ERROR, + GT_PKT_GET_ALL_WARNINGS, + GT_PKT_ACK, + + GT_PKT_BUTT = 0xffffffff +} GT_PACKET_HEAD_CMDS; + +/*** + * Packet header for Client-Server communication. + * + ***/ +typedef struct tagGtPacketHead { + uint32 ulMagicNum; /* Magic number used for packet validation */ + int32 packetCmd; /* Type of command being executed */ + uint16 usProtocolVersion; /* Protocol version */ + int8 rsvd1[2]; /*Alignment */ + uint32 uiSize; /* Size of the packet including header */ + int32 uiErrorCode; /* Error code. 0 for success */ + uint32 uiTotDataSize; /* Size of the complete Data, valid for 1st packet */ + int8 cByteOrder; /* Byte order */ + bool bIsPendingData; /* Is the data partial */ + int8 rsvd2[2]; + int32 cOptions; /* Placeholder holder for future use */ +} GT_PACKET_HEAD, *LPGT_PACKET_HEAD; + +/*** + * Client Server Packet overall structure + ***/ +typedef struct tagGtPacket { + GT_PACKET_HEAD packetHeader; + unsigned char* packetPayload; +} GT_PACKET, *LPGT_PACKET; + +#endif /* __GT_WARN_COMMON_H__ */ diff -uprN postgresql-hll-2.14_old/include/include/alarm/gt_threads.h postgresql-hll-2.14/include/include/alarm/gt_threads.h --- postgresql-hll-2.14_old/include/include/alarm/gt_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/alarm/gt_threads.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,142 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gt_threads.h + * Thread operations functionality header file. Uses pthread library. + * This library is part of Gauss tools common code library. + * + * + * IDENTIFICATION + * src/include/alarm/gt_threads.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GT_THREADS_H__ +#define __GT_THREADS_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include +#include +#include "alarm/gs_warn_common.h" + +extern "C" { + +#define GT_THREAD_STACK_SIZE 131072 /* 128K [32768 - 32K thread stack size] */ +#define GT_THREAD_SLEEP_TIME (100) /* 1/10th of a sec */ +#define GT_THREAD_START_MAX_RETRY_COUNT (10000) /* 10s */ +#define MAX_THREAD_NAME_LEN 16 + +typedef pthread_mutex_t THREAD_LOCK; + +/* Thread state enum. */ +typedef enum tagGTThreadStatUS_E { + GT_THREAD_FREE = 0, + GT_THREAD_STARTING, + GT_THREAD_STARTED, + GT_THREAD_RUNNING, + GT_THREAD_START_FAILED, + GT_THREAD_EXITING, + + GT_THREAD_BUTT = 0xffff +} GT_THREAD_STATUS_E; + +/* Thread structure definition. */ +typedef struct tagGTThread { + pthread_t id; + + /* thread's run-time status, other thread can read it*/ + GT_THREAD_STATUS_E enStatus; + + void* pvProc; /* pointer of thread entry procedure*/ + void* pvArgument; /* argument */ + int32 ulResult; /* result of thread's execution */ + bool bExitThreadFlag; /* thread will quit gracefully, if set */ + void* pvCleanup; /* Any cleanup like release thread to pool etc */ +} GT_THREAD_S, *LPGT_THREAD_S; + +/*** + * Function signature for the thread entry functions. + * + * @param pstThread Thread context + * @return NA + ***/ +typedef void (*LPGT_THREAD_PROC)(LPGT_THREAD_S pstThread); + +/*** + * Create thread on demand. + * + * @param pfnProc : Function pointer, entry function to the thread. + * @param pvArgs : Argument to the entry function. + * @param ulStackSize : Stack size of the new thread. + * @param pstThread : Thread context structure. + * + * @ return GT_SUCCESS on success or error code on failure. + ***/ +WARNERRCODE createThread(LPGT_THREAD_PROC pfnThreadProc, void* pvArgs, uint32 ulStackSize, LPGT_THREAD_S pstThread); + +/*** + * Joins the thread to parent. Wait for the thread to close. + * + * @param pstThread : Thread context structure. + * @ return NA. + ***/ +void closeThread(LPGT_THREAD_S pstThread); + +/*** + * Get the current thread id + * + * @return id of the current thread. + ***/ +int32 getThreadID(); + +/*** + * Sleep function for the thread. + * + * @param sleep time in milli-second + ***/ +void threadSleep(uint32 ulSleepMs); + +/*** + * Initialize the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE initThreadLock(THREAD_LOCK* lock); + +/*** + * Destory the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE destroyThreadLock(THREAD_LOCK* lock); + +/*** + * Acquire Lock the thread + * + * @param lock parameter + ***/ +WARNERRCODE lock(THREAD_LOCK* lock); + +/*** + * Release the thread lock + * + * @param lock parameter + ***/ +WARNERRCODE unlock(THREAD_LOCK* lock); +} + +#endif /* __GT_THREADS_H__ */ diff -uprN postgresql-hll-2.14_old/include/include/auditfuncs.h postgresql-hll-2.14/include/include/auditfuncs.h --- postgresql-hll-2.14_old/include/include/auditfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/auditfuncs.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,52 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * auditfuncs.h + * record the aduit informations of the database operation + * + * + * IDENTIFICATION + * src/include/auditfuncs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PGAUDIT_AGENT_H +#define PGAUDIT_AGENT_H +#include "pgaudit.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/namespace.h" + +#define PGAUDIT_MAXLENGTH 1024 +#define NoShutdown 0 +#define SmartShutdown 1 +#define FastShutdown 2 +#define ImmediateShutdown 3 + +char* pgaudit_get_relation_name(List* relation_name_list); +void pgaudit_dml_table(const char* objectname, const char* cmdtext); +void pgaudit_dml_table_select(const char* objectname, const char* cmdtext); + +extern void pgaudit_agent_init(void); +extern void pgaudit_agent_fini(void); +extern void pgaudit_user_no_privileges(const char* object_name, const char* detailsinfo); +extern void pgaudit_system_start_ok(int port); +extern void pgaudit_system_switchover_ok(const char* detaisinfo); +extern void pgaudit_system_recovery_ok(void); +extern void pgaudit_system_stop_ok(int shutdown); +extern void pgaudit_user_login(bool login_ok, const char* object_name, const char* detaisinfo); +extern void pgaudit_user_logout(void); +extern void pgaudit_lock_or_unlock_user(bool islocked, const char* user_name); +#endif diff -uprN postgresql-hll-2.14_old/include/include/bin/elog.h postgresql-hll-2.14/include/include/bin/elog.h --- postgresql-hll-2.14_old/include/include/bin/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bin/elog.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * elog.h + * + * + * + * IDENTIFICATION + * src/include/bin/elog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMMON_H +#define COMMON_H + +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); +extern void write_log(const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); +extern void init_log(char* prefix_name); +extern void check_env_value_c(const char* input_env_value); +extern void check_env_name_c(const char* input_env_value); +#endif /* COMMON_H */ diff -uprN postgresql-hll-2.14_old/include/include/bootstrap/bootstrap.h postgresql-hll-2.14/include/include/bootstrap/bootstrap.h --- postgresql-hll-2.14_old/include/include/bootstrap/bootstrap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bootstrap/bootstrap.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * bootstrap.h + * include file for the bootstrapping code + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/bootstrap/bootstrap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BOOTSTRAP_H +#define BOOTSTRAP_H + +#include "nodes/execnodes.h" + +/* + * MAXATTR is the maximum number of attributes in a relation supported + * at bootstrap time (i.e., the max possible in a system table). + */ +#define MAXATTR 40 + +extern void BootStrapProcessMain(int argc, char* argv[]); + +extern void err_out(void); + +extern void closerel(char* name); +extern void boot_openrel(char* name); + +extern void DefineAttr(const char* name, char* type, int attnum); +extern void InsertOneTuple(Oid objectid); +extern void InsertOneValue(char* value, int i); +extern void InsertOneNull(int i); + +extern const char* MapArrayTypeName(const char* s); + +extern void index_register(Oid heap, Oid ind, IndexInfo* indexInfo); +extern void build_indices(void); + +extern void boot_get_type_io_data(Oid typid, int16* typlen, bool* typbyval, char* typalign, char* typdelim, + Oid* typioparam, Oid* typinput, Oid* typoutput); + +extern int boot_yyparse(void); + +extern int boot_yylex(void); +extern void boot_yyerror(const char* str); + +#endif /* BOOTSTRAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/bulkload/dist_fdw.h postgresql-hll-2.14/include/include/bulkload/dist_fdw.h --- postgresql-hll-2.14_old/include/include/bulkload/dist_fdw.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/dist_fdw.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,144 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dist_fdw.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/dist_fdw.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __DIST_FDW_H__ +#define __DIST_FDW_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" +#include "nodes/nodes.h" +#include "nodes/pg_list.h" +#include "storage/block.h" +#include "storage/fd.h" +#include "nodes/parsenodes.h" +#include "bulkload/importerror.h" + +extern "C" Datum dist_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum dist_fdw_validator(PG_FUNCTION_ARGS); + +extern "C" Datum file_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum file_fdw_validator(PG_FUNCTION_ARGS); + +extern "C" Datum hdfs_fdw_handler(PG_FUNCTION_ARGS); +extern "C" Datum hdfs_fdw_validator(PG_FUNCTION_ARGS); + +#ifdef ENABLE_MOT +extern "C" Datum mot_fdw_validator(PG_FUNCTION_ARGS); +extern "C" Datum mot_fdw_handler(PG_FUNCTION_ARGS); +#endif + +extern void encryptOBSForeignTableOption(List** options); + +/* + * in shared mode coordinator assign file to data node + */ +typedef struct DistFdwFileSegment { + NodeTag type; + char* filename; + long begin; + long end; /* -1 means read the end of file*/ + int64 ObjectSize; +} DistFdwFileSegment; + +typedef struct DistFdwDataNodeTask { + NodeTag type; + char* dnName; + List* task; +} DistFdwDataNodeTask; + +typedef struct { + NodeTag type; + int logger_num; /* number of loggers */ + RangeTblEntry* rte; /* error relation*/ + char* filename; /* path of cache file*/ + ImportErrorLogger** loggers; /* error logger */ +} ErrorCacheEntry; + +extern const char* optLocation; +extern const char* optFormat; +extern const char* optHeader; +extern const char* optDelimiter; +extern const char* optQutote; +extern const char* optEscape; +extern const char* optNull; +extern const char* optEncoding; +extern const char* optFillMissFields; +extern const char* optRejectLimit; +extern const char* optMode; +extern const char* optForceNotNull; +extern const char* optWriteOnly; +extern const char* optWithoutEscaping; +extern const char* optErrorRel; +extern const char* optFormatter; +extern const char* optFix; +extern const char* optFileHeader; +extern const char* optOutputFilePrefix; +extern const char* optOutputFixAlignment; + +extern const char* optLogRemote; +extern const char* optSessionKey; +extern const char* optTaskList; +extern const char* optIgnoreExtraData; + +/* OBS specific options */ +extern const char* optChunkSize; +extern const char* optAsync; +extern const char* optEncrypt; +extern const char* optAccessKey; +extern const char* optSecretAccessKey; +#define DEST_CIPHER_LENGTH 1024 + +/* + * bulkload compatible illegal chars option + */ +extern const char* optCompatibleIllegalChars; +/* + * bulkload datetime format options + */ +extern const char* optDateFormat; +extern const char* optTimeFormat; +extern const char* optTimestampFormat; +extern const char* optSmalldatetimeFormat; + +extern const char* GSFS_PREFIX; +extern const char* GSFSS_PREFIX; +extern const char* LOCAL_PREFIX; +extern const char* ROACH_PREFIX; +extern const char* GSOBS_PREFIX; +extern const int GSFS_PREFIX_LEN; +extern const int GSFSS_PREFIX_LEN; +extern const int LOCAL_PREFIX_LEN; +extern const int ROACH_PREFIX_LEN; +extern const int GSOBS_PREFIX_LEN; + +extern bool is_obs_protocol(const char* filename); +// reject_limit is set as unlimited +// +#define REJECT_UNLIMITED -1 + +extern ErrorCacheEntry* GetForeignErrCacheEntry(Oid relid, uint32 distSessionKey); +List* CNSchedulingForDistOBSFt(Oid foreignTableId); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/bulkload/foreignroutine.h postgresql-hll-2.14/include/include/bulkload/foreignroutine.h --- postgresql-hll-2.14_old/include/include/bulkload/foreignroutine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/foreignroutine.h 2020-12-12 17:06:43.146346735 +0800 @@ -0,0 +1,100 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * foreignroutine.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/foreignroutine.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FOREIGNROUTINE_H +#define FOREIGNROUTINE_H + +#include "nodes/execnodes.h" +#include "commands/copy.h" +#include "commands/explain.h" + +#define IS_SHARED_MODE(mode) ((mode) == MODE_SHARED) +#define IS_NORMAL_MODE(mode) ((mode) == MODE_NORMAL) +#define IS_PRIVATE_MODE(mode) ((mode) == MODE_PRIVATE) +#define IS_INVALID_MODE(mode) ((mode) == MODE_INVALID) + +typedef struct DistImportExecutionState : public CopyStateData { + List* source; /* data input source */ + List* options; /* merged COPY options, excluding filename */ + int rejectLimit; + Relation errLogRel; + Datum beginTime; + List* elogger; + bool isLogRemote; + bool needSaveError; +} DistImportExecutionState; + +typedef struct DistImportPlanState { + char* filename; + List* source; /* data input source */ + List* options; /* merged options, excluding filename */ + BlockNumber pages; /* estimate of file's physical size */ + double ntuples; /* estimate of number of rows in file */ + int rejectLimit; + char* errorName; + ImportMode mode; + bool writeOnly; + int fileEncoding; + bool doLogRemote; + char* remoteName; + + // explicit constructor + DistImportPlanState() + : filename(NULL), + source(NULL), + options(NULL), + pages(0), + ntuples(0), + rejectLimit(0), + errorName(NULL), + mode(MODE_INVALID), + writeOnly(false), + fileEncoding(0), + doLogRemote(false), + remoteName(NULL) + { + } +} DistImportPlanState; + +extern void ProcessDistImportOptions(DistImportPlanState *planstate, List *options, bool isPropagateToFE, + bool isValidate = false); + +extern void distImportGetRelSize(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); +extern void distImportGetPaths(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); +extern ForeignScan* distImportGetPlan(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid, + ForeignPath* best_path, List* tlist, List* scan_clauses); + +extern void distImportExplain(ForeignScanState* node, ExplainState* es); + +extern void distImportBegin(ForeignScanState* node, int eflags); + +extern TupleTableSlot* distExecImport(ForeignScanState* node); + +extern void distImportEnd(ForeignScanState* node); + +extern void distReImport(ForeignScanState* node); + +extern void getOBSOptions(ObsCopyOptions* obs_copy_options, List* options); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/bulkload/importerror.h postgresql-hll-2.14/include/include/bulkload/importerror.h --- postgresql-hll-2.14_old/include/include/bulkload/importerror.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/importerror.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,205 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * importerror.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/importerror.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef IMPORTERROR_H +#define IMPORTERROR_H + +#include "access/tupdesc.h" +#include "commands/gds_stream.h" +#include "storage/fd.h" + +typedef struct CopyStateData* CopyState; + +struct ErrLogInfo { + /* SMP ID */ + uint32 smp_id; + + /* + * T, responsibility for unlinking local cache file. + * see also FD_ERRTBL_LOG_OWNER flag. + */ + bool unlink_owner; +}; + +class BaseError : public BaseObject { +public: + BaseError() + { + m_desc = NULL; + Reset(); + } + virtual ~BaseError() + { + } + + virtual void Serialize(StringInfo buf); + + virtual void Deserialize(StringInfo buf); + + virtual void serializeMaxNumOfValue(StringInfo buf) = 0; + + void Reset(); + + static const int StartTimeIdx = 1; + static const int FileNameIdx = 2; + static const int LineNOIdx = 3; + static const int RawDataIdx = 4; + static const int DetailIdx = 5; + static const int MaxNumOfValue = 6; + + Datum m_values[MaxNumOfValue]; + bool m_isNull[MaxNumOfValue]; + TupleDesc m_desc; +}; + +class ImportError : public BaseError { +public: + ImportError() + { + } + ~ImportError() + { + } + + void serializeMaxNumOfValue(StringInfo buf) override; + + static const int NodeIdIdx = 0; +}; + +/* ImportError for Copy */ +class CopyError : public BaseError { +public: + CopyError() + { + } + ~CopyError() + { + } + + void serializeMaxNumOfValue(StringInfo buf) override; + + static const int RelNameIdx = 0; +}; + +class BaseErrorLogger : public BaseObject { +public: + BaseErrorLogger() : m_memCxt(NULL), m_errDesc(NULL), m_buffer(NULL), m_fd(-1), m_offset(0) + { + } + virtual ~BaseErrorLogger() + { + } + + virtual void Destroy() = 0; + virtual int FetchError(BaseError* edata); + virtual void SaveError(BaseError* edata); + + MemoryContext m_memCxt; + TupleDesc m_errDesc; + +protected: + /* for LocalErrorLogger and CopyErrorLogger */ + StringInfo m_buffer; + File m_fd; + Size m_offset; +}; + +class ImportErrorLogger : public BaseErrorLogger { +public: + ImportErrorLogger() + { + } + virtual ~ImportErrorLogger() + { + } + + virtual void Destroy() override; + + virtual void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo); + virtual void FormError(CopyState cstate, Datum begintime, ImportError* edata){}; +}; + +class GDSErrorLogger : public ImportErrorLogger { +public: + GDSErrorLogger() : m_output(NULL), m_name(NULL) + { + } + ~GDSErrorLogger() + { + } + + void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo) override; + void Destroy() override; + /* GDSErrorLogger doesn't support FetchError method */ + int FetchError(BaseError* edata) override; + void SaveError(BaseError* edata) override; + void FormError(CopyState cstate, Datum begintime, ImportError* edata) override; + +private: + GDSStream* m_output; + char* m_name; +#ifdef USE_ASSERT_CHECKING + int m_counter; +#endif +}; + +class LocalErrorLogger : public ImportErrorLogger { +public: + LocalErrorLogger() + { + } + ~LocalErrorLogger() + { + } + + void Initialize(const void* output, TupleDesc errDesc, ErrLogInfo& errInfo) override; + void Destroy() override; + void FormError(CopyState cstate, Datum begintime, ImportError* edata) override; +}; + +/* Error logger for copy */ +class CopyErrorLogger : public BaseErrorLogger { +public: + CopyErrorLogger() : m_namespace(NULL) + { + } + ~CopyErrorLogger() + { + } + + void Destroy() override; + + void Initialize(CopyState cstate); + void Reset(); + void FormError(CopyState cstate, Datum begintime, CopyError* edata); + + char* m_namespace; +}; + +extern char* generate_unique_cache_name_prefix(Oid oid, uint32 distSessionKey); +extern char* generate_unique_cache_name_prefix(const char* relname); +extern void unlink_local_cache_file(const char* prefix, const uint32 smpId); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/bulkload/roach_adpter.h postgresql-hll-2.14/include/include/bulkload/roach_adpter.h --- postgresql-hll-2.14_old/include/include/bulkload/roach_adpter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/roach_adpter.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * roach_adpter.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/roach_adpter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __ROACH_ADPTER_H__ +#define __ROACH_ADPTER_H__ + +#include "bulkload/roach_api.h" +#include "commands/copy.h" + +template +extern bool getNextRoach(CopyState cstate); + +extern int copyGetRoachData(CopyState cstate, void* databuf, int minread, int maxread); + +template +extern void initRoachState(CopyState cstate, const char* filename, List* totalTask); + +extern void endRoachBulkLoad(CopyState cstate); + +extern void exportRoach(CopyState cstate); + +extern void exportRoachFlushOut(CopyState cstate, bool isWholeLineAtEnd); + +extern RoachRoutine* initRoachRoutine(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/bulkload/roach_api.h postgresql-hll-2.14/include/include/bulkload/roach_api.h --- postgresql-hll-2.14_old/include/include/bulkload/roach_api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/roach_api.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * roach_api.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/roach_api.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef __ROACH_API_H__ +#define __ROACH_API_H__ + +#include "nodes/nodes.h" + +#ifndef __cplusplus + +#ifndef bool +typedef char bool; +#endif + +#ifndef true +#define true((bool)1) +#endif + +#ifndef false +#define false((bool)0) +#endif + +#endif /* __cplusplus */ + +typedef void* (*OpenFunc)(char* url, char* mode); +typedef size_t (*WriteFunc)(void* buf, size_t size, size_t len, void* roach_context, bool complete_line); +typedef size_t (*ReadFunc)(void* buf, size_t size, size_t len, void* roach_context); +typedef int (*CloseFunc)(void* roach_context); +typedef int (*ErrorFunc)(void* roach_context); + +typedef struct RoachRoutine { + NodeTag type; + OpenFunc Open; + WriteFunc Write; + ReadFunc Read; + CloseFunc Close; + ErrorFunc Error; +} RoachRoutine; + +#endif /*__ROACH_API_H__*/ diff -uprN postgresql-hll-2.14_old/include/include/bulkload/utils.h postgresql-hll-2.14/include/include/bulkload/utils.h --- postgresql-hll-2.14_old/include/include/bulkload/utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/utils.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,312 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * utils.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef UTILS_H_ +#define UTILS_H_ + +#ifndef WIN32 +#include "postgres.h" +#include "knl/knl_variable.h" +#endif + +#ifndef GDS_SERVER +#include "cjson/cJSON.h" +#else +#include "gds.h" +#endif + +typedef enum { + CMD_TYPE_BEGIN, // 0db->gds + CMD_TYPE_END, // 1db<->gds + CMD_TYPE_EXPLAIN, // 2not support + CMD_TYPE_RESPONSE, // 3db<-gds + CMD_TYPE_CANCEL, // 4not support + CMD_TYPE_REQ, // 5db->gds + CMD_TYPE_ERROR, // 6db<-gds + CMD_TYPE_FILE_SWITCH, // 7db<-gds + CMD_TYPE_DATA, // 8db<->gds + CMD_TYPE_QUERY_RESULT, // 9db<-gds + CMD_TYPE_REMOTELOG, // 10db->gds + CMD_TYPE_DATA_SEG, // 11indicate a segment of line, db<-gds + CMD_TYPE_QUERY_RESULT_V1, // 12update version of QR, db<-gds + CMD_TYPE_INVALID +} GDSCmdType; + +struct CmdBase { + char m_type; + + // explicit constructor + CmdBase() : m_type(0) + { + } + + virtual ~CmdBase(){}; +}; + +struct CmdData : public CmdBase { + char* m_data; + uint32 m_len; + + CmdData() : m_data(NULL), m_len(0) + { + } +}; + +struct CmdBegin : public CmdBase { + char* m_url; + uint64 m_id; + char m_format; + char m_nodeType; + char m_quote; + char m_escape; + char* m_eol; + bool m_header; + int m_nodeNum; + char* m_nodeName; + int m_fixSize; + char* m_prefix; + char* m_fileheader; + + CmdBegin() + { + m_url = NULL; + m_id = 0; + m_format = -1; + m_nodeType = 'C'; + m_quote = '"'; + m_escape = '"'; + m_eol = NULL; + m_header = false; + m_nodeNum = 0; + m_nodeName = NULL; + m_fixSize = 0; + m_prefix = NULL; + m_fileheader = NULL; + } + ~CmdBegin() + { + if (m_url) + cJSON_free(m_url); + if (m_eol) + cJSON_free(m_eol); + if (m_nodeName) + cJSON_free(m_nodeName); + if (m_prefix) + cJSON_free(m_prefix); + if (m_fileheader) + cJSON_free(m_fileheader); + } +}; + +struct CmdResponse : public CmdBase { + int m_result; + char* m_reason; + CmdResponse() : m_result(0), m_reason(NULL) + { + } + + ~CmdResponse() + { + if (m_reason) + cJSON_free(m_reason); + } +}; + +struct CmdError : public CmdBase { + char m_level; + char* m_detail; + + CmdError() : m_level(0), m_detail(NULL) + { + } + + ~CmdError() + { + if (m_detail) + cJSON_free(m_detail); + } +}; + +struct CmdRemoteLog : public CmdBase { + int m_datasize; + char* m_data; + char* m_name; + CmdRemoteLog() : m_datasize(0), m_data(NULL), m_name(NULL) + { + } + + ~CmdRemoteLog() + { + if (m_name) + cJSON_free(m_name); + } +}; + +struct CmdFileSwitch : public CmdBase { + char* m_fileName; + + CmdFileSwitch() : m_fileName(NULL) + { + } + ~CmdFileSwitch() + { + if (m_fileName) + cJSON_free(m_fileName); + } +}; + +struct CmdQueryResult : public CmdBase { + int m_result; + const char* m_version_num; + + // explicit constructor + CmdQueryResult() : m_result(0) + { + } +}; + +inline void U64ToString(uint64 in, char* out, int len) +{ +#if __WORDSIZE == 64 + int rc = snprintf_s(out, len, len - 1, "%lu", in); + securec_check_ss(rc, "\0", "\0"); +#else + int rc = snprintf_s(out, len, len - 1, "%llu", in); + securec_check_ss(rc, "\0", "\0"); +#endif +} + +#define WRITE_JSON_START(_type, obj) do { \ + cJSON *json = cJSON_CreateObject(); \ + char *print = NULL; \ + _type *tmp = obj; \ + if (json == NULL) \ +break +#define WRITE_JSON_INT(_field) cJSON_AddNumberToObject(json, #_field, tmp->_field) +#define WRITE_JSON_BOOL(_field) cJSON_AddBoolToObject(json, #_field, tmp->_field) +#define WRITE_JSON_STRING(_field) do { \ + if (tmp->_field) \ + cJSON_AddStringToObject(json, #_field, tmp->_field); \ +} while (0) + +#define WRITE_JSON_UINT64(_field) do { \ + char tmpstr[128]; \ + U64ToString(tmp->_field, tmpstr, 128); \ + cJSON_AddStringToObject(json, #_field, tmpstr); \ +} while (0) + +#define WRITE_JSON_END() \ + print = cJSON_Print(json); \ + cJSON_Delete(json); \ + return print; \ + } \ + while (0) \ + ; \ + return NULL + +#define READ_JSON_START(_type, obj, msg) do { \ + cJSON *json = cJSON_Parse(msg); \ + _type *tmp = obj; \ + cJSON *tmpObj = NULL; \ + if (json == NULL) \ +return -1 + +#define READ_JSON_INT(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = tmpObj->valueint; \ + else \ + return -1; \ + } while (0) + +#define READ_JSON_STRING(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = (char*)cJSON_strdup((const unsigned char*)tmpObj->valuestring); \ + else \ + tmp->_field = NULL; \ + } while (0) + +#define READ_JSON_BOOL(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) \ + tmp->_field = tmpObj->type == cJSON_True; \ + else \ + return -1; \ + } while (0) + +#define READ_JSON_UINT64(_field) \ + do { \ + tmpObj = cJSON_GetObjectItem(json, #_field); \ + if (tmpObj) { \ + char* str = tmpObj->valuestring; \ + if (str) { \ + char* _end; \ + tmp->_field = strtoul(str, &_end, 10); \ + } else { \ + return -1; \ + } \ + } else { \ + return -1; \ + } \ + } while (0) + +#define READ_JSON_END() \ + cJSON_Delete(json); \ + } \ + while (0) \ + ; \ + return 0 + +typedef enum { + LEVEL_STATUS = 17, + LEVEL_LOG, + LEVEL_WARNING, + LEVEL_ERROR +} LogLevel; + +#define GDSCmdHeaderSize 5 /*length of Cmd header*/ + +typedef enum { + FORMAT_UNKNOWN, + FORMAT_BINARY, + FORMAT_CSV, + FORMAT_TEXT, + FORMAT_FIXED, + FORMAT_REMOTEWRITE +} FileFormat; + +typedef enum { + NOTIFY_CMD_ADD_SESSION, /* used to add a new session just for worker thread */ + NOTIFY_CMD_DEL_WORKLOAD, /* used to delete a work load just for main thread */ + NOTIFY_CMD_ERROR_LOG, /* used to commit all kinds of error log for main thread and worker threads */ + NOTIFY_CMD_EXIT, /* used to notify threads to exit */ + NOTIFY_CMD_UNKNOWN /* a boundary */ +} NotifyCmdType; + +#endif /* UTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/bulkload/vecforeignroutine.h postgresql-hll-2.14/include/include/bulkload/vecforeignroutine.h --- postgresql-hll-2.14_old/include/include/bulkload/vecforeignroutine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/bulkload/vecforeignroutine.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecforeignroutine.h + * + * + * + * IDENTIFICATION + * src/include/bulkload/vecforeignroutine.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H +#define SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H +#include "nodes/execnodes.h" + +extern VectorBatch* distExecVecImport(VecForeignScanState* node); + +#endif // SRC_INCLUDE_BULKLOAD_VECFOREIGNROUTINE_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/catalog/catalog.h postgresql-hll-2.14/include/include/catalog/catalog.h --- postgresql-hll-2.14_old/include/include/catalog/catalog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/catalog.h 2020-12-12 17:06:43.147346748 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * catalog.h + * prototypes for functions in backend/catalog/catalog.c + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/catalog.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATALOG_H +#define CATALOG_H + +/* + * 'pgrminclude ignore' needed here because CppAsString2() does not throw + * an error if the symbol is not defined. + */ +#include "catalog/catversion.h" /* pgrminclude ignore */ +#include "catalog/pg_class.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +#define FORKNAMECHARS 4 /* max chars for a fork name */ +#define OIDCHARS 10 /* max chars printed by %u */ +#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \ + CppAsString2(CATALOG_VERSION_NO) + +/* file name: Cxxxxx.0 + * the max length is up to MaxAttrNumber + */ +#define COLFILE_SUFFIX "C" +#define COLFILE_SUFFIX_MAXLEN 8 + +extern const char *forkNames[]; +extern ForkNumber forkname_to_number(char *forkName, BlockNumber *segno = NULL); +extern int forkname_chars(const char *str, ForkNumber *); + +extern char *relpathbackend(RelFileNode rnode, BackendId backend, ForkNumber forknum); +extern char *GetDatabasePath(Oid dbNode, Oid spcNode); +extern char* GetBucketDirPath(const RelFileNodeBackend& rel_file_node_backend); + + +/* First argument is a RelFileNodeBackend */ +#define relpath(rnode, forknum) \ + relpathbackend((rnode).node, (rnode).backend, (forknum)) + +/* First argument is a RelFileNode */ +#define relpathperm(rnode, forknum) \ + relpathbackend((rnode), InvalidBackendId, (forknum)) + +extern RelFileNodeForkNum relpath_to_filenode(char *path); + +extern bool IsSystemRelation(Relation relation); +extern bool IsToastRelation(Relation relation); +extern bool IsCatalogRelation(Relation relation); + +extern bool IsSystemClass(Form_pg_class reltuple); +extern bool IsToastClass(Form_pg_class reltuple); +extern bool IsCatalogClass(Oid relid, Form_pg_class reltuple); + +extern bool IsSystemNamespace(Oid namespaceId); +extern bool IsToastNamespace(Oid namespaceId); +extern bool IsCStoreNamespace(Oid namespaceId); + +extern bool IsPerformanceNamespace(Oid namespaceId); +extern bool IsSnapshotNamespace(Oid namespaceId); + +extern bool IsReservedName(const char *name); + +extern bool IsSharedRelation(Oid relationId); + +extern Oid GetNewOid(Relation relation); +extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); +extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence); + +#endif /* CATALOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/catversion.h postgresql-hll-2.14/include/include/catalog/catversion.h --- postgresql-hll-2.14_old/include/include/catalog/catversion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/catversion.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * catversion.h + * "Catalog version number" for PostgreSQL. + * + * The catalog version number is used to flag incompatible changes in + * the PostgreSQL system catalogs. Whenever anyone changes the format of + * a system catalog relation, or adds, deletes, or modifies standard + * catalog entries in such a way that an updated backend wouldn't work + * with an old database (or vice versa), the catalog version number + * should be changed. The version number stored in pg_control by initdb + * is checked against the version number compiled into the backend at + * startup time, so that a backend can refuse to run in an incompatible + * database. + * + * The point of this feature is to provide a finer grain of compatibility + * checking than is possible from looking at the major version number + * stored in PG_VERSION. It shouldn't matter to end users, but during + * development cycles we usually make quite a few incompatible changes + * to the contents of the system catalogs, and we don't want to bump the + * major version number for each one. What we can do instead is bump + * this internal version number. This should save some grief for + * developers who might otherwise waste time tracking down "bugs" that + * are really just code-vs-database incompatibilities. + * + * The rule for developers is: if you commit a change that requires + * an initdb, you should update the catalog version number (as well as + * notifying the pghackers mailing list, which has been the informal + * practice for a long time). + * + * The catalog version number is placed here since modifying files in + * include/catalog is the most common kind of initdb-forcing change. + * But it could be used to protect any kind of incompatible change in + * database contents or layout, such as altering tuple headers. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/catversion.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATVERSION_H +#define CATVERSION_H + +/* + * We could use anything we wanted for version numbers, but I recommend + * following the "YYYYMMDDN" style often used for DNS zone serial numbers. + * YYYYMMDD are the date of the change, and N is the number of the change + * on that day. (Hopefully we'll never commit ten independent sets of + * catalog changes on the same day...) + * + * yyyymmddN + * */ +#ifdef PGXC +#define CATALOG_VERSION_NO 201611171 +#else +#define CATALOG_VERSION_NO 201611171 +#endif + +#define NAILED_IN_CATALOG_NUM 8 +#define CATALOG_NUM 91 + +#endif diff -uprN postgresql-hll-2.14_old/include/include/catalog/cstore_ctlg.h postgresql-hll-2.14/include/include/catalog/cstore_ctlg.h --- postgresql-hll-2.14_old/include/include/catalog/cstore_ctlg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/cstore_ctlg.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_ctlg.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/catalog/cstore_ctlg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_CTLG_H +#define CSTORE_CTLG_H + +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +extern void AlterCStoreCreateTables(Oid relOid, Datum reloptions, CreateStmt *mainTblStmt); + +extern bool CreateDeltaTable(Relation rel, Datum reloptions, bool isPartition, CreateStmt *mainTblStmt); +extern bool CreateCUDescTable(Relation rel, Datum reloptions, bool isPartition); +extern bool createDeltaTableForPartition(Oid relOid, Oid partOid, Datum reloptions, CreateStmt *mainTblStmt); +extern bool createCUDescTableForPartition(Oid relOid, Oid partOid, Datum reloptions); +extern Datum AddInternalOption(Datum reloptions, int mask); +extern Datum AddOrientationOption(Datum relOptions, bool isColStore); + + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/catalog/dependency.h postgresql-hll-2.14/include/include/catalog/dependency.h --- postgresql-hll-2.14_old/include/include/catalog/dependency.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/dependency.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,368 @@ +/* ------------------------------------------------------------------------- + * + * dependency.h + * Routines to support inter-object dependencies. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/dependency.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEPENDENCY_H +#define DEPENDENCY_H + +#include "catalog/objectaddress.h" +#include "catalog/dfsstore_ctlg.h" +#include "catalog/pg_directory.h" + + +/* + * Precise semantics of a dependency relationship are specified by the + * DependencyType code (which is stored in a "char" field in pg_depend, + * so we assign ASCII-code values to the enumeration members). + * + * In all cases, a dependency relationship indicates that the referenced + * object may not be dropped without also dropping the dependent object. + * However, there are several subflavors: + * + * DEPENDENCY_NORMAL ('n'): normal relationship between separately-created + * objects. The dependent object may be dropped without affecting the + * referenced object. The referenced object may only be dropped by + * specifying CASCADE, in which case the dependent object is dropped too. + * Example: a table column has a normal dependency on its datatype. + * + * DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately + * from the referenced object, and should be automatically dropped + * (regardless of RESTRICT or CASCADE mode) if the referenced object + * is dropped. + * Example: a named constraint on a table is made auto-dependent on + * the table, so that it will go away if the table is dropped. + * + * DEPENDENCY_INTERNAL ('i'): the dependent object was created as part + * of creation of the referenced object, and is really just a part of + * its internal implementation. A DROP of the dependent object will be + * disallowed outright (we'll tell the user to issue a DROP against the + * referenced object, instead). A DROP of the referenced object will be + * propagated through to drop the dependent object whether CASCADE is + * specified or not. + * Example: a trigger that's created to enforce a foreign-key constraint + * is made internally dependent on the constraint's pg_constraint entry. + * + * DEPENDENCY_EXTENSION ('e'): the dependent object is a member of the + * extension that is the referenced object. The dependent object can be + * dropped only via DROP EXTENSION on the referenced object. Functionally + * this dependency type acts the same as an internal dependency, but it's + * kept separate for clarity and to simplify pg_dump. + * + * DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry + * is a signal that the system itself depends on the referenced object, + * and so that object must never be deleted. Entries of this type are + * created only during initdb. The fields for the dependent object + * contain zeroes. + * + * Other dependency flavors may be needed in future. + */ + +typedef enum DependencyType { + DEPENDENCY_NORMAL = 'n', + DEPENDENCY_AUTO = 'a', + DEPENDENCY_INTERNAL = 'i', + DEPENDENCY_EXTENSION = 'e', + DEPENDENCY_PIN = 'p' +} DependencyType; + +/* + * Deletion processing requires additional state for each ObjectAddress that + * it's planning to delete. For simplicity and code-sharing we make the + * ObjectAddresses code support arrays with or without this extra state. + */ +typedef struct { + int flags; /* bitmask, see bit definitions below */ + ObjectAddress dependee; /* object whose deletion forced this one */ +} ObjectAddressExtra; + +/* expansible list of ObjectAddresses */ +struct ObjectAddresses { + ObjectAddress *refs; /* => palloc'd array */ + ObjectAddressExtra *extras; /* => palloc'd array, or NULL if not used */ + int numrefs; /* current number of references */ + int maxrefs; /* current size of palloc'd array(s) */ +}; + +/* typedef ObjectAddresses appears in dependency.h */ + +/* threaded list of ObjectAddresses, for recursion detection */ +typedef struct ObjectAddressStack { + const ObjectAddress* object; /* object being visited */ + int flags; /* its current flag bits */ + struct ObjectAddressStack* next; /* next outer stack level */ +} ObjectAddressStack; + +/* for find_expr_references_walker */ +typedef struct { + ObjectAddresses* addrs; /* addresses being accumulated */ + List* rtables; /* list of rangetables to resolve Vars */ +} find_expr_references_context; + +/* + * There is also a SharedDependencyType enum type that determines the exact + * semantics of an entry in pg_shdepend. Just like regular dependency entries, + * any pg_shdepend entry means that the referenced object cannot be dropped + * unless the dependent object is dropped at the same time. There are some + * additional rules however: + * + * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object -- + * rather, the referenced object is an essential part of the system. This + * applies to the initdb-created superuser. Entries of this type are only + * created by initdb; objects in this category don't need further pg_shdepend + * entries if more objects come to depend on them. + * + * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is + * the role owning the dependent object. The referenced object must be + * a pg_authid entry. + * + * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is + * a role mentioned in the ACL field of the dependent object. The referenced + * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not + * created for the owner of an object; hence two objects may be linked by + * one or the other, but not both, of these dependency types.) + * + * (d) a SHARED_DEPENDENCY_RLSPOLICY entry means that the referenced object + * is the role mentioned in a policy object. The referenced object must be a + * pg_authid entry. + * + * (m) a SHARED_DEPENDENCY_MOT_TABLE entry means that the referenced object + * is the database holding FDW table. The dependent object must be a FDW table entry. + * + * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal + * routines, and is not valid in the catalog itself. + */ +typedef enum SharedDependencyType { + SHARED_DEPENDENCY_PIN = 'p', + SHARED_DEPENDENCY_OWNER = 'o', + SHARED_DEPENDENCY_ACL = 'a', + SHARED_DEPENDENCY_RLSPOLICY = 'r', + SHARED_DEPENDENCY_MOT_TABLE = 'm', + SHARED_DEPENDENCY_INVALID = 0 +} SharedDependencyType; + +/* expansible list of ObjectAddresses (private in dependency.c) */ +typedef struct ObjectAddresses ObjectAddresses; + +/* + * This enum covers all system catalogs whose OIDs can appear in + * pg_depend.classId or pg_shdepend.classId. + */ +typedef enum ObjectClass { + OCLASS_CLASS, /* pg_class */ + OCLASS_PROC, /* pg_proc */ + OCLASS_TYPE, /* pg_type */ + OCLASS_CAST, /* pg_cast */ + OCLASS_COLLATION, /* pg_collation */ + OCLASS_CONSTRAINT, /* pg_constraint */ + OCLASS_CONVERSION, /* pg_conversion */ + OCLASS_DEFAULT, /* pg_attrdef */ + OCLASS_LANGUAGE, /* pg_language */ + OCLASS_LARGEOBJECT, /* pg_largeobject */ + OCLASS_OPERATOR, /* pg_operator */ + OCLASS_OPCLASS, /* pg_opclass */ + OCLASS_OPFAMILY, /* pg_opfamily */ + OCLASS_AMOP, /* pg_amop */ + OCLASS_AMPROC, /* pg_amproc */ + OCLASS_REWRITE, /* pg_rewrite */ + OCLASS_TRIGGER, /* pg_trigger */ + OCLASS_SCHEMA, /* pg_namespace */ + OCLASS_TSPARSER, /* pg_ts_parser */ + OCLASS_TSDICT, /* pg_ts_dict */ + OCLASS_TSTEMPLATE, /* pg_ts_template */ + OCLASS_TSCONFIG, /* pg_ts_config */ + OCLASS_ROLE, /* pg_authid */ + OCLASS_DATABASE, /* pg_database */ + OCLASS_TBLSPACE, /* pg_tablespace */ + OCLASS_FDW, /* pg_foreign_data_wrapper */ + OCLASS_FOREIGN_SERVER, /* pg_foreign_server */ + OCLASS_USER_MAPPING, /* pg_user_mapping */ + OCLASS_SYNONYM, /* pg_synonym */ +#ifdef PGXC + OCLASS_PGXC_CLASS, /* pgxc_class */ + OCLASS_PGXC_NODE, /* pgxc_node */ + OCLASS_PGXC_GROUP, /* pgxc_group */ +#endif + OCLASS_GLOBAL_SETTING, /* global setting */ + OCLASS_COLUMN_SETTING, /* column setting */ + OCLASS_CL_CACHED_COLUMN, /* client logic cached column */ + OCLASS_GLOBAL_SETTING_ARGS, /* global setting args */ + OCLASS_COLUMN_SETTING_ARGS, /* column setting args */ + OCLASS_DEFACL, /* pg_default_acl */ + OCLASS_EXTENSION, /* pg_extension */ + OCLASS_DATA_SOURCE, /* data source */ + OCLASS_DIRECTORY, /* pg_directory */ + OCLASS_PG_JOB, /* pg_job */ + OCLASS_RLSPOLICY, /* pg_rlspolicy */ + MAX_OCLASS /* MUST BE LAST */ +} ObjectClass; + + +/* in dependency.c */ + +#define PERFORM_DELETION_INTERNAL 0x0001 +#define PERFORM_DELETION_CONCURRENTLY 0x0002 + +/* ObjectAddressExtra flag bits */ +#define DEPFLAG_ORIGINAL 0x0001 /* an original deletion target */ +#define DEPFLAG_NORMAL 0x0002 /* reached via normal dependency */ +#define DEPFLAG_AUTO 0x0004 /* reached via auto dependency */ +#define DEPFLAG_INTERNAL 0x0008 /* reached via internal dependency */ +#define DEPFLAG_EXTENSION 0x0010 /* reached via extension dependency */ +#define DEPFLAG_REVERSE 0x0020 /* reverse internal/extension link */ + + +extern void performDeletion(const ObjectAddress *object, + DropBehavior behavior, + int flags); + +extern void performMultipleDeletions(const ObjectAddresses *objects, + DropBehavior behavior, + uint32 flags); + +extern void deleteWhatDependsOn(const ObjectAddress *object, + bool showNotices); + +extern void recordDependencyOnExpr(const ObjectAddress *depender, + Node *expr, + List *rtable, + DependencyType behavior); + +extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, + Node *expr, + Oid relId, + DependencyType behavior, + DependencyType self_behavior); + +extern ObjectClass getObjectClass(const ObjectAddress *object); + +extern char *getObjectDescription(const ObjectAddress *object); +extern char *getObjectDescriptionOids(Oid classid, Oid objid); + +extern ObjectAddresses *new_object_addresses(const int maxRefs = 32); + +extern void add_exact_object_address(const ObjectAddress *object, + ObjectAddresses *addrs); + +extern bool object_address_present(const ObjectAddress *object, + const ObjectAddresses *addrs); + +extern void record_object_address_dependencies(const ObjectAddress *depender, + ObjectAddresses *referenced, + DependencyType behavior); + +extern void free_object_addresses(ObjectAddresses *addrs); + +/* in pg_depend.c */ +extern void recordDependencyOn(const ObjectAddress *depender, + const ObjectAddress *referenced, + DependencyType behavior); + +extern void recordMultipleDependencies(const ObjectAddress *depender, + const ObjectAddress *referenced, + int nreferenced, + DependencyType behavior); + +extern void recordDependencyOnCurrentExtension(const ObjectAddress *object, + bool isReplace); + +extern void recordPinnedDependency(const ObjectAddress *object); + +extern long deleteDependencyRecordsFor(Oid classId, + Oid objectId, + bool skipExtensionDeps); + +extern long deleteDependencyRecordsForClass(Oid classId, + Oid objectId, + Oid refclassId, + char deptype); + +extern long changeDependencyFor(Oid classId, + Oid objectId, + Oid refClassId, + Oid oldRefObjectId, + Oid newRefObjectId); + +extern Oid getExtensionOfObject(Oid classId, Oid objectId); + +extern bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId); + +extern void markSequenceUnowned(Oid seqId); + +extern List *getOwnedSequences(Oid relid, List *attrList = NULL); + +extern Oid get_constraint_index(Oid constraintId); + +extern Oid get_index_constraint(Oid indexId); + +/* in pg_shdepend.c */ +extern void recordSharedDependencyOn(ObjectAddress *depender, + ObjectAddress *referenced, + SharedDependencyType deptype, + const char *objfile = NULL); + +extern void deleteSharedDependencyRecordsFor(Oid classId, + Oid objectId, + int32 objectSubId); + +extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner, const char *objfile = NULL); +#ifdef ENABLE_MOT +extern void recordDependencyOnDatabase(Oid classId, Oid objectId, Oid serverId, Oid owner, const char *objfile = NULL); +#endif + +extern void changeDependencyOnOwner(Oid classId, + Oid objectId, + Oid newOwnerId); + +extern void updateAclDependencies(Oid classId, + Oid objectId, + int32 objectSubId, + Oid ownerId, + int noldmembers, + Oid *oldmembers, + int nnewmembers, + Oid *newmembers); + +extern bool checkSharedDependencies(Oid classId, + Oid objectId, + char **detail_msg, + char **detail_log_msg); + +extern void shdepLockAndCheckObject(Oid classId, Oid objectId); + +extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId); + +extern void dropDatabaseDependencies(Oid databaseId); + +extern void shdepDropOwned(List *relids, DropBehavior behavior); + +extern void shdepReassignOwned(List *relids, Oid newrole); + +extern bool TSConfigurationHasDependentObjects(Oid tsconfoid); + +extern void recordDependencyOnRespool(Oid classId, Oid objectId, Oid owner); + +extern bool CheckDependencyOnRespool(Oid classId, Oid objectId, List **foundlist, bool full); +extern void changeDependencyOnRespool(Oid classId, Oid objectId, Oid newOwnerId); +extern void prepareDatabaseCFunLibrary(Oid databaseId); + +extern void deleteDictionaryTSFile(Oid dictId); +extern void deleteDatabaseTSFile(Oid databaseId); +extern void changeDependencyOnObjfile(Oid objectId, Oid refobjId, const char *newObjfile); + +#ifdef ENABLE_MULTIPLE_NODES +namespace Tsdb { +extern void performTsCudescDeletion(List* cudesc_oids); +} +#endif /* ENABLE_MULTIPLE_NODES */ +#endif /* DEPENDENCY_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/dfsstore_ctlg.h postgresql-hll-2.14/include/include/catalog/dfsstore_ctlg.h --- postgresql-hll-2.14_old/include/include/catalog/dfsstore_ctlg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/dfsstore_ctlg.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfsstore_ctlg.h + * routines to support HdfsStore + * + * + * IDENTIFICATION + * src/include/catalog/dfsstore_ctlg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFSSTORE_CTLG_H +#define DFSSTORE_CTLG_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/objectaddress.h" +#include "lib/stringinfo.h" +#include "utils/relcache.h" +#include "storage/block.h" +#include "storage/dfs/dfs_connector.h" + + +/* + * DropDfsTblInfo holds the some information when drop + * a Dfs table. + */ +typedef struct DropDfsTblInfo { + DfsSrvOptions *srvOptions; + StringInfo dfsTblPath; + Oid tblSpaceOid; +}DropDfsTblInfo; + + +void createDfsDescTable(Relation rel, Datum reloptions); +StringInfo getDfsStorePath(Relation rel); +extern Oid getDfsDescTblOid(Oid mainTblOid); +extern Oid getDfsDescIndexOid(Oid mainTblOid); +extern List* getDataFiles(Oid tbloid); +extern void InsertDeletedFilesForTransaction(Relation dataDestRelation); +extern int64 getDFSRelSize(Relation rel); +extern StringInfo getHDFSTblSpcStorePath(Oid tblSpcOid); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/catalog/duplicate_oids postgresql-hll-2.14/include/include/catalog/duplicate_oids --- postgresql-hll-2.14_old/include/include/catalog/duplicate_oids 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/duplicate_oids 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,30 @@ +#!/bin/sh +# +# duplicate_oids +# +# src/include/catalog/duplicate_oids +# +# finds manually-assigned oids that are duplicated in the system tables. +# +# run this script in src/include/catalog. +# + +# note: we exclude BKI_BOOTSTRAP relations since they are expected to have +# matching DATA lines in pg_class.h and pg_type.h + +cat pgxc_*.h pg_*.h toasting.h indexing.h | \ +egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \ +sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \ +tr ',' '\n' | \ +sort -n | \ +uniq -d | \ +grep '.' + +# nonzero exit code if lines were produced +[ $? -eq 1 ] +exit diff -uprN postgresql-hll-2.14_old/include/include/catalog/genbki.h postgresql-hll-2.14/include/include/catalog/genbki.h --- postgresql-hll-2.14_old/include/include/catalog/genbki.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/genbki.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,52 @@ +/* ------------------------------------------------------------------------- + * + * genbki.h + * Required include file for all POSTGRES catalog header files + * + * genbki.h defines CATALOG(), DATA(), BKI_BOOTSTRAP and related macros + * so that the catalog header files can be read by the C compiler. + * (These same words are recognized by genbki.pl to build the BKI + * bootstrap file from these header files.) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/genbki.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GENBKI_H +#define GENBKI_H + +/* Introduces a catalog's structure definition */ +#define CATALOG(name,oid) typedef struct CppConcat(FormData_,name) + +/* + * This is never defined; it's here only for documentation. + * + * Variable-length catalog fields (except possibly the first not nullable one) + * should not be visible in C structures, so they are made invisible by #ifdefs + * of an undefined symbol. See also MARKNOTNULL in bootstrap.c for how this is + * handled. + */ +#undef CATALOG_VARLEN + +/* Options that may appear after CATALOG (on the same line) */ +#define BKI_BOOTSTRAP +#define BKI_SHARED_RELATION +#define BKI_WITHOUT_OIDS +#define BKI_ROWTYPE_OID(oid) +#define BKI_SCHEMA_MACRO + +/* Declarations that provide the initial content of a catalog */ +/* In C, these need to expand into some harmless, repeatable declaration */ +#define DATA(x) extern int no_such_variable +#define DESCR(x) extern int no_such_variable +#define SHDESCR(x) extern int no_such_variable + +/* PHONY type definitions for use in catalog structure definitions only */ +typedef int aclitem; +typedef int pg_node_tree; + +#endif /* GENBKI_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_asp.h postgresql-hll-2.14/include/include/catalog/gs_asp.h --- postgresql-hll-2.14_old/include/include/catalog/gs_asp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_asp.h 2020-12-12 17:06:43.148346761 +0800 @@ -0,0 +1,120 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_asp.h + * + * IDENTIFICATION + * src/include/catalog/gs_asp.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PG_ASP_H +#define PG_ASP_H + +#include "postgres.h" +#include "utils/inet.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" +#include "utils/date.h" + +#define timestamptz Datum +#define int8 int64 + +/*------------------------------------------------------------------------- + * gs_asp definition. cpp turns this into + * typedef struct GsAspRelation_Rowtype_Id + *------------------------------------------------------------------------- + * */ +#define GsAspRelationId 9534 +#define GsAspRelation_Rowtype_Id 3465 + +CATALOG(gs_asp,9534) BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(3465) BKI_SCHEMA_MACRO +{ + int8 sampleid; + timestamptz sample_time; + bool need_flush_sample; + Oid databaseid; + int8 thread_id; + int8 sessionid; + timestamptz start_time; +#ifdef CATALOG_VARLEN /* Null value constrain */ + text event; + int4 lwtid; + int8 psessionid; + int4 tlevel; + int4 smpid; + Oid userid; + text application_name; + inet client_addr; + text client_hostname; + int4 client_port; + int8 query_id; + int8 unique_query_id; + Oid user_id; + int4 cn_id; + text unique_query; + text locktag; + text lockmode; + int8 block_sessionid; + text wait_status; +#endif +} FormData_gs_asp; + +#undef timestamp +#undef int8 + +/*------------------------------------------------------------------------- + * FormData_gs_asp corresponds to a pointer to a tuple with + * the format of gs_asp relation. + *------------------------------------------------------------------------- + * */ +typedef FormData_gs_asp* Form_gs_asp; + +/*------------------------------------------------------------------------- + * compiler constants for gs_asp + *------------------------------------------------------------------------- + */ +#define Natts_gs_asp 26 +#define Anum_gs_asp_sample_id 1 +#define Anum_gs_asp_sample_time 2 +#define Anum_gs_asp_need_flush_sample 3 +#define Anum_gs_asp_databaseid 4 +#define Anum_gs_asp_tid 5 +#define Anum_gs_asp_sessionid 6 +#define Anum_gs_asp_start_time 7 +#define Anum_gs_asp_event 8 +#define Anum_gs_asp_lwtid 9 +#define Anum_gs_asp_psessionid 10 +#define Anum_gs_asp_tlevel 11 +#define Anum_gs_asp_smpid 12 +#define Anum_gs_asp_useid 13 +#define Anum_gs_asp_application_name 14 +#define Anum_gs_asp_client_addr 15 +#define Anum_gs_asp_client_hostname 16 +#define Anum_gs_asp_client_port 17 +#define Anum_gs_asp_query_id 18 +#define Anum_gs_asp_unique_query_id 19 +#define Anum_gs_asp_user_id 20 +#define Anum_gs_asp_cn_id 21 +#define Anum_gs_asp_unique_query 22 +#define Anum_gs_asp_locktag 23 +#define Anum_gs_asp_lockmode 24 +#define Anum_gs_asp_block_sessionid 25 +#define Anum_gs_asp_wait_status 26 + +#endif /* GS_ASP */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_acc.h postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_acc.h --- postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_acc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_acc.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_acc.h + * Definition about access catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_acc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_ACC_H +#define GS_AUDITING_POLICY_ACC_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyAccessRelationId 9520 +#define GsAuditingPolicyAccessRelationId_Rowtype_Id 9523 + +CATALOG(gs_auditing_policy_access,9520) BKI_SCHEMA_MACRO +{ + NameData accesstype; + NameData labelname; + Oid policyoid; + timestamp modifydate; +} FormData_gs_auditing_policy_access; + +typedef FormData_gs_auditing_policy_access *Form_gs_auditing_policy_access; + +#define Natts_gs_auditing_policy_acc 4 + +#define Anum_gs_auditing_policy_acc_type 1 +#define Anum_gs_auditing_policy_acc_label_name 2 +#define Anum_gs_auditing_policy_acc_policy_oid 3 +#define Anum_gs_auditing_policy_acc_modify_date 4 + +#endif /* GS_AUDITING_POLICY_ACC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_filter.h postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_filter.h --- postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_filter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_filter.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Definition about filter catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_filter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_FILTER_H +#define GS_AUDITING_POLICY_FILTER_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyFiltersRelationId 9540 +#define GsAuditingPolicyFiltersRelationId_Rowtype_Id 9543 + +CATALOG(gs_auditing_policy_filters,9540) BKI_SCHEMA_MACRO +{ + NameData filtertype; + NameData labelname; + Oid policyoid; + timestamp modifydate; + text logicaloperator; +} FormData_gs_auditing_policy_filters; + +typedef FormData_gs_auditing_policy_filters *Form_gs_auditing_policy_filters; + +#define Natts_gs_auditing_policy_filters 5 + +#define Anum_gs_auditing_policy_fltr_filter_type 1 +#define Anum_gs_auditing_policy_fltr_label_name 2 +#define Anum_gs_auditing_policy_fltr_policy_oid 3 +#define Anum_gs_auditing_policy_fltr_modify_date 4 +#define Anum_gs_auditing_policy_fltr_logical_operator 5 + +#endif /* GS_AUDITING_POLICY_FILTER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy.h postgresql-hll-2.14/include/include/catalog/gs_auditing_policy.h --- postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_auditing_policy.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy.h + * Definition of gs_auditing_policy catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_H +#define GS_AUDITING_POLICY_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyRelationId 9510 +#define GsAuditingPolicyRelationId_Rowtype_Id 9513 + +CATALOG(gs_auditing_policy,9510) BKI_SCHEMA_MACRO +{ + NameData polname; + NameData polcomments; + timestamp modifydate; + bool polenabled; +} FormData_gs_auditing_policy; + +typedef FormData_gs_auditing_policy *Form_gs_auditing_policy; + +#define Natts_gs_auditing_policy 4 + +#define Anum_gs_auditing_policy_pol_name 1 +#define Anum_gs_auditing_policy_pol_comments 2 +#define Anum_gs_auditing_policy_pol_modify_date 3 +#define Anum_gs_auditing_policy_pol_enabled 4 + + +#endif /* GS_AUDITING_POLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_priv.h postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_priv.h --- postgresql-hll-2.14_old/include/include/catalog/gs_auditing_policy_priv.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_auditing_policy_priv.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Definition about privileges(DML) catalog in auditing policy + * + * + * IDENTIFICATION + * src/include/catalog/gs_auditing_policy_priv.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_AUDITING_POLICY_PRIV_H +#define GS_AUDITING_POLICY_PRIV_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsAuditingPolicyPrivilegesRelationId 9530 +#define GsAuditingPolicyPrivilegesRelationId_Rowtype_Id 9533 + +CATALOG(gs_auditing_policy_privileges,9530) BKI_SCHEMA_MACRO +{ + NameData privilegetype; + NameData labelname; + Oid policyoid; + timestamp modifydate; +} FormData_gs_auditing_policy_privileges; + +typedef FormData_gs_auditing_policy_privileges *Form_gs_auditing_policy_privileges; + +#define Natts_gs_auditing_policy_priv 4 + +#define Anum_gs_auditing_policy_priv_type 1 +#define Anum_gs_auditing_policy_priv_label_name 2 +#define Anum_gs_auditing_policy_priv_policy_oid 3 +#define Anum_gs_auditing_policy_priv_modify_date 4 + +#endif /* GS_AUDITING_POLICY_PRIV_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_client_global_keys_args.h postgresql-hll-2.14/include/include/catalog/gs_client_global_keys_args.h --- postgresql-hll-2.14_old/include/include/catalog/gs_client_global_keys_args.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_client_global_keys_args.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_client_global_keys_args.h + * + * IDENTIFICATION + * src/include/catalog/gs_client_global_keys_args.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_CLIENT_GLOBAL_KEYS_ARGS_H +#define GS_CLIENT_GLOBAL_KEYS_ARGS_H +#include "catalog/genbki.h" + +#define ClientLogicGlobalSettingsArgsId 9730 +#define ClientLogicGlobalSettingsArgsId_Rowtype_Id 9730 +CATALOG(gs_client_global_keys_args,9730) BKI_SCHEMA_MACRO +{ + /* ID of the master client key that was used to encrypt the columd encryption key. (foreign key) */ + Oid global_key_id; + NameData function_name; + NameData key; + bytea value; +} FormData_gs_client_global_keys_args; + +typedef FormData_gs_client_global_keys_args *Form_gs_client_global_keys_args; + +#define Natts_gs_client_global_keys_args 4 +#define Anum_gs_client_global_keys_args_global_key_id 1 +#define Anum_gs_client_global_keys_args_function_name 2 +#define Anum_gs_client_global_keys_args_key 3 +#define Anum_gs_client_global_keys_args_value 4 + +#endif /* GS_CLIENT_GLOBAL_KEYS_ARGS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_client_global_keys.h postgresql-hll-2.14/include/include/catalog/gs_client_global_keys.h --- postgresql-hll-2.14_old/include/include/catalog/gs_client_global_keys.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_client_global_keys.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_client_global_keys.h + * + * IDENTIFICATION + * src/include/catalog/gs_client_global_keys.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_CLIENT_GLOBAL_KEYS_H +#define GS_CLIENT_GLOBAL_KEYS_H + +#include "catalog/genbki.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicGlobalSettingsId 9710 +#define ClientLogicGlobalSettingsId_Rowtype_Id 9713 +CATALOG(gs_client_global_keys,9710) BKI_SCHEMA_MACRO +{ + NameData global_key_name; /* An alias for client encrypyion key */ + Oid key_namespace; + Oid key_owner; +#ifdef CATALOG_VARLEN + aclitem key_acl[1]; +#endif + timestamp create_date; +} FormData_gs_client_global_keys; + +typedef FormData_gs_client_global_keys *Form_gs_client_global_keys; + +#define Natts_gs_client_global_keys 5 +#define Anum_gs_client_global_keys_global_key_name 1 +#define Anum_gs_client_global_keys_key_namespace 2 +#define Anum_gs_client_global_keys_key_owner 3 +#define Anum_gs_client_global_keys_key_acl 4 +#define Anum_gs_client_global_keys_create_date 5 + +#endif /* GS_CLIENT_GLOBAL_KEYS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_column_keys_args.h postgresql-hll-2.14/include/include/catalog/gs_column_keys_args.h --- postgresql-hll-2.14_old/include/include/catalog/gs_column_keys_args.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_column_keys_args.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_column_keys_args.h + * + * IDENTIFICATION + * src/include/catalog/gs_column_keys_args.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_COLUMN_KEYS_ARGS_H +#define GS_COLUMN_KEYS_ARGS_H + + +#include "catalog/genbki.h" + +#define ClientLogicColumnSettingsArgsId 9740 +#define ClientLogicColumnSettingsArgsId_Rowtype_Id 9743 +CATALOG(gs_column_keys_args,9740) BKI_SCHEMA_MACRO +{ + Oid column_key_id; + NameData function_name; + NameData key; + bytea value; +} FormData_gs_column_keys_args; + +typedef FormData_gs_column_keys_args *Form_gs_column_keys_args; + +#define Natts_gs_column_keys_args 4 +#define Anum_gs_column_keys_args_column_key_id 1 +#define Anum_gs_column_keys_args_function_name 2 +#define Anum_gs_column_keys_args_key 3 +#define Anum_gs_column_keys_args_value 4 + +#endif /* GS_COLUMN_KEYS_ARGS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_column_keys.h postgresql-hll-2.14/include/include/catalog/gs_column_keys.h --- postgresql-hll-2.14_old/include/include/catalog/gs_column_keys.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_column_keys.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_column_keys.h + * + * IDENTIFICATION + * src/include/catalog/gs_column_keys.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_COLUMN_KEYS_H +#define GS_COLUMN_KEYS_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" + + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicColumnSettingsId 9720 +#define ClientLogicColumnSettingsId_Rowtype_Id 9724 + +CATALOG(gs_column_keys,9720) BKI_SCHEMA_MACRO +{ + NameData column_key_name; /* An alias for column encrypyion key */ + Oid column_key_distributed_id; /* id created from hasing fqdn */ + /* ID of the client encryption key that was used to encrypt the columd encryption key. (foreign key) */ + Oid global_key_id; + Oid key_namespace; + Oid key_owner; + timestamp create_date; +#ifdef CATALOG_VARLEN + aclitem key_acl[1]; /* access permissions */ +#endif +} FormData_gs_column_keys; + +typedef FormData_gs_column_keys *Form_gs_column_keys; + +#define Natts_gs_column_keys 7 + +#define Anum_gs_column_keys_column_key_name 1 +#define Anum_gs_column_keys_column_key_distributed_id 2 +#define Anum_gs_column_keys_global_key_id 3 +#define Anum_gs_column_keys_key_namespace 4 +#define Anum_gs_column_keys_key_owner 5 +#define Anum_gs_column_keys_create_date 6 +#define Anum_gs_column_keys_key_acl 7 + +#endif /* GS_COLUMN_KEYS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_encrypted_columns.h postgresql-hll-2.14/include/include/catalog/gs_encrypted_columns.h --- postgresql-hll-2.14_old/include/include/catalog/gs_encrypted_columns.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_encrypted_columns.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_encrypted_columns.h + * + * IDENTIFICATION + * src/include/catalog/gs_encrypted_columns.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_ENCRYPTED_COLUMNS_H +#define GS_ENCRYPTED_COLUMNS_H + +#include "catalog/genbki.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define ClientLogicCachedColumnsId 9700 +#define ClientLogicCachedColumnsId_Rowtype_Id 9703 +CATALOG(gs_encrypted_columns,9700) BKI_SCHEMA_MACRO +{ + Oid rel_id; + NameData column_name; + Oid column_key_id; + int1 encryption_type; + Oid data_type_original_oid; + int4 data_type_original_mod; + timestamp create_date; +} FormData_gs_encrypted_columns; + +typedef FormData_gs_encrypted_columns *Form_gs_encrypted_columns; + +#define Natts_gs_encrypted_columns 7 + +#define Anum_gs_encrypted_columns_rel_id 1 +#define Anum_gs_encrypted_columns_column_name 2 +#define Anum_gs_encrypted_columns_column_key_id 3 +#define Anum_gs_sec_encrypted_columns_encryption_type 4 +#define Anum_gs_encrypted_columns_data_type_original_oid 5 +#define Anum_gs_encrypted_columns_data_type_original_mod 6 +#define Anum_gs_encrypted_columns_create_date 7 + +#endif /* GS_ENCRYPTED_COLUMNS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_global_config.h postgresql-hll-2.14/include/include/catalog/gs_global_config.h --- postgresql-hll-2.14_old/include/include/catalog/gs_global_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_global_config.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * gs_global_config.h + * definition of the system global configuration parameters + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * IDENTIFICATION + * src/include/catalog/gs_global_config.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + *------------------------------------------------------------------------- + */ +#ifndef GS_GLOBAL_CONFIG_H +#define GS_GLOBAL_CONFIG_H + +#include "catalog/genbki.h" + +#define GsGlobalConfigRelationId 9080 +#define GsGlobalConfigRelationId_Rowtype_Id 9081 + +CATALOG(gs_global_config,9080) BKI_SHARED_RELATION BKI_SCHEMA_MACRO BKI_WITHOUT_OIDS +{ + NameData name; /* Configure name */ + +#ifdef CATALOG_VARLEN + text value; /* Configure value */ +#endif +} FormData_gs_global_config; + +typedef FormData_gs_global_config *Form_gs_global_config; + +#define Natts_gs_global_config 2 + +#define Anum_gs_global_config_name 1 +#define Anum_gs_global_config_value 2 + +#endif /* GS_GLOBAL_CONFIG_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy_actions.h postgresql-hll-2.14/include/include/catalog/gs_masking_policy_actions.h --- postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy_actions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_masking_policy_actions.h 2020-12-12 17:06:43.149346774 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy_actions.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy_actions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_ACTIONS_H +#define GS_MASKING_POLICY_ACTIONS_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyActionsId 9650 +#define GsMaskingPolicyActionsId_Rowtype_Id 9654 + +CATALOG(gs_masking_policy_actions,9650) BKI_SCHEMA_MACRO +{ + NameData actiontype; + NameData actparams; + NameData actlabelname; + Oid policyoid; + timestamp actmodifydate; +} FormData_gs_masking_policy_actions; + +typedef FormData_gs_masking_policy_actions *Form_gs_masking_policy_actions; + +#define Natts_gs_masking_policy_actions 5 + +#define Anum_gs_masking_policy_act_action_type 1 +#define Anum_gs_masking_policy_act_action_params 2 +#define Anum_gs_masking_policy_act_label_name 3 +#define Anum_gs_masking_policy_act_policy_oid 4 +#define Anum_gs_masking_policy_act_modify_date 5 + + +#endif /* GS_MASKING_POLICY_ACTIONS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy_filters.h postgresql-hll-2.14/include/include/catalog/gs_masking_policy_filters.h --- postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy_filters.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_masking_policy_filters.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy_filter.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy_filter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_FILTER_H +#define GS_MASKING_POLICY_FILTER_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyFiltersId 9640 +#define GsMaskingPolicyFiltersId_Rowtype_Id 9643 + +CATALOG(gs_masking_policy_filters,9640) BKI_SCHEMA_MACRO +{ + NameData filtertype; + NameData filterlabelname; + Oid policyoid; + timestamp modifydate; +#ifdef CATALOG_VARLEN + text logicaloperator; +#endif +} FormData_gs_masking_policy_filters; + +typedef FormData_gs_masking_policy_filters *Form_gs_masking_policy_filters; + +#define Natts_gs_masking_policy_filters 5 + +#define Anum_gs_masking_policy_fltr_filter_type 1 +#define Anum_gs_masking_policy_fltr_label_name 2 +#define Anum_gs_masking_policy_fltr_policy_oid 3 +#define Anum_gs_masking_policy_fltr_modify_date 4 +#define Anum_gs_masking_policy_fltr_logical_operator 5 + + +#endif /* GS_MASKING_POLICY_FILTER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy.h postgresql-hll-2.14/include/include/catalog/gs_masking_policy.h --- postgresql-hll-2.14_old/include/include/catalog/gs_masking_policy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_masking_policy.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_masking_policy.h + * + * IDENTIFICATION + * src/include/catalog/gs_masking_policy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_MASKING_POLICY_H +#define GS_MASKING_POLICY_H + +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsMaskingPolicyRelationId 9610 +#define GsMaskingPolicyRelationId_Rowtype_Id 9613 + +CATALOG(gs_masking_policy,9610) BKI_SCHEMA_MACRO +{ + NameData polname; + NameData polcomments; + timestamp modifydate; + bool polenabled; +} FormData_gs_masking_policy; + +typedef FormData_gs_masking_policy *Form_gs_masking_policy; + +#define Natts_gs_masking_policy 4 + +#define Anum_gs_masking_policy_pol_name 1 +#define Anum_gs_masking_policy_pol_comments 2 +#define Anum_gs_masking_policy_pol_modify_date 3 +#define Anum_gs_masking_policy_pol_enabled 4 + + +#endif /* GS_MASKING_POLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_matview_dependency.h postgresql-hll-2.14/include/include/catalog/gs_matview_dependency.h --- postgresql-hll-2.14_old/include/include/catalog/gs_matview_dependency.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_matview_dependency.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * --------------------------------------------------------------------------------------- + * + * gs_matview_dependency.h + * Definition about catalog of matviews dependency + * + * + * IDENTIFICATION + * src/include/catalog/gs_matview_dependency.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_MATVIEW_DEPENDENCY_H +#define GS_MATVIEW_DEPENDENCY_H + +#include "catalog/genbki.h" +#include "c.h" + +#define MatviewDependencyId 9985 +#define MatviewDependencyId_Rowtype_Id 9987 + +CATALOG(gs_matview_dependency,9985) BKI_SCHEMA_MACRO +{ + Oid matviewid; + Oid relid; + Oid mlogid; + int4 mxmin; +} FormData_gs_matview_dependency; + +typedef FormData_gs_matview_dependency *Form_gs_matview_dependency; + +#define Natts_gs_matview_dependency 4 + +#define Anum_gs_matview_dep_matviewid 1 +#define Anum_gs_matview_dep_relid 2 +#define Anum_gs_matview_dep_mlogid 3 +#define Anum_gs_matview_dep_mxmin 4 + + +#endif /* GS_MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_matview.h postgresql-hll-2.14/include/include/catalog/gs_matview.h --- postgresql-hll-2.14_old/include/include/catalog/gs_matview.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_matview.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * --------------------------------------------------------------------------------------- + * + * gs_matview.h + * Definition about catalog of matviews. + * + * + * IDENTIFICATION + * src/include/catalog/gs_matview.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_MATVIEW_H +#define GS_MATVIEW_H + +#include "catalog/genbki.h" +#include "nodes/parsenodes.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define MatviewRelationId 9982 +#define MatviewRelationId_Rowtype_Id 9984 + +typedef enum { + MATVIEW_NOT = 0, /* Not a matview related table */ + MATVIEW_MAP, /* Matviewmap table */ + MATVIEW_LOG /* Mlog table */ +} MvRelationType; + +CATALOG(gs_matview,9982) BKI_SCHEMA_MACRO +{ + Oid matviewid; + Oid mapid; + bool ivm; + bool needrefresh; + timestamp refreshtime; +} FormData_gs_matview; + +typedef FormData_gs_matview *Form_gs_matview; + +#define Natts_gs_matview 5 + +#define Anum_gs_matview_matviewid 1 +#define Anum_gs_matview_mapid 2 +#define Anum_gs_matview_ivm 3 +#define Anum_gs_matview_needrefresh 4 +#define Anum_gs_matview_refreshtime 5 + +extern void create_matview_tuple(Oid matviewOid, Oid mapid, bool isIncremental); +extern void update_matview_tuple(Oid matviewOid, bool needrefresh, Datum curtime); +extern void delete_matview_tuple(Oid matviewOid); + +extern void insert_matviewdep_tuple(Oid matviewOid, Oid relid, Oid mlogid); +extern void delete_matviewdep_tuple(Oid matviewOid); +extern void delete_matdep_table(Oid mlogid); + +extern Datum get_matview_refreshtime(Oid matviewOid, bool *isNUll); +extern Datum get_matview_mapid(Oid matviewOid); +extern bool is_incremental_matview(Oid oid); +extern bool IsMatviewRelationbyOid(Oid relOid, MvRelationType *matviewRelationType); +extern Oid MatviewRelationGetBaseid(Oid relOid, MvRelationType matviewRelationType); +extern Query *get_matview_query(Relation matviewRel); +extern void CheckRefreshMatview(Relation matviewRel); +extern bool CheckPermissionForBasetable(Oid relid); + +#endif /* GS_MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_obsscaninfo.h postgresql-hll-2.14/include/include/catalog/gs_obsscaninfo.h --- postgresql-hll-2.14_old/include/include/catalog/gs_obsscaninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_obsscaninfo.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_obsscaninfo.h + * definition of the system "obsscaninfo" relation (gs_obsscaninfo) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/gs_obsscaninfo.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GS_OBSSCANINFO_H +#define GS_OBSSCANINFO_H + +#include "catalog/genbki.h" + +/* ---------------- + * gs_obsscaninfo definition.cpp turns this into + * typedef struct FormData_gs_obsscaninfo + * ---------------- + */ +#define timestamptz Datum +#define GSObsScanInfoRelationId 5680 +#define GSObsScanInfoRelation_Rowtype_Id 11661 + +CATALOG(gs_obsscaninfo,5680) BKI_SHARED_RELATION BKI_WITHOUT_OIDS +{ + /* These fields form the unique key for the entry: */ + int8 query_id; +#ifdef CATALOG_VARLEN + text user_id; + text table_name; + text file_type; +#endif + timestamptz time_stamp; + float8 actual_time; + int8 file_scanned; + float8 data_size; +#ifdef CATALOG_VARLEN + text billing_info; +#endif +} FormData_gs_obsscaninfo; + +#undef timestamptz + +/* ---------------- + * Form_gs_obsscaninfo corresponds to a pointer to a tuple with + * the format of gs_obsscaninfo relation. + * ---------------- + */ +typedef FormData_gs_obsscaninfo *Form_gs_obsscaninfo; + +/* ---------------- + * compiler constants for gs_obsscaninfo + * ---------------- + */ +#define Natts_gs_obsscaninfo 9 +#define Anum_gs_obsscaninfo_query_id 1 +#define Anum_gs_obsscaninfo_user_id 2 +#define Anum_gs_obsscaninfo_table_name 3 +#define Anum_gs_obsscaninfo_file_type 4 +#define Anum_gs_obsscaninfo_time_stamp 5 +#define Anum_gs_obsscaninfo_actual_time 6 +#define Anum_gs_obsscaninfo_file_scanned 7 +#define Anum_gs_obsscaninfo_data_size 8 +#define Anum_gs_obsscaninfo_billing_info 9 + +#endif /* GS_OBSSCANINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_opt_model.h postgresql-hll-2.14/include/include/catalog/gs_opt_model.h --- postgresql-hll-2.14_old/include/include/catalog/gs_opt_model.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_opt_model.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,100 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_opt_model.h + * + * + * + * IDENTIFICATION + * src/include/catalog/gs_opt_model.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GS_OPT_MODEL_H +#define GS_OPT_MODEL_H + +#include "catalog/genbki.h" + +#define OptModelRelationId 9998 +#define OptModelRelationId_Rowtype_Id 9996 + +CATALOG(gs_opt_model,9998) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* index information */ + NameData template_name; + NameData model_name; /* model's name */ + NameData datname; + /* connection information */ + NameData ip; + int4 port; + /* user-set configuration */ + int4 max_epoch; + float4 learning_rate; + float4 dim_red; + int4 hidden_units; + int4 batch_size; + /* model info, to be filled after training. */ + int4 feature_size; /* size of the feature set */ + bool available; + bool is_training; +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + char label[1]; /* meaning of label: 'S': Startup time + * 'T': Total time + * 'R': Rows + * 'M': Memory */ + int8 max[1]; /* keep tracks of the max values occured for each label */ + float4 acc[1]; /* ratio error accuracy */ + text description; /* description */ +#endif /* CATALOG_VARLEN */ + +} FormData_gs_opt_model; + +typedef FormData_gs_opt_model *Form_gs_opt_model; + +/* ---------------- + * compiler constants for gs_opt_model + * ---------------- + */ +#define Natts_gs_opt_model 17 +#define Anum_gs_opt_model_template_name 1 +#define Anum_gs_opt_model_model_name 2 +#define Anum_gs_opt_model_datname 3 +#define Anum_gs_opt_model_ip 4 +#define Anum_gs_opt_model_port 5 +#define Anum_gs_opt_model_max_epoch 6 +#define Anum_gs_opt_model_learning_rate 7 +#define Anum_gs_opt_model_dim_red 8 +#define Anum_gs_opt_model_hidden_units 9 +#define Anum_gs_opt_model_batch_size 10 +#define Anum_gs_opt_model_feature_size 11 +#define Anum_gs_opt_model_available 12 +#define Anum_gs_opt_model_is_training 13 +#define Anum_gs_opt_model_label 14 +#define Anum_gs_opt_model_max 15 +#define Anum_gs_opt_model_acc 16 +#define Anum_gs_opt_model_description 17 + +#define gs_opt_model_label_length 4 +#define gs_opt_model_label_startup_time 'S' +#define gs_opt_model_label_total_time 'T' +#define gs_opt_model_label_rows 'R' +#define gs_opt_model_label_peak_memory 'M' + +#define LABEL_START_TIME_INDEX 0 +#define LABEL_TOTAL_TIME_INDEX 1 +#define LABEL_ROWS_INDEX 2 +#define LABEL_PEAK_MEMEORY_INDEX 3 + +#endif /* gs_opt_model_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/catalog/gs_policy_label.h postgresql-hll-2.14/include/include/catalog/gs_policy_label.h --- postgresql-hll-2.14_old/include/include/catalog/gs_policy_label.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/gs_policy_label.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_policy_label.h + * + * IDENTIFICATION + * src/include/catalog/gs_policy_label.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_LABEL_H +#define GS_POLICY_LABEL_H + +#include "postgres.h" +#include "catalog/genbki.h" +#include "utils/timestamp.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define GsPolicyLabelRelationId 9500 +#define GsPolicyLabelRelationId_Rowtype_Id 9503 + +CATALOG(gs_policy_label,9500) BKI_SCHEMA_MACRO +{ + NameData labelname; + NameData labeltype; /* resource label */ + Oid fqdnnamespace; /* namespace oid */ + Oid fqdnid; /* relation oid */ + NameData relcolumn; /* column name */ + NameData fqdntype; /* schema, table, column, view etc. */ +} FormData_gs_policy_label; + +typedef FormData_gs_policy_label *Form_gs_policy_label; + +#define Natts_gs_policy_label 6 + +#define Anum_gs_policy_label_labelname 1 +#define Anum_gs_policy_label_labeltype 2 +#define Anum_gs_policy_label_fqdnnamespace 3 +#define Anum_gs_policy_label_fqdnid 4 +#define Anum_gs_policy_label_relcolumn 5 +#define Anum_gs_policy_label_fqdntype 6 + +#endif /* GS_POLICY_LABEL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/catalog/heap.h postgresql-hll-2.14/include/include/catalog/heap.h --- postgresql-hll-2.14_old/include/include/catalog/heap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/heap.h 2020-12-12 17:06:43.150346787 +0800 @@ -0,0 +1,217 @@ +/* ------------------------------------------------------------------------- + * + * heap.h + * prototypes for functions in backend/catalog/heap.c + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/heap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HEAP_H +#define HEAP_H + +#include "parser/parse_node.h" +#include "catalog/indexing.h" +#include "utils/partcache.h" + +#define PSORT_RESERVE_COLUMN "tid" +#define CHCHK_PSORT_RESERVE_COLUMN(attname) (strcmp(PSORT_RESERVE_COLUMN, (attname)) == 0) + +typedef struct RawColumnDefault { + AttrNumber attnum; /* attribute to attach default to */ + Node *raw_default; /* default value (untransformed parse tree) */ +} RawColumnDefault; + +typedef struct CookedConstraint { + ConstrType contype; /* CONSTR_DEFAULT or CONSTR_CHECK */ + char *name; /* name, or NULL if none */ + AttrNumber attnum; /* which attr (only for DEFAULT) */ + Node *expr; /* transformed default or check expr */ + bool skip_validation; /* skip validation? (only for CHECK) */ + bool is_local; /* constraint has local (non-inherited) def */ + int inhcount; /* number of times constraint is inherited */ + bool is_no_inherit; /* constraint has local def and cannot be + * inherited */ +} CookedConstraint; + +typedef struct CeHeapInfo { + int8 alg_type; /* int representation of encryption type RANDOMIZED/DETERMINISTIC */ + Oid orig_typ; + int32 orig_mod; + Oid cek_id; + NameData column_name; + int4 attnum; +} CeHeapInfo; + +typedef struct HashBucketInfo { + oidvector *bucketlist; + int2vector *bucketcol; + Oid bucketOid; +} HashBucketInfo; + +extern Relation heap_create(const char *relname, + Oid relnamespace, + Oid reltablespace, + Oid relid, + Oid relfilenode, + Oid bucketOid, + TupleDesc tupDesc, + char relkind, + char relpersistence, + bool partitioned_relation, + bool rowMovement, + bool shared_relation, + bool mapped_relation, + bool allow_system_table_mods, + int8 row_compress, + Oid ownerid, + bool skip_create_storage, + TableAmType tam_type); + +extern bool heap_is_matview_init_state(Relation rel); + +extern Partition +heapCreatePartition(const char* part_name, + bool for_partitioned_table, + Oid part_tablespace, + Oid part_id, + Oid partFileNode, + Oid bucketOid, + Oid ownerid); + +extern Oid heap_create_with_catalog(const char *relname, + Oid relnamespace, + Oid reltablespace, + Oid relid, + Oid reltypeid, + Oid reloftypeid, + Oid ownerid, + TupleDesc tupdesc, + List *cooked_constraints, + char relkind, + char relpersistence, + bool shared_relation, + bool mapped_relation, + bool oidislocal, + int oidinhcount, + OnCommitAction oncommit, + Datum reloptions, + bool use_user_acl, + bool allow_system_table_mods, + PartitionState *partTableState, + int8 row_compress, + List *filenodelist, + HashBucketInfo *bucketinfo, + bool record_dependce = true, + List* ceLst = NULL); + +extern void heap_create_init_fork(Relation rel); + +extern void heap_drop_with_catalog(Oid relid); +extern void heapDropPartition(Relation rel, Partition part); +extern void dropToastTableOnPartition(Oid partId); +extern void dropCuDescTableOnPartition(Oid partId); +extern void dropDeltaTableOnPartition(Oid partId); + + +extern void heapDropPartitionToastList(List* toastList); +extern void heapDropPartitionList(Relation rel, List* partitionList); +extern Oid heapAddRangePartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, RangePartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern Oid HeapAddListPartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, ListPartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern Oid HeapAddHashPartition(Relation pgPartRel, Oid partTableOid, Oid partrelfileOid, Oid partTablespace, + Oid bucketOid, HashPartitionDefState *newPartDef, Oid ownerid, Datum reloptions, + const bool* isTimestamptz); + +extern void heapDropPartitionIndex(Relation parentIndex, Oid partIndexId); +extern void addNewPartitionTuple(Relation pg_part_desc, Partition new_part_desc, int2vector* pkey, oidvector *intablespace, + Datum interval, Datum maxValues, Datum transitionPoint, Datum reloptions); + +extern void heap_truncate_one_part(Relation rel , Oid partOid); +extern Oid heapTupleGetPartitionId(Relation rel, HeapTuple tuple); +extern void heap_truncate(List *relids); +extern void heap_truncate_one_rel(Relation rel); +extern void heap_truncate_check_FKs(List *relations, bool tempTables); +extern List *heap_truncate_find_FKs(List *relationIds); +extern void InsertPgAttributeTuple(Relation pg_attribute_rel, Form_pg_attribute new_attribute, CatalogIndexState indstate); + +extern void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, + Datum reloptions, char relkind, int2vector *bucketcol); + +extern List *AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local); + +extern List *AddRelClusterConstraints(Relation rel, List *clusterKeys); +extern void StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr); +extern Node *cookDefault(ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, char *attname); +extern void DeleteRelationTuple(Oid relid); +extern void DeleteAttributeTuples(Oid relid); +extern void DeleteSystemAttributeTuples(Oid relid); +extern void RemoveAttributeById(Oid relid, AttrNumber attnum); +extern void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal); +extern void RemoveAttrDefaultById(Oid attrdefId); + +template +extern void RemoveStatistics(Oid relid, AttrNumber attnum); + +extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno, bool relhasoids, bool relhasbucket); +extern Form_pg_attribute SystemAttributeByName(const char *attname, bool relhasoids); + +extern int GetSysAttLength(bool hasBucketAttr = true); + +extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, bool allow_system_table_mods); +extern void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, bool allow_system_table_mods); + +#ifdef PGXC +/* Functions related to distribution data of relations */ +extern void AddRelationDistribution(const char *relname, Oid relid, DistributeBy *distributeby, + PGXCSubCluster *subcluster, List *parentOids, TupleDesc descriptor, bool isinstallationgroup); +extern void GetRelationDistributionItems(Oid relid, DistributeBy *distributeby, TupleDesc descriptor, char *locatortype, + int *hashalgorithm, int *hashbuckets, AttrNumber *attnum); +extern HashBucketInfo *GetRelationBucketInfo(DistributeBy *distributeby, TupleDesc tupledsc, + bool *createbucket, Oid bucket, bool enable_createbucket); +extern void TryReuseIndex(Oid oldId, IndexStmt *stmt); +extern void tryReusePartedIndex(Oid oldId, IndexStmt *stmt, Relation rel); +extern Oid *GetRelationDistributionNodes(PGXCSubCluster *subcluster, int *numnodes); +extern Oid *BuildRelationDistributionNodes(List *nodes, int *numnodes); +extern Oid *SortRelationDistributionNodes(Oid *nodeoids, int numnodes); +#endif + +extern void SetRelHasClusterKey(Relation rel, bool has); +extern int2vector* buildPartitionKey(List *keys, TupleDesc tupledsc); +/* + * @hdfs + * Check the constraint from pg_constraint. + */ +extern bool FindExistingConstraint(const char *ccname, Relation rel); +/** + * @Description: Build the column map. Store the column number using + * bitmap method. + * @in tuple_desc, A tuple descriptor. + * @return reutrn the column map. + */ +extern char* make_column_map(TupleDesc tuple_desc); + +/** + * @Description: check whether the partition keys has timestampwithzone type. + * @input: partTableRel, the partition table relation. + * @return: a bool array to indicate the result. The length of array is equal to the number of partition keys. + * @Notes: remember to pfree the array. + */ +extern bool* check_partkey_has_timestampwithzone(Relation partTableRel); + +extern Oid AddNewIntervalPartition(Relation rel, HeapTuple insertTuple); + +extern int GetIndexKeyAttsByTuple(Relation relation, HeapTuple indexTuple); + +#endif /* HEAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/index.h postgresql-hll-2.14/include/include/catalog/index.h --- postgresql-hll-2.14_old/include/include/catalog/index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/index.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------------- + * + * index.h + * prototypes for catalog/index.c. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/index.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEX_H +#define INDEX_H + +#include "nodes/execnodes.h" +#include "utils/tuplesort.h" + +#define DEFAULT_INDEX_TYPE "btree" +#define DEFAULT_CSTORE_INDEX_TYPE "psort" +#define DEFAULT_GIST_INDEX_TYPE "gist" +#define CSTORE_BTREE_INDEX_TYPE "cbtree" +#define DEFAULT_GIN_INDEX_TYPE "gin" +#define CSTORE_GINBTREE_INDEX_TYPE "cgin" + +/* Typedef for callback function for IndexBuildHeapScan */ +typedef void (*IndexBuildCallback)(Relation index, HeapTuple htup, Datum *values, const bool *isnull, + bool tupleIsAlive, void *state); + +typedef void (*IndexBuildVecBatchScanCallback)(Relation index, ItemPointer tid, Datum *values, + const bool *isnull, void *state); + +/* Action code for index_set_state_flags */ +typedef enum +{ + INDEX_CREATE_SET_READY, + INDEX_CREATE_SET_VALID, + INDEX_DROP_CLEAR_VALID, + INDEX_DROP_SET_DEAD +} IndexStateFlagsAction; + +/* */ +#define REINDEX_BTREE_INDEX (1<<1) +#define REINDEX_HASH_INDEX (1<<2) +#define REINDEX_GIN_INDEX (1<<3) +#define REINDEX_GIST_INDEX (1<<4) +#define REINDEX_CGIN_INDEX (1<<5) +#define REINDEX_ALL_INDEX (REINDEX_BTREE_INDEX|REINDEX_HASH_INDEX|REINDEX_GIN_INDEX|REINDEX_GIST_INDEX|REINDEX_CGIN_INDEX) + + +/* state info for validate_index bulkdelete callback */ +typedef struct { + Tuplesortstate* tuplesort; /* for sorting the index TIDs */ + /* statistics (for debug purposes only): */ + double htups, itups, tups_inserted; +} v_i_state; + + +typedef enum CheckWaitMode +{ + CHECK_WAIT, + CHECK_NOWAIT, +} CheckWaitMode; + +extern void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table); + +/* + * Parameter isPartitionedIndex indicates whether the index is a partition index. + * Parameter isGlobalPartitionedIndex indicates whether the index is a global partition index. + * ------------------------------------------------------------------------- + * | isPartitionedIndex | isGlobalPartitionedIndex | Description | + * ------------------------------------------------------------------------- + * | false | false | normal relation index | + * ------------------------------------------------------------------------- + * | true | false | local partition index | + * ------------------------------------------------------------------------- + * | false | true | can not happen | + * ------------------------------------------------------------------------- + * | true | true | global partition index | + * ------------------------------------------------------------------------- + */ +typedef struct +{ + Oid existingPSortOid; + bool isPartitionedIndex; + bool isGlobalPartitionedIndex; +} IndexCreateExtraArgs; + +typedef enum { + INDEX_CREATE_NONE_PARTITION, + INDEX_CREATE_LOCAL_PARTITION, + INDEX_CREATE_GLOBAL_PARTITION +} IndexCreatePartitionType; + +typedef enum { ALL_KIND, GLOBAL_INDEX, LOCAL_INDEX } IndexKind; + +#define PARTITION_TYPE(extra) \ + (extra->isPartitionedIndex == false ? INDEX_CREATE_NONE_PARTITION \ + : (extra->isGlobalPartitionedIndex == false ? INDEX_CREATE_LOCAL_PARTITION \ + : INDEX_CREATE_GLOBAL_PARTITION)) + + +extern Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, + Oid relFileNode, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, + Oid tableSpaceId, Oid *collationObjectId, Oid *classObjectId, int16 *coloptions, + Datum reloptions, bool isprimary, bool isconstraint, bool deferrable, + bool initdeferred, bool allow_system_table_mods, bool skip_build, bool concurrent, + IndexCreateExtraArgs *extra); + +extern void index_constraint_create(Relation heapRelation, Oid indexRelationId, IndexInfo *indexInfo, + const char *constraintName, char constraintType, bool deferrable, + bool initdeferred, bool mark_as_primary, bool update_pgindex, + bool remove_old_dependencies, bool allow_system_table_mods); + +extern void index_drop(Oid indexId, bool concurrent); + +extern IndexInfo *BuildIndexInfo(Relation index); +extern IndexInfo *BuildDummyIndexInfo(Relation index); + +extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo* ii); + +extern void FormIndexDatum(IndexInfo *indexInfo, + TupleTableSlot *slot, + EState *estate, + Datum *values, + bool *isnull); +extern void index_build(Relation heapRelation, + Partition heapPartition, + Relation indexRelation, + Partition indexPartition, + IndexInfo *indexInfo, + bool isprimary, + bool isreindex, + IndexCreatePartitionType partitionType); + +extern double IndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + bool allow_sync, IndexBuildCallback callback, void *callback_state); +extern double* GlobalIndexBuildHeapScan(Relation heapRelation, Relation indexRelation, IndexInfo* indexInfo, + IndexBuildCallback callback, void* callbackState); +extern double IndexBuildVectorBatchScan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + VectorBatch *vecScanBatch, Snapshot snapshot, + IndexBuildVecBatchScanCallback callback, void *callback_state, + void *transferFuncs); + + +extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot); +extern void validate_index_heapscan( + Relation heapRelation, Relation indexRelation, IndexInfo* indexInfo, Snapshot snapshot, v_i_state* state); + +extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action); +extern void reindex_indexpart_internal(Relation heapRelation, + Relation iRel, + IndexInfo* indexInfo, + Oid indexPartId); +extern void reindex_index(Oid indexId, Oid indexPartId, + bool skip_constraint_checks, AdaptMem *memInfo, + bool dbWide); +extern void ReindexGlobalIndexInternal(Relation heapRelation, Relation iRel, IndexInfo* indexInfo); + +/* Flag bits for reindex_relation(): */ +#define REINDEX_REL_PROCESS_TOAST 0x01 +#define REINDEX_REL_SUPPRESS_INDEX_USE 0x02 +#define REINDEX_REL_CHECK_CONSTRAINTS 0x04 + +extern bool reindex_relation(Oid relid, int flags, int reindexType, AdaptMem* memInfo = NULL, bool dbWide = false, + IndexKind indexKind = ALL_KIND); +extern bool ReindexIsProcessingHeap(Oid heapOid); +extern bool ReindexIsProcessingIndex(Oid indexOid); +extern Oid IndexGetRelation(Oid indexId, bool missing_ok); + +typedef struct +{ + Oid existingPSortOid; +} PartIndexCreateExtraArgs; + +extern Oid partition_index_create(const char* partIndexName, + Oid partIndexFileNode, + Partition partition, + Oid tspid, + Relation parentIndex, + Relation partitionedTable, + Relation pg_partition_rel, + IndexInfo *indexInfo, + List *indexColNames, + Datum indexRelOptions, + bool skipBuild, + PartIndexCreateExtraArgs *extra); +extern void addIndexForPartition(Relation partitionedRelation, Oid partOid); +extern void dropIndexForPartition(Oid partOid); +extern void index_update_stats(Relation rel, bool hasindex, bool isprimary, + Oid reltoastidxid, Oid relcudescidx, double reltuples); +extern void PartitionNameCallbackForIndexPartition(Oid partitionedRelationOid, + const char *partitionName, + Oid partId, + Oid oldPartId, + char partition_type, + void *arg, + LOCKMODE callbackobj_lockMode); +extern void reindex_partIndex(Relation heapRel, Partition heapPart, Relation indexRel , Partition indexPart); +extern bool reindexPartition(Oid relid, Oid partOid, int flags, int reindexType); +extern void AddGPIForPartition(Oid partTableOid, Oid partOid); +extern void mergeBTreeIndexes(List* mergingBtreeIndexes, List* srcPartMergeOffset); +extern void SetIndexCreateExtraArgs(IndexCreateExtraArgs* extra, Oid psortOid, bool isPartition, bool isGlobal); +#endif /* INDEX_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/indexing.h postgresql-hll-2.14/include/include/catalog/indexing.h --- postgresql-hll-2.14_old/include/include/catalog/indexing.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/indexing.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,553 @@ +/* ------------------------------------------------------------------------- + * + * indexing.h + * This file provides some definitions to support indexing + * on system catalogs + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/indexing.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEXING_H +#define INDEXING_H + +#include "access/htup.h" +#include "utils/relcache.h" + +/* + * The state object used by CatalogOpenIndexes and friends is actually the + * same as the executor's ResultRelInfo, but we give it another type name + * to decouple callers from that fact. + */ +typedef struct ResultRelInfo *CatalogIndexState; + +/* + * indexing.c prototypes + */ +extern CatalogIndexState CatalogOpenIndexes(Relation heapRel); +extern void CatalogCloseIndexes(CatalogIndexState indstate); +extern void CatalogIndexInsert(CatalogIndexState indstate, + HeapTuple heapTuple); +extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple); + + +/* + * These macros are just to keep the C compiler from spitting up on the + * upcoming commands for genbki.pl. + */ +#define DECLARE_INDEX(name,oid,decl) extern int no_such_variable +#define DECLARE_UNIQUE_INDEX(name,oid,decl) extern int no_such_variable +#define BUILD_INDICES + + +/* + * What follows are lines processed by genbki.pl to create the statements + * the bootstrap parser will turn into DefineIndex commands. + * + * The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX. The first two + * arguments are the index name and OID, the rest is much like a standard + * 'create index' SQL command. + * + * For each index, we also provide a #define for its OID. References to + * the index in the C code should always use these #defines, not the actual + * index name (much less the numeric OID). + */ + +DECLARE_UNIQUE_INDEX(pg_aggregate_fnoid_index, 2650, on pg_aggregate using btree(aggfnoid oid_ops)); +#define AggregateFnoidIndexId 2650 + +DECLARE_UNIQUE_INDEX(pg_am_name_index, 2651, on pg_am using btree(amname name_ops)); +#define AmNameIndexId 2651 +DECLARE_UNIQUE_INDEX(pg_am_oid_index, 2652, on pg_am using btree(oid oid_ops)); +#define AmOidIndexId 2652 + +DECLARE_UNIQUE_INDEX(pg_amop_fam_strat_index, 2653, on pg_amop using btree(amopfamily oid_ops, amoplefttype oid_ops, amoprighttype oid_ops, amopstrategy int2_ops)); +#define AccessMethodStrategyIndexId 2653 +DECLARE_UNIQUE_INDEX(pg_amop_opr_fam_index, 2654, on pg_amop using btree(amopopr oid_ops, amoppurpose char_ops, amopfamily oid_ops)); +#define AccessMethodOperatorIndexId 2654 +DECLARE_UNIQUE_INDEX(pg_amop_oid_index, 2756, on pg_amop using btree(oid oid_ops)); +#define AccessMethodOperatorOidIndexId 2756 + +DECLARE_UNIQUE_INDEX(pg_amproc_fam_proc_index, 2655, on pg_amproc using btree(amprocfamily oid_ops, amproclefttype oid_ops, amprocrighttype oid_ops, amprocnum int2_ops)); +#define AccessMethodProcedureIndexId 2655 +DECLARE_UNIQUE_INDEX(pg_amproc_oid_index, 2757, on pg_amproc using btree(oid oid_ops)); +#define AccessMethodProcedureOidIndexId 2757 + +DECLARE_UNIQUE_INDEX(pg_attrdef_adrelid_adnum_index, 2656, on pg_attrdef using btree(adrelid oid_ops, adnum int2_ops)); +#define AttrDefaultIndexId 2656 +DECLARE_UNIQUE_INDEX(pg_attrdef_oid_index, 2657, on pg_attrdef using btree(oid oid_ops)); +#define AttrDefaultOidIndexId 2657 + +DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnam_index, 2658, on pg_attribute using btree(attrelid oid_ops, attname name_ops)); +#define AttributeRelidNameIndexId 2658 +DECLARE_UNIQUE_INDEX(pg_attribute_relid_attnum_index, 2659, on pg_attribute using btree(attrelid oid_ops, attnum int2_ops)); +#define AttributeRelidNumIndexId 2659 + +DECLARE_UNIQUE_INDEX(pg_authid_rolname_index, 2676, on pg_authid using btree(rolname name_ops)); +#define AuthIdRolnameIndexId 2676 +DECLARE_UNIQUE_INDEX(pg_authid_oid_index, 2677, on pg_authid using btree(oid oid_ops)); +#define AuthIdOidIndexId 2677 + +DECLARE_UNIQUE_INDEX(pg_auth_members_role_member_index, 2694, on pg_auth_members using btree(roleid oid_ops, member oid_ops)); +#define AuthMemRoleMemIndexId 2694 +DECLARE_UNIQUE_INDEX(pg_auth_members_member_role_index, 2695, on pg_auth_members using btree(member oid_ops, roleid oid_ops)); +#define AuthMemMemRoleIndexId 2695 + +DECLARE_UNIQUE_INDEX(pg_cast_oid_index, 2660, on pg_cast using btree(oid oid_ops)); +#define CastOidIndexId 2660 +DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, on pg_cast using btree(castsource oid_ops, casttarget oid_ops)); +#define CastSourceTargetIndexId 2661 + +DECLARE_UNIQUE_INDEX(pg_class_oid_index, 2662, on pg_class using btree(oid oid_ops)); +#define ClassOidIndexId 2662 +DECLARE_UNIQUE_INDEX(pg_class_relname_nsp_index, 2663, on pg_class using btree(relname name_ops, relnamespace oid_ops)); +#define ClassNameNspIndexId 2663 +DECLARE_INDEX(pg_class_tblspc_relfilenode_index, 9981, on pg_class using btree(reltablespace oid_ops, relfilenode oid_ops)); +#define ClassTblspcRelfilenodeIndexId 9981 +DECLARE_UNIQUE_INDEX(pg_collation_name_enc_nsp_index, 3164, on pg_collation using btree(collname name_ops, collencoding int4_ops, collnamespace oid_ops)); +#define CollationNameEncNspIndexId 3164 +DECLARE_UNIQUE_INDEX(pg_collation_oid_index, 3085, on pg_collation using btree(oid oid_ops)); +#define CollationOidIndexId 3085 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_conname_nsp_index, 2664, on pg_constraint using btree(conname name_ops, connamespace oid_ops)); +#define ConstraintNameNspIndexId 2664 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_conrelid_index, 2665, on pg_constraint using btree(conrelid oid_ops)); +#define ConstraintRelidIndexId 2665 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_constraint_contypid_index, 2666, on pg_constraint using btree(contypid oid_ops)); +#define ConstraintTypidIndexId 2666 +DECLARE_UNIQUE_INDEX(pg_constraint_oid_index, 2667, on pg_constraint using btree(oid oid_ops)); +#define ConstraintOidIndexId 2667 + +DECLARE_UNIQUE_INDEX(pg_conversion_default_index, 2668, on pg_conversion using btree(connamespace oid_ops, conforencoding int4_ops, contoencoding int4_ops, oid oid_ops)); +#define ConversionDefaultIndexId 2668 +DECLARE_UNIQUE_INDEX(pg_conversion_name_nsp_index, 2669, on pg_conversion using btree(conname name_ops, connamespace oid_ops)); +#define ConversionNameNspIndexId 2669 +DECLARE_UNIQUE_INDEX(pg_conversion_oid_index, 2670, on pg_conversion using btree(oid oid_ops)); +#define ConversionOidIndexId 2670 + +DECLARE_UNIQUE_INDEX(pg_database_datname_index, 2671, on pg_database using btree(datname name_ops)); +#define DatabaseNameIndexId 2671 +DECLARE_UNIQUE_INDEX(pg_database_oid_index, 2672, on pg_database using btree(oid oid_ops)); +#define DatabaseOidIndexId 2672 + +/* This follwing index is used for Data Source */ +DECLARE_UNIQUE_INDEX(pg_extension_data_source_oid_index, 7166, on pg_extension_data_source using btree(oid oid_ops)); +#define DataSourceOidIndexId 7166 + +DECLARE_UNIQUE_INDEX(pg_extension_data_source_name_index, 7167, on pg_extension_data_source using btree(srcname name_ops)); +#define DataSourceNameIndexId 7167 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_depend_depender_index, 2673, on pg_depend using btree(classid oid_ops, objid oid_ops, objsubid int4_ops)); +#define DependDependerIndexId 2673 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_depend_reference_index, 2674, on pg_depend using btree(refclassid oid_ops, refobjid oid_ops, refobjsubid int4_ops)); +#define DependReferenceIndexId 2674 + +DECLARE_UNIQUE_INDEX(pg_description_o_c_o_index, 2675, on pg_description using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops)); +#define DescriptionObjIndexId 2675 +DECLARE_UNIQUE_INDEX(pg_shdescription_o_c_index, 2397, on pg_shdescription using btree(objoid oid_ops, classoid oid_ops)); +#define SharedDescriptionObjIndexId 2397 + +DECLARE_UNIQUE_INDEX(pg_enum_oid_index, 3502, on pg_enum using btree(oid oid_ops)); +#define EnumOidIndexId 3502 +DECLARE_UNIQUE_INDEX(pg_enum_typid_label_index, 3503, on pg_enum using btree(enumtypid oid_ops, enumlabel name_ops)); +#define EnumTypIdLabelIndexId 3503 +DECLARE_UNIQUE_INDEX(pg_enum_typid_sortorder_index, 3534, on pg_enum using btree(enumtypid oid_ops, enumsortorder float4_ops)); +#define EnumTypIdSortOrderIndexId 3534 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_index_indrelid_index, 2678, on pg_index using btree(indrelid oid_ops)); +#define IndexIndrelidIndexId 2678 +DECLARE_UNIQUE_INDEX(pg_index_indexrelid_index, 2679, on pg_index using btree(indexrelid oid_ops)); +#define IndexRelidIndexId 2679 + +DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index, 2680, on pg_inherits using btree(inhrelid oid_ops, inhseqno int4_ops)); +#define InheritsRelidSeqnoIndexId 2680 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_inherits_parent_index, 2187, on pg_inherits using btree(inhparent oid_ops)); +#define InheritsParentIndexId 2187 + +DECLARE_UNIQUE_INDEX(pg_language_name_index, 2681, on pg_language using btree(lanname name_ops)); +#define LanguageNameIndexId 2681 +DECLARE_UNIQUE_INDEX(pg_language_oid_index, 2682, on pg_language using btree(oid oid_ops)); +#define LanguageOidIndexId 2682 + +DECLARE_UNIQUE_INDEX(pg_largeobject_loid_pn_index, 2683, on pg_largeobject using btree(loid oid_ops, pageno int4_ops)); +#define LargeObjectLOidPNIndexId 2683 + +DECLARE_UNIQUE_INDEX(pg_largeobject_metadata_oid_index, 2996, on pg_largeobject_metadata using btree(oid oid_ops)); +#define LargeObjectMetadataOidIndexId 2996 + +DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, on pg_namespace using btree(nspname name_ops)); +#define NamespaceNameIndexId 2684 +DECLARE_UNIQUE_INDEX(pg_namespace_oid_index, 2685, on pg_namespace using btree(oid oid_ops)); +#define NamespaceOidIndexId 2685 + +DECLARE_UNIQUE_INDEX(pg_opclass_am_name_nsp_index, 2686, on pg_opclass using btree(opcmethod oid_ops, opcname name_ops, opcnamespace oid_ops)); +#define OpclassAmNameNspIndexId 2686 +DECLARE_UNIQUE_INDEX(pg_opclass_oid_index, 2687, on pg_opclass using btree(oid oid_ops)); +#define OpclassOidIndexId 2687 + +DECLARE_UNIQUE_INDEX(pg_operator_oid_index, 2688, on pg_operator using btree(oid oid_ops)); +#define OperatorOidIndexId 2688 +DECLARE_UNIQUE_INDEX(pg_operator_oprname_l_r_n_index, 2689, on pg_operator using btree(oprname name_ops, oprleft oid_ops, oprright oid_ops, oprnamespace oid_ops)); +#define OperatorNameNspIndexId 2689 + +DECLARE_UNIQUE_INDEX(pg_opfamily_am_name_nsp_index, 2754, on pg_opfamily using btree(opfmethod oid_ops, opfname name_ops, opfnamespace oid_ops)); +#define OpfamilyAmNameNspIndexId 2754 +DECLARE_UNIQUE_INDEX(pg_opfamily_oid_index, 2755, on pg_opfamily using btree(oid oid_ops)); +#define OpfamilyOidIndexId 2755 + +DECLARE_UNIQUE_INDEX(pg_pltemplate_name_index, 1137, on pg_pltemplate using btree(tmplname name_ops)); +#define PLTemplateNameIndexId 1137 + +DECLARE_UNIQUE_INDEX(pg_proc_oid_index, 2690, on pg_proc using btree(oid oid_ops)); +#define ProcedureOidIndexId 2690 +DECLARE_UNIQUE_INDEX(pg_proc_proname_args_nsp_index, 2691, on pg_proc using btree(proname name_ops, proargtypes oidvector_ops, pronamespace oid_ops)); +#define ProcedureNameArgsNspIndexId 2691 + +DECLARE_UNIQUE_INDEX(pg_rewrite_oid_index, 2692, on pg_rewrite using btree(oid oid_ops)); +#define RewriteOidIndexId 2692 +DECLARE_UNIQUE_INDEX(pg_rewrite_rel_rulename_index, 2693, on pg_rewrite using btree(ev_class oid_ops, rulename name_ops)); +#define RewriteRelRulenameIndexId 2693 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_shdepend_depender_index, 1232, on pg_shdepend using btree(dbid oid_ops, classid oid_ops, objid oid_ops, objsubid int4_ops)); +#define SharedDependDependerIndexId 1232 +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_shdepend_reference_index, 1233, on pg_shdepend using btree(refclassid oid_ops, refobjid oid_ops)); +#define SharedDependReferenceIndexId 1233 + +DECLARE_UNIQUE_INDEX(pg_statistic_relid_kind_att_inh_index, 2696, on pg_statistic using btree(starelid oid_ops, starelkind char_ops, staattnum int2_ops, stainherit bool_ops)); +#define StatisticRelidKindAttnumInhIndexId 2696 + +DECLARE_UNIQUE_INDEX(pg_statistic_ext_relid_kind_inh_key_index, 3222, on pg_statistic_ext using btree(starelid oid_ops, starelkind char_ops, stainherit bool_ops, stakey array_ops)); +#define StatisticExtRelidKindInhKeyIndexId 3222 + +DECLARE_UNIQUE_INDEX(pg_tablespace_oid_index, 2697, on pg_tablespace using btree(oid oid_ops)); +#define TablespaceOidIndexId 2697 +DECLARE_UNIQUE_INDEX(pg_tablespace_spcname_index, 2698, on pg_tablespace using btree(spcname name_ops)); +#define TablespaceNameIndexId 2698 + +/* This following index is not used for a cache and is not unique */ +DECLARE_INDEX(pg_trigger_tgconstraint_index, 2699, on pg_trigger using btree(tgconstraint oid_ops)); +#define TriggerConstraintIndexId 2699 +DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index, 2701, on pg_trigger using btree(tgrelid oid_ops, tgname name_ops)); +#define TriggerRelidNameIndexId 2701 +DECLARE_UNIQUE_INDEX(pg_trigger_oid_index, 2702, on pg_trigger using btree(oid oid_ops)); +#define TriggerOidIndexId 2702 + +DECLARE_UNIQUE_INDEX(pg_ts_config_cfgname_index, 3608, on pg_ts_config using btree(cfgname name_ops, cfgnamespace oid_ops)); +#define TSConfigNameNspIndexId 3608 +DECLARE_UNIQUE_INDEX(pg_ts_config_oid_index, 3712, on pg_ts_config using btree(oid oid_ops)); +#define TSConfigOidIndexId 3712 + +DECLARE_UNIQUE_INDEX(pg_ts_config_map_index, 3609, on pg_ts_config_map using btree(mapcfg oid_ops, maptokentype int4_ops, mapseqno int4_ops)); +#define TSConfigMapIndexId 3609 + +DECLARE_UNIQUE_INDEX(pg_ts_dict_dictname_index, 3604, on pg_ts_dict using btree(dictname name_ops, dictnamespace oid_ops)); +#define TSDictionaryNameNspIndexId 3604 +DECLARE_UNIQUE_INDEX(pg_ts_dict_oid_index, 3605, on pg_ts_dict using btree(oid oid_ops)); +#define TSDictionaryOidIndexId 3605 + +DECLARE_UNIQUE_INDEX(pg_ts_parser_prsname_index, 3606, on pg_ts_parser using btree(prsname name_ops, prsnamespace oid_ops)); +#define TSParserNameNspIndexId 3606 +DECLARE_UNIQUE_INDEX(pg_ts_parser_oid_index, 3607, on pg_ts_parser using btree(oid oid_ops)); +#define TSParserOidIndexId 3607 + +DECLARE_UNIQUE_INDEX(pg_ts_template_tmplname_index, 3766, on pg_ts_template using btree(tmplname name_ops, tmplnamespace oid_ops)); +#define TSTemplateNameNspIndexId 3766 +DECLARE_UNIQUE_INDEX(pg_ts_template_oid_index, 3767, on pg_ts_template using btree(oid oid_ops)); +#define TSTemplateOidIndexId 3767 + +DECLARE_UNIQUE_INDEX(pg_type_oid_index, 2703, on pg_type using btree(oid oid_ops)); +#define TypeOidIndexId 2703 +DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index, 2704, on pg_type using btree(typname name_ops, typnamespace oid_ops)); +#define TypeNameNspIndexId 2704 + +DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_oid_index, 112, on pg_foreign_data_wrapper using btree(oid oid_ops)); +#define ForeignDataWrapperOidIndexId 112 + +DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_name_index, 548, on pg_foreign_data_wrapper using btree(fdwname name_ops)); +#define ForeignDataWrapperNameIndexId 548 + +DECLARE_UNIQUE_INDEX(pg_foreign_server_oid_index, 113, on pg_foreign_server using btree(oid oid_ops)); +#define ForeignServerOidIndexId 113 + +DECLARE_UNIQUE_INDEX(pg_foreign_server_name_index, 549, on pg_foreign_server using btree(srvname name_ops)); +#define ForeignServerNameIndexId 549 + +DECLARE_UNIQUE_INDEX(pg_user_mapping_oid_index, 174, on pg_user_mapping using btree(oid oid_ops)); +#define UserMappingOidIndexId 174 + +DECLARE_UNIQUE_INDEX(pg_user_mapping_user_server_index, 175, on pg_user_mapping using btree(umuser oid_ops, umserver oid_ops)); +#define UserMappingUserServerIndexId 175 + +#ifdef PGXC +DECLARE_UNIQUE_INDEX(pgxc_class_pcrelid_index, 9002, on pgxc_class using btree(pcrelid oid_ops)); +#define PgxcClassPgxcRelIdIndexId 9002 + +DECLARE_UNIQUE_INDEX(pgxc_node_oid_index, 9010, on pgxc_node using btree(oid oid_ops)); +#define PgxcNodeOidIndexId 9010 + +DECLARE_UNIQUE_INDEX(pgxc_node_name_type_index, 9024, on pgxc_node using btree(node_name name_ops, node_type char_ops, oid oid_ops)); +#define PgxcNodeNodeNameIndexId 9024 +#define PgxcNodeNodeNameIndexIdOld 9011 + +DECLARE_UNIQUE_INDEX(pgxc_group_name_index, 9012, on pgxc_group using btree(group_name name_ops)); +#define PgxcGroupGroupNameIndexId 9012 + +DECLARE_UNIQUE_INDEX(pgxc_group_oid, 9013, on pgxc_group using btree(oid oid_ops)); +#define PgxcGroupOidIndexId 9013 + +DECLARE_UNIQUE_INDEX(pg_resource_pool_name_index, 9000, on pg_resource_pool using btree(respool_name name_ops)); +#define ResourcePoolPoolNameIndexId 9000 + +DECLARE_UNIQUE_INDEX(pg_resource_pool_oid_index, 9017, on pg_resource_pool using btree(oid oid_ops)); +#define ResourcePoolOidIndexId 9017 + +DECLARE_UNIQUE_INDEX(pg_workload_group_name_index, 9018, on pg_workload_group using btree(workload_gpname name_ops)); +#define WorkloadGroupGroupNameIndexId 9018 + +DECLARE_UNIQUE_INDEX(pg_workload_group_oid_index, 9019, on pg_workload_group using btree(oid oid_ops)); +#define WorkloadGroupOidIndexId 9019 + +DECLARE_UNIQUE_INDEX(pg_app_workloadgroup_mapping_name_index, 9020, on pg_app_workloadgroup_mapping using btree(appname name_ops)); +#define AppWorkloadGroupMappingNameIndexId 9020 + +DECLARE_UNIQUE_INDEX(pg_app_workloadgroup_mapping_oid_index, 9021, on pg_app_workloadgroup_mapping using btree(oid oid_ops)); +#define AppWorkloadGroupMappingOidIndexId 9021 + +DECLARE_UNIQUE_INDEX(pgxc_node_id_index, 9003, on pgxc_node using btree(node_id int4_ops)); +#define PgxcNodeNodeIdIndexId 9003 + +DECLARE_UNIQUE_INDEX(pgxc_slice_relid_index, 9033, on pgxc_slice using btree(relid oid_ops, type char_ops, relname name_ops, sindex int4_ops)); +#define PgxcSliceIndexId 9033 + +DECLARE_UNIQUE_INDEX(pgxc_slice_order_index, 9034, on pgxc_slice using btree(relid oid_ops, type char_ops, sliceorder int4_ops, sindex int4_ops)); +#define PgxcSliceOrderIndexId 9034 + +#endif + +DECLARE_UNIQUE_INDEX(pg_foreign_table_relid_index, 3119, on pg_foreign_table using btree(ftrelid oid_ops)); +#define ForeignTableRelidIndexId 3119 + +DECLARE_UNIQUE_INDEX(pg_default_acl_role_nsp_obj_index, 827, on pg_default_acl using btree(defaclrole oid_ops, defaclnamespace oid_ops, defaclobjtype char_ops)); +#define DefaultAclRoleNspObjIndexId 827 +DECLARE_UNIQUE_INDEX(pg_default_acl_oid_index, 828, on pg_default_acl using btree(oid oid_ops)); +#define DefaultAclOidIndexId 828 + +DECLARE_UNIQUE_INDEX(pg_db_role_setting_databaseid_rol_index, 2965, on pg_db_role_setting using btree(setdatabase oid_ops, setrole oid_ops)); +#define DbRoleSettingDatidRolidIndexId 2965 + +DECLARE_UNIQUE_INDEX(pg_seclabel_object_index, 3597, on pg_seclabel using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops, provider text_ops)); +#define SecLabelObjectIndexId 3597 + +DECLARE_UNIQUE_INDEX(pg_shseclabel_object_index, 3593, on pg_shseclabel using btree(objoid oid_ops, classoid oid_ops, provider text_ops)); +#define SharedSecLabelObjectIndexId 3593 + +DECLARE_UNIQUE_INDEX(pg_extension_oid_index, 3080, on pg_extension using btree(oid oid_ops)); +#define ExtensionOidIndexId 3080 + +DECLARE_UNIQUE_INDEX(pg_extension_name_index, 3081, on pg_extension using btree(extname name_ops)); +#define ExtensionNameIndexId 3081 + +DECLARE_UNIQUE_INDEX(pg_range_rngtypid_index, 3542, on pg_range using btree(rngtypid oid_ops)); +#define RangeTypidIndexId 3542 + +/* add index of passwordtime for pg_auth_history */ +DECLARE_UNIQUE_INDEX(pg_auth_history_index, 3458, on pg_auth_history using btree(roloid oid_ops, passwordtime timestamptz_ops)); +#define AuthHistoryIndexId 3458 +DECLARE_UNIQUE_INDEX(pg_auth_history_oid_index, 3459, on pg_auth_history using btree(oid oid_ops)); +#define AuthHistoryOidIndexId 3459 +/* add index of roleid for pg_user_status */ +DECLARE_UNIQUE_INDEX(pg_user_status_index, 3461, on pg_user_status using btree(roloid oid_ops)); +#define UserStatusRoleidIndexId 3461 +DECLARE_UNIQUE_INDEX(pg_user_status_oid_index, 3462, on pg_user_status using btree(oid oid_ops)); +#define UserStatusOidIndexId 3462 +DECLARE_UNIQUE_INDEX(pg_partition_reloid_index, 3472, on pg_partition using btree(oid oid_ops)); +#define PartitionOidIndexId 3472 +DECLARE_INDEX(pg_partition_parentoid_index,3473, on pg_partition using btree(parttype char_ops, parentid oid_ops)); +#define PartitionParentOidIndexId 3473 +DECLARE_INDEX(pg_partition_indextblid_index,3474, on pg_partition using btree(indextblid oid_ops)); +#define PartitionIndexTableIdIndexId 3474 +DECLARE_UNIQUE_INDEX(pg_partition_partoid_index, 3479, on pg_partition using btree(relname name_ops, parttype char_ops, parentid oid_ops)); +#define PartitionPartOidIndexId 3479 + +/* Add index of table oid for pg_hashbucket */ +DECLARE_UNIQUE_INDEX(pg_hashbucket_oid_index, 3490, on pg_hashbucket using btree(oid oid_ops)); +#define HashBucketOidIndexId 3490 +DECLARE_INDEX(pg_hashbucket_bid_index,3491, on pg_hashbucket using btree(bucketid oid_ops, bucketcnt int4_ops)); +#define HashBucketBidIndexId 3491 + +/* Add index of table oid for pg_job, pg_job_proc */ +DECLARE_UNIQUE_INDEX(pg_job_oid_index, 3453, on pg_job using btree(oid oid_ops)); +#define PgJobOidIndexId 3453 +DECLARE_UNIQUE_INDEX(pg_job_id_index, 3454, on pg_job using btree(job_id int8_ops)); +#define PgJobIdIndexId 3454 +DECLARE_UNIQUE_INDEX(pg_job_proc_oid_index, 3455, on pg_job_proc using btree(oid oid_ops)); +#define PgJobProcOidIndexId 3455 +DECLARE_UNIQUE_INDEX(pg_job_proc_id_index, 3449, on pg_job_proc using btree(job_id int4_ops)); +#define PgJobProcIdIndexId 3449 + +DECLARE_INDEX(gs_asp_sampletime_index, 2999, on gs_asp using btree(sample_time timestamptz_ops)); +#define GsAspSampleIdTimedexId 2999 + +/* Add index of table oid for pg_directory */ +DECLARE_UNIQUE_INDEX(pg_directory_oid_index, 4349, on pg_directory using btree(oid oid_ops)); +#define PgDirectoryOidIndexId 4349 +DECLARE_UNIQUE_INDEX(pg_directory_name_index, 4350, on pg_directory using btree(dirname name_ops)); +#define PgDirectoryDirectoriesNameIndexId 4350 + +/* Add index of table oid for gs_policy_label */ +DECLARE_UNIQUE_INDEX(gs_policy_label_oid_index, 9501, on gs_policy_label using btree(oid oid_ops)); +#define GsPolicyLabelOidIndexId 9501 +DECLARE_INDEX(gs_policy_label_name_index, 9502, on gs_policy_label using btree(labelname name_ops, fqdnnamespace oid_ops, fqdnid oid_ops)); +#define GsPolicyLabelNameIndexId 9502 + +/* Add index of table oid for gs_auditing_policy */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_oid_index, 9511, on gs_auditing_policy using btree(oid oid_ops)); +#define GsAuditingPolicyOidIndexId 9511 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_name_index, 9512, on gs_auditing_policy using btree(polname name_ops)); +#define GsAuditingPolicyNameIndexId 9512 + +/* Add index of table oid for policy access and privileges */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_access_oid_index, 9521, on gs_auditing_policy_access using btree(oid oid_ops)); +#define GsAuditingPolicyAccessOidIndexId 9521 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_privileges_oid_index, 9531, on gs_auditing_policy_privileges using btree(oid oid_ops)); +#define GsAuditingPolicyPrivilegesOidIndexId 9531 + +/* Add index for whole policy access and privileges row */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_access_row_index, 9522, on gs_auditing_policy_access using btree(accesstype name_ops, labelname name_ops, policyoid oid_ops)); +#define GsAuditingPolicyAccessRowIndexId 9522 +DECLARE_UNIQUE_INDEX(gs_auditing_policy_privileges_row_index, 9532, on gs_auditing_policy_privileges using btree(privilegetype name_ops, labelname name_ops, policyoid oid_ops)); +#define GsAuditingPolicyPrivilegesRowIndexId 9532 + +/* Add index for table oid for auditing policy filters */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_filters_oid_index, 9541, on gs_auditing_policy_filters using btree(oid oid_ops)); +#define GsAuditingPolicyFiltersOidIndexId 9541 +/* Add index for policy oid filter row */ +DECLARE_UNIQUE_INDEX(gs_auditing_policy_filters_row_index, 9542, on gs_auditing_policy_filters using btree(policyoid oid_ops)); +#define GsAuditingPolicyFiltersPolicyOidIndexId 9542 + +/* Add index of table oid for gs_masking_policy */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_oid_index, 9611, on gs_masking_policy using btree(oid oid_ops)); +#define GsMaskingPolicyOidIndexId 9611 +DECLARE_UNIQUE_INDEX(gs_masking_policy_name_index, 9612, on gs_masking_policy using btree(polname name_ops)); +#define GsMaskingPolicyNameIndexId 9612 + +/* Add index for table oid for masking policy filters */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_filters_oid_index, 9641, on gs_masking_policy_filters using btree(oid oid_ops)); +#define GsMaskingPolicyFiltersOidIndexId 9641 +/* Add index for whole masking policy filter row */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_filters_row_index, 9642, on gs_masking_policy_filters using btree(policyoid oid_ops)); +#define GsMaskingPolicyFiltersPolicyOidIndexId 9642 + +/* Add index of table oid for gs_masking_policy_actions */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_actions_oid_index, 9651, on gs_masking_policy_actions using btree(oid oid_ops)); +#define GsMaskingPolicyActionsOidIndexId 9651 + +/* Add index for whole masking actions row */ +DECLARE_UNIQUE_INDEX(gs_masking_policy_actions_row_index, 9652, on gs_masking_policy_actions using btree(actiontype name_ops, actlabelname name_ops, policyoid oid_ops)); +#define GsMaskingPolicyActionsRowIndexId 9652 +/* Add index for whole masking actions row */ +DECLARE_INDEX(gs_masking_policy_actions_policy_oid_index, 9653, on gs_masking_policy_actions using btree(policyoid oid_ops)); +#define GsMaskingPolicyActionsPolicyOidIndexId 9653 + +/* Add index of table oid for pg_rlspolicy */ +DECLARE_UNIQUE_INDEX(pg_rlspolicy_oid_index, 3224, on pg_rlspolicy using btree(oid oid_ops)); +#define PgRlspolicyOidIndex 3224 +DECLARE_UNIQUE_INDEX(pg_rlspolicy_polrelid_polname_index, 3225, on pg_rlspolicy using btree(polrelid oid_ops, polname name_ops)); +#define PgRlspolicyPolrelidPolnameIndex 3225 + +/* Add index for pg_objcet */ +DECLARE_UNIQUE_INDEX(pg_object_index, 3227, on pg_object using btree(object_oid oid_ops, object_type char_ops)); +#define PgObjectIndex 3227 + +/* Add index of table oid for pg_synonym */ +DECLARE_UNIQUE_INDEX(pg_synonym_name_nsp_index, 3547, on pg_synonym using btree(synname name_ops, synnamespace oid_ops)); +#define SynonymNameNspIndexId 3547 +DECLARE_UNIQUE_INDEX(pg_synonym_oid_index, 3548, on pg_synonym using btree(oid oid_ops)); +#define SynonymOidIndexId 3548 + +/* Add index of table oid for streaming_stream, streaming_cont_query */ +DECLARE_UNIQUE_INDEX(streaming_stream_oid_index, 3228, on streaming_stream using btree(oid oid_ops)); +#define StreamingStreamOidIndexId 3228 +DECLARE_UNIQUE_INDEX(streaming_stream_relid_index, 3229, on streaming_stream using btree(relid oid_ops)); +#define StreamingStreamRelidIndexId 3229 + +DECLARE_UNIQUE_INDEX(streaming_cont_query_relid_index, 3230, on streaming_cont_query using btree(relid oid_ops)); +#define StreamingContQueryRelidIndexId 3230 +DECLARE_UNIQUE_INDEX(streaming_cont_query_defrelid_index, 3231, on streaming_cont_query using btree(defrelid oid_ops)); +#define StreamingContQueryDefrelidIndexId 3231 +DECLARE_UNIQUE_INDEX(streaming_cont_query_id_index, 3232, on streaming_cont_query using btree(id int4_ops)); +#define StreamingContQueryIdIndexId 3232 +DECLARE_UNIQUE_INDEX(streaming_cont_query_oid_index, 3233, on streaming_cont_query using btree(oid oid_ops)); +#define StreamingContQueryOidIndexId 3233 +DECLARE_INDEX(streaming_cont_query_matrelid_index, 3234, on streaming_cont_query using btree(matrelid oid_ops)); +#define StreamingContQueryMatrelidIndexId 3234 +DECLARE_INDEX(streaming_cont_query_lookupidxid_index, 3235, on streaming_cont_query using btree(lookupidxid oid_ops)); +#define StreamingContQueryLookupidxidIndexId 3235 +DECLARE_INDEX(streaming_cont_query_schema_change_index, 3236, on streaming_cont_query using btree(matrelid oid_ops, active bool_ops)); +#define StreamingContQuerySchemaChangeIndexId 3236 +DECLARE_INDEX(streaming_gather_agg_index, 3237, on pg_aggregate using btree(aggtransfn oid_ops, aggcollectfn oid_ops, aggfinalfn oid_ops)); +#define StreamingGatherAggIndexId 3237 + +/* Add index of contquery oid for streaming_reaper_status */ +DECLARE_UNIQUE_INDEX(streaming_reaper_status_id_index, 9995, on streaming_reaper_status using btree(id int4_ops)); +#define StreamingReaperStatusOidIndexId 9995 +DECLARE_UNIQUE_INDEX(streaming_reaper_status_oid_index, 9999, on streaming_reaper_status using btree(oid oid_ops)); +#define StreamingCQReaperStatusOidIndexId 9999 + +/* Add index of table oid for gs_encrypted_columns */ +DECLARE_UNIQUE_INDEX(gs_encrypted_columns_oid_index, 9701, on gs_encrypted_columns using btree(oid oid_ops)); +#define GsSecEncryptedColumnsOidIndexId 9701 +DECLARE_UNIQUE_INDEX(gs_encrypted_columns_rel_id_column_name_index, 9702, on gs_encrypted_columns using btree(rel_id oid_ops, column_name name_ops)); +#define GsSecEncryptedColumnsRelidColumnnameIndexId 9702 + +/* Add index of table oid for gs_client_global_keys */ +DECLARE_UNIQUE_INDEX(gs_client_global_keys_oid_index, 9711, on gs_client_global_keys using btree(oid oid_ops)); +#define ClientLogicGlobalSettingsOidIndexId 9711 +DECLARE_UNIQUE_INDEX(gs_client_global_keys_name_index, 9712, on gs_client_global_keys using btree(global_key_name name_ops, key_namespace oid_ops)); +#define ClientLogicGlobalSettingsNameIndexId 9712 + +/* Add index of table oid for gs_column_keys */ +DECLARE_UNIQUE_INDEX(gs_column_keys_oid_index, 9721, on gs_column_keys using btree(oid oid_ops)); +#define ClientLogicColumnSettingsOidIndexId 9721 +DECLARE_UNIQUE_INDEX(gs_column_keys_name_index, 9722, on gs_column_keys using btree(column_key_name name_ops, key_namespace oid_ops)); +#define ClientLogicColumnSettingsNameIndexId 9722 +DECLARE_UNIQUE_INDEX(gs_column_keys_distributed_id_index, 9723, on gs_column_keys using btree(column_key_distributed_id oid_ops)); +#define ClientLogicColumnSettingDistributedIdIndexId 9723 + +/* Add index of table oid for gs_client_global_keys_args */ +DECLARE_UNIQUE_INDEX(gs_client_global_keys_args_oid_index, 9731, on gs_client_global_keys_args using btree(oid oid_ops)); +#define ClientLogicGlobalSettingsArgsOidIndexId 9731 + +/* Add index of table oid for gs_sec_column_encrption_keys_args */ +DECLARE_UNIQUE_INDEX(gs_column_keys_args_oid_index, 9741, on gs_column_keys_args using btree(oid oid_ops)); +#define ClientLogicColumnSettingsArgsOidIndexId 9741 +/* Add index for matview catalog*/ +DECLARE_UNIQUE_INDEX(gs_matview_oid_index, 9991, on gs_matview using btree(oid oid_ops)); +#define GsMatviewOidIndexId 9991 +DECLARE_UNIQUE_INDEX(gs_matviewdep_oid_index, 9992, on gs_matview_dependency using btree(oid oid_ops)); +#define GsMatviewDepOidIndexId 9992 + + +/* Add index of table model name for gs_opt_model */ +DECLARE_UNIQUE_INDEX(gs_opt_model_name_index, 9997, on gs_opt_model using btree(model_name name_ops)); +#define GsOPTModelNameIndexId 9997 + +/* last step of initialization script: build the indexes declared above */ +BUILD_INDICES + +#endif /* INDEXING_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/namespace.h postgresql-hll-2.14/include/include/catalog/namespace.h --- postgresql-hll-2.14_old/include/include/catalog/namespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/namespace.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,222 @@ +/* ------------------------------------------------------------------------- + * + * namespace.h + * prototypes for functions in backend/catalog/namespace.c + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/namespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NAMESPACE_H +#define NAMESPACE_H + +#include "access/htup.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "lib/stringinfo.h" + + +/* + * This structure holds a list of possible functions or operators + * found by namespace lookup. Each function/operator is identified + * by OID and by argument types; the list must be pruned by type + * resolution rules that are embodied in the parser, not here. + * See FuncnameGetCandidates's comments for more info. + */ +typedef struct _FuncCandidateList +{ + struct _FuncCandidateList *next; + int pathpos; /* for internal use of namespace lookup */ + Oid oid; /* the function or operator's OID */ + int nargs; /* number of arg types returned */ + int nvargs; /* number of args to become variadic array */ + int ndargs; /* number of defaulted args */ + int *argnumbers; /* args' positional indexes, if named call */ + Oid refSynOid; /* referenced synonym's OID if mapping successfully, and drop it when view decoupling */ + Oid args[FLEXIBLE_ARRAY_MEMBER]; /* arg types --- VARIABLE LENGTH ARRAY */ +} *FuncCandidateList; /* VARIABLE LENGTH STRUCT */ + +#define MinSizeOfFuncCandidateList offsetof(struct _FuncCandidateList, args) + +typedef struct _KeyCandidateList { + struct _KeyCandidateList *next; + int pathpos; /* for internal use of namespace lookup */ + Oid oid; /* the function or operator's OID */ +} *KeyCandidateList; /* VARIABLE LENGTH STRUCT */ + +#define SEARCH_PATH_GUC_NAME "search_path" +#define CURRENT_SCHEMA_GUC_NAME "current_schema" +#define SCHEMA_TEMP_NAME "pg_temp" +#define SCHEMA_CATALOG_NAME "pg_catalog" + +/* + * Structure for xxxOverrideSearchPath functions + */ +typedef struct OverrideSearchPath +{ + List *schemas; /* OIDs of explicitly named schemas */ + bool addCatalog; /* implicitly prepend pg_catalog? */ + bool addTemp; /* implicitly prepend temp schema? */ + bool addUser; /* implicitly postfix $user */ +} OverrideSearchPath; + +/* Override requests are remembered in a stack of OverrideStackEntry structs */ + +typedef struct +{ + List *searchPath; /* the desired search path */ + Oid creationNamespace; /* the desired creation namespace */ + int nestLevel; /* subtransaction nesting level */ + bool inProcedure; /* is true if in plpgsql */ +} OverrideStackEntry; + +typedef void (*RangeVarGetRelidCallback) (const RangeVar *relation, Oid relId, + Oid oldRelId, bool target_is_partition, void *callback_arg); + +#define RangeVarGetRelid(relation, lockmode, missing_ok) \ + RangeVarGetRelidExtended(relation, lockmode, missing_ok, false, false, false, NULL, NULL, NULL, NULL) + +#define isTempNamespaceName(name) \ + (strncasecmp((name), "pg_temp_", 8) == 0) + +#define isTempNamespaceNameWithQuote(name) \ + (strncasecmp((name), "\"pg_temp_", 9) == 0) + +#define isToastTempNamespaceName(name) \ + (strncasecmp((name), "pg_toast_temp_", 14) == 0) + +#define IS_TEMP_NAMESPACE(name) \ + (strncasecmp((name), "pg_temp", 7) == 0) + +#define IS_CATALOG_NAMESPACE(name) \ + (strncasecmp((name), "pg_catalog", 10) == 0) + +extern Oid RangeVarGetRelidExtended(const RangeVar *relation, + LOCKMODE lockmode, bool missing_ok, bool nowait, bool target_is_partition, + bool isSupportSynonym, + RangeVarGetRelidCallback callback, + void *callback_arg, + StringInfo detailInfo = NULL, + Oid *refSynOid = NULL); +extern Oid RangeVarGetCreationNamespace(const RangeVar *newRelation); +extern Oid RangeVarGetAndCheckCreationNamespace(RangeVar *newRelation, + LOCKMODE lockmode, + Oid *existing_relation_id); +extern void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid); +extern Oid RelnameGetRelid(const char *relname, StringInfo detailInfo = NULL); +extern char* RelnameGetRelidExtended(const char *relname, Oid *relOid, Oid *refSynOid = NULL, + StringInfo detailInfo = NULL); +extern bool RelationIsVisible(Oid relid); + +extern Oid TypenameGetTypid(const char *typname); +extern bool TypeIsVisible(Oid typid); + +extern void SetTempFromSearchPath(List* namelist); + + +extern FuncCandidateList FuncnameGetCandidates(List *names, + int nargs, List *argnames, + bool expand_variadic, + bool expand_defaults, + bool func_create, + bool include_out = false); + +extern bool FunctionIsVisible(Oid funcid); + +extern Oid OpernameGetOprid(List *names, Oid oprleft, Oid oprright); +extern FuncCandidateList OpernameGetCandidates(List *names, char oprkind); +extern bool OperatorIsVisible(Oid oprid); + +extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname); +extern bool OpclassIsVisible(Oid opcid); + +extern Oid OpfamilynameGetOpfid(Oid amid, const char *opfname); +extern bool OpfamilyIsVisible(Oid opfid); + +extern Oid CollationGetCollid(const char *collname); +extern bool CollationIsVisible(Oid collid); + +extern Oid ConversionGetConid(const char *conname); +extern bool ConversionIsVisible(Oid conid); + +extern Oid get_ts_parser_oid(List *names, bool missing_ok); +extern bool TSParserIsVisible(Oid prsId); + +extern Oid get_ts_dict_oid(List *names, bool missing_ok); +extern bool TSDictionaryIsVisible(Oid dictId); + +extern Oid get_ts_template_oid(List *names, bool missing_ok); +extern bool TSTemplateIsVisible(Oid tmplId); + +extern Oid get_ts_config_oid(List *names, bool missing_ok); +extern bool TSConfigIsVisible(Oid cfgid); + +extern void DeconstructQualifiedName(const List *names, + char **nspname_p, + char **objname_p); +extern Oid LookupNamespaceNoError(const char *nspname); +extern Oid LookupExplicitNamespace(const char *nspname); +extern Oid get_namespace_oid(const char *nspname, bool missing_ok); +extern Oid SchemaNameGetSchemaOid(const char *schemaname, bool missing_ok = false); +extern Oid GetOidBySchemaName(bool missing_ok = false); +extern Oid LookupCreationNamespace(const char *nspname); +extern void CheckSetNamespace(Oid oldNspOid, Oid nspOid, Oid classid, + Oid objid); +extern Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p); +extern RangeVar *makeRangeVarFromNameList(List *names); +extern char *NameListToString(const List *names); +extern char *NameListToQuotedString(List *names); + +extern bool isTempNamespace(Oid namespaceId); +extern bool isTempToastNamespace(Oid namespaceId); +extern bool isTempOrToastNamespace(Oid namespaceId); +extern bool isAnyTempNamespace(Oid namespaceId); +extern bool isOtherTempNamespace(Oid namespaceId); +extern Oid GetTempToastNamespace(void); +extern void ResetTempTableNamespace(void); + +extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); +extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path); +extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path); +extern void PushOverrideSearchPath(OverrideSearchPath *newpath, bool inProcedure=false); +extern void PopOverrideSearchPath(void); +extern void AddTmpNspToOverrideSearchPath(Oid tmpnspId); +extern void RemoveTmpNspFromSearchPath(Oid tmpnspId); + +extern Oid get_collation_oid(List *collname, bool missing_ok); +extern Oid get_conversion_oid(List *conname, bool missing_ok); +extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding); + +/* initialization & transaction cleanup code */ +extern void InitializeSearchPath(void); +extern void AtEOXact_Namespace(bool isCommit); +extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid, + SubTransactionId parentSubid); + + +extern List *fetch_search_path(bool includeImplicit); +extern int fetch_search_path_array(Oid *sarray, int sarray_len); +extern Oid get_my_temp_schema(); + +extern void FetchDefaultArgumentPos(int **defpos, int2vector *adefpos, + const char *argmodes, int pronallargs); +extern Oid GetUserIdFromNspId(Oid nspid, bool is_securityadmin = false); + +extern void SetTempNamespace(Node *stmt, Oid namespaceOid); +extern void setTempToastNspName(); +extern void validateTempRelation(Relation rel); +extern bool checkGroup(Oid relid, bool missing_ok); + +extern bool validateTempNamespace(Oid tmepNspId); + +extern bool IsPackageFunction(List* funcname); + +extern void recomputeNamespacePath(StringInfo error_info = NULL); +extern KeyCandidateList GlobalSettingGetCandidates(List *names, bool); +extern KeyCandidateList CeknameGetCandidates(List *names, bool); +#endif /* NAMESPACE_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/objectaccess.h postgresql-hll-2.14/include/include/catalog/objectaccess.h --- postgresql-hll-2.14_old/include/include/catalog/objectaccess.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/objectaccess.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,63 @@ +/* + * objectaccess.h + * + * Object access hooks. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + */ + +#ifndef OBJECTACCESS_H +#define OBJECTACCESS_H + +/* + * Object access hooks are intended to be called just before or just after + * performing certain actions on a SQL object. This is intended as + * infrastructure for security or logging pluggins. + * + * OAT_POST_CREATE should be invoked just after the object is created. + * Typically, this is done after inserting the primary catalog records and + * associated dependencies. + * + * OAT_DROP should be invoked just before deletion of objects; typically + * deleteOneObject(). Its arguments are packed within ObjectAccessDrop. + * + * Other types may be added in the future. + */ +typedef enum ObjectAccessType +{ + OAT_POST_CREATE, + OAT_DROP, +} ObjectAccessType; + +/* + * Arguments of OAT_DROP event + */ +typedef struct +{ + /* + * Flags to inform extensions the context of this deletion. Also see + * PERFORM_DELETION_* in dependency.h + */ + int dropflags; +} ObjectAccessDrop; + +/* + * Hook, and a macro to invoke it. + */ +typedef void (*object_access_hook_type) (ObjectAccessType access, + Oid classId, + Oid objectId, + int subId, + void *arg); + +extern THR_LOCAL PGDLLIMPORT object_access_hook_type object_access_hook; + +#define InvokeObjectAccessHook(access,classId,objectId,subId,arg) \ + do { \ + if (object_access_hook) \ + (*object_access_hook)((access),(classId), \ + (objectId),(subId),(arg)); \ + } while(0) + +#endif /* OBJECTACCESS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/objectaddress.h postgresql-hll-2.14/include/include/catalog/objectaddress.h --- postgresql-hll-2.14_old/include/include/catalog/objectaddress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/objectaddress.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,40 @@ +/* ------------------------------------------------------------------------- + * + * objectaddress.h + * functions for working with object addresses + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/objectaddress.h + * + * ------------------------------------------------------------------------- + */ +#ifndef OBJECTADDRESS_H +#define OBJECTADDRESS_H + +#include "nodes/parsenodes.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +/* + * An ObjectAddress represents a database object of any type. + */ +typedef struct ObjectAddress +{ + Oid classId; /* Class Id from pg_class */ + Oid objectId; /* OID of the object */ + int32 objectSubId; /* Subitem within object (eg column), or 0 */ +} ObjectAddress; + +extern ObjectAddress get_object_address(ObjectType objtype, List *objname, + List *objargs, Relation *relp, + LOCKMODE lockmode, bool missing_ok); + +extern void check_object_ownership(Oid roleid, + ObjectType objtype, ObjectAddress address, + List *objname, List *objargs, Relation relation); + +extern Oid get_object_namespace(const ObjectAddress *address); + +#endif /* PARSE_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_aggregate.h postgresql-hll-2.14/include/include/catalog/pg_aggregate.h --- postgresql-hll-2.14_old/include/include/catalog/pg_aggregate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_aggregate.h 2020-12-12 17:06:43.151346800 +0800 @@ -0,0 +1,489 @@ +/* ------------------------------------------------------------------------- + * + * pg_aggregate.h + * definition of the system "aggregate" relation (pg_aggregate) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_aggregate.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AGGREGATE_H +#define PG_AGGREGATE_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------------------------------------------------------- + * pg_aggregate definition. + * + * cpp turns this into typedef struct FormData_pg_aggregate + * +#ifdef PGXC + * Derived from pg_aggregate, added collection function, collection data + * type and collection initial value. +#endif + * + * aggfnoid pg_proc OID of the aggregate itself + * aggtransfn transition function +#ifdef PGXC + * aggcollectfn collectition function +#endif + * aggfinalfn final function (0 if none) + * aggsortop associated sort operator (0 if none) + * aggtranstype type of aggregate's transition (state) data + * agginitval initial value for transition state (can be NULL) +#ifdef PGXC + * agginitcollect initial value for collection state (can be NULL) +#endif + * ---------------------------------------------------------------- + */ +#define AggregateRelationId 2600 +#define AggregateRelation_Rowtype_Id 11326 + +CATALOG(pg_aggregate,2600) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + regproc aggfnoid; + regproc aggtransfn; + regproc aggcollectfn; /* PGXC */ + regproc aggfinalfn; + Oid aggsortop; + Oid aggtranstype; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text agginitval; + text agginitcollect; /* PGXC, VARIABLE LENGTH FIELD */ +#endif + char aggkind; + int2 aggnumdirectargs; +} FormData_pg_aggregate; + +/* ---------------- + * Form_pg_aggregate corresponds to a pointer to a tuple with + * the format of pg_aggregate relation. + * ---------------- + */ +typedef FormData_pg_aggregate *Form_pg_aggregate; + +/* ---------------- + * compiler constants for pg_aggregate + * ---------------- + */ + +#ifdef PGXC +#define Natts_pg_aggregate 10 +#define Anum_pg_aggregate_aggfnoid 1 +#define Anum_pg_aggregate_aggtransfn 2 +#define Anum_pg_aggregate_aggcollectfn 3 +#define Anum_pg_aggregate_aggfinalfn 4 +#define Anum_pg_aggregate_aggsortop 5 +#define Anum_pg_aggregate_aggtranstype 6 +#define Anum_pg_aggregate_agginitval 7 +#define Anum_pg_aggregate_agginitcollect 8 +#define Anum_pg_aggregate_aggkind 9 +#define Anum_pg_aggregate_aggnumdirectargs 10 +#endif + +/* + * Symbolic values for aggkind column. We distinguish normal aggregates + * from ordered-set aggregates (which have two sets of arguments, namely + * direct and aggregated arguments). + */ +#define AGGKIND_NORMAL 'n' +#define AGGKIND_DEFAULT 'n' +#define AGGKIND_ORDERED_SET 'o' +#define AGGKIND_IS_ORDERED_SET(kind) ((kind) == AGGKIND_ORDERED_SET) +#define AGGNUMDIRECTARGS_DEFAULT 0 +/* ---------------- + * initial contents of pg_aggregate + * --------------- + */ + +/* avg */ +#ifdef PGXC +DATA(insert ( 2100 int8_avg_accum numeric_avg_collect numeric_avg 0 1231 "{0,0}" "{0,0}" n 0)); +#define INT8AVGFUNCOID 2100 +DATA(insert ( 2101 int4_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT4AVGFUNCOID 2101 +DATA(insert ( 2102 int2_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT2AVGFUNCOID 2102 +DATA(insert ( 5537 int1_avg_accum int8_avg_collect int8_avg 0 1016 "{0,0}" "{0,0}" n 0)); +#define INT1AVGFUNCOID 5537 +DATA(insert ( 2103 numeric_avg_accum numeric_avg_collect numeric_avg 0 1231 "{0,0}" "{0,0}" n 0)); +#define NUMERICAVGFUNCOID 2103 +DATA(insert ( 2104 float4_accum float8_collect float8_avg 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +#define FLOAT4AVGFUNCOID 2104 +DATA(insert ( 2105 float8_accum float8_collect float8_avg 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +#define FLOAT8AVGFUNCOID 2105 +DATA(insert ( 2106 interval_accum interval_collect interval_avg 0 1187 "{0 second,0 second}" "{0 second,0 second}" n 0)); +#define INTERVALAGGAVGFUNCOID 2106 +#endif + +/* sum */ +#ifdef PGXC +DATA(insert ( 2107 int8_sum numeric_add - 0 1700 _null_ _null_ n 0)); +#define INT8SUMFUNCOID 2107 +DATA(insert ( 2108 int4_sum int8_sum_to_int8 - 0 20 _null_ _null_ n 0)); +#define INT4SUMFUNCOID 2108 +DATA(insert ( 2109 int2_sum int8_sum_to_int8 - 0 20 _null_ _null_ n 0)); +#define INT2SUMFUNCOID 2109 +DATA(insert ( 2110 float4pl float4pl - 0 700 _null_ _null_ n 0)); +DATA(insert ( 2111 float8pl float8pl - 0 701 _null_ _null_ n 0)); +DATA(insert ( 2112 cash_pl cash_pl - 0 790 _null_ _null_ n 0)); +DATA(insert ( 2113 interval_pl interval_pl - 0 1186 _null_ _null_ n 0)); +DATA(insert ( 2114 numeric_add numeric_add - 0 1700 _null_ _null_ n 0)); +#define NUMERICSUMFUNCOID 2114 +#endif + +/* max */ +#ifdef PGXC +DATA(insert ( 2115 int8larger int8larger - 413 20 _null_ _null_ n 0)); +#define INT8LARGERFUNCOID 2115 +DATA(insert ( 2116 int4larger int4larger - 521 23 _null_ _null_ n 0)); +#define INT4LARGERFUNCOID 2116 +DATA(insert ( 2117 int2larger int2larger - 520 21 _null_ _null_ n 0)); +#define INT2LARGERFUNCOID 2117 +DATA(insert ( 5538 int1larger int1larger - 5517 5545 _null_ _null_ n 0)); +DATA(insert ( 2118 oidlarger oidlarger - 610 26 _null_ _null_ n 0)); +DATA(insert ( 2119 float4larger float4larger - 623 700 _null_ _null_ n 0)); +DATA(insert ( 2120 float8larger float8larger - 674 701 _null_ _null_ n 0)); +DATA(insert ( 2121 int4larger int4larger - 563 702 _null_ _null_ n 0)); +DATA(insert ( 2122 date_larger date_larger - 1097 1082 _null_ _null_ n 0)); +DATA(insert ( 2123 time_larger time_larger - 1112 1083 _null_ _null_ n 0)); +DATA(insert ( 2124 timetz_larger timetz_larger - 1554 1266 _null_ _null_ n 0)); +DATA(insert ( 2125 cashlarger cashlarger - 903 790 _null_ _null_ n 0)); +DATA(insert ( 2126 timestamp_larger timestamp_larger - 2064 1114 _null_ _null_ n 0)); +DATA(insert ( 2127 timestamptz_larger timestamptz_larger - 1324 1184 _null_ _null_ n 0)); +DATA(insert ( 2128 interval_larger interval_larger - 1334 1186 _null_ _null_ n 0)); +DATA(insert ( 2129 text_larger text_larger - 666 25 _null_ _null_ n 0)); +DATA(insert ( 2130 numeric_larger numeric_larger - 1756 1700 _null_ _null_ n 0)); +#define NUMERICLARGERFUNCOID 2130 +DATA(insert ( 2050 array_larger array_larger - 1073 2277 _null_ _null_ n 0)); +DATA(insert ( 2244 bpchar_larger bpchar_larger - 1060 1042 _null_ _null_ n 0)); +DATA(insert ( 2797 tidlarger tidlarger - 2800 27 _null_ _null_ n 0)); +DATA(insert ( 3526 enum_larger enum_larger - 3519 3500 _null_ _null_ n 0)); +DATA(insert ( 9010 smalldatetime_larger smalldatetime_larger - 5554 9003 _null_ _null_ n 0)); +DATA(insert ( 9009 smalldatetime_smaller smalldatetime_smaller - 5552 9003 _null_ _null_ n 0)); +#endif + +/* min */ +#ifdef PGXC +DATA(insert ( 2131 int8smaller int8smaller - 412 20 _null_ _null_ n 0)); +#define INT8SMALLERFUNCOID 2131 +DATA(insert ( 2132 int4smaller int4smaller - 97 23 _null_ _null_ n 0)); +#define INT4SMALLERFUNCOID 2132 +DATA(insert ( 2133 int2smaller int2smaller - 95 21 _null_ _null_ n 0)); +#define INT2SMALLERFUNCOID 2133 +DATA(insert ( 2134 oidsmaller oidsmaller - 609 26 _null_ _null_ n 0)); +DATA(insert ( 2135 float4smaller float4smaller - 622 700 _null_ _null_ n 0)); +DATA(insert ( 2136 float8smaller float8smaller - 672 701 _null_ _null_ n 0)); +DATA(insert ( 2137 int4smaller int4smaller - 562 702 _null_ _null_ n 0)); +DATA(insert ( 2138 date_smaller date_smaller - 1095 1082 _null_ _null_ n 0)); +DATA(insert ( 2139 time_smaller time_smaller - 1110 1083 _null_ _null_ n 0)); +DATA(insert ( 2140 timetz_smaller timetz_smaller - 1552 1266 _null_ _null_ n 0)); +DATA(insert ( 2141 cashsmaller cashsmaller - 902 790 _null_ _null_ n 0)); +DATA(insert ( 2142 timestamp_smaller timestamp_smaller - 2062 1114 _null_ _null_ n 0)); +DATA(insert ( 2143 timestamptz_smaller timestamptz_smaller - 1322 1184 _null_ _null_ n 0)); +DATA(insert ( 2144 interval_smaller interval_smaller - 1332 1186 _null_ _null_ n 0)); +DATA(insert ( 2145 text_smaller text_smaller - 664 25 _null_ _null_ n 0)); +DATA(insert ( 2146 numeric_smaller numeric_smaller - 1754 1700 _null_ _null_ n 0)); +#define NUMERICSMALLERFUNCOID 2146 +DATA(insert ( 2051 array_smaller array_smaller - 1072 2277 _null_ _null_ n 0)); +DATA(insert ( 2245 bpchar_smaller bpchar_smaller - 1058 1042 _null_ _null_ n 0)); +DATA(insert ( 2798 tidsmaller tidsmaller - 2799 27 _null_ _null_ n 0)); +DATA(insert ( 3527 enum_smaller enum_smaller - 3518 3500 _null_ _null_ n 0)); +#endif + +/* count */ +/* Final function is data type conversion function numeric_int8 is referenced by OID because of ambiguous definition in pg_proc */ +#ifdef PGXC +DATA(insert ( 2147 int8inc_any int8_sum_to_int8 - 0 20 "0" "0" n 0)); +DATA(insert ( 2803 int8inc int8_sum_to_int8 - 0 20 "0" "0" n 0)); +#endif + +/* var_pop */ +#ifdef PGXC +DATA(insert ( 2718 int8_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2719 int4_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2720 int2_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2721 float4_accum float8_collect float8_var_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2722 float8_accum float8_collect float8_var_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2723 numeric_accum numeric_collect numeric_var_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* var_samp */ +#ifdef PGXC +DATA(insert ( 2641 int8_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2642 int4_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2643 int2_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2644 float4_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2645 float8_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2646 numeric_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* variance: historical Postgres syntax for var_samp */ +#ifdef PGXC +DATA(insert ( 2148 int8_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2149 int4_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2150 int2_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2151 float4_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2152 float8_accum float8_collect float8_var_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2153 numeric_accum numeric_collect numeric_var_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev_pop */ +#ifdef PGXC +DATA(insert ( 2724 int8_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2725 int4_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2726 int2_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2727 float4_accum float8_collect float8_stddev_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2728 float8_accum float8_collect float8_stddev_pop 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2729 numeric_accum numeric_collect numeric_stddev_pop 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev_samp */ +#ifdef PGXC +DATA(insert ( 2712 int8_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2713 int4_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2714 int2_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2715 float4_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2716 float8_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2717 numeric_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* stddev: historical Postgres syntax for stddev_samp */ +#ifdef PGXC +DATA(insert ( 2154 int8_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2155 int4_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2156 int2_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2157 float4_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2158 float8_accum float8_collect float8_stddev_samp 0 1022 "{0,0,0}" "{0,0,0}" n 0)); +DATA(insert ( 2159 numeric_accum numeric_collect numeric_stddev_samp 0 1231 "{0,0,0}" "{0,0,0}" n 0)); +#endif + +/* SQL2003 binary regression aggregates */ +#ifdef PGXC +DATA(insert ( 2818 int8inc_float8_float8 int8_sum_to_int8 - 0 20 "0" _null_ n 0)); +DATA(insert ( 2819 float8_regr_accum float8_regr_collect float8_regr_sxx 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2820 float8_regr_accum float8_regr_collect float8_regr_syy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2821 float8_regr_accum float8_regr_collect float8_regr_sxy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2822 float8_regr_accum float8_regr_collect float8_regr_avgx 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2823 float8_regr_accum float8_regr_collect float8_regr_avgy 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2824 float8_regr_accum float8_regr_collect float8_regr_r2 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2825 float8_regr_accum float8_regr_collect float8_regr_slope 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2826 float8_regr_accum float8_regr_collect float8_regr_intercept 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2827 float8_regr_accum float8_regr_collect float8_covar_pop 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2828 float8_regr_accum float8_regr_collect float8_covar_samp 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +DATA(insert ( 2829 float8_regr_accum float8_regr_collect float8_corr 0 1022 "{0,0,0,0,0,0}" "{0,0,0,0,0,0}" n 0)); +#endif + +/* boolean-and and boolean-or */ +#ifdef PGXC +DATA(insert ( 2517 booland_statefunc booland_statefunc - 58 16 _null_ _null_ n 0)); +DATA(insert ( 2518 boolor_statefunc boolor_statefunc - 59 16 _null_ _null_ n 0)); +DATA(insert ( 2519 booland_statefunc booland_statefunc - 58 16 _null_ _null_ n 0)); +#endif + +/* bitwise integer */ +#ifdef PGXC +DATA(insert ( 5539 int1and int1and - 0 5545 _null_ _null_ n 0)); +DATA(insert ( 5540 int1or int1or - 0 5545 _null_ _null_ n 0)); +DATA(insert ( 2236 int2and int2and - 0 21 _null_ _null_ n 0)); +DATA(insert ( 2237 int2or int2or - 0 21 _null_ _null_ n 0)); +DATA(insert ( 2238 int4and int4and - 0 23 _null_ _null_ n 0)); +DATA(insert ( 2239 int4or int4or - 0 23 _null_ _null_ n 0)); +DATA(insert ( 2240 int8and int8and - 0 20 _null_ _null_ n 0)); +DATA(insert ( 2241 int8or int8or - 0 20 _null_ _null_ n 0)); +DATA(insert ( 2242 bitand bitand - 0 1560 _null_ _null_ n 0)); +DATA(insert ( 2243 bitor bitor - 0 1560 _null_ _null_ n 0)); +#endif + +/* xml */ +#ifdef PGXC +DATA(insert ( 2901 xmlconcat2 xmlconcat2 - 0 142 _null_ _null_ n 0)); +#endif + +/* array */ +#ifdef PGXC +DATA(insert ( 2335 array_agg_transfn - array_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* text */ +#ifdef PGXC +DATA(insert ( 3538 string_agg_transfn - string_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* checksum */ +#ifdef PGXC +DATA(insert ( 4600 checksumtext_agg_transfn numeric_add - 0 1700 _null_ _null_ n 0)); +#endif + +/* bytea */ +#ifdef PGXC +DATA(insert ( 3545 bytea_string_agg_transfn - bytea_string_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* hll distribute agg */ +DATA(insert ( 4366 hll_add_trans0 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS0_OID 4366 +DATA(insert ( 4380 hll_add_trans1 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS1_OID 4380 +DATA(insert ( 4381 hll_add_trans2 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS2_OID 4381 +DATA(insert ( 4382 hll_add_trans3 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS3_OID 4382 +DATA(insert ( 4383 hll_add_trans4 hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_ADD_TRANS4_OID 4383 +DATA(insert ( 4367 hll_union_trans hll_union_collect hll_pack 0 4370 _null_ _null_ n 0)); +#define HLL_UNION_TRANS_OID 4367 + +/* list */ +#ifdef PGXC +DATA(insert ( 3552 list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter */ +#ifdef PGXC +DATA(insert ( 3554 list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int2) */ +#ifdef PGXC +DATA(insert ( 3556 int2_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int2) */ +#ifdef PGXC +DATA(insert ( 3558 int2_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int4) */ +#ifdef PGXC +DATA(insert ( 3560 int4_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int4) */ +#ifdef PGXC +DATA(insert ( 3562 int4_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (int8) */ +#ifdef PGXC +DATA(insert ( 3564 int8_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (int8) */ +#ifdef PGXC +DATA(insert ( 3566 int8_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (float4) */ +#ifdef PGXC +DATA(insert ( 3568 float4_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (float4) */ +#ifdef PGXC +DATA(insert ( 3570 float4_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (float8) */ +#ifdef PGXC +DATA(insert ( 3572 float8_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (float8) */ +#ifdef PGXC +DATA(insert ( 3574 float8_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (numeric) */ +#ifdef PGXC +DATA(insert ( 3576 numeric_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (numeric) */ +#ifdef PGXC +DATA(insert ( 3578 numeric_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (date) */ +#ifdef PGXC +DATA(insert ( 3580 date_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (date) */ +#ifdef PGXC +DATA(insert ( 3582 date_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (timestamp) */ +#ifdef PGXC +DATA(insert ( 3584 timestamp_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (timestamptz) */ +#ifdef PGXC +DATA(insert ( 3586 timestamp_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (timestamptz) */ +#ifdef PGXC +DATA(insert ( 3588 timestamptz_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (timestamptz) */ +#ifdef PGXC +DATA(insert ( 3590 timestamptz_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list (interval) */ +#ifdef PGXC +DATA(insert ( 4506 interval_list_agg_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* list without delimiter (interval) */ +#ifdef PGXC +DATA(insert ( 4508 interval_list_agg_noarg2_transfn - list_agg_finalfn 0 2281 _null_ _null_ n 0)); +#endif + +/* ordered-set aggregates XXX shall we add collect funcs? */ +DATA(insert ( 4452 ordered_set_transition - percentile_cont_float8_final 0 2281 _null_ _null_ o 1)); +DATA(insert ( 4454 ordered_set_transition - percentile_cont_interval_final 0 2281 _null_ _null_ o 1)); +DATA(insert (4461 ordered_set_transition - mode_final 0 2281 _null_ _null_ o 0)); + +DATA(insert (5555 median_transfn - median_float8_finalfn 0 2281 _null_ _null_ n 0)); +DATA(insert (5556 median_transfn - median_interval_finalfn 0 2281 _null_ _null_ n 0)); + +/* + * prototypes for functions in pg_aggregate.c + */ +extern void AggregateCreate(const char *aggName, + Oid aggNamespace, + char aggKind, + Oid *aggArgTypes, + int numArgs, + List *aggtransfnName, +#ifdef PGXC + List *aggcollectfnName, +#endif + List *aggfinalfnName, + List *aggsortopName, + Oid aggTransType, +#ifdef PGXC + const char *agginitval, + const char *agginitcollect); +#else + const char *agginitval); +#endif + +#endif /* PG_AGGREGATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_am.h postgresql-hll-2.14/include/include/catalog/pg_am.h --- postgresql-hll-2.14_old/include/include/catalog/pg_am.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_am.h 2020-12-12 17:06:43.152346813 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * pg_am.h + * definition of the system "access method" relation (pg_am) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_am.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AM_H +#define PG_AM_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_am definition. cpp turns this into + * typedef struct FormData_pg_am + * ---------------- + */ +#define AccessMethodRelationId 2601 +#define AccessMethodRelation_Rowtype_Id 10164 + +CATALOG(pg_am,2601) BKI_SCHEMA_MACRO +{ + NameData amname; /* access method name */ + int2 amstrategies; /* total number of strategies (operators) by + * which we can traverse/search this AM. Zero + * if AM does not have a fixed set of strategy + * assignments. */ + int2 amsupport; /* total number of support functions that this + * AM uses */ + bool amcanorder; /* does AM support order by column value? */ + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amcanbackward; /* does AM support backward scan? */ + bool amcanunique; /* does AM support UNIQUE indexes? */ + bool amcanmulticol; /* does AM support multi-column indexes? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amstorage; /* can storage type differ from column type? */ + bool amclusterable; /* does AM support cluster command? */ + bool ampredlocks; /* does AM handle predicate locks? */ + Oid amkeytype; /* type of data in index, or InvalidOid */ + regproc aminsert; /* "insert this tuple" function */ + regproc ambeginscan; /* "prepare for index scan" function */ + regproc amgettuple; /* "next valid tuple" function, or 0 */ + regproc amgetbitmap; /* "fetch all valid tuples" function, or 0 */ + regproc amrescan; /* "(re)start index scan" function */ + regproc amendscan; /* "end index scan" function */ + regproc ammarkpos; /* "mark current scan position" function */ + regproc amrestrpos; /* "restore marked scan position" function */ + regproc ammerge; /* "merge several index relation into one" function */ + regproc ambuild; /* "build new index" function */ + regproc ambuildempty; /* "build empty index" function */ + regproc ambulkdelete; /* bulk-delete function */ + regproc amvacuumcleanup; /* post-VACUUM cleanup function */ + regproc amcanreturn; /* can indexscan return IndexTuples? */ + regproc amcostestimate; /* estimate cost of an indexscan */ + regproc amoptions; /* parse AM-specific parameters */ +} FormData_pg_am; + +/* ---------------- + * Form_pg_am corresponds to a pointer to a tuple with + * the format of pg_am relation. + * ---------------- + */ +typedef FormData_pg_am *Form_pg_am; + +/* ---------------- + * compiler constants for pg_am + * ---------------- + */ +#define Natts_pg_am 31 +#define Anum_pg_am_amname 1 +#define Anum_pg_am_amstrategies 2 +#define Anum_pg_am_amsupport 3 +#define Anum_pg_am_amcanorder 4 +#define Anum_pg_am_amcanorderbyop 5 +#define Anum_pg_am_amcanbackward 6 +#define Anum_pg_am_amcanunique 7 +#define Anum_pg_am_amcanmulticol 8 +#define Anum_pg_am_amoptionalkey 9 +#define Anum_pg_am_amsearcharray 10 +#define Anum_pg_am_amsearchnulls 11 +#define Anum_pg_am_amstorage 12 +#define Anum_pg_am_amclusterable 13 +#define Anum_pg_am_ampredlocks 14 +#define Anum_pg_am_amkeytype 15 +#define Anum_pg_am_aminsert 16 +#define Anum_pg_am_ambeginscan 17 +#define Anum_pg_am_amgettuple 18 +#define Anum_pg_am_amgetbitmap 19 +#define Anum_pg_am_amrescan 20 +#define Anum_pg_am_amendscan 21 +#define Anum_pg_am_ammarkpos 22 +#define Anum_pg_am_amrestrpos 23 +#define Anum_pg_am_ammerge 24 +#define Anum_pg_am_ambuild 25 +#define Anum_pg_am_ambuildempty 26 +#define Anum_pg_am_ambulkdelete 27 +#define Anum_pg_am_amvacuumcleanup 28 +#define Anum_pg_am_amcanreturn 29 +#define Anum_pg_am_amcostestimate 30 +#define Anum_pg_am_amoptions 31 + +/* ---------------- + * initial contents of pg_am + * ---------------- + */ + +DATA(insert OID = 403 ( btree 5 2 t f t t t t t t f t t 0 btinsert btbeginscan btgettuple btgetbitmap btrescan btendscan btmarkpos btrestrpos btmerge btbuild btbuildempty btbulkdelete btvacuumcleanup btcanreturn btcostestimate btoptions )); +DESCR("b-tree index access method"); +#define BTREE_AM_OID 403 +DATA(insert OID = 405 ( hash 1 1 f f t f f f f f f f f 23 hashinsert hashbeginscan hashgettuple hashgetbitmap hashrescan hashendscan hashmarkpos hashrestrpos hashmerge hashbuild hashbuildempty hashbulkdelete hashvacuumcleanup - hashcostestimate hashoptions )); +DESCR("hash index access method"); +#define HASH_AM_OID 405 +DATA(insert OID = 783 ( gist 0 8 f t f f t t f t t t f 0 gistinsert gistbeginscan gistgettuple gistgetbitmap gistrescan gistendscan gistmarkpos gistrestrpos gistmerge gistbuild gistbuildempty gistbulkdelete gistvacuumcleanup - gistcostestimate gistoptions )); +DESCR("GiST index access method"); +#define GIST_AM_OID 783 +DATA(insert OID = 2742 ( gin 0 6 f f f f t t f f t f f 0 gininsert ginbeginscan - gingetbitmap ginrescan ginendscan ginmarkpos ginrestrpos ginmerge ginbuild ginbuildempty ginbulkdelete ginvacuumcleanup - gincostestimate ginoptions )); +DESCR("GIN index access method"); +#define GIN_AM_OID 2742 +DATA(insert OID = 4000 ( spgist 0 5 f f f f f t f t f f f 0 spginsert spgbeginscan spggettuple spggetbitmap spgrescan spgendscan spgmarkpos spgrestrpos spgmerge spgbuild spgbuildempty spgbulkdelete spgvacuumcleanup spgcanreturn spgcostestimate spgoptions )); +DESCR("SP-GiST index access method"); +#define SPGIST_AM_OID 4000 + +DATA(insert OID = 4039 ( psort 5 1 f f f f t t f t f f f 0 - - psortgettuple psortgetbitmap - - - - - psortbuild - - - psortcanreturn psortcostestimate psortoptions )); +DESCR("psort index access method"); +#define PSORT_AM_OID 4039 + +DATA(insert OID = 4239 ( cbtree 5 1 f f f f t t f t f f t 0 btinsert btbeginscan cbtreegettuple cbtreegetbitmap btrescan btendscan - - - cbtreebuild btbuildempty - - cbtreecanreturn cbtreecostestimate cbtreeoptions )); +DESCR("cstore btree index access method"); +#define CBTREE_AM_OID 4239 + +DATA(insert OID = 4444 ( cgin 0 6 f f f f t t f f t f f 0 gininsert ginbeginscan - cgingetbitmap ginrescan ginendscan ginmarkpos ginrestrpos ginmerge cginbuild ginbuildempty ginbulkdelete ginvacuumcleanup - gincostestimate ginoptions )); +DESCR("cstore GIN index access method"); +#define CGIN_AM_OID 4444 + +#endif /* PG_AM_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_amop.h postgresql-hll-2.14/include/include/catalog/pg_amop.h --- postgresql-hll-2.14_old/include/include/catalog/pg_amop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_amop.h 2020-12-12 17:06:43.152346813 +0800 @@ -0,0 +1,1233 @@ +/* ------------------------------------------------------------------------- + * + * pg_amop.h + * definition of the system "amop" relation (pg_amop) + * along with the relation's initial contents. + * + * The amop table identifies the operators associated with each index operator + * family and operator class (classes are subsets of families). An associated + * operator can be either a search operator or an ordering operator, as + * identified by amoppurpose. + * + * The primary key for this table is . amoplefttype and amoprighttype are just copies of the + * operator's oprleft/oprright, ie its declared input data types. The + * "default" operators for a particular opclass within the family are those + * with amoplefttype = amoprighttype = opclass's opcintype. An opfamily may + * also contain other operators, typically cross-data-type operators. All the + * operators within a family are supposed to be compatible, in a way that is + * defined by each individual index AM. + * + * We also keep a unique index on , so that + * we can use a syscache to quickly answer questions of the form "is this + * operator in this opfamily, and if so what are its semantics with respect to + * the family?" This implies that the same operator cannot be listed for + * multiple strategy numbers within a single opfamily, with the exception that + * it's possible to list it for both search and ordering purposes (with + * different strategy numbers for the two purposes). + * + * amopmethod is a copy of the owning opfamily's opfmethod field. This is an + * intentional denormalization of the catalogs to buy lookup speed. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_amop.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AMOP_H +#define PG_AMOP_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_amop definition. cpp turns this into + * typedef struct FormData_pg_amop + * ---------------- + */ +#define AccessMethodOperatorRelationId 2602 +#define AccessMethodOperatorRelation_Rowtype_Id 10165 + +CATALOG(pg_amop,2602) BKI_SCHEMA_MACRO +{ + Oid amopfamily; /* the index opfamily this entry is for */ + Oid amoplefttype; /* operator's left input data type */ + Oid amoprighttype; /* operator's right input data type */ + int2 amopstrategy; /* operator strategy number */ + char amoppurpose; /* is operator for 's'earch or 'o'rdering? */ + Oid amopopr; /* the operator's pg_operator OID */ + Oid amopmethod; /* the index access method this entry is for */ + Oid amopsortfamily; /* ordering opfamily OID, or 0 if search op */ +} FormData_pg_amop; + +/* allowed values of amoppurpose: */ +#define AMOP_SEARCH 's' /* operator is for search */ +#define AMOP_ORDER 'o' /* operator is for ordering */ + +/* ---------------- + * Form_pg_amop corresponds to a pointer to a tuple with + * the format of pg_amop relation. + * ---------------- + */ +typedef FormData_pg_amop *Form_pg_amop; + +/* ---------------- + * compiler constants for pg_amop + * ---------------- + */ +#define Natts_pg_amop 8 +#define Anum_pg_amop_amopfamily 1 +#define Anum_pg_amop_amoplefttype 2 +#define Anum_pg_amop_amoprighttype 3 +#define Anum_pg_amop_amopstrategy 4 +#define Anum_pg_amop_amoppurpose 5 +#define Anum_pg_amop_amopopr 6 +#define Anum_pg_amop_amopmethod 7 +#define Anum_pg_amop_amopsortfamily 8 + +/* ---------------- + * initial contents of pg_amop + * ---------------- + */ + +/* + * btree integer_ops + */ + +/* default operators int2 */ +DATA(insert ( 1976 21 21 1 s 95 403 0 )); +DATA(insert ( 1976 21 21 2 s 522 403 0 )); +DATA(insert ( 1976 21 21 3 s 94 403 0 )); +DATA(insert ( 1976 21 21 4 s 524 403 0 )); +DATA(insert ( 1976 21 21 5 s 520 403 0 )); +/* crosstype operators int24 */ +DATA(insert ( 1976 21 23 1 s 534 403 0 )); +DATA(insert ( 1976 21 23 2 s 540 403 0 )); +DATA(insert ( 1976 21 23 3 s 532 403 0 )); +DATA(insert ( 1976 21 23 4 s 542 403 0 )); +DATA(insert ( 1976 21 23 5 s 536 403 0 )); +/* crosstype operators int28 */ +DATA(insert ( 1976 21 20 1 s 1864 403 0 )); +DATA(insert ( 1976 21 20 2 s 1866 403 0 )); +DATA(insert ( 1976 21 20 3 s 1862 403 0 )); +DATA(insert ( 1976 21 20 4 s 1867 403 0 )); +DATA(insert ( 1976 21 20 5 s 1865 403 0 )); +/* default operators int4 */ +DATA(insert ( 1976 23 23 1 s 97 403 0 )); +DATA(insert ( 1976 23 23 2 s 523 403 0 )); +DATA(insert ( 1976 23 23 3 s 96 403 0 )); +DATA(insert ( 1976 23 23 4 s 525 403 0 )); +DATA(insert ( 1976 23 23 5 s 521 403 0 )); +/* crosstype operators int42 */ +DATA(insert ( 1976 23 21 1 s 535 403 0 )); +DATA(insert ( 1976 23 21 2 s 541 403 0 )); +DATA(insert ( 1976 23 21 3 s 533 403 0 )); +DATA(insert ( 1976 23 21 4 s 543 403 0 )); +DATA(insert ( 1976 23 21 5 s 537 403 0 )); +/* crosstype operators int48 */ +DATA(insert ( 1976 23 20 1 s 37 403 0 )); +DATA(insert ( 1976 23 20 2 s 80 403 0 )); +DATA(insert ( 1976 23 20 3 s 15 403 0 )); +DATA(insert ( 1976 23 20 4 s 82 403 0 )); +DATA(insert ( 1976 23 20 5 s 76 403 0 )); +/* default operators int8 */ +DATA(insert ( 1976 20 20 1 s 412 403 0 )); +DATA(insert ( 1976 20 20 2 s 414 403 0 )); +DATA(insert ( 1976 20 20 3 s 410 403 0 )); +DATA(insert ( 1976 20 20 4 s 415 403 0 )); +DATA(insert ( 1976 20 20 5 s 413 403 0 )); +/* crosstype operators int82 */ +DATA(insert ( 1976 20 21 1 s 1870 403 0 )); +DATA(insert ( 1976 20 21 2 s 1872 403 0 )); +DATA(insert ( 1976 20 21 3 s 1868 403 0 )); +DATA(insert ( 1976 20 21 4 s 1873 403 0 )); +DATA(insert ( 1976 20 21 5 s 1871 403 0 )); +/* crosstype operators int84 */ +DATA(insert ( 1976 20 23 1 s 418 403 0 )); +DATA(insert ( 1976 20 23 2 s 420 403 0 )); +DATA(insert ( 1976 20 23 3 s 416 403 0 )); +DATA(insert ( 1976 20 23 4 s 430 403 0 )); +DATA(insert ( 1976 20 23 5 s 419 403 0 )); + +/* + * btree oid_ops + */ + +DATA(insert ( 1989 26 26 1 s 609 403 0 )); +DATA(insert ( 1989 26 26 2 s 611 403 0 )); +DATA(insert ( 1989 26 26 3 s 607 403 0 )); +DATA(insert ( 1989 26 26 4 s 612 403 0 )); +DATA(insert ( 1989 26 26 5 s 610 403 0 )); + +/* + * btree tid_ops + */ + +DATA(insert ( 2789 27 27 1 s 2799 403 0 )); +DATA(insert ( 2789 27 27 2 s 2801 403 0 )); +DATA(insert ( 2789 27 27 3 s 387 403 0 )); +DATA(insert ( 2789 27 27 4 s 2802 403 0 )); +DATA(insert ( 2789 27 27 5 s 2800 403 0 )); + +/* + * btree oidvector_ops + */ + +DATA(insert ( 1991 30 30 1 s 645 403 0 )); +DATA(insert ( 1991 30 30 2 s 647 403 0 )); +DATA(insert ( 1991 30 30 3 s 649 403 0 )); +DATA(insert ( 1991 30 30 4 s 648 403 0 )); +DATA(insert ( 1991 30 30 5 s 646 403 0 )); + +/* + * btree float_ops + */ + +/* default operators float4 */ +DATA(insert ( 1970 700 700 1 s 622 403 0 )); +DATA(insert ( 1970 700 700 2 s 624 403 0 )); +DATA(insert ( 1970 700 700 3 s 620 403 0 )); +DATA(insert ( 1970 700 700 4 s 625 403 0 )); +DATA(insert ( 1970 700 700 5 s 623 403 0 )); +/* crosstype operators float48 */ +DATA(insert ( 1970 700 701 1 s 1122 403 0 )); +DATA(insert ( 1970 700 701 2 s 1124 403 0 )); +DATA(insert ( 1970 700 701 3 s 1120 403 0 )); +DATA(insert ( 1970 700 701 4 s 1125 403 0 )); +DATA(insert ( 1970 700 701 5 s 1123 403 0 )); +/* default operators float8 */ +DATA(insert ( 1970 701 701 1 s 672 403 0 )); +DATA(insert ( 1970 701 701 2 s 673 403 0 )); +DATA(insert ( 1970 701 701 3 s 670 403 0 )); +DATA(insert ( 1970 701 701 4 s 675 403 0 )); +DATA(insert ( 1970 701 701 5 s 674 403 0 )); +/* crosstype operators float84 */ +DATA(insert ( 1970 701 700 1 s 1132 403 0 )); +DATA(insert ( 1970 701 700 2 s 1134 403 0 )); +DATA(insert ( 1970 701 700 3 s 1130 403 0 )); +DATA(insert ( 1970 701 700 4 s 1135 403 0 )); +DATA(insert ( 1970 701 700 5 s 1133 403 0 )); + +/* + * btree char_ops + */ + +DATA(insert ( 429 18 18 1 s 631 403 0 )); +DATA(insert ( 429 18 18 2 s 632 403 0 )); +DATA(insert ( 429 18 18 3 s 92 403 0 )); +DATA(insert ( 429 18 18 4 s 634 403 0 )); +DATA(insert ( 429 18 18 5 s 633 403 0 )); + +/* + * btree name_ops + */ + +DATA(insert ( 1986 19 19 1 s 660 403 0 )); +DATA(insert ( 1986 19 19 2 s 661 403 0 )); +DATA(insert ( 1986 19 19 3 s 93 403 0 )); +DATA(insert ( 1986 19 19 4 s 663 403 0 )); +DATA(insert ( 1986 19 19 5 s 662 403 0 )); + +/* + * btree text_ops + */ + +DATA(insert ( 1994 25 25 1 s 664 403 0 )); +DATA(insert ( 1994 25 25 2 s 665 403 0 )); +DATA(insert ( 1994 25 25 3 s 98 403 0 )); +DATA(insert ( 1994 25 25 4 s 667 403 0 )); +DATA(insert ( 1994 25 25 5 s 666 403 0 )); + +/* + * btree bpchar_ops + */ + +DATA(insert ( 426 1042 1042 1 s 1058 403 0 )); +DATA(insert ( 426 1042 1042 2 s 1059 403 0 )); +DATA(insert ( 426 1042 1042 3 s 1054 403 0 )); +DATA(insert ( 426 1042 1042 4 s 1061 403 0 )); +DATA(insert ( 426 1042 1042 5 s 1060 403 0 )); + +/* + * btree bytea_ops + */ + +DATA(insert ( 428 17 17 1 s 1957 403 0 )); +DATA(insert ( 428 17 17 2 s 1958 403 0 )); +DATA(insert ( 428 17 17 3 s 1955 403 0 )); +DATA(insert ( 428 17 17 4 s 1960 403 0 )); +DATA(insert ( 428 17 17 5 s 1959 403 0 )); + +/* + * btree byteawithoutorderwithequalcol_ops + */ + +DATA(insert ( 436 4402 4402 3 s 4453 403 0 )); + +/* + * btree raw_ops + */ + +DATA(insert ( 3806 86 86 1 s 3800 403 0 )); +DATA(insert ( 3806 86 86 2 s 3801 403 0 )); +DATA(insert ( 3806 86 86 3 s 3798 403 0 )); +DATA(insert ( 3806 86 86 4 s 3803 403 0 )); +DATA(insert ( 3806 86 86 5 s 3802 403 0 )); +DATA(insert ( 5535 5545 5545 1 s 5515 403 0 )); +DATA(insert ( 5535 5545 5545 2 s 5516 403 0 )); +DATA(insert ( 5535 5545 5545 3 s 5513 403 0 )); +DATA(insert ( 5535 5545 5545 4 s 5518 403 0 )); +DATA(insert ( 5535 5545 5545 5 s 5517 403 0 )); + +/* + * btree abstime_ops + */ + +DATA(insert ( 421 702 702 1 s 562 403 0 )); +DATA(insert ( 421 702 702 2 s 564 403 0 )); +DATA(insert ( 421 702 702 3 s 560 403 0 )); +DATA(insert ( 421 702 702 4 s 565 403 0 )); +DATA(insert ( 421 702 702 5 s 563 403 0 )); + +/* + * btree datetime_ops + */ + +/* default operators date */ +DATA(insert ( 434 1082 1082 1 s 1095 403 0 )); +DATA(insert ( 434 1082 1082 2 s 1096 403 0 )); +DATA(insert ( 434 1082 1082 3 s 1093 403 0 )); +DATA(insert ( 434 1082 1082 4 s 1098 403 0 )); +DATA(insert ( 434 1082 1082 5 s 1097 403 0 )); +/* crosstype operators vs timestamp */ +DATA(insert ( 434 1082 1114 1 s 2345 403 0 )); +DATA(insert ( 434 1082 1114 2 s 2346 403 0 )); +DATA(insert ( 434 1082 1114 3 s 2347 403 0 )); +DATA(insert ( 434 1082 1114 4 s 2348 403 0 )); +DATA(insert ( 434 1082 1114 5 s 2349 403 0 )); +/* crosstype operators vs timestamptz */ +DATA(insert ( 434 1082 1184 1 s 2358 403 0 )); +DATA(insert ( 434 1082 1184 2 s 2359 403 0 )); +DATA(insert ( 434 1082 1184 3 s 2360 403 0 )); +DATA(insert ( 434 1082 1184 4 s 2361 403 0 )); +DATA(insert ( 434 1082 1184 5 s 2362 403 0 )); +/* default operators timestamp */ +DATA(insert ( 434 1114 1114 1 s 2062 403 0 )); +DATA(insert ( 434 1114 1114 2 s 2063 403 0 )); +DATA(insert ( 434 1114 1114 3 s 2060 403 0 )); +DATA(insert ( 434 1114 1114 4 s 2065 403 0 )); +DATA(insert ( 434 1114 1114 5 s 2064 403 0 )); +/* crosstype operators vs date */ +DATA(insert ( 434 1114 1082 1 s 2371 403 0 )); +DATA(insert ( 434 1114 1082 2 s 2372 403 0 )); +DATA(insert ( 434 1114 1082 3 s 2373 403 0 )); +DATA(insert ( 434 1114 1082 4 s 2374 403 0 )); +DATA(insert ( 434 1114 1082 5 s 2375 403 0 )); +/* crosstype operators vs timestamptz */ +DATA(insert ( 434 1114 1184 1 s 2534 403 0 )); +DATA(insert ( 434 1114 1184 2 s 2535 403 0 )); +DATA(insert ( 434 1114 1184 3 s 2536 403 0 )); +DATA(insert ( 434 1114 1184 4 s 2537 403 0 )); +DATA(insert ( 434 1114 1184 5 s 2538 403 0 )); +/* default operators timestamptz */ +DATA(insert ( 434 1184 1184 1 s 1322 403 0 )); +DATA(insert ( 434 1184 1184 2 s 1323 403 0 )); +DATA(insert ( 434 1184 1184 3 s 1320 403 0 )); +DATA(insert ( 434 1184 1184 4 s 1325 403 0 )); +DATA(insert ( 434 1184 1184 5 s 1324 403 0 )); +/* crosstype operators vs date */ +DATA(insert ( 434 1184 1082 1 s 2384 403 0 )); +DATA(insert ( 434 1184 1082 2 s 2385 403 0 )); +DATA(insert ( 434 1184 1082 3 s 2386 403 0 )); +DATA(insert ( 434 1184 1082 4 s 2387 403 0 )); +DATA(insert ( 434 1184 1082 5 s 2388 403 0 )); +/* crosstype operators vs timestamp */ +DATA(insert ( 434 1184 1114 1 s 2540 403 0 )); +DATA(insert ( 434 1184 1114 2 s 2541 403 0 )); +DATA(insert ( 434 1184 1114 3 s 2542 403 0 )); +DATA(insert ( 434 1184 1114 4 s 2543 403 0 )); +DATA(insert ( 434 1184 1114 5 s 2544 403 0 )); + +/* + * btree time_ops + */ + +DATA(insert ( 1996 1083 1083 1 s 1110 403 0 )); +DATA(insert ( 1996 1083 1083 2 s 1111 403 0 )); +DATA(insert ( 1996 1083 1083 3 s 1108 403 0 )); +DATA(insert ( 1996 1083 1083 4 s 1113 403 0 )); +DATA(insert ( 1996 1083 1083 5 s 1112 403 0 )); + +/* + * btree timetz_ops + */ + +DATA(insert ( 2000 1266 1266 1 s 1552 403 0 )); +DATA(insert ( 2000 1266 1266 2 s 1553 403 0 )); +DATA(insert ( 2000 1266 1266 3 s 1550 403 0 )); +DATA(insert ( 2000 1266 1266 4 s 1555 403 0 )); +DATA(insert ( 2000 1266 1266 5 s 1554 403 0 )); + +/* + * btree interval_ops + */ + +DATA(insert ( 1982 1186 1186 1 s 1332 403 0 )); +DATA(insert ( 1982 1186 1186 2 s 1333 403 0 )); +DATA(insert ( 1982 1186 1186 3 s 1330 403 0 )); +DATA(insert ( 1982 1186 1186 4 s 1335 403 0 )); +DATA(insert ( 1982 1186 1186 5 s 1334 403 0 )); + +/* + * btree macaddr + */ + +DATA(insert ( 1984 829 829 1 s 1222 403 0 )); +DATA(insert ( 1984 829 829 2 s 1223 403 0 )); +DATA(insert ( 1984 829 829 3 s 1220 403 0 )); +DATA(insert ( 1984 829 829 4 s 1225 403 0 )); +DATA(insert ( 1984 829 829 5 s 1224 403 0 )); + +/* + * btree network + */ + +DATA(insert ( 1974 869 869 1 s 1203 403 0 )); +DATA(insert ( 1974 869 869 2 s 1204 403 0 )); +DATA(insert ( 1974 869 869 3 s 1201 403 0 )); +DATA(insert ( 1974 869 869 4 s 1206 403 0 )); +DATA(insert ( 1974 869 869 5 s 1205 403 0 )); + +/* + * btree numeric + */ + +DATA(insert ( 1988 1700 1700 1 s 1754 403 0 )); +DATA(insert ( 1988 1700 1700 2 s 1755 403 0 )); +DATA(insert ( 1988 1700 1700 3 s 1752 403 0 )); +DATA(insert ( 1988 1700 1700 4 s 1757 403 0 )); +DATA(insert ( 1988 1700 1700 5 s 1756 403 0 )); + +/* + * btree bool + */ + +DATA(insert ( 424 16 16 1 s 58 403 0 )); +DATA(insert ( 424 16 16 2 s 1694 403 0 )); +DATA(insert ( 424 16 16 3 s 91 403 0 )); +DATA(insert ( 424 16 16 4 s 1695 403 0 )); +DATA(insert ( 424 16 16 5 s 59 403 0 )); + +/* + * btree bit + */ + +DATA(insert ( 423 1560 1560 1 s 1786 403 0 )); +DATA(insert ( 423 1560 1560 2 s 1788 403 0 )); +DATA(insert ( 423 1560 1560 3 s 1784 403 0 )); +DATA(insert ( 423 1560 1560 4 s 1789 403 0 )); +DATA(insert ( 423 1560 1560 5 s 1787 403 0 )); + +/* + * btree varbit + */ + +DATA(insert ( 2002 1562 1562 1 s 1806 403 0 )); +DATA(insert ( 2002 1562 1562 2 s 1808 403 0 )); +DATA(insert ( 2002 1562 1562 3 s 1804 403 0 )); +DATA(insert ( 2002 1562 1562 4 s 1809 403 0 )); +DATA(insert ( 2002 1562 1562 5 s 1807 403 0 )); + +/* + * btree text pattern + */ + +DATA(insert ( 2095 25 25 1 s 2314 403 0 )); +DATA(insert ( 2095 25 25 2 s 2315 403 0 )); +DATA(insert ( 2095 25 25 3 s 98 403 0 )); +DATA(insert ( 2095 25 25 4 s 2317 403 0 )); +DATA(insert ( 2095 25 25 5 s 2318 403 0 )); + +/* + * btree bpchar pattern + */ + +DATA(insert ( 2097 1042 1042 1 s 2326 403 0 )); +DATA(insert ( 2097 1042 1042 2 s 2327 403 0 )); +DATA(insert ( 2097 1042 1042 3 s 1054 403 0 )); +DATA(insert ( 2097 1042 1042 4 s 2329 403 0 )); +DATA(insert ( 2097 1042 1042 5 s 2330 403 0 )); + +/* + * btree money_ops + */ + +DATA(insert ( 2099 790 790 1 s 902 403 0 )); +DATA(insert ( 2099 790 790 2 s 904 403 0 )); +DATA(insert ( 2099 790 790 3 s 900 403 0 )); +DATA(insert ( 2099 790 790 4 s 905 403 0 )); +DATA(insert ( 2099 790 790 5 s 903 403 0 )); + +/* + * btree reltime_ops + */ + +DATA(insert ( 2233 703 703 1 s 568 403 0 )); +DATA(insert ( 2233 703 703 2 s 570 403 0 )); +DATA(insert ( 2233 703 703 3 s 566 403 0 )); +DATA(insert ( 2233 703 703 4 s 571 403 0 )); +DATA(insert ( 2233 703 703 5 s 569 403 0 )); + +/* + * btree tinterval_ops + */ + +DATA(insert ( 2234 704 704 1 s 813 403 0 )); +DATA(insert ( 2234 704 704 2 s 815 403 0 )); +DATA(insert ( 2234 704 704 3 s 811 403 0 )); +DATA(insert ( 2234 704 704 4 s 816 403 0 )); +DATA(insert ( 2234 704 704 5 s 814 403 0 )); + +/* + * btree array_ops + */ + +DATA(insert ( 397 2277 2277 1 s 1072 403 0 )); +DATA(insert ( 397 2277 2277 2 s 1074 403 0 )); +DATA(insert ( 397 2277 2277 3 s 1070 403 0 )); +DATA(insert ( 397 2277 2277 4 s 1075 403 0 )); +DATA(insert ( 397 2277 2277 5 s 1073 403 0 )); + +/* + * btree record_ops + */ + +DATA(insert ( 2994 2249 2249 1 s 2990 403 0 )); +DATA(insert ( 2994 2249 2249 2 s 2992 403 0 )); +DATA(insert ( 2994 2249 2249 3 s 2988 403 0 )); +DATA(insert ( 2994 2249 2249 4 s 2993 403 0 )); +DATA(insert ( 2994 2249 2249 5 s 2991 403 0 )); + +/* + * btree uuid_ops + */ + +DATA(insert ( 2968 2950 2950 1 s 2974 403 0 )); +DATA(insert ( 2968 2950 2950 2 s 2976 403 0 )); +DATA(insert ( 2968 2950 2950 3 s 2972 403 0 )); +DATA(insert ( 2968 2950 2950 4 s 2977 403 0 )); +DATA(insert ( 2968 2950 2950 5 s 2975 403 0 )); + +/* + * hash index _ops + */ + +/* bpchar_ops */ +DATA(insert ( 427 1042 1042 1 s 1054 405 0 )); +/* char_ops */ +DATA(insert ( 431 18 18 1 s 92 405 0 )); +/* date_ops */ +DATA(insert ( 435 1082 1082 1 s 1093 405 0 )); +/* float_ops */ +DATA(insert ( 1971 700 700 1 s 620 405 0 )); +DATA(insert ( 1971 701 701 1 s 670 405 0 )); +DATA(insert ( 1971 700 701 1 s 1120 405 0 )); +DATA(insert ( 1971 701 700 1 s 1130 405 0 )); +/* network_ops */ +DATA(insert ( 1975 869 869 1 s 1201 405 0 )); +/* integer_ops */ +DATA(insert ( 1977 21 21 1 s 94 405 0 )); +DATA(insert ( 1977 23 23 1 s 96 405 0 )); +DATA(insert ( 1977 20 20 1 s 410 405 0 )); +DATA(insert ( 1977 21 23 1 s 532 405 0 )); +DATA(insert ( 1977 21 20 1 s 1862 405 0 )); +DATA(insert ( 1977 23 21 1 s 533 405 0 )); +DATA(insert ( 1977 23 20 1 s 15 405 0 )); +DATA(insert ( 1977 20 21 1 s 1868 405 0 )); +DATA(insert ( 1977 20 23 1 s 416 405 0 )); +/* interval_ops */ +DATA(insert ( 1983 1186 1186 1 s 1330 405 0 )); +/* macaddr_ops */ +DATA(insert ( 1985 829 829 1 s 1220 405 0 )); +/* name_ops */ +DATA(insert ( 1987 19 19 1 s 93 405 0 )); +/* oid_ops */ +DATA(insert ( 1990 26 26 1 s 607 405 0 )); +/* oidvector_ops */ +DATA(insert ( 1992 30 30 1 s 649 405 0 )); +/* text_ops */ +DATA(insert ( 1995 25 25 1 s 98 405 0 )); +/* time_ops */ +DATA(insert ( 1997 1083 1083 1 s 1108 405 0 )); +/* timestamptz_ops */ +DATA(insert ( 1999 1184 1184 1 s 1320 405 0 )); +/* timetz_ops */ +DATA(insert ( 2001 1266 1266 1 s 1550 405 0 )); +/* timestamp_ops */ +DATA(insert ( 2040 1114 1114 1 s 2060 405 0 )); +/* bool_ops */ +DATA(insert ( 2222 16 16 1 s 91 405 0 )); +/* bytea_ops */ +DATA(insert ( 2223 17 17 1 s 1955 405 0 )); +/* byteawithoutorderwithequalcol_ops */ +DATA(insert ( 4470 4402 4402 1 s 4453 405 0 )); + +/* raw_ops */ +DATA(insert ( 3807 86 86 1 s 3798 405 0 )); +/* tinyint_ops */ +DATA(insert ( 5536 5545 5545 1 s 5513 405 0 )); +/* int2vector_ops */ +DATA(insert ( 2224 22 22 1 s 386 405 0 )); +/* xid_ops */ +DATA(insert ( 2225 28 28 1 s 352 405 0 )); +DATA(insert ( 2232 31 31 1 s 355 405 0 )); +/* cid_ops */ +DATA(insert ( 2226 29 29 1 s 385 405 0 )); +/* abstime_ops */ +DATA(insert ( 2227 702 702 1 s 560 405 0 )); +/* reltime_ops */ +DATA(insert ( 2228 703 703 1 s 566 405 0 )); +/* text_pattern_ops */ +DATA(insert ( 2229 25 25 1 s 98 405 0 )); +/* bpchar_pattern_ops */ +DATA(insert ( 2231 1042 1042 1 s 1054 405 0 )); +/* aclitem_ops */ +DATA(insert ( 2235 1033 1033 1 s 974 405 0 )); +/* uuid_ops */ +DATA(insert ( 2969 2950 2950 1 s 2972 405 0 )); +/* numeric_ops */ +DATA(insert ( 1998 1700 1700 1 s 1752 405 0 )); +/* array_ops */ +DATA(insert ( 627 2277 2277 1 s 1070 405 0 )); + + +/* + * gist box_ops + */ + +DATA(insert ( 2593 603 603 1 s 493 783 0 )); +DATA(insert ( 2593 603 603 2 s 494 783 0 )); +DATA(insert ( 2593 603 603 3 s 500 783 0 )); +DATA(insert ( 2593 603 603 4 s 495 783 0 )); +DATA(insert ( 2593 603 603 5 s 496 783 0 )); +DATA(insert ( 2593 603 603 6 s 499 783 0 )); +DATA(insert ( 2593 603 603 7 s 498 783 0 )); +DATA(insert ( 2593 603 603 8 s 497 783 0 )); +DATA(insert ( 2593 603 603 9 s 2571 783 0 )); +DATA(insert ( 2593 603 603 10 s 2570 783 0 )); +DATA(insert ( 2593 603 603 11 s 2573 783 0 )); +DATA(insert ( 2593 603 603 12 s 2572 783 0 )); +DATA(insert ( 2593 603 603 13 s 2863 783 0 )); +DATA(insert ( 2593 603 603 14 s 2862 783 0 )); + +/* + * gist point_ops + */ +DATA(insert ( 1029 600 600 11 s 506 783 0 )); +DATA(insert ( 1029 600 600 1 s 507 783 0 )); +DATA(insert ( 1029 600 600 5 s 508 783 0 )); +DATA(insert ( 1029 600 600 10 s 509 783 0 )); +DATA(insert ( 1029 600 600 6 s 510 783 0 )); +DATA(insert ( 1029 600 600 15 o 517 783 1970 )); +DATA(insert ( 1029 600 603 28 s 511 783 0 )); +DATA(insert ( 1029 600 604 48 s 756 783 0 )); +DATA(insert ( 1029 600 718 68 s 758 783 0 )); + + +/* + * gist poly_ops (supports polygons) + */ + +DATA(insert ( 2594 604 604 1 s 485 783 0 )); +DATA(insert ( 2594 604 604 2 s 486 783 0 )); +DATA(insert ( 2594 604 604 3 s 492 783 0 )); +DATA(insert ( 2594 604 604 4 s 487 783 0 )); +DATA(insert ( 2594 604 604 5 s 488 783 0 )); +DATA(insert ( 2594 604 604 6 s 491 783 0 )); +DATA(insert ( 2594 604 604 7 s 490 783 0 )); +DATA(insert ( 2594 604 604 8 s 489 783 0 )); +DATA(insert ( 2594 604 604 9 s 2575 783 0 )); +DATA(insert ( 2594 604 604 10 s 2574 783 0 )); +DATA(insert ( 2594 604 604 11 s 2577 783 0 )); +DATA(insert ( 2594 604 604 12 s 2576 783 0 )); +DATA(insert ( 2594 604 604 13 s 2861 783 0 )); +DATA(insert ( 2594 604 604 14 s 2860 783 0 )); + +/* + * gist circle_ops + */ + +DATA(insert ( 2595 718 718 1 s 1506 783 0 )); +DATA(insert ( 2595 718 718 2 s 1507 783 0 )); +DATA(insert ( 2595 718 718 3 s 1513 783 0 )); +DATA(insert ( 2595 718 718 4 s 1508 783 0 )); +DATA(insert ( 2595 718 718 5 s 1509 783 0 )); +DATA(insert ( 2595 718 718 6 s 1512 783 0 )); +DATA(insert ( 2595 718 718 7 s 1511 783 0 )); +DATA(insert ( 2595 718 718 8 s 1510 783 0 )); +DATA(insert ( 2595 718 718 9 s 2589 783 0 )); +DATA(insert ( 2595 718 718 10 s 1515 783 0 )); +DATA(insert ( 2595 718 718 11 s 1514 783 0 )); +DATA(insert ( 2595 718 718 12 s 2590 783 0 )); +DATA(insert ( 2595 718 718 13 s 2865 783 0 )); +DATA(insert ( 2595 718 718 14 s 2864 783 0 )); + +/* + * gin array_ops (these anyarray operators are used with all the opclasses + * of the family) + */ +DATA(insert ( 2745 2277 2277 1 s 2750 2742 0 )); +DATA(insert ( 2745 2277 2277 2 s 2751 2742 0 )); +DATA(insert ( 2745 2277 2277 3 s 2752 2742 0 )); +DATA(insert ( 2745 2277 2277 4 s 1070 2742 0 )); + +/* + * cgin array_ops (these anyarray operators are used with all the opclasses + * of the family) + */ +/* +DATA(insert ( 4445 2277 2277 1 s 2750 4444 0 )); +DATA(insert ( 4445 2277 2277 2 s 2751 4444 0 )); +DATA(insert ( 4445 2277 2277 3 s 2752 4444 0 )); +DATA(insert ( 4445 2277 2277 4 s 1070 4444 0 )); +*/ + +/* + * btree enum_ops + */ +DATA(insert ( 3522 3500 3500 1 s 3518 403 0 )); +DATA(insert ( 3522 3500 3500 2 s 3520 403 0 )); +DATA(insert ( 3522 3500 3500 3 s 3516 403 0 )); +DATA(insert ( 3522 3500 3500 4 s 3521 403 0 )); +DATA(insert ( 3522 3500 3500 5 s 3519 403 0 )); + +/* + * hash enum_ops + */ +DATA(insert ( 3523 3500 3500 1 s 3516 405 0 )); + +/* + * btree tsvector_ops + */ +DATA(insert ( 3626 3614 3614 1 s 3627 403 0 )); +DATA(insert ( 3626 3614 3614 2 s 3628 403 0 )); +DATA(insert ( 3626 3614 3614 3 s 3629 403 0 )); +DATA(insert ( 3626 3614 3614 4 s 3631 403 0 )); +DATA(insert ( 3626 3614 3614 5 s 3632 403 0 )); + +/* + * GiST tsvector_ops + */ +DATA(insert ( 3655 3614 3615 1 s 3636 783 0 )); + +/* + * GIN tsvector_ops + */ +DATA(insert ( 3659 3614 3615 1 s 3636 2742 0 )); +DATA(insert ( 3659 3614 3615 2 s 3660 2742 0 )); + +/* + * CGIN tsvector_ops + */ +DATA(insert ( 4446 3614 3615 1 s 3636 4444 0 )); +DATA(insert ( 4446 3614 3615 2 s 3660 4444 0 )); + +/* + * btree tsquery_ops + */ +DATA(insert ( 3683 3615 3615 1 s 3674 403 0 )); +DATA(insert ( 3683 3615 3615 2 s 3675 403 0 )); +DATA(insert ( 3683 3615 3615 3 s 3676 403 0 )); +DATA(insert ( 3683 3615 3615 4 s 3678 403 0 )); +DATA(insert ( 3683 3615 3615 5 s 3679 403 0 )); + +/* + * GiST tsquery_ops + */ +DATA(insert ( 3702 3615 3615 7 s 3693 783 0 )); +DATA(insert ( 3702 3615 3615 8 s 3694 783 0 )); + +/* + * btree range_ops + */ +DATA(insert ( 3901 3831 3831 1 s 3884 403 0 )); +DATA(insert ( 3901 3831 3831 2 s 3885 403 0 )); +DATA(insert ( 3901 3831 3831 3 s 3882 403 0 )); +DATA(insert ( 3901 3831 3831 4 s 3886 403 0 )); +DATA(insert ( 3901 3831 3831 5 s 3887 403 0 )); + +/* + * hash range_ops + */ +DATA(insert ( 3903 3831 3831 1 s 3882 405 0 )); + +/* + * GiST range_ops + */ +DATA(insert ( 3919 3831 3831 1 s 3893 783 0 )); +DATA(insert ( 3919 3831 3831 2 s 3895 783 0 )); +DATA(insert ( 3919 3831 3831 3 s 3888 783 0 )); +DATA(insert ( 3919 3831 3831 4 s 3896 783 0 )); +DATA(insert ( 3919 3831 3831 5 s 3894 783 0 )); +DATA(insert ( 3919 3831 3831 6 s 3897 783 0 )); +DATA(insert ( 3919 3831 3831 7 s 3890 783 0 )); +DATA(insert ( 3919 3831 3831 8 s 3892 783 0 )); +DATA(insert ( 3919 3831 2283 16 s 3889 783 0 )); +DATA(insert ( 3919 3831 3831 18 s 3882 783 0 )); + +/* + * SP-GiST quad_point_ops + */ +DATA(insert ( 4015 600 600 11 s 506 4000 0 )); +DATA(insert ( 4015 600 600 1 s 507 4000 0 )); +DATA(insert ( 4015 600 600 5 s 508 4000 0 )); +DATA(insert ( 4015 600 600 10 s 509 4000 0 )); +DATA(insert ( 4015 600 600 6 s 510 4000 0 )); +DATA(insert ( 4015 600 603 8 s 511 4000 0 )); + +/* + * SP-GiST kd_point_ops + */ +DATA(insert ( 4016 600 600 11 s 506 4000 0 )); +DATA(insert ( 4016 600 600 1 s 507 4000 0 )); +DATA(insert ( 4016 600 600 5 s 508 4000 0 )); +DATA(insert ( 4016 600 600 10 s 509 4000 0 )); +DATA(insert ( 4016 600 600 6 s 510 4000 0 )); +DATA(insert ( 4016 600 603 8 s 511 4000 0 )); + +/* + * SP-GiST text_ops + */ +DATA(insert ( 4017 25 25 1 s 2314 4000 0 )); +DATA(insert ( 4017 25 25 2 s 2315 4000 0 )); +DATA(insert ( 4017 25 25 3 s 98 4000 0 )); +DATA(insert ( 4017 25 25 4 s 2317 4000 0 )); +DATA(insert ( 4017 25 25 5 s 2318 4000 0 )); +DATA(insert ( 4017 25 25 11 s 664 4000 0 )); +DATA(insert ( 4017 25 25 12 s 665 4000 0 )); +DATA(insert ( 4017 25 25 14 s 667 4000 0 )); +DATA(insert ( 4017 25 25 15 s 666 4000 0 )); +DATA(insert ( 5570 9003 9003 1 s 5552 403 0 )); +DATA(insert ( 5570 9003 9003 2 s 5553 403 0 )); +DATA(insert ( 5570 9003 9003 3 s 5550 403 0 )); +DATA(insert ( 5570 9003 9003 4 s 5549 403 0 )); +DATA(insert ( 5570 9003 9003 5 s 5554 403 0 )); +DATA(insert ( 5571 9003 9003 1 s 5550 405 0 )); + +/* psort, fake data just make index work */ +DATA(insert ( 4050 21 21 1 s 95 4039 0 )); +DATA(insert ( 4050 21 21 2 s 522 4039 0 )); +DATA(insert ( 4050 21 21 3 s 94 4039 0 )); +DATA(insert ( 4050 21 21 4 s 524 4039 0 )); +DATA(insert ( 4050 21 21 5 s 520 4039 0 )); + +DATA(insert ( 4050 21 23 1 s 534 4039 0 )); +DATA(insert ( 4050 21 23 2 s 540 4039 0 )); +DATA(insert ( 4050 21 23 3 s 532 4039 0 )); +DATA(insert ( 4050 21 23 4 s 542 4039 0 )); +DATA(insert ( 4050 21 23 5 s 536 4039 0 )); + +DATA(insert ( 4050 21 20 1 s 1864 4039 0 )); +DATA(insert ( 4050 21 20 2 s 1866 4039 0 )); +DATA(insert ( 4050 21 20 3 s 1862 4039 0 )); +DATA(insert ( 4050 21 20 4 s 1867 4039 0 )); +DATA(insert ( 4050 21 20 5 s 1865 4039 0 )); + +DATA(insert ( 4050 23 23 1 s 97 4039 0 )); +DATA(insert ( 4050 23 23 2 s 523 4039 0 )); +DATA(insert ( 4050 23 23 3 s 96 4039 0 )); +DATA(insert ( 4050 23 23 4 s 525 4039 0 )); +DATA(insert ( 4050 23 23 5 s 521 4039 0 )); + +DATA(insert ( 4050 23 21 1 s 535 4039 0 )); +DATA(insert ( 4050 23 21 2 s 541 4039 0 )); +DATA(insert ( 4050 23 21 3 s 533 4039 0 )); +DATA(insert ( 4050 23 21 4 s 543 4039 0 )); +DATA(insert ( 4050 23 21 5 s 537 4039 0 )); + +DATA(insert ( 4050 23 20 1 s 37 4039 0 )); +DATA(insert ( 4050 23 20 2 s 80 4039 0 )); +DATA(insert ( 4050 23 20 3 s 15 4039 0 )); +DATA(insert ( 4050 23 20 4 s 82 4039 0 )); +DATA(insert ( 4050 23 20 5 s 76 4039 0 )); + +DATA(insert ( 4050 20 20 1 s 412 4039 0 )); +DATA(insert ( 4050 20 20 2 s 414 4039 0 )); +DATA(insert ( 4050 20 20 3 s 410 4039 0 )); +DATA(insert ( 4050 20 20 4 s 415 4039 0 )); +DATA(insert ( 4050 20 20 5 s 413 4039 0 )); + +DATA(insert ( 4050 20 21 1 s 1870 4039 0 )); +DATA(insert ( 4050 20 21 2 s 1872 4039 0 )); +DATA(insert ( 4050 20 21 3 s 1868 4039 0 )); +DATA(insert ( 4050 20 21 4 s 1873 4039 0 )); +DATA(insert ( 4050 20 21 5 s 1871 4039 0 )); + +DATA(insert ( 4050 20 23 1 s 418 4039 0 )); +DATA(insert ( 4050 20 23 2 s 420 4039 0 )); +DATA(insert ( 4050 20 23 3 s 416 4039 0 )); +DATA(insert ( 4050 20 23 4 s 430 4039 0 )); +DATA(insert ( 4050 20 23 5 s 419 4039 0 )); + +DATA(insert ( 4051 26 26 1 s 609 4039 0 )); +DATA(insert ( 4051 26 26 2 s 611 4039 0 )); +DATA(insert ( 4051 26 26 3 s 607 4039 0 )); +DATA(insert ( 4051 26 26 4 s 612 4039 0 )); +DATA(insert ( 4051 26 26 5 s 610 4039 0 )); + +DATA(insert ( 4052 1082 1082 1 s 1095 4039 0 )); +DATA(insert ( 4052 1082 1082 2 s 1096 4039 0 )); +DATA(insert ( 4052 1082 1082 3 s 1093 4039 0 )); +DATA(insert ( 4052 1082 1082 4 s 1098 4039 0 )); +DATA(insert ( 4052 1082 1082 5 s 1097 4039 0 )); + +DATA(insert ( 4052 1082 1114 1 s 2345 4039 0 )); +DATA(insert ( 4052 1082 1114 2 s 2346 4039 0 )); +DATA(insert ( 4052 1082 1114 3 s 2347 4039 0 )); +DATA(insert ( 4052 1082 1114 4 s 2348 4039 0 )); +DATA(insert ( 4052 1082 1114 5 s 2349 4039 0 )); + +DATA(insert ( 4052 1082 1184 1 s 2358 4039 0 )); +DATA(insert ( 4052 1082 1184 2 s 2359 4039 0 )); +DATA(insert ( 4052 1082 1184 3 s 2360 4039 0 )); +DATA(insert ( 4052 1082 1184 4 s 2361 4039 0 )); +DATA(insert ( 4052 1082 1184 5 s 2362 4039 0 )); + +DATA(insert ( 4052 1114 1114 1 s 2062 4039 0 )); +DATA(insert ( 4052 1114 1114 2 s 2063 4039 0 )); +DATA(insert ( 4052 1114 1114 3 s 2060 4039 0 )); +DATA(insert ( 4052 1114 1114 4 s 2065 4039 0 )); +DATA(insert ( 4052 1114 1114 5 s 2064 4039 0 )); + +DATA(insert ( 4052 1114 1082 1 s 2371 4039 0 )); +DATA(insert ( 4052 1114 1082 2 s 2372 4039 0 )); +DATA(insert ( 4052 1114 1082 3 s 2373 4039 0 )); +DATA(insert ( 4052 1114 1082 4 s 2374 4039 0 )); +DATA(insert ( 4052 1114 1082 5 s 2375 4039 0 )); + +DATA(insert ( 4052 1114 1184 1 s 2534 4039 0 )); +DATA(insert ( 4052 1114 1184 2 s 2535 4039 0 )); +DATA(insert ( 4052 1114 1184 3 s 2536 4039 0 )); +DATA(insert ( 4052 1114 1184 4 s 2537 4039 0 )); +DATA(insert ( 4052 1114 1184 5 s 2538 4039 0 )); + +DATA(insert ( 4052 1184 1184 1 s 1322 4039 0 )); +DATA(insert ( 4052 1184 1184 2 s 1323 4039 0 )); +DATA(insert ( 4052 1184 1184 3 s 1320 4039 0 )); +DATA(insert ( 4052 1184 1184 4 s 1325 4039 0 )); +DATA(insert ( 4052 1184 1184 5 s 1324 4039 0 )); + +DATA(insert ( 4052 1184 1082 1 s 2384 4039 0 )); +DATA(insert ( 4052 1184 1082 2 s 2385 4039 0 )); +DATA(insert ( 4052 1184 1082 3 s 2386 4039 0 )); +DATA(insert ( 4052 1184 1082 4 s 2387 4039 0 )); +DATA(insert ( 4052 1184 1082 5 s 2388 4039 0 )); + +DATA(insert ( 4052 1184 1114 1 s 2540 4039 0 )); +DATA(insert ( 4052 1184 1114 2 s 2541 4039 0 )); +DATA(insert ( 4052 1184 1114 3 s 2542 4039 0 )); +DATA(insert ( 4052 1184 1114 4 s 2543 4039 0 )); +DATA(insert ( 4052 1184 1114 5 s 2544 4039 0 )); + +DATA(insert ( 4053 700 700 1 s 622 4039 0 )); +DATA(insert ( 4053 700 700 2 s 624 4039 0 )); +DATA(insert ( 4053 700 700 3 s 620 4039 0 )); +DATA(insert ( 4053 700 700 4 s 625 4039 0 )); +DATA(insert ( 4053 700 700 5 s 623 4039 0 )); + +DATA(insert ( 4053 700 701 1 s 1122 4039 0 )); +DATA(insert ( 4053 700 701 2 s 1124 4039 0 )); +DATA(insert ( 4053 700 701 3 s 1120 4039 0 )); +DATA(insert ( 4053 700 701 4 s 1125 4039 0 )); +DATA(insert ( 4053 700 701 5 s 1123 4039 0 )); + +DATA(insert ( 4053 701 701 1 s 672 4039 0 )); +DATA(insert ( 4053 701 701 2 s 673 4039 0 )); +DATA(insert ( 4053 701 701 3 s 670 4039 0 )); +DATA(insert ( 4053 701 701 4 s 675 4039 0 )); +DATA(insert ( 4053 701 701 5 s 674 4039 0 )); + +DATA(insert ( 4053 701 700 1 s 1132 4039 0 )); +DATA(insert ( 4053 701 700 2 s 1134 4039 0 )); +DATA(insert ( 4053 701 700 3 s 1130 4039 0 )); +DATA(insert ( 4053 701 700 4 s 1135 4039 0 )); +DATA(insert ( 4053 701 700 5 s 1133 4039 0 )); + +DATA(insert ( 4054 1700 1700 1 s 1754 4039 0 )); +DATA(insert ( 4054 1700 1700 2 s 1755 4039 0 )); +DATA(insert ( 4054 1700 1700 3 s 1752 4039 0 )); +DATA(insert ( 4054 1700 1700 4 s 1757 4039 0 )); +DATA(insert ( 4054 1700 1700 5 s 1756 4039 0 )); + +DATA(insert ( 4055 25 25 1 s 664 4039 0 )); +DATA(insert ( 4055 25 25 2 s 665 4039 0 )); +DATA(insert ( 4055 25 25 3 s 98 4039 0 )); +DATA(insert ( 4055 25 25 4 s 667 4039 0 )); +DATA(insert ( 4055 25 25 5 s 666 4039 0 )); + +DATA(insert ( 4056 1042 1042 1 s 1058 4039 0 )); +DATA(insert ( 4056 1042 1042 2 s 1059 4039 0 )); +DATA(insert ( 4056 1042 1042 3 s 1054 4039 0 )); +DATA(insert ( 4056 1042 1042 4 s 1061 4039 0 )); +DATA(insert ( 4056 1042 1042 5 s 1060 4039 0 )); + +DATA(insert ( 4057 1083 1083 1 s 1110 4039 0 )); +DATA(insert ( 4057 1083 1083 2 s 1111 4039 0 )); +DATA(insert ( 4057 1083 1083 3 s 1108 4039 0 )); +DATA(insert ( 4057 1083 1083 4 s 1113 4039 0 )); +DATA(insert ( 4057 1083 1083 5 s 1112 4039 0 )); + +DATA(insert ( 4058 1266 1266 1 s 1552 4039 0 )); +DATA(insert ( 4058 1266 1266 2 s 1553 4039 0 )); +DATA(insert ( 4058 1266 1266 3 s 1550 4039 0 )); +DATA(insert ( 4058 1266 1266 4 s 1555 4039 0 )); +DATA(insert ( 4058 1266 1266 5 s 1554 4039 0 )); + +DATA(insert ( 4059 790 790 1 s 902 4039 0 )); +DATA(insert ( 4059 790 790 2 s 904 4039 0 )); +DATA(insert ( 4059 790 790 3 s 900 4039 0 )); +DATA(insert ( 4059 790 790 4 s 905 4039 0 )); +DATA(insert ( 4059 790 790 5 s 903 4039 0 )); + +DATA(insert ( 4060 1186 1186 1 s 1332 4039 0 )); +DATA(insert ( 4060 1186 1186 2 s 1333 4039 0 )); +DATA(insert ( 4060 1186 1186 3 s 1330 4039 0 )); +DATA(insert ( 4060 1186 1186 4 s 1335 4039 0 )); +DATA(insert ( 4060 1186 1186 5 s 1334 4039 0 )); + +DATA(insert ( 4061 704 704 1 s 813 4039 0 )); +DATA(insert ( 4061 704 704 2 s 815 4039 0 )); +DATA(insert ( 4061 704 704 3 s 811 4039 0 )); +DATA(insert ( 4061 704 704 4 s 816 4039 0 )); +DATA(insert ( 4061 704 704 5 s 814 4039 0 )); + +DATA(insert ( 4062 5545 5545 1 s 5515 4039 0 )); +DATA(insert ( 4062 5545 5545 2 s 5516 4039 0 )); +DATA(insert ( 4062 5545 5545 3 s 5513 4039 0 )); +DATA(insert ( 4062 5545 5545 4 s 5518 4039 0 )); +DATA(insert ( 4062 5545 5545 5 s 5517 4039 0 )); + +DATA(insert ( 4063 16 16 1 s 58 4039 0 )); +DATA(insert ( 4063 16 16 2 s 1694 4039 0 )); +DATA(insert ( 4063 16 16 3 s 91 4039 0 )); +DATA(insert ( 4063 16 16 4 s 1695 4039 0 )); +DATA(insert ( 4063 16 16 5 s 59 4039 0 )); + +DATA(insert ( 4064 9003 9003 1 s 5552 4039 0 )); +DATA(insert ( 4064 9003 9003 2 s 5553 4039 0 )); +DATA(insert ( 4064 9003 9003 3 s 5550 4039 0 )); +DATA(insert ( 4064 9003 9003 4 s 5549 4039 0 )); +DATA(insert ( 4064 9003 9003 5 s 5554 4039 0 )); + +/* cbtree, fake data just make index work */ +DATA(insert ( 4250 21 21 1 s 95 4239 0 )); +DATA(insert ( 4250 21 21 2 s 522 4239 0 )); +DATA(insert ( 4250 21 21 3 s 94 4239 0 )); +DATA(insert ( 4250 21 21 4 s 524 4239 0 )); +DATA(insert ( 4250 21 21 5 s 520 4239 0 )); + +DATA(insert ( 4250 21 23 1 s 534 4239 0 )); +DATA(insert ( 4250 21 23 2 s 540 4239 0 )); +DATA(insert ( 4250 21 23 3 s 532 4239 0 )); +DATA(insert ( 4250 21 23 4 s 542 4239 0 )); +DATA(insert ( 4250 21 23 5 s 536 4239 0 )); + +DATA(insert ( 4250 21 20 1 s 1864 4239 0 )); +DATA(insert ( 4250 21 20 2 s 1866 4239 0 )); +DATA(insert ( 4250 21 20 3 s 1862 4239 0 )); +DATA(insert ( 4250 21 20 4 s 1867 4239 0 )); +DATA(insert ( 4250 21 20 5 s 1865 4239 0 )); + +DATA(insert ( 4250 23 23 1 s 97 4239 0 )); +DATA(insert ( 4250 23 23 2 s 523 4239 0 )); +DATA(insert ( 4250 23 23 3 s 96 4239 0 )); +DATA(insert ( 4250 23 23 4 s 525 4239 0 )); +DATA(insert ( 4250 23 23 5 s 521 4239 0 )); + +DATA(insert ( 4250 23 21 1 s 535 4239 0 )); +DATA(insert ( 4250 23 21 2 s 541 4239 0 )); +DATA(insert ( 4250 23 21 3 s 533 4239 0 )); +DATA(insert ( 4250 23 21 4 s 543 4239 0 )); +DATA(insert ( 4250 23 21 5 s 537 4239 0 )); + +DATA(insert ( 4250 23 20 1 s 37 4239 0 )); +DATA(insert ( 4250 23 20 2 s 80 4239 0 )); +DATA(insert ( 4250 23 20 3 s 15 4239 0 )); +DATA(insert ( 4250 23 20 4 s 82 4239 0 )); +DATA(insert ( 4250 23 20 5 s 76 4239 0 )); + +DATA(insert ( 4250 20 20 1 s 412 4239 0 )); +DATA(insert ( 4250 20 20 2 s 414 4239 0 )); +DATA(insert ( 4250 20 20 3 s 410 4239 0 )); +DATA(insert ( 4250 20 20 4 s 415 4239 0 )); +DATA(insert ( 4250 20 20 5 s 413 4239 0 )); + +DATA(insert ( 4250 20 21 1 s 1870 4239 0 )); +DATA(insert ( 4250 20 21 2 s 1872 4239 0 )); +DATA(insert ( 4250 20 21 3 s 1868 4239 0 )); +DATA(insert ( 4250 20 21 4 s 1873 4239 0 )); +DATA(insert ( 4250 20 21 5 s 1871 4239 0 )); + +DATA(insert ( 4250 20 23 1 s 418 4239 0 )); +DATA(insert ( 4250 20 23 2 s 420 4239 0 )); +DATA(insert ( 4250 20 23 3 s 416 4239 0 )); +DATA(insert ( 4250 20 23 4 s 430 4239 0 )); +DATA(insert ( 4250 20 23 5 s 419 4239 0 )); + +DATA(insert ( 4251 26 26 1 s 609 4239 0 )); +DATA(insert ( 4251 26 26 2 s 611 4239 0 )); +DATA(insert ( 4251 26 26 3 s 607 4239 0 )); +DATA(insert ( 4251 26 26 4 s 612 4239 0 )); +DATA(insert ( 4251 26 26 5 s 610 4239 0 )); + +DATA(insert ( 4252 1082 1082 1 s 1095 4239 0 )); +DATA(insert ( 4252 1082 1082 2 s 1096 4239 0 )); +DATA(insert ( 4252 1082 1082 3 s 1093 4239 0 )); +DATA(insert ( 4252 1082 1082 4 s 1098 4239 0 )); +DATA(insert ( 4252 1082 1082 5 s 1097 4239 0 )); + +DATA(insert ( 4252 1082 1114 1 s 2345 4239 0 )); +DATA(insert ( 4252 1082 1114 2 s 2346 4239 0 )); +DATA(insert ( 4252 1082 1114 3 s 2347 4239 0 )); +DATA(insert ( 4252 1082 1114 4 s 2348 4239 0 )); +DATA(insert ( 4252 1082 1114 5 s 2349 4239 0 )); + +DATA(insert ( 4252 1082 1184 1 s 2358 4239 0 )); +DATA(insert ( 4252 1082 1184 2 s 2359 4239 0 )); +DATA(insert ( 4252 1082 1184 3 s 2360 4239 0 )); +DATA(insert ( 4252 1082 1184 4 s 2361 4239 0 )); +DATA(insert ( 4252 1082 1184 5 s 2362 4239 0 )); + +DATA(insert ( 4252 1114 1114 1 s 2062 4239 0 )); +DATA(insert ( 4252 1114 1114 2 s 2063 4239 0 )); +DATA(insert ( 4252 1114 1114 3 s 2060 4239 0 )); +DATA(insert ( 4252 1114 1114 4 s 2065 4239 0 )); +DATA(insert ( 4252 1114 1114 5 s 2064 4239 0 )); + +DATA(insert ( 4252 1114 1082 1 s 2371 4239 0 )); +DATA(insert ( 4252 1114 1082 2 s 2372 4239 0 )); +DATA(insert ( 4252 1114 1082 3 s 2373 4239 0 )); +DATA(insert ( 4252 1114 1082 4 s 2374 4239 0 )); +DATA(insert ( 4252 1114 1082 5 s 2375 4239 0 )); + +DATA(insert ( 4252 1114 1184 1 s 2534 4239 0 )); +DATA(insert ( 4252 1114 1184 2 s 2535 4239 0 )); +DATA(insert ( 4252 1114 1184 3 s 2536 4239 0 )); +DATA(insert ( 4252 1114 1184 4 s 2537 4239 0 )); +DATA(insert ( 4252 1114 1184 5 s 2538 4239 0 )); + +DATA(insert ( 4252 1184 1184 1 s 1322 4239 0 )); +DATA(insert ( 4252 1184 1184 2 s 1323 4239 0 )); +DATA(insert ( 4252 1184 1184 3 s 1320 4239 0 )); +DATA(insert ( 4252 1184 1184 4 s 1325 4239 0 )); +DATA(insert ( 4252 1184 1184 5 s 1324 4239 0 )); + +DATA(insert ( 4252 1184 1082 1 s 2384 4239 0 )); +DATA(insert ( 4252 1184 1082 2 s 2385 4239 0 )); +DATA(insert ( 4252 1184 1082 3 s 2386 4239 0 )); +DATA(insert ( 4252 1184 1082 4 s 2387 4239 0 )); +DATA(insert ( 4252 1184 1082 5 s 2388 4239 0 )); + +DATA(insert ( 4252 1184 1114 1 s 2540 4239 0 )); +DATA(insert ( 4252 1184 1114 2 s 2541 4239 0 )); +DATA(insert ( 4252 1184 1114 3 s 2542 4239 0 )); +DATA(insert ( 4252 1184 1114 4 s 2543 4239 0 )); +DATA(insert ( 4252 1184 1114 5 s 2544 4239 0 )); + +DATA(insert ( 4253 700 700 1 s 622 4239 0 )); +DATA(insert ( 4253 700 700 2 s 624 4239 0 )); +DATA(insert ( 4253 700 700 3 s 620 4239 0 )); +DATA(insert ( 4253 700 700 4 s 625 4239 0 )); +DATA(insert ( 4253 700 700 5 s 623 4239 0 )); + +DATA(insert ( 4253 700 701 1 s 1122 4239 0 )); +DATA(insert ( 4253 700 701 2 s 1124 4239 0 )); +DATA(insert ( 4253 700 701 3 s 1120 4239 0 )); +DATA(insert ( 4253 700 701 4 s 1125 4239 0 )); +DATA(insert ( 4253 700 701 5 s 1123 4239 0 )); + +DATA(insert ( 4253 701 701 1 s 672 4239 0 )); +DATA(insert ( 4253 701 701 2 s 673 4239 0 )); +DATA(insert ( 4253 701 701 3 s 670 4239 0 )); +DATA(insert ( 4253 701 701 4 s 675 4239 0 )); +DATA(insert ( 4253 701 701 5 s 674 4239 0 )); + +DATA(insert ( 4253 701 700 1 s 1132 4239 0 )); +DATA(insert ( 4253 701 700 2 s 1134 4239 0 )); +DATA(insert ( 4253 701 700 3 s 1130 4239 0 )); +DATA(insert ( 4253 701 700 4 s 1135 4239 0 )); +DATA(insert ( 4253 701 700 5 s 1133 4239 0 )); + +DATA(insert ( 4254 1700 1700 1 s 1754 4239 0 )); +DATA(insert ( 4254 1700 1700 2 s 1755 4239 0 )); +DATA(insert ( 4254 1700 1700 3 s 1752 4239 0 )); +DATA(insert ( 4254 1700 1700 4 s 1757 4239 0 )); +DATA(insert ( 4254 1700 1700 5 s 1756 4239 0 )); + +DATA(insert ( 4255 25 25 1 s 664 4239 0 )); +DATA(insert ( 4255 25 25 2 s 665 4239 0 )); +DATA(insert ( 4255 25 25 3 s 98 4239 0 )); +DATA(insert ( 4255 25 25 4 s 667 4239 0 )); +DATA(insert ( 4255 25 25 5 s 666 4239 0 )); + +DATA(insert ( 4256 1042 1042 1 s 1058 4239 0 )); +DATA(insert ( 4256 1042 1042 2 s 1059 4239 0 )); +DATA(insert ( 4256 1042 1042 3 s 1054 4239 0 )); +DATA(insert ( 4256 1042 1042 4 s 1061 4239 0 )); +DATA(insert ( 4256 1042 1042 5 s 1060 4239 0 )); + +DATA(insert ( 4257 1083 1083 1 s 1110 4239 0 )); +DATA(insert ( 4257 1083 1083 2 s 1111 4239 0 )); +DATA(insert ( 4257 1083 1083 3 s 1108 4239 0 )); +DATA(insert ( 4257 1083 1083 4 s 1113 4239 0 )); +DATA(insert ( 4257 1083 1083 5 s 1112 4239 0 )); + +DATA(insert ( 4258 1266 1266 1 s 1552 4239 0 )); +DATA(insert ( 4258 1266 1266 2 s 1553 4239 0 )); +DATA(insert ( 4258 1266 1266 3 s 1550 4239 0 )); +DATA(insert ( 4258 1266 1266 4 s 1555 4239 0 )); +DATA(insert ( 4258 1266 1266 5 s 1554 4239 0 )); + +DATA(insert ( 4259 790 790 1 s 902 4239 0 )); +DATA(insert ( 4259 790 790 2 s 904 4239 0 )); +DATA(insert ( 4259 790 790 3 s 900 4239 0 )); +DATA(insert ( 4259 790 790 4 s 905 4239 0 )); +DATA(insert ( 4259 790 790 5 s 903 4239 0 )); + +DATA(insert ( 4260 1186 1186 1 s 1332 4239 0 )); +DATA(insert ( 4260 1186 1186 2 s 1333 4239 0 )); +DATA(insert ( 4260 1186 1186 3 s 1330 4239 0 )); +DATA(insert ( 4260 1186 1186 4 s 1335 4239 0 )); +DATA(insert ( 4260 1186 1186 5 s 1334 4239 0 )); + +DATA(insert ( 4261 704 704 1 s 813 4239 0 )); +DATA(insert ( 4261 704 704 2 s 815 4239 0 )); +DATA(insert ( 4261 704 704 3 s 811 4239 0 )); +DATA(insert ( 4261 704 704 4 s 816 4239 0 )); +DATA(insert ( 4261 704 704 5 s 814 4239 0 )); + +DATA(insert ( 4262 5545 5545 1 s 5515 4239 0 )); +DATA(insert ( 4262 5545 5545 2 s 5516 4239 0 )); +DATA(insert ( 4262 5545 5545 3 s 5513 4239 0 )); +DATA(insert ( 4262 5545 5545 4 s 5518 4239 0 )); +DATA(insert ( 4262 5545 5545 5 s 5517 4239 0 )); + +DATA(insert ( 4263 16 16 1 s 58 4239 0 )); +DATA(insert ( 4263 16 16 2 s 1694 4239 0 )); +DATA(insert ( 4263 16 16 3 s 91 4239 0 )); +DATA(insert ( 4263 16 16 4 s 1695 4239 0 )); +DATA(insert ( 4263 16 16 5 s 59 4239 0 )); + +DATA(insert ( 4264 9003 9003 1 s 5552 4239 0 )); +DATA(insert ( 4264 9003 9003 2 s 5553 4239 0 )); +DATA(insert ( 4264 9003 9003 3 s 5550 4239 0 )); +DATA(insert ( 4264 9003 9003 4 s 5549 4239 0 )); +DATA(insert ( 4264 9003 9003 5 s 5554 4239 0 )); + +#endif /* PG_AMOP_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_amproc.h postgresql-hll-2.14/include/include/catalog/pg_amproc.h --- postgresql-hll-2.14_old/include/include/catalog/pg_amproc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_amproc.h 2020-12-12 17:06:43.152346813 +0800 @@ -0,0 +1,501 @@ +/* ------------------------------------------------------------------------- + * + * pg_amproc.h + * definition of the system "amproc" relation (pg_amproc) + * along with the relation's initial contents. + * + * The amproc table identifies support procedures associated with index + * operator families and classes. These procedures can't be listed in pg_amop + * since they are not the implementation of any indexable operator. + * + * The primary key for this table is . The "default" support functions for a + * particular opclass within the family are those with amproclefttype = + * amprocrighttype = opclass's opcintype. These are the ones loaded into the + * relcache for an index and typically used for internal index operations. + * Other support functions are typically used to handle cross-type indexable + * operators with oprleft/oprright matching the entry's amproclefttype and + * amprocrighttype. The exact behavior depends on the index AM, however, and + * some don't pay attention to non-default functions at all. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_amproc.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AMPROC_H +#define PG_AMPROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_amproc definition. cpp turns this into + * typedef struct FormData_pg_amproc + * ---------------- + */ +#define AccessMethodProcedureRelationId 2603 +#define AccessMethodProcedureRelation_Rowtype_Id 10920 + +CATALOG(pg_amproc,2603) BKI_SCHEMA_MACRO +{ + Oid amprocfamily; /* the index opfamily this entry is for */ + Oid amproclefttype; /* procedure's left input data type */ + Oid amprocrighttype; /* procedure's right input data type */ + int2 amprocnum; /* support procedure index */ + regproc amproc; /* OID of the proc */ +} FormData_pg_amproc; + +/* ---------------- + * Form_pg_amproc corresponds to a pointer to a tuple with + * the format of pg_amproc relation. + * ---------------- + */ +typedef FormData_pg_amproc *Form_pg_amproc; + +/* ---------------- + * compiler constants for pg_amproc + * ---------------- + */ +#define Natts_pg_amproc 5 +#define Anum_pg_amproc_amprocfamily 1 +#define Anum_pg_amproc_amproclefttype 2 +#define Anum_pg_amproc_amprocrighttype 3 +#define Anum_pg_amproc_amprocnum 4 +#define Anum_pg_amproc_amproc 5 + +/* ---------------- + * initial contents of pg_amproc + * ---------------- + */ + +/* btree */ +DATA(insert ( 397 2277 2277 1 382 )); +DATA(insert ( 421 702 702 1 357 )); +DATA(insert ( 423 1560 1560 1 1596 )); +DATA(insert ( 424 16 16 1 1693 )); +DATA(insert ( 426 1042 1042 1 1078 )); +DATA(insert ( 426 1042 1042 2 3256 )); +DATA(insert ( 428 17 17 1 1954 )); +DATA(insert ( 428 17 17 2 3452 )); +DATA(insert ( 429 18 18 1 358 )); +DATA(insert ( 434 1082 1082 1 1092 )); +DATA(insert ( 434 1082 1082 2 3136 )); +DATA(insert ( 434 1082 1114 1 2344 )); +DATA(insert ( 434 1082 1184 1 2357 )); +DATA(insert ( 434 1114 1114 1 2045 )); +DATA(insert ( 434 1114 1114 2 3137 )); +DATA(insert ( 434 1114 1082 1 2370 )); +DATA(insert ( 434 1114 1184 1 2526 )); +DATA(insert ( 434 1184 1184 1 1314 )); +DATA(insert ( 434 1184 1184 2 3137 )); +DATA(insert ( 434 1184 1082 1 2383 )); +DATA(insert ( 434 1184 1114 1 2533 )); +DATA(insert ( 436 4402 4402 1 4418 )); +DATA(insert ( 436 4402 4402 2 3452 )); +DATA(insert ( 1970 700 700 1 354 )); +DATA(insert ( 1970 700 700 2 3132 )); +DATA(insert ( 1970 700 701 1 2194 )); +DATA(insert ( 1970 701 701 1 355 )); +DATA(insert ( 1970 701 701 2 3133 )); +DATA(insert ( 1970 701 700 1 2195 )); +DATA(insert ( 1974 869 869 1 926 )); +DATA(insert ( 1976 21 21 1 350 )); +DATA(insert ( 1976 21 21 2 3129 )); +DATA(insert ( 1976 21 23 1 2190 )); +DATA(insert ( 1976 21 20 1 2192 )); +DATA(insert ( 1976 23 23 1 351 )); +DATA(insert ( 1976 23 23 2 3130 )); +DATA(insert ( 1976 23 20 1 2188 )); +DATA(insert ( 1976 23 21 1 2191 )); +DATA(insert ( 1976 20 20 1 842 )); +DATA(insert ( 1976 20 20 2 3131 )); +DATA(insert ( 1976 20 23 1 2189 )); +DATA(insert ( 1976 20 21 1 2193 )); +DATA(insert ( 1982 1186 1186 1 1315 )); +DATA(insert ( 1984 829 829 1 836 )); +DATA(insert ( 1986 19 19 1 359 )); +DATA(insert ( 1986 19 19 2 3135 )); +DATA(insert ( 1988 1700 1700 1 1769 )); +DATA(insert ( 1988 1700 1700 2 3283 )); +DATA(insert ( 1989 26 26 1 356 )); +DATA(insert ( 1989 26 26 2 3134 )); +DATA(insert ( 1991 30 30 1 404 )); +DATA(insert ( 2994 2249 2249 1 2987 )); +DATA(insert ( 1994 25 25 1 360 )); +DATA(insert ( 1994 25 25 2 3255 )); +DATA(insert ( 1996 1083 1083 1 1107 )); +DATA(insert ( 2000 1266 1266 1 1358 )); +DATA(insert ( 2002 1562 1562 1 1672 )); +DATA(insert ( 2095 25 25 1 2166 )); +DATA(insert ( 2097 1042 1042 1 2180 )); +DATA(insert ( 2099 790 790 1 377 )); +DATA(insert ( 2233 703 703 1 380 )); +DATA(insert ( 2234 704 704 1 381 )); +DATA(insert ( 2789 27 27 1 2794 )); +DATA(insert ( 2968 2950 2950 1 2960 )); +DATA(insert ( 3522 3500 3500 1 3514 )); + +DATA(insert ( 3806 86 86 1 3475 )); +DATA(insert ( 3807 86 86 1 456 )); +DATA(insert ( 5535 5545 5545 1 5519 )); +DATA(insert ( 5536 5545 5545 1 5520 )); +/* hash */ +DATA(insert ( 427 1042 1042 1 1080 )); +DATA(insert ( 431 18 18 1 454 )); +DATA(insert ( 435 1082 1082 1 450 )); +DATA(insert ( 627 2277 2277 1 626 )); +DATA(insert ( 1971 700 700 1 451 )); +DATA(insert ( 1971 701 701 1 452 )); +DATA(insert ( 1975 869 869 1 422 )); +DATA(insert ( 1977 21 21 1 449 )); +DATA(insert ( 1977 23 23 1 450 )); +DATA(insert ( 1977 20 20 1 949 )); +DATA(insert ( 1983 1186 1186 1 1697 )); +DATA(insert ( 1985 829 829 1 399 )); +DATA(insert ( 1987 19 19 1 455 )); +DATA(insert ( 1990 26 26 1 453 )); +DATA(insert ( 1992 30 30 1 457 )); +DATA(insert ( 1995 25 25 1 400 )); +DATA(insert ( 1997 1083 1083 1 1688 )); +DATA(insert ( 1998 1700 1700 1 432 )); +DATA(insert ( 1999 1184 1184 1 2039 )); +DATA(insert ( 2001 1266 1266 1 1696 )); +DATA(insert ( 2040 1114 1114 1 2039 )); +DATA(insert ( 2222 16 16 1 454 )); +DATA(insert ( 2223 17 17 1 456 )); +DATA(insert ( 4470 4402 4402 1 456 )); +DATA(insert ( 2224 22 22 1 398 )); +DATA(insert ( 2225 28 28 1 949 )); +DATA(insert ( 2226 29 29 1 450 )); +DATA(insert ( 2227 702 702 1 450 )); +DATA(insert ( 2228 703 703 1 450 )); +DATA(insert ( 2229 25 25 1 400 )); +DATA(insert ( 2231 1042 1042 1 1080 )); +DATA(insert ( 2232 31 31 1 450 )); +DATA(insert ( 2235 1033 1033 1 329 )); +DATA(insert ( 2969 2950 2950 1 2963 )); +DATA(insert ( 3523 3500 3500 1 3515 )); + + +/* gist */ +DATA(insert ( 2593 603 603 1 2578 )); +DATA(insert ( 2593 603 603 2 2583 )); +DATA(insert ( 2593 603 603 3 2579 )); +DATA(insert ( 2593 603 603 4 2580 )); +DATA(insert ( 2593 603 603 5 2581 )); +DATA(insert ( 2593 603 603 6 2582 )); +DATA(insert ( 2593 603 603 7 2584 )); +DATA(insert ( 2594 604 604 1 2585 )); +DATA(insert ( 2594 604 604 2 2583 )); +DATA(insert ( 2594 604 604 3 2586 )); +DATA(insert ( 2594 604 604 4 2580 )); +DATA(insert ( 2594 604 604 5 2581 )); +DATA(insert ( 2594 604 604 6 2582 )); +DATA(insert ( 2594 604 604 7 2584 )); +DATA(insert ( 2595 718 718 1 2591 )); +DATA(insert ( 2595 718 718 2 2583 )); +DATA(insert ( 2595 718 718 3 2592 )); +DATA(insert ( 2595 718 718 4 2580 )); +DATA(insert ( 2595 718 718 5 2581 )); +DATA(insert ( 2595 718 718 6 2582 )); +DATA(insert ( 2595 718 718 7 2584 )); +DATA(insert ( 3655 3614 3614 1 3654 )); +DATA(insert ( 3655 3614 3614 2 3651 )); +DATA(insert ( 3655 3614 3614 3 3648 )); +DATA(insert ( 3655 3614 3614 4 3649 )); +DATA(insert ( 3655 3614 3614 5 3653 )); +DATA(insert ( 3655 3614 3614 6 3650 )); +DATA(insert ( 3655 3614 3614 7 3652 )); +DATA(insert ( 3702 3615 3615 1 3701 )); +DATA(insert ( 3702 3615 3615 2 3698 )); +DATA(insert ( 3702 3615 3615 3 3695 )); +DATA(insert ( 3702 3615 3615 4 3696 )); +DATA(insert ( 3702 3615 3615 5 3700 )); +DATA(insert ( 3702 3615 3615 6 3697 )); +DATA(insert ( 3702 3615 3615 7 3699 )); +DATA(insert ( 1029 600 600 1 2179 )); +DATA(insert ( 1029 600 600 2 2583 )); +DATA(insert ( 1029 600 600 3 1030 )); +DATA(insert ( 1029 600 600 4 2580 )); +DATA(insert ( 1029 600 600 5 2581 )); +DATA(insert ( 1029 600 600 6 2582 )); +DATA(insert ( 1029 600 600 7 2584 )); +DATA(insert ( 1029 600 600 8 3064 )); + + +/* gin */ +DATA(insert ( 2745 1007 1007 1 351 )); +DATA(insert ( 2745 1007 1007 2 2743 )); +DATA(insert ( 2745 1007 1007 3 2774 )); +DATA(insert ( 2745 1007 1007 4 2744 )); +DATA(insert ( 2745 1007 1007 6 3920 )); +DATA(insert ( 2745 1009 1009 1 360 )); +DATA(insert ( 2745 1009 1009 2 2743 )); +DATA(insert ( 2745 1009 1009 3 2774 )); +DATA(insert ( 2745 1009 1009 4 2744 )); +DATA(insert ( 2745 1009 1009 6 3920 )); +DATA(insert ( 2745 1015 1015 1 360 )); +DATA(insert ( 2745 1015 1015 2 2743 )); +DATA(insert ( 2745 1015 1015 3 2774 )); +DATA(insert ( 2745 1015 1015 4 2744 )); +DATA(insert ( 2745 1015 1015 6 3920 )); +DATA(insert ( 2745 1023 1023 1 357 )); +DATA(insert ( 2745 1023 1023 2 2743 )); +DATA(insert ( 2745 1023 1023 3 2774 )); +DATA(insert ( 2745 1023 1023 4 2744 )); +DATA(insert ( 2745 1023 1023 6 3920 )); +DATA(insert ( 2745 1561 1561 1 1596 )); +DATA(insert ( 2745 1561 1561 2 2743 )); +DATA(insert ( 2745 1561 1561 3 2774 )); +DATA(insert ( 2745 1561 1561 4 2744 )); +DATA(insert ( 2745 1561 1561 6 3920 )); +DATA(insert ( 2745 1000 1000 1 1693 )); +DATA(insert ( 2745 1000 1000 2 2743 )); +DATA(insert ( 2745 1000 1000 3 2774 )); +DATA(insert ( 2745 1000 1000 4 2744 )); +DATA(insert ( 2745 1000 1000 6 3920 )); +DATA(insert ( 2745 1014 1014 1 1078 )); +DATA(insert ( 2745 1014 1014 2 2743 )); +DATA(insert ( 2745 1014 1014 3 2774 )); +DATA(insert ( 2745 1014 1014 4 2744 )); +DATA(insert ( 2745 1014 1014 6 3920 )); +DATA(insert ( 2745 1001 1001 1 1954 )); +DATA(insert ( 2745 1001 1001 2 2743 )); +DATA(insert ( 2745 1001 1001 3 2774 )); +DATA(insert ( 2745 1001 1001 4 2744 )); +DATA(insert ( 2745 1001 1001 6 3920 )); +DATA(insert ( 2745 1002 1002 1 358 )); +DATA(insert ( 2745 1002 1002 2 2743 )); +DATA(insert ( 2745 1002 1002 3 2774 )); +DATA(insert ( 2745 1002 1002 4 2744 )); +DATA(insert ( 2745 1002 1002 6 3920 )); +DATA(insert ( 2745 1182 1182 1 1092 )); +DATA(insert ( 2745 1182 1182 2 2743 )); +DATA(insert ( 2745 1182 1182 3 2774 )); +DATA(insert ( 2745 1182 1182 4 2744 )); +DATA(insert ( 2745 1182 1182 6 3920 )); +DATA(insert ( 2745 1021 1021 1 354 )); +DATA(insert ( 2745 1021 1021 2 2743 )); +DATA(insert ( 2745 1021 1021 3 2774 )); +DATA(insert ( 2745 1021 1021 4 2744 )); +DATA(insert ( 2745 1021 1021 6 3920 )); +DATA(insert ( 2745 1022 1022 1 355 )); +DATA(insert ( 2745 1022 1022 2 2743 )); +DATA(insert ( 2745 1022 1022 3 2774 )); +DATA(insert ( 2745 1022 1022 4 2744 )); +DATA(insert ( 2745 1022 1022 6 3920 )); +DATA(insert ( 2745 1041 1041 1 926 )); +DATA(insert ( 2745 1041 1041 2 2743 )); +DATA(insert ( 2745 1041 1041 3 2774 )); +DATA(insert ( 2745 1041 1041 4 2744 )); +DATA(insert ( 2745 1041 1041 6 3920 )); +DATA(insert ( 2745 651 651 1 926 )); +DATA(insert ( 2745 651 651 2 2743 )); +DATA(insert ( 2745 651 651 3 2774 )); +DATA(insert ( 2745 651 651 4 2744 )); +DATA(insert ( 2745 651 651 6 3920 )); +DATA(insert ( 2745 1005 1005 1 350 )); +DATA(insert ( 2745 1005 1005 2 2743 )); +DATA(insert ( 2745 1005 1005 3 2774 )); +DATA(insert ( 2745 1005 1005 4 2744 )); +DATA(insert ( 2745 1005 1005 6 3920 )); +DATA(insert ( 2745 1016 1016 1 842 )); +DATA(insert ( 2745 1016 1016 2 2743 )); +DATA(insert ( 2745 1016 1016 3 2774 )); +DATA(insert ( 2745 1016 1016 4 2744 )); +DATA(insert ( 2745 1016 1016 6 3920 )); +DATA(insert ( 2745 1187 1187 1 1315 )); +DATA(insert ( 2745 1187 1187 2 2743 )); +DATA(insert ( 2745 1187 1187 3 2774 )); +DATA(insert ( 2745 1187 1187 4 2744 )); +DATA(insert ( 2745 1187 1187 6 3920 )); +DATA(insert ( 2745 1040 1040 1 836 )); +DATA(insert ( 2745 1040 1040 2 2743 )); +DATA(insert ( 2745 1040 1040 3 2774 )); +DATA(insert ( 2745 1040 1040 4 2744 )); +DATA(insert ( 2745 1040 1040 6 3920 )); +DATA(insert ( 2745 1003 1003 1 359 )); +DATA(insert ( 2745 1003 1003 2 2743 )); +DATA(insert ( 2745 1003 1003 3 2774 )); +DATA(insert ( 2745 1003 1003 4 2744 )); +DATA(insert ( 2745 1003 1003 6 3920 )); +DATA(insert ( 2745 1231 1231 1 1769 )); +DATA(insert ( 2745 1231 1231 2 2743 )); +DATA(insert ( 2745 1231 1231 3 2774 )); +DATA(insert ( 2745 1231 1231 4 2744 )); +DATA(insert ( 2745 1231 1231 6 3920 )); +DATA(insert ( 2745 1028 1028 1 356 )); +DATA(insert ( 2745 1028 1028 2 2743 )); +DATA(insert ( 2745 1028 1028 3 2774 )); +DATA(insert ( 2745 1028 1028 4 2744 )); +DATA(insert ( 2745 1028 1028 6 3920 )); +DATA(insert ( 2745 1013 1013 1 404 )); +DATA(insert ( 2745 1013 1013 2 2743 )); +DATA(insert ( 2745 1013 1013 3 2774 )); +DATA(insert ( 2745 1013 1013 4 2744 )); +DATA(insert ( 2745 1013 1013 6 3920 )); +DATA(insert ( 2745 1183 1183 1 1107 )); +DATA(insert ( 2745 1183 1183 2 2743 )); +DATA(insert ( 2745 1183 1183 3 2774 )); +DATA(insert ( 2745 1183 1183 4 2744 )); +DATA(insert ( 2745 1183 1183 6 3920 )); +DATA(insert ( 2745 1185 1185 1 1314 )); +DATA(insert ( 2745 1185 1185 2 2743 )); +DATA(insert ( 2745 1185 1185 3 2774 )); +DATA(insert ( 2745 1185 1185 4 2744 )); +DATA(insert ( 2745 1185 1185 6 3920 )); +DATA(insert ( 2745 1270 1270 1 1358 )); +DATA(insert ( 2745 1270 1270 2 2743 )); +DATA(insert ( 2745 1270 1270 3 2774 )); +DATA(insert ( 2745 1270 1270 4 2744 )); +DATA(insert ( 2745 1270 1270 6 3920 )); +DATA(insert ( 2745 1563 1563 1 1672 )); +DATA(insert ( 2745 1563 1563 2 2743 )); +DATA(insert ( 2745 1563 1563 3 2774 )); +DATA(insert ( 2745 1563 1563 4 2744 )); +DATA(insert ( 2745 1563 1563 6 3920 )); +DATA(insert ( 2745 1115 1115 1 2045 )); +DATA(insert ( 2745 1115 1115 2 2743 )); +DATA(insert ( 2745 1115 1115 3 2774 )); +DATA(insert ( 2745 1115 1115 4 2744 )); +DATA(insert ( 2745 1115 1115 6 3920 )); +DATA(insert ( 2745 791 791 1 377 )); +DATA(insert ( 2745 791 791 2 2743 )); +DATA(insert ( 2745 791 791 3 2774 )); +DATA(insert ( 2745 791 791 4 2744 )); +DATA(insert ( 2745 791 791 6 3920 )); +DATA(insert ( 2745 1024 1024 1 380 )); +DATA(insert ( 2745 1024 1024 2 2743 )); +DATA(insert ( 2745 1024 1024 3 2774 )); +DATA(insert ( 2745 1024 1024 4 2744 )); +DATA(insert ( 2745 1024 1024 6 3920 )); +DATA(insert ( 2745 1025 1025 1 381 )); +DATA(insert ( 2745 1025 1025 2 2743 )); +DATA(insert ( 2745 1025 1025 3 2774 )); +DATA(insert ( 2745 1025 1025 4 2744 )); +DATA(insert ( 2745 1025 1025 6 3920 )); +DATA(insert ( 3659 3614 3614 1 3724 )); +DATA(insert ( 3659 3614 3614 2 3656 )); +DATA(insert ( 3659 3614 3614 3 3657 )); +DATA(insert ( 3659 3614 3614 4 3658 )); +DATA(insert ( 3659 3614 3614 5 2700 )); +DATA(insert ( 3659 3614 3614 6 3921 )); +DATA(insert ( 3626 3614 3614 1 3622 )); +DATA(insert ( 3683 3615 3615 1 3668 )); +DATA(insert ( 3901 3831 3831 1 3870 )); +DATA(insert ( 3903 3831 3831 1 3902 )); +DATA(insert ( 3919 3831 3831 1 3875 )); +DATA(insert ( 3919 3831 3831 2 3876 )); +DATA(insert ( 3919 3831 3831 3 3877 )); +DATA(insert ( 3919 3831 3831 4 3878 )); +DATA(insert ( 3919 3831 3831 5 3879 )); +DATA(insert ( 3919 3831 3831 6 3880 )); +DATA(insert ( 3919 3831 3831 7 3881 )); + +/* cgin */ +DATA(insert ( 4446 3614 3614 1 3724 )); +DATA(insert ( 4446 3614 3614 2 3656 )); +DATA(insert ( 4446 3614 3614 3 3657 )); +DATA(insert ( 4446 3614 3614 4 3658 )); +DATA(insert ( 4446 3614 3614 5 2700 )); +DATA(insert ( 4446 3614 3614 6 3921 )); + +/* sp-gist */ +DATA(insert ( 4015 600 600 1 4018 )); +DATA(insert ( 4015 600 600 2 4019 )); +DATA(insert ( 4015 600 600 3 4020 )); +DATA(insert ( 4015 600 600 4 4021 )); +DATA(insert ( 4015 600 600 5 4022 )); +DATA(insert ( 4016 600 600 1 4023 )); +DATA(insert ( 4016 600 600 2 4024 )); +DATA(insert ( 4016 600 600 3 4025 )); +DATA(insert ( 4016 600 600 4 4026 )); +DATA(insert ( 4016 600 600 5 4022 )); +DATA(insert ( 4017 25 25 1 4027 )); +DATA(insert ( 4017 25 25 2 4028 )); +DATA(insert ( 4017 25 25 3 4029 )); +DATA(insert ( 4017 25 25 4 4030 )); +DATA(insert ( 4017 25 25 5 4031 )); +DATA(insert ( 5570 9003 9003 1 5586 )); +DATA(insert ( 5571 9003 9003 1 5587 )); + +/* psort, fake data just make index work */ +DATA(insert ( 4050 21 21 1 350)); +DATA(insert ( 4050 21 23 1 2190)); +DATA(insert ( 4050 21 20 1 2192)); +DATA(insert ( 4050 23 23 1 351)); +DATA(insert ( 4050 23 20 1 2188)); +DATA(insert ( 4050 23 21 1 2191)); +DATA(insert ( 4050 20 20 1 842)); +DATA(insert ( 4050 20 23 1 2189)); +DATA(insert ( 4050 20 21 1 2193)); +DATA(insert ( 4051 26 26 1 356)); +DATA(insert ( 4052 1082 1082 1 1092)); +DATA(insert ( 4052 1082 1114 1 2344)); +DATA(insert ( 4052 1082 1184 1 2357)); +DATA(insert ( 4052 1114 1114 1 2045)); +DATA(insert ( 4052 1114 1082 1 2370)); +DATA(insert ( 4052 1114 1184 1 2526)); +DATA(insert ( 4052 1184 1184 1 1314)); +DATA(insert ( 4052 1184 1082 1 2383)); +DATA(insert ( 4052 1184 1114 1 2533)); +DATA(insert ( 4053 700 700 1 354)); +DATA(insert ( 4053 700 701 1 2194)); +DATA(insert ( 4053 701 701 1 355)); +DATA(insert ( 4053 701 700 1 2195)); +DATA(insert ( 4054 1700 1700 1 1769)); +DATA(insert ( 4055 25 25 1 360)); +DATA(insert ( 4056 1042 1042 1 1078)); +DATA(insert ( 4057 1083 1083 1 1107)); +DATA(insert ( 4058 1266 1266 1 1358)); +DATA(insert ( 4059 790 790 1 377)); +DATA(insert ( 4060 1186 1186 1 1315)); +DATA(insert ( 4061 704 704 1 381)); +DATA(insert ( 4062 5545 5545 1 5519)); +DATA(insert ( 4063 16 16 1 1693)); +DATA(insert ( 4064 9003 9003 1 5586)); + +/* cbtree, fake data just make index work */ +DATA(insert ( 4250 21 21 1 350)); +DATA(insert ( 4250 21 23 1 2190)); +DATA(insert ( 4250 21 20 1 2192)); +DATA(insert ( 4250 23 23 1 351)); +DATA(insert ( 4250 23 20 1 2188)); +DATA(insert ( 4250 23 21 1 2191)); +DATA(insert ( 4250 20 20 1 842)); +DATA(insert ( 4250 20 23 1 2189)); +DATA(insert ( 4250 20 21 1 2193)); +DATA(insert ( 4251 26 26 1 356)); +DATA(insert ( 4252 1082 1082 1 1092)); +DATA(insert ( 4252 1082 1114 1 2344)); +DATA(insert ( 4252 1082 1184 1 2357)); +DATA(insert ( 4252 1114 1114 1 2045)); +DATA(insert ( 4252 1114 1082 1 2370)); +DATA(insert ( 4252 1114 1184 1 2526)); +DATA(insert ( 4252 1184 1184 1 1314)); +DATA(insert ( 4252 1184 1082 1 2383)); +DATA(insert ( 4252 1184 1114 1 2533)); +DATA(insert ( 4253 700 700 1 354)); +DATA(insert ( 4253 700 701 1 2194)); +DATA(insert ( 4253 701 701 1 355)); +DATA(insert ( 4253 701 700 1 2195)); +DATA(insert ( 4254 1700 1700 1 1769)); +DATA(insert ( 4255 25 25 1 360)); +DATA(insert ( 4256 1042 1042 1 1078)); +DATA(insert ( 4257 1083 1083 1 1107)); +DATA(insert ( 4258 1266 1266 1 1358)); +DATA(insert ( 4259 790 790 1 377)); +DATA(insert ( 4260 1186 1186 1 1315)); +DATA(insert ( 4261 704 704 1 381)); +DATA(insert ( 4262 5545 5545 1 5519)); +DATA(insert ( 4263 16 16 1 1693)); +DATA(insert ( 4264 9003 9003 1 5586)); + +#endif /* PG_AMPROC_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_app_workloadgroup_mapping.h postgresql-hll-2.14/include/include/catalog/pg_app_workloadgroup_mapping.h --- postgresql-hll-2.14_old/include/include/catalog/pg_app_workloadgroup_mapping.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_app_workloadgroup_mapping.h 2020-12-12 17:06:43.152346813 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_app_workloadgroup_mapping.h + * define the mapping between application and workload group. + * + * + * IDENTIFICATION + * src/include/catalog/pg_app_workloadgroup_mapping.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_APP_WORKLOADGROUP_MAPPING_H +#define PG_APP_WORKLOADGROUP_MAPPING_H + +#include "catalog/genbki.h" +#include "catalog/pg_workload_group.h" + + +/* define the OID of the table pg_app_workloadgroup_mapping*/ +#define AppWorkloadGroupMappingRelationId 3464 +#define AppWorkloadGroupMappingRelation_Rowtype_Id 3468 + +CATALOG(pg_app_workloadgroup_mapping,3464) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3468) BKI_SCHEMA_MACRO +{ + NameData appname; /*Name of application*/ + NameData workload_gpname; /*Name of workload group*/ +} FormData_pg_app_workloadgroup_mapping; + + +/*------------------------------------------------------------------------- + * Form_pg_app_workloadgroup_mapping corresponds to a pointer to a tuple with + * the format of pg_app_workloadgroup_mapping relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_app_workloadgroup_mapping *Form_pg_app_workloadgroup_mapping; + +/*------------------------------------------------------------------------- + * compiler constants for pg_app_workloadgroup_mapping + *------------------------------------------------------------------------- + */ +#define Natts_pg_app_workloadgroup_mapping 2 +#define Anum_pg_app_workloadgroup_mapping_appname 1 +#define Anum_pg_app_workloadgroup_mapping_wgname 2 + +DATA(insert OID = 10 ("default_application" "default_group")); +#define DEFAULT_APP_OID 10 +#define DEFAULT_APP_NAME "default_application" + +/*default setting for user defined application*/ +#define DEFAULT_WORKLOAD_GROUP DEFAULT_GROUP_NAME +#define DEFAULT_WORKLOAD_GROUP_OID DEFAULT_GROUP_OID + +#endif /* PG_APP_WORKLOADGROUP_MAPPING_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_attrdef.h postgresql-hll-2.14/include/include/catalog/pg_attrdef.h --- postgresql-hll-2.14_old/include/include/catalog/pg_attrdef.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_attrdef.h 2020-12-12 17:06:43.152346813 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_attrdef.h + * definition of the system "attribute defaults" relation (pg_attrdef) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_attrdef.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ATTRDEF_H +#define PG_ATTRDEF_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_attrdef definition. cpp turns this into + * typedef struct FormData_pg_attrdef + * ---------------- + */ +#define AttrDefaultRelationId 2604 +#define AttrDefaultRelation_Rowtype_Id 10000 + +CATALOG(pg_attrdef,2604) BKI_SCHEMA_MACRO +{ + Oid adrelid; /* OID of table containing attribute */ + int2 adnum; /* attnum of attribute */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + pg_node_tree adbin; /* nodeToString representation of default */ + text adsrc; /* human-readable representation of default */ +#endif +} FormData_pg_attrdef; + +/* ---------------- + * Form_pg_attrdef corresponds to a pointer to a tuple with + * the format of pg_attrdef relation. + * ---------------- + */ +typedef FormData_pg_attrdef *Form_pg_attrdef; + +/* ---------------- + * compiler constants for pg_attrdef + * ---------------- + */ +#define Natts_pg_attrdef 4 +#define Anum_pg_attrdef_adrelid 1 +#define Anum_pg_attrdef_adnum 2 +#define Anum_pg_attrdef_adbin 3 +#define Anum_pg_attrdef_adsrc 4 + +#endif /* PG_ATTRDEF_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_attribute.h postgresql-hll-2.14/include/include/catalog/pg_attribute.h --- postgresql-hll-2.14_old/include/include/catalog/pg_attribute.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_attribute.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,235 @@ +/* ------------------------------------------------------------------------- + * + * pg_attribute.h + * definition of the system "attribute" relation (pg_attribute) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_attribute.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ATTRIBUTE_H +#define PG_ATTRIBUTE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_attribute definition. cpp turns this into + * typedef struct FormData_pg_attribute + * + * If you change the following, make sure you change the structs for + * system attributes in catalog/heap.c also. + * You may need to change catalog/genbki.pl as well. + * ---------------- + */ +#define AttributeRelationId 1249 +#define AttributeRelation_Rowtype_Id 75 + +#define IsAttributeRelation(rel) (RelationGetRelid(rel) == AttributeRelationId) +#define IsAttributeCache(cache) ((cache)->cc_reloid == AttributeRelationId) + +CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BKI_SCHEMA_MACRO +{ + Oid attrelid; /* OID of relation containing this attribute */ + NameData attname; /* name of attribute */ + + /* + * atttypid is the OID of the instance in Catalog Class pg_type that + * defines the data type of this attribute (e.g. int4). Information in + * that instance is redundant with the attlen, attbyval, and attalign + * attributes of this instance, so they had better match or Postgres will + * fail. + */ + Oid atttypid; + + /* + * attstattarget is the target number of statistics datapoints to collect + * during VACUUM ANALYZE of this column. A zero here indicates that we do + * not wish to collect any stats about this column. A "-1" here indicates + * that no value has been explicitly set for this column, so ANALYZE + * should use the default setting. + */ + int4 attstattarget; + + /* + * attlen is a copy of the typlen field from pg_type for this attribute. + * See atttypid comments above. + */ + int2 attlen; + + /* + * attnum is the "attribute number" for the attribute: A value that + * uniquely identifies this attribute within its class. For user + * attributes, Attribute numbers are greater than 0 and not greater than + * the number of attributes in the class. I.e. if the Class pg_class says + * that Class XYZ has 10 attributes, then the user attribute numbers in + * Class pg_attribute must be 1-10. + * + * System attributes have attribute numbers less than 0 that are unique + * within the class, but not constrained to any particular range. + * + * Note that (attnum - 1) is often used as the index to an array. + */ + int2 attnum; + + /* + * attndims is the declared number of dimensions, if an array type, + * otherwise zero. + */ + int4 attndims; + + /* + * fastgetattr() uses attcacheoff to cache byte offsets of attributes in + * heap tuples. The value actually stored in pg_attribute (-1) indicates + * no cached value. But when we copy these tuples into a tuple + * descriptor, we may then update attcacheoff in the copies. This speeds + * up the attribute walking process. + * + * Important: this is only for uncompressed tuples, both cached and updated. + * And it cann't be applied to compressed tuples. Each attribute within + * compressed tuple should be accessed one by one, step by step. + */ + int4 attcacheoff; + + /* + * atttypmod records type-specific data supplied at table creation time + * (for example, the max length of a varchar field). It is passed to + * type-specific input and output functions as the third argument. The + * value will generally be -1 for types that do not need typmod. + */ + int4 atttypmod; + + /* + * attbyval is a copy of the typbyval field from pg_type for this + * attribute. See atttypid comments above. + */ + bool attbyval; + + /* ---------- + * attstorage tells for VARLENA attributes, what the heap access + * methods can do to it if a given tuple doesn't fit into a page. + * Possible values are + * 'p': Value must be stored plain always + * 'e': Value can be stored in "secondary" relation (if relation + * has one, see pg_class.reltoastrelid) + * 'm': Value can be stored compressed inline + * 'x': Value can be stored compressed inline or in "secondary" + * Note that 'm' fields can also be moved out to secondary storage, + * but only as a last resort ('e' and 'x' fields are moved first). + * ---------- + */ + char attstorage; + + /* + * attalign is a copy of the typalign field from pg_type for this + * attribute. See atttypid comments above. + */ + char attalign; + + /* This flag represents the "NOT NULL" constraint */ + bool attnotnull; + + /* Has DEFAULT value or not */ + bool atthasdef; + + /* Is dropped (ie, logically invisible) or not */ + bool attisdropped; + + /* Has a local definition (hence, do not drop when attinhcount is 0) */ + bool attislocal; + + /* Compression Mode for this attribute + * its size is 1Byte, and the 7 fields before are also 1Btye wide, so place it here; + * its valid value is: CMPR_NONE ~ CMPR_NUMSTR. see also pagecompress.h + */ + int1 attcmprmode; + + /* Number of times inherited from direct parent relation(s) */ + int4 attinhcount; + + /* attribute's collation */ + Oid attcollation; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* NOTE: The following fields are not present in tuple descriptors. */ + + /* Column-level access permissions */ + aclitem attacl[1]; + + /* Column-level options */ + text attoptions[1]; + + /* Column-level FDW options */ + text attfdwoptions[1]; + + /* the value is not null only when ALTER TABLE ... ADD COLUMN call */ + bytea attinitdefval; + +#endif + /* the attribute type for kv storage: tag(1), field(2), time(3), hide(4) or default(0) */ + int1 attkvtype; +} FormData_pg_attribute; + +/* + * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout, + * guaranteed-not-null part of a pg_attribute row. This is in fact as much + * of the row as gets copied into tuple descriptors, so don't expect you + * can access fields beyond attcollation except in a real tuple! + */ +#define ATTRIBUTE_FIXED_PART_SIZE \ + (offsetof(FormData_pg_attribute, attkvtype) + sizeof(Oid)) + +/* ---------------- + * Form_pg_attribute corresponds to a pointer to a tuple with + * the format of pg_attribute relation. + * ---------------- + */ +typedef FormData_pg_attribute *Form_pg_attribute; + +/* ---------------- + * compiler constants for pg_attribute + * ---------------- + */ +#define Natts_pg_attribute 24 +#define Anum_pg_attribute_attrelid 1 +#define Anum_pg_attribute_attname 2 +#define Anum_pg_attribute_atttypid 3 +#define Anum_pg_attribute_attstattarget 4 +#define Anum_pg_attribute_attlen 5 +#define Anum_pg_attribute_attnum 6 +#define Anum_pg_attribute_attndims 7 +#define Anum_pg_attribute_attcacheoff 8 +#define Anum_pg_attribute_atttypmod 9 +#define Anum_pg_attribute_attbyval 10 +#define Anum_pg_attribute_attstorage 11 +#define Anum_pg_attribute_attalign 12 +#define Anum_pg_attribute_attnotnull 13 +#define Anum_pg_attribute_atthasdef 14 +#define Anum_pg_attribute_attisdropped 15 +#define Anum_pg_attribute_attislocal 16 +#define Anum_pg_attribute_attcmprmode 17 +#define Anum_pg_attribute_attinhcount 18 +#define Anum_pg_attribute_attcollation 19 +#define Anum_pg_attribute_attacl 20 +#define Anum_pg_attribute_attoptions 21 +#define Anum_pg_attribute_attfdwoptions 22 +#define Anum_pg_attribute_attinitdefval 23 +#define Anum_pg_attribute_attkvtype 24 + +/* ---------------- + * initial contents of pg_attribute + * + * The initial contents of pg_attribute are generated at compile time by + * genbki.pl. Only "bootstrapped" relations need be included. + * ---------------- + */ +#endif /* PG_ATTRIBUTE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_auth_history.h postgresql-hll-2.14/include/include/catalog/pg_auth_history.h --- postgresql-hll-2.14_old/include/include/catalog/pg_auth_history.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_auth_history.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_auth_history.h + * definition of the system "authorization history" relation (pg_auth_history) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_auth_history.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_AUTH_HISTORY_H +#define PG_AUTH_HISTORY_H + +/* define the timestamptz for the passwordtime in pg_auth_history*/ +#define timestamptz Datum + +/* define the OID of the table pg_auth_history*/ +#define AuthHistoryRelationId 3457 +#define AuthHistoryRelation_Rowtype_Id 11642 + +CATALOG(pg_auth_history,3457) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + Oid roloid; /* role OID*/ + timestamptz passwordtime; /* the time while create or alter password */ + text rolpassword; /* role password, md5-encryption,sha256-encryption, or none-encryption */ +} FormData_pg_auth_history; + +#undef timestamptz + +/*------------------------------------------------------------------------- + * Form_pg_auth_history corresponds to a pointer to a tuple with + * the format of pg_auth_history relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_auth_history *Form_pg_auth_history; + +/*------------------------------------------------------------------------- + * compiler constants for pg_auth_history + *------------------------------------------------------------------------- + */ +#define Natts_pg_auth_history 3 +#define Anum_pg_auth_history_roloid 1 +#define Anum_pg_auth_history_passwordtime 2 +#define Anum_pg_auth_history_rolpassword 3 + +#endif /* PG_AUTH_HISTORY_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_authid.h postgresql-hll-2.14/include/include/catalog/pg_authid.h --- postgresql-hll-2.14_old/include/include/catalog/pg_authid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_authid.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,138 @@ +/* ------------------------------------------------------------------------- + * + * pg_authid.h + * definition of the system "authorization identifier" relation (pg_authid) + * along with the relation's initial contents. + * + * pg_shadow and pg_group are now publicly accessible views on pg_authid. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_authid.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AUTHID_H +#define PG_AUTHID_H + +#include "catalog/genbki.h" +#include "catalog/pg_resource_pool.h" + +/* + * The CATALOG definition has to refer to the type of rolvaliduntil as + * "timestamptz" (lower case) so that bootstrap mode recognizes it. But + * the C header files define this type as TimestampTz. Since the field is + * potentially-null and therefore can't be accessed directly from C code, + * there is no particular need for the C struct definition to show the + * field type as TimestampTz --- instead we just make it int. + */ +#define timestamptz int + + +/* ---------------- + * pg_authid definition. cpp turns this into + * typedef struct FormData_pg_authid + * ---------------- + */ +#define AuthIdRelationId 1260 +#define AuthIdRelation_Rowtype_Id 2842 + +CATALOG(pg_authid,1260) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2842) BKI_SCHEMA_MACRO +{ + NameData rolname; /* name of role */ + bool rolsuper; /* the first role created by initdb.*/ + bool rolinherit; /* inherit privileges from other roles? */ + bool rolcreaterole; /* allowed to create more roles? */ + bool rolcreatedb; /* allowed to create databases? */ + bool rolcatupdate; /* allowed to alter catalogs manually? */ + bool rolcanlogin; /* allowed to log in as session user? */ + bool rolreplication; /* role used for streaming replication */ + bool rolauditadmin; /* role used for administer audit data */ + bool rolsystemadmin; + int4 rolconnlimit; /* max connections allowed (-1=no limit) */ + + /* remaining fields may be null; use heap_getattr to read them! */ +#ifdef CATALOG_VARLEN + text rolpassword; /* password, if any */ + timestamptz rolvalidbegin; /* password initiation time, if any */ + timestamptz rolvaliduntil; /* password expiration time, if any */ + + NameData rolrespool; /* wlm resource pool */ + bool roluseft; /* allowed to use foreign table? */ + Oid rolparentid; /* parent user oid */ + text roltabspace; /* user perm space */ + char rolkind; /* role kind for special use. */ + Oid rolnodegroup; /* nodegroup id */ + text roltempspace; /* user temp space */ + text rolspillspace; /* user spill space */ + text rolexcpdata; /* user exception data */ +#endif + bool rolmonitoradmin; + bool roloperatoradmin; + bool rolpolicyadmin; +} FormData_pg_authid; + +#undef timestamptz + + +/* ---------------- + * Form_pg_authid corresponds to a pointer to a tuple with + * the format of pg_authid relation. + * ---------------- + */ +typedef FormData_pg_authid *Form_pg_authid; + +/* ---------------- + * compiler constants for pg_authid + * ---------------- + */ +#define Natts_pg_authid 26 +#define Anum_pg_authid_rolname 1 +#define Anum_pg_authid_rolsuper 2 +#define Anum_pg_authid_rolinherit 3 +#define Anum_pg_authid_rolcreaterole 4 +#define Anum_pg_authid_rolcreatedb 5 +#define Anum_pg_authid_rolcatupdate 6 +#define Anum_pg_authid_rolcanlogin 7 +#define Anum_pg_authid_rolreplication 8 +#define Anum_pg_authid_rolauditadmin 9 +#define Anum_pg_authid_rolsystemadmin 10 +#define Anum_pg_authid_rolconnlimit 11 +#define Anum_pg_authid_rolpassword 12 +#define Anum_pg_authid_rolvalidbegin 13 +#define Anum_pg_authid_rolvaliduntil 14 +#define Anum_pg_authid_rolrespool 15 +#define Anum_pg_authid_roluseft 16 +#define Anum_pg_authid_rolparentid 17 +#define Anum_pg_authid_roltabspace 18 +#define Anum_pg_authid_rolkind 19 +#define Anum_pg_authid_rolnodegroup 20 +#define Anum_pg_authid_roltempspace 21 +#define Anum_pg_authid_rolspillspace 22 +#define Anum_pg_authid_rolexcpdata 23 +#define Anum_pg_authid_rolmonitoradmin 24 +#define Anum_pg_authid_roloperatoradmin 25 +#define Anum_pg_authid_rolpolicyadmin 26 + +/* ---------------- + * initial contents of pg_authid + * + * The uppercase quantities will be replaced at initdb time with + * user choices. + * ---------------- + */ +DATA(insert OID = 10 ( "POSTGRES" t t t t t t t t t -1 _null_ _null_ _null_ "default_pool" t 0 _null_ n 0 _null_ _null_ _null_ t t t)); + +#define BOOTSTRAP_SUPERUSERID 10 +#define ROLKIND_NORMAL 'n' /* regular user */ +#define ROLKIND_INDEPENDENT 'i' /* independent user */ +#define ROLKIND_VCADMIN 'v' /* logic cluster admin user */ +#define ROLKIND_PERSISTENCE 'p' /* persistence user */ + +#endif /* PG_AUTHID_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_auth_members.h postgresql-hll-2.14/include/include/catalog/pg_auth_members.h --- postgresql-hll-2.14_old/include/include/catalog/pg_auth_members.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_auth_members.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,57 @@ +/* ------------------------------------------------------------------------- + * + * pg_auth_members.h + * definition of the system "authorization identifier members" relation + * (pg_auth_members) along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_auth_members.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_AUTH_MEMBERS_H +#define PG_AUTH_MEMBERS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_auth_members definition. cpp turns this into + * typedef struct FormData_pg_auth_members + * ---------------- + */ +#define AuthMemRelationId 1261 +#define AuthMemRelation_Rowtype_Id 2843 + +CATALOG(pg_auth_members,1261) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(2843) BKI_SCHEMA_MACRO +{ + Oid roleid; /* ID of a role */ + Oid member; /* ID of a member of that role */ + Oid grantor; /* who granted the membership */ + bool admin_option; /* granted with admin option? */ +} FormData_pg_auth_members; + +/* ---------------- + * Form_pg_auth_members corresponds to a pointer to a tuple with + * the format of pg_auth_members relation. + * ---------------- + */ +typedef FormData_pg_auth_members *Form_pg_auth_members; + +/* ---------------- + * compiler constants for pg_auth_members + * ---------------- + */ +#define Natts_pg_auth_members 4 +#define Anum_pg_auth_members_roleid 1 +#define Anum_pg_auth_members_member 2 +#define Anum_pg_auth_members_grantor 3 +#define Anum_pg_auth_members_admin_option 4 + +#endif /* PG_AUTH_MEMBERS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_cast.h postgresql-hll-2.14/include/include/catalog/pg_cast.h --- postgresql-hll-2.14_old/include/include/catalog/pg_cast.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_cast.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,535 @@ +/* ------------------------------------------------------------------------- + * + * pg_cast.h + * definition of the system "type casts" relation (pg_cast) + * along with the relation's initial contents. + * + * As of Postgres 8.0, pg_cast describes not only type coercion functions + * but also length coercion functions. + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/catalog/pg_cast.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CAST_H +#define PG_CAST_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_cast definition. cpp turns this into + * typedef struct FormData_pg_cast + * ---------------- + */ +#define CastRelationId 2605 +#define CastRelation_Rowtype_Id 11331 + +CATALOG(pg_cast,2605) BKI_SCHEMA_MACRO +{ + Oid castsource; /* source datatype for cast */ + Oid casttarget; /* destination datatype for cast */ + Oid castfunc; /* cast function; 0 = binary coercible */ + char castcontext; /* contexts in which cast can be used */ + char castmethod; /* cast method */ +} FormData_pg_cast; + +typedef FormData_pg_cast *Form_pg_cast; + +/* + * The allowable values for pg_cast.castcontext are specified by this enum. + * Since castcontext is stored as a "char", we use ASCII codes for human + * convenience in reading the table. Note that internally to the backend, + * these values are converted to the CoercionContext enum (see primnodes.h), + * which is defined to sort in a convenient order; the ASCII codes don't + * have to sort in any special order. + */ + +typedef enum CoercionCodes +{ + COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */ + COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */ + COERCION_CODE_EXPLICIT = 'e' /* explicit cast operation */ +} CoercionCodes; + +/* + * The allowable values for pg_cast.castmethod are specified by this enum. + * Since castmethod is stored as a "char", we use ASCII codes for human + * convenience in reading the table. + */ +typedef enum CoercionMethod +{ + COERCION_METHOD_FUNCTION = 'f', /* use a function */ + COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */ + COERCION_METHOD_INOUT = 'i' /* use input/output functions */ +} CoercionMethod; + + +/* ---------------- + * compiler constants for pg_cast + * ---------------- + */ +#define Natts_pg_cast 5 +#define Anum_pg_cast_castsource 1 +#define Anum_pg_cast_casttarget 2 +#define Anum_pg_cast_castfunc 3 +#define Anum_pg_cast_castcontext 4 +#define Anum_pg_cast_castmethod 5 + +/* ---------------- + * initial contents of pg_cast + * + * Note: this table has OIDs, but we don't bother to assign them manually, + * since nothing needs to know the specific OID of any built-in cast. + * ---------------- + */ + +/* + * Numeric category: implicit casts are allowed in the direction + * int2->int4->int8->numeric->float4->float8, while casts in the + * reverse direction are assignment-only. + */ +DATA(insert ( 23 5545 5526 i f )); +DATA(insert ( 5545 16 5533 i f )); +DATA(insert ( 16 5545 5534 i f )); +DATA(insert ( 5545 26 5525 i f )); +DATA(insert ( 5545 24 5525 i f )); +DATA(insert ( 5545 2202 5525 i f )); +DATA(insert ( 5545 2203 5525 i f )); +DATA(insert ( 5545 2204 5525 i f )); +DATA(insert ( 5545 2205 5525 i f )); +DATA(insert ( 5545 2206 5525 i f )); +DATA(insert ( 5545 3734 5525 i f )); +DATA(insert ( 5545 3769 5525 i f )); +DATA(insert ( 5545 21 5523 i f )); +DATA(insert ( 5545 23 5525 i f )); +DATA(insert ( 5545 20 5527 i f )); +DATA(insert ( 5545 1700 5521 i f )); +DATA(insert ( 5545 700 5529 i f )); +DATA(insert ( 5545 701 5531 i f )); +DATA(insert ( 20 5545 5528 a f )); +DATA(insert ( 21 5545 5524 i f )); +DATA(insert ( 700 5545 5530 i f )); +DATA(insert ( 701 5545 5532 i f )); +DATA(insert ( 1700 5545 5522 i f )); +DATA(insert ( 20 21 714 a f )); +DATA(insert ( 20 23 480 a f )); +DATA(insert ( 20 700 652 i f )); +DATA(insert ( 20 701 482 i f )); +DATA(insert ( 20 1700 1781 i f )); +DATA(insert ( 21 20 754 i f )); +DATA(insert ( 21 23 313 i f )); +DATA(insert ( 21 700 236 i f )); +DATA(insert ( 21 701 235 i f )); +DATA(insert ( 21 1700 1782 i f )); +DATA(insert ( 23 20 481 i f )); +DATA(insert ( 23 21 314 i f )); +DATA(insert ( 23 700 318 i f )); +DATA(insert ( 23 701 316 i f )); +DATA(insert ( 23 1700 1740 i f )); +DATA(insert ( 700 20 653 i f )); +DATA(insert ( 700 21 238 i f )); +DATA(insert ( 700 23 319 i f )); +DATA(insert ( 700 701 311 i f )); +DATA(insert ( 700 1700 1742 i f )); +DATA(insert ( 701 20 483 i f )); +DATA(insert ( 701 21 237 i f )); +DATA(insert ( 701 23 317 i f )); +DATA(insert ( 701 700 312 i f )); + +/* + * convert float8 to numeric implicit(not assignment-only) + * support mod(numeric, float8) and mod(float8, numeric) + */ +DATA(insert ( 701 1700 1743 i f )); +DATA(insert ( 1700 20 1779 i f )); +DATA(insert ( 1700 21 1783 i f )); +DATA(insert ( 1700 23 1744 i f )); +DATA(insert ( 1700 700 1745 i f )); +DATA(insert ( 1700 701 1746 i f )); +DATA(insert ( 790 1700 3823 a f )); +DATA(insert ( 1700 790 3824 a f )); +DATA(insert ( 23 790 3811 a f )); +DATA(insert ( 20 790 3812 a f )); + +/* Allow explicit coercions between int4 and bool */ + +/*Bool <-->INT4*/ +DATA(insert ( 23 16 2557 i f )); +DATA(insert ( 16 23 2558 i f )); +/*Bool <-->INT2*/ +DATA(insert ( 21 16 3180 i f )); +DATA(insert ( 16 21 3181 i f )); +/*Bool <-->INT8*/ +DATA(insert ( 20 16 3177 i f )); +DATA(insert ( 16 20 3178 i f )); + +/* int4 ->bpchar */ +DATA(insert ( 23 1042 3192 i f )); + +/* numeric ->interval */ +DATA(insert ( 1700 1186 3842 i f )); + +/* float8-> interval */ +DATA(insert ( 701 1186 4229 i f )); + +/* int1 ->interval */ +DATA(insert ( 5545 1186 3189 i f )); + +/* int2 ->interval */ +DATA(insert ( 21 1186 3190 i f )); + +/* int4 ->interval */ +DATA(insert ( 23 1186 3191 i f )); + +/* + * OID category: allow implicit conversion from any integral type (including + * int8, to support OID literals > 2G) to OID, as well as assignment coercion + * from OID to int4 or int8. Similarly for each OID-alias type. Also allow + * implicit coercions between OID and each OID-alias type, as well as + * regproc<->regprocedure and regoper<->regoperator. (Other coercions + * between alias types must pass through OID.) Lastly, there are implicit + * casts from text and varchar to regclass, which exist mainly to support + * legacy forms of nextval() and related functions. + */ +DATA(insert ( 20 26 1287 i f )); +DATA(insert ( 21 26 313 i f )); +DATA(insert ( 23 26 0 i b )); +DATA(insert ( 26 20 1288 a f )); +DATA(insert ( 26 23 0 a b )); +DATA(insert ( 26 24 0 i b )); +DATA(insert ( 24 26 0 i b )); +DATA(insert ( 20 24 1287 i f )); +DATA(insert ( 21 24 313 i f )); +DATA(insert ( 23 24 0 i b )); +DATA(insert ( 24 20 1288 a f )); +DATA(insert ( 24 23 0 a b )); +DATA(insert ( 24 2202 0 i b )); +DATA(insert ( 2202 24 0 i b )); +DATA(insert ( 26 2202 0 i b )); +DATA(insert ( 2202 26 0 i b )); +DATA(insert ( 20 2202 1287 i f )); +DATA(insert ( 21 2202 313 i f )); +DATA(insert ( 23 2202 0 i b )); +DATA(insert ( 2202 20 1288 a f )); +DATA(insert ( 2202 23 0 a b )); +DATA(insert ( 26 2203 0 i b )); +DATA(insert ( 2203 26 0 i b )); +DATA(insert ( 20 2203 1287 i f )); +DATA(insert ( 21 2203 313 i f )); +DATA(insert ( 23 2203 0 i b )); +DATA(insert ( 2203 20 1288 a f )); +DATA(insert ( 2203 23 0 a b )); +DATA(insert ( 2203 2204 0 i b )); +DATA(insert ( 2204 2203 0 i b )); +DATA(insert ( 26 2204 0 i b )); +DATA(insert ( 2204 26 0 i b )); +DATA(insert ( 20 2204 1287 i f )); +DATA(insert ( 21 2204 313 i f )); +DATA(insert ( 23 2204 0 i b )); +DATA(insert ( 2204 20 1288 a f )); +DATA(insert ( 2204 23 0 a b )); +DATA(insert ( 26 2205 0 i b )); +DATA(insert ( 2205 26 0 i b )); +DATA(insert ( 20 2205 1287 i f )); +DATA(insert ( 21 2205 313 i f )); +DATA(insert ( 23 2205 0 i b )); +DATA(insert ( 2205 20 1288 a f )); +DATA(insert ( 2205 23 0 a b )); +DATA(insert ( 26 2206 0 i b )); +DATA(insert ( 2206 26 0 i b )); +DATA(insert ( 20 2206 1287 i f )); +DATA(insert ( 21 2206 313 i f )); +DATA(insert ( 23 2206 0 i b )); +DATA(insert ( 2206 20 1288 a f )); +DATA(insert ( 2206 23 0 a b )); +DATA(insert ( 26 3734 0 i b )); +DATA(insert ( 3734 26 0 i b )); +DATA(insert ( 20 3734 1287 i f )); +DATA(insert ( 21 3734 313 i f )); +DATA(insert ( 23 3734 0 i b )); +DATA(insert ( 3734 20 1288 a f )); +DATA(insert ( 3734 23 0 a b )); +DATA(insert ( 26 3769 0 i b )); +DATA(insert ( 3769 26 0 i b )); +DATA(insert ( 20 3769 1287 i f )); +DATA(insert ( 21 3769 313 i f )); +DATA(insert ( 23 3769 0 i b )); +DATA(insert ( 3769 20 1288 a f )); +DATA(insert ( 3769 23 0 a b )); +DATA(insert ( 25 2205 1079 i f )); +DATA(insert ( 90 2205 1079 i f )); +DATA(insert ( 1043 2205 1079 i f )); +DATA(insert ( 3969 2205 1079 i f )); + +/* + * String category + */ +DATA(insert ( 25 1042 0 i b )); +DATA(insert ( 25 1043 0 i b )); +DATA(insert ( 25 3969 0 i b )); +DATA(insert ( 90 1042 0 i b )); +DATA(insert ( 90 1043 0 i b )); +DATA(insert ( 90 3969 0 i b )); +DATA(insert ( 1042 25 401 i f )); +DATA(insert ( 1042 90 401 i f )); +DATA(insert ( 1042 1043 401 i f )); +DATA(insert ( 1043 25 0 i b )); +DATA(insert ( 1043 90 0 i b )); +DATA(insert ( 1043 1042 0 i b )); +DATA(insert ( 1042 3969 401 i f )); +DATA(insert ( 3969 25 0 i b )); +DATA(insert ( 3969 90 0 i b )); +DATA(insert ( 3969 1042 0 i b )); +DATA(insert ( 3969 1043 0 i b )); +DATA(insert ( 1043 3969 0 i b )); +DATA(insert ( 18 25 946 i f )); +DATA(insert ( 18 90 946 i f )); +DATA(insert ( 18 1042 860 a f )); +DATA(insert ( 18 1043 946 a f )); +DATA(insert ( 18 3969 946 a f )); +DATA(insert ( 19 25 406 i f )); +DATA(insert ( 19 90 406 i f )); +DATA(insert ( 19 1042 408 a f )); +DATA(insert ( 19 1043 1401 a f )); +DATA(insert ( 19 3969 1401 a f )); +DATA(insert ( 25 18 944 a f )); +DATA(insert ( 90 18 944 a f )); +DATA(insert ( 1042 18 944 a f )); +DATA(insert ( 1043 18 944 a f )); +DATA(insert ( 3969 18 944 a f )); +DATA(insert ( 25 19 407 i f )); +DATA(insert ( 90 19 407 i f )); +DATA(insert ( 1042 19 409 i f )); +DATA(insert ( 1043 19 1400 i f )); +DATA(insert ( 3969 19 1400 i f )); + + + +/* Allow explicit coercions between int4 and "char" */ +DATA(insert ( 18 23 77 e f )); +DATA(insert ( 23 18 78 e f )); + +/* pg_node_tree can be coerced to, but not from, text */ +DATA(insert ( 194 25 0 i b )); +DATA(insert ( 194 90 0 i b )); + +/* + * Datetime category + */ +DATA(insert ( 702 1082 1179 a f )); +DATA(insert ( 702 1083 1364 a f )); +DATA(insert ( 702 1114 2023 i f )); +DATA(insert ( 702 1184 1173 i f )); +DATA(insert ( 703 1186 1177 i f )); +DATA(insert ( 1082 1114 2024 i f )); +DATA(insert ( 1082 1184 1174 i f )); +DATA(insert ( 1083 1186 1370 i f )); +DATA(insert ( 1083 1266 2047 i f )); +DATA(insert ( 1114 702 2030 a f )); +DATA(insert ( 1114 1082 2029 a f )); +DATA(insert ( 1114 1083 1316 a f )); +DATA(insert ( 1114 1184 2028 i f )); +DATA(insert ( 1184 702 1180 a f )); +DATA(insert ( 1184 1082 1178 a f )); +DATA(insert ( 1184 1083 2019 a f )); +DATA(insert ( 1184 1114 2027 a f )); +DATA(insert ( 1184 1266 1388 a f )); +DATA(insert ( 1186 703 1194 a f )); +DATA(insert ( 1186 1083 1419 a f )); +DATA(insert ( 1266 1083 2046 a f )); +DATA(insert ( 25 1114 4073 i f )); +DATA(insert ( 90 1114 4073 i f )); + +/* Cross-category casts between int4 and abstime, reltime */ +DATA(insert ( 23 702 0 e b )); +DATA(insert ( 702 23 0 e b )); +DATA(insert ( 23 703 0 e b )); +DATA(insert ( 703 23 0 e b )); + +/* + * Geometric category + */ +DATA(insert ( 601 600 1532 e f )); +DATA(insert ( 602 600 1533 e f )); +DATA(insert ( 602 604 1449 a f )); +DATA(insert ( 603 600 1534 e f )); +DATA(insert ( 603 601 1541 e f )); +DATA(insert ( 603 604 1448 a f )); +DATA(insert ( 603 718 1479 e f )); +DATA(insert ( 604 600 1540 e f )); +DATA(insert ( 604 602 1447 a f )); +DATA(insert ( 604 603 1446 e f )); +DATA(insert ( 604 718 1474 e f )); +DATA(insert ( 718 600 1416 e f )); +DATA(insert ( 718 603 1480 e f )); +DATA(insert ( 718 604 1544 e f )); + +/* + * INET category + */ +DATA(insert ( 650 869 0 i b )); +DATA(insert ( 869 650 1715 a f )); + +/* + * BitString category + */ +DATA(insert ( 1560 1562 0 i b )); +DATA(insert ( 1562 1560 0 i b )); +/* Cross-category casts between bit and int4, int8 */ +DATA(insert ( 20 1560 2075 e f )); +DATA(insert ( 23 1560 1683 e f )); +DATA(insert ( 1560 20 2076 e f )); +DATA(insert ( 1560 23 1684 e f )); + +/* + * Cross-category casts to and from TEXT + * + * We need entries here only for a few specialized cases where the behavior + * of the cast function differs from the datatype's I/O functions. Otherwise, + * parse_coerce.c will generate CoerceViaIO operations without any prompting. + * + * Note that the castcontext values specified here should be no stronger than + * parse_coerce.c's automatic casts ('a' to text, 'e' from text) else odd + * behavior will ensue when the automatic cast is applied instead of the + * pg_cast entry! + */ +DATA(insert ( 650 25 730 a f )); +DATA(insert ( 869 25 730 a f )); +DATA(insert ( 16 25 2971 a f )); +DATA(insert ( 142 25 0 a b )); +DATA(insert ( 25 142 2896 e f )); + +DATA(insert ( 650 90 730 a f )); +DATA(insert ( 869 90 730 a f )); +DATA(insert ( 16 90 2971 a f )); +DATA(insert ( 142 90 0 a b )); +DATA(insert ( 90 142 2896 e f )); + +/* + * Cross-category casts to and from VARCHAR + * + * We support all the same casts as for TEXT. + */ +DATA(insert ( 650 1043 730 a f )); +DATA(insert ( 869 1043 730 a f )); +DATA(insert ( 16 1043 2971 a f )); +DATA(insert ( 142 1043 0 a b )); +DATA(insert ( 1043 142 2896 e f )); +DATA(insert ( 650 3969 730 a f )); +DATA(insert ( 869 3969 730 a f )); +DATA(insert ( 16 3969 2971 a f )); +DATA(insert ( 142 3969 0 a b )); +DATA(insert ( 3969 142 2896 e f )); + +/* + * Cross-category casts to and from BPCHAR + * + * We support all the same casts as for TEXT. + */ +DATA(insert ( 650 1042 730 a f )); +DATA(insert ( 869 1042 730 a f )); +DATA(insert ( 16 1042 2971 a f )); +DATA(insert ( 142 1042 0 a b )); +DATA(insert ( 1042 142 2896 e f )); +DATA(insert ( 1042 20 4195 i f )); + + +/* + * Length-coercion functions + */ +DATA(insert ( 1042 1042 668 i f )); +DATA(insert ( 1043 1043 669 i f )); +DATA(insert ( 3969 3969 3961 i f )); +DATA(insert ( 1083 1083 1968 i f )); +DATA(insert ( 1114 1114 1961 i f )); +DATA(insert ( 1184 1184 1967 i f )); +DATA(insert ( 1186 1186 1200 i f )); +DATA(insert ( 1266 1266 1969 i f )); +DATA(insert ( 1560 1560 1685 i f )); +DATA(insert ( 1562 1562 1687 i f )); +DATA(insert ( 1700 1700 1703 i f )); + +DATA(insert ( 1082 25 4159 i f )); +/*DATA(insert ( 1082 90 4159 i f ));*/ +DATA(insert ( 1082 1042 4160 i f )); +DATA(insert ( 1082 1043 4161 i f )); +DATA(insert ( 1043 1082 4162 i f )); +DATA(insert ( 1042 1082 4163 i f )); +DATA(insert ( 25 1082 4164 i f )); +/*DATA(insert ( 90 1082 4164 i f ));*/ + +DATA(insert ( 5545 25 4165 i f )); +DATA(insert ( 21 25 4166 i f )); +DATA(insert ( 23 25 4167 i f )); +DATA(insert ( 20 25 4168 i f )); +DATA(insert ( 700 25 4169 i f )); +DATA(insert ( 701 25 4170 i f )); +DATA(insert ( 1700 25 4171 i f )); +DATA(insert ( 5545 90 4165 i f )); +DATA(insert ( 21 90 4166 i f )); +DATA(insert ( 23 90 4167 i f )); +DATA(insert ( 20 90 4168 i f )); +DATA(insert ( 700 90 4169 i f )); +DATA(insert ( 701 90 4170 i f )); +DATA(insert ( 1700 90 4171 i f )); +DATA(insert ( 1042 1700 4172 i f )); +DATA(insert ( 1043 1700 4173 i f )); +DATA(insert ( 1043 23 4174 i f )); +DATA(insert ( 1042 23 4175 i f )); +DATA(insert ( 1043 20 4176 i f )); +DATA(insert ( 1184 25 4177 i f )); +DATA(insert ( 1114 25 4178 i f )); +DATA(insert ( 1184 90 4177 i f )); +DATA(insert ( 1114 90 4178 i f )); +DATA(insert ( 1114 1043 4179 i f )); +DATA(insert ( 21 1043 4180 i f )); +DATA(insert ( 23 1043 4181 i f )); +DATA(insert ( 20 1043 4182 i f )); +DATA(insert ( 1700 1043 4183 i f )); +DATA(insert ( 700 1043 4184 i f )); +DATA(insert ( 701 1043 4185 i f )); +DATA(insert ( 1043 1114 4186 i f )); +DATA(insert ( 1042 1114 4187 i f )); + +DATA(insert ( 25 5545 4188 i f )); +DATA(insert ( 25 21 4189 i f )); +DATA(insert ( 25 23 4190 i f )); +DATA(insert ( 25 20 4191 i f )); +DATA(insert ( 25 700 4192 i f )); +DATA(insert ( 25 701 4193 i f )); +DATA(insert ( 25 1700 4194 i f )); + +DATA(insert ( 90 5545 4188 i f )); +DATA(insert ( 90 21 4189 i f )); +DATA(insert ( 90 23 4190 i f )); +DATA(insert ( 90 20 4191 i f )); +DATA(insert ( 90 700 4192 i f )); +DATA(insert ( 90 701 4193 i f )); +DATA(insert ( 90 1700 4194 i f )); + +DATA(insert (5545 1043 4065 i f )); +DATA(insert (5545 3969 4066 i f )); +DATA(insert (5545 1042 4067 i f )); +DATA(insert (21 1042 4068 i f )); +DATA(insert (20 1042 4069 i f )); +DATA(insert (700 1042 4070 i f )); +DATA(insert (701 1042 4071 i f )); +DATA(insert (1700 1042 4072 i f )); + +/* hll */ +DATA(insert (4301 4301 4311 i f )); +DATA(insert (17 4301 0 e b )); +DATA(insert (20 4303 0 e b )); +DATA(insert (23 4303 4317 e f )); +DATA(insert (4402 4301 0 e b )); + + + +#endif /* PG_CAST_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_class.h postgresql-hll-2.14/include/include/catalog/pg_class.h --- postgresql-hll-2.14_old/include/include/catalog/pg_class.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_class.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,207 @@ +/* ------------------------------------------------------------------------- + * + * pg_class.h + * definition of the system "relation" relation (pg_class) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_class.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CLASS_H +#define PG_CLASS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_class definition. cpp turns this into + * typedef struct FormData_pg_class + * ---------------- + */ +#define RelationRelationId 1259 +#define RelationRelation_Rowtype_Id 83 + +CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO +{ + NameData relname; /* class name */ + Oid relnamespace; /* OID of namespace containing this class */ + Oid reltype; /* OID of entry in pg_type for table's + * implicit row type */ + Oid reloftype; /* OID of entry in pg_type for underlying + * composite type */ + Oid relowner; /* class owner */ + Oid relam; /* index access method; 0 if not an index */ + Oid relfilenode; /* identifier of physical storage file */ + + /* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */ + Oid reltablespace; /* identifier of table space for relation */ + float8 relpages; /* # of blocks (not always up-to-date) */ + float8 reltuples; /* # of tuples (not always up-to-date) */ + int4 relallvisible; /* # of all-visible blocks (not always + * up-to-date) */ + Oid reltoastrelid; /* OID of toast table; 0 if none */ + Oid reltoastidxid; /* if toast table, OID of chunk_id index */ + Oid reldeltarelid; /* if ColStore table, it is not 0 */ + Oid reldeltaidx; + Oid relcudescrelid; /* if ColStore table, it is not 0, if TsStore, it is partition oid */ + Oid relcudescidx; + bool relhasindex; /* T if has (or has had) any indexes */ + bool relisshared; /* T if shared across databases */ + char relpersistence; /* see RELPERSISTENCE_xxx constants below */ + char relkind; /* see RELKIND_xxx constants below */ + int2 relnatts; /* number of user attributes */ + + /* + * Class pg_attribute must contain exactly "relnatts" user attributes + * (with attnums ranging from 1 to relnatts) for this class. It may also + * contain entries with negative attnums for system attributes. + */ + int2 relchecks; /* # of CHECK constraints for class */ + bool relhasoids; /* T if we generate OIDs for rows of rel */ + bool relhaspkey; /* has (or has had) PRIMARY KEY index */ + bool relhasrules; /* has (or has had) any rules */ + bool relhastriggers; /* has (or has had) any TRIGGERs */ + bool relhassubclass; /* has (or has had) derived classes */ + int1 relcmprs; /* row compression attribution */ + bool relhasclusterkey; /* has (or has had) any PARTIAL CLUSTER KEY */ + bool relrowmovement; /* enable or disable rowmovement */ + char parttype; /* 'p' for partitioned relation, 'n' for non-partitioned relation */ + ShortTransactionId relfrozenxid; /* all Xids < this are frozen in this rel */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* NOTE: These fields are not present in a relcache entry's rd_rel field. */ + aclitem relacl[1]; /* access permissions */ + text reloptions[1]; /* access-method-specific options */ +#endif + char relreplident; /* see REPLICA_IDENTITY_xxx constants */ + TransactionId relfrozenxid64; /* all Xids < this are frozen in this rel */ + Oid relbucket; /* bucket info in pg_hashbucket */ + int2vector relbucketkey; /* Column number of hash partition */ +} +FormData_pg_class; + +/* Size of fixed part of pg_class tuples, not counting var-length fields */ +#define CLASS_TUPLE_SIZE (offsetof(FormData_pg_class, relfrozenxid) + sizeof(ShortTransactionId)) + +/* ---------------- + * Form_pg_class corresponds to a pointer to a tuple with + * the format of pg_class relation. + * ---------------- + */ +typedef FormData_pg_class* Form_pg_class; + +/* ---------------- + * compiler constants for pg_class + * ---------------- + */ +#define Natts_pg_class 39 +#define Anum_pg_class_relname 1 +#define Anum_pg_class_relnamespace 2 +#define Anum_pg_class_reltype 3 +#define Anum_pg_class_reloftype 4 +#define Anum_pg_class_relowner 5 +#define Anum_pg_class_relam 6 +#define Anum_pg_class_relfilenode 7 +#define Anum_pg_class_reltablespace 8 +#define Anum_pg_class_relpages 9 +#define Anum_pg_class_reltuples 10 +#define Anum_pg_class_relallvisible 11 +#define Anum_pg_class_reltoastrelid 12 +#define Anum_pg_class_reltoastidxid 13 +#define Anum_pg_class_reldeltarelid 14 +#define Anum_pg_class_reldeltaidx 15 +#define Anum_pg_class_relcudescrelid 16 +#define Anum_pg_class_relcudescidx 17 +#define Anum_pg_class_relhasindex 18 +#define Anum_pg_class_relisshared 19 +#define Anum_pg_class_relpersistence 20 +#define Anum_pg_class_relkind 21 +#define Anum_pg_class_relnatts 22 +#define Anum_pg_class_relchecks 23 +#define Anum_pg_class_relhasoids 24 +#define Anum_pg_class_relhaspkey 25 +#define Anum_pg_class_relhasrules 26 +#define Anum_pg_class_relhastriggers 27 +#define Anum_pg_class_relhassubclass 28 +#define ANUM_PG_CLASS_RELCMPRS 29 +#define Anum_pg_class_relhasclusterkey 30 +#define Anum_pg_clsss_relrowmovement 31 +#define Anum_pg_class_parttype 32 +#define Anum_pg_class_relfrozenxid 33 +#define Anum_pg_class_relacl 34 +#define Anum_pg_class_reloptions 35 +#define Anum_pg_class_relreplident 36 +#define Anum_pg_class_relfrozenxid64 37 +#define Anum_pg_class_relbucket 38 +#define Anum_pg_class_relbucketkey 39 + +/* ---------------- + * initial contents of pg_class + * + * NOTE: only "bootstrapped" relations need to be declared here. Be sure that + * the OIDs listed here match those given in their CATALOG macros, and that + * the relnatts values are correct. + * ---------------- + */ + +/* Note: "3" in the relfrozenxid and the relfrozenxid64 column stands for FirstNormalTransactionId */ +DATA(insert OID = 1247 ( pg_type PGNSP 71 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 30 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1249 ( pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 24 0 f f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1255 ( pg_proc PGNSP 81 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 32 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); +DATA(insert OID = 1259 ( pg_class PGNSP 83 0 PGUID 0 0 0 0 0 0 0 0 0 0 0 0 f f p r 39 0 t f f f f 0 f f n 3 _null_ _null_ n 3 _null_ _null_)); +DESCR(""); + +#define RELKIND_RELATION 'r' /* ordinary table */ +#define RELKIND_INDEX 'i' /* secondary index */ +#define RELKIND_GLOBAL_INDEX 'I' /* GLOBAL partitioned index */ +#define RELKIND_SEQUENCE 'S' /* sequence object */ +#define RELKIND_TOASTVALUE 't' /* for out-of-line values */ +#define RELKIND_VIEW 'v' /* view */ +#define RELKIND_MATVIEW 'm' /* materialized view */ +#define RELKIND_COMPOSITE_TYPE 'c' /* composite type */ +#define RELKIND_FOREIGN_TABLE 'f' /* foreign table */ +#define RELKIND_STREAM 'e' /* stream */ +#define RELKIND_CONTQUERY 'o' /* contquery */ +#define PARTTYPE_PARTITIONED_RELATION 'p' /* partitioned relation */ +#define PARTTYPE_VALUE_PARTITIONED_RELATION 'v' /* value partitioned relation */ +#define PARTTYPE_NON_PARTITIONED_RELATION 'n' /* non-partitioned relation */ +#define RELPERSISTENCE_PERMANENT 'p' /* regular table */ +#define RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent table */ +#define RELPERSISTENCE_TEMP 't' /* temporary table */ +#define RELPERSISTENCE_GLOBAL_TEMP 'g' /* global temporary table */ + +/* default selection for replica identity (primary key or nothing) */ +#define REPLICA_IDENTITY_DEFAULT 'd' +/* no replica identity is logged for this relation */ +#define REPLICA_IDENTITY_NOTHING 'n' +/* all columns are loged as replica identity */ +#define REPLICA_IDENTITY_FULL 'f' + +/* + * Relation kinds that have physical storage. These relations normally have + * relfilenode set to non-zero, but it can also be zero if the relation is + * mapped. + */ +#define RELKIND_HAS_STORAGE(relkind) \ + ((relkind) == RELKIND_RELATION || \ + (relkind) == RELKIND_INDEX || \ + (relkind) == RELKIND_SEQUENCE || \ + (relkind) == RELKIND_TOASTVALUE) + +/* + * an explicitly chosen candidate key's columns are used as identity; + * will still be set if the index has been dropped, in that case it + * has the same meaning as 'd' + */ +#define REPLICA_IDENTITY_INDEX 'i' +#endif /* PG_CLASS_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_collation_fn.h postgresql-hll-2.14/include/include/catalog/pg_collation_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_collation_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_collation_fn.h 2020-12-12 17:06:43.153346825 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * pg_collation_fn.h + * prototypes for functions in catalog/pg_collation.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_collation_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_COLLATION_FN_H +#define PG_COLLATION_FN_H + +extern Oid CollationCreate(const char *collname, Oid collnamespace, Oid collowner, int32 collencoding, + const char *collcollate, const char *collctype); +extern void RemoveCollationById(Oid collationOid); + +#endif /* PG_COLLATION_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_collation.h postgresql-hll-2.14/include/include/catalog/pg_collation.h --- postgresql-hll-2.14_old/include/include/catalog/pg_collation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_collation.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * pg_collation.h + * definition of the system "collation" relation (pg_collation) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/pg_collation.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_COLLATION_H +#define PG_COLLATION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_collation definition. cpp turns this into + * typedef struct FormData_pg_collation + * ---------------- + */ +#define CollationRelationId 3456 +#define CollationRelation_Rowtype_Id 11656 + +CATALOG(pg_collation,3456) BKI_SCHEMA_MACRO +{ + NameData collname; /* collation name */ + Oid collnamespace; /* OID of namespace containing collation */ + Oid collowner; /* owner of collation */ + int4 collencoding; /* encoding for this collation; -1 = "all" */ + NameData collcollate; /* LC_COLLATE setting */ + NameData collctype; /* LC_CTYPE setting */ +} FormData_pg_collation; + +/* ---------------- + * Form_pg_collation corresponds to a pointer to a row with + * the format of pg_collation relation. + * ---------------- + */ +typedef FormData_pg_collation *Form_pg_collation; + +/* ---------------- + * compiler constants for pg_collation + * ---------------- + */ +#define Natts_pg_collation 6 +#define Anum_pg_collation_collname 1 +#define Anum_pg_collation_collnamespace 2 +#define Anum_pg_collation_collowner 3 +#define Anum_pg_collation_collencoding 4 +#define Anum_pg_collation_collcollate 5 +#define Anum_pg_collation_collctype 6 + +/* ---------------- + * initial contents of pg_collation + * ---------------- + */ + +DATA(insert OID = 100 ( default PGNSP PGUID -1 "" "" )); +DESCR("database's default collation"); +#define DEFAULT_COLLATION_OID 100 +DATA(insert OID = 950 ( C PGNSP PGUID -1 "C" "C" )); +DESCR("standard C collation"); +#define C_COLLATION_OID 950 +DATA(insert OID = 951 ( POSIX PGNSP PGUID -1 "POSIX" "POSIX" )); +DESCR("standard POSIX collation"); +#define POSIX_COLLATION_OID 951 + +#endif /* PG_COLLATION_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_constraint.h postgresql-hll-2.14/include/include/catalog/pg_constraint.h --- postgresql-hll-2.14_old/include/include/catalog/pg_constraint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_constraint.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,283 @@ +/* ------------------------------------------------------------------------- + * + * pg_constraint.h + * definition of the system "constraint" relation (pg_constraint) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_constraint.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONSTRAINT_H +#define PG_CONSTRAINT_H + +#include "catalog/genbki.h" +#include "catalog/dependency.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_constraint definition. cpp turns this into + * typedef struct FormData_pg_constraint + * ---------------- + */ +#define ConstraintRelationId 2606 +#define ConstraintRelation_Rowtype_Id 10001 + +CATALOG(pg_constraint,2606) BKI_SCHEMA_MACRO +{ + /* + * conname + connamespace is deliberately not unique; we allow, for + * example, the same name to be used for constraints of different + * relations. This is partly for backwards compatibility with past + * Postgres practice, and partly because we don't want to have to obtain a + * global lock to generate a globally unique name for a nameless + * constraint. We associate a namespace with constraint names only for + * SQL-spec compatibility. + */ + NameData conname; /* name of this constraint */ + Oid connamespace; /* OID of namespace containing constraint */ + char contype; /* constraint type; see codes below */ + bool condeferrable; /* deferrable constraint? */ + bool condeferred; /* deferred by default? */ + bool convalidated; /* constraint has been validated? */ + + /* + * conrelid and conkey are only meaningful if the constraint applies to a + * specific relation (this excludes domain constraints and assertions). + * Otherwise conrelid is 0 and conkey is NULL. + */ + Oid conrelid; /* relation this constraint constrains */ + + /* + * contypid links to the pg_type row for a domain if this is a domain + * constraint. Otherwise it's 0. + * + * For SQL-style global ASSERTIONs, both conrelid and contypid would be + * zero. This is not presently supported, however. + */ + Oid contypid; /* domain this constraint constrains */ + + /* + * conindid links to the index supporting the constraint, if any; + * otherwise it's 0. This is used for unique, primary-key, and exclusion + * constraints, and less obviously for foreign-key constraints (where the + * index is a unique index on the referenced relation's referenced + * columns). Notice that the index is on conrelid in the first case but + * confrelid in the second. + */ + Oid conindid; /* index supporting this constraint */ + + /* + * These fields, plus confkey, are only meaningful for a foreign-key + * constraint. Otherwise confrelid is 0 and the char fields are spaces. + */ + Oid confrelid; /* relation referenced by foreign key */ + char confupdtype; /* foreign key's ON UPDATE action */ + char confdeltype; /* foreign key's ON DELETE action */ + char confmatchtype; /* foreign key's match type */ + + /* Has a local definition (hence, do not drop when coninhcount is 0) */ + bool conislocal; + + /* Number of times inherited from direct parent relation(s) */ + int4 coninhcount; + + /* Has a local definition and cannot be inherited */ + bool connoinherit; + + bool consoft; /* @hdfs show informational constraint. */ + bool conopt; /* @hdfs decide whether to optimize plan by using informational constraint. */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + + /* + * Columns of conrelid that the constraint applies to, if known (this is + * NULL for trigger constraints) + */ + int2 conkey[1]; + + /* + * If a foreign key, the referenced columns of confrelid + */ + int2 confkey[1]; + + /* + * If a foreign key, the OIDs of the PK = FK equality operators for each + * column of the constraint + */ + Oid conpfeqop[1]; + + /* + * If a foreign key, the OIDs of the PK = PK equality operators for each + * column of the constraint (i.e., equality for the referenced columns) + */ + Oid conppeqop[1]; + + /* + * If a foreign key, the OIDs of the FK = FK equality operators for each + * column of the constraint (i.e., equality for the referencing columns) + */ + Oid conffeqop[1]; + + /* + * If an exclusion constraint, the OIDs of the exclusion operators for + * each column of the constraint + */ + Oid conexclop[1]; + + /* + * If a check constraint, nodeToString representation of expression + */ + pg_node_tree conbin; + + /* + * If a check constraint, source-text representation of expression + */ + text consrc; + + /* + * Columns of conrelid that the constraint does not apply to, but included + * into the same index with key columns. + */ + int2 conincluding[1]; +#endif +} FormData_pg_constraint; + +/* ---------------- + * Form_pg_constraint corresponds to a pointer to a tuple with + * the format of pg_constraint relation. + * ---------------- + */ +typedef FormData_pg_constraint *Form_pg_constraint; + +/* ---------------- + * compiler constants for pg_constraint + * ---------------- + */ +#define Natts_pg_constraint 27 +#define Anum_pg_constraint_conname 1 +#define Anum_pg_constraint_connamespace 2 +#define Anum_pg_constraint_contype 3 +#define Anum_pg_constraint_condeferrable 4 +#define Anum_pg_constraint_condeferred 5 +#define Anum_pg_constraint_convalidated 6 +#define Anum_pg_constraint_conrelid 7 +#define Anum_pg_constraint_contypid 8 +#define Anum_pg_constraint_conindid 9 +#define Anum_pg_constraint_confrelid 10 +#define Anum_pg_constraint_confupdtype 11 +#define Anum_pg_constraint_confdeltype 12 +#define Anum_pg_constraint_confmatchtype 13 +#define Anum_pg_constraint_conislocal 14 +#define Anum_pg_constraint_coninhcount 15 +#define Anum_pg_constraint_connoinherit 16 +#define Anum_pg_constraint_consoft 17 +#define Anum_pg_constraint_conopt 18 +#define Anum_pg_constraint_conkey 19 +#define Anum_pg_constraint_confkey 20 +#define Anum_pg_constraint_conpfeqop 21 +#define Anum_pg_constraint_conppeqop 22 +#define Anum_pg_constraint_conffeqop 23 +#define Anum_pg_constraint_conexclop 24 +#define Anum_pg_constraint_conbin 25 +#define Anum_pg_constraint_consrc 26 +#define Anum_pg_constraint_conincluding 27 + + +/* Valid values for contype */ +#define CONSTRAINT_CHECK 'c' +#define CONSTRAINT_FOREIGN 'f' +#define CONSTRAINT_PRIMARY 'p' +#define CONSTRAINT_UNIQUE 'u' +#define CONSTRAINT_TRIGGER 't' +#define CONSTRAINT_EXCLUSION 'x' +#define CONSTRAINT_CLUSTER 's' +#define CONSTRAINT_INVALID 'i' + + +/* + * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx + * constants defined in parsenodes.h. Valid values for confmatchtype are + * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h. + */ + +/* + * Identify constraint type for lookup purposes + */ +typedef enum ConstraintCategory +{ + CONSTRAINT_RELATION, + CONSTRAINT_DOMAIN, + CONSTRAINT_ASSERTION /* for future expansion */ +} ConstraintCategory; + +/* + * prototypes for functions in pg_constraint.c + */ +extern Oid CreateConstraintEntry(const char *constraintName, + Oid constraintNamespace, + char constraintType, + bool isDeferrable, + bool isDeferred, + bool isValidated, + Oid relId, + const int16 *constraintKey, + int constraintNKeys, + int constraintNTotalKeys, + Oid domainId, + Oid indexRelId, + Oid foreignRelId, + const int16 *foreignKey, + const Oid *pfEqOp, + const Oid *ppEqOp, + const Oid *ffEqOp, + int foreignNKeys, + char foreignUpdateType, + char foreignDeleteType, + char foreignMatchType, + const Oid *exclOp, + Node *conExpr, + const char *conBin, + const char *conSrc, + bool conIsLocal, + int conInhCount, + bool conNoInherit, + InformationalConstraint *inforConstraint); + +extern void RemoveConstraintById(Oid conId); +extern void RenameConstraintById(Oid conId, const char *newname); +extern void SetValidatedConstraintById(Oid conId); + +extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, + Oid objNamespace, const char *conname); +extern char *ChooseConstraintName(const char *name1, const char *name2, + const char *label, Oid namespaceid, + List *others); + +extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, + Oid newNspId, bool isType, ObjectAddresses *objsMoved); +extern void get_constraint_relation_oids(Oid constraint_oid, Oid *conrelid, Oid *confrelid); +extern Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok); +extern Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok); + +extern bool check_functional_grouping(Oid relid, + Index varno, Index varlevelsup, + List *grouping_columns, + List **constraintDeps); + +extern List *get_parse_dependency_rel_list(List *conids); + +#ifdef PGXC +extern int pgxc_find_primarykey(Oid relid, int16 **indexed_col, bool check_is_immediate = false); +#endif + +#endif /* PG_CONSTRAINT_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_control.h postgresql-hll-2.14/include/include/catalog/pg_control.h --- postgresql-hll-2.14_old/include/include/catalog/pg_control.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_control.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,305 @@ +/* ------------------------------------------------------------------------- + * + * pg_control.h + * The system control file "pg_control" is not a heap relation. + * However, we define it here so that the format is documented. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_control.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONTROL_H +#define PG_CONTROL_H + +#include "access/xlogdefs.h" +#include "pgtime.h" /* for pg_time_t */ +#include "utils/pg_crc.h" +#include "port/pg_crc32c.h" + + +/* Version identifier for this pg_control format */ +#define PG_CONTROL_VERSION 923 + +/* + * Body of CheckPoint XLOG records. This is declared here because we keep + * a copy of the latest one in pg_control for possible disaster recovery. + * Changing this struct requires a PG_CONTROL_VERSION bump. + */ +typedef struct CheckPoint { + XLogRecPtr redo; /* next RecPtr available when we began to + * create CheckPoint (i.e. REDO start point) */ + TimeLineID ThisTimeLineID; /* current TLI */ + bool fullPageWrites; /* current full_page_writes */ + TransactionId nextXid; /* next free XID */ + Oid nextOid; /* next free OID */ + MultiXactId nextMulti; /* next free MultiXactId */ + MultiXactOffset nextMultiOffset; /* next free MultiXact offset */ + TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + pg_time_t time; /* time stamp of checkpoint */ + XLogSegNo remove_seg; /*the xlog segno we keep during this checkpoint*/ + /* + * Oldest XID still running. This is only needed to initialize hot standby + * mode from an online checkpoint, so we only bother calculating this for + * online checkpoints and only when wal_level is hot_standby. Otherwise + * it's set to InvalidTransactionId. + */ + TransactionId oldestActiveXid; +} CheckPoint; + +/* + * checkpoint new + */ +typedef struct CheckPointNew { + CheckPoint ori_checkpoint; + CommitSeqNo next_csn; +} CheckPointNew; + +/* add length to distinguish between different versions of checkpoint */ +typedef struct CheckPointPlus +{ + CheckPoint ori_checkpoint; + CommitSeqNo next_csn; + uint64 length; + TransactionId recent_global_xmin; + /* you can add more attributes here */ +} CheckPointPlus; + +typedef struct CheckPointOld { + XLogRecPtrOld redo; /* next RecPtr available when we began to + * create CheckPoint (i.e. REDO start point) */ + TimeLineID ThisTimeLineID; /* current TLI */ + bool fullPageWrites; /* current full_page_writes */ + uint32 nextXidEpoch; /* higher-order bits of nextXid */ + ShortTransactionId nextXid; /* next free XID */ + Oid nextOid; /* next free OID */ + ShortTransactionId nextMulti; /* next free MultiXactId */ + ShortTransactionId nextMultiOffset; /* next free MultiXact offset */ + ShortTransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ + Oid oldestXidDB; /* database with minimum datfrozenxid */ + pg_time_t time; /* time stamp of checkpoint */ + ShortTransactionId oldestActiveXid; +} CheckPointOld; + + +/* XLOG info values for XLOG rmgr */ + +#define XLOG_CHECKPOINT_SHUTDOWN 0x00 +#define XLOG_CHECKPOINT_ONLINE 0x10 +#define XLOG_NOOP 0x20 +#define XLOG_NEXTOID 0x30 +#define XLOG_SWITCH 0x40 +#define XLOG_BACKUP_END 0x50 +#define XLOG_PARAMETER_CHANGE 0x60 +#define XLOG_RESTORE_POINT 0x70 +#define XLOG_FPW_CHANGE 0x80 +#define XLOG_END_OF_RECOVERY 0x90 /* not use in mppdb*/ +#define XLOG_FPI_FOR_HINT 0xA0 +#define XLOG_FPI 0xB0 /* not use in mppdb*/ +#define XLOG_DELAY_XLOG_RECYCLE 0xC0 + + +/* + * System status indicator. Note this is stored in pg_control; if you change + * it, you must bump PG_CONTROL_VERSION + */ +typedef enum DBState { + DB_STARTUP = 0, + DB_SHUTDOWNED, + DB_SHUTDOWNED_IN_RECOVERY, + DB_SHUTDOWNING, + DB_IN_CRASH_RECOVERY, + DB_IN_ARCHIVE_RECOVERY, + DB_IN_PRODUCTION +} DBState; + +/* + * Contents of pg_control. + * + * NOTE: try to keep this under 512 bytes so that it will fit on one physical + * sector of typical disk drives. This reduces the odds of corruption due to + * power failure midway through a write. + */ +typedef struct ControlFileData { + /* + * Unique system identifier --- to ensure we match up xlog files with the + * installation that produced them. + */ + uint64 system_identifier; + + /* + * Version identifier information. Keep these fields at the same offset, + * especially pg_control_version; they won't be real useful if they move + * around. (For historical reasons they must be 8 bytes into the file + * rather than immediately at the front.) + * + * pg_control_version identifies the format of pg_control itself. + * catalog_version_no identifies the format of the system catalogs. + * + * There are additional version identifiers in individual files; for + * example, WAL logs contain per-page magic numbers that can serve as + * version cues for the WAL log. + */ + uint32 pg_control_version; /* PG_CONTROL_VERSION */ + uint32 catalog_version_no; /* see catversion.h */ + uint32 timeline; + + /* + * System status data + */ + DBState state; /* see enum above */ + pg_time_t time; /* time stamp of last pg_control update */ + XLogRecPtr checkPoint; /* last check point record ptr */ + XLogRecPtr prevCheckPoint; /* previous check point record ptr */ + + CheckPoint checkPointCopy; /* copy of last check point record */ + + /* + * These two values determine the minimum point we must recover up to + * before starting up: + * + * minRecoveryPoint is updated to the latest replayed LSN whenever we + * flush a data change during archive recovery. That guards against + * starting archive recovery, aborting it, and restarting with an earlier + * stop location. If we've already flushed data changes from WAL record X + * to disk, we mustn't start up until we reach X again. Zero when not + * doing archive recovery. + * + * backupStartPoint is the redo pointer of the backup start checkpoint, if + * we are recovering from an online backup and haven't reached the end of + * backup yet. It is reset to zero when the end of backup is reached, and + * we mustn't start up before that. A boolean would suffice otherwise, but + * we use the redo pointer as a cross-check when we see an end-of-backup + * record, to make sure the end-of-backup record corresponds the base + * backup we're recovering from. + * + * backupEndPoint is the backup end location, if we are recovering from an + * online backup which was taken from the standby and haven't reached the + * end of backup yet. It is initialized to the minimum recovery point in + * pg_control which was backed up last. It is reset to zero when the end + * of backup is reached, and we mustn't start up before that. + * + * If backupEndRequired is true, we know for sure that we're restoring + * from a backup, and must see a backup-end record before we can safely + * start up. If it's false, but backupStartPoint is set, a backup_label + * file was found at startup but it may have been a leftover from a stray + * pg_start_backup() call, not accompanied by pg_stop_backup(). + */ + XLogRecPtr minRecoveryPoint; + XLogRecPtr backupStartPoint; + XLogRecPtr backupEndPoint; + bool backupEndRequired; + + /* + * Parameter settings that determine if the WAL can be used for archival + * or hot standby. + */ + int wal_level; + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + + /* + * This data is used to check for hardware-architecture compatibility of + * the database and the backend executable. We need not check endianness + * explicitly, since the pg_control version will surely look wrong to a + * machine of different endianness, but we do need to worry about MAXALIGN + * and floating-point format. (Note: storage layout nominally also + * depends on SHORTALIGN and INTALIGN, but in practice these are the same + * on all architectures of interest.) + * + * Testing just one double value is not a very bulletproof test for + * floating-point compatibility, but it will catch most cases. + */ + uint32 maxAlign; /* alignment requirement for tuples */ + double floatFormat; /* constant 1234567.0 */ +#define FLOATFORMAT_VALUE 1234567.0 + + /* + * This data is used to make sure that configuration of this database is + * compatible with the backend executable. + */ + uint32 blcksz; /* data block size for this DB */ + uint32 relseg_size; /* blocks per segment of large relation */ + + uint32 xlog_blcksz; /* block size within WAL files */ + uint32 xlog_seg_size; /* size of each WAL segment */ + + uint32 nameDataLen; /* catalog name field width */ + uint32 indexMaxKeys; /* max number of columns in an index */ + + uint32 toast_max_chunk_size; /* chunk size in TOAST tables */ + + /* flag indicating internal format of timestamp, interval, time */ + bool enableIntTimes; /* int64 storage enabled? */ + + /* flags indicating pass-by-value status of various types */ + bool float4ByVal; /* float4 pass-by-value? */ + bool float8ByVal; /* float8, int8, etc pass-by-value? */ + + /* CRC of all above ... MUST BE LAST! */ + pg_crc32c crc; +} ControlFileData; + +/*This struct is used to verify the checksum of old version control file*/ +typedef struct ControlFileDataOld { + uint64 system_identifier; + uint32 pg_control_version; + uint32 catalog_version_no; + uint32 timeline; + DBState state; + pg_time_t time; + XLogRecPtrOld checkPoint; + XLogRecPtrOld prevCheckPoint; + CheckPointOld checkPointCopy; + XLogRecPtrOld minRecoveryPoint; + XLogRecPtrOld backupStartPoint; + XLogRecPtrOld backupEndPoint; + bool backupEndRequired; + int wal_level; + int MaxConnections; + int max_prepared_xacts; + int max_locks_per_xact; + uint32 maxAlign; + double floatFormat; + uint32 blcksz; + uint32 relseg_size; + uint32 xlog_blcksz; + uint32 xlog_seg_size; + uint32 nameDataLen; + uint32 indexMaxKeys; + uint32 toast_max_chunk_size; + bool enableIntTimes; + bool float4ByVal; + bool float8ByVal; + pg_crc32 crc; +}ControlFileDataOld; + +typedef struct LsnXlogFlushData { + XLogRecPtr localLsnFlushPoint; /* latest flush buffer's lsn postion on primary*/ + XLogRecPtr peerXlogFlushPoint; /* flush xlog postion on standby */ + pg_crc32 crc; +} LsnXlogFlushData; + +/* + * Physical size of the pg_control file. Note that this is considerably + * bigger than the actually used size (ie, sizeof(ControlFileData)). + * The idea is to keep the physical size constant independent of format + * changes, so that ReadControlFile will deliver a suitable wrong-version + * message instead of a read error if it's looking at an incompatible file. + */ +#define PG_CONTROL_SIZE 8192 + +#define PG_LSNXLOGFLUSHCHK_FILESIZE 512 +extern uint32 get_controlfile_timeline(void); +/* + * LsnXlogFlushData struct reserved 40 bytes,may be used in the future. + */ +#define PG_LSNXLOGFLUSHCHK_DATASIZE (40 + 2 * sizeof (XLogRecPtr)) + +#endif /* PG_CONTROL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_conversion_fn.h postgresql-hll-2.14/include/include/catalog/pg_conversion_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_conversion_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_conversion_fn.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * pg_conversion_fn.h + * prototypes for functions in catalog/pg_conversion.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_conversion_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONVERSION_FN_H +#define PG_CONVERSION_FN_H + +extern Oid ConversionCreate(const char *conname, Oid connamespace, + Oid conowner, + int32 conforencoding, int32 contoencoding, + Oid conproc, bool def); +extern void RemoveConversionById(Oid conversionOid); +extern Oid FindDefaultConversion(Oid connamespace, int32 for_encoding, int32 to_encoding); + +#endif /* PG_CONVERSION_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_conversion.h postgresql-hll-2.14/include/include/catalog/pg_conversion.h --- postgresql-hll-2.14_old/include/include/catalog/pg_conversion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_conversion.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * pg_conversion.h + * definition of the system "conversion" relation (pg_conversion) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_conversion.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CONVERSION_H +#define PG_CONVERSION_H + +#include "catalog/genbki.h" + +/* ---------------------------------------------------------------- + * pg_conversion definition. + * + * cpp turns this into typedef struct FormData_pg_namespace + * + * conname name of the conversion + * connamespace name space which the conversion belongs to + * conowner owner of the conversion + * conforencoding FOR encoding id + * contoencoding TO encoding id + * conproc OID of the conversion proc + * condefault TRUE if this is a default conversion + * ---------------------------------------------------------------- + */ +#define ConversionRelationId 2607 +#define ConversionRelation_Rowtype_Id 11630 + +CATALOG(pg_conversion,2607) BKI_SCHEMA_MACRO +{ + NameData conname; + Oid connamespace; + Oid conowner; + int4 conforencoding; + int4 contoencoding; + regproc conproc; + bool condefault; +} FormData_pg_conversion; + +/* ---------------- + * Form_pg_conversion corresponds to a pointer to a tuple with + * the format of pg_conversion relation. + * ---------------- + */ +typedef FormData_pg_conversion *Form_pg_conversion; + +/* ---------------- + * compiler constants for pg_conversion + * ---------------- + */ +#define Natts_pg_conversion 7 +#define Anum_pg_conversion_conname 1 +#define Anum_pg_conversion_connamespace 2 +#define Anum_pg_conversion_conowner 3 +#define Anum_pg_conversion_conforencoding 4 +#define Anum_pg_conversion_contoencoding 5 +#define Anum_pg_conversion_conproc 6 +#define Anum_pg_conversion_condefault 7 + +/* ---------------- + * initial contents of pg_conversion + * --------------- + */ +#endif /* PG_CONVERSION_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_database.h postgresql-hll-2.14/include/include/catalog/pg_database.h --- postgresql-hll-2.14_old/include/include/catalog/pg_database.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_database.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,91 @@ +/* ------------------------------------------------------------------------- + * + * pg_database.h + * definition of the system "database" relation (pg_database) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_database.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DATABASE_H +#define PG_DATABASE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_database definition. cpp turns this into + * typedef struct FormData_pg_database + * ---------------- + */ +#define DatabaseRelationId 1262 +#define DatabaseRelation_Rowtype_Id 1248 + +CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_MACRO +{ + NameData datname; /* database name */ + Oid datdba; /* owner of database */ + int4 encoding; /* character encoding */ + NameData datcollate; /* LC_COLLATE setting */ + NameData datctype; /* LC_CTYPE setting */ + bool datistemplate; /* allowed as CREATE DATABASE template? */ + bool datallowconn; /* new connections allowed? */ + int4 datconnlimit; /* max connections allowed (-1=no limit) */ + Oid datlastsysoid; /* highest OID to consider a system OID */ + ShortTransactionId datfrozenxid; /* all Xids < this are frozen in this DB */ + Oid dattablespace; /* default table space for this DB */ + NameData datcompatibility; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem datacl[1]; /* access permissions */ +#endif + TransactionId datfrozenxid64; /* all Xids < this are frozen in this DB */ +} FormData_pg_database; + +/* Size of fixed part of pg_database tuples, not counting var-length fields */ +#define DATABASE_TUPLE_SIZE \ + (offsetof(FormData_pg_database, datcompatibility) + sizeof(NameData)) + +/* ---------------- + * Form_pg_database corresponds to a pointer to a tuple with + * the format of pg_database relation. + * ---------------- + */ +typedef FormData_pg_database *Form_pg_database; + +/* ---------------- + * compiler constants for pg_database + * ---------------- + */ +#define Natts_pg_database 14 +#define Anum_pg_database_datname 1 +#define Anum_pg_database_datdba 2 +#define Anum_pg_database_encoding 3 +#define Anum_pg_database_datcollate 4 +#define Anum_pg_database_datctype 5 +#define Anum_pg_database_datistemplate 6 +#define Anum_pg_database_datallowconn 7 +#define Anum_pg_database_datconnlimit 8 +#define Anum_pg_database_datlastsysoid 9 +#define Anum_pg_database_datfrozenxid 10 +#define Anum_pg_database_dattablespace 11 +#define Anum_pg_database_compatibility 12 +#define Anum_pg_database_datacl 13 +#define Anum_pg_database_datfrozenxid64 14 + +DATA(insert OID = 1 ( template1 PGUID ENCODING "LC_COLLATE" "LC_CTYPE" t t -1 0 0 1663 "DB_COMPATIBILITY" _null_ 3)); +SHDESCR("default template for new databases"); +#define TemplateDbOid 1 + +#define DEFAULT_DATABASE "postgres" + +#endif /* PG_DATABASE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_db_role_setting.h postgresql-hll-2.14/include/include/catalog/pg_db_role_setting.h --- postgresql-hll-2.14_old/include/include/catalog/pg_db_role_setting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_db_role_setting.h 2020-12-12 17:06:43.154346838 +0800 @@ -0,0 +1,69 @@ +/* ------------------------------------------------------------------------- + * + * pg_db_role_setting.h + * definition of configuration settings + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_db_role_setting.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DB_ROLE_SETTING_H +#define PG_DB_ROLE_SETTING_H + +#include "utils/guc.h" +#include "utils/relcache.h" + +/* ---------------- + * pg_db_role_setting definition. cpp turns this into + * typedef struct FormData_pg_db_role_setting + * ---------------- + */ +#define DbRoleSettingRelationId 2964 +#define DbRoleSettingRelation_Rowtype_Id 11632 + +CATALOG(pg_db_role_setting,2964) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid setdatabase; /* database */ + Oid setrole; /* role */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text setconfig[1]; /* GUC settings to apply at login */ +#endif +} FormData_pg_db_role_setting; + +typedef FormData_pg_db_role_setting *Form_pg_db_role_setting; + +/* ---------------- + * compiler constants for pg_db_role_setting + * ---------------- + */ +#define Natts_pg_db_role_setting 3 +#define Anum_pg_db_role_setting_setdatabase 1 +#define Anum_pg_db_role_setting_setrole 2 +#define Anum_pg_db_role_setting_setconfig 3 + +/* ---------------- + * initial contents of pg_db_role_setting are NOTHING + * ---------------- + */ + +/* + * prototypes for functions in pg_db_role_setting.h + */ +extern void AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt); +extern void DropSetting(Oid databaseid, Oid roleid); +extern void ApplySetting(Oid databaseid, Oid roleid, Relation relsetting, GucSource source); + +#endif /* PG_DB_ROLE_SETTING_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_default_acl.h postgresql-hll-2.14/include/include/catalog/pg_default_acl.h --- postgresql-hll-2.14_old/include/include/catalog/pg_default_acl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_default_acl.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------------- + * + * pg_default_acl.h + * definition of default ACLs for new objects. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_default_acl.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DEFAULT_ACL_H +#define PG_DEFAULT_ACL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_default_acl definition. cpp turns this into + * typedef struct FormData_pg_default_acl + * ---------------- + */ +#define DefaultAclRelationId 826 +#define DefaultAclRelation_Rowtype_Id 11653 + +CATALOG(pg_default_acl,826) BKI_SCHEMA_MACRO +{ + Oid defaclrole; /* OID of role owning this ACL */ + Oid defaclnamespace; /* OID of namespace, or 0 for all */ + char defaclobjtype; /* see DEFACLOBJ_xxx constants below */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem defaclacl[1]; /* permissions to add at CREATE time */ +#endif +} FormData_pg_default_acl; + +/* ---------------- + * Form_pg_default_acl corresponds to a pointer to a tuple with + * the format of pg_default_acl relation. + * ---------------- + */ +typedef FormData_pg_default_acl *Form_pg_default_acl; + +/* ---------------- + * compiler constants for pg_default_acl + * ---------------- + */ +#define Natts_pg_default_acl 4 +#define Anum_pg_default_acl_defaclrole 1 +#define Anum_pg_default_acl_defaclnamespace 2 +#define Anum_pg_default_acl_defaclobjtype 3 +#define Anum_pg_default_acl_defaclacl 4 + +/* ---------------- + * pg_default_acl has no initial contents + * ---------------- + */ + +/* + * Types of objects for which the user is allowed to specify default + * permissions through pg_default_acl. These codes are used in the + * defaclobjtype column. + */ +#define DEFACLOBJ_RELATION 'r' /* table, view */ +#define DEFACLOBJ_SEQUENCE 'S' /* sequence */ +#define DEFACLOBJ_FUNCTION 'f' /* function */ +#define DEFACLOBJ_TYPE 'T' /* type */ +#define DEFACLOBJ_GLOBAL_SETTING 'K' /* Global Setting */ +#define DEFACLOBJ_COLUMN_SETTING 'k' /* Column Setting */ +#endif /* PG_DEFAULT_ACL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_depend.h postgresql-hll-2.14/include/include/catalog/pg_depend.h --- postgresql-hll-2.14_old/include/include/catalog/pg_depend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_depend.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,92 @@ +/* ------------------------------------------------------------------------- + * + * pg_depend.h + * definition of the system "dependency" relation (pg_depend) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_depend.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DEPEND_H +#define PG_DEPEND_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_depend definition. cpp turns this into + * typedef struct FormData_pg_depend + * ---------------- + */ +#define DependRelationId 2608 +#define DependRelation_Rowtype_Id 11631 + +CATALOG(pg_depend,2608) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* + * Identification of the dependent (referencing) object. + * + * These fields are all zeroes for a DEPENDENCY_PIN entry. + */ + Oid classid; /* OID of table containing object */ + Oid objid; /* OID of object itself */ + int4 objsubid; /* column number, or 0 if not used */ + + /* + * Identification of the independent (referenced) object. + */ + Oid refclassid; /* OID of table containing object */ + Oid refobjid; /* OID of object itself */ + int4 refobjsubid; /* column number, or 0 if not used */ + + /* + * Precise semantics of the relationship are specified by the deptype + * field. See DependencyType in catalog/dependency.h. + */ + char deptype; /* see codes in dependency.h */ +} FormData_pg_depend; + +/* ---------------- + * Form_pg_depend corresponds to a pointer to a row with + * the format of pg_depend relation. + * ---------------- + */ +typedef FormData_pg_depend *Form_pg_depend; + +/* ---------------- + * compiler constants for pg_depend + * ---------------- + */ +#define Natts_pg_depend 7 +#define Anum_pg_depend_classid 1 +#define Anum_pg_depend_objid 2 +#define Anum_pg_depend_objsubid 3 +#define Anum_pg_depend_refclassid 4 +#define Anum_pg_depend_refobjid 5 +#define Anum_pg_depend_refobjsubid 6 +#define Anum_pg_depend_deptype 7 + + +/* + * pg_depend has no preloaded contents; system-defined dependencies are + * loaded into it during a late stage of the initdb process. + * + * NOTE: we do not represent all possible dependency pairs in pg_depend; + * for example, there's not much value in creating an explicit dependency + * from an attribute to its relation. Usually we make a dependency for + * cases where the relationship is conditional rather than essential + * (for example, not all triggers are dependent on constraints, but all + * attributes are dependent on relations) or where the dependency is not + * convenient to find from the contents of other catalogs. + */ + +#endif /* PG_DEPEND_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_description.h postgresql-hll-2.14/include/include/catalog/pg_description.h --- postgresql-hll-2.14_old/include/include/catalog/pg_description.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_description.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,89 @@ +/* ------------------------------------------------------------------------- + * + * pg_description.h + * definition of the system "description" relation (pg_description) + * + * NOTE: an object is identified by the OID of the row that primarily + * defines the object, plus the OID of the table that that row appears in. + * For example, a function is identified by the OID of its pg_proc row + * plus the pg_class OID of table pg_proc. This allows unique identification + * of objects without assuming that OIDs are unique across tables. + * + * Since attributes don't have OIDs of their own, we identify an attribute + * comment by the objoid+classoid of its parent table, plus an "objsubid" + * giving the attribute column number. "objsubid" must be zero in a comment + * for a table itself, so that it is distinct from any column comment. + * Currently, objsubid is unused and zero for all other kinds of objects, + * but perhaps it might be useful someday to associate comments with + * constituent elements of other kinds of objects (arguments of a function, + * for example). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_description.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_DESCRIPTION_H +#define PG_DESCRIPTION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_description definition. cpp turns this into + * typedef struct FormData_pg_description + * ---------------- + */ +#define DescriptionRelationId 2609 +#define DescriptionRelation_Rowtype_Id 11330 + +CATALOG(pg_description,2609) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of object itself */ + Oid classoid; /* OID of table containing object */ + int4 objsubid; /* column number, or 0 if not used */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text description; /* description of object */ +#endif +} FormData_pg_description; + +/* ---------------- + * Form_pg_description corresponds to a pointer to a tuple with + * the format of pg_description relation. + * ---------------- + */ +typedef FormData_pg_description *Form_pg_description; + +/* ---------------- + * compiler constants for pg_description + * ---------------- + */ +#define Natts_pg_description 4 +#define Anum_pg_description_objoid 1 +#define Anum_pg_description_classoid 2 +#define Anum_pg_description_objsubid 3 +#define Anum_pg_description_description 4 + +/* ---------------- + * initial contents of pg_description + * ---------------- + */ + +/* + * Because the contents of this table are taken from the other *.h files, + * there is no initialization here. The initial contents are extracted + * by genbki.pl and loaded during initdb. + */ + +#endif /* PG_DESCRIPTION_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_directory.h postgresql-hll-2.14/include/include/catalog/pg_directory.h --- postgresql-hll-2.14_old/include/include/catalog/pg_directory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_directory.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_directory.h + * definition of the system "pg_directory" relation (pg_directory) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_directory.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_DIRECTORY_H +#define PG_DIRECTORY_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" + +/* ------------------------------------------------------------------------- + * pg_directories definition. cpp turns this into + * typedef struct FormData_pg_directory + * ------------------------------------------------------------------------- + */ +#define PgDirectoryRelationId 4347 +#define PgDirectoryRelation_Rowtype_Id 11662 + +CATALOG(pg_directory,4347) BKI_SCHEMA_MACRO +{ + NameData dirname; /* directory name */ + Oid owner; /* owner of directory */ + text dirpath; /* real directory path */ +#ifdef CATALOG_VARLEN /* variable-length fields start here*/ + aclitem diracl[1]; /* access permissions */ +#endif +} FormData_pg_directory; + + +/* ------------------------------------------------------------------------- + * Form_pg_directory corresponds to a pointer to a tuple with + * the format of pg_directory relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_directory* Form_pg_directory; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_directory + * ------------------------------------------------------------------------- + */ +#define Natts_pg_directory 4 +#define Anum_pg_directory_directory_name 1 +#define Anum_pg_directory_owner 2 +#define Anum_pg_directory_directory_path 3 +#define Anum_pg_directory_directory_acl 4 + +#endif /* PG_DIRECTORY_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_enum.h postgresql-hll-2.14/include/include/catalog/pg_enum.h --- postgresql-hll-2.14_old/include/include/catalog/pg_enum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_enum.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,74 @@ +/* ------------------------------------------------------------------------- + * + * pg_enum.h + * definition of the system "enum" relation (pg_enum) + * along with the relation's initial contents. + * + * + * Copyright (c) 2006-2012, PostgreSQL Global Development Group + * + * src/include/catalog/pg_enum.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_ENUM_H +#define PG_ENUM_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_enum definition. cpp turns this into + * typedef struct FormData_pg_enum + * ---------------- + */ +#define EnumRelationId 3501 +#define EnumRelation_Rowtype_Id 11628 + +CATALOG(pg_enum,3501) BKI_SCHEMA_MACRO +{ + Oid enumtypid; /* OID of owning enum type */ + float4 enumsortorder; /* sort position of this enum value */ + NameData enumlabel; /* text representation of enum value */ +} FormData_pg_enum; + +/* ---------------- + * Form_pg_enum corresponds to a pointer to a tuple with + * the format of pg_enum relation. + * ---------------- + */ +typedef FormData_pg_enum *Form_pg_enum; + +/* ---------------- + * compiler constants for pg_enum + * ---------------- + */ +#define Natts_pg_enum 3 +#define Anum_pg_enum_enumtypid 1 +#define Anum_pg_enum_enumsortorder 2 +#define Anum_pg_enum_enumlabel 3 + +/* ---------------- + * pg_enum has no initial contents + * ---------------- + */ + +/* + * prototypes for functions in pg_enum.c + */ +extern void EnumValuesCreate(Oid enumTypeOid, List *vals); +extern void EnumValuesDelete(Oid enumTypeOid); +extern void AddEnumLabel(Oid enumTypeOid, const char *newVal, + const char *neighbor, bool newValIsAfter, + bool skipIfExists); +extern void RenameEnumLabel(Oid enumTypeOid, const char *oldVal, const char *newVal); + +#endif /* PG_ENUM_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_extension_data_source.h postgresql-hll-2.14/include/include/catalog/pg_extension_data_source.h --- postgresql-hll-2.14_old/include/include/catalog/pg_extension_data_source.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_extension_data_source.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,65 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_extension_data_source.h + * definition of the system "data source" relation (pg_extension_data_source) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/catalog/pg_extension_data_source.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_EXTENSION_DATA_SOURCE_H +#define PG_EXTENSION_DATA_SOURCE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_extension_data_source definition. cpp turns this into + * typedef struct FormData_pg_extension_data_source + * ---------------- + */ +#define DataSourceRelationId 4211 +#define DataSourceRelation_Rowtype_Id 7177 + +CATALOG(pg_extension_data_source,4211) BKI_SHARED_RELATION BKI_ROWTYPE_OID(7177) BKI_SCHEMA_MACRO +{ + NameData srcname; /* data source name */ + Oid srcowner; /* source owner */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text srctype; /* source type */ + text srcversion; /* source version */ + aclitem srcacl[1]; /* access permissions */ + text srcoptions[1]; /* options */ +#endif +} FormData_pg_extension_data_source; + +/* ---------------- + * Form_data_source corresponds to a pointer to a tuple with + * the format of pg_extension_data_source relation. + * ---------------- + */ +typedef FormData_pg_extension_data_source *Form_pg_extension_data_source; + +/* ---------------- + * compiler constants for pg_extension_data_source + * ---------------- + */ +#define Natts_pg_extension_data_source 6 +#define Anum_pg_extension_data_source_srcname 1 +#define Anum_pg_extension_data_source_srcowner 2 +#define Anum_pg_extension_data_source_srctype 3 +#define Anum_pg_extension_data_source_srcversion 4 +#define Anum_pg_extension_data_source_srcacl 5 +#define Anum_pg_extension_data_source_srcoptions 6 + +#endif /* PG_EXTENSION_DATA_SOURCE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_extension.h postgresql-hll-2.14/include/include/catalog/pg_extension.h --- postgresql-hll-2.14_old/include/include/catalog/pg_extension.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_extension.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,73 @@ +/* ------------------------------------------------------------------------- + * + * pg_extension.h + * definition of the system "extension" relation (pg_extension) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_extension.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_EXTENSION_H +#define PG_EXTENSION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_extension definition. cpp turns this into + * typedef struct FormData_pg_extension + * ---------------- + */ +#define ExtensionRelationId 3079 +#define ExtensionRelation_Rowtype_Id 11643 + +CATALOG(pg_extension,3079) BKI_SCHEMA_MACRO +{ + NameData extname; /* extension name */ + Oid extowner; /* extension owner */ + Oid extnamespace; /* namespace of contained objects */ + bool extrelocatable; /* if true, allow ALTER EXTENSION SET SCHEMA */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + /* extversion should never be null, but the others can be. */ + text extversion; /* extension version name */ + Oid extconfig[1]; /* dumpable configuration tables */ + text extcondition[1]; /* WHERE clauses for config tables */ +#endif +} FormData_pg_extension; + +/* ---------------- + * Form_pg_extension corresponds to a pointer to a tuple with + * the format of pg_extension relation. + * ---------------- + */ +typedef FormData_pg_extension *Form_pg_extension; + +/* ---------------- + * compiler constants for pg_extension + * ---------------- + */ +#define Natts_pg_extension 7 +#define Anum_pg_extension_extname 1 +#define Anum_pg_extension_extowner 2 +#define Anum_pg_extension_extnamespace 3 +#define Anum_pg_extension_extrelocatable 4 +#define Anum_pg_extension_extversion 5 +#define Anum_pg_extension_extconfig 6 +#define Anum_pg_extension_extcondition 7 + +/* ---------------- + * pg_extension has no initial contents + * ---------------- + */ + +#endif /* PG_EXTENSION_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_foreign_data_wrapper.h postgresql-hll-2.14/include/include/catalog/pg_foreign_data_wrapper.h --- postgresql-hll-2.14_old/include/include/catalog/pg_foreign_data_wrapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_foreign_data_wrapper.h 2020-12-12 17:06:43.155346851 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_data_wrapper.h + * definition of the system "foreign-data wrapper" relation (pg_foreign_data_wrapper) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_data_wrapper.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_DATA_WRAPPER_H +#define PG_FOREIGN_DATA_WRAPPER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_data_wrapper definition. cpp turns this into + * typedef struct FormData_pg_foreign_data_wrapper + * ---------------- + */ +#define ForeignDataWrapperRelationId 2328 +#define ForeignDataWrapperRelation_Rowtype_Id 11645 + +CATALOG(pg_foreign_data_wrapper,2328) BKI_SCHEMA_MACRO +{ + NameData fdwname; /* foreign-data wrapper name */ + Oid fdwowner; /* FDW owner */ + Oid fdwhandler; /* handler function, or 0 if none */ + Oid fdwvalidator; /* option validation function, or 0 if none */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem fdwacl[1]; /* access permissions */ + text fdwoptions[1]; /* FDW options */ +#endif +} FormData_pg_foreign_data_wrapper; + +/* ---------------- + * Form_pg_fdw corresponds to a pointer to a tuple with + * the format of pg_fdw relation. + * ---------------- + */ +typedef FormData_pg_foreign_data_wrapper *Form_pg_foreign_data_wrapper; + +/* ---------------- + * compiler constants for pg_fdw + * ---------------- + */ +#define Natts_pg_foreign_data_wrapper 6 +#define Anum_pg_foreign_data_wrapper_fdwname 1 +#define Anum_pg_foreign_data_wrapper_fdwowner 2 +#define Anum_pg_foreign_data_wrapper_fdwhandler 3 +#define Anum_pg_foreign_data_wrapper_fdwvalidator 4 +#define Anum_pg_foreign_data_wrapper_fdwacl 5 +#define Anum_pg_foreign_data_wrapper_fdwoptions 6 + +#endif /* PG_FOREIGN_DATA_WRAPPER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_foreign_server.h postgresql-hll-2.14/include/include/catalog/pg_foreign_server.h --- postgresql-hll-2.14_old/include/include/catalog/pg_foreign_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_foreign_server.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,66 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_server.h + * definition of the system "foreign server" relation (pg_foreign_server) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_server.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_SERVER_H +#define PG_FOREIGN_SERVER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_server definition. cpp turns this into + * typedef struct FormData_pg_foreign_server + * ---------------- + */ +#define ForeignServerRelationId 1417 +#define ForeignServerRelation_Rowtype_Id 11646 + + +CATALOG(pg_foreign_server,1417) BKI_SCHEMA_MACRO +{ + NameData srvname; /* foreign server name */ + Oid srvowner; /* server owner */ + Oid srvfdw; /* server FDW */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text srvtype; + text srvversion; + aclitem srvacl[1]; /* access permissions */ + text srvoptions[1]; /* FDW-specific options */ +#endif +} FormData_pg_foreign_server; + +/* ---------------- + * Form_pg_foreign_server corresponds to a pointer to a tuple with + * the format of pg_foreign_server relation. + * ---------------- + */ +typedef FormData_pg_foreign_server *Form_pg_foreign_server; + +/* ---------------- + * compiler constants for pg_foreign_server + * ---------------- + */ +#define Natts_pg_foreign_server 7 +#define Anum_pg_foreign_server_srvname 1 +#define Anum_pg_foreign_server_srvowner 2 +#define Anum_pg_foreign_server_srvfdw 3 +#define Anum_pg_foreign_server_srvtype 4 +#define Anum_pg_foreign_server_srvversion 5 +#define Anum_pg_foreign_server_srvacl 6 +#define Anum_pg_foreign_server_srvoptions 7 + +#endif /* PG_FOREIGN_SERVER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_foreign_table.h postgresql-hll-2.14/include/include/catalog/pg_foreign_table.h --- postgresql-hll-2.14_old/include/include/catalog/pg_foreign_table.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_foreign_table.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * pg_foreign_table.h + * definition of the system "foreign table" relation (pg_foreign_table) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_foreign_table.h + * + * NOTES + * the genbki.sh script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_FOREIGN_TABLE_H +#define PG_FOREIGN_TABLE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_foreign_table definition. cpp turns this into + * typedef struct FormData_pg_foreign_table + * ---------------- + */ +#define ForeignTableRelationId 3118 +#define ForeignTableRelation_Rowtype_Id 11651 + +CATALOG(pg_foreign_table,3118) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid ftrelid; /* OID of foreign table */ + Oid ftserver; /* OID of foreign server */ + bool ftwriteonly; /* Read/Write only, Notice: all low case */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text ftoptions[1]; /* FDW-specific options */ +#endif +} FormData_pg_foreign_table; + +/* ---------------- + * Form_pg_foreign_table corresponds to a pointer to a tuple with + * the format of pg_foreign_table relation. + * ---------------- + */ +typedef FormData_pg_foreign_table *Form_pg_foreign_table; + +/* ---------------- + * compiler constants for pg_foreign_table + * ---------------- + */ +#define Natts_pg_foreign_table 4 +#define Anum_pg_foreign_table_ftrelid 1 +#define Anum_pg_foreign_table_ftserver 2 +#define Anum_pg_foreign_table_ftwriteonly 3 +#define Anum_pg_foreign_table_ftoptions 4 + +#endif /* PG_FOREIGN_TABLE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_hashbucket_fn.h postgresql-hll-2.14/include/include/catalog/pg_hashbucket_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_hashbucket_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_hashbucket_fn.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_hashbucket_fn.h + * + * + * IDENTIFICATION + * src/include/catalog/pg_hashbucket_fn.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_HASHBUCKET_FN_H +#define PG_HASHBUCKET_FN_H + +extern Oid insertHashBucketEntry(oidvector *bucketlist, Oid bucketid); +extern Oid searchHashBucketByBucketid(oidvector *bucketlist, Oid bucketid); +extern text* searchMergeListByRelid(Oid reloid, bool *find, bool retresult = true); + +extern oidvector *searchHashBucketByOid(Oid bucketOid); +extern List *relationGetBucketRelList(Relation rel, Partition part); +extern void BucketCacheInitialize(void); +extern void AtEOXact_BucketCache(bool isCommit); +extern void AtEOSubXact_BucketCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern int64 execute_drop_bucketlist(Oid relOid1, Oid relOid2, bool isPart); +extern int64 execute_move_bucketlist(Oid relOid1, Oid relOid2, bool isPart); +extern void relation_swap_bucket(Oid r1, Oid r2); +#endif + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_hashbucket.h postgresql-hll-2.14/include/include/catalog/pg_hashbucket.h --- postgresql-hll-2.14_old/include/include/catalog/pg_hashbucket.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_hashbucket.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_hashbucket.h + * + * + * IDENTIFICATION + * src/include/catalog/pg_hashbucket.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef PG_HASHBUCKET_H +#define PG_HASHBUCKET_H +#include "catalog/genbki.h" + +#define HashBucketRelationId 9026 +#define HashBucketRelationId_Rowtype_Id 9007 + +CATALOG(pg_hashbucket,9026) BKI_SCHEMA_MACRO +{ + Oid bucketid; + int4 bucketcnt; +#ifdef CATALOG_VARLEN + oidvector_extend bucketvector; +#endif +} FormData_pg_hashbucket; + +#define Natts_pg_hashbucket 3 +#define Anum_pg_hashbucket_bucketid 1 +#define Anum_pg_hashbucket_bucketcnt 2 +#define Anum_pg_hashbucket_bucketvector 3 +#endif /* PG_HASHBUCKET_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_index.h postgresql-hll-2.14/include/include/catalog/pg_index.h --- postgresql-hll-2.14_old/include/include/catalog/pg_index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_index.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,117 @@ +/* ------------------------------------------------------------------------- + * + * pg_index.h + * definition of the system "index" relation (pg_index) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_index.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INDEX_H +#define PG_INDEX_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_index definition. cpp turns this into + * typedef struct FormData_pg_index. + * ---------------- + */ +#define IndexRelationId 2610 +#define IndexRelation_Rowtype_Id 10003 + +CATALOG(pg_index,2610) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid indexrelid; /* OID of the index */ + Oid indrelid; /* OID of the relation it indexes */ + int2 indnatts; /* total number of columns in index */ + bool indisunique; /* is this a unique index? */ + bool indisprimary; /* is this index for primary key? */ + bool indisexclusion; /* is this index for exclusion constraint? */ + bool indimmediate; /* is uniqueness enforced immediately? */ + bool indisclustered; /* is this the index last clustered by? */ + bool indisusable; /* is this index useable for insert and select?*/ + /*if yes, insert and select should ignore this index*/ + bool indisvalid; /* is this index valid for use by queries? */ + bool indcheckxmin; /* must we wait for xmin to be old? */ + bool indisready; /* is this index ready for inserts? */ + + /* variable-length fields start here, but we allow direct access to indkey */ + int2vector indkey; /* column numbers of indexed cols, or 0 */ + +#ifdef CATALOG_VARLEN + oidvector indcollation; /* collation identifiers */ + oidvector indclass; /* opclass identifiers */ + int2vector indoption; /* per-column flags (AM-specific meanings) */ + pg_node_tree indexprs; /* expression trees for index attributes that + * are not simple column references; one for + * each zero entry in indkey[] */ + pg_node_tree indpred; /* expression tree for predicate, if a partial + * index; else NULL */ + bool indisreplident; /* is this index the identity for replication? */ + int2 indnkeyatts; /* number of key columns in index */ +#endif +} FormData_pg_index; + +/* ---------------- + * Form_pg_index corresponds to a pointer to a tuple with + * the format of pg_index relation. + * ---------------- + */ +typedef FormData_pg_index *Form_pg_index; + +/* ---------------- + * compiler constants for pg_index + * ---------------- + */ +#define Natts_pg_index 20 +#define Anum_pg_index_indexrelid 1 +#define Anum_pg_index_indrelid 2 +#define Anum_pg_index_indnatts 3 +#define Anum_pg_index_indisunique 4 +#define Anum_pg_index_indisprimary 5 +#define Anum_pg_index_indisexclusion 6 +#define Anum_pg_index_indimmediate 7 +#define Anum_pg_index_indisclustered 8 +#define Anum_pg_index_indisusable 9 +#define Anum_pg_index_indisvalid 10 +#define Anum_pg_index_indcheckxmin 11 +#define Anum_pg_index_indisready 12 +#define Anum_pg_index_indkey 13 +#define Anum_pg_index_indcollation 14 +#define Anum_pg_index_indclass 15 +#define Anum_pg_index_indoption 16 +#define Anum_pg_index_indexprs 17 +#define Anum_pg_index_indpred 18 +#define Anum_pg_index_indisreplident 19 +#define Anum_pg_index_indnkeyatts 20 + +/* + * Index AMs that support ordered scans must support these two indoption + * bits. Otherwise, the content of the per-column indoption fields is + * open for future definition. + */ +#define INDOPTION_DESC 0x0001 /* values are in reverse order */ +#define INDOPTION_NULLS_FIRST 0x0002 /* NULLs are first instead of last */ + +/* + * Use of these macros is recommended over direct examination of the state + * flag columns where possible; this allows source code compatibility with + * the less ugly representation used after 9.2. + */ +#define IndexIsUsable(indexForm) ((indexForm)->indisusable) +#define IndexIsReady(indexForm) ((indexForm)->indisready) +#define IndexIsValid(indexForm) (((indexForm)->indisvalid && (indexForm)->indisready) && ((indexForm)->indisusable)) +#define IndexIsLive(indexForm) (((indexForm)->indisready || !(indexForm)->indisvalid) && ((indexForm)->indisusable)) + +#endif /* PG_INDEX_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_inherits_fn.h postgresql-hll-2.14/include/include/catalog/pg_inherits_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_inherits_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_inherits_fn.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * pg_inherits_fn.h + * prototypes for functions in catalog/pg_inherits.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_inherits_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INHERITS_FN_H +#define PG_INHERITS_FN_H + +#include "nodes/pg_list.h" +#include "storage/lock.h" + +extern List *find_inheritance_children(Oid parentrelId, LOCKMODE lockmode); +extern List *find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **parents); +extern bool has_subclass(Oid relationId); +extern bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId); + +#endif /* PG_INHERITS_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_inherits.h postgresql-hll-2.14/include/include/catalog/pg_inherits.h --- postgresql-hll-2.14_old/include/include/catalog/pg_inherits.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_inherits.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_inherits.h + * definition of the system "inherits" relation (pg_inherits) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_inherits.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_INHERITS_H +#define PG_INHERITS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_inherits definition. cpp turns this into + * typedef struct FormData_pg_inherits + * ---------------- + */ +#define InheritsRelationId 2611 +#define InheritsRelation_Rowtype_Id 10002 + +CATALOG(pg_inherits,2611) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid inhrelid; + Oid inhparent; + int4 inhseqno; +} FormData_pg_inherits; + +/* ---------------- + * Form_pg_inherits corresponds to a pointer to a tuple with + * the format of pg_inherits relation. + * ---------------- + */ +typedef FormData_pg_inherits *Form_pg_inherits; + +/* ---------------- + * compiler constants for pg_inherits + * ---------------- + */ +#define Natts_pg_inherits 3 +#define Anum_pg_inherits_inhrelid 1 +#define Anum_pg_inherits_inhparent 2 +#define Anum_pg_inherits_inhseqno 3 + +/* ---------------- + * pg_inherits has no initial contents + * ---------------- + */ +#endif /* PG_INHERITS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_job.h postgresql-hll-2.14/include/include/catalog/pg_job.h --- postgresql-hll-2.14_old/include/include/catalog/pg_job.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_job.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,161 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_job.h + * definition of the system "job" relation (pg_job) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_job.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_JOB_H +#define PG_JOB_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "fmgr.h" +#include "utils/date.h" + +#ifdef HAVE_INT64_TIMESTAMP +#define timestamp int64 +#else +#define timestamp double +#endif + +#define int8 int64 + +/* ------------------------------------------------------------------------- + * pg_job definition. cpp turns this into + * typedef struct FormData_pg_job + * ------------------------------------------------------------------------- + */ +#define PgJobRelationId 9022 +#define PgJobRelation_Rowtype_Id 11658 + +CATALOG(pg_job,9022) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + int8 job_id; /* Identifier of job. */ + int8 current_postgres_pid; /* if jobstatus is 'r', this is postgres's pid which is running this job */ + NameData log_user; /* Login user when the job was submitted */ + NameData priv_user; /* User whose default privileges apply to this job, reserved, unused at present */ + NameData dbname; /* A database name against which to run the script */ + NameData node_name; /* Identify the which coordinator the job create and execute */ + char job_status; /* Status of job: r=running, s=successfully finished, f=failed stopping job, + * i=ignored failure, d=aborted */ + timestamp start_date; /* Date that this job first started executing */ + timestamp next_run_date; /* Date that this job will next be executed, this is calculated by + * pg_job_schedule.RECURRENCE_EXPR */ + int2 failure_count; /* Number of times the job has started and failed since its last success, + * if more than 16, this job will be terminated */ +#ifdef CATALOG_VARLEN /* Null value constrain */ + text interval; /* A date function, evaluated at the start of execution, becomes next NEXT_DATE */ + timestamp last_start_date; /* This is when the last execution started. */ + timestamp last_end_date; /* This is when the last execution stoped. */ + timestamp last_suc_date; /* This is when the last successful execution started. */ + timestamp this_run_date; /* Date that this job started executing (usually null if not executing) */ +#endif + NameData nspname; +} FormData_pg_job; + +#undef timestamp +#undef int8 + +/* ------------------------------------------------------------------------- + * Form_pg_job corresponds to a pointer to a tuple with + * the format of pg_job relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_job* Form_pg_job; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_job + * ------------------------------------------------------------------------- + */ +#define Natts_pg_job 16 +#define Anum_pg_job_job_id 1 +#define Anum_pg_job_current_postgres_pid 2 +#define Anum_pg_job_log_user 3 +#define Anum_pg_job_priv_user 4 +#define Anum_pg_job_dbname 5 +#define Anum_pg_job_node_name 6 +#define Anum_pg_job_job_status 7 +#define Anum_pg_job_start_date 8 +#define Anum_pg_job_next_run_date 9 +#define Anum_pg_job_failure_count 10 +#define Anum_pg_job_interval 11 +#define Anum_pg_job_last_start_date 12 +#define Anum_pg_job_last_end_date 13 +#define Anum_pg_job_last_suc_date 14 +#define Anum_pg_job_this_run_date 15 +#define Anum_pg_job_nspname 16 + + + +/* Type of pg job command. */ +typedef enum +{ + Job_Submit, + Job_ISubmit, + Job_ISubmit_Node, + Job_ISubmit_Node_Internal, + Job_Remove, + Job_Update, + Job_Finish +} Pgjob_Command_Type; + +/* Status of pg job. */ +typedef enum { + Pgjob_Run, + Pgjob_Succ, + Pgjob_Fail, /* Execute what fail */ +} Update_Pgjob_Status; + +/* Oid of related for delete pg_job. */ +typedef enum { + DbOid, + UserOid, + RelOid +} Delete_Pgjob_Oid; + +/* Define job status. */ +#define PGJOB_RUN_STATUS 'r' +#define PGJOB_SUCC_STATUS 's' +#define PGJOB_FAIL_STATUS 'f' +#define PGJOB_ABORT_STATUS 'd' + +/* job run type */ +#define PGJOB_TYPE_ALL_CN "ALL_CN" +#define PGJOB_TYPE_ALL_DN "ALL_DN" +#define PGJOB_TYPE_ALL "ALL_NODE" +#define PGJOB_TYPE_CCN "CCN" + +extern void update_run_job_to_fail(); +extern void remove_job_by_oid(const char *objname, Delete_Pgjob_Oid oidFlag, bool local, Oid job_id = InvalidOid); +extern void execute_job(int4 job_id); +extern void get_job_values(int4 job_id, HeapTuple tup, Relation relation, Datum *values, bool *visnull); +extern void check_job_permission(HeapTuple tuple, bool check_running = true); +extern int jobid_alloc(uint16* pusJobId); +#define JOBID_MAX_NUMBER ((uint16)(32767)) + +#define JOBID_ALLOC_OK 0 /* alloc jobid ok */ +#define JOBID_ALLOC_ERROR 1 /* alloc jobid error */ + +#endif /* PG_JOB_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_job_proc.h postgresql-hll-2.14/include/include/catalog/pg_job_proc.h --- postgresql-hll-2.14_old/include/include/catalog/pg_job_proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_job_proc.h 2020-12-12 17:06:43.156346864 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_job_proc.h + * definition of the system "job task" relation (pg_job_proc) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_job_proc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_JOB_PROC_H +#define PG_JOB_PROC_H + +#include "catalog/genbki.h" + +/*------------------------------------------------------------------------- + * pg_job_proc definition. cpp turns this into + * typedef struct FormData_pg_job_proc + *------------------------------------------------------------------------- + */ +#define PgJobProcRelationId 9023 +#define PgJobProcRelation_Rowtype_Id 11659 + +CATALOG(pg_job_proc,9023) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + int4 job_id; /* foreign key, reference to pg_job.job_id */ + text what; /* Body of the anonymous PL/pgSQL block that the job executes */ +} FormData_pg_job_proc; + +/*------------------------------------------------------------------------- + * Form_pg_job_proc corresponds to a pointer to a tuple with + * the format of pg_job_proc relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_job_proc* Form_pg_job_proc; + +/*------------------------------------------------------------------------- + * compiler constants for pg_job_schedule + *------------------------------------------------------------------------- + */ +#define Natts_pg_job_proc 2 +#define Anum_pg_job_proc_job_id 1 +#define Anum_pg_job_proc_what 2 + +#endif /* PG_JOB_PROC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_language.h postgresql-hll-2.14/include/include/catalog/pg_language.h --- postgresql-hll-2.14_old/include/include/catalog/pg_language.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_language.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_language.h + * definition of the system "language" relation (pg_language) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_language.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LANGUAGE_H +#define PG_LANGUAGE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_language definition. cpp turns this into + * typedef struct FormData_pg_language + * ---------------- + */ +#define LanguageRelationId 2612 +#define LanguageRelation_Rowtype_Id 11323 + +CATALOG(pg_language,2612) BKI_SCHEMA_MACRO +{ + NameData lanname; /* Language name */ + Oid lanowner; /* Language's owner */ + bool lanispl; /* Is a procedural language */ + bool lanpltrusted; /* PL is trusted */ + Oid lanplcallfoid; /* Call handler for PL */ + Oid laninline; /* Optional anonymous-block handler function */ + Oid lanvalidator; /* Optional validation function */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem lanacl[1]; /* Access privileges */ +#endif +} FormData_pg_language; + +/* ---------------- + * Form_pg_language corresponds to a pointer to a tuple with + * the format of pg_language relation. + * ---------------- + */ +typedef FormData_pg_language *Form_pg_language; + +/* ---------------- + * compiler constants for pg_language + * ---------------- + */ +#define Natts_pg_language 8 +#define Anum_pg_language_lanname 1 +#define Anum_pg_language_lanowner 2 +#define Anum_pg_language_lanispl 3 +#define Anum_pg_language_lanpltrusted 4 +#define Anum_pg_language_lanplcallfoid 5 +#define Anum_pg_language_laninline 6 +#define Anum_pg_language_lanvalidator 7 +#define Anum_pg_language_lanacl 8 + +/* ---------------- + * initial contents of pg_language + * ---------------- + */ +DATA(insert OID = 12 ( "internal" PGUID f f 0 0 2246 _null_ )); +DESCR("built-in functions"); +#define INTERNALlanguageId 12 +DATA(insert OID = 13 ( "c" PGUID f f 0 0 2247 _null_ )); +DESCR("dynamically-loaded C functions"); +#define ClanguageId 13 +DATA(insert OID = 14 ( "sql" PGUID f t 0 0 2248 _null_ )); +DESCR("SQL-language functions"); +#define SQLlanguageId 14 +DATA(insert OID = 15 ( "java" PGUID f f 0 0 0 _null_ )); +DESCR("dynamically-loaded Java functions"); +#define JavalanguageId 15 + +#endif /* PG_LANGUAGE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_largeobject.h postgresql-hll-2.14/include/include/catalog/pg_largeobject.h --- postgresql-hll-2.14_old/include/include/catalog/pg_largeobject.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_largeobject.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * pg_largeobject.h + * definition of the system "largeobject" relation (pg_largeobject) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_largeobject.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LARGEOBJECT_H +#define PG_LARGEOBJECT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_largeobject definition. cpp turns this into + * typedef struct FormData_pg_largeobject + * ---------------- + */ +#define LargeObjectRelationId 2613 +#define LargeObjectRelation_Rowtype_Id 11325 + +CATALOG(pg_largeobject,2613) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid loid; /* Identifier of large object */ + int4 pageno; /* Page number (starting from 0) */ + + /* data has variable length, but we allow direct access; see inv_api.c */ + bytea data; /* Data for page (may be zero-length) */ +} FormData_pg_largeobject; + +/* ---------------- + * Form_pg_largeobject corresponds to a pointer to a tuple with + * the format of pg_largeobject relation. + * ---------------- + */ +typedef FormData_pg_largeobject *Form_pg_largeobject; + +/* ---------------- + * compiler constants for pg_largeobject + * ---------------- + */ +#define Natts_pg_largeobject 3 +#define Anum_pg_largeobject_loid 1 +#define Anum_pg_largeobject_pageno 2 +#define Anum_pg_largeobject_data 3 + +extern Oid LargeObjectCreate(Oid loid); +extern void LargeObjectDrop(Oid loid); +extern void LargeObjectAlterOwner(Oid loid, Oid newOwnerId); +extern bool LargeObjectExists(Oid loid); + +#endif /* PG_LARGEOBJECT_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_largeobject_metadata.h postgresql-hll-2.14/include/include/catalog/pg_largeobject_metadata.h --- postgresql-hll-2.14_old/include/include/catalog/pg_largeobject_metadata.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_largeobject_metadata.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,57 @@ +/* ------------------------------------------------------------------------- + * + * pg_largeobject_metadata.h + * definition of the system "largeobject_metadata" relation (pg_largeobject_metadata) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_largeobject_metadata.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LARGEOBJECT_METADATA_H +#define PG_LARGEOBJECT_METADATA_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_largeobject_metadata definition. cpp turns this into + * typedef struct FormData_pg_largeobject_metadata + * ---------------- + */ +#define LargeObjectMetadataRelationId 2995 +#define LargeObjectMetadataRelation_Rowtype_Id 11324 + +CATALOG(pg_largeobject_metadata,2995) BKI_SCHEMA_MACRO +{ + Oid lomowner; /* OID of the largeobject owner */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem lomacl[1]; /* access permissions */ +#endif +} FormData_pg_largeobject_metadata; + +/* ---------------- + * Form_pg_largeobject_metadata corresponds to a pointer to a tuple + * with the format of pg_largeobject_metadata relation. + * ---------------- + */ +typedef FormData_pg_largeobject_metadata *Form_pg_largeobject_metadata; + +/* ---------------- + * compiler constants for pg_largeobject_metadata + * ---------------- + */ +#define Natts_pg_largeobject_metadata 2 +#define Anum_pg_largeobject_metadata_lomowner 1 +#define Anum_pg_largeobject_metadata_lomacl 2 + +#endif /* PG_LARGEOBJECT_METADATA_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_namespace.h postgresql-hll-2.14/include/include/catalog/pg_namespace.h --- postgresql-hll-2.14_old/include/include/catalog/pg_namespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_namespace.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,107 @@ +/* ------------------------------------------------------------------------- + * + * pg_namespace.h + * definition of the system "namespace" relation (pg_namespace) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_namespace.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_NAMESPACE_H +#define PG_NAMESPACE_H + +#include "catalog/genbki.h" + +/* ---------------------------------------------------------------- + * pg_namespace definition. + * + * cpp turns this into typedef struct FormData_pg_namespace + * + * nspname name of the namespace + * nspowner owner (creator) of the namespace + * nspacl access privilege list + * ---------------------------------------------------------------- + */ +#define NamespaceRelationId 2615 +#define NamespaceRelation_Rowtype_Id 11629 + +CATALOG(pg_namespace,2615) BKI_SCHEMA_MACRO +{ + NameData nspname; + Oid nspowner; + int8 nsptimeline; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem nspacl[1]; +#endif + char in_redistribution; +} FormData_pg_namespace; + +/* ---------------- + * Form_pg_namespace corresponds to a pointer to a tuple with + * the format of pg_namespace relation. + * ---------------- + */ +typedef FormData_pg_namespace *Form_pg_namespace; + +/* ---------------- + * compiler constants for pg_namespace + * ---------------- + */ + +#define Natts_pg_namespace 5 +#define Anum_pg_namespace_nspname 1 +#define Anum_pg_namespace_nspowner 2 +#define Anum_pg_namespace_nsptimeline 3 +#define Anum_pg_namespace_nspacl 4 +#define Anum_pg_namespace_in_redistribution 5 + + +/* ---------------- + * initial contents of pg_namespace + * --------------- + */ + +DATA(insert OID = 11 ( "pg_catalog" PGUID 0 _null_ n)); +DESCR("system catalog schema"); +#define PG_CATALOG_NAMESPACE 11 +DATA(insert OID = 99 ( "pg_toast" PGUID 0 _null_ n)); +DESCR("reserved schema for TOAST tables"); +#define PG_TOAST_NAMESPACE 99 + +DATA(insert OID = 100 ( "cstore" PGUID 0 _null_ n)); +DESCR("reserved schema for DELTA tables"); +#define CSTORE_NAMESPACE 100 + +DATA(insert OID = 3988 ( "pkg_service" PGUID 0 _null_ n)); +DESCR("pkg_service schema"); +#define PG_PKG_SERVICE_NAMESPACE 3988 + +DATA(insert OID = 2200 ( "public" PGUID 0 _null_ n)); +DESCR("standard public schema"); +#define PG_PUBLIC_NAMESPACE 2200 + +DATA(insert OID = 4988 ( "dbe_perf" PGUID 0 _null_ n)); +DESCR("dbe_perf schema"); +#define PG_DBEPERF_NAMESPACE 4988 + +DATA(insert OID = 4989 ( "snapshot" PGUID 0 _null_ n)); +DESCR("snapshot schema"); +#define PG_SNAPSHOT_NAMESPACE 4989 + +/* + * prototypes for functions in pg_namespace.c + */ +extern Oid NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp); + +#endif /* PG_NAMESPACE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_object.h postgresql-hll-2.14/include/include/catalog/pg_object.h --- postgresql-hll-2.14_old/include/include/catalog/pg_object.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_object.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_object.h + * definition of the system "object" relation (pg_object). + * + * + * IDENTIFICATION + * src/include/catalog/pg_object.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_OBJECT_H +#define PG_OBJECT_H + +#include "catalog/genbki.h" +#include "fmgr.h" +#include "nodes/parsenodes.h" +#include "catalog/objectaddress.h" +#include "postgres.h" + + +#ifndef timestamptz +#ifdef HAVE_INT64_TIMESTAMP +#define timestamptz int64 +#else +#define timestamptz double +#endif +#define new_timestamptz +#endif + +/*------------------------------------------------------------------------- + * pg_object definition. cpp turns this into + * typedef struct FormData_pg_object + *------------------------------------------------------------------------- + */ +#define PgObjectRelationId 9025 +#define PgObjectRelationId_Rowtype_Id 11661 + +CATALOG(pg_object,9025) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid object_oid; /* Object oid. */ + char object_type; /* Object type. */ + Oid creator; /* Who create the object. */ + timestamptz ctime; /* When create the object. */ + timestamptz mtime; /* When modify the object. */ +} FormData_pg_object; + +#ifdef new_timestamptz +#undef new_timestamptz +#undef timestamptz +#endif + +/*------------------------------------------------------------------------- + * Form_pg_object corresponds to a pointer to a tuple with + * the format of pg_object relation. + *------------------------------------------------------------------------- + */ +typedef FormData_pg_object* Form_pg_object; + +/*------------------------------------------------------------------------- + * compiler constants for pg_object + *------------------------------------------------------------------------- + */ +#define Natts_pg_object 5 +#define Anum_pg_object_oid 1 +#define Anum_pg_object_type 2 +#define Anum_pg_object_creator 3 +#define Anum_pg_object_ctime 4 +#define Anum_pg_object_mtime 5 + +#define PgObjectType char + +/* Define the type of object which maybe different with object is pg_class. */ +#define OBJECT_TYPE_INVALID '\0' +#define OBJECT_TYPE_RELATION 'r' +#define OBJECT_TYPE_FOREIGN_TABLE 'f' +#define OBJECT_TYPE_INDEX 'i' +#define OBJECT_TYPE_SEQUENCE 's' +#define OBJECT_TYPE_VIEW 'v' +#define OBJECT_TYPE_CONTQUERY 'o' +#define OBJECT_TYPE_PROC 'P' +#define OBJECT_TYPE_STREAM 'e' + +extern void CreatePgObject(Oid objectOid, PgObjectType objectType, Oid creator, bool hasCtime, bool hasMtime); +extern void DeletePgObject(Oid objectOid, PgObjectType objectType); +extern void UpdatePgObjectMtime(Oid objectOid, PgObjectType objectType); +extern PgObjectType GetPgObjectTypePgClass(char relkind); +extern void recordCommentObjectTime(ObjectAddress addr, Relation rel, ObjectType objType); +extern void recordRelationMTime(Oid relOid, char relkind); + +#endif /* PG_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_obsscaninfo.h postgresql-hll-2.14/include/include/catalog/pg_obsscaninfo.h --- postgresql-hll-2.14_old/include/include/catalog/pg_obsscaninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_obsscaninfo.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,76 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_obsscaninfo.h + * definition of the system "obsscaninfo" relation (pg_obsscaninfo) + * along with the relation's initial contents. + + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/catalog/pg_obsscaninfo.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_OBSSCANINFO_H +#define PG_OBSSCANINFO_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_obsscaninfo definition.cpp turns this into + * typedef struct FormData_pg_obsscaninfo + * ---------------- + */ +#define timestamptz Datum +#define ObsScanInfoRelationId 5679 +#define ObsScanInfoRelation_Rowtype_Id 11644 + +CATALOG(pg_obsscaninfo,5679) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + int8 query_id; +#ifdef CATALOG_VARLEN + text user_id; + text table_name; + text file_type; +#endif + timestamptz time_stamp; + float8 actual_time; + int8 file_scanned; + float8 data_size; +#ifdef CATALOG_VARLEN + text billing_info; +#endif +} FormData_pg_obsscaninfo; + + +/* ---------------- + * Form_pg_obsscaninfo corresponds to a pointer to a tuple with + * the format of pg_obsscaninfo relation. + * ---------------- + */ +typedef FormData_pg_obsscaninfo *Form_pg_obsscaninfo; + +/* ---------------- + * compiler constants for pg_obsscaninfo + * ---------------- + */ +#define Natts_pg_obsscaninfo 9 +#define Anum_pg_obsscaninfo_query_id 1 +#define Anum_pg_obsscaninfo_user_id 2 +#define Anum_pg_obsscaninfo_table_name 3 +#define Anum_pg_obsscaninfo_file_type 4 +#define Anum_pg_obsscaninfo_time_stamp 5 +#define Anum_pg_obsscaninfo_actual_time 6 +#define Anum_pg_obsscaninfo_file_scanned 7 +#define Anum_pg_obsscaninfo_data_size 8 +#define Anum_pg_obsscaninfo_billing_info 9 + +#endif /* PG_OBSSCANINFO_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_opclass.h postgresql-hll-2.14/include/include/catalog/pg_opclass.h --- postgresql-hll-2.14_old/include/include/catalog/pg_opclass.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_opclass.h 2020-12-12 17:06:43.157346877 +0800 @@ -0,0 +1,318 @@ +/* ------------------------------------------------------------------------- + * + * pg_opclass.h + * definition of the system "opclass" relation (pg_opclass) + * along with the relation's initial contents. + * + * The primary key for this table is --- + * that is, there is a row for each valid combination of opclass name and + * index access method type. This row specifies the expected input data type + * for the opclass (the type of the heap column, or the expression output type + * in the case of an index expression). Note that types binary-coercible to + * the specified type will be accepted too. + * + * For a given pair, there can be at most one row that + * has opcdefault = true; this row is the default opclass for such data in + * such an index. (This is not currently enforced by an index, because we + * don't support partial indexes on system catalogs.) + * + * Normally opckeytype = InvalidOid (zero), indicating that the data stored + * in the index is the same as the data in the indexed column. If opckeytype + * is nonzero then it indicates that a conversion step is needed to produce + * the stored index data, which will be of type opckeytype (which might be + * the same or different from the input datatype). Performing such a + * conversion is the responsibility of the index access method --- not all + * AMs support this. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_opclass.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPCLASS_H +#define PG_OPCLASS_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_opclass definition. cpp turns this into + * typedef struct FormData_pg_opclass + * ---------------- + */ +#define OperatorClassRelationId 2616 +#define OperatorClassRelation_Rowtype_Id 10006 + +CATALOG(pg_opclass,2616) BKI_SCHEMA_MACRO +{ + Oid opcmethod; /* index access method opclass is for */ + NameData opcname; /* name of this opclass */ + Oid opcnamespace; /* namespace of this opclass */ + Oid opcowner; /* opclass owner */ + Oid opcfamily; /* containing operator family */ + Oid opcintype; /* type of data indexed by opclass */ + bool opcdefault; /* T if opclass is default for opcintype */ + Oid opckeytype; /* type of data in index, or InvalidOid */ +} FormData_pg_opclass; + +/* ---------------- + * Form_pg_opclass corresponds to a pointer to a tuple with + * the format of pg_opclass relation. + * ---------------- + */ +typedef FormData_pg_opclass *Form_pg_opclass; + +/* ---------------- + * compiler constants for pg_opclass + * ---------------- + */ +#define Natts_pg_opclass 8 +#define Anum_pg_opclass_opcmethod 1 +#define Anum_pg_opclass_opcname 2 +#define Anum_pg_opclass_opcnamespace 3 +#define Anum_pg_opclass_opcowner 4 +#define Anum_pg_opclass_opcfamily 5 +#define Anum_pg_opclass_opcintype 6 +#define Anum_pg_opclass_opcdefault 7 +#define Anum_pg_opclass_opckeytype 8 + +/* ---------------- + * initial contents of pg_opclass + * + * Note: we hard-wire an OID only for a few entries that have to be explicitly + * referenced in the C code or in built-in catalog entries. The rest get OIDs + * assigned on-the-fly during initdb. + * ---------------- + */ +DATA(insert ( 403 abstime_ops PGNSP PGUID 421 702 t 0 )); +DATA(insert ( 403 array_ops PGNSP PGUID 397 2277 t 0 )); +DATA(insert ( 405 array_ops PGNSP PGUID 627 2277 t 0 )); +DATA(insert ( 403 bit_ops PGNSP PGUID 423 1560 t 0 )); +DATA(insert ( 403 bool_ops PGNSP PGUID 424 16 t 0 )); +DATA(insert ( 403 bpchar_ops PGNSP PGUID 426 1042 t 0 )); +DATA(insert ( 405 bpchar_ops PGNSP PGUID 427 1042 t 0 )); +DATA(insert ( 403 bytea_ops PGNSP PGUID 428 17 t 0 )); +DATA(insert ( 403 byteawithoutorderwithequalcol_ops PGNSP PGUID 436 4402 t 0 )); +DATA(insert ( 403 char_ops PGNSP PGUID 429 18 t 0 )); +DATA(insert ( 405 char_ops PGNSP PGUID 431 18 t 0 )); +DATA(insert ( 403 cidr_ops PGNSP PGUID 1974 869 f 0 )); +DATA(insert ( 405 cidr_ops PGNSP PGUID 1975 869 f 0 )); +DATA(insert OID = 3122 ( 403 date_ops PGNSP PGUID 434 1082 t 0 )); +#define DATE_BTREE_OPS_OID 3122 +DATA(insert ( 405 date_ops PGNSP PGUID 435 1082 t 0 )); +DATA(insert ( 403 float4_ops PGNSP PGUID 1970 700 t 0 )); +DATA(insert ( 405 float4_ops PGNSP PGUID 1971 700 t 0 )); +DATA(insert OID = 3123 ( 403 float8_ops PGNSP PGUID 1970 701 t 0 )); +#define FLOAT8_BTREE_OPS_OID 3123 +DATA(insert ( 405 float8_ops PGNSP PGUID 1971 701 t 0 )); +DATA(insert ( 403 inet_ops PGNSP PGUID 1974 869 t 0 )); +DATA(insert ( 405 inet_ops PGNSP PGUID 1975 869 t 0 )); +DATA(insert OID = 1979 ( 403 int2_ops PGNSP PGUID 1976 21 t 0 )); +#define INT2_BTREE_OPS_OID 1979 +DATA(insert ( 405 int2_ops PGNSP PGUID 1977 21 t 0 )); +DATA(insert OID = 1978 ( 403 int4_ops PGNSP PGUID 1976 23 t 0 )); +#define INT4_BTREE_OPS_OID 1978 +DATA(insert ( 405 int4_ops PGNSP PGUID 1977 23 t 0 )); +DATA(insert OID = 3124 ( 403 int8_ops PGNSP PGUID 1976 20 t 0 )); +#define INT8_BTREE_OPS_OID 3124 +DATA(insert ( 405 int8_ops PGNSP PGUID 1977 20 t 0 )); +DATA(insert ( 403 interval_ops PGNSP PGUID 1982 1186 t 0 )); +DATA(insert ( 405 interval_ops PGNSP PGUID 1983 1186 t 0 )); +DATA(insert ( 403 macaddr_ops PGNSP PGUID 1984 829 t 0 )); +DATA(insert ( 405 macaddr_ops PGNSP PGUID 1985 829 t 0 )); +/* + * Here's an ugly little hack to save space in the system catalog indexes. + * btree doesn't ordinarily allow a storage type different from input type; + * but cstring and name are the same thing except for trailing padding, + * and we can safely omit that within an index entry. So we declare the + * btree opclass for name as using cstring storage type. + */ +DATA(insert ( 403 name_ops PGNSP PGUID 1986 19 t 2275 )); +DATA(insert ( 405 name_ops PGNSP PGUID 1987 19 t 0 )); +DATA(insert OID = 3125 ( 403 numeric_ops PGNSP PGUID 1988 1700 t 0 )); +#define NUMERIC_BTREE_OPS_OID 3125 +DATA(insert ( 405 numeric_ops PGNSP PGUID 1998 1700 t 0 )); +DATA(insert OID = 1981 ( 403 oid_ops PGNSP PGUID 1989 26 t 0 )); +#define OID_BTREE_OPS_OID 1981 +DATA(insert ( 405 oid_ops PGNSP PGUID 1990 26 t 0 )); +DATA(insert ( 403 oidvector_ops PGNSP PGUID 1991 30 t 0 )); +DATA(insert ( 405 oidvector_ops PGNSP PGUID 1992 30 t 0 )); +DATA(insert ( 403 record_ops PGNSP PGUID 2994 2249 t 0 )); +DATA(insert OID = 3126 ( 403 text_ops PGNSP PGUID 1994 25 t 0 )); +#define TEXT_BTREE_OPS_OID 3126 +DATA(insert ( 405 text_ops PGNSP PGUID 1995 25 t 0 )); +DATA(insert ( 403 time_ops PGNSP PGUID 1996 1083 t 0 )); +DATA(insert ( 405 time_ops PGNSP PGUID 1997 1083 t 0 )); +DATA(insert OID = 3127 ( 403 timestamptz_ops PGNSP PGUID 434 1184 t 0 )); +#define TIMESTAMPTZ_BTREE_OPS_OID 3127 +DATA(insert ( 405 timestamptz_ops PGNSP PGUID 1999 1184 t 0 )); +DATA(insert ( 403 timetz_ops PGNSP PGUID 2000 1266 t 0 )); +DATA(insert ( 405 timetz_ops PGNSP PGUID 2001 1266 t 0 )); +DATA(insert ( 403 varbit_ops PGNSP PGUID 2002 1562 t 0 )); +DATA(insert ( 403 varchar_ops PGNSP PGUID 1994 25 f 0 )); +DATA(insert ( 405 varchar_ops PGNSP PGUID 1995 25 f 0 )); +DATA(insert OID = 3128 ( 403 timestamp_ops PGNSP PGUID 434 1114 t 0 )); +#define TIMESTAMP_BTREE_OPS_OID 3128 +DATA(insert ( 405 timestamp_ops PGNSP PGUID 2040 1114 t 0 )); +DATA(insert ( 403 text_pattern_ops PGNSP PGUID 2095 25 f 0 )); +DATA(insert ( 403 varchar_pattern_ops PGNSP PGUID 2095 25 f 0 )); +DATA(insert ( 403 bpchar_pattern_ops PGNSP PGUID 2097 1042 f 0 )); +DATA(insert ( 403 money_ops PGNSP PGUID 2099 790 t 0 )); +DATA(insert ( 405 bool_ops PGNSP PGUID 2222 16 t 0 )); +DATA(insert ( 405 bytea_ops PGNSP PGUID 2223 17 t 0 )); +DATA(insert ( 405 byteawithoutorderwithequalcol_ops PGNSP PGUID 4470 4402 t 0 )); +DATA(insert ( 405 int2vector_ops PGNSP PGUID 2224 22 t 0 )); +DATA(insert ( 403 tid_ops PGNSP PGUID 2789 27 t 0 )); +DATA(insert ( 405 xid_ops PGNSP PGUID 2225 28 t 0 )); +DATA(insert ( 405 xid32_ops PGNSP PGUID 2232 31 t 0 )); +DATA(insert ( 405 cid_ops PGNSP PGUID 2226 29 t 0 )); +DATA(insert ( 405 abstime_ops PGNSP PGUID 2227 702 t 0 )); +DATA(insert ( 405 reltime_ops PGNSP PGUID 2228 703 t 0 )); +DATA(insert ( 405 text_pattern_ops PGNSP PGUID 2229 25 f 0 )); +DATA(insert ( 405 varchar_pattern_ops PGNSP PGUID 2229 25 f 0 )); +DATA(insert ( 405 bpchar_pattern_ops PGNSP PGUID 2231 1042 f 0 )); +DATA(insert ( 403 reltime_ops PGNSP PGUID 2233 703 t 0 )); +DATA(insert ( 403 tinterval_ops PGNSP PGUID 2234 704 t 0 )); +DATA(insert ( 405 aclitem_ops PGNSP PGUID 2235 1033 t 0 )); +DATA(insert ( 783 box_ops PGNSP PGUID 2593 603 t 0 )); +DATA(insert ( 783 point_ops PGNSP PGUID 1029 600 t 603 )); +DATA(insert ( 783 poly_ops PGNSP PGUID 2594 604 t 603 )); +DATA(insert ( 783 circle_ops PGNSP PGUID 2595 718 t 603 )); +DATA(insert ( 2742 _int4_ops PGNSP PGUID 2745 1007 t 23 )); +DATA(insert ( 2742 _text_ops PGNSP PGUID 2745 1009 t 25 )); +DATA(insert ( 2742 _abstime_ops PGNSP PGUID 2745 1023 t 702 )); +DATA(insert ( 2742 _bit_ops PGNSP PGUID 2745 1561 t 1560 )); +DATA(insert ( 2742 _bool_ops PGNSP PGUID 2745 1000 t 16 )); +DATA(insert ( 2742 _bpchar_ops PGNSP PGUID 2745 1014 t 1042 )); +DATA(insert ( 2742 _bytea_ops PGNSP PGUID 2745 1001 t 17 )); +DATA(insert ( 2742 _char_ops PGNSP PGUID 2745 1002 t 18 )); +DATA(insert ( 2742 _cidr_ops PGNSP PGUID 2745 651 t 650 )); +DATA(insert ( 2742 _date_ops PGNSP PGUID 2745 1182 t 1082 )); +DATA(insert ( 2742 _float4_ops PGNSP PGUID 2745 1021 t 700 )); +DATA(insert ( 2742 _float8_ops PGNSP PGUID 2745 1022 t 701 )); +DATA(insert ( 2742 _inet_ops PGNSP PGUID 2745 1041 t 869 )); +DATA(insert ( 2742 _int2_ops PGNSP PGUID 2745 1005 t 21 )); +DATA(insert ( 2742 _int8_ops PGNSP PGUID 2745 1016 t 20 )); +DATA(insert ( 2742 _interval_ops PGNSP PGUID 2745 1187 t 1186 )); +DATA(insert ( 2742 _macaddr_ops PGNSP PGUID 2745 1040 t 829 )); +DATA(insert ( 2742 _name_ops PGNSP PGUID 2745 1003 t 19 )); +DATA(insert ( 2742 _numeric_ops PGNSP PGUID 2745 1231 t 1700 )); +DATA(insert ( 2742 _oid_ops PGNSP PGUID 2745 1028 t 26 )); +DATA(insert ( 2742 _oidvector_ops PGNSP PGUID 2745 1013 t 30 )); +DATA(insert ( 2742 _time_ops PGNSP PGUID 2745 1183 t 1083 )); +DATA(insert ( 2742 _timestamptz_ops PGNSP PGUID 2745 1185 t 1184 )); +DATA(insert ( 2742 _timetz_ops PGNSP PGUID 2745 1270 t 1266 )); +DATA(insert ( 2742 _varbit_ops PGNSP PGUID 2745 1563 t 1562 )); +DATA(insert ( 2742 _varchar_ops PGNSP PGUID 2745 1015 t 1043 )); +DATA(insert ( 2742 _timestamp_ops PGNSP PGUID 2745 1115 t 1114 )); +DATA(insert ( 2742 _money_ops PGNSP PGUID 2745 791 t 790 )); +DATA(insert ( 2742 _reltime_ops PGNSP PGUID 2745 1024 t 703 )); +DATA(insert ( 2742 _tinterval_ops PGNSP PGUID 2745 1025 t 704 )); +/* +DATA(insert ( 4444 _int4_ops PGNSP PGUID 4445 1007 t 23 )); +DATA(insert ( 4444 _text_ops PGNSP PGUID 4445 1009 t 25 )); +DATA(insert ( 4444 _abstime_ops PGNSP PGUID 4445 1023 t 702 )); +DATA(insert ( 4444 _bit_ops PGNSP PGUID 4445 1561 t 1560 )); +DATA(insert ( 4444 _bool_ops PGNSP PGUID 4445 1000 t 16 )); +DATA(insert ( 4444 _bpchar_ops PGNSP PGUID 4445 1014 t 1042 )); +DATA(insert ( 4444 _bytea_ops PGNSP PGUID 4445 1001 t 17 )); +DATA(insert ( 4444 _char_ops PGNSP PGUID 4445 1002 t 18 )); +DATA(insert ( 4444 _cidr_ops PGNSP PGUID 4445 651 t 650 )); +DATA(insert ( 4444 _date_ops PGNSP PGUID 4445 1182 t 1082 )); +DATA(insert ( 4444 _float4_ops PGNSP PGUID 4445 1021 t 700 )); +DATA(insert ( 4444 _float8_ops PGNSP PGUID 4445 1022 t 701 )); +DATA(insert ( 4444 _inet_ops PGNSP PGUID 4445 1041 t 869 )); +DATA(insert ( 4444 _int2_ops PGNSP PGUID 4445 1005 t 21 )); +DATA(insert ( 4444 _int8_ops PGNSP PGUID 4445 1016 t 20 )); +DATA(insert ( 4444 _interval_ops PGNSP PGUID 4445 1187 t 1186 )); +DATA(insert ( 4444 _macaddr_ops PGNSP PGUID 4445 1040 t 829 )); +DATA(insert ( 4444 _name_ops PGNSP PGUID 4445 1003 t 19 )); +DATA(insert ( 4444 _numeric_ops PGNSP PGUID 4445 1231 t 1700 )); +DATA(insert ( 4444 _oid_ops PGNSP PGUID 4445 1028 t 26 )); +DATA(insert ( 4444 _oidvector_ops PGNSP PGUID 4445 1013 t 30 )); +DATA(insert ( 4444 _time_ops PGNSP PGUID 4445 1183 t 1083 )); +DATA(insert ( 4444 _timestamptz_ops PGNSP PGUID 4445 1185 t 1184 )); +DATA(insert ( 4444 _timetz_ops PGNSP PGUID 4445 1270 t 1266 )); +DATA(insert ( 4444 _varbit_ops PGNSP PGUID 4445 1563 t 1562 )); +DATA(insert ( 4444 _varchar_ops PGNSP PGUID 4445 1015 t 1043 )); +DATA(insert ( 4444 _timestamp_ops PGNSP PGUID 4445 1115 t 1114 )); +DATA(insert ( 4444 _money_ops PGNSP PGUID 4445 791 t 790 )); +DATA(insert ( 4444 _reltime_ops PGNSP PGUID 4445 1024 t 703 )); +DATA(insert ( 4444 _tinterval_ops PGNSP PGUID 4445 1025 t 704 )); +*/ +DATA(insert ( 403 uuid_ops PGNSP PGUID 2968 2950 t 0 )); +DATA(insert ( 405 uuid_ops PGNSP PGUID 2969 2950 t 0 )); +DATA(insert ( 403 enum_ops PGNSP PGUID 3522 3500 t 0 )); +DATA(insert ( 405 enum_ops PGNSP PGUID 3523 3500 t 0 )); +DATA(insert ( 403 tsvector_ops PGNSP PGUID 3626 3614 t 0 )); +DATA(insert ( 783 tsvector_ops PGNSP PGUID 3655 3614 t 3642 )); +DATA(insert ( 2742 tsvector_ops PGNSP PGUID 3659 3614 t 25 )); +DATA(insert ( 4444 tsvector_ops PGNSP PGUID 4446 3614 t 25 )); +DATA(insert ( 403 tsquery_ops PGNSP PGUID 3683 3615 t 0 )); +DATA(insert ( 783 tsquery_ops PGNSP PGUID 3702 3615 t 20 )); +DATA(insert ( 403 range_ops PGNSP PGUID 3901 3831 t 0 )); +DATA(insert ( 405 range_ops PGNSP PGUID 3903 3831 t 0 )); +DATA(insert ( 783 range_ops PGNSP PGUID 3919 3831 t 0 )); +DATA(insert ( 4000 quad_point_ops PGNSP PGUID 4015 600 t 0 )); +DATA(insert ( 4000 kd_point_ops PGNSP PGUID 4016 600 f 0 )); +DATA(insert ( 4000 text_ops PGNSP PGUID 4017 25 t 0 )); + +DATA(insert ( 403 raw_ops PGNSP PGUID 3806 86 t 0 )); +DATA(insert ( 405 raw_ops PGNSP PGUID 3807 86 t 0 )); +DATA(insert ( 403 int1_ops PGNSP PGUID 5535 5545 t 0 )); +DATA(insert ( 405 int1_ops PGNSP PGUID 5536 5545 t 0 )); +DATA(insert ( 403 smalldatetime_ops PGNSP PGUID 5570 9003 t 0 )); +DATA(insert ( 405 smalldatetime_ops PGNSP PGUID 5571 9003 t 0 )); + +/* psort index, fake data just make index work */ +DATA(insert ( 4039 int4_ops PGNSP PGUID 4050 23 t 0)); +DATA(insert ( 4039 int2_ops PGNSP PGUID 4050 21 t 0)); +DATA(insert ( 4039 int8_ops PGNSP PGUID 4050 20 t 0)); +DATA(insert ( 4039 oid_ops PGNSP PGUID 4051 26 t 0)); +DATA(insert ( 4039 date_ops PGNSP PGUID 4052 1082 t 0)); +DATA(insert ( 4039 timestamp_ops PGNSP PGUID 4052 1114 t 0)); +DATA(insert ( 4039 timestamptz_ops PGNSP PGUID 4052 1184 t 0)); +DATA(insert ( 4039 float4_ops PGNSP PGUID 4053 700 t 0)); +DATA(insert ( 4039 float8_ops PGNSP PGUID 4053 701 t 0)); +DATA(insert ( 4039 numeric_ops PGNSP PGUID 4054 1700 t 0)); +DATA(insert ( 4039 text_ops PGNSP PGUID 4055 25 t 0)); +DATA(insert ( 4039 bpchar_ops PGNSP PGUID 4056 1042 t 0)); +DATA(insert ( 4039 time_ops PGNSP PGUID 4057 1083 t 0)); +DATA(insert ( 4039 timetz_ops PGNSP PGUID 4058 1266 t 0)); +DATA(insert ( 4039 money_ops PGNSP PGUID 4059 790 t 0)); +DATA(insert ( 4039 interval_ops PGNSP PGUID 4060 1186 t 0)); +DATA(insert ( 4039 tinterval_ops PGNSP PGUID 4061 704 t 0)); +DATA(insert ( 4039 int1_ops PGNSP PGUID 4062 5545 t 0)); +DATA(insert ( 4039 bool_ops PGNSP PGUID 4063 16 t 0)); +DATA(insert ( 4039 smalldatetime_ops PGNSP PGUID 4064 9003 t 0)); + +/* cbtree index, fake data just make index work */ +DATA(insert ( 4239 int4_ops PGNSP PGUID 4250 23 t 0)); +DATA(insert ( 4239 int2_ops PGNSP PGUID 4250 21 t 0)); +DATA(insert ( 4239 int8_ops PGNSP PGUID 4250 20 t 0)); +DATA(insert ( 4239 oid_ops PGNSP PGUID 4251 26 t 0)); +DATA(insert ( 4239 date_ops PGNSP PGUID 4252 1082 t 0)); +DATA(insert ( 4239 timestamp_ops PGNSP PGUID 4252 1114 t 0)); +DATA(insert ( 4239 timestamptz_ops PGNSP PGUID 4252 1184 t 0)); +DATA(insert ( 4239 float4_ops PGNSP PGUID 4253 700 t 0)); +DATA(insert ( 4239 float8_ops PGNSP PGUID 4253 701 t 0)); +DATA(insert ( 4239 numeric_ops PGNSP PGUID 4254 1700 t 0)); +DATA(insert ( 4239 text_ops PGNSP PGUID 4255 25 t 0)); +DATA(insert ( 4239 bpchar_ops PGNSP PGUID 4256 1042 t 0)); +DATA(insert ( 4239 time_ops PGNSP PGUID 4257 1083 t 0)); +DATA(insert ( 4239 timetz_ops PGNSP PGUID 4258 1266 t 0)); +DATA(insert ( 4239 money_ops PGNSP PGUID 4259 790 t 0)); +DATA(insert ( 4239 interval_ops PGNSP PGUID 4260 1186 t 0)); +DATA(insert ( 4239 tinterval_ops PGNSP PGUID 4261 704 t 0)); +DATA(insert ( 4239 int1_ops PGNSP PGUID 4262 5545 t 0)); +DATA(insert ( 4239 bool_ops PGNSP PGUID 4263 16 t 0)); +DATA(insert ( 4239 smalldatetime_ops PGNSP PGUID 4264 9003 t 0)); + +#endif /* PG_OPCLASS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_operator.h postgresql-hll-2.14/include/include/catalog/pg_operator.h --- postgresql-hll-2.14_old/include/include/catalog/pg_operator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_operator.h 2020-12-12 17:06:43.158346890 +0800 @@ -0,0 +1,1962 @@ +/* ------------------------------------------------------------------------- + * + * pg_operator.h + * definition of the system "operator" relation (pg_operator) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_operator.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPERATOR_H +#define PG_OPERATOR_H + +#include "catalog/genbki.h" +#include "nodes/pg_list.h" + +/* ---------------- + * pg_operator definition. cpp turns this into + * typedef struct FormData_pg_operator + * ---------------- + */ +#define OperatorRelationId 2617 +#define OperatorRelation_Rowtype_Id 10004 + +CATALOG(pg_operator,2617) BKI_SCHEMA_MACRO +{ + NameData oprname; /* name of operator */ + Oid oprnamespace; /* OID of namespace containing this oper */ + Oid oprowner; /* operator owner */ + char oprkind; /* 'l', 'r', or 'b' */ + bool oprcanmerge; /* can be used in merge join? */ + bool oprcanhash; /* can be used in hash join? */ + Oid oprleft; /* left arg type, or 0 if 'l' oprkind */ + Oid oprright; /* right arg type, or 0 if 'r' oprkind */ + Oid oprresult; /* result datatype */ + Oid oprcom; /* OID of commutator oper, or 0 if none */ + Oid oprnegate; /* OID of negator oper, or 0 if none */ + regproc oprcode; /* OID of underlying function */ + regproc oprrest; /* OID of restriction estimator, or 0 */ + regproc oprjoin; /* OID of join estimator, or 0 */ +} FormData_pg_operator; + +/* ---------------- + * Form_pg_operator corresponds to a pointer to a tuple with + * the format of pg_operator relation. + * ---------------- + */ +typedef FormData_pg_operator *Form_pg_operator; + +/* ---------------- + * compiler constants for pg_operator + * ---------------- + */ +#define Natts_pg_operator 14 +#define Anum_pg_operator_oprname 1 +#define Anum_pg_operator_oprnamespace 2 +#define Anum_pg_operator_oprowner 3 +#define Anum_pg_operator_oprkind 4 +#define Anum_pg_operator_oprcanmerge 5 +#define Anum_pg_operator_oprcanhash 6 +#define Anum_pg_operator_oprleft 7 +#define Anum_pg_operator_oprright 8 +#define Anum_pg_operator_oprresult 9 +#define Anum_pg_operator_oprcom 10 +#define Anum_pg_operator_oprnegate 11 +#define Anum_pg_operator_oprcode 12 +#define Anum_pg_operator_oprrest 13 +#define Anum_pg_operator_oprjoin 14 + +/* ---------------- + * initial contents of pg_operator + * ---------------- + */ + +/* + * Note: every entry in pg_operator.h is expected to have a DESCR() comment. + * If the operator is a deprecated equivalent of some other entry, be sure + * to comment it as such so that initdb doesn't think it's a preferred name + * for the underlying function. + */ + +DATA(insert OID = 15 ("=" PGNSP PGUID b t t 23 20 16 416 36 int48eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT48EQOID 15 +DATA(insert OID = 36 ("<>" PGNSP PGUID b f f 23 20 16 417 15 int48ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT48NEOID 36 +DATA(insert OID = 37 ("<" PGNSP PGUID b f f 23 20 16 419 82 int48lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT48LTOID 37 +DATA(insert OID = 76 (">" PGNSP PGUID b f f 23 20 16 418 80 int48gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT48GTOID 76 +DATA(insert OID = 80 ("<=" PGNSP PGUID b f f 23 20 16 430 76 int48le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT48LEOID 80 +DATA(insert OID = 82 (">=" PGNSP PGUID b f f 23 20 16 420 37 int48ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT48GEOID 82 + +DATA(insert OID = 58 ("<" PGNSP PGUID b f f 16 16 16 59 1695 boollt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 59 (">" PGNSP PGUID b f f 16 16 16 58 1694 boolgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 85 ("<>" PGNSP PGUID b f f 16 16 16 85 91 boolne neqsel neqjoinsel)); +DESCR("not equal"); +#define BooleanNotEqualOperator 85 +DATA(insert OID = 91 ("=" PGNSP PGUID b t t 16 16 16 91 85 booleq eqsel eqjoinsel)); +DESCR("equal"); +#define BooleanEqualOperator 91 +DATA(insert OID = 1694 ("<=" PGNSP PGUID b f f 16 16 16 1695 59 boolle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1695 (">=" PGNSP PGUID b f f 16 16 16 1694 58 boolge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define CHAREQOID 92 +DATA(insert OID = 92 ("=" PGNSP PGUID b t t 18 18 16 92 630 chareq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 93 ("=" PGNSP PGUID b t t 19 19 16 93 643 nameeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 94 ("=" PGNSP PGUID b t t 21 21 16 94 519 int2eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT2EQOID 94 +DATA(insert OID = 95 ("<" PGNSP PGUID b f f 21 21 16 520 524 int2lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT2LTOID 95 +DATA(insert OID = 96 ("=" PGNSP PGUID b t t 23 23 16 96 518 int4eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT4EQOID 96 +DATA(insert OID = 97 ("<" PGNSP PGUID b f f 23 23 16 521 525 int4lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT4LTOID 97 +DATA(insert OID = 98 ("=" PGNSP PGUID b t t 25 25 16 98 531 texteq eqsel eqjoinsel)); +DESCR("equal"); +#define TEXTEQOID 98 + +DATA(insert OID = 349 ("||" PGNSP PGUID b f f 2277 2283 2277 0 0 array_append - - )); +DESCR("append element onto end of array"); +DATA(insert OID = 374 ("||" PGNSP PGUID b f f 2283 2277 2277 0 0 array_prepend - - )); +DESCR("prepend element onto front of array"); +DATA(insert OID = 375 ("||" PGNSP PGUID b f f 2277 2277 2277 0 0 array_cat - - )); +DESCR("concatenate"); + +DATA(insert OID = 352 ("=" PGNSP PGUID b f t 28 28 16 352 0 xideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 353 ("=" PGNSP PGUID b f f 28 20 16 0 0 xideqint8 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 354 ("<" PGNSP PGUID b f f 28 28 16 0 0 xidlt neqsel neqjoinsel)); +DESCR("less than"); +DATA(insert OID = 355 ("=" PGNSP PGUID b f t 31 31 16 355 0 xideq4 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 356 ("=" PGNSP PGUID b f f 31 23 16 0 0 xideqint4 eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 357 ("<" PGNSP PGUID b f f 31 31 16 0 0 xidlt4 neqsel neqjoinsel)); +DESCR("less than"); +DATA(insert OID = 388 ("!" PGNSP PGUID r f f 20 0 1700 0 0 numeric_fac - -)); +DESCR("factorial"); +DATA(insert OID = 389 ("!!" PGNSP PGUID l f f 0 20 1700 0 0 numeric_fac - -)); +DESCR("deprecated, use ! instead"); +DATA(insert OID = 385 ("=" PGNSP PGUID b f t 29 29 16 385 0 cideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 386 ("=" PGNSP PGUID b f t 22 22 16 386 0 int2vectoreq eqsel eqjoinsel)); +DESCR("equal"); + +DATA(insert OID = 387 ("=" PGNSP PGUID b t f 27 27 16 387 402 tideq eqsel eqjoinsel)); +DESCR("equal"); +#define TIDEqualOperator 387 +DATA(insert OID = 402 ("<>" PGNSP PGUID b f f 27 27 16 402 387 tidne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2799 ("<" PGNSP PGUID b f f 27 27 16 2800 2802 tidlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIDLessOperator 2799 +DATA(insert OID = 2800 (">" PGNSP PGUID b f f 27 27 16 2799 2801 tidgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2801 ("<=" PGNSP PGUID b f f 27 27 16 2802 2800 tidle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2802 (">=" PGNSP PGUID b f f 27 27 16 2801 2799 tidge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 410 ("=" PGNSP PGUID b t t 20 20 16 410 411 int8eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT8EQOID 410 +DATA(insert OID = 411 ("<>" PGNSP PGUID b f f 20 20 16 411 410 int8ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT8NEOID 411 +DATA(insert OID = 412 ("<" PGNSP PGUID b f f 20 20 16 413 415 int8lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT8LTOID 412 +DATA(insert OID = 413 (">" PGNSP PGUID b f f 20 20 16 412 414 int8gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT8GTOID 413 +DATA(insert OID = 414 ("<=" PGNSP PGUID b f f 20 20 16 415 413 int8le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT8LEOID 414 +DATA(insert OID = 415 (">=" PGNSP PGUID b f f 20 20 16 414 412 int8ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT8GEOID 415 + +DATA(insert OID = 416 ("=" PGNSP PGUID b t t 20 23 16 15 417 int84eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT84EQOID 416 +DATA(insert OID = 417 ("<>" PGNSP PGUID b f f 20 23 16 36 416 int84ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT84NEOID 417 +DATA(insert OID = 418 ("<" PGNSP PGUID b f f 20 23 16 76 430 int84lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT84LTOID 418 +DATA(insert OID = 419 (">" PGNSP PGUID b f f 20 23 16 37 420 int84gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT84GTOID 419 +DATA(insert OID = 420 ("<=" PGNSP PGUID b f f 20 23 16 82 419 int84le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT84LEOID 420 +DATA(insert OID = 430 (">=" PGNSP PGUID b f f 20 23 16 80 418 int84ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT84GEOID 430 +DATA(insert OID = 439 ("%" PGNSP PGUID b f f 20 20 20 0 0 int8mod - -)); +DESCR("modulus"); +DATA(insert OID = 473 ("@" PGNSP PGUID l f f 0 20 20 0 0 int8abs - -)); +DESCR("absolute value"); + +DATA(insert OID = 484 ("-" PGNSP PGUID l f f 0 20 20 0 0 int8um - -)); +DESCR("negate"); +DATA(insert OID = 485 ("<<" PGNSP PGUID b f f 604 604 16 0 0 poly_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 486 ("&<" PGNSP PGUID b f f 604 604 16 0 0 poly_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 487 ("&>" PGNSP PGUID b f f 604 604 16 0 0 poly_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 488 (">>" PGNSP PGUID b f f 604 604 16 0 0 poly_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 489 ("<@" PGNSP PGUID b f f 604 604 16 490 0 poly_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 490 ("@>" PGNSP PGUID b f f 604 604 16 489 0 poly_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 491 ("~=" PGNSP PGUID b f f 604 604 16 491 0 poly_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 492 ("&&" PGNSP PGUID b f f 604 604 16 492 0 poly_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 493 ("<<" PGNSP PGUID b f f 603 603 16 0 0 box_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 494 ("&<" PGNSP PGUID b f f 603 603 16 0 0 box_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 495 ("&>" PGNSP PGUID b f f 603 603 16 0 0 box_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 496 (">>" PGNSP PGUID b f f 603 603 16 0 0 box_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 497 ("<@" PGNSP PGUID b f f 603 603 16 498 0 box_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 498 ("@>" PGNSP PGUID b f f 603 603 16 497 0 box_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 499 ("~=" PGNSP PGUID b f f 603 603 16 499 0 box_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 500 ("&&" PGNSP PGUID b f f 603 603 16 500 0 box_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 501 (">=" PGNSP PGUID b f f 603 603 16 505 504 box_ge areasel areajoinsel)); +DESCR("greater than or equal by area"); +DATA(insert OID = 502 (">" PGNSP PGUID b f f 603 603 16 504 505 box_gt areasel areajoinsel)); +DESCR("greater than by area"); +DATA(insert OID = 503 ("=" PGNSP PGUID b f f 603 603 16 503 0 box_eq eqsel eqjoinsel)); +DESCR("equal by area"); +DATA(insert OID = 504 ("<" PGNSP PGUID b f f 603 603 16 502 501 box_lt areasel areajoinsel)); +DESCR("less than by area"); +DATA(insert OID = 505 ("<=" PGNSP PGUID b f f 603 603 16 501 502 box_le areasel areajoinsel)); +DESCR("less than or equal by area"); +DATA(insert OID = 506 (">^" PGNSP PGUID b f f 600 600 16 0 0 point_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 507 ("<<" PGNSP PGUID b f f 600 600 16 0 0 point_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 508 (">>" PGNSP PGUID b f f 600 600 16 0 0 point_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 509 ("<^" PGNSP PGUID b f f 600 600 16 0 0 point_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 510 ("~=" PGNSP PGUID b f f 600 600 16 510 713 point_eq eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 511 ("<@" PGNSP PGUID b f f 600 603 16 433 0 on_pb contsel contjoinsel)); +DESCR("point inside box"); +DATA(insert OID = 433 ("@>" PGNSP PGUID b f f 603 600 16 511 0 box_contain_pt contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 512 ("<@" PGNSP PGUID b f f 600 602 16 755 0 on_ppath - -)); +DESCR("point within closed path, or point on open path"); +DATA(insert OID = 513 ("@@" PGNSP PGUID l f f 0 603 600 0 0 box_center - -)); +DESCR("center of"); +DATA(insert OID = 514 ("*" PGNSP PGUID b f f 23 23 23 514 0 int4mul - -)); +DESCR("multiply"); +#define INT4MULOID 514 +DATA(insert OID = 517 ("<->" PGNSP PGUID b f f 600 600 701 517 0 point_distance - -)); +DESCR("distance between"); +DATA(insert OID = 518 ("<>" PGNSP PGUID b f f 23 23 16 518 96 int4ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT4NEOID 518 +DATA(insert OID = 519 ("<>" PGNSP PGUID b f f 21 21 16 519 94 int2ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT2NEOID 519 +DATA(insert OID = 520 (">" PGNSP PGUID b f f 21 21 16 95 522 int2gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT2GTOID 520 +DATA(insert OID = 521 (">" PGNSP PGUID b f f 23 23 16 97 523 int4gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT4GTOID 521 +DATA(insert OID = 522 ("<=" PGNSP PGUID b f f 21 21 16 524 520 int2le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT2LEOID 522 +DATA(insert OID = 523 ("<=" PGNSP PGUID b f f 23 23 16 525 521 int4le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT4LEOID 523 +DATA(insert OID = 524 (">=" PGNSP PGUID b f f 21 21 16 522 95 int2ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT2GEOID 524 +DATA(insert OID = 525 (">=" PGNSP PGUID b f f 23 23 16 523 97 int4ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT4GEOID 525 +DATA(insert OID = 526 ("*" PGNSP PGUID b f f 21 21 21 526 0 int2mul - -)); +DESCR("multiply"); +#define INT2MULOID 526 +DATA(insert OID = 527 ("/" PGNSP PGUID b f f 21 21 701 0 0 int2div - -)); +DESCR("divide"); +#define INT2DIVOID 527 +DATA(insert OID = 528 ("/" PGNSP PGUID b f f 23 23 701 0 0 int4div - -)); +DESCR("divide"); +#define INT4DIVOID 528 +DATA(insert OID = 529 ("%" PGNSP PGUID b f f 21 21 21 0 0 int2mod - -)); +DESCR("modulus"); +DATA(insert OID = 530 ("%" PGNSP PGUID b f f 23 23 23 0 0 int4mod - -)); +DESCR("modulus"); +DATA(insert OID = 531 ("<>" PGNSP PGUID b f f 25 25 16 531 98 textne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 532 ("=" PGNSP PGUID b t t 21 23 16 533 538 int24eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT24EQOID 532 +DATA(insert OID = 533 ("=" PGNSP PGUID b t t 23 21 16 532 539 int42eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT42EQOID 533 +DATA(insert OID = 534 ("<" PGNSP PGUID b f f 21 23 16 537 542 int24lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT24LTOID 534 +DATA(insert OID = 535 ("<" PGNSP PGUID b f f 23 21 16 536 543 int42lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT42LTOID 535 +DATA(insert OID = 536 (">" PGNSP PGUID b f f 21 23 16 535 540 int24gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT24GTOID 536 +DATA(insert OID = 537 (">" PGNSP PGUID b f f 23 21 16 534 541 int42gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT42GTOID 537 +DATA(insert OID = 538 ("<>" PGNSP PGUID b f f 21 23 16 539 532 int24ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT24NEOID 538 +DATA(insert OID = 539 ("<>" PGNSP PGUID b f f 23 21 16 538 533 int42ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT42NEOID 539 +DATA(insert OID = 540 ("<=" PGNSP PGUID b f f 21 23 16 543 536 int24le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT24LEOID 540 +DATA(insert OID = 541 ("<=" PGNSP PGUID b f f 23 21 16 542 537 int42le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT42LEOID 541 +DATA(insert OID = 542 (">=" PGNSP PGUID b f f 21 23 16 541 534 int24ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT24GEOID 542 +DATA(insert OID = 543 (">=" PGNSP PGUID b f f 23 21 16 540 535 int42ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT42GEOID 543 +DATA(insert OID = 544 ("*" PGNSP PGUID b f f 21 23 23 545 0 int24mul - -)); +DESCR("multiply"); +#define INT24MULOID 544 +DATA(insert OID = 545 ("*" PGNSP PGUID b f f 23 21 23 544 0 int42mul - -)); +DESCR("multiply"); +#define INT42MULOID 545 +DATA(insert OID = 546 ("/" PGNSP PGUID b f f 21 23 701 0 0 int24div - -)); +DESCR("divide"); +#define INT24DIVOID 546 +DATA(insert OID = 547 ("/" PGNSP PGUID b f f 23 21 701 0 0 int42div - -)); +DESCR("divide"); +#define INT42DIVOID 547 +DATA(insert OID = 550 ("+" PGNSP PGUID b f f 21 21 21 550 0 int2pl - -)); +DESCR("add"); +#define INT2PLOID 550 +DATA(insert OID = 551 ("+" PGNSP PGUID b f f 23 23 23 551 0 int4pl - -)); +DESCR("add"); +#define INT4PLOID 551 +DATA(insert OID = 552 ("+" PGNSP PGUID b f f 21 23 23 553 0 int24pl - -)); +DESCR("add"); +#define INT24PLOID 552 +DATA(insert OID = 553 ("+" PGNSP PGUID b f f 23 21 23 552 0 int42pl - -)); +DESCR("add"); +#define INT42PLOID 553 +DATA(insert OID = 554 ("-" PGNSP PGUID b f f 21 21 21 0 0 int2mi - -)); +DESCR("subtract"); +#define INT2MIOID 554 +DATA(insert OID = 555 ("-" PGNSP PGUID b f f 23 23 23 0 0 int4mi - -)); +DESCR("subtract"); +#define INT4MIOID 555 +DATA(insert OID = 556 ("-" PGNSP PGUID b f f 21 23 23 0 0 int24mi - -)); +DESCR("subtract"); +#define INT24MIOID 556 +DATA(insert OID = 557 ("-" PGNSP PGUID b f f 23 21 23 0 0 int42mi - -)); +DESCR("subtract"); +#define INT42MIOID 557 +DATA(insert OID = 558 ("-" PGNSP PGUID l f f 0 23 23 0 0 int4um - -)); +DESCR("negate"); +DATA(insert OID = 559 ("-" PGNSP PGUID l f f 0 21 21 0 0 int2um - -)); +DESCR("negate"); +DATA(insert OID = 560 ("=" PGNSP PGUID b t t 702 702 16 560 561 abstimeeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 561 ("<>" PGNSP PGUID b f f 702 702 16 561 560 abstimene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 562 ("<" PGNSP PGUID b f f 702 702 16 563 565 abstimelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 563 (">" PGNSP PGUID b f f 702 702 16 562 564 abstimegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 564 ("<=" PGNSP PGUID b f f 702 702 16 565 563 abstimele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 565 (">=" PGNSP PGUID b f f 702 702 16 564 562 abstimege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 566 ("=" PGNSP PGUID b t t 703 703 16 566 567 reltimeeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 567 ("<>" PGNSP PGUID b f f 703 703 16 567 566 reltimene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 568 ("<" PGNSP PGUID b f f 703 703 16 569 571 reltimelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 569 (">" PGNSP PGUID b f f 703 703 16 568 570 reltimegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 570 ("<=" PGNSP PGUID b f f 703 703 16 571 569 reltimele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 571 (">=" PGNSP PGUID b f f 703 703 16 570 568 reltimege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 572 ("~=" PGNSP PGUID b f f 704 704 16 572 0 tintervalsame eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 573 ("<<" PGNSP PGUID b f f 704 704 16 0 0 tintervalct - -)); +DESCR("contains"); +DATA(insert OID = 574 ("&&" PGNSP PGUID b f f 704 704 16 574 0 tintervalov - -)); +DESCR("overlaps"); +DATA(insert OID = 575 ("#=" PGNSP PGUID b f f 704 703 16 0 576 tintervalleneq - -)); +DESCR("equal by length"); +DATA(insert OID = 576 ("#<>" PGNSP PGUID b f f 704 703 16 0 575 tintervallenne - -)); +DESCR("not equal by length"); +DATA(insert OID = 577 ("#<" PGNSP PGUID b f f 704 703 16 0 580 tintervallenlt - -)); +DESCR("less than by length"); +DATA(insert OID = 578 ("#>" PGNSP PGUID b f f 704 703 16 0 579 tintervallengt - -)); +DESCR("greater than by length"); +DATA(insert OID = 579 ("#<=" PGNSP PGUID b f f 704 703 16 0 578 tintervallenle - -)); +DESCR("less than or equal by length"); +DATA(insert OID = 580 ("#>=" PGNSP PGUID b f f 704 703 16 0 577 tintervallenge - -)); +DESCR("greater than or equal by length"); +DATA(insert OID = 581 ("+" PGNSP PGUID b f f 702 703 702 0 0 timepl - -)); +DESCR("add"); +DATA(insert OID = 582 ("-" PGNSP PGUID b f f 702 703 702 0 0 timemi - -)); +DESCR("subtract"); +DATA(insert OID = 583 ("" PGNSP PGUID b f f 702 704 16 0 0 intinterval - -)); +DESCR("is contained by"); +DATA(insert OID = 584 ("-" PGNSP PGUID l f f 0 700 700 0 0 float4um - -)); +DESCR("negate"); +DATA(insert OID = 585 ("-" PGNSP PGUID l f f 0 701 701 0 0 float8um - -)); +DESCR("negate"); +DATA(insert OID = 586 ("+" PGNSP PGUID b f f 700 700 700 586 0 float4pl - -)); +DESCR("add"); +DATA(insert OID = 587 ("-" PGNSP PGUID b f f 700 700 700 0 0 float4mi - -)); +DESCR("subtract"); +DATA(insert OID = 588 ("/" PGNSP PGUID b f f 700 700 700 0 0 float4div - -)); +DESCR("divide"); +DATA(insert OID = 589 ("*" PGNSP PGUID b f f 700 700 700 589 0 float4mul - -)); +DESCR("multiply"); +DATA(insert OID = 590 ("@" PGNSP PGUID l f f 0 700 700 0 0 float4abs - -)); +DESCR("absolute value"); +DATA(insert OID = 591 ("+" PGNSP PGUID b f f 701 701 701 591 0 float8pl - -)); +DESCR("add"); +DATA(insert OID = 592 ("-" PGNSP PGUID b f f 701 701 701 0 0 float8mi - -)); +DESCR("subtract"); +DATA(insert OID = 593 ("/" PGNSP PGUID b f f 701 701 701 0 0 float8div - -)); +DESCR("divide"); +DATA(insert OID = 594 ("*" PGNSP PGUID b f f 701 701 701 594 0 float8mul - -)); +DESCR("multiply"); +DATA(insert OID = 595 ("@" PGNSP PGUID l f f 0 701 701 0 0 float8abs - -)); +DESCR("absolute value"); +DATA(insert OID = 596 ("|/" PGNSP PGUID l f f 0 701 701 0 0 dsqrt - -)); +DESCR("square root"); +DATA(insert OID = 597 ("||/" PGNSP PGUID l f f 0 701 701 0 0 dcbrt - -)); +DESCR("cube root"); +DATA(insert OID = 1284 ("|" PGNSP PGUID l f f 0 704 702 0 0 tintervalstart - -)); +DESCR("start of interval"); +DATA(insert OID = 606 ("<#>" PGNSP PGUID b f f 702 702 704 0 0 mktinterval - -)); +DESCR("convert to tinterval"); + +DATA(insert OID = 607 ("=" PGNSP PGUID b t t 26 26 16 607 608 oideq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 608 ("<>" PGNSP PGUID b f f 26 26 16 608 607 oidne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 609 ("<" PGNSP PGUID b f f 26 26 16 610 612 oidlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 610 (">" PGNSP PGUID b f f 26 26 16 609 611 oidgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 611 ("<=" PGNSP PGUID b f f 26 26 16 612 610 oidle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 612 (">=" PGNSP PGUID b f f 26 26 16 611 609 oidge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 644 ("<>" PGNSP PGUID b f f 30 30 16 644 649 oidvectorne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 645 ("<" PGNSP PGUID b f f 30 30 16 646 648 oidvectorlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 646 (">" PGNSP PGUID b f f 30 30 16 645 647 oidvectorgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 647 ("<=" PGNSP PGUID b f f 30 30 16 648 646 oidvectorle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 648 (">=" PGNSP PGUID b f f 30 30 16 647 645 oidvectorge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 649 ("=" PGNSP PGUID b t t 30 30 16 649 644 oidvectoreq eqsel eqjoinsel)); +DESCR("equal"); + +DATA(insert OID = 613 ("<->" PGNSP PGUID b f f 600 628 701 0 0 dist_pl - -)); +DESCR("distance between"); +DATA(insert OID = 614 ("<->" PGNSP PGUID b f f 600 601 701 0 0 dist_ps - -)); +DESCR("distance between"); +DATA(insert OID = 615 ("<->" PGNSP PGUID b f f 600 603 701 0 0 dist_pb - -)); +DESCR("distance between"); +DATA(insert OID = 616 ("<->" PGNSP PGUID b f f 601 628 701 0 0 dist_sl - -)); +DESCR("distance between"); +DATA(insert OID = 617 ("<->" PGNSP PGUID b f f 601 603 701 0 0 dist_sb - -)); +DESCR("distance between"); +DATA(insert OID = 618 ("<->" PGNSP PGUID b f f 600 602 701 0 0 dist_ppath - -)); +DESCR("distance between"); + +DATA(insert OID = 620 ("=" PGNSP PGUID b t t 700 700 16 620 621 float4eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT4EQOID 620 +DATA(insert OID = 621 ("<>" PGNSP PGUID b f f 700 700 16 621 620 float4ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT4NEOID 621 +DATA(insert OID = 622 ("<" PGNSP PGUID b f f 700 700 16 623 625 float4lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT4LTOID 622 +DATA(insert OID = 623 (">" PGNSP PGUID b f f 700 700 16 622 624 float4gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT4GTOID 623 +DATA(insert OID = 624 ("<=" PGNSP PGUID b f f 700 700 16 625 623 float4le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT4LEOID 624 +DATA(insert OID = 625 (">=" PGNSP PGUID b f f 700 700 16 624 622 float4ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT4GEOID 625 +DATA(insert OID = 630 ("<>" PGNSP PGUID b f f 18 18 16 630 92 charne neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 631 ("<" PGNSP PGUID b f f 18 18 16 633 634 charlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 632 ("<=" PGNSP PGUID b f f 18 18 16 634 633 charle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 633 (">" PGNSP PGUID b f f 18 18 16 631 632 chargt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 634 (">=" PGNSP PGUID b f f 18 18 16 632 631 charge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT1EQOID 5513 +DATA(insert OID = 5513 ("=" PGNSP PGUID b t t 5545 5545 16 5513 5514 int1eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 5514 ("<>" PGNSP PGUID b f f 5545 5545 16 5514 5513 int1ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 5515 ("<" PGNSP PGUID b f f 5545 5545 16 5517 5518 int1lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 5516 ("<=" PGNSP PGUID b f f 5545 5545 16 5518 5517 int1le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 5517 (">" PGNSP PGUID b f f 5545 5545 16 5515 5516 int1gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 5518 (">=" PGNSP PGUID b f f 5545 5545 16 5516 5515 int1ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 639 ("~" PGNSP PGUID b f f 19 25 16 0 640 nameregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_NAME_REGEXEQ_OP 639 +DATA(insert OID = 640 ("!~" PGNSP PGUID b f f 19 25 16 0 639 nameregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 641 ("~" PGNSP PGUID b f f 25 25 16 0 642 textregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_TEXT_REGEXEQ_OP 641 +DATA(insert OID = 642 ("!~" PGNSP PGUID b f f 25 25 16 0 641 textregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 643 ("<>" PGNSP PGUID b f f 19 19 16 643 93 namene neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 654 ("||" PGNSP PGUID b f f 25 25 25 0 0 textcat - -)); +DESCR("concatenate"); + +DATA(insert OID = 660 ("<" PGNSP PGUID b f f 19 19 16 662 663 namelt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 661 ("<=" PGNSP PGUID b f f 19 19 16 663 662 namele scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 662 (">" PGNSP PGUID b f f 19 19 16 660 661 namegt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 663 (">=" PGNSP PGUID b f f 19 19 16 661 660 namege scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 664 ("<" PGNSP PGUID b f f 25 25 16 666 667 text_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TEXTLTOID 664 +DATA(insert OID = 665 ("<=" PGNSP PGUID b f f 25 25 16 667 666 text_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 666 (">" PGNSP PGUID b f f 25 25 16 664 665 text_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TEXTGTOID 666 +DATA(insert OID = 667 (">=" PGNSP PGUID b f f 25 25 16 665 664 text_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 670 ("=" PGNSP PGUID b t t 701 701 16 670 671 float8eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT8EQOID 670 +DATA(insert OID = 671 ("<>" PGNSP PGUID b f f 701 701 16 671 670 float8ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT8NEOID 671 +DATA(insert OID = 672 ("<" PGNSP PGUID b f f 701 701 16 674 675 float8lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT8LTOID 672 +DATA(insert OID = 673 ("<=" PGNSP PGUID b f f 701 701 16 675 674 float8le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT8LEOID 673 +DATA(insert OID = 674 (">" PGNSP PGUID b f f 701 701 16 672 673 float8gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT8GTOID 674 +DATA(insert OID = 675 (">=" PGNSP PGUID b f f 701 701 16 673 672 float8ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT8GEOID 675 + +DATA(insert OID = 682 ("@" PGNSP PGUID l f f 0 21 21 0 0 int2abs - -)); +DESCR("absolute value"); +DATA(insert OID = 684 ("+" PGNSP PGUID b f f 20 20 20 684 0 int8pl - -)); +DESCR("add"); +#define INT8PLOID 684 +DATA(insert OID = 685 ("-" PGNSP PGUID b f f 20 20 20 0 0 int8mi - -)); +DESCR("subtract"); +#define INT8MIOID 685 +DATA(insert OID = 686 ("*" PGNSP PGUID b f f 20 20 20 686 0 int8mul - -)); +DESCR("multiply"); +#define INT8MULOID 686 +DATA(insert OID = 687 ("/" PGNSP PGUID b f f 20 20 701 0 0 int8div - -)); +DESCR("divide"); +#define INT8DIVOID 687 +DATA(insert OID = 688 ("+" PGNSP PGUID b f f 20 23 20 692 0 int84pl - -)); +DESCR("add"); +#define INT84PLOID 688 +DATA(insert OID = 689 ("-" PGNSP PGUID b f f 20 23 20 0 0 int84mi - -)); +DESCR("subtract"); +#define INT84MIOID 689 +DATA(insert OID = 690 ("*" PGNSP PGUID b f f 20 23 20 694 0 int84mul - -)); +DESCR("multiply"); +#define INT84MULOID 690 +DATA(insert OID = 691 ("/" PGNSP PGUID b f f 20 23 701 0 0 int84div - -)); +DESCR("divide"); +#define INT84DIVOID 691 +DATA(insert OID = 692 ("+" PGNSP PGUID b f f 23 20 20 688 0 int48pl - -)); +DESCR("add"); +#define INT48PLOID 692 +DATA(insert OID = 693 ("-" PGNSP PGUID b f f 23 20 20 0 0 int48mi - -)); +DESCR("subtract"); +#define INT48MIOID 693 +DATA(insert OID = 694 ("*" PGNSP PGUID b f f 23 20 20 690 0 int48mul - -)); +DESCR("multiply"); +#define INT48MULOID 694 +DATA(insert OID = 695 ("/" PGNSP PGUID b f f 23 20 701 0 0 int48div - -)); +DESCR("divide"); +#define INT48DIVOID 695 +DATA(insert OID = 818 ("+" PGNSP PGUID b f f 20 21 20 822 0 int82pl - -)); +DESCR("add"); +#define INT82PLOID 818 +DATA(insert OID = 819 ("-" PGNSP PGUID b f f 20 21 20 0 0 int82mi - -)); +DESCR("subtract"); +#define INT82MIOID 819 +DATA(insert OID = 820 ("*" PGNSP PGUID b f f 20 21 20 824 0 int82mul - -)); +DESCR("multiply"); +#define INT82MULOID 820 +DATA(insert OID = 821 ("/" PGNSP PGUID b f f 20 21 701 0 0 int82div - -)); +DESCR("divide"); +#define INT82DIVOID 821 +DATA(insert OID = 822 ("+" PGNSP PGUID b f f 21 20 20 818 0 int28pl - -)); +DESCR("add"); +#define INT28PLOID 822 +DATA(insert OID = 823 ("-" PGNSP PGUID b f f 21 20 20 0 0 int28mi - -)); +DESCR("subtract"); +#define INT28MIOID 823 +DATA(insert OID = 824 ("*" PGNSP PGUID b f f 21 20 20 820 0 int28mul - -)); +DESCR("multiply"); +#define INT28MULOID 824 +DATA(insert OID = 825 ("/" PGNSP PGUID b f f 21 20 701 0 0 int28div - -)); +DESCR("divide"); +#define INT28DIVOID 825 +DATA(insert OID = 706 ("<->" PGNSP PGUID b f f 603 603 701 706 0 box_distance - -)); +DESCR("distance between"); +DATA(insert OID = 707 ("<->" PGNSP PGUID b f f 602 602 701 707 0 path_distance - -)); +DESCR("distance between"); +DATA(insert OID = 708 ("<->" PGNSP PGUID b f f 628 628 701 708 0 line_distance - -)); +DESCR("distance between"); +DATA(insert OID = 709 ("<->" PGNSP PGUID b f f 601 601 701 709 0 lseg_distance - -)); +DESCR("distance between"); +DATA(insert OID = 712 ("<->" PGNSP PGUID b f f 604 604 701 712 0 poly_distance - -)); +DESCR("distance between"); + +DATA(insert OID = 713 ("<>" PGNSP PGUID b f f 600 600 16 713 510 point_ne neqsel neqjoinsel)); +DESCR("not equal"); + +/* add translation/rotation/scaling operators for geometric types. - thomas 97/05/10 */ +DATA(insert OID = 731 ("+" PGNSP PGUID b f f 600 600 600 731 0 point_add - -)); +DESCR("add points (translate)"); +DATA(insert OID = 732 ("-" PGNSP PGUID b f f 600 600 600 0 0 point_sub - -)); +DESCR("subtract points (translate)"); +DATA(insert OID = 733 ("*" PGNSP PGUID b f f 600 600 600 733 0 point_mul - -)); +DESCR("multiply points (scale/rotate)"); +DATA(insert OID = 734 ("/" PGNSP PGUID b f f 600 600 600 0 0 point_div - -)); +DESCR("divide points (scale/rotate)"); +DATA(insert OID = 735 ("+" PGNSP PGUID b f f 602 602 602 735 0 path_add - -)); +DESCR("concatenate"); +DATA(insert OID = 736 ("+" PGNSP PGUID b f f 602 600 602 0 0 path_add_pt - -)); +DESCR("add (translate path)"); +DATA(insert OID = 737 ("-" PGNSP PGUID b f f 602 600 602 0 0 path_sub_pt - -)); +DESCR("subtract (translate path)"); +DATA(insert OID = 738 ("*" PGNSP PGUID b f f 602 600 602 0 0 path_mul_pt - -)); +DESCR("multiply (rotate/scale path)"); +DATA(insert OID = 739 ("/" PGNSP PGUID b f f 602 600 602 0 0 path_div_pt - -)); +DESCR("divide (rotate/scale path)"); +DATA(insert OID = 755 ("@>" PGNSP PGUID b f f 602 600 16 512 0 path_contain_pt - -)); +DESCR("contains"); +DATA(insert OID = 756 ("<@" PGNSP PGUID b f f 600 604 16 757 0 pt_contained_poly contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 757 ("@>" PGNSP PGUID b f f 604 600 16 756 0 poly_contain_pt contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 758 ("<@" PGNSP PGUID b f f 600 718 16 759 0 pt_contained_circle contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 759 ("@>" PGNSP PGUID b f f 718 600 16 758 0 circle_contain_pt contsel contjoinsel)); +DESCR("contains"); + +DATA(insert OID = 773 ("@" PGNSP PGUID l f f 0 23 23 0 0 int4abs - -)); +DESCR("absolute value"); + +/* additional operators for geometric types - thomas 1997-07-09 */ +DATA(insert OID = 792 ("=" PGNSP PGUID b f f 602 602 16 792 0 path_n_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 793 ("<" PGNSP PGUID b f f 602 602 16 794 0 path_n_lt - -)); +DESCR("less than"); +DATA(insert OID = 794 (">" PGNSP PGUID b f f 602 602 16 793 0 path_n_gt - -)); +DESCR("greater than"); +DATA(insert OID = 795 ("<=" PGNSP PGUID b f f 602 602 16 796 0 path_n_le - -)); +DESCR("less than or equal"); +DATA(insert OID = 796 (">=" PGNSP PGUID b f f 602 602 16 795 0 path_n_ge - -)); +DESCR("greater than or equal"); +DATA(insert OID = 797 ("#" PGNSP PGUID l f f 0 602 23 0 0 path_npoints - -)); +DESCR("number of points"); +DATA(insert OID = 798 ("?#" PGNSP PGUID b f f 602 602 16 0 0 path_inter - -)); +DESCR("intersect"); +DATA(insert OID = 799 ("@-@" PGNSP PGUID l f f 0 602 701 0 0 path_length - -)); +DESCR("sum of path segment lengths"); +DATA(insert OID = 800 (">^" PGNSP PGUID b f f 603 603 16 0 0 box_above_eq positionsel positionjoinsel)); +DESCR("is above (allows touching)"); +DATA(insert OID = 801 ("<^" PGNSP PGUID b f f 603 603 16 0 0 box_below_eq positionsel positionjoinsel)); +DESCR("is below (allows touching)"); +DATA(insert OID = 802 ("?#" PGNSP PGUID b f f 603 603 16 0 0 box_overlap areasel areajoinsel)); +DESCR("deprecated, use && instead"); +DATA(insert OID = 803 ("#" PGNSP PGUID b f f 603 603 603 0 0 box_intersect - -)); +DESCR("box intersection"); +DATA(insert OID = 804 ("+" PGNSP PGUID b f f 603 600 603 0 0 box_add - -)); +DESCR("add point to box (translate)"); +DATA(insert OID = 805 ("-" PGNSP PGUID b f f 603 600 603 0 0 box_sub - -)); +DESCR("subtract point from box (translate)"); +DATA(insert OID = 806 ("*" PGNSP PGUID b f f 603 600 603 0 0 box_mul - -)); +DESCR("multiply box by point (scale)"); +DATA(insert OID = 807 ("/" PGNSP PGUID b f f 603 600 603 0 0 box_div - -)); +DESCR("divide box by point (scale)"); +DATA(insert OID = 808 ("?-" PGNSP PGUID b f f 600 600 16 808 0 point_horiz - -)); +DESCR("horizontally aligned"); +DATA(insert OID = 809 ("?|" PGNSP PGUID b f f 600 600 16 809 0 point_vert - -)); +DESCR("vertically aligned"); + +DATA(insert OID = 811 ("=" PGNSP PGUID b t f 704 704 16 811 812 tintervaleq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 812 ("<>" PGNSP PGUID b f f 704 704 16 812 811 tintervalne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 813 ("<" PGNSP PGUID b f f 704 704 16 814 816 tintervallt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 814 (">" PGNSP PGUID b f f 704 704 16 813 815 tintervalgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 815 ("<=" PGNSP PGUID b f f 704 704 16 816 814 tintervalle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 816 (">=" PGNSP PGUID b f f 704 704 16 815 813 tintervalge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 843 ("*" PGNSP PGUID b f f 790 700 790 845 0 cash_mul_flt4 - -)); +DESCR("multiply"); +DATA(insert OID = 844 ("/" PGNSP PGUID b f f 790 700 790 0 0 cash_div_flt4 - -)); +DESCR("divide"); +DATA(insert OID = 845 ("*" PGNSP PGUID b f f 700 790 790 843 0 flt4_mul_cash - -)); +DESCR("multiply"); + +DATA(insert OID = 900 ("=" PGNSP PGUID b t f 790 790 16 900 901 cash_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 901 ("<>" PGNSP PGUID b f f 790 790 16 901 900 cash_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 902 ("<" PGNSP PGUID b f f 790 790 16 903 905 cash_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 903 (">" PGNSP PGUID b f f 790 790 16 902 904 cash_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 904 ("<=" PGNSP PGUID b f f 790 790 16 905 903 cash_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 905 (">=" PGNSP PGUID b f f 790 790 16 904 902 cash_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 906 ("+" PGNSP PGUID b f f 790 790 790 906 0 cash_pl - -)); +DESCR("add"); +DATA(insert OID = 907 ("-" PGNSP PGUID b f f 790 790 790 0 0 cash_mi - -)); +DESCR("subtract"); +DATA(insert OID = 908 ("*" PGNSP PGUID b f f 790 701 790 916 0 cash_mul_flt8 - -)); +DESCR("multiply"); +DATA(insert OID = 909 ("/" PGNSP PGUID b f f 790 701 790 0 0 cash_div_flt8 - -)); +DESCR("divide"); +DATA(insert OID = 3346 ("*" PGNSP PGUID b f f 790 20 790 3349 0 cash_mul_int8 - -)); +DESCR("multiply"); +DATA(insert OID = 3347 ("/" PGNSP PGUID b f f 790 20 790 0 0 cash_div_int8 - -)); +DESCR("divide"); +DATA(insert OID = 912 ("*" PGNSP PGUID b f f 790 23 790 917 0 cash_mul_int4 - -)); +DESCR("multiply"); +DATA(insert OID = 913 ("/" PGNSP PGUID b f f 790 23 790 0 0 cash_div_int4 - -)); +DESCR("divide"); +DATA(insert OID = 914 ("*" PGNSP PGUID b f f 790 21 790 918 0 cash_mul_int2 - -)); +DESCR("multiply"); +DATA(insert OID = 915 ("/" PGNSP PGUID b f f 790 21 790 0 0 cash_div_int2 - -)); +DESCR("divide"); +DATA(insert OID = 3352 ("*" PGNSP PGUID b f f 790 5545 790 3354 0 cash_mul_int1 - -)); +DESCR("multiply"); +DATA(insert OID = 3353 ("/" PGNSP PGUID b f f 790 5545 790 0 0 cash_div_int1 - -)); +DESCR("divide"); +DATA(insert OID = 916 ("*" PGNSP PGUID b f f 701 790 790 908 0 flt8_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3349 ("*" PGNSP PGUID b f f 20 790 790 3346 0 int8_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 917 ("*" PGNSP PGUID b f f 23 790 790 912 0 int4_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 918 ("*" PGNSP PGUID b f f 21 790 790 914 0 int2_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3354 ("*" PGNSP PGUID b f f 5545 790 790 3352 0 int1_mul_cash - -)); +DESCR("multiply"); +DATA(insert OID = 3825 ("/" PGNSP PGUID b f f 790 790 701 0 0 cash_div_cash - -)); +DESCR("divide"); + +DATA(insert OID = 965 ("^" PGNSP PGUID b f f 701 701 701 0 0 dpow - -)); +DESCR("exponentiation"); +DATA(insert OID = 966 ("+" PGNSP PGUID b f f 1034 1033 1034 0 0 aclinsert - -)); +DESCR("add/update ACL item"); +DATA(insert OID = 967 ("-" PGNSP PGUID b f f 1034 1033 1034 0 0 aclremove - -)); +DESCR("remove ACL item"); +DATA(insert OID = 968 ("@>" PGNSP PGUID b f f 1034 1033 16 0 0 aclcontains - -)); +DESCR("contains"); +DATA(insert OID = 974 ("=" PGNSP PGUID b f t 1033 1033 16 974 0 aclitemeq eqsel eqjoinsel)); +DESCR("equal"); + +/* additional geometric operators - thomas 1997-07-09 */ +DATA(insert OID = 969 ("@@" PGNSP PGUID l f f 0 601 600 0 0 lseg_center - -)); +DESCR("center of"); +DATA(insert OID = 970 ("@@" PGNSP PGUID l f f 0 602 600 0 0 path_center - -)); +DESCR("center of"); +DATA(insert OID = 971 ("@@" PGNSP PGUID l f f 0 604 600 0 0 poly_center - -)); +DESCR("center of"); + +DATA(insert OID = 1054 ("=" PGNSP PGUID b t t 1042 1042 16 1054 1057 bpchareq eqsel eqjoinsel)); +DESCR("equal"); +#define BPCHAREQOID 1054 +DATA(insert OID = 1055 ("~" PGNSP PGUID b f f 1042 25 16 0 1056 bpcharregexeq regexeqsel regexeqjoinsel)); +DESCR("matches regular expression, case-sensitive"); +#define OID_BPCHAR_REGEXEQ_OP 1055 +DATA(insert OID = 1056 ("!~" PGNSP PGUID b f f 1042 25 16 0 1055 bpcharregexne regexnesel regexnejoinsel)); +DESCR("does not match regular expression, case-sensitive"); +DATA(insert OID = 1057 ("<>" PGNSP PGUID b f f 1042 1042 16 1057 1054 bpcharne neqsel neqjoinsel)); +DESCR("not equal"); +#define BPCHARNEOID 1057 +DATA(insert OID = 1058 ("<" PGNSP PGUID b f f 1042 1042 16 1060 1061 bpcharlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define BPCHARLTOID 1058 +DATA(insert OID = 1059 ("<=" PGNSP PGUID b f f 1042 1042 16 1061 1060 bpcharle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1060 (">" PGNSP PGUID b f f 1042 1042 16 1058 1059 bpchargt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define BPCHARGTOID 1060 +DATA(insert OID = 1061 (">=" PGNSP PGUID b f f 1042 1042 16 1059 1058 bpcharge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* generic array comparison operators */ +DATA(insert OID = 1070 ("=" PGNSP PGUID b t t 2277 2277 16 1070 1071 array_eq eqsel eqjoinsel)); +DESCR("equal"); +#define ARRAY_EQ_OP 1070 +DATA(insert OID = 1071 ("<>" PGNSP PGUID b f f 2277 2277 16 1071 1070 array_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1072 ("<" PGNSP PGUID b f f 2277 2277 16 1073 1075 array_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define ARRAY_LT_OP 1072 +DATA(insert OID = 1073 (">" PGNSP PGUID b f f 2277 2277 16 1072 1074 array_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define ARRAY_GT_OP 1073 +DATA(insert OID = 1074 ("<=" PGNSP PGUID b f f 2277 2277 16 1075 1073 array_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1075 (">=" PGNSP PGUID b f f 2277 2277 16 1074 1072 array_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* date operators */ +DATA(insert OID = 1076 ("+" PGNSP PGUID b f f 1082 1186 1114 2551 0 date_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1077 ("-" PGNSP PGUID b f f 1082 1186 1114 0 0 date_mi_interval - -)); +DESCR("subtract"); +DATA(insert OID = 1093 ("=" PGNSP PGUID b t t 1082 1082 16 1093 1094 date_eq eqsel eqjoinsel)); +DESCR("equal"); +#define DATEEQOID 1093 +DATA(insert OID = 1094 ("<>" PGNSP PGUID b f f 1082 1082 16 1094 1093 date_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define DATENEOID 1094 +DATA(insert OID = 1095 ("<" PGNSP PGUID b f f 1082 1082 16 1097 1098 date_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define DATELTOID 1095 +DATA(insert OID = 1096 ("<=" PGNSP PGUID b f f 1082 1082 16 1098 1097 date_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define DATELEOID 1096 +DATA(insert OID = 1097 (">" PGNSP PGUID b f f 1082 1082 16 1095 1096 date_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define DATEGTOID 1097 +DATA(insert OID = 1098 (">=" PGNSP PGUID b f f 1082 1082 16 1096 1095 date_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define DATEGEOID 1098 +DATA(insert OID = 1099 ("-" PGNSP PGUID b f f 1082 1082 23 0 0 date_mi - -)); +DESCR("subtract"); +DATA(insert OID = 1100 ("+" PGNSP PGUID b f f 1082 23 1082 2555 0 date_pli - -)); +DESCR("add"); +DATA(insert OID = 1101 ("-" PGNSP PGUID b f f 1082 23 1082 0 0 date_mii - -)); +DESCR("subtract"); + +/* time operators */ +DATA(insert OID = 1108 ("=" PGNSP PGUID b t t 1083 1083 16 1108 1109 time_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1109 ("<>" PGNSP PGUID b f f 1083 1083 16 1109 1108 time_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1110 ("<" PGNSP PGUID b f f 1083 1083 16 1112 1113 time_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1111 ("<=" PGNSP PGUID b f f 1083 1083 16 1113 1112 time_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1112 (">" PGNSP PGUID b f f 1083 1083 16 1110 1111 time_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1113 (">=" PGNSP PGUID b f f 1083 1083 16 1111 1110 time_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* timetz operators */ +DATA(insert OID = 1550 ("=" PGNSP PGUID b t t 1266 1266 16 1550 1551 timetz_eq eqsel eqjoinsel)); +DESCR("equal"); +#define TIMETZEQOID 1550 +DATA(insert OID = 1551 ("<>" PGNSP PGUID b f f 1266 1266 16 1551 1550 timetz_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1552 ("<" PGNSP PGUID b f f 1266 1266 16 1554 1555 timetz_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1553 ("<=" PGNSP PGUID b f f 1266 1266 16 1555 1554 timetz_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1554 (">" PGNSP PGUID b f f 1266 1266 16 1552 1553 timetz_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1555 (">=" PGNSP PGUID b f f 1266 1266 16 1553 1552 timetz_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* float48 operators */ +DATA(insert OID = 1116 ("+" PGNSP PGUID b f f 700 701 701 1126 0 float48pl - -)); +DESCR("add"); +DATA(insert OID = 1117 ("-" PGNSP PGUID b f f 700 701 701 0 0 float48mi - -)); +DESCR("subtract"); +DATA(insert OID = 1118 ("/" PGNSP PGUID b f f 700 701 701 0 0 float48div - -)); +DESCR("divide"); +DATA(insert OID = 1119 ("*" PGNSP PGUID b f f 700 701 701 1129 0 float48mul - -)); +DESCR("multiply"); +DATA(insert OID = 1120 ("=" PGNSP PGUID b t t 700 701 16 1130 1121 float48eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT48EQOID 1120 +DATA(insert OID = 1121 ("<>" PGNSP PGUID b f f 700 701 16 1131 1120 float48ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT48NEOID 1121 +DATA(insert OID = 1122 ("<" PGNSP PGUID b f f 700 701 16 1133 1125 float48lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT48LTOID 1122 +DATA(insert OID = 1123 (">" PGNSP PGUID b f f 700 701 16 1132 1124 float48gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT48GTOID 1123 +DATA(insert OID = 1124 ("<=" PGNSP PGUID b f f 700 701 16 1135 1123 float48le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT48LEOID 1124 +DATA(insert OID = 1125 (">=" PGNSP PGUID b f f 700 701 16 1134 1122 float48ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT48GEOID 1125 + +/* float84 operators */ +DATA(insert OID = 1126 ("+" PGNSP PGUID b f f 701 700 701 1116 0 float84pl - -)); +DESCR("add"); +DATA(insert OID = 1127 ("-" PGNSP PGUID b f f 701 700 701 0 0 float84mi - -)); +DESCR("subtract"); +DATA(insert OID = 1128 ("/" PGNSP PGUID b f f 701 700 701 0 0 float84div - -)); +DESCR("divide"); +DATA(insert OID = 1129 ("*" PGNSP PGUID b f f 701 700 701 1119 0 float84mul - -)); +DESCR("multiply"); +DATA(insert OID = 1130 ("=" PGNSP PGUID b t t 701 700 16 1120 1131 float84eq eqsel eqjoinsel)); +DESCR("equal"); +#define FLOAT84EQOID 1130 +DATA(insert OID = 1131 ("<>" PGNSP PGUID b f f 701 700 16 1121 1130 float84ne neqsel neqjoinsel)); +DESCR("not equal"); +#define FLOAT84NEOID 1131 +DATA(insert OID = 1132 ("<" PGNSP PGUID b f f 701 700 16 1123 1135 float84lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define FLOAT84LTOID 1132 +DATA(insert OID = 1133 (">" PGNSP PGUID b f f 701 700 16 1122 1134 float84gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define FLOAT84GTOID 1133 +DATA(insert OID = 1134 ("<=" PGNSP PGUID b f f 701 700 16 1125 1133 float84le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define FLOAT84LEOID 1134 +DATA(insert OID = 1135 (">=" PGNSP PGUID b f f 701 700 16 1124 1132 float84ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define FLOAT84GEOID 1135 + + +/* LIKE hacks by Keith Parks. */ +DATA(insert OID = 1207 ("~~" PGNSP PGUID b f f 19 25 16 0 1208 namelike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_NAME_LIKE_OP 1207 +DATA(insert OID = 1208 ("!~~" PGNSP PGUID b f f 19 25 16 0 1207 namenlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define OID_NAME_NOT_LIKE_OP 1208 +DATA(insert OID = 1209 ("~~" PGNSP PGUID b f f 25 25 16 0 1210 textlike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_TEXT_LIKE_OP 1209 +DATA(insert OID = 1210 ("!~~" PGNSP PGUID b f f 25 25 16 0 1209 textnlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define TEXTNOTLIKEOID 1210 +DATA(insert OID = 1211 ("~~" PGNSP PGUID b f f 1042 25 16 0 1212 bpcharlike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_BPCHAR_LIKE_OP 1211 +DATA(insert OID = 1212 ("!~~" PGNSP PGUID b f f 1042 25 16 0 1211 bpcharnlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +#define OID_BPCHAR_NOT_LIKE_OP 1212 + +/* case-insensitive regex hacks */ +DATA(insert OID = 1226 ("~*" PGNSP PGUID b f f 19 25 16 0 1227 nameicregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_NAME_ICREGEXEQ_OP 1226 +DATA(insert OID = 1227 ("!~*" PGNSP PGUID b f f 19 25 16 0 1226 nameicregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); +DATA(insert OID = 1228 ("~*" PGNSP PGUID b f f 25 25 16 0 1229 texticregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_TEXT_ICREGEXEQ_OP 1228 +DATA(insert OID = 1229 ("!~*" PGNSP PGUID b f f 25 25 16 0 1228 texticregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); +DATA(insert OID = 1234 ("~*" PGNSP PGUID b f f 1042 25 16 0 1235 bpcharicregexeq icregexeqsel icregexeqjoinsel)); +DESCR("matches regular expression, case-insensitive"); +#define OID_BPCHAR_ICREGEXEQ_OP 1234 +DATA(insert OID = 1235 ("!~*" PGNSP PGUID b f f 1042 25 16 0 1234 bpcharicregexne icregexnesel icregexnejoinsel)); +DESCR("does not match regular expression, case-insensitive"); + +/* timestamptz operators */ +DATA(insert OID = 1320 ("=" PGNSP PGUID b t t 1184 1184 16 1320 1321 timestamptz_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1321 ("<>" PGNSP PGUID b f f 1184 1184 16 1321 1320 timestamptz_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1322 ("<" PGNSP PGUID b f f 1184 1184 16 1324 1325 timestamptz_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIMESTAMPTZLTOID 1322 +DATA(insert OID = 1323 ("<=" PGNSP PGUID b f f 1184 1184 16 1325 1324 timestamptz_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define TIMESTAMPTZLEOID 1323 +DATA(insert OID = 1324 (">" PGNSP PGUID b f f 1184 1184 16 1322 1323 timestamptz_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TIMESTAMPTZGTOID 1324 +DATA(insert OID = 1325 (">=" PGNSP PGUID b f f 1184 1184 16 1323 1322 timestamptz_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define TIMESTAMPTZGEOID 1325 +DATA(insert OID = 1327 ("+" PGNSP PGUID b f f 1184 1186 1184 2554 0 timestamptz_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1328 ("-" PGNSP PGUID b f f 1184 1184 1186 0 0 timestamptz_mi - -)); +DESCR("subtract"); +DATA(insert OID = 1329 ("-" PGNSP PGUID b f f 1184 1186 1184 0 0 timestamptz_mi_interval - -)); +DESCR("subtract"); + +/* interval operators */ +DATA(insert OID = 1330 ("=" PGNSP PGUID b t t 1186 1186 16 1330 1331 interval_eq eqsel eqjoinsel)); +DESCR("equal"); +#define INTERVALEQOID 1330 +DATA(insert OID = 1331 ("<>" PGNSP PGUID b f f 1186 1186 16 1331 1330 interval_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1332 ("<" PGNSP PGUID b f f 1186 1186 16 1334 1335 interval_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1333 ("<=" PGNSP PGUID b f f 1186 1186 16 1335 1334 interval_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1334 (">" PGNSP PGUID b f f 1186 1186 16 1332 1333 interval_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1335 (">=" PGNSP PGUID b f f 1186 1186 16 1333 1332 interval_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 1336 ("-" PGNSP PGUID l f f 0 1186 1186 0 0 interval_um - -)); +DESCR("negate"); +DATA(insert OID = 1337 ("+" PGNSP PGUID b f f 1186 1186 1186 1337 0 interval_pl - -)); +DESCR("add"); +DATA(insert OID = 1338 ("-" PGNSP PGUID b f f 1186 1186 1186 0 0 interval_mi - -)); +DESCR("subtract"); + +DATA(insert OID = 1360 ("+" PGNSP PGUID b f f 1082 1083 1114 1363 0 datetime_pl - -)); +DESCR("convert date and time to timestamp"); +DATA(insert OID = 1361 ("+" PGNSP PGUID b f f 1082 1266 1184 1366 0 datetimetz_pl - -)); +DESCR("convert date and time with time zone to timestamp with time zone"); +DATA(insert OID = 1363 ("+" PGNSP PGUID b f f 1083 1082 1114 1360 0 timedate_pl - -)); +DESCR("convert time and date to timestamp"); +DATA(insert OID = 1366 ("+" PGNSP PGUID b f f 1266 1082 1184 1361 0 timetzdate_pl - -)); +DESCR("convert time with time zone and date to timestamp with time zone"); + +DATA(insert OID = 1399 ("-" PGNSP PGUID b f f 1083 1083 1186 0 0 time_mi_time - -)); +DESCR("subtract"); + +/* additional geometric operators - thomas 97/04/18 */ +DATA(insert OID = 1420 ("@@" PGNSP PGUID l f f 0 718 600 0 0 circle_center - -)); +DESCR("center of"); +DATA(insert OID = 1500 ("=" PGNSP PGUID b f f 718 718 16 1500 1501 circle_eq eqsel eqjoinsel)); +DESCR("equal by area"); +DATA(insert OID = 1501 ("<>" PGNSP PGUID b f f 718 718 16 1501 1500 circle_ne neqsel neqjoinsel)); +DESCR("not equal by area"); +DATA(insert OID = 1502 ("<" PGNSP PGUID b f f 718 718 16 1503 1505 circle_lt areasel areajoinsel)); +DESCR("less than by area"); +DATA(insert OID = 1503 (">" PGNSP PGUID b f f 718 718 16 1502 1504 circle_gt areasel areajoinsel)); +DESCR("greater than by area"); +DATA(insert OID = 1504 ("<=" PGNSP PGUID b f f 718 718 16 1505 1503 circle_le areasel areajoinsel)); +DESCR("less than or equal by area"); +DATA(insert OID = 1505 (">=" PGNSP PGUID b f f 718 718 16 1504 1502 circle_ge areasel areajoinsel)); +DESCR("greater than or equal by area"); + +DATA(insert OID = 1506 ("<<" PGNSP PGUID b f f 718 718 16 0 0 circle_left positionsel positionjoinsel)); +DESCR("is left of"); +DATA(insert OID = 1507 ("&<" PGNSP PGUID b f f 718 718 16 0 0 circle_overleft positionsel positionjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 1508 ("&>" PGNSP PGUID b f f 718 718 16 0 0 circle_overright positionsel positionjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 1509 (">>" PGNSP PGUID b f f 718 718 16 0 0 circle_right positionsel positionjoinsel)); +DESCR("is right of"); +DATA(insert OID = 1510 ("<@" PGNSP PGUID b f f 718 718 16 1511 0 circle_contained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 1511 ("@>" PGNSP PGUID b f f 718 718 16 1510 0 circle_contain contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 1512 ("~=" PGNSP PGUID b f f 718 718 16 1512 0 circle_same eqsel eqjoinsel)); +DESCR("same as"); +DATA(insert OID = 1513 ("&&" PGNSP PGUID b f f 718 718 16 1513 0 circle_overlap areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 1514 ("|>>" PGNSP PGUID b f f 718 718 16 0 0 circle_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 1515 ("<<|" PGNSP PGUID b f f 718 718 16 0 0 circle_below positionsel positionjoinsel)); +DESCR("is below"); + +DATA(insert OID = 1516 ("+" PGNSP PGUID b f f 718 600 718 0 0 circle_add_pt - -)); +DESCR("add"); +DATA(insert OID = 1517 ("-" PGNSP PGUID b f f 718 600 718 0 0 circle_sub_pt - -)); +DESCR("subtract"); +DATA(insert OID = 1518 ("*" PGNSP PGUID b f f 718 600 718 0 0 circle_mul_pt - -)); +DESCR("multiply"); +DATA(insert OID = 1519 ("/" PGNSP PGUID b f f 718 600 718 0 0 circle_div_pt - -)); +DESCR("divide"); + +DATA(insert OID = 1520 ("<->" PGNSP PGUID b f f 718 718 701 1520 0 circle_distance - -)); +DESCR("distance between"); +DATA(insert OID = 1521 ("#" PGNSP PGUID l f f 0 604 23 0 0 poly_npoints - -)); +DESCR("number of points"); +DATA(insert OID = 1522 ("<->" PGNSP PGUID b f f 600 718 701 0 0 dist_pc - -)); +DESCR("distance between"); +DATA(insert OID = 1523 ("<->" PGNSP PGUID b f f 718 604 701 0 0 dist_cpoly - -)); +DESCR("distance between"); + +/* additional geometric operators - thomas 1997-07-09 */ +DATA(insert OID = 1524 ("<->" PGNSP PGUID b f f 628 603 701 0 0 dist_lb - -)); +DESCR("distance between"); + +DATA(insert OID = 1525 ("?#" PGNSP PGUID b f f 601 601 16 1525 0 lseg_intersect - -)); +DESCR("intersect"); +DATA(insert OID = 1526 ("?||" PGNSP PGUID b f f 601 601 16 1526 0 lseg_parallel - -)); +DESCR("parallel"); +DATA(insert OID = 1527 ("?-|" PGNSP PGUID b f f 601 601 16 1527 0 lseg_perp - -)); +DESCR("perpendicular"); +DATA(insert OID = 1528 ("?-" PGNSP PGUID l f f 0 601 16 0 0 lseg_horizontal - -)); +DESCR("horizontal"); +DATA(insert OID = 1529 ("?|" PGNSP PGUID l f f 0 601 16 0 0 lseg_vertical - -)); +DESCR("vertical"); +DATA(insert OID = 1535 ("=" PGNSP PGUID b f f 601 601 16 1535 1586 lseg_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1536 ("#" PGNSP PGUID b f f 601 601 600 1536 0 lseg_interpt - -)); +DESCR("intersection point"); +DATA(insert OID = 1537 ("?#" PGNSP PGUID b f f 601 628 16 0 0 inter_sl - -)); +DESCR("intersect"); +DATA(insert OID = 1538 ("?#" PGNSP PGUID b f f 601 603 16 0 0 inter_sb - -)); +DESCR("intersect"); +DATA(insert OID = 1539 ("?#" PGNSP PGUID b f f 628 603 16 0 0 inter_lb - -)); +DESCR("intersect"); + +DATA(insert OID = 1546 ("<@" PGNSP PGUID b f f 600 628 16 0 0 on_pl - -)); +DESCR("point on line"); +DATA(insert OID = 1547 ("<@" PGNSP PGUID b f f 600 601 16 0 0 on_ps - -)); +DESCR("is contained by"); +DATA(insert OID = 1548 ("<@" PGNSP PGUID b f f 601 628 16 0 0 on_sl - -)); +DESCR("lseg on line"); +DATA(insert OID = 1549 ("<@" PGNSP PGUID b f f 601 603 16 0 0 on_sb - -)); +DESCR("is contained by"); + +DATA(insert OID = 1557 ("##" PGNSP PGUID b f f 600 628 600 0 0 close_pl - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1558 ("##" PGNSP PGUID b f f 600 601 600 0 0 close_ps - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1559 ("##" PGNSP PGUID b f f 600 603 600 0 0 close_pb - -)); +DESCR("closest point to A on B"); + +DATA(insert OID = 1566 ("##" PGNSP PGUID b f f 601 628 600 0 0 close_sl - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1567 ("##" PGNSP PGUID b f f 601 603 600 0 0 close_sb - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1568 ("##" PGNSP PGUID b f f 628 603 600 0 0 close_lb - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1577 ("##" PGNSP PGUID b f f 628 601 600 0 0 close_ls - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1578 ("##" PGNSP PGUID b f f 601 601 600 0 0 close_lseg - -)); +DESCR("closest point to A on B"); +DATA(insert OID = 1583 ("*" PGNSP PGUID b f f 1186 701 1186 1584 0 interval_mul - -)); +DESCR("multiply"); +DATA(insert OID = 1584 ("*" PGNSP PGUID b f f 701 1186 1186 1583 0 mul_d_interval - -)); +DESCR("multiply"); +DATA(insert OID = 1585 ("/" PGNSP PGUID b f f 1186 701 1186 0 0 interval_div - -)); +DESCR("divide"); + +DATA(insert OID = 1586 ("<>" PGNSP PGUID b f f 601 601 16 1586 1535 lseg_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1587 ("<" PGNSP PGUID b f f 601 601 16 1589 1590 lseg_lt - -)); +DESCR("less than by length"); +DATA(insert OID = 1588 ("<=" PGNSP PGUID b f f 601 601 16 1590 1589 lseg_le - -)); +DESCR("less than or equal by length"); +DATA(insert OID = 1589 (">" PGNSP PGUID b f f 601 601 16 1587 1588 lseg_gt - -)); +DESCR("greater than by length"); +DATA(insert OID = 1590 (">=" PGNSP PGUID b f f 601 601 16 1588 1587 lseg_ge - -)); +DESCR("greater than or equal by length"); + +DATA(insert OID = 1591 ("@-@" PGNSP PGUID l f f 0 601 701 0 0 lseg_length - -)); +DESCR("distance between endpoints"); + +DATA(insert OID = 1611 ("?#" PGNSP PGUID b f f 628 628 16 1611 0 line_intersect - -)); +DESCR("intersect"); +DATA(insert OID = 1612 ("?||" PGNSP PGUID b f f 628 628 16 1612 0 line_parallel - -)); +DESCR("parallel"); +DATA(insert OID = 1613 ("?-|" PGNSP PGUID b f f 628 628 16 1613 0 line_perp - -)); +DESCR("perpendicular"); +DATA(insert OID = 1614 ("?-" PGNSP PGUID l f f 0 628 16 0 0 line_horizontal - -)); +DESCR("horizontal"); +DATA(insert OID = 1615 ("?|" PGNSP PGUID l f f 0 628 16 0 0 line_vertical - -)); +DESCR("vertical"); +DATA(insert OID = 1616 ("=" PGNSP PGUID b f f 628 628 16 1616 0 line_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1617 ("#" PGNSP PGUID b f f 628 628 600 1617 0 line_interpt - -)); +DESCR("intersection point"); + +/* MAC type */ +DATA(insert OID = 1220 ("=" PGNSP PGUID b t t 829 829 16 1220 1221 macaddr_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1221 ("<>" PGNSP PGUID b f f 829 829 16 1221 1220 macaddr_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1222 ("<" PGNSP PGUID b f f 829 829 16 1224 1225 macaddr_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1223 ("<=" PGNSP PGUID b f f 829 829 16 1225 1224 macaddr_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1224 (">" PGNSP PGUID b f f 829 829 16 1222 1223 macaddr_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1225 (">=" PGNSP PGUID b f f 829 829 16 1223 1222 macaddr_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 3147 ("~" PGNSP PGUID l f f 0 829 829 0 0 macaddr_not - -)); +DESCR("bitwise not"); +DATA(insert OID = 3148 ("&" PGNSP PGUID b f f 829 829 829 0 0 macaddr_and - -)); +DESCR("bitwise and"); +DATA(insert OID = 3149 ("|" PGNSP PGUID b f f 829 829 829 0 0 macaddr_or - -)); +DESCR("bitwise or"); + +/* INET type (these also support CIDR via implicit cast) */ +DATA(insert OID = 1201 ("=" PGNSP PGUID b t t 869 869 16 1201 1202 network_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1202 ("<>" PGNSP PGUID b f f 869 869 16 1202 1201 network_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1203 ("<" PGNSP PGUID b f f 869 869 16 1205 1206 network_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1204 ("<=" PGNSP PGUID b f f 869 869 16 1206 1205 network_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1205 (">" PGNSP PGUID b f f 869 869 16 1203 1204 network_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1206 (">=" PGNSP PGUID b f f 869 869 16 1204 1203 network_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 931 ("<<" PGNSP PGUID b f f 869 869 16 933 0 network_sub - -)); +DESCR("is subnet"); +#define OID_INET_SUB_OP 931 +DATA(insert OID = 932 ("<<=" PGNSP PGUID b f f 869 869 16 934 0 network_subeq - -)); +DESCR("is subnet or equal"); +#define OID_INET_SUBEQ_OP 932 +DATA(insert OID = 933 (">>" PGNSP PGUID b f f 869 869 16 931 0 network_sup - -)); +DESCR("is supernet"); +#define OID_INET_SUP_OP 933 +DATA(insert OID = 934 (">>=" PGNSP PGUID b f f 869 869 16 932 0 network_supeq - -)); +DESCR("is supernet or equal"); +#define OID_INET_SUPEQ_OP 934 + +DATA(insert OID = 2634 ("~" PGNSP PGUID l f f 0 869 869 0 0 inetnot - -)); +DESCR("bitwise not"); +DATA(insert OID = 2635 ("&" PGNSP PGUID b f f 869 869 869 0 0 inetand - -)); +DESCR("bitwise and"); +DATA(insert OID = 2636 ("|" PGNSP PGUID b f f 869 869 869 0 0 inetor - -)); +DESCR("bitwise or"); +DATA(insert OID = 2637 ("+" PGNSP PGUID b f f 869 20 869 2638 0 inetpl - -)); +DESCR("add"); +DATA(insert OID = 2638 ("+" PGNSP PGUID b f f 20 869 869 2637 0 int8pl_inet - -)); +DESCR("add"); +DATA(insert OID = 2639 ("-" PGNSP PGUID b f f 869 20 869 0 0 inetmi_int8 - -)); +DESCR("subtract"); +DATA(insert OID = 2640 ("-" PGNSP PGUID b f f 869 869 20 0 0 inetmi - -)); +DESCR("subtract"); + +/* case-insensitive LIKE hacks */ +DATA(insert OID = 1625 ("~~*" PGNSP PGUID b f f 19 25 16 0 1626 nameiclike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_NAME_ICLIKE_OP 1625 +DATA(insert OID = 1626 ("!~~*" PGNSP PGUID b f f 19 25 16 0 1625 nameicnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); +DATA(insert OID = 1627 ("~~*" PGNSP PGUID b f f 25 25 16 0 1628 texticlike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_TEXT_ICLIKE_OP 1627 +DATA(insert OID = 1628 ("!~~*" PGNSP PGUID b f f 25 25 16 0 1627 texticnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); +DATA(insert OID = 1629 ("~~*" PGNSP PGUID b f f 1042 25 16 0 1630 bpchariclike iclikesel iclikejoinsel)); +DESCR("matches LIKE expression, case-insensitive"); +#define OID_BPCHAR_ICLIKE_OP 1629 +DATA(insert OID = 1630 ("!~~*" PGNSP PGUID b f f 1042 25 16 0 1629 bpcharicnlike icnlikesel icnlikejoinsel)); +DESCR("does not match LIKE expression, case-insensitive"); + +/* NUMERIC type - OID's 1700-1799 */ +DATA(insert OID = 1751 ("-" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_uminus - -)); +DESCR("negate"); +#define NUMEQOID 1752 +DATA(insert OID = 1752 ("=" PGNSP PGUID b t t 1700 1700 16 1752 1753 numeric_eq eqsel eqjoinsel)); +DESCR("equal"); +#define NUMERICEQOID 1752 +DATA(insert OID = 1753 ("<>" PGNSP PGUID b f f 1700 1700 16 1753 1752 numeric_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define NUMERICNEOID 1753 +DATA(insert OID = 1754 ("<" PGNSP PGUID b f f 1700 1700 16 1756 1757 numeric_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define NUMERICLTOID 1754 +DATA(insert OID = 1755 ("<=" PGNSP PGUID b f f 1700 1700 16 1757 1756 numeric_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define NUMERICLEOID 1755 +DATA(insert OID = 1756 (">" PGNSP PGUID b f f 1700 1700 16 1754 1755 numeric_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define NUMERICGTOID 1756 +DATA(insert OID = 1757 (">=" PGNSP PGUID b f f 1700 1700 16 1755 1754 numeric_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define NUMERICGEOID 1757 +DATA(insert OID = 1758 ("+" PGNSP PGUID b f f 1700 1700 1700 1758 0 numeric_add - -)); +DESCR("add"); +#define NUMERICADDOID 1758 +DATA(insert OID = 1759 ("-" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_sub - -)); +DESCR("subtract"); +#define NUMERICSUBOID 1759 +DATA(insert OID = 1760 ("*" PGNSP PGUID b f f 1700 1700 1700 1760 0 numeric_mul - -)); +DESCR("multiply"); +#define NUMERICMULOID 1760 +DATA(insert OID = 1761 ("/" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_div - -)); +DESCR("divide"); +#define NUMERICDIVOID 1761 +DATA(insert OID = 1762 ("%" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_mod - -)); +DESCR("modulus"); +#define NUMERICMODOID 1762 +DATA(insert OID = 1038 ("^" PGNSP PGUID b f f 1700 1700 1700 0 0 numeric_power - -)); +DESCR("exponentiation"); +DATA(insert OID = 1763 ("@" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_abs - -)); +DESCR("absolute value"); + +DATA(insert OID = 1784 ("=" PGNSP PGUID b t f 1560 1560 16 1784 1785 biteq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1785 ("<>" PGNSP PGUID b f f 1560 1560 16 1785 1784 bitne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1786 ("<" PGNSP PGUID b f f 1560 1560 16 1787 1789 bitlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1787 (">" PGNSP PGUID b f f 1560 1560 16 1786 1788 bitgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1788 ("<=" PGNSP PGUID b f f 1560 1560 16 1789 1787 bitle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1789 (">=" PGNSP PGUID b f f 1560 1560 16 1788 1786 bitge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 1791 ("&" PGNSP PGUID b f f 1560 1560 1560 1791 0 bitand - -)); +DESCR("bitwise and"); +DATA(insert OID = 1792 ("|" PGNSP PGUID b f f 1560 1560 1560 1792 0 bitor - -)); +DESCR("bitwise or"); +DATA(insert OID = 1793 ("#" PGNSP PGUID b f f 1560 1560 1560 1793 0 bitxor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1794 ("~" PGNSP PGUID l f f 0 1560 1560 0 0 bitnot - -)); +DESCR("bitwise not"); +DATA(insert OID = 1795 ("<<" PGNSP PGUID b f f 1560 23 1560 0 0 bitshiftleft - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1796 (">>" PGNSP PGUID b f f 1560 23 1560 0 0 bitshiftright - -)); +DESCR("bitwise shift right"); +DATA(insert OID = 1797 ("||" PGNSP PGUID b f f 1562 1562 1562 0 0 bitcat - -)); +DESCR("concatenate"); + +DATA(insert OID = 1800 ("+" PGNSP PGUID b f f 1083 1186 1083 1849 0 time_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1801 ("-" PGNSP PGUID b f f 1083 1186 1083 0 0 time_mi_interval - -)); +DESCR("subtract"); +DATA(insert OID = 1802 ("+" PGNSP PGUID b f f 1266 1186 1266 2552 0 timetz_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 1803 ("-" PGNSP PGUID b f f 1266 1186 1266 0 0 timetz_mi_interval - -)); +DESCR("subtract"); + +DATA(insert OID = 1804 ("=" PGNSP PGUID b t f 1562 1562 16 1804 1805 varbiteq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1805 ("<>" PGNSP PGUID b f f 1562 1562 16 1805 1804 varbitne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1806 ("<" PGNSP PGUID b f f 1562 1562 16 1807 1809 varbitlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1807 (">" PGNSP PGUID b f f 1562 1562 16 1806 1808 varbitgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1808 ("<=" PGNSP PGUID b f f 1562 1562 16 1809 1807 varbitle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1809 (">=" PGNSP PGUID b f f 1562 1562 16 1808 1806 varbitge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 1849 ("+" PGNSP PGUID b f f 1186 1083 1083 1800 0 interval_pl_time - -)); +DESCR("add"); + +DATA(insert OID = 1862 ("=" PGNSP PGUID b t t 21 20 16 1868 1863 int28eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT28EQOID 1862 +DATA(insert OID = 1863 ("<>" PGNSP PGUID b f f 21 20 16 1869 1862 int28ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT28NEOID 1863 +DATA(insert OID = 1864 ("<" PGNSP PGUID b f f 21 20 16 1871 1867 int28lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT28LTOID 1864 +DATA(insert OID = 1865 (">" PGNSP PGUID b f f 21 20 16 1870 1866 int28gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT28GTOID 1865 +DATA(insert OID = 1866 ("<=" PGNSP PGUID b f f 21 20 16 1873 1865 int28le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT28LEOID 1866 +DATA(insert OID = 1867 (">=" PGNSP PGUID b f f 21 20 16 1872 1864 int28ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT28GEOID 1867 + +DATA(insert OID = 1868 ("=" PGNSP PGUID b t t 20 21 16 1862 1869 int82eq eqsel eqjoinsel)); +DESCR("equal"); +#define INT82EQOID 1868 +DATA(insert OID = 1869 ("<>" PGNSP PGUID b f f 20 21 16 1863 1868 int82ne neqsel neqjoinsel)); +DESCR("not equal"); +#define INT82NEOID 1869 +DATA(insert OID = 1870 ("<" PGNSP PGUID b f f 20 21 16 1865 1873 int82lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define INT82LTOID 1870 +DATA(insert OID = 1871 (">" PGNSP PGUID b f f 20 21 16 1864 1872 int82gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define INT82GTOID 1871 +DATA(insert OID = 1872 ("<=" PGNSP PGUID b f f 20 21 16 1867 1871 int82le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define INT82LEOID 1872 +DATA(insert OID = 1873 (">=" PGNSP PGUID b f f 20 21 16 1866 1870 int82ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define INT82GEOID 1873 + +DATA(insert OID = 1874 ("&" PGNSP PGUID b f f 21 21 21 1874 0 int2and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1875 ("|" PGNSP PGUID b f f 21 21 21 1875 0 int2or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1876 ("#" PGNSP PGUID b f f 21 21 21 1876 0 int2xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1877 ("~" PGNSP PGUID l f f 0 21 21 0 0 int2not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1878 ("<<" PGNSP PGUID b f f 21 23 21 0 0 int2shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1879 (">>" PGNSP PGUID b f f 21 23 21 0 0 int2shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1880 ("&" PGNSP PGUID b f f 23 23 23 1880 0 int4and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1881 ("|" PGNSP PGUID b f f 23 23 23 1881 0 int4or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1882 ("#" PGNSP PGUID b f f 23 23 23 1882 0 int4xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1883 ("~" PGNSP PGUID l f f 0 23 23 0 0 int4not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1884 ("<<" PGNSP PGUID b f f 23 23 23 0 0 int4shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1885 (">>" PGNSP PGUID b f f 23 23 23 0 0 int4shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1886 ("&" PGNSP PGUID b f f 20 20 20 1886 0 int8and - -)); +DESCR("bitwise and"); +DATA(insert OID = 1887 ("|" PGNSP PGUID b f f 20 20 20 1887 0 int8or - -)); +DESCR("bitwise or"); +DATA(insert OID = 1888 ("#" PGNSP PGUID b f f 20 20 20 1888 0 int8xor - -)); +DESCR("bitwise exclusive or"); +DATA(insert OID = 1889 ("~" PGNSP PGUID l f f 0 20 20 0 0 int8not - -)); +DESCR("bitwise not"); +DATA(insert OID = 1890 ("<<" PGNSP PGUID b f f 20 23 20 0 0 int8shl - -)); +DESCR("bitwise shift left"); +DATA(insert OID = 1891 (">>" PGNSP PGUID b f f 20 23 20 0 0 int8shr - -)); +DESCR("bitwise shift right"); + +DATA(insert OID = 1916 ("+" PGNSP PGUID l f f 0 20 20 0 0 int8up - -)); +DESCR("unary plus"); +DATA(insert OID = 1917 ("+" PGNSP PGUID l f f 0 21 21 0 0 int2up - -)); +DESCR("unary plus"); +DATA(insert OID = 1918 ("+" PGNSP PGUID l f f 0 23 23 0 0 int4up - -)); +DESCR("unary plus"); +DATA(insert OID = 1919 ("+" PGNSP PGUID l f f 0 700 700 0 0 float4up - -)); +DESCR("unary plus"); +DATA(insert OID = 1920 ("+" PGNSP PGUID l f f 0 701 701 0 0 float8up - -)); +DESCR("unary plus"); +DATA(insert OID = 1921 ("+" PGNSP PGUID l f f 0 1700 1700 0 0 numeric_uplus - -)); +DESCR("unary plus"); + +/* bytea operators */ +DATA(insert OID = 1955 ("=" PGNSP PGUID b t t 17 17 16 1955 1956 byteaeq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 1956 ("<>" PGNSP PGUID b f f 17 17 16 1956 1955 byteane neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 1957 ("<" PGNSP PGUID b f f 17 17 16 1959 1960 bytealt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 1958 ("<=" PGNSP PGUID b f f 17 17 16 1960 1959 byteale scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 1959 (">" PGNSP PGUID b f f 17 17 16 1957 1958 byteagt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 1960 (">=" PGNSP PGUID b f f 17 17 16 1958 1957 byteage scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +DATA(insert OID = 2016 ("~~" PGNSP PGUID b f f 17 17 16 0 2017 bytealike likesel likejoinsel)); +DESCR("matches LIKE expression"); +#define OID_BYTEA_LIKE_OP 2016 +DATA(insert OID = 2017 ("!~~" PGNSP PGUID b f f 17 17 16 0 2016 byteanlike nlikesel nlikejoinsel)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 2018 ("||" PGNSP PGUID b f f 17 17 17 0 0 byteacat - -)); +DESCR("concatenate"); + +/* byteawithoutorderwithequalcol operators */ +DATA(insert OID = 4453 ("=" PGNSP PGUID b t t 4402 4402 16 4453 4454 byteawithoutorderwithequalcoleq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4454 ("<>" PGNSP PGUID b f f 4402 4402 16 4454 4453 byteawithoutorderwithequalcolne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 4422 ("=" PGNSP PGUID b f f 4402 17 16 4431 4423 byteawithoutorderwithequalcoleqbytear eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4423 ("<>" PGNSP PGUID b f f 4402 17 16 4432 4422 byteawithoutorderwithequalcolnebytear neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 4431 ("=" PGNSP PGUID b f f 17 4402 16 4422 4432 byteawithoutorderwithequalcoleqbyteal eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 4432 ("<>" PGNSP PGUID b f f 17 4402 16 4423 4431 byteawithoutorderwithequalcolnebyteal neqsel neqjoinsel)); +DESCR("not equal"); + +/* raw operators */ +DATA(insert OID = 3798 ("=" PGNSP PGUID b t t 86 86 16 3798 3799 raweq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3799 ("<>" PGNSP PGUID b f f 86 86 16 3799 3798 rawne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3800 ("<" PGNSP PGUID b f f 86 86 16 3802 3803 rawlt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3801 ("<=" PGNSP PGUID b f f 86 86 16 3803 3802 rawle scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3802 (">" PGNSP PGUID b f f 86 86 16 3800 3801 rawgt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3803 (">=" PGNSP PGUID b f f 86 86 16 3801 3800 rawge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3804 ("~~" PGNSP PGUID b f f 86 86 16 0 3805 rawlike likesel likejoinsel)); +DESCR("matches like expression"); +#define OID_RAW_LIKE_OP 3804 +DATA(insert OID = 3805 ("!~~" PGNSP PGUID b f f 86 86 16 0 3804 rawnlike nlikesel nlikejoinsel)); +DESCR("does not match like expression"); + +/* timestamp operators */ +DATA(insert OID = 2060 ("=" PGNSP PGUID b t t 1114 1114 16 2060 2061 timestamp_eq eqsel eqjoinsel)); +DESCR("equal"); +#define TIMESTAMPEQOID 2060 +DATA(insert OID = 2061 ("<>" PGNSP PGUID b f f 1114 1114 16 2061 2060 timestamp_ne neqsel neqjoinsel)); +DESCR("not equal"); +#define TIMESTAMPNEOID 2061 +DATA(insert OID = 2062 ("<" PGNSP PGUID b f f 1114 1114 16 2064 2065 timestamp_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define TIMESTAMPLTOID 2062 +DATA(insert OID = 2063 ("<=" PGNSP PGUID b f f 1114 1114 16 2065 2064 timestamp_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +#define TIMESTAMPLEOID 2063 +DATA(insert OID = 2064 (">" PGNSP PGUID b f f 1114 1114 16 2062 2063 timestamp_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define TIMESTAMPGTOID 2064 +DATA(insert OID = 2065 (">=" PGNSP PGUID b f f 1114 1114 16 2063 2062 timestamp_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +#define TIMESTAMPGEOID 2065 +DATA(insert OID = 2066 ("+" PGNSP PGUID b f f 1114 1186 1114 2553 0 timestamp_pl_interval - -)); +DESCR("add"); +DATA(insert OID = 2067 ("-" PGNSP PGUID b f f 1114 1114 1186 0 0 timestamp_mi - -)); +DESCR("subtract"); +DATA(insert OID = 2068 ("-" PGNSP PGUID b f f 1114 1186 1114 0 0 timestamp_mi_interval - -)); +DESCR("subtract"); + +/* character-by-character (not collation order) comparison operators for character types */ +DATA(insert OID = 2314 ("~<~" PGNSP PGUID b f f 25 25 16 2318 2317 text_pattern_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2315 ("~<=~" PGNSP PGUID b f f 25 25 16 2317 2318 text_pattern_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2317 ("~>=~" PGNSP PGUID b f f 25 25 16 2315 2314 text_pattern_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2318 ("~>~" PGNSP PGUID b f f 25 25 16 2314 2315 text_pattern_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); + +DATA(insert OID = 2326 ("~<~" PGNSP PGUID b f f 1042 1042 16 2330 2329 bpchar_pattern_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2327 ("~<=~" PGNSP PGUID b f f 1042 1042 16 2329 2330 bpchar_pattern_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2329 ("~>=~" PGNSP PGUID b f f 1042 1042 16 2327 2326 bpchar_pattern_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2330 ("~>~" PGNSP PGUID b f f 1042 1042 16 2326 2327 bpchar_pattern_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); + +/* crosstype operations for date vs. timestamp and timestamptz */ +DATA(insert OID = 2345 ("<" PGNSP PGUID b f f 1082 1114 16 2375 2348 date_lt_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2346 ("<=" PGNSP PGUID b f f 1082 1114 16 2374 2349 date_le_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2347 ("=" PGNSP PGUID b t f 1082 1114 16 2373 2350 date_eq_timestamp eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2348 (">=" PGNSP PGUID b f f 1082 1114 16 2372 2345 date_ge_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2349 (">" PGNSP PGUID b f f 1082 1114 16 2371 2346 date_gt_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2350 ("<>" PGNSP PGUID b f f 1082 1114 16 2376 2347 date_ne_timestamp neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2358 ("<" PGNSP PGUID b f f 1082 1184 16 2388 2361 date_lt_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2359 ("<=" PGNSP PGUID b f f 1082 1184 16 2387 2362 date_le_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2360 ("=" PGNSP PGUID b t f 1082 1184 16 2386 2363 date_eq_timestamptz eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2361 (">=" PGNSP PGUID b f f 1082 1184 16 2385 2358 date_ge_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2362 (">" PGNSP PGUID b f f 1082 1184 16 2384 2359 date_gt_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2363 ("<>" PGNSP PGUID b f f 1082 1184 16 2389 2360 date_ne_timestamptz neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2371 ("<" PGNSP PGUID b f f 1114 1082 16 2349 2374 timestamp_lt_date scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2372 ("<=" PGNSP PGUID b f f 1114 1082 16 2348 2375 timestamp_le_date scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2373 ("=" PGNSP PGUID b t f 1114 1082 16 2347 2376 timestamp_eq_date eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2374 (">=" PGNSP PGUID b f f 1114 1082 16 2346 2371 timestamp_ge_date scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2375 (">" PGNSP PGUID b f f 1114 1082 16 2345 2372 timestamp_gt_date scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2376 ("<>" PGNSP PGUID b f f 1114 1082 16 2350 2373 timestamp_ne_date neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2384 ("<" PGNSP PGUID b f f 1184 1082 16 2362 2387 timestamptz_lt_date scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2385 ("<=" PGNSP PGUID b f f 1184 1082 16 2361 2388 timestamptz_le_date scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2386 ("=" PGNSP PGUID b t f 1184 1082 16 2360 2389 timestamptz_eq_date eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2387 (">=" PGNSP PGUID b f f 1184 1082 16 2359 2384 timestamptz_ge_date scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2388 (">" PGNSP PGUID b f f 1184 1082 16 2358 2385 timestamptz_gt_date scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2389 ("<>" PGNSP PGUID b f f 1184 1082 16 2363 2386 timestamptz_ne_date neqsel neqjoinsel)); +DESCR("not equal"); + +/* crosstype operations for timestamp vs. timestamptz */ +DATA(insert OID = 2534 ("<" PGNSP PGUID b f f 1114 1184 16 2544 2537 timestamp_lt_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2535 ("<=" PGNSP PGUID b f f 1114 1184 16 2543 2538 timestamp_le_timestamptz scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2536 ("=" PGNSP PGUID b t f 1114 1184 16 2542 2539 timestamp_eq_timestamptz eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2537 (">=" PGNSP PGUID b f f 1114 1184 16 2541 2534 timestamp_ge_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2538 (">" PGNSP PGUID b f f 1114 1184 16 2540 2535 timestamp_gt_timestamptz scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2539 ("<>" PGNSP PGUID b f f 1114 1184 16 2545 2536 timestamp_ne_timestamptz neqsel neqjoinsel)); +DESCR("not equal"); + +DATA(insert OID = 2540 ("<" PGNSP PGUID b f f 1184 1114 16 2538 2543 timestamptz_lt_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2541 ("<=" PGNSP PGUID b f f 1184 1114 16 2537 2544 timestamptz_le_timestamp scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2542 ("=" PGNSP PGUID b t f 1184 1114 16 2536 2545 timestamptz_eq_timestamp eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2543 (">=" PGNSP PGUID b f f 1184 1114 16 2535 2540 timestamptz_ge_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 2544 (">" PGNSP PGUID b f f 1184 1114 16 2534 2541 timestamptz_gt_timestamp scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2545 ("<>" PGNSP PGUID b f f 1184 1114 16 2539 2542 timestamptz_ne_timestamp neqsel neqjoinsel)); +DESCR("not equal"); + +/* formerly-missing interval + datetime operators */ +DATA(insert OID = 2551 ("+" PGNSP PGUID b f f 1186 1082 1114 1076 0 interval_pl_date - -)); +DESCR("add"); +DATA(insert OID = 2552 ("+" PGNSP PGUID b f f 1186 1266 1266 1802 0 interval_pl_timetz - -)); +DESCR("add"); +DATA(insert OID = 2553 ("+" PGNSP PGUID b f f 1186 1114 1114 2066 0 interval_pl_timestamp - -)); +DESCR("add"); +DATA(insert OID = 2554 ("+" PGNSP PGUID b f f 1186 1184 1184 1327 0 interval_pl_timestamptz - -)); +DESCR("add"); +DATA(insert OID = 2555 ("+" PGNSP PGUID b f f 23 1082 1082 1100 0 integer_pl_date - -)); +DESCR("add"); + +/* new operators for Y-direction rtree opfamilies */ +DATA(insert OID = 2570 ("<<|" PGNSP PGUID b f f 603 603 16 0 0 box_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 2571 ("&<|" PGNSP PGUID b f f 603 603 16 0 0 box_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2572 ("|&>" PGNSP PGUID b f f 603 603 16 0 0 box_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); +DATA(insert OID = 2573 ("|>>" PGNSP PGUID b f f 603 603 16 0 0 box_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 2574 ("<<|" PGNSP PGUID b f f 604 604 16 0 0 poly_below positionsel positionjoinsel)); +DESCR("is below"); +DATA(insert OID = 2575 ("&<|" PGNSP PGUID b f f 604 604 16 0 0 poly_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2576 ("|&>" PGNSP PGUID b f f 604 604 16 0 0 poly_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); +DATA(insert OID = 2577 ("|>>" PGNSP PGUID b f f 604 604 16 0 0 poly_above positionsel positionjoinsel)); +DESCR("is above"); +DATA(insert OID = 2589 ("&<|" PGNSP PGUID b f f 718 718 16 0 0 circle_overbelow positionsel positionjoinsel)); +DESCR("overlaps or is below"); +DATA(insert OID = 2590 ("|&>" PGNSP PGUID b f f 718 718 16 0 0 circle_overabove positionsel positionjoinsel)); +DESCR("overlaps or is above"); + +/* overlap/contains/contained for arrays */ +DATA(insert OID = 2750 ("&&" PGNSP PGUID b f f 2277 2277 16 2750 0 arrayoverlap arraycontsel arraycontjoinsel)); +DESCR("overlaps"); +#define OID_ARRAY_OVERLAP_OP 2750 +DATA(insert OID = 2751 ("@>" PGNSP PGUID b f f 2277 2277 16 2752 0 arraycontains arraycontsel arraycontjoinsel)); +DESCR("contains"); +#define OID_ARRAY_CONTAINS_OP 2751 +DATA(insert OID = 2752 ("<@" PGNSP PGUID b f f 2277 2277 16 2751 0 arraycontained arraycontsel arraycontjoinsel)); +DESCR("is contained by"); +#define OID_ARRAY_CONTAINED_OP 2752 + +/* capturing operators to preserve pre-8.3 behavior of text concatenation */ +DATA(insert OID = 2779 ("||" PGNSP PGUID b f f 25 2776 25 0 0 textanycat - -)); +DESCR("concatenate"); +DATA(insert OID = 2780 ("||" PGNSP PGUID b f f 2776 25 25 0 0 anytextcat - -)); +DESCR("concatenate"); + +/* obsolete names for contains/contained-by operators; remove these someday */ +DATA(insert OID = 2860 ("@" PGNSP PGUID b f f 604 604 16 2861 0 poly_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2861 ("~" PGNSP PGUID b f f 604 604 16 2860 0 poly_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2862 ("@" PGNSP PGUID b f f 603 603 16 2863 0 box_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2863 ("~" PGNSP PGUID b f f 603 603 16 2862 0 box_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2864 ("@" PGNSP PGUID b f f 718 718 16 2865 0 circle_contained contsel contjoinsel)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2865 ("~" PGNSP PGUID b f f 718 718 16 2864 0 circle_contain contsel contjoinsel)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2866 ("@" PGNSP PGUID b f f 600 603 16 0 0 on_pb - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2867 ("@" PGNSP PGUID b f f 600 602 16 2868 0 on_ppath - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2868 ("~" PGNSP PGUID b f f 602 600 16 2867 0 path_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2869 ("@" PGNSP PGUID b f f 600 604 16 2870 0 pt_contained_poly - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2870 ("~" PGNSP PGUID b f f 604 600 16 2869 0 poly_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2871 ("@" PGNSP PGUID b f f 600 718 16 2872 0 pt_contained_circle - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2872 ("~" PGNSP PGUID b f f 718 600 16 2871 0 circle_contain_pt - -)); +DESCR("deprecated, use @> instead"); +DATA(insert OID = 2873 ("@" PGNSP PGUID b f f 600 628 16 0 0 on_pl - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2874 ("@" PGNSP PGUID b f f 600 601 16 0 0 on_ps - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2875 ("@" PGNSP PGUID b f f 601 628 16 0 0 on_sl - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2876 ("@" PGNSP PGUID b f f 601 603 16 0 0 on_sb - -)); +DESCR("deprecated, use <@ instead"); +DATA(insert OID = 2877 ("~" PGNSP PGUID b f f 1034 1033 16 0 0 aclcontains - -)); +DESCR("deprecated, use @> instead"); + +/* uuid operators */ +DATA(insert OID = 2972 ("=" PGNSP PGUID b t t 2950 2950 16 2972 2973 uuid_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 2973 ("<>" PGNSP PGUID b f f 2950 2950 16 2973 2972 uuid_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2974 ("<" PGNSP PGUID b f f 2950 2950 16 2975 2977 uuid_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 2975 (">" PGNSP PGUID b f f 2950 2950 16 2974 2976 uuid_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 2976 ("<=" PGNSP PGUID b f f 2950 2950 16 2977 2975 uuid_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2977 (">=" PGNSP PGUID b f f 2950 2950 16 2976 2974 uuid_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* enum operators */ +DATA(insert OID = 3516 ("=" PGNSP PGUID b t t 3500 3500 16 3516 3517 enum_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3517 ("<>" PGNSP PGUID b f f 3500 3500 16 3517 3516 enum_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3518 ("<" PGNSP PGUID b f f 3500 3500 16 3519 3521 enum_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3519 (">" PGNSP PGUID b f f 3500 3500 16 3518 3520 enum_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3520 ("<=" PGNSP PGUID b f f 3500 3500 16 3521 3519 enum_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3521 (">=" PGNSP PGUID b f f 3500 3500 16 3520 3518 enum_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* + * tsearch operations + */ +DATA(insert OID = 3627 ("<" PGNSP PGUID b f f 3614 3614 16 3632 3631 tsvector_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3628 ("<=" PGNSP PGUID b f f 3614 3614 16 3631 3632 tsvector_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3629 ("=" PGNSP PGUID b t f 3614 3614 16 3629 3630 tsvector_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3630 ("<>" PGNSP PGUID b f f 3614 3614 16 3630 3629 tsvector_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3631 (">=" PGNSP PGUID b f f 3614 3614 16 3628 3627 tsvector_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3632 (">" PGNSP PGUID b f f 3614 3614 16 3627 3628 tsvector_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3633 ("||" PGNSP PGUID b f f 3614 3614 3614 0 0 tsvector_concat - -)); +DESCR("concatenate"); +DATA(insert OID = 3636 ("@@" PGNSP PGUID b f f 3614 3615 16 3637 0 ts_match_vq tsmatchsel tsmatchjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3637 ("@@" PGNSP PGUID b f f 3615 3614 16 3636 0 ts_match_qv tsmatchsel tsmatchjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3660 ("@@@" PGNSP PGUID b f f 3614 3615 16 3661 0 ts_match_vq tsmatchsel tsmatchjoinsel)); +DESCR("deprecated, use @@ instead"); +DATA(insert OID = 3661 ("@@@" PGNSP PGUID b f f 3615 3614 16 3660 0 ts_match_qv tsmatchsel tsmatchjoinsel)); +DESCR("deprecated, use @@ instead"); +DATA(insert OID = 3674 ("<" PGNSP PGUID b f f 3615 3615 16 3679 3678 tsquery_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3675 ("<=" PGNSP PGUID b f f 3615 3615 16 3678 3679 tsquery_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3676 ("=" PGNSP PGUID b t f 3615 3615 16 3676 3677 tsquery_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3677 ("<>" PGNSP PGUID b f f 3615 3615 16 3677 3676 tsquery_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3678 (">=" PGNSP PGUID b f f 3615 3615 16 3675 3674 tsquery_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3679 (">" PGNSP PGUID b f f 3615 3615 16 3674 3675 tsquery_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3680 ("&&" PGNSP PGUID b f f 3615 3615 3615 0 0 tsquery_and - -)); +DESCR("AND-concatenate"); +DATA(insert OID = 3681 ("||" PGNSP PGUID b f f 3615 3615 3615 0 0 tsquery_or - -)); +DESCR("OR-concatenate"); +DATA(insert OID = 3682 ("!!" PGNSP PGUID l f f 0 3615 3615 0 0 tsquery_not - -)); +DESCR("NOT tsquery"); +DATA(insert OID = 3693 ("@>" PGNSP PGUID b f f 3615 3615 16 3694 0 tsq_mcontains contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3694 ("<@" PGNSP PGUID b f f 3615 3615 16 3693 0 tsq_mcontained contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3762 ("@@" PGNSP PGUID b f f 25 25 16 0 0 ts_match_tt contsel contjoinsel)); +DESCR("text search match"); +DATA(insert OID = 3763 ("@@" PGNSP PGUID b f f 25 3615 16 0 0 ts_match_tq contsel contjoinsel)); +DESCR("text search match"); + +/* generic record comparison operators */ +DATA(insert OID = 2988 ("=" PGNSP PGUID b t f 2249 2249 16 2988 2989 record_eq eqsel eqjoinsel)); +DESCR("equal"); +#define RECORD_EQ_OP 2988 +DATA(insert OID = 2989 ("<>" PGNSP PGUID b f f 2249 2249 16 2989 2988 record_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 2990 ("<" PGNSP PGUID b f f 2249 2249 16 2991 2993 record_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +#define RECORD_LT_OP 2990 +DATA(insert OID = 2991 (">" PGNSP PGUID b f f 2249 2249 16 2990 2992 record_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +#define RECORD_GT_OP 2991 +DATA(insert OID = 2992 ("<=" PGNSP PGUID b f f 2249 2249 16 2993 2991 record_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 2993 (">=" PGNSP PGUID b f f 2249 2249 16 2992 2990 record_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* generic range type operators */ +DATA(insert OID = 3882 ("=" PGNSP PGUID b t t 3831 3831 16 3882 3883 range_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 3883 ("<>" PGNSP PGUID b f f 3831 3831 16 3883 3882 range_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 3884 ("<" PGNSP PGUID b f f 3831 3831 16 3887 3886 range_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 3885 ("<=" PGNSP PGUID b f f 3831 3831 16 3886 3887 range_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 3886 (">=" PGNSP PGUID b f f 3831 3831 16 3885 3884 range_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); +DATA(insert OID = 3887 (">" PGNSP PGUID b f f 3831 3831 16 3884 3885 range_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 3888 ("&&" PGNSP PGUID b f f 3831 3831 16 3888 0 range_overlaps areasel areajoinsel)); +DESCR("overlaps"); +DATA(insert OID = 3889 ("@>" PGNSP PGUID b f f 3831 2283 16 3891 0 range_contains_elem contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3890 ("@>" PGNSP PGUID b f f 3831 3831 16 3892 0 range_contains contsel contjoinsel)); +DESCR("contains"); +DATA(insert OID = 3891 ("<@" PGNSP PGUID b f f 2283 3831 16 3889 0 elem_contained_by_range contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3892 ("<@" PGNSP PGUID b f f 3831 3831 16 3890 0 range_contained_by contsel contjoinsel)); +DESCR("is contained by"); +DATA(insert OID = 3893 ("<<" PGNSP PGUID b f f 3831 3831 16 3894 0 range_before scalarltsel scalarltjoinsel)); +DESCR("is left of"); +DATA(insert OID = 3894 (">>" PGNSP PGUID b f f 3831 3831 16 3893 0 range_after scalargtsel scalargtjoinsel)); +DESCR("is right of"); +DATA(insert OID = 3895 ("&<" PGNSP PGUID b f f 3831 3831 16 0 0 range_overleft scalarltsel scalarltjoinsel)); +DESCR("overlaps or is left of"); +DATA(insert OID = 3896 ("&>" PGNSP PGUID b f f 3831 3831 16 0 0 range_overright scalargtsel scalargtjoinsel)); +DESCR("overlaps or is right of"); +DATA(insert OID = 3897 ("-|-" PGNSP PGUID b f f 3831 3831 16 3897 0 range_adjacent contsel contjoinsel)); +DESCR("is adjacent to"); +DATA(insert OID = 3898 ("+" PGNSP PGUID b f f 3831 3831 3831 3898 0 range_union - -)); +DESCR("range union"); +DATA(insert OID = 3899 ("-" PGNSP PGUID b f f 3831 3831 3831 0 0 range_minus - -)); +DESCR("range difference"); +DATA(insert OID = 3900 ("*" PGNSP PGUID b f f 3831 3831 3831 3900 0 range_intersect - -)); +DESCR("range intersection"); +DATA(insert OID = 5550 ("=" PGNSP PGUID b t t 9003 9003 16 5550 5551 smalldatetime_eq eqsel eqjoinsel)); +DESCR("equal"); +DATA(insert OID = 5551 ("<>" PGNSP PGUID b f f 9003 9003 16 5551 5550 smalldatetime_ne neqsel neqjoinsel)); +DESCR("not equal"); +DATA(insert OID = 5552 ("<" PGNSP PGUID b f f 9003 9003 16 5554 5549 smalldatetime_lt scalarltsel scalarltjoinsel)); +DESCR("less than"); +DATA(insert OID = 5553 ("<=" PGNSP PGUID b f f 9003 9003 16 5549 5554 smalldatetime_le scalarltsel scalarltjoinsel)); +DESCR("less than or equal"); +DATA(insert OID = 5554 (">" PGNSP PGUID b f f 9003 9003 16 5552 5553 smalldatetime_gt scalargtsel scalargtjoinsel)); +DESCR("greater than"); +DATA(insert OID = 5549 (">=" PGNSP PGUID b f f 9003 9003 16 5553 5552 smalldatetime_ge scalargtsel scalargtjoinsel)); +DESCR("greater than or equal"); + +/* hll */ +DATA(insert OID = 4372 ( "=" PGNSP PGUID b f f 4301 4301 16 4372 4373 hll_eq eqsel eqjoinsel )); +DESCR("hyper log log equal op"); +DATA(insert OID = 4373 ( "<>" PGNSP PGUID b f f 4301 4301 16 4373 4372 hll_ne neqsel neqjoinsel )); +DESCR("hyper log log not equal op"); +DATA(insert OID = 4374 ( "||" PGNSP PGUID b f f 4301 4301 4301 0 0 hll_union - - )); +DESCR("hyper log log union op"); +DATA(insert OID = 4375 ( "||" PGNSP PGUID b f f 4301 4303 4301 0 0 hll_add - - )); +DESCR("hyper log log add op"); +DATA(insert OID = 4376 ( "||" PGNSP PGUID b f f 4303 4301 4301 0 0 hll_add_rev - - )); +DESCR("hyper log log add rev op"); +DATA(insert OID = 4377 ( "#" PGNSP PGUID l f f 0 4301 701 0 0 hll_cardinality - - )); +DESCR("hyper log log cardinality op"); +DATA(insert OID = 4378 ( "=" PGNSP PGUID b f f 4303 4303 16 4378 4379 hll_hashval_eq eqsel eqjoinsel )); +DESCR("hyper log log equal hashval op"); +DATA(insert OID = 4379 ( "<>" PGNSP PGUID b f f 4303 4303 16 4379 4378 hll_hashval_ne neqsel neqjoinsel )); +DESCR("hyper log log not equal hashval op"); +/* + * function prototypes + */ +extern void OperatorCreate(const char *operatorName, Oid operatorNamespace, Oid leftTypeId, Oid rightTypeId, Oid procedureId, + List *commutatorName, List *negatorName, Oid restrictionId, Oid joinId, bool canMerge, bool canHash); + +extern Oid OperatorGet(const char *operatorName, Oid operatorNamespace, Oid leftObjectId, Oid rightObjectId, bool *defined); + +#endif /* PG_OPERATOR_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_opfamily.h postgresql-hll-2.14/include/include/catalog/pg_opfamily.h --- postgresql-hll-2.14_old/include/include/catalog/pg_opfamily.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_opfamily.h 2020-12-12 17:06:43.158346890 +0800 @@ -0,0 +1,197 @@ +/* ------------------------------------------------------------------------- + * + * pg_opfamily.h + * definition of the system "opfamily" relation (pg_opfamily) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_opfamily.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_OPFAMILY_H +#define PG_OPFAMILY_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_opfamily definition. cpp turns this into + * typedef struct FormData_pg_opfamily + * ---------------- + */ +#define OperatorFamilyRelationId 2753 +#define OperatorFamilyRelation_Rowtype_Id 10005 + +CATALOG(pg_opfamily,2753) BKI_SCHEMA_MACRO +{ + Oid opfmethod; /* index access method opfamily is for */ + NameData opfname; /* name of this opfamily */ + Oid opfnamespace; /* namespace of this opfamily */ + Oid opfowner; /* opfamily owner */ +} FormData_pg_opfamily; + +/* ---------------- + * Form_pg_opfamily corresponds to a pointer to a tuple with + * the format of pg_opfamily relation. + * ---------------- + */ +typedef FormData_pg_opfamily *Form_pg_opfamily; + +/* ---------------- + * compiler constants for pg_opfamily + * ---------------- + */ +#define Natts_pg_opfamily 4 +#define Anum_pg_opfamily_opfmethod 1 +#define Anum_pg_opfamily_opfname 2 +#define Anum_pg_opfamily_opfnamespace 3 +#define Anum_pg_opfamily_opfowner 4 + +/* ---------------- + * initial contents of pg_opfamily + * ---------------- + */ +DATA(insert OID = 421 (403 abstime_ops PGNSP PGUID)); +DATA(insert OID = 397 (403 array_ops PGNSP PGUID)); +DATA(insert OID = 627 (405 array_ops PGNSP PGUID)); +DATA(insert OID = 423 (403 bit_ops PGNSP PGUID)); +DATA(insert OID = 424 (403 bool_ops PGNSP PGUID)); +#define BOOL_BTREE_FAM_OID 424 +DATA(insert OID = 426 (403 bpchar_ops PGNSP PGUID)); +#define BPCHAR_BTREE_FAM_OID 426 +DATA(insert OID = 427 (405 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 428 (403 bytea_ops PGNSP PGUID)); +#define BYTEA_BTREE_FAM_OID 428 +DATA(insert OID = 436 (403 byteawithoutorderwithequalcol_ops PGNSP PGUID)); +#define ENCRYPTEDCOL_BTREE_FAM_OID 436 +DATA(insert OID = 429 (403 char_ops PGNSP PGUID)); +DATA(insert OID = 431 (405 char_ops PGNSP PGUID)); +DATA(insert OID = 434 (403 datetime_ops PGNSP PGUID)); +DATA(insert OID = 435 (405 date_ops PGNSP PGUID)); +DATA(insert OID = 1970 (403 float_ops PGNSP PGUID)); +DATA(insert OID = 1971 (405 float_ops PGNSP PGUID)); +DATA(insert OID = 1974 (403 network_ops PGNSP PGUID)); +#define NETWORK_BTREE_FAM_OID 1974 +DATA(insert OID = 1975 (405 network_ops PGNSP PGUID)); +DATA(insert OID = 1976 (403 integer_ops PGNSP PGUID)); +#define INTEGER_BTREE_FAM_OID 1976 +DATA(insert OID = 1977 (405 integer_ops PGNSP PGUID)); +DATA(insert OID = 1982 (403 interval_ops PGNSP PGUID)); +DATA(insert OID = 1983 (405 interval_ops PGNSP PGUID)); +DATA(insert OID = 1984 (403 macaddr_ops PGNSP PGUID)); +DATA(insert OID = 1985 (405 macaddr_ops PGNSP PGUID)); +DATA(insert OID = 1986 (403 name_ops PGNSP PGUID)); +#define NAME_BTREE_FAM_OID 1986 +DATA(insert OID = 1987 (405 name_ops PGNSP PGUID)); +DATA(insert OID = 1988 (403 numeric_ops PGNSP PGUID)); +DATA(insert OID = 1998 (405 numeric_ops PGNSP PGUID)); +DATA(insert OID = 1989 (403 oid_ops PGNSP PGUID)); +#define OID_BTREE_FAM_OID 1989 +DATA(insert OID = 1990 (405 oid_ops PGNSP PGUID)); +DATA(insert OID = 1991 (403 oidvector_ops PGNSP PGUID)); +DATA(insert OID = 1992 (405 oidvector_ops PGNSP PGUID)); +DATA(insert OID = 2994 (403 record_ops PGNSP PGUID)); +DATA(insert OID = 1994 (403 text_ops PGNSP PGUID)); +#define TEXT_BTREE_FAM_OID 1994 +DATA(insert OID = 1995 (405 text_ops PGNSP PGUID)); +DATA(insert OID = 1996 (403 time_ops PGNSP PGUID)); +DATA(insert OID = 1997 (405 time_ops PGNSP PGUID)); +DATA(insert OID = 1999 (405 timestamptz_ops PGNSP PGUID)); +DATA(insert OID = 2000 (403 timetz_ops PGNSP PGUID)); +DATA(insert OID = 2001 (405 timetz_ops PGNSP PGUID)); +DATA(insert OID = 2002 (403 varbit_ops PGNSP PGUID)); +DATA(insert OID = 2040 (405 timestamp_ops PGNSP PGUID)); +DATA(insert OID = 2095 (403 text_pattern_ops PGNSP PGUID)); +#define TEXT_PATTERN_BTREE_FAM_OID 2095 +DATA(insert OID = 2097 (403 bpchar_pattern_ops PGNSP PGUID)); +#define BPCHAR_PATTERN_BTREE_FAM_OID 2097 +DATA(insert OID = 2099 (403 money_ops PGNSP PGUID)); +DATA(insert OID = 2222 (405 bool_ops PGNSP PGUID)); +#define BOOL_HASH_FAM_OID 2222 +DATA(insert OID = 2223 (405 bytea_ops PGNSP PGUID)); +DATA(insert OID = 4470 (405 byteawithoutorderwithequalcol_ops PGNSP PGUID )); +DATA(insert OID = 2224 (405 int2vector_ops PGNSP PGUID)); +DATA(insert OID = 2789 (403 tid_ops PGNSP PGUID)); +DATA(insert OID = 2225 (405 xid_ops PGNSP PGUID)); +DATA(insert OID = 2232 (405 xid32_ops PGNSP PGUID)); +DATA(insert OID = 2226 (405 cid_ops PGNSP PGUID)); +DATA(insert OID = 2227 (405 abstime_ops PGNSP PGUID)); +DATA(insert OID = 2228 (405 reltime_ops PGNSP PGUID)); +DATA(insert OID = 2229 (405 text_pattern_ops PGNSP PGUID)); +DATA(insert OID = 2231 (405 bpchar_pattern_ops PGNSP PGUID)); +DATA(insert OID = 2233 (403 reltime_ops PGNSP PGUID)); +DATA(insert OID = 2234 (403 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 2235 (405 aclitem_ops PGNSP PGUID)); +DATA(insert OID = 2593 (783 box_ops PGNSP PGUID)); +DATA(insert OID = 2594 (783 poly_ops PGNSP PGUID)); +DATA(insert OID = 2595 (783 circle_ops PGNSP PGUID)); +DATA(insert OID = 1029 (783 point_ops PGNSP PGUID)); +DATA(insert OID = 2745 (2742 array_ops PGNSP PGUID)); +DATA(insert OID = 2968 (403 uuid_ops PGNSP PGUID)); +DATA(insert OID = 2969 (405 uuid_ops PGNSP PGUID)); +DATA(insert OID = 3522 (403 enum_ops PGNSP PGUID)); +DATA(insert OID = 3523 (405 enum_ops PGNSP PGUID)); +DATA(insert OID = 3626 (403 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3655 (783 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3659 (2742 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 4446 (4444 tsvector_ops PGNSP PGUID)); +DATA(insert OID = 3683 (403 tsquery_ops PGNSP PGUID)); +DATA(insert OID = 3702 (783 tsquery_ops PGNSP PGUID)); +DATA(insert OID = 3901 (403 range_ops PGNSP PGUID)); +DATA(insert OID = 3903 (405 range_ops PGNSP PGUID)); +DATA(insert OID = 3919 (783 range_ops PGNSP PGUID)); +DATA(insert OID = 4015 (4000 quad_point_ops PGNSP PGUID)); +DATA(insert OID = 4016 (4000 kd_point_ops PGNSP PGUID)); +DATA(insert OID = 4017 (4000 text_ops PGNSP PGUID)); +#define TEXT_SPGIST_FAM_OID 4017 + +DATA(insert OID = 3806 (403 raw_ops PGNSP PGUID)); +DATA(insert OID = 3807 (405 raw_ops PGNSP PGUID)); +DATA(insert OID = 5535 (403 int1_ops PGNSP PGUID)); +DATA(insert OID = 5536 (405 int1_ops PGNSP PGUID)); +DATA(insert OID = 5570 (403 smalldatetime_ops PGNSP PGUID)); +DATA(insert OID = 5571 (405 smalldatetime_ops PGNSP PGUID)); + +/* psort index, fake data just make index work */ +DATA(insert OID = 4050 (4039 integer_ops PGNSP PGUID)); +DATA(insert OID = 4051 (4039 oid_ops PGNSP PGUID)); +DATA(insert OID = 4052 (4039 datetime_ops PGNSP PGUID)); +DATA(insert OID = 4053 (4039 float_ops PGNSP PGUID)); +DATA(insert OID = 4054 (4039 numeric_ops PGNSP PGUID)); +DATA(insert OID = 4055 (4039 text_ops PGNSP PGUID)); +DATA(insert OID = 4056 (4039 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 4057 (4039 time_ops PGNSP PGUID)); +DATA(insert OID = 4058 (4039 timetz_ops PGNSP PGUID)); +DATA(insert OID = 4059 (4039 money_ops PGNSP PGUID)); +DATA(insert OID = 4060 (4039 interval_ops PGNSP PGUID)); +DATA(insert OID = 4061 (4039 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 4062 (4039 int1_ops PGNSP PGUID)); +DATA(insert OID = 4063 (4039 bool_ops PGNSP PGUID)); +DATA(insert OID = 4064 (4039 smalldatetime_ops PGNSP PGUID)); + +/* cbtree index, fake data just make index work */ +DATA(insert OID = 4250 (4239 integer_ops PGNSP PGUID)); +DATA(insert OID = 4251 (4239 oid_ops PGNSP PGUID)); +DATA(insert OID = 4252 (4239 datetime_ops PGNSP PGUID)); +DATA(insert OID = 4253 (4239 float_ops PGNSP PGUID)); +DATA(insert OID = 4254 (4239 numeric_ops PGNSP PGUID)); +DATA(insert OID = 4255 (4239 text_ops PGNSP PGUID)); +DATA(insert OID = 4256 (4239 bpchar_ops PGNSP PGUID)); +DATA(insert OID = 4257 (4239 time_ops PGNSP PGUID)); +DATA(insert OID = 4258 (4239 timetz_ops PGNSP PGUID)); +DATA(insert OID = 4259 (4239 money_ops PGNSP PGUID)); +DATA(insert OID = 4260 (4239 interval_ops PGNSP PGUID)); +DATA(insert OID = 4261 (4239 tinterval_ops PGNSP PGUID)); +DATA(insert OID = 4262 (4239 int1_ops PGNSP PGUID)); +DATA(insert OID = 4263 (4239 bool_ops PGNSP PGUID)); +DATA(insert OID = 4264 (4239 smalldatetime_ops PGNSP PGUID)); + +#endif /* PG_OPFAMILY_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_partition_fn.h postgresql-hll-2.14/include/include/catalog/pg_partition_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_partition_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_partition_fn.h 2020-12-12 17:06:43.158346890 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_partition_fn.h + * + * + * + * IDENTIFICATION + * src/include/catalog/pg_partition_fn.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_PARTITION_FN_H +#define PG_PARTITION_FN_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/indexing.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/array.h" +#include "utils/builtins.h" +#include "nodes/pg_list.h" +#include "access/htup.h" +#include "storage/lock.h" +#include "access/heapam.h" + +#define MAX_PARTITIONKEY_NUM 4 +#define MAX_PARTITION_NUM 32767 /* update LEN_PARTITION_PREFIX as well ! */ +#define MAX_LH_PARTITION_NUM 64 /* update LEN_LIST/HASH_PARTITION_PREFIX as well ! */ +#define INTERVAL_PARTITION_NAME_PREFIX "sys_p" +#define INTERVAL_PARTITION_NAME_PREFIX_FMT "sys_p%u" +#define INTERVAL_PARTITION_NAME_SUFFIX_LEN 5 /* max length of partitio num */ + +/* + * In start/end syntax, partition name is of form: + * PARTITION_PREFIX_NUM, + * so length of the name prefix must be restricted to: + * NAMEDATALEN (64) - 1 - LENGTH ( "MAX_PARTITION_NUM" ) - 1 + * NOTICE: please update LEN_PARTITION_PREFIX if you modify macro MAX_PARTITION_NUM + */ +#define LEN_PARTITION_PREFIX 57 + +/* + * A suppositional sequence number for partition. + */ +#define ADD_PARTITION_ACTION (MAX_PARTITION_NUM + 1) + +/* + * We acquire a AccessExclusiveLock on ADD_PARTITION_ACTION before we decide + * to add an interval partition to prevent parallel complaints. + */ +#define lockRelationForAddIntervalPartition(relation) \ + LockPartition(RelationGetRelid(relation), ADD_PARTITION_ACTION, \ + AccessExclusiveLock, PARTITION_SEQUENCE_LOCK); + +#define unLockRelationForAddIntervalPartition(relation) \ + UnlockPartition(RelationGetRelid(relation), ADD_PARTITION_ACTION, \ + AccessExclusiveLock, PARTITION_SEQUENCE_LOCK); + +typedef void (*PartitionNameGetPartidCallback) (Oid partitioned_relation, const char *partition_name, Oid partId, + Oid oldPartId, char partition_type, void *callback_arg, LOCKMODE callbackobj_lockMode); +extern void insertPartitionEntry(Relation pg_partition_desc, Partition new_part_desc, Oid new_part_id, + int2vector *pkey, const oidvector *inttablespace, Datum interval, + Datum maxValues, Datum transitionPoint, Datum reloptions, char parttype); +extern bool isPartitionedObject(Oid relid, char relkind, bool missing_ok); +extern bool isPartitionObject(Oid partid, char partkind, bool missing_ok); +extern Oid getPartitionIndexOid(Oid indexid, Oid partitionid); +extern Oid getPartitionIndexTblspcOid(Oid indexid, Oid partitionid); +extern Oid indexPartGetHeapPart(Oid indexPart, bool missing_ok); +extern Oid searchPartitionIndexOid(Oid partitionedIndexid, List *pindex); +extern List *getPartitionObjectIdList(Oid relid, char relkind); +extern Oid partitionNameGetPartitionOid (Oid partitionedTableOid, + const char *partitionName, + char objectType, + LOCKMODE lockMode, + bool missingOk, + bool nowWait, + PartitionNameGetPartidCallback callback, + void *callback_arg, + LOCKMODE callbackobj_lockMode); +extern Oid partitionValuesGetPartitionOid(Relation rel, List *partKeyValueList, LOCKMODE lockMode, bool topClosed, + bool missingOk, bool noWait); +extern List *searchPartitionIndexesByblid(Oid blid); +extern List *searchPgPartitionByParentId(char parttype, Oid parentId); +extern void freePartList(List *l); +extern HeapTuple searchPgPartitionByParentIdCopy(char parttype, Oid parentId); + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_partition.h postgresql-hll-2.14/include/include/catalog/pg_partition.h --- postgresql-hll-2.14_old/include/include/catalog/pg_partition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_partition.h 2020-12-12 17:06:43.159346903 +0800 @@ -0,0 +1,124 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_partition.h + * + * + * + * IDENTIFICATION + * src/include/catalog/pg_partition.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_PARTITION_H +#define PG_PARTITION_H +#include "catalog/genbki.h" + +#define PartitionRelationId 9016 +#define PartitionRelation_Rowtype_Id 3790 +CATALOG(pg_partition,9016) BKI_ROWTYPE_OID(3790) BKI_SCHEMA_MACRO +{ + NameData relname; + char parttype; + Oid parentid; + int4 rangenum; + int4 intervalnum; + char partstrategy; + Oid relfilenode; + Oid reltablespace; + float8 relpages; + float8 reltuples; + int4 relallvisible; + Oid reltoastrelid; + Oid reltoastidxid; + Oid indextblid; /* index partition's table partition's oid */ + bool indisusable; /* is this index partition useable for insert and select? */ + /*if yes, insert and select should ignore this index partition */ + Oid reldeltarelid; /* if ColStore table, it is not 0 */ + Oid reldeltaidx; + Oid relcudescrelid; /* if ColStore table, it is not 0 */ + Oid relcudescidx; + ShortTransactionId relfrozenxid; + int4 intspnum; +#ifdef CATALOG_VARLEN + int2vector partkey; + oidvector intervaltablespace; + text interval[1]; + text boundaries[1]; + text transit[1]; + text reloptions[1]; /* access-method-specific options */ +#endif + TransactionId relfrozenxid64; +} FormData_pg_partition; +/* Size of fixed part of pg_partition tuples, not counting var-length fields */ +#define PARTITION_TUPLE_SIZE \ + (offsetof(FormData_pg_partition,intspnum) + sizeof(int4)) + +/* Get a more readable name of partition strategy by given abbreviation */ +#define GetPartitionStrategyNameByType(s)\ +(\ + (s == 'r') ? "RANGE-PARTITION" : \ + (s == 'i') ? "INTERVAL-PARTITION" : \ + (s == 'l') ? "LIST-PARTITION" : \ + (s == 'h') ? "HASH-PARTITION" : \ + (s == 'v') ? "VALUE-PARTITION" : "INVALID"\ +)\ + +typedef FormData_pg_partition *Form_pg_partition; + +#define PART_STRATEGY_RANGE 'r' +#define PART_STRATEGY_INTERVAL 'i' +#define PART_STRATEGY_VALUE 'v' +#define PART_STRATEGY_LIST 'l' +#define PART_STRATEGY_HASH 'h' +#define PART_STRATEGY_INVALID 'n' + +#define PART_OBJ_TYPE_PARTED_TABLE 'r' +#define PART_OBJ_TYPE_TOAST_TABLE 't' +#define PART_OBJ_TYPE_TABLE_PARTITION 'p' +#define PART_OBJ_TYPE_INDEX_PARTITION 'x' + +#define Natts_pg_partition 28 +#define Anum_pg_partition_relname 1 +#define Anum_pg_partition_parttype 2 +#define Anum_pg_partition_parentid 3 +#define Anum_pg_partition_rangenum 4 +#define Anum_pg_partition_intervalnum 5 +#define Anum_pg_partition_partstrategy 6 +#define Anum_pg_partition_relfilenode 7 +#define Anum_pg_partition_reltablespace 8 +#define Anum_pg_partition_relpages 9 +#define Anum_pg_partition_reltuples 10 +#define Anum_pg_partition_relallvisible 11 +#define Anum_pg_partition_reltoastrelid 12 +#define Anum_pg_partition_reltoastidxid 13 +#define Anum_pg_partition_indextblid 14 +#define Anum_pg_partition_indisusable 15 +#define Anum_pg_partition_deltarelid 16 +#define Anum_pg_partition_reldeltaidx 17 +#define Anum_pg_partition_relcudescrelid 18 +#define Anum_pg_partition_relcudescidx 19 +#define Anum_pg_partition_relfrozenxid 20 +#define Anum_pg_partition_intspnum 21 +#define Anum_pg_partition_partkey 22 +#define Anum_pg_partition_intablespace 23 +#define Anum_pg_partition_interval 24 +#define Anum_pg_partition_boundaries 25 +#define Anum_pg_partition_transit 26 +#define Anum_pg_partition_reloptions 27 +#define Anum_pg_partition_relfrozenxid64 28 +#endif/*PG_PARTITION_H*/ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_pltemplate.h postgresql-hll-2.14/include/include/catalog/pg_pltemplate.h --- postgresql-hll-2.14_old/include/include/catalog/pg_pltemplate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_pltemplate.h 2020-12-12 17:06:43.159346903 +0800 @@ -0,0 +1,84 @@ +/* ------------------------------------------------------------------------- + * + * pg_pltemplate.h + * definition of the system "PL template" relation (pg_pltemplate) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_pltemplate.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PLTEMPLATE_H +#define PG_PLTEMPLATE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_pltemplate definition. cpp turns this into + * typedef struct FormData_pg_pltemplate + * ---------------- + */ +#define PLTemplateRelationId 1136 +#define PLTemplateRelation_Rowtype_Id 11634 + + +CATALOG(pg_pltemplate,1136) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + NameData tmplname; /* name of PL */ + bool tmpltrusted; /* PL is trusted? */ + bool tmpldbacreate; /* PL is installable by db owner? */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text tmplhandler; /* name of call handler function */ + text tmplinline; /* name of anonymous-block handler, or NULL */ + text tmplvalidator; /* name of validator function, or NULL */ + text tmpllibrary; /* path of shared library */ + aclitem tmplacl[1]; /* access privileges for template */ +#endif +} FormData_pg_pltemplate; + +/* ---------------- + * Form_pg_pltemplate corresponds to a pointer to a row with + * the format of pg_pltemplate relation. + * ---------------- + */ +typedef FormData_pg_pltemplate *Form_pg_pltemplate; + +/* ---------------- + * compiler constants for pg_pltemplate + * ---------------- + */ +#define Natts_pg_pltemplate 8 +#define Anum_pg_pltemplate_tmplname 1 +#define Anum_pg_pltemplate_tmpltrusted 2 +#define Anum_pg_pltemplate_tmpldbacreate 3 +#define Anum_pg_pltemplate_tmplhandler 4 +#define Anum_pg_pltemplate_tmplinline 5 +#define Anum_pg_pltemplate_tmplvalidator 6 +#define Anum_pg_pltemplate_tmpllibrary 7 +#define Anum_pg_pltemplate_tmplacl 8 + + +/* ---------------- + * initial contents of pg_pltemplate + * ---------------- + */ +DATA(insert ("plpgsql" t t "plpgsql_call_handler" "plpgsql_inline_handler" "plpgsql_validator" "$libdir/plpgsql" _null_)); +DATA(insert ("pltcl" t t "pltcl_call_handler" _null_ _null_ "$libdir/pltcl" _null_)); +DATA(insert ("pltclu" f f "pltclu_call_handler" _null_ _null_ "$libdir/pltcl" _null_)); +DATA(insert ("plperl" t t "plperl_call_handler" "plperl_inline_handler" "plperl_validator" "$libdir/plperl" _null_)); +DATA(insert ("plperlu" f f "plperlu_call_handler" "plperlu_inline_handler" "plperlu_validator" "$libdir/plperl" _null_)); +DATA(insert ("plpythonu" f f "plpython_call_handler" "plpython_inline_handler" "plpython_validator" "$libdir/plpython2" _null_)); +DATA(insert ("plpython2u" f f "plpython2_call_handler" "plpython2_inline_handler" "plpython2_validator" "$libdir/plpython2" _null_)); +DATA(insert ("plpython3u" f f "plpython3_call_handler" "plpython3_inline_handler" "plpython3_validator" "$libdir/plpython3" _null_)); + +#endif /* PG_PLTEMPLATE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_proc_fn.h postgresql-hll-2.14/include/include/catalog/pg_proc_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_proc_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_proc_fn.h 2020-12-12 17:06:43.159346903 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * pg_proc_fn.h + * prototypes for functions in catalog/pg_proc.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PROC_FN_H +#define PG_PROC_FN_H + +#include "nodes/pg_list.h" + +extern Oid ProcedureCreate(const char *procedureName, + Oid procNamespace, + bool isOraStyle, + bool replace, + bool returnsSet, + Oid returnType, + Oid proowner, + Oid languageObjectId, + Oid languageValidator, + const char *prosrc, + const char *probin, + bool isAgg, + bool isWindowFunc, + bool security_definer, + bool isLeakProof, + bool isStrict, + char volatility, + oidvector *parameterTypes, + Datum allParameterTypes, + Datum parameterModes, + Datum parameterNames, + List *parameterDefaults, + Datum proconfig, + float4 procost, + float4 prorows, + int2vector *prodefaultargpos, + bool fenced, + bool shippable, + bool package, + bool proIsProcedure); + +extern bool function_parse_error_transpose(const char *prosrc); + +#endif /* PG_PROC_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_proc.h postgresql-hll-2.14/include/include/catalog/pg_proc.h --- postgresql-hll-2.14_old/include/include/catalog/pg_proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_proc.h 2020-12-12 17:06:43.159346903 +0800 @@ -0,0 +1,444 @@ +/* +------------------------------------------------------------------------ + * + * pg_proc.h + * definition of the system "procedure" relation (pg_proc) + * along with the relation's initial contents. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc.h + * + * NOTES + * The script catalog/genbki.pl reads this file and generates .bki + * information from the DATA() statements. utils/Gen_fmgrtab.pl + * generates fmgroids.h and fmgrtab.c the same way. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * XXX (eg. #if 0 #endif won't do what you think) + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PROC_H +#define PG_PROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_proc definition. cpp turns this into + * typedef struct FormData_pg_proc + * ---------------- + */ +#define ProcedureRelationId 1255 +#define ProcedureRelation_Rowtype_Id 81 + +#define IsProcRelation(rel) (RelationGetRelid(rel) == ProcedureRelationId) +#define IsProcCache(cache) ((cache)->cc_reloid == ProcedureRelationId) + +CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO +{ + NameData proname; /* procedure name */ + Oid pronamespace; /* OID of namespace containing this proc */ + Oid proowner; /* procedure owner */ + Oid prolang; /* OID of pg_language entry */ + float4 procost; /* estimated execution cost */ + float4 prorows; /* estimated # of rows out (if proretset) */ + Oid provariadic; /* element type of variadic array, or 0 */ + regproc protransform; /* transforms calls to it during planning */ + bool proisagg; /* is it an aggregate? */ + bool proiswindow; /* is it a window function? */ + bool prosecdef; /* security definer */ + bool proleakproof; /* is it a leak-proof function? */ + bool proisstrict; /* strict with respect to NULLs? */ + bool proretset; /* returns a set? */ + char provolatile; /* see PROVOLATILE_ categories below */ + int2 pronargs; /* number of arguments */ + int2 pronargdefaults; /* number of arguments with defaults */ + Oid prorettype; /* OID of result type */ + + /* + * variable-length fields start here, but we allow direct access to + * proargtypes + */ + oidvector proargtypes; /* parameter types (excludes OUT params) */ + +#ifdef CATALOG_VARLEN + Oid proallargtypes[1]; /* all param types (NULL if IN only) */ + char proargmodes[1]; /* parameter modes (NULL if IN only) */ + text proargnames[1]; /* parameter names (NULL if no names) */ + pg_node_tree proargdefaults; /* list of expression trees for argument + * defaults (NULL if none) */ + text prosrc; /* procedure source text */ + text probin; /* secondary procedure info (can be NULL) */ + text proconfig[1]; /* procedure-local GUC settings */ + aclitem proacl[1]; /* access permissions */ + int2vector prodefaultargpos; + bool fencedmode; + bool proshippable; /* if provolatile is not 'i', proshippable will determine if the func can be shipped */ + bool propackage; + char prokind; /* see PROKIND_ categories below */ +#endif +} FormData_pg_proc; + +/* ---------------- + * Form_pg_proc corresponds to a pointer to a tuple with + * the format of pg_proc relation. + * ---------------- + */ +typedef FormData_pg_proc *Form_pg_proc; + +/* ---------------- + * compiler constants for pg_proc + * ---------------- + */ +#define Natts_pg_proc 32 +#define Anum_pg_proc_proname 1 +#define Anum_pg_proc_pronamespace 2 +#define Anum_pg_proc_proowner 3 +#define Anum_pg_proc_prolang 4 +#define Anum_pg_proc_procost 5 +#define Anum_pg_proc_prorows 6 +#define Anum_pg_proc_provariadic 7 +#define Anum_pg_proc_protransform 8 +#define Anum_pg_proc_proisagg 9 +#define Anum_pg_proc_proiswindow 10 +#define Anum_pg_proc_prosecdef 11 +#define Anum_pg_proc_proleakproof 12 +#define Anum_pg_proc_proisstrict 13 +#define Anum_pg_proc_proretset 14 +#define Anum_pg_proc_provolatile 15 +#define Anum_pg_proc_pronargs 16 +#define Anum_pg_proc_pronargdefaults 17 +#define Anum_pg_proc_prorettype 18 +#define Anum_pg_proc_proargtypes 19 +#define Anum_pg_proc_proallargtypes 20 +#define Anum_pg_proc_proargmodes 21 +#define Anum_pg_proc_proargnames 22 +#define Anum_pg_proc_proargdefaults 23 +#define Anum_pg_proc_prosrc 24 +#define Anum_pg_proc_probin 25 +#define Anum_pg_proc_proconfig 26 +#define Anum_pg_proc_proacl 27 +#define Anum_pg_proc_prodefaultargpos 28 +#define Anum_pg_proc_fenced 29 +#define Anum_pg_proc_shippable 30 +#define Anum_pg_proc_package 31 +#define Anum_pg_proc_prokind 32 + +/* proc_oid is only for builitin + * func view shouldn't be included in Natts_pg_proc + */ +#define Anum_pg_proc_oid 33 + +/* ---------------- + * initial contents of pg_proc + * ---------------- + */ + +/* + * Note: every entry in pg_proc.h is expected to have a DESCR() comment, + * except for functions that implement pg_operator.h operators and don't + * have a good reason to be called directly rather than via the operator. + * (If you do expect such a function to be used directly, you should + * duplicate the operator's comment.) initdb will supply suitable default + * comments for functions referenced by pg_operator. + * + * Try to follow the style of existing functions' comments. + * Some recommended conventions: + * "I/O" for typinput, typoutput, typreceive, typsend functions + * "I/O typmod" for typmodin, typmodout functions + * "aggregate transition function" for aggtransfn functions, unless + * they are reasonably useful in their own right + * "aggregate final function" for aggfinalfn functions (likewise) + * "convert srctypename to desttypename" for cast functions + * "less-equal-greater" for B-tree comparison functions + */ + +/* keep the following ordered by OID so that later changes can be made easier */ + /* OIDS 1 - 99 */ +#define TEXTLENOID 1257 +#define EQSELRETURNOID 101 +#define NEQSELRETURNOID 102 +#define ABSTIMEINFUNCOID 240 +#define ABSTIMEOUTFUNCOID 241 +#define RELTIMEINFUNCOID 242 +#define RELTIMEOUTFUNCOID 243 +#define TINTERVALINFUNCOID 246 +#define TINTERVALOUTFUNCOID 247 +#define TIMENOWFUNCOID 250 +#define INT4TOFLOAT8FUNCOID 316 +#define BTINT4CMP_OID 351 +#define RTRIM1FUNCOID 401 +#define NAME2TEXTFUNCOID 406 +#define HASHINT4OID 450 +#define HASHINT8OID 949 +#define HASHTEXTOID 400 +#define GETPGUSERNAMEFUNCOID 710 +#define CURRENTUSERFUNCOID 745 +#define SESSIONUSERFUNCOID 746 +#define ARRAYTOSTRINGFUNCOID 395 +#define ARRAYTOSTRINGNULLFUNCOID 384 +#define ARRAYAGGFUNCOID 2335 +#define POSITIONFUNCOID 849 +#define CURRENTDATABASEFUNCOID 861 +#define CASHINFUNCOID 886 +#define CASHOUTFUNCOID 887 +#define CASH2NUMERICFUNCOID 3823 +#define NUMERIC2CASHFUNCOID 3824 +#define INTEGER2CASHFUNCOID 3811 +#define BIGINT2CASHFUNCOID 3812 +#define HASHBPCHAROID 1080 +#define DATEINFUNCOID 1084 +#define DATEOUTFUNCOID 1085 +#define TIMEINFUNCOID 1143 +#define TIMEOUTFUNCOID 1144 +#define TIMESTAMPTZINFUNCOID 1150 +#define TIMESTAMPTZOUTFUNCOID 1151 +#define INTERVALINFUNCOID 1160 +#define TIMESTAMPTZPARTFUNCOID 1171 +#define INTERVALPARTFUNCOID 1172 +#define DATETIMESTAMPTZFUNCOID 1174 +#define DTAETIME2TIMESTAMPTZFUNCOID 1176 +#define TIMESTAMPTZ2DATEFUNCOID 1178 +#define ABSTIME2DATEFUNCOID 1179 +#define TIMESTAMPTZPLINTERVALFUNCOID 1189 +#define TIMESTAMPTZMIINTERVALFUNCOID 1190 +#define TIMESTAMPTZTRUNCFUNCOID 1217 +#define INTERVALTRUNCFUNCOID 1218 +#define TIMEZPARTFUNCOID 1273 +#define NOWFUNCOID 1299 +#define TRANSACTIONTIMESTAMPFUNCOID 2647 +#define STATEMENTTIMESTAMPFUNCOID 2648 +#define PGSYSTIMESTAMPFUNCOID 3951 +#define OVERLAPSV1FUNCOID 1305 +#define OVERLAPSV2FUNCOID 1306 +#define OVERLAPSV3FUNCOID 1307 +#define TIMESTAMPINFUNCOID 1312 +#define TIMESTAMPOUTFUNCOID 1313 +#define LENGTHFUNCOID 1317 +#define BPLENFUNCOID 1318 +#define TEXTOCTLENFUNCOID 3175 +#define BPOCTLENFUNCOID 3176 +#define SQRTFUNCOID 1344 +#define POWFUNCOID 1346 +#define POWERFUNCOID 1368 +#define TIMETZINFUNCOID 1350 +#define ABSTIME2TIMEFUNCOID 1364 +#define CHARLENFUNCOID 1381 +#define DATEPARTFROMABSTIMEFUNCOID 1382 +#define DATEPARTFROMRELTIMEFUNCOID 1383 +#define DATEPARTFUNCOID 1384 +#define TIMEPARTFUNCOID 1385 +#define AGEDATETOTIMETZFUNCOID 1386 +#define TIMESTAMPTZ2TIMETZFUNCOID 1388 +#define CURRENTSCHEMAFUNCOID 1402 +#define NEXTVALFUNCOID 1574 +#define CURRVALFUNCOID 1575 +#define SETVAL1FUNCOID 1576 +#define SETVAL3FUNCOID 1765 +#define INT4NUMERICFUNCOID 1740 +#define INT8NUMERICFUNCOID 1781 +#define VARCHARINT8FUNCOID 4176 +#define RANDOMFUNCOID 1598 +#define ECEXTENSIONFUNCOID 4244 +#define ECHADOOPFUNCOID 4255 +#define ARCSINEFUNCOID 1600 +#define SINEFUNCOID 1604 +#define COSINEFUNCOID 1605 +#define STRPOSFUNCOID 868 +#define LPADFUNCOID 873 +#define RPADFUNCOID 874 +#define LTRIMFUNCOID 875 +#define RTRIMFUNCOID 876 +#define SUBSTRFUNCOID 877 +#define SUBSTRBWITHLENFUNCOID 3205 +#define SUBSTRBNOLENFUNCOID 3206 +#define LPADPARAFUNCOID 879 +#define RPADPARAFUNCOID 880 +#define LTRIMPARAFUNCOID 881 +#define RTRIMPARAFUNCOID 882 +#define SUBSTRNOLENFUNCOID 883 +#define BTRIMPARAFUNCOID 884 +#define BTRIMFUNCOID 885 +#define SUBSTRINNFUNCOID 3182 +#define SUBSTRINNNOLENFUNCOID 3183 +#define TEXTSUBSTRINGFUNCOID 936 +#define TEXTSUBSTRINGNOLENFUNCOID 937 +#define PGCLIENTENCODINGFUNCOID 810 +#define CONVERTFROMFUNCOID 1714 +#define CONVERTTOFUNCOID 1717 +#define CONVERTFUNCOID 1813 +#define PGCHARTOENCODINGFUNCOID 1264 +#define PGENCODINGTOCHARFUNCOID 1597 +#define PGTYPEOFFUNCOID 1619 +#define BITSUBSTRINGFUNOID 1680 +#define BITPOSITIONFUNCOID 1698 +#define BITSUBSTRINGNOLENFUNCOID 1699 +#define NUMTOFLOAT8FUNCOID 1746 +#define TIMESTAMPTZ2CHARFUNCOID 1770 +#define NUMERIC2CHARFUNCOID 1772 +#define INTEGER2CHARFUNCOID 1773 +#define BIGINT2CHARFUNCOID 1774 +#define FLOAT4TOCHARFUNCOID 1775 +#define FLOAT8TOCHARFUNCOID 1776 +#define TONUMBERFUNCOID 1777 +#define TOTIMESTAMPFUNCOID 1778 +#define TOTIMESTAMPDEFAULTFUNCOID 3207 +#define TODATEFUNCOID 1780 +#define INTERVALTOCHARFUNCOID 1768 +#define CONCATFUNCOID 3058 +#define CONCATWSFUNCOID 3059 +#define ANYTOTEXTFORMATFUNCOID 3539 +#define DEFAULTFORMATFUNCOID 3540 +#define INTERVALACCUMFUNCOID 1843 +#define INTERVALAVGFUNCOID 1844 +#define STRINGAGGTRANSFNFUNCOID 3535 +#define STRINGAGGFUNCOID 3538 +#define BYTEASTRINGAGGFUNCOID 3545 +#define LISTAGGFUNCOID 3552 +#define LISTAGGNOARG2FUNCOID 3554 +#define INT2LISTAGGFUNCOID 3556 +#define INT2LISTAGGNOARG2FUNCOID 3558 +#define INT4LISTAGGFUNCOID 3560 +#define INT4LISTAGGNOARG2FUNCOID 3562 +#define INT8LISTAGGFUNCOID 3564 +#define INT8LISTAGGNOARG2FUNCOID 3566 +#define FLOAT4LISTAGGFUNCOID 3568 +#define FLOAT4LISTAGGNOARG2FUNCOID 3570 +#define FLOAT8LISTAGGFUNCOID 3572 +#define FLOAT8LISTAGGNOARG2FUNCOID 3574 +#define NUMERICLISTAGGFUNCOID 3576 +#define NUMERICLISTAGGNOARG2FUNCOID 3578 +#define DATELISTAGGFUNCOID 3580 +#define DATELISTAGGNOARG2FUNCOID 3582 +#define TIMESTAMPLISTAGGFUNCOID 3584 +#define TIMESTAMPLISTAGGNOARG2FUNCOID 3586 +#define TIMESTAMPTZLISTAGGFUNCOID 3588 +#define TIMESTAMPTZLISTAGGNOARG2FUNCOID 3590 +#define INTERVALLISTAGGFUNCOID 4506 +#define INTERVALLISTAGGNOARG2FUNCOID 4508 +#define PGBACKENDPIDFUNCOID 2026 +#define PGSTATGETBACKENDPIDFUNCOID 1937 +#define TEXTANYCATFUNCOID 2003 +#define ANYTEXTCATFUNCOID 2004 +#define BYTEASUBSTRINGFUNCOID 2012 +#define BYTEASUBSTRINGNOLENOID 2013 +#define BYTEASUBSTRFUNCOID 2085 +#define BYTEASUBSTRNOLENFUNCOID 2086 +#define BYTEAPOSFUNCOID 2014 +#define TIMESTAMPTZ2TIMEFUNCOID 2019 +#define TIMESTAMPTRUNCFUNCOID 2020 +#define TIMESTAMPPARTFUNCOID 2021 +#define ABSTIMETIMESTAMPFUNCOID 2023 +#define TIMESTAMPTZ2TIMESTAMPFUNCOID 2027 +#define TIMESTAMP2TIMESTAMPTZFUNCOID 2028 +#define TIMESTAMP2DATEOID 2029 +#define TIMESTAMP2ABSTIMEFUNCOID 2030 +#define TIMEZONETZFUNCOID 2037 +#define TIMESTAMPHASHOID 2039 +#define TIME2TIMETZFUNCOID 2047 +#define TIMESTAMP2CHARFUNCOID 2049 +#define DEFAULTFORMATTIMESTAMP2CHARFUNCOID 3808 +#define DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID 3813 +#define AGEDATETOTIMEFUNCOID 2059 +#define TEXTREGEXSUBSTRINGOID 2073 +#define SUBSTRINGESCAPEFUNCOID 2074 +#define ANYCOUNTOID 2147 +#define COUNTOID 2803 +#define PGCOLUMNSIZEFUNCOID 1269 +#define ANYARRAYINFUNCOID 2296 +#define DATELTTIMESTAMPTZFUNCOID 2351 +#define DATELETIMESTAMPTZFUNCOID 2352 +#define DATEEQTIMESTAMPTZFUNCOID 2353 +#define DATEGTTIMESTAMPTZFUNCOID 2354 +#define DATEGETIMESTAMPTZFUNCOID 2355 +#define DATENETIMESTAMPTZFUNCOID 2356 +#define DATECMPTIMESTAMPTZFUNCOID 2357 +#define TIMESTAMPTZLTDATEFUNCOID 2377 +#define TIMESTAMPTZLEDATEFUNCOID 2378 +#define TIMESTAMPTZEQDATEFUNCOID 2379 +#define TIMESTAMPTZGTDATEFUNCOID 2380 +#define TIMESTAMPTZGEDATEFUNCOID 2381 +#define TIMESTAMPTZNEDATEFUNCOID 2382 +#define TIMESTAMPTZCMPDATEFUNCOID 2383 +#define TIMESTAMPLTTIMESTAMPTZFUNCOID 2520 +#define TIMESTAMPLETIMESTAMPTZFUNCOID 2521 +#define TIMESTAMPEQTIMESTAMPTZFUNCOID 2522 +#define TIMESTAMPGTTIMESTAMPTZFUNCOID 2523 +#define TIMESTAMPGETIMESTAMPTZFUNCOID 2524 +#define TIMESTAMPNETIMESTAMPTZFUNCOID 2525 +#define TIMESTAMPCMPTIMESTAMPTZFUNCOID 2526 +#define TIMESTAMPTZLTTIMESTAMPFUNCOID 2527 +#define TIMESTAMPTZLETIMESTAMPFUNCOID 2528 +#define TIMESTAMPTZEQTIMESTAMPFUNCOID 2529 +#define TIMESTAMPTZGTTIMESTAMPFUNCOID 2530 +#define TIMESTAMPTZGETIMESTAMPFUNCOID 2531 +#define TIMESTAMPTZNETIMESTAMPFUNCOID 2532 +#define TIMESTAMPTZCMPTIMESTAMPFUNCOID 2533 +#define GENERATESERIESFUNCOID 939 +#define EVERYFUNCOID 2519 +#define INTERVALPLTIMESTAMPTZFUNCOID 2549 +#define LASTVALFUNCOID 2559 +#define XMLAGGFUNCOID 2901 +#define ROWNUMBERFUNCOID 3100 +#define RANKFUNCOID 3101 +#define DENSERANKFUNCOID 3102 +#define INSTR2FUNCOID 3167 +#define INSTR3FUNCOID 3168 +#define INSTR4FUNCOID 3169 +#define SMALLDATETIMEINFUNCOID 9004 +#define SMALLDATETIMEOUTFUNCOID 9006 +#define TODATEDEFAULTFUNCOID 5560 +#define GSENCRYPTAES128FUNCOID 3464 +#define TESTSKEWNESSRETURNTYPE 4048 +#define PERCENTILECONTAGGFUNCOID 4452 +#define MODEAGGFUNCOID 4461 +#define PGCHECKAUTHIDFUNCOID 3228 + +/* + * Symbolic values for prokind column + */ +#define PROKIND_FUNCTION 'f' +#define PROKIND_AGGREGATE 'a' +#define PROKIND_WINDOW 'w' +#define PROKIND_PROCEDURE 'p' + +#define PROC_IS_FUNC(prokind) ((prokind) == PROKIND_FUNCTION) +#define PROC_IS_AGG(prokind) ((prokind) == PROKIND_AGGREGATE) +#define PROC_IS_WIN(prokind) ((prokind) == PROKIND_WINDOW) +#define PROC_IS_PRO(prokind) ((prokind) == PROKIND_PROCEDURE) + +/* + * Symbolic values for provolatile column: these indicate whether the result + * of a function is dependent *only* on the values of its explicit arguments, + * or can change due to outside factors (such as parameter variables or + * table contents). NOTE: functions having side-effects, such as setval(), + * must be labeled volatile to ensure they will not get optimized away, + * even if the actual return value is not changeable. + */ +#define PROVOLATILE_IMMUTABLE 'i' /* never changes for given input */ +#define PROVOLATILE_STABLE 's' /* does not change within a scan */ +#define PROVOLATILE_VOLATILE 'v' /* can change even within a scan */ + +/* + * Symbolic values for proargmodes column. Note that these must agree with + * the FunctionParameterMode enum in parsenodes.h; we declare them here to + * be accessible from either header. + */ +#define PROARGMODE_IN 'i' +#define PROARGMODE_OUT 'o' +#define PROARGMODE_INOUT 'b' +#define PROARGMODE_VARIADIC 'v' +#define PROARGMODE_TABLE 't' + +#define PROC_LIB_PATH "$libdir/" +#define PORC_PLUGIN_LIB_PATH "$libdir/pg_plugin/" +#define PORC_SRC_LIB_PATH "$libdir/proc_srclib/" + +#define OID_REGEXP_SPLIT_TO_TABLE 2765 +#define OID_REGEXP_SPLIT_TO_TABLE_NO_FLAG 2766 + +#endif /* PG_PROC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_proc.h_for_llt postgresql-hll-2.14/include/include/catalog/pg_proc.h_for_llt --- postgresql-hll-2.14_old/include/include/catalog/pg_proc.h_for_llt 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_proc.h_for_llt 2020-12-12 17:06:43.163346954 +0800 @@ -0,0 +1,5740 @@ +/*------------------------------------------------------------------------- + * + * pg_proc.h_for_llt + * definition of the system "procedure" relation (pg_proc) + * along with the relation's initial contents. + * + * Portions Copyright (c) 2020, Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_proc.h_for_llt + * + * NOTES + * The script catalog/genbki.pl reads this file and generates .bki + * information from the DATA() statements. utils/Gen_fmgrtab.pl + * generates fmgroids.h and fmgrtab.c the same way. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * XXX (eg. #if 0 #endif won't do what you think) + * + *------------------------------------------------------------------------- + */ +#ifndef PG_PROC_H +#define PG_PROC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_proc definition. cpp turns this into + * typedef struct FormData_pg_proc + * ---------------- + */ +#define ProcedureRelationId 1255 +#define ProcedureRelation_Rowtype_Id 81 + +CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO +{ + NameData proname; /* procedure name */ + Oid pronamespace; /* OID of namespace containing this proc */ + Oid proowner; /* procedure owner */ + Oid prolang; /* OID of pg_language entry */ + float4 procost; /* estimated execution cost */ + float4 prorows; /* estimated # of rows out (if proretset) */ + Oid provariadic; /* element type of variadic array, or 0 */ + regproc protransform; /* transforms calls to it during planning */ + bool proisagg; /* is it an aggregate? */ + bool proiswindow; /* is it a window function? */ + bool prosecdef; /* security definer */ + bool proleakproof; /* is it a leak-proof function? */ + bool proisstrict; /* strict with respect to NULLs? */ + bool proretset; /* returns a set? */ + char provolatile; /* see PROVOLATILE_ categories below */ + int2 pronargs; /* number of arguments */ + int2 pronargdefaults; /* number of arguments with defaults */ + Oid prorettype; /* OID of result type */ + + /* + * variable-length fields start here, but we allow direct access to + * proargtypes + */ + oidvector proargtypes; /* parameter types (excludes OUT params) */ + +#ifdef CATALOG_VARLEN + Oid proallargtypes[1]; /* all param types (NULL if IN only) */ + char proargmodes[1]; /* parameter modes (NULL if IN only) */ + text proargnames[1]; /* parameter names (NULL if no names) */ + pg_node_tree proargdefaults;/* list of expression trees for argument + * defaults (NULL if none) */ + text prosrc; /* procedure source text */ + text probin; /* secondary procedure info (can be NULL) */ + text proconfig[1]; /* procedure-local GUC settings */ + aclitem proacl[1]; /* access permissions */ + int2vector prodefaultargpos; +#endif + bool fencedmode; +} FormData_pg_proc; + +/* ---------------- + * Form_pg_proc corresponds to a pointer to a tuple with + * the format of pg_proc relation. + * ---------------- + */ +typedef FormData_pg_proc *Form_pg_proc; + +/* ---------------- + * compiler constants for pg_proc + * ---------------- + */ +#define Natts_pg_proc 29 +#define Anum_pg_proc_proname 1 +#define Anum_pg_proc_pronamespace 2 +#define Anum_pg_proc_proowner 3 +#define Anum_pg_proc_prolang 4 +#define Anum_pg_proc_procost 5 +#define Anum_pg_proc_prorows 6 +#define Anum_pg_proc_provariadic 7 +#define Anum_pg_proc_protransform 8 +#define Anum_pg_proc_proisagg 9 +#define Anum_pg_proc_proiswindow 10 +#define Anum_pg_proc_prosecdef 11 +#define Anum_pg_proc_proleakproof 12 +#define Anum_pg_proc_proisstrict 13 +#define Anum_pg_proc_proretset 14 +#define Anum_pg_proc_provolatile 15 +#define Anum_pg_proc_pronargs 16 +#define Anum_pg_proc_pronargdefaults 17 +#define Anum_pg_proc_prorettype 18 +#define Anum_pg_proc_proargtypes 19 +#define Anum_pg_proc_proallargtypes 20 +#define Anum_pg_proc_proargmodes 21 +#define Anum_pg_proc_proargnames 22 +#define Anum_pg_proc_proargdefaults 23 +#define Anum_pg_proc_prosrc 24 +#define Anum_pg_proc_probin 25 +#define Anum_pg_proc_proconfig 26 +#define Anum_pg_proc_proacl 27 +#define Anum_pg_proc_prodefaultargpos 28 +#define Anum_pg_proc_fenced 29 + + +/* ---------------- + * initial contents of pg_proc + * ---------------- + */ + +/* + * Note: every entry in pg_proc.h is expected to have a DESCR() comment, + * except for functions that implement pg_operator.h operators and don't + * have a good reason to be called directly rather than via the operator. + * (If you do expect such a function to be used directly, you should + * duplicate the operator's comment.) initdb will supply suitable default + * comments for functions referenced by pg_operator. + * + * Try to follow the style of existing functions' comments. + * Some recommended conventions: + * "I/O" for typinput, typoutput, typreceive, typsend functions + * "I/O typmod" for typmodin, typmodout functions + * "aggregate transition function" for aggtransfn functions, unless + * they are reasonably useful in their own right + * "aggregate final function" for aggfinalfn functions (likewise) + * "convert srctypename to desttypename" for cast functions + * "less-equal-greater" for B-tree comparison functions + */ + +/* keep the following ordered by OID so that later changes can be made easier */ + +/* OIDS 1 - 99 */ + +DATA(insert OID = 1242 ( boolin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "2275" _null_ _null_ _null_ _null_ boolin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1243 ( boolout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "16" _null_ _null_ _null_ _null_ boolout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1244 ( byteain PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ byteain _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 31 ( byteaout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ byteaout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + + +DATA(insert OID = 4035 ( rawin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ rawin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4036 ( rawout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ rawout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 1245 ( charin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "2275" _null_ _null_ _null_ _null_ charin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 33 ( charout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "18" _null_ _null_ _null_ _null_ charout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 34 ( namein PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "2275" _null_ _null_ _null_ _null_ namein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 35 ( nameout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "19" _null_ _null_ _null_ _null_ nameout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 38 ( int2in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "2275" _null_ _null_ _null_ _null_ int2in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 39 ( int2out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "21" _null_ _null_ _null_ _null_ int2out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5541 ( int1in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "2275" _null_ _null_ _null_ _null_ int1in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5542 ( int1out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "5545" _null_ _null_ _null_ _null_ int1out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 40 ( int2vectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 22 "2275" _null_ _null_ _null_ _null_ int2vectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 41 ( int2vectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "22" _null_ _null_ _null_ _null_ int2vectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 42 ( int4in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2275" _null_ _null_ _null_ _null_ int4in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 43 ( int4out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ int4out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 44 ( regprocin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 24 "2275" _null_ _null_ _null_ _null_ regprocin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 45 ( regprocout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "24" _null_ _null_ _null_ _null_ regprocout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 46 ( textin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2275" _null_ _null_ _null_ _null_ textin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 47 ( textout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "25" _null_ _null_ _null_ _null_ textout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 48 ( tidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 27 "2275" _null_ _null_ _null_ _null_ tidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 49 ( tidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "27" _null_ _null_ _null_ _null_ tidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 50 ( xidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 28 "2275" _null_ _null_ _null_ _null_ xidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 51 ( xidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "28" _null_ _null_ _null_ _null_ xidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 52 ( cidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 29 "2275" _null_ _null_ _null_ _null_ cidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 53 ( cidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "29" _null_ _null_ _null_ _null_ cidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 54 ( oidvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 30 "2275" _null_ _null_ _null_ _null_ oidvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 55 ( oidvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "30" _null_ _null_ _null_ _null_ oidvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 56 ( boollt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boollt _null_ _null_ _null_ "" f)); +DATA(insert OID = 57 ( boolgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 60 ( booleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ booleq _null_ _null_ _null_ "" f)); +DATA(insert OID = 61 ( chareq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ chareq _null_ _null_ _null_ "" f)); +DATA(insert OID = 62 ( nameeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ nameeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 63 ( int2eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 64 ( int2lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 65 ( int4eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 66 ( int4lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 67 ( texteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 68 ( xideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "28 28" _null_ _null_ _null_ _null_ xideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 69 ( cideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "29 29" _null_ _null_ _null_ _null_ cideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 70 ( charne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1246 ( charlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 72 ( charle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charle _null_ _null_ _null_ "" f)); +DATA(insert OID = 73 ( chargt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ chargt _null_ _null_ _null_ "" f)); +DATA(insert OID = 74 ( charge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "18 18" _null_ _null_ _null_ _null_ charge _null_ _null_ _null_ "" f)); +DATA(insert OID = 77 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "18" _null_ _null_ _null_ _null_ chartoi4 _null_ _null_ _null_ "" f)); +DESCR("convert char to int4"); +DATA(insert OID = 78 ( char PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "23" _null_ _null_ _null_ _null_ i4tochar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to char"); +DATA(insert OID = 5547 ( int1eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1eq _null_ _null_ _null_ "" f)); +DESCR("equal"); +DATA(insert OID = 5508 ( int1ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1ne _null_ _null_ _null_ "" f)); +DESCR("not equal"); +DATA(insert OID = 5509 ( int1lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1lt _null_ _null_ _null_ "" f)); +DESCR("less than"); +DATA(insert OID = 5510 ( int1le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1le _null_ _null_ _null_ "" f)); +DESCR("less than or equal"); +DATA(insert OID = 5511 ( int1gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1gt _null_ _null_ _null_ "" f)); +DESCR("greater than"); +DATA(insert OID = 5512 ( int1ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "5545 5545" _null_ _null_ _null_ _null_ int1ge _null_ _null_ _null_ "" f)); +DESCR("greater than or equal"); +DATA(insert OID = 5519 ( int1cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 5545" _null_ _null_ _null_ _null_ int1cmp _null_ _null_ _null_ "" f)); +DESCR("int1"); +DATA(insert OID = 79 ( nameregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1252 ( nameregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1254 ( textregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1256 ( textregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1257 ( textlen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("length"); +#define TEXTLENOID 1257 +DATA(insert OID = 1258 ( textcat PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ textcat _null_ _null_ _null_ "" f)); + +DATA(insert OID = 84 ( boolne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolne _null_ _null_ _null_ "" f)); +DATA(insert OID = 89 ( version PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pgsql_version _null_ _null_ _null_ "" f)); +DESCR("PostgreSQL version string"); +#ifdef PGXC +DATA(insert OID = 90 ( pgxc_version PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pgxc_version _null_ _null_ _null_ "" f)); +DESCR("Postgres-XC version string"); +#endif + +/* OIDS 100 - 199 */ + +DATA(insert OID = 101 ( eqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ eqsel _null_ _null_ _null_ "" f)); +#define EQSELRETURNOID 101 +DESCR("restriction selectivity of = and related operators"); +DATA(insert OID = 102 ( neqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ neqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of <> and related operators"); +#define NEQSELRETURNOID 102 +DATA(insert OID = 103 ( scalarltsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ scalarltsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of < and related operators on scalar datatypes"); +DATA(insert OID = 104 ( scalargtsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ scalargtsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of > and related operators on scalar datatypes"); +DATA(insert OID = 105 ( eqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ eqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of = and related operators"); +DATA(insert OID = 106 ( neqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ neqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of <> and related operators"); +DATA(insert OID = 107 ( scalarltjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ scalarltjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of < and related operators on scalar datatypes"); +DATA(insert OID = 108 ( scalargtjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ scalargtjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of > and related operators on scalar datatypes"); + +DATA(insert OID = 109 ( unknownin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 705 "2275" _null_ _null_ _null_ _null_ unknownin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 110 ( unknownout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "705" _null_ _null_ _null_ _null_ unknownout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 111 ( numeric_fac PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ numeric_fac _null_ _null_ _null_ "" f)); + +DATA(insert OID = 115 ( box_above_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_above_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 116 ( box_below_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_below_eq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 117 ( point_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "2275" _null_ _null_ _null_ _null_ point_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 118 ( point_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "600" _null_ _null_ _null_ _null_ point_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 119 ( lseg_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "2275" _null_ _null_ _null_ _null_ lseg_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 120 ( lseg_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "601" _null_ _null_ _null_ _null_ lseg_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 121 ( path_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "2275" _null_ _null_ _null_ _null_ path_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 122 ( path_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "602" _null_ _null_ _null_ _null_ path_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 123 ( box_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "2275" _null_ _null_ _null_ _null_ box_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 124 ( box_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "603" _null_ _null_ _null_ _null_ box_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 125 ( box_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 126 ( box_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 127 ( box_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 128 ( box_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 129 ( box_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 130 ( box_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 131 ( point_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 132 ( point_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 133 ( point_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 134 ( point_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 135 ( point_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 136 ( on_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 603" _null_ _null_ _null_ _null_ on_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 137 ( on_ppath PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 602" _null_ _null_ _null_ _null_ on_ppath _null_ _null_ _null_ "" f)); +DATA(insert OID = 138 ( box_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 139 ( areasel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ areasel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for area-comparison operators"); +DATA(insert OID = 140 ( areajoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ areajoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for area-comparison operators"); +DATA(insert OID = 141 ( int4mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 144 ( int4ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 145 ( int2ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 146 ( int2gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 147 ( int4gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 148 ( int2le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2le _null_ _null_ _null_ "" f)); +DATA(insert OID = 149 ( int4le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4le _null_ _null_ _null_ "" f)); +DATA(insert OID = 150 ( int4ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 23" _null_ _null_ _null_ _null_ int4ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 151 ( int2ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 21" _null_ _null_ _null_ _null_ int2ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 152 ( int2mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 153 ( int2div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 21" _null_ _null_ _null_ _null_ int2div _null_ _null_ _null_ "" f)); +DATA(insert OID = 154 ( int4div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 23" _null_ _null_ _null_ _null_ int4div _null_ _null_ _null_ "" f)); +DATA(insert OID = 155 ( int2mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 156 ( int4mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 157 ( textne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textne _null_ _null_ _null_ "" f)); +DATA(insert OID = 158 ( int24eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 159 ( int42eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 160 ( int24lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 161 ( int42lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 162 ( int24gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 163 ( int42gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 164 ( int24ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 165 ( int42ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 166 ( int24le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24le _null_ _null_ _null_ "" f)); +DATA(insert OID = 167 ( int42le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42le _null_ _null_ _null_ "" f)); +DATA(insert OID = 168 ( int24ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 23" _null_ _null_ _null_ _null_ int24ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 169 ( int42ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 21" _null_ _null_ _null_ _null_ int42ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 170 ( int24mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 171 ( int42mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 172 ( int24div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 23" _null_ _null_ _null_ _null_ int24div _null_ _null_ _null_ "" f)); +DATA(insert OID = 173 ( int42div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 21" _null_ _null_ _null_ _null_ int42div _null_ _null_ _null_ "" f)); +DATA(insert OID = 176 ( int2pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 177 ( int4pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 178 ( int24pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 179 ( int42pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 180 ( int2mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 181 ( int4mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 182 ( int24mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ int24mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 183 ( int42mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ int42mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 6109 ( int1pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1pl _null_ _null_ _null_ "" f)); +DESCR("int1 plus"); +DATA(insert OID = 6110 ( int1mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mi _null_ _null_ _null_ "" f)); +DESCR("int1 minus"); +DATA(insert OID = 6111 ( int1mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mul _null_ _null_ _null_ "" f)); +DESCR("int1 multiply"); +DATA(insert OID = 6112 ( int1div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1div _null_ _null_ _null_ "" f)); +DESCR("int1 divid"); +DATA(insert OID = 184 ( oideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 185 ( oidne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidne _null_ _null_ _null_ "" f)); +DATA(insert OID = 186 ( box_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 187 ( box_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 188 ( box_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 189 ( box_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 190 ( box_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 191 ( box_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 192 ( box_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 193 ( box_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 600" _null_ _null_ _null_ _null_ box_contain_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 195 ( pg_node_tree_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 194 "2275" _null_ _null_ _null_ _null_ pg_node_tree_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 196 ( pg_node_tree_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "194" _null_ _null_ _null_ _null_ pg_node_tree_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 197 ( pg_node_tree_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 194 "2281" _null_ _null_ _null_ _null_ pg_node_tree_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 198 ( pg_node_tree_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "194" _null_ _null_ _null_ _null_ pg_node_tree_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* OIDS 200 - 299 */ + +DATA(insert OID = 200 ( float4in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "2275" _null_ _null_ _null_ _null_ float4in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 201 ( float4out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "700" _null_ _null_ _null_ _null_ float4out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 202 ( float4mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 203 ( float4div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4div _null_ _null_ _null_ "" f)); +DATA(insert OID = 204 ( float4pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 205 ( float4mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 206 ( float4um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4um _null_ _null_ _null_ "" f)); +DATA(insert OID = 207 ( float4abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 208 ( float4_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 700" _null_ _null_ _null_ _null_ float4_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 209 ( float4larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 211 ( float4smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "700 700" _null_ _null_ _null_ _null_ float4smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 212 ( int4um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4um _null_ _null_ _null_ "" f)); +DATA(insert OID = 213 ( int2um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2um _null_ _null_ _null_ "" f)); +DATA(insert OID = 6108 ( int1um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "5545" _null_ _null_ _null_ _null_ int1um _null_ _null_ _null_ "" f)); +DESCR("int1um"); +DATA(insert OID = 214 ( float8in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "2275" _null_ _null_ _null_ _null_ float8in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 215 ( float8out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "701" _null_ _null_ _null_ _null_ float8out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 216 ( float8mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 217 ( float8div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8div _null_ _null_ _null_ "" f)); +DATA(insert OID = 218 ( float8pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 219 ( float8mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 220 ( float8um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8um _null_ _null_ _null_ "" f)); +DATA(insert OID = 221 ( float8abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 222 ( float8_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 701" _null_ _null_ _null_ _null_ float8_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 223 ( float8larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 224 ( float8smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ float8smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 225 ( lseg_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "601" _null_ _null_ _null_ _null_ lseg_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 226 ( path_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "602" _null_ _null_ _null_ _null_ path_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 227 ( poly_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "604" _null_ _null_ _null_ _null_ poly_center _null_ _null_ _null_ "" f)); + +DATA(insert OID = 228 ( dround PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dround _null_ _null_ _null_ "" f)); +DESCR("round to nearest integer"); +DATA(insert OID = 229 ( dtrunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtrunc _null_ _null_ _null_ "" f)); +DESCR("truncate to integer"); +DATA(insert OID = 2308 ( ceil PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2320 ( ceiling PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2309 ( floor PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dfloor _null_ _null_ _null_ "" f)); +DESCR("nearest integer <= value"); +DATA(insert OID = 2310 ( sign PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsign _null_ _null_ _null_ "" f)); +DESCR("sign of value"); +DATA(insert OID = 230 ( dsqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsqrt _null_ _null_ _null_ "" f)); +DATA(insert OID = 231 ( dcbrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcbrt _null_ _null_ _null_ "" f)); +DATA(insert OID = 232 ( dpow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DATA(insert OID = 233 ( dexp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dexp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 234 ( dlog1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog1 _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 235 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "21" _null_ _null_ _null_ _null_ i2tod _null_ _null_ _null_ "" f)); +DESCR("convert int2 to float8"); +DATA(insert OID = 236 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "21" _null_ _null_ _null_ _null_ i2tof _null_ _null_ _null_ "" f)); +DESCR("convert int2 to float4"); +DATA(insert OID = 237 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "701" _null_ _null_ _null_ _null_ dtoi2 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int2"); +DATA(insert OID = 238 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "700" _null_ _null_ _null_ _null_ ftoi2 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int2"); +DATA(insert OID = 239 ( line_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "628 628" _null_ _null_ _null_ _null_ line_distance _null_ _null_ _null_ "" f)); + +DATA(insert OID = 240 ( abstimein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 702 "2275" _null_ _null_ _null_ _null_ abstimein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ABSTIMEINFUNCOID 240 +DATA(insert OID = 241 ( abstimeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "702" _null_ _null_ _null_ _null_ abstimeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ABSTIMEOUTFUNCOID 241 +DATA(insert OID = 242 ( reltimein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 703 "2275" _null_ _null_ _null_ _null_ reltimein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define RELTIMEINFUNCOID 242 +DATA(insert OID = 243 ( reltimeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "703" _null_ _null_ _null_ _null_ reltimeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define RELTIMEOUTFUNCOID 243 + +DATA(insert OID = 244 ( timepl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 702 "702 703" _null_ _null_ _null_ _null_ timepl _null_ _null_ _null_ "" f)); +DATA(insert OID = 245 ( timemi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 702 "702 703" _null_ _null_ _null_ _null_ timemi _null_ _null_ _null_ "" f)); +DATA(insert OID = 246 ( tintervalin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 704 "2275" _null_ _null_ _null_ _null_ tintervalin _null_ _null_ _null_ "" f)); +#define TINTERVALINFUNCOID 246 +DESCR("I/O"); +DATA(insert OID = 247 ( tintervalout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "704" _null_ _null_ _null_ _null_ tintervalout _null_ _null_ _null_ "" f)); +#define TINTERVALOUTFUNCOID 247 +DESCR("I/O"); +DATA(insert OID = 248 ( intinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "702 704" _null_ _null_ _null_ _null_ intinterval _null_ _null_ _null_ "" f)); +DATA(insert OID = 249 ( tintervalrel PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "704" _null_ _null_ _null_ _null_ tintervalrel _null_ _null_ _null_ "" f)); +DESCR("tinterval to reltime"); +DATA(insert OID = 250 ( timenow PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 702 "" _null_ _null_ _null_ _null_ timenow _null_ _null_ _null_ "" f)); +DESCR("current date and time (abstime)"); +DATA(insert OID = 251 ( abstimeeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimeeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 252 ( abstimene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimene _null_ _null_ _null_ "" f)); +DATA(insert OID = 253 ( abstimelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 254 ( abstimegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 255 ( abstimele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimele _null_ _null_ _null_ "" f)); +DATA(insert OID = 256 ( abstimege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "702 702" _null_ _null_ _null_ _null_ abstimege _null_ _null_ _null_ "" f)); +DATA(insert OID = 257 ( reltimeeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimeeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 258 ( reltimene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimene _null_ _null_ _null_ "" f)); +DATA(insert OID = 259 ( reltimelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 260 ( reltimegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 261 ( reltimele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimele _null_ _null_ _null_ "" f)); +DATA(insert OID = 262 ( reltimege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "703 703" _null_ _null_ _null_ _null_ reltimege _null_ _null_ _null_ "" f)); +DATA(insert OID = 263 ( tintervalsame PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalsame _null_ _null_ _null_ "" f)); +DATA(insert OID = 264 ( tintervalct PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalct _null_ _null_ _null_ "" f)); +DATA(insert OID = 265 ( tintervalov PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalov _null_ _null_ _null_ "" f)); +DATA(insert OID = 266 ( tintervalleneq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervalleneq _null_ _null_ _null_ "" f)); +DATA(insert OID = 267 ( tintervallenne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenne _null_ _null_ _null_ "" f)); +DATA(insert OID = 268 ( tintervallenlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 269 ( tintervallengt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallengt _null_ _null_ _null_ "" f)); +DATA(insert OID = 270 ( tintervallenle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenle _null_ _null_ _null_ "" f)); +DATA(insert OID = 271 ( tintervallenge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 703" _null_ _null_ _null_ _null_ tintervallenge _null_ _null_ _null_ "" f)); +DATA(insert OID = 272 ( tintervalstart PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "704" _null_ _null_ _null_ _null_ tintervalstart _null_ _null_ _null_ "" f)); +DATA(insert OID = 273 ( tintervalend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "704" _null_ _null_ _null_ _null_ tintervalend _null_ _null_ _null_ "" f)); +DESCR("end of interval"); +DATA(insert OID = 274 ( timeofday PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ timeofday _null_ _null_ _null_ "" f)); +DESCR("current date and time - increments during transactions"); +DATA(insert OID = 275 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "702" _null_ _null_ _null_ _null_ abstime_finite _null_ _null_ _null_ "" f)); +DESCR("finite abstime?"); + +DATA(insert OID = 277 ( inter_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 628" _null_ _null_ _null_ _null_ inter_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 278 ( inter_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 603" _null_ _null_ _null_ _null_ inter_lb _null_ _null_ _null_ "" f)); + +DATA(insert OID = 279 ( float48mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 280 ( float48div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48div _null_ _null_ _null_ "" f)); +DATA(insert OID = 281 ( float48pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 282 ( float48mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "700 701" _null_ _null_ _null_ _null_ float48mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 283 ( float84mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 284 ( float84div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84div _null_ _null_ _null_ "" f)); +DATA(insert OID = 285 ( float84pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 286 ( float84mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 700" _null_ _null_ _null_ _null_ float84mi _null_ _null_ _null_ "" f)); + +DATA(insert OID = 287 ( float4eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 288 ( float4ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 289 ( float4lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 290 ( float4le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4le _null_ _null_ _null_ "" f)); +DATA(insert OID = 291 ( float4gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 292 ( float4ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 700" _null_ _null_ _null_ _null_ float4ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 293 ( float8eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 294 ( float8ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 295 ( float8lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 296 ( float8le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8le _null_ _null_ _null_ "" f)); +DATA(insert OID = 297 ( float8gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 298 ( float8ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 701" _null_ _null_ _null_ _null_ float8ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 299 ( float48eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48eq _null_ _null_ _null_ "" f)); + +/* OIDS 300 - 399 */ + +DATA(insert OID = 300 ( float48ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 301 ( float48lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 302 ( float48le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48le _null_ _null_ _null_ "" f)); +DATA(insert OID = 303 ( float48gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 304 ( float48ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "700 701" _null_ _null_ _null_ _null_ float48ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 305 ( float84eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 306 ( float84ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 307 ( float84lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 308 ( float84le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84le _null_ _null_ _null_ "" f)); +DATA(insert OID = 309 ( float84gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 310 ( float84ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "701 700" _null_ _null_ _null_ _null_ float84ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 320 ( width_bucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "701 701 701 23" _null_ _null_ _null_ _null_ width_bucket_float8 _null_ _null_ _null_ "" f)); +DESCR("bucket number of operand in equidepth histogram"); + +DATA(insert OID = 311 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "700" _null_ _null_ _null_ _null_ ftod _null_ _null_ _null_ "" f)); +DESCR("convert float4 to float8"); +DATA(insert OID = 312 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "701" _null_ _null_ _null_ _null_ dtof _null_ _null_ _null_ "" f)); +DESCR("convert float8 to float4"); +DATA(insert OID = 313 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "21" _null_ _null_ _null_ _null_ i2toi4 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int4"); +DATA(insert OID = 314 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "23" _null_ _null_ _null_ _null_ i4toi2 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int2"); +DATA(insert OID = 315 ( int2vectoreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "22 22" _null_ _null_ _null_ _null_ int2vectoreq _null_ _null_ _null_ "" f)); +DATA(insert OID = 316 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "23" _null_ _null_ _null_ _null_ i4tod _null_ _null_ _null_ "" f)); +DESCR("convert int4 to float8"); +#define INT4TOFLOAT8FUNCOID 316 +DATA(insert OID = 317 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "701" _null_ _null_ _null_ _null_ dtoi4 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int4"); +DATA(insert OID = 318 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "23" _null_ _null_ _null_ _null_ i4tof _null_ _null_ _null_ "" f)); +DESCR("convert int4 to float4"); +DATA(insert OID = 319 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "700" _null_ _null_ _null_ _null_ ftoi4 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int4"); + +DATA(insert OID = 330 ( btgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ btgettuple _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 636 ( btgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ btgetbitmap _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 331 ( btinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btinsert _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 333 ( btbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ btbeginscan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 334 ( btrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btrescan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 335 ( btendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btendscan _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 336 ( btmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btmarkpos _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 337 ( btrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btrestrpos _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 3184 ( btmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btmerge _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 338 ( btbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ btbuild _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 328 ( btbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ btbuildempty _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 332 ( btbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ btbulkdelete _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 972 ( btvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ btvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 276 ( btcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ btcanreturn _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 1268 ( btcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ btcostestimate _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); +DATA(insert OID = 2785 ( btoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ btoptions _null_ _null_ _null_ "" f)); +DESCR("btree(internal)"); + +DATA(insert OID = 339 ( poly_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 340 ( poly_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 341 ( poly_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 342 ( poly_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 343 ( poly_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 344 ( poly_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 345 ( poly_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 346 ( poly_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 347 ( poly_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "2275" _null_ _null_ _null_ _null_ poly_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 348 ( poly_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "604" _null_ _null_ _null_ _null_ poly_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 350 ( btint2cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 21" _null_ _null_ _null_ _null_ btint2cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3129 ( btint2sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint2sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 351 ( btint4cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ btint4cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3130 ( btint4sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint4sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 842 ( btint8cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 20" _null_ _null_ _null_ _null_ btint8cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3131 ( btint8sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btint8sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 354 ( btfloat4cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 700" _null_ _null_ _null_ _null_ btfloat4cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3132 ( btfloat4sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btfloat4sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 355 ( btfloat8cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 701" _null_ _null_ _null_ _null_ btfloat8cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3133 ( btfloat8sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btfloat8sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 356 ( btoidcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 26" _null_ _null_ _null_ _null_ btoidcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3134 ( btoidsortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btoidsortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 404 ( btoidvectorcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 30" _null_ _null_ _null_ _null_ btoidvectorcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 357 ( btabstimecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 702" _null_ _null_ _null_ _null_ btabstimecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 358 ( btcharcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 18" _null_ _null_ _null_ _null_ btcharcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 359 ( btnamecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 19" _null_ _null_ _null_ _null_ btnamecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3135 ( btnamesortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ btnamesortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 360 ( bttextcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ bttextcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3255 ( bttextsortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bttextsortsupport _null_ _null_ _null_ ""f)); +DESCR("sort support"); +DATA(insert OID = 377 ( cash_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 790" _null_ _null_ _null_ _null_ cash_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 380 ( btreltimecmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 703" _null_ _null_ _null_ _null_ btreltimecmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 381 ( bttintervalcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "704 704" _null_ _null_ _null_ _null_ bttintervalcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 382 ( btarraycmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 2277" _null_ _null_ _null_ _null_ btarraycmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 361 ( lseg_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 601" _null_ _null_ _null_ _null_ lseg_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 362 ( lseg_interpt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 601" _null_ _null_ _null_ _null_ lseg_interpt _null_ _null_ _null_ "" f)); +DATA(insert OID = 363 ( dist_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 601" _null_ _null_ _null_ _null_ dist_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 364 ( dist_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 603" _null_ _null_ _null_ _null_ dist_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 365 ( dist_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 603" _null_ _null_ _null_ _null_ dist_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 366 ( close_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 601" _null_ _null_ _null_ _null_ close_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 367 ( close_pb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 603" _null_ _null_ _null_ _null_ close_pb _null_ _null_ _null_ "" f)); +DATA(insert OID = 368 ( close_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 603" _null_ _null_ _null_ _null_ close_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 369 ( on_ps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 601" _null_ _null_ _null_ _null_ on_ps _null_ _null_ _null_ "" f)); +DATA(insert OID = 370 ( path_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "602 602" _null_ _null_ _null_ _null_ path_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 371 ( dist_ppath PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 602" _null_ _null_ _null_ _null_ dist_ppath _null_ _null_ _null_ "" f)); +DATA(insert OID = 372 ( on_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 603" _null_ _null_ _null_ _null_ on_sb _null_ _null_ _null_ "" f)); +DATA(insert OID = 373 ( inter_sb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 603" _null_ _null_ _null_ _null_ inter_sb _null_ _null_ _null_ "" f)); + +/* OIDS 400 - 499 */ + +DATA(insert OID = 401 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1042" _null_ _null_ _null_ _null_ rtrim1 _null_ _null_ _null_ "" f)); +DESCR("convert char(n) to text"); +#define RTRIM1FUNCOID 401 +DATA(insert OID = 406 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "19" _null_ _null_ _null_ _null_ name_text _null_ _null_ _null_ "" f)); +DESCR("convert name to text"); +DATA(insert OID = 407 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "25" _null_ _null_ _null_ _null_ text_name _null_ _null_ _null_ "" f)); +DESCR("convert text to name"); +DATA(insert OID = 408 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "19" _null_ _null_ _null_ _null_ name_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert name to char(n)"); +DATA(insert OID = 409 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "1042" _null_ _null_ _null_ _null_ bpchar_name _null_ _null_ _null_ "" f)); +DESCR("convert char(n) to name"); + +DATA(insert OID = 440 ( hashgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ hashgettuple _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 637 ( hashgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ hashgetbitmap _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 441 ( hashinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashinsert _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 443 ( hashbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ hashbeginscan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 444 ( hashrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashrescan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 445 ( hashendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashendscan _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 446 ( hashmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashmarkpos _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 447 ( hashrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashrestrpos _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 3185 ( hashmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashmerge _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 448 ( hashbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ hashbuild _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 327 ( hashbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ hashbuildempty _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 442 ( hashbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashbulkdelete _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 425 ( hashvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ hashvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 438 ( hashcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ hashcostestimate _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 2786 ( hashoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ hashoptions _null_ _null_ _null_ "" f)); +DESCR("hash(internal)"); +DATA(insert OID = 5520 ( hashint1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "5545" _null_ _null_ _null_ _null_ hashint1 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 449 ( hashint2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "21" _null_ _null_ _null_ _null_ hashint2 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 450 ( hashint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ hashint4 _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHINT4OID 450 +DATA(insert OID = 949 ( hashint8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "20" _null_ _null_ _null_ _null_ hashint8 _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHINT8OID 949 +DATA(insert OID = 451 ( hashfloat4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "700" _null_ _null_ _null_ _null_ hashfloat4 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 452 ( hashfloat8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "701" _null_ _null_ _null_ _null_ hashfloat8 _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 453 ( hashoid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "26" _null_ _null_ _null_ _null_ hashoid _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 454 ( hashchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "18" _null_ _null_ _null_ _null_ hashchar _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 455 ( hashname PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "19" _null_ _null_ _null_ _null_ hashname _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 400 ( hashtext PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ hashtext _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHTEXTOID 400 +DATA(insert OID = 456 ( hashvarlena PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2281" _null_ _null_ _null_ _null_ hashvarlena _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 457 ( hashoidvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "30" _null_ _null_ _null_ _null_ hashoidvector _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 329 ( hash_aclitem PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1033" _null_ _null_ _null_ _null_ hash_aclitem _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 398 ( hashint2vector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "22" _null_ _null_ _null_ _null_ hashint2vector _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 399 ( hashmacaddr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "829" _null_ _null_ _null_ _null_ hashmacaddr _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 422 ( hashinet PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ hashinet _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 432 ( hash_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1700" _null_ _null_ _null_ _null_ hash_numeric _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 458 ( text_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ text_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 459 ( text_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ text_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 460 ( int8in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2275" _null_ _null_ _null_ _null_ int8in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 461 ( int8out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "20" _null_ _null_ _null_ _null_ int8out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 462 ( int8um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8um _null_ _null_ _null_ "" f)); +DATA(insert OID = 463 ( int8pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 464 ( int8mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 465 ( int8mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 466 ( int8div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 20" _null_ _null_ _null_ _null_ int8div _null_ _null_ _null_ "" f)); +DATA(insert OID = 467 ( int8eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 468 ( int8ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 469 ( int8lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 470 ( int8gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 471 ( int8le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8le _null_ _null_ _null_ "" f)); +DATA(insert OID = 472 ( int8ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 20" _null_ _null_ _null_ _null_ int8ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 474 ( int84eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 475 ( int84ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 476 ( int84lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 477 ( int84gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 478 ( int84le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84le _null_ _null_ _null_ "" f)); +DATA(insert OID = 479 ( int84ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 23" _null_ _null_ _null_ _null_ int84ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3177 ( int8_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "20" _null_ _null_ _null_ _null_ int8_bool _null_ _null_ _null_ "" f)); +DESCR("convert int8 to boolean"); +DATA(insert OID = 3178 ( bool_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "16" _null_ _null_ _null_ _null_ bool_int8 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int8"); + +DATA(insert OID = 3180 ( int2_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "21" _null_ _null_ _null_ _null_ int2_bool _null_ _null_ _null_ "" f)); +DESCR("convert int2 to boolean"); +DATA(insert OID = 3181 ( bool_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "16" _null_ _null_ _null_ _null_ bool_int2 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int2"); + + +DATA(insert OID = 480 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "20" _null_ _null_ _null_ _null_ int84 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int4"); +DATA(insert OID = 481 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "23" _null_ _null_ _null_ _null_ int48 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int8"); +DATA(insert OID = 482 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "20" _null_ _null_ _null_ _null_ i8tod _null_ _null_ _null_ "" f)); +DESCR("convert int8 to float8"); +DATA(insert OID = 483 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "701" _null_ _null_ _null_ _null_ dtoi8 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int8"); + +/* OIDS 500 - 599 */ + +/* OIDS 600 - 699 */ + +DATA(insert OID = 626 ( hash_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ hash_array _null_ _null_ _null_ "" f)); +DESCR("hash"); + +DATA(insert OID = 652 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "20" _null_ _null_ _null_ _null_ i8tof _null_ _null_ _null_ "" f)); +DESCR("convert int8 to float4"); +DATA(insert OID = 653 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "700" _null_ _null_ _null_ _null_ ftoi8 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int8"); + +DATA(insert OID = 714 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "20" _null_ _null_ _null_ _null_ int82 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int2"); +DATA(insert OID = 754 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "21" _null_ _null_ _null_ _null_ int28 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int8"); + +DATA(insert OID = 655 ( namelt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namelt _null_ _null_ _null_ "" f)); +DATA(insert OID = 656 ( namele PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namele _null_ _null_ _null_ "" f)); +DATA(insert OID = 657 ( namegt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namegt _null_ _null_ _null_ "" f)); +DATA(insert OID = 658 ( namege PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namege _null_ _null_ _null_ "" f)); +DATA(insert OID = 659 ( namene PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "19 19" _null_ _null_ _null_ _null_ namene _null_ _null_ _null_ "" f)); + +DATA(insert OID = 668 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1042 "1042 23 16" _null_ _null_ _null_ _null_ bpchar _null_ _null_ _null_ "" f)); +DESCR("adjust char() to typmod length"); +DATA(insert OID = 3097 ( varchar_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ varchar_transform _null_ _null_ _null_ "" f)); +DESCR("transform a varchar length coercion"); +DATA(insert OID = 669 ( varchar PGNSP PGUID 12 1 0 0 varchar_transform f f f f t f i 3 0 1043 "1043 23 16" _null_ _null_ _null_ _null_ varchar _null_ _null_ _null_ "" f)); +DESCR("adjust varchar() to typmod length"); +DATA(insert OID = 3961 ( nvarchar2 PGNSP PGUID 12 1 0 0 varchar_transform f f f f t f i 3 0 3969 "3969 23 16" _null_ _null_ _null_ _null_ nvarchar2 _null_ _null_ _null_ "" f)); +DESCR("adjust nvarchar2() to typmod length"); + +DATA(insert OID = 676 ( mktinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 704 "702 702" _null_ _null_ _null_ _null_ mktinterval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 619 ( oidvectorne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorne _null_ _null_ _null_ "" f)); +DATA(insert OID = 677 ( oidvectorlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 678 ( oidvectorle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorle _null_ _null_ _null_ "" f)); +DATA(insert OID = 679 ( oidvectoreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectoreq _null_ _null_ _null_ "" f)); +DATA(insert OID = 680 ( oidvectorge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorge _null_ _null_ _null_ "" f)); +DATA(insert OID = 681 ( oidvectorgt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "30 30" _null_ _null_ _null_ _null_ oidvectorgt _null_ _null_ _null_ "" f)); + +/* OIDS 700 - 799 */ +DATA(insert OID = 710 ( getpgusername PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_user _null_ _null_ _null_ "" f)); +DESCR("deprecated, use current_user instead"); +DATA(insert OID = 716 ( oidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 717 ( oidle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidle _null_ _null_ _null_ "" f)); + +DATA(insert OID = 720 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ byteaoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 721 ( get_byte PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ byteaGetByte _null_ _null_ _null_ "" f)); +DESCR("get byte"); +DATA(insert OID = 722 ( set_byte PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ byteaSetByte _null_ _null_ _null_ "" f)); +DESCR("set byte"); +DATA(insert OID = 723 ( get_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ byteaGetBit _null_ _null_ _null_ "" f)); +DESCR("get bit"); +DATA(insert OID = 724 ( set_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ byteaSetBit _null_ _null_ _null_ "" f)); +DESCR("set bit"); +DATA(insert OID = 749 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 17 "17 17 23 23" _null_ _null_ _null_ _null_ byteaoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); +DATA(insert OID = 752 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 17 23" _null_ _null_ _null_ _null_ byteaoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); + +DATA(insert OID = 725 ( dist_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 628" _null_ _null_ _null_ _null_ dist_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 726 ( dist_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "628 603" _null_ _null_ _null_ _null_ dist_lb _null_ _null_ _null_ "" f)); +DATA(insert OID = 727 ( dist_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "601 628" _null_ _null_ _null_ _null_ dist_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 728 ( dist_cpoly PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "718 604" _null_ _null_ _null_ _null_ dist_cpoly _null_ _null_ _null_ "" f)); +DATA(insert OID = 729 ( poly_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "604 604" _null_ _null_ _null_ _null_ poly_distance _null_ _null_ _null_ "" f)); + +DATA(insert OID = 740 ( text_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 741 ( text_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 742 ( text_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 743 ( text_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 745 ( current_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_user _null_ _null_ _null_ "" f)); +DESCR("current user name"); +DATA(insert OID = 3216 ( definer_current_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pseudo_current_user _null_ _null_ _null_ "" f)); +DATA(insert OID = 746 ( session_user PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ session_user _null_ _null_ _null_ "" f)); +DESCR("session user name"); + +DATA(insert OID = 744 ( array_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 390 ( array_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 391 ( array_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 392 ( array_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 393 ( array_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 396 ( array_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ array_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 747 ( array_dims PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2277" _null_ _null_ _null_ _null_ array_dims _null_ _null_ _null_ "" f)); +DESCR("array dimensions"); +DATA(insert OID = 748 ( array_ndims PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2277" _null_ _null_ _null_ _null_ array_ndims _null_ _null_ _null_ "" f)); +DESCR("number of array dimensions"); +DATA(insert OID = 750 ( array_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2275 26 23" _null_ _null_ _null_ _null_ array_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 756 ( complex_array_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2275 26 2275" _null_ _null_ _null_ _null_ complex_array_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 751 ( array_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2277" _null_ _null_ _null_ _null_ array_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2091 ( array_lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_lower _null_ _null_ _null_ "" f)); +DESCR("array lower dimension"); +DATA(insert OID = 2092 ( array_upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_upper _null_ _null_ _null_ "" f)); +DESCR("array upper dimension"); +DATA(insert OID = 2176 ( array_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ array_length _null_ _null_ _null_ "" f)); +DESCR("array length"); +DATA(insert OID = 378 ( array_append PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2277 2283" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ "" f)); +DATA(insert OID = 3179 ( array_extend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "23" _null_ _null_ _null_ _null_ array_extend _null_ _null_ _null_ "" f)); +DESCR("array extend"); +DESCR("append element onto end of array"); +DATA(insert OID = 379 ( array_prepend PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2283 2277" _null_ _null_ _null_ _null_ array_push _null_ _null_ _null_ "" f)); +DESCR("prepend element onto front of array"); +DATA(insert OID = 383 ( array_cat PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_cat _null_ _null_ _null_ "" f)); +DATA(insert OID = 394 ( string_to_array PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ text_to_array _null_ _null_ _null_ "" f)); +DESCR("split delimited text into text[]"); +DATA(insert OID = 395 ( array_to_string PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "2277 25" _null_ _null_ _null_ _null_ array_to_text _null_ _null_ _null_ "" f)); +DESCR("concatenate array elements, using delimiter, into text"); +#define ARRAYTOSTRINGFUNCOID 395 +DATA(insert OID = 376 ( string_to_array PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ text_to_array_null _null_ _null_ _null_ "" f)); +DESCR("split delimited text into text[], with null string"); +DATA(insert OID = 384 ( array_to_string PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 25 "2277 25 25" _null_ _null_ _null_ _null_ array_to_text_null _null_ _null_ _null_ "" f)); +DESCR("concatenate array elements, using delimiter and null string, into text"); +#define ARRAYTOSTRINGNULLFUNCOID 384 +DATA(insert OID = 515 ( array_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 516 ( array_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2277 "2277 2277" _null_ _null_ _null_ _null_ array_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1191 ( generate_subscripts PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 23 "2277 23 16" _null_ _null_ _null_ _null_ generate_subscripts _null_ _null_ _null_ "" f)); +DESCR("array subscripts generator"); +DATA(insert OID = 1192 ( generate_subscripts PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 23 "2277 23" _null_ _null_ _null_ _null_ generate_subscripts_nodir _null_ _null_ _null_ "" f)); +DESCR("array subscripts generator"); +DATA(insert OID = 1193 ( array_fill PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2277 "2283 1007" _null_ _null_ _null_ _null_ array_fill _null_ _null_ _null_ "" f)); +DESCR("array constructor with value"); +DATA(insert OID = 1286 ( array_fill PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2277 "2283 1007 1007" _null_ _null_ _null_ _null_ array_fill_with_lower_bounds _null_ _null_ _null_ "" f)); +DESCR("array constructor with value"); +DATA(insert OID = 2331 ( unnest PGNSP PGUID 12 1 100 0 0 f f f f t t i 1 0 2283 "2277" _null_ _null_ _null_ _null_ array_unnest _null_ _null_ _null_ "" f)); +DESCR("expand array to set of rows"); +DATA(insert OID = 2333 ( array_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 2281 "2281 2283" _null_ _null_ _null_ _null_ array_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2334 ( array_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2277 "2281" _null_ _null_ _null_ _null_ array_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2335 ( array_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2283" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into an array"); +#define ARRAYAGGFUNCOID 2335 +DATA(insert OID = 3816 ( array_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ array_typanalyze _null_ _null_ _null_ "" f)); +DESCR("array typanalyze"); +DATA(insert OID = 3817 ( arraycontsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ arraycontsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for array-containment operators"); +DATA(insert OID = 3818 ( arraycontjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ arraycontjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for array-containment operators"); + +DATA(insert OID = 760 ( smgrin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 210 "2275" _null_ _null_ _null_ _null_ smgrin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 761 ( smgrout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "210" _null_ _null_ _null_ _null_ smgrout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 762 ( smgreq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "210 210" _null_ _null_ _null_ _null_ smgreq _null_ _null_ _null_ "" f)); +DESCR("storage manager"); +DATA(insert OID = 763 ( smgrne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "210 210" _null_ _null_ _null_ _null_ smgrne _null_ _null_ _null_ "" f)); +DESCR("storage manager"); + +DATA(insert OID = 764 ( lo_import PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "25" _null_ _null_ _null_ _null_ lo_import _null_ _null_ _null_ "" f)); +DESCR("large object import"); +DATA(insert OID = 767 ( lo_import PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 26 "25 26" _null_ _null_ _null_ _null_ lo_import_with_oid _null_ _null_ _null_ "" f)); +DESCR("large object import"); +DATA(insert OID = 765 ( lo_export PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "26 25" _null_ _null_ _null_ _null_ lo_export _null_ _null_ _null_ "" f)); +DESCR("large object export"); +DATA(insert OID = 6117 ( int1inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 766 ( int4inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 768 ( int4larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 769 ( int4smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 770 ( int2larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 771 ( int2smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 6115 ( int1larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 6116 ( int1smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 774 ( gistgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ gistgettuple _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 638 ( gistgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ gistgetbitmap _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 775 ( gistinsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistinsert _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 777 ( gistbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gistbeginscan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 778 ( gistrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistrescan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 779 ( gistendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistendscan _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 780 ( gistmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistmarkpos _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 781 ( gistrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistrestrpos _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 3187 ( gistmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistmerge _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 782 ( gistbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gistbuild _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 326 ( gistbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ gistbuildempty _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 776 ( gistbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistbulkdelete _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 2561 ( gistvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gistvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 772 ( gistcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gistcostestimate _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); +DATA(insert OID = 2787 ( gistoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ gistoptions _null_ _null_ _null_ "" f)); +DESCR("gist(internal)"); + +DATA(insert OID = 784 ( tintervaleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervaleq _null_ _null_ _null_ "" f)); +DATA(insert OID = 785 ( tintervalne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalne _null_ _null_ _null_ "" f)); +DATA(insert OID = 786 ( tintervallt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervallt _null_ _null_ _null_ "" f)); +DATA(insert OID = 787 ( tintervalgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 788 ( tintervalle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalle _null_ _null_ _null_ "" f)); +DATA(insert OID = 789 ( tintervalge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "704 704" _null_ _null_ _null_ _null_ tintervalge _null_ _null_ _null_ "" f)); + +/* OIDS 800 - 899 */ + +DATA(insert OID = 846 ( cash_mul_flt4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 700" _null_ _null_ _null_ _null_ cash_mul_flt4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 847 ( cash_div_flt4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 700" _null_ _null_ _null_ _null_ cash_div_flt4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 848 ( flt4_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "700 790" _null_ _null_ _null_ _null_ flt4_mul_cash _null_ _null_ _null_ "" f)); + +DATA(insert OID = 849 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define POSITIONFUNCOID 849 +DATA(insert OID = 850 ( textlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 851 ( textnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 852 ( int48eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 853 ( int48ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 854 ( int48lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 855 ( int48gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 856 ( int48le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48le _null_ _null_ _null_ "" f)); +DATA(insert OID = 857 ( int48ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "23 20" _null_ _null_ _null_ _null_ int48ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 858 ( namelike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namelike _null_ _null_ _null_ "" f)); +DATA(insert OID = 859 ( namenlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namenlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 860 ( bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "18" _null_ _null_ _null_ _null_ char_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert char to char(n)"); + +DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_database _null_ _null_ _null_ "" f)); +DESCR("name of the current database"); +DATA(insert OID = 817 ( current_query PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 25 "" _null_ _null_ _null_ _null_ current_query _null_ _null_ _null_ "" f)); +DESCR("get the currently executing query"); + +DATA(insert OID = 862 ( int4_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "23 790" _null_ _null_ _null_ _null_ int4_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 863 ( int2_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "21 790" _null_ _null_ _null_ _null_ int2_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 864 ( cash_mul_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 23" _null_ _null_ _null_ _null_ cash_mul_int4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 865 ( cash_div_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 23" _null_ _null_ _null_ _null_ cash_div_int4 _null_ _null_ _null_ "" f)); +DATA(insert OID = 866 ( cash_mul_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 21" _null_ _null_ _null_ _null_ cash_mul_int2 _null_ _null_ _null_ "" f)); +DATA(insert OID = 867 ( cash_div_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 21" _null_ _null_ _null_ _null_ cash_div_int2 _null_ _null_ _null_ "" f)); + +DATA(insert OID = 886 ( cash_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "2275" _null_ _null_ _null_ _null_ cash_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define CASHINFUNCOID 886 +DATA(insert OID = 887 ( cash_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "790" _null_ _null_ _null_ _null_ cash_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define CASHOUTFUNCOID 887 +DATA(insert OID = 888 ( cash_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 889 ( cash_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 890 ( cash_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 891 ( cash_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 892 ( cash_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 893 ( cash_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "790 790" _null_ _null_ _null_ _null_ cash_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 894 ( cash_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cash_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 895 ( cash_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cash_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 896 ( cash_mul_flt8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 701" _null_ _null_ _null_ _null_ cash_mul_flt8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 897 ( cash_div_flt8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 701" _null_ _null_ _null_ _null_ cash_div_flt8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 898 ( cashlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cashlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 899 ( cashsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "790 790" _null_ _null_ _null_ _null_ cashsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 919 ( flt8_mul_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 790 "701 790" _null_ _null_ _null_ _null_ flt8_mul_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 935 ( cash_words PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "790" _null_ _null_ _null_ _null_ cash_words _null_ _null_ _null_ "" f)); +DESCR("output money amount as words"); +DATA(insert OID = 3822 ( cash_div_cash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "790 790" _null_ _null_ _null_ _null_ cash_div_cash _null_ _null_ _null_ "" f)); +DATA(insert OID = 3823 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1700 "790" _null_ _null_ _null_ _null_ cash_numeric _null_ _null_ _null_ "" f)); +DESCR("convert money to numeric"); +#define CASH2NUMERICFUNCOID 3823 +DATA(insert OID = 3824 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "1700" _null_ _null_ _null_ _null_ numeric_cash _null_ _null_ _null_ "" f)); +DESCR("convert numeric to money"); +#define NUMERIC2CASHFUNCOID 3824 +DATA(insert OID = 3811 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "23" _null_ _null_ _null_ _null_ int4_cash _null_ _null_ _null_ "" f)); +DESCR("convert int4 to money"); +#define INTEGER2CASHFUNCOID 3811 +DATA(insert OID = 3812 ( money PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 790 "20" _null_ _null_ _null_ _null_ int8_cash _null_ _null_ _null_ "" f)); +DESCR("convert int8 to money"); +#define BIGINT2CASHFUNCOID 3812 + + +/* OIDS 900 - 999 */ +DATA(insert OID = 6114 ( int1mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 940 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 941 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); + +DATA(insert OID = 945 ( int8mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 947 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); + +DATA(insert OID = 944 ( char PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "25" _null_ _null_ _null_ _null_ text_char _null_ _null_ _null_ "" f)); +DESCR("convert text to char"); +DATA(insert OID = 946 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "18" _null_ _null_ _null_ _null_ char_text _null_ _null_ _null_ "" f)); +DESCR("convert char to text"); + +DATA(insert OID = 952 ( lo_open PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "26 23" _null_ _null_ _null_ _null_ lo_open _null_ _null_ _null_ "" f)); +DESCR("large object open"); +DATA(insert OID = 953 ( lo_close PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "23" _null_ _null_ _null_ _null_ lo_close _null_ _null_ _null_ "" f)); +DESCR("large object close"); +DATA(insert OID = 954 ( loread PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 17 "23 23" _null_ _null_ _null_ _null_ loread _null_ _null_ _null_ "" f)); +DESCR("large object read"); +DATA(insert OID = 955 ( lowrite PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "23 17" _null_ _null_ _null_ _null_ lowrite _null_ _null_ _null_ "" f)); +DESCR("large object write"); +DATA(insert OID = 956 ( lo_lseek PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ lo_lseek _null_ _null_ _null_ "" f)); +DESCR("large object seek"); +DATA(insert OID = 957 ( lo_creat PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "23" _null_ _null_ _null_ _null_ lo_creat _null_ _null_ _null_ "" f)); +DESCR("large object create"); +DATA(insert OID = 715 ( lo_create PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 26 "26" _null_ _null_ _null_ _null_ lo_create _null_ _null_ _null_ "" f)); +DESCR("large object create"); +DATA(insert OID = 958 ( lo_tell PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "23" _null_ _null_ _null_ _null_ lo_tell _null_ _null_ _null_ "" f)); +DESCR("large object position"); +DATA(insert OID = 1004 ( lo_truncate PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 23 "23 23" _null_ _null_ _null_ _null_ lo_truncate _null_ _null_ _null_ "" f)); +DESCR("truncate large object"); + +DATA(insert OID = 959 ( on_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 628" _null_ _null_ _null_ _null_ on_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 960 ( on_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 628" _null_ _null_ _null_ _null_ on_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 961 ( close_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 628" _null_ _null_ _null_ _null_ close_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 962 ( close_sl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 628" _null_ _null_ _null_ _null_ close_sl _null_ _null_ _null_ "" f)); +DATA(insert OID = 963 ( close_lb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 603" _null_ _null_ _null_ _null_ close_lb _null_ _null_ _null_ "" f)); + +DATA(insert OID = 964 ( lo_unlink PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 23 "26" _null_ _null_ _null_ _null_ lo_unlink _null_ _null_ _null_ "" f)); +DESCR("large object unlink (delete)"); + +DATA(insert OID = 973 ( path_inter PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_inter _null_ _null_ _null_ "" f)); +DATA(insert OID = 975 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_area _null_ _null_ _null_ "" f)); +DESCR("box area"); +DATA(insert OID = 976 ( width PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_width _null_ _null_ _null_ "" f)); +DESCR("box width"); +DATA(insert OID = 977 ( height PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "603" _null_ _null_ _null_ _null_ box_height _null_ _null_ _null_ "" f)); +DESCR("box height"); +DATA(insert OID = 978 ( box_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "603 603" _null_ _null_ _null_ _null_ box_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 979 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_area _null_ _null_ _null_ "" f)); +DESCR("area of a closed path"); +DATA(insert OID = 980 ( box_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 603" _null_ _null_ _null_ _null_ box_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 981 ( diagonal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "603" _null_ _null_ _null_ _null_ box_diagonal _null_ _null_ _null_ "" f)); +DESCR("box diagonal"); +DATA(insert OID = 982 ( path_n_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 983 ( path_n_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 984 ( path_n_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 985 ( path_n_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 986 ( path_n_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "602 602" _null_ _null_ _null_ _null_ path_n_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 987 ( path_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_length _null_ _null_ _null_ "" f)); +DATA(insert OID = 988 ( point_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 989 ( point_vert PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_vert _null_ _null_ _null_ "" f)); +DATA(insert OID = 990 ( point_horiz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_horiz _null_ _null_ _null_ "" f)); +DATA(insert OID = 991 ( point_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 600" _null_ _null_ _null_ _null_ point_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 992 ( slope PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 600" _null_ _null_ _null_ _null_ point_slope _null_ _null_ _null_ "" f)); +DESCR("slope between points"); +DATA(insert OID = 993 ( lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 601 "600 600" _null_ _null_ _null_ _null_ lseg_construct _null_ _null_ _null_ "" f)); +DESCR("convert points to line segment"); +DATA(insert OID = 994 ( lseg_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 995 ( lseg_parallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_parallel _null_ _null_ _null_ "" f)); +DATA(insert OID = 996 ( lseg_perp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_perp _null_ _null_ _null_ "" f)); +DATA(insert OID = 997 ( lseg_vertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_vertical _null_ _null_ _null_ "" f)); +DATA(insert OID = 998 ( lseg_horizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_horizontal _null_ _null_ _null_ "" f)); +DATA(insert OID = 999 ( lseg_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_eq _null_ _null_ _null_ "" f)); + +/* OIDS 1000 - 1999 */ + +DATA(insert OID = 1026 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1186 1184" _null_ _null_ _null_ _null_ timestamptz_izone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); + +DATA(insert OID = 1031 ( aclitemin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1033 "2275" _null_ _null_ _null_ _null_ aclitemin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1032 ( aclitemout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1033" _null_ _null_ _null_ _null_ aclitemout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1035 ( aclinsert PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "1034 1033" _null_ _null_ _null_ _null_ aclinsert _null_ _null_ _null_ "" f)); +DESCR("add/update ACL item"); +DATA(insert OID = 1036 ( aclremove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "1034 1033" _null_ _null_ _null_ _null_ aclremove _null_ _null_ _null_ "" f)); +DESCR("remove ACL item"); +DATA(insert OID = 1037 ( aclcontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1034 1033" _null_ _null_ _null_ _null_ aclcontains _null_ _null_ _null_ "" f)); +DESCR("contains"); +DATA(insert OID = 1062 ( aclitemeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1033 1033" _null_ _null_ _null_ _null_ aclitem_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1365 ( makeaclitem PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 1033 "26 26 25 16" _null_ _null_ _null_ _null_ makeaclitem _null_ _null_ _null_ "" f)); +DESCR("make ACL item"); +DATA(insert OID = 3943 ( acldefault PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1034 "18 26" _null_ _null_ _null_ _null_ acldefault_sql _null_ _null_ _null_ "" f)); +DESCR("TODO"); +DATA(insert OID = 1689 ( aclexplode PGNSP PGUID 12 1 10 0 0 f f f f t t s 1 0 2249 "1034" "{1034,26,26,25,16}" "{i,o,o,o,o}" "{acl,grantor,grantee,privilege_type,is_grantable}" _null_ aclexplode _null_ _null_ _null_ "" f)); +DESCR("convert ACL item array to table, for use by information schema"); +DATA(insert OID = 1044 ( bpcharin PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1042 "2275 26 23" _null_ _null_ _null_ _null_ bpcharin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1045 ( bpcharout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1042" _null_ _null_ _null_ _null_ bpcharout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2913 ( bpchartypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ bpchartypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2914 ( bpchartypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ bpchartypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1046 ( varcharin PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1043 "2275 26 23" _null_ _null_ _null_ _null_ varcharin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1047 ( varcharout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1043" _null_ _null_ _null_ _null_ varcharout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3962 ( nvarchar2in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 3969 "2275 26 23" _null_ _null_ _null_ _null_ nvarchar2in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3963 ( nvarchar2out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3969" _null_ _null_ _null_ _null_ nvarchar2out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3964 ( nvarchar2typmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ nvarchar2typmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 3965 ( nvarchar2typmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ nvarchar2typmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2915 ( varchartypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ varchartypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2916 ( varchartypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ varchartypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1048 ( bpchareq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchareq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1049 ( bpcharlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1050 ( bpcharle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1051 ( bpchargt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchargt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1052 ( bpcharge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1053 ( bpcharne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpcharne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1063 ( bpchar_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1042 "1042 1042" _null_ _null_ _null_ _null_ bpchar_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1064 ( bpchar_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1042 "1042 1042" _null_ _null_ _null_ _null_ bpchar_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1078 ( bpcharcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 1042" _null_ _null_ _null_ _null_ bpcharcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3256 ( bpchar_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bpchar_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 1080 ( hashbpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ hashbpchar _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define HASHBPCHAROID 1080 +DATA(insert OID = 1081 ( format_type PGNSP PGUID 12 1 0 0 0 f f f f f f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ format_type _null_ _null_ _null_ "" f)); +DESCR("format a type oid and atttypmod to canonical SQL"); +DATA(insert OID = 1084 ( date_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "2275" _null_ _null_ _null_ _null_ date_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define DATEINFUNCOID 1084 +DATA(insert OID = 1085 ( date_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1082" _null_ _null_ _null_ _null_ date_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define DATEOUTFUNCOID 1085 +DATA(insert OID = 1086 ( date_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1087 ( date_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1088 ( date_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1089 ( date_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1090 ( date_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1091 ( date_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1082 1082" _null_ _null_ _null_ _null_ date_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1092 ( date_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1082" _null_ _null_ _null_ _null_ date_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3136 ( date_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ date_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); + +/* OIDS 1100 - 1199 */ + +DATA(insert OID = 1102 ( time_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1103 ( time_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1104 ( time_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1105 ( time_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1106 ( time_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1107 ( time_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 1083" _null_ _null_ _null_ _null_ time_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1138 ( date_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 1082" _null_ _null_ _null_ _null_ date_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1139 ( date_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 1082" _null_ _null_ _null_ _null_ date_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1140 ( date_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1082" _null_ _null_ _null_ _null_ date_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1141 ( date_pli PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 23" _null_ _null_ _null_ _null_ date_pli _null_ _null_ _null_ "" f)); +DATA(insert OID = 1142 ( date_mii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1082 "1082 23" _null_ _null_ _null_ _null_ date_mii _null_ _null_ _null_ "" f)); +DATA(insert OID = 1143 ( time_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1083 "2275 26 23" _null_ _null_ _null_ _null_ time_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMEINFUNCOID 1143 +DATA(insert OID = 1144 ( time_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1083" _null_ _null_ _null_ _null_ time_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMEOUTFUNCOID 1144 +DATA(insert OID = 2909 ( timetypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timetypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2910 ( timetypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timetypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1145 ( time_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1083 1083" _null_ _null_ _null_ _null_ time_eq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1146 ( circle_add_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_add_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1147 ( circle_sub_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_sub_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1148 ( circle_mul_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_mul_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1149 ( circle_div_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "718 600" _null_ _null_ _null_ _null_ circle_div_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1150 ( timestamptz_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1184 "2275 26 23" _null_ _null_ _null_ _null_ timestamptz_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPTZINFUNCOID 1150 +DATA(insert OID = 1151 ( timestamptz_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1184" _null_ _null_ _null_ _null_ timestamptz_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPTZOUTFUNCOID 1151 +DATA(insert OID = 2907 ( timestamptztypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timestamptztypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2908 ( timestamptztypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timestamptztypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1152 ( timestamptz_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1153 ( timestamptz_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1154 ( timestamptz_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1155 ( timestamptz_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1156 ( timestamptz_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1157 ( timestamptz_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1184 1184" _null_ _null_ _null_ _null_ timestamp_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1158 ( to_timestamp PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1184 "701" _null_ _null_ _null_ _null_ "select (''epoch''::pg_catalog.timestamptz + $1 * ''1 second''::pg_catalog.interval)" _null_ _null_ _null_ "" f)); +DESCR("convert UNIX epoch to timestamptz"); +DATA(insert OID = 1159 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "25 1184" _null_ _null_ _null_ _null_ timestamptz_zone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); + +DATA(insert OID = 1160 ( interval_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1186 "2275 26 23" _null_ _null_ _null_ _null_ interval_in _null_ _null_ _null_ "" f)); +#define INTERVALINFUNCOID 1160 +DESCR("I/O"); +DATA(insert OID = 1161 ( interval_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1186" _null_ _null_ _null_ _null_ interval_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2903 ( intervaltypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ intervaltypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2904 ( intervaltypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ intervaltypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1162 ( interval_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1163 ( interval_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1164 ( interval_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1165 ( interval_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1166 ( interval_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1167 ( interval_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1186 1186" _null_ _null_ _null_ _null_ interval_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1168 ( interval_um PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_um _null_ _null_ _null_ "" f)); +DATA(insert OID = 1169 ( interval_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1170 ( interval_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1171 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 701 "25 1184" _null_ _null_ _null_ _null_ timestamptz_part _null_ _null_ _null_ "" f)); +DESCR("extract field from timestamp with time zone"); +#define TIMESTAMPTZPARTFUNCOID 1171 +DATA(insert OID = 1172 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1186" _null_ _null_ _null_ _null_ interval_part _null_ _null_ _null_ "" f)); +DESCR("extract field from interval"); +#define INTERVALPARTFUNCOID 1172 +DATA(insert OID = 1173 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1184 "702" _null_ _null_ _null_ _null_ abstime_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert abstime to timestamp with time zone"); +DATA(insert OID = 1174 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "1082" _null_ _null_ _null_ _null_ date_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert date to timestamp with time zone"); +#define DATETIMESTAMPTZFUNCOID 1174 +DATA(insert OID = 2711 ( justify_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_interval _null_ _null_ _null_ "" f)); +DESCR("promote groups of 24 hours to numbers of days and promote groups of 30 days to numbers of months"); +DATA(insert OID = 1175 ( justify_hours PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_hours _null_ _null_ _null_ "" f)); +DESCR("promote groups of 24 hours to numbers of days"); +DATA(insert OID = 1295 ( justify_days PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ interval_justify_days _null_ _null_ _null_ "" f)); +DESCR("promote groups of 30 days to numbers of months"); +DATA(insert OID = 1176 ( timestamptz PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 1184 "1082 1083" _null_ _null_ _null_ _null_ "select cast(($1 + $2) as timestamp with time zone)" _null_ _null_ _null_ "" f)); +DESCR("convert date and time to timestamp with time zone"); +#define DTAETIME2TIMESTAMPTZFUNCOID 1176 +DATA(insert OID = 1177 ( interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "703" _null_ _null_ _null_ _null_ reltime_interval _null_ _null_ _null_ "" f)); +DESCR("convert reltime to interval"); +DATA(insert OID = 1178 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "1184" _null_ _null_ _null_ _null_ timestamptz_date _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to date"); +#define TIMESTAMPTZ2DATEFUNCOID 1178 +DATA(insert OID = 1179 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1082 "702" _null_ _null_ _null_ _null_ abstime_date _null_ _null_ _null_ "" f)); +DESCR("convert abstime to date"); +#define ABSTIME2DATEFUNCOID 1179 +DATA(insert OID = 1180 ( abstime PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "1184" _null_ _null_ _null_ _null_ timestamptz_abstime _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to abstime"); +DATA(insert OID = 1181 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "28" _null_ _null_ _null_ _null_ xid_age _null_ _null_ _null_ "" f)); +DESCR("age of a transaction ID, in transactions before current transaction"); + +DATA(insert OID = 1188 ( timestamptz_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1184 1184" _null_ _null_ _null_ _null_ timestamp_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1189 ( timestamptz_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "1184 1186" _null_ _null_ _null_ _null_ timestamptz_pl_interval _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZPLINTERVALFUNCOID 1189 +DATA(insert OID = 1190 ( timestamptz_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "1184 1186" _null_ _null_ _null_ _null_ timestamptz_mi_interval _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZMIINTERVALFUNCOID 1190 +DATA(insert OID = 1194 ( reltime PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "1186" _null_ _null_ _null_ _null_ interval_reltime _null_ _null_ _null_ "" f)); +DESCR("convert interval to reltime"); +DATA(insert OID = 1195 ( timestamptz_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1184 1184" _null_ _null_ _null_ _null_ timestamp_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1196 ( timestamptz_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1184 1184" _null_ _null_ _null_ _null_ timestamp_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1197 ( interval_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1198 ( interval_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 1186" _null_ _null_ _null_ _null_ interval_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1199 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1184 1184" _null_ _null_ _null_ _null_ timestamptz_age _null_ _null_ _null_ "" f)); +DESCR("date difference preserving months and years"); + +/* OIDS 1200 - 1299 */ + +DATA(insert OID = 3918 ( interval_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ interval_transform _null_ _null_ _null_ "" f)); +DESCR("transform an interval length coercion"); +DATA(insert OID = 1200 ( interval PGNSP PGUID 12 1 0 0 interval_transform f f f f t f i 2 0 1186 "1186 23" _null_ _null_ _null_ _null_ interval_scale _null_ _null_ _null_ "" f)); +DESCR("adjust interval precision"); + +DATA(insert OID = 1215 ( obj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 19" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and classoid = (select oid from pg_catalog.pg_class where relname = $2 and relnamespace = PGNSP) and objsubid = 0" _null_ _null_ _null_ "" f)); +DESCR("get description for object id and catalog name"); +DATA(insert OID = 1216 ( col_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and classoid = ''pg_catalog.pg_class''::pg_catalog.regclass and objsubid = $2" _null_ _null_ _null_ "" f)); +DESCR("get description for table column"); +DATA(insert OID = 1993 ( shobj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 2 0 25 "26 19" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_shdescription where objoid = $1 and classoid = (select oid from pg_catalog.pg_class where relname = $2 and relnamespace = PGNSP)" _null_ _null_ _null_ "" f)); +DESCR("get description for object id and shared catalog name"); + +DATA(insert OID = 1217 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1184 "25 1184" _null_ _null_ _null_ _null_ timestamptz_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate timestamp with time zone to specified units"); +#define TIMESTAMPTZTRUNCFUNCOID 1217 +DATA(insert OID = 1218 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "25 1186" _null_ _null_ _null_ _null_ interval_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate interval to specified units"); +#define INTERVALTRUNCFUNCOID 1218 + +DATA(insert OID = 1219 ( int8inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8inc _null_ _null_ _null_ "" f)); +DESCR("increment"); +DATA(insert OID = 2804 ( int8inc_any PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 2276" _null_ _null_ _null_ _null_ int8inc_any _null_ _null_ _null_ "" f)); +DESCR("increment, ignores second argument"); +DATA(insert OID = 1230 ( int8abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8abs _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1236 ( int8larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1237 ( int8smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1238 ( texticregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1239 ( texticregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1240 ( nameicregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1241 ( nameicregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicregexne _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1251 ( int4abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 1253 ( int2abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 6113 ( int1abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1abs _null_ _null_ _null_ "" f)); +DESCR("absolute value "); +DATA(insert OID = 1271 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1266 1266 1266 1266" _null_ _null_ _null_ _null_ overlaps_timetz _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1272 ( datetime_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1083" _null_ _null_ _null_ _null_ datetime_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 1273 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1266" _null_ _null_ _null_ _null_ timetz_part _null_ _null_ _null_ "" f)); +DESCR("extract field from time with time zone"); +#define TIMEZPARTFUNCOID 1273 +DATA(insert OID = 1274 ( int84pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1275 ( int84mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1276 ( int84mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int84mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1277 ( int84div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 23" _null_ _null_ _null_ _null_ int84div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1278 ( int48pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1279 ( int48mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 1280 ( int48mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "23 20" _null_ _null_ _null_ _null_ int48mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1281 ( int48div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 20" _null_ _null_ _null_ _null_ int48div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 837 ( int82pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 838 ( int82mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 839 ( int82mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int82mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 840 ( int82div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 21" _null_ _null_ _null_ _null_ int82div _null_ _null_ _null_ "" f)); +DATA(insert OID = 841 ( int28pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28pl _null_ _null_ _null_ "" f)); +DATA(insert OID = 942 ( int28mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 943 ( int28mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "21 20" _null_ _null_ _null_ _null_ int28mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 948 ( int28div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "21 20" _null_ _null_ _null_ _null_ int28div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1287 ( oid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "20" _null_ _null_ _null_ _null_ i8tooid _null_ _null_ _null_ "" f)); +DESCR("convert int8 to oid"); +DATA(insert OID = 1288 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "26" _null_ _null_ _null_ _null_ oidtoi8 _null_ _null_ _null_ "" f)); +DESCR("convert oid to int8"); + +DATA(insert OID = 1291 ( suppress_redundant_updates_trigger PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ suppress_redundant_updates_trigger _null_ _null_ _null_ "" f)); +DESCR("trigger to suppress updates when new and old records match"); + +DATA(insert OID = 1292 ( tideq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1293 ( currtid PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 27 "26 27" _null_ _null_ _null_ _null_ currtid_byreloid _null_ _null_ _null_ "" f)); +DESCR("latest tid of a tuple"); +DATA(insert OID = 1294 ( currtid2 PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 27 "25 27" _null_ _null_ _null_ _null_ currtid_byrelname _null_ _null_ _null_ "" f)); +DESCR("latest tid of a tuple"); +DATA(insert OID = 1265 ( tidne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2790 ( tidgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2791 ( tidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2792 ( tidge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2793 ( tidle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "27 27" _null_ _null_ _null_ _null_ tidle _null_ _null_ _null_ "" f)); +DATA(insert OID = 2794 ( bttidcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "27 27" _null_ _null_ _null_ _null_ bttidcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2795 ( tidlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 27 "27 27" _null_ _null_ _null_ _null_ tidlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2796 ( tidsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 27 "27 27" _null_ _null_ _null_ _null_ tidsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1296 ( timedate_pl PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1083 1082" _null_ _null_ _null_ _null_ "select ($2 + $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1297 ( datetimetz_pl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1082 1266" _null_ _null_ _null_ _null_ datetimetz_timestamptz _null_ _null_ _null_ "" f)); +DATA(insert OID = 1298 ( timetzdate_pl PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1184 "1266 1082" _null_ _null_ _null_ _null_ "select ($2 + $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1299 ( now PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ now _null_ _null_ _null_ "" f)); +DESCR("current transaction time"); +DATA(insert OID = 2647 ( transaction_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ now _null_ _null_ _null_ "" f)); +DESCR("current transaction time"); +DATA(insert OID = 2648 ( statement_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ statement_timestamp _null_ _null_ _null_ "" f)); +DESCR("current statement time"); +DATA(insert OID = 2649 ( clock_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ clock_timestamp _null_ _null_ _null_ "" f)); +DESCR("current clock time"); +DATA(insert OID = 3951 ( pg_systimestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ pg_system_timestamp _null_ _null_ _null_ "" f)); + +/* OIDS 1300 - 1399 */ + +DATA(insert OID = 1300 ( positionsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ positionsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for position-comparison operators"); +DATA(insert OID = 1301 ( positionjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ positionjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for position-comparison operators"); +DATA(insert OID = 1302 ( contsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ contsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity for containment comparison operators"); +DATA(insert OID = 1303 ( contjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ contjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity for containment comparison operators"); + +DATA(insert OID = 1304 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1184 1184 1184 1184" _null_ _null_ _null_ _null_ overlaps_timestamp _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1305 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1186 1184 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1306 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1184 1184 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1307 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f s 4 0 16 "1184 1186 1184 1184" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); + +DATA(insert OID = 1308 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1083 1083 1083 1083" _null_ _null_ _null_ _null_ overlaps_time _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1309 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1186 1083 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1310 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1083 1083 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 1311 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1083 1186 1083 1083" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); + +DATA(insert OID = 1312 ( timestamp_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1114 "2275 26 23" _null_ _null_ _null_ _null_ timestamp_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPINFUNCOID 1312 +DATA(insert OID = 1313 ( timestamp_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "1114" _null_ _null_ _null_ _null_ timestamp_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMESTAMPOUTFUNCOID 1313 +DATA(insert OID = 2905 ( timestamptypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timestamptypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2906 ( timestamptypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timestamptypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1314 ( timestamptz_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 1184" _null_ _null_ _null_ _null_ timestamp_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1315 ( interval_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 1186" _null_ _null_ _null_ _null_ interval_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1316 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1114" _null_ _null_ _null_ _null_ timestamp_time _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to time"); + +DATA(insert OID = 1317 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +#define LENGTHFUNCOID 1317 +DESCR("length"); +DATA(insert OID = 1318 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +#define BPLENFUNCOID 1318 + +DATA(insert OID = 3175 ( lengthb PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textoctetlen _null_ _null_ _null_ "" f)); +DESCR("lengthb"); +#define TEXTOCTLENFUNCOID 3175 +DATA(insert OID = 3176 ( lengthb PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlenb _null_ _null_ _null_ "" f)); +DESCR("character lengthb"); +#define BPOCTLENFUNCOID 3176 + +DATA(insert OID = 1319 ( xideqint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "28 23" _null_ _null_ _null_ _null_ xideq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1320 ( xidlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "28 28" _null_ _null_ _null_ _null_ xidlt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1326 ( interval_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 701" _null_ _null_ _null_ _null_ interval_div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1339 ( dlog10 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog10 _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1340 ( log PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog10 _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1341 ( ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dlog1 _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1342 ( round PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dround _null_ _null_ _null_ "" f)); +DESCR("round to nearest integer"); +DATA(insert OID = 1343 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtrunc _null_ _null_ _null_ "" f)); +DESCR("truncate to integer"); +DATA(insert OID = 1344 ( sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +#define SQRTFUNCOID 1344 +DATA(insert OID = 1345 ( cbrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcbrt _null_ _null_ _null_ "" f)); +DESCR("cube root"); +DATA(insert OID = 1346 ( pow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +#define POWFUNCOID 1346 +DATA(insert OID = 1368 ( power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ dpow _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +#define POWERFUNCOID 1368 +DATA(insert OID = 1347 ( exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dexp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); + +/* + * This form of obj_description is now deprecated, since it will fail if + * OIDs are not unique across system catalogs. Use the other form instead. + */ +DATA(insert OID = 1348 ( obj_description PGNSP PGUID 14 100 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ "select description from pg_catalog.pg_description where objoid = $1 and objsubid = 0" _null_ _null_ _null_ "" f)); +DESCR("deprecated, use two-argument form instead"); +DATA(insert OID = 1349 ( oidvectortypes PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "30" _null_ _null_ _null_ _null_ oidvectortypes _null_ _null_ _null_ "" f)); +DESCR("print type names of oidvector field"); + + +DATA(insert OID = 1350 ( timetz_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1266 "2275 26 23" _null_ _null_ _null_ _null_ timetz_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define TIMETZINFUNCOID 1350 +DATA(insert OID = 1351 ( timetz_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1266" _null_ _null_ _null_ _null_ timetz_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2911 ( timetztypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ timetztypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2912 ( timetztypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ timetztypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 1352 ( timetz_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1353 ( timetz_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1354 ( timetz_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1355 ( timetz_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1356 ( timetz_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1357 ( timetz_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1266 1266" _null_ _null_ _null_ _null_ timetz_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1358 ( timetz_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 1266" _null_ _null_ _null_ _null_ timetz_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 1359 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1082 1266" _null_ _null_ _null_ _null_ datetimetz_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert date and time with time zone to timestamp with time zone"); + +DATA(insert OID = 1364 ( time PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1083 "702" _null_ _null_ _null_ _null_ "select cast(cast($1 as timestamp without time zone) as pg_catalog.time)" _null_ _null_ _null_ "" f)); +DESCR("convert abstime to time"); +#define ABSTIME2TIMEFUNCOID 1364 +DATA(insert OID = 1367 ( character_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +DATA(insert OID = 1369 ( character_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("character length"); + +DATA(insert OID = 1370 ( interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1083" _null_ _null_ _null_ _null_ time_interval _null_ _null_ _null_ "" f)); +DESCR("convert time to interval"); +DATA(insert OID = 1372 ( char_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +DATA(insert OID = 1374 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 1375 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpcharoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); + +DATA(insert OID = 1377 ( time_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1083" _null_ _null_ _null_ _null_ time_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1378 ( time_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1083" _null_ _null_ _null_ _null_ time_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1379 ( timetz_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1266" _null_ _null_ _null_ _null_ timetz_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1380 ( timetz_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1266" _null_ _null_ _null_ _null_ timetz_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1381 ( char_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ textlen _null_ _null_ _null_ "" f)); +DESCR("character length"); +#define CHARLENFUNCOID 1381 + +DATA(insert OID = 1382 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 701 "25 702" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as timestamp with time zone))" _null_ _null_ _null_ "" f)); +DESCR("extract field from abstime"); +#define DATEPARTFROMABSTIMEFUNCOID 1382 +DATA(insert OID = 1383 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 701 "25 703" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as pg_catalog.interval))" _null_ _null_ _null_ "" f)); +DESCR("extract field from reltime"); +#define DATEPARTFROMRELTIMEFUNCOID 1383 +DATA(insert OID = 1384 ( date_part PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 701 "25 1082" _null_ _null_ _null_ _null_ "select pg_catalog.date_part($1, cast($2 as timestamp without time zone))" _null_ _null_ _null_ "" f)); +DESCR("extract field from date"); +#define DATEPARTFUNCOID 1384 +DATA(insert OID = 1385 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1083" _null_ _null_ _null_ _null_ time_part _null_ _null_ _null_ "" f)); +DESCR("extract field from time"); +#define TIMEPARTFUNCOID 1385 +DATA(insert OID = 1386 ( age PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1186 "1184" _null_ _null_ _null_ _null_ "select pg_catalog.age(cast(current_date as timestamp with time zone), $1)" _null_ _null_ _null_ "" f)); +DESCR("date difference from today preserving months and years"); + +DATA(insert OID = 1388 ( timetz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1266 "1184" _null_ _null_ _null_ _null_ timestamptz_timetz _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to time with time zone"); +#define TIMESTAMPTZ2TIMETZFUNCOID 1388 +DATA(insert OID = 1373 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1082" _null_ _null_ _null_ _null_ date_finite _null_ _null_ _null_ "" f)); +DESCR("finite date?"); +DATA(insert OID = 1389 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1184" _null_ _null_ _null_ _null_ timestamp_finite _null_ _null_ _null_ "" f)); +DESCR("finite timestamp?"); +DATA(insert OID = 1390 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1186" _null_ _null_ _null_ _null_ interval_finite _null_ _null_ _null_ "" f)); +DESCR("finite interval?"); + + +DATA(insert OID = 1376 ( factorial PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ numeric_fac _null_ _null_ _null_ "" f)); +DESCR("factorial"); +DATA(insert OID = 1394 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1395 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1396 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1397 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1398 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); + +/* OIDS 1400 - 1499 */ + +DATA(insert OID = 1400 ( name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 19 "1043" _null_ _null_ _null_ _null_ text_name _null_ _null_ _null_ "" f)); +DESCR("convert varchar to name"); +DATA(insert OID = 1401 ( varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "19" _null_ _null_ _null_ _null_ name_text _null_ _null_ _null_ "" f)); +DESCR("convert name to varchar"); + +DATA(insert OID = 1402 ( current_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ current_schema _null_ _null_ _null_ "" f)); +DESCR("current schema name"); +DATA(insert OID = 1403 ( current_schemas PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1003 "16" _null_ _null_ _null_ _null_ current_schemas _null_ _null_ _null_ "" f)); +DESCR("current schema search list"); + +DATA(insert OID = 1404 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 25 "25 25 23 23" _null_ _null_ _null_ _null_ textoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); +DATA(insert OID = 1405 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 23" _null_ _null_ _null_ _null_ textoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of string"); + +DATA(insert OID = 1406 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_vert _null_ _null_ _null_ "" f)); +DESCR("vertically aligned"); +DATA(insert OID = 1407 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 600" _null_ _null_ _null_ _null_ point_horiz _null_ _null_ _null_ "" f)); +DESCR("horizontally aligned"); +DATA(insert OID = 1408 ( isparallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_parallel _null_ _null_ _null_ "" f)); +DESCR("parallel"); +DATA(insert OID = 1409 ( isperp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_perp _null_ _null_ _null_ "" f)); +DESCR("perpendicular"); +DATA(insert OID = 1410 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_vertical _null_ _null_ _null_ "" f)); +DESCR("vertical"); +DATA(insert OID = 1411 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "601" _null_ _null_ _null_ _null_ lseg_horizontal _null_ _null_ _null_ "" f)); +DESCR("horizontal"); +DATA(insert OID = 1412 ( isparallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_parallel _null_ _null_ _null_ "" f)); +DESCR("parallel"); +DATA(insert OID = 1413 ( isperp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_perp _null_ _null_ _null_ "" f)); +DESCR("perpendicular"); +DATA(insert OID = 1414 ( isvertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_vertical _null_ _null_ _null_ "" f)); +DESCR("vertical"); +DATA(insert OID = 1415 ( ishorizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_horizontal _null_ _null_ _null_ "" f)); +DESCR("horizontal"); +DATA(insert OID = 1416 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DESCR("center of"); + +DATA(insert OID = 1419 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1186" _null_ _null_ _null_ _null_ interval_time _null_ _null_ _null_ "" f)); +DESCR("convert interval to time"); + +DATA(insert OID = 1421 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "600 600" _null_ _null_ _null_ _null_ points_box _null_ _null_ _null_ "" f)); +DESCR("convert points to box"); +DATA(insert OID = 1422 ( box_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1423 ( box_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1424 ( box_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1425 ( box_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "603 600" _null_ _null_ _null_ _null_ box_div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1426 ( path_contain_pt PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 16 "602 600" _null_ _null_ _null_ _null_ "select pg_catalog.on_ppath($2, $1)" _null_ _null_ _null_ "" f)); +DATA(insert OID = 1428 ( poly_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 600" _null_ _null_ _null_ _null_ poly_contain_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1429 ( pt_contained_poly PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 604" _null_ _null_ _null_ _null_ pt_contained_poly _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1430 ( isclosed PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "602" _null_ _null_ _null_ _null_ path_isclosed _null_ _null_ _null_ "" f)); +DESCR("path closed?"); +DATA(insert OID = 1431 ( isopen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "602" _null_ _null_ _null_ _null_ path_isopen _null_ _null_ _null_ "" f)); +DESCR("path open?"); +DATA(insert OID = 1432 ( path_npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "602" _null_ _null_ _null_ _null_ path_npoints _null_ _null_ _null_ "" f)); + +/* pclose and popen might better be named close and open, but that crashes initdb. + * - thomas 97/04/20 + */ + +DATA(insert OID = 1433 ( pclose PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "602" _null_ _null_ _null_ _null_ path_close _null_ _null_ _null_ "" f)); +DESCR("close path"); +DATA(insert OID = 1434 ( popen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "602" _null_ _null_ _null_ _null_ path_open _null_ _null_ _null_ "" f)); +DESCR("open path"); +DATA(insert OID = 1435 ( path_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 602" _null_ _null_ _null_ _null_ path_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1436 ( path_add_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_add_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1437 ( path_sub_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_sub_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1438 ( path_mul_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_mul_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1439 ( path_div_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 602 "602 600" _null_ _null_ _null_ _null_ path_div_pt _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1440 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "701 701" _null_ _null_ _null_ _null_ construct_point _null_ _null_ _null_ "" f)); +DESCR("convert x, y to point"); +DATA(insert OID = 1441 ( point_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1442 ( point_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1443 ( point_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1444 ( point_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "600 600" _null_ _null_ _null_ _null_ point_div _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1445 ( poly_npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "604" _null_ _null_ _null_ _null_ poly_npoints _null_ _null_ _null_ "" f)); +DATA(insert OID = 1446 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "604" _null_ _null_ _null_ _null_ poly_box _null_ _null_ _null_ "" f)); +DESCR("convert polygon to bounding box"); +DATA(insert OID = 1447 ( path PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "604" _null_ _null_ _null_ _null_ poly_path _null_ _null_ _null_ "" f)); +DESCR("convert polygon to path"); +DATA(insert OID = 1448 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "603" _null_ _null_ _null_ _null_ box_poly _null_ _null_ _null_ "" f)); +DESCR("convert box to polygon"); +DATA(insert OID = 1449 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "602" _null_ _null_ _null_ _null_ path_poly _null_ _null_ _null_ "" f)); +DESCR("convert path to polygon"); + +DATA(insert OID = 1450 ( circle_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "2275" _null_ _null_ _null_ _null_ circle_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1451 ( circle_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "718" _null_ _null_ _null_ _null_ circle_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1452 ( circle_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_same _null_ _null_ _null_ "" f)); +DATA(insert OID = 1453 ( circle_contain PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_contain _null_ _null_ _null_ "" f)); +DATA(insert OID = 1454 ( circle_left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_left _null_ _null_ _null_ "" f)); +DATA(insert OID = 1455 ( circle_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 1456 ( circle_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overright _null_ _null_ _null_ "" f)); +DATA(insert OID = 1457 ( circle_right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_right _null_ _null_ _null_ "" f)); +DATA(insert OID = 1458 ( circle_contained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_contained _null_ _null_ _null_ "" f)); +DATA(insert OID = 1459 ( circle_overlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 1460 ( circle_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 1461 ( circle_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 1462 ( circle_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1463 ( circle_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1464 ( circle_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1465 ( circle_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1466 ( circle_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1467 ( circle_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1468 ( area PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_area _null_ _null_ _null_ "" f)); +DESCR("area of circle"); +DATA(insert OID = 1469 ( diameter PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_diameter _null_ _null_ _null_ "" f)); +DESCR("diameter of circle"); +DATA(insert OID = 1470 ( radius PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "718" _null_ _null_ _null_ _null_ circle_radius _null_ _null_ _null_ "" f)); +DESCR("radius of circle"); +DATA(insert OID = 1471 ( circle_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "718 718" _null_ _null_ _null_ _null_ circle_distance _null_ _null_ _null_ "" f)); +DATA(insert OID = 1472 ( circle_center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DATA(insert OID = 1473 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 718 "600 701" _null_ _null_ _null_ _null_ cr_circle _null_ _null_ _null_ "" f)); +DESCR("convert point and radius to circle"); +DATA(insert OID = 1474 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "604" _null_ _null_ _null_ _null_ poly_circle _null_ _null_ _null_ "" f)); +DESCR("convert polygon to circle"); +DATA(insert OID = 1475 ( polygon PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 604 "23 718" _null_ _null_ _null_ _null_ circle_poly _null_ _null_ _null_ "" f)); +DESCR("convert vertex count and circle to polygon"); +DATA(insert OID = 1476 ( dist_pc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "600 718" _null_ _null_ _null_ _null_ dist_pc _null_ _null_ _null_ "" f)); +DATA(insert OID = 1477 ( circle_contain_pt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 600" _null_ _null_ _null_ _null_ circle_contain_pt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1478 ( pt_contained_circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "600 718" _null_ _null_ _null_ _null_ pt_contained_circle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1479 ( circle PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "603" _null_ _null_ _null_ _null_ box_circle _null_ _null_ _null_ "" f)); +DESCR("convert box to circle"); +DATA(insert OID = 1480 ( box PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "718" _null_ _null_ _null_ _null_ circle_box _null_ _null_ _null_ "" f)); +DESCR("convert circle to box"); +DATA(insert OID = 1481 ( tinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 704 "702 702" _null_ _null_ _null_ _null_ mktinterval _null_ _null_ _null_ "" f)); +DESCR("convert to tinterval"); + +DATA(insert OID = 1482 ( lseg_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1483 ( lseg_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1484 ( lseg_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1485 ( lseg_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1486 ( lseg_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "601 601" _null_ _null_ _null_ _null_ lseg_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1487 ( lseg_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "601" _null_ _null_ _null_ _null_ lseg_length _null_ _null_ _null_ "" f)); +DATA(insert OID = 1488 ( close_ls PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 601" _null_ _null_ _null_ _null_ close_ls _null_ _null_ _null_ "" f)); +DATA(insert OID = 1489 ( close_lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "601 601" _null_ _null_ _null_ _null_ close_lseg _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1490 ( line_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 628 "2275" _null_ _null_ _null_ _null_ line_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1491 ( line_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "628" _null_ _null_ _null_ _null_ line_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1492 ( line_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1493 ( line PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 628 "600 600" _null_ _null_ _null_ _null_ line_construct_pp _null_ _null_ _null_ "" f)); +DESCR("construct line from points"); +DATA(insert OID = 1494 ( line_interpt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 600 "628 628" _null_ _null_ _null_ _null_ line_interpt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1495 ( line_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_intersect _null_ _null_ _null_ "" f)); +DATA(insert OID = 1496 ( line_parallel PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_parallel _null_ _null_ _null_ "" f)); +DATA(insert OID = 1497 ( line_perp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "628 628" _null_ _null_ _null_ _null_ line_perp _null_ _null_ _null_ "" f)); +DATA(insert OID = 1498 ( line_vertical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_vertical _null_ _null_ _null_ "" f)); +DATA(insert OID = 1499 ( line_horizontal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "628" _null_ _null_ _null_ _null_ line_horizontal _null_ _null_ _null_ "" f)); + +/* OIDS 1500 - 1599 */ + +DATA(insert OID = 1530 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "601" _null_ _null_ _null_ _null_ lseg_length _null_ _null_ _null_ "" f)); +DESCR("distance between endpoints"); +DATA(insert OID = 1531 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "602" _null_ _null_ _null_ _null_ path_length _null_ _null_ _null_ "" f)); +DESCR("sum of path segments"); + + +DATA(insert OID = 1532 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "601" _null_ _null_ _null_ _null_ lseg_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1533 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "602" _null_ _null_ _null_ _null_ path_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1534 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1540 ( point PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "604" _null_ _null_ _null_ _null_ poly_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1541 ( lseg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "603" _null_ _null_ _null_ _null_ box_diagonal _null_ _null_ _null_ "" f)); +DESCR("diagonal of"); +DATA(insert OID = 1542 ( center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "603" _null_ _null_ _null_ _null_ box_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1543 ( center PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "718" _null_ _null_ _null_ _null_ circle_center _null_ _null_ _null_ "" f)); +DESCR("center of"); +DATA(insert OID = 1544 ( polygon PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 604 "718" _null_ _null_ _null_ _null_ "select pg_catalog.polygon(12, $1)" _null_ _null_ _null_ "" f)); +DESCR("convert circle to 12-vertex polygon"); +DATA(insert OID = 1545 ( npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "602" _null_ _null_ _null_ _null_ path_npoints _null_ _null_ _null_ "" f)); +DESCR("number of points"); +DATA(insert OID = 1556 ( npoints PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "604" _null_ _null_ _null_ _null_ poly_npoints _null_ _null_ _null_ "" f)); +DESCR("number of points"); + +DATA(insert OID = 1564 ( bit_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2275 26 23" _null_ _null_ _null_ _null_ bit_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1565 ( bit_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1560" _null_ _null_ _null_ _null_ bit_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2919 ( bittypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ bittypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2920 ( bittypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ bittypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); + +DATA(insert OID = 1569 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 1570 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 1571 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namelike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 1572 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ namenlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); + + +/* SEQUENCE functions */ +DATA(insert OID = 1574 ( nextval PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ nextval_oid _null_ _null_ _null_ "" f)); +DESCR("sequence next value"); +#define NEXTVALFUNCOID 1574 +DATA(insert OID = 1575 ( currval PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ currval_oid _null_ _null_ _null_ "" f)); +DESCR("sequence current value"); +#define CURRVALFUNCOID 1575 +DATA(insert OID = 1576 ( setval PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 20" _null_ _null_ _null_ _null_ setval_oid _null_ _null_ _null_ "" f)); +DESCR("set sequence value"); +#define SETVAL1FUNCOID 1576 +DATA(insert OID = 1765 ( setval PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 20 "2205 20 16" _null_ _null_ _null_ _null_ setval3_oid _null_ _null_ _null_ "" f)); +DESCR("set sequence value and is_called status"); +#define SETVAL3FUNCOID 1765 +DATA(insert OID = 3078 ( pg_sequence_parameters PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2249 "26" "{26,20,20,20,20,16}" "{i,o,o,o,o,o}" "{sequence_oid,start_value,minimum_value,maximum_value,increment,cycle_option}" _null_ pg_sequence_parameters _null_ _null_ _null_"" f)); +DESCR("sequence parameters, for use by information schema"); + +DATA(insert OID = 1579 ( varbit_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1562 "2275 26 23" _null_ _null_ _null_ _null_ varbit_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1580 ( varbit_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1562" _null_ _null_ _null_ _null_ varbit_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2902 ( varbittypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ varbittypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2921 ( varbittypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ varbittypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); + +DATA(insert OID = 1581 ( biteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ biteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1582 ( bitne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1592 ( bitge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1593 ( bitgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1594 ( bitle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1595 ( bitlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1560 1560" _null_ _null_ _null_ _null_ bitlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1596 ( bitcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 1560" _null_ _null_ _null_ _null_ bitcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1598 ( random PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 701 "" _null_ _null_ _null_ _null_ drandom _null_ _null_ _null_ "" f)); +DESCR("random value"); +#define RANDOMFUNCOID 1598 +DATA(insert OID = 1599 ( setseed PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "701" _null_ _null_ _null_ _null_ setseed _null_ _null_ _null_ "" f)); +DESCR("set random seed"); +/* For LLT +DATA(insert OID = 4244 ( exec_on_extension PGNSP PGUID 12 1 1000 0 0 f f f f f t v 2 0 2249 "25 25" _null_ _null_ _null_ _null_ exec_on_extension _null_ _null_ _null_ "" f)); +DESCR("get data from remote database"); +*/ +#define ECFUNCOID 4244 +/*For LLT +DATA(insert OID = 4255 ( exec_hadoop_sql PGNSP PGUID 12 1 1000 0 0 f f f f f t v 3 0 2249 "25 25 25" _null_ _null_ _null_ _null_ exec_hadoop_sql _null_ _null_ _null_ "" f)); +DESCR("get data from remote database in hadoop"); +*/ +/* OIDS 1600 - 1699 */ + +DATA(insert OID = 1600 ( asin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dasin _null_ _null_ _null_ "" f)); +DESCR("arcsine"); +#define ARCSINEFUNCOID 1600 +DATA(insert OID = 1601 ( acos PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dacos _null_ _null_ _null_ "" f)); +DESCR("arccosine"); +DATA(insert OID = 1602 ( atan PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ datan _null_ _null_ _null_ "" f)); +DESCR("arctangent"); +DATA(insert OID = 1603 ( atan2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ datan2 _null_ _null_ _null_ "" f)); +DESCR("arctangent, two arguments"); +DATA(insert OID = 1604 ( sin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dsin _null_ _null_ _null_ "" f)); +DESCR("sine"); +#define SINEFUNCOID 1604 +DATA(insert OID = 1605 ( cos PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcos _null_ _null_ _null_ "" f)); +DESCR("cosine"); +#define COSINEFUNCOID 1605 +DATA(insert OID = 1606 ( tan PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dtan _null_ _null_ _null_ "" f)); +DESCR("tangent"); +DATA(insert OID = 1607 ( cot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ dcot _null_ _null_ _null_ "" f)); +DESCR("cotangent"); +DATA(insert OID = 1608 ( degrees PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ degrees _null_ _null_ _null_ "" f)); +DESCR("radians to degrees"); +DATA(insert OID = 1609 ( radians PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ radians _null_ _null_ _null_ "" f)); +DESCR("degrees to radians"); +DATA(insert OID = 1610 ( pi PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 701 "" _null_ _null_ _null_ _null_ dpi _null_ _null_ _null_ "" f)); +DESCR("PI"); + +DATA(insert OID = 1618 ( interval_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1186 701" _null_ _null_ _null_ _null_ interval_mul _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1620 ( ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ ascii _null_ _null_ _null_ "" f)); +DESCR("convert first char to int4"); +DATA(insert OID = 1621 ( chr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "23" _null_ _null_ _null_ _null_ chr _null_ _null_ _null_ "" f)); +DESCR("convert int4 to char"); +DATA(insert OID = 1622 ( repeat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ repeat _null_ _null_ _null_ "" f)); +DESCR("replicate string n times"); + +DATA(insert OID = 1623 ( similar_escape PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ similar_escape _null_ _null_ _null_ "" f)); +DESCR("convert SQL99 regexp pattern to POSIX style"); + +DATA(insert OID = 1624 ( mul_d_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "701 1186" _null_ _null_ _null_ _null_ mul_d_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1631 ( bpcharlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1632 ( bpcharnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textnlike _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1633 ( texticlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1634 ( texticnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ texticnlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1635 ( nameiclike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameiclike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1636 ( nameicnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "19 25" _null_ _null_ _null_ _null_ nameicnlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1637 ( like_escape PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ like_escape _null_ _null_ _null_ "" f)); +DESCR("convert LIKE pattern to use backslash escapes"); + +DATA(insert OID = 1656 ( bpcharicregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1657 ( bpcharicregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1658 ( bpcharregexeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textregexeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1659 ( bpcharregexne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ textregexne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1660 ( bpchariclike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 1661 ( bpcharicnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 25" _null_ _null_ _null_ _null_ texticnlike _null_ _null_ _null_ "" f)); + +/* Oracle Compatibility Related Functions - By Edmund Mergl */ +DATA(insert OID = 868 ( strpos PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define STRPOSFUNCOID 868 +DATA(insert OID = 870 ( lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ lower _null_ _null_ _null_ "" f)); +DESCR("lowercase"); +DATA(insert OID = 871 ( upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ upper _null_ _null_ _null_ "" f)); +DESCR("uppercase"); +DATA(insert OID = 872 ( initcap PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ initcap _null_ _null_ _null_ "" f)); +DESCR("capitalize each word"); +DATA(insert OID = 873 ( lpad PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 25" _null_ _null_ _null_ _null_ lpad _null_ _null_ _null_ "" f)); +DESCR("left-pad string to length"); +#define LPADFUNCOID 873 +DATA(insert OID = 874 ( rpad PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 25" _null_ _null_ _null_ _null_ rpad _null_ _null_ _null_ "" f)); +DESCR("right-pad string to length"); +#define RPADFUNCOID 874 +DATA(insert OID = 875 ( ltrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ ltrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from left end of string"); +#define LTRIMFUNCOID 875 +DATA(insert OID = 876 ( rtrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ rtrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from right end of string"); +#define RTRIMFUNCOID 876 +DATA(insert OID = 877 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr_orclcompat _null_ _null_ _null_ "" f)); +#define SUBSTRFUNCOID 877 +DESCR("extract portion of string"); +DATA(insert OID = 3814 ( empty_blob PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 88 "" _null_ _null_ _null_ _null_ get_empty_blob _null_ _null_ _null_ "" f)); +DESCR("return empty blob"); +DATA(insert OID = 3205 ( substrb PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ substrb_with_lenth - _null_ _null_ "" f)); +DESCR("return portion of byte string"); +#define SUBSTRBWITHLENFUNCOID 3205 +DATA(insert OID = 3206 ( substrb PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ substrb_without_lenth - _null_ _null_ "" f)); +DESCR("return portion of byte string"); +#define SUBSTRBNOLENFUNCOID 3206 +DATA(insert OID = 878 ( translate PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ translate _null_ _null_ _null_ "" f)); +DESCR("map a set of characters appearing in string"); +DATA(insert OID = 879 ( lpad PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ "select pg_catalog.lpad($1, $2, '' '')" _null_ _null_ _null_ "" f)); +DESCR("left-pad string to length"); +#define LPADPARAFUNCOID 879 +DATA(insert OID = 880 ( rpad PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ "select pg_catalog.rpad($1, $2, '' '')" _null_ _null_ _null_ "" f)); +DESCR("right-pad string to length"); +#define RPADPARAFUNCOID 880 +DATA(insert OID = 881 ( ltrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ ltrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from left end of string"); +#define LTRIMPARAFUNCOID 881 +DATA(insert OID = 882 ( rtrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ rtrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from right end of string"); +#define RTRIMPARAFUNCOID 882 +DATA(insert OID = 883 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRNOLENFUNCOID 883 +DATA(insert OID = 884 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ btrim _null_ _null_ _null_ "" f)); +DESCR("trim selected characters from both ends of string"); +#define BTRIMPARAFUNCOID 884 +DATA(insert OID = 885 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ btrim1 _null_ _null_ _null_ "" f)); +DESCR("trim spaces from both ends of string"); +#define BTRIMFUNCOID 885 + +DATA(insert OID = 3182 ( substring_inner PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRINNFUNCOID 3182 +DATA(insert OID = 3183 ( substring_inner PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define SUBSTRINNNOLENFUNCOID 3183 +DATA(insert OID = 936 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 23 23" _null_ _null_ _null_ _null_ text_substr_null _null_ _null_ _null_ "" f)); +#define TEXTSUBSTRINGFUNCOID 936 +DESCR("extract portion of string"); +DATA(insert OID = 937 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_substr_no_len_null _null_ _null_ _null_ "" f)); +#define TEXTSUBSTRINGNOLENFUNCOID 937 +DESCR("extract portion of string"); +DATA(insert OID = 2087 ( replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ replace_text _null_ _null_ _null_ "" f)); +DESCR("replace all occurrences in string of old_substr with new_substr"); +DATA(insert OID = 2284 ( regexp_replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ textregexreplace_noopt _null_ _null_ _null_ "" f)); +DESCR("replace text using regexp"); +DATA(insert OID = 2285 ( regexp_replace PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 25 "25 25 25 25" _null_ _null_ _null_ _null_ textregexreplace _null_ _null_ _null_ "" f)); +DESCR("replace text using regexp"); +DATA(insert OID = 2763 ( regexp_matches PGNSP PGUID 12 1 1 0 0 f f f f t t i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ regexp_matches_no_flags _null_ _null_ _null_ "" f)); +DESCR("find all match groups for regexp"); +DATA(insert OID = 2764 ( regexp_matches PGNSP PGUID 12 1 10 0 0 f f f f t t i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ regexp_matches _null_ _null_ _null_ "" f)); +DESCR("find all match groups for regexp"); +DATA(insert OID = 2088 ( split_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "25 25 23" _null_ _null_ _null_ _null_ split_text _null_ _null_ _null_ "" f)); +DESCR("split string by field_sep and return field_num"); +DATA(insert OID = 2765 ( regexp_split_to_table PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 25 "25 25" _null_ _null_ _null_ _null_ regexp_split_to_table_no_flags _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2766 ( regexp_split_to_table PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ regexp_split_to_table _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2767 ( regexp_split_to_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1009 "25 25" _null_ _null_ _null_ _null_ regexp_split_to_array_no_flags _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2768 ( regexp_split_to_array PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1009 "25 25 25" _null_ _null_ _null_ _null_ regexp_split_to_array _null_ _null_ _null_ "" f)); +DESCR("split string by pattern"); +DATA(insert OID = 2089 ( to_hex PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "23" _null_ _null_ _null_ _null_ to_hex32 _null_ _null_ _null_ "" f)); +DESCR("convert int4 number to hex"); +DATA(insert OID = 2090 ( to_hex PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "20" _null_ _null_ _null_ _null_ to_hex64 _null_ _null_ _null_ "" f)); +DESCR("convert int8 number to hex"); + +/* for character set encoding support */ + +/* return database encoding name */ +DATA(insert OID = 1039 ( getdatabaseencoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ getdatabaseencoding _null_ _null_ _null_ "" f)); +DESCR("encoding name of current database"); + +/* return client encoding name i.e. session encoding */ +DATA(insert OID = 810 ( pg_client_encoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pg_client_encoding _null_ _null_ _null_ "" f)); +DESCR("encoding name of current database"); + +DATA(insert OID = 1713 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "17 19" _null_ _null_ _null_ _null_ length_in_encoding _null_ _null_ _null_ "" f)); +DESCR("length of string in specified encoding"); + +DATA(insert OID = 1714 ( convert_from PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "17 19" _null_ _null_ _null_ _null_ pg_convert_from _null_ _null_ _null_ "" f)); +DESCR("convert string with specified source encoding name"); + +DATA(insert OID = 1717 ( convert_to PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "25 19" _null_ _null_ _null_ _null_ pg_convert_to _null_ _null_ _null_ "" f)); +DESCR("convert string with specified destination encoding name"); + +DATA(insert OID = 1813 ( convert PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 17 "17 19 19" _null_ _null_ _null_ _null_ pg_convert _null_ _null_ _null_ "" f)); +DESCR("convert string with specified encoding names"); + +DATA(insert OID = 1264 ( pg_char_to_encoding PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "19" _null_ _null_ _null_ _null_ PG_char_to_encoding _null_ _null_ _null_ "" f)); +DESCR("convert encoding name to encoding id"); + +DATA(insert OID = 1597 ( pg_encoding_to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "23" _null_ _null_ _null_ _null_ PG_encoding_to_char _null_ _null_ _null_ "" f)); +DESCR("convert encoding id to encoding name"); + +DATA(insert OID = 2319 ( pg_encoding_max_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ pg_encoding_max_length_sql _null_ _null_ _null_ "" f)); +DESCR("maximum octet length of a character in given encoding"); + +DATA(insert OID = 1638 ( oidgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1639 ( oidge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidge _null_ _null_ _null_ "" f)); + +/* System-view support functions */ +DATA(insert OID = 1573 ( pg_get_ruledef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_ruledef _null_ _null_ _null_ "" f)); +DESCR("source text of a rule"); +DATA(insert OID = 1640 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "25" _null_ _null_ _null_ _null_ pg_get_viewdef_name _null_ _null_ _null_ "" f)); +DESCR("select statement of a view"); +DATA(insert OID = 1641 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_viewdef _null_ _null_ _null_ "" f)); +DESCR("select statement of a view"); +DATA(insert OID = 1642 ( pg_get_userbyid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "26" _null_ _null_ _null_ _null_ pg_get_userbyid _null_ _null_ _null_ "" f)); +DESCR("role name by OID (with fallback)"); +DATA(insert OID = 1643 ( pg_get_indexdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_indexdef _null_ _null_ _null_ "" f)); +DESCR("index description"); +DATA(insert OID = 1662 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_triggerdef _null_ _null_ _null_ "" f)); +DESCR("trigger description"); +DATA(insert OID = 1387 ( pg_get_constraintdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_constraintdef _null_ _null_ _null_ "" f)); +DESCR("constraint description"); +DATA(insert OID = 1716 ( pg_get_expr PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "194 26" _null_ _null_ _null_ _null_ pg_get_expr _null_ _null_ _null_ "" f)); +DESCR("deparse an encoded expression"); +DATA(insert OID = 1665 ( pg_get_serial_sequence PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 25" _null_ _null_ _null_ _null_ pg_get_serial_sequence _null_ _null_ _null_ "" f)); +DESCR("name of sequence for a serial column"); +DATA(insert OID = 2098 ( pg_get_functiondef PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2249 "26" "{26,23,25}" "{i,o,o}" "{funcid,headerlines,definition}" _null_ pg_get_functiondef _null_ _null_ _null_ "" f)); +DESCR("definition of a function"); +DATA(insert OID = 2162 ( pg_get_function_arguments PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_arguments _null_ _null_ _null_ "" f)); +DESCR("argument list of a function"); +DATA(insert OID = 2232 ( pg_get_function_identity_arguments PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_identity_arguments _null_ _null_ _null_ "" f)); +DESCR("identity argument list of a function"); +DATA(insert OID = 2165 ( pg_get_function_result PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_get_function_result _null_ _null_ _null_ "" f)); +DESCR("result type of a function"); + +DATA(insert OID = 1686 ( pg_get_keywords PGNSP PGUID 12 10 400 0 0 f f f f t t s 0 0 2249 "" "{25,18,25}" "{o,o,o}" "{word,catcode,catdesc}" _null_ pg_get_keywords _null_ _null_ _null_ "" f)); +DESCR("list of SQL keywords"); + +DATA(insert OID = 2289 ( pg_options_to_table PGNSP PGUID 12 1 3 0 0 f f f f t t s 1 0 2249 "1009" "{1009,25,25}" "{i,o,o}" "{options_array,option_name,option_value}" _null_ pg_options_to_table _null_ _null_ _null_ "" f)); +DESCR("convert generic options array to name/value table"); + +DATA(insert OID = 1619 ( pg_typeof PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 2206 "2276" _null_ _null_ _null_ _null_ pg_typeof _null_ _null_ _null_ "" f)); +DESCR("type of the argument"); +DATA(insert OID = 3162 ( pg_collation_for PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 25 "2276" _null_ _null_ _null_ _null_ pg_collation_for _null_ _null_ _null_ "" f)); +DESCR("collation of the argument; implementation of the COLLATION FOR expression"); + +/* Deferrable unique constraint trigger */ +DATA(insert OID = 1250 ( unique_key_recheck PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ unique_key_recheck _null_ _null_ _null_ "" f)); +DESCR("deferred UNIQUE constraint check"); + +/* Generic referential integrity constraint triggers */ +DATA(insert OID = 1644 ( RI_FKey_check_ins PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_check_ins _null_ _null_ _null_ "" f)); +DESCR("referential integrity FOREIGN KEY ... REFERENCES"); +DATA(insert OID = 1645 ( RI_FKey_check_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_check_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity FOREIGN KEY ... REFERENCES"); +DATA(insert OID = 1646 ( RI_FKey_cascade_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_cascade_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE CASCADE"); +DATA(insert OID = 1647 ( RI_FKey_cascade_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_cascade_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE CASCADE"); +DATA(insert OID = 1648 ( RI_FKey_restrict_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_restrict_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE RESTRICT"); +DATA(insert OID = 1649 ( RI_FKey_restrict_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_restrict_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE RESTRICT"); +DATA(insert OID = 1650 ( RI_FKey_setnull_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setnull_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE SET NULL"); +DATA(insert OID = 1651 ( RI_FKey_setnull_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setnull_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE SET NULL"); +DATA(insert OID = 1652 ( RI_FKey_setdefault_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setdefault_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE SET DEFAULT"); +DATA(insert OID = 1653 ( RI_FKey_setdefault_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_setdefault_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE SET DEFAULT"); +DATA(insert OID = 1654 ( RI_FKey_noaction_del PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_noaction_del _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON DELETE NO ACTION"); +DATA(insert OID = 1655 ( RI_FKey_noaction_upd PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2279 "" _null_ _null_ _null_ _null_ RI_FKey_noaction_upd _null_ _null_ _null_ "" f)); +DESCR("referential integrity ON UPDATE NO ACTION"); + +DATA(insert OID = 1666 ( varbiteq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ biteq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1667 ( varbitne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1668 ( varbitge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1669 ( varbitgt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitgt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1670 ( varbitle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1671 ( varbitlt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1562 1562" _null_ _null_ _null_ _null_ bitlt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1672 ( varbitcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1562 1562" _null_ _null_ _null_ _null_ bitcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1673 ( bitand PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bit_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1674 ( bitor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bit_or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1675 ( bitxor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 1560" _null_ _null_ _null_ _null_ bitxor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1676 ( bitnot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ bitnot _null_ _null_ _null_ "" f)); +DATA(insert OID = 1677 ( bitshiftleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitshiftleft _null_ _null_ _null_ "" f)); +DATA(insert OID = 1678 ( bitshiftright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitshiftright _null_ _null_ _null_ "" f)); +DATA(insert OID = 1679 ( bitcat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1562 "1562 1562" _null_ _null_ _null_ _null_ bitcat _null_ _null_ _null_ "" f)); +DATA(insert OID = 1680 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 23" _null_ _null_ _null_ _null_ bitsubstr _null_ _null_ _null_ "" f)); +#define BITSUBSTRINGFUNOID 1680 +DESCR("extract portion of bitstring"); +DATA(insert OID = 1681 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bitlength _null_ _null_ _null_ "" f)); +DESCR("bitstring length"); +DATA(insert OID = 1682 ( octet_length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bitoctetlength _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 1683 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "23 23" _null_ _null_ _null_ _null_ bitfromint4 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to bitstring"); +DATA(insert OID = 1684 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ bittoint4 _null_ _null_ _null_ "" f)); +DESCR("convert bitstring to int4"); + +DATA(insert OID = 1685 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 16" _null_ _null_ _null_ _null_ bit _null_ _null_ _null_ "" f)); +DESCR("adjust bit() to typmod length"); +DATA(insert OID = 3158 ( varbit_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ varbit_transform _null_ _null_ _null_ "" f)); +DESCR("transform a varbit length coercion"); +DATA(insert OID = 1687 ( varbit PGNSP PGUID 12 1 0 0 varbit_transform f f f f t f i 3 0 1562 "1562 23 16" _null_ _null_ _null_ _null_ varbit _null_ _null_ _null_ "" f)); +DESCR("adjust varbit() to typmod length"); + +DATA(insert OID = 1698 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 1560" _null_ _null_ _null_ _null_ bitposition _null_ _null_ _null_ "" f)); +DESCR("position of sub-bitstring"); +#define BITPOSITIONFUNCOID 1698 +DATA(insert OID = 1699 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "1560 23" _null_ _null_ _null_ _null_ bitsubstr_no_len _null_ _null_ _null_ "" f)); +#define BITSUBSTRINGNOLENFUNCOID 1699 +DESCR("extract portion of bitstring"); + +DATA(insert OID = 3030 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 1560 "1560 1560 23 23" _null_ _null_ _null_ _null_ bitoverlay _null_ _null_ _null_ "" f)); +DESCR("substitute portion of bitstring"); +DATA(insert OID = 3031 ( overlay PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 1560 23" _null_ _null_ _null_ _null_ bitoverlay_no_len _null_ _null_ _null_ "" f)); +DESCR("substitute portion of bitstring"); +DATA(insert OID = 3032 ( get_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1560 23" _null_ _null_ _null_ _null_ bitgetbit _null_ _null_ _null_ "" f)); +DESCR("get bit"); +DATA(insert OID = 3033 ( set_bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "1560 23 23" _null_ _null_ _null_ _null_ bitsetbit _null_ _null_ _null_ "" f)); +DESCR("set bit"); + +/* for mac type support */ +DATA(insert OID = 436 ( macaddr_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "2275" _null_ _null_ _null_ _null_ macaddr_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 437 ( macaddr_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "829" _null_ _null_ _null_ _null_ macaddr_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 753 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "829" _null_ _null_ _null_ _null_ macaddr_trunc _null_ _null_ _null_ "" f)); +DESCR("MAC manufacturer fields"); + +DATA(insert OID = 830 ( macaddr_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 831 ( macaddr_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 832 ( macaddr_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 833 ( macaddr_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 834 ( macaddr_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 835 ( macaddr_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "829 829" _null_ _null_ _null_ _null_ macaddr_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 836 ( macaddr_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "829 829" _null_ _null_ _null_ _null_ macaddr_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3144 ( macaddr_not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "829" _null_ _null_ _null_ _null_ macaddr_not _null_ _null_ _null_ "" f)); +DATA(insert OID = 3145 ( macaddr_and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 829 "829 829" _null_ _null_ _null_ _null_ macaddr_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 3146 ( macaddr_or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 829 "829 829" _null_ _null_ _null_ _null_ macaddr_or _null_ _null_ _null_ "" f)); + +/* for inet type support */ +DATA(insert OID = 910 ( inet_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "2275" _null_ _null_ _null_ _null_ inet_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 911 ( inet_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "869" _null_ _null_ _null_ _null_ inet_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* for cidr type support */ +DATA(insert OID = 1267 ( cidr_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "2275" _null_ _null_ _null_ _null_ cidr_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1427 ( cidr_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "650" _null_ _null_ _null_ _null_ cidr_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* these are used for both inet and cidr */ +DATA(insert OID = 920 ( network_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 921 ( network_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 922 ( network_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 923 ( network_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 924 ( network_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 925 ( network_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 926 ( network_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "869 869" _null_ _null_ _null_ _null_ network_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 927 ( network_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 928 ( network_subeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_subeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 929 ( network_sup PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sup _null_ _null_ _null_ "" f)); +DATA(insert OID = 930 ( network_supeq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_supeq _null_ _null_ _null_ "" f)); + +/* inet/cidr functions */ +DATA(insert OID = 598 ( abbrev PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ inet_abbrev _null_ _null_ _null_ "" f)); +DESCR("abbreviated display of inet value"); +DATA(insert OID = 599 ( abbrev PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "650" _null_ _null_ _null_ _null_ cidr_abbrev _null_ _null_ _null_ "" f)); +DESCR("abbreviated display of cidr value"); +DATA(insert OID = 605 ( set_masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 23" _null_ _null_ _null_ _null_ inet_set_masklen _null_ _null_ _null_ "" f)); +DESCR("change netmask of inet"); +DATA(insert OID = 635 ( set_masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 650 "650 23" _null_ _null_ _null_ _null_ cidr_set_masklen _null_ _null_ _null_ "" f)); +DESCR("change netmask of cidr"); +DATA(insert OID = 711 ( family PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ network_family _null_ _null_ _null_ "" f)); +DESCR("address family (4 for IPv4, 6 for IPv6)"); +DATA(insert OID = 683 ( network PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "869" _null_ _null_ _null_ _null_ network_network _null_ _null_ _null_ "" f)); +DESCR("network part of address"); +DATA(insert OID = 696 ( netmask PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_netmask _null_ _null_ _null_ "" f)); +DESCR("netmask of address"); +DATA(insert OID = 697 ( masklen PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "869" _null_ _null_ _null_ _null_ network_masklen _null_ _null_ _null_ "" f)); +DESCR("netmask length"); +DATA(insert OID = 698 ( broadcast PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_broadcast _null_ _null_ _null_ "" f)); +DESCR("broadcast address of network"); +DATA(insert OID = 699 ( host PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ network_host _null_ _null_ _null_ "" f)); +DESCR("show address octets only"); +DATA(insert OID = 730 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "869" _null_ _null_ _null_ _null_ network_show _null_ _null_ _null_ "" f)); +DESCR("show all parts of inet/cidr value"); +DATA(insert OID = 1362 ( hostmask PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ network_hostmask _null_ _null_ _null_ "" f)); +DESCR("hostmask of address"); +DATA(insert OID = 1715 ( cidr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "869" _null_ _null_ _null_ _null_ inet_to_cidr _null_ _null_ _null_ "" f)); +DESCR("convert inet to cidr"); + +DATA(insert OID = 2196 ( inet_client_addr PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 869 "" _null_ _null_ _null_ _null_ inet_client_addr _null_ _null_ _null_ "" f)); +DESCR("inet address of the client"); +DATA(insert OID = 2197 ( inet_client_port PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 23 "" _null_ _null_ _null_ _null_ inet_client_port _null_ _null_ _null_ "" f)); +DESCR("client's port number for this connection"); +DATA(insert OID = 2198 ( inet_server_addr PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 869 "" _null_ _null_ _null_ _null_ inet_server_addr _null_ _null_ _null_ "" f)); +DESCR("inet address of the server"); +DATA(insert OID = 2199 ( inet_server_port PGNSP PGUID 12 1 0 0 0 f f f f f f s 0 0 23 "" _null_ _null_ _null_ _null_ inet_server_port _null_ _null_ _null_ "" f)); +DESCR("server's port number for this connection"); + +DATA(insert OID = 2627 ( inetnot PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "869" _null_ _null_ _null_ _null_ inetnot _null_ _null_ _null_ "" f)); +DATA(insert OID = 2628 ( inetand PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ inetand _null_ _null_ _null_ "" f)); +DATA(insert OID = 2629 ( inetor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ inetor _null_ _null_ _null_ "" f)); +DATA(insert OID = 2630 ( inetpl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 20" _null_ _null_ _null_ _null_ inetpl _null_ _null_ _null_ "" f)); +DATA(insert OID = 2631 ( int8pl_inet PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 869 "20 869" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2632 ( inetmi_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 20" _null_ _null_ _null_ _null_ inetmi_int8 _null_ _null_ _null_ "" f)); +DATA(insert OID = 2633 ( inetmi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "869 869" _null_ _null_ _null_ _null_ inetmi _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1690 ( time_mi_time PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1083 1083" _null_ _null_ _null_ _null_ time_mi_time _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1691 ( boolle PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolle _null_ _null_ _null_ "" f)); +DATA(insert OID = 1692 ( boolge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1693 ( btboolcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 16" _null_ _null_ _null_ _null_ btboolcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 1688 ( time_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1083" _null_ _null_ _null_ _null_ time_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 1696 ( timetz_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1266" _null_ _null_ _null_ _null_ timetz_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 1697 ( interval_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1186" _null_ _null_ _null_ _null_ interval_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); + + +/* OID's 1700 - 1799 NUMERIC data type */ +DATA(insert OID = 1701 ( numeric_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1700 "2275 26 23" _null_ _null_ _null_ _null_ numeric_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1702 ( numeric_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "1700" _null_ _null_ _null_ _null_ numeric_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2917 ( numerictypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ numerictypmodin _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 2918 ( numerictypmodout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "23" _null_ _null_ _null_ _null_ numerictypmodout _null_ _null_ _null_ "" f)); +DESCR("I/O typmod"); +DATA(insert OID = 3157 ( numeric_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ numeric_transform _null_ _null_ _null_ "" f)); +DESCR("transform a numeric length coercion"); +DATA(insert OID = 1703 ( numeric PGNSP PGUID 12 1 0 0 numeric_transform f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric _null_ _null_ _null_ "" f)); +DESCR("adjust numeric to typmod precision/scale"); +DATA(insert OID = 1704 ( numeric_abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_abs _null_ _null_ _null_ "" f)); +DATA(insert OID = 1705 ( abs PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_abs _null_ _null_ _null_ "" f)); +DESCR("absolute value"); +DATA(insert OID = 1706 ( sign PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sign _null_ _null_ _null_ "" f)); +DESCR("sign of value"); +DATA(insert OID = 1707 ( round PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric_round _null_ _null_ _null_ "" f)); +DESCR("value rounded to 'scale'"); +DATA(insert OID = 1708 ( round PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.round($1,0)" _null_ _null_ _null_ "" f)); +DESCR("value rounded to 'scale' of zero"); +DATA(insert OID = 1709 ( trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 23" _null_ _null_ _null_ _null_ numeric_trunc _null_ _null_ _null_ "" f)); +DESCR("value truncated to 'scale'"); +DATA(insert OID = 1710 ( trunc PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.trunc($1,0)" _null_ _null_ _null_ "" f)); +DESCR("value truncated to 'scale' of zero"); +DATA(insert OID = 1711 ( ceil PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 2167 ( ceiling PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ceil _null_ _null_ _null_ "" f)); +DESCR("nearest integer >= value"); +DATA(insert OID = 1712 ( floor PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_floor _null_ _null_ _null_ "" f)); +DESCR("nearest integer <= value"); +DATA(insert OID = 1718 ( numeric_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1719 ( numeric_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1720 ( numeric_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1721 ( numeric_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 1722 ( numeric_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1723 ( numeric_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1700 1700" _null_ _null_ _null_ _null_ numeric_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1724 ( numeric_add PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_add _null_ _null_ _null_ "" f)); +DATA(insert OID = 1725 ( numeric_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_sub _null_ _null_ _null_ "" f)); +DATA(insert OID = 1726 ( numeric_mul PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mul _null_ _null_ _null_ "" f)); +DATA(insert OID = 1727 ( numeric_div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div _null_ _null_ _null_ "" f)); +DATA(insert OID = 1728 ( mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mod _null_ _null_ _null_ "" f)); +DESCR("modulus"); +DATA(insert OID = 1729 ( numeric_mod PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_mod _null_ _null_ _null_ "" f)); +DATA(insert OID = 1730 ( sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +DATA(insert OID = 1731 ( numeric_sqrt PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_sqrt _null_ _null_ _null_ "" f)); +DESCR("square root"); +DATA(insert OID = 1732 ( exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_exp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 1733 ( numeric_exp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_exp _null_ _null_ _null_ "" f)); +DESCR("natural exponential (e^x)"); +DATA(insert OID = 1734 ( ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ln _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1735 ( numeric_ln PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_ln _null_ _null_ _null_ "" f)); +DESCR("natural logarithm"); +DATA(insert OID = 1736 ( log PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_log _null_ _null_ _null_ "" f)); +DESCR("logarithm base m of n"); +DATA(insert OID = 1737 ( numeric_log PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_log _null_ _null_ _null_ "" f)); +DESCR("logarithm base m of n"); +DATA(insert OID = 1738 ( pow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +DATA(insert OID = 2169 ( power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DESCR("exponentiation"); +DATA(insert OID = 1739 ( numeric_power PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_power _null_ _null_ _null_ "" f)); +DATA(insert OID = 1740 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "23" _null_ _null_ _null_ _null_ int4_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int4 to numeric"); +DATA(insert OID = 1741 ( log PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ "select pg_catalog.log(10, $1)" _null_ _null_ _null_ "" f)); +DESCR("base 10 logarithm"); +DATA(insert OID = 1742 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "700" _null_ _null_ _null_ _null_ float4_numeric _null_ _null_ _null_ "" f)); +DESCR("convert float4 to numeric"); +DATA(insert OID = 1743 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "701" _null_ _null_ _null_ _null_ float8_numeric _null_ _null_ _null_ "" f)); +DESCR("convert float8 to numeric"); +DATA(insert OID = 1744 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1700" _null_ _null_ _null_ _null_ numeric_int4 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int4"); +DATA(insert OID = 1745 ( float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1700" _null_ _null_ _null_ _null_ numeric_float4 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to float4"); +DATA(insert OID = 1746 ( float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1700" _null_ _null_ _null_ _null_ numeric_float8 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to float8"); +#define NUMTOFLOAT8FUNCOID 1746 +DATA(insert OID = 1973 ( div PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div_trunc _null_ _null_ _null_ "" f)); +DESCR("trunc(x/y)"); +DATA(insert OID = 1980 ( numeric_div_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_div_trunc _null_ _null_ _null_ "" f)); +DESCR("trunc(x/y)"); +DATA(insert OID = 2170 ( width_bucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "1700 1700 1700 23" _null_ _null_ _null_ _null_ width_bucket_numeric _null_ _null_ _null_ "" f)); +DESCR("bucket number of operand in equidepth histogram"); + +DATA(insert OID = 1747 ( time_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1186" _null_ _null_ _null_ _null_ time_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1748 ( time_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1083 "1083 1186" _null_ _null_ _null_ _null_ time_mi_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1749 ( timetz_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1186" _null_ _null_ _null_ _null_ timetz_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 1750 ( timetz_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1266 1186" _null_ _null_ _null_ _null_ timetz_mi_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1764 ( numeric_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_inc _null_ _null_ _null_ "" f)); +DESCR("increment by one"); +DATA(insert OID = 1766 ( numeric_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 1767 ( numeric_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "1700 1700" _null_ _null_ _null_ _null_ numeric_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1769 ( numeric_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 1700" _null_ _null_ _null_ _null_ numeric_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3283 ( numeric_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ numeric_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 1771 ( numeric_uminus PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_uminus _null_ _null_ _null_ "" f)); +DATA(insert OID = 1779 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1700" _null_ _null_ _null_ _null_ numeric_int8 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int8"); +DATA(insert OID = 1781 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "20" _null_ _null_ _null_ _null_ int8_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int8 to numeric"); +DATA(insert OID = 1782 ( numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "21" _null_ _null_ _null_ _null_ int2_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int2 to numeric"); +DATA(insert OID = 1783 ( int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "1700" _null_ _null_ _null_ _null_ numeric_int2 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int2"); + +/* formatting */ +DATA(insert OID = 1770 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1184 25" _null_ _null_ _null_ _null_ timestamptz_to_char _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZ2CHARFUNCOID 1770 +DESCR("format timestamp with time zone to text"); +DATA(insert OID = 1772 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1700 25" _null_ _null_ _null_ _null_ numeric_to_char _null_ _null_ _null_ "" f)); +#define NUMERIC2CHARFUNCOID 1772 +DESCR("format numeric to text"); +DATA(insert OID = 1773 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "23 25" _null_ _null_ _null_ _null_ int4_to_char _null_ _null_ _null_ "" f)); +#define INTEGER2CHARFUNCOID 1773 +DESCR("format int4 to text"); +DATA(insert OID = 1774 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "20 25" _null_ _null_ _null_ _null_ int8_to_char _null_ _null_ _null_ "" f)); +#define BIGINT2CHARFUNCOID 1774 +DESCR("format int8 to text"); +DATA(insert OID = 1775 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "700 25" _null_ _null_ _null_ _null_ float4_to_char _null_ _null_ _null_ "" f)); +DESCR("format float4 to text"); +DATA(insert OID = 1776 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "701 25" _null_ _null_ _null_ _null_ float8_to_char _null_ _null_ _null_ "" f)); +DESCR("format float8 to text"); +DATA(insert OID = 1777 ( to_number PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1700 "25 25" _null_ _null_ _null_ _null_ numeric_to_number _null_ _null_ _null_ "" f)); +DESCR("convert text to numeric"); +DATA(insert OID = 1778 ( to_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1114 "25 25" _null_ _null_ _null_ _null_ to_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp with time zone"); +#define TOTIMESTAMPFUNCOID 1778 +DATA(insert OID = 3207 ( to_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "25" _null_ _null_ _null_ _null_ to_timestamp_default_format _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp without time zone"); +DATA(insert OID = 1780 ( to_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 1114 "25 25" _null_ _null_ _null_ _null_ to_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to date"); +#define TODATEFUNCOID 1780 +DATA(insert OID = 1768 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1186 25" _null_ _null_ _null_ _null_ interval_to_char _null_ _null_ _null_ "" f)); +DESCR("format interval to text"); + +DATA(insert OID = 1282 ( quote_ident PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_ident _null_ _null_ _null_ "" f)); +DESCR("quote an identifier for usage in a querystring"); +DATA(insert OID = 1283 ( quote_literal PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_literal _null_ _null_ _null_ "" f)); +DESCR("quote a literal for usage in a querystring"); +DATA(insert OID = 1285 ( quote_literal PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 25 "2283" _null_ _null_ _null_ _null_ "select pg_catalog.quote_literal($1::pg_catalog.text)" _null_ _null_ _null_ "" f)); +DESCR("quote a data value for usage in a querystring"); +DATA(insert OID = 1289 ( quote_nullable PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ quote_nullable _null_ _null_ _null_ "" f)); +DESCR("quote a possibly-null literal for usage in a querystring"); +DATA(insert OID = 1290 ( quote_nullable PGNSP PGUID 14 1 0 0 0 f f f f f f s 1 0 25 "2283" _null_ _null_ _null_ _null_ "select pg_catalog.quote_nullable($1::pg_catalog.text)" _null_ _null_ _null_ "" f)); +DESCR("quote a possibly-null data value for usage in a querystring"); + +DATA(insert OID = 1798 ( oidin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2275" _null_ _null_ _null_ _null_ oidin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1799 ( oidout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ oidout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3058 ( concat PGNSP PGUID 12 1 0 2276 0 f f f f f f s 1 0 25 "2276" "{2276}" "{v}" _null_ _null_ text_concat _null_ _null_ _null_ "" f)); +DESCR("concatenate values"); +DATA(insert OID = 3059 ( concat_ws PGNSP PGUID 12 1 0 2276 0 f f f f f f s 2 0 25 "25 2276" "{25,2276}" "{i,v}" _null_ _null_ text_concat_ws _null_ _null_ _null_ "" f)); +DESCR("concatenate values with separators"); +DATA(insert OID = 3060 ( left PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_left _null_ _null_ _null_ "" f)); +DESCR("extract the first n characters"); +DATA(insert OID = 3061 ( right PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ text_right _null_ _null_ _null_ "" f)); +DESCR("extract the last n characters"); +DATA(insert OID = 3062 ( reverse PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ text_reverse _null_ _null_ _null_ "" f)); +DESCR("reverse text"); +DATA(insert OID = 3539 ( format PGNSP PGUID 12 1 0 2276 0 f f f f f f s 2 0 25 "25 2276" "{25,2276}" "{i,v}" _null_ _null_ text_format _null_ _null_ _null_ "" f)); +DESCR("format text message"); +DATA(insert OID = 3540 ( format PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 25 "25" _null_ _null_ _null_ _null_ text_format_nv _null_ _null_ _null_ "" f)); +DESCR("format text message"); + +DATA(insert OID = 1810 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ "select pg_catalog.octet_length($1) * 8" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); +DATA(insert OID = 1811 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ "select pg_catalog.octet_length($1) * 8" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); +DATA(insert OID = 1812 ( bit_length PGNSP PGUID 14 1 0 0 0 f f f f t f i 1 0 23 "1560" _null_ _null_ _null_ _null_ "select pg_catalog.length($1)" _null_ _null_ _null_ "" f)); +DESCR("length in bits"); + +/* Selectivity estimators for LIKE and related operators */ +DATA(insert OID = 1814 ( iclikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ iclikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of ILIKE"); +DATA(insert OID = 1815 ( icnlikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icnlikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of NOT ILIKE"); +DATA(insert OID = 1816 ( iclikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ iclikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of ILIKE"); +DATA(insert OID = 1817 ( icnlikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icnlikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of NOT ILIKE"); +DATA(insert OID = 1818 ( regexeqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ regexeqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of regex match"); +DATA(insert OID = 1819 ( likesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ likesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of LIKE"); +DATA(insert OID = 1820 ( icregexeqsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icregexeqsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of case-insensitive regex match"); +DATA(insert OID = 1821 ( regexnesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ regexnesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of regex non-match"); +DATA(insert OID = 1822 ( nlikesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ nlikesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of NOT LIKE"); +DATA(insert OID = 1823 ( icregexnesel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ icregexnesel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of case-insensitive regex non-match"); +DATA(insert OID = 1824 ( regexeqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ regexeqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of regex match"); +DATA(insert OID = 1825 ( likejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ likejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of LIKE"); +DATA(insert OID = 1826 ( icregexeqjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icregexeqjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of case-insensitive regex match"); +DATA(insert OID = 1827 ( regexnejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ regexnejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of regex non-match"); +DATA(insert OID = 1828 ( nlikejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ nlikejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of NOT LIKE"); +DATA(insert OID = 1829 ( icregexnejoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ icregexnejoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of case-insensitive regex non-match"); + +/* Aggregate-related functions */ +DATA(insert OID = 1830 ( float8_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2512 ( float8_var_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_var_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1831 ( float8_var_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_var_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2513 ( float8_stddev_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_stddev_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1832 ( float8_stddev_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_stddev_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1833 ( numeric_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1700" _null_ _null_ _null_ _null_ numeric_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2858 ( numeric_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1700" _null_ _null_ _null_ _null_ numeric_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1834 ( int2_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 21" _null_ _null_ _null_ _null_ int2_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1835 ( int4_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 23" _null_ _null_ _null_ _null_ int4_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1836 ( int8_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 20" _null_ _null_ _null_ _null_ int8_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2746 ( int8_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 20" _null_ _null_ _null_ _null_ int8_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1837 ( numeric_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2514 ( numeric_var_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_var_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1838 ( numeric_var_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_var_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2596 ( numeric_stddev_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_stddev_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1839 ( numeric_stddev_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1231" _null_ _null_ _null_ _null_ numeric_stddev_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 1840 ( int2_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 21" _null_ _null_ _null_ _null_ int2_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1841 ( int4_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int4_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1842 ( int8_sum PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1700 "1700 20" _null_ _null_ _null_ _null_ int8_sum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1843 ( interval_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1187 "1187 1186" _null_ _null_ _null_ _null_ interval_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1844 ( interval_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1187" _null_ _null_ _null_ _null_ interval_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 5548 ( int1_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 5545" _null_ _null_ _null_ _null_ int1_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1962 ( int2_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 21" _null_ _null_ _null_ _null_ int2_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1963 ( int4_avg_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 23" _null_ _null_ _null_ _null_ int4_avg_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 1964 ( int8_avg PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1016" _null_ _null_ _null_ _null_ int8_avg _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2805 ( int8inc_float8_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 20 "20 701 701" _null_ _null_ _null_ _null_ int8inc_float8_float8 _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2806 ( float8_regr_accum PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1022 "1022 701 701" _null_ _null_ _null_ _null_ float8_regr_accum _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2807 ( float8_regr_sxx PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_sxx _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2808 ( float8_regr_syy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_syy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2809 ( float8_regr_sxy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_sxy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2810 ( float8_regr_avgx PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_avgx _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2811 ( float8_regr_avgy PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_avgy _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2812 ( float8_regr_r2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_r2 _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2813 ( float8_regr_slope PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_slope _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2814 ( float8_regr_intercept PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_regr_intercept _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2815 ( float8_covar_pop PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_covar_pop _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2816 ( float8_covar_samp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_covar_samp _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 2817 ( float8_corr PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1022" _null_ _null_ _null_ _null_ float8_corr _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); + +DATA(insert OID = 3535 ( string_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2281 "2281 25 25" _null_ _null_ _null_ _null_ string_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +#define STRINGAGGTRANSFNFUNCOID 3535 +#ifdef PGXC +DATA(insert OID = 2966 ( float8_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 1022" _null_ _null_ _null_ _null_ float8_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2964 ( numeric_avg_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1231" _null_ _null_ _null_ _null_ numeric_avg_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2968 ( numeric_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1231 "1231 1231" _null_ _null_ _null_ _null_ numeric_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate collection function"); +DATA(insert OID = 2967 ( interval_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1187 "1187 1187" _null_ _null_ _null_ _null_ interval_collect _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2965 ( int8_avg_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1016 "1016 1016" _null_ _null_ _null_ _null_ int8_avg_collect _null_ _null_ _null_ "" f)); +DESCR("AVG(int) collection function"); +DATA(insert OID = 2996 ( int8_sum_to_int8 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8_sum_to_int8 _null_ _null_ _null_ "" f)); +DESCR("SUM(int) collection function"); +DATA(insert OID = 2995 ( float8_regr_collect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1022 "1022 1022" _null_ _null_ _null_ _null_ float8_regr_collect _null_ _null_ _null_ "" f)); +DESCR("REGR_...(double, double) collection function"); +#endif +DATA(insert OID = 3536 ( string_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 25 "2281" _null_ _null_ _null_ _null_ string_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 3538 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into a string"); +#define STRINGAGGFUNCOID 3538 +DATA(insert OID = 3543 ( bytea_string_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 2281 "2281 17 17" _null_ _null_ _null_ _null_ bytea_string_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 3544 ( bytea_string_agg_finalfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytea_string_agg_finalfn _null_ _null_ _null_ "" f)); +DESCR("aggregate final function"); +DATA(insert OID = 3545 ( string_agg PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate aggregate input into a bytea"); +#define BYTEASTRINGAGGFUNCOID 3545 + +DATA(insert OID = 4600 ( checksum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("checksum aggregate text input into a numeric"); +DATA(insert OID = 4601 ( checksumtext_agg_transfn PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 1700 "1700 25" _null_ _null_ _null_ _null_ checksumtext_agg_transfn _null_ _null_ _null_ "" f)); +DESCR("checksumtext aggregate transition function"); + +/* To ASCII conversion */ +DATA(insert OID = 1845 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ to_ascii_default _null_ _null_ _null_ "" f)); +DESCR("encode text from DB encoding to ASCII text"); +DATA(insert OID = 1846 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 23" _null_ _null_ _null_ _null_ to_ascii_enc _null_ _null_ _null_ "" f)); +DESCR("encode text from encoding to ASCII text"); +DATA(insert OID = 1847 ( to_ascii PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 19" _null_ _null_ _null_ _null_ to_ascii_encname _null_ _null_ _null_ "" f)); +DESCR("encode text from encoding to ASCII text"); + +DATA(insert OID = 1848 ( interval_pl_time PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1083 "1186 1083" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1850 ( int28eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1851 ( int28ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1852 ( int28lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1853 ( int28gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1854 ( int28le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1855 ( int28ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "21 20" _null_ _null_ _null_ _null_ int28ge _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1856 ( int82eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1857 ( int82ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 1858 ( int82lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1859 ( int82gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1860 ( int82le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82le _null_ _null_ _null_ "" f)); +DATA(insert OID = 1861 ( int82ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "20 21" _null_ _null_ _null_ _null_ int82ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 6101 ( int1and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1and _null_ _null_ _null_ "" f)); +DESCR("int1 and int1"); +DATA(insert OID = 6102 ( int1or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1or _null_ _null_ _null_ "" f)); +DESCR("int1 or int1"); +DATA(insert OID = 6103 ( int1xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 5545" _null_ _null_ _null_ _null_ int1xor _null_ _null_ _null_ "" f)); +DESCR("int1 xor int1"); +DATA(insert OID = 6104 ( int1not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1not _null_ _null_ _null_ "" f)); +DESCR("int1 not int1"); +DATA(insert OID = 6105 ( int1shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 23" _null_ _null_ _null_ _null_ int1shl _null_ _null_ _null_ "" f)); +DESCR("left shift"); +DATA(insert OID = 6106 ( int1shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 5545 "5545 23" _null_ _null_ _null_ _null_ int1shr _null_ _null_ _null_ "" f)); +DESCR("right shift"); +DATA(insert OID = 1892 ( int2and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1893 ( int2or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1894 ( int2xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 21" _null_ _null_ _null_ _null_ int2xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1895 ( int2not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1896 ( int2shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 23" _null_ _null_ _null_ _null_ int2shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1897 ( int2shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "21 23" _null_ _null_ _null_ _null_ int2shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1898 ( int4and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1899 ( int4or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1900 ( int4xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1901 ( int4not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1902 ( int4shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1903 ( int4shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ int4shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1904 ( int8and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8and _null_ _null_ _null_ "" f)); +DATA(insert OID = 1905 ( int8or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8or _null_ _null_ _null_ "" f)); +DATA(insert OID = 1906 ( int8xor PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 20" _null_ _null_ _null_ _null_ int8xor _null_ _null_ _null_ "" f)); +DATA(insert OID = 1907 ( int8not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8not _null_ _null_ _null_ "" f)); +DATA(insert OID = 1908 ( int8shl PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int8shl _null_ _null_ _null_ "" f)); +DATA(insert OID = 1909 ( int8shr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 20 "20 23" _null_ _null_ _null_ _null_ int8shr _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1910 ( int8up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "20" _null_ _null_ _null_ _null_ int8up _null_ _null_ _null_ "" f)); +DATA(insert OID = 6107 ( int1up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ int1up _null_ _null_ _null_ "" f)); +DESCR("int1up"); +DATA(insert OID = 1911 ( int2up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "21" _null_ _null_ _null_ _null_ int2up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1912 ( int4up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ int4up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1913 ( float4up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "700" _null_ _null_ _null_ _null_ float4up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1914 ( float8up PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "701" _null_ _null_ _null_ _null_ float8up _null_ _null_ _null_ "" f)); +DATA(insert OID = 1915 ( numeric_uplus PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ numeric_uplus _null_ _null_ _null_ "" f)); + +DATA(insert OID = 1922 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_table_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by username, rel name"); +DATA(insert OID = 1923 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_table_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by username, rel oid"); +DATA(insert OID = 1924 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_table_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by user oid, rel name"); +DATA(insert OID = 1925 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_table_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on relation by user oid, rel oid"); +DATA(insert OID = 1926 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_table_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on relation by rel name"); +DATA(insert OID = 1927 ( has_table_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_table_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on relation by rel oid"); + +DATA(insert OID = 2181 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by username, seq name"); +DATA(insert OID = 2182 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by username, seq oid"); +DATA(insert OID = 2183 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by user oid, seq name"); +DATA(insert OID = 2184 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on sequence by user oid, seq oid"); +DATA(insert OID = 2185 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_sequence_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on sequence by seq name"); +DATA(insert OID = 2186 ( has_sequence_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_sequence_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on sequence by seq oid"); + +DATA(insert OID = 3012 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel name, col name"); +DATA(insert OID = 3013 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel name, col attnum"); +DATA(insert OID = 3014 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel oid, col name"); +DATA(insert OID = 3015 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "19 26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_id_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by username, rel oid, col attnum"); +DATA(insert OID = 3016 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel name, col name"); +DATA(insert OID = 3017 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel name, col attnum"); +DATA(insert OID = 3018 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel oid, col name"); +DATA(insert OID = 3019 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 16 "26 26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_id_attnum _null_ _null_ _null_ "" f)); +DESCR("user privilege on column by user oid, rel oid, col attnum"); +DATA(insert OID = 3020 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "25 25 25" _null_ _null_ _null_ _null_ has_column_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel name, col name"); +DATA(insert OID = 3021 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "25 21 25" _null_ _null_ _null_ _null_ has_column_privilege_name_attnum _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel name, col attnum"); +DATA(insert OID = 3022 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_column_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel oid, col name"); +DATA(insert OID = 3023 ( has_column_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 21 25" _null_ _null_ _null_ _null_ has_column_privilege_id_attnum _null_ _null_ _null_ "" f)); +DESCR("current user privilege on column by rel oid, col attnum"); + +DATA(insert OID = 3024 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by username, rel name"); +DATA(insert OID = 3025 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by username, rel oid"); +DATA(insert OID = 3026 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by user oid, rel name"); +DATA(insert OID = 3027 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on any column by user oid, rel oid"); +DATA(insert OID = 3028 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_any_column_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on any column by rel name"); +DATA(insert OID = 3029 ( has_any_column_privilege PGNSP PGUID 12 10 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_any_column_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on any column by rel oid"); + + +DATA(insert OID = 3843 ( pg_control_group_config PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pg_control_group_config _null_ _null_ _null_ "" f)); +DESCR("control group config on current node."); +DATA(insert OID = 1928 ( pg_stat_get_numscans PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_numscans _null_ _null_ _null_ "" f)); +DESCR("statistics: number of scans done for table/index"); +DATA(insert OID = 1929 ( pg_stat_get_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples read by seqscan"); +DATA(insert OID = 1930 ( pg_stat_get_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples fetched by idxscan"); +DATA(insert OID = 1931 ( pg_stat_get_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples inserted"); +DATA(insert OID = 1932 ( pg_stat_get_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples updated"); +DATA(insert OID = 1933 ( pg_stat_get_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples deleted"); +DATA(insert OID = 1972 ( pg_stat_get_tuples_hot_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_tuples_hot_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples hot updated"); +DATA(insert OID = 2878 ( pg_stat_get_live_tuples PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_live_tuples _null_ _null_ _null_ "" f)); +DESCR("statistics: number of live tuples"); +DATA(insert OID = 2879 ( pg_stat_get_dead_tuples PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_dead_tuples _null_ _null_ _null_ "" f)); +DESCR("statistics: number of dead tuples"); +DATA(insert OID = 1934 ( pg_stat_get_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks fetched"); +DATA(insert OID = 1935 ( pg_stat_get_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks found in cache"); +DATA(insert OID = 2781 ( pg_stat_get_last_vacuum_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_vacuum_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last manual vacuum time for a table"); +DATA(insert OID = 2782 ( pg_stat_get_last_autovacuum_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_autovacuum_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last auto vacuum time for a table"); +DATA(insert OID = 2783 ( pg_stat_get_last_analyze_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_analyze_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last manual analyze time for a table"); +DATA(insert OID = 2784 ( pg_stat_get_last_autoanalyze_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_last_autoanalyze_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last auto analyze time for a table"); +DATA(insert OID = 3054 ( pg_stat_get_vacuum_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_vacuum_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of manual vacuums for a table"); +DATA(insert OID = 3055 ( pg_stat_get_autovacuum_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autovacuum_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of auto vacuums for a table"); +DATA(insert OID = 3056 ( pg_stat_get_analyze_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_analyze_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of manual analyzes for a table"); +DATA(insert OID = 3057 ( pg_stat_get_autoanalyze_count PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_autoanalyze_count _null_ _null_ _null_ "" f)); +DESCR("statistics: number of auto analyzes for a table"); +DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 0 f f f f t t s 0 0 23 "" _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ "" f)); +DESCR("statistics: currently active backend IDs"); +DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,26,20,26,25,25,25,16,1184,1184,1184,1184,869,25,23,25,20}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,pid,usesysid,application_name,state,query,waiting,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,enqueue,query_id}" _null_ pg_stat_get_activity _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active backends"); +DATA(insert OID = 3980 ( pg_stat_get_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,25,25,25,20,20,23,23,23,23,25,25}" "{i,o,o,o,o,o,o,o,o,o,o,o}" "{tid,node_name,db_name,thread_name,query_id,tid,lwtid,ptid,tlevel,smpid,wait_status,wait_event}" _null_ pg_stat_get_status _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active threads"); +DATA(insert OID = 3981 ( pg_stat_get_thread PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,20,23,25,1184}" "{o,o,o,o,o}" "{node_name,pid,lwpid,thread_name,creation_time}" _null_ pg_stat_get_thread _null_ _null_ _null_ "" f)); +DESCR("statistics: information about now active threads"); +DATA(insert OID = 3982 ( pg_stat_get_env PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,23,23,25,25,25}" "{o,o,o,o,o,o,o}" "{node_name,host,process,port,installpath,datapath,log_directory}" _null_ pg_stat_get_env _null_ _null_ _null_ "" f)); +DESCR("statistics: information about environment variables"); +DATA(insert OID = 3947 ( pg_stat_get_sql_count PGNSP PGUID 12 1 0 0 0 f f f f f t s 0 0 2249 "" "{25,25,20,20,20,20,20}" "{o,o,o,o,o,o,o}" "{node_name,user_name,select_count,update_count,insert_count,delete_count,mergeinto_count}" _null_ pg_stat_get_sql_count _null_ _null_ _null_ "" f)); +DESCR("statistics: sql count information about currently node"); + +/* stream replication */ +DATA(insert OID = 3099 ( pg_stat_get_wal_senders PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{20,23,25,25,25,25,1184,1184,25,25,25,25,25,25,25,25,25,25,23,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,sender_pid,local_role,peer_role,peer_state,state,catchup_start,catchup_end,sender_sent_location,sender_write_location,sender_flush_location,sender_replay_location,receiver_received_location,receiver_write_location,receiver_flush_location,receiver_replay_location,sync_percent,sync_state,sync_priority,sync_most_available,channel}" _null_ pg_stat_get_wal_senders _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active wal senders"); +DATA(insert OID = 3819 ( pg_stat_get_wal_receiver PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{23,25,25,25,25,25,25,25,25,25,25,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{receiver_pid,local_role,peer_role,peer_state,state,sender_sent_location,sender_write_location,sender_flush_location,sender_replay_location,receiver_received_location,receiver_write_location,receiver_flush_location,receiver_replay_location,sync_percent,channel}" _null_ pg_stat_get_wal_receiver _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently wal receiver"); +DATA(insert OID = 3499 ( pg_stat_get_stream_replications PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,25}" "{o,o,o,o}" "{local_role,static_connections,db_state,detail_information}" _null_ pg_stat_get_stream_replications _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently stream replication"); +DATA(insert OID = 3785 ( pg_stat_get_data_senders PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{20,23,25,25,25,1184,1184,23,25,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,sender_pid,local_role,peer_role,state,catchup_start,catchup_end,queue_size,queue_lower_tail,queue_header,queue_upper_tail,send_position,receive_position}" _null_ pg_stat_get_data_senders _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently active data senders"); +DATA(insert OID = 3972 ( pv_instance_time PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{23,25,20}" "{o,o,o}" "{stat_id,stat_name,value}" _null_ pv_instance_time _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the instance time for various operations"); +DATA(insert OID = 3970 ( pv_os_run_info PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{23,25,1700,25,16}" "{o,o,o,o,o}" "{id,name,value,comments,cumulative}" _null_ pv_os_run_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about system performance."); +DATA(insert OID = 3971 ( pv_session_memory_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,25,21,25,20,20,20}" "{o,o,o,o,o,o,o,o}" "{sessid,sesstype,contextname,level,parent,totalsize,freesize,usedsize}" _null_ pv_session_memory_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session memory detail"); +DATA(insert OID = 3972 ( pv_session_time PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,20}" "{o,o,o,o}" "{sessid,stat_id,stat_name,value}" _null_ pv_session_time _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the session-accumulated time for various operations"); +DATA(insert OID = 3973 ( pg_stat_get_redo_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o}" "{phywrts,phyblkwrt,writetim,avgiotim,lstiotim,miniotim,maxiowtm}" _null_ pg_stat_get_redo_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about pv_redo_stat"); +DATA(insert OID = 3974 ( pv_session_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,23,25,25,20}" "{o,o,o,o,o}" "{sessid,statid,statname,statunit,value}" _null_ pv_session_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session status"); +DATA(insert OID = 3975 ( pg_stat_get_file_stat PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{26,26,26,20,20,20,20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o}" "{filenum,dbid,spcid,phyrds,phywrts,phyblkrd,phyblkwrt,readtim,writetim,avgiotim,lstiotim,miniotim,maxiowtm}" _null_ pg_stat_get_file_stat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about pv_file_stat"); +DATA(insert OID = 3976 ( total_cpu PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ total_cpu _null_ _null_ _null_ "" f)); +DESCR("statistics: MppDB cpu usage."); +DATA(insert OID = 3977 ( get_hostname PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ get_hostname _null_ _null_ _null_ "" f)); +DESCR("statistics: current host name"); +DATA(insert OID = 3978 ( sessionid2pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "2275" _null_ _null_ _null_ _null_ sessionid_to_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: convert session id to pid"); +DATA(insert OID = 3979 ( total_memory PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ total_memory _null_ _null_ _null_ "" f)); +DESCR("statistics: convert session id to pid"); +DATA(insert OID = 3983 ( pv_session_memctx_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 2 0 16 "20 2275" _null_ _null_ _null_ _null_ pv_session_memctx_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently session memory detail"); +DATA(insert OID = 3986 ( pg_shared_memory_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,21,25,20,20,20}" "{o,o,o,o,o,o}" "{contextname,level,parent,totalsize,freesize,usedsize}" _null_ pg_shared_memory_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently shared memory detail"); +DATA(insert OID = 3987 ( pg_shared_memctx_detail PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 16 "2275" _null_ _null_ _null_ _null_ pg_shared_memctx_detail _null_ _null_ _null_ "" f)); +DESCR("statistics: information about currently shared memory debug detail"); +DATA(insert OID = 2026 ( pg_backend_pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_backend_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: current backend PID"); +DATA(insert OID = 3984 ( pv_session_memory PGNSP PGUID 12 1 1000 0 0 f f f f f t s 0 0 2249 "" "{25,23,23,23}" "{o,o,o,o}" "{sessid,init_mem,used_mem,peak_mem}" _null_ pv_session_memory _null_ _null_ _null_ "" f)); +DESCR("statistics: information about the session-accumulated memory for various operations"); +DATA(insert OID = 3985 ( pv_total_memory_detail PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,25,23}" "{o,o,o}" "{nodename,memorytype,memorymbytes}" _null_ pv_total_memory_detail _null_ _null_ _null_ "" f)); +DESCR("total memory information on node"); +DATA(insert OID = 4500 ( gs_control_group_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{25,25,25,25,20,20,20,20,25}" "{o,o,o,o,o,o,o,o,o}" "{name,class,workload,type,gid,shares,limits,rate,cpucores}" _null_ gs_control_group_info _null_ _null_ _null_ "" f)); +DESCR("control group information on node"); +DATA(insert OID = 4501 ( gs_respool_exception_info PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 2249 "2275" "{25,25,25,25,25,20}" "{o,o,o,o,o,o}" "{name,class,workload,rule,type,value}" _null_ gs_respool_exception_info _null_ _null_ _null_ "" f)); +DESCR("resouce pool exception information on node"); +DATA(insert OID = 4502 ( gs_all_control_group_info PGNSP PGUID 12 1 100 0 0 f f f f t t v 0 0 2249 "" "{25,25,20,20,25,25,20,20,20,25}" "{o,o,o,o,o,o,o,o,o,o}" "{name,type,gid,classgid,class,workload,shares,limits,wdlevel,cpucores}" _null_ gs_all_control_group_info _null_ _null_ _null_ "" f)); +DESCR("get all control group information on node"); +DATA(insert OID = 4503 ( gs_cgroup_map_ng_conf PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 16 "2275" _null_ _null_ _null_ _null_ gs_cgroup_map_ng_conf _null_ _null_ _null_ "" f)); +DESCR("logical cluster: map the cgroup information into process for the logical cluster"); +#define PGBACKENDPIDFUNCOID 2026 +DATA(insert OID = 1937 ( pg_stat_get_backend_pid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_pid _null_ _null_ _null_ "" f)); +DESCR("statistics: PID of backend"); +#define PGSTATGETBACKENDPIDFUNCOID 1937 +DATA(insert OID = 1938 ( pg_stat_get_backend_dbid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_dbid _null_ _null_ _null_ "" f)); +DESCR("statistics: database ID of backend"); +DATA(insert OID = 1939 ( pg_stat_get_backend_userid PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_userid _null_ _null_ _null_ "" f)); +DESCR("statistics: user ID of backend"); +DATA(insert OID = 1940 ( pg_stat_get_backend_activity PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_activity _null_ _null_ _null_ "" f)); +DESCR("statistics: current query of backend"); +DATA(insert OID = 2853 ( pg_stat_get_backend_waiting PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_waiting _null_ _null_ _null_ "" f)); +DESCR("statistics: is backend currently waiting for a lock"); +DATA(insert OID = 2094 ( pg_stat_get_backend_activity_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_activity_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for current query of backend"); +DATA(insert OID = 2857 ( pg_stat_get_backend_xact_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_xact_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for backend's current transaction"); +DATA(insert OID = 1391 ( pg_stat_get_backend_start PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_start _null_ _null_ _null_ "" f)); +DESCR("statistics: start time for current backend session"); +DATA(insert OID = 1392 ( pg_stat_get_backend_client_addr PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 869 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_client_addr _null_ _null_ _null_ "" f)); +DESCR("statistics: address of client connected to backend"); +DATA(insert OID = 1393 ( pg_stat_get_backend_client_port PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "23" _null_ _null_ _null_ _null_ pg_stat_get_backend_client_port _null_ _null_ _null_ "" f)); +DESCR("statistics: port number of client connected to backend"); +DATA(insert OID = 1941 ( pg_stat_get_db_numbackends PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_numbackends _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backends in database"); +DATA(insert OID = 1942 ( pg_stat_get_db_xact_commit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_xact_commit _null_ _null_ _null_ "" f)); +DESCR("statistics: transactions committed"); +DATA(insert OID = 1943 ( pg_stat_get_db_xact_rollback PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_xact_rollback _null_ _null_ _null_ "" f)); +DESCR("statistics: transactions rolled back"); +DATA(insert OID = 1944 ( pg_stat_get_db_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: blocks fetched for database"); +DATA(insert OID = 1945 ( pg_stat_get_db_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: blocks found in cache for database"); +DATA(insert OID = 2758 ( pg_stat_get_db_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples returned for database"); +DATA(insert OID = 2759 ( pg_stat_get_db_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples fetched for database"); +DATA(insert OID = 2760 ( pg_stat_get_db_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples inserted in database"); +DATA(insert OID = 2761 ( pg_stat_get_db_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples updated in database"); +DATA(insert OID = 2762 ( pg_stat_get_db_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: tuples deleted in database"); +DATA(insert OID = 3065 ( pg_stat_get_db_conflict_tablespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_tablespace _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by drop tablespace"); +DATA(insert OID = 3066 ( pg_stat_get_db_conflict_lock PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_lock _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by relation lock"); +DATA(insert OID = 3067 ( pg_stat_get_db_conflict_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_snapshot _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by snapshot expiry"); +DATA(insert OID = 3068 ( pg_stat_get_db_conflict_bufferpin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_bufferpin _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by shared buffer pin"); +DATA(insert OID = 3069 ( pg_stat_get_db_conflict_startup_deadlock PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_startup_deadlock _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database caused by buffer deadlock"); +DATA(insert OID = 3070 ( pg_stat_get_db_conflict_all PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_conflict_all _null_ _null_ _null_ "" f)); +DESCR("statistics: recovery conflicts in database"); +DATA(insert OID = 3152 ( pg_stat_get_db_deadlocks PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_deadlocks _null_ _null_ _null_ "" f)); +DESCR("statistics: deadlocks detected in database"); +DATA(insert OID = 3074 ( pg_stat_get_db_stat_reset_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_stat_reset_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last reset for a database"); +DATA(insert OID = 3150 ( pg_stat_get_db_temp_files PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_temp_files _null_ _null_ _null_ "" f)); +DESCR("statistics: number of temporary files written"); +DATA(insert OID = 3151 ( pg_stat_get_db_temp_bytes PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_temp_bytes _null_ _null_ _null_ "" f)); +DESCR("statistics: number of bytes in temporary files written"); +DATA(insert OID = 2844 ( pg_stat_get_db_blk_read_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_read_time _null_ _null_ _null_ "" f)); +DESCR("statistics: block read time, in msec"); +DATA(insert OID = 2845 ( pg_stat_get_db_blk_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_write_time _null_ _null_ _null_ "" f)); +DESCR("statistics: block write time, in msec"); +DATA(insert OID = 2846 ( pg_stat_get_mem_mbytes_reserved PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "20" _null_ _null_ _null_ _null_ pg_stat_get_mem_mbytes_reserved _null_ _null_ _null_ "" f)); +DESCR("statistics: memory reserved, in Mbytes"); +DATA(insert OID = 3500 ( pg_stat_get_realtime_info_internal PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 25 "26 26 20 2275 26" _null_ _null_ _null_ _null_ pg_stat_get_realtime_info_internal _null_ _null_ _null_ "" f)); +DESCR("statistics: datanode session info"); +DATA(insert OID = 3501 ( pg_stat_get_wlm_statistics PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,20,20,20,20,23,25,25,25}" "{o,o,o,o,o,o,o,o,o}" "{statement,block_time,elapsed_time,total_cpu_time,qualification_time,skew_percent,control_group,status,action}" _null_ pg_stat_get_wlm_statistics _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of statement"); +DATA(insert OID = 3502 ( pg_stat_get_session_wlmstat PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,20,23,26,25,25,20,20,20,20,23,23,23,23,25,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{datid,threadid,threadpid,usesysid,appname,query,priority,block_time,elapsed_time,total_cpu_time,skew_percent,statement_mem,active_points,dop_value,current_cgroup,current_status,enqueue_state,attribute}" _null_ pg_stat_get_session_wlmstat _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session wlm statistics"); +DATA(insert OID = 3503 ( pg_wlm_jump_queue PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_wlm_jump_queue _null_ _null_ _null_ "" f)); +DESCR("wlm jump the queue"); +DATA(insert OID = 5001 ( pg_stat_get_wlm_session_info_internal PGNSP PGUID 12 1 100 0 0 f f f f f t s 4 0 25 "26 26 20 26" _null_ _null_ _null_ _null_ pg_stat_get_wlm_session_info_internal _null_ _null_ _null_ "" f)); +DESCR("session info: information about session wlm info"); +DATA(insert OID = 5002 ( pg_stat_get_wlm_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "26" "{26,25,25,25,25,25,869,25,23,25,20,1184,1184,20,20,25,25,25,25,23,23,23,23,23,25,23,23,23,23,20,20,20,23,20,20,20,23,23,23,23,23,25,23,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{datid,dbname,schemaname,nodename,username,application_name,client_addr,client_hostname,client_port,query_band,block_time,start_time,finish_time,duration,estimate_total_time,status,abort_info,resource_pool,control_group,estimate_memory,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,spill_info,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_dn_time,max_dn_time,average_dn_time,dntime_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,min_peak_iops,max_peak_iops,average_peak_iops,iops_skew_percent,warning,queryid,query,query_plan}" _null_ pg_stat_get_wlm_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of statement"); +DATA(insert OID = 5003 ( pg_stat_get_wlm_realtime_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,20,20,20,20,20,25,25,25,25,23,23,23,23,23,23,23,23,23,20,20,20,23,20,20,20,23,23,23,23,23,25,25,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{nodename,threadid,block_time,duration,estimate_total_time,estimate_left_time,schemaname,query_band,spill_info,control_group,estimate_memory,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_dn_time,max_dn_time,average_dn_time,dntime_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,min_peak_iops,max_peak_iops,average_peak_iops,iops_skew_percent,warning,query,query_plan}" _null_ pg_stat_get_wlm_realtime_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about realtime wlm statistics of statement"); +DATA(insert OID = 5004 ( gs_wlm_get_resource_pool_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{respool_oid,ref_count,active_points,running_count,waiting_count,iops_limits,io_priority}" _null_ pg_stat_get_resource_pool_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about resource pool data"); +DATA(insert OID = 5005 ( gs_wlm_switch_cgroup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "20 2275" _null_ _null_ _null_ _null_ gs_wlm_switch_cgroup _null_ _null_ _null_ "" f)); +DESCR("wlm attah the cgroup"); +DATA(insert OID = 5006 ( gs_wlm_rebuild_user_resource_pool PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "25" _null_ _null_ _null_ _null_ gs_wlm_rebuild_user_resource_pool _null_ _null_ _null_ "" f)); +DESCR("rebuild user and resource pool data"); +DATA(insert OID = 5007 ( gs_wlm_get_user_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,16,26,26,20,20,23,25}" "{o,o,o,o,o,o,o,o}" "{userid,sysadmin,rpoid,parentid,totalspace,spacelimit,childcount,childlist}" _null_ pg_stat_get_wlm_user_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about user data"); +DATA(insert OID = 5008 ( pg_stat_get_cgroup_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{25,23,23,20,20,25,25,25}" "{o,o,o,o,o,o,o,o}" "{cgroup_name,percent,usage_percent,shares,usage,cpuset,relpath,valid}" _null_ pg_stat_get_cgroup_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about cgroup"); +DATA(insert OID = 5009 ( gs_wlm_get_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{20,25,23,23,23,20,23,23}" "{o,o,o,o,o,o,o,o}" "{threadid,node_name,used_memory,peak_memory,spill_count,cpu_time,peak_iops,curr_iops}" _null_ pg_wlm_get_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session"); +DATA(insert OID = 5010 ( pg_stat_get_role_name PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ gs_get_role_name _null_ _null_ _null_ "" f)); +DESCR("statistics: get role name"); +DATA(insert OID = 5011 ( gs_wlm_readjust_user_space PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ gs_wlm_readjust_user_space _null_ _null_ _null_ "" f)); +DESCR("statistics: readjust user space"); +DATA(insert OID = 5012 ( gs_wlm_user_resource_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{26,23,23,23,23,20,20}" "{o,o,o,o,o,o,o}" "{userid,used_memory,total_memory,used_cpu,total_cpu,used_space,total_space}" _null_ pg_stat_get_wlm_user_resource_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get user resource info"); +DATA(insert OID = 5017 ( gs_wlm_node_recover PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "16" _null_ _null_ _null_ _null_ gs_wlm_node_recover _null_ _null_ _null_ "" f)); +DESCR("do recover of the node"); +DATA(insert OID = 5018 ( gs_wlm_get_workload_records PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{26,26,20,23,23,23,23,25,25,25}" "{o,o,o,o,o,o,o,o,o,o}" "{node_idx,query_pid,start_time,memory,actpts,maxpts,priority,resource_pool,node_name,queue_type}" _null_ pg_stat_get_workload_records _null_ _null_ _null_ "" f)); +DESCR("get dynamic workload records"); +DATA(insert OID = 5015 ( get_nodename PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 25 "" _null_ _null_ _null_ _null_ pg_get_nodename _null_ _null_ _null_ "" f)); +DESCR("statistics: current node name"); +DATA(insert OID = 5016 ( gs_wlm_node_clean PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "2275" _null_ _null_ _null_ _null_ gs_wlm_node_clean _null_ _null_ _null_ "" f)); +DESCR("wlm clean node info on central node"); +DATA(insert OID = 5013 ( pg_user_iostat PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{26,23,23,23,23,23,25}" "{o,o,o,o,o,o,o}" "{userid,min_curr_iops,max_curr_iops,min_peak_iops,max_peak_iops,io_limits,io_priority}" _null_ pg_stat_get_wlm_user_iostat_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get user iostat info"); +DATA(insert OID = 5014 ( pg_stat_get_wlm_session_iostat_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{20,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{threadid,maxcurr_iops,mincurr_iops,maxpeak_iops,minpeak_iops,iops_limits,io_priority}" _null_ pg_stat_get_wlm_session_iostat_info _null_ _null_ _null_ "" f)); +DESCR("statistics: get query iostat info"); +DATA(insert OID = 5019 ( pg_stat_get_wlm_node_resource_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{23,23,23,23,23,23,23}" "{o,o,o,o,o,o,o}" "{min_mem_util,max_mem_util,min_cpu_util,max_cpu_util,min_io_util,max_io_util,used_mem_rate}" _null_ pg_stat_get_wlm_node_resource_info _null_ _null_ _null_ "" f)); +DESCR("get resource usage info of nodes"); +DATA(insert OID = 5020 ( gs_wlm_get_user_session_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "2275" "{25,25,23,23,23,20,23,23}" "{o,o,o,o,o,o,o,o}" "{username,node_name,used_memory,peak_memory,spill_count,cpu_time,peak_iops,curr_iops}" _null_ pg_wlm_get_user_session_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about user"); +DATA(insert OID = 5021 ( gs_wlm_session_respool PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "20" "{26,20,23,26,25,19}" "{o,o,o,o,o,o}" "{datid,threadid,threadpid,usesysid,cgroup,session_respool}" _null_ pg_stat_get_session_respool _null_ _null_ _null_ "" f)); +DESCR("statistics: information about session_respool"); +DATA(insert OID = 5022 ( pg_stat_get_wlm_realtime_operator_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "23" "{20,20,23,25,1184,20,25,23,20,20,23,23,23,23,23,23,23,23,20,20,20,23,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{queryid,pid,plan_node_id,plan_node_name,start_time,duration,status,query_dop,estimated_rows,tuple_processed,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,warning}" _null_ pg_stat_get_wlm_realtime_operator_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about realtime wlm statistics of operator"); +DATA(insert OID = 5023 ( pg_stat_get_wlm_operator_info PGNSP PGUID 12 1 100 0 0 f f f f f t s 1 0 2249 "26" "{20,20,23,25,1184,20,23,20,20,23,23,23,23,23,23,23,23,20,20,20,23,25}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{queryid,pid,plan_node_id,plan_node_name,start_time,duration,query_dop,estimated_rows,tuple_processed,min_peak_memory,max_peak_memory,average_peak_memory,memory_skew_percent,min_spill_size,max_spill_size,average_spill_size,spill_skew_percent,min_cpu_time,max_cpu_time,total_cpu_time,cpu_skew_percent,warning}" _null_ pg_stat_get_wlm_operator_info _null_ _null_ _null_ "" f)); +DESCR("statistics: information about wlm statistics of operator"); +DATA(insert OID = 2769 ( pg_stat_get_bgwriter_timed_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_timed_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of timed checkpoints started by the bgwriter"); +DATA(insert OID = 2770 ( pg_stat_get_bgwriter_requested_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_requested_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backend requested checkpoints started by the bgwriter"); +DATA(insert OID = 2771 ( pg_stat_get_bgwriter_buf_written_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_checkpoints _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by the bgwriter during checkpoints"); +DATA(insert OID = 2772 ( pg_stat_get_bgwriter_buf_written_clean PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_clean _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by the bgwriter for cleaning dirty buffers"); +DATA(insert OID = 2773 ( pg_stat_get_bgwriter_maxwritten_clean PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_maxwritten_clean _null_ _null_ _null_ "" f)); +DESCR("statistics: number of times the bgwriter stopped processing when it had written too many buffers while cleaning"); +DATA(insert OID = 3075 ( pg_stat_get_bgwriter_stat_reset_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_stat_reset_time _null_ _null_ _null_ "" f)); +DESCR("statistics: last reset for the bgwriter"); +DATA(insert OID = 3160 ( pg_stat_get_checkpoint_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_write_time _null_ _null_ _null_ "" f)); +DESCR("statistics: checkpoint time spent writing buffers to disk, in msec"); +DATA(insert OID = 3161 ( pg_stat_get_checkpoint_sync_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_sync_time _null_ _null_ _null_ "" f)); +DESCR("statistics: checkpoint time spent synchronizing buffers to disk, in msec"); +DATA(insert OID = 2775 ( pg_stat_get_buf_written_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_written_backend _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffers written by backends"); +DATA(insert OID = 3063 ( pg_stat_get_buf_fsync_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_fsync_backend _null_ _null_ _null_ "" f)); +DESCR("statistics: number of backend buffer writes that did their own fsync"); +DATA(insert OID = 2859 ( pg_stat_get_buf_alloc PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_alloc _null_ _null_ _null_ "" f)); +DESCR("statistics: number of buffer allocations"); + +DATA(insert OID = 2978 ( pg_stat_get_function_calls PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_calls _null_ _null_ _null_ "" f)); +DESCR("statistics: number of function calls"); +DATA(insert OID = 2979 ( pg_stat_get_function_total_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_total_time _null_ _null_ _null_ "" f)); +DESCR("statistics: total execution time of function, in msec"); +DATA(insert OID = 2980 ( pg_stat_get_function_self_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_self_time _null_ _null_ _null_ "" f)); +DESCR("statistics: self execution time of function, in msec"); + +DATA(insert OID = 3037 ( pg_stat_get_xact_numscans PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_numscans _null_ _null_ _null_ "" f)); +DESCR("statistics: number of scans done for table/index in current transaction"); +DATA(insert OID = 3038 ( pg_stat_get_xact_tuples_returned PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_returned _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples read by seqscan in current transaction"); +DATA(insert OID = 3039 ( pg_stat_get_xact_tuples_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples fetched by idxscan in current transaction"); +DATA(insert OID = 3040 ( pg_stat_get_xact_tuples_inserted PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_inserted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples inserted in current transaction"); +DATA(insert OID = 3041 ( pg_stat_get_xact_tuples_updated PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples updated in current transaction"); +DATA(insert OID = 3042 ( pg_stat_get_xact_tuples_deleted PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_deleted _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples deleted in current transaction"); +DATA(insert OID = 3043 ( pg_stat_get_xact_tuples_hot_updated PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_hot_updated _null_ _null_ _null_ "" f)); +DESCR("statistics: number of tuples hot updated in current transaction"); +DATA(insert OID = 3044 ( pg_stat_get_xact_blocks_fetched PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_fetched _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks fetched in current transaction"); +DATA(insert OID = 3045 ( pg_stat_get_xact_blocks_hit PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of blocks found in cache in current transaction"); +DATA(insert OID = 3046 ( pg_stat_get_xact_function_calls PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_calls _null_ _null_ _null_ "" f)); +DESCR("statistics: number of function calls in current transaction"); +DATA(insert OID = 3047 ( pg_stat_get_xact_function_total_time PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_total_time _null_ _null_ _null_ "" f)); +DESCR("statistics: total execution time of function in current transaction, in msec"); +DATA(insert OID = 3048 ( pg_stat_get_xact_function_self_time PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_self_time _null_ _null_ _null_ "" f)); +DESCR("statistics: self execution time of function in current transaction, in msec"); + +DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_clear_snapshot _null_ _null_ _null_ "" f)); +DESCR("statistics: discard current transaction's statistics snapshot"); +DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_reset _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for current database"); +DATA(insert OID = 3775 ( pg_stat_reset_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "25" _null_ _null_ _null_ _null_ pg_stat_reset_shared _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics shared across the cluster"); +DATA(insert OID = 3776 ( pg_stat_reset_single_table_counters PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_table_counters _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for a single table or index in the current database"); +DATA(insert OID = 3777 ( pg_stat_reset_single_function_counters PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "26" _null_ _null_ _null_ _null_ pg_stat_reset_single_function_counters _null_ _null_ _null_ "" f)); +DESCR("statistics: reset collected statistics for a single function in the current database"); + +DATA(insert OID = 3480 ( pg_stat_get_cu_mem_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_mem_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu found in memory"); +DATA(insert OID = 3483 ( pg_stat_get_cu_hdd_sync PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_hdd_sync _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu synchronous read from hdd"); +DATA(insert OID = 3484 ( pg_stat_get_cu_hdd_asyn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_cu_hdd_asyn _null_ _null_ _null_ "" f)); +DESCR("statistics: number of cu asynchronous read from hdd"); +DATA(insert OID = 3485 ( pg_stat_get_db_cu_mem_hit PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_mem_hit _null_ _null_ _null_ "" f)); +DESCR("statistics: cu found in memory for database"); +DATA(insert OID = 3488 ( pg_stat_get_db_cu_hdd_sync PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_hdd_sync _null_ _null_ _null_ "" f)); +DESCR("statistics: cu synchronous read from hdd for database"); +DATA(insert OID = 3489 ( pg_stat_get_db_cu_hdd_asyn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_cu_hdd_asyn _null_ _null_ _null_ "" f)); +DESCR("statistics: cu asynchronous read from hdd for database"); + +/* add pgaudit functions */ +DATA(insert OID = 3780 ( pg_query_audit PGNSP PGUID 12 1 10 0 0 f f f f f t v 2 0 2249 "1184 1184" "{1184,1184,1184,25,25,25,25,25,25,25,25,25,25,25}" "{i,i,o,o,o,o,o,o,o,o,o,o,o,o}" "{begin,end,time,type,result,username,database,client_conninfo,object_name,detail_info,node_name,thread_id,local_port,remote_port}" _null_ pg_query_audit _null_ _null_ _null_ "" f)); +DESCR("audit: query audit information"); +DATA(insert OID = 3782 ( pg_query_audit PGNSP PGUID 12 1 10 0 0 f f f f f t v 3 0 2249 "1184 1184 25" "{1184,1184,25,1184,25,25,25,25,25,25,25,25,25,25,25}" "{i,i,i,o,o,o,o,o,o,o,o,o,o,o,o}" "{begin,end,directory,time,type,result,username,database,client_conninfo,object_name,detail_info,node_name,thread_id,local_port,remote_port}" _null_ pg_query_audit _null_ _null_ _null_ "" f)); +DESCR("audit: query audit information"); +DATA(insert OID = 3781 ( pg_delete_audit PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2278 "1184 1184" "{1184,1184}" "{i,i}" "{begin,end}" _null_ pg_delete_audit _null_ _null_ _null_ "" f)); +DESCR("audit: delete audit information"); + +DATA(insert OID = 3163 ( pg_trigger_depth PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 23 "" _null_ _null_ _null_ _null_ pg_trigger_depth _null_ _null_ _null_ "" f)); +DESCR("current trigger depth"); + +DATA(insert OID = 3778 ( pg_tablespace_location PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "26" _null_ _null_ _null_ _null_ pg_tablespace_location _null_ _null_ _null_ "" f)); +DESCR("tablespace location"); + +DATA(insert OID = 1946 ( encode PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "17 25" _null_ _null_ _null_ _null_ binary_encode _null_ _null_ _null_ "" f)); +DESCR("convert bytea value into some ascii-only text string"); +DATA(insert OID = 1947 ( decode PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "25 25" _null_ _null_ _null_ _null_ binary_decode _null_ _null_ _null_ "" f)); +DESCR("convert ascii-encoded text string into bytea value"); + +DATA(insert OID = 1948 ( byteaeq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteaeq _null_ _null_ _null_ "" f)); +DATA(insert OID = 1949 ( bytealt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1950 ( byteale PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteale _null_ _null_ _null_ "" f)); +DATA(insert OID = 1951 ( byteagt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteagt _null_ _null_ _null_ "" f)); +DATA(insert OID = 1952 ( byteage PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteage _null_ _null_ _null_ "" f)); +DATA(insert OID = 1953 ( byteane PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteane _null_ _null_ _null_ "" f)); +DATA(insert OID = 1954 ( byteacmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 17" _null_ _null_ _null_ _null_ byteacmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3452 ( bytea_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ bytea_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); + +DATA(insert OID = 3931 ( raweq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ raweq _null_ _null_ _null_"" f)); +DESCR("equal"); +DATA(insert OID = 3932 ( rawlt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawlt _null_ _null_ _null_ ""f)); +DESCR("less than"); +DATA(insert OID = 3935 ( rawle PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawle _null_ _null_ _null_ ""f)); +DESCR("less than or equal"); +DATA(insert OID = 3936 ( rawgt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawgt _null_ _null_ _null_ ""f)); +DESCR("greater than"); +DATA(insert OID = 3939 ( rawge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawge _null_ _null_ _null_ ""f)); +DESCR("greater than or equal"); +DATA(insert OID = 3940 ( rawne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawne _null_ _null_ _null_ ""f)); +DESCR("not equal"); +DATA(insert OID = 3475 ( rawcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 86" _null_ _null_ _null_ _null_ rawcmp _null_ _null_ _null_"" f)); +DESCR("less equal greater"); +DATA(insert OID = 3476 ( rawlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawlike _null_ _null_ _null_"" f)); +DESCR("matches like expression"); +DATA(insert OID = 3477 ( rawnlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "86 86" _null_ _null_ _null_ _null_ rawnlike _null_ _null_ _null_"" f)); +DESCR("does not match like expression"); +DATA(insert OID = 3478 ( rawcat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 86 "86 86" _null_ _null_ _null_ _null_ rawcat _null_ _null_ _null_"" f)); +DESCR("concatenate"); + +DATA(insert OID = 3917 ( timestamp_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ timestamp_transform _null_ _null_ _null_ "" f)); +DESCR("transform a timestamp length coercion"); +DATA(insert OID = 3944 ( time_transform PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ time_transform _null_ _null_ _null_ "" f)); +DESCR("transform a time length coercion"); + +DATA(insert OID = 1961 ( timestamp PGNSP PGUID 12 1 0 0 timestamp_transform f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ timestamp_scale _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp precision"); + +DATA(insert OID = 1965 ( oidlarger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 26 "26 26" _null_ _null_ _null_ _null_ oidlarger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 1966 ( oidsmaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 26 "26 26" _null_ _null_ _null_ _null_ oidsmaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); + +DATA(insert OID = 1967 ( timestamptz PGNSP PGUID 12 1 0 0 timestamp_transform f f f f t f i 2 0 1184 "1184 23" _null_ _null_ _null_ _null_ timestamptz_scale _null_ _null_ _null_ "" f)); +DESCR("adjust timestamptz precision"); +DATA(insert OID = 1968 ( time PGNSP PGUID 12 1 0 0 time_transform f f f f t f i 2 0 1083 "1083 23" _null_ _null_ _null_ _null_ time_scale _null_ _null_ _null_ "" f)); +DESCR("adjust time precision"); +DATA(insert OID = 1969 ( timetz PGNSP PGUID 12 1 0 0 time_transform f f f f t f i 2 0 1266 "1266 23" _null_ _null_ _null_ _null_ timetz_scale _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone precision"); + +DATA(insert OID = 2003 ( textanycat PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 25 "25 2776" _null_ _null_ _null_ _null_ "select $1 || $2::pg_catalog.text" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2004 ( anytextcat PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 25 "2776 25" _null_ _null_ _null_ _null_ "select $1::pg_catalog.text || $2" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2005 ( bytealike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealike _null_ _null_ _null_ "" f)); +DATA(insert OID = 2006 ( byteanlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteanlike _null_ _null_ _null_ "" f)); +DATA(insert OID = 2007 ( like PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ bytealike _null_ _null_ _null_ "" f)); +DESCR("matches LIKE expression"); +DATA(insert OID = 2008 ( notlike PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "17 17" _null_ _null_ _null_ _null_ byteanlike _null_ _null_ _null_ "" f)); +DESCR("does not match LIKE expression"); +DATA(insert OID = 2009 ( like_escape PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ like_escape_bytea _null_ _null_ _null_ "" f)); +DESCR("convert LIKE pattern to use backslash escapes"); +DATA(insert OID = 2010 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "17" _null_ _null_ _null_ _null_ byteaoctetlen _null_ _null_ _null_ "" f)); +DESCR("octet length"); +DATA(insert OID = 2011 ( byteacat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ byteacat _null_ _null_ _null_ "" f)); +DATA(insert OID = 2012 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ bytea_substr _null_ _null_ _null_ "" f)); +#define BYTEASUBSTRINGFUNCOID 2012 +DESCR("extract portion of string"); +DATA(insert OID = 2013 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 23" _null_ _null_ _null_ _null_ bytea_substr_no_len _null_ _null_ _null_ "" f)); +#define BYTEASUBSTRINGNOLENOID 2013 +DESCR("extract portion of string"); +DATA(insert OID = 2085 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 17 "17 23 23" _null_ _null_ _null_ _null_ bytea_substr_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define BYTEASUBSTRFUNCOID 2085 +DATA(insert OID = 2086 ( substr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 23" _null_ _null_ _null_ _null_ bytea_substr_no_len_orclcompat _null_ _null_ _null_ "" f)); +DESCR("extract portion of string"); +#define BYTEASUBSTRNOLENFUNCOID 2086 +DATA(insert OID = 2014 ( position PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 17" _null_ _null_ _null_ _null_ byteapos _null_ _null_ _null_ "" f)); +DESCR("position of substring"); +#define BYTEAPOSFUNCOID 2014 +DATA(insert OID = 2015 ( btrim PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 17 "17 17" _null_ _null_ _null_ _null_ byteatrim _null_ _null_ _null_ "" f)); +DESCR("trim both ends of string"); + +DATA(insert OID = 2019 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1083 "1184" _null_ _null_ _null_ _null_ timestamptz_time _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to time"); +#define TIMESTAMPTZ2TIMEFUNCOID 2019 +DATA(insert OID = 2020 ( date_trunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "25 1114" _null_ _null_ _null_ _null_ timestamp_trunc _null_ _null_ _null_ "" f)); +DESCR("truncate timestamp to specified units"); +#define TIMESTAMPTRUNCFUNCOID 2020 +DATA(insert OID = 2021 ( date_part PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 1114" _null_ _null_ _null_ _null_ timestamp_part _null_ _null_ _null_ "" f)); +DESCR("extract field from timestamp"); +#define TIMESTAMPPARTFUNCOID 2021 +DATA(insert OID = 2023 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "702" _null_ _null_ _null_ _null_ abstime_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert abstime to timestamp"); +#define ABSTIMETIMESTAMPFUNCOID 2023 +DATA(insert OID = 2024 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1082" _null_ _null_ _null_ _null_ date_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert date to timestamp"); +DATA(insert OID = 2025 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1083" _null_ _null_ _null_ _null_ datetime_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert date and time to timestamp"); +DATA(insert OID = 2027 ( timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "1184" _null_ _null_ _null_ _null_ timestamptz_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert timestamp with time zone to timestamp"); +#define TIMESTAMPTZ2TIMESTAMPFUNCOID 2027 +DATA(insert OID = 2028 ( timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1184 "1114" _null_ _null_ _null_ _null_ timestamp_timestamptz _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to timestamp with time zone"); +#define TIMESTAMP2TIMESTAMPTZFUNCOID 2028 +DATA(insert OID = 2029 ( date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1114" _null_ _null_ _null_ _null_ timestamp_date _null_ _null_ _null_ "" f)); +#define TIMESTAMP2DATEOID 2029 +DESCR("convert timestamp to date"); +DATA(insert OID = 2030 ( abstime PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 702 "1114" _null_ _null_ _null_ _null_ timestamp_abstime _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to abstime"); +#define TIMESTAMP2ABSTIMEFUNCOID 2030 +DATA(insert OID = 2031 ( timestamp_mi PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1114 1114" _null_ _null_ _null_ _null_ timestamp_mi _null_ _null_ _null_ "" f)); +DATA(insert OID = 2032 ( timestamp_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1186" _null_ _null_ _null_ _null_ timestamp_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2033 ( timestamp_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1186" _null_ _null_ _null_ _null_ timestamp_mi_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2035 ( timestamp_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1114" _null_ _null_ _null_ _null_ timestamp_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 2036 ( timestamp_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 1114" _null_ _null_ _null_ _null_ timestamp_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2037 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 1266 "25 1266" _null_ _null_ _null_ _null_ timetz_zone _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone to new zone"); +DATA(insert OID = 2038 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1266 "1186 1266" _null_ _null_ _null_ _null_ timetz_izone _null_ _null_ _null_ "" f)); +DESCR("adjust time with time zone to new zone"); +DATA(insert OID = 2039 ( timestamp_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1114" _null_ _null_ _null_ _null_ timestamp_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); +#define TIMESTAMPHASHOID 2039 +DATA(insert OID = 2041 ( overlaps PGNSP PGUID 12 1 0 0 0 f f f f f f i 4 0 16 "1114 1114 1114 1114" _null_ _null_ _null_ _null_ overlaps_timestamp _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2042 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1186 1114 1186" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2043 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1114 1114 1186" _null_ _null_ _null_ _null_ "select ($1, $2) overlaps ($3, ($3 + $4))" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2044 ( overlaps PGNSP PGUID 14 1 0 0 0 f f f f f f i 4 0 16 "1114 1186 1114 1114" _null_ _null_ _null_ _null_ "select ($1, ($1 + $2)) overlaps ($3, $4)" _null_ _null_ _null_ "" f)); +DESCR("intervals overlap?"); +DATA(insert OID = 2045 ( timestamp_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 1114" _null_ _null_ _null_ _null_ timestamp_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3137 ( timestamp_sortsupport PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ timestamp_sortsupport _null_ _null_ _null_ "" f)); +DESCR("sort support"); +DATA(insert OID = 2046 ( time PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1083 "1266" _null_ _null_ _null_ _null_ timetz_time _null_ _null_ _null_ "" f)); +DESCR("convert time with time zone to time"); +DATA(insert OID = 2047 ( timetz PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1266 "1083" _null_ _null_ _null_ _null_ time_timetz _null_ _null_ _null_ "" f)); +DESCR("convert time to time with time zone"); +#define TIME2TIMETZFUNCOID 2047 +DATA(insert OID = 2048 ( isfinite PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "1114" _null_ _null_ _null_ _null_ timestamp_finite _null_ _null_ _null_ "" f)); +DESCR("finite timestamp?"); +DATA(insert OID = 2049 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "1114 25" _null_ _null_ _null_ _null_ timestamp_to_char _null_ _null_ _null_ "" f)); +#define TIMESTAMP2CHARFUNCOID 2049 +DESCR("format timestamp to text"); +DATA(insert OID = 3808 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "1114" _null_ _null_ _null_ _null_ timestamp_to_char_default_format _null_ _null_ _null_ "" f)); +#define DEFAULTFORMATTIMESTAMP2CHARFUNCOID 3808 +DESCR("default format timestamp to text"); +DATA(insert OID = 3813 ( to_char PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "1184" _null_ _null_ _null_ _null_ timestamptz_to_char_default_format _null_ _null_ _null_ "" f)); +#define DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID 3813 +DESCR("default format timestamptz to text"); +DATA(insert OID = 2052 ( timestamp_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2053 ( timestamp_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2054 ( timestamp_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2055 ( timestamp_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2056 ( timestamp_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2057 ( timestamp_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "1114 1114" _null_ _null_ _null_ _null_ timestamp_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2058 ( age PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1114 1114" _null_ _null_ _null_ _null_ timestamp_age _null_ _null_ _null_ "" f)); +DESCR("date difference preserving months and years"); +DATA(insert OID = 2059 ( age PGNSP PGUID 14 1 0 0 0 f f f f t f s 1 0 1186 "1114" _null_ _null_ _null_ _null_ "select pg_catalog.age(cast(current_date as timestamp without time zone), $1)" _null_ _null_ _null_ "" f)); +DESCR("date difference from today preserving months and years"); + +DATA(insert OID = 2069 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "25 1114" _null_ _null_ _null_ _null_ timestamp_zone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); +DATA(insert OID = 2070 ( timezone PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1184 "1186 1114" _null_ _null_ _null_ _null_ timestamp_izone _null_ _null_ _null_ "" f)); +DESCR("adjust timestamp to new time zone"); +DATA(insert OID = 2071 ( date_pl_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1186" _null_ _null_ _null_ _null_ date_pl_interval _null_ _null_ _null_ "" f)); +DATA(insert OID = 2072 ( date_mi_interval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1082 1186" _null_ _null_ _null_ _null_ date_mi_interval _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2073 ( substring PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ textregexsubstr _null_ _null_ _null_ "" f)); +#define TEXTREGEXSUBSTRINGOID 2073 +DESCR("extract text matching regular expression"); +DATA(insert OID = 2074 ( substring PGNSP PGUID 14 1 0 0 0 f f f f t f i 3 0 25 "25 25 25" _null_ _null_ _null_ _null_ "select pg_catalog.substring($1, pg_catalog.similar_escape($2, $3))" _null_ _null_ _null_ "" f)); +#define SUBSTRINGESCAPEFUNCOID 2074 +DESCR("extract text matching SQL99 regular expression"); + +DATA(insert OID = 2075 ( bit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1560 "20 23" _null_ _null_ _null_ _null_ bitfromint8 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to bitstring"); +DATA(insert OID = 2076 ( int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1560" _null_ _null_ _null_ _null_ bittoint8 _null_ _null_ _null_ "" f)); +DESCR("convert bitstring to int8"); + +DATA(insert OID = 2077 ( current_setting PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "25" _null_ _null_ _null_ _null_ show_config_by_name _null_ _null_ _null_ "" f)); +DESCR("SHOW X as a function"); +DATA(insert OID = 2078 ( set_config PGNSP PGUID 12 1 0 0 0 f f f f f f v 3 0 25 "25 25 16" _null_ _null_ _null_ _null_ set_config_by_name _null_ _null_ _null_ "" f)); +DESCR("SET X as a function"); +DATA(insert OID = 2084 ( pg_show_all_settings PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,25,25,25,25,25,25,25,25,25,1009,25,25,25,23}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{name,setting,unit,category,short_desc,extra_desc,context,vartype,source,min_val,max_val,enumvals,boot_val,reset_val,sourcefile,sourceline}" _null_ show_all_settings _null_ _null_ _null_ "" f)); +DESCR("SHOW ALL as a function"); +DATA(insert OID = 1371 ( pg_lock_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,26,26,23,21,25,28,26,26,21,25,20,25,16,16}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{locktype,database,relation,page,tuple,virtualxid,transactionid,classid,objid,objsubid,virtualtransaction,pid,mode,granted,fastpath}" _null_ pg_lock_status _null_ _null_ _null_ "" f)); +DESCR("view system lock information"); +DATA(insert OID = 1065 ( pg_prepared_xact PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,25,1184,26,26}" "{o,o,o,o,o}" "{transaction,gid,prepared,ownerid,dbid}" _null_ pg_prepared_xact _null_ _null_ _null_ "" f)); +DESCR("view two-phase transactions"); +DATA(insert OID = 3212 ( pg_parse_clog PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,25}" "{o,o}" "{xid,status}" _null_ pg_parse_clog _null_ _null_ _null_ "" f)); +DESCR("view transaction clog"); +DATA(insert OID = 1998 ( pg_get_running_xacts PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{23,28,5545,25,28,16,20,28,20,28}" "{o,o,o,o,o,o,o,o,o,o}" "{handle,gxid,state,node,xmin,vacuum,timeline,prepare_xid,pid,next_xid}" _null_ pg_get_running_xacts _null_ _null_ _null_ "" f)); +DESCR("view running transactions"); +DATA(insert OID = 3199 ( get_prepared_pending_xid PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ get_prepared_pending_xid _null_ _null_ _null_ "" f)); +DESCR("nextxid when recovery done"); +DATA(insert OID = 1999 ( pg_check_xidlimit PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_check_xidlimit _null_ _null_ _null_ "" f)); +DESCR("is nextXid >= dWarnLimit?"); +DATA(insert OID = 1983 ( pg_log_comm_status PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_log_comm_status _null_ _null_ _null_ "" f)); +DESCR("log communication layer status"); +DATA(insert OID = 1984 ( pg_comm_recv_stream PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,25,20,23,23,23,25,23,23,23,23,23,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{node_name,local_tid,remote_name,remote_tid,idx,sid,tcp_sock,state,query_id,plan_id,pn_id,send_smp,recv_smp,recv_bytes,time,speed,quota,buff_usize}" _null_ pg_comm_recv_stream _null_ _null_ _null_ "" f)); +DESCR("communication recv stream status"); +DATA(insert OID = 1985 ( pg_comm_send_stream PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,25,20,23,23,23,25,23,23,23,23,23,20,20,20,20,20}" "{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{node_name,local_tid,remote_name,remote_tid,idx,sid,tcp_sock,state,query_id,plan_id,pn_id,send_smp,recv_smp,send_bytes,time,speed,quota,wait_quota}" _null_ pg_comm_send_stream _null_ _null_ _null_ "" f)); +DESCR("communication send stream status"); +DATA(insert OID = 1986 ( pg_comm_status PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,20,20,20,20,20,20,20}" "{o,o,o,o,o,o,o,o}" "{node_name,recv_speed,min_recv_idx,max_recv_idx,send_speed,min_send_idx,max_send_idx,mem_used}" _null_ pg_comm_status _null_ _null_ _null_ "" f)); +DESCR("communication net status"); +DATA(insert OID = 1987 ( pg_comm_delay PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{25,25,25,23,23,23,23}" "{o,o,o,o,o,o,o}" "{node_name,remote_name,remote_host,stream_num,min_delay,average,max_delay}" _null_ pg_comm_delay _null_ _null_ _null_ "" f)); +DESCR("sctp communication delay information"); +DATA(insert OID = 2000 ( pg_get_xidlimit PGNSP PGUID 12 1 1000 0 0 f f f f t t v 0 0 2249 "" "{28,28,28,28,28,28,26}" "{o,o,o,o,o,o,o}" "{nextXid,oldestXid,xidVacLimit,xidWarnLimit,xidStopLimit,xidWrapLimit,oldestXidDB}" _null_ pg_get_xidlimit _null_ _null_ _null_ "" f)); +DESCR("view TransactionId information"); +DATA(insert OID = 3537 ( pg_describe_object PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "26 26 23" _null_ _null_ _null_ _null_ pg_describe_object _null_ _null_ _null_ "" f)); +DESCR("get identification of SQL object"); +DATA(insert OID = 2079 ( pg_table_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_table_is_visible _null_ _null_ _null_ "" f)); +DESCR("is table visible in search path?"); +DATA(insert OID = 2080 ( pg_type_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_type_is_visible _null_ _null_ _null_ "" f)); +DESCR("is type visible in search path?"); +DATA(insert OID = 2081 ( pg_function_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_function_is_visible _null_ _null_ _null_ "" f)); +DESCR("is function visible in search path?"); +DATA(insert OID = 2082 ( pg_operator_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_operator_is_visible _null_ _null_ _null_ "" f)); +DESCR("is operator visible in search path?"); +DATA(insert OID = 2083 ( pg_opclass_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opclass_is_visible _null_ _null_ _null_ "" f)); +DESCR("is opclass visible in search path?"); +DATA(insert OID = 3829 ( pg_opfamily_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opfamily_is_visible _null_ _null_ _null_ "" f)); +DESCR("is opfamily visible in search path?"); +DATA(insert OID = 2093 ( pg_conversion_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_conversion_is_visible _null_ _null_ _null_ "" f)); +DESCR("is conversion visible in search path?"); +DATA(insert OID = 3756 ( pg_ts_parser_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_parser_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search parser visible in search path?"); +DATA(insert OID = 3757 ( pg_ts_dict_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_dict_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search dictionary visible in search path?"); +DATA(insert OID = 3768 ( pg_ts_template_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_template_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search template visible in search path?"); +DATA(insert OID = 3758 ( pg_ts_config_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_config_is_visible _null_ _null_ _null_ "" f)); +DESCR("is text search configuration visible in search path?"); +DATA(insert OID = 3815 ( pg_collation_is_visible PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_collation_is_visible _null_ _null_ _null_ "" f)); +DESCR("is collation visible in search path?"); + +DATA(insert OID = 2854 ( pg_my_temp_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 26 "" _null_ _null_ _null_ _null_ pg_my_temp_schema _null_ _null_ _null_ "" f)); +DESCR("get OID of current session's temp schema, if any"); +DATA(insert OID = 2855 ( pg_is_other_temp_schema PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_is_other_temp_schema _null_ _null_ _null_ "" f)); +DESCR("is schema another session's temp schema?"); + +DATA(insert OID = 2171 ( pg_cancel_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_cancel_backend _null_ _null_ _null_ "" f)); +DESCR("cancel a server process' current query"); +DATA(insert OID = 3213 ( pg_cancel_invalid_query PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_cancel_invalid_query _null_ _null_ _null_ "" f)); +DESCR("cancel queries on coordinator sessions connected to demoted GTM"); +DATA(insert OID = 2537 ( report_fatal PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ report_fatal _null_ _null_ _null_ "" f)); +DESCR("report a fatal error"); +DATA(insert OID = 2539 ( signal_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "20 23" _null_ _null_ _null_ _null_ signal_backend _null_ _null_ _null_ "" f)); +DESCR("signal a server thread"); +DATA(insert OID = 2096 ( pg_terminate_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_terminate_backend _null_ _null_ _null_ "" f)); +DESCR("terminate a server process"); +DATA(insert OID = 2172 ( pg_start_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 25 "25 16" _null_ _null_ _null_ _null_ pg_start_backup _null_ _null_ _null_ "" f)); +DESCR("prepare for taking an online backup"); +DATA(insert OID = 2173 ( pg_stop_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_stop_backup _null_ _null_ _null_ "" f)); +DESCR("finish taking an online backup"); +DATA(insert OID = 2848 ( pg_switch_xlog PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_switch_xlog _null_ _null_ _null_ "" f)); +DESCR("switch to new xlog file"); +DATA(insert OID = 3098 ( pg_create_restore_point PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_create_restore_point _null_ _null_ _null_ "" f)); +DESCR("create a named restore point"); +DATA(insert OID = 2849 ( pg_current_xlog_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_current_xlog_location _null_ _null_ _null_ "" f)); +DESCR("current xlog write location"); +DATA(insert OID = 2852 ( pg_current_xlog_insert_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_current_xlog_insert_location _null_ _null_ _null_ "" f)); +DESCR("current xlog insert location"); +DATA(insert OID = 2850 ( pg_xlogfile_name_offset PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2249 "25" "{25,25,23}" "{i,o,o}" "{wal_location,file_name,file_offset}" _null_ pg_xlogfile_name_offset _null_ _null_ _null_ "" f)); +DESCR("xlog filename and byte offset, given an xlog location"); +DATA(insert OID = 2851 ( pg_xlogfile_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ pg_xlogfile_name _null_ _null_ _null_ "" f)); +DESCR("xlog filename, given an xlog location"); + +DATA(insert OID = 3165 ( pg_xlog_location_diff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1700 "25 25" _null_ _null_ _null_ _null_ pg_xlog_location_diff _null_ _null_ _null_ "" f)); +DESCR("difference in bytes, given two xlog locations"); + +DATA(insert OID = 3809 ( pg_export_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_export_snapshot _null_ _null_ _null_ "" f)); +DESCR("export a snapshot"); + +DATA(insert OID = 3810 ( pg_is_in_recovery PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_in_recovery _null_ _null_ _null_ "" f)); +DESCR("true if server is in recovery"); + +DATA(insert OID = 3820 ( pg_last_xlog_receive_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_receive_location _null_ _null_ _null_ "" f)); +DESCR("current xlog flush location"); +DATA(insert OID = 3821 ( pg_last_xlog_replay_location PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 25 "" _null_ _null_ _null_ _null_ pg_last_xlog_replay_location _null_ _null_ _null_ "" f)); +DESCR("last xlog replay location"); +DATA(insert OID = 3830 ( pg_last_xact_replay_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 1184 "" _null_ _null_ _null_ _null_ pg_last_xact_replay_timestamp _null_ _null_ _null_ "" f)); +DESCR("timestamp of last replay xact"); + +DATA(insert OID = 3071 ( pg_xlog_replay_pause PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_xlog_replay_pause _null_ _null_ _null_ "" f)); +DESCR("pause xlog replay"); +DATA(insert OID = 3072 ( pg_xlog_replay_resume PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_xlog_replay_resume _null_ _null_ _null_ "" f)); +DESCR("resume xlog replay, if it was paused"); +DATA(insert OID = 3073 ( pg_is_xlog_replay_paused PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_is_xlog_replay_paused _null_ _null_ _null_ "" f)); +DESCR("true if xlog replay is paused"); + +DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_reload_conf _null_ _null_ _null_ "" f)); +DESCR("reload configuration files"); +DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pg_rotate_logfile _null_ _null_ _null_ "" f)); +DESCR("rotate log file"); + +DATA(insert OID = 2623 ( pg_stat_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2249 "25" "{25,20,1184,1184,1184,1184,16}" "{i,o,o,o,o,o,o}" "{filename,size,access,modification,change,creation,isdir}" _null_ pg_stat_file _null_ _null_ _null_ "" f)); +DESCR("get information about file"); +DATA(insert OID = 6321 ( pg_stat_file_recursive PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 2249 "25" "{25,25,25,20,16}" "{i,o,o,o,o}" "{location,path,filename,size,isdir}" _null_ pg_stat_file_recursive _null_ _null_ _null_ "" f)); +DESCR("get information about a few files"); +DATA(insert OID = 2624 ( pg_read_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 25 "25 20 20" _null_ _null_ _null_ _null_ pg_read_file _null_ _null_ _null_ "" f)); +DESCR("read text from a file"); +DATA(insert OID = 3826 ( pg_read_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_read_file_all _null_ _null_ _null_ "" f)); +DESCR("read text from a file"); +DATA(insert OID = 3827 ( pg_read_binary_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 17 "25 20 20 16" _null_ _null_ _null_ _null_ pg_read_binary_file _null_ _null_ _null_ "" f)); +DESCR("read bytea from a file"); +DATA(insert OID = 3828 ( pg_read_binary_file PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 17 "25" _null_ _null_ _null_ _null_ pg_read_binary_file_all _null_ _null_ _null_ "" f)); +DESCR("read bytea from a file"); +DATA(insert OID = 2625 ( pg_ls_dir PGNSP PGUID 12 1 1000 0 0 f f f f t t v 1 0 25 "25" _null_ _null_ _null_ _null_ pg_ls_dir _null_ _null_ _null_ "" f)); +DESCR("list all files in a directory"); +DATA(insert OID = 2626 ( pg_sleep PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "701" _null_ _null_ _null_ _null_ pg_sleep _null_ _null_ _null_ "" f)); +DESCR("sleep for the specified time in seconds"); +DATA(insert OID = 9999 ( pg_test_err_contain_err PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "23" _null_ _null_ _null_ _null_ pg_test_err_contain_err _null_ _null_ _null_ "" f)); +DESCR("test error contain error"); + +DATA(insert OID = 2971 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "16" _null_ _null_ _null_ _null_ booltext _null_ _null_ _null_ "" f)); +DESCR("convert boolean to text"); + +/* Aggregates (moved here from pg_aggregate for 7.3) */ + +DATA(insert OID = 2100 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all bigint values"); +DATA(insert OID = 2101 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all integer values"); +DATA(insert OID = 2102 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all smallint values"); +DATA(insert OID = 2103 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all numeric values"); +DATA(insert OID = 2104 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as float8 of all float4 values"); +DATA(insert OID = 2105 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as float8 of all float8 values"); +DATA(insert OID = 2106 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as interval of all interval values"); +DATA(insert OID = 5537 ( avg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("the average (arithmetic mean) as numeric of all tinyint values"); +DATA(insert OID = 2107 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as numeric across all bigint input values"); +DATA(insert OID = 2108 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as bigint across all integer input values"); +DATA(insert OID = 2109 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as bigint across all smallint input values"); +DATA(insert OID = 2110 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as float4 across all float4 input values"); +DATA(insert OID = 2111 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as float8 across all float8 input values"); +DATA(insert OID = 2112 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as money across all money input values"); +DATA(insert OID = 2113 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as interval across all interval input values"); +DATA(insert OID = 2114 ( sum PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum as numeric across all numeric input values"); + +DATA(insert OID = 2115 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all bigint input values"); +DATA(insert OID = 2116 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all integer input values"); +DATA(insert OID = 2117 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all smallint input values"); +DATA(insert OID = 2118 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 26 "26" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all oid input values"); +DATA(insert OID = 2119 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all float4 input values"); +DATA(insert OID = 2120 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all float8 input values"); +DATA(insert OID = 2121 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 702 "702" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all abstime input values"); +DATA(insert OID = 2122 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1082 "1082" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all date input values"); +DATA(insert OID = 2123 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1083 "1083" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all time input values"); +DATA(insert OID = 2124 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1266 "1266" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all time with time zone input values"); +DATA(insert OID = 2125 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all money input values"); +DATA(insert OID = 2126 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all timestamp input values"); +DATA(insert OID = 9010 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 9003 "9003" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all smalldatetime input values"); +DATA(insert OID = 9009 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 9003 "9003" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all smalldatetime input values"); +DATA(insert OID = 9011 ( smalldatetime_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 9003 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 9012 ( smalldatetime_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 9003 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 2127 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1184 "1184" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all timestamp with time zone input values"); +DATA(insert OID = 2128 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all interval input values"); +DATA(insert OID = 2129 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all text input values"); +DATA(insert OID = 2130 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all numeric input values"); +DATA(insert OID = 2050 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2277" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all anyarray input values"); +DATA(insert OID = 2244 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "1042" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all bpchar input values"); +DATA(insert OID = 2797 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all tid input values"); +DATA(insert OID = 5538 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all tinyint input values"); +DATA(insert OID = 2131 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all bigint input values"); +DATA(insert OID = 2132 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all integer input values"); +DATA(insert OID = 2133 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all smallint input values"); +DATA(insert OID = 2134 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 26 "26" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all oid input values"); +DATA(insert OID = 2135 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 700 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all float4 input values"); +DATA(insert OID = 2136 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all float8 input values"); +DATA(insert OID = 2137 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 702 "702" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all abstime input values"); +DATA(insert OID = 2138 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1082 "1082" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all date input values"); +DATA(insert OID = 2139 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1083 "1083" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all time input values"); +DATA(insert OID = 2140 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1266 "1266" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all time with time zone input values"); +DATA(insert OID = 2141 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 790 "790" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all money input values"); +DATA(insert OID = 2142 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all timestamp input values"); +DATA(insert OID = 2143 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1184 "1184" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all timestamp with time zone input values"); +DATA(insert OID = 2144 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1186 "1186" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all interval input values"); +DATA(insert OID = 2145 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 25 "25" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all text values"); +DATA(insert OID = 2146 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all numeric input values"); +DATA(insert OID = 2051 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 2277 "2277" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all anyarray input values"); +DATA(insert OID = 2245 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "1042" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all bpchar input values"); +DATA(insert OID = 2798 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all tid input values"); + +/* count has two forms: count(any) and count(*) */ +DATA(insert OID = 2147 ( count PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "2276" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows for which the input expression is not null"); +#define ANYCOUNTOID 2147 +DATA(insert OID = 2803 ( count PGNSP PGUID 12 1 0 0 0 t f f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows"); +#define COUNTOID 2803 + +DATA(insert OID = 2718 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of bigint input values (square of the population standard deviation)"); +DATA(insert OID = 2719 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of integer input values (square of the population standard deviation)"); +DATA(insert OID = 2720 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of smallint input values (square of the population standard deviation)"); +DATA(insert OID = 2721 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of float4 input values (square of the population standard deviation)"); +DATA(insert OID = 2722 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of float8 input values (square of the population standard deviation)"); +DATA(insert OID = 2723 ( var_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population variance of numeric input values (square of the population standard deviation)"); + +DATA(insert OID = 2641 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of bigint input values (square of the sample standard deviation)"); +DATA(insert OID = 2642 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of integer input values (square of the sample standard deviation)"); +DATA(insert OID = 2643 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of smallint input values (square of the sample standard deviation)"); +DATA(insert OID = 2644 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of float4 input values (square of the sample standard deviation)"); + +DATA(insert OID = 2645 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of float8 input values (square of the sample standard deviation)"); +DATA(insert OID = 2646 ( var_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample variance of numeric input values (square of the sample standard deviation)"); + +DATA(insert OID = 2148 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2149 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2150 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2151 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2152 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); +DATA(insert OID = 2153 ( variance PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for var_samp"); + +DATA(insert OID = 2724 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of bigint input values"); +DATA(insert OID = 2725 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of integer input values"); +DATA(insert OID = 2726 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of smallint input values"); +DATA(insert OID = 2727 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of float4 input values"); +DATA(insert OID = 2728 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of float8 input values"); +DATA(insert OID = 2729 ( stddev_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population standard deviation of numeric input values"); + +DATA(insert OID = 2712 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of bigint input values"); +DATA(insert OID = 2713 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of integer input values"); +DATA(insert OID = 2714 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of smallint input values"); +DATA(insert OID = 2715 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of float4 input values"); +DATA(insert OID = 2716 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of float8 input values"); +DATA(insert OID = 2717 ( stddev_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample standard deviation of numeric input values"); + +DATA(insert OID = 2154 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2155 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2156 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2157 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2158 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 701 "701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); +DATA(insert OID = 2159 ( stddev PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1700 "1700" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("historical alias for stddev_samp"); + +DATA(insert OID = 2818 ( regr_count PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 20 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("number of input rows in which both expressions are not null"); +DATA(insert OID = 2819 ( regr_sxx PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of squares of the independent variable (sum(X^2) - sum(X)^2/N)"); +DATA(insert OID = 2820 ( regr_syy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of squares of the dependent variable (sum(Y^2) - sum(Y)^2/N)"); +DATA(insert OID = 2821 ( regr_sxy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sum of products of independent times dependent variable (sum(X*Y) - sum(X) * sum(Y)/N)"); +DATA(insert OID = 2822 ( regr_avgx PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("average of the independent variable (sum(X)/N)"); +DATA(insert OID = 2823 ( regr_avgy PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("average of the dependent variable (sum(Y)/N)"); +DATA(insert OID = 2824 ( regr_r2 PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("square of the correlation coefficient"); +DATA(insert OID = 2825 ( regr_slope PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("slope of the least-squares-fit linear equation determined by the (X, Y) pairs"); +DATA(insert OID = 2826 ( regr_intercept PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs"); + +DATA(insert OID = 2827 ( covar_pop PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("population covariance"); +DATA(insert OID = 2828 ( covar_samp PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("sample covariance"); +DATA(insert OID = 2829 ( corr PGNSP PGUID 12 1 0 0 0 t f f f f f i 2 0 701 "701 701" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("correlation coefficient"); + +DATA(insert OID = 2160 ( text_pattern_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2161 ( text_pattern_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2163 ( text_pattern_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2164 ( text_pattern_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 25" _null_ _null_ _null_ _null_ text_pattern_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2166 ( bttext_pattern_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ bttext_pattern_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2174 ( bpchar_pattern_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2175 ( bpchar_pattern_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2177 ( bpchar_pattern_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2178 ( bpchar_pattern_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1042 1042" _null_ _null_ _null_ _null_ bpchar_pattern_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2180 ( btbpchar_pattern_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 1042" _null_ _null_ _null_ _null_ btbpchar_pattern_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2188 ( btint48cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 20" _null_ _null_ _null_ _null_ btint48cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2189 ( btint84cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ btint84cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2190 ( btint24cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ btint24cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2191 ( btint42cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 21" _null_ _null_ _null_ _null_ btint42cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2192 ( btint28cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 20" _null_ _null_ _null_ _null_ btint28cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2193 ( btint82cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 21" _null_ _null_ _null_ _null_ btint82cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2194 ( btfloat48cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 701" _null_ _null_ _null_ _null_ btfloat48cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2195 ( btfloat84cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 700" _null_ _null_ _null_ _null_ btfloat84cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2212 ( regprocedurein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2202 "2275" _null_ _null_ _null_ _null_ regprocedurein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2213 ( regprocedureout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2202" _null_ _null_ _null_ _null_ regprocedureout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2214 ( regoperin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2203 "2275" _null_ _null_ _null_ _null_ regoperin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2215 ( regoperout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2203" _null_ _null_ _null_ _null_ regoperout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2216 ( regoperatorin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2204 "2275" _null_ _null_ _null_ _null_ regoperatorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2217 ( regoperatorout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2204" _null_ _null_ _null_ _null_ regoperatorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2218 ( regclassin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "2275" _null_ _null_ _null_ _null_ regclassin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2219 ( regclassout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2205" _null_ _null_ _null_ _null_ regclassout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2220 ( regtypein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2206 "2275" _null_ _null_ _null_ _null_ regtypein _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2221 ( regtypeout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2206" _null_ _null_ _null_ _null_ regtypeout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ "" f)); +DESCR("convert text to regclass"); + +DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 2248 ( fmgr_sql_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_sql_validator _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 2250 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_database_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by username, database name"); +DATA(insert OID = 2251 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_database_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by username, database oid"); +DATA(insert OID = 2252 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_database_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by user oid, database name"); +DATA(insert OID = 2253 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_database_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on database by user oid, database oid"); +DATA(insert OID = 2254 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_database_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on database by database name"); +DATA(insert OID = 2255 ( has_database_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_database_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on database by database oid"); + +DATA(insert OID = 2256 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_function_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by username, function name"); +DATA(insert OID = 2257 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_function_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by username, function oid"); +DATA(insert OID = 2258 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_function_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by user oid, function name"); +DATA(insert OID = 2259 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_function_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on function by user oid, function oid"); +DATA(insert OID = 2260 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_function_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on function by function name"); +DATA(insert OID = 2261 ( has_function_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_function_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on function by function oid"); + +DATA(insert OID = 2262 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_language_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by username, language name"); +DATA(insert OID = 2263 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_language_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by username, language oid"); +DATA(insert OID = 2264 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_language_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by user oid, language name"); +DATA(insert OID = 2265 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_language_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on language by user oid, language oid"); +DATA(insert OID = 2266 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_language_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on language by language name"); +DATA(insert OID = 2267 ( has_language_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_language_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on language by language oid"); + +DATA(insert OID = 2268 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_schema_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by username, schema name"); +DATA(insert OID = 2269 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_schema_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by username, schema oid"); +DATA(insert OID = 2270 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_schema_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by user oid, schema name"); +DATA(insert OID = 2271 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_schema_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on schema by user oid, schema oid"); +DATA(insert OID = 2272 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_schema_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on schema by schema name"); +DATA(insert OID = 2273 ( has_schema_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_schema_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on schema by schema oid"); + +DATA(insert OID = 2390 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by username, tablespace name"); +DATA(insert OID = 2391 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by username, tablespace oid"); +DATA(insert OID = 2392 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by user oid, tablespace name"); +DATA(insert OID = 2393 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on tablespace by user oid, tablespace oid"); +DATA(insert OID = 2394 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on tablespace by tablespace name"); +DATA(insert OID = 2395 ( has_tablespace_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_tablespace_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on tablespace by tablespace oid"); + +DATA(insert OID = 3000 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by username, foreign data wrapper name"); +DATA(insert OID = 3001 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by username, foreign data wrapper oid"); +DATA(insert OID = 3002 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by user oid, foreign data wrapper name"); +DATA(insert OID = 3003 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on foreign data wrapper by user oid, foreign data wrapper oid"); +DATA(insert OID = 3004 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on foreign data wrapper by foreign data wrapper name"); +DATA(insert OID = 3005 ( has_foreign_data_wrapper_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_foreign_data_wrapper_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on foreign data wrapper by foreign data wrapper oid"); + +DATA(insert OID = 3006 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_server_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by username, server name"); +DATA(insert OID = 3007 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_server_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by username, server oid"); +DATA(insert OID = 3008 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_server_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by user oid, server name"); +DATA(insert OID = 3009 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_server_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on server by user oid, server oid"); +DATA(insert OID = 3010 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_server_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on server by server name"); +DATA(insert OID = 3011 ( has_server_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_server_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on server by server oid"); + +DATA(insert OID = 3138 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_type_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by username, type name"); +DATA(insert OID = 3139 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_type_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by username, type oid"); +DATA(insert OID = 3140 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_type_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by user oid, type name"); +DATA(insert OID = 3141 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_type_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on type by user oid, type oid"); +DATA(insert OID = 3142 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_type_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on type by type name"); +DATA(insert OID = 3143 ( has_type_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_type_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on type by type oid"); + +DATA(insert OID = 2705 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 19 25" _null_ _null_ _null_ _null_ pg_has_role_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by username, role name"); +DATA(insert OID = 2706 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ pg_has_role_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by username, role oid"); +DATA(insert OID = 2707 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 19 25" _null_ _null_ _null_ _null_ pg_has_role_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by user oid, role name"); +DATA(insert OID = 2708 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ pg_has_role_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on role by user oid, role oid"); +DATA(insert OID = 2709 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "19 25" _null_ _null_ _null_ _null_ pg_has_role_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on role by role name"); +DATA(insert OID = 2710 ( pg_has_role PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ pg_has_role_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on role by role oid"); + +DATA(insert OID = 1269 ( pg_column_size PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 23 "2276" _null_ _null_ _null_ _null_ pg_column_size _null_ _null_ _null_ "" f)); +DESCR("bytes required to store the value, perhaps with compression"); +#define PGCOLUMNSIZEFUNCOID 1269 +DATA(insert OID = 2322 ( pg_tablespace_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_tablespace_size_oid _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified tablespace"); +DATA(insert OID = 2323 ( pg_tablespace_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "19" _null_ _null_ _null_ _null_ pg_tablespace_size_name _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified tablespace"); +DATA(insert OID = 2324 ( pg_database_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_database_size_oid _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified database"); +DATA(insert OID = 4049 ( gs_switch_relfilenode PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 2205" _null_ _null_ _null_ _null_ pg_switch_relfilenode_name _null_ _null_ _null_ "" f)); +DESCR("exchange relfilenodes between relations or partitions"); +DATA(insert OID = 2168 ( pg_database_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "19" _null_ _null_ _null_ _null_ pg_database_size_name _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified database"); +DATA(insert OID = 2325 ( pg_relation_size PGNSP PGUID 14 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ "select pg_catalog.pg_relation_size($1, ''main'')" _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the main fork of the specified table or index"); +DATA(insert OID = 2332 ( pg_relation_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2205 25" _null_ _null_ _null_ _null_ pg_relation_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified fork of a table or index"); +DATA(insert OID = 2286 ( pg_total_relation_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_total_relation_size _null_ _null_ _null_ "" f)); +DESCR("total disk space usage for the specified table and associated indexes"); +DATA(insert OID = 2288 ( pg_size_pretty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "20" _null_ _null_ _null_ _null_ pg_size_pretty _null_ _null_ _null_ "" f)); +DESCR("convert a long int to a human readable text using size units"); +DATA(insert OID = 3166 ( pg_size_pretty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 25 "1700" _null_ _null_ _null_ _null_ pg_size_pretty_numeric _null_ _null_ _null_ "" f)); +DESCR("convert a numeric to a human readable text using size units"); +DATA(insert OID = 2997 ( pg_table_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_table_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified table, including TOAST, free space and visibility map"); +DATA(insert OID = 3193 ( pg_partition_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "25 25" _null_ _null_ _null_ _null_ pg_partition_size_name _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified partition, including TOAST, free space and visibility map"); +DATA(insert OID = 3194 ( pg_partition_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "26 26" _null_ _null_ _null_ _null_ pg_partition_size_oid _null_ _null_ _null_ "" f)); +DESCR("disk space usage for the specified partition, including TOAST, free space and visibility map"); +DATA(insert OID = 3195 ( pg_partition_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "25 25" _null_ _null_ _null_ _null_ pg_partition_indexes_size_name _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified partition"); +DATA(insert OID = 3196 ( pg_partition_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "26 26" _null_ _null_ _null_ _null_ pg_partition_indexes_size_oid _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified partition"); +DATA(insert OID = 2998 ( pg_indexes_size PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ pg_indexes_size _null_ _null_ _null_ "" f)); +DESCR("disk space usage for all indexes attached to the specified table"); +DATA(insert OID = 2999 ( pg_relation_filenode PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "2205" _null_ _null_ _null_ _null_ pg_relation_filenode _null_ _null_ _null_ "" f)); +DESCR("filenode identifier of relation"); +DATA(insert OID = 3197 ( pg_partition_filenode PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 26 "2205" _null_ _null_ _null_ _null_ pg_partition_filenode _null_ _null_ _null_ "" f)); +DESCR("filenode identifier of partition"); +DATA(insert OID = 3034 ( pg_relation_filepath PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "2205" _null_ _null_ _null_ _null_ pg_relation_filepath _null_ _null_ _null_ "" f)); +DESCR("file path of relation"); + +/* usable for column orientated table */ +DATA(insert OID = 3210 ( pg_relation_with_compression PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ pg_relation_with_compression _null_ _null_ _null_ "" f)); +DESCR("query the relation's compression attrubute"); +DATA(insert OID = 3211 ( pg_relation_compression_ratio PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "25" _null_ _null_ _null_ _null_ pg_relation_compression_ratio _null_ _null_ _null_ "" f)); +DESCR("query the relation data's compression ration"); + +DATA(insert OID = 2316 ( postgresql_fdw_validator PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1009 26" _null_ _null_ _null_ _null_ postgresql_fdw_validator _null_ _null_ _null_"" f)); +DESCR("(internal)"); + +DATA(insert OID = 2290 ( record_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2249 "2275 26 23" _null_ _null_ _null_ _null_ record_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2291 ( record_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2249" _null_ _null_ _null_ _null_ record_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2292 ( cstring_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2275" _null_ _null_ _null_ _null_ cstring_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2293 ( cstring_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2275" _null_ _null_ _null_ _null_ cstring_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2294 ( any_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2276 "2275" _null_ _null_ _null_ _null_ any_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2295 ( any_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2276" _null_ _null_ _null_ _null_ any_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2296 ( anyarray_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2277 "2275" _null_ _null_ _null_ _null_ anyarray_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +#define ANYARRAYINFUNCOID 2296 +DATA(insert OID = 2297 ( anyarray_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2277" _null_ _null_ _null_ _null_ anyarray_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2298 ( void_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2275" _null_ _null_ _null_ _null_ void_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2299 ( void_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2278" _null_ _null_ _null_ _null_ void_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2300 ( trigger_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2279 "2275" _null_ _null_ _null_ _null_ trigger_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2301 ( trigger_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2279" _null_ _null_ _null_ _null_ trigger_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2302 ( language_handler_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2280 "2275" _null_ _null_ _null_ _null_ language_handler_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2303 ( language_handler_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2280" _null_ _null_ _null_ _null_ language_handler_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2304 ( internal_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2281 "2275" _null_ _null_ _null_ _null_ internal_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2305 ( internal_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2281" _null_ _null_ _null_ _null_ internal_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2306 ( opaque_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2282 "2275" _null_ _null_ _null_ _null_ opaque_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2307 ( opaque_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2282" _null_ _null_ _null_ _null_ opaque_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2312 ( anyelement_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "2275" _null_ _null_ _null_ _null_ anyelement_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2313 ( anyelement_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2283" _null_ _null_ _null_ _null_ anyelement_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2398 ( shell_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 2282 "2275" _null_ _null_ _null_ _null_ shell_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2399 ( shell_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2282" _null_ _null_ _null_ _null_ shell_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2597 ( domain_in PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2276 "2275 26 23" _null_ _null_ _null_ _null_ domain_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2598 ( domain_recv PGNSP PGUID 12 1 0 0 0 f f f f f f s 3 0 2276 "2281 26 23" _null_ _null_ _null_ _null_ domain_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2777 ( anynonarray_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2776 "2275" _null_ _null_ _null_ _null_ anynonarray_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2778 ( anynonarray_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2776" _null_ _null_ _null_ _null_ anynonarray_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3116 ( fdw_handler_in PGNSP PGUID 12 1 0 0 0 f f f f f f i 1 0 3115 "2275" _null_ _null_ _null_ _null_ fdw_handler_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3117 ( fdw_handler_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3115" _null_ _null_ _null_ _null_ fdw_handler_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* cryptographic */ +DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ md5_text _null_ _null_ _null_ "" f)); +DESCR("MD5 hash"); +DATA(insert OID = 2321 ( md5 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "17" _null_ _null_ _null_ _null_ md5_bytea _null_ _null_ _null_ "" f)); +DESCR("MD5 hash"); + +/* crosstype operations for date vs. timestamp and timestamptz */ +DATA(insert OID = 2338 ( date_lt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_lt_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2339 ( date_le_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_le_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2340 ( date_eq_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_eq_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2341 ( date_gt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_gt_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2342 ( date_ge_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_ge_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2343 ( date_ne_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1082 1114" _null_ _null_ _null_ _null_ date_ne_timestamp _null_ _null_ _null_ "" f)); +DATA(insert OID = 2344 ( date_cmp_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 1114" _null_ _null_ _null_ _null_ date_cmp_timestamp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2351 ( date_lt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_lt_timestamptz _null_ _null_ _null_ "" f)); +#define DATELTTIMESTAMPTZFUNCOID 2351 +DATA(insert OID = 2352 ( date_le_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_le_timestamptz _null_ _null_ _null_ "" f)); +#define DATELETIMESTAMPTZFUNCOID 2352 +DATA(insert OID = 2353 ( date_eq_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_eq_timestamptz _null_ _null_ _null_ "" f)); +#define DATEEQTIMESTAMPTZFUNCOID 2353 +DATA(insert OID = 2354 ( date_gt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_gt_timestamptz _null_ _null_ _null_ "" f)); +#define DATEGTTIMESTAMPTZFUNCOID 2354 +DATA(insert OID = 2355 ( date_ge_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_ge_timestamptz _null_ _null_ _null_ "" f)); +#define DATEGETIMESTAMPTZFUNCOID 2355 +DATA(insert OID = 2356 ( date_ne_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1082 1184" _null_ _null_ _null_ _null_ date_ne_timestamptz _null_ _null_ _null_ "" f)); +#define DATENETIMESTAMPTZFUNCOID 2356 +DATA(insert OID = 2357 ( date_cmp_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1082 1184" _null_ _null_ _null_ _null_ date_cmp_timestamptz _null_ _null_ _null_ "" f)); +#define DATECMPTIMESTAMPTZFUNCOID 2357 +DESCR("less-equal-greater"); + +DATA(insert OID = 2364 ( timestamp_lt_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_lt_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2365 ( timestamp_le_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_le_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2366 ( timestamp_eq_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_eq_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2367 ( timestamp_gt_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_gt_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2368 ( timestamp_ge_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_ge_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2369 ( timestamp_ne_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "1114 1082" _null_ _null_ _null_ _null_ timestamp_ne_date _null_ _null_ _null_ "" f)); +DATA(insert OID = 2370 ( timestamp_cmp_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 1082" _null_ _null_ _null_ _null_ timestamp_cmp_date _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 2377 ( timestamptz_lt_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_lt_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLTDATEFUNCOID 2377 +DATA(insert OID = 2378 ( timestamptz_le_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_le_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLEDATEFUNCOID 2378 +DATA(insert OID = 2379 ( timestamptz_eq_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_eq_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZEQDATEFUNCOID 2379 +DATA(insert OID = 2380 ( timestamptz_gt_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_gt_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGTDATEFUNCOID 2380 +DATA(insert OID = 2381 ( timestamptz_ge_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_ge_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGEDATEFUNCOID 2381 +DATA(insert OID = 2382 ( timestamptz_ne_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_ne_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZNEDATEFUNCOID 2382 +DATA(insert OID = 2383 ( timestamptz_cmp_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1184 1082" _null_ _null_ _null_ _null_ timestamptz_cmp_date _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZCMPDATEFUNCOID 2383 + +DESCR("less-equal-greater"); + +/* crosstype operations for timestamp vs. timestamptz */ +DATA(insert OID = 2520 ( timestamp_lt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_lt_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPLTTIMESTAMPTZFUNCOID 2520 + +DATA(insert OID = 2521 ( timestamp_le_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_le_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPLETIMESTAMPTZFUNCOID 2521 +DATA(insert OID = 2522 ( timestamp_eq_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_eq_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPEQTIMESTAMPTZFUNCOID 2522 +DATA(insert OID = 2523 ( timestamp_gt_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_gt_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPGTTIMESTAMPTZFUNCOID 2523 +DATA(insert OID = 2524 ( timestamp_ge_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_ge_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPGETIMESTAMPTZFUNCOID 2524 +DATA(insert OID = 2525 ( timestamp_ne_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1114 1184" _null_ _null_ _null_ _null_ timestamp_ne_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPNETIMESTAMPTZFUNCOID 2525 +DATA(insert OID = 2526 ( timestamp_cmp_timestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1114 1184" _null_ _null_ _null_ _null_ timestamp_cmp_timestamptz _null_ _null_ _null_ "" f)); +#define TIMESTAMPCMPTIMESTAMPTZFUNCOID 2526 +DESCR("less-equal-greater"); + +DATA(insert OID = 2527 ( timestamptz_lt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_lt_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLTTIMESTAMPFUNCOID 2527 +DATA(insert OID = 2528 ( timestamptz_le_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_le_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZLETIMESTAMPFUNCOID 2528 +DATA(insert OID = 2529 ( timestamptz_eq_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_eq_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZEQTIMESTAMPFUNCOID 2529 +DATA(insert OID = 2530 ( timestamptz_gt_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_gt_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGTTIMESTAMPFUNCOID 2530 +DATA(insert OID = 2531 ( timestamptz_ge_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_ge_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZGETIMESTAMPFUNCOID 2531 +DATA(insert OID = 2532 ( timestamptz_ne_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_ne_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZNETIMESTAMPFUNCOID 2532 +DATA(insert OID = 2533 ( timestamptz_cmp_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 23 "1184 1114" _null_ _null_ _null_ _null_ timestamptz_cmp_timestamp _null_ _null_ _null_ "" f)); +#define TIMESTAMPTZCMPTIMESTAMPFUNCOID 2533 +DESCR("less-equal-greater"); + + +/* send/receive functions */ +DATA(insert OID = 2400 ( array_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2277 "2281 26 23" _null_ _null_ _null_ _null_ array_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2401 ( array_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2277" _null_ _null_ _null_ _null_ array_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2402 ( record_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 2249 "2281 26 23" _null_ _null_ _null_ _null_ record_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2403 ( record_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2249" _null_ _null_ _null_ _null_ record_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2404 ( int2recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "2281" _null_ _null_ _null_ _null_ int2recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2405 ( int2send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "21" _null_ _null_ _null_ _null_ int2send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5543 ( int1recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "2281" _null_ _null_ _null_ _null_ int1recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5544 ( int1send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "5545" _null_ _null_ _null_ _null_ int1send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 5521 ( int1_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "5545" _null_ _null_ _null_ _null_ int1_numeric _null_ _null_ _null_ "" f)); +DESCR("convert int1 to numeric"); +DATA(insert OID = 5522 ( numeric_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "1700" _null_ _null_ _null_ _null_ numeric_int1 _null_ _null_ _null_ "" f)); +DESCR("convert numeric to int1"); +DATA(insert OID = 5523 ( i1toi2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "5545" _null_ _null_ _null_ _null_ i1toi2 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int2"); +DATA(insert OID = 5524 ( i2toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "21" _null_ _null_ _null_ _null_ i2toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int2 to int1"); +DATA(insert OID = 5525 ( i1toi4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "5545" _null_ _null_ _null_ _null_ i1toi4 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int4"); +DATA(insert OID = 5526 ( i4toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "23" _null_ _null_ _null_ _null_ i4toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int4 to int1"); +DATA(insert OID = 5527 ( i1toi8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "5545" _null_ _null_ _null_ _null_ i1toi8 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to int8"); +DATA(insert OID = 5528 ( i8toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "20" _null_ _null_ _null_ _null_ i8toi1 _null_ _null_ _null_ "" f)); +DESCR("convert int8 to int1"); +DATA(insert OID = 5529 ( i1tof4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "5545" _null_ _null_ _null_ _null_ i1tof4 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to float4"); +DATA(insert OID = 5530 ( f4toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "700" _null_ _null_ _null_ _null_ f4toi1 _null_ _null_ _null_ "" f)); +DESCR("convert float4 to int1"); +DATA(insert OID = 5531 ( i1tof8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "5545" _null_ _null_ _null_ _null_ i1tof8 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to float8"); +DATA(insert OID = 5532 ( f8toi1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "701" _null_ _null_ _null_ _null_ f8toi1 _null_ _null_ _null_ "" f)); +DESCR("convert float8 to int1"); +DATA(insert OID = 5533 ( int1_bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "5545" _null_ _null_ _null_ _null_ int1_bool _null_ _null_ _null_ "" f)); +DESCR("convert int1 to bool"); +DATA(insert OID = 5534 ( bool_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "16" _null_ _null_ _null_ _null_ bool_int1 _null_ _null_ _null_ "" f)); +DESCR("convert bool to int1"); +DATA(insert OID = 3192 ( int4_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "23" _null_ _null_ _null_ _null_ int4_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to bpchar"); +DATA(insert OID = 2406 ( int4recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2281" _null_ _null_ _null_ _null_ int4recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2407 ( int4send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "23" _null_ _null_ _null_ _null_ int4send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2408 ( int8recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2281" _null_ _null_ _null_ _null_ int8recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2409 ( int8send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "20" _null_ _null_ _null_ _null_ int8send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2410 ( int2vectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 22 "2281" _null_ _null_ _null_ _null_ int2vectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2411 ( int2vectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "22" _null_ _null_ _null_ _null_ int2vectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2412 ( bytearecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2281" _null_ _null_ _null_ _null_ bytearecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2413 ( byteasend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "17" _null_ _null_ _null_ _null_ byteasend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 4033 ( rawrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 86 "2281" _null_ _null_ _null_ _null_ bytearecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4034 ( rawsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "86" _null_ _null_ _null_ _null_ byteasend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 4037 ( rawtohex PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "86" _null_ _null_ _null_ _null_ rawtotext _null_ _null_ _null_ "" f)); +DESCR("raw convert text"); +DATA(insert OID = 4038 ( hextoraw PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 86 "25" _null_ _null_ _null_ _null_ texttoraw _null_ _null_ _null_ "" f)); +DESCR("text convert to raw"); + +DATA(insert OID = 2414 ( textrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "2281" _null_ _null_ _null_ _null_ textrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2415 ( textsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "25" _null_ _null_ _null_ _null_ textsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2416 ( unknownrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 705 "2281" _null_ _null_ _null_ _null_ unknownrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2417 ( unknownsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "705" _null_ _null_ _null_ _null_ unknownsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2418 ( oidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2281" _null_ _null_ _null_ _null_ oidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2419 ( oidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "26" _null_ _null_ _null_ _null_ oidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2420 ( oidvectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 30 "2281" _null_ _null_ _null_ _null_ oidvectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2421 ( oidvectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "30" _null_ _null_ _null_ _null_ oidvectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2422 ( namerecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 19 "2281" _null_ _null_ _null_ _null_ namerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2423 ( namesend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "19" _null_ _null_ _null_ _null_ namesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2424 ( float4recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "2281" _null_ _null_ _null_ _null_ float4recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2425 ( float4send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "700" _null_ _null_ _null_ _null_ float4send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2426 ( float8recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "2281" _null_ _null_ _null_ _null_ float8recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2427 ( float8send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "701" _null_ _null_ _null_ _null_ float8send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2428 ( point_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 600 "2281" _null_ _null_ _null_ _null_ point_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2429 ( point_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "600" _null_ _null_ _null_ _null_ point_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2430 ( bpcharrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1042 "2281 26 23" _null_ _null_ _null_ _null_ bpcharrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2431 ( bpcharsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "1042" _null_ _null_ _null_ _null_ bpcharsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2432 ( varcharrecv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 1043 "2281 26 23" _null_ _null_ _null_ _null_ varcharrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2433 ( varcharsend PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "1043" _null_ _null_ _null_ _null_ varcharsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3966 ( nvarchar2recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3969 "2281 26 23" _null_ _null_ _null_ _null_ nvarchar2recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3967 ( nvarchar2send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3969" _null_ _null_ _null_ _null_ nvarchar2send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2434 ( charrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 18 "2281" _null_ _null_ _null_ _null_ charrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2435 ( charsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "18" _null_ _null_ _null_ _null_ charsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2436 ( boolrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "2281" _null_ _null_ _null_ _null_ boolrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2437 ( boolsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "16" _null_ _null_ _null_ _null_ boolsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2438 ( tidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 27 "2281" _null_ _null_ _null_ _null_ tidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2439 ( tidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "27" _null_ _null_ _null_ _null_ tidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2440 ( xidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 28 "2281" _null_ _null_ _null_ _null_ xidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2441 ( xidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "28" _null_ _null_ _null_ _null_ xidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2442 ( cidrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 29 "2281" _null_ _null_ _null_ _null_ cidrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2443 ( cidsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "29" _null_ _null_ _null_ _null_ cidsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2444 ( regprocrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 24 "2281" _null_ _null_ _null_ _null_ regprocrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2445 ( regprocsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "24" _null_ _null_ _null_ _null_ regprocsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2446 ( regprocedurerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2202 "2281" _null_ _null_ _null_ _null_ regprocedurerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2447 ( regproceduresend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2202" _null_ _null_ _null_ _null_ regproceduresend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2448 ( regoperrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2203 "2281" _null_ _null_ _null_ _null_ regoperrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2449 ( regopersend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2203" _null_ _null_ _null_ _null_ regopersend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2450 ( regoperatorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2204 "2281" _null_ _null_ _null_ _null_ regoperatorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2451 ( regoperatorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2204" _null_ _null_ _null_ _null_ regoperatorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2452 ( regclassrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2205 "2281" _null_ _null_ _null_ _null_ regclassrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2453 ( regclasssend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2205" _null_ _null_ _null_ _null_ regclasssend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2206 "2281" _null_ _null_ _null_ _null_ regtyperecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2458 ( varbit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1562 "2281 26 23" _null_ _null_ _null_ _null_ varbit_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2459 ( varbit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1562" _null_ _null_ _null_ _null_ varbit_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2460 ( numeric_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1700 "2281 26 23" _null_ _null_ _null_ _null_ numeric_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2461 ( numeric_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1700" _null_ _null_ _null_ _null_ numeric_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2462 ( abstimerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 702 "2281" _null_ _null_ _null_ _null_ abstimerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2463 ( abstimesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "702" _null_ _null_ _null_ _null_ abstimesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2464 ( reltimerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 703 "2281" _null_ _null_ _null_ _null_ reltimerecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2465 ( reltimesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "703" _null_ _null_ _null_ _null_ reltimesend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2466 ( tintervalrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 704 "2281" _null_ _null_ _null_ _null_ tintervalrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2467 ( tintervalsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "704" _null_ _null_ _null_ _null_ tintervalsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2468 ( date_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "2281" _null_ _null_ _null_ _null_ date_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2469 ( date_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1082" _null_ _null_ _null_ _null_ date_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2470 ( time_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1083 "2281 26 23" _null_ _null_ _null_ _null_ time_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2471 ( time_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1083" _null_ _null_ _null_ _null_ time_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2472 ( timetz_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1266 "2281 26 23" _null_ _null_ _null_ _null_ timetz_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2473 ( timetz_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1266" _null_ _null_ _null_ _null_ timetz_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2474 ( timestamp_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1114 "2281 26 23" _null_ _null_ _null_ _null_ timestamp_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2475 ( timestamp_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1114" _null_ _null_ _null_ _null_ timestamp_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2476 ( timestamptz_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1184 "2281 26 23" _null_ _null_ _null_ _null_ timestamptz_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2477 ( timestamptz_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1184" _null_ _null_ _null_ _null_ timestamptz_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2478 ( interval_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1186 "2281 26 23" _null_ _null_ _null_ _null_ interval_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2479 ( interval_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1186" _null_ _null_ _null_ _null_ interval_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2480 ( lseg_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 601 "2281" _null_ _null_ _null_ _null_ lseg_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2481 ( lseg_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "601" _null_ _null_ _null_ _null_ lseg_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2482 ( path_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 602 "2281" _null_ _null_ _null_ _null_ path_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2483 ( path_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "602" _null_ _null_ _null_ _null_ path_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2484 ( box_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 603 "2281" _null_ _null_ _null_ _null_ box_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2485 ( box_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "603" _null_ _null_ _null_ _null_ box_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2486 ( poly_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 604 "2281" _null_ _null_ _null_ _null_ poly_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2487 ( poly_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "604" _null_ _null_ _null_ _null_ poly_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2488 ( line_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 628 "2281" _null_ _null_ _null_ _null_ line_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2489 ( line_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "628" _null_ _null_ _null_ _null_ line_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2490 ( circle_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 718 "2281" _null_ _null_ _null_ _null_ circle_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2491 ( circle_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "718" _null_ _null_ _null_ _null_ circle_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2492 ( cash_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 790 "2281" _null_ _null_ _null_ _null_ cash_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2493 ( cash_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "790" _null_ _null_ _null_ _null_ cash_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2494 ( macaddr_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 829 "2281" _null_ _null_ _null_ _null_ macaddr_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2495 ( macaddr_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "829" _null_ _null_ _null_ _null_ macaddr_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2496 ( inet_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 869 "2281" _null_ _null_ _null_ _null_ inet_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2497 ( inet_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "869" _null_ _null_ _null_ _null_ inet_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2498 ( cidr_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 650 "2281" _null_ _null_ _null_ _null_ cidr_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2499 ( cidr_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "650" _null_ _null_ _null_ _null_ cidr_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2500 ( cstring_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "2281" _null_ _null_ _null_ _null_ cstring_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2501 ( cstring_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2275" _null_ _null_ _null_ _null_ cstring_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2502 ( anyarray_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2277 "2281" _null_ _null_ _null_ _null_ anyarray_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "2277" _null_ _null_ _null_ _null_ anyarray_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3120 ( void_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ void_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3121 ( void_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2278" _null_ _null_ _null_ _null_ void_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* System-view support functions with pretty-print option */ +DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_ruledef_ext _null_ _null_ _null_ "" f)); +DESCR("source text of a rule with pretty-print option"); +DATA(insert OID = 2505 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 16" _null_ _null_ _null_ _null_ pg_get_viewdef_name_ext _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-print option"); +DATA(insert OID = 2506 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_viewdef_ext _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-print option"); +DATA(insert OID = 3159 ( pg_get_viewdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 23" _null_ _null_ _null_ _null_ pg_get_viewdef_wrap _null_ _null_ _null_ "" f)); +DESCR("select statement of a view with pretty-printing and specified line wrapping"); +DATA(insert OID = 2507 ( pg_get_indexdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "26 23 16" _null_ _null_ _null_ _null_ pg_get_indexdef_ext _null_ _null_ _null_ "" f)); +DESCR("index description (full create statement or single expression) with pretty-print option"); +DATA(insert OID = 2508 ( pg_get_constraintdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_constraintdef_ext _null_ _null_ _null_ "" f)); +DESCR("constraint description with pretty-print option"); +DATA(insert OID = 2509 ( pg_get_expr PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "194 26 16" _null_ _null_ _null_ _null_ pg_get_expr_ext _null_ _null_ _null_ "" f)); +DESCR("deparse an encoded expression with pretty-print option"); +DATA(insert OID = 2510 ( pg_prepared_statement PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,1184,2211,16}" "{o,o,o,o,o}" "{name,statement,prepare_time,parameter_types,from_sql}" _null_ pg_prepared_statement _null_ _null_ _null_ "" f)); +DESCR("get the prepared statements for this session"); +DATA(insert OID = 2511 ( pg_cursor PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,16,16,16,1184}" "{o,o,o,o,o,o}" "{name,statement,is_holdable,is_binary,is_scrollable,creation_time}" _null_ pg_cursor _null_ _null_ _null_ "" f)); +DESCR("get the open cursors for this session"); +DATA(insert OID = 2599 ( pg_timezone_abbrevs PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,1186,16}" "{o,o,o}" "{abbrev,utc_offset,is_dst}" _null_ pg_timezone_abbrevs _null_ _null_ _null_ "" f)); +DESCR("get the available time zone abbreviations"); +DATA(insert OID = 2856 ( pg_timezone_names PGNSP PGUID 12 1 1000 0 0 f f f f t t s 0 0 2249 "" "{25,25,1186,16}" "{o,o,o,o}" "{name,abbrev,utc_offset,is_dst}" _null_ pg_timezone_names _null_ _null_ _null_ "" f)); +DESCR("get the available time zone names"); +DATA(insert OID = 2730 ( pg_get_triggerdef PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_triggerdef_ext _null_ _null_ _null_ "" f)); +DESCR("trigger description with pretty-print option"); +DATA(insert OID = 3035 ( pg_listening_channels PGNSP PGUID 12 1 10 0 0 f f f f t t s 0 0 25 "" _null_ _null_ _null_ _null_ pg_listening_channels _null_ _null_ _null_ "" f)); +DESCR("get the channels that the current backend listens to"); +DATA(insert OID = 3036 ( pg_notify PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2278 "25 25" _null_ _null_ _null_ _null_ pg_notify _null_ _null_ _null_ "" f)); +DESCR("send a notification event"); + +/* non-persistent series generator */ +DATA(insert OID = 1066 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 23 "23 23 23" _null_ _null_ _null_ _null_ generate_series_step_int4 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1067 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 23 "23 23" _null_ _null_ _null_ _null_ generate_series_int4 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1068 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 20 "20 20 20" _null_ _null_ _null_ _null_ generate_series_step_int8 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 1069 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 20 "20 20" _null_ _null_ _null_ _null_ generate_series_int8 _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 938 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t i 3 0 1114 "1114 1114 1186" _null_ _null_ _null_ _null_ generate_series_timestamp _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); +DATA(insert OID = 939 ( generate_series PGNSP PGUID 12 1 1000 0 0 f f f f t t s 3 0 1184 "1184 1184 1186" _null_ _null_ _null_ _null_ generate_series_timestamptz _null_ _null_ _null_ "" f)); +DESCR("non-persistent series generator"); + +/* boolean aggregates */ +DATA(insert OID = 2515 ( booland_statefunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ booland_statefunc _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2516 ( boolor_statefunc PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "16 16" _null_ _null_ _null_ _null_ boolor_statefunc _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2517 ( bool_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-and aggregate"); +/* ANY, SOME? These names conflict with subquery operators. See doc. */ +DATA(insert OID = 2518 ( bool_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-or aggregate"); +DATA(insert OID = 2519 ( every PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 16 "16" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("boolean-and aggregate"); +#define EVERYFUNCOID 2519 + +/* bitwise integer aggregates */ +DATA(insert OID = 5539 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and tinyint aggregate"); +DATA(insert OID = 5540 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 5545 "5545" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or tinyint aggregate"); +DATA(insert OID = 2236 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and smallint aggregate"); +DATA(insert OID = 2237 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 21 "21" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or smallint aggregate"); +DATA(insert OID = 2238 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and integer aggregate"); +DATA(insert OID = 2239 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 23 "23" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or integer aggregate"); +DATA(insert OID = 2240 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and bigint aggregate"); +DATA(insert OID = 2241 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or bigint aggregate"); +DATA(insert OID = 2242 ( bit_and PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-and bit aggregate"); +DATA(insert OID = 2243 ( bit_or PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1560 "1560" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("bitwise-or bit aggregate"); + +/* formerly-missing interval + datetime operators */ +DATA(insert OID = 2546 ( interval_pl_date PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1186 1082" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2547 ( interval_pl_timetz PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1266 "1186 1266" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2548 ( interval_pl_timestamp PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1114 "1186 1114" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +DATA(insert OID = 2549 ( interval_pl_timestamptz PGNSP PGUID 14 1 0 0 0 f f f f t f s 2 0 1184 "1186 1184" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); +#define INTERVALPLTIMESTAMPTZFUNCOID 2549 +DATA(insert OID = 2550 ( integer_pl_date PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 1082 "23 1082" _null_ _null_ _null_ _null_ "select $2 + $1" _null_ _null_ _null_ "" f)); + +DATA(insert OID = 2556 ( pg_tablespace_databases PGNSP PGUID 12 1 1000 0 0 f f f f t t s 1 0 26 "26" _null_ _null_ _null_ _null_ pg_tablespace_databases _null_ _null_ _null_ "" f)); +DESCR("get OIDs of databases in a tablespace"); + +DATA(insert OID = 2557 ( bool PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "23" _null_ _null_ _null_ _null_ int4_bool _null_ _null_ _null_ "" f)); +DESCR("convert int4 to boolean"); +DATA(insert OID = 2558 ( int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "16" _null_ _null_ _null_ _null_ bool_int4 _null_ _null_ _null_ "" f)); +DESCR("convert boolean to int4"); +DATA(insert OID = 2559 ( lastval PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 20 "" _null_ _null_ _null_ _null_ lastval _null_ _null_ _null_ "" f)); +DESCR("current value from last used sequence"); +#define LASTVALFUNCOID 2559 + +/* start time function */ +DATA(insert OID = 2560 ( pg_postmaster_start_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_postmaster_start_time _null_ _null_ _null_ "" f)); +DESCR("postmaster start time"); +/* config reload time function */ +DATA(insert OID = 2034 ( pg_conf_load_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_conf_load_time _null_ _null_ _null_ "" f)); +DESCR("configuration load time"); + +/* new functions for Y-direction rtree opclasses */ +DATA(insert OID = 2562 ( box_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 2563 ( box_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2564 ( box_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_overabove _null_ _null_ _null_ "" f)); +DATA(insert OID = 2565 ( box_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "603 603" _null_ _null_ _null_ _null_ box_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 2566 ( poly_below PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_below _null_ _null_ _null_ "" f)); +DATA(insert OID = 2567 ( poly_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2568 ( poly_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_overabove _null_ _null_ _null_ "" f)); +DATA(insert OID = 2569 ( poly_above PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "604 604" _null_ _null_ _null_ _null_ poly_above _null_ _null_ _null_ "" f)); +DATA(insert OID = 2587 ( circle_overbelow PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overbelow _null_ _null_ _null_ "" f)); +DATA(insert OID = 2588 ( circle_overabove PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "718 718" _null_ _null_ _null_ _null_ circle_overabove _null_ _null_ _null_ "" f)); + +/* support functions for GiST r-tree emulation */ +DATA(insert OID = 2578 ( gist_box_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 603 23 26 2281" _null_ _null_ _null_ _null_ gist_box_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2579 ( gist_box_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_box_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2580 ( gist_box_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_box_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2581 ( gist_box_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gist_box_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2582 ( gist_box_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gist_box_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2583 ( gist_box_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 603 "2281 2281" _null_ _null_ _null_ _null_ gist_box_union _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2584 ( gist_box_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "603 603 2281" _null_ _null_ _null_ _null_ gist_box_same _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2585 ( gist_poly_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 604 23 26 2281" _null_ _null_ _null_ _null_ gist_poly_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2586 ( gist_poly_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_poly_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2591 ( gist_circle_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 718 23 26 2281" _null_ _null_ _null_ _null_ gist_circle_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2592 ( gist_circle_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_circle_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 1030 ( gist_point_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gist_point_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 2179 ( gist_point_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 600 23 26 2281" _null_ _null_ _null_ _null_ gist_point_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3064 ( gist_point_distance PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 701 "2281 600 23 26" _null_ _null_ _null_ _null_ gist_point_distance _null_ _null_ _null_ "" f)); +DESCR("GiST support"); + +/* GIN */ +DATA(insert OID = 2731 ( gingetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ gingetbitmap _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2732 ( gininsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gininsert _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2733 ( ginbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ginbeginscan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2734 ( ginrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginrescan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2735 ( ginendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginendscan _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2736 ( ginmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginmarkpos _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2737 ( ginrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginrestrpos _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 3186 ( ginmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginmerge _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2738 ( ginbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ginbuild _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 325 ( ginbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ ginbuildempty _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2739 ( ginbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginbulkdelete _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2740 ( ginvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ ginvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2741 ( gincostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gincostestimate _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); +DATA(insert OID = 2788 ( ginoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ ginoptions _null_ _null_ _null_ "" f)); +DESCR("gin(internal)"); + +/* GIN array support */ +DATA(insert OID = 2743 ( ginarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2277 2281 2281" _null_ _null_ _null_ _null_ ginarrayextract _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 2774 ( ginqueryarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "2277 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginqueryarrayextract _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 2744 ( ginarrayconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 2277 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ ginarrayconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 3920 ( ginarraytriconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 16 "2281 21 2277 23 2281 2281 2281" _null_ _null_ _null_ _null_ ginarraytriconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN array support"); +DATA(insert OID = 3076 ( ginarrayextract PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2277 2281" _null_ _null_ _null_ _null_ ginarrayextract_2args _null_ _null_ _null_ "" f)); +DESCR("GIN array support (obsolete)"); + +/* overlap/contains/contained */ +DATA(insert OID = 2747 ( arrayoverlap PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arrayoverlap _null_ _null_ _null_ "" f)); +DATA(insert OID = 2748 ( arraycontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arraycontains _null_ _null_ _null_ "" f)); +DATA(insert OID = 2749 ( arraycontained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2277 2277" _null_ _null_ _null_ _null_ arraycontained _null_ _null_ _null_ "" f)); + +/* userlock replacements */ +DATA(insert OID = 2880 ( pg_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 3089 ( pg_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 2881 ( pg_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 3090 ( pg_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "20" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 2882 ( pg_try_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 3091 ( pg_try_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 2883 ( pg_try_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 3092 ( pg_try_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 2884 ( pg_advisory_unlock PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_advisory_unlock_int8 _null_ _null_ _null_ "" f)); +DESCR("release exclusive advisory lock"); +DATA(insert OID = 2885 ( pg_advisory_unlock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 16 "20" _null_ _null_ _null_ _null_ pg_advisory_unlock_shared_int8 _null_ _null_ _null_ "" f)); +DESCR("release shared advisory lock"); +DATA(insert OID = 2886 ( pg_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 3093 ( pg_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock"); +DATA(insert OID = 2887 ( pg_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 3094 ( pg_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "23 23" _null_ _null_ _null_ _null_ pg_advisory_xact_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock"); +DATA(insert OID = 2888 ( pg_try_advisory_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 3095 ( pg_try_advisory_xact_lock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain exclusive advisory lock if available"); +DATA(insert OID = 2889 ( pg_try_advisory_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 3096 ( pg_try_advisory_xact_lock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_try_advisory_xact_lock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("obtain shared advisory lock if available"); +DATA(insert OID = 2890 ( pg_advisory_unlock PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_advisory_unlock_int4 _null_ _null_ _null_ "" f)); +DESCR("release exclusive advisory lock"); +DATA(insert OID = 2891 ( pg_advisory_unlock_shared PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "23 23" _null_ _null_ _null_ _null_ pg_advisory_unlock_shared_int4 _null_ _null_ _null_ "" f)); +DESCR("release shared advisory lock"); +DATA(insert OID = 2892 ( pg_advisory_unlock_all PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_advisory_unlock_all _null_ _null_ _null_ "" f)); +DESCR("release all advisory locks"); + +/* XML support */ +DATA(insert OID = 2893 ( xml_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "2275" _null_ _null_ _null_ _null_ xml_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2894 ( xml_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "142" _null_ _null_ _null_ _null_ xml_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2895 ( xmlcomment PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 142 "25" _null_ _null_ _null_ _null_ xmlcomment _null_ _null_ _null_ "" f)); +DESCR("generate XML comment"); +DATA(insert OID = 2896 ( xml PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "25" _null_ _null_ _null_ _null_ texttoxml _null_ _null_ _null_ "" f)); +DESCR("perform a non-validating parse of a character string to produce an XML value"); +DATA(insert OID = 2897 ( xmlvalidate PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "142 25" _null_ _null_ _null_ _null_ xmlvalidate _null_ _null_ _null_ "" f)); +DESCR("validate an XML value"); +DATA(insert OID = 2898 ( xml_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 142 "2281" _null_ _null_ _null_ _null_ xml_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2899 ( xml_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "142" _null_ _null_ _null_ _null_ xml_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2900 ( xmlconcat2 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 142 "142 142" _null_ _null_ _null_ _null_ xmlconcat2 _null_ _null_ _null_ "" f)); +DESCR("aggregate transition function"); +DATA(insert OID = 2901 ( xmlagg PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 142 "142" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("concatenate XML values"); +#define XMLAGGFUNCOID 2901 +DATA(insert OID = 2922 ( text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "142" _null_ _null_ _null_ _null_ xmltotext _null_ _null_ _null_ "" f)); +DESCR("serialize an XML value to a character string"); + +DATA(insert OID = 2923 ( table_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xml _null_ _null_ _null_ "" f)); +DESCR("map table contents to XML"); +DATA(insert OID = 2924 ( query_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xml _null_ _null_ _null_ "" f)); +DESCR("map query result to XML"); +DATA(insert OID = 2925 ( cursor_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 5 0 142 "1790 23 16 16 25" _null_ _null_ "{cursor,count,nulls,tableforest,targetns}" _null_ cursor_to_xml _null_ _null_ _null_ "" f)); +DESCR("map rows from cursor to XML"); +DATA(insert OID = 2926 ( table_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map table structure to XML Schema"); +DATA(insert OID = 2927 ( query_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map query result structure to XML Schema"); +DATA(insert OID = 2928 ( cursor_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "1790 16 16 25" _null_ _null_ "{cursor,nulls,tableforest,targetns}" _null_ cursor_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map cursor structure to XML Schema"); +DATA(insert OID = 2929 ( table_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "2205 16 16 25" _null_ _null_ "{tbl,nulls,tableforest,targetns}" _null_ table_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map table contents and structure to XML and XML Schema"); +DATA(insert OID = 2930 ( query_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "25 16 16 25" _null_ _null_ "{query,nulls,tableforest,targetns}" _null_ query_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map query result and structure to XML and XML Schema"); + +DATA(insert OID = 2933 ( schema_to_xml PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xml _null_ _null_ _null_ "" f)); +DESCR("map schema contents to XML"); +DATA(insert OID = 2934 ( schema_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map schema structure to XML Schema"); +DATA(insert OID = 2935 ( schema_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f f f s 4 0 142 "19 16 16 25" _null_ _null_ "{schema,nulls,tableforest,targetns}" _null_ schema_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map schema contents and structure to XML and XML Schema"); + +DATA(insert OID = 2936 ( database_to_xml PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xml _null_ _null_ _null_ "" f)); +DESCR("map database contents to XML"); +DATA(insert OID = 2937 ( database_to_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map database structure to XML Schema"); +DATA(insert OID = 2938 ( database_to_xml_and_xmlschema PGNSP PGUID 12 100 0 0 0 f f f f t f s 3 0 142 "16 16 25" _null_ _null_ "{nulls,tableforest,targetns}" _null_ database_to_xml_and_xmlschema _null_ _null_ _null_ "" f)); +DESCR("map database contents and structure to XML and XML Schema"); + +DATA(insert OID = 2931 ( xpath PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 143 "25 142 1009" _null_ _null_ _null_ _null_ xpath _null_ _null_ _null_ "" f)); +DESCR("evaluate XPath expression, with namespaces support"); +DATA(insert OID = 2932 ( xpath PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 143 "25 142" _null_ _null_ _null_ _null_ "select pg_catalog.xpath($1, $2, ''{}''::pg_catalog.text[])" _null_ _null_ _null_ "" f)); +DESCR("evaluate XPath expression"); + +DATA(insert OID = 2614 ( xmlexists PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "25 142" _null_ _null_ _null_ _null_ xmlexists _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression"); + +DATA(insert OID = 3049 ( xpath_exists PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 16 "25 142 1009" _null_ _null_ _null_ _null_ xpath_exists _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression, with namespace support"); +DATA(insert OID = 3050 ( xpath_exists PGNSP PGUID 14 1 0 0 0 f f f f t f i 2 0 16 "25 142" _null_ _null_ _null_ _null_ "select pg_catalog.xpath_exists($1, $2, ''{}''::pg_catalog.text[])" _null_ _null_ _null_ "" f)); +DESCR("test XML value against XPath expression"); +DATA(insert OID = 3051 ( xml_is_well_formed PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML"); +DATA(insert OID = 3052 ( xml_is_well_formed_document PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed_document _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML document"); +DATA(insert OID = 3053 ( xml_is_well_formed_content PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "25" _null_ _null_ _null_ _null_ xml_is_well_formed_content _null_ _null_ _null_ "" f)); +DESCR("determine if a string is well formed XML content"); + +/* json */ +DATA(insert OID = 321 ( json_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2275" _null_ _null_ _null_ _null_ json_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 322 ( json_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "114" _null_ _null_ _null_ _null_ json_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 323 ( json_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2281" _null_ _null_ _null_ _null_ json_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 324 ( json_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "114" _null_ _null_ _null_ _null_ json_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3153 ( array_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2277" _null_ _null_ _null_ _null_ array_to_json _null_ _null_ _null_ "" f)); +DESCR("map array to json"); +DATA(insert OID = 3154 ( array_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "2277 16" _null_ _null_ _null_ _null_ array_to_json_pretty _null_ _null_ _null_ "" f)); +DESCR("map array to json with optional pretty printing"); +DATA(insert OID = 3155 ( row_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 114 "2249" _null_ _null_ _null_ _null_ row_to_json _null_ _null_ _null_ "" f)); +DESCR("map row to json"); +DATA(insert OID = 3156 ( row_to_json PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 114 "2249 16" _null_ _null_ _null_ _null_ row_to_json_pretty _null_ _null_ _null_ "" f)); +DESCR("map row to json with optional pretty printing"); + +/* uuid */ +DATA(insert OID = 2952 ( uuid_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2950 "2275" _null_ _null_ _null_ _null_ uuid_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2953 ( uuid_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2950" _null_ _null_ _null_ _null_ uuid_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2954 ( uuid_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2955 ( uuid_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2956 ( uuid_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2957 ( uuid_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2958 ( uuid_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2959 ( uuid_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "2950 2950" _null_ _null_ _null_ _null_ uuid_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2960 ( uuid_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2950 2950" _null_ _null_ _null_ _null_ uuid_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 2961 ( uuid_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2950 "2281" _null_ _null_ _null_ _null_ uuid_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2962 ( uuid_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2950" _null_ _null_ _null_ _null_ uuid_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2963 ( uuid_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "2950" _null_ _null_ _null_ _null_ uuid_hash _null_ _null_ _null_ "" f)); +DESCR("hash"); + +/* enum related procs */ +DATA(insert OID = 3504 ( anyenum_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3500 "2275" _null_ _null_ _null_ _null_ anyenum_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3505 ( anyenum_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3500" _null_ _null_ _null_ _null_ anyenum_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3506 ( enum_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 3500 "2275 26" _null_ _null_ _null_ _null_ enum_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3507 ( enum_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3500" _null_ _null_ _null_ _null_ enum_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3508 ( enum_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3509 ( enum_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3510 ( enum_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3511 ( enum_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3512 ( enum_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3513 ( enum_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3500 3500" _null_ _null_ _null_ _null_ enum_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3514 ( enum_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3500 3500" _null_ _null_ _null_ _null_ enum_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3515 ( hashenum PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3500" _null_ _null_ _null_ _null_ hashenum _null_ _null_ _null_ "" f)); +DESCR("hash"); +DATA(insert OID = 3524 ( enum_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3500 "3500 3500" _null_ _null_ _null_ _null_ enum_smaller _null_ _null_ _null_ "" f)); +DESCR("smaller of two"); +DATA(insert OID = 3525 ( enum_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3500 "3500 3500" _null_ _null_ _null_ _null_ enum_larger _null_ _null_ _null_ "" f)); +DESCR("larger of two"); +DATA(insert OID = 3526 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 3500 "3500" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("maximum value of all enum input values"); +DATA(insert OID = 3527 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 3500 "3500" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ "" f)); +DESCR("minimum value of all enum input values"); +DATA(insert OID = 3528 ( enum_first PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 3500 "3500" _null_ _null_ _null_ _null_ enum_first _null_ _null_ _null_ "" f)); +DESCR("first value of the input enum type"); +DATA(insert OID = 3529 ( enum_last PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 3500 "3500" _null_ _null_ _null_ _null_ enum_last _null_ _null_ _null_ "" f)); +DESCR("last value of the input enum type"); +DATA(insert OID = 3530 ( enum_range PGNSP PGUID 12 1 0 0 0 f f f f f f s 2 0 2277 "3500 3500" _null_ _null_ _null_ _null_ enum_range_bounds _null_ _null_ _null_ "" f)); +DESCR("range between the two given enum values, as an ordered array"); +DATA(insert OID = 3531 ( enum_range PGNSP PGUID 12 1 0 0 0 f f f f f f s 1 0 2277 "3500" _null_ _null_ _null_ _null_ enum_range_all _null_ _null_ _null_ "" f)); +DESCR("range of the given enum type, as an ordered array"); +DATA(insert OID = 3532 ( enum_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 3500 "2275 26" _null_ _null_ _null_ _null_ enum_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3533 ( enum_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3500" _null_ _null_ _null_ _null_ enum_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* text search stuff */ +DATA(insert OID = 3610 ( tsvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "2275" _null_ _null_ _null_ _null_ tsvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3639 ( tsvectorrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "2281" _null_ _null_ _null_ _null_ tsvectorrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3611 ( tsvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3614" _null_ _null_ _null_ _null_ tsvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3638 ( tsvectorsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3614" _null_ _null_ _null_ _null_ tsvectorsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3612 ( tsqueryin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "2275" _null_ _null_ _null_ _null_ tsqueryin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3641 ( tsqueryrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "2281" _null_ _null_ _null_ _null_ tsqueryrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3613 ( tsqueryout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3615" _null_ _null_ _null_ _null_ tsqueryout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3640 ( tsquerysend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3615" _null_ _null_ _null_ _null_ tsquerysend _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3646 ( gtsvectorin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3642 "2275" _null_ _null_ _null_ _null_ gtsvectorin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3647 ( gtsvectorout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "3642" _null_ _null_ _null_ _null_ gtsvectorout _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3616 ( tsvector_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3617 ( tsvector_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3618 ( tsvector_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3619 ( tsvector_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3620 ( tsvector_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3621 ( tsvector_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3614" _null_ _null_ _null_ _null_ tsvector_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3622 ( tsvector_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3614 3614" _null_ _null_ _null_ _null_ tsvector_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 3711 ( length PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3614" _null_ _null_ _null_ _null_ tsvector_length _null_ _null_ _null_ "" f)); +DESCR("number of lexemes"); +DATA(insert OID = 3623 ( strip PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "3614" _null_ _null_ _null_ _null_ tsvector_strip _null_ _null_ _null_ "" f)); +DESCR("strip position information"); +DATA(insert OID = 3624 ( setweight PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3614 18" _null_ _null_ _null_ _null_ tsvector_setweight _null_ _null_ _null_ "" f)); +DESCR("set weight of lexeme's entries"); +DATA(insert OID = 3625 ( tsvector_concat PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3614 3614" _null_ _null_ _null_ _null_ tsvector_concat _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3634 ( ts_match_vq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3614 3615" _null_ _null_ _null_ _null_ ts_match_vq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3635 ( ts_match_qv PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3614" _null_ _null_ _null_ _null_ ts_match_qv _null_ _null_ _null_ "" f)); +DATA(insert OID = 3760 ( ts_match_tt PGNSP PGUID 12 3 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ ts_match_tt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3761 ( ts_match_tq PGNSP PGUID 12 2 0 0 0 f f f f t f s 2 0 16 "25 3615" _null_ _null_ _null_ _null_ ts_match_tq _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3648 ( gtsvector_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsvector_compress _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3649 ( gtsvector_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsvector_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3650 ( gtsvector_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsvector_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3651 ( gtsvector_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsvector_union _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3652 ( gtsvector_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3642 3642 2281" _null_ _null_ _null_ _null_ gtsvector_same _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3653 ( gtsvector_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gtsvector_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); +DATA(insert OID = 3654 ( gtsvector_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 3642 23 26 2281" _null_ _null_ _null_ _null_ gtsvector_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST tsvector support"); + +DATA(insert OID = 3656 ( gin_extract_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3614 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsvector _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3657 ( gin_extract_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 2281 "3615 2281 21 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3658 ( gin_tsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 8 0 16 "2281 21 3615 23 2281 2281 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_consistent _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3921 ( gin_tsquery_triconsistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 7 0 16 "2281 21 3615 23 2281 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_triconsistent _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3724 ( gin_cmp_tslexeme PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ gin_cmp_tslexeme _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 2700 ( gin_cmp_prefix PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "25 25 21 2281" _null_ _null_ _null_ _null_ gin_cmp_prefix _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support"); +DATA(insert OID = 3077 ( gin_extract_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "3614 2281" _null_ _null_ _null_ _null_ gin_extract_tsvector_2args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); +DATA(insert OID = 3087 ( gin_extract_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 2281 "3615 2281 21 2281 2281" _null_ _null_ _null_ _null_ gin_extract_tsquery_5args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); +DATA(insert OID = 3088 ( gin_tsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 6 0 16 "2281 21 3615 23 2281 2281" _null_ _null_ _null_ _null_ gin_tsquery_consistent_6args _null_ _null_ _null_ "" f)); +DESCR("GIN tsvector support (obsolete)"); + +DATA(insert OID = 3989 ( gin_clean_pending_list PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "2205" _null_ _null_ _null_ _null_ gin_clean_pending_list _null_ _null_ _null_ "" f)); +DESCR("clean up GIN pending list"); + +DATA(insert OID = 3662 ( tsquery_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3663 ( tsquery_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3664 ( tsquery_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 3665 ( tsquery_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 3666 ( tsquery_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3667 ( tsquery_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsquery_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3668 ( tsquery_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3615 3615" _null_ _null_ _null_ _null_ tsquery_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +DATA(insert OID = 3669 ( tsquery_and PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3615 3615" _null_ _null_ _null_ _null_ tsquery_and _null_ _null_ _null_ "" f)); +DATA(insert OID = 3670 ( tsquery_or PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3615 3615" _null_ _null_ _null_ _null_ tsquery_or _null_ _null_ _null_ "" f)); +DATA(insert OID = 3671 ( tsquery_not PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "3615" _null_ _null_ _null_ _null_ tsquery_not _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3691 ( tsq_mcontains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsq_mcontains _null_ _null_ _null_ "" f)); +DATA(insert OID = 3692 ( tsq_mcontained PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3615 3615" _null_ _null_ _null_ _null_ tsq_mcontained _null_ _null_ _null_ "" f)); + +DATA(insert OID = 3672 ( numnode PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3615" _null_ _null_ _null_ _null_ tsquery_numnode _null_ _null_ _null_ "" f)); +DESCR("number of nodes"); +DATA(insert OID = 3673 ( querytree PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "3615" _null_ _null_ _null_ _null_ tsquerytree _null_ _null_ _null_ "" f)); +DESCR("show real useful query for GiST index"); + +DATA(insert OID = 3684 ( ts_rewrite PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 3615 "3615 3615 3615" _null_ _null_ _null_ _null_ tsquery_rewrite _null_ _null_ _null_ "" f)); +DESCR("rewrite tsquery"); +DATA(insert OID = 3685 ( ts_rewrite PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 3615 "3615 25" _null_ _null_ _null_ _null_ tsquery_rewrite_query _null_ _null_ _null_ "" f)); +DESCR("rewrite tsquery"); + +DATA(insert OID = 3695 ( gtsquery_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsquery_compress _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3696 ( gtsquery_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ gtsquery_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3697 ( gtsquery_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsquery_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3698 ( gtsquery_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ gtsquery_union _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3699 ( gtsquery_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "20 20 2281" _null_ _null_ _null_ _null_ gtsquery_same _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3700 ( gtsquery_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ gtsquery_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); +DATA(insert OID = 3701 ( gtsquery_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 2281 23 26 2281" _null_ _null_ _null_ _null_ gtsquery_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST tsquery support"); + +DATA(insert OID = 3686 ( tsmatchsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 4 0 701 "2281 26 2281 23" _null_ _null_ _null_ _null_ tsmatchsel _null_ _null_ _null_ "" f)); +DESCR("restriction selectivity of tsvector @@ tsquery"); +DATA(insert OID = 3687 ( tsmatchjoinsel PGNSP PGUID 12 1 0 0 0 f f f f t f s 5 0 701 "2281 26 2281 21 2281" _null_ _null_ _null_ _null_ tsmatchjoinsel _null_ _null_ _null_ "" f)); +DESCR("join selectivity of tsvector @@ tsquery"); +DATA(insert OID = 3688 ( ts_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ ts_typanalyze _null_ _null_ _null_ "" f)); +DESCR("tsvector typanalyze"); + +DATA(insert OID = 3689 ( ts_stat PGNSP PGUID 12 10 10000 0 0 f f f f t t v 1 0 2249 "25" "{25,25,23,23}" "{i,o,o,o}" "{query,word,ndoc,nentry}" _null_ ts_stat1 _null_ _null_ _null_ "" f)); +DESCR("statistics of tsvector column"); +DATA(insert OID = 3690 ( ts_stat PGNSP PGUID 12 10 10000 0 0 f f f f t t v 2 0 2249 "25 25" "{25,25,25,23,23}" "{i,i,o,o,o}" "{query,weights,word,ndoc,nentry}" _null_ ts_stat2 _null_ _null_ _null_ "" f)); +DESCR("statistics of tsvector column"); + +DATA(insert OID = 3703 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 700 "1021 3614 3615 23" _null_ _null_ _null_ _null_ ts_rank_wttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3704 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "1021 3614 3615" _null_ _null_ _null_ _null_ ts_rank_wtt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3705 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "3614 3615 23" _null_ _null_ _null_ _null_ ts_rank_ttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3706 ( ts_rank PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "3614 3615" _null_ _null_ _null_ _null_ ts_rank_tt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3707 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 700 "1021 3614 3615 23" _null_ _null_ _null_ _null_ ts_rankcd_wttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3708 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "1021 3614 3615" _null_ _null_ _null_ _null_ ts_rankcd_wtt _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3709 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 700 "3614 3615 23" _null_ _null_ _null_ _null_ ts_rankcd_ttf _null_ _null_ _null_ "" f)); +DESCR("relevance"); +DATA(insert OID = 3710 ( ts_rank_cd PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 700 "3614 3615" _null_ _null_ _null_ _null_ ts_rankcd_tt _null_ _null_ _null_ "" f)); +DESCR("relevance"); + +DATA(insert OID = 3713 ( ts_token_type PGNSP PGUID 12 1 16 0 0 f f f f t t i 1 0 2249 "26" "{26,23,25,25}" "{i,o,o,o}" "{parser_oid,tokid,alias,description}" _null_ ts_token_type_byid _null_ _null_ _null_ "" f)); +DESCR("get parser's token types"); +DATA(insert OID = 3714 ( ts_token_type PGNSP PGUID 12 1 16 0 0 f f f f t t s 1 0 2249 "25" "{25,23,25,25}" "{i,o,o,o}" "{parser_name,tokid,alias,description}" _null_ ts_token_type_byname _null_ _null_ _null_ "" f)); +DESCR("get parser's token types"); +DATA(insert OID = 3715 ( ts_parse PGNSP PGUID 12 1 1000 0 0 f f f f t t i 2 0 2249 "26 25" "{26,25,23,25}" "{i,i,o,o}" "{parser_oid,txt,tokid,token}" _null_ ts_parse_byid _null_ _null_ _null_ "" f)); +DESCR("parse text to tokens"); +DATA(insert OID = 3716 ( ts_parse PGNSP PGUID 12 1 1000 0 0 f f f f t t s 2 0 2249 "25 25" "{25,25,23,25}" "{i,i,o,o}" "{parser_name,txt,tokid,token}" _null_ ts_parse_byname _null_ _null_ _null_ "" f)); +DESCR("parse text to tokens"); + +DATA(insert OID = 3717 ( prsd_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ prsd_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3718 ( prsd_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ prsd_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3719 ( prsd_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ prsd_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3720 ( prsd_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 3615" _null_ _null_ _null_ _null_ prsd_headline _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3721 ( prsd_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ prsd_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3723 ( ts_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1009 "3769 25" _null_ _null_ _null_ _null_ ts_lexize _null_ _null_ _null_ "" f)); +DESCR("normalize one word by dictionary"); + +DATA(insert OID = 3725 ( dsimple_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dsimple_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3726 ( dsimple_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dsimple_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3728 ( dsynonym_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dsynonym_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3729 ( dsynonym_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dsynonym_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3731 ( dispell_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ dispell_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3732 ( dispell_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ dispell_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3740 ( thesaurus_init PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ thesaurus_init _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3741 ( thesaurus_lexize PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ thesaurus_lexize _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3743 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 25 "3734 25 3615 25" _null_ _null_ _null_ _null_ ts_headline_byid_opt _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3744 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 25 "3734 25 3615" _null_ _null_ _null_ _null_ ts_headline_byid _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3754 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 25 "25 3615 25" _null_ _null_ _null_ _null_ ts_headline_opt _null_ _null_ _null_ "" f)); +DESCR("generate headline"); +DATA(insert OID = 3755 ( ts_headline PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 25 "25 3615" _null_ _null_ _null_ _null_ ts_headline _null_ _null_ _null_ "" f)); +DESCR("generate headline"); + +DATA(insert OID = 3745 ( to_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3734 25" _null_ _null_ _null_ _null_ to_tsvector_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3746 ( to_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3734 25" _null_ _null_ _null_ _null_ to_tsquery_byid _null_ _null_ _null_ "" f)); +DESCR("make tsquery"); +DATA(insert OID = 3747 ( plainto_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3615 "3734 25" _null_ _null_ _null_ _null_ plainto_tsquery_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsquery"); +DATA(insert OID = 3749 ( to_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "25" _null_ _null_ _null_ _null_ to_tsvector _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3750 ( to_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3615 "25" _null_ _null_ _null_ _null_ to_tsquery _null_ _null_ _null_ "" f)); +DESCR("make tsquery"); +DATA(insert OID = 3751 ( plainto_tsquery PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3615 "25" _null_ _null_ _null_ _null_ plainto_tsquery _null_ _null_ _null_ "" f)); +DESCR("transform to tsquery"); + +DATA(insert OID = 3752 ( tsvector_update_trigger PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2279 "" _null_ _null_ _null_ _null_ tsvector_update_trigger_byid _null_ _null_ _null_ "" f)); +DESCR("trigger for automatic update of tsvector column"); +DATA(insert OID = 3753 ( tsvector_update_trigger_column PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2279 "" _null_ _null_ _null_ _null_ tsvector_update_trigger_bycolumn _null_ _null_ _null_ "" f)); +DESCR("trigger for automatic update of tsvector column"); + +DATA(insert OID = 3759 ( get_current_ts_config PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 3734 "" _null_ _null_ _null_ _null_ get_current_ts_config _null_ _null_ _null_ "" f)); +DESCR("get current tsearch configuration"); + +DATA(insert OID = 3736 ( regconfigin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3734 "2275" _null_ _null_ _null_ _null_ regconfigin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3737 ( regconfigout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3734" _null_ _null_ _null_ _null_ regconfigout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3738 ( regconfigrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3734 "2281" _null_ _null_ _null_ _null_ regconfigrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3739 ( regconfigsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3734" _null_ _null_ _null_ _null_ regconfigsend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +DATA(insert OID = 3771 ( regdictionaryin PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 3769 "2275" _null_ _null_ _null_ _null_ regdictionaryin _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3772 ( regdictionaryout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3769" _null_ _null_ _null_ _null_ regdictionaryout _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3773 ( regdictionaryrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3769 "2281" _null_ _null_ _null_ _null_ regdictionaryrecv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3774 ( regdictionarysend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "3769" _null_ _null_ _null_ _null_ regdictionarysend _null_ _null_ _null_ "" f)); +DESCR("I/O"); + +/* replication slots */ +DATA(insert OID = 3779 ( pg_create_physical_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2249 "19 16" "{19,16,25,25}" "{i,i,o,o}" "{slotname,dummy_standby,slotname,xlog_position}" _null_ pg_create_physical_replication_slot _null_ _null_ _null_ ""f)); +DESCR("create a physical replication slot"); +DATA(insert OID = 3783 ( pg_drop_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "19" _null_ _null_ _null_ _null_ pg_drop_replication_slot _null_ _null_ _null_ ""f)); +DESCR("drop a replication slot"); +DATA(insert OID = 3784 ( pg_get_replication_slots PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{25,25,26,16,28,25,16}" "{o,o,o,o,o,o,o}" "{slot_name,slot_type,datoid,active,xmin,restart_lsn,dummy_standby}" _null_ pg_get_replication_slots _null_ _null_ _null_ ""f)); +DESCR("information about replication slots currently in use"); + +/* Parser function for ngram */ +DATA(insert OID = 3786 ( ngram_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ ngram_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3787 ( ngram_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ ngram_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3788 ( ngram_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ ngram_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3789 ( ngram_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ ngram_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +DATA(insert OID = 3792 ( zhprs_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ zhprs_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3793 ( zhprs_getlexeme PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ zhprs_getlexeme _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3794 ( zhprs_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ zhprs_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3795 ( zhprs_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ zhprs_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + +/* Parser function for pound */ +DATA(insert OID = 3798 ( pound_start PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 23 26" _null_ _null_ _null_ _null_ pound_start _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3799 ( pound_nexttoken PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ pound_nexttoken _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3800 ( pound_end PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ pound_end _null_ _null_ _null_ "" f)); +DESCR("(internal)"); +DATA(insert OID = 3801 ( pound_lextype PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ pound_lextype _null_ _null_ _null_ "" f)); +DESCR("(internal)"); + + +/* txid */ +DATA(insert OID = 2939 ( txid_snapshot_in PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2970 "2275" _null_ _null_ _null_ _null_ txid_snapshot_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2940 ( txid_snapshot_out PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "2970" _null_ _null_ _null_ _null_ txid_snapshot_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2941 ( txid_snapshot_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2970 "2281" _null_ _null_ _null_ _null_ txid_snapshot_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2942 ( txid_snapshot_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2970" _null_ _null_ _null_ _null_ txid_snapshot_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 2943 ( txid_current PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ txid_current _null_ _null_ _null_ "" f)); +DESCR("get current transaction ID"); +DATA(insert OID = 2944 ( txid_current_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 2970 "" _null_ _null_ _null_ _null_ txid_current_snapshot _null_ _null_ _null_ "" f)); +DESCR("get current snapshot"); +DATA(insert OID = 2945 ( txid_snapshot_xmin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xmin _null_ _null_ _null_ "" f)); +DESCR("get xmin of snapshot"); +DATA(insert OID = 2946 ( txid_snapshot_xmax PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xmax _null_ _null_ _null_ "" f)); +DESCR("get xmax of snapshot"); +DATA(insert OID = 2947 ( txid_snapshot_xip PGNSP PGUID 12 1 50 0 0 f f f f t t i 1 0 20 "2970" _null_ _null_ _null_ _null_ txid_snapshot_xip _null_ _null_ _null_ "" f)); +DESCR("get set of in-progress txids in snapshot"); +DATA(insert OID = 2948 ( txid_visible_in_snapshot PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "20 2970" _null_ _null_ _null_ _null_ txid_visible_in_snapshot _null_ _null_ _null_ "" f)); +DESCR("is txid visible in snapshot?"); +DATA(insert OID = 2949 ( pgxc_snapshot_status PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 2249 "" "{28,28,23,28,28,23,23,23,23,20}" "{o,o,o,o,o,o,o,o,o,o}" "{xmin,xmax,xcnt,oldestxmin,next_xid,timeline,active_thread_num,max_active_thread_num,snapshot_num,snapshot_totalsize}" _null_ pgxc_snapshot_status _null_ _null_ _null_ "" f)); +DESCR("get gtm snapshot status information"); + +/* record comparison */ +DATA(insert OID = 2981 ( record_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_eq _null_ _null_ _null_ "" f)); +DATA(insert OID = 2982 ( record_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_ne _null_ _null_ _null_ "" f)); +DATA(insert OID = 2983 ( record_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2984 ( record_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 2985 ( record_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 2986 ( record_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2249 2249" _null_ _null_ _null_ _null_ record_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 2987 ( btrecordcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2249 2249" _null_ _null_ _null_ _null_ btrecordcmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); + +/* Extensions */ +DATA(insert OID = 3082 ( pg_available_extensions PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{19,25,25}" "{o,o,o}" "{name,default_version,comment}" _null_ pg_available_extensions _null_ _null_ _null_ "" f)); +DESCR("list available extensions"); +DATA(insert OID = 3083 ( pg_available_extension_versions PGNSP PGUID 12 10 100 0 0 f f f f t t s 0 0 2249 "" "{19,25,16,16,19,1003,25}" "{o,o,o,o,o,o,o}" "{name,version,superuser,relocatable,schema,requires,comment}" _null_ pg_available_extension_versions _null_ _null_ _null_ "" f)); +DESCR("list available extension versions"); +DATA(insert OID = 3084 ( pg_extension_update_paths PGNSP PGUID 12 10 100 0 0 f f f f t t s 1 0 2249 "19" "{19,25,25,25}" "{i,o,o,o}" "{name,source,target,path}" _null_ pg_extension_update_paths _null_ _null_ _null_ "" f)); +DESCR("list an extension's version update paths"); +DATA(insert OID = 3086 ( pg_extension_config_dump PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2278 "2205 25" _null_ _null_ _null_ _null_ pg_extension_config_dump _null_ _null_ _null_ "" f)); +DESCR("flag an extension's table contents to be emitted by gs_dump"); + +/* SQL-spec window functions */ +DATA(insert OID = 3100 ( row_number PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_row_number _null_ _null_ _null_ "" f)); +DESCR("row number within partition"); +#define ROWNUMBERFUNCOID 3100 +DATA(insert OID = 3101 ( rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_rank _null_ _null_ _null_ "" f)); +DESCR("integer rank with gaps"); +#define RANKFUNCOID 3101 +DATA(insert OID = 3102 ( dense_rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 20 "" _null_ _null_ _null_ _null_ window_dense_rank _null_ _null_ _null_ "" f)); +DESCR("integer rank without gaps"); +#define DENSERANKFUNCOID 3102 +DATA(insert OID = 3103 ( percent_rank PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 701 "" _null_ _null_ _null_ _null_ window_percent_rank _null_ _null_ _null_ "" f)); +DESCR("fractional rank within partition"); +DATA(insert OID = 3104 ( cume_dist PGNSP PGUID 12 1 0 0 0 f t f f f f i 0 0 701 "" _null_ _null_ _null_ _null_ window_cume_dist _null_ _null_ _null_ "" f)); +DESCR("fractional row number within partition"); +DATA(insert OID = 3105 ( ntile PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 23 "23" _null_ _null_ _null_ _null_ window_ntile _null_ _null_ _null_ "" f)); +DESCR("split rows into N groups"); +DATA(insert OID = 3106 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_lag _null_ _null_ _null_ "" f)); +DESCR("fetch the preceding row value"); +DATA(insert OID = 3107 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_lag_with_offset _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth preceding row value"); +DATA(insert OID = 3108 ( lag PGNSP PGUID 12 1 0 0 0 f t f f t f i 3 0 2283 "2283 23 2283" _null_ _null_ _null_ _null_ window_lag_with_offset_and_default _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth preceding row value with default"); +DATA(insert OID = 3109 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_lead _null_ _null_ _null_ "" f)); +DESCR("fetch the following row value"); +DATA(insert OID = 3110 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_lead_with_offset _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth following row value"); +DATA(insert OID = 3111 ( lead PGNSP PGUID 12 1 0 0 0 f t f f t f i 3 0 2283 "2283 23 2283" _null_ _null_ _null_ _null_ window_lead_with_offset_and_default _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth following row value with default"); +DATA(insert OID = 3112 ( first_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_first_value _null_ _null_ _null_ "" f)); +DESCR("fetch the first row value"); +DATA(insert OID = 3113 ( last_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 1 0 2283 "2283" _null_ _null_ _null_ _null_ window_last_value _null_ _null_ _null_ "" f)); +DESCR("fetch the last row value"); +DATA(insert OID = 3114 ( nth_value PGNSP PGUID 12 1 0 0 0 f t f f t f i 2 0 2283 "2283 23" _null_ _null_ _null_ _null_ window_nth_value _null_ _null_ _null_ "" f)); +DESCR("fetch the Nth row value"); +DATA(insert OID = 3167 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 25" _null_ _null_ _null_ _null_ textpos - _null_ _null_ "" f)); +DESCR("find position of substringi with two args"); +#define INSTR2FUNCOID 3167 +DATA(insert OID = 3168 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 23 "25 25 23" _null_ _null_ _null_ _null_ instr_3args - _null_ _null_"" f)); +DESCR("find position of substring with three args"); +#define INSTR3FUNCOID 3168 +DATA(insert OID = 3169 ( instr PGNSP PGUID 12 1 0 0 0 f f f f t f i 4 0 23 "25 25 23 23" _null_ _null_ _null_ _null_ instr_4args - _null_ _null_"" f)); +DESCR("find position of substring with four args"); +#define INSTR4FUNCOID 3169 +DATA(insert OID = 3170 ( multiply PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "25 701" _null_ _null_ _null_ _null_ text_multiply_float8 _null_ _null_ _null_"" f)); +DATA(insert OID = 3171 ( multiply PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "701 25" _null_ _null_ _null_ _null_ float8_multiply_text _null_ _null_ _null_"" f)); +DATA(insert OID = 3172 ( numtodsinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1186 "1700 25" _null_ _null_ _null_ _null_ numtodsinterval - _null_ _null_ "" f)); +DESCR("convert numeric to interval"); +DATA(insert OID = 3842 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "1700" _null_ _null_ _null_ _null_ numeric_interval - _null_ _null_ "" f)); +DESCR("convert numeric to interval"); +DATA(insert OID = 3189 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "5545" _null_ _null_ _null_ _null_ int1_interval - _null_ _null_ "" f)); +DESCR("convert int1 to interval"); +DATA(insert OID = 3190 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "21" _null_ _null_ _null_ _null_ int2_interval - _null_ _null_ "" f)); +DESCR("convert int2 to interval"); +DATA(insert OID = 3191 ( numtoday PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1186 "23" _null_ _null_ _null_ _null_ int4_interval - _null_ _null_ "" f)); +DESCR("convert int4 to interval"); +/* functions for range types */ +DATA(insert OID = 3832 ( anyrange_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2275 26 23" _null_ _null_ _null_ _null_ anyrange_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3833 ( anyrange_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3831" _null_ _null_ _null_ _null_ anyrange_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3834 ( range_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2275 26 23" _null_ _null_ _null_ _null_ range_in _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3835 ( range_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "3831" _null_ _null_ _null_ _null_ range_out _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3836 ( range_recv PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 3831 "2281 26 23" _null_ _null_ _null_ _null_ range_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3837 ( range_send PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 17 "3831" _null_ _null_ _null_ _null_ range_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3848 ( lower PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "3831" _null_ _null_ _null_ _null_ range_lower _null_ _null_ _null_ "" f)); +DESCR("lower bound of range"); +DATA(insert OID = 3849 ( upper PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2283 "3831" _null_ _null_ _null_ _null_ range_upper _null_ _null_ _null_ "" f)); +DESCR("upper bound of range"); +DATA(insert OID = 3850 ( isempty PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_empty _null_ _null_ _null_ "" f)); +DESCR("is the range empty?"); +DATA(insert OID = 3851 ( lower_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_lower_inc _null_ _null_ _null_ "" f)); +DESCR("is the range's lower bound inclusive?"); +DATA(insert OID = 3852 ( upper_inc PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_upper_inc _null_ _null_ _null_ "" f)); +DESCR("is the range's upper bound inclusive?"); +DATA(insert OID = 3853 ( lower_inf PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_lower_inf _null_ _null_ _null_ "" f)); +DESCR("is the range's lower bound infinite?"); +DATA(insert OID = 3854 ( upper_inf PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 16 "3831" _null_ _null_ _null_ _null_ range_upper_inf _null_ _null_ _null_ "" f)); +DESCR("is the range's upper bound infinite?"); +DATA(insert OID = 3855 ( range_eq PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_eq _null_ _null_ _null_ "" f)); +DESCR("implementation of = operator"); +DATA(insert OID = 3856 ( range_ne PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_ne _null_ _null_ _null_ "" f)); +DESCR("implementation of <> operator"); +DATA(insert OID = 3857 ( range_overlaps PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overlaps _null_ _null_ _null_ "" f)); +DESCR("implementation of && operator"); +DATA(insert OID = 3858 ( range_contains_elem PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 2283" _null_ _null_ _null_ _null_ range_contains_elem _null_ _null_ _null_ "" f)); +DESCR("implementation of @> operator"); +DATA(insert OID = 3859 ( range_contains PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_contains _null_ _null_ _null_ "" f)); +DESCR("implementation of @> operator"); +DATA(insert OID = 3860 ( elem_contained_by_range PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2283 3831" _null_ _null_ _null_ _null_ elem_contained_by_range _null_ _null_ _null_ "" f)); +DESCR("implementation of <@ operator"); +DATA(insert OID = 3861 ( range_contained_by PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_contained_by _null_ _null_ _null_ "" f)); +DESCR("implementation of <@ operator"); +DATA(insert OID = 3862 ( range_adjacent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_adjacent _null_ _null_ _null_ "" f)); +DESCR("implementation of -|- operator"); +DATA(insert OID = 3863 ( range_before PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_before _null_ _null_ _null_ "" f)); +DESCR("implementation of << operator"); +DATA(insert OID = 3864 ( range_after PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_after _null_ _null_ _null_ "" f)); +DESCR("implementation of >> operator"); +DATA(insert OID = 3865 ( range_overleft PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overleft _null_ _null_ _null_ "" f)); +DESCR("implementation of &< operator"); +DATA(insert OID = 3866 ( range_overright PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_overright _null_ _null_ _null_ "" f)); +DESCR("implementation of &> operator"); +DATA(insert OID = 3867 ( range_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_union _null_ _null_ _null_ "" f)); +DESCR("implementation of + operator"); +DATA(insert OID = 3868 ( range_intersect PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_intersect _null_ _null_ _null_ "" f)); +DESCR("implementation of * operator"); +DATA(insert OID = 3869 ( range_minus PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3831 "3831 3831" _null_ _null_ _null_ _null_ range_minus _null_ _null_ _null_ "" f)); +DESCR("implementation of - operator"); +DATA(insert OID = 3870 ( range_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3831 3831" _null_ _null_ _null_ _null_ range_cmp _null_ _null_ _null_ "" f)); +DESCR("less-equal-greater"); +DATA(insert OID = 3871 ( range_lt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_lt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3872 ( range_le PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_le _null_ _null_ _null_ "" f)); +DATA(insert OID = 3873 ( range_ge PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_ge _null_ _null_ _null_ "" f)); +DATA(insert OID = 3874 ( range_gt PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "3831 3831" _null_ _null_ _null_ _null_ range_gt _null_ _null_ _null_ "" f)); +DATA(insert OID = 3875 ( range_gist_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 5 0 16 "2281 3831 23 26 2281" _null_ _null_ _null_ _null_ range_gist_consistent _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3876 ( range_gist_union PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ range_gist_union _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3877 ( range_gist_compress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ range_gist_compress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3878 ( range_gist_decompress PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2281 "2281" _null_ _null_ _null_ _null_ range_gist_decompress _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3879 ( range_gist_penalty PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ range_gist_penalty _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3880 ( range_gist_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ range_gist_picksplit _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3881 ( range_gist_same PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 2281 "3831 3831 2281" _null_ _null_ _null_ _null_ range_gist_same _null_ _null_ _null_ "" f)); +DESCR("GiST support"); +DATA(insert OID = 3902 ( hash_range PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "3831" _null_ _null_ _null_ _null_ hash_range _null_ _null_ _null_ "" f)); +DESCR("hash a range"); +DATA(insert OID = 3916 ( range_typanalyze PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ range_typanalyze _null_ _null_ _null_ "" f)); +DESCR("range typanalyze"); + +DATA(insert OID = 3914 ( int4range_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3904 "3904" _null_ _null_ _null_ _null_ int4range_canonical _null_ _null_ _null_ "" f)); +DESCR("convert an int4 range to canonical form"); +DATA(insert OID = 3928 ( int8range_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3926 "3926" _null_ _null_ _null_ _null_ int8range_canonical _null_ _null_ _null_ "" f)); +DESCR("convert an int8 range to canonical form"); +DATA(insert OID = 3915 ( daterange_canonical PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3912 "3912" _null_ _null_ _null_ _null_ daterange_canonical _null_ _null_ _null_ "" f)); +DESCR("convert a date range to canonical form"); +DATA(insert OID = 3922 ( int4range_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "23 23" _null_ _null_ _null_ _null_ int4range_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two int4 values"); +DATA(insert OID = 3923 ( int8range_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "20 20" _null_ _null_ _null_ _null_ int8range_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two int8 values"); +DATA(insert OID = 3924 ( numrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1700 1700" _null_ _null_ _null_ _null_ numrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two numeric values"); +DATA(insert OID = 3925 ( daterange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1082 1082" _null_ _null_ _null_ _null_ daterange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two date values"); +DATA(insert OID = 3929 ( tsrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1114 1114" _null_ _null_ _null_ _null_ tsrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two timestamp values"); +DATA(insert OID = 3930 ( tstzrange_subdiff PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 701 "1184 1184" _null_ _null_ _null_ _null_ tstzrange_subdiff _null_ _null_ _null_ "" f)); +DESCR("float8 difference of two timestamp with time zone values"); + +DATA(insert OID = 3840 ( int4range PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3904 "23 23" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("int4range constructor"); +DATA(insert OID = 3841 ( int4range PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3904 "23 23 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("int4range constructor"); +DATA(insert OID = 3844 ( numrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3906 "1700 1700" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("numrange constructor"); +DATA(insert OID = 3845 ( numrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3906 "1700 1700 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("numrange constructor"); +DATA(insert OID = 3933 ( tsrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3908 "1114 1114" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("tsrange constructor"); +DATA(insert OID = 3934 ( tsrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3908 "1114 1114 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("tsrange constructor"); +DATA(insert OID = 3937 ( tstzrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3910 "1184 1184" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("tstzrange constructor"); +DATA(insert OID = 3938 ( tstzrange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3910 "1184 1184 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("tstzrange constructor"); +DATA(insert OID = 3941 ( daterange PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3912 "1082 1082" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("daterange constructor"); +DATA(insert OID = 3942 ( daterange PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3912 "1082 1082 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("daterange constructor"); +DATA(insert OID = 3945 ( int8range PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 3926 "20 20" _null_ _null_ _null_ _null_ range_constructor2 _null_ _null_ _null_ "" f)); +DESCR("int8range constructor"); +DATA(insert OID = 3946 ( int8range PGNSP PGUID 12 1 0 0 0 f f f f f f i 3 0 3926 "20 20 25" _null_ _null_ _null_ _null_ range_constructor3 _null_ _null_ _null_ "" f)); +DESCR("int8range constructor"); + +/* spgist support functions */ +DATA(insert OID = 4001 ( spggettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spggettuple _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4002 ( spggetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ spggetbitmap _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4003 ( spginsert PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 16 "2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spginsert _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4004 ( spgbeginscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ spgbeginscan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4005 ( spgrescan PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2278 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgrescan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4006 ( spgendscan PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgendscan _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4007 ( spgmarkpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgmarkpos _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4008 ( spgrestrpos PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgrestrpos _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 3188 ( spgmerge PGNSP PGUID 12 1 0 0 0 f f f f t f v 5 0 2281 "2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgmerge _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4009 ( spgbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ spgbuild _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4010 ( spgbuildempty PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "2281" _null_ _null_ _null_ _null_ spgbuildempty _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4011 ( spgbulkdelete PGNSP PGUID 12 1 0 0 0 f f f f t f v 4 0 2281 "2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgbulkdelete _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4012 ( spgvacuumcleanup PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 2281 "2281 2281" _null_ _null_ _null_ _null_ spgvacuumcleanup _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4032 ( spgcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ spgcanreturn _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4013 ( spgcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ spgcostestimate _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); +DATA(insert OID = 4014 ( spgoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ spgoptions _null_ _null_ _null_ "" f)); +DESCR("spgist(internal)"); + +/* spgist opclasses */ +DATA(insert OID = 4018 ( spg_quad_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4019 ( spg_quad_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4020 ( spg_quad_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4021 ( spg_quad_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree over point"); +DATA(insert OID = 4022 ( spg_quad_leaf_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spg_quad_leaf_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for quad tree and k-d tree over point"); + +DATA(insert OID = 4023 ( spg_kd_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4024 ( spg_kd_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4025 ( spg_kd_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); +DATA(insert OID = 4026 ( spg_kd_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_kd_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for k-d tree over point"); + +DATA(insert OID = 4027 ( spg_text_config PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_config _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4028 ( spg_text_choose PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_choose _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4029 ( spg_text_picksplit PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_picksplit _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4030 ( spg_text_inner_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 2278 "2281 2281" _null_ _null_ _null_ _null_ spg_text_inner_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); +DATA(insert OID = 4031 ( spg_text_leaf_consistent PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ spg_text_leaf_consistent _null_ _null_ _null_ "" f)); +DESCR("SP-GiST support for suffix tree over text"); + +DATA(insert OID = 5580 ( smalldatetime_eq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_eq _null_ _null_ _null_ "" f)); +DESCR("equal"); +DATA(insert OID = 5581 ( smalldatetime_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_ne _null_ _null_ _null_ "" f)); +DESCR("not equal"); +DATA(insert OID = 5582 ( smalldatetime_lt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_lt _null_ _null_ _null_ "" f)); +DESCR("less than"); +DATA(insert OID = 5583 ( smalldatetime_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_le _null_ _null_ _null_ "" f)); +DESCR("less than or equal"); +DATA(insert OID = 5584 ( smalldatetime_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_ge _null_ _null_ _null_ "" f)); +DESCR("greater than or equal"); +DATA(insert OID = 5585 ( smalldatetime_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_gt _null_ _null_ _null_ "" f)); +DESCR("greater than"); +DATA(insert OID = 5586 ( smalldatetime_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 9003" _null_ _null_ _null_ _null_ smalldatetime_cmp _null_ _null_ _null_ "" f)); +DESCR("smalldatetime compare"); +DATA(insert OID = 5587 ( smalldatetime_hash PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "9003" _null_ _null_ _null_ _null_ smalldatetime_hash _null_ _null_ _null_ "" f)); +DESCR("smalldatetime difference preserving months and years"); +DATA(insert OID = 9004 ( smalldatetime_in PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 9003 "2275 26 23" _null_ _null_ _null_ _null_ smalldatetime_in _null_ _null_ _null_ "" f)); +#define SMALLDATETIMEINFUNCOID 9004 +DESCR("I/O"); +DATA(insert OID = 9006 ( smalldatetime_out PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "9003" _null_ _null_ _null_ _null_ smalldatetime_out _null_ _null_ _null_ "" f)); +#define SMALLDATETIMEOUTFUNCOID 9006 +DESCR("I/O"); +DATA(insert OID = 9007 ( smalldatetime_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 9003 "2281 26 23" _null_ _null_ _null_ _null_ smalldatetime_recv _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 9008 ( smalldatetime_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "9003" _null_ _null_ _null_ _null_ smalldatetime_send _null_ _null_ _null_ "" f)); +DESCR("I/O"); +DATA(insert OID = 3198 ( convert_to_nocase PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "25 19" _null_ _null_ _null_ _null_ pg_convert_to_nocase _null_ _null_ _null_ "" f)); +DESCR("convert string with specified destination encoding name"); +DATA(insert OID = 5560 ( to_date PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 1114 "25" _null_ _null_ _null_ _null_ to_date_default_format _null_ _null_ _null_ "" f)); +#define TODATEDEFAULTFUNCOID 5560 +DESCR("to_date_default_format"); + +#ifdef PGXC +DATA(insert OID = 3200 ( pgxc_pool_check PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_check _null_ _null_ _null_ "" f)); +DESCR("check connection information consistency in pooler"); +DATA(insert OID = 3201 ( pgxc_pool_reload PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_reload _null_ _null_ _null_ "" f)); +DESCR("reload connection information in pooler and reload server sessions"); +DATA(insert OID = 3202 ( pgxc_node_str PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 19 "" _null_ _null_ _null_ _null_ pgxc_node_str _null_ _null_ _null_ "" f)); +DESCR("get the name of the node"); +DATA(insert OID = 3203 ( pgxc_is_committed PGNSP PGUID 12 1 1 0 0 f f f f t t s 1 0 16 "28" _null_ _null_ _null_ _null_ pgxc_is_committed _null_ _null_ _null_ "" f)); +DESCR("is given GXID committed or aborted?"); +DATA(insert OID = 3204 ( pgxc_lock_for_backup PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_lock_for_backup _null_ _null_ _null_ "" f)); +DESCR("lock the cluster for taking backup"); +DATA(insert OID = 3950 ( node_oid_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ node_oid_name _null_ _null_ _null_ ""f)); +DESCR("transfer node oid to node name"); +DATA(insert OID = 3952 ( tablespace_oid_name PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "26" _null_ _null_ _null_ _null_ tablespace_oid_name _null_ _null_ _null_ ""f)); +DESCR("transfer tablespace oid to tablespace name"); +DATA(insert OID = 3953 ( get_schema_oid PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 26 "2275" _null_ _null_ _null_ _null_ get_schema_oid _null_ _null_ _null_ ""f)); +DESCR("transfer schema name to schema/namespace oid"); +DATA(insert OID = 3954 ( pgxc_pool_connection_status PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 16 "" _null_ _null_ _null_ _null_ pgxc_pool_connection_status _null_ _null_ _null_ "" f)); +DESCR("check if pooler connection is normal"); +DATA(insert OID = 3471 ( pg_pool_validate PGNSP PGUID 12 1 100 0 0 f f f f t t s 2 0 2249 "16 2275" "{16,2275,20,25}" "{i,i,o,o}" "{clear,co_node_name,pid,node_name}" _null_ pg_pool_validate _null_ _null_ _null_ "" f)); +DESCR("cancel the invalid connections to standby"); +DATA(insert OID = 3955 ( pg_stat_get_pooler_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,25,20,25,20,16}" "{o,o,o,o,o,o}" "{database_name,user_name,tid,pgoptions,node_oid,in_use}" _null_ pg_stat_get_pooler_status _null_ _null_ _null_ "" f)); +DESCR("check pooler connection status"); +DATA(insert OID = 3472 ( pg_pool_ping PGNSP PGUID 12 1 1 0 0 f f f f t t s 1 0 16 "16" _null_ _null_ _null_ _null_ pg_pool_ping _null_ _null_ _null_ "" f)); +DESCR("enable pooler ping"); +DATA(insert OID = 1982 ( comm_check_connection_status PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25, 25, 25, 23, 16}" "{o,o,o,o,o}" "{node_name,remote_name,remote_host,remote_port,is_connected}" _null_ comm_check_connection_status _null_ _null_ _null_ "" f)); +DESCR("check connections status"); +#endif + +/* used for bulkload */ +DATA(insert OID = 3208 ( to_tsvector_for_batch PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 3614 "3734 25" _null_ _null_ _null_ _null_ to_tsvector_byid _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); +DATA(insert OID = 3209 ( to_tsvector_for_batch PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3614 "25" _null_ _null_ _null_ _null_ to_tsvector _null_ _null_ _null_ "" f)); +DESCR("transform to tsvector"); + +/* used for aes encrypt/decrypt */ +DATA(insert OID = 3464 ( gs_encrypt_aes128 PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 25 "25 25" _null_ _null_ _null_ _null_ gs_encrypt_aes128 _null_ _null_ _null_ "" f)); +DESCR("internal encrypt"); +#define GSENCRYPTAES128FUNCOID 3464 +DATA(insert OID = 3465 ( gs_decrypt_aes128 PGNSP PGUID 12 1 0 0 0 f f f f f f i 2 0 25 "25 25" _null_ _null_ _null_ _null_ gs_decrypt_aes128 _null_ _null_ _null_ "" f)); +DESCR("internal decrypt"); + +/* used for show password expired time and notice time user set. */ +DATA(insert OID = 3469 ( gs_password_deadline PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 1186 "" _null_ _null_ _null_ _null_ gs_password_deadline _null_ _null_ _null_ "" f)); +DESCR("password deadline"); +DATA(insert OID = 3470 ( gs_password_notifytime PGNSP PGUID 12 1 0 0 0 f f f f t f i 0 0 23 "" _null_ _null_ _null_ _null_ gs_password_notifytime _null_ _null_ _null_ "" f)); +DESCR("password noticetime"); + +DATA(insert OID = 4000 ( gs_fault_inject PGNSP PGUID 12 1 0 0 0 f f f f t f v 6 0 20 "20 25 25 25 25 25" _null_ _null_ _null_ _null_ gs_fault_inject _null_ _null_ _null_ "" f)); +DESCR("SQL function for fault injection"); + +/* psort index */ +DATA(insert OID = 4040 ( psortbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ psortbuild _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4041 ( psortoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ psortoptions _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4042 ( psortgettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ psortgettuple _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4043 ( psortgetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ psortgetbitmap _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4044 ( psortcostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ psortcostestimate _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); +DATA(insert OID = 4045 ( psortcanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ psortcanreturn _null_ _null_ _null_ "" f)); +DESCR("psort(internal)"); + +/* cbtree index */ +DATA(insert OID = 4240 ( cbtreebuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ cbtreebuild _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4241 ( cbtreeoptions PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 17 "1009 16" _null_ _null_ _null_ _null_ cbtreeoptions _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4242 ( cbtreegettuple PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 16 "2281 2281" _null_ _null_ _null_ _null_ cbtreegettuple _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4243 ( cbtreecostestimate PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "2281 2281 2281 2281 2281 2281 2281" _null_ _null_ _null_ _null_ cbtreecostestimate _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4245 ( cbtreecanreturn PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 16 "2281" _null_ _null_ _null_ _null_ cbtreecanreturn _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); +DATA(insert OID = 4246 ( cbtreegetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ cbtreegetbitmap _null_ _null_ _null_ "" f)); +DESCR("cbtree(internal)"); + + +/* cginbtree index */ +DATA(insert OID = 4400 ( cginbuild PGNSP PGUID 12 1 0 0 0 f f f f t f v 3 0 2281 "2281 2281 2281" _null_ _null_ _null_ _null_ cginbuild _null_ _null_ _null_ "" f)); +DESCR("cgin(internal)"); +DATA(insert OID = 4401 ( cgingetbitmap PGNSP PGUID 12 1 0 0 0 f f f f t f v 2 0 20 "2281 2281" _null_ _null_ _null_ _null_ cgingetbitmap _null_ _null_ _null_ "" f)); +DESCR("cgin(internal)"); + + + +/* used for data redistribution bucket functions OID from 4100 to 4129 */ +/* support type should match with IsTypeDistributable(Oid col_type) in locator.cpp */ +DATA(insert OID = 4100 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ bucketint4 _null_ _null_ _null_ "" f)); +DESCR("int4 value"); +DATA(insert OID = 4101 ( bucketint4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "23 23" _null_ _null_ _null_ _null_ bucketint4 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int4 value"); +DATA(insert OID = 4102 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ bucketint2 _null_ _null_ _null_ "" f)); +DESCR("int2 value"); +DATA(insert OID = 4103 ( bucketint2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "21 23" _null_ _null_ _null_ _null_ bucketint2 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int2 value"); +DATA(insert OID = 4104 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ bucketint8 _null_ _null_ _null_ "" f)); +DESCR("int8 value"); +DATA(insert OID = 4105 ( bucketint8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "20 23" _null_ _null_ _null_ _null_ bucketint8 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int8 value"); +DATA(insert OID = 4106 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 23" _null_ _null_ _null_ _null_ bucketbpchar _null_ _null_ _null_ "" f)); +DESCR("bpchar value"); +DATA(insert OID = 4107 ( bucketbpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1042 23" _null_ _null_ _null_ _null_ bucketbpchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from bpchar value"); +DATA(insert OID = 4108 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 23" _null_ _null_ _null_ _null_ bucketchar _null_ _null_ _null_ "" f)); +DESCR("char value"); +DATA(insert OID = 4109 ( bucketchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "18 23" _null_ _null_ _null_ _null_ bucketchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from char value"); +DATA(insert OID = 4110 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1043 23" _null_ _null_ _null_ _null_ bucketvarchar _null_ _null_ _null_ "" f)); +DESCR("varchar value"); +DATA(insert OID = 4111 ( bucketvarchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1043 23" _null_ _null_ _null_ _null_ bucketvarchar _null_ _null_ _null_ "" f)); +DESCR("get bucket from varchar value"); +DATA(insert OID = 4112 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 23" _null_ _null_ _null_ _null_ bucketdate _null_ _null_ _null_ "" f)); +DESCR("date value"); +DATA(insert OID = 4113 ( bucketdate PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1082 23" _null_ _null_ _null_ _null_ bucketdate _null_ _null_ _null_ "" f)); +DESCR("get bucket from date value"); +DATA(insert OID = 4114 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 23" _null_ _null_ _null_ _null_ buckettime _null_ _null_ _null_ "" f)); +DESCR("time value"); +DATA(insert OID = 4115 ( buckettime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1083 23" _null_ _null_ _null_ _null_ buckettime _null_ _null_ _null_ "" f)); +DESCR("get bucket from time value"); +DATA(insert OID = 4116 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 23" _null_ _null_ _null_ _null_ buckettimestamp _null_ _null_ _null_ "" f)); +DESCR("timestamp value"); +DATA(insert OID = 4117 ( buckettimestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1114 23" _null_ _null_ _null_ _null_ buckettimestamp _null_ _null_ _null_ "" f)); +DESCR("get bucket from timestamp value"); +DATA(insert OID = 4118 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 23" _null_ _null_ _null_ _null_ buckettimetz _null_ _null_ _null_ "" f)); +DESCR("date value"); +DATA(insert OID = 4119 ( buckettimetz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1266 23" _null_ _null_ _null_ _null_ buckettimetz _null_ _null_ _null_ "" f)); +DESCR("get bucket from date value"); +DATA(insert OID = 4120 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 23" _null_ _null_ _null_ _null_ bucketinterval _null_ _null_ _null_ "" f)); +DESCR("time value"); +DATA(insert OID = 4121 ( bucketinterval PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1186 23" _null_ _null_ _null_ _null_ bucketinterval _null_ _null_ _null_ "" f)); +DESCR("get bucket from time value"); +DATA(insert OID = 4122 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 23" _null_ _null_ _null_ _null_ buckettimestamptz _null_ _null_ _null_ "" f)); +DESCR("timestamp value"); +DATA(insert OID = 4123 ( buckettimestamptz PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1184 23" _null_ _null_ _null_ _null_ buckettimestamptz _null_ _null_ _null_ "" f)); +DESCR("get bucket from timestamp value"); +DATA(insert OID = 4124 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 23" _null_ _null_ _null_ _null_ bucketint1 _null_ _null_ _null_ "" f)); +DESCR("int1 value"); +DATA(insert OID = 4125 ( bucketint1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "5545 23" _null_ _null_ _null_ _null_ bucketint1 _null_ _null_ _null_ "" f)); +DESCR("get bucket from int1 value"); +DATA(insert OID = 4126 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 23" _null_ _null_ _null_ _null_ bucketsmalldatetime _null_ _null_ _null_ "" f)); +DESCR("smalldatetime value"); +DATA(insert OID = 4127 ( bucketsmalldatetime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "9003 23" _null_ _null_ _null_ _null_ bucketsmalldatetime _null_ _null_ _null_ "" f)); +DESCR("get bucket from smalldatetime value"); +DATA(insert OID = 4128 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3969 23" _null_ _null_ _null_ _null_ bucketnvarchar2 _null_ _null_ _null_ "" f)); +DESCR("varchar value"); +DATA(insert OID = 4129 ( bucketnvarchar2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "3969 23" _null_ _null_ _null_ _null_ bucketnvarchar2 _null_ _null_ _null_ "" f)); +DESCR("get bucket from varchar value"); +DATA(insert OID = 4130 ( pg_buffercache_pages PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{23,26,26,26,21,20,16,21}" "{o,o,o,o,o,o,o,o}" "{bufferid,relfilenode,reltablespace,reldatabase,relforknumber,relblocknumber,isdirty,usage_count}" _null_ pg_buffercache_pages _null_ _null_ _null_ "" f)); +DESCR("statistics: information about shared buffer cache detail"); +DATA(insert OID = 4131 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 23" _null_ _null_ _null_ _null_ bucketnumeric _null_ _null_ _null_ "" f)); +DESCR("numeric value"); +DATA(insert OID = 4132 ( bucketnumeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "1700 23" _null_ _null_ _null_ _null_ bucketnumeric _null_ _null_ _null_ "" f)); +DESCR("get bucket from numeric value"); +DATA(insert OID = 4133 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 23" _null_ _null_ _null_ _null_ bucketoid _null_ _null_ _null_ "" f)); +DESCR("oid value"); +DATA(insert OID = 4134 ( bucketoid PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "26 23" _null_ _null_ _null_ _null_ bucketoid _null_ _null_ _null_ "" f)); +DESCR("get bucket from oid value"); +DATA(insert OID = 4135 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 23" _null_ _null_ _null_ _null_ bucketabstime _null_ _null_ _null_ "" f)); +DESCR("abstime value"); +DATA(insert OID = 4136 ( bucketabstime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "702 23" _null_ _null_ _null_ _null_ bucketabstime _null_ _null_ _null_ "" f)); +DESCR("get bucket from abstime value"); +DATA(insert OID = 4137 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 23" _null_ _null_ _null_ _null_ bucketreltime _null_ _null_ _null_ "" f)); +DESCR("reltime value"); +DATA(insert OID = 4138 ( bucketreltime PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "703 23" _null_ _null_ _null_ _null_ bucketreltime _null_ _null_ _null_ "" f)); +DESCR("get bucket from reltime value"); +DATA(insert OID = 4139 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 23" _null_ _null_ _null_ _null_ bucketcash _null_ _null_ _null_ "" f)); +DESCR("cash value"); +DATA(insert OID = 4140 ( bucketcash PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "790 23" _null_ _null_ _null_ _null_ bucketcash _null_ _null_ _null_ "" f)); +DESCR("get bucket from cash value"); +DATA(insert OID = 4141 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ bucketbytea _null_ _null_ _null_ "" f)); +DESCR("bytea value"); +DATA(insert OID = 4142 ( bucketbytea PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 23" _null_ _null_ _null_ _null_ bucketbytea _null_ _null_ _null_ "" f)); +DESCR("get bucket from bytea value"); +DATA(insert OID = 4143 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 23" _null_ _null_ _null_ _null_ bucketraw _null_ _null_ _null_ "" f)); +DESCR("raw value"); +DATA(insert OID = 4144 ( bucketraw PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "86 23" _null_ _null_ _null_ _null_ bucketraw _null_ _null_ _null_ "" f)); +DESCR("get bucket from raw value"); +DATA(insert OID = 4145 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 23" _null_ _null_ _null_ _null_ bucketbool _null_ _null_ _null_ "" f)); +DESCR("bool value"); +DATA(insert OID = 4146 ( bucketbool PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "16 23" _null_ _null_ _null_ _null_ bucketbool _null_ _null_ _null_ "" f)); +DESCR("get bucket from bool value"); +DATA(insert OID = 4147 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 23" _null_ _null_ _null_ _null_ bucketname _null_ _null_ _null_ "" f)); +DESCR("name value"); +DATA(insert OID = 4148 ( bucketname PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "19 23" _null_ _null_ _null_ _null_ bucketname _null_ _null_ _null_ "" f)); +DESCR("get bucket from name value"); +DATA(insert OID = 4149 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "22 23" _null_ _null_ _null_ _null_ bucketint2vector _null_ _null_ _null_ "" f)); +DESCR("int2vector value"); +DATA(insert OID = 4150 ( bucketint2vector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "22 23" _null_ _null_ _null_ _null_ bucketint2vector _null_ _null_ _null_ "" f)); +DESCR("get bucket from int2vector value"); +DATA(insert OID = 4151 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 23" _null_ _null_ _null_ _null_ buckettext _null_ _null_ _null_ "" f)); +DESCR("text value"); +DATA(insert OID = 4152 ( buckettext PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "25 23" _null_ _null_ _null_ _null_ buckettext _null_ _null_ _null_ "" f)); +DESCR("get bucket from text value"); +DATA(insert OID = 4153 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 23" _null_ _null_ _null_ _null_ bucketoidvector _null_ _null_ _null_ "" f)); +DESCR("oidvector value"); +DATA(insert OID = 4154 ( bucketoidvector PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "30 23" _null_ _null_ _null_ _null_ bucketoidvector _null_ _null_ _null_ "" f)); +DESCR("get bucket from oidvector value"); +DATA(insert OID = 4155 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 23" _null_ _null_ _null_ _null_ bucketfloat4 _null_ _null_ _null_ "" f)); +DESCR("float4 value"); +DATA(insert OID = 4156 ( bucketfloat4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "700 23" _null_ _null_ _null_ _null_ bucketfloat4 _null_ _null_ _null_ "" f)); +DESCR("get bucket from float4 value"); +DATA(insert OID = 4157 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 23" _null_ _null_ _null_ _null_ bucketfloat8 _null_ _null_ _null_ "" f)); +DESCR("float8 value"); +DATA(insert OID = 4158 ( bucketfloat8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "701 23" _null_ _null_ _null_ _null_ bucketfloat8 _null_ _null_ _null_ "" f)); +DESCR("get bucket from float8 value"); + +DATA(insert OID = 4159 ( date_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1082" _null_ _null_ _null_ _null_ date_text _null_ _null_ _null_ "" f)); +DESCR("convert date to text"); +DATA(insert OID = 4160 ( date_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "1082" _null_ _null_ _null_ _null_ date_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert date to bpchar"); +DATA(insert OID = 4161 ( date_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1082" _null_ _null_ _null_ _null_ date_varchar _null_ _null_ _null_ "" f)); +DESCR("convert date to varchar"); +DATA(insert OID = 4162 ( varchar_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1043" _null_ _null_ _null_ _null_ varchar_date _null_ _null_ _null_ "" f)); +DESCR("convert varchar to date"); +DATA(insert OID = 4163 ( bpchar_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "1042" _null_ _null_ _null_ _null_ bpchar_date _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to date"); +DATA(insert OID = 4164 ( text_date PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1082 "25" _null_ _null_ _null_ _null_ text_date _null_ _null_ _null_ "" f)); +DESCR("convert text to date"); + +DATA(insert OID = 4165 ( int1_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "5545" _null_ _null_ _null_ _null_ int1_text _null_ _null_ _null_ "" f)); +DESCR("convert int1 to text"); +DATA(insert OID = 4166 ( int2_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "21" _null_ _null_ _null_ _null_ int2_text _null_ _null_ _null_ "" f)); +DESCR("convert int2 to text"); +DATA(insert OID = 4167 ( int4_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "23" _null_ _null_ _null_ _null_ int4_text _null_ _null_ _null_ "" f)); +DESCR("convert int4 to text"); +DATA(insert OID = 4168 ( int8_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "20" _null_ _null_ _null_ _null_ int8_text _null_ _null_ _null_ "" f)); +DESCR("convert int8 to text"); +DATA(insert OID = 4169 ( float4_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "700" _null_ _null_ _null_ _null_ float4_text _null_ _null_ _null_ "" f)); +DESCR("convert float4 to text"); +DATA(insert OID = 4170 ( float8_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "701" _null_ _null_ _null_ _null_ float8_text _null_ _null_ _null_ "" f)); +DESCR("convert float8 to text"); +DATA(insert OID = 4171 ( numeric_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1700" _null_ _null_ _null_ _null_ numeric_text _null_ _null_ _null_ "" f)); +DESCR("convert numeric to text"); +DATA(insert OID = 4172 ( bpchar_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1042" _null_ _null_ _null_ _null_ bpchar_numeric _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to numeric"); +DATA(insert OID = 4173 ( varchar_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "1043" _null_ _null_ _null_ _null_ varchar_numeric _null_ _null_ _null_ "" f)); +DESCR("convert varchar to numeric"); +DATA(insert OID = 4174 ( varchar_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1043" _null_ _null_ _null_ _null_ varchar_int4 _null_ _null_ _null_ "" f)); +DESCR("convert varchar to int4"); +DATA(insert OID = 4175 ( bpchar_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1042" _null_ _null_ _null_ _null_ bpchar_int4 _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to int4"); +DATA(insert OID = 4176 ( varchar_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1043" _null_ _null_ _null_ _null_ varchar_int8 _null_ _null_ _null_ "" f)); +DESCR("convert varchar to int8"); +DATA(insert OID = 4177 ( timestampzone_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1184" _null_ _null_ _null_ _null_ timestampzone_text _null_ _null_ _null_ "" f)); +DESCR("convert timestampzone to text"); +DATA(insert OID = 4178 ( timestamp_text PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "1114" _null_ _null_ _null_ _null_ timestamp_text _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to text"); +DATA(insert OID = 4179 ( timestamp_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1114" _null_ _null_ _null_ _null_ timestamp_varchar _null_ _null_ _null_ "" f)); +DESCR("convert timestamp to text"); +DATA(insert OID = 4180 ( int2_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "21" _null_ _null_ _null_ _null_ int2_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int2 to varchar"); +DATA(insert OID = 4181 ( int4_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "23" _null_ _null_ _null_ _null_ int4_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int4 to varchar"); +DATA(insert OID = 4182 ( int8_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "20" _null_ _null_ _null_ _null_ int8_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int8 to varchar"); +DATA(insert OID = 4183 ( numeric_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "1700" _null_ _null_ _null_ _null_ numeric_varchar _null_ _null_ _null_ "" f)); +DESCR("convert numeric to varchar"); +DATA(insert OID = 4184 ( float4_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "700" _null_ _null_ _null_ _null_ float4_varchar _null_ _null_ _null_ "" f)); +DESCR("convert float4 to varchar"); +DATA(insert OID = 4185 ( float8_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "701" _null_ _null_ _null_ _null_ float8_varchar _null_ _null_ _null_ "" f)); +DESCR("convert float8 to varchar"); +DATA(insert OID = 4186 ( varchar_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1043" _null_ _null_ _null_ _null_ varchar_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert varchar to timestamp"); +DATA(insert OID = 4187 ( bpchar_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1042" _null_ _null_ _null_ _null_ bpchar_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to timestamp"); +DATA(insert OID = 4188 ( text_int1 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 5545 "25" _null_ _null_ _null_ _null_ text_int1 _null_ _null_ _null_ "" f)); +DESCR("convert text to int1"); +DATA(insert OID = 4189 ( text_int2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 21 "25" _null_ _null_ _null_ _null_ text_int2 _null_ _null_ _null_ "" f)); +DESCR("convert text to int2"); +DATA(insert OID = 4190 ( text_int4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "25" _null_ _null_ _null_ _null_ text_int4 _null_ _null_ _null_ "" f)); +DESCR("convert text to int4"); +DATA(insert OID = 4191 ( text_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "25" _null_ _null_ _null_ _null_ text_int8 _null_ _null_ _null_ "" f)); +DESCR("convert text to int8"); +DATA(insert OID = 4192 ( text_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "25" _null_ _null_ _null_ _null_ text_float4 _null_ _null_ _null_ "" f)); +DESCR("convert text to float4"); +DATA(insert OID = 4193 ( text_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "25" _null_ _null_ _null_ _null_ text_float8 _null_ _null_ _null_ "" f)); +DESCR("convert text to float8"); +DATA(insert OID = 4194 ( text_numeric PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1700 "25" _null_ _null_ _null_ _null_ text_numeric _null_ _null_ _null_ "" f)); +DESCR("convert text to numeric"); +DATA(insert OID = 4195 ( bpchar_int8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 20 "1042" _null_ _null_ _null_ _null_ bpchar_int8 _null_ _null_ _null_ "" f)); +DESCR("convert bpchar to int8"); +DATA(insert OID = 4196 ( bpchar_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1042" _null_ _null_ _null_ _null_ bpchar_float4 _null_ _null_ _null_ ""f)); +DESCR("convert bpchar to float4"); +DATA(insert OID = 4197 ( bpchar_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1042" _null_ _null_ _null_ _null_ bpchar_float8 _null_ _null_ _null_ ""f)); +DESCR("convert bpchar to float8"); +DATA(insert OID = 4198 ( varchar_float4 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 700 "1043" _null_ _null_ _null_ _null_ varchar_float4 _null_ _null_ _null_ ""f)); +DESCR("convert varchar to float4"); +DATA(insert OID = 4199 ( varchar_float8 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 701 "1043" _null_ _null_ _null_ _null_ varchar_float8 _null_ _null_ _null_ ""f)); +DESCR("convert varchar to float8"); +DATA(insert OID = 4200 ( plan_seed PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ get_plan_seed _null_ _null_ _null_ ""f)); +DESCR("get plan seed"); +DATA(insert OID = 4046 ( getbucket PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "2249 18" _null_ _null_ _null_ _null_ getbucket _null_ _null_ _null_ "" f)); +DESCR("get bucket"); +DATA(insert OID = 4047 ( getdistributekey PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 25 "2205" _null_ _null_ _null_ _null_ getDistributeKey _null_ _null_ _null_ "" f)); +DESCR("Get distribute columns"); +DATA(insert OID = 4048 ( table_data_skewness PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 21 "2249 18" _null_ _null_ _null_ _null_ table_data_skewness _null_ _null_ _null_ "" f)); +DESCR("get datanode series number"); +#define TESTSKEWNESSRETURNTYPE 4048 +DATA(insert OID = 4065 ( int1_varchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1043 "5545" _null_ _null_ _null_ _null_ int1_varchar _null_ _null_ _null_ "" f)); +DESCR("convert int1 to varchar"); +DATA(insert OID = 4066 ( int1_nvarchar2 PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 3969 "5545" _null_ _null_ _null_ _null_ int1_nvarchar2 _null_ _null_ _null_ "" f)); +DESCR("convert int1 to nvarchar2"); +DATA(insert OID = 4067 ( int1_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "5545" _null_ _null_ _null_ _null_ int1_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int1 to bpchar"); +DATA(insert OID = 4068 ( int2_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "21" _null_ _null_ _null_ _null_ int2_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int2 to bpchar"); +DATA(insert OID = 4069 ( int8_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "20" _null_ _null_ _null_ _null_ int8_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert int8 to bpchar"); +DATA(insert OID = 4070 ( float4_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "700" _null_ _null_ _null_ _null_ float4_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert float4 to bpchar"); +DATA(insert OID = 4071 ( float8_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "701" _null_ _null_ _null_ _null_ float8_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert float8 to bpchar"); +DATA(insert OID = 4072 ( numeric_bpchar PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1042 "1700" _null_ _null_ _null_ _null_ numeric_bpchar _null_ _null_ _null_ "" f)); +DESCR("convert numeric to bpchar"); +DATA(insert OID = 4073 ( text_timestamp PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "25" _null_ _null_ _null_ _null_ text_timestamp _null_ _null_ _null_ "" f)); +DESCR("convert text to timestamp"); +/* add months to a timestamp */ +DATA(insert OID = 4074 ( add_months PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ add_months _null_ _null_ _null_ "" f)); +DESCR("add a int months to a timestamp"); +DATA(insert OID = 4075 ( last_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 1114 "1114" _null_ _null_ _null_ _null_ last_day _null_ _null_ _null_ "" f)); +DESCR("the last day of the month"); +DATA(insert OID = 4076 ( next_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 23" _null_ _null_ _null_ _null_ next_day_int _null_ _null_ _null_ "" f)); +DESCR("next_day with offset number"); +DATA(insert OID = 4077 ( next_day PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 1114 "1114 25" _null_ _null_ _null_ _null_ next_day_str _null_ _null_ _null_ "" f)); +DESCR("next_day with offset string of week"); + +DATA(insert OID = 3990 ( task_submit 3988 PGUID 12 1 0 0 0 f f f f f f i 4 0 2278 "20 25 1114 25" _null_ _null_ _null_ _null_ task_submit _null_ _null_ _null_ "" f)); +DESCR("add job"); +DATA(insert OID = 3991 ( remove 3988 PGUID 12 1 0 0 0 f f f f f f i 1 0 2278 "20" _null_ _null_ _null_ _null_ remove_job _null_ _null_ _null_ "" f)); +DESCR("remove job"); +DESCR("add job"); +DATA(insert OID = 3993 ( broken 3988 PGUID 12 1 0 0 0 f f f f f f i 3 0 2278 "20 16 1114" _null_ _null_ _null_ _null_ broken_job_state _null_ _null_ _null_ "" f)); +DESCR("broken job"); +DATA(insert OID = 3994 ( change 3988 PGUID 12 1 0 0 0 f f f f f f i 4 0 2278 "20 25 1114 25" _null_ _null_ _null_ _null_ change_job _null_ _null_ _null_ "" f)); +DESCR("change job"); +DATA(insert OID = 3995 ( what 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 25" _null_ _null_ _null_ _null_ update_what _null_ _null_ _null_ "" f)); +DESCR("update job what"); +DATA(insert OID = 3996 ( next_date 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 1114" _null_ _null_ _null_ _null_ update_next_date _null_ _null_ _null_ "" f)); +DESCR("update job next date"); +DATA(insert OID = 3997 ( interval 3988 PGUID 12 1 0 0 0 f f f f f f i 2 0 2278 "20 25" _null_ _null_ _null_ _null_ update_interval_date _null_ _null_ _null_ "" f)); +DESCR("update job interval"); +DATA(insert OID = 3998 ( update_pgjob PGNSP PGUID 12 1 0 0 0 f f f f f f v 9 0 2278 "20 18 20 1114 1114 1114 1114 1114 21" _null_ _null_ _null_ _null_ syn_update_pg_job _null_ _null_ _null_ "" f)); +DESCR("update pg_job synchronize from original coordinator."); +DATA(insert OID = 7998 ( set_working_grand_version_num_manually PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2278 "26" _null_ _null_ _null_ _null_ set_working_grand_version_num_manually _null_ _null_ _null_ "" f)); +DESCR("Manually set the working grand version number of the instance."); +DATA(insert OID = 4201 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by username, nodegroup name"); +DATA(insert OID = 4202 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "19 26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by username, nodegroup oid"); +DATA(insert OID = 4203 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id_name _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by user oid, nodegroup name"); +DATA(insert OID = 4204 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 3 0 16 "26 26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id_id _null_ _null_ _null_ "" f)); +DESCR("user privilege on nodegroup by user oid, nodegroup oid"); +DATA(insert OID = 4205 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "25 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_name _null_ _null_ _null_ "" f)); +DESCR("current user privilege on nodegroup by nodegroup name"); +DATA(insert OID = 4206 ( has_nodegroup_privilege PGNSP PGUID 12 1 0 0 0 f f f f t f s 2 0 16 "26 25" _null_ _null_ _null_ _null_ has_nodegroup_privilege_id _null_ _null_ _null_ "" f)); +DESCR("current user privilege on nodegroup by nodegroup oid"); +DATA(insert OID = 4207 ( fenced_udf_process PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 25 "23" _null_ _null_ _null_ _null_ fenced_udf_process _null_ _null_ _null_ "" f)); +DATA(insert OID = 4300 ( pv_compute_pool_workload PGNSP PGUID 12 1 100 0 0 f f f f f t s 0 0 2249 "" "{25,23,23,25}" "{o,o,o,o}" "{nodename, rpinuse, maxrp, nodestate}" _null_ pv_compute_pool_workload _null_ _null_ _null_ "" f)); +DESCR("the current workload of the compute pool"); +DATA(insert OID = 4208 ( get_db_source_datasize PGNSP PGUID 12 1 0 0 0 f f f f t f v 0 0 20 "" _null_ _null_ _null_ _null_ get_db_source_datasize _null_ _null_ _null_ "" f)); +DESCR("total source datasize for the current database"); +DATA(insert OID = 4209 ( pg_clean_region_info PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1043 "" _null_ _null_ _null_ _null_ pg_clean_region_info _null_ _null_ _null_ "" f)); +DESCR("clean region map information cache for the current database"); + +/* + * Symbolic values for provolatile column: these indicate whether the result + * of a function is dependent *only* on the values of its explicit arguments, + * or can change due to outside factors (such as parameter variables or + * table contents). NOTE: functions having side-effects, such as setval(), + * must be labeled volatile to ensure they will not get optimized away, + * even if the actual return value is not changeable. + */ +#define PROVOLATILE_IMMUTABLE 'i' /* never changes for given input */ +#define PROVOLATILE_STABLE 's' /* does not change within a scan */ +#define PROVOLATILE_VOLATILE 'v' /* can change even within a scan */ + +/* + * Symbolic values for proargmodes column. Note that these must agree with + * the FunctionParameterMode enum in parsenodes.h; we declare them here to + * be accessible from either header. + */ +#define PROARGMODE_IN 'i' +#define PROARGMODE_OUT 'o' +#define PROARGMODE_INOUT 'b' +#define PROARGMODE_VARIADIC 'v' +#define PROARGMODE_TABLE 't' + +DATA(insert OID = 4440 ( byteawithoutorderwithequalcolin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2275" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolin _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4446 ( byteawithoutorderwithequalcolout PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 2275 "17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolout _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4444 ( byteawithoutorderwithequalcolrecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2281" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolrecv _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4451 ( byteawithoutorderwithequalcolsend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolsend _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4412 ( byteawithoutorderwithequalcoleq PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleq _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4417 ( byteawithoutorderwithequalcolne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolne _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4418 ( byteawithoutorderwithequalcolcmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "4402 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmp _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4447 ( byteawithoutorderwithequalcoleqbytear PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleqbytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4460 ( byteawithoutorderwithequalcolnebytear PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolnebytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4456 ( byteawithoutorderwithequalcolcmpbytear PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "4402 17" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmpbytear _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4457 ( byteawithoutorderwithequalcoleqbyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoleqbyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4461 ( byteawithoutorderwithequalcolgebyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolgebyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4462 ( byteawithoutorderwithequalcolnebyteal PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolnebyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4463 ( byteawithoutorderwithequalcolcmpbyteal PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "17 4402" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcolcmpbyteal _null_ _null_ _null_ "" f _null_ f)); +DATA(insert OID = 4369 ( hll_hash_byteawithoutorderwithequalcol PGNSP PGUID 12 1 0 0 - f f f f t f i 1 0 4303 "4402" _null_ _null_ _null_ _null_ hll_hash_varlena _null_ _null_ _null_ "" f f f)); +DESCR("hypper log log hash a byteawithoutorderwithequalcol type"); +DATA(insert OID = 4449 ( byteawithoutorderwithequalcoltypmodin PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 23 "1263" _null_ _null_ _null_ _null_ byteawithoutorderwithequalcoltypmodin _null_ _null_ _null_ "" f _null_ f)); +#endif /* PG_PROC_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_range.h postgresql-hll-2.14/include/include/catalog/pg_range.h --- postgresql-hll-2.14_old/include/include/catalog/pg_range.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_range.h 2020-12-12 17:06:43.163346954 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_range.h + * definition of the system "range" relation (pg_range) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_range.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_RANGE_H +#define PG_RANGE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_range definition. cpp turns this into + * typedef struct FormData_pg_range + * ---------------- + */ +#define RangeRelationId 3541 +#define RangeRelation_Rowtype_Id 11657 + +CATALOG(pg_range,3541) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid rngtypid; /* OID of owning range type */ + Oid rngsubtype; /* OID of range's element type (subtype) */ + Oid rngcollation; /* collation for this range type, or 0 */ + Oid rngsubopc; /* subtype's btree opclass */ + regproc rngcanonical; /* canonicalize range, or 0 */ + regproc rngsubdiff; /* subtype difference as a float8, or 0 */ +} FormData_pg_range; + +/* ---------------- + * Form_pg_range corresponds to a pointer to a tuple with + * the format of pg_range relation. + * ---------------- + */ +typedef FormData_pg_range *Form_pg_range; + +/* ---------------- + * compiler constants for pg_range + * ---------------- + */ +#define Natts_pg_range 6 +#define Anum_pg_range_rngtypid 1 +#define Anum_pg_range_rngsubtype 2 +#define Anum_pg_range_rngcollation 3 +#define Anum_pg_range_rngsubopc 4 +#define Anum_pg_range_rngcanonical 5 +#define Anum_pg_range_rngsubdiff 6 + + +/* ---------------- + * initial contents of pg_range + * ---------------- + */ +DATA(insert (3904 23 0 1978 int4range_canonical int4range_subdiff)); +DATA(insert (3906 1700 0 3125 - numrange_subdiff)); +DATA(insert (3908 1114 0 3128 - tsrange_subdiff)); +DATA(insert (3910 1184 0 3127 - tstzrange_subdiff)); +DATA(insert (3912 1082 0 3122 daterange_canonical daterange_subdiff)); +DATA(insert (3926 20 0 3124 int8range_canonical int8range_subdiff)); + + +/* + * prototypes for functions in pg_range.c + */ + +extern void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation, + Oid rangeSubOpclass, RegProcedure rangeCanonical, + RegProcedure rangeSubDiff); +extern void RangeDelete(Oid rangeTypeOid); + +#endif /* PG_RANGE_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_resource_pool.h postgresql-hll-2.14/include/include/catalog/pg_resource_pool.h --- postgresql-hll-2.14_old/include/include/catalog/pg_resource_pool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_resource_pool.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,117 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_resource_pool.h + * define the system resource pool information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_resource_pool.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_RESOURCE_POOL_H +#define PG_RESOURCE_POOL_H + +#include "catalog/genbki.h" +#include "workload/workload.h" + +/* define the OID of the table pg_resource_pool */ +#define ResourcePoolRelationId 3450 +#define ResourcePoolRelation_Rowtype_Id 3466 + +CATALOG(pg_resource_pool,3450) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3466) BKI_SCHEMA_MACRO +{ + NameData respool_name; /* Name of resource pool */ + int4 mem_percent; /* Memory percentage */ + int8 cpu_affinity; /* CPU affinity mask */ + NameData control_group; /* Name of control group */ + int4 active_statements; /* Active statements */ + int4 max_dop; /* Max dop */ + NameData memory_limit; /* Memory limit to use */ + Oid parentid; /* parent resource pool oid */ + int4 io_limits; /* iops limit */ + NameData io_priority; /* percentage of IO resource for DN */ + NameData nodegroup; /* node group */ + bool is_foreign; /* flag to indicate the resource pool for foreign users */ +} FormData_pg_resource_pool; + + +/* ------------------------------------------------------------------------- + * Form_pg_resource_pool corresponds to a pointer to a tuple with + * the format of pg_resource_pool relation. + * There is different meaning that "int8" means 8-bits in C codes, while + * it means 64-bits in catalogs. + * ------------------------------------------------------------------------- + */ +typedef struct FormData_pg_resource_pool_real { + NameData respool_name; /* Name of resource pool */ + int4 mem_percent; /* Memory percentage */ + int64 cpu_affinity; /* CPU affinity mask */ + NameData control_group; /* Name of control group */ + int4 active_statements; /* Active statements */ + int4 max_dop; /* Max dop */ + NameData memory_limit; /* Memory limit to use */ + Oid parentid; /* parent resource pool oid */ + int4 iops_limits; /* iops limit */ + NameData io_priority; /* percentage of IO resource for DN */ + NameData nodegroup; /* node group */ + bool is_foreign; /* flag to indicate the resource pool for foreign users */ +} FormData_pg_resource_pool_real; + +typedef FormData_pg_resource_pool_real *Form_pg_resource_pool; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_resource_pool + * ------------------------------------------------------------------------- + */ +#define Natts_pg_resource_pool 12 +#define Anum_pg_resource_pool_rpname 1 +#define Anum_pg_resource_pool_mem_percentage 2 +#define Anum_pg_resource_pool_cpu_affinity 3 +#define Anum_pg_resource_pool_control_group 4 +#define Anum_pg_resource_pool_active_statements 5 +#define Anum_pg_resource_pool_max_dop 6 +#define Anum_pg_resource_pool_memory_limit 7 +#define Anum_pg_resource_pool_parent 8 +#define Anum_pg_resource_pool_iops_limits 9 +#define Anum_pg_resource_pool_io_priority 10 +#define Anum_pg_resource_pool_nodegroup 11 +#define Anum_pg_resource_pool_is_foreign 12 + +/* -1 means 0xffffffffffffffff */ +DATA(insert OID = 10 ("default_pool" 100 -1 "DefaultClass:Medium" -1 1 "8GB" 0 0 "None" "installation" f)); + +#define DEFAULT_POOL_OID 10 +#define DEFAULT_POOL_NAME "default_pool" +#define INVALID_POOL_NAME "invalid_pool" +#define ULIMITED_MEMORY_PERCENTAGE 100 +#define ULIMITED_CPU_AFFINITY 0xffffffffffffffffULL +#define ULIMITED_ACT_STATEMENTS -1 +#define DEFAULT_CONTROL_GROUP "DefaultClass:Medium" +#define DEFAULT_MAX_DOP 1 +#define DEFAULT_MEMORY_LIMIT "8GB" +#define DEFAULT_IOPS_LIMITS 0 +#define DEFAULT_IO_PRIORITY "None" +#define DEFAULT_NODE_GROUP "installation" // the same as CNG_OPTION_INSTALLATION + +/* default setting for user defined resource pool */ +#define DEFAULT_MEMORY_PERCENTAGE 0 +#define DEFAULT_MULTI_TENANT_MEMPCT 20 +#define DEFAULT_ACT_STATEMENTS 10 + +#endif /* PG_RESOURCE_POOL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_rewrite.h postgresql-hll-2.14/include/include/catalog/pg_rewrite.h --- postgresql-hll-2.14_old/include/include/catalog/pg_rewrite.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_rewrite.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pg_rewrite.h + * definition of the system "rewrite-rule" relation (pg_rewrite) + * along with the relation's initial contents. + * + * As of Postgres 7.3, the primary key for this table is + * --- ie, rule names are only unique among the rules of a given table. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_rewrite.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_REWRITE_H +#define PG_REWRITE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_rewrite definition. cpp turns this into + * typedef struct FormData_pg_rewrite + * ---------------- + */ +#define RewriteRelationId 2618 +#define RewriteRelation_Rowtype_Id 11328 + +CATALOG(pg_rewrite,2618) BKI_SCHEMA_MACRO +{ + NameData rulename; + Oid ev_class; + int2 ev_attr; + char ev_type; + char ev_enabled; + bool is_instead; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + pg_node_tree ev_qual; + pg_node_tree ev_action; +#endif +} FormData_pg_rewrite; + +/* ---------------- + * Form_pg_rewrite corresponds to a pointer to a tuple with + * the format of pg_rewrite relation. + * ---------------- + */ +typedef FormData_pg_rewrite *Form_pg_rewrite; + +/* ---------------- + * compiler constants for pg_rewrite + * ---------------- + */ +#define Natts_pg_rewrite 8 +#define Anum_pg_rewrite_rulename 1 +#define Anum_pg_rewrite_ev_class 2 +#define Anum_pg_rewrite_ev_attr 3 +#define Anum_pg_rewrite_ev_type 4 +#define Anum_pg_rewrite_ev_enabled 5 +#define Anum_pg_rewrite_is_instead 6 +#define Anum_pg_rewrite_ev_qual 7 +#define Anum_pg_rewrite_ev_action 8 + +#endif /* PG_REWRITE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_rlspolicy.h postgresql-hll-2.14/include/include/catalog/pg_rlspolicy.h --- postgresql-hll-2.14_old/include/include/catalog/pg_rlspolicy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_rlspolicy.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_rlspolicy.h + * definition of the row level security policy system catalog (pg_rlspolicy) + * the genbki.pl script reads this file and generates postgres.bki information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_rlspolicy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_RLSPOLICY_H +#define PG_RLSPOLICY_H + +#include "catalog/genbki.h" + +#define RlsPolicyRelationId 3254 +#define RlsPolicyRelation_Rowtype_Id 11652 + +CATALOG(pg_rlspolicy,3254) BKI_SCHEMA_MACRO +{ + NameData polname; /* Rlspolicy name */ + Oid polrelid; /* Oid of the relation with rlspolicy */ + char polcmd; /* Keep same with ACL_*_CHR, support 'a','r','w','d','*'(all) */ + bool polpermissive; /* Permissive or Restrictive rlspolicy */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + Oid polroles[1]; /* Roles associated with rlspolicy */ + pg_node_tree polqual; /* Using quals */ +#endif +} FormData_pg_rlspolicy; + +/* ---------------- + * Form_pg_rlspolicy corresponds to a pointer to a row with + * the format of pg_rlspolicy relation. + * ---------------- + */ +typedef FormData_pg_rlspolicy *Form_pg_rlspolicy; + +/* ---------------- + * compiler constants for pg_rlspolicy + * ---------------- + */ +#define Natts_pg_rlspolicy 6 +#define Anum_pg_rlspolicy_polname 1 +#define Anum_pg_rlspolicy_polrelid 2 +#define Anum_pg_rlspolicy_polcmd 3 +#define Anum_pg_rlspolicy_polpermissive 4 +#define Anum_pg_rlspolicy_polroles 5 +#define Anum_pg_rlspolicy_polqual 6 + +#endif /* PG_RLSPOLICY_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_seclabel.h postgresql-hll-2.14/include/include/catalog/pg_seclabel.h --- postgresql-hll-2.14_old/include/include/catalog/pg_seclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_seclabel.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * pg_seclabel.h + * definition of the system "security label" relation (pg_seclabel) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SECLABEL_H +#define PG_SECLABEL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_seclabel definition. cpp turns this into + * typedef struct FormData_pg_seclabel + * ---------------- + */ +#define SecLabelRelationId 3596 +#define SecLabelRelation_Rowtype_Id 33654 + +CATALOG(pg_seclabel,3596) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of the object itself */ + Oid classoid; /* OID of table containing the object */ + int4 objsubid; /* column number, or 0 if not used */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text provider; /* name of label provider */ + text label; /* security label of the object */ +#endif +} FormData_pg_seclabel; + +/* ---------------- + * compiler constants for pg_seclabel + * ---------------- + */ +#define Natts_pg_seclabel 5 +#define Anum_pg_seclabel_objoid 1 +#define Anum_pg_seclabel_classoid 2 +#define Anum_pg_seclabel_objsubid 3 +#define Anum_pg_seclabel_provider 4 +#define Anum_pg_seclabel_label 5 + +#endif /* PG_SECLABEL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_shdepend.h postgresql-hll-2.14/include/include/catalog/pg_shdepend.h --- postgresql-hll-2.14_old/include/include/catalog/pg_shdepend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_shdepend.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,96 @@ +/* ------------------------------------------------------------------------- + * + * pg_shdepend.h + * definition of the system "shared dependency" relation (pg_shdepend) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_shdepend.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHDEPEND_H +#define PG_SHDEPEND_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shdepend definition. cpp turns this into + * typedef struct FormData_pg_shdepend + * ---------------- + */ +#define SharedDependRelationId 1214 +#define SharedDependRelation_Rowtype_Id 11635 + +CATALOG(pg_shdepend,1214) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* + * Identification of the dependent (referencing) object. + * + * These fields are all zeroes for a DEPENDENCY_PIN entry. Also, dbid can + * be zero to denote a shared object. + */ + Oid dbid; /* OID of database containing object */ + Oid classid; /* OID of table containing object */ + Oid objid; /* OID of object itself */ + int4 objsubid; /* column number, or 0 if not used */ + + /* + * Identification of the independent (referenced) object. This is always + * a shared object, so we need no database ID field. We don't bother with + * a sub-object ID either. + */ + Oid refclassid; /* OID of table containing object */ + Oid refobjid; /* OID of object itself */ + + /* + * Precise semantics of the relationship are specified by the deptype + * field. See SharedDependencyType in catalog/dependency.h. + */ + char deptype; /* see codes in dependency.h */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text objfile; /* library file path */ +#endif +} FormData_pg_shdepend; + +/* ---------------- + * Form_pg_shdepend corresponds to a pointer to a row with + * the format of pg_shdepend relation. + * ---------------- + */ +typedef FormData_pg_shdepend *Form_pg_shdepend; + +/* ---------------- + * compiler constants for pg_shdepend + * ---------------- + */ +#define Natts_pg_shdepend 8 +#define Anum_pg_shdepend_dbid 1 +#define Anum_pg_shdepend_classid 2 +#define Anum_pg_shdepend_objid 3 +#define Anum_pg_shdepend_objsubid 4 +#define Anum_pg_shdepend_refclassid 5 +#define Anum_pg_shdepend_refobjid 6 +#define Anum_pg_shdepend_deptype 7 +#define Anum_pg_shdepend_objfile 8 + + +/* + * pg_shdepend has no preloaded contents; system-defined dependencies are + * loaded into it during a late stage of the initdb process. + * + * NOTE: we do not represent all possible dependency pairs in pg_shdepend; + * for example, there's not much value in creating an explicit dependency + * from a relation to its database. Currently, only dependencies on roles + * are explicitly stored in pg_shdepend. + */ + +#endif /* PG_SHDEPEND_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_shdescription.h postgresql-hll-2.14/include/include/catalog/pg_shdescription.h --- postgresql-hll-2.14_old/include/include/catalog/pg_shdescription.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_shdescription.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * pg_shdescription.h + * definition of the system "shared description" relation + * (pg_shdescription) + * + * NOTE: an object is identified by the OID of the row that primarily + * defines the object, plus the OID of the table that that row appears in. + * For example, a database is identified by the OID of its pg_database row + * plus the pg_class OID of table pg_database. This allows unique + * identification of objects without assuming that OIDs are unique + * across tables. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_shdescription.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHDESCRIPTION_H +#define PG_SHDESCRIPTION_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shdescription definition. cpp turns this into + * typedef struct FormData_pg_shdescription + * ---------------- + */ +#define SharedDescriptionRelationId 2396 +#define SharedDescriptionRelation_Rowtype_Id 11636 + +CATALOG(pg_shdescription,2396) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of object itself */ + Oid classoid; /* OID of table containing object */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text description; /* description of object */ +#endif +} FormData_pg_shdescription; + +/* ---------------- + * Form_pg_shdescription corresponds to a pointer to a tuple with + * the format of pg_shdescription relation. + * ---------------- + */ +typedef FormData_pg_shdescription *Form_pg_shdescription; + +/* ---------------- + * compiler constants for pg_shdescription + * ---------------- + */ +#define Natts_pg_shdescription 3 +#define Anum_pg_shdescription_objoid 1 +#define Anum_pg_shdescription_classoid 2 +#define Anum_pg_shdescription_description 3 + +/* ---------------- + * initial contents of pg_shdescription + * ---------------- + */ + +/* + * Because the contents of this table are taken from the other *.h files, + * there is no initialization here. The initial contents are extracted + * by genbki.pl and loaded during initdb. + */ + +#endif /* PG_SHDESCRIPTION_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_shseclabel.h postgresql-hll-2.14/include/include/catalog/pg_shseclabel.h --- postgresql-hll-2.14_old/include/include/catalog/pg_shseclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_shseclabel.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * pg_shseclabel.h + * definition of the system "security label" relation (pg_shseclabel) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHSECLABEL_H +#define PG_SHSECLABEL_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_shseclabel definition. cpp turns this into + * typedef struct FormData_pg_shseclabel + * ---------------- + */ +#define SharedSecLabelRelationId 3592 +#define SharedSecLabelRelation_Rowtype_Id 11655 + +CATALOG(pg_shseclabel,3592) BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid objoid; /* OID of the shared object itself */ + Oid classoid; /* OID of table containing the shared object */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text provider; /* name of label provider */ + text label; /* security label of the object */ +#endif +} FormData_pg_shseclabel; + +/* ---------------- + * compiler constants for pg_shseclabel + * ---------------- + */ +#define Natts_pg_shseclabel 4 +#define Anum_pg_shseclabel_objoid 1 +#define Anum_pg_shseclabel_classoid 2 +#define Anum_pg_shseclabel_provider 3 +#define Anum_pg_shseclabel_label 4 + +#endif /* PG_SHSECLABEL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_statistic_ext.h postgresql-hll-2.14/include/include/catalog/pg_statistic_ext.h --- postgresql-hll-2.14_old/include/include/catalog/pg_statistic_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_statistic_ext.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,188 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_statistic_ext.h + * definition of the system "extended statistic" relation (pg_statistic_ext) + * along with the relation's initial contents. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/pg_statistic_ext.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_STATISTIC_EXT_H +#define PG_STATISTIC_EXT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_statistic_ext definition. cpp turns this into + * typedef struct FormData_pg_statistic_ext + * ---------------- + */ +#define StatisticExtRelationId 3220 +#define StatisticExtRelation_Rowtype_Id 11660 + +CATALOG(pg_statistic_ext,3220) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + Oid starelid; /* relation containing attribute */ + char starelkind; /* 'c': starelid ref pg_class.oid + * 'p': starelid ref pg_partition.oid */ + bool stainherit; /* true if inheritance children are included */ + + /* the fraction of the column's entries that are NULL: */ + float4 stanullfrac; + + /* + * stawidth is the average width in bytes of non-null entries. For + * fixed-width datatypes this is of course the same as the typlen, but for + * var-width types it is more useful. Note that this is the average width + * of the data as actually stored, post-TOASTing (eg, for a + * moved-out-of-line value, only the size of the pointer object is + * counted). This is the appropriate definition for the primary use of + * the statistic, which is to estimate sizes of in-memory hash tables of + * tuples. + */ + int4 stawidth; + + /* ---------------- + * stadistinct indicates the (approximate) number of distinct non-null + * data values in the column. The interpretation is: + * 0 unknown or not computed + * > 0 actual number of distinct values + * < 0 negative of multiplier for number of rows + * The special negative case allows us to cope with columns that are + * unique (stadistinct = -1) or nearly so (for example, a column in + * which values appear about twice on the average could be represented + * by stadistinct = -0.5). Because the number-of-rows statistic in + * pg_class may be updated more frequently than pg_statistic_ext is, it's + * important to be able to describe such situations as a multiple of + * the number of rows, rather than a fixed number of distinct values. + * But in other cases a fixed number is correct (eg, a boolean column). + * ---------------- + */ + float4 stadistinct; + float4 stadndistinct; + + /* ---------------- + * To allow keeping statistics on different kinds of datatypes, + * we do not hard-wire any particular meaning for the remaining + * statistical fields. Instead, we provide several "slots" in which + * statistical data can be placed. Each slot includes: + * kind integer code identifying kind of data (see below) + * op OID of associated operator, if needed + * numbers float4 array (for statistical values) + * values anyarray (for representations of data values) + * The ID and operator fields are never NULL; they are zeroes in an + * unused slot. The numbers and values fields are NULL in an unused + * slot, and might also be NULL in a used slot if the slot kind has + * no need for one or the other. + * ---------------- + */ + int2 stakind1; + int2 stakind2; + int2 stakind3; + int2 stakind4; + int2 stakind5; + + Oid staop1; + Oid staop2; + Oid staop3; + Oid staop4; + Oid staop5; + + /* variable-length fields start here, but we allow direct access to stakey */ + int2vector stakey; /* attribute (column) stats are for */ +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + float4 stanumbers1[1]; + float4 stanumbers2[1]; + float4 stanumbers3[1]; + float4 stanumbers4[1]; + float4 stanumbers5[1]; + + /* + * Values in these arrays are values of the column's data type, or of some + * related type such as an array element type. We presently have to cheat + * quite a bit to allow polymorphic arrays of this kind, but perhaps + * someday it'll be a less bogus facility. + */ + anyarray stavalues1; + anyarray stavalues2; + anyarray stavalues3; + anyarray stavalues4; + anyarray stavalues5; + pg_node_tree staexprs; +#endif +} FormData_pg_statistic_ext; + +#define STATISTIC_NUM_SLOTS 5 +#define STATISTIC_KIND_TBLSIZE 6 +#define STARELKIND_CLASS 'c' +#define STARELKIND_PARTITION 'p' + +/* ---------------- + * Form_pg_statistic_ext corresponds to a pointer to a tuple with + * the format of pg_statistic_ext relation. + * ---------------- + */ +typedef FormData_pg_statistic_ext *Form_pg_statistic_ext; + +/* ---------------- + * compiler constants for pg_statistic + * ---------------- + */ +#define Natts_pg_statistic_ext 29 +#define Anum_pg_statistic_ext_starelid 1 +#define Anum_pg_statistic_ext_starelkind 2 +#define Anum_pg_statistic_ext_stainherit 3 +#define Anum_pg_statistic_ext_stanullfrac 4 +#define Anum_pg_statistic_ext_stawidth 5 +#define Anum_pg_statistic_ext_stadistinct 6 +#define Anum_pg_statistic_ext_stadndistinct 7 +#define Anum_pg_statistic_ext_stakind1 8 +#define Anum_pg_statistic_ext_stakind2 9 +#define Anum_pg_statistic_ext_stakind3 10 +#define Anum_pg_statistic_ext_stakind4 11 +#define Anum_pg_statistic_ext_stakind5 12 +#define Anum_pg_statistic_ext_staop1 13 +#define Anum_pg_statistic_ext_staop2 14 +#define Anum_pg_statistic_ext_staop3 15 +#define Anum_pg_statistic_ext_staop4 16 +#define Anum_pg_statistic_ext_staop5 17 +#define Anum_pg_statistic_ext_stakey 18 +#define Anum_pg_statistic_ext_stanumbers1 19 +#define Anum_pg_statistic_ext_stanumbers2 20 +#define Anum_pg_statistic_ext_stanumbers3 21 +#define Anum_pg_statistic_ext_stanumbers4 22 +#define Anum_pg_statistic_ext_stanumbers5 23 +#define Anum_pg_statistic_ext_stavalues1 24 +#define Anum_pg_statistic_ext_stavalues2 25 +#define Anum_pg_statistic_ext_stavalues3 26 +#define Anum_pg_statistic_ext_stavalues4 27 +#define Anum_pg_statistic_ext_stavalues5 28 +#define Anum_pg_statistic_ext_staexprs 29 + +/* statistic definition for extended statistic */ +/* + * In a "most common values" slot that contains NULL value staop is the OID + * of the "=" operator used to decide whether values are the same or not. + * stavalues contains the K most common values(NULLS contains ) appearing in + * the column, and stanumbers contains their frequencies (fractions of total + * row count). The values shall be ordered in decreasing frequency. Note that + * since the arrays are variable-size, K may be chosen by the statistics + * collector. Values should not appear in MCV unless they have been observed + * to occur more than once; a unique column will have no MCV slot. + */ +#define STATISTIC_KIND_NULL_MCV 6 + +#define STATISTIC_KIND_MULTICOLUMN 10001 + +#endif /* PG_STATISTIC_EXT_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_statistic.h postgresql-hll-2.14/include/include/catalog/pg_statistic.h --- postgresql-hll-2.14_old/include/include/catalog/pg_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_statistic.h 2020-12-12 17:06:43.164346967 +0800 @@ -0,0 +1,281 @@ +/* ------------------------------------------------------------------------- + * + * pg_statistic.h + * definition of the system "statistic" relation (pg_statistic) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_statistic.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_STATISTIC_H +#define PG_STATISTIC_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_statistic definition. cpp turns this into + * typedef struct FormData_pg_statistic + * ---------------- + */ +#define StatisticRelationId 2619 +#define StatisticRelation_Rowtype_Id 11327 + +CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + /* These fields form the unique key for the entry: */ + Oid starelid; /* relation containing attribute */ + char starelkind; /*'c': starelid ref pg_class.oid + *'p': starelid ref pg_partition.oid*/ + int2 staattnum; /* attribute (column) stats are for */ + bool stainherit; /* true if inheritance children are included */ + + /* the fraction of the column's entries that are NULL: */ + float4 stanullfrac; + + /* + * stawidth is the average width in bytes of non-null entries. For + * fixed-width datatypes this is of course the same as the typlen, but for + * var-width types it is more useful. Note that this is the average width + * of the data as actually stored, post-TOASTing (eg, for a + * moved-out-of-line value, only the size of the pointer object is + * counted). This is the appropriate definition for the primary use of + * the statistic, which is to estimate sizes of in-memory hash tables of + * tuples. + */ + int4 stawidth; + + /* ---------------- + * stadistinct indicates the (approximate) number of distinct non-null + * data values in the column. The interpretation is: + * 0 unknown or not computed + * > 0 actual number of distinct values + * < 0 negative of multiplier for number of rows + * The special negative case allows us to cope with columns that are + * unique (stadistinct = -1) or nearly so (for example, a column in + * which values appear about twice on the average could be represented + * by stadistinct = -0.5). Because the number-of-rows statistic in + * pg_class may be updated more frequently than pg_statistic is, it's + * important to be able to describe such situations as a multiple of + * the number of rows, rather than a fixed number of distinct values. + * But in other cases a fixed number is correct (eg, a boolean column). + * ---------------- + */ + float4 stadistinct; + + /* ---------------- + * To allow keeping statistics on different kinds of datatypes, + * we do not hard-wire any particular meaning for the remaining + * statistical fields. Instead, we provide several "slots" in which + * statistical data can be placed. Each slot includes: + * kind integer code identifying kind of data (see below) + * op OID of associated operator, if needed + * numbers float4 array (for statistical values) + * values anyarray (for representations of data values) + * The ID and operator fields are never NULL; they are zeroes in an + * unused slot. The numbers and values fields are NULL in an unused + * slot, and might also be NULL in a used slot if the slot kind has + * no need for one or the other. + * ---------------- + */ + int2 stakind1; + int2 stakind2; + int2 stakind3; + int2 stakind4; + int2 stakind5; + + Oid staop1; + Oid staop2; + Oid staop3; + Oid staop4; + Oid staop5; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + float4 stanumbers1[1]; + float4 stanumbers2[1]; + float4 stanumbers3[1]; + float4 stanumbers4[1]; + float4 stanumbers5[1]; + + /* + * Values in these arrays are values of the column's data type, or of some + * related type such as an array element type. We presently have to cheat + * quite a bit to allow polymorphic arrays of this kind, but perhaps + * someday it'll be a less bogus facility. + */ + anyarray stavalues1; + anyarray stavalues2; + anyarray stavalues3; + anyarray stavalues4; + anyarray stavalues5; + float4 stadndistinct; + text staextinfo; +#endif +} FormData_pg_statistic; + +#define STATISTIC_NUM_SLOTS 5 +#define STATISTIC_KIND_TBLSIZE 6 +#define STARELKIND_CLASS 'c' +#define STARELKIND_PARTITION 'p' + +/* ---------------- + * Form_pg_statistic corresponds to a pointer to a tuple with + * the format of pg_statistic relation. + * ---------------- + */ +typedef FormData_pg_statistic *Form_pg_statistic; + +/* ---------------- + * compiler constants for pg_statistic + * ---------------- + */ +#define Natts_pg_statistic 29 +#define Anum_pg_statistic_starelid 1 +#define Anum_pg_statistic_starelkind 2 +#define Anum_pg_statistic_staattnum 3 +#define Anum_pg_statistic_stainherit 4 +#define Anum_pg_statistic_stanullfrac 5 +#define Anum_pg_statistic_stawidth 6 +#define Anum_pg_statistic_stadistinct 7 +#define Anum_pg_statistic_stakind1 8 +#define Anum_pg_statistic_stakind2 9 +#define Anum_pg_statistic_stakind3 10 +#define Anum_pg_statistic_stakind4 11 +#define Anum_pg_statistic_stakind5 12 +#define Anum_pg_statistic_staop1 13 +#define Anum_pg_statistic_staop2 14 +#define Anum_pg_statistic_staop3 15 +#define Anum_pg_statistic_staop4 16 +#define Anum_pg_statistic_staop5 17 +#define Anum_pg_statistic_stanumbers1 18 +#define Anum_pg_statistic_stanumbers2 19 +#define Anum_pg_statistic_stanumbers3 20 +#define Anum_pg_statistic_stanumbers4 21 +#define Anum_pg_statistic_stanumbers5 22 +#define Anum_pg_statistic_stavalues1 23 +#define Anum_pg_statistic_stavalues2 24 +#define Anum_pg_statistic_stavalues3 25 +#define Anum_pg_statistic_stavalues4 26 +#define Anum_pg_statistic_stavalues5 27 +#define Anum_pg_statistic_stadndistinct 28 +#define Anum_pg_statistic_staextinfo 29 + +/* + * Currently, five statistical slot "kinds" are defined by core PostgreSQL, + * as documented below. Additional "kinds" will probably appear in + * future to help cope with non-scalar datatypes. Also, custom data types + * can define their own "kind" codes by mutual agreement between a custom + * typanalyze routine and the selectivity estimation functions of the type's + * operators. + * + * Code reading the pg_statistic relation should not assume that a particular + * data "kind" will appear in any particular slot. Instead, search the + * stakind fields to see if the desired data is available. (The standard + * function get_attstatsslot() may be used for this.) + */ + +/* + * The present allocation of "kind" codes is: + * + * 1-99: reserved for assignment by the core PostgreSQL project + * (values in this range will be documented in this file) + * 100-199: reserved for assignment by the PostGIS project + * (values to be documented in PostGIS documentation) + * 200-299: reserved for assignment by the ESRI ST_Geometry project + * (values to be documented in ESRI ST_Geometry documentation) + * 300-9999: reserved for future public assignments + * + * For private use you may choose a "kind" code at random in the range + * 10000-30000. However, for code that is to be widely disseminated it is + * better to obtain a publicly defined "kind" code by request from the + * PostgreSQL Global Development Group. + */ + +/* + * In a "most common values" slot, staop is the OID of the "=" operator + * used to decide whether values are the same or not. stavalues contains + * the K most common non-null values appearing in the column, and stanumbers + * contains their frequencies (fractions of total row count). The values + * shall be ordered in decreasing frequency. Note that since the arrays are + * variable-size, K may be chosen by the statistics collector. Values should + * not appear in MCV unless they have been observed to occur more than once; + * a unique column will have no MCV slot. + */ +#define STATISTIC_KIND_MCV 1 + +/* + * A "histogram" slot describes the distribution of scalar data. staop is + * the OID of the "<" operator that describes the sort ordering. (In theory, + * more than one histogram could appear, if a datatype has more than one + * useful sort operator.) stavalues contains M (>=2) non-null values that + * divide the non-null column data values into M-1 bins of approximately equal + * population. The first stavalues item is the MIN and the last is the MAX. + * stanumbers is not used and should be NULL. IMPORTANT POINT: if an MCV + * slot is also provided, then the histogram describes the data distribution + * *after removing the values listed in MCV* (thus, it's a "compressed + * histogram" in the technical parlance). This allows a more accurate + * representation of the distribution of a column with some very-common + * values. In a column with only a few distinct values, it's possible that + * the MCV list describes the entire data population; in this case the + * histogram reduces to empty and should be omitted. + */ +#define STATISTIC_KIND_HISTOGRAM 2 + +/* + * A "correlation" slot describes the correlation between the physical order + * of table tuples and the ordering of data values of this column, as seen + * by the "<" operator identified by staop. (As with the histogram, more + * than one entry could theoretically appear.) stavalues is not used and + * should be NULL. stanumbers contains a single entry, the correlation + * coefficient between the sequence of data values and the sequence of + * their actual tuple positions. The coefficient ranges from +1 to -1. + */ +#define STATISTIC_KIND_CORRELATION 3 + +/* + * A "most common elements" slot is similar to a "most common values" slot, + * except that it stores the most common non-null *elements* of the column + * values. This is useful when the column datatype is an array or some other + * type with identifiable elements (for instance, tsvector). staop contains + * the equality operator appropriate to the element type. stavalues contains + * the most common element values, and stanumbers their frequencies. Unlike + * MCV slots, frequencies are measured as the fraction of non-null rows the + * element value appears in, not the frequency of all rows. Also unlike + * MCV slots, the values are sorted into the element type's default order + * (to support binary search for a particular value). Since this puts the + * minimum and maximum frequencies at unpredictable spots in stanumbers, + * there are two extra members of stanumbers, holding copies of the minimum + * and maximum frequencies. Optionally, there can be a third extra member, + * which holds the frequency of null elements (expressed in the same terms: + * the fraction of non-null rows that contain at least one null element). If + * this member is omitted, the column is presumed to contain no null elements. + * + * Note: in current usage for tsvector columns, the stavalues elements are of + * type text, even though their representation within tsvector is not + * exactly text. + */ +#define STATISTIC_KIND_MCELEM 4 + +/* + * A "distinct elements count histogram" slot describes the distribution of + * the number of distinct element values present in each row of an array-type + * column. Only non-null rows are considered, and only non-null elements. + * staop contains the equality operator appropriate to the element type. + * stavalues is not used and should be NULL. The last member of stanumbers is + * the average count of distinct element values over all non-null rows. The + * preceding M (>=2) members form a histogram that divides the population of + * distinct-elements counts into M-1 bins of approximately equal population. + * The first of these is the minimum observed count, and the last the maximum. + */ +#define STATISTIC_KIND_DECHIST 5 + +#endif /* PG_STATISTIC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_streaming_cont_query.h postgresql-hll-2.14/include/include/catalog/pg_streaming_cont_query.h --- postgresql-hll-2.14_old/include/include/catalog/pg_streaming_cont_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_streaming_cont_query.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,59 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_cont_query.h + * streaming continuous query catalog schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_cont_query.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_CONT_QUERY_H +#define STREAMING_CONT_QUERY_H + +#include "catalog/genbki.h" + +#define StreamingContQueryRelationId 9029 +#define StreamingContQueryRelation_Rowtype_Id 7201 + +CATALOG(streaming_cont_query,9029) BKI_SCHEMA_MACRO +{ + int4 id; + char type; + Oid relid; + Oid defrelid; + bool active; + Oid streamrelid; + Oid matrelid; + Oid lookupidxid; + int2 step_factor; + int4 ttl; + int2 ttl_attno; + Oid dictrelid; + int2 grpnum; + int2vector grpidx; +} FormData_streaming_cont_query; + +typedef FormData_streaming_cont_query *Form_streaming_cont_query; + + +#define Natts_streaming_cont_query 14 + +#define Anum_streaming_cont_query_id 1 +#define Anum_streaming_cont_query_type 2 +#define Anum_streaming_cont_query_relid 3 +#define Anum_streaming_cont_query_defrelid 4 +#define Anum_streaming_cont_query_active 5 +#define Anum_streaming_cont_query_streamrelid 6 +#define Anum_streaming_cont_query_matrelid 7 +#define Anum_streaming_cont_query_lookupidxid 8 +#define Anum_streaming_cont_query_step_factor 9 +#define Anum_streaming_cont_query_ttl 10 +#define Anum_streaming_cont_query_ttl_attno 11 +#define Anum_streaming_cont_query_dictrelid 12 +#define Anum_streaming_cont_query_grpnum 13 +#define Anum_streaming_cont_query_grpidx 14 + +#endif diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_streaming_fn.h postgresql-hll-2.14/include/include/catalog/pg_streaming_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_streaming_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_streaming_fn.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,25 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_fn.h + * streaming functions + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_fn.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef PG_STREAMING_FN_H +#define PG_STREAMING_FN_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/indexing.h" +#include "catalog/pg_type.h" + +#define STREAMING_SERVER "streaming" + +void lookup_pg_stream_cont_query(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_streaming_reaper_status.h postgresql-hll-2.14/include/include/catalog/pg_streaming_reaper_status.h --- postgresql-hll-2.14_old/include/include/catalog/pg_streaming_reaper_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_streaming_reaper_status.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,41 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_reaper_status.h + * streaming continuous query catalog schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_reaper_status.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_REAPER_STATUS_H +#define STREAMING_REAPER_STATUS_H + +#include "catalog/genbki.h" + +#define StreamingReaperStatusRelationId 9030 +#define StreamingReaperStatusRelation_Rowtype_Id 7202 + +CATALOG(streaming_reaper_status,9030) BKI_SCHEMA_MACRO +{ + int4 id; + NameData contquery_name; +#ifdef CATALOG_VARLEN + text gather_interval; + text gather_completion_time; +#endif +} FormData_streaming_reaper_status; + +typedef FormData_streaming_reaper_status *Form_streaming_reaper_status; + + +#define Natts_streaming_reaper_status 4 + +#define Anum_streaming_reaper_status_id 1 +#define Anum_streaming_reaper_status_contquery_name 2 +#define Anum_streaming_reaper_status_gather_interval 3 +#define Anum_streaming_reaper_status_gather_completion_time 4 + +#endif diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_streaming_stream.h postgresql-hll-2.14/include/include/catalog/pg_streaming_stream.h --- postgresql-hll-2.14_old/include/include/catalog/pg_streaming_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_streaming_stream.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,34 @@ +/*--------------------------------------------------------------------------------------- + * + * pg_streaming_stream.h + * streaming stream schema + * + * Portions Copyright (c), Huawei Gauss Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/catalog/pg_streaming_stream.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef STREAMING_STREAM_H +#define STREAMING_STREAM_H + +#include "catalog/genbki.h" + +#define StreamingStreamRelationId 9028 +#define StreamingStreamRelation_Rowtype_Id 7200 + +CATALOG(streaming_stream,9028) BKI_SCHEMA_MACRO +{ + Oid relid; + bytea queries; +} FormData_streaming_stream; + +typedef FormData_streaming_stream *Form_streaming_stream; + +#define Natts_streaming_stream 2 + +#define Anum_streaming_stream_relid 1 +#define Anum_streaming_stream_queries 2 + +#endif /* PG_STREAMING_STREAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_synonym.h postgresql-hll-2.14/include/include/catalog/pg_synonym.h --- postgresql-hll-2.14_old/include/include/catalog/pg_synonym.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_synonym.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,99 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_synonym.h + * definition of the system "synonym" relation (pg_synonym) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_synonym.h + * + * NOTES + * the genbki.sh script reads this file and generates .bki + * information from the DATA() statements. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_SYNONYM_H +#define PG_SYNONYM_H + +#include "catalog/genbki.h" +#include "nodes/parsenodes.h" + +/* ---------------------------------------------------------------- + * pg_synonym definition. + * + * synname name of the synonym + * synnamespace name space which the synonym belongs to + * synowner owner of the synonym + * synobjschema schema name which the referenced object belongs to + * synobjname referenced object name + * ---------------------------------------------------------------- + */ +#define PgSynonymRelationId 3546 +#define PgSynonymRelationId_Rowtype_Id 11662 + +#define SYNONYM_VERSION_NUM 92059 + +CATALOG(pg_synonym,3546) BKI_SCHEMA_MACRO +{ + NameData synname; + Oid synnamespace; + Oid synowner; + NameData synobjschema; + NameData synobjname; +} FormData_pg_synonym; + +/* ---------------- + * Form_pg_synonym corresponds to a pointer to a tuple with + * the format of pg_synonym relation. + * ---------------- + */ +typedef FormData_pg_synonym *Form_pg_synonym; + +/* ---------------- + * compiler constants for pg_synonym + * ---------------- + */ +#define Natts_pg_synonym 5 +#define Anum_pg_synonym_synname 1 +#define Anum_pg_synonym_synnamespace 2 +#define Anum_pg_synonym_synowner 3 +#define Anum_pg_synonym_synobjschema 4 +#define Anum_pg_synonym_synobjname 5 + +/* ---------------- + * initial contents of pg_synonym + * --------------- + */ + +/* + * function prototypes + */ +extern void CreateSynonym(CreateSynonymStmt *stmt); +extern void DropSynonym(DropSynonymStmt *stmt); +extern void AlterSynonymOwner(List *name, Oid newOwnerId); +extern void RemoveSynonymById(Oid synonymOid); +extern RangeVar* SearchReferencedObject(const char *synName, Oid synNamespace); +extern RangeVar* ReplaceReferencedObject(const RangeVar *relation); +extern char* CheckReferencedObject(Oid relOid, RangeVar *objVar, const char *synName); +extern Oid GetSynonymOid(const char *synName, Oid synNamespace, bool missing); +extern char* GetQualifiedSynonymName(Oid synOid, bool qualified = true); +extern void GetSynonymAndSchemaName(Oid synOid, char **synName_p, char **synSchema_p); + +#endif /* PG_SYNONYM_H */ + + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_tablespace.h postgresql-hll-2.14/include/include/catalog/pg_tablespace.h --- postgresql-hll-2.14_old/include/include/catalog/pg_tablespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_tablespace.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,85 @@ +/* ------------------------------------------------------------------------- + * + * pg_tablespace.h + * definition of the system "tablespace" relation (pg_tablespace) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_tablespace.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TABLESPACE_H +#define PG_TABLESPACE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_tablespace definition. cpp turns this into + * typedef struct FormData_pg_tablespace + * ---------------- + */ +#define TableSpaceRelationId 1213 +#define TableSpaceRelation_Rowtype_Id 11633 + +CATALOG(pg_tablespace,1213) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData spcname; /* tablespace name */ + Oid spcowner; /* owner of tablespace */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + aclitem spcacl[1]; /* access permissions */ + text spcoptions[1]; /* per-tablespace options */ + text spcmaxsize; /* tablespace max size */ + bool relative; /* relative location */ +#endif +} FormData_pg_tablespace; + +/* ---------------- + * Form_pg_tablespace corresponds to a pointer to a tuple with + * the format of pg_tablespace relation. + * ---------------- + */ +typedef FormData_pg_tablespace *Form_pg_tablespace; + +/* ---------------- + * compiler constants for pg_tablespace + * ---------------- + */ +#define Natts_pg_tablespace 6 +#define Anum_pg_tablespace_spcname 1 +#define Anum_pg_tablespace_spcowner 2 +#define Anum_pg_tablespace_spcacl 3 +#define Anum_pg_tablespace_spcoptions 4 +#define Anum_pg_tablespace_maxsize 5 +#define Anum_pg_tablespace_relative 6 + + +DATA(insert OID = 1663 (pg_default PGUID _null_ _null_ _null_ f)); +DATA(insert OID = 1664 (pg_global PGUID _null_ _null_ _null_ f)); + +#define DEFAULTTABLESPACE_OID 1663 +#define GLOBALTABLESPACE_OID 1664 + +#define MAX_TABLESPACE_LIMITED_STRING_LEN 21 + +#define TABLESPACE_OPTION_FILESYSTEM "filesystem" +#define TABLESPACE_OPTION_ADDRESS "address" +#define TABLESPACE_OPTION_CFGPATH "cfgpath" +#define TABLESPACE_OPTION_STOREPATH "storepath" +#define TABLESPACE_OPTION_SEQ_PAGE_COST "seq_page_cost" +#define TABLESPACE_OPTION_RANDOM_PAGE_COST "random_page_cost" + +#define DFS_TABLESPACE_SUBDIR "tablespace_secondary" +#define DFS_TABLESPACE_TEMPDIR_SUFFIX "pgsql_tmp" + + +#endif /* PG_TABLESPACE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_trigger.h postgresql-hll-2.14/include/include/catalog/pg_trigger.h --- postgresql-hll-2.14_old/include/include/catalog/pg_trigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_trigger.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,151 @@ + +/* ------------------------------------------------------------------------- + * + * pg_trigger.h + * definition of the system "trigger" relation (pg_trigger) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_trigger.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TRIGGER_H +#define PG_TRIGGER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_trigger definition. cpp turns this into + * typedef struct FormData_pg_trigger + * + * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid, + * tgdeferrable, and tginitdeferred are largely redundant with the referenced + * pg_constraint entry. However, it is possible for a non-deferrable trigger + * to be associated with a deferrable constraint. + * ---------------- + */ +#define TriggerRelationId 2620 +#define TriggerRelation_Rowtype_Id 11329 + +CATALOG(pg_trigger,2620) BKI_SCHEMA_MACRO +{ + Oid tgrelid; /* relation trigger is attached to */ + NameData tgname; /* trigger's name */ + Oid tgfoid; /* OID of function to be called */ + int2 tgtype; /* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT, + * ROW/STATEMENT; see below */ + char tgenabled; /* trigger's firing configuration WRT + * session_replication_role */ + bool tgisinternal; /* trigger is system-generated */ + Oid tgconstrrelid; /* constraint's FROM table, if any */ + Oid tgconstrindid; /* constraint's supporting index, if any */ + Oid tgconstraint; /* associated pg_constraint entry, if any */ + bool tgdeferrable; /* constraint trigger is deferrable */ + bool tginitdeferred; /* constraint trigger is deferred initially */ + int2 tgnargs; /* # of extra arguments in tgargs */ + + /* + * Variable-length fields start here, but we allow direct access to + * tgattr. Note: tgattr and tgargs must not be null. + */ + int2vector tgattr; /* column numbers, if trigger is on columns */ + +#ifdef CATALOG_VARLEN + bytea tgargs; /* first\000second\000tgnargs\000 */ + pg_node_tree tgqual; /* WHEN expression, or NULL if none */ + Oid tgowner; /* trigger owner's oid */ +#endif +} FormData_pg_trigger; + +/* ---------------- + * Form_pg_trigger corresponds to a pointer to a tuple with + * the format of pg_trigger relation. + * ---------------- + */ +typedef FormData_pg_trigger *Form_pg_trigger; + +/* ---------------- + * compiler constants for pg_trigger + * ---------------- + */ +#define Natts_pg_trigger 16 +#define Anum_pg_trigger_tgrelid 1 +#define Anum_pg_trigger_tgname 2 +#define Anum_pg_trigger_tgfoid 3 +#define Anum_pg_trigger_tgtype 4 +#define Anum_pg_trigger_tgenabled 5 +#define Anum_pg_trigger_tgisinternal 6 +#define Anum_pg_trigger_tgconstrrelid 7 +#define Anum_pg_trigger_tgconstrindid 8 +#define Anum_pg_trigger_tgconstraint 9 +#define Anum_pg_trigger_tgdeferrable 10 +#define Anum_pg_trigger_tginitdeferred 11 +#define Anum_pg_trigger_tgnargs 12 +#define Anum_pg_trigger_tgattr 13 +#define Anum_pg_trigger_tgargs 14 +#define Anum_pg_trigger_tgqual 15 +#define Anum_pg_trigger_tgowner 16 + + +/* Bits within tgtype */ +#define TRIGGER_TYPE_ROW (1 << 0) +#define TRIGGER_TYPE_BEFORE (1 << 1) +#define TRIGGER_TYPE_INSERT (1 << 2) +#define TRIGGER_TYPE_DELETE (1 << 3) +#define TRIGGER_TYPE_UPDATE (1 << 4) +#define TRIGGER_TYPE_TRUNCATE (1 << 5) +#define TRIGGER_TYPE_INSTEAD (1 << 6) + +#define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW) +#define TRIGGER_TYPE_STATEMENT 0 + +/* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */ +#define TRIGGER_TYPE_TIMING_MASK \ + (TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD) +#define TRIGGER_TYPE_AFTER 0 + +#define TRIGGER_TYPE_EVENT_MASK \ + (TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE) + +/* Macros for manipulating tgtype */ +#define TRIGGER_CLEAR_TYPE(type) ((type) = 0) + +#define TRIGGER_SETT_ROW(type) ((type) |= TRIGGER_TYPE_ROW) +#define TRIGGER_SETT_STATEMENT(type) ((type) |= TRIGGER_TYPE_STATEMENT) +#define TRIGGER_SETT_BEFORE(type) ((type) |= TRIGGER_TYPE_BEFORE) +#define TRIGGER_SETT_AFTER(type) ((type) |= TRIGGER_TYPE_AFTER) +#define TRIGGER_SETT_INSTEAD(type) ((type) |= TRIGGER_TYPE_INSTEAD) +#define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT) +#define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE) +#define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE) +#define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE) + +#define TRIGGER_FOR_ROW(type) (((uint32)(type)) & TRIGGER_TYPE_ROW) +#define TRIGGER_FOR_BEFORE(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE) +#define TRIGGER_FOR_AFTER(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER) +#define TRIGGER_FOR_INSTEAD(type) ((((uint32)(type)) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD) +#define TRIGGER_FOR_INSERT(type) (((uint32)(type)) & TRIGGER_TYPE_INSERT) +#define TRIGGER_FOR_DELETE(type) (((uint32)(type)) & TRIGGER_TYPE_DELETE) +#define TRIGGER_FOR_UPDATE(type) (((uint32)(type)) & TRIGGER_TYPE_UPDATE) +#define TRIGGER_FOR_TRUNCATE(type) (((uint32)(type)) & TRIGGER_TYPE_TRUNCATE) + +/* + * Efficient macro for checking if tgtype matches a particular level + * (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE, + * TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT, + * TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE). Note + * that a tgtype can match more than one event, but only one level or timing. + */ +#define TRIGGER_TYPE_MATCHES(type, level, timing, event) \ + ((((uint32)type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | ((uint32)event))) == (((uint32)level) | ((uint32)timing) | ((uint32)event))) + +#endif /* PG_TRIGGER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_ts_config.h postgresql-hll-2.14/include/include/catalog/pg_ts_config.h --- postgresql-hll-2.14_old/include/include/catalog/pg_ts_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_ts_config.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_config.h + * definition of configuration of tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_config.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_CONFIG_H +#define PG_TS_CONFIG_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_config definition. cpp turns this into + * typedef struct FormData_pg_ts_config + * ---------------- + */ +#define TSConfigRelationId 3602 +#define TSConfigRelation_Rowtype_Id 11637 + +CATALOG(pg_ts_config,3602) BKI_SCHEMA_MACRO +{ + NameData cfgname; /* name of configuration */ + Oid cfgnamespace; /* name space */ + Oid cfgowner; /* owner */ + Oid cfgparser; /* OID of parser (in pg_ts_parser) */ + text cfoptions[1]; /* configuration options */ +} FormData_pg_ts_config; + +typedef FormData_pg_ts_config *Form_pg_ts_config; + +/* ---------------- + * compiler constants for pg_ts_config + * ---------------- + */ +#define Natts_pg_ts_config 5 +#define Anum_pg_ts_config_cfgname 1 +#define Anum_pg_ts_config_cfgnamespace 2 +#define Anum_pg_ts_config_cfgowner 3 +#define Anum_pg_ts_config_cfgparser 4 +#define Anum_pg_ts_config_cfoptions 5 + +/* ---------------- + * initial contents of pg_ts_config + * ---------------- + */ +DATA(insert OID = 3748 ( "simple" PGNSP PGUID 3722 _null_)); +DESCR("simple configuration"); +DATA(insert OID = 3791 ( "ngram" PGNSP PGUID 3789 _null_)); +DESCR("ngram configuration"); +DATA(insert OID = 3792 ( "zhparser" PGNSP PGUID 3790 _null_)); +DESCR("zhparser configuration"); +DATA(insert OID = 3793 ( "pound" PGNSP PGUID 3801 _null_)); +DESCR("pound configuration"); + + +#endif /* PG_TS_CONFIG_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_ts_config_map.h postgresql-hll-2.14/include/include/catalog/pg_ts_config_map.h --- postgresql-hll-2.14_old/include/include/catalog/pg_ts_config_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_ts_config_map.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_config_map.h + * definition of token mappings for configurations of tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_config_map.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_CONFIG_MAP_H +#define PG_TS_CONFIG_MAP_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_config_map definition. cpp turns this into + * typedef struct FormData_pg_ts_config_map + * ---------------- + */ +#define TSConfigMapRelationId 3603 +#define TSConfigMapRelation_Rowtype_Id 11638 + +CATALOG(pg_ts_config_map,3603) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid mapcfg; /* OID of configuration owning this entry */ + int4 maptokentype; /* token type from parser */ + int4 mapseqno; /* order in which to consult dictionaries */ + Oid mapdict; /* dictionary to consult */ +} FormData_pg_ts_config_map; + +typedef FormData_pg_ts_config_map *Form_pg_ts_config_map; + +/* ---------------- + * compiler constants for pg_ts_config_map + * ---------------- + */ +#define Natts_pg_ts_config_map 4 +#define Anum_pg_ts_config_map_mapcfg 1 +#define Anum_pg_ts_config_map_maptokentype 2 +#define Anum_pg_ts_config_map_mapseqno 3 +#define Anum_pg_ts_config_map_mapdict 4 + +/* ---------------- + * initial contents of pg_ts_config_map + * ---------------- + */ +DATA(insert (3748 1 1 3765)); +DATA(insert (3748 2 1 3765)); +DATA(insert (3748 3 1 3765)); +DATA(insert (3748 4 1 3765)); +DATA(insert (3748 5 1 3765)); +DATA(insert (3748 6 1 3765)); +DATA(insert (3748 7 1 3765)); +DATA(insert (3748 8 1 3765)); +DATA(insert (3748 9 1 3765)); +DATA(insert (3748 10 1 3765)); +DATA(insert (3748 11 1 3765)); +DATA(insert (3748 15 1 3765)); +DATA(insert (3748 16 1 3765)); +DATA(insert (3748 17 1 3765)); +DATA(insert (3748 18 1 3765)); +DATA(insert (3748 19 1 3765)); +DATA(insert (3748 20 1 3765)); +DATA(insert (3748 21 1 3765)); +DATA(insert (3748 22 1 3765)); + +#endif /* PG_TS_CONFIG_MAP_H */ + + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_ts_dict.h postgresql-hll-2.14/include/include/catalog/pg_ts_dict.h --- postgresql-hll-2.14_old/include/include/catalog/pg_ts_dict.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_ts_dict.h 2020-12-12 17:06:43.165346980 +0800 @@ -0,0 +1,69 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_dict.h + * definition of dictionaries for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_dict.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_DICT_H +#define PG_TS_DICT_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_dict definition. cpp turns this into + * typedef struct FormData_pg_ts_dict + * ---------------- + */ +#define TSDictionaryRelationId 3600 +#define TSDictionaryRelation_Rowtype_Id 11639 + +CATALOG(pg_ts_dict,3600) BKI_SCHEMA_MACRO +{ + NameData dictname; /* dictionary name */ + Oid dictnamespace; /* name space */ + Oid dictowner; /* owner */ + Oid dicttemplate; /* dictionary's template */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text dictinitoption; /* options passed to dict_init() */ +#endif +} FormData_pg_ts_dict; + +typedef FormData_pg_ts_dict *Form_pg_ts_dict; + +/* ---------------- + * compiler constants for pg_ts_dict + * ---------------- + */ +#define Natts_pg_ts_dict 5 +#define Anum_pg_ts_dict_dictname 1 +#define Anum_pg_ts_dict_dictnamespace 2 +#define Anum_pg_ts_dict_dictowner 3 +#define Anum_pg_ts_dict_dicttemplate 4 +#define Anum_pg_ts_dict_dictinitoption 5 + +/* ---------------- + * initial contents of pg_ts_dict + * ---------------- + */ + +DATA(insert OID = 3765 ( "simple" PGNSP PGUID 3727 _null_)); +DESCR("simple dictionary: just lower case and check for stopword"); + +#endif /* PG_TS_DICT_H */ + + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_ts_parser.h postgresql-hll-2.14/include/include/catalog/pg_ts_parser.h --- postgresql-hll-2.14_old/include/include/catalog/pg_ts_parser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_ts_parser.h 2020-12-12 17:06:43.166346993 +0800 @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_parser.h + * definition of parsers for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_parser.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_PARSER_H +#define PG_TS_PARSER_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_parser definition. cpp turns this into + * typedef struct FormData_pg_ts_parser + * ---------------- + */ +#define TSParserRelationId 3601 +#define TSParserRelation_Rowtype_Id 11640 + +CATALOG(pg_ts_parser,3601) BKI_SCHEMA_MACRO +{ + NameData prsname; /* parser's name */ + Oid prsnamespace; /* name space */ + regproc prsstart; /* init parsing session */ + regproc prstoken; /* return next token */ + regproc prsend; /* finalize parsing session */ + regproc prsheadline; /* return data for headline creation */ + regproc prslextype; /* return descriptions of lexeme's types */ +} FormData_pg_ts_parser; + +typedef FormData_pg_ts_parser *Form_pg_ts_parser; + +/* ---------------- + * compiler constants for pg_ts_parser + * ---------------- + */ +#define Natts_pg_ts_parser 7 +#define Anum_pg_ts_parser_prsname 1 +#define Anum_pg_ts_parser_prsnamespace 2 +#define Anum_pg_ts_parser_prsstart 3 +#define Anum_pg_ts_parser_prstoken 4 +#define Anum_pg_ts_parser_prsend 5 +#define Anum_pg_ts_parser_prsheadline 6 +#define Anum_pg_ts_parser_prslextype 7 + +/* ---------------- + * initial contents of pg_ts_parser + * ---------------- + */ + +DATA(insert OID = 3722 ( "default" PGNSP prsd_start prsd_nexttoken prsd_end prsd_headline prsd_lextype )); +DESCR("default word parser"); + +DATA(insert OID = 3789 ( "ngram" PGNSP ngram_start ngram_nexttoken ngram_end prsd_headline ngram_lextype )); +DESCR("ngram chinese word parser"); +#define NGRAM_PARSER 3789 + +DATA(insert OID = 3790 ( "zhparser" PGNSP zhprs_start zhprs_getlexeme zhprs_end prsd_headline zhprs_lextype )); +DESCR("zhparser chinese word parser"); +#define ZHPARSER_PARSER 3790 + +DATA(insert OID = 3801 ( "pound" PGNSP pound_start pound_nexttoken pound_end prsd_headline pound_lextype )); +DESCR(" pound split parser"); +#define POUND_PARSER 3801 + +#endif /* PG_TS_PARSER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_ts_template.h postgresql-hll-2.14/include/include/catalog/pg_ts_template.h --- postgresql-hll-2.14_old/include/include/catalog/pg_ts_template.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_ts_template.h 2020-12-12 17:06:43.166346993 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pg_ts_template.h + * definition of dictionary templates for tsearch + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_ts_template.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * XXX do NOT break up DATA() statements into multiple lines! + * the scripts are not as smart as you might think... + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TS_TEMPLATE_H +#define PG_TS_TEMPLATE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_ts_template definition. cpp turns this into + * typedef struct FormData_pg_ts_template + * ---------------- + */ +#define TSTemplateRelationId 3764 +#define TSTemplateRelation_Rowtype_Id 11641 + +CATALOG(pg_ts_template,3764) BKI_SCHEMA_MACRO +{ + NameData tmplname; /* template name */ + Oid tmplnamespace; /* name space */ + regproc tmplinit; /* initialization method of dict (may be 0) */ + regproc tmpllexize; /* base method of dictionary */ +} FormData_pg_ts_template; + +typedef FormData_pg_ts_template *Form_pg_ts_template; + +/* ---------------- + * compiler constants for pg_ts_template + * ---------------- + */ +#define Natts_pg_ts_template 4 +#define Anum_pg_ts_template_tmplname 1 +#define Anum_pg_ts_template_tmplnamespace 2 +#define Anum_pg_ts_template_tmplinit 3 +#define Anum_pg_ts_template_tmpllexize 4 + +/* ---------------- + * initial contents of pg_ts_template + * ---------------- + */ + +DATA(insert OID = 3727 ( "simple" PGNSP dsimple_init dsimple_lexize )); +DESCR("simple dictionary: just lower case and check for stopword"); +DATA(insert OID = 3730 ( "synonym" PGNSP dsynonym_init dsynonym_lexize )); +DESCR("synonym dictionary: replace word by its synonym"); +#define TSTemplateSynonymId 3730 +DATA(insert OID = 3733 ( "ispell" PGNSP dispell_init dispell_lexize )); +DESCR("ispell dictionary"); +#define TSTemplateIspellId 3733 +DATA(insert OID = 3742 ( "thesaurus" PGNSP thesaurus_init thesaurus_lexize )); +DESCR("thesaurus dictionary: phrase by phrase substitution"); +#define TSTemplateThesaurusId 3742 + +#endif /* PG_TS_TEMPLATE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_type_fn.h postgresql-hll-2.14/include/include/catalog/pg_type_fn.h --- postgresql-hll-2.14_old/include/include/catalog/pg_type_fn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_type_fn.h 2020-12-12 17:06:43.166346993 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_type_fn.h + * prototypes for functions in catalog/pg_type.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_type_fn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TYPE_FN_H +#define PG_TYPE_FN_H + +#include "nodes/nodes.h" + + +extern Oid TypeShellMake(const char *typname, + Oid typeNamespace, + Oid ownerId); + +extern Oid TypeCreate(Oid newTypeOid, + const char *typname, + Oid typeNamespace, + Oid relationOid, + char relationKind, + Oid ownerId, + int16 internalSize, + char typeType, + char typeCategory, + bool typePreferred, + char typDelim, + Oid inputProcedure, + Oid outputProcedure, + Oid receiveProcedure, + Oid sendProcedure, + Oid typmodinProcedure, + Oid typmodoutProcedure, + Oid analyzeProcedure, + Oid elementType, + bool isImplicitArray, + Oid arrayType, + Oid baseType, + const char *defaultTypeValue, + char *defaultTypeBin, + bool passedByValue, + char alignment, + char storage, + int32 typeMod, + int32 typNDims, + bool typeNotNull, + Oid typeCollation); + +extern void GenerateTypeDependencies(Oid typeNamespace, + Oid typeObjectId, + Oid relationOid, + char relationKind, + Oid owner, + Oid inputProcedure, + Oid outputProcedure, + Oid receiveProcedure, + Oid sendProcedure, + Oid typmodinProcedure, + Oid typmodoutProcedure, + Oid analyzeProcedure, + Oid elementType, + bool isImplicitArray, + Oid baseType, + Oid typeCollation, + Node *defaultExpr, + bool rebuild); + +extern void RenameTypeInternal(Oid typeOid, + const char *newTypeName, + Oid typeNamespace); + +extern char *makeArrayTypeName(const char *typname, Oid typeNamespace); + +extern bool moveArrayTypeName(Oid typeOid, + const char *typname, + Oid typeNamespace); + +#endif /* PG_TYPE_FN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_type.h postgresql-hll-2.14/include/include/catalog/pg_type.h --- postgresql-hll-2.14_old/include/include/catalog/pg_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_type.h 2020-12-12 17:06:43.166346993 +0800 @@ -0,0 +1,798 @@ +/* ------------------------------------------------------------------------- + * + * pg_type.h + * definition of the system "type" relation (pg_type) + * along with the relation's initial contents. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_type.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_TYPE_H +#define PG_TYPE_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_type definition. cpp turns this into + * typedef struct FormData_pg_type + * + * Some of the values in a pg_type instance are copied into + * pg_attribute instances. Some parts of Postgres use the pg_type copy, + * while others use the pg_attribute copy, so they must match. + * See struct FormData_pg_attribute for details. + * ---------------- + */ +#define TypeRelationId 1247 +#define TypeRelation_Rowtype_Id 71 + +CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71) BKI_SCHEMA_MACRO +{ + NameData typname; /* type name */ + Oid typnamespace; /* OID of namespace containing this type */ + Oid typowner; /* type owner */ + + /* + * For a fixed-size type, typlen is the number of bytes we use to + * represent a value of this type, e.g. 4 for an int4. But for a + * variable-length type, typlen is negative. We use -1 to indicate a + * "varlena" type (one that has a length word), -2 to indicate a + * null-terminated C string. + */ + int2 typlen; + + /* + * typbyval determines whether internal Postgres routines pass a value of + * this type by value or by reference. typbyval had better be FALSE if + * the length is not 1, 2, or 4 (or 8 on 8-byte-Datum machines). + * Variable-length types are always passed by reference. Note that + * typbyval can be false even if the length would allow pass-by-value; + * this is currently true for type float4, for example. + */ + bool typbyval; + + /* + * typtype is 'b' for a base type, 'c' for a composite type (e.g., a + * table's rowtype), 'd' for a domain, 'e' for an enum type, 'p' for a + * pseudo-type, or 'r' for a range type. (Use the TYPTYPE macros below.) + * + * If typtype is 'c', typrelid is the OID of the class' entry in pg_class. + */ + char typtype; + + /* + * typcategory and typispreferred help the parser distinguish preferred + * and non-preferred coercions. The category can be any single ASCII + * character (but not \0). The categories used for built-in types are + * identified by the TYPCATEGORY macros below. + */ + char typcategory; /* arbitrary type classification */ + + bool typispreferred; /* is type "preferred" within its category? */ + + /* + * If typisdefined is false, the entry is only a placeholder (forward + * reference). We know the type name, but not yet anything else about it. + */ + bool typisdefined; + + char typdelim; /* delimiter for arrays of this type */ + + Oid typrelid; /* 0 if not a composite type */ + + /* + * If typelem is not 0 then it identifies another row in pg_type. The + * current type can then be subscripted like an array yielding values of + * type typelem. A non-zero typelem does not guarantee this type to be a + * "real" array type; some ordinary fixed-length types can also be + * subscripted (e.g., name, point). Variable-length types can *not* be + * turned into pseudo-arrays like that. Hence, the way to determine + * whether a type is a "true" array type is if: + * + * typelem != 0 and typlen == -1. + */ + Oid typelem; + + /* + * If there is a "true" array type having this type as element type, + * typarray links to it. Zero if no associated "true" array type. + */ + Oid typarray; + + /* + * I/O conversion procedures for the datatype. + */ + regproc typinput; /* text format (required) */ + regproc typoutput; + regproc typreceive; /* binary format (optional) */ + regproc typsend; + + /* + * I/O functions for optional type modifiers. + */ + regproc typmodin; + regproc typmodout; + + /* + * Custom ANALYZE procedure for the datatype (0 selects the default). + */ + regproc typanalyze; + + /* ---------------- + * typalign is the alignment required when storing a value of this + * type. It applies to storage on disk as well as most + * representations of the value inside Postgres. When multiple values + * are stored consecutively, such as in the representation of a + * complete row on disk, padding is inserted before a datum of this + * type so that it begins on the specified boundary. The alignment + * reference is the beginning of the first datum in the sequence. + * + * 'c' = CHAR alignment, ie no alignment needed. + * 's' = SHORT alignment (2 bytes on most machines). + * 'i' = INT alignment (4 bytes on most machines). + * 'd' = DOUBLE alignment (8 bytes on many machines, but by no means all). + * + * See include/access/tupmacs.h for the macros that compute these + * alignment requirements. Note also that we allow the nominal alignment + * to be violated when storing "packed" varlenas; the TOAST mechanism + * takes care of hiding that from most code. + * + * NOTE: for types used in system tables, it is critical that the + * size and alignment defined in pg_type agree with the way that the + * compiler will lay out the field in a struct representing a table row. + * ---------------- + */ + char typalign; + + /* ---------------- + * typstorage tells if the type is prepared for toasting and what + * the default strategy for attributes of this type should be. + * + * 'p' PLAIN type not prepared for toasting + * 'e' EXTERNAL external storage possible, don't try to compress + * 'x' EXTENDED try to compress and store external if required + * 'm' MAIN like 'x' but try to keep in main tuple + * ---------------- + */ + char typstorage; + + /* + * This flag represents a "NOT NULL" constraint against this datatype. + * + * If true, the attnotnull column for a corresponding table column using + * this datatype will always enforce the NOT NULL constraint. + * + * Used primarily for domain types. + */ + bool typnotnull; + + /* + * Domains use typbasetype to show the base (or domain) type that the + * domain is based on. Zero if the type is not a domain. + */ + Oid typbasetype; + + /* + * Domains use typtypmod to record the typmod to be applied to their base + * type (-1 if base type does not use a typmod). -1 if this type is not a + * domain. + */ + int4 typtypmod; + + /* + * typndims is the declared number of dimensions for an array domain type + * (i.e., typbasetype is an array type). Otherwise zero. + */ + int4 typndims; + + /* + * Collation: 0 if type cannot use collations, DEFAULT_COLLATION_OID for + * collatable base types, possibly other OID for domains + */ + Oid typcollation; + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + + /* + * If typdefaultbin is not NULL, it is the nodeToString representation of + * a default expression for the type. Currently this is only used for + * domains. + */ + pg_node_tree typdefaultbin; + + /* + * typdefault is NULL if the type has no associated default value. If + * typdefaultbin is not NULL, typdefault must contain a human-readable + * version of the default expression represented by typdefaultbin. If + * typdefaultbin is NULL and typdefault is not, then typdefault is the + * external representation of the type's default value, which may be fed + * to the type's input converter to produce a constant. + */ + text typdefault; + + /* + * Access permissions + */ + aclitem typacl[1]; +#endif +} FormData_pg_type; + +/* ---------------- + * Form_pg_type corresponds to a pointer to a row with + * the format of pg_type relation. + * ---------------- + */ +typedef FormData_pg_type *Form_pg_type; + +/* ---------------- + * compiler constants for pg_type + * ---------------- + */ +#define Natts_pg_type 30 +#define Anum_pg_type_typname 1 +#define Anum_pg_type_typnamespace 2 +#define Anum_pg_type_typowner 3 +#define Anum_pg_type_typlen 4 +#define Anum_pg_type_typbyval 5 +#define Anum_pg_type_typtype 6 +#define Anum_pg_type_typcategory 7 +#define Anum_pg_type_typispreferred 8 +#define Anum_pg_type_typisdefined 9 +#define Anum_pg_type_typdelim 10 +#define Anum_pg_type_typrelid 11 +#define Anum_pg_type_typelem 12 +#define Anum_pg_type_typarray 13 +#define Anum_pg_type_typinput 14 +#define Anum_pg_type_typoutput 15 +#define Anum_pg_type_typreceive 16 +#define Anum_pg_type_typsend 17 +#define Anum_pg_type_typmodin 18 +#define Anum_pg_type_typmodout 19 +#define Anum_pg_type_typanalyze 20 +#define Anum_pg_type_typalign 21 +#define Anum_pg_type_typstorage 22 +#define Anum_pg_type_typnotnull 23 +#define Anum_pg_type_typbasetype 24 +#define Anum_pg_type_typtypmod 25 +#define Anum_pg_type_typndims 26 +#define Anum_pg_type_typcollation 27 +#define Anum_pg_type_typdefaultbin 28 +#define Anum_pg_type_typdefault 29 +#define Anum_pg_type_typacl 30 + + +/* ---------------- + * initial contents of pg_type + * ---------------- + */ + +/* + * Keep the following ordered by OID so that later changes can be made more + * easily. + * + * For types used in the system catalogs, make sure the values here match + * TypInfo[] in bootstrap.c. + */ + +/* OIDS 1 - 99 */ +DATA(insert OID = 16 ( bool PGNSP PGUID 1 t b B t t \054 0 0 1000 boolin boolout boolrecv boolsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("boolean, 'true'/'false'"); +#define BOOLOID 16 + +DATA(insert OID = 17 ( bytea PGNSP PGUID -1 f b U f t \054 0 0 1001 byteain byteaout bytearecv byteasend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length string, binary values escaped"); +#define BYTEAOID 17 + +DATA(insert OID = 18 ( char PGNSP PGUID 1 t b S f t \054 0 0 1002 charin charout charrecv charsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("single character"); +#define CHAROID 18 + +DATA(insert OID = 19 ( name PGNSP PGUID NAMEDATALEN f b S f t \054 0 18 1003 namein nameout namerecv namesend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("63-byte type for storing system identifiers"); +#define NAMEOID 19 + +DATA(insert OID = 20 ( int8 PGNSP PGUID 8 FLOAT8PASSBYVAL b N f t \054 0 0 1016 int8in int8out int8recv int8send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("~18 digit integer, 8-byte storage"); +#define INT8OID 20 + +DATA(insert OID = 21 ( int2 PGNSP PGUID 2 t b N f t \054 0 0 1005 int2in int2out int2recv int2send - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("-32 thousand to 32 thousand, 2-byte storage"); +#define INT2OID 21 + +DATA(insert OID = 5545 ( int1 PGNSP PGUID 1 t b N f t \054 0 0 5546 int1in int1out int1recv int1send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("0 to 255, 1-byte storage"); +#define INT1OID 5545 +DATA(insert OID = 22 ( int2vector PGNSP PGUID -1 f b A f t \054 0 21 1006 int2vectorin int2vectorout int2vectorrecv int2vectorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of int2, used in system tables"); +#define INT2VECTOROID 22 + +DATA(insert OID = 23 ( int4 PGNSP PGUID 4 t b N f t \054 0 0 1007 int4in int4out int4recv int4send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("-2 billion to 2 billion integer, 4-byte storage"); +#define INT4OID 23 + +DATA(insert OID = 24 ( regproc PGNSP PGUID 4 t b N f t \054 0 0 1008 regprocin regprocout regprocrecv regprocsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered procedure"); +#define REGPROCOID 24 + +DATA(insert OID = 25 ( text PGNSP PGUID -1 f b S t t \054 0 0 1009 textin textout textrecv textsend - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("variable-length string, no limit specified"); +#define TEXTOID 25 + +DATA(insert OID = 26 ( oid PGNSP PGUID 4 t b N t t \054 0 0 1028 oidin oidout oidrecv oidsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("object identifier(oid), maximum 4 billion"); +#define OIDOID 26 + +DATA(insert OID = 27 ( tid PGNSP PGUID 6 f b U f t \054 0 0 1010 tidin tidout tidrecv tidsend - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("(block, offset), physical location of tuple"); +#define TIDOID 27 +#define TID_TYPE_LEN 6 + +DATA(insert OID = 28 ( xid PGNSP PGUID 8 FLOAT8PASSBYVAL b U f t \054 0 0 1011 xidin xidout xidrecv xidsend - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("transaction id"); +#define XIDOID 28 + +DATA(insert OID = 31 ( xid32 PGNSP PGUID 4 t b U f t \054 0 0 1029 xidin4 xidout4 xidrecv4 xidsend4 - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("short transaction id"); +#define SHORTXIDOID 31 + +DATA(insert OID = 29 ( cid PGNSP PGUID 4 t b U f t \054 0 0 1012 cidin cidout cidrecv cidsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("command identifier type, sequence in transaction id"); +#define CIDOID 29 + +DATA(insert OID = 30 ( oidvector PGNSP PGUID -1 f b A f t \054 0 26 1013 oidvectorin oidvectorout oidvectorrecv oidvectorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of oids, used in system tables"); +#define OIDVECTOROID 30 + +DATA(insert OID = 32 ( oidvector_extend PGNSP PGUID -1 f b A f t \054 0 26 1013 oidvectorin_extend oidvectorout_extend oidvectorrecv_extend oidvectorsend_extend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("array of oids, used in system tables and support toast storage"); +#define OIDVECTOREXTENDOID 32 + +DATA(insert OID = 86 ( raw PGNSP PGUID -1 f b U f t \054 0 0 87 rawin rawout rawrecv rawsend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length string, binary values escaped"); +#define RAWOID 86 +DATA(insert OID = 87 ( _raw PGNSP PGUID -1 f b A f t \054 0 86 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 88 ( blob PGNSP PGUID -1 f b U f t \054 0 0 3201 rawin rawout bytearecv byteasend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BLOBOID 88 +DATA(insert OID = 3201 ( _blob PGNSP PGUID -1 f b A f t \054 0 88 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 90 ( clob PGNSP PGUID -1 f b S t t \054 0 0 3202 textin textout textrecv textsend - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define CLOBOID 90 +DATA(insert OID = 3202 ( _clob PGNSP PGUID -1 f b A f t \054 0 90 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); + +/* hand-built rowtype entries for bootstrapped catalogs */ +/* NB: OIDs assigned here must match the BKI_ROWTYPE_OID declarations */ + +DATA(insert OID = 71 ( pg_type PGNSP PGUID -1 f c C f t \054 1247 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 75 ( pg_attribute PGNSP PGUID -1 f c C f t \054 1249 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 81 ( pg_proc PGNSP PGUID -1 f c C f t \054 1255 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 83 ( pg_class PGNSP PGUID -1 f c C f t \054 1259 0 0 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* OIDS 100 - 199 */ +DATA(insert OID = 114 ( json PGNSP PGUID -1 f b U f t \054 0 0 199 json_in json_out json_recv json_send - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define JSONOID 114 +DATA(insert OID = 142 ( xml PGNSP PGUID -1 f b U f t \054 0 0 143 xml_in xml_out xml_recv xml_send - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("XML content"); +#define XMLOID 142 +DATA(insert OID = 143 ( _xml PGNSP PGUID -1 f b A f t \054 0 142 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 199 ( _json PGNSP PGUID -1 f b A f t \054 0 114 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 194 ( pg_node_tree PGNSP PGUID -1 f b S f t \054 0 0 0 pg_node_tree_in pg_node_tree_out pg_node_tree_recv pg_node_tree_send - - - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("string representing an internal node tree"); +#define PGNODETREEOID 194 + +/* OIDS 200 - 299 */ + +DATA(insert OID = 210 ( smgr PGNSP PGUID 2 t b U f t \054 0 0 0 smgrin smgrout - - - - - s p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("storage manager"); +#define SMGROID 210 + +/* OIDS 300 - 399 */ + +/* OIDS 400 - 499 */ + +/* OIDS 500 - 599 */ + +/* OIDS 600 - 699 */ +DATA(insert OID = 600 ( point PGNSP PGUID 16 f b G f t \054 0 701 1017 point_in point_out point_recv point_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric point '(x, y)'"); +#define POINTOID 600 +DATA(insert OID = 601 ( lseg PGNSP PGUID 32 f b G f t \054 0 600 1018 lseg_in lseg_out lseg_recv lseg_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric line segment '(pt1,pt2)'"); +#define LSEGOID 601 +DATA(insert OID = 602 ( path PGNSP PGUID -1 f b G f t \054 0 0 1019 path_in path_out path_recv path_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric path '(pt1,...)'"); +#define PATHOID 602 +DATA(insert OID = 603 ( box PGNSP PGUID 32 f b G f t \073 0 600 1020 box_in box_out box_recv box_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric box '(lower left,upper right)'"); +#define BOXOID 603 +DATA(insert OID = 604 ( polygon PGNSP PGUID -1 f b G f t \054 0 0 1027 poly_in poly_out poly_recv poly_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric polygon '(pt1,...)'"); +#define POLYGONOID 604 + +DATA(insert OID = 628 ( line PGNSP PGUID 32 f b G f t \054 0 701 629 line_in line_out line_recv line_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric line (not implemented)"); +#define LINEOID 628 +DATA(insert OID = 629 ( _line PGNSP PGUID -1 f b A f t \054 0 628 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR(""); + +/* OIDS 700 - 799 */ + +DATA(insert OID = 700 ( float4 PGNSP PGUID 4 FLOAT4PASSBYVAL b N f t \054 0 0 1021 float4in float4out float4recv float4send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("single-precision floating point number, 4-byte storage"); +#define FLOAT4OID 700 +DATA(insert OID = 701 ( float8 PGNSP PGUID 8 FLOAT8PASSBYVAL b N t t \054 0 0 1022 float8in float8out float8recv float8send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("double-precision floating point number, 8-byte storage"); +#define FLOAT8OID 701 +DATA(insert OID = 702 ( abstime PGNSP PGUID 4 t b D f t \054 0 0 1023 abstimein abstimeout abstimerecv abstimesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("absolute, limited-range date and time (Unix system time)"); +#define ABSTIMEOID 702 +DATA(insert OID = 703 ( reltime PGNSP PGUID 4 t b T f t \054 0 0 1024 reltimein reltimeout reltimerecv reltimesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("relative, limited-range time interval (Unix delta time)"); +#define RELTIMEOID 703 +DATA(insert OID = 704 ( tinterval PGNSP PGUID 12 f b T f t \054 0 0 1025 tintervalin tintervalout tintervalrecv tintervalsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("(abstime,abstime), time interval"); +#define TINTERVALOID 704 +DATA(insert OID = 705 ( unknown PGNSP PGUID -2 f b X f t \054 0 0 0 unknownin unknownout unknownrecv unknownsend - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR(""); +#define UNKNOWNOID 705 + +DATA(insert OID = 718 ( circle PGNSP PGUID 24 f b G f t \054 0 0 719 circle_in circle_out circle_recv circle_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("geometric circle '(center,radius)'"); +#define CIRCLEOID 718 +DATA(insert OID = 719 ( _circle PGNSP PGUID -1 f b A f t \054 0 718 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 790 ( money PGNSP PGUID 8 FLOAT8PASSBYVAL b N f t \054 0 0 791 cash_in cash_out cash_recv cash_send - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("monetary amounts, $d,ddd.cc"); +#define CASHOID 790 +DATA(insert OID = 791 ( _money PGNSP PGUID -1 f b A f t \054 0 790 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CASHARRAYOID 791 + +/* OIDS 800 - 899 */ +DATA(insert OID = 829 ( macaddr PGNSP PGUID 6 f b U f t \054 0 0 1040 macaddr_in macaddr_out macaddr_recv macaddr_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("XX:XX:XX:XX:XX:XX, MAC address"); +#define MACADDROID 829 +DATA(insert OID = 869 ( inet PGNSP PGUID -1 f b I t t \054 0 0 1041 inet_in inet_out inet_recv inet_send - - - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("IP address/netmask, host address, netmask optional"); +#define INETOID 869 +DATA(insert OID = 650 ( cidr PGNSP PGUID -1 f b I f t \054 0 0 651 cidr_in cidr_out cidr_recv cidr_send - - - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("network IP address/netmask, network address"); +#define CIDROID 650 + +/* OIDS 900 - 999 */ + +/* OIDS 1000 - 1099 */ +DATA(insert OID = 1000 ( _bool PGNSP PGUID -1 f b A f t \054 0 16 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BOOLARRAYOID 1000 +DATA(insert OID = 1001 ( _bytea PGNSP PGUID -1 f b A f t \054 0 17 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BYTEARRAYOID 1001 +DATA(insert OID = 1002 ( _char PGNSP PGUID -1 f b A f t \054 0 18 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CHARARRAYOID 1002 +DATA(insert OID = 1003 ( _name PGNSP PGUID -1 f b A f t \054 0 19 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define NAMEARRAYOID 1003 +DATA(insert OID = 1005 ( _int2 PGNSP PGUID -1 f b A f t \054 0 21 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT2ARRAYOID 1005 +DATA(insert OID = 5546 ( _int1 PGNSP PGUID -1 f b A f t \054 0 5545 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT1ARRAYOID 5546 +DATA(insert OID = 1006 ( _int2vector PGNSP PGUID -1 f b A f t \054 0 22 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1007 ( _int4 PGNSP PGUID -1 f b A f t \054 0 23 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT4ARRAYOID 1007 +DATA(insert OID = 1008 ( _regproc PGNSP PGUID -1 f b A f t \054 0 24 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1009 ( _text PGNSP PGUID -1 f b A f t \054 0 25 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define TEXTARRAYOID 1009 +DATA(insert OID = 1028 ( _oid PGNSP PGUID -1 f b A f t \054 0 26 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1010 ( _tid PGNSP PGUID -1 f b A f t \054 0 27 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1011 ( _xid PGNSP PGUID -1 f b A f t \054 0 28 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1029 ( _xid32 PGNSP PGUID -1 f b A f t \054 0 31 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1012 ( _cid PGNSP PGUID -1 f b A f t \054 0 29 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1013 ( _oidvector PGNSP PGUID -1 f b A f t \054 0 30 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1014 ( _bpchar PGNSP PGUID -1 f b A f t \054 0 1042 0 array_in array_out array_recv array_send bpchartypmodin bpchartypmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define BPCHARARRAYOID 1014 +DATA(insert OID = 1015 ( _varchar PGNSP PGUID -1 f b A f t \054 0 1043 0 array_in array_out array_recv array_send varchartypmodin varchartypmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define VARCHARARRAYOID 1015 +DATA(insert OID = 1016 ( _int8 PGNSP PGUID -1 f b A f t \054 0 20 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INT8ARRAYOID 1016 +DATA(insert OID = 1017 ( _point PGNSP PGUID -1 f b A f t \054 0 600 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1018 ( _lseg PGNSP PGUID -1 f b A f t \054 0 601 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1019 ( _path PGNSP PGUID -1 f b A f t \054 0 602 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1020 ( _box PGNSP PGUID -1 f b A f t \073 0 603 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1021 ( _float4 PGNSP PGUID -1 f b A f t \054 0 700 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define FLOAT4ARRAYOID 1021 +DATA(insert OID = 1022 ( _float8 PGNSP PGUID -1 f b A f t \054 0 701 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define FLOAT8ARRAYOID 1022 +DATA(insert OID = 1023 ( _abstime PGNSP PGUID -1 f b A f t \054 0 702 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ABSTIMEARRAYOID 1023 +DATA(insert OID = 1024 ( _reltime PGNSP PGUID -1 f b A f t \054 0 703 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RELTIMEARRAYOID 1024 +DATA(insert OID = 1025 ( _tinterval PGNSP PGUID -1 f b A f t \054 0 704 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYTINTERVALOID 1025 +DATA(insert OID = 1027 ( _polygon PGNSP PGUID -1 f b A f t \054 0 604 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1033 ( aclitem PGNSP PGUID 12 f b U f t \054 0 0 1034 aclitemin aclitemout - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("access control list"); +#define ACLITEMOID 1033 +DATA(insert OID = 1034 ( _aclitem PGNSP PGUID -1 f b A f t \054 0 1033 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ACLITEMARRAYOID 1034 +DATA(insert OID = 1040 ( _macaddr PGNSP PGUID -1 f b A f t \054 0 829 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 1041 ( _inet PGNSP PGUID -1 f b A f t \054 0 869 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define INETARRAYOID 1041 +DATA(insert OID = 651 ( _cidr PGNSP PGUID -1 f b A f t \054 0 650 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CIDRARRAYOID 651 +DATA(insert OID = 1263 ( _cstring PGNSP PGUID -1 f b A f t \054 0 2275 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define CSTRINGARRAYOID 1263 + +DATA(insert OID = 1042 ( bpchar PGNSP PGUID -1 f b S f t \054 0 0 1014 bpcharin bpcharout bpcharrecv bpcharsend bpchartypmodin bpchartypmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("char(length), blank-padded string, fixed storage length"); +#define BPCHAROID 1042 +DATA(insert OID = 1043 ( varchar PGNSP PGUID -1 f b S f t \054 0 0 1015 varcharin varcharout varcharrecv varcharsend varchartypmodin varchartypmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("varchar(length), non-blank-padded string, variable storage length"); +#define VARCHAROID 1043 + +DATA(insert OID = 3969 ( nvarchar2 PGNSP PGUID -1 f b S f t \054 0 0 3968 nvarchar2in nvarchar2out nvarchar2recv nvarchar2send nvarchar2typmodin nvarchar2typmodout - i x f 0 -1 0 100 _null_ _null_ _null_ )); +DESCR("nvarchar2(length), non-blank-padded string, variable storage length"); +#define NVARCHAR2OID 3969 +DATA(insert OID = 3968 ( _nvarchar2 PGNSP PGUID -1 f b A f t \054 0 3969 0 array_in array_out array_recv array_send nvarchar2typmodin nvarchar2typmodout array_typanalyze i x f 0 -1 0 100 _null_ _null_ _null_ )); +#define NVARCHAR2ARRAYOID 3968 + +DATA(insert OID = 1082 ( date PGNSP PGUID 4 t b D f t \054 0 0 1182 date_in date_out date_recv date_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date"); +#define DATEOID 1082 +DATA(insert OID = 1083 ( time PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 1183 time_in time_out time_recv time_send timetypmodin timetypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("time of day"); +#define TIMEOID 1083 + +/* OIDS 1100 - 1199 */ +DATA(insert OID = 1114 ( timestamp PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 1115 timestamp_in timestamp_out timestamp_recv timestamp_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time"); +#define TIMESTAMPOID 1114 +DATA(insert OID = 1115 ( _timestamp PGNSP PGUID -1 f b A f t \054 0 1114 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMESTAMPARRAYOID 1115 +DATA(insert OID = 1182 ( _date PGNSP PGUID -1 f b A f t \054 0 1082 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define DATEARRAYOID 1182 +DATA(insert OID = 1183 ( _time PGNSP PGUID -1 f b A f t \054 0 1083 0 array_in array_out array_recv array_send timetypmodin timetypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMEARRAYOID 1183 +DATA(insert OID = 1184 ( timestamptz PGNSP PGUID 8 FLOAT8PASSBYVAL b D t t \054 0 0 1185 timestamptz_in timestamptz_out timestamptz_recv timestamptz_send timestamptztypmodin timestamptztypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time with time zone"); +#define TIMESTAMPTZOID 1184 +DATA(insert OID = 1185 ( _timestamptz PGNSP PGUID -1 f b A f t \054 0 1184 0 array_in array_out array_recv array_send timestamptztypmodin timestamptztypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define TIMESTAMPTZARRAYOID 1185 +DATA(insert OID = 1186 ( interval PGNSP PGUID 16 f b T t t \054 0 0 1187 interval_in interval_out interval_recv interval_send intervaltypmodin intervaltypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("@ , time interval"); +#define INTERVALOID 1186 +DATA(insert OID = 1187 ( _interval PGNSP PGUID -1 f b A f t \054 0 1186 0 array_in array_out array_recv array_send intervaltypmodin intervaltypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYINTERVALOID 1187 +/* OIDS 1200 - 1299 */ +DATA(insert OID = 1231 ( _numeric PGNSP PGUID -1 f b A f t \054 0 1700 0 array_in array_out array_recv array_send numerictypmodin numerictypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYNUMERICOID 1231 + +DATA(insert OID = 1266 ( timetz PGNSP PGUID 12 f b D f t \054 0 0 1270 timetz_in timetz_out timetz_recv timetz_send timetztypmodin timetztypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("time of day with time zone"); +#define TIMETZOID 1266 +DATA(insert OID = 1270 ( _timetz PGNSP PGUID -1 f b A f t \054 0 1266 0 array_in array_out array_recv array_send timetztypmodin timetztypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ARRAYTIMETZOID 1270 + +/* OIDS 1500 - 1599 */ +DATA(insert OID = 1560 ( bit PGNSP PGUID -1 f b V f t \054 0 0 1561 bit_in bit_out bit_recv bit_send bittypmodin bittypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("fixed-length bit string"); +#define BITOID 1560 +DATA(insert OID = 1561 ( _bit PGNSP PGUID -1 f b A f t \054 0 1560 0 array_in array_out array_recv array_send bittypmodin bittypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define BITARRAYOID 1561 +DATA(insert OID = 1562 ( varbit PGNSP PGUID -1 f b V t t \054 0 0 1563 varbit_in varbit_out varbit_recv varbit_send varbittypmodin varbittypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("variable-length bit string"); +#define VARBITOID 1562 +DATA(insert OID = 1563 ( _varbit PGNSP PGUID -1 f b A f t \054 0 1562 0 array_in array_out array_recv array_send varbittypmodin varbittypmodout array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define VARBITARRAYOID 1563 + +/* OIDS 1600 - 1699 */ + +/* OIDS 1700 - 1799 */ +DATA(insert OID = 1700 ( numeric PGNSP PGUID -1 f b N f t \054 0 0 1231 numeric_in numeric_out numeric_recv numeric_send numerictypmodin numerictypmodout - i m f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("numeric(precision, decimal), arbitrary precision number"); +#define NUMERICOID 1700 + +DATA(insert OID = 1790 ( refcursor PGNSP PGUID -1 f b U f t \054 0 0 2201 textin textout textrecv textsend - - - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("reference to cursor (portal name)"); +#define REFCURSOROID 1790 + +/* OIDS 2200 - 2299 */ +DATA(insert OID = 2201 ( _refcursor PGNSP PGUID -1 f b A f t \054 0 1790 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 2202 ( regprocedure PGNSP PGUID 4 t b N f t \054 0 0 2207 regprocedurein regprocedureout regprocedurerecv regproceduresend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered procedure (with args)"); +#define REGPROCEDUREOID 2202 + +DATA(insert OID = 2203 ( regoper PGNSP PGUID 4 t b N f t \054 0 0 2208 regoperin regoperout regoperrecv regopersend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered operator"); +#define REGOPEROID 2203 + +DATA(insert OID = 2204 ( regoperator PGNSP PGUID 4 t b N f t \054 0 0 2209 regoperatorin regoperatorout regoperatorrecv regoperatorsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered operator (with args)"); +#define REGOPERATOROID 2204 + +DATA(insert OID = 2205 ( regclass PGNSP PGUID 4 t b N f t \054 0 0 2210 regclassin regclassout regclassrecv regclasssend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered class"); +#define REGCLASSOID 2205 + +DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regtypein regtypeout regtyperecv regtypesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered type"); +#define REGTYPEOID 2206 + +DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +#define REGTYPEARRAYOID 2211 + +/* uuid */ +DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("UUID datatype"); +#define UUIDOID 2950 + +DATA(insert OID = 2951 ( _uuid PGNSP PGUID -1 f b A f t \054 0 2950 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* text search */ +DATA(insert OID = 3614 ( tsvector PGNSP PGUID -1 f b U f t \054 0 0 3643 tsvectorin tsvectorout tsvectorrecv tsvectorsend - - ts_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("text representation for text search"); +#define TSVECTOROID 3614 +DATA(insert OID = 3642 ( gtsvector PGNSP PGUID -1 f b U f t \054 0 0 3644 gtsvectorin gtsvectorout - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("GiST index internal text representation for text search"); +#define GTSVECTOROID 3642 +DATA(insert OID = 3615 ( tsquery PGNSP PGUID -1 f b U f t \054 0 0 3645 tsqueryin tsqueryout tsqueryrecv tsquerysend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("query representation for text search"); +#define TSQUERYOID 3615 +DATA(insert OID = 3734 ( regconfig PGNSP PGUID 4 t b N f t \054 0 0 3735 regconfigin regconfigout regconfigrecv regconfigsend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered text search configuration"); +#define REGCONFIGOID 3734 +DATA(insert OID = 3769 ( regdictionary PGNSP PGUID 4 t b N f t \054 0 0 3770 regdictionaryin regdictionaryout regdictionaryrecv regdictionarysend - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("registered text search dictionary"); +#define REGDICTIONARYOID 3769 + +DATA(insert OID = 3643 ( _tsvector PGNSP PGUID -1 f b A f t \054 0 3614 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3644 ( _gtsvector PGNSP PGUID -1 f b A f t \054 0 3642 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3645 ( _tsquery PGNSP PGUID -1 f b A f t \054 0 3615 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3735 ( _regconfig PGNSP PGUID -1 f b A f t \054 0 3734 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3770 ( _regdictionary PGNSP PGUID -1 f b A f t \054 0 3769 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); + +DATA(insert OID = 2970 ( txid_snapshot PGNSP PGUID -1 f b U f t \054 0 0 2949 txid_snapshot_in txid_snapshot_out txid_snapshot_recv txid_snapshot_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("txid snapshot"); +DATA(insert OID = 2949 ( _txid_snapshot PGNSP PGUID -1 f b A f t \054 0 2970 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); + +/* range types */ +DATA(insert OID = 3904 ( int4range PGNSP PGUID -1 f r R f t \054 0 0 3905 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of integers"); +#define INT4RANGEOID 3904 +DATA(insert OID = 3905 ( _int4range PGNSP PGUID -1 f b A f t \054 0 3904 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3906 ( numrange PGNSP PGUID -1 f r R f t \054 0 0 3907 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of numerics"); +DATA(insert OID = 3907 ( _numrange PGNSP PGUID -1 f b A f t \054 0 3906 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3908 ( tsrange PGNSP PGUID -1 f r R f t \054 0 0 3909 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of timestamps without time zone"); +DATA(insert OID = 3909 ( _tsrange PGNSP PGUID -1 f b A f t \054 0 3908 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3910 ( tstzrange PGNSP PGUID -1 f r R f t \054 0 0 3911 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of timestamps with time zone"); +DATA(insert OID = 3911 ( _tstzrange PGNSP PGUID -1 f b A f t \054 0 3910 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3912 ( daterange PGNSP PGUID -1 f r R f t \054 0 0 3913 range_in range_out range_recv range_send - - range_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of dates"); +DATA(insert OID = 3913 ( _daterange PGNSP PGUID -1 f b A f t \054 0 3912 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DATA(insert OID = 3926 ( int8range PGNSP PGUID -1 f r R f t \054 0 0 3927 range_in range_out range_recv range_send - - range_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("range of bigints"); +DATA(insert OID = 3927 ( _int8range PGNSP PGUID -1 f b A f t \054 0 3926 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +/* + * pseudo-types + * + * types with typtype='p' represent various special cases in the type system. + * + * These cannot be used to define table columns, but are valid as function + * argument and result types (if supported by the function's implementation + * language). + * + * Note: cstring is a borderline case; it is still considered a pseudo-type, + * but there is now support for it in records and arrays. Perhaps we should + * just treat it as a regular base type? + */ +DATA(insert OID = 2249 ( record PGNSP PGUID -1 f p P f t \054 0 0 2287 record_in record_out record_recv record_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RECORDOID 2249 +DATA(insert OID = 2287 ( _record PGNSP PGUID -1 f p P f t \054 0 2249 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define RECORDARRAYOID 2287 +DATA(insert OID = 2275 ( cstring PGNSP PGUID -2 f p P f t \054 0 0 1263 cstring_in cstring_out cstring_recv cstring_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ )); +#define CSTRINGOID 2275 +DATA(insert OID = 2276 ( any PGNSP PGUID 4 t p P f t \054 0 0 0 any_in any_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYOID 2276 +DATA(insert OID = 2277 ( anyarray PGNSP PGUID -1 f p P f t \054 0 0 0 anyarray_in anyarray_out anyarray_recv anyarray_send - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYARRAYOID 2277 +DATA(insert OID = 2278 ( void PGNSP PGUID 4 t p P f t \054 0 0 0 void_in void_out void_recv void_send - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define VOIDOID 2278 +DATA(insert OID = 2279 ( trigger PGNSP PGUID 4 t p P f t \054 0 0 0 trigger_in trigger_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define TRIGGEROID 2279 +DATA(insert OID = 2280 ( language_handler PGNSP PGUID 4 t p P f t \054 0 0 0 language_handler_in language_handler_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define LANGUAGE_HANDLEROID 2280 +DATA(insert OID = 2281 ( internal PGNSP PGUID SIZEOF_POINTER t p P f t \054 0 0 0 internal_in internal_out - - - - - ALIGNOF_POINTER p f 0 -1 0 0 _null_ _null_ _null_ )); +#define INTERNALOID 2281 +DATA(insert OID = 2282 ( opaque PGNSP PGUID 4 t p P f t \054 0 0 0 opaque_in opaque_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define OPAQUEOID 2282 +DATA(insert OID = 2283 ( anyelement PGNSP PGUID 4 t p P f t \054 0 0 0 anyelement_in anyelement_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYELEMENTOID 2283 +DATA(insert OID = 2776 ( anynonarray PGNSP PGUID 4 t p P f t \054 0 0 0 anynonarray_in anynonarray_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYNONARRAYOID 2776 +DATA(insert OID = 3500 ( anyenum PGNSP PGUID 4 t p P f t \054 0 0 0 anyenum_in anyenum_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYENUMOID 3500 +DATA(insert OID = 3115 ( fdw_handler PGNSP PGUID 4 t p P f t \054 0 0 0 fdw_handler_in fdw_handler_out - - - - - i p f 0 -1 0 0 _null_ _null_ _null_ )); +#define FDW_HANDLEROID 3115 +DATA(insert OID = 3831 ( anyrange PGNSP PGUID -1 f p P f t \054 0 0 0 anyrange_in anyrange_out - - - - - d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define ANYRANGEOID 3831 +DATA(insert OID = 9003 ( smalldatetime PGNSP PGUID 8 FLOAT8PASSBYVAL b D f t \054 0 0 9005 smalldatetime_in smalldatetime_out smalldatetime_recv smalldatetime_send timestamptypmodin timestamptypmodout - d p f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("date and time"); +#define SMALLDATETIMEOID 9003 +DATA(insert OID = 9005 ( _smalldatetime PGNSP PGUID -1 f b A f t \054 0 9003 0 array_in array_out array_recv array_send timestamptypmodin timestamptypmodout array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +#define SMALLDATETIMEARRAYOID 9005 +DATA(insert OID = 4301 ( hll PGNSP PGUID -1 f b U f t \054 0 0 4302 hll_in hll_out hll_recv hll_send hll_typmod_in hll_typmod_out - i e f 0 -1 0 0 _null_ _null_ _null_ )); +#define HLL_OID 4301 +DESCR("hypper log log type"); +DATA(insert OID = 4302 ( _hll PGNSP PGUID -1 f p P f t \054 0 4301 0 array_in array_out array_recv array_send hll_typmod_in hll_typmod_out array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log array"); +#define HLL_ARRAYOID 4302 +DATA(insert OID = 4303 ( hll_hashval PGNSP PGUID 8 t p P f t \054 0 0 4304 hll_hashval_in hll_hashval_out - - - - - d p f 0 -1 0 0 _null_ _null_ _null_ )); +#define HLL_HASHVAL_OID 4303 +DESCR("hypper log log hashval"); +DATA(insert OID = 4304 ( _hll_hashval PGNSP PGUID -1 f p P f t \054 0 4303 0 array_in array_out array_recv array_send - - array_typanalyze d x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log hashval array"); +#define HLL_HASHVAL_ARRAYOID 4304 +DATA(insert OID = 4370 ( hll_trans_type PGNSP PGUID -1 f p P f t \054 0 0 4371 hll_trans_in hll_trans_out hll_trans_recv hll_trans_send - - - i e f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log internal type"); +DATA(insert OID = 4371 ( _hll_trans_type PGNSP PGUID -1 f p P f t \054 0 4370 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("hypper log log internal type"); + +DATA(insert OID = 4402 ( byteawithoutorderwithequalcol PGNSP PGUID -1 f b U f t \054 0 0 1001 byteawithoutorderwithequalcolin byteawithoutorderwithequalcolout byteawithoutorderwithequalcolrecv byteawithoutorderwithequalcolsend byteawithoutorderwithequalcoltypmodin byteawithoutorderwithequalcoltypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("encrypted data variable-length string, binary values escaped"); +#define BYTEAWITHOUTORDERWITHEQUALCOLOID 4402 + +DATA(insert OID = 4403 ( byteawithoutordercol PGNSP PGUID -1 f b U f t \054 0 0 1001 byteawithoutordercolin byteawithoutordercolout byteawithoutorderwithequalcolrecv byteawithoutorderwithequalcolsend byteawithoutorderwithequalcoltypmodin byteawithoutorderwithequalcoltypmodout - i x f 0 -1 0 0 _null_ _null_ _null_ )); +DESCR("encrypted data variable-length string, binary values escaped"); +#define BYTEAWITHOUTORDERCOLOID 4403 + +/* + * macros + */ +#define TYPTYPE_BASE 'b' /* base type (ordinary scalar type) */ +#define TYPTYPE_COMPOSITE 'c' /* composite (e.g., table's rowtype) */ +#define TYPTYPE_DOMAIN 'd' /* domain over another type */ +#define TYPTYPE_ENUM 'e' /* enumerated type */ +#define TYPTYPE_PSEUDO 'p' /* pseudo-type */ +#define TYPTYPE_RANGE 'r' /* range type */ + +#define TYPCATEGORY_INVALID '\0' /* not an allowed category */ +#define TYPCATEGORY_ARRAY 'A' +#define TYPCATEGORY_BOOLEAN 'B' +#define TYPCATEGORY_COMPOSITE 'C' +#define TYPCATEGORY_DATETIME 'D' +#define TYPCATEGORY_ENUM 'E' +#define TYPCATEGORY_GEOMETRIC 'G' +#define TYPCATEGORY_NETWORK 'I' /* think INET */ +#define TYPCATEGORY_NUMERIC 'N' +#define TYPCATEGORY_PSEUDOTYPE 'P' +#define TYPCATEGORY_RANGE 'R' +#define TYPCATEGORY_STRING 'S' +#define TYPCATEGORY_TIMESPAN 'T' +#define TYPCATEGORY_USER 'U' +#define TYPCATEGORY_BITSTRING 'V' /* er ... "varbit"? */ +#define TYPCATEGORY_UNKNOWN 'X' + +/* Is a type OID a polymorphic pseudotype? (Beware of multiple evaluation) */ +#define IsPolymorphicType(typid) \ + ((typid) == ANYELEMENTOID || \ + (typid) == ANYARRAYOID || \ + (typid) == ANYNONARRAYOID || \ + (typid) == ANYENUMOID || \ + (typid) == ANYRANGEOID) +#define IsClientLogicType(typid) \ +((typid) == BYTEAWITHOUTORDERCOLOID || \ +(typid) == BYTEAWITHOUTORDERWITHEQUALCOLOID) + +#endif /* PG_TYPE_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_user_mapping.h postgresql-hll-2.14/include/include/catalog/pg_user_mapping.h --- postgresql-hll-2.14_old/include/include/catalog/pg_user_mapping.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_user_mapping.h 2020-12-12 17:06:43.166346993 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * pg_user_mapping.h + * definition of the system "user mapping" relation (pg_user_mapping) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/pg_user_mapping.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_USER_MAPPING_H +#define PG_USER_MAPPING_H + +#include "catalog/genbki.h" + +/* ---------------- + * pg_user_mapping definition. cpp turns this into + * typedef struct FormData_pg_user_mapping + * ---------------- + */ +#define UserMappingRelationId 1418 +#define UserMappingRelation_Rowtype_Id 11647 + +CATALOG(pg_user_mapping,1418) BKI_SCHEMA_MACRO +{ + Oid umuser; /* Id of the user, InvalidOid if PUBLIC + * is wanted */ + Oid umserver; /* server of this mapping */ + +#ifdef CATALOG_VARLEN /* variable-length fields start here */ + text umoptions[1]; /* user mapping options */ +#endif +} FormData_pg_user_mapping; + +/* ---------------- + * Form_pg_user_mapping corresponds to a pointer to a tuple with + * the format of pg_user_mapping relation. + * ---------------- + */ +typedef FormData_pg_user_mapping *Form_pg_user_mapping; + +/* ---------------- + * compiler constants for pg_user_mapping + * ---------------- + */ +#define Natts_pg_user_mapping 3 +#define Anum_pg_user_mapping_umuser 1 +#define Anum_pg_user_mapping_umserver 2 +#define Anum_pg_user_mapping_umoptions 3 + +#endif /* PG_USER_MAPPING_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_user_status.h postgresql-hll-2.14/include/include/catalog/pg_user_status.h --- postgresql-hll-2.14_old/include/include/catalog/pg_user_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_user_status.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_user_status.h + * definition of the system "user status" relation (pg_user_status) + * along with the relation's initial contents. + * + * + * IDENTIFICATION + * src/include/catalog/pg_user_status.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_USER_STATUS_H +#define PG_USER_STATUS_H + +#include "catalog/genbki.h" + + +/* define the timestamptz for the locktime in pg_user_status */ +#define timestamptz Datum + +/* define the OID of the table pg_user_status */ +#define UserStatusRelationId 3460 +#define UserStatusRelation_Rowtype_Id 3463 + +CATALOG(pg_user_status,3460) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3463) BKI_SCHEMA_MACRO +{ + Oid roloid; /* role OID */ + int4 failcount; /* failed num of login attampts */ + timestamptz locktime; /* role lock time */ + int2 rolstatus; /* role status */ + int8 permspace; /* perm space */ + int8 tempspace; /* temp space */ + int2 passwordexpired; /* password expired status */ +} FormData_pg_user_status; + +#undef timestamptz + +/* ------------------------------------------------------------------------- + * Form_pg_user_status corresponds to a pointer to a tuple with + * the format of pg_user_status relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_user_status *Form_pg_user_status; + +/* ------------------------------------------------------------------------- + * compiler constants for pg_user_status + * ------------------------------------------------------------------------- + */ +#define Natts_pg_user_status 7 +#define Anum_pg_user_status_roloid 1 +#define Anum_pg_user_status_failcount 2 +#define Anum_pg_user_status_locktime 3 +#define Anum_pg_user_status_rolstatus 4 +#define Anum_pg_user_status_permspace 5 +#define Anum_pg_user_status_tempspace 6 +#define Anum_pg_user_status_passwordexpired 7 + +#endif /* PG_USER_STATUS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pg_workload_group.h postgresql-hll-2.14/include/include/catalog/pg_workload_group.h --- postgresql-hll-2.14_old/include/include/catalog/pg_workload_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pg_workload_group.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pg_workload_group.h + * define the system workload group information. + * + * + * IDENTIFICATION + * src/include/catalog/pg_workload_group.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PG_WORKLOAD_GROUP_H +#define PG_WORKLOAD_GROUP_H + +#include "catalog/genbki.h" +#include "catalog/pg_resource_pool.h" + + +/* define the OID of the table pg_workload_group */ +#define WorkloadGroupRelationId 3451 +#define WorkloadGroupRelation_Rowtype_Id 3467 + +CATALOG(pg_workload_group,3451) BKI_SHARED_RELATION BKI_ROWTYPE_OID(3467) BKI_SCHEMA_MACRO +{ + NameData workload_gpname; /* Name of worload group */ + Oid respool_oid; /* The oid of resource pool which the workload group is created under */ + int4 act_statements; /* The number of active statements */ +} FormData_pg_workload_group; + + +/*------------------------------------------------------------------------- + * Form_pg_workload_group corresponds to a pointer to a tuple with + * the format of pg_workload_group relation. + * ------------------------------------------------------------------------- + */ +typedef FormData_pg_workload_group *Form_pg_workload_group; + +/*------------------------------------------------------------------------- + * compiler constants for pg_workload_group + * ------------------------------------------------------------------------- + */ +#define Natts_pg_workload_group 3 +#define Anum_pg_workload_group_wgname 1 +#define Anum_pg_workload_group_rgoid 2 +#define Anum_pg_workload_group_acstatements 3 + +DATA(insert OID = 10 ( "default_group" 10 -1)); /* -1 means ulimited */ +#define DEFAULT_GROUP_OID 10 +#define DEFAULT_GROUP_NAME "default_group" +#define ULIMITED_ACTIVE_STATEMENTS -1 + +/* default setting for user defined workload group */ +#define DEFAULT_RESOURCE_POOL DEFAULT_POOL_OID +#define DEFAULT_ACTIVE_STATEMENTS -1 + +#endif /* PG_WORKLOAD_GROUP_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pgxc_class.h postgresql-hll-2.14/include/include/catalog/pgxc_class.h --- postgresql-hll-2.14_old/include/include/catalog/pgxc_class.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pgxc_class.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,81 @@ +/* ----------------------------------------------------------- + * + * Copyright (c) 2010-2013 Postgres-XC Development Group + * + * ----------------------------------------------------------- + */ +#ifndef PGXC_CLASS_H +#define PGXC_CLASS_H + +#include "nodes/parsenodes.h" + +#define PgxcClassRelationId 9001 +#define PgxcClassRelation_Rowtype_Id 11648 + +CATALOG(pgxc_class,9001) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + Oid pcrelid; /* Table Oid */ + char pclocatortype; /* Type of distribution */ + int2 pchashalgorithm; /* Hashing algorithm */ + int2 pchashbuckets; /* Number of buckets */ + NameData pgroup; /* Group name */ + char redistributed; /* relation is re-distributed */ + int4 redis_order; /* data redistribution order */ + + int2vector pcattnum; /* Column number of distribution */ + +#ifdef CATALOG_VARLEN + /* VARIABLE LENGTH FIELDS: */ + oidvector_extend nodeoids; /* List of nodes used by table */ + text options; /* Reserve column */ +#endif +} FormData_pgxc_class; + +typedef FormData_pgxc_class *Form_pgxc_class; + +#define Natts_pgxc_class 10 + +#define Anum_pgxc_class_pcrelid 1 +#define Anum_pgxc_class_pclocatortype 2 +#define Anum_pgxc_class_pchashalgorithm 3 +#define Anum_pgxc_class_pchashbuckets 4 +#define Anum_pgxc_class_pgroup 5 +#define Anum_pgxc_class_redistributed 6 +#define Anum_pgxc_class_redis_order 7 +#define Anum_pgxc_class_pcattnum 8 +#define Anum_pgxc_class_nodes 9 +#define Anum_pgxc_class_option 10 + +typedef enum PgxcClassAlterType { + PGXC_CLASS_ALTER_DISTRIBUTION, + PGXC_CLASS_ALTER_NODES, + PGXC_CLASS_ALTER_ALL +} PgxcClassAlterType; + +extern void PgxcClassCreate(Oid pcrelid, + char pclocatortype, + int2* pcattnum, + int pchashalgorithm, + int pchashbuckets, + int numnodes, + Oid *nodes, + int distributeNum, + const char *groupname); +extern void PgxcClassAlter(Oid pcrelid, + char pclocatortype, + int2 *pcattnum, + int numpcattnum, + int pchashalgorithm, + int pchashbuckets, + int numnodes, + Oid *nodes, + char ch_redis, + PgxcClassAlterType type, + const char *groupname); +extern void RemovePgxcClass(Oid pcrelid); +extern bool RelationRedisCheck(Relation rel); +extern void PgxcClassAlterForReloption(Oid pcrelid, const char* reloptionstr); +extern void PgxcClassCreateForReloption(Oid pcrelid, const char* reloptionstr); + +#endif /* PGXC_CLASS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pgxc_group.h postgresql-hll-2.14/include/include/catalog/pgxc_group.h --- postgresql-hll-2.14_old/include/include/catalog/pgxc_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pgxc_group.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,68 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_group.h + * definition of the system "PGXC group" relation (pgxc_group) + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/pgxc_group.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_GROUP_H +#define PGXC_GROUP_H + +#include "nodes/parsenodes.h" +#include "pgxc/groupmgr.h" + +#define PgxcGroupRelationId 9014 +#define PgxcGroupRelation_Rowtype_Id 11650 + +CATALOG(pgxc_group,9014) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData group_name; /* Group name */ + char in_redistribution; /* flag to determine if node group is under re-dsitribution */ + +#ifdef CATALOG_VARLEN + /* VARIABLE LENGTH FIELDS: */ + oidvector_extend group_members; /* Group members */ + text group_buckets; /* hash bucket location -- which node */ +#endif + + bool is_installation; /* flag to indicate if this nodegroup is installation nodegroup */ +#ifdef CATALOG_VARLEN + aclitem group_acl[1]; /* access permissions */ +#endif + char group_kind; /* Node group kind: 'v' ,'i','e','n' */ +} FormData_pgxc_group; + +typedef FormData_pgxc_group *Form_pgxc_group; + +#define Natts_pgxc_group 7 + +#define Anum_pgxc_group_name 1 +#define Anum_pgxc_group_in_redistribution 2 +#define Anum_pgxc_group_members 3 +#define Anum_pgxc_group_buckets 4 +#define Anum_pgxc_group_is_installation 5 +#define Anum_pgxc_group_group_acl 6 +#define Anum_pgxc_group_kind 7 + +#define PGXC_REDISTRIBUTION_SRC_GROUP 'y' +#define PGXC_REDISTRIBUTION_DST_GROUP 't' +#define PGXC_NON_REDISTRIBUTION_GROUP 'n' + +#define PGXC_GROUPKIND_INSTALLATION 'i' +#define PGXC_GROUPKIND_NODEGROUP 'n' +#define PGXC_GROUPKIND_LCGROUP 'v' +#define PGXC_GROUPKING_ELASTIC 'e' + +#endif /* PGXC_GROUP_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pgxc_node.h postgresql-hll-2.14/include/include/catalog/pgxc_node.h --- postgresql-hll-2.14_old/include/include/catalog/pgxc_node.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pgxc_node.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,135 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_node.h + * definition of the system "PGXC node" relation (pgxc_node) + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/pgxc_node.h + * + * NOTES + * the genbki.pl script reads this file and generates .bki + * information from the DATA() statements. + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_NODE_H +#define PGXC_NODE_H + +#include "catalog/genbki.h" + +#define PgxcNodeRelationId 9015 +#define PgxcNodeRelation_Rowtype_Id 11649 + +CATALOG(pgxc_node,9015) BKI_SHARED_RELATION BKI_SCHEMA_MACRO +{ + NameData node_name; + + /* + * Possible node types are defined as follows + * Types are defined below PGXC_NODES_XXXX + */ + char node_type; + + /* + * Port number of the node to connect to + */ + int4 node_port; + + /* + * Host name of IP address of the node to connect to + */ + NameData node_host; + + /* + * Port1 number of the node to connect to + */ + int4 node_port1; + + /* + * Host1 name of IP address of the node to connect to + */ + NameData node_host1; + + /* + * Is static config primary node primary + */ + bool hostis_primary; + + /* + * Is this node primary + */ + bool nodeis_primary; + + /* + * Is this node preferred + */ + bool nodeis_preferred; + + /* + * Node identifier to be used at places where a fixed length node identification is required + */ + int4 node_id; + + /* + * Sctp port start number of the data node to connect to each ohter + */ + int4 sctp_port; + + /* + * Stream control port start number of the data node to connect to each ohter + */ + int4 control_port; + + /* + * Sctp port1 number of the data node to connect to each ohter + */ + int4 sctp_port1; + + /* + * Stream control port start number of the data node to connect to each ohter + */ + int4 control_port1; + + bool nodeis_central; + + bool nodeis_active; +} FormData_pgxc_node; + +typedef FormData_pgxc_node *Form_pgxc_node; + +#define Natts_pgxc_node 16 + +#define Anum_pgxc_node_name 1 +#define Anum_pgxc_node_type 2 +#define Anum_pgxc_node_port 3 +#define Anum_pgxc_node_host 4 +#define Anum_pgxc_node_port1 5 +#define Anum_pgxc_node_host1 6 +#define Anum_pgxc_host_is_primary 7 +#define Anum_pgxc_node_is_primary 8 +#define Anum_pgxc_node_is_preferred 9 +#define Anum_pgxc_node_id 10 + +#define Anum_pgxc_node_sctp_port 11 +#define Anum_pgxc_node_strmctl_port 12 +#define Anum_pgxc_node_sctp_port1 13 +#define Anum_pgxc_node_strmctl_port1 14 + +#define Anum_pgxc_node_is_central 15 +#define Anum_pgxc_node_is_active 16 + +/* Possible types of nodes */ +#define PGXC_NODE_COORDINATOR 'C' +#define PGXC_NODE_DATANODE 'D' +#define PGXC_NODE_DATANODE_STANDBY 'S' +#define PGXC_NODE_NONE 'N' + +#define IS_DATA_NODE(type) ((type) == PGXC_NODE_DATANODE || (type) == PGXC_NODE_DATANODE_STANDBY) +#define IS_PRIMARY_DATA_NODE(type) ((type) == PGXC_NODE_DATANODE) + +#endif /* PGXC_NODE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/pgxc_slice.h postgresql-hll-2.14/include/include/catalog/pgxc_slice.h --- postgresql-hll-2.14_old/include/include/catalog/pgxc_slice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/pgxc_slice.h 2020-12-12 17:06:43.167347006 +0800 @@ -0,0 +1,82 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pgxc_slice.h + * system catalog table that storing slice information for list/range distributed table. + * + * + * IDENTIFICATION + * src/include/catalog/pgxc_slice.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PGXC_SLICE_H +#define PGXC_SLICE_H + +#include "access/tupdesc.h" +#include "catalog/genbki.h" +#include "nodes/primnodes.h" + +#define PgxcSliceRelationId 9035 +#define PgxcSliceRelation_Rowtype_Id 9032 + +CATALOG(pgxc_slice,9035) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO +{ + NameData relname; /* list/range distributed table name or slice name of the table */ + char type; + char strategy; + Oid relid; /* table oid */ + Oid referenceoid; /* table oid that slice referenced to */ + int4 sindex; + +#ifdef CATALOG_VARLEN + text interval[1]; + text transitboundary[1]; +#endif + int4 transitno; + Oid nodeoid; +#ifdef CATALOG_VARLEN + text boundaries[1]; +#endif + bool specified; /* whether nodeoid is specified by user in DDL */ + int4 sliceorder; +} FormData_pgxc_slice; + +typedef FormData_pgxc_slice *Form_pgxc_slice; + +#define Natts_pgxc_slice 13 +#define Anum_pgxc_slice_relname 1 +#define Anum_pgxc_slice_type 2 +#define Anum_pgxc_slice_strategy 3 +#define Anum_pgxc_slice_relid 4 +#define Anum_pgxc_slice_referenceoid 5 +#define Anum_pgxc_slice_sindex 6 +#define Anum_pgxc_slice_interval 7 +#define Anum_pgxc_slice_transitboundary 8 +#define Anum_pgxc_slice_transitno 9 +#define Anum_pgxc_slice_nodeoid 10 +#define Anum_pgxc_slice_boundaries 11 +#define Anum_pgxc_slice_specified 12 +#define Anum_pgxc_slice_sliceorder 13 + +#define PGXC_SLICE_TYPE_TABLE 't' +#define PGXC_SLICE_TYPE_SLICE 's' + +extern void PgxcSliceCreate(const char* relname, Oid relid, DistributeBy* distributeby, + TupleDesc desc, const Oid* nodeoids, uint32 nodenum, uint32 startpos); +extern void RemovePgxcSlice(Oid relid); + +#endif /* PGXC_SLICE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/schemapg.h postgresql-hll-2.14/include/include/catalog/schemapg.h --- postgresql-hll-2.14_old/include/include/catalog/schemapg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/schemapg.h 2020-12-12 17:06:43.168347019 +0800 @@ -0,0 +1,1032 @@ +/*------------------------------------------------------------------------- + * + * schemapg.h + * Schema_pg_xxx macros for use by relcache.c + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * NOTES + * ****************************** + * *** DO NOT EDIT THIS FILE! *** + * ****************************** + * + * It has been GENERATED by genbki.pl + * + *------------------------------------------------------------------------- + */ +#ifndef SCHEMAPG_H +#define SCHEMAPG_H + +#define Schema_pg_proc \ +{ 1255, {"proname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prolang"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"procost"}, 700, -1, 4, 5, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prorows"}, 700, -1, 4, 6, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"provariadic"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"protransform"}, 24, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proisagg"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proiswindow"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prosecdef"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proleakproof"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proisstrict"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proretset"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"provolatile"}, 18, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronargs"}, 21, -1, 2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"pronargdefaults"}, 21, -1, 2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prorettype"}, 26, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargtypes"}, 30, -1, -1, 19, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proallargtypes"}, 1028, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargmodes"}, 1002, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proargnames"}, 1009, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proargdefaults"}, 194, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"prosrc"}, 25, -1, -1, 24, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"probin"}, 25, -1, -1, 25, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proconfig"}, 1009, -1, -1, 26, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1255, {"proacl"}, 1034, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prodefaultargpos"}, 22, -1, -1, 28, 1, -1, -1, false, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"fencedmode"}, 16, -1, 1, 29, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"proshippable"}, 16, -1, 1, 30, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"propackage"}, 16, -1, 1, 31, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1255, {"prokind"}, 18, -1, 1, 32, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_type \ +{ 1247, {"typname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typlen"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typbyval"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typtype"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typcategory"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typispreferred"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typisdefined"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typdelim"}, 18, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typrelid"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typelem"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typarray"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typinput"}, 24, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typoutput"}, 24, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typreceive"}, 24, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typsend"}, 24, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typmodin"}, 24, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typmodout"}, 24, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typanalyze"}, 24, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typalign"}, 18, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typstorage"}, 18, -1, 1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typnotnull"}, 16, -1, 1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typbasetype"}, 26, -1, 4, 24, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typtypmod"}, 23, -1, 4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typndims"}, 23, -1, 4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typcollation"}, 26, -1, 4, 27, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1247, {"typdefaultbin"}, 194, -1, -1, 28, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1247, {"typdefault"}, 25, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1247, {"typacl"}, 1034, -1, -1, 30, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_attribute \ +{ 1249, {"attrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atttypid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attstattarget"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attlen"}, 21, -1, 2, 5, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attnum"}, 21, -1, 2, 6, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attndims"}, 23, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcacheoff"}, 23, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atttypmod"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attbyval"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attstorage"}, 18, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attalign"}, 18, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attnotnull"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"atthasdef"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attisdropped"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attislocal"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcmprmode"}, 5545, -1, 1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attinhcount"}, 23, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attcollation"}, 26, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attacl"}, 1034, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attoptions"}, 1009, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1249, {"attfdwoptions"}, 1009, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1249, {"attinitdefval"}, 17, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1249, {"attkvtype"}, 5545, -1, 1, 24, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_class \ +{ 1259, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reloftype"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relowner"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relam"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfilenode"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltablespace"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relpages"}, 701, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltuples"}, 701, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relallvisible"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltoastrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reltoastidxid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reldeltarelid"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reldeltaidx"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcudescrelid"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcudescidx"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasindex"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relisshared"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relpersistence"}, 18, -1, 1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relkind"}, 18, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relnatts"}, 21, -1, 2, 22, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relchecks"}, 21, -1, 2, 23, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasoids"}, 16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhaspkey"}, 16, -1, 1, 25, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasrules"}, 16, -1, 1, 26, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhastriggers"}, 16, -1, 1, 27, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhassubclass"}, 16, -1, 1, 28, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relcmprs"}, 5545, -1, 1, 29, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relhasclusterkey"}, 16, -1, 1, 30, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relrowmovement"}, 16, -1, 1, 31, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"parttype"}, 18, -1, 1, 32, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfrozenxid"}, 31, -1, 4, 33, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relacl"}, 1034, -1, -1, 34, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"reloptions"}, 1009, -1, -1, 35, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1259, {"relreplident"}, 18, -1, 1, 36, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relfrozenxid64"}, 28, -1, 8, 37, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relbucket"}, 26, -1, 4, 38, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1259, {"relbucketkey"}, 22, -1, -1, 39, 1, -1, -1, false, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_partition \ +{ 9016, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"parttype"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"parentid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"rangenum"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intervalnum"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"partstrategy"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relfilenode"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltablespace"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relpages"}, 701, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltuples"}, 701, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relallvisible"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltoastrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reltoastidxid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"indextblid"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"indisusable"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reldeltarelid"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"reldeltaidx"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relcudescrelid"}, 26, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relcudescidx"}, 26, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"relfrozenxid"}, 31, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intspnum"}, 23, -1, 4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"partkey"}, 22, -1, -1, 22, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"intervaltablespace"}, 30, -1, -1, 23, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9016, {"interval"}, 1009, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"boundaries"}, 1009, -1, -1, 25, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"transit"}, 1009, -1, -1, 26, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"reloptions"}, 1009, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9016, {"relfrozenxid64"}, 28, -1, 8, 28, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_attrdef \ +{ 2604, {"adrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2604, {"adnum"}, 21, -1, 2, 2, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2604, {"adbin"}, 194, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2604, {"adsrc"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_constraint \ +{ 2606, {"conname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"connamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"contype"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"condeferrable"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"condeferred"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"convalidated"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"contypid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conindid"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confrelid"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confupdtype"}, 18, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confdeltype"}, 18, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confmatchtype"}, 18, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conislocal"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"coninhcount"}, 23, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"connoinherit"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"consoft"}, 16, -1, 1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conopt"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conkey"}, 1005, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"confkey"}, 1005, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conpfeqop"}, 1028, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conppeqop"}, 1028, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conffeqop"}, 1028, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conexclop"}, 1028, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2606, {"conbin"}, 194, -1, -1, 25, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2606, {"consrc"}, 25, -1, -1, 26, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2606, {"conincluding"}, 1005, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_inherits \ +{ 2611, {"inhrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2611, {"inhparent"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2611, {"inhseqno"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_index \ +{ 2610, {"indexrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indrelid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indnatts"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisunique"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisprimary"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisexclusion"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indimmediate"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisclustered"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisusable"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisvalid"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indcheckxmin"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indisready"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indkey"}, 22, -1, -1, 13, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indcollation"}, 30, -1, -1, 14, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indclass"}, 30, -1, -1, 15, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indoption"}, 22, -1, -1, 16, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indexprs"}, 194, -1, -1, 17, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2610, {"indpred"}, 194, -1, -1, 18, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2610, {"indisreplident"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2610, {"indnkeyatts"}, 21, -1, 2, 20, 0, -1, -1, true, 'p', 's', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_operator \ +{ 2617, {"oprname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprkind"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcanmerge"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcanhash"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprleft"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprright"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprresult"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcom"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprnegate"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprcode"}, 24, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprrest"}, 24, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2617, {"oprjoin"}, 24, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_opfamily \ +{ 2753, {"opfmethod"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2753, {"opfowner"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_opclass \ +{ 2616, {"opcmethod"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcowner"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcfamily"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcintype"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opcdefault"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2616, {"opckeytype"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_am \ +{ 2601, {"amname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amstrategies"}, 21, -1, 2, 2, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsupport"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanorder"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanorderbyop"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanbackward"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanunique"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanmulticol"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amoptionalkey"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsearcharray"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amsearchnulls"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amstorage"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amclusterable"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ampredlocks"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amkeytype"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"aminsert"}, 24, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambeginscan"}, 24, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amgettuple"}, 24, -1, 4, 18, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amgetbitmap"}, 24, -1, 4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amrescan"}, 24, -1, 4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amendscan"}, 24, -1, 4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ammarkpos"}, 24, -1, 4, 22, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amrestrpos"}, 24, -1, 4, 23, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ammerge"}, 24, -1, 4, 24, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambuild"}, 24, -1, 4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambuildempty"}, 24, -1, 4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"ambulkdelete"}, 24, -1, 4, 27, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amvacuumcleanup"}, 24, -1, 4, 28, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcanreturn"}, 24, -1, 4, 29, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amcostestimate"}, 24, -1, 4, 30, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2601, {"amoptions"}, 24, -1, 4, 31, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_amop \ +{ 2602, {"amopfamily"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoplefttype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoprighttype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopstrategy"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amoppurpose"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopopr"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopmethod"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2602, {"amopsortfamily"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_amproc \ +{ 2603, {"amprocfamily"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amproclefttype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amprocrighttype"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amprocnum"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2603, {"amproc"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_language \ +{ 2612, {"lanname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanispl"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanpltrusted"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanplcallfoid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"laninline"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanvalidator"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2612, {"lanacl"}, 1034, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_largeobject_metadata \ +{ 2995, {"lomowner"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2995, {"lomacl"}, 1034, -1, -1, 2, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_largeobject \ +{ 2613, {"loid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2613, {"pageno"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2613, {"data"}, 17, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_aggregate \ +{ 2600, {"aggfnoid"}, 24, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggtransfn"}, 24, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggcollectfn"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggfinalfn"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggsortop"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggtranstype"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"agginitval"}, 25, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2600, {"agginitcollect"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2600, {"aggkind"}, 18, -1, 1, 9, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2600, {"aggnumdirectargs"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_statistic \ +{ 2619, {"starelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"starelkind"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staattnum"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stainherit"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanullfrac"}, 700, -1, 4, 5, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stawidth"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stadistinct"}, 700, -1, 4, 7, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind1"}, 21, -1, 2, 8, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind2"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind3"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind4"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stakind5"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop1"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop2"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop3"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop4"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staop5"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers1"}, 1021, -1, -1, 18, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers2"}, 1021, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers3"}, 1021, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers4"}, 1021, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stanumbers5"}, 1021, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues1"}, 2277, -1, -1, 23, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues2"}, 2277, -1, -1, 24, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues3"}, 2277, -1, -1, 25, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues4"}, 2277, -1, -1, 26, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stavalues5"}, 2277, -1, -1, 27, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"stadndistinct"}, 700, -1, 4, 28, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2619, {"staextinfo"}, 25, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_rewrite \ +{ 2618, {"rulename"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_class"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_attr"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_type"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_enabled"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"is_instead"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2618, {"ev_qual"}, 194, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2618, {"ev_action"}, 194, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_trigger \ +{ 2620, {"tgrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgfoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgtype"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgenabled"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgisinternal"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstrrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstrindid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgconstraint"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgdeferrable"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tginitdeferred"}, 16, -1, 1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgnargs"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgattr"}, 22, -1, -1, 13, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgargs"}, 17, -1, -1, 14, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2620, {"tgqual"}, 194, -1, -1, 15, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 2620, {"tgowner"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_description \ +{ 2609, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2609, {"description"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_cast \ +{ 2605, {"castsource"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"casttarget"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castfunc"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castcontext"}, 18, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2605, {"castmethod"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_enum \ +{ 3501, {"enumtypid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3501, {"enumsortorder"}, 700, -1, 4, 2, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3501, {"enumlabel"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_namespace \ +{ 2615, {"nspname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nspowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nsptimeline"}, 20, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"nspacl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2615, {"in_redistribution"}, 18, -1, 1, 5, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_conversion \ +{ 2607, {"conname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"connamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conforencoding"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"contoencoding"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"conproc"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2607, {"condefault"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_depend \ +{ 2608, {"classid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"objid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refclassid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refobjid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"refobjsubid"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2608, {"deptype"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_database \ +{ 1262, {"datname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datdba"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"encoding"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datcollate"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datctype"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datistemplate"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datallowconn"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datconnlimit"}, 23, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datlastsysoid"}, 26, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datfrozenxid"}, 31, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"dattablespace"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datcompatibility"}, 19, -1, NAMEDATALEN, 12, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datacl"}, 1034, -1, -1, 13, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1262, {"datfrozenxid64"}, 28, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_db_role_setting \ +{ 2964, {"setdatabase"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2964, {"setrole"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2964, {"setconfig"}, 1009, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_tablespace \ +{ 1213, {"spcname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcacl"}, 1034, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1213, {"spcoptions"}, 1009, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1213, {"spcmaxsize"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1213, {"relative"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_pltemplate \ +{ 1136, {"tmplname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmpltrusted"}, 16, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmpldbacreate"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1136, {"tmplhandler"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplinline"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplvalidator"}, 25, -1, -1, 6, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmpllibrary"}, 25, -1, -1, 7, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1136, {"tmplacl"}, 1034, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_authid \ +{ 1260, {"rolname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolsuper"}, 16, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolinherit"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcreaterole"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcreatedb"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcatupdate"}, 16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolcanlogin"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolreplication"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolauditadmin"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolsystemadmin"}, 16, -1, 1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolconnlimit"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolpassword"}, 25, -1, -1, 12, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolvalidbegin"}, 1184, -1, 8, 13, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolvaliduntil"}, 1184, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolrespool"}, 19, -1, NAMEDATALEN, 15, 0, -1, -1, false, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roluseft"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolparentid"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roltabspace"}, 25, -1, -1, 18, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolkind"}, 18, -1, 1, 19, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolnodegroup"}, 26, -1, 4, 20, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roltempspace"}, 25, -1, -1, 21, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolspillspace"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolexcpdata"}, 25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1260, {"rolmonitoradmin"}, 16, -1, 1, 24, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"roloperatoradmin"}, 16, -1, 1, 25, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1260, {"rolpolicyadmin"}, 16, -1, 1, 26, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_auth_members \ +{ 1261, {"roleid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"member"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"grantor"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1261, {"admin_option"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_shdepend \ +{ 1214, {"dbid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"classid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objsubid"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"refclassid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"refobjid"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"deptype"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1214, {"objfile"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_shdescription \ +{ 2396, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2396, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2396, {"description"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_config \ +{ 3602, {"cfgname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfgparser"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3602, {"cfoptions"}, 1009, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_config_map \ +{ 3603, {"mapcfg"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"maptokentype"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"mapseqno"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3603, {"mapdict"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_ts_dict \ +{ 3600, {"dictname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dicttemplate"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3600, {"dictinitoption"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_ts_parser \ +{ 3601, {"prsname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsstart"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prstoken"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsend"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prsheadline"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3601, {"prslextype"}, 24, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_ts_template \ +{ 3764, {"tmplname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmplnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmplinit"}, 24, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3764, {"tmpllexize"}, 24, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_auth_history \ +{ 3457, {"roloid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3457, {"passwordtime"}, 1184, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3457, {"rolpassword"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_user_status \ +{ 3460, {"roloid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"failcount"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"locktime"}, 1184, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"rolstatus"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"permspace"}, 20, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"tempspace"}, 20, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3460, {"passwordexpired"}, 21, -1, 2, 7, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_extension \ +{ 3079, {"extname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extrelocatable"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extversion"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3079, {"extconfig"}, 1028, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3079, {"extcondition"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_obsscaninfo \ +{ 5679, {"query_id"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"user_id"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"table_name"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"file_type"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 5679, {"time_stamp"}, 1184, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"actual_time"}, 701, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"file_scanned"}, 20, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"data_size"}, 701, -1, 8, 8, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 5679, {"billing_info"}, 25, -1, -1, 9, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_foreign_data_wrapper \ +{ 2328, {"fdwname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwhandler"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwvalidator"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwacl"}, 1034, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 2328, {"fdwoptions"}, 1009, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_foreign_server \ +{ 1417, {"srvname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvfdw"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvtype"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1417, {"srvversion"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 1417, {"srvacl"}, 1034, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 1417, {"srvoptions"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_user_mapping \ +{ 1418, {"umuser"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1418, {"umserver"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 1418, {"umoptions"}, 1009, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pgxc_class \ +{ 9001, {"pcrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pclocatortype"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pchashalgorithm"}, 21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pchashbuckets"}, 21, -1, 2, 4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pgroup"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"redistributed"}, 18, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"redis_order"}, 23, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"pcattnum"}, 22, -1, -1, 8, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"nodeoids"}, 32, -1, -1, 9, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9001, {"options"}, 25, -1, -1, 10, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pgxc_node \ +{ 9015, {"node_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_port"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_host"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_port1"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_host1"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"hostis_primary"}, 16, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_primary"}, 16, -1, 1, 8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_preferred"}, 16, -1, 1, 9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"node_id"}, 23, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"sctp_port"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"control_port"}, 23, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"sctp_port1"}, 23, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"control_port1"}, 23, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_central"}, 16, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9015, {"nodeis_active"}, 16, -1, 1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pgxc_group \ +{ 9014, {"group_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"in_redistribution"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_members"}, 32, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_buckets"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9014, {"is_installation"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_acl"}, 1034, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9014, {"group_kind"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_resource_pool \ +{ 3450, {"respool_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"mem_percent"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"cpu_affinity"}, 20, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"control_group"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"active_statements"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"max_dop"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"memory_limit"}, 19, -1, NAMEDATALEN, 7, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"parentid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"io_limits"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"io_priority"}, 19, -1, NAMEDATALEN, 10, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"nodegroup"}, 19, -1, NAMEDATALEN, 11, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3450, {"is_foreign"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_workload_group \ +{ 3451, {"workload_gpname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3451, {"respool_oid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3451, {"act_statements"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_app_workloadgroup_mapping \ +{ 3464, {"appname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3464, {"workload_gpname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_foreign_table \ +{ 3118, {"ftrelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftserver"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftwriteonly"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3118, {"ftoptions"}, 1009, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_rlspolicy \ +{ 3254, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polrelid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polcmd"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polpermissive"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polroles"}, 1028, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3254, {"polqual"}, 194, -1, -1, 6, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_default_acl \ +{ 826, {"defaclrole"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclobjtype"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 826, {"defaclacl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_seclabel \ +{ 3596, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"objsubid"}, 23, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3596, {"provider"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3596, {"label"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_shseclabel \ +{ 3592, {"objoid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3592, {"classoid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3592, {"provider"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 3592, {"label"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_collation \ +{ 3456, {"collname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collencoding"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collcollate"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3456, {"collctype"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_range \ +{ 3541, {"rngtypid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubtype"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngcollation"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubopc"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngcanonical"}, 24, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3541, {"rngsubdiff"}, 24, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_policy_label \ +{ 9500, {"labelname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"labeltype"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdnnamespace"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdnid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"relcolumn"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9500, {"fqdntype"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy \ +{ 9510, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"polcomments"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"modifydate"}, 1114, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9510, {"polenabled"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_access \ +{ 9520, {"accesstype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9520, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_privileges \ +{ 9530, {"privilegetype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9530, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_auditing_policy_filters \ +{ 9540, {"filtertype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"labelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9540, {"logicaloperator"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_masking_policy \ +{ 9610, {"polname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"polcomments"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"modifydate"}, 1114, -1, 8, 3, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9610, {"polenabled"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_masking_policy_actions \ +{ 9650, {"actiontype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actparams"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actlabelname"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"policyoid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9650, {"actmodifydate"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_masking_policy_filters \ +{ 9640, {"filtertype"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"filterlabelname"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"policyoid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"modifydate"}, 1114, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9640, {"logicaloperator"}, 25, -1, -1, 5, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_encrypted_columns \ +{ 9700, {"rel_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"column_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"column_key_id"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"encryption_type"}, 5545, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"data_type_original_oid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"data_type_original_mod"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9700, {"create_date"}, 1114, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_column_keys \ +{ 9720, {"column_key_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"column_key_distributed_id"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"global_key_id"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_namespace"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_owner"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"create_date"}, 1114, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9720, {"key_acl"}, 1034, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_column_keys_args \ +{ 9740, {"column_key_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"function_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"key"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9740, {"value"}, 17, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_client_global_keys \ +{ 9710, {"global_key_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_namespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_owner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"key_acl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9710, {"create_date"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_client_global_keys_args \ +{ 9730, {"global_key_id"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"function_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"key"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9730, {"value"}, 17, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_job \ +{ 9022, {"job_id"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"current_postgres_pid"}, 20, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"log_user"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"priv_user"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"dbname"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"node_name"}, 19, -1, NAMEDATALEN, 6, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"job_status"}, 18, -1, 1, 7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"start_date"}, 1114, -1, 8, 8, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"next_run_date"}, 1114, -1, 8, 9, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"failure_count"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"interval"}, 25, -1, -1, 11, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9022, {"last_start_date"}, 1114, -1, 8, 12, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"last_end_date"}, 1114, -1, 8, 13, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"last_suc_date"}, 1114, -1, 8, 14, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"this_run_date"}, 1114, -1, 8, 15, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9022, {"nspname"}, 19, -1, NAMEDATALEN, 16, 0, -1, -1, false, 'p', 'c', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_asp \ +{ 9534, {"sampleid"}, 20, -1, 8, 1, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"sample_time"}, 1184, -1, 8, 2, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"need_flush_sample"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"databaseid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"thread_id"}, 20, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"sessionid"}, 20, -1, 8, 6, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"start_time"}, 1184, -1, 8, 7, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"event"}, 25, -1, -1, 8, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"lwtid"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"psessionid"}, 20, -1, 8, 10, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"tlevel"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"smpid"}, 23, -1, 4, 12, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"userid"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"application_name"}, 25, -1, -1, 14, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"client_addr"}, 869, -1, -1, 15, 0, -1, -1, false, 'm', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"client_hostname"}, 25, -1, -1, 16, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"client_port"}, 23, -1, 4, 17, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"query_id"}, 20, -1, 8, 18, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"unique_query_id"}, 20, -1, 8, 19, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"user_id"}, 26, -1, 4, 20, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"cn_id"}, 23, -1, 4, 21, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"unique_query"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"locktag"}, 25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"lockmode"}, 25, -1, -1, 24, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9534, {"block_sessionid"}, 20, -1, 8, 25, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9534, {"wait_status"}, 25, -1, -1, 26, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_job_proc \ +{ 9023, {"job_id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9023, {"what"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_extension_data_source \ +{ 4211, {"srcname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srcowner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srctype"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4211, {"srcversion"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4211, {"srcacl"}, 1034, -1, -1, 5, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 4211, {"srcoptions"}, 1009, -1, -1, 6, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_statistic_ext \ +{ 3220, {"starelid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"starelkind"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stainherit"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanullfrac"}, 700, -1, 4, 4, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stawidth"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stadistinct"}, 700, -1, 4, 6, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stadndistinct"}, 700, -1, 4, 7, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind1"}, 21, -1, 2, 8, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind2"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind3"}, 21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind4"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakind5"}, 21, -1, 2, 12, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop1"}, 26, -1, 4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop2"}, 26, -1, 4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop3"}, 26, -1, 4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop4"}, 26, -1, 4, 16, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staop5"}, 26, -1, 4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stakey"}, 22, -1, -1, 18, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers1"}, 1021, -1, -1, 19, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers2"}, 1021, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers3"}, 1021, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers4"}, 1021, -1, -1, 22, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stanumbers5"}, 1021, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues1"}, 2277, -1, -1, 24, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues2"}, 2277, -1, -1, 25, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues3"}, 2277, -1, -1, 26, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues4"}, 2277, -1, -1, 27, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"stavalues5"}, 2277, -1, -1, 28, 0, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 3220, {"staexprs"}, 194, -1, -1, 29, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_pg_object \ +{ 9025, {"object_oid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"object_type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"creator"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"ctime"}, 1184, -1, 8, 4, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9025, {"mtime"}, 1184, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_synonym \ +{ 3546, {"synname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synnamespace"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synowner"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synobjschema"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 3546, {"synobjname"}, 19, -1, NAMEDATALEN, 5, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_directory \ +{ 4347, {"dirname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4347, {"owner"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 4347, {"dirpath"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 4347, {"diracl"}, 1034, -1, -1, 4, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_pg_hashbucket \ +{ 9026, {"bucketid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9026, {"bucketcnt"}, 23, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9026, {"bucketvector"}, 32, -1, -1, 3, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_global_config \ +{ 9080, {"name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9080, {"value"}, 25, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_streaming_stream \ +{ 9028, {"relid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9028, {"queries"}, 17, -1, -1, 2, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_streaming_cont_query \ +{ 9029, {"id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"relid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"defrelid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"active"}, 16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"streamrelid"}, 26, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"matrelid"}, 26, -1, 4, 7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"lookupidxid"}, 26, -1, 4, 8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"step_factor"}, 21, -1, 2, 9, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"ttl"}, 23, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"ttl_attno"}, 21, -1, 2, 11, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"dictrelid"}, 26, -1, 4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"grpnum"}, 21, -1, 2, 13, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9029, {"grpidx"}, 22, -1, -1, 14, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_streaming_reaper_status \ +{ 9030, {"id"}, 23, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9030, {"contquery_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9030, {"gather_interval"}, 25, -1, -1, 3, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9030, {"gather_completion_time"}, 25, -1, -1, 4, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#define Schema_gs_matview \ +{ 9982, {"matviewid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"mapid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"ivm"}, 16, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"needrefresh"}, 16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9982, {"refreshtime"}, 1114, -1, 8, 5, 0, -1, -1, FLOAT8PASSBYVAL, 'p', 'd', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_matview_dependency \ +{ 9985, {"matviewid"}, 26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"relid"}, 26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"mlogid"}, 26, -1, 4, 3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9985, {"mxmin"}, 23, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 } + +#define Schema_pgxc_slice \ +{ 9035, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"type"}, 18, -1, 1, 2, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"strategy"}, 18, -1, 1, 3, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"relid"}, 26, -1, 4, 4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"referenceoid"}, 26, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"sindex"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"interval"}, 1009, -1, -1, 7, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"transitboundary"}, 1009, -1, -1, 8, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"transitno"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"nodeoid"}, 26, -1, 4, 10, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"boundaries"}, 1009, -1, -1, 11, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 }, \ +{ 9035, {"specified"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9035, {"sliceorder"}, 23, -1, 4, 13, 0, -1, -1, true, 'p', 'i', false, false, false, true, 0, 0, 0, 0 } + +#define Schema_gs_opt_model \ +{ 9998, {"template_name"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"model_name"}, 19, -1, NAMEDATALEN, 2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"datname"}, 19, -1, NAMEDATALEN, 3, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"ip"}, 19, -1, NAMEDATALEN, 4, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"port"}, 23, -1, 4, 5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"max_epoch"}, 23, -1, 4, 6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"learning_rate"}, 700, -1, 4, 7, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"dim_red"}, 700, -1, 4, 8, 0, -1, -1, FLOAT4PASSBYVAL, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"hidden_units"}, 23, -1, 4, 9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"batch_size"}, 23, -1, 4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"feature_size"}, 23, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"available"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"is_training"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"label"}, 1002, -1, -1, 14, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"max"}, 1016, -1, -1, 15, 1, -1, -1, false, 'x', 'd', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"acc"}, 1021, -1, -1, 16, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 0, 0 }, \ +{ 9998, {"description"}, 25, -1, -1, 17, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, 0, 100, 0 } + +#endif /* SCHEMAPG_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/storage_gtt.h postgresql-hll-2.14/include/include/catalog/storage_gtt.h --- postgresql-hll-2.14_old/include/include/catalog/storage_gtt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/storage_gtt.h 2020-12-12 17:06:43.168347019 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * storage_gtt.h + * prototypes for functions in backend/catalog/storage_gtt.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/catalog/storage_gtt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STORAGE_GTT_H +#define STORAGE_GTT_H + +#include "access/htup.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "nodes/execnodes.h" +#include "utils/relcache.h" + +extern Size active_gtt_shared_hash_size(void); +extern void active_gtt_shared_hash_init(void); +extern void remember_gtt_storage_info(const RelFileNode rnode, Relation rel); +extern void forget_gtt_storage_info(Oid relid, const RelFileNode relfilenode, bool isCommit); +extern bool is_other_backend_use_gtt(Oid relid); +extern bool gtt_storage_attached(Oid relid); +extern Bitmapset *copy_active_gtt_bitmap(Oid relid); +extern void up_gtt_att_statistic( + Oid reloid, int attnum, int natts, TupleDesc tupleDescriptor, Datum* values, bool* isnull); +extern HeapTuple get_gtt_att_statistic(Oid reloid, int attnum); +extern void release_gtt_statistic_cache(HeapTuple tup); +extern void up_gtt_relstats(const Relation relation, + BlockNumber numPages, + double numTuples, + BlockNumber numAllVisiblePages, + TransactionId relfrozenxid); +extern bool get_gtt_relstats( + Oid relid, BlockNumber* relpages, double* reltuples, BlockNumber* relallvisible, TransactionId* relfrozenxid); +extern void gtt_force_enable_index(Relation index); +extern void gtt_fix_index_state(Relation index); +extern void init_gtt_storage(CmdType operation, ResultRelInfo *resultRelInfo); +extern Oid gtt_fetch_current_relfilenode(Oid relid); +extern void gtt_switch_rel_relfilenode(Oid rel1, Oid relfilenode1, Oid rel2, Oid relfilenode2, bool footprint); +extern void gtt_create_storage_files(Oid relid); +extern void remove_gtt_att_statistic(Oid reloid, int attnum); +#endif /* STORAGE_GTT_H */ diff -uprN postgresql-hll-2.14_old/include/include/catalog/storage.h postgresql-hll-2.14/include/include/catalog/storage.h --- postgresql-hll-2.14_old/include/include/catalog/storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/storage.h 2020-12-12 17:06:43.168347019 +0800 @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------------- + * + * storage.h + * prototypes for functions in backend/catalog/storage.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/storage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STORAGE_H +#define STORAGE_H +#include "dfsdesc.h" +#include "storage/dfs/dfs_connector.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "storage/lmgr.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" + +#define DFS_STOR_FLAG -1 + +extern void RelationCreateStorage(RelFileNode rnode, char relpersistence, Oid ownerid, Oid bucketOid = InvalidOid, + Oid relfilenode=InvalidOid, Relation rel = NULL); +extern void RelationDropStorage(Relation rel, bool isDfsTruncate = false); +extern void RelationPreserveStorage(RelFileNode rnode, bool atCommit); +extern void RelationTruncate(Relation rel, BlockNumber nblocks); +extern void PartitionTruncate(Relation parent, Partition part, BlockNumber nblocks); +extern void PartitionDropStorage(Relation rel, Partition part); +extern void BucketCreateStorage(RelFileNode rnode, Oid bucketOid, Oid ownerid, Oid relfilenode); +extern void BucketDropStorage(Relation relation, Partition partition); + +#ifdef ENABLE_MULTIPLE_NODES +namespace Tsdb { +extern void DropPartStorage( + Oid partition_id, RelFileNode* partition_rnode, BackendId backend, Oid ownerid, List* target_cudesc_relids); +extern void InsertPartStorageIntoPendingList(_in_ RelFileNode* partition_rnode, _in_ AttrNumber part_id, + _in_ BackendId backend, _in_ Oid ownerid, _in_ bool atCommit); +} +#endif /* ENABLE_MULTIPLE_NODES */ + +// column-storage relation api +extern void CStoreRelCreateStorage(RelFileNode* rnode, AttrNumber attrnum, char relpersistence, Oid ownerid); +extern void CStoreRelDropColumn(Relation rel, AttrNumber attrnum, Oid ownerid); +extern void DfsStoreRelCreateStorage(RelFileNode* rnode, AttrNumber attrnum, char relpersistence); + +/* + * These functions used to be in storage/smgr/smgr.c, which explains the + * naming + */ +extern void smgrDoPendingDeletes(bool isCommit); +extern int smgrGetPendingDeletes(bool forCommit, ColFileNodeRel **ptr); +extern void AtSubCommit_smgr(void); +extern void AtSubAbort_smgr(void); +extern void PostPrepare_smgr(void); + +extern void InsertIntoPendingDfsDelete(const char* filename, bool atCommit, Oid ownerid, uint64 filesize); +extern void ResetPendingDfsDelete(); +extern void doPendingDfsDelete(bool isCommit, TransactionId *xid); + +extern void ColMainFileNodesCreate(void); +extern void ColMainFileNodesDestroy(void); +extern void ColMainFileNodesAppend(RelFileNode* bcmFileNode, BackendId backend); +extern void ColumnRelationDoDeleteFiles(RelFileNode* bcmFileNode, ForkNumber forknum, BackendId backend, Oid ownerid); +extern void RowRelationDoDeleteFiles(RelFileNode rnode, BackendId backend, Oid ownerid, Oid relOid = InvalidOid, + bool isCommit = false); + +extern uint64 GetSMgrRelSize(RelFileNode* relfilenode, BackendId backend, ForkNumber forkNum); + +/* + * dfs storage api + */ +extern void ClearDfsStorage(ColFileNode* pFileNode, int nrels, bool dropDir, bool cfgFromMapper); +extern void DropMapperFiles(ColFileNode* pColFileNode, int nrels); +extern void UnregisterDfsSpace(ColFileNode* pColFileNode, int rels); +extern void CreateDfsStorage(Relation rel); +extern void DropDfsStorage(Relation rel, bool isDfsTruncate = false); +extern void DropDfsDirectory(ColFileNode *colFileNode, bool cfgFromMapper); +extern void DropMapperFile(RelFileNode fNode); +extern void ClearDfsDirectory(ColFileNode *colFileNode, bool cfgFromMapper); +extern void DropDfsFilelist(RelFileNode fNode); +extern int ReadDfsFilelist(RelFileNode fNode, Oid ownerid, List** pendingList); +extern void SaveDfsFilelist(Relation rel, DFSDescHandler *handler); +extern uint64 GetDfsDelFileSize(List *dfsfilelist, bool isCommit); +extern bool IsSmgrTruncate(const XLogReaderState *record); +extern bool IsSmgrCreate(const XLogReaderState* record); + +extern void smgrApplyXLogTruncateRelation(XLogReaderState *record); +extern void XLogBlockSmgrRedoTruncate(RelFileNode rnode, BlockNumber blkno); + +/* + * to check whether is external storage + */ +#define IsDfsStor(flag) \ + ((bool) ((flag) == DFS_STOR_FLAG)) + +#endif /* STORAGE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/storage_xlog.h postgresql-hll-2.14/include/include/catalog/storage_xlog.h --- postgresql-hll-2.14_old/include/include/catalog/storage_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/storage_xlog.h 2020-12-12 17:06:43.168347019 +0800 @@ -0,0 +1,51 @@ +/* --------------------------------------------------------------------------------------- + * + * storage_xlog.h + * prototypes for functions in backend/catalog/storage.cpp + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/catalog/storage_xlog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STORAGE_XLOG_H +#define STORAGE_XLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +/* + * Declarations for smgr-related XLOG records + * + * Note: we log file creation and truncation here, but logging of deletion + * actions is handled by xact.c, because it is part of transaction commit. + */ + +/* XLOG gives us high 4 bits */ +#define XLOG_SMGR_CREATE 0x10 +#define XLOG_SMGR_TRUNCATE 0x20 + +typedef struct xl_smgr_create { + RelFileNodeOld rnode; + ForkNumber forkNum; +} xl_smgr_create; + +typedef struct xl_smgr_truncate { + BlockNumber blkno; + RelFileNodeOld rnode; +} xl_smgr_truncate; + +extern void log_smgrcreate(RelFileNode *rnode, ForkNumber forkNum, const oidvector* bucketlist = NULL); + +extern void smgr_redo(XLogReaderState *record); +extern void smgr_desc(StringInfo buf, XLogReaderState *record); +extern void smgr_redo_create(RelFileNode rnode, ForkNumber forkNum, char *data); +extern void xlog_block_smgr_redo_truncate(RelFileNode rnode, BlockNumber blkno, XLogRecPtr lsn); + +#endif /* STORAGE_XLOG_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/toasting.h postgresql-hll-2.14/include/include/catalog/toasting.h --- postgresql-hll-2.14_old/include/include/catalog/toasting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/toasting.h 2020-12-12 17:06:43.168347019 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * toasting.h + * This file provides some definitions to support creation of toast tables + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/catalog/toasting.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TOASTING_H +#define TOASTING_H + +/* + * toasting.c prototypes + */ +extern void AlterTableCreateToastTable(Oid relOid, Datum reloptions, List *filenodelist = NIL); +extern void BootstrapToastTable(char *relName, + Oid toastOid, + Oid toastIndexOid); +extern bool createToastTableForPartition(Oid relOid, + Oid partOid, + Datum reloptions, + List *relfilenode); + +/* + * This macro is just to keep the C compiler from spitting up on the + * upcoming commands for genbki.pl. + */ +#define DECLARE_TOAST(name,toastoid, indexoid) extern int no_such_variable + +/* + * What follows are lines processed by genbki.pl to create the statements + * the bootstrap parser will turn into BootstrapToastTable commands. + * Each line specifies the system catalog that needs a toast table, + * the OID to assign to the toast table, and the OID to assign to the + * toast table's index. The reason we hard-wire these OIDs is that we + * need stable OIDs for shared relations, and that includes toast tables + * of shared relations. + */ + +/* normal catalogs */ +DECLARE_TOAST(pg_attrdef, 2830, 2831); +DECLARE_TOAST(pg_constraint, 2832, 2833); +DECLARE_TOAST(pg_description, 2834, 2835); +DECLARE_TOAST(pg_proc, 2836, 2837); +DECLARE_TOAST(pg_rewrite, 2838, 2839); +DECLARE_TOAST(pg_rlspolicy, 3173, 3174); +DECLARE_TOAST(pg_seclabel, 3598, 3599); +DECLARE_TOAST(pg_statistic, 2840, 2841); +DECLARE_TOAST(pg_statistic_ext, 3439, 3440); +DECLARE_TOAST(pg_trigger, 2336, 2337); +DECLARE_TOAST(pg_partition, 5502, 5503); +DECLARE_TOAST(pgxc_class, 5506, 5507); +DECLARE_TOAST(pg_hashbucket, 4390, 4391); + +/* shared catalogs */ +DECLARE_TOAST(pg_shdescription, 2846, 2847); +#define PgShdescriptionToastTable 2846 +#define PgShdescriptionToastIndex 2847 +DECLARE_TOAST(pg_db_role_setting, 2966, 2967); +#define PgDbRoleSettingToastTable 2966 +#define PgDbRoleSettingToastIndex 2967 +DECLARE_TOAST(pgxc_group, 5504, 5505); +#define PgxcGroupToastTable 5504 +#define PgxcGroupToastIndex 5505 +#endif /* TOASTING_H */ + diff -uprN postgresql-hll-2.14_old/include/include/catalog/unused_oids postgresql-hll-2.14/include/include/catalog/unused_oids --- postgresql-hll-2.14_old/include/include/catalog/unused_oids 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/catalog/unused_oids 2020-12-12 17:06:43.169347032 +0800 @@ -0,0 +1,57 @@ +#!/bin/sh +# +# unused_oids +# +# src/include/catalog/unused_oids +# +# finds blocks of manually-assignable oids that have not already been +# claimed by post_hackers. primarily useful for finding available +# oids for new internal functions. the numbers printed are inclusive +# ranges of unused oids. +# +# before using a large empty block, make sure you aren't about +# to take over what was intended as expansion space for something +# else. +# +# run this script in src/include/catalog. +# + + +AWK="awk" + +# Get FirstBootstrapObjectId from access/transam.h +FIRSTOBJECTID=`grep '#define[ ]*FirstBootstrapObjectId' ../access/transam.h | $AWK '{ print $3 }'` +export FIRSTOBJECTID + +# this part (down to the uniq step) should match the duplicate_oids script +# note: we exclude BKI_BOOTSTRAP relations since they are expected to have +# matching DATA lines in pg_class.h and pg_type.h + +cat pgxc_*.h pg_*.h toasting.h indexing.h | \ +egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \ +sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \ + -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \ + -e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \ +tr ',' '\n' | \ +sort -n | \ +uniq | \ +$AWK ' +BEGIN { + last = 0; +} +/^[0-9]/ { + if ($1 > last + 1) { + if ($1 > last + 2) { + print last + 1, "-", $1 - 1; + } else { + print last + 1; + } + } + last = $1; +} +END { + print last + 1, "-", ENVIRON["FIRSTOBJECTID"]-1; +}' diff -uprN postgresql-hll-2.14_old/include/include/c.h postgresql-hll-2.14/include/include/c.h --- postgresql-hll-2.14_old/include/include/c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/c.h 2020-12-12 17:06:43.169347032 +0800 @@ -0,0 +1,1184 @@ +/* ------------------------------------------------------------------------- + * + * c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/c.h + * + * ------------------------------------------------------------------------- + */ +/* + * ---------------------------------------------------------------- + * TABLE OF CONTENTS + * + * When adding stuff to this file, please try to put stuff + * into the relevant section, or add new sections as appropriate. + * + * section description + * ------- ------------------------------------------------ + * 0) pg_config.h and standard system headers + * 1) hacks to cope with non-ANSI C compilers + * 2) bool, true, false, TRUE, FALSE, NULL + * 3) standard system types + * 4) IsValid macros for system types + * 5) offsetof, lengthof, endof, alignment + * 6) widely useful macros + * 7) random stuff + * 8) system-specific hacks + * 9) C++-specific stuff + * + * NOTE: since this file is included by both frontend and backend modules, it's + * almost certainly wrong to put an "extern" declaration here. typedefs and + * macros are the kind of thing that might go here. + * + * ---------------------------------------------------------------- + */ +#ifndef C_H +#define C_H + +/* + * We have to include stdlib.h here because it defines many of these macros + * on some platforms, and we only want our definitions used if stdlib.h doesn't + * have its own. The same goes for stddef and stdarg if present. + */ + +#include "pg_config.h" +#include "pg_config_manual.h" /* must be after pg_config.h */ +#if !defined(WIN32) && !defined(__CYGWIN__) /* win32 will include further \ + * down */ +#include "pg_config_os.h" /* must be before any system header files */ +#endif +#include "postgres_ext.h" + +#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H) +#define errcode __msvc_errcode +#include +#undef errcode +#endif + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#ifdef HAVE_STDINT_H +/* to use INT64_MIN and INT64_MAX */ +#define __STDC_LIMIT_MACROS +#include +#endif +#include +#include + +#include +#if defined(WIN32) || defined(__CYGWIN__) +#include /* ensure O_BINARY is available */ +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +/* We have to redefine some system functions after they are included above. */ +#include "pg_config_os.h" +#endif + +/* Must be before gettext() games below */ +#include + +#define _(x) gettext(x) + +#ifndef likely +#define likely(x) __builtin_expect((x) != 0, 1) +#endif +#ifndef unlikely +#define unlikely(x) __builtin_expect((x) != 0, 0) +#endif + +#ifdef ENABLE_NLS +#include +#else +#define gettext(x) (x) + +#define dgettext(d, x) (x) +#define ngettext(s, p, n) ((n) == 1 ? (s) : (p)) +#define dngettext(d, s, p, n) ((n) == 1 ? (s) : (p)) +#endif + +/* + * Use this to mark string constants as needing translation at some later + * time, rather than immediately. This is useful for cases where you need + * access to the original string and translated string, and for cases where + * immediate translation is not possible, like when initializing global + * variables. + * http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html + */ +#define gettext_noop(x) (x) + +/* ---------------------------------------------------------------- + * Section 1: hacks to cope with non-ANSI C compilers + * + * type prefixes (const, signed, volatile, inline) are handled in pg_config.h. + * ---------------------------------------------------------------- + */ + +/* + * CppAsString + * Convert the argument to a string, using the C preprocessor. + * CppConcat + * Concatenate two arguments together, using the C preprocessor. + * + * Note: the standard Autoconf macro AC_C_STRINGIZE actually only checks + * whether #identifier works, but if we have that we likely have ## too. + */ +#if defined(HAVE_STRINGIZE) + +#define CppAsString(identifier) #identifier +#define CppConcat(x, y) x##y +#else /* !HAVE_STRINGIZE */ + +#define CppAsString(identifier) "identifier" + +/* + * CppIdentity -- On Reiser based cpp's this is used to concatenate + * two tokens. That is + * CppIdentity(A)B ==> AB + * We renamed it to _private_CppIdentity because it should not + * be referenced outside this file. On other cpp's it + * produces A B. + */ +#define _priv_CppIdentity(x) x +#define CppConcat(x, y) _priv_CppIdentity(x) y +#endif /* !HAVE_STRINGIZE */ + +/* + * dummyret is used to set return values in macros that use ?: to make + * assignments. gcc wants these to be void, other compilers like char + */ +#ifdef __GNUC__ /* GNU cc */ +#define dummyret void +#else +#define dummyret char +#endif + +#ifndef __GNUC__ +#define __attribute__(_arg_) +#endif + +/* ---------------------------------------------------------------- + * Section 2: bool, true, false, TRUE, FALSE, NULL + * ---------------------------------------------------------------- + */ + +/* + * bool + * Boolean value, either true or false. + * + * XXX for C++ compilers, we assume the compiler has a compatible + * built-in definition of bool. + */ + +#ifndef __cplusplus + +#ifndef bool +typedef char bool; +#endif + +#ifndef true +#define true ((bool)1) +#endif + +#ifndef false +#define false ((bool)0) +#endif +#endif /* not C++ */ + +typedef bool* BoolPtr; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/* + * NULL + * Null pointer. + */ +#ifndef NULL +#define NULL ((void*)0) +#endif + +/* ---------------------------------------------------------------- + * Section 3: standard system types + * ---------------------------------------------------------------- + */ + +/* + * Pointer + * Variable holding address of any memory resident object. + * + * XXX Pointer arithmetic is done with this, so it can't be void * + * under "true" ANSI compilers. + */ +typedef char* Pointer; + +/* + * intN + * Signed integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. + */ +#ifndef HAVE_INT8 +typedef signed char int8; /* == 8 bits */ +typedef signed short int16; /* == 16 bits */ +typedef signed int int32; /* == 32 bits */ +#endif /* not HAVE_INT8 */ + +/* + * uintN + * Unsigned integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. + */ +#ifndef HAVE_UINT8 +typedef unsigned char uint8; /* == 8 bits */ +typedef unsigned short uint16; /* == 16 bits */ +typedef unsigned int uint32; /* == 32 bits */ +#endif /* not HAVE_UINT8 */ + +typedef unsigned int uint; /* == 32 bits */ + +/* + * bitsN + * Unit of bitwise operation, AT LEAST N BITS IN SIZE. + */ +typedef uint8 bits8; /* >= 8 bits */ +typedef uint16 bits16; /* >= 16 bits */ +typedef uint32 bits32; /* >= 32 bits */ + +/* + * 64-bit integers + */ +#ifdef HAVE_LONG_INT_64 +/* Plain "long int" fits, use it */ + +#ifndef HAVE_INT64 +typedef long int int64; +#endif +#ifndef HAVE_UINT64 +typedef unsigned long int uint64; +#endif +#elif defined(HAVE_LONG_LONG_INT_64) +/* We have working support for "long long int", use that */ + +#ifndef HAVE_INT64 +typedef long long int int64; +#endif +#ifndef HAVE_UINT64 +typedef unsigned long long int uint64; +#endif +#else +/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */ +#error must have a working 64-bit integer datatype +#endif + +/* Decide if we need to decorate 64-bit constants */ +#ifdef HAVE_LL_CONSTANTS +#define INT64CONST(x) ((int64)x##LL) +#define UINT64CONST(x) ((uint64)x##ULL) +#else +#define INT64CONST(x) ((int64)(x)) +#define UINT64CONST(x) ((uint64)(x)) +#endif + +/* + * stdint.h limits aren't guaranteed to be present and aren't guaranteed to + * have compatible types with our fixed width types. So just define our own. + */ +#define PG_INT8_MIN (-0x7F - 1) +#define PG_INT8_MAX 0x7F +#define PG_UINT8_MAX 0xFF +#define PG_INT16_MIN (-0x7FFF - 1) +#define PG_INT16_MAX 0x7FFF +#define PG_UINT16_MAX 0xFFFF +#define PG_INT32_MIN (-0x7FFFFFFF - 1) +#define PG_INT32_MAX (0x7FFFFFFF) +#define PG_UINT32_MAX 0xFFFFFFFFU +#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1) +#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF) +#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF) + +/* Select timestamp representation (float8 or int64) */ +#ifdef USE_INTEGER_DATETIMES +#define HAVE_INT64_TIMESTAMP +#endif + +/* sig_atomic_t is required by ANSI C, but may be missing on old platforms */ +#ifndef HAVE_SIG_ATOMIC_T +typedef int sig_atomic_t; +#endif + +/* + * Size + * Size of any memory resident object, as returned by sizeof. + */ +typedef size_t Size; + +/* + * Index + * Index into any memory resident array. + * + * Note: + * Indices are non negative. + */ +typedef unsigned int Index; + +/* + * Offset + * Offset into any memory resident array. + * + * Note: + * This differs from an Index in that an Index is always + * non negative, whereas Offset may be negative. + */ +typedef signed int Offset; + +/* + * Common Postgres datatype names (as used in the catalogs) + */ + +typedef int8 int1; +typedef int16 int2; +typedef int32 int4; +typedef float float4; +typedef double float8; + +typedef uint8 uint1; +typedef uint16 uint2; +typedef uint32 uint4; + +/* + * Define signed 128 bit int type. + * Define unsigned 128 bit int type. + */ +#ifndef ENABLE_DEFAULT_GCC +#if !defined(WIN32) +typedef __int128 int128; +typedef unsigned __int128 uint128; +#endif +#else +#ifdef __linux__ +#if __GNUC__ >= 7 +typedef __int128 int128; +typedef unsigned __int128 uint128; +#endif +#endif +#endif + +#if !defined(WIN32) +typedef union { + uint128 u128; + uint64 u64[2]; + uint32 u32[4]; +} uint128_u; +#endif + +/* + * int128 type has 128 bits. + * INT128_MIN is (-1 * (1 << 127)) + * INT128_MAX is ((1 << 127) - 1) + * UINT128_MIN is 0 + * UINT128_MAX is ((1 << 128) - 1) + * + */ +#define INT128_MAX (int128)(((uint128)1 << 127) - 1) +#define INT128_MIN (-INT128_MAX - 1) +#define UINT128_MAX (((uint128)INT128_MAX << 1) + 1) + +#define UINT128_IS_EQUAL(x, y) ((x).u128 == (y).u128) +#define UINT128_COPY(x, y) (x).u128 = (y).u128 + + +/* + * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId, + * CommandId + */ + +/* typedef Oid is in postgres_ext.h */ + +/* + * regproc is the type name used in the include/catalog headers, but + * RegProcedure is the preferred name in C code. + */ +typedef Oid regproc; +typedef regproc RegProcedure; + +/* Macro for checking XID 64-bitness */ +#define XID_IS_64BIT +#define MAX_START_XID UINT64CONST(0x3fffffffffffffff) + +typedef uint64 TransactionId; + +#define TransactionIdPrecedes(id1, id2) ((id1) < (id2)) +#define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) +#define TransactionIdFollows(id1, id2) ((id1) > (id2)) +#define TransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +#define StartTransactionIdIsValid(start_xid) ((start_xid) <= MAX_START_XID) + +typedef uint32 ShortTransactionId; + +typedef uint64 LocalTransactionId; + +typedef uint64 SubTransactionId; + +#define XID_FMT UINT64_FORMAT + +#define CSN_FMT UINT64_FORMAT + +#define InvalidSubTransactionId ((SubTransactionId)0) +#define TopSubTransactionId ((SubTransactionId)1) + +typedef TransactionId MultiXactId; +#define MultiXactIdPrecedes(id1, id2) ((id1) < (id2)) +#define MultiXactIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) +#define MultiXactIdFollows(id1, id2) ((id1) > (id2)) +#define MultiXactIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +typedef uint64 MultiXactOffset; + +/* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */ +#define StartMultiXactIdIsValid(start_mx_id) ((start_mx_id) <= MAX_START_XID) +#define StartMultiXactOffsetIsValid(start_mx_offset) ((start_mx_offset) <= MAX_START_XID) +typedef uint32 CommandId; + +#define FirstCommandId ((CommandId)0) +#define InvalidCommandId (~(CommandId)0) + +/* + * CommitSeqNo is currently an LSN, but keep use a separate datatype for clarity. + */ +typedef uint64 CommitSeqNo; + +#define InvalidCommitSeqNo ((CommitSeqNo)0) + +/* + * Array indexing support + */ +#define MAXDIM 6 +typedef struct { + int indx[MAXDIM]; +} IntArray; + +/* ---------------- + * Variable-length datatypes all share the 'struct varlena' header. + * + * NOTE: for TOASTable types, this is an oversimplification, since the value + * may be compressed or moved out-of-line. However datatype-specific routines + * are mostly content to deal with de-TOASTed values only, and of course + * client-side routines should never see a TOASTed value. But even in a + * de-TOASTed value, beware of touching vl_len_ directly, as its representation + * is no longer convenient. It's recommended that code always use the VARDATA, + * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of + * the struct fields. See postgres.h for details of the TOASTed form. + * ---------------- + */ +struct varlena { + char vl_len_[4]; /* Do not touch this field directly! */ + char vl_dat[FLEXIBLE_ARRAY_MEMBER]; +}; + +#define VARHDRSZ ((int32)sizeof(int32)) + +/* + * These widely-used datatypes are just a varlena header and the data bytes. + * There is no terminating null or anything like that --- the data length is + * always VARSIZE(ptr) - VARHDRSZ. + */ +typedef struct varlena bytea; +typedef struct varlena byteawithoutorderwithequalcol; +typedef struct varlena text; +typedef struct varlena BpChar; /* blank-padded char, ie SQL char(n) */ +typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */ +typedef struct varlena NVarChar2; /* var-length char, ie SQL nvarchar2(n) */ +/* + * Specialized array types. These are physically laid out just the same + * as regular arrays (so that the regular array subscripting code works + * with them). They exist as distinct types mostly for historical reasons: + * they have nonstandard I/O behavior which we don't want to change for fear + * of breaking applications that look at the system catalogs. There is also + * an implementation issue for oidvector: it's part of the primary key for + * pg_proc, and we can't use the normal btree array support routines for that + * without circularity. + */ +typedef struct { + int32 vl_len_; /* these fields must match ArrayType! */ + int ndim; /* always 1 for int2vector */ + int32 dataoffset; /* always 0 for int2vector */ + Oid elemtype; + int dim1; + int lbound1; + int2 values[FLEXIBLE_ARRAY_MEMBER]; +} int2vector; + +typedef struct { + int32 vl_len_; /* these fields must match ArrayType! */ + int ndim; /* always 1 for oidvector */ + int32 dataoffset; /* always 0 for oidvector */ + Oid elemtype; + int dim1; + int lbound1; + Oid values[FLEXIBLE_ARRAY_MEMBER]; +} oidvector; + +typedef oidvector oidvector_extend; + +typedef struct ArrayInt4 { + int32 count; + int4* values; +} ArrayInt4; + +typedef struct ArrayInt2 { + int32 count; + int2* values; +} ArrayInt2; + +typedef struct ArrayOid { + int32 count; + Oid* values; +} ArrayOid; + +typedef struct ArrayChar { + int32 count; + char* values; +} ArrayChar; + +typedef struct ArrayCStr { + int32 count; + char** values; +} ArrayCStr; + +/* the array type of aclitem */ +typedef ArrayInt4 ArrayAcl; + +#define MakeArray(_type, cnt, ...) \ + { \ + .count = cnt, .values = (cnt == 0) ? NULL : (_type[cnt]) \ + { \ + __VA_ARGS__ \ + } \ + } + +#define MakeArrayInt4(cnt, ...) (ArrayInt4) MakeArray(int4, cnt, __VA_ARGS__) +#define MakeArrayInt2(cnt, ...) (ArrayInt2) MakeArray(int2, cnt, __VA_ARGS__) +#define MakeArrayOid(cnt, ...) (ArrayOid) MakeArray(Oid, cnt, __VA_ARGS__) +#define MakeArrayChar(cnt, ...) (ArrayChar) MakeArray(char, cnt, __VA_ARGS__) +#define MakeArrayCStr(cnt, ...) (ArrayCStr) MakeArray(char*, cnt, __VA_ARGS__) + +#define MakeArrayOidPtr(cnt, ...) \ + (ArrayOid[1]) \ + { \ + MakeArray(Oid, cnt, __VA_ARGS__) \ + } +#define MakeArrayCStrPtr(cnt, ...) \ + (ArrayCStr[1]) \ + { \ + MakeArray(char*, cnt, __VA_ARGS__) \ + } +#define MakeArrayCharPtr(cnt, ...) \ + (ArrayChar[1]) \ + { \ + MakeArray(char, cnt, __VA_ARGS__) \ + } +#define MakeArrayInt4Ptr(cnt, ...) \ + (ArrayInt4[1]) \ + { \ + MakeArray(int4, cnt, __VA_ARGS__) \ + } +#define MakeArrayInt2Ptr(cnt, ...) \ + (ArrayInt2[1]) \ + { \ + MakeArray(int2, cnt, __VA_ARGS__) \ + } + +#define MakeSingleValuePtr(_type, val) \ + (_type[1]) \ + { \ + val \ + } + +/* + * Representation of a Name: effectively just a C string, but null-padded to + * exactly NAMEDATALEN bytes. The use of a struct is historical. + */ +typedef struct nameData { + char data[NAMEDATALEN]; +} NameData; +typedef NameData* Name; + +#define NameStr(name) ((name).data) + +typedef struct pathData { + char data[MAXPGPATH]; +} PathData; + +/* + * Support macros for escaping strings. escape_backslash should be TRUE + * if generating a non-standard-conforming string. Prefixing a string + * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming. + * Beware of multiple evaluation of the "ch" argument! + */ +#define SQL_STR_DOUBLE(ch, escape_backslash) ((ch) == '\'' || ((ch) == '\\' && (escape_backslash))) + +#define ESCAPE_STRING_SYNTAX 'E' + +/* ---------------------------------------------------------------- + * Section 4: IsValid macros for system types + * ---------------------------------------------------------------- + */ +/* + * BoolIsValid + * True iff bool is valid. + */ +#define BoolIsValid(boolean) ((boolean) == false || (boolean) == true) + +/* + * PointerIsValid + * True iff pointer is valid. + */ +#define PointerIsValid(pointer) ((const void*)(pointer) != NULL) + +/* + * PointerIsAligned + * True iff pointer is properly aligned to point to the given type. + */ +#define PointerIsAligned(pointer, type) (((intptr_t)(pointer) % (sizeof(type))) == 0) + +#define OidIsValid(objectId) ((bool)((objectId) != InvalidOid)) + +#define RegProcedureIsValid(p) OidIsValid(p) + +/* ---------------------------------------------------------------- + * Section 5: offsetof, lengthof, endof, alignment + * ---------------------------------------------------------------- + */ +/* + * offsetof + * Offset of a structure/union field within that structure/union. + * + * XXX This is supposed to be part of stddef.h, but isn't on + * some systems (like SunOS 4). + */ +#ifndef offsetof +#define offsetof(type, field) ((long)&((type*)0)->field) +#endif /* offsetof */ + +/* + * lengthof + * Number of elements in an array. + */ +#define lengthof(array) (sizeof(array) / sizeof((array)[0])) + +/* + * endof + * Address of the element one past the last in an array. + */ +#define endof(array) (&(array)[lengthof(array)]) + +/* ---------------- + * Alignment macros: align a length or address appropriately for a given type. + * The fooALIGN() macros round up to a multiple of the required alignment, + * while the fooALIGN_DOWN() macros round down. The latter are more useful + * for problems like "how many X-sized structures will fit in a page?". + * + * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2. + * That case seems extremely unlikely to be needed in practice, however. + * ---------------- + */ + +#define TYPEALIGN(ALIGNVAL, LEN) (((uintptr_t)(LEN) + ((ALIGNVAL)-1)) & ~((uintptr_t)((ALIGNVAL)-1))) + +#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN)) +#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN)) +#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN)) +#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN)) +#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN)) +/* MAXALIGN covers only built-in types, not buffers */ +#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN)) +#define CACHELINEALIGN(LEN) TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN)) + +#define TYPEALIGN_DOWN(ALIGNVAL, LEN) (((uintptr_t)(LEN)) & ~((uintptr_t)((ALIGNVAL)-1))) + +#define SHORTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN)) +#define INTALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_INT, (LEN)) +#define LONGALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN)) +#define DOUBLEALIGN_DOWN(LEN) TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN)) +#define MAXALIGN_DOWN(LEN) TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN)) + +/* ---------------------------------------------------------------- + * Section 6: widely useful macros + * ---------------------------------------------------------------- + */ +/* + * Max + * Return the maximum of two numbers. + */ +#define Max(x, y) ((x) > (y) ? (x) : (y)) + +#define MaxTriple(x, y, z) ((x) > (y) ? ((x) > (z) ? (x) : (z)) : ((y) > (z) ? (y) : (z))) + +/* + * Min + * Return the minimum of two numbers. + */ +#define Min(x, y) ((x) < (y) ? (x) : (y)) + +/* + * Abs + * Return the absolute value of the argument. + */ +#define Abs(x) ((x) >= 0 ? (x) : -(x)) + +/* + * MemCpy + * same as memcpy. + */ +#if defined(__x86_64__) && !defined(WIN32) + +static inline void* MemCpy(void* dest, const void* src, Size len) +{ + if (len <= 1024) { + if (len >= 4) { + __asm__ __volatile__("shr $2,%2\n" + "rep movsl\n" + "testb $2,%b6\n" + "je 1f\n" + "movsw\n" + "1:\n" + "testb $1,%b6\n" + "je 2f\n" + "movsb\n" + "2:" + : "=&D"(dest), "=&S"(src), "=&c"(len) + : "0"(dest), "1"(src), "2"(len), "q"(len) + : "memory"); + + return dest; + } + + __asm__ __volatile__("rep movsb" + : "=&D"(dest), "=&S"(src), "=&c"(len) + : "0"(dest), "1"(src), "2"(len) + : "memory"); + + return dest; + } + + return memcpy(dest, src, len); +} + +#else +static inline void* MemCpy(void* dest, const void* src, Size len) +{ + return memcpy(dest, src, len); +} +#endif + +/* + * StrNCpy + * Like standard library function strncpy(), except that result string + * is guaranteed to be null-terminated --- that is, at most N-1 bytes + * of the source string will be kept. + * Also, the macro returns no result (too hard to do that without + * evaluating the arguments multiple times, which seems worse). + * + * BTW: when you need to copy a non-null-terminated string (like a text + * datum) and add a null, do not do it with StrNCpy(..., len+1). That + * might seem to work, but it fetches one byte more than there is in the + * text object. One fine day you'll have a SIGSEGV because there isn't + * another byte before the end of memory. Don't laugh, we've had real + * live bug reports from real live users over exactly this mistake. + * Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead. + */ +#define StrNCpy(dst, src, len) \ + do { \ + char* _dst = (dst); \ + Size _len = (len); \ + \ + if (_len > 0) { \ + strncpy(_dst, (src), _len); \ + _dst[_len - 1] = '\0'; \ + } \ + } while (0) + +/* Get a bit mask of the bits set in non-long aligned addresses */ +#define LONG_ALIGN_MASK (sizeof(long) - 1) + +/* + * MemSet + * Exactly the same as standard library function memset(), but considerably + * faster for zeroing small word-aligned structures (such as parsetree nodes). + * This has to be a macro because the main point is to avoid function-call + * overhead. However, we have also found that the loop is faster than + * native libc memset() on some platforms, even those with assembler + * memset() functions. More research needs to be done, perhaps with + * MEMSET_LOOP_LIMIT tests in configure. + */ +#define MemSet(start, val, len) \ + do { \ + /* must be void* because we don't know if it is integer aligned yet */ \ + void* _vstart = (void*)(start); \ + int _val = (val); \ + Size _len = (len); \ + \ + if ((((uintptr_t)_vstart) & LONG_ALIGN_MASK) == 0 && (_len & LONG_ALIGN_MASK) == 0 && _val == 0 && \ + _len <= MEMSET_LOOP_LIMIT && /* \ + * If MEMSET_LOOP_LIMIT == 0, optimizer should find \ + * the whole "if" false at compile time. \ + */ \ + MEMSET_LOOP_LIMIT != 0) { \ + long* _start = (long*)_vstart; \ + long* _stop = (long*)((char*)_start + _len); \ + while (_start < _stop) \ + *_start++ = 0; \ + } else \ + memset(_vstart, _val, _len); \ + } while (0) + +/* + * MemSetAligned is the same as MemSet except it omits the test to see if + * "start" is word-aligned. This is okay to use if the caller knows a-priori + * that the pointer is suitably aligned (typically, because he just got it + * from palloc(), which always delivers a max-aligned pointer). + */ +#define MemSetAligned(start, val, len) \ + do { \ + long* _start = (long*)(start); \ + int _val = (val); \ + Size _len = (len); \ + \ + if ((_len & LONG_ALIGN_MASK) == 0 && _val == 0 && _len <= MEMSET_LOOP_LIMIT && MEMSET_LOOP_LIMIT != 0) { \ + long* _stop = (long*)((char*)_start + _len); \ + while (_start < _stop) \ + *_start++ = 0; \ + } else \ + memset(_start, _val, _len); \ + } while (0) + +/* + * MemSetTest/MemSetLoop are a variant version that allow all the tests in + * MemSet to be done at compile time in cases where "val" and "len" are + * constants *and* we know the "start" pointer must be word-aligned. + * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use + * MemSetAligned. Beware of multiple evaluations of the arguments when using + * this approach. + */ +#define MemSetTest(val, len) \ + (((len)&LONG_ALIGN_MASK) == 0 && (len) <= MEMSET_LOOP_LIMIT && MEMSET_LOOP_LIMIT != 0 && (val) == 0) + +#define MemSetLoop(start, val, len) \ + do { \ + long* _start = (long*)(start); \ + long* _stop = (long*)((char*)_start + (Size)(len)); \ + \ + while (_start < _stop) \ + *_start++ = 0; \ + } while (0) + +/* ---------------------------------------------------------------- + * Section 7: random stuff + * ---------------------------------------------------------------- + */ + +/* msb for char */ +#define HIGHBIT 0x80 +#define IS_HIGHBIT_SET(ch) ((unsigned char)(ch)&HIGHBIT) + +#define STATUS_OK 0 +#define STATUS_ERROR (-1) +#define STATUS_EOF (-2) +#define STATUS_WRONG_PASSWORD (-3) +#define STATUS_EXPIRED (-4) +#define STATUS_FOUND 1 +#define STATUS_WAITING 2 +#define STATUS_FOUND_NEED_CANCEL 3 + +/* + * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only + * used in assert-enabled builds, to avoid compiler warnings about unused + * variables in assert-disabled builds. + */ +#ifdef USE_ASSERT_CHECKING +#define PG_USED_FOR_ASSERTS_ONLY +#else +#define PG_USED_FOR_ASSERTS_ONLY __attribute__((unused)) +#endif + +// Conditionally disable a feature +// +// To reduce the exposure surface of the engine, we disabled some seldom +// used, or not-confident features. But we still want keep them minimally +// execised to make sure later code changes won't break them totally. Thus +// we differentiate them with a configure directive, and test them only +// when it is enabled. For public release, the features are disabled. +// + +#ifdef PGXC +#define FEATURE_NOT_PUBLIC_ERROR(x) \ + do { \ + /* initdb might use some of the features, hornour it */ \ + if (!IsInitdb && !g_instance.attr.attr_common.support_extended_features && \ + !u_sess->attr.attr_common.IsInplaceUpgrade) \ + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg(x))); \ + } while (0) +#endif /*PGXC*/ + +/* gettext domain name mangling */ + +/* + * To better support parallel installations of major PostgeSQL + * versions as well as parallel installations of major library soname + * versions, we mangle the gettext domain name by appending those + * version numbers. The coding rule ought to be that whereever the + * domain name is mentioned as a literal, it must be wrapped into + * PG_TEXTDOMAIN(). The macros below do not work on non-literals; but + * that is somewhat intentional because it avoids having to worry + * about multiple states of premangling and postmangling as the values + * are being passed around. + * + * Make sure this matches the installation rules in nls-global.mk. + */ + +/* need a second indirection because we want to stringize the macro value, not the name */ +#define CppAsString2(x) CppAsString(x) + +#ifdef SO_MAJOR_VERSION +#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION) +#else +#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION) +#endif + +#ifndef WIN32 +// Compiler hint to force inlining or unlining a function +// +#if defined(_MSC_VER) +#define FORCE_INLINE __forceinline +#define NO_INLINE __declspec(noinline) +#else +#if (!defined ENABLE_LLT) && (!defined ENABLE_UT) +#define FORCE_INLINE __attribute__((always_inline)) +#else +#define FORCE_INLINE +#endif +#define NO_INLINE __attribute__((noinline)) +#endif + +// SAL annotations -- remove when compiler annotation header is fixed. +// +#define _in_ // input argument: function reads it +#define _out_ // output argument: function writes it +#define __inout // both in and out argument: function r/w it +#endif /* WIN32 */ +/* ---------------------------------------------------------------- + * Section 8: system-specific hacks + * + * This should be limited to things that absolutely have to be + * included in every source file. The port-specific header file + * is usually a better place for this sort of thing. + * ---------------------------------------------------------------- + */ + +/* + * NOTE: this is also used for opening text files. + * WIN32 treats Control-Z as EOF in files opened in text mode. + * Therefore, we open files in binary mode on Win32 so we can read + * literal control-Z. The other affect is that we see CRLF, but + * that is OK because we can already handle those cleanly. + */ +#if defined(WIN32) || defined(__CYGWIN__) +#define PG_BINARY O_BINARY +#define PG_BINARY_A "ab" +#define PG_BINARY_R "rb" +#define PG_BINARY_W "wb" +#define PG_BINARY_RW "r+" +#else +#define PG_BINARY 0 +#define PG_BINARY_A "a" +#define PG_BINARY_R "r" +#define PG_BINARY_W "w" +#define PG_BINARY_RW "r+" +#endif + +/* + * Macros to support compile-time assertion checks. + * + * If the "condition" (a compile-time-constant expression) evaluates to false, + * throw a compile error using the "errmessage" (a string literal). + * + * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic + * placement restrictions. These macros make it safe to use as a statement + * or in an expression, respectively. + * + * Otherwise we fall back on a kluge that assumes the compiler will complain + * about a negative width for a struct bit-field. This will not include a + * helpful error message, but it beats not getting an error at all. + */ +#define StaticAssertStmt(condition, errmessage) ((void)(1 / (int)(!!(condition)))) +#define StaticAssertExpr(condition, errmessage) StaticAssertStmt(condition, errmessage) + +/* + * Compile-time checks that a variable (or expression) has the specified type. + * + * AssertVariableIsOfType() can be used as a statement. + * AssertVariableIsOfTypeMacro() is intended for use in macros, eg + * #define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x)) + * + * If we don't have __builtin_types_compatible_p, we can still assert that + * the types have the same size. This is far from ideal (especially on 32-bit + * platforms) but it provides at least some coverage. + */ + +#define AssertVariableIsOfType(varname, typename) \ + StaticAssertStmt( \ + sizeof(varname) == sizeof(typename), CppAsString(varname) " does not have type " CppAsString(typename)) +#define AssertVariableIsOfTypeMacro(varname, typename) \ + (StaticAssertExpr( \ + sizeof(varname) == sizeof(typename), CppAsString(varname) " does not have type " CppAsString(typename))) +/* + * Provide prototypes for routines not present in a particular machine's + * standard C library. + */ + +#if !HAVE_DECL_SNPRINTF +extern int snprintf(char* str, size_t count, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4))); +#endif + +#if !HAVE_DECL_VSNPRINTF +extern int vsnprintf(char* str, size_t count, const char* fmt, va_list args); +#endif + +/* no special DLL markers on most ports */ +#ifndef PGDLLIMPORT +#define PGDLLIMPORT +#endif +#ifndef PGDLLEXPORT +#define PGDLLEXPORT +#endif + +/* + * The following is used as the arg list for signal handlers. Any ports + * that take something other than an int argument should override this in + * their pg_config_os.h file. Note that variable names are required + * because it is used in both the prototypes as well as the definitions. + * Note also the long name. We expect that this won't collide with + * other names causing compiler warnings. + */ + +#ifndef SIGNAL_ARGS +#define SIGNAL_ARGS int postgres_signal_arg +#endif + +/* + * When there is no sigsetjmp, its functionality is provided by plain + * setjmp. Incidentally, nothing provides setjmp's functionality in + * that case. + */ +#ifndef HAVE_SIGSETJMP +#define sigjmp_buf jmp_buf +#define sigsetjmp(x, y) setjmp(x) +#define siglongjmp longjmp +#endif + +#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC +extern int fdatasync(int fildes); +#endif + +/* If strtoq() exists, rename it to the more standard strtoll() */ +#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ) +#define strtoll strtoq +#define HAVE_STRTOLL 1 +#endif + +/* If strtouq() exists, rename it to the more standard strtoull() */ +#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ) +#define strtoull strtouq +#define HAVE_STRTOULL 1 +#endif + +/* + * We assume if we have these two functions, we have their friends too, and + * can use the wide-character functions. + */ +#if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER) +#define USE_WIDE_UPPER_LOWER +#endif + +#define EXEC_BACKEND + +/* EXEC_BACKEND defines */ +#ifdef EXEC_BACKEND +#define NON_EXEC_STATIC +#else +#define NON_EXEC_STATIC static +#endif + +/* ---------------------------------------------------------------- + * Section 9: C++-specific stuff + * + * This should be limited to stuff that are C++ language specific. + * ---------------------------------------------------------------- + */ +#ifndef WIN32 +#ifdef __cplusplus + +// The rtl namespace (read as "run time library") contains some crystally clear +// stuff from STL, which we do not encourage to use to avoid potential issues. +// Fortunately there shouldn't be much to copy here. +// +namespace rtl { +template +const T& max(const T& a, const T& b) +{ + return (a >= b) ? a : b; +} + +template +const T& min(const T& a, const T& b) +{ + return (a < b) ? a : b; +} +} // namespace rtl + +#endif /* __cplusplus */ +#endif /* WIN32 */ + +/* /port compatibility functions */ +#include "port.h" + +#define LOG2(x) (log(x) / 0.693147180559945) + +#define pg_restrict __restrict + +#define INT2UINT64(val) (unsigned int64)((unsigned int)(val)) + +#define INT2ULONG(val) (unsigned long)((unsigned int)(val)) + +#define INT2SIZET(val) (Size)((unsigned int)(val)) + +#define isIntergratedMachine false // not work for now, adapt it later + +#endif /* C_H */ diff -uprN postgresql-hll-2.14_old/include/include/cipher.h postgresql-hll-2.14/include/include/cipher.h --- postgresql-hll-2.14_old/include/include/cipher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cipher.h 2020-12-12 17:06:43.169347032 +0800 @@ -0,0 +1,137 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cipher.h + * + * + * + * IDENTIFICATION + * src/include/cipher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CIPHER_H +#define CIPHER_H + +#include +#include +#include + +#include "c.h" + +#include "utils/pg_crc.h" +#include "openssl/ssl.h" +#include "openssl/tls1.h" +#include "openssl/ossl_typ.h" +#include "openssl/obj_mac.h" + +#ifdef WIN32 +typedef unsigned __int64 GS_UINT64; +#else +typedef unsigned long long GS_UINT64; +#endif +#if defined(__LP64__) || defined(__64BIT__) +typedef unsigned int GS_UINT32; + +typedef signed int GS_INT32; +#else +typedef unsigned long GS_UINT32; + +typedef signed long GS_INT32; +#endif + +typedef unsigned char GS_UCHAR; + +#define CIPHER_KEY_FILE ".key.cipher" +#define RAN_KEY_FILE ".key.rand" +#define RANDOM_LEN 16 +#define CIPHER_LEN 16 +#define DEK_LEN 16 +#define ITERATE_TIMES 10000 +#define MAC_ITERATE_TIMES 10000 +#define MAC_LEN 20 +#define MIN_KEY_LEN 8 +#define MAX_KEY_LEN 16 +#define AK_LEN 512 +#define SK_LEN 512 +#define AK_VALID_CHRS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +#define SK_VALID_CHRS AK_VALID_CHRS +#define DEK_SAMPLE_STRING "TRANS_ENCRYPT_SAMPLE_STRING" + +typedef enum { + UNKNOWN_KEY_MODE, + SERVER_MODE, + CLIENT_MODE, + OBS_MODE, + SOURCE_MODE, + GDS_MODE +} KeyMode; + +typedef struct { + GS_UCHAR cipherkey[CIPHER_LEN + 1]; /* cipher text vector */ + GS_UCHAR key_salt[RANDOM_LEN + 1]; /* salt vector used to derive key */ + GS_UCHAR vector_salt[RANDOM_LEN + 1]; /* salt vector used to encrypt/decrypt text */ + pg_crc32 crc; +} CipherkeyFile; + +typedef struct { + GS_UCHAR randkey[CIPHER_LEN + 1]; + pg_crc32 crc; +} RandkeyFile; + +typedef enum { + OBS_CLOUD_TYPE = 0, /* on cloud obs cipher for encrypt and decrypt ak/sk */ + INITDB_NOCLOUDOBS_TYPE, /* non-cloud obs use the cipher same as initdb */ + GSQL_SSL_TYPE, /* gsql ssl connection cipher */ + GDS_SSL_TYPE, /* gds ssl connection cipher */ + CIPHER_TYPE_MAX /* The max number of types should be at the end */ +} CipherType; + +extern void gen_cipher_rand_files( + KeyMode mode, const char* plain_key, const char* user_name, const char* datadir, const char* preStr); +extern void decode_cipher_files( + KeyMode mode, const char* user_name, const char* datadir, GS_UCHAR* plainpwd, bool obs_server_mode = false); +extern bool check_input_password(const char* password); +extern bool EncryptInputKey(GS_UCHAR* pucPlainText, GS_UCHAR* initrand, GS_UCHAR* keySaltVector, + GS_UCHAR* encryptVector, GS_UCHAR* pucCipherText, GS_UINT32* pulCLen); +extern bool ReadContentFromFile(const char* filename, void* content, size_t csize); +extern bool check_certificate_signature_algrithm(const SSL_CTX* SSL_context); +extern long check_certificate_time(const SSL_CTX* SSL_context, const int alarm_days); +extern bool CipherFileIsValid(CipherkeyFile* cipher); +extern bool RandFileIsValid(RandkeyFile* randfile); +extern void ClearCipherKeyFile(CipherkeyFile* cipher_file_content); +extern void ClearRandKeyFile(RandkeyFile* rand_file_content); +extern bool DecryptInputKey(GS_UCHAR* pucCipherText, GS_UINT32 ulCLen, GS_UCHAR* initrand, GS_UCHAR* initVector, + GS_UCHAR* decryptVector, GS_UCHAR* pucPlainText, GS_UINT32* pulPLen); + +extern bool getTransEncryptKeyString(GS_UCHAR** cipherKey, GS_UCHAR** rndm); +extern bool getAkSkForTransEncrypt(char* ak, int akbuflen, char* sk, int skbuflen); +extern bool getKeyVectorFromCipherFile(const char* cipherkeyfile, const char* cipherrndfile, GS_UCHAR* key, GS_UCHAR* vector); +extern bool encryptStringByAES128Speed(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern char* getGaussHome(); +extern bool getAndCheckTranEncryptDEK(); + +extern char* SEC_decodeBase64(const char* pucInBuf, GS_UINT32* pulOutBufLen); +extern char* SEC_encodeBase64(const char* pucInBuf, GS_UINT32 ulInBufLen); +extern GS_UINT32 CRYPT_encrypt(GS_UINT32 ulAlgId, const GS_UCHAR* pucKey, GS_UINT32 ulKeyLen, const GS_UCHAR* pucIV, + GS_UINT32 ulIVLen, GS_UCHAR* pucPlainText, GS_UINT32 ulPlainLen, GS_UCHAR* pucCipherText, GS_UINT32* pulCLen); +extern GS_UINT32 CRYPT_decrypt(GS_UINT32 ulAlgId, const GS_UCHAR* pucKey, GS_UINT32 ulKeyLen, const GS_UCHAR* pucIV, + GS_UINT32 ulIVLen, GS_UCHAR* pucCipherText, GS_UINT32 ulCLen, GS_UCHAR* pucPlainText, GS_UINT32* pulPLen); +extern GS_UINT32 CRYPT_hmac(GS_UINT32 ulAlgType, const GS_UCHAR* pucKey, GS_UINT32 upucKeyLen, const GS_UCHAR* pucData, + GS_UINT32 ulDataLen, GS_UCHAR* pucDigest, GS_UINT32* pulDigestLen); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/client_logic/cache.h postgresql-hll-2.14/include/include/client_logic/cache.h --- postgresql-hll-2.14_old/include/include/client_logic/cache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/client_logic/cache.h 2020-12-12 17:06:43.169347032 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cache.h + * + * IDENTIFICATION + * src\include\client_logic\cache.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CACHE_H +#define CACHE_H + +#include "utils/syscache.h" +#include "access/htup.h" + +HeapTuple search_syscache_cek_name(const char *key_name, Oid namespace_id); +HeapTuple search_syscache_cmk_name(const char *key_name, Oid namespace_id); +HeapTuple search_sys_cache_ce_col_name(Oid relid, const char *attname); +HeapTuple search_sys_cache_copy_ce_col_name(Oid relid, const char *attname); +bool search_sys_cache_exists_ce_col_name(Oid relid, const char *attname); + +#endif /* CACHE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/client_logic/client_logic_common.h postgresql-hll-2.14/include/include/client_logic/client_logic_common.h --- postgresql-hll-2.14_old/include/include/client_logic/client_logic_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/client_logic/client_logic_common.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic_common.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic_common.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GS_CL_COMMON_H +#define GS_CL_COMMON_H + +#include +#include "cstrings_map.h" + +enum class ArgsParseState { + KEY, + VALUE, + FLUSH +}; + +typedef CStringsMap StringArgsVec; +#endif diff -uprN postgresql-hll-2.14_old/include/include/client_logic/client_logic_enums.h postgresql-hll-2.14/include/include/client_logic/client_logic_enums.h --- postgresql-hll-2.14_old/include/include/client_logic/client_logic_enums.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/client_logic/client_logic_enums.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic_enums.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic_enums.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CLIENT_LOGIC_ENUMS_H +#define CLIENT_LOGIC_ENUMS_H + +#include + +typedef enum class CmkKeyStore { + INVALID_KEYSTORE = -1, + GS_KTOOL +} CmkKeyStore; + +typedef enum class CmkAlgorithm { + INVALID_ALGORITHM, + AES_256_CBC +} CmkAlgorithm; + +typedef enum class EncryptionType { + INVALID_TYPE, + RANDOMIZED_TYPE, + DETERMINISTIC_TYPE +} EncryptionType; + + +typedef enum ColumnEncryptionAlgorithm { + INVALID_ALGORITHM, + AEAD_AES_256_CBC_HMAC_SHA256, + AEAD_AES_128_CBC_HMAC_SHA256 +} ColumnEncryptionAlgorithm; + + +inline ColumnEncryptionAlgorithm get_cek_algorithm_from_string(const char *alg) +{ + if (alg == NULL || strlen(alg) == 0) { + return ColumnEncryptionAlgorithm::INVALID_ALGORITHM; + } + if (strncasecmp(alg, "AEAD_AES_256_CBC_HMAC_SHA256", strlen("AEAD_AES_256_CBC_HMAC_SHA256")) == 0) { + return ColumnEncryptionAlgorithm::AEAD_AES_256_CBC_HMAC_SHA256; + } else if (strncasecmp(alg, "AEAD_AES_128_CBC_HMAC_SHA256", strlen("AEAD_AES_128_CBC_HMAC_SHA256")) == 0) { + return ColumnEncryptionAlgorithm::AEAD_AES_128_CBC_HMAC_SHA256; + } + return ColumnEncryptionAlgorithm::INVALID_ALGORITHM; +} + +inline CmkKeyStore get_key_store_from_string(const char *key_store) +{ + if (key_store == NULL || strlen(key_store) == 0) { + return CmkKeyStore::INVALID_KEYSTORE; + } + + if (strncasecmp(key_store, "gs_ktool", strlen("gs_ktool")) == 0) { + return CmkKeyStore::GS_KTOOL; + } + + return CmkKeyStore::INVALID_KEYSTORE; +} + +inline CmkAlgorithm get_algorithm_from_string(const char *algorithm) +{ + if (algorithm == NULL || strlen(algorithm) == 0) { + return CmkAlgorithm::INVALID_ALGORITHM; + } + + if (strncasecmp(algorithm, "AES_256_CBC", strlen("AES_256_CBC")) == 0) { + return CmkAlgorithm::AES_256_CBC; + } + + return CmkAlgorithm::INVALID_ALGORITHM; +} + +inline EncryptionType get_algorithm_type_from_string(const char *algorithm_type) +{ + if (algorithm_type == NULL || strlen(algorithm_type) == 0) { + return EncryptionType::INVALID_TYPE; + } + if (strncasecmp(algorithm_type, "DETERMINISTIC", strlen("DETERMINISTIC")) == 0) { + return EncryptionType::DETERMINISTIC_TYPE; + } else if (strncasecmp(algorithm_type, "RANDOMIZED", strlen("RANDOMIZED")) == 0) { + return EncryptionType::RANDOMIZED_TYPE; + } + + return EncryptionType::INVALID_TYPE; +} +#endif /* CLIENT_LOGIC_ENUMS_H */ diff -uprN postgresql-hll-2.14_old/include/include/client_logic/client_logic.h postgresql-hll-2.14/include/include/client_logic/client_logic.h --- postgresql-hll-2.14_old/include/include/client_logic/client_logic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/client_logic/client_logic.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,54 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * client_logic.h + * + * IDENTIFICATION + * src\include\client_logic\client_logic.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once +#include "postgres.h" +#include "catalog/heap.h" +#include "catalog/dependency.h" +#include "catalog/gs_client_global_keys.h" +#include "catalog/gs_client_global_keys_args.h" +#include "catalog/gs_column_keys.h" +#include "catalog/gs_column_keys_args.h" +#include "catalog/gs_encrypted_columns.h" +#include "client_logic_common.h" +#include "lib/stringinfo.h" + +int set_column_encryption(const ColumnDef *def, CeHeapInfo *ce_heap_info); +int process_global_settings(CreateClientLogicGlobal *parsetree); +int process_column_settings(CreateClientLogicColumn *parsetree); +int drop_global_settings(DropStmt *stmt); +int drop_column_settings(DropStmt *stmt); +void remove_cmk_by_id(Oid id); +void remove_cek_by_id(Oid id); +void remove_encrypted_col_by_id(Oid id); +void remove_cmk_args_by_id(Oid id); +void remove_cek_args_by_id(Oid id); +void insert_gs_sec_encrypted_column_tuple(CeHeapInfo *ce_heap_info, Relation rel, const Oid rel_id, + CatalogIndexState indstate); +bool is_exist_encrypted_column(const ObjectAddresses *targetObjects); +/* Get description functions */ +void get_global_setting_description(StringInfo buffer, const ObjectAddress* object); +void get_column_setting_description(StringInfo buffer, const ObjectAddress* object); +void get_cached_column_description(StringInfo buffer, const ObjectAddress* object); +void get_global_setting_args_description(StringInfo buffer, const ObjectAddress* object); +void get_column_setting_args_description(StringInfo buffer, const ObjectAddress* object); \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/client_logic/cstrings_map.h postgresql-hll-2.14/include/include/client_logic/cstrings_map.h --- postgresql-hll-2.14_old/include/include/client_logic/cstrings_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/client_logic/cstrings_map.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cstrings_map.h + * + * IDENTIFICATION + * src\include\client_logic\cstrings_map.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef C_STRINGS_MAP_H +#define C_STRINGS_MAP_H +#include +#include + +#define MAX_VAL_LEN 1024 +#define NAMEDATALEN 64 +#define NAME_CNT 4 + +struct ConstKeyValue { + char key[NAMEDATALEN + 1]; + char value[MAX_VAL_LEN]; + size_t valsize; +}; + +class CStringsMap { +public: + CStringsMap(); + CStringsMap(const CStringsMap &other); + CStringsMap &operator = (const CStringsMap &other); + ~CStringsMap(); + void set(const char *key, const char *value, size_t valsize = 0); + void clear(); + const char *find(const char *key) const; + const char *find(const char *key, size_t *size) const; + const size_t Size() const + { + return size; + } + ConstKeyValue *at(size_t i) const + { + if (i < size) { + return &k_v_map[i]; + } else { + return NULL; + } + } + +private: + size_t size; + struct ConstKeyValue *k_v_map; + const size_t index(const char *key) const; +}; +#endif /* C_STRINGS_MAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_alarm.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_alarm.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_alarm.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,42 @@ +/** + * @file cma_alarm.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_ALARM_H +#define CMA_ALARM_H + +extern Alarm* StartupAlarmList; +extern int StartupAlarmListSize; + +extern Alarm* AbnormalAlarmList; +extern int AbnormalAlarmListSize; + +extern Alarm* AbnormalCmaConnAlarmList; +extern int AbnormalCmaConnAlarmListSize; + +extern Alarm* AbnormalBuildAlarmList; +extern Alarm* AbnormalDataInstDiskAlarmList; +extern int DatanodeAbnormalAlarmListSize; + +extern Alarm* AbnormalEtcdAlarmList; +extern int AbnormalEtcdAlarmListSize; + +extern void StorageScalingAlarmItemInitialize(void); +extern void ReportStorageScalingAlarm(AlarmType alarmType, const char* instanceName, int alarmIndex); +extern void StartupAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void AbnormalAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void AbnormalCmaConnAlarmItemInitialize(staticNodeConfig* g_currentNode); +extern void DatanodeAbnormalAlarmItemInitialize(staticNodeConfig* g_currentNode); + +extern void report_build_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); +extern void report_dn_disk_alarm(AlarmType alarmType, char* instanceName, int alarmIndex, char* data_path); +extern void report_etcd_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); +extern void InitializeAlarmItem(staticNodeConfig* g_currentNode); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_common.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_common.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_common.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,31 @@ +/** + * @file cma_common.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_COMMON_H +#define CMA_COMMON_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +void set_thread_state(pthread_t thrId); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); + +char* type_int_to_str_binname(InstanceTypes ins_type); +char* type_int_to_str_name(InstanceTypes ins_type); + +int ExecuteCmd(const char* command, struct timeval timeout); +int cmagent_getenv(const char* env_var, char* output_env_value, uint32 env_value_len); + +void listen_ip_merge(uint32 ip_count, char ip_listen[][CM_IP_LENGTH], char* ret_ip_merge, uint32 ipMergeLength); +void reload_parameters_from_configfile(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_connect.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_connect.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_connect.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_connect.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,29 @@ +/** + * @file cma_connect.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_CONNECT_H +#define CMA_CONNECT_H + +#include "cm/libpq-fe.h" +#include "cm/libpq-int.h" + +#define MAX_PRE_CONN_CMS 2 +#define MAX_CONN_TIMEOUT 3 + +extern CM_Conn* agent_cm_server_connect; +extern CM_Conn* GetConnToCmserver(uint32 nodeid); + +void CloseConnToCmserver(void); + +int cm_client_flush_msg(CM_Conn* conn); +int cm_client_send_msg(CM_Conn* conn, char msgtype, const char* s, size_t lenmsg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_coordinator.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_coordinator.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_coordinator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_coordinator.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,44 @@ +/** + * @file cma_coordinator.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_COORDINATOR_H +#define CMA_COORDINATOR_H + +#include "cm/cm_msg.h" + +void* auto_repair_cn(void* arg); + +int set_pgxc_node_isactive_to_false(); +int cmagent_to_coordinator_disconnect(void); +int cm_check_to_coordinate_node_group(char* pid_path, char* node_group_name1, char* node_group_members1, + char* node_group_name2, char* node_group_members2); +int cm_static_config_check_to_coordinate_wrapper(const char* pid_path, int* coordinate_node_check, + char data_node_check[][CM_MAX_DATANODE_PER_NODE], char* name_record[CM_NODE_MAXNUM * CM_MAX_INSTANCE_PER_NODE], + uint32* name_record_count, int* currentNodeNum); +int coordinate_status_check_and_report_wrapper( + const char* pid_path, agent_to_cm_coordinate_status_report* report_msg, uint32 lc_count); +int drop_fault_coordinator(const char* pid_path, agent_to_cm_coordinate_status_report* report_msg); +int agent_notify_coordinator_cancel_session(const char* pid_path); +int process_notify_ccn_command(const cm_to_agent_notify_cn_central_node* notify); +int coordinate_status_check_phony_dead(const char* pid_path); +int process_notify_ccn_command_internal(const char* pid_path); +int update_ha_relation_to_coordinator(const char* pid_path); + +bool create_connection_to_healthcn(uint32 healthCn); +bool IsCnDnDisconnected(); +bool lock_coordinator(); +bool unlock_coordinator(); +bool update_pgxc_node(uint32 healthCn); +bool start_delay_xlog_recycle(); +bool stop_delay_xlog_recycle(); +void CnDnDisconnectCheck(); +void close_reset_conn(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_create_conn_cms.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_create_conn_cms.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_create_conn_cms.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_create_conn_cms.h 2020-12-12 17:06:43.170347045 +0800 @@ -0,0 +1,21 @@ +/** + * @file cma_create_conn_cms.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_CREATE_CONN_CMS_H +#define CMA_CREATE_CONN_CMS_H + +typedef enum CMA_OPERATION_ { + CMA_KILL_SELF_INSTANCES = 0, +} cma_operation; + +void* ConnCmsPMain(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_datanode.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_datanode.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_datanode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_datanode.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,37 @@ +/** + * @file cma_datanode.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_DATANODE_H +#define CMA_DATANODE_H + +#include "cma_main.h" + +void* DNStorageScalingCheckMain(void * const arg); + +bool is_process_alive(pgpid_t pid); + +pgpid_t get_pgpid(char* pid_path); + +uint32 GetDatanodeNumSort(staticNodeConfig* p_node_config, uint32 sort); + +int cm_check_install_nodegroup_is_exist(); +int cm_select_datanode_names( + char* pid_path, char datanode_names[][CM_NODE_NAME], char datanode_name_oids[][CM_NODE_NAME], int* datanode_count); +int ReadDBStateFile(GaussState* state, char* state_path); +int process_unlock_command(uint32 instance_id); +/* Agent to DN connection */ +int process_lock_no_primary_command(uint32 instance_id); +int process_lock_chosen_primary_command(cm_to_agent_lock2* msg_type_lock2_ptr); +int check_datanode_status(const char* pid_path, int* role); + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_datanode_utils.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_datanode_utils.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_datanode_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_datanode_utils.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,73 @@ +/** + * @file cma_datanode_utils.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_DATANODE_UTILS_H +#define CMA_DATANODE_UTILS_H + +#include "libpq/libpq-int.h" +#include "libpq/libpq-fe.h" +#include "cma_main.h" + + +#define close_and_reset_connection(conn) \ + if (conn != NULL) { \ + closePGconn(conn); \ + freePGconn(conn); \ + conn = NULL; \ + } + +#define CLOSE_CONNECTION(con) \ + do { \ + close_and_reset_connection(con); \ + assert(NULL == con); \ + return -1; \ + } while (0) + +#define CLEAR_AND_CLOSE_CONNECTION(node_result, con) \ + do { \ + PQclear(node_result); \ + close_and_reset_connection(con); \ + assert(NULL == con); \ + return -1; \ + } while (0) + + +int GetAllDatabaseInfo(int index, DNDatabaseInfo **dnDatabaseInfo, int *dnDatabaseCount); +int GetDBTableFromSQL(int index, uint32 databaseId, uint32 tableId, uint32 tableIdSize, + DNDatabaseInfo *dnDatabaseInfo, int dnDatabaseCount, char* databaseName, char* tableName); +int cmagent_execute_query_and_check_result(PGconn* db_connection, const char* run_command); +int cmagent_execute_query(PGconn* db_connection, const char* run_command); + +const int MAXCONNINFO = 1024; +extern PGconn* DN_conn[CM_MAX_DATANODE_PER_NODE]; +extern THR_LOCAL PGconn* g_Conn; + +extern void check_parallel_redo_status_by_file( + agent_to_cm_datanode_status_report* report_msg, uint32 ii, char* redo_state_path); +extern int check_datanode_status_by_SQL0(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL1(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL2(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL3(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern int check_datanode_status_by_SQL4(agent_to_cm_datanode_status_report* report_msg, uint32 ii); +extern void check_datanode_status_by_SQL5(agent_to_cm_datanode_status_report* report_msg, uint32 ii, char* data_path); +extern int check_datanode_status_by_SQL6( + agent_to_cm_datanode_status_report* report_msg, uint32 ii, const char* data_path); +extern int cmagent_execute_query(PGconn* db_connection, const char* run_command); +extern int cmagent_execute_query_and_check_result(PGconn* db_connection, const char* run_command); + +extern int cmagent_to_coordinator_connect(const char* pid_path); +uint32 find_cn_active_info_index(agent_to_cm_coordinate_status_report_old* report_msg, uint32 coordinatorId); +extern int is_cn_connect_ok(uint32 coordinatorId); +extern int datanode_rebuild_reason_enum_to_int(HaRebuildReason reason); +extern PGconn* get_connection(const char* pid_path, bool isCoordinater = false, int connectTimeOut = 5); +extern LocalMaxLsnMng g_LMLsn[CM_MAX_DATANODE_PER_NODE]; + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_global_params.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_global_params.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_global_params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_global_params.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,232 @@ +/** + * @file cma_global_params.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_GLOBAL_PARAMS_H +#define CMA_GLOBAL_PARAMS_H + +#include "cm/cm_c.h" +#include "cm/cm_misc.h" +#include "cm/etcdapi.h" +#include "cma_main.h" + +typedef enum MAINTENANCE_MODE_ { + MAINTENANCE_MODE_NONE = 0, + MAINTENANCE_MODE_UPGRADE, + MAINTENANCE_MODE_UPGRADE_OBSERVATION, + MAINTENANCE_MODE_DILATATION, +} maintenance_mode; + +#define CM_SERVER_DATA_DIR "cm_server" +#define CM_INSTANCE_REPLACE "instance_replace" +#define PROC_NET_TCP "/proc/net/tcp" + +/* + * ssh connect does not exit automatically when the network is fault, + * this will cause cm_ctl hang for several hours, + * so we should add the following timeout options for ssh. + */ +#define SSH_CONNECT_TIMEOUT "5" +#define SSH_CONNECT_ATTEMPTS "3" +#define SSH_SERVER_ALIVE_INTERVAL "15" +#define SSH_SERVER_ALIVE_COUNT_MAX "3" +#define PSSH_TIMEOUT_OPTION \ + " -t 60 -O ConnectTimeout=" SSH_CONNECT_TIMEOUT " -O ConnectionAttempts=" SSH_CONNECT_ATTEMPTS \ + " -O ServerAliveInterval=" SSH_SERVER_ALIVE_INTERVAL " -O ServerAliveCountMax=" SSH_SERVER_ALIVE_COUNT_MAX " " + +/* UDF_DEFAULT_MEMORY is 200*1024 kB */ +/* Must be same as UDF_DEFAULT_MEMORY in memprot.h and udf_memory_limit in cluster_guc.conf */ +#define UDF_DEFAULT_MEMORY (200 * 1024) +#define AGENT_RECV_CYCLE (200 * 1000) +#define AGENT_REPORT_ETCD_CYCLE 600 +#define INSTANCE_ID_LEN 8 +#define SINGLE_INSTANCE 0 +#define SINGLE_NODE 1 +#define ALL_NODES 2 +#define COMM_PORT_TYPE_DATA 1 +#define COMM_PORT_TYPE_CTRL 2 +#define MAX_RETRY_TIME 10 +#define MAX_INSTANCE_BUILD 3 +#define COMM_DATA_DFLT_PORT 7000 +#define COMM_CTRL_DFLT_PORT 7001 + +#define INSTANCE_START_CYCLE 20 +#define INSTANCE_BUILD_CYCLE 10 + +#define STARTUP_DN_CHECK_TIMES 3 +#define STARTUP_CN_CHECK_TIMES 3 +#define STARTUP_GTM_CHECK_TIMES 3 +#define STARTUP_CMS_CHECK_TIMES 3 + +#define LISTEN 10 + +extern struct passwd* pw; +extern FILE* lockfile; +extern EtcdSession g_sess; +extern cm_instance_central_node g_central_node; +extern gtm_status_info gtm_report_msg; +extern coordinate_status_info cn_report_msg; +extern datanode_status_info dn_report_msg[CM_MAX_DATANODE_PER_NODE]; +extern etcd_status_info etcd_report_msg; +extern kerberos_status_info g_kerberos_report_msg; +/* Enable the datanode incremental build mode */ +extern volatile bool incremental_build; +extern volatile bool security_mode; +extern bool enable_xc_maintenance_mode; +extern char sys_log_path[MAX_PATH_LEN]; +extern FILE* syslogFile; +extern LocalMaxLsnMng g_LMLsn[CM_MAX_DATANODE_PER_NODE]; +extern pthread_t g_repair_cn_thread; +extern struct timeval gServerHeartbeatTime; +extern struct timeval gDisconnectTime; + +extern EtcdTlsAuthPath g_tlsPath; +extern pthread_t g_thread_id[CM_MAX_DATANODE_PER_NODE + 5]; +extern syscalllock cmagent_env_lock; + +extern const char* progname; +extern char configDir[MAX_PATH_LEN]; +extern char bin_path[MAX_PATH_LEN]; +extern char cmagent_lockfile[MAX_PATH_LEN]; +extern char run_long_command[MAX_LOGIC_DATANODE * CM_NODE_NAME + 64]; +extern char cn_name_buf[MAXPGPATH]; +extern char logic_cluster_list_path[MAXPGPATH]; +extern char system_call_log_name[MAXPGPATH]; +extern char result_path[MAX_PATH_LEN]; +extern char cm_agent_log_path[MAX_PATH_LEN]; +extern char cm_static_configure_path[MAX_PATH_LEN]; +extern char cm_manual_start_path[MAX_PATH_LEN]; +extern char cm_instance_manual_start_path[MAX_PATH_LEN]; +extern char cm_resuming_cn_stop_path[MAX_PATH_LEN]; +extern int datanode_num; +extern char datanode_names[MAX_LOGIC_DATANODE][CM_NODE_NAME]; +extern char datanode_name_oids[MAX_LOGIC_DATANODE][CM_NODE_NAME]; +extern char system_alarm_log[MAXPGPATH]; +extern char dn_name_buf[MAX_LOGIC_DATANODE * CM_NODE_NAME]; +extern char node_group_members1[MAX_NODE_GROUP_MEMBERS_LEN]; +extern char node_group_members2[MAX_NODE_GROUP_MEMBERS_LEN]; +extern char cm_cluster_resize_path[MAX_PATH_LEN]; +extern char cm_cluster_replace_path[MAX_PATH_LEN]; +extern char system_call_log[MAXPGPATH]; +extern char g_unix_socket_directory[MAXPGPATH]; +extern char log_base_path[MAXPGPATH]; +extern char g_enable_cn_auto_repair[10]; +extern char g_enableOnlineOrOffline[10]; +extern char g_enableLogCompress[10]; +extern char instance_maintance_path[MAX_PATH_LEN]; + +extern volatile bool g_repair_cn; +extern bool shutdown_request; +extern bool g_sync_dropped_coordinator; +extern bool exit_flag; +extern bool cm_do_force; /* stop by force */ +extern bool g_pgxc_node_consist; +extern bool cm_agent_first_start; +extern bool cm_static_config_need_verify_to_coordinator; +extern bool cm_server_need_reconnect; +extern bool cm_agent_need_alter_pgxc_node; +extern bool cm_agent_need_check_libcomm_port; +extern bool is_cma_building_dn[CM_MAX_DATANODE_PER_NODE]; +extern bool needUpdateSecboxConf; +extern bool gtm_disk_damage; +extern bool cn_disk_damage; +extern bool cms_disk_damage; +extern bool fenced_UDF_stopped; +extern bool cn_nic_down; +extern bool cms_nic_down; +extern bool gtm_nic_down; +extern bool dn_disk_damage[CM_MAX_DATANODE_PER_NODE]; +extern bool dn_build[CM_MAX_DATANODE_PER_NODE]; +extern bool nic_down[CM_MAX_DATANODE_PER_NODE]; +extern bool g_cm_server_instance_pending; +extern bool cm_agent_first_start; +extern bool isStart; +extern bool suppressAlarm; +extern bool g_need_reload_active; + +extern const uint32 AGENT_WATCH_DOG_THRESHOLD; +/* cm_agent config parameters */ +extern uint32 agent_report_interval; +extern uint32 agent_heartbeat_timeout; +extern uint32 agent_connect_timeout; +extern uint32 agent_connect_retries; +extern uint32 agent_check_interval; +extern uint32 agent_kill_instance_timeout; +extern uint32 agent_kerberos_status_check_interval; +extern uint32 agentDiskUsageStatusCheckTimes; +extern uint32 cn_auto_repair_delay; +extern uint32 dilatation_shard_count_for_disk_capacity_alarm; +extern uint32 g_check_disc_instance_now; +extern uint32 g_nodeId; +extern uint32 g_health_cn_for_repair; +extern uint32 agent_phony_dead_check_interval; +extern uint32 g_agentToDb; +extern uint32 thread_dead_effective_time; +extern uint32 enable_gtm_phony_dead_check; +extern uint32 g_cmaConnectCmsInOtherNodeCount; +extern uint32 g_cmaConnectCmsPrimaryInLocalNodeCount; +extern uint32 g_cmaConnectCmsInOtherAzCount; +extern uint32 g_cmaConnectCmsPrimaryInLocalAzCount; +extern uint32 dn_build_check_times[CM_MAX_DATANODE_PER_NODE]; +extern uint32 g_node_index_for_cm_server[CM_PRIMARY_STANDBY_NUM]; + +extern const int cn_repair_build_full; +extern const int cn_repair_build_incre; +extern int cm_shutdown_level; /* cm_ctl stop single instance, single node or all nodes */ +extern int cm_shutdown_mode; /* fast shutdown */ +extern int cn_frequent_restart_counts; +extern int g_CnDnPairsCount; +extern int is_catalog_changed; +extern int g_currenPgxcNodeNum; +extern int normalStopTryTimes; +extern int gtm_start_counts; +extern int co_start_counts; +extern int dn_start_counts[CM_MAX_DATANODE_PER_NODE]; +extern int primary_dn_restart_counts[CM_MAX_DATANODE_PER_NODE]; +extern int primary_dn_restart_counts_in_hour[CM_MAX_DATANODE_PER_NODE]; + +extern int startCMSCount; +extern int startCNCount; +extern int startDNCount[CM_MAX_DATANODE_PER_NODE]; +extern int startGTMCount; +extern int g_clean_drop_cn_flag; +extern int g_cm_server_instance_status; +extern int g_dn_role_for_phony_dead[CM_MAX_DATANODE_PER_NODE]; +extern int g_gtm_role_for_phony_dead; +extern int g_cn_state_for_phony_dead; +extern int g_dn_phony_dead_times[CM_MAX_DATANODE_PER_NODE]; +extern int g_gtm_phony_dead_times; +extern int g_cn_phony_dead_times; +extern volatile uint32 g_cn_dn_disconnect_times; + +extern int64 log_max_size; +extern uint32 log_max_count; +extern uint32 log_saved_days; +extern uint32 log_threshold_check_interval; +extern long g_check_disc_state; +extern long g_thread_state[CM_MAX_DATANODE_PER_NODE + 5]; +extern uint32 g_serverNodeId; +#define FENCE_TIMEOUT (agent_connect_retries * (agent_connect_timeout + agent_report_interval)) + +#ifdef __aarch64__ +extern uint32 agent_process_cpu_affinity; +extern uint32 g_datanode_primary_and_standby_num; +extern uint32 g_datanode_primary_num; +extern uint32 total_cpu_core_num; +extern bool g_dn_report_msg_ok; +/* cm_agent start_command parameters */ +#define PHYSICAL_CPU_NUM (1 << agent_process_cpu_affinity) +#define CPU_AFFINITY_MAX 2 +#endif + +bool find_instance_by_id( + uint32 instanceId, int* instance_type, uint32* node, uint32* node_index, uint32* instance_index); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_gtm.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_gtm.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_gtm.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_gtm.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_GTM_H +#define CMA_GTM_H + +#include "gtm/gtm_c.h" +#include "gtm/utils/libpq-fe.h" +#include "cm/cm_c.h" + +extern void* GtmModeMain(void* arg); +extern GTM_Conn* GetConnectionToGTM(char gtm_pid_file[MAXPGPATH], int connectTimeOut = 5); +extern void CloseGTMConnection(GTM_Conn* conn); + +/* this is used for cm_agent to query gtm status. */ +extern int query_gtm_status(GTM_Conn* conn, int* server_mode, int* connection_status, GlobalTransactionId* pxid, + long* send_count, long* receive_count, int* sync_mode); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_instance_management.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_instance_management.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_instance_management.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_instance_management.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,37 @@ +/** + * @file cma_instance_management.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_INSTANCE_MANAGEMENT_H +#define CMA_INSTANCE_MANAGEMENT_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +#define MAX_BUF_LEN 10 +#define CHECK_DN_BUILD_TIME 25 + +void start_coordinator(); +void kill_instance_force(const char* data_path, InstanceTypes ins_type); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); +void immediate_shutdown_nodes(bool kill_cmserver, bool kill_cn); +void* agentStartAndStopMain(void* arg); + +bool ExecuteCmdWithResult(char* cmd, char* result); +bool getnicstatus(uint32 listen_ip_count, char ips[][CM_IP_LENGTH]); +bool Is_cluster_replacing(void); +bool Is_cluster_resizing(void); + +int agentCheckPort(uint32 port); + +uint32 GetLibcommPort(const char* file_path, uint32 base_port, int port_type); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_log_management.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_log_management.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_log_management.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_log_management.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,31 @@ +/** + * @file cma_log_management.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_LOG_MANAGEMENT_H +#define CMA_LOG_MANAGEMENT_H + +/* compress buffer size */ +#define GZ_BUFFER_LEN 65535 +/* + * trace will be deleted directly if exceeded LOG_GUARD_COUNT + * the priority of this guard higher than save days but lower than maximum capacity + */ +#define LOG_GUARD_COUNT 20000 +#define LOG_GUARD_COUNT_BUF 21000 + +/* Initialize log pattern and log count when started */ +extern LogPattern* logPattern; +extern uint32 len; + +int isLogFile(char* fileName); +int get_log_pattern(); +void* CompressAndRemoveLogFile(void* arg); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_main.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_main.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_main.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_main.h 2020-12-12 17:06:43.171347058 +0800 @@ -0,0 +1,228 @@ +/** + * @file cma_main.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-11 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_MAIN_H +#define CMA_MAIN_H + + +#include "common/config/cm_config.h" +#include "alarm/alarm.h" +#include "cm/elog.h" +#include "cm/cm_msg.h" +#include "cma_alarm.h" + +#define STOP_PRIMARY_RESULT "stop_primary_result" +#define CHECK_VERSION_RESULT "check_version_result" + +#define CM_AGENT_LOG_FILE "cm_agent.log" +#define CM_STATIC_CONFIG_FILE "cluster_static_config" +#define CM_CLUSTER_MANUAL_START "cluster_manual_start" +#define CM_INSTANCE_MANUAL_START "instance_manual_start" +#define CM_RESUMING_CN_STOP "resuming_cn_stop" +#define CM_CLUSTER_RESIZE "cluster_resize.progress" +#define CM_CLUSTER_REPLACE "cluster_replace.progress" +#define LOGIC_CLUSTER_LIST "logic_cluster_name.txt" +#define CM_AGENT_DATA_DIR "cm_agent" +#define INSTANCE_MAINTANCE "instance_maintance" +#define SYSTEM_CALL_LOG "system_call" +#define MAX_LOGFILE_TIMESTAMP "99991231235959" + +#define CONN_FAIL_TIMES 3 +#define MAX_PATH_LEN 1024 +/*time style length*/ +#define MAX_TIME_LEN 20 +const int cn_repair_retry_times = 3; +/* interval set to 10s to reduce invalid log */ +const uint32 g_check_dn_sql5_interval = 10; + +typedef long pgpid_t; + +/* These global variables are used to compressed traces */ +typedef struct LogFile { + char fileName[MAX_PATH_LEN]; + char basePath[MAX_PATH_LEN]; + char pattern[MAX_TIME_LEN]; + char timestamp[MAX_TIME_LEN]; + int64 fileSize; +} LogFile; + +/* Log pattern for compress */ +typedef struct LogPattern { + char patternName[MAX_PATH_LEN]; +} LogPattern; + +/* get local max lsn */ +typedef struct LocalMaxLsnMng { + bool checked; + XLogRecPtr max_lsn; +} LocalMaxLsnMng; + +/* get dn database info */ +typedef struct DNDatabaseInfo { + char dbname[NAMEDATALEN]; + uint32 oid; +} DNDatabaseInfo; + +/* + * Cut time from trace name. + * This time will be used to sort traces. + */ +void cutTimeFromFileLog(const char* fileName, char* pattern, char* time); +/* + * Sort of trace file by time asc. + * This time is part of trace name. + */ +void sortLogFileByTimeAsc(LogFile* logFile, int low, int high); + +/* + * get the mode of the cluster. + */ +void get_start_mode(char* config_file); + +/* + * used for connection mode or option between cm_agent and cn/dn. + */ +void get_connection_mode(char* config_file); + +/* + * Read parameter from cm_agent.conf by accurate parameter name. + */ +int get_config_param(const char* config_file, const char* srcParam, char* destParam, int destLen); + +/* + * Compressed trace to gz by zlib. + * The gzread() function shall read data from the compressed file referenced by file, + * which shall have been opened in a read mode (see gzopen() and gzdopen()). The gzread() + * function shall read data from file, and * uncompress it into buf. At most, len + * bytes of uncompressed data shall be copied to buf. If the file is not compressed, + * gzread() shall simply copy data from file to buf without alteration. + * The gzwrite() function shall write data to the compressed file referenced by file, which shall + * have been opened in a write mode (see gzopen() and gzdopen()). On entry, buf shall point to a + * buffer containing lenbytes of uncompressed data. The gzwrite() function shall compress this + * data and write it to file. The gzwrite() function shall return the number of uncompressed + * bytes actually written. + */ + +int GZCompress(char* inpath, char* outpath); + +/* + * Get trace pattern from cm_agent.conf. + * All trace pattern to be compressed are defined in cm_agent.conf. + */ + +/* + * Create compress and remove thread for trace. + * Use Thread for this task avoid taking too much starting time of cm server. + */ +void CreateLogFileCompressAndRemoveThread(const char* patternName); + +/* + * Read all traces by log pattern,including zip file and non zip file. + * Trace information are file time,file size,file path.These traces are + * saved in the global variable. + */ +int readFileList(char* basePath, LogFile* logFile, uint32* count, int64* totalSize); +/* + * Remove a file. + * It's always used to remove a trace compressed. + */ +void delLogFile(const char* fileName); +extern int check_datanode_status_phony_dead(char pid_path[MAXPGPATH], int agentCheckTimeInterval); + +typedef enum { STARTING, ALL_NORMAL, INSTANCE_NEED_REPAIR, ALL_PENDING } ClusterStatus; + +typedef enum { INSTANCE_CN, INSTANCE_DN, INSTANCE_GTM, INSTANCE_CM, INSTANCE_FENCED, INSTANCE_KERBEROS} InstanceTypes; + +typedef enum { DOWN, PRIMARY, STANDBY, PENDING } InstanceStatus; + +typedef enum { UNKNOWN_HA_STATE, NORMAL_HA_STATE, NEED_REPAIR, BUILD } HAStatus; + +typedef enum { NA, SYSTEM_MARK_INCONSISTENT, TIMELINE_INCONSISTENT, LOG_NOT_EXIST } BuildReason; + +typedef enum { SMART_MODE, FAST_MODE, IMMEDIATE_MODE, RESUME_MODE } ShutdownMode; + +typedef enum { INSTANCE_START, INSTANCE_STOP } OperateType; + +typedef struct InstanceStatusReport { + uint32 node; + + char DataPath[CM_PATH_LENGTH]; + uint32 type; + uint32 InstanceStatus; + + char LogPath[CM_PATH_LENGTH]; + uint32 HAStatus; + uint32 reason; +} InstanceStatusReport; + +typedef enum { NORMAL, UNKNOWN } CoordinateStatus; + +typedef struct NodeStatusReport { + uint32 node; + char nodeName[CM_NODE_NAME]; + uint32 isCn; + uint32 CoordinateStatus; + uint32 isGtm; + InstanceStatusReport gtm; + uint32 datanodesNum; + InstanceStatusReport datanodes[CM_MAX_DATANODE_PER_NODE]; +} NodeStatusReport; + +typedef struct datanode_failover { + bool datanodes[CM_MAX_DATANODE_PER_NODE]; + bool coordinator; +} datanode_failover; + +typedef struct gtm_failover { + bool gtmnodes; + bool coordinator; +} gtm_failover; + +typedef struct coordinator_status { + int cn_status; + bool delayed_repair; +} coordinator_status; + +extern volatile bool g_repair_cn; +extern coordinator_status* g_cn_status; +extern bool* g_coordinators_drop; +extern pthread_rwlock_t g_coordinators_drop_lock; +extern uint32* g_dropped_coordinatorId; +extern bool g_coordinators_cancel; +extern pthread_rwlock_t g_coordinators_cancel_lock; +extern cm_instance_central_node_msg g_ccn_notify; + +/* Control whether agent request cluster state */ +extern bool pooler_ping_end_request; +/* Control whether agent close the pooler ping switch */ +extern bool pooler_ping_end; + +extern datanode_failover* g_datanodes_failover; +extern gtm_failover* g_gtms_failover; +extern pthread_rwlock_t g_datanodes_failover_lock; +extern pthread_rwlock_t g_gtms_failover_lock; +extern int g_gtmMode; + +extern int datanode_status_check_and_report_wrapper(agent_to_cm_datanode_status_report* report_msg, uint32 ii, + char* data_path, bool do_build, uint32 check_dn_sql5_timer); +extern int node_match_find(char* node_type, const char* node_port, const char* node_host, char* node_port1, + char* node_host1, int* node_index, int* instance_index, int* inode_type); +extern int check_one_instance_status(const char *process_name, const char *cmd_line, int *isPhonyDead); +extern void report_conn_fail_alarm(AlarmType alarmType, InstanceTypes instance_type, uint32 instanceId); +extern int get_connection_to_coordinator(); +typedef bool (*IsResultExpectedFunPtr)(const void*); +int cmagent_to_coordinator_execute_query(char* run_command, IsResultExpectedFunPtr IsResultExpected = NULL); +bool IsResultExpectedPoolReload(const void* result); + +#ifdef __aarch64__ +void process_bind_cpu(uint32 instance_index, uint32 primary_dn_index, pgpid_t pid); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_phony_dead_check.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_phony_dead_check.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_phony_dead_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_phony_dead_check.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_phony_dead_check.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_PHONY_DEAD_CHECK_H +#define CMA_PHONY_DEAD_CHECK_H + +void* DNPhonyDeadStatusCheckMain(void * const arg); +void* CNPhonyDeadStatusCheckMain(void* arg); +void* GTMPhonyDeadStatusCheckMain(void* arg); +void* FaultDetectMain(void* arg); + + + + + + + + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_process_messages.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_process_messages.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_process_messages.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_process_messages.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,27 @@ +/** + * @file cma_process_messages.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMA_PROCESS_MESSAGES_H +#define CMA_PROCESS_MESSAGES_H + +#ifndef CM_IP_LENGTH +#define CM_IP_LENGTH 128 +#endif + +void* SendCmsMsgMain(void* arg); +void immediate_stop_one_instance(const char* instance_data_path, InstanceTypes instance_type); +void kill_instance_force(const char* data_path, InstanceTypes ins_type); +int search_HA_node(uint32 loal_port, uint32 LocalHAListenCount, char LocalHAIP[][CM_IP_LENGTH], uint32 Peer_port, + uint32 PeerHAListenCount, char PeerHAIP[][CM_IP_LENGTH], uint32* node_index, uint32* instance_index, + uint32 loal_role); +char* get_logicClusterName_by_dnInstanceId(uint32 dnInstanceId); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_status_check.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_status_check.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_status_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_status_check.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,46 @@ +/** + * @file cma_status_check.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_STATUS_CHECK_H +#define CMA_STATUS_CHECK_H + +#define DN_RESTART_COUNT_CHECK_TIME 600 +#define DN_RESTART_COUNT_CHECK_TIME_HOUR 3600 + +#define MAX_DEVICE_DIR 1024 +#define FILE_CPUSTAT "/proc/stat" +#define FILE_DISKSTAT "/proc/diskstats" +#define FILE_MOUNTS "/proc/mounts" + +#define ETCD_NODE_UNHEALTH_FRE 15 +#define CHECK_INVALID_ETCD_TIMES 15 + +/* when report_interval has changed to bigger ,this number 3 will also change */ +#define CHECK_DUMMY_STATE_TIMES 3 + +void gtm_status_check_and_report(void); +void coordinator_status_check_and_report(void); +void datanode_status_check_and_report(void); +void fenced_UDF_status_check_and_report(void); +void etcd_status_check_and_report(void); +void kerberos_status_check_and_report(); +void CheckDiskForCNDataPathAndReport(); +void CheckDiskForDNDataPathAndReport(); + +void* ETCDStatusCheckMain(void* arg); +void* GTMStatusCheckMain(void* arg); +void* DNStatusCheckMain(void * const arg); +void* CNStatusCheckMain(void* arg); +void* CCNStatusCheckMain(void* const arg); +void* KerberosStatusCheckMain(void* const arg); + +void* CNDnDisconnectCheckMain(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_threads.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_threads.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_threads.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,32 @@ +/** + * @file cma_thread.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-01 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMA_THREADS_H +#define CMA_THREADS_H + +void CreateETCDStatusCheckThread(); +void CreatePhonyDeadCheckThread(); +void CreateCnDnDisconnectCheckThread(); +void CreateStartAndStopThread(); +void CreateGTMStatusCheckThread(); +void CreateCNStatusCheckThread(); +void CreateCCNStatusCheckThread(void); +void CreateDNStatusCheckThread(int* i); +void CreateDNXlogCheckThread(int* i); +void CreateDNStorageScalingAlarmThread(int* i); +void CreateFaultDetectThread(); +void CreateGtmModeThread(); +void CreateConnCmsPThread(); +void CreateSendCmsMsgThread(); +void CreateKerberosStatusCheckThread(); +void CreateAutoRepairCnThread(); +void CreateLogFileCompressAndRemoveThread(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_xlog.h postgresql-hll-2.14/include/include/cm/cm_agent/cma_xlog.h --- postgresql-hll-2.14_old/include/include/cm/cm_agent/cma_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_agent/cma_xlog.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,70 @@ +/** + * @file cma_xlog.h + * @brief Define functions of reading xlog for agent. + * @author xxx + * @version 1.0 + * @date 2020-08-03 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + + +#ifndef CMA_XLOG_H +#define CMA_XLOG_H + +#include "access/xlog_basic.h" + +typedef struct AgentXLogPageReadPrivate { + const char* datadir; + TimeLineID tli; +} AgentXLogPageReadPrivate; + +typedef struct AgentXlogFileList { + AgentXlogFileList* next; + char* filename; +} AgentXlogFileList; + +void* DNXlogCheckMain(void * const arg); + +/* + * Allocate and initialize a new XLogReader. + * + * Returns NULL if the xlogreader couldn't be allocated. + */ +extern XLogReaderState* AgentXLogReaderAllocate(XLogPageReadCB pagereadfunc, void* private_data); + +/* + * Find the first record with at an lsn >= RecPtr. + * + * Useful for checking wether RecPtr is a valid xlog address for reading and to + * find the first valid address after some address when dumping records for + * debugging purposes. + */ +extern XLogRecPtr AgentXLogFindNextRecord(XLogReaderState* state, XLogRecPtr RecPtr); + +/* + * Attempt to read an XLOG record. + * + * If RecPtr is not NULL, try to read a record at that position. Otherwise + * try to read a record just after the last one previously read. + * + * If the page read callback fails to read the requested data, NULL is + * returned. The callback is expected to have reported the error; errormsg + * is set to NULL. + * + * If the reading fails for some other reason, NULL is also returned, and + * *errormsg is set to a string with details of the failure. + * + * The returned pointer (or *errormsg) points to an internal buffer that's + * valid until the next call to XLogReadRecord. + */ +extern XLogRecord* AgentXLogReadRecord( + XLogReaderState* state, XLogRecPtr RecPtr, char** errormsg, bool readoldversion = false); + +/* + * Free the xlog reader memory. + */ +extern void AgentXLogReaderFree(XLogReaderState* state); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_cgroup.h postgresql-hll-2.14/include/include/cm/cm_cgroup.h --- postgresql-hll-2.14_old/include/include/cm/cm_cgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_cgroup.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_cgroup.h + * + * + * + * IDENTIFICATION + * src/include/cm/cm_cgroup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_CGROUP_H +#define CM_CGROUP_H +#ifdef ENABLE_MULTIPLE_NODES +/* get the cm cgroup relpath and initialize cgroup. + * Please note,caller should free the return value. + */ +extern char* gscgroup_cm_init(); + +/* make the current thread attach to cm cgroup */ +extern void gscgroup_cm_attach_task(const char* relpath); +extern void gscgroup_cm_attach_task_pid(const char* relpath, pid_t tid); +#endif +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_c.h postgresql-hll-2.14/include/include/cm/cm_c.h --- postgresql-hll-2.14_old/include/include/cm/cm_c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_c.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,134 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_c.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_C_H +#define CM_C_H + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#include +#include +#include +#include +#include "c.h" +#include "cm/cm_misc.h" +#include "securec.h" +#include "securec_check.h" + +#ifdef PC_LINT +#ifndef Assert +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#endif /* Assert */ +#else +#ifndef USE_ASSERT_CHECKING +#ifndef Assert +#define Assert(condition) +#endif /* Assert */ +#else +#ifdef Assert +#undef Assert +#endif +#ifndef Assert +#define Assert(condition) assert(condition) +#endif /* Assert */ +#endif +#endif +/* Possible type of nodes for registration */ +typedef enum CM_PGXCNodeType { + CM_NODE_GTM_PROXY = 1, + CM_NODE_GTM_PROXY_POSTMASTER = 2, + /* Used by Proxy to communicate with GTM and not use Proxy headers */ + CM_NODE_COORDINATOR = 3, + CM_NODE_DATANODE = 4, + CM_NODE_GTM = 5, + CM_NODE_DEFAULT = 6 /* In case nothing is associated to connection */ +} CM_PGXCNodeType; + +typedef enum CM_PortLastCall { + CM_LastCall_NONE = 0, + CM_LastCall_SEND, + CM_LastCall_RECV, + CM_LastCall_READ, + CM_LastCall_WRITE +} CM_PortLastCall; + +#define TCP_SOCKET_ERROR_EPIPE (-2) +#define TCP_SOCKET_ERROR_NO_MESSAGE (-3) +#define TCP_SOCKET_ERROR_NO_BUFFER (-4) +#define TCP_SOCKET_ERROR_INVALID_IP (-5) + +/* Define max size of user in start up packet */ +#define SP_USER 32 + +/* Define max size of node name in start up packet */ +#define SP_NODE_NAME 64 +#define MAX_PATH_LEN 1024 + +/* Define max size of host in start up packet */ +#define SP_HOST 16 + +typedef struct CM_StartupPacket { + char sp_user[SP_USER]; + char sp_node_name[SP_NODE_NAME]; + char sp_host[SP_HOST]; + int node_id; + int sp_remotetype; + bool sp_ispostmaster; +} CM_StartupPacket; + +#define _(x) gettext(x) + +#define MAX_NODE_GROUP_MEMBERS_LEN (CM_NODE_MAXNUM * LOGIC_DN_PER_NODE * (CM_NODE_NAME + 1)) + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) \ + do { \ + if (NULL != (ptr)) { \ + free(ptr); \ + (ptr) = NULL; \ + } \ + } while (0) +#endif + +#endif /* GTM_C_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_ip.h postgresql-hll-2.14/include/include/cm/cm_ip.h --- postgresql-hll-2.14_old/include/include/cm/cm_ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_ip.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_ip.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_IP_H +#define CM_IP_H + +#include "cm/pqcomm.h" + +extern int cm_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void cm_freeaddrinfo_all(int hint_ai_family, struct addrinfo* ai); + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* CM_IP_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_misc.h postgresql-hll-2.14/include/include/cm/cm_misc.h --- postgresql-hll-2.14_old/include/include/cm/cm_misc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_misc.h 2020-12-12 17:06:43.172347071 +0800 @@ -0,0 +1,222 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_misc.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/cm_misc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_MISC_H +#define CM_MISC_H + +#include "utils/syscall_lock.h" +#include "cm/etcdapi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct instance_not_exist_reason_string { + const char* level_string; + int level_val; +} instance_not_exist_reason_string; + +typedef struct log_level_string { + + const char* level_string; + int level_val; +} log_level_string; + +typedef struct instance_datanode_build_reason_string { + + const char* reason_string; + int reason_val; +} instance_datanode_build_reason_string; + +typedef struct instacne_type_string { + + const char* type_string; + int type_val; +} instacne_type_string; + +typedef struct gtm_con_string { + + const char* con_string; + int con_val; +} gtm_con_string; + +typedef struct instance_coordinator_active_status_string { + + const char* active_status_string; + int active_status_val; +} instance_coordinator_active_status_string; + +typedef struct instance_datanode_lockmode_string { + const char* lockmode_string; + uint32 lockmode_val; +} instance_datanode_lockmode_string; + +typedef struct instacne_datanode_role_string { + + const char* role_string; + uint32 role_val; +} instacne_datanode_role_string; + +typedef struct instacne_datanode_dbstate_string { + + const char* dbstate_string; + int dbstate_val; +} instacne_datanode_dbstate_string; + +typedef struct instacne_datanode_wal_send_state_string { + + const char* wal_send_state_string; + int wal_send_state_val; +} instacne_datanode_wal_send_state_string; + +typedef struct instacne_datanode_sync_state_string { + + const char* wal_sync_state_string; + int wal_sync_state_val; +} instacne_datanode_sync_state_string; + +typedef struct cluster_state_string { + + const char* cluster_state_string; + int cluster_state_val; +} cluster_state_string; + +typedef struct cluster_msg_string { + const char* cluster_msg_str; + int cluster_msg_val; +} cluster_msg_string; + +typedef struct server_role_string { + int role_val; + const char* role_string; +} server_role_string; + +#define LOCK_FILE_LINE_PID 1 +#define LOCK_FILE_LINE_DATA_DIR 2 +#define LOCK_FILE_LINE_START_TIME 3 +#define LOCK_FILE_LINE_PORT 4 +#define LOCK_FILE_LINE_SOCKET_DIR 5 +#define LOCK_FILE_LINE_LISTEN_ADDR 6 +#define LOCK_FILE_LINE_SHMEM_KEY 7 + +#ifndef ERROR_LIMIT_LEN +#define ERROR_LIMIT_LEN 256 +#endif + +/** + * @def SHELL_RETURN_CODE + * @brief Get the shell command return code. + * @return Return the shell command return code. + */ +#define SHELL_RETURN_CODE(systemReturn) \ + (systemReturn > 0 ? static_cast(static_cast(systemReturn) >> 8) : systemReturn) + +extern char** readfile(const char* path); +extern void freefile(char** lines); +extern int log_level_string_to_int(const char* log_level); +extern int datanode_rebuild_reason_string_to_int(const char* reason); +extern const char* instance_not_exist_reason_to_string(int reason); +extern int datanode_lockmode_string_to_int(const char* lockmode); +extern int datanode_role_string_to_int(const char* role); +extern int datanode_dbstate_string_to_int(const char* dbstate); +extern int datanode_wal_send_state_string_to_int(const char* dbstate); +extern int datanode_wal_sync_state_string_to_int(const char* dbstate); +extern const char* log_level_int_to_string(int log_level); +extern const char* cluster_state_int_to_string(int cluster_state); +extern const char* cluster_msg_int_to_string(int cluster_msg); +extern const char* datanode_wal_sync_state_int_to_string(int dbstate); +extern const char * datanode_wal_send_state_int_to_string(int dbstate); + +extern const char* datanode_dbstate_int_to_string(int dbstate); +extern const char* type_int_to_string(int type); +const char* gtm_con_int_to_string(int con); +extern const char* datanode_role_int_to_string(int role); +extern const char* datanode_static_role_int_to_string(uint32 role); +extern const char* datanode_rebuild_reason_int_to_string(int reason); +extern const char* server_role_to_string(int role, bool is_pending); +extern const char* etcd_role_to_string(int role); +extern const char* kerberos_status_to_string(int role); + +extern void cm_sleep(unsigned int sec); +extern void cm_usleep(unsigned int usec); + +extern uint32 get_healthy_etcd_node_count(EtcdTlsAuthPath* tlsPath, int programType); + +extern void check_input_for_security(char* input); +extern void check_env_value(const char* input_env_value); + +extern void print_environ(void); + +/** + * @brief + * Creates a lock file for a process with a specified PID. + * + * @note + * When pid is set to -1, the specified process is the current process. + * + * @param [in] filename + * The name of the lockfile to create. + * @param [in] data_path + * The data path of the instance. + * @param [in] pid + * The pid of the process. + * + * @return + * - 0 Create successfully. + * - -1 Create failure. + */ +extern int create_lock_file(const char* filename, const char* data_path, const pid_t pid = -1); + + +/** + * @brief + * Delete pid file. + * + * @param [in] filename + * The pid file to be deleted. + * + * @return + * void. + */ +extern void delete_lock_file(const char *filename); + +extern void cm_pthread_rw_lock(pthread_rwlock_t* rwlock); +extern void cm_pthread_rw_unlock(pthread_rwlock_t* rwlock); + +extern int cm_getenv( + const char* env_var, char* output_env_value, uint32 env_value_len, syscalllock cmLock, int elevel = -1); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_msg.h postgresql-hll-2.14/include/include/cm/cm_msg.h --- postgresql-hll-2.14_old/include/include/cm/cm_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_msg.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,1339 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_msg.h + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/cm_msg.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_MSG_H +#define CM_MSG_H + +#include "replication/replicainternal.h" +#include "access/xlogdefs.h" +#include "access/redo_statistic_msg.h" +#include "../common/config/cm_config.h" +#include +#include + +#define CM_MAX_SENDER_NUM 2 +#define LOGIC_CLUSTER_NUMBER (32 + 1) ////max 32 logic + 1 elastic group +#define CM_LOGIC_CLUSTER_NAME_LEN 64 +#define CM_MSG_ERR_INFORMATION_LENGTH 1024 +#define MAX_INT32 (2147483600) +#define CN_INFO_NUM 8 +#define RESERVE_NUM 160 +#define RESERVE_NUM_USED 4 + +using std::string; +using std::vector; + +/* + * Symbols in the following enum are usd in cluster_msg_map_string defined in cm_misc.cpp. + * Modifictaion to the following enum should be reflected to cluster_msg_map_string as well. + */ +typedef enum CM_MessageType { + MSG_CTL_CM_SWITCHOVER = 0, + MSG_CTL_CM_BUILD = 1, + MSG_CTL_CM_SYNC = 2, + MSG_CTL_CM_QUERY = 3, + MSG_CTL_CM_NOTIFY = 4, + MSG_CTL_CM_BUTT = 5, + MSG_CM_CTL_DATA_BEGIN = 6, + MSG_CM_CTL_DATA = 7, + MSG_CM_CTL_NODE_END = 8, + MSG_CM_CTL_DATA_END = 9, + MSG_CM_CTL_COMMAND_ACK = 10, + + MSG_CM_AGENT_SWITCHOVER = 11, + MSG_CM_AGENT_FAILOVER = 12, + MSG_CM_AGENT_BUILD = 13, + MSG_CM_AGENT_SYNC = 14, + MSG_CM_AGENT_NOTIFY = 15, + MSG_CM_AGENT_NOTIFY_CN = 16, + MSG_AGENT_CM_NOTIFY_CN_FEEDBACK = 17, + MSG_CM_AGENT_CANCEL_SESSION = 18, + MSG_CM_AGENT_RESTART = 19, + MSG_CM_AGENT_RESTART_BY_MODE = 20, + MSG_CM_AGENT_REP_SYNC = 21, + MSG_CM_AGENT_REP_ASYNC = 22, + MSG_CM_AGENT_REP_MOST_AVAILABLE = 23, + MSG_CM_AGENT_BUTT = 24, + + MSG_AGENT_CM_DATA_INSTANCE_REPORT_STATUS = 25, + MSG_AGENT_CM_COORDINATE_INSTANCE_STATUS = 26, + MSG_AGENT_CM_GTM_INSTANCE_STATUS = 27, + MSG_AGENT_CM_BUTT = 28, + + /**************** =====CAUTION===== ****************: + If you want to add a new MessageType, you should add at the end , + It's forbidden to insert new MessageType at middle, it will change the other MessageType value. + The MessageType is transfered between cm_agent and cm_server on different host, + You should ensure the type value be identical and compatible between old and new versions */ + + MSG_CM_CM_VOTE = 29, + MSG_CM_CM_BROADCAST = 30, + MSG_CM_CM_NOTIFY = 31, + MSG_CM_CM_SWITCHOVER = 32, + MSG_CM_CM_FAILOVER = 33, + MSG_CM_CM_SYNC = 34, + MSG_CM_CM_SWITCHOVER_ACK = 35, + MSG_CM_CM_FAILOVER_ACK = 36, + MSG_CM_CM_ROLE_CHANGE_NOTIFY = 37, + MSG_CM_CM_REPORT_SYNC = 38, + + MSG_AGENT_CM_HEARTBEAT = 39, + MSG_CM_AGENT_HEARTBEAT = 40, + MSG_CTL_CM_SET = 41, + MSG_CTL_CM_SWITCHOVER_ALL = 42, + MSG_CM_CTL_SWITCHOVER_ALL_ACK = 43, + MSG_CTL_CM_BALANCE_CHECK = 44, + MSG_CM_CTL_BALANCE_CHECK_ACK = 45, + MSG_CTL_CM_BALANCE_RESULT = 46, + MSG_CM_CTL_BALANCE_RESULT_ACK = 47, + MSG_CTL_CM_QUERY_CMSERVER = 48, + MSG_CM_CTL_CMSERVER = 49, + + MSG_TYPE_BUTT = 50, + MSG_CM_AGENT_NOTIFY_CN_CENTRAL_NODE = 51, + MSG_CM_AGENT_DROP_CN = 52, + MSG_CM_AGENT_DROPPED_CN = 53, + MSG_AGENT_CM_FENCED_UDF_INSTANCE_STATUS = 54, + MSG_CTL_CM_SWITCHOVER_FULL = 55, /* inform cm agent to do switchover -A */ + MSG_CM_CTL_SWITCHOVER_FULL_ACK = 56, /* inform cm ctl that cm server is doing swtichover -A */ + MSG_CM_CTL_SWITCHOVER_FULL_DENIED = 57, /* inform cm ctl that switchover -A is denied by cm server */ + MSG_CTL_CM_SWITCHOVER_FULL_CHECK = 58, /* cm ctl inform cm server to check if swtichover -A is done */ + MSG_CM_CTL_SWITCHOVER_FULL_CHECK_ACK = 59, /* inform cm ctl that swtichover -A is done */ + MSG_CTL_CM_SWITCHOVER_FULL_TIMEOUT = 60, /* cm ctl inform cm server to swtichover -A timed out */ + MSG_CM_CTL_SWITCHOVER_FULL_TIMEOUT_ACK = 61, /* inform cm ctl that swtichover -A stopped */ + + MSG_CTL_CM_SETMODE = 62, /* new mode */ + MSG_CM_CTL_SETMODE_ACK = 63, + + MSG_CTL_CM_SWITCHOVER_AZ = 64, /* inform cm agent to do switchover -zazName */ + MSG_CM_CTL_SWITCHOVER_AZ_ACK = 65, /* inform cm ctl that cm server is doing swtichover -zazName */ + MSG_CM_CTL_SWITCHOVER_AZ_DENIED = 66, /* inform cm ctl that switchover -zazName is denied by cm server */ + MSG_CTL_CM_SWITCHOVER_AZ_CHECK = 67, /* cm ctl inform cm server to check if swtichover -zazName is done */ + MSG_CM_CTL_SWITCHOVER_AZ_CHECK_ACK = 68, /* inform cm ctl that swtichover -zazName is done */ + MSG_CTL_CM_SWITCHOVER_AZ_TIMEOUT = 69, /* cm ctl inform cm server to swtichover -zazName timed out */ + MSG_CM_CTL_SWITCHOVER_AZ_TIMEOUT_ACK = 70, /* inform cm ctl that swtichover -zazName stopped */ + + MSG_CM_CTL_SET_ACK = 71, + MSG_CTL_CM_GET = 72, + MSG_CM_CTL_GET_ACK = 73, + MSG_CM_AGENT_GS_GUC = 74, + MSG_AGENT_CM_GS_GUC_ACK = 75, + MSG_CM_CTL_SWITCHOVER_INCOMPLETE_ACK = 76, + MSG_CM_CM_TIMELINE = 77, /*when restart cluster , cmserver primary and standy timeline*/ + MSG_CM_BUILD_DOING = 78, + MSG_AGENT_CM_ETCD_CURRENT_TIME = 79, /*etcd clock monitoring message*/ + MSG_CM_QUERY_INSTANCE_STATUS = 80, + MSG_CM_SERVER_TO_AGENT_CONN_CHECK = 81, + MSG_CTL_CM_GET_DATANODE_RELATION = 82, /* depracated for the removal of quick switchover */ + MSG_CM_BUILD_DOWN = 83, + MSG_CTL_CM_HOTPATCH = 84, + MSG_CM_SERVER_REPAIR_CN_ACK = 85, + MSG_CTL_CM_DISABLE_CN = 86, + MSG_CTL_CM_DISABLE_CN_ACK = 87, + MSG_CM_AGENT_LOCK_NO_PRIMARY = 88, + MSG_CM_AGENT_LOCK_CHOSEN_PRIMARY = 89, + MSG_CM_AGENT_UNLOCK = 90, + MSG_CTL_CM_STOP_ARBITRATION = 91, + MSG_CTL_CM_FINISH_REDO = 92, + MSG_CM_CTL_FINISH_REDO_ACK = 93, + MSG_CM_AGENT_FINISH_REDO = 94, + MSG_CTL_CM_FINISH_REDO_CHECK = 95, + MSG_CM_CTL_FINISH_REDO_CHECK_ACK = 96, + MSG_AGENT_CM_KERBEROS_STATUS = 97, + MSG_CTL_CM_QUERY_KERBEROS = 98, + MSG_CTL_CM_QUERY_KERBEROS_ACK = 99, + MSG_AGENT_CM_DISKUSAGE_STATUS = 100 +} CM_MessageType; + +#define UNDEFINED_LOCKMODE 0 +#define POLLING_CONNECTION 1 +#define SPECIFY_CONNECTION 2 +#define PROHIBIT_CONNECTION 3 + +#define INSTANCE_ROLE_INIT 0 +#define INSTANCE_ROLE_PRIMARY 1 +#define INSTANCE_ROLE_STANDBY 2 +#define INSTANCE_ROLE_PENDING 3 +#define INSTANCE_ROLE_NORMAL 4 +#define INSTANCE_ROLE_UNKNOWN 5 +#define INSTANCE_ROLE_DUMMY_STANDBY 6 +#define INSTANCE_ROLE_DELETED 7 +#define INSTANCE_ROLE_DELETING 8 +#define INSTANCE_ROLE_READONLY 9 + +#define INSTANCE_ROLE_FIRST_INIT 1 +#define INSTANCE_ROLE_HAVE_INIT 2 + +#define INSTANCE_DATA_REPLICATION_SYNC 1 +#define INSTANCE_DATA_REPLICATION_ASYNC 2 +#define INSTANCE_DATA_REPLICATION_MOST_AVAILABLE 3 +#define INSTANCE_DATA_REPLICATION_POTENTIAL_SYNC 4 +#define INSTANCE_DATA_REPLICATION_QUORUM 5 +#define INSTANCE_DATA_REPLICATION_UNKONWN 6 + +#define INSTANCE_TYPE_GTM 1 +#define INSTANCE_TYPE_DATANODE 2 +#define INSTANCE_TYPE_COORDINATE 3 +#define INSTANCE_TYPE_FENCED_UDF 4 +#define INSTANCE_TYPE_UNKNOWN 5 + +#define INSTANCE_WALSNDSTATE_STARTUP 0 +#define INSTANCE_WALSNDSTATE_BACKUP 1 +#define INSTANCE_WALSNDSTATE_CATCHUP 2 +#define INSTANCE_WALSNDSTATE_STREAMING 3 +#define INSTANCE_WALSNDSTATE_DUMPLOG 4 +const int INSTANCE_WALSNDSTATE_NORMAL = 5; +const int INSTANCE_WALSNDSTATE_UNKNOWN = 6; + +#define CON_OK 0 +#define CON_BAD 1 +#define CON_STARTED 2 +#define CON_MADE 3 +#define CON_AWAITING_RESPONSE 4 +#define CON_AUTH_OK 5 +#define CON_SETEN 6 +#define CON_SSL_STARTUP 7 +#define CON_NEEDED 8 +#define CON_UNKNOWN 9 +#define CON_MANUAL_STOPPED 10 +#define CON_DISK_DEMAGED 11 +#define CON_PORT_USED 12 +#define CON_NIC_DOWN 13 +#define CON_GTM_STARTING 14 + +#define CM_SERVER_UNKNOWN 0 +#define CM_SERVER_PRIMARY 1 +#define CM_SERVER_STANDBY 2 +#define CM_SERVER_INIT 3 +#define CM_SERVER_DOWN 4 + +#define CM_ETCD_UNKNOWN 0 +#define CM_ETCD_FOLLOWER 1 +#define CM_ETCD_LEADER 2 +#define CM_ETCD_DOWN 3 + +#define SWITCHOVER_UNKNOWN 0 +#define SWITCHOVER_FAIL 1 +#define SWITCHOVER_SUCCESS 2 +#define SWITCHOVER_EXECING 3 +#define SWITCHOVER_PARTLY_SUCCESS 4 +#define SWITCHOVER_ABNORMAL 5 + +#define UNKNOWN_BAD_REASON 0 +#define PORT_BAD_REASON 1 +#define NIC_BAD_REASON 2 +#define DISC_BAD_REASON 3 +#define STOPPED_REASON 4 +#define CN_DELETEED_REASON 5 + +#define KERBEROS_STATUS_UNKNOWN 0 +#define KERBEROS_STATUS_NORMAL 1 +#define KERBEROS_STATUS_ABNORMAL 2 +#define KERBEROS_STATUS_DOWN 3 + +#define HOST_LENGTH 32 +// the length of cm_serer sync msg is 9744, msg type is MSG_CM_CM_REPORT_SYNC +#define CM_MSG_MAX_LENGTH (12288 * 2) + +#define CMAGENT_NO_CCN "NoCentralNode" + +extern int g_gtm_phony_dead_times; +extern int g_dn_phony_dead_times[CM_MAX_DATANODE_PER_NODE]; +extern int g_cn_phony_dead_times; + +typedef enum {DN, CN} GetinstanceType; +typedef struct cm_msg_type { + int msg_type; +} cm_msg_type; + +typedef struct cm_switchover_incomplete_msg { + int msg_type; + char errMsg[CM_MSG_ERR_INFORMATION_LENGTH]; +} cm_switchover_incomplete_msg; + +typedef struct cm_redo_stats { + int is_by_query; + uint64 redo_replayed_speed; + XLogRecPtr standby_last_replayed_read_Ptr; +} cm_redo_stats; + +typedef struct ctl_to_cm_stop_arbitration { + int msg_type; +} ctl_to_cm_stop_arbitration; + +typedef struct ctl_to_cm_switchover { + int msg_type; + char azName[CM_AZ_NAME]; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_switchover; + +typedef struct ctl_to_cm_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_failover; + +typedef struct cm_to_ctl_finish_redo_check_ack { + int msg_type; + int finish_redo_count; +} cm_to_ctl_finish_redo_check_ack; + +typedef struct ctl_to_cm_finish_redo { + int msg_type; +} ctl_to_cm_finish_redo; + +#define CM_CTL_UNFORCE_BUILD 0 +#define CM_CTL_FORCE_BUILD 1 + +typedef struct ctl_to_cm_build { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int force_build; + int full_build; +} ctl_to_cm_build; + +typedef struct ctl_to_cm_query { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int detail; + int relation; +} ctl_to_cm_query; + +typedef struct ctl_to_cm_disable_cn { + int msg_type; + uint32 instanceId; + int wait_seconds; +} ctl_to_cm_disable_cn; + +typedef struct ctl_to_cm_disable_cn_ack { + int msg_type; + bool disable_ok; + char errMsg[CM_MSG_ERR_INFORMATION_LENGTH]; +} ctl_to_cm_disable_cn_ack; + +typedef enum arbitration_mode { + UNKNOWN_ARBITRATION = 0, + MAJORITY_ARBITRATION = 1, + MINORITY_ARBITRATION = 2 +} arbitration_mode; + +typedef enum cm_start_mode { + UNKNOWN_START = 0, + MAJORITY_START = 1, + MINORITY_START = 2, + OTHER_MINORITY_START = 3 +} cm_start_mode; + +typedef enum switchover_az_mode { + UNKNOWN_SWITCHOVER_AZ = 0, + NON_AUTOSWITCHOVER_AZ = 1, + AUTOSWITCHOVER_AZ = 2 +} switchover_az_mode; + +typedef enum logic_cluster_restart_mode { + UNKNOWN_LOGIC_CLUSTER_RESTART = 0, + INITIAL_LOGIC_CLUSTER_RESTART = 1, + MODIFY_LOGIC_CLUSTER_RESTART = 2 +} logic_cluster_restart_mode; + +typedef enum cluster_mode { + INVALID_CLUSTER_MODE = 0, + ONE_MASTER_1_SLAVE, + ONE_MASTER_2_SLAVE, + ONE_MASTER_3_SLAVE, + ONE_MASTER_4_SLAVE, + ONE_MASTER_5_SLAVE +} cluster_mode; + +typedef enum synchronous_standby_mode { + AnyFirstNo = 0, /* don't have */ + AnyAz1, /* ANY 1(az1) */ + FirstAz1, /* FIRST 1(az1) */ + AnyAz2, /* ANY 1(az2) */ + FirstAz2, /* FIRST 1(az2) */ + Any2Az1Az2, /* ANY 2(az1,az2) */ + First2Az1Az2, /* FIRST 2(az1,az2) */ + Any3Az1Az2, /* ANY 3(az1, az2) */ + First3Az1Az2 /* FIRST 3(az1, az2) */ +} synchronous_standby_mode; + +typedef struct ctl_to_cm_set { + int msg_type; + int log_level; + uint32 logic_cluster_delay; + arbitration_mode cm_arbitration_mode; + switchover_az_mode cm_switchover_az_mode; + logic_cluster_restart_mode cm_logic_cluster_restart_mode; +} ctl_to_cm_set, cm_to_ctl_get; + +typedef struct cm_to_agent_switchover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int role; + uint32 term; +} cm_to_agent_switchover; + +typedef struct cm_to_agent_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + uint32 term; +} cm_to_agent_failover; + +typedef struct cm_to_agent_build { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; + int role; + int full_build; + uint32 term; +} cm_to_agent_build; + +typedef struct cm_to_agent_lock1 { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_lock1; + +typedef struct cm_to_agent_lock2 { + int msg_type; + uint32 node; + uint32 instanceId; + char disconn_host[HOST_LENGTH]; + uint32 disconn_port; +} cm_to_agent_lock2; + +typedef struct cm_to_agent_unlock { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_unlock; + +typedef struct cm_to_agent_finish_redo { + int msg_type; + uint32 node; + uint32 instanceId; + bool is_finish_redo_cmd_sent; +} cm_to_agent_finish_redo; + +typedef struct cm_to_agent_gs_guc { + int msg_type; + uint32 node; + uint32 instanceId; + synchronous_standby_mode type; +} cm_to_agent_gs_guc; + +typedef struct agent_to_cm_gs_guc_feedback { + int msg_type; + uint32 node; + uint32 instanceId; /* node of this agent */ + synchronous_standby_mode type; + bool status; /* gs guc command exec status */ +} agent_to_cm_gs_guc_feedback; + +typedef struct cm_to_agent_notify { + int msg_type; + uint32 node; + uint32 instanceId; + int role; + uint32 term; +} cm_to_agent_notify; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_notify_cn { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + int datanodeCount; /* current count of datanode got primaryed */ + uint32 coordinatorId; + int notifyCount; + /* datanode instance id array */ + uint32 datanodeId[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} cm_to_agent_notify_cn; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_drop_cn { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + uint32 coordinatorId; + int role; + bool delay_repair; +} cm_to_agent_drop_cn; + +typedef struct cm_to_agent_notify_cn_central_node { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + char cnodename[NAMEDATALEN]; /* central node id */ + char nodename[NAMEDATALEN]; +} cm_to_agent_notify_cn_central_node; + +/* + * msg struct using for cmserver to cmagent + * including primaryed datanode count and datanode instanceId list. + */ +typedef struct cm_to_agent_cancel_session { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ +} cm_to_agent_cancel_session; + +/* + * msg struct using for cmagent to cmserver + * feedback msg for notify cn. + */ +typedef struct agent_to_cm_notify_cn_feedback { + int msg_type; + uint32 node; /* node of this coordinator */ + uint32 instanceId; /* coordinator instance id */ + bool status; /* notify command exec status */ + int notifyCount; +} agent_to_cm_notify_cn_feedback; + +typedef struct cm_to_agent_restart { + int msg_type; + uint32 node; + uint32 instanceId; +} cm_to_agent_restart; + +typedef struct cm_to_agent_restart_by_mode { + int msg_type; + uint32 node; + uint32 instanceId; + int role_old; + int role_new; +} cm_to_agent_restart_by_mode; + +typedef struct cm_to_agent_rep_sync { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_sync; + +typedef struct cm_to_agent_rep_async { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_async; + +typedef struct cm_to_agent_rep_most_available { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int sync_mode; +} cm_to_agent_rep_most_available; + +typedef struct cm_instance_central_node { + pthread_rwlock_t rw_lock; + pthread_mutex_t mt_lock; + uint32 instanceId; + uint32 node; + uint32 recover; + uint32 isCentral; + uint32 nodecount; + char nodename[NAMEDATALEN]; + char cnodename[NAMEDATALEN]; + char* failnodes; + cm_to_agent_notify_cn_central_node notify; +} cm_instance_central_node; + +typedef struct cm_instance_central_node_msg { + pthread_rwlock_t rw_lock; + cm_to_agent_notify_cn_central_node notify; +} cm_instance_central_node_msg; + +#define MAX_LENGTH_HP_CMD (9) +#define MAX_LENGTH_HP_PATH (256) +#define MAX_LENGTH_HP_RETURN_MSG (1024) + +typedef struct cm_hotpatch_msg { + int msg_type; + char command[MAX_LENGTH_HP_CMD]; + char path[MAX_LENGTH_HP_PATH]; +} cm_hotpatch_msg; + +typedef struct cm_hotpatch_ret_msg { + char msg[MAX_LENGTH_HP_RETURN_MSG]; +} cm_hotpatch_ret_msg; + +#define IP_LEN 64 +#define MAX_REPL_CONNINFO_LEN 256 +#define MAX_REBUILD_REASON_LEN 256 + +const int cn_active_unknown = 0; +const int cn_active = 1; +const int cn_inactive = 2; + +#define INSTANCE_HA_STATE_UNKONWN 0 +#define INSTANCE_HA_STATE_NORMAL 1 +#define INSTANCE_HA_STATE_NEED_REPAIR 2 +#define INSTANCE_HA_STATE_STARTING 3 +#define INSTANCE_HA_STATE_WAITING 4 +#define INSTANCE_HA_STATE_DEMOTING 5 +#define INSTANCE_HA_STATE_PROMOTING 6 +#define INSTANCE_HA_STATE_BUILDING 7 +#define INSTANCE_HA_STATE_CATCH_UP 8 +#define INSTANCE_HA_STATE_COREDUMP 9 +#define INSTANCE_HA_STATE_MANUAL_STOPPED 10 +#define INSTANCE_HA_STATE_DISK_DAMAGED 11 +#define INSTANCE_HA_STATE_PORT_USED 12 +#define INSTANCE_HA_STATE_BUILD_FAILED 13 +#define INSTANCE_HA_STATE_HEARTBEAT_TIMEOUT 14 +#define INSTANCE_HA_STATE_NIC_DOWN 15 +#define INSTANCE_HA_STATE_READ_ONLY 16 + +#define INSTANCE_HA_DATANODE_BUILD_REASON_NORMAL 0 +#define INSTANCE_HA_DATANODE_BUILD_REASON_WALSEGMENT_REMOVED 1 +#define INSTANCE_HA_DATANODE_BUILD_REASON_DISCONNECT 2 +#define INSTANCE_HA_DATANODE_BUILD_REASON_VERSION_NOT_MATCHED 3 +#define INSTANCE_HA_DATANODE_BUILD_REASON_MODE_NOT_MATCHED 4 +#define INSTANCE_HA_DATANODE_BUILD_REASON_SYSTEMID_NOT_MATCHED 5 +#define INSTANCE_HA_DATANODE_BUILD_REASON_TIMELINE_NOT_MATCHED 6 +#define INSTANCE_HA_DATANODE_BUILD_REASON_UNKNOWN 7 +#define INSTANCE_HA_DATANODE_BUILD_REASON_USER_PASSWD_INVALID 8 +#define INSTANCE_HA_DATANODE_BUILD_REASON_CONNECTING 9 + +#define UNKNOWN_LEVEL 0 + +typedef uint64 XLogRecPtr; + +typedef struct cm_local_replconninfo { + int local_role; + int static_connections; + int db_state; + XLogRecPtr last_flush_lsn; + int buildReason; + uint32 term; + uint32 disconn_mode; + char disconn_host[HOST_LENGTH]; + uint32 disconn_port; + char local_host[HOST_LENGTH]; + uint32 local_port; + bool redo_finished; +} cm_local_replconninfo; + +typedef struct cm_sender_replconninfo { + pid_t sender_pid; + int local_role; + int peer_role; + int peer_state; + int state; + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + int sync_percent; + int sync_state; + int sync_priority; +} cm_sender_replconninfo; + +typedef struct cm_receiver_replconninfo { + pid_t receiver_pid; + int local_role; + int peer_role; + int peer_state; + int state; + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + int sync_percent; +} cm_receiver_replconninfo; + +typedef struct cm_gtm_replconninfo { + int local_role; + int connect_status; + TransactionId xid; + uint64 send_msg_count; + uint64 receive_msg_count; + int sync_mode; +} cm_gtm_replconninfo; + +typedef struct cm_coordinate_replconninfo { + int status; + int db_state; +} cm_coordinate_replconninfo; + +typedef enum cm_coordinate_group_mode { + GROUP_MODE_INIT, + GROUP_MODE_NORMAL, + GROUP_MODE_PENDING, + GROUP_MODE_BUTT +} cm_coordinate_group_mode; + +#define AGENT_TO_INSTANCE_CONNECTION_BAD 0 +#define AGENT_TO_INSTANCE_CONNECTION_OK 1 + +#define INSTANCE_PROCESS_DIED 0 +#define INSTANCE_PROCESS_RUNNING 1 + +const int max_cn_node_num_for_old_version = 16; + +typedef struct cluster_cn_info { + uint32 cn_Id; + uint32 cn_active; + bool cn_connect; + bool drop_success; +} cluster_cn_info; + +typedef struct agent_to_cm_coordinate_status_report_old { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + cluster_cn_info cn_active_info[max_cn_node_num_for_old_version]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report_old; + + +typedef struct agent_to_cm_coordinate_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + int cn_active_info[CN_INFO_NUM]; + char resevered[RESERVE_NUM]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report; + +typedef struct agent_to_cm_coordinate_status_report_v1 { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + int isCentral; + char nodename[NAMEDATALEN]; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + char cnodename[NAMEDATALEN]; + cm_coordinate_replconninfo status; + cm_coordinate_group_mode group_mode; + bool cleanDropCnFlag; + bool isCnDnDisconnected; + int cn_active_info[CN_INFO_NUM]; + int cn_dn_disconnect_times; + char resevered[RESERVE_NUM - RESERVE_NUM_USED]; + int cn_restart_counts; + int phony_dead_times; +} agent_to_cm_coordinate_status_report_v1; + +typedef struct agent_to_cm_fenced_UDF_status_report { + int msg_type; + uint32 nodeid; + int status; +} agent_to_cm_fenced_UDF_status_report; + +typedef struct agent_to_cm_datanode_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + cm_local_replconninfo local_status; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + int dn_restart_counts; + int phony_dead_times; + int dn_restart_counts_in_hour; + +} agent_to_cm_datanode_status_report; + +typedef struct agent_to_cm_gtm_status_report { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int connectStatus; + int processStatus; + cm_gtm_replconninfo status; + int phony_dead_times; +} agent_to_cm_gtm_status_report; + +typedef struct agent_to_cm_current_time_report { + int msg_type; + uint32 nodeid; + long int etcd_time; +} agent_to_cm_current_time_report; + +typedef struct AgentToCMS_DiskUsageStatusReport { + int msgType; + uint32 instanceId; + uint32 dataPathUsage; + uint32 logPathUsage; +} AgentToCMS_DiskUsageStatusReport; + +typedef struct agent_to_cm_heartbeat { + int msg_type; + uint32 node; + uint32 instanceId; + int instanceType; + int cluster_status_request; +} agent_to_cm_heartbeat; + +typedef struct coordinate_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_coordinate_status_report report_msg; +} coordinate_status_info; + +typedef struct datanode_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_datanode_status_report report_msg; +} datanode_status_info; + +typedef struct gtm_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_gtm_status_report report_msg; +} gtm_status_info; + +typedef struct cm_to_agent_heartbeat { + int msg_type; + uint32 node; + int type; + int cluster_status; + uint32 healthCoorId; +} cm_to_agent_heartbeat; + +typedef struct cm_to_cm_vote { + int msg_type; + uint32 node; + uint32 instanceId; + int role; +} cm_to_cm_vote; + +typedef struct cm_to_cm_timeline { + int msg_type; + uint32 node; + uint32 instanceId; + long timeline; +} cm_to_cm_timeline; + +typedef struct cm_to_cm_broadcast { + int msg_type; + uint32 node; + uint32 instanceId; + int role; +} cm_to_cm_broadcast; + +typedef struct cm_to_cm_notify { + int msg_type; + int role; +} cm_to_cm_notify; + +typedef struct cm_to_cm_switchover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_switchover; + +typedef struct cm_to_cm_switchover_ack { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_switchover_ack; + +typedef struct cm_to_cm_failover { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_failover; + +typedef struct cm_to_cm_failover_ack { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} cm_to_cm_failover_ack; + +typedef struct cm_to_cm_sync { + int msg_type; + int role; +} cm_to_cm_sync; + +typedef struct cm_instance_command_status { + int command_status; + int command_send_status; + int command_send_times; + int command_send_num; + int pengding_command; + int time_out; + int role_changed; + int heat_beat; + int arbitrate_delay_time_out; + int arbitrate_delay_set; + int local_arbitrate_delay_role; + int peerl_arbitrate_delay_role; + int full_build; + int notifyCnCount; + int keep_heartbeat_timeout; + int sync_mode; +} cm_instance_command_status; + +// need to keep consist with cm_to_ctl_instance_datanode_status +typedef struct cm_instance_datanode_report_status { + cm_local_replconninfo local_status; + int sender_count; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + synchronous_standby_mode sync_standby_mode; + int send_gs_guc_time; + int dn_restart_counts; + bool arbitrateFlag; + int failoverStep; + int failoverTimeout; + int phony_dead_times; + int phony_dead_interval; + int dn_restart_counts_in_hour; + bool is_finish_redo_cmd_sent; + bool setGucSyncFlag; + short setGucSyncDelay; +} cm_instance_datanode_report_status; + +typedef struct cm_instance_gtm_report_status { + cm_gtm_replconninfo local_status; + int phony_dead_times; + int phony_dead_interval; +} cm_instance_gtm_report_status; + +/* + * each coordinator manage a list of datanode notify status + */ +typedef struct cm_notify_msg_status { + uint32* datanode_instance; + uint32* datanode_index; + bool* notify_status; + bool* have_notified; + bool* have_dropped; + bool have_canceled; +} cm_notify_msg_status; + +typedef struct cm_instance_coordinate_report_status { + cm_coordinate_replconninfo status; + int isdown; + int clean; + uint32 exec_drop_instanceId; + cm_coordinate_group_mode group_mode; + cm_notify_msg_status notify_msg; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + uint32 cn_restart_counts; + int phony_dead_times; + int phony_dead_interval; + bool delay_repair; + bool isCnDnDisconnected; + int auto_delete_delay_time; + int disable_time_out; + int cma_fault_timeout_to_killcn; +} cm_instance_coordinate_report_status; + +typedef struct cm_instance_arbitrate_status { + int sync_mode; + bool restarting; + int promoting_timeout; +} cm_instance_arbitrate_status; + +#define MAX_CM_TO_CM_REPORT_SYNC_COUNT_PER_CYCLE 5 +typedef struct cm_to_cm_report_sync { + int msg_type; + uint32 node[CM_PRIMARY_STANDBY_NUM]; + uint32 instanceId[CM_PRIMARY_STANDBY_NUM]; + int instance_type[CM_PRIMARY_STANDBY_NUM]; + cm_instance_command_status command_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_coordinate_report_status coordinatemember; + cm_instance_arbitrate_status arbitrate_status_member[CM_PRIMARY_STANDBY_NUM]; +} cm_to_cm_report_sync; + +typedef struct cm_instance_role_status { + // available zone information + char azName[CM_AZ_NAME]; + uint32 azPriority; + + uint32 node; + uint32 instanceId; + int instanceType; + int role; + int dataReplicationMode; + int instanceRoleInit; +} cm_instance_role_status; + +typedef struct cm_instance_role_status_0 { + uint32 node; + uint32 instanceId; + int instanceType; + int role; + int dataReplicationMode; + int instanceRoleInit; +} cm_instance_role_status_0; + +#define CM_PRIMARY_STANDBY_MAX_NUM 8 // supprot 1 primary and [1, 7] standby +#define CM_PRIMARY_STANDBY_MAX_NUM_0 3 // support master standby dummy + +typedef struct cm_instance_role_group_0 { + int count; + cm_instance_role_status_0 instanceMember[CM_PRIMARY_STANDBY_MAX_NUM_0]; +} cm_instance_role_group_0; + +typedef struct cm_instance_role_group { + int count; + cm_instance_role_status instanceMember[CM_PRIMARY_STANDBY_MAX_NUM]; +} cm_instance_role_group; + +typedef struct cm_to_cm_role_change_notify { + int msg_type; + cm_instance_role_group role_change; +} cm_to_cm_role_change_notify; + +typedef struct ctl_to_cm_datanode_relation_info { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int wait_seconds; +} ctl_to_cm_datanode_relation_info; + +typedef struct cm_to_ctl_get_datanode_relation_ack { + int command_result; + int member_index; + cm_instance_role_status instanceMember[CM_PRIMARY_STANDBY_MAX_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_MAX_NUM]; +} cm_to_ctl_get_datanode_relation_ack; + +// need to keep consist with the struct cm_instance_datanode_report_status +typedef struct cm_to_ctl_instance_datanode_status { + cm_local_replconninfo local_status; + int sender_count; + BuildState build_info; + cm_sender_replconninfo sender_status[CM_MAX_SENDER_NUM]; + cm_receiver_replconninfo receive_status; + RedoStatsData parallel_redo_status; + cm_redo_stats local_redo_stats; + synchronous_standby_mode sync_standby_mode; + int send_gs_guc_time; +} cm_to_ctl_instance_datanode_status; + +typedef struct cm_to_ctl_instance_gtm_status { + cm_gtm_replconninfo local_status; +} cm_to_ctl_instance_gtm_status; + +typedef struct cm_to_ctl_instance_coordinate_status { + int status; + cm_coordinate_group_mode group_mode; + /* no notify map in ctl */ +} cm_to_ctl_instance_coordinate_status; + +typedef struct cm_to_ctl_instance_status { + int msg_type; + uint32 node; + uint32 instanceId; + int instance_type; + int member_index; + int is_central; + int fenced_UDF_status; + cm_to_ctl_instance_datanode_status data_node_member; + cm_to_ctl_instance_gtm_status gtm_member; + cm_to_ctl_instance_coordinate_status coordinatemember; +} cm_to_ctl_instance_status; + +typedef struct cm_to_ctl_central_node_status { + uint32 instanceId; + int node_index; + int status; +} cm_to_ctl_central_node_status; + +#define CM_CAN_PRCESS_COMMAND 0 +#define CM_ANOTHER_COMMAND_RUNNING 1 +#define CM_INVALID_COMMAND 2 +#define CM_DN_NORMAL_STATE 3 + +typedef struct cm_to_ctl_command_ack { + int msg_type; + int command_result; + uint32 node; + uint32 instanceId; + int instance_type; + int command_status; + int pengding_command; + int time_out; +} cm_to_ctl_command_ack; + +typedef struct cm_to_ctl_balance_check_ack { + int msg_type; + int switchoverDone; +} cm_to_ctl_balance_check_ack; + +typedef struct cm_to_ctl_switchover_full_check_ack { + int msg_type; + int switchoverDone; +} cm_to_ctl_switchover_full_check_ack, cm_to_ctl_switchover_az_check_ack; + +#define MAX_INSTANCES_LEN 512 +typedef struct cm_to_ctl_balance_result { + int msg_type; + int imbalanceCount; + uint32 instances[MAX_INSTANCES_LEN]; +} cm_to_ctl_balance_result; + +#define CM_STATUS_STARTING 0 +#define CM_STATUS_PENDING 1 +#define CM_STATUS_NORMAL 2 +#define CM_STATUS_NEED_REPAIR 3 +#define CM_STATUS_DEGRADE 4 +#define CM_STATUS_UNKNOWN 5 +#define CM_STATUS_NORMAL_WITH_CN_DELETED 6 + +typedef struct cm_to_ctl_cluster_status { + int msg_type; + int cluster_status; + bool is_all_group_mode_pending; + int switchedCount; + int node_id; +} cm_to_ctl_cluster_status; + +typedef struct cm_to_ctl_logic_cluster_status { + int msg_type; + int cluster_status; + bool is_all_group_mode_pending; + int switchedCount; + + int logic_cluster_status[LOGIC_CLUSTER_NUMBER]; + bool logic_is_all_group_mode_pending[LOGIC_CLUSTER_NUMBER]; + int logic_switchedCount[LOGIC_CLUSTER_NUMBER]; +} cm_to_ctl_logic_cluster_status; + +typedef struct cm_to_ctl_cmserver_status { + int msg_type; + int local_role; + bool is_pending; +} cm_to_ctl_cmserver_status; + +typedef struct cm_query_instance_status { + int msg_type; + uint32 nodeId; + uint32 instanceType; // only for etcd and cmserver + uint32 msg_step; + uint32 status; + bool pending; +} cm_query_instance_status; + +typedef struct etcd_status_info { + pthread_rwlock_t lk_lock; + cm_query_instance_status report_msg; +} etcd_status_info; + +/* kerberos information */ +#define ENV_MAX 100 +#define ENVLUE_NUM 3 +#define MAX_BUFF 1024 +#define MAXLEN 20 +#define KERBEROS_NUM 2 + +typedef struct agent_to_cm_kerberos_status_report { + int msg_type; + uint32 node; + char kerberos_ip[CM_IP_LENGTH]; + uint32 port; + uint32 status; + char role[MAXLEN]; + char nodeName[CM_NODE_NAME]; +} agent_to_cm_kerberos_status_report; + +typedef struct kerberos_status_info { + pthread_rwlock_t lk_lock; + agent_to_cm_kerberos_status_report report_msg; +} kerberos_status_info; + +typedef struct cm_to_ctl_kerberos_status_query { + int msg_type; + uint32 heartbeat[KERBEROS_NUM]; + uint32 node[KERBEROS_NUM]; + char kerberos_ip[KERBEROS_NUM][CM_IP_LENGTH]; + uint32 port[KERBEROS_NUM]; + uint32 status[KERBEROS_NUM]; + char role[KERBEROS_NUM][MAXLEN]; + char nodeName[KERBEROS_NUM][CM_NODE_NAME]; +} cm_to_ctl_kerberos_status_query; + +typedef struct kerberos_group_report_status { + pthread_rwlock_t lk_lock; + cm_to_ctl_kerberos_status_query kerberos_status; +} kerberos_group_report_status; + + +typedef uint32 ShortTransactionId; + +/* ---------------- + * Special transaction ID values + * + * BootstrapTransactionId is the XID for "bootstrap" operations, and + * FrozenTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define InvalidTransactionId ((TransactionId)0) +#define BootstrapTransactionId ((TransactionId)1) +#define FrozenTransactionId ((TransactionId)2) +#define FirstNormalTransactionId ((TransactionId)3) +#define MaxTransactionId ((TransactionId)0xFFFFFFFF) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) + +/* + * Macros for comparing XLogRecPtrs + * + * Beware of passing expressions with side-effects to these macros, + * since the arguments may be evaluated multiple times. + */ +#define XLByteLT(a, b) ((a) < (b)) +#define XLByteLE(a, b) ((a) <= (b)) +#define XLByteEQ(a, b) ((a) == (b)) + +#define InvalidTerm (0) +#define FirstTerm (1) + +#define XLByteLT_W_TERM(a_term, a_logptr, b_term, b_logptr) \ + (((a_term) < (b_term)) || (((a_term) == (b_term)) && ((a_logptr) < (b_logptr)))) +#define XLByteLE_W_TERM(a_term, a_logptr, b_term, b_logptr) \ + (((a_term) < (b_term)) || (((a_term) == (b_term)) && ((a_logptr) <= (b_logptr)))) +#define XLByteEQ_W_TERM(a_term, a_logptr, b_term, b_logptr) (((a_term) == (b_term)) && ((a_logptr) == (b_logptr))) + +#define CM_RESULT_COMM_ERROR (-2) /* Communication error */ +#define CM_RESULT_ERROR (-1) +#define CM_RESULT_OK (0) +/* + * This error is used ion the case where allocated buffer is not large + * enough to store the errors. It may happen of an allocation failed + * so it's status is considered as unknown. + */ +#define CM_RESULT_UNKNOWN (1) + +typedef struct ResultDataPacked { + char pad[CM_MSG_MAX_LENGTH]; + +} ResultDataPacked; + +typedef union CM_ResultData { + ResultDataPacked packed; + +} CM_ResultData; + +typedef struct CM_Result { + int gr_msglen; + int gr_status; + int gr_type; + CM_ResultData gr_resdata; +} CM_Result; + +extern int query_gtm_status_wrapper(char pid_path[MAXPGPATH], agent_to_cm_gtm_status_report& agent_to_cm_gtm); +extern int query_gtm_status_for_phony_dead(char pid_path[MAXPGPATH]); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_alarm.h postgresql-hll-2.14/include/include/cm/cm_server/cms_alarm.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_alarm.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_alarm.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_alarm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_ALARM_H +#define CMS_ALARM_H + +#include "alarm/alarm.h" + +typedef enum CM_DiskPreAlarmType { + PRE_ALARM_LOG = 0, + PRE_ALARM_CN = 1, + PRE_ALARM_DN = 2 +} CM_DiskPreAlarmType; + +typedef struct instance_phony_dead_alarm { + uint32 instanceId; + Alarm PhonyDeadAlarmItem[1]; +} instance_phony_dead_alarm; + +extern void StorageThresholdPreAlarmItemInitialize(void); +extern void ReportStorageThresholdPreAlarm( + AlarmType alarmType, + const char* instanceName, + CM_DiskPreAlarmType alarmNode, + uint32 alarmIndex); +extern void ReadOnlyAlarmItemInitialize(void); +extern void ReportReadOnlyAlarm(AlarmType alarmType, const char* instanceName, uint32 alarmIndex); +extern void PhonyDeadAlarmItemInitialize(void); +extern void report_phony_dead_alarm(AlarmType alarmType, const char* instanceName, uint32 instanceid); +extern void report_unbalanced_alarm(AlarmType alarmType); + + +extern void EtcdAbnormalAlarmItemInitialize(void); +extern void UnbalanceAlarmItemInitialize(void); +extern void ServerSwitchAlarmItemInitialize(void); +extern void report_server_switch_alarm(AlarmType alarmType, const char* instanceName); +void report_etcd_fail_alarm(AlarmType alarmType, char* instanceName, int alarmIndex); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_cms.h postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_cms.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_cms.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_cms.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,17 @@ +/** + * @file cms_arbitrate_cms.h + * @brief + * @author xxx + * @version 1.0 + * @date 2020-08-07 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_ARBITRATE_CMS_H +#define CMS_ARBITRATE_CMS_H + +extern void CloseHAConnection(CM_Connection* con); +extern void* CM_ThreadHAMain(void* argp); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_datanode.h postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_datanode.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_datanode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_datanode.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,42 @@ +/** + * @file cms_arbitrate_datanode.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ +#ifndef CMS_ARBITRATE_DATANODE_H +#define CMS_ARBITRATE_DATANODE_H + +#include "cm/elog.h" +#include "cm/cm_msg.h" +#include "cm_server.h" +#include "cms_global_params.h" + +extern uint32 find_primary_term(uint32 group_index); +extern uint32 read_term_from_etcd(uint32 group_index); +bool check_datanode_arbitrate_status(uint32 group_index, int member_index); + +cm_instance_datanode_report_status &GetDataNodeMember(const uint32 &group, const int &member); + +int find_candiate_primary_node_in_instance_role_group(uint32 group_index, int member_index); +int find_auto_switchover_primary_node(uint32 group_index, int member_index); + +void datanode_instance_arbitrate( + CM_Connection *con, agent_to_cm_datanode_status_report *agent_to_cm_datanode_status_ptr); +void datanode_instance_arbitrate_for_psd( + CM_Connection *con, agent_to_cm_datanode_status_report *agent_to_cm_datanode_status_ptr); +void datanode_instance_arbitrate_new( + CM_Connection* con, agent_to_cm_datanode_status_report* agent_to_cm_datanode_status_ptr, + uint32 group_index, int member_index, maintenance_mode mode); +void datanode_instance_arbitrate_single( + CM_Connection* con, agent_to_cm_datanode_status_report* agent_to_cm_datanode_status_ptr); + +void DealDataNodeDBStateChange(const uint32 &group, const int &member, const int &dbStatePrev); +void NotifyDatanodeDynamicPrimary(CM_Connection *con, const uint32 &node, const uint32 &instanceId, const uint32 &group, + const int &member); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_gtm.h postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_gtm.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_arbitrate_gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_arbitrate_gtm.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_arbitrate_gtm.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_arbitrate_gtm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_ARBITRATE_GTM_H +#define CMS_ARBITRATE_GTM_H + +#include "cm/cm_msg.h" + +extern void gtm_instance_arbitrate(CM_Connection* con, agent_to_cm_gtm_status_report* agent_to_cm_gtm_status_ptr); +extern void gtm_instance_arbitrate_single(CM_Connection* con, + agent_to_cm_gtm_status_report* agent_to_cm_gtm_status_ptr); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_az.h postgresql-hll-2.14/include/include/cm/cm_server/cms_az.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_az.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_az.h 2020-12-12 17:06:43.173347083 +0800 @@ -0,0 +1,45 @@ +/** + * @file cms_az.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_AZ_CHECK_H +#define CMS_AZ_CHECK_H + +#define AZ_STATUS_RUNNING 0 +#define AZ_STAUTS_STOPPED 1 + +#define PING_TIMEOUT_OPTION " -c 2 -W 2" +/* for the limit of check node of success, when check az1 is success */ +#define AZ1_AND_AZ2_CHECK_SUCCESS_NODE_LIMIT 10 +#define AZ1_AZ2_CONNECT_PING_TRY_TIMES 3 + +const int MAX_PING_NODE_NUM = 10; + +/* data structure to store input/output of ping-check thread function */ +typedef struct PingCheckThreadParmInfo { + /* the node to ping */ + uint32 azNode; + /* ping thread idnex */ + uint32 threadIdx; + /* the array of ping result */ + uint32 *pingResultArrayRef; +}PingCheckThreadParmInfo; + +typedef enum {START_AZ, STOP_AZ} OperateType; +typedef enum {SET_ETCD_AZ, GET_ETCD_AZ} EtcdOperateType; +typedef enum {UNKNOWN_AZ_DEPLOYMENT, TWO_AZ_DEPLOYMENT, THREE_AZ_DEPLOYMENT} AZDeploymentType; + +extern void* Az1Az2ConnectStateCheck(void* arg); +extern void* MultiAzConnectStateCheckMain(void* arg); +extern void getAZDyanmicStatus( + int azCount, int* statusOnline, int* statusPrimary, int* statusFail, int* statusDnFail, char azArray[][CM_AZ_NAME]); + +extern void* AZStatusCheckAndArbitrate(void* arg); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_cluster_switchover.h postgresql-hll-2.14/include/include/cm/cm_server/cms_cluster_switchover.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_cluster_switchover.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_cluster_switchover.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,22 @@ +/** + * @file cms_cluster_switchover.h + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2020-07-31 + * + * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2011-2020. All rights reserved. + * + */ + +#ifndef CMS_CLUSTER_SWITCHOVER_H +#define CMS_CLUSTER_SWITCHOVER_H + +#include "cm_server.h" + +#define MAX_CYCLE 600 + +extern char switchover_flag_file_path[MAX_PATH_LEN]; +extern void* Deal_switchover_for_init_cluster(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_cn.h postgresql-hll-2.14/include/include/cm/cm_server/cms_cn.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_cn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_cn.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_cn.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_cn.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_CN_H +#define CMS_CN_H + +#include "cm_server.h" + +#ifdef ENABLE_MULTIPLE_NODES +void process_cm_to_agent_repair_ack(CM_Connection* con, uint32 group_index); +void process_agent_to_cm_coordinate_status_report_msg( + CM_Connection* con, agent_to_cm_coordinate_status_report* agent_to_cm_coordinate_status_ptr); +void process_ctl_to_cm_disable_cn(CM_Connection* con, ctl_to_cm_disable_cn* ctl_to_cm_disable_cn_ptr); +void process_agent_to_central_coordinate_status( + CM_Connection* con, const agent_to_cm_coordinate_status_report* report_msg, int group_index, uint32 count); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_common.h postgresql-hll-2.14/include/include/cm/cm_server/cms_common.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_common.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_common.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_common.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_COMMON_H +#define CMS_COMMON_H + + +uint32 findMinCmServerInstanceIdIndex(); +uint32 findCmServerOrderIndex(uint32 nodeIndex); +void setNotifyCnFlagByNodeId(uint32 nodeId); +bool is_valid_host(CM_Connection* con, int remote_type); +bool findMinCmServerId(int primaryId); +void get_parameters_from_configfile(); +#ifdef ENABLE_MULTIPLE_NODES +void get_paramter_coordinator_heartbeat_timeout(); +#endif +void clean_init_cluster_state(); +void get_config_param(const char* config_file, const char* srcParam, char* destParam, int destLen); +int StopCheckNode(uint32 nodeIdCheck); +void SendSignalToAgentThreads(); +extern int GetCtlThreadNum(); +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_conn.h postgresql-hll-2.14/include/include/cm/cm_server/cms_conn.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_conn.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,52 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_conn.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_conn.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_CONN_H +#define CMS_CONN_H + +#include "cm/libpq-fe.h" +#include "cm_server.h" + + +#define CM_SERVER_PACKET_ERROR_MSG 128 +#define MSG_COUNT_FOR_LOG 300 + +extern int ServerListenSocket[MAXLISTEN]; + +void* CM_ThreadMain(void* argp); +void RemoveCMAgentConnection(CM_Connection* con); +void ConnCloseAndFree(CM_Connection* con); +void CloseHAConnection(CM_Connection* con); +void set_socket_timeout(Port* my_port, int timeout); + +Port* ConnCreate(int serverFd); +void ConnFree(Port* conn); +int initMasks(const int* ListenSocket, fd_set* rmask); +int CMHandleCheckAuth(CM_Connection* con); +int cm_server_flush_msg(CM_Connection* conn); + +int EventAdd(int epoll_handle, int events, CM_Connection* con); +void EventDel(int epollFd, CM_Connection* con); +void CMPerformAuthentication(CM_Connection* con); +int ReadCommand(Port* myport, CM_StringInfo inBuf); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_disk_check.h postgresql-hll-2.14/include/include/cm/cm_server/cms_disk_check.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_disk_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_disk_check.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_disk_check.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_disk_check.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_DISK_CHECK_H +#define CMS_DISK_CHECK_H + +#include "common/config/cm_config.h" + +#define INSTANCE_NAME_LENGTH 256 + +extern int InitNodeReadonlyInfo(); +extern bool checkReadOnlyStatus(uint32 instanceId); + +extern void* StorageDetectMain(void* arg); + +extern void SetPreAlarmForNodeInstance(uint32 instanceId); +extern void ReportPreAlarmForNodeInstance(); +extern void PreAlarmForNodeThreshold(); + +extern void SetPreAlarmForLogDiskInstance(const char* nodeName); +extern void RepostPreAlarmForLogDiskInstance(); +extern void PreAlarmForLogPathThreshold(); +extern void SetNodeInstanceReadOnlyStatus(int instanceType, uint32 instanceId, uint32 readonly); +extern void SaveNodeReadOnlyConfig(); +extern void CheckAndSetStorageThresholdReadOnlyAlarm(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cm_server.h postgresql-hll-2.14/include/include/cm/cm_server/cm_server.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cm_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cm_server.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,239 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_server.h + * + * + * + * IDENTIFICATION + * src/include/cm/cm_server/cm_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SERVER_MAIN_H +#define SERVER_MAIN_H + +#include "common/config/cm_config.h" +#include "cm/elog.h" +#include "cm/stringinfo.h" +#include "cm/libpq-be.h" +#include "cm/cm_msg.h" +#include "cm/pqsignal.h" + +#define CM_MAX_CONNECTIONS 1024 +#define CM_MAX_THREADS 1024 + +#define CM_MONITOR_THREAD_NUM 1 +#define CM_HA_THREAD_NUM 1 + +#define MAXLISTEN 64 + +#define MAX_EVENTS 512 + +#define DEFAULT_THREAD_NUM 5 + +#define INVALIDFD (-1) + +#define CM_INCREMENT_TERM_VALUE 100 + +#define CM_UINT32_MAX 0xFFFFFFFFU + +#define CM_MIN_CONN_TO_ETCD 2 + +#define CM_MAX_CONN_TO_ETCD 100 + +#define CM_TEN_DIVISOR 10 + +typedef void (*PCallback)(int fd, int events, void* arg); + +typedef struct CM_Connection { + int fd; + int epHandle; + int events; + PCallback callback; + void* arg; + Port* port; + CM_StringInfo inBuffer; + long last_active; + bool gss_check; + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +} CM_Connection; + +typedef struct CM_Connections { + uint32 count; + CM_Connection* connections[CM_MAX_CONNECTIONS + MAXLISTEN]; + pthread_rwlock_t lock; +} CM_Connections; + +typedef struct CM_Thread { + pthread_t tid; + int type; + int epHandle; + +} CM_Thread; + +typedef struct CM_Threads { + uint32 count; + CM_Thread threads[CM_MAX_THREADS]; +} CM_Threads; + +typedef struct CM_HAThread { + CM_Thread thread; + int heartbeat; + CM_Connection conn; +} CM_HAThread; + +typedef struct CM_HAThreads { + uint32 count; + CM_HAThread threads[CM_HA_THREAD_NUM]; +} CM_HAThreads; + +typedef struct CM_MonitorThread { + CM_Thread thread; +} CM_MonitorThread; + +typedef struct CM_MonitorNodeStopThread { + CM_Thread thread; +} CM_MonitorNodeStopThread; + +typedef enum CM_ThreadStatus { + CM_THREAD_STARTING, + CM_THREAD_RUNNING, + CM_THREAD_EXITING, + CM_THREAD_INVALID +} CM_ThreadStatus; + +typedef struct CM_Server_HA_Status { + int local_role; + int peer_role; + int status; + bool is_all_group_mode_pending; + pthread_rwlock_t ha_lock; +} CM_Server_HA_Status; + +typedef struct CM_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + +} CM_ConnectionInfo; + +typedef struct CM_ConnEtcdInfo { + uint32 count; + EtcdSession etcdSession[CM_MAX_CONN_TO_ETCD]; +} CM_ConnEtcdInfo; + +#define THREAD_TYPE_HA 1 +#define THREAD_TYPE_MONITOR 2 +#define THREAD_TYPE_CTL_SERVER 3 +#define THREAD_TYPE_AGENT_SERVER 4 +#define THREAD_TYPE_INIT 5 +#define THREAD_TYPE_ALARM_CHECKER 6 + +#define MONITOR_CYCLE_TIMER 1000000 +#define MONITOR_CYCLE_TIMER_OUT 6000000 +#define MONITOR_CYCLE_MAX_COUNT (MONITOR_CYCLE_TIMER_OUT / MONITOR_CYCLE_TIMER) + +// ARBITRATE_DELAY_CYCLE 10s +#define MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT (10) + +#define MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT2 (MONITOR_INSTANCE_ARBITRATE_DELAY_CYCLE_MAX_COUNT * 2) +#define BUILD_TIMER_OUT (60 * 60 * 2) +#define PROMOTING_TIME_OUT (30) + +#define CM_INSTANCE_GROUP_SIZE 128 + +#define INSTANCE_NONE_COMMAND 0 +#define INSTANCE_COMMAND_WAIT_SEND_SERVER 1 +#define INSTANCE_COMMAND_WAIT_SERVER_ACK 2 +#define INSTANCE_COMMAND_WAIT_EXEC 3 +#define INSTANCE_COMMAND_WAIT_EXEC_ACK 4 + +#define INSTANCE_COMMAND_SEND_STATUS_NONE 0 +#define INSTANCE_COMMAND_SEND_STATUS_SENDING 1 +#define INSTANCE_COMMAND_SEND_STATUS_OK 2 +#define INSTANCE_COMMAND_SEND_STATUS_FAIL 3 + +#define INSTANCE_ROLE_NO_CHANGE 0 +#define INSTANCE_ROLE_CHANGED 1 + +#define INSTANCE_ARBITRATE_DELAY_NO_SET 0 +#define INSTANCE_ARBITRATE_DELAY_HAVE_SET 1 +constexpr int NO_NEED_TO_SET_PARAM = -1; + +typedef struct cm_instance_report_status { + cm_instance_command_status command_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_datanode_report_status data_node_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_gtm_report_status gtm_member[CM_PRIMARY_STANDBY_NUM]; + cm_instance_coordinate_report_status coordinatemember; + cm_instance_arbitrate_status arbitrate_status_member[CM_PRIMARY_STANDBY_NUM]; + uint32 time; + uint32 term; + int etcd_synced; + int cma_kill_instance_timeout; + struct timeval finishredo_time; + bool finish_redo; +} cm_instance_report_status; + +typedef struct cm_instance_group_report_status { + pthread_rwlock_t lk_lock; + cm_instance_report_status instance_status; +} cm_instance_group_report_status; + +typedef struct cm_fenced_UDF_report_status { + pthread_rwlock_t lk_lock; + int heart_beat; + int status; +} cm_fenced_UDF_report_status; + +typedef enum ProcessingMode { + BootstrapProcessing, /* bootstrap creation of template database */ + InitProcessing, /* initializing system */ + NormalProcessing, /* normal processing */ + PostUpgradeProcessing /* Post upgrade to run script */ +} ProcessingMode; + +#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing) +#define IsInitProcessingMode() (Mode == InitProcessing) +#define IsNormalProcessingMode() (Mode == NormalProcessing) +#define IsPostUpgradeProcessingMode() (Mode == PostUpgradeProcessing) + +#define GetProcessingMode() Mode + +#define SetProcessingMode(mode) \ + do { \ + if ((mode) == BootstrapProcessing || (mode) == InitProcessing || (mode) == NormalProcessing || \ + (mode) == PostUpgradeProcessing) \ + Mode = (mode); \ + } while (0) + +extern volatile sig_atomic_t got_stop; +extern volatile sig_atomic_t got_parameter_reload; +extern volatile sig_atomic_t ha_connection_closed; +extern THR_LOCAL volatile sig_atomic_t got_conns_close; + +extern void ProcessStartupPacket(int epollFd, int events, void* arg); +extern int cm_server_process_ha_startuppacket(CM_Connection* con, CM_StringInfo msg); +extern int cm_server_send_msg(CM_Connection* con, char msgtype, const char* s, size_t len, int log_level = LOG); +void set_pending_command( + const uint32 &group_index, + const int &member_index, + const CM_MessageType &pending_command, + const int &time_out = NO_NEED_TO_SET_PARAM, + const int &full_build = NO_NEED_TO_SET_PARAM); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_etcd.h postgresql-hll-2.14/include/include/cm/cm_server/cms_etcd.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_etcd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_etcd.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_etcd.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_etcd.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_ETCD_H +#define CMS_ETCD_H + +#include "cm_server.h" +#include "cms_global_params.h" + +extern volatile bool g_arbitration_changed_from_minority; +uint32 read_term_from_etcd(uint32 group_index); +void clear_sync_with_etcd_flag(); +void etcd_ip_port_info_balance(EtcdServerSocket* server); +void CmsGetKerberosInfoFromEtcd(); + +void get_all_cmserver_heartbeat_from_etcd(); +bool set_heartbeat_to_etcd(char* key); +bool get_finish_redo_flag_from_etcd(uint32 group_index); +bool GetFinishRedoFlagFromEtcdNew(); +bool getDnFailStatusFromEtcd(int* statusOnline); +bool setDnFailStatusToEtcd(int* statusOnline); + +bool getOnlineStatusFromEtcd(int* statusOnline); +bool setOnlineStatusToEtcd(int* statusOnline); + +void set_dynamic_config_change_to_etcd(uint32 group_index, int member_index); +void get_coordinator_dynamic_config_change_from_etcd(uint32 group_index); +void GetCoordinatorDynamicConfigChangeFromEtcdNew(uint32 group_index); +void get_datanode_dynamic_config_change_from_etcd(uint32 group_index); +void GetDatanodeDynamicConfigChangeFromEtcdNew(uint32 group_index); +void get_gtm_dynamic_config_change_from_etcd(uint32 group_index); +void SetStaticPrimaryRole(uint32 group_index, int static_primary__index); + +void GetNodeReadOnlyStatusFromEtcd(); +errno_t SetNodeReadOnlyStatusToEtcd(const char* bitsString); + +int try_etcd_get(char* key, char* value, int max_size, int tryTimes); +long GetTimeMinus(struct timeval checkEnd, struct timeval checkBegin); +int GetInstanceKeyValueFromEtcd(const char *key, InstanceStatusKeyValue *keyValue, const int length); + +void server_etcd_init(); + +void CloseAllEtcdSession(); +EtcdSession GetNextEtcdSession(); +int SetTermToEtcd(uint32 term); +int IncrementTermToEtcd(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_global_params.h postgresql-hll-2.14/include/include/cm/cm_server/cms_global_params.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_global_params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_global_params.h 2020-12-12 17:06:43.174347096 +0800 @@ -0,0 +1,407 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_global_params.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_global_params.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_GLOBAL_PARAMS_H +#define CMS_GLOBAL_PARAMS_H + +#include +#include +#include +#include "common/config/cm_config.h" +#include "alarm/alarm.h" +#include "cm_server.h" +#include "cm/cm_c.h" +#include "cm/etcdapi.h" + +using std::set; +using std::string; +using std::vector; + + +typedef struct azInfo { + char azName[CM_AZ_NAME]; + uint32 nodes[CM_NODE_MAXNUM]; +} azInfo; + +typedef enum CMS_OPERATION_ { + CMS_SWITCHOVER_DN = 0, + CMS_FAILOVER_DN, + CMS_BUILD_DN, + CMS_DROP_CN, + CMS_PHONY_DEAD_CHECK, +} cms_operation ; + +typedef enum MAINTENANCE_MODE_ { + MAINTENANCE_MODE_NONE = 0, + MAINTENANCE_MODE_UPGRADE, + MAINTENANCE_MODE_UPGRADE_OBSERVATION, + MAINTENANCE_MODE_DILATATION, +} maintenance_mode; + +/* data structures to record instances that are in switchover procedure */ +typedef struct switchover_instance { + uint32 node; + uint32 instanceId; + int instanceType; +} switchover_instance; +typedef struct DataNodeReadOnlyInfo { + char dataNodePath[CM_PATH_LENGTH]; + uint32 instanceId; + uint32 currReadOnly; + uint32 lastReadOnly; + uint32 currPreAlarm; + uint32 lastPreAlarm; + uint32 dataDiskUsage; +} DataNodeReadOnlyInfo; + +typedef struct InstanceStatusKeyValue { + char key[ETCD_KEY_LENGTH]; + char value[ETCD_VLAUE_LENGTH]; +} InstanceStatusKeyValue; + +typedef struct DynamicNodeReadOnlyInfo { + char nodeName[CM_NODE_NAME]; + uint32 dataNodeCount; + DataNodeReadOnlyInfo dataNode[CM_MAX_DATANODE_PER_NODE]; + + DataNodeReadOnlyInfo coordinateNode; + uint32 currLogDiskPreAlarm; + uint32 lastLogDiskPreAlarm; + uint32 logDiskUsage; +} DynamicNodeReadOnlyInfo; + +#define ELASTICGROUP "elastic_group" + +#define PROCESS_NOT_EXIST 0 +#define PROCESS_CORPSE 1 +#define PROCESS_RUNNING 2 + +#define CMS_CURRENT_VERSION 1 +#define LOGIC_CLUSTER_LIST "logic_cluster_name.txt" +#define CM_STATIC_CONFIG_FILE "cluster_static_config" +#define CM_CLUSTER_MANUAL_START "cluster_manual_start" +#define CM_INSTANCE_MANUAL_START "instance_manual_start" +#define MINORITY_AZ_START "minority_az_start" +#define MINORITY_AZ_ARBITRATE "minority_az_arbitrate_hist" +#define INSTANCE_MAINTANCE "instance_maintance" +#define CM_PID_FILE "cm_server.pid" + +#define PRIMARY "PRIMARY" +#define STANDBY "STANDBY" +#define DELETED "DELETED" +#define DELETING "DELETING" +#define UNKNOWN "UNKNOWN" +#define NORMAL "NORMAL" +#define DATANODE_ALL 0 +#define READONLY_OFF 0 +#define READONLY_ON 1 +#define DN_RESTART_COUNTS 3 /* DN restarts frequently due to core down */ +#define DN_RESTART_COUNTS_IN_HOUR 8 /* DN restarts in hour */ +#define TRY_TIME_GET_STATUSONLINE_FROM_ETCD 1 +#define CMA_KILL_INSTANCE_BALANCE_TIME 10 +/* + * the sum of cm_server heartbeat timeout and arbitrate delay time must be less than + * cm_agent disconnected timeout. or else, cm_agent may self-kill before cm_server + * standby failover. + */ +#define AZ_MEMBER_MAX_COUNT (3) +#define INIT_CLUSTER_MODE_INSTANCE_DEAL_TIME 180 +#define CM_SERVER_ARBITRATE_DELAY_CYCLE_MAX_COUNT 3 +#define MAX_CN_COUNT 100 +#define MAX_PATH_LEN 1024 +#define THREAHOLD_LEN 10 +#define BYTENUM 4 +#define DEFAULT_THREAD_NUM 5 +#define SWITCHOVER_SEND_CHECK_NUM 3 +#define MAX_VALUE_OF_CM_PRIMARY_HEARTBEAT 86400 +#define MAX_COUNT_OF_NOTIFY_CN 86400 +#define CM_MAX_AUTH_TOKEN_LENGTH 65535 +#define INSTANCE_ID_LEN 5 +#define CM_GS_GUC_SEND_INTERVAL 3 +#define CM_GS_GUC_SYNC_INTERVAL 300 + +#define CN_DELETE_DELAY_SECONDS 10 +#define MAX_QUERY_DOWN_COUNTS 30 + +#define AZ1_INDEX 0 // for the index flag, az1 +#define AZ2_INDEX 1 // for the index flag, az2 +#define AZ3_INDEX 2 // for the index flag, az3 +#define AZ_ALL_INDEX (-1) // for the index flag, az1 and az2,az3 + + +#define GS_GUC_SYNCHRONOUS_STANDBY_MODE 1 +/* + * ssh connect does not exit automatically when the network is fault, + * this will cause cm_ctl hang for several hours, + * so we should add the following timeout options for ssh. + */ +#define SSH_CONNECT_TIMEOUT "5" +#define SSH_CONNECT_ATTEMPTS "3" +#define SSH_SERVER_ALIVE_INTERVAL "15" +#define SSH_SERVER_ALIVE_COUNT_MAX "3" +#define PSSH_TIMEOUT_OPTION \ + " -t 60 -O ConnectTimeout=" SSH_CONNECT_TIMEOUT " -O ConnectionAttempts=" SSH_CONNECT_ATTEMPTS \ + " -O ServerAliveInterval=" SSH_SERVER_ALIVE_INTERVAL " -O ServerAliveCountMax=" SSH_SERVER_ALIVE_COUNT_MAX " " +#define PSSH_TIMEOUT " -t 30 " + + +/* + * the sum of cm_server heartbeat timeout and arbitrate delay time must be less than + * cm_agent disconnected timeout. or else, cm_agent may self-kill before cm_server + * standby failover. + */ +#define AZ_MEMBER_MAX_COUNT (3) +#define SWITCHOVER_DEFAULT_WAIT 1200 /* It needs an integer multiple of 3, because of sleep(3) */ + +#define AUTHENTICATION_TIMEOUT 60 + + +#define IS_CN_INSTANCEID(instanceId) \ + ((instanceId) > 5000 && (instanceId) < 6000) +#define IS_DN_INSTANCEID(instanceId) \ + ((instanceId) > 6000 && (instanceId) < 7000) +#define IS_GTM_INSTANCEID(instanceId) \ + ((instanceId) > 1000 && (instanceId) < 2000) + +extern set g_stopNodes; +extern set::iterator g_stopNodeIter; +extern vector switchOverInstances; +extern vector vecSortCmId; + +extern const int HALF_HOUR; +extern const int MINUS_ONE; +extern const uint32 ZERO; +extern const uint32 FIVE; + +extern volatile arbitration_mode cm_arbitration_mode; +extern uint32 ctl_stop_cluster_server_halt_arbitration_timeout; +extern struct passwd* pw; +/* extern CM_Server_HA_Status g_HA_status_data; */ +extern CM_Server_HA_Status* g_HA_status; +extern dynamicConfigHeader* g_dynamic_header; +extern cm_instance_role_group* g_instance_role_group_ptr; +extern CM_ConnEtcdInfo* g_sess; +extern EtcdTlsAuthPath g_tlsPath; +extern dynamicConfigHeader* g_dynamic_header; +extern cm_instance_group_report_status* g_instance_group_report_status_ptr; +extern CM_Connections gConns; +extern cm_instance_central_node g_central_node; +extern pthread_rwlock_t switchover_az_rwlock; +extern pthread_rwlock_t etcd_access_lock; +extern pthread_rwlock_t gsguc_feedback_rwlock; +extern pthread_rwlock_t g_finish_redo_rwlock; +extern syscalllock cmserver_env_lock; +extern synchronous_standby_mode current_cluster_az_status; +extern CM_Threads gThreads; +extern CM_HAThreads gHAThreads; +extern CM_MonitorThread gMonitorThread; +extern CM_MonitorNodeStopThread gMonitorNodeStopThread; +extern cm_fenced_UDF_report_status* g_fenced_UDF_report_status_ptr; +extern pthread_rwlock_t instance_status_rwlock; +extern pthread_rwlock_t dynamic_file_rwlock; +extern pthread_rwlock_t term_update_rwlock; +extern pthread_rwlock_t g_minorityArbitrateFileRwlock; +extern pthread_rwlock_t switchover_full_rwlock; +extern kerberos_group_report_status g_kerberos_group_report_status; +extern dynamic_cms_timeline* g_timeline; +extern DynamicNodeReadOnlyInfo *g_dynamicNodeReadOnlyInfo; +extern Alarm UnbalanceAlarmItem[1]; +extern Alarm ServerSwitchAlarmItem[1]; +extern Alarm* AbnormalEtcdAlarmList; +extern volatile logic_cluster_restart_mode cm_logic_cluster_restart_mode; +extern volatile cm_start_mode cm_server_start_mode; +extern volatile switchover_az_mode cm_switchover_az_mode; + +extern THR_LOCAL ProcessingMode Mode; + +extern const int majority_reelection_timeout_init; +#ifdef ENABLE_MULTIPLE_NODES +extern const int coordinator_deletion_timeout_init; +#endif +extern const int ctl_stop_cluster_server_halt_arbitration_timeout_init; +extern const int cn_dn_disconnect_to_delete_time; +extern int AbnormalEtcdAlarmListSize; +extern int switch_rto; +extern int force_promote; +extern int cm_auth_method; +extern int g_cms_ha_heartbeat; +extern int cm_server_arbitrate_delay_set; +extern int g_init_cluster_delay_time; +extern int g_sever_agent_conn_check_interval; +extern int datastorage_threshold_check_interval; +extern int max_datastorage_threshold_check; +extern int az_switchover_threshold; +extern int az_check_and_arbitrate_interval; +extern int az1_and_az2_connect_check_interval; +extern int az1_and_az2_connect_check_delay_time; +extern int phony_dead_effective_time; +extern int instance_phony_dead_restart_interval; +extern int enable_az_auto_switchover; +extern int cmserver_demote_delay_on_etcd_fault; +extern int cmserver_demote_delay_on_conn_less; +extern int cmserver_promote_delay_count; +extern int g_cmserver_promote_delay_count; +extern int g_cmserver_demote_delay_on_etcd_fault; +extern int g_monitor_thread_check_invalid_times; +extern int cm_server_current_role; +extern int ccn_change_delay_time; +extern int* cn_dn_disconnect_times; +extern int g_cms_ha_heartbeat_timeout[CM_PRIMARY_STANDBY_NUM]; +extern int g_cms_ha_heartbeat_from_etcd[CM_PRIMARY_STANDBY_NUM]; +extern int HAListenSocket[MAXLISTEN]; + + +extern const uint32 min_normal_cn_number; +extern uint32 g_instance_manual_start_file_exist; +extern uint32 g_gaussdb_restart_counts; +extern uint32 g_cm_to_cm_report_sync_cycle_count; +extern uint32 g_current_node_index; +extern uint32 cm_server_arbitrate_delay_time_out; +extern uint32 arbitration_majority_reelection_timeout; +#ifdef ENABLE_MULTIPLE_NODES +extern uint32 g_cnDeleteDelayTimeForClusterStarting; +extern uint32 g_cnDeleteDelayTimeForDnWithoutPrimary; +extern uint32 g_cmd_disable_coordinatorId; +#endif +extern uint32 g_instance_failover_delay_time_from_set; +extern uint32 cmserver_gs_guc_reload_timeout; +extern uint32 serverHATimeout; +extern uint32 cmserver_switchover_timeout; +extern uint32 g_datanode_instance_count; +extern uint32 g_health_etcd_count_for_pre_conn; +extern uint32 cn_delete_default_time; +extern uint32 instance_heartbeat_timeout; +extern uint32 instance_failover_delay_timeout; +extern uint32 cmserver_ha_connect_timeout; +extern uint32 cmserver_ha_heartbeat_timeout; +extern uint32 cmserver_ha_status_interval; +extern uint32 cmserver_self_vote_timeout; +extern uint32 instance_keep_heartbeat_timeout; +extern uint32 cm_server_arbitrate_delay_base_time_out; +extern uint32 cm_server_arbitrate_delay_incrememtal_time_out; +#ifdef ENABLE_MULTIPLE_NODES +extern uint32 coordinator_heartbeat_timeout; +#endif +extern uint32 g_pre_agent_conn_count; +extern uint32 g_cm_agent_kill_instance_time; +extern uint32 cmserver_switchover_timeout; +extern uint32 cmserver_and_etcd_instance_status_for_timeout; +extern uint32 g_dropped_cn[MAX_CN_NUM]; +extern uint32 g_instance_status_for_etcd[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_etcd_timeout[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_node_index_for_cm_server[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_cm_server_timeout[CM_PRIMARY_STANDBY_NUM]; +extern uint32 g_instance_status_for_cm_server[CM_PRIMARY_STANDBY_NUM]; + +extern azInfo g_azArray[CM_NODE_MAXNUM]; +extern uint32 g_azNum; +extern bool do_finish_redo; +extern bool isNeedCancel; +extern bool g_init_cluster_mode; +extern bool g_gtm_free_mode; +extern bool g_open_new_logical; +extern bool isStart; +extern bool switchoverAZInProgress; +extern bool agentVotePrimary; +extern bool g_dnWithoutPrimaryFlag; +extern bool g_syncDNReadOnlyStatusFromEtcd; +extern bool switchoverFullInProgress; +extern bool g_elastic_exist_node; +extern bool g_kerberos_check_cms_primary_standby; +extern bool g_sync_dn_finish_redo_flag_from_etcd; +extern bool g_getHistoryDnStatusFromEtcd; +extern bool g_getHistoryCnStatusFromEtcd; +extern volatile uint32 g_refreshDynamicCfgNum; +extern bool g_needIncTermToEtcdAgain; +extern bool g_instance_status_for_cm_server_pending[CM_PRIMARY_STANDBY_NUM]; +/* thread count of thread pool */ +extern unsigned int cm_thread_count; + +extern FILE* syslogFile; +extern char* cm_server_dataDir; +extern char sys_log_path[MAX_PATH_LEN]; +extern char curLogFileName[MAXPGPATH]; +extern char system_alarm_log[MAXPGPATH]; +extern char cm_krb_server_keyfile[MAX_PATH_LEN]; +extern char configDir[MAX_PATH_LEN]; +extern char minority_az_start_file[MAX_PATH_LEN]; +extern char g_minorityAzArbitrateFile[MAX_PATH_LEN]; +extern char cm_instance_manual_start_path[MAX_PATH_LEN]; + +extern char g_enableSetReadOnly[10]; +extern char g_enableSetReadOnlyThreshold[THREAHOLD_LEN]; +extern char g_storageReadOnlyCheckCmd[MAX_PATH_LEN]; +extern char cm_static_configure_path[MAX_PATH_LEN]; +extern char cm_dynamic_configure_path[MAX_PATH_LEN]; +extern char g_pre_agent_conn_flag[CM_MAX_CONNECTIONS]; +extern char logic_cluster_list_path[MAX_PATH_LEN]; +extern char instance_maintance_path[MAX_PATH_LEN]; +extern char cm_manual_start_path[MAX_PATH_LEN]; +extern char cm_force_start_file_path[MAX_PATH_LEN]; + +extern volatile int log_min_messages; +extern volatile int maxLogFileSize; +extern volatile int curLogFileNum; +extern volatile bool logInitFlag; +extern volatile bool cm_server_pending; + +extern void clean_init_cluster_state(); +extern void instance_delay_arbitrate_time_out_direct_clean(uint32 group_index, int member_index, uint32 delay_max_count); +extern void instance_delay_arbitrate_time_out_clean( + int local_dynamic_role, int peerl_dynamic_role, uint32 group_index, int member_index, int delay_max_count); + +extern int find_node_in_dynamic_configure( + uint32 node, uint32 instanceId, int instanceType, uint32* group_index, int* member_index); + +extern void change_primary_member_index(uint32 group_index, int primary_member_index); +extern void ChangeDnPrimaryMemberIndex(uint32 group_index, int primary_member_index); +extern void deal_dbstate_normal_primary_down(uint32 group_index, int instanceType); +extern int find_other_member_index(uint32 group_index, int member_index, int role, bool* majority); +extern int instance_delay_arbitrate_time_out( + int local_dynamic_role, int peerl_dynamic_role, uint32 group_index, int member_index, int delay_max_count); +extern void CleanCommand(uint32 group_index, int member_index); +extern bool isLoneNode(int timeout); +extern int SetNotifyPrimaryInfoToEtcd(uint32 groupIndex, int memberIndex); +extern void deal_phony_dead_status( + CM_Connection *con, int instanceRole, int group_index, int member_index, maintenance_mode mode); +extern void kill_instance_for_agent_fault(uint32 node, uint32 instanceId, int insType); +extern int find_other_member_index_for_DN_psd(uint32 group_index, int member_index); +extern int find_other_member_index_for_DN(uint32 group_index, int member_index, bool* majority); +extern int find_other_member_index_for_Gtm(uint32 group_index, int member_index); +extern int cmserver_getenv(const char* env_var, char* output_env_value, uint32 env_value_len, int elevel); +extern bool IsMaintenanceModeDisableOperation(const cms_operation &op, maintenance_mode mode); +extern void cm_pending_notify_broadcast_msg(uint32 group_index, uint32 instanceId); +extern inline bool isDisableSwitchoverDN(const maintenance_mode &mode); +extern inline bool isDisableFailoverDN(const maintenance_mode &mode); +extern inline bool isDisableDropCN(const maintenance_mode &mode); +extern inline bool isDisablePhonyDeadCheck(const maintenance_mode &mode); +extern inline bool isDisableBuildDN(const maintenance_mode &mode); +extern maintenance_mode getMaintenanceMode(const uint32 &group_index); +extern uint32 GetTermForMinorityStart(void); +extern cm_start_mode get_cm_start_mode(const char* path); + +extern void initazArray(char azArray[][CM_AZ_NAME]); +bool isLargerNode(); +void setStorageCheckCmd(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_monitor_main.h postgresql-hll-2.14/include/include/cm/cm_server/cms_monitor_main.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_monitor_main.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_monitor_main.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_monitor_main.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_monitor_main.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_MONITOR_MAIN_H +#define CMS_MONITOR_MAIN_H + +extern void* CM_ThreadMonitorMain(void* argp); +extern void* CM_ThreadMonitorNodeStopMain(void* argp); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_phony_dead_check.h postgresql-hll-2.14/include/include/cm/cm_server/cms_phony_dead_check.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_phony_dead_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_phony_dead_check.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_phony_dead_check.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_phony_dead_check.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_PHONY_DEAD_CHECK_H +#define CMS_PHONY_DEAD_CHECK_H + +extern void* deal_phony_dead_alarm(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_process_messages.h postgresql-hll-2.14/include/include/cm/cm_server/cms_process_messages.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_process_messages.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_process_messages.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,94 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_process_messages.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_process_messages.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CMS_PROCESS_MESSAGES_H +#define CMS_PROCESS_MESSAGES_H + +#ifndef CM_AZ_NAME +#define CM_AZ_NAME 65 +#endif + +// ETCD TIME THRESHOLD +#define ETCD_CLOCK_THRESHOLD 3 +#define SWITCHOVER_SEND_CHECK_RATE 30 + +extern int cmserver_getenv(const char* env_var, char* output_env_value, uint32 env_value_len, int elevel); +extern int check_if_candidate_is_in_faulty_az(uint32 group_index, int candidate_member_index); +extern int findAzIndex(char azArray[][CM_AZ_NAME], const char* azName); +extern int ReadCommand(Port* myport, CM_StringInfo inBuf); +extern int isNodeBalanced(uint32* switchedInstance); +extern int get_logicClusterId_by_dynamic_dataNodeId(uint32 dataNodeId); + +extern bool process_auto_switchover_full_check(); +extern bool existMaintenanceInstanceInGroup(uint32 group_index,int *init_primary_member_index); +extern bool isMaintenanceInstance(const char *file_path,uint32 notify_instance_id); + +extern uint32 GetClusterUpgradeMode(); + +extern void cm_to_cm_report_sync_setting(cm_to_cm_report_sync* cm_to_cm_report_sync_content, uint32 sync_cycle_count); +extern void cm_server_process_msg(CM_Connection* con, CM_StringInfo inBuffer); +extern void set_command_status_due_send_status(int send_status); +extern void SwitchOverSetting(int time_out, int instanceType, int ptrIndex, int memberIndex); + +extern void getAZDyanmicStatus( + int azCount, int* statusOnline, int* statusPrimary, int* statusFail, int* statusDnFail, char azArray[][CM_AZ_NAME]); +extern void process_cm_to_cm_report_sync_msg(cm_to_cm_report_sync* cm_to_cm_report_sync_ptr); +extern void process_cm_to_cm_role_change_msg(cm_to_cm_role_change_notify* cm_to_cm_role_change_notify_content_ptr); +extern void process_cm_to_cm_broadcast_msg(cm_to_cm_broadcast* cm_to_cm_broadcast_msg_content_ptr); +extern void process_cm_to_cm_vote_msg(cm_to_cm_vote* cm_to_cm_vote_msg_content_ptr); +extern void check_cluster_status(); +int switchoverFullDone(void); +void set_cluster_status(void); + +void process_ctl_to_cm_balance_result_msg(CM_Connection* con); +void process_ctl_to_cm_get_msg(CM_Connection* con); +void process_ctl_to_cm_build_msg(CM_Connection* con, ctl_to_cm_build* ctl_to_cm_build_ptr); +void process_ctl_to_cm_query_msg(CM_Connection* con, ctl_to_cm_query* ctl_to_cm_query_ptr); +void process_ctl_to_cm_query_kerberos_status_msg(CM_Connection* con); +void process_ctl_to_cm_query_cmserver_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_all_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_full_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_full_check_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_full_timeout_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_az_msg(CM_Connection* con, ctl_to_cm_switchover* ctl_to_cm_swithover_ptr); +void process_ctl_to_cm_switchover_az_check_msg(CM_Connection* con); +void process_ctl_to_cm_switchover_az_timeout_msg(CM_Connection* con); +void process_ctl_to_cm_setmode(CM_Connection* con); +void process_ctl_to_cm_set_msg(CM_Connection* con, ctl_to_cm_set* ctl_to_cm_set_ptr); +void process_ctl_to_cm_balance_check_msg(CM_Connection* con); +void process_ctl_to_cm_get_datanode_relation_msg( + CM_Connection* con, ctl_to_cm_datanode_relation_info* ctl_to_cm_datanode_relation_info_ptr); + +void process_cm_to_cm_timeline_msg(cm_to_cm_timeline* cm_to_cm_timeline_msg_content_ptr); + +void process_gs_guc_feedback_msg(agent_to_cm_gs_guc_feedback* feedback_ptr); +void process_notify_cn_feedback_msg(CM_Connection* con, agent_to_cm_notify_cn_feedback* feedback_ptr); +void process_agent_to_cm_heartbeat_msg(CM_Connection* con, agent_to_cm_heartbeat* agent_to_cm_heartbeat_ptr); +void process_agent_to_cm_disk_usage_msg(CM_Connection* con, AgentToCMS_DiskUsageStatusReport* agent_to_cm_disk_usage_ptr); +void process_agent_to_cm_current_time_msg(agent_to_cm_current_time_report* etcd_time_ptr); +void process_agent_to_cm_kerberos_status_report_msg( + CM_Connection* con, agent_to_cm_kerberos_status_report* agent_to_cm_kerberos_status_ptr); +void process_agent_to_cm_fenced_UDF_status_report_msg( + agent_to_cm_fenced_UDF_status_report* agent_to_cm_fenced_UDF_status_ptr); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_sync_dynamic_info.h postgresql-hll-2.14/include/include/cm/cm_server/cms_sync_dynamic_info.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_sync_dynamic_info.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_sync_dynamic_info.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_sync_dynamic_info.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_sync_dynamic_info.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_SYNC_DYNAMIC_INFO_H +#define CMS_SYNC_DYNAMIC_INFO_H + +extern void* SyncDynamicInfoFromEtcd(void* arg); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_threads.h postgresql-hll-2.14/include/include/cm/cm_server/cms_threads.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_threads.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_threads.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_threads.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_threads.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_THREADS_H +#define CMS_THREADS_H + +#define SWITCHOVER_FLAG_FILE "cms_need_to_switchover" + +extern int CM_CreateHA(void); +extern int CM_CreateMonitor(void); +extern int CM_CreateMonitorStopNode(void); +extern int CM_CreateThreadPool(int thrCount); + +extern void CreateStorageThresholdCheckThread(); +extern void create_deal_phony_alarm_thread(); +extern void CreateAzStatusCheckForAzThread(); +extern void CreateAz1Az2ConnectStateCheckThread(); +extern void Init_cluster_to_switchover(); +extern void CreateSyncDynamicInfoThread(); +extern void CreateMultiAzConnectStateCheckThread(); +extern void CreateCheckBlackListThread(); +extern void* CheckBlackList(void* arg); +extern void CreateDynamicCfgSyncThread(); +extern CM_Thread* GetNextThread(int ctlThreadNum); +extern CM_Thread* GetNextCtlThread(int threadNum); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/cm_server/cms_write_dynamic_config.h postgresql-hll-2.14/include/include/cm/cm_server/cms_write_dynamic_config.h --- postgresql-hll-2.14_old/include/include/cm/cm_server/cms_write_dynamic_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/cm_server/cms_write_dynamic_config.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cms_write_dynamic_config.h + * + * IDENTIFICATION + * src/include/cm/cm_server/cms_write_dynamic_config.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CMS_WRITE_DYNAMIC_CONFIG_H +#define CMS_WRITE_DYNAMIC_CONFIG_H + +extern bool NeedCreateWriteDynamicThread(); +extern int WriteDynamicConfigFile(bool isRealWriteDynamic); +extern void *WriteDynamicCfgMain(void *arg); +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/elog.h postgresql-hll-2.14/include/include/cm/elog.h --- postgresql-hll-2.14_old/include/include/cm/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/elog.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/elog.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include "c.h" +#include "pgtime.h" +#include + +#ifdef HAVE_SYSLOG +#ifndef MONITOR_SYSLOG_LIMIT +#define MONITOR_SYSLOG_LIMIT 900 +#endif +#endif + +#define LOG_DESTION_STDERR 0 +#define LOG_DESTION_SYSLOG 1 +#define LOG_DESTION_FILE 2 +#define LOG_DESTION_DEV_NULL 3 + +extern int log_destion_choice; +extern volatile int log_min_messages; +extern volatile int maxLogFileSize; +extern volatile int curLogFileNum; +extern volatile bool logInitFlag; +/* unify log style */ +extern THR_LOCAL const char* thread_name; + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ + +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ + +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define FATAL 22 /* fatal error - abort process */ + +/* + * express means you want to free the space alloced + * by yourself. e.g. express could be "free(str1);free(str2)" + */ +#define check_errno(errno, express, file, line) \ + { \ + if (EOK != errno) { \ + express; \ + write_runlog(ERROR, "%s : %d failed on calling security function, err:%u.\n", file, line, errno); \ + exit(1); \ + } \ + } + +#define securec_check_errno(errno, express) check_errno(errno, express, __FILE__, __LINE__) + +/* Only used in sprintf_s or scanf_s cluster function */ +#define check_intval(errno, express, file, line) \ + { \ + if (errno == -1) { \ + express; \ + write_runlog(ERROR, "check_intval %s : %d failed on calling security function.\n", file, line); \ + exit(1); \ + } \ + } + +#define securec_check_intval(errno, express) check_intval(errno, express, __FILE__, __LINE__) + +#define check_sscanf_s_result(rc, expect_rc) \ + { \ + if (rc != expect_rc) { \ + write_runlog(ERROR, "get value by sscanf_s return error:%d, %s:%d \n", rc, __FILE__, __LINE__); \ + } \ + } + +#define PG_CTL_NAME "gs_ctl" +#define PG_REWIND_NAME "gs_rewind" +#define GTM_CTL_NAME "gtm_ctl" +#define CM_CTL_NAME "cm_ctl" + +#define COORDINATE_BIN_NAME "gaussdb" +#define DATANODE_BIN_NAME "gaussdb" +#define GTM_BIN_NAME "gs_gtm" +#define CM_SERVER_BIN_NAME "cm_server" +#define CM_AGENT_NAME "cm_agent" +#define FENCED_MASTER_BIN_NAME "gaussdb" +#define KERBEROS_BIN_NAME "krb5kdc" + +#define CM_AUTH_REJECT (0) +#define CM_AUTH_TRUST (1) +#define CM_AUTH_GSS (2) + +extern void write_runlog(int elevel, const char* fmt, ...) __attribute__((format(printf, 2, 3))); + +FILE* logfile_open(const char* filename, const char* mode); +void write_runlog(int elevel, const char* fmt, ...); +void add_log_prefix(char* str); + +void write_log_file(const char* buffer, int count); + +#define curLogFileMark ("-current.log") + +int logfile_init(); +void openLogFile(void); +void switchLogFile(void); + +void get_log_paramter(const char* confDir); +int get_cm_thread_count(const char* config_file); +void get_build_mode(const char* config_file); +/*trim blank characters on both ends*/ +char* trim(char* src); +int is_comment_line(const char* str); +int is_digit_string(char* str); +int SetFdCloseExecFlag(FILE* fp); + +/* + * @Description: get value of paramater from configuration file + * + * @in config_file: configuration file path + * @in key: name of paramater + * @in defaultValue: default value of parameter + * + * @out: value of parameter + */ +int get_int_value_from_config(const char* config_file, const char* key, int defaultValue); +int64 get_int64_value_from_config(const char* config_file, const char* key, int64 defaultValue); +uint32 get_uint32_value_from_config(const char* config_file, const char* key, uint32 defaultValue); +extern int get_authentication_type(const char* config_file); +extern void get_krb_server_keyfile(const char* config_file); + +extern const char* prefix_name; + +#define LOG_MAX_TIMELEN 80 + +/* inplace upgrade stuffs */ +extern volatile uint32 undocumentedVersion; +#define INPLACE_UPGRADE_PRECOMMIT_VERSION 1 + +#endif /* GTM_ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/etcdapi.h postgresql-hll-2.14/include/include/cm/etcdapi.h --- postgresql-hll-2.14_old/include/include/cm/etcdapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/etcdapi.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,339 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * etcdapi.h + * + * + * + * IDENTIFICATION + * src/include/cm/etcdapi.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _ETCD_API_H_ +#define _ETCD_API_H_ + +typedef int EtcdSession; + +typedef enum { + ETCD_OK = 0, + ETCD_WTF = -1, + EcodeKeyNotFound = 100, + EcodeTestFailed = 101, + EcodeNotFile = 102, + ecodeNoMorePeer = 103, + EcodeNotDir = 104, + EcodeNodeExist = 105, + ecodeKeyIsPreserved = 106, + EcodeRootROnly = 107, + EcodeDirNotEmpty = 108, + ecodeExistingPeerAddr = 109, + EcodeUnauthorized = 110, + ecodeValueRequired = 200, + EcodePrevValueRequired = 201, + EcodeTTLNaN = 202, + EcodeIndexNaN = 203, + ecodeValueOrTTLRequired = 204, + ecodeTimeoutNaN = 205, + ecodeNameRequired = 206, + ecodeIndexOrValueRequired = 207, + ecodeIndexValueMutex = 208, + EcodeInvalidField = 209, + EcodeInvalidForm = 210, + EcodeRefreshValue = 211, + EcodeRefreshTTLRequired = 212, + EcodeRaftInternal = 300, + EcodeLeaderElect = 301, + EcodeWatcherCleared = 400, + EcodeEventIndexCleared = 401, + ecodeStandbyInternal = 402, + ecodeInvalidActiveSize = 403, + ecodeInvalidRemoveDelay = 404, + ecodeClientInternal = 500 +} EtcdResult; + +typedef struct { + // PrevValue specifies what the current value of the Node must + // be in order for the Set operation to succeed. + // Leaving this field empty or NULL means that the caller wishes to + // ignore the current value of the Node. This cannot be used + // to compare the Node's current value to an empty string. + // PrevValue is ignored if Dir=true + char* prevValue; + + // PrevIndex indicates what the current ModifiedIndex of the + // Node must be in order for the Set operation to succeed. + // + // If PrevIndex is set to 0 (default), no comparison is made. + uint64_t prevIndex; + + // TTL defines a period of time after-which the Node should + // expire and no longer exist. Values <= 0 are ignored. Given + // that the zero-value is ignored, TTL cannot be used to set + // a TTL of 0. + int64_t ttl; + + // PrevExist specifies whether the Node must currently exist + // (PrevExist) or not (PrevNoExist). If the caller does not + // care about existence, set PrevExist to PrevIgnore, or simply + // leave it unset. + char prevExist[5]; + + // Refresh set to true means a TTL value can be updated + // without firing a watch or changing the node value. A + // value must not be provided when refreshing a key. + bool refresh; + + // Dir specifies whether or not this Node should be created as a directory. + bool dir; + + // NoValueOnSuccess specifies whether the response contains the current value of the Node. + // If set, the response will only contain the current value when the request fails. + bool noValueOnSuccess; +} SetEtcdOption; + +typedef struct { + // Recursive defines whether or not all children of the Node + // should be returned. + bool recursive; + + // Sort instructs the server whether or not to sort the Nodes. + // If true, the Nodes are sorted alphabetically by key in + // ascending order (A to z). If false (default), the Nodes will + // not be sorted and the ordering used should not be considered + // predictable. + bool sort; + + // Quorum specifies whether it gets the latest committed value that + // has been applied in quorum of members, which ensures external + // consistency (or linearizability). + bool quorum; +} GetEtcdOption; + +typedef struct { + // PrevValue specifies what the current value of the Node must + // be in order for the Delete operation to succeed. + // + // Leaving this field empty means that the caller wishes to + // ignore the current value of the Node. This cannot be used + // to compare the Node's current value to an empty string. + char* prevValue; + + // PrevIndex indicates what the current ModifiedIndex of the + // Node must be in order for the Delete operation to succeed. + // + // If PrevIndex is set to 0 (default), no comparison is made. + uint64_t prevIndex; + + // Recursive defines whether or not all children of the Node + // should be deleted. If set to true, all children of the Node + // identified by the given key will be deleted. If left unset + // or explicitly set to false, only a single Node will be + // deleted. + bool recursive; + + // Dir specifies whether or not this Node should be removed as a directory. + bool dir; +} DeleteEtcdOption; + +typedef struct { + char* host; + unsigned short port; +} EtcdServerSocket; + +const int ETCD_MAX_PATH_LEN = 1024; + +typedef struct { + char etcd_ca_path[ETCD_MAX_PATH_LEN]; + char client_crt_path[ETCD_MAX_PATH_LEN]; + char client_key_path[ETCD_MAX_PATH_LEN]; +} EtcdTlsAuthPath; + +#define ETCD_VALUE_LEN 128 +#define ERR_LEN 1024 +#define ETCD_STATE_LEN 16 +/* The default timeout is 2s */ +const int ETCD_DEFAULT_TIMEOUT = 2000; + +/* + * etcd_open + * + * Establish a session to an etcd cluster.On success, 0 is returned; + * on failure, an error code is returned + * + * session + * The index of the session being created + * + * server_list + * Array of etcd_server structures, with the last having host=NULL. The + * caller is responsible for ensuring that this remains valid as long as + * the session exists. + * + * tls_path + * Certificate information required for HTTPS connection + * + * time_out + * This parameter is used to set the session timeout period. + */ +int etcd_open(EtcdSession* session, EtcdServerSocket* server_list, EtcdTlsAuthPath* tls_path, int time_out); + +/* + * etcd_close + * + * Terminate a session, closing connections and freeing memory (or any other + * resources) associated with it. + * + * session + * The index of the session to be closed. + */ +int etcd_close(int session); + +/* + * etcd_open_str + * + * Create a session for the ETCD cluster with a string containing + * the list of services and certificates and timeout information. + * + * session + * The index of the session being created + * + * server_names + * String containing the service list. If the session information + * exists, The caller is responsible for ensuring that this remains + * valid as long as the session exists. + * + * tls_path + * Certificate information required for HTTPS connection + * + * timeout + * This parameter is used to set the session timeout period. + */ +int etcd_open_str(EtcdSession* session, char* server_names, EtcdTlsAuthPath* tls_path, int timeout); + +/* + * etcd_set + * + * Write a key, with optional previous value (as a precondition). + * + * session + * The index of the session + * + * key + * The etcd key (path) to set. + * + * value + * New value as a null-terminated string. + * + * option + * Indicates the operation information structure of the set operation. + * Currently, only prevValue is used. If prevValue = NULL, prevValue + * is not used. That is, the value of the current node is not considered. + */ +int etcd_set(EtcdSession session, char* key, char* value, SetEtcdOption* option); + +/* + * etcd_get + * + * Fetch a key from one of the servers in a session.On success, 0 is returned; + * on failure, an error code is returned + * + * session + * The index of the session + * + * key + * The etcd key (path) to fetch. + * + * value + * The value of the key, it is a newly allocated string, which must be + * freed by the caller. + * + * max_size + * defines the max buffer size of health_member + * + * option + * Operation information structure of the Get operation. Currently, + * only quorum is used to specify whether to obtain the latest committed + * value applied in the member arbitration to ensure external consistency + * (or linearization). + */ +int etcd_get(int session, char* key, char* value, int max_size, GetEtcdOption* option); + +/* + * etcd_delete + * + * Delete a key from one of the servers in a session. + * + * session + * The index of the session + * + * key + * The etcd key (path) to delete. + * + * option + * Indicates the operation information structure of the Delete operation. + * No information is used at present. + */ +int etcd_delete(int session, char* key, DeleteEtcdOption* option); + +/* + * etcd_cluster_health + * + * Get the health of the cluster.If member_name is not empty, check the health + * status of the corresponding etcd node and store the health status into + * health_member. If member_name is empty, check the health status of the entire + * etcd cluster and write health_member. + * + * session + * The index of the session + * + * member_name + * etcd member name,If this parameter is set to NULL or an empty string, + * the health status of the ETCD cluster is obtained. If the character + * string is a node name, it indicates the health status of a node. + * + * health_state + * Save the etcd cluster health information + * + * state_Size + * defines the max buffer size of health_member + */ +int etcd_cluster_health(int session, char* member_name, char* health_state, int state_Size); + +/* + * etcd_cluster_state + * + * Get the state of the cluster member. + * + * session + * The index of the session + * + * member_name + * etcd member name + * + * is_leader + * Whether this node is the leader node or not + */ +int etcd_cluster_state(int session, char* member_name, bool* is_leader); + +/* + * get_last_error + * + * Obtains the information that fails to be invoked and saves the information to the buffer. If the interface is + * successfully invoked, the buffer is empty. + * + */ +const char* get_last_error(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/ip.h postgresql-hll-2.14/include/include/cm/ip.h --- postgresql-hll-2.14_old/include/include/cm/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/ip.h 2020-12-12 17:06:43.175347109 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/ip.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "cm/pqcomm.h" + +extern int cmpg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void cmpg_freeaddrinfo_all(struct addrinfo* ai); + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/libpq-be.h postgresql-hll-2.14/include/include/cm/libpq-be.h --- postgresql-hll-2.14_old/include/include/cm/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/libpq-be.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,129 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-be.h + * This file contains definitions for structures and externs used + * by the cm server during client coonect. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/libpq-be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_BE_H +#define CM_LIBPQ_BE_H + +#include "cm/pqcomm.h" +#include "cm/cm_c.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * This is used by the cm server in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMostMemoryContext, + * so that it survives into GTM_ThreadMain execution! + */ + +typedef struct Port { + int sock; /* File descriptor */ + CMSockAddr laddr; /* local addr (postmaster) */ + CMSockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_port; /* text rep of remote port */ + CM_PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ + + char* user_name; + int remote_type; /* Type of remote connection */ + uint32 node_id; + char* node_name; + bool is_postmaster; /* Is remote a node postmaster? */ + bool startpack_have_processed; +#define PQ_BUFFER_SIZE (16 * 1024) + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + + /* + * GTM communication error handling. See libpq-int.h for details. + */ + int connErr_WaitOpt; + int connErr_WaitInterval; + int connErr_WaitCount; + + /* Support kerberos authentication for gtm server */ + char* krbsrvname; /* Kerberos service name */ +} Port; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); +extern int pq_getbyte(Port* myport); +extern int pq_getmessage(Port* myport, CM_StringInfo s, int maxlen); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int SetSocketNoBlock(int isocketId); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/libpq-fe.h postgresql-hll-2.14/include/include/cm/libpq-fe.h --- postgresql-hll-2.14_old/include/include/cm/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/libpq-fe.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * + * IDENTIFICATION + * src/include/cm/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_FE_H +#define CM_LIBPQ_FE_H + +#include +#include "cm_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define libpq_gettext(x) x + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +/* Application-visible enum types */ + +/* + * Although it is okay to add to these lists, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + +typedef enum { + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} CMConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} CMPostgresPollingStatusType; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or CMPQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. CMPQconninfoFree() + * will release both the val strings and the CMPQconninfoOption array itself. + * ---------------- + */ +typedef struct _CMPQconninfoOption { + char* keyword; /* The keyword of the option */ + char* val; /* Option's current value, or NULL */ +} CMPQconninfoOption; + +typedef struct cm_conn CM_Conn; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern CM_Conn* PQconnectCMStart(const char* conninfo); +extern CMPostgresPollingStatusType CMPQconnectPoll(CM_Conn* conn); + +/* Synchronous (blocking) */ +extern CM_Conn* PQconnectCM(const char* conninfo); + +/* close the current connection and free the CM_Conn data structure */ +extern void CMPQfinish(CM_Conn* conn); + +/* free the data structure returned by PQconndefaults() or CMPQconninfoParse() */ +extern void CMPQconninfoFree(CMPQconninfoOption* connOptions); + +extern CMConnStatusType CMPQstatus(const CM_Conn* conn); +extern char* CMPQerrorMessage(const CM_Conn* conn); + +/* Force the write buffer to be written (or at least try) */ +extern int CMPQflush(CM_Conn* conn); + +extern int CMPQPacketSend(CM_Conn* conn, char packet_type, const void* buf, size_t buf_len); +extern char* gs_getenv_with_check(const char* envKey); + +#ifdef __cplusplus +} +#endif + +#endif /* CM_LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/libpq.h postgresql-hll-2.14/include/include/cm/libpq.h --- postgresql-hll-2.14_old/include/include/cm/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/libpq.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/libpq.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_H +#define CM_LIBPQ_H + +#include +#include + +#include "cm/stringinfo.h" +#include "cm/libpq-be.h" + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); + +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len, size_t* recvlen); + +extern int pq_getmessage(Port* myport, CM_StringInfo s, int maxlen); +extern int pq_getbyte(Port* myport); + +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/libpq-int.h postgresql-hll-2.14/include/include/cm/libpq-int.h --- postgresql-hll-2.14_old/include/include/cm/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/libpq-int.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,162 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * + * IDENTIFICATION + * src/include/cm/libpq-int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_INT_H +#define CM_LIBPQ_INT_H + +#include +#include +#include +#include "cm/pqcomm.h" +#include "cm/pqexpbuffer.h" +#include "cm/cm_c.h" +#include "cm/cm_msg.h" + +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * cm_Conn stores all the state data associated with a single connection + * to a backend. + */ +struct cm_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the IPv4 address of the machine on which + * the server is running, in IPv4 + * numbers-and-dots notation. Takes precedence + * over above. */ + char* pgport; /* the server's communication port */ + char* pglocalhost; + char* pglocalport; + char* connect_timeout; /* connection timeout (numeric string) */ + char* pguser; /* CM username and password, if any */ + int node_id; + char* gc_node_name; /* PGXC Node Name */ + int remote_type; /* is this a connection to/from a proxy ? */ + int is_postmaster; /* is this connection to/from a postmaster instance */ + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Status indicators */ + CMConnStatusType status; + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + CMSockAddr laddr; /* Local address */ + CMSockAddr raddr; /* Remote address */ + + /* Error info for cm communication */ + int last_call; + int last_errno; /* Last errno. zero if the last call succeeds. */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + + /* Pointer to the result of last operation */ + CM_Result* result; + + /* Support kerberos authentication for gtm server */ + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_name_t gss_targ_nam; /* GSS target name */ + gss_buffer_desc gss_inbuf; /* GSS input token */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +}; + +/* === in fe-misc.c === */ + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int cmpqCheckOutBufferSpace(size_t bytes_needed, CM_Conn* conn); +extern int cmpqCheckInBufferSpace(size_t bytes_needed, CM_Conn* conn); +extern int cmpqGetc(char* result, CM_Conn* conn); +extern int cmpqGets(PQExpBuffer buf, CM_Conn* conn); +extern int cmpqGets_append(PQExpBuffer buf, CM_Conn* conn); +extern int cmpqPutnchar(const char* s, size_t len, CM_Conn* conn); +extern int cmpqGetnchar(char* s, size_t len, CM_Conn* conn); +extern int cmpqGetInt(int* result, size_t bytes, CM_Conn* conn); +extern int cmpqPutMsgStart(char msg_type, bool force_len, CM_Conn* conn); +extern int cmpqPutMsgEnd(CM_Conn* conn); +extern int cmpqReadData(CM_Conn* conn); +extern int cmpqFlush(CM_Conn* conn); +extern int cmpqWait(int forRead, int forWrite, CM_Conn* conn); +extern int cmpqWaitTimed(int forRead, int forWrite, CM_Conn* conn, time_t finish_time); +extern int cmpqReadReady(CM_Conn* conn); + +/* + * In fe-protocol.c + */ +extern CM_Result* cmpqGetResult(CM_Conn* conn); +extern int cmpqGetError(CM_Conn* conn, CM_Result* result); +extern void cmpqResetResultData(CM_Result* result); + +#define SOCK_ERRNO errno +#define SOCK_ERRNO_SET(e) (errno = (e)) + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/path.h postgresql-hll-2.14/include/include/cm/path.h --- postgresql-hll-2.14_old/include/include/cm/path.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/path.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * path.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/path.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PATH_H +#define _PATH_H + +#include "cm/cm_c.h" + +extern void trim_directory(char* path); +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/pqcomm.h postgresql-hll-2.14/include/include/cm/pqcomm.h --- postgresql-hll-2.14_old/include/include/cm/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/pqcomm.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/cm/pqcomm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_PQCOMM_H +#define CM_PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} CMSockAddr; + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +/* These are the authentication request codes sent by gtm server. */ +#define CM_AUTH_REQ_OK 0 /* User is authenticated */ +#define CM_AUTH_REQ_GSS 1 /* GSSAPI without wrap() */ +#define CM_AUTH_REQ_GSS_CONT 2 /* Continue GSS exchange */ + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/pqexpbuffer.h postgresql-hll-2.14/include/include/cm/pqexpbuffer.h --- postgresql-hll-2.14_old/include/include/cm/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/pqexpbuffer.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqexpbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H + +/*------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + *------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/*------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + *------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/*------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + *------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/*------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + *------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/*------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createCMPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initCMPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + *------------------------- + */ + +/*------------------------ + * initCMPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyCMPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createCMPQExpBuffer(). + * + * termCMPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initCMPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void termCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * resetCMPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetCMPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * enlargeCMPQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargeCMPQExpBuffer(PQExpBuffer str, size_t needed); + +/*------------------------ + * printfCMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetCMPQExpBuffer() followed by appendCMPQExpBuffer(). + */ +extern void printfCMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendCMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendCMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendBinaryCMPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryCMPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/pqformat.h postgresql-hll-2.14/include/include/cm/pqformat.h --- postgresql-hll-2.14_old/include/include/cm/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/pqformat.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqformat.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "cm/stringinfo.h" +#include "cm/cm_msg.h" + +extern const char* pq_get_msg_type(CM_StringInfo msg, int datalen); +extern const char* pq_getmsgbytes(CM_StringInfo msg, int datalen); +extern const char* pq_getmsgbytes(CM_Result* msg, int datalen); +#endif diff -uprN postgresql-hll-2.14_old/include/include/cm/pqsignal.h postgresql-hll-2.14/include/include/cm/pqsignal.h --- postgresql-hll-2.14_old/include/include/cm/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/pqsignal.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/pqsignal.h + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +extern sigset_t unblock_sig, block_sig; + +typedef void (*sigfunc)(int); + +extern void init_signal_mask(void); + +#ifndef WIN32 +extern sigfunc setup_signal_handle(int signo, sigfunc func); +#endif /* WIN32 */ + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/cm/stringinfo.h postgresql-hll-2.14/include/include/cm/stringinfo.h --- postgresql-hll-2.14_old/include/include/cm/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cm/stringinfo.h 2020-12-12 17:06:43.176347122 +0800 @@ -0,0 +1,184 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/cm/stringinfo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_STRINGINFO_H +#define CM_STRINGINFO_H + +#include + +/*------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + *------------------------- + */ +typedef struct CM_StringInfoData { + char* data; + int len; + int maxlen; + int cursor; + int qtype; + int msglen; +} CM_StringInfoData; + +typedef CM_StringInfoData* CM_StringInfo; + +#define CM_MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define CM_AllocSizeIsValid(size) ((Size)(size) <= CM_MaxAllocSize) + +/*------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + *------------------------- + */ + +/*------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern CM_StringInfo CM_makeStringInfo(void); + +/*------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void CM_initStringInfo(CM_StringInfo str); + +/*------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void CM_resetStringInfo(CM_StringInfo str); + +/*------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void CM_appendStringInfo(CM_StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/*------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool CM_appendStringInfoVA(CM_StringInfo str, const char* fmt, va_list args) + __attribute__((format(printf, 2, 0))); + +/*------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void CM_appendStringInfoString(CM_StringInfo str, const char* s); + +/*------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void CM_appendStringInfoChar(CM_StringInfo str, char ch); + +/*------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define CM_appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? CM_appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/*------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void CM_appendBinaryStringInfo(CM_StringInfo str, const char* data, int datalen); + +/*------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern int CM_enlargeStringInfo(CM_StringInfo str, int needed); + +/*----------------------- + * dupStringInfo + * Get new StringInfo and copy the original to it. + */ +extern CM_StringInfo CM_dupStringInfo(CM_StringInfo orig); + +/*------------------------ + * copyStringInfo + * Copy StringInfo. Deep copy: Data will be copied too. + * cursor of "to" will be initialized to zero. + */ +extern void CM_copyStringInfo(CM_StringInfo to, CM_StringInfo from); + +extern int CM_is_str_all_digit(const char* name); +extern void CM_destroyStringInfo(CM_StringInfo str); +extern void CM_freeStringInfo(CM_StringInfo str); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/codegen/builtinscodegen.h postgresql-hll-2.14/include/include/codegen/builtinscodegen.h --- postgresql-hll-2.14_old/include/include/codegen/builtinscodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/builtinscodegen.h 2020-12-12 17:06:43.177347135 +0800 @@ -0,0 +1,173 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * builtinscodegen.h + * Declarations of code generation for operations on built-in types. + * + * + * IDENTIFICATION + * src/include/codegen/builtinscodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_BUILTINS_H +#define LLVM_BUILTINS_H +#include "catalog/pg_type.h" +#include "codegen/gscodegen.h" +#include "fmgr.h" +#include "nodes/execnodes.h" +#include "nodes/primnodes.h" +#include "utils/biginteger.h" + +namespace dorado { +/* Get the byte length of a multibyte character. */ +#define MB_LEN(mlen, string) \ + if ((*string & 0x80) == 0) \ + mlen = 1; \ + else if ((*string & 0xe0) == 0xc0) \ + mlen = 2; \ + else if ((*string & 0xf0) == 0xe0) \ + mlen = 3; \ + else if ((*string & 0xf8) == 0xf0) \ + mlen = 4; \ + else \ + mlen = 1; + +/* + * int_codegen.inl + * template function for simple op('='/'!='/'<='/'>='/'<'/'>') of int type. + */ +template +llvm::Function* int2_sop_codegen(); +template +llvm::Function* int4_sop_codegen(); +template +llvm::Function* int8_sop_codegen(); +template +llvm::Function* int2_int4_sop_codegen(); +template +llvm::Function* int4_int8_sop_codegen(); + +/* + * numeric_codegen.inl + * template function for simple op('='/'!='/'<='/'>='/'<'/'>') of numeric type. + * Since most cases the data can be converted to BI integer, we especially + * codegen the bi64 operations. For orginal numeric data, just call original + * row functions. + */ +template +llvm::Function* numeric_sop_codegen(); +template +llvm::Function* bi64cmp64_codegen(); +template +llvm::Function* fast_numericbi_sop_codegen(); +template +llvm::Value* WrapnumericFuncCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* arg); + +/* boolcodegen.cpp */ +llvm::Function* booleq_codegen(); + +/* intcodegen.cpp */ +llvm::Function* int4pl_codegen(); +llvm::Function* int4mi_codegen(); +llvm::Function* int4mul_codegen(); +llvm::Function* int4div_codegen(); +llvm::Function* int8pl_codegen(); +llvm::Function* int8mi_codegen(); +llvm::Function* int8mul_codegen(); +llvm::Function* int8div_codegen(); +llvm::Function* int48pl_codegen(); +llvm::Function* int84pl_codegen(); +llvm::Function* int48mi_codegen(); +llvm::Function* int84mi_codegen(); +llvm::Function* int48mul_codegen(); +llvm::Function* int84mul_codegen(); +llvm::Function* int48div_codegen(); +llvm::Function* int84div_codegen(); + +/* floatcodegen.cpp */ +llvm::Function* float8eq_codegen(); +llvm::Function* float8ne_codegen(); +llvm::Function* float8lt_codegen(); +llvm::Function* float8le_codegen(); +llvm::Function* float8gt_codegen(); +llvm::Function* float8ge_codegen(); + +/* numericcodegen.cpp */ +llvm::Function* int8_sum_codegen(Aggref* aggref); +llvm::Function* int8_avg_codegen(Aggref* aggref); +llvm::Function* numeric_sum_codegen(Aggref* aggref); +llvm::Function* vsnumeric_sum_codegen(Aggref* aggref); +llvm::Function* numeric_avg_codegen(Aggref* aggref); +llvm::Function* vsnumeric_avg_codegen(Aggref* aggref); +llvm::Function* vec_count_codegen(Aggref* aggref); +llvm::Function* vsonic_count_codegen(Aggref* aggref); + +/* assistant function needed by numeric agg functions */ +llvm::Value* DatumGetBINumericCodeGenShort(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval); +llvm::Value* DatumGetBINumericCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval); +llvm::Value* WrapaddVariableCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ccontext, llvm::Value* val); +llvm::Value* WrapreplVariableCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ccontext, llvm::Value* oldval, llvm::Value* val); +llvm::Value* WrapmakeNumeric64CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* scale); +llvm::Value* WrapmakeNumeric128CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* scale); +void WrapBiAggAddMatrixCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* arg1, llvm::Value* arg2, + llvm::Value* leftarg, llvm::Value* rightarg, llvm::Value* ctl); +llvm::Value* WrapBiFunMatrixCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* op, llvm::Value* arg1, + llvm::Value* arg2, llvm::Value* leftarg, llvm::Value* rightarg); +void WrapDeconstructArrayCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* pval, llvm::Value* datumarray, llvm::Value* ndatum); +void WrapcallnumericaddCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* cell, llvm::Value* mct, + llvm::Value* larg, llvm::Value* rarg, llvm::Value* nidx); +void WrapcallscnumaddCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data, llvm::Value* larg, llvm::Value* rarg, llvm::Value* loc); + +/* bigintegercodegen.cpp */ +llvm::Function* bi64add64_codegen(bool use_ctl); +llvm::Function* bi64sub64_codegen(); +llvm::Function* bi64mul64_codegen(); +llvm::Function* bi64div64_codegen(); + +/* assistant function needed by biginteger functions */ +llvm::Value* GetInt64MulOutofBoundCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +llvm::Value* ScaleMultiCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +llvm::Value* GetScaleMultiCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* deltascale); +void WrapReplVarWithOldCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* ctl, llvm::Value* Val); +llvm::Value* Wrapbi64div64CodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* larg, llvm::Value* rarg); + +/* varcharcodegen.cpp */ +llvm::Function* bpchareq_codegen(); +llvm::Function* bpcharne_codegen(); +llvm::Function* bpcharlen_codegen(int current_encoding); + +/* varlenacodegen.cpp */ +llvm::Function* texteq_codegen(); +llvm::Function* textlt_codegen(); +llvm::Function* textgt_codegen(); +llvm::Function* substr_codegen(); +llvm::Function* rtrim1_codegen(); +llvm::Function* btrim1_codegen(); +llvm::Function* textlike_codegen(); +llvm::Function* textnlike_codegen(); + +llvm::Function* VarlenaCvtCodeGen(); +llvm::Value* VarlenaGetDatumCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* len, llvm::Value* data); +} // namespace dorado + +/* Include template function in int_codegen.inl */ +#include "../../gausskernel/runtime/codegen/codegenutil/int_codegen.inl" +#include "../../gausskernel/runtime/codegen/codegenutil/numeric_codegen.inl" + +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/codegendebuger.h postgresql-hll-2.14/include/include/codegen/codegendebuger.h --- postgresql-hll-2.14_old/include/include/codegen/codegendebuger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/codegendebuger.h 2020-12-12 17:06:43.177347135 +0800 @@ -0,0 +1,89 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * codegendebuger.h + * + * + * + * IDENTIFICATION + * src/include/codegen/codegendebuger.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CODEGEN_DEBUGER_H +#define CODEGEN_DEBUGER_H + +#include "codegen/gscodegen.h" + +namespace dorado { +class DebugerCodeGen : public BaseObject { +public: + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Support debuging in machine code by calling c-function + * WrapCodeGenDebuger. + * Input : ptrbuilder : in which builder we call this function + * value : the actual value when running. + * flag : mask the position to distinct diffrent cases + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void CodeGenDebugInfo(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* value, Datum flag); + + static void CodeGenDebugString(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* value, Datum flag); + + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Support debuging in machine code by calling c-function + * WrapElog. + * Input : ptrbuilder : in which builder we call this function + * eleval : reporting level. + * cvalue : the actual error string defined in LLVM function. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void CodeGenElogInfo(GsCodeGen::LlvmBuilder* ptrbuilder, Datum elevel, const char* cvalue); + + /* + * Brief : Wrap an elog function to support gdb functionability. + * Description : Wrap the elog function, with which we could easily + * see the actual value when debugging. + * Input : value : the actual value when running. + * flag : mask the position to distinct diffrent cases + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void WrapCodeGenDebuger(Datum value, Datum flag); + + static void WrapCodeGenString(char* string, Datum flag); + + /* + * Brief : Wrap an elog function with different error level. + * Description : Wrap the elog function, which will be call in LLVM + * to support error reporting. + * Input : elevel : reporting level. + * strdate : the actual error string. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static void WrapCodeGenElog(Datum elevel, char* strdata); +}; +} // namespace dorado + +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/datecodegen.h postgresql-hll-2.14/include/include/codegen/datecodegen.h --- postgresql-hll-2.14_old/include/include/codegen/datecodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/datecodegen.h 2020-12-12 17:06:43.177347135 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datecodegen.h + * Definitions of code generation for the SQL92 "date" and + * "time" types. + * + * + * IDENTIFICATION + * src/include/codegen/datecodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_DATE_H +#define LLVM_DATE_H +#include "codegen/gscodegen.h" + +namespace dorado { +/* + * Comparision functions for dates + */ +llvm::Function* date_eq_codegen(); +llvm::Function* date_ne_codegen(); +llvm::Function* date_lt_codegen(); +llvm::Function* date_le_codegen(); +llvm::Function* date_gt_codegen(); +llvm::Function* date_ge_codegen(); +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/codegen/foreignscancodegen.h postgresql-hll-2.14/include/include/codegen/foreignscancodegen.h --- postgresql-hll-2.14_old/include/include/codegen/foreignscancodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/foreignscancodegen.h 2020-12-12 17:06:43.177347135 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * foreignscancodegen.h + * + * + * + * IDENTIFICATION + * src/include/codegen/foreignscancodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_FOREIGN_SCAN_H +#define LLVM_FOREIGN_SCAN_H + +#include "codegen/gscodegen.h" +#include "optimizer/clauses.h" +#include "nodes/execnodes.h" + +namespace dorado { + +/* + * LlvmForeignScan class implements specific optimization by using LLVM. + * Just now, pushed down predicate is optimized by using LLVM. + */ +class ForeignScanCodeGen : public BaseObject { +public: + static bool ScanCodeGen(Expr* expr, PlanState* parent, void** jittedFunc); + + /* + * Brief : Check whether operator is legal or not. + * Description : Just now, the follwing operator is legal. + * "=", "!=", ">", ">=", "<", "<=". + * These operator must act on the following data types. + * int2, int4, int8, float4, float8. + * Input : expr, the node to be checked. + * Output : None. + * Return Value : None. + * Notes : None. + */ + static bool IsJittableExpr(Expr* expr); + + /* + * Brief : Build LLVM value by using node. + * Description : + * Input : node, the node to be used to create IR. + * llvm_args, the argument of IR functionto to be created. + * builder, a LlvmBuilder object. + * fname, function name. + * Output : None. + * Return Value : Retrun llvm::Value. + * Notes : None. + */ + static llvm::Value* buildConstValue( + Expr* node, llvm::Value* llvm_args[], GsCodeGen::LlvmBuilder builder, StringInfo fname); +}; +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/codegen/gscodegen.h postgresql-hll-2.14/include/include/codegen/gscodegen.h --- postgresql-hll-2.14_old/include/include/codegen/gscodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/gscodegen.h 2020-12-12 17:06:43.177347135 +0800 @@ -0,0 +1,756 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gscodegen.h + * + * + * + * IDENTIFICATION + * src/include/codegen/gscodegen.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_CODEGENH +#define GS_CODEGENH + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +#endif + +#include "llvm/IR/Verifier.h" +#include "llvm/ExecutionEngine/MCJIT.h" +#include "llvm/ExecutionEngine/ObjectCache.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Intrinsics.h" +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/circular_raw_ostream.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/raw_os_ostream.h" + +#undef __STDC_LIMIT_MACROS +#include "c.h" +#include "nodes/pg_list.h" +#include "lib/stringinfo.h" +#include "utils/dfs_vector.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +#ifndef BITS +#define BITS 8 +#endif + +/* The max length of the IR Function's path */ +#define MAX_LLVMIR_PATH 1024 + +/* position of elements that needed in vechashtbl */ +#define pos_hashtbl_size 0 +#define pos_hashtbl_data 1 + +/* position of elements that needed in VectorBatch class */ +#define pos_batch_mrows 0 +#define pos_batch_mcols 1 +#define pos_batch_marr 4 + +/* position of elements that needed in ScalarVector class */ +#define pos_scalvec_mrows 0 +#define pos_scalvec_flag 3 +#define pos_scalvec_vals 5 + +/* position of elements that needed in hashJoinTbl class */ +#define pos_hjointbl_inbatch 12 +#define pos_hjointbl_outbatch 13 +#define pos_hjointbl_StateLog 23 +#define pos_hjointbl_match 26 + +/* position of elements that needed in hashBasedOperator class */ +#define pos_hBOper_htbl 1 +#define pos_hBOper_hcxt 2 +#define pos_hBOper_cacheLoc 4 +#define pos_hBOper_cellCache 5 +#define pos_hBOper_keyMatch 6 +#define pos_hBOper_cols 18 +#define pos_hBOper_mkey 19 +#define pos_hBOper_keyIdx 20 + +/* position of elements that needed in HashAggRunner class */ +#define pos_hAggR_hashVal 3 +#define pos_hAggR_hSegTbl 12 +#define pos_hAggR_hsegmax 14 +#define pos_hAggR_hashSize 15 + +/* position of elements that needed in BaseAggRunner class */ +#define pos_bAggR_keyIdxInCell 8 +#define pos_bAggR_keySimple 11 +#define pos_bAggR_Loc 18 +#define pos_bAggR_econtext 22 + +/* position of elements that needed in ExprContext structure */ +#define pos_ecxt_pertuple 5 +#define pos_ecxt_scanbatch 17 +#define pos_ecxt_innerbatch 18 +#define pos_ecxt_outerbatch 19 + +/* position of elements that needed in hashCell structure */ +#define pos_hcell_mval 1 + +/* position of elements that needed in hashVal structure */ +#define pos_hval_val 0 +#define pos_hval_flag 1 + +/* position of elements that needed in StringInfo structure */ +#define pos_strinfo_data 0 +#define pos_strinfo_len 1 + +/* position of elements that needed in SonicHashAgg structure */ +#define pos_shashagg_ecxt 12 + +/* position of elements that needed in SonicHash structure */ +#define pos_shash_data 1 +#define pos_shash_sonichmemctl 14 +#define pos_shash_loc 16 + +/* position of elements that needed in SonicHashMemoryControl structure */ +#define pos_sonichmemctl_hcxt 8 + +/* position of elements that needed in SonicDatumArray structure */ +#define pos_sdarray_cxt 1 +#define pos_sdarray_atomsize 5 +#define pos_sdarray_nbit 7 +#define pos_sdarray_arr 8 + +/* position of elements that needed in atom structure */ +#define pos_atom_data 0 +#define pos_atom_nullflag 1 + +/* + * Declare related LLVM classes to avoid namespace pollution. + */ +namespace llvm { +class AllocaInst; +class BasicBlock; +class ConstantFolder; +class ExecutionEngine; +class Function; +using legacy::FunctionPassManager; +class LLVMContext; +class Module; +class NoFolder; +using legacy::PassManager; +class PointerType; +class StructType; +class TargetData; +class Type; +class Value; +class PassManagerBuilder; + +template +class IRBuilder; + +class IRBuilderDefaultInserter; +} // namespace llvm + +namespace dorado { + +/* + * @Description : Check whether we have the right to init codegen inviroment. + * @return : Return true if we can initialize the codgen inviroment. + */ +bool canInitCodegenInvironment(); + +/* + * @Description : Check whether we can initialize the CodeGen Object. + * @return : Return true if we can initialize the GsCodeGen Obj. + */ +bool canInitThreadCodeGen(); + +class GsCodeGen : public BaseObject { +public: + void initialize(); + + /* + * @Brief : Initialize LLVM environment. + * @Description : This function must be called once per process before + * any llvm API called. LLVM needs to allocate data + * structures for multi-threading support and to enable + * dynamic linking of jitted code. if 'load_backend' is + * true, load the backend static object for llvm. This + * is needed when libbackend.so is loaded from java. llvm + * will be default only look in the current object and + * not be able to find the backend symbols. + * @in load_backend : Decide to load the backend static object or not. + * The default value is false. + * @return : Return true if succeed. + */ + static bool InitializeLlvm(bool load_backend = false); + + /* + * @Description : Clear up the LLVM environment. + */ + static void cleanUpLlvm(); + + /* + * @Description : Load IR file and create a module. + * @in filename : Finename, a IR file path, like:\user\xxx\xxx.ir. + * @return : Return true if succeed.. + */ + bool parseIRFile(StringInfo filename); + + /* + * @Description : Find the location of IR file and load it. + */ + void loadIRFile(); + + /* + * Typedef builder in case we want to change the template arguments later + */ + typedef llvm::IRBuilder<> LlvmBuilder; + + /* + * Utility struct that wraps a variable name and llvm type. + */ + struct NamedVariable { + char* name; + llvm::Type* type; + + NamedVariable(char* name = "", llvm::Type* type = NULL) + { + this->name = name; + this->type = type; + } + }; + + /* + * define a Llvm_map which is similar to std::map + * in order to stroe the key-value pairs. + */ + template + class Llvm_Map : public BaseObject { + public: + T_KEY key; + T_VALUE value; + }; + + /* + * Abstraction over function prototypes. Contains helpers to build prototypes and + * generate IR for the types. + */ + class FnPrototype { + public: + /* + * @Description : Create a function prototype object + * @in gen : A LlvmCodeGen pointer. + * @in name : A specified function name. + * @in ret_type : The return value of the LLVM function. + * @Notes : It is a constructor. + */ + FnPrototype(GsCodeGen* gen, const char* name, llvm::Type* ret_type); + + /* + * @Description : Add a argument for the function. + * @in var : var, a struct for function argument + */ + void addArgument(const NamedVariable& var) + { + functionArgs.push_back(var); + } + + /* + * @Description : Create a LLVM function prototype. + * @in builder : The LLVM object, obtain many api for building LLVM function. + * @in params : return argumnets of LLVM function created. + * @return : return a created LLVM function pointer. + * @Notes : If params is non-null, this function will also + * return the arguments. + */ + llvm::Function* generatePrototype(LlvmBuilder* builder = NULL, llvm::Value** params = NULL); + + private: + friend class GsCodeGen; + + GsCodeGen* codeGen; + + char* functionName; /* functions name */ + llvm::Type* returnType; + + Vector functionArgs; /* the functions parameters */ + }; + + /* + * @Brief : Get a PointerType pointer. + * @Description : Get a LLVM Type pointer point to 'type'. + * @in type : a type struct of LLVM namespace. + * @return : return a PointerType pointer. + */ + llvm::PointerType* getPtrType(llvm::Type* type); + + /* + * @Brief : Get a Void Type of LLVM namespace + * @return : return the void type in LLVM Data Type. + */ + llvm::Type* getVoidType(); + + /* + * @Description : Get a Type of LLVM namespace according to a type OID. + * @in type : A type OID in Gauss200 database. + * @return : return a LLVM Data Type . + */ + llvm::Type* getType(unsigned int type); + + /* + * @Description : Get a PointerType pointer of LLVM namespace. + * @in type : A type OID in Gauss200 database. + * @return : return a PointerType Type . + */ + llvm::PointerType* getPtrType(unsigned int type); + + /* + * @Description : Get a Type of LLVM namespace according to a type name. + * : This name should be the one recorded in LLVM module. + * @in name : name of the struct type/class type. + * @return : return a Type . + */ + llvm::Type* getType(const char* name); + + /* + * @Description : Get a Type of LLVM namespace according to the 'name' type. + * @in type : A type name which can be recognized in Gauss200 database. + * @return : return a PointerType Type. + */ + llvm::PointerType* getPtrType(const char* name); + + /* + * @Description : Create a llvm pointer value from 'ptr'. This is used + * to pass pointers between c-code and code-generated IR. + * @in type : Data type in LLVM assemble with respect to the actual + * c-type we want to codegen. + * @in ptr : Pointer point to the actual c-code data type. + * @return : value in 'type' type. + */ + llvm::Value* CastPtrToLlvmPtr(llvm::Type* type, const void* ptr); + + /* + * @Description : Get reference to llvm context object. + * Each GsCodeGen has its own context to allow multiple + * threads to be calling into llvm at the same time. + * @return : Return reference to llvm context object. + */ + llvm::LLVMContext& context(); + + /* + * @Description : Get a current module. + * Module looks likes a container, which contains varibles, + * functions and types. + * @return : Return the current module in use. + */ + llvm::Module* module() + { + return m_currentModule; + } + + /* + * @Description : Adds the IR function to m_machineCodeJitCompiled List + * of GsCodeGen Object. Make a map which is consisted of + * IR function and machine code function pointer. At this + * time, the machine function pointer is a NULL pointer. + * @in F : A IR function which will be as a key of map. + * @in result_fn_ptr : A machine code function pointer which will be as + * a value of map. + * @return : void + */ + void addFunctionToMCJit(llvm::Function* F, void** result_fn_ptr); + + /* + * @Description : Adds the c-function calls to m_cfunctions_calls List in case of + * codegen_strategy is 'full'. + * each element in this List is a pair of funcName and funcOid. + * @return : void + */ + void recordCFunctionCalls(char* name); + + /* + * @Description : check whether we have used C-function calls in codegen. + * it will check C-function call recording list, + * and return whether m_cfunction_calls is empty or not + * @return : bool + */ + bool hasCFunctionCalls(); + + /* + * @Description : Clearing the C-function calls list m_cfunction_calls. + * @return : void + */ + void clearCFunctionCalls(); + + /* + * @Description : Dumping out the C-function calls in m_cfunction_calls. + * @in plan_id : plan id as extra information to display. + * @in location : description string for Filter Codegen or Targetlist Codegen. + * @return :void + */ + void dumpCFunctionCalls(const char* location, int plan_id); + + /** + * @Description : Verfies the generated IR function. + * + * @in function : The compiled function. + * @return : Return true if the funcion is valid, else retrun false. . + */ + bool verifyFunction(llvm::Function* function); + + /** + * @Description : + * @in function : LLVM Function we need to check. + * @in plan_node_id : The string flag of this IR function in module . + * @return : Void + */ + void FinalizeFunction(llvm::Function* function, int plan_node_id = 0); + + /* + * @Description : Returns the constant 'val' of 'type'. Since LLVM could only + * deal with arguments with the same type, we should make a + * difference between these types, even with the same value, + * say, int32 0 and int64 0. + * @in type : The corresponding type defined in PG we need to use in LLVM + * @in val : the natural value + * @return : the actual value defined in LLVM + */ + llvm::Value* getIntConstant(unsigned int type, int64_t val); + + /* + * @Description : Loads an LLVM module. 'file' should be the local path to the + * LLVM bitcode (.ll) file. If 'file_size' is not NULL, it will + * be set to the size of 'file'. The caller is responsible for + * cleaning up module. + * @in codegen : A GsCodeGen object. + * @in file : file, a IR file to be loaded. + * @in module : The current module we need to load. + * @return : Return true if successed. + */ + static bool loadModule(GsCodeGen* codegen, char* file, llvm::Module** module); + + /* + * @Description : Get a new llvm::ExecutionEngine with all the IR function + * be compiled. + * @in M : A llvm::Module pointer. + * @in enable_jitcache : If enable_jitcache is true, we need to use cache, + * else we do not need to use cache. + * @return : ExecutionEngien, which includs the module. + */ + llvm::ExecutionEngine* compileModule(llvm::Module* M, bool enable_jitcache); + + /* + * @Description : A GsCodeGen constructor. + * Initialize some variables of LlvmCodegen object. + */ + GsCodeGen(); + + /* + * @Description : release some variables of LlvmCodegen object. + */ + virtual ~GsCodeGen(); + + /* + * @Description : Turns on/off optimization passes for current module. + * @in : enable value, used to decide optimize passes or not + * @out : flag to optimization or not. + */ + void enableOptimizations(bool enable); + + /* + * @Description : Create a new module. + */ + bool createNewModule(); + + /* + * @Description : Create a new engine. + */ + llvm::ExecutionEngine* createNewEngine(llvm::Module* module); + + /* + * @Description : Close the current module. + */ + void closeCurrentModule() + { + m_currentModule = NULL; + } + + /* + * @Description : IR compile to machine code. + */ + void compileCurrentModule(bool enable_jitcache); + + /* + * @Description : Release resource. + * The resource includes IR function lists and execution engine. + */ + void releaseResource(); + + /* + * @Description : Get the pointer to the current module. + * @return : Current module in use. + */ + llvm::Module* getCurrentModule() + { + return m_currentModule; + } + + /* reset m_machineCodeJitCompiled */ + void resetMCJittedFunc() + { + m_machineCodeJitCompiled = NIL; + } + +public: + /* The module in use during this query process */ + llvm::Module* m_currentModule; + +private: + /* Initializes the jitter and execution engine. */ + bool init(); + + /* + * Optimize the module, this includes pruning the module of any unused + * functions. + */ + void optimizeModule(llvm::Module* module); + + /* Flag used to optimize the module or not */ + bool m_optimizations_enabled; + + /* Flag used to mask if we have loaded the ir file or not */ + bool m_llvmIRLoaded; + + /* + * If true, the module is corrupt and we cannot codegen this query. + * we could consider just removing the offending function and attempting to + * codegen the rest of the query. This requires more testing though to make sure + * that the error is recoverable. + */ + bool m_isCorrupt; + + /* Flag used to mask if the GsCodeGen Obj has been initialized or not */ + bool m_initialized; + + llvm::LLVMContext* m_llvmContext; + + /* The map of function to MCJIT compiled object */ + List* m_machineCodeJitCompiled; + + /* Execution Engine in use during this query process */ + llvm::ExecutionEngine* m_currentEngine; + + /* + * If true, the module has been compiled. It is not valid to add additional + * functions after this point. + */ + bool m_moduleCompiled; + + MemoryContext m_codeGenContext; + + /* Records the c-function calls in codegen IR fucntion of expression tree */ + List* m_cfunction_calls; +}; + +/* + * Macros used to define the variables + * + * By following all these regulars, we could easily define + * consts + */ +#define DEFINE_CGVAR_INT1(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(BITOID, val) +#define DEFINE_CGVAR_INT8(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(CHAROID, val) +#define DEFINE_CGVAR_INT16(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT2OID, val) +#define DEFINE_CGVAR_INT32(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT4OID, val) +#define DEFINE_CGVAR_INT64(name, val) llvm::Value* name = llvmCodeGen->getIntConstant(INT8OID, val) + +/* + * Macros used to define the data types + */ +#define DEFINE_CG_VOIDTYPE(name) llvm::Type* name = llvmCodeGen->getVoidType() +#define DEFINE_CG_TYPE(name, typoid) llvm::Type* name = llvmCodeGen->getType(typoid) +#define DEFINE_CG_PTRTYPE(name, typoid) llvm::Type* name = llvmCodeGen->getPtrType(typoid) +#define DEFINE_CG_NINTTYP(name, nbit) llvm::Type* name = llvm::IntegerType::getIntNTy(context, nbit) +#define DEFINE_CG_ARRTYPE(name, typoid, num) llvm::Type* name = llvm::ArrayType::get(typoid, num) + +/* + * Define some operation + */ +#define DEFINE_BLOCK(name, insertbfpointer) \ + llvm::BasicBlock* name = llvm::BasicBlock::Create(context, #name, insertbfpointer); + +/* + * Define macros which help to catch and print the exception + * use SEGSEGVhandler to catch internal coredump occurred in LLVM. + */ +#define LLVM_TRY() \ + bool llvm_oper_success = true; \ + try + +#define LLVM_CATCH(msg) \ + catch (...) \ + { \ + llvm_oper_success = false; \ + } \ + if (!llvm_oper_success) { \ + ereport(ERROR, (errcode(ERRCODE_CODEGEN_ERROR), errmodule(MOD_LLVM), errmsg(msg))); \ + } + +} // namespace dorado + +/* + * Series of llvm::crc32 function. + * + * Contains llvm_crc32_32_8, llvm_crc32_32_16, llvm_crc32_32_32, llvm_crc32_32_64. + * + * All functions have three input parameters. The first parameter is the result value, + * and the next two parameters are input values. + * Each funtion's parameters are indicated through the function name. + * + * For example, llvm_crc32_32_8 indicates the result value is 32bits, + * the first input parameter is 32bits, and the second input is 8bits. + */ + +#ifdef __aarch64__ /* on ARM platform */ + +/* its function proto is: i32 @llvm.aarch64.crc32cb(i32 %cur, i32 %bits) */ +#define llvm_crc32_32_8(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cb); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cb function!\n"))); \ + } \ + llvm::Value* next_ext = builder.CreateZExt(next, int32Type); \ + res = builder.CreateCall(fn_crc, {current, next_ext}, "crc32_8"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32ch(i32 %cur, i32 %bits) */ +#define llvm_crc32_32_16(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32ch); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32ch function!\n"))); \ + } \ + llvm::Value* next_ext = builder.CreateZExt(next, int32Type); \ + res = builder.CreateCall(fn_crc, {current, next_ext}, "crc32_16"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32cw(i32 %cur, i32 %next) */ +#define llvm_crc32_32_32(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cw); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cw function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_32"); \ + } while (0) + +/* its function proto is: i32 @llvm.aarch64.crc32cx(i32 %cur, i64 %next) */ +#define llvm_crc32_32_64(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::aarch64_crc32cx); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::aarch64_crc32cx function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_64"); \ + } while (0) + +#else /* on X86 platform */ + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.8(i32 %a, i8 %b) */ +#define llvm_crc32_32_8(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_8); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_8 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_8"); \ + } while (0) + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.16(i32 %a, i16 %b) */ +#define llvm_crc32_32_16(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_16); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_16 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_16"); \ + } while (0) + +/* its function proto is: i32 @llvm.x86.sse42.crc32.32.32(i32 %a, i32 %b) */ +#define llvm_crc32_32_32(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_32_32); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_32_32 function!\n"))); \ + } \ + res = builder.CreateCall(fn_crc, {current, next}, "crc32_32"); \ + } while (0) + +/* + * its function proto is: i64 @llvm.x86.sse42.crc32.64.64(i64 %a0, i64 %a1). + * x86_sse42_crc32_64_64 gets two 64bit inputs, and returns 64bits. + * So we have to convert its first input param and the result. + */ +#define llvm_crc32_32_64(res, current, next) \ + do { \ + llvm::Function* fn_crc = llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::x86_sse42_crc32_64_64); \ + if (fn_crc == NULL) { \ + ereport(ERROR, \ + (errcode(ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED), \ + errmodule(MOD_LLVM), \ + errmsg("Failed to get function Intrinsic::x86_sse42_crc32_64_64 function!\n"))); \ + } \ + llvm::Value* current_ext = builder.CreateZExt(current, int64Type); \ + res = builder.CreateCall(fn_crc, {current_ext, next}, "crc32_64"); \ + res = builder.CreateTrunc(res, int32Type); \ + } while (0) + +#endif /* end of definition of series of llvm::crc32 function */ + +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/timestampcodegen.h postgresql-hll-2.14/include/include/codegen/timestampcodegen.h --- postgresql-hll-2.14_old/include/include/codegen/timestampcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/timestampcodegen.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * timestampcodegen.h + * Definitions of code generation for timestamp operation + * + * + * IDENTIFICATION + * src/include/codegen/timestampcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_TIMESTAMP_H +#define LLVM_TIMESTAMP_H +#include "codegen/gscodegen.h" + +namespace dorado { +llvm::Function* timestamp_eq_codegen(); +llvm::Function* timestamp_ne_codegen(); +llvm::Function* timestamp_lt_codegen(); +llvm::Function* timestamp_le_codegen(); +llvm::Function* timestamp_gt_codegen(); +llvm::Function* timestamp_ge_codegen(); +} // namespace dorado +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/codegen/vecexprcodegen.h postgresql-hll-2.14/include/include/codegen/vecexprcodegen.h --- postgresql-hll-2.14_old/include/include/codegen/vecexprcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/vecexprcodegen.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,468 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexprcodegen.h + * Declarations of code generation for vecexpression funtions. + * + * For each expression, first decide if this expression can be LLVM optimized + * or not according to the detail information. The expression functions + * accomplished here have the same functionality as the ones defined in + * vecexpression.h, though more constraints are used. + * + * IDENTIFICATION + * src/include/codegen/vecexprcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECEXPRESSION_H +#define LLVM_VECEXPRESSION_H +#include "optimizer/clauses.h" +#include "nodes/execnodes.h" +#include "codegen/gscodegen.h" + +namespace dorado { +/* + * @Description : Arguments used for Vectorized Expression CodeGen Engine. + */ +typedef struct { + ExprState* exprstate; /* Expression information used to + generate IR function */ + PlanState* parent; /* The parent planstate information */ + GsCodeGen::LlvmBuilder* builder; /* LLVM builder in upper level */ + llvm::Value** llvm_args; /* LLVM parameters*/ +} ExprCodeGenArgs; + +/* + * @Description : Parameters needed to pass to the original c-function. + */ +typedef struct { + int nargs; /* number of args */ + llvm::Value** args; /* values of parameters with length nargs */ + llvm::Value** argnulls; /* flags of parameters with length nargs */ +} LLVMFuncCallInfo; + +typedef llvm::Value* (*VectorExprCodeGen)(ExprCodeGenArgs* args); + +/* + * LlvmExecQual class implements specific optimization by using LLVM. + */ +class VecExprCodeGen : public BaseObject { +public: + /* + * @Brief : Check whether state could be legal or not. + * @Description : Check is the current state->expr could be codegened + * or not. + * @in state : exprstate, the node to be checked. + * @return : return true is state could be codegened. + */ + static bool ExprJittable(ExprState* state); + + /* + * The following functions are codegen functions and their guardian function: + * Since each expression has its own restricts, we should consider them + * independently. For each expression, we have one guardian function and + * one codegen function. + */ + + /* + * @Brief : Check if the whole qual list can be codegened or not. + * @Description : Check if the qual list can be codegened or not. The qual + * list can be joinqual, hashjoin_clauses and so on. + * @in qual : the expr node list need to be checked. + * @return : return true if the whole qual can be codegened. + */ + static bool QualJittable(List* qual); + + /* + * @Brief : Code generation for ExecEvalQual. + * @Description : Since ExprState stored the plan-tree information, ExprContext + * stored the actual data information during execution. We need + * to separate these two parameters in 'InitNode' and 'ExecNode' + * status. So during expression processes, we should pass through + * 'Expr' as parameter in 'InitNode' and pass through 'econtext' + * as LLVM parameter in 'ExecNode'. + * @in qual : the expr node list need to be codegened. + * @in parent : the whole planstate of the expr node. + * @return : ScalarVector result of the qual list in LLVM assemble. + * @notes : firstly, econtext is passed when qual is needed; secondly, for + * each LLVM function in ExecVecQual, the interface is + * LLVM_Expr_Func(ExprCodeGenArgs); + */ + static llvm::Function* QualCodeGen(List* qual, PlanState* parent, bool isReset = true); + + /* + * @Description : Check if the scalararrayop expr can be codegened or not. + * @in state : ExprState of ScalarArrayOpExpr. + * @return : return true if scalararrayop expr can be codegened. + */ + static bool ScalarArrayJittable(ExprState* state); + + /* + * @Brief : Codegen for scalararrayop expression. + * @Description : Codegeneration of the ExecEvalVecScalarArrayOp: + * For integer/float/date/timestamp, we use switch + * structure in LLVM, for bpchar/varchar/text, we use + * codegen function. + * @in args : arguments of vector expr codegen engine. + * @return : return true when tuple satisfies the condition + * @Notes : Support ...in (...) and any(array[....]) only. + */ + static llvm::Value* ScalarArrayCodeGen(ExprCodeGenArgs* args); + + /* + * @Description : Check if the boolean test expr can be codegened or not. + * @in state : ExprState of BooleanTest Expr. + * @Output : return true if boolean test expr can be codegened. + */ + static bool BooleanTestJittable(ExprState* state); + + /* + * @Brief : Codegen for boolean test expression. + * @Description : Codegeneration of the ExecEvalBooleanTest. + * @in args : arguments of vector expr codegen engine. + * @return : return the result of Boolean Test Expr. + */ + static llvm::Value* BooleanTestCodeGen(ExprCodeGenArgs* args); + + /* + * @Description : Check if the null test expr can be codegened or not. + * + * @in state : NullTest ExprState. + * @return : return true if nulltest expr can be codegened. + */ + static bool NullTestJittable(ExprState* state); + + /* + * @Brief : Codegen for NullTest expression. + * @Description : Codegeneration of the ExecEvalNullTest: contains + * IS_NULL, IS_NOT_NULL. + * @in args : arguments of vector expr codegen engine. + * @return : return true only if argument is nulll, else return false. + */ + static llvm::Value* NullTestCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the oper func can be codegened or not. + * @Description : Check if the FuncExprState can be codegened or not : + * right now most of the oper expr can be codegened, but + * some of them still have some constraints. + * @in state : ExprState representation of FuncExprSate. + * @return : return true if the operation function can be codegened. + */ + static bool OpJittable(ExprState* state); + + /* + * @Brief : Check if the oper func with numeric data can be codegened in special path. + * @Description : Check if the Numeric OperExpr can be codegened in a special way: + * the data we considered here are all can be represented in BI64. + * @in state : ExprState representation of OperExprSate. + * @return : return true if the operation function can be codegened in fast path. + */ + static bool NumericOpFastJittable(ExprState* state); + + /* + * @Brief : Codegen for vecoper expression. + * @Description : Codegeneration of the ExecEvalVecOp: Right row + * we only support several cases with data type + * int/float/date/timestamp and text(eq,gt)/bpchar(eq) + * @in args : arguments of vector expr codegen engine. + * @return : return the result of oper expr in LLVM assemble. + * @Notes : Since we have not codegen ExecMakeVecFunctionResult + * as we do in vecexpression.cpp, only seveal cases + * are supported. + */ + static llvm::Value* OpCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for numeric type operation expression. + * @Description : Codegeneration for numeric operation expression: we make a special + * path for data that can be transformed to BI64. While for other cases, + * we use normal codegen path(NormalNumericOpCodeGen). + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in estate : opexprstate associated with current operation. + * @in funcoid : function oid of current numeric operation. + * @in larg : left argument passed to llvm. + * @in rarg : right argument passed to llvm. + */ + static llvm::Value* FastNumericOpCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, ExprState* estate, llvm::Value* larg, llvm::Value* rarg); + static llvm::Value* NormalNumericOpCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, Oid funcoid, llvm::Value* larg, llvm::Value* rarg); + + /* + * @Brief : Check if the FuncExpr can be codegened or not. + * @Description : Check if the FuncExprState can be codegened or not : + * right now most of the func expr can be codegened, but + * some of them still have some constraints. + * @in state : ExprState representation of FuncExprSate. + * @return : return true if the func can be codegen. + * @Notes : We only support C / UTF-8 encoding. + */ + static bool FuncJittable(ExprState* state); + + /* + * @Brief : Codegen for vecfunc expression. + * @Description : Codegeneration of the ExecEvalVecFunc: Only part of them + * have been codegened, the rest would be used by + * call original C-Function. + * @in args : arguments of vector expr codegen engine. + * @return : result of ExecEvalFunc in LLVM assemble. + * @Notes : We only support C / UTF-8 encoding. + */ + static llvm::Value* FuncCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if veccase expression can be codegened or not. + * @Description : Codegeneration of the ExecEvalVecCase: The logic here + * is the same as ExecEvalVecCase. Since operation is only + * partly supported, the exprs in case arg/when expr/default + * expr are the ones supported by OpCodeGen. + * @in state : context of CaseExprState + * @return : return true if veccase expr can be codegened. + */ + static bool CaseJittable(ExprState* state); + + /* + * @Brief : Codegen for veccase expression. + * @Description : Codegeneration of the ExecEvalVecCase: The logic here + * is the same as ExecEvalVecCase. Since operation is only + * partly supported, the exprs in case arg/when expr/default + * expr are the ones supported by OpCodeGen. + * @in args : arguments of vector expr codegen engine. + * @return : wclause->result or default->result in LLVM assemble. + */ + static llvm::Value* CaseCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if nullif expression can be codegened or not. + * @Description : Codegeneration of the ExecEvalVecNullif checking. + * @in state : ExprState + * @return : return true if nullif expr can be codegened. + */ + static bool NullIfJittable(ExprState* state); + + /* + * Brief : Codegen for nullif expression. + * Description : NullIfCodeGen is the codegeneration of the ExecEvalVecNullIf. + * Input : ExprCodeGenArgs + * Output : when expr1=expr2 return null, else return expr1. + * Notes : None. + */ + static llvm::Value* NullIfCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if and/or/not expr can be codegened or not. + * @Description : Check if the bool expr can be codegened or not. The + * expr type contatins and, or and not expr. While + * and/or expression and not expression should be + * considered independently. + * @in state : the context of bool expr state + * @return : return true the expr in state can be codegened. + */ + static bool BoolJittable(ExprState* state); + + /* + * @Brief : Codegen for vector and/or expression. + * @Description : Codegeneration of the ExecEvalProcessAndOrLogic: The + * logic here is the same as ExecEvalProcessAndOrLogic. + * BoolJittable would check and/or/not expression argument, + * but and/or expression and not expression would be + * considered independently. + * @in args : arguments of vector expr codegen engine. + * @return : the and/or expr's result in LLVM assemble. + */ + static llvm::Value* AndOrLogicCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for vector not expression. + * @Description : Codegeneration of the ExecEvalVecNot. + * @in args : arguments of vector expr codegen engine. + * @return : the not expr's result in LLVM assemble. + */ + static llvm::Value* NotCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if vecrelabel expr can be codegened or not. + * @Description : Check if the relabel expr in genericexprstate can be + * : codegened or not. Only support the case when arg + * : is a var or casetestexpr. + * @in state : context of relabel expr. + * @return : return true if relabel expr can be codegened. + */ + static bool RelabelJittable(ExprState* state); + + /* + * @Brief : Codegen for vecrelabel expression. + * @Description : Codegeneration of the ExecEvalVecRelabelType: + * Support the case when arg is a var or casetestexpr. + * @in args : arguments of vector expr codegen engine. + * @return : result of relabel expr in LLVM assemble + */ + static llvm::Value* RelabelCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the var expr can be codegened or not. + * @Description : Check if the Var in state can be codegened or not, + * : only need to consider the var type. + * @in state : context of Var Expr State + * @return : return true if const expr can be codegened. + */ + static bool VarJittable(ExprState* state); + + /* + * @Brief : Codegen for evalvar expr. + * @Description : Codegeneration of the ExecEvalVecVar : Get the + * values from econtext->vectorbatch with fixed + * column index and row index(loop_index). Also we + * should restore the null flag. + * @in args : arguments of vector expr codegen engine. + * @out isNull : null flag of batch->m_arr[varattno-1] + * @return : return true if const expr can be codegened. + */ + static llvm::Value* VarCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Codegen for vecconst expression. + * @Description : Check is const expr could be codegened or not. + * @in state : const expr state. + * @return : return true if const expr can be codegened. + */ + static bool ConstJittable(ExprState* state); + + /* + * @Brief : Codegen for vecconst expression. + * @Description : Codegeneration of the ExecEvalVecConst + * @in args : arguments of vector expr codegen engine. + * @return : the value in const expr. + */ + static llvm::Value* ConstCodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : Check if the targetlist could be codegened or not. + * @Description : Check the jittable of the ExecVecTargetList, which + * : evaluates a targetlist with respect to the given + * : expression context in LLVM assemble. + * @in targetlist : the expr node list need to be checked. + * @return : return true if we were able to codegen the list. + */ + static bool TargetListJittable(List* targetlist); + + /* + * @Brief : Codegen for TargetList expression. + * @Description : Codegeneration of the ExecVecTargetList, which + * : evaluates a targetlist with respect to the given + * : expression context in LLVM assemble. + * @in targetlist : the expr node list need to be codegened. + * @in parent : PlanState of the whole targetlist. + * @return : LLVM function of targetlist expr. + */ + static llvm::Function* TargetListCodeGen(List* targetlist, PlanState* parent); + + /* + * @Description : CodeGen routine for Expression. + * @in args : arguments of vector expr codegen engine. + * @return : the result of current args->exprstate. + */ + static llvm::Value* CodeGen(ExprCodeGenArgs* args); + + /* + * @Brief : CodeGen for general function call. + * @Description : For functions we do not codegened, invoke these + * function in LLVM assemble, and reduce the logical + * branches in dealing with arguments and return vals + * by using LLVM optimization. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcache : The function expr dealed with. + * @in isNull : used to record the null flag of the return value. + * @in lfcinfo : arguments about fcache. + * + */ + static llvm::Value* EvalFuncResultCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, FuncExprState* fcache, llvm::Value* isNull, LLVMFuncCallInfo* lfcinfo); + + /* + * @Brief : Make sure the ExtractFunc according the datum type. + * @Description : Wrap all the Extract Func in LLVM assemble, which could + * : easily deal with input argument according the different + * : datum type. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in argtyp : input argument datum type.type + * @in data : input data + * @return : the result after extraction. + */ + static llvm::Value* WrapChooExtFunCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, Oid argtyp, llvm::Value* argval); + static llvm::Value* WrapExtFixedTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtAddrTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtCStrTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + static llvm::Value* WrapExtVarTypeCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* data); + + /* + * @Brief : Wrap Datum to Scalar Func according the datum type. + * @Description : Wrap all the Convert Func in LLVM assemble. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in val : input data argument. + * @in len : the argument data len with respect to datum type. + * @return : the result after conversation. + */ + static llvm::Value* WrapDFixLToScalCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* val, llvm::Value* len); + static llvm::Value* WrapDCStrToScalCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* val); + + /* + * @Description : Wrap the c-function : GetVectorBatch, which is used to + * get the vectorbatch during vectargetlist-codegeneration. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in econtext : exprcontext in LLVM assemble. + */ + static llvm::Value* WrapGetVectorBatchCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - FunctionCallInvoke, only consider strict + * : function, where we do not consider the flag of args. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcinfo : data with FunctionCallInfo type in LLVM assemble. + * @in arg : array of arguments, contain the arguments of fcinfo + * : and the flag of the result. + */ + static llvm::Value* WrapStrictOpFuncCodeGen( + GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* fcinfo, llvm::Value* arg, llvm::Value* isNull); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - FunctionCallInvoke, only consider non-strict + * : function. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in fcinfo : data with FunctionCallInfo type in LLVM assemble. + * @in arg : array of arguments, contain the arguments of fcinfo + * : and the flag of the result. + * @in argnull : the flag of the input args. + * @in isNull : the flag of the result. + */ + static llvm::Value* WrapNonStrictOpFuncCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* fcinfo, + llvm::Value* arg, llvm::Value* argnull, llvm::Value* isNull); + + /* + * @Brief : Wrap the Invoke function. + * @Description : Codegen the interface, used to call the original + * : C-Function - MemoryContextSwitchTo. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in context : MemoryContext that we want to access. + */ + static llvm::Value* MemCxtSwitToCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* context); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/vechashaggcodegen.h postgresql-hll-2.14/include/include/codegen/vechashaggcodegen.h --- postgresql-hll-2.14_old/include/include/codegen/vechashaggcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/vechashaggcodegen.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,230 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashaggcodegen.h + * Declarations of code generation for vechashagg funtions. + * + * For each vechashagg function, they have the same functionality as the ones + * defined in vechashagg.h. Code generation will not change the logical of the + * the whole function. + * + * IDENTIFICATION + * src/include/codegen/vechashaggcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECHASHAGG_H +#define LLVM_VECHASHAGG_H +#include "codegen/gscodegen.h" +#include "executor/nodeAgg.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +namespace dorado { +/* + * VecHashAggCodeGen class implements specific optimization by using LLVM + */ +class VecHashAggCodeGen : public BaseObject { +public: + /* + * @Brief : Calculate scale of expression. + * @Description : Give expression node, calculate the scale of current, + * this function only be used when we can use fast codegen. + * @in node : The expression that we need to evaluate scale. + * @return : return the scale of current node expr. + */ + static int GetAlignedScale(Expr* node); + + /* + * @Brief : Check the expressions we supported + * @Description : Since we only support simple expression in agg + * operator, we should restrict the ones we support. + * @in state : Input expression state node. + * @return : If the current node is allowed to do codegen or not. + */ + static bool AggRefJittable(ExprState* state); + + /* + * @Brief : Check if current expression can use special codegen path. + * @Description : For simple var expression and simple algorithm expression + * with numeric data type, if we could represent it by + * big integer, use fast path at the beginning. + * @in state : Input expression state node. + * @return : Return true if the expression can use fast codegen path. + */ + static bool AggRefFastJittable(ExprState* state); + + /* + * @Brief : Check the validation of VecAggState for agghashing. + * @Description : Check if the current agg node could be codegened + * or not. We only support sum and avg operation. The + * data type could only be int8 and numeric with + * precision less than or equal to 18. + * @in node : vecaggstate, the node to be checked. + * @return : Return true if current agg node could be codegened. + */ + static bool AgghashingJittable(VecAggState* node); + + /* + * @Brief : Main function process to build LLVM ir function used to generate + * : machine code. + * @Description : Build LLVM ir function with respect to special query according to + * : current agg state, including build function and agg function. + * @in node : vector aggregate state information. + */ + static void HashAggCodeGen(VecAggState* node); + + /* + * @Brief : Main function process to build LLVM IR function used to generate + * : machine code. + * @Description : Build LLVM ir function with respect to special query according to + * : current sonic agg state, including agg function. + * @in node : vector aggregate state information, special for sonic case. + */ + static void SonicHashAggCodeGen(VecAggState* node); + + /* + * @Brief : Code generation for Hashing process + * @Description : The whole HashAggRunner::BuildAggTbl functions + * can be divieded into three part. AgghashingCodeGen + * contains (a)computing hash value & compare hash value + * & match key and (b)allocate new hash cell. + * @in node : vecaggstate, the node to be codegened + * @return : The codegeneration of part of HashAggRunner::BuildAggTbl + * function. + */ + template + static llvm::Function* AgghashingCodeGenorSglTbl(VecAggState* node); + + /* + * @Description : Same as above function except the prefetching hashCell. + */ + template + static llvm::Function* AgghashingWithPrefetchCodeGenorSglTbl(VecAggState* node); + /* + * @Brief : Code generation for vechashtable::hashBatch function. + * @Description : Code generation for hashBatch function with the fixed + * row number 'idx'. The original function calculate the + * whole hash values of that batch with respect to the + * group by clauses. hashBatchCodeGen only calculate the + * hash value of one row. + * @in node : node which contains aggstate information. + * @in idx : the row number of the batch. + * @in rehash : check if we need to rehash the row. + * @return : LLVM function pointer. + * + */ + static llvm::Function* HashBatchCodeGen(VecAggState* node, int idx, bool rehash); + + /* + * @Brief : Code generation for match_key function with respect to + * one key. + * @Description : Code generation for match_key function with the fixed + * row number 'idx' and fixed key. We only consider the + * idx-th cell and the idx-th tuple in batch. + * @in node : Node which contains aggstate information. + * @in idx : The row number of the batch. + * @return : LLVM function pointer. + */ + static llvm::Function* MatchOneKeyCodeGen(VecAggState* node, int idx); + + /* + * @Brief : Check the validation of VecAggState for batch aggregation. + * @Description : Check if the current node can be codegened for aggregation + * or not. Since we only support sum and avg operation with + * data type int8 and numeric with allowed precision(<=18). + * @in node : vecaggstate, the node to be codegened + * @return : return true if current node is allowed to do codegen of + * batch aggregation. + */ + static bool BatchAggJittable(VecAggState* node, bool isSonic); + + /* + * @Brief : Code generation for BatchAggregation. + * @Description : Do codegen for function BaseAggRunner::BatchAggregation. + * The main process contains projection of expressions and + * aggregation of the agg operator. + * @in node : vecaggstate, the node to be codegened + * @in use_prefetch : Flag used to decide if we need to prefetch data. + * @return : LLVM function pointer that point to the codegeneration of + * BatchAggregation. + */ + static llvm::Function* BatchAggregationCodeGen(VecAggState* node, bool use_prefetch); + + /* + * @Brief : LLVM function used to evaluation numeric expression in + * fast path. + * @Description : Evaluate numeric expression in fast path if the mid-result + * can be represented in BI64 by avoiding make numeric + * result all the time. + * @in state : ExprState node + * @in builder : LLVM Builder associated with the current module. + * @in jitted_func : the current llvm function that we need to generate. + * @in bb_null : null basicblock used for deal with null value. + * @in bb_last : maks parent basic block dynamically to get value from + * last basicblock. + * @bb_outofbound : basicblock used to deal with the case where the result + * can not be represented in BI64. + * @econtext : ExprContext of the current operator. + * @argVector : the input scalevector. + * @phi_idx : the idxth row that we need to evaluation. + * @return : the result of this value if no outofbound or null is meet. + */ + static llvm::Value* EvalFastExprInBatchAgg(ExprState* state, GsCodeGen::LlvmBuilder builder, + llvm::Function* jitted_func, llvm::BasicBlock** bb_null, llvm::BasicBlock** bb_last, + llvm::BasicBlock** bb_outofbound, llvm::Value* econtext, llvm::Value* argVector, llvm::Value* phi_idx); + + /* + * @Brief : Code generation for expressions in agg function. + * @Description : Do codegen for ExecVecProject function in BatchAggregation. + * Since we only deal with simple expressions, we could list + * these simple cases one by one. + * @in node : ExprState node. + * @in builder : LLVM Builder associated with the current module. + * @in econtext : Expr Context with respect to current aggref Expr. + * @in phi_idx : the index of the current tuple. + * @in isNull : flag used to mask the return value is null or not. + * @return : return the result of this expression. + */ + static llvm::Value* EvalSimpleExprInBatchAgg(ExprState* node, GsCodeGen::LlvmBuilder builder, llvm::Value* econtext, + llvm::Value* phi_idx, llvm::Value* isNull); + + static llvm::Function* SonicBatchAggregationCodeGen(VecAggState* node, bool use_prefetch); + + /* + * @Brief : Code generation for allocating a new hash cell and initialization. + * @Description : Code generation for allocating hash cell and initilize the + * hash cell. It has the same functionality as the orginal one. + * @in ptrbuilder : LLVM Builder associated with the current module. + * @in hAggRunner : HashAggRunner information. + * @in batch : vectorbatch which needed to creat hash cell. + * @in idx : the index of the current tuple. + * @in keysimple : mark whether the key is simple or not. + */ + static void WarpAllocHashSlotCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* hAggRunner, + llvm::Value* batch, llvm::Value* idx, llvm::Value* keysimple); + static void WarpSglTblAllocHashSlotCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* hAggRunner, + llvm::Value* batch, llvm::Value* idx, llvm::Value* keysimple); + + /* + * @Brief : Reset current expr context. + * @Description : Codeg generation for reset expr context in LLVM assemble. + * @in econtext : Current expr context. + */ + static void WrapResetEContextCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext); +}; + +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/vechashjoincodegen.h postgresql-hll-2.14/include/include/codegen/vechashjoincodegen.h --- postgresql-hll-2.14_old/include/include/codegen/vechashjoincodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/vechashjoincodegen.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,172 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashjoincodegen.h + * Declarations of code generation for vechashjoin funtions. + * + * Since the most cpu intensive part of hashjoin function locates + * at build hash table part and join part, we mainly do codegeneration + * for buildHashTable, innerJoin and so on. + * + * IDENTIFICATION + * src/include/codegen/vechashjoincodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECHASHJOIN_H +#define LLVM_VECHASHJOIN_H +#include "codegen/gscodegen.h" +#include "codegen/vecexprcodegen.h" +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +namespace dorado { +/* + * VecHashJoinCodeGen class implements specific optimization by using LLVM + */ +class VecHashJoinCodeGen : public BaseObject { +public: + /* + * @Brief : Check if the hash key is simple var or not. + * @Description : Since we only support simple hash condition now, + * the hash key expr should be simple var. If this + * var is marked as not_null, we could use fast + * key match path. + * @in node : VecHashJoinState, the node to be checked. + * @in estate : The expr of hashkey. + * @in is_simple_var : Flag used to mark if hash cond expr is simple var + * or not. + * @in enable_fast_keymatch : Flag used to mark fast codegen path. + * @return : Return simple var expression. + */ + static Var* GetSimpHashCondExpr( + VecHashJoinState* node, ExprState* estate, bool* is_simple_var, int* enable_fast_keyMatch); + + /* + * @Brief : Check the validation of VecHashJoinState. + * @Description : Check if the current hash join node could be codegened + * or not. We only support hash inner join. The + * data type of hash keys could only be int4, int8 or bpchar. + * @in node : VecHashJoinState, the node to be checked. + * @return : Return true if current hash join node could be codegened. + * set VecHashJoinState->enable_fast_keyMatch = 2 if + * (1) all hash keys are NOT NULL columns from base tables + * (2) all hash key data types are int4 or int8 + * else set VecHashJoinState->enable_fast_keyMatch = 1 if + * (1) there is only one hash clause + * else set VecHashJoinState->enable_fast_keyMatch = 0 + */ + static bool JittableHashJoin(VecHashJoinState* node); + + /* @Brief : Check if we can do codegen on buildHashTable and probeHashTable + * @Description : We separate this check from the JittableHashJoin for + * innerJoinT/matchKey since the build/probe function can + * be used for all joins (inner, semi, anti, ...). + * @in : VecHashJoinState, the node to be checked. + * @return : true if we can do codegen on buildHashTable/probeHashTable + * (1) No any complicate hash clauses + * (2) only support hash keys with int4,int8,bpchar type. + */ + static bool JittableHashJoin_buildandprobe(VecHashJoinState* node); + + /* + * @Brief : Check if we can do codegen on bloom filter function. + * @Description : During initialization, we initilized the runtime bloomfilter. + * If the var type is int2, int4 or int8, we chould use + * codegen optimization for bloom filter function. + * @in : VecHashJoinState, the node to be checked. + * @return : return true if we can do codegen on addLong and includeLong + * function in bloom filter. + */ + static bool JittableHashJoin_bloomfilter(VecHashJoinState* node); + + /* + * @Brief : Code generation for hash join + * @Description : Codegen for the hot path in innerJoinT + * match_key, buildHashTable, probeHashTable + * @in node : VecHashJoinState, the node to be codegened + * @return : true if innerJoinT is generated; otherwise, false. + */ + static void HashJoinCodeGen(VecHashJoinState* node); + static llvm::Function* HashJoinCodeGen_normal(VecHashJoinState* node); + + /* + * @Description : Generate more efficient code with less memory access + * and less branches. + * @in node : Hash join state node. + * @return : LLVM function about specialized hash inner join. + * @Note : The condition is one hash clause, hash keys are NOT NULL, + * and hash keys are integer type. + */ + static llvm::Function* HashJoinCodeGen_fastpath(VecHashJoinState* node); + + /* + * @Brief : Code generation for keyMatch function in hash join + * @Description : Codegen for the whole function keyMatch for hash join + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of keyMatch for hash join + */ + static llvm::Function* KeyMatchCodeGen(VecHashJoinState* node, Var* variable); + + /* + * @Brief : Code generation for buildHashTable function in hash join + * @Description : The hash function (hashint4 + hash_uint32) is replaced by + * CRC32 hardware instruction. Need to make sure the + * probeHashTable use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of buildHashTable for hash join + */ + static llvm::Function* HashJoinCodeGen_buildHashTable(VecHashJoinState* node); + + /* + * @Description : Similiar as above function except NeedCopy is true. + * @Note : NeedCopy is true when we have partition table. + */ + static llvm::Function* HashJoinCodeGen_buildHashTable_NeedCopy(VecHashJoinState* node); + + /* + * @Brief : Code generation for probeHashTable function in hash join + * @Description : The hash function (hashint4 + hash_uint32) is replaced by + * CRC32 hardware instruction. Need to make sure the + * buildHashTable use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of probeHashTable for hash join + */ + static llvm::Function* HashJoinCodeGen_probeHashTable(VecHashJoinState* node); + + /* + * @Brief : Code generation for addLongInternal in bloom filter + * @Description : We use CRC32 hash function to replace the original Thomas + * Wang's hash function. When addLongInternal function is + * codegened, includeLong must use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of addLongInternal for hash bloom filter. + */ + static llvm::Function* HashJoinCodeGen_bf_addLong(VecHashJoinState* node); + + /* + * @Brief : Code generation for includeLong in bloom filter + * @Description : We use CRC32 hash function to replace the original Thomas + * Wang's hash function. When includeLong function is + * codegened, addLong must use the same hash function. + * @in node : VecHashJoinState, the node to be codegened + * @return : The LLVM IR function of includeLong for hash bloom filter. + */ + static llvm::Function* HashJoinCodeGen_bf_includeLong(VecHashJoinState* node); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/include/codegen/vecsortcodegen.h postgresql-hll-2.14/include/include/codegen/vecsortcodegen.h --- postgresql-hll-2.14_old/include/include/codegen/vecsortcodegen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/codegen/vecsortcodegen.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,155 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsortcodegen.h + * Declarations of code generation for vecsort funtions. + * + * Since the most cpu intensive part of sort function locates + * at CompareMultiColumn, we mainly do code generation for CompareMultiColumn + * and the functions it calls. + * + * + * IDENTIFICATION + * src/include/codegen/vecsortcodegen.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LLVM_VECSORT_H +#define LLVM_VECSORT_H +#include "codegen/gscodegen.h" +#include "vecexecutor/vecnodesort.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "utils/batchsort.h" +#include "access/tuptoaster.h" + +namespace dorado { +/* + * VecSortCodeGen class implements specific optimization by using LLVM + */ +class VecSortCodeGen : public BaseObject { +public: + /* + * @Brief : Check the validation of VecSortState. + * @Description : Check if the current sort node could be codegened + * or not. We only support the codegen on CompareMultiColumn + * and functions it calls. The data type of sort keys + * could only be int4, int8, char, text, varchar or numeric. + * @in node : VecSortState, the node to be checked. + * @return : return true if current sort node could be codegened. + */ + static bool JittableCompareMultiColumn(VecSortState* node); + + /* + * @Brief : Code generation for CompareMultiColumn + * @Description : Codegen for the hot path in sort + * @in node : VecSortState, the node to be codegened + * @return : The codegeneration of part of CompareMultiColumn + * function. + */ + static llvm::Function* CompareMultiColumnCodeGen(VecSortState* node, bool use_prefetch); + + /* + * @Brief : Code generation for CompareMultiColumn under Top N sort + * @Description : Codegen for the hot path in sort for Top N + * @in node : VecSortState, the node to be codegened + * @return : The codegeneration of part of CompareMultiColumn + * function. + */ + static llvm::Function* CompareMultiColumnCodeGen_TOPN(VecSortState* node, bool use_prefetch); + + /* + * @Brief : Code generation for bpcharcmp function + * @Description : Codegen for bpcharcmp and all functions it calls. + * If bpchar length is greater than 16 bytes, use bpcharcmpCodeGen_long() + * Otherwise, use bpcharcmpCodeGen_short() + * the generated function will be called by CompareMultiColumn + * @return : The codegeneration of bpcharcmp + * function. + */ + static llvm::Function* bpcharcmpCodeGen_long(); + static llvm::Function* bpcharcmpCodeGen_short(); + + /* + * @Brief : Code generation for memcmp function. + * @Description : Codegen for memcmp and all functions it calls. In sort + * node this function is called by varstr_cmp inlined + * into bpcharcmp function. + * @return : The LLVM IR function generated for memcmp function + * called by varstr_cmp inlined into bpcharcmp. + */ + static llvm::Function* LLVMIRmemcmp_CMC_CodeGen(); + + /* + * @Brief : Code generation for text_cmp function + * @return : The LLVM IR function generated for text_cmp function + */ + static llvm::Function* textcmpCodeGen(); + + /* + * @Brief : Code generation for numeric_cmp function + * @return : The LLVM IR function generated for numeric compare. + */ + static llvm::Function* numericcmpCodeGen(); + static llvm::Function* numericcmpCodeGen_fastpath(); + + /* + * @Brief : Check the validation of VecAggState. + * @Description : Check if the match_key function in sort aggregation + * could be codegened or not. + * @in node : VecAggState, the node to be checked. + * @return : true if it's jittable, otherwise, false. + */ + static bool JittableSortAggMatchKey(VecAggState* node); + + /* + * @Brief : Codegeneration for match_key function in Sort Aggregation. + * @Description : Codegeneration for match_key function in sort aggregation, + * The data type of sort keys could only be int4, int8, + * char, text, varchar or numeric, and we only support the + * group by rollup case without considering multiple phases. + * @in node : VecAggState, the node to be codegened. + * @return : The LLVM IR function generated for match_key function. + */ + static llvm::Function* SortAggMatchKeyCodeGen(VecAggState* node); + + /* + * @Description : Code generation for bpchareq function called by + * match_key function in Sort Aggregation. + * @in length : The length of the bpchar definition. + * @return : The LLVM IR function generated for bpchareq function + * in match_key of sortagg. + */ + static llvm::Function* SortAggBpchareqCodeGen(int length); + + /* + * @Description : Code generation for memcmp function called by bpchareq + * in match_key function of Sort Aggregation. If the bpchar + * length is >= 16, call SortAggMemcmpCodeGen_long(), + * otherwise, call SortAggMemcmpCodeGen_short(). + * @return : The LLVM IR function generated for memcmp function + * called by bpchareq in match_key of sortagg. + */ + static llvm::Function* SortAggMemcmpCodeGen_long(); + static llvm::Function* SortAggMemcmpCodeGen_short(); + + /* + * @Description : Code generation for texteq function in match_key of sortagg. + * @return : The LLVM IR function generated for texteq function. + */ + static llvm::Function* SortAggTexteqCodeGen(); +}; +} // namespace dorado +#endif diff -uprN postgresql-hll-2.14_old/include/include/com_err.h postgresql-hll-2.14/include/include/com_err.h --- postgresql-hll-2.14_old/include/include/com_err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/com_err.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,80 @@ +/* + * Copyright 1988, Student Information Processing Board of the + * Massachusetts Institute of Technology. + * + * Copyright 1995 by Cygnus Support. + * + * For copyright and distribution info, see the documentation supplied + * with this package. + */ + +/* Header file for common error description library. */ + +#ifndef __COM_ERR_H + +#if defined(_WIN32) +#include +#endif + +#ifndef KRB5_CALLCONV +#define KRB5_CALLCONV +#define KRB5_CALLCONV_C +#endif + +#include + +typedef long errcode_t; +typedef void (*et_old_error_hook_func) (const char *, errcode_t, + const char *, va_list ap); + +struct error_table { + /*@shared@*/ char const * const * msgs; + long base; + unsigned int n_msgs; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/* Public interfaces */ +extern void KRB5_CALLCONV_C com_err + (const char *, errcode_t, const char *, ...) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 4))) +#endif + ; +extern void KRB5_CALLCONV com_err_va + (const char *whoami, errcode_t code, const char *fmt, + va_list ap) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 0))) +#endif + ; +extern /*@observer@*//*@dependent@*/ const char * KRB5_CALLCONV error_message + (errcode_t) + /*@modifies internalState@*/; +extern errcode_t KRB5_CALLCONV add_error_table + (/*@dependent@*/ const struct error_table *) + /*@modifies internalState@*/; +extern errcode_t KRB5_CALLCONV remove_error_table + (const struct error_table *) + /*@modifies internalState@*/; + +#if !defined(_WIN32) +/* + * The display routine should be application specific. A global hook, + * may cause inappropriate display procedures to be called between + * applications under non-Unix environments. + */ + +extern et_old_error_hook_func set_com_err_hook (et_old_error_hook_func); +extern et_old_error_hook_func reset_com_err_hook (void); +#endif + +#ifdef __cplusplus +} +#endif + +#define __COM_ERR_H +#endif /* ! defined(__COM_ERR_H) */ diff -uprN postgresql-hll-2.14_old/include/include/commands/alter.h postgresql-hll-2.14/include/include/commands/alter.h --- postgresql-hll-2.14_old/include/include/commands/alter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/alter.h 2020-12-12 17:06:43.178347148 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * alter.h + * prototypes for commands/alter.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/alter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ALTER_H +#define ALTER_H + +#include "catalog/dependency.h" +#include "utils/acl.h" +#include "utils/relcache.h" + +extern void ExecRenameStmt(RenameStmt* stmt); +extern void ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt* stmt); +extern Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses* objsMoved); +extern Oid AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId, Oid objid, Oid nspOid, int Anum_name, + int Anum_namespace, int Anum_owner, AclObjectKind acl_kind); +extern void ExecAlterOwnerStmt(AlterOwnerStmt* stmt); + +#endif /* ALTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/async.h postgresql-hll-2.14/include/include/commands/async.h --- postgresql-hll-2.14_old/include/include/commands/async.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/async.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * async.h + * Asynchronous notification: NOTIFY, LISTEN, UNLISTEN + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/async.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ASYNC_H +#define ASYNC_H + +#include +#include "fmgr.h" + +/* + * The number of SLRU page buffers we use for the notification queue. + */ +#define NUM_ASYNC_BUFFERS 8 + +extern THR_LOCAL volatile sig_atomic_t notifyInterruptPending; + +extern Size AsyncShmemSize(void); +extern void AsyncShmemInit(void); + +/* notify-related SQL statements */ +extern void Async_Notify(const char* channel, const char* payload); +extern void Async_Listen(const char* channel); +extern void Async_Unlisten(const char* channel); +extern void Async_UnlistenAll(void); + +/* notify-related SQL functions */ +extern Datum pg_listening_channels(PG_FUNCTION_ARGS); +extern Datum pg_notify(PG_FUNCTION_ARGS); + +/* perform (or cancel) outbound notify processing at transaction commit */ +extern void PreCommit_Notify(void); +extern void AtCommit_Notify(void); +extern void AtAbort_Notify(void); +extern void AtSubStart_Notify(void); +extern void AtSubCommit_Notify(void); +extern void AtSubAbort_Notify(void); +extern void AtPrepare_Notify(void); +extern void ProcessCompletedNotifies(void); + +/* signal handler for inbound notifies (PROCSIG_NOTIFY_INTERRUPT) */ +extern void HandleNotifyInterrupt(void); + +/* process interrupts */ +extern void ProcessNotifyInterrupt(void); + +#endif /* ASYNC_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/cluster.h postgresql-hll-2.14/include/include/commands/cluster.h --- postgresql-hll-2.14_old/include/include/commands/cluster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/cluster.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * cluster.h + * header file for postgres cluster command stuff + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/cluster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CLUSTER_H +#define CLUSTER_H + +#include "nodes/parsenodes.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +extern void cluster(ClusterStmt* stmt, bool isTopLevel); +extern void cluster_rel(Oid tableOid, Oid partitionOid, Oid indexOid, bool recheck, bool verbose, int freeze_min_age, + int freeze_table_age, void* mem_info, bool onerel); +extern void check_index_is_clusterable( + Relation OldHeap, Oid indexOid, bool recheck, LOCKMODE lockmode, Oid* amid = NULL); +extern void mark_index_clustered(Relation rel, Oid indexOid); + +extern Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, int lockMode = AccessExclusiveLock); + +extern Oid makePartitionNewHeap(Relation partitionedTableRel, TupleDesc partTabHeapDesc, Datum partTabRelOptions, + Oid oldPartOid, Oid partToastOid, Oid NewTableSpace, bool isCStore = false); +extern double copy_heap_data_internal(Relation OldHeap, Relation OldIndex, Relation NewHeap, TransactionId OldestXmin, + TransactionId FreezeXid, bool verbose, bool use_sort, AdaptMem* memUsage); +extern TransactionId getPartitionRelfrozenxid(Relation ordTableRel); +extern TransactionId getRelationRelfrozenxid(Relation ordTableRel); +extern void setRelationRelfrozenxid(Oid relid, TransactionId frozenXid); +extern void setPartitionRelfrozenxid(Oid partid, TransactionId frozenXid); +extern void finishPartitionHeapSwap(Oid partitionOid, Oid tempTableOid, bool swapToastByContent, + TransactionId frozenXid, bool tempTableIsPartition = false); + +extern void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, + bool check_constraints, TransactionId frozenXid, AdaptMem* memInfo = NULL); + +extern void vacuumFullPart(Oid partOid, VacuumStmt* vacstmt, int freeze_min_age, int freeze_table_age); +extern void GpiVacuumFullMainPartiton(Oid parentOid); +extern void updateRelationName(Oid relOid, bool isPartition, const char* relNewName); + +#endif /* CLUSTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/collationcmds.h postgresql-hll-2.14/include/include/commands/collationcmds.h --- postgresql-hll-2.14_old/include/include/commands/collationcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/collationcmds.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * collationcmds.h + * prototypes for collationcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/collationcmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef COLLATIONCMDS_H +#define COLLATIONCMDS_H + +#include "nodes/parsenodes.h" + +extern void DefineCollation(List* names, List* parameters); +extern void RenameCollation(List* name, const char* newname); +extern void AlterCollationOwner(List* name, Oid newOwnerId); +extern void AlterCollationOwner_oid(Oid collationOid, Oid newOwnerId); +extern void AlterCollationNamespace(List* name, const char* newschema); +extern Oid AlterCollationNamespace_oid(Oid collOid, Oid newNspOid); + +#endif /* COLLATIONCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/comment.h postgresql-hll-2.14/include/include/commands/comment.h --- postgresql-hll-2.14_old/include/include/commands/comment.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/comment.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,44 @@ +/* + * src/include/commands/comment.h + * + * ------------------------------------------------------------------------- + * + * comment.h + * + * Prototypes for functions in commands/comment.c + * + * Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * ------------------------------------------------------------------------- + */ + +#ifndef COMMENT_H +#define COMMENT_H + +#include "nodes/parsenodes.h" + +/* ------------------------------------------------------------------ + * Function Prototypes -- + * + * The following prototypes define the public functions of the comment + * related routines. CommentObject() implements the SQL "COMMENT ON" + * command. DeleteComments() deletes all comments for an object. + * CreateComments creates (or deletes, if comment is NULL) a comment + * for a specific key. There are versions of these two methods for + * both normal and shared objects. + * ------------------------------------------------------------------ + */ + +extern void CommentObject(CommentStmt* stmt); + +extern void DeleteComments(Oid oid, Oid classoid, int32 subid); + +extern void CreateComments(Oid oid, Oid classoid, int32 subid, const char* comment); + +extern void DeleteSharedComments(Oid oid, Oid classoid); + +extern void CreateSharedComments(Oid oid, Oid classoid, const char* comment); + +extern char* GetComment(Oid oid, Oid classoid, int32 subid); + +#endif /* COMMENT_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/conversioncmds.h postgresql-hll-2.14/include/include/commands/conversioncmds.h --- postgresql-hll-2.14_old/include/include/commands/conversioncmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/conversioncmds.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * conversioncmds.h + * prototypes for conversioncmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/conversioncmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CONVERSIONCMDS_H +#define CONVERSIONCMDS_H + +#include "nodes/parsenodes.h" + +extern void CreateConversionCommand(CreateConversionStmt* parsetree); +extern void RenameConversion(List* name, const char* newname); +extern void AlterConversionOwner(List* name, Oid newOwnerId); +extern void AlterConversionOwner_oid(Oid conversionOid, Oid newOwnerId); +extern void AlterConversionNamespace(List* name, const char* newschema); +extern Oid AlterConversionNamespace_oid(Oid convOid, Oid newNspOid); + +#endif /* CONVERSIONCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/copy.h postgresql-hll-2.14/include/include/commands/copy.h --- postgresql-hll-2.14_old/include/include/commands/copy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/copy.h 2020-12-12 17:06:43.179347161 +0800 @@ -0,0 +1,383 @@ +/* ------------------------------------------------------------------------- + * + * copy.h + * Definitions for using the POSTGRES copy command. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/copy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COPY_H +#define COPY_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "executor/execdesc.h" +#include "commands/gds_stream.h" +#include "bulkload/utils.h" + +#ifdef PGXC +#include "pgxc/pgxc.h" +#include "pgxc/execRemote.h" +#include "pgxc/locator.h" +#include "pgxc/remotecopy.h" +#include "nodes/nodes.h" +#include "pgxc/poolmgr.h" +#include "catalog/pgxc_node.h" +#include "access/obs/obs_am.h" +#endif + +struct Formatter; + +/* CopyStateData is private in commands/copy.c */ +struct CopyStateData; +typedef struct CopyStateData* CopyState; + +/* + * Represents the different source/dest cases we need to worry about at + * the bottom level + */ +typedef enum CopyDest { + COPY_FILE, /* to/from file */ + COPY_OLD_FE, /* to/from frontend (2.0 protocol) */ + COPY_NEW_FE /* to/from frontend (3.0 protocol) */ +#ifdef PGXC + , + COPY_BUFFER /* Do not send, just prepare */ +#endif + , + COPY_GDS, + COPY_FILE_SEGMENT, + COPY_ROACH, + COPY_OBS +} CopyDest; + +/* + * Represents the end-of-line terminator type of the input + */ +typedef enum EolType { EOL_UNKNOWN, EOL_NL, EOL_CR, EOL_CRNL, EOL_UD } EolType; + +typedef enum { MODE_INVALID, MODE_NORMAL, MODE_SHARED, MODE_PRIVATE } ImportMode; + +typedef struct BulkLoadFunc { + void (*initBulkLoad)(CopyState cstate, const char* filename, List* totalTask); + void (*endBulkLoad)(CopyState cstate); +} BulkLoadFunc; + +typedef int (*CopyGetDataFunc)(CopyState cstate, void* databuf, int minread, int maxread); +typedef bool (*CopyReadlineFunc)(CopyState cstate); +typedef void (*CopyWriteLineFunc)(CopyState cstate); +typedef bool (*GetNextCopyFunc)(CopyState cstate); +typedef int (*CopyReadAttrsFunc)(CopyState cstate); + +/* + * This struct is used to record original illegal chars error info; + * For non-char type field illegal_chars_fault_torlerance doesn't work, + * so still report illegal chars error. + */ +typedef struct IllegalCharErrInfo { + int err_offset; /* original error offset in each bulkload date line */ + int err_field_no; /* original error corresponding to the number of field */ + int err_code; /* original error code */ + char* err_info; /* original error info */ + + int src_encoding; + int dest_encoding; +} IllegalCharErrInfo; + +/* StringInfo pointer */ +struct stringinfo_pointer { + char* data; /* data buffer */ + int len; /* data length */ + int cursor; /* cursor to scan data buffer */ + + inline void reset(void) + { + data = NULL; + len = 0; + cursor = 0; + } + + void set(char* strinfo, int strinfo_len) + { + data = strinfo; + len = strinfo_len; + cursor = 0; + } +}; + +typedef stringinfo_pointer* stringinfo_ptr; + +/* custom format about date/time/timestamp/small datetime. */ +struct user_time_format { + /* text about date/time/timestamp/small datetime. */ + char* str; + + /* + * FormatNode info about date/time/timestamp/small datetime. + * because FormatNode is defined in CPP file, so use void* type here. + */ + void* fmt; +}; + +/* OBS Manipulation functions */ +extern void initOBSModeState(CopyState cstate, const char* filename, List* totalTask); +extern void endOBSModeBulkLoad(CopyState cstate); +extern bool CopyGetNextLineFromOBS(CopyState cstate); +extern bool getNextOBS(CopyState cstate); + +/* + * This struct contains all the state variables used throughout a COPY + * operation. For simplicity, we use the same struct for all variants of COPY, + * even though some fields are used in only some cases. + * + * Multi-byte encodings: all supported client-side encodings encode multi-byte + * characters by having the first byte's high bit set. Subsequent bytes of the + * character can have the high bit not set. When scanning data in such an + * encoding to look for a match to a single-byte (ie ASCII) character, we must + * use the full pg_encoding_mblen() machinery to skip over multibyte + * characters, else we might find a false match to a trailing byte. In + * supported server encodings, there is no possibility of a false match, and + * it's faster to make useless comparisons to trailing bytes than it is to + * invoke pg_encoding_mblen() to skip over them. encoding_embeds_ascii is TRUE + * when we have to do it the hard way. + */ +typedef struct CopyStateData { + /* low-level state data */ + CopyDest copy_dest; /* type of copy source/destination */ + bool is_from; /* Is this a Copy From or Copy To? */ + FILE* copy_file; /* used if copy_dest == COPY_FILE */ + StringInfo fe_msgbuf; /* used for all dests during COPY TO, only for + * dest == COPY_NEW_FE in COPY FROM */ + bool fe_eof; /* true if detected end of copy data */ + EolType eol_type; /* EOL type of input */ + int file_encoding; /* file or remote side's character encoding */ + bool need_transcoding; /* file encoding diff from server? */ + bool encoding_embeds_ascii; /* ASCII can be non-first byte? */ + + /* parameters from the COPY command */ + Relation rel; /* relation to copy to or from */ + Relation curPartionRel; /* current partion to copy to*/ + QueryDesc* queryDesc; /* executable query to copy from */ + List* attnumlist; /* integer list of attnums to copy */ + char* filename; /* filename, or NULL for STDIN/STDOUT */ + char* null_print; /* NULL marker string (server encoding!) */ + char* delim; /* column delimiter (must be no more than 10 bytes) */ + int null_print_len; /* length of same */ + int delim_len; + char* null_print_client; /* same converted to file encoding */ + char* quote; /* CSV quote char (must be 1 byte) */ + char* escape; /* CSV escape char (must be 1 byte) */ + char* eol; /* user defined EOL string */ + List* force_quote; /* list of column names */ + bool* force_quote_flags; /* per-column CSV FQ flags */ + List* force_notnull; /* list of column names */ + bool* force_notnull_flags; /* per-column CSV FNN flags */ + user_time_format date_format; /* user-defined date format */ + user_time_format time_format; /* user-defined time format */ + user_time_format timestamp_format; /* user-defined timestamp format */ + user_time_format smalldatetime_format; /* user-defined smalldatetime format */ + /* the flag used to control whether illegal characters can be fault-tolerant or not */ + bool compatible_illegal_chars; + bool oids; /* include OIDs? */ + bool freeze; + bool header_line; /* CSV header line? */ + bool force_quote_all; /* FORCE QUOTE *? */ + bool without_escaping; + + /* these are just for error messages, see CopyFromErrorCallback */ + const char* cur_relname; /* table name for error messages */ + uint32 cur_lineno; /* line number for error messages */ + const char* cur_attname; /* current att for error messages */ + const char* cur_attval; /* current att value for error messages */ + + /* + * Working state for COPY TO/FROM + */ + MemoryContext copycontext; /* per-copy execution context */ + + /* + * Working state for COPY TO + */ + FmgrInfo* out_functions; /* lookup info for output functions */ + MemoryContext rowcontext; /* per-row evaluation context */ + + /* + * Working state for COPY FROM + */ + AttrNumber num_defaults; + bool file_has_oids; + FmgrInfo oid_in_function; + Oid oid_typioparam; + FmgrInfo* in_functions; /* array of input functions for each attrs */ + Oid* typioparams; /* array of element types for in_functions */ + bool* accept_empty_str; /* is type of each column can accept empty string? */ + int* defmap; /* array of default att numbers */ + ExprState** defexprs; /* array of default att expressions */ + bool volatile_defexprs; /* is any of defexprs volatile? */ + List* range_table; + Datum copy_beginTime; /* log the query start time*/ + bool log_errors; /* mark where we tolerate data exceptions and log them into copy_error_log */ + int reject_limit; /* number of data exceptions we allow per Copy (on coordinator) */ + bool logErrorsData; /* mark where we tolerate data exceptions and log them into copy_error_log and make sure + Whether to fill the rowrecord field of the copy_error_log*/ + Relation err_table; /* opened copy_error_log table */ + CopyErrorLogger* logger; /* logger used for copy from error logging*/ + FmgrInfo* err_out_functions; /* lookup info for output functions of copy_error_log*/ + + /* + * These variables are used to reduce overhead in textual COPY FROM. + * + * attribute_buf holds the separated, de-escaped text for each field of + * the current line. The CopyReadAttributes functions return arrays of + * pointers into this buffer. We avoid palloc/pfree overhead by re-using + * the buffer on each cycle. + */ + StringInfoData attribute_buf; + + /* field raw data pointers found by COPY FROM */ + + int max_fields; + char** raw_fields; + + /* + * Similarly, line_buf holds the whole input line being processed. The + * input cycle is first to read the whole line into line_buf, convert it + * to server encoding there, and then extract the individual attribute + * fields into attribute_buf. line_buf is preserved unmodified so that we + * can display it in error messages if appropriate. + */ + StringInfoData line_buf; + bool line_buf_converted; /* converted to server encoding? */ + + /* + * Finally, raw_buf holds raw data read from the data source (file or + * client connection). CopyReadLine parses this data sufficiently to + * locate line boundaries, then transfers the data to line_buf and + * converts it. Note: we guarantee that there is a \0 at + * raw_buf[raw_buf_len]. + */ +#define RAW_BUF_SIZE 65536 /* we palloc RAW_BUF_SIZE+1 bytes */ + char* raw_buf; + int raw_buf_index; /* next byte to process */ + int raw_buf_len; /* total # of bytes stored */ + + PageCompress* pcState; + +#ifdef PGXC + /* Remote COPY state data */ + RemoteCopyData* remoteCopyState; +#endif + bool fill_missing_fields; + bool ignore_extra_data; /* ignore overflowing fields */ + + Formatter* formatter; + FileFormat fileformat; + char* headerFilename; /* User define header filename */ + char* out_filename_prefix; + char* out_fix_alignment; + StringInfo headerString; + + /* For bulkload*/ + BulkLoadStream* io_stream; + List* file_list; + ListCell* file_index; + ImportMode mode; + List* taskList; + ListCell* curTaskPtr; + long curReadOffset; + BulkLoadFunc bulkLoadFunc; + CopyGetDataFunc copyGetDataFunc; + CopyReadlineFunc readlineFunc; + CopyReadAttrsFunc readAttrsFunc; + GetNextCopyFunc getNextCopyFunc; + stringinfo_pointer inBuffer; + + uint32 distSessionKey; + List* illegal_chars_error; /* used to record every illegal_chars_error for each imported data line. */ + + bool isExceptionShutdown; /* To differentiate normal end of a bulkload task or a task abort because of exceptions*/ + + // For export + // + uint64 distCopyToTotalSize; + CopyWriteLineFunc writelineFunc; + bool remoteExport; + StringInfo outBuffer; + + // For Roach + void* roach_context; + Node* roach_routine; + + // For OBS parallel import/export + ObsCopyOptions obs_copy_options; + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; +} CopyStateData; + +#define IS_CSV(cstate) ((cstate)->fileformat == FORMAT_CSV) +#define IS_BINARY(cstate) ((cstate)->fileformat == FORMAT_BINARY) +#define IS_FIXED(cstate) ((cstate)->fileformat == FORMAT_FIXED) +#define IS_TEXT(cstate) ((cstate)->fileformat == FORMAT_TEXT) +#define IS_REMOTEWRITE(cstate) ((cstate)->fileformat == FORMAT_WRITABLE) + +extern uint64 DoCopy(CopyStmt* stmt, const char* queryString); + +extern void ProcessCopyOptions(CopyState cstate, bool is_from, List* options); +extern bool IsTypeAcceptEmptyStr(Oid typeOid); +extern CopyState BeginCopyFrom(Relation rel, const char* filename, List* attnamelist, List* options, void* mem_info); +extern void EndCopyFrom(CopyState cstate); +extern bool NextCopyFrom(CopyState cstate, ExprContext* econtext, Datum* values, bool* nulls, Oid* tupleOid); +extern bool NextCopyFromRawFields(CopyState cstate, char*** fields, int* nfields); +extern void CopyFromErrorCallback(void* arg); +extern void BulkloadErrorCallback(void* arg); + +extern DestReceiver* CreateCopyDestReceiver(void); + +extern CopyState begin_dist_copy_from( + Relation rel, const char* filename, List* attnamelist, List* options, List* totalTask); + +extern void end_dist_copy(CopyState cstate); + +extern List* DeserializeLocations(const char* location); + +extern bool is_valid_location(const char* location); + +extern bool is_local_location(const char* location); + +extern bool is_roach_location(const char* location); + +extern void getPathAndPattern(char* url, char** path, char** pattern); + +extern char* scan_dir(DIR* dir, const char* dirpath, const char* pattern, long* filesize); + +extern CopyState beginExport( + Relation rel, const char* filename, List* options, bool isRemote, uint32 sessionKey, List* tasklist); +extern void execExport(CopyState cpstate, TupleTableSlot* slot); +extern void endExport(CopyState cstate); + +extern uint64 exportGetTotalSize(CopyState cstate); +extern void exportResetTotalSize(CopyState cstate); +extern void exportAllocNewFile(CopyState cstate, const char* newfile); +extern void exportFlushOutBuffer(CopyState cstate); + +extern void ProcessFileHeader(CopyState cstate); + +extern List* addNullTask(List* taskList); +extern void CopySendString(CopyState cstate, const char* str); +extern void CopySendChar(CopyState cstate, char c); + +extern void cstate_fields_buffer_init(CopyState cstate); +extern bool IsCharType(Oid attr_type); +extern int GetDecimalFromHex(char hex); +extern char* limit_printout_length(const char* str); + +extern char* TrimStr(const char* str); + +#endif /* COPY_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/copypartition.h postgresql-hll-2.14/include/include/commands/copypartition.h --- postgresql-hll-2.14_old/include/include/commands/copypartition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/copypartition.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,206 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * copypartition.h + * + * + * + * IDENTIFICATION + * src/include/commands/copypartition.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COPYPARTITION_H +#define COPYPARTITION_H + +#define MAX_BUFFERED_TUPLES 20000 +#define MAX_TUPLES_SIZE (1024 * 1024) + +#define MIN_MEMCXT_NUM (16) +#define MAX_MEMCXT_NUM (1024) +#define PART_NUM_PER_MEMCXT (4) +#define LMT_SIZE_PER_PART (BLCKSZ * 4) +#define MAX_SIZE_PER_MEMCXT (LMT_SIZE_PER_PART * PART_NUM_PER_MEMCXT) +#define MAX_HASH_ENTRY_NUM (PART_NUM_PER_MEMCXT * MAX_MEMCXT_NUM) +#define DEF_BUFFERED_TUPLES (128) + +struct CopyFromMemCxtData; +typedef struct CopyFromMemCxtData* CopyFromMemCxt; +typedef struct CopyFromManagerData* CopyFromManager; +typedef struct CopyFromBulkData* CopyFromBulk; + +typedef struct CopyFromMemCxtData { + /* used for tuples' memory in the partition chunk */ + MemoryContext memCxtCandidate; + uint32 memCxtSize; + + /* members for bulk chunk */ + int16 nextBulk; /* nextBulk < PART_NUM_PER_MEMCXT, otherwise this chunk is full */ + int16 id; + CopyFromBulk chunk[PART_NUM_PER_MEMCXT]; +} CopyFromMemCxtData; + +typedef struct CopyFromBulkKey +{ + /* the hash key */ + Oid partOid; + int4 bucketId; +} CopyFromBulkKey; + +typedef struct CopyFromBulkData { + /* the hash key */ + Oid partOid; + int4 bucketId; + + /* the other entry info in hash table */ + int numTuples; + int maxTuples; + HeapTuple* tuples; + Size sizeTuples; + /* bulk-insert Memory Context */ + CopyFromMemCxt memCxt; +} CopyFromBulkData; + +typedef struct CopyFromManagerData { + /* members under PARTITION condition */ + MemoryContext parent; + CopyFromMemCxt* memCxt; + uint16 numMemCxt; + uint16 maxMemCxt; + uint16 nextMemCxt; + uint16 numFreeMemCxt; + uint16 freeMemCxt[MAX_MEMCXT_NUM]; + + HTAB* hash; + + /* members without PARTITION */ + bool isPartRel; + bool LastFlush; + CopyFromBulk bulk; + CopyFromBulkKey switchKey; +} CopyFromManagerData; + +extern void CopyFromBulkInsert(EState* estate, CopyFromBulk bulk, PageCompress* pcState, CommandId mycid, + int hi_options, ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, bool forceToFlush, BulkInsertState bistate); + +extern CopyFromBulk findBulk(CopyFromManager mgr, Oid partOid, int2 bucketId, bool *toFlush); +extern bool isBulkFull(CopyFromBulk bulk); +template +void addToBulk(CopyFromBulk bulk, HeapTuple tup, bool needCopy) +{ + MemoryContext oldCxt = NULL; + CopyFromMemCxt copyFromMemCxt = NULL; + HeapTuple newTuple = NULL; + + Assert(bulk != NULL && tup != NULL); + if (needCopy) { +#ifdef USE_ASSERT_CHECKING + int idx; + bool found = false; +#endif + copyFromMemCxt = bulk->memCxt; + Assert(copyFromMemCxt != NULL); + +#ifdef USE_ASSERT_CHECKING + if (!isInsertSelect) { + for (idx = 0; idx < copyFromMemCxt->nextBulk; idx++) { + found = found || (copyFromMemCxt->chunk[idx] == bulk); + } + Assert(true == found); + } +#endif + + oldCxt = MemoryContextSwitchTo(copyFromMemCxt->memCxtCandidate); + + newTuple = heap_copytuple(tup); + copyFromMemCxt->memCxtSize += newTuple->t_len; + if (bulk->numTuples == bulk->maxTuples) { + bulk->maxTuples *= 2; + bulk->tuples = (HeapTuple*)repalloc(bulk->tuples, sizeof(HeapTuple) * bulk->maxTuples); + } + + (void)MemoryContextSwitchTo(oldCxt); + } else { + Assert(InvalidOid == bulk->partOid); + Assert(NULL == bulk->memCxt); + Assert(bulk->numTuples < MAX_BUFFERED_TUPLES); + Assert(bulk->sizeTuples < MAX_TUPLES_SIZE); + newTuple = tup; + } + + Assert(bulk->numTuples < bulk->maxTuples); + bulk->tuples[bulk->numTuples] = newTuple; + bulk->sizeTuples += newTuple->t_len; + bulk->numTuples++; +} + +template +bool CopyFromChunkInsert(CopyState cstate, EState* estate, CopyFromBulk bulk, CopyFromManager mgr, + PageCompress* pCState, CommandId mycid, int hiOptions, ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, + BulkInsertState bistate) +{ + int cnt; + CopyFromMemCxt copyFromMemCxt = bulk->memCxt; + MemoryContext oldCxt; + + if (!mgr->isPartRel) { + + if (isInsertSelect) { + CopyFromBulkInsert(estate, bulk, pCState, mycid, hiOptions, resultRelInfo, myslot, mgr->LastFlush, bistate); + if (bulk->numTuples == 0) { + MemoryContextReset(copyFromMemCxt->memCxtCandidate); + copyFromMemCxt->memCxtSize = 0; + } + } else + CopyFromBulkInsert(estate, bulk, pCState, mycid, hiOptions, resultRelInfo, myslot, mgr->LastFlush, bistate); + return (0 == bulk->numTuples); + } + + Assert(((InvalidOid != bulk->partOid) && (InvalidOid == mgr->switchKey.partOid)) || + ((InvalidOid == bulk->partOid) && (InvalidOid != mgr->switchKey.partOid))); + for (cnt = 0; cnt < copyFromMemCxt->nextBulk; cnt++) { + CopyFromBulk bulkItem = copyFromMemCxt->chunk[cnt]; + CopyFromBulkKey key = {bulkItem->partOid, bulkItem->bucketId}; + bool found = false; + CopyFromBulkInsert(estate, bulkItem, pCState, mycid, hiOptions, resultRelInfo, myslot, true, bistate); + (void)hash_search(mgr->hash, &key, HASH_REMOVE, &found); + Assert(found); + } + + /* reset CopyFromMemCxt */ + copyFromMemCxt->nextBulk = 0; + MemoryContextReset(copyFromMemCxt->memCxtCandidate); + copyFromMemCxt->memCxtSize = 0; + + if (InvalidOid == mgr->switchKey.partOid) { + /* add to freelist */ + mgr->freeMemCxt[mgr->numFreeMemCxt++] = copyFromMemCxt->id; + } else { + copyFromMemCxt->chunk[copyFromMemCxt->nextBulk++] = bulk; + + /* reset Bulk, excluding memCxt */ + bulk->partOid = mgr->switchKey.partOid; + bulk->bucketId = mgr->switchKey.bucketId; + mgr->switchKey.partOid = InvalidOid; + mgr->switchKey.bucketId = InvalidBktId; + bulk->maxTuples = DEF_BUFFERED_TUPLES; + oldCxt = MemoryContextSwitchTo(copyFromMemCxt->memCxtCandidate); + bulk->tuples = (HeapTuple*)palloc(sizeof(HeapTuple) * bulk->maxTuples); + (void)MemoryContextSwitchTo(oldCxt); + } + + return true; +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/commands/createas.h postgresql-hll-2.14/include/include/commands/createas.h --- postgresql-hll-2.14_old/include/include/commands/createas.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/createas.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,32 @@ +/* ------------------------------------------------------------------------- + * + * createas.h + * prototypes for createas.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/createas.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CREATEAS_H +#define CREATEAS_H + +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "tcop/dest.h" + +extern void ExecCreateTableAs( + CreateTableAsStmt* stmt, const char* queryString, ParamListInfo params, char* completionTag); + +extern int GetIntoRelEFlags(IntoClause* intoClause); + +extern DestReceiver* CreateIntoRelDestReceiver(IntoClause* intoClause); + +extern Query *SetupForCreateTableAs(Query *query, IntoClause *into, + const char *queryString, + ParamListInfo params, DestReceiver *dest); + +#endif /* CREATEAS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/dbcommands.h postgresql-hll-2.14/include/include/commands/dbcommands.h --- postgresql-hll-2.14_old/include/include/commands/dbcommands.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/dbcommands.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * dbcommands.h + * Database management commands (create/drop database). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/dbcommands.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DBCOMMANDS_H +#define DBCOMMANDS_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" + +/* XLOG stuff */ +#define XLOG_DBASE_CREATE 0x00 +#define XLOG_DBASE_DROP 0x10 + +typedef struct xl_dbase_create_rec_old { + /* Records copying of a single subdirectory incl. contents */ + Oid db_id; + char src_path[1]; /* VARIABLE LENGTH STRING */ + /* dst_path follows src_path */ +} xl_dbase_create_rec_old; + +typedef struct xl_dbase_drop_rec_old { + /* Records dropping of a single subdirectory incl. contents */ + Oid db_id; + char dir_path[1]; /* VARIABLE LENGTH STRING */ +} xl_dbase_drop_rec_old; + +typedef struct xl_dbase_create_rec { + /* Records copying of a single subdirectory incl. contents */ + Oid db_id; + Oid tablespace_id; + Oid src_db_id; + Oid src_tablespace_id; +} xl_dbase_create_rec; + +typedef struct xl_dbase_drop_rec { + /* Records dropping of a single subdirectory incl. contents */ + Oid db_id; + Oid tablespace_id; +} xl_dbase_drop_rec; + +extern void createdb(const CreatedbStmt* stmt); +extern void dropdb(const char* dbname, bool missing_ok); +extern void RenameDatabase(const char* oldname, const char* newname); +extern void AlterDatabase(AlterDatabaseStmt* stmt, bool isTopLevel); +extern void AlterDatabaseSet(AlterDatabaseSetStmt* stmt); +extern void AlterDatabaseOwner(const char* dbname, Oid newOwnerId); + +extern Oid get_database_oid(const char* dbname, bool missingok); +extern char* get_database_name(Oid dbid); +extern char* get_and_check_db_name(Oid dbid, bool is_ereport = false); +extern bool have_createdb_privilege(void); + +extern void dbase_redo(XLogReaderState* rptr); +extern void dbase_desc(StringInfo buf, XLogReaderState* record); +extern void xlog_db_drop(Oid dbId, Oid tbSpcId); +extern void xlog_db_create(Oid dstDbId, Oid dstTbSpcId, Oid srcDbId, Oid srcTbSpcId); + +extern void check_encoding_locale_matches(int encoding, const char* collate, const char* ctype); + +#ifdef PGXC +extern bool IsSetTableSpace(AlterDatabaseStmt* stmt); +extern int errdetail_busy_db(int notherbackends, int npreparedxacts); +extern void PreCleanAndCheckConns(const char* dbname, bool missing_ok); +#endif + +extern List* HDFSTablespaceDirExistDatabase(Oid db_id); + +#endif /* DBCOMMANDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/defrem.h postgresql-hll-2.14/include/include/commands/defrem.h --- postgresql-hll-2.14_old/include/include/commands/defrem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/defrem.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * + * defrem.h + * POSTGRES define and remove utility definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/defrem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEFREM_H +#define DEFREM_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" + +/* commands/dropcmds.c */ +extern void RemoveObjects(DropStmt* stmt, bool missing_ok, bool is_securityadmin = false); + +/* commands/indexcmds.c */ +extern Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_alter_table, bool check_rights, + bool skip_build, bool quiet); +extern void ReindexIndex(RangeVar* indexRelation, const char* partition_name, AdaptMem* mem_info); +extern void ReindexTable(RangeVar* relation, const char* partition_name, AdaptMem* mem_info); +extern void ReindexInternal(RangeVar* relation, const char* partition_name); + +extern void ReindexDatabase(const char* databaseName, bool do_system, bool do_user, AdaptMem* mem_info); +extern char* makeObjectName(const char* name1, const char* name2, const char* label, bool reverseTruncate = false); +extern char* ChooseRelationName( + const char* name1, const char* name2, const char* label, size_t labelLength, Oid namespaceid, + bool reverseTruncate = false); +extern bool CheckIndexCompatible(Oid oldId, char* accessMethodName, List* attributeList, List* exclusionOpNames); +extern Oid GetDefaultOpClass(Oid type_id, Oid am_id); + +/* commands/functioncmds.c */ +extern bool PrepareCFunctionLibrary(HeapTuple tup); +extern void InsertIntoPendingLibraryDelete(const char* filename, bool atCommit); +extern void libraryDoPendingDeletes(bool isCommit); +extern void ResetPendingLibraryDelete(); +extern void CreateFunction(CreateFunctionStmt* stmt, const char* queryString); +extern void RemoveFunctionById(Oid funcOid); +extern void SetFunctionReturnType(Oid funcOid, Oid newRetType); +extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType); +extern void RenameFunction(List* name, List* argtypes, const char* newname); +extern void AlterFunctionOwner(List* name, List* argtypes, Oid newOwnerId); +extern void AlterFunctionOwner_oid(Oid procOid, Oid newOwnerId); +extern bool IsFunctionTemp(AlterFunctionStmt* stmt); +extern void AlterFunction(AlterFunctionStmt* stmt); +extern void CreateCast(CreateCastStmt* stmt); +extern void DropCastById(Oid castOid); +extern void AlterFunctionNamespace(List* name, List* argtypes, bool isagg, const char* newschema); +extern Oid AlterFunctionNamespace_oid(Oid procOid, Oid nspOid); +extern void ExecuteDoStmt(DoStmt* stmt, bool atomic); +extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok); + +/* commands/operatorcmds.c */ +extern void DefineOperator(List* names, List* parameters); +extern void RemoveOperatorById(Oid operOid); +extern void AlterOperatorOwner(List* name, TypeName* typeName1, TypeName* typename2, Oid newOwnerId); +extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId); +extern void AlterOperatorNamespace(List* names, List* argtypes, const char* newschema); +extern Oid AlterOperatorNamespace_oid(Oid operOid, Oid newNspOid); + +/* commands/aggregatecmds.c */ +extern void DefineAggregate(List* name, List* args, bool oldstyle, List* parameters); +extern void RenameAggregate(List* name, List* args, const char* newname); +extern void AlterAggregateOwner(List* name, List* args, Oid newOwnerId); + +/* commands/opclasscmds.c */ +extern void DefineOpClass(CreateOpClassStmt* stmt); +extern void DefineOpFamily(CreateOpFamilyStmt* stmt); +extern void AlterOpFamily(AlterOpFamilyStmt* stmt); +extern void RemoveOpClassById(Oid opclassOid); +extern void RemoveOpFamilyById(Oid opfamilyOid); +extern void RemoveAmOpEntryById(Oid entryOid); +extern void RemoveAmProcEntryById(Oid entryOid); +extern void RenameOpClass(List* name, const char* access_method, const char* newname); +extern void RenameOpFamily(List* name, const char* access_method, const char* newname); +extern void AlterOpClassOwner(List* name, const char* access_method, Oid newOwnerId); +extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId); +extern void AlterOpClassNamespace(List* name, char* access_method, const char* newschema); +extern Oid AlterOpClassNamespace_oid(Oid opclassOid, Oid newNspOid); +extern void AlterOpFamilyOwner(List* name, const char* access_method, Oid newOwnerId); +extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId); +extern void AlterOpFamilyNamespace(List* name, char* access_method, const char* newschema); +extern Oid AlterOpFamilyNamespace_oid(Oid opfamilyOid, Oid newNspOid); +extern Oid get_am_oid(const char* amname, bool missing_ok); +extern Oid get_opclass_oid(Oid amID, List* opclassname, bool missing_ok); +extern Oid get_opfamily_oid(Oid amID, List* opfamilyname, bool missing_ok); + +/* commands/tsearchcmds.c */ +extern void DefineTSParser(List* names, List* parameters); +extern void RenameTSParser(List* oldname, const char* newname); +extern void AlterTSParserNamespace(List* name, const char* newschema); +extern Oid AlterTSParserNamespace_oid(Oid prsId, Oid newNspOid); +extern void RemoveTSParserById(Oid prsId); + +extern void DefineTSDictionary(List* names, List* parameters); +extern void RenameTSDictionary(List* oldname, const char* newname); +extern void RemoveTSDictionaryById(Oid dictId); +extern void AlterTSDictionary(AlterTSDictionaryStmt* stmt); +extern void AlterTSDictionaryOwner(List* name, Oid newOwnerId); +extern void AlterTSDictionaryOwner_oid(Oid dictId, Oid newOwnerId); +extern void AlterTSDictionaryNamespace(List* name, const char* newschema); +extern Oid AlterTSDictionaryNamespace_oid(Oid dictId, Oid newNspOid); + +extern void DefineTSTemplate(List* names, List* parameters); +extern void RenameTSTemplate(List* oldname, const char* newname); +extern void AlterTSTemplateNamespace(List* name, const char* newschema); +extern Oid AlterTSTemplateNamespace_oid(Oid tmplId, Oid newNspOid); +extern void RemoveTSTemplateById(Oid tmplId); + +extern void DefineTSConfiguration(List* names, List* parameters, List* cfoptions); +extern void RenameTSConfiguration(List* oldname, const char* newname); +extern void RemoveTSConfigurationById(Oid cfgId); +extern void AlterTSConfiguration(AlterTSConfigurationStmt* stmt); +extern void AlterTSConfigurationOwner(List* name, Oid newOwnerId); +extern void AlterTSConfigurationNamespace(List* name, const char* newschema); +extern Oid AlterTSConfigurationNamespace_oid(Oid cfgId, Oid newNspOid); + +extern text* serialize_deflist(List* deflist); +extern List* deserialize_deflist(Datum txt); + +/* commands/weak_password_dictioanry.c */ +extern void CreateWeakPasswordDictionary(CreateWeakPasswordDictionaryStmt* stmt); +extern void DropWeakPasswordDictionary(); + +/* commands/foreigncmds.c */ +extern void RenameForeignServer(const char* oldname, const char* newname); +extern void RenameForeignDataWrapper(const char* oldname, const char* newname); +extern void AlterForeignServerOwner(const char* name, Oid newOwnerId); +extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId); +extern void AlterForeignDataWrapperOwner(const char* name, Oid newOwnerId); +extern void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId); +extern void CreateForeignDataWrapper(CreateFdwStmt* stmt); +extern void AlterForeignDataWrapper(AlterFdwStmt* stmt); +extern void RemoveForeignDataWrapperById(Oid fdwId); +extern void CreateForeignServer(CreateForeignServerStmt* stmt); +extern void AlterForeignServer(AlterForeignServerStmt* stmt); +extern void RemoveForeignServerById(Oid srvId); +extern void CreateUserMapping(CreateUserMappingStmt* stmt); +extern void AlterUserMapping(AlterUserMappingStmt* stmt); +extern void RemoveUserMapping(DropUserMappingStmt* stmt); +extern void RemoveUserMappingById(Oid umId); +extern void CreateForeignTable(CreateForeignTableStmt* stmt, Oid relid); +#ifdef ENABLE_MOT +extern void CreateForeignIndex(IndexStmt* stmt, Oid indexRelationId); +#endif +extern Datum transformGenericOptions(Oid catalogId, Datum oldOptions, List* options, Oid fdwvalidator); +extern Datum optionListToArray(List* options); +extern List* FindOrRemoveForeignTableOption(List* optList, const char* optName, bool remove, bool* found); + +/* support routines in commands/define.c */ + +extern char* defGetString(DefElem* def); +extern double defGetNumeric(DefElem* def); +extern bool defGetBoolean(DefElem* def); +extern int64 defGetInt64(DefElem* def); +extern List* defGetQualifiedName(DefElem* def); +extern TypeName* defGetTypeName(DefElem* def); +extern int defGetTypeLength(DefElem* def); +extern List* defSetOption(List* options, const char* name, Node* value); +extern void delete_file_handle(const char* library_path); +extern int libraryGetPendingDeletes(bool forCommit, char** str_ptr, int* libraryLen); +extern void removeLibrary(const char* filename); + +/* support routines in commands/datasourcecmds.cpp */ +extern void CreateDataSource(CreateDataSourceStmt* stmt); +extern void AlterDataSource(AlterDataSourceStmt* stmt); +extern void RenameDataSource(const char* oldname, const char* newname); +extern void AlterDataSourceOwner(const char* name, Oid newOwnerId); +extern void RemoveDataSourceById(Oid src_Id); + +extern Oid GetFunctionNodeGroup(CreateFunctionStmt* stmt, bool* multi_group); +extern Oid GetFunctionNodeGroupByFuncid(Oid funcid); +extern Oid GetFunctionNodeGroup(AlterFunctionStmt* stmt); + +#endif /* !FRONTEND_PARSER */ +extern DefElem* defWithOids(bool value); +#endif /* DEFREM_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/directory.h postgresql-hll-2.14/include/include/commands/directory.h --- postgresql-hll-2.14_old/include/include/commands/directory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/directory.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * directory.h + * The declaration of directory operate function. The functions + * use to simulate A db's directory. + * + * + * IDENTIFICATION + * src/include/commands/directory.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DIRECTORY_H +#define DIRECTORY_H + +#include "nodes/parsenodes.h" + +/* directory.h */ +extern void CreatePgDirectory(CreateDirectoryStmt* stmt); +extern void DropPgDirectory(DropDirectoryStmt* stmt); +extern Oid get_directory_oid(const char* directoryname, bool missing_ok); +extern char* get_directory_name(Oid dir_oid); +extern void RemoveDirectoryById(Oid dirOid); +extern void AlterDirectoryOwner(const char* dirname, Oid newOwnerId); + +#endif /* DIRECTORY_H*/ diff -uprN postgresql-hll-2.14_old/include/include/commands/discard.h postgresql-hll-2.14/include/include/commands/discard.h --- postgresql-hll-2.14_old/include/include/commands/discard.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/discard.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,20 @@ +/* ------------------------------------------------------------------------- + * + * discard.h + * prototypes for discard.c. + * + * + * Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/commands/discard.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DISCARD_H +#define DISCARD_H + +#include "nodes/parsenodes.h" + +extern void DiscardCommand(DiscardStmt* stmt, bool isTopLevel); + +#endif /* DISCARD_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/explain.h postgresql-hll-2.14/include/include/commands/explain.h --- postgresql-hll-2.14_old/include/include/commands/explain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/explain.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,506 @@ +/* ------------------------------------------------------------------------- + * + * explain.h + * prototypes for explain.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994-5, Regents of the University of California + * + * src/include/commands/explain.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXPLAIN_H +#define EXPLAIN_H + +#include "executor/executor.h" +#include "utils/portal.h" + +extern uint32 RunGetSlotFromExplain(Portal portal, TupleTableSlot* slot, DestReceiver* dest, int count); + +typedef enum ExplainFormat { + EXPLAIN_FORMAT_TEXT, + EXPLAIN_FORMAT_XML, + EXPLAIN_FORMAT_JSON, + EXPLAIN_FORMAT_YAML +} ExplainFormat; + +struct ExplainState; + +#define ASCE 1 +#define DESC 5 + +typedef enum PlanInfoType { + PLANID = 0, + PLAN, + ACTUAL_TIME, + PREDICT_TIME, + ACTUAL_ROWS, + PREDICT_ROWS, + ESTIMATE_ROWS, + ESTIMATE_DISTINCT, + ACTUAL_MEMORY, + PREDICT_MEMORY, + ESTIMATE_MEMORY, + ACTUAL_WIDTH, + ESTIMATE_WIDTH, + ESTIMATE_COSTS, + + SLOT_NUMBER // this is the length of the slot number, this is the last number +} PlanInfoType; + +typedef enum Plantype { + PLANINFO = 0, + DETAILINFO, + STATICINFO, + VERBOSEINFO, + DATANODEINFO, + IOINFO, + RUNTIMEINFO, + PROFILEINFO, + RECURSIVEINFO, + QUERYSUMMARY +} Plantype; + +typedef enum ExplainType { + QUERY_ID = 0, + PLAN_PARENT_ID, + PLAN_NODE_ID, + PLAN_TYPE, + FROM_DATANODE, + NODE_NAME, + PLAN_NAME, + START_TIME, + TOTAL_TIME, + OPER_TIME, + PLAN_ROWS, + PLAN_LOOPS, + EX_CYC, + INC_CYC, + EX_CYC_PER_ROWS, + PEAK_OP_MEMORY, + PEAK_NODE_MEMORY, + + SHARED_BLK_HIT, + SHARED_BLK_READ, + SHARED_BLK_DIRTIED, + SHARED_BLK_WRITTEN, + LOCAL_BLK_HIT, + LOCAL_BLK_READ, + LOCAL_BLK_DIRTIED, + LOCAL_BLK_WRITTEN, + TEMP_BLK_READ, + TEMP_BLK_WRITTEN, + BLK_READ_TIME, + BLK_WRITE_TIME, + + CU_NONE, + CU_SOME, + + SORT_METHOD, + SORT_TYPE, + SORT_SPACE, + + HASH_BATCH, + HASH_BATCH_ORIGNAL, + HASH_BUCKET, + HASH_SPACE, + + HASH_FILENUM, + + QUERY_NETWORK, + NETWORK_POLL_TIME, + + LLVM_OPTIMIZATION, + BLOOM_FILTER_INFO, + DFS_BLOCK_INFO, + + MERGE_INSERTED, + MERGE_UPDATED, + + EXPLAIN_TOTAL_ATTNUM // this is the attnum of the table +} ExplainType; + +typedef struct MultiInfo { + Datum* m_Datum; + bool* m_Nulls; +} MultiInfo; + +typedef struct CompareInfo { + SortSupport ssup; + int attnum; + int* att; +} CompareInfo; + +/* plan table entry of each column in the table */ +typedef enum PlanColOpt { + ANAL_OPT = 0, COST_OPT, VERBOSE_OPT, PRED_OPT_TIME, PRED_OPT_ROW, PRED_OPT_MEM +} PlanColOpt; +typedef enum ExecutorTime { DN_START_TIME = 0, DN_RUN_TIME, DN_END_TIME} ExecutorTime; +typedef struct PlanTableEntry { + const char* name; /* column name */ + int val; /* column enum index in PlanInfoType */ + Oid typid; /* column type */ + PlanColOpt disoption; /* explain display option */ +} PlanTableEntry; + +/* --------------------------for explain plan && plan_table--------------------------- */ +/* for table "plan_table_data". */ +#define T_PLAN_TABLE_DATA "plan_table_data" +/* for view "plan_table". */ +#define V_PLAN_TABLE "plan_table" + +/* plan_table column length for explain plan. */ +#define PLANTABLECOLNUM 11 +#define SESSIONIDLEN 32 +#define STMTIDLEN 31 /* the max statement_id length is 30 byte. */ +#define OPERATIONLEN 31 +#define OPTIONSLEN 256 +#define OBJECTLEN 31 +#define PROJECTIONLEN 4001 + +/* plan_table_data column defination. */ +typedef struct PlanTableData { + char session_id[SESSIONIDLEN]; /* start time + thread id */ + Oid user_id; /* user id of this record, uint32 */ + char statement_id[STMTIDLEN]; /* statement_id that user input. */ + uint64 query_id; /* A db use plan_id instead of query_id as column name*/ + int node_id; /* plan node id. */ + char operation[OPERATIONLEN]; /* plan node operation. */ + char options[OPTIONSLEN]; /* plan node options. */ + char object_name[NAMEDATALEN]; /* object_name of this node operate. */ + char object_type[OBJECTLEN]; /* object type. */ + char object_owner[NAMEDATALEN]; /* object schema */ + StringInfo projection; /* output targetlist of the node */ +} PlanTableData; + +typedef enum PlanTableCol { + PT_SESSION_ID = 0, + PT_USER_ID, + PT_STATEMENT_ID, + PT_QUERY_ID, + + PT_NODE_ID, + + PT_OPERATION, + PT_OPTIONS, + + PT_OBJECT_NAME, + PT_OBJECT_TYPE, + PT_OBJECT_OWNER, + + PT_PROJECTION +} PlanTableCol; + +/* Store all node tupls of one plan. */ +typedef struct PlanTableMultiData { + PlanTableData* m_datum; + bool* m_isnull; +} PlanTableMultiData; + +extern THR_LOCAL bool OnlySelectFromPlanTable; +extern THR_LOCAL bool OnlyDeleteFromPlanTable; +extern THR_LOCAL bool PTFastQueryShippingStore; +extern THR_LOCAL bool IsExplainPlanStmt; +/* --------------------------end--------------------------- */ + +typedef int (*SortCompareFunc)(const MultiInfo* arg1, const MultiInfo* arg2, CompareInfo* ssup); + +class PlanTable : public BaseObject { + friend class PlanInformation; + +public: + Datum get(int type); + void put(int infotype, Datum datum); + void put(int nodeId, int smpId, int type, Datum value); + void flush(DestReceiver* dest, int plantype); + int print_plan(Portal portal, DestReceiver* dest); + void init(int plantype); + void set(int planNodeId) + { + m_plan_node_id = planNodeId; + m_has_write_planname = false; + } + + template + void set_plan_name(); + void flush_data_to_file(); + void set_datanode_name(char* nodename, int smp_idx, int dop); + + /* -----------Functions for explain plan stmt. ---------------- */ + void make_session_id(char* sessid); + + /* Set session_id, user_id, statement_id, query_id and plan node id for the query. */ + void set_plan_table_ids(uint64 query_id, ExplainState* es); + + /* Set object_name, object_type, object_owner for one paln node. */ + void set_plan_table_objs( + int plan_node_id, const char* object_name, const char* object_type, const char* object_owner); + + /* Set object_type according to relkind in pg_class. */ + void set_object_type(RangeTblEntry* rte, char** object_type); + + /* Set operation and options for remote query and stream node.*/ + void set_plan_table_streaming_ops(char* pname, char** operation, char** options); + + /* Set join option 'CARTESIAN' to fit with A db. */ + void set_plan_table_join_options(Plan* plan, char** options); + + /* Set operation and options for node except stream node. */ + void set_plan_table_ops(int plan_node_id, char* operation, char* options); + + /* Set projection for one paln node. */ + void set_plan_table_projection(int plan_node_id, List* tlist); + + /* Call heap_insert to insert all nodes tuples of the plan into table. */ + void insert_plan_table_tuple(); + +public: + StringInfo info_str; + int64 m_size; + int m_plan_node_id; + TupleDesc m_desc; + bool m_costs; + bool m_verbose; + bool m_cpu; + bool m_analyze; + bool m_timing; + StringInfoData m_pname; + bool m_has_write_planname; + double m_total_time; + int m_plan_size; + int m_data_size; + int* m_node_num; + int m_consumer_data_size; /* the number of datanode that has consumer info */ + bool m_query_mem_mode; + PlanTableMultiData** m_plan_table; + int m_plan_node_num; + bool m_pred_time; + bool m_pred_row; + bool m_pred_mem; + +private: + Datum** m_data; + bool** m_isnull; + MultiInfo*** m_multi_info; + int2 m_col_loc[SLOT_NUMBER]; + + void init_planinfo(int plansize); + void init_multi_info(ExplainState* es, int plansize, int num_nodes); + /* init the data of MultiInfo. */ + void init_multi_info_data(MultiInfo* multi_info, int dop); + + /* For explain plan: init the data of plan_table. */ + void init_plan_table_data(int num_plan_nodes); + + TupleDesc getTupleDesc(); + TupleDesc getTupleDesc(const char* attname); + TupleDesc getTupleDesc_detail(); + + void flush_plan(TupOutputState* tstate); + void flush_other(TupOutputState* tstate); + void set_pname(char* data); +}; + +class PlanInformation : public BaseObject { +public: + void init(ExplainState* es, int size, int num_nodes, bool quey_mem_mode); + + void dump(DestReceiver* dest) + { + if (m_runtimeinfo && t_thrd.explain_cxt.explain_perf_mode == EXPLAIN_RUN) + dump_runtimeinfo_file(); + if (m_planInfo) + m_planInfo->flush(dest, PLANINFO); + if (m_detailInfo) + m_detailInfo->flush(dest, DETAILINFO); + if (m_staticInfo) + m_staticInfo->flush(dest, STATICINFO); + if (m_verboseInfo) + m_verboseInfo->flush(dest, VERBOSEINFO); + if (m_datanodeInfo && m_runtimeinfo) + m_datanodeInfo->flush(dest, DATANODEINFO); + if (m_IOInfo) + m_IOInfo->flush(dest, IOINFO); + if (m_recursiveInfo) + m_recursiveInfo->flush(dest, RECURSIVEINFO); + if (m_profileInfo) + m_profileInfo->flush(dest, PROFILEINFO); + if (m_query_summary) + m_query_summary->flush(dest, QUERYSUMMARY); + } + + int print_plan(Portal portal, DestReceiver* dest); + + void set_id(int plan_id) + { + if (m_planInfo) + m_planInfo->set(plan_id); + if (m_detailInfo) + m_detailInfo->set(plan_id); + if (m_staticInfo) + m_staticInfo->set(plan_id); + if (m_verboseInfo) + m_verboseInfo->set(plan_id); + if (m_datanodeInfo) + m_datanodeInfo->set(plan_id); + if (m_IOInfo) + m_IOInfo->set(plan_id); + if (m_recursiveInfo) + m_recursiveInfo->set(plan_id); + if (m_query_summary) + m_query_summary->set(plan_id); + } + + void set_pname(char* data) + { + if (m_planInfo) + m_planInfo->set_pname(data); + if (m_detailInfo) + m_detailInfo->set_pname(data); + if (m_staticInfo) + m_staticInfo->set_pname(data); + if (m_verboseInfo) + m_verboseInfo->set_pname(data); + if (m_datanodeInfo) + m_datanodeInfo->set_pname(data); + if (m_IOInfo) + m_IOInfo->set_pname(data); + if (m_recursiveInfo) + m_recursiveInfo->set_pname(data); + if (m_query_summary) + m_query_summary->set_pname(data); + } + + void append_str_info(const char* data, int id, const char* value); + + PlanTable* m_planInfo; + PlanTable* m_detailInfo; + PlanTable* m_staticInfo; + PlanTable* m_verboseInfo; + PlanTable* m_datanodeInfo; + PlanTable* m_IOInfo; + PlanTable* m_profileInfo; + PlanTable* m_query_summary; + PlanTable* m_recursiveInfo; + + /* For explain plan */ + PlanTable* m_planTableData; + + int m_count; + PlanTable* m_runtimeinfo; + bool m_detail; + int m_query_id; + +private: + void dump_runtimeinfo_file(); + void flush_runtime_info(DestReceiver* dest); + void flush_summary_info(DestReceiver* dest); + void flush_memory_info(DestReceiver* dest); + + void write_datanode(); + void append_time_info(int node_idx, int plan_idx, bool from_datanode); + void append_cpu_info(int node_idx, int plan_idx, bool from_datanode); + void append_buffer_info(int node_idx, int plan_idx, bool from_datanode); + void append_roughcheck_info(int node_idx, int plan_idx, bool from_datanode); + void append_llvm_info(int node_idx, int plan_idx, bool from_datanode); + void append_bloomfilter_info(int node_idx, int plan_idx, bool from_datanode); + void append_dfs_block_info(int node_idx, int plan_idx, bool from_datanode); + + void write_memory(); + void append_peak_memory_info(int node_idx, int plan_idx, bool from_datanode); + void append_memory_info(int node_idx, int plan_idx, bool from_datanode); + void append_network_info(int node_idx, int plan_idx); + void append_sort_info(int node_idx, int plan_idx, bool from_datanode); + void append_filenum_info(int node_idx, int plan_idx, bool from_datanode); + void append_hash_info(int node_idx, int plan_idx, bool from_datanode); + void append_vechash_info(int node_idx, int plan_idx, bool from_datanode); + + void free_memory(); +}; + +typedef struct DN_RunInfo { + bool all_datanodes; + int len_nodelist; + int* node_index; +} DN_RunInfo; + +typedef struct ExplainState { + StringInfo str; /* output buffer */ + /* options */ + bool plan; /* do not print plan */ + bool verbose; /* be verbose */ + bool analyze; /* print actual times */ + bool costs; /* print costs */ + bool buffers; /* print buffer usage */ +#ifdef PGXC + bool nodes; /* print nodes in RemoteQuery node */ + bool num_nodes; /* print number of nodes in RemoteQuery node */ +#endif /* PGXC */ + bool timing; /* print timing */ + bool cpu; + bool detail; + bool performance; + bool from_dn; + bool sql_execute; + bool isexplain_execute; /* is explain execute statement */ + ExplainFormat format; /* output format */ + /* other states */ + PlannedStmt* pstmt; /* top of plan */ + List* rtable; /* range table */ + int indent; /* current indentation level */ + int pindent; + List* grouping_stack; /* format-specific grouping state */ + PlanInformation* planinfo; + DN_RunInfo datanodeinfo; + int* wlm_statistics_plan_max_digit; /* print plan for wlm statistics */ + char* statement_id; /* statement_id for EXPLAIN PLAN */ + bool is_explain_gplan; + char* opt_model_name; +} ExplainState; + +/* Hook for plugins to get control in explain_get_index_name() */ +typedef const char *(*explain_get_index_name_hook_type) (Oid indexId); +extern THR_LOCAL PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook; + +extern void ExplainQuery( + ExplainStmt* stmt, const char* queryString, ParamListInfo params, DestReceiver* dest, char* completionTag); + +extern void ExplainInitState(ExplainState* es); + +extern TupleDesc ExplainResultDesc(ExplainStmt* stmt); + +extern void ExplainOneUtility( + Node* utilityStmt, IntoClause* into, ExplainState* es, const char* queryString, ParamListInfo params); + +extern void ExplainOnePlan( + PlannedStmt* plannedstmt, IntoClause* into, ExplainState* es, const char* queryString, + DestReceiver *dest, ParamListInfo params); + +extern void ExplainPrintPlan(ExplainState* es, QueryDesc* queryDesc); + +extern void ExplainQueryText(ExplainState* es, QueryDesc* queryDesc); + +extern void ExplainOneQueryForStatistics(QueryDesc* queryDesc); + +extern void ExplainBeginOutput(ExplainState* es); +extern void ExplainEndOutput(ExplainState* es); +extern void ExplainSeparatePlans(ExplainState* es); + +extern void ExplainPropertyList(const char* qlabel, List* data, ExplainState* es); +extern void ExplainPropertyText(const char* qlabel, const char* value, ExplainState* es); +extern void ExplainPropertyInteger(const char* qlabel, int value, ExplainState* es); +extern void ExplainPropertyLong(const char* qlabel, long value, ExplainState* es); +extern void ExplainPropertyFloat(const char* qlabel, double value, int ndigits, ExplainState* es); + +extern int get_track_time(ExplainState* es, PlanState* planstate, bool show_track, bool show_buffer, + bool show_dummygroup, bool show_indexinfo, bool show_storage_info = false); + +extern void ExplainPropertyListNested(const char* qlabel, List* data, ExplainState* es); +extern List* set_deparse_context_planstate(List* dpcontext, Node* planstate, List* ancestors); +extern double elapsed_time(instr_time* starttime); +extern void print_explain_info(StreamInstrumentation* instrumentdata, QueryDesc* querydesc, ExplainState* es); +extern bool checkSelectStmtForPlanTable(List* rangeTable); +extern int checkPermsForPlanTable(RangeTblEntry* rte); + +#endif /* EXPLAIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/extension.h postgresql-hll-2.14/include/include/commands/extension.h --- postgresql-hll-2.14_old/include/include/commands/extension.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/extension.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * extension.h + * Extension management commands (create/drop extension). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/extension.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXTENSION_H +#define EXTENSION_H + +#include "nodes/parsenodes.h" + +/* + * creating_extension is only true while running a CREATE EXTENSION command. + * It instructs recordDependencyOnCurrentExtension() to register a dependency + * on the current pg_extension object for each SQL object created by its + * installation script. + */ +extern THR_LOCAL bool creating_extension; + +extern void CreateExtension(CreateExtensionStmt* stmt); + +extern void RemoveExtensionById(Oid extId); + +extern Oid InsertExtensionTuple(const char* extName, Oid extOwner, Oid schemaOid, bool relocatable, + const char* extVersion, Datum extConfig, Datum extCondition, List* requiredExtensions); + +extern void ExecAlterExtensionStmt(AlterExtensionStmt* stmt); + +extern void ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt* stmt); + +extern Oid get_extension_oid(const char* extname, bool missing_ok); +extern char* get_extension_name(Oid ext_oid); + +extern void AlterExtensionNamespace(List* names, const char* newschema); + +extern void AlterExtensionOwner_oid(Oid extensionOid, Oid newOwnerId); + +#endif /* EXTENSION_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/formatter.h postgresql-hll-2.14/include/include/commands/formatter.h --- postgresql-hll-2.14_old/include/include/commands/formatter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/formatter.h 2020-12-12 17:06:43.180347174 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * formatter.h + * + * + * + * IDENTIFICATION + * src/include/commands/formatter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef FORMATTER_H_ +#define FORMATTER_H_ + +#include "c.h" +#include "nodes/pg_list.h" +#include "bulkload/utils.h" + +typedef enum { ALIGN_INVALID, ALIGN_LEFT, ALIGN_RIGHT } FieldAlign; + +struct FieldDesc { + char* fieldname; + char* nullString; + int fieldPos; + int fieldSize; + int attnum; + FieldAlign align; +}; + +struct Formatter { + FileFormat format; + int nfield; +}; + +struct FixFormatter : public Formatter { + int lineSize; + FieldDesc* fieldDesc; + bool forceLineSize; +}; + +#endif /* FORMATTER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/commands/gds_stream.h postgresql-hll-2.14/include/include/commands/gds_stream.h --- postgresql-hll-2.14_old/include/include/commands/gds_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/gds_stream.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gds_stream.h + * + * + * + * IDENTIFICATION + * src/include/commands/gds_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GDS_STREAM_H +#define GDS_STREAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "bulkload/utils.h" +#include "ssl/gs_openssl_client.h" + +/* + * Bulkload base class + */ +class BulkLoadStream : public BaseObject { +public: + /* Bulkload stream close */ + virtual void Close() = 0; + + /* Bulkload stream read */ + virtual int Read() = 0; + + virtual int InternalRead() = 0; + + virtual int ReadMessage(StringInfoData& dst) = 0; + + /* Bulkload stream write */ + virtual int Write(void* src, Size len) = 0; + + virtual void Flush() = 0; + + virtual void VerifyAddr() = 0; +}; + +class GDSUri : public BaseObject { +public: + GDSUri() + { + m_uri = NULL; + m_protocol = NULL; + m_host = NULL; + m_port = -1; + m_path = NULL; + } + + ~GDSUri() + { + if (m_uri) + pfree(m_uri); + if (m_protocol) + pfree(m_protocol); + if (m_host) + pfree(m_host); + if (m_path) + pfree(m_path); + } + + void Parse(const char* uri); + + const char* ToString() + { + return m_uri; + } + + static void Trim(char* str); + + char* m_uri; + char* m_protocol; + char* m_host; + int m_port; + char* m_path; +}; + +class GDSStream : public BulkLoadStream { +public: + GDSStream(); + + virtual ~GDSStream(); + + void Initialize(const char* uri); + + void Close(); + + int Read(); + + int ReadMessage(StringInfoData& dst); + + int Write(void* src, Size len); + + void Flush(); + + void VerifyAddr(); + + GDSUri* m_uri; + int m_fd; + bool m_ssl_enable; + gs_openssl_cli m_ssl; + StringInfo m_inBuf; + StringInfo m_outBuf; + +private: + /* function type pointer defination */ + typedef int (GDSStream::*readfun)(void); + readfun m_read; + + void PrepareReadBuf(void); + int InternalRead(void); + int InternalReadSSL(void); + + void InitSSL(void); +}; + +extern void SerializeCmd(CmdBase* cmd, StringInfo buf); +extern CmdBase* DeserializeCmd(StringInfo buf); +extern void PackData(StringInfo data, StringInfo dst); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/commands/lockcmds.h postgresql-hll-2.14/include/include/commands/lockcmds.h --- postgresql-hll-2.14_old/include/include/commands/lockcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/lockcmds.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * lockcmds.h + * prototypes for lockcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/lockcmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCKCMDS_H +#define LOCKCMDS_H + +#include "nodes/parsenodes.h" + +/* + * LOCK + */ +extern void LockTableCommand(LockStmt* lockstmt); + +#endif /* LOCKCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/matview.h postgresql-hll-2.14/include/include/commands/matview.h --- postgresql-hll-2.14_old/include/include/commands/matview.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/matview.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,76 @@ +/*------------------------------------------------------------------------- + * + * matview.h + * prototypes for matview.c. + * + * src/include/commands/matview.h + * + * ------------------------------------------------------------------------ + */ +#ifndef MATVIEW_H +#define MATVIEW_H + +#include "nodes/params.h" +#include "tcop/dest.h" +#include "utils/relcache.h" + +#define MlogAttributeNum 5 + +#define MlogAttributeAction 1 +#define MlogAttributeTime 2 +#define MlogAttributeCtid 3 +#define MlogAttributeXid 4 +#define MlogAttributeSeqno 5 + +#define MatMapAttributeNum 5 +#define MatMapAttributeMatid 1 +#define MatMapAttributeMatctid 2 +#define MatMapAttributeRelid 3 +#define MatMapAttributeRelctid 4 +#define MatMapAttributeRelxid 5 + +#define ActionCreateMat 1 +#define ActionRefreshInc 2 + +/* used to blocking ANALYZE */ +#define MLOGLEN 5 +#define MATMAPLEN 11 +#define MATMAPNAME "matviewmap_" +#define MLOGNAME "mlog_" + +#define ISMATMAP(relname) (strncmp(relname, MATMAPNAME, MATMAPLEN) == 0) +#define ISMLOG(relname) (strncmp(relname, MLOGNAME, MLOGLEN) == 0) + +extern Size MatviewShmemSize(void); +extern void MatviewShmemInit(void); + +extern void SetRelationIsScannable(Relation relation); + +extern void ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); + +extern void ExecRefreshMatViewInc(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); +extern void ExecCreateMatViewInc(CreateTableAsStmt* stmt, const char* queryString, ParamListInfo params); +extern void ExecRefreshMatViewAll(RefreshMatViewStmt *stmt, const char *queryString, + ParamListInfo params, char *completionTag); + +extern DestReceiver *CreateTransientRelDestReceiver(Oid oid); + +extern void build_matview_dependency(Oid matviewOid, Relation materRel); +extern Oid create_matview_map(Oid intoRelationId); +extern void insert_into_matview_map(Oid mapid, Oid matid, ItemPointer matcitd, + Oid relid, ItemPointer relctid, TransactionId xid); +extern Oid find_matview_mlog_table(Oid relid); +extern void insert_into_mlog_table(Relation rel, Oid mlogid, HeapTuple tuple, + ItemPointer tid, TransactionId xid, char action); +extern void create_matview_meta(Query *query, RangeVar *rel, bool incremental); + +extern void check_matview_op_supported(CreateTableAsStmt *ctas); +extern DistributeBy *infer_incmatview_distkey(CreateTableAsStmt *stmt); +extern void check_basetable(Query *query); +extern bool isIncMatView(RangeVar *rv); +extern void MatviewShmemSetInvalid(); +extern void acquire_mativew_tables_lock(Relation matview, bool incremental); + +#endif /* MATVIEW_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/obs_stream.h postgresql-hll-2.14/include/include/commands/obs_stream.h --- postgresql-hll-2.14_old/include/include/commands/obs_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/obs_stream.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,97 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * obs_stream.h + * + * + * + * IDENTIFICATION + * src/include/commands/obs_stream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OBS_STREAM_H +#define OBS_STREAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "bulkload/utils.h" +#include "storage/parser.h" +#include "commands/copy.h" +#include "commands/gds_stream.h" +#include "storage/buffile.h" + +class OBSStream : public BulkLoadStream { +public: + /* Constructor & De-constructor */ + OBSStream(FileFormat format, bool is_write); + virtual ~OBSStream(); + + /* Routines inherited from interface */ + void Initialize(const char* uri, CopyState cstate); + + void Close(); /* virtual function */ + + int Read(); /* virtual function */ + + int InternalRead(); /* virtual function */ + + int ReadMessage(StringInfoData& dst); /* virtual function */ + + int Write(void* src, Size len); /* virtual function */ + + void Flush(); /* virtual function */ + + void VerifyAddr(); + + /* Getter & Setter */ + inline GDS::Parser* GetOBSParser() + { + Assert(m_parser != NULL); + return this->m_parser; + }; + + void set_parser_chunksize(uint32_t chunksize); + void set_source_obs_copy_options(ObsCopyOptions* options); + + const ObsCopyOptions* get_obs_copy_options(void); + void set_obs_copy_options(ObsCopyOptions* options); + + const char* StartNewSegment(void); + +private: + FileList m_filelist; + + /* Parser to handle OBS objects */ + GDS::Parser* m_parser; + + /* OBS object realted variables */ + string m_url; + char* m_hostname; + char* m_bucket; + char* m_prefix; + + /* writer specific */ + bool m_write; + BufFile* m_buffile; + StringInfo m_cur_segment; + size_t m_cur_segment_offset; + int m_cur_segment_num; + + ObsCopyOptions* m_obs_options; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/commands/portalcmds.h postgresql-hll-2.14/include/include/commands/portalcmds.h --- postgresql-hll-2.14_old/include/include/commands/portalcmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/portalcmds.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * portalcmds.h + * prototypes for portalcmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/portalcmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PORTALCMDS_H +#define PORTALCMDS_H + +#include "nodes/parsenodes.h" +#include "utils/portal.h" + +extern void PerformCursorOpen(PlannedStmt* stmt, ParamListInfo params, const char* queryString, bool isTopLevel); + +extern void PerformPortalFetch(FetchStmt* stmt, DestReceiver* dest, char* completionTag); + +extern void PerformPortalClose(const char* name); + +extern void PortalCleanup(Portal portal); + +extern void PersistHoldablePortal(Portal portal); + +#endif /* PORTALCMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/prepare.h postgresql-hll-2.14/include/include/commands/prepare.h --- postgresql-hll-2.14_old/include/include/commands/prepare.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/prepare.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------------- + * + * prepare.h + * PREPARE, EXECUTE and DEALLOCATE commands, and prepared-stmt storage + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/commands/prepare.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREPARE_H +#define PREPARE_H + +#include "commands/explain.h" +#include "utils/globalplancache.h" +#include "utils/plancache.h" + +#ifdef PGXC +typedef struct DatanodeStatement { + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + int current_nodes_number; /* number of nodes where statement is active */ + int max_nodes_number; /* maximum number of nodes where statement is active */ + int* dns_node_indices; /* node ids where statement is active */ + instr_time* last_used_time; /* for gpc, save time when use this statement to send msg to dn */ +} DatanodeStatement; +#endif + +#define NEED_SEND_PARSE_AGAIN(last_used_time, cur_time) \ + (INSTR_TIME_GET_DOUBLE(cur_time) - INSTR_TIME_GET_DOUBLE(last_used_time)) > ((double)MAX_PREPARE_WAIING_TIME / 2) + +/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */ +extern void PrepareQuery(PrepareStmt* stmt, const char* queryString); +extern void ExecuteQuery(ExecuteStmt* stmt, IntoClause* intoClause, const char* queryString, ParamListInfo params, + DestReceiver* dest, char* completionTag); +extern void DeallocateQuery(DeallocateStmt* stmt); +extern void ExplainExecuteQuery( + ExecuteStmt* execstmt, IntoClause* into, ExplainState* es, const char* queryString, ParamListInfo params); + +/* Low-level access to stored prepared statements */ +extern void StorePreparedStatementCNGPC(const char *stmt_name, CachedPlanSource *plansource, + bool from_sql, bool is_share); +extern void StorePreparedStatement(const char* stmt_name, CachedPlanSource* plansource, bool from_sql); +extern PreparedStatement* FetchPreparedStatement(const char* stmt_name, bool throwError, bool need_valid); +extern void DropPreparedStatement(const char* stmt_name, bool showError); +extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt); +extern List* FetchPreparedStatementTargetList(PreparedStatement *stmt); + +extern void DropAllPreparedStatements(void); +extern void HandlePreparedStatementsForReload(void); +extern void HandlePreparedStatementsForRetry(void); +extern bool HaveActiveCoordinatorPreparedStatement(const char* stmt_name); + +#ifdef PGXC +extern DatanodeStatement* FetchDatanodeStatement(const char* stmt_name, bool throwError); +extern bool ActivateDatanodeStatementOnNode(const char* stmt_name, int noid); +extern void DeActiveAllDataNodeStatements(void); +extern bool HaveActiveDatanodeStatements(void); +extern void DropDatanodeStatement(const char* stmt_name); +extern int SetRemoteStatementName(Plan* plan, const char* stmt_name, int num_params, Oid* param_types, int n, + bool isBuildingCustomPlan, bool is_plan_shared = false); +extern char* get_datanode_statement_name(const char* stmt_name, int n); +#endif +extern bool needRecompileQuery(ExecuteStmt* stmt); +extern void RePrepareQuery(ExecuteStmt* stmt); +extern bool checkRecompileCondition(CachedPlanSource* plansource); + +extern void GetRemoteQuery(PlannedStmt* stmt, const char* queryString); +extern void GetRemoteQueryWalker(Plan* plan, void* context, const char* queryString); +extern void PlanTreeWalker( + Plan* plan, void (*walker)(Plan*, void*, const char*), void* context, const char* queryString); + +extern DatanodeStatement* light_set_datanode_queries(const char* stmt_name); +#endif /* PREPARE_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/proclang.h postgresql-hll-2.14/include/include/commands/proclang.h --- postgresql-hll-2.14_old/include/include/commands/proclang.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/proclang.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,25 @@ +/* + * src/include/commands/proclang.h + * + * ------------------------------------------------------------------------- + * + * proclang.h + * prototypes for proclang.c. + * + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCLANG_H +#define PROCLANG_H + +#include "nodes/parsenodes.h" + +extern void CreateProceduralLanguage(CreatePLangStmt* stmt); +extern void DropProceduralLanguageById(Oid langOid); +extern void RenameLanguage(const char* oldname, const char* newname); +extern void AlterLanguageOwner(const char* name, Oid newOwnerId); +extern void AlterLanguageOwner_oid(Oid oid, Oid newOwnerId); +extern bool PLTemplateExists(const char* languageName); +extern Oid get_language_oid(const char* langname, bool missing_ok); + +#endif /* PROCLANG_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/schemacmds.h postgresql-hll-2.14/include/include/commands/schemacmds.h --- postgresql-hll-2.14_old/include/include/commands/schemacmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/schemacmds.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * schemacmds.h + * prototypes for schemacmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/schemacmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCHEMACMDS_H +#define SCHEMACMDS_H + +#include "nodes/parsenodes.h" + +#ifdef PGXC +extern void CreateSchemaCommand(CreateSchemaStmt* parsetree, const char* queryString, bool is_top_level); +#else +extern void CreateSchemaCommand(CreateSchemaStmt* parsetree, const char* queryString); +#endif +extern void RemoveSchemaById(Oid schemaOid); + +extern void RenameSchema(const char* oldname, const char* newname); +extern void AlterSchemaOwner(const char* name, Oid newOwnerId); +extern void AlterSchemaOwner_oid(Oid schemaOid, Oid newOwnerId); + +#endif /* SCHEMACMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/seclabel.h postgresql-hll-2.14/include/include/commands/seclabel.h --- postgresql-hll-2.14_old/include/include/commands/seclabel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/seclabel.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,30 @@ +/* + * seclabel.h + * + * Prototypes for functions in commands/seclabel.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + */ +#ifndef SECLABEL_H +#define SECLABEL_H + +#include "catalog/objectaddress.h" + +/* + * Internal APIs + */ +extern char* GetSecurityLabel(const ObjectAddress* object, const char* provider); +extern void SetSecurityLabel(const ObjectAddress* object, const char* provider, const char* label); +extern void DeleteSecurityLabel(const ObjectAddress* object); +extern void DeleteSharedSecurityLabel(Oid objectId, Oid classId); + +/* + * Statement and ESP hook support + */ +extern void ExecSecLabelStmt(SecLabelStmt* stmt); + +typedef void (*check_object_relabel_type)(const ObjectAddress* object, const char* seclabel); +extern void register_label_provider(const char* provider, check_object_relabel_type hook); + +#endif /* SECLABEL_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/sec_rls_cmds.h postgresql-hll-2.14/include/include/commands/sec_rls_cmds.h --- postgresql-hll-2.14_old/include/include/commands/sec_rls_cmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/sec_rls_cmds.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * sec_rls_cmds.h + * Security Module. + * Variables and function commands used in Row Level Security Policy. + * + * + * IDENTIFICATION + * src/include/commands/sec_rls_cmds.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_RLS_CMDS_H +#define SEC_RLS_CMDS_H + +#include "nodes/parsenodes.h" + +extern void CreateRlsPolicy(CreateRlsPolicyStmt* stmt); +extern void AlterRlsPolicy(AlterRlsPolicyStmt* stmt); +extern void RenameRlsPolicy(RenameStmt* stmt); +extern void RemoveRlsPolicyById(Oid rlsPolicyOid); +extern bool RemoveRoleFromRlsPolicy(Oid roleid, Oid rlsrelid, Oid rlspolicyid); +extern void RelationBuildRlsPolicies(Relation relation); +extern Oid get_rlspolicy_oid(Oid relid, const char* policy_name, bool missing_ok); +extern bool RelationHasRlspolicy(Oid relid); +extern void CreateRlsPolicyForSystem( + char* schemaName, char* relName, char* policyName, char* funcName, char* relColname, char* privType); + +#endif /* SEC_RLS_CMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/sequence.h postgresql-hll-2.14/include/include/commands/sequence.h --- postgresql-hll-2.14_old/include/include/commands/sequence.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/sequence.h 2020-12-12 17:06:43.181347187 +0800 @@ -0,0 +1,166 @@ +/* ------------------------------------------------------------------------- + * + * sequence.h + * prototypes for sequence.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/sequence.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SEQUENCE_H +#define SEQUENCE_H + +#include "access/xlogreader.h" +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "storage/relfilenode.h" + +#ifdef PGXC +#include "utils/relcache.h" +#include "gtm/gtm_c.h" +#include "access/xact.h" +#include "optimizer/streamplan.h" +#include "pgxc/pgxcnode.h" +#include "tcop/utility.h" +#endif + +#define INVALIDSEQUUID 0 + +// extern THR_LOCAL char *PGXCNodeName; + +typedef int64 GTM_UUID; + +typedef struct FormData_pg_sequence { + NameData sequence_name; + int64 last_value; + int64 start_value; + int64 increment_by; + int64 max_value; + int64 min_value; + int64 cache_value; + int64 log_cnt; + bool is_cycled; + bool is_called; + GTM_UUID uuid; +} FormData_pg_sequence; + +typedef FormData_pg_sequence* Form_pg_sequence; + +/* + * Columns of a sequence relation + */ + +#define SEQ_COL_NAME 1 +#define SEQ_COL_LASTVAL 2 +#define SEQ_COL_STARTVAL 3 +#define SEQ_COL_INCBY 4 +#define SEQ_COL_MAXVALUE 5 +#define SEQ_COL_MINVALUE 6 +#define SEQ_COL_CACHE 7 +#define SEQ_COL_LOG 8 +#define SEQ_COL_CYCLE 9 +#define SEQ_COL_CALLED 10 +#define SEQ_COL_UUID 11 + +#define SEQ_COL_FIRSTCOL SEQ_COL_NAME +#define SEQ_COL_LASTCOL SEQ_COL_UUID + +/* XLOG stuff */ +#define XLOG_SEQ_LOG 0x00 + +/* + * The "special area" of a sequence's buffer page looks like this. + */ +#define SEQ_MAGIC 0x1717 + +typedef struct xl_seq_rec { + RelFileNodeOld node; + /* SEQUENCE TUPLE DATA FOLLOWS AT THE END */ +} xl_seq_rec; + +/* + * We don't want to log each fetching of a value from a sequence, + * so we pre-log a few fetches in advance. In the event of + * crash we can lose (skip over) as many values as we pre-logged. + */ +#define SEQ_LOG_VALS 32 + + +/* + * The "special area" of a old version sequence's buffer page looks like this. + */ + +typedef struct sequence_magic { + uint32 magic; +} sequence_magic; + + +extern Datum nextval(PG_FUNCTION_ARGS); +extern Datum nextval_oid(PG_FUNCTION_ARGS); +extern Datum currval_oid(PG_FUNCTION_ARGS); +extern Datum setval_oid(PG_FUNCTION_ARGS); +extern Datum setval3_oid(PG_FUNCTION_ARGS); +extern Datum lastval(PG_FUNCTION_ARGS); + +extern Datum pg_sequence_parameters(PG_FUNCTION_ARGS); + +extern void DefineSequence(CreateSeqStmt* stmt); +extern void AlterSequence(AlterSeqStmt* stmt); +extern void PreventAlterSeqInTransaction(bool isTopLevel, AlterSeqStmt* stmt); +extern void ResetSequence(Oid seq_relid); + +extern void seq_redo(XLogReaderState* rptr); +extern void seq_desc(StringInfo buf, XLogReaderState* record); +extern GTM_UUID get_uuid_from_rel(Relation rel); +extern void lockNextvalOnCn(Oid relid); + +extern void get_sequence_params(Relation rel, int64* uuid, int64* start, int64* increment, int64* maxvalue, + int64* minvalue, int64* cache, bool* cycle); + +#ifdef PGXC +/* + * List of actions that registered the callback. + * This is listed here and not in sequence.c because callback can also + * be registered in dependency.c and tablecmds.c as sequences can be dropped + * or renamed in cascade. + */ +typedef enum { GTM_CREATE_SEQ, GTM_DROP_SEQ } GTM_SequenceDropType; +/* + * Arguments for callback of sequence drop on GTM + */ +typedef struct drop_sequence_callback_arg { + GTM_UUID seq_uuid; + GTM_SequenceDropType type; + GTM_SequenceKeyType key; +} drop_sequence_callback_arg; + +/* + * Arguments for callback of sequence rename on GTM + */ +typedef struct rename_sequence_callback_arg { + char* newseqname; + char* oldseqname; +} rename_sequence_callback_arg; + +extern void delete_global_seq(Oid relid, Relation seqrel); +/* Sequence callbacks on GTM */ +extern void register_sequence_rename_cb(const char* oldseqname, const char* newseqname); +extern void rename_sequence_cb(GTMEvent event, void* args); +extern void register_sequence_cb(GTM_UUID seq_uuid, GTM_SequenceDropType type); +extern void drop_sequence_cb(GTMEvent event, void* args); + +extern bool IsTempSequence(Oid relid); +extern char* GetGlobalSeqName(Relation rel, const char* new_seqname, const char* new_schemaname); +extern char* gen_hybirdmsg_for_CreateSeqStmt(CreateSeqStmt* stmt, const char* queryString); +extern int64 gen_uuid(List* uuids); +extern char* gen_hybirdmsg_for_CreateSchemaStmt(CreateSchemaStmt* stmt, const char* queryString); +extern void gen_uuid_for_CreateStmt(CreateStmt* stmt, List* uuids); +extern void gen_uuid_for_CreateSchemaStmt(List* stmts, List* uuids); + +#endif + +#endif /* SEQUENCE_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/shutdown.h postgresql-hll-2.14/include/include/commands/shutdown.h --- postgresql-hll-2.14_old/include/include/commands/shutdown.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/shutdown.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,19 @@ +/* ------------------------------------------------------------------------- + * + * shutdown.h + * prototypes for shutdown.cpp + * + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * src/include/commands/shutdown.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SHUTDOWN_H +#define SHUTDOWN_H + +#include "nodes/parsenodes.h" + +extern void DoShutdown(ShutdownStmt* stmt); + +#endif /* SHUTDOWN_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/tablecmds.h postgresql-hll-2.14/include/include/commands/tablecmds.h --- postgresql-hll-2.14_old/include/include/commands/tablecmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/tablecmds.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * tablecmds.h + * prototypes for tablecmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablecmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TABLECMDS_H +#define TABLECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "rewrite/rewriteRlsPolicy.h" +#include "storage/lock.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" + +#define MAX_MERGE_PARTITIONS 300 +#define ATT_DEFAULT_LEN 128 + +#define FOREIGNTABLE_SUPPORT_AT_CMD(cmd) \ + ((cmd) == AT_ChangeOwner || (cmd) == AT_AddNodeList || (cmd) == AT_SubCluster || (cmd) == AT_DeleteNodeList || \ + (cmd) == AT_GenericOptions) + +#define DIST_OBS_SUPPORT_AT_CMD(cmd) \ + ((cmd) == AT_ChangeOwner || (cmd) == AT_AddNodeList || (cmd) == AT_DeleteNodeList || (cmd) == AT_SubCluster || \ + (cmd) == AT_GenericOptions || (cmd) == AT_DropNotNull || (cmd) == AT_SetNotNull || \ + (cmd) == AT_SetStatistics || (cmd) == AT_AlterColumnType || (cmd) == AT_AlterColumnGenericOptions || \ + (cmd) == AT_AddIndex || (cmd) == AT_DropConstraint) + +extern Oid DefineRelation(CreateStmt* stmt, char relkind, Oid ownerId); + +extern void RemoveRelationsonMainExecCN(DropStmt* drop, ObjectAddresses* objects); + +extern bool check_ts_idx_ddl(RangeVar* rel, IndexStmt* stmt = NULL); + +extern void RemoveRelations(DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExecType* exec_type); + +extern void RemoveObjectsonMainExecCN(DropStmt* drop, ObjectAddresses* objects, bool isFirstNode); + +extern ObjectAddresses* PreCheckforRemoveObjects(DropStmt* stmt, StringInfo tmp_queryString, + RemoteQueryExecType* exec_type, bool isFirstNode, bool is_securityadmin = false); + +extern ObjectAddresses* PreCheckforRemoveRelation( + DropStmt* drop, StringInfo tmp_queryString, RemoteQueryExecType* exec_type); + +extern Oid AlterTableLookupRelation(AlterTableStmt* stmt, LOCKMODE lockmode, bool unlock = false); + +extern void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt* stmt); + +extern LOCKMODE AlterTableGetLockLevel(List* cmds); + +extern void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode); + +extern void AlterTableInternal(Oid relid, List* cmds, bool recurse); + +extern void AlterTableNamespace(AlterObjectSchemaStmt* stmt); + +extern void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses* objsMoved); + +extern void AlterRelationNamespaceInternal( + Relation classRel, Oid relOid, Oid oldNspOid, Oid newNspOid, bool hasDependEntry, ObjectAddresses* objsMoved); + +extern void CheckTableNotInUse(Relation rel, const char* stmt); +extern void CheckPartitionNotInUse(Partition part, const char* stmt); +#ifdef PGXC +extern void ExecuteTruncate(TruncateStmt* stmt, const char* sql_statement); +#else +extern void ExecuteTruncate(TruncateStmt* stmt); +#endif + +extern void SetRelationHasSubclass(Oid relationId, bool relhassubclass); + +extern void renameatt(RenameStmt* stmt); + +extern void RenameConstraint(RenameStmt* stmt); + +extern void RenameRelation(RenameStmt* stmt); + +extern void RenameRelationInternal(Oid myrelid, const char* newrelname); + +extern void find_composite_type_dependencies(Oid typeOid, Relation origRelation, const char* origTypeName); + +extern void check_of_type(HeapTuple typetuple); + +extern void register_on_commit_action(Oid relid, OnCommitAction action); +extern void remove_on_commit_action(Oid relid); + +extern void PreCommit_on_commit_actions(void); +extern void AtEOXact_on_commit_actions(bool isCommit); +extern void AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +#ifdef PGXC +extern bool IsTempTable(Oid relid); +extern bool IsRelaionView(Oid relid); +extern bool IsIndexUsingTempTable(Oid relid); +extern bool IsOnCommitActions(void); +extern void DropTableThrowErrorExternal(RangeVar* relation, ObjectType removeType, bool missing_ok); +#endif + +extern void RangeVarCallbackOwnsTable( + const RangeVar* relation, Oid relId, Oid oldRelId, bool target_is_partition, void* arg); +extern void RangeVarCallbackOwnsRelation( + const RangeVar* relation, Oid relId, Oid oldRelId, bool target_is_partition, void* noCatalogs); +extern void checkPartNotInUse(Partition part, const char* stmt); +extern List* transformConstIntoTargetType(Form_pg_attribute* attrs, int2vector* partitionKey, List* boundary); +extern List* transformIntoTargetType(Form_pg_attribute* attrs, int2 pos, List* boundary); + +extern void renamePartitionedTable(Oid partitionedTableOid, const char* partitionedTableNewName); +extern void renamePartition(RenameStmt* stmt); +extern void renamePartitionIndex(RenameStmt* stmt); +extern void renamePartitionInternal(Oid partitionedTableOid, Oid partitionOid, const char* partitionNewName); + +extern Oid addPartitionBySN(Relation rel, int seqnum); +extern Datum caculateBoundary(Datum transpoint, Oid attrtypid, Datum intervalue, Oid intertypid, int seqnum); +extern void ATExecSetIndexUsableState(Oid objclassOid, Oid objOid, bool newState); +extern bool checkPartitionLocalIndexesUsable(Oid partitionOid); +extern bool checkRelationLocalIndexesUsable(Relation relation); +extern List* GetPartitionkeyPos(List* partitionkeys, List* schema); + +extern void ComparePartitionValue(List* pos, Form_pg_attribute* attrs, List *partitionList, bool isPartition = true); +extern void clearAttrInitDefVal(Oid relid); + +extern void AlterDfsCreateTables(Oid relOid, Datum toast_options, CreateStmt* mainTblStmt); +/** + * @Description: Whether judge the column is partition column. + * @in rel, A relation. + * @in att_no, Attribute number. + * @return If the the column is partition column, return true, otherwise return false. + */ +extern bool is_partition_column(Relation rel, AttrNumber att_no); +extern Const* GetPartitionValue(List* pos, Form_pg_attribute* attrs, List* value, bool isinterval, bool isPartition); +extern Node* GetTargetValue(Form_pg_attribute attrs, Const* src, bool isinterval); +extern void ATExecEnableDisableRls(Relation rel, RelationRlsStatus changeType, LOCKMODE lockmode); +extern bool isQueryUsingTempRelation(Query *query); +#ifdef ENABLE_MULTIPLE_NODES +extern void create_part_policy_if_needed(CreateStmt *stmt, Oid relOid); +void delete_ts_aux_table(Node* parsetree, const char* query_string); +#endif /* ENABLE_MULTIPLE_NODES */ +extern void addToastTableForNewPartition(Relation relation, Oid newPartId); +extern void fastDropPartition(Relation rel, Oid partOid, const char* stmt, Oid intervalPartOid = InvalidOid); +#endif /* TABLECMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/tablespace.h postgresql-hll-2.14/include/include/commands/tablespace.h --- postgresql-hll-2.14_old/include/include/commands/tablespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/tablespace.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,140 @@ +/* ------------------------------------------------------------------------- + * + * tablespace.h + * Tablespace management commands (create/drop tablespace). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/tablespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TABLESPACE_H +#define TABLESPACE_H + +#include "access/xloginsert.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "storage/dfs/dfs_connector.h" +#include "workload/workload.h" + +/* XLOG stuff */ +#define XLOG_TBLSPC_CREATE 0x00 +#define XLOG_TBLSPC_DROP 0x10 +#define XLOG_TBLSPC_RELATIVE_CREATE 0x20 + +#define TABLESPACE_USAGE_SLOT_NUM 65536U +#define TABLESPACE_BUCKET_CONFLICT_LISTLEN 2 +#define CRITICA_POINT_VALUE 104857600 /* 100 MB */ +#define TABLESPACE_THRESHOLD_RATE 0.9 /* threshold rate */ +#define TABLESPACE_UNLIMITED_STRING "unlimited" +#define PG_LOCATION_DIR "pg_location" + +typedef struct TableSpaceUsageSlot { + uint64 maxSize; + uint64 currentSize; + uint64 thresholdSize; + Oid tableSpaceOid; +} TableSpaceUsageSlot; + +typedef struct TableSpaceUsageBucket { + int count; + slock_t mutex; + TableSpaceUsageSlot spcUsage[TABLESPACE_BUCKET_CONFLICT_LISTLEN]; +} TableSpaceUsageBucket; + +typedef struct TableSpaceUsageStruct { + TableSpaceUsageBucket m_tab[TABLESPACE_USAGE_SLOT_NUM]; +} TableSpaceUsageStruct; + +class TableSpaceUsageManager { +public: + static int ShmemSize(void); + static void Init(void); + static void IsExceedMaxsize(Oid tableSpaceOid, uint64 requestSize); + +private: + static bool IsLimited(Oid tableSpaceOid, uint64* maxSize); + static inline int GetBucketIndex(Oid tableSpaceOid); + static inline void ResetUsageSlot(TableSpaceUsageSlot* info); + static inline void ResetBucket(TableSpaceUsageBucket* bucket); + static inline bool WithinLimit(TableSpaceUsageSlot* slot, uint64 currentSize, uint64 requestSize); + static inline bool IsFull(uint64 maxSize, uint64 currentSize, uint64 requestSize); + static inline uint64 GetThresholdSize(uint64 maxSize, uint64 currentSize); +}; + +typedef struct xl_tblspc_create_rec { + Oid ts_id; + char ts_path[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH STRING */ +} xl_tblspc_create_rec; + +typedef struct xl_tblspc_drop_rec { + Oid ts_id; +} xl_tblspc_drop_rec; + +typedef struct TableSpaceOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ + float8 random_page_cost; + float8 seq_page_cost; + char* filesystem; + char* address; + char* cfgpath; + char* storepath; +} TableSpaceOpts; + +/* This definition is used when storage space is increasing, it includes two main functionalities: + * 1. Check tablespace is exceed the specified size + * 2. Increase the permanent space on users' record + */ +#define STORAGE_SPACE_OPERATION(relation, requestSize) \ + { \ + TableSpaceUsageManager::IsExceedMaxsize(relation->rd_node.spcNode, requestSize); \ + perm_space_increase( \ + relation->rd_rel->relowner, requestSize, RelationUsesSpaceType(relation->rd_rel->relpersistence)); \ + } + +extern void CreateTableSpace(CreateTableSpaceStmt* stmt); +extern void DropTableSpace(DropTableSpaceStmt* stmt); +extern void RenameTableSpace(const char* oldname, const char* newname); +extern void AlterTableSpaceOwner(const char* name, Oid newOwnerId); +extern void AlterTableSpaceOptions(AlterTableSpaceOptionsStmt* stmt); +extern bool IsSpecifiedTblspc(Oid spcOid, const char* specifedTblspc); + +extern void TablespaceCreateDbspace(const RelFileNode rnode, bool isRedo); + +extern Oid GetDefaultTablespace(char relpersistence); +extern DataSpaceType RelationUsesSpaceType(char relpersistence); + +/* + * Get the Specified optioin value. + */ +extern char* GetTablespaceOptionValue(Oid spcNode, const char* optionName); +/* + * Get the all optioin values. + */ +extern List* GetTablespaceOptionValues(Oid spcNode); +/* + * Get the DfsSrvOptions info from pg_tablespace. + */ +extern DfsSrvOptions* GetDfsSrvOptions(Oid spcNode); + +extern void PrepareTempTablespaces(void); + +extern Oid get_tablespace_oid(const char* tablespacename, bool missing_ok); +extern char* get_tablespace_name(Oid spc_oid); + +extern bool directory_is_empty(const char* path); +extern void remove_tablespace_symlink(const char *linkloc); +extern void check_create_dir(char* location); + +extern void tblspc_redo(XLogReaderState* rptr); +extern void tblspc_desc(StringInfo buf, XLogReaderState* record); +extern uint64 pg_cal_tablespace_size_oid(Oid tblspcOid); +extern Oid ConvertToPgclassRelTablespaceOid(Oid tblspc); +extern Oid ConvertToRelfilenodeTblspcOid(Oid tblspc); +extern void xlog_create_tblspc(Oid tsId, char* tsPath, bool isRelativePath); +extern void xlog_drop_tblspc(Oid tsId); + +#endif /* TABLESPACE_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/trigger.h postgresql-hll-2.14/include/include/commands/trigger.h --- postgresql-hll-2.14_old/include/include/commands/trigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/trigger.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,197 @@ +/* ------------------------------------------------------------------------- + * + * trigger.h + * Declarations for trigger handling. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/trigger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TRIGGER_H +#define TRIGGER_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" + +#define InvalidTgOwnerId ((Oid)(-1)) /* An invalid trigger owner oid, for old version pg_trigger */ + +/* + * TriggerData is the node type that is passed as fmgr "context" info + * when a function is called by the trigger manager. + */ + +#define CALLED_AS_TRIGGER(fcinfo) ((fcinfo)->context != NULL && IsA((fcinfo)->context, TriggerData)) + +typedef uint32 TriggerEvent; + +typedef struct TriggerData { + NodeTag type; + TriggerEvent tg_event; + Relation tg_relation; + HeapTuple tg_trigtuple; + HeapTuple tg_newtuple; + Trigger* tg_trigger; + Buffer tg_trigtuplebuf; + Buffer tg_newtuplebuf; +} TriggerData; + +/* + * TriggerEvent bit flags + * + * Note that we assume different event types (INSERT/DELETE/UPDATE/TRUNCATE) + * can't be OR'd together in a single TriggerEvent. This is unlike the + * situation for pg_trigger rows, so pg_trigger.tgtype uses a different + * representation! + */ +#define TRIGGER_EVENT_INSERT 0x00000000 +#define TRIGGER_EVENT_DELETE 0x00000001 +#define TRIGGER_EVENT_UPDATE 0x00000002 +#define TRIGGER_EVENT_TRUNCATE 0x00000003 +#define TRIGGER_EVENT_OPMASK 0x00000003 + +#define TRIGGER_EVENT_ROW 0x00000004 + +#define TRIGGER_EVENT_BEFORE 0x00000008 +#define TRIGGER_EVENT_AFTER 0x00000000 +#define TRIGGER_EVENT_INSTEAD 0x00000010 +#define TRIGGER_EVENT_TIMINGMASK 0x00000018 + +/* More TriggerEvent flags, used only within trigger.c */ + +#define AFTER_TRIGGER_DEFERRABLE 0x00000020 +#define AFTER_TRIGGER_INITDEFERRED 0x00000040 + +#define TRIGGER_FIRED_BY_INSERT(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_INSERT) + +#define TRIGGER_FIRED_BY_DELETE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_DELETE) + +#define TRIGGER_FIRED_BY_UPDATE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_UPDATE) + +#define TRIGGER_FIRED_BY_TRUNCATE(event) (((event)&TRIGGER_EVENT_OPMASK) == TRIGGER_EVENT_TRUNCATE) + +#define TRIGGER_FIRED_FOR_ROW(event) ((event)&TRIGGER_EVENT_ROW) + +#define TRIGGER_FIRED_FOR_STATEMENT(event) (!TRIGGER_FIRED_FOR_ROW(event)) + +#define TRIGGER_FIRED_BEFORE(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_BEFORE) + +#define TRIGGER_FIRED_AFTER(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_AFTER) + +#define TRIGGER_FIRED_INSTEAD(event) (((event)&TRIGGER_EVENT_TIMINGMASK) == TRIGGER_EVENT_INSTEAD) + +/* + * Definitions for replication role based firing. + */ +#define SESSION_REPLICATION_ROLE_ORIGIN 0 +#define SESSION_REPLICATION_ROLE_REPLICA 1 +#define SESSION_REPLICATION_ROLE_LOCAL 2 +extern THR_LOCAL PGDLLIMPORT int SessionReplicationRole; + +/* + * States at which a trigger can be fired. These are the + * possible values for pg_trigger.tgenabled. + */ +#define TRIGGER_FIRES_ON_ORIGIN 'O' +#define TRIGGER_FIRES_ALWAYS 'A' +#define TRIGGER_FIRES_ON_REPLICA 'R' +#define TRIGGER_DISABLED 'D' + +extern Oid CreateTrigger(CreateTrigStmt* stmt, const char* queryString, Oid relOid, Oid refRelOid, Oid constraintOid, + Oid indexOid, bool isInternal); + +extern void RemoveTriggerById(Oid trigOid); +extern Oid get_trigger_oid(Oid relid, const char* name, bool missing_ok); + +extern void renametrig(RenameStmt* stmt); + +extern void EnableDisableTrigger(Relation rel, const char* tgname, char fires_when, bool skip_system); + +extern void RelationBuildTriggers(Relation relation); + +extern TriggerDesc* CopyTriggerDesc(TriggerDesc* trigdesc); + +extern void FreeTriggerDesc(TriggerDesc* trigdesc); + +extern void ExecBSInsertTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASInsertTriggers(EState* estate, ResultRelInfo* relinfo); +extern TupleTableSlot* ExecBRInsertTriggers(EState* estate, ResultRelInfo* relinfo, TupleTableSlot* slot); +extern void ExecARInsertTriggers( + EState* estate, ResultRelInfo* relinfo, Oid insertPartition, int2 bucketid, HeapTuple trigtuple, List* recheckIndexes); +extern TupleTableSlot* ExecIRInsertTriggers(EState* estate, ResultRelInfo* relinfo, TupleTableSlot* slot); +extern void ExecBSDeleteTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASDeleteTriggers(EState* estate, ResultRelInfo* relinfo); +extern bool ExecBRDeleteTriggers(EState* estate, EPQState* epqstate, ResultRelInfo* relinfo, Oid deletePartitionOid, + int2 bucketid, + +#ifdef PGXC + HeapTupleHeader datanode_tuphead, +#endif + ItemPointer tupleid); +extern void ExecARDeleteTriggers(EState* estate, ResultRelInfo* relinfo, Oid deletePartitionOid, int2 bucketid, + +#ifdef PGXC + HeapTupleHeader trigtuphead, +#endif + ItemPointer tupleid); +extern bool ExecIRDeleteTriggers(EState* estate, ResultRelInfo* relinfo, HeapTuple trigtuple); +extern void ExecBSUpdateTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASUpdateTriggers(EState* estate, ResultRelInfo* relinfo); +extern TupleTableSlot* ExecBRUpdateTriggers(EState* estate, EPQState* epqstate, ResultRelInfo* relinfo, + Oid oldPartitionOid, int2 bucketid, +#ifdef PGXC + HeapTupleHeader datanode_tuphead, +#endif + ItemPointer tupleid, TupleTableSlot* slot); +extern void ExecARUpdateTriggers(EState* estate, ResultRelInfo* relinfo, Oid oldPartitionOid, int2 bucketid, Oid newPartitionOid, + ItemPointer tupleid, HeapTuple newtuple, +#ifdef PGXC + HeapTupleHeader trigtuphead, +#endif + List* recheckIndexes); +extern TupleTableSlot* ExecIRUpdateTriggers( + EState* estate, ResultRelInfo* relinfo, HeapTuple trigtuple, TupleTableSlot* slot); +extern void ExecBSTruncateTriggers(EState* estate, ResultRelInfo* relinfo); +extern void ExecASTruncateTriggers(EState* estate, ResultRelInfo* relinfo); + +extern void AfterTriggerBeginXact(void); +extern void AfterTriggerBeginQuery(void); +extern void AfterTriggerEndQuery(EState* estate); +extern void AfterTriggerFireDeferred(void); +extern bool IsAfterTriggerBegin(void); +#ifdef PGXC +extern bool IsAnyAfterTriggerDeferred(void); +#endif +extern void AfterTriggerEndXact(bool isCommit); +extern void AfterTriggerBeginSubXact(void); +extern void AfterTriggerEndSubXact(bool isCommit); +extern void AfterTriggerSetState(ConstraintsSetStmt* stmt); +extern bool AfterTriggerPendingOnRel(Oid relid); + +/* + * in utils/adt/ri_triggers.c + */ +extern bool RI_FKey_keyequal_upd_pk(Trigger* trigger, Relation pk_rel, HeapTuple old_row, HeapTuple new_row); +extern bool RI_FKey_keyequal_upd_fk(Trigger* trigger, Relation fk_rel, HeapTuple old_row, HeapTuple new_row); +extern bool RI_Initial_Check(Trigger* trigger, Relation fk_rel, Relation pk_rel); + +/* result values for RI_FKey_trigger_type: */ +#define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */ +#define RI_TRIGGER_FK 2 /* is a trigger on the FK relation */ +#define RI_TRIGGER_NONE 0 /* is not an RI trigger function */ + +extern int RI_FKey_trigger_type(Oid tgfoid); + +extern Datum pg_trigger_depth(PG_FUNCTION_ARGS); + +#ifdef PGXC +/* Postgres-XC related functions for triggers */ +extern bool pgxc_trig_oldrow_reqd(Relation rel, CmdType commandType); +extern int16 pgxc_get_trigevent(CmdType commandType); +extern bool pgxc_should_exec_br_trigger(Relation rel, int16 trigevent, EState* estate = NULL); +extern bool pgxc_has_trigger_for_event(int16 tg_event, TriggerDesc* trigdesc); +#endif + +#endif /* TRIGGER_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/typecmds.h postgresql-hll-2.14/include/include/commands/typecmds.h --- postgresql-hll-2.14_old/include/include/commands/typecmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/typecmds.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * typecmds.h + * prototypes for typecmds.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/typecmds.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TYPECMDS_H +#define TYPECMDS_H + +#include "access/htup.h" +#include "catalog/dependency.h" +#include "nodes/parsenodes.h" + +#define DEFAULT_TYPDELIM ',' + +extern void DefineType(List* names, List* parameters); +extern void RemoveTypeById(Oid typeOid); +extern void DefineDomain(CreateDomainStmt* stmt); +extern void DefineEnum(CreateEnumStmt* stmt); +extern void DefineRange(CreateRangeStmt* stmt); +extern void AlterEnum(AlterEnumStmt* stmt); +extern Oid DefineCompositeType(RangeVar* typevar, List* coldeflist); +extern Oid AssignTypeArrayOid(void); + +extern void AlterDomainDefault(List* names, Node* defaultRaw); +extern void AlterDomainNotNull(List* names, bool notNull); +extern void AlterDomainAddConstraint(List* names, Node* constr); +extern void AlterDomainValidateConstraint(List* names, char* constrName); +extern void AlterDomainDropConstraint(List* names, const char* constrName, DropBehavior behavior, bool missing_ok); + +extern void checkDomainOwner(HeapTuple tup); + +extern List* GetDomainConstraints(Oid typeOid); + +extern void RenameType(RenameStmt* stmt); +extern void AlterTypeOwner(List* names, Oid newOwnerId, ObjectType objecttype); +extern void AlterTypeOwnerInternal(Oid typeOid, Oid newOwnerId, bool hasDependEntry); +extern void AlterTypeNamespace(List* names, const char* newschema, ObjectType objecttype); +extern Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses* objsMoved); +extern Oid AlterTypeNamespaceInternal( + Oid typeOid, Oid nspOid, bool isImplicitArray, bool errorOnTableType, ObjectAddresses* objsMoved); + +#endif /* TYPECMDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/user.h postgresql-hll-2.14/include/include/commands/user.h --- postgresql-hll-2.14_old/include/include/commands/user.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/user.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,96 @@ +/* ------------------------------------------------------------------------- + * + * user.h + * Commands for manipulating roles (formerly called users). + * + * + * src/include/commands/user.h + * + * ------------------------------------------------------------------------- + */ +#ifndef USER_H +#define USER_H + +#include "nodes/parsenodes.h" +#include "utils/timestamp.h" + +/* Hook to check passwords in CreateRole() and AlterRole() */ +#define PASSWORD_TYPE_PLAINTEXT 0 +#define PASSWORD_TYPE_MD5 1 +typedef struct LockInfoBuck { + Oid pid; + Oid relation; + Oid database; + Oid nspoid; +} LockInfoBuck; + +typedef struct AccountLockHashEntry { + Oid roleoid; + int4 failcount; + TimestampTz locktime; + int2 rolstatus; + slock_t mutex; +} AccountLockHashEntry; + +#define PASSWORD_TYPE_SHA256 2 +#define UNLOCK_FLAG -1 + +/* status of the account */ +typedef enum { UNLOCK_STATUS = 0, LOCK_STATUS, SUPERLOCK_STATUS } USER_STATUS; +typedef enum { UNEXPIRED_STATUS = 0, EXPIRED_STATUS } PASSWORD_STATUS; + +typedef void (*check_password_hook_type)( + const char* username, const char* password, int password_type, Datum validuntil_time, bool validuntil_null); + +extern THR_LOCAL PGDLLIMPORT check_password_hook_type check_password_hook; + +extern void CreateRole(CreateRoleStmt* stmt); +extern void AlterRole(AlterRoleStmt* stmt); +extern void AlterRoleSet(AlterRoleSetStmt* stmt); +extern void DropRole(DropRoleStmt* stmt); +extern void GrantRole(GrantRoleStmt* stmt); +extern void RenameRole(const char* oldname, const char* newname); +extern void DropOwnedObjects(DropOwnedStmt* stmt); +extern void ReassignOwnedObjects(ReassignOwnedStmt* stmt); +extern void TryLockAccount(Oid roleID, int extrafails, bool superlock); +extern bool TryUnlockAccount(Oid roleID, bool superunlock, bool isreset); +void TryUnlockAllAccounts(void); +extern USER_STATUS GetAccountLockedStatus(Oid roleID); +extern void DropUserStatus(Oid roleID); +extern Oid GetRoleOid(const char* username); +extern bool IsRoleExist(const char* username); +bool HasModifiedInitPwdByChkAuthHistory(Oid roleID); +void CheckLockPrivilege(Oid roleID, HeapTuple tuple, bool is_opradmin); +extern bool is_role_persistence(Oid roleid); +void CheckAlterAuditadminPrivilege(Oid roleid, bool isOnlyAlterPassword); +extern char* GetRoleName(Oid rolid, char* rolname, size_t size); +extern char* GetSuperUserName(char* username); +extern int decode_iteration(const char* auth_iteration_string); +extern void initSqlCount(); +extern void initWaitCount(Oid userid); +extern PASSWORD_STATUS GetAccountPasswordExpired(Oid roleID); + +void ReportLockAccountMessage(bool locked, const char *rolename); +bool LockAccountParaValid(Oid roleID, int extrafails, bool superlock); +void UpdateFailCountToHashTable(Oid roleid, int extrafails, bool superlock); +bool UnlockAccountToHashTable(Oid roleid, bool superlock, bool isreset); +int64 SearchAllAccounts(); +void InitAccountLockHashTable(); +extern USER_STATUS GetAccountLockedStatusFromHashTable(Oid roleid); +extern void UpdateAccountInfoFromHashTable(); + + +extern inline void str_reset(char* str) +{ + if (str != NULL) { + memset(str, 0, strlen(str)); + } + + return; +} + +#ifdef PGXC +extern void PreCleanAndCheckUserConns(const char* username, bool missing_ok); +#endif /* PGXC */ + +#endif /* USER_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/vacuum.h postgresql-hll-2.14/include/include/commands/vacuum.h --- postgresql-hll-2.14_old/include/include/commands/vacuum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/vacuum.h 2020-12-12 17:06:43.182347200 +0800 @@ -0,0 +1,431 @@ +/* ------------------------------------------------------------------------- + * + * vacuum.h + * header file for postgres vacuum cleaner and statistics analyzer + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/vacuum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VACUUM_H +#define VACUUM_H +#include "dfsdesc.h" +#include "access/htup.h" +#include "catalog/pg_partition_fn.h" +#include "catalog/pg_statistic.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "storage/buf.h" +#include "storage/cu.h" +#include "storage/lock.h" +#include "utils/relcache.h" + +typedef enum DELETE_STATS_OPTION { + DELETE_STATS_NONE = 0x00u, + DELETE_STATS_SINGLE = 0x01u, + DELETE_STATS_MULTI = 0x02u, + DELETE_STATS_ALL = 0x03u, +} DELETE_STATS_OPTION; + +/* ---------- + * ANALYZE builds one of these structs for each attribute (column) that is + * to be analyzed. The struct and subsidiary data are in anl_context, + * so they live until the end of the ANALYZE operation. + * + * The type-specific typanalyze function is passed a pointer to this struct + * and must return TRUE to continue analysis, FALSE to skip analysis of this + * column. In the TRUE case it must set the compute_stats and minrows fields, + * and can optionally set extra_data to pass additional info to compute_stats. + * minrows is its request for the minimum number of sample rows to be gathered + * (but note this request might not be honored, eg if there are fewer rows + * than that in the table). + * + * The compute_stats routine will be called after sample rows have been + * gathered. Aside from this struct, it is passed: + * fetchfunc: a function for accessing the column values from the + * sample rows + * samplerows: the number of sample tuples + * totalrows: estimated total number of rows in relation + * The fetchfunc may be called with rownum running from 0 to samplerows-1. + * It returns a Datum and an isNull flag. + * + * compute_stats should set stats_valid TRUE if it is able to compute + * any useful statistics. If it does, the remainder of the struct holds + * the information to be stored in a pg_statistic row for the column. Be + * careful to allocate any pointed-to data in anl_context, which will NOT + * be CurrentMemoryContext when compute_stats is called. + * + * Note: for the moment, all comparisons done for statistical purposes + * should use the database's default collation (DEFAULT_COLLATION_OID). + * This might change in some future release. + * ---------- + */ +typedef struct VacAttrStats* VacAttrStatsP; + +typedef Datum (*AnalyzeAttrFetchFunc)(VacAttrStatsP stats, int rownum, bool* isNull, Relation rel); + +typedef void (*AnalyzeAttrComputeStatsFunc)( + VacAttrStatsP stats, AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows, Relation rel); + +typedef struct VacAttrStats { + /* + * These fields are set up by the main ANALYZE code before invoking the + * type-specific typanalyze function. + * + * Note: do not assume that the data being analyzed has the same datatype + * shown in attr, ie do not trust attr->atttypid, attlen, etc. This is + * because some index opclasses store a different type than the underlying + * column/expression. Instead use attrtypid, attrtypmod, and attrtype for + * information about the datatype being fed to the typanalyze function. + */ + unsigned int num_attrs; + Form_pg_attribute* attrs; /* copy of pg_attribute row for columns */ + Oid* attrtypid; /* type of data being analyzed */ + int32* attrtypmod; /* typmod of data being analyzed */ + Form_pg_type* attrtype; /* copy of pg_type row for attrtypid */ + MemoryContext anl_context; /* where to save long-lived data */ + + /* + * These fields must be filled in by the typanalyze routine, unless it + * returns FALSE. + */ + AnalyzeAttrComputeStatsFunc compute_stats; /* function pointer */ + int minrows; /* Minimum # of rows wanted for stats */ + void* extra_data; /* for extra type-specific data */ + + /* + * These fields are to be filled in by the compute_stats routine. (They + * are initialized to zero when the struct is created.) + */ + bool stats_valid; + float4 stanullfrac; /* fraction of entries that are NULL */ + int4 stawidth; /* average width of column values */ + float4 stadistinct; /* # distinct values */ + float4 stadndistinct; /* # distinct value of dn1*/ + int2 stakind[STATISTIC_NUM_SLOTS]; + Oid staop[STATISTIC_NUM_SLOTS]; + int numnumbers[STATISTIC_NUM_SLOTS]; + float4* stanumbers[STATISTIC_NUM_SLOTS]; + int numvalues[STATISTIC_NUM_SLOTS]; + Datum* stavalues[STATISTIC_NUM_SLOTS]; + bool* stanulls[STATISTIC_NUM_SLOTS]; + + /* + * These fields describe the stavalues[n] element types. They will be + * initialized to match attrtypid, but a custom typanalyze function might + * want to store an array of something other than the analyzed column's + * elements. It should then overwrite these fields. + */ + Oid statypid[STATISTIC_NUM_SLOTS]; + int2 statyplen[STATISTIC_NUM_SLOTS]; + bool statypbyval[STATISTIC_NUM_SLOTS]; + char statypalign[STATISTIC_NUM_SLOTS]; + + /* + * These fields are private to the main ANALYZE code and should not be + * looked at by type-specific functions. + */ + int tupattnum; /* attribute number within tuples */ + HeapTuple* rows; /* access info for std fetch function */ + TupleDesc tupDesc; + Datum* exprvals; /* access info for index fetch function */ + bool* exprnulls; + int rowstride; +} VacAttrStats; + +/* + * flags for vacuum object + */ +typedef enum VacuumFlags { + VACFLG_SIMPLE_HEAP = 1 << 0, /* simple heap */ + VACFLG_SIMPLE_BTREE = 1 << 1, /* no use, btree index on simple heap */ + VACFLG_MAIN_PARTITION = 1 << 2, /* partitioned table */ + VACFLG_MAIN_PARTITION_BTREE = 1 << 3, /* no use, btree index on partitioned table */ + VACFLG_SUB_PARTITION = 1 << 4, /* table partition */ + VACFLG_SUB_PARTITION_BTREE = 1 << 5, /* no use, btree index on table partition */ + VACFLG_TOAST = 1 << 6, /* no use*/ + VACFLG_TOAST_BTREE = 1 << 7 /* no use*/ +} VacuumFlags; + +typedef struct vacuum_object { + Oid tab_oid; /* object id for a table, index or a partition */ + Oid parent_oid; /* parent object id if it's a partition */ + + /* + * we ues following flag to skip some check + * 1. for partitioned table , we vacuum all the partitiones when we + * vacuum partitioned so we just skip check all partiitons + * 2. for main table, we vaccum toast table when we vacuum main table + */ + bool dovacuum; + bool dovacuum_toast; /* flags for vacuum toast table, do vacuum on toast if true */ + bool doanalyze; + bool need_freeze; /* flag to freeze old tuple for recycle clog */ + bool is_internal_relation; /* flag to mark if it is an internal relation */ + bool is_tsdb_deltamerge; /* flag to mark if it is a tsdb deltamerge task */ + int flags; /* flags for vacuum object */ +} vacuum_object; + +/* + * This struct is used to store the partitioned table's information in pg_class, + * after the VACUUM or ANALYZE, update pg_class with it. + */ +typedef struct UpdatePartitionedTableData { + Oid tabOid; /* partitioned table's oid */ + BlockNumber pages; /* all blocks, including all its partitions */ + double tuples; /* all tuples, including all its partitions */ + BlockNumber allVisiblePages; /* all visible pages */ + bool hasIndex; /* true, iff table has index */ + TransactionId frozenXid; /* frozen Xid */ +} UpdatePartitionedTableData; + +/* Identify create temp table for attribute or table. */ +typedef enum { TempSmpleTblType_Table, TempSmpleTblType_Attrbute } TempSmpleTblType; + +/* The stage for datanode send sample to coordinator under debugging. */ +typedef enum { DebugStage_Begin, DebugStage_Execute, DebugStage_End } AnalyzeTempTblDebugStage; + +/* Each sample of distinct value. */ +typedef struct { + Datum value; /* a sample value */ + int64 count; /* how many duplicate values */ +} SampleItem; + +/* Mcv list for compute statistic.*/ +typedef struct { + int stattarget; /* how many most common values we should save. */ + int64 rows_mcv; /* sum of rows of all the most common values */ + int num_mcv; /* num of mcv for the current saved */ +} McvInfo; + +/* Histgram list for compute statistic.*/ +typedef struct { + bool is_last_value; /* indentify the value is the last value. */ + int stattarget; /* how many histgrams we should save. */ + int num_hist; /* num of histgram for the current saved. */ + int64 rows_hist; /* sum of rows of all the histgrams. */ + int64 bucketSize; /* the step length for histogram bound. */ + int64 sum_count; /* sum of the count for saved histogram value. */ + int64 cur_mcv_idx; + int64 start_value_count; /* how many duplicate values */ + Datum start_value; /* a sample value */ + SampleItem* histitem; /* item of histgram */ +} HistgramInfo; + +/* The sample info of special attribute for compute statistic */ +typedef struct { + bool is_varwidth; /* the width of attribute is variable-length type or not. */ + double totalrows; /* total rows for the table. */ + int64 samplerows; /* how many sample rows for the table. */ + double ndistinct; /* # distinct values */ + int64 nmultiple; /* duplicate num of distinct values more than 1. */ + int64 null_cnt; /* count of null value */ + int64 nonnull_cnt; /* count of non-null values for all samples. */ + McvInfo mcv_list; /* mcv list for compute stats.*/ + HistgramInfo hist_list; /* histgram list for compute stats.*/ + char** v_alias; /* alias for column v in temp table. */ + VacAttrStats* stats; /* the statistics of attribute for update to pg_staitsitc. */ +} AnalyzeSampleTableSpecInfo; + +/* + * data and functions for delta merge + */ +typedef struct { + StringInfo row_count_sql; + StringInfo merge_sql; + StringInfo vacuum_sql; + uint64 max_row; + + /* original info */ + Oid oid; + StringInfo relname; + StringInfo schemaname; + bool is_hdfs; + +} MergeInfo; + +#define vacuumRelation(flag) (((flag)&VACFLG_SIMPLE_HEAP) == VACFLG_SIMPLE_HEAP) + +#define vacuumMainPartition(flag) (((flag)&VACFLG_MAIN_PARTITION) == VACFLG_MAIN_PARTITION) + +#define vacuumPartition(flag) (((flag)&VACFLG_SUB_PARTITION) == VACFLG_SUB_PARTITION) + +#define hdfsVcuumAction(flag) (((flag)&VACOPT_HDFSDIRECTORY) || ((flag)&VACOPT_COMPACT) || ((flag)&VACOPT_MERGE)) + +/* We need estimate total rows on datanode only sample rate is -1. */ +#define NEED_EST_TOTAL_ROWS_DN(vacstmt) \ + (IS_PGXC_DATANODE && IsConnFromCoord() && (vacstmt)->pstGlobalStatEx[(vacstmt)->tableidx].sampleRate < 0) + +/* + * remote analyze user-defined table + * 1. for system catalog, do local analyze + * 2. for user-define table, local coordinator broadcast statistics + */ +#define udtRemoteAnalyze(relid) (FirstNormalObjectId < (relid) && IS_PGXC_COORDINATOR && IsConnFromCoord()) + +typedef bool (*EqualFunc)(const void*, const void*); + +/* GUC parameters */ +extern THR_LOCAL PGDLLIMPORT int default_statistics_target; /* PGDLLIMPORT for + * PostGIS */ + +#define DEBUG_START_TIMER \ + struct timeval stStartTime; \ + struct timeval stStopTime; \ + double dTotalElapsTime; \ + if (log_min_messages <= DEBUG1) { \ + (void)gettimeofday(&stStartTime, NULL); \ + dTotalElapsTime = 0; \ + } + +#define DEBUG_RESET_TIMER \ + do { \ + dTotalElapsTime = 0; \ + if (log_min_messages <= DEBUG1) \ + (void)gettimeofday(&stStartTime, NULL); \ + } while (0) + +#define DEBUG_STOP_TIMER(fmt, ...) \ + do { \ + if (log_min_messages <= DEBUG1) { \ + StringInfoData str1; \ + initStringInfo(&str1); \ + (void)gettimeofday(&stStopTime, NULL); \ + dTotalElapsTime = \ + (stStopTime.tv_sec - stStartTime.tv_sec) + (stStopTime.tv_usec - stStartTime.tv_usec) * 0.000001; \ + appendStringInfo(&str1, fmt, ##__VA_ARGS__); \ + elog(DEBUG1, \ + "%s for queryid[%lu]: %s --- elapse time: [%9.3lfs] \n", \ + g_instance.attr.attr_common.PGXCNodeName, \ + u_sess->debug_query_id, \ + str1.data, \ + dTotalElapsTime); \ + pfree(str1.data); \ + } \ + } while (0) + +#define allow_debug(MOD) (log_min_messages <= DEBUG2 && module_logging_is_on(MOD)) + +#define DEBUG_MOD_START_TIMER(MOD) \ + struct timeval stStartTime; \ + double dTotalElapsTime; \ + if (allow_debug(MOD)) { \ + (void)gettimeofday(&stStartTime, NULL); \ + dTotalElapsTime = 0; \ + } + +#define DEBUG_MOD_STOP_TIMER(MOD, fmt, ...) \ + do { \ + if (allow_debug(MOD)) { \ + StringInfoData str1; \ + initStringInfo(&str1); \ + struct timeval stStopTime; \ + (void)gettimeofday(&stStopTime, NULL); \ + dTotalElapsTime = \ + (stStopTime.tv_sec - stStartTime.tv_sec) + (stStopTime.tv_usec - stStartTime.tv_usec) * 0.000001; \ + appendStringInfo(&str1, fmt, ##__VA_ARGS__); \ + ereport(DEBUG2, \ + (errmodule(MOD), \ + errmsg("%s for queryid[%lu]: %s --- elapse time: [%9.6lfs] \n", \ + g_instance.attr.attr_common.PGXCNodeName, \ + u_sess->debug_query_id, \ + str1.data, \ + dTotalElapsTime))); \ + dTotalElapsTime = 0; \ + (void)gettimeofday(&stStartTime, NULL); \ + pfree(str1.data); \ + } \ + } while (0) + +/* Time elapse stats end */ + +/* in commands/vacuum.c */ +extern void vacuum(VacuumStmt* vacstmt, Oid relid, bool do_toast, BufferAccessStrategy bstrategy, bool isTopLevel); +extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int* nindexes, Relation** Irel); +extern void vac_close_indexes(int nindexes, Relation* Irel, LOCKMODE lockmode); +extern double vac_estimate_reltuples( + Relation relation, BlockNumber total_pages, BlockNumber scanned_pages, double scanned_tuples); +extern void vac_update_relstats(Relation relation, Relation classRel, RelPageType num_pages, double num_tuples, + BlockNumber num_all_visible_pages, bool hasindex, TransactionId frozenxid); +extern void vacuum_set_xid_limits(Relation rel, int64 freeze_min_age, int64 freeze_table_age, TransactionId* oldestXmin, + TransactionId* freezeLimit, TransactionId* freezeTableLimit); +extern void vac_update_datfrozenxid(void); +extern void vacuum_delay_point(void); + +/* in commands/vacuumlazy.c */ +extern void lazy_vacuum_rel(Relation onerel, VacuumStmt* vacstmt, BufferAccessStrategy bstrategy); + +/* in commands/analyze.c */ +extern void analyze_rel(Oid relid, VacuumStmt* vacstmt, BufferAccessStrategy bstrategy); +extern char* buildTempSampleTable(Oid relid, Oid mian_relid, TempSmpleTblType type, + AnalyzeMode analyzemode = ANALYZENORMAL, bool inh = false, VacuumStmt* vacstmt = NULL, + AnalyzeSampleTableSpecInfo* spec = NULL); +extern void dropSampleTable(const char* tableName); +extern const char* get_sample_tblname(AnalyzeMode analyzemode, List* tmpSampleTblNameList); +extern VacAttrStats* examine_attribute(Relation onerel, Bitmapset* bms_attnums, bool isLog); +extern void update_attstats( + Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats, char relpersistence); +extern void update_attstats(Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats); +/* we should delete all records in pg_statistic when the data is dirty and current totalrows is null. */ +extern void delete_attstats(Oid relid, char relkind, bool inh, int natts, VacAttrStats** vacattrstats, + unsigned int delete_stats_option = DELETE_STATS_SINGLE); + +/* get one relation by relid before do analyze */ +extern Relation analyze_get_relation(Oid relid, VacuumStmt* vacstmt); +extern bool std_typanalyze(VacAttrStats* stats); +extern double anl_random_fract(void); +extern double anl_init_selection_state(int n); +extern double anl_get_next_S(double t, int n, double* stateptr); +extern int compute_sample_size( + VacuumStmt* vacstmt, int num_samples, bool** require_samp, Oid relid = 0, int tableidx = 0); +extern void set_complex_sample(VacuumStmt* pStmt); +extern void delete_attstats_replication(Oid relid, VacuumStmt* stmt); +extern int compute_attr_target(Form_pg_attribute attr); + +extern void vac_update_partstats(Partition part, BlockNumber num_pages, double num_tuples, + BlockNumber num_all_visible_pages, TransactionId frozenxid); +extern void vac_open_part_indexes(VacuumStmt* vacstmt, LOCKMODE lockmode, int* nindexes, int* nindexesGlobal, + Relation** Irel, Relation** indexrel, Partition** indexpart); +extern void vac_close_part_indexes( + int nindexes, int nindexesGlobal, Relation* Irel, Relation* indexrel, Partition* indexpart, LOCKMODE lockmode); +extern void vac_update_pgclass_partitioned_table(Relation partitionRel, bool hasIndex, TransactionId newFrozenXid); + +extern void CStoreVacUpdateNormalRelStats(Oid relid, TransactionId frozenxid, Relation pgclassRel); +extern void CStoreVacUpdatePartitionRelStats(Relation partitionRel, TransactionId newFrozenXid); +extern void CStoreVacUpdatePartitionStats(Oid relid, TransactionId frozenxid); +extern void CalculatePartitionedRelStats(_in_ Relation partitionRel, _in_ Relation pgPartitionRel, + _out_ BlockNumber* totalPages, _out_ BlockNumber* totalVisiblePages, _out_ double* totalTuples, + _out_ TransactionId* minFrozenXid); + +extern bool IsToastRelationbyOid(Oid relid); +extern Oid pg_toast_get_baseid(Oid relOid, bool* isPartToast); +extern void elogVacuumInfo(Relation rel, HeapTuple tuple, char* funcName, TransactionId oldestxmin); + +typedef Datum (*GetValFunc[2])(CU* cuPtr, int rowIdx); +extern void InitGetValFunc(int attlen, GetValFunc* getValFuncPtr, int col); + +extern void DfsVacuumFull(Oid relid, VacuumStmt* vacstmt); +extern void RemoveGarbageFiles(Relation rel, DFSDescHandler* handler); + +extern bool equal_string(const void* _str1, const void* _str2); +extern List* GetDifference(const List* list1, const List* list2, EqualFunc fn); + +extern void merge_one_relation(void* _info); +extern void merge_cu_relation(void* info, VacuumStmt* stmt); + +extern List* get_rel_oids(Oid relid, VacuumStmt* vacstmt); + +extern char* get_nsp_relname(Oid relid); + +// obs foreign table options totalrows +extern void updateTotalRows(Oid relid, double n); + +extern void analyze_concurrency_process(Oid relid, int16 attnum, MemoryContext oldcontext, const char* funcname); + +extern int GetOneTupleSize(VacuumStmt* stmt, Relation rel); + +#endif /* VACUUM_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/variable.h postgresql-hll-2.14/include/include/commands/variable.h --- postgresql-hll-2.14_old/include/include/commands/variable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/variable.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,41 @@ +/* + * variable.h + * Routines for handling specialized SET variables. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/variable.h + */ +#ifndef VARIABLE_H +#define VARIABLE_H + +#include "utils/guc.h" + +extern bool check_datestyle(char** newval, void** extra, GucSource source); +extern void assign_datestyle(const char* newval, void* extra); +extern bool check_timezone(char** newval, void** extra, GucSource source); +extern void assign_timezone(const char* newval, void* extra); +extern const char* show_timezone(void); +extern bool check_log_timezone(char** newval, void** extra, GucSource source); +extern void assign_log_timezone(const char* newval, void* extra); +extern const char* show_log_timezone(void); +extern bool check_transaction_read_only(bool* newval, void** extra, GucSource source); +extern bool check_default_transaction_read_only(bool* newval, void** extra, GucSource source); +extern bool check_XactIsoLevel(char** newval, void** extra, GucSource source); +extern void assign_XactIsoLevel(const char* newval, void* extra); +extern const char* show_XactIsoLevel(void); +extern bool check_transaction_deferrable(bool* newval, void** extra, GucSource source); +extern bool check_random_seed(double* newval, void** extra, GucSource source); +extern void assign_random_seed(double newval, void* extra); +extern const char* show_random_seed(void); +extern bool check_client_encoding(char** newval, void** extra, GucSource source); +extern void assign_client_encoding(const char* newval, void* extra); +extern bool check_mix_replication_param(bool* newval, void** extra, GucSource source); +extern bool check_session_authorization(char** newval, void** extra, GucSource source); +extern void assign_session_authorization(const char* newval, void* extra); +extern bool check_role(char** newval, void** extra, GucSource source); +extern void assign_role(const char* newval, void* extra); +extern const char* show_role(void); + +#endif /* VARIABLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/verify.h postgresql-hll-2.14/include/include/commands/verify.h --- postgresql-hll-2.14_old/include/include/commands/verify.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/verify.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,56 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * verify.h + * header file for anlayse verify commands to check the datafile. + * + * + * IDENTIFICATION + * src/include/commands/verify.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VERIFY_H +#define VERIFY_H + +#include "pgxc/pgxcnode.h" +#include "tcop/tcopprot.h" +#include "dfsdesc.h" +#include "access/htup.h" +#include "catalog/pg_authid.h" +#include "catalog/pg_auth_members.h" +#include "catalog/namespace.h" +#include "catalog/pg_database.h" +#include "catalog/pg_namespace.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_partition_fn.h" +#include "catalog/pg_statistic.h" +#include "catalog/pg_user_status.h" +#include "catalog/pg_tablespace.h" +#include "catalog/pg_type.h" +#include "nodes/parsenodes.h" +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/cu.h" +#include "storage/lock.h" +#include "storage/remote_read.h" +#include "utils/relcache.h" + +extern void DoGlobalVerifyMppTable(VacuumStmt* stmt, const char* queryString, bool sentToRemote); +extern void DoGlobalVerifyDatabase(VacuumStmt* stmt, const char* queryString, bool sentToRemote); +extern void DoVerifyTableOtherNode(VacuumStmt* stmt, bool sentToRemote); +extern void VerifyAbortBufferIO(void); + +#endif /* VERIFY_H */ diff -uprN postgresql-hll-2.14_old/include/include/commands/view.h postgresql-hll-2.14/include/include/commands/view.h --- postgresql-hll-2.14_old/include/include/commands/view.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/commands/view.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * view.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/commands/view.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VIEW_H +#define VIEW_H + +#include "nodes/parsenodes.h" + +extern Oid DefineView(ViewStmt* stmt, const char* queryString, bool send_remote = true, bool isFirstNode = true); +extern bool IsViewTemp(ViewStmt* stmt, const char* queryString); +extern void StoreViewQuery(Oid viewOid, Query *viewParse, bool replace); + +#endif /* VIEW_H */ diff -uprN postgresql-hll-2.14_old/include/include/common/build_query/build_query.h postgresql-hll-2.14/include/include/common/build_query/build_query.h --- postgresql-hll-2.14_old/include/include/common/build_query/build_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/common/build_query/build_query.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * build_query.h + * interfaces used by cm_ctl and gs_ctl to display build progress + * + * Portions Copyright (c) 2012-2015, Huawei Tech. Co., Ltd. + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/common/build_query/build_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BUILD_QUERY_H +#define BUILD_QUERY_H + +#include "c.h" +#include "replication/replicainternal.h" + +#define KB_PER_MB (1024) +#define KB_PER_GB (1024 * 1024) +#define KB_PER_TB (1024 * 1024 * 1024) + +#define S_PER_MIN 60 +#define S_PER_H (60 * 60) + +#define REPORT_TIMEOUT 30 /* report and calculate sync speed every 30s */ +#define CACULATE_MIN_TIME 2 /* calculate sync speed at least every 2s */ + +extern char* show_estimated_time(int time); +extern char* show_datasize(uint64 size); +extern void UpdateDBStateFile(char* path, GaussState* state); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/common/config/cm_config.h postgresql-hll-2.14/include/include/common/config/cm_config.h --- postgresql-hll-2.14_old/include/include/common/config/cm_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/common/config/cm_config.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,416 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cm_config.h + * + * + * + * IDENTIFICATION + * src/include/common/config/cm_config.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_CONFIG_H +#define CM_CONFIG_H + +#include "c.h" + +#define CM_NODE_NAME 65 +#define CM_AZ_NAME 65 +#define CM_QUORUM_NAME 65 +#define CM_LOGIC_CLUSTER_NAME_LEN 64 +#define LOGIC_CLUSTER_NUMBER (32 + 1) // max 32 logic + 1 elastic group +#define MAX_PATH_LEN 1024 +#define CM_IP_NUM 3 +#define GTM_IP_PORT 64 +#define CM_IP_LENGTH 128 +#define CM_IP_ALL_NUM_LENGTH (CM_IP_NUM * CM_IP_LENGTH) +#define CM_PATH_LENGTH 1024 +#define CM_NODE_MAXNUM 1024 +#define CM_MAX_DATANODE_PER_NODE 160 +#define CM_MAX_INSTANCE_PER_NODE 192 +#define INVALID_NODE_NUM (CM_NODE_MAXNUM + 1) +#define INVALID_INSTACNE_NUM (0xFFFFFFFF) +#define CM_MAX_INSTANCE_GROUP_NUM (CM_NODE_MAXNUM * CM_MAX_INSTANCE_PER_NODE) +#define AGLINMENT_SIZE (1024 * 8) +#define CM_MAX_COMMAND_LEN 1024 +#define CM_MAX_COMMAND_LONG_LEN 2048 +#define CONNSTR_LEN 256 + +// A logic datanode number in a node, The logic datanode can be include the primary, standby and dummystandby DN. +#define LOGIC_DN_PER_NODE 32 +#define MAX_LOGIC_DATANODE (CM_NODE_MAXNUM * LOGIC_DN_PER_NODE) + +#define CM_PRIMARY_STANDBY_NUM (8) // supprot one primary and multi standby +#define CM_MAX_CMSERVER_STANDBY_NUM (7) +#define CM_MAX_DATANODE_STANDBY_NUM 7 +#define CM_MAX_GTM_STANDBY_NUM (7) +#define MAX_CN_NUM 256 +#define CM_MAX_SQL_COMMAND_LEN 2048 + +#define HAVE_GTM 1 +#define NONE_GTM 0 +#define PRIMARY_GTM 0 +#define STANDBY_GTM 1 + +// consist with OM +#define PRIMARY_DN 0 +#define STANDBY_DN 1 +#define DUMMY_STANDBY_DN 2 + +#define CM_DATANODE 1 +#define CM_COORDINATENODE 2 +#define CM_GTM 3 + +#define CM_AGENT 7 +#define CM_CTL 8 +#define CM_SERVER 9 + +#define GROUP_NAME_VERSION1 "group_version1" +#define GROUP_NAME_VERSION2 "group_version2" + +#define OPEN_FILE_ERROR -1 +#define OUT_OF_MEMORY -2 +#define READ_FILE_ERROR -3 + +#define CLUSTER_STATUS_QUERY 0 +#define CLUSTER_DETAIL_STATUS_QUERY 1 +#define CLUSTER_COUPLE_STATUS_QUERY 2 +#define CLUSTER_COUPLE_DETAIL_STATUS_QUERY 3 +#define CLUSTER_BALANCE_COUPLE_DETAIL_STATUS_QUERY 4 +#define CLUSTER_LOGIC_COUPLE_DETAIL_STATUS_QUERY 5 +#define CLUSTER_PARALLEL_REDO_REPLAY_STATUS_QUERY 6 +#define CLUSTER_PARALLEL_REDO_REPLAY_DETAIL_STATUS_QUERY 7 +#define CLUSTER_ABNORMAL_COUPLE_DETAIL_STATUS_QUERY 8 +#define CLUSTER_ABNORMAL_BALANCE_COUPLE_DETAIL_STATUS_QUERY 9 +#define CLUSTER_START_STATUS_QUERY 10 + +#define DYNAMC_CONFIG_FILE "cluster_dynamic_config" + +#define PROCESS_UNKNOWN -1 +#define PROCESS_NOT_EXIST 0 +#define PROCESS_CORPSE 1 +#define PROCESS_RUNNING 2 +#define PROCESS_PHONY_DEAD_T 3 +#define PROCESS_PHONY_DEAD_D 4 +#define PROCESS_PHONY_DEAD_Z 5 +/***/ +#define PROCESS_WAIT_STOP 3 +#define PROCESS_WAIT_START 4 + +#define PROCESS_ETCD 0 +#define PROCESS_CMSERVER 1 + +#define QUERY_STATUS_CMSERVER_STEP 0 +#define QUERY_STATUS_CMSERVER_SETP_ACK 1 +#define QUERY_STATUS_CMAGENT_STEP 2 +#define QUERY_STATUS_CMAGENT_STEP_ACK 3 + +#define AZ_START_STOP_INTERVEL 2 +#define AZ_STOP_DELAY 2 + +#define ETCD_KEY_LENGTH 1024 +#define ETCD_VLAUE_LENGTH 1024 + +/* az_Priorities, only init the values when load config file */ +const uint32 g_az_invalid = 0; +extern uint32 g_az_master; +extern uint32 g_az_slave; +extern uint32 g_az_arbiter; + +typedef enum AZRole { AZMaster, AZSlave, AZArbiter } AZRole; + +typedef struct az_role_string { + const char* role_string; + uint32 role_val; +} az_role_string; + +typedef enum cmServerLevel { + CM_SERVER_NONE = 0, // no cm_server + CM_SERVER_LEVEL_1 = 1 +} cmServerLevel; + +typedef struct staticConfigHeader { + uint32 crc; + uint32 len; + uint32 version; + int64 time; + uint32 nodeCount; + uint32 node; +} staticConfigHeader; + +typedef struct peerDatanodeInfo { + char datanodePeerDataPath[CM_PATH_LENGTH]; + uint32 datanodePeerHAListenCount; + char datanodePeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeerHAPort; + uint32 datanodePeerRole; +} peerDatanodeInfo; + +typedef struct dataNodeInfo { + uint32 datanodeId; + uint32 datanodeMirrorId; + char datanodeLocalDataPath[CM_PATH_LENGTH]; + char datanodeXlogPath[CM_PATH_LENGTH]; + char datanodeSSDDataPath[CM_PATH_LENGTH]; + uint32 datanodeListenCount; + char datanodeListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePort; + + uint32 datanodeRole; + + uint32 datanodeLocalHAListenCount; + char datanodeLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodeLocalHAPort; + + char datanodePeerDataPath[CM_PATH_LENGTH]; + uint32 datanodePeerHAListenCount; + char datanodePeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeerHAPort; + uint32 datanodePeerRole; + + char datanodePeer2DataPath[CM_PATH_LENGTH]; + uint32 datanodePeer2HAListenCount; + char datanodePeer2HAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 datanodePeer2HAPort; + uint32 datanodePeer2Role; + + char LogicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + + // multi available zone: single primary and multi standby datanodes + peerDatanodeInfo peerDatanodes[CM_MAX_DATANODE_STANDBY_NUM]; +} dataNodeInfo; + +typedef struct peerCmServerInfo { + uint32 cmServerPeerHAListenCount; + char cmServerPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerPeerHAPort; +} peerCmServerInfo; + +typedef struct peerGtmInfo { + uint32 gtmPeerHAListenCount; + char gtmPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmPeerHAPort; +} peerGtmInfo; + +typedef struct staticNodeConfig { + uint32 crc; + + char azName[CM_AZ_NAME]; + uint32 azPriority; + + uint32 node; + char nodeName[CM_NODE_NAME]; + + uint32 sshCount; + char sshChannel[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 backIpCount; + char backIps[CM_IP_NUM][CM_IP_LENGTH]; + + /**/ + uint32 cmServerId; + uint32 cmServerMirrorId; + char cmDataPath[CM_PATH_LENGTH]; + uint32 cmServerLevel; + char cmServerFloatIP[CM_IP_LENGTH]; + + uint32 cmServerListenCount; + char cmServer[CM_IP_NUM][CM_IP_LENGTH]; + uint32 port; + /**/ + uint32 cmServerLocalHAListenCount; + char cmServerLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerLocalHAPort; + + int32 cmServerRole; + /**/ + uint32 cmServerPeerHAListenCount; + char cmServerPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 cmServerPeerHAPort; + + peerCmServerInfo peerCmServers[CM_MAX_CMSERVER_STANDBY_NUM]; + + /**/ + uint32 gtmAgentId; + uint32 cmAgentMirrorId; + uint32 cmAgentListenCount; + char cmAgentIP[CM_IP_NUM][CM_IP_LENGTH]; + + /**/ + uint32 gtmId; + uint32 gtmMirrorId; + uint32 gtm; + char gtmLocalDataPath[CM_PATH_LENGTH]; + uint32 gtmLocalListenCount; + char gtmLocalListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmLocalport; + + uint32 gtmRole; + + uint32 gtmLocalHAListenCount; + char gtmLocalHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmLocalHAPort; + + char gtmPeerDataPath[CM_PATH_LENGTH]; + uint32 gtmPeerHAListenCount; + char gtmPeerHAIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmPeerHAPort; + + peerGtmInfo peerGtms[CM_MAX_CMSERVER_STANDBY_NUM]; + + /*****/ + uint32 gtmProxyId; + uint32 gtmProxyMirrorId; + uint32 gtmProxy; + uint32 gtmProxyListenCount; + char gtmProxyListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 gtmProxyPort; + + /*****/ + uint32 coordinateId; + uint32 coordinateMirrorId; + uint32 coordinate; + char DataPath[CM_PATH_LENGTH]; + char SSDDataPath[CM_PATH_LENGTH]; + uint32 coordinateListenCount; + char coordinateListenIP[CM_IP_NUM][CM_IP_LENGTH]; + uint32 coordinatePort; + uint32 coordinateHAPort; + + /*****/ + uint32 datanodeCount; + dataNodeInfo datanode[CM_MAX_DATANODE_PER_NODE]; + + uint32 etcd; + uint32 etcdId; + uint32 etcdMirrorId; + char etcdName[CM_NODE_NAME]; + char etcdDataPath[CM_PATH_LENGTH]; + uint32 etcdClientListenIPCount; + char etcdClientListenIPs[CM_IP_NUM][CM_IP_LENGTH]; + uint32 etcdClientListenPort; + uint32 etcdHAListenIPCount; + char etcdHAListenIPs[CM_IP_NUM][CM_IP_LENGTH]; + uint32 etcdHAListenPort; + + uint32 sctpBeginPort; + uint32 sctpEndPort; + +} staticNodeConfig; + +typedef struct dynamicConfigHeader { + uint32 crc; + uint32 len; + uint32 version; + int64 time; + uint32 nodeCount; /* physicalNodeNum,same as staic config file head. */ + uint32 relationCount; + uint32 term; +} dynamicConfigHeader; + +typedef struct dynamic_cms_timeline { + long int timeline; // Record current time at the CMS instance is upgraded to the primary instance. +} dynamic_cms_timeline; + +typedef struct dynamicRelationConfig { + uint32 crc; + uint32 currentPrimary; + uint32 node[CM_PRIMARY_STANDBY_NUM]; + char dataPath[CM_PRIMARY_STANDBY_NUM][CM_PATH_LENGTH]; +} dynamicRelationConfig; + +typedef struct staticLogicNodeConfig { + + uint32 crc; + uint32 node; + char nodeName[CM_NODE_NAME]; + + uint32 sshCount; + char sshChannel[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 backIpCount; + char backIps[CM_IP_NUM][CM_IP_LENGTH]; + + uint32 sctpBeginPort; + uint32 sctpEndPort; + + uint32 datanodeCount; + uint32 datanodeId[CM_MAX_DATANODE_PER_NODE]; +} staticLogicNodeConfig; + +typedef struct logicClusterStaticConfig { + char LogicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; + uint32 LogicClusterStatus; + uint32 isLogicClusterBalanced; + uint32 isRedistribution; + staticConfigHeader logicClusterNodeHeader; + staticLogicNodeConfig* logicClusterNode; +} logicClusterStaticConfig; + +typedef struct logicClusterInfo { + uint32 logicClusterId; + char logicClusterName[CM_LOGIC_CLUSTER_NAME_LEN]; +} logicClusterInfo; + +typedef struct logicClusterList { + uint32 logicClusterCount; + logicClusterInfo lcInfoArray[LOGIC_CLUSTER_NUMBER]; +} logicClusterList; + +extern staticConfigHeader g_nodeHeader; +extern staticNodeConfig* g_node; +extern staticNodeConfig* g_currentNode; +extern bool g_single_node_cluster; +extern bool g_multi_az_cluster; +extern bool g_one_master_multi_slave; +extern bool g_only_dn_cluster; +extern uint32 g_node_num; +extern uint32 g_cluster_total_instance_group_num; +extern uint32 g_etcd_num; +extern uint32 g_cm_server_num; +extern uint32 g_dn_replication_num; +extern uint32 g_gtm_num; +extern uint32 g_coordinator_num; +extern uint32 max_node_name_len; +extern uint32 max_az_name_len; +extern uint32 max_datapath_len; +extern uint32 max_cnpath_len; +extern uint32 max_gtmpath_len; +extern uint32 max_etcdpath_len; +extern uint32 max_cmpath_len; +extern logicClusterStaticConfig g_logicClusterStaticConfig[LOGIC_CLUSTER_NUMBER]; +extern uint32 g_logic_cluster_count; +extern uint32 max_logic_cluster_state_len; +extern uint32 max_logic_cluster_name_len; +extern bool logic_cluster_query; +extern bool logic_cluster_restart; +extern uint32 g_datanodeid; +extern char* g_logicClusterName; + +extern int read_single_file(const char *file_path, int *err_no, uint32 nodeId, const char *dataPath); +extern int read_config_file(const char* file_path, int* err_no); +extern int read_logic_cluster_name(const char* file_path, logicClusterList& lcList, int* err_no); +extern int read_logic_cluster_config_files(const char* file_path, int* err_no); +extern int read_lc_config_file(const char* file_path, int* err_no); +extern int find_node_index_by_nodeid(uint32 nodeId, uint32* node_index); +extern int find_current_node_by_nodeid(uint32 nodeId); +extern int node_index_Comparator(const void* arg1, const void* arg2); +extern void set_cm_read_flag(bool falg); +extern char* getAZNamebyPriority(uint32 azPriority); +extern int cmconfig_getenv(const char* env_var, char* output_env_value, uint32 env_value_len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/common/fe_memutils.h postgresql-hll-2.14/include/include/common/fe_memutils.h --- postgresql-hll-2.14_old/include/include/common/fe_memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/common/fe_memutils.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * fe_memutils.h + * memory management support for frontend code + * + * Copyright (c) 2003-2015, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/common/fe_memutils.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FE_MEMUTILS_H +#define FE_MEMUTILS_H + +/* + * Flags for pg_malloc_extended and palloc_extended, deliberately named + * the same as the backend flags. + */ +#define MCXT_ALLOC_HUGE \ + 0x01 /* allow huge allocation (> 1 GB) not \ + * actually used for frontends */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +#include "c.h" + +/* + * "Safe" memory allocation functions --- these exit(1) on failure + * (except pg_malloc_extended with MCXT_ALLOC_NO_OOM) + */ +extern char* pg_strdup(const char* in); +extern void* pg_malloc(size_t size); +extern void* pg_malloc0(size_t size); +extern void* pg_malloc_extended(size_t size, int flags); +extern void* pg_realloc(void* pointer, size_t size); +extern void pg_free(void* pointer); + +/* Equivalent functions, deliberately named the same as backend functions */ +extern void* palloc(Size size); +extern void* palloc_extended(Size size, int flags); +extern void pfree(void* pointer); + +#endif /* FE_MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/common/int.h postgresql-hll-2.14/include/include/common/int.h --- postgresql-hll-2.14_old/include/include/common/int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/common/int.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,262 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * int.h + * Routines to perform integer math, while checking for overflows. + * + * The routines in this file are intended to be well defined C, without + * relying on compiler flags like -fwrapv. + * + * To reduce the overhead of these routines try to use compiler intrinsics + * where available. That's not that important for the 16, 32 bit cases, but + * the 64 bit cases can be considerably faster with intrinsics. In case no + * intrinsics are available 128 bit math is used where available. + * + * Copyright (c) 2017-2019, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/common/int.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMMON_INT_H +#define COMMON_INT_H + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#else + int32 res = (int32)a + (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#else + int32 res = (int32)a - (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s16_overflow(int16 a, int16 b, int16* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#else + int32 res = (int32)a * (int32)b; + + if (res > PG_INT16_MAX || res < PG_INT16_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int16)res; + return false; +#endif +} + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#else + int64 res = (int64)a + (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#else + int64 res = (int64)a - (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s32_overflow(int32 a, int32 b, int32* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#else + int64 res = (int64)a * (int64)b; + + if (res > PG_INT32_MAX || res < PG_INT32_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int32)res; + return false; +#endif +} + +/* + * If a + b overflows, return true, otherwise store the result of a + b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_add_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_add_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a + (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + if ((a > 0 && b > 0 && a > PG_INT64_MAX - b) || (a < 0 && b < 0 && a < PG_INT64_MIN - b)) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a + b; + return false; +#endif +} + +/* + * If a - b overflows, return true, otherwise store the result of a - b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_sub_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_sub_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a - (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + if ((a < 0 && b > 0 && a < PG_INT64_MIN + b) || (a > 0 && b < 0 && a > PG_INT64_MAX + b)) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a - b; + return false; +#endif +} + +/* + * If a * b overflows, return true, otherwise store the result of a * b into + * *result. The content of *result is implementation defined in case of + * overflow. + */ +static inline bool pg_mul_s64_overflow(int64 a, int64 b, int64* result) +{ +#if defined(HAVE__BUILTIN_OP_OVERFLOW) + return __builtin_mul_overflow(a, b, result); +#elif defined(HAVE_INT128) + int128 res = (int128)a * (int128)b; + + if (res > PG_INT64_MAX || res < PG_INT64_MIN) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = (int64)res; + return false; +#else + /* + * Overflow can only happen if at least one value is outside the range + * sqrt(min)..sqrt(max) so check that first as the division can be quite a + * bit more expensive than the multiplication. + * + * Multiplying by 0 or 1 can't overflow of course and checking for 0 + * separately avoids any risk of dividing by 0. Be careful about dividing + * INT_MIN by -1 also, note reversing the a and b to ensure we're always + * dividing it by a positive value. + * + */ + if ((a > PG_INT32_MAX || a < PG_INT32_MIN || b > PG_INT32_MAX || b < PG_INT32_MIN) && a != 0 && a != 1 && b != 0 && + b != 1 && + ((a > 0 && b > 0 && a > PG_INT64_MAX / b) || (a > 0 && b < 0 && b < PG_INT64_MIN / a) || + (a < 0 && b > 0 && a < PG_INT64_MIN / b) || (a < 0 && b < 0 && a < PG_INT64_MAX / b))) { + *result = 0x5EED; /* to avoid spurious warnings */ + return true; + } + *result = a * b; + return false; +#endif +} + +#endif /* COMMON_INT_H */ diff -uprN postgresql-hll-2.14_old/include/include/connector.h postgresql-hll-2.14/include/include/connector.h --- postgresql-hll-2.14_old/include/include/connector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/connector.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * connector.h + * Definitions for c-function interface of the module + * + * + * IDENTIFICATION + * src/include/connector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CONNECTOR_H +#define CONNECTOR_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +/* + * External declarations + */ +extern Datum exec_hadoop_sql(PG_FUNCTION_ARGS); +extern Datum exec_on_extension(PG_FUNCTION_ARGS); + +enum EC_Status { EC_STATUS_INIT = 0, EC_STATUS_CONNECTED, EC_STATUS_EXECUTED, EC_STATUS_FETCHING, EC_STATUS_END }; + +#define NOT_EC_OPERATOR 0 +#define IS_EC_OPERATOR 1 +#define EC_LIBODBC_TYPE_ONE 1 /* libodbc.so.1 */ +#define EC_LIBODBC_TYPE_TWO 2 /* libodbc.so.2 */ + +#endif /* CONNECTOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/cstore.h postgresql-hll-2.14/include/include/cstore.h --- postgresql-hll-2.14_old/include/include/cstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/cstore.h 2020-12-12 17:06:43.183347213 +0800 @@ -0,0 +1,132 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore.h + * Common head file to support ColStore + * + * + * IDENTIFICATION + * src/include/cstore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_H +#define CSTORE_H + +#include "storage/relfilenode.h" +#include "vecexecutor/vectorbatch.h" + +/* 0~FirstCUID is reserved for page id of delta table + * We want to keep delta table small + */ +const int FirstCUID = 1000; +/* + * The size of full CU by default + */ +#define DefaultFullCUSize ((int)BatchMaxSize * 60) + +/* + * Invalid CU ID + */ +const uint32 InValidCUID = 0xffffffff; + +/* + * Dictionary virtual CU Id + */ +const uint32 DicVirtualCUID = 0xfffffffe; + +/* Warning threshold of CUID */ +const uint32 CUIDWarningThreshold = 0xfff00000; + +/* Max CUID */ +const uint32 MaxCUID = 0xfffffff0; + +/* The ID of system-defined attributes have used from -1 to -9. + * look up system-define attributes. you can refer to file sysattr.h + */ +const int VitrualDelColID = -10; + +const int VirtualSpaceCacheColID = -11; + +/* The attribute number of CUDesc table */ +const int CUDescColIDAttr = 1; +const int CUDescCUIDAttr = 2; +const int CUDescMinAttr = 3; +const int CUDescMaxAttr = 4; +const int CUDescRowCountAttr = 5; +const int CUDescCUModeAttr = 6; +const int CUDescSizeAttr = 7; +const int CUDescCUPointerAttr = 8; +const int CUDescCUMagicAttr = 9; +const int CUDescCUExtraAttr = 10; + +// The column number of CUDesc table. +// If that table schema change, we should change this const variable +// +#define CUDescMaxAttrNum 10 + +typedef uint64 CUPointer; + +/* + * Judge whether valid CUID + */ +#define IsValidCUID(CUId) ((CUId) != InValidCUID) + +/* + * Judge whether dictionary CUID + */ +#define IsDicVCU(CUId) ((CUId) == DicVirtualCUID) + +/* + * File node of GsCStore. It includes file type. + */ +typedef struct CFileNode : public BaseObject { + RelFileNode m_rnode; + ForkNumber m_forkNum; + int m_attid; + + CFileNode(RelFileNode rnode, ForkNumber forkNum = MAIN_FORKNUM) + { + m_rnode = rnode; + m_rnode.bucketNode = -1; + m_forkNum = forkNum; + m_attid = -1; + } + + CFileNode(RelFileNode rnode, int attid, ForkNumber forkNum = MAIN_FORKNUM) + { + m_rnode = rnode; + m_rnode.bucketNode = -1; + m_forkNum = forkNum; + m_attid = attid; + } + + CFileNode(const CFileNode& cFilenode) + { + m_rnode = cFilenode.m_rnode; + m_rnode.bucketNode = -1; + m_forkNum = cFilenode.m_forkNum; + m_attid = cFilenode.m_attid; + } +} CFileNode; + +/* + * CStorage allocate strategy. + */ +typedef enum { APPEND_ONLY, USING_FREE_SPACE } CStoreAllocateStrategy; + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/datasource/datasource.h postgresql-hll-2.14/include/include/datasource/datasource.h --- postgresql-hll-2.14_old/include/include/datasource/datasource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/datasource/datasource.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasource.h + * support for data source + * + * + * IDENTIFICATION + * src/include/datasource/datasource.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATASOURCE_H +#define DATASOURCE_H + +#include "nodes/parsenodes.h" + +typedef struct DataSource { + Oid sourceid; /* source Oid */ + Oid owner; /* source owner user Oid */ + char* srcname; /* name of the source */ + char* srctype; /* source type, optional */ + char* srcversion; /* source version, optional */ + List* options; /* source options as DefElem list */ +} DataSource; + +extern Oid get_data_source_oid(const char* sourcename, bool missing_ok); +extern DataSource* GetDataSource(Oid sourceid); +extern DataSource* GetDataSourceByName(const char* sourcename, bool missing_ok); + +#define EC_CIPHER_TEXT_LENGTH 1024 + +#endif /* DATASOURCE_H */ diff -uprN postgresql-hll-2.14_old/include/include/datatype/timestamp.h postgresql-hll-2.14/include/include/datatype/timestamp.h --- postgresql-hll-2.14_old/include/include/datatype/timestamp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/datatype/timestamp.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,233 @@ +/* ------------------------------------------------------------------------- + * + * timestamp.h + * Timestamp and Interval typedefs and related macros. + * + * Note: this file must be includable in both frontend and backend contexts. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/datatype/timestamp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATATYPE_TIMESTAMP_H +#define DATATYPE_TIMESTAMP_H + +#include +#include +#include + +/* + * Timestamp represents absolute time. + * + * Interval represents delta time. Keep track of months (and years), days, + * and hours/minutes/seconds separately since the elapsed time spanned is + * unknown until instantiated relative to an absolute time. + * + * Note that Postgres uses "time interval" to mean a bounded interval, + * consisting of a beginning and ending time, not a time span - thomas 97/03/20 + * + * We have two implementations, one that uses int64 values with units of + * microseconds, and one that uses double values with units of seconds. + * + * TimeOffset and fsec_t are convenience typedefs for temporary variables + * that are of different types in the two cases. Do not use fsec_t in values + * stored on-disk, since it is not the same size in both implementations. + * Also, fsec_t is only meant for *fractional* seconds; beware of overflow + * if the value you need to store could be many seconds. + */ + +#ifdef HAVE_INT64_TIMESTAMP + +typedef int64 Timestamp; +typedef int64 TimestampTz; +typedef int64 TimeOffset; +typedef int32 fsec_t; /* fractional seconds (in microseconds) */ +#else + +typedef double Timestamp; +typedef double TimestampTz; +typedef double TimeOffset; +typedef double fsec_t; /* fractional seconds (in seconds) */ +#endif + +typedef struct { + TimeOffset time; /* all time units other than days, months and + * years */ + int32 day; /* days, after time for alignment */ + int32 month; /* months and years, after time for alignment */ +} Interval; + +/* + * Convert an Interval to an approximate equivalent number of usec + */ +#define INTERVAL_TO_USEC(ivp) \ + ((ivp->month * DAYS_PER_MONTH * USECS_PER_DAY) + (ivp->day * USECS_PER_DAY) + ivp->time) + +#define MAX_TIMESTAMP_PRECISION 6 +#define MAX_INTERVAL_PRECISION 6 + +/* + * Round off to MAX_TIMESTAMP_PRECISION decimal places. + * Note: this is also used for rounding off intervals. + */ +#define TS_PREC_INV 1000000.0 +#define TSROUND(j) (rint(((double)(j)) * TS_PREC_INV) / TS_PREC_INV) + +/* + * Assorted constants for datetime-related calculations + */ + +#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */ +#define DAYS_PER_NYEAR 365 +#define MONTHS_PER_YEAR 12 +/* + * DAYS_PER_MONTH is very imprecise. The more accurate value is + * 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only + * return an integral number of days, but someday perhaps we should + * also return a 'time' value to be used as well. ISO 8601 suggests + * 30 days. + */ +#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */ +#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */ + +/* + * This doesn't adjust for uneven daylight savings time intervals or leap + * seconds, and it crudely estimates leap years. A more accurate value + * for days per years is 365.2422. + */ +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 +#define SECS_PER_HOUR 3600 +#define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 +#define MINS_PER_DAY (HOURS_PER_DAY * MINS_PER_HOUR) + +#define USECS_PER_DAY INT64CONST(86400000000) +#define USECS_PER_HOUR INT64CONST(3600000000) +#define USECS_PER_MINUTE INT64CONST(60000000) +#define USECS_PER_SEC INT64CONST(1000000) + +#define USECS_PER_MSEC 1000 +#define MSECS_PER_SEC 1000 +#define MSECS_PER_MIN (SECS_PER_MINUTE * MSECS_PER_SEC) + +/* + * We allow numeric timezone offsets up to 15:59:59 either way from Greenwich. + * Currently, the record holders for wackiest offsets in actual use are zones + * Asia/Manila, at -15:56:00 until 1844, and America/Metlakatla, at +15:13:42 + * until 1867. If we were to reject such values we would fail to dump and + * restore old timestamptz values with these zone settings. + */ +#define MAX_TZDISP_HOUR 15 /* maximum allowed hour part */ +#define TZDISP_LIMIT ((MAX_TZDISP_HOUR + 1) * SECS_PER_HOUR) + +/* + * DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity + */ +#ifdef HAVE_INT64_TIMESTAMP +#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1) +#define DT_NOEND (INT64CONST(0x7fffffffffffffff)) +#else /* !HAVE_INT64_TIMESTAMP */ +#ifdef HUGE_VAL +#define DT_NOBEGIN (-HUGE_VAL) +#define DT_NOEND (HUGE_VAL) +#else +#define DT_NOBEGIN (-DBL_MAX) +#define DT_NOEND (DBL_MAX) +#endif +#endif /* HAVE_INT64_TIMESTAMP */ + +#define TIMESTAMP_NOBEGIN(j) \ + do { \ + (j) = DT_NOBEGIN; \ + } while (0) + +#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN) + +#define TIMESTAMP_NOEND(j) \ + do { \ + (j) = DT_NOEND; \ + } while (0) + +#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND) + +#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) + +/* + * Julian date support. + * + * IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy + * about the maximum, since it's far enough out to not be especially + * interesting. + */ + +#define JULIAN_MINYEAR (-4713) +#define JULIAN_MINMONTH (11) +#define JULIAN_MINDAY (24) +#define JULIAN_MAXYEAR (5874898) + +#define IS_VALID_JULIAN(y, m, d) \ + (((y) > JULIAN_MINYEAR || \ + ((y) == JULIAN_MINYEAR && ((m) > JULIAN_MINMONTH || ((m) == JULIAN_MINMONTH && (d) >= JULIAN_MINDAY)))) && \ + (y) < JULIAN_MAXYEAR) + +#define JULIAN_MAX (2147483494) /* == date2j(JULIAN_MAXYEAR, 1, 1) */ + +/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */ +#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */ +#define POSTGRES_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */ + +#define MAX_VALUE_12_CLOCK (HOURS_PER_DAY / 2) +#define MIN_VALUE_12_CLOCK 1 + +#define MAX_VALUE_24_CLOCK (HOURS_PER_DAY) +#define MIN_VALUE_24_CLOCK 0 + +#define MAX_VALUE_MI (MINS_PER_HOUR) +#define MIN_VALUE_MI 0 + +#define MAX_VALUE_SS (SECS_PER_MINUTE) +#define MIN_VALUE_SS 0 + +#define MAX_VALUE_SSSSS 86400 +#define MIN_VALUE_SSSSS 0 + +#define MAX_VALUE_D 7 +#define MIN_VALUE_D 1 + +#define MAX_VALUE_DD 31 +#define MIN_VALUE_DD 1 + +#define MAX_VALUE_DDD 366 +#define MIN_VALUE_DDD 1 + +#define MAX_VALUE_MM 12 +#define MIN_VALUE_MM 1 + +#define MAX_VALUE_MS 999 +#define MIN_VALUE_MS 0 + +#define MIN_VALUE_YEAR -4712 +#define MAX_VALUE_YEAR 9999 + +#define MAX_VALUE_WW 53 +#define MIN_VALUE_WW 1 + +#define MAX_VALUE_W 5 +#define MIN_VALUE_W 1 + +/* to meet MAX_VALUE_YEAR */ +#define MAX_VALUE_J 5373484 +#define MIN_VALUE_J 1 + +#define MAX_VALUE_US 999999 +#define MIN_VALUE_US 0 + +#define MIN_VALUE_RR 0 +#define MID_VALUE_RR 49 +#define MAX_VALUE_RR 99 + +#endif /* DATATYPE_TIMESTAMP_H */ diff -uprN postgresql-hll-2.14_old/include/include/datatypes.h postgresql-hll-2.14/include/include/datatypes.h --- postgresql-hll-2.14_old/include/include/datatypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/datatypes.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * datatypes.h + * + * IDENTIFICATION + * src\include\datatypes.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef DATA_TYPES_H +#define DATA_TYPES_H + +typedef unsigned int Oid; +typedef uintptr_t Datum; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef int32_t int32; + +#endif /* DATA_TYPES_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/dbmind/hypopg_index.h postgresql-hll-2.14/include/include/dbmind/hypopg_index.h --- postgresql-hll-2.14_old/include/include/dbmind/hypopg_index.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/dbmind/hypopg_index.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * hypopg_index.h: Implementation of hypothetical indexes for PostgreSQL + * + * This file contains all includes for the internal code related to + * hypothetical indexes support. + * + * This program is open source, licensed under the PostgreSQL license. + * For license terms, see the LICENSE file. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Copyright (C) 2015-2018: Julien Rouhaud + * + * + * IDENTIFICATION + * src/include/dbmind/hypopg_index.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _HYPOPG_INDEX_H_ +#define _HYPOPG_INDEX_H_ + +/* -------------------------------------------------------- + * Hypothetical index storage, pretty much an IndexOptInfo + * Some dynamic informations such as pages and lines are not stored but + * computed when the hypothetical index is used. + */ +typedef struct hypoIndex { + Oid oid; /* hypothetical index unique identifier */ + Oid relid; /* related relation Oid */ + Oid reltablespace; /* tablespace of the index, if set */ + char *indexname; /* hypothetical index name */ + + BlockNumber pages; /* number of estimated disk pages for the + * index */ + double tuples; /* number of estimated tuples in the index */ + + /* index descriptor informations */ + int ncolumns; /* number of columns, only 1 for now */ + int nkeycolumns; /* number of key columns */ + short int *indexkeys; /* attnums */ + Oid *indexcollations; /* OIDs of collations of index columns */ + Oid *opfamily; /* OIDs of operator families for columns */ + Oid *opclass; /* OIDs of opclass data types */ + Oid *opcintype; /* OIDs of opclass declared input data types */ + Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */ + bool *reverse_sort; /* is sort order descending? */ + bool *nulls_first; /* do NULLs come first in the sort order? */ + Oid relam; /* OID of the access method (in pg_am) */ + + RegProcedure amcostestimate; /* OID of the access method's cost fcn */ + RegProcedure amcanreturn; /* OID of the access method's canreturn fcn */ + + List *indexprs; /* expressions for non-simple index columns */ + List *indpred; /* predicate if a partial index, else NIL */ + + bool predOK; /* true if predicate matches query */ + bool unique; /* true if a unique index */ + bool immediate; /* is uniqueness enforced immediately? */ + bool canreturn; /* can index return IndexTuples? */ + + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amhasgettuple; /* does AM have amgettuple interface? */ + bool amhasgetbitmap; /* does AM have amgetbitmap interface? */ + bool amcanunique; /* does AM support UNIQUE indexes? */ + bool amcanmulticol; /* does AM support multi-column indexes? */ + + /* store some informations usually saved in catalogs */ + List *options; /* WITH clause options: a list of DefElem */ + bool amcanorder; /* does AM support order by column value? */ +} hypoIndex; + +void InitHypopg(); +void hypopg_register_hook(); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/dfs_adaptor.h postgresql-hll-2.14/include/include/dfs_adaptor.h --- postgresql-hll-2.14_old/include/include/dfs_adaptor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/dfs_adaptor.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_adaptor.h + * Define macros of the same function for different platform. + * + * + * IDENTIFICATION + * src/include/dfs_adaptor.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ADAPTER_HH +#define ADAPTER_HH + +#include "dfs_config.h" + +#ifndef DFS_CXX_HAS_NOEXCEPT +#define noexcept DFS_NOEXCEPT +#endif + +#ifndef DFS_CXX_HAS_OVERRIDE +#define override DFS_OVERRIDE +#endif + +#ifdef HAS_DIAGNOSTIC_PUSH +#ifdef __clang__ +#define DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") +#define DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +#define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +#define DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#else +#error("Unknown compiler") +#endif +#else +#define DIAGNOSTIC_PUSH +#define DIAGNOSTIC_POP +#endif + +#define PRAGMA(TXT) _Pragma(#TXT) + +#ifdef __clang__ +#define DIAGNOSTIC_IGNORE(XXX) PRAGMA(clang diagnostic ignored XXX) +#elif defined(__GNUC__) +#define DIAGNOSTIC_IGNORE(XXX) PRAGMA(GCC diagnostic ignored XXX) +#else +#define DIAGNOSTIC_IGNORE(XXX) +#endif + +#ifndef DFS_CXX_HAS_UNIQUE_PTR +#define unique_ptr auto_ptr +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX 0xffffffff +#endif + +#define GTEST_LANG_CXX11 0 + +#endif /* ADAPTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/dfs_config.h postgresql-hll-2.14/include/include/dfs_config.h --- postgresql-hll-2.14_old/include/include/dfs_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/dfs_config.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,93 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_config.h + * + * + * + * IDENTIFICATION + * src/include/dfs_config.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFS_UNIQUE_H +#define DFS_UNIQUE_H + +#define DFS_CXX_HAS_CSTDINT +#define DFS_CXX_HAS_INITIALIZER_LIST +#define DFS_CXX_HAS_NOEXCEPT +#define DFS_CXX_HAS_NULLPTR +#define DFS_CXX_HAS_OVERRIDE +#define DFS_CXX_HAS_UNIQUE_PTR + +#ifdef DFS_CXX_HAS_CSTDINT +#include +#else +#include +#endif + +#ifdef DFS_CXX_HAS_NOEXCEPT +#define DFS_NOEXCEPT noexcept +#else +#define DFS_NOEXCEPT throw() +#endif + +#ifdef DFS_CXX_HAS_NULLPTR +#define DFS_NULLPTR nullptr +#else +namespace dfs { +class nullptr_t { +public: + template + operator T *() const + { + return 0; + } + + template + operator T C::*() const + { + return 0; + } + +private: + void operator&() const; // whose address can't be taken +}; +const nullptr_t nullPtr = {}; +} // namespace dfs +#define DFS_NULLPTR dfs::nullPtr +#endif + +#ifdef DFS_CXX_HAS_OVERRIDE +#define DFS_OVERRIDE override +#else +#define DFS_OVERRIDE +#endif + +#ifdef DFS_CXX_HAS_UNIQUE_PTR +#define DFS_UNIQUE_PTR std::unique_ptr +#else +#define DFS_UNIQUE_PTR std::auto_ptr +namespace dfs { +template +inline T move(T &x) +{ + return x; +} +} // namespace dfs +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/dfsdesc.h postgresql-hll-2.14/include/include/dfsdesc.h --- postgresql-hll-2.14_old/include/include/dfsdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/dfsdesc.h 2020-12-12 17:06:43.184347225 +0800 @@ -0,0 +1,634 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfsdesc.h + * classes & routines to support dfsdesc + * + * + * IDENTIFICATION + * src/include/dfsdesc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DFSDESC_H +#define DFSDESC_H + +#include "securec.h" +#include "securec_check.h" +#include "nodes/pg_list.h" +#include "utils/snapshot.h" +#include "access/htup.h" +#include "access/tupdesc.h" + +#define DfsDescMaxAttrNum 11 + +#define Anum_pg_dfsdesc_duid 1 +#define Anum_pg_dfsdesc_partid 2 +#define Anum_pg_dfsdesc_rowcount 3 +#define Anum_pg_dfsdesc_magic 4 +#define Anum_pg_dfsdesc_min 5 +#define Anum_pg_dfsdesc_max 6 +#define Anum_pg_dfsdesc_deletemap 7 +#define Anum_pg_dfsdesc_relativelyfilename 8 +#define Anum_pg_dfsdesc_extra 9 +#define Anum_pg_dfsdesc_columnmap 10 +#define Anum_pg_dfsdesc_filesize 11 + +#define MAX_LOADED_DFSDESC 100 +#define MAX_DFS_FILE_NAME_SIZE 256 + +#define MIN_MAX_SIZE 32 +#define BITS_IN_BYTE 8 +#define MEGA_SHIFT 20 + +#define DFSDESC_MAX_COL DfsDescMaxAttrNum +#define NON_PARTITION_TALBE_PART_NUM 0xFFFF +#define NULL_MAGIC 255 + +#define DfsDescIndexMaxAttrNum 1 + +/* + * Since the attno starts at 1, so the first bit of the map is never used. + * so we need add 1 here to avoid memory overflow. + */ +#define GET_COLMAP_LENGTH(nCols) (((uint32)(int32)(nCols) >> 3) + 1) + +/* + * we need to get the delete map, column map, min value, max value from + * Desc table. the logic of getting delete map is same to the logic of + * getting column. Between the logic of getting min value and logic of + * getting max value are same. + * So build a enum for function parameter. + */ +typedef enum { DELETE_MAP_ATTR = 0, COLUMN_MAP_ATTR, MIN_COLUMN_ATTR, MAX_COLUMN_ATTR } ColumnEnum; + +typedef struct { + int Len; + char szContent[MIN_MAX_SIZE]; + +} stMinMax; + +class DFSDesc : public BaseObject { +public: + DFSDesc(); + DFSDesc(uint32 PartId, uint32 DescId, uint32 ColCnt); + + void Destroy(); + virtual ~DFSDesc(); + +public: + /* + * get column count + */ + uint32 GetColCnt() const + { + return m_ColCnt; + } + /* + * set column count + */ + void SetColCnt(uint32 ColCnt) + { + m_ColCnt = ColCnt; + } + + /* + * get transaction Id that alway is tuple xmin if has set + */ + uint32 GetXId() const + { + return m_Xmin; + } + + /* + * set transaction Id (tuple xmin) + */ + void SetXId(uint32 XId) + { + m_Xmin = XId; + } + + /* + * get the descriptor Id + */ + uint32 GetDescId() const + { + return m_DescId; + } + + /* + * set the descriptor Id + */ + void SetDescId(uint32 DescId) + { + m_DescId = DescId; + } + + /* + * get the row count include those deleted + */ + uint32 GetRowCnt() const + { + return m_RowCnt; + } + + /* + * get the row count include those deleted + */ + void SetRowCnt(uint32 RowCnt) + { + m_RowCnt = RowCnt; + } + + /* get the size of hdfs file */ + int64 GetFileSize() const + { + return m_FileSize; + } + + /* set the size of hdfs file */ + void SetFileSize(int64 FileSize) + { + m_FileSize = FileSize; + } + + /* + * get the magic that may be the current transaction Id(cu use that) + */ + uint32 GetMagic() const + { + return m_Magic; + } + + /* + * set the magic that may be the current transaction Id(cu use that) + */ + void SetMagic(uint32 Magic) + { + m_Magic = Magic; + } + + /* + * get file name + */ + const char* GetFileName() const + { + return m_FileName; + } + + /* + * set file name + */ + void SetFileName(const char* pFileName) + { + if (pFileName != NULL) { + size_t len = strlen(pFileName); + if (0 == m_name_len) { + m_FileName = (char*)palloc(len + 1); + m_name_len = len + 1; + } + + if ((len + 1) > m_name_len) { + m_FileName = (char*)repalloc(m_FileName, len + 1); + m_name_len = len + 1; + } + + errno_t rc = strcpy_s(m_FileName, m_name_len, pFileName); + securec_check(rc, "", ""); + } + + return; + } + + /** + * @Description: Set the column map. + * @in colMap, The column map string. + * @in length, The length of colMap string. + * @return None. + */ + void setColMap(const char* colMap, int length) + { + if (colMap != NULL) { + errno_t rc = EOK; + m_colMap = (char*)palloc0(length + 1); + rc = memcpy_s(m_colMap, length + 1, colMap, length); + securec_check(rc, "", ""); + m_colMapLen = length; + } else { + /* + * Never occur here. + */ + ereport(ERROR, (errcode(ERRCODE_UNDEFINED_COLUMN), errmsg("The table has no column."))); + } + } + + /** + * @Description: Get the column map. + * @return return the column map. + */ + const char* getColMap() + { + return m_colMap; + } + + /** + * @Description: Get the length of column map binary. + * @return the length. + */ + uint32 getColMapLength() + { + return m_colMapLen; + } + + /** + * @Description: Whether the column is default column. The default column means + * that the column value is stored in pg_attribute. + * @in attNo, The attribute number of the column. It starts from 1. + * @return If the column is default column, return true, otherwise retuen false. + */ + bool isDefaultColumn(uint32 attNo) + { + Assert(NULL != m_colMap); + bool defaultCol = true; + if ((attNo >> 3) > m_colMapLen) { + defaultCol = true; + } else if ((unsigned char)m_colMap[attNo >> 3] & (1 << (attNo % BITS_IN_BYTE))) { + defaultCol = false; + } + return defaultCol; + } + + /* + * get the table partition id + */ + uint32 GetPartId() const + { + return m_PartId; + } + + /* + * set the table partition id + */ + void SetPartId(uint32 PartId) + { + m_PartId = PartId; + } + + /* + * @Description: get the min value according to the column number + * @IN Col: the column number + * @Return: the min value or NULL + * @See also: + */ + stMinMax* GetMinVal(uint32 Col) const + { + if ((Col >= m_ColCnt) || (m_MinVal == NULL)) { + return NULL; + } + + return m_MinVal[Col]; + } + + /* + * @Description: set the min value + * @IN Col: column id + * @IN pMinVal: the string of min value + * @IN Size: the size of string + * @Return: 0 if success, 1 if fail + * @See also: + */ + int SetMinVal(uint32 Col, const char* pMinVal, uint32 Size); + + /* + * @Description: get the max value according to the column number + * @IN Col: the column number + * @Return: the max value or NULL + * @See also: + */ + stMinMax* GetMaxVal(uint32 Col) const + { + if ((Col >= m_ColCnt) || (m_MinVal == NULL)) { + return NULL; + } + + return m_MaxVal[Col]; + } + + /* + * @Description: set the max value + * @IN Col: column id + * @IN pMinVal: the string of max value + * @IN Size: the size of string + * @Return: 0 if success, 1 if fail + * @See also: + */ + int SetMaxVal(uint32 Col, const char* pMaxVal, uint32 Size); + + /* + * set the delete map value,Just copy + */ + int MaskDelMap(const char* pDelMap, uint32 Size, bool ChkDelHasDone = true); + + /* + * get the delete map value + */ + const char* GetDelMap() const + { + return m_DelMap; + } + + /*tell whether is deleted by row number*/ + bool IsDeleted(uint32 Row) + { + bool Ret = false; + + /*not set delmap means none was deleted. exceed row scope also tell false*/ + if ((m_DelMap == NULL) || (Row >= m_RowCnt)) { + Ret = false; + } else { + if ((unsigned char)m_DelMap[Row >> 3] & (1 << (Row % 8))) { + Ret = true; + } + } + + return Ret; + } + + void Reset(); + + /* tid for this desc tuple */ + ItemPointerData tid; + +private: + int AllocMinMax(); + void DeallocMinMax(); + int AllocDelMap(); + void DeallocDelMap(); + +private: + /* + * DfsDesc Id + */ + uint32 m_DescId; + + /* + * row count include those deleted + */ + uint32 m_RowCnt; + + /* file size */ + int64 m_FileSize; + + /* + * column count of the table that described + */ + uint32 m_ColCnt; + + /* + *delete map buffer size in bytes + */ + uint32 m_DelMapBaseSize; + /* + *min&max buffer size in bytes (one column) + */ + uint32 m_MinMaxBaseSize; + + /* + *partition id of the table that described + */ + uint32 m_PartId; + + /* + * magic id + */ + uint32 m_Magic; + + /* + * transation id + */ + uint32 m_Xmin; + + /* + * Orc file name + */ + char* m_FileName; + size_t m_name_len; + +public: + /* + * Min values array + * the column min value format is (head byte - total length + other bytes - actual min value) + for example the column is INT type and the min value is 1 + then the head byte store the length is 5, and next 4 bytes is the 1 values + + */ + stMinMax** m_MinVal; + + /* + * Max values array + * the column max value format is (head byte - length + other bytes - actual max value) + for example the column is INT type and the max value is 1 + then the head byte store the length is 5 and next 4 bytes is the 1 values + */ + stMinMax** m_MaxVal; + +private: + /* + * delete map values + */ + char* m_DelMap; + + /** + * It stores the columns by bitmap method. When read data, the m_colMap stores + * the columns which is included in the corresponding file. When insert data, + * the m_colMap stores all columns, but it excludeds dropped columns. + */ + char* m_colMap; + uint32 m_colMapLen; +}; + +class DFSDescHandler : public BaseObject { + +public: + /** + * @Description: The construct function. + * @in MaxBatCnt, Max load count in one batch. + * @in SrcRelCols, The column count of described table. + * @in mainRel, The main table. + * @return None. + */ + DFSDescHandler(uint32 MaxBatCnt, int SrcRelCols, Relation mainRel); + + /* + * deconstruction + */ + virtual ~DFSDescHandler(); + +public: + /* + * load dfs descriptors in rows + * pDFSDescArray [in/out] - DFSDesc array to Contain descriptors + * Size[in] -size of DFSDesc array + * Partid[in] - which table partition to load (partition table use it actual id, + * non-partition table use NON_PARTITION_TALBE_PART_NUM) + * StartDescId [in]- the descriptor id to start load + * SnapShot [in] - which snapshot, fill NULL is to use GetActiveSnapshot + * pLoadCnt [out] - contain the number of exact loaded + * pLastId[out] - the last descriptor id loaded + * + * return 0 if success + */ + int Load(DFSDesc* pDFSDescArray, uint32 Size, uint32 PartId, uint32 StartDescId, Snapshot SnapShot, + uint32* pLoadCnt, uint32* pLastId); + + /* + * We always generate xlog for dfsdesc tuple + */ + /* + * add dfs descriptors in rows + * pDFSDescArray [in] - DFSDesc array to append + * Size[in] -size of DFSDesc array + * CmdId[in] - the command id + * options [in]- the options heap_insert, (advice generate xlog for dfsdesc tuple) + * + * return 0 if success + */ + int Add(DFSDesc* pDFSDescArray, uint32 Cnt, CommandId CmdId, int Options); + + /* + * delete rows by mask the delete map buffer + * Tid [in] - file id & row offset + * return none + */ + uint32 SetDelMap(ItemPointer Tid, bool reportError); + + /* + * flush the delete map buffer to descriptor + * return none + */ + void FlushDelMap(); + + /* + * get how many rows not deleted + */ + uint64 GetLivedRowNumbers(int64* deadrows); + + /* + * dfsdesc to tuple + * pDFSDesc[in] - which descriptor to handle + * pTupVals[in/out] - the values of columns + * pTupNulls[in/out] - mark which column is NULL + * DfsDescTupDesc[in] - description of the heap tuple + * return the heap tuple + */ + HeapTuple DfsDescToTuple(DFSDesc* pDFSDesc, Datum* pTupVals, bool* pTupNulls, TupleDesc DfsDescTupDesc); + + /* + * dfsdesc to tuple + * HeapTuple [in]- which heap tuple to handle + * DfsDescTupDesc[in] - description of the heap tuple + * pDFSDesc[out] - the DFSDesc changed from heap tuple + */ + void TupleToDfsDesc(HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc); + + /* + * get list of desc tuples in which some row(s) was deleted + */ + List* GetDescsToBeMerged(Snapshot _snapshot); + + /* + * get all desc tuples + */ + List* GetAllDescs(Snapshot _snapshot); + + /* + * test whether row is deleted in one desc tuple + */ + bool ContainDeleteRow(const char* all_valid_bitmap, int bitmap_length, const char* delmap, int rows) const; + + /* + * delete one desc tuple + */ + void DeleteDesc(DFSDesc* desc) const; + +private: + /* + * get list of desc tuples in which some row(s) was deleted or not + */ + List* GetDescTuples(Snapshot _snapshot, bool only_tuples_with_invalid_data); + + /** + * @Description: Set minimum/maximun value of the each column in current file from Desc table. + * @in pCudescTup, The HeapTuple struct. + * @in DfsDescTupDesc, The TupleDesc struct. + * @out DFSDesc, The DFSDesc struct. + * @out columnAttr, the column to be got value, the column is min value column + * or max value column. So value of the columnAttr only is MIN_COLUMN_ATTR or + * MAX_COLUMN_ATTR. + * @return + */ + void setMinMaxByHeapTuple(HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc, ColumnEnum columnAttr); + + /** + * @Description: Set map value in current file from Desc table. The map has two + * kind types, one is delete map, the other one is column map. + * @in pCudescTup, The HeapTuple struct. + * @in DfsDescTupDesc, The TupleDesc struct. + * @out DFSDesc, The DFSDesc struct. + * @out columnAttr, the column to be got value, the column is deletemap column + * or colmap column. So value of the columnAttr only is DELETE_MAP_ATTR or + * COLUMN_MAP_ATTR. + * @return + */ + void setMapColumnByHeapTuple( + HeapTuple pCudescTup, TupleDesc DfsDescTupDesc, DFSDesc* pDFSDesc, ColumnEnum columnAttr); + /* + * dfs descriptor table id + */ + Oid m_TableOid; + + /* + * dfs descriptor index table id(the index by partition id and desc id) + */ + Oid m_IndexOid; + /* + * The main relation. + */ + Relation m_mainRel; + + /* + * the column count of described table + */ + uint32 m_SrcRelCols; + + /* + * max batch rows + */ + uint32 m_MaxBatCnt; + + /*the file id to set delmap*/ + int32 m_DelMapFileId; + + /*the delmap cache for a fileid*/ + char* m_pDelMap; + + /*the delmap cache size*/ + uint32 m_DelMapSize; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamConsumer.h postgresql-hll-2.14/include/include/distributelayer/streamConsumer.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamConsumer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamConsumer.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,116 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamConsumer.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamConsumer.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ + +#include "distributelayer/streamCore.h" + +class StreamConsumer; +typedef struct { + StreamConsumer* consumer; + int connNum; + int connInfoSize; + StreamConnInfo* connInfo; +} StreamValue; + +/* Element in stream information table. */ +typedef struct { + StreamKey key; + StreamValue* value; +} StreamElement; + +class StreamConsumer : public StreamObj { +public: + StreamConsumer(MemoryContext context); + + ~StreamConsumer(); + + /* Init the consumer object. */ + void init(StreamKey key, List* execProducerNodes, ParallelDesc desc, StreamTransType transType, + StreamSharedContext* sharedContext); + + /* Deinit the consumer. */ + void deInit(); + + /* Waiting for the producer is ready. */ + void waitProducerReady(); + + /* Find un connect producer. */ + void findUnconnectProducer(StringInfo str); + + /* Get nodeIdx of producer which is waited for. */ + int getFirstUnconnectedProducerNodeIdx(); + + /* Wake up consumer and let it work. */ + static bool wakeUpConsumerCallBack(CommStreamKey commKey, StreamConnInfo connInfo); + + /* Release comm mode stream. */ + void releaseCommStream(); + + /* Get nodeIdx of producer by nodename. */ + int getNodeIdx(const char* nodename); + + /* Get shared context for local stream. */ + inline StreamSharedContext* getSharedContext() + { + return m_sharedContext; + } + + /* + * Record the orign node list in case of DN pruned in with-recursive execution + * mode, store the corresponding producer connection list from which the + * ExecStream will get + */ + List* m_originProducerNodeList; + +private: + + /* Update the stream info. */ + bool updateStreamCommInfo(StreamConnInfo* connInfo); + + /* Update the transport info. */ + void updateTransportInfo(StreamValue* val); + +private: + /* Current producer number. */ + int m_currentProducerNum; + + /* All producer is ready or not. */ + bool m_ready; + + /* Expected producer info. */ + StreamConnInfo* m_expectProducer; + + /* Mutex and condition waiting for producer is ready. */ + pthread_mutex_t m_mutex; + + pthread_cond_t m_cond; + + StreamSharedContext* m_sharedContext; +}; + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMCONSUMER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamCore.h postgresql-hll-2.14/include/include/distributelayer/streamCore.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamCore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamCore.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,498 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamCore.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamCore.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ + +#include + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "pgxc/execRemote.h" +#include "optimizer/planner.h" +#include "optimizer/streamplan.h" +#include "libcomm/libcomm.h" +#include "libpq/libpq-be.h" +#include "libpq/pqformat.h" +#include "access/xact.h" +#include "utils/distribute_test.h" +#include +#include "storage/spin.h" +#include "workload/workload.h" +#include "pgstat.h" +#include "distributelayer/streamTransportCore.h" + +/* The max stream thread in one node. */ +#define MAX_STREAM_PER_PLAN 128 + +/* The max number of nodes that stream can connect. */ +#define INIT_STREAMINFO_SIZE 64 + +#define STREAM_BUF_INIT_SIZE 16 * 1024 + +#define PRINTTRUE(A) (((A) == true) ? "true" : "false") + +#define TupleVectorMaxSize 100 + +struct StreamState; +class StreamObj; +class StreamNodeGroup; +struct SyncController; + +typedef bool (*scanStreamFun)(StreamState* node); +typedef bool (*deserializeStreamFun)(StreamState* node); + +typedef struct { + uint64 queryId; /* u_sess->debug_query_id */ + unsigned int planNodeId; + unsigned int smpIdentifier; +} StreamKey; + +typedef union { + struct { + int fd; + } tcpLayer; + + struct { + gsocket gsock; /* libcomm logic socket */ + } libcomm_layer; +} StreamIdentity; + +typedef struct StreamConnInfo { + StreamIdentity port; + char nodeName[NAMEDATALEN]; + Oid nodeoid; + int nodeIdx; /* datanode index, like PGXCNodeId */ + unsigned int producerSmpId; /* For SCTP, mark connect which producer */ +} StreamConnInfo; + +typedef struct { + ThreadId key; + StreamNodeGroup* value; +} StreamNodeElement; + +typedef struct { + uint64 key; +} StreamConnectSyncElement; + +enum StreamObjType { + STREAM_PRODUCER, + STREAM_CONSUMER, +}; + +enum StreamObjStatus { + STREAM_UNDEFINED, + STREAM_INPROGRESS, + STREAM_COMPLETE, + STREAM_ERROR, +}; + +typedef struct { + StreamObj* streamObj; /* A stream Node has only one or null producer object. */ + List* consumerList; /* A stream Node may contain many consumer. */ + StreamObjStatus status; + bool* stopFlag; +} StreamNode; + +typedef struct { + StreamKey key; + List* producerList; /* corresponding producer. */ + List* consumerList; /* corresponding consumer. */ + int expectThreadNum; /* producer thread sub thread number. */ + int createThreadNum; +} StreamPair; + +enum DataStatus { + DATA_EMPTY, + DATA_PREPARE, + DATA_READY, + CONN_ERR, +}; + +enum EdataWriteStatus { + EDATA_WRITE_ENABLE, + EDATA_WRITE_START, + EDATA_WRITE_FINISH, + ERROR_READ_FINISH, +}; + +typedef struct TupleVector { + TupleTableSlot** tupleVector; + int tuplePointer; +} TupleVector; + +typedef struct StreamSharedContext { + MemoryContext localStreamMemoryCtx; /**/ + VectorBatch*** sharedBatches; + TupleVector*** sharedTuples; + StringInfo** messages; + DataStatus** dataStatus; + bool** is_connect_end; + int* scanLoc; + TcpStreamKey key_s; + bool vectorized; + struct hash_entry** poll_entrys; + struct hash_entry*** quota_entrys; +} StreamSharedContext; + +typedef struct StreamSyncParam { + Oid TempNamespace; + Oid TempToastNamespace; + bool IsBinaryUpgrade; + bool CommIpcLog; +} StreamSyncParam; + +class StreamObj : public BaseObject { +public: + StreamObj(MemoryContext context, StreamObjType type); + ~StreamObj(); + + /* Initiliaze the stream environment. */ + static void startUp(); + + /* Get the node group. */ + StreamNodeGroup* getNodeGroup(); + + /* Set stream thread id. */ + void setThreadId(ThreadId pid); + + /* Set stream pair. */ + void setPair(StreamPair* pair); + + /* Get the stream key. */ + StreamKey getKey(); + + /* Get the stream type. */ + StreamObjType getType(); + + /* Get parallel description. */ + ParallelDesc getParallelDesc(); + + /* Get stream thread id. */ + ThreadId getThreadId(); + + /* Get the pgxc data node id. */ + int getPgxcNodeId(); + + /* Get the index itself in the group. */ + int getNodeGroupIdx(); + + /* Get the stream pair. */ + StreamPair* getPair(); + + /* Get the stream plan node. */ + Stream* getStream(); + + /* Get stream transport. */ + StreamTransport** getTransport(); + + /* Get connection number. */ + int getConnNum(); + + /* Release net port. */ + void releaseNetPort(); + + /* Release net port in hash table. */ + static void releaseNetPortInHashTable(); + + /* Stream node group belongs to. */ + StreamNodeGroup* m_nodeGroup; + + /* Stream transport array. */ + StreamTransport** m_transport; + + /* Stream pair. */ + StreamPair* m_pair; + +protected: + /* Stream type. */ + StreamObjType m_type; + + /* Stream key. */ + StreamKey m_key; + + /* Memory context the stream object use. */ + MemoryContext m_memoryCxt; + + /* Stream transportation type. */ + StreamTransType m_transtype; + + /* Expected socket number. */ + int m_connNum; + + /* Stream node. */ + Stream* m_streamNode; + + /* Identify itself in the group. */ + int m_nodeGroupIdx; + + /* The thread id that take the stream object. */ + ThreadId m_threadId; + + /* The node id that the stream thread is running on. */ + int m_nodeId; + + /* Stream object is init or not. */ + bool m_init; + + /* Stream sync object is init or not. */ + bool m_threadSyncObjInit; + + /* Stream object status. */ + StreamObjStatus m_status; + + /* Parallel description. */ + ParallelDesc m_parallel_desc; + +protected: + /* Global context stream object using. */ + static MemoryContext m_memoryGlobalCxt; + + /* Hash table for stream information, mainly for stream connect. */ + static HTAB* m_streamInfoTbl; + +public: + /* Mutex for stream info table. */ + static pthread_mutex_t m_streamInfoLock; +}; + +/* Stream node group is book keeper for stream object. */ +class StreamNodeGroup : public BaseObject { +public: + StreamNodeGroup(); + + ~StreamNodeGroup(); + + /* Init stream node group. */ + void Init(int threadNum); + + /* Init some static member. */ + static void StartUp(); + + /* Stop all register stream thread in the node group. */ + static void stopAllThreadInNodeGroup(ThreadId pid, uint64 query_id); + + /* Destory a stream Node group, clean some status. */ + static void destroy(StreamObjStatus status); + + /* Synchronize quit. */ + static void syncQuit(StreamObjStatus status); + + /* Grant stream connect permission. */ + static void grantStreamConnectPermission(); + + /* Revoke stream connect permission. */ + static void revokeStreamConnectPermission(); + + /* Check if can accept connection. */ + static bool checkStreamConnectPermission(uint64 query_id); + + /* Clear the stream node group. */ + void deInit(StreamObjStatus status); + + /* Register the object in stream node group. */ + int registerStream(StreamObj* obj); + + /* Unregister the stream object represented in group idx with status. */ + void unregisterStream(int groupIdx, StreamObjStatus status); + + /* Send signal to all stream thread registered in node group. */ + void signalStreamThreadInNodeGroup(int signo); + + /* Cancel all stream thread registered in node group. */ + static void cancelStreamThread(); + + /* Set the stop flag. */ + void setStopFlagPoint(int groupIdx, bool* stopFlag); + + /* Set the node status. */ + void setNodeStatus(int groupIdx, StreamObjStatus status); + + /* Wait all thread in the node group to quit. */ + void quitSyncPoint(); + + /* Push a stream pair. */ + StreamPair* pushStreamPair(StreamKey key, List* producer, List* consumer); + + /* Pop a stream pair according to key. */ + StreamPair* popStreamPair(StreamKey key); + + /* Get stream pair list */ + List* getStreamPairList(); + + /* Start a stream thread. */ + void initStreamThread(StreamProducer* producer, uint8 smpIdentifier, StreamPair* pair); + + /* In the same node group? */ + bool inNodeGroup(ThreadId pid1, ThreadId pid2); + + /* Restore stream enter. */ + void restoreStreamEnter(); + + /* Set need clean flag. */ + void setNeedClean(bool flag); + + /* Check if query already canceled. */ + bool isQueryCanceled() + { + return m_canceled; + } + + /* Save the first error data of producer */ + void saveProducerEdata(); + + /* Get the saved error data of producer */ + ErrorData* getProducerEdata(); + + /* Stream Consumer List. */ + List* m_streamConsumerList; + + /* Stream Producer List. */ + List* m_streamProducerList; + + /* Controller list for recursive */ + List* m_syncControllers; + + MemoryContext m_streamRuntimeContext; + + /* Save the first error data of producer thread */ + ErrorData* m_producerEdata; + + /* MPP with-recursive support */ + static void SyncConsumerNextPlanStep(int controller_plannodeid, int step); + static void SyncProducerNextPlanStep(int controller_plannodeid, int producer_plannodeid, int step, int tuple_count, + bool* need_rescan, int target_iteration); + + void ConsumerNodeStreamMessage(StreamState* node); + void ConsumerGetSyncUpMessage(RecursiveUnionController* controller, int step, StreamState* node, char msg_type); + void ConsumerMarkRUStepStatus(RecursiveUnionController* controller, int step, int iteration, StreamState* node, + int pgxc_nodeid, int producer_plannodeid, int tuple_processed); + void ProducerSendSyncMessage( + RecursiveUnionController* controller, int producer_plannodeid, int step, int tuple_count, char msg_type); + void ProducerFinishRUIteration(int step); + static bool IsRecursiveUnionDone(RecursiveUnionState* state); + static bool IsRUCoordNode(); + static bool IsRUSyncProducer(); + void AddSyncController(SyncController* controller); + SyncController* GetSyncController(int controller_plannodeid); + void MarkSyncControllerStopFlagAll(); + + inline pthread_mutex_t* GetStreamMutext() + { + return &m_mutex; + }; + + inline pthread_mutex_t* GetRecursiveMutex() + { + return &m_recursiveMutex; + }; + + inline uint64 GetQueryId(); + + inline void SetRecursiveVfdInvalid() + { + m_recursiveVfdInvalid = true; + } + + inline bool GetRecursiveVfdInvalid() + { + return m_recursiveVfdInvalid; + } + + /* Mark recursive vfd is invalid before aborting transaction. */ + static void MarkRecursiveVfdInvalid(); + +private: + /* Set the executor stop flag to true. */ + void stopThread(); + + /* Top consumer pid also the node group creator pid. */ + ThreadId m_pid; + + /* How many stream object can hold. */ + int m_size; + + /* How many stream object currently hold. */ + int m_streamNum; + + /* Stream Object Node Container. */ + StreamNode* m_streamArray; + + /* Stream Pair list. */ + List* m_streamPairList; + + /* A counter that't signal the stream thread group can destroy. */ + volatile int m_quitWaitCond; + + /* A counter remeber the already created thread number. */ + volatile int m_createThreadNum; + + /* A flag to indicate stream enter the quit point. */ + volatile int m_streamEnter; + + /* Mutex and condition waiting for all thread in the node group is complete. */ + pthread_mutex_t m_mutex; + + pthread_cond_t m_cond; + + /* Mark if query already canceled. */ + bool m_canceled; + + /* Mark if need clean stream info hash table. */ + bool m_needClean; + + /* First error data write protect */ + int m_edataWriteProtect; + + /* Mark if query failed. */ + bool m_errorStop; + + /* Mark if VFD of recursive is invalid. */ + bool m_recursiveVfdInvalid; + + /* Mutex for sync controller and vfd operation. */ + pthread_mutex_t m_recursiveMutex; + + /* Global context stream object using. */ + static MemoryContext m_memoryGlobalCxt; + + /* Hash table for stream node group. */ + static HTAB* m_streamNodeGroupTbl; + + /* Mutex for stream node group. */ + static pthread_mutex_t m_streamNodeGroupLock; + + /* Hash table for stream connect sync. */ + static HTAB* m_streamConnectSyncTbl; + + /* Mutex for stream connect sync. */ + static pthread_mutex_t m_streamConnectSyncLock; +}; + +extern bool IsThreadProcessStreamRecursive(); + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMCORE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamMain.h postgresql-hll-2.14/include/include/distributelayer/streamMain.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamMain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamMain.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * streamMain.h + * stream main Interface + * + * IDENTIFICATION + * src/include/distributelayer/streamMain.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef STREAM_MAIN_H +#define STREAM_MAIN_H + +extern int StreamMain(); +extern void SetStreamWorkerInfo(class StreamProducer* proObj); +extern void ResetStreamEnv(); +extern void ExtractProduerInfo(); +extern ThreadId ApplyStreamThread(StreamProducer *producer); +extern void RestoreStream(); +extern void StreamExit(); +extern void RestoreStreamSyncParam(struct StreamSyncParam *syncParam); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamProducer.h postgresql-hll-2.14/include/include/distributelayer/streamProducer.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamProducer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamProducer.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,506 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamProducer.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamProducer.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ +#define SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ + +#include "distributelayer/streamCore.h" + +#define VALUE_TYPE 0 +#define NUMERIC_TYPE 1 +#define VARLENA_TYPE 2 +#define CSTRING_TYPE 3 +#define TID_TYPE 4 +#define FIXED_TYPE 5 + +class StreamProducer : public StreamObj { +public: + StreamProducer(StreamKey key, PlannedStmt* pstmt, Stream* streamNode, MemoryContext context, int socketNum, + StreamTransType type); + + ~StreamProducer(); + + /* Init the stream producer. */ + void init(TupleDesc desc, StreamTxnContext txnCxt, ParamListInfo params, int parentPlanNodeId); + + /* Init stream key */ + void initStreamKey(); + + /* Init dataskew info. */ + void initSkewState(); + + typedef void (StreamProducer::*criticalSectionFunc)(void); + + /* Connect consumer. */ + void connectConsumer(libcomm_addrinfo** consumerAddr, int& count, int totalNum); + + /* Enter critical section for net protect purpose. */ + void enterCriticalSection(criticalSectionFunc func); + + /* Deinit the producer. */ + void deInit(StreamObjStatus status); + + /* Init the net environment. */ + void netInit(); + + /* Init the net port. */ + void netPortInit(); + + /* Release net port with protect. */ + void releaseUninitializeResourceWithProtect(); + + /* Release net port of sub consumers. */ + void releaseSubConsumerList(); + + /* Release net port if net is not init yet. */ + void releaseUninitializeResource(); + + /* Register producer thread into thread node group, it should be call in the stream thread. */ + void registerGroup(); + + /* Switch the send direction to the nth channel. */ + bool netSwitchDest(int nthChannel); + + /* Save some network status for next sending. */ + void netStatusSave(int nthChannel); + + /*======== Data stream function for tuple ============*/ + /* Broadcast the tuple. */ + void broadCastStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local broadcast the tuple through memory. */ + void localBroadCastStream(TupleTableSlot* tuple); + + /* Redistribute the tuple. */ + void redistributeStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local redistribute the tuple through memory. */ + void localRedistributeStream(TupleTableSlot* tuple); + + void redistributeSkewStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Send tuple with Roundrobin. */ + void roundRobinStream(TupleTableSlot* tuple, DestReceiver* self); + + /* Local roundrobin the tuple through memory. */ + void localRoundRobinStream(TupleTableSlot* tuple); + + /* Hybrid Stream Type. */ + void hybridStream(TupleTableSlot* tuple, DestReceiver* self); + + /*======== Data stream function for batch ============*/ + /* Broadcast the batch without compress. */ + void broadCastStream(VectorBatch* batch); + + /* Broadcast the batch with compress. */ + void broadCastStreamCompress(VectorBatch* batch); + + /* Local broadcast the batch throug memory. */ + void localBroadCastStream(VectorBatch* batch); + + /* Redistribute the batch. */ + void redistributeStream(VectorBatch* batch); + + /* Mark the data type of each column of a batch. */ + void serializeStreamTypeInit(); + + /*Serialize the given row of the batch into the buffer */ + void serializeStream(VectorBatch* batch, int index); + + /* Local redistribute the batch through memory. */ + void localRedistributeStream(VectorBatch* batch); + + /* Send tuple batch Roundrobin. */ + template + void roundRobinBatch(VectorBatch* batch); + + /* Local roundrobin the batch through memory. */ + void localRoundRobinStream(VectorBatch* batch); + + /* Hybrid Stream Type. */ + void hybridStream(VectorBatch* batch, DestReceiver* self); + + /* Flush the tuple buffer to the destination. */ + void sendByteStream(int nthChannel); + + /* Copy the batch/tuple to shared memory. */ + void sendByMemory(TupleTableSlot* tuple, VectorBatch* batchSrc, int nthChannel, int nthRow = -1); + + /* Mark local stream as finished. */ + void finalizeLocalStream(); + + /* Init data buffer in shared context. */ + void initSharedContext(); + + /* Flush the data in the buffer. */ + void flushStream(); + + /* Set up the write transaction status for the stream thread. */ + void setUpStreamTxnEnvironment(); + + /* Report error to consumer node. */ + void reportError(); + + /* Report notice to consumer node. */ + void reportNotice(); + + /* Get the dummy attribute. */ + bool isDummy(); + + /* Get the stream smp distriType. */ + bool isLocalStream(); + + /* Copy snapshot. */ + void copySnapShot(); + + /* Wait thread ID ready. */ + void waitThreadIdReady(); + +public: + /* All get function. */ + + /* Get database name. */ + char* getDbName(); + + /* Get user name. */ + char* getUserName(); + + /* Get the wlm params. */ + WLMGeneralParam getWlmParams(); + + uint32 getExplainThreadid(); + + unsigned char getExplainTrack(); + + /* Get the serialize plan. */ + PlannedStmt* getPlan(); + + /* Get the snap shot data. */ + Snapshot getSnapShot(); + + /* Get the params. */ + ParamListInfo getParams(); + + /* Get the command dest. */ + CommandDest getDest(); + + /* Get the instrumentation stream. */ + StreamInstrumentation* getStreamInstrumentation(); + + /* Get the OBS instrumentation. */ + OBSInstrumentation* getOBSInstrumentation(); + + /* Get the Session Memory structure. */ + SessionLevelMemory* getSessionMemory(); + + /* Get child slot. */ + int getChildSlot(); + + /* Get parent session id. */ + uint64 getParentSessionid(); + + /* Get parent Plannode id. */ + int getParentPlanNodeId(); + + /* Get sub producer list. */ + List* getSubProducerList(); + + /* Get the value of sync_guc_variables. */ + struct config_generic** get_sync_guc_variables(); + + /* Get the memory shared context. */ + StreamSharedContext* getSharedContext(); + + int getNth(); + + /* Get thread init flag. */ + bool getThreadInit() + { + return m_threadInit; + } + + void getUniqueSQLKey(uint64* unique_id, Oid* user_id, uint32* cn_id); + + /* All set function. */ + + /* Get/set postmaster child slot. */ + void setChildSlot(int childSlot); + + /* Set sub producer list. */ + void setSubProducerList(List* subProducerList); + + /* Set sub consumer list. */ + void setSubConsumerList(List* subProducerList); + + /* Set parent session id. */ + void setParentSessionid(uint64 sessionid); + + /* Set the Session Memory structure. */ + void setSessionMemory(SessionLevelMemory* sessionMemory); + + /* Set shared context for in-memory data exchange. */ + void setSharedContext(StreamSharedContext* sharedContext); + + /* Set thread init flag. */ + void setThreadInit(bool flag) + { + m_threadInit = flag; + } + + void setUniqueSQLKey(uint64 unique_sql_id, Oid unique_user_id, uint32 unique_cn_id); + + /* The plan the producer thread will run. */ + PlannedStmt* m_plan; + + /* Database name. */ + char* m_databaseName; + + /* User name. */ + char* m_userName; + + /* Session memory. */ + SessionLevelMemory* m_sessionMemory; + + /* A list to remember the sub producer. */ + List* m_subProducerList; + + /* Transaction context the producer thread will hold. */ + StreamTxnContext m_streamTxnCxt; + + /* Instrumentation data. */ + StreamInstrumentation* m_instrStream; + + /* OBS Instrumentation data */ + OBSInstrumentation* m_obsinstr; + + /* Carry the sync_guc_variables to stream thread. */ + struct config_generic** m_sync_guc_variables; + + ParamListInfo m_params; + + StreamSharedContext* m_sharedContext; + + /* + * MPP recursive execution support + * + * Record the orign nodelist in case of DN pruned in with-recursive execution + * mode, because the global plan step synchronization we need each datanode's + * produer start up without short-cut at its execution time. + */ + /* + * Store the original corresponding consumer side's nodelist, normally used to + * send redis/broacast target + */ + List* m_originConsumerNodeList; + + /* + * Store the original corresponding consumer side's nodelist, norammly used to + * respecify the execution stop flag + */ + List* m_originProducerExecNodeList; + + StreamSyncParam m_syncParam; + +private: + /* Set distribute Idx. */ + void setDistributeIdx(); + + /* Set distribute info. */ + void setDistributeInfo(); + + /* Two different major redistribute function for tuple. */ + void (StreamProducer::*m_channelCalFun)(TupleTableSlot* tuple); + + /* Vector redistribute function for batch. */ + void (StreamProducer::*m_channelCalVecFun)(VectorBatch* batch); + + /* Choose which node to send by hash value. */ + inline uint2 NodeLocalizer(ScalarValue hashValue); + + /* Choose which thread to send by hash value. */ + inline int ThreadLocalizer(ScalarValue hashValue, int dop); + + template + void redistributeBatchChannel(VectorBatch* batch); + + template + void redistributeTupleChannel(TupleTableSlot* tuple); + + /* Choose which channel to send by hash value. */ + template + inline int ChannelLocalizer(ScalarValue hashValue, int Dop, int nodeSize); + + /* Building binding function. */ + template + void BindingRedisFunction(); + + /* Dispatch batch sending function. */ + void DispatchBatchRedistrFunction(int len); + + /* Dispatch tuple sending function. */ + void DispatchRowRedistrFunction(int len); + + /* Dispatch batch sending function by redistribute type. */ + template + void DispatchBatchRedistrFunctionByRedisType(); + + /* Dispatch tuple sending function by redistribute type. */ + template + void DispatchRowRedistrFunctionByRedisType(); + + typedef Datum (*hashFun)(Datum value); + + void AddCheckInfo(int nthChannel); + + int findLocalChannel(); + + inline uint2 NodeLocalizerForSlice(Const **distValues); + + inline int ThreadLocalizerForSlice(ScalarValue hashValue, int dop) const; + + template + int ChannelLocalizerForSlice(ScalarValue hashValue, Const **distValues, int dop); + + template + void redistributeTupleChannelForSlice(TupleTableSlot *tuple); + + void DispatchRowRedistrFunctionForSlice(); + + template + void redistributeBatchChannelForSlice(VectorBatch* batch); + + void DispatchBatchRedistrFunctionForSlice(); + +private: + /* Hash function for redistribute. */ + hashFun* m_hashFun; + + /* Wlm params. */ + WLMGeneralParam m_wlmParams; + + uint32 m_explain_thread_id; + + bool m_explain_track; + + /* + * Producer is dummy means it will + * do very little thing + * 1) init the child stream thread + * 2) will end as quick as possible, send nothing outside. + */ + bool m_isDummy; + + /* A list to remember the sub consumer */ + List* m_subConsumerList; + + /* Postmaster child slot. */ + int m_postMasterChildSlot; + + /* A unique query id for debug purpose. */ + uint64 m_queryId; + + /* Null flag length of redistribute serialization */ + uint32 m_bitNullLen; + + /* Numeric flag length of redistribute serialization */ + uint32 m_bitNumericLen; + + /* temp buffer for redistribute */ + char* m_tempBuffer; + + /* Mark the data type of each column of a batch. */ + uint32* m_colsType; + + /* Parent session ID. */ + uint64 m_parentSessionid; + + /* Parent planNode ID*/ + int m_parentPlanNodeId; + + /* The tuple description for the output data. */ + TupleDesc m_desc; + + /* The consumer nodes information. */ + ExecNodes* m_consumerNodes; + + /* The stream type. */ + StreamType m_streamType; + + /* The dest type the producer thread will follow. */ + CommandDest m_dest; + + /* The bucket map for redistribute. */ + uint2* m_bucketMap; + + /* boundary extracted from ExecNodes if redistribute by range/list */ + ExecBoundary* m_sliceBoundary; + + /* A quick node index for distribute. */ + uint2** m_disQuickLocator; + + /* A tuple buffer for send message. */ + StringInfoData m_tupleBuffer; + + /* A tuple buffer for send message and check info . */ + StringInfoData m_tupleBufferWithCheck; + + /* The distribute key information. */ + List* m_distributeKey; + + /* Extract from key, as we can have multicolumn keys culrrently, hold the attribute number for convenient. */ + AttrNumber* m_distributeIdx; + + /* Net is init? */ + volatile bool m_netInit; + + /* Use this to protect the net init flag, we can't use spinlock as it may hit the stuck problem. */ + volatile sig_atomic_t m_netProtect; + + int m_roundRobinIdx; + + int m_locator[BatchMaxSize]; + + /* The send dest for local stream to send error message. */ + int m_nth; + + bool m_sharedContextInit; + int64 m_broadcastSize; + + void* m_skewState; + + int m_skewMatch[BatchMaxSize]; + + /* If thread already inited*/ + bool m_threadInit; + + /* instrumentation: */ + uint64 m_uniqueSQLId; + Oid m_uniqueSQLUserId; + uint32 m_uniqueSQLCNId; +}; + +extern THR_LOCAL StreamProducer* streamProducer; + +#endif /* SRC_INCLUDE_DISTRIBUTELAYER_STREAMPRODUCER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamTransportComm.h postgresql-hll-2.14/include/include/distributelayer/streamTransportComm.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamTransportComm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamTransportComm.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamTransportComm.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamTransportComm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMTRANSPORTCOMM_H_ +#define STREAMTRANSPORTCOMM_H_ + +class StreamCOMM : public StreamTransport { +public: + StreamCOMM(libcommaddrinfo* addr, bool flag); + ~StreamCOMM(); + + /* Send a normal message. */ + int send(char msgtype, const char* msg, size_t len); + + /* Flush pending output. */ + void flush(); + + /* Close stream. */ + void release(); + + /* Init stream port. */ + void init(char* dbname, char* usrname); + + /* Is stream closed? */ + bool isClosed(); + + /* Allocate net buffer for stream port. */ + void allocNetBuffer(); + + /* Set send buffer active. */ + bool setActive(); + + /* Set send buffer inactive. */ + void setInActive(); + + /* Update connection info. */ + void updateInfo(StreamConnInfo* connInfo); + +public: + /* address array. */ + libcommaddrinfo* m_addr; +}; + +#endif /* STREAMTRANSPORTCOMM_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/distributelayer/streamTransportCore.h postgresql-hll-2.14/include/include/distributelayer/streamTransportCore.h --- postgresql-hll-2.14_old/include/include/distributelayer/streamTransportCore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/distributelayer/streamTransportCore.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,107 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streamTransportCore.h + * + * + * + * IDENTIFICATION + * src/include/distributelayer/streamTransportCore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMTRANSPORTCORE_H_ +#define STREAMTRANSPORTCORE_H_ + +enum StreamTransType { STREAM_COMM, STREAM_MEM }; + +class StreamTransport : public BaseObject { +public: + StreamTransport() + {} + + virtual ~StreamTransport() + {} + + virtual int send(char msgtype, const char* msg, size_t len) + { + Assert(false); + return 0; + } + + virtual void flush() + { + Assert(false); + } + + virtual void release() + { + Assert(false); + } + + virtual bool isClosed() + { + Assert(false); + return false; + } + + virtual void init(char* dbname, char* usrname) + { + Assert(false); + } + + virtual void allocNetBuffer() + { + Assert(false); + } + + virtual bool setActive() + { + Assert(false); + return false; + } + + virtual void setInActive() + { + Assert(false); + } + + virtual void updateInfo(StreamConnInfo* connInfo) + { + Assert(false); + } + +public: + /* Node name of data node sending data, only for consumer currently. */ + char m_nodeName[NAMEDATALEN]; + + /* Oid of data node sending data, only for consumer currently. */ + Oid m_nodeoid; + + /* Transport type. */ + StreamTransType m_type; + + /* Mark if transport is for producer */ + bool m_sendSide; + + /* Communication port. */ + Port* m_port; + + /* Stream buffer. */ + StreamBuffer* m_buffer; +}; + +#endif /* STREAMTRANSPORTCORE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/executor/execdebug.h postgresql-hll-2.14/include/include/executor/execdebug.h --- postgresql-hll-2.14_old/include/include/executor/execdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/execdebug.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,145 @@ +/* ------------------------------------------------------------------------- + * + * execdebug.h + * #defines governing debugging behaviour in the executor + * + * XXX this is all pretty old and crufty. Newer code tends to use elog() + * for debug printouts, because that's more flexible than printf(). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/execdebug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECDEBUG_H +#define EXECDEBUG_H + +#include "executor/executor.h" +#include "nodes/print.h" + +/* ---------------------------------------------------------------- + * debugging defines. + * + * If you want certain debugging behaviour, then #define + * the variable to 1. No need to explicitly #undef by default, + * since we can use -D compiler options to enable features. + * - thomas 1999-02-20 + * ---------------------------------------------------------------- + */ + +/* ---------------- + * EXEC_NESTLOOPDEBUG is a flag which turns on debugging of the + * nest loop node by NL_printf() and ENL_printf() in nodeNestloop.c + * ---------------- +#undef EXEC_NESTLOOPDEBUG + */ + +/* ---------------- + * EXEC_EVALDEBUG is a flag which turns on debugging of + * ExecEval and ExecTargetList() stuff by EV_printf() in execQual.c + * ---------------- +#undef EXEC_EVALDEBUG + */ + +/* ---------------- + * EXEC_SORTDEBUG is a flag which turns on debugging of + * the ExecSort() stuff by SO_printf() in nodeSort.c + * ---------------- +#undef EXEC_SORTDEBUG + */ + +/* ---------------- + * EXEC_MERGEJOINDEBUG is a flag which turns on debugging of + * the ExecMergeJoin() stuff by MJ_printf() in nodeMergejoin.c + * ---------------- +#undef EXEC_MERGEJOINDEBUG + */ + +/* ---------------------------------------------------------------- + * #defines controlled by above definitions + * + * Note: most of these are "incomplete" because I didn't + * need the ones not defined. More should be added + * only as necessary -cim 10/26/89 + * ---------------------------------------------------------------- + */ +#define T_OR_F(b) ((b) ? "true" : "false") +#define NULL_OR_TUPLE(slot) (TupIsNull(slot) ? "null" : "a tuple") + +/* ---------------- + * nest loop debugging defines + * ---------------- + */ +#ifdef EXEC_NESTLOOPDEBUG +#define NL_nodeDisplay(l) nodeDisplay(l) +#define NL_printf(s) printf(s) +#define NL1_printf(s, a) printf(s, a) +#define ENL1_printf(message) printf("ExecNestLoop: %s\n", message) +#else +#define NL_nodeDisplay(l) +#define NL_printf(s) +#define NL1_printf(s, a) +#define ENL1_printf(message) +#endif /* EXEC_NESTLOOPDEBUG */ + +/* ---------------- + * exec eval / target list debugging defines + * ---------------- + */ +#ifdef EXEC_EVALDEBUG +#define EV_nodeDisplay(l) nodeDisplay(l) +#define EV_printf(s) printf(s) +#define EV1_printf(s, a) printf(s, a) +#else +#define EV_nodeDisplay(l) +#define EV_printf(s) +#define EV1_printf(s, a) +#endif /* EXEC_EVALDEBUG */ + +/* ---------------- + * sort node debugging defines + * ---------------- + */ +#ifdef EXEC_SORTDEBUG +#define SO_nodeDisplay(l) nodeDisplay(l) +#define SO_printf(s) printf(s) +#define SO1_printf(s, p) printf(s, p) +#else +#define SO_nodeDisplay(l) +#define SO_printf(s) +#define SO1_printf(s, p) +#endif /* EXEC_SORTDEBUG */ + +/* ---------------- + * merge join debugging defines + * ---------------- + */ +#ifdef EXEC_MERGEJOINDEBUG + +#define MJ_nodeDisplay(l) nodeDisplay(l) +#define MJ_printf(s) printf(s) +#define MJ1_printf(s, p) printf(s, p) +#define MJ2_printf(s, p1, p2) printf(s, p1, p2) +#define MJ_debugtup(slot) debugtup(slot, NULL) +#define MJ_dump(state) ExecMergeTupleDump(state) +#define MJ_DEBUG_COMPARE(res) MJ1_printf(" MJCompare() returns %d\n", (res)) +#define MJ_DEBUG_QUAL(clause, res) MJ2_printf(" ExecQual(%s, econtext) returns %s\n", CppAsString(clause), T_OR_F(res)) +#define MJ_DEBUG_PROC_NODE(slot) \ + MJ2_printf(" %s = ExecProcNode(...) returns %s\n", CppAsString(slot), NULL_OR_TUPLE(slot)) +#else + +#define MJ_nodeDisplay(l) +#define MJ_printf(s) +#define MJ1_printf(s, p) +#define MJ2_printf(s, p1, p2) +#define MJ_debugtup(slot) +#define MJ_dump(state) +#define MJ_DEBUG_COMPARE(res) +#define MJ_DEBUG_QUAL(clause, res) +#define MJ_DEBUG_PROC_NODE(slot) +#endif /* EXEC_MERGEJOINDEBUG */ + +#endif /* ExecDebugIncluded */ diff -uprN postgresql-hll-2.14_old/include/include/executor/execdesc.h postgresql-hll-2.14/include/include/executor/execdesc.h --- postgresql-hll-2.14_old/include/include/executor/execdesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/execdesc.h 2020-12-12 17:06:43.185347238 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * execdesc.h + * plan and query descriptor accessor macros used by the executor + * and related modules. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/execdesc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECDESC_H +#define EXECDESC_H + +#include "nodes/execnodes.h" +#include "tcop/dest.h" + +#ifdef ENABLE_MOT +// forward declaration +namespace JitExec +{ + struct JitContext; +} +#endif + +/* ---------------- + * query descriptor: + * + * a QueryDesc encapsulates everything that the executor + * needs to execute the query. + * + * For the convenience of SQL-language functions, we also support QueryDescs + * containing utility statements; these must not be passed to the executor + * however. + * --------------------- + */ +typedef struct QueryDesc { + /* These fields are provided by CreateQueryDesc */ + CmdType operation; /* CMD_SELECT, CMD_UPDATE, etc. */ + PlannedStmt* plannedstmt; /* planner's output, or null if utility */ + Node* utilitystmt; /* utility statement, or null */ + const char* sourceText; /* source text of the query */ + Snapshot snapshot; /* snapshot to use for query */ + Snapshot crosscheck_snapshot; /* crosscheck for RI update/delete */ + DestReceiver* dest; /* the destination for tuple output */ + ParamListInfo params; /* param values being passed in */ + int instrument_options; /* OR of InstrumentOption flags */ + + /* These fields are set by ExecutorStart */ + TupleDesc tupDesc; /* descriptor for result tuples */ + EState* estate; /* executor's query-wide state */ + PlanState* planstate; /* tree of per-plan-node state */ + + /* This is always set NULL by the core system, but plugins can change it */ + struct Instrumentation* totaltime; /* total time spent in ExecutorRun */ + bool executed; /* if the query already executed */ +#ifdef ENABLE_MOT + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif +} QueryDesc; + +/* in pquery.c */ +#ifdef ENABLE_MOT +extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot, + Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options, + JitExec::JitContext* mot_jit_context = nullptr); +#else +extern QueryDesc* CreateQueryDesc(PlannedStmt* plannedstmt, const char* sourceText, Snapshot snapshot, + Snapshot crosscheck_snapshot, DestReceiver* dest, ParamListInfo params, int instrument_options); +#endif + +extern QueryDesc* CreateUtilityQueryDesc( + Node* utilitystmt, const char* sourceText, Snapshot snapshot, DestReceiver* dest, ParamListInfo params); + +extern void FreeQueryDesc(QueryDesc* qdesc); + +#endif /* EXECDESC_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/execMerge.h postgresql-hll-2.14/include/include/executor/execMerge.h --- postgresql-hll-2.14_old/include/include/executor/execMerge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/execMerge.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * execMerge.h + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/executor/execMerge.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef EXECMERGE_H +#define EXECMERGE_H + +#include "nodes/execnodes.h" + +/* flags for mt_merge_subcommands */ +#define MERGE_INSERT 0x01 +#define MERGE_UPDATE 0x02 + +struct VecModifyTableState; + +extern void ExecMerge(ModifyTableState* mtstate, EState* estate, TupleTableSlot* slot, JunkFilter* junkfilter, + ResultRelInfo* resultRelInfo); + +extern void ExecInitMerge(ModifyTableState* mtstate, EState* estate, ResultRelInfo* resultRelInfo); + +extern TupleTableSlot* ExtractScanTuple(ModifyTableState* mtstate, TupleTableSlot* slot, TupleDesc tupDesc); + +extern TupleTableSlot* ExecMergeProjQual(ModifyTableState* mtstate, List* mergeMatchedActionStates, + ExprContext* econtext, TupleTableSlot* originSlot, TupleTableSlot* result_slot, EState* estate); + +#endif /* NODEMERGE_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/execStream.h postgresql-hll-2.14/include/include/executor/execStream.h --- postgresql-hll-2.14_old/include/include/executor/execStream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/execStream.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,150 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * execStream.h + * Support routines for datanodes exchange. + * + * + * IDENTIFICATION + * src/include/executor/execStream.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef EXECSTREAM_H +#define EXECSTREAM_H + +#include "pgxc/execRemote.h" +#include "optimizer/planner.h" +#include "optimizer/streamplan.h" +#include "libcomm/libcomm.h" +#include "libpq/libpq-be.h" +#include "access/xact.h" +#include "utils/distribute_test.h" +#include +#include "storage/spin.h" +#include "workload/workload.h" +#include "pgstat.h" +#include "distributelayer/streamConsumer.h" +#include "distributelayer/streamProducer.h" + +typedef struct StreamDataBuf { + char* msg; + int size; + int len; +} StreamDataBuf; + +#define SetCheckInfo(checkInfo, plan) \ + do { \ + *(checkInfo.parentProducerExecNodeList) = plan->exec_nodes->nodeList; \ + *(checkInfo.parentPlanNodeId) = plan->plan_node_id; \ + *(checkInfo.parentProducerDop) = plan->dop; \ + } while (0) + +typedef struct StreamFlowCheckInfo { + List* parentProducerExecNodeList; /* Producer exec_nodes of parent stream node. */ + int parentPlanNodeId; /* plan node id of parent node. */ + int parentProducerDop; /* Dop of parent producer. */ +} StreamFlowCheckInfo; + +typedef struct StreamFlowCtl { + PlannedStmt* pstmt; /* PlannedStmt node, output of planner, + holds the "one time" information needed by the executor. */ + Plan* plan; /* Top node of plan tree. */ + List** allConsumerList; /* All consumer object list. */ + List** allProducerList; /* All producer object list. */ + List** subProducerList; /* All sub producer object list. */ + List** subConsumerList; /* All sub consumer object list. */ + int* threadNum; /* The number of stream thread. */ + bool dummyThread; /* If it's a dummy stream node? */ + StreamFlowCheckInfo checkInfo; /* Check if consumer match producer between stream node. */ +} StreamFlowCtl; + +typedef union { + struct { + struct pollfd* ufds; /* tcp poll fds. */ + int* poll2conn; /* poll idx to connection idx. */ + } tcpLayer; + + struct { + int* datamarks; /* producer number triggers poll. */ + int* poll2conn; /* poll idx to connection idx. */ + gsocket* gs_sock; + } sctpLayer; + +} StreamNetCtlLayer; + +typedef struct StreamNetCtl { + StreamNetCtlLayer layer; /* stream net controller layer. */ +} StreamNetCtl; + +typedef struct StreamState { + ScanState ss; /* its first field is NodeTag */ + PGXCNodeHandle** connections; /* Datanode connections */ + int conn_count; /* count of active connections */ + int last_conn_idx; /* last connection index */ + bool isReady; /* is ready for scan from socket fd*/ + bool need_fresh_data; /* need retrieve data from connection */ + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + bool vector_output; /* is vector format output */ + StreamDataBuf buf; /* data buffer for stream data */ + StreamConsumer* consumer; /* the stream consumer object which control the stream node*/ + scanStreamFun StreamScan; /* scan function for tuple stream */ + deserializeStreamFun StreamDeserialize; /* stream deserialize for tuple */ + RemoteErrorData remoteErrData; /* error data from remote */ + int64 recvDataLen; /* network data length for performance info of stream node. */ + StreamNetCtl netctl; /* stream net controller for node receiving. */ + StreamSharedContext* sharedContext; /* Shared context for local stream. */ + TupleVector* tempTupleVec; + StreamType type; /* indicate it's Redistribute/Broadcast. */ + int64* spill_size; + void* sortstate; /* merge sort for stream */ + bool receive_message; /* The stream consumer has receive message from then producer */ +} StreamState; + +extern StreamState* ExecInitStream(Stream* node, EState* estate, int eflags); +extern TupleTableSlot* ExecStream(StreamState* node); +extern void ExecEndStream(StreamState* node); +extern int HandleStreamResponse(PGXCNodeHandle* conn, StreamState* node); +extern void StreamPrepareRequest(StreamState* node); +extern void StreamPrepareRequestForRecursive(StreamState* node, bool stepsync); +extern void StreamReportError(StreamState* node); +extern void ExecEarlyDeinitConsumer(PlanState* node); +extern void SetupStreamRuntime(StreamState* node); +extern bool ScanStreamByLibcomm(StreamState* node); +extern void InitStreamContext(); +extern void DeinitStreamContext(); +extern void gs_memory_init_entry(StreamSharedContext* sharedContext, int consumerNum, int producerNum); +extern bool ScanMemoryStream(StreamState* node); +extern bool gs_memory_recv(StreamState* node); +extern void gs_memory_send( + TupleTableSlot* tuple, VectorBatch* batchsrc, StreamSharedContext* sharedContext, int nthChannel, int nthRow); +extern void gs_memory_disconnect(StreamSharedContext* sharedContext, int nthChannel); +extern void gs_message_by_memory(StringInfo buf, StreamSharedContext* sharedContext, int nthChannel); +extern void gs_memory_send_finish(StreamSharedContext* sharedContext, int connNum); +extern void gs_memory_close_conn(StreamSharedContext* sharedContext, int connNum, int smpId); +extern void HandleStreamNotice(StreamState* node, char* msg_body, size_t len); +extern void HandleStreamError(StreamState* node, char* msg_body, int len); +extern const char* GetStreamType(Stream* node); +extern bool ThreadIsDummy(Plan* plan_tree); +extern void AddCheckMessage(StringInfo msg_new, StringInfo msg_org, bool is_stream, unsigned int planNodeId = 0); +extern void CheckMessages(uint64 query_id, uint32 plan_node_id, char* msg, int msg_len, bool is_stream); +extern bool IsThreadProcessStreamRecursive(); +extern void ExecReSetStream(StreamState* node); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/executor/executor.h postgresql-hll-2.14/include/include/executor/executor.h --- postgresql-hll-2.14_old/include/include/executor/executor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/executor.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,480 @@ +/* ------------------------------------------------------------------------- + * + * executor.h + * support for the POSTGRES executor module + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/executor.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECUTOR_H +#define EXECUTOR_H + +#include "executor/execdesc.h" +#include "nodes/parsenodes.h" +#include "nodes/params.h" +#include "pgxc/pgxc.h" +#include "utils/memprot.h" +#include "utils/memutils.h" +#include "utils/resowner.h" +#include "utils/partitionmap_gs.h" +#include "utils/plpgsql.h" + +/* + * The "eflags" argument to ExecutorStart and the various ExecInitNode + * routines is a bitwise OR of the following flag bits, which tell the + * called plan node what to expect. Note that the flags will get modified + * as they are passed down the plan tree, since an upper node may require + * functionality in its subnode not demanded of the plan as a whole + * (example: MergeJoin requires mark/restore capability in its inner input), + * or an upper node may shield its input from some functionality requirement + * (example: Materialize shields its input from needing to do backward scan). + * + * EXPLAIN_ONLY indicates that the plan tree is being initialized just so + * EXPLAIN can print it out; it will not be run. Hence, no side-effects + * of startup should occur. However, error checks (such as permission checks) + * should be performed. + * + * REWIND indicates that the plan node should try to efficiently support + * rescans without parameter changes. (Nodes must support ExecReScan calls + * in any case, but if this flag was not given, they are at liberty to do it + * through complete recalculation. Note that a parameter change forces a + * full recalculation in any case.) + * + * BACKWARD indicates that the plan node must respect the es_direction flag. + * When this is not passed, the plan node will only be run forwards. + * + * MARK indicates that the plan node must support Mark/Restore calls. + * When this is not passed, no Mark/Restore will occur. + * + * SKIP_TRIGGERS tells ExecutorStart/ExecutorFinish to skip calling + * AfterTriggerBeginQuery/AfterTriggerEndQuery. This does not necessarily + * mean that the plan can't queue any AFTER triggers; just that the caller + * is responsible for there being a trigger context for them to be queued in. + * + * WITH/WITHOUT_OIDS tell the executor to emit tuples with or without space + * for OIDs, respectively. These are currently used only for CREATE TABLE AS. + * If neither is set, the plan may or may not produce tuples including OIDs. + */ +#define EXEC_FLAG_EXPLAIN_ONLY 0x0001 /* EXPLAIN, no ANALYZE */ +#define EXEC_FLAG_REWIND 0x0002 /* need efficient rescan */ +#define EXEC_FLAG_BACKWARD 0x0004 /* need backward scan */ +#define EXEC_FLAG_MARK 0x0008 /* need mark/restore */ +#define EXEC_FLAG_SKIP_TRIGGERS 0x0010 /* skip AfterTrigger calls */ +#define EXEC_FLAG_WITH_OIDS 0x0020 /* force OIDs in returned tuples */ +#define EXEC_FLAG_WITHOUT_OIDS 0x0040 /* force no OIDs in returned tuples */ +#define EXEC_FLAG_WITH_NO_DATA 0x0080 /* rel scannability doesn't matter */ + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); + +#define STREAM_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_STREAM)) { \ + ereport(level, (errmodule(MOD_STREAM), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#define MEMCTL_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_MEM)) { \ + ereport(level, (errmodule(MOD_MEM), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#ifdef USE_ASSERT_CHECKING +#define EARLY_FREE_LOG(A) +#else +#define EARLY_FREE_LOG(A) +#endif + +#ifdef USE_ASSERT_CHECKING +#define RECURSIVE_LOG(level, format, ...) \ + do { \ + ereport(level, (errmsg(format, ##__VA_ARGS__))); \ + } while (0) +#else +#define RECURSIVE_LOG(level, format, ...) \ + do { \ + ereport(DEBUG1, (errmsg(format, ##__VA_ARGS__))); \ + } while (0) +#endif + +#define SET_DOP(dop) (dop > 1 ? dop : 1) +/* + * Calculate the memory restriction in each thread. + * And the memeory in each thread must be larger than 64K. + */ +#define SET_NODEMEM(opmem, dop) \ + ((opmem > 0 ? opmem : u_sess->attr.attr_memory.work_mem) / \ + ((opmem > 0 ? opmem : u_sess->attr.attr_memory.work_mem) > (SET_DOP(dop) * 64) ? SET_DOP(dop) : 1)) + +#define SET_NUMGROUPS(node) \ + (node->numGroups / SET_DOP(node->plan.dop) > 0 ? node->numGroups / SET_DOP(node->plan.dop) : 1) + +#define HAS_INSTR(node, dnonly) \ + (!dnonly || IS_PGXC_DATANODE) && u_sess->instr_cxt.global_instr != NULL && (node)->ps.instrument != NULL + +/* + * ExecEvalExpr was formerly a function containing a switch statement; + * now it's just a macro invoking the function pointed to by an ExprState + * node. Beware of double evaluation of the ExprState argument! + */ +#define ExecEvalExpr(expr, econtext, isNull, isDone) ((*(expr)->evalfunc)(expr, econtext, isNull, isDone)) + +/* + * recursive union macro + */ +#define INVALID_RU_PLANNODE_ID 0 +#define EXEC_IN_RECURSIVE_MODE(x) (((Plan*)x)->recursive_union_plan_nodeid != INVALID_RU_PLANNODE_ID) + +/* Hook for plugins to get control in ExecutorStart() */ +typedef void (*ExecutorStart_hook_type)(QueryDesc* queryDesc, int eflags); +extern THR_LOCAL PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook; + +/* Hook for plugins to get control in ExecutorRun() */ +typedef void (*ExecutorRun_hook_type)(QueryDesc* queryDesc, ScanDirection direction, long count); +extern THR_LOCAL PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook; + +/* Hook for plugins to get control in ExecutorFinish() */ +typedef void (*ExecutorFinish_hook_type)(QueryDesc* queryDesc); +extern THR_LOCAL PGDLLIMPORT ExecutorFinish_hook_type ExecutorFinish_hook; + +/* Hook for plugins to get control in ExecutorEnd() */ +typedef void (*ExecutorEnd_hook_type)(QueryDesc* queryDesc); +extern THR_LOCAL PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook; + +/* Hook for plugins to get control in ExecCheckRTPerms() */ +typedef bool (*ExecutorCheckPerms_hook_type)(List*, bool); +extern THR_LOCAL PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook; + +/* + * prototypes from functions in execAmi.c + */ +extern void ExecReScan(PlanState* node); +extern void ExecMarkPos(PlanState* node); +extern void ExecRestrPos(PlanState* node); +extern bool ExecSupportsMarkRestore(NodeTag plantype); +extern bool ExecSupportsBackwardScan(Plan* node); +extern bool ExecMaterializesOutput(NodeTag plantype); + +/* + * prototypes from functions in execCurrent.c + */ +extern bool execCurrentOf(CurrentOfExpr* cexpr, ExprContext* econtext, Relation relation, ItemPointer current_tid, + RelationPtr partitionOfCursor_tid); +#ifdef PGXC +ScanState* search_plan_tree(PlanState* node, Oid table_oid); +#endif + +/* + * prototypes from functions in execGrouping.c + */ +extern bool execTuplesMatch(TupleTableSlot* slot1, TupleTableSlot* slot2, int numCols, AttrNumber* matchColIdx, + FmgrInfo* eqfunctions, MemoryContext evalContext); +extern bool execTuplesUnequal(TupleTableSlot* slot1, TupleTableSlot* slot2, int numCols, AttrNumber* matchColIdx, + FmgrInfo* eqfunctions, MemoryContext evalContext); +extern FmgrInfo* execTuplesMatchPrepare(int numCols, Oid* eqOperators); +extern void execTuplesHashPrepare(int numCols, Oid* eqOperators, FmgrInfo** eqFunctions, FmgrInfo** hashFunctions); +extern TupleHashTable BuildTupleHashTable(int numCols, AttrNumber* keyColIdx, FmgrInfo* eqfunctions, + FmgrInfo* hashfunctions, long nbuckets, Size entrysize, MemoryContext tablecxt, MemoryContext tempcxt, int workMem); +extern TupleHashEntry LookupTupleHashEntry( + TupleHashTable hashtable, TupleTableSlot* slot, bool* isnew, bool isinserthashtbl = true); +extern TupleHashEntry FindTupleHashEntry( + TupleHashTable hashtable, TupleTableSlot* slot, FmgrInfo* eqfunctions, FmgrInfo* hashfunctions); + +/* + * prototypes from functions in execJunk.c + */ +extern JunkFilter* ExecInitJunkFilter(List* targetList, bool hasoid, TupleTableSlot* slot, TableAmType tam = TAM_HEAP); +extern JunkFilter* ExecInitJunkFilterConversion(List* targetList, TupleDesc cleanTupType, TupleTableSlot* slot); +extern AttrNumber ExecFindJunkAttribute(JunkFilter* junkfilter, const char* attrName); +extern AttrNumber ExecFindJunkAttributeInTlist(List* targetlist, const char* attrName); +extern Datum ExecGetJunkAttribute(TupleTableSlot* slot, AttrNumber attno, bool* isNull); +extern TupleTableSlot* ExecFilterJunk(JunkFilter* junkfilter, TupleTableSlot* slot); +extern void ExecSetjunkFilteDescriptor(JunkFilter* junkfilter, TupleDesc tupdesc); + +#ifdef PGXC +extern List* ExecFindJunkPrimaryKeys(List* targetlist); +#endif +extern VectorBatch* BatchExecFilterJunk(JunkFilter* junkfilter, VectorBatch* batch); +extern void BatchCheckNodeIdentifier(JunkFilter* junkfilter, VectorBatch* batch); +extern int ExecGetPlanNodeid(void); + +/* + * prototypes from functions in execMain.c + */ +extern void ExecutorStart(QueryDesc* queryDesc, int eflags); +extern void standard_ExecutorStart(QueryDesc* queryDesc, int eflags); +extern void ExecutorRun(QueryDesc* queryDesc, ScanDirection direction, long count); +extern void standard_ExecutorRun(QueryDesc* queryDesc, ScanDirection direction, long count); +extern void ExecutorFinish(QueryDesc* queryDesc); +extern void standard_ExecutorFinish(QueryDesc* queryDesc); +extern void ExecutorEnd(QueryDesc* queryDesc); +extern void standard_ExecutorEnd(QueryDesc* queryDesc); +extern void ExecutorRewind(QueryDesc* queryDesc); +extern bool ExecCheckRTPerms(List* rangeTable, bool ereport_on_violation); +extern void CheckValidResultRel(Relation resultRel, CmdType operation); +extern void InitResultRelInfo( + ResultRelInfo* resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, int instrument_options); +extern ResultRelInfo* ExecGetTriggerResultRel(EState* estate, Oid relid); +extern bool ExecContextForcesOids(PlanState* planstate, bool* hasoids); +extern void ExecConstraints(ResultRelInfo* resultRelInfo, TupleTableSlot* slot, EState* estate); +extern ExecRowMark* ExecFindRowMark(EState* estate, Index rti); +extern ExecAuxRowMark* ExecBuildAuxRowMark(ExecRowMark* erm, List* targetlist); +extern TupleTableSlot* EvalPlanQual( + EState* estate, EPQState* epqstate, Relation relation, Index rti, ItemPointer tid, TransactionId priorXmax); +extern HeapTuple heap_lock_updated( + CommandId cid, Relation relation, int lockmode, ItemPointer tid, TransactionId priorXmax); +extern void EvalPlanQualInit(EPQState* epqstate, EState* estate, Plan* subplan, List* auxrowmarks, int epqParam); +extern void EvalPlanQualSetPlan(EPQState* epqstate, Plan* subplan, List* auxrowmarks); +extern void EvalPlanQualSetTuple(EPQState* epqstate, Index rti, HeapTuple tuple); +extern HeapTuple EvalPlanQualGetTuple(EPQState* epqstate, Index rti); + +#define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot)) +extern void EvalPlanQualFetchRowMarks(EPQState* epqstate); +extern TupleTableSlot* EvalPlanQualNext(EPQState* epqstate); +extern void EvalPlanQualBegin(EPQState* epqstate, EState* parentestate); +extern void EvalPlanQualEnd(EPQState* epqstate); + +/* + * prototypes from functions in execProcnode.c + */ +extern PlanState* ExecInitNode(Plan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecProcNode(PlanState* node); +extern Node* MultiExecProcNode(PlanState* node); +extern void ExecEndNode(PlanState* node); + +extern long ExecGetPlanMemCost(Plan* node); + +/* + * prototypes from functions in execQual.c + */ +extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno, bool* isNull); +extern Datum GetAttributeByName(HeapTupleHeader tuple, const char* attname, bool* isNull); +extern Tuplestorestate* ExecMakeTableFunctionResult( + ExprState* funcexpr, ExprContext* econtext, TupleDesc expectedDesc, bool randomAccess, FunctionScanState* node); +extern Datum ExecEvalExprSwitchContext( + ExprState* expression, ExprContext* econtext, bool* isNull, ExprDoneCond* isDone); +extern ExprState* ExecInitExpr(Expr* node, PlanState* parent); +extern ExprState* ExecPrepareExpr(Expr* node, EState* estate); +extern bool ExecQual(List* qual, ExprContext* econtext, bool resultForNull); +extern int ExecTargetListLength(List* targetlist); +extern int ExecCleanTargetListLength(List* targetlist); +extern TupleTableSlot* ExecProject(ProjectionInfo* projInfo, ExprDoneCond* isDone); + +extern TupleTableSlot* ExecScan(ScanState* node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd); +extern void ExecAssignScanProjectionInfo(ScanState* node); +extern void ExecScanReScan(ScanState* node); + +/* + * prototypes from functions in execTuples.c + */ +extern void ExecInitResultTupleSlot(EState* estate, PlanState* planstate, TableAmType tam = TAM_HEAP); +extern void ExecInitScanTupleSlot(EState* estate, ScanState* scanstate, TableAmType tam = TAM_HEAP); +extern TupleTableSlot* ExecInitExtraTupleSlot(EState* estate, TableAmType tam = TAM_HEAP); +extern TupleTableSlot* ExecInitNullTupleSlot(EState* estate, TupleDesc tupType); +extern TupleDesc ExecTypeFromTL(List* targetList, bool hasoid, bool markdropped = false, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecCleanTypeFromTL(List* targetList, bool hasoid, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecTypeFromExprList(List* exprList, List* namesList, TableAmType tam = TAM_HEAP); +extern void UpdateChangedParamSet(PlanState* node, Bitmapset* newchg); + +typedef struct TupOutputState { + TupleTableSlot* slot; + DestReceiver* dest; +} TupOutputState; + +extern TupOutputState* begin_tup_output_tupdesc(DestReceiver* dest, TupleDesc tupdesc); +extern void do_tup_output( + TupOutputState* tstate, Datum* values, size_t values_len, const bool* isnull, size_t isnull_len); +extern int do_text_output_multiline(TupOutputState* tstate, char* text); +extern void end_tup_output(TupOutputState* tstate); + +/* + * Write a single line of text given as a C string. + * + * Should only be used with a single-TEXT-attribute tupdesc. + */ +#define do_text_output_oneline(tstate, str_to_emit) \ + do { \ + Datum values_[1]; \ + bool isnull_[1]; \ + values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \ + isnull_[0] = false; \ + do_tup_output(tstate, values_, 1, isnull_, 1); \ + pfree(DatumGetPointer(values_[0])); \ + } while (0) + +/* + * prototypes from functions in execUtils.c + */ +extern EState* CreateExecutorState(void); +extern void FreeExecutorState(EState* estate); +extern ExprContext* CreateExprContext(EState* estate); +extern ExprContext* CreateStandaloneExprContext(void); +extern void FreeExprContext(ExprContext* econtext, bool isCommit); +extern void ReScanExprContext(ExprContext* econtext); + +#define ResetExprContext(econtext) MemoryContextReset((econtext)->ecxt_per_tuple_memory) + +extern ExprContext* MakePerTupleExprContext(EState* estate); + +#define RuntimeBinding(func, strategy) (this->*func[strategy]) +#define InvokeFp(func) (this->*func) + +/* Get an EState's per-output-tuple exprcontext, making it if first use */ +#define GetPerTupleExprContext(estate) \ + ((estate)->es_per_tuple_exprcontext ? (estate)->es_per_tuple_exprcontext : MakePerTupleExprContext(estate)) + +#define GetPerTupleMemoryContext(estate) (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory) + +/* Reset an EState's per-output-tuple exprcontext, if one's been created */ +#define ResetPerTupleExprContext(estate) \ + do { \ + if ((estate)->es_per_tuple_exprcontext) \ + ResetExprContext((estate)->es_per_tuple_exprcontext); \ + } while (0) + +/* Reset an Slot's per-output-tuple context, if one's been created */ +#define ResetSlotPerTupleContext(slot) \ + do { \ + if ((slot) && (slot)->tts_per_tuple_mcxt) \ + MemoryContextReset((slot)->tts_per_tuple_mcxt); \ + } while (0) + +extern void ExecAssignExprContext(EState* estate, PlanState* planstate); +extern void ExecAssignResultType(PlanState* planstate, TupleDesc tupDesc); +extern void ExecAssignResultTypeFromTL(PlanState* planstate, TableAmType tam = TAM_HEAP); +extern TupleDesc ExecGetResultType(PlanState* planstate); +extern void ExecAssignVectorForExprEval(ExprContext* econtext); +extern ProjectionInfo* ExecBuildProjectionInfo( + List* targetList, ExprContext* econtext, TupleTableSlot* slot, TupleDesc inputDesc); +extern void ExecAssignProjectionInfo(PlanState* planstate, TupleDesc inputDesc); +extern void ExecAssignScanProjectionInfoWithVarno(ScanState* node, Index varno); +extern void ExecFreeExprContext(PlanState* planstate); +extern TupleDesc ExecGetScanType(ScanState* scanstate); +extern void ExecAssignScanType(ScanState* scanstate, TupleDesc tupDesc); +extern void ExecAssignScanTypeFromOuterPlan(ScanState* scanstate); + +extern bool ExecRelationIsTargetRelation(EState* estate, Index scanrelid); + +extern Relation ExecOpenScanRelation(EState* estate, Index scanrelid); +extern void ExecCloseScanRelation(Relation scanrel); + +extern Partition ExecOpenScanParitition( + EState* estate, Relation parent, PartitionIdentifier* partID, LOCKMODE lockmode); + +extern void ExecOpenIndices(ResultRelInfo* resultRelInfo, bool speculative); +extern void ExecCloseIndices(ResultRelInfo* resultRelInfo); +extern List* ExecInsertIndexTuples( + TupleTableSlot* slot, ItemPointer tupleid, EState* estate, Relation targetPartRel, Partition p, int2 bucketId, bool* conflict); +extern bool ExecCheckIndexConstraints(TupleTableSlot* slot, EState* estate, + Relation targetRel, Partition p, int2 bucketId, ItemPointer conflictTid); +extern bool check_exclusion_constraint(Relation heap, Relation index, IndexInfo* indexInfo, ItemPointer tupleid, + Datum* values, const bool* isnull, EState* estate, bool newIndex, bool errorOK); +extern void RegisterExprContextCallback(ExprContext* econtext, ExprContextCallbackFunction function, Datum arg); +extern void UnregisterExprContextCallback(ExprContext* econtext, ExprContextCallbackFunction function, Datum arg); +extern List* GetAccessedVarnoList(List* targetList, List* qual); +extern ProjectionInfo* ExecBuildVecProjectionInfo( + List* targetList, List* nt_qual, ExprContext* econtext, TupleTableSlot* slot, TupleDesc inputDesc); +extern bool tlist_matches_tupdesc(PlanState* ps, List* tlist, Index varno, TupleDesc tupdesc); + +extern int PthreadMutexLock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); +extern int PthreadMutexTryLock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); +extern int PthreadMutexUnlock(ResourceOwner owner, pthread_mutex_t* mutex, bool trace = true); + +extern bool executorEarlyStop(); +extern void ExecEarlyFree(PlanState* node); +extern void ExecEarlyFreeBody(PlanState* node); +extern void ExecReSetRecursivePlanTree(PlanState* node); + +extern void ExplainNodePending(PlanState* result_plan); +extern void ExplainNodeFinish(PlanState* result_plan, PlannedStmt* pstmt, TimestampTz current_time, bool is_pending); + +extern void ExecCopyDataFromDatum(PLpgSQL_datum** datums, int dno, Cursor_Data* target_cursor); +extern void ExecCopyDataToDatum(PLpgSQL_datum** datums, int dno, Cursor_Data* target_cursor); + +// AutoMutexLock +// Auto object for non-recursive pthread_mutex_t lock +// +class AutoMutexLock { +public: + AutoMutexLock(pthread_mutex_t* mutex, bool trace = true) + : m_mutex(mutex), m_fLocked(false), m_trace(trace), m_owner(t_thrd.utils_cxt.CurrentResourceOwner) + {} + + ~AutoMutexLock() + { + unLock(); + } + + inline void lock() + { + // Guard against recursive lock + // + if (!m_fLocked) { + int ret = 0; + + ret = PthreadMutexLock(m_owner, m_mutex, m_trace); + m_fLocked = (ret == 0 ? true : false); + if (!m_fLocked) { + /* this should never happen, system may be completely in a mess */ + if (ErrorContext == NULL) { + write_stderr(_("ERROR: pthread mutex lock failed, query id %lu: %s\n"), + u_sess->debug_query_id, + strerror(ret)); + abort(); + } else + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("pthread mutex lock failed: %s", strerror(ret)))); + } + } + } + + inline bool TryLock() + { + // Guard against recursive lock + // + if (!m_fLocked) { + m_fLocked = (PthreadMutexTryLock(m_owner, m_mutex, m_trace) == 0 ? true : false); + return m_fLocked; + } + + return false; + } + + inline void unLock() + { + if (m_fLocked) { + int ret = 0; + + if (t_thrd.utils_cxt.CurrentResourceOwner == NULL) + m_owner = NULL; + + ret = PthreadMutexUnlock(m_owner, m_mutex, m_trace); + m_fLocked = (ret == 0 ? false : true); + if (m_fLocked) { + /* this should never happen, system may be completely in a mess */ + if (ErrorContext == NULL) { + write_stderr(_("ERROR: pthread mutex unlock failed, query id %lu: %s\n"), + u_sess->debug_query_id, + strerror(ret)); + abort(); + } else + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("pthread mutex unlock failed: %s", strerror(ret)))); + } + } + } + +private: + pthread_mutex_t* m_mutex; + bool m_fLocked; + bool m_trace; + ResourceOwner m_owner; +}; + +#endif /* EXECUTOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/functions.h postgresql-hll-2.14/include/include/executor/functions.h --- postgresql-hll-2.14_old/include/include/executor/functions.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/functions.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * functions.h + * Declarations for execution of SQL-language functions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/functions.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FUNCTIONS_H +#define FUNCTIONS_H + +#include "nodes/execnodes.h" +#include "tcop/dest.h" + +/* This struct is known only within executor/functions.c */ +typedef struct SQLFunctionParseInfo* SQLFunctionParseInfoPtr; + +extern Datum fmgr_sql(PG_FUNCTION_ARGS); + +extern SQLFunctionParseInfoPtr prepare_sql_fn_parse_info(HeapTuple procedureTuple, Node* call_expr, Oid inputCollation); + +extern void sql_fn_parser_setup(struct ParseState* pstate, SQLFunctionParseInfoPtr pinfo); + +extern bool check_sql_fn_retval( + Oid func_id, Oid rettype, List* queryTreeList, bool* modifyTargetList, JunkFilter** junkFilter); + +extern DestReceiver* CreateSQLFunctionDestReceiver(void); + +#endif /* FUNCTIONS_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/hashjoin.h postgresql-hll-2.14/include/include/executor/hashjoin.h --- postgresql-hll-2.14_old/include/include/executor/hashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/hashjoin.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,185 @@ +/* ------------------------------------------------------------------------- + * + * hashjoin.h + * internal structures for hash joins + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/hashjoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HASHJOIN_H +#define HASHJOIN_H + +#include "nodes/execnodes.h" +#include "storage/buffile.h" + +/* ---------------------------------------------------------------- + * hash-join hash table structures + * + * Each active hashjoin has a HashJoinTable control block, which is + * palloc'd in the executor's per-query context. All other storage needed + * for the hashjoin is kept in private memory contexts, two for each hashjoin. + * This makes it easy and fast to release the storage when we don't need it + * anymore. (Exception: data associated with the temp files lives in the + * per-query context too, since we always call buffile.c in that context.) + * + * The hashtable contexts are made children of the per-query context, ensuring + * that they will be discarded at end of statement even if the join is + * aborted early by an error. (Likewise, any temporary files we make will + * be cleaned up by the virtual file manager in event of an error.) + * + * Storage that should live through the entire join is allocated from the + * "hashCxt", while storage that is only wanted for the current batch is + * allocated in the "batchCxt". By resetting the batchCxt at the end of + * each batch, we free all the per-batch storage reliably and without tedium. + * + * During first scan of inner relation, we get its tuples from executor. + * If nbatch > 1 then tuples that don't belong in first batch get saved + * into inner-batch temp files. The same statements apply for the + * first scan of the outer relation, except we write tuples to outer-batch + * temp files. After finishing the first scan, we do the following for + * each remaining batch: + * 1. Read tuples from inner batch file, load into hash buckets. + * 2. Read tuples from outer batch file, match to hash buckets and output. + * + * It is possible to increase nbatch on the fly if the in-memory hash table + * gets too big. The hash-value-to-batch computation is arranged so that this + * can only cause a tuple to go into a later batch than previously thought, + * never into an earlier batch. When we increase nbatch, we rescan the hash + * table and dump out any tuples that are now of a later batch to the correct + * inner batch file. Subsequently, while reading either inner or outer batch + * files, we might find tuples that no longer belong to the current batch; + * if so, we just dump them out to the correct batch file. + * ---------------------------------------------------------------- + */ + +/* these are in nodes/execnodes.h: */ +/* typedef struct HashJoinTupleData *HashJoinTuple; */ +/* typedef struct HashJoinTableData *HashJoinTable; */ + +typedef struct HashJoinTupleData { + struct HashJoinTupleData* next; /* link to next tuple in same bucket */ + uint32 hashvalue; /* tuple's hash code */ + /* Tuple data, in MinimalTuple format, follows on a MAXALIGN boundary */ +} HashJoinTupleData; + +#define HJTUPLE_OVERHEAD MAXALIGN(sizeof(HashJoinTupleData)) +#define HJTUPLE_MINTUPLE(hjtup) ((MinimalTuple)((char*)(hjtup) + HJTUPLE_OVERHEAD)) + +/* + * If the outer relation's distribution is sufficiently nonuniform, we attempt + * to optimize the join by treating the hash values corresponding to the outer + * relation's MCVs specially. Inner relation tuples matching these hash + * values go into the "skew" hashtable instead of the main hashtable, and + * outer relation tuples with these hash values are matched against that + * table instead of the main one. Thus, tuples with these hash values are + * effectively handled as part of the first batch and will never go to disk. + * The skew hashtable is limited to SKEW_WORK_MEM_PERCENT of the total memory + * allowed for the join; while building the hashtables, we decrease the number + * of MCVs being specially treated if needed to stay under this limit. + * + * Note: you might wonder why we look at the outer relation stats for this, + * rather than the inner. One reason is that the outer relation is typically + * bigger, so we get more I/O savings by optimizing for its most common values. + * Also, for similarly-sized relations, the planner prefers to put the more + * uniformly distributed relation on the inside, so we're more likely to find + * interesting skew in the outer relation. + */ +typedef struct HashSkewBucket { + uint32 hashvalue; /* common hash value */ + HashJoinTuple tuples; /* linked list of inner-relation tuples */ +} HashSkewBucket; + +#define SKEW_BUCKET_OVERHEAD MAXALIGN(sizeof(HashSkewBucket)) +#define INVALID_SKEW_BUCKET_NO (-1) +#define SKEW_WORK_MEM_PERCENT 2 +#define SKEW_MIN_OUTER_FRACTION 0.01 + +/* + * To reduce palloc overhead, the HashJoinTuples for the current batch are + * packed in 32kB buffers instead of pallocing each tuple individually. + */ +typedef struct HashMemoryChunkData { + int ntuples; /* number of tuples stored in this chunk */ + size_t maxlen; /* size of the buffer holding the tuples */ + size_t used; /* number of buffer bytes already used */ + + struct HashMemoryChunkData* next; /* pointer to the next chunk (linked list) */ + + char data[FLEXIBLE_ARRAY_MEMBER]; /* buffer allocated at the end */ +} HashMemoryChunkData; + +typedef struct HashMemoryChunkData* HashMemoryChunk; + +#define HASH_CHUNK_SIZE (32 * 1024L) +#define HASH_CHUNK_THRESHOLD (HASH_CHUNK_SIZE / 4) + +typedef struct HashJoinTableData { + int nbuckets; /* # buckets in the in-memory hash table */ + int log2_nbuckets; /* its log2 (nbuckets must be a power of 2) */ + + /* buckets[i] is head of list of tuples in i'th in-memory bucket */ + struct HashJoinTupleData** buckets; + /* buckets array is per-batch storage, as are all the tuples */ + + bool keepNulls; /* true to store unmatchable NULL tuples */ + + bool skewEnabled; /* are we using skew optimization? */ + HashSkewBucket** skewBucket; /* hashtable of skew buckets */ + int skewBucketLen; /* size of skewBucket array (a power of 2!) */ + int nSkewBuckets; /* number of active skew buckets */ + int* skewBucketNums; /* array indexes of active skew buckets */ + + int nbatch; /* number of batches */ + int curbatch; /* current batch #; 0 during 1st pass */ + + int nbatch_original; /* nbatch when we started inner scan */ + int nbatch_outstart; /* nbatch when we started outer scan */ + + bool growEnabled; /* flag to shut off nbatch increases */ + + double totalTuples; /* # tuples obtained from inner plan */ + + /* + * These arrays are allocated for the life of the hash join, but only if + * nbatch > 1. A file is opened only when we first write a tuple into it + * (otherwise its pointer remains NULL). Note that the zero'th array + * elements never get used, since we will process rather than dump out any + * tuples of batch zero. + */ + BufFile** innerBatchFile; /* buffered virtual temp file per batch */ + BufFile** outerBatchFile; /* buffered virtual temp file per batch */ + + /* + * Info about the datatype-specific hash functions for the datatypes being + * hashed. These are arrays of the same length as the number of hash join + * clauses (hash keys). + */ + FmgrInfo* outer_hashfunctions; /* lookup data for hash functions */ + FmgrInfo* inner_hashfunctions; /* lookup data for hash functions */ + bool* hashStrict; /* is each hash join operator strict? */ + + int64 spaceUsed; /* memory space currently used by tuples */ + int64 spaceAllowed; /* upper limit for space used */ + int64 spacePeak; /* peak space used */ + int64 spaceUsedSkew; /* skew hash table's current space usage */ + int64 spaceAllowedSkew; /* upper limit for skew hashtable */ + + MemoryContext hashCxt; /* context for whole-hash-join storage */ + MemoryContext batchCxt; /* context for this-batch-only storage */ + + /* used for dense allocation of tuples (into linked chunks) */ + HashMemoryChunk chunks; /* one list for the whole batch */ + int64 width[2]; /* first records tuple count, second records total width */ + bool causedBySysRes; /* the batch increase caused by system resources limit? */ + int64 maxMem; /* batch auto spread mem */ + int spreadNum; /* auto spread times */ + int64* spill_size; + uint64 spill_count; /* times of spilling to disk */ +} HashJoinTableData; + +#endif /* HASHJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/instrument.h postgresql-hll-2.14/include/include/executor/instrument.h --- postgresql-hll-2.14_old/include/include/executor/instrument.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/instrument.h 2020-12-12 17:06:43.186347251 +0800 @@ -0,0 +1,1062 @@ +/* ------------------------------------------------------------------------- + * + * instrument.h + * definitions for run-time statistics collection + * + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/executor/instrument.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTRUMENT_H +#define INSTRUMENT_H + +#include "portability/instr_time.h" +#include "nodes/pg_list.h" +#include "nodes/plannodes.h" +#include "lib/stringinfo.h" +#include "miscadmin.h" +#include "utils/anls_opt.h" +#include +#include "datatype/timestamp.h" +#include "storage/lwlock.h" + +class ThreadInstrumentation; +class StreamInstrumentation; + +extern THR_LOCAL ThreadInstrumentation* runtimeThreadInstr; + +#define trackpoint_number 10 +#define DN_NUM_STREAMS_IN_CN(num_streams, gather_count, query_dop) ((num_streams + gather_count) * query_dop) + +#define ECQUERYDATALEN 1024 + +#define TRACK_START(nodeid, id) \ + do { \ + StreamInstrumentation::TrackStartTime(nodeid, id); \ + } while (0); + +#define TRACK_END(nodeid, id) \ + do { \ + StreamInstrumentation::TrackEndTime(nodeid, id); \ + } while (0); + +typedef struct BufferUsage { + long shared_blks_hit; /* # of shared buffer hits */ + long shared_blks_read; /* # of shared disk blocks read */ + long shared_blks_dirtied; /* # of shared blocks dirtied */ + long shared_blks_written; /* # of shared disk blocks written */ + long local_blks_hit; /* # of local buffer hits */ + long local_blks_read; /* # of local disk blocks read */ + long local_blks_dirtied; /* # of shared blocks dirtied */ + long local_blks_written; /* # of local disk blocks written */ + long temp_blks_read; /* # of temp blocks read */ + long temp_blks_written; /* # of temp blocks written */ + instr_time blk_read_time; /* time spent reading */ + instr_time blk_write_time; /* time spent writing */ +} BufferUsage; + +typedef struct CPUUsage { + double m_cycles; /* number of cycles */ +} CPUUsage; + +/* Flag bits included in InstrAlloc's instrument_options bitmask */ +typedef enum InstrumentOption { + INSTRUMENT_NONE = 0, + INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */ + INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */ + INSTRUMENT_ROWS = 1 << 2, /* needs row count */ + INSTRUMENT_ALL = 0x7FFFFFFF +} InstrumentOption; + +/* Mark the DFS storage system type */ +typedef enum DFSType { + DFS_HDFS = 1, /* Hadoop HDFS storage system */ + DFS_OBS = 2, /* OBS key-value storage system */ + DFS_DFV = 3 /* DFV p-log based storage system */ + , + TYPE_LOG_FT /* foreign table type, log data */ +} DFSType; + +#define SORT_IN_DISK 0x00000001 /* space type Disk */ +#define SORT_IN_MEMORY 0x00000002 /* space type Memory */ + +enum sortMethodId { + /* sort Method */ + HEAPSORT, + QUICKSORT, + EXTERNALSORT, + EXTERNALMERGE, + STILLINPROGRESS +}; + +struct sortMessage { + sortMethodId TypeId; + char* sortName; +}; + +typedef struct SortHashInfo { + int sortMethodId; + int spaceTypeId; + long spaceUsed; + int nbatch; + int nbatch_original; + int nbuckets; + Size spacePeak; + int64 hash_FileNum; + int64 hash_innerFileNum; /* number of files to store build side data */ + int64 hash_outerFileNum; /* number of files to store probe side data */ + bool hash_writefile; + int hash_spillNum; + int hashtable_expand_times; + double hashbuild_time; + double hashagg_time; + long spill_size; /* Totoal disk IO */ + long spill_innerSize; /* disk IO of build side data that are spilt to disk */ + long spill_innerSizePartMax; + long spill_innerSizePartMin; + long spill_outerSize; /* disk IO of probe side data that are spilt to disk */ + long spill_outerSizePartMax; + long spill_outerSizePartMin; + int spill_innerPartNum; /* number of inner partitions that are spilt to disk */ + int spill_outerPartNum; /* number of outer partitions that are spilt to disk */ + int hash_partNum; /* partition number of either build or probe side */ +} SortHashInfo; + +typedef struct StreamTime { + bool need_timer; + bool running; + instr_time starttime; + instr_time counter; + double firsttuple; + double tuplecount; + double startup; /* Total startup time (in seconds) */ + double total; /* Total total time (in seconds) */ + double ntuples; /* Total tuples produced */ + double nloops; /* # of run cycles for this node */ + +} StreamTime; + +typedef struct AccumCounters { + int64 accumCounters[3]; + int64 tempCounters[3]; +} AccumCounters; + +typedef struct Track { + int node_id; + bool is_datanode; /* mark current plan node is datanode or not */ + ThreadId track_threadId; + int registerTrackId; + StreamTime track_time; + AccumCounters accumCounters; + bool active; /* track.active == true means track is effective */ +} Track; + +typedef struct RoughCheckInfo { + uint64 m_CUFull; + uint64 m_CUNone; + uint64 m_CUSome; + + inline void IncFullCUNum() + { + ++m_CUFull; + } + inline void IncNoneCUNum() + { + ++m_CUNone; + } + inline void IncSomeCUNum() + { + ++m_CUSome; + } + +} RCInfo; + +typedef struct NetWorkPerfData { + int64 network_size; + instr_time start_poll_time; + instr_time start_deserialize_time; + instr_time start_copy_time; + instr_time network_poll_time; + instr_time network_deserialize_time; + instr_time network_copy_time; + double total_poll_time; + double total_deserialize_time; + double total_copy_time; +} NetWorkPerfData; + +/* For stream thread sending time */ +typedef struct StreamSendData { + instr_time start_send_time; + instr_time start_wait_quota_time; + instr_time start_OS_send_time; + instr_time start_serialize_time; + instr_time start_copy_time; + instr_time stream_send_time; + instr_time stream_wait_quota_time; + instr_time stream_OS_send_time; + instr_time stream_serialize_time; + instr_time stream_copy_time; + double total_send_time; + double total_wait_quota_time; + double total_os_send_time; + double total_serialize_time; + double total_copy_time; + bool loops; +} StreamSendData; + +typedef struct MemoryInfo { + int64 peakOpMemory; /* Peak Memory usage for per operator */ + int64 peakControlMemory; /* Peak Control Memory */ + int64 peakNodeMemory; /* Peak Memory usage for per query */ + int32 operatorMemory; /* Operator Memory for intensive operator */ + MemoryContext nodeContext; /* node context */ + List* controlContextList; /* control list of memory contexts */ +} MemoryInfo; + +/* + * max non-iteration and iteration times performance can support + */ +#define RECUSIVE_MAX_ITER_NUM 201 + +typedef struct RecursiveInfo { + int niters; /* iteration number */ + uint64 iter_ntuples[RECUSIVE_MAX_ITER_NUM]; + bool has_reach_limit; +} RecursiveInfo; + +typedef struct Instrumentation { + /* Parameters set at node creation: */ + bool need_timer; /* TRUE if we need timer data */ + bool need_bufusage; /* TRUE if we need buffer usage data */ + bool needRCInfo; + /* Info about current plan cycle: */ + bool running; /* TRUE if we've completed first tuple */ + instr_time starttime; /* Start time of current iteration of node */ + instr_time counter; /* Accumulated runtime for this node */ + double firsttuple; /* Time for first tuple of this cycle */ + double tuplecount; /* Tuples emitted so far this cycle */ + BufferUsage bufusage_start; /* Buffer usage at start */ + /* Accumulated statistics across all completed cycles: */ + double startup; /* Total startup time (in seconds) */ + double total; /* Total total time (in seconds) */ + double ntuples; /* Total tuples produced */ + double nloops; /* # of run cycles for this node */ + double nfiltered1; /* # tuples removed by scanqual or joinqual */ + double nfiltered2; /* # tuples removed by "other" quals OR + * # tuples updated by MERGE */ + BufferUsage bufusage; /* Total buffer usage */ + CPUUsage cpuusage_start; /* CPU usage at start */ + CPUUsage cpuusage; /* Total CPU usage */ + SortHashInfo sorthashinfo; /* Sort/hash operator perf data*/ + NetWorkPerfData network_perfdata; /* Network performance data */ + StreamSendData stream_senddata; /* Stream send time */ + RCInfo rcInfo; /* Cu filter performance data */ + MemoryInfo memoryinfo; /* Peak Memory data */ + /* Count up the number of files which are pruned dynamically. */ + uint64 dynamicPrunFiles; + /* Count up the number of files which are pruned static */ + uint64 staticPruneFiles; + /* Count up the number of rows which are filtered by the bloom filter. */ + uint64 bloomFilterRows; + /* Count up the number of strides which are filtered by the bloom filter. */ + uint64 bloomFilterBlocks; + /* Count up the number of rows which are filtered by the min/max. */ + uint64 minmaxFilterRows; + double init_time; /* executor start time */ + double end_time; /* executor end time */ + double run_time; /* executor run time */ + /* Count up the number of hdfs local block read. */ + double localBlock; + /* Count up the number of hdfs remote blocks read. */ + double remoteBlock; + uint32 warning; + /* Count the number of intersections with dfs namenode/datanode. */ + uint64 nnCalls; + uint64 dnCalls; + /* Count up the number of files to access */ + uint64 minmaxCheckFiles; + /* Count up the number of filtered files */ + uint64 minmaxFilterFiles; + /* Count up the number of stripe to access */ + uint64 minmaxCheckStripe; + /* Count up the number of filtered stripe */ + uint64 minmaxFilterStripe; + /* Count up the number of stride to access */ + uint64 minmaxCheckStride; + /* Count up the number of filtered stride */ + uint64 minmaxFilterStride; + /* Count up the number of cache hint of orc data */ + uint64 orcDataCacheBlockCount; + uint64 orcDataCacheBlockSize; + /* Count up the number of load of orc data */ + uint64 orcDataLoadBlockCount; + uint64 orcDataLoadBlockSize; + /* Count up the number of cache hint of orc meta data*/ + uint64 orcMetaCacheBlockCount; + uint64 orcMetaCacheBlockSize; + /* Count up the number of oad of orc meta data */ + uint64 orcMetaLoadBlockCount; + uint64 orcMetaLoadBlockSize; + bool isLlvmOpt; /* Optimize plan by using llvm. */ + int dfsType; /* Indicate the storage file system type */ + int width; /* avg width for the in memory tuples */ + bool sysBusy; /* if disk spill caused by system busy */ + int spreadNum; /* auto spread num */ + bool status; + bool first_time; + int dop; + TimestampTz enter_time; + + int ec_operator; /* is ec operator */ + int ec_status; /* ec task status */ + char ec_execute_datanode[NAMEDATALEN + 1]; /* ec execute datanode name*/ + char ec_dsn[NAMEDATALEN + 1]; /* ec dsn*/ + char ec_username[NAMEDATALEN + 1]; /* ec username*/ + char ec_query[ECQUERYDATALEN + 1]; /* ec execute query*/ + int ec_libodbc_type; /* ec execute libodbc_type*/ + int64 ec_fetch_count; /* ec fetch count*/ + RecursiveInfo recursiveInfo; +} Instrumentation; + +/* instrumentation data */ +typedef struct InstrStreamPlanData { + /* whether the plannode is valid */ + bool isValid; + bool isExecute; + bool isSend; + Instrumentation instruPlanData; +} InstrStreamPlanData; + +/* every plannode has a nodeInstr */ +struct NodeInstr { + /* Instrument data */ + InstrStreamPlanData instr; + int planNodeId; + int planParentId; + /* plan type for writing csv */ + int planType; + /* plantypestridx correspond to plantype for writing csv */ + uint planTypeStrIdx; + /* plan node name */ + char* name; + Track* tracks; + double ntime; +}; + +/* threadTrack is correspond to trackId in trackdesc */ +enum ThreadTrack { + /* general track */ + RECV_PLAN = 0, + START_EXEC, + FINISH_EXEC, + REPORT_FINISH, + PASS_WLM, + STREAMNET_INIT, + + /* node track */ + LOAD_CU_DESC, + MIN_MAX_CHECK, + FILL_BATCH, + GET_CU_DATA, + UNCOMPRESS_CU, + CSTORE_PROJECT, + LLVM_COMPILE_TIME, + CNNET_INIT, + CN_CHECK_AND_UPDATE_NODEDEF, + CN_SERIALIZE_PLAN, + CN_SEND_QUERYID_WITH_SYNC, + CN_SEND_BEGIN_COMMAND, + CN_START_COMMAND, + DN_STREAM_THREAD_INIT, + FILL_LATER_BATCH, + GET_CU_DATA_LATER_READ, + GET_CU_SIZE, + GET_CU_DATA_FROM_CACHE, + FILL_VECTOR_BATCH_BY_TID, + SCAN_BY_TID, + PREFETCH_CU_LIST, + GET_COMPUTE_DATANODE_CONNECTION, + GET_COMPUTE_POOL_CONNECTION, + GET_PG_LOG_TUPLES, + GET_GS_PROFILE_TUPLES, + TSSTORE_PROJECT, + TSSTORE_SEARCH, + TSSTORE_SEARCH_TAGID, + + TRACK_NUM +}; + +/* planType */ +#define HASHJOIN_OP 0x00000001 /* hashjoin */ +#define IO_OP 0x00000002 /* scan */ +#define JOIN_OP 0x00000004 /* join */ +#define SORT_OP 0x00000008 /* sort */ +#define NET_OP 0x00000010 /* net */ +#define UTILITY_OP 0x00000020 /* utility */ +#define HASHAGG_OP 0x00000040 /* hashagg */ + +/* trackType */ +#define TRACK_TIMESTAMP 0x00000001 +#define TRACK_TIME 0x00000002 +#define TRACK_COUNT 0x00000004 +#define TRACK_VALUE 0x00000008 +#define TRACK_VALUE_COUNT 0x00000010 + +/* track information */ +struct TrackDesc { + /* trackId in ThreadTrack */ + ThreadTrack trackId; + + /* trackName correspond to trackId */ + char* trackName; + + /* nodeBind is false means general track, true means node track */ + bool nodeBind; + + /* track type includes TRACK_COUNT, TRACK_TIME ,TRACK_TIMESTAMP */ + int trackType; +}; + +/* + * threadInstrInfo is obtained from getstreamInfo. + * threadInstrInfo in CN larger than threadInstrInfo in DN + * because of GATHER in CN. + */ +typedef struct ThreadInstrInfo { + /* head node id. */ + int segmentId; + + /* num of nodes in this stream. */ + int numOfNodes; + + /* base offset by the node instr array. */ + int offset; + +} ThreadInstrInfo; + +struct Plan; + +/* + * thread instrumentation + * is allocated in globalstreaminstrumentation according to needs. + * nodeInstr include instrumentation and nodetrack info in a plannodeid. + * generaltrack record the generaltrack info in every thread. + */ +class ThreadInstrumentation : public BaseObject { +public: + /* init in every thread */ + ThreadInstrumentation(uint64 queryId, int segmentId, int nodesInThread, int nodesInSql); + + ~ThreadInstrumentation(); + + /* return allocated slot for planNodeId */ + Instrumentation* allocInstrSlot(int planNodeId, int parentPlanId, Plan* plan, struct EState* estate); + + /* thread track time */ + void startTrack(int planId, ThreadTrack instrIdx); + + void endTrack(int planId, ThreadTrack instrIdx); + + int getSegmentId() + { + return m_segmentId; + } + + void setQueryString(char* qstr); + + int* get_instrArrayMap() + { + return m_instrArrayMap; + } + + Track* get_tracks(int planNodeId) + { + if (m_instrArrayMap[planNodeId - 1] == -1) + return NULL; + else { + Assert(m_instrArrayMap[planNodeId - 1] != -1); + return m_instrArray[m_instrArrayMap[planNodeId - 1]].tracks; + } + } + + int get_tracknum() + { + return m_nodeTrackNum; + } + + int getgeneraltracknum() + { + return m_generalTrackNum; + } + + int get_generaltracknum() + { + return m_generalTrackNum; + } + + int get_instrArrayLen() + { + return m_instrArrayLen; + } + +public: + uint64 m_queryId; + + /* stream top plan_node_id */ + int m_segmentId; + + /* the allocate instr array. */ + NodeInstr* m_instrArray; + + /* instr array length. */ + int m_instrArrayLen; + + /* node id to the offset of the instr array map. */ + int* m_instrArrayMap; + + /* map array length has all nodes. */ + int m_instrArrayMapLen; + + int m_instrArrayAllocIndx; + + int m_generalTrackNum; + + /* track which do not belong to any plan_node_id */ + Track* m_generalTrackArray; + + int m_nodeTrackNum; + + char* m_queryString; +}; + +/* + * GlobalStreamInstrumentation + * Instrumentation information for distributed query. + * allocated in topconsumer of DN and CN. + */ +class StreamInstrumentation : public BaseObject { +public: + /* construnctor */ + StreamInstrumentation(int size, int num_streams, int gather_count, int query_dop, int plan_size, int start_node_id, + int option, bool trackoption); + + /* deconstructor */ + ~StreamInstrumentation(); + + static StreamInstrumentation* InitOnDn(void* desc, int dop); + + static StreamInstrumentation* InitOnCn(void* desc, int dop); + + /* init globalstreaminstrumentation and threadinstrumentation in compute pool */ + static StreamInstrumentation* InitOnCP(void* desc, int dop); + + /* get the toplogy of this stream query. */ + void getStreamInfo(Plan* result_plan, PlannedStmt* planned_stmt, int dop, ThreadInstrInfo* info, int offset); + + void allocateAllThreadInstrOnDN(bool in_compute_pool); + + void allocateAllThreadInstrOnCN(); + + /* register thread in compute pool */ + void allocateAllThreadInstrOnCP(int dop); + + /* serialize the specific instrument data to remote */ + void serializeSend(); + + /* deserialize the data, and put in the specific slot. -1 means on DWS CN, else on DWS DN */ + void deserialize(int idx, char* msg, size_t len, bool operator_statitics, int cur_smp_id = -1); + + /* serialize the track data to remote. */ + void serializeSendTrack(); + + /* deserialize the track data. */ + void deserializeTrack(int idx, char* msg, size_t len); + + /* return the instrumentation related node number. */ + int getInstruNodeNum() + { + return m_nodes_num; + } + + int getInstruPlanSize() + { + return m_plannodes_num; + } + + int getInstruStartId() + { + return m_start_node_id; + } + + int getInstruThreadNum() + { + return m_num_streams; + } + + int get_gather_num() + { + return m_gather_count; + } + + int get_threadInstrArrayLen() + { + return m_threadInstrArrayLen; + } + + /* allocate slot for a node. */ + Instrumentation* allocInstrSlot(int planNodeId); + + /* return a slot in specific idx,plannodeid */ + Instrumentation* getInstrSlot(int idx, int planNodeId); + + /* Return a slot by specific idx, plannodeid and smpid. */ + Instrumentation* getInstrSlot(int idx, int planNodeId, int smpId); + + /* if this plan node run in the data node. */ + bool isFromDataNode(int planNodeId); + + bool isTrack(); + + bool needTrack() + { + return m_trackoption; + } + + void set_size(int plan_size) + { + m_nodes_num = plan_size; + m_option = 1; + } + + void SetStreamSend(int planNodeId, bool send); + bool IsSend(int idx, int plan_id, int smp_id); + + /* Get dop by plan node id. */ + int getNodeDop(int planNodeId) + { + Assert(planNodeId >= 1 && planNodeId <= m_plannodes_num); + return m_node_dops[planNodeId - 1]; + } + + int get_option() + { + return m_option; + } + + int get_query_dop() + { + return m_query_dop; + } + + MemoryContext getInstrDataContext() + { + return m_instrDataContext; + } + + int* get_planIdOffsetArray() + { + return m_planIdOffsetArray; + } + + // track time + static void TrackStartTime(int planNodeId, int trackId); + static void TrackEndTime(int planNodeId, int trackId); + + /* context for CN instrData */ + MemoryContext m_instrDataContext; + + void SetNetWork(int planNodeId, int64 buf_len); + void SetPeakNodeMemory(int planNodeId, int64 memory_size); + + ThreadInstrumentation* allocThreadInstrumentation(int SegmentId); + + /* just called by the CN of the compute pool */ + void aggregate(int plannode_num); + + /*thread instrumenation array.*/ + ThreadInstrumentation** m_threadInstrArray; + + /* every node has a offset. */ + int* m_planIdOffsetArray; + + /* get ThreadInstrumentation of TOPconsumer */ + ThreadInstrumentation* getThreadInstrumentationCN(int idx) + { + int dn_num_streams = DN_NUM_STREAMS_IN_CN(m_num_streams, m_gather_count, m_query_dop); + return m_threadInstrArray[1 + idx * dn_num_streams]; + } + + /* get threadinstrArray in idx(DN) and planNodeId */ + ThreadInstrumentation* getThreadInstrumentationCN(int idx, int planNodeId, int smp) + { + int offset = + (m_planIdOffsetArray[planNodeId - 1] == 0) ? -1 : (m_planIdOffsetArray[planNodeId - 1] - 1) * m_query_dop; + int dn_num_streams = DN_NUM_STREAMS_IN_CN(m_num_streams, m_gather_count, m_query_dop); + + Assert(planNodeId >= 1 && planNodeId <= m_plannodes_num); + + if (offset == -1) + return m_threadInstrArray[0]; + else + return m_threadInstrArray[1 + idx * dn_num_streams + offset + smp]; + } + + /* get ThreadInstrumentation in DN */ + ThreadInstrumentation* getThreadInstrumentationDN(int planNodeId) + { + return m_threadInstrArray[m_planIdOffsetArray[planNodeId - 1] * m_query_dop]; + } + + /* get threadinstrumentation of current CN */ + ThreadInstrumentation* get_cnthreadinstrumentation(int index) + { + Assert(index >= 0 && index <= m_threadInstrArrayLen); + + return m_threadInstrArray[index]; + } + + int get_startnodeid() + { + /* get start_node_id of DN*/ + for (int i = 1; i < m_plannodes_num + 1; i++) { + if (m_planIdOffsetArray[i - 1] == 1) { + return i; + } + } + + return 1; + } + +private: + /* number of data nodes. */ + int m_nodes_num; + + /* number of stream nodes. */ + int m_num_streams; + + /* gather operator count */ + int m_gather_count; + + /* query dop. */ + int m_query_dop; + + /* number of plan nodes. */ + int m_plannodes_num; + + // the query id of the global instrumentation. + uint64 m_query_id; + + /* start node id of plan. */ + int m_start_node_id; + + /* dop of each plan nodes. */ + int* m_node_dops; + + /* how many thread instrumentation */ + int m_threadInstrArrayLen; + + /* thread info for this query*/ + ThreadInstrInfo* m_streamInfo; + + int m_streamInfoIdx; + + /* instrumentation flag. */ + int m_option; + + /* track flag */ + bool m_trackoption; +}; + +// Maximal number of counters support +// +#define MAX_CPU_COUNTERS 3 + +// Predefined PMU counter groups +// +typedef enum CPUMonGroupID { + CMON_GENERAL = 0, +} CPUMonGroupID; + +// For view of gs_wlm_operator_history +// +typedef enum WlmOperatorstatus { + Operator_Normal = 0, + Operator_Pending, + Operator_Invalid, +} WlmOperatorstatus; + +typedef struct CPUMonGroup { + // group identifier + // + CPUMonGroupID m_id; + // list of counters + // + int m_cCounters; + int m_counters[MAX_CPU_COUNTERS]; +} CPUMonGroup; + +// Core class implementing PMU counters monitoring +// +class CPUMon { +public: + static THR_LOCAL bool m_has_perf; + static THR_LOCAL bool m_has_initialize; + +private: + // Number of counters in the group + // + static THR_LOCAL int m_cCounters; + + // File descriptor for each counter + // + static THR_LOCAL int m_fd[MAX_CPU_COUNTERS]; + +private: + FORCE_INLINE static void validCounter(_in_ int i) + { + DBG_ASSERT(i >= 0 && i < m_cCounters); + } + +public: + static void Initialize(_in_ CPUMonGroupID id); + static void Shutdown(); + static int64 ReadCounter(_in_ int i); + static int ReadCounters(_out_ int64* pCounters); + static int ResetCounters(_out_ int64* pCounters); + static int RestartCounters(_out_ int64* pCounters, _out_ int64* pAccumCounters); + static int AccumCounters(__inout int64* pCounters, __inout int64* pAccumCounters); + static bool get_perf(); +}; + +typedef struct OBSRuntimeInfo { + NameData relname; + int32 file_scanned; + int64 data_size; + double actual_time; + int32 format; +} OBSRuntimeInfo; + +/* class to collect the OBS runtime info. */ +class OBSInstrumentation : public BaseObject { +public: + // construnctor + OBSInstrumentation(); + + // deconstructor + ~OBSInstrumentation(); + + /* called by HdfsEndForeignScan to collect node data */ + void save(const char* relname, int file_scanned, int64 data_size, double actual_time, int32 format); + + /* send the obs runimte info to uppler node. */ + void serializeSend(); + + /* receive data from lower node. */ + void deserialize(char* msg, size_t len); + + /* insert obs runtime data to pg_obsscaninfo. */ + void insertData(uint64 queryid); + + bool* m_p_globalOBSInstrument_valid; + +private: + List* m_rels; + MemoryContext m_ctx; +}; + +typedef struct Qpid { + Oid procId; /* cn thread id for the statement */ + uint64 queryId; /* debug query id for statement */ + int plannodeid; +} Qpid; + +typedef struct OperatorProfileTable { + int max_realtime_num; /* max session info num in the hash table */ + int max_collectinfo_num; /* max collect info num in list */ + + HTAB* explain_info_hashtbl; /* collect information hash table */ + HTAB* collected_info_hashtbl; /* collect information hash table */ +} OperatorProfileTable; + +typedef struct OperatorPlanInfo { + char* operation; /* operator name */ + char* orientation; /* row or column */ + char* strategy; /* physical attributes of the operator */ + char* options; /* logical attributes of the operator */ + char* condition; /* predicates */ + char* projection; /* projection of operator */ + int parent_node_id; /* id of parent node */ + int left_child_id; /* id of the left child */ + int right_child_id; /* id of the right child */ +} OperatorPlanInfo; + +typedef struct OperatorInfo { + int64 total_tuples; /* Total tuples produced */ + int64 peak_memory; + int64 spill_size; + TimestampTz enter_time; + int64 startup_time; + int64 execute_time; + uint status; + uint warning; + + int ec_operator; + int ec_status; + char* ec_execute_datanode; + char* ec_dsn; + char* ec_username; + char* ec_query; + int ec_libodbc_type; + int64 ec_fetch_count; + OperatorPlanInfo planinfo; + + char* datname; +} OperatorInfo; + +typedef struct ExplainDNodeInfo { + Qpid qid; /* id for statement on dn */ + Oid userid; /* user id */ + bool execute_on_datanode; /* execute on datanode */ + bool can_record_to_table; /* flag for whether to record the information table */ + WlmOperatorstatus status; /* the status for this operator */ + char* plan_name; /* plan node name */ + int query_dop; /* query dop */ + int64 estimated_rows; /* plan estimated rows */ + void* explain_entry; /* session instrumentation entry */ + OperatorInfo geninfo; /* general info for the dnode collect info */ + TimestampTz exptime; /* record expire time */ +} ExplainDNodeInfo; + +typedef struct ExplainGeneralInfo { + ThreadId tid; /* thread id for statement */ + uint64 query_id; /* debug query id */ + int plan_node_id; /* plan node id */ + char* plan_node_name; /* plan node name */ + TimestampTz start_time; /* start execute time for operator */ + double startup_time; /* the latency of the first output tuple */ + double duration_time; /* max execute time */ + int query_dop; /* query dop */ + int64 estimate_rows; /* plan estimated rows */ + int64 tuple_processed; /* plan processed rows */ + int32 min_peak_memory; /* min peak memory for each datanode */ + int32 max_peak_memory; /* max peak memory for each datanode */ + int32 avg_peak_memory; /* average peak memory for each datanode */ + int memory_skewed; /* peak memory skew for each datanode */ + int32 min_spill_size; /* min spill size for each datanode */ + int32 max_spill_size; /* max spill size for each datanode */ + int32 avg_spill_size; /* average spill size for each datanode */ + int i_o_skew; /* spill size skew for each datanode */ + int64 min_cpu_time; /* min execute time for each datanode */ + int64 max_cpu_time; /* max execute time for each datanode */ + int64 total_cpu_time; /* total execute time for each datanode */ + int cpu_skew; /* execute time skew for each datanode */ + int warn_prof_info; /* warning info */ + bool status; /* execute status */ + bool execute_on_datanode; /* execute on datanode */ + bool remove; /* remove info from hash table */ + + int ec_operator; /* is ec operator */ + int ec_status; /* ec task status */ + char* ec_execute_datanode; /* ec execute datanode name*/ + char* ec_dsn; /* ec dsn*/ + char* ec_username; /* ec username*/ + char* ec_query; /* ec execute query*/ + int ec_libodbc_type; /* ec execute libodbc_type*/ + int64 ec_fetch_count; /* ec fetch count*/ + + char* operation; + char* orientation; + char* strategy; + char* options; + char* condition; + char* projection; + int parent_node_id; + int left_child_id; + int right_child_id; + char* datname; +} ExplainGeneralInfo; + +typedef struct size_info { + int64 total_tuple; + int64 total_memory; + int64 total_spill_size; + int64 total_cpu_time; + int64 max_peak_memory; + int64 min_peak_memory; + int64 max_spill_size; + int64 min_spill_size; + int64 min_cpu_time; + int64 max_cpu_time; + TimestampTz start_time; + double startup_time; + double duration_time; /* max execute time */ + char* plan_node_name; + uint warn_prof_info; + uint status; + bool has_data; + int dn_count; + + int ec_operator; + int ec_status; + char* ec_execute_datanode; + char* ec_dsn; + char* ec_username; + char* ec_query; + int ec_libodbc_type; + int64 ec_fetch_count; +} size_info; + +extern OperatorProfileTable g_operator_table; + +extern Instrumentation* InstrAlloc(int n, int instrument_options); +extern void InstrStartNode(Instrumentation* instr); +extern void InstrStopNode(Instrumentation* instr, double nTuples); +extern void InstrEndLoop(Instrumentation* instr); +extern void StreamEndLoop(StreamTime* instr); +extern void AddControlMemoryContext(Instrumentation* instr, MemoryContext context); +extern void CalculateContextSize(MemoryContext ctx, int64* memorySize); +extern void NetWorkTimePollStart(Instrumentation* instr); +extern void NetWorkTimePollEnd(Instrumentation* instr); +extern void NetWorkTimeDeserializeStart(Instrumentation* instr); +extern void NetWorkTimeDeserializeEnd(Instrumentation* instr); +extern void NetWorkTimeCopyStart(Instrumentation* instr); +extern void NetWorkTimeCopyEnd(Instrumentation* instr); +extern void SetInstrNull(); + +extern void StreamTimeSendStart(Instrumentation* instr); +extern void StreamTimeSendEnd(Instrumentation* instr); +extern void StreamTimeWaitQuotaStart(Instrumentation* instr); +extern void StreamTimeWaitQuotaEnd(Instrumentation* instr); +extern void StreamTimeOSSendStart(Instrumentation* instr); +extern void StreamTimeOSSendEnd(Instrumentation* instr); +extern void StreamTimeSerilizeStart(Instrumentation* instr); +extern void StreamTimeSerilizeEnd(Instrumentation* instr); +extern void StreamTimeCopyStart(Instrumentation* instr); +extern void StreamTimeCopyEnd(Instrumentation* instr); + +extern LWLock* LockOperRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockOperHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockOperRealTHashPartition(uint32 hashCode); +extern void UnLockOperHistHashPartition(uint32 hashCode); +extern void ExplainCreateDNodeInfoOnDN( + Qpid* qid, Instrumentation* instr, bool on_dn, const char* plan_name, int dop, int64 estimated_rows); +extern uint32 GetHashPlanCode(const void* key1, Size keysize); +extern void InitOperStatProfile(void); +extern void* ExplainGetSessionStatistics(int* num); +extern void ExplainSetSessionInfo(int plan_node_id, Instrumentation* instr, bool on_datanode, const char* plan_name, + int dop, int64 estimated_rows, TimestampTz current_time, OperatorPlanInfo* opt_plan_info); +extern void* ExplainGetSessionInfo(const Qpid* qid, int removed, int* num); +extern void releaseExplainTable(); +extern bool IsQpidInvalid(const Qpid* qid); +extern void sendExplainInfo(OperatorInfo* sessionMemory); +extern void ExplainStartToGetStatistics(void); +extern void removeExplainInfo(int plan_node_id); +extern void OperatorStrategyFunc4SessionInfo(StringInfo msg, void* suminfo, int size); +extern void setOperatorInfo(OperatorInfo* operatorMemory, Instrumentation* InstrMemory, + OperatorPlanInfo* opt_plan_info = NULL); +extern int64 e_rows_convert_to_int64(double plan_rows); +extern void releaseOperatorInfoEC(OperatorInfo* sessionMemory); +#endif /* INSTRUMENT_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/lightProxy.h postgresql-hll-2.14/include/include/executor/lightProxy.h --- postgresql-hll-2.14_old/include/include/executor/lightProxy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/lightProxy.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,206 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lightProxy.h + * + * + * + * IDENTIFICATION + * src/include/executor/lightProxy.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ +#define SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ + +#include "commands/prepare.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/plancache.h" + +#define BIND_MESSAGE 1 +#define DESC_MESSAGE 2 +#define EXEC_MESSAGE 3 + +#ifdef USE_ASSERT_CHECKING +#ifndef LPROXY_DEBUG +#define LPROXY_DEBUG(A) A +#endif +#else +#ifndef LPROXY_DEBUG +#define LPROXY_DEBUG(A) /* A */ +#endif +#endif + +/* check whether query executed through light proxy or not*/ +extern bool IsLightProxyOn(void); +extern void GPCDropLPIfNecessary(const char *stmt_name, bool need_drop_dnstmt, + bool need_del, CachedPlanSource *reset_plan); +void GPCFillMsgForLp(CachedPlanSource* psrc); + +CmdType set_command_type_by_commandTag(const char* commandTag); + +typedef enum LightUnSupportType { + CTRL_DISABLE = 0, + ENCODE_UNSUPPORT, + CURSOR_UNSUPPORT, + REMOTE_UNSUPPORT, + CMD_UNSUPPORT, + FOREIGN_UNSUPPORT, + STATEMENT_UNSUPPORT, + USERTYPE_UNSUPPORT, + MAX_UNSUPPORT_TYPE +} LightUnSupportType; + +/* like in RemoteQueryState */ +struct lightProxyErrData { + bool hasError; /* indicate whether some error occurs */ + + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + bool is_fatal_error; /* mark if it is a FATAL error */ + RemoteErrorData remoteErrData; /* error data from remote */ +}; + +struct lightProxyMsgCtl { + bool cnMsg; + bool sendDMsg; + bool hasResult; + lightProxyErrData* errData; + + int* process_count; + +#ifdef LPROXY_DEBUG + char* stmt_name; + const char* query_string; +#endif +}; + +typedef struct stmtLpObj { + char stmtname[NAMEDATALEN]; + lightProxy *proxy; +} stmtLpObj; + +typedef struct lightProxyNamedObj { + char portalname[NAMEDATALEN]; + lightProxy *proxy; +} lightProxyNamedObj; + +class lightProxy : public BaseObject { +public: + // constructor. + lightProxy(MemoryContext context, CachedPlanSource *psrc, const char *portalname, const char *stmtname); + + lightProxy(Query *query); + + ~lightProxy(); + + static ExecNodes *checkLightQuery(Query *query); + + // check if enable router for lightproxy + static ExecNodes *checkRouterQuery(Query *query); + + // after bind we need to set this for discrible and execute + static void setCurrentProxy(lightProxy *proxy); + + // process B/D/E message + static bool processMsg(int msgType, StringInfo msg); + + static void initStmtHtab(); + + static void initlightProxyTable(); + + static lightProxy *locateLpByStmtName(const char *stmtname); + + static lightProxy *locateLightProxy(const char *portalname); + + static lightProxy *tryLocateLightProxy(StringInfo msg); + // run with simple query message + void runSimpleQuery(StringInfo exec_message); + + // run with batch message + int runBatchMsg(StringInfo batch_message, bool sendDMsg, int batch_count); + + static void tearDown(lightProxy *proxy); + + void storeLpByStmtName(const char *stmtname); + + void storeLightProxy(const char *portalname); + + void removeLpByStmtName(const char *stmtname); + + static void removeLightProxy(const char* portalname); + + static bool isDeleteLimit(const Query *query); + +public: + CachedPlanSource *m_cplan; + + int m_nodeIdx; + + MemoryContext m_context; + + /* whether row trigger can shippable. */ + bool m_isRowTriggerShippable; + + const char *m_stmtName; + + const char *m_portalName; + + int16 *m_formats; + + DatanodeStatement *m_entry; + +protected: + // saveMsg + void saveMsg(int msgType, StringInfo msg); + // get result format from msg + void getResultFormat(StringInfo message); + + void assemableMsg(char msgtype, StringInfo msgBuf, bool trigger_ship = false); + + // run with execute message + void runMsg(StringInfo exec_message); + + void connect(); + + void handleResponse(); + + void sendParseIfNecessary(); + + void proxyNodeBegin(bool is_read_only); + + CmdType m_cmdType; + CmdType queryType; + +private: + Query *m_query; + + PGXCNodeHandle *m_handle; + + StringInfoData m_bindMessage; + + StringInfoData m_describeMessage; + + lightProxyMsgCtl *m_msgctl; +}; + +extern bool exec_query_through_light_proxy(List* querytree_list, Node* parsetree, bool snapshot_set, StringInfo msg, + MemoryContext OptimizerContext); + +#endif /* SRC_INCLUDE_EXECUTOR_LIGHTPROXY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeAgg.h postgresql-hll-2.14/include/include/executor/nodeAgg.h --- postgresql-hll-2.14_old/include/include/executor/nodeAgg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeAgg.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,288 @@ +/* ------------------------------------------------------------------------- + * + * nodeAgg.h + * prototypes for nodeAgg.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeAgg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEAGG_H +#define NODEAGG_H + +#include "nodes/execnodes.h" +#include "catalog/pg_aggregate.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" +#include "executor/executor.h" +#include "executor/nodeAgg.h" +#include "miscadmin.h" +#include "nodes/nodeFuncs.h" +#include "optimizer/clauses.h" +#include "optimizer/tlist.h" +#include "parser/parse_agg.h" +#include "parser/parse_coerce.h" +#include "utils/acl.h" +#include "utils/builtins.h" +#include "utils/lsyscache.h" +#include "utils/memutils.h" +#include "utils/syscache.h" +#include "utils/tuplesort.h" +#include "utils/datum.h" +#include "vecexecutor/vechashtable.h" + +// hash strategy +#define MEMORY_HASHAGG 0 +#define DIST_HASHAGG 1 + +#define HASHAGG_PREPARE 0 +#define HASHAGG_FETCH 1 + +#define HASH_MIN_FILENUMBER 48 +#define HASH_MAX_FILENUMBER 512 + +typedef struct AggWriteFileControl { + bool spillToDisk; /*whether data write to temp file*/ + bool finishwrite; + int strategy; + int runState; + int64 useMem; /* useful memory, in bytes */ + int64 totalMem; /*total memory, in bytes*/ + int64 inmemoryRownum; + hashSource* m_hashAggSource; + hashFileSource* filesource; + int filenum; + int curfile; + int64 maxMem; /* mem spread memory, in bytes */ + int spreadNum; /* dynamic spread time */ +} AggWriteFileControl; + +/* + * AggStatePerAggData - per-aggregate working state for the Agg scan + */ +typedef struct AggStatePerAggData { + /* + * These values are set up during ExecInitAgg() and do not change + * thereafter: + */ + + /* Links to Aggref expr and state nodes this working state is for */ + AggrefExprState* aggrefstate; + Aggref* aggref; + + /* number of input arguments for aggregate function proper */ + int numArguments; + + /* number of inputs including ORDER BY expressions */ + int numInputs; + + bool is_avg; + + /* + * Number of aggregated input columns to pass to the transfn. This + * includes the ORDER BY columns for ordered-set aggs, but not for plain + * aggs. (This doesn't count the transition state value!) + */ + int numTransInputs; + + /* Oids of transfer functions */ + Oid transfn_oid; + Oid finalfn_oid; /* may be InvalidOid */ +#ifdef PGXC + Oid collectfn_oid; /* may be InvalidOid */ +#endif /* PGXC */ + + /* + * fmgr lookup data for transfer functions --- only valid when + * corresponding oid is not InvalidOid. Note in particular that fn_strict + * flags are kept here. + */ + FmgrInfo transfn; + FmgrInfo finalfn; +#ifdef PGXC + FmgrInfo collectfn; +#endif /* PGXC */ + + /* Input collation derived for aggregate */ + Oid aggCollation; + + /* number of sorting columns */ + int numSortCols; + + /* number of sorting columns to consider in DISTINCT comparisons */ + /* (this is either zero or the same as numSortCols) */ + int numDistinctCols; + + /* deconstructed sorting information (arrays of length numSortCols) */ + AttrNumber* sortColIdx; + Oid* sortOperators; + Oid* sortCollations; + bool* sortNullsFirst; + + /* + * fmgr lookup data for input columns' equality operators --- only + * set/used when aggregate has DISTINCT flag. Note that these are in + * order of sort column index, not parameter index. + */ + FmgrInfo* equalfns; /* array of length numDistinctCols */ + + /* + * initial value from pg_aggregate entry + */ + Datum initValue; + bool initValueIsNull; +#ifdef PGXC + Datum initCollectValue; + bool initCollectValueIsNull; +#endif /* PGXC */ + + /* + * We need the len and byval info for the agg's input, result, and + * transition data types in order to know how to copy/delete values. + * + * Note that the info for the input type is used only when handling + * DISTINCT aggs with just one argument, so there is only one input type. + */ + int16 inputtypeLen, resulttypeLen, transtypeLen; + bool inputtypeByVal, resulttypeByVal, transtypeByVal; + + /* + * Stuff for evaluation of inputs. We used to just use ExecEvalExpr, but + * with the addition of ORDER BY we now need at least a slot for passing + * data to the sort object, which requires a tupledesc, so we might as + * well go whole hog and use ExecProject too. + */ + TupleDesc evaldesc; /* descriptor of input tuples */ + ProjectionInfo* evalproj; /* projection machinery */ + + /* + * Slots for holding the evaluated input arguments. These are set up + * during ExecInitAgg() and then used for each input row. + */ + TupleTableSlot* evalslot; /* current input tuple */ + TupleTableSlot* uniqslot; /* used for multi-column DISTINCT */ + + /* + * These values are working state that is initialized at the start of an + * input tuple group and updated for each input tuple. + * + * For a simple (non DISTINCT/ORDER BY) aggregate, we just feed the input + * values straight to the transition function. If it's DISTINCT or + * requires ORDER BY, we pass the input values into a Tuplesort object; + * then at completion of the input tuple group, we scan the sorted values, + * eliminate duplicates if needed, and run the transition function on the + * rest. + */ + + Tuplesortstate** sortstates; /* sort object, if DISTINCT or ORDER BY */ + Tuplesortstate* sortstate; /* sort object, if DISTINCT or ORDER BY */ + + /* + * This field is a pre-initialized FunctionCallInfo struct used for + * calling this aggregate's transfn. We save a few cycles per row by not + * re-initializing the unchanging fields; which isn't much, but it seems + * worth the extra space consumption. + */ + FunctionCallInfoData transfn_fcinfo; +} AggStatePerAggData; + +/* + * AggStatePerPhaseData - per-grouping-set-phase state + * + * Grouping sets are divided into "phases", where a single phase can be + * processed in one pass over the input. If there is more than one phase, then + * at the end of input from the current phase, state is reset and another pass + * taken over the data which has been re-sorted in the mean time. + * + * Accordingly, each phase specifies a list of grouping sets and group clause + * information, plus each phase after the first also has a sort order. + */ +typedef struct AggStatePerPhaseData { + int numsets; /* number of grouping sets (or 0) */ + int* gset_lengths; /* lengths of grouping sets */ + Bitmapset** grouped_cols; /* column groupings for rollup */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + Agg* aggnode; /* Agg node for phase data */ + Sort* sortnode; /* Sort node for input ordering for phase */ +} AggStatePerPhaseData; + +/* + * AggStatePerGroupData - per-aggregate-per-group working state + * + * These values are working state that is initialized at the start of + * an input tuple group and updated for each input tuple. + * + * In AGG_PLAIN and AGG_SORTED modes, we have a single array of these + * structs (pointed to by aggstate->pergroup); we re-use the array for + * each input group, if it's AGG_SORTED mode. In AGG_HASHED mode, the + * hash table contains an array of these structs for each tuple group. + * + * Logically, the sortstate field belongs in this struct, but we do not + * keep it here for space reasons: we don't support DISTINCT aggregates + * in AGG_HASHED mode, so there's no reason to use up a pointer field + * in every entry of the hashtable. + */ +typedef struct AggStatePerGroupData { + Datum transValue; /* current transition value */ + Datum collectValue; /* current collection value */ + bool transValueIsNull; + + bool noTransValue; /* true if transValue not set yet */ + bool collectValueIsNull; + bool noCollectValue; /* true if the collectValue not set yet */ + + /* + * Note: noTransValue initially has the same value as transValueIsNull, + * and if true both are cleared to false at the same time. They are not + * the same though: if transfn later returns a NULL, we want to keep that + * NULL and not auto-replace it with a later input value. Only the first + * non-NULL input will be auto-substituted. + */ +#ifdef PGXC + /*collectValue, collectValueIsNull and noCollectValue are added by PGXC*/ + /* + * We should be able to reuse the fields above, rather than having + * separate fields here, that can be done once we get rid of different + * collection and transition result types in pg_aggregate.h. Collection at + * Coordinator is equivalent to the transition at non-XC PG. + */ +#endif /* PGXC */ +} AggStatePerGroupData; + +/* + * To implement hashed aggregation, we need a hashtable that stores a + * representative tuple and an array of AggStatePerGroup structs for each + * distinct set of GROUP BY column values. We compute the hash key from + * the GROUP BY columns. + */ +typedef struct AggHashEntryData* AggHashEntry; + +typedef struct AggHashEntryData { + TupleHashEntryData shared; /* common header for hash table entries */ + /* per-aggregate transition status array - must be last! */ + AggStatePerGroupData pergroup[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} AggHashEntryData; /* VARIABLE LENGTH STRUCT */ + +extern AggState* ExecInitAgg(Agg* node, EState* estate, int eflags); +extern TupleTableSlot* ExecAgg(AggState* node); +extern void ExecEndAgg(AggState* node); +extern void ExecReScanAgg(AggState* node); +extern Datum GetAggInitVal(Datum textInitVal, Oid transtype); +extern Size hash_agg_entry_size(int numAggs); + +extern Datum aggregate_dummy(PG_FUNCTION_ARGS); +extern long ExecGetMemCostAgg(Agg*); +extern void initialize_phase(AggState* aggstate, int newphase); +extern List* find_hash_columns(AggState* aggstate); +extern uint32 ComputeHashValue(TupleHashTable hashtbl); +extern int getPower2Num(int num); +extern void agg_spill_to_disk(AggWriteFileControl* TempFileControl, TupleHashTable hashtable, TupleTableSlot* hashslot, + int numGroups, bool isAgg, int planId, int dop, Instrumentation* intrument = NULL); +extern void ExecEarlyFreeAggregation(AggState* node); +extern void ExecReSetAgg(AggState* node); + +#endif /* NODEAGG_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeAppend.h postgresql-hll-2.14/include/include/executor/nodeAppend.h --- postgresql-hll-2.14_old/include/include/executor/nodeAppend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeAppend.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeAppend.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeAppend.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEAPPEND_H +#define NODEAPPEND_H + +#include "nodes/execnodes.h" + +extern AppendState* ExecInitAppend(Append* node, EState* estate, int eflags); +extern TupleTableSlot* ExecAppend(AppendState* node); +extern void ExecEndAppend(AppendState* node); +extern void ExecReScanAppend(AppendState* node); +extern bool exec_append_initialize_next(AppendState* appendstate); + +#endif /* NODEAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeBitmapAnd.h postgresql-hll-2.14/include/include/executor/nodeBitmapAnd.h --- postgresql-hll-2.14_old/include/include/executor/nodeBitmapAnd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeBitmapAnd.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapAnd.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapAnd.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPAND_H +#define NODEBITMAPAND_H + +#include "nodes/execnodes.h" + +extern BitmapAndState* ExecInitBitmapAnd(BitmapAnd* node, EState* estate, int eflags); +extern Node* MultiExecBitmapAnd(BitmapAndState* node); +extern void ExecEndBitmapAnd(BitmapAndState* node); +extern void ExecReScanBitmapAnd(BitmapAndState* node); + +#endif /* NODEBITMAPAND_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeBitmapHeapscan.h postgresql-hll-2.14/include/include/executor/nodeBitmapHeapscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeBitmapHeapscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeBitmapHeapscan.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapHeapscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapHeapscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPHEAPSCAN_H +#define NODEBITMAPHEAPSCAN_H + +#include "nodes/execnodes.h" + +extern BitmapHeapScanState* ExecInitBitmapHeapScan(BitmapHeapScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecBitmapHeapScan(BitmapHeapScanState* node); +extern void ExecEndBitmapHeapScan(BitmapHeapScanState* node); +extern void ExecReScanBitmapHeapScan(BitmapHeapScanState* node); + +#endif /* NODEBITMAPHEAPSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeBitmapIndexscan.h postgresql-hll-2.14/include/include/executor/nodeBitmapIndexscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeBitmapIndexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeBitmapIndexscan.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapIndexscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapIndexscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPINDEXSCAN_H +#define NODEBITMAPINDEXSCAN_H + +#include "nodes/execnodes.h" + +extern BitmapIndexScanState* ExecInitBitmapIndexScan(BitmapIndexScan* node, EState* estate, int eflags); +extern Node* MultiExecBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecEndBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecReScanBitmapIndexScan(BitmapIndexScanState* node); +extern void ExecInitPartitionForBitmapIndexScan(BitmapIndexScanState* indexstate, EState* estate, Relation rel); + +#endif /* NODEBITMAPINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeBitmapOr.h postgresql-hll-2.14/include/include/executor/nodeBitmapOr.h --- postgresql-hll-2.14_old/include/include/executor/nodeBitmapOr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeBitmapOr.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeBitmapOr.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeBitmapOr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEBITMAPOR_H +#define NODEBITMAPOR_H + +#include "nodes/execnodes.h" + +extern BitmapOrState* ExecInitBitmapOr(BitmapOr* node, EState* estate, int eflags); +extern Node* MultiExecBitmapOr(BitmapOrState* node); +extern void ExecEndBitmapOr(BitmapOrState* node); +extern void ExecReScanBitmapOr(BitmapOrState* node); + +#endif /* NODEBITMAPOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeCtescan.h postgresql-hll-2.14/include/include/executor/nodeCtescan.h --- postgresql-hll-2.14_old/include/include/executor/nodeCtescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeCtescan.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeCtescan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeCtescan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODECTESCAN_H +#define NODECTESCAN_H + +#include "nodes/execnodes.h" + +extern CteScanState* ExecInitCteScan(CteScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecCteScan(CteScanState* node); +extern void ExecEndCteScan(CteScanState* node); +extern void ExecReScanCteScan(CteScanState* node); + +#endif /* NODECTESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeExtensible.h postgresql-hll-2.14/include/include/executor/nodeExtensible.h --- postgresql-hll-2.14_old/include/include/executor/nodeExtensible.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeExtensible.h 2020-12-12 17:06:43.187347264 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeExtensible.h + * the structure of extensible plan node + * + * + * IDENTIFICATION + * src/include/executor/nodeExtensible.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODEEXTENSIBLE_H +#define NODEEXTENSIBLE_H + +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" +/* + * General executor code + */ +extern ExtensiblePlanState* ExecInitExtensiblePlan(ExtensiblePlan* eplan, EState* estate, int eflags); +extern TupleTableSlot* ExecExtensiblePlan(ExtensiblePlanState* node); +extern void ExecEndExtensiblePlan(ExtensiblePlanState* node); + +extern void ExecReScanExtensiblePlan(ExtensiblePlanState* node); +extern ExtensiblePlanMethods* GetExtensiblePlanMethods(const char* ExtensibleName, bool missing_ok); + +#ifdef ENABLE_MULTIPLE_NODES +extern void InitExtensiblePlanMethodsHashTable(); +#endif + +#endif /* NODEEXTENSIBLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeForeignscan.h postgresql-hll-2.14/include/include/executor/nodeForeignscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeForeignscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeForeignscan.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeForeignscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeForeignscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFOREIGNSCAN_H +#define NODEFOREIGNSCAN_H + +#include "nodes/execnodes.h" + +extern ForeignScanState* ExecInitForeignScan(ForeignScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecForeignScan(ForeignScanState* node); +extern void ExecEndForeignScan(ForeignScanState* node); +extern void ExecReScanForeignScan(ForeignScanState* node); + +#endif /* NODEFOREIGNSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeFunctionscan.h postgresql-hll-2.14/include/include/executor/nodeFunctionscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeFunctionscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeFunctionscan.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeFunctionscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeFunctionscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFUNCTIONSCAN_H +#define NODEFUNCTIONSCAN_H + +#include "nodes/execnodes.h" + +extern FunctionScanState* ExecInitFunctionScan(FunctionScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecFunctionScan(FunctionScanState* node); +extern void ExecEndFunctionScan(FunctionScanState* node); +extern void ExecReScanFunctionScan(FunctionScanState* node); + +#endif /* NODEFUNCTIONSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeGroup.h postgresql-hll-2.14/include/include/executor/nodeGroup.h --- postgresql-hll-2.14_old/include/include/executor/nodeGroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeGroup.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeGroup.h + * prototypes for nodeGroup.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeGroup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEGROUP_H +#define NODEGROUP_H + +#include "nodes/execnodes.h" + +extern GroupState* ExecInitGroup(Group* node, EState* estate, int eflags); +extern TupleTableSlot* ExecGroup(GroupState* node); +extern void ExecEndGroup(GroupState* node); +extern void ExecReScanGroup(GroupState* node); + +#endif /* NODEGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeHash.h postgresql-hll-2.14/include/include/executor/nodeHash.h --- postgresql-hll-2.14_old/include/include/executor/nodeHash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeHash.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * nodeHash.h + * prototypes for nodeHash.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeHash.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEHASH_H +#define NODEHASH_H + +#include "nodes/execnodes.h" +#include "nodes/relation.h" + +#define MIN_HASH_BUCKET_SIZE 32768 /* min bucketsize for hash join */ +#define BUCKET_OVERHEAD 8 + +extern HashState* ExecInitHash(Hash* node, EState* estate, int eflags); +extern TupleTableSlot* ExecHash(void); +extern Node* MultiExecHash(HashState* node); +extern void ExecEndHash(HashState* node); +extern void ExecReScanHash(HashState* node); + +extern HashJoinTable ExecHashTableCreate(Hash* node, List* hashOperators, bool keepNulls); +extern void ExecHashTableDestroy(HashJoinTable hashtable); +extern void ExecHashTableInsert(HashJoinTable hashtable, TupleTableSlot* slot, uint32 hashvalue, int planid, int dop, + Instrumentation* instrument = NULL); +extern bool ExecHashGetHashValue(HashJoinTable hashtable, ExprContext* econtext, List* hashkeys, bool outer_tuple, + bool keep_nulls, uint32* hashvalue); +extern void ExecHashGetBucketAndBatch(HashJoinTable hashtable, uint32 hashvalue, int* bucketno, int* batchno); +extern bool ExecScanHashBucket(HashJoinState* hjstate, ExprContext* econtext); +extern void ExecPrepHashTableForUnmatched(HashJoinState* hjstate); +extern bool ExecScanHashTableForUnmatched(HashJoinState* hjstate, ExprContext* econtext); +extern void ExecHashTableReset(HashJoinTable hashtable); +extern void ExecHashTableResetMatchFlags(HashJoinTable hashtable); +extern void ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew, int* numbuckets, int* numbatches, + int* num_skew_mcvs, int4 localWorkMem, bool vectorized = false, OpMemInfo* memInfo = NULL); +extern double ExecChooseHashTableMaxTuples(int tupwidth, bool useskew, bool vectorized, double hash_table_bytes); +extern int ExecHashGetSkewBucket(HashJoinTable hashtable, uint32 hashvalue); +extern void ExecHashTableStats(HashJoinTable hashtable, int planid); +extern int ExecSonicHashGetAtomTypeSize(Oid typeOid, int typeMod, bool isHashKey); +extern int64 ExecSonicHashGetAtomArrayBytes( + double ntuples, int m_arrSize, int m_atomSize, int64 atomTypeSize, bool hasNullFlag); +extern void ExecChooseSonicHashTableSize(Path* inner_path, List* hashclauses, int* inner_width, + bool isComplicateHashKey, int* numbuckets, int* numbatches, int4 localWorkMem, OpMemInfo* memInfo, int dop); +extern uint8 EstimateBucketTypeSize(int nbuckets); + +#endif /* NODEHASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeHashjoin.h postgresql-hll-2.14/include/include/executor/nodeHashjoin.h --- postgresql-hll-2.14_old/include/include/executor/nodeHashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeHashjoin.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * nodeHashjoin.h + * prototypes for nodeHashjoin.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeHashjoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEHASHJOIN_H +#define NODEHASHJOIN_H + +#include "nodes/execnodes.h" +#include "storage/buffile.h" +#include "optimizer/planmem_walker.h" + +extern HashJoinState* ExecInitHashJoin(HashJoin* node, EState* estate, int eflags); +extern TupleTableSlot* ExecHashJoin(HashJoinState* node); +extern void ExecEndHashJoin(HashJoinState* node); +extern void ExecReScanHashJoin(HashJoinState* node); +extern void ExecHashJoinSaveTuple(MinimalTuple tuple, uint32 hashvalue, BufFile** fileptr); +extern void ExecEarlyFreeHashJoin(HashJoinState* node); +extern void ExecReSetHashJoin(HashJoinState* node); +extern bool FindParam(Node* node_plan, void* context); +extern bool CheckParamWalker(PlanState* plan_stat); + +#endif /* NODEHASHJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeIndexonlyscan.h postgresql-hll-2.14/include/include/executor/nodeIndexonlyscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeIndexonlyscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeIndexonlyscan.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeIndexonlyscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeIndexonlyscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEINDEXONLYSCAN_H +#define NODEINDEXONLYSCAN_H + +#include "nodes/execnodes.h" + +extern IndexOnlyScanState* ExecInitIndexOnlyScan(IndexOnlyScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecIndexOnlyScan(IndexOnlyScanState* node); +extern void ExecEndIndexOnlyScan(IndexOnlyScanState* node); +extern void ExecIndexOnlyMarkPos(IndexOnlyScanState* node); +extern void ExecIndexOnlyRestrPos(IndexOnlyScanState* node); +extern void ExecReScanIndexOnlyScan(IndexOnlyScanState* node); +extern void StoreIndexTuple(TupleTableSlot* slot, IndexTuple itup, TupleDesc itupdesc); +#endif /* NODEINDEXONLYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeIndexscan.h postgresql-hll-2.14/include/include/executor/nodeIndexscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeIndexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeIndexscan.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * nodeIndexscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeIndexscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEINDEXSCAN_H +#define NODEINDEXSCAN_H + +#include "nodes/execnodes.h" + +extern IndexScanState* ExecInitIndexScan(IndexScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecIndexScan(IndexScanState* node); +extern void ExecEndIndexScan(IndexScanState* node); +extern void ExecIndexMarkPos(IndexScanState* node); +extern void ExecIndexRestrPos(IndexScanState* node); +extern void ExecReScanIndexScan(IndexScanState* node); + +/* + * These routines are exported to share code with nodeIndexonlyscan.c and + * nodeBitmapIndexscan.c + */ +extern void ExecIndexBuildScanKeys(PlanState* planstate, Relation index, List* quals, bool isorderby, ScanKey* scanKeys, + int* numScanKeys, IndexRuntimeKeyInfo** runtimeKeys, int* numRuntimeKeys, IndexArrayKeyInfo** arrayKeys, + int* numArrayKeys); +extern void ExecIndexEvalRuntimeKeys(ExprContext* econtext, IndexRuntimeKeyInfo* runtimeKeys, int numRuntimeKeys); +extern bool ExecIndexEvalArrayKeys(ExprContext* econtext, IndexArrayKeyInfo* arrayKeys, int numArrayKeys); +extern bool ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo* arrayKeys, int numArrayKeys); +extern void ExecInitPartitionForIndexScan(IndexScanState* indexstate, EState* estate); +extern void ExecInitPartitionForIndexOnlyScan(IndexOnlyScanState* indexstate, EState* estate); + +#endif /* NODEINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeLimit.h postgresql-hll-2.14/include/include/executor/nodeLimit.h --- postgresql-hll-2.14_old/include/include/executor/nodeLimit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeLimit.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * nodeLimit.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeLimit.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODELIMIT_H +#define NODELIMIT_H + +#include "nodes/execnodes.h" + +extern LimitState* ExecInitLimit(Limit* node, EState* estate, int eflags); +extern TupleTableSlot* ExecLimit(LimitState* node); +extern void ExecEndLimit(LimitState* node); +extern void ExecReScanLimit(LimitState* node); +extern void recompute_limits(LimitState* node); + +#endif /* NODELIMIT_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeLockRows.h postgresql-hll-2.14/include/include/executor/nodeLockRows.h --- postgresql-hll-2.14_old/include/include/executor/nodeLockRows.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeLockRows.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeLockRows.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeLockRows.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODELOCKROWS_H +#define NODELOCKROWS_H + +#include "nodes/execnodes.h" + +extern LockRowsState* ExecInitLockRows(LockRows* node, EState* estate, int eflags); +extern TupleTableSlot* ExecLockRows(LockRowsState* node); +extern void ExecEndLockRows(LockRowsState* node); +extern void ExecReScanLockRows(LockRowsState* node); + +#endif /* NODELOCKROWS_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeMaterial.h postgresql-hll-2.14/include/include/executor/nodeMaterial.h --- postgresql-hll-2.14_old/include/include/executor/nodeMaterial.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeMaterial.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * nodeMaterial.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMaterial.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMATERIAL_H +#define NODEMATERIAL_H + +#include "nodes/execnodes.h" + +extern MaterialState* ExecInitMaterial(Material* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMaterial(MaterialState* node); +extern void ExecEndMaterial(MaterialState* node); +extern void ExecMaterialMarkPos(MaterialState* node); +extern void ExecMaterialRestrPos(MaterialState* node); +extern void ExecReScanMaterial(MaterialState* node); +extern void ExecEarlyFreeMaterial(MaterialState* node); +extern void ExecReSetMaterial(MaterialState* node); + +#endif /* NODEMATERIAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeMergeAppend.h postgresql-hll-2.14/include/include/executor/nodeMergeAppend.h --- postgresql-hll-2.14_old/include/include/executor/nodeMergeAppend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeMergeAppend.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeMergeAppend.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMergeAppend.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMERGEAPPEND_H +#define NODEMERGEAPPEND_H + +#include "nodes/execnodes.h" + +extern MergeAppendState* ExecInitMergeAppend(MergeAppend* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMergeAppend(MergeAppendState* node); +extern void ExecEndMergeAppend(MergeAppendState* node); +extern void ExecReScanMergeAppend(MergeAppendState* node); + +#endif /* NODEMERGEAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeMergejoin.h postgresql-hll-2.14/include/include/executor/nodeMergejoin.h --- postgresql-hll-2.14_old/include/include/executor/nodeMergejoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeMergejoin.h 2020-12-12 17:06:43.188347277 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * nodeMergejoin.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeMergejoin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMERGEJOIN_H +#define NODEMERGEJOIN_H + +#include "nodes/execnodes.h" + +extern MergeJoinState* ExecInitMergeJoin(MergeJoin* node, EState* estate, int eflags); +extern TupleTableSlot* ExecMergeJoin(MergeJoinState* node); +extern void ExecEndMergeJoin(MergeJoinState* node); +extern void ExecReScanMergeJoin(MergeJoinState* node); + +/* + * States of the ExecMergeJoin state machine + */ +#define EXEC_MJ_INITIALIZE_OUTER 1 +#define EXEC_MJ_INITIALIZE_INNER 2 +#define EXEC_MJ_JOINTUPLES 3 +#define EXEC_MJ_NEXTOUTER 4 +#define EXEC_MJ_TESTOUTER 5 +#define EXEC_MJ_NEXTINNER 6 +#define EXEC_MJ_SKIP_TEST 7 +#define EXEC_MJ_SKIPOUTER_ADVANCE 8 +#define EXEC_MJ_SKIPINNER_ADVANCE 9 +#define EXEC_MJ_ENDOUTER 10 +#define EXEC_MJ_ENDINNER 11 + +extern bool check_constant_qual(List* qual, bool* is_const_false); + +#endif /* NODEMERGEJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeModifyTable.h postgresql-hll-2.14/include/include/executor/nodeModifyTable.h --- postgresql-hll-2.14_old/include/include/executor/nodeModifyTable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeModifyTable.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * nodeModifyTable.h + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeModifyTable.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMODIFYTABLE_H +#define NODEMODIFYTABLE_H + +#include "nodes/execnodes.h" +#include "storage/lock.h" + +typedef TupleTableSlot* (*ExecInsertMtd)(ModifyTableState* state,TupleTableSlot*, + TupleTableSlot*, EState*, bool, int, List**); +typedef TupleTableSlot* (*ExecUpdateMtd)(ItemPointer, Oid, Oid, HeapTupleHeader, TupleTableSlot*, + TupleTableSlot*, EPQState*, ModifyTableState*, bool, bool); + +extern ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int eflags); +extern TupleTableSlot* ExecModifyTable(ModifyTableState* node); +extern void ExecEndModifyTable(ModifyTableState* node); +extern void ExecReScanModifyTable(ModifyTableState* node); +extern void RecordDeletedTuple(Oid relid, int2 bucketid, const ItemPointer tupleid, const Relation deldelta_rel); + +/* May move all resizing declaration to appropriate postion sometime. */ +extern bool RelationInClusterResizing(const Relation rel); +extern bool RelationInClusterResizingReadOnly(const Relation rel); +extern bool CheckRangeVarInRedistribution(const RangeVar* range_var); +extern bool RelationIsDeleteDeltaTable(char* delete_delta_name); +extern Relation GetAndOpenDeleteDeltaRel(const Relation rel, LOCKMODE lockmode, bool isMultiCatchup); +extern Relation GetAndOpenNewTableRel(const Relation rel, LOCKMODE lockmode); +extern bool redis_func_dnstable(Oid funcid); +extern List* eval_ctid_funcs(Relation rel, List* original_quals, RangeScanInRedis *rangeScanInRedis); +extern char* nodeTagToString(NodeTag type); +extern bool ClusterResizingInProgress(); +extern void RelationGetNewTableName(Relation rel, char* newtable_name); + +extern TupleTableSlot* ExecDelete(ItemPointer tupleid, Oid deletePartitionOid, int2 bucketid, HeapTupleHeader oldtuple, + TupleTableSlot* planSlot, EPQState* epqstate, ModifyTableState* node, bool canSetTag); + +extern TupleTableSlot* ExecUpdate(ItemPointer tupleid, Oid oldPartitionOid, int2 bucketid, HeapTupleHeader oldtuple, + TupleTableSlot* slot, TupleTableSlot* planSlot, EPQState* epqstate, ModifyTableState* node, bool canSetTag, + bool partKeyUpdate); + +template +extern TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, TupleTableSlot* planSlot, + EState* estate, bool canSetTag, int options, List** partitionList); +template +extern TupleTableSlot * +ExecHBucketInsertT(ModifyTableState* state, TupleTableSlot *slot, + TupleTableSlot *planSlot, + EState *estate, + bool canSetTag, + int options, + List** partition_list); + +extern void ExecCheckPlanOutput(Relation resultRel, List* targetList); + +#endif /* NODEMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeNestloop.h postgresql-hll-2.14/include/include/executor/nodeNestloop.h --- postgresql-hll-2.14_old/include/include/executor/nodeNestloop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeNestloop.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeNestloop.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeNestloop.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODENESTLOOP_H +#define NODENESTLOOP_H + +#include "nodes/execnodes.h" + +extern NestLoopState* ExecInitNestLoop(NestLoop* node, EState* estate, int eflags); +extern TupleTableSlot* ExecNestLoop(NestLoopState* node); +extern void ExecEndNestLoop(NestLoopState* node); +extern void ExecReScanNestLoop(NestLoopState* node); + +#endif /* NODENESTLOOP_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodePartIterator.h postgresql-hll-2.14/include/include/executor/nodePartIterator.h --- postgresql-hll-2.14_old/include/include/executor/nodePartIterator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodePartIterator.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodePartIterator.h + * + * + * + * IDENTIFICATION + * src/include/executor/nodePartIterator.h + * + * NOTE + * Partition Iterator is a new execution operator for partition wise join. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODEPARTITERATOR_H +#define NODEPARTITERATOR_H + +#include "nodes/execnodes.h" + +extern PartIteratorState* ExecInitPartIterator(PartIterator* node, EState* estate, int eflags); +extern TupleTableSlot* ExecPartIterator(PartIteratorState* node); +extern void ExecEndPartIterator(PartIteratorState* node); +extern void ExecReScanPartIterator(PartIteratorState* node); + +#endif /* NODEPARTITERATOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeRecursiveunion.h postgresql-hll-2.14/include/include/executor/nodeRecursiveunion.h --- postgresql-hll-2.14_old/include/include/executor/nodeRecursiveunion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeRecursiveunion.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,259 @@ +/* ------------------------------------------------------------------------- + * + * nodeRecursiveunion.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeRecursiveunion.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODERECURSIVEUNION_H +#define NODERECURSIVEUNION_H + +#include "executor/execStream.h" +#include "nodes/execnodes.h" +#include "storage/fd.h" +#include "storage/vfd.h" +/* + * -------------------------------------------------------------------------------------- + * MPPDB Distributed RecursiveUnion Support (with-recursive) + * -------------------------------------------------------------------------------------- + */ + +extern THR_LOCAL char* producer_top_plannode_str; +extern THR_LOCAL bool is_syncup_producer; + +extern char* nodeTagToString(NodeTag type); + +/* Cluster-wide sync up each datanodes that none-recursive part has finished */ +#define WITH_RECURSIVE_SYNC_NONERQ 1 + +/* Cluster-wide sync up each datanodes that one iteration is done */ +#define WITH_RECURSIVE_SYNC_RQSTEP 2 + +/* Cluster-wide sync up each datanodes that all iteration steps are done */ +#define WITH_RECURSIVE_SYNC_DONE 3 + +/* + * Recursive Union message types + * - 'R' indicates datanode STEP finsih the iteration (W->C) + * - 'F' indicates cluster STEP finsih the iteration (C->W) + */ +#define RUSYNC_MSGTYPE_NODE_FINISH 'R' + +/* + * Base class for syncup controller + */ +typedef struct SyncController { + /* type of controller*/ + NodeTag controller_type; + + /* controller plan node id */ + int controller_plannodeid; + + /* control-node xc_node_id */ + int controlnode_xcnodeid; + + /* controler plan state desc */ + PlanState* controller_planstate; + + /* indicate the controller side is showdown */ + bool executor_stop; +} SyncController; + +/* + * SubClass inheriented from SyncController for Stream Operator + */ +typedef struct StreamController { + SyncController controller; + int iteration; + bool iteration_finished; + int total_tuples; + bool stream_finish; +} StreamController; + +typedef struct RecursiveVfd { + /* Reference to Consumer thread's VfdCache' address */ + Vfd** recursive_VfdCache; + + /* Reference to Consumer thread's SizeVfdCache */ + Size* recursive_SizeVfdCache; +} RecursiveVfd; + +/* + * SubClass inheriented from SyncController for RecursiveUnion Operator + */ +typedef struct RecursiveUnionController { + /* base controller information */ + SyncController controller; + + /* will move to base */ + int total_execution_datanodes; + List* streamlist; + StreamState* syncup_streamnode; + int stepno; + int ru_coordnodeid; + + /* RecursiveUnion specific control information */ + int recursiveunion_stepno; + + /* none-recursive desc */ + int* none_recursive_tuples; + bool none_recursive_finished; + int total_step1_rows; + + /* recursive desc */ + int* recursive_tuples; + bool recursive_finished; + int iteration; + int total_step2_substep_rows; + int total_step2_rows; + + /* overall desc */ + int total_step_rows; + bool recursive_union_finish; + + RecursiveVfd recursive_vfd; +} RecursiveUnionController; + +/* + * *********************************************************************************** + * Synchronization functions for each controller + * *********************************************************************************** + */ + +/* For RecursoveUnion's Producer/Consumer functions */ +extern void ExecSyncRecursiveUnionConsumer(RecursiveUnionController* controller, int stepno); +extern void ExecSyncRecursiveUnionProducer(RecursiveUnionController* controller, int producer_plannodeid, int step, + int tuple_count, bool* need_rescan, int target_iteration); + +/* + * For Stream's Producer/Consumer functions + */ +extern void ExecSyncStreamProducer(StreamController* controller, bool* need_rescan, int target_iteration); +extern void ExecSyncStreamConsumer(StreamController* controller); + +extern bool ExecutePlanSyncProducer( + PlanState* planstate, int step, bool* recursive_early_stop, long* current_tuple_count); + +/* + * SyncController-Creator for each supported operator + * SyncController-Destructor for each supported oeprator + */ +extern void ExecSyncControllerCreate(Plan* node); +extern void ExecSyncControllerDelete(SyncController* controller); + +/* + * Producer thread reset function for each operator + */ +extern void ExecSetStreamFinish(PlanState* state); + +/* + * working-horse marocs for sync-up relevant operations + */ +#define GET_PLAN_NODEID(x) ((Plan*)x)->plan_node_id +#define GET_RECURSIVE_UNION_PLAN_NODEID(x) ((Plan*)x)->recursive_union_plan_nodeid +#define GET_CONTROL_PLAN_NODEID(x) ((Plan*)x)->control_plan_nodeid + +/* + * Plan Step sync-up check functions + * [1]. NeedSyncUpRecursiveUnionStep() invoked in ExecRecursiveUnion to set up sync-up point + * [2]. NeedSetupSyncUpController() Invoked in init-node to set up controller + * [3]. NeedSyncUpProducerStep() invoked in producer side to do sync-up point + */ +extern bool NeedSyncUpRecursiveUnionStep(Plan* plan); +extern bool NeedSetupSyncUpController(Plan* plan); +extern bool NeedSyncUpProducerStep(Plan* top_plan); + +typedef struct TryStreamRecursivePlanContext { + bool stream_plan; +} TryStreamRecursivePlanContext; + +extern void mark_stream_recursiveunion_plan( + RecursiveUnion* runode, Plan* node, bool recursive_branch, List* subplans, List** initplans); + +/* + * Helper functions to identify the thread or consumer node is the sync-up thread + */ +extern bool IsSyncUpProducerThread(); +extern bool IsSyncUpConsumerStreamNode(const Stream* node); + +/* + * Iteration context structure to support distributed RecursiveUnion plan generation + */ +typedef struct RecursiveRefContext { + /* field to store recursive union plan node */ + const RecursiveUnion* ru_plan; + + /* + * store the current control plan node if current runing-plan need controlled when + * iterating the plan tree. + */ + Plan* control_plan; + + /* depth of current stream operation depths */ + int nested_stream_depth; + + /* indicate if we need set control_plan_id for current iterating plan node */ + bool set_control_plan_nodeid; + + /* flag to indicate whether the sync up producer is specified (for multi-stream case) */ + bool is_syncup_producer_specified; + + /* join type of most close upper layer join type */ + NodeTag join_type; + + List* initplans; /* Plans for initplan nodes */ + List* subplans; /* Plans for SubPlan nodes */ +} RecursiveRefContext; + +/* Function to generate control plannode for recursvie-union's underlying plantree */ +extern void set_recursive_cteplan_ref(Plan* node, RecursiveRefContext* context); + +extern RecursiveUnionState* ExecInitRecursiveUnion(RecursiveUnion* node, EState* estate, int eflags); +extern TupleTableSlot* ExecRecursiveUnion(RecursiveUnionState* node); +extern void ExecEndRecursiveUnion(RecursiveUnionState* node); +extern void ExecReScanRecursiveUnion(RecursiveUnionState* node); +extern bool IsFirstLevelStreamStateNode(StreamState* node); +extern void ExecReScanRecursivePlanTree(PlanState* ps); + +/* + * @Function: recursive_union_sleep() **INLINE** + * + * @Brief: wrapper sleep() function for recursive union use, compare with regular + * pg_usleep(), we check interrupt as well + * + * @Input usec: time-unit(micro) that going to sleep + * + * @Return: void + */ +static inline void recursive_union_sleep(long usec) +{ + /* setup interrupt check */ + CHECK_FOR_INTERRUPTS(); + + /* wait for given length */ + pg_usleep(usec); + + return; +} + +/* default check interval for iteration finish */ +#define CHECK_INTERVAL 500L + +/* check interval macro */ +#define WITH_RECURSIVE_SYNCPOINT_WAIT_INTERVAL \ + { \ + recursive_union_sleep(CHECK_INTERVAL); \ + \ + /* Check if current thread is required to exit from top consumer*/ \ + if (u_sess->exec_cxt.executor_stop_flag) { \ + break; \ + } \ + } + +#endif /* NODERECURSIVEUNION_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeResult.h postgresql-hll-2.14/include/include/executor/nodeResult.h --- postgresql-hll-2.14_old/include/include/executor/nodeResult.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeResult.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeResult.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeResult.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODERESULT_H +#define NODERESULT_H + +#include "nodes/execnodes.h" + +extern ResultState* ExecInitResult(BaseResult* node, EState* estate, int eflags); +extern TupleTableSlot* ExecResult(ResultState* node); +extern void ExecEndResult(ResultState* node); +extern void ExecResultMarkPos(ResultState* node); +extern void ExecResultRestrPos(ResultState* node); +extern void ExecReScanResult(ResultState* node); + +#endif /* NODERESULT_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSamplescan.h postgresql-hll-2.14/include/include/executor/nodeSamplescan.h --- postgresql-hll-2.14_old/include/include/executor/nodeSamplescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSamplescan.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,112 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeSamplescan.h + * Table Sample Scan header file, include class and class member declaration. + * + * + * IDENTIFICATION + * src/include/executor/nodeSamplescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODESAMPLESCAN_H +#define NODESAMPLESCAN_H + +#include "access/relscan.h" +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +#define NEWBLOCK 0 /* Identify we have got a new block. */ +#define NONEWBLOCK 1 /* Identify we are under scanning tuple in old block. */ + +#define MIN_PERCENT_ARG 0 /* Minimum value of percent. */ +#define MAX_PERCENT_ARG 100 /* Maxmum value of percent. */ + +/* The flag identify the tuple or block is valid or not for sample scan. */ +typedef enum { VALIDDATA, NEXTDATA, INVALIDBLOCKNO, INVALIDOFFSET } ScanValid; + +/* The flag identify the sample scan state. */ +typedef enum { GETMAXBLOCK, GETBLOCKNO, GETMAXOFFSET, GETOFFSET, GETDATA } SampleScanFlag; + +/* Table sample scan base class.*/ +class BaseTableSample : public BaseObject { +public: + BaseTableSample(void* scanstate); + virtual ~BaseTableSample(); + void resetSampleScan(); + +public: + ScanState* sampleScanState; + CStoreScanState* vecsampleScanState; + int runState; + int scanTupState; + uint32 seed; + double* percent; + BlockNumber totalBlockNum; + /* current block to consider sampling. To system table, next blosk need be chosen.*/ + BlockNumber currentBlock; + /* last tuple returned from current block.*/ + OffsetNumber currentOffset; + /* how many tuples in current page. */ + OffsetNumber curBlockMaxoffset; + bool finished; + void (BaseTableSample::*nextSampleBlock_function)(); + void (BaseTableSample::*nextSampleTuple_function)(); + +private: + void getSeed(); + void getPercent(); + void system_nextsampleblock(); + void system_nextsampletuple(); + void bernoulli_nextsampleblock(); + void bernoulli_nextsampletuple(); +}; + +/* Row table sample scan.*/ +class RowTableSample : public BaseTableSample { +public: + RowTableSample(ScanState* scanstate); + virtual ~RowTableSample(); + ScanValid scanTup(); + HeapTuple scanSample(); + void getMaxOffset(); +}; + +/* Column table sample scan.*/ +class ColumnTableSample : public BaseTableSample { +private: + uint16* offsetIds; + uint32 currentCuId; + int batchRowCount; + VectorBatch* tids; + +public: + ColumnTableSample(CStoreScanState* scanstate); + virtual ~ColumnTableSample(); + void resetVecSampleScan(); + void getBatchBySamples(VectorBatch* vbout); + ScanValid scanBatch(VectorBatch* batch); + void scanVecSample(VectorBatch* batch); + void getMaxOffset(); +}; + +extern TableScanDesc InitSampleScanDesc(ScanState *scanstate, Relation currentRelation); +extern TupleTableSlot* SeqSampleNext(SeqScanState *node); +extern TupleTableSlot* HbktSeqSampleNext(SeqScanState *node); + +#endif /* NODESAMPLESCAN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSeqscan.h postgresql-hll-2.14/include/include/executor/nodeSeqscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeSeqscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSeqscan.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * nodeSeqscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSeqscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESEQSCAN_H +#define NODESEQSCAN_H + +#include "nodes/execnodes.h" + +extern SeqScanState* ExecInitSeqScan(SeqScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSeqScan(SeqScanState* node); +extern void ExecEndSeqScan(SeqScanState* node); +extern void ExecSeqMarkPos(SeqScanState* node); +extern void ExecSeqRestrPos(SeqScanState* node); +extern void ExecReScanSeqScan(SeqScanState* node); +extern void InitScanRelation(SeqScanState* node, EState* estate); + +#endif /* NODESEQSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSetOp.h postgresql-hll-2.14/include/include/executor/nodeSetOp.h --- postgresql-hll-2.14_old/include/include/executor/nodeSetOp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSetOp.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * nodeSetOp.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSetOp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESETOP_H +#define NODESETOP_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vechashtable.h" +#include "executor/nodeAgg.h" + +// hash strategy +#define MEMORY_HASHSETOP 0 +#define DIST_HASHSETOP 1 + +#define HASHSETOP_PREPARE 0 +#define HASHSETOP_FETCH 1 + +typedef struct SetopWriteFileControl : public AggWriteFileControl { +} SetopWriteFileControl; + +extern SetOpState* ExecInitSetOp(SetOp* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSetOp(SetOpState* node); +extern void ExecEndSetOp(SetOpState* node); +extern void ExecReScanSetOp(SetOpState* node); +extern void ExecEarlyFreeHashedSetop(SetOpState* node); +extern void ExecReSetSetOp(SetOpState* node); + +#endif /* NODESETOP_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSort.h postgresql-hll-2.14/include/include/executor/nodeSort.h --- postgresql-hll-2.14_old/include/include/executor/nodeSort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSort.h 2020-12-12 17:06:43.189347290 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * nodeSort.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSort.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESORT_H +#define NODESORT_H + +#include "nodes/execnodes.h" + +extern SortState* ExecInitSort(Sort* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSort(SortState* node); +extern void ExecEndSort(SortState* node); +extern void ExecSortMarkPos(SortState* node); +extern void ExecSortRestrPos(SortState* node); +extern void ExecReScanSort(SortState* node); +extern long ExecGetMemCostSort(Sort* node); +extern void ExecEarlyFreeSort(SortState* node); +extern void ExecReSetSort(SortState* node); + +#endif /* NODESORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeStub.h postgresql-hll-2.14/include/include/executor/nodeStub.h --- postgresql-hll-2.14_old/include/include/executor/nodeStub.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeStub.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodeStub.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/executor/nodeStub.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef NODESTUB_H +#define NODESTUB_H + +#include "nodes/execnodes.h" + +/* nodegroup */ +extern PlanState *ExecInitNodeStubNorm(Plan *node, EState *estate, int eflags); +extern TupleTableSlot *ExecProcNodeStub(PlanState *node); +extern void ExecEndNodeStub(PlanState *node); + +#endif /* NODESTUB_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSubplan.h postgresql-hll-2.14/include/include/executor/nodeSubplan.h --- postgresql-hll-2.14_old/include/include/executor/nodeSubplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSubplan.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,32 @@ +/* ------------------------------------------------------------------------- + * + * nodeSubplan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSubplan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESUBPLAN_H +#define NODESUBPLAN_H + +#include "nodes/execnodes.h" + +extern SubPlanState* ExecInitSubPlan(SubPlan* subplan, PlanState* parent); + +extern AlternativeSubPlanState* ExecInitAlternativeSubPlan(AlternativeSubPlan* asplan, PlanState* parent); + +extern void ExecReScanSetParamPlan(SubPlanState* node, PlanState* parent); + +extern void ExecSetParamPlan(SubPlanState* node, ExprContext* econtext); +extern void buildSubPlanHash(SubPlanState* node, ExprContext* econtext); +extern bool slotAllNulls(TupleTableSlot* slot); +extern bool slotNoNulls(TupleTableSlot* slot); + +extern bool findPartialMatch(TupleHashTable hashtable, TupleTableSlot* slot, FmgrInfo* eqfunctions); + +#endif /* NODESUBPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeSubqueryscan.h postgresql-hll-2.14/include/include/executor/nodeSubqueryscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeSubqueryscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeSubqueryscan.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeSubqueryscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeSubqueryscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODESUBQUERYSCAN_H +#define NODESUBQUERYSCAN_H + +#include "nodes/execnodes.h" + +extern SubqueryScanState* ExecInitSubqueryScan(SubqueryScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecSubqueryScan(SubqueryScanState* node); +extern void ExecEndSubqueryScan(SubqueryScanState* node); +extern void ExecReScanSubqueryScan(SubqueryScanState* node); + +#endif /* NODESUBQUERYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeTidscan.h postgresql-hll-2.14/include/include/executor/nodeTidscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeTidscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeTidscan.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeTidscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeTidscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODETIDSCAN_H +#define NODETIDSCAN_H + +#include "nodes/execnodes.h" + +extern TidScanState* ExecInitTidScan(TidScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecTidScan(TidScanState* node); +extern void ExecEndTidScan(TidScanState* node); +extern void ExecTidMarkPos(TidScanState* node); +extern void ExecTidRestrPos(TidScanState* node); +extern void ExecReScanTidScan(TidScanState* node); + +#endif /* NODETIDSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeUnique.h postgresql-hll-2.14/include/include/executor/nodeUnique.h --- postgresql-hll-2.14_old/include/include/executor/nodeUnique.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeUnique.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeUnique.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeUnique.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEUNIQUE_H +#define NODEUNIQUE_H + +#include "nodes/execnodes.h" + +extern UniqueState* ExecInitUnique(Unique* node, EState* estate, int eflags); +extern TupleTableSlot* ExecUnique(UniqueState* node); +extern void ExecEndUnique(UniqueState* node); +extern void ExecReScanUnique(UniqueState* node); + +#endif /* NODEUNIQUE_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeValuesscan.h postgresql-hll-2.14/include/include/executor/nodeValuesscan.h --- postgresql-hll-2.14_old/include/include/executor/nodeValuesscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeValuesscan.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * nodeValuesscan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeValuesscan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEVALUESSCAN_H +#define NODEVALUESSCAN_H + +#include "nodes/execnodes.h" + +extern ValuesScanState* ExecInitValuesScan(ValuesScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecValuesScan(ValuesScanState* node); +extern void ExecEndValuesScan(ValuesScanState* node); +extern void ExecValuesMarkPos(ValuesScanState* node); +extern void ExecValuesRestrPos(ValuesScanState* node); +extern void ExecReScanValuesScan(ValuesScanState* node); + +#endif /* NODEVALUESSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeWindowAgg.h postgresql-hll-2.14/include/include/executor/nodeWindowAgg.h --- postgresql-hll-2.14_old/include/include/executor/nodeWindowAgg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeWindowAgg.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeWindowAgg.h + * prototypes for nodeWindowAgg.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeWindowAgg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEWINDOWAGG_H +#define NODEWINDOWAGG_H + +#include "nodes/execnodes.h" + +extern WindowAggState* ExecInitWindowAgg(WindowAgg* node, EState* estate, int eflags); +extern TupleTableSlot* ExecWindowAgg(WindowAggState* node); +extern void ExecEndWindowAgg(WindowAggState* node); +extern void ExecReScanWindowAgg(WindowAggState* node); + +#endif /* NODEWINDOWAGG_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/nodeWorktablescan.h postgresql-hll-2.14/include/include/executor/nodeWorktablescan.h --- postgresql-hll-2.14_old/include/include/executor/nodeWorktablescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/nodeWorktablescan.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * nodeWorktablescan.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/nodeWorktablescan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEWORKTABLESCAN_H +#define NODEWORKTABLESCAN_H + +#include "nodes/execnodes.h" + +extern WorkTableScanState* ExecInitWorkTableScan(WorkTableScan* node, EState* estate, int eflags); +extern TupleTableSlot* ExecWorkTableScan(WorkTableScanState* node); +extern void ExecEndWorkTableScan(WorkTableScanState* node); +extern void ExecReScanWorkTableScan(WorkTableScanState* node); + +#endif /* NODEWORKTABLESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/spi.h postgresql-hll-2.14/include/include/executor/spi.h --- postgresql-hll-2.14_old/include/include/executor/spi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/spi.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------------- + * + * spi.h + * Server Programming Interface public declarations + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/spi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPI_H +#define SPI_H + +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "utils/resowner.h" +#include "utils/portal.h" + +typedef struct SPITupleTable { + MemoryContext tuptabcxt; /* memory context of result table */ + uint32 alloced; /* # of alloced vals */ + uint32 free; /* # of free vals */ + TupleDesc tupdesc; /* tuple descriptor */ + HeapTuple* vals; /* tuples */ +} SPITupleTable; + +/* Plans are opaque structs for standard users of SPI */ +typedef struct _SPI_plan* SPIPlanPtr; + +#define SPI_ERROR_CONNECT (-1) +#define SPI_ERROR_COPY (-2) +#define SPI_ERROR_OPUNKNOWN (-3) +#define SPI_ERROR_UNCONNECTED (-4) +#define SPI_ERROR_CURSOR (-5) /* not used anymore */ +#define SPI_ERROR_ARGUMENT (-6) +#define SPI_ERROR_PARAM (-7) +#define SPI_ERROR_TRANSACTION (-8) +#define SPI_ERROR_NOATTRIBUTE (-9) +#define SPI_ERROR_NOOUTFUNC (-10) +#define SPI_ERROR_TYPUNKNOWN (-11) + +#define SPI_OK_CONNECT 1 +#define SPI_OK_FINISH 2 +#define SPI_OK_FETCH 3 +#define SPI_OK_UTILITY 4 +#define SPI_OK_SELECT 5 +#define SPI_OK_SELINTO 6 +#define SPI_OK_INSERT 7 +#define SPI_OK_DELETE 8 +#define SPI_OK_UPDATE 9 +#define SPI_OK_CURSOR 10 +#define SPI_OK_INSERT_RETURNING 11 +#define SPI_OK_DELETE_RETURNING 12 +#define SPI_OK_UPDATE_RETURNING 13 +#define SPI_OK_REWRITTEN 14 +#define SPI_OK_MERGE 15 +#define SPI_OPT_NONATOMIC (1 << 0) + +extern THR_LOCAL PGDLLIMPORT uint32 SPI_processed; +extern THR_LOCAL PGDLLIMPORT SPITupleTable* SPI_tuptable; +extern THR_LOCAL PGDLLIMPORT int SPI_result; + +extern int SPI_connect(CommandDest dest = DestSPI, void (*spiCallbackfn)(void*) = NULL, void* clientData = NULL); +extern int SPI_connect_ext(CommandDest dest = DestSPI, void (*spiCallbackfn)(void *) = NULL, void *clientData = NULL, + int options = 0, Oid func_oid = InvalidOid); +extern int SPI_finish(void); +extern void SPI_push(void); +extern void SPI_pop(void); +extern bool SPI_push_conditional(void); +extern void SPI_pop_conditional(bool pushed); +extern void SPI_restore_connection(void); +extern int SPI_execute(const char* src, bool read_only, long tcount); +extern int SPI_execute_plan(SPIPlanPtr plan, Datum* Values, const char* Nulls, bool read_only, long tcount); +extern int SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params, bool read_only, long tcount); +extern int SPI_exec(const char* src, long tcount); +extern int SPI_execp(SPIPlanPtr plan, Datum* Values, const char* Nulls, long tcount); +extern int SPI_execute_snapshot(SPIPlanPtr plan, Datum* Values, const char* Nulls, Snapshot snapshot, + Snapshot crosscheck_snapshot, bool read_only, bool fire_triggers, long tcount); +extern int SPI_execute_with_args(const char* src, int nargs, Oid* argtypes, Datum* Values, const char* Nulls, + bool read_only, long tcount, Cursor_Data* cursor_data); +extern SPIPlanPtr SPI_prepare(const char* src, int nargs, Oid* argtypes); +extern SPIPlanPtr SPI_prepare_cursor(const char* src, int nargs, Oid* argtypes, int cursorOptions); +extern SPIPlanPtr SPI_prepare_params( + const char* src, ParserSetupHook parserSetup, void* parserSetupArg, int cursorOptions); +extern int SPI_keepplan(SPIPlanPtr plan); +extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan); +extern int SPI_freeplan(SPIPlanPtr plan); + +extern Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex); +extern int SPI_getargcount(SPIPlanPtr plan); +extern bool SPI_is_cursor_plan(SPIPlanPtr plan, ParamListInfo paramLI); +extern bool SPI_plan_is_valid(SPIPlanPtr plan); +extern const char* SPI_result_code_string(int code); + +extern List* SPI_plan_get_plan_sources(SPIPlanPtr plan); +extern CachedPlan* SPI_plan_get_cached_plan(SPIPlanPtr plan); + +extern HeapTuple SPI_copytuple(HeapTuple tuple); +extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc); +extern HeapTuple SPI_modifytuple( + Relation rel, HeapTuple tuple, int natts, int* attnum, Datum* Values, const char* Nulls); +extern int SPI_fnumber(TupleDesc tupdesc, const char* fname); +extern char* SPI_fname(TupleDesc tupdesc, int fnumber); +extern char* SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber); +extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool* isnull); +extern char* SPI_gettype(TupleDesc tupdesc, int fnumber); +extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber); +extern char* SPI_getrelname(Relation rel); +extern char* SPI_getnspname(Relation rel); +extern void* SPI_palloc(Size size); +extern void* SPI_repalloc(void* pointer, Size size); +extern void SPI_pfree(void* pointer); +extern void SPI_freetuple(HeapTuple pointer); +extern void SPI_freetuptable(SPITupleTable* tuptable); + +extern Portal SPI_cursor_open(const char* name, SPIPlanPtr plan, Datum* Values, const char* Nulls, bool read_only); +extern Portal SPI_cursor_open_with_args(const char* name, const char* src, int nargs, Oid* argtypes, Datum* Values, + const char* Nulls, bool read_only, int cursorOptions); +extern Portal SPI_cursor_open_with_paramlist(const char* name, SPIPlanPtr plan, ParamListInfo params, bool read_only); +extern Portal SPI_cursor_find(const char* name); +extern void SPI_cursor_fetch(Portal portal, bool forward, long count); +extern void SPI_cursor_move(Portal portal, bool forward, long count); +extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count); +extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count); +extern void SPI_cursor_close(Portal portal); +extern void SPI_start_transaction(void); +extern void SPI_stp_transaction_check(bool read_only); +extern void SPI_commit(); +extern void SPI_rollback(); +extern void SPI_save_current_stp_transaction_state(); +extern void SPI_restore_current_stp_transaction_state(); +extern TransactionId SPI_get_top_transaction_id(); + +extern void SPICleanup(void); +extern void AtEOXact_SPI(bool isCommit, bool STP_rollback, bool STP_commit); +extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid, bool STP_rollback, bool STP_commit); +extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid); +extern DestReceiver* createAnalyzeSPIDestReceiver(CommandDest dest); +/* SPI execution helpers */ +extern void spi_exec_with_callback(CommandDest dest, const char* src, bool read_only, long tcount, bool direct_call, + void (*callbackFn)(void*), void* clientData); + +extern void _SPI_error_callback(void *arg); + +#ifdef PGXC +extern int SPI_execute_direct(const char* src, char* nodename); +#endif +extern int _SPI_end_call(bool procmem); +extern void _SPI_hold_cursor(); +#endif /* SPI_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/spi_priv.h postgresql-hll-2.14/include/include/executor/spi_priv.h --- postgresql-hll-2.14_old/include/include/executor/spi_priv.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/spi_priv.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * spi_priv.h + * Server Programming Interface private declarations + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/spi_priv.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPI_PRIV_H +#define SPI_PRIV_H + +#include "executor/spi.h" + +#define _SPI_PLAN_MAGIC 569278163 +#define INVALID_SPI_KEY (uint32)(-1) +typedef struct _SPI_connection { + /* current results */ + uint64 processed; /* by Executor */ + Oid lastoid; + SPITupleTable* tuptable; + + MemoryContext procCxt; /* procedure context */ + MemoryContext execCxt; /* executor context */ + MemoryContext savedcxt; /* context of SPI_connect's caller */ + SubTransactionId connectSubid; /* ID of connecting subtransaction */ + CommandDest dest; /* identify which is the orientated caller of spi interface, analyze or normal */ + + /* transaction management support */ + bool atomic; /* atomic execution context, does not allow transactions */ + bool internal_xact; /* SPI-managed transaction boundary, skip cleanup */ + + void* clientData; /* argument to call back function */ + void (*spiCallback)(void*); /* callback for process received data. */ + Oid func_oid; /* corresponding oid */ + uint32 spi_hash_key; /* corresponding oid */ + uint32 visit_id; /* visit count */ + int plan_id; +} _SPI_connection; + +/* + * SPI plans have three states: saved, unsaved, or temporary. + * + * Ordinarily, the _SPI_plan struct itself as well as the argtypes array + * are in a dedicated memory context identified by plancxt (which can be + * really small). All the other subsidiary state is in plancache entries + * identified by plancache_list (note: the list cells themselves are in + * plancxt). + * + * In an unsaved plan, the plancxt as well as the plancache entries' contexts + * are children of the SPI procedure context, so they'll all disappear at + * function exit. plancache.c also knows that the plancache entries are + * "unsaved", so it doesn't link them into its global list; hence they do + * not respond to inval events. This is OK since we are presumably holding + * adequate locks to prevent other backends from messing with the tables. + * + * For a saved plan, the plancxt is made a child of t_thrd.mem_cxt.cache_mem_cxt + * since it should persist until explicitly destroyed. Likewise, the + * plancache entries will be under t_thrd.mem_cxt.cache_mem_cxt since we tell + * plancache.c to save them. We rely on plancache.c to keep the cache + * entries up-to-date as needed in the face of invalidation events. + * + * There are also "temporary" SPI plans, in which the _SPI_plan struct is + * not even palloc'd but just exists in some function's local variable. + * The plancache entries are unsaved and exist under the SPI executor context, + * while additional data such as argtypes and list cells is loose in the SPI + * executor context. Such plans can be identified by having plancxt == NULL. + * + * We can also have "one-shot" SPI plans (which are typically temporary, + * as described above). These are meant to be executed once and discarded, + * and various optimizations are made on the assumption of single use. + * Note in particular that the CachedPlanSources within such an SPI plan + * are not "complete" until execution. + * + * Note: if the original query string contained only whitespace and comments, + * the plancache_list will be NIL and so there is no place to store the + * query string. We don't care about that, but we do care about the + * argument type array, which is why it's seemingly-redundantly stored. + */ +typedef struct _SPI_plan { + int magic; /* should equal _SPI_PLAN_MAGIC */ + bool saved; /* saved or unsaved plan? */ + bool oneshot; /* one-shot plan? */ + List* plancache_list; /* one CachedPlanSource per parsetree */ + MemoryContext plancxt; /* Context containing _SPI_plan and data */ + int cursor_options; /* Cursor options used for planning */ + int nargs; /* number of plan arguments */ + Oid* argtypes; /* Argument types (NULL if nargs is 0) */ + ParserSetupHook parserSetup; /* alternative parameter spec method */ + void* parserSetupArg; + uint32 id; /* SPIplan id in a function */ + uint32 spi_key; /* key in SPICacheTable */ +} _SPI_plan; + +#endif /* SPI_PRIV_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/tstoreReceiver.h postgresql-hll-2.14/include/include/executor/tstoreReceiver.h --- postgresql-hll-2.14_old/include/include/executor/tstoreReceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/tstoreReceiver.h 2020-12-12 17:06:43.190347303 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * tstoreReceiver.h + * prototypes for tstoreReceiver.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/tstoreReceiver.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSTORE_RECEIVER_H +#define TSTORE_RECEIVER_H + +#include "tcop/dest.h" +#include "utils/tuplestore.h" + +extern DestReceiver* CreateTuplestoreDestReceiver(void); + +extern void SetTuplestoreDestReceiverParams( + DestReceiver* self, Tuplestorestate* tStore, MemoryContext tContext, bool detoast); + +#endif /* TSTORE_RECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/include/executor/tuptable.h postgresql-hll-2.14/include/include/executor/tuptable.h --- postgresql-hll-2.14_old/include/include/executor/tuptable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/executor/tuptable.h 2020-12-12 17:06:43.191347316 +0800 @@ -0,0 +1,195 @@ +/* ------------------------------------------------------------------------- + * + * tuptable.h + * tuple table support stuff + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/executor/tuptable.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPTABLE_H +#define TUPTABLE_H + +#include "access/htup.h" +#include "storage/buf.h" + +#ifndef FRONTEND_PARSER +/* ---------- + * The executor stores tuples in a "tuple table" which is a List of + * independent TupleTableSlots. There are several cases we need to handle: + * 1. physical tuple in a disk buffer page + * 2. physical tuple constructed in palloc'ed memory + * 3. "minimal" physical tuple constructed in palloc'ed memory + * 4. "virtual" tuple consisting of Datum/isnull arrays + * + * The first two cases are similar in that they both deal with "materialized" + * tuples, but resource management is different. For a tuple in a disk page + * we need to hold a pin on the buffer until the TupleTableSlot's reference + * to the tuple is dropped; while for a palloc'd tuple we usually want the + * tuple pfree'd when the TupleTableSlot's reference is dropped. + * + * A "minimal" tuple is handled similarly to a palloc'd regular tuple. + * At present, minimal tuples never are stored in buffers, so there is no + * parallel to case 1. Note that a minimal tuple has no "system columns". + * (Actually, it could have an OID, but we have no need to access the OID.) + * + * A "virtual" tuple is an optimization used to minimize physical data + * copying in a nest of plan nodes. Any pass-by-reference Datums in the + * tuple point to storage that is not directly associated with the + * TupleTableSlot; generally they will point to part of a tuple stored in + * a lower plan node's output TupleTableSlot, or to a function result + * constructed in a plan node's per-tuple econtext. It is the responsibility + * of the generating plan node to be sure these resources are not released + * for as long as the virtual tuple needs to be valid. We only use virtual + * tuples in the result slots of plan nodes --- tuples to be copied anywhere + * else need to be "materialized" into physical tuples. Note also that a + * virtual tuple does not have any "system columns". + * + * It is also possible for a TupleTableSlot to hold both physical and minimal + * copies of a tuple. This is done when the slot is requested to provide + * the format other than the one it currently holds. (Originally we attempted + * to handle such requests by replacing one format with the other, but that + * had the fatal defect of invalidating any pass-by-reference Datums pointing + * into the existing slot contents.) Both copies must contain identical data + * payloads when this is the case. + * + * The Datum/isnull arrays of a TupleTableSlot serve double duty. When the + * slot contains a virtual tuple, they are the authoritative data. When the + * slot contains a physical tuple, the arrays contain data extracted from + * the tuple. (In this state, any pass-by-reference Datums point into + * the physical tuple.) The extracted information is built "lazily", + * ie, only as needed. This serves to avoid repeated extraction of data + * from the physical tuple. + * + * A TupleTableSlot can also be "empty", holding no valid data. This is + * the only valid state for a freshly-created slot that has not yet had a + * tuple descriptor assigned to it. In this state, tts_isempty must be + * TRUE, tts_shouldFree FALSE, tts_tuple NULL, tts_buffer InvalidBuffer, + * and tts_nvalid zero. + * + * The tupleDescriptor is simply referenced, not copied, by the TupleTableSlot + * code. The caller of ExecSetSlotDescriptor() is responsible for providing + * a descriptor that will live as long as the slot does. (Typically, both + * slots and descriptors are in per-query memory and are freed by memory + * context deallocation at query end; so it's not worth providing any extra + * mechanism to do more. However, the slot will increment the tupdesc + * reference count if a reference-counted tupdesc is supplied.) + * + * When tts_shouldFree is true, the physical tuple is "owned" by the slot + * and should be freed when the slot's reference to the tuple is dropped. + * + * If tts_buffer is not InvalidBuffer, then the slot is holding a pin + * on the indicated buffer page; drop the pin when we release the + * slot's reference to that buffer. (tts_shouldFree should always be + * false in such a case, since presumably tts_tuple is pointing at the + * buffer page.) + * + * tts_nvalid indicates the number of valid columns in the tts_values/isnull + * arrays. When the slot is holding a "virtual" tuple this must be equal + * to the descriptor's natts. When the slot is holding a physical tuple + * this is equal to the number of columns we have extracted (we always + * extract columns from left to right, so there are no holes). + * + * tts_values/tts_isnull are allocated when a descriptor is assigned to the + * slot; they are of length equal to the descriptor's natts. + * + * tts_mintuple must always be NULL if the slot does not hold a "minimal" + * tuple. When it does, tts_mintuple points to the actual MinimalTupleData + * object (the thing to be pfree'd if tts_shouldFreeMin is true). If the slot + * has only a minimal and not also a regular physical tuple, then tts_tuple + * points at tts_minhdr and the fields of that struct are set correctly + * for access to the minimal tuple; in particular, tts_minhdr.t_data points + * MINIMAL_TUPLE_OFFSET bytes before tts_mintuple. This allows column + * extraction to treat the case identically to regular physical tuples. + * + * tts_slow/tts_off are saved state for slot_deform_tuple, and should not + * be touched by any other code. + * ---------- + */ +typedef struct TupleTableSlot { + NodeTag type; + bool tts_isempty; /* true = slot is empty */ + bool tts_shouldFree; /* should pfree tts_tuple? */ + bool tts_shouldFreeMin; /* should pfree tts_mintuple? */ + bool tts_slow; /* saved state for slot_deform_tuple */ + + //XXXTAM: remove tts_utuple later. + + Tuple tts_tuple; /* physical tuple, or NULL if virtual */ + +#ifdef PGXC + /* + * PGXC extension to support tuples sent from remote Datanode. + */ + char* tts_dataRow; /* Tuple data in DataRow format */ + int tts_dataLen; /* Actual length of the data row */ + bool tts_shouldFreeRow; /* should pfree tts_dataRow? */ + struct AttInMetadata* tts_attinmeta; /* store here info to extract values from the DataRow */ + Oid tts_xcnodeoid; /* Oid of node from where the datarow is fetched */ + MemoryContext tts_per_tuple_mcxt; +#endif + TupleDesc tts_tupleDescriptor; /* slot's tuple descriptor */ + MemoryContext tts_mcxt; /* slot itself is in this context */ + Buffer tts_buffer; /* tuple's buffer, or InvalidBuffer */ + int tts_nvalid; /* # of valid values in tts_values */ + Datum* tts_values; /* current per-attribute values */ + bool* tts_isnull; /* current per-attribute isnull flags */ + MinimalTuple tts_mintuple; /* minimal tuple, or NULL if none */ + HeapTupleData tts_minhdr; /* workspace for minimal-tuple-only case */ + long tts_off; /* saved state for slot_deform_tuple */ + long tts_meta_off; /* saved state for slot_deform_cmpr_tuple */ + TableAmType tts_tupslotTableAm; /* slots's tuple table type */ +} TupleTableSlot; + +#define TTS_HAS_PHYSICAL_TUPLE(slot) ((slot)->tts_tuple != NULL && (slot)->tts_tuple != &((slot)->tts_minhdr)) + +/* + * TupIsNull -- is a TupleTableSlot empty? + */ +#define TupIsNull(slot) ((slot) == NULL || (slot)->tts_isempty) + +/* in executor/execTuples.c */ +extern TupleTableSlot* MakeTupleTableSlot(bool has_tuple_mcxt = true, TableAmType tupslotTableAm = TAM_HEAP); +extern TupleTableSlot* ExecAllocTableSlot(List** tupleTable, TableAmType tupslotTableAm = TAM_HEAP); +extern void ExecResetTupleTable(List* tupleTable, bool shouldFree); +extern TupleTableSlot* MakeSingleTupleTableSlot(TupleDesc tupdesc, bool allocSlotCxt = false, TableAmType tupslotTableAm = TAM_HEAP); +extern void ExecDropSingleTupleTableSlot(TupleTableSlot* slot); +extern void ExecSetSlotDescriptor(TupleTableSlot* slot, TupleDesc tupdesc); +extern TupleTableSlot* ExecStoreTuple(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool shouldFree); +extern TupleTableSlot* ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot* slot, bool shouldFree); +#ifdef PGXC +extern TupleTableSlot* ExecStoreDataRowTuple( + char* msg, size_t len, Oid msgnode_oid, TupleTableSlot* slot, bool shouldFree); +#endif +extern TupleTableSlot* ExecClearTuple(TupleTableSlot* slot); +extern TupleTableSlot* ExecStoreVirtualTuple(TupleTableSlot* slot); +extern TupleTableSlot* ExecStoreAllNullTuple(TupleTableSlot* slot); +extern HeapTuple ExecCopySlotTuple(TupleTableSlot* slot); +extern MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot* slot, bool need_transform_anyarray = false); +extern HeapTuple ExecFetchSlotTuple(TupleTableSlot* slot); +extern MinimalTuple ExecFetchSlotMinimalTuple(TupleTableSlot* slot); +extern Datum ExecFetchSlotTupleDatum(TupleTableSlot* slot); +extern HeapTuple ExecMaterializeSlot(TupleTableSlot* slot); +extern TupleTableSlot* ExecCopySlot(TupleTableSlot* dstslot, TupleTableSlot* srcslot); + +/* heap table specific slot/tuple operations*/ +/* definitions are found in access/common/heaptuple.c */ +extern void heap_slot_clear(TupleTableSlot* slot); +extern void heap_slot_materialize(TupleTableSlot* slot); +extern MinimalTuple heap_slot_get_minimal_tuple(TupleTableSlot *slot); +extern MinimalTuple heap_slot_copy_minimal_tuple(TupleTableSlot *slot); +extern void heap_slot_store_minimal_tuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree); +extern HeapTuple heap_slot_get_heap_tuple (TupleTableSlot* slot); +extern HeapTuple heap_slot_copy_heap_tuple (TupleTableSlot *slot); +extern void heap_slot_store_heap_tuple(HeapTuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free); +extern Datum heap_slot_getattr(TupleTableSlot* slot, int attnum, bool* isnull, bool need_transform_anyarray = false); +extern void heap_slot_getallattrs(TupleTableSlot* slot, bool need_transform_anyarray = false); +extern void heap_slot_getsomeattrs(TupleTableSlot* slot, int attnum); +extern bool heap_slot_attisnull(TupleTableSlot* slot, int attnum); + +#endif /* !FRONTEND_PARSER */ +#endif /* TUPTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/flock.h postgresql-hll-2.14/include/include/flock.h --- postgresql-hll-2.14_old/include/include/flock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/flock.h 2020-12-12 17:06:43.191347316 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * flock.h + * + * + * + * IDENTIFICATION + * src/include/flock.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef FLOCK_H +#define FLOCK_H + +/* + * flock ports + */ +#ifndef LOCK_EX + +#undef LOCK_SH +#undef LOCK_EX +#undef LOCK_UN +#undef LOCK_NB + +#define LOCK_SH 1 /* Shared lock. */ +#define LOCK_EX 2 /* Exclusive lock. */ +#define LOCK_UN 8 /* Unlock. */ +#define LOCK_NB 4 /* Don't block when locking. */ +#endif + +#define START_LOCATION 1 +#define CURRENT_LOCATION 2 +#define END_LOCATION 4 + +extern int pgut_flock(int fd, int operation, int64 offset, int location, int64 len); +#define flock pgut_flock + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/fmgr.h postgresql-hll-2.14/include/include/fmgr.h --- postgresql-hll-2.14_old/include/include/fmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/fmgr.h 2020-12-12 17:06:43.191347316 +0800 @@ -0,0 +1,968 @@ +/* ------------------------------------------------------------------------- + * + * fmgr.h + * Definitions for the Postgres function manager and function-call + * interface. + * + * This file must be included by all Postgres modules that either define + * or call fmgr-callable functions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/fmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FMGR_H +#define FMGR_H + +#if defined(FRONTEND_PARSER) +#include "postgres_fe.h" +#else +#include "postgres.h" +#endif // FRONTEND_PARSER +#include "lib/stringinfo.h" + +/* We don't want to include primnodes.h here, so make a stub reference */ +typedef struct Node* fmNodePtr; +class ScalarVector; + +/* Likewise, avoid including stringinfo.h here */ +typedef struct StringInfoData* fmStringInfo; + +struct FunctionCallInfoData; + +struct Cursor_Data; + +typedef Datum (*UDFArgsFuncType)(FunctionCallInfoData* fcinfo, int idx, Datum val); + +/* + * All functions that can be called directly by fmgr must have this signature. + * (Other functions can be called by using a handler that does have this + * signature.) + */ + +typedef struct FunctionCallInfoData* FunctionCallInfo; + +#ifndef FRONTEND_PARSER + +typedef Datum (*PGFunction)(FunctionCallInfo fcinfo); + +typedef ScalarVector* (*VectorFunction)(FunctionCallInfo fcinfo); +typedef Datum (*GenericArgExtract)(Datum* data); + +extern void InitFuncCallUDFInfo(FunctionCallInfoData* fcinfo, int argN, bool setFuncPtr); +extern void InitFunctionCallUDFArgs(FunctionCallInfoData* fcinfo, int argN, int batchRows); +extern void FreeFuncCallUDFInfo(FunctionCallInfoData* Fcinfo); + +#define VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS 32 +#define VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS 10 + +struct GenericFunRuntimeArg { + ScalarVector** arg; + Oid argType; + GenericArgExtract getArgFun; +}; + +struct GenericFunRuntime { + /* maxium number of the arguements can be stored */ + uint16 compacity; + + /* pointer to the address of the real arg */ + GenericFunRuntimeArg* args; + Datum* inputargs; + bool* nulls; + + bool restrictFlag[BatchMaxSize]; + FunctionCallInfoData* internalFinfo; +}; +/* + * This struct holds the system-catalog information that must be looked up + * before a function can be called through fmgr. If the same function is + * to be called multiple times, the lookup need be done only once and the + * info struct saved for re-use. + * + * Note that fn_expr really is parse-time-determined information about the + * arguments, rather than about the function itself. But it's convenient + * to store it here rather than in FunctionCallInfoData, where it might more + * logically belong. + */ +typedef struct FmgrInfo { + PGFunction fn_addr; /* pointer to function or handler to be called */ + Oid fn_oid; /* OID of function (NOT of handler, if any) */ + short fn_nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable arg + * count */ + bool fn_strict; /* function is "strict" (NULL in => NULL out) */ + bool fn_retset; /* function returns a set */ + unsigned char fn_stats; /* collect stats if track_functions > this */ + void* fn_extra; /* extra space for use by handler */ + MemoryContext fn_mcxt; /* memory context to store fn_extra in */ + fmNodePtr fn_expr; /* expression parse tree for call, or NULL */ + Oid fn_rettype; // Oid of function return type + char fnName[NAMEDATALEN]; /* function name */ + char* fnLibPath; /* library path for c-udf + * package.class.method(args) for java-udf */ + bool fn_fenced; + Oid fn_languageId; /* function language id*/ + char fn_volatile; /* procvolatile */ + // Vector Function + VectorFunction vec_fn_addr; + VectorFunction* vec_fn_cache; + GenericFunRuntime* genericRuntime; +} FmgrInfo; + +/* + * number of prealloced arguments to a function. + * In deepsql (SVM and elastic_net), we cannot explicitly set all elements to false. + */ +#define FUNC_PREALLOCED_ARGS 20 + +typedef struct UDFInfoType { + UDFArgsFuncType* UDFArgsHandlerPtr; /* UDF send/recv argument function */ + UDFArgsFuncType UDFResultHandlerPtr; + StringInfo udfMsgBuf; + char* msgReadPtr; + int argBatchRows; + int allocRows; + Datum** arg; + bool** null; + Datum* result; + bool* resultIsNull; + bool valid_UDFArgsHandlerPtr; /* True if funcUDFArgs are filled ok */ + + UDFInfoType() + { + udfMsgBuf = NULL; + msgReadPtr = NULL; + arg = NULL; + null = NULL; + result = NULL; + resultIsNull = NULL; + UDFArgsHandlerPtr = NULL; + UDFResultHandlerPtr = NULL; + valid_UDFArgsHandlerPtr = false; + allocRows = 0; + argBatchRows = 0; + } +} UDFInfoType; + +typedef struct RefcusorInfoData { + Cursor_Data* argCursor; + Cursor_Data* returnCursor; + int return_number; +} RefcusorInfoData; + +/* + * This struct is the data actually passed to an fmgr-called function. + */ +typedef struct FunctionCallInfoData { + FmgrInfo* flinfo; /* ptr to lookup info used for this call */ + fmNodePtr context; /* pass info about context of call */ + fmNodePtr resultinfo; /* pass or return extra info about result */ + Oid fncollation; /* collation for function to use */ + bool isnull; /* function must set true if result is NULL */ + short nargs; /* # arguments actually passed */ + Datum* arg; /* Arguments passed to function */ + bool* argnull; /* T if arg[i] is actually NULL */ + Oid* argTypes; /* Argument type */ + Datum prealloc_arg[FUNC_PREALLOCED_ARGS]; /* prealloced arguments.*/ + bool prealloc_argnull[FUNC_PREALLOCED_ARGS]; /* prealloced argument null flags.*/ + Oid prealloc_argTypes[FUNC_PREALLOCED_ARGS]; /* prealloced argument type */ + ScalarVector* argVector; /*Scalar Vector */ + RefcusorInfoData refcursor_data; + UDFInfoType udfInfo; + + FunctionCallInfoData() + { + flinfo = NULL; + arg = NULL; + argnull = NULL; + argTypes = NULL; + argVector = NULL; + fncollation = 0; + context = NULL; + resultinfo = NULL; + nargs = 0; + isnull = false; + } +} FunctionCallInfoData; + +/* + * List of dynamically loaded files (kept in malloc'd memory). + */ + +typedef struct df_files { + struct df_files* next; /* List link */ + dev_t device; /* Device file is on */ +#ifndef WIN32 /* ensures we never again depend on this under \ + * win32 */ + ino_t inode; /* Inode number of file */ +#endif + void* handle; /* a handle for pg_dl* functions */ + char filename[FLEXIBLE_ARRAY_MEMBER]; /* Full pathname of file */ + + /* + * we allocate the block big enough for actual length of pathname. + * filename[] must be last item in struct! + */ +} DynamicFileList; + +/*Introduced to judge whether PG_init has done or not*/ +typedef struct df_files_init { + struct df_files_init* next; /*List Link*/ + DynamicFileList* file_list; /*restore file_list in the linked list*/ +} FileListInit; + +extern DynamicFileList* file_list; +extern DynamicFileList* file_tail; + +#define EXTRA_NARGS 3 + +extern bool file_exists(const char* name); +/* + * This routine fills a FmgrInfo struct, given the OID + * of the function to be called. + */ +extern void fmgr_info(Oid functionId, FmgrInfo* finfo); + +/* + * Same, when the FmgrInfo struct is in a memory context longer-lived than + * CurrentMemoryContext. The specified context will be set as fn_mcxt + * and used to hold all subsidiary data of finfo. + */ +extern void fmgr_info_cxt(Oid functionId, FmgrInfo* finfo, MemoryContext mcxt); + +extern void InitVecFunctionCallInfoData( + FunctionCallInfoData* Fcinfo, FmgrInfo* Flinfo, int Nargs, Oid Collation, fmNodePtr Context, fmNodePtr Resultinfo); + +/* Convenience macro for setting the fn_expr field */ +#define fmgr_info_set_expr(expr, finfo) ((finfo)->fn_expr = (expr)) + +/* + * Copy an FmgrInfo struct + */ +extern void fmgr_info_copy(FmgrInfo* dstinfo, FmgrInfo* srcinfo, MemoryContext destcxt); + +/* + * This macro initializes all the fields of a GenericFunRuntime except + * for the all the prealloc arrays. Performance testing has shown that + * the fastest way to set up static arrays for small numbers of arguments is to + * explicitly set each required element to false, so we don't try to zero + * out the static prealloc array in the macro. + */ + +#define InitGenericFunRuntimeInfo(GenericRuntime, Nargs) \ + do { \ + (GenericRuntime).compacity = VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS; \ + if (unlikely((Nargs) > VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS)) { \ + (GenericRuntime).compacity += \ + (((Nargs)-VECTOR_GENERIC_FUNCTION_PREALLOCED_ARGS - 1) / VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS + \ + 1) * \ + VECTOR_GENERIC_FUNCTION_INCREMENTAL_ARGS; \ + } \ + (GenericRuntime).args = \ + (GenericFunRuntimeArg*)palloc0(sizeof(GenericFunRuntimeArg) * (GenericRuntime).compacity); \ + (GenericRuntime).inputargs = (Datum*)palloc0(sizeof(Datum) * (GenericRuntime).compacity); \ + (GenericRuntime).nulls = (bool*)palloc0(sizeof(bool) * (GenericRuntime).compacity); \ + } while (0) + +#define FreeGenericFunRuntimeInfo(GenericRuntime) \ + do { \ + pfree_ext((GenericRuntime).args); \ + pfree_ext((GenericRuntime).inputargs); \ + pfree_ext((GenericRuntime).nulls); \ + if (unlikely((GenericRuntime).internalFinfo != NULL)) \ + FreeFunctionCallInfoData(*((GenericRuntime).internalFinfo)); \ + (GenericRuntime).compacity = 0; \ + } while (0) + +/* + * This macro initializes all the fields of a FunctionCallInfoData except + * for the arg[] and argnull[] arrays. Performance testing has shown that + * the fastest way to set up argnull[] for small numbers of arguments is to + * explicitly set each required element to false, so we don't try to zero + * out the argnull[] array in the macro. + */ +#define InitFunctionCallInfoArgs(Fcinfo, Nargs, batchRow) \ + do { \ + (Fcinfo).nargs = (Nargs); \ + if ((Nargs) > FUNC_PREALLOCED_ARGS) { \ + (Fcinfo).arg = (Datum*)palloc0((Nargs) * sizeof(Datum)); \ + (Fcinfo).argnull = (bool*)palloc0(Nargs * sizeof(bool)); \ + (Fcinfo).argTypes = (Oid*)palloc0((Nargs) * sizeof(Oid)); \ + } else { \ + (Fcinfo).arg = (Fcinfo).prealloc_arg; \ + (Fcinfo).argnull = (Fcinfo).prealloc_argnull; \ + (Fcinfo).argTypes = (Fcinfo).prealloc_argTypes; \ + } \ + if (unlikely((Fcinfo).flinfo && (Fcinfo).flinfo->fn_fenced)) \ + InitFunctionCallUDFArgs(&(Fcinfo), (Nargs), (batchRow)); \ + } while (0) + +#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo) \ + do { \ + (Fcinfo).flinfo = (Flinfo); \ + (Fcinfo).context = (Context); \ + (Fcinfo).resultinfo = (Resultinfo); \ + (Fcinfo).fncollation = (Collation); \ + (Fcinfo).isnull = false; \ + (Fcinfo).nargs = (Nargs); \ + if ((Nargs) > FUNC_PREALLOCED_ARGS) { \ + (Fcinfo).arg = (Datum*)palloc0((Nargs) * sizeof(Datum)); \ + (Fcinfo).argnull = (bool*)palloc0((Nargs) * sizeof(bool)); \ + (Fcinfo).argTypes = (Oid*)palloc0((Nargs) * sizeof(Oid)); \ + } else { \ + (Fcinfo).arg = (Fcinfo).prealloc_arg; \ + (Fcinfo).argnull = (Fcinfo).prealloc_argnull; \ + (Fcinfo).argTypes = (Fcinfo).prealloc_argTypes; \ + } \ + if (unlikely((Flinfo) != NULL && (Fcinfo).flinfo->fn_fenced)) \ + InitFuncCallUDFInfo(&(Fcinfo), (Nargs), false); \ + (Fcinfo).refcursor_data.argCursor = NULL; \ + (Fcinfo).refcursor_data.returnCursor = NULL; \ + (Fcinfo).refcursor_data.return_number = 0; \ + } while (0) + +#define FreeFunctionCallInfoData(Fcinfo) \ + do { \ + if ((Fcinfo).nargs > FUNC_PREALLOCED_ARGS) { \ + pfree((Fcinfo).arg); \ + pfree((Fcinfo).argnull); \ + pfree((Fcinfo).argTypes); \ + (Fcinfo).argTypes = NULL; \ + (Fcinfo).arg = NULL; \ + (Fcinfo).argnull = NULL; \ + } \ + FreeFuncCallUDFInfo(&(Fcinfo)); \ + } while (0) +/* + * This macro invokes a function given a filled-in FunctionCallInfoData + * struct. The macro result is the returned Datum --- but note that + * caller must still check fcinfo->isnull! Also, if function is strict, + * it is caller's responsibility to verify that no null arguments are present + * before calling. + */ +#define FunctionCallInvoke(fcinfo) ((*(fcinfo)->flinfo->fn_addr)(fcinfo)) + +#define VecFunctionCallInvoke(fcinfo) ((*(fcinfo)->flinfo->vec_fn_addr)(fcinfo)) + +#endif /* FRONTEND_PARSER */ +/* ------------------------------------------------------------------------- + * Support macros to ease writing fmgr-compatible functions + * + * A C-coded fmgr-compatible function should be declared as + * + * Datum + * function_name(PG_FUNCTION_ARGS) + * { + * ... + * } + * + * It should access its arguments using appropriate PG_GETARG_xxx macros + * and should return its result using PG_RETURN_xxx. + * + * ------------------------------------------------------------------------- + */ + +/* Standard parameter list for fmgr-compatible functions */ +#define PG_FUNCTION_ARGS FunctionCallInfo fcinfo + +/* + * Get collation function should use. + */ +#define PG_GET_COLLATION() (fcinfo->fncollation) + +/* + * Get number of arguments passed to function. + */ +#define PG_NARGS() (fcinfo->nargs) + +/* + * If function is not marked "proisstrict" in pg_proc, it must check for + * null arguments using this macro. Do not try to GETARG a null argument! + */ +#define PG_ARGISNULL(n) (fcinfo->argnull[n]) + +#ifndef FRONTEND_PARSER +/* + * Support for fetching detoasted copies of toastable datatypes (all of + * which are varlena types). pg_detoast_datum() gives you either the input + * datum (if not toasted) or a detoasted copy allocated with palloc(). + * pg_detoast_datum_copy() always gives you a palloc'd copy --- use it + * if you need a modifiable copy of the input. Caller is expected to have + * checked for null inputs first, if necessary. + * + * pg_detoast_datum_packed() will return packed (1-byte header) datums + * unmodified. It will still expand an externally toasted or compressed datum. + * The resulting datum can be accessed using VARSIZE_ANY() and VARDATA_ANY() + * (beware of multiple evaluations in those macros!) + * + * WARNING: It is only safe to use pg_detoast_datum_packed() and + * VARDATA_ANY() if you really don't care about the alignment. Either because + * you're working with something like text where the alignment doesn't matter + * or because you're not going to access its constituent parts and just use + * things like memcpy on it anyways. + * + * Note: it'd be nice if these could be macros, but I see no way to do that + * without evaluating the arguments multiple times, which is NOT acceptable. + */ +extern struct varlena* pg_detoast_datum(struct varlena* datum); +extern struct varlena* pg_detoast_datum_copy(struct varlena* datum); +extern struct varlena* pg_detoast_datum_slice(struct varlena* datum, int32 first, int32 count); +extern struct varlena* pg_detoast_datum_packed(struct varlena* datum); + +#define PG_DETOAST_DATUM(datum) pg_detoast_datum((struct varlena*)DatumGetPointer(datum)) +#define PG_DETOAST_DATUM_COPY(datum) pg_detoast_datum_copy((struct varlena*)DatumGetPointer(datum)) +#define PG_DETOAST_DATUM_SLICE(datum, f, c) \ + pg_detoast_datum_slice((struct varlena*)DatumGetPointer(datum), (int32)(f), (int32)(c)) +/* WARNING -- unaligned pointer */ +#define PG_DETOAST_DATUM_PACKED(datum) pg_detoast_datum_packed((struct varlena*)DatumGetPointer(datum)) + +/* + * Support for cleaning up detoasted copies of inputs. This must only + * be used for pass-by-ref datatypes, and normally would only be used + * for toastable types. If the given pointer is different from the + * original argument, assume it's a palloc'd detoasted copy, and pfree it. + * NOTE: most functions on toastable types do not have to worry about this, + * but we currently require that support functions for indexes not leak + * memory. + */ +#define PG_FREE_IF_COPY(ptr, n) \ + do { \ + if ((Pointer)(ptr) != PG_GETARG_POINTER(n)) \ + pfree(ptr); \ + } while (0) + +/* Macros for fetching arguments of standard types */ + +#define PG_GETARG_DATUM(n) (fcinfo->arg[n]) +#define PG_GETARG_INT32(n) DatumGetInt32(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT32(n) DatumGetUInt32(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT16(n) DatumGetInt16(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT16(n) DatumGetUInt16(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT8(n) DatumGetInt8(PG_GETARG_DATUM(n)) +#define PG_GETARG_UINT8(n) DatumGetUInt8(PG_GETARG_DATUM(n)) +#define PG_GETARG_CHAR(n) DatumGetChar(PG_GETARG_DATUM(n)) +#define PG_GETARG_BOOL(n) DatumGetBool(PG_GETARG_DATUM(n)) +#define PG_GETARG_OID(n) DatumGetObjectId(PG_GETARG_DATUM(n)) +#define PG_GETARG_POINTER(n) DatumGetPointer(PG_GETARG_DATUM(n)) +#define PG_GETARG_CSTRING(n) DatumGetCString(PG_GETARG_DATUM(n)) +#define PG_GETARG_NAME(n) DatumGetName(PG_GETARG_DATUM(n)) +/* these macros hide the pass-by-reference-ness of the datatype: */ +#define PG_GETARG_FLOAT4(n) DatumGetFloat4(PG_GETARG_DATUM(n)) +#define PG_GETARG_FLOAT8(n) DatumGetFloat8(PG_GETARG_DATUM(n)) +#define PG_GETARG_INT64(n) DatumGetInt64(PG_GETARG_DATUM(n)) +#define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n)) +#define PG_GETARG_SHORTTRANSACTIONID(n) DatumGetShortTransactionId(PG_GETARG_DATUM(n)) +/* use this if you want the raw, possibly-toasted input datum: */ +#define PG_GETARG_RAW_VARLENA_P(n) ((struct varlena*)PG_GETARG_POINTER(n)) +/* use this if you want the input datum de-toasted: */ +#define PG_GETARG_VARLENA_P(n) PG_DETOAST_DATUM(PG_GETARG_DATUM(n)) +/* and this if you can handle 1-byte-header datums: */ +#define PG_GETARG_VARLENA_PP(n) PG_DETOAST_DATUM_PACKED(PG_GETARG_DATUM(n)) +/* DatumGetFoo macros for varlena types will typically look like this: */ +#define DatumGetByteaP(X) ((bytea*)PG_DETOAST_DATUM(X)) +#define DatumGetByteaPP(X) ((bytea*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetTextP(X) ((text*)PG_DETOAST_DATUM(X)) +#define DatumGetTextPP(X) ((text*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetBpCharP(X) ((BpChar*)PG_DETOAST_DATUM(X)) +#define DatumGetBpCharPP(X) ((BpChar*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetVarCharP(X) ((VarChar*)PG_DETOAST_DATUM(X)) +#define DatumGetVarCharPP(X) ((VarChar*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetNVarChar2PP(X) ((NVarChar2*)PG_DETOAST_DATUM_PACKED(X)) +#define DatumGetHeapTupleHeader(X) ((HeapTupleHeader)PG_DETOAST_DATUM(X)) +#define DatumGetEncryptedcolP(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM(X)) +#define DatumGetEncryptedcolPP(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM_PACKED(X)) +/* And we also offer variants that return an OK-to-write copy */ +#define DatumGetByteaPCopy(X) ((bytea*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetEncryptedcolPCopy(X) ((byteawithoutorderwithequalcol *) PG_DETOAST_DATUM_COPY(X)) +#define DatumGetTextPCopy(X) ((text*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetBpCharPCopy(X) ((BpChar*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetVarCharPCopy(X) ((VarChar*)PG_DETOAST_DATUM_COPY(X)) +#define DatumGetHeapTupleHeaderCopy(X) ((HeapTupleHeader)PG_DETOAST_DATUM_COPY(X)) +/* Variants which return n bytes starting at pos. m */ +#define DatumGetByteaPSlice(X, m, n) ((bytea*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetTextPSlice(X, m, n) ((text*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetBpCharPSlice(X, m, n) ((BpChar*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetVarCharPSlice(X, m, n) ((VarChar*)PG_DETOAST_DATUM_SLICE(X, m, n)) +#define DatumGetEncryptedcolPSlice(X, m, n) ((byteawithoutorderwithequalcol *)PG_DETOAST_DATUM_SLICE(X, m, n)) +/* GETARG macros for varlena types will typically look like this: */ +#define PG_GETARG_BYTEA_P(n) DatumGetByteaP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BYTEA_PP(n) DatumGetByteaPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_P(n) DatumGetTextP(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_PP(n) DatumGetTextPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_P(n) DatumGetBpCharP(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_PP(n) DatumGetBpCharPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_P(n) DatumGetVarCharP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_PP(n) DatumGetVarCharPP(PG_GETARG_DATUM(n)) +#define PG_GETARG_NVARCHAR2_PP(n) DatumGetNVarChar2PP(PG_GETARG_DATUM(n)) +#define PG_GETARG_HEAPTUPLEHEADER(n) DatumGetHeapTupleHeader(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_P(n) DatumGetEncryptedcolP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_PP(n) DatumGetEncryptedcolPP(PG_GETARG_DATUM(n)) +/* And we also offer variants that return an OK-to-write copy */ +#define PG_GETARG_BYTEA_P_COPY(n) DatumGetByteaPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_TEXT_P_COPY(n) DatumGetTextPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_BPCHAR_P_COPY(n) DatumGetBpCharPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARCHAR_P_COPY(n) DatumGetVarCharPCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_HEAPTUPLEHEADER_COPY(n) DatumGetHeapTupleHeaderCopy(PG_GETARG_DATUM(n)) +#define PG_GETARG_ENCRYPTEDCOL_P_COPY(n) DatumGetEncryptedcolPCopy(PG_GETARG_DATUM(n)) +/* And a b-byte slice from position a -also OK to write */ +#define PG_GETARG_BYTEA_P_SLICE(n, a, b) DatumGetByteaPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_ENCRYPTEDCOL_P_SLICE(n, a, b) DatumGetEncryptedcolPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_TEXT_P_SLICE(n, a, b) DatumGetTextPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_BPCHAR_P_SLICE(n, a, b) DatumGetBpCharPSlice(PG_GETARG_DATUM(n), a, b) +#define PG_GETARG_VARCHAR_P_SLICE(n, a, b) DatumGetVarCharPSlice(PG_GETARG_DATUM(n), a, b) + +// Vectorized getters +// +#define PG_GETARG_VECTOR(n) ((ScalarVector*)(PG_GETARG_DATUM(n))) +#define PG_GETARG_SELECTION(n) ((bool*)(PG_GETARG_DATUM(n))) +#define PG_GETARG_VECVAL(n) ((ScalarValue*)(PG_GETARG_VECTOR(n)->m_vals)) + +/* To return a NULL do this: */ +#define PG_RETURN_NULL() \ + do { \ + fcinfo->isnull = true; \ + return (Datum)0; \ + } while (0) + +/* A few internal functions return void (which is not the same as NULL!) */ +#define PG_RETURN_VOID() return (Datum)0 + +/* Macros for returning results of standard types */ + +#define PG_RETURN_DATUM(x) return (x) +#define PG_RETURN_INT32(x) return Int32GetDatum(x) +#define PG_RETURN_UINT32(x) return UInt32GetDatum(x) +#define PG_RETURN_INT16(x) return Int16GetDatum(x) +#define PG_RETURN_UINT16(x) return UInt16GetDatum(x) +#define PG_RETURN_UINT8(x) return UInt8GetDatum(x) +#define PG_RETURN_CHAR(x) return CharGetDatum(x) +#define PG_RETURN_BOOL(x) return BoolGetDatum(x) +#define PG_RETURN_OID(x) return ObjectIdGetDatum(x) +#define PG_RETURN_POINTER(x) return PointerGetDatum(x) +#define PG_RETURN_CSTRING(x) return CStringGetDatum(x) +#define PG_RETURN_NAME(x) return NameGetDatum(x) +/* these macros hide the pass-by-reference-ness of the datatype: */ +#define PG_RETURN_FLOAT4(x) return Float4GetDatum(x) +#define PG_RETURN_FLOAT8(x) return Float8GetDatum(x) +#define PG_RETURN_INT64(x) return Int64GetDatum(x) +#define PG_RETURN_TRANSACTIONID(x) return TransactionIdGetDatum(x) +#define PG_RETURN_SHORTTRANSACTIONID(x) return ShortTransactionIdGetDatum(x) +/* RETURN macros for other pass-by-ref types will typically look like this: */ +#define PG_RETURN_BYTEA_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_ENCRYPTEDCOL_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_TEXT_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_BPCHAR_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_VARCHAR_P(x) PG_RETURN_POINTER(x) +#define PG_RETURN_HEAPTUPLEHEADER(x) PG_RETURN_POINTER(x) +#define PG_RETURN_NVARCHAR2_P(x) PG_RETURN_POINTER(x) + +typedef enum COMM_ARG_IDX { + ARG_0, + ARG_1, + ARG_2, + ARG_3, + ARG_4, + ARG_5, + ARG_6, + ARG_7, + ARG_8, + ARG_9, + ARG_10, + ARG_11, + ARG_12, + ARG_13, + ARG_14, + ARG_15, + ARG_16, + ARG_17, + ARG_18, + ARG_19, + ARG_20, + ARG_END +} COMM_ARG_IDX; + +typedef enum COMM_ARR_IDX { + ARR_0, + ARR_1, + ARR_2, + ARR_3, + ARR_4, + ARR_5, + ARR_6, + ARR_7, + ARR_8, + ARR_9, + ARR_10, + ARR_11, + ARR_12, + ARR_13, + ARR_14, + ARR_15, + ARR_16, + ARR_17, + ARR_18, + ARR_19, + ARR_20, + ARR_END +} COMM_ARR_IDX; + +/* ------------------------------------------------------------------------- + * Support for detecting call convention of dynamically-loaded functions + * + * Dynamically loaded functions may use either the version-1 ("new style") + * or version-0 ("old style") calling convention. Version 1 is the call + * convention defined in this header file; version 0 is the old "plain C" + * convention. A version-1 function must be accompanied by the macro call + * + * PG_FUNCTION_INFO_V1(function_name); + * + * Note that internal functions do not need this decoration since they are + * assumed to be version-1. + * + * ------------------------------------------------------------------------- + */ + +typedef struct { + int api_version; /* specifies call convention version number */ + /* More fields may be added later, for version numbers > 1. */ +} Pg_finfo_record; + +/* Expected signature of an info function */ +typedef const Pg_finfo_record* (*PGFInfoFunction)(void); + +/* + * Macro to build an info function associated with the given function name. + * Win32 loadable functions usually link with 'dlltool --export-all', but it + * doesn't hurt to add PGDLLIMPORT in case they don't. + */ +#define PG_FUNCTION_INFO_V1(funcname) \ + extern "C" PGDLLEXPORT const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void); \ + const Pg_finfo_record* CppConcat(pg_finfo_, funcname)(void) \ + { \ + static const Pg_finfo_record my_finfo = {1}; \ + return &my_finfo; \ + } \ + extern int no_such_variable + +/* ------------------------------------------------------------------------- + * Support for verifying backend compatibility of loaded modules + * + * We require dynamically-loaded modules to include the macro call + * PG_MODULE_MAGIC; + * so that we can check for obvious incompatibility, such as being compiled + * for a different major PostgreSQL version. + * + * To compile with versions of PostgreSQL that do not support this, + * you may put an #ifdef/#endif test around it. Note that in a multiple- + * source-file module, the macro call should only appear once. + * + * The specific items included in the magic block are intended to be ones that + * are custom-configurable and especially likely to break dynamically loaded + * modules if they were compiled with other values. Also, the length field + * can be used to detect definition changes. + * + * Note: we compare magic blocks with memcmp(), so there had better not be + * any alignment pad bytes in them. + * + * Note: when changing the contents of magic blocks, be sure to adjust the + * incompatible_module_error() function in dfmgr.c. + * ------------------------------------------------------------------------- + */ + +/* Definition of the magic block structure */ +typedef struct { + int len; /* sizeof(this struct) */ + int version; /* PostgreSQL major version */ + int funcmaxargs; /* FUNC_MAX_ARGS */ + int indexmaxkeys; /* INDEX_MAX_KEYS */ + int namedatalen; /* NAMEDATALEN */ + int float4byval; /* FLOAT4PASSBYVAL */ + int float8byval; /* FLOAT8PASSBYVAL */ +} Pg_magic_struct; + +/* The actual data block contents */ +#define PG_MODULE_MAGIC_DATA \ + { \ + sizeof(Pg_magic_struct), PG_VERSION_NUM / 100, FUNC_MAX_ARGS, INDEX_MAX_KEYS, NAMEDATALEN, FLOAT4PASSBYVAL, \ + FLOAT8PASSBYVAL \ + } + +/* + * Declare the module magic function. It needs to be a function as the dlsym + * in the backend is only guaranteed to work on functions, not data + */ +typedef const Pg_magic_struct* (*PGModuleMagicFunction)(void); + +#define PG_MAGIC_FUNCTION_NAME Pg_magic_func +#define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func" + +#define PG_MODULE_MAGIC \ + extern "C" PGDLLEXPORT const Pg_magic_struct* PG_MAGIC_FUNCTION_NAME(void); \ + const Pg_magic_struct* PG_MAGIC_FUNCTION_NAME(void) \ + { \ + static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \ + return &Pg_magic_data; \ + } \ + extern int no_such_variable + +/* ------------------------------------------------------------------------- + * Support routines and macros for callers of fmgr-compatible functions + * ------------------------------------------------------------------------- + */ + +/* These are for invocation of a specifically named function with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. + */ +extern Datum DirectFunctionCall1Coll(PGFunction func, Oid collation, Datum arg1); +extern Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2); +extern Datum DirectFunctionCall3Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum DirectFunctionCall4Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum DirectFunctionCall5Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum DirectFunctionCall6Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum DirectFunctionCall7Coll( + PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7); +extern Datum DirectFunctionCall8Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum DirectFunctionCall9Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These are for invocation of a previously-looked-up function with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. + */ +extern Datum FunctionCall1Coll(FmgrInfo* flinfo, Oid collation, Datum arg1); +extern Datum FunctionCall2Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2); +extern Datum FunctionCall3Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum FunctionCall4Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum FunctionCall5Coll( + FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum FunctionCall6Coll( + FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum FunctionCall7Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7); +extern Datum FunctionCall8Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum FunctionCall9Coll(FmgrInfo* flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These are for invocation of a function identified by OID with a + * directly-computed parameter list. Note that neither arguments nor result + * are allowed to be NULL. These are essentially FunctionLookup() followed + * by FunctionCallN(). If the same function is to be invoked repeatedly, + * do the FunctionLookup() once and then use FunctionCallN(). + */ +extern Datum OidFunctionCall0Coll(Oid functionId, Oid collation); +extern Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1); +extern Datum OidFunctionCall2Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2); +extern Datum OidFunctionCall3Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum OidFunctionCall4Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4); +extern Datum OidFunctionCall5Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5); +extern Datum OidFunctionCall6Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6); +extern Datum OidFunctionCall7Coll( + Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7); +extern Datum OidFunctionCall8Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8); +extern Datum OidFunctionCall9Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, + Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9); + +/* These macros allow the collation argument to be omitted (with a default of + * InvalidOid, ie, no collation). They exist mostly for backwards + * compatibility of source code. + */ +#define DirectFunctionCall1(func, arg1) DirectFunctionCall1Coll(func, InvalidOid, arg1) +#define DirectFunctionCall2(func, arg1, arg2) DirectFunctionCall2Coll(func, InvalidOid, arg1, arg2) +#define DirectFunctionCall3(func, arg1, arg2, arg3) DirectFunctionCall3Coll(func, InvalidOid, arg1, arg2, arg3) +#define DirectFunctionCall4(func, arg1, arg2, arg3, arg4) \ + DirectFunctionCall4Coll(func, InvalidOid, arg1, arg2, arg3, arg4) +#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5) \ + DirectFunctionCall5Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define DirectFunctionCall6(func, arg1, arg2, arg3, arg4, arg5, arg6) \ + DirectFunctionCall6Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define DirectFunctionCall7(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + DirectFunctionCall7Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define DirectFunctionCall8(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + DirectFunctionCall8Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define DirectFunctionCall9(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + DirectFunctionCall9Coll(func, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +#define FunctionCall1(flinfo, arg1) FunctionCall1Coll(flinfo, InvalidOid, arg1) +#define FunctionCall2(flinfo, arg1, arg2) FunctionCall2Coll(flinfo, InvalidOid, arg1, arg2) +#define FunctionCall3(flinfo, arg1, arg2, arg3) FunctionCall3Coll(flinfo, InvalidOid, arg1, arg2, arg3) +#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4) FunctionCall4Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4) +#define FunctionCall5(flinfo, arg1, arg2, arg3, arg4, arg5) \ + FunctionCall5Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define FunctionCall6(flinfo, arg1, arg2, arg3, arg4, arg5, arg6) \ + FunctionCall6Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define FunctionCall7(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + FunctionCall7Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define FunctionCall8(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + FunctionCall8Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define FunctionCall9(flinfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + FunctionCall9Coll(flinfo, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +#define OidFunctionCall0(functionId) OidFunctionCall0Coll(functionId, InvalidOid) +#define OidFunctionCall1(functionId, arg1) OidFunctionCall1Coll(functionId, InvalidOid, arg1) +#define OidFunctionCall2(functionId, arg1, arg2) OidFunctionCall2Coll(functionId, InvalidOid, arg1, arg2) +#define OidFunctionCall3(functionId, arg1, arg2, arg3) OidFunctionCall3Coll(functionId, InvalidOid, arg1, arg2, arg3) +#define OidFunctionCall4(functionId, arg1, arg2, arg3, arg4) \ + OidFunctionCall4Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4) +#define OidFunctionCall5(functionId, arg1, arg2, arg3, arg4, arg5) \ + OidFunctionCall5Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5) +#define OidFunctionCall6(functionId, arg1, arg2, arg3, arg4, arg5, arg6) \ + OidFunctionCall6Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6) +#define OidFunctionCall7(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + OidFunctionCall7Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +#define OidFunctionCall8(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + OidFunctionCall8Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) +#define OidFunctionCall9(functionId, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + OidFunctionCall9Coll(functionId, InvalidOid, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + +typedef struct { + PGFunction user_fn; /* the function's address */ + const Pg_finfo_record* inforec; /* address of its info record */ +} CFunInfo; + +/* Special cases for convenient invocation of datatype I/O functions. */ +extern Datum InputFunctionCall(FmgrInfo* flinfo, char* str, Oid typioparam, int32 typmod); +extern Datum InputFunctionCallForDateType( + FmgrInfo* flinfo, char* str, Oid typioparam, int32 typmod, char* date_time_fmt); +extern Datum OidInputFunctionCall(Oid functionId, char* str, Oid typioparam, int32 typmod); +extern char* OutputFunctionCall(FmgrInfo* flinfo, Datum val); +extern char* OidOutputFunctionCall(Oid functionId, Datum val); +extern Datum ReceiveFunctionCall(FmgrInfo* flinfo, fmStringInfo buf, Oid typioparam, int32 typmod); +extern Datum OidReceiveFunctionCall(Oid functionId, fmStringInfo buf, Oid typioparam, int32 typmod); +extern bytea* SendFunctionCall(FmgrInfo* flinfo, Datum val); +extern bytea* OidSendFunctionCall(Oid functionId, Datum val); + +/* + * Routines in fmgr.c + */ +extern const Pg_finfo_record* fetch_finfo_record(void* filehandle, char* funcname, bool isValidate); +extern void clear_external_function_hash(void* filehandle); +extern Oid fmgr_internal_function(const char* proname); +extern Oid get_fn_expr_rettype(FmgrInfo* flinfo); +extern Oid get_fn_expr_argtype(FmgrInfo* flinfo, int argnum); +extern Oid get_call_expr_argtype(fmNodePtr expr, int argnum); +extern bool get_fn_expr_arg_stable(FmgrInfo* flinfo, int argnum); +extern bool get_call_expr_arg_stable(fmNodePtr expr, int argnum); +extern bool get_fn_expr_variadic(FmgrInfo* flinfo); +extern bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid); + +extern void check_external_function(const char* filepath, const char* filename, const char* funcname); +extern CFunInfo load_external_function(const char* filename, char* funcname, bool signalNotFound, bool isValidate); +extern char* expand_dynamic_library_name(const char* name); +extern PGFunction lookup_external_function(void* filehandle, const char* funcname); +extern void load_file(const char* filename, bool restricted); +extern void** find_rendezvous_variable(const char* varName); + +/* + * Support for aggregate functions + * + * This is actually in executor/nodeAgg.c, but we declare it here since the + * whole point is for callers of it to not be overly friendly with nodeAgg. + */ + +/* AggCheckCallContext can return one of the following codes, or 0: */ +#define AGG_CONTEXT_AGGREGATE 1 /* regular aggregate */ +#define AGG_CONTEXT_WINDOW 2 /* window function */ + +extern int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext* aggcontext); + +/* + * We allow plugin modules to hook function entry/exit. This is intended + * as support for loadable security policy modules, which may want to + * perform additional privilege checks on function entry or exit, or to do + * other internal bookkeeping. To make this possible, such modules must be + * able not only to support normal function entry and exit, but also to trap + * the case where we bail out due to an error; and they must also be able to + * prevent inlining. + */ +typedef enum FmgrHookEventType { FHET_START, FHET_END, FHET_ABORT } FmgrHookEventType; + +typedef bool (*needs_fmgr_hook_type)(Oid fn_oid); + +typedef void (*fmgr_hook_type)(FmgrHookEventType event, FmgrInfo* flinfo, Datum* arg); + +extern THR_LOCAL PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook; +extern THR_LOCAL PGDLLIMPORT fmgr_hook_type fmgr_hook; + +#define FmgrHookIsNeeded(fn_oid) (!needs_fmgr_hook ? false : (*needs_fmgr_hook)(fn_oid)) + +// Define common stuff for vectorized expression // +typedef enum SimpleOp { + SOP_EQ, // = + SOP_NEQ, // != + SOP_LE, // <= + SOP_LT, // < + SOP_GE, // >= + SOP_GT, // > +} SimpleOp; + +template +inline bool eval_simple_op(Datatype dataVal1, Datatype dataVal2) +{ + if (sop == SOP_EQ) + return ((dataVal1) == (dataVal2)); + if (sop == SOP_NEQ) + return ((dataVal1) != (dataVal2)); + if (sop == SOP_LE) + return ((dataVal1) <= (dataVal2)); + if (sop == SOP_LT) + return ((dataVal1) < (dataVal2)); + if (sop == SOP_GE) + return ((dataVal1) >= (dataVal2)); + if (sop == SOP_GT) + return ((dataVal1) > (dataVal2)); + return false; +} + +/* + * !!! OLD INTERFACE !!! + * + * fmgr() is the only remaining vestige of the old-style caller support + * functions. It's no longer used anywhere in the Postgres distribution, + * but we should leave it around for a release or two to ease the transition + * for user-supplied C functions. OidFunctionCallN() replaces it for new + * code. + */ + +/* + * DEPRECATED, DO NOT USE IN NEW CODE + */ +extern char* fmgr(Oid procedureId, ...); + +extern Datum DirectCall0(bool* isRetNull, PGFunction func, Oid collation); +extern Datum DirectCall1(bool* isRetNull, PGFunction func, Oid collation, Datum arg1); +extern Datum DirectCall2(bool* isRetNull, PGFunction func, Oid collation, Datum arg1, Datum arg2); +extern Datum DirectCall3(bool* isRetNull, PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3); +extern Datum interval_in(PG_FUNCTION_ARGS); + +#define CHECK_RETNULL_RETURN_DATUM(x) \ + do { \ + _datum = (x); \ + if (_isRetNull) \ + PG_RETURN_NULL(); \ + else \ + return _datum; \ + } while (0) +#define CHECK_RETNULL_CALL0(func, collation) DirectCall0(&_isRetNull, func, collation) +#define CHECK_RETNULL_CALL1(func, collation, arg1) DirectCall1(&_isRetNull, func, collation, arg1) +#define CHECK_RETNULL_CALL2(func, collation, arg1, arg2) DirectCall2(&_isRetNull, func, collation, arg1, arg2) +#define CHECK_RETNULL_CALL3(func, collation, arg1, arg2, arg3) \ + DirectCall3(&_isRetNull, func, collation, arg1, arg2, arg3) +#define CHECK_RETNULL_INIT() \ + Datum _datum; \ + bool _isRetNull = false + +#endif /* !FRONTEND_PARSER */ + +extern void CopyCursorInfoData(Cursor_Data* target_data, Cursor_Data* source_data); + +#endif /* FMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/foreign/dummyserver.h postgresql-hll-2.14/include/include/foreign/dummyserver.h --- postgresql-hll-2.14_old/include/include/foreign/dummyserver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/foreign/dummyserver.h 2020-12-12 17:06:43.191347316 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dummyserver.h + * support for computing pool. The dummy server is used to store the + * connection information of computing pool. + * + * + * IDENTIFICATION + * src/include/foreign/dummyserver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_DUMMYSERVER_H +#define GAUSSDB_FOREIGN_DUMMYSERVER_H + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "utils/hsearch.h" + +#ifndef DUMMY_SERVER +#define DUMMY_SERVER "dummy" +#endif + +/* user name for logging in computing pool. */ +#define OPTION_NAME_USER_NAME "username" +/* password for logging in computing pool. */ +#define OPTION_NAME_PASSWD "password" + +char* getOptionValueFromOptionList(List* optionList, const char* optionName); + +/* + * Store computing pool information in order to connect + * computing pool. + */ +typedef struct DummyServerOptions { + /* the given dummy server oid. it is used to be hash key also. + the server information will store in cache. */ + Oid serverOid; + /*user name of connect computing pool. */ + char* userName; + /* user password of connect computing pool. */ + char* passWord; + char* address; + char* dbname; + char* remoteservername; +} DummyServerOptions; + +/** + * @Description: Get the dummy server options. Currently, only dummy server + * exist in database. + * @return return server options if found it, otherwise return NULL. + */ +DummyServerOptions* getDummyServerOption(); + +/** + * @Description: Init dummy server cache. + * @return none. + */ +void InitDummyServrCache(); + +/** + * @Description: Drop cache when we operator alter server + * or drop server. + * @in serverOid, the server oid to be deleted. + * @return none. + */ +void InvalidDummyServerCache(Oid serverOid); + +/** + * @Description: get dummy server oid from catalog. + * @return return server oid if find one server oid, otherwise return InvalidOid. + */ +Oid getDummyServerOid(); + +/** + * @Description: if the optionList belong to dummy server, we need check the entire + * database. if exists one dummy server, throw error, otherwise do nothing. + * @in optionList, the option list to be checked. + * @return if exists one dummy server in current database, + * throw error, otherwise do nothing. + */ + +void checkExistDummyServer(List* optionList); + +/** + * @Description: jugde a dummy server type by checking server option list. + * @in optionList, the option list to be checked. + * @return + */ +bool isDummyServerByOptions(List* optionList); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/foreign/fdwapi.h postgresql-hll-2.14/include/include/foreign/fdwapi.h --- postgresql-hll-2.14_old/include/include/foreign/fdwapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/foreign/fdwapi.h 2020-12-12 17:06:43.191347316 +0800 @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------------- + * + * fdwapi.h + * API for foreign-data wrappers + * + * Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/foreign/fdwapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FDWAPI_H +#define FDWAPI_H + +#include "nodes/execnodes.h" +#include "nodes/relation.h" +#include "vecexecutor/vectorbatch.h" +#include "vecexecutor/vecnodes.h" +#include "pgstat.h" + +/* To avoid including explain.h here, reference ExplainState thus: */ +struct ExplainState; + +/* + * Callback function signatures --- see fdwhandler.sgml for more info. + */ + +typedef void (*GetForeignRelSize_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); + +typedef void (*GetForeignPaths_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid); + +typedef ForeignScan* (*GetForeignPlan_function)(PlannerInfo* root, RelOptInfo* baserel, Oid foreigntableid, + ForeignPath* best_path, List* tlist, List* scan_clauses); + +typedef void (*BeginForeignScan_function)(ForeignScanState* node, int eflags); + +typedef TupleTableSlot* (*IterateForeignScan_function)(ForeignScanState* node); + +typedef void (*ReScanForeignScan_function)(ForeignScanState* node); + +typedef void (*EndForeignScan_function)(ForeignScanState* node); + +typedef void (*AddForeignUpdateTargets_function)(Query* parsetree, RangeTblEntry* target_rte, Relation target_relation); + +typedef List* (*PlanForeignModify_function)( + PlannerInfo* root, ModifyTable* plan, Index resultRelation, int subplan_index); + +typedef void (*BeginForeignModify_function)( + ModifyTableState* mtstate, ResultRelInfo* rinfo, List* fdw_private, int subplan_index, int eflags); + +typedef TupleTableSlot* (*ExecForeignInsert_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef TupleTableSlot* (*ExecForeignUpdate_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef TupleTableSlot* (*ExecForeignDelete_function)( + EState* estate, ResultRelInfo* rinfo, TupleTableSlot* slot, TupleTableSlot* planSlot); + +typedef void (*EndForeignModify_function)(EState* estate, ResultRelInfo* rinfo); + +typedef int (*IsForeignRelUpdatable_function)(Relation rel); + +typedef void (*ExplainForeignScan_function)(ForeignScanState* node, struct ExplainState* es); + +typedef void (*ExplainForeignModify_function)( + ModifyTableState* mtstate, ResultRelInfo* rinfo, List* fdw_private, int subplan_index, struct ExplainState* es); + +typedef int (*AcquireSampleRowsFunc)(Relation relation, /* relation to be sampled */ + int elevel, /* log level */ + HeapTuple* rows, /* store sampled data */ + int targrows, /* the count of tuples we want to sample */ + double* totalrows, /* the actual count of tuples we sampled */ + double* totaldeadrows, /* totaldeadrows is no means for DFS table */ + void* additionalData, /* We use this parameter to pass data */ + bool estimate_table_rownum); /* wether get sample rows */ + +typedef bool (*AnalyzeForeignTable_function)(Relation relation, /* relation to be analzyed */ + AcquireSampleRowsFunc* func, /* foreign table sampling fucntion point */ + BlockNumber* totalpages, /* total pages in relation, will be set in analzyeforeigntable_function*/ + void* additionalData, /* pass data used by AnalyzeForeignTable function */ + bool estimate_table_rownum); /* wether get sample rows */ + +typedef VectorBatch* (*VecIterateForeignScan_function)(VecForeignScanState* node); + +/* + * @hdfs + * + * GetFdwType_function + * This function is used to return the type of FDW. + * Return value "hdfs_orc" for hdfs orc file. + */ +typedef int (*GetFdwType_function)(); + +typedef void (*ValidateTableDef_function)(Node* Obj); + +typedef void (*TruncateForeignTable_function)(TruncateStmt* stmt, Relation rel); +typedef void (*VacuumForeignTable_function)(VacuumStmt* stmt, Relation rel); +typedef uint64_t (*GetForeignRelationMemSize_function)(Oid reloid, Oid ixoid); +typedef MotMemoryDetail* (*GetForeignMemSize_function)(uint32* nodeCount, bool isGlobal); +typedef MotSessionMemoryDetail* (*GetForeignSessionMemSize_function)(uint32* sessionCount); +typedef void (*NotifyForeignConfigChange_function)(); + +typedef enum { + HDFS_DROP_PARTITIONED_FOREIGNTBL, + HDFS_CREATE_PARTITIONED_FOREIGNTBL, + HDFS_ALTER_PARTITIONED_FOREIGNTBL +} HDFS_PARTTBL_OPERATOR; +typedef void (*PartitionTblProcess_function)(Node* Obj, Oid relid, HDFS_PARTTBL_OPERATOR op); + +typedef enum { + HDFS_BLOOM_FILTER +} HDFS_RUNTIME_PREDICATE; +typedef void (*BuildRuntimePredicate_function)( + ForeignScanState* node, void* value, int colIdx, HDFS_RUNTIME_PREDICATE type); + +/* + * FdwRoutine is the struct returned by a foreign-data wrapper's handler + * function. It provides pointers to the callback functions needed by the + * planner and executor. + * + * More function pointers are likely to be added in the future. Therefore + * it's recommended that the handler initialize the struct with + * makeNode(FdwRoutine) so that all fields are set to NULL. This will + * ensure that no fields are accidentally left undefined. + */ +typedef struct FdwRoutine { + NodeTag type; + + /* Functions for scanning foreign tables */ + GetForeignRelSize_function GetForeignRelSize; + GetForeignPaths_function GetForeignPaths; + GetForeignPlan_function GetForeignPlan; + BeginForeignScan_function BeginForeignScan; + IterateForeignScan_function IterateForeignScan; + ReScanForeignScan_function ReScanForeignScan; + EndForeignScan_function EndForeignScan; + + /* + * These functions are optional. Set the pointer to NULL for any that are + * not provided. + */ + + /* Functions for updating foreign tables */ + AddForeignUpdateTargets_function AddForeignUpdateTargets; + PlanForeignModify_function PlanForeignModify; + BeginForeignModify_function BeginForeignModify; + ExecForeignInsert_function ExecForeignInsert; + ExecForeignUpdate_function ExecForeignUpdate; + ExecForeignDelete_function ExecForeignDelete; + EndForeignModify_function EndForeignModify; + IsForeignRelUpdatable_function IsForeignRelUpdatable; + + /* Support functions for EXPLAIN */ + ExplainForeignScan_function ExplainForeignScan; + ExplainForeignModify_function ExplainForeignModify; + + /* @hdfs Support functions for ANALYZE */ + AnalyzeForeignTable_function AnalyzeForeignTable; + + /* @hdfs Support function for sampling */ + AcquireSampleRowsFunc AcquireSampleRows; + + /* @hdfs Support Vector Interface */ + VecIterateForeignScan_function VecIterateForeignScan; + + /* @hdfs This function is uesed to return the type of FDW */ + GetFdwType_function GetFdwType; + + /* @hdfs Validate table definition */ + ValidateTableDef_function ValidateTableDef; + + /* @hdfs + * Partition foreign table process: create/drop + */ + PartitionTblProcess_function PartitionTblProcess; + + /* @hdfs Runtime dynamic predicate push down like bloom filter. */ + BuildRuntimePredicate_function BuildRuntimePredicate; + + /* Support truncate for foreign table */ + TruncateForeignTable_function TruncateForeignTable; + + /* Support vacuum */ + VacuumForeignTable_function VacuumForeignTable; + + /* Get table/index memory size */ + GetForeignRelationMemSize_function GetForeignRelationMemSize; + + /* Get memory size */ + GetForeignMemSize_function GetForeignMemSize; + + /* Get all session memory size */ + GetForeignSessionMemSize_function GetForeignSessionMemSize; + + /* Notify engine that envelope configuration changed */ + NotifyForeignConfigChange_function NotifyForeignConfigChange; +} FdwRoutine; + +/* Functions in foreign/foreign.c */ +extern FdwRoutine* GetFdwRoutine(Oid fdwhandler); +extern FdwRoutine* GetFdwRoutineByRelId(Oid relid); +extern FdwRoutine* GetFdwRoutineByServerId(Oid serverid); +extern FdwRoutine* GetFdwRoutineForRelation(Relation relation, bool makecopy); + +#endif /* FDWAPI_H */ diff -uprN postgresql-hll-2.14_old/include/include/foreign/foreign.h postgresql-hll-2.14/include/include/foreign/foreign.h --- postgresql-hll-2.14_old/include/include/foreign/foreign.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/foreign/foreign.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,336 @@ +/* ------------------------------------------------------------------------- + * + * foreign.h + * support for foreign-data wrappers, servers and user mappings. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/foreign/foreign.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FOREIGN_H +#define FOREIGN_H + +#include "access/obs/obs_am.h" +#include "commands/defrem.h" +#include "nodes/parsenodes.h" + +#ifndef OBS_SERVER +#define OBS_SERVER "obs" +#endif +#ifndef HDFS_SERVER +#define HDFS_SERVER "hdfs" +#endif + +#define OBS_BUCKET_URL_FORMAT_FLAG ".obs." +#define OBS_PREFIX "obs://" +#define OBS_PREfIX_LEN strlen(OBS_PREFIX) + +/* Defines for valid option names. */ +/* The followings are foreign table options. */ +#define OPTION_NAME_LOCATION "location" +#define OPTION_NAME_FORMAT "format" +#define OPTION_NAME_HEADER "header" +#define OPTION_NAME_DELIMITER "delimiter" +#define OPTION_NAME_QUOTE "quote" +#define OPTION_NAME_ESCAPE "escape" +#define OPTION_NAME_NULL "null" +#define OPTION_NAME_NOESCAPING "noescaping" +#define OPTION_NAME_ENCODING "encoding" +#define OPTION_NAME_FILL_MISSING_FIELDS "fill_missing_fields" +#define OPTION_NAME_IGNORE_EXTRA_DATA "ignore_extra_data" +#define OPTION_NAME_DATE_FORMAT "date_format" +#define OPTION_NAME_TIME_FORMAT "time_format" +#define OPTION_NAME_TIMESTAMP_FORMAT "timestamp_format" +#define OPTION_NAME_SMALLDATETIME_FORMAT "smalldatetime_format" +#define OPTION_NAME_CHUNK_SIZE "chunksize" + +#define OPTION_NAME_FILENAMES "filenames" +#define OPTION_NAME_FOLDERNAME "foldername" +#define OPTION_NAME_CHECK_ENCODING "checkencoding" +#define OPTION_NAME_TOTALROWS "totalrows" + +/* The followings are foreign server options. */ +#define OPTION_NAME_REGION "region" +#define OPTION_NAME_ADDRESS "address" +#define OPTION_NAME_CFGPATH "hdfscfgpath" +#define OPTION_NAME_SERVER_ENCRYPT "encrypt" +#define OPTION_NAME_SERVER_AK "access_key" +#define OPTION_NAME_SERVER_SAK "secret_access_key" +#define OPTION_NAME_SERVER_TYPE "type" +#define OPTION_NAME_DBNAME "dbname" +#define OPTION_NAME_REMOTESERVERNAME "remoteservername" +#define OPTION_NAME_OBSKEY "obskey" + +/* The followings are foreign table option values */ +#define MAX_TOTALROWS LONG_MAX +#define MIN_TOTALROWS 1 + +/* Helper for obtaining username for user mapping */ +#define MappingUserName(userid) (OidIsValid(userid) ? GetUserNameFromId(userid) : "public") + +#define DFS_FORMAT_TEXT "text" +#define DFS_FORMAT_CSV "csv" +#define DFS_FORMAT_ORC "orc" +#define DFS_FORMAT_PARQUET "parquet" +#define DFS_FORMAT_CARBONDATA "carbondata" + +typedef enum DFSFileType { + DFS_INVALID = -1, + DFS_ORC = 0, + DFS_PARQUET = 1, + DFS_TEXT = 2, + DFS_CSV = 3, + DFS_CARBONDATA = 4 +} DFSFileType; + +/* + * Generic option types for validation. + * NB! Thes are treated as flags, so use only powers of two here. + */ +typedef enum { + ServerOpt = 1, /* options applicable to SERVER */ + UserMappingOpt = 2, /* options for USER MAPPING */ + FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */ +} GenericOptionFlags; + +typedef struct ForeignDataWrapper { + Oid fdwid; /* FDW Oid */ + Oid owner; /* FDW owner user Oid */ + char* fdwname; /* Name of the FDW */ + Oid fdwhandler; /* Oid of handler function, or 0 */ + Oid fdwvalidator; /* Oid of validator function, or 0 */ + List* options; /* fdwoptions as DefElem list */ +} ForeignDataWrapper; + +typedef struct ForeignServer { + Oid serverid; /* server Oid */ + Oid fdwid; /* foreign-data wrapper */ + Oid owner; /* server owner user Oid */ + char* servername; /* name of the server */ + char* servertype; /* server type, optional */ + char* serverversion; /* server version, optional */ + List* options; /* srvoptions as DefElem list */ +} ForeignServer; + +typedef struct UserMapping { + Oid userid; /* local user Oid */ + Oid serverid; /* server Oid */ + List* options; /* useoptions as DefElem list */ +} UserMapping; + +typedef struct ForeignTable { + Oid relid; /* relation Oid */ + Oid serverid; /* server Oid */ + List* options; /* ftoptions as DefElem list */ + bool write_only; /* is relation updatable ? */ +} ForeignTable; + +/* + *HdfsServerAddress keeps foreign server ip and port + */ +typedef struct HdfsServerAddress { + char* HdfsIp; + char* HdfsPort; +} HdfsServerAddress; + +/* Define the server type enum in order to realize some function interface. */ +typedef enum ServerTypeOption { + T_INVALID = 0, + T_OBS_SERVER, + T_HDFS_SERVER, + T_MOT_SERVER, + T_DUMMY_SERVER, + T_TXT_CSV_OBS_SERVER, /* mark the txt/csv foramt OBS foreign server. the fdw + is dist_fdw. */ + T_PGFDW_SERVER +} ServerTypeOption; + +/* + * This struct store the foreign table options for computing pool. + */ +typedef struct ForeignOptions { + NodeTag type; + + ServerTypeOption stype; + + /* it store the all foreign options. */ + List* fOptions; +} ForeignOptions; + +/* + * HdfsFdwOptions holds the option values to be used when reading and parsing + * the orc file. To resolve these values, we first check foreign table's + * options, and if not present, we then fall back to the default values + * specified above. + */ +typedef struct HdfsFdwOptions { + char* foldername; + char* filename; + char* address; + int port; + char* location; +} HdfsFdwOptions; + +typedef struct HdfsOptions { + char* servername; + char* format; +} HdfsOptions; + +extern int find_Nth(const char* str, unsigned N, const char* find); + +extern ForeignServer* GetForeignServer(Oid serverid); +extern ForeignServer* GetForeignServerByName(const char* name, bool missing_ok); +extern UserMapping* GetUserMapping(Oid userid, Oid serverid); +extern ForeignDataWrapper* GetForeignDataWrapper(Oid fdwid); +extern ForeignDataWrapper* GetForeignDataWrapperByName(const char* name, bool missing_ok); +extern ForeignTable* GetForeignTable(Oid relid); + +extern List* GetForeignColumnOptions(Oid relid, AttrNumber attnum); + +extern Oid get_foreign_data_wrapper_oid(const char* fdwname, bool missing_ok); +extern Oid get_foreign_server_oid(const char* servername, bool missing_ok); + +extern DefElem* GetForeignTableOptionByName(Oid reloid, const char* optname); +extern bool IsSpecifiedFDW(const char* ServerName, const char* SepcifiedType); +extern char* getServerOptionValue(Oid srvOid, const char* optionName); + +// foreign table option values +DefElem* HdfsGetOptionDefElem(Oid foreignTableId, const char* optionName); + +extern char* getFTOptionValue(List* option_list, const char* option_name); +extern DefElemAction getFTAlterAction(List* option_list, const char* option_name); + +extern DefElem* getFTOptionDefElemFromList(List* optionList, const char* optionName); + +extern double convertFTOptionValue(const char* s); +extern char* GetForeignServerName(Oid serverid); +extern ColumnDef* makeColumnDef(const char* colname, char* coltype); + +/** + * @Description: Jude whether type of the foreign table equal to the specified type or not. + * @in relId: The foreign table Oid. + * @in SepcifiedType: The given type of foreign table. + * @return If the relation type equal to the given type of foreign table, return true, + * otherwise return false. + */ +extern bool IsSpecifiedFDWFromRelid(Oid relId, const char* SepcifiedType); + +/** + * @Description: Jude whether type of the foreign table support SELECT/INSERT/UPDATE/DELETE/COPY + * @in relId: The foreign table Oid. + * @return Rreturn true if the foreign table support those DML. + */ +extern bool CheckSupportedFDWType(Oid relId); + +/** + * @Description: Get the all options for the OBS foreign table. + * we store the option into ObsOptions. + * @in foreignTable, the foreign table oid. + * @return return all options. + */ +extern ObsOptions* getObsOptions(Oid foreignTableId); + +/* + * brief: Creates and returns the option values to be used. + * input param @foreignTableId: Oid of the foreign tableId. + */ +HdfsFdwOptions* HdfsGetOptions(Oid foreignTableId); + +bool isSpecifiedSrvTypeFromRelId(Oid relId, const char* SepcifiedType); +bool isSpecifiedSrvTypeFromSrvName(const char* srvName, const char* SepcifiedType); + +/** + * @Description: Currently, two OBS location format support in database. + * one format is "gsobs:://obsdomain/bucket/prefix", another is "gsobs:://bucket.obsdomain/prefix". + * we adjust second format to the first format, we only deal with the first format in parse phase. + * @in optionsList, if the list include location option, we will adjust format. + * @return return new optionsList. + */ +List* regularizeObsLocationInfo(List* optionsList); + +char* rebuildAllLocationOptions(char* regionCode, char* location); + +/** + * @Description: If using the region option, we must to reset location option + * with region string, eg. obs://bucket/prefix ->obs://URL/prefix/bucket. + * @in option List tobe given. + * @return return the modified option. + */ +List* adaptOBSURL(List* list); + +/** + * @Description: Currently, two OBS location format support in database. + * one format is "gsobs:://obsdomain/bucket/prefix", another is "gsobs:://bucket.obsdomain/prefix". + * we adjust second format to the first format, we only deal with the first format in parse phase. + * @in sourceStr, if the list include location option, we will adjust format. + * @return return new location string. + */ +char* adjustObsLocationInfoOrder(char* sourceStr); + +/* + * brief: Get the value of the given option name by traversing + * foreign table and foreign server options. Return the + * value of the given option, if found. Otherwise, return NULL; + * input param @foreignTableId: Oid of the foreign tableId; + * input param @optionName: name of the option. + */ +char* HdfsGetOptionValue(Oid foreignTableId, const char* optionName); +ServerTypeOption getServerType(Oid foreignTableId); +List* getFdwOptions(Oid foreignTableId); +int getSpecialCharCnt(const char* path, const char specialChar); +ObsOptions* setObsSrvOptions(ForeignOptions* fOptions); +HdfsOptions* setHdfsSrvOptions(ForeignOptions* fOptions); + +bool isWriteOnlyFt(Oid relid); + +#define isObsOrHdfsTableFormTblOid(relId) \ + (isSpecifiedSrvTypeFromRelId(relId, HDFS) || isSpecifiedSrvTypeFromRelId(relId, OBS)) + +#define isMOTFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, MOT_FDW)) + +#define isObsOrHdfsTableFormSrvName(srvName) \ + (isSpecifiedSrvTypeFromSrvName(srvName, HDFS) || isSpecifiedSrvTypeFromSrvName(srvName, OBS)) + +#define isMOTTableFromSrvName(srvName) \ + (IsSpecifiedFDW(srvName, MOT_FDW)) + +#define isPostgresFDWFromSrvName(srvName) \ + (IsSpecifiedFDW(srvName, POSTGRES_FDW)) + +#define isMysqlFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, MYSQL_FDW)) + +#define isOracleFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, ORACLE_FDW)) + +#define isPostgresFDWFromTblOid(relId) \ + (IsSpecifiedFDWFromRelid(relId, POSTGRES_FDW)) + +#define IS_OBS_CSV_TXT_FOREIGN_TABLE(relId) \ + (IsSpecifiedFDWFromRelid(relId, DIST_FDW) && (is_obs_protocol(HdfsGetOptionValue(relId, optLocation)))) + +#define CAN_BUILD_INFORMATIONAL_CONSTRAINT_BY_RELID(relId) \ + (isObsOrHdfsTableFormTblOid(relId) || IS_OBS_CSV_TXT_FOREIGN_TABLE(relId)) + +#define CAN_BUILD_INFORMATIONAL_CONSTRAINT_BY_STMT(stmt) \ + (isObsOrHdfsTableFormSrvName(stmt->servername) || \ + (NULL == getFTOptionValue(stmt->options, optLocation) \ + ? false \ + : is_obs_protocol(getFTOptionValue(stmt->options, optLocation)))) + +#define IS_LOGFDW_FOREIGN_TABLE(relId) (IsSpecifiedFDWFromRelid(relId, LOG_FDW)) + +#define IS_POSTGRESFDW_FOREIGN_TABLE(relId) (IsSpecifiedFDWFromRelid(relId, GC_FDW)) + +#define ENCRYPT_STR_PREFIX "encryptstr" +#define MIN_ENCRYPTED_PASSWORD_LENGTH 54 + +#define isEncryptedPassword(passwd) \ + (strncmp(passwd, ENCRYPT_STR_PREFIX, strlen(ENCRYPT_STR_PREFIX)) == 0 && \ + strlen(passwd) >= MIN_ENCRYPTED_PASSWORD_LENGTH) + +#endif /* FOREIGN_H */ diff -uprN postgresql-hll-2.14_old/include/include/foreign/metainformation.h postgresql-hll-2.14/include/include/foreign/metainformation.h --- postgresql-hll-2.14_old/include/include/foreign/metainformation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/foreign/metainformation.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * metainformation.h + * support interface for pushdown metainformation. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/foreign/metainformation.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_METAINFORMATION +#define GAUSSDB_FOREIGN_METAINFORMATION + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "foreign/foreign.h" +#include "utils/hsearch.h" + +ForeignOptions* setForeignOptions(Oid relid); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/foreign/regioninfo.h postgresql-hll-2.14/include/include/foreign/regioninfo.h --- postgresql-hll-2.14_old/include/include/foreign/regioninfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/foreign/regioninfo.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,24 @@ +/* --------------------------------------------------------------------------------------- + * + * regioninfo.h + * support the obs foreign table, we get the region info from + * the region_map file, and clean the region info in database. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/foreign/regioninfo.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAUSSDB_FOREIGN_REGIION_INFO +#define GAUSSDB_FOREIGN_REGIION_INFO + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "commands/defrem.h" +#include "nodes/parsenodes.h" + +char* readDataFromJsonFile(char* region); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/funcapi.h postgresql-hll-2.14/include/include/funcapi.h --- postgresql-hll-2.14_old/include/include/funcapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/funcapi.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,286 @@ +/* ------------------------------------------------------------------------- + * + * funcapi.h + * Definitions for functions which return composite type and/or sets + * + * This file must be included by all Postgres modules that either define + * or call FUNCAPI-callable functions or macros. + * + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * src/include/funcapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FUNCAPI_H +#define FUNCAPI_H + +#include "fmgr.h" +#include "access/tupdesc.h" +#include "executor/executor.h" +#include "executor/tuptable.h" + +/* ------------------------------------------------------------------------- + * Support to ease writing Functions returning composite types + * ------------------------------------------------------------------------- + * + * This struct holds arrays of individual attribute information + * needed to create a tuple from raw C strings. It also requires + * a copy of the TupleDesc. The information carried here + * is derived from the TupleDesc, but it is stored here to + * avoid redundant cpu cycles on each call to an SRF. + */ +typedef struct AttInMetadata { + /* full TupleDesc */ + TupleDesc tupdesc; + + /* array of attribute type input function finfo */ + FmgrInfo* attinfuncs; + + /* array of attribute type i/o parameter OIDs */ + Oid* attioparams; + + /* array of attribute typmod */ + int32* atttypmods; +} AttInMetadata; + +/* ------------------------------------------------------------------------- + * Support struct to ease writing Set Returning Functions (SRFs) + * ------------------------------------------------------------------------- + * + * This struct holds function context for Set Returning Functions. + * Use fn_extra to hold a pointer to it across calls + */ +typedef struct FuncCallContext { + /* + * Number of times we've been called before + * + * call_cntr is initialized to 0 for you by SRF_FIRSTCALL_INIT(), and + * incremented for you every time SRF_RETURN_NEXT() is called. + */ + uint32 call_cntr; + + /* + * OPTIONAL maximum number of calls + * + * max_calls is here for convenience only and setting it is optional. If + * not set, you must provide alternative means to know when the function + * is done. + */ + uint32 max_calls; + + /* + * OPTIONAL pointer to result slot + * + * This is obsolete and only present for backwards compatibility, viz, + * user-defined SRFs that use the deprecated TupleDescGetSlot(). + */ + TupleTableSlot* slot; + + /* + * OPTIONAL pointer to miscellaneous user-provided context information + * + * user_fctx is for use as a pointer to your own struct to retain + * arbitrary context information between calls of your function. + */ + void* user_fctx; + + /* + * OPTIONAL pointer to struct containing attribute type input metadata + * + * attinmeta is for use when returning tuples (i.e. composite data types) + * and is not used when returning base data types. It is only needed if + * you intend to use BuildTupleFromCStrings() to create the return tuple. + */ + AttInMetadata* attinmeta; + + /* + * memory context used for structures that must live for multiple calls + * + * multi_call_memory_ctx is set by SRF_FIRSTCALL_INIT() for you, and used + * by SRF_RETURN_DONE() for cleanup. It is the most appropriate memory + * context for any memory that is to be reused across multiple calls of + * the SRF. + */ + MemoryContext multi_call_memory_ctx; + + /* + * OPTIONAL pointer to struct containing tuple description + * + * tuple_desc is for use when returning tuples (i.e. composite data types) + * and is only needed if you are going to build the tuples with + * heap_form_tuple() rather than with BuildTupleFromCStrings(). Note that + * the TupleDesc pointer stored here should usually have been run through + * BlessTupleDesc() first. + */ + TupleDesc tuple_desc; + +} FuncCallContext; + +/* ---------- + * Support to ease writing functions returning composite types + * + * External declarations: + * get_call_result_type: + * Given a function's call info record, determine the kind of datatype + * it is supposed to return. If resultTypeId isn't NULL, *resultTypeId + * receives the actual datatype OID (this is mainly useful for scalar + * result types). If resultTupleDesc isn't NULL, *resultTupleDesc + * receives a pointer to a TupleDesc when the result is of a composite + * type, or NULL when it's a scalar result or the rowtype could not be + * determined. NB: the tupledesc should be copied if it is to be + * accessed over a long period. + * get_expr_result_type: + * Given an expression node, return the same info as for + * get_call_result_type. Note: the cases in which rowtypes cannot be + * determined are different from the cases for get_call_result_type. + * get_func_result_type: + * Given only a function's OID, return the same info as for + * get_call_result_type. Note: the cases in which rowtypes cannot be + * determined are different from the cases for get_call_result_type. + * Do *not* use this if you can use one of the others. + * ---------- + */ + +/* Type categories for get_call_result_type and siblings */ +typedef enum TypeFuncClass { + TYPEFUNC_SCALAR, /* scalar result type */ + TYPEFUNC_COMPOSITE, /* determinable rowtype result */ + TYPEFUNC_RECORD, /* indeterminate rowtype result */ + TYPEFUNC_OTHER /* bogus type, eg pseudotype */ +} TypeFuncClass; + +extern TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid* resultTypeId, TupleDesc* resultTupleDesc); +extern TypeFuncClass get_expr_result_type(Node* expr, Oid* resultTypeId, TupleDesc* resultTupleDesc); +extern TypeFuncClass get_func_result_type(Oid functionId, Oid* resultTypeId, TupleDesc* resultTupleDesc); + +extern bool resolve_polymorphic_argtypes(int numargs, Oid* argtypes, const char* argmodes, Node* call_expr); + +extern int get_func_arg_info(HeapTuple procTup, Oid** p_argtypes, char*** p_argnames, char** p_argmodes); + +extern int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char*** arg_names); + +extern char* get_func_result_name(Oid functionId); + +extern TupleDesc build_function_result_tupdesc_d(Datum proallargtypes, Datum proargmodes, Datum proargnames); +extern TupleDesc build_function_result_tupdesc_t(HeapTuple procTuple); + +/* ---------- + * Support to ease writing functions returning composite types + * + * External declarations: + * TupleDesc BlessTupleDesc(TupleDesc tupdesc) - "Bless" a completed tuple + * descriptor so that it can be used to return properly labeled tuples. + * You need to call this if you are going to use heap_form_tuple directly. + * TupleDescGetAttInMetadata does it for you, however, so no need to call + * it if you call TupleDescGetAttInMetadata. + * AttInMetadata *TupleDescGetAttInMetadata(TupleDesc tupdesc) - Build an + * AttInMetadata struct based on the given TupleDesc. AttInMetadata can + * be used in conjunction with C strings to produce a properly formed + * tuple. + * HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) - + * build a HeapTuple given user data in C string form. values is an array + * of C strings, one for each attribute of the return tuple. + * + * Macro declarations: + * HeapTupleGetDatum(HeapTuple tuple) - convert a HeapTuple to a Datum. + * + * Obsolete routines and macros: + * TupleDesc RelationNameGetTupleDesc(const char *relname) - Use to get a + * TupleDesc based on a named relation. + * TupleDesc TypeGetTupleDesc(Oid typeoid, List *colaliases) - Use to get a + * TupleDesc based on a type OID. + * TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc) - Builds a + * TupleTableSlot, which is not needed anymore. + * TupleGetDatum(TupleTableSlot *slot, HeapTuple tuple) - get a Datum + * given a tuple and a slot. + * ---------- + */ + +#define HeapTupleGetDatum(_tuple) PointerGetDatum((_tuple)->t_data) +/* obsolete version of above */ +#define TupleGetDatum(_slot, _tuple) PointerGetDatum((_tuple)->t_data) + +extern TupleDesc RelationNameGetTupleDesc(const char* relname); +extern TupleDesc TypeGetTupleDesc(Oid typeoid, List* colaliases); + +/* from execTuples.c */ +extern TupleDesc BlessTupleDesc(TupleDesc tupdesc); +extern AttInMetadata* TupleDescGetAttInMetadata(TupleDesc tupdesc); +extern HeapTuple BuildTupleFromCStrings(AttInMetadata* attinmeta, char** values); +extern TupleTableSlot* TupleDescGetSlot(TupleDesc tupdesc); + +/* ---------- + * Support for Set Returning Functions (SRFs) + * + * The basic API for SRFs looks something like: + * + * Datum + * my_Set_Returning_Function(PG_FUNCTION_ARGS) + * { + * FuncCallContext *funcctx; + * Datum result; + * MemoryContext oldcontext; + * + * + * if (SRF_IS_FIRSTCALL()) + * { + * funcctx = SRF_FIRSTCALL_INIT(); + * // switch context when allocating stuff to be used in later calls + * oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + * + * + * + * + * + * // return to original context when allocating transient memory + * MemoryContextSwitchTo(oldcontext); + * } + * + * funcctx = SRF_PERCALL_SETUP(); + * + * + * if (funcctx->call_cntr < funcctx->max_calls) + * { + * + * + * SRF_RETURN_NEXT(funcctx, result); + * } + * else + * SRF_RETURN_DONE(funcctx); + * } + * + * ---------- + */ + +/* from funcapi.c */ +extern FuncCallContext* init_MultiFuncCall(PG_FUNCTION_ARGS); +extern FuncCallContext* per_MultiFuncCall(PG_FUNCTION_ARGS); +extern void end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext* funcctx); + +#define SRF_IS_FIRSTCALL() (fcinfo->flinfo->fn_extra == NULL) + +#define SRF_FIRSTCALL_INIT() init_MultiFuncCall(fcinfo) + +#define SRF_PERCALL_SETUP() per_MultiFuncCall(fcinfo) + +#define SRF_RETURN_NEXT(_funcctx, _result) \ + do { \ + ReturnSetInfo* rsi; \ + (_funcctx)->call_cntr++; \ + rsi = (ReturnSetInfo*)fcinfo->resultinfo; \ + rsi->isDone = ExprMultipleResult; \ + PG_RETURN_DATUM(_result); \ + } while (0) + +#define SRF_RETURN_DONE(_funcctx) \ + do { \ + ReturnSetInfo* rsi; \ + end_MultiFuncCall(fcinfo, _funcctx); \ + rsi = (ReturnSetInfo*)fcinfo->resultinfo; \ + rsi->isDone = ExprEndResult; \ + PG_RETURN_NULL(); \ + } while (0) + +#endif /* FUNCAPI_H */ diff -uprN postgresql-hll-2.14_old/include/include/gaussdb_version.h postgresql-hll-2.14/include/include/gaussdb_version.h --- postgresql-hll-2.14_old/include/include/gaussdb_version.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gaussdb_version.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,65 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gaussdb_version.h + * Definitions for the Gaussdb features check + * + * + * IDENTIFICATION + * src/include/gaussdb_version.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GAUSSDB_VERSION_H_INCLUDED +#define GAUSSDB_VERSION_H_INCLUDED + +typedef enum { + MULTI_VALUE_COLUMN = 0, + JSON, + XML, + DATA_STORAGE_FORMAT, + GTM_FREE, + DOUBLE_LIVE_DISASTER_RECOVERY_IN_THE_SAME_CITY, + DISASTER_RECOVERY_IN_TWO_PLACES_AND_THREE_CENTRES, + GPU_ACCELERATION_IN_MULTIDIMENSIONAL_COLLISION_ANALYSIS, + FULL_TEXT_INDEX, + EXTENSION_CONNECTOR, + SQL_ON_HDFS, + SQL_ON_OBS, + EXPRESS_CLUSTER, + CROSS_DC_COLLABORATION, + GRAPH_COMPUTING_ENGINE, + SEQUENTIAL_DATA_ENGINE, + POSTGIS_DOCKING, + HA_SINGLE_PRIMARY_MULTI_STANDBY, + ROW_LEVEL_SECURITY, + TRANSPARENT_ENCRYPTION, + PRIVATE_TABLE, + FEATURE_NAME_MAX_VALUE // Must be the last one +} feature_name; + +/* Product version number is unknown. */ +#define PRODUCT_VERSION_UNKNOWN ((uint32)0) +/* GaussDB 200 product version number. */ +#define PRODUCT_VERSION_GAUSSDB200 ((uint32)2) +/* GaussDB 300 product version number. */ +#define PRODUCT_VERSION_GAUSSDB300 ((uint32)3) + +extern void initialize_feature_flags(); +extern bool is_feature_disabled(feature_name); +extern void signalReloadLicenseHandler(int sig); +extern uint32 get_product_version(); +#endif // GAUSSDB_VERSION_H_INCLUDED diff -uprN postgresql-hll-2.14_old/include/include/gen_alloc.h postgresql-hll-2.14/include/include/gen_alloc.h --- postgresql-hll-2.14_old/include/include/gen_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gen_alloc.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * gen_alloc.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gen_alloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GEN_ALLOC_H +#define GEN_ALLOC_H + +/* + * Common memory allocation binary interface both for Postgres and GTM processes. + * Especially needed by gtm_serialize.c and gtm_serialize_debug.c + */ +typedef struct Gen_Alloc { + void* (*alloc)(void*, size_t); + void* (*alloc0)(void*, size_t); + void* (*realloc)(void*, size_t); + void (*free)(void*); + void* (*current_memcontext)(void); + void* (*allocTop)(size_t); +} Gen_Alloc; + +extern Gen_Alloc genAlloc_class; + +#define genAlloc(x) genAlloc_class.alloc(genAlloc_class.current_memcontext(), x) +#define genRealloc(x, y) genAlloc_class.realloc(x, y) +#define genFree(x) genAlloc_class.free(x) +#define genAlloc0(x) genAlloc_class.alloc0(genAlloc_class.current_memcontext(), x) +#define genAllocTop(x) genAlloc_class.allocTop(x) + +#endif /* GEN_ALLOC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/getaddrinfo.h postgresql-hll-2.14/include/include/getaddrinfo.h --- postgresql-hll-2.14_old/include/include/getaddrinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/getaddrinfo.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------------- + * + * getaddrinfo.h + * Support getaddrinfo() on platforms that don't have it. + * + * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO, + * whether or not the library routine getaddrinfo() can be found. This + * policy is needed because on some platforms a manually installed libbind.a + * may provide getaddrinfo(), yet the system headers may not provide the + * struct definitions needed to call it. To avoid conflict with the libbind + * definition in such cases, we rename our routines to pg_xxx() via macros. + * + * This code will also work on platforms where struct addrinfo is defined + * in the system headers but no getaddrinfo() can be located. + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/getaddrinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GETADDRINFO_H +#define GETADDRINFO_H + +#include +#include + +/* Various macros that ought to be in , but might not be */ + +#ifndef EAI_FAIL +#ifndef WIN32 +#define EAI_BADFLAGS (-1) +#define EAI_NONAME (-2) +#define EAI_AGAIN (-3) +#define EAI_FAIL (-4) +#define EAI_FAMILY (-6) +#define EAI_SOCKTYPE (-7) +#define EAI_SERVICE (-8) +#define EAI_MEMORY (-10) +#define EAI_SYSTEM (-11) +#else /* WIN32 */ +#ifdef WIN32_ONLY_COMPILER +#ifndef WSA_NOT_ENOUGH_MEMORY +#define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS) +#endif +#ifndef __BORLANDC__ +#define WSATYPE_NOT_FOUND (WSABASEERR + 109) +#endif +#endif +#define EAI_AGAIN WSATRY_AGAIN +#define EAI_BADFLAGS WSAEINVAL +#define EAI_FAIL WSANO_RECOVERY +#define EAI_FAMILY WSAEAFNOSUPPORT +#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY +#define EAI_NODATA WSANO_DATA +#define EAI_NONAME WSAHOST_NOT_FOUND +#define EAI_SERVICE WSATYPE_NOT_FOUND +#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT +#endif /* !WIN32 */ +#endif /* !EAI_FAIL */ + +#ifndef AI_PASSIVE +#define AI_PASSIVE 0x0001 +#endif + +#ifndef AI_NUMERICHOST +/* + * some platforms don't support AI_NUMERICHOST; define as zero if using + * the system version of getaddrinfo... + */ +#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) +#define AI_NUMERICHOST 0 +#else +#define AI_NUMERICHOST 0x0004 +#endif +#endif + +#ifndef NI_NUMERICHOST +#define NI_NUMERICHOST 1 +#endif +#ifndef NI_NUMERICSERV +#define NI_NUMERICSERV 2 +#endif + +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif + +#ifndef NI_MAXSERV +#define NI_MAXSERV 32 +#endif + +#ifndef HAVE_STRUCT_ADDRINFO + +#ifndef WIN32 +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr* ai_addr; + char* ai_canonname; + struct addrinfo* ai_next; +}; +#else +/* + * The order of the structure elements on Win32 doesn't match the + * order specified in the standard, but we have to match it for + * IPv6 to work. + */ +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + char* ai_canonname; + struct sockaddr* ai_addr; + struct addrinfo* ai_next; +}; +#endif +#endif /* HAVE_STRUCT_ADDRINFO */ + +#ifndef HAVE_GETADDRINFO + +/* Rename private copies per comments above */ +#ifdef getaddrinfo +#undef getaddrinfo +#endif +#define getaddrinfo pg_getaddrinfo + +#ifdef freeaddrinfo +#undef freeaddrinfo +#endif +#define freeaddrinfo pg_freeaddrinfo + +#ifdef gai_strerror +#undef gai_strerror +#endif +#define gai_strerror pg_gai_strerror + +#ifdef getnameinfo +#undef getnameinfo +#endif +#define getnameinfo pg_getnameinfo + +extern int getaddrinfo(const char* node, const char* service, const struct addrinfo* hints, struct addrinfo** res); +extern void freeaddrinfo(struct addrinfo* res); +extern const char* gai_strerror(int errcode); +extern int getnameinfo( + const struct sockaddr* sa, int salen, char* node, int nodelen, char* service, int servicelen, int flags); +#endif /* HAVE_GETADDRINFO */ + +#endif /* GETADDRINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/getopt_long.h postgresql-hll-2.14/include/include/getopt_long.h --- postgresql-hll-2.14_old/include/include/getopt_long.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/getopt_long.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,41 @@ +/* + * Portions Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Portions Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/getopt_long.h + */ +#ifndef GETOPT_LONG_H +#define GETOPT_LONG_H + +#ifdef HAVE_GETOPT_H +#include +#endif + +/* These are picked up from the system's getopt() facility. */ +extern int opterr; +extern int optind; +extern int optopt; +extern char* optarg; + +#ifndef HAVE_STRUCT_OPTION + +struct option { + const char* name; + int has_arg; + int* flag; + int val; +}; + +#define no_argument 0 +#define required_argument 1 +#endif + +#ifndef HAVE_GETOPT_LONG + +extern int getopt_long( + int argc, char* const argv[], const char* optstring, const struct option* longopts, int* longindex); +#endif + +#endif /* GETOPT_LONG_H */ diff -uprN postgresql-hll-2.14_old/include/include/gs_bbox.h postgresql-hll-2.14/include/include/gs_bbox.h --- postgresql-hll-2.14_old/include/include/gs_bbox.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_bbox.h 2020-12-12 17:06:43.192347329 +0800 @@ -0,0 +1,128 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_bbox.h + * + * IDENTIFICATION + * src/include/gs_bbox.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_BBOX_H__ +#define __GS_BBOX_H__ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "utils/guc.h" + +/* + * all kinds of blacklist items. + * + * NOTE: at most 64 different blacklist items are supported now. We can enlarge this upper limits + * by changing g_instance.attr.attr_common.bbox_blacklist_mask from uint64 to Bitmap. + */ +typedef enum { + SHARED_BUFFER = 0, + XLOG_BUFFER, + DW_BUFFER, + XLOG_MESSAGE_SEND, + DATA_MESSAGE_SEND, + WALRECIVER_CTL_BLOCK, + DATA_WRITER_QUEUE +} BlacklistIndex; + +/* blacklist item */ +typedef struct { + /* blacklist item's ID */ + BlacklistIndex blacklist_ID; + + /* blacklist item's name */ + char *blacklist_name; + + /* whether or not only added by postmaster. */ + bool pm_only; +} BlacklistItem; + +/* all information about blacklist items. */ +extern BlacklistItem g_blacklist_items[]; + +/* whether or not bbox is enabled. */ +#define BBOX_ENABLED (u_sess->attr.attr_common.enable_bbox_dump) + +/* fetch instance's blacklist items' mask. */ +#define BBOX_BLACKLIST (g_instance.attr.attr_common.bbox_blacklist_mask) + +/* fetch one blacklist item's bits mask by ID (internal) */ +#define BLACKLIST_ITEM_MASK(blacklist_ID) ((uint64)1 << (unsigned int)(blacklist_ID)) + +/* t_thrd.storage_cxt.BufferBlocks */ +#define BBOX_BLACKLIST_SHARE_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(SHARED_BUFFER))) + +/* t_thrd.shemem_ptr_cxt.XLogCtl->pages */ +#define BBOX_BLACKLIST_XLOG_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(XLOG_BUFFER))) + +/* g_instance.dw_batch_cxt.buf */ +#define BBOX_BLACKLIST_DW_BUFFER (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DW_BUFFER))) + +/* t_thrd.walsender_cxt.output_xlog_message*/ +#define BBOX_BLACKLIST_XLOG_MESSAGE_SEND (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(XLOG_MESSAGE_SEND))) + +/* t_thrd.datasender_cxt.output_message */ +#define BBOX_BLACKLIST_DATA_MESSAGE_SEND (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DATA_MESSAGE_SEND))) + +/* t_thrd.walreceiver_cxt.walRcvCtlBlock */ +#define BBOX_BLACKLIST_WALREC_CTL_BLOCK (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(WALRECIVER_CTL_BLOCK))) + +/*t_thrd.dataqueue_cxt.DataWriterQueue*/ +#define BBOX_BLACKLIST_DATA_WRITER_QUEUE (BBOX_ENABLED && (BBOX_BLACKLIST & BLACKLIST_ITEM_MASK(DATA_WRITER_QUEUE))) + +// t_thrd.walsender_cxt.output_data_message, LogicalDecodingContext + +// t_thrd.libwalreceiver_cxt.recvBuf (malloc each time) +// t_thrd.datareceiver_cxt.recvBuf +// XLogReaderState->readbuf + +#ifdef ENABLE_UT +#include "../gausskernel/cbb/bbox/bbox.h" +extern int bbox_handler_exit; +extern void bbox_handler(SIGNAL_ARGS); +extern s32 BBOX_CreateCoredump(char* file_name); +#endif + +/* do initilaization for dumping core file */ +extern void bbox_initialize(); + +/* add an blacklist item to exclude it from core file. */ +extern void bbox_blacklist_add(BlacklistIndex item, void *addr, uint64 size); + +/* remove an blacklist item. */ +extern void bbox_blacklist_remove(BlacklistIndex item, void *addr); + +/* for GUC parameter - bbox_dump_path */ +extern bool check_bbox_corepath(char** newval, void** extra, GucSource source); +extern void assign_bbox_corepath(const char* newval, void* extra); +extern const char* show_bbox_dump_path(void); + +/* for GUC parameter - bbox_blanklist_items */ +extern bool check_bbox_blacklist(char** newval, void** extra, GucSource source); +extern void assign_bbox_blacklist(const char* newval, void* extra); +extern const char* show_bbox_blacklist(); + +/* for GUC parameter - enable_bbox_dump */ +extern void assign_bbox_coredump(const bool newval, void* extra); +extern int CheckFilenameValid(const char* inputEnvValue); +#endif + diff -uprN postgresql-hll-2.14_old/include/include/gs_ktool/kt_interface.h postgresql-hll-2.14/include/include/gs_ktool/kt_interface.h --- postgresql-hll-2.14_old/include/include/gs_ktool/kt_interface.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_ktool/kt_interface.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + *------------------------------------------------------------------------- + * + * kt_interface.cpp + * APIs for Encrypted Database. + * + * IDENTIFICATION + * src/bin/gs_ktool/kt_interface.cpp + * + *------------------------------------------------------------------------- + */ + +#ifndef KT_INTERFACE_H +#define KT_INTERFACE_H + +#include +#include +#include + +extern bool get_cmk_len(unsigned int cmk_id, unsigned int *cmk_len); +extern bool get_cmk_plain(unsigned int cmk_id, unsigned char *cmk_plain_buffer, unsigned int *cmk_len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/curl_utils.h postgresql-hll-2.14/include/include/gs_policy/curl_utils.h --- postgresql-hll-2.14_old/include/include/gs_policy/curl_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/curl_utils.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * CurlUtils.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/gs_policy/CurlUtils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SRC_LIBS_LIBCURL_CURLUTILS_H_ +#define SRC_LIBS_LIBCURL_CURLUTILS_H_ + +#include +#include +#include "curl/curl.h" + +class CurlUtils +{ +public: + CurlUtils(); + ~CurlUtils(); + void initialize(bool withSSL, const std::string certificate, const std::string user, const std::string password); + bool http_post_file_request(const std::string url, const std::string fileName, bool connection_testing = false); +private: + bool m_withSSL; + std::string m_certificate; + std::string m_user; + std::string m_password; + CURL* m_curlForPost; +}; + +#endif /* SRC_LIBS_LIBCURL_CURLUTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_audit.h postgresql-hll-2.14/include/include/gs_policy/gs_policy_audit.h --- postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_audit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/gs_policy_audit.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,54 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Main enterance for Auditing Policy + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy_audit.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_POLICY_AUDIT_H +#define GS_POLICY_AUDIT_H + +#include "access/xact.h" +#include "access/heapam.h" +#include "access/genam.h" +#include "access/sysattr.h" +#include "catalog/pg_proc.h" +#include "catalog/indexing.h" + +#include "gs_policy/gs_string.h" +#include "gs_policy/policy_set.h" +#include "nodes/parsenodes.h" +#include "postgres.h" +#include "storage/lock.h" +#include "utils/builtins.h" +#include "utils/timestamp.h" +#include "utils/fmgroids.h" +#include "utils/snapmgr.h" +#include "utils/lsyscache.h" +#include "utils/syscache.h" + +extern void create_audit_policy(CreateAuditPolicyStmt *stmt); +extern void alter_audit_policy(AlterAuditPolicyStmt *stmt); +extern void drop_audit_policy(DropAuditPolicyStmt *stmt); +void construct_resource_name(const RangeVar *rel, gs_stl::gs_string *target_name_s); + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_masking.h postgresql-hll-2.14/include/include/gs_policy/gs_policy_masking.h --- postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_masking.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/gs_policy_masking.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gs_policy_masking.h + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy_masking.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_POLICY_MASKING_H +#define _PG_POLICY_MASKING_H + +#include "postgres.h" +#include "nodes/parsenodes.h" + +extern void create_masking_policy(CreateMaskingPolicyStmt *stmt); + +extern void alter_masking_policy(AlterMaskingPolicyStmt *stmt); + +extern void drop_masking_policy(DropMaskingPolicyStmt *stmt); +extern bool IsMaskingFunctionOid(Oid funcid); +extern bool is_masked_relation(Oid relid); +extern bool is_masked_relation_enabled(Oid relid); +#endif + diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_utils.h postgresql-hll-2.14/include/include/gs_policy/gs_policy_utils.h --- postgresql-hll-2.14_old/include/include/gs_policy/gs_policy_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/gs_policy_utils.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,332 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_auditing_policy_priv.h + * Declaration of functions for dealing with policy records + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_policy.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _GS_POLICY_UTILS_H +#define _GS_POLICY_UTILS_H + +#include "access/heapam.h" +#include "access/tableam.h" +#include "nodes/parsenodes.h" +#include "policy_common.h" +#include "policy_set.h" +#include "gs_vector.h" +#include "policy_map.h" +#include "postgres.h" +#include "pgaudit.h" +#include "utils/snapmgr.h" + +#define MAX_POLICIES_NUM 98 +#define MAX_IP_LEN 129 + +enum {POLICY_OPT_UNKNOWN, POLICY_OPT_PRIVILEGES, POLICY_OPT_ACCESS, POLICY_OPT_FILTER, POLICY_OPT_BLOCK}; + +static inline int get_option_type(const char *option_type) +{ + if (!strcasecmp(option_type, "privileges")) { + return POLICY_OPT_PRIVILEGES; + } + if (!strcasecmp(option_type, "access")) + return POLICY_OPT_ACCESS; + if (!strcasecmp(option_type, "filter")) + return POLICY_OPT_FILTER; + + return POLICY_OPT_UNKNOWN; +} + +enum {POLICY_CMD_UNKNOWN, POLICY_CMD_ADD, POLICY_CMD_REMOVE, POLICY_CMD_MODIFY, POLICY_CMD_DROP_FILTER}; + +static inline int get_policy_command_type(const char *command) +{ + if (!strcasecmp(command, "add")) { + return POLICY_CMD_ADD; + } + if (!strcasecmp(command, "remove")) { + return POLICY_CMD_REMOVE; + } + if (!strcasecmp(command, "modify")) { + return POLICY_CMD_MODIFY; + } + if (!strcasecmp(command, "drop_filter")) { + return POLICY_CMD_DROP_FILTER; + } + return POLICY_CMD_UNKNOWN; +} + +struct GsPolicyStruct { + GsPolicyStruct(const gs_stl::gs_string name = ""):m_id(0), m_name(name), m_enabled(false){} + bool operator < (const GsPolicyStruct arg) const; + long long m_id; + gs_stl::gs_string m_name; + gs_stl::gs_string m_comments; + bool m_enabled; +}; + +/* set of existing policies keyed by name */ +typedef policy_memory::pg_set policies_set; + +struct PgPolicyFiltersStruct { + bool operator < (const PgPolicyFiltersStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_label_name; + gs_stl::gs_string m_tree_string; + long long m_policy_oid; +}; + +/* set of existing filters keyed by type & label name */ +typedef policy_memory::pg_set filters_set; + +struct PgPolicyMaskingActionStruct { + bool operator < (const PgPolicyMaskingActionStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_params; + gs_stl::gs_string m_label_name; + long long m_policy_oid; +}; +typedef policy_memory::pg_set masking_actions_set; + +struct PgPolicyPrivilegesAccessStruct { + PgPolicyPrivilegesAccessStruct() : m_id(0), m_type(""), m_label_name(""), m_policy_oid(0) {} + bool operator < (const PgPolicyPrivilegesAccessStruct arg) const; + long long m_id; + gs_stl::gs_string m_type; + gs_stl::gs_string m_label_name; + long long m_policy_oid; +}; + +/* set of existing privileges keyed by type & label name */ +typedef policy_memory::pg_set + privileges_access_set; + +template +extern void load_existing_policies(Relation rel, policies_set *existing_policies) +{ + if (rel == nullptr) + return; + HeapTuple rtup; + T rel_data; + GsPolicyStruct item; + TableScanDesc scan = tableam_scan_begin(rel, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + item.m_id = HeapTupleGetOid(rtup); + item.m_name = rel_data->polname.data; + item.m_enabled = rel_data->polenabled; + existing_policies->insert(item); + } + tableam_scan_end(scan); +} + +template +extern size_t get_num_of_existing_policies(Relation rel) +{ + size_t amount = 0; + if (rel == nullptr) + return amount; + HeapTuple rtup; + T rel_data; + TableScanDesc scan = heap_beginscan(rel, SnapshotNow, 0, NULL); + while (scan && (rtup = heap_getnext(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + amount++; + } + heap_endscan(scan); + return amount; +} + +template +void drop_policy_by_name(unsigned int rel_oid, const char *polname, + policy_memory::pg_set *ids) +{ + Relation relation = heap_open(rel_oid, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + T rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + if (!strcasecmp(polname, rel_data->polname.data)) { + ids->insert(HeapTupleGetOid(rtup)); + simple_heap_delete(relation, &rtup->t_self); + } + } + tableam_scan_end(scan); + + heap_close(relation, RowExclusiveLock); +} + +template +void drop_policy_reference(unsigned int rel_oid, long long policy_oid) +{ + Relation relation = heap_open(rel_oid, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + T rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + if ((long long)rel_data->policyoid == policy_oid) { + simple_heap_delete(relation, &rtup->t_self); + } + } + tableam_scan_end(scan); + + heap_close(relation, RowExclusiveLock); +} + +template +void load_existing_filters(Relation relation, filters_set *fltrs, long long policy_oid = 0) +{ + if (!relation) + return; + HeapTuple rtup; + T rel_data; + PgPolicyFiltersStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->filtertype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* when policy_oid is zero - load all privileges + * when policy_oid greater than zero, load only matching + */ + if ((policy_oid == 0) || ((policy_oid > 0) && (item.m_policy_oid == policy_oid))) + fltrs->insert(item); + } + tableam_scan_end(scan); +} + +template +void load_existing_privileges(int relationId, privileges_access_set *privs, long long policy_oid = 0) +{ + Relation relation = heap_open(relationId, RowExclusiveLock); + if (!relation) + return; + HeapTuple rtup; + T rel_data; + PgPolicyPrivilegesAccessStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) + continue; + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->privilegetype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* load only matching privileges to policy id */ + if (item.m_policy_oid == policy_oid) { + privs->insert(item); + } + } + tableam_scan_end(scan); + heap_close(relation, RowExclusiveLock); +} + +template +void load_existing_access(int relationId, privileges_access_set *acc, long long policy_oid = 0) +{ + Relation relation = heap_open(relationId, RowExclusiveLock); + if (!relation) { + return; + } + HeapTuple rtup; + T rel_data; + PgPolicyPrivilegesAccessStruct item; + TableScanDesc scan = tableam_scan_begin(relation, SnapshotNow, 0, NULL); + while (scan && (rtup = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection))) { + rel_data = (T)GETSTRUCT(rtup); + if (rel_data == NULL) { + continue; + } + item.m_id = HeapTupleGetOid(rtup); + item.m_type = rel_data->accesstype.data; + item.m_label_name = rel_data->labelname.data; + item.m_policy_oid = (long long)(rel_data->policyoid); + /* load only matching access to policy id */ + if (item.m_policy_oid == policy_oid) { + acc->insert(item); + } + } + tableam_scan_end(scan); + heap_close(relation, RowExclusiveLock); +} + +/* Process new filters from parser tree and tranform them into string */ +extern bool process_new_filters(const List *policy_filters, gs_stl::gs_string *flat_tree); + +extern bool verify_ip_role_app(const char *obj_type, const char *obj_value, gs_stl::gs_string *return_value); + +/* Parses & validates (recursively) polish-notation format string into logical tree; on error uses ereport() */ +extern bool validate_logical_expression(const gs_stl::gs_string logical_expr_str, int *offset); + +extern bool scan_to_delete_from_relation(long long row_id, Relation relation, unsigned int index_id); + +extern bool remove_filters(const filters_set filters_to_remove, Relation relation, filters_set *existing_filters, + unsigned int index_id, gs_stl::gs_string *err_msg); + +extern bool remove_filters(const filters_set filters_to_remove, unsigned int relation_id, unsigned int index_id, + gs_stl::gs_string *err_msg); + +extern void construct_resource_name(const RangeVar *rel, gs_stl::gs_string *target_name_s); + +bool handle_target(ListCell *target, + int opt_type, + bool is_add, + gs_stl::gs_string *err_msg, + privileges_access_set *access_to_add, privileges_access_set *access_to_remove, + privileges_access_set *privs_to_add, privileges_access_set *privs_to_remove, + const policy_labels_map *existing_labels, + const GsPolicyStruct *policy, const char *acc_action_type); + +void save_manage_message(const char *message); +void send_manage_message(AuditResult result_type); + +extern void get_session_ip(char *session_ip, int len); +extern void get_client_ip(const struct sockaddr* remote_addr, char *ip_str); + +bool is_database_valid(const char* dbname); + +/* create and release temp resource owner should use together to solve the empty owner of table */ +ResourceOwnerData* create_temp_resourceowner(); +void release_temp_resourceowner(ResourceOwnerData* resource_owner); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/gs_string.h postgresql-hll-2.14/include/include/gs_policy/gs_string.h --- postgresql-hll-2.14_old/include/include/gs_policy/gs_string.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/gs_string.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_string.h + * Containers common parts and string declare + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_string.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INCLUDE_UTILS_GS_STRING_H_ +#define INCLUDE_UTILS_GS_STRING_H_ + +#include "c.h" +#include "utils/palloc.h" +#include "utils/memutils.h" +#include + +namespace gs_stl { + /* vector memory */ + MemoryContext GetVectorMemory(); + void DeleteVectorMemory(); + /* string memory */ + void DeleteStringMemory(); + + class gs_string { + public: + static const size_t npos = -1; + gs_string(const char *str = "", size_t len = 0); + ~gs_string(); + gs_string(const gs_string &arg); + gs_string &operator =(const gs_string &arg); + bool operator ==(const gs_string &arg) const; + bool operator <(const gs_string &arg) const; + const char *c_str() const + { + return m_buff; + } + size_t size() const + { + return m_len; + } + size_t capacity() const + { + return m_capacity; + } + bool empty() const + { + return !size(); + } + gs_string &append(const char *str, size_t len = 0); + gs_string &append(const gs_string &str); + void push_back(char ch); + void pop_back(); + char operator[](int idx) const; + void clear(); + size_t find(char arg, size_t start = 0) const; + char back() const; + gs_string substr(size_t pos, size_t len) const; + gs_string &replace(size_t pos, size_t len, const char *s); + void erase(size_t pos, size_t len); + private: + inline char *AllocFunc(size_t _size) const; + inline char *ReallocFunc(size_t _size); + inline bool InitBuff(const char *str, size_t len = 0); + char *m_buff; + size_t m_len; + size_t m_capacity; + }; +} + +#endif /* INCLUDE_UTILS_GS_STRING_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/gs_vector.h postgresql-hll-2.14/include/include/gs_policy/gs_vector.h --- postgresql-hll-2.14_old/include/include/gs_policy/gs_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/gs_vector.h 2020-12-12 17:06:43.193347341 +0800 @@ -0,0 +1,329 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_vector.h + * vector declare and implementation. + * + * + * IDENTIFICATION + * src/include/gs_policy/gs_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INCLUDE_UTILS_GS_VECTOR_H_ +#define INCLUDE_UTILS_GS_VECTOR_H_ + +#include "gs_string.h" + + +namespace gs_stl { +#define MIN_VECTOR_CAPACITY 16 + template + class gs_vector { + public: + typedef T *iterator; + typedef const T * const_iterator; + + gs_vector(size_t size = 1):m_buff(nullptr), m_len(0), m_capacity(0) + { + m_capacity = Max(size, MIN_VECTOR_CAPACITY); + InitBuff(); + } + + ~gs_vector() + { + if ((m_buff) != NULL && (t_thrd.port_cxt.thread_is_exiting == false)) { + Assert(t_thrd.top_mem_cxt != NULL); + for (size_t i = 0; i < m_len; ++i) { + m_buff[i].~T(); + } + pfree(m_buff); + m_buff = nullptr; + } + } + + gs_vector(const gs_vector &arg):m_buff(nullptr), m_len(0), m_capacity(0) + { + operator =(arg); + } + + gs_vector &operator =(const gs_vector &arg) + { + if (arg.size() > 0) { + if (m_buff != NULL) { + clear(); + pfree(m_buff); + } + m_len = m_capacity = arg.size(); + m_buff = (T*)AllocFunc(sizeof(T) * m_capacity); + for (size_t i = 0; i < m_len; ++i) { + m_buff[i] = arg.m_buff[i]; + } + } else if (m_buff == NULL) { + m_len = 0; + m_capacity = MIN_VECTOR_CAPACITY; + InitBuff(); + } + return *this; + } + + size_t size() const + { + return m_len; + } + + size_t capacity() const + { + return m_capacity; + } + + bool empty() const + { + return !size(); + } + + void insert(iterator it, const T &arg) + { + if ((m_len + 1) >= m_capacity) { + ReallocFunc(); + } + size_t moved_len = m_len - (it - begin()); + size_t remain_len = m_capacity - (it - begin()) - 1; + errno_t rc = memmove_s((void*)(it + 1), remain_len * sizeof(T), (const void*)it, moved_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + new(static_cast(it))T(arg); + ++m_len; + } + + void insert(const_iterator it, const_iterator eit) + { + for (; it != eit; ++it) { + push_back(*it); + } + } + + /* add an element into the vector (at end) */ + void push_back(const T& arg) + { + if ((m_len + 1) >= m_capacity) { + ReallocFunc(); + } + if (is_sorted) { + if (find(arg) != end()) { + return; + } + for (size_t i = 0; i < m_len; ++i) { + if (m_buff[i] < arg) { + iterator it(m_buff + i); + errno_t rc = memmove_s((void*)(it + 1), (m_capacity - i - 1) * sizeof(T), + (const void*)it, (m_len - i) * sizeof(T)); + securec_check(rc, "\0", "\0"); + new(static_cast(m_buff + i))T(arg); + ++m_len; + return; + } + } + } + + new(static_cast(m_buff + m_len))T(arg); + ++m_len; + } + + /* Return the first item */ + T &front() + { + return m_buff[0]; + } + + /* return the last item */ + T &back() + { + if (m_len > 0) { + return m_buff[m_len - 1]; + } + return m_buff[0]; + } + + const_iterator find(const T &arg) const + { + if (is_sorted) { + if (m_len < 10) { + for (size_t i = 0; i < m_len; ++i) { + if (m_buff[i] < arg) { + return end(); + } + if (arg < m_buff[i]) { + continue; + } + return const_iterator(m_buff + i); + } + } else { + return binary_search(arg); + } + } else { + Assert(false); + } + return end(); + } + + bool has_intersect(const gs_vector &arg) const + { + iterator it = begin(); + iterator eit = end(); + for (; it != eit; ++it) { + if (arg.find(*it) != arg.end()) { + return true; + } + } + return false; + } + + void pop_front() + { + if (m_len > 0) { + --m_len; + m_buff[0].~T(); + if (m_len > 0) { + errno_t rc = memmove_s((void*)m_buff, m_capacity * sizeof(T), + (const void*)(m_buff + 1), m_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + } + } + } + + void pop_back() + { + if (m_len > 0) { + --m_len; + m_buff[m_len].~T(); + } + } + + T &operator[](size_t idx) + { + if (idx < m_len) { + return m_buff[idx]; + } + Assert(false); + return m_buff[0]; + } + + const T &operator[](size_t idx) const + { + if (idx < m_len) { + return m_buff[idx]; + } + Assert(false); + return m_buff[0]; + } + + void clear() + { + for (size_t i = 0; i < m_len; ++i) { + m_buff[i].~T(); + } + m_len = 0; + } + + void swap(gs_vector& arg) + { + m_len = arg.size(); + m_capacity = arg.capacity(); + std::swap(arg.m_buff, m_buff); + } + + iterator begin() + { + return iterator(m_buff); + } + + iterator end() + { + return iterator(m_buff + m_len); + } + + const iterator begin() const + { + return iterator(m_buff); + } + + const iterator end() const + { + return iterator(m_buff + m_len); + } + private: + + const_iterator binary_search(const T& arg) const + { + size_t start = 0; + size_t mid = m_len / 2; + size_t up = m_len; + while (start < up) { + if (m_buff[start] < arg) { + return end(); + } + if (arg < m_buff[start]) { + ++start; + if (start == m_len) { + return end(); + } + if (m_buff[mid] < arg) { + start = mid + 1; + mid = (up - start) / 2; + } else if (arg < m_buff[mid]) { + up = mid - 1; + mid = (up - start) / 2; + } else { + return const_iterator(m_buff + mid); + } + } else { + return const_iterator(m_buff + start); + } + } + return end(); + } + + inline bool InitBuff() + { + if (m_buff == NULL && m_capacity > 0) { + m_buff = (T*)AllocFunc(sizeof(T) * m_capacity); + return true; + } + return false; + } + inline void *AllocFunc(size_t _size) + { + return MemoryContextAllocZero(GetVectorMemory(), _size); + } + + inline void ReallocFunc() + { + m_capacity += MIN_VECTOR_CAPACITY; + /* allocate a new array */ + T *buff = (T*)AllocFunc(sizeof(T) * m_capacity); + /* copy old data */ + errno_t rc = memcpy_s((void*)buff, sizeof(T) * m_capacity, (void*)m_buff, m_len * sizeof(T)); + securec_check(rc, "\0", "\0"); + pfree(m_buff); + m_buff = buff; + } + T *m_buff; + size_t m_len; + size_t m_capacity; + }; +} + +#endif /* INCLUDE_UTILS_GS_VECTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/policy_common.h postgresql-hll-2.14/include/include/gs_policy/policy_common.h --- postgresql-hll-2.14_old/include/include/gs_policy/policy_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/policy_common.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_common.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_common.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _GS_POLICY_COMMON_H +#define _GS_POLICY_COMMON_H +#include "nodes/parsenodes.h" + +#include "postgres.h" +#include "policy_map.h" +#include "gs_vector.h" +#include "pgaudit.h" + +struct GsPolicyFQDN { + GsPolicyFQDN():m_value_schema(0), m_value_object(0), is_function(false){} + Oid m_value_schema; /* schema */ + Oid m_value_object; /* table */ + gs_stl::gs_string m_value_object_attrib; /* column */ + bool is_function; +}; + +struct GsPolicyLabel { + bool operator < (const GsPolicyLabel& arg) const; + long long m_id; + gs_stl::gs_string m_name; + gs_stl::gs_string m_type; + gs_stl::gs_string m_data_value; + GsPolicyFQDN m_data_value_fqdn; + gs_stl::gs_string m_data_type; +}; + +struct GsPolicyLabelKey { + gs_stl::gs_string m_name; + gs_stl::gs_string m_type; +}; + +typedef policy_memory::pg_set policy_labelname_set; +typedef policy_memory::pg_unordered_set policy_oid_set; + +/* set of existing labels keyed by data type and data value */ +typedef policy_memory::pg_set policy_labels_set; +/* map of existing labels - key: label name, value: set of labels keyed by resource type & name. */ +typedef policy_memory::pg_unordered_map policy_labels_map; +/* set of tables fqdn contained in label */ +typedef policy_memory::pg_unordered_set policy_label_tables_set; + +extern void create_policy_label(CreatePolicyLabelStmt *stmt); +extern void load_existing_labels(Relation rel, policy_labels_map *existing_labels); +extern void alter_policy_label(AlterPolicyLabelStmt *stmt); +extern void drop_policy_label(DropPolicyLabelStmt *stmt); +extern bool VerifyLabelHasColumn(RangeVar *rel, GsPolicyFQDN *fqdn, + const policy_memory::pg_set *labels); + +typedef bool(*ValidateBehaviourPtr)(const char *func_name); +extern PGDLLIMPORT ValidateBehaviourPtr validate_masking_behaviour_hook; + +typedef bool (*LoadLabelsPtr)(bool); +extern PGDLLIMPORT LoadLabelsPtr load_labels_hook; + +typedef bool (*IsLabelsHasBoundObjectPtr)(const GsPolicyFQDN*, + const policy_memory::pg_set*, + bool (*CheckLabelBoundPolicy)(bool, const gs_stl::gs_string)); +extern PGDLLIMPORT IsLabelsHasBoundObjectPtr check_labels_has_object_hook; + +typedef void (*RelationBuildPtr)(Relation); +extern PGDLLIMPORT RelationBuildPtr RelationBuildRlsPolicies_hook; + +typedef void(*GetRlsPoliciesPtr)(const Query *query, const RangeTblEntry *rte, + const Relation relation, List *&rlsQuals, List *&withCheckOptions, + int rtIndex, bool &hasRowSecurity, bool &hasSubLink); +extern PGDLLIMPORT GetRlsPoliciesPtr get_rls_policies_hook; + +typedef bool (*GetLabelTablesPtr)(const gs_stl::gs_string&, policy_label_tables_set&); +extern PGDLLIMPORT GetLabelTablesPtr get_label_tables_hook; + +typedef void (*ReseThreadValuesPtr)(); +extern THR_LOCAL PGDLLIMPORT ReseThreadValuesPtr reset_policy_thr_hook; + +typedef bool (*LoadPoliciesPtr)(bool); +extern PGDLLIMPORT LoadPoliciesPtr load_rls_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_audit_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_masking_policies_hook; +extern PGDLLIMPORT LoadPoliciesPtr load_security_policies_hook; + +typedef void (*LightUnifiedAuditExecutorPtr)(const Query *query); +extern THR_LOCAL PGDLLIMPORT LightUnifiedAuditExecutorPtr light_unified_audit_executor_hook; + +typedef bool (*LoadPolicyAccessPtr)(bool); +extern PGDLLIMPORT LoadPolicyAccessPtr load_policy_access_hook; +extern PGDLLIMPORT LoadPolicyAccessPtr load_masking_policy_actions_hook; +extern PGDLLIMPORT LoadPolicyAccessPtr load_security_access_hook; + +typedef bool (*LoadPolicyPrivilegesPtr)(bool); +extern PGDLLIMPORT LoadPolicyPrivilegesPtr load_policy_privileges_hook; +extern PGDLLIMPORT LoadPolicyPrivilegesPtr load_security_privileges_hook; + +typedef bool (*LoadPolicyFilterPtr)(bool); +extern PGDLLIMPORT LoadPolicyFilterPtr load_policy_filter_hook; +extern PGDLLIMPORT LoadPolicyFilterPtr load_masking_policy_filter_hook; +extern PGDLLIMPORT LoadPolicyFilterPtr load_security_filter_hook; + +typedef bool (*IsMaskingHasObjPtr)(bool, const gs_stl::gs_string); +extern PGDLLIMPORT IsMaskingHasObjPtr isMaskingHasObj_hook; + +typedef bool (*CheckPolicyPrivilegesForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyPrivilegesForLabelPtr check_audit_policy_privileges_for_label_hook; + +typedef bool (*CheckPolicyAccessForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyAccessForLabelPtr check_audit_policy_access_for_label_hook; + +typedef bool (*CheckPolicyActionsForLabelPtr)(const policy_labels_map*); +extern PGDLLIMPORT CheckPolicyActionsForLabelPtr check_masking_policy_actions_for_label_hook; +extern PGDLLIMPORT CheckPolicyActionsForLabelPtr check_rls_policy_actions_for_label_hook; + +typedef void (*LoginUserPtr)(const char* /* db name */, const char* /* user */, bool /* sucess */, bool /* login */); +extern THR_LOCAL PGDLLIMPORT LoginUserPtr user_login_hook; + +typedef bool (*VerifyCopyCommandIsReparsed)(List*, const char*, gs_stl::gs_string&); +extern THR_LOCAL PGDLLIMPORT VerifyCopyCommandIsReparsed copy_need_to_be_reparse; + +typedef bool (*IsRecompilePrepareStmtPtr)(const char *stmt_name); +extern PGDLLIMPORT IsRecompilePrepareStmtPtr recompile_prepare_stmt_hook; + +typedef void (*IsInsidePrepareStmtPtr)(const char *stmt_name); +extern PGDLLIMPORT IsInsidePrepareStmtPtr prepare_stmt_state_hook; + +typedef bool (*IsLabelExistPtr)(const char *label_name); +extern PGDLLIMPORT IsLabelExistPtr verify_label_hook; + +typedef void (*InSideView)(bool); +extern PGDLLIMPORT InSideView query_from_view_hook; + +typedef void (*GsSaveManagementEvent)(const char *message); +extern PGDLLIMPORT GsSaveManagementEvent gs_save_mng_event_hook; + +typedef void (*GsSendManagementEvent)(AuditResult result_type); +extern PGDLLIMPORT GsSendManagementEvent gs_send_mng_event_hook; + +typedef bool (*VerifyLabelsByPolicy)(const char* filter_tree, const policy_labelname_set *policy_labels, + Oid policyOid, gs_stl::gs_string *polname); +extern PGDLLIMPORT VerifyLabelsByPolicy gs_verify_labels_by_policy_hook; + +bool get_files_list(const char *dir,std::vector& files,const char *ext, int queue_size); +bool is_policy_enabled(); +bool is_security_policy_relation(Oid table_oid); + +#endif /* _GS_POLICY_COMMON_H */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/policy_map.h postgresql-hll-2.14/include/include/gs_policy/policy_map.h --- postgresql-hll-2.14_old/include/include/gs_policy/policy_map.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/policy_map.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_map.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_map.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_MAP_H_ +#define GS_POLICY_MAP_H_ + +#include +#include "policy_memory_alloc.h" +#include "policy_set.h" +#include + +namespace policy_memory +{ + template, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator, type> > + class pg_map + : public std::map<_Key, _Ty, _Pr, _Alloc> { + public: + using std::map<_Key, _Ty, _Pr, _Alloc>::map; + }; + + /* + replace standard dynamic memory allocation (on heap) to local thread memory usage (preallocated memory on thread) + support for sdt::unordered_set + */ + template, + class _Pred = policy_memory::PgMemoryEqualTo<_Key>, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator, type> > + class pg_unordered_map + : public std::unordered_map<_Key, _T, _Hash, _Pred, _Alloc> { + public: + using std::unordered_map<_Key, _T, _Hash, _Pred, _Alloc>::unordered_map; + }; +} + +#endif /* GS_POLICY_MAP_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/policy_memory_alloc.h postgresql-hll-2.14/include/include/gs_policy/policy_memory_alloc.h --- postgresql-hll-2.14_old/include/include/gs_policy/policy_memory_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/policy_memory_alloc.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,115 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_memory_alloc.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_memory_alloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_MEMORY_ALLOC_H_ +#define GS_POLICY_MEMORY_ALLOC_H_ + +#include +#include "knl/knl_instance.h" +#include +#include "postgres.h" +#include +#include +#include "utils/palloc.h" + +namespace Memory_allocator +{ + typedef enum MemoryContextType { + MemoryCxt_Audit, + MemoryCxt_Mask, + MemoryCxt_RLS, + MemoryCxt_policy_instance + } MemoryContextType; + + template + class MemoryContextAdapterAllocator { + public: + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef T value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + MemoryContextAdapterAllocator () {} + ~MemoryContextAdapterAllocator () {} + template MemoryContextAdapterAllocator (const MemoryContextAdapterAllocator&) {} + template + struct rebind { typedef MemoryContextAdapterAllocator other; }; + pointer address(reference node) const {return &node;} + const_pointer address(const_reference node) const {return &node;} + + static bool has_free_memory(size_t size) + { + return true; + } + + pointer allocate(size_type n, const_pointer hint = 0) + { + switch (type) { + case MemoryCxt_Audit: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_audit_context, n * sizeof(T))); + case MemoryCxt_Mask: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_mask_context, n * sizeof(T))); + case MemoryCxt_RLS: + return static_cast( + MemoryContextAlloc(t_thrd.security_policy_cxt.policy_rls_context, n * sizeof(T))); + default: + return static_cast( + MemoryContextAlloc(g_instance.policy_cxt.policy_instance_cxt, n * sizeof(T))); + } + } + + void deallocate(pointer p, size_type n) + { + pfree(p); + } + + void construct(pointer p, const T& val) + { + new(static_cast(p)) T(val); + } + + void construct(pointer p) + { + new(static_cast(p)) T(); + } + + void destroy(pointer p) + { + p->~T(); + } + }; + + template + inline bool operator == (const MemoryContextAdapterAllocator&, + const MemoryContextAdapterAllocator&){return true;} + + template + inline bool operator != (const MemoryContextAdapterAllocator&, + const MemoryContextAdapterAllocator&){return false;} +} + +#endif /* GS_POLICY_MEMORY_ALLOC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_policy/policy_set.h postgresql-hll-2.14/include/include/gs_policy/policy_set.h --- postgresql-hll-2.14_old/include/include/gs_policy/policy_set.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_policy/policy_set.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,78 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * policy_set.h + * + * IDENTIFICATION + * src/include/gs_policy/policy_set.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GS_POLICY_SET_H_ +#define GS_POLICY_SET_H_ + +#include "policy_memory_alloc.h" +#include "gs_string.h" +#include +#include + +namespace policy_memory +{ + template + struct PgMemoryKeyHash : std::hash<_Key> {}; + + template<> + struct PgMemoryKeyHash { + size_t operator()(const gs_stl::gs_string& k) const + { + return std::hash{}(k.c_str()); + } + }; + + template + struct PgMemoryEqualTo : std::equal_to<_Key> {}; + + template<> + struct PgMemoryEqualTo { + bool operator()(const gs_stl::gs_string& l, const gs_stl::gs_string& r) const + { + return l == r; + } + }; + + template, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator<_Key, type> > + class pg_set + : public std::set<_Key, _Pr, _Alloc> {}; + + /* + replace standard dynamic memory allocation (on heap) to local thread memory usage (preallocated memory on thread) + support for sdt::unordered_set + */ + template, + class _Pred = policy_memory::PgMemoryEqualTo<_Key>, + class _Alloc = Memory_allocator::MemoryContextAdapterAllocator<_Key, type> > + class pg_unordered_set + : public std::unordered_set<_Key, _Hash, _Pred, _Alloc> { + public: + using std::unordered_set<_Key, _Hash, _Pred, _Alloc>::unordered_set; + }; +} + +#endif /* GS_POLICY_SET_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_register/gs_malloc.h postgresql-hll-2.14/include/include/gs_register/gs_malloc.h --- postgresql-hll-2.14_old/include/include/gs_register/gs_malloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_register/gs_malloc.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,131 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_malloc.h + * + * + * IDENTIFICATION + * src/include/gs_register/gs_malloc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GS_MALLOC_H +#define GS_MALLOC_H + +#include +#include +#include +#include +#include +#include "gssignal/gs_signal.h" +#include "gs_threadlocal.h" + +#ifdef WIN32 +#define register_hash_len 1111 +#define register_local_info_len 64 +#define REGISTER_TRUE 1 +#define REGISTER_FALSE 0 +#endif + +/* these memory apply macro is used only for memory context */ +#define gs_free(local_register_ptr, local_register_size) \ + do { \ + if ((local_register_size) < mmap_threshold) { \ + free((void*)(local_register_ptr)); \ + } else { \ + (void)munmap(local_register_ptr, (local_register_size)); \ + } \ + } while (0) + +#define gs_calloc(local_register_nmemb, local_register_size, local_register_ptr, local_register_type) \ + do { \ + Size gSize = (local_register_nmemb) * (local_register_size); \ + if (gSize < mmap_threshold) { \ + (local_register_ptr) = \ + (local_register_type)calloc((size_t)(local_register_nmemb), (size_t)(local_register_size)); \ + } else { \ + (local_register_ptr) = \ + (local_register_type)mmap(NULL, gSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + } \ + } while (0) + +#define gs_malloc(local_register_size, local_register_ptr, local_register_type) \ + do { \ + if ((local_register_size) < mmap_threshold) { \ + (local_register_ptr) = (local_register_type)malloc((size_t)(local_register_size)); \ + } else { \ + (local_register_ptr) = (local_register_type)mmap( \ + NULL, (local_register_size), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + } \ + } while (0) + +#define gs_realloc(local_register_old_ptr, \ + local_register_old_size, \ + local_register_new_ptr, \ + local_register_new_size, \ + local_register_type) \ + do { \ + if ((local_register_new_size) < mmap_threshold) { \ + (local_register_new_ptr) = \ + (local_register_type)realloc((local_register_old_ptr), (local_register_new_size)); \ + } else { \ + (local_register_new_ptr) = (local_register_type)mmap( \ + NULL, (local_register_new_size), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + if (NULL == (local_register_new_ptr)) { \ + break; \ + } else { \ + errno_t rc = EOK; \ + rc = memmove_s(local_register_new_ptr, \ + local_register_new_size, \ + local_register_old_ptr, \ + (local_register_old_size)); \ + securec_check(rc, "\0", "\0"); \ + gs_free(local_register_old_ptr, local_register_old_size); \ + } \ + } \ + } while (0) + +#define gs_strdup(local_register_str, local_register_new_str) \ + do { \ + Size gSize = strlen(local_register_str) + 1; \ + if (gSize < mmap_threshold) { \ + (local_register_new_str) = strdup((local_register_str)); \ + } else { \ + (local_register_new_str) = \ + (char*)mmap(NULL, gSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \ + if (NULL == (local_register_new_str)) { \ + break; \ + } else { \ + errno_t rc = EOK; \ + rc = strncpy_s(local_register_new_str, gSize, local_register_str, gSize - 1); \ + securec_check(rc, "\0", "\0"); \ + local_register_new_str[gSize - 1] = '\0'; \ + } \ + } \ + } while (0) + +#ifdef WIN32 +typedef struct tag_register_node { + unsigned long size_mem; + void *addr_mem; + struct tag_register_node *next; + struct tag_register_node *prior; + unsigned long no_ctl; /* pool no.*/ + char register_local[register_local_info_len]; +} register_node; +#endif + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/gssapi/gssapi_ext.h postgresql-hll-2.14/include/include/gssapi/gssapi_ext.h --- postgresql-hll-2.14_old/include/include/gssapi/gssapi_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi/gssapi_ext.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,596 @@ +/* + * Copyright 2008 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef GSSAPI_EXT_H_ +#define GSSAPI_EXT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Solaris extensions + */ +#ifndef _WIN32 +OM_uint32 KRB5_CALLCONV +gss_pname_to_uid + (OM_uint32 *minor, + const gss_name_t name, + const gss_OID mech_type, + uid_t *uidOut); +#endif + +/** + * Provides a platform-specific name for a GSSAPI name as interpreted by a + * given mechanism. + * + * @param [out] minor Minor status code + * @param [in] name The gss name resulting from accept_sec_context + * @param [in] mech_type The mechanism that will be asked to map @a name to a + * local name + * @param [out] localname Caller-allocated buffer to be filled in with the + * local name on success + */ +OM_uint32 KRB5_CALLCONV +gss_localname + (OM_uint32 *minor, + const gss_name_t name, + gss_const_OID mech_type, + gss_buffer_t localname); + +/** + * Determine whether a mechanism name is authorized to act as a username. + * + * @param [in] name Mechanism name + * @param [in] username System username + * + * This is a simple wrapper around gss_authorize_localname(). It only supports + * system usernames as local names, and cannot distinguish between lack of + * authorization and other errors. + * + * @retval 1 @a name is authorized to act as @a username + * @retval 0 @a name is not authorized or an error occurred + */ +int KRB5_CALLCONV +gss_userok(const gss_name_t name, + const char *username); + +/** + * Determine whether a mechanism name is authorized to act as a local name. + * + * @param [out] minor Minor status code + * @param [in] name Mechanism name + * @param [in] user Local name + * + * @a name is a mechanism name, typically the result of a completed + * gss_accept_sec_context(). @a user is an internal name representing a local + * name, such as a name imported by gss_import_name() with an @a + * input_name_type of @c GSS_C_NT_USER_NAME. + * + * @return Return GSS_S_COMPLETE if @a name is authorized to act as @a user, + * GSS_S_UNAUTHORIZED if not, or an appropriate GSS error code if an error + * occured. + * + * @sa gss_userok + */ +OM_uint32 KRB5_CALLCONV +gss_authorize_localname(OM_uint32 *minor, + const gss_name_t name, + const gss_name_t user); + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_with_password( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* desired_name */ + const gss_buffer_t, /* password */ + OM_uint32, /* time_req */ + const gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_with_password( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t,/* input_cred_handle */ + const gss_name_t, /* desired_name */ + const gss_OID, /* desired_mech */ + const gss_buffer_t, /* password */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* + * GGF extensions + */ +typedef struct gss_buffer_set_desc_struct { + size_t count; + gss_buffer_desc *elements; +} gss_buffer_set_desc, *gss_buffer_set_t; + +#define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t) 0) + +OM_uint32 KRB5_CALLCONV gss_create_empty_buffer_set + (OM_uint32 * /*minor_status*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_add_buffer_set_member + (OM_uint32 * /*minor_status*/, + const gss_buffer_t /*member_buffer*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_release_buffer_set + (OM_uint32 * /*minor_status*/, + gss_buffer_set_t * /*buffer_set*/); + +OM_uint32 KRB5_CALLCONV gss_inquire_sec_context_by_oid + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + const gss_OID /*desired_object*/, + gss_buffer_set_t * /*data_set*/); + +OM_uint32 KRB5_CALLCONV gss_inquire_cred_by_oid + (OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*cred_handle*/, + const gss_OID /*desired_object*/, + gss_buffer_set_t * /*data_set*/); + +OM_uint32 KRB5_CALLCONV gss_set_sec_context_option + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t * /*cred_handle*/, + const gss_OID /*desired_object*/, + const gss_buffer_t /*value*/); + +/* + * Export import cred extensions from GGF, but using Heimdal's signatures + */ +OM_uint32 KRB5_CALLCONV gss_export_cred + (OM_uint32 * /* minor_status */, + gss_cred_id_t /* cred_handle */, + gss_buffer_t /* token */); + +OM_uint32 KRB5_CALLCONV gss_import_cred + (OM_uint32 * /* minor_status */, + gss_buffer_t /* token */, + gss_cred_id_t * /* cred_handle */); + +/* + * Heimdal extension + */ +OM_uint32 KRB5_CALLCONV gss_set_cred_option + (OM_uint32 * /*minor_status*/, + gss_cred_id_t * /*cred*/, + const gss_OID /*desired_object*/, + const gss_buffer_t /*value*/); + +/* + * Call the given method on the given mechanism + */ +OM_uint32 KRB5_CALLCONV gssspi_mech_invoke + (OM_uint32 * /*minor_status*/, + const gss_OID /*desired_mech*/, + const gss_OID /*desired_object*/, + gss_buffer_t /*value*/); + +/* + * AEAD extensions + */ + +OM_uint32 KRB5_CALLCONV gss_wrap_aead + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + int /*conf_req_flag*/, + gss_qop_t /*qop_req*/, + gss_buffer_t /*input_assoc_buffer*/, + gss_buffer_t /*input_payload_buffer*/, + int * /*conf_state*/, + gss_buffer_t /*output_message_buffer*/); + +OM_uint32 KRB5_CALLCONV gss_unwrap_aead + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + gss_buffer_t /*input_message_buffer*/, + gss_buffer_t /*input_assoc_buffer*/, + gss_buffer_t /*output_payload_buffer*/, + int * /*conf_state*/, + gss_qop_t * /*qop_state*/); + +/* + * SSPI extensions + */ +#define GSS_C_DCE_STYLE 0x1000 +#define GSS_C_IDENTIFY_FLAG 0x2000 +#define GSS_C_EXTENDED_ERROR_FLAG 0x4000 + +/* + * Returns a buffer set with the first member containing the + * session key for SSPI compatibility. The optional second + * member contains an OID identifying the session key type. + */ +GSS_DLLIMP extern gss_OID GSS_C_INQ_SSPI_SESSION_KEY; + +OM_uint32 KRB5_CALLCONV gss_complete_auth_token + (OM_uint32 *minor_status, + const gss_ctx_id_t context_handle, + gss_buffer_t input_message_buffer); + +typedef struct gss_iov_buffer_desc_struct { + OM_uint32 type; + gss_buffer_desc buffer; +} gss_iov_buffer_desc, *gss_iov_buffer_t; + +#define GSS_C_NO_IOV_BUFFER ((gss_iov_buffer_t)0) + +#define GSS_IOV_BUFFER_TYPE_EMPTY 0 +#define GSS_IOV_BUFFER_TYPE_DATA 1 /* Packet data */ +#define GSS_IOV_BUFFER_TYPE_HEADER 2 /* Mechanism header */ +#define GSS_IOV_BUFFER_TYPE_MECH_PARAMS 3 /* Mechanism specific parameters */ +#define GSS_IOV_BUFFER_TYPE_TRAILER 7 /* Mechanism trailer */ +#define GSS_IOV_BUFFER_TYPE_PADDING 9 /* Padding */ +#define GSS_IOV_BUFFER_TYPE_STREAM 10 /* Complete wrap token */ +#define GSS_IOV_BUFFER_TYPE_SIGN_ONLY 11 /* Sign only packet data */ +#define GSS_IOV_BUFFER_TYPE_MIC_TOKEN 12 /* MIC token destination */ + +#define GSS_IOV_BUFFER_FLAG_MASK 0xFFFF0000 +#define GSS_IOV_BUFFER_FLAG_ALLOCATE 0x00010000 /* indicates GSS should allocate */ +#define GSS_IOV_BUFFER_FLAG_ALLOCATED 0x00020000 /* indicates caller should free */ + +#define GSS_IOV_BUFFER_TYPE(_type) ((_type) & ~(GSS_IOV_BUFFER_FLAG_MASK)) +#define GSS_IOV_BUFFER_FLAGS(_type) ((_type) & GSS_IOV_BUFFER_FLAG_MASK) + +/* + * Sign and optionally encrypt a sequence of buffers. The buffers + * shall be ordered HEADER | DATA | PADDING | TRAILER. Suitable + * space for the header, padding and trailer should be provided + * by calling gss_wrap_iov_length(), or the ALLOCATE flag should + * be set on those buffers. + * + * Encryption is in-place. SIGN_ONLY buffers are untouched. Only + * a single PADDING buffer should be provided. The order of the + * buffers in memory does not matter. Buffers in the IOV should + * be arranged in the order above, and in the case of multiple + * DATA buffers the sender and receiver should agree on the + * order. + * + * With GSS_C_DCE_STYLE it is acceptable to not provide PADDING + * and TRAILER, but the caller must guarantee the plaintext data + * being encrypted is correctly padded, otherwise an error will + * be returned. + * + * While applications that have knowledge of the underlying + * cryptosystem may request a specific configuration of data + * buffers, the only generally supported configurations are: + * + * HEADER | DATA | PADDING | TRAILER + * + * which will emit GSS_Wrap() compatible tokens, and: + * + * HEADER | SIGN_ONLY | DATA | PADDING | TRAILER + * + * for AEAD. + * + * The typical (special cased) usage for DCE is as follows: + * + * SIGN_ONLY_1 | DATA | SIGN_ONLY_2 | HEADER + */ +OM_uint32 KRB5_CALLCONV gss_wrap_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + int *, /* conf_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Verify and optionally decrypt a sequence of buffers. To process + * a GSS-API message without separate buffer, pass STREAM | DATA. + * Upon return DATA will contain the decrypted or integrity + * protected message. Only a single DATA buffer may be provided + * with this usage. DATA by default will point into STREAM, but if + * the ALLOCATE flag is set a copy will be returned. + * + * Otherwise, decryption is in-place. SIGN_ONLY buffers are + * untouched. + */ +OM_uint32 KRB5_CALLCONV gss_unwrap_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int *, /* conf_state */ + gss_qop_t *, /* qop_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Query HEADER, PADDING and TRAILER buffer lengths. DATA buffers + * should be provided so the correct padding length can be determined. + */ +OM_uint32 KRB5_CALLCONV gss_wrap_iov_length +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + int *, /* conf_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Produce a GSSAPI MIC token for a sequence of buffers. All SIGN_ONLY and + * DATA buffers will be signed, in the order they appear. One MIC_TOKEN buffer + * must be included for the result. Suitable space should be provided for the + * MIC_TOKEN buffer by calling gss_get_mic_iov_length, or the ALLOCATE flag + * should be set on that buffer. If the ALLOCATE flag is used, use + * gss_release_iov_buffer to free the allocated buffer within the iov list when + * it is no longer needed. + */ +OM_uint32 KRB5_CALLCONV gss_get_mic_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Query the MIC_TOKEN buffer length within the iov list. + */ +OM_uint32 KRB5_CALLCONV gss_get_mic_iov_length( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Verify the MIC_TOKEN buffer within the iov list against the SIGN_ONLY and + * DATA buffers in the order they appear. Return values are the same as for + * gss_verify_mic. + */ +OM_uint32 KRB5_CALLCONV gss_verify_mic_iov +( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t *, /* qop_state */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Release buffers that have the ALLOCATED flag set. + */ +OM_uint32 KRB5_CALLCONV gss_release_iov_buffer +( + OM_uint32 *, /* minor_status */ + gss_iov_buffer_desc *, /* iov */ + int); /* iov_count */ + +/* + * Protocol transition + */ +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_impersonate_name( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t, /* impersonator_cred_handle */ + const gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + const gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_impersonate_name( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + const gss_cred_id_t, /* impersonator_cred_handle */ + const gss_name_t, /* desired_name */ + const gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* + * Naming extensions + */ +GSS_DLLIMP extern gss_buffer_t GSS_C_ATTR_LOCAL_LOGIN_USER; +GSS_DLLIMP extern gss_OID GSS_C_NT_COMPOSITE_EXPORT; + +OM_uint32 KRB5_CALLCONV gss_display_name_ext +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_OID, /* display_as_name_type */ + gss_buffer_t /* display_name */ +); + +OM_uint32 KRB5_CALLCONV gss_inquire_name +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int *, /* name_is_MN */ + gss_OID *, /* MN_mech */ + gss_buffer_set_t * /* attrs */ +); + +OM_uint32 KRB5_CALLCONV gss_get_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t, /* attr */ + int *, /* authenticated */ + int *, /* complete */ + gss_buffer_t, /* value */ + gss_buffer_t, /* display_value */ + int * /* more */ +); + +OM_uint32 KRB5_CALLCONV gss_set_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int, /* complete */ + gss_buffer_t, /* attr */ + gss_buffer_t /* value */ +); + +OM_uint32 KRB5_CALLCONV gss_delete_name_attribute +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t /* attr */ +); + +OM_uint32 KRB5_CALLCONV gss_export_name_composite +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t /* exp_composite_name */ +); + +typedef struct gss_any *gss_any_t; + +OM_uint32 KRB5_CALLCONV gss_map_name_to_any +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + int, /* authenticated */ + gss_buffer_t, /* type_id */ + gss_any_t * /* output */ +); + +OM_uint32 KRB5_CALLCONV gss_release_any_name_mapping +( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name */ + gss_buffer_t, /* type_id */ + gss_any_t * /* input */ +); + +/* draft-josefsson-gss-capsulate */ +OM_uint32 KRB5_CALLCONV gss_encapsulate_token +( + gss_const_buffer_t, /* input_token */ + gss_const_OID, /* token_oid */ + gss_buffer_t /* output_token */ +); + +OM_uint32 KRB5_CALLCONV gss_decapsulate_token +( + gss_const_buffer_t, /* input_token */ + gss_const_OID, /* token_oid */ + gss_buffer_t /* output_token */ +); + +int KRB5_CALLCONV gss_oid_equal +( + gss_const_OID, /* first_oid */ + gss_const_OID /* second_oid */ +); + +/* Credential store extensions */ + +struct gss_key_value_element_struct { + const char *key; + const char *value; +}; +typedef struct gss_key_value_element_struct gss_key_value_element_desc; + +struct gss_key_value_set_struct { + OM_uint32 count; + gss_key_value_element_desc *elements; +}; +typedef struct gss_key_value_set_struct gss_key_value_set_desc; +typedef const gss_key_value_set_desc *gss_const_key_value_set_t; + +#define GSS_C_NO_CRED_STORE ((gss_const_key_value_set_t) 0) + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred_from( + OM_uint32 *, /* minor_status */ + gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_const_key_value_set_t, /* cred_store */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_add_cred_from( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_name_t, /* desired_name */ + gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_const_key_value_set_t, /* cred_store */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_store_cred_into( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_cred_usage_t, /* input_usage */ + gss_OID, /* desired_mech */ + OM_uint32, /* overwrite_cred */ + OM_uint32, /* default_cred */ + gss_const_key_value_set_t, /* cred_store */ + gss_OID_set *, /* elements_stored */ + gss_cred_usage_t *); /* cred_usage_stored */ + +#ifdef __cplusplus +} +#endif + +/* + * When used with gss_inquire_sec_context_by_oid(), return a buffer set with + * the first member containing an unsigned 32-bit integer in network byte + * order. This is the Security Strength Factor (SSF) associated with the + * secure channel established by the security context. NOTE: This value is + * made available solely as an indication for use by APIs like Cyrus SASL that + * classify the strength of a secure channel via this number. The strength of + * a channel cannot necessarily be represented by a simple number. + */ +GSS_DLLIMP extern gss_OID GSS_C_SEC_CONTEXT_SASL_SSF; + +#endif /* GSSAPI_EXT_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gssapi/gssapi_generic.h postgresql-hll-2.14/include/include/gssapi/gssapi_generic.h --- postgresql-hll-2.14_old/include/include/gssapi/gssapi_generic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi/gssapi_generic.h 2020-12-12 17:06:43.194347354 +0800 @@ -0,0 +1,59 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_GENERIC_H_ +#define _GSSAPI_GENERIC_H_ + +/* + * $Id$ + */ + +#include + +#if defined(__cplusplus) && !defined(GSSAPIGENERIC_BEGIN_DECLS) +#define GSSAPIGENERIC_BEGIN_DECLS extern "C" { +#define GSSAPIGENERIC_END_DECLS } +#else +#define GSSAPIGENERIC_BEGIN_DECLS +#define GSSAPIGENERIC_END_DECLS +#endif + +#define GSS_EMPTY_BUFFER(buf) ((buf) == NULL || \ + (buf)->value == NULL || (buf)->length == 0) + +GSSAPIGENERIC_BEGIN_DECLS + +/* Deprecated MIT krb5 oid names provided for compatibility. + * The correct oids (GSS_C_NT_USER_NAME, etc) from rfc 2744 + * are defined in gssapi.h. */ + +GSS_DLLIMP extern gss_OID gss_nt_user_name; +GSS_DLLIMP extern gss_OID gss_nt_machine_uid_name; +GSS_DLLIMP extern gss_OID gss_nt_string_uid_name; +extern gss_OID gss_nt_service_name_v2; +GSS_DLLIMP extern gss_OID gss_nt_service_name; +extern gss_OID gss_nt_exported_name; + +GSSAPIGENERIC_END_DECLS + +#endif /* _GSSAPI_GENERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gssapi/gssapi.h postgresql-hll-2.14/include/include/gssapi/gssapi.h --- postgresql-hll-2.14_old/include/include/gssapi/gssapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi/gssapi.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,923 @@ +/* This is the gssapi.h prologue. */ +/* no xom.h */ +/* End of gssapi.h prologue. */ +/* -*- mode: c; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_H_ +#define _GSSAPI_H_ + +/* + * Determine platform-dependent configuration. + */ + +#if defined(__MACH__) && defined(__APPLE__) +# include +# if TARGET_RT_MAC_CFM +# error "Use KfM 4.0 SDK headers for CFM compilation." +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(push,2) +#endif + +#if defined(_MSDOS) || defined(_WIN32) +#include +#endif + +#ifndef KRB5_CALLCONV +#define KRB5_CALLCONV +#define KRB5_CALLCONV_C +#endif + +#include + +/* + * First, include stddef.h to get size_t defined. + */ +#include + +/* + * POSIX says that sys/types.h is where size_t is defined. + */ +#include + +/* + * $Id$ + */ + +/* + * First, define the three platform-dependent pointer types. + */ + +struct gss_name_struct; +typedef struct gss_name_struct * gss_name_t; + +struct gss_cred_id_struct; +typedef struct gss_cred_id_struct * gss_cred_id_t; + +struct gss_ctx_id_struct; +typedef struct gss_ctx_id_struct * gss_ctx_id_t; + +/* + * The following type must be defined as the smallest natural unsigned integer + * supported by the platform that has at least 32 bits of precision. + */ +typedef uint32_t gss_uint32; +typedef int32_t gss_int32; + +#ifdef OM_STRING +/* + * We have included the xom.h header file. Use the definition for + * OM_object identifier. + */ +typedef OM_object_identifier gss_OID_desc, *gss_OID; +#else /* OM_STRING */ +/* + * We can't use X/Open definitions, so roll our own. + */ +typedef gss_uint32 OM_uint32; + +typedef struct gss_OID_desc_struct { + OM_uint32 length; + void *elements; +} gss_OID_desc, *gss_OID; +#endif /* OM_STRING */ + +typedef struct gss_OID_set_desc_struct { + size_t count; + gss_OID elements; +} gss_OID_set_desc, *gss_OID_set; + +typedef struct gss_buffer_desc_struct { + size_t length; + void *value; +} gss_buffer_desc, *gss_buffer_t; + +typedef struct gss_channel_bindings_struct { + OM_uint32 initiator_addrtype; + gss_buffer_desc initiator_address; + OM_uint32 acceptor_addrtype; + gss_buffer_desc acceptor_address; + gss_buffer_desc application_data; +} *gss_channel_bindings_t; + +/* + * For now, define a QOP-type as an OM_uint32 (pending resolution of ongoing + * discussions). + */ +typedef OM_uint32 gss_qop_t; +typedef int gss_cred_usage_t; + +/* + * Flag bits for context-level services. + */ +#define GSS_C_DELEG_FLAG 1 +#define GSS_C_MUTUAL_FLAG 2 +#define GSS_C_REPLAY_FLAG 4 +#define GSS_C_SEQUENCE_FLAG 8 +#define GSS_C_CONF_FLAG 16 +#define GSS_C_INTEG_FLAG 32 +#define GSS_C_ANON_FLAG 64 +#define GSS_C_PROT_READY_FLAG 128 +#define GSS_C_TRANS_FLAG 256 +#define GSS_C_DELEG_POLICY_FLAG 32768 + +/* + * Credential usage options + */ +#define GSS_C_BOTH 0 +#define GSS_C_INITIATE 1 +#define GSS_C_ACCEPT 2 + +/* + * Status code types for gss_display_status + */ +#define GSS_C_GSS_CODE 1 +#define GSS_C_MECH_CODE 2 + +/* + * The constant definitions for channel-bindings address families + */ +#define GSS_C_AF_UNSPEC 0 +#define GSS_C_AF_LOCAL 1 +#define GSS_C_AF_INET 2 +#define GSS_C_AF_IMPLINK 3 +#define GSS_C_AF_PUP 4 +#define GSS_C_AF_CHAOS 5 +#define GSS_C_AF_NS 6 +#define GSS_C_AF_NBS 7 +#define GSS_C_AF_ECMA 8 +#define GSS_C_AF_DATAKIT 9 +#define GSS_C_AF_CCITT 10 +#define GSS_C_AF_SNA 11 +#define GSS_C_AF_DECnet 12 +#define GSS_C_AF_DLI 13 +#define GSS_C_AF_LAT 14 +#define GSS_C_AF_HYLINK 15 +#define GSS_C_AF_APPLETALK 16 +#define GSS_C_AF_BSC 17 +#define GSS_C_AF_DSS 18 +#define GSS_C_AF_OSI 19 +#define GSS_C_AF_NETBIOS 20 +#define GSS_C_AF_X25 21 + +#define GSS_C_AF_NULLADDR 255 + +/* + * Various Null values. + */ +#define GSS_C_NO_NAME ((gss_name_t) 0) +#define GSS_C_NO_BUFFER ((gss_buffer_t) 0) +#define GSS_C_NO_OID ((gss_OID) 0) +#define GSS_C_NO_OID_SET ((gss_OID_set) 0) +#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0) +#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0) +#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0) +#define GSS_C_EMPTY_BUFFER {0, NULL} + +/* + * Some alternate names for a couple of the above values. These are defined + * for V1 compatibility. + */ +#define GSS_C_NULL_OID GSS_C_NO_OID +#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET + +/* + * Define the default Quality of Protection for per-message services. Note + * that an implementation that offers multiple levels of QOP may either reserve + * a value (for example zero, as assumed here) to mean "default protection", or + * alternatively may simply equate GSS_C_QOP_DEFAULT to a specific explicit + * QOP value. However a value of 0 should always be interpreted by a GSSAPI + * implementation as a request for the default protection level. + */ +#define GSS_C_QOP_DEFAULT 0 + +/* + * Expiration time of 2^32-1 seconds means infinite lifetime for a + * credential or security context + */ +#define GSS_C_INDEFINITE ((OM_uint32) 0xfffffffful) + + +/* Major status codes */ + +#define GSS_S_COMPLETE 0 + +/* + * Some "helper" definitions to make the status code macros obvious. + */ +#define GSS_C_CALLING_ERROR_OFFSET 24 +#define GSS_C_ROUTINE_ERROR_OFFSET 16 +#define GSS_C_SUPPLEMENTARY_OFFSET 0 +#define GSS_C_CALLING_ERROR_MASK ((OM_uint32) 0377ul) +#define GSS_C_ROUTINE_ERROR_MASK ((OM_uint32) 0377ul) +#define GSS_C_SUPPLEMENTARY_MASK ((OM_uint32) 0177777ul) + +/* + * The macros that test status codes for error conditions. Note that the + * GSS_ERROR() macro has changed slightly from the V1 GSSAPI so that it now + * evaluates its argument only once. + */ +#define GSS_CALLING_ERROR(x) \ + ((x) & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET)) +#define GSS_ROUTINE_ERROR(x) \ + ((x) & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)) +#define GSS_SUPPLEMENTARY_INFO(x) \ + ((x) & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET)) +#define GSS_ERROR(x) \ + ((x) & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \ + (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))) + +/* + * Now the actual status code definitions + */ + +/* + * Calling errors: + */ +#define GSS_S_CALL_INACCESSIBLE_READ \ + (((OM_uint32) 1ul) << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_INACCESSIBLE_WRITE \ + (((OM_uint32) 2ul) << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_BAD_STRUCTURE \ + (((OM_uint32) 3ul) << GSS_C_CALLING_ERROR_OFFSET) + +/* + * Routine errors: + */ +#define GSS_S_BAD_MECH (((OM_uint32) 1ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAME (((OM_uint32) 2ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAMETYPE (((OM_uint32) 3ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_BINDINGS (((OM_uint32) 4ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_STATUS (((OM_uint32) 5ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_SIG (((OM_uint32) 6ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MIC GSS_S_BAD_SIG +#define GSS_S_NO_CRED (((OM_uint32) 7ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NO_CONTEXT (((OM_uint32) 8ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_TOKEN (((OM_uint32) 9ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_CREDENTIAL \ + (((OM_uint32) 10ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CREDENTIALS_EXPIRED \ + (((OM_uint32) 11ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CONTEXT_EXPIRED \ + (((OM_uint32) 12ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_FAILURE (((OM_uint32) 13ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_QOP (((OM_uint32) 14ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAUTHORIZED (((OM_uint32) 15ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAVAILABLE (((OM_uint32) 16ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DUPLICATE_ELEMENT \ + (((OM_uint32) 17ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NAME_NOT_MN \ + (((OM_uint32) 18ul) << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MECH_ATTR \ + (((OM_uint32) 19ul) << GSS_C_ROUTINE_ERROR_OFFSET) + +/* + * Supplementary info bits: + */ +#define GSS_S_CONTINUE_NEEDED (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 0)) +#define GSS_S_DUPLICATE_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 1)) +#define GSS_S_OLD_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 2)) +#define GSS_S_UNSEQ_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 3)) +#define GSS_S_GAP_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 4)) + + +/* + * Finally, function prototypes for the GSSAPI routines. + */ + +#if defined (_WIN32) && defined (_MSC_VER) +# ifdef GSS_DLL_FILE +# define GSS_DLLIMP __declspec(dllexport) +# else +# define GSS_DLLIMP __declspec(dllimport) +# endif +#else +# define GSS_DLLIMP +#endif + +/* Reserved static storage for GSS_oids. Comments are quotes from RFC 2744. + * + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_USER_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_MACHINE_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_STRING_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + * corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x04"}, corresponding to an + * object-identifier value of {iso(1) member-body(2) + * Unites States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The constant + * GSS_C_NT_HOSTBASED_SERVICE should be initialized + * to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + * corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_ANONYMOUS; + + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + * corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_EXPORT_NAME; + +/* Function Prototypes */ + +OM_uint32 KRB5_CALLCONV +gss_acquire_cred( + OM_uint32 *, /* minor_status */ + gss_name_t, /* desired_name */ + OM_uint32, /* time_req */ + gss_OID_set, /* desired_mechs */ + gss_cred_usage_t, /* cred_usage */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_release_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t *); /* cred_handle */ + +OM_uint32 KRB5_CALLCONV +gss_init_sec_context( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* claimant_cred_handle */ + gss_ctx_id_t *, /* context_handle */ + gss_name_t, /* target_name */ + gss_OID, /* mech_type (used to be const) */ + OM_uint32, /* req_flags */ + OM_uint32, /* time_req */ + gss_channel_bindings_t, /* input_chan_bindings */ + gss_buffer_t, /* input_token */ + gss_OID *, /* actual_mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 *); /* time_rec */ + +OM_uint32 KRB5_CALLCONV +gss_accept_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_cred_id_t, /* acceptor_cred_handle */ + gss_buffer_t, /* input_token_buffer */ + gss_channel_bindings_t, /* input_chan_bindings */ + gss_name_t *, /* src_name */ + gss_OID *, /* mech_type */ + gss_buffer_t, /* output_token */ + OM_uint32 *, /* ret_flags */ + OM_uint32 *, /* time_rec */ + gss_cred_id_t *); /* delegated_cred_handle */ + +OM_uint32 KRB5_CALLCONV +gss_process_context_token( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t); /* token_buffer */ + + +OM_uint32 KRB5_CALLCONV +gss_delete_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t); /* output_token */ + + +OM_uint32 KRB5_CALLCONV +gss_context_time( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + OM_uint32 *); /* time_rec */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_get_mic( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_qop_t, /* qop_req */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t); /* message_token */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_verify_mic(OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t, /* message_token */ + gss_qop_t * /* qop_state */ +); + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_wrap( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t); /* output_message_buffer */ + + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_unwrap( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + gss_qop_t *); /* qop_state */ + + +OM_uint32 KRB5_CALLCONV +gss_display_status( + OM_uint32 *, /* minor_status */ + OM_uint32, /* status_value */ + int, /* status_type */ + gss_OID, /* mech_type (used to be const) */ + OM_uint32 *, /* message_context */ + gss_buffer_t); /* status_string */ + + +OM_uint32 KRB5_CALLCONV +gss_indicate_mechs( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* mech_set */ + + +OM_uint32 KRB5_CALLCONV +gss_compare_name( + OM_uint32 *, /* minor_status */ + gss_name_t, /* name1 */ + gss_name_t, /* name2 */ + int *); /* name_equal */ + + +OM_uint32 KRB5_CALLCONV +gss_display_name( + OM_uint32 *, /* minor_status */ + gss_name_t, /* input_name */ + gss_buffer_t, /* output_name_buffer */ + gss_OID *); /* output_name_type */ + + +OM_uint32 KRB5_CALLCONV +gss_import_name( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* input_name_buffer */ + gss_OID, /* input_name_type(used to be const) */ + gss_name_t *); /* output_name */ + +OM_uint32 KRB5_CALLCONV +gss_release_name( + OM_uint32 *, /* minor_status */ + gss_name_t *); /* input_name */ + +OM_uint32 KRB5_CALLCONV +gss_release_buffer( + OM_uint32 *, /* minor_status */ + gss_buffer_t); /* buffer */ + +OM_uint32 KRB5_CALLCONV +gss_release_oid_set( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* set */ + +OM_uint32 KRB5_CALLCONV +gss_inquire_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + gss_name_t *, /* name */ + OM_uint32 *, /* lifetime */ + gss_cred_usage_t *, /* cred_usage */ + gss_OID_set *); /* mechanisms */ + +/* Last argument new for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_name_t *, /* src_name */ + gss_name_t *, /* targ_name */ + OM_uint32 *, /* lifetime_rec */ + gss_OID *, /* mech_type */ + OM_uint32 *, /* ctx_flags */ + int *, /* locally_initiated */ + int *); /* open */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_wrap_size_limit( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + gss_qop_t, /* qop_req */ + OM_uint32, /* req_output_size */ + OM_uint32 *); /* max_input_size */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_import_name_object( + OM_uint32 *, /* minor_status */ + void *, /* input_name */ + gss_OID, /* input_name_type */ + gss_name_t *); /* output_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_name_object( + OM_uint32 *, /* minor_status */ + gss_name_t, /* input_name */ + gss_OID, /* desired_name_type */ + void **); /* output_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_add_cred( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* input_cred_handle */ + gss_name_t, /* desired_name */ + gss_OID, /* desired_mech */ + gss_cred_usage_t, /* cred_usage */ + OM_uint32, /* initiator_time_req */ + OM_uint32, /* acceptor_time_req */ + gss_cred_id_t *, /* output_cred_handle */ + gss_OID_set *, /* actual_mechs */ + OM_uint32 *, /* initiator_time_rec */ + OM_uint32 *); /* acceptor_time_rec */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_cred_by_mech( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + gss_OID, /* mech_type */ + gss_name_t *, /* name */ + OM_uint32 *, /* initiator_lifetime */ + OM_uint32 *, /* acceptor_lifetime */ + gss_cred_usage_t *); /* cred_usage */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_sec_context( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t *, /* context_handle */ + gss_buffer_t); /* interprocess_token */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_import_sec_context( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* interprocess_token */ + gss_ctx_id_t *); /* context_handle */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_release_oid( + OM_uint32 *, /* minor_status */ + gss_OID *); /* oid */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_create_empty_oid_set( + OM_uint32 *, /* minor_status */ + gss_OID_set *); /* oid_set */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_add_oid_set_member( + OM_uint32 *, /* minor_status */ + gss_OID, /* member_oid */ + gss_OID_set *); /* oid_set */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_test_oid_set_member( + OM_uint32 *, /* minor_status */ + gss_OID, /* member */ + gss_OID_set, /* set */ + int *); /* present */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_str_to_oid( + OM_uint32 *, /* minor_status */ + gss_buffer_t, /* oid_str */ + gss_OID *); /* oid */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_oid_to_str( + OM_uint32 *, /* minor_status */ + gss_OID, /* oid */ + gss_buffer_t); /* oid_str */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_names_for_mech( + OM_uint32 *, /* minor_status */ + gss_OID, /* mechanism */ + gss_OID_set *); /* name_types */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_inquire_mechs_for_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_OID_set *); /* mech_types */ + +/* + * The following routines are obsolete variants of gss_get_mic, gss_wrap, + * gss_verify_mic and gss_unwrap. They should be provided by GSSAPI V2 + * implementations for backwards compatibility with V1 applications. Distinct + * entrypoints (as opposed to #defines) should be provided, to allow GSSAPI + * V1 applications to link against GSSAPI V2 implementations. + */ +OM_uint32 KRB5_CALLCONV +gss_sign( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* qop_req */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t); /* message_token */ + +OM_uint32 KRB5_CALLCONV +gss_verify( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* message_buffer */ + gss_buffer_t, /* token_buffer */ + int *); /* qop_state */ + +OM_uint32 KRB5_CALLCONV +gss_seal( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + int, /* conf_req_flag */ + int, /* qop_req */ + gss_buffer_t, /* input_message_buffer */ + int *, /* conf_state */ + gss_buffer_t); /* output_message_buffer */ + +OM_uint32 KRB5_CALLCONV +gss_unseal( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context_handle */ + gss_buffer_t, /* input_message_buffer */ + gss_buffer_t, /* output_message_buffer */ + int *, /* conf_state */ + int *); /* qop_state */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_export_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_buffer_t); /* exported_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_duplicate_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + gss_name_t *); /* dest_name */ + +/* New for V2 */ +OM_uint32 KRB5_CALLCONV +gss_canonicalize_name( + OM_uint32 *, /* minor_status */ + const gss_name_t, /* input_name */ + const gss_OID, /* mech_type */ + gss_name_t *); /* output_name */ + +/* RFC 4401 */ + +#define GSS_C_PRF_KEY_FULL 0 +#define GSS_C_PRF_KEY_PARTIAL 1 + +OM_uint32 KRB5_CALLCONV +gss_pseudo_random( + OM_uint32 *, /* minor_status */ + gss_ctx_id_t, /* context */ + int, /* prf_key */ + const gss_buffer_t, /* prf_in */ + ssize_t, /* desired_output_len */ + gss_buffer_t); /* prf_out */ + +OM_uint32 KRB5_CALLCONV +gss_store_cred( + OM_uint32 *, /* minor_status */ + const gss_cred_id_t,/* input_cred_handle */ + gss_cred_usage_t, /* input_usage */ + const gss_OID, /* desired_mech */ + OM_uint32, /* overwrite_cred */ + OM_uint32, /* default_cred */ + gss_OID_set *, /* elements_stored */ + gss_cred_usage_t *);/* cred_usage_stored */ + +OM_uint32 KRB5_CALLCONV +gss_set_neg_mechs( + OM_uint32 *, /* minor_status */ + gss_cred_id_t, /* cred_handle */ + const gss_OID_set); /* mech_set */ + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif + +/* XXXX these are not part of the GSSAPI C bindings! (but should be) */ + +#define GSS_CALLING_ERROR_FIELD(x) \ + (((x) >> GSS_C_CALLING_ERROR_OFFSET) & GSS_C_CALLING_ERROR_MASK) +#define GSS_ROUTINE_ERROR_FIELD(x) \ + (((x) >> GSS_C_ROUTINE_ERROR_OFFSET) & GSS_C_ROUTINE_ERROR_MASK) +#define GSS_SUPPLEMENTARY_INFO_FIELD(x) \ + (((x) >> GSS_C_SUPPLEMENTARY_OFFSET) & GSS_C_SUPPLEMENTARY_MASK) + +/* XXXX This is a necessary evil until the spec is fixed */ +#define GSS_S_CRED_UNAVAIL GSS_S_FAILURE + +/* + * RFC 5587 + */ +typedef const gss_buffer_desc *gss_const_buffer_t; +typedef const struct gss_channel_bindings_struct *gss_const_channel_bindings_t; +typedef const struct gss_ctx_id_struct *gss_const_ctx_id_t; +typedef const struct gss_cred_id_struct *gss_const_cred_id_t; +typedef const struct gss_name_struct *gss_const_name_t; +typedef const gss_OID_desc *gss_const_OID; +typedef const gss_OID_set_desc *gss_const_OID_set; + +OM_uint32 KRB5_CALLCONV +gss_indicate_mechs_by_attrs( + OM_uint32 *, /* minor_status */ + gss_const_OID_set, /* desired_mech_attrs */ + gss_const_OID_set, /* except_mech_attrs */ + gss_const_OID_set, /* critical_mech_attrs */ + gss_OID_set *); /* mechs */ + +OM_uint32 KRB5_CALLCONV +gss_inquire_attrs_for_mech( + OM_uint32 *, /* minor_status */ + gss_const_OID, /* mech */ + gss_OID_set *, /* mech_attrs */ + gss_OID_set *); /* known_mech_attrs */ + +OM_uint32 KRB5_CALLCONV +gss_display_mech_attr( + OM_uint32 *, /* minor_status */ + gss_const_OID, /* mech_attr */ + gss_buffer_t, /* name */ + gss_buffer_t, /* short_desc */ + gss_buffer_t); /* long_desc */ + +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_CONCRETE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_PSEUDO; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_COMPOSITE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_NEGO; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MECH_GLUE; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_NOT_MECH; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_DEPRECATED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_NOT_DFLT_MECH; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_ITOK_FRAMED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG_INIT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_INIT_ANON; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_AUTH_TARG_ANON; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_DELEG_CRED; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_INTEG_PROT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CONF_PROT; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_MIC; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_WRAP; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_PROT_READY; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_REPLAY_DET; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_OOS_DET; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CBINDINGS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_PFS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_COMPRESS; +GSS_DLLIMP extern gss_const_OID GSS_C_MA_CTX_TRANS; + +/* + * RFC 5801 + */ +OM_uint32 KRB5_CALLCONV +gss_inquire_saslname_for_mech( + OM_uint32 *, /* minor_status */ + const gss_OID, /* desired_mech */ + gss_buffer_t, /* sasl_mech_name */ + gss_buffer_t, /* mech_name */ + gss_buffer_t /* mech_description */ +); + +OM_uint32 KRB5_CALLCONV +gss_inquire_mech_for_saslname( + OM_uint32 *, /* minor_status */ + const gss_buffer_t, /* sasl_mech_name */ + gss_OID * /* mech_type */ +); + +#endif /* _GSSAPI_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gssapi/gssapi_krb5.h postgresql-hll-2.14/include/include/gssapi/gssapi_krb5.h --- postgresql-hll-2.14_old/include/include/gssapi/gssapi_krb5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi/gssapi_krb5.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,300 @@ +/* -*- mode: c; indent-tabs-mode: nil -*- */ +/* + * Copyright 1993 by OpenVision Technologies, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _GSSAPI_KRB5_H_ +#define _GSSAPI_KRB5_H_ + +#include +#include +#include +#include + +/* C++ friendlyness */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Reserved static storage for GSS_oids. See rfc 1964 for more details. */ + +/* 2.1.1. Kerberos Principal Name Form: */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_NT_PRINCIPAL_NAME; +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5_name(1)}. The recommended symbolic name for this type + * is "GSS_KRB5_NT_PRINCIPAL_NAME". */ + +/* 2.1.2. Host-Based Service Name Form */ +#define GSS_KRB5_NT_HOSTBASED_SERVICE_NAME GSS_C_NT_HOSTBASED_SERVICE +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The previously recommended symbolic + * name for this type is "GSS_KRB5_NT_HOSTBASED_SERVICE_NAME". The + * currently preferred symbolic name for this type is + * "GSS_C_NT_HOSTBASED_SERVICE". */ + +/* 2.2.1. User Name Form */ +#define GSS_KRB5_NT_USER_NAME GSS_C_NT_USER_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) user_name(1)}. The recommended symbolic name for this + * type is "GSS_KRB5_NT_USER_NAME". */ + +/* 2.2.2. Machine UID Form */ +#define GSS_KRB5_NT_MACHINE_UID_NAME GSS_C_NT_MACHINE_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) machine_uid_name(2)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_MACHINE_UID_NAME". */ + +/* 2.2.3. String UID Form */ +#define GSS_KRB5_NT_STRING_UID_NAME GSS_C_NT_STRING_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) string_uid_name(3)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_STRING_UID_NAME". */ + +/* Kerberos Enterprise Name Form (see RFC 6806 section 5): */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_NT_ENTERPRISE_NAME; +/* {iso(1) member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5-enterprise-name(6)}. */ + +GSS_DLLIMP extern const gss_OID gss_mech_krb5; +GSS_DLLIMP extern const gss_OID gss_mech_krb5_old; +GSS_DLLIMP extern const gss_OID gss_mech_krb5_wrong; +GSS_DLLIMP extern const gss_OID gss_mech_iakerb; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5_old; +GSS_DLLIMP extern const gss_OID_set gss_mech_set_krb5_both; + +GSS_DLLIMP extern const gss_OID gss_nt_krb5_name; +GSS_DLLIMP extern const gss_OID gss_nt_krb5_principal; + +GSS_DLLIMP extern const gss_OID_desc krb5_gss_oid_array[]; + +/* + * This OID can be used with gss_set_cred_option() to suppress the + * confidentiality and integrity flags from being asserted in initial context + * tokens. + * + * iso(1) member-body(2) Sweden(752) Stockholm University(43) Heimdal GSS-API + * Extensions(13) no_ci_flags(29) + */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_CRED_NO_CI_FLAGS_X; + +/* + * This OID can be used with gss_inquire_cred_by_oid(0 to retrieve the + * impersonator name (if any). + * + * iso(1) member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5-gssapi-ext(5) get-cred-impersonator(14) + */ +GSS_DLLIMP extern const gss_OID GSS_KRB5_GET_CRED_IMPERSONATOR; + +#define gss_krb5_nt_general_name gss_nt_krb5_name +#define gss_krb5_nt_principal gss_nt_krb5_principal +#define gss_krb5_nt_service_name gss_nt_service_name +#define gss_krb5_nt_user_name gss_nt_user_name +#define gss_krb5_nt_machine_uid_name gss_nt_machine_uid_name +#define gss_krb5_nt_string_uid_name gss_nt_string_uid_name + +typedef struct gss_krb5_lucid_key { + OM_uint32 type; /* key encryption type */ + OM_uint32 length; /* length of key data */ + void * data; /* actual key data */ +} gss_krb5_lucid_key_t; + +typedef struct gss_krb5_rfc1964_keydata { + OM_uint32 sign_alg; /* signing algorthm */ + OM_uint32 seal_alg; /* seal/encrypt algorithm */ + gss_krb5_lucid_key_t ctx_key; + /* Context key + (Kerberos session key or subkey) */ +} gss_krb5_rfc1964_keydata_t; + +typedef struct gss_krb5_cfx_keydata { + OM_uint32 have_acceptor_subkey; + /* 1 if there is an acceptor_subkey + present, 0 otherwise */ + gss_krb5_lucid_key_t ctx_key; + /* Context key + (Kerberos session key or subkey) */ + gss_krb5_lucid_key_t acceptor_subkey; + /* acceptor-asserted subkey or + 0's if no acceptor subkey */ +} gss_krb5_cfx_keydata_t; + +typedef struct gss_krb5_lucid_context_v1 { + OM_uint32 version; /* Structure version number (1) + MUST be at beginning of struct! */ + OM_uint32 initiate; /* Are we the initiator? */ + OM_uint32 endtime; /* expiration time of context */ + uint64_t send_seq; /* sender sequence number */ + uint64_t recv_seq; /* receive sequence number */ + OM_uint32 protocol; /* 0: rfc1964, + 1: draft-ietf-krb-wg-gssapi-cfx-07 */ + /* + * if (protocol == 0) rfc1964_kd should be used + * and cfx_kd contents are invalid and should be zero + * if (protocol == 1) cfx_kd should be used + * and rfc1964_kd contents are invalid and should be zero + */ + gss_krb5_rfc1964_keydata_t rfc1964_kd; + gss_krb5_cfx_keydata_t cfx_kd; +} gss_krb5_lucid_context_v1_t; + +/* + * Mask for determining the version of a lucid context structure. Callers + * should not require this. + */ +typedef struct gss_krb5_lucid_context_version { + OM_uint32 version; /* Structure version number */ +} gss_krb5_lucid_context_version_t; + + + + +/* Alias for Heimdal compat. */ +#define gsskrb5_register_acceptor_identity krb5_gss_register_acceptor_identity + +OM_uint32 KRB5_CALLCONV krb5_gss_register_acceptor_identity(const char *); + +OM_uint32 KRB5_CALLCONV gss_krb5_get_tkt_flags( + OM_uint32 *minor_status, + gss_ctx_id_t context_handle, + krb5_flags *ticket_flags); + +/* + * Copy krb5 creds from cred_handle into out_ccache, which must already be + * initialized. Use gss_store_cred_into() (new in krb5 1.11) instead, if + * possible. + */ +OM_uint32 KRB5_CALLCONV gss_krb5_copy_ccache( + OM_uint32 *minor_status, + gss_cred_id_t cred_handle, + krb5_ccache out_ccache); + +OM_uint32 KRB5_CALLCONV gss_krb5_ccache_name( + OM_uint32 *minor_status, const char *name, + const char **out_name); + +/* + * gss_krb5_set_allowable_enctypes + * + * This function may be called by a context initiator after calling + * gss_acquire_cred(), but before calling gss_init_sec_context(), + * to restrict the set of enctypes which will be negotiated during + * context establishment to those in the provided array. + * + * 'cred' must be a valid credential handle obtained via + * gss_acquire_cred(). It may not be GSS_C_NO_CREDENTIAL. + * gss_acquire_cred() may have been called to get a handle to + * the default credential. + * + * The purpose of this function is to limit the keys that may + * be exported via gss_krb5_export_lucid_sec_context(); thus it + * should limit the enctypes of all keys that will be needed + * after the security context has been established. + * (i.e. context establishment may use a session key with a + * stronger enctype than in the provided array, however a + * subkey must be established within the enctype limits + * established by this function.) + * + */ +OM_uint32 KRB5_CALLCONV +gss_krb5_set_allowable_enctypes(OM_uint32 *minor_status, + gss_cred_id_t cred, + OM_uint32 num_ktypes, + krb5_enctype *ktypes); + +/* + * Returns a non-opaque (lucid) version of the internal context + * information. + * + * Note that context_handle must not be used again by the caller + * after this call. The GSS implementation is free to release any + * resources associated with the original context. It is up to the + * GSS implementation whether it returns pointers to existing data, + * or copies of the data. The caller should treat the returned + * lucid context as read-only. + * + * The caller must call gss_krb5_free_lucid_context() to free + * the context and allocated resources when it is finished with it. + * + * 'version' is an integer indicating the requested version of the lucid + * context. If the implementation does not understand the requested version, + * it will return an error. + * + * For example: + * void *return_ctx; + * gss_krb5_lucid_context_v1_t *ctx; + * OM_uint32 min_stat, maj_stat; + * OM_uint32 vers; + * gss_ctx_id_t *ctx_handle; + * + * maj_stat = gss_krb5_export_lucid_sec_context(&min_stat, + * ctx_handle, 1, &return_ctx); + * // Verify success + * ctx = (gss_krb5_lucid_context_v1_t *) return_ctx; + */ + +OM_uint32 KRB5_CALLCONV +gss_krb5_export_lucid_sec_context(OM_uint32 *minor_status, + gss_ctx_id_t *context_handle, + OM_uint32 version, + void **kctx); + +/* + * Frees the allocated storage associated with an + * exported struct gss_krb5_lucid_context. + */ +OM_uint32 KRB5_CALLCONV +gss_krb5_free_lucid_sec_context(OM_uint32 *minor_status, + void *kctx); + + +OM_uint32 KRB5_CALLCONV +gsskrb5_extract_authz_data_from_sec_context(OM_uint32 *minor_status, + const gss_ctx_id_t context_handle, + int ad_type, + gss_buffer_t ad_data); + +OM_uint32 KRB5_CALLCONV +gss_krb5_set_cred_rcache(OM_uint32 *minor_status, + gss_cred_id_t cred, + krb5_rcache rcache); + +OM_uint32 KRB5_CALLCONV +gsskrb5_extract_authtime_from_sec_context(OM_uint32 *, gss_ctx_id_t, krb5_timestamp *); + +OM_uint32 KRB5_CALLCONV +gss_krb5_import_cred(OM_uint32 *minor_status, + krb5_ccache id, + krb5_principal keytab_principal, + krb5_keytab keytab, + gss_cred_id_t *cred); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _GSSAPI_KRB5_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gssapi/mechglue.h postgresql-hll-2.14/include/include/gssapi/mechglue.h --- postgresql-hll-2.14_old/include/include/gssapi/mechglue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi/mechglue.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,42 @@ +/* #ident "@(#)mechglue.h 1.13 95/08/07 SMI" */ + +/* + * Copyright 1996 by Sun Microsystems, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of Sun Microsystems not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. Sun Microsystems makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * This header contains the mechglue definitions. + */ + +#ifndef _GSS_MECHGLUE_H +#define _GSS_MECHGLUE_H + +#include + +/********************************************************/ +/* GSSAPI Extension functions -- these functions aren't */ +/* in the GSSAPI, but they are provided in this library */ + +#include + +void KRB5_CALLCONV gss_initialize(void); + +#endif /* _GSS_MECHGLUE_H */ diff -uprN postgresql-hll-2.14_old/include/include/gssapi.h postgresql-hll-2.14/include/include/gssapi.h --- postgresql-hll-2.14_old/include/include/gssapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssapi.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,6 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Wrapper so that #include will work without special include + * paths. + */ +#include diff -uprN postgresql-hll-2.14_old/include/include/gssignal/gs_signal.h postgresql-hll-2.14/include/include/gssignal/gs_signal.h --- postgresql-hll-2.14_old/include/include/gssignal/gs_signal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssignal/gs_signal.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,181 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_signal.h + * + * + * + * IDENTIFICATION + * src/include/gssignal/gs_signal.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_SIGNAL_H_ +#define GS_SIGNAL_H_ + +#include "gs_thread.h" +#include +#include "storage/s_lock.h" +#include + +#ifdef WIN32 +#include "pthread-win32.h" +#endif + +#define GS_SIGNAL_COUNT 32 + +typedef void (*gs_sigfunc)(int); + +#ifdef WIN32 +typedef int sigset_t; +#endif + +typedef enum GsSignalCheckType { + SIGNAL_CHECK_NONE, + SIGNAL_CHECK_EXECUTOR_STOP, + SIGNAL_CHECK_STREAM_STOP, + SIGNAL_CHECK_SESS_KEY +} GsSignalCheckType; + +/* the struct of signal check */ +typedef struct GsSignalCheck { + GsSignalCheckType check_type; + uint64 debug_query_id; + uint64 session_id; +} GsSignalCheck; + +/* the struct of signal to be handled and the signal sender's thread id */ +typedef struct GsSndSignal { + unsigned int signo; /* the signal to be handled */ + gs_thread_t thread; /* the signal sender's thread id */ + GsSignalCheck check; /* the signal sender's check information if need check */ +} GsSndSignal; + +/* the list struct of GsSndSignal */ +typedef struct GsNode { + GsSndSignal sig_data; + struct GsNode* next; +} GsNode; + +/* + * Each thread has a signal pool, which contains the used signal list and free signal list. + * free signal list keeps the free signal slots for this thread. + * used signal list keeps the signal which will be handled for this thread. + * When a analog signal arrives, it will search a free signal slot, fill the sig_data + * then put it info the used list; after a signal handled, the used slot will be put + * back to the free list. + */ +typedef struct SignalPool { + GsNode* free_head; /* the head of free signal list */ + GsNode* free_tail; /* the tail of free signal list */ + GsNode* used_head; /* the head of used signal list */ + GsNode* used_tail; /* the tail of used signal list */ + int pool_size; /* the size of the array list */ + pthread_mutex_t sigpool_lock; +} SignalPool; + +/* the struct keeps signal handle function array and signal pool for each thread */ +typedef struct GsSignal { + gs_sigfunc handlerList[GS_SIGNAL_COUNT]; + sigset_t masksignal; + SignalPool sig_pool; +#ifndef WIN32 + volatile unsigned int bitmapSigProtectFun; +#else + HANDLE signal_event; +#endif +} GsSignal; + +/* each thread has a GsSignalSlot to keep their thread id, thread name, signals and signal handles */ +typedef struct GsSignalSlot { + ThreadId thread_id; + char* thread_name; + GsSignal* gssignal; +} GsSignalSlot; + +typedef volatile int gs_atomic_t; + +#ifndef WIN32 +extern sigset_t gs_signal_unblock_sigusr2(void); + +extern sigset_t gs_signal_block_sigusr2(void); + +extern void gs_signal_recover_mask(sigset_t mask); + +#else + +#define gs_signal_unblock_sigusr2() 0 +#define gs_signal_block_sigusr2() 0 +#define gs_signal_recover_mask(_mask) _mask + +#endif + +#ifndef WIN32 +typedef void (*gs_sigaction_func) (int, siginfo_t *, void *); +#endif + +/* global GsSignalSlot manager, keeps all threads' GsSignalSlot */ +typedef struct GsSignalBase { + GsSignalSlot* slots; + unsigned int slots_size; + pthread_mutex_t slots_lock; +} GsSignalBase; + +#ifdef WIN32 +#define pgwin32_signal_event (MySignalSlot->gssignal->signal_event) +#endif + +extern gs_sigfunc gspqsignal(int signo, gs_sigfunc func); + +extern void gs_signal_setmask(sigset_t* mask, sigset_t* old_mask); + +/* + * initialize signal slots + */ +extern void gs_signal_slots_init(unsigned long size); + +extern GsSignalSlot* gs_signal_slot_release(ThreadId thread_id); + +/*gs send signal to thread*/ +extern int gs_signal_send(ThreadId thread_id, int signo, int nowait = 0); +extern int gs_signal_send(ThreadId thread_id, int signo, bool is_thread_pool); + +extern void gs_signal_startup_siginfo(char* thread_name); + +extern int gs_thread_kill(ThreadId tid, int sig); + +extern void gs_signal_handle(void); + +/* Create timer support for current thread */ +extern int gs_signal_createtimer(void); + +/* A thread-safe version replacement of setitimer () call. */ +extern int gs_signal_settimer(struct itimerval* interval); + +/* A thread-safe version replacement of CancelTimer (0) call. */ +extern int gs_signal_canceltimer(void); + +/* A thread-safe version replacement of delteitimer (0) call. */ +extern int gs_signal_deletetimer(void); + +extern void gs_signal_monitor_startup(void); + +#ifdef WIN32 +#define pgwin32_dispatch_queued_signals gs_signal_handle +#define UNBLOCKED_SIGNAL_QUEUE() true +#endif + +#endif /* GS_SIGNAL_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/auth_gssapi.h postgresql-hll-2.14/include/include/gssrpc/auth_gssapi.h --- postgresql-hll-2.14_old/include/include/gssrpc/auth_gssapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/auth_gssapi.h 2020-12-12 17:06:43.195347367 +0800 @@ -0,0 +1,162 @@ +/* include/gssrpc/auth_gssapi.h - GSS-API style auth parameters for RPC */ +/* + * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved. + */ + +#ifndef GSSRPC_AUTH_GSSAPI_H +#define GSSRPC_AUTH_GSSAPI_H + +GSSRPC__BEGIN_DECLS + +#define AUTH_GSSAPI_EXIT 0 +#define AUTH_GSSAPI_INIT 1 +#define AUTH_GSSAPI_CONTINUE_INIT 2 +#define AUTH_GSSAPI_MSG 3 +#define AUTH_GSSAPI_DESTROY 4 + +/* + * Yuck. Some sys/types.h files leak symbols + */ +#ifdef major +#undef major +#endif +#ifdef minor +#undef minor +#endif + +typedef struct _auth_gssapi_name { + char *name; + gss_OID type; +} auth_gssapi_name; + +typedef struct _auth_gssapi_creds { + uint32_t version; + bool_t auth_msg; + gss_buffer_desc client_handle; +} auth_gssapi_creds; + +typedef struct _auth_gssapi_init_arg { + uint32_t version; + gss_buffer_desc token; +} auth_gssapi_init_arg; + +typedef struct _auth_gssapi_init_res { + uint32_t version; + gss_buffer_desc client_handle; + OM_uint32 gss_major, gss_minor; + gss_buffer_desc token; + gss_buffer_desc signed_isn; +} auth_gssapi_init_res; + +typedef void (*auth_gssapi_log_badauth_func) + (OM_uint32 major, + OM_uint32 minor, + struct sockaddr_in *raddr, + caddr_t data); + +/* auth_gssapi_log_badauth_func is IPv4-specific; this version gives the + * transport handle so the fd can be used to get the address. */ +typedef void (*auth_gssapi_log_badauth2_func) + (OM_uint32 major, + OM_uint32 minor, + SVCXPRT *xprt, + caddr_t data); + +typedef void (*auth_gssapi_log_badverf_func) + (gss_name_t client, + gss_name_t server, + struct svc_req *rqst, + struct rpc_msg *msg, + caddr_t data); + +typedef void (*auth_gssapi_log_miscerr_func) + (struct svc_req *rqst, + struct rpc_msg *msg, + char *error, + caddr_t data); + +bool_t xdr_gss_buf(XDR *, gss_buffer_t); +bool_t xdr_authgssapi_creds(XDR *, auth_gssapi_creds *); +bool_t xdr_authgssapi_init_arg(XDR *, auth_gssapi_init_arg *); +bool_t xdr_authgssapi_init_res(XDR *, auth_gssapi_init_res *); + +bool_t auth_gssapi_wrap_data +(OM_uint32 *major, OM_uint32 *minor, + gss_ctx_id_t context, uint32_t seq_num, XDR + *out_xdrs, bool_t (*xdr_func)(), caddr_t + xdr_ptr); +bool_t auth_gssapi_unwrap_data +(OM_uint32 *major, OM_uint32 *minor, + gss_ctx_id_t context, uint32_t seq_num, XDR + *in_xdrs, bool_t (*xdr_func)(), caddr_t + xdr_ptr); + +AUTH *auth_gssapi_create +(CLIENT *clnt, + OM_uint32 *major_status, + OM_uint32 *minor_status, + gss_cred_id_t claimant_cred_handle, + gss_name_t target_name, + gss_OID mech_type, + OM_uint32 req_flags, + OM_uint32 time_req, + gss_OID *actual_mech_type, + OM_uint32 *ret_flags, + OM_uint32 *time_rec); + +AUTH *auth_gssapi_create_default +(CLIENT *clnt, char *service_name); + +void auth_gssapi_display_status +(char *msg, OM_uint32 major, + OM_uint32 minor); + +bool_t auth_gssapi_seal_seq +(gss_ctx_id_t context, uint32_t seq_num, gss_buffer_t out_buf); + +bool_t auth_gssapi_unseal_seq +(gss_ctx_id_t context, gss_buffer_t in_buf, uint32_t *seq_num); + +bool_t svcauth_gssapi_set_names +(auth_gssapi_name *names, int num); +void svcauth_gssapi_unset_names +(void); + +void svcauth_gssapi_set_log_badauth_func +(auth_gssapi_log_badauth_func func, + caddr_t data); +void svcauth_gssapi_set_log_badauth2_func +(auth_gssapi_log_badauth2_func func, + caddr_t data); +void svcauth_gssapi_set_log_badverf_func +(auth_gssapi_log_badverf_func func, + caddr_t data); +void svcauth_gssapi_set_log_miscerr_func +(auth_gssapi_log_miscerr_func func, + caddr_t data); + +void svcauth_gss_set_log_badauth_func(auth_gssapi_log_badauth_func, + caddr_t); +void svcauth_gss_set_log_badauth2_func(auth_gssapi_log_badauth2_func, + caddr_t); +void svcauth_gss_set_log_badverf_func(auth_gssapi_log_badverf_func, + caddr_t); +void svcauth_gss_set_log_miscerr_func(auth_gssapi_log_miscerr_func, + caddr_t data); + +#define GSS_COPY_BUFFER(dest, src) { \ + (dest).length = (src).length; \ + (dest).value = (src).value; } + +#define GSS_DUP_BUFFER(dest, src) { \ + (dest).length = (src).length; \ + (dest).value = (void *) malloc((dest).length); \ + memcpy((dest).value, (src).value, (dest).length); } + +#define GSS_BUFFERS_EQUAL(b1, b2) (((b1).length == (b2).length) && \ + !memcmp((b1).value,(b2).value,(b1.length))) + + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_AUTH_GSSAPI_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/auth_gss.h postgresql-hll-2.14/include/include/gssrpc/auth_gss.h --- postgresql-hll-2.14_old/include/include/gssrpc/auth_gss.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/auth_gss.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,148 @@ +/* include/gssrpc/auth_gss.h */ +/* + Copyright (c) 2000 The Regents of the University of Michigan. + All rights reserved. + + Copyright (c) 2000 Dug Song . + All rights reserved, all wrongs reversed. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the University nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Id: auth_gss.h,v 1.13 2002/05/08 16:54:33 andros Exp +*/ + +#ifndef GSSRPC_AUTH_GSS_H +#define GSSRPC_AUTH_GSS_H + +#include +#include +#ifdef HAVE_HEIMDAL +#include +#else +#include +#endif + +GSSRPC__BEGIN_DECLS + +/* RPCSEC_GSS control procedures. */ +typedef enum { + RPCSEC_GSS_DATA = 0, + RPCSEC_GSS_INIT = 1, + RPCSEC_GSS_CONTINUE_INIT = 2, + RPCSEC_GSS_DESTROY = 3 +} rpc_gss_proc_t; + +/* RPCSEC_GSS services. */ +typedef enum { + RPCSEC_GSS_SVC_NONE = 1, + RPCSEC_GSS_SVC_INTEGRITY = 2, + RPCSEC_GSS_SVC_PRIVACY = 3 +} rpc_gss_svc_t; + +#define RPCSEC_GSS_VERSION 1 + +/* RPCSEC_GSS security triple. */ +struct rpc_gss_sec { + gss_OID mech; /* mechanism */ + gss_qop_t qop; /* quality of protection */ + rpc_gss_svc_t svc; /* service */ + gss_cred_id_t cred; /* cred handle */ + uint32_t req_flags; /* req flags for init_sec_context */ +}; + +/* Private data required for kernel implementation */ +struct authgss_private_data { + gss_ctx_id_t pd_ctx; /* Session context handle */ + gss_buffer_desc pd_ctx_hndl; /* Credentials context handle */ + uint32_t pd_seq_win; /* Sequence window */ +}; + +/* Krb 5 default mechanism +#define KRB5OID "1.2.840.113554.1.2.2" + +gss_OID_desc krb5oid = { + 20, KRB5OID +}; + */ + +/* +struct rpc_gss_sec krb5mech = { + (gss_OID)&krb5oid, + GSS_QOP_DEFAULT, + RPCSEC_GSS_SVC_NONE +}; +*/ + +/* Credentials. */ +struct rpc_gss_cred { + u_int gc_v; /* version */ + rpc_gss_proc_t gc_proc; /* control procedure */ + uint32_t gc_seq; /* sequence number */ + rpc_gss_svc_t gc_svc; /* service */ + gss_buffer_desc gc_ctx; /* context handle */ +}; + +/* Context creation response. */ +struct rpc_gss_init_res { + gss_buffer_desc gr_ctx; /* context handle */ + uint32_t gr_major; /* major status */ + uint32_t gr_minor; /* minor status */ + uint32_t gr_win; /* sequence window */ + gss_buffer_desc gr_token; /* token */ +}; + +/* Maximum sequence number value. */ +#define MAXSEQ 0x80000000 + +/* Prototypes. */ +bool_t xdr_rpc_gss_buf (XDR *xdrs, gss_buffer_t, u_int maxsize); +bool_t xdr_rpc_gss_cred (XDR *xdrs, struct rpc_gss_cred *p); +bool_t xdr_rpc_gss_init_args (XDR *xdrs, gss_buffer_desc *p); +bool_t xdr_rpc_gss_init_res (XDR *xdrs, struct rpc_gss_init_res *p); +bool_t xdr_rpc_gss_data (XDR *xdrs, xdrproc_t xdr_func, + caddr_t xdr_ptr, gss_ctx_id_t ctx, + gss_qop_t qop, rpc_gss_svc_t svc, + uint32_t seq); +bool_t xdr_rpc_gss_wrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t + xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, + rpc_gss_svc_t svc, uint32_t seq); +bool_t xdr_rpc_gss_unwrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t + xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, + rpc_gss_svc_t svc, uint32_t seq); + +AUTH *authgss_create (CLIENT *, gss_name_t, struct rpc_gss_sec *); +AUTH *authgss_create_default (CLIENT *, char *, struct rpc_gss_sec *); +bool_t authgss_service (AUTH *auth, int svc); +bool_t authgss_get_private_data (AUTH *auth, struct authgss_private_data *); + +#ifdef GSSRPC__IMPL +void log_debug (const char *fmt, ...); +void log_status (char *m, OM_uint32 major, OM_uint32 minor); +void log_hexdump (const u_char *buf, int len, int offset); +#endif + +GSSRPC__END_DECLS +#endif /* !defined(GSSRPC_AUTH_GSS_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/auth.h postgresql-hll-2.14/include/include/gssrpc/auth.h --- postgresql-hll-2.14_old/include/include/gssrpc/auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/auth.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,206 @@ +/* @(#)auth.h 2.3 88/08/07 4.0 RPCSRC; from 1.17 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * auth.h, Authentication interface. + * + * The data structures are completely opaque to the client. The client + * is required to pass a AUTH * to routines that create rpc + * "sessions". + */ +#ifndef GSSRPC_AUTH_H +#define GSSRPC_AUTH_H + +#include + +GSSRPC__BEGIN_DECLS + +#define MAX_AUTH_BYTES 400 +#define MAXNETNAMELEN 255 /* maximum length of network user's name */ + +/* + * Status returned from authentication check + */ +enum auth_stat { + AUTH_OK=0, + /* + * failed at remote end + */ + AUTH_BADCRED=1, /* bogus credentials (seal broken) */ + AUTH_REJECTEDCRED=2, /* client should begin new session */ + AUTH_BADVERF=3, /* bogus verifier (seal broken) */ + AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ + AUTH_TOOWEAK=5, /* rejected due to security reasons */ + /* + * failed locally + */ + AUTH_INVALIDRESP=6, /* bogus response verifier */ + AUTH_FAILED=7, /* some unknown reason */ + /* + * RPCSEC_GSS errors + */ + RPCSEC_GSS_CREDPROBLEM = 13, + RPCSEC_GSS_CTXPROBLEM = 14 +}; + +union des_block { + char c[8]; +}; +typedef union des_block des_block; +extern bool_t xdr_des_block(XDR *, des_block *); + +/* + * Authentication info. Opaque to client. + */ +struct opaque_auth { + enum_t oa_flavor; /* flavor of auth */ + caddr_t oa_base; /* address of more auth stuff */ + u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ +}; + + +/* + * Auth handle, interface to client side authenticators. + */ +struct rpc_msg; + +typedef struct AUTH { + struct opaque_auth ah_cred; + struct opaque_auth ah_verf; + union des_block ah_key; + struct auth_ops { + void (*ah_nextverf)(struct AUTH *); + /* nextverf & serialize */ + int (*ah_marshal)(struct AUTH *, XDR *); + /* validate varifier */ + int (*ah_validate)(struct AUTH *, + struct opaque_auth *); + /* refresh credentials */ + int (*ah_refresh)(struct AUTH *, struct rpc_msg *); + /* destroy this structure */ + void (*ah_destroy)(struct AUTH *); + /* encode data for wire */ + int (*ah_wrap)(struct AUTH *, XDR *, + xdrproc_t, caddr_t); + /* decode data from wire */ + int (*ah_unwrap)(struct AUTH *, XDR *, + xdrproc_t, caddr_t); + } *ah_ops; + void *ah_private; +} AUTH; + + +/* + * Authentication ops. + * The ops and the auth handle provide the interface to the authenticators. + * + * AUTH *auth; + * XDR *xdrs; + * struct opaque_auth verf; + */ +#define AUTH_NEXTVERF(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) +#define auth_nextverf(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) + +#define AUTH_MARSHALL(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) +#define auth_marshall(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) + +#define AUTH_VALIDATE(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) +#define auth_validate(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) + +#define AUTH_REFRESH(auth, msg) \ + ((*((auth)->ah_ops->ah_refresh))(auth, msg)) +#define auth_refresh(auth, msg) \ + ((*((auth)->ah_ops->ah_refresh))(auth, msg)) + +#define AUTH_WRAP(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \ + xfunc, xwhere)) +#define auth_wrap(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \ + xfunc, xwhere)) +#define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \ + xfunc, xwhere)) +#define auth_unwrap(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \ + xfunc, xwhere)) + +#define AUTH_DESTROY(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) +#define auth_destroy(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) + + +#ifdef GSSRPC__IMPL +/* RENAMED: should be _null_auth if we can use reserved namespace. */ +extern struct opaque_auth gssrpc__null_auth; +#endif + +/* + * These are the various implementations of client side authenticators. + */ + +/* + * Unix style authentication + * AUTH *authunix_create(machname, uid, gid, len, aup_gids) + * char *machname; + * int uid; + * int gid; + * int len; + * int *aup_gids; + */ +extern AUTH *authunix_create(char *machname, int uid, int gid, int len, + int *aup_gids); +extern AUTH *authunix_create_default(void); /* takes no parameters */ +extern AUTH *authnone_create(void); /* takes no parameters */ +extern AUTH *authdes_create(); +extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); + +#define AUTH_NONE 0 /* no authentication */ +#define AUTH_NULL 0 /* backward compatibility */ +#define AUTH_UNIX 1 /* unix style (uid, gids) */ +#define AUTH_SHORT 2 /* short hand unix style */ +#define AUTH_DES 3 /* des style (encrypted timestamps) */ +#define AUTH_GSSAPI 300001 /* GSS-API style */ +#define RPCSEC_GSS 6 /* RPCSEC_GSS */ + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_AUTH_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/auth_unix.h postgresql-hll-2.14/include/include/gssrpc/auth_unix.h --- postgresql-hll-2.14_old/include/include/gssrpc/auth_unix.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/auth_unix.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,82 @@ +/* @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC; from 1.8 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* @(#)auth_unix.h 1.5 86/07/16 SMI */ + +/* + * auth_unix.h, Protocol for UNIX style authentication parameters for RPC + */ + +#ifndef GSSRPC_AUTH_UNIX_H +#define GSSRPC_AUTH_UNIX_H + +GSSRPC__BEGIN_DECLS +/* + * The system is very weak. The client uses no encryption for it + * credentials and only sends null verifiers. The server sends backs + * null verifiers or optionally a verifier that suggests a new short hand + * for the credentials. + */ + +/* The machine name is part of a credential; it may not exceed 255 bytes */ +#define MAX_MACHINE_NAME 255 + +/* gids compose part of a credential; there may not be more than 16 of them */ +#define NGRPS 16 + +/* + * Unix style credentials. + */ +struct authunix_parms { + uint32_t aup_time; + char *aup_machname; + int aup_uid; + int aup_gid; + u_int aup_len; + int *aup_gids; +}; + +extern bool_t xdr_authunix_parms(XDR *, struct authunix_parms *); + +/* + * If a response verifier has flavor AUTH_SHORT, + * then the body of the response verifier encapsulates the following structure; + * again it is serialized in the obvious fashion. + */ +struct short_hand_verf { + struct opaque_auth new_cred; +}; + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_AUTH_UNIX_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/clnt.h postgresql-hll-2.14/include/include/gssrpc/clnt.h --- postgresql-hll-2.14_old/include/include/gssrpc/clnt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/clnt.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,346 @@ +/* @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * clnt.h - Client side remote procedure call interface. + */ + +#ifndef GSSRPC_CLNT_H +#define GSSRPC_CLNT_H + +GSSRPC__BEGIN_DECLS +/* + * Rpc calls return an enum clnt_stat. This should be looked at more, + * since each implementation is required to live with this (implementation + * independent) list of errors. + */ +enum clnt_stat { + RPC_SUCCESS=0, /* call succeeded */ + /* + * local errors + */ + RPC_CANTENCODEARGS=1, /* can't encode arguments */ + RPC_CANTDECODERES=2, /* can't decode results */ + RPC_CANTSEND=3, /* failure in sending call */ + RPC_CANTRECV=4, /* failure in receiving result */ + RPC_TIMEDOUT=5, /* call timed out */ + /* + * remote errors + */ + RPC_VERSMISMATCH=6, /* rpc versions not compatible */ + RPC_AUTHERROR=7, /* authentication error */ + RPC_PROGUNAVAIL=8, /* program not available */ + RPC_PROGVERSMISMATCH=9, /* program version mismatched */ + RPC_PROCUNAVAIL=10, /* procedure unavailable */ + RPC_CANTDECODEARGS=11, /* decode arguments error */ + RPC_SYSTEMERROR=12, /* generic "other problem" */ + + /* + * callrpc & clnt_create errors + */ + RPC_UNKNOWNHOST=13, /* unknown host name */ + RPC_UNKNOWNPROTO=17, /* unkown protocol */ + + /* + * _ create errors + */ + RPC_PMAPFAILURE=14, /* the pmapper failed in its call */ + RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ + /* + * unspecified error + */ + RPC_FAILED=16 +}; + + +/* + * Error info. + */ +struct rpc_err { + enum clnt_stat re_status; + union { + int RE_errno; /* realated system error */ + enum auth_stat RE_why; /* why the auth error occurred */ + struct { + rpcvers_t low; /* lowest verion supported */ + rpcvers_t high; /* highest verion supported */ + } RE_vers; + struct { /* maybe meaningful if RPC_FAILED */ + int32_t s1; + int32_t s2; + } RE_lb; /* life boot & debugging only */ + } ru; +#define re_errno ru.RE_errno +#define re_why ru.RE_why +#define re_vers ru.RE_vers +#define re_lb ru.RE_lb +}; + + +/* + * Client rpc handle. + * Created by individual implementations, see e.g. rpc_udp.c. + * Client is responsible for initializing auth, see e.g. auth_none.c. + */ +typedef struct CLIENT { + AUTH *cl_auth; /* authenticator */ + struct clnt_ops { + /* call remote procedure */ + enum clnt_stat (*cl_call)(struct CLIENT *, + rpcproc_t, xdrproc_t, void *, + xdrproc_t, void *, + struct timeval); + /* abort a call */ + void (*cl_abort)(struct CLIENT *); + /* get specific error code */ + void (*cl_geterr)(struct CLIENT *, + struct rpc_err *); + /* frees results */ + bool_t (*cl_freeres)(struct CLIENT *, + xdrproc_t, void *); + /* destroy this structure */ + void (*cl_destroy)(struct CLIENT *); + /* the ioctl() of rpc */ + /* XXX CITI makes 2nd arg take u_int */ + bool_t (*cl_control)(struct CLIENT *, int, + void *); + } *cl_ops; + void *cl_private; /* private stuff */ +} CLIENT; + + +/* + * client side rpc interface ops + * + * Parameter types are: + * + */ + +/* + * enum clnt_stat + * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) + * CLIENT *rh; + * rpcproc_t proc; + * xdrproc_t xargs; + * caddr_t argsp; + * xdrproc_t xres; + * caddr_t resp; + * struct timeval timeout; + */ +#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) +#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) + +/* + * void + * CLNT_ABORT(rh); + * CLIENT *rh; + */ +#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) +#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) + +/* + * struct rpc_err + * CLNT_GETERR(rh); + * CLIENT *rh; + */ +#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) +#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) + + +/* + * bool_t + * CLNT_FREERES(rh, xres, resp); + * CLIENT *rh; + * xdrproc_t xres; + * caddr_t resp; + */ +#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) +#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) + +/* + * bool_t + * CLNT_CONTROL(cl, request, info) + * CLIENT *cl; + * u_int request; + * char *info; + */ +#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) +#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) + +/* + * control operations that apply to both udp and tcp transports + */ +#define CLSET_TIMEOUT 1 /* set timeout (timeval) */ +#define CLGET_TIMEOUT 2 /* get timeout (timeval) */ +#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ +/* + * udp only control operations + */ +#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ +#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ +/* + * new control operations + */ +#define CLGET_LOCAL_ADDR 6 /* get local address (sockaddr, getsockname)*/ + +/* + * void + * CLNT_DESTROY(rh); + * CLIENT *rh; + */ +#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) +#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) + + +/* + * RPCTEST is a test program which is accessable on every rpc + * transport/port. It is used for testing, performance evaluation, + * and network administration. + */ + +#define RPCTEST_PROGRAM ((rpcprog_t)1) +#define RPCTEST_VERSION ((rpcvers_t)1) +#define RPCTEST_NULL_PROC ((rpcproc_t)2) +#define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3) + +/* + * By convention, procedure 0 takes null arguments and returns them + */ + +#define NULLPROC ((rpcproc_t)0) + +/* + * Below are the client handle creation routines for the various + * implementations of client side rpc. They can return NULL if a + * creation failure occurs. + */ + +/* + * Memory based rpc (for speed check and testing) + * CLIENT * + * clntraw_create(prog, vers) + * rpcprog_t prog; + * rpcvers_t vers; + */ +extern CLIENT *clntraw_create(rpcprog_t, rpcvers_t); + +/* + * Generic client creation routine. Supported protocols are "udp" and "tcp" + */ +extern CLIENT *clnt_create(char *, rpcprog_t, rpcvers_t, char *); + + +/* + * TCP based rpc + * CLIENT * + * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * rpcprog_t prog; + * rpcvers_t version; + * int *sockp; + * u_int sendsz; + * u_int recvsz; + */ +extern CLIENT *clnttcp_create(struct sockaddr_in *, rpcprog_t, rpcvers_t, + int *, u_int, u_int); + +/* + * UDP based rpc. + * CLIENT * + * clntudp_create(raddr, program, version, wait, sockp) + * struct sockaddr_in *raddr; + * rpcprog_t program; + * rpcvers_t version; + * struct timeval wait; + * int *sockp; + * + * Same as above, but you specify max packet sizes. + * CLIENT * + * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * rpcprog_t program; + * rpcvers_t version; + * struct timeval wait; + * int *sockp; + * u_int sendsz; + * u_int recvsz; + */ +extern CLIENT *clntudp_create(struct sockaddr_in *, rpcprog_t, + rpcvers_t, struct timeval, int *); +extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, rpcprog_t, + rpcvers_t, struct timeval, int *, + u_int, u_int); + +/* + * Print why creation failed + */ +void clnt_pcreateerror(char *); /* stderr */ +char *clnt_spcreateerror(char *); /* string */ + +/* + * Like clnt_perror(), but is more verbose in its output + */ +void clnt_perrno(enum clnt_stat); /* stderr */ + +/* + * Print an English error message, given the client error code + */ +void clnt_perror(CLIENT *, char *); /* stderr */ +char *clnt_sperror(CLIENT *, char *); /* string */ + +/* + * If a creation fails, the following allows the user to figure out why. + */ +struct rpc_createerr { + enum clnt_stat cf_stat; + struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ +}; + +extern struct rpc_createerr rpc_createerr; + + + +/* + * Copy error message to buffer. + */ +char *clnt_sperrno(enum clnt_stat num); /* string */ + +#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ +#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_CLNT_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/netdb.h postgresql-hll-2.14/include/include/gssrpc/netdb.h --- postgresql-hll-2.14_old/include/include/gssrpc/netdb.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/netdb.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,58 @@ +/* include/gssrpc/netdb.h */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* @(#)netdb.h 2.1 88/07/29 3.9 RPCSRC */ +/* @(#)rpc.h 1.8 87/07/24 SMI */ + +#ifndef RPC_NETDB_H +#define RPC_NETDB_H + +#include +/* since the gssrpc library requires that any application using it be +built with these header files, I am making the decision that any app +which uses the rpcent routines must use this header file, or something +compatible (which most are) --marc */ + +/* Really belongs in */ +#ifdef STRUCT_RPCENT_IN_RPC_NETDB_H +struct rpcent { + char *r_name; /* name of server for this rpc program */ + char **r_aliases; /* alias list */ + int r_number; /* rpc program number */ +}; +#endif /*STRUCT_RPCENT_IN_RPC_NETDB_H*/ + +struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/pmap_clnt.h postgresql-hll-2.14/include/include/gssrpc/pmap_clnt.h --- postgresql-hll-2.14_old/include/include/gssrpc/pmap_clnt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/pmap_clnt.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,83 @@ +/* @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.11 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * pmap_clnt.h + * Supplies C routines to get to portmap services. + */ + +#ifndef GSSRPC_PMAP_CLNT_H +#define GSSRPC_PMAP_CLNT_H + +/* + * Usage: + * success = pmap_set(program, version, protocol, port); + * success = pmap_unset(program, version); + * port = pmap_getport(address, program, version, protocol); + * head = pmap_getmaps(address); + * clnt_stat = pmap_rmtcall(address, program, version, procedure, + * xdrargs, argsp, xdrres, resp, tout, port_ptr) + * (works for udp only.) + * clnt_stat = clnt_broadcast(program, version, procedure, + * xdrargs, argsp, xdrres, resp, eachresult) + * (like pmap_rmtcall, except the call is broadcasted to all + * locally connected nets. For each valid response received, + * the procedure eachresult is called. Its form is: + * done = eachresult(resp, raddr) + * bool_t done; + * caddr_t resp; + * struct sockaddr_in raddr; + * where resp points to the results of the call and raddr is the + * address if the responder to the broadcast. + */ + +GSSRPC__BEGIN_DECLS +extern bool_t pmap_set(rpcprog_t, rpcvers_t, rpcprot_t, u_int); +extern bool_t pmap_unset(rpcprog_t, rpcvers_t); +extern struct pmaplist *pmap_getmaps(struct sockaddr_in *); +enum clnt_stat pmap_rmtcall(struct sockaddr_in *, rpcprog_t, + rpcvers_t, rpcproc_t, xdrproc_t, + caddr_t, xdrproc_t, caddr_t, + struct timeval, rpcport_t *); + +typedef bool_t (*resultproc_t)(caddr_t, struct sockaddr_in *); + +enum clnt_stat clnt_broadcast(rpcprog_t, rpcvers_t, rpcproc_t, + xdrproc_t, caddr_t, xdrproc_t, + caddr_t, resultproc_t); +extern u_short pmap_getport(struct sockaddr_in *, + rpcprog_t, + rpcvers_t, rpcprot_t); +GSSRPC__END_DECLS +#endif /* !defined(GSSRPC_PMAP_CLNT_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/pmap_prot.h postgresql-hll-2.14/include/include/gssrpc/pmap_prot.h --- postgresql-hll-2.14_old/include/include/gssrpc/pmap_prot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/pmap_prot.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,103 @@ +/* @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC; from 1.14 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * pmap_prot.h + * Protocol for the local binder service, or pmap. + * + * The following procedures are supported by the protocol: + * + * PMAPPROC_NULL() returns () + * takes nothing, returns nothing + * + * PMAPPROC_SET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Registers the tuple + * [prog, vers, prot, port]. + * + * PMAPPROC_UNSET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Un-registers pair + * [prog, vers]. prot and port are ignored. + * + * PMAPPROC_GETPORT(struct pmap) returns (u_short). + * 0 is failure. Otherwise returns the port number where the pair + * [prog, vers] is registered. It may lie! + * + * PMAPPROC_DUMP() RETURNS (struct pmaplist *) + * + * PMAPPROC_CALLIT(rpcprog_t, rpcvers_t, rpcproc_t, string<>) + * RETURNS (port, string<>); + * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); + * Calls the procedure on the local machine. If it is not registered, + * this procedure is quite; ie it does not return error information!!! + * This procedure only is supported on rpc/udp and calls via + * rpc/udp. This routine only passes null authentication parameters. + * This file has no interface to xdr routines for PMAPPROC_CALLIT. + * + * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. + */ + +#ifndef GSSRPC_PMAP_PROT_H +#define GSSRPC_PMAP_PROT_H +GSSRPC__BEGIN_DECLS + +#define PMAPPORT ((u_short)111) +#define PMAPPROG ((rpcprog_t)100000) +#define PMAPVERS ((rpcvers_t)2) +#define PMAPVERS_PROTO ((rpcprot_t)2) +#define PMAPVERS_ORIG ((rpcvers_t)1) +#define PMAPPROC_NULL ((rpcproc_t)0) +#define PMAPPROC_SET ((rpcproc_t)1) +#define PMAPPROC_UNSET ((rpcproc_t)2) +#define PMAPPROC_GETPORT ((rpcproc_t)3) +#define PMAPPROC_DUMP ((rpcproc_t)4) +#define PMAPPROC_CALLIT ((rpcproc_t)5) + +struct pmap { + rpcprog_t pm_prog; + rpcvers_t pm_vers; + rpcprot_t pm_prot; + rpcport_t pm_port; +}; + +extern bool_t xdr_pmap(XDR *, struct pmap *); + +struct pmaplist { + struct pmap pml_map; + struct pmaplist *pml_next; +}; + +extern bool_t xdr_pmaplist(XDR *, struct pmaplist **); + +GSSRPC__END_DECLS +#endif /* !defined(GSSRPC_PMAP_PROT_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/pmap_rmt.h postgresql-hll-2.14/include/include/gssrpc/pmap_rmt.h --- postgresql-hll-2.14_old/include/include/gssrpc/pmap_rmt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/pmap_rmt.h 2020-12-12 17:06:43.196347380 +0800 @@ -0,0 +1,65 @@ +/* @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC; from 1.2 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Structures and XDR routines for parameters to and replies from + * the portmapper remote-call-service. + */ + +#ifndef GSSRPC_PMAP_RMT_H +#define GSSRPC_PMAP_RMT_H +GSSRPC__BEGIN_DECLS + +struct rmtcallargs { + rpcprog_t prog; + rpcvers_t vers; + rpcproc_t proc; + uint32_t arglen; + caddr_t args_ptr; + xdrproc_t xdr_args; +}; + +bool_t xdr_rmtcall_args(XDR *, struct rmtcallargs *); + +struct rmtcallres { + rpcport_t *port_ptr; + uint32_t resultslen; + caddr_t results_ptr; + xdrproc_t xdr_results; +}; + +bool_t xdr_rmtcallres(XDR *, struct rmtcallres *); + +GSSRPC__END_DECLS +#endif /* !defined(GSSRPC_PMAP_RMT_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/rename.h postgresql-hll-2.14/include/include/gssrpc/rename.h --- postgresql-hll-2.14_old/include/include/gssrpc/rename.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/rename.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,287 @@ +/* include/gssrpc/rename.h */ +/* + * Copyright (C) 2004 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +/* + * + * Namespace mangling for various purposes. + * + * Symbols in the object code need to be renamed to not conflict with + * an OS-provided RPC implementation. Without renaming, the conflicts + * can cause problems with things like RPC-enabled NSS + * implementations. + * + * Symbols in headers should not conflict with implementation-reserved + * namespace (prefixes "_[A-Z_]" for any purpose; prefix "_" + * for file scope identifiers and tag names), or unnecessarily impinge + * on user namespace. + * + * The renaming of the header directory is done to avoid problems when + * the OS header files include and might get ours instead. + * OS vendors should replace all the inclusions with + * inclusions, as appropriate. Additionally, vendors + * should probably put some symbols into the implementation namespace. + * + * For example, inclusion protection should change from "GSSRPC_*_H" + * to "_RPC_*_H", struct tags should get "__" prefixes, etc. + * + * This implementation reserves the object code prefix "gssrpc_". + * External names in the RPC API not beginning with "_" get renamed + * with the prefix "gssrpc_" via #define, e.g., "foo" -> "gssrpc_foo". + * External names in the RPC API beginning with "_" get textually + * rewritten. + */ + +#ifndef GSSRPC_RENAME_H +#define GSSRPC_RENAME_H + +/* auth.h */ + +#define xdr_des_block gssrpc_xdr_des_block + +#define authany_wrap gssrpc_authany_wrap +#define authany_unwrap gssrpc_authany_unwrap + +#define authunix_create gssrpc_authunix_create +#define authunix_create_default gssrpc_authunix_create_default +#define authnone_create gssrpc_authnone_create +#define authdes_create gssrpc_authdes_create +#define xdr_opaque_auth gssrpc_xdr_opaque_auth + +/* auth_gss.c */ + +#define auth_debug_gss gssrpc_auth_debug_gss +#define misc_debug_gss gssrpc_misc_debug_gss + +/* auth_gss.h */ + +#define xdr_rpc_gss_buf gssrpc_xdr_rpc_gss_buf +#define xdr_rpc_gss_cred gssrpc_xdr_rpc_gss_cred +#define xdr_rpc_gss_init_args gssrpc_xdr_rpc_gss_init_args +#define xdr_rpc_gss_init_res gssrpc_xdr_rpc_gss_init_res +#define xdr_rpc_gss_data gssrpc_xdr_rpc_gss_data +#define xdr_rpc_gss_wrap_data gssrpc_xdr_rpc_gss_wrap_data +#define xdr_rpc_gss_unwrap_data gssrpc_xdr_rpc_gss_unwrap_data + +#define authgss_create gssrpc_authgss_create +#define authgss_create_default gssrpc_authgss_create_default +#define authgss_get_private_data gssrpc_authgss_get_private_data +#define authgss_service gssrpc_authgss_service + +#ifdef GSSRPC__IMPL +#define log_debug gssrpc_log_debug +#define log_status gssrpc_log_status +#define log_hexdump gssrpc_log_hexdump +#endif + +/* auth_gssapi.c */ + +#define auth_debug_gssapi gssrpc_auth_debug_gssapi +#define misc_debug_gssapi gssrpc_misc_debug_gssapi + +/* auth_gssapi.h */ + +#define xdr_gss_buf gssrpc_xdr_gss_buf +#define xdr_authgssapi_creds gssrpc_xdr_authgssapi_creds +#define xdr_authgssapi_init_arg gssrpc_xdr_authgssapi_init_arg +#define xdr_authgssapi_init_res gssrpc_xdr_authgssapi_init_res + +#define auth_gssapi_wrap_data gssrpc_auth_gssapi_wrap_data +#define auth_gssapi_unwrap_data gssrpc_auth_gssapi_unwrap_data +#define auth_gssapi_create gssrpc_auth_gssapi_create +#define auth_gssapi_create_default gssrpc_auth_gssapi_create_default +#define auth_gssapi_display_status gssrpc_auth_gssapi_display_status +#define auth_gssapi_seal_seq gssrpc_auth_gssapi_seal_seq +#define auth_gssapi_unseal_seq gssrpc_auth_gssapi_unseal_seq + +#define svcauth_gssapi_set_names gssrpc_svcauth_gssapi_set_names +#define svcauth_gssapi_unset_names gssrpc_svcauth_gssapi_unset_names +#define svcauth_gssapi_set_log_badauth_func gssrpc_svcauth_gssapi_set_log_badauth_func +#define svcauth_gssapi_set_log_badauth2_func gssrpc_svcauth_gssapi_set_log_badauth2_func +#define svcauth_gssapi_set_log_badverf_func gssrpc_svcauth_gssapi_set_log_badverf_func +#define svcauth_gssapi_set_log_miscerr_func gssrpc_svcauth_gssapi_set_log_miscerr_func + +#define svcauth_gss_set_log_badauth_func gssrpc_svcauth_gss_set_log_badauth_func +#define svcauth_gss_set_log_badauth2_func gssrpc_svcauth_gss_set_log_badauth2_func +#define svcauth_gss_set_log_badverf_func gssrpc_svcauth_gss_set_log_badverf_func +#define svcauth_gss_set_log_miscerr_func gssrpc_svcauth_gss_set_log_miscerr_func + +/* auth_unix.h */ + +#define xdr_authunix_parms gssrpc_xdr_authunix_parms + +/* clnt.h */ + +#define clntraw_create gssrpc_clntraw_create +#define clnt_create gssrpc_clnt_create +#define clnttcp_create gssrpc_clnttcp_create +#define clntudp_create gssrpc_clntudp_create +#define clntudp_bufcreate gssrpc_clntudp_bufcreate +#define clnt_pcreateerror gssrpc_clnt_pcreateerror +#define clnt_spcreateerror gssrpc_clnt_spcreateerror +#define clnt_perrno gssrpc_clnt_perrno +#define clnt_perror gssrpc_clnt_perror +#define clnt_sperror gssrpc_clnt_sperror +/* XXX do we need to rename the struct? */ +#define rpc_createerr gssrpc_rpc_createrr +#define clnt_sperrno gssrpc_clnt_sperrno + +/* pmap_clnt.h */ + +#define pmap_set gssrpc_pmap_set +#define pmap_unset gssrpc_pmap_unset +#define pmap_getmaps gssrpc_pmap_getmaps +#define pmap_rmtcall gssrpc_pmap_rmtcall +#define clnt_broadcast gssrpc_clnt_broadcast +#define pmap_getport gssrpc_pmap_getport + +/* pmap_prot.h */ + +#define xdr_pmap gssrpc_xdr_pmap +#define xdr_pmaplist gssrpc_xdr_pmaplist + +/* pmap_rmt.h */ + +#define xdr_rmtcall_args gssrpc_xdr_rmtcall_args +#define xdr_rmtcallres gssrpc_xdr_rmtcallres + +/* rpc.h */ + +#define get_myaddress gssrpc_get_myaddress +#define bindresvport gssrpc_bindresvport +#define bindresvport_sa gssrpc_bindresvport_sa +#define callrpc gssrpc_callrpc +#define getrpcport gssrpc_getrpcport + +/* rpc_msg.h */ + +#define xdr_callmsg gssrpc_xdr_callmsg +#define xdr_callhdr gssrpc_xdr_callhdr +#define xdr_replymsg gssrpc_xdr_replymsg +#define xdr_accepted_reply gssrpc_xdr_accepted_reply +#define xdr_rejected_reply gssrpc_xdr_rejected_reply + +/* svc.h */ + +#define svc_register gssrpc_svc_register +#define registerrpc gssrpc_registerrpc +#define svc_unregister gssrpc_svc_unregister +#define xprt_register gssrpc_xprt_register +#define xprt_unregister gssrpc_xprt_unregister + +#define svc_sendreply gssrpc_svc_sendreply +#define svcerr_decode gssrpc_svcerr_decode +#define svcerr_weakauth gssrpc_svcerr_weakauth +#define svcerr_noproc gssrpc_svcerr_noproc +#define svcerr_progvers gssrpc_svcerr_progvers +#define svcerr_auth gssrpc_svcerr_auth +#define svcerr_noprog gssrpc_svcerr_noprog +#define svcerr_systemerr gssrpc_svcerr_systemerr + +#define svc_maxfd gssrpc_svc_maxfd +#define svc_fdset gssrpc_svc_fdset +#define svc_fds gssrpc_svc_fds + +#define rpctest_service gssrpc_rpctest_service + +#define svc_getreq gssrpc_svc_getreq +#define svc_getreqset gssrpc_svc_getreqset +#define svc_getreqset2 gssrpc_svc_getreqset2 +#define svc_run gssrpc_svc_run + +#define svcraw_create gssrpc_svcraw_create + +#define svcudp_create gssrpc_svcudp_create +#define svcudp_bufcreate gssrpc_svcudp_bufcreate +#define svcudp_enablecache gssrpc_svcudp_enablecache + +#define svctcp_create gssrpc_svctcp_create + +#define svcfd_create gssrpc_svcfd_create + +/* svc_auth.h */ + +#define svc_auth_none_ops gssrpc_svc_auth_none_ops +#define svc_auth_gssapi_ops gssrpc_svc_auth_gssapi_ops +#define svc_auth_gss_ops gssrpc_svc_auth_gss_ops + +#define svcauth_gss_set_svc_name gssrpc_svcauth_gss_set_svc_name +#define svcauth_gss_get_principal gssrpc_svcauth_gss_get_principal + +/* svc_auth_gss.c */ + +#define svc_debug_gss gssrpc_svc_debug_gss + +/* svc_auth_gssapi.c */ + +#define svc_debug_gssapi gssrpc_svc_debug_gssapi + +/* svc_auth_none.c */ + +#define svc_auth_none gssrpc_svc_auth_none + +/* xdr.h */ + +#define xdr_void gssrpc_xdr_void +#define xdr_int gssrpc_xdr_int +#define xdr_u_int gssrpc_xdr_u_int +#define xdr_long gssrpc_xdr_long +#define xdr_u_long gssrpc_xdr_u_long +#define xdr_short gssrpc_xdr_short +#define xdr_u_short gssrpc_xdr_u_short +#define xdr_bool gssrpc_xdr_bool +#define xdr_enum gssrpc_xdr_enum +#define xdr_array gssrpc_xdr_array +#define xdr_bytes gssrpc_xdr_bytes +#define xdr_opaque gssrpc_xdr_opaque +#define xdr_string gssrpc_xdr_string +#define xdr_union gssrpc_xdr_union +#define xdr_char gssrpc_xdr_char +#define xdr_u_char gssrpc_xdr_u_char +#define xdr_vector gssrpc_xdr_vector +#define xdr_float gssrpc_xdr_float +#define xdr_double gssrpc_xdr_double +#define xdr_reference gssrpc_xdr_reference +#define xdr_pointer gssrpc_xdr_pointer +#define xdr_wrapstring gssrpc_xdr_wrapstring +#define xdr_free gssrpc_xdr_free + +#define xdr_sizeof gssrpc_xdr_sizeof + +#define xdr_netobj gssrpc_xdr_netobj +#define xdr_int32 gssrpc_xdr_int32 +#define xdr_u_int32 gssrpc_xdr_u_int32 + +#define xdralloc_create gssrpc_xdralloc_create +#define xdralloc_release gssrpc_xdralloc_release +#define xdralloc_getdata gssrpc_xdralloc_getdata + +#define xdrmem_create gssrpc_xdrmem_create +#define xdrstdio_create gssrpc_xdrstdio_create +#define xdrrec_create gssrpc_xdrrec_create +#define xdrrec_endofrecord gssrpc_xdrrec_endofrecord +#define xdrrec_skiprecord gssrpc_xdrrec_skiprecord +#define xdrrec_eof gssrpc_xdrrec_eof + +#endif /* !defined(GSSRPC_RENAME_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/rpc.h postgresql-hll-2.14/include/include/gssrpc/rpc.h --- postgresql-hll-2.14_old/include/include/gssrpc/rpc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/rpc.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,77 @@ +/* @(#)rpc.h 2.3 88/08/10 4.0 RPCSRC; from 1.9 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * rpc.h, Just includes the billions of rpc header files necessary to + * do remote procedure calling. + */ +#ifndef GSSRPC_RPC_H +#define GSSRPC_RPC_H + +#include /* some typedefs */ +#include + +/* external data representation interfaces */ +#include /* generic (de)serializer */ + +/* Client side only authentication */ +#include /* generic authenticator (client side) */ + +/* Client side (mostly) remote procedure call */ +#include /* generic rpc stuff */ + +/* semi-private protocol headers */ +#include /* protocol for rpc messages */ +#include /* protocol for unix style cred */ +#include /* RPCSEC_GSS */ + +/* Server side only remote procedure callee */ +#include /* service side authenticator */ +#include /* service manager and multiplexer */ + +/* + * get the local host's IP address without consulting + * name service library functions + */ +GSSRPC__BEGIN_DECLS +extern int get_myaddress(struct sockaddr_in *); +extern int bindresvport(int, struct sockaddr_in *); +extern int bindresvport_sa(int, struct sockaddr *); +extern int callrpc(char *, rpcprog_t, rpcvers_t, rpcproc_t, xdrproc_t, + char *, xdrproc_t , char *); +extern int getrpcport(char *, rpcprog_t, rpcvers_t, rpcprot_t); +extern int gssrpc__rpc_dtablesize(void); +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_RPC_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/rpc_msg.h postgresql-hll-2.14/include/include/gssrpc/rpc_msg.h --- postgresql-hll-2.14_old/include/include/gssrpc/rpc_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/rpc_msg.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,207 @@ +/* @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* @(#)rpc_msg.h 1.7 86/07/16 SMI */ + +/* + * rpc_msg.h + * rpc message definition + */ + +#ifndef GSSRPC_RPC_MSG_H +#define GSSRPC_RPC_MSG_H + +GSSRPC__BEGIN_DECLS + +#define RPC_MSG_VERSION ((uint32_t) 2) +#define RPC_SERVICE_PORT ((u_short) 2048) + +/* + * Bottom up definition of an rpc message. + * NOTE: call and reply use the same overall stuct but + * different parts of unions within it. + */ + +enum msg_type { + CALL=0, + REPLY=1 +}; + +enum reply_stat { + MSG_ACCEPTED=0, + MSG_DENIED=1 +}; + +enum accept_stat { + SUCCESS=0, + PROG_UNAVAIL=1, + PROG_MISMATCH=2, + PROC_UNAVAIL=3, + GARBAGE_ARGS=4, + SYSTEM_ERR=5 +}; + +enum reject_stat { + RPC_MISMATCH=0, + AUTH_ERROR=1 +}; + +/* + * Reply part of an rpc exchange + */ + +/* + * Reply to an rpc request that was accepted by the server. + * Note: there could be an error even though the request was + * accepted. + */ +struct accepted_reply { + struct opaque_auth ar_verf; + enum accept_stat ar_stat; + union { + struct { + rpcvers_t low; + rpcvers_t high; + } AR_versions; + struct { + caddr_t where; + xdrproc_t proc; + } AR_results; + /* and many other null cases */ + } ru; +#define ar_results ru.AR_results +#define ar_vers ru.AR_versions +}; + +/* + * Reply to an rpc request that was rejected by the server. + */ +struct rejected_reply { + enum reject_stat rj_stat; + union { + struct { + rpcvers_t low; + rpcvers_t high; + } RJ_versions; + enum auth_stat RJ_why; /* why authentication did not work */ + } ru; +#define rj_vers ru.RJ_versions +#define rj_why ru.RJ_why +}; + +/* + * Body of a reply to an rpc request. + */ +struct reply_body { + enum reply_stat rp_stat; + union { + struct accepted_reply RP_ar; + struct rejected_reply RP_dr; + } ru; +#define rp_acpt ru.RP_ar +#define rp_rjct ru.RP_dr +}; + +/* + * Body of an rpc request call. + */ +struct call_body { + rpcvers_t cb_rpcvers; /* must be equal to two */ + rpcprog_t cb_prog; + rpcvers_t cb_vers; + rpcproc_t cb_proc; + struct opaque_auth cb_cred; + struct opaque_auth cb_verf; /* protocol specific - provided by client */ +}; + +/* + * The rpc message + */ +struct rpc_msg { + uint32_t rm_xid; + enum msg_type rm_direction; + union { + struct call_body RM_cmb; + struct reply_body RM_rmb; + } ru; +#define rm_call ru.RM_cmb +#define rm_reply ru.RM_rmb +}; +#define acpted_rply ru.RM_rmb.ru.RP_ar +#define rjcted_rply ru.RM_rmb.ru.RP_dr + + +/* + * XDR routine to handle a rpc message. + * xdr_callmsg(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callmsg(XDR *, struct rpc_msg *); + +/* + * XDR routine to pre-serialize the static part of a rpc message. + * xdr_callhdr(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callhdr(XDR *, struct rpc_msg *); + +/* + * XDR routine to handle a rpc reply. + * xdr_replymsg(xdrs, rmsg) + * XDR *xdrs; + * struct rpc_msg *rmsg; + */ +extern bool_t xdr_replymsg(XDR *, struct rpc_msg *); + +/* + * Fills in the error part of a reply message. + * _seterr_reply(msg, error) + * struct rpc_msg *msg; + * struct rpc_err *error; + */ +/* + * RENAMED: should be _seterr_reply or __seterr_reply if we can use + * reserved namespace. + */ +extern void gssrpc__seterr_reply(struct rpc_msg *, struct rpc_err *); + +/* XDR the MSG_ACCEPTED part of a reply message union */ +extern bool_t xdr_accepted_reply(XDR *, struct accepted_reply *); + +/* XDR the MSG_DENIED part of a reply message union */ +extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *); +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_RPC_MSG_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/svc_auth.h postgresql-hll-2.14/include/include/gssrpc/svc_auth.h --- postgresql-hll-2.14_old/include/include/gssrpc/svc_auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/svc_auth.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,119 @@ +/* @(#)svc_auth.h 2.1 88/07/29 4.0 RPCSRC */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* @(#)svc_auth.h 1.6 86/07/16 SMI */ + +/* + * svc_auth.h, Service side of rpc authentication. + */ + +/* + * Interface to server-side authentication flavors. + */ + +#ifndef GSSRPC_SVC_AUTH_H +#define GSSRPC_SVC_AUTH_H + +#include + +GSSRPC__BEGIN_DECLS + +struct svc_req; + +typedef struct SVCAUTH { + struct svc_auth_ops { + int (*svc_ah_wrap)(struct SVCAUTH *, XDR *, xdrproc_t, + caddr_t); + int (*svc_ah_unwrap)(struct SVCAUTH *, XDR *, xdrproc_t, + caddr_t); + int (*svc_ah_destroy)(struct SVCAUTH *); + } *svc_ah_ops; + void * svc_ah_private; +} SVCAUTH; + +#ifdef GSSRPC__IMPL + +extern SVCAUTH svc_auth_none; + +extern struct svc_auth_ops svc_auth_none_ops; +extern struct svc_auth_ops svc_auth_gssapi_ops; +extern struct svc_auth_ops svc_auth_gss_ops; + +/* + * Server side authenticator + */ +/* RENAMED: should be _authenticate. */ +extern enum auth_stat gssrpc__authenticate(struct svc_req *rqst, + struct rpc_msg *msg, bool_t *no_dispatch); + +#define SVCAUTH_WRAP(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->svc_ah_ops->svc_ah_wrap))(auth, xdrs, xfunc, xwhere)) +#define SVCAUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \ + ((*((auth)->svc_ah_ops->svc_ah_unwrap))(auth, xdrs, xfunc, xwhere)) +#define SVCAUTH_DESTROY(auth) \ + ((*((auth)->svc_ah_ops->svc_ah_destroy))(auth)) + +/* no authentication */ +/* RENAMED: should be _svcauth_none. */ +enum auth_stat gssrpc__svcauth_none(struct svc_req *, + struct rpc_msg *, bool_t *); +/* unix style (uid, gids) */ +/* RENAMED: shoudl be _svcauth_unix. */ +enum auth_stat gssrpc__svcauth_unix(struct svc_req *, + struct rpc_msg *, bool_t *); +/* short hand unix style */ +/* RENAMED: should be _svcauth_short. */ +enum auth_stat gssrpc__svcauth_short(struct svc_req *, + struct rpc_msg *, bool_t *); +/* GSS-API style */ +/* RENAMED: should be _svcauth_gssapi. */ +enum auth_stat gssrpc__svcauth_gssapi(struct svc_req *, + struct rpc_msg *, bool_t *); +/* RPCSEC_GSS */ +enum auth_stat gssrpc__svcauth_gss(struct svc_req *, + struct rpc_msg *, bool_t *); + +#endif /* defined(GSSRPC__IMPL) */ + +/* + * Approved way of getting principal of caller + */ +char *svcauth_gss_get_principal(SVCAUTH *auth); +/* + * Approved way of setting server principal + */ +bool_t svcauth_gss_set_svc_name(gss_name_t name); + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_SVC_AUTH_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/svc.h postgresql-hll-2.14/include/include/gssrpc/svc.h --- postgresql-hll-2.14_old/include/include/gssrpc/svc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/svc.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,343 @@ +/* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * svc.h, Server-side remote procedure call interface. + */ + +#ifndef GSSRPC_SVC_H +#define GSSRPC_SVC_H + +#include + +GSSRPC__BEGIN_DECLS +/* + * This interface must manage two items concerning remote procedure calling: + * + * 1) An arbitrary number of transport connections upon which rpc requests + * are received. The two most notable transports are TCP and UDP; they are + * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; + * they in turn call xprt_register and xprt_unregister. + * + * 2) An arbitrary number of locally registered services. Services are + * described by the following four data: program number, version number, + * "service dispatch" function, a transport handle, and a boolean that + * indicates whether or not the exported program should be registered with a + * local binder service; if true the program's number and version and the + * port number from the transport handle are registered with the binder. + * These data are registered with the rpc svc system via svc_register. + * + * A service's dispatch function is called whenever an rpc request comes in + * on a transport. The request's program and version numbers must match + * those of the registered service. The dispatch function is passed two + * parameters, struct svc_req * and SVCXPRT *, defined below. + */ + +enum xprt_stat { + XPRT_DIED, + XPRT_MOREREQS, + XPRT_IDLE +}; + +/* + * Server side transport handle + */ +typedef struct SVCXPRT { +#ifdef _WIN32 + SOCKET xp_sock; +#else + int xp_sock; +#endif + u_short xp_port; /* associated port number */ + struct xp_ops { + /* receive incomming requests */ + bool_t (*xp_recv)(struct SVCXPRT *, struct rpc_msg *); + /* get transport status */ + enum xprt_stat (*xp_stat)(struct SVCXPRT *); + /* get arguments */ + bool_t (*xp_getargs)(struct SVCXPRT *, xdrproc_t, + void *); + /* send reply */ + bool_t (*xp_reply)(struct SVCXPRT *, + struct rpc_msg *); + /* free mem allocated for args */ + bool_t (*xp_freeargs)(struct SVCXPRT *, xdrproc_t, + void *); + /* destroy this struct */ + void (*xp_destroy)(struct SVCXPRT *); + } *xp_ops; + int xp_addrlen; /* length of remote address */ + struct sockaddr_in xp_raddr; /* remote address */ + struct opaque_auth xp_verf; /* raw response verifier */ + SVCAUTH *xp_auth; /* auth flavor of current req */ + void *xp_p1; /* private */ + void *xp_p2; /* private */ + int xp_laddrlen; /* lenght of local address */ + struct sockaddr_in xp_laddr; /* local address */ +} SVCXPRT; + +/* + * Approved way of getting address of caller + */ +#define svc_getcaller(x) (&(x)->xp_raddr) + +/* + * Operations defined on an SVCXPRT handle + * + * SVCXPRT *xprt; + * struct rpc_msg *msg; + * xdrproc_t xargs; + * caddr_t argsp; + */ +#define SVC_RECV(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) +#define svc_recv(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) + +#define SVC_STAT(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) +#define svc_stat(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) + +#define SVC_GETARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) +#define svc_getargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) + +#define SVC_GETARGS_REQ(xprt, req, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp)) +#define svc_getargs_req(xprt, req, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp)) + +#define SVC_REPLY(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) +#define svc_reply(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) + +#define SVC_REPLY_REQ(xprt, req, msg) \ + (*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg)) +#define svc_reply_req(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg)) + +#define SVC_FREEARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) +#define svc_freeargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) + +#define SVC_DESTROY(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) +#define svc_destroy(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) + + +/* + * Service request + */ +struct svc_req { + rpcprog_t rq_prog; /* service program number */ + rpcvers_t rq_vers; /* service protocol version */ + rpcproc_t rq_proc; /* the desired procedure */ + struct opaque_auth rq_cred; /* raw creds from the wire */ + void * rq_clntcred; /* read only cooked client cred */ + void * rq_svccred; /* read only svc cred/context */ + void * rq_clntname; /* read only client name */ + SVCXPRT *rq_xprt; /* associated transport */ + /* The request's auth flavor *should* be here, but the svc_req */ + /* isn't passed around everywhere it is necessary. The */ + /* transport *is* passed around, so the auth flavor it stored */ + /* there. This means that the transport must be single */ + /* threaded, but other parts of SunRPC already require that. */ + /*SVCAUTH *rq_auth; associated auth flavor */ +}; + + +/* + * Service registration + * + * svc_register(xprt, prog, vers, dispatch, protocol) + * SVCXPRT *xprt; + * rpcprog_t prog; + * rpcvers_t vers; + * void (*dispatch)(); + * int protocol; like IPPROTO_TCP or _UDP; zero means do not register + * + * registerrpc(prog, vers, proc, routine, inproc, outproc) + * returns 0 upon success, -1 if error. + */ +extern bool_t svc_register(SVCXPRT *, rpcprog_t, rpcvers_t, + void (*)(struct svc_req *, SVCXPRT *), int); + +extern int registerrpc(rpcprog_t, rpcvers_t, rpcproc_t, + char *(*)(void *), + xdrproc_t, xdrproc_t); + +/* + * Service un-registration + * + * svc_unregister(prog, vers) + * rpcprog_t prog; + * rpcvers_t vers; + */ +extern void svc_unregister(rpcprog_t, rpcvers_t); + +/* + * Transport registration. + * + * xprt_register(xprt) + * SVCXPRT *xprt; + */ +extern void xprt_register(SVCXPRT *); + +/* + * Transport un-register + * + * xprt_unregister(xprt) + * SVCXPRT *xprt; + */ +extern void xprt_unregister(SVCXPRT *); + + +/* + * When the service routine is called, it must first check to see if + * it knows about the procedure; if not, it should call svcerr_noproc + * and return. If so, it should deserialize its arguments via + * SVC_GETARGS or the new SVC_GETARGS_REQ (both defined above). If + * the deserialization does not work, svcerr_decode should be called + * followed by a return. Successful decoding of the arguments should + * be followed the execution of the procedure's code and a call to + * svc_sendreply or the new svc_sendreply_req. + * + * Also, if the service refuses to execute the procedure due to too- + * weak authentication parameters, svcerr_weakauth should be called. + * Note: do not confuse access-control failure with weak authentication! + * + * NB: In pure implementations of rpc, the caller always waits for a reply + * msg. This message is sent when svc_sendreply is called. + * Therefore pure service implementations should always call + * svc_sendreply even if the function logically returns void; use + * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows + * for the abuse of pure rpc via batched calling or pipelining. In the + * case of a batched call, svc_sendreply should NOT be called since + * this would send a return message, which is what batching tries to avoid. + * It is the service/protocol writer's responsibility to know which calls are + * batched and which are not. Warning: responding to batch calls may + * deadlock the caller and server processes! + */ + +extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, caddr_t); +extern void svcerr_decode(SVCXPRT *); +extern void svcerr_weakauth(SVCXPRT *); +extern void svcerr_noproc(SVCXPRT *); +extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t); +extern void svcerr_auth(SVCXPRT *, enum auth_stat); +extern void svcerr_noprog(SVCXPRT *); +extern void svcerr_systemerr(SVCXPRT *); + +/* + * Lowest level dispatching -OR- who owns this process anyway. + * Somebody has to wait for incoming requests and then call the correct + * service routine. The routine svc_run does infinite waiting; i.e., + * svc_run never returns. + * Since another (co-existant) package may wish to selectively wait for + * incoming calls or other events outside of the rpc architecture, the + * routine svc_getreq is provided. It must be passed readfds, the + * "in-place" results of a select system call (see select, section 2). + */ + +/* + * Global keeper of rpc service descriptors in use + * dynamic; must be inspected before each call to select + */ +extern int svc_maxfd; +#ifdef FD_SETSIZE +extern fd_set svc_fdset; +/* RENAMED */ +#define gssrpc_svc_fds gsssrpc_svc_fdset.fds_bits[0] /* compatibility */ +#else +extern int svc_fds; +#endif /* def FD_SETSIZE */ +extern int svc_maxfd; + +/* + * a small program implemented by the svc_rpc implementation itself; + * also see clnt.h for protocol numbers. + */ +extern void rpctest_service(); + +extern void svc_getreq(int); +#ifdef FD_SETSIZE +extern void svc_getreqset(fd_set *);/* takes fdset instead of int */ +extern void svc_getreqset2(fd_set *, int); +#else +extern void svc_getreqset(int *); +#endif +extern void svc_run(void); /* never returns */ + +/* + * Socket to use on svcxxx_create call to get default socket + */ +#define RPC_ANYSOCK -1 + +/* + * These are the existing service side transport implementations + */ + +/* + * Memory based rpc for testing and timing. + */ +extern SVCXPRT *svcraw_create(void); + +/* + * Udp based rpc. + */ +extern SVCXPRT *svcudp_create(int); +extern SVCXPRT *svcudp_bufcreate(int, u_int, u_int); +extern int svcudp_enablecache(SVCXPRT *, uint32_t); + +/* + * Tcp based rpc. + */ +extern SVCXPRT *svctcp_create(int, u_int, u_int); + +/* + * Like svtcp_create(), except the routine takes any *open* UNIX file + * descriptor as its first input. + */ +extern SVCXPRT *svcfd_create(int, u_int, u_int); + +/* XXX add auth_gsapi_log_*? */ + +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_SVC_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/types.h postgresql-hll-2.14/include/include/gssrpc/types.h --- postgresql-hll-2.14_old/include/include/gssrpc/types.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/types.h 2020-12-12 17:06:43.197347393 +0800 @@ -0,0 +1,130 @@ +/* @(#)types.h 2.3 88/08/15 4.0 RPCSRC */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the “Oracle America, Inc.” nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* @(#)types.h 1.18 87/07/24 SMI */ + +/* + * Rpc additions to + */ +#ifndef GSSRPC_TYPES_H +#define GSSRPC_TYPES_H + +#include + +#include +#include +#include + +/* + * Try to get MAXHOSTNAMELEN from somewhere. + */ +#include +/* #include */ + +/* Get htonl(), ntohl(), etc. */ +#include + +#include +#include +#include + +#ifndef GSSRPC__BEGIN_DECLS +#ifdef __cplusplus +#define GSSRPC__BEGIN_DECLS extern "C" { +#define GSSRPC__END_DECLS } +#else +#define GSSRPC__BEGIN_DECLS +#define GSSRPC__END_DECLS +#endif +#endif + +GSSRPC__BEGIN_DECLS + +#if defined(CHAR_BIT) && CHAR_BIT != 8 +#error "Bytes must be exactly 8 bits." +#endif + +/* Define if we need to fake up some BSD type aliases. */ +#ifndef GSSRPC__BSD_TYPEALIASES /* Allow application to override. */ +/* #undef GSSRPC__BSD_TYPEALIASES */ +#endif +#if GSSRPC__BSD_TYPEALIASES +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; +#endif + +typedef uint32_t rpcprog_t; +typedef uint32_t rpcvers_t; +typedef uint32_t rpcprot_t; +typedef uint32_t rpcproc_t; +typedef uint32_t rpcport_t; +typedef int32_t rpc_inline_t; + +/* This is for rpc/netdb.h */ +#define STRUCT_RPCENT_IN_RPC_NETDB_H + +#define bool_t int +#define enum_t int +#ifndef FALSE +# define FALSE (0) +#endif +#ifndef TRUE +# define TRUE (1) +#endif +/* XXX namespace */ +#define __dontcare__ -1 +#ifndef NULL +# define NULL 0 +#endif + +/* + * The below should probably be internal-only, but seem to be + * traditionally exported in RPC implementations. + */ +#define mem_alloc(bsize) malloc(bsize) +#define mem_free(ptr, bsize) free(ptr) + +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK (uint32_t)0x7F000001 +#endif +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + +GSSRPC__END_DECLS + +#include + +#endif /* !defined(GSSRPC_TYPES_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gssrpc/xdr.h postgresql-hll-2.14/include/include/gssrpc/xdr.h --- postgresql-hll-2.14_old/include/include/gssrpc/xdr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gssrpc/xdr.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,338 @@ +/* @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the "Oracle America, Inc." nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* @(#)xdr.h 1.19 87/04/22 SMI */ + +/* + * xdr.h, External Data Representation Serialization Routines. + */ + +#ifndef GSSRPC_XDR_H +#define GSSRPC_XDR_H + +#include /* for FILE */ + +GSSRPC__BEGIN_DECLS +/* + * XDR provides a conventional way for converting between C data + * types and an external bit-string representation. Library supplied + * routines provide for the conversion on built-in C data types. These + * routines and utility routines defined here are used to help implement + * a type encode/decode routine for each user-defined type. + * + * Each data type provides a single procedure which takes two arguments: + * + * bool_t + * xdrproc(xdrs, argresp) + * XDR *xdrs; + * *argresp; + * + * xdrs is an instance of a XDR handle, to which or from which the data + * type is to be converted. argresp is a pointer to the structure to be + * converted. The XDR handle contains an operation field which indicates + * which of the operations (ENCODE, DECODE * or FREE) is to be performed. + * + * XDR_DECODE may allocate space if the pointer argresp is null. This + * data can be freed with the XDR_FREE operation. + * + * We write only one procedure per data type to make it easy + * to keep the encode and decode procedures for a data type consistent. + * In many cases the same code performs all operations on a user defined type, + * because all the hard work is done in the component type routines. + * decode as a series of calls on the nested data types. + */ + +/* + * Xdr operations. XDR_ENCODE causes the type to be encoded into the + * stream. XDR_DECODE causes the type to be extracted from the stream. + * XDR_FREE can be used to release the space allocated by an XDR_DECODE + * request. + */ +enum xdr_op { + XDR_ENCODE=0, + XDR_DECODE=1, + XDR_FREE=2 +}; + +/* + * This is the number of bytes per unit of external data. + */ +#define BYTES_PER_XDR_UNIT (4) +#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ + * BYTES_PER_XDR_UNIT) + +/* + * A xdrproc_t exists for each data type which is to be encoded or decoded. + * + * The second argument to the xdrproc_t is a pointer to an opaque pointer. + * The opaque pointer generally points to a structure of the data type + * to be decoded. If this pointer is 0, then the type routines should + * allocate dynamic storage of the appropriate size and return it. + * bool_t (*xdrproc_t)(XDR *, caddr_t *); + * + * XXX can't actually prototype it, because some take three args!!! + */ +typedef bool_t (*xdrproc_t)(); + +/* + * The XDR handle. + * Contains operation which is being applied to the stream, + * an operations vector for the paticular implementation (e.g. see xdr_mem.c), + * and two private fields for the use of the particular impelementation. + */ +typedef struct XDR { + enum xdr_op x_op; /* operation; fast additional param */ + struct xdr_ops { + /* get a long from underlying stream */ + bool_t (*x_getlong)(struct XDR *, long *); + + /* put a long to underlying stream */ + bool_t (*x_putlong)(struct XDR *, long *); + + /* get some bytes from underlying stream */ + bool_t (*x_getbytes)(struct XDR *, caddr_t, u_int); + + /* put some bytes to underlying stream */ + bool_t (*x_putbytes)(struct XDR *, caddr_t, u_int); + + /* returns bytes off from beginning */ + u_int (*x_getpostn)(struct XDR *); + + /* lets you reposition the stream */ + bool_t (*x_setpostn)(struct XDR *, u_int); + + /* buf quick ptr to buffered data */ + rpc_inline_t *(*x_inline)(struct XDR *, int); + + /* free privates of this xdr_stream */ + void (*x_destroy)(struct XDR *); + } *x_ops; + caddr_t x_public; /* users' data */ + void * x_private; /* pointer to private data */ + caddr_t x_base; /* private used for position info */ + int x_handy; /* extra private word */ +} XDR; + +/* + * Operations defined on a XDR handle + * + * XDR *xdrs; + * int32_t *longp; + * caddr_t addr; + * u_int len; + * u_int pos; + */ +#define XDR_GETLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) +#define xdr_getlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) + +#define XDR_PUTLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +#define xdr_putlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) + +#define XDR_GETBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) +#define xdr_getbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) + +#define XDR_PUTBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) +#define xdr_putbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) + +#define XDR_GETPOS(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) +#define xdr_getpos(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) + +#define XDR_SETPOS(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) +#define xdr_setpos(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) + +#define XDR_INLINE(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) +#define xdr_inline(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) + +#define XDR_DESTROY(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) +#define xdr_destroy(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) + +/* + * Support struct for discriminated unions. + * You create an array of xdrdiscrim structures, terminated with + * a entry with a null procedure pointer. The xdr_union routine gets + * the discriminant value and then searches the array of structures + * for a matching value. If a match is found the associated xdr routine + * is called to handle that part of the union. If there is + * no match, then a default routine may be called. + * If there is no match and no default routine it is an error. + */ +#define NULL_xdrproc_t ((xdrproc_t)0) +struct xdr_discrim { + int value; + xdrproc_t proc; +}; + +/* + * In-line routines for fast encode/decode of primitve data types. + * Caveat emptor: these use single memory cycles to get the + * data from the underlying buffer, and will fail to operate + * properly if the data is not aligned. The standard way to use these + * is to say: + * if ((buf = XDR_INLINE(xdrs, count)) == NULL) + * return (FALSE); + * <<< macro calls >>> + * where ``count'' is the number of bytes of data occupied + * by the primitive data types. + * + * N.B. and frozen for all time: each data type here uses 4 bytes + * of external representation. + */ +#define IXDR_GET_INT32(buf) ((int32_t)IXDR_GET_U_INT32(buf)) +#define IXDR_PUT_INT32(buf, v) IXDR_PUT_U_INT32((buf),((uint32_t)(v))) +#define IXDR_GET_U_INT32(buf) (ntohl((uint32_t)*(buf)++)) +#define IXDR_PUT_U_INT32(buf, v) (*(buf)++ = (int32_t)htonl((v))) + +#define IXDR_GET_LONG(buf) ((long)IXDR_GET_INT32(buf)) +#define IXDR_PUT_LONG(buf, v) IXDR_PUT_U_INT32((buf),((uint32_t)(v))) + +#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) +#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_INT32(buf)) +#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_U_INT32(buf)) +#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_INT32(buf)) +#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_U_INT32(buf)) + +#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_INT32((buf),((int32_t)(v))) +#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_INT32((buf),((int32_t)(v))) +#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_U_INT32((buf),((uint32_t)(v))) +#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_INT32((buf),((int32_t)(v))) +#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_U_INT32((buf),((uint32_t)(v))) + +/* + * These are the "generic" xdr routines. + */ +extern bool_t xdr_void(XDR *, void *); +extern bool_t xdr_int(XDR *, int *); +extern bool_t xdr_u_int(XDR *, u_int *); +extern bool_t xdr_long(XDR *, long *); +extern bool_t xdr_u_long(XDR *, u_long *); +extern bool_t xdr_short(XDR *, short *); +extern bool_t xdr_u_short(XDR *, u_short *); +extern bool_t xdr_bool(XDR *, bool_t *); +extern bool_t xdr_enum(XDR *, enum_t *); +extern bool_t xdr_array(XDR *, caddr_t *, u_int *, + u_int, u_int, xdrproc_t); +extern bool_t xdr_bytes(XDR *, char **, u_int *, u_int); +extern bool_t xdr_opaque(XDR *, caddr_t, u_int); +extern bool_t xdr_string(XDR *, char **, u_int); +extern bool_t xdr_union(XDR *, enum_t *, char *, struct xdr_discrim *, + xdrproc_t); +extern bool_t xdr_char(XDR *, char *); +extern bool_t xdr_u_char(XDR *, u_char *); +extern bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); +extern bool_t xdr_float(XDR *, float *); +extern bool_t xdr_double(XDR *, double *); +extern bool_t xdr_reference(XDR *, caddr_t *, u_int, xdrproc_t); +extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t); +extern bool_t xdr_wrapstring(XDR *, char **); + +extern unsigned long xdr_sizeof(xdrproc_t, void *); + +#define xdr_rpcprog xdr_u_int32 +#define xdr_rpcvers xdr_u_int32 +#define xdr_rpcprot xdr_u_int32 +#define xdr_rpcproc xdr_u_int32 +#define xdr_rpcport xdr_u_int32 + +/* + * Common opaque bytes objects used by many rpc protocols; + * declared here due to commonality. + */ +#define MAX_NETOBJ_SZ 2048 +struct netobj { + u_int n_len; + char *n_bytes; +}; +typedef struct netobj netobj; + +extern bool_t xdr_netobj(XDR *, struct netobj *); + +extern bool_t xdr_int32(XDR *, int32_t *); +extern bool_t xdr_u_int32(XDR *, uint32_t *); + +/* + * These are the public routines for the various implementations of + * xdr streams. + */ + +/* XDR allocating memory buffer */ +extern void xdralloc_create(XDR *, enum xdr_op); + +/* destroy xdralloc, save buf */ +extern void xdralloc_release(XDR *); + +/* get buffer from xdralloc */ +extern caddr_t xdralloc_getdata(XDR *); + +/* XDR using memory buffers */ +extern void xdrmem_create(XDR *, caddr_t, u_int, enum xdr_op); + +/* XDR using stdio library */ +extern void xdrstdio_create(XDR *, FILE *, enum xdr_op); + +/* XDR pseudo records for tcp */ +extern void xdrrec_create(XDR *xdrs, u_int, u_int, caddr_t, + int (*) (caddr_t, caddr_t, int), + int (*) (caddr_t, caddr_t, int)); + +/* make end of xdr record */ +extern bool_t xdrrec_endofrecord(XDR *, bool_t); + +/* move to beginning of next record */ +extern bool_t xdrrec_skiprecord (XDR *xdrs); + +/* true if no more input */ +extern bool_t xdrrec_eof (XDR *xdrs); + +/* free memory buffers for xdr */ +extern void xdr_free (xdrproc_t, void *); +GSSRPC__END_DECLS + +#endif /* !defined(GSSRPC_XDR_H) */ diff -uprN postgresql-hll-2.14_old/include/include/gs_tar_const.h postgresql-hll-2.14/include/include/gs_tar_const.h --- postgresql-hll-2.14_old/include/include/gs_tar_const.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_tar_const.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,91 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * + * + * IDENTIFICATION + * src/include/gs_tar_const.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_TAR_CONST_H_ +#define GS_TAR_CONST_H_ + +#ifdef HAVE_LIBZ +#include "zlib.h" +#endif + + +/* gs_tar offset */ +static const int TAR_LEN_LEFT = 1048; +static const int TAR_FILE_PADDING = 511; /* All files are padded up to 512 bytes */ +static const int TAR_FILE_TYPE = 1080; /* file type */ +static const int TAR_BLOCK_SIZE = 2560; /* gs_tar block size */ +static const int TAR_FILE_MODE = 1024; + +/* fileStream result */ +static const int TAR_READ_ERROR = -2; + +/* file type */ +static const char TAR_TYPE_DICTORY = '5'; +static const int FILE_PERMISSION = 16832; + +#define PADDING_LEFT(current_len_left) (((current_len_left + TAR_FILE_PADDING) & ~TAR_FILE_PADDING) - current_len_left); + +#define CLOSE_AND_RETURN(tarfile) \ + do { \ + fclose(tarfile); \ + return -1; \ + } while (0) + +#define CLOSE_AND_SET_NULL(file) \ + do { \ + fclose(file); \ + file = NULL; \ + } while (0) + +#ifdef HAVE_LIBZ +static const char* get_gz_error(gzFile gzf) +{ + int errnum; + const char* errmsg = NULL; + + errmsg = gzerror(gzf, &errnum); + if (errnum == Z_ERRNO) + return strerror(errno); + else + return errmsg; +} + +static gzFile openGzFile(const char* filename, int compresslevel, const char* mode = "wb") +{ + gzFile ztarfile = gzopen(filename, mode); + if (gzsetparams(ztarfile, compresslevel, Z_DEFAULT_STRATEGY) != Z_OK) { + return NULL; + } + return ztarfile; +} + +static bool writeGzFile(gzFile ztarfile, char* copybuf, int buf_size) +{ + if (gzwrite(ztarfile, copybuf, buf_size) != buf_size) { + return false; + } + return true; +} +#endif + +#endif /* GS_TAR_CONST_H_ */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gs_thread.h postgresql-hll-2.14/include/include/gs_thread.h --- postgresql-hll-2.14_old/include/include/gs_thread.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_thread.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,196 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_thread.h + * Exports from src/port/gs_thread.c. + * + * + * IDENTIFICATION + * src/include/gs_thread.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_THREAD_H_ +#define GS_THREAD_H_ + +#include "gs_threadlocal.h" + +#ifdef WIN32 +#include +#define _WINSOCKAPI_ +#include +#else +#include +#endif + +#define gs_thread_id(_t) ((_t).thid) + +#ifdef WIN32 +#define gs_thread_handle(_t) ((HANDLE)(_t).os_handle) +typedef unsigned ThreadId; +typedef struct gs_thread_t { + ThreadId thid; + HANDLE os_handle; +} gs_thread_t; +#else + +typedef pthread_t ThreadId; +typedef struct gs_thread_t { + ThreadId thid; +} gs_thread_t; +#endif + +typedef enum knl_thread_role { + MASTER_THREAD = 0, + WORKER = 1, + THREADPOOL_WORKER = 2, + THREADPOOL_LISTENER, + THREADPOOL_SCHEDULER, + THREADPOOL_STREAM, + STREAM_WORKER, + AUTOVACUUM_LAUNCHER, + AUTOVACUUM_WORKER, + JOB_SCHEDULER, + JOB_WORKER, + WLM_WORKER, + WLM_MONITOR, + WLM_ARBITER, + WLM_CPMONITOR, + AUDITOR, + PGSTAT, + SYSLOGGER, + RPC_WORKER, + RPC_SERVICE, + CATCHUP, + ARCH, + ALARMCHECK, + REAPER, + PAGEREDO, + TWOPASECLEANER, + STARTUP, + FAULTMONITOR, + BGWRITER, + PERCENTILE_WORKER, + SNAPSHOT_WORKER, + ASH_WORKER, + STATEMENT_WORKER, + CHECKPOINT_THREAD, + WALWRITER, + WALWRITERAUXILIARY, + WALRECEIVER, + WALRECWRITE, + DATARECIVER, + DATARECWRITER, + CBMWRITER, + PAGEWRITER_THREAD, + HEARTBEAT, + COMM_SENDERFLOWER, + COMM_RECEIVERFLOWER, + COMM_RECEIVER, + COMM_AUXILIARY, + COMM_POOLER_CLEAN, + CSNMIN_SYNC, + TS_COMPACTION, + TS_COMPACTION_CONSUMER, + TS_COMPACTION_AUXILIAY, + STREAMING_BACKEND, + STREAMING_ROUTER_BACKEND, + STREAMING_WORKER_BACKEND, + STREAMING_COLLECTOR_BACKEND, + STREAMING_QUEUE_BACKEND, + STREAMING_REAPER_BACKEND, + /* should be last valid thread. */ + THREAD_ENTRY_BOUND, + + NO_SUBROLE, + REDISTRIBUTION_WORKER, + WAL_NORMAL_SENDER, + WAL_STANDBY_SENDER, /* Am I cascading WAL to another standby ? */ + WAL_DB_SENDER, + TOP_CONSUMER, +} knl_thread_role; + +/* + * It is an 64bit identifier in Linux x64 system. There are many legacy + * code assumes the original pid is 32 bit where we replace with threadId. + * If printf this number, we use %lu within the server. When compare valid + * ThreadIds, use PtThread::Equal() function. + */ +#define INVALID_NEXT_ADDR (void*)((unsigned long)(-1)) + +typedef struct knl_thread_arg { + knl_thread_role role; + char* save_para; + void* payload; + void* t_thrd; + union { + struct syslog_thread { + int syslog_handle; + } log_thread; + } extra_payload; +} knl_thread_arg; + +typedef int (*GaussdbThreadEntry)(knl_thread_arg* arg); + +typedef struct ThreadMetaData { + GaussdbThreadEntry func; + knl_thread_role role; + const char* thr_name; /* keep strlen(thr_name) < 16 */ + const char* thr_long_name; +} ThreadMetaData; + +/* + * A generic holder to keep all necessary arguments passed to generic + * ThreadStarterFunc() function. + */ +typedef struct ThreadArg { + void* (*m_taskRoutine)(void*); /* Task function caller passed in by the caller. */ + struct ThreadArg* next; /* if next is INVALID_NEXT_ID, the ThreadArg is malloc when create a thread */ + knl_thread_arg m_thd_arg; +} ThreadArg; + +#define InvalidTid ((ThreadId)(-1)) /* An invalid thread identifier */ + +#ifdef WIN32 +extern HANDLE gs_thread_get_handle(unsigned ThreadId); +#endif + +extern gs_thread_t gs_thread_get_cur_thread(void); + +extern ThreadId gs_thread_self(void); + +extern void gs_thread_exit(int code); +extern void gs_thread_args_free(void); + +extern int gs_thread_create(gs_thread_t* thread, void* (*taskRoutine)(void*), int argc, void* argv); + +extern int gs_thread_join(gs_thread_t thread, void** value_ptr); + +extern void gs_thread_args_pool_init(unsigned long pool_size, unsigned long backend_para_size); + +extern void gs_thread_release_args_slot(ThreadArg* thrArg); + +extern ThreadArg* gs_thread_get_args_slot(void); + +extern void gs_thread_get_name(char** name_thread, char** argv, int argc); + +extern void ThreadExitCXX(int code); +extern int ShowThreadName(const char* name); + +typedef void (*uuid_struct_destroy_hook_type)(int which); +extern THR_LOCAL uuid_struct_destroy_hook_type uuid_struct_destroy_hook; + +#endif /*GS_THREAD_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gs_threadlocal.h postgresql-hll-2.14/include/include/gs_threadlocal.h --- postgresql-hll-2.14_old/include/include/gs_threadlocal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gs_threadlocal.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_threadlocal.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gs_threadlocal.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GS_THREADLOCAL_H_ +#define GS_THREADLOCAL_H_ + +/*PClint*/ +#ifdef PC_LINT +#define THR_LOCAL +#endif + +#ifndef THR_LOCAL +#ifndef WIN32 +#define THR_LOCAL __thread +#else +#define THR_LOCAL __declspec(thread) +#endif +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gstrace/access_gstrace.h postgresql-hll-2.14/include/include/gstrace/access_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/access_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/access_gstrace.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,121 @@ +// This is a generated file + +#ifndef _ACCESS_GSTRACE_H +#define _ACCESS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_heap_compute_data_size GS_TRC_ID_PACK(COMP_ACCESS, 1) +#define GS_TRC_ID_heap_fill_tuple GS_TRC_ID_PACK(COMP_ACCESS, 2) +#define GS_TRC_ID_heap_attisnull GS_TRC_ID_PACK(COMP_ACCESS, 3) +#define GS_TRC_ID_nocache_cmprs_get_attr GS_TRC_ID_PACK(COMP_ACCESS, 4) +#define GS_TRC_ID_nocachegetattr GS_TRC_ID_PACK(COMP_ACCESS, 5) +#define GS_TRC_ID_heap_getsysattr GS_TRC_ID_PACK(COMP_ACCESS, 6) +#define GS_TRC_ID_heap_copytuple GS_TRC_ID_PACK(COMP_ACCESS, 7) +#define GS_TRC_ID_heapCopyCompressedTuple GS_TRC_ID_PACK(COMP_ACCESS, 8) +#define GS_TRC_ID_heapCopyTuple GS_TRC_ID_PACK(COMP_ACCESS, 9) +#define GS_TRC_ID_heap_copytuple_with_tuple GS_TRC_ID_PACK(COMP_ACCESS, 10) +#define GS_TRC_ID_heap_form_tuple GS_TRC_ID_PACK(COMP_ACCESS, 11) +#define GS_TRC_ID_heap_form_cmprs_tuple GS_TRC_ID_PACK(COMP_ACCESS, 12) +#define GS_TRC_ID_heap_modify_tuple GS_TRC_ID_PACK(COMP_ACCESS, 13) +#define GS_TRC_ID_heap_deform_cmprs_tuple GS_TRC_ID_PACK(COMP_ACCESS, 14) +#define GS_TRC_ID_heap_deform_tuple GS_TRC_ID_PACK(COMP_ACCESS, 15) +#define GS_TRC_ID_heap_deform_tuple2 GS_TRC_ID_PACK(COMP_ACCESS, 16) +#define GS_TRC_ID_heap_deform_tuple3 GS_TRC_ID_PACK(COMP_ACCESS, 17) +#define GS_TRC_ID_heap_formtuple GS_TRC_ID_PACK(COMP_ACCESS, 18) +#define GS_TRC_ID_heap_modifytuple GS_TRC_ID_PACK(COMP_ACCESS, 19) +#define GS_TRC_ID_heap_deformtuple GS_TRC_ID_PACK(COMP_ACCESS, 20) +#define GS_TRC_ID_heap_freetuple GS_TRC_ID_PACK(COMP_ACCESS, 21) +#define GS_TRC_ID_heap_form_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 22) +#define GS_TRC_ID_heap_free_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 23) +#define GS_TRC_ID_heap_copy_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 24) +#define GS_TRC_ID_heap_tuple_from_minimal_tuple GS_TRC_ID_PACK(COMP_ACCESS, 25) +#define GS_TRC_ID_minimal_tuple_from_heap_tuple GS_TRC_ID_PACK(COMP_ACCESS, 26) +#define GS_TRC_ID_heapGetInitDefVal GS_TRC_ID_PACK(COMP_ACCESS, 27) +#define GS_TRC_ID_relationAttIsNull GS_TRC_ID_PACK(COMP_ACCESS, 28) +#define GS_TRC_ID_heapFormMinimalTuple GS_TRC_ID_PACK(COMP_ACCESS, 29) +#define GS_TRC_ID_XLogInsertRecord GS_TRC_ID_PACK(COMP_ACCESS, 30) +#define GS_TRC_ID_XLogFlush GS_TRC_ID_PACK(COMP_ACCESS, 31) +#define GS_TRC_ID_XLogBackgroundFlush GS_TRC_ID_PACK(COMP_ACCESS, 32) +#define GS_TRC_ID_XLogNeedsFlush GS_TRC_ID_PACK(COMP_ACCESS, 33) +#define GS_TRC_ID_XLogFileInit GS_TRC_ID_PACK(COMP_ACCESS, 34) +#define GS_TRC_ID_XLogFileOpen GS_TRC_ID_PACK(COMP_ACCESS, 35) +#define GS_TRC_ID_CheckXLogRemoved GS_TRC_ID_PACK(COMP_ACCESS, 36) +#define GS_TRC_ID_XLogSetAsyncXactLSN GS_TRC_ID_PACK(COMP_ACCESS, 37) +#define GS_TRC_ID_XLogSetReplicationSlotMinimumLSN GS_TRC_ID_PACK(COMP_ACCESS, 38) +#define GS_TRC_ID_XLogSetReplicationSlotMaximumLSN GS_TRC_ID_PACK(COMP_ACCESS, 39) +#define GS_TRC_ID_XLogGetReplicationSlotMaximumLSN GS_TRC_ID_PACK(COMP_ACCESS, 40) +#define GS_TRC_ID_xlog_redo GS_TRC_ID_PACK(COMP_ACCESS, 41) +#define GS_TRC_ID_xlog_desc GS_TRC_ID_PACK(COMP_ACCESS, 42) +#define GS_TRC_ID_issue_xlog_fsync GS_TRC_ID_PACK(COMP_ACCESS, 43) +#define GS_TRC_ID_RecoveryInProgress GS_TRC_ID_PACK(COMP_ACCESS, 44) +#define GS_TRC_ID_HotStandbyActive GS_TRC_ID_PACK(COMP_ACCESS, 45) +#define GS_TRC_ID_HotStandbyActiveInReplay GS_TRC_ID_PACK(COMP_ACCESS, 46) +#define GS_TRC_ID_XLogInsertAllowed GS_TRC_ID_PACK(COMP_ACCESS, 47) +#define GS_TRC_ID_GetXLogReceiptTime GS_TRC_ID_PACK(COMP_ACCESS, 48) +#define GS_TRC_ID_GetXLogReplayRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 49) +#define GS_TRC_ID_GetXLogReplayRecPtrInPending GS_TRC_ID_PACK(COMP_ACCESS, 50) +#define GS_TRC_ID_GetStandbyFlushRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 51) +#define GS_TRC_ID_GetXLogInsertRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 52) +#define GS_TRC_ID_GetXLogWriteRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 53) +#define GS_TRC_ID_RecoveryIsPaused GS_TRC_ID_PACK(COMP_ACCESS, 54) +#define GS_TRC_ID_SetRecoveryPause GS_TRC_ID_PACK(COMP_ACCESS, 55) +#define GS_TRC_ID_GetLatestXTime GS_TRC_ID_PACK(COMP_ACCESS, 56) +#define GS_TRC_ID_GetCurrentChunkReplayStartTime GS_TRC_ID_PACK(COMP_ACCESS, 57) +#define GS_TRC_ID_GetXlogRecordCrc GS_TRC_ID_PACK(COMP_ACCESS, 58) +#define GS_TRC_ID_UpdateControlFile GS_TRC_ID_PACK(COMP_ACCESS, 59) +#define GS_TRC_ID_GetSystemIdentifier GS_TRC_ID_PACK(COMP_ACCESS, 60) +#define GS_TRC_ID_SetSystemIdentifier GS_TRC_ID_PACK(COMP_ACCESS, 61) +#define GS_TRC_ID_GetThisTimeID GS_TRC_ID_PACK(COMP_ACCESS, 62) +#define GS_TRC_ID_SetThisTimeID GS_TRC_ID_PACK(COMP_ACCESS, 63) +#define GS_TRC_ID_XLOGShmemSize GS_TRC_ID_PACK(COMP_ACCESS, 64) +#define GS_TRC_ID_XLOGShmemInit GS_TRC_ID_PACK(COMP_ACCESS, 65) +#define GS_TRC_ID_BootStrapXLOG GS_TRC_ID_PACK(COMP_ACCESS, 66) +#define GS_TRC_ID_StartupXLOG GS_TRC_ID_PACK(COMP_ACCESS, 67) +#define GS_TRC_ID_ShutdownXLOG GS_TRC_ID_PACK(COMP_ACCESS, 68) +#define GS_TRC_ID_InitXLOGAccess GS_TRC_ID_PACK(COMP_ACCESS, 69) +#define GS_TRC_ID_StartupDummyStandby GS_TRC_ID_PACK(COMP_ACCESS, 70) +#define GS_TRC_ID_CreateCheckPoint GS_TRC_ID_PACK(COMP_ACCESS, 71) +#define GS_TRC_ID_CreateRestartPoint GS_TRC_ID_PACK(COMP_ACCESS, 72) +#define GS_TRC_ID_CheckPointGuts GS_TRC_ID_PACK(COMP_ACCESS, 73) +#define GS_TRC_ID_XLogPutNextOid GS_TRC_ID_PACK(COMP_ACCESS, 74) +#define GS_TRC_ID_XLogRestorePoint GS_TRC_ID_PACK(COMP_ACCESS, 75) +#define GS_TRC_ID_UpdateFullPageWrites GS_TRC_ID_PACK(COMP_ACCESS, 76) +#define GS_TRC_ID_GetFullPageWriteInfo GS_TRC_ID_PACK(COMP_ACCESS, 77) +#define GS_TRC_ID_GetRedoRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 78) +#define GS_TRC_ID_GetInsertRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 79) +#define GS_TRC_ID_GetFlushRecPtr GS_TRC_ID_PACK(COMP_ACCESS, 80) +#define GS_TRC_ID_GetNextXidAndEpoch GS_TRC_ID_PACK(COMP_ACCESS, 81) +#define GS_TRC_ID_GetRecoveryTargetTLI GS_TRC_ID_PACK(COMP_ACCESS, 82) +#define GS_TRC_ID_DummyStandbySetRecoveryTargetTLI GS_TRC_ID_PACK(COMP_ACCESS, 83) +#define GS_TRC_ID_CheckPromoteSignal GS_TRC_ID_PACK(COMP_ACCESS, 84) +#define GS_TRC_ID_CheckPrimarySignal GS_TRC_ID_PACK(COMP_ACCESS, 85) +#define GS_TRC_ID_CheckStandbySignal GS_TRC_ID_PACK(COMP_ACCESS, 86) +#define GS_TRC_ID_CheckSwitchoverSignal GS_TRC_ID_PACK(COMP_ACCESS, 87) +#define GS_TRC_ID_ReadLsnXlogFlushChkFile GS_TRC_ID_PACK(COMP_ACCESS, 88) +#define GS_TRC_ID_WakeupRecovery GS_TRC_ID_PACK(COMP_ACCESS, 89) +#define GS_TRC_ID_WakeupDataRecovery GS_TRC_ID_PACK(COMP_ACCESS, 90) +#define GS_TRC_ID_SetWalWriterSleeping GS_TRC_ID_PACK(COMP_ACCESS, 91) +#define GS_TRC_ID_CheckFpwBeforeFirstCkpt GS_TRC_ID_PACK(COMP_ACCESS, 92) +#define GS_TRC_ID_DisableFpwBeforeFirstCkpt GS_TRC_ID_PACK(COMP_ACCESS, 93) +#define GS_TRC_ID_UpdateLsnXlogFlushChkFile GS_TRC_ID_PACK(COMP_ACCESS, 94) +#define GS_TRC_ID_LsnXlogFlushChkShmemSize GS_TRC_ID_PACK(COMP_ACCESS, 95) +#define GS_TRC_ID_LsnXlogFlushChkShmInit GS_TRC_ID_PACK(COMP_ACCESS, 96) +#define GS_TRC_ID_IfLsnXlogFlushChkFileExist GS_TRC_ID_PACK(COMP_ACCESS, 97) +#define GS_TRC_ID_heap_xlog_logical_new_page GS_TRC_ID_PACK(COMP_ACCESS, 98) +#define GS_TRC_ID_StartTransaction GS_TRC_ID_PACK(COMP_ACCESS, 99) +#define GS_TRC_ID_KeepLogSeg GS_TRC_ID_PACK(COMP_ACCESS, 100) +#define GS_TRC_ID_RemoveOldXlogFiles GS_TRC_ID_PACK(COMP_ACCESS, 101) +#define GS_TRC_ID_dw_truncate GS_TRC_ID_PACK(COMP_ACCESS, 102) +#define GS_TRC_ID_heap_change_xidbase_after_freeze GS_TRC_ID_PACK(COMP_ACCESS, 103) +#define GS_TRC_ID_heap_page_prepare_for_xid GS_TRC_ID_PACK(COMP_ACCESS, 104) +#define GS_TRC_ID_ExtendCSNLOG GS_TRC_ID_PACK(COMP_ACCESS, 105) +#define GS_TRC_ID_freeze_single_heap_page GS_TRC_ID_PACK(COMP_ACCESS, 106) +#define GS_TRC_ID_heap_page_prune GS_TRC_ID_PACK(COMP_ACCESS, 107) +#define GS_TRC_ID_heap_prune_chain GS_TRC_ID_PACK(COMP_ACCESS, 108) +#define GS_TRC_ID_PreallocXlogFiles GS_TRC_ID_PACK(COMP_ACCESS, 109) +#define GS_TRC_ID_do_pg_stop_backup GS_TRC_ID_PACK(COMP_ACCESS, 110) +#define GS_TRC_ID_do_pg_start_backup GS_TRC_ID_PACK(COMP_ACCESS, 111) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/bootstrap_gstrace.h postgresql-hll-2.14/include/include/gstrace/bootstrap_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/bootstrap_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/bootstrap_gstrace.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,25 @@ +// This is a generated file + +#ifndef _BOOTSTRAP_GSTRACE_H +#define _BOOTSTRAP_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_AuxiliaryProcessMain GS_TRC_ID_PACK(COMP_BOOTSTRAP, 1) +#define GS_TRC_ID_err_out GS_TRC_ID_PACK(COMP_BOOTSTRAP, 2) +#define GS_TRC_ID_closerel GS_TRC_ID_PACK(COMP_BOOTSTRAP, 3) +#define GS_TRC_ID_boot_openrel GS_TRC_ID_PACK(COMP_BOOTSTRAP, 4) +#define GS_TRC_ID_DefineAttr GS_TRC_ID_PACK(COMP_BOOTSTRAP, 5) +#define GS_TRC_ID_InsertOneTuple GS_TRC_ID_PACK(COMP_BOOTSTRAP, 6) +#define GS_TRC_ID_InsertOneValue GS_TRC_ID_PACK(COMP_BOOTSTRAP, 7) +#define GS_TRC_ID_InsertOneNull GS_TRC_ID_PACK(COMP_BOOTSTRAP, 8) +#define GS_TRC_ID_MapArrayTypeName GS_TRC_ID_PACK(COMP_BOOTSTRAP, 9) +#define GS_TRC_ID_index_register GS_TRC_ID_PACK(COMP_BOOTSTRAP, 10) +#define GS_TRC_ID_build_indices GS_TRC_ID_PACK(COMP_BOOTSTRAP, 11) +#define GS_TRC_ID_boot_get_type_io_data GS_TRC_ID_PACK(COMP_BOOTSTRAP, 12) +#define GS_TRC_ID_boot_yyparse GS_TRC_ID_PACK(COMP_BOOTSTRAP, 13) +#define GS_TRC_ID_boot_yylex GS_TRC_ID_PACK(COMP_BOOTSTRAP, 14) +#define GS_TRC_ID_boot_yyerror GS_TRC_ID_PACK(COMP_BOOTSTRAP, 15) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/catalog_gstrace.h postgresql-hll-2.14/include/include/gstrace/catalog_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/catalog_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/catalog_gstrace.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,54 @@ +// This is a generated file + +#ifndef _CATALOG_GSTRACE_H +#define _CATALOG_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_forkname_to_number GS_TRC_ID_PACK(COMP_CATALOG, 1) +#define GS_TRC_ID_forkname_chars GS_TRC_ID_PACK(COMP_CATALOG, 2) +#define GS_TRC_ID_relpathbackend GS_TRC_ID_PACK(COMP_CATALOG, 3) +#define GS_TRC_ID_GetDatabasePath GS_TRC_ID_PACK(COMP_CATALOG, 4) +#define GS_TRC_ID_relpath_to_filenode GS_TRC_ID_PACK(COMP_CATALOG, 5) +#define GS_TRC_ID_IsSystemRelation GS_TRC_ID_PACK(COMP_CATALOG, 6) +#define GS_TRC_ID_IsToastRelation GS_TRC_ID_PACK(COMP_CATALOG, 7) +#define GS_TRC_ID_IsSystemClass GS_TRC_ID_PACK(COMP_CATALOG, 8) +#define GS_TRC_ID_IsToastClass GS_TRC_ID_PACK(COMP_CATALOG, 9) +#define GS_TRC_ID_IsSystemNamespace GS_TRC_ID_PACK(COMP_CATALOG, 10) +#define GS_TRC_ID_IsToastNamespace GS_TRC_ID_PACK(COMP_CATALOG, 11) +#define GS_TRC_ID_IsCStoreNamespace GS_TRC_ID_PACK(COMP_CATALOG, 12) +#define GS_TRC_ID_IsReservedName GS_TRC_ID_PACK(COMP_CATALOG, 13) +#define GS_TRC_ID_IsSharedRelation GS_TRC_ID_PACK(COMP_CATALOG, 14) +#define GS_TRC_ID_GetNewOid GS_TRC_ID_PACK(COMP_CATALOG, 15) +#define GS_TRC_ID_GetNewOidWithIndex GS_TRC_ID_PACK(COMP_CATALOG, 16) +#define GS_TRC_ID_GetNewRelFileNode GS_TRC_ID_PACK(COMP_CATALOG, 17) +#define GS_TRC_ID_heap_truncate GS_TRC_ID_PACK(COMP_CATALOG, 18) +#define GS_TRC_ID_heap_truncate_one_rel GS_TRC_ID_PACK(COMP_CATALOG, 19) +#define GS_TRC_ID_heap_truncate_check_FKs GS_TRC_ID_PACK(COMP_CATALOG, 20) +#define GS_TRC_ID_heap_truncate_find_FKs GS_TRC_ID_PACK(COMP_CATALOG, 21) +#define GS_TRC_ID_InsertPgAttributeTuple GS_TRC_ID_PACK(COMP_CATALOG, 22) +#define GS_TRC_ID_InsertPgClassTuple GS_TRC_ID_PACK(COMP_CATALOG, 23) +#define GS_TRC_ID_AddRelationNewConstraints GS_TRC_ID_PACK(COMP_CATALOG, 24) +#define GS_TRC_ID_AddRelClusterConstraints GS_TRC_ID_PACK(COMP_CATALOG, 25) +#define GS_TRC_ID_StoreAttrDefault GS_TRC_ID_PACK(COMP_CATALOG, 26) +#define GS_TRC_ID_cookDefault GS_TRC_ID_PACK(COMP_CATALOG, 27) +#define GS_TRC_ID_DeleteRelationTuple GS_TRC_ID_PACK(COMP_CATALOG, 28) +#define GS_TRC_ID_DeleteAttributeTuples GS_TRC_ID_PACK(COMP_CATALOG, 29) +#define GS_TRC_ID_DeleteSystemAttributeTuples GS_TRC_ID_PACK(COMP_CATALOG, 30) +#define GS_TRC_ID_RemoveAttributeById GS_TRC_ID_PACK(COMP_CATALOG, 31) +#define GS_TRC_ID_RemoveAttrDefault GS_TRC_ID_PACK(COMP_CATALOG, 32) +#define GS_TRC_ID_RemoveAttrDefaultById GS_TRC_ID_PACK(COMP_CATALOG, 33) +#define GS_TRC_ID_RemoveStatistics GS_TRC_ID_PACK(COMP_CATALOG, 34) +#define GS_TRC_ID_SystemAttributeDefinition GS_TRC_ID_PACK(COMP_CATALOG, 35) +#define GS_TRC_ID_SystemAttributeByName GS_TRC_ID_PACK(COMP_CATALOG, 36) +#define GS_TRC_ID_CheckAttributeNamesTypes GS_TRC_ID_PACK(COMP_CATALOG, 37) +#define GS_TRC_ID_CheckAttributeType GS_TRC_ID_PACK(COMP_CATALOG, 38) +#define GS_TRC_ID_AddRelationDistribution GS_TRC_ID_PACK(COMP_CATALOG, 39) +#define GS_TRC_ID_GetRelationDistributionItems GS_TRC_ID_PACK(COMP_CATALOG, 40) +#define GS_TRC_ID_GetRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 41) +#define GS_TRC_ID_BuildRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 42) +#define GS_TRC_ID_SortRelationDistributionNodes GS_TRC_ID_PACK(COMP_CATALOG, 43) +#define GS_TRC_ID_SetRelHasClusterKey GS_TRC_ID_PACK(COMP_CATALOG, 44) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/commands_gstrace.h postgresql-hll-2.14/include/include/gstrace/commands_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/commands_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/commands_gstrace.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,53 @@ +// This is a generated file + +#ifndef _COMMANDS_GSTRACE_H +#define _COMMANDS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_createdb GS_TRC_ID_PACK(COMP_COMMANDS, 1) +#define GS_TRC_ID_dropdb GS_TRC_ID_PACK(COMP_COMMANDS, 2) +#define GS_TRC_ID_RenameDatabase GS_TRC_ID_PACK(COMP_COMMANDS, 3) +#define GS_TRC_ID_AlterDatabase GS_TRC_ID_PACK(COMP_COMMANDS, 4) +#define GS_TRC_ID_AlterDatabaseSet GS_TRC_ID_PACK(COMP_COMMANDS, 5) +#define GS_TRC_ID_AlterDatabaseOwner GS_TRC_ID_PACK(COMP_COMMANDS, 6) +#define GS_TRC_ID_get_database_oid GS_TRC_ID_PACK(COMP_COMMANDS, 7) +#define GS_TRC_ID_get_database_name GS_TRC_ID_PACK(COMP_COMMANDS, 8) +#define GS_TRC_ID_dbase_redo GS_TRC_ID_PACK(COMP_COMMANDS, 9) +#define GS_TRC_ID_dbase_desc GS_TRC_ID_PACK(COMP_COMMANDS, 10) +#define GS_TRC_ID_check_encoding_locale_matches GS_TRC_ID_PACK(COMP_COMMANDS, 11) +#define GS_TRC_ID_IsSetTableSpace GS_TRC_ID_PACK(COMP_COMMANDS, 12) +#define GS_TRC_ID_errdetail_busy_db GS_TRC_ID_PACK(COMP_COMMANDS, 13) +#define GS_TRC_ID_PreCleanAndCheckConns GS_TRC_ID_PACK(COMP_COMMANDS, 14) +#define GS_TRC_ID_vacuum GS_TRC_ID_PACK(COMP_COMMANDS, 15) +#define GS_TRC_ID_vac_open_indexes GS_TRC_ID_PACK(COMP_COMMANDS, 16) +#define GS_TRC_ID_vac_close_indexes GS_TRC_ID_PACK(COMP_COMMANDS, 17) +#define GS_TRC_ID_vac_estimate_reltuples GS_TRC_ID_PACK(COMP_COMMANDS, 18) +#define GS_TRC_ID_vac_update_relstats GS_TRC_ID_PACK(COMP_COMMANDS, 19) +#define GS_TRC_ID_vacuum_set_xid_limits GS_TRC_ID_PACK(COMP_COMMANDS, 20) +#define GS_TRC_ID_vac_update_datfrozenxid GS_TRC_ID_PACK(COMP_COMMANDS, 21) +#define GS_TRC_ID_vacuum_delay_point GS_TRC_ID_PACK(COMP_COMMANDS, 22) +#define GS_TRC_ID_analyze_rel GS_TRC_ID_PACK(COMP_COMMANDS, 23) +#define GS_TRC_ID_buildTempSampleTable GS_TRC_ID_PACK(COMP_COMMANDS, 24) +#define GS_TRC_ID_dropSampleTable GS_TRC_ID_PACK(COMP_COMMANDS, 25) +#define GS_TRC_ID_DefineRelation GS_TRC_ID_PACK(COMP_COMMANDS, 26) +#define GS_TRC_ID_RemoveRelations GS_TRC_ID_PACK(COMP_COMMANDS, 27) +#define GS_TRC_ID_AlterTableLookupRelation GS_TRC_ID_PACK(COMP_COMMANDS, 28) +#define GS_TRC_ID_AlterTable GS_TRC_ID_PACK(COMP_COMMANDS, 29) +#define GS_TRC_ID_AlterTableGetLockLevel GS_TRC_ID_PACK(COMP_COMMANDS, 30) +#define GS_TRC_ID_ATExecChangeOwner GS_TRC_ID_PACK(COMP_COMMANDS, 31) +#define GS_TRC_ID_AlterTableInternal GS_TRC_ID_PACK(COMP_COMMANDS, 32) +#define GS_TRC_ID_AlterTableNamespace GS_TRC_ID_PACK(COMP_COMMANDS, 33) +#define GS_TRC_ID_AlterTableNamespaceInternal GS_TRC_ID_PACK(COMP_COMMANDS, 34) +#define GS_TRC_ID_AlterRelationNamespaceInternal GS_TRC_ID_PACK(COMP_COMMANDS, 35) +#define GS_TRC_ID_vacuum_rel GS_TRC_ID_PACK(COMP_COMMANDS, 36) +#define GS_TRC_ID_cluster_rel GS_TRC_ID_PACK(COMP_COMMANDS, 37) +#define GS_TRC_ID_lazy_scan_heap GS_TRC_ID_PACK(COMP_COMMANDS, 38) +#define GS_TRC_ID_lazy_vacuum_rel GS_TRC_ID_PACK(COMP_COMMANDS, 39) +#define GS_TRC_ID_lazy_vacuum_index GS_TRC_ID_PACK(COMP_COMMANDS, 40) +#define GS_TRC_ID_lazy_vacuum_heap GS_TRC_ID_PACK(COMP_COMMANDS, 41) +#define GS_TRC_ID_lazy_truncate_heap GS_TRC_ID_PACK(COMP_COMMANDS, 42) +#define GS_TRC_ID_lazy_cleanup_index GS_TRC_ID_PACK(COMP_COMMANDS, 43) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/common_gstrace.h postgresql-hll-2.14/include/include/gstrace/common_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/common_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/common_gstrace.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,13 @@ +// This is a generated file + +#ifndef _COMMON_GSTRACE_H +#define _COMMON_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_charshow_estimated_time GS_TRC_ID_PACK(COMP_COMMON, 1) +#define GS_TRC_ID_charshow_datasize GS_TRC_ID_PACK(COMP_COMMON, 2) +#define GS_TRC_ID_UpdateDBStateFile GS_TRC_ID_PACK(COMP_COMMON, 3) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/comps.h postgresql-hll-2.14/include/include/gstrace/comps.h --- postgresql-hll-2.14_old/include/include/gstrace/comps.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/comps.h 2020-12-12 17:06:43.198347406 +0800 @@ -0,0 +1,28 @@ +// This is a generated file + +#ifndef _COMPS_H +#define _COMPS_H + +#define COMP_COMMON 1 +#define COMP_LIBPQ 2 +#define COMP_PG_CTL 3 +#define COMP_ACCESS 4 +#define COMP_BOOTSTRAP 5 +#define COMP_CATALOG 6 +#define COMP_PARSER 7 +#define COMP_COMMANDS 8 +#define COMP_EXECUTER 9 +#define COMP_VECEXECUTOR 10 +#define COMP_OPTIMIZER 11 +#define COMP_POSTMASTER 12 +#define COMP_REPLICATION 13 +#define COMP_REWRITE 14 +#define COMP_STORAGE 15 +#define COMP_TCOP 16 +#define COMP_TSEARCH 17 +#define COMP_UTILS 18 +#define COMP_WLM 19 +#define COMP_SYSTEM 20 +#define COMP_MAX 21 + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/executer_gstrace.h postgresql-hll-2.14/include/include/gstrace/executer_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/executer_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/executer_gstrace.h 2020-12-12 17:06:43.199347419 +0800 @@ -0,0 +1,89 @@ +// This is a generated file + +#ifndef _EXECUTER_GSTRACE_H +#define _EXECUTER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_execTuplesMatch GS_TRC_ID_PACK(COMP_EXECUTER, 1) +#define GS_TRC_ID_execTuplesUnequal GS_TRC_ID_PACK(COMP_EXECUTER, 2) +#define GS_TRC_ID_execTuplesMatchPrepare GS_TRC_ID_PACK(COMP_EXECUTER, 3) +#define GS_TRC_ID_execTuplesHashPrepare GS_TRC_ID_PACK(COMP_EXECUTER, 4) +#define GS_TRC_ID_BuildTupleHashTable GS_TRC_ID_PACK(COMP_EXECUTER, 5) +#define GS_TRC_ID_LookupTupleHashEntry GS_TRC_ID_PACK(COMP_EXECUTER, 6) +#define GS_TRC_ID_FindTupleHashEntry GS_TRC_ID_PACK(COMP_EXECUTER, 7) +#define GS_TRC_ID_ExecInitJunkFilter GS_TRC_ID_PACK(COMP_EXECUTER, 8) +#define GS_TRC_ID_ExecInitJunkFilterConversion GS_TRC_ID_PACK(COMP_EXECUTER, 9) +#define GS_TRC_ID_ExecFindJunkAttribute GS_TRC_ID_PACK(COMP_EXECUTER, 10) +#define GS_TRC_ID_ExecFindJunkAttributeInTlist GS_TRC_ID_PACK(COMP_EXECUTER, 11) +#define GS_TRC_ID_ExecGetJunkAttribute GS_TRC_ID_PACK(COMP_EXECUTER, 12) +#define GS_TRC_ID_ExecFilterJunk GS_TRC_ID_PACK(COMP_EXECUTER, 13) +#define GS_TRC_ID_ExecSetjunkFilteDescriptor GS_TRC_ID_PACK(COMP_EXECUTER, 14) +#define GS_TRC_ID_ExecFindJunkPrimaryKeys GS_TRC_ID_PACK(COMP_EXECUTER, 15) +#define GS_TRC_ID_BatchExecFilterJunk GS_TRC_ID_PACK(COMP_EXECUTER, 16) +#define GS_TRC_ID_BatchCheckNodeIdentifier GS_TRC_ID_PACK(COMP_EXECUTER, 17) +#define GS_TRC_ID_ExecGetPlanNodeid GS_TRC_ID_PACK(COMP_EXECUTER, 18) +#define GS_TRC_ID_ExecutorStart GS_TRC_ID_PACK(COMP_EXECUTER, 19) +#define GS_TRC_ID_standard_ExecutorStart GS_TRC_ID_PACK(COMP_EXECUTER, 20) +#define GS_TRC_ID_ExecutorRun GS_TRC_ID_PACK(COMP_EXECUTER, 21) +#define GS_TRC_ID_standard_ExecutorRun GS_TRC_ID_PACK(COMP_EXECUTER, 22) +#define GS_TRC_ID_ExecutorFinish GS_TRC_ID_PACK(COMP_EXECUTER, 23) +#define GS_TRC_ID_standard_ExecutorFinish GS_TRC_ID_PACK(COMP_EXECUTER, 24) +#define GS_TRC_ID_ExecutorEnd GS_TRC_ID_PACK(COMP_EXECUTER, 25) +#define GS_TRC_ID_standard_ExecutorEnd GS_TRC_ID_PACK(COMP_EXECUTER, 26) +#define GS_TRC_ID_ExecutorRewind GS_TRC_ID_PACK(COMP_EXECUTER, 27) +#define GS_TRC_ID_ExecCheckRTPerms GS_TRC_ID_PACK(COMP_EXECUTER, 28) +#define GS_TRC_ID_CheckValidResultRel GS_TRC_ID_PACK(COMP_EXECUTER, 29) +#define GS_TRC_ID_InitResultRelInfo GS_TRC_ID_PACK(COMP_EXECUTER, 30) +#define GS_TRC_ID_ExecGetTriggerResultRel GS_TRC_ID_PACK(COMP_EXECUTER, 31) +#define GS_TRC_ID_ExecContextForcesOids GS_TRC_ID_PACK(COMP_EXECUTER, 32) +#define GS_TRC_ID_ExecConstraints GS_TRC_ID_PACK(COMP_EXECUTER, 33) +#define GS_TRC_ID_ExecFindRowMark GS_TRC_ID_PACK(COMP_EXECUTER, 34) +#define GS_TRC_ID_ExecBuildAuxRowMark GS_TRC_ID_PACK(COMP_EXECUTER, 35) +#define GS_TRC_ID_EvalPlanQual GS_TRC_ID_PACK(COMP_EXECUTER, 36) +#define GS_TRC_ID_EvalPlanQualFetch GS_TRC_ID_PACK(COMP_EXECUTER, 37) +#define GS_TRC_ID_EvalPlanQualInit GS_TRC_ID_PACK(COMP_EXECUTER, 38) +#define GS_TRC_ID_EvalPlanQualSetPlan GS_TRC_ID_PACK(COMP_EXECUTER, 39) +#define GS_TRC_ID_EvalPlanQualSetTuple GS_TRC_ID_PACK(COMP_EXECUTER, 40) +#define GS_TRC_ID_EvalPlanQualGetTuple GS_TRC_ID_PACK(COMP_EXECUTER, 41) +#define GS_TRC_ID_EvalPlanQualFetchRowMarks GS_TRC_ID_PACK(COMP_EXECUTER, 42) +#define GS_TRC_ID_EvalPlanQualNext GS_TRC_ID_PACK(COMP_EXECUTER, 43) +#define GS_TRC_ID_EvalPlanQualBegin GS_TRC_ID_PACK(COMP_EXECUTER, 44) +#define GS_TRC_ID_EvalPlanQualEnd GS_TRC_ID_PACK(COMP_EXECUTER, 45) +#define GS_TRC_ID_ExecInitNode GS_TRC_ID_PACK(COMP_EXECUTER, 46) +#define GS_TRC_ID_ExecProcNode GS_TRC_ID_PACK(COMP_EXECUTER, 47) +#define GS_TRC_ID_MultiExecProcNode GS_TRC_ID_PACK(COMP_EXECUTER, 48) +#define GS_TRC_ID_ExecEndNode GS_TRC_ID_PACK(COMP_EXECUTER, 49) +#define GS_TRC_ID_ExecGetPlanMemCost GS_TRC_ID_PACK(COMP_EXECUTER, 50) +#define GS_TRC_ID_GetAttributeByNum GS_TRC_ID_PACK(COMP_EXECUTER, 51) +#define GS_TRC_ID_GetAttributeByName GS_TRC_ID_PACK(COMP_EXECUTER, 52) +#define GS_TRC_ID_ExecMakeTableFunctionResult GS_TRC_ID_PACK(COMP_EXECUTER, 53) +#define GS_TRC_ID_ExecEvalExprSwitchContext GS_TRC_ID_PACK(COMP_EXECUTER, 54) +#define GS_TRC_ID_ExecInitExpr GS_TRC_ID_PACK(COMP_EXECUTER, 55) +#define GS_TRC_ID_ExecPrepareExpr GS_TRC_ID_PACK(COMP_EXECUTER, 56) +#define GS_TRC_ID_ExecQual GS_TRC_ID_PACK(COMP_EXECUTER, 57) +#define GS_TRC_ID_ExecTargetListLength GS_TRC_ID_PACK(COMP_EXECUTER, 58) +#define GS_TRC_ID_ExecCleanTargetListLength GS_TRC_ID_PACK(COMP_EXECUTER, 59) +#define GS_TRC_ID_ExecProject GS_TRC_ID_PACK(COMP_EXECUTER, 60) +#define GS_TRC_ID_ExecScan GS_TRC_ID_PACK(COMP_EXECUTER, 61) +#define GS_TRC_ID_ExecAssignScanProjectionInfo GS_TRC_ID_PACK(COMP_EXECUTER, 62) +#define GS_TRC_ID_ExecScanReScan GS_TRC_ID_PACK(COMP_EXECUTER, 63) +#define GS_TRC_ID_ExecInitResultTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 64) +#define GS_TRC_ID_ExecInitScanTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 65) +#define GS_TRC_ID_ExecInitExtraTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 66) +#define GS_TRC_ID_ExecInitNullTupleSlot GS_TRC_ID_PACK(COMP_EXECUTER, 67) +#define GS_TRC_ID_ExecTypeFromTL GS_TRC_ID_PACK(COMP_EXECUTER, 68) +#define GS_TRC_ID_ExecCleanTypeFromTL GS_TRC_ID_PACK(COMP_EXECUTER, 69) +#define GS_TRC_ID_ExecTypeFromExprList GS_TRC_ID_PACK(COMP_EXECUTER, 70) +#define GS_TRC_ID_UpdateChangedParamSet GS_TRC_ID_PACK(COMP_EXECUTER, 71) +#define GS_TRC_ID_begin_tup_output_tupdesc GS_TRC_ID_PACK(COMP_EXECUTER, 72) +#define GS_TRC_ID_do_tup_output GS_TRC_ID_PACK(COMP_EXECUTER, 73) +#define GS_TRC_ID_do_text_output_multiline GS_TRC_ID_PACK(COMP_EXECUTER, 74) +#define GS_TRC_ID_end_tup_output GS_TRC_ID_PACK(COMP_EXECUTER, 75) +#define GS_TRC_ID_InitPlan GS_TRC_ID_PACK(COMP_EXECUTER, 76) +#define GS_TRC_ID_ExecCheckRTEPerms GS_TRC_ID_PACK(COMP_EXECUTER, 77) +#define GS_TRC_ID_ExecInitIndexScan GS_TRC_ID_PACK(COMP_EXECUTER, 78) +#define GS_TRC_ID_BypassExecutor GS_TRC_ID_PACK(COMP_EXECUTER, 79) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/funcs.comps.h postgresql-hll-2.14/include/include/gstrace/funcs.comps.h --- postgresql-hll-2.14_old/include/include/gstrace/funcs.comps.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/funcs.comps.h 2020-12-12 17:06:43.199347419 +0800 @@ -0,0 +1,921 @@ +// This is a generated file + +#include "comps.h" + +#ifndef _FUNCSCOMPS_H +#define _FUNCSCOMPS_H + +#define HASH_TRACE_CONFIG "588172a1f3a60b449ac8796c2361709035e6ddebcc8e9a2f2c7c43740096eafd" + +struct comp_func { + uint32_t comp; + uint32_t func_num; + const char **func_names; +}; + +struct comp_name { + uint32_t comp; + const char *compName; +}; + + +static const char* GS_TRC_COMMANDS_FUNC_NAMES[] = +{ + "", + "createdb", + "dropdb", + "RenameDatabase", + "AlterDatabase", + "AlterDatabaseSet", + "AlterDatabaseOwner", + "get_database_oid", + "get_database_name", + "dbase_redo", + "dbase_desc", + "check_encoding_locale_matches", + "IsSetTableSpace", + "errdetail_busy_db", + "PreCleanAndCheckConns", + "vacuum", + "vac_open_indexes", + "vac_close_indexes", + "vac_estimate_reltuples", + "vac_update_relstats", + "vacuum_set_xid_limits", + "vac_update_datfrozenxid", + "vacuum_delay_point", + "analyze_rel", + "buildTempSampleTable", + "dropSampleTable", + "DefineRelation", + "RemoveRelations", + "AlterTableLookupRelation", + "AlterTable", + "AlterTableGetLockLevel", + "ATExecChangeOwner", + "AlterTableInternal", + "AlterTableNamespace", + "AlterTableNamespaceInternal", + "AlterRelationNamespaceInternal", + "vacuum_rel", + "cluster_rel", + "lazy_scan_heap", + "lazy_vacuum_rel", + "lazy_vacuum_index", + "lazy_vacuum_heap", + "lazy_truncate_heap", + "lazy_cleanup_index" +}; + +static const char* GS_TRC_PARSER_FUNC_NAMES[] = +{ + "", + "make_parsestate", + "free_parsestate", + "parser_errposition", + "setup_parser_errposition_callback", + "cancel_parser_errposition_callback", + "make_var", + "transformArrayType", + "transformArraySubscripts", + "make_const", + "scanner_init", + "scanner_finish", + "core_yylex", + "scanner_errposition", + "scanner_yyerror" +}; + +static const char* GS_TRC_OPTIMIZER_FUNC_NAMES[] = +{ + "", + "clauselist_selectivity", + "clause_selectivity", + "set_rel_width", + "restore_hashjoin_cost", + "finalize_dml_cost", + "copy_mem_info", + "columnar_get_col_width", + "get_path_actual_total_width", + "query_planner", + "preprocess_minmax_aggregates", + "optimize_minmax_aggregates", + "set_plan_rows", + "create_plan", + "disuse_physical_tlist", + "copy_plan_costsize", + "make_subqueryscan", + "make_foreignscan", + "make_append", + "make_recursive_union", + "make_sort_from_pathkeys", + "make_sort_from_sortclauses", + "make_sort_from_groupcols", + "make_sort_from_targetlist", + "make_sort", + "make_agg", + "make_windowagg", + "make_group", + "materialize_finished_plan", + "make_unique", + "make_lockrows", + "make_limit", + "make_stream_limit", + "compare_path_costs", + "compare_fractional_path_costs", + "set_cheapest", + "get_cheapest_path", + "find_hinted_path", + "add_path", + "add_path_precheck", + "create_seqscan_path", + "create_cstorescan_path", + "create_index_path", + "build_seqScanPath_by_indexScanPath", + "check_bitmap_heap_path_index_unusable", + "is_partitionIndex_Subpath", + "is_pwj_path", + "create_bitmap_heap_path" +}; + +static const char* GS_TRC_REWRITE_FUNC_NAMES[] = +{ + "", + "OffsetVarNodes", + "ChangeVarNodes", + "IncrementVarSublevelsUp", + "IncrementVarSublevelsUp_rtable", + "rangeTableEntry_used", + "attribute_used", + "getInsertSelectQuery", + "AddQual", + "AddInvertedQual", + "contain_aggs_of_level", + "checkExprHasAggs", + "checkExprHasWindowFuncs", + "checkExprHasSubLink" +}; + +static const char* GS_TRC_LIBPQ_FUNC_NAMES[] = +{ + "", + "StreamServerPort", + "StreamConnection", + "StreamClose", + "TouchSocketFile", + "pq_init", + "pq_comm_reset", + "pq_getbytes", + "pq_getstring", + "pq_getmessage", + "pq_getbyte", + "pq_peekbyte", + "pq_getbyte_if_available", + "pq_putbytes", + "pq_flush", + "pq_flush_if_writable", + "pq_flush_timedwait", + "pq_is_send_pending", + "pq_putmessage", + "pq_putmessage_noblock", + "pq_startcopyout", + "pq_endcopyout", + "pq_select" +}; + +static const char* GS_TRC_UTILS_FUNC_NAMES[] = +{ + "", + "has_any_column_privilege_name_name", + "has_any_column_privilege_name_id", + "has_any_column_privilege_id_name", + "has_any_column_privilege_id_id", + "has_any_column_privilege_name", + "has_any_column_privilege_id", + "has_column_privilege_name_name_name", + "has_column_privilege_name_name_attnum", + "has_column_privilege_name_id_name", + "has_column_privilege_name_id_attnum", + "has_column_privilege_id_name_name", + "has_column_privilege_id_name_attnum", + "has_column_privilege_id_id_name", + "has_column_privilege_id_id_attnum", + "has_column_privilege_name_name", + "has_column_privilege_name_attnum", + "has_column_privilege_id_name", + "has_column_privilege_id_attnum", + "has_table_privilege_name_name", + "has_table_privilege_name_id", + "has_table_privilege_id_name", + "has_table_privilege_id_id", + "has_table_privilege_name", + "has_table_privilege_id", + "has_sequence_privilege_name_name", + "has_sequence_privilege_name_id", + "has_sequence_privilege_id_name", + "has_sequence_privilege_id_id", + "has_sequence_privilege_name", + "has_sequence_privilege_id", + "has_database_privilege_name_name", + "has_database_privilege_name_id", + "has_database_privilege_id_name", + "has_database_privilege_id_id", + "has_database_privilege_name", + "has_database_privilege_id", + "has_foreign_data_wrapper_privilege_name_name", + "has_foreign_data_wrapper_privilege_name_id", + "has_foreign_data_wrapper_privilege_id_name", + "has_foreign_data_wrapper_privilege_id_id", + "has_foreign_data_wrapper_privilege_name", + "has_foreign_data_wrapper_privilege_id", + "has_function_privilege_name_name", + "has_function_privilege_name_id", + "has_function_privilege_id_name", + "has_function_privilege_id_id", + "has_function_privilege_name", + "has_function_privilege_id", + "has_language_privilege_name_name", + "has_language_privilege_name_id", + "has_language_privilege_id_name", + "has_language_privilege_id_id", + "has_language_privilege_name", + "has_language_privilege_id", + "has_nodegroup_privilege_name_name", + "has_nodegroup_privilege_name_id", + "has_nodegroup_privilege_id_name", + "has_nodegroup_privilege_id_id", + "has_nodegroup_privilege_name", + "has_nodegroup_privilege_id", + "has_schema_privilege_name_name", + "has_schema_privilege_name_id", + "has_schema_privilege_id_name", + "has_schema_privilege_id_id", + "has_schema_privilege_name", + "has_schema_privilege_id", + "has_server_privilege_name_name", + "has_server_privilege_name_id", + "has_server_privilege_id_name", + "has_server_privilege_id_id", + "has_server_privilege_name", + "has_server_privilege_id", + "has_tablespace_privilege_name_name", + "has_tablespace_privilege_name_id", + "has_tablespace_privilege_id_name", + "has_tablespace_privilege_id_id", + "has_tablespace_privilege_name", + "has_tablespace_privilege_id", + "has_type_privilege_name_name", + "has_type_privilege_name_id", + "has_type_privilege_id_name", + "has_type_privilege_id_id", + "has_type_privilege_name", + "has_type_privilege_id", + "pg_has_role_name_name", + "pg_has_role_name_id", + "pg_has_role_id_name", + "pg_has_role_id_id", + "pg_has_role_name", + "pg_has_role_id", + "GetConfigOption", + "GetConfigOptionResetString", + "ProcessConfigFile", + "InitializeGUCOptions", + "init_sync_guc_variables", + "repair_guc_variables", + "SelectConfigFiles", + "ResetAllOptions", + "AtStart_GUC", + "NewGUCNestLevel", + "AtEOXact_GUC", + "BeginReportingGUCOptions", + "ParseLongOption", + "set_config_option", + "GetConfigOptionByName", + "GetConfigOptionByNum", + "GetNumConfigOptions", + "SetPGVariable", + "GetPGVariable", + "GetPGVariableResultDesc", + "RewriteBeginQuery", + "ExecSetVariableStmt", + "ExtractSetVariableArgs", + "RelationIdGetRelation", + "RelationClose", + "PartitionGetPartIndexList", + "RelationGetIndexList", + "RelationGetIndexNum", + "RelationGetOidIndex", + "RelationGetIndexExpressions", + "RelationGetIndexPredicate", + "RelationGetIndexAttrBitmap", + "RelationGetExclusionInfo" +}; + +static const char* GS_TRC_BOOTSTRAP_FUNC_NAMES[] = +{ + "", + "AuxiliaryProcessMain", + "err_out", + "closerel", + "boot_openrel", + "DefineAttr", + "InsertOneTuple", + "InsertOneValue", + "InsertOneNull", + "MapArrayTypeName", + "index_register", + "build_indices", + "boot_get_type_io_data", + "boot_yyparse", + "boot_yylex", + "boot_yyerror" +}; + +static const char* GS_TRC_STORAGE_FUNC_NAMES[] = +{ + "", + "InitBufferPool", + "InitBufferPoolAccess", + "InitBufferPoolBackend", + "AtEOXact_Buffers", + "PrintBufferLeakWarning", + "CheckPointBuffers", + "RelationGetNumberOfBlocksInFork", + "FlushRelationBuffers", + "FlushDatabaseBuffers", + "DropRelFileNodeBuffers", + "DropRelFileNodeAllBuffers", + "DropDatabaseBuffers", + "ProcArrayShmemSize", + "ProcArrayAdd", + "ProcArrayRemove", + "ProcArrayEndTransaction", + "ProcArrayClearTransaction", + "SetGlobalSnapshotData", + "UnsetGlobalSnapshotData", + "ReloadConnInfoOnBackends", + "DumpMemoryCtxOnBackend", + "ProcArrayInitRecovery", + "ProcArrayApplyRecoveryInfo", + "ProcArrayApplyXidAssignment", + "RecordKnownAssignedTransactionIds", + "ExpireTreeKnownAssignedTransactionIds", + "ExpireAllKnownAssignedTransactionIds", + "ExpireOldKnownAssignedTransactionIds", + "GetMaxSnapshotXidCount", + "GetMaxSnapshotSubxidCount", + "smgrinit", + "smgropen", + "smgrexists", + "smgrsetowner", + "smgrclearowner", + "smgrclose", + "smgrcloseall", + "smgrclosenode", + "smgrcreate", + "smgrdounlink", + "smgrdounlinkfork", + "smgrextend", + "smgrprefetch", + "smgrread", + "smgrwrite", + "smgrwriteback", + "smgrnblocks", + "smgrtruncate", + "smgrimmedsync", + "smgrpreckpt", + "smgrsync", + "smgrpostckpt", + "AtEOXact_SMgr", + "BufferAlloc", + "SyncLocalXidWait", + "BufferSync", + "BgBufferSync", + "fsm_vacuum_page", + "fsm_search", + "fsm_set_and_search" +}; + +static const char* GS_TRC_POSTMASTER_FUNC_NAMES[] = +{ + "", + "PostmasterMain", + "ClosePostmasterPorts", + "MaxLivePostmasterChildren", + "HaShmemSize", + "HaShmemInit", + "postmaster_forkexec", + "stream_forkexec", + "WLMProcessForkExec", + "SubPostmasterMain", + "ShmemBackendArraySize", + "ShmemBackendArrayAllocation", + "SysLogger_Start", + "SysLoggerClose", + "write_syslogger_file", + "AioCompltrMain", + "AioCompltrStop", + "AioCompltrStart", + "AioCompltrIsReady", + "CompltrContext", + "CompltrPriority", + "AutoVacuumingActive", + "IsAutoVacuumLauncherProcess", + "IsAutoVacuumWorkerProcess", + "autovac_init", + "StartAutoVacLauncher", + "StartAutoVacWorker", + "AutoVacWorkerFailed", + "AutoVacuumUpdateDelay", + "AutoVacLauncherMain", + "AutoVacWorkerMain", + "AutovacuumWorkerIAm", + "AutovacuumLauncherIAm", + "HandleStartupProcInterrupts", + "StartupProcessMain", + "PreRestoreCommand", + "PostRestoreCommand", + "IsFailoverTriggered", + "IsSwitchoverTriggered", + "IsPrimaryTriggered", + "ResetSwitchoverTriggered", + "ResetFailoverTriggered", + "ResetPrimaryTriggered", + "NotifySignalShmemSize", + "NotifySignalShmemInit", + "SendNotifySignal", + "CheckNotifySignal", + "BackgroundWriterMain", + "CheckpointerMain", + "RequestCheckpoint", + "CheckpointWriteDelay", + "ForwardFsyncRequest", + "AbsorbFsyncRequests", + "CheckpointerShmemSize", + "CheckpointerShmemInit", + "FirstCallSinceLastCheckpoint", + "IsBgwriterProcess", + "isDirExist", + "startAlarmChecker", + "AlarmCheckerMain", + "fork_process", + "WalWriterMain", + "ckpt_try_prune_dirty_page_queue" +}; + +static const char* GS_TRC_SYSTEM_FUNC_NAMES[] = +{ + "", + "TRY_CATCH" +}; + +static const char* GS_TRC_ACCESS_FUNC_NAMES[] = +{ + "", + "heap_compute_data_size", + "heap_fill_tuple", + "heap_attisnull", + "nocache_cmprs_get_attr", + "nocachegetattr", + "heap_getsysattr", + "heap_copytuple", + "heapCopyCompressedTuple", + "heapCopyTuple", + "heap_copytuple_with_tuple", + "heap_form_tuple", + "heap_form_cmprs_tuple", + "heap_modify_tuple", + "heap_deform_cmprs_tuple", + "heap_deform_tuple", + "heap_deform_tuple2", + "heap_deform_tuple3", + "heap_formtuple", + "heap_modifytuple", + "heap_deformtuple", + "heap_freetuple", + "heap_form_minimal_tuple", + "heap_free_minimal_tuple", + "heap_copy_minimal_tuple", + "heap_tuple_from_minimal_tuple", + "minimal_tuple_from_heap_tuple", + "heapGetInitDefVal", + "relationAttIsNull", + "heapFormMinimalTuple", + "XLogInsertRecord", + "XLogFlush", + "XLogBackgroundFlush", + "XLogNeedsFlush", + "XLogFileInit", + "XLogFileOpen", + "CheckXLogRemoved", + "XLogSetAsyncXactLSN", + "XLogSetReplicationSlotMinimumLSN", + "XLogSetReplicationSlotMaximumLSN", + "XLogGetReplicationSlotMaximumLSN", + "xlog_redo", + "xlog_desc", + "issue_xlog_fsync", + "RecoveryInProgress", + "HotStandbyActive", + "HotStandbyActiveInReplay", + "XLogInsertAllowed", + "GetXLogReceiptTime", + "GetXLogReplayRecPtr", + "GetXLogReplayRecPtrInPending", + "GetStandbyFlushRecPtr", + "GetXLogInsertRecPtr", + "GetXLogWriteRecPtr", + "RecoveryIsPaused", + "SetRecoveryPause", + "GetLatestXTime", + "GetCurrentChunkReplayStartTime", + "GetXlogRecordCrc", + "UpdateControlFile", + "GetSystemIdentifier", + "SetSystemIdentifier", + "GetThisTimeID", + "SetThisTimeID", + "XLOGShmemSize", + "XLOGShmemInit", + "BootStrapXLOG", + "StartupXLOG", + "ShutdownXLOG", + "InitXLOGAccess", + "StartupDummyStandby", + "CreateCheckPoint", + "CreateRestartPoint", + "CheckPointGuts", + "XLogPutNextOid", + "XLogRestorePoint", + "UpdateFullPageWrites", + "GetFullPageWriteInfo", + "GetRedoRecPtr", + "GetInsertRecPtr", + "GetFlushRecPtr", + "GetNextXidAndEpoch", + "GetRecoveryTargetTLI", + "DummyStandbySetRecoveryTargetTLI", + "CheckPromoteSignal", + "CheckPrimarySignal", + "CheckStandbySignal", + "CheckSwitchoverSignal", + "ReadLsnXlogFlushChkFile", + "WakeupRecovery", + "WakeupDataRecovery", + "SetWalWriterSleeping", + "CheckFpwBeforeFirstCkpt", + "DisableFpwBeforeFirstCkpt", + "UpdateLsnXlogFlushChkFile", + "LsnXlogFlushChkShmemSize", + "LsnXlogFlushChkShmInit", + "IfLsnXlogFlushChkFileExist", + "heap_xlog_logical_new_page", + "StartTransaction", + "KeepLogSeg", + "RemoveOldXlogFiles", + "dw_truncate", + "heap_change_xidbase_after_freeze", + "heap_page_prepare_for_xid", + "ExtendCSNLOG", + "freeze_single_heap_page", + "heap_page_prune", + "heap_prune_chain", + "PreallocXlogFiles", + "do_pg_stop_backup", + "do_pg_start_backup" +}; + +static const char* GS_TRC_REPLICATION_FUNC_NAMES[] = +{ + "", + "WalReceiverMain", + "walrcvWriterMain", + "WalRcvShmemSize", + "WalRcvShmemInit", + "ShutdownWalRcv", + "WalRcvInProgress", + "connect_dn_str", + "RequestXLogStreaming", + "get_rcv_slot_name", + "GetWalRcvWriteRecPtr", + "GetReplicationApplyDelay", + "GetReplicationTransferLatency", + "GetWalRcvDummyStandbySyncPercent", + "SetWalRcvDummyStandbySyncPercent", + "getCurrentWalRcvCtlBlock", + "walRcvWrite", + "WalRcvXLogClose", + "WalRcvIsShutdown", + "ProcessRmXLog", + "SetWalRcvWriterPID", + "WalRcvWriterInProgress", + "walRcvCtlBlockIsEmpty", + "GetRepConnArray", + "get_sync_percent", + "wal_get_role_string", + "pg_stat_get_stream_replications", + "DataReceiverMain", + "DataRcvShmemSize", + "DataRcvShmemInit", + "DataRcvInProgress", + "ShutdownDataRcv", + "StartupDataStreaming", + "RequestDataStreaming", + "InitDummyDataNum", + "WakeupDataRcvWriter", + "DataRcvWriterInProgress", + "DataRcvDataCleanup", + "DataRcvWriterMain", + "DataRcvWrite", + "SetDataRcvDummyStandbySyncPercent", + "GetDataRcvDummyStandbySyncPercent", + "SetDataRcvWriterPID", + "ProcessDataRcvInterrupts", + "CloseDataFile", + "WalSenderMain", + "WalSndSignals", + "WalSndShmemSize", + "WalSndShmemInit", + "WalSndWakeup", + "WalSndRqstFileReload", + "WalSndInProgress", + "StandbyOrSecondaryIsAlive" +}; + +static const char* GS_TRC_CATALOG_FUNC_NAMES[] = +{ + "", + "forkname_to_number", + "forkname_chars", + "relpathbackend", + "GetDatabasePath", + "relpath_to_filenode", + "IsSystemRelation", + "IsToastRelation", + "IsSystemClass", + "IsToastClass", + "IsSystemNamespace", + "IsToastNamespace", + "IsCStoreNamespace", + "IsReservedName", + "IsSharedRelation", + "GetNewOid", + "GetNewOidWithIndex", + "GetNewRelFileNode", + "heap_truncate", + "heap_truncate_one_rel", + "heap_truncate_check_FKs", + "heap_truncate_find_FKs", + "InsertPgAttributeTuple", + "InsertPgClassTuple", + "AddRelationNewConstraints", + "AddRelClusterConstraints", + "StoreAttrDefault", + "cookDefault", + "DeleteRelationTuple", + "DeleteAttributeTuples", + "DeleteSystemAttributeTuples", + "RemoveAttributeById", + "RemoveAttrDefault", + "RemoveAttrDefaultById", + "RemoveStatistics", + "SystemAttributeDefinition", + "SystemAttributeByName", + "CheckAttributeNamesTypes", + "CheckAttributeType", + "AddRelationDistribution", + "GetRelationDistributionItems", + "GetRelationDistributionNodes", + "BuildRelationDistributionNodes", + "SortRelationDistributionNodes", + "SetRelHasClusterKey" +}; + +static const char* GS_TRC_PG_CTL_FUNC_NAMES[] = +{ + "", + "ReceiveXlogStream", + "get_replconn_number", + "ParseReplConnInfo" +}; + +static const char* GS_TRC_COMMON_FUNC_NAMES[] = +{ + "", + "charshow_estimated_time", + "charshow_datasize", + "UpdateDBStateFile" +}; + +static const char* GS_TRC_TSEARCH_FUNC_NAMES[] = +{ + "", + "init_tsvector_parser", + "reset_tsvector_parser", + "gettoken_tsvector", + "close_tsvector_parser" +}; + +static const char* GS_TRC_TCOP_FUNC_NAMES[] = +{ + "", + "BeginCommand", + "CreateDestReceiver", + "CreateReceiverForMerge", + "EndCommand", + "EndCommand_noblock", + "ProcessUtility", + "standard_ProcessUtility", + "UtilityReturnsTuples", + "UtilityTupleDescriptor", + "UtilityContainsQuery", + "CreateCommandTag", + "GetCommandLogLevel", + "CommandIsReadOnly", + "CheckRelationOwnership", + "pg_parse_query", + "pg_analyze_and_rewrite", + "pg_analyze_and_rewrite_params", + "pg_plan_query", + "pg_plan_queries", + "check_max_stack_depth", + "assign_max_stack_depth", + "die", + "quickdie", + "StatementCancelHandler", + "FloatExceptionHandler", + "RecoveryConflictInterrupt", + "prepare_for_client_read", + "client_read_ended", + "prepare_for_logic_conn_read", + "logic_conn_read_check_ended", + "process_postgres_switches", + "PostgresMain", + "StreamMain", + "get_stack_depth_rlimit", + "ResetUsage", + "ShowUsage", + "check_log_duration", + "set_debug_options", + "set_plan_disabling_options", + "get_stats_option_name", + "exec_parse_message", + "exec_bind_message", + "exec_execute_message", + "PortalStart", + "PortalRun" +}; + +static const char* GS_TRC_VECEXECUTOR_FUNC_NAMES[] = +{ + "", + "VectorEngine", + "ExecVecProject", + "ExecInitVecExpr", + "ExecAssignVecScanProjectionInfo", + "ExecVecMarkPos", + "ExecVecRestrPos", + "VecExecReScan" +}; + +static const char* GS_TRC_WLM_FUNC_NAMES[] = +{ + "", + "WLMIsSimpleQuery" +}; + +static const char* GS_TRC_EXECUTER_FUNC_NAMES[] = +{ + "", + "execTuplesMatch", + "execTuplesUnequal", + "execTuplesMatchPrepare", + "execTuplesHashPrepare", + "BuildTupleHashTable", + "LookupTupleHashEntry", + "FindTupleHashEntry", + "ExecInitJunkFilter", + "ExecInitJunkFilterConversion", + "ExecFindJunkAttribute", + "ExecFindJunkAttributeInTlist", + "ExecGetJunkAttribute", + "ExecFilterJunk", + "ExecSetjunkFilteDescriptor", + "ExecFindJunkPrimaryKeys", + "BatchExecFilterJunk", + "BatchCheckNodeIdentifier", + "ExecGetPlanNodeid", + "ExecutorStart", + "standard_ExecutorStart", + "ExecutorRun", + "standard_ExecutorRun", + "ExecutorFinish", + "standard_ExecutorFinish", + "ExecutorEnd", + "standard_ExecutorEnd", + "ExecutorRewind", + "ExecCheckRTPerms", + "CheckValidResultRel", + "InitResultRelInfo", + "ExecGetTriggerResultRel", + "ExecContextForcesOids", + "ExecConstraints", + "ExecFindRowMark", + "ExecBuildAuxRowMark", + "EvalPlanQual", + "EvalPlanQualFetch", + "EvalPlanQualInit", + "EvalPlanQualSetPlan", + "EvalPlanQualSetTuple", + "EvalPlanQualGetTuple", + "EvalPlanQualFetchRowMarks", + "EvalPlanQualNext", + "EvalPlanQualBegin", + "EvalPlanQualEnd", + "ExecInitNode", + "ExecProcNode", + "MultiExecProcNode", + "ExecEndNode", + "ExecGetPlanMemCost", + "GetAttributeByNum", + "GetAttributeByName", + "ExecMakeTableFunctionResult", + "ExecEvalExprSwitchContext", + "ExecInitExpr", + "ExecPrepareExpr", + "ExecQual", + "ExecTargetListLength", + "ExecCleanTargetListLength", + "ExecProject", + "ExecScan", + "ExecAssignScanProjectionInfo", + "ExecScanReScan", + "ExecInitResultTupleSlot", + "ExecInitScanTupleSlot", + "ExecInitExtraTupleSlot", + "ExecInitNullTupleSlot", + "ExecTypeFromTL", + "ExecCleanTypeFromTL", + "ExecTypeFromExprList", + "UpdateChangedParamSet", + "begin_tup_output_tupdesc", + "do_tup_output", + "do_text_output_multiline", + "end_tup_output", + "InitPlan", + "ExecCheckRTEPerms", + "ExecInitIndexScan", + "BypassExecutor" +}; + +static struct comp_func GS_TRC_FUNC_NAMES_BY_COMP[] = +{ + {0, 0, NULL}, + {COMP_COMMON, 4, GS_TRC_COMMON_FUNC_NAMES}, + {COMP_LIBPQ, 23, GS_TRC_LIBPQ_FUNC_NAMES}, + {COMP_PG_CTL, 4, GS_TRC_PG_CTL_FUNC_NAMES}, + {COMP_ACCESS, 112, GS_TRC_ACCESS_FUNC_NAMES}, + {COMP_BOOTSTRAP, 16, GS_TRC_BOOTSTRAP_FUNC_NAMES}, + {COMP_CATALOG, 45, GS_TRC_CATALOG_FUNC_NAMES}, + {COMP_PARSER, 15, GS_TRC_PARSER_FUNC_NAMES}, + {COMP_COMMANDS, 44, GS_TRC_COMMANDS_FUNC_NAMES}, + {COMP_EXECUTER, 80, GS_TRC_EXECUTER_FUNC_NAMES}, + {COMP_VECEXECUTOR, 8, GS_TRC_VECEXECUTOR_FUNC_NAMES}, + {COMP_OPTIMIZER, 48, GS_TRC_OPTIMIZER_FUNC_NAMES}, + {COMP_POSTMASTER, 63, GS_TRC_POSTMASTER_FUNC_NAMES}, + {COMP_REPLICATION, 53, GS_TRC_REPLICATION_FUNC_NAMES}, + {COMP_REWRITE, 14, GS_TRC_REWRITE_FUNC_NAMES}, + {COMP_STORAGE, 61, GS_TRC_STORAGE_FUNC_NAMES}, + {COMP_TCOP, 46, GS_TRC_TCOP_FUNC_NAMES}, + {COMP_TSEARCH, 5, GS_TRC_TSEARCH_FUNC_NAMES}, + {COMP_UTILS, 124, GS_TRC_UTILS_FUNC_NAMES}, + {COMP_WLM, 2, GS_TRC_WLM_FUNC_NAMES}, + {COMP_SYSTEM, 2, GS_TRC_SYSTEM_FUNC_NAMES} +}; + +static struct comp_name GS_TRC_COMP_NAMES_BY_COMP[] = +{ + {0, NULL}, + {COMP_COMMON, "common"}, + {COMP_LIBPQ, "libpq"}, + {COMP_PG_CTL, "pg_ctl"}, + {COMP_ACCESS, "access"}, + {COMP_BOOTSTRAP, "bootstrap"}, + {COMP_CATALOG, "catalog"}, + {COMP_PARSER, "parser"}, + {COMP_COMMANDS, "commands"}, + {COMP_EXECUTER, "executer"}, + {COMP_VECEXECUTOR, "vecexecutor"}, + {COMP_OPTIMIZER, "optimizer"}, + {COMP_POSTMASTER, "postmaster"}, + {COMP_REPLICATION, "replication"}, + {COMP_REWRITE, "rewrite"}, + {COMP_STORAGE, "storage"}, + {COMP_TCOP, "tcop"}, + {COMP_TSEARCH, "tsearch"}, + {COMP_UTILS, "utils"}, + {COMP_WLM, "wlm"}, + {COMP_SYSTEM, "system"} +}; + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/gstrace_infra.h postgresql-hll-2.14/include/include/gstrace/gstrace_infra.h --- postgresql-hll-2.14_old/include/include/gstrace/gstrace_infra.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/gstrace_infra.h 2020-12-12 17:06:43.199347419 +0800 @@ -0,0 +1,70 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_infra.h + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_infra.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TRACE_INFRA_H_ +#define TRACE_INFRA_H_ + +/* use low 16 bits for function name */ +#define GS_TRC_COMP_SHIFT 16 +#define GS_TRC_FUNC_SHIFT 0 +#define GS_TRC_ID_PACK(comp, func) (func | (comp) << GS_TRC_COMP_SHIFT) + +/* used for gstrace_data() to inform tool how to decode its probe data. */ +typedef enum trace_data_fmt { + TRC_DATA_FMT_NONE, /* no data in this trace record */ + TRC_DATA_FMT_DFLT, /* data is stored with HEX format */ + TRC_DATA_FMT_UINT32 /* data is stored as uint32 */ +} trace_data_fmt; + +#ifdef ENABLE_GSTRACE + +/* Initialize context during startup process. */ +extern int gstrace_init(int key); +extern void gstrace_destory(int code, uintptr_t arg); + +/* write one ENTRY trace record */ +extern void gstrace_entry(const uint32_t rec_id); + +/* write one EXIT trace record */ +extern void gstrace_exit(const uint32_t rec_id); + +/* write on DATA trace record. If data_len is greater than 1920, no data is traced. */ +extern void gstrace_data( + const uint32_t probe, const uint32_t rec_id, const trace_data_fmt fmt_type, const char* pData, size_t data_len); + +extern int* gstrace_tryblock_entry(int* newTryCounter); +extern void gstrace_tryblock_exit(bool inCatch, int* oldTryCounter); + +#else + +#define gstrace_init(key) (1) +#define gstrace_destory (NULL) +#define gstrace_entry(rec_id) +#define gstrace_exit(rec_id) +#define gstrace_data(probe, rec_id, fmt_type, pData, data_len) +#define gstrace_tryblock_entry(curTryCounter) (curTryCounter) +#define gstrace_tryblock_exit(inCatch, oldTryCounter) + +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gstrace/gstrace_infra_int.h postgresql-hll-2.14/include/include/gstrace/gstrace_infra_int.h --- postgresql-hll-2.14_old/include/include/gstrace/gstrace_infra_int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/gstrace_infra_int.h 2020-12-12 17:06:43.199347419 +0800 @@ -0,0 +1,263 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_infra_int.h + * + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_infra_int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TRACE_INFRA_INT_H_ +#define TRACE_INFRA_INT_H_ + +#include +#include "gstrace/gstrace_infra.h" +#include "gstrace/system_gstrace.h" +// ----------------------------------------------------------------------------- +// Global #defines +// ----------------------------------------------------------------------------- +#define SLOT_SIZE 64 +#define MAX_TRC_RC_SZ 2048 // 2^11 +#define MAX_TRC_SLOTS (MAX_TRC_RC_SZ / SLOT_SIZE) +#define MAX_PATH_LEN 1024 +#define LENGTH_TRACE_CONFIG_HASH (64) + +#define TRACE_VERSION (0x1) +#define SLOT_AREAD_HEADER_MAGIC_NO 0xBCD7BCD7 +#define GS_TRC_CFG_MAGIC_N 0xABCDABCE + +#define MIN_BUF_SIZE 128 // The buffer size when it's tracing to file +#define DFT_BUF_SIZE 1073741824 // Default trace buffer size. 1GB. must be a power of 2 + +#define CACHE_LINE_SIZE 64 + +#define USECS_PER_SEC ((uint64_t)(1000000)) + +/* some mask related functions */ +#define GS_TRC_COMP_MASK 0x0FF0000 +#define GS_TRC_FUNC_MASK 0x000FFFF +#define GS_TRC_NUM_BITS 8 +#define GS_TRC_COMP_MAX 256 +#define GS_TRC_COMP_MASK_SZ (GS_TRC_COMP_MAX / GS_TRC_NUM_BITS) // 32 +#define GS_TRC_FUNC_MAX 65536 +#define GS_TRC_FUNC_MASK_SZ (GS_TRC_FUNC_MAX / GS_TRC_NUM_BITS) // 8192 + +#define TRACE_COMMON_ERROR (-1) + +typedef enum trace_msg_code { + TRACE_OK, + TRACE_ALREADY_START, + TRACE_ALREADY_STOP, + TRACE_PARAMETER_ERR, + TRACE_BUFFER_SIZE_ERR, + TRACE_ATTACH_CFG_SHARE_MEMORY_ERR, + TRACE_ATTACH_BUFFER_SHARE_MEMORY_ERR, + TRACE_OPEN_SHARE_MEMORY_ERR, + TRACE_TRUNCATE_ERR, + TRACE_MMAP_ERR, + TRACE_MUNMAP_ERR, + TRACE_UNLINK_SHARE_MEMORY_ERR, + TRACE_DISABLE_ERR, + TRACE_OPEN_OUTPUT_FILE_ERR, + TRACE_OPEN_INPUT_FILE_ERR, + TRACE_WRITE_BUFFER_HEADER_ERR, + TRACE_WRITE_CFG_HEADER_ERR, + TRACE_WRITE_BUFFER_ERR, + TRACE_READ_CFG_FROM_FILE_ERR, + TRACE_BUFFER_SIZE_FROM_FILE_ERR, + TRACE_MAGIC_FROM_FILE_ERR, + TRACE_READ_INFRA_FROM_FILE_ERR, + TRACE_NO_RECORDS_ERR, + TRACE_READ_SLOT_HEADER_ERR, + TRACE_NUM_SLOT_ERR, + TRACE_SLOT_MAGIC_ERR, + TRACE_READ_SLOT_DATA_ERR, + TRACE_WRITE_FORMATTED_RECORD_ERR, + TRACE_STATR_SLOT_ERR, + TRACE_TAIL_OFFSET_ERR, + TRACE_SEQ_ERR, + TRACE_VERSION_ERR, + TRACE_CONFIG_SIZE_ERR, + TRACE_MSG_MAX, +} trace_msg_code; + +typedef struct trace_msg { + trace_msg_code msg_code; + const char* msg_string; +} trace_msg_t; + + +#define securec_check(errno, charList, ...) \ + do { \ + if (errno != EOK) { \ + freeSecurityFuncSpace_c(charList, ##__VA_ARGS__); \ + printf("ERROR at %s : %d : The destination buffer or format is " \ + "a NULL pointer or the invalid parameter handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) + +/* White list for trace Id */ +typedef struct trace_mask { + /* while component's traceId is active */ + uint8_t comp_bitmap[GS_TRC_COMP_MASK_SZ]; + + /* while function's traceId is active */ + uint8_t func_bitmap[GS_TRC_FUNC_MASK_SZ]; +} trace_mask; + +typedef enum trace_status { + TRACE_STATUS_END_STOP = 0, + TRACE_STATUS_RECORDING, + TRACE_STATUS_PREPARE_STOP, + TRACE_STATUS_BEGIN_STOP +} trace_status; + +typedef enum trace_type { TRACE_ENTRY, TRACE_EXIT, TRACE_DATA } trace_type; + +/* + * Trace Buffer Header + * The writable buffer will start right after this struct. + */ +typedef struct trace_infra { + /* the number of trace records since startup */ + volatile uint64_t g_Counter; + + /* the number of used slots since startup */ + volatile uint64_t g_slot_count; + + /* ensure the previous one field in an sepreate cacheline */ + char pad[CACHE_LINE_SIZE - sizeof(uint64_t)]; + + /* buffer size + size of this struct */ + uint64_t total_size; + + /* the number of trace slots in writable region */ + uint64_t num_slots; + + /* Used to calculate slot index in an efficient manner */ + uint64_t slot_index_mask; + + /* ensure the previous three fields in an sepreate cacheline */ + char pad2[CACHE_LINE_SIZE - 3 * sizeof(uint64_t)]; +} trace_infra; + +typedef struct trace_config { + /* a magic number for validation */ + uint32_t trc_cfg_magic_no; + + /* mark which process are traced */ + uint32_t key; + + /* whether or not trace is activated */ + volatile bool bEnabled; + + /* record trace into disk file or memory mapping file */ + bool bTrcToFile; + + /* Trace buffer size */ + uint64_t size; + + /* additional options, such as traceId white list */ + uint64_t options; + + /* if bTrcToFile is true, records are write down this file */ + char filePath[MAX_PATH_LEN]; + + volatile int status; + volatile int status_counter; + + /* trace ids white list */ + trace_mask gs_trc_mask; + /* gstrace version. default value is TRACE_VERSION. + * if change struct trace_config or trace_infra, should add 1 on TRACE_VERSION */ + uint32_t version; + /* hash sum value of trace config files in gstrace/config. sha256(sha256(access.in) + sha256(bootstrap.in)+..) + * default value is HASH_TRACE_CONFIG which auto generate by trc_gen.py. */ + char hash_trace_config_file[LENGTH_TRACE_CONFIG_HASH]; +} trace_config; + +typedef struct trace_context { + /* address of trace infra struct in shared mem */ + trace_infra* pTrcInfra; + + /* address of trace config buffer in shared mem */ + trace_config* pTrcCfg; +} trace_context; + +// slot area header is 16 bytes +// slot aread tail is 8 bytes +// trace record ( payload of the first slot ) is 28 bytes +// that leaves us with 12 free bytes ( 64 - 52 ) in the first slot +// we can us them for rc or code path value +typedef struct trace_slot_head { + uint64_t hdr_sequence; + uint32_t hdr_magic_number; + uint32_t num_slots_in_area; +} trace_slot_head; + +typedef struct trace_slot_tail { + uint64_t tail_sequence; +} trace_slot_tail; + +// total size of trace record is 40 bytes +// and we have 16 bytes for slot header and 8 for tail +// that makes up 64 bytes which just fits in on slot!! +// ---------------------------------------------------- +typedef struct trace_record { + uint64_t timestamp; + pid_t pid; + pid_t tid; + trace_type type; // entry, exit or data + uint32_t probe; // probe point in function + uint32_t rec_id; // traceId that contains info on function and component etc. + uint32_t rc; + uint32_t un_used; // the compiler will reserve 40 bytes for the whole structre any way, + // due to alignment, may as well use it explicitly + uint32_t user_data_len; +} trace_record; + +extern trace_msg_code gstrace_start(int pid, const char* mask, uint64_t bufferSize, const char* trcFile); +extern trace_msg_code gstrace_stop(int pid); +extern trace_msg_code gstrace_dump(int pid, const char* outPath); +extern trace_msg_code gstrace_config(int pid); +extern bool isNumeric(const char* str); + +extern uint32_t getFunctionIdxByName(const char* funcName, uint32_t* comp); +extern uint32_t getCompIdxByName(const char* compName); +extern const char* getCompNameById(uint32_t trc_id); +extern const char* getTraceConfigHash(void); +extern const char* getTraceFunctionName(uint32_t trc_id); +extern const char* getTraceTypeString(trace_type type); + +// Will round up i to the nearest multiple of +// X. X must be a power of 2 +inline uint32_t gsAlign(uint32_t i, uint32_t X) +{ + return ((i + (X - 1)) & ~(uint32_t)(X - 1)); +} + +extern FILE* trace_fopen(const char* file_name, const char* mode); +extern int trace_fclose(FILE* stream); +extern int trace_open_filedesc(const char* file_name, int oflag, int mode); +extern int trace_close_filedesc(int fd); + +#endif /* TRACE_INFRA_INT_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gstrace/gstrace_tool.h postgresql-hll-2.14/include/include/gstrace/gstrace_tool.h --- postgresql-hll-2.14_old/include/include/gstrace/gstrace_tool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/gstrace_tool.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,186 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gstrace_tool.h + * + * + * IDENTIFICATION + * src/include/gstrace/gstrace_tool.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TRACE_TOOL_H_ +#define TRACE_TOOL_H_ + +#include +#include + +#define HEX_DUMP_ADDR_SZ (sizeof("0xffffffffffff") + 2) +#define HEX_DUMP_PER_LINE 16 + +// 2 bytes for each plus space in between each 2 +#define HEX_DUMP_LEN (HEX_DUMP_PER_LINE * 2 + HEX_DUMP_PER_LINE / 2) +#define HEX_DUMP_SPC 2 +#define HEX_DUMP_ASCII_START (HEX_DUMP_LEN + HEX_DUMP_SPC) + +#define HEX_DUMP_BUF_SZ (HEX_DUMP_ADDR_SZ + HEX_DUMP_ASCII_START + HEX_DUMP_PER_LINE + sizeof("\n")) + +#define HEX_DUMP_INCLUDE_ADDRESS (1 << 0) +#define HEX_DUMP_INCLUDE_ASCII (1 << 1) + +typedef struct trace_func_stat { + pid_t max_pid; + pid_t max_tid; + uint32_t max_seq; + pid_t min_pid; + pid_t min_tid; + uint32_t min_seq; + uint32_t counter; + double total_time; + double max_elapsed_time; + double min_elapsed_time; + double average_elapsed_time; +} trace_func_stat; + +typedef std::map func_stat; + +// Class: ThreadFlow +// Using a stack to construct a control flow for each thread. +// ------------------------------------------------------------------------------------------- +class ThreadFlow { +public: + ThreadFlow(pid_t pid, pid_t tid, bool analyze, int stepSize, FILE* fpStepOut); + ~ThreadFlow(); + void flush(); + void handleEntry(trace_record* pRec, uint32_t seqNum); + void handleExit(trace_record* pRec, uint32_t seqNum, func_stat* func_flow, func_stat* func_flow_step, + uint64_t* stepStartTime, uint32_t* stepCounter); + void handleData(trace_record* pRec, void* pData, size_t len, uint32_t seqNum); + void refreshStats(trace_record* entry_rec, double elaps_time, trace_func_stat* funcInfo, uint32_t seqNum); + void writeToFile(trace_record* rec, double elapse_time, uint32_t indentation, uint32_t seqNum); + void flushStepStatsToFile(func_stat* func_stats, uint32_t stepCounter); + double getElapsetime(trace_record* entry_rec, trace_record* exit_rec); + void refreshAnalyzeData(trace_record* topRec, trace_record* pRec, func_stat* func_flow, func_stat* func_flow_step, + uint64_t* stepStartTime, double elapse_time, uint32_t seqNum, uint32_t* stepCounter); + +private: + pid_t m_Pid; + pid_t m_Tid; + bool m_analyze; + int m_stepSize; + std::stack m_GsFlowStack; + FILE* fpOut; /* output file */ + FILE* fpStepOut; /* step analyze file */ + const int max_step_analyze_line_size = 2048; +}; + +typedef std::map map_flow; + +// Class: DumpFileVisitor +// Define the interface for any kind of visitors. To decouple the parser +// and the logic how you want to use the data parsed from dmp file. +// e.g. For trace to flow, can create a concrete class named DumpFileFlowVisitor +// and implement visitEntry, visitExit and visitData respectively. +// +// For formatting, can create another concrete class named FormatVisitor, +// and implement each visitXXX method to append each records in order to the fmt file. +// ------------------------------------------------------------------------------------------- +class DumpFileVisitor { +public: + // dataOrRec: + // 0 - data + // 1 - rec + DumpFileVisitor() + {} + virtual ~DumpFileVisitor() + {} + + // Check the type of the record and call different methods for different types + void visit(trace_record* pRec, void* pData, size_t len); + virtual void visitEntry(trace_record* pRec){}; + virtual void visitExit(trace_record* pRec){}; + virtual void visitData(trace_record* pRec, void* pData, size_t len){}; + virtual void outputStat(FILE* fp){}; + +protected: + uint32_t m_Counter = 1; + bool m_analyze = false; + int m_stepSize = 0; + char m_stepOutputFile[MAX_PATH_LEN] = {0}; + size_t m_stepOutputFileLen = 0; + FILE* fpStepOut = NULL; /* step analyze file */ +}; + +// Class: DumpFileFlowVisitor +// Extend the DumpFileVisitor, and implement visitEntry, visitExit and visitData. +// It's used for taking records in order and create a control flow for each thread. +// ------------------------------------------------------------------------------------------- +class DumpFileFlowVisitor : public DumpFileVisitor { +public: + DumpFileFlowVisitor(bool analyze, int stepSize = 0, const char* outputFile = "", size_t output_len = 0); + ~DumpFileFlowVisitor(); + void visitEntry(trace_record* pRec) override; + void visitExit(trace_record* pRec) override; + void visitData(trace_record* pRec, void* pData, size_t len) override; + void outputStat(FILE* fp) override; + void putIfUnexisted(pid_t pid, pid_t tid); + void putFuncStatIfUnexisted(uint32_t func_id, func_stat* func_stat_map); + void mergeFiles(const char* outPath, size_t len); + void flushThreadFlows(); + +private: + map_flow mapFlows; + func_stat funcFlows; + func_stat funcFlowsStep; + uint64_t stepStartTime; + uint32_t stepCounter; + const int max_analyze_line_size = 2048; + const int microsecond = 1000000; +}; + +// Dump File Parser +// ----------------------------------------------------------- +class DumpFileParser { +public: + DumpFileParser(const char* inputFile, size_t len); + ~DumpFileParser(); + + // get header (the first slot) + // so the first slot contains header or the record + trace_msg_code parseHeader(void* pSlotHeader, size_t hdr_len); + trace_msg_code parseData(void* pData, size_t data_len); + trace_msg_code parseCfg(trace_config* pCfg); + trace_msg_code parseInfra(trace_infra* pInfra); + + trace_msg_code readAndParseDump(uint64_t counter, uint64_t* totNumRecsFormatted); + // Parse the whole dmp file. + trace_msg_code parse(); + + // Dynamically accept a visitor as the logic used for processing records + // during parsing. + void acceptVisitor(DumpFileVisitor* visitor); + trace_msg_code parseOneRecord(const char rec_tmp_buf[MAX_TRC_RC_SZ], size_t bufSize, bool hasdata); + trace_msg_code readAndParseOneRecord(void); + uint64_t findStartSlot(uint64_t maxSeq, uint64_t maxSlots, off_t* firstRecordOffset); + +private: + int fdInput; + DumpFileVisitor* pVisitor = NULL; + uint64_t firstTimestamp = 0; + uint64_t lenFirstNotOverlaped = 0; + bool processForOverlap = false; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gstrace/libpq_gstrace.h postgresql-hll-2.14/include/include/gstrace/libpq_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/libpq_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/libpq_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,32 @@ +// This is a generated file + +#ifndef _LIBPQ_GSTRACE_H +#define _LIBPQ_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_StreamServerPort GS_TRC_ID_PACK(COMP_LIBPQ, 1) +#define GS_TRC_ID_StreamConnection GS_TRC_ID_PACK(COMP_LIBPQ, 2) +#define GS_TRC_ID_StreamClose GS_TRC_ID_PACK(COMP_LIBPQ, 3) +#define GS_TRC_ID_TouchSocketFile GS_TRC_ID_PACK(COMP_LIBPQ, 4) +#define GS_TRC_ID_pq_init GS_TRC_ID_PACK(COMP_LIBPQ, 5) +#define GS_TRC_ID_pq_comm_reset GS_TRC_ID_PACK(COMP_LIBPQ, 6) +#define GS_TRC_ID_pq_getbytes GS_TRC_ID_PACK(COMP_LIBPQ, 7) +#define GS_TRC_ID_pq_getstring GS_TRC_ID_PACK(COMP_LIBPQ, 8) +#define GS_TRC_ID_pq_getmessage GS_TRC_ID_PACK(COMP_LIBPQ, 9) +#define GS_TRC_ID_pq_getbyte GS_TRC_ID_PACK(COMP_LIBPQ, 10) +#define GS_TRC_ID_pq_peekbyte GS_TRC_ID_PACK(COMP_LIBPQ, 11) +#define GS_TRC_ID_pq_getbyte_if_available GS_TRC_ID_PACK(COMP_LIBPQ, 12) +#define GS_TRC_ID_pq_putbytes GS_TRC_ID_PACK(COMP_LIBPQ, 13) +#define GS_TRC_ID_pq_flush GS_TRC_ID_PACK(COMP_LIBPQ, 14) +#define GS_TRC_ID_pq_flush_if_writable GS_TRC_ID_PACK(COMP_LIBPQ, 15) +#define GS_TRC_ID_pq_flush_timedwait GS_TRC_ID_PACK(COMP_LIBPQ, 16) +#define GS_TRC_ID_pq_is_send_pending GS_TRC_ID_PACK(COMP_LIBPQ, 17) +#define GS_TRC_ID_pq_putmessage GS_TRC_ID_PACK(COMP_LIBPQ, 18) +#define GS_TRC_ID_pq_putmessage_noblock GS_TRC_ID_PACK(COMP_LIBPQ, 19) +#define GS_TRC_ID_pq_startcopyout GS_TRC_ID_PACK(COMP_LIBPQ, 20) +#define GS_TRC_ID_pq_endcopyout GS_TRC_ID_PACK(COMP_LIBPQ, 21) +#define GS_TRC_ID_pq_select GS_TRC_ID_PACK(COMP_LIBPQ, 22) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/optimizer_gstrace.h postgresql-hll-2.14/include/include/gstrace/optimizer_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/optimizer_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/optimizer_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,57 @@ +// This is a generated file + +#ifndef _OPTIMIZER_GSTRACE_H +#define _OPTIMIZER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_clauselist_selectivity GS_TRC_ID_PACK(COMP_OPTIMIZER, 1) +#define GS_TRC_ID_clause_selectivity GS_TRC_ID_PACK(COMP_OPTIMIZER, 2) +#define GS_TRC_ID_set_rel_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 3) +#define GS_TRC_ID_restore_hashjoin_cost GS_TRC_ID_PACK(COMP_OPTIMIZER, 4) +#define GS_TRC_ID_finalize_dml_cost GS_TRC_ID_PACK(COMP_OPTIMIZER, 5) +#define GS_TRC_ID_copy_mem_info GS_TRC_ID_PACK(COMP_OPTIMIZER, 6) +#define GS_TRC_ID_columnar_get_col_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 7) +#define GS_TRC_ID_get_path_actual_total_width GS_TRC_ID_PACK(COMP_OPTIMIZER, 8) +#define GS_TRC_ID_query_planner GS_TRC_ID_PACK(COMP_OPTIMIZER, 9) +#define GS_TRC_ID_preprocess_minmax_aggregates GS_TRC_ID_PACK(COMP_OPTIMIZER, 10) +#define GS_TRC_ID_optimize_minmax_aggregates GS_TRC_ID_PACK(COMP_OPTIMIZER, 11) +#define GS_TRC_ID_set_plan_rows GS_TRC_ID_PACK(COMP_OPTIMIZER, 12) +#define GS_TRC_ID_create_plan GS_TRC_ID_PACK(COMP_OPTIMIZER, 13) +#define GS_TRC_ID_disuse_physical_tlist GS_TRC_ID_PACK(COMP_OPTIMIZER, 14) +#define GS_TRC_ID_copy_plan_costsize GS_TRC_ID_PACK(COMP_OPTIMIZER, 15) +#define GS_TRC_ID_make_subqueryscan GS_TRC_ID_PACK(COMP_OPTIMIZER, 16) +#define GS_TRC_ID_make_foreignscan GS_TRC_ID_PACK(COMP_OPTIMIZER, 17) +#define GS_TRC_ID_make_append GS_TRC_ID_PACK(COMP_OPTIMIZER, 18) +#define GS_TRC_ID_make_recursive_union GS_TRC_ID_PACK(COMP_OPTIMIZER, 19) +#define GS_TRC_ID_make_sort_from_pathkeys GS_TRC_ID_PACK(COMP_OPTIMIZER, 20) +#define GS_TRC_ID_make_sort_from_sortclauses GS_TRC_ID_PACK(COMP_OPTIMIZER, 21) +#define GS_TRC_ID_make_sort_from_groupcols GS_TRC_ID_PACK(COMP_OPTIMIZER, 22) +#define GS_TRC_ID_make_sort_from_targetlist GS_TRC_ID_PACK(COMP_OPTIMIZER, 23) +#define GS_TRC_ID_make_sort GS_TRC_ID_PACK(COMP_OPTIMIZER, 24) +#define GS_TRC_ID_make_agg GS_TRC_ID_PACK(COMP_OPTIMIZER, 25) +#define GS_TRC_ID_make_windowagg GS_TRC_ID_PACK(COMP_OPTIMIZER, 26) +#define GS_TRC_ID_make_group GS_TRC_ID_PACK(COMP_OPTIMIZER, 27) +#define GS_TRC_ID_materialize_finished_plan GS_TRC_ID_PACK(COMP_OPTIMIZER, 28) +#define GS_TRC_ID_make_unique GS_TRC_ID_PACK(COMP_OPTIMIZER, 29) +#define GS_TRC_ID_make_lockrows GS_TRC_ID_PACK(COMP_OPTIMIZER, 30) +#define GS_TRC_ID_make_limit GS_TRC_ID_PACK(COMP_OPTIMIZER, 31) +#define GS_TRC_ID_make_stream_limit GS_TRC_ID_PACK(COMP_OPTIMIZER, 32) +#define GS_TRC_ID_compare_path_costs GS_TRC_ID_PACK(COMP_OPTIMIZER, 33) +#define GS_TRC_ID_compare_fractional_path_costs GS_TRC_ID_PACK(COMP_OPTIMIZER, 34) +#define GS_TRC_ID_set_cheapest GS_TRC_ID_PACK(COMP_OPTIMIZER, 35) +#define GS_TRC_ID_get_cheapest_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 36) +#define GS_TRC_ID_find_hinted_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 37) +#define GS_TRC_ID_add_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 38) +#define GS_TRC_ID_add_path_precheck GS_TRC_ID_PACK(COMP_OPTIMIZER, 39) +#define GS_TRC_ID_create_seqscan_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 40) +#define GS_TRC_ID_create_cstorescan_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 41) +#define GS_TRC_ID_create_index_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 42) +#define GS_TRC_ID_build_seqScanPath_by_indexScanPath GS_TRC_ID_PACK(COMP_OPTIMIZER, 43) +#define GS_TRC_ID_check_bitmap_heap_path_index_unusable GS_TRC_ID_PACK(COMP_OPTIMIZER, 44) +#define GS_TRC_ID_is_partitionIndex_Subpath GS_TRC_ID_PACK(COMP_OPTIMIZER, 45) +#define GS_TRC_ID_is_pwj_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 46) +#define GS_TRC_ID_create_bitmap_heap_path GS_TRC_ID_PACK(COMP_OPTIMIZER, 47) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/parser_gstrace.h postgresql-hll-2.14/include/include/gstrace/parser_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/parser_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/parser_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,24 @@ +// This is a generated file + +#ifndef _PARSER_GSTRACE_H +#define _PARSER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_make_parsestate GS_TRC_ID_PACK(COMP_PARSER, 1) +#define GS_TRC_ID_free_parsestate GS_TRC_ID_PACK(COMP_PARSER, 2) +#define GS_TRC_ID_parser_errposition GS_TRC_ID_PACK(COMP_PARSER, 3) +#define GS_TRC_ID_setup_parser_errposition_callback GS_TRC_ID_PACK(COMP_PARSER, 4) +#define GS_TRC_ID_cancel_parser_errposition_callback GS_TRC_ID_PACK(COMP_PARSER, 5) +#define GS_TRC_ID_make_var GS_TRC_ID_PACK(COMP_PARSER, 6) +#define GS_TRC_ID_transformArrayType GS_TRC_ID_PACK(COMP_PARSER, 7) +#define GS_TRC_ID_transformArraySubscripts GS_TRC_ID_PACK(COMP_PARSER, 8) +#define GS_TRC_ID_make_const GS_TRC_ID_PACK(COMP_PARSER, 9) +#define GS_TRC_ID_scanner_init GS_TRC_ID_PACK(COMP_PARSER, 10) +#define GS_TRC_ID_scanner_finish GS_TRC_ID_PACK(COMP_PARSER, 11) +#define GS_TRC_ID_core_yylex GS_TRC_ID_PACK(COMP_PARSER, 12) +#define GS_TRC_ID_scanner_errposition GS_TRC_ID_PACK(COMP_PARSER, 13) +#define GS_TRC_ID_scanner_yyerror GS_TRC_ID_PACK(COMP_PARSER, 14) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/pg_ctl_gstrace.h postgresql-hll-2.14/include/include/gstrace/pg_ctl_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/pg_ctl_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/pg_ctl_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,13 @@ +// This is a generated file + +#ifndef _PG_CTL_GSTRACE_H +#define _PG_CTL_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_ReceiveXlogStream GS_TRC_ID_PACK(COMP_PG_CTL, 1) +#define GS_TRC_ID_get_replconn_number GS_TRC_ID_PACK(COMP_PG_CTL, 2) +#define GS_TRC_ID_ParseReplConnInfo GS_TRC_ID_PACK(COMP_PG_CTL, 3) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/postmaster_gstrace.h postgresql-hll-2.14/include/include/gstrace/postmaster_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/postmaster_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/postmaster_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,72 @@ +// This is a generated file + +#ifndef _POSTMASTER_GSTRACE_H +#define _POSTMASTER_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_PostmasterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 1) +#define GS_TRC_ID_ClosePostmasterPorts GS_TRC_ID_PACK(COMP_POSTMASTER, 2) +#define GS_TRC_ID_MaxLivePostmasterChildren GS_TRC_ID_PACK(COMP_POSTMASTER, 3) +#define GS_TRC_ID_HaShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 4) +#define GS_TRC_ID_HaShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 5) +#define GS_TRC_ID_postmaster_forkexec GS_TRC_ID_PACK(COMP_POSTMASTER, 6) +#define GS_TRC_ID_stream_forkexec GS_TRC_ID_PACK(COMP_POSTMASTER, 7) +#define GS_TRC_ID_WLMProcessForkExec GS_TRC_ID_PACK(COMP_POSTMASTER, 8) +#define GS_TRC_ID_SubPostmasterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 9) +#define GS_TRC_ID_ShmemBackendArraySize GS_TRC_ID_PACK(COMP_POSTMASTER, 10) +#define GS_TRC_ID_ShmemBackendArrayAllocation GS_TRC_ID_PACK(COMP_POSTMASTER, 11) +#define GS_TRC_ID_SysLogger_Start GS_TRC_ID_PACK(COMP_POSTMASTER, 12) +#define GS_TRC_ID_SysLoggerClose GS_TRC_ID_PACK(COMP_POSTMASTER, 13) +#define GS_TRC_ID_write_syslogger_file GS_TRC_ID_PACK(COMP_POSTMASTER, 14) +#define GS_TRC_ID_AioCompltrMain GS_TRC_ID_PACK(COMP_POSTMASTER, 15) +#define GS_TRC_ID_AioCompltrStop GS_TRC_ID_PACK(COMP_POSTMASTER, 16) +#define GS_TRC_ID_AioCompltrStart GS_TRC_ID_PACK(COMP_POSTMASTER, 17) +#define GS_TRC_ID_AioCompltrIsReady GS_TRC_ID_PACK(COMP_POSTMASTER, 18) +#define GS_TRC_ID_CompltrContext GS_TRC_ID_PACK(COMP_POSTMASTER, 19) +#define GS_TRC_ID_CompltrPriority GS_TRC_ID_PACK(COMP_POSTMASTER, 20) +#define GS_TRC_ID_AutoVacuumingActive GS_TRC_ID_PACK(COMP_POSTMASTER, 21) +#define GS_TRC_ID_IsAutoVacuumLauncherProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 22) +#define GS_TRC_ID_IsAutoVacuumWorkerProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 23) +#define GS_TRC_ID_autovac_init GS_TRC_ID_PACK(COMP_POSTMASTER, 24) +#define GS_TRC_ID_StartAutoVacLauncher GS_TRC_ID_PACK(COMP_POSTMASTER, 25) +#define GS_TRC_ID_StartAutoVacWorker GS_TRC_ID_PACK(COMP_POSTMASTER, 26) +#define GS_TRC_ID_AutoVacWorkerFailed GS_TRC_ID_PACK(COMP_POSTMASTER, 27) +#define GS_TRC_ID_AutoVacuumUpdateDelay GS_TRC_ID_PACK(COMP_POSTMASTER, 28) +#define GS_TRC_ID_AutoVacLauncherMain GS_TRC_ID_PACK(COMP_POSTMASTER, 29) +#define GS_TRC_ID_AutoVacWorkerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 30) +#define GS_TRC_ID_AutovacuumWorkerIAm GS_TRC_ID_PACK(COMP_POSTMASTER, 31) +#define GS_TRC_ID_AutovacuumLauncherIAm GS_TRC_ID_PACK(COMP_POSTMASTER, 32) +#define GS_TRC_ID_HandleStartupProcInterrupts GS_TRC_ID_PACK(COMP_POSTMASTER, 33) +#define GS_TRC_ID_StartupProcessMain GS_TRC_ID_PACK(COMP_POSTMASTER, 34) +#define GS_TRC_ID_PreRestoreCommand GS_TRC_ID_PACK(COMP_POSTMASTER, 35) +#define GS_TRC_ID_PostRestoreCommand GS_TRC_ID_PACK(COMP_POSTMASTER, 36) +#define GS_TRC_ID_IsFailoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 37) +#define GS_TRC_ID_IsSwitchoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 38) +#define GS_TRC_ID_IsPrimaryTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 39) +#define GS_TRC_ID_ResetSwitchoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 40) +#define GS_TRC_ID_ResetFailoverTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 41) +#define GS_TRC_ID_ResetPrimaryTriggered GS_TRC_ID_PACK(COMP_POSTMASTER, 42) +#define GS_TRC_ID_NotifySignalShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 43) +#define GS_TRC_ID_NotifySignalShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 44) +#define GS_TRC_ID_SendNotifySignal GS_TRC_ID_PACK(COMP_POSTMASTER, 45) +#define GS_TRC_ID_CheckNotifySignal GS_TRC_ID_PACK(COMP_POSTMASTER, 46) +#define GS_TRC_ID_BackgroundWriterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 47) +#define GS_TRC_ID_CheckpointerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 48) +#define GS_TRC_ID_RequestCheckpoint GS_TRC_ID_PACK(COMP_POSTMASTER, 49) +#define GS_TRC_ID_CheckpointWriteDelay GS_TRC_ID_PACK(COMP_POSTMASTER, 50) +#define GS_TRC_ID_ForwardFsyncRequest GS_TRC_ID_PACK(COMP_POSTMASTER, 51) +#define GS_TRC_ID_AbsorbFsyncRequests GS_TRC_ID_PACK(COMP_POSTMASTER, 52) +#define GS_TRC_ID_CheckpointerShmemSize GS_TRC_ID_PACK(COMP_POSTMASTER, 53) +#define GS_TRC_ID_CheckpointerShmemInit GS_TRC_ID_PACK(COMP_POSTMASTER, 54) +#define GS_TRC_ID_FirstCallSinceLastCheckpoint GS_TRC_ID_PACK(COMP_POSTMASTER, 55) +#define GS_TRC_ID_IsBgwriterProcess GS_TRC_ID_PACK(COMP_POSTMASTER, 56) +#define GS_TRC_ID_isDirExist GS_TRC_ID_PACK(COMP_POSTMASTER, 57) +#define GS_TRC_ID_startAlarmChecker GS_TRC_ID_PACK(COMP_POSTMASTER, 58) +#define GS_TRC_ID_AlarmCheckerMain GS_TRC_ID_PACK(COMP_POSTMASTER, 59) +#define GS_TRC_ID_fork_process GS_TRC_ID_PACK(COMP_POSTMASTER, 60) +#define GS_TRC_ID_WalWriterMain GS_TRC_ID_PACK(COMP_POSTMASTER, 61) +#define GS_TRC_ID_ckpt_try_prune_dirty_page_queue GS_TRC_ID_PACK(COMP_POSTMASTER, 62) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/replication_gstrace.h postgresql-hll-2.14/include/include/gstrace/replication_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/replication_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/replication_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,62 @@ +// This is a generated file + +#ifndef _REPLICATION_GSTRACE_H +#define _REPLICATION_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_WalReceiverMain GS_TRC_ID_PACK(COMP_REPLICATION, 1) +#define GS_TRC_ID_walrcvWriterMain GS_TRC_ID_PACK(COMP_REPLICATION, 2) +#define GS_TRC_ID_WalRcvShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 3) +#define GS_TRC_ID_WalRcvShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 4) +#define GS_TRC_ID_ShutdownWalRcv GS_TRC_ID_PACK(COMP_REPLICATION, 5) +#define GS_TRC_ID_WalRcvInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 6) +#define GS_TRC_ID_connect_dn_str GS_TRC_ID_PACK(COMP_REPLICATION, 7) +#define GS_TRC_ID_RequestXLogStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 8) +#define GS_TRC_ID_get_rcv_slot_name GS_TRC_ID_PACK(COMP_REPLICATION, 9) +#define GS_TRC_ID_GetWalRcvWriteRecPtr GS_TRC_ID_PACK(COMP_REPLICATION, 10) +#define GS_TRC_ID_GetReplicationApplyDelay GS_TRC_ID_PACK(COMP_REPLICATION, 11) +#define GS_TRC_ID_GetReplicationTransferLatency GS_TRC_ID_PACK(COMP_REPLICATION, 12) +#define GS_TRC_ID_GetWalRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 13) +#define GS_TRC_ID_SetWalRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 14) +#define GS_TRC_ID_getCurrentWalRcvCtlBlock GS_TRC_ID_PACK(COMP_REPLICATION, 15) +#define GS_TRC_ID_walRcvWrite GS_TRC_ID_PACK(COMP_REPLICATION, 16) +#define GS_TRC_ID_WalRcvXLogClose GS_TRC_ID_PACK(COMP_REPLICATION, 17) +#define GS_TRC_ID_WalRcvIsShutdown GS_TRC_ID_PACK(COMP_REPLICATION, 18) +#define GS_TRC_ID_ProcessRmXLog GS_TRC_ID_PACK(COMP_REPLICATION, 19) +#define GS_TRC_ID_SetWalRcvWriterPID GS_TRC_ID_PACK(COMP_REPLICATION, 20) +#define GS_TRC_ID_WalRcvWriterInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 21) +#define GS_TRC_ID_walRcvCtlBlockIsEmpty GS_TRC_ID_PACK(COMP_REPLICATION, 22) +#define GS_TRC_ID_GetRepConnArray GS_TRC_ID_PACK(COMP_REPLICATION, 23) +#define GS_TRC_ID_get_sync_percent GS_TRC_ID_PACK(COMP_REPLICATION, 24) +#define GS_TRC_ID_wal_get_role_string GS_TRC_ID_PACK(COMP_REPLICATION, 25) +#define GS_TRC_ID_pg_stat_get_stream_replications GS_TRC_ID_PACK(COMP_REPLICATION, 26) +#define GS_TRC_ID_DataReceiverMain GS_TRC_ID_PACK(COMP_REPLICATION, 27) +#define GS_TRC_ID_DataRcvShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 28) +#define GS_TRC_ID_DataRcvShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 29) +#define GS_TRC_ID_DataRcvInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 30) +#define GS_TRC_ID_ShutdownDataRcv GS_TRC_ID_PACK(COMP_REPLICATION, 31) +#define GS_TRC_ID_StartupDataStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 32) +#define GS_TRC_ID_RequestDataStreaming GS_TRC_ID_PACK(COMP_REPLICATION, 33) +#define GS_TRC_ID_InitDummyDataNum GS_TRC_ID_PACK(COMP_REPLICATION, 34) +#define GS_TRC_ID_WakeupDataRcvWriter GS_TRC_ID_PACK(COMP_REPLICATION, 35) +#define GS_TRC_ID_DataRcvWriterInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 36) +#define GS_TRC_ID_DataRcvDataCleanup GS_TRC_ID_PACK(COMP_REPLICATION, 37) +#define GS_TRC_ID_DataRcvWriterMain GS_TRC_ID_PACK(COMP_REPLICATION, 38) +#define GS_TRC_ID_DataRcvWrite GS_TRC_ID_PACK(COMP_REPLICATION, 39) +#define GS_TRC_ID_SetDataRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 40) +#define GS_TRC_ID_GetDataRcvDummyStandbySyncPercent GS_TRC_ID_PACK(COMP_REPLICATION, 41) +#define GS_TRC_ID_SetDataRcvWriterPID GS_TRC_ID_PACK(COMP_REPLICATION, 42) +#define GS_TRC_ID_ProcessDataRcvInterrupts GS_TRC_ID_PACK(COMP_REPLICATION, 43) +#define GS_TRC_ID_CloseDataFile GS_TRC_ID_PACK(COMP_REPLICATION, 44) +#define GS_TRC_ID_WalSenderMain GS_TRC_ID_PACK(COMP_REPLICATION, 45) +#define GS_TRC_ID_WalSndSignals GS_TRC_ID_PACK(COMP_REPLICATION, 46) +#define GS_TRC_ID_WalSndShmemSize GS_TRC_ID_PACK(COMP_REPLICATION, 47) +#define GS_TRC_ID_WalSndShmemInit GS_TRC_ID_PACK(COMP_REPLICATION, 48) +#define GS_TRC_ID_WalSndWakeup GS_TRC_ID_PACK(COMP_REPLICATION, 49) +#define GS_TRC_ID_WalSndRqstFileReload GS_TRC_ID_PACK(COMP_REPLICATION, 50) +#define GS_TRC_ID_WalSndInProgress GS_TRC_ID_PACK(COMP_REPLICATION, 51) +#define GS_TRC_ID_StandbyOrSecondaryIsAlive GS_TRC_ID_PACK(COMP_REPLICATION, 52) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/rewrite_gstrace.h postgresql-hll-2.14/include/include/gstrace/rewrite_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/rewrite_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/rewrite_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,23 @@ +// This is a generated file + +#ifndef _REWRITE_GSTRACE_H +#define _REWRITE_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_OffsetVarNodes GS_TRC_ID_PACK(COMP_REWRITE, 1) +#define GS_TRC_ID_ChangeVarNodes GS_TRC_ID_PACK(COMP_REWRITE, 2) +#define GS_TRC_ID_IncrementVarSublevelsUp GS_TRC_ID_PACK(COMP_REWRITE, 3) +#define GS_TRC_ID_IncrementVarSublevelsUp_rtable GS_TRC_ID_PACK(COMP_REWRITE, 4) +#define GS_TRC_ID_rangeTableEntry_used GS_TRC_ID_PACK(COMP_REWRITE, 5) +#define GS_TRC_ID_attribute_used GS_TRC_ID_PACK(COMP_REWRITE, 6) +#define GS_TRC_ID_getInsertSelectQuery GS_TRC_ID_PACK(COMP_REWRITE, 7) +#define GS_TRC_ID_AddQual GS_TRC_ID_PACK(COMP_REWRITE, 8) +#define GS_TRC_ID_AddInvertedQual GS_TRC_ID_PACK(COMP_REWRITE, 9) +#define GS_TRC_ID_contain_aggs_of_level GS_TRC_ID_PACK(COMP_REWRITE, 10) +#define GS_TRC_ID_checkExprHasAggs GS_TRC_ID_PACK(COMP_REWRITE, 11) +#define GS_TRC_ID_checkExprHasWindowFuncs GS_TRC_ID_PACK(COMP_REWRITE, 12) +#define GS_TRC_ID_checkExprHasSubLink GS_TRC_ID_PACK(COMP_REWRITE, 13) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/storage_gstrace.h postgresql-hll-2.14/include/include/gstrace/storage_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/storage_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/storage_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,70 @@ +// This is a generated file + +#ifndef _STORAGE_GSTRACE_H +#define _STORAGE_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_InitBufferPool GS_TRC_ID_PACK(COMP_STORAGE, 1) +#define GS_TRC_ID_InitBufferPoolAccess GS_TRC_ID_PACK(COMP_STORAGE, 2) +#define GS_TRC_ID_InitBufferPoolBackend GS_TRC_ID_PACK(COMP_STORAGE, 3) +#define GS_TRC_ID_AtEOXact_Buffers GS_TRC_ID_PACK(COMP_STORAGE, 4) +#define GS_TRC_ID_PrintBufferLeakWarning GS_TRC_ID_PACK(COMP_STORAGE, 5) +#define GS_TRC_ID_CheckPointBuffers GS_TRC_ID_PACK(COMP_STORAGE, 6) +#define GS_TRC_ID_RelationGetNumberOfBlocksInFork GS_TRC_ID_PACK(COMP_STORAGE, 7) +#define GS_TRC_ID_FlushRelationBuffers GS_TRC_ID_PACK(COMP_STORAGE, 8) +#define GS_TRC_ID_FlushDatabaseBuffers GS_TRC_ID_PACK(COMP_STORAGE, 9) +#define GS_TRC_ID_DropRelFileNodeBuffers GS_TRC_ID_PACK(COMP_STORAGE, 10) +#define GS_TRC_ID_DropRelFileNodeAllBuffers GS_TRC_ID_PACK(COMP_STORAGE, 11) +#define GS_TRC_ID_DropDatabaseBuffers GS_TRC_ID_PACK(COMP_STORAGE, 12) +#define GS_TRC_ID_ProcArrayShmemSize GS_TRC_ID_PACK(COMP_STORAGE, 13) +#define GS_TRC_ID_ProcArrayAdd GS_TRC_ID_PACK(COMP_STORAGE, 14) +#define GS_TRC_ID_ProcArrayRemove GS_TRC_ID_PACK(COMP_STORAGE, 15) +#define GS_TRC_ID_ProcArrayEndTransaction GS_TRC_ID_PACK(COMP_STORAGE, 16) +#define GS_TRC_ID_ProcArrayClearTransaction GS_TRC_ID_PACK(COMP_STORAGE, 17) +#define GS_TRC_ID_SetGlobalSnapshotData GS_TRC_ID_PACK(COMP_STORAGE, 18) +#define GS_TRC_ID_UnsetGlobalSnapshotData GS_TRC_ID_PACK(COMP_STORAGE, 19) +#define GS_TRC_ID_ReloadConnInfoOnBackends GS_TRC_ID_PACK(COMP_STORAGE, 20) +#define GS_TRC_ID_DumpMemoryCtxOnBackend GS_TRC_ID_PACK(COMP_STORAGE, 21) +#define GS_TRC_ID_ProcArrayInitRecovery GS_TRC_ID_PACK(COMP_STORAGE, 22) +#define GS_TRC_ID_ProcArrayApplyRecoveryInfo GS_TRC_ID_PACK(COMP_STORAGE, 23) +#define GS_TRC_ID_ProcArrayApplyXidAssignment GS_TRC_ID_PACK(COMP_STORAGE, 24) +#define GS_TRC_ID_RecordKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 25) +#define GS_TRC_ID_ExpireTreeKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 26) +#define GS_TRC_ID_ExpireAllKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 27) +#define GS_TRC_ID_ExpireOldKnownAssignedTransactionIds GS_TRC_ID_PACK(COMP_STORAGE, 28) +#define GS_TRC_ID_GetMaxSnapshotXidCount GS_TRC_ID_PACK(COMP_STORAGE, 29) +#define GS_TRC_ID_GetMaxSnapshotSubxidCount GS_TRC_ID_PACK(COMP_STORAGE, 30) +#define GS_TRC_ID_smgrinit GS_TRC_ID_PACK(COMP_STORAGE, 31) +#define GS_TRC_ID_smgropen GS_TRC_ID_PACK(COMP_STORAGE, 32) +#define GS_TRC_ID_smgrexists GS_TRC_ID_PACK(COMP_STORAGE, 33) +#define GS_TRC_ID_smgrsetowner GS_TRC_ID_PACK(COMP_STORAGE, 34) +#define GS_TRC_ID_smgrclearowner GS_TRC_ID_PACK(COMP_STORAGE, 35) +#define GS_TRC_ID_smgrclose GS_TRC_ID_PACK(COMP_STORAGE, 36) +#define GS_TRC_ID_smgrcloseall GS_TRC_ID_PACK(COMP_STORAGE, 37) +#define GS_TRC_ID_smgrclosenode GS_TRC_ID_PACK(COMP_STORAGE, 38) +#define GS_TRC_ID_smgrcreate GS_TRC_ID_PACK(COMP_STORAGE, 39) +#define GS_TRC_ID_smgrdounlink GS_TRC_ID_PACK(COMP_STORAGE, 40) +#define GS_TRC_ID_smgrdounlinkfork GS_TRC_ID_PACK(COMP_STORAGE, 41) +#define GS_TRC_ID_smgrextend GS_TRC_ID_PACK(COMP_STORAGE, 42) +#define GS_TRC_ID_smgrprefetch GS_TRC_ID_PACK(COMP_STORAGE, 43) +#define GS_TRC_ID_smgrread GS_TRC_ID_PACK(COMP_STORAGE, 44) +#define GS_TRC_ID_smgrwrite GS_TRC_ID_PACK(COMP_STORAGE, 45) +#define GS_TRC_ID_smgrwriteback GS_TRC_ID_PACK(COMP_STORAGE, 46) +#define GS_TRC_ID_smgrnblocks GS_TRC_ID_PACK(COMP_STORAGE, 47) +#define GS_TRC_ID_smgrtruncate GS_TRC_ID_PACK(COMP_STORAGE, 48) +#define GS_TRC_ID_smgrimmedsync GS_TRC_ID_PACK(COMP_STORAGE, 49) +#define GS_TRC_ID_smgrpreckpt GS_TRC_ID_PACK(COMP_STORAGE, 50) +#define GS_TRC_ID_smgrsync GS_TRC_ID_PACK(COMP_STORAGE, 51) +#define GS_TRC_ID_smgrpostckpt GS_TRC_ID_PACK(COMP_STORAGE, 52) +#define GS_TRC_ID_AtEOXact_SMgr GS_TRC_ID_PACK(COMP_STORAGE, 53) +#define GS_TRC_ID_BufferAlloc GS_TRC_ID_PACK(COMP_STORAGE, 54) +#define GS_TRC_ID_SyncLocalXidWait GS_TRC_ID_PACK(COMP_STORAGE, 55) +#define GS_TRC_ID_BufferSync GS_TRC_ID_PACK(COMP_STORAGE, 56) +#define GS_TRC_ID_BgBufferSync GS_TRC_ID_PACK(COMP_STORAGE, 57) +#define GS_TRC_ID_fsm_vacuum_page GS_TRC_ID_PACK(COMP_STORAGE, 58) +#define GS_TRC_ID_fsm_search GS_TRC_ID_PACK(COMP_STORAGE, 59) +#define GS_TRC_ID_fsm_set_and_search GS_TRC_ID_PACK(COMP_STORAGE, 60) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/system_gstrace.h postgresql-hll-2.14/include/include/gstrace/system_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/system_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/system_gstrace.h 2020-12-12 17:06:43.200347432 +0800 @@ -0,0 +1,11 @@ +// This is a generated file + +#ifndef _SYSTEM_GSTRACE_H +#define _SYSTEM_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_TRY_CATCH GS_TRC_ID_PACK(COMP_SYSTEM, 1) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/tcop_gstrace.h postgresql-hll-2.14/include/include/gstrace/tcop_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/tcop_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/tcop_gstrace.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,55 @@ +// This is a generated file + +#ifndef _TCOP_GSTRACE_H +#define _TCOP_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_BeginCommand GS_TRC_ID_PACK(COMP_TCOP, 1) +#define GS_TRC_ID_CreateDestReceiver GS_TRC_ID_PACK(COMP_TCOP, 2) +#define GS_TRC_ID_CreateReceiverForMerge GS_TRC_ID_PACK(COMP_TCOP, 3) +#define GS_TRC_ID_EndCommand GS_TRC_ID_PACK(COMP_TCOP, 4) +#define GS_TRC_ID_EndCommand_noblock GS_TRC_ID_PACK(COMP_TCOP, 5) +#define GS_TRC_ID_ProcessUtility GS_TRC_ID_PACK(COMP_TCOP, 6) +#define GS_TRC_ID_standard_ProcessUtility GS_TRC_ID_PACK(COMP_TCOP, 7) +#define GS_TRC_ID_UtilityReturnsTuples GS_TRC_ID_PACK(COMP_TCOP, 8) +#define GS_TRC_ID_UtilityTupleDescriptor GS_TRC_ID_PACK(COMP_TCOP, 9) +#define GS_TRC_ID_UtilityContainsQuery GS_TRC_ID_PACK(COMP_TCOP, 10) +#define GS_TRC_ID_CreateCommandTag GS_TRC_ID_PACK(COMP_TCOP, 11) +#define GS_TRC_ID_GetCommandLogLevel GS_TRC_ID_PACK(COMP_TCOP, 12) +#define GS_TRC_ID_CommandIsReadOnly GS_TRC_ID_PACK(COMP_TCOP, 13) +#define GS_TRC_ID_CheckRelationOwnership GS_TRC_ID_PACK(COMP_TCOP, 14) +#define GS_TRC_ID_pg_parse_query GS_TRC_ID_PACK(COMP_TCOP, 15) +#define GS_TRC_ID_pg_analyze_and_rewrite GS_TRC_ID_PACK(COMP_TCOP, 16) +#define GS_TRC_ID_pg_analyze_and_rewrite_params GS_TRC_ID_PACK(COMP_TCOP, 17) +#define GS_TRC_ID_pg_plan_query GS_TRC_ID_PACK(COMP_TCOP, 18) +#define GS_TRC_ID_pg_plan_queries GS_TRC_ID_PACK(COMP_TCOP, 19) +#define GS_TRC_ID_check_max_stack_depth GS_TRC_ID_PACK(COMP_TCOP, 20) +#define GS_TRC_ID_assign_max_stack_depth GS_TRC_ID_PACK(COMP_TCOP, 21) +#define GS_TRC_ID_die GS_TRC_ID_PACK(COMP_TCOP, 22) +#define GS_TRC_ID_quickdie GS_TRC_ID_PACK(COMP_TCOP, 23) +#define GS_TRC_ID_StatementCancelHandler GS_TRC_ID_PACK(COMP_TCOP, 24) +#define GS_TRC_ID_FloatExceptionHandler GS_TRC_ID_PACK(COMP_TCOP, 25) +#define GS_TRC_ID_RecoveryConflictInterrupt GS_TRC_ID_PACK(COMP_TCOP, 26) +#define GS_TRC_ID_prepare_for_client_read GS_TRC_ID_PACK(COMP_TCOP, 27) +#define GS_TRC_ID_client_read_ended GS_TRC_ID_PACK(COMP_TCOP, 28) +#define GS_TRC_ID_prepare_for_logic_conn_read GS_TRC_ID_PACK(COMP_TCOP, 29) +#define GS_TRC_ID_logic_conn_read_check_ended GS_TRC_ID_PACK(COMP_TCOP, 30) +#define GS_TRC_ID_process_postgres_switches GS_TRC_ID_PACK(COMP_TCOP, 31) +#define GS_TRC_ID_PostgresMain GS_TRC_ID_PACK(COMP_TCOP, 32) +#define GS_TRC_ID_StreamMain GS_TRC_ID_PACK(COMP_TCOP, 33) +#define GS_TRC_ID_get_stack_depth_rlimit GS_TRC_ID_PACK(COMP_TCOP, 34) +#define GS_TRC_ID_ResetUsage GS_TRC_ID_PACK(COMP_TCOP, 35) +#define GS_TRC_ID_ShowUsage GS_TRC_ID_PACK(COMP_TCOP, 36) +#define GS_TRC_ID_check_log_duration GS_TRC_ID_PACK(COMP_TCOP, 37) +#define GS_TRC_ID_set_debug_options GS_TRC_ID_PACK(COMP_TCOP, 38) +#define GS_TRC_ID_set_plan_disabling_options GS_TRC_ID_PACK(COMP_TCOP, 39) +#define GS_TRC_ID_get_stats_option_name GS_TRC_ID_PACK(COMP_TCOP, 40) +#define GS_TRC_ID_exec_parse_message GS_TRC_ID_PACK(COMP_TCOP, 41) +#define GS_TRC_ID_exec_bind_message GS_TRC_ID_PACK(COMP_TCOP, 42) +#define GS_TRC_ID_exec_execute_message GS_TRC_ID_PACK(COMP_TCOP, 43) +#define GS_TRC_ID_PortalStart GS_TRC_ID_PACK(COMP_TCOP, 44) +#define GS_TRC_ID_PortalRun GS_TRC_ID_PACK(COMP_TCOP, 45) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/tsearch_gstrace.h postgresql-hll-2.14/include/include/gstrace/tsearch_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/tsearch_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/tsearch_gstrace.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,14 @@ +// This is a generated file + +#ifndef _TSEARCH_GSTRACE_H +#define _TSEARCH_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_init_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 1) +#define GS_TRC_ID_reset_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 2) +#define GS_TRC_ID_gettoken_tsvector GS_TRC_ID_PACK(COMP_TSEARCH, 3) +#define GS_TRC_ID_close_tsvector_parser GS_TRC_ID_PACK(COMP_TSEARCH, 4) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/utils_gstrace.h postgresql-hll-2.14/include/include/gstrace/utils_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/utils_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/utils_gstrace.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,133 @@ +// This is a generated file + +#ifndef _UTILS_GSTRACE_H +#define _UTILS_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_has_any_column_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 1) +#define GS_TRC_ID_has_any_column_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 2) +#define GS_TRC_ID_has_any_column_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 3) +#define GS_TRC_ID_has_any_column_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 4) +#define GS_TRC_ID_has_any_column_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 5) +#define GS_TRC_ID_has_any_column_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 6) +#define GS_TRC_ID_has_column_privilege_name_name_name GS_TRC_ID_PACK(COMP_UTILS, 7) +#define GS_TRC_ID_has_column_privilege_name_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 8) +#define GS_TRC_ID_has_column_privilege_name_id_name GS_TRC_ID_PACK(COMP_UTILS, 9) +#define GS_TRC_ID_has_column_privilege_name_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 10) +#define GS_TRC_ID_has_column_privilege_id_name_name GS_TRC_ID_PACK(COMP_UTILS, 11) +#define GS_TRC_ID_has_column_privilege_id_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 12) +#define GS_TRC_ID_has_column_privilege_id_id_name GS_TRC_ID_PACK(COMP_UTILS, 13) +#define GS_TRC_ID_has_column_privilege_id_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 14) +#define GS_TRC_ID_has_column_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 15) +#define GS_TRC_ID_has_column_privilege_name_attnum GS_TRC_ID_PACK(COMP_UTILS, 16) +#define GS_TRC_ID_has_column_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 17) +#define GS_TRC_ID_has_column_privilege_id_attnum GS_TRC_ID_PACK(COMP_UTILS, 18) +#define GS_TRC_ID_has_table_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 19) +#define GS_TRC_ID_has_table_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 20) +#define GS_TRC_ID_has_table_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 21) +#define GS_TRC_ID_has_table_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 22) +#define GS_TRC_ID_has_table_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 23) +#define GS_TRC_ID_has_table_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 24) +#define GS_TRC_ID_has_sequence_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 25) +#define GS_TRC_ID_has_sequence_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 26) +#define GS_TRC_ID_has_sequence_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 27) +#define GS_TRC_ID_has_sequence_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 28) +#define GS_TRC_ID_has_sequence_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 29) +#define GS_TRC_ID_has_sequence_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 30) +#define GS_TRC_ID_has_database_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 31) +#define GS_TRC_ID_has_database_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 32) +#define GS_TRC_ID_has_database_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 33) +#define GS_TRC_ID_has_database_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 34) +#define GS_TRC_ID_has_database_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 35) +#define GS_TRC_ID_has_database_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 36) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 37) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 38) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 39) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 40) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 41) +#define GS_TRC_ID_has_foreign_data_wrapper_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 42) +#define GS_TRC_ID_has_function_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 43) +#define GS_TRC_ID_has_function_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 44) +#define GS_TRC_ID_has_function_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 45) +#define GS_TRC_ID_has_function_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 46) +#define GS_TRC_ID_has_function_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 47) +#define GS_TRC_ID_has_function_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 48) +#define GS_TRC_ID_has_language_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 49) +#define GS_TRC_ID_has_language_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 50) +#define GS_TRC_ID_has_language_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 51) +#define GS_TRC_ID_has_language_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 52) +#define GS_TRC_ID_has_language_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 53) +#define GS_TRC_ID_has_language_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 54) +#define GS_TRC_ID_has_nodegroup_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 55) +#define GS_TRC_ID_has_nodegroup_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 56) +#define GS_TRC_ID_has_nodegroup_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 57) +#define GS_TRC_ID_has_nodegroup_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 58) +#define GS_TRC_ID_has_nodegroup_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 59) +#define GS_TRC_ID_has_nodegroup_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 60) +#define GS_TRC_ID_has_schema_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 61) +#define GS_TRC_ID_has_schema_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 62) +#define GS_TRC_ID_has_schema_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 63) +#define GS_TRC_ID_has_schema_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 64) +#define GS_TRC_ID_has_schema_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 65) +#define GS_TRC_ID_has_schema_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 66) +#define GS_TRC_ID_has_server_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 67) +#define GS_TRC_ID_has_server_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 68) +#define GS_TRC_ID_has_server_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 69) +#define GS_TRC_ID_has_server_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 70) +#define GS_TRC_ID_has_server_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 71) +#define GS_TRC_ID_has_server_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 72) +#define GS_TRC_ID_has_tablespace_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 73) +#define GS_TRC_ID_has_tablespace_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 74) +#define GS_TRC_ID_has_tablespace_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 75) +#define GS_TRC_ID_has_tablespace_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 76) +#define GS_TRC_ID_has_tablespace_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 77) +#define GS_TRC_ID_has_tablespace_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 78) +#define GS_TRC_ID_has_type_privilege_name_name GS_TRC_ID_PACK(COMP_UTILS, 79) +#define GS_TRC_ID_has_type_privilege_name_id GS_TRC_ID_PACK(COMP_UTILS, 80) +#define GS_TRC_ID_has_type_privilege_id_name GS_TRC_ID_PACK(COMP_UTILS, 81) +#define GS_TRC_ID_has_type_privilege_id_id GS_TRC_ID_PACK(COMP_UTILS, 82) +#define GS_TRC_ID_has_type_privilege_name GS_TRC_ID_PACK(COMP_UTILS, 83) +#define GS_TRC_ID_has_type_privilege_id GS_TRC_ID_PACK(COMP_UTILS, 84) +#define GS_TRC_ID_pg_has_role_name_name GS_TRC_ID_PACK(COMP_UTILS, 85) +#define GS_TRC_ID_pg_has_role_name_id GS_TRC_ID_PACK(COMP_UTILS, 86) +#define GS_TRC_ID_pg_has_role_id_name GS_TRC_ID_PACK(COMP_UTILS, 87) +#define GS_TRC_ID_pg_has_role_id_id GS_TRC_ID_PACK(COMP_UTILS, 88) +#define GS_TRC_ID_pg_has_role_name GS_TRC_ID_PACK(COMP_UTILS, 89) +#define GS_TRC_ID_pg_has_role_id GS_TRC_ID_PACK(COMP_UTILS, 90) +#define GS_TRC_ID_GetConfigOption GS_TRC_ID_PACK(COMP_UTILS, 91) +#define GS_TRC_ID_GetConfigOptionResetString GS_TRC_ID_PACK(COMP_UTILS, 92) +#define GS_TRC_ID_ProcessConfigFile GS_TRC_ID_PACK(COMP_UTILS, 93) +#define GS_TRC_ID_InitializeGUCOptions GS_TRC_ID_PACK(COMP_UTILS, 94) +#define GS_TRC_ID_init_sync_guc_variables GS_TRC_ID_PACK(COMP_UTILS, 95) +#define GS_TRC_ID_repair_guc_variables GS_TRC_ID_PACK(COMP_UTILS, 96) +#define GS_TRC_ID_SelectConfigFiles GS_TRC_ID_PACK(COMP_UTILS, 97) +#define GS_TRC_ID_ResetAllOptions GS_TRC_ID_PACK(COMP_UTILS, 98) +#define GS_TRC_ID_AtStart_GUC GS_TRC_ID_PACK(COMP_UTILS, 99) +#define GS_TRC_ID_NewGUCNestLevel GS_TRC_ID_PACK(COMP_UTILS, 100) +#define GS_TRC_ID_AtEOXact_GUC GS_TRC_ID_PACK(COMP_UTILS, 101) +#define GS_TRC_ID_BeginReportingGUCOptions GS_TRC_ID_PACK(COMP_UTILS, 102) +#define GS_TRC_ID_ParseLongOption GS_TRC_ID_PACK(COMP_UTILS, 103) +#define GS_TRC_ID_set_config_option GS_TRC_ID_PACK(COMP_UTILS, 104) +#define GS_TRC_ID_GetConfigOptionByName GS_TRC_ID_PACK(COMP_UTILS, 105) +#define GS_TRC_ID_GetConfigOptionByNum GS_TRC_ID_PACK(COMP_UTILS, 106) +#define GS_TRC_ID_GetNumConfigOptions GS_TRC_ID_PACK(COMP_UTILS, 107) +#define GS_TRC_ID_SetPGVariable GS_TRC_ID_PACK(COMP_UTILS, 108) +#define GS_TRC_ID_GetPGVariable GS_TRC_ID_PACK(COMP_UTILS, 109) +#define GS_TRC_ID_GetPGVariableResultDesc GS_TRC_ID_PACK(COMP_UTILS, 110) +#define GS_TRC_ID_RewriteBeginQuery GS_TRC_ID_PACK(COMP_UTILS, 111) +#define GS_TRC_ID_ExecSetVariableStmt GS_TRC_ID_PACK(COMP_UTILS, 112) +#define GS_TRC_ID_ExtractSetVariableArgs GS_TRC_ID_PACK(COMP_UTILS, 113) +#define GS_TRC_ID_RelationIdGetRelation GS_TRC_ID_PACK(COMP_UTILS, 114) +#define GS_TRC_ID_RelationClose GS_TRC_ID_PACK(COMP_UTILS, 115) +#define GS_TRC_ID_PartitionGetPartIndexList GS_TRC_ID_PACK(COMP_UTILS, 116) +#define GS_TRC_ID_RelationGetIndexList GS_TRC_ID_PACK(COMP_UTILS, 117) +#define GS_TRC_ID_RelationGetIndexNum GS_TRC_ID_PACK(COMP_UTILS, 118) +#define GS_TRC_ID_RelationGetOidIndex GS_TRC_ID_PACK(COMP_UTILS, 119) +#define GS_TRC_ID_RelationGetIndexExpressions GS_TRC_ID_PACK(COMP_UTILS, 120) +#define GS_TRC_ID_RelationGetIndexPredicate GS_TRC_ID_PACK(COMP_UTILS, 121) +#define GS_TRC_ID_RelationGetIndexAttrBitmap GS_TRC_ID_PACK(COMP_UTILS, 122) +#define GS_TRC_ID_RelationGetExclusionInfo GS_TRC_ID_PACK(COMP_UTILS, 123) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/vecexecutor_gstrace.h postgresql-hll-2.14/include/include/gstrace/vecexecutor_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/vecexecutor_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/vecexecutor_gstrace.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,17 @@ +// This is a generated file + +#ifndef _VECEXECUTOR_GSTRACE_H +#define _VECEXECUTOR_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_VectorEngine GS_TRC_ID_PACK(COMP_VECEXECUTOR, 1) +#define GS_TRC_ID_ExecVecProject GS_TRC_ID_PACK(COMP_VECEXECUTOR, 2) +#define GS_TRC_ID_ExecInitVecExpr GS_TRC_ID_PACK(COMP_VECEXECUTOR, 3) +#define GS_TRC_ID_ExecAssignVecScanProjectionInfo GS_TRC_ID_PACK(COMP_VECEXECUTOR, 4) +#define GS_TRC_ID_ExecVecMarkPos GS_TRC_ID_PACK(COMP_VECEXECUTOR, 5) +#define GS_TRC_ID_ExecVecRestrPos GS_TRC_ID_PACK(COMP_VECEXECUTOR, 6) +#define GS_TRC_ID_VecExecReScan GS_TRC_ID_PACK(COMP_VECEXECUTOR, 7) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gstrace/wlm_gstrace.h postgresql-hll-2.14/include/include/gstrace/wlm_gstrace.h --- postgresql-hll-2.14_old/include/include/gstrace/wlm_gstrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gstrace/wlm_gstrace.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,11 @@ +// This is a generated file + +#ifndef _WLM_GSTRACE_H +#define _WLM_GSTRACE_H + +#include "comps.h" +#include "gstrace_infra.h" + +#define GS_TRC_ID_WLMIsSimpleQuery GS_TRC_ID_PACK(COMP_WLM, 1) + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_alarm.h postgresql-hll-2.14/include/include/gtm/gtm_alarm.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_alarm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_alarm.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,22 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_alarm.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_alarm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GTM_ALARM_H +#define GTM_ALARM_H + +extern bool enable_alarm; + +extern int GTMAddAlarmCheckerThread(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_atomic.h postgresql-hll-2.14/include/include/gtm/gtm_atomic.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_atomic.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,187 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_atomic.h + * + * + * + * IDENTIFICATION + * src/include/gtm/gtm_atomic.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ +#define CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ + +template +struct GTM_AtomicStride { + /* increment value when add it. */ + static const unsigned int unitSize = 1; +}; +template +struct GTM_AtomicStride { + /* increment value when add it. */ + static const unsigned int unitSize = sizeof(T); +}; + +/** + * atomic operations used in gtm + */ +template +class GTM_Atomic { +public: + /** + * Construct an GTM_Atomic use initial value + */ + explicit GTM_Atomic(const ValueType value = 0) : m_value(value) + { + } + ~GTM_Atomic(){}; + + /** + * atomic increment + */ + void add(int64_t increment) + { + __sync_fetch_and_add(&m_value, increment); + } + + /** + * atomic compare exchange + */ + ValueType compareExchange(ValueType tmpValue, ValueType newValue) + { + tmpValue = __sync_val_compare_and_swap(&m_value, tmpValue, newValue); + return tmpValue; + } + + /** + * atomic exchange + */ + ValueType exchange(ValueType newValue) + { + newValue = __sync_lock_test_and_set(&m_value, newValue); + return newValue; + } + + /** + * atomic increment + */ + void inc() + { + add(1); + } + + /** + * Return the current value. + */ + ValueType load() + { + return m_value; + } + + /** + * overload operator = + */ + GTM_Atomic& operator=(ValueType newValue) + { + store(newValue); + return *this; + } + + /** + * Return the current value. + */ + operator ValueType() + { + return load(); + } + + /** + * overload operator ++ + */ + const GTM_Atomic& operator++() + { + inc(); + return *this; + } + const GTM_Atomic operator++(int) + { + GTM_Atomic tmp = *this; + inc(); + return tmp; + } + + /** + * overload operator -- + */ + const GTM_Atomic& operator--() + { + add(-1); + return *this; + } + const GTM_Atomic operator--(int) + { + GTM_Atomic tmp = *this; + add(-1); + return tmp; + } + + /** + * set value + */ + void store(ValueType newValue) + { + m_value = newValue; + } + +protected: + /* The value on which the atomic operations operate. */ + volatile ValueType m_value; +}; + +/** + * This method provides appropriate fencing for the end of a critical + * section. It guarantees the following: + * - Loads coming from code preceding this method will complete before the + * method returns, so they will not see any changes made to memory by other + * threads after the method is invoked. + * - Stores coming from code preceding this method will be reflected + * in memory before the method returns, so when the next thread enters + * the critical section it is guaranteed to see any changes made in the + * current critical section. + */ +static inline void GTM_loadStoreFence() +{ +#ifdef __aarch64__ + + __asm__ __volatile__("DMB ish" ::: "memory"); +#else + __asm__ __volatile__("lfence" ::: "memory"); + __asm__ __volatile__("sfence" ::: "memory"); +#endif +} + +static inline void GTM_loadFence() +{ + __asm__ __volatile__("lfence" ::: "memory"); +} + +static inline void GTM_StoreFence() +{ + __asm__ __volatile__("sfence" ::: "memory"); +} +#endif /* CODE_SRC_INCLUDE_GTM_GTM_ATOMIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_auth.h postgresql-hll-2.14/include/include/gtm/gtm_auth.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_auth.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_auth.h + * GTM server authentication module. + * Variables and function commands used for handling authentication between gtm client and gtm server. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_auth.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GTM_AUTH_H +#define GTM_AUTH_H +#include "gtm/gtm_opt.h" + +/* Gtm guc parameter name */ +#define GTM_OPTNAME_AUTHENTICATION_TYPE "gtm_authentication_type" +#define GTM_OPTNAME_KRB_SERVER_KEYFILE "gtm_krb_server_keyfile" + +/* define gtm server autnentication method */ +#define GTM_AUTH_REJECT (0) +#define GTM_AUTH_TRUST (1) +#define GTM_AUTH_GSS (2) + +extern int gtm_auth_method; +extern char* gtm_krb_server_keyfile; +extern const struct config_enum_entry gtm_auth_options[]; + +extern bool CheckGtmKrbKeyFilePath(char** newval, void** extra, GtmOptSource source); +extern bool CheckGtmAuthMethod(int* newval, void** extra, GtmOptSource source); +extern void GtmPerformAuthentication(GTM_ThreadInfo* thrinfo); +extern void GtmAuthCleanup(); +#endif /* GTM_AUTH_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_backup.h postgresql-hll-2.14/include/include/gtm/gtm_backup.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_backup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_backup.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * gtm_backup.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2013 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_BACKUP_H +#define _GTM_BACKUP_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_seq.h" + +extern GTM_RWLock gtm_bkup_lock; +extern GTM_RWLock seq_bkup_lock; +extern uint32 GTMWorkingGrandVersionNum; + +#define SeqRestoreDuration 20000 + +extern void GTM_ReadRestorePoint(GlobalTransactionId next_gxid); +extern void GTM_ReadTimeLineAndTxactLen(GlobalTransactionId next_gxid); +extern void GTM_ReadRestoreSequence(void); +extern void GTM_WriteRestoreControlPoint(bool xid_restore); +extern void GTM_WriteRestoreSequencePoint(GTM_UUID* seq_id, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteRestorePoint(GTM_UUID* seq_id, bool xid_restore, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteControlFile(bool saveinfo, bool xid_restore); +extern void GTM_WriteSequenceFile(bool saveinfo, GTM_UUID* seq_uuid, bool all_seq_restore, bool uuid_restore); +extern void GTM_WriteXidToFile(bool saveinfo, bool xid_restore); +extern void GTM_MakeBackup(char* path); +extern void GTM_SetNeedBackup(void); +extern bool GTM_NeedBackup(void); +extern void GTM_SetXidAndTxnBackup(void); +extern void GTM_SetSequenceBackup(void); +extern bool GTM_SequenceBackup(void); +extern void GTM_WriteBarrierBackup(const char* barrier_id); + +#endif /* GTM_BACKUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_cgroup.h postgresql-hll-2.14/include/include/gtm/gtm_cgroup.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_cgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_cgroup.h 2020-12-12 17:06:43.201347445 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_cgroup.h + * get the gaussdb cgroup relpath and initialize cgroup. + * Please note,caller should free the return value. + * + * IDENTIFICATION + * src/include/gtm/gtm_cgroup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_GTM_GTM_CGROUP_H +#define SRC_INCLUDE_GTM_GTM_CGROUP_H +extern char* gscgroup_gtm_init(); + +/* make the current thread attach to gaussdb cgroup */ +extern void gscgroup_gtm_attach_task(const char* relpath); +/* just an unused function, reserving this function for future. */ +extern void gscgroup_gtm_attach_task_pid(const char* relpath, pid_t tid); + +#endif // SRC_INCLUDE_GTM_GTM_CGROUP_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_c.h postgresql-hll-2.14/include/include/gtm/gtm_c.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_c.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,287 @@ +/* ------------------------------------------------------------------------- + * + * gtm_c.h + * Fundamental C definitions. This is included by every .c file in + * PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate). + * + * Note that the definitions here are not intended to be exposed to clients + * of the frontend interface libraries --- so we don't worry much about + * polluting the namespace with lots of stuff... + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/c.h,v 1.234 2009/01/01 17:23:55 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_C_H +#define GTM_C_H + +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include +#endif +#include + +#include +#include +#include "c.h" +#include "cm/etcdapi.h" + +typedef uint64 GlobalTransactionId; /* 64-bit global transaction ids */ +typedef int16 GTMProxy_ConnID; +typedef uint32 GTM_StrLen; + +#define InvalidGTMProxyConnID -1 + +typedef pthread_t GTM_ThreadID; + +typedef uint32 GTM_PGXCNodeId; +typedef uint32 GTM_PGXCNodePort; + +/* Possible type of nodes for registration */ +typedef enum GTM_PGXCNodeType { + GTM_NODE_ALL = 0, /* For pgxcnode_find_by_type, pass this value means to get all type node */ + GTM_NODE_GTM_PROXY = 1, + GTM_NODE_GTM_PROXY_POSTMASTER = 2, + /* Used by Proxy to communicate with GTM and not use Proxy headers */ + GTM_NODE_COORDINATOR = 3, + GTM_NODE_DATANODE = 4, + GTM_NODE_GTM_PRIMARY = 5, + GTM_NODE_GTM_STANDBY = 6, + GTM_NODE_GTM_CLIENT = 7, + GTM_NODE_DEFAULT = 8 /* In case nothing is associated to connection */ +} GTM_PGXCNodeType; + +typedef enum GTM_SnapshotType { + GTM_SNAPSHOT_TYPE_UNDEFINED, + GTM_SNAPSHOT_TYPE_LOCAL, + GTM_SNAPSHOT_TYPE_GLOBAL, + GTM_SNAPSHOT_TYPE_AUTOVACUUM +} GTM_SnapshotType; + +/* + * A unique handle to identify transaction at the GTM. It could just be + * an index in an array or a pointer to the structure + * + * Note: If we get rid of BEGIN transaction at the GTM, we can use GXID + * as a handle because we would never have a transaction state at the + * GTM without assigned GXID. + */ +typedef int32 GTM_TransactionHandle; +typedef uint32 GTM_Timeline; + +/* GTM_TransactionKey used to identify a transaction + * it is composed by handle and timeline + */ +typedef struct GTM_TransactionKey { + GTM_TransactionHandle txnHandle; /* txn handle in GTM */ + GTM_Timeline txnTimeline; /* txn timeline in GTM */ +} GTM_TransactionKey; + +typedef struct GTM_TransactionKey GTM_TransactionKey; + +extern GTM_Timeline gtmTimeline; +extern uint32 gtmTransactionsLenWhenExit; +extern bool write_fake_TransLen; + +extern uint32 snapshot_num; +extern uint32 snapshot_num_now; +extern uint64 snapshot_totalsize; +extern uint64 snapshot_totalsize_now; +extern uint32 MaxNumThreadActive; + +#define InvalidTransactionHandle -1 +#define InvalidTransactionTimeline 0 + +#define GlobalTransactionHandleIsValid(handle) (((GTM_TransactionHandle)(handle)) != InvalidTransactionHandle) +#define GlobalTransactionTimelineIsValid(timeline) (((GTM_Timeline)(timeline)) != InvalidTransactionTimeline) + +/* + * As GTM and Postgres-XC packages are separated, GTM and XC's API + * use different type names for timestamps and sequences, but they have to be the same! + */ +typedef int64 GTM_Timestamp; /* timestamp data is 64-bit based */ + +typedef int64 GTM_Sequence; /* a 64-bit sequence */ + +typedef int64 GTM_UUID; /* a 64-bit UUID */ + +extern EtcdSession g_etcdSession; + +/* Type of sequence name used when dropping it */ +typedef enum GTM_SequenceKeyType { + GTM_SEQ_FULL_NAME, /* Full sequence key */ + GTM_SEQ_DB_NAME, /* DB name part of sequence key */ + GTM_SEQ_DB_SCHEMA_NAME /* Part of sequence key: dbname.schemaname */ +} GTM_SequenceKeyType; + +typedef struct GTM_SequenceKeyData { + uint32 gsk_keylen; + char* gsk_key; + GTM_SequenceKeyType gsk_type; /* see constants below */ +} GTM_SequenceKeyData; /* Counter key, set by the client */ + +typedef GTM_SequenceKeyData* GTM_SequenceKey; + +typedef struct GTM_DBNameData { + uint32 gsd_dblen; + char* gsd_db; +} GTM_DBNameData; /* database that sequence belongs to */ + +typedef GTM_DBNameData* GTM_DBName; + +#define GTM_MAX_SEQKEY_LENGTH 1024 + +#define InvalidSequenceValue 0x7fffffffffffffffLL +#define SEQVAL_IS_VALID(v) ((v) != InvalidSequenceValue) + +#define MaxSequenceValue 0x7fffffffffffffffLL +#define InvalidUUID ((GTM_UUID)0) +#define InitialUUIDValue_Default ((GTM_UUID)1000000) +#define MaxSequenceUUID 0x7fffffffffffffffLL + +#define GTM_MAX_GLOBAL_TRANSACTIONS 16384 + +#define GTM_MAX_ERROR_LENGTH 1024 + +#define GTM_HOST_FLAG_BASE 100 +#define HOST2FLAG(h) ((uint32)((h) + GTM_HOST_FLAG_BASE)) +#define FLAG2HOST(f) ((GtmHostIndex)((f) - GTM_HOST_FLAG_BASE)) + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) do { \ + if (NULL != (ptr)) { \ + pfree(ptr); \ + (ptr) = NULL; \ + } \ +} while (0) +#endif + +typedef enum GTM_IsolationLevel { + GTM_ISOLATION_SERIALIZABLE, /* serializable txn */ + GTM_ISOLATION_RC /* read-committed txn */ +} GTM_IsolationLevel; + +typedef struct GTM_SnapshotData { + GlobalTransactionId sn_xmin; + GlobalTransactionId sn_xmax; + GlobalTransactionId sn_recent_global_xmin; + uint64 csn; +} GTM_SnapshotData; + +typedef GTM_SnapshotData* GTM_Snapshot; + +typedef struct GTM_SnapshotStatusData { + GlobalTransactionId xmin; + GlobalTransactionId xmax; + uint64 csn; + GlobalTransactionId recent_global_xmin; + GlobalTransactionId next_xid; + GTM_Timeline timeline; + uint32 active_thread_num; + uint32 max_thread_num; + uint32 snapshot_num; + Size snapshot_totalsize; +} GTM_SnapshotStatusData; + +typedef GTM_SnapshotStatusData* GTM_SnapshotStatus; + +/* A struct providing some info of gtm for views */ +typedef struct GTMLite_StatusData { + GlobalTransactionId backup_xid; + uint64 csn; +} GTMLite_StatusData; + +typedef GTMLite_StatusData* GTMLite_Status; + +/* Define max size of node name in start up packet */ +#define SP_NODE_NAME 64 + +typedef struct GTM_StartupPacket { + char sp_node_name[SP_NODE_NAME]; + GTM_PGXCNodeType sp_remotetype; + bool sp_ispostmaster; + pthread_t sp_remote_thdpid; +} GTM_StartupPacket; + +typedef enum GTM_PortLastCall { + GTM_LastCall_NONE = 0, + GTM_LastCall_SEND, + GTM_LastCall_RECV, + GTM_LastCall_READ, + GTM_LastCall_WRITE +} GTM_PortLastCall; + +#define InvalidGlobalTransactionId ((GlobalTransactionId)0) + +typedef enum GTMServerMode { + GTMServer_Unknown = 0, + GTMServer_PrimaryMode, + GTMServer_StandbyMode, + GTMServer_PendingMode +} GTMServerMode; + +typedef enum GTMConnectionStatus { + GTMConnection_Unknown = 0, + GTMConnection_bad, + GTMConnection_ok +} GTMConnectionStatus; + +typedef enum GTMSyncStatus { + GTMSync_Unknown = 0, + GTMSync_PrimaryMode, + GTMSync_StandbyMode +} GTMSyncStatus; + +typedef struct tagGtmHostIP { + char acHostIP[128]; +} GTM_HOST_IP; + +/* ---------- + * GTM connection states + * + * Traditionally, gtm_host_0 stands for primary while + * gtm_host_1 stands for (promoted) standby. + * ---------- + */ +typedef enum GtmHostIndex { + GTM_HOST_INVAILD = 0, + GTM_HOST_0, + GTM_HOST_1, + GTM_HOST_2, + GTM_HOST_3, + GTM_HOST_4, + GTM_HOST_5, + GTM_HOST_6, + GTM_HOST_7, +} GtmHostIndex; + +extern int gtm_max_trans; + +extern int gtm_num_threads; + +/* + * Initial GXID value to start with, when -x option is not specified at the first run. + * + * This value is supposed to be safe enough. If initdb involves huge amount of initial + * statements/transactions, users should consider to tweak this value with explicit + * -x option. + */ +#define InitialGXIDValue_Default ((GlobalTransactionId)10000) + +#define GlobalTransactionIdIsValid(gxid) (((GlobalTransactionId)(gxid)) != InvalidGlobalTransactionId) + +#ifdef ENABLE_UT +extern void GTM_CopySnapshot(GTM_Snapshot dst, GTM_Snapshot src); +#endif + +extern const char *transfer_snapshot_type(GTM_SnapshotType gtm_snap_type); +#endif /* GTM_C_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_client.h postgresql-hll-2.14/include/include/gtm/gtm_client.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_client.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,337 @@ +/* ------------------------------------------------------------------------- + * + * gtm_client.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_CLIENT_H +#define GTM_CLIENT_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_seq.h" +#include "gtm/gtm_txn.h" +#include "gtm/gtm_msg.h" +#include "gtm/utils/register.h" +#include "gtm/utils/libpq-fe.h" + +/* DFX: client error code for connecting to GTM */ +typedef enum GTMClientErrCode { + GTMC_OK = 0, + GTMC_SEND_ERROR, + GTMC_RECV_ERROR +} GTMClientErrCode; + +typedef enum GTM_CONN_ERR { + GTM_OK, + GTM_UNCONNECTED = 0xE, + GTM_START_ERROR, + GTM_SEND_ERROR, + GTM_SEND_END_ERROR, + GTM_FLUSH_ERROR, + GTM_RECEIVE_ERROR, +} GTM_CONN_ERR_T; + +typedef union GTM_ResultData { + GTM_TransactionHandle grd_txnhandle; /* TXN_BEGIN */ + + struct { + GlobalTransactionId gxid; + GTM_Timestamp timestamp; + } grd_gxid_tp; /* TXN_BEGIN_GETGXID */ + + GlobalTransactionId grd_gxid; /* TXN_PREPARE + * TXN_START_PREPARED + * TXN_GET_GLOBAL_XMIN_RESULT + */ + struct { + GlobalTransactionId gxid; + int status; + } grd_txn_rc; /* + * TXN_COMMIT + * TXN_COMMIT_PREPARED + * TXN_ROLLBACK + */ + + GlobalTransactionId grd_next_gxid; + + struct { + GTM_TransactionHandle txnhandle; + GlobalTransactionId gxid; + } grd_txn; /* TXN_GET_GXID */ + + GTM_SequenceKeyData grd_seqkey; /* SEQUENCE_INIT + * SEQUENCE_RESET + * SEQUENCE_CLOSE */ + + GTM_DBNameData grd_seqdb; /* SEQUENCE_RENAME */ + + struct { + GTM_UUID seq_uuid; + } grd_uuid; /* SEQUENCE_GET_UUID */ + + struct { + GTM_UUID seq_uuid; + GTM_Sequence seqval; + GTM_Sequence rangemax; + } grd_seq; /* SEQUENCE_GET_NEXT */ + + struct { + int seq_count; + GTM_SeqInfo* seq; + } grd_seq_list; /* SEQUENCE_GET_LIST */ + + struct { + int txn_count; /* TXN_BEGIN_GETGXID_MULTI */ + GlobalTransactionId start_gxid; + GTM_Timestamp timestamp; + } grd_txn_get_multi; + + struct { + int txn_count; /* TXN_COMMIT_MULTI */ + int status[GTM_MAX_GLOBAL_TRANSACTIONS]; + } grd_txn_rc_multi; + + struct { + GTM_TransactionHandle txnhandle; /* SNAPSHOT_GXID_GET */ + GlobalTransactionId gxid; /* SNAPSHOT_GET */ + int txn_count; /* SNAPSHOT_GET_MULTI */ + int status[GTM_MAX_GLOBAL_TRANSACTIONS]; + } grd_txn_snap_multi; + + struct { + GlobalTransactionId gxid; + GlobalTransactionId prepared_gxid; + int nodelen; + char* nodestring; + } grd_txn_get_gid_data; /* TXN_GET_GID_DATA_RESULT */ + + struct { + char* ptr; + size_t len; + } grd_txn_gid_list; /* TXN_GXID_LIST_RESULT */ + + struct { + GTM_PGXCNodeType type; /* NODE_REGISTER */ + size_t len; + char* node_name; /* NODE_UNREGISTER */ + } grd_node; + + struct { + int num_node; + GTM_PGXCNodeInfo* nodeinfo[MAX_NODES]; + } grd_node_list; + + struct { + int server_mode; + int connection_status; + GlobalTransactionId xid; + long send_count; + long receive_count; + int sync_mode; + } grd_query_gtm_status; /*MSG_QUREY_GTM_STATUS*/ + + int grd_gtm_sync_mode_result; + + int32 grd_check_standby_role_result; /*MSG_CHECK_STANDBY_ROLE*/ + + int32 grd_sync_file_result; /*MSG_SYNC_FILE*/ + + int32 grd_check_next_gxid_result; /*MSG_SYNC_FILE*/ + + struct { + int max_server_memory; + double query_memory_limit; + } grd_workload_manager_init_result; /*MSG_TXN_WORKLOAD_INIT*/ + + int32 grd_create_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_CREATE*/ + int32 grd_update_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_UPDATE*/ + int32 grd_delete_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_DELETE*/ + int32 grd_init_resource_pool_result; /*MSG_WLM_RESOURCEPOOL_INIT*/ + + struct { + int32 length; + char* result; + } gtm_hotpatch_result; + /* + * TXN_GET_STATUS + * TXN_GET_ALL_PREPARED + */ +} GTM_ResultData; + +#define GTM_RESULT_COMM_ERROR (-2) /* Communication error */ +#define GTM_RESULT_ERROR (-1) +#define GTM_RESULT_OK (0) +/* + * This error is used ion the case where allocated buffer is not large + * enough to store the errors. It may happen of an allocation failed + * so it's status is considered as unknown. + */ +#define GTM_RESULT_UNKNOWN (1) + +typedef struct GTM_Result { + GTM_ResultType gr_type; + int gr_msglen; + int gr_status; + GTM_ProxyMsgHeader gr_proxyhdr; + GTM_ResultData gr_resdata; + GTM_Timeline gr_timeline; /*GTM start status, now mean restart times*/ + uint64 csn; /* snapshot csn or commit csn */ + /* + * We keep these two items outside the union to avoid repeated malloc/free + * of the xip array. If these items are pushed inside the union, they may + * get overwritten by other members in the union + */ + int gr_xip_size; + GTM_SnapshotData gr_snapshot; + GTM_SnapshotStatusData gr_snapshot_status; + GTMLite_StatusData gr_gtm_lite_status; + + /* + * Similarly, keep the buffer for proxying data outside the union + */ + char* gr_proxy_data; + int gr_proxy_datalen; +} GTM_Result; + +/* + * Connection Management API + */ +GTM_Conn* connect_gtm(const char* connect_string); + +int get_node_list(GTM_Conn*, GTM_PGXCNodeInfo*, size_t); +GlobalTransactionId get_next_gxid(GTM_Conn*); +CommitSeqNo get_next_csn(GTM_Conn* conn, bool is_gtm_lite); +TransactionId get_global_xmin(GTM_Conn* conn); +GTM_Timeline get_gtm_timeline(GTM_Conn* conn); +int32 get_txn_gxid_list(GTM_Conn*, GTM_Transactions*); +int get_sequence_list(GTM_Conn*, GTM_SeqInfo**); + +/* + * Transaction Management API + */ +int reset_gtm_handle_xmin(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_TransactionKey txnKey); +int set_gtm_vaccum_flag(GTM_Conn* conn, bool is_vaccum, GTM_TransactionKey txnKey); +GTM_TransactionKey begin_transaction(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_Timestamp* timestamp); +GlobalTransactionId begin_get_gxid(GTM_Conn* conn, GTM_TransactionKey txn, bool is_sub_xact, GTMClientErrCode* err); + +GlobalTransactionId begin_transaction_gxid(GTM_Conn* conn, GTM_IsolationLevel isolevel, GTM_Timestamp* timestamp); + +int bkup_gtm_control_file_gxid(GTM_Conn* conn, GlobalTransactionId gxid); +int bkup_gtm_control_file_timeline(GTM_Conn* conn, GTM_Timeline timeline); + +GlobalTransactionId begin_transaction_autovacuum(GTM_Conn* conn, GTM_IsolationLevel isolevel); + +int commit_transaction(GTM_Conn *conn, GlobalTransactionId gxid, GlobalTransactionId *childXids, int nChildXids, + uint64 *commit_csn = NULL); +int commit_transaction_handle(GTM_Conn *conn, GTM_TransactionKey txnKey, GlobalTransactionId *gxid, bool is_backup, + uint64 *commit_csn); +int bkup_commit_transaction(GTM_Conn *conn, GlobalTransactionId gxid); + +int commit_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); +int bkup_commit_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId prepared_gxid); +int abort_transaction(GTM_Conn* conn, GlobalTransactionId gxid, GlobalTransactionId* childXids, int nChildXids); +int abort_transaction_handle(GTM_Conn* conn, GTM_TransactionKey txnKey, GlobalTransactionId* gxid, bool is_backup); +int bkup_abort_transaction(GTM_Conn* conn, GlobalTransactionId gxid); + +int start_prepared_transaction(GTM_Conn* conn, GlobalTransactionId gxid, const char* gid, const char* nodestring); +int prepare_transaction(GTM_Conn* conn, GlobalTransactionId gxid); +int bkup_prepare_transaction(GTM_Conn* conn, GlobalTransactionId gxid); +int get_gid_data(GTM_Conn* conn, GTM_IsolationLevel isolevel, const char* gid, GlobalTransactionId* gxid, + GlobalTransactionId* prepared_gxid, char** nodestring); + +/* + * Snapshot Management API + */ +GTM_SnapshotData *get_snapshot(GTM_Conn *conn, GTM_TransactionKey txnKey, GlobalTransactionId gxid, bool canbe_grouped, + bool is_vacuum); +GTM_SnapshotData *get_snapshot_gtm_lite(GTM_Conn *conn); +GTMLite_StatusData *get_status_gtm_lite(GTM_Conn *conn); + + +GTM_SnapshotStatusData* get_snapshot_status(GTM_Conn* conn, GTM_TransactionKey key); + +/* + * Node Registering management API + */ +int node_register(GTM_Conn *conn, GTM_PGXCNodeType type, GTM_PGXCNodePort port, char *node_name, char *datafolder, + uint32 timeline); + +int node_register_internal(GTM_Conn* conn, GTM_PGXCNodeType type, const char* host, GTM_PGXCNodePort port, + const char* node_name, const char* datafolder, GTM_PGXCNodeStatus status); +int bkup_node_register_internal(GTM_Conn* conn, GTM_PGXCNodeType type, const char* host, GTM_PGXCNodePort port, + const char* node_name, const char* datafolder, GTM_PGXCNodeStatus status); +int node_unregister(GTM_Conn* conn, GTM_PGXCNodeType type, const char* node_name); +int bkup_node_unregister(GTM_Conn* conn, GTM_PGXCNodeType type, const char* node_name); +int backend_disconnect(GTM_Conn* conn, bool is_postmaster, GTM_PGXCNodeType type, const char* node_name); + +/* + * Sequence Management API + */ +GTM_UUID get_next_sequuid(GTM_Conn* conn); +int get_uuid(GTM_Conn* conn, GTM_UUID* result, GTMClientErrCode* err); +int bkup_seq_uuid(GTM_Conn* conn, GTM_UUID seq_uuid); + +int open_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, GTMClientErrCode *err = NULL); +int bkup_open_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, + GTMClientErrCode *err); +int alter_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +int bkup_alter_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart); +int close_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int bkup_close_sequence(GTM_Conn *conn, GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int rename_sequence(GTM_Conn *conn, GTM_DBName dbName, GTM_DBName newdbName); +int bkup_rename_sequence(GTM_Conn *conn, GTM_DBName dbName, GTM_DBName newdbName); + +int get_next(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence* result, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence range, GTM_Sequence* rangemax, bool cycle); +int bkup_get_next(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence* result, GTM_Sequence increment, GTM_Sequence minval, + GTM_Sequence maxval, GTM_Sequence range, GTM_Sequence* rangemax, bool cycle); +int set_val(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence nextval, bool is_called); +int bkup_set_val(GTM_Conn* conn, GTM_UUID seq_uuid, GTM_Sequence nextval, GTM_Sequence range, bool is_called); +int reset_sequence(GTM_Conn* conn, GTM_UUID seq_uuid); +int bkup_reset_sequence(GTM_Conn* conn, GTM_UUID seq_uuid); + +/* + * Barrier + */ +int report_barrier(GTM_Conn* conn, const char* barier_id); +int bkup_report_barrier(GTM_Conn* conn, const char* barrier_id); + +/* + * GTM-Standby + */ +int set_begin_end_backup(GTM_Conn* conn, bool begin); +int gtm_sync_standby(GTM_Conn* conn, bool autosync); +int set_begin_end_switchover(GTM_Conn* conn, bool begin); +int gtm_check_remote_role(GTM_Conn* conn, int32 port, int32* result); +int sync_files_to_standby(GTM_Conn* conn, int filetype, const char* files, int len); + +/* + * * workload management API + * */ +int bkup_initialize_workload_manager(GTM_Conn* conn, int initServerMem); +int initialize_workload_manager(GTM_Conn* conn, int* max_server_memory, double* query_memory_limit); +int bkup_reserve_memory_wlm(GTM_Conn* conn, int memoryCost, const char*, int); +int reserve_memory_wlm(GTM_Conn* conn, int memoryCost, const char*, int); +int bkup_release_memory_wlm(GTM_Conn* conn, int memoryReserve, const char*, int); +int release_memory_wlm(GTM_Conn* conn, int memoryReserve, const char*, int); + +int CreateUpdateResourcePool(GTM_Conn* conn, bool create, char* rpName, int rpId, int memPercentage); +int DeleteResourcePool(GTM_Conn* conn, char* rpName, int rpId); +int InitResourcePool(GTM_Conn* conn, int rp_count, int buf_len, char* buf); + +/* Set parameter API */ +void set_gtm_client_rw_timeout(int timeout); +extern void process_for_gtm_connection_failed(GTM_Conn* conn); +extern THR_LOCAL bool need_reset_xmin; +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_conn.h postgresql-hll-2.14/include/include/gtm/gtm_conn.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_conn.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,43 @@ +/* ------------------------------------------------------------------------- + * + * gtm_conn.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_CONN_H +#define GTM_CONN_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/utils/libpq-fe.h" +#include "gtm/utils/libpq-int.h" + +struct GTM_ThreadInfo; + +typedef struct GTM_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + struct GTM_ThreadInfo* con_thrinfo; + bool con_authenticated; + + /* a connection object to the standby */ + GTM_Conn* standby; + + /* times of receiving illegal message */ + int illegal_message_count; +} GTM_ConnectionInfo; + +typedef struct GTM_Connections { + uint32 gc_conn_count; + uint32 gc_array_size; + GTM_ConnectionInfo* gc_connections; + GTM_RWLock gc_lock; +} GTM_Connections; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_csnsync.h postgresql-hll-2.14/include/include/gtm/gtm_csnsync.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_csnsync.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_csnsync.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_csnsync.h + * GTM csn sync thread head file. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_csnsync.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef GTM_CSNSYNC_H +#define GTM_CSNSYNC_H +extern int GTMAddCsnSyncThread(void); +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_dynahash.h postgresql-hll-2.14/include/include/gtm/gtm_dynahash.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_dynahash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_dynahash.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,122 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_dynahash.h + * POSTGRES dynahash.h file definitions + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_dynahash.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DYNAHASH_H +#define DYNAHASH_H + +#include "gtm_spinlock.h" +#include "gtm_hsearch.h" + +/* Number of freelists to be used for a partitioned hash table. */ +#define NUM_FREELISTS 32 + +/* A hash bucket is a linked list of HASHELEMENTs */ +typedef HASHELEMENT* HASHBUCKET; + +/* A hash segment is an array of bucket headers */ +typedef HASHBUCKET* HASHSEGMENT; + +/* + * Using array of FreeListData instead of separate arrays of mutexes, nentries + * and freeLists prevents, at least partially, sharing one cache line between + * different mutexes (see below). + */ +typedef struct { + slock_t mutex; /* spinlock */ + long nentries; /* number of entries */ + HASHELEMENT* freeList; /* list of free elements */ +} FreeListData; + +/* + * Header structure for a hash table --- contains all changeable info + * + * In a shared-memory hash table, the HASHHDR is in shared memory, while + * each backend has a local HTAB struct. For a non-shared table, there isn't + * any functional difference between HASHHDR and HTAB, but we separate them + * anyway to share code between shared and non-shared tables. + */ +struct HASHHDR { + /* + * The freelist can become a point of contention on high-concurrency hash + * tables, so we use an array of freelist, each with its own mutex and + * nentries count, instead of just a single one. + * + * If hash table is not partitioned only freeList[0] is used and spinlocks + * are not used at all. + */ + FreeListData freeList[NUM_FREELISTS]; + + /* These fields can change, but not in a partitioned table */ + /* Also, dsize can't change in a shared table, even if unpartitioned */ + long dsize; /* directory size */ + long nsegs; /* number of allocated segments (<= dsize) */ + uint32 max_bucket; /* ID of maximum bucket in use */ + uint32 high_mask; /* mask to modulo into entire table */ + uint32 low_mask; /* mask to modulo into lower half of table */ + + /* These fields are fixed at hashtable creation */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + long num_partitions; /* # partitions (must be power of 2), or 0 */ + long ffactor; /* target fill factor */ + long max_dsize; /* 'dsize' limit if directory is fixed size */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ + int nelem_alloc; /* number of entries to allocate at once */ + +#ifdef HASH_STATISTICS + + /* + * Count statistics here. NB: stats code doesn't bother with mutex, so + * counts could be corrupted a bit in a partitioned table. + */ + long accesses; + long collisions; +#endif +}; + +/* the offset of the last padding if exists*/ +#define HTAB_PAD_OFFSET 104 + +/* + * Top control structure for a hashtable --- in a shared table, each backend + * has its own copy (OK since no fields change at runtime) + */ +struct HTAB { + HASHHDR* hctl; /* => shared control information */ + HASHSEGMENT* dir; /* directory of segment starts */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context if default allocator used */ + char* tabname; /* table name (for error messages) */ + bool isshared; /* true if table is in shared memory */ + bool isfixed; /* if true, don't enlarge */ + + /* freezing a shared table isn't allowed, so we can keep state here */ + bool frozen; /* true = no more inserts allowed */ + + /* We keep local copies of these fixed values to reduce contention */ + Size keysize; /* hash key length in bytes */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - HTAB_PAD_OFFSET]; +#endif +}; + +extern int my_log2(long num); + +#endif /* DYNAHASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_event.h postgresql-hll-2.14/include/include/gtm/gtm_event.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_event.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_event.h 2020-12-12 17:06:43.202347458 +0800 @@ -0,0 +1,120 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * gtm_event.h + * GTM event header file + * + * IDENTIFICATION + * src/include/gtm/gtm_event.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_EVENT_H +#define GTM_EVENT_H + +#include "gtm/utils/event_engine.h" + +/* + * states of a connection + */ +enum gs_gtm_conn_states { + GS_GTM_CONN_LISTENING, + GS_GTM_CONN_ACCEPTED, + GS_GTM_CONN_WAIT_DATA_RECEIVE, + GS_GTM_CONN_PROCESS, + GS_GTM_CONN_CLOSE, + GS_GTM_CONN_MAX_STATE +}; + +const char* const gs_gtm_state_name[] = { + "GS_GTM_CONN_LISTENING", + "GS_GTM_CONN_ACCEPTED", + "GS_GTM_CONN_WAIT_DATA_RECEIVE", + "GS_GTM_CONN_PROCESS", + "GS_GTM_CONN_CLOSE", + "GS_GTM_CONN_MAX_STATE" +}; + +enum gs_gtm_conn_substates { + GS_GTM_CONN_PROCESS_BEGIN, + GS_GTM_CONN_PROCESS_PROGRESSING, + GS_GTM_CONN_PROCESS_END +}; + +typedef struct gs_gtm_conn gs_gtm_conn_t; +typedef struct gs_gtm_conn_queue gs_gtm_cq_t; +typedef struct gs_gtm_conn_queue_item gs_gtm_cqi_t; +typedef struct gs_gtm_event_thread gs_gtm_event_thread_t; + +struct gs_gtm_conn_queue_item { + int sfd; + SockAddr sa; + enum gs_gtm_conn_states init_state; + unsigned short event_flags; + struct gs_gtm_conn_queue_item *next; +}; + +/* A connection queue. */ +struct gs_gtm_conn_queue { + gs_gtm_cqi_t *head; + gs_gtm_cqi_t *tail; + pthread_mutex_t lock; +}; + +struct gs_gtm_event_thread { + pthread_t thread_id; /* unique ID of this thread */ + int tid; /* thread index in the global thread array */ + struct event_base *base; /* event engine handle this thread uses */ + struct event notify_event; /* listen event for notify pipe */ + int notify_receive_fd; /* receiving end of notify pipe */ + int notify_send_fd; /* sending end of notify pipe */ + gs_gtm_cq_t *new_conn_queue; /* queue of new connections to handle */ + GTM_ThreadInfo *thrinfo; + pg_atomic_int32 status; +}; + +struct gs_gtm_conn { + int sfd; + pg_atomic_int32 refcount; + GTM_ConnectionInfo *gtm_conninfo; + enum gs_gtm_conn_states state; + enum gs_gtm_conn_substates conn_process_substate; + struct event event; + unsigned short ev_flags; + unsigned short which; + bool is_switchover_processing; + gs_gtm_event_thread_t *thread; + struct gs_gtm_conn *next; +}; + +extern int gs_gtm_max_conns_per_event; +extern int gtm_num_threads; +extern int gs_gtm_max_conns; +extern gs_gtm_conn_t **gs_gtm_conns; +extern pthread_t gs_gtm_start_workers_requester; + +extern int gs_gtm_conn_pool_init(); +extern void gs_gtm_thread_pool_init(int nthreads); +extern int gs_gtm_listen_conns_init(const int listen_sockets[], int nsockets, struct event_base *main_base); +extern void gs_gtm_listen_conns_refresh(const int listen_sockets[], int nsockets, struct event_base *main_base); +extern void gs_gtm_start_workers(); +extern void gs_gtm_quit_workers(); +extern void gs_gtm_signal_start_workers(); +extern void gs_gtm_check_restart_worker(); +extern void gs_gtm_set_worker_exit(gs_gtm_event_thread_t *thread); +extern void gs_gtm_conn_closesocket(int sfd); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_ext.h postgresql-hll-2.14/include/include/gtm/gtm_ext.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_ext.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * gtm_ext.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_EXT_H +#define GTM_EXT_H + +/* + * Identifiers of error message fields. Kept here to keep common + * between frontend and backend, and also to export them to libpq + * applications. + */ +#define PG_DIAG_SEVERITY 'S' +#define PG_DIAG_MESSAGE_PRIMARY 'M' +#define PG_DIAG_MESSAGE_DETAIL 'D' +#define PG_DIAG_MESSAGE_HINT 'H' +#define PG_DIAG_SOURCE_FILE 'F' +#define PG_DIAG_SOURCE_LINE 'L' +#define PG_DIAG_SOURCE_FUNCTION 'R' + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm.h postgresql-hll-2.14/include/include/gtm/gtm.h --- postgresql-hll-2.14_old/include/include/gtm/gtm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,286 @@ +/* ------------------------------------------------------------------------- + * + * gtm.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_H +#define _GTM_H + +#include + +#include "common/config/cm_config.h" +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_conn.h" +#include "gtm/utils/elog.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_semaphore.h" + +extern char* GTMLogFileName; +extern FILE* gtmlogFile; + +extern volatile long int NumThreadAdded; +extern volatile long int NumThreadRemoved; + +extern char* Log_directory; +extern GTM_RWLock gtmlogFileLock; + +#define MAXLISTEN 64 + +#define MAX_IPADDR_LEN 32 +#define MAX_IPSTR_LEN 64 + +#define ETCD_AVA() (g_etcd_num > 0) + +typedef struct GTM_ListenEntry { + char ipaddr[MAX_IPADDR_LEN]; + int portnum; + bool needcreate; +} GTM_ListenEntry; + +typedef struct GTM_ListenAddress { + int usedNum; + GTM_ListenEntry listenArray[MAXLISTEN]; +} GTM_ListenAddress; + +/* gtm synchronous level */ +#define SYNC_GTM_OFF (0) /* asynchronous transmission between gtm and standby */ +#define SYNC_GTM_ON (1) /* synchronous transmission between gtm and standby */ +#define SYNC_GTM_AUTO (2) /* available sync mode switch sync to async */ + +typedef enum GTM_ThreadStatus { + GTM_THREAD_STARTING, + GTM_THREAD_RUNNING, + GTM_THREAD_EXITING, + GTM_THREAD_BACKUP, /* Backup to standby is in progress */ + GTM_THREAD_SWITCHOVER, + /* Must be the last */ + GTM_THREAD_INVALID +} GTM_ThreadStatus; + +typedef volatile uint32 pg_atomic_uint32; + +struct GTM_ConnectionInfo; + +#define ERRORDATA_STACK_SIZE 20 + +#define GTM_MAX_PATH 1024 +#define INVALID_GROUP_NEXT (0x7FFFFFFF) /* int32 max value*/ + +/* + * This struct is for counting messages send and receive of gtm thread between primary and standby + * Notice: current counter type is uint32. When the message count is too big than the max value of + * uint32(overflow uint32), this may have problem, some thread counter will be started from zero again. + */ +typedef struct GTM_ThreadStat { + uint32 thr_send_count; /*current thread send message count */ + uint32 thr_receive_count; /*current thread receive message count */ + uint32 thr_localid; /*the location of current thread in global thread stat array */ + bool thr_used; /*mark this thread stat slot is used or not. */ +} GTM_ThreadStat; + +typedef struct GTM_ThreadInfo { + /* + * Thread specific information such as connection(s) served by it + */ + GTM_ThreadID thr_id; + uint32 thr_localid; + bool is_main_thread; + void* (*thr_startroutine)(void*); + void (*thr_cleanuproutine)(void*); + + MemoryContext thr_thread_context; + MemoryContext thr_message_context; + MemoryContext thr_current_context; + MemoryContext thr_error_context; + MemoryContext thr_parent_context; + + sigjmp_buf* thr_sigjmp_buf; + + ErrorData thr_error_data[ERRORDATA_STACK_SIZE]; + int thr_error_stack_depth; + int thr_error_recursion_depth; + int thr_criticalsec_count; + + GTM_ThreadStatus thr_status; + GTM_ConnectionInfo* thr_conn; + /* unique client identifier */ + uint32 thr_client_id; + bool thr_need_bkup; + bool thr_seq_bkup; + bool thr_thread_over; + + GTM_RWLock thr_lock; + gtm_List* thr_cached_txninfo; + + /* main thread set other thread sema_key. */ + int sema_key; + /* when this thread want to one sema, create it. */ + PGSemaphoreData sema; + + /* store the next thread index for group sequence. */ + pg_atomic_uint32 group_next; + /* the end thread in group. */ + pg_atomic_uint32 group_end_index; + + /* + * if it's INVALID_GROUP_NEXT, that means it's not in blocked list of sequence info. + * otherwise it's blocked until the sequence is synced to standby/etcd successfully. + */ + pg_atomic_uint32 next_blocked_thread; + + /* + * store the sequence infomation, in order to transfer + * seq info for threads of thread group. + */ + GTM_ThreadSeqInfo seq_info_set; + + bool success_get_seq; +} GTM_ThreadInfo; + +typedef struct GTM_Threads { + uint32 gt_thread_count; + uint32 gt_array_size; + bool gt_standby_ready; + GTM_ThreadInfo** gt_threads; + GTM_RWLock gt_lock; + pg_atomic_uint32 thread_group_first; +} GTM_Threads; + +extern volatile GTM_Threads* GTMThreads; +extern int get_gtm_port(); + +GTM_ThreadStat* GTM_GetThreadStatSlot(uint32 localid); +int GTM_ThreadAdd(GTM_ThreadInfo* thrinfo); +int GTM_ThreadRemove(GTM_ThreadInfo* thrinfo); +int GTM_ThreadJoin(GTM_ThreadInfo* thrinfo); +void GTM_ThreadExit(void); +void ConnFree(Port* port); +void GTM_LockAllOtherThreads(void); +void GTM_UnlockAllOtherThreads(void); +void GTM_DoForAllOtherThreads(void (*process_routine)(GTM_ThreadInfo*)); +void FlushPort(Port* myport); +void CollectGTMStatus(Port* myport, bool is_backup); + +extern GTM_ThreadInfo* GTM_ThreadCreate( + GTM_ConnectionInfo* conninfo, bool normal_thread, void* (*startroutine)(void*), void (*cleanuproutine)(void* argp)); +extern GTM_ThreadInfo *GTM_ThreadCreateNoBlock(bool normal_thread, pthread_attr_t *pThreadAttr, + void* (*startroutine)(void*), void (*cleanuproutine)(void* argp)); +extern void GTM_ThreadCleanup(void* argp); +extern void GTM_CsnSyncCleanup(void *argp); +extern void GTM_AlarmCheckerCleanup(void* argp); + +GTM_ThreadInfo* GTM_GetThreadInfo(GTM_ThreadID thrid); + +extern void DestroyConnectControlTable(void); +extern void RebuildConnectControlTable(void); + +/* + * pthread keys to get thread specific information + */ +extern pthread_key_t threadinfo_key; +extern MemoryContext TopMostMemoryContext; +extern GTM_ThreadID TopMostThreadID; + +extern char* ListenAddresses; +extern int GTMPortNumber; +extern GTM_HOST_IP* ListenArray; +extern int ListenLength; + +extern char* active_addr; +extern int active_port; +extern GTM_HOST_IP* ActAddressArray; +extern int ActAddressLength; +extern int standby_connection_timeout; + +extern char* HALocalHost; +extern int HALocalPort; +extern GTM_HOST_IP* HaAddressArray; +extern int HaAddressLength; +extern bool LocalAddressChanged; +extern bool LocalPortChanged; +extern bool EnableConnectControl; +#define GTMOPTION_GTM 0 +#define GTMOPTION_GTMLITE 1 +#define GTMOPTION_GTMFREE 2 +extern int gtm_option; +extern int CsnSyncInterval; +extern int RestoreDuration; + +extern volatile int Backup_synchronously; +extern int guc_standby_only; + +extern char* NodeName; +extern char GTMControlFile[GTM_MAX_PATH]; +extern char GTMSequenceFile[GTM_MAX_PATH]; +extern volatile bool GTMPreAbortPending; +extern volatile bool primary_switchover_processing; +extern bool switchover_processing; + +extern GTM_RWLock* mainThreadLock; + +#define SetMyThreadInfo(thrinfo) pthread_setspecific(threadinfo_key, (thrinfo)) +#define GetMyThreadInfo ((GTM_ThreadInfo*)pthread_getspecific(threadinfo_key)) + +#define TopMemoryContext (GetMyThreadInfo->thr_thread_context) +#define ThreadTopContext (GetMyThreadInfo->thr_thread_context) +#define MessageContext (GetMyThreadInfo->thr_message_context) +#define CurrentMemoryContext (GetMyThreadInfo->thr_current_context) +#define ErrorContext (GetMyThreadInfo->thr_error_context) +#define errordata (GetMyThreadInfo->thr_error_data) +#define recursion_depth (GetMyThreadInfo->thr_error_recursion_depth) +#define errordata_stack_depth (GetMyThreadInfo->thr_error_stack_depth) +#define CritSectionCount (GetMyThreadInfo->thr_criticalsec_count) +#define gtm_need_bkup (GetMyThreadInfo->thr_need_bkup) +#define seq_need_bkup (GetMyThreadInfo->thr_seq_bkup) + +#define PG_exception_stack (GetMyThreadInfo->thr_sigjmp_buf) +#define MyConnection (GetMyThreadInfo->thr_conn) +#define MyPort ((GetMyThreadInfo->thr_conn != NULL) ? GetMyThreadInfo->thr_conn->con_port : NULL) +#define MyThreadID (GetMyThreadInfo->thr_id) +#define IsMainThread() (GetMyThreadInfo->thr_id == TopMostThreadID) + +#define GTM_CachedTransInfo (GetMyThreadInfo->thr_cached_txninfo) +#define GTM_HaveFreeCachedTransInfo() (gtm_list_length(GTM_CachedTransInfo)) + +#define GTM_MAX_CACHED_TRANSINFO 0 +#define GTM_HaveEnoughCachedTransInfo() (gtm_list_length(GTM_CachedTransInfo) >= GTM_MAX_CACHED_TRANSINFO) + +#define START_CRIT_SECTION() (CritSectionCount++) + +#define END_CRIT_SECTION() do { \ + Assert(CritSectionCount > 0); \ + CritSectionCount--; \ +} while (0) + +typedef enum GtmHaMode { + GHM_NO_HA, /* used for normal. */ + GHM_SINGLE_STANDBY, /* used for mode without etcd. */ + GHM_MULT_STANDBY, /* used for mode under multistandbys, only sync data with etcd. */ + GHM_MIXED /* used for version commpatible, one primary & one standby. */ +} GtmHaMode; + +extern volatile GtmHaMode gtm_ha_mode; +#define IS_SINGLE_STANBY_HA_MODE() (gtm_ha_mode == GHM_SINGLE_STANDBY) +#define IS_MULT_STANDBY_HA_MODE() (gtm_ha_mode == GHM_MULT_STANDBY) +#define IS_MIXED_HA_MODE() (gtm_ha_mode == GHM_MIXED) +#define MINORITY_MODE() (Backup_synchronously == SYNC_GTM_OFF && IS_MULT_STANDBY_HA_MODE()) +#define ETCD_MODE() (IS_MULT_STANDBY_HA_MODE() || (!IS_MULT_STANDBY_HA_MODE() && ETCD_AVA())) + +#define ETCD_MODE_ACTIVE_PORT 0 + +#define SET_GTM_HAMODE(mode) do { \ + Assert((mode) >= GHM_SINGLE_STANDBY && (mode) <= GHM_MIXED); \ + gtm_ha_mode = (mode); \ +} while (0) + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_hsearch.h postgresql-hll-2.14/include/include/gtm/gtm_hsearch.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_hsearch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_hsearch.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,156 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_hsearch.h + * exported definitions for utils/hash/dynahash.c; see notes therein + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/gtm/gtm_hsearch.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef HSEARCH_H +#define HSEARCH_H + +/* + * Hash functions must have this signature. + */ +typedef uint32 (*HashValueFunc)(const void* key, Size keysize); + +/* + * Key comparison functions must have this signature. Comparison functions + * return zero for match, nonzero for no match. (The comparison function + * definition is designed to allow memcmp() and strncmp() to be used directly + * as key comparison functions.) + */ +typedef int (*HashCompareFunc)(const void* key1, const void* key2, Size keysize); + +/* + * Key copying functions must have this signature. The return value is not + * used. (The definition is set up to allow memcpy() and strncpy() to be + * used directly.) + */ +typedef void* (*HashCopyFunc)(void* dest, const void* src, Size keysize); + +/* + * Space allocation function for a hashtable --- designed to match malloc(). + * Note: there is no free function API; can't destroy a hashtable unless you + * use the default allocator. + */ +typedef void* (*HashAllocFunc)(Size request); + +/* + * Space deallocation function for a hashtable --- designed to match allocator(). + * Note: it's a free function API; you must use it with allocator you defined. + */ +typedef void (*HashDeallocFunc)(void* pointer); + +/* + * HASHELEMENT is the private part of a hashtable entry. The caller's data + * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key + * is expected to be at the start of the caller's hash entry data structure. + */ +typedef struct HASHELEMENT { + struct HASHELEMENT* link; /* link to next entry in same bucket */ + uint32 hashvalue; /* hash function result for this entry */ +} HASHELEMENT; + +/* Hash table header struct is an opaque type known only within dynahash.c */ +typedef struct HASHHDR HASHHDR; + +/* Hash table control struct is an opaque type known only within dynahash.c */ +typedef struct HTAB HTAB; + +/* Parameter data structure for hash_create */ +/* Only those fields indicated by hash_flags need be set */ +typedef struct HASHCTL { + long num_partitions; /* # partitions (must be power of 2) */ + long ssize; /* segment size */ + long dsize; /* (initial) directory size */ + long max_dsize; /* limit to dsize if dir size is limited */ + long ffactor; /* fill factor */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context to use for allocations */ + HASHHDR* hctl; /* location of header in shared mem */ +} HASHCTL; + +/* Flags to indicate which parameters are supplied */ +#define HASH_PARTITION 0x001 /* Hashtable is used w/partitioned locking */ +#define HASH_SEGMENT 0x002 /* Set segment size */ +#define HASH_DIRSIZE 0x004 /* Set directory size (initial and max) */ +#define HASH_FFACTOR 0x008 /* Set fill factor */ +#define HASH_FUNCTION 0x010 /* Set user defined hash function */ +#define HASH_ELEM 0x020 /* Set keysize and entrysize */ +#define HASH_SHARED_MEM 0x040 /* Hashtable is in shared memory */ +#define HASH_ATTACH 0x080 /* Do not initialize hctl */ +#define HASH_ALLOC 0x100 /* Set memory allocator */ +#define HASH_CONTEXT 0x200 /* Set memory allocation context */ +#define HASH_COMPARE 0x400 /* Set user defined comparison function */ +#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */ +#define HASH_FIXED_SIZE 0x1000 /* Initial size is a hard limit */ +#define HASH_HEAP_MEM 0x2000 /* Hashtable is in heap memory */ +#define HASH_EXTERN_CONTEXT 0x4000 /* use extern context directly */ +#define HASH_SHRCTX 0x8000 /* Set shared memory allocation context */ +#define HASH_DEALLOC 0x10000 /* Set memory deallocator */ +#define HASH_BLOBS 0x20000 /* Select support functions for binary keys */ +#define HASH_NOEXCEPT 0x40000 /* Do not throw exception when malloc memory */ + +/* max_dsize value to indicate expansible directory */ +#define NO_MAX_DSIZE (-1) + +/* hash_search operations */ +typedef enum { + HASH_FIND, + HASH_ENTER, + HASH_REMOVE, + HASH_ENTER_NULL +} HASHACTION; + +/* hash_seq status (should be considered an opaque type by callers) */ +typedef struct { + HTAB* hashp; + uint32 curBucket; /* index of current bucket */ + HASHELEMENT* curEntry; /* current entry in bucket */ +} HASH_SEQ_STATUS; + +/* + * prototypes for functions in dynahash.c + */ +extern HTAB *hash_create(const char *tabname, long nelem, HASHCTL *info, int flags); +extern void hash_destroy(HTAB *hashp); +extern void hash_remove(HTAB *hashp); +extern void hash_stats(const char *where, HTAB *hashp); +extern void *hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr); +extern uint32 get_hash_value(HTAB *hashp, const void *keyPtr); +extern void *hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, + bool *foundPtr); +extern long hash_get_num_entries(HTAB *hashp); +extern void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp); +extern void *hash_seq_search(HASH_SEQ_STATUS *status); +extern void hash_seq_term(HASH_SEQ_STATUS *status); +extern void hash_freeze(HTAB *hashp); +extern Size hash_estimate_size(long num_entries, Size entrysize); +extern long hash_select_dirsize(long num_entries); +extern Size hash_get_shared_size(HASHCTL* info, int flags); +extern int hash_get_seq_num(); +extern void release_all_seq_scan(); +extern MemoryContext hash_get_current_dynacxt(void); + +/* + * prototypes for functions in hashfn.c + */ +extern uint32 string_hash(const void* key, Size keysize); +extern uint32 tag_hash(const void* key, Size keysize); +extern uint32 oid_hash(const void* key, Size keysize); +extern uint32 bitmap_hash(const void* key, Size keysize); +extern int bitmap_match(const void* key1, const void* key2, Size keysize); + +#endif /* HSEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_ip.h postgresql-hll-2.14/include/include/gtm/gtm_ip.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_ip.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * gtm_ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.20 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_IP_H +#define GTM_IP_H + +#include "gtm/utils/pqcomm.h" + +extern int gtm_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, + struct addrinfo **result); +extern void gtm_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai); + +extern int gtm_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, + int servicelen, int flags); + +extern int gtm_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int gtm_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void gtm_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void gtm_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* GTM_IP_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_list.h postgresql-hll-2.14/include/include/gtm/gtm_list.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_list.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,270 @@ +/* ------------------------------------------------------------------------- + * + * gtm_list.h + * interface for PostgreSQL generic linked list package + * + * This package implements singly-linked homogeneous lists. + * + * It is important to have constant-time length, append, and prepend + * operations. To achieve this, we deal with two distinct data + * structures: + * + * 1. A set of "list cells": each cell contains a data field and + * a link to the next cell in the list or NULL. + * 2. A single structure containing metadata about the list: the + * type of the list, pointers to the head and tail cells, and + * the length of the list. + * + * We support three types of lists: + * + * T_List: lists of pointers + * (in practice usually pointers to Nodes, but not always; + * declared as "void *" to minimize casting annoyances) + * T_IntList: lists of integers + * T_OidList: lists of Oids + * + * (At the moment, ints and Oids are the same size, but they may not + * always be so; try to be careful to maintain the distinction.) + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/nodes/pg_list.h,v 1.59 2008/08/14 18:48:00 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_LIST_H +#define GTM_LIST_H + +typedef struct gtm_ListCell gtm_ListCell; + +typedef struct gtm_List { + int length; + gtm_ListCell* head; + gtm_ListCell* tail; +} gtm_List; + +struct gtm_ListCell { + union { + void* ptr_value; + int int_value; + } data; + gtm_ListCell* next; +}; + +/* + * The *only* valid representation of an empty list is gtm_NIL; in other + * words, a non-gtm_NIL list is guaranteed to have length >= 1 and + * head/tail != NULL + */ +#define gtm_NIL ((gtm_List*)NULL) + +/* + * These routines are used frequently. However, we can't implement + * them as macros, since we want to avoid double-evaluation of macro + * arguments. Therefore, we implement them using GCC inline functions, + * and as regular functions with non-GCC compilers. + */ +#ifdef __GNUC__ + +static __inline__ gtm_ListCell* gtm_list_head(gtm_List* l) +{ + return l ? l->head : NULL; +} + +static __inline__ gtm_ListCell* gtm_list_tail(gtm_List* l) +{ + return l ? l->tail : NULL; +} + +static __inline__ int gtm_list_length(gtm_List* l) +{ + return l ? l->length : 0; +} +#else + +extern gtm_ListCell* gtm_list_head(gtm_List* l); +extern gtm_ListCell* gtm_list_tail(gtm_List* l); +extern int gtm_list_length(gtm_List* l); +#endif /* __GNUC__ */ + +/* + * NB: There is an unfortunate legacy from a previous incarnation of + * the gtm_List API: the macro gtm_lfirst() was used to mean "the data in this + * cons cell". To avoid changing every usage of gtm_lfirst(), that meaning + * has been kept. As a result, gtm_lfirst() takes a gtm_ListCell and returns + * the data it contains; to get the data in the first cell of a + * gtm_List, use gtm_linitial(). Worse, gtm_lsecond() is more closely related to + * gtm_linitial() than gtm_lfirst(): given a gtm_List, gtm_lsecond() returns the data + * in the second cons cell. + */ + +#define gtm_lnext(lc) ((lc)->next) +#define gtm_lfirst(lc) ((lc)->data.ptr_value) +#define gtm_lfirst_int(lc) ((lc)->data.int_value) + +#define gtm_linitial(l) gtm_lfirst(gtm_list_head(l)) +#define gtm_linitial_int(l) gtm_lfirst_int(gtm_list_head(l)) + +#define gtm_lsecond(l) gtm_lfirst(gtm_lnext(gtm_list_head(l))) +#define gtm_lsecond_int(l) gtm_lfirst_int(gtm_lnext(gtm_list_head(l))) + +#define gtm_lthird(l) gtm_lfirst(gtm_lnext(gtm_lnext(gtm_list_head(l)))) +#define gtm_lthird_int(l) gtm_lfirst_int(gtm_lnext(gtm_lnext(gtm_list_head(l)))) + +#define gtm_lfourth(l) gtm_lfirst(gtm_lnext(gtm_lnext(gtm_lnext(gtm_list_head(l))))) +#define gtm_lfourth_int(l) gtm_lfirst_int(gtm_lnext(gtm_lnext(gtm_lnext(gtm_list_head(l))))) + +#define gtm_llast(l) gtm_lfirst(gtm_list_tail(l)) +#define gtm_llast_int(l) gtm_lfirst_int(gtm_list_tail(l)) + +/* + * Convenience macros for building fixed-length lists + */ +#define gtm_list_make1(x1) gtm_lcons(x1, gtm_NIL) +#define gtm_list_make2(x1, x2) gtm_lcons(x1, gtm_list_make1(x2)) +#define gtm_list_make3(x1, x2, x3) gtm_lcons(x1, gtm_list_make2(x2, x3)) +#define gtm_list_make4(x1, x2, x3, x4) gtm_lcons(x1, gtm_list_make3(x2, x3, x4)) + +#define gtm_list_make1_int(x1) gtm_lcons_int(x1, gtm_NIL) +#define gtm_list_make2_int(x1, x2) gtm_lcons_int(x1, gtm_list_make1_int(x2)) +#define gtm_list_make3_int(x1, x2, x3) gtm_lcons_int(x1, gtm_list_make2_int(x2, x3)) +#define gtm_list_make4_int(x1, x2, x3, x4) gtm_lcons_int(x1, gtm_list_make3_int(x2, x3, x4)) + +/* + * gtm_foreach - + * a convenience macro which loops through the list + */ +#define gtm_foreach(cell, l) for ((cell) = gtm_list_head(l); (cell) != NULL; (cell) = gtm_lnext(cell)) + +/* + * gtm_for_each_cell - + * a convenience macro which loops through a list starting from a + * specified cell + */ +#define gtm_for_each_cell(cell, initcell) for ((cell) = (initcell); (cell) != NULL; (cell) = gtm_lnext(cell)) + +/* + * gtm_forboth - + * a convenience macro for advancing through two linked lists + * simultaneously. This macro loops through both lists at the same + * time, stopping when either list runs out of elements. Depending + * on the requirements of the call site, it may also be wise to + * assert that the lengths of the two lists are gtm_equal. + */ +#define gtm_forboth(cell1, list1, cell2, list2) \ + for ((cell1) = gtm_list_head(list1), (cell2) = gtm_list_head(list2); (cell1) != NULL && (cell2) != NULL; \ + (cell1) = gtm_lnext(cell1), (cell2) = gtm_lnext(cell2)) + +extern gtm_List* gtm_lappend(gtm_List* list, void* datum); +extern gtm_List* gtm_lappend_int(gtm_List* list, int datum); + +extern gtm_ListCell* gtm_lappend_cell(gtm_List* list, gtm_ListCell* prev, void* datum); +extern gtm_ListCell* gtm_lappend_cell_int(gtm_List* list, gtm_ListCell* prev, int datum); + +extern gtm_List* gtm_lcons(void* datum, gtm_List* list); +extern gtm_List* gtm_lcons_int(int datum, gtm_List* list); + +extern gtm_List* gtm_list_concat(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_truncate(gtm_List* list, int new_size); + +extern void* gtm_list_nth(gtm_List* list, int n); +extern int gtm_list_nth_int(gtm_List* list, int n); + +extern bool gtm_list_member(gtm_List* list, const void* datum); +extern bool gtm_list_member_ptr(gtm_List* list, const void* datum); +extern bool gtm_list_member_int(gtm_List* list, int datum); + +extern gtm_List* gtm_list_delete(gtm_List* list, const void* datum); +extern gtm_List* gtm_list_delete_ptr(gtm_List* list, const void* datum); +extern gtm_List* gtm_list_delete_int(gtm_List* list, int datum); +extern gtm_List* gtm_list_delete_first(gtm_List* list); +extern gtm_List* gtm_list_delete_cell(gtm_List* list, gtm_ListCell* cell, gtm_ListCell* prev); + +extern gtm_List* gtm_list_union(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_union_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_union_int(gtm_List* list1, gtm_List* list2); + +extern gtm_List* gtm_list_intersection(gtm_List* list1, gtm_List* list2); +/* currently, there's no need for list_intersection_int etc */ + +extern gtm_List* gtm_list_difference(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_difference_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_difference_int(gtm_List* list1, gtm_List* list2); + +extern gtm_List* gtm_list_append_unique(gtm_List* list, void* datum); +extern gtm_List* gtm_list_append_unique_ptr(gtm_List* list, void* datum); +extern gtm_List* gtm_list_append_unique_int(gtm_List* list, int datum); + +extern gtm_List* gtm_list_concat_unique(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_concat_unique_ptr(gtm_List* list1, gtm_List* list2); +extern gtm_List* gtm_list_concat_unique_int(gtm_List* list1, gtm_List* list2); + +extern void gtm_list_free(gtm_List* list); +extern void gtm_list_free_deep(gtm_List* list); + +extern gtm_List* gtm_list_copy(gtm_List* list); +extern gtm_List* gtm_list_copy_tail(gtm_List* list, int nskip); + +/* + * To ease migration to the new list API, a set of compatibility + * macros are provided that reduce the impact of the list API changes + * as far as possible. Until client code has been rewritten to use the + * new list API, the ENABLE_LIST_COMPAT symbol can be defined before + * including pg_list.h + */ +#ifdef ENABLE_LIST_COMPAT + +#define gtm_lfirsti(lc) gtm_lfirst_int(lc) + +#define gtm_makeList1(x1) gtm_list_make1(x1) +#define gtm_makeList2(x1, x2) gtm_list_make2(x1, x2) +#define gtm_makeList3(x1, x2, x3) gtm_list_make3(x1, x2, x3) +#define gtm_makeList4(x1, x2, x3, x4) gtm_list_make4(x1, x2, x3, x4) + +#define gtm_makeListi1(x1) gtm_list_make1_int(x1) +#define gtm_makeListi2(x1, x2) gtm_list_make2_int(x1, x2) + +#define gtm_lconsi(datum, list) gtm_lcons_int(datum, list) + +#define gtm_lappendi(list, datum) gtm_lappend_int(list, datum) + +#define gtm_nconc(l1, l2) gtm_list_concat(l1, l2) + +#define gtm_nth(n, list) gtm_list_nth(list, n) + +#define gtm_member(datum, list) gtm_list_member(list, datum) +#define gtm_ptrMember(datum, list) gtm_list_member_ptr(list, datum) +#define gtm_intMember(datum, list) gtm_list_member_int(list, datum) + +/* + * Note that the old gtm_lremove() determined equality via pointer + * comparison, whereas the new gtm_list_delete() uses gtm_equal(); in order to + * keep the same behavior, we therefore need to map gtm_lremove() calls to + * gtm_list_delete_ptr() rather than gtm_list_delete() + */ +#define gtm_lremove(elem, list) gtm_list_delete_ptr(list, elem) +#define gtm_LispRemove(elem, list) gtm_list_delete(list, elem) +#define gtm_lremovei(elem, list) gtm_list_delete_int(list, elem) + +#define gtm_ltruncate(n, list) gtm_list_truncate(list, n) + +#define gtm_set_union(l1, l2) gtm_list_union(l1, l2) +#define gtm_set_ptrUnion(l1, l2) gtm_list_union_ptr(l1, l2) + +#define gtm_set_difference(l1, l2) gtm_list_difference(l1, l2) +#define gtm_set_ptrDifference(l1, l2) gtm_list_difference_ptr(l1, l2) + +#define gtm_equali(l1, l2) gtm_equal(l1, l2) +#define gtm_equalo(l1, l2) gtm_equal(l1, l2) + +#define gtm_freeList(list) gtm_list_free(list) + +#define gtm_listCopy(list) gtm_list_copy(list) + +extern int gtm_length(gtm_List* list); +#endif /* ENABLE_LIST_COMPAT */ + +#endif /* GTM_LIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_lock.h postgresql-hll-2.14/include/include/gtm/gtm_lock.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_lock.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,93 @@ +/* ------------------------------------------------------------------------- + * + * gtm_lock.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_LOCK_H +#define GTM_LOCK_H + +#include + +typedef struct GTM_RWLock { + pthread_rwlock_t lk_lock; +} GTM_RWLock; + +typedef struct GTM_MutexLock { + pthread_mutex_t lk_lock; +} GTM_MutexLock; + +typedef enum GTM_LockMode { + GTM_LOCKMODE_WRITE, + GTM_LOCKMODE_READ +} GTM_LockMode; + +typedef struct GTM_CV { + pthread_cond_t cv_condvar; +} GTM_CV; + +extern void GTM_RWLockAcquire(GTM_RWLock* lock, GTM_LockMode mode); +extern void GTM_RWLockRelease(GTM_RWLock* lock); +extern void GTM_RWLockInit(GTM_RWLock* lock); +extern void GTM_RWLockDestroy(GTM_RWLock* lock); +extern bool GTM_RWLockConditionalAcquire(GTM_RWLock* lock, GTM_LockMode mode); + +extern void GTM_MutexLockAcquire(GTM_MutexLock* lock); +extern void GTM_MutexLockRelease(GTM_MutexLock* lock); +extern void GTM_MutexLockInit(GTM_MutexLock* lock); +extern void GTM_MutexLockDestroy(GTM_MutexLock* lock); +extern void GTM_MutexLockConditionalAcquire(GTM_MutexLock* lock); + +extern int GTM_CVInit(GTM_CV* cv); +extern int GTM_CVDestroy(GTM_CV* cv); +extern int GTM_CVSignal(GTM_CV* cv); +extern int GTM_CVBcast(GTM_CV* cv); +extern int GTM_CVWait(GTM_CV* cv, GTM_MutexLock* lock); + +// AutoGTMRWLock +// Auto object for GTM reader-writer lock +// +class AutoGTMRWLock { +public: + AutoGTMRWLock(_in_ volatile GTM_RWLock* glock) + { + m_glock = (GTM_RWLock*)glock; + } + + ~AutoGTMRWLock() + { + LockRelease(); + } + + inline void LockAcquire(_in_ GTM_LockMode mode) + { + GTM_RWLockAcquire(m_glock, mode); + } + + inline bool LockConditionalAcquire(_in_ GTM_LockMode mode) + { + return GTM_RWLockConditionalAcquire(m_glock, mode); + } + + inline void LockRelease() + { + if (m_glock != NULL) { + GTM_RWLockRelease(m_glock); + m_glock = NULL; + } + } + +private: + // Point to an existing GTM_RWLock object + // + GTM_RWLock* m_glock; +}; +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_msg.h postgresql-hll-2.14/include/include/gtm/gtm_msg.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_msg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_msg.h 2020-12-12 17:06:43.203347471 +0800 @@ -0,0 +1,218 @@ +/* ------------------------------------------------------------------------- + * + * gtm_msg.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_MSG_H +#define GTM_MSG_H + +/* + * The following enum symbols are also used in message_name_tab structure + * in gtm_utils.c. Modification of the following enum should reflect + * changes to message_name_tab structure as well. + */ +typedef enum GTM_MessageType { + MSG_TYPE_INVALID, + MSG_SYNC_STANDBY, /* Message to sync woth GTM-Standby */ + MSG_NODE_REGISTER, /* Register a PGXC Node with GTM */ + MSG_BKUP_NODE_REGISTER, /* Backup of MSG_NODE_REGISTER */ + MSG_NODE_UNREGISTER, /* Unregister a PGXC Node with GTM */ + MSG_BKUP_NODE_UNREGISTER, /* Backup of MSG_NODE_UNREGISTER */ + MSG_NODE_LIST, /* Get node list */ + MSG_NODE_BEGIN_REPLICATION_INIT, /* deprecated message for upgrade compatibility */ + MSG_NODE_END_REPLICATION_INIT, /* deprecated message for upgrade compatibility */ + MSG_BEGIN_BACKUP, /* Start backup by Standby */ + + MSG_END_BACKUP, /* End backup preparation by Standby */ + MSG_TXN_XMINRESET, /* reset handle xmin when isolation is RC */ + MSG_TXN_BEGIN, /* Start a new transaction */ + MSG_BKUP_TXN_BEGIN, /* Backup of MSG_TXN_BEGIN */ + MSG_TXN_BEGIN_GETGXID, /* Start a new transaction and get GXID */ + MSG_BKUP_TXN_BEGIN_GETGXID, /* Backup of MSG_TXN_BEGIN_GETGXID */ + MSG_BKUP_GTM_CONTROL_FILE_GXID, /*Backup of gtm control file gxid */ + MSG_BKUP_GTM_CONTROL_FILE_TIMELINE, /*Backup of gtm control file timeline */ + MSG_TXN_BEGIN_GETGXID_MULTI, /* Start multiple new transactions and get GXIDs */ + MSG_BKUP_TXN_BEGIN_GETGXID_MULTI, /* Backup of MSG_TXN_BEGIN_GETGXID_MULTI */ + MSG_TXN_START_PREPARED, /* Begins to prepare a transation for commit */ + MSG_BKUP_TXN_START_PREPARED, /* Backup of MSG_TXN_START_PREPARED */ + + MSG_TXN_COMMIT, /* Commit a running or prepared transaction */ + MSG_BKUP_TXN_COMMIT, /* Backup of MSG_TXN_COMMIT */ + MSG_TXN_COMMIT_MULTI, /* Commit multiple running or prepared transactions */ + MSG_BKUP_TXN_COMMIT_MULTI, /* Bacukp of MSG_TXN_COMMIT_MULTI */ + MSG_TXN_COMMIT_PREPARED, /* Commit a prepared transaction */ + MSG_BKUP_TXN_COMMIT_PREPARED, /* Backup of MSG_TXN_COMMIT_PREPARED */ + MSG_TXN_PREPARE, /* Finish preparing a transaction */ + MSG_BKUP_TXN_PREPARE, /* Backup of MSG_TXN_PREPARE */ + MSG_TXN_ROLLBACK, /* Rollback a transaction */ + MSG_BKUP_TXN_ROLLBACK, /* Backup of MSG_TXN_ROLLBACK */ + + MSG_TXN_ROLLBACK_MULTI, /* Rollback multiple transactions */ + MSG_BKUP_TXN_ROLLBACK_MULTI, /* Backup of MSG_TXN_ROLLBACK_MULTI */ + MSG_TXN_GET_GID_DATA, /* Get info associated with a GID, and get a GXID */ + MSG_TXN_GET_GXID, /* Get a GXID for a transaction */ + MSG_SUB_TXN_GET_GXID, /* Get a GXID for a sub transaction */ + MSG_BKUP_TXN_GET_GXID, + MSG_TXN_GET_NEXT_GXID, /* Get next GXID */ + MSG_TXN_GET_NEXT_CSN, /* Get next CSN without commit */ + MSG_TXN_GET_TIMELINE, /* Get gtm timeline*/ + MSG_TXN_GET_GLOBAL_XMIN, /* Get global xmin */ + MSG_TXN_GXID_LIST, + MSG_SET_VACUUM_FLAG, + MSG_SNAPSHOT_GET, /* Get a global snapshot */ + MSG_SNAPSHOT_GET_MULTI, /* Get multiple global snapshots */ + MSG_SNAPSHOT_STATUS_GET, /* Get snapshot status */ + + MSG_SNAPSHOT_GXID_GET, /* Get GXID and snapshot together */ + MSG_SEQUENCE_GET_NEXT_UUID, /* Get sequuid for issuring sequence */ + MSG_SEQUENCE_UUID, /* Create UUID matched with seqKey */ + MSG_BKUP_SEQUENCE_UUID, /* Backup of MSG_SEQUENCE_UUID */ + MSG_BKUP_GTM_UUID, /* Backup of gtm control file seq_uuid*/ + MSG_SEQUENCE_INIT, /* Initialize a new global sequence =41*/ + MSG_BKUP_SEQUENCE_INIT, /* Backup of MSG_SEQUENCE_INIT */ + MSG_SEQUENCE_GET_NEXT, /* Get the next sequence value of sequence */ + MSG_BKUP_SEQUENCE_GET_NEXT, /* Backup of MSG_SEQUENCE_GET_NEXT */ + MSG_SEQUENCE_GET_LAST, /* Get the last sequence value of sequence */ + MSG_SEQUENCE_SET_VAL, /* Set values for sequence */ + MSG_BKUP_SEQUENCE_SET_VAL, /* Backup of MSG_SEQUENCE_SET_VAL */ + MSG_SEQUENCE_RESET, /* Reset the sequence */ + MSG_BKUP_SEQUENCE_RESET, /* Backup of MSG_SEQUENCE_RESET */ + + MSG_SEQUENCE_CLOSE, /* Close a previously inited sequence 50*/ + MSG_BKUP_SEQUENCE_CLOSE, /* Backup of MSG_SEQUENCE_CLOSE */ + MSG_SEQUENCE_RENAME, /* Rename a sequence */ + MSG_BKUP_SEQUENCE_RENAME, /* Backup of MSG_SEQUENCE_RENAME */ + MSG_SEQUENCE_ALTER, /* Alter a sequence */ + MSG_BKUP_SEQUENCE_ALTER, /* Backup of MSG_SEQUENCE_ALTER */ + MSG_SEQUENCE_LIST, /* Get a list of sequences */ + MSG_TXN_GET_STATUS, /* Get status of a given transaction */ + MSG_TXN_GET_ALL_PREPARED, /* Get information about all outstanding + * prepared transactions */ + MSG_TXN_BEGIN_GETGXID_AUTOVACUUM, /* Start a new transaction and get GXID for autovacuum */ + MSG_BKUP_TXN_BEGIN_GETGXID_AUTOVACUUM, /* Backup of MSG_TXN_BEGIN_GETGXID_AUTOVACUUM */ + MSG_DATA_FLUSH, /* flush pending data */ + MSG_BACKEND_DISCONNECT, /* tell GTM that the backend diconnected from the proxy */ + MSG_BARRIER, /* Tell the barrier was issued */ + MSG_BKUP_BARRIER, /* Backup barrier to standby */ + MSG_BEGIN_SWITCHOVER, /*Tell primary GTM to do switchover*/ + MSG_END_SWITCHOVER, /*Tell primary GTM to do switchover*/ + MSG_QUERY_GTM_STATUS, + MSG_SET_GTM_SYNCMODE, + MSG_CHECK_REMOTE_ROLE, + MSG_SYNC_FILE, + MSG_TXN_WORKLOAD_INIT, /* Initialize the workload manager bookkeeper */ + MSG_BKUP_TXN_WORKLOAD_INIT, /* Backup of MSG_TXN_WORKLOAD_INIT */ + MSG_TXN_WORKLOAD_RESERVE_MEM, /* Workload management: reserve memory if there is enough */ + MSG_BKUP_TXN_WORKLOAD_RESERVE_MEM, /* Backup of MSG_TXN_WORKLOAD_RESERVE_MEM */ + MSG_TXN_WORKLOAD_RELEASE_MEM, /* return to WLM the memory reserved after execution is done */ + MSG_BKUP_TXN_WORKLOAD_RELEASE_MEM, /* Backup of MSG_TXN_WORKLOAD_RELEASE_MEM */ + MSG_WLM_RESOURCEPOOL_CREATE, /*create resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_UPDATE, /*update resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_DELETE, /*delete resource pool on gtm*/ + MSG_WLM_RESOURCEPOOL_INIT, /*initialize resource pool list on gtm*/ + MSG_CHECK_NEXT_GXID, + MSG_BKUP_GTM_CONTROL_FILE_SEQUENCE, /*Backup of gtm control file sequence*/ + + MSG_HOTPATCH, + + MSG_TXN_GET_NEXT_CSN_LITE, /* gtm-lite commit csn */ + MSG_SNAPSHOT_GET_LITE, /* Get a GTMLite global snapshot */ + MSG_GET_GTM_LITE_STATUS, /* Get the status of gtm lite */ + /* + * Must be at the end + */ + MSG_TYPE_COUNT /* A dummmy entry just to count the message types */ +} GTM_MessageType; + +/* + * Symbols in the following enum are usd in result_name_tab defined in gtm_utils.c. + * Modifictaion to the following enum should be reflected to result_name_tab as well. + */ +typedef enum GTM_ResultType { + SYNC_STANDBY_RESULT, + NODE_REGISTER_RESULT, + NODE_UNREGISTER_RESULT, + NODE_LIST_RESULT, + NODE_BEGIN_REPLICATION_INIT_RESULT, /* deprecated return type for upgrade compatibility */ + NODE_END_REPLICATION_INIT_RESULT, /* deprecated return type for upgrade compatibility */ + BEGIN_BACKUP_RESULT, + END_BACKUP_RESULT, + TXN_XMINRESET_RESULT, + TXN_SETVACUUM_RESULT, + TXN_BEGIN_RESULT, + TXN_BEGIN_GETGXID_RESULT, + TXN_BEGIN_GETGXID_MULTI_RESULT, + TXN_PREPARE_RESULT, + TXN_START_PREPARED_RESULT, + TXN_COMMIT_PREPARED_RESULT, + TXN_COMMIT_RESULT, + TXN_COMMIT_MULTI_RESULT, + TXN_ROLLBACK_RESULT, + TXN_ROLLBACK_MULTI_RESULT, + TXN_GET_GID_DATA_RESULT, + TXN_GET_GXID_RESULT, + TXN_GET_NEXT_GXID_RESULT, + TXN_GET_NEXT_CSN_RESULT, + TXN_GET_TIMELINE_RESULT, + TXN_GET_GLOBAL_XMIN_RESULT, + TXN_WORKLOAD_INIT_RESULT, + TXN_WORKLOAD_RESERVE_MEM_RESULT, + TXN_WORKLOAD_RELEASE_MEM_RESULT, + WLM_RESOURCEPOOL_CREATE_RESULT, /*create resource pool on gtm*/ + WLM_RESOURCEPOOL_UPDATE_RESULT, /*update resource pool on gtm*/ + WLM_RESOURCEPOOL_DELETE_RESULT, /*delete resource pool on gtm*/ + WLM_RESOURCEPOOL_INIT_RESULT, /*initialize resource pool list on gtm*/ + + TXN_GXID_LIST_RESULT, + SNAPSHOT_GET_RESULT, + SNAPSHOT_GET_MULTI_RESULT, + SNAPSHOT_GXID_GET_RESULT, + SNAPSHOT_STATUS_GET_RESULT, + SEQUENCE_GET_NEXT_UUID_RESULT, + SEQUENCE_GET_UUID_RESULT, + SEQUENCE_INIT_RESULT, + SEQUENCE_GET_NEXT_RESULT, + SEQUENCE_GET_LAST_RESULT, + SEQUENCE_SET_VAL_RESULT, + SEQUENCE_RESET_RESULT, + SEQUENCE_CLOSE_RESULT, + SEQUENCE_RENAME_RESULT, + SEQUENCE_ALTER_RESULT, + SEQUENCE_LIST_RESULT, + TXN_GET_STATUS_RESULT, + TXN_GET_ALL_PREPARED_RESULT, + TXN_BEGIN_GETGXID_AUTOVACUUM_RESULT, + BARRIER_RESULT, + BEGIN_SWITCHOVER_RESULT, + END_SWITCHOVER_RESULT, + QUERY_GTM_STATUS_RESULT, + CHECK_STANDBY_ROLE_RESULT, + SYNC_FILE_RESUTL, + GTM_SETSYNCMODE_RESULT, + CHECK_SYNC_NEXT_GXID_RESULT, + GTM_HOTPATCH_RESULT, + SNAPSHOT_GET_RESULT_LITE, + GTM_LITE_STATUS_RESULT, + RESULT_TYPE_COUNT +} GTM_ResultType; + +/* + * Special message header for the messgaes exchanged between the GTM server and + * the proxy. + * + * ph_conid: connection identifier which is used to route + * the messages to the right backend. + */ +typedef struct GTM_ProxyMsgHeader { + GTMProxy_ConnID ph_conid; +} GTM_ProxyMsgHeader; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_opt.h postgresql-hll-2.14/include/include/gtm/gtm_opt.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_opt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_opt.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,368 @@ +/* -------------------------------------------------------------------- + * gtm_opt.h + * + * External declarations pertaining to gtm/main/gtm_opt.c, gtm/proxy/gtm_proxy_opt.c and + * gtm/common/gtm_opt_file.l + * + * Portions Copyright (c) 2011, Postgres-XC Development Group + * Portions Copyright (c) 2000-2011, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * Modified by Koichi Suzuki + * + * src/include/gtm/gtm_opt.h + * -------------------------------------------------------------------- + */ +#ifndef GTM_OPT_H +#define GTM_OPT_H + +/* + * Certain options can only be set at certain times. The rules are + * like this: + * + * INTERNAL options cannot be set by the user at all, but only through + * internal processes ("server_version" is an example). These are GUC + * variables only so they can be shown by SHOW, etc. + * + * POSTMASTER options can only be set when the postmaster starts, + * either from the configuration file or the command line. + * + * SIGHUP options can only be set at postmaster startup or by changing + * the configuration file and sending the HUP signal to the postmaster + * or a backend process. (Notice that the signal receipt will not be + * evaluated immediately. The postmaster and the backend check it at a + * certain point in their main loop. It's safer to wait than to read a + * file asynchronously.) + * + * BACKEND options can only be set at postmaster startup, from the + * configuration file, or by client request in the connection startup + * packet (e.g., from libpq's PGOPTIONS variable). Furthermore, an + * already-started backend will ignore changes to such an option in the + * configuration file. The idea is that these options are fixed for a + * given backend once it's started, but they can vary across backends. + * + * SUSET options can be set at postmaster startup, with the SIGHUP + * mechanism, or from SQL if you're a superuser. + * + * USERSET options can be set by anyone any time. + */ +typedef enum { + GTMC_DEFAULT, + GTMC_STARTUP, + GTMC_SIGHUP, + GTMC_USERSET +} GtmOptContext; + +/* + * The following type records the source of the current setting. A + * new setting can only take effect if the previous setting had the + * same or lower level. (E.g, changing the config file doesn't + * override the postmaster command line.) Tracking the source allows us + * to process sources in any convenient order without affecting results. + * Sources <= GTMC_S_OVERRIDE will set the default used by RESET, as well + * as the current value. Note that source == GTMC_S_OVERRIDE should be + * used when setting a GTMC_INTERNAL option. + * + * GTMC_S_INTERACTIVE isn't actually a source value, but is the + * dividing line between "interactive" and "non-interactive" sources for + * error reporting purposes. + * + * GTMC_S_TEST is used when testing values to be stored as per-database or + * per-user defaults ("doit" will always be false, so this never gets stored + * as the actual source of any value). This is an interactive case, but + * it needs its own source value because some assign hooks need to make + * different validity checks in this case. + * + * NB: see GtmOptSource_Names in gtm_opt.c and gtm_proxy_opt.c if you change this. + */ +typedef enum { + GTMC_S_DEFAULT, /* hard-wired default ("boot_val") */ + GTMC_S_DYNAMIC_DEFAULT, /* default computed during initialization */ + GTMC_S_ENV_VAR, + /* postmaster environment variable */ /* Not used in GTM */ + GTMC_S_FILE, /* gtm.conf or gtm_proxy.conf */ + GTMC_S_ARGV, /* postmaster command line */ + GTMC_S_DATABASE, + /* per-database setting */ /* Not used in GTM */ + GTMC_S_USER, + /* per-user setting */ /* Not used in GTM */ + GTMC_S_DATABASE_USER, + /* per-user-and-database setting */ /* Not used in GTM */ + GTMC_S_CLIENT, + /* from client connection request */ /* Not used in GTM */ + GTMC_S_OVERRIDE, + /* special case to forcibly set default */ /* Not used in GTM */ + GTMC_S_INTERACTIVE, + /* dividing line for error reporting */ /* Not used in GTM */ + GTMC_S_TEST, + /* test per-database or per-user setting */ /* Not used in GTM */ + GTMC_S_SESSION /* SET command */ /* Not used in GTM */ +} GtmOptSource; + +/* + * Parsing the configuration file will return a list of name-value pairs + * with source location info. + */ +typedef struct ConfigVariable { + char* name; + char* value; + char* filename; + int sourceline; + struct ConfigVariable* next; +} ConfigVariable; + +extern bool ParseConfigFile(const char *config_file, const char *calling_file, int depth, int elevel, + ConfigVariable **head_p, ConfigVariable **tail_p); +extern bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, + ConfigVariable **tail_p); +extern void FreeConfigVariables(ConfigVariable *list); + +/* + * The possible values of an enum variable are specified by an array of + * name-value pairs. The "hidden" flag means the value is accepted but + * won't be displayed when guc.c is asked for a list of acceptable values. + */ +struct config_enum_entry { + const char* name; + int val; + bool hidden; +}; + +/* + * Signatures for per-variable check/assign hook functions + */ +typedef bool (*GtmOptBoolCheckHook)(bool* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptIntCheckHook)(int* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptRealCheckHook)(double* newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptStringCheckHook)(char** newval, void** extra, GtmOptSource source); +typedef bool (*GtmOptEnumCheckHook)(int* newval, void** extra, GtmOptSource source); + +typedef void (*GtmOptBoolAssignHook)(bool newval, void* extra); +typedef void (*GtmOptIntAssignHook)(int newval, void* extra); +typedef void (*GtmOptRealAssignHook)(double newval, void* extra); +typedef void (*GtmOptStringAssignHook)(const char* newval, void* extra); +typedef void (*GtmOptEnumAssignHook)(int newval, void* extra); + +/* + * Miscellaneous + */ +/* + * GTM does not have SET command so it is not used in GTM. It's a dummy. + */ +typedef enum { + /* Types of set_config_option actions */ + GTMOPT_ACTION_SET, /* regular SET command */ + GTMOPT_ACTION_LOCAL, /* SET LOCAL command */ + GTMOPT_ACTION_SAVE /* function SET option */ +} GtmOptAction; + +#define GTMOPT_QUALIFIER_SEPARATOR '.' + +/* + * bit values in "flags" of a GUC variable + */ +#define GTMOPT_LIST_INPUT 0x0001 /* input can be list format */ +#define GTMOPT_LIST_QUOTE 0x0002 /* double-quote list elements */ +#define GTMOPT_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */ +#define GTMOPT_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */ +#define GTMOPT_REPORT 0x0010 /* auto-report changes to client */ +#define GTMOPT_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */ +#define GTMOPT_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */ +#define GTMOPT_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */ +#define GTMOPT_SUPERUSER_ONLY 0x0100 /* show only to superusers */ +#define GTMOPT_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */ + +#define GTMOPT_UNIT_KB 0x0400 /* value is in kilobytes */ +#define GTMOPT_UNIT_BLOCKS 0x0800 /* value is in blocks */ +#define GTMOPT_UNIT_XBLOCKS 0x0C00 /* value is in xlog blocks */ +#define GTMOPT_UNIT_MEMORY 0x0C00 /* mask for KB, BLOCKS, XBLOCKS */ + +#define GTMOPT_UNIT_MS 0x1000 /* value is in milliseconds */ +#define GTMOPT_UNIT_S 0x2000 /* value is in seconds */ +#define GTMOPT_UNIT_MIN 0x4000 /* value is in minutes */ +#define GTMOPT_UNIT_TIME 0x7000 /* mask for MS, S, MIN */ + +#define GTMOPT_NOT_WHILE_SEC_REST 0x8000 /* can't set if security restricted */ + +/* + * Functions exported by gtm_opt.c + */ +extern void SetConfigOption(const char* name, const char* value, GtmOptContext context, GtmOptSource source); + +extern void EmitWarningsOnPlaceholders(const char* className); + +extern const char* GetConfigOption(const char* name, bool restrict_superuser); +extern const char* GetConfigOptionResetString(const char* name); +extern void ProcessConfigFile(GtmOptContext context); +extern void InitializeGTMOptions(void); +extern bool SelectConfigFiles(const char* userDoption, const char* progname); +extern void ResetAllOptions(void); +extern int NewGTMNestLevel(void); +extern bool parse_int(const char *value, int *result, int flags, const char **hintmsg); +extern bool parse_real(const char *value, double *result); +extern bool set_config_option(const char *name, const char *value, GtmOptContext context, GtmOptSource source, + bool changeVal); + +extern char* GetConfigOptionByName(const char* name, const char** varname); +extern void GetConfigOptionByNum(int varnum, const char** values, bool* noshow); +extern int GetNumConfigOptions(void); +extern void ParseLongOption(const char* string, char** name, char** value); + +#ifndef PG_KRB_SRVTAB +#define PG_KRB_SRVTAB "" +#endif +#ifndef PG_KRB_SRVNAM +#define PG_KRB_SRVNAM "" +#endif + +/* upper limit for GUC variables measured in kilobytes of memory */ +/* note that various places assume the byte size fits in a "long" variable */ +#if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4 +#define MAX_KILOBYTES INT_MAX +#else +#define MAX_KILOBYTES (INT_MAX / 1024) +#endif + +#ifdef TRACE_SORT +extern THR_LOCAL bool trace_sort; +#endif +#ifdef TRACE_SYNCSCAN +extern bool trace_syncscan; +#endif +#ifdef DEBUG_BOUNDED_SORT +extern bool optimize_bounded_sort; +#endif + +/* + * Log_min_messages ENUM strings + */ +#define Server_Message_Level_Options() \ + static const struct config_enum_entry server_message_level_options[] = {{"debug", DEBUG2, true}, \ + {"debug5", DEBUG5, false}, \ + {"debug4", DEBUG4, false}, \ + {"debug3", DEBUG3, false}, \ + {"debug2", DEBUG2, false}, \ + {"debug1", DEBUG1, false}, \ + {"info", INFO, false}, \ + {"notice", NOTICE, false}, \ + {"warning", WARNING, false}, \ + {"error", ERROR, false}, \ + {"log", LOG, false}, \ + {"fatal", FATAL, false}, \ + {"panic", PANIC, false}, \ + {NULL, 0, false}} + +/* + * Server Startup Option ENUM strings + */ +#define Gtm_Startup_Mode_Options() \ + static const struct config_enum_entry gtm_startup_mode_options[] = { \ + {"act", GTM_ACT_MODE, false}, {"standby", GTM_STANDBY_MODE, false}, {NULL, 0, false}} + +/* + * Gtm Synchronous Option ENUM strings + */ +#define Gtm_Sync_Options() \ + static const struct config_enum_entry gtm_sync_options[] = {{"off", SYNC_GTM_OFF, false}, \ + {"on", SYNC_GTM_ON, false}, \ + {"auto", SYNC_GTM_AUTO, false}, \ + {"true", SYNC_GTM_ON, true}, \ + {"false", SYNC_GTM_OFF, true}, \ + {"yes", SYNC_GTM_ON, true}, \ + {"no", SYNC_GTM_OFF, true}, \ + {"1", SYNC_GTM_ON, true}, \ + {"0", SYNC_GTM_OFF, true}, \ + {NULL, 0, false}} + +/* + * Gtm Authentication Type ENUM strings + */ +#define Gtm_Authentication_Options() \ + static const struct config_enum_entry gtm_authentication_options[] = { \ + {"trust", GTM_AUTH_TRUST, false}, {"gss", GTM_AUTH_GSS, false}, {NULL, 0, false}} + +/* + * Displayable names for context types (enum GtmContext) + * + * Note: these strings are deliberately not localized. + */ +#define gtmOptContext_Names() \ + const char* const GtmOptContext_Names[] = {/* GTMC_STGARTUP */ "startup", /* GTMC_SIGHUP */ "sighup"} + +/* + * Displayable names for source types (enum GtmSource) + * + * Note: these strings are deliberately not localized. + */ +#define gtmOptSource_Names() \ + const char* const GtmOptSource_Names[] = {/* GTMC_S_DEFAULT */ "default", \ + /* GTMC_S_DYNAMIC_DEFAULT */ "default", \ + /* GTMC_S_ENV_VAR */ "environment variable", \ + /* GTMC_S_FILE */ "configuration file", \ + /* GTMC_S_ARGV */ "command line", \ + /* GTMC_S_DATABASE */ "database", \ + /* GTMC_S_USER */ "user", \ + /* GTMC_S_DATABASE_USER */ "database user", \ + /* GTMC_S_CLIENT */ "client", \ + /* GTMC_S_OVERRIDE */ "override", \ + /* GTMC_S_INTERACTIVE */ "interactive", \ + /* GTMC_S_TEST */ "test", \ + /* GTMC_S_SESSION */ "session"} + +/* + * Displayable names for GTM variable types (enum config_type) + * + * Note: these strings are deliberately not localized. + */ +#define Config_Type_Names() \ + const char *const config_type_names[] = { /* GTMC_BOOL */ "bool", /* GTMC_INT */ "integer", \ + /* GTMC_REAL */ "real", /* GTMC_STRING */ "string", \ + /* GTMC_ENUM */ "enum" } + +/* + * Option name defintion --- common to gtm.conf and gtm_proxy.conf + * + * This will be used both in *.conf and command line option override. + * Add local_host and local_port for ha to get connect to standby + */ + +#define GTM_OPTNAME_LOCAL_HOST "local_host" +#define GTM_OPTNAME_LOCAL_PORT "local_port" +#define GTM_OPTNAME_ACTIVE_HOST "active_host" +#define GTM_OPTNAME_ACTIVE_PORT "active_port" +#define GTM_OPTNAME_STANDBY_CONNECT_TIMEOUT "standby_connection_timeout" +#define GTM_OPTNAME_CONFIG_FILE "config_file" +#define GTM_OPTNAME_DATA_DIR "data_dir" +#define GTM_OPTNAME_CONNECT_RETRY_INTERVAL "gtm_connect_retry_interval" +#define GTM_OPTNAME_GTM_HOST "gtm_host" +#define GTM_OPTNAME_GTM_PORT "gtm_port" +#define GTM_OPTNAME_KEEPALIVES_IDLE "keepalives_idle" +#define GTM_OPTNAME_KEEPALIVES_INTERVAL "keepalives_interval" +#define GTM_OPTNAME_KEEPALIVES_COUNT "keepalives_count" +#define GTM_OPTNAME_LISTEN_ADDRESSES "listen_addresses" +#define GTM_OPTNAME_LOG_FILE "log_file" +#define GTM_OPTNAME_LOG_DIRECTORY "log_directory" +#define GTM_OPTNAME_LOG_MIN_MESSAGES "log_min_messages" +#define GTM_OPTNAME_NODENAME "nodename" +#define GTM_OPTNAME_PORT "port" +#define GTM_OPTNAME_SYNCHRONOUS_BACKUP "synchronous_backup" +#define GTM_OPTNAME_WORKER_THREADS "worker_threads" +#define GTM_OPTNAME_ALARM_COMPONENT "alarm_component" +#define GTM_OPTNAME_ALARM_REPORT_INTERVAL "alarm_report_interval" + +#define GTM_OPTNAME_ENABLE_ALARM "enable_alarm" +#define GTM_OPTNAME_ACCESS_CONTROL "enable_connect_control" +#define GTM_OPTNAME_ENABLE_THREADPOOL "gtm_enable_threadpool" + +#define GTM_OPTNAME_WRM_MAX_SERVER_MEMORY "wlm_max_mem" +#define GTM_OPTNAME_WRM_QUERY_MEMORY_LIMIT "query_memory_limit" +#define GTM_OPTNAME_MAX_TRANS "gtm_max_trans" +#define GTM_OPTNAME_THREAD_NUMBER "gtm_num_threads" + +#define GTM_OPTNAME_STANDBY_ONLY "standby_only" +#define GTM_OPTION "gtm_option" +#define GTM_RESTORE_DURATION "restore_duration" +#define GTM_CSN_SYNC_INTERVAL "csn_sync_interval" + +#define GTM_DISTRIBUTE_TEST_PARAM "distribute_test_param" + +#endif /* GTM_OPT_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_opt_tables.h postgresql-hll-2.14/include/include/gtm/gtm_opt_tables.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_opt_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_opt_tables.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,190 @@ +/* ------------------------------------------------------------------------- + * + * gtm_opt_tables.h + * Declarations of tables used by GTM configuration file. + * + * Portions Copyright (c) 2011, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * src/include/gtm/gtm_opt_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_OPT_TABLES_H +#define GTM_OPT_TABLES_H + +#include "gtm/gtm_opt.h" + +/* + * GUC supports these types of variables: + */ +enum config_type { + GTMC_BOOL, + GTMC_INT, + GTMC_REAL, + GTMC_STRING, + GTMC_ENUM +}; + +union config_var_val { + bool boolval; + int intval; + double realval; + char* stringval; + int enumval; +}; + +/* + * The actual value of a GUC variable can include a malloc'd opaque struct + * "extra", which is created by its check_hook and used by its assign_hook. + */ +typedef struct config_var_value { + union config_var_val val; + void* extra; +} config_var_value; + +/* + * Stack entry for saving the state a variable had prior to an uncommitted + * transactional change. In GTM, only chance to update options is SIGINT. + */ +typedef enum { + /* This is almost GtmOptAction, but we need a fourth state for SET+LOCAL */ + GTMOPT_SAVE, /* entry caused by function SET option */ + GTMOPT_SET, /* entry caused by plain SET command */ + GTMOPT_LOCAL, /* entry caused by SET LOCAL command */ + GTMOPT_SET_LOCAL /* entry caused by SET then SET LOCAL */ +} GtmOptStackState; + +typedef struct guc_stack { + struct guc_stack* prev; /* previous stack item, if any */ + int nest_level; /* nesting depth at which we made entry */ + GtmOptStackState state; /* see enum above */ + GtmOptSource source; /* source of the prior value */ + config_var_value prior; /* previous value of variable */ + config_var_value masked; /* SET value in a GTMOPT_SET_LOCAL entry */ + /* masked value's source must be GTMC_S_SESSION, so no need to store it */ +} GtmOptStack; + +/* + * Generic fields applicable to all types of variables + * + * The short description should be less than 80 chars in length. Some + * applications may use the long description as well, and will append + * it to the short description. (separated by a newline or '. ') + * + * Note that sourcefile/sourceline are kept here, and not pushed into stacked + * values, although in principle they belong with some stacked value if the + * active value is session- or transaction-local. This is to avoid bloating + * stack entries. We know they are only relevant when source == GTMC_S_FILE. + */ +struct config_generic { + /* constant fields, must be set correctly in initial value: */ + const char* name; /* name of variable - MUST BE FIRST */ + GtmOptContext context; /* context required to set the variable */ + const char* short_desc; /* short desc. of this variable's purpose */ + const char* long_desc; /* long desc. of this variable's purpose */ + int flags; /* flag bits, see below */ + /* variable fields, initialized at runtime: */ + enum config_type vartype; /* type of variable (set only at startup) */ + int status; /* status bits, see below */ + GtmOptSource reset_source; /* source of the reset_value */ + GtmOptSource source; /* source of the current actual value */ + GtmOptStack* stack; /* stacked prior values */ + void* extra; /* "extra" pointer for current actual value */ + char* sourcefile; /* file current setting is from (NULL if not + * file) */ + int sourceline; /* line in source file */ +}; + +/* bit values in flags field are defined in guc.h */ + +/* bit values in status field */ +#define GTMOPT_IS_IN_FILE 0x0001 /* found it in config file */ +/* + * Caution: the GTMOPT_IS_IN_FILE bit is transient state for ProcessConfigFile. + * Do not assume that its value represents useful information elsewhere. + */ + +/* GUC records for specific variable types */ + +struct config_bool { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + bool* variable; + bool boot_val; + GtmOptBoolCheckHook check_hook; + GtmOptBoolAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + bool reset_val; + void* reset_extra; +}; + +struct config_int { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + int min; + int max; + GtmOptIntCheckHook check_hook; + GtmOptIntAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +struct config_real { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + double* variable; + double boot_val; + double min; + double max; + GtmOptRealCheckHook check_hook; + GtmOptRealAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + double reset_val; + void* reset_extra; +}; + +struct config_string { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + char** variable; + const char* boot_val; + GtmOptStringCheckHook check_hook; + GtmOptStringAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + char* reset_val; + void* reset_extra; +}; + +struct config_enum { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + const struct config_enum_entry* options; + GtmOptEnumCheckHook check_hook; + GtmOptEnumAssignHook assign_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +/* constant tables corresponding to enums above and in guc.h */ +extern const char* const config_group_names[]; +extern const char* const config_type_names[]; +extern const char* const GtmOptContext_Names[]; +extern const char* const GtmOptSource_Names[]; + +/* get the current set of variables */ +extern struct config_generic** get_guc_variables(void); + +extern void build_guc_variables(void); + +/* search in enum options */ +extern const char* config_enum_lookup_by_value(struct config_enum* record, int val); +extern bool config_enum_lookup_by_name(struct config_enum* record, const char* value, int* retval); + +#endif /* GTM_OPT_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_proxy.h postgresql-hll-2.14/include/include/gtm/gtm_proxy.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_proxy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_proxy.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,254 @@ +/* ------------------------------------------------------------------------- + * + * gtm_proxy.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_PROXY_H +#define _GTM_PROXY_H + +#include +#include + +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_conn.h" +#include "gtm/utils/elog.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_msg.h" +#include "gtm/utils/libpq-fe.h" + +extern char* GTMProxyLogFile; + +typedef enum GTMProxy_ThreadStatus { + GTM_PROXY_THREAD_STARTING, + GTM_PROXY_THREAD_RUNNING, + GTM_PROXY_THREAD_EXITING, + /* Must be the last */ + GTM_PROXY_THREAD_INVALID +} GTMProxy_ThreadStatus; + +typedef struct GTMProxy_ConnectionInfo { + /* Port contains all the vital information about this connection */ + Port* con_port; + struct GTMProxy_ThreadInfo* con_thrinfo; + bool con_authenticated; + bool con_disconnected; + GTMProxy_ConnID con_id; + + GTM_MessageType con_pending_msg; + GlobalTransactionId con_txid; + GTM_TransactionHandle con_handle; +} GTMProxy_ConnectionInfo; + +typedef struct GTMProxy_Connections { + uint32 gc_conn_count; + uint32 gc_array_size; + GTMProxy_ConnectionInfo* gc_connections; + GTM_RWLock gc_lock; +} GTMProxy_Connections; + +#define ERRORDATA_STACK_SIZE 20 +#define GTM_PROXY_MAX_CONNECTIONS 1024 + +typedef struct GTMProxy_ThreadInfo { + /* + * Thread specific information such as connection(s) served by it + */ + GTM_ThreadID thr_id; + uint32 thr_localid; + bool is_main_thread; + void* (*thr_startroutine)(void*); + + MemoryContext thr_thread_context; + MemoryContext thr_message_context; + MemoryContext thr_current_context; + MemoryContext thr_error_context; + MemoryContext thr_parent_context; + + sigjmp_buf* thr_sigjmp_buf; + + ErrorData thr_error_data[ERRORDATA_STACK_SIZE]; + int thr_error_stack_depth; + int thr_error_recursion_depth; + int thr_criticalsec_count; + + GTMProxy_ThreadStatus thr_status; + GTMProxy_ConnectionInfo* thr_conn; /* Current set of connections from clients */ + uint32 thr_conn_count; /* number of connections served by this thread */ + + /* + * The structure member type/sequence upto this point must match the + * GTM_ThreadInfo structure in gtm.h since they are shared in some common + * library routines such as elog.c. Keeping them in sync helps us use the + * same library for the proxy as well as the server. + */ + GTM_MutexLock thr_lock; + GTM_CV thr_cv; + + /* + * We use a sequence number to track the state of connection/fd array. + * Whenever a new connection is added or an existing connection is deleted + * from the connection array, the sequence number is incremented. The + * thread main routine can then reconstruct the fd array again. + */ + int32 thr_seqno; + + /* connection array */ + GTMProxy_ConnectionInfo* thr_all_conns[GTM_PROXY_MAX_CONNECTIONS]; + struct pollfd thr_poll_fds[GTM_PROXY_MAX_CONNECTIONS]; + + /* Command backup */ + short thr_any_backup[GTM_PROXY_MAX_CONNECTIONS]; + int thr_qtype[GTM_PROXY_MAX_CONNECTIONS]; + StringInfoData thr_inBufData[GTM_PROXY_MAX_CONNECTIONS]; + + gtm_List* thr_processed_commands; + gtm_List* thr_pending_commands[MSG_TYPE_COUNT]; + + GTM_Conn* thr_gtm_conn; /* Connection to GTM */ + + /* Reconnect Info */ + int can_accept_SIGUSR2; + int reconnect_issued; + int can_longjmp; + sigjmp_buf longjmp_env; + +} GTMProxy_ThreadInfo; + +typedef struct GTMProxy_Threads { + uint32 gt_thread_count; + uint32 gt_array_size; + uint32 gt_next_worker; + GTMProxy_ThreadInfo** gt_threads; + GTM_RWLock gt_lock; +} GTMProxy_Threads; + +extern GTMProxy_Threads* GTMProxyThreads; + +int GTMProxy_ThreadAdd(GTMProxy_ThreadInfo* thrinfo); +int GTMProxy_ThreadRemove(GTMProxy_ThreadInfo* thrinfo); +int GTMProxy_ThreadJoin(GTMProxy_ThreadInfo* thrinfo); +void GTMProxy_ThreadExit(void); + +extern GTMProxy_ThreadInfo* GTMProxy_ThreadCreate(void* (*startroutine)(void*), int idx); +extern GTMProxy_ThreadInfo* GTMProxy_GetThreadInfo(GTM_ThreadID thrid); +extern GTMProxy_ThreadInfo* GTMProxy_ThreadAddConnection(GTMProxy_ConnectionInfo* conninfo); +extern int GTMProxy_ThreadRemoveConnection(GTMProxy_ThreadInfo* thrinfo, GTMProxy_ConnectionInfo* conninfo); + +/* + * Command data - the only relevant information right now is the XID + * and data necessary for registering (modification of Proxy number registered) + */ +typedef union GTMProxy_CommandData { + struct { + bool rdonly; + GTM_IsolationLevel iso_level; + } cd_beg; + + struct { + bool isgxid; + GlobalTransactionId gxid; + GTM_TransactionHandle handle; + } cd_rc; + + struct { + bool isgxid; + GlobalTransactionId gxid; + GTM_TransactionHandle handle; + } cd_snap; + + struct { + GTM_PGXCNodeType type; + char* nodename; + GTM_PGXCNodePort port; + char* gtm_proxy_nodename; + char* datafolder; + char* ipaddress; + uint32 timeline; + GTM_PGXCNodeStatus status; + } cd_reg; +} GTMProxy_CommandData; + +/* + * Structures to be used for message proxing. There will be one such entry for + * each pending command from a backend. To keep it simple, we have a separate + * entry even if the commands are grouped together. + * + * An array of these entries is maintained which is sorted by the order in + * which the commands are sent to the GTM server. We expect the GTM server to + * respond back in the same order and the sorted array helps us in + * matching/confirming the responses. + */ +typedef struct GTMProxy_CommandInfo { + GTM_MessageType ci_mtype; + int ci_res_index; + GTMProxy_CommandData ci_data; + GTMProxy_ConnectionInfo* ci_conn; +} GTMProxy_CommandInfo; + +/* + * pthread keys to get thread specific information + */ +extern pthread_key_t threadinfo_key; +extern MemoryContext TopMostMemoryContext; +extern char* GTMLogFileName; +extern char* Log_directory; +extern GTM_RWLock gtmlogFileLock; +extern GTM_ThreadID TopMostThreadID; + +#define SetMyThreadInfo(thrinfo) pthread_setspecific(threadinfo_key, (thrinfo)) +#define GetMyThreadInfo ((GTMProxy_ThreadInfo*)pthread_getspecific(threadinfo_key)) + +#define TopMemoryContext (GetMyThreadInfo->thr_thread_context) +#define ThreadTopContext (GetMyThreadInfo->thr_thread_context) +#define MessageContext (GetMyThreadInfo->thr_message_context) +#define CurrentMemoryContext (GetMyThreadInfo->thr_current_context) +#define ErrorContext (GetMyThreadInfo->thr_error_context) +#define errordata (GetMyThreadInfo->thr_error_data) +#define recursion_depth (GetMyThreadInfo->thr_error_recursion_depth) +#define errordata_stack_depth (GetMyThreadInfo->thr_error_stack_depth) +#define CritSectionCount (GetMyThreadInfo->thr_criticalsec_count) + +#define PG_exception_stack (GetMyThreadInfo->thr_sigjmp_buf) +#define MyConnection (GetMyThreadInfo->thr_conn) +#define MyPort ((GetMyThreadInfo->thr_conn != NULL) ? GetMyThreadInfo->thr_conn->con_port : NULL) +#define MyThreadID (GetMyThreadInfo->thr_id) + +#define START_CRIT_SECTION() (t_thrd.int_cxt.CritSectionCount++) + +#define END_CRIT_SECTION() do { \ + Assert(t_thrd.int_cxt.CritSectionCount > 0); \ + t_thrd.int_cxt.CritSectionCount--; \ +} while (0) + +/* Signal Handler controller */ +#define SIGUSR2DETECTED() (GetMyThreadInfo->reconnect_issued == TRUE) +#define RECONNECT_LONGJMP() do { \ + longjmp(GetMyThreadInfo->longjmp_env, 1); \ +} while (0) +#if 1 +#define Disable_Longjmp() do { \ + GetMyThreadInfo->can_longjmp = FALSE; \ +} while (0) +#define Enable_Longjmp() do { \ + if (SIGUSR2DETECTED()) { \ + RECONNECT_LONGJMP(); \ + } else { \ + GetMyThreadInfo->can_longjmp = TRUE; \ + } \ +} while (0) +#else +#define Disable_Longjmp() +#define Enable_Longjmp() +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_semaphore.h postgresql-hll-2.14/include/include/gtm/gtm_semaphore.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_semaphore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_semaphore.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,126 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_semaphore.h + * Wrapper semaphore for the sysv sema. Currently the database only use the + * sysv sema. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_semaphore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _GTM_SEMA_H +#define _GTM_SEMA_H + +#include +#include + +typedef struct PGSemaphoreData { + int semId; /* semaphore set identifier */ + int semNum; /* semaphore number within set */ +} PGSemaphoreData; + +typedef PGSemaphoreData* PGSemaphore; + +/* key_t is the int type */ +typedef key_t IpcSemaphoreKey; /* semaphore key passed to semget */ +typedef int IpcSemaphoreId; /* semaphore ID returned by semget */ + +#define GTM_MAX_SEMASET (GTM_MAX_GLOBAL_TRANSACTIONS * 2) + +/* + * it is used to assign sema key. if the is_used[index] is true, + * it means that the index key is used. + */ +typedef struct GlobalSemaKeySet { + bool is_used[GTM_MAX_SEMASET]; + int current_key; /* current used sema key, default value is invalid. */ +} GlobalSemaKeySet; + +/* + * the number of sema sets. when create one sema set, + * must set the sema number. the valid sema number is SEMA_SET_NUM. + * when we create the sema set, we assign the sema num is SEMA_SET_NUM + 1, + * it stat from 0. the SEMA_SET_NUM sema is setted to PGSemaMagic, PGSemaMagic + * represents the sema set is create by GTM Thread. + */ +#define SEMA_SET_NUM 1 + +/** + * @Description: init glocal sema key. set current sema key is invalid. + * and init the lock. Only the main thread can call this function. + * destory the lock also is called by main thread only. + * @return none. + */ +void init_global_sema_key(); + +/** + * @Description: destroy sema_key lock + * @return none. + */ +void destory_sema_key_lock(); + +/** + * @Description: get the global seme key for creating the sema. + * If could not get the sema key. report the error. + * @return return the sema key. + */ +int get_next_sema_key(); + +/** + * @Description: the thread will exit, we must reset the global sema in + * order to be used by other new thread. + * @in seme_key, the given key to be reset. + * @return none. + */ +void reset_sema_key(int sema_key); + +/** + * @Description: create sema and init the sema by the given value. + * we store the sema id in seme->semId. seme->semNum keeps the index of this + * sema set array. + * @in key, the given key for sema. + * @in value, the given initial value. + * @return none + */ +void create_sema(PGSemaphore sema, IpcSemaphoreKey& key, int value); + +/** + * @Description: Lock a semaphore (decrement count), blocking if + * count would be < 0. + * @return none. + */ +void sema_lock(PGSemaphore sema); + +/** + * @Description: Unlock a semaphore (increment count) + * @return none. + */ +void sema_unlock(PGSemaphore sema); + +/** + * @Description: release the sema when current thread exit. + * @in sema, it keeps the sema id info. + * do the following things: + * 1. release the sema from the system kenel. + * 2. release the sema memory. + * 3. set the is_used of GlobalSemaKeySet to false. + * @return none + */ +void release_sema(PGSemaphore sema); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_seq.h postgresql-hll-2.14/include/include/gtm/gtm_seq.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_seq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_seq.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,167 @@ +/* ------------------------------------------------------------------------- + * + * gtm_seq.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_SEQ_H +#define GTM_SEQ_H + +#include "gtm/utils/stringinfo.h" +#include "gtm/gtm_lock.h" +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_list.h" +#include "gtm/gtm_msg.h" + +typedef volatile int32 pg_atomic_int32; +typedef volatile uint32 pg_atomic_uint32; + +/* Global sequence related structures */ +typedef struct GTM_SeqUUID { + GTM_UUID uuid_nextId; + GTM_UUID uuid_backUpId; + GTM_RWLock uuid_seqLock; +} GTM_SeqUUID; + +extern GTM_SeqUUID GTMSeqUUID; + +typedef struct GTM_SeqInfo { + GTM_SequenceKey gs_key; + GTM_UUID gs_seqId; + GTM_Sequence gs_value; + GTM_Sequence gs_backedUpValue; + GTM_Sequence gs_init_value; + GTM_Sequence gs_last_value; + GTM_Sequence gs_increment_by; + GTM_Sequence gs_min_value; + GTM_Sequence gs_max_value; + GTM_Sequence gs_range; /* cache in client */ + + /* + * the blocked list for the same sequence, wait until gs_backedUpValue is synced + * to standby/etcd successfully. + * thread index will be remmebered, see also GTM_ThreadInfo::next_blocked_thread. + */ + pg_atomic_uint32 gs_blocked_head; + + pg_atomic_int32 gs_ref_count; + int32 gs_state; + GTM_RWLock gs_lock; + GTM_DBName gs_database; + + /* true if need to backup. reset false after backup finish. */ + bool gs_need_backup; + bool gs_called_after_startup; + bool gs_cycle; + bool gs_called; +} GTM_SeqInfo; + +typedef struct { + GTM_UUID seq_uuid; + GTM_Sequence increment; + GTM_Sequence minval; + GTM_Sequence maxval; + GTM_Sequence startval; + GTM_Sequence lastval; + GTM_Sequence range; + bool cycle; + bool is_standby; + bool is_restart; +} GTM_SeqMsgData; + +typedef struct GTM_ThreadSeqInfo { + GTM_SeqInfo* seqinfo; + GTM_Sequence range; + GTM_Sequence* rangemax; + bool backup; + GTM_Sequence seq_value; +} GTM_ThreadSeqInfo; + +#define SEQ_STATE_ACTIVE 1 +#define SEQ_STATE_DELETED 2 + +#define SEQ_IS_ASCENDING(s) ((s)->gs_increment_by > 0) +#define SEQ_IS_CYCLE(s) ((s)->gs_cycle) +#define SEQ_IS_CALLED(s) ((s)->gs_called) + +#define SEQ_DEF_MAX_SEQVAL_ASCEND 0x7ffffffffffffffeLL +#define SEQ_DEF_MIN_SEQVAL_ASCEND 0x1 + +#define SEQ_DEF_MAX_SEQVAL_DESCEND -0x1 +#define SEQ_DEF_MIN_SEQVAL_DESCEND -0x7ffffffffffffffeLL + +#define MaxGlobalUUId ((GTM_UUID)0x7fffffffffffffffLL) + +#define SEQ_MAX_REFCOUNT 1024 + +/* SEQUENCE Management */ +void GTM_InitSeqManager(void); +int GTM_SeqOpen(GTM_UUID seq_uuid, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, bool cycle, GTM_DBName seq_dbName, bool is_backup); +int GTM_SeqAlter(GTM_SeqMsgData* msg); +int GTM_SeqClose(GTM_UUID seq_uuid, GTM_DBName seq_dbName); +int GTM_SeqDBRename(GTM_DBName dbName, GTM_DBName newdbName); +GTM_Sequence GTM_SeqGetNext(GTM_SeqMsgData* msg, GTM_Sequence* rangemax); +int GTM_SeqSetVal(GTM_UUID seq_uuid, GTM_Sequence nextval, GTM_Sequence range, bool iscalled); +int GTM_SeqReset(GTM_UUID seq_uuid); +void GTM_SyncSequence(GTM_MessageType mtype, GTM_UUID seq_uuid, GTM_SeqInfo *thisSeq, GTM_DBName dbName = NULL, + GTM_DBName newdbName = NULL); +bool GTM_SyncSequenceToStandby(GTM_MessageType mtype, GTM_UUID seq_uuid, GTM_SeqInfo *thisSeq, GTM_DBName dbName, + GTM_DBName newdbName = NULL); + +void GTM_SyncUUID(GTM_UUID seq_uuid); +void GTM_GetSyncUUIDFromEtcd(); +bool GTM_GetUUIDFromEtcd(GTM_UUID& seq_uuid, bool force); +bool GTM_SyncUUIDToStandby(GTM_UUID seq_uuid); + +void ProcessSequenceGetUUIDCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceInitCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceGetNextCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceSetValCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceResetCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceCloseCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceDBRenameCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessSequenceAlterCommand(Port* myport, StringInfo message, bool is_backup); + +void ProcessSequenceListCommand(Port* myport, StringInfo message); +void ProcessBkupGTMSequenceFileUUIDCommand(Port* myport, StringInfo message); +void ProcessGetNextSeqUUIDTransactionCommand(Port* myport, StringInfo message); + +void GTM_SaveSeqInfo(FILE* ctlf); +void GTM_RestoreSeqUUIDInfo(FILE* ctlf); +int GTM_SeqRestore(GTM_SequenceKey seqkey, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence curval, int32 state, bool cycle, bool called); +int GTM_SeqUUIDRestore(GTM_UUID seq_uuid, GTM_Sequence increment_by, GTM_Sequence minval, GTM_Sequence maxval, + GTM_Sequence startval, GTM_Sequence curval, GTM_Sequence range, int32 state, bool cycle, + bool called, GTM_DBName seq_dbName); + +void GTM_RestoreUUIDInfo(FILE* seqf, GTM_UUID seq_uuid); +void SetNextGlobalUUID(GTM_UUID seq_uuid); +bool GlobalUUIDIsValid(GTM_UUID seq_uuid); +bool GTM_NeedUUIDRestoreUpdate(void); + +bool GTM_NeedSeqRestoreUpdate(GTM_UUID seq_uuid); +void GTM_WriteRestorePointSeq(FILE* ctlf, GTM_UUID* seqId, bool all_seq_restore); + +void RemoveGTMSeqs(void); + +void GTM_WriteRestorePointUUID(FILE* file, bool uuid_restore); + +void GTM_SaveUUIDInfo(FILE* file); +GTM_UUID ReadNewGlobalUUId(); + +bool GTM_SetSeqToEtcd(GTM_MessageType mtype, GTM_SeqInfo* thisSeq, bool isBackup, GTM_UUID seq_uuid); +extern void release_group_seq_lock(); +void handleGetSeqException(); + +bool GTM_SetUUIDToEtcd(GTM_UUID seq_uuid, bool save); +bool GTMSyncUUIDToEtcdInternal(GTM_UUID seq_uuid, bool force); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_serialize_debug.h postgresql-hll-2.14/include/include/gtm/gtm_serialize_debug.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_serialize_debug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_serialize_debug.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * gtm_serialize_debug.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_serialize_debug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_SERIALIZE_DEBUG_H +#define GTM_SERIALIZE_DEBUG_H + +#include + +#include "gtm/gtm_txn.h" + +void dump_transactions_elog(GTM_Transactions*, int); +void dump_transactioninfo_elog(GTM_TransactionInfo*); + +#endif /* GTM_SERIALIZE_DEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_serialize.h postgresql-hll-2.14/include/include/gtm/gtm_serialize.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_serialize.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_serialize.h 2020-12-12 17:06:43.204347483 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * gtm_serialize.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_serialize.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_SERIALIZE_H +#define GTM_SERIALIZE_H + +#include + +#include "gtm/gtm_c.h" +#include "gtm/gtm_txn.h" +#include "gtm/utils/register.h" +#include "gtm/gtm_seq.h" + +size_t gtm_get_snapshotdata_size(GTM_SnapshotData*); +size_t gtm_serialize_snapshotdata(GTM_SnapshotData*, char*, size_t); +size_t gtm_deserialize_snapshotdata(GTM_SnapshotData*, const char*, size_t); + +size_t gtm_get_transactioninfo_size(GTM_TransactionInfo*); +size_t gtm_serialize_transactioninfo(GTM_TransactionInfo*, char*, size_t); +size_t gtm_deserialize_transactioninfo(GTM_TransactionInfo*, const char*, size_t); + +size_t gtm_get_transactions_size(GTM_Transactions*); +size_t gtm_serialize_transactions(GTM_Transactions*, char*, size_t); +size_t gtm_deserialize_transactions(GTM_Transactions*, const char*, size_t); + +size_t gtm_get_pgxcnodeinfo_size(GTM_PGXCNodeInfo*); +size_t gtm_serialize_pgxcnodeinfo(GTM_PGXCNodeInfo*, char*, size_t); +size_t gtm_deserialize_pgxcnodeinfo(GTM_PGXCNodeInfo*, const char*, size_t); + +size_t gtm_get_sequence_size(GTM_SeqInfo*); +size_t gtm_serialize_sequence(GTM_SeqInfo*, char*, size_t); +size_t gtm_deserialize_sequence(GTM_SeqInfo* seq, const char*, size_t); + +void dump_transactions_elog(GTM_Transactions*, int); +void dump_transactioninfo_elog(GTM_TransactionInfo*); + +#endif /* GTM_SERIALIZE_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_slock.h postgresql-hll-2.14/include/include/gtm/gtm_slock.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_slock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_slock.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,1108 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_slock.h + * Hardware-dependent implementation of spinlocks. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_slock.h + * + * NOTE: none of the macros in this file are intended to be called directly. + * Call them through the hardware-independent macros in spin.h. + * + * The following hardware-dependent macros must be provided for each + * supported platform: + * + * void S_INIT_LOCK(slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void S_LOCK(slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void S_UNLOCK(slock_t *lock) + * Unlock a previously acquired lock. + * + * bool S_LOCK_FREE(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * void SPIN_DELAY(void) + * Delay operation to occur inside spinlock wait loop. + * + * Note to implementors: there are default implementations for all these + * macros at the bottom of the file. Check if your platform can use + * these or needs to override them. + * + * Usually, S_LOCK() is implemented in terms of even lower-level macros + * TAS() and TAS_SPIN(): + * + * int TAS(slock_t *lock) + * Atomic test-and-set instruction. Attempt to acquire the lock, + * but do *not* wait. Returns 0 if successful, nonzero if unable + * to acquire the lock. + * + * int TAS_SPIN(slock_t *lock) + * Like TAS(), but this version is used when waiting for a lock + * previously found to be contended. By default, this is the + * same as TAS(), but on some architectures it's better to poll a + * contended lock using an unlocked instruction and retry the + * atomic test-and-set only when it appears free. + * + * TAS() and TAS_SPIN() are NOT part of the API, and should never be called + * directly. + * + * CAUTION: on some platforms TAS() and/or TAS_SPIN() may sometimes report + * failure to acquire a lock even when the lock is not locked. For example, + * on Alpha TAS() will "fail" if interrupted. Therefore a retry loop must + * always be used, even if you are certain the lock is free. + * + * It is the responsibility of these macros to make sure that the compiler + * does not re-order accesses to shared memory to precede the actual lock + * acquisition, or follow the lock release. Prior to PostgreSQL 9.5, this + * was the caller's responsibility, which meant that callers had to use + * volatile-qualified pointers to refer to both the spinlock itself and the + * shared data being accessed within the spinlocked critical section. This + * was notationally awkward, easy to forget (and thus error-prone), and + * prevented some useful compiler optimizations. For these reasons, we + * now require that the macros themselves prevent compiler re-ordering, + * so that the caller doesn't need to take special precautions. + * + * On platforms with weak memory ordering, the TAS(), TAS_SPIN(), and + * S_UNLOCK() macros must further include hardware-level memory fence + * instructions to prevent similar re-ordering at the hardware level. + * TAS() and TAS_SPIN() must guarantee that loads and stores issued after + * the macro are not executed until the lock has been obtained. Conversely, + * S_UNLOCK() must guarantee that loads and stores issued before the macro + * have been executed before the lock is released. + * + * On most supported platforms, TAS() uses a tas() function written + * in assembly language to execute a hardware atomic-test-and-set + * instruction. Equivalent OS-supplied mutex routines could be used too. + * + * If no system-specific TAS() is available (ie, HAVE_SPINLOCKS is not + * defined), then we fall back on an emulation that uses SysV semaphores + * (see spin.c). This emulation will be MUCH MUCH slower than a proper TAS() + * implementation, because of the cost of a kernel call per lock or unlock. + * An old report is that Postgres spends around 40% of its time in semop(2) + * when using the SysV semaphore code. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef S_LOCK_H +#define S_LOCK_H + +#include "gtm/gtm_semaphore.h" + +#ifndef ENABLE_THREAD_CHECK +#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +/************************************************************************* + * All the gcc inlines + * Gcc consistently defines the CPU as __cpu__. + * Other compilers use __cpu or __cpu__ so we test for both in those cases. + */ + +/*---------- + * Standard gcc asm format (assuming "volatile slock_t *lock"): + + __asm__ __volatile__( + " instruction \n" + " instruction \n" + " instruction \n" +: "=r"(_res), "+m"(*lock) // return register, in/out lock value +: "r"(lock) // lock pointer, in input register +: "memory", "cc"); // show clobbered registers here + + * The output-operands list (after first colon) should always include + * "+m"(*lock), whether or not the asm code actually refers to this + * operand directly. This ensures that gcc believes the value in the + * lock variable is used and set by the asm code. Also, the clobbers + * list (after third colon) should always include "memory"; this prevents + * gcc from thinking it can cache the values of shared-memory fields + * across the asm code. Add "cc" if your asm code changes the condition + * code register, and also list any temp registers the code uses. + *---------- + */ + +#ifdef __i386__ /* 32-bit i386 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * Use a non-locking test before asserting the bus lock. Note that the + * extra test appears to be a small loss on some x86 platforms and a small + * win on others; it's by no means clear that we should keep it. + */ + __asm__ __volatile__(" cmpb $0,%1 \n" + " jne 1f \n" + " lock \n" + " xchgb %0,%1 \n" + "1: \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * This sequence is equivalent to the PAUSE instruction ("rep" is + * ignored by old IA32 processors if the following instruction is + * not a string operation); the IA-32 Architecture Software + * Developer's Manual, Vol. 3, Section 7.7.2 describes why using + * PAUSE in the inner loop of a spin lock is necessary for good + * performance: + * + * The PAUSE instruction improves the performance of IA-32 + * processors supporting Hyper-Threading Technology when + * executing spin-wait loops and other routines where one + * thread is accessing a shared lock or semaphore in a tight + * polling loop. When executing a spin-wait loop, the + * processor can suffer a severe performance penalty when + * exiting the loop because it detects a possible memory order + * violation and flushes the core processor's pipeline. The + * PAUSE instruction provides a hint to the processor that the + * code sequence is a spin-wait loop. The processor uses this + * hint to avoid the memory order violation and prevent the + * pipeline flush. In addition, the PAUSE instruction + * de-pipelines the spin-wait loop to prevent it from + * consuming execution resources excessively. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __i386__ */ + +#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * On Opteron, using a non-locking test before the locking instruction + * is a huge loss. On EM64T, it appears to be a wash or small loss, + * so we needn't bother to try to distinguish the sub-architectures. + */ + __asm__ __volatile__(" lock \n" + " xchgb %0,%1 \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * Adding a PAUSE in the spin delay loop is demonstrably a no-op on + * Opteron, but it may be of some use on EM64T, so we keep it. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __x86_64__ */ + +#if defined(__ia64__) || defined(__ia64) +/* + * Intel Itanium, gcc or Intel's compiler. + * + * Itanium has weak memory ordering, but we rely on the compiler to enforce + * strict ordering of accesses to volatile data. In particular, while the + * xchg instruction implicitly acts as a memory barrier with 'acquire' + * semantics, we do not have an explicit memory fence instruction in the + * S_UNLOCK macro. We use a regular assignment to clear the spinlock, and + * trust that the compiler marks the generated store instruction with the + * ".rel" opcode. + * + * Testing shows that assumption to hold on gcc, although I could not find + * any explicit statement on that in the gcc manual. In Intel's compiler, + * the -m[no-]serialize-volatile option controls that, and testing shows that + * it is enabled by default. + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +#ifndef __INTEL_COMPILER + +static __inline__ int tas(volatile slock_t* lock) +{ + long int ret; + + __asm__ __volatile__(" xchg4 %0=%1,%2 \n" : "=r"(ret), "+m"(*lock) : "r"(1) : "memory"); + return (int)ret; +} + +#else /* __INTEL_COMPILER */ + +static __inline__ int tas(volatile slock_t* lock) +{ + int ret; + + ret = _InterlockedExchange(lock, 1); /* this is a xchg asm macro */ + + return ret; +} + +#endif /* __INTEL_COMPILER */ +#endif /* __ia64__ || __ia64 */ + +/* + * On ARM64, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ + +#if defined(__aarch64__) || defined(__aarch64) + +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int + + tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile register slock_t* ulAddr = lock; + register slock_t _res = 1; + unsigned int tmp = 0; + + __asm__ volatile("// __xchg4\n" + "1: ldaxr %w0, %2\n" + " stlxr %w1, %w3, %2\n" + " cbnz %w1, 1b\n" + : "=&r"(_res), "=&r"(tmp), "+Q"(*ulAddr) + : "r"(_res) + : "cc", "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __aarch64__ */ + +/* + * On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ +#if defined(__arm__) || defined(__arm) +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned char slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + __asm__ __volatile__(" swpb %0, %0, [%2] \n" : "+r"(_res), "+m"(*lock) : "r"(lock) : "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __arm__ */ + +/* S/390 and S/390x Linux (32- and 64-bit zSeries) */ +#if defined(__s390__) || defined(__s390x__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + int _res = 0; + + __asm__ __volatile__(" cs %0,%3,0(%2) \n" : "+d"(_res), "+m"(*lock) : "a"(lock), "d"(1) : "memory", "cc"); + return _res; +} + +#endif /* __s390__ || __s390x__ */ + +#if defined(__sparc__) /* Sparc */ +/* + * Solaris has always run sparc processors in TSO (total store) mode, but + * linux didn't use to and the *BSDs still don't. So, be careful about + * acquire/release semantics. The CPU will treat superflous membars as NOPs, + * so it's just code space. + */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + /* + * See comment in /pg/backend/port/tas/solaris_sparc.s for why this + * uses "ldstub", and that file uses "cas". gcc currently generates + * sparcv7-targeted binaries, so "cas" use isn't possible. + */ + __asm__ __volatile__(" ldstub [%2], %0 \n" : "=r"(_res), "+m"(*lock) : "r"(lock) : "memory"); +#if defined(__sparcv7) + /* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. + */ +#elif defined(__sparcv8) + /* stbar is available (and required for both PSO, RMO), membar isn't */ + __asm__ __volatile__("stbar \n" ::: "memory"); +#else + /* + * #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire + * barrier for sparcv8+ upwards. + */ + __asm__ __volatile__("membar #LoadStore | #LoadLoad \n" ::: "memory"); +#endif + return (int)_res; +} + +#if defined(__sparcv7) +/* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. We fall through to the default gcc definition of + * S_UNLOCK in this case. + */ +#elif defined(__sparcv8) +/* stbar is available (and required for both PSO, RMO), membar isn't */ +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("stbar \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#else +/* + * #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate + * release barrier for sparcv8+ upwards. + */ +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("membar #LoadStore | #StoreStore \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#endif + +#endif /* __sparc__ */ + +/* PowerPC */ +#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On PPC, it's a win to use a non-locking test before the lwarx */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +/* + * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002, + * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop. + * On newer machines, we can use lwsync instead for better performance. + */ +static __inline__ int tas(volatile slock_t* lock) +{ + slock_t _t; + int _res; + + __asm__ __volatile__( +#ifdef USE_PPC_LWARX_MUTEX_HINT + " lwarx %0,0,%3,1 \n" +#else + " lwarx %0,0,%3 \n" +#endif + " cmpwi %0,0 \n" + " bne 1f \n" + " addi %0,%0,1 \n" + " stwcx. %0,0,%3 \n" + " beq 2f \n" + "1: li %1,1 \n" + " b 3f \n" + "2: \n" +#ifdef USE_PPC_LWSYNC + " lwsync \n" +#else + " isync \n" +#endif + " li %1,0 \n" + "3: \n" + + : "=&r"(_t), "=r"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "cc"); + return _res; +} + +/* + * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction. + * On newer machines, we can use lwsync instead for better performance. + */ +#ifdef USE_PPC_LWSYNC +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" lwsync \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#else +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" sync \n" ::: "memory"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) +#endif /* USE_PPC_LWSYNC */ + +#endif /* powerpc */ + +/* Linux Motorola 68k */ +#if (defined(__mc68000__) || defined(__m68k__)) && defined(__linux__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int rv; + + __asm__ __volatile__(" clrl %0 \n" + " tas %1 \n" + " sne %0 \n" + : "=d"(rv), "+m"(*lock) + : + : "memory", "cc"); + return rv; +} + +#endif /* (__mc68000__ || __m68k__) && __linux__ */ + +/* + * VAXen -- even multiprocessor ones + * (thanks to Tom Ivar Helbekkmo) + */ +#if defined(__vax__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" movl $1, %0 \n" + " bbssi $0, (%2), 1f \n" + " clrl %0 \n" + "1: \n" + : "=&r"(_res), "+m"(*lock) + : "r"(lock) + : "memory"); + return _res; +} + +#endif /* __vax__ */ + +#if defined(__ns32k__) /* National Semiconductor 32K */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" sbitb 0, %1 \n" + " sfsd %0 \n" + : "=r"(_res), "+m"(*lock) + : + : "memory"); + return _res; +} + +#endif /* __ns32k__ */ + +#if defined(__alpha) || defined(__alpha__) /* Alpha */ +/* + * Correct multi-processor locking methods are explained in section 5.5.3 + * of the Alpha AXP Architecture Handbook, which at this writing can be + * found at ftp://ftp.netbsd.org/pub/NetBSD/misc/dec-docs/index.html. + * For gcc we implement the handbook's code directly with inline assembler. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + __asm__ __volatile__(" ldq $0, %1 \n" + " bne $0, 2f \n" + " ldq_l %0, %1 \n" + " bne %0, 2f \n" + " mov 1, $0 \n" + " stq_c $0, %1 \n" + " beq $0, 2f \n" + " mb \n" + " br 3f \n" + "2: mov 1, %0 \n" + "3: \n" + : "=&r"(_res), "+m"(*lock) + : + : "memory", "0"); + return (int)_res; +} + +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__(" mb \n"); \ + *((volatile slock_t *)(lock)) = 0; \ +} while (0) + +#endif /* __alpha || __alpha__ */ + +#if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ +/* Note: on SGI we use the OS' mutex ABI, see below */ +/* Note: R10000 processors require a separate SYNC */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register volatile slock_t* _l = lock; + register int _res; + register int _tmp; + + __asm__ __volatile__(" .set push \n" + " .set mips2 \n" + " .set noreorder \n" + " .set nomacro \n" + " ll %0, %2 \n" + " or %1, %0, 1 \n" + " sc %1, %2 \n" + " xori %1, 1 \n" + " or %0, %0, %1 \n" + " sync \n" + " .set pop " + : "=&r"(_res), "=&r"(_tmp), "+R"(*_l) + : + : "memory"); + return _res; +} + +/* MIPS S_UNLOCK is almost standard but requires a "sync" instruction */ +#define S_UNLOCK(lock) do { \ +__asm__ __volatile__( \ + " .set push \n" \ + " .set mips2 \n" \ + " .set noreorder \n" \ + " .set nomacro \n" \ + " sync \n" \ + " .set pop " +: +: "memory"); +*((volatile slock_t*)(lock)) = 0; +} +while (0) + +#endif /* __mips__ && !__sgi */ + +#if defined(__m32r__) && defined(HAVE_SYS_TAS_H) /* Renesas' M32R */ +#define HAS_TEST_AND_SET + +#include + + typedef int slock_t; + +#define TAS(lock) tas(lock) + +#endif /* __m32r__ */ + +#if defined(__sh__) /* Renesas' SuperH */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + /* + * This asm is coded as if %0 could be any register, but actually SuperH + * restricts the target of xor-immediate to be R0. That's handled by + * the "z" constraint on _res. + */ + __asm__ __volatile__(" tas.b @%2 \n" + " movt %0 \n" + " xor #1,%0 \n" + : "=z"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "t"); + return _res; +} + +#endif /* __sh__ */ + +/* These live in s_lock.c, but only for gcc */ + +#if defined(__m68k__) && !defined(__linux__) /* non-Linux Motorola 68k */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +/* + * Note that this implementation is unsafe for any platform that can speculate + * a memory access (either load or store) after a following store. That + * happens not to be possible x86 and most legacy architectures (some are + * single-processor!), but many modern systems have weaker memory ordering. + * Those that do must define their own version S_UNLOCK() rather than relying + * on this one. + */ +#if !defined(S_UNLOCK) +#if defined(__INTEL_COMPILER) +#define S_UNLOCK(lock) do { \ + __memory_barrier(); \ + *(lock) = 0; \ +} while (0) +#else +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("" : : : "memory"); \ + *(lock) = 0; \ +} while (0) +#endif +#endif + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +/* + * --------------------------------------------------------------------- + * Platforms that use non-gcc inline assembly: + * --------------------------------------------------------------------- + */ + +#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ + +#if defined(USE_UNIVEL_CC) /* Unixware compiler */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +asm int tas(volatile slock_t* s_lock) +{ + /* UNIVEL wants %mem in column 1, so we don't pg_indent this file */ + % mem s_lock pushl % ebx movl s_lock, % ebx movl $255, % eax lock xchgb % al, (% ebx) popl % ebx +} + +#endif /* defined(USE_UNIVEL_CC) */ + +#if defined(__alpha) || defined(__alpha__) /* Tru64 Unix Alpha compiler */ +/* + * The Tru64 compiler doesn't support gcc-style inline asm, but it does + * have some builtin functions that accomplish much the same results. + * For simplicity, slock_t is defined as long (ie, quadword) on Alpha + * regardless of the compiler in use. LOCK_LONG and UNLOCK_LONG only + * operate on an int (ie, longword), but that's OK as long as we define + * S_INIT_LOCK to zero out the whole quadword. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include +#define S_INIT_LOCK(lock) (*(lock) = 0) +#define TAS(lock) (__LOCK_LONG_RETRY((lock), 1) == 0) +#define S_UNLOCK(lock) __UNLOCK_LONG(lock) + +#endif /* __alpha || __alpha__ */ + +#if defined(__hppa) || defined(__hppa__) /* HP PA-RISC, GCC and HP compilers */ +/* + * HP's PA-RISC + * + * See src/backend/port/hpux/tas.c.template for details about LDCWX. Because + * LDCWX requires a 16-byte-aligned address, we declare slock_t as a 16-byte + * struct. The active word in the struct is whichever has the aligned address; + * the other three words just sit at -1. + * + * When using gcc, we can inline the required assembly code. + */ +#define HAS_TEST_AND_SET + +typedef struct { + int sema[4]; +} slock_t; + +#define TAS_ACTIVE_WORD(lock) ((volatile int*)(((uintptr_t)(lock) + 15) & ~15)) + +#if defined(__GNUC__) + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile int* lockword = TAS_ACTIVE_WORD(lock); + register int lockval; + + __asm__ __volatile__(" ldcwx 0(0,%2),%0 \n" : "=r"(lockval), "+m"(*lockword) : "r"(lockword) : "memory"); + return (lockval == 0); +} + +#define S_UNLOCK(lock) do { \ + __asm__ __volatile__("" : : : "memory"); \ + *TAS_ACTIVE_WORD(lock) = -1; \ +} while (0) + +#endif /* __GNUC__ */ + +#define S_INIT_LOCK(lock) do { \ + volatile slock_t *lock_ = (lock); \ + lock_->sema[0] = -1; \ + lock_->sema[1] = -1; \ + lock_->sema[2] = -1; \ + lock_->sema[3] = -1; \ +} while (0) + +#define S_LOCK_FREE(lock) (*TAS_ACTIVE_WORD(lock) != 0) + +#endif /* __hppa || __hppa__ */ + +#if defined(__hpux) && defined(__ia64) && !defined(__GNUC__) +/* + * HP-UX on Itanium, non-gcc compiler + * + * We assume that the compiler enforces strict ordering of loads/stores on + * volatile data (see comments on the gcc-version earlier in this file). + * Note that this assumption does *not* hold if you use the + * +Ovolatile=__unordered option on the HP-UX compiler, so don't do that. + * + * See also Implementing Spinlocks on the Intel Itanium Architecture and + * PA-RISC, by Tor Ekqvist and David Graves, for more information. As of + * this writing, version 1.0 of the manual is available at: + * http://h21007.www2.hp.com/portal/download/files/unprot/itanium/spinlocks.pdf + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#include +#define TAS(lock) _Asm_xchg(_SZ_W, lock, 1, _LDHINT_NONE) +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) +#define S_UNLOCK(lock) do { \ + _Asm_sched_fence(); (*(lock)) = 0); \ +} while (0) + +#endif /* HPUX on IA64, non gcc */ + +#if defined(__sgi) /* SGI compiler */ +/* + * SGI IRIX 5 + * slock_t is defined as a unsigned long. We use the standard SGI + * mutex API. + * + * The following comment is left for historical reasons, but is probably + * not a good idea since the mutex ABI is supported. + * + * This stuff may be supplemented in the future with Masato Kataoka's MIPS-II + * assembly from his NECEWS SVR4 port, but we probably ought to retain this + * for the R3000 chips out there. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include "mutex.h" +#define TAS(lock) (test_and_set(lock, 1)) +#define S_UNLOCK(lock) (test_then_and(lock, 0)) +#define S_INIT_LOCK(lock) (test_then_and(lock, 0)) +#define S_LOCK_FREE(lock) (test_then_add(lock, 0) == 0) +#endif /* __sgi */ + +#if defined(sinix) /* Sinix */ +/* + * SINIX / Reliant UNIX + * slock_t is defined as a struct abilock_t, which has a single unsigned long + * member. (Basically same as SGI) + */ +#define HAS_TEST_AND_SET + +#include "abi_mutex.h" +typedef abilock_t slock_t; + +#define TAS(lock) (!acquire_lock(lock)) +#define S_UNLOCK(lock) release_lock(lock) +#define S_INIT_LOCK(lock) init_lock(lock) +#define S_LOCK_FREE(lock) (stat_lock(lock) == UNLOCKED) +#endif /* sinix */ + +#if defined(_AIX) /* AIX */ +/* + * AIX (POWER) + */ +#define HAS_TEST_AND_SET + +#include + +typedef int slock_t; + +#define TAS(lock) _check_lock((slock_t*)(lock), 0, 1) +#define S_UNLOCK(lock) _clear_lock((slock_t*)(lock), 0) +#endif /* _AIX */ + +/* These are in s_lock.c */ + +#if defined(sun3) /* Sun3 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +#if defined(__SUNPRO_C) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) +#define HAS_TEST_AND_SET + +#if defined(__i386) || defined(__x86_64__) || defined(__sparcv9) || defined(__sparcv8plus) +typedef unsigned int slock_t; +#else +typedef unsigned char slock_t; +#endif + +extern slock_t pg_atomic_cas(volatile slock_t* lock, slock_t with, slock_t cmp); + +#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0) +#endif + +#ifdef WIN32_ONLY_COMPILER +typedef LONG slock_t; + +#define HAS_TEST_AND_SET +#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) + +#define SPIN_DELAY() spin_delay() + +/* If using Visual C++ on Win64, inline assembly is unavailable. + * Use a _mm_pause instrinsic instead of rep nop. + */ +#if defined(_WIN64) +static __forceinline void spin_delay(void) +{ + _mm_pause(); +} +#else +static __forceinline void spin_delay(void) +{ + /* See comment for gcc code. Same code, MASM syntax */ + __asm rep nop; +} +#endif + +#include +#pragma intrinsic(_ReadWriteBarrier) + +#define S_UNLOCK(lock) do { \ + _ReadWriteBarrier(); \ + (*(lock)) = 0; \ +} while (0) + +#endif + +#endif /* !defined(HAS_TEST_AND_SET) */ + +/* Blow up if we didn't have any way to do spinlocks */ +#ifndef HAS_TEST_AND_SET +#error PostgreSQL does not have native spinlock support on this platform. To continue the compilation, rerun configure using --disable-spinlocks. However, performance will be poor. Please report this to pgsql-bugs@postgresql.org. +#endif + +#else /* !HAVE_SPINLOCKS */ + +/* + * Fake spinlock implementation using semaphores --- slow and prone + * to fall foul of kernel limits on number of semaphores, so don't use this + * unless you must! The subroutines appear in spin.c. + */ +typedef PGSemaphoreData slock_t; + +extern bool s_lock_free_sema(volatile slock_t* lock); +extern void s_unlock_sema(volatile slock_t* lock); +extern void s_init_lock_sema(volatile slock_t* lock); +extern int tas_sema(volatile slock_t* lock); + +#define S_LOCK_FREE(lock) s_lock_free_sema(lock) +#define S_UNLOCK(lock) s_unlock_sema(lock) +#define S_INIT_LOCK(lock) s_init_lock_sema(lock) +#define TAS(lock) tas_sema(lock) + +#endif /* HAVE_SPINLOCKS */ + +/* + * Default Definitions - override these above as needed. + */ + +#if !defined(S_LOCK) +#define S_LOCK(lock) do { \ + if (TAS(lock)) \ + s_lock((lock), __FILE__, __LINE__); \ +} while (0) +#endif /* S_LOCK */ + +#if !defined(S_LOCK_FREE) +#define S_LOCK_FREE(lock) (*(lock) == 0) +#endif /* S_LOCK_FREE */ + +#if !defined(S_UNLOCK) +/* + * Our default implementation of S_UNLOCK is essentially *(lock) = 0. This + * is unsafe if the platform can speculate a memory access (either load or + * store) after a following store; platforms where this is possible must + * define their own S_UNLOCK. But CPU reordering is not the only concern: + * if we simply defined S_UNLOCK() as an inline macro, the compiler might + * reorder instructions from inside the critical section to occur after the + * lock release. Since the compiler probably can't know what the external + * function s_unlock is doing, putting the same logic there should be adequate. + * A sufficiently-smart globally optimizing compiler could break that + * assumption, though, and the cost of a function call for every spinlock + * release may hurt performance significantly, so we use this implementation + * only for platforms where we don't know of a suitable intrinsic. For the + * most part, those are relatively obscure platform/compiler combinations to + * which the PostgreSQL project does not have access. + */ +#define USE_DEFAULT_S_UNLOCK +extern void s_unlock(volatile slock_t* lock); +#define S_UNLOCK(lock) s_unlock(lock) +#endif /* S_UNLOCK */ + +#if !defined(S_INIT_LOCK) +#define S_INIT_LOCK(lock) S_UNLOCK(lock) +#endif /* S_INIT_LOCK */ + +#if !defined(SPIN_DELAY) +#define SPIN_DELAY() ((void)0) +#endif /* SPIN_DELAY */ + +#if !defined(TAS) +extern int tas(volatile slock_t* lock); /* in port/.../tas.s, or + * s_lock.c */ + +#define TAS(lock) tas(lock) +#endif /* TAS */ + +#if !defined(TAS_SPIN) +#define TAS_SPIN(lock) TAS(lock) +#endif /* TAS_SPIN */ + +#endif /* ENABLE_THREAD_CHECK */ + +#ifdef ENABLE_THREAD_CHECK + +#include +typedef pthread_mutex_t slock_t; +#define SPIN_DELAY() ((void)0) +#define TAS_SPIN(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_INIT_LOCK(lock) pthread_mutex_init((pthread_mutex_t*)lock, NULL) +#define S_LOCK(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_UNLOCK(lock) pthread_mutex_unlock((pthread_mutex_t*)lock) +#define S_LOCK_FREE(lock) pthread_mutex_destroy((pthread_mutex_t*)lock) + +#endif +/* + * Platform-independent out-of-line support routines + */ +extern int s_lock(volatile slock_t* lock, const char* file, int line); + +/* Support for dynamic adjustment of spins_per_delay */ +#define DEFAULT_SPINS_PER_DELAY 100 + +extern void set_spins_per_delay(int shared_spins_per_delay); +extern int update_spins_per_delay(int shared_spins_per_delay); + +/* + * Support for spin delay which is useful in various places where + * spinlock-like procedures take place. + */ +typedef struct { + int spins; + int delays; + int cur_delay; + void* ptr; + const char* file; + int line; +} SpinDelayStatus; + +#define init_spin_delay(ptr) \ + { \ + 0, 0, 0, (ptr), __FILE__, __LINE__ \ + } +void perform_spin_delay(SpinDelayStatus* status); +void finish_spin_delay(SpinDelayStatus* status); + +#endif /* S_LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_spinlock.h postgresql-hll-2.14/include/include/gtm/gtm_spinlock.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_spinlock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_spinlock.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,73 @@ +/* --------------------------------------------------------------------------------------- + * + * gtm_spinlock.h + * Hardware-independent implementation of spinlocks. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_spinlock.h + * + * NOTE + * The hardware-independent interface to spinlocks is defined by the + * typedef "slock_t" and these macros: + * + * void SpinLockInit(volatile slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void SpinLockAcquire(volatile slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void SpinLockRelease(volatile slock_t *lock) + * Unlock a previously acquired lock. + * + * bool SpinLockFree(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * Callers must beware that the macro argument may be evaluated multiple + * times! + * + * CAUTION: Care must be taken to ensure that loads and stores of + * shared memory values are not rearranged around spinlock acquire + * and release. This is done using the "volatile" qualifier: the C + * standard states that loads and stores of volatile objects cannot + * be rearranged *with respect to other volatile objects*. The + * spinlock is always written through a volatile pointer by the + * spinlock macros, but this is not sufficient by itself: code that + * protects shared data with a spinlock MUST reference that shared + * data through a volatile pointer. + * + * Keep in mind the coding rule that spinlocks must not be held for more + * than a few instructions. In particular, we assume it is not possible + * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so + * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros. + * + * These macros are implemented in terms of hardware-dependent macros + * supplied by s_lock.h. There is not currently any extra functionality + * added by this header, but there has been in the past and may someday + * be again. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SPIN_H +#define SPIN_H + +#include "gtm/gtm_slock.h" + +#define SpinLockInit(lock) S_INIT_LOCK(lock) + +#define SpinLockAcquire(lock) S_LOCK(lock) + +#define SpinLockRelease(lock) S_UNLOCK(lock) + +#define SpinLockFree(lock) S_LOCK_FREE(lock) + +extern int SpinlockSemas(void); + +#endif /* SPIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_standby.h postgresql-hll-2.14/include/include/gtm/gtm_standby.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_standby.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_standby.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,97 @@ +/* ------------------------------------------------------------------------- + * + * gtm_standby.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_standby.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_STANDBY_H +#define GTM_STANDBY_H + +#include "c.h" +#include "gtm/gtm_c.h" +#include "gtm/utils/libpq-fe.h" +#include "gtm/utils/register.h" +#include "alarm/alarm.h" + +/* + * Variables to interact with GTM active under GTM standby mode. + */ +bool gtm_is_standby(void); +void gtm_set_standby(bool standby); +void gtm_set_active_conninfo(const char* addr, int port); + +int gtm_standby_start_startup(void); +int gtm_standby_finish_startup(void); + +int gtm_standby_restore_next_gxid(void); +int gtm_standby_restore_timeline(void); +int gtm_standby_restore_next_sequuid(void); +int gtm_standby_restore_sequence(void); +int gtm_standby_restore_node(void); + +int gtm_standby_activate_self(void); + +GTM_Conn* gtm_standby_connect_to_standby(void); +void gtm_standby_disconnect_from_standby(GTM_Conn* conn); +GTM_Conn* gtm_standby_reconnect_to_standby(GTM_Conn* old_conn, int retry_max); +bool gtm_standby_check_communication_error(int* retry_count, GTM_Conn* oldconn); + +GTM_PGXCNodeInfo* find_standby_node_info(void); + +int gtm_standby_begin_backup(void); +int gtm_standby_end_backup(void); +void gtm_standby_closeActiveConn(void); +void gtm_standby_finishActiveConn(void); + +/* Functions to process backup */ +void ProcessGTMBeginBackup(Port* myport, StringInfo message); +void ProcessGTMEndBackup(Port* myport, StringInfo message); +int gtm_standby_begin_switchover(void); +int gtm_standby_end_switchover(void); +void ProcessGTMBeginSwitchover(Port* myport, StringInfo message, bool noblock); +void ProcessGTMEndSwitchover(Port* myport, StringInfo message, bool noblock); +void RemoveGTMXids(void); +GTMConnStatusType GetConnectionStatus(void); +bool SendBackupFileToStandby(void); +void WriteTempFile(const char* buf, char* temppath, int size); + +#define invalid_file -1 +#define register_node_file 0 +#define gtm_control_file 1 +#define gtm_sequence_file 2 + +extern AlarmCheckResult GTMStandbyNotAliveChecker(Alarm* alarm, char* buffer); +extern AlarmCheckResult GTMNotInSyncStatusChecker(Alarm* alarm, char* buffer); + +/* + * Startup mode + */ +#define GTM_ACT_MODE 0 +#define GTM_STANDBY_MODE 1 + +typedef enum CheckStandbyRoleResult { + SRR_Unknown = 0, + SRR_Success, + SRR_InetError, + SRR_NotAStandby, + SRR_ConfigureError, +} CheckStandbyRoleResult; + +void QuerySyncStatus(long* sendCount, long* receiveCount); +void PrimaryASyncStandby(void); +void AdvanceStandbyASyncCounter(void); +void PrimarySyncStandby(GTM_Conn* conn, bool autosync); + +void gtm_primary_sync_standby(GTM_Conn* conn); +bool gtm_sync_primary_info_to_etcd(const char* host, int port); +char* gtm_get_primary_info_from_etcd(bool force); + +#endif /* GTM_STANDBY_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_test_framework.h postgresql-hll-2.14/include/include/gtm/gtm_test_framework.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_test_framework.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_test_framework.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,105 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gtm_test_framework.h + * Routines for gtm distributed test framework. + * + * + * IDENTIFICATION + * src/include/gtm/gtm_test_framework.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DISTRIBUTE_TEST_H +#define DISTRIBUTE_TEST_H + +#include "gtm/gtm_c.h" +#include "gtm/gtm_opt.h" +#include "gtm/utils/elog.h" + +#ifdef USE_ASSERT_CHECKING +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_DISTRIBUTE_TEST +#endif + +#define MAX_GID_STR_LEN (1024) +#define MAX_NAME_STR_LEN (256) + +/* white-box log handle */ +#define ereport_whitebox_domain(elevel, file, line, func, domain, rest) \ + (errstart(elevel, file, line, func, domain) ? (errfinish rest) : (void)0) + +#define ereport_whitebox(elevel, file, line, func, rest) \ + ereport_whitebox_domain(elevel, file, line, func, TEXTDOMAIN, rest) + +#define WHITEBOX_LOC __FILE__, __LINE__, PG_FUNCNAME_MACRO + +typedef struct GtmDistributeTestParam { + /* use as the guc-control white-box-fault probability + * range [0, 100000], probability 0, 1/100000 -> 1 + */ + int guc_probability; + + /* fault level, support ERROR and PANIC */ + int elevel; + + /* when white-box fault is WHITEBOX_WAIT, guc can provide "sleep_time" + * for sleep time control, if guc not contain this field, use the default value 30s + */ + int sleep_time; +} GtmDistributeTestParam; + +/* GTM white-box failure injection type definition */ +typedef enum GtmWhiteboxFaillueType { + GTM_WHITEBOX_DEFAULT = 0, + GTM_WHITEBOX_WAIT, + GTM_WHITEBOX_REPEAT, + GTM_WHITEBOX_USERDEFINE, + GTM_WHITEBOX_BUTT +} GtmWhiteboxFaillueType; + +/* struct created for white-box tesing, support expansion */ +typedef struct GtmWhiteBoxInjectStruct { + /* test location record */ + char filename[MAX_NAME_STR_LEN]; + int lineno; + char funcname[MAX_NAME_STR_LEN]; + + /* failure type, defined above */ + int failureType; + + /* trigger as the probability, 0 -1, if set as 1, definitely trigger */ + double triggerProbability; + + /* white box test info needed */ + GlobalTransactionId currentXid; + GTM_TransactionHandle handle; +} GtmWhiteBoxInjectStruct; + +typedef void (*on_whitebox_callback)(GtmWhiteBoxInjectStruct* wbinfo); + +extern GtmDistributeTestParam* gtmDistributeTestParam; + +extern void gtm_default_whitebox_emit(GtmWhiteBoxInjectStruct* wbinfo); +extern bool gtm_check_distribute_test_param(char** newval, void** extra, GtmOptSource source); +extern void gtm_assign_distribute_test_param(const char* newval, void* extra); +extern bool gtm_execute_whitebox(const char* filename, int lineno, const char* funcname, GlobalTransactionId xid, + GTM_TransactionHandle handle, int failureType, double probability); + +/*GTM exception scenes*/ + +#endif + +#endif /* DISTRIBUTE_TEST_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_time.h postgresql-hll-2.14/include/include/gtm/gtm_time.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_time.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * gtm_time.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_TIME_H +#define GTM_TIME_H + +/* Julian-date equivalents of Day 0 in Unix and GTM reckoning */ +#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */ +#define GTM_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */ + +#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */ +#define SECS_PER_DAY 86400 +#define SECS_PER_HOUR 3600 +#define SECS_PER_MINUTE 60 +#define MINS_PER_HOUR 60 + +#ifdef HAVE_INT64_TIMESTAMP +#define USECS_PER_DAY INT64CONST(86400000000) +#define USECS_PER_HOUR INT64CONST(3600000000) +#define USECS_PER_MINUTE INT64CONST(60000000) +#define USECS_PER_SEC INT64CONST(1000000) +#endif + +GTM_Timestamp GTM_TimestampGetCurrent(void); + +bool GTM_TimestampDifferenceExceeds(GTM_Timestamp start_time, GTM_Timestamp stop_time, int msec); +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_txn.h postgresql-hll-2.14/include/include/gtm/gtm_txn.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_txn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_txn.h 2020-12-12 17:06:43.205347496 +0800 @@ -0,0 +1,360 @@ +/* ------------------------------------------------------------------------- + * + * gtm_txn.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _GTM_TXN_H +#define _GTM_TXN_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_list.h" +#include "gtm/utils/stringinfo.h" +#include "gtm/gtm_msg.h" +#include "gtm/gtm_atomic.h" + +typedef struct MemoryContextData* MemoryContext; + +/* ---------------- + * Special transaction ID values + * + * BootstrapGlobalTransactionId is the XID for "bootstrap" operations, and + * FrozenGlobalTransactionId is used for very old tuples. Both should + * always be considered valid. + * + * FirstNormalGlobalTransactionId is the first "normal" transaction id. + * Note: if you need to change it, you must change pg_class.h as well. + * ---------------- + */ +#define BootstrapGlobalTransactionId ((GlobalTransactionId)1) +#define FrozenGlobalTransactionId ((GlobalTransactionId)2) +#define FirstNormalGlobalTransactionId ((GlobalTransactionId)3) + +/* ---------------- + * transaction ID manipulation macros + * ---------------- + */ +#define GlobalTransactionIdIsNormal(xid) ((xid) >= FirstNormalGlobalTransactionId) +#define GlobalTransactionIdEquals(id1, id2) ((id1) == (id2)) +#define GlobalTransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidGlobalTransactionId(dest) (*(dest) = InvalidGlobalTransactionId) + +/* advance a transaction ID variable */ +#define GlobalTransactionIdAdvance(dest) do { \ + (dest)++; \ + if ((dest) < FirstNormalGlobalTransactionId) \ + (dest) = FirstNormalGlobalTransactionId; \ +} while (0) + +typedef int XidStatus; + +#define TRANSACTION_STATUS_IN_PROGRESS 0x00 +#define TRANSACTION_STATUS_COMMITTED 0x01 +#define TRANSACTION_STATUS_ABORTED 0x02 + +#define XACT_RESFILE "pgxc_running_xact.ready" +#define XACT_DONEFILE "pgxc_running_xact.done" + +#define ECTD_RETRY_TIMES 10 +#define ETCD_RETRY_TIMEOUT 12 /* assume etcd RTO is 10s */ + +/* + * check whether etcd retry limit exceeded + */ +extern bool etcd_retry_exceeded(time_t start_time, int count); + +/* + * prototypes for functions in transam/transam.c + */ +extern bool GlobalTransactionIdDidCommit(GlobalTransactionId transactionId); +extern bool GlobalTransactionIdDidAbort(GlobalTransactionId transactionId); +extern void GlobalTransactionIdAbort(GlobalTransactionId transactionId); + +/* + * GlobalTransactionIdPrecedes --- is id1 < id2? + */ +#define GlobalTransactionIdPrecedes(id1, id2) ((id1) < (id2)) + +/* + * GlobalTransactionIdPrecedesOrEquals --- is id1 <= id2? + */ +#define GlobalTransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) + +/* + * GlobalTransactionIdFollows --- is id1 > id2? + */ +#define GlobalTransactionIdFollows(id1, id2) ((id1) > (id2)) + +/* + * GlobalTransactionIdFollowsOrEquals --- is id1 >= id2? + */ +#define GlobalTransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) + +extern void GTM_CalculateLatestSnapshot(bool calc_xmin); + +/* in transam/varsup.c */ +extern bool GTM_SetDoVacuum(GTM_TransactionHandle handle); +extern GlobalTransactionId GTM_GetGlobalTransactionId(GTM_TransactionHandle handle, bool is_sub_xact); +extern GlobalTransactionId GTM_GetGlobalTransactionIdMulti(GTM_TransactionHandle handle[], int txn_count, + bool is_sub_xact); +extern GlobalTransactionId ReadNewGlobalTransactionId(void); +extern void SetGlobalTransactionIdLimit(GlobalTransactionId oldest_datfrozenxid); +extern void SetNextGlobalTransactionId(GlobalTransactionId gxid); +extern void GTM_SetShuttingDown(void); + +/* For restoration point backup */ +extern bool GTM_NeedXidRestoreUpdate(void); +extern bool GTM_NeedCsnRestoreUpdate(void); +extern void GTM_WriteRestorePointXid(FILE* f, bool xid_restore); +extern void GTM_WriteRestorePointCSN(FILE* f); +extern void GTM_WriteTimeline(FILE* f); +extern void GTM_WriteTransactionLength(FILE* f); + +typedef enum GTM_States { + GTM_STARTING, + GTM_RUNNING, + GTM_SHUTTING_DOWN +} GTM_States; + +/* Global transaction states at the GTM */ +typedef enum GTM_TransactionStates { + GTM_TXN_STARTING, + GTM_TXN_IN_PROGRESS, + GTM_TXN_PREPARE_IN_PROGRESS, + GTM_TXN_PREPARED, + GTM_TXN_COMMIT_IN_PROGRESS, + GTM_TXN_COMMITTED, + GTM_TXN_ABORT_IN_PROGRESS, + GTM_TXN_ABORTED +} GTM_TransactionStates; + +typedef struct GTM_TransactionInfo { + GTM_TransactionHandle gti_handle; + GTM_ThreadID gti_thread_id; + uint32 gti_client_id; + + GTM_Atomic gti_in_use; + GlobalTransactionId gti_gxid; + GTM_TransactionStates gti_state; + char* gti_coordname; + GlobalTransactionId gti_xmin; + GlobalTransactionId gti_xmax; /* The max gxid of the current txn_slot(including sub xacts) */ + GTM_IsolationLevel gti_isolevel; + bool gti_readonly; + GTMProxy_ConnID gti_backend_id; + char* nodestring; /* List of nodes prepared */ + char* gti_gid; + + GTM_SnapshotData gti_current_snapshot; + bool gti_snapshot_set; + + volatile bool gti_vacuum; + uint32 gti_timeline; + GTM_RWLock gti_lock; +} GTM_TransactionInfo; + +struct MemReservation { + pthread_cond_t mem_Reserve_cond; + int4 mem_to_reserve; + char* rp_name; + + bool is_invalid; +}; + +/* By default a GID length is limited to 256 bits in PostgreSQL */ +#define GTM_MAX_GID_LEN 256 +#define GTM_CheckTransactionHandle(x) ((x) >= 0 && (x) < gtm_max_trans) +#define GTM_IsTransSerializable(x) ((x)->gti_isolevel == GTM_ISOLATION_SERIALIZABLE) + +typedef struct GTM_Transactions { + uint32 gt_txn_count; + GTM_States gt_gtm_state; + + GTM_RWLock gt_XidGenLock; + + /* + * These fields are protected by XidGenLock + */ + GlobalTransactionId gt_nextXid; /* next XID to assign */ + volatile GlobalTransactionId gt_backedUpXid; /* backed up, restoration point */ + + volatile uint64 gt_csn; /* current commit sequence number */ + GlobalTransactionId gt_oldestXid; /* cluster-wide minimum datfrozenxid */ + + /* + * These fields are protected by TransArrayLock. + */ + GlobalTransactionId gt_latestCompletedXid; /* newest XID that has committed or + * aborted */ + + GlobalTransactionId gt_xmin; + GlobalTransactionId gt_recent_global_xmin; + + int32 gt_lastslot; + GTM_TransactionInfo* gt_transactions_array; + + GTM_MutexLock gt_TransArrayLock; + + /* + * These fields are for lock-free snapshot management + */ + MemoryContext gt_SnapCalcCtx; + GTM_Snapshot gt_snapArray; + volatile uint32_t gt_currentSnap; + volatile uint32_t gt_nextSnap; + uint32_t gt_numVersions; + GTM_Atomic* gt_rcArray; + GTM_Atomic gt_concurrentTransactions; + uint32_t gt_snapshotPendingCnt; +} GTM_Transactions; + +extern GTM_Transactions GTMTransactions; + +/* + * When gtm restart as primary or restart as pending->primary, its xid will increase 2000. + * Then we should sync the new xid to standby, so we make the GTM_SyncGXIDFlag to true. + * When a gtm client get a new xid from gtm primary, if the GTM_SyncGXIDFlag is true, it + * will sync the new xid to stanby. + */ +extern volatile bool GTM_SyncGXIDFlag; + +/* + * This macro should be used with READ lock held on gt_TransArrayLock as the + * number of open transactions might change when counting open transactions + * if a lock is not hold. + */ +#define GTM_CountOpenTransactions() (GTMTransactions.gt_concurrentTransactions) + +/* + * Two hash tables will be maintained to quickly find the + * GTM_TransactionInfo block given either the GXID or the GTM_TransactionHandle. + */ +GlobalTransactionId GTM_HandleToTransactionId(GTM_TransactionHandle handle); +GTM_TransactionInfo* GTM_HandleToTransactionInfo(GTM_TransactionHandle handle); +GTM_TransactionHandle GTM_GXIDToHandle(GlobalTransactionId gxid); +GTM_TransactionHandle GTM_GIDToHandle(const char* gid); + +/* Transaction Control */ +void GTM_InitTxnManager(void); +GTM_TransactionHandle GTM_BeginTransaction(const char* coord_name, GTM_IsolationLevel isolevel, bool readonly); +int GTM_BeginTransactionMulti(const char* coord_name, GTM_IsolationLevel isolevel[], const bool readonly[], + GTMProxy_ConnID connid[], int txn_count, GTM_TransactionHandle txns[]); +bool GTM_FillTransactionInfo(const char* coord_name, GTM_TransactionHandle handle, GlobalTransactionId gxid, + GTM_TransactionStates state, GlobalTransactionId xmin, bool vacuum, uint32 timeline); + +int GTM_RollbackTransaction(GTM_TransactionHandle txn, bool isTimelineOK); +int GTM_RollbackTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[], bool isTimelineOK); +int GTM_RollbackTransactionGXID(GlobalTransactionId gxid); +int GTM_CommitTransaction(GTM_TransactionHandle txn, bool isTimelineOK, uint64 *csn); +int GTM_CommitTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[], bool isTimelineOK, + uint64 *csn); + +int GTM_PrepareTransaction(GTM_TransactionHandle txn); +int GTM_StartPreparedTransaction(GTM_TransactionHandle txn, const char* gid, const char* nodestring); +int GTM_StartPreparedTransactionGXID(GlobalTransactionId gxid, const char* gid, const char* nodestring); +int GTM_GetGIDData(GTM_TransactionHandle prepared_txn, GlobalTransactionId* prepared_gxid, char** nodestring); +uint32 GTM_GetAllPrepared(GlobalTransactionId gxids[], uint32 gxidcnt); +GTM_TransactionStates GTM_GetStatus(GTM_TransactionHandle txn); +GTM_TransactionStates GTM_GetStatusGXID(GlobalTransactionId gxid); +int GTM_GetAllTransactions(GTM_TransactionInfo txninfo[], uint32 txncnt); +void GTM_RemoveAllTransInfos(int backend_id); +void GTM_RemoveAllTransInfosForClient(uint32 client_id, int backend_id); +void GTM_RemoveAllTransInfosOutofTimeline(char* nodename, uint32 timeline); + +GTM_Snapshot GTM_GetSnapshotData(GTM_TransactionInfo* my_txninfo, GTM_Snapshot snapshot); +GTM_Snapshot GTM_GetTransactionSnapshot(GTM_TransactionHandle handle[], int txn_count, int* status); +void GTM_FreeCachedTransInfo(void); + +void ProcessResetTrasactionXminCommand(Port* myport, StringInfo message); +void ProcessSetVacuumCommand(Port* myport, StringInfo message); +void ProcessBeginTransactionCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionCommandMulti(Port* myport, StringInfo message); +void ProcessBeginTransactionGetGXIDCommand(Port* myport, StringInfo message); +void ProcessCommitTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessCommitPreparedTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessRollbackTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessPrepareTransactionCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessGetGIDDataTransactionCommand(Port* myport, StringInfo message); + +void ProcessGetGXIDTransactionCommand(Port* myport, StringInfo message, bool is_sub_xact); + +void ProcessGXIDListCommand(Port* myport, StringInfo message); +void ProcessGetNextGXIDTransactionCommand(Port* myport, StringInfo message); +void ProcessGetNextCSNTransactionCommand(Port* myport, StringInfo message); +void ProcessGetNextCSNTransactionLiteCommand(Port* myport, StringInfo message); +void ProcessGetGlobalXminTransactionCommand(Port* myport, StringInfo message); +void ProcessGetTimelineTransactionCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionGetGXIDAutovacuumCommand(Port* myport, StringInfo message); + +/* + * * workload manager + * */ +struct GTM_WorkloadManager { + int free_server_mem; + pthread_mutex_t workldmgr_mem_mutex; +}; + +void ProcessWorkloadManagerInitCommand(Port* myport, StringInfo message); +void ProcessWorkloadManagerReserveMemCommand(Port* myport, StringInfo message); +void ProcessWorkloadManagerReleaseMemCommand(Port* myport, StringInfo message); + +void ProcessBeginTransactionGetGXIDCommandMulti(Port* myport, StringInfo message); +void ProcessCommitTransactionCommandMulti(Port* myport, StringInfo message, bool is_backup); +void ProcessRollbackTransactionCommandMulti(Port* myport, StringInfo message, bool is_backup); + +void GTM_SaveTxnInfo(FILE* ctlf); +void GTM_SaveTimelineInfo(FILE* ctlf); +void GTM_SaveTransactionLength(FILE* ctlf); + +void GTM_RestoreTxnInfo(FILE* ctlf, GlobalTransactionId next_gxid); +void GTM_RestoreTimelineInfo(FILE* ctlf, GTM_Timeline* timeline); +void GTM_RestoreTransactionsLen(FILE* ctlf, uint32* len); + +void ProcessBkupGtmControlFileGXIDCommand(Port* myport, StringInfo message); +void ProcessBkupGtmControlFileTIMELINECommand(Port* myport, StringInfo message); + +void GTM_SyncGXID(GlobalTransactionId xid, int txn_count = 0); +bool GTM_SyncXidToStandby(GlobalTransactionId xid); +bool GTM_SetXidToEtcd(GlobalTransactionId xid, bool save, GlobalTransactionId etcd_xid = InvalidGlobalTransactionId); +bool GTMSyncXidToEtcdInternal(GlobalTransactionId xid, bool force, + GlobalTransactionId etcd_xid = InvalidGlobalTransactionId); +bool GTM_SetGlobalMaxXidToEtcd(GlobalTransactionId xid, bool save, int txn_count = 0); +bool GTM_GetXidFromEtcd(GlobalTransactionId& xid, bool force, bool need_retry = false); +void GTM_GetSyncXidFromEtcd(const char* errString); + +void GTM_SyncTimeline(GTM_Timeline timeline); +bool GTM_SyncTimelineToStandby(GTM_Timeline timeline); +bool GTM_SetTimelineToEtcd(GTM_Timeline timeline); +bool GTM_GetTimelineFromEtcd(GTM_Timeline& timeline); + +void ProcessWorkloadManagerInitCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerReserveMemCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerReleaseMemCommand(Port* myport, StringInfo message, bool is_backup); + +extern void initialize_resource_pool(void); +int CheckInitialization(Port* myport, StringInfo message, GTM_MessageType mtype); +void ProcessWorkloadManagerInitializeResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerCreateResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerUpdateResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); +void ProcessWorkloadManagerDeleteResourcePoolCommand(Port* myport, StringInfo message, bool is_backup); + +/* + * In gtm_snap.c + */ +void ProcessGetSnapshotCommand(Port* myport, StringInfo message, bool get_gxid); +void ProcessGetSnapshotLiteCommand(Port* myport, StringInfo message); +void ProcessGetSnapshotStatusCommand(Port* myport, StringInfo message); +void ProcessGetGTMLiteStatusCommand(Port* myport, StringInfo message); +void GTM_FreeSnapshotData(GTM_Snapshot snapshot); +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/gtm_utils.h postgresql-hll-2.14/include/include/gtm/gtm_utils.h --- postgresql-hll-2.14_old/include/include/gtm/gtm_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/gtm_utils.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,89 @@ +/* ------------------------------------------------------------------------- + * + * gtm_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/gtm_utils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_UTILS_H +#define GTM_UTILS_H + +#include "gtm/utils/libpq-int.h" +#include "gtm/gtm_msg.h" + +#ifndef WIN32 + +#include + +/* GTMS --> GTM Server */ +typedef struct timeval gtms_time; + +#define GTMS_TIME_IS_ZERO(t) ((t).tv_usec == 0 && (t).tv_sec == 0) + +#define GTMS_TIME_IS_INTMAX(t) ((t).tv_usec == LONG_MAX && (t).tv_sec == LONG_MAX) + +#define GTMS_TIME_INITIAL_MIN(t) ((t).tv_usec = LONG_MAX, (t).tv_sec = LONG_MAX) + +#define GTMS_TIME_IS_BIGGER(x, y) ((x).tv_sec >= (y).tv_sec && (x).tv_usec >= (y).tv_usec) + +#define GTMS_TIME_SET_ZERO(t) ((t).tv_sec = 0, (t).tv_usec = 0) + +#define GTMS_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) + +#define GTMS_TIME_ADD(x, y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define GTMS_TIME_SUBTRACT(x, y) \ + do { \ + (x).tv_sec -= (y).tv_sec; \ + (x).tv_usec -= (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + } while (0) + +#define GTMS_TIME_ACCUM_DIFF(x, y, z) \ + do { \ + (x).tv_sec += (y).tv_sec - (z).tv_sec; \ + (x).tv_usec += (y).tv_usec - (z).tv_usec; \ + /* Normalize after each add to avoid overflow/underflow of tv_usec */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define GTMS_TIME_GET_DOUBLE(t) (((double)(t).tv_sec) + ((double)(t).tv_usec) / 1000000.0) + +#define GTMS_TIME_GET_MILLISEC(t) (((double)(t).tv_sec * 1000.0) + ((double)(t).tv_usec) / 1000.0) + +#define GTMS_TIME_GET_MICROSEC(t) (((uint64)(t).tv_sec * (uint64)1000000) + (uint64)(t).tv_usec) + +#endif /* WIN32 */ + +void gtm_util_init_nametabs(void); +char* gtm_util_message_name(GTM_MessageType type); +char* gtm_util_result_name(GTM_ResultType type); + +extern void gtm_usleep(long microsec); +#endif /* GTM_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/assert.h postgresql-hll-2.14/include/include/gtm/utils/assert.h --- postgresql-hll-2.14_old/include/include/gtm/utils/assert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/assert.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * assert.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_ASSERT_H +#define GTM_ASSERT_H + +#include "c.h" + +extern THR_LOCAL bool assert_enabled; + +/* + * USE_ASSERT_CHECKING, if defined, turns on all the assertions. + * - plai 9/5/90 + * + * It should _NOT_ be defined in releases or in benchmark copies + */ + +/* + * Trap + * Generates an exception if the given condition is true. + */ +#define Trap(condition, errorType) \ + do { \ + if ((assert_enabled) && (condition)) \ + ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__); \ + } while (0) + +/* + * TrapMacro is the same as Trap but it's intended for use in macros: + * + * #define foo(x) (AssertMacro(x != 0) && bar(x)) + * + * Isn't CPP fun? + */ +#define TrapMacro(condition, errorType) \ + ((bool)((!assert_enabled) || !(condition) || \ + (ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__)))) +#ifdef PC_LINT +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#define AssertMacro Assert +#define AssertArg Assert +#define DBG_ASSERT Assert +#define AssertState Assert +#else + +#ifndef USE_ASSERT_CHECKING +#define Assert(condition) +#define AssertMacro(condition) ((void)true) +#define AssertArg(condition) +#define AssertState(condition) +#else +#define Assert(condition) Trap(!(condition), "FailedAssertion") + +#define AssertMacro(condition) ((void)TrapMacro(!(condition), "FailedAssertion")) + +#define AssertArg(condition) Trap(!(condition), "BadArgument") + +#define AssertState(condition) Trap(!(condition), "BadState") +#endif /* USE_ASSERT_CHECKING */ +#endif // PC_LINT +extern int ExceptionalCondition(const char* conditionName, const char* errorType, const char* fileName, int lineNumber); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/atomic.h postgresql-hll-2.14/include/include/gtm/utils/atomic.h --- postgresql-hll-2.14_old/include/include/gtm/utils/atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/atomic.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * atomic.h + * Header file for atomic operations. + * + * + * IDENTIFICATION + * src/include/gtm/atomic.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_GTM_ATOMIC_H +#define SRC_INCLUDE_GTM_ATOMIC_H + +extern int32 gs_atomic_add_32(volatile int32* ptr, int32 inc); +extern int64 gs_atomic_add_64(int64* ptr, int64 inc); + +extern int32 gs_lock_test_and_set(volatile int32* ptr, int32 val); +extern int64 gs_lock_test_and_set_64(volatile int64* ptr, int64 val); + +extern bool gs_compare_and_swap_32(volatile int32* dest, int32 oldval, int32 newval); +extern bool gs_compare_and_swap_64(int64* dest, int64 oldval, int64 newval); + +extern void pg_atomic_init_u32(volatile uint32* ptr, uint32 val); +extern uint32 pg_atomic_read_u32(volatile uint32* ptr); +extern uint32 pg_atomic_fetch_or_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_and_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_add_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_add_fetch_u32(volatile uint32* ptr, uint32 inc); +extern uint32 pg_atomic_fetch_sub_u32(volatile uint32* ptr, int32 inc); +extern uint32 pg_atomic_sub_fetch_u32(volatile uint32* ptr, int32 inc); +extern bool pg_atomic_compare_exchange_u32(volatile uint32* ptr, uint32* expected, uint32 newval); +extern void pg_atomic_write_u32(volatile uint32* ptr, uint32 val); +extern uint32 pg_atomic_exchange_u32(volatile uint32* ptr, uint32 newval); + +extern void pg_atomic_init_u64(volatile uint64* ptr, uint64 val); +extern uint64 pg_atomic_read_u64(volatile uint64* ptr); +extern uint64 pg_atomic_fetch_or_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_and_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_add_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_add_fetch_u64(volatile uint64* ptr, uint64 inc); +extern uint64 pg_atomic_fetch_sub_u64(volatile uint64* ptr, int64 inc); +extern uint64 pg_atomic_sub_fetch_u64(volatile uint64* ptr, int64 inc); +extern bool pg_atomic_compare_exchange_u64(volatile uint64* ptr, uint64* expected, uint64 newval); +extern void pg_atomic_write_u64(volatile uint64* ptr, uint64 val); +extern uint64 pg_atomic_exchange_u64(volatile uint64* ptr, uint64 newval); + +#endif // SRC_INCLUDE_GTM_ATOMIC_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/barrier.h postgresql-hll-2.14/include/include/gtm/utils/barrier.h --- postgresql-hll-2.14_old/include/include/gtm/utils/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/barrier.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * Memory barrier operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/gtm/utils/barrier.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GTMBARRIER_H +#define GTMBARRIER_H + +#include "gtm/gtm_slock.h" + +/* + * A compiler barrier need not (and preferably should not) emit any actual + * machine code, but must act as an optimization fence: the compiler must not + * reorder loads or stores to main memory around the barrier. However, the + * CPU may still reorder loads or stores at runtime, if the architecture's + * memory model permits this. + * + * A memory barrier must act as a compiler barrier, and in addition must + * guarantee that all loads and stores issued prior to the barrier are + * completed before any loads or stores issued after the barrier. Unless + * loads and stores are totally ordered (which is not the case on most + * architectures) this requires issuing some sort of memory fencing + * instruction. + * + * A read barrier must act as a compiler barrier, and in addition must + * guarantee that any loads issued prior to the barrier are completed before + * any loads issued after the barrier. Similarly, a write barrier acts + * as a compiler barrier, and also orders stores. Read and write barriers + * are thus weaker than a full memory barrier, but stronger than a compiler + * barrier. In practice, on machines with strong memory ordering, read and + * write barriers may require nothing more than a compiler barrier. + * + * For an introduction to using memory barriers within the PostgreSQL backend, + * see src/backend/storage/lmgr/README.barrier + */ + +#if defined(DISABLE_BARRIERS) + +/* + * Fall through to the spinlock-based implementation. + */ +#elif defined(__INTEL_COMPILER) + +/* + * icc defines __GNUC__, but doesn't support gcc's inline asm syntax + */ +#define pg_memory_barrier() _mm_mfence() +#define pg_compiler_barrier() __memory_barrier() +#elif defined(__GNUC__) + +/* This works on any architecture, since it's only talking to GCC itself. */ +#define pg_compiler_barrier() __asm__ __volatile__("" : : : "memory") + +#if defined(__i386__) + +/* + * i386 does not allow loads to be reordered with other loads, or stores to be + * reordered with other stores, but a load can be performed before a subsequent + * store. + * + * "lock; addl" has worked for longer than "mfence". + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__x86_64__) /* 64 bit x86 */ + +/* + * x86_64 has similar ordering characteristics to i386. + * + * Technically, some x86-ish chips support uncached memory access and/or + * special instructions that are weakly ordered. In those cases we'd need + * the read and write barriers to be lfence and sfence. But since we don't + * do those things, a compiler barrier should be enough. + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%rsp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__aarch64__) +/* + * aarch64 architecure memory barrier. In order to minimize the impact on + * performance, here use dmb memory barrier. + */ +#define pg_memory_barrier_dsb(opt) __asm__ __volatile__("DMB " #opt::: "memory") + +#ifndef ENABLE_THREAD_CHECK + +#define pg_memory_barrier() pg_memory_barrier_dsb(ish) +#define pg_read_barrier() pg_memory_barrier_dsb(ishld) +#define pg_write_barrier() pg_memory_barrier_dsb(ishst) + +#else + +#include "tsan_annotation.h" + +#define pg_memory_barrier() do { \ + TsAnnotateReadBarrier(); \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ish); \ +} while (0) + +#define pg_read_barrier() do { \ + TsAnnotateReadBarrier(); \ + pg_memory_barrier_dsb(ishld); \ +} while (0) + +#define pg_write_barrier() do { \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ishst); \ +} while (0) + +#endif +#elif defined(__ia64__) || defined(__ia64) + +/* + * Itanium is weakly ordered, so read and write barriers require a full + * fence. + */ +#define pg_memory_barrier() __asm__ __volatile__("mf" : : : "memory") +#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) + +/* + * lwsync orders loads with respect to each other, and similarly with stores. + * But a load can be performed before a subsequent store, so sync must be used + * for a full memory barrier. + */ +#define pg_memory_barrier() __asm__ __volatile__("sync" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#elif defined(__alpha) || defined(__alpha__) /* Alpha */ + +/* + * Unlike all other known architectures, Alpha allows dependent reads to be + * reordered, but we don't currently find it necessary to provide a conditional + * read barrier to cover that case. We might need to add that later. + */ +#define pg_memory_barrier() __asm__ __volatile__("mb" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("rmb" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("wmb" : : : "memory") +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) + +/* + * If we're on GCC 4.1.0 or higher, we should be able to get a memory + * barrier out of this compiler built-in. But we prefer to rely on our + * own definitions where possible, and use this only as a fallback. + */ +#define pg_memory_barrier() __sync_synchronize() +#endif +#elif defined(__ia64__) || defined(__ia64) + +#define pg_compiler_barrier() _Asm_sched_fence() +#define pg_memory_barrier() _Asm_mf() +#elif defined(WIN32_ONLY_COMPILER) + +/* Should work on both MSVC and Borland. */ +#include +#pragma intrinsic(_ReadWriteBarrier) +#define pg_compiler_barrier() _ReadWriteBarrier() +#define pg_memory_barrier() MemoryBarrier() +#endif + +/* + * If we have no memory barrier implementation for this architecture, we + * fall back to acquiring and releasing a spinlock. This might, in turn, + * fall back to the semaphore-based spinlock implementation, which will be + * amazingly slow. + * + * It's not self-evident that every possible legal implementation of a + * spinlock acquire-and-release would be equivalent to a full memory barrier. + * For example, I'm not sure that Itanium's acq and rel add up to a full + * fence. But all of our actual implementations seem OK in this regard. + */ + +#if !defined(pg_memory_barrier) +#define pg_memory_barrier(x) \ + do { \ + S_LOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + S_UNLOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + } while (0) +#endif +/* + * If read or write barriers are undefined, we upgrade them to full memory + * barriers. + * + * If a compiler barrier is unavailable, you probably don't want a full + * memory barrier instead, so if you have a use case for a compiler barrier, + * you'd better use #ifdef. + */ +#if !defined(pg_read_barrier) +#define pg_read_barrier() pg_memory_barrier() +#endif +#if !defined(pg_write_barrier) +#define pg_write_barrier() pg_memory_barrier() +#endif + +#endif /* GTMBARRIER_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/elog.h postgresql-hll-2.14/include/include/gtm/utils/elog.h --- postgresql-hll-2.14_old/include/include/gtm/utils/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/elog.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,314 @@ +/* ------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.98 2009/01/01 17:24:02 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include "c.h" +#include "securec.h" +#include "securec_check.h" + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ +#define DEBUG4 11 +#define DEBUG3 12 +#define DEBUG2 13 +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ +#define COMMERROR \ + 16 /* Client communication problems; same as LOG \ + * for server reporting, but never sent to \ + * client. */ +#define INFO \ + 17 /* Messages specifically requested by user \ + * (eg VACUUM VERBOSE output); always sent to \ + * client regardless of client_min_messages, \ + * but by default not sent to server log. */ +#define NOTICE \ + 18 /* Helpful messages to users about query \ + * operation; sent to client and server log \ + * by default. */ +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define ERROR2 \ + 21 /* user error - only send error message to the \ + * client */ +#define FATAL 22 /* fatal error - abort process */ +#define PANIC 23 /* take down the other backends with me */ + +/* Which __func__ symbol do we have, if any? */ +#ifdef HAVE_FUNCNAME__FUNC +#define PG_FUNCNAME_MACRO __func__ +#else +#ifdef HAVE_FUNCNAME__FUNCTION +#define PG_FUNCNAME_MACRO __FUNCTION__ +#else +#define PG_FUNCNAME_MACRO NULL +#endif +#endif + +#define securec_check(errno, charList, ...) \ + { \ + if (unlikely(EOK != errno)) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + switch (errno) { \ + case EINVAL: \ + elog(ERROR, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(ERROR, "%s : %d : The source buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(ERROR, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } + +/* Only used in sprintf_s or scanf_s cluster function */ +#define securec_check_ss(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + elog(ERROR, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } + +/* + * ErrorData holds the data accumulated during any one ereport() cycle. + * Any non-NULL pointers must point to palloc'd data. + * (The const pointers are an exception; we assume they point at non-freeable + * constant strings.) + */ +typedef struct ErrorData { + int elevel; /* error level */ + bool output_to_server; /* will report to server log? */ + bool output_to_client; /* will report to client? */ + bool show_funcname; /* true to force funcname inclusion */ + const char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + const char* funcname; /* __func__ of ereport() call */ + const char* domain; /* message domain */ + char* message; /* primary error message */ + char* detail; /* detail error message */ + char* detail_log; /* detail error message for server log only */ + char* hint; /* hint message */ + char* context; /* context message */ + int saved_errno; /* errno at entry */ +} ErrorData; + +/* ---------- + * New-style error reporting API: to be used in this way: + * ereport(ERROR, + * (errcode(ERRCODE_UNDEFINED_CURSOR), + * errmsg("portal \"%s\" not found", stmt->portalname), + * ... other errxxx() fields as needed ...)); + * + * The error level is required, and so is a primary error message (errmsg + * or errmsg_internal). All else is optional. errcode() defaults to + * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING + * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is + * NOTICE or below. + * + * ereport_domain() allows a message domain to be specified, for modules that + * wish to use a different message catalog from the backend's. To avoid having + * one copy of the default text domain per .o file, we define it as NULL here + * and have errstart insert the default text domain. Modules can either use + * ereport_domain() directly, or preferably they can override the TEXTDOMAIN + * macro. + * ---------- + */ +#define TEXTDOMAIN "GTM" + +#define ereport_domain(elevel, domain, rest) \ + (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? (errfinish rest) : (void)0) + +#define ereport(elevel, rest) ereport_domain(elevel, TEXTDOMAIN, rest) + +#define PG_RE_THROW() pg_re_throw() + +extern bool errstart(int elevel, const char* filename, int lineno, const char* funcname, const char* domain); +extern void errfinish(int dummy, ...); + +extern int errmsg(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errmsg_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errdetail(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errdetail_log(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +extern int errhint(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); + +/* ---------- + * Old-style error reporting API: to be used in this way: + * elog(ERROR, "portal \"%s\" not found", stmt->portalname); + * ---------- + */ + +#ifdef PC_LINT +#define elog(level, ...) \ + do { \ + if (level >= ERROR) \ + exit(0); \ + } while (0) +#else +#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish +#endif /* PCLINT_CHECK */ + +extern void elog_start(const char* filename, int lineno, const char* funcname); +extern void elog_finish(int elevel, const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 2, 3))); + +/* ---------- + * API for catching ereport(ERROR) exits. Use these macros like so: + * + * PG_TRY(); + * { + * ... code that might throw ereport(ERROR) ... + * } + * PG_CATCH(); + * { + * ... error recovery code ... + * } + * PG_END_TRY(); + * + * (The braces are not actually necessary, but are recommended so that + * pg_indent will indent the construct nicely.) The error recovery code + * can optionally do PG_RE_THROW() to propagate the same error outwards. + * + * Note: while the system will correctly propagate any new ereport(ERROR) + * occurring in the recovery section, there is a small limit on the number + * of levels this will work for. It's best to keep the error recovery + * section simple enough that it can't generate any new errors, at least + * not before popping the error stack. + * + * Note: an ereport(FATAL) will not be caught by this construct; control will + * exit straight through proc_exit(). Therefore, do NOT put any cleanup + * of non-process-local resources into the error recovery section, at least + * not without taking thought for what will happen during ereport(FATAL). + * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be + * helpful in such cases. + * ---------- + */ +#define PG_TRY() \ + do { \ + sigjmp_buf* save_exception_stack = PG_exception_stack; \ + sigjmp_buf local_sigjmp_buf; \ + if (sigsetjmp(local_sigjmp_buf, 0) == 0) { \ + PG_exception_stack = &local_sigjmp_buf + +#define PG_CATCH() \ + } \ + else \ + { \ + PG_exception_stack = save_exception_stack; + +#define PG_END_TRY() \ + } \ + PG_exception_stack = save_exception_stack; \ + } \ + while (0) + +int errfunction(const char* funcname); + +extern void EmitErrorReport(void* port); + +/* GUC-configurable parameters */ + +typedef enum { + PGERROR_TERSE, /* single-line error messages */ + PGERROR_DEFAULT, /* recommended style */ + PGERROR_VERBOSE /* all the facts, ma'am */ +} PGErrorVerbosity; + +/* Log destination bitmap */ +#define LOG_DESTINATION_STDERR 1 +#define LOG_DESTINATION_SYSLOG 2 +#define LOG_DESTINATION_EVENTLOG 4 +#define LOG_DESTINATION_CSVLOG 8 + +/* Other exported functions */ +extern void pg_re_throw(void); +extern void DebugFileOpen(void); +extern void FlushErrorState(void); + +void freeSecurityFuncSpace(char* charList, ...); + +/* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used + * safely (memory context, GUC load etc) + */ +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(printf, 1, 2))); +extern void check_gtm_env(const char* input_env_value); +#endif /* GTM_ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/event_engine.h postgresql-hll-2.14/include/include/gtm/utils/event_engine.h --- postgresql-hll-2.14_old/include/include/gtm/utils/event_engine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/event_engine.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,112 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * event_engine.h + * event engine header file + * + * IDENTIFICATION + * src/include/gtm/utils/event_engine.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef EVENT_ENGINE_H +#define EVENT_ENGINE_H + +#include +#include "c.h" + +/* wait for a socket or FD to become readable */ +#define EV_READ 0x02 + +/* wait for a socket or FD to become writeable */ +#define EV_WRITE 0x04 + +/* persistent event */ +#define EV_PERSIST 0x10 + +/* select edge-triggered behavior, if supported by the backend */ +#define EV_ET 0x20 + +/* connection close event */ +#define EV_CLOSED 0x80 + +typedef struct event_config event_config_t; +typedef struct epoll_info epoll_info_t; +typedef struct event event_t; +typedef struct event_iomap event_iomap_t; +typedef struct event_base event_base_t; +typedef struct event_callback event_callback_t; + +struct event_config { + int max_dispatch_callbacks; +}; + +struct epoll_info { + int epfd; + int nevents; + struct epoll_event *epevs; +}; + +struct event { + event_base_t *ev_base; + int ev_fd; + int ev_state; + unsigned short ev_events; + unsigned short ev_res; /* result passed to event callback */ + void (*ev_cb)(int, unsigned short, void *); + void *ev_cb_arg; +}; + +struct event_iomap { + event_t **entries; + int nentries; +}; + +struct event_base { + epoll_info_t *epi; + event_iomap_t iomap; + /* number of total events added to this event_base */ + int event_count; + /* number of total active events in this event_base */ + int event_count_active; + /* set if we should terminate the loop immediately */ + bool event_break; + bool event_exit; + bool interruptable; + bool loop_one_shot; + /* set to prevent reentrant invocation */ + bool running_loop; + struct timeval timeout; + int max_dispatch_callbacks; +}; + +extern event_config_t *event_config_new(); +extern void event_config_free(event_config_t *cfg); +extern event_base_t *event_base_new(const event_config_t *cfg); +extern int event_assign(event_t *ev, event_base_t *base, int fd, unsigned short events, + void (*callback)(int, unsigned short, void *), void *arg); +extern int event_add(event_t *ev, const struct timeval *tv); +extern int event_del(event_t *ev); +extern int event_base_dispatch(event_base_t *event_base); +extern int event_base_loop(event_base_t *base, int flags); +extern int event_base_loopbreak(event_base_t *event_base); +extern int event_base_loopexit(event_base_t *event_base); +extern void event_base_free(event_base_t *base); +extern int event_get_max(); +extern bool event_exceed_limit(const event_base_t *base); +extern int event_base_retrieve_fds(event_base_t *base, int *fds, int len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/ip.h postgresql-hll-2.14/include/include/gtm/utils/ip.h --- postgresql-hll-2.14_old/include/include/gtm/utils/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/ip.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.20 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "gtm/utils/pqcomm.h" + +extern int pg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void pg_freeaddrinfo_all(struct addrinfo* ai); + +extern int pg_getnameinfo_all( + const struct sockaddr_storage* addr, int salen, char* node, int nodelen, char* service, int servicelen, int flags); + +extern int pg_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int pg_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/libpq-be.h postgresql-hll-2.14/include/include/gtm/utils/libpq-be.h --- postgresql-hll-2.14_old/include/include/gtm/utils/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/libpq-be.h 2020-12-12 17:06:43.206347509 +0800 @@ -0,0 +1,113 @@ +/* ------------------------------------------------------------------------- + * + * libpq_be.h + * This file contains definitions for structures and externs used + * by the postmaster during client authentication. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.69 2009/01/01 17:23:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_BE_H +#define LIBPQ_BE_H + +#include "gtm/utils/pqcomm.h" +#include "gtm/gtm_c.h" +#include "libpq/sha2.h" +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif + +/* + * This is used by the postmaster in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMostMemoryContext, + * so that it survives into GTM_ThreadMain execution! + */ + +typedef struct Port { + int sock; /* File descriptor */ + SockAddr laddr; /* local addr (postmaster) */ + SockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_port; /* text rep of remote port */ + GTM_PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ + + GTMProxy_ConnID conn_id; /* RequestID of this command */ + + GTM_PGXCNodeType remote_type; /* Type of remote connection */ + char* node_name; + bool is_postmaster; /* Is remote a node postmaster? */ + pthread_t remote_thdpid; /* remote connection thread pid */ +#define PQ_BUFFER_SIZE 8192 + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + + /* + * GTM communication error handling. See libpq-int.h for details. + */ + int connErr_WaitOpt; + int connErr_WaitInterval; + int connErr_WaitCount; + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token buffer */ +#endif + +} Port; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +typedef enum { GTM_UNUSED_LISTEN_SOCKET = 0, GTM_SERVICE_LISTEN_SOCKET, GTM_HA_LISTEN_SOCKET } GTM_ListenSocketType; + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/libpq-fe.h postgresql-hll-2.14/include/include/gtm/utils/libpq-fe.h --- postgresql-hll-2.14_old/include/include/gtm/utils/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/libpq-fe.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,135 @@ +/* ------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.145 2009/01/01 17:24:03 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ + +#ifndef GTM_LIBPQ_FE_H +#define GTM_LIBPQ_FE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* + * postgres_ext.h defines the backend's externally visible types, + * such as Oid. + */ +#include "gtm/gtm_ext.h" + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +/* Application-visible enum types */ + +typedef enum { + /* + * Although it is okay to add to this list, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} GTMConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} GTMClientPollingStatusType; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or GTMPQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. GTMPQconninfoFree() + * will release both the val strings and the GTMPQconninfoOption array itself. + * ---------------- + */ +typedef struct _GTMPQconninfoOption { + char* keyword; /* The keyword of the option */ + char* val; /* Option's current value, or NULL */ +} GTMPQconninfoOption; + +typedef struct gtm_conn GTM_Conn; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern GTM_Conn* PQconnectGTMStart(const char* conninfo); +extern GTMClientPollingStatusType GTMPQconnectPoll(GTM_Conn* conn); + +/* Synchronous (blocking) */ +extern GTM_Conn* PQconnectGTM(const char* conninfo); + +/* close the current connection and free the GTM_Conn data structure */ +extern void GTMPQfinish(GTM_Conn* conn); + +/* parse connection options in same way as PQconnectGTM */ +extern GTMPQconninfoOption* GTMPQconninfoParse(const char* conninfo, char** errmsg); + +/* free the data structure returned by PQconndefaults() or GTMPQconninfoParse() */ +extern void GTMPQconninfoFree(GTMPQconninfoOption* connOptions); + +extern char* GTMPQhost(const GTM_Conn* conn); +extern char* GTMPQport(const GTM_Conn* conn); +extern GTMConnStatusType GTMPQstatus(const GTM_Conn* conn); +extern int GTMPQispostmaster(const GTM_Conn* conn); +extern char* GTMPQerrorMessage(const GTM_Conn* conn); +extern int GTMPQsocket(const GTM_Conn* conn); + +/* Enable/disable tracing */ +extern void GTMPQtrace(GTM_Conn* conn, FILE* debug_port); +extern void GTMPQuntrace(GTM_Conn* conn); + +/* Force the write buffer to be written (or at least try) */ +extern int PQflush(GTM_Conn* conn); + +#define libpq_gettext(x) x + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/libpq.h postgresql-hll-2.14/include/include/gtm/utils/libpq.h --- postgresql-hll-2.14_old/include/include/gtm/utils/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/libpq.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/libpq.h,v 1.70 2008/11/20 09:29:36 mha Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_H +#define LIBPQ_H + +#include +#include + +#include "gtm/utils/stringinfo.h" +#include "gtm/utils/libpq-be.h" + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], + GTM_ListenSocketType listenSocketType[], int MaxListen, bool isServiceSocket, bool noblock); +extern int StreamConnection(int sfd, Port* port, SockAddr *sa, bool noblock); +extern void StreamClose(int sock); +extern void TouchSocketFile(void); +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len); +extern int pq_getstring(Port* myport, StringInfo s); +extern int pq_getmessage(Port* myport, StringInfo s, int maxlen); +extern int pq_getbyte(Port* myport); +extern int pq_peekbyte(Port* myport); +extern int pq_putbytes(Port* myport, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/libpq-int.h postgresql-hll-2.14/include/include/gtm/utils/libpq-int.h --- postgresql-hll-2.14_old/include/include/gtm/utils/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/libpq-int.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.139 2009/01/01 17:24:03 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_INT_H +#define LIBPQ_INT_H + +#include +#include +#include +#include "gtm/utils/pqcomm.h" +#include "gtm/utils/pqexpbuffer.h" +#include "gtm/gtm_client.h" +#include "gtm/gtm_c.h" +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif +/* + * GTM_Conn stores all the state data associated with a single connection + * to a backend. + */ +struct gtm_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the IPv4 address of the machine on which + * the server is running, in IPv4 + * numbers-and-dots notation. Takes precedence + * over above. */ + char* gtmlocalhost; /* for gtm HA to connect to standby */ + char* gtmlocalport; /* for gtm HA to connect to standby */ + char* pgport; /* the server's communication port */ + char* connect_timeout; /* connection timeout (numeric string) */ + char* gc_node_name; /* PGXC Node Name */ + int remote_type; /* is this a connection to/from a proxy ? */ + int is_postmaster; /* is this connection to/from a postmaster instance */ + pthread_t remote_thdpid; /* remote node thread pid */ + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Status indicators */ + GTMConnStatusType status; + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + SockAddr laddr; /* Local address */ + SockAddr raddr; /* Remote address */ + + /* Error info for GTM communication */ + GTM_PortLastCall last_call; /* Last syscall to this sock. */ + int last_errno; /* Last errno. zero if the last call succeeds. */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + + /* Pointer to the result of last operation */ + GTM_Result* result; + + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_name_t gss_targ_nam; /* GSS target name */ + gss_buffer_desc gss_inbuf; /* GSS input token */ + gss_buffer_desc gss_outbuf; /* GSS output token */ +#endif +}; + +/* === in fe-misc.c === */ +extern THR_LOCAL bool g_gtm_interrupt_happened; + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int gtmpqCheckOutBufferSpace(size_t bytes_needed, GTM_Conn* conn); +extern int gtmpqCheckInBufferSpace(size_t bytes_needed, GTM_Conn* conn); +extern int gtmpqGetc(char* result, GTM_Conn* conn); +extern int gtmpqPutc(char c, GTM_Conn* conn); +extern int gtmpqGets(PQExpBuffer buf, GTM_Conn* conn); +extern int gtmpqGets_append(PQExpBuffer buf, GTM_Conn* conn); +extern int gtmpqPuts(const char* s, GTM_Conn* conn); +extern int gtmpqGetnchar(char* s, size_t len, GTM_Conn* conn); +extern int gtmpqPutnchar(const char* s, size_t len, GTM_Conn* conn); +extern int gtmpqGetInt(int* result, size_t bytes, GTM_Conn* conn); +extern int64 gtmpqGetInt64(uint64* result, GTM_Conn* conn); +extern int gtmpqPutInt(int value, size_t bytes, GTM_Conn* conn); +extern int gtmpqPutInt64(uint64 value, GTM_Conn* conn); +extern int gtmpqPutMsgStart(char msg_type, bool force_len, GTM_Conn* conn); +extern int gtmpqPutMsgEnd(GTM_Conn* conn); +extern int gtmpqReadData(GTM_Conn* conn); +extern int gtmpqFlush(GTM_Conn* conn); +extern int gtmpqWait(int forRead, int forWrite, GTM_Conn* conn); +extern int gtmpqWaitTimed(int forRead, int forWrite, GTM_Conn* conn, time_t finish_time); +extern int gtmpqReadReady(GTM_Conn* conn); +extern int gtmpqWriteReady(GTM_Conn* conn); + +/* + * In fe-protocol.c + */ +GTM_Result* GTMPQgetResult(GTM_Conn* conn); +extern int gtmpqGetError(GTM_Conn* conn, GTM_Result* result); +void gtmpqFreeResultData(GTM_Result* result, GTM_PGXCNodeType remote_type); + +// In gtmctl-protocol.c +GTM_Result* GTMCTLPQgetResult(GTM_Conn* conn); +int gtmpqPutMsgBytes(const void* buf, size_t len, GTM_Conn* conn); + +#define SOCK_ERRNO errno +#define SOCK_ERRNO_SET(e) (errno = (e)) + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/memnodes.h postgresql-hll-2.14/include/include/gtm/utils/memnodes.h --- postgresql-hll-2.14_old/include/include/gtm/utils/memnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/memnodes.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * memnodes.h + * POSTGRES memory context node definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.34 2008/01/01 19:45:58 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMNODES_H +#define MEMNODES_H + +#include "gtm/gtm_lock.h" + +/* + * MemoryContext + * A logical context in which memory allocations occur. + * + * MemoryContext itself is an abstract type that can have multiple + * implementations, though for now we have only AllocSetContext. + * The function pointers in MemoryContextMethods define one specific + * implementation of MemoryContext --- they are a virtual function table + * in C++ terms. + * + * Note: for largely historical reasons, typedef MemoryContext is a pointer + * to the context struct rather than the struct type itself. + */ + +typedef struct MemoryContextMethods { + void* (*alloc)(MemoryContext context, Size size); + /* call this free_p in case someone #define's free() */ + void (*free_p)(MemoryContext context, void* pointer); + void* (*realloc)(MemoryContext context, void* pointer, Size size); + void (*init)(MemoryContext context); + void (*reset)(MemoryContext context); + void (*delete_context)(MemoryContext context); + Size (*get_chunk_space)(MemoryContext context, void* pointer); + bool (*is_empty)(MemoryContext context); + void (*stats)(MemoryContext context, int level); +#ifdef MEMORY_CONTEXT_CHECKING + void (*check)(MemoryContext context); +#endif +} MemoryContextMethods; + +typedef struct MemoryContextData { + MemoryContextMethods* methods; /* virtual function table */ + MemoryContext parent; /* NULL if no parent (toplevel context) */ + MemoryContext firstchild; /* head of linked list of children */ + MemoryContext nextchild; /* next child of same parent */ + char* name; /* context name (just for debugging) */ + bool is_shared; /* context is shared by threads */ + GTM_RWLock lock; /* lock to protect members if the context is shared */ +} MemoryContextData; + +#define MemoryContextIsShared(context) (((MemoryContextData*)(context))->is_shared) + +#define MemoryContextLock(context) (GTM_RWLockAcquire(&((MemoryContextData*)(context))->lock, GTM_LOCKMODE_WRITE)) +#define MemoryContextUnlock(context) (GTM_RWLockRelease(&((MemoryContextData*)(context))->lock)) +/* + * MemoryContextIsValid + * True iff memory context is valid. + * + * Add new context types to the set accepted by this macro. + */ +#define MemoryContextIsValid(context) ((context) != NULL) + +#endif /* MEMNODES_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/memutils.h postgresql-hll-2.14/include/include/gtm/utils/memutils.h --- postgresql-hll-2.14_old/include/include/gtm/utils/memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/memutils.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,121 @@ +/* ------------------------------------------------------------------------- + * + * memutils.h + * This file contains declarations for memory allocation utility + * functions. These are functions that are not quite widely used + * enough to justify going in utils/palloc.h, but are still part + * of the API of the memory management subsystem. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.64 2008/01/01 19:45:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMUTILS_H +#define MEMUTILS_H + +#include "gtm/gtm_c.h" +#include "gtm/utils/palloc.h" +#include "gtm/utils/memnodes.h" + +enum GTMMemoryContextType { + STANDARD_CONTEXT /* postgres orignal context */ + , + SHARED_CONTEXT /* shared context used by different threads */ +}; + +/* + * MaxAllocSize + * Quasi-arbitrary limit on size of allocations. + * + * Note: + * There is no guarantee that allocations smaller than MaxAllocSize + * will succeed. Allocation requests larger than MaxAllocSize will + * be summarily denied. + * + * XXX This is deliberately chosen to correspond to the limiting size + * of varlena objects under TOAST. See VARATT_MASK_SIZE in postgres.h. + * + * XXX Also, various places in aset.c assume they can compute twice an + * allocation's size without overflow, so beware of raising this. + */ +#define MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define AllocSizeIsValid(size) ((Size)(size) <= MaxAllocSize) + +/* + * All chunks allocated by any memory context manager are required to be + * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. + * A currently-allocated chunk must contain a backpointer to its owning + * context as well as the allocated size of the chunk. The backpointer is + * used by pfree() and repalloc() to find the context to call. The allocated + * size is not absolutely essential, but it's expected to be needed by any + * reasonable implementation. + */ +typedef struct StandardChunkHeader { + MemoryContext context; /* owning context */ + Size size; /* size of data space allocated in chunk */ +#ifdef MEMORY_CONTEXT_CHECKING + /* when debugging memory usage, also store actual requested size */ + Size requested_size; +#endif +} StandardChunkHeader; + +#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader)) + +/* + * Memory-context-type-independent functions in mcxt.c + */ +extern void MemoryContextInit(void); +extern void MemoryContextReset(MemoryContext context); +extern void MemoryContextDelete(MemoryContext context); +extern void MemoryContextResetChildren(MemoryContext context); +extern void MemoryContextDeleteChildren(MemoryContext context); +extern void MemoryContextResetAndDeleteChildren(MemoryContext context); +extern Size GetMemoryChunkSpace(void* pointer); +extern MemoryContext GetMemoryChunkContext(void* pointer); +extern bool MemoryContextIsEmpty(MemoryContext context); +extern void MemoryContextStats(MemoryContext context); + +#ifdef MEMORY_CONTEXT_CHECKING +extern void MemoryContextCheck(MemoryContext context); +#endif +extern bool MemoryContextContains(MemoryContext context, void* pointer); + +/* + * This routine handles the context-type-independent part of memory + * context creation. It's intended to be called from context-type- + * specific creation routines, and noplace else. + */ +extern MemoryContext MemoryContextCreate( + Size size, MemoryContextMethods* methods, MemoryContext parent, const char* name); + +/* + * Memory-context-type-specific functions + */ + +/* aset.c */ +extern MemoryContext AllocSetContextCreate( + MemoryContext parent, const char* name, Size minContextSize, Size initBlockSize, Size maxBlockSize, bool isShared); + +/* + * Recommended default alloc parameters, suitable for "ordinary" contexts + * that might hold quite a lot of data. + */ +#define ALLOCSET_DEFAULT_MINSIZE 0 +#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024) +#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024) + +/* + * Recommended alloc parameters for "small" contexts that are not expected + * to contain much data (for example, a context to contain a query plan). + */ +#define ALLOCSET_SMALL_MINSIZE 0 +#define ALLOCSET_SMALL_INITSIZE (1 * 1024) +#define ALLOCSET_SMALL_MAXSIZE (8 * 1024) + +#endif /* MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/palloc.h postgresql-hll-2.14/include/include/gtm/utils/palloc.h --- postgresql-hll-2.14_old/include/include/gtm/utils/palloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/palloc.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,104 @@ +/* ------------------------------------------------------------------------- + * + * palloc.h + * POSTGRES memory allocator definitions. + * + * This file contains the basic memory allocation interface that is + * needed by almost every backend module. It is included directly by + * postgres.h, so the definitions here are automatically available + * everywhere. Keep it lean! + * + * Memory allocation occurs within "contexts". Every chunk obtained from + * palloc()/MemoryContextAlloc() is allocated within a specific context. + * The entire contents of a context can be freed easily and quickly by + * resetting or deleting the context --- this is both faster and less + * prone to memory-leakage bugs than releasing chunks individually. + * We organize contexts into context trees to allow fine-grain control + * over chunk lifetime while preserving the certainty that we will free + * everything that should be freed. See utils/mmgr/README for more info. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.40 2008/06/28 16:45:22 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PALLOC_H +#define PALLOC_H + +/* + * Flags for MemoryContextAllocExtended. + */ +#define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +/* + * Type MemoryContextData is declared in nodes/memnodes.h. Most users + * of memory allocation should just treat it as an abstract type, so we + * do not provide the struct contents here. + */ +typedef struct MemoryContextData* MemoryContext; + +/* + * Fundamental memory-allocation operations (more are in utils/memutils.h) + */ +extern void* MemoryContextAlloc(MemoryContext context, Size size); +extern void* MemoryContextAllocZero(MemoryContext context, Size size); +extern void* MemoryContextAllocZeroAligned(MemoryContext context, Size size); + +#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz)) + +#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz)) + +/* + * The result of palloc() is always word-aligned, so we can skip testing + * alignment of the pointer when deciding which MemSet variant to use. + * Note that this variant does not offer any advantage, and should not be + * used, unless its "sz" argument is a compile-time constant; therefore, the + * issue that it evaluates the argument multiple times isn't a problem in + * practice. + */ +#define palloc0fast(sz) \ + (MemSetTest(0, sz) ? MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) \ + : MemoryContextAllocZero(CurrentMemoryContext, sz)) + +extern void pfree(void* pointer); + +extern void* repalloc(void* pointer, Size size); + +/* + * MemoryContextSwitchTo can't be a macro in standard C compilers. + * But we can make it an inline function when using GCC. + */ + +extern MemoryContext MemoryContextSwitchTo(MemoryContext context); + +/* + * These are like standard strdup() except the copied string is + * allocated in a context, not with malloc(). + */ +extern char* MemoryContextStrdup(MemoryContext context, const char* string); + +#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str)) + +extern char* pnstrdup(const char* in, Size len); + +#if defined(WIN32) || defined(__CYGWIN__) +extern void* pgport_palloc(Size sz); +extern char* pgport_pstrdup(const char* str); +extern void pgport_pfree(void* pointer); +#endif + +#ifdef PGXC +/* + * The following part provides common palloc binary interface. This + * is needed especially for gtm_serialize.c and gtm_serialize_debug.c. + */ +#include "gen_alloc.h" +#endif + +#endif /* PALLOC_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/path.h postgresql-hll-2.14/include/include/gtm/utils/path.h --- postgresql-hll-2.14_old/include/include/gtm/utils/path.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/path.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * path.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef _PATH_H +#define _PATH_H + +#include "gtm/gtm_c.h" + +extern void canonicalize_path(char* path); +extern char* make_absolute_path(const char* path); +extern void get_parent_directory(char* path); +extern void join_path_components(char* ret_path, const char* head, const char* tail); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/pqcomm.h postgresql-hll-2.14/include/include/gtm/utils/pqcomm.h --- postgresql-hll-2.14_old/include/include/gtm/utils/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/pqcomm.h 2020-12-12 17:06:43.207347522 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqcomm.h,v 1.109 2008/10/28 12:10:44 mha Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQCOMM_H +#define PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} SockAddr; + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 +/* These are the authentication request codes sent by gtm server. */ +#define GTM_AUTH_REQ_OK 0 /* User is authenticated */ +#define GTM_AUTH_REQ_GSS 1 /* GSSAPI without wrap() */ +#define GTM_AUTH_REQ_GSS_CONT 2 /* Continue GSS exchange */ + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/pqexpbuffer.h postgresql-hll-2.14/include/include/gtm/utils/pqexpbuffer.h --- postgresql-hll-2.14_old/include/include/gtm/utils/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/pqexpbuffer.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,183 @@ +/* ------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/interfaces/libpq/pqexpbuffer.h,v 1.21 2008/11/26 16:23:11 tgl Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H + +/* ------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + * ------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/* ------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + * ------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/* ------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + * ------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/* ------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + * ------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/* ------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createGTMPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initGTMPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + * ------------------------- + */ + +/* ------------------------ + * createGTMPQExpBuffer + * Create an empty 'PQExpBufferData' & return a pointer to it. + */ +extern PQExpBuffer createGTMPQExpBuffer(void); + +/* ------------------------ + * initGTMPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyGTMPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createGTMPQExpBuffer(). + * + * termGTMPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initGTMPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void destroyGTMPQExpBuffer(PQExpBuffer str); +extern void termGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * resetGTMPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetGTMPQExpBuffer(PQExpBuffer str); + +/* ------------------------ + * enlargeGTMPQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargeGTMPQExpBuffer(PQExpBuffer str, size_t needed); + +/* ------------------------ + * printfGTMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetGTMPQExpBuffer() followed by appendGTMPQExpBuffer(). + */ +extern void printfGTMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendGTMPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendGTMPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendGTMPQExpBufferStr + * Append the given string to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendGTMPQExpBufferStr(PQExpBuffer str, const char* data); + +/* ------------------------ + * appendGTMPQExpBufferChar + * Append a single byte to str. + * Like appendGTMPQExpBuffer(str, "%c", ch) but much faster. + */ +extern void appendGTMPQExpBufferChar(PQExpBuffer str, char ch); + +/* ------------------------ + * appendBinaryGTMPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryGTMPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/pqformat.h postgresql-hll-2.14/include/include/gtm/utils/pqformat.h --- postgresql-hll-2.14_old/include/include/gtm/utils/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/pqformat.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqformat.h,v 1.27 2009/01/01 17:23:59 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "gtm/utils/stringinfo.h" + +extern void pq_beginmessage(StringInfo buf, char msgtype); +extern void pq_sendbyte(StringInfo buf, int byt); +extern void pq_sendbytes(StringInfo buf, const char* data, int datalen); +extern void pq_sendcountedtext(StringInfo buf, const char* str, int slen, bool countincludesself); +extern void pq_sendtext(StringInfo buf, const char* str, int slen); +extern void pq_sendstring(StringInfo buf, const char* str); +extern void pq_send_ascii_string(StringInfo buf, const char* str); +extern void pq_sendint(StringInfo buf, int i, int b); +extern void pq_sendint64(StringInfo buf, int64 i); +extern void pq_sendfloat4(StringInfo buf, float4 f); +extern void pq_sendfloat8(StringInfo buf, float8 f); +extern void pq_endmessage(Port* myport, StringInfo buf); + +extern void pq_puttextmessage(Port* myport, char msgtype, const char* str); +extern void pq_putemptymessage(Port* myport, char msgtype); + +extern int pq_getmsgbyte(StringInfo msg); +extern unsigned int pq_getmsgint(StringInfo msg, int b); +extern int64 pq_getmsgint64(StringInfo msg); +extern float4 pq_getmsgfloat4(StringInfo msg); +extern float8 pq_getmsgfloat8(StringInfo msg); +extern const char* pq_getmsgbytes(StringInfo msg, int datalen); +extern void pq_copymsgbytes(StringInfo msg, char* buf, int datalen); +extern char* pq_getmsgtext(StringInfo msg, int rawbytes, int* nbytes); +extern const char* pq_getmsgstring(StringInfo msg); +extern void pq_getmsgend(StringInfo msg); +extern int pq_getmsgunreadlen(StringInfo msg); + +#endif /* PQFORMAT_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/pqsignal.h postgresql-hll-2.14/include/include/gtm/utils/pqsignal.h --- postgresql-hll-2.14_old/include/include/gtm/utils/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/pqsignal.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/libpq/pqsignal.h,v 1.32 2008/01/01 19:45:58 momjian Exp $ + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * ------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +#ifdef HAVE_SIGPROCMASK +extern THR_LOCAL sigset_t UnBlockSig, BlockSig, AuthBlockSig; + +#define PG_SETMASK(mask) pthread_sigmask(SIG_SETMASK, mask, NULL) +#else +extern THR_LOCAL int UnBlockSig, BlockSig, AuthBlockSig; + +#ifndef WIN32 +#define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) +#else +#define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) +int pqsigsetmask(int mask); +#endif +#endif + +typedef void (*pqsigfunc)(int); + +extern void pqinitmask(void); + +extern pqsigfunc pqsignal(int signo, pqsigfunc func); + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/proxy_utils.h postgresql-hll-2.14/include/include/gtm/utils/proxy_utils.h --- postgresql-hll-2.14_old/include/include/gtm/utils/proxy_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/proxy_utils.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * proxy_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/proxy_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PROXY_UTILS_H +#define PROXY_UTILS_H + +#include "gtm/utils/libpq-int.h" + +bool gtm_standby_check_communication_error(int*, GTM_Conn*); + +#endif /* PROXY_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/register.h postgresql-hll-2.14/include/include/gtm/utils/register.h --- postgresql-hll-2.14_old/include/include/gtm/utils/register.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/register.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * register.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL$ + * + * ------------------------------------------------------------------------- + */ +#ifndef GTM_REGISTER_H +#define GTM_REGISTER_H + +#include "gtm/utils/libpq-be.h" +#include "gtm/gtm_c.h" +#include "gtm/gtm_lock.h" +#include "gtm/gtm_list.h" +#include "gtm/utils/stringinfo.h" + +/* + * This structure represents the data that is saved each time a Postgres-XC node + * registered on GTM. + * It contains: + * - Type of the Node: Proxy, Coordinator, Datanode + * - Node number + * - Proxy number: This ID number is set at 0 if node does not go through a Proxy + * or if Node Type is Proxy + * - PostgreSQL port the node uses to communicate + * - IP visible to GTM + * - Data folder of the node + */ + +typedef enum GTM_PGXCNodeStatus { NODE_CONNECTED, NODE_DISCONNECTED } GTM_PGXCNodeStatus; + +typedef struct GTM_PGXCNodeInfo { + GTM_PGXCNodeType type; /* Type of node */ + char* nodename; /* Node Name */ + char* proxyname; /* Proxy name the node goes through */ + GTM_PGXCNodePort port; /* Port number of the node */ + char* ipaddress; /* IP address of the nodes */ + char* datafolder; /* Data folder of the node */ + GTM_PGXCNodeStatus status; /* Node status */ + GTM_RWLock node_lock; /* Lock on this structure */ + int socket; /* socket number used for registration */ + uint32 timeline; /* Timeline for node (restart times) */ +} GTM_PGXCNodeInfo; + +/* Maximum number of nodes that can be registered */ +#define MAX_NODES 1024 + +size_t pgxcnode_find_by_type(GTM_PGXCNodeType type, GTM_PGXCNodeInfo** data, size_t maxlen); + +int Recovery_PGXCNodeRegister(GTM_PGXCNodeType type, char* nodename, GTM_PGXCNodePort port, char* proxyname, + GTM_PGXCNodeStatus status, char* ipaddress, char* datafolder, bool in_recovery, int socket, uint32 timeline); +int Recovery_PGXCNodeUnregister(GTM_PGXCNodeType type, const char* node_name, bool in_recovery, int socket); +int Recovery_PGXCNodeBackendDisconnect(GTM_PGXCNodeType type, const char* nodename, int socket); + +void Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo* nodeinfo, bool is_register); +void Recovery_SaveRegisterInfo(void); +void Recovery_PGXCNodeDisconnect(Port* myport); +void Recovery_SaveRegisterFileName(const char* dir); + +void ProcessPGXCNodeRegister(Port* myport, StringInfo message, bool is_backup); +void ProcessPGXCNodeUnregister(Port* myport, StringInfo message, bool is_backup); +void ProcessPGXCNodeBackendDisconnect(Port* myport, StringInfo message); +void ProcessPGXCNodeList(Port* myport, StringInfo message); + +void ProcessGTMBeginBackup(Port* myport, StringInfo message); +void ProcessGTMEndBackup(Port* myport, StringInfo message); + +void RemoveGTMNodes(void); +char* Recovery_GetRegisterFileName(void); +void Recovery_RegisterFileLock(void); + +#endif /* GTM_NODE_H */ diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/standby_utils.h postgresql-hll-2.14/include/include/gtm/utils/standby_utils.h --- postgresql-hll-2.14_old/include/include/gtm/utils/standby_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/standby_utils.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * standby_utils.h + * + * + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/gtm/standby_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef STANDBY_UTILS_H +#define STANDBY_UTILS_H + +#include "gtm/gtm_c.h" + +bool Recovery_IsPrimary(void); +bool Recovery_IsStandby(void); +bool Recovery_IsPending(void); +bool Recovery_InProgress(void); +GTMServerMode Recovery_Mode(void); + +void Recovery_StandbySetStandby(GTMServerMode mode); +void Recovery_InitStandbyLock(void); +void Recovery_SetPosition(int HA, int local); +void Recovery_GetPosition(int* HA, int* local); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/gtm/utils/stringinfo.h postgresql-hll-2.14/include/include/gtm/utils/stringinfo.h --- postgresql-hll-2.14_old/include/include/gtm/utils/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/gtm/utils/stringinfo.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,157 @@ +/* ------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.35 2008/01/01 19:45:57 momjian Exp $ + * + * ------------------------------------------------------------------------- + */ +#ifndef STRINGINFO_H +#define STRINGINFO_H + +/* ------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + * ------------------------- + */ +typedef struct StringInfoData { + char* data; + int len; + int maxlen; + int cursor; +} StringInfoData; + +typedef StringInfoData* StringInfo; + +/* ------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + * ------------------------- + */ + +/* ------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern StringInfo makeStringInfo(void); + +/* ------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initStringInfo(StringInfo str); + +/* ------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void resetStringInfo(StringInfo str); + +/* ------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendStringInfo(StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(printf, 2, 3))); + +/* ------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool appendStringInfoVA(StringInfo str, const char* fmt, va_list args) __attribute__((format(printf, 2, 0))); + +/* ------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void appendStringInfoString(StringInfo str, const char* s); + +/* ------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void appendStringInfoChar(StringInfo str, char ch); + +/* ------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/* ------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void appendBinaryStringInfo(StringInfo str, const char* data, int datalen); + +/* ------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern void enlargeStringInfo(StringInfo str, int needed); + +/* ----------------------- + * dupStringInfo + * Get new StringInfo and copy the original to it. + */ +extern StringInfo dupStringInfo(StringInfo orig); + +/* ------------------------ + * copyStringInfo + * Copy StringInfo. Deep copy: Data will be copied too. + * cursor of "to" will be initialized to zero. + */ +extern void copyStringInfo(StringInfo to, StringInfo from); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_backend.h postgresql-hll-2.14/include/include/hotpatch/hotpatch_backend.h --- postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_backend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/hotpatch/hotpatch_backend.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_backend.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_backend.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_BACKEND_H +#define HOTPATCH_BACKEND_H + +typedef struct knl_hotpatch_context { + bool under_patching; +} knl_hotpatch_context_t; + +void check_and_process_hotpatch(void); +int hotpatch_remove_signal_file(const char* data_dir); +#endif diff -uprN postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_client.h postgresql-hll-2.14/include/include/hotpatch/hotpatch_client.h --- postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/hotpatch/hotpatch_client.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_client.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_CLIENT_H +#define HOTPATCH_CLIENT_H + +const int g_millisecond = 1000; +const int g_hotpatch_wait_counter = 2000; + +typedef void (*LogFunc)(const char*, ...) __attribute__((format(printf, 1, 2))); + +void hotpatch_patch_state_to_string(unsigned int state, char* state_string, int length_state_string); +extern int hotpatch_check(const char* path, const char* command, bool* is_list); +extern void hotpatch_process_list(const char* return_string, int string_length, const char* data_dir, size_t dir_length, + void (*canonicalize_path)(char*), LogFunc log_func); +#endif diff -uprN postgresql-hll-2.14_old/include/include/hotpatch/hotpatch.h postgresql-hll-2.14/include/include/hotpatch/hotpatch.h --- postgresql-hll-2.14_old/include/include/hotpatch/hotpatch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/hotpatch/hotpatch.h 2020-12-12 17:06:43.208347535 +0800 @@ -0,0 +1,130 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_H +#define HOTPATCH_H + +#define HP_OK (0) +#define HP_ERR (-1) +const int g_max_length_time = 64; +const int g_max_length_act = 16; +const int g_max_length_path = 512; +const int g_max_length_std_path = 4096; +const int g_first_err = 0x1000; +const int g_lock_file_size = 1024; +const int g_length_statstr = 50; +const int g_max_number_patch = 1000; +const int g_length_okstr = 15; +const int g_length_list = 4; +const int g_max_length_line = 128; +const int g_rev_bytes_info = 3; + +#define MAX_LENGTH_RETURN_STRING (1024) + +typedef enum HP_STATE { + HP_STATE_UNKNOW, + HP_STATE_UNLOAD, + HP_STATE_DEACTIVE, + HP_STATE_ACTIVED, +} HP_STATE_T; + +typedef enum HP_ERROR_CODE { + HP_ERROR_NAME_NUMBER = g_first_err, + HP_ERROR_INSUFFICIENT_MEM, + HP_ERROR_SUFFIX_INCORRECT, + HP_ERROR_UNKNOWN_NAME, + HP_ERROR_EMPTY_NAME, + HP_ERROR_EMPTY_COMMAND, + HP_ERROR_LOADED_BEFORE, + HP_ERROR_CANNOT_UNLOAD, + HP_ERROR_CANNOT_ACTIVE, + HP_ERROR_CANNOT_DEACTIVE, + HP_ERROR_RANGE, + HP_ERROR_NO_PATCH_LOADED, + HP_ERROR_EMPTY_PARAMETER, + HP_ERROR_INITED_BEFORE, + HP_ERROR_LIB_INIT_ERROR, + HP_ERROR_NOT_INIT, + HP_ERROR_UNKNOWN_ACTION, + HP_ERROR_FETCH_ERROR, + HP_ERROR_VERSION, + HP_ERROR_GTM_UNCONNECTED, + HP_ERROR_GTM_START_ERROR, + HP_ERROR_GTM_SEND_ERROR, + HP_ERROR_GTM_SEND_END_ERROR, + HP_ERROR_GTM_FLUSH_ERROR, + HP_ERROR_GTM_RECEIVE_ERROR, + HP_ERROR_OPERATION_LOG_ERR, + HP_ERROR_COMMUNICATION_ERR, + HP_ERROR_UNDER_PATCHING, + HP_ERROR_SYSTEM_ERROR, + HP_ERROR_FILE_SEEK_ERROR, + HP_ERROR_FILE_WRITE_ERROR, + HP_ERROR_FILE_READ_ERROR, + HP_ERROR_FILE_OPEN_ERROR, + HP_ERROR_FILE_SYNC_ERROR, + HP_ERROR_FILE_LOCK_ERROR, + HP_ERROR_FILE_RENAME_ERROR, + HP_ERROR_FILE_PATH_ERROR, + HP_ERROR_PATCH_NUMBER_ERROR, + HP_ERROR_PATCH_INFO_ERROR, + HP_ERROR_CM_DATADIR_NULL, + HP_ERROR_REG_LOG_CALLBACK_ERROR, + HP_ERROR_REG_PAGESIZE_CALLBACK_ERROR, + HP_ERROR_COMMON_ERROR_MAX, +} HP_ERROR_CODE_T; + +typedef enum HP_INFO_STATE { + HP_INFO_NOT_EXIST, + HP_INFO_EXIST, + HP_INFO_NEED_RFRESH, +} HP_INFO_STATE_T; + +typedef struct PATCH_LOG { + char time_stamp[g_max_length_time]; + char operation[g_max_length_act]; + char patch_name[g_max_length_path]; + char rev[16]; +} PATCH_LOG_T; + +typedef struct PATCH_INFO_HEADER { + int max_patch_number; // record how many patchs has been loaded + int rev; +} PATCH_INFO_HEADER_T; + +typedef struct PATCH_INFO { + int patch_number; + char patch_state; + char rev[g_rev_bytes_info]; + char patch_name[g_max_length_path]; +} PATCH_INFO_T; + +typedef void (*HOTPATCH_LOG_FUNC)(unsigned int level, const char* fmt); + +extern int hotpatch_init(const char* default_dir, HOTPATCH_LOG_FUNC log_func); +extern int exec_hotpatch_command(const char* filename, const char* action, char* output_string, size_t string_length); +void patch_err_info_handler(int error_code, char* out_string, size_t string_length); +char* strip_path_from_pathname(const char* name_withpath); +#endif diff -uprN postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_inner.h postgresql-hll-2.14/include/include/hotpatch/hotpatch_inner.h --- postgresql-hll-2.14_old/include/include/hotpatch/hotpatch_inner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/hotpatch/hotpatch_inner.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hotpatch_inner.h + * + * + * + * IDENTIFICATION + * src/include/hotpatch/hotpatch_inner.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HOTPATCH_INNER_H +#define HOTPATCH_INNER_H + +#define hp_check_intval(errno, express, file, line) \ + do { \ + if (errno < 0) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.errno is 0x%x\n", \ + file, \ + line, \ + errno); \ + express; \ + } \ + } while (0) + +#define securec_check_hp(errno, express) hp_check_intval(errno, express, __FILE__, __LINE__) + +typedef enum TIME_USAGE { + TIME_STRING_FOR_FILE_NAME, + TIME_STRING_FOR_DISPLAY, +} TIME_USAGE_T; +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/ash.h postgresql-hll-2.14/include/include/instruments/ash.h --- postgresql-hll-2.14_old/include/include/instruments/ash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/ash.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,60 @@ +#ifndef ASH_H +#define ASH_H +#include "gs_thread.h" +#include "pgstat.h" + +#define ENABLE_ASP u_sess->attr.attr_common.enable_asp +typedef struct SessionHistEntry { + uint64 changCount; + uint64 sample_id; + /* time stamp of every case */ + TimestampTz sample_time; + /* Whether the sample has been flushed to wdr */ + bool need_flush_sample; + + uint64 session_id; + TimestampTz start_time; + bool is_flushed_sample; + uint64 psessionid; + /* Database OID, owning user's OID, connection client address */ + Oid databaseid; + Oid userid; + SockAddr clientaddr; + char* clienthostname; /* MUST be null-terminated */ + + /* application name; MUST be null-terminated */ + char* st_appname; + + uint64 queryid; /* debug query id of current query */ + UniqueSQLKey unique_sql_key; /* get unique sql key */ + ThreadId procpid; /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */ + pid_t tid; + int thread_level; /* thread level, mark with plan node id of Stream node */ + uint32 smpid; /* smp worker id, used for parallel execution */ + WaitState waitstatus; /* backend waiting states */ + uint32 waitevent; /* backend's wait event */ + uint64 xid; /* for transaction id, fit for 64-bit */ + int waitnode_count; /* count of waiting nodes */ + int nodeid; /* maybe for nodeoid/nodeidx */ + int plannodeid; /* indentify which consumer is receiving data for SCTP */ + char* relname; /* relation name, for analyze, vacuum, .etc.*/ + Oid libpq_wait_nodeid; /* for libpq, point to libpq_wait_node*/ + int libpq_wait_nodecount; /* for libpq, point to libpq_wait_nodecount*/ + WaitStatePhase waitstatus_phase; /* detailed phase for wait status, now only for 'wait node' status */ + int numnodes; /* nodes number when reporting waitstatus in case it changed */ + LOCALLOCKTAG locallocktag; /* locked object */ + uint64 st_block_sessionid; /* block session */ +} SessionHistEntry; + +typedef struct ActiveSessHistArrary { + uint32 curr_index; /* the current index of active session history arrary */ + uint32 max_size; /* the max size of the active_sess_hist_arrary */ + SessionHistEntry *active_sess_hist_info; +} ActiveSessHistArrary; + +void InitAsp(); +extern ThreadId ash_start(void); +extern void ActiveSessionCollectMain(); +extern bool IsJobAspProcess(void); +#endif + diff -uprN postgresql-hll-2.14_old/include/include/instruments/capture_view.h postgresql-hll-2.14/include/include/instruments/capture_view.h --- postgresql-hll-2.14_old/include/include/instruments/capture_view.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/capture_view.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * capture_view.cpp + * support utility to capture view to json file + * + * IDENTIFICATION + * src/gausskernel/cbb/instruments/capture_view/capture_view.cpp + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_CAPTURE_VIEW_H +#define INSTR_CAPTURE_VIEW_H + +void init_capture_view(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/dblink_query.h postgresql-hll-2.14/include/include/instruments/dblink_query.h --- postgresql-hll-2.14_old/include/include/instruments/dblink_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/dblink_query.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dblink_query.h + * Functions returning results from a remote database + * + * + * IDENTIFICATION + * src/include/instruments/dblink_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DBLINK_QUERY_H +#define DBLINK_QUERY_H + +#include "fmgr.h" + +extern Datum wdr_xdb_query(PG_FUNCTION_ARGS); + +extern void dblinkCloseConn(void); + +extern void dblinkRequestCancel(void); + +#endif /* DBLINK_QUERY_H */ diff -uprN postgresql-hll-2.14_old/include/include/instruments/generate_report.h postgresql-hll-2.14/include/include/instruments/generate_report.h --- postgresql-hll-2.14_old/include/include/instruments/generate_report.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/generate_report.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * generate_report.h + * definitions for WDR report. + * + * Before generating a report, you need to generate at least two WDR snapshot. + * A WDR report is used to show the performance of the database between snapshots. + * + * + * IDENTIFICATION + * src/include/instruments/generate_report.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef GENER_REPORT +#define GENER_REPORT + +#include + +extern Datum generate_wdr_report(PG_FUNCTION_ARGS); +extern char* Datum_to_string(Datum value, Oid type, bool isnull); +extern void DeepListFree(List* deepList, bool deep); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/gs_stat.h postgresql-hll-2.14/include/include/instruments/gs_stat.h --- postgresql-hll-2.14_old/include/include/instruments/gs_stat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/gs_stat.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------- + * + * gs_stat.h + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/instruments/gs_stat.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GS_STAT_H +#define GS_STAT_H +#include "c.h" +#include "funcapi.h" +#include "gs_thread.h" + +static inline void gsGetStatCurrentStatus(PG_FUNCTION_ARGS, FuncCallContext* funcctx, bool has_first_arg = true) +{ + funcctx->user_fctx = gs_stat_read_current_status(&funcctx->max_calls); + if (has_first_arg && !PG_ARGISNULL(0)) { + ThreadId pid = PG_GETARG_INT64(0); + PgBackendStatusNode* beNode = (PgBackendStatusNode*)funcctx->user_fctx; + bool isFind = false; + while (beNode != NULL) { + PgBackendStatus* be = beNode->data; + if (be != NULL && be->st_procpid == pid) { + isFind = true; + funcctx->user_fctx = beNode; + break; + } + beNode = beNode->next; + } + if (isFind) + funcctx->max_calls = 1; + else + funcctx->max_calls = 0; + } +} +extern PgBackendStatusNode* gs_stat_get_timeout_beentry(int timeout_threshold); +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_event.h postgresql-hll-2.14/include/include/instruments/instr_event.h --- postgresql-hll-2.14_old/include/include/instruments/instr_event.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_event.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_event.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/instr_event.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_EVENT_H +#define INSTR_EVENT_H +#include "storage/lwlock.h" +void LWLockReportWaitFailed(LWLock *lock); +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_handle_mgr.h postgresql-hll-2.14/include/include/instruments/instr_handle_mgr.h --- postgresql-hll-2.14_old/include/include/instruments/instr_handle_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_handle_mgr.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_handle_mgr.h + * definitions for handle manager used in full/slow sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_handle_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_HANDLE_MGR_H +#define INSTR_HANDLE_MGR_H +#include "pgstat.h" + +#define CURRENT_STMT_METRIC_HANDLE ((StatementStatContext*)(u_sess->statement_cxt.curStatementMetrics)) +#define CHECK_STMT_HANDLE() \ +{ \ + if (CURRENT_STMT_METRIC_HANDLE == NULL || u_sess->statement_cxt.stmt_stat_cxt == NULL) { \ + return; \ + } \ +} + +void statement_init_metric_context(); +void statement_commit_metirc_context(); +void release_statement_context(PgBackendStatus* beentry, const char* func, int line); +void concat_suspend_to_free_list(List* free_list, List* suspend_list); +void* bind_statement_context(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_slow_query.h postgresql-hll-2.14/include/include/instruments/instr_slow_query.h --- postgresql-hll-2.14_old/include/include/instruments/instr_slow_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_slow_query.h 2020-12-12 17:06:43.209347548 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * instr_slow_query.h + * + * IDENTIFICATION + * src/include/instruments/instr_slow_query.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef INSTR_SLOW_QUERY_H +#define INSTR_SLOW_QUERY_H +#include "nodes/parsenodes.h" +#include "pgstat.h" +#include "c.h" + +void ReportQueryStatus(void); +void WLMSetSessionSlowInfo(WLMStmtDetail* pDetail); +void exec_auto_explain(QueryDesc *queryDesc); +void exec_explain_plan(QueryDesc *queryDesc); +void print_duration(const QueryDesc *queryDesc); +void explain_querydesc(ExplainState *es, QueryDesc *queryDesc); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_slow_query_log.h postgresql-hll-2.14/include/include/instruments/instr_slow_query_log.h --- postgresql-hll-2.14_old/include/include/instruments/instr_slow_query_log.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_slow_query_log.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * instr_slow_query_log.h + * + * IDENTIFICATION + * src/include/instruments/instr_slow_query_log.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_SLOW_QUERY_LOG_H +#define INSTR_SLOW_QUERY_LOG_H + +void write_local_slow_log(char *data, int len, bool end); + +#endif + + diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_statement.h postgresql-hll-2.14/include/include/instruments/instr_statement.h --- postgresql-hll-2.14_old/include/include/instruments/instr_statement.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_statement.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,207 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_statement.h + * definitions for full/slow sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_statement.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_STATEMENT_H +#define INSTR_STATEMENT_H + +#include "c.h" +#include "pgstat.h" +#include "instruments/unique_sql_basic.h" + +#define ENABLE_STATEMENT_TRACK u_sess->attr.attr_common.enable_stmt_track +typedef enum { + STMT_TRACK_OFF = 0, + STMT_TRACK_L0, + STMT_TRACK_L1, + STMT_TRACK_L2, + LEVEL_INVALID +} StatLevel; + +#define MAX_STATEMENT_STAT_LEVEL (STMT_TRACK_L2) + +struct LockSummaryStat { + /* lock */ + int64 lock_start_time; + int64 lock_cnt; + int64 lock_time; + int64 lock_wait_start_time; + int64 lock_wait_cnt; + int64 lock_wait_time; + + /* lwlock */ + int64 lwlock_start_time; + int64 lwlock_cnt; + int64 lwlock_time; + int64 lwlock_wait_start_time; + int64 lwlock_wait_cnt; + int64 lwlock_wait_time; + + /* the maximum lock count at a time. */ + int64 lock_max_cnt; + int64 lock_hold_cnt; +}; + +#pragma pack (1) +typedef struct { + char eventType; + int64 timestamp; + LOCKTAG tag; + LOCKMODE mode; +} LockEventStartInfo; + +typedef struct { + char eventType; + int64 timestamp; + uint16 id; + LWLockMode mode; +} LWLockEventStartInfo; + +typedef struct { + char eventType; + int64 timestamp; +} LockEventEndInfo; +#pragma pack() + +typedef enum { + LOCK_START = 1, + LOCK_END, + LOCK_WAIT_START, + LOCK_WAIT_END, + LOCK_RELEASE_START, + LOCK_RELEASE_END, + LWLOCK_START, + LWLOCK_END, + LWLOCK_WAIT_START, + LWLOCK_WAIT_END, + LWLOCK_RELEASE_START, + LWLOCK_RELEASE_END, + TYPE_INVALID +} StatementDetailType; + +// type(1 byte), timestamp(8 bytes), locktag(20 bytes), lockmode(4 bytes) +#define LOCK_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_END_DETAIL_BUFSIZE 9 +// type, timestamp, locktag, lockmode +#define LOCK_WAIT_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_WAIT_END_DETAIL_BUFSIZE 9 +// type, timestamp, locktag, lockmode +#define LOCK_RELEASE_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_RELEASE_END_DETAIL_BUFSIZE 9 +// type(1 byte), timestamp(8 bytes), lwlockId(2 bytes), lockmode(4 bytes) +#define LWLOCK_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_END_DETAIL_BUFSIZE 9 +// type, timestamp, lwlockId, lockmode +#define LWLOCK_WAIT_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_WAIT_END_DETAIL_BUFSIZE 9 +// type, timestamp, lwlockId, lockmode +#define LWLOCK_RELEASE_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_RELEASE_END_DETAIL_BUFSIZE 9 +#define INVALID_DETAIL_BUFSIZE 0 + +#define STATEMENT_DETAIL_BUF_MULTI 10 +#define STATEMENT_DETAIL_BUF 256 + +#define STATEMENT_DETAIL_BUFSIZE 4096 +struct StatementDetailItem { + void *next; /* next item */ + char buf[STATEMENT_DETAIL_BUFSIZE]; /* [version, [LOCK_START, timestamp, locktag, lockmode], [...]] */ +}; + +struct StatementDetail { + int n_items; /* how many of detail items */ + uint32 cur_pos; /* the write position of the last item */ + StatementDetailItem *head; /* the first detail item. */ + StatementDetailItem *tail; /* the last detail item. */ +}; + +#define STATEMENT_DETAIL_VERSION 1 +#define STATEMENT_DETAIL_NOT_TRUNCATED 0 +#define STATEMENT_DETAIL_TRUNCATED 1 +#define STATEMENT_DETAIL_FORMAT_STRING "plaintext" +#define STATEMENT_DETAIL_FORMAT_JSON "json" +#define STATEMENT_DETAIL_TYPE_PRETTY "pretty" + +/* entry for full/slow sql stat */ +typedef struct StatementStatContext { + // GUC variant + char* schema_name; /* search path */ + char* application_name; /* workload identifier */ + StatLevel level; /* which level metrics to be collected base on GUC */ + + // variant, collect at commit handler + uint64 unique_query_id; /* from knl_u_unique_sql_context's unique_sql_id */ + uint64 debug_query_id; /* from knl_session_context's debug_query_id */ + uint32 unique_sql_cn_id; /* from knl_session_context's unique_sql_cn_id */ + char* query; /* from PgBackendStatus's st_activity + or knl_u_unique_sql_context's curr_single_unique_sql */ + TimestampTz start_time; /* from PgBackendStatus's st_activity_start_timestamp */ + TimestampTz finish_time; /* commit's GetCurrentTimestamp */ + int slow_query_threshold; /* from knl_session_attr_storage's log_min_duration_statement */ + + int64 timeModel[TOTAL_TIME_INFO_TYPES]; /* from knl_u_stat_context's localTimeInfoArray */ + int64 networkInfo[TOTAL_NET_INFO_TYPES]; /* from knl_u_stat_context's localNetInfo */ + UniqueSQLRowActivity row_activity; /* row activity */ + UniqueSQLCacheIO cache_io; /* cache/IO */ + + // variant, collect them during its progress + ThreadId tid; + TransactionId txn_id; + UniqueSQLParse parse; + char* query_plan; /* query plan */ + uint64 plan_size; + LockSummaryStat lock_summary; + StatementDetail details; +} StatementStatContext; +extern void StatementFlushMain(); +extern bool IsStatementFlushProcess(void); + +extern bool check_statement_stat_level(char** newval, void** extra, GucSource source); +extern void assign_statement_stat_level(const char* newval, void* extra); +extern bool check_statement_retention_time(char** newval, void** extra, GucSource source); +extern void assign_statement_retention_time(const char* newval, void* extra); + +extern void statement_full_info_record( + StatementDetailType type, int lockmode = -1, const LOCKTAG *locktag = NULL, uint16 lwlockId = 0); +extern void instr_stmt_report_basic_info(); +extern void instr_stmt_report_stat_at_handle_commit(); +extern void instr_stmt_report_unique_sql_info(const PgStat_TableCounts *agg_table_stat, + const int64 timeInfo[], const uint64 *netInfo, const UniqueSQLParse *parse); +extern void instr_stmt_report_txid(uint64 txid); +extern void instr_stmt_report_query(uint64 unique_query_id); +extern void instr_stmt_report_query_plan(QueryDesc *queryDesc); +extern void instr_stmt_report_debug_query_id(uint64 debug_query_id); +extern void instr_stmt_report_start_time(); +extern void instr_stmt_report_finish_time(); +extern text *get_statement_detail(StatementDetail *text); +extern char *decode_statement_detail_text(text *details, const char *format, bool pretty); + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_unique_sql.h postgresql-hll-2.14/include/include/instruments/instr_unique_sql.h --- postgresql-hll-2.14_old/include/include/instruments/instr_unique_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_unique_sql.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,211 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_unique_sql.h + * definitions for unique sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_unique_sql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_UNIQUE_SQL_H +#define INSTR_UNIQUE_SQL_H + +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "pgstat.h" +#include "instruments/unique_sql_basic.h" +#include "utils/batchsort.h" + +typedef struct { + int64 total_time; /* total time for the unique sql entry */ + int64 min_time; /* min time for unique sql entry's history events */ + int64 max_time; /* max time for unique sql entry's history events */ +} UniqueSQLElapseTime; + +typedef struct UniqueSQLTime { + int64 TimeInfoArray[TOTAL_TIME_INFO_TYPES]; +} UniqueSQLTime; + +typedef struct UniqueSQLNetInfo { + uint64 netInfoArray[TOTAL_NET_INFO_TYPES]; +} UniqueSQLNetInfo; + +typedef struct UniqueSQLWorkMemInfo { + pg_atomic_uint64 counts; /* # of operation during unique sql */ + int64 used_work_mem; /* space of used work mem by kbs */ + int64 total_time; /* execution time of sort/hash operation */ + pg_atomic_uint64 spill_counts; /* # of spill times during the sort/hash operation */ + pg_atomic_uint64 spill_size; /* spill size for temp table by kbs */ +} UniqueSQLWorkMemInfo; + +typedef struct { + UniqueSQLKey key; /* CN oid + user oid + unique sql id */ + + /* alloc extra UNIQUE_SQL_MAX_LEN space to store unique sql string */ + char* unique_sql; /* unique sql text */ + + pg_atomic_uint64 calls; /* calling times */ + UniqueSQLElapseTime elapse_time; /* elapst time stat in ms */ + TimestampTz updated_time; /* latest update time for the unique sql entry */ + UniqueSQLTime timeInfo; + UniqueSQLNetInfo netInfo; + + UniqueSQLRowActivity row_activity; /* row activity */ + UniqueSQLCacheIO cache_io; /* cache/IO */ + UniqueSQLParse parse; /* hard/soft parse counter */ + bool is_local; /* local sql(run from current node) */ + UniqueSQLWorkMemInfo sort_state; /* work mem info of sort operation */ + UniqueSQLWorkMemInfo hash_state; /* work mem info of hash operation */ +} UniqueSQL; + +/* Unique SQL track type */ +typedef enum { + UNIQUE_SQL_NONE = 0, + UNIQUE_SQL_TRACK_TOP, /* only top SQL will be tracked */ + UNIQUE_SQL_TRACK_ALL /* later maybe support parent and child SQLs */ +} UniqueSQLTrackType; + +typedef struct { + int64* timeInfo; + uint64* netInfo; +} UniqueSQLStat; + +extern int GetUniqueSQLTrackType(); + +#define UniqueSQLStatCountReturnedRows(n) \ + if ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_returned_rows_counter += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %lu returned rows", \ + u_sess->unique_sql_cxt.unique_sql_id, \ + (uint64)n))); \ + } + +#define UniqueSQLStatCountResetReturnedRows() \ + if ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_returned_rows_counter = 0); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: reset returned rows", u_sess->unique_sql_cxt.unique_sql_id))); \ + } + +#define UniqueSQLStatCountSoftParse(n) \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_soft_parse += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %d soft parse", u_sess->unique_sql_cxt.unique_sql_id, n))); \ + } + +#define UniqueSQLStatCountHardParse(n) \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_hard_parse += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %d hard parse", u_sess->unique_sql_cxt.unique_sql_id, n))); \ + } + +#define UniqueSQLStatCountResetParseCounter() \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_soft_parse = 0); \ + (u_sess->unique_sql_cxt.unique_sql_hard_parse = 0); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: reset parse counter", u_sess->unique_sql_cxt.unique_sql_id))); \ + } + +#define UniqueSQLSumTableStatCounter(A, B) \ + if (IS_PGXC_DATANODE && is_unique_sql_enabled()) { \ + A.t_tuples_returned += B.t_tuples_returned; \ + A.t_tuples_fetched += B.t_tuples_fetched; \ + A.t_tuples_inserted += B.t_tuples_inserted; \ + A.t_tuples_updated += B.t_tuples_updated; \ + A.t_tuples_deleted += B.t_tuples_deleted; \ + A.t_blocks_fetched += B.t_blocks_fetched; \ + A.t_blocks_hit += B.t_blocks_hit; \ + } + +#define UniqueSQLDiffTableStatCounter(A, B, C) \ + if (IS_PGXC_DATANODE && is_unique_sql_enabled()) { \ + A.t_tuples_returned = B.t_tuples_returned - C.t_tuples_returned; \ + A.t_tuples_fetched = B.t_tuples_fetched - C.t_tuples_fetched; \ + A.t_tuples_inserted = B.t_tuples_inserted - C.t_tuples_inserted; \ + A.t_tuples_updated = B.t_tuples_updated - C.t_tuples_updated; \ + A.t_tuples_deleted = B.t_tuples_deleted - C.t_tuples_deleted; \ + A.t_blocks_fetched = B.t_blocks_fetched - C.t_blocks_fetched; \ + A.t_blocks_hit = B.t_blocks_hit - C.t_blocks_hit; \ + } + +#define IS_UNIQUE_SQL_TRACK_TOP ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && GetUniqueSQLTrackType() == UNIQUE_SQL_TRACK_TOP) + +#define INIT_UNIQUE_SQL_CXT() \ + bool old_is_top_unique_sql = false; \ + uint64 old_unique_sql_id = 0; + +#define BACKUP_UNIQUE_SQL_CXT() \ + old_is_top_unique_sql = IsTopUniqueSQL(); \ + if (old_is_top_unique_sql) { \ + SetIsTopUniqueSQL(false); \ + old_unique_sql_id = u_sess->unique_sql_cxt.unique_sql_id; \ + } + +#define RESTORE_UNIQUE_SQL_CXT() \ + if (old_is_top_unique_sql) { \ + SetIsTopUniqueSQL(true); \ + u_sess->unique_sql_cxt.unique_sql_id = old_unique_sql_id; \ + } + +void InitUniqueSQL(); +void UpdateUniqueSQLStat(Query* query, const char* sql, int64 elapse_start_time, + PgStat_TableCounts* agg_table_count = NULL, UniqueSQLStat* sql_stat = NULL); +void ResetUniqueSQLString(); + +void instr_unique_sql_register_hook(); +void SetUniqueSQLIdFromPortal(Portal portal, CachedPlanSource* unnamedPsrc); +void SetUniqueSQLIdFromCachedPlanSource(CachedPlanSource* cplan); + +void ReplyUniqueSQLsStat(StringInfo msg, uint32 count); + +void PrintPgStatTableCounter(char type, PgStat_TableCounts* stat); +void UpdateUniqueSQLStatOnRemote(); + +bool is_unique_sql_enabled(); + +bool IsNeedUpdateUniqueSQLStat(Portal portal); + +void SetIsTopUniqueSQL(bool value); +bool IsTopUniqueSQL(); + +bool is_local_unique_sql(); +bool need_normalize_unique_string(); +bool need_update_unique_sql_row_stat(); +void ResetCurrentUniqueSQL(bool need_reset_cn_id = false); +bool isUniqueSQLContextInvalid(); +void UpdateSingleNodeByPassUniqueSQLStat(bool isTopLevel); +void UpdateUniqueSQLHashStats(HashJoinTable hashtable, TimestampTz* start_time); +void UpdateUniqueSQLVecSortStats(Batchsortstate* state, uint64 spill_count, TimestampTz* start_time); +void FindUniqueSQL(UniqueSQLKey key, char* unique_sql); +char* FindCurrentUniqueSQL(); + +bool is_instr_top_portal(); +void increase_instr_portal_nesting_level(); +void decrease_instr_portal_nesting_level(); +void instr_unique_sql_handle_multi_sql(bool is_first_parsetree); +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_user.h postgresql-hll-2.14/include/include/instruments/instr_user.h --- postgresql-hll-2.14_old/include/include/instruments/instr_user.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_user.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_user.h + * definitions for user stat info + * + * + * IDENTIFICATION + * src/include/instruments/instr_user.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_USER_H +#define INSTR_USER_H + +void InstrUpdateUserLogCounter(bool is_login); +void InitInstrUser(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_waitevent.h postgresql-hll-2.14/include/include/instruments/instr_waitevent.h --- postgresql-hll-2.14_old/include/include/instruments/instr_waitevent.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_waitevent.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_waitevent.h + * definitions for wait event stat + * + * + * IDENTIFICATION + * src/include/instruments/instr_waitevent.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_WAITEVENT_H +#define INSTR_WAITEVENT_H + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/instr_workload.h postgresql-hll-2.14/include/include/instruments/instr_workload.h --- postgresql-hll-2.14_old/include/include/instruments/instr_workload.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/instr_workload.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_workload.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/instr_workload.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_WORKLOAD_H +#define INSTR_WORKLOAD_H +#include "c.h" +#include "utils/timestamp.h" +#include "utils/syscache.h" + +typedef struct StatData { + TimestampTz max; + TimestampTz min; + TimestampTz average; + TimestampTz total; +} StatData; + +typedef struct WLMTransactonInfo { + uint64 commit_counter; + uint64 rollback_counter; + StatData responstime; +} WLMTransactionInfo; + +typedef struct WLMWorkLoadKey { + Oid user_id; +} WLMWorkLoadKey; + +typedef struct WorkloadXactInfo { + // WLMWorkLoadKey wlkey; + Oid user_id; + WLMTransactionInfo transaction_info; + WLMTransactionInfo bg_xact_info; +} WorkloadXactInfo; + +extern void InitInstrWorkloadTransaction(void); +extern void InitInstrOneUserTransaction(Oid userId); +extern void instr_report_workload_xact_info(bool isCommit); +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/list.h postgresql-hll-2.14/include/include/instruments/list.h --- postgresql-hll-2.14_old/include/include/instruments/list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/list.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * list.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/list.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIST_H +#define LIST_H +#include "c.h" +#include "lib/stringinfo.h" +/* top dn info*/ +typedef struct WLMTopDnInfo { + char nodeName[NAMEDATALEN]; + int64 data; +} WLMTopDnInfo; + +/* list of top dn*/ +typedef struct WLMTopDnList { + WLMTopDnInfo topDn; + WLMTopDnList* nextTopDn; +} WLMTopDnList; + +void InsertElemSortTopN(WLMTopDnList** head, WLMTopDnList** elem, int topN); +void DeleteList(WLMTopDnList** head); +void GetTopNInfo(WLMTopDnList* head, char name[][NAMEDATALEN], int* values, int topN); +void GetTopNInfoJsonFormat(StringInfoData topNstr, char nodeName[][NAMEDATALEN], int* value, int topN); +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/percentile.h postgresql-hll-2.14/include/include/instruments/percentile.h --- postgresql-hll-2.14_old/include/include/instruments/percentile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/percentile.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * percentile.h + * Definitions for the PostgreSQL statistics collector daemon. + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/instruments/percentile.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PERCENTILE_H +#define PERCENTILE_H +#include "gs_thread.h" + +extern void PercentileMain(); +extern void JobPercentileIAm(void); +extern bool IsJobPercentileProcess(void); +extern void InitPercentile(void); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/instruments/snapshot.h postgresql-hll-2.14/include/include/instruments/snapshot.h --- postgresql-hll-2.14_old/include/include/instruments/snapshot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/snapshot.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * snapshot.h + * definitions for WDR snapshot. + * + * + * By default, the snapshot thread collects database statistics + * from the views in dbe_perf schema in one hour, + * and insert these data into the corresponding tables in the snapshot schema. + * The WDR report generates a performance diagnosis report + * based on the data collected by the snapshot thread. + * + * IDENTIFICATION + * src/include/instruments/snapshot.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_SNAPSHOT_H +#define INSTR_SNAPSHOT_H +#include "gs_thread.h" + +extern ThreadId snapshot_start(void); +extern void SnapshotMain(); +extern Datum create_wdr_snapshot(PG_FUNCTION_ARGS); + +extern void JobSnapshotIAm(void); +extern bool IsJobSnapshotProcess(void); +extern THR_LOCAL bool am_job_snapshot; +extern THR_LOCAL bool operate_snapshot_tables; + +extern Datum GetDatumValue(const char* query, uint32 row, uint32 col, bool* isnull = NULL); + +extern void instrSnapshotClean(void); + +extern void instrSnapshotCancel(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/unique_query.h postgresql-hll-2.14/include/include/instruments/unique_query.h --- postgresql-hll-2.14_old/include/include/instruments/unique_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/unique_query.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * unique_query.h + * definitions for unique query + * + * + * IDENTIFICATION + * src/include/instruments/unique_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _QUERYID_ +#define _QUERYID_ + +#include "nodes/parsenodes.h" +#include "c.h" + +extern uint32 generate_unique_queryid(Query* query, const char* query_string); +extern bool normalized_unique_querystring(Query* query, const char* query_string, char* unique_string, int len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/instruments/unique_sql_basic.h postgresql-hll-2.14/include/include/instruments/unique_sql_basic.h --- postgresql-hll-2.14_old/include/include/instruments/unique_sql_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/instruments/unique_sql_basic.h 2020-12-12 17:06:43.210347561 +0800 @@ -0,0 +1,33 @@ +#ifndef UNIQUE_SQL_BASIC_H +#define UNIQUE_SQL_BASIC_H + +typedef struct { + uint32 cn_id; /* SQL is run on which CN node, + * same with node_id in PGXC_NODE */ + Oid user_id; /* user id */ + uint64 unique_sql_id; /* unique sql id */ +} UniqueSQLKey; + +typedef struct { + pg_atomic_uint64 soft_parse; /* reuse plan counter */ + pg_atomic_uint64 hard_parse; /* new generated plan counter */ +} UniqueSQLParse; + +typedef struct { + pg_atomic_uint64 returned_rows; /* select SQL returned rows */ + + pg_atomic_uint64 tuples_fetched; /* randowm IO */ + pg_atomic_uint64 tuples_returned; /* sequence IO */ + + pg_atomic_uint64 tuples_inserted; /* inserted tuples counter */ + pg_atomic_uint64 tuples_updated; /* updated tuples counter */ + pg_atomic_uint64 tuples_deleted; /* deleted tuples counter */ +} UniqueSQLRowActivity; + +typedef struct { + pg_atomic_uint64 blocks_fetched; /* the blocks fetched times */ + pg_atomic_uint64 blocks_hit; /* the blocks hit times in buffer */ +} UniqueSQLCacheIO; + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/iprange/iprange.h postgresql-hll-2.14/include/include/iprange/iprange.h --- postgresql-hll-2.14_old/include/include/iprange/iprange.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/iprange/iprange.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,194 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * iprange.h + * define operation functions for ip type data + * + * IDENTIFICATION + * src/include/iprange/iprange.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef IPRANGE_AUDIT_H_ +#define IPRANGE_AUDIT_H_ + +#include +#include +#include +#include + +typedef unsigned char ipv6arr[16]; + +typedef struct IPV6_64_s +{ + uint64_t lower; + uint64_t upper; +} IPV6_64; + +typedef struct IPV6_32_s +{ + uint32_t a; + uint32_t b; + uint32_t c; + uint32_t d; +} IPV6_32; + +typedef union IPV6_s +{ + IPV6_64 ip_64; + IPV6_32 ip_32; +} IPV6; + +inline bool operator< (const IPV6 lhs, const IPV6 rhs){ return lhs.ip_64.upper < rhs.ip_64.upper || lhs.ip_64.lower < rhs.ip_64.lower; } +inline bool operator> (const IPV6 lhs, const IPV6 rhs){ return rhs < lhs; } +inline bool operator<=(const IPV6 lhs, const IPV6 rhs){ return !(lhs > rhs); } +inline bool operator>=(const IPV6 lhs, const IPV6 rhs){ return !(lhs < rhs); } + +inline const IPV6 operator~(const IPV6 ip) +{ + IPV6 new_ip; + new_ip.ip_64.lower = ~ip.ip_64.lower; + new_ip.ip_64.upper = ~ip.ip_64.upper; + return new_ip; +} + +inline bool operator==(const IPV6 lhs, const IPV6 rhs) +{ + return lhs.ip_64.lower == rhs.ip_64.lower && lhs.ip_64.upper == rhs.ip_64.upper; +} + +inline const IPV6 operator+(const IPV6 lhs, const IPV6 rhs) +{ + uint64_t tmp; + IPV6 new_ip {0,0}; + + if (lhs.ip_32.b == 0x0000FFFF) { + new_ip.ip_32.a = lhs.ip_32.a + rhs.ip_32.a; + new_ip.ip_32.b = 0x0000FFFF; + return new_ip; + } + + new_ip.ip_32.a = tmp = ((int64_t)lhs.ip_32.a) + rhs.ip_32.a; + new_ip.ip_32.b = tmp = ((int64_t)lhs.ip_32.b) + rhs.ip_32.b + (tmp >> 32); + new_ip.ip_32.c = tmp = ((int64_t)lhs.ip_32.c) + rhs.ip_32.c + (tmp >> 32); + new_ip.ip_32.d = ((int64_t)lhs.ip_32.d) + rhs.ip_32.d + (tmp >> 32); + return new_ip; +} + +inline const IPV6 operator+(const IPV6 lhs, const int i) +{ + IPV6 new_ip {0,0}; + new_ip.ip_64.lower = i; + return lhs + new_ip; +} + +inline const IPV6 operator-(const IPV6 lhs, const IPV6 rhs) +{ + if (lhs.ip_32.b == 0x0000FFFF) { + IPV6 new_ip {0,0}; + new_ip.ip_32.a = lhs.ip_32.a - rhs.ip_32.a; + new_ip.ip_32.b = 0x0000FFFF; + return new_ip; + } + + uint64_t tmp; + IPV6 new_ip {0,0}; + new_ip.ip_32.a = tmp = ((int64_t)lhs.ip_32.a) - rhs.ip_32.a; + new_ip.ip_32.b = tmp = ((int64_t)lhs.ip_32.b) - rhs.ip_32.b - (tmp>>63); + new_ip.ip_32.c = tmp = ((int64_t)lhs.ip_32.c) - rhs.ip_32.c - (tmp>>63); + new_ip.ip_32.d = ((int64_t)lhs.ip_32.d) - rhs.ip_32.d - (tmp>>63); + return new_ip; +} + +inline const IPV6 operator-(const IPV6 lhs, const int i) +{ + IPV6 new_ip {0,0}; + new_ip.ip_64.lower = i; + return lhs - new_ip; +} + +inline const IPV6 operator&(const IPV6 lhs, const IPV6 rhs) +{ + IPV6 new_ip; + new_ip.ip_64.lower = lhs.ip_64.lower & rhs.ip_64.lower; + new_ip.ip_64.upper = lhs.ip_64.upper & rhs.ip_64.upper; + return new_ip; +} + +inline const IPV6 operator|(const IPV6 lhs, const IPV6 rhs) +{ + IPV6 new_ip; + new_ip.ip_64.lower = lhs.ip_64.lower | rhs.ip_64.lower; + new_ip.ip_64.upper = lhs.ip_64.upper | rhs.ip_64.upper; + return new_ip; +} + +typedef struct Range_s +{ + Range_s(const IPV6 _from = IPV6(), const IPV6 _to = IPV6()):from(_from), to(_to){} + IPV6 from; + IPV6 to; +} Range; + +class IPRange +{ +public: + + IPRange(); + ~IPRange(); + + static bool is_range_valid(const std::string range); + bool add_ranges(const std::unordered_set ranges); + bool add_range(Range *new_range); + bool add_range(const char *range, size_t range_len); + bool remove_ranges(const std::unordered_set ranges); + bool remove_range(const char *range, size_t range_len); + std::unordered_set get_ranges_set(); + + bool is_in_range(const char *ip_str); + bool is_in_range(const IPV6 *ip); + bool is_in_range(const uint32_t ipv4); + bool is_intersect(const IPRange *arg); + bool empty() const; + + const std::string& get_err_str() { return m_err_str; } + void print_ranges(); + std::string ip_to_str(const IPV6 *ip) const; + bool str_to_ip(const char* ip_str, IPV6 *ip); +private: + + typedef std::vector Ranges_t; + Ranges_t m_ranges; + std::string m_err_str; + + bool parse_range(const char* range, size_t range_len, Range *new_range); + bool parse_slash(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_hyphen(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_mask(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_single(const char* range, size_t range_len, Range *new_range); + bool binary_search(const IPV6 ip) const; + + bool mask_range(Range *range, unsigned short cidr); + void handle_remove_intersection(Ranges_t *new_ranges, const Range *remove_range, Range *exist_range); + bool handle_add_intersection(Range *new_range, const Range *exist_range); + void print_range(const Range *range); + void copy_without_spaces(char buf[], size_t buf_len, const char *original, size_t original_len) const; + void net_ipv6_to_host_order(IPV6 *ip, const struct sockaddr_in6 *sa) const; + void net_ipv4_to_host_order(IPV6 *ip, const struct in_addr *addr) const; + +}; + +#endif // IPRANGE_AUDIT_H_ diff -uprN postgresql-hll-2.14_old/include/include/job/job_scheduler.h postgresql-hll-2.14/include/include/job/job_scheduler.h --- postgresql-hll-2.14_old/include/include/job/job_scheduler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/job/job_scheduler.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,73 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_scheduler.h + * declare functions and guc variables for external + * + * + * IDENTIFICATION + * src/include/job/job_scheduler.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_SCHEDULER_H +#define JOB_SCHEDULER_H + +/* GUC variables */ +extern THR_LOCAL int job_queue_processes; +#define DEFAULT_JOB_QUEUE_PROCESSES 10 +#define MIN_JOB_QUEUE_PROCESSES 0 +#define MAX_JOB_QUEUE_PROCESSES 1000 + +/* Job info define */ +typedef struct JobInfoData { + int4 job_id; + Oid job_oid; + Oid job_dboid; + NameData log_user; + NameData node_name; + TimestampTz last_start_date; /* arrange jobs in last_start_date order */ +} JobInfoData; + +typedef struct JobInfoData* JobInfo; + +/***************************************************************************** + Description : shared memory size. +*****************************************************************************/ +extern Size JobInfoShmemSize(void); + +/***************************************************************************** + Description : init shared memory +*****************************************************************************/ +extern void JobInfoShmemInit(void); + +/***************************************************************************** + Description : start job scheduler process. +*****************************************************************************/ +extern ThreadId StartJobScheduler(void); + +/***************************************************************************** + Description : +*****************************************************************************/ +extern void JobScheduleMain(); + +/* Status inquiry functions */ +extern bool IsJobSchedulerProcess(void); + +/* called from postmaster when a worker could not be forked */ +extern void RecordForkJobWorkerFailed(void); + +#endif /* JOB_SCHEDULER_H */ diff -uprN postgresql-hll-2.14_old/include/include/job/job_shmem.h postgresql-hll-2.14/include/include/job/job_shmem.h --- postgresql-hll-2.14_old/include/include/job/job_shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/job/job_shmem.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_shmem.h + * define the shared memory for jobs. + * + * + * IDENTIFICATION + * src/include/job/job_shmem.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_SHMEM_H +#define JOB_SHMEM_H +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "storage/shmem.h" +#include "utils/timestamp.h" + +/* Job worker info define */ +typedef struct JobWorkerInfoData { + SHM_QUEUE job_links; + ThreadId job_worker_pid; + int4 job_id; + Oid job_oid; + Oid job_dboid; + NameData username; + TimestampTz job_launchtime; +} JobWorkerInfoData; + +typedef struct JobWorkerInfoData* JobWorkerInfo; + +/* shared memeory define */ +typedef enum JobShmemE { + ForkJobWorkerFailed, + JobScheduleSignalNum /* must be last */ +} JobShmemE; + +typedef struct JobScheduleShmemStruct { + sig_atomic_t jsch_signal[JobScheduleSignalNum]; + ThreadId jsch_pid; + JobWorkerInfo jsch_freeWorkers; + SHM_QUEUE jsch_runningWorkers; + JobWorkerInfo jsch_startingWorker; +} JobScheduleShmemStruct; + +#endif /* JOB_SHMEM_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/job/job_worker.h postgresql-hll-2.14/include/include/job/job_worker.h --- postgresql-hll-2.14_old/include/include/job/job_worker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/job/job_worker.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_worker.h + * declare functions for external + * + * + * IDENTIFICATION + * src/include/job/job_worker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_WORKER_H +#define JOB_WORKER_H + +/***************************************************************************** + Description : start job worker process. +*****************************************************************************/ +extern ThreadId StartJobExecuteWorker(void); +extern void JobExecuteWorkerMain(); + +/* Status inquiry functions */ +extern bool IsJobWorkerProcess(void); + +#endif /* JOB_WORKER_H */ diff -uprN postgresql-hll-2.14_old/include/include/kadm5/admin.h postgresql-hll-2.14/include/include/kadm5/admin.h --- postgresql-hll-2.14_old/include/include/kadm5/admin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/kadm5/admin.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,501 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* lib/kadm5/admin.h */ +/* + * Copyright 2001, 2008 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ +/* + * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved + * + * $Header$ + */ + +/* + * This API is not considered as stable as the main krb5 API. + * + * - We may make arbitrary incompatible changes between feature + * releases (e.g. from 1.7 to 1.8). + * - We will make some effort to avoid making incompatible changes for + * bugfix releases, but will make them if necessary. + */ + +#ifndef __KADM5_ADMIN_H__ +#define __KADM5_ADMIN_H__ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef KADM5INT_BEGIN_DECLS +#if defined(__cplusplus) +#define KADM5INT_BEGIN_DECLS extern "C" { +#define KADM5INT_END_DECLS } +#else +#define KADM5INT_BEGIN_DECLS +#define KADM5INT_END_DECLS +#endif +#endif + +KADM5INT_BEGIN_DECLS + +#define KADM5_ADMIN_SERVICE "kadmin/admin" +#define KADM5_CHANGEPW_SERVICE "kadmin/changepw" +#define KADM5_HIST_PRINCIPAL "kadmin/history" +#define KADM5_KIPROP_HOST_SERVICE "kiprop" + +typedef krb5_principal kadm5_princ_t; +typedef char *kadm5_policy_t; +typedef long kadm5_ret_t; + +#define KADM5_PW_FIRST_PROMPT \ + (error_message(CHPASS_UTIL_NEW_PASSWORD_PROMPT)) +#define KADM5_PW_SECOND_PROMPT \ + (error_message(CHPASS_UTIL_NEW_PASSWORD_AGAIN_PROMPT)) + +/* + * Successful return code + */ +#define KADM5_OK 0 + +/* + * Field masks + */ + +/* kadm5_principal_ent_t */ +#define KADM5_PRINCIPAL 0x000001 +#define KADM5_PRINC_EXPIRE_TIME 0x000002 +#define KADM5_PW_EXPIRATION 0x000004 +#define KADM5_LAST_PWD_CHANGE 0x000008 +#define KADM5_ATTRIBUTES 0x000010 +#define KADM5_MAX_LIFE 0x000020 +#define KADM5_MOD_TIME 0x000040 +#define KADM5_MOD_NAME 0x000080 +#define KADM5_KVNO 0x000100 +#define KADM5_MKVNO 0x000200 +#define KADM5_AUX_ATTRIBUTES 0x000400 +#define KADM5_POLICY 0x000800 +#define KADM5_POLICY_CLR 0x001000 +/* version 2 masks */ +#define KADM5_MAX_RLIFE 0x002000 +#define KADM5_LAST_SUCCESS 0x004000 +#define KADM5_LAST_FAILED 0x008000 +#define KADM5_FAIL_AUTH_COUNT 0x010000 +#define KADM5_KEY_DATA 0x020000 +#define KADM5_TL_DATA 0x040000 +#ifdef notyet /* Novell */ +#define KADM5_CPW_FUNCTION 0x080000 +#define KADM5_RANDKEY_USED 0x100000 +#endif +#define KADM5_LOAD 0x200000 +#define KADM5_KEY_HIST 0x400000 + +/* all but KEY_DATA, TL_DATA, LOAD */ +#define KADM5_PRINCIPAL_NORMAL_MASK 0x41ffff + + +/* kadm5_policy_ent_t */ +#define KADM5_PW_MAX_LIFE 0x00004000 +#define KADM5_PW_MIN_LIFE 0x00008000 +#define KADM5_PW_MIN_LENGTH 0x00010000 +#define KADM5_PW_MIN_CLASSES 0x00020000 +#define KADM5_PW_HISTORY_NUM 0x00040000 +#define KADM5_REF_COUNT 0x00080000 +#define KADM5_PW_MAX_FAILURE 0x00100000 +#define KADM5_PW_FAILURE_COUNT_INTERVAL 0x00200000 +#define KADM5_PW_LOCKOUT_DURATION 0x00400000 +#define KADM5_POLICY_ATTRIBUTES 0x00800000 +#define KADM5_POLICY_MAX_LIFE 0x01000000 +#define KADM5_POLICY_MAX_RLIFE 0x02000000 +#define KADM5_POLICY_ALLOWED_KEYSALTS 0x04000000 +#define KADM5_POLICY_TL_DATA 0x08000000 + +/* kadm5_config_params */ +#define KADM5_CONFIG_REALM 0x00000001 +#define KADM5_CONFIG_DBNAME 0x00000002 +#define KADM5_CONFIG_MKEY_NAME 0x00000004 +#define KADM5_CONFIG_MAX_LIFE 0x00000008 +#define KADM5_CONFIG_MAX_RLIFE 0x00000010 +#define KADM5_CONFIG_EXPIRATION 0x00000020 +#define KADM5_CONFIG_FLAGS 0x00000040 +/*#define KADM5_CONFIG_ADMIN_KEYTAB 0x00000080*/ +#define KADM5_CONFIG_STASH_FILE 0x00000100 +#define KADM5_CONFIG_ENCTYPE 0x00000200 +#define KADM5_CONFIG_ADBNAME 0x00000400 +#define KADM5_CONFIG_ADB_LOCKFILE 0x00000800 +#define KADM5_CONFIG_KADMIND_LISTEN 0x00001000 +#define KADM5_CONFIG_ACL_FILE 0x00002000 +#define KADM5_CONFIG_KADMIND_PORT 0x00004000 +#define KADM5_CONFIG_ENCTYPES 0x00008000 +#define KADM5_CONFIG_ADMIN_SERVER 0x00010000 +#define KADM5_CONFIG_DICT_FILE 0x00020000 +#define KADM5_CONFIG_MKEY_FROM_KBD 0x00040000 +#define KADM5_CONFIG_KPASSWD_PORT 0x00080000 +#define KADM5_CONFIG_OLD_AUTH_GSSAPI 0x00100000 +#define KADM5_CONFIG_NO_AUTH 0x00200000 +#define KADM5_CONFIG_AUTH_NOFALLBACK 0x00400000 +#define KADM5_CONFIG_KPASSWD_LISTEN 0x00800000 +#define KADM5_CONFIG_IPROP_ENABLED 0x01000000 +#define KADM5_CONFIG_ULOG_SIZE 0x02000000 +#define KADM5_CONFIG_POLL_TIME 0x04000000 +#define KADM5_CONFIG_IPROP_LOGFILE 0x08000000 +#define KADM5_CONFIG_IPROP_PORT 0x10000000 +#define KADM5_CONFIG_KVNO 0x20000000 +#define KADM5_CONFIG_IPROP_RESYNC_TIMEOUT 0x40000000 +#define KADM5_CONFIG_IPROP_LISTEN 0x80000000 +/* + * permission bits + */ +#define KADM5_PRIV_GET 0x01 +#define KADM5_PRIV_ADD 0x02 +#define KADM5_PRIV_MODIFY 0x04 +#define KADM5_PRIV_DELETE 0x08 + +/* + * API versioning constants + */ +#define KADM5_MASK_BITS 0xffffff00 + +#define KADM5_STRUCT_VERSION_MASK 0x12345600 +#define KADM5_STRUCT_VERSION_1 (KADM5_STRUCT_VERSION_MASK|0x01) +#define KADM5_STRUCT_VERSION KADM5_STRUCT_VERSION_1 + +#define KADM5_API_VERSION_MASK 0x12345700 +#define KADM5_API_VERSION_2 (KADM5_API_VERSION_MASK|0x02) +#define KADM5_API_VERSION_3 (KADM5_API_VERSION_MASK|0x03) +#define KADM5_API_VERSION_4 (KADM5_API_VERSION_MASK|0x04) + +typedef struct _kadm5_principal_ent_t { + krb5_principal principal; + krb5_timestamp princ_expire_time; + krb5_timestamp last_pwd_change; + krb5_timestamp pw_expiration; + krb5_deltat max_life; + krb5_principal mod_name; + krb5_timestamp mod_date; + krb5_flags attributes; + krb5_kvno kvno; + krb5_kvno mkvno; + char *policy; + long aux_attributes; + + /* version 2 fields */ + krb5_deltat max_renewable_life; + krb5_timestamp last_success; + krb5_timestamp last_failed; + krb5_kvno fail_auth_count; + krb5_int16 n_key_data; + krb5_int16 n_tl_data; + krb5_tl_data *tl_data; + krb5_key_data *key_data; +} kadm5_principal_ent_rec, *kadm5_principal_ent_t; + +typedef struct _kadm5_policy_ent_t { + char *policy; + long pw_min_life; + long pw_max_life; + long pw_min_length; + long pw_min_classes; + long pw_history_num; + long policy_refcnt; /* no longer used */ + + /* version 3 fields */ + krb5_kvno pw_max_fail; + krb5_deltat pw_failcnt_interval; + krb5_deltat pw_lockout_duration; + + /* version 4 fields */ + krb5_flags attributes; + krb5_deltat max_life; + krb5_deltat max_renewable_life; + char *allowed_keysalts; + krb5_int16 n_tl_data; + krb5_tl_data *tl_data; +} kadm5_policy_ent_rec, *kadm5_policy_ent_t; + +/* + * Data structure returned by kadm5_get_config_params() + */ +typedef struct _kadm5_config_params { + long mask; + char * realm; + int kadmind_port; + int kpasswd_port; + + char * admin_server; +#ifdef notyet /* Novell */ /* ABI change? */ + char * kpasswd_server; +#endif + + /* Deprecated except for db2 backwards compatibility. Don't add + new uses except as fallbacks for parameters that should be + specified in the database module section of the config + file. */ + char * dbname; + + char * acl_file; + char * dict_file; + + int mkey_from_kbd; + char * stash_file; + char * mkey_name; + krb5_enctype enctype; + krb5_deltat max_life; + krb5_deltat max_rlife; + krb5_timestamp expiration; + krb5_flags flags; + krb5_key_salt_tuple *keysalts; + krb5_int32 num_keysalts; + krb5_kvno kvno; + bool_t iprop_enabled; + uint32_t iprop_ulogsize; + krb5_deltat iprop_poll_time; + char * iprop_logfile; +/* char * iprop_server;*/ + int iprop_port; + int iprop_resync_timeout; + char * kadmind_listen; + char * kpasswd_listen; + char * iprop_listen; +} kadm5_config_params; + +typedef struct _kadm5_key_data { + krb5_kvno kvno; + krb5_keyblock key; + krb5_keysalt salt; +} kadm5_key_data; + +/* + * functions + */ + +krb5_error_code kadm5_get_config_params(krb5_context context, + int use_kdc_config, + kadm5_config_params *params_in, + kadm5_config_params *params_out); + +krb5_error_code kadm5_free_config_params(krb5_context context, + kadm5_config_params *params); + +krb5_error_code kadm5_get_admin_service_name(krb5_context, char *, + char *, size_t); + +/* + * For all initialization functions, the caller must first initialize + * a context with kadm5_init_krb5_context which will survive as long + * as the resulting handle. The caller should free the context with + * krb5_free_context. + */ + +kadm5_ret_t kadm5_init(krb5_context context, char *client_name, + char *pass, char *service_name, + kadm5_config_params *params, + krb5_ui_4 struct_version, + krb5_ui_4 api_version, + char **db_args, + void **server_handle); +kadm5_ret_t kadm5_init_anonymous(krb5_context context, char *client_name, + char *service_name, + kadm5_config_params *params, + krb5_ui_4 struct_version, + krb5_ui_4 api_version, + char **db_args, + void **server_handle); +kadm5_ret_t kadm5_init_with_password(krb5_context context, + char *client_name, + char *pass, + char *service_name, + kadm5_config_params *params, + krb5_ui_4 struct_version, + krb5_ui_4 api_version, + char **db_args, + void **server_handle); +kadm5_ret_t kadm5_init_with_skey(krb5_context context, + char *client_name, + char *keytab, + char *service_name, + kadm5_config_params *params, + krb5_ui_4 struct_version, + krb5_ui_4 api_version, + char **db_args, + void **server_handle); +kadm5_ret_t kadm5_init_with_creds(krb5_context context, + char *client_name, + krb5_ccache cc, + char *service_name, + kadm5_config_params *params, + krb5_ui_4 struct_version, + krb5_ui_4 api_version, + char **db_args, + void **server_handle); +kadm5_ret_t kadm5_lock(void *server_handle); +kadm5_ret_t kadm5_unlock(void *server_handle); +kadm5_ret_t kadm5_flush(void *server_handle); +kadm5_ret_t kadm5_destroy(void *server_handle); +kadm5_ret_t kadm5_create_principal(void *server_handle, + kadm5_principal_ent_t ent, + long mask, char *pass); +kadm5_ret_t kadm5_create_principal_3(void *server_handle, + kadm5_principal_ent_t ent, + long mask, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + char *pass); +kadm5_ret_t kadm5_delete_principal(void *server_handle, + krb5_principal principal); +kadm5_ret_t kadm5_modify_principal(void *server_handle, + kadm5_principal_ent_t ent, + long mask); +kadm5_ret_t kadm5_rename_principal(void *server_handle, + krb5_principal,krb5_principal); +kadm5_ret_t kadm5_get_principal(void *server_handle, + krb5_principal principal, + kadm5_principal_ent_t ent, + long mask); +kadm5_ret_t kadm5_chpass_principal(void *server_handle, + krb5_principal principal, + char *pass); +kadm5_ret_t kadm5_chpass_principal_3(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + char *pass); +kadm5_ret_t kadm5_randkey_principal(void *server_handle, + krb5_principal principal, + krb5_keyblock **keyblocks, + int *n_keys); +kadm5_ret_t kadm5_randkey_principal_3(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + krb5_keyblock **keyblocks, + int *n_keys); +kadm5_ret_t kadm5_setv4key_principal(void *server_handle, + krb5_principal principal, + krb5_keyblock *keyblock); + +kadm5_ret_t kadm5_setkey_principal(void *server_handle, + krb5_principal principal, + krb5_keyblock *keyblocks, + int n_keys); + +kadm5_ret_t kadm5_setkey_principal_3(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + krb5_keyblock *keyblocks, + int n_keys); + +kadm5_ret_t kadm5_setkey_principal_4(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + kadm5_key_data *key_data, + int n_key_data); + +kadm5_ret_t kadm5_decrypt_key(void *server_handle, + kadm5_principal_ent_t entry, krb5_int32 + ktype, krb5_int32 stype, krb5_int32 + kvno, krb5_keyblock *keyblock, + krb5_keysalt *keysalt, int *kvnop); + +kadm5_ret_t kadm5_create_policy(void *server_handle, + kadm5_policy_ent_t ent, + long mask); +kadm5_ret_t kadm5_delete_policy(void *server_handle, + kadm5_policy_t policy); +kadm5_ret_t kadm5_modify_policy(void *server_handle, + kadm5_policy_ent_t ent, + long mask); +kadm5_ret_t kadm5_get_policy(void *server_handle, + kadm5_policy_t policy, + kadm5_policy_ent_t ent); +kadm5_ret_t kadm5_get_privs(void *server_handle, + long *privs); + +kadm5_ret_t kadm5_chpass_principal_util(void *server_handle, + krb5_principal princ, + char *new_pw, + char **ret_pw, + char *msg_ret, + unsigned int msg_len); + +kadm5_ret_t kadm5_free_principal_ent(void *server_handle, + kadm5_principal_ent_t + ent); +kadm5_ret_t kadm5_free_policy_ent(void *server_handle, + kadm5_policy_ent_t ent); + +kadm5_ret_t kadm5_get_principals(void *server_handle, + char *exp, char ***princs, + int *count); + +kadm5_ret_t kadm5_get_policies(void *server_handle, + char *exp, char ***pols, + int *count); + +kadm5_ret_t kadm5_free_key_data(void *server_handle, + krb5_int16 *n_key_data, + krb5_key_data *key_data); + +kadm5_ret_t kadm5_free_name_list(void *server_handle, char **names, + int count); + +krb5_error_code kadm5_init_krb5_context (krb5_context *); + +krb5_error_code kadm5_init_iprop(void *server_handle, char **db_args); + +kadm5_ret_t kadm5_get_principal_keys(void *server_handle, + krb5_principal principal, + krb5_kvno kvno, + kadm5_key_data **key_data, + int *n_key_data); + +kadm5_ret_t kadm5_purgekeys(void *server_handle, + krb5_principal principal, + int keepkvno); + +kadm5_ret_t kadm5_get_strings(void *server_handle, + krb5_principal principal, + krb5_string_attr **strings_out, + int *count_out); + +kadm5_ret_t kadm5_set_string(void *server_handle, + krb5_principal principal, + const char *key, + const char *value); + +kadm5_ret_t kadm5_free_strings(void *server_handle, + krb5_string_attr *strings, + int count); + +kadm5_ret_t kadm5_free_kadm5_key_data(krb5_context context, int n_key_data, + kadm5_key_data *key_data); + +KADM5INT_END_DECLS + +#endif /* __KADM5_ADMIN_H__ */ diff -uprN postgresql-hll-2.14_old/include/include/kadm5/chpass_util_strings.h postgresql-hll-2.14/include/include/kadm5/chpass_util_strings.h --- postgresql-hll-2.14_old/include/include/kadm5/chpass_util_strings.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/kadm5/chpass_util_strings.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,38 @@ +/* + * et-h-chpass_util_strings.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define CHPASS_UTIL_GET_POLICY_INFO (-1492553984L) +#define CHPASS_UTIL_GET_PRINC_INFO (-1492553983L) +#define CHPASS_UTIL_NEW_PASSWORD_MISMATCH (-1492553982L) +#define CHPASS_UTIL_NEW_PASSWORD_PROMPT (-1492553981L) +#define CHPASS_UTIL_NEW_PASSWORD_AGAIN_PROMPT (-1492553980L) +#define CHPASS_UTIL_NO_PASSWORD_READ (-1492553979L) +#define CHPASS_UTIL_NO_POLICY_YET_Q_ERROR (-1492553978L) +#define CHPASS_UTIL_PASSWORD_CHANGED (-1492553977L) +#define CHPASS_UTIL_PASSWORD_IN_DICTIONARY (-1492553976L) +#define CHPASS_UTIL_PASSWORD_NOT_CHANGED (-1492553975L) +#define CHPASS_UTIL_PASSWORD_TOO_SHORT (-1492553974L) +#define CHPASS_UTIL_TOO_FEW_CLASSES (-1492553973L) +#define CHPASS_UTIL_PASSWORD_TOO_SOON (-1492553972L) +#define CHPASS_UTIL_PASSWORD_REUSE (-1492553971L) +#define CHPASS_UTIL_WHILE_TRYING_TO_CHANGE (-1492553970L) +#define CHPASS_UTIL_WHILE_READING_PASSWORD (-1492553969L) +#define ERROR_TABLE_BASE_ovku (-1492553984L) + +extern const struct error_table et_ovku_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_ovku_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_ovku_error_table() +#endif + +#if !defined(_WIN32) +#define init_ovku_err_tbl initialize_ovku_error_table +#define ovku_err_base ERROR_TABLE_BASE_ovku +#endif diff -uprN postgresql-hll-2.14_old/include/include/kadm5/kadm_err.h postgresql-hll-2.14/include/include/kadm5/kadm_err.h --- postgresql-hll-2.14_old/include/include/kadm5/kadm_err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/kadm5/kadm_err.h 2020-12-12 17:06:43.211347574 +0800 @@ -0,0 +1,85 @@ +/* + * et-h-kadm_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KADM5_FAILURE (43787520L) +#define KADM5_AUTH_GET (43787521L) +#define KADM5_AUTH_ADD (43787522L) +#define KADM5_AUTH_MODIFY (43787523L) +#define KADM5_AUTH_DELETE (43787524L) +#define KADM5_AUTH_INSUFFICIENT (43787525L) +#define KADM5_BAD_DB (43787526L) +#define KADM5_DUP (43787527L) +#define KADM5_RPC_ERROR (43787528L) +#define KADM5_NO_SRV (43787529L) +#define KADM5_BAD_HIST_KEY (43787530L) +#define KADM5_NOT_INIT (43787531L) +#define KADM5_UNK_PRINC (43787532L) +#define KADM5_UNK_POLICY (43787533L) +#define KADM5_BAD_MASK (43787534L) +#define KADM5_BAD_CLASS (43787535L) +#define KADM5_BAD_LENGTH (43787536L) +#define KADM5_BAD_POLICY (43787537L) +#define KADM5_BAD_PRINCIPAL (43787538L) +#define KADM5_BAD_AUX_ATTR (43787539L) +#define KADM5_BAD_HISTORY (43787540L) +#define KADM5_BAD_MIN_PASS_LIFE (43787541L) +#define KADM5_PASS_Q_TOOSHORT (43787542L) +#define KADM5_PASS_Q_CLASS (43787543L) +#define KADM5_PASS_Q_DICT (43787544L) +#define KADM5_PASS_REUSE (43787545L) +#define KADM5_PASS_TOOSOON (43787546L) +#define KADM5_POLICY_REF (43787547L) +#define KADM5_INIT (43787548L) +#define KADM5_BAD_PASSWORD (43787549L) +#define KADM5_PROTECT_PRINCIPAL (43787550L) +#define KADM5_BAD_SERVER_HANDLE (43787551L) +#define KADM5_BAD_STRUCT_VERSION (43787552L) +#define KADM5_OLD_STRUCT_VERSION (43787553L) +#define KADM5_NEW_STRUCT_VERSION (43787554L) +#define KADM5_BAD_API_VERSION (43787555L) +#define KADM5_OLD_LIB_API_VERSION (43787556L) +#define KADM5_OLD_SERVER_API_VERSION (43787557L) +#define KADM5_NEW_LIB_API_VERSION (43787558L) +#define KADM5_NEW_SERVER_API_VERSION (43787559L) +#define KADM5_SECURE_PRINC_MISSING (43787560L) +#define KADM5_NO_RENAME_SALT (43787561L) +#define KADM5_BAD_CLIENT_PARAMS (43787562L) +#define KADM5_BAD_SERVER_PARAMS (43787563L) +#define KADM5_AUTH_LIST (43787564L) +#define KADM5_AUTH_CHANGEPW (43787565L) +#define KADM5_GSS_ERROR (43787566L) +#define KADM5_BAD_TL_TYPE (43787567L) +#define KADM5_MISSING_CONF_PARAMS (43787568L) +#define KADM5_BAD_SERVER_NAME (43787569L) +#define KADM5_AUTH_SETKEY (43787570L) +#define KADM5_SETKEY_DUP_ENCTYPES (43787571L) +#define KADM5_SETV4KEY_INVAL_ENCTYPE (43787572L) +#define KADM5_SETKEY3_ETYPE_MISMATCH (43787573L) +#define KADM5_MISSING_KRB5_CONF_PARAMS (43787574L) +#define KADM5_XDR_FAILURE (43787575L) +#define KADM5_CANT_RESOLVE (43787576L) +#define KADM5_PASS_Q_GENERIC (43787577L) +#define KADM5_BAD_KEYSALTS (43787578L) +#define KADM5_SETKEY_BAD_KVNO (43787579L) +#define KADM5_AUTH_EXTRACT (43787580L) +#define KADM5_PROTECT_KEYS (43787581L) +#define KADM5_AUTH_INITIAL (43787582L) +#define ERROR_TABLE_BASE_ovk (43787520L) + +extern const struct error_table et_ovk_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_ovk_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_ovk_error_table() +#endif + +#if !defined(_WIN32) +#define init_ovk_err_tbl initialize_ovk_error_table +#define ovk_err_base ERROR_TABLE_BASE_ovk +#endif diff -uprN postgresql-hll-2.14_old/include/include/kdb.h postgresql-hll-2.14/include/include/kdb.h --- postgresql-hll-2.14_old/include/include/kdb.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/kdb.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,1406 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright 1990, 1991, 2016 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ +/* + * Copyright (C) 1998 by the FundsXpress, INC. + * + * All rights reserved. + * + * Export of this software from the United States of America may require + * a specific license from the United States Government. It is the + * responsibility of any person or organization contemplating export to + * obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of FundsXpress. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. FundsXpress makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* KDC Database interface definitions */ + +/* This API is not considered as stable as the main krb5 API. + * + * - We may make arbitrary incompatible changes between feature + * releases (e.g. from 1.7 to 1.8). + * - We will make some effort to avoid making incompatible changes for + * bugfix releases, but will make them if necessary. + */ + +#ifndef KRB5_KDB5__ +#define KRB5_KDB5__ + +#include + +/* This version will be incremented when incompatible changes are made to the + * KDB API, and will be kept in sync with the libkdb major version. */ +#define KRB5_KDB_API_VERSION 9 + +/* Salt types */ +#define KRB5_KDB_SALTTYPE_NORMAL 0 +#define KRB5_KDB_SALTTYPE_V4 1 +#define KRB5_KDB_SALTTYPE_NOREALM 2 +#define KRB5_KDB_SALTTYPE_ONLYREALM 3 +#define KRB5_KDB_SALTTYPE_SPECIAL 4 +#define KRB5_KDB_SALTTYPE_AFS3 5 +#define KRB5_KDB_SALTTYPE_CERTHASH 6 + +/* Attributes */ +#define KRB5_KDB_DISALLOW_POSTDATED 0x00000001 +#define KRB5_KDB_DISALLOW_FORWARDABLE 0x00000002 +#define KRB5_KDB_DISALLOW_TGT_BASED 0x00000004 +#define KRB5_KDB_DISALLOW_RENEWABLE 0x00000008 +#define KRB5_KDB_DISALLOW_PROXIABLE 0x00000010 +#define KRB5_KDB_DISALLOW_DUP_SKEY 0x00000020 +#define KRB5_KDB_DISALLOW_ALL_TIX 0x00000040 +#define KRB5_KDB_REQUIRES_PRE_AUTH 0x00000080 +#define KRB5_KDB_REQUIRES_HW_AUTH 0x00000100 +#define KRB5_KDB_REQUIRES_PWCHANGE 0x00000200 +#define KRB5_KDB_DISALLOW_SVR 0x00001000 +#define KRB5_KDB_PWCHANGE_SERVICE 0x00002000 +#define KRB5_KDB_SUPPORT_DESMD5 0x00004000 +#define KRB5_KDB_NEW_PRINC 0x00008000 +#define KRB5_KDB_OK_AS_DELEGATE 0x00100000 +#define KRB5_KDB_OK_TO_AUTH_AS_DELEGATE 0x00200000 /* S4U2Self OK */ +#define KRB5_KDB_NO_AUTH_DATA_REQUIRED 0x00400000 +#define KRB5_KDB_LOCKDOWN_KEYS 0x00800000 + +/* Creation flags */ +#define KRB5_KDB_CREATE_BTREE 0x00000001 +#define KRB5_KDB_CREATE_HASH 0x00000002 + +/* Private flag used to indicate principal is local TGS */ +#define KRB5_KDB_TICKET_GRANTING_SERVICE 0x01000000 +/* Private flag used to indicate xrealm relationship is non-transitive */ +#define KRB5_KDB_XREALM_NON_TRANSITIVE 0x02000000 + +/* Entry get flags */ +/* Name canonicalization requested */ +#define KRB5_KDB_FLAG_CANONICALIZE 0x00000010 +/* Include authorization data generated by backend */ +#define KRB5_KDB_FLAG_INCLUDE_PAC 0x00000020 +/* Is AS-REQ (client referrals only) */ +#define KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY 0x00000040 +/* Map cross-realm principals */ +#define KRB5_KDB_FLAG_MAP_PRINCIPALS 0x00000080 +/* Protocol transition */ +#define KRB5_KDB_FLAG_PROTOCOL_TRANSITION 0x00000100 +/* Constrained delegation */ +#define KRB5_KDB_FLAG_CONSTRAINED_DELEGATION 0x00000200 +/* User-to-user */ +#define KRB5_KDB_FLAG_USER_TO_USER 0x00000800 +/* Cross-realm */ +#define KRB5_KDB_FLAG_CROSS_REALM 0x00001000 +/* Allow in-realm aliases */ +#define KRB5_KDB_FLAG_ALIAS_OK 0x00002000 + +#define KRB5_KDB_FLAGS_S4U ( KRB5_KDB_FLAG_PROTOCOL_TRANSITION | \ + KRB5_KDB_FLAG_CONSTRAINED_DELEGATION ) + +/* KDB iteration flags */ +#define KRB5_DB_ITER_WRITE 0x00000001 +#define KRB5_DB_ITER_REV 0x00000002 +#define KRB5_DB_ITER_RECURSE 0x00000004 + +/* String attribute names recognized by krb5 */ +#define KRB5_KDB_SK_SESSION_ENCTYPES "session_enctypes" +#define KRB5_KDB_SK_REQUIRE_AUTH "require_auth" + +#if !defined(_WIN32) + +/* + * Note --- these structures cannot be modified without changing the + * database version number in libkdb.a, but should be expandable by + * adding new tl_data types. + */ +typedef struct _krb5_tl_data { + struct _krb5_tl_data* tl_data_next; /* NOT saved */ + krb5_int16 tl_data_type; + krb5_ui_2 tl_data_length; + krb5_octet * tl_data_contents; +} krb5_tl_data; + +/* String attributes (currently stored inside tl-data) map C string keys to + * values. They can be set via kadmin and consumed by KDC plugins. */ +typedef struct krb5_string_attr_st { + char *key; + char *value; +} krb5_string_attr; + +/* + * If this ever changes up the version number and make the arrays be as + * big as necessary. + * + * Currently the first type is the enctype and the second is the salt type. + */ +typedef struct _krb5_key_data { + krb5_int16 key_data_ver; /* Version */ + krb5_ui_2 key_data_kvno; /* Key Version */ + krb5_int16 key_data_type[2]; /* Array of types */ + krb5_ui_2 key_data_length[2]; /* Array of lengths */ + krb5_octet * key_data_contents[2]; /* Array of pointers */ +} krb5_key_data; + +#define KRB5_KDB_V1_KEY_DATA_ARRAY 2 /* # of array elements */ + +typedef struct _krb5_keysalt { + krb5_int16 type; + krb5_data data; /* Length, data */ +} krb5_keysalt; + +/* + * A principal database entry. Extensions to this structure currently use the + * tl_data list. The e_data and e_length fields are not used by any calling + * code except kdb5_util dump and load, which marshal and unmarshal the array + * in the dump record. KDB modules may use these fields internally as long as + * they set e_length appropriately (non-zero if the data should be marshalled + * across dump and load, zero if not) and handle null e_data values in + * caller-constructed principal entries. + */ +typedef struct _krb5_db_entry_new { + krb5_magic magic; /* NOT saved */ + krb5_ui_2 len; + krb5_ui_4 mask; /* members currently changed/set */ + krb5_flags attributes; + krb5_deltat max_life; + krb5_deltat max_renewable_life; + krb5_timestamp expiration; /* When the client expires */ + krb5_timestamp pw_expiration; /* When its passwd expires */ + krb5_timestamp last_success; /* Last successful passwd */ + krb5_timestamp last_failed; /* Last failed passwd attempt */ + krb5_kvno fail_auth_count; /* # of failed passwd attempt */ + krb5_int16 n_tl_data; + krb5_int16 n_key_data; + krb5_ui_2 e_length; /* Length of extra data */ + krb5_octet * e_data; /* Extra data to be saved */ + + krb5_principal princ; /* Length, data */ + krb5_tl_data * tl_data; /* Linked list */ + + /* key_data must be sorted by kvno in descending order. */ + krb5_key_data * key_data; /* Array */ +} krb5_db_entry; + +typedef struct _osa_policy_ent_t { + int version; + char *name; + krb5_ui_4 pw_min_life; + krb5_ui_4 pw_max_life; + krb5_ui_4 pw_min_length; + krb5_ui_4 pw_min_classes; + krb5_ui_4 pw_history_num; + krb5_ui_4 policy_refcnt; /* no longer used */ + /* Only valid if version > 1 */ + krb5_ui_4 pw_max_fail; /* pwdMaxFailure */ + krb5_ui_4 pw_failcnt_interval; /* pwdFailureCountInterval */ + krb5_ui_4 pw_lockout_duration; /* pwdLockoutDuration */ + /* Only valid if version > 2 */ + krb5_ui_4 attributes; + krb5_ui_4 max_life; + krb5_ui_4 max_renewable_life; + char * allowed_keysalts; + krb5_int16 n_tl_data; + krb5_tl_data * tl_data; +} osa_policy_ent_rec, *osa_policy_ent_t; + +typedef void (*osa_adb_iter_policy_func) (void *, osa_policy_ent_t); + +typedef struct __krb5_key_salt_tuple { + krb5_enctype ks_enctype; + krb5_int32 ks_salttype; +} krb5_key_salt_tuple; + +#define KRB5_KDB_MAGIC_NUMBER 0xdbdbdbdb +#define KRB5_KDB_V1_BASE_LENGTH 38 + +#define KRB5_KDB_MAX_ALLOWED_KS_LEN 512 + +#define KRB5_TL_LAST_PWD_CHANGE 0x0001 +#define KRB5_TL_MOD_PRINC 0x0002 +#define KRB5_TL_KADM_DATA 0x0003 +#define KRB5_TL_KADM5_E_DATA 0x0004 +#define KRB5_TL_RB1_CHALLENGE 0x0005 +#ifdef SECURID +#define KRB5_TL_SECURID_STATE 0x0006 +#endif /* SECURID */ +#define KRB5_TL_USER_CERTIFICATE 0x0007 +#define KRB5_TL_MKVNO 0x0008 +#define KRB5_TL_ACTKVNO 0x0009 +#define KRB5_TL_MKEY_AUX 0x000a + +/* String attributes may not always be represented in tl-data. kadmin clients + * must use the get_strings and set_string RPCs. */ +#define KRB5_TL_STRING_ATTRS 0x000b + +#define KRB5_TL_PAC_LOGON_INFO 0x0100 /* NDR encoded validation info */ +#define KRB5_TL_SERVER_REFERRAL 0x0200 /* ASN.1 encoded ServerReferralInfo */ +#define KRB5_TL_SVR_REFERRAL_DATA 0x0300 /* ASN.1 encoded PA-SVR-REFERRAL-DATA */ +#define KRB5_TL_CONSTRAINED_DELEGATION_ACL 0x0400 /* Each entry is a permitted SPN */ +#define KRB5_TL_LM_KEY 0x0500 /* LM OWF */ +#define KRB5_TL_X509_SUBJECT_ISSUER_NAME 0x0600 /* IssuerDNSubjectDN */ +#define KRB5_TL_LAST_ADMIN_UNLOCK 0x0700 /* Timestamp of admin unlock */ + +#define KRB5_TL_DB_ARGS 0x7fff + +/* version number for KRB5_TL_ACTKVNO data */ +#define KRB5_TL_ACTKVNO_VER 1 + +/* version number for KRB5_TL_MKEY_AUX data */ +#define KRB5_TL_MKEY_AUX_VER 1 + +typedef struct _krb5_actkvno_node { + struct _krb5_actkvno_node *next; + krb5_kvno act_kvno; + krb5_timestamp act_time; +} krb5_actkvno_node; + +typedef struct _krb5_mkey_aux_node { + struct _krb5_mkey_aux_node *next; + krb5_kvno mkey_kvno; /* kvno of mkey protecting the latest_mkey */ + krb5_key_data latest_mkey; /* most recent mkey */ +} krb5_mkey_aux_node; + +typedef struct _krb5_keylist_node { + krb5_keyblock keyblock; + krb5_kvno kvno; + struct _krb5_keylist_node *next; +} krb5_keylist_node; + +/* + * Determines the number of failed KDC requests before DISALLOW_ALL_TIX is set + * on the principal. + */ +#define KRB5_MAX_FAIL_COUNT 5 + +/* XXX depends on knowledge of krb5_parse_name() formats */ +#define KRB5_KDB_M_NAME "K/M" /* Kerberos/Master */ + +/* prompts used by default when reading the KDC password from the keyboard. */ +#define KRB5_KDC_MKEY_1 "Enter KDC database master key" +#define KRB5_KDC_MKEY_2 "Re-enter KDC database master key to verify" + + +extern char *krb5_mkey_pwd_prompt1; +extern char *krb5_mkey_pwd_prompt2; + +/* + * These macros specify the encoding of data within the database. + * + * Data encoding is little-endian. + */ +#ifdef _KRB5_INT_H +#include "k5-platform.h" +#define krb5_kdb_decode_int16(cp, i16) \ + *((krb5_int16 *) &(i16)) = load_16_le(cp) +#define krb5_kdb_decode_int32(cp, i32) \ + *((krb5_int32 *) &(i32)) = load_32_le(cp) +#define krb5_kdb_encode_int16(i16, cp) store_16_le(i16, cp) +#define krb5_kdb_encode_int32(i32, cp) store_32_le(i32, cp) +#endif /* _KRB5_INT_H */ + +#define KRB5_KDB_OPEN_RW 0 +#define KRB5_KDB_OPEN_RO 1 + +#ifndef KRB5_KDB_SRV_TYPE_KDC +#define KRB5_KDB_SRV_TYPE_KDC 0x0100 +#endif + +#ifndef KRB5_KDB_SRV_TYPE_ADMIN +#define KRB5_KDB_SRV_TYPE_ADMIN 0x0200 +#endif + +/* 0x0300 was KRB5_KDB_SRV_TYPE_PASSWD but it is no longer used. */ + +#ifndef KRB5_KDB_SRV_TYPE_OTHER +#define KRB5_KDB_SRV_TYPE_OTHER 0x0400 +#endif + +#define KRB5_KDB_OPT_SET_DB_NAME 0 +#define KRB5_KDB_OPT_SET_LOCK_MODE 1 + +#define KRB5_DB_LOCKMODE_SHARED 0x0001 +#define KRB5_DB_LOCKMODE_EXCLUSIVE 0x0002 +#define KRB5_DB_LOCKMODE_PERMANENT 0x0008 + +/* libkdb.spec */ +krb5_error_code krb5_db_setup_lib_handle(krb5_context kcontext); +krb5_error_code krb5_db_open( krb5_context kcontext, char **db_args, int mode ); +krb5_error_code krb5_db_init ( krb5_context kcontext ); +krb5_error_code krb5_db_create ( krb5_context kcontext, char **db_args ); +krb5_error_code krb5_db_inited ( krb5_context kcontext ); +krb5_error_code kdb5_db_create ( krb5_context kcontext, char **db_args ); +krb5_error_code krb5_db_fini ( krb5_context kcontext ); +const char * krb5_db_errcode2string ( krb5_context kcontext, long err_code ); +krb5_error_code krb5_db_destroy ( krb5_context kcontext, char **db_args ); +krb5_error_code krb5_db_promote ( krb5_context kcontext, char **db_args ); +krb5_error_code krb5_db_get_age ( krb5_context kcontext, char *db_name, time_t *t ); +krb5_error_code krb5_db_lock ( krb5_context kcontext, int lock_mode ); +krb5_error_code krb5_db_unlock ( krb5_context kcontext ); +krb5_error_code krb5_db_get_principal ( krb5_context kcontext, + krb5_const_principal search_for, + unsigned int flags, + krb5_db_entry **entry ); +void krb5_db_free_principal ( krb5_context kcontext, krb5_db_entry *entry ); +krb5_error_code krb5_db_put_principal ( krb5_context kcontext, + krb5_db_entry *entry ); +krb5_error_code krb5_db_delete_principal ( krb5_context kcontext, + krb5_principal search_for ); +krb5_error_code krb5_db_rename_principal ( krb5_context kcontext, + krb5_principal source, + krb5_principal target ); + +/* + * Iterate over principals in the KDB. If the callback may write to the DB, + * the caller must get an exclusive lock with krb5_db_lock before iterating, + * and release it with krb5_db_unlock after iterating. + */ +krb5_error_code krb5_db_iterate ( krb5_context kcontext, + char *match_entry, + int (*func) (krb5_pointer, krb5_db_entry *), + krb5_pointer func_arg, krb5_flags iterflags ); + + +krb5_error_code krb5_db_store_master_key ( krb5_context kcontext, + char *keyfile, + krb5_principal mname, + krb5_kvno kvno, + krb5_keyblock *key, + char *master_pwd); +krb5_error_code krb5_db_store_master_key_list ( krb5_context kcontext, + char *keyfile, + krb5_principal mname, + char *master_pwd); +krb5_error_code krb5_db_fetch_mkey ( krb5_context context, + krb5_principal mname, + krb5_enctype etype, + krb5_boolean fromkeyboard, + krb5_boolean twice, + char *db_args, + krb5_kvno *kvno, + krb5_data *salt, + krb5_keyblock *key); +krb5_error_code +krb5_db_fetch_mkey_list( krb5_context context, + krb5_principal mname, + const krb5_keyblock * mkey ); + +krb5_error_code +krb5_dbe_find_enctype( krb5_context kcontext, + krb5_db_entry *dbentp, + krb5_int32 ktype, + krb5_int32 stype, + krb5_int32 kvno, + krb5_key_data **kdatap); + + +krb5_error_code krb5_dbe_search_enctype ( krb5_context kcontext, + krb5_db_entry *dbentp, + krb5_int32 *start, + krb5_int32 ktype, + krb5_int32 stype, + krb5_int32 kvno, + krb5_key_data **kdatap); + +krb5_error_code +krb5_db_setup_mkey_name ( krb5_context context, + const char *keyname, + const char *realm, + char **fullname, + krb5_principal *principal); + +/** + * Decrypts the key given in @@a key_data. If @a mkey is specified, that + * master key is used. If @a mkey is NULL, then all master keys are tried. + */ +krb5_error_code +krb5_dbe_decrypt_key_data( krb5_context context, + const krb5_keyblock * mkey, + const krb5_key_data * key_data, + krb5_keyblock * dbkey, + krb5_keysalt * keysalt); + +krb5_error_code +krb5_dbe_encrypt_key_data( krb5_context context, + const krb5_keyblock * mkey, + const krb5_keyblock * dbkey, + const krb5_keysalt * keysalt, + int keyver, + krb5_key_data * key_data); + +krb5_error_code +krb5_dbe_fetch_act_key_list(krb5_context context, + krb5_principal princ, + krb5_actkvno_node **act_key_list); + +krb5_error_code +krb5_dbe_find_act_mkey( krb5_context context, + krb5_actkvno_node * act_mkey_list, + krb5_kvno * act_kvno, + krb5_keyblock ** act_mkey); + +krb5_error_code +krb5_dbe_find_mkey( krb5_context context, + krb5_db_entry * entry, + krb5_keyblock ** mkey); + +/* Set *mkvno to mkvno in entry tl_data, or 0 if not present. */ +krb5_error_code +krb5_dbe_lookup_mkvno( krb5_context context, + krb5_db_entry * entry, + krb5_kvno * mkvno); + +krb5_keylist_node * +krb5_db_mkey_list_alias( krb5_context kcontext ); + +/* Set *mkvno to mkvno in entry tl_data, or minimum value from mkey_list. */ +krb5_error_code +krb5_dbe_get_mkvno( krb5_context context, + krb5_db_entry * entry, + krb5_kvno * mkvno); + +krb5_error_code +krb5_dbe_lookup_mod_princ_data( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp * mod_time, + krb5_principal * mod_princ); + +krb5_error_code +krb5_dbe_lookup_mkey_aux( krb5_context context, + krb5_db_entry * entry, + krb5_mkey_aux_node ** mkey_aux_data_list); +krb5_error_code +krb5_dbe_update_mkvno( krb5_context context, + krb5_db_entry * entry, + krb5_kvno mkvno); + +krb5_error_code +krb5_dbe_lookup_actkvno( krb5_context context, + krb5_db_entry * entry, + krb5_actkvno_node ** actkvno_list); + +krb5_error_code +krb5_dbe_update_mkey_aux( krb5_context context, + krb5_db_entry * entry, + krb5_mkey_aux_node * mkey_aux_data_list); + +krb5_error_code +krb5_dbe_update_actkvno(krb5_context context, + krb5_db_entry * entry, + const krb5_actkvno_node *actkvno_list); + +krb5_error_code +krb5_dbe_update_last_pwd_change( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp stamp); + +krb5_error_code +krb5_dbe_update_last_admin_unlock( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp stamp); + +krb5_error_code +krb5_dbe_lookup_tl_data( krb5_context context, + krb5_db_entry * entry, + krb5_tl_data * ret_tl_data); + +krb5_error_code +krb5_dbe_create_key_data( krb5_context context, + krb5_db_entry * entry); + + +krb5_error_code +krb5_dbe_update_mod_princ_data( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp mod_date, + krb5_const_principal mod_princ); + +/* + * These are wrappers around realloc() and free(). Applications and KDB + * modules can use them when manipulating principal and policy entries to + * ensure that they allocate and free memory in a manner compatible with the + * library. Using libkrb5 or libkbd5 functions to construct values (such as + * krb5_copy_principal() to construct the princ field of a krb5_db_entry) is + * also safe. On Unix platforms, just using malloc() and free() is safe as + * long as the application or module does not use a malloc replacement. + */ +void *krb5_db_alloc( krb5_context kcontext, + void *ptr, + size_t size ); +void krb5_db_free( krb5_context kcontext, + void *ptr); + + +krb5_error_code +krb5_dbe_lookup_last_pwd_change( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp * stamp); + +krb5_error_code +krb5_dbe_lookup_last_admin_unlock( krb5_context context, + krb5_db_entry * entry, + krb5_timestamp * stamp); + +/* Retrieve the set of string attributes in entry, in no particular order. + * Free *strings_out with krb5_dbe_free_strings when done. */ +krb5_error_code +krb5_dbe_get_strings(krb5_context context, krb5_db_entry *entry, + krb5_string_attr **strings_out, int *count_out); + +/* Retrieve a single string attribute from entry, or NULL if there is no + * attribute for key. Free *value_out with krb5_dbe_free_string when done. */ +krb5_error_code +krb5_dbe_get_string(krb5_context context, krb5_db_entry *entry, + const char *key, char **value_out); + +/* Change or add a string attribute in entry, or delete it if value is NULL. */ +krb5_error_code +krb5_dbe_set_string(krb5_context context, krb5_db_entry *entry, + const char *key, const char *value); + +krb5_error_code +krb5_dbe_delete_tl_data( krb5_context context, + krb5_db_entry * entry, + krb5_int16 tl_data_type); + +krb5_error_code +krb5_db_update_tl_data(krb5_context context, + krb5_int16 * n_tl_datap, + krb5_tl_data **tl_datap, + krb5_tl_data * new_tl_data); + +krb5_error_code +krb5_dbe_update_tl_data( krb5_context context, + krb5_db_entry * entry, + krb5_tl_data * new_tl_data); + +/* Compute the salt for a key data entry given the corresponding principal. */ +krb5_error_code +krb5_dbe_compute_salt(krb5_context context, const krb5_key_data *key, + krb5_const_principal princ, krb5_int16 *salttype_out, + krb5_data **salt_out); + +/* + * Modify the key data of entry to explicitly store salt values using the + * KRB5_KDB_SALTTYPE_SPECIAL salt type. + */ +krb5_error_code +krb5_dbe_specialize_salt(krb5_context context, krb5_db_entry *entry); + +krb5_error_code +krb5_dbe_cpw( krb5_context kcontext, + krb5_keyblock * master_key, + krb5_key_salt_tuple * ks_tuple, + int ks_tuple_count, + char * passwd, + int new_kvno, + krb5_boolean keepold, + krb5_db_entry * db_entry); + + +krb5_error_code +krb5_dbe_ark( krb5_context context, + krb5_keyblock * master_key, + krb5_key_salt_tuple * ks_tuple, + int ks_tuple_count, + krb5_db_entry * db_entry); + +krb5_error_code +krb5_dbe_crk( krb5_context context, + krb5_keyblock * master_key, + krb5_key_salt_tuple * ks_tuple, + int ks_tuple_count, + krb5_boolean keepold, + krb5_db_entry * db_entry); + +krb5_error_code +krb5_dbe_apw( krb5_context context, + krb5_keyblock * master_key, + krb5_key_salt_tuple * ks_tuple, + int ks_tuple_count, + char * passwd, + krb5_db_entry * db_entry); + +int +krb5_db_get_key_data_kvno( krb5_context context, + int count, + krb5_key_data * data); + +krb5_error_code krb5_db_sign_authdata(krb5_context kcontext, + unsigned int flags, + krb5_const_principal client_princ, + krb5_db_entry *client, + krb5_db_entry *server, + krb5_db_entry *krbtgt, + krb5_keyblock *client_key, + krb5_keyblock *server_key, + krb5_keyblock *krbtgt_key, + krb5_keyblock *session_key, + krb5_timestamp authtime, + krb5_authdata **tgt_auth_data, + krb5_authdata ***signed_auth_data); + +krb5_error_code krb5_db_check_transited_realms(krb5_context kcontext, + const krb5_data *tr_contents, + const krb5_data *client_realm, + const krb5_data *server_realm); + +krb5_error_code krb5_db_check_policy_as(krb5_context kcontext, + krb5_kdc_req *request, + krb5_db_entry *client, + krb5_db_entry *server, + krb5_timestamp kdc_time, + const char **status, + krb5_pa_data ***e_data); + +krb5_error_code krb5_db_check_policy_tgs(krb5_context kcontext, + krb5_kdc_req *request, + krb5_db_entry *server, + krb5_ticket *ticket, + const char **status, + krb5_pa_data ***e_data); + +void krb5_db_audit_as_req(krb5_context kcontext, krb5_kdc_req *request, + const krb5_address *local_addr, + const krb5_address *remote_addr, + krb5_db_entry *client, krb5_db_entry *server, + krb5_timestamp authtime, krb5_error_code error_code); + +void krb5_db_refresh_config(krb5_context kcontext); + +krb5_error_code krb5_db_check_allowed_to_delegate(krb5_context kcontext, + krb5_const_principal client, + const krb5_db_entry *server, + krb5_const_principal proxy); + +/** + * Sort an array of @a krb5_key_data keys in descending order by their kvno. + * Key data order within a kvno is preserved. + * + * @param key_data + * The @a krb5_key_data array to sort. This is sorted in place so the + * array will be modified. + * @param key_data_length + * The length of @a key_data. + */ +void +krb5_dbe_sort_key_data(krb5_key_data *key_data, size_t key_data_length); + +/* default functions. Should not be directly called */ +/* + * Default functions prototype + */ + +krb5_error_code +krb5_dbe_def_search_enctype( krb5_context kcontext, + krb5_db_entry *dbentp, + krb5_int32 *start, + krb5_int32 ktype, + krb5_int32 stype, + krb5_int32 kvno, + krb5_key_data **kdatap); + +krb5_error_code +krb5_def_store_mkey_list( krb5_context context, + char *keyfile, + krb5_principal mname, + krb5_keylist_node *keylist, + char *master_pwd); + +krb5_error_code +krb5_db_def_fetch_mkey( krb5_context context, + krb5_principal mname, + krb5_keyblock *key, + krb5_kvno *kvno, + char *db_args); + +krb5_error_code +krb5_def_fetch_mkey_list( krb5_context context, + krb5_principal mprinc, + const krb5_keyblock *mkey, + krb5_keylist_node **mkeys_list); + +krb5_error_code +krb5_dbe_def_cpw( krb5_context context, + krb5_keyblock * master_key, + krb5_key_salt_tuple * ks_tuple, + int ks_tuple_count, + char * passwd, + int new_kvno, + krb5_boolean keepold, + krb5_db_entry * db_entry); + +krb5_error_code +krb5_dbe_def_decrypt_key_data( krb5_context context, + const krb5_keyblock * mkey, + const krb5_key_data * key_data, + krb5_keyblock * dbkey, + krb5_keysalt * keysalt); + +krb5_error_code +krb5_dbe_def_encrypt_key_data( krb5_context context, + const krb5_keyblock * mkey, + const krb5_keyblock * dbkey, + const krb5_keysalt * keysalt, + int keyver, + krb5_key_data * key_data); + +krb5_error_code +krb5_db_def_rename_principal( krb5_context kcontext, + krb5_const_principal source, + krb5_const_principal target); + +krb5_error_code +krb5_db_create_policy( krb5_context kcontext, + osa_policy_ent_t policy); + +krb5_error_code +krb5_db_get_policy ( krb5_context kcontext, + char *name, + osa_policy_ent_t *policy ); + +krb5_error_code +krb5_db_put_policy( krb5_context kcontext, + osa_policy_ent_t policy); + +krb5_error_code +krb5_db_iter_policy( krb5_context kcontext, + char *match_entry, + osa_adb_iter_policy_func func, + void *data); + +krb5_error_code +krb5_db_delete_policy( krb5_context kcontext, + char *policy); + +void +krb5_db_free_policy( krb5_context kcontext, + osa_policy_ent_t policy); + + +krb5_error_code +krb5_db_set_context(krb5_context, void *db_context); + +krb5_error_code +krb5_db_get_context(krb5_context, void **db_context); + +void +krb5_dbe_free_key_data_contents(krb5_context, krb5_key_data *); + +void +krb5_dbe_free_key_list(krb5_context, krb5_keylist_node *); + +void +krb5_dbe_free_actkvno_list(krb5_context, krb5_actkvno_node *); + +void +krb5_dbe_free_mkey_aux_list(krb5_context, krb5_mkey_aux_node *); + +void +krb5_dbe_free_tl_data(krb5_context, krb5_tl_data *); + +void +krb5_dbe_free_strings(krb5_context, krb5_string_attr *, int count); + +void +krb5_dbe_free_string(krb5_context, char *); + +/* + * Register the KDB keytab type, allowing "KDB:" to be used as a keytab name. + * For this type to work, the context used for keytab operations must have an + * associated database handle (via krb5_db_open()). + */ +krb5_error_code krb5_db_register_keytab(krb5_context context); + +#define KRB5_KDB_DEF_FLAGS 0 + +#define KDB_MAX_DB_NAME 128 +#define KDB_REALM_SECTION "realms" +#define KDB_MODULE_POINTER "database_module" +#define KDB_MODULE_DEF_SECTION "dbdefaults" +#define KDB_MODULE_SECTION "dbmodules" +#define KDB_LIB_POINTER "db_library" +#define KDB_DATABASE_CONF_FILE DEFAULT_SECURE_PROFILE_PATH +#define KDB_DATABASE_ENV_PROF KDC_PROFILE_ENV + +#define KRB5_KDB_OPEN_RW 0 +#define KRB5_KDB_OPEN_RO 1 + +#define KRB5_KDB_OPT_SET_DB_NAME 0 +#define KRB5_KDB_OPT_SET_LOCK_MODE 1 + +/* + * This number indicates the date of the last incompatible change to the DAL. + * The maj_ver field of the module's vtable structure must match this version. + */ +#define KRB5_KDB_DAL_MAJOR_VERSION 7 + +/* + * A krb5_context can hold one database object. Modules should use + * krb5_db_set_context and krb5_db_get_context to store state associated with + * the database object. + * + * Some module functions are mandatory for KDC operation; others are optional + * or apply only to administrative operations. If a function is optional, a + * module can leave the function pointer as NULL. Alternatively, modules can + * return KRB5_PLUGIN_OP_NOTSUPP when asked to perform an inapplicable action. + * + * Some module functions have default implementations which will call back into + * the vtable interface. Leave these functions as NULL to use the default + * implementations. + * + * The documentation in these comments describes the DAL as it is currently + * implemented and used, not as it should be. So if anything seems off, that + * probably means the current state of things is off. + * + * Modules must allocate memory for principal entries, policy entries, and + * other structures using an allocator compatible with malloc() as seen by + * libkdb5 and libkrb5. Modules may link against libkdb5 and call + * krb5_db_alloc() to be certain that the same malloc implementation is used. + */ + +typedef struct _kdb_vftabl { + short int maj_ver; + short int min_ver; + + /* + * Mandatory: Invoked after the module library is loaded, when the first DB + * using the module is opened, across all contexts. + */ + krb5_error_code (*init_library)(void); + + /* + * Mandatory: Invoked before the module library is unloaded, after the last + * DB using the module is closed, across all contexts. + */ + krb5_error_code (*fini_library)(void); + + /* + * Mandatory: Initialize a database object. Profile settings should be + * read from conf_section inside KDB_MODULE_SECTION. db_args communicates + * command-line arguments for module-specific flags. mode will be one of + * KRB5_KDB_OPEN_{RW,RO} or'd with one of + * KRB5_KDB_SRV_TYPE_{KDC,ADMIN,PASSWD,OTHER}. + */ + krb5_error_code (*init_module)(krb5_context kcontext, char *conf_section, + char **db_args, int mode); + + /* + * Mandatory: Finalize the database object contained in a context. Free + * any state contained in the db_context pointer and null it out. + */ + krb5_error_code (*fini_module)(krb5_context kcontext); + + /* + * Optional: Initialize a database object while creating the underlying + * database. conf_section and db_args have the same meaning as in + * init_module. This function may return an error if the database already + * exists. Used by kdb5_util create. + * + * If db_args contains the value "temporary", the module should create an + * exclusively locked side copy of the database suitable for loading in a + * propagation from master to replica. This side copy will later be + * promoted with promote_db, allowing complete updates of the DB with no + * loss in read availability. If the module cannot comply with this + * architecture, it should return an error. + */ + krb5_error_code (*create)(krb5_context kcontext, char *conf_section, + char **db_args); + + /* + * Optional: Destroy a database. conf_section and db_args have the same + * meaning as in init_module. Used by kdb5_util destroy. In current + * usage, the database is destroyed while open, so the module should handle + * that. + */ + krb5_error_code (*destroy)(krb5_context kcontext, char *conf_section, + char **db_args); + + /* + * Deprecated: No longer used as of krb5 1.10; can be removed in the next + * DAL revision. Modules should leave as NULL. + */ + krb5_error_code (*get_age)(krb5_context kcontext, char *db_name, + time_t *age); + + /* + * Optional: Lock the database, with semantics depending on the mode + * argument: + * + * KRB5_DB_LOCKMODE_SHARED: Lock may coexist with other shared locks. + * KRB5_DB_LOCKMODE_EXCLUSIVE: Lock may not coexist with other locks. + * KRB5_DB_LOCKMODE_PERMANENT: Exclusive lock surviving process exit. + * + * Used by the "kadmin lock" command, incremental propagation, and + * kdb5_util dump. Incremental propagation support requires shared locks + * to operate. kdb5_util dump will continue unlocked if the module returns + * KRB5_PLUGIN_OP_NOTSUPP. + */ + krb5_error_code (*lock)(krb5_context kcontext, int mode); + + /* Optional: Release a lock created with db_lock. */ + krb5_error_code (*unlock)(krb5_context kcontext); + + /* + * Mandatory: Set *entry to an allocated entry for the principal + * search_for. If the principal is not found, return KRB5_KDB_NOENTRY. + * + * The meaning of flags are as follows: + * + * KRB5_KDB_FLAG_CANONICALIZE: Set by the KDC when looking up entries for + * an AS or TGS request with canonicalization requested. Determines + * whether the module should return out-of-realm referrals. + * + * KRB5_KDB_FLAG_INCLUDE_PAC: Set by the KDC during an AS request when the + * client requested PAC information during padata, and during most TGS + * requests. Indicates that the module should include PAC information + * when its sign_authdata method is invoked. + * + * KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY: Set by the KDC when looking up the + * client entry in an AS request. Affects how the module should return + * out-of-realm referrals. + * + * KRB5_KDB_FLAG_MAP_PRINCIPALS: Set by the KDC when looking up the client + * entry during TGS requests, except for S4U TGS requests and requests + * where the server entry has the KRB5_KDB_NO_AUTH_DATA_REQUIRED + * attribute. Indicates that the module should map foreign principals + * to local principals if it supports doing so. + * + * KRB5_KDB_FLAG_PROTOCOL_TRANSITION: Set by the KDC when looking up the + * client entry during an S4U2Self TGS request. This affects the PAC + * information which should be included when authorization data is + * generated; see the Microsoft S4U specification for details. + * + * KRB5_KDB_FLAG_CONSTRAINED_DELEGATION: Set by the KDC when looking up the + * client entry during an S4U2Proxy TGS request. Also affects PAC + * generation. + * + * KRB5_KDB_FLAG_CROSS_REALM: Set by the KDC when looking up a client entry + * during a TGS request, if the client principal is not part of the + * realm being served. + * + * KRB5_KDB_FLAG_ALIAS_OK: Set by the KDC for server principal lookups and + * for AS request client principal lookups with canonicalization + * requested; also set by the admin interface. Determines whether the + * module should return in-realm aliases. + * + * A module can return in-realm aliases if KRB5_KDB_FLAG_ALIAS_OK is set, + * or if search_for->type is KRB5_NT_ENTERPRISE_PRINCIPAL. To return an + * in-realm alias, fill in a different value for entries->princ than the + * one requested. + * + * A module can return out-of-realm referrals if KRB5_KDB_FLAG_CANONICALIZE + * is set. For AS request clients (KRB5_KDB_FLAG_CLIENT_REFERRALS_ONLY is + * also set), the module should do so by simply filling in an out-of-realm + * name in entries->princ and setting all other fields to NULL. Otherwise, + * the module should return the entry for the cross-realm TGS of the + * referred-to realm. For TGS referals, the module can also include + * tl-data of type KRB5_TL_SERVER_REFERRAL containing ASN.1-encoded Windows + * referral data as documented in draft-ietf-krb-wg-kerberos-referrals-11 + * appendix A; this will be returned to the client as encrypted padata. + */ + krb5_error_code (*get_principal)(krb5_context kcontext, + krb5_const_principal search_for, + unsigned int flags, + krb5_db_entry **entry); + + /* + * Optional: Create or modify a principal entry. db_args communicates + * command-line arguments for module-specific flags. + * + * The mask field of an entry indicates the changed fields. Mask values + * are defined in kadmin's admin.h header. If KADM5_PRINCIPAL is set in + * the mask, the entry is new; otherwise it already exists. All fields of + * an entry are expected to contain correct values, regardless of whether + * they are specified in the mask, so it is acceptable for a module to + * ignore the mask and update the entire entry. + */ + krb5_error_code (*put_principal)(krb5_context kcontext, + krb5_db_entry *entry, char **db_args); + + /* + * Optional: Delete the entry for the principal search_for. If the + * principal did not exist, return KRB5_KDB_NOENTRY. + */ + krb5_error_code (*delete_principal)(krb5_context kcontext, + krb5_const_principal search_for); + + /* + * Optional with default: Rename a principal. If the source principal does + * not exist, return KRB5_KDB_NOENTRY. If the target exists, return an + * error. + * + * NOTE: If the module chooses to implement a custom function for renaming + * a principal instead of using the default, then rename operations will + * fail if iprop logging is enabled. + */ + krb5_error_code (*rename_principal)(krb5_context kcontext, + krb5_const_principal source, + krb5_const_principal target); + + /* + * Optional: For each principal entry in the database, invoke func with the + * argments func_arg and the entry data. If match_entry is specified, the + * module may narrow the iteration to principal names matching that regular + * expression; a module may alternatively ignore match_entry. + */ + krb5_error_code (*iterate)(krb5_context kcontext, + char *match_entry, + int (*func)(krb5_pointer, krb5_db_entry *), + krb5_pointer func_arg, krb5_flags iterflags); + + /* + * Optional: Create a password policy entry. Return an error if the policy + * already exists. + */ + krb5_error_code (*create_policy)(krb5_context kcontext, + osa_policy_ent_t policy); + + /* + * Optional: Set *policy to the policy entry of the specified name. If the + * entry does not exist, return KRB5_KDB_NOENTRY. + */ + krb5_error_code (*get_policy)(krb5_context kcontext, char *name, + osa_policy_ent_t *policy); + + /* + * Optional: Modify an existing password policy entry to match the values + * in policy. Return an error if the policy does not already exist. + */ + krb5_error_code (*put_policy)(krb5_context kcontext, + osa_policy_ent_t policy); + + /* + * Optional: For each password policy entry in the database, invoke func + * with the argments data and the entry data. If match_entry is specified, + * the module may narrow the iteration to policy names matching that + * regular expression; a module may alternatively ignore match_entry. + */ + krb5_error_code (*iter_policy)(krb5_context kcontext, char *match_entry, + osa_adb_iter_policy_func func, + void *data); + + /* + * Optional: Delete the password policy entry with the name policy. Return + * an error if the entry does not exist. + */ + krb5_error_code (*delete_policy)(krb5_context kcontext, char *policy); + + /* + * Optional with default: Retrieve a master keyblock from the stash file + * db_args, filling in *key and *kvno. mname is the name of the master + * principal for the realm. + * + * The default implementation reads the master keyblock from a keytab or + * old-format stash file. + */ + krb5_error_code (*fetch_master_key)(krb5_context kcontext, + krb5_principal mname, + krb5_keyblock *key, krb5_kvno *kvno, + char *db_args); + + /* + * Optional with default: Given a keyblock for some version of the + * database's master key, fetch the decrypted master key values from the + * database and store the list into *mkeys_list. The caller will free + * *mkeys_list using a libkdb5 function which uses the standard free() + * function, so the module must not use a custom allocator. + * + * The caller may not know the version number of the master key it has, in + * which case it will pass IGNORE_VNO. + * + * The default implementation ignores kvno and tries the key against the + * current master key data and all KRB5_TL_MKEY_AUX values, which contain + * copies of the master keys encrypted with old master keys. + */ + krb5_error_code (*fetch_master_key_list)(krb5_context kcontext, + krb5_principal mname, + const krb5_keyblock *key, + krb5_keylist_node **mkeys_list); + + /* + * Optional with default: Save a list of master keyblocks, obtained from + * fetch_master_key_list, into the stash file db_arg. The caller will set + * master_pwd to NULL, so the module should just ignore it. mname is the + * name of the master principal for the realm. + * + * The default implementation saves the list of master keys in a + * keytab-format file. + */ + krb5_error_code (*store_master_key_list)(krb5_context kcontext, + char *db_arg, + krb5_principal mname, + krb5_keylist_node *keylist, + char *master_pwd); + + /* + * Optional with default: Starting at position *start, scan the key data of + * a database entry for a key matching the enctype ktype, the salt type + * stype, and the version kvno. Store the resulting key into *kdatap and + * set *start to the position after the key found. If ktype is negative, + * match any enctype. If stype is negative, match any salt type. If kvno + * is zero or negative, find the most recent key version satisfying the + * other constraints. + */ + krb5_error_code (*dbe_search_enctype)(krb5_context kcontext, + krb5_db_entry *dbentp, + krb5_int32 *start, krb5_int32 ktype, + krb5_int32 stype, krb5_int32 kvno, + krb5_key_data **kdatap); + + + /* + * Optional with default: Change the key data for db_entry to include keys + * derived from the password passwd in each of the specified key-salt + * types, at version new_kvno. Discard the old key data if keepold is not + * set. + * + * The default implementation uses the keyblock master_key to encrypt each + * new key, via the function encrypt_key_data. + */ + krb5_error_code (*change_pwd)(krb5_context context, + krb5_keyblock *master_key, + krb5_key_salt_tuple *ks_tuple, + int ks_tuple_count, char *passwd, + int new_kvno, krb5_boolean keepold, + krb5_db_entry *db_entry); + + /* + * Optional: Promote a temporary database to be the live one. context must + * be initialized with an exclusively locked database created with the + * "temporary" db_arg. On success, the database object contained in + * context will be finalized. + * + * This method is used by kdb5_util load to replace the live database with + * minimal loss of read availability. + */ + krb5_error_code (*promote_db)(krb5_context context, char *conf_section, + char **db_args); + + /* + * Optional with default: Decrypt the key in key_data with master keyblock + * mkey, placing the result into dbkey. Copy the salt from key_data, if + * any, into keysalt. Either dbkey or keysalt may be left unmodified on + * successful return if key_data does not contain key or salt information. + * + * The default implementation expects the encrypted key (in krb5_c_encrypt + * format) to be stored in key_data_contents[0], with length given by + * key_data_length[0]. If key_data_ver is 2, it expects the salt to be + * stored, unencrypted, in key_data_contents[1], with length given by + * key_data_length[1]. + */ + krb5_error_code (*decrypt_key_data)(krb5_context kcontext, + const krb5_keyblock *mkey, + const krb5_key_data *key_data, + krb5_keyblock *dbkey, + krb5_keysalt *keysalt); + + /* + * Optional with default: Encrypt dbkey with master keyblock mkey, placing + * the result into key_data along with keysalt. + * + * The default implementation stores the encrypted key (in krb5_c_encrypt + * format) in key_data_contents[0] and the length in key_data_length[0]. + * If keysalt is specified, it sets key_data_ver to 2, and stores the salt + * in key_data_contents[1] and its length in key_data_length[1]. If + * keysalt is not specified, key_data_ver is set to 1. + */ + krb5_error_code (*encrypt_key_data)(krb5_context kcontext, + const krb5_keyblock *mkey, + const krb5_keyblock *dbkey, + const krb5_keysalt *keysalt, + int keyver, krb5_key_data *key_data); + + /* + * Optional: Generate signed authorization data, such as a Windows PAC, for + * the ticket to be returned to the client. Place the signed authorization + * data, if any, in *signed_auth_data. This function will be invoked for + * an AS request if the client included padata requesting a PAC. This + * function will be invoked for a TGS request if there is authorization + * data in the TGT, if the client is from another realm, or if the TGS + * request is an S4U2Self or S4U2Proxy request. This function will not be + * invoked during TGS requests if the server principal has the + * no_auth_data_required attribute set. Input parameters are: + * + * flags: The flags used to look up the client principal. + * + * client_princ: For S4U2Self and S4U2Proxy TGS requests, the client + * principal requested by the service; for regular TGS requests, the + * possibly-canonicalized client principal. + * + * client: The DB entry of the client. For S4U2Self, this will be the DB + * entry for the client principal requested by the service). + * + * server: The DB entry of the service principal, or of a cross-realm + * krbtgt principal in case of referral. + * + * krbtgt: For TGS requests, the DB entry of the server of the ticket in + * the PA-TGS-REQ padata; this is usually a local or cross-realm krbtgt + * principal, but not always. For AS requests, the DB entry of the + * service principal; this is usually a local krbtgt principal, but not + * always. + * + * client_key: The reply key for the KDC request, before any FAST armor + * is applied. For AS requests, this may be the client's long-term key + * or a key chosen by a preauth mechanism. For TGS requests, this may + * be the subkey found in the AP-REQ or the session key of the TGT. + * + * server_key: The server key used to encrypt the returned ticket. + * + * krbtgt_key: For TGS requests, the key used to decrypt the ticket in + * the PA-TGS-REQ padata. For AS requests, the server key used to + * encrypt the returned ticket. + * + * session_key: The session key of the ticket being granted to the + * requestor. + * + * authtime: The timestamp of the original client authentication time. + * For AS requests, this is the current time. For TGS requests, this + * is the authtime of the subject ticket (TGT or S4U2Proxy evidence + * ticket). + * + * tgt_auth_data: For TGS requests, the authorization data present in the + * subject ticket. For AS requests, NULL. + */ + krb5_error_code (*sign_authdata)(krb5_context kcontext, + unsigned int flags, + krb5_const_principal client_princ, + krb5_db_entry *client, + krb5_db_entry *server, + krb5_db_entry *krbtgt, + krb5_keyblock *client_key, + krb5_keyblock *server_key, + krb5_keyblock *krbtgt_key, + krb5_keyblock *session_key, + krb5_timestamp authtime, + krb5_authdata **tgt_auth_data, + krb5_authdata ***signed_auth_data); + + /* + * Optional: Perform a policy check on a cross-realm ticket's transited + * field. Return 0 if the check authoritatively succeeds, + * KRB5_PLUGIN_NO_HANDLE to use the core transited-checking mechanisms, or + * another error (other than KRB5_PLUGIN_OP_NOTSUPP) if the check fails. + */ + krb5_error_code (*check_transited_realms)(krb5_context kcontext, + const krb5_data *tr_contents, + const krb5_data *client_realm, + const krb5_data *server_realm); + + /* + * Optional: Perform a policy check on an AS request, in addition to the + * standard policy checks. Return 0 if the AS request is allowed. If the + * AS request is not allowed: + * - Place a short string literal into *status. + * - If desired, place data into e_data. Any data placed here will be + * freed by the caller using the standard free function. + * - Return an appropriate error (such as KRB5KDC_ERR_POLICY). + */ + krb5_error_code (*check_policy_as)(krb5_context kcontext, + krb5_kdc_req *request, + krb5_db_entry *client, + krb5_db_entry *server, + krb5_timestamp kdc_time, + const char **status, + krb5_pa_data ***e_data); + + /* + * Optional: Perform a policy check on a TGS request, in addition to the + * standard policy checks. Return 0 if the TGS request is allowed. If the + * TGS request is not allowed: + * - Place a short string literal into *status. + * - If desired, place data into e_data. Any data placed here will be + * freed by the caller using the standard free function. + * - Return an appropriate error (such as KRB5KDC_ERR_POLICY). + * The input parameter ticket contains the TGT used in the TGS request. + */ + krb5_error_code (*check_policy_tgs)(krb5_context kcontext, + krb5_kdc_req *request, + krb5_db_entry *server, + krb5_ticket *ticket, + const char **status, + krb5_pa_data ***e_data); + + /* + * Optional: This method informs the module of a successful or unsuccessful + * AS request. + */ + void (*audit_as_req)(krb5_context kcontext, krb5_kdc_req *request, + const krb5_address *local_addr, + const krb5_address *remote_addr, + krb5_db_entry *client, krb5_db_entry *server, + krb5_timestamp authtime, krb5_error_code error_code); + + /* Note: there is currently no method for auditing TGS requests. */ + + /* + * Optional: This method informs the module of a request to reload + * configuration or other state (that is, the KDC received a SIGHUP). + */ + void (*refresh_config)(krb5_context kcontext); + + /* + * Optional: Perform a policy check on server being allowed to obtain + * tickets from client to proxy. (Note that proxy is the target of the + * delegation, not the delegating service; the term "proxy" is from the + * viewpoint of the delegating service asking another service to perform + * some of its work in the authentication context of the client. This + * terminology comes from the Microsoft S4U protocol documentation.) + * Return 0 if policy allows it, or an appropriate error (such as + * KRB5KDC_ERR_POLICY) if not. If this method is not implemented, all + * S4U2Proxy delegation requests will be rejected. + */ + krb5_error_code (*check_allowed_to_delegate)(krb5_context context, + krb5_const_principal client, + const krb5_db_entry *server, + krb5_const_principal proxy); + + /* End of minor version 0. */ + + /* + * Optional: Free the e_data pointer of a database entry. If this method + * is not implemented, the e_data pointer in principal entries will be + * freed with free() as seen by libkdb5. + */ + void (*free_principal_e_data)(krb5_context kcontext, krb5_octet *e_data); + + /* End of minor version 1 for major version 6. */ +} kdb_vftabl; + +#endif /* !defined(_WIN32) */ + +#endif /* KRB5_KDB5__ */ diff -uprN postgresql-hll-2.14_old/include/include/keymanagement/FIKMSmessage.h postgresql-hll-2.14/include/include/keymanagement/FIKMSmessage.h --- postgresql-hll-2.14_old/include/include/keymanagement/FIKMSmessage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/keymanagement/FIKMSmessage.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * FIKMSmessage.h + * Processing of messages defined by FI KMS + * + * + * IDENTIFICATION + * src/include/keymanagement/FIKMSmessage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_FIKMSMESSAGE_H +#define SEC_KEY_FIKMSMESSAGE_H + +#include "cjson/cJSON.h" +#include + +/* The following values are defined by the RESTful interface of FI KMS */ +const char* const FIKMS_MESSAGE_name = "name"; +const char* const FIKMS_MESSAGE_cipher = "cipher"; +const char* const FIKMS_MESSAGE_length = "length"; +const char* const FIKMS_MESSAGE_material = "material"; +const char* const FIKMS_MESSAGE_number_of_keys_to_generate = "number_of_keys_to_generate"; +const char* const FIKMS_MESSAGE_key_name = "key-name"; +const char* const FIKMS_MESSAGE_versionname = "versionName"; +const char* const FIKMS_MESSAGE_iv = "iv"; +const char* const FIKMS_MESSAGE_encryptedKeyVersion = "encryptedKeyVersion"; +const char* const FIKMS_MESSAGE_exception = "RemoteException"; + +/* This class is used for FI KMS protocol parsing. */ +class FIKMSmessage { +public: + FIKMSmessage(); + ~FIKMSmessage(); + + /* Parsing JSON structure from string. */ + bool parser(std::string serizial_str); + + /* Use name, cipher, length to assemble the message needed by FI KMS.Returns the result of serialization of JSON + * information.*/ + std::string create(std::string name, std::string cipher, int length); + /* Use name, iv, material to assemble the message needed by FI KMS.Returns the result of serialization of JSON + * information.*/ + std::string create(std::string name, std::string iv, std::string material); + + /* Parsing Create CEK Messages. */ + bool parser_create_CEK(std::string& CEK_name); + /* Parsing Create DEK Messages. */ + bool parser_create_DEK(std::string& DEK_IV, std::string& DEK_cipher, std::string& CEK_versionname); + + /* Parsing gte DEK Messages. */ + bool parser_get_DEK(std::string& DEK); + /* Parsing get CEK Messages. */ + bool parser_get_CEK(const std::string& CEK_name); + +private: + cJSON* response_data; + bool is_exception(); +}; + +#endif // SEC_KEY_FIKMSMESSAGE_H diff -uprN postgresql-hll-2.14_old/include/include/keymanagement/HttpRestfulClient.h postgresql-hll-2.14/include/include/keymanagement/HttpRestfulClient.h --- postgresql-hll-2.14_old/include/include/keymanagement/HttpRestfulClient.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/keymanagement/HttpRestfulClient.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * HttpRestfulClient.h + * Implementation of Exchanging Data with FI KMS Restful API + * + * + * IDENTIFICATION + * src/include/keymanagement/HttpRestfulClient.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_HTTPRESTFULCLIENT_H +#define SEC_KEY_HTTPRESTFULCLIENT_H + +#include +#include +#include + +/* + * This class is used to complete the network connection and realize the transmission and reception of network data. + * Support GSS-Negotiate authentication. + */ +class HttpRestfulClient { +public: + HttpRestfulClient(); + ~HttpRestfulClient(); + std::string post(const char* res, const char* data, const long length); + std::string get(const char* res); + +private: + std::string host; + std::string port; + std::string http_protocol; + std::vector hosts; + bool is_ReportAlarmAbnormalKMSConnt; + CURL* curl; + CURLcode response_code; + struct curl_slist* headers; + + bool send(); + void update_kms_url(); +}; + +#endif // SEC_KEY_HTTPRESTFULCLIENT_H diff -uprN postgresql-hll-2.14_old/include/include/keymanagement/KeyManager.h postgresql-hll-2.14/include/include/keymanagement/KeyManager.h --- postgresql-hll-2.14_old/include/include/keymanagement/KeyManager.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/keymanagement/KeyManager.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,73 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * KeyManager.h + * TDE key management is the external interface of key management + * + * + * IDENTIFICATION + * src/include/keymanagement/KeyManager.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_KEYMANAGER_H +#define SEC_KEY_KEYMANAGER_H + +#include "TDEKeysFile.h" +enum TDE_KEY_STATUS { + CEK_NONE, + CEK_ERROR, + CEK_CREATED, + DEK_NONE, + DEK_ERROR, + DEK_CREATED, + DEK_IV_NONE, + DEK_IV_ERROR, + DEK_IV_CREATED, + KEY_NOT_INIT, + KEY_INITED +}; + +/* This class is used for key management */ +class KeyManager : public TDEKeysFile { +public: + KeyManager(const char* db_uid_in, const char* tb_uid_in); + virtual ~KeyManager(); + /* + * Initialization of key environment based on key algorithm and CEK key name. + * the algo and cekname come form user. + */ + bool init_Key(const char* algo, const char* cekname); + /* use default value init key environment.*/ + bool init_Key(); + + /* Checking whether DEK is correct will be judged by the saved encrypted_sample_string. */ + bool check_key(unsigned char* dek); + + std::string getDEK(); + TDE_KEY_STATUS getKey_status() const; + +private: + TDE_KEY_STATUS Key_status; + + bool createCEK(); + bool createDEK(); + + bool fill_Disk(); + bool read_Disk(); +}; + +#endif // SEC_KEY_KEYMANAGER_H diff -uprN postgresql-hll-2.14_old/include/include/keymanagement/KeyRecord.h postgresql-hll-2.14/include/include/keymanagement/KeyRecord.h --- postgresql-hll-2.14_old/include/include/keymanagement/KeyRecord.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/keymanagement/KeyRecord.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * KeyRecord.h + * encrypt and decrypt functions for MPPDB + * + * + * IDENTIFICATION + * src/include/keymanagement/KeyRecord.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_KEYRECORD_H +#define SEC_KEY_KEYRECORD_H + +#include + +const int TDE_IV_LEN = 16; + +enum TDE_ALGO { TDE_ALGO_SM4_CTR_128, TDE_ALGO_AES_CTR_128, TDE_ALGO_NULL }; + +class KeyRecord { + +public: + KeyRecord(); + virtual ~KeyRecord() = default; + + bool create_encrypted_sample_string(std::string dek_b64); + bool check_encrypted_sample_string(unsigned char* dek); + std::string getEncryptedSampleStr(); + + bool create_dek_iv(); + bool getIV(unsigned char* out_iv); + + TDE_ALGO get_tde_algo() const; + +protected: + std::string cek_name; + std::string cek_version; + std::string cek_IV; + std::string dek_cipher; + std::string db_uid; + std::string tb_uid; + std::string encrypted_sample_string; + unsigned char dek_iv[TDE_IV_LEN] = {}; + TDE_ALGO tde_algo; +}; + +#endif // SEC_KEY_KEYRECORD_H diff -uprN postgresql-hll-2.14_old/include/include/keymanagement/TDEKeysFile.h postgresql-hll-2.14/include/include/keymanagement/TDEKeysFile.h --- postgresql-hll-2.14_old/include/include/keymanagement/TDEKeysFile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/keymanagement/TDEKeysFile.h 2020-12-12 17:06:43.212347587 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * TDEKeysFile.h + * encrypt and decrypt functions for MPPDB + * + * + * IDENTIFICATION + * src/include/keymanagement/TDEKeysFile.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_TDEKEYSFILE_H +#define SEC_KEY_TDEKEYSFILE_H + +#include "KeyRecord.h" +#include + +#define TDE_KEYS_STORE_NAME "gs_tde_keys.cipher" + +class TDEKeysFile : public KeyRecord { +public: + TDEKeysFile(); + virtual ~TDEKeysFile(); + void setfile(const char* gausshome); + bool existed() const; + bool save(); + bool parser(); + void clear(); + +private: + std::string tde_keys_store_path; +}; + +#endif // SEC_KEY_TDEKEYSFILE_H diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_guc_common.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_guc_common.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_guc_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_guc_common.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_guc_common.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_guc_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ + +#include "c.h" + +/* Configuration variables */ +#define MAX_GTM_HOST_NUM (8) +#ifdef ENABLE_MULTIPLE_NODES +#define GUC_MAX_REPLNODE_NUM (8) +#else +#define GUC_MAX_REPLNODE_NUM (9) +#endif + +#ifdef WIN32 +typedef unsigned __int64 GS_UINT64; +#else +typedef unsigned long long GS_UINT64; +#endif + +#if defined(__LP64__) || defined(__64BIT__) +typedef unsigned int GS_UINT32; + +typedef signed int GS_INT32; +#else +typedef unsigned long GS_UINT32; + +typedef signed long GS_INT32; +#endif + +typedef unsigned char GS_UCHAR; + +const int GTMOPTION_GTM = 0; +const int GTMOPTION_GTMLITE = 1; +const int GTMOPTION_GTMFREE = 2; +const int GTM_OLD_VERSION_NUM = 92061; +const int SLOW_QUERY_VERSION = 92089; +const int STATEMENT_TRACK_VERSION = 92277; +#endif /* SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_common.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_common.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_common.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,99 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_common.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_common { + bool support_extended_features; + bool lastval_supported; +#ifdef USE_BONJOUR + bool enable_bonjour; +#endif + bool Logging_collector; + bool allowSystemTableMods; + bool enable_thread_pool; + bool enable_global_plancache; + int max_files_per_process; + int pgstat_track_activity_query_size; + int GtmHostPortArray[MAX_GTM_HOST_NUM]; + int MaxDataNodes; + int max_changes_in_memory; + int max_cached_tuplebufs; +#ifdef USE_BONJOUR + char* bonjour_name; +#endif + char* shared_preload_libraries_string; + char* event_source; + char* data_directory; + char* ConfigFileName; + char* HbaFileName; + char* IdentFileName; + char* external_pid_file; + char* PGXCNodeName; + char* transparent_encrypt_kms_url; + char* thread_pool_attr; + char* numa_distribute_mode; + + bool data_sync_retry; + + bool enable_alarm; + char* Alarm_component; + bool enable_tsdb; + char* Perf_directory; + char* asp_log_directory; + char* query_log_directory; + int asp_sample_num; + + /* + * guc - bbox_blacklist_items + * char* : original value + * uint64 : parsed bits mask + */ + char* bbox_blacklist_items; + uint64 bbox_blacklist_mask; +#ifdef ENABLE_MOT + char* MOTConfigFileName; +#endif +#ifndef ENABLE_MULTIPLE_NODES + int config_sync_interval; +#endif +} knl_instance_attr_common; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_memory.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_memory.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_memory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_memory.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_memory.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_memory.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_memory { + bool memorypool_enable; + bool enable_memory_limit; + int memorypool_size; + int max_process_memory; + int local_syscache_threshold; +} knl_instance_attr_memory; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_network.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_network.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_network.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_network.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_network.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_network { + bool PoolerStatelessReuse; + bool comm_tcp_mode; + int MaxConnections; + int maxInnerToolConnections; + int ReservedBackends; + int PostPortNumber; + int Unix_socket_permissions; + int MaxPoolSize; + int PoolerPort; + int MaxCoords; + int comm_sctp_port; + int comm_control_port; + int comm_quota_size; + int comm_usable_memory; + int comm_memory_pool; + int comm_memory_pool_percent; + int comm_max_stream; + int comm_max_receiver; + int cn_send_buffer_size; + char* Unix_socket_group; + char* UnixSocketDir; + char* ListenAddresses; + char* tcp_link_addr; +} knl_instance_attr_network; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_resource.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_resource.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_resource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_resource.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_resource.h + * Data struct to store all knl_instance_attr_resource GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_resource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_resource { + bool enable_dynamic_workload; + bool enable_backend_control; + bool enable_vacuum_control; + bool enable_perm_space; +} knl_instance_attr_resource; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_security.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_security.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_security.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_security.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_security.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_security.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_security { + bool EnableSSL; + bool enablePrivilegesSeparate; + bool enable_nonsysadmin_execute_direct; + char* ssl_cert_file; + char* ssl_key_file; + char* ssl_ca_file; + char* ssl_crl_file; + char* SSLCipherSuites; + char* Audit_directory; + char* Audit_data_format; + char* transparent_encrypted_string; + char* transparent_encrypt_kms_region; + bool use_elastic_search; + char* elastic_search_ip_addr; +} knl_instance_attr_security; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_sql.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_sql.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_sql.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,56 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_sql.h + * Data struct to store all knl_instance_attr_sql GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_sql.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_sql { + bool string_hash_compatible; + bool enable_acceleration_cluster_wlm; + bool enable_orc_cache; + bool enable_default_cfunc_libpath; + int udf_memory_limit; + int UDFWorkerMemHardLimit; + int job_queue_processes; + int max_compile_functions; + int max_resource_package; +} knl_instance_attr_sql; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_storage.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_storage.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_instance_attr_storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_instance_attr_storage.h 2020-12-12 17:06:43.213347600 +0800 @@ -0,0 +1,98 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_storage.h + * Data struct to store all knl_instance_attr_storage GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_storage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_storage { + bool wal_log_hints; + bool EnableHotStandby; + bool enable_mix_replication; + bool IsRoachStandbyCluster; + bool enable_gtm_free; + bool comm_cn_dn_logic_conn; + bool enable_adio_function; + bool enable_access_server_directory; + bool enableIncrementalCheckpoint; + bool enable_double_write; + bool enable_delta_store; + bool enableWalLsnCheck; + int WalReceiverBufSize; + int DataQueueBufSize; + int NBuffers; + int cstore_buffers; + int MaxSendSize; + int max_prepared_xacts; + int max_locks_per_xact; + int max_predicate_locks_per_xact; + int64 xlog_idle_flushes_before_sleep; + int num_xloginsert_locks; + int wal_writer_cpu; + int xlog_flush_uplimit; + int wal_file_init_num; + int XLOGbuffers; + int max_wal_senders; + int max_replication_slots; + int replication_type; + int autovacuum_max_workers; + int64 autovacuum_freeze_max_age; + int wal_level; + /* User specified maximum number of recovery threads. */ + int max_recovery_parallelism; + int recovery_parse_workers; + int recovery_redo_workers_per_paser_worker; + int pagewriter_thread_num; + int bgwriter_thread_num; + int real_recovery_parallelism; + int batch_redo_num; + int remote_read_mode; + int advance_xlog_file_num; + int gtm_option; + int enable_update_max_page_flush_lsn; + int max_keep_log_seg; + int catchup2normal_wait_time; +#ifdef EXTREME_RTO_DEBUG_AB + int extreme_rto_ab_pos; + int extreme_rto_ab_type; + int extreme_rto_ab_count; +#endif + char* available_zone; +} knl_instance_attr_storage; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_common.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_common.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_common.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,208 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_common.h + * Data struct to store all knl_session_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_common { + bool enable_beta_features; + bool session_auth_is_superuser; + bool ignore_checksum_failure; + bool log_checkpoints; + bool Log_disconnections; + bool ExitOnAnyError; + bool omit_encoding_error; + bool log_parser_stats; + bool log_planner_stats; + bool log_executor_stats; + bool log_statement_stats; + bool pgstat_track_activities; + bool pgstat_track_counts; + bool pgstat_track_sql_count; + bool track_io_timing; + bool update_process_title; + bool pooler_cache_connection; + bool Trace_notify; + bool log_hostname; + bool XactReadOnly; + bool Log_truncate_on_rotation; + bool trace_sort; + bool integer_datetimes; + bool XLogArchiveMode; + bool IsInplaceUpgrade; + bool allow_concurrent_tuple_update; + bool IgnoreSystemIndexes; + bool PersistentConnections; + bool xc_maintenance_mode; + bool enable_redistribute; + bool check_implicit_conversions_for_indexcol; + bool support_batch_bind; + int XLogArchiveTimeout; + int Log_file_mode; + int bbox_dump_count; + int session_sequence_cache; + int max_stack_depth; + int max_query_retry_times; + int StatementTimeout; + int SessionTimeout; + int pgstat_collect_thread_status_interval; + int extra_float_digits; + int effective_io_concurrency; + int backend_flush_after; + int Log_RotationAge; + int Log_RotationSize; + int max_function_args; + int max_user_defined_exception; + int tcp_keepalives_idle; + int tcp_keepalives_interval; + int tcp_keepalives_count; + int GinFuzzySearchLimit; + int server_version_num; + int log_temp_files; + int transaction_sync_naptime; + int ngram_gram_size; + int gtm_connect_timeout; + int gtm_rw_timeout; + int transaction_sync_timeout; + int fault_mon_timeout; + double ConnectionAlarmRate; + char* client_encoding_string; + char* Log_line_prefix; + char* log_timezone_string; + char* datestyle_string; + char* Dynamic_library_path; + char* locale_collate; + char* locale_ctype; + char* locale_messages; + char* locale_monetary; + char* locale_numeric; + char* locale_time; + char* local_preload_libraries_string; + char* current_logic_cluster_name; + char* node_group_mode; + char* namespace_search_path; + char* nls_timestamp_format_string; + char* namespace_current_schema; + char* server_encoding_string; + char* server_version_string; + char* role_string; + char* session_authorization_string; + char* log_destination_string; + char* Log_directory; + char* asp_flush_mode; + char* asp_log_filename; + char* Perf_log; + char* Log_filename; + char* query_log_file; + char* syslog_ident_str; + char* timezone_string; + struct pg_tz* session_timezone; + struct pg_tz* log_timezone; + char* timezone_abbreviations_string; + char* pgstat_temp_directory; + char* TSCurrentConfig; + char* GtmHostInfoStringArray[MAX_GTM_HOST_NUM]; + struct tagGtmHostIP* GtmHostArray[MAX_GTM_HOST_NUM]; + int GtmHostIPNumArray[MAX_GTM_HOST_NUM]; + char* test_param_str; + char* application_name; + char* analysis_options; + int bytea_output; + int DefaultXactIsoLevel; + int IntervalStyle; + int Log_error_verbosity; + int backtrace_min_messages; + int client_min_messages; + int log_min_messages; + int log_min_error_statement; + int log_statement; + int syslog_facility; + int SessionReplicationRole; + int trace_recovery_messages; + int pgstat_track_functions; + int xmlbinary; + int remoteConnType; + + bool enable_bbox_dump; + char* bbox_dump_path; + + bool assert_enabled; + int AlarmReportInterval; + int xmloption; + bool enable_ts_compaction; + bool ts_adaptive_threads; + char* ts_compaction_strategy; + int ts_consumer_workers; + + /* instrumentation guc parameters */ + int instr_unique_sql_count; + bool enable_instr_cpu_timer; + int unique_sql_track_type; + bool enable_instr_track_wait; + bool enable_slow_query_log; + + int instr_rt_percentile_interval; + bool enable_instr_rt_percentile; + char* percentile_values; + + /* instr - full sql/slow sql */ + bool enable_stmt_track; + int track_stmt_session_slot; + char *track_stmt_stat_level; + int64 track_stmt_details_size; + char* track_stmt_retention_time; + + bool enable_wdr_snapshot; + bool enable_asp; + int wdr_snapshot_interval; + int wdr_snapshot_retention_days; + int asp_sample_interval; + int asp_flush_rate; + int asp_retention_days; + int max_datanode_for_plan; + int upgrade_mode; + int wdr_snapshot_query_timeout; + int dn_heartbeat_interval; + bool enable_full_encryption; + + char* router_att; + bool enable_router; +} knl_session_attr_common; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_memory.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_memory.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_memory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_memory.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_memory.h + * knl_session_attr_memory.h + * Data struct to store all knl_session_attr_memory GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_memory.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_memory { + bool enable_memory_context_control; + bool disable_memory_protect; + int work_mem; + int maintenance_work_mem; + char* memory_detail_tracking; + char* uncontrolled_memory_context; + int memory_tracking_mode; +} knl_session_attr_memory; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_network.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_network.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_network.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_network.h + * Data struct to store all knl_session_attr_network GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_network.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_network { + bool PoolerForceReuse; + bool comm_debug_mode; + bool comm_stat_mode; + bool comm_timer_mode; + bool comm_no_delay; + int PoolerTimeout; + int MinPoolSize; + int PoolerMaxIdleTime; + int PoolerConnectMaxLoops; + int PoolerConnectIntervalTime; + int PoolerConnectTimeout; + int PoolerCancelTimeout; + int comm_max_datanode; +#ifdef LIBCOMM_SPEED_TEST_ENABLE + int comm_test_thread_num; + int comm_test_msg_len; + int comm_test_send_sleep; + int comm_test_send_once; + int comm_test_recv_sleep; + int comm_test_recv_once; +#endif +#ifdef LIBCOMM_FAULT_INJECTION_ENABLE + int comm_fault_injection; +#endif + bool comm_client_bind; + int comm_ackchk_time; +} knl_session_attr_network; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_resource.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_resource.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_resource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_resource.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,95 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_resource.h + * Data struct to store all knl_session_attr_resource GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_resource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_resource { +#ifdef BTREE_BUILD_STATS + bool log_btree_build_stats; +#endif +#ifdef TRACE_SYNCSCAN + bool trace_syncscan; +#endif + bool enable_cgroup_switch; + bool enable_resource_track; + bool enable_hotkeys_collection; + bool enable_verify_statements; + bool enable_force_memory_control; + bool enable_dywlm_adjust; + bool enable_resource_record; + bool enable_user_metric_persistent; + bool enable_instance_metric_persistent; + bool enable_logical_io_statistics; + bool enable_reaper_backend; + bool enable_transaction_parctl; + int max_active_statements; + int dynamic_memory_quota; + int memory_fault_percent; + int parctl_min_cost; + int resource_track_cost; + int resource_track_duration; + int user_metric_retention_time; + int topsql_retention_time; + int unique_sql_retention_time; + int instance_metric_retention_time; + int cpu_collect_timer; + int iops_limits; + int autovac_iops_limits; + int io_control_unit; + int transaction_pending_time; + char* cgroup_name; + char* query_band; + char* session_resource_pool; + int resource_track_level; + int io_priority; + bool use_workload_manager; + bool enable_control_group; + + /* GUC variable for session statistics memory */ + int session_statistics_memory; + /* GUC variable for session history memory */ + int session_history_memory; + bool bypass_workload_manager; + /* sql_use_spacelimit */ + int sqlUseSpaceLimit; + bool enable_auto_explain; + int auto_explain_level; +} knl_session_attr_resource; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_security.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_security.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_security.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_security.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,91 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_security.h + * Data struct to store all knl_session_attr_security GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_security.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_security { + bool RequireSSL; + bool zero_damaged_pages; + bool pg_krb_caseins_users; + bool Audit_enabled; + bool Audit_CleanupPolicy; + bool Modify_initial_password; + bool operation_mode; + int PostAuthDelay; + int AuthenticationTimeout; + int PreAuthDelay; + int ssl_renegotiation_limit; + int ssl_cert_notify_time; + int Password_policy; + int Password_encryption_type; + int Password_reuse_max; + int Failed_login_attempts; + int Password_min_upper; + int Password_min_lower; + int Password_min_digital; + int Password_min_special; + int Password_min_length; + int Password_max_length; + int Password_notify_time; + int Audit_RotationAge; + int Audit_RotationSize; + int Audit_SpaceLimit; + int Audit_RemainAge; + int Audit_RemainThreshold; + int Audit_Session; + int Audit_ServerAction; + int Audit_LockUser; + int Audit_UserViolation; + int Audit_PrivilegeAdmin; + int Audit_DDL; + int Audit_DML; + int Audit_DML_SELECT; + int Audit_Exec; + int Audit_Copy; + int Audit_Set; + int auth_iteration_count; + double Password_reuse_time; + double Password_effect_time; + double Password_lock_time; + char* pg_krb_server_keyfile; + char* pg_krb_srvnam; + bool Enable_Security_Policy; +} knl_session_attr_security; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_sql.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_sql.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_sql.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,216 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_sql.h + * Data struct to store knl_session_attr_sql variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_sql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_sql { + bool enable_fast_numeric; + bool enable_global_stats; + bool enable_hdfs_predicate_pushdown; + bool enable_absolute_tablespace; + bool enable_hadoop_env; + bool enable_valuepartition_pruning; + bool enable_constraint_optimization; + bool enable_bloom_filter; + bool enable_codegen; + bool enable_codegen_print; + bool enable_sonic_optspill; + bool enable_sonic_hashjoin; + bool enable_sonic_hashagg; + bool enable_upsert_to_merge; + bool enable_csqual_pushdown; + bool enable_change_hjcost; + bool enable_seqscan; + bool enable_indexscan; + bool enable_indexonlyscan; + bool enable_bitmapscan; + bool force_bitmapand; + bool enable_parallel_ddl; + bool enable_tidscan; + bool enable_sort; + bool enable_compress_spill; + bool enable_hashagg; + bool enable_material; + bool enable_nestloop; + bool enable_mergejoin; + bool enable_hashjoin; + bool enable_index_nestloop; + bool under_explain; + bool enable_nodegroup_debug; + bool enable_partitionwise; + bool enable_remotejoin; + bool enable_fast_query_shipping; + bool enable_compress_hll; + bool enable_remotegroup; + bool enable_remotesort; + bool enable_remotelimit; + bool gtm_backup_barrier; + bool explain_allow_multinode; + bool enable_stream_operator; + bool enable_stream_concurrent_update; + bool enable_vector_engine; + bool enable_force_vector_engine; + bool enable_random_datanode; + bool enable_fstream; + bool enable_geqo; + bool restart_after_crash; + bool enable_early_free; + bool enable_kill_query; + bool log_duration; + bool Debug_print_parse; + bool Debug_print_rewritten; + bool Debug_print_plan; + bool Debug_pretty_print; + bool enable_analyze_check; + bool enable_autoanalyze; + bool SQL_inheritance; + bool Transform_null_equals; + bool check_function_bodies; + bool Array_nulls; + bool default_with_oids; +#ifdef DEBUG_BOUNDED_SORT + bool optimize_bounded_sort; +#endif + bool escape_string_warning; + bool standard_conforming_strings; + bool enable_light_proxy; + bool enable_pbe_optimization; + bool enable_cluster_resize; + bool lo_compat_privileges; + bool quote_all_identifiers; + bool enforce_a_behavior; + bool enable_slot_log; + bool convert_string_to_digit; + bool agg_redistribute_enhancement; + bool enable_broadcast; + bool ngram_punctuation_ignore; + bool ngram_grapsymbol_ignore; + bool enable_fast_allocate; + bool td_compatible_truncation; + bool enable_upgrade_merge_lock_mode; + bool acceleration_with_compute_pool; + bool enable_extrapolation_stats; + bool enable_trigger_shipping; + bool enable_agg_pushdown_for_cooperation_analysis; + bool enable_online_ddl_waitlock; + bool show_acce_estimate_detail; + bool enable_prevent_job_task_startup; + bool enable_dngather; + int from_collapse_limit; + int join_collapse_limit; + int geqo_threshold; + int Geqo_effort; + int Geqo_pool_size; + int Geqo_generations; + int g_default_log2m; + int g_default_regwidth; + int g_default_sparseon; + int g_max_sparse; + int g_planCacheMode; + int cost_param; + int schedule_splits_threshold; + int hashagg_table_size; + int statement_mem; + int statement_max_mem; + int temp_file_limit; + int effective_cache_size; + int best_agg_plan; + int query_dop_tmp; + int plan_mode_seed; + int codegen_cost_threshold; + int acce_min_datasize_per_thread; + int max_cn_temp_file_size; + int default_statistics_target; + /* Memory Limit user could set in session */ + int FencedUDFMemoryLimit; + int64 g_default_expthresh; + double seq_page_cost; + double random_page_cost; + double cpu_tuple_cost; + double allocate_mem_cost; + double cpu_index_tuple_cost; + double cpu_operator_cost; + double stream_multiple; + double dngather_min_rows; + double cursor_tuple_fraction; + double Geqo_selection_bias; + double Geqo_seed; + double phony_random_seed; + char* expected_computing_nodegroup; + char* default_storage_nodegroup; + char* inlist2join_optmode; + char* behavior_compat_string; + char* connection_info; + char* retry_errcode_list; + /* the vmoptions to start JVM */ + char* pljava_vmoptions; + int backslash_quote; + int constraint_exclusion; + int rewrite_rule; + int sql_compatibility; + int guc_explain_perf_mode; + int skew_strategy_store; + int codegen_strategy; + + int application_type; + + bool enable_unshipping_log; + /* + * enable to support "with-recursive" stream plan + */ + bool enable_stream_recursive; + bool enable_save_datachanged_timestamp; + int max_recursive_times; + /* Table skewness warning rows, range from 0 to INT_MAX*/ + int table_skewness_warning_rows; + /* Table skewness warning threshold, range from 0 to 1, 0 indicates feature disabled*/ + double table_skewness_warning_threshold; + bool enable_opfusion; + bool enable_beta_opfusion; + bool enable_partition_opfusion; + int opfusion_debug_mode; + double cost_weight_index; + double default_limit_rows; + int sql_beta_feature; + /* hypo index */ + bool enable_hypo_index; + bool hypopg_is_explain; +} knl_session_attr_sql; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_storage.h postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_storage.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc/knl_session_attr_storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc/knl_session_attr_storage.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,194 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_storage.h + * Data struct to store all knl_session_attr_storage GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_storage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_storage { + bool raise_errors_if_no_files; + bool enableFsync; + bool fullPageWrites; + bool Log_connections; + bool autovacuum_start_daemon; +#ifdef LOCK_DEBUG + bool Trace_locks; + bool Trace_userlocks; + bool Trace_lwlocks; +#endif + /* belong to #ifdef LOCK_DEBUG, but if #ifdef, compile error */ + bool Debug_deadlocks; + bool log_lock_waits; + bool phony_autocommit; + bool DefaultXactReadOnly; + bool DefaultXactDeferrable; + bool XactDeferrable; +#ifdef WAL_DEBUG + bool XLOG_DEBUG; +#endif + bool synchronize_seqscans; + bool enable_data_replicate; + bool HaModuleDebug; + bool hot_standby_feedback; + bool enable_stream_replication; + bool EnforceTwoPhaseCommit; + bool guc_most_available_sync; + bool enable_show_any_tuples; + bool enable_debug_vacuum; + bool enable_adio_debug; + bool gds_debug_mod; + bool log_pagewriter; + bool enable_incremental_catchup; + bool auto_explain_log_verbose; + int wait_dummy_time; + int DeadlockTimeout; + int LockWaitTimeout; + int LockWaitUpdateTimeout; + int max_standby_archive_delay; + int max_standby_streaming_delay; + int wal_receiver_status_interval; + int wal_receiver_timeout; + int wal_receiver_connect_timeout; + int wal_receiver_connect_retries; + int basebackup_timeout; + int max_loaded_cudesc; + int num_temp_buffers; + int psort_work_mem; + int bulk_write_ring_size; + int bulk_read_ring_size; + int partition_mem_batch; + int partition_max_cache_size; + int VacuumCostPageHit; + int VacuumCostPageMiss; + int VacuumCostPageDirty; + int VacuumCostLimit; + int VacuumCostDelay; + int autovacuum_vac_cost_delay; + int autovacuum_vac_cost_limit; + int gs_clean_timeout; + int twophase_clean_workers; +#ifdef LOCK_DEBUG + int Trace_lock_oidmin; + int Trace_lock_table; +#endif + int replorigin_sesssion_origin; + int wal_keep_segments; + int CheckPointSegments; + int CheckPointTimeout; + int fullCheckPointTimeout; + int incrCheckPointTimeout; + int CheckPointWarning; + int checkpoint_flush_after; + int CheckPointWaitTimeOut; + int WalWriterDelay; + int wal_sender_timeout; + int CommitDelay; + int partition_lock_upgrade_timeout; + int CommitSiblings; + int log_min_duration_statement; + int Log_autovacuum_min_duration; + int BgWriterDelay; + int bgwriter_lru_maxpages; + int bgwriter_flush_after; + int max_index_keys; + int max_identifier_length; + int block_size; + int segment_size; + int wal_block_size; + int wal_segment_size; + int autovacuum_naptime; + int autoanalyze_timeout; + int autovacuum_vac_thresh; + int autovacuum_anl_thresh; + int prefetch_quantity; + int backwrite_quantity; + int cstore_prefetch_quantity; + int cstore_backwrite_max_threshold; + int cstore_backwrite_quantity; + int fast_extend_file_size; + int gin_pending_list_limit; + int gtm_connect_retries; + int gtm_conn_check_interval; + int dfs_max_parsig_length; + int plog_merge_age; + int max_redo_log_size; + int max_io_capacity; + int64 vacuum_freeze_min_age; + int64 vacuum_freeze_table_age; + int64 vacuum_defer_cleanup_age; + double bgwriter_lru_multiplier; + double shared_buffers_fraction; + double autovacuum_vac_scale; + double autovacuum_anl_scale; + double CheckPointCompletionTarget; + double candidate_buf_percent_target; + double dirty_page_percent_max; + char* XLogArchiveCommand; + char* XLogArchiveDest; + char* default_tablespace; + char* temp_tablespaces; + char* XactIsoLevel_string; + char* SyncRepStandbyNames; + char* ReplConnInfoArr[GUC_MAX_REPLNODE_NUM]; + char* PrimarySlotName; + char* logging_module; + char* Inplace_upgrade_next_system_object_oids; + int resource_track_log; + int guc_synchronous_commit; + int sync_method; + int autovacuum_mode; + int cstore_insert_mode; + int pageWriterSleep; + bool enable_cbm_tracking; + bool enable_copy_server_files; + int target_rto; + bool enable_twophase_commit; + /* + * xlog keep for all standbys even through they are not connect and donnot created replslot. + */ + bool enable_xlog_prune; + int max_size_for_xlog_prune; + int defer_csn_cleanup_time; + + bool enable_hashbucket; + + /* for GTT */ + int max_active_gtt; + int vacuum_gtt_defer_check_age; +} knl_session_attr_storage; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_guc.h postgresql-hll-2.14/include/include/knl/knl_guc.h --- postgresql-hll-2.14_old/include/include/knl/knl_guc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_guc.h 2020-12-12 17:06:43.214347613 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_guc.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_GUC_H_ +#define SRC_INCLUDE_KNL_KNL_GUC_H_ + +#include "knl_guc/knl_session_attr_sql.h" +#include "knl_guc/knl_instance_attr_sql.h" +#include "knl_guc/knl_session_attr_storage.h" +#include "knl_guc/knl_instance_attr_storage.h" +#include "knl_guc/knl_session_attr_security.h" +#include "knl_guc/knl_instance_attr_security.h" +#include "knl_guc/knl_session_attr_network.h" +#include "knl_guc/knl_instance_attr_network.h" +#include "knl_guc/knl_session_attr_memory.h" +#include "knl_guc/knl_instance_attr_memory.h" +#include "knl_guc/knl_session_attr_resource.h" +#include "knl_guc/knl_instance_attr_resource.h" +#include "knl_guc/knl_session_attr_common.h" +#include "knl_guc/knl_instance_attr_common.h" + +#endif /* SRC_INCLUDE_KNL_KNL_GUC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_instance.h postgresql-hll-2.14/include/include/knl/knl_instance.h --- postgresql-hll-2.14_old/include/include/knl/knl_instance.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_instance.h 2020-12-12 17:06:43.215347625 +0800 @@ -0,0 +1,812 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance.h + * Data stucture for instance level global variables. + * + * Instance level variables can be accessed by all threads in gaussdb. + * Thread competition must be considered at the first place. If it can + * be changed by every thread in this process, then we must use lock or + * atomic operation to prevent competition. + * + * IDENTIFICATION + * src/include/knl/knl_instance.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_H_ + +#include +#include "c.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "knl/knl_guc.h" +#include "lib/circularqueue.h" +#include "nodes/pg_list.h" +#include "storage/s_lock.h" +#include "access/double_write_basic.h" +#include "utils/palloc.h" +#include "replication/replicainternal.h" +#include "storage/latch.h" +#include "libcomm/libcomm.h" +#include "knl/knl_session.h" +#include "hotpatch/hotpatch.h" +#include "hotpatch/hotpatch_backend.h" +#include "utils/atomic.h" +#include "postmaster/bgwriter.h" +#include "postmaster/pagewriter.h" +#include "replication/heartbeat.h" +#include "access/multi_redo_settings.h" +#include "access/redo_statistic_msg.h" +#include "portability/instr_time.h" +#include "streaming/init.h" +#include "replication/rto_statistic.h" +#ifdef ENABLE_MULTIPLE_NODES +#include "tsdb/utils/constant_def.h" +#endif +#include "streaming/init.h" +#include "storage/lwlock.h" +#include "utils/memgroup.h" + +const int NUM_PERCENTILE_COUNT = 2; +const int INIT_NUMA_ALLOC_COUNT = 32; +const int HOTKEY_ABANDON_LENGTH = 100; + +enum knl_virtual_role { + VUNKNOWN = 0, + VCOORDINATOR = 1, + VDATANODE = 2, + VSINGLENODE = 3, +}; + +/* + * start process: set to REDO_INIT + * parallel redo begin:set to REDO_STARTING_BEGIN, wait for redo worker thread to start + * all redo workers are started or waiting timeout: set to REDO_STARTING_END, + * if redo worker starts at this stage, the redo worker has to exit + */ +enum knl_parallel_redo_state { + REDO_INIT = 0, + REDO_STARTING_BEGIN, + REDO_STARTING_END, + REDO_IN_PROGRESS, + REDO_DONE, +}; + +/* all process level attribute which expose to user */ +typedef struct knl_instance_attr { + + knl_instance_attr_sql attr_sql; + knl_instance_attr_storage attr_storage; + knl_instance_attr_security attr_security; + knl_instance_attr_network attr_network; + knl_instance_attr_memory attr_memory; + knl_instance_attr_resource attr_resource; + knl_instance_attr_common attr_common; + +} knl_instance_attr_t; + +typedef struct knl_g_cache_context +{ + MemoryContext global_cache_mem; +} knl_g_cache_context; + +typedef struct knl_g_cost_context { + double cpu_hash_cost; + + double send_kdata_cost; + + double receive_kdata_cost; + + Cost disable_cost; + + Cost disable_cost_enlarge_factor; + +} knl_g_cost_context; + +typedef struct knl_g_pid_context { + ThreadId StartupPID; + ThreadId TwoPhaseCleanerPID; + ThreadId FaultMonitorPID; + ThreadId BgWriterPID; + ThreadId* CkptBgWriterPID; + ThreadId* PageWriterPID; + ThreadId CheckpointerPID; + ThreadId WalWriterPID; + ThreadId WalWriterAuxiliaryPID; + ThreadId WalReceiverPID; + ThreadId WalRcvWriterPID; + ThreadId DataReceiverPID; + ThreadId DataRcvWriterPID; + ThreadId AutoVacPID; + ThreadId PgJobSchdPID; + ThreadId PgArchPID; + ThreadId PgStatPID; + ThreadId PercentilePID; + ThreadId PgAuditPID; + ThreadId SysLoggerPID; + ThreadId CatchupPID; + ThreadId WLMCollectPID; + ThreadId WLMCalSpaceInfoPID; + ThreadId WLMMonitorPID; + ThreadId WLMArbiterPID; + ThreadId CPMonitorPID; + ThreadId AlarmCheckerPID; + ThreadId CBMWriterPID; + ThreadId RemoteServicePID; + ThreadId AioCompleterStarted; + ThreadId HeartbeatPID; + ThreadId CsnminSyncPID; + volatile ThreadId ReaperBackendPID; + volatile ThreadId SnapshotPID; + ThreadId AshPID; + ThreadId StatementPID; + ThreadId CommSenderFlowPID; + ThreadId CommReceiverFlowPID; + ThreadId CommAuxiliaryPID; + ThreadId CommPoolerCleanPID; + ThreadId* CommReceiverPIDS; + ThreadId TsCompactionPID; + ThreadId TsCompactionAuxiliaryPID; +} knl_g_pid_context; + +typedef struct knl_g_stat_context { + /* Every cell is a array size of 128 and the list stores all users` sql count results */ + struct List* WaitCountStatusList; + + /* Shared hashtable used to mapping user and g_instance.stat.WaitCountStatusList index for QPS */ + struct HTAB* WaitCountHashTbl; + + pgsocket pgStatSock; + + Latch pgStatLatch; + + time_t last_pgstat_start_time; + + /* Last time the collector successfully wrote the stats file */ + TimestampTz last_statwrite; + + /* Latest statistics request time from backends */ + TimestampTz last_statrequest; + + volatile bool need_exit; + + volatile bool got_SIGHUP; + + /* unique sql */ + MemoryContext UniqueSqlContext; + HTAB* volatile UniqueSQLHashtbl; + + /* hypothetical index */ + MemoryContext HypopgContext; + + /* user logon/logout stat */ + MemoryContext InstrUserContext; + HTAB* InstrUserHTAB; + + /* workload trx stat */ + HTAB* workload_info_hashtbl; + + /* percentile stat */ + volatile bool calculate_on_other_cn; + volatile bool force_process; + int64 RTPERCENTILE[NUM_PERCENTILE_COUNT]; + struct SqlRTInfoArray* sql_rt_info_array; + MemoryContext InstrPercentileContext; + + /* Set at the following cases: + 1. the cluster occures ha action + 2. user perform reset action + 3. the node startup + 4. ... + */ + volatile TimestampTz NodeStatResetTime; + int64* gInstanceTimeInfo; + + /* snapshot thread status counter, will +1 when "each" startup */ + volatile uint32 snapshot_thread_counter; + /* Record the sum of file io stat */ + struct FileIOStat* fileIOStat; + + /* Active session history */ + MemoryContext AshContext; + struct ActiveSessHistArrary *active_sess_hist_arrary; + char *ash_appname; + char *ash_clienthostname; + char *ashRelname; + HTAB* ASHUniqueSQLHashtbl; + /* used for capture view to json file */ + HTAB* capture_view_file_hashtbl; + + /* used for track memory alloc info */ + MemoryContext track_context; + HTAB* track_context_hash; + HTAB* track_memory_info_hash; + bool track_memory_inited; +#ifndef WIN32 + pthread_rwlock_t track_memory_lock; + + /* A g_instance lock-free queue to collect keys */ + CircularQueue* hotkeysCollectList; + + /* memorycontext for managing hotkeys */ + MemoryContext hotkeysCxt; + + struct LRUCache* lru; + List* fifo; +#endif +} knl_g_stat_context; + +/* + *quota related + */ +typedef struct knl_g_quota_context { + /* quota for each stream */ + unsigned long g_quota; + /* quota ratio for dynamic quota changing, but no use now */ + unsigned long g_quotanofify_ratio; + /* using quota or not */ + bool g_having_quota; + /* for notifying bufCAP of stream is changed */ + struct binary_semaphore* g_quota_changing; +} knl_g_quota_context; + +typedef enum { + POLLING_CONNECTION = 0, + + SPECIFY_CONNECTION = 1, + + PROHIBIT_CONNECTION = 2 +} CONN_MODE; + +typedef struct knl_g_disconn_node_context_data { + CONN_MODE conn_mode; + char disable_conn_node_host[NAMEDATALEN]; + int disable_conn_node_port; +} knl_g_disconn_node_context_data; + +typedef struct knl_g_disconn_node_context { + knl_g_disconn_node_context_data disable_conn_node_data; + slock_t info_lck; /* locks shared variables shown above */ +} knl_g_disconn_node_context; + +/* + *local basic connection info + */ +typedef struct knl_g_localinfo_context { + char* g_local_host; + char* g_self_nodename; + int g_local_ctrl_tcp_sock; + int sock_to_server_loop; + /* The start time of receiving the ready message */ + uint64 g_r_first_recv_time; + /* record CPU utilization, gs_receivers_flow_controller ,gs_sender_flow_controller, gs_reveiver_loop, postmaster */ + int *g_libcomm_used_rate; + /* GSS kerberos authentication */ + char* gs_krb_keyfile; +#ifndef WIN32 + volatile uint32 term_from_file = 1; + volatile uint32 term_from_xlog = 1; + bool set_term = true; + knl_g_disconn_node_context disable_conn_node; + volatile uint32 is_finish_redo = 0; + volatile bool need_disable_connection_node = false; +#else + volatile uint32 term_from_file; + volatile uint32 term_from_xlog; + bool set_term; + knl_g_disconn_node_context disable_conn_node; + volatile uint32 is_finish_redo; + volatile bool need_disable_connection_node; +#endif +} knl_g_localinfo_context; + +typedef struct knl_g_counters_context { + /* connection number, equal to real node number (dn + cn) */ + int g_cur_node_num; + /* + * expected node number, if g_expect_node_num != g_cur_node_num, + * we will use online capacity change. + */ + int g_expect_node_num; + /* stream number of each logic connection */ + int g_max_stream_num; + /* the number of receiver thread */ + int g_recv_num; + int g_comm_send_timeout; +} knl_g_counters_context; + +typedef struct knl_g_tests_context { + int libcomm_test_current_thread; + int* libcomm_test_thread_arg; + bool libcomm_stop_flag; + int libcomm_test_thread_num; + int libcomm_test_msg_len; + int libcomm_test_send_sleep; + int libcomm_test_send_once; + int libcomm_test_recv_sleep; + int libcomm_test_recv_once; +} knl_g_tests_context; + +/* the epoll cabinets for receiving control messages and data */ +typedef struct knl_g_pollers_context { + /* data receiver epoll cabinet */ + class mc_poller_hndl_list* g_libcomm_receiver_poller_list; + pthread_mutex_t* g_r_libcomm_poller_list_lock; + /* the epoll cabinet for receiving control messages at receiver */ + class mc_poller_hndl_list* g_r_poller_list; + pthread_mutex_t* g_r_poller_list_lock; + /* the epoll cabinet for receiving control messages at sender */ + class mc_poller_hndl_list* g_s_poller_list; + pthread_mutex_t* g_s_poller_list_lock; +} knl_g_pollers_context; + +/* request checking variable */ +typedef struct knl_g_reqcheck_context { + volatile bool g_shutdown_requested; + volatile ThreadId g_cancel_requested; + volatile bool g_close_poll_requested; +} knl_g_reqcheck_context; + +typedef struct knl_g_mctcp_context { + int mc_tcp_keepalive_idle; + int mc_tcp_keepalive_interval; + int mc_tcp_keepalive_count; + int mc_tcp_connect_timeout; + int mc_tcp_send_timeout; +} knl_g_mctcp_context; + +typedef struct knl_g_commutil_context { + volatile bool g_debug_mode; + volatile bool g_timer_mode; + volatile bool g_stat_mode; + volatile bool g_no_delay; + + int g_comm_sender_buffer_size; + long g_total_usable_memory; + long g_memory_pool_size; + bool ut_libcomm_test; +} knl_g_commutil_context; + +const int TWO_UINT64_SLOT = 2; +/*checkpoint*/ +typedef struct knl_g_ckpt_context { + uint64 dirty_page_queue_reclsn; + uint64 dirty_page_queue_tail; + + CkptSortItem* CkptBufferIds; + + /* dirty_page_queue store dirty buffer, buf_id + 1, 0 is invalid */ + DirtyPageQueueSlot* dirty_page_queue; + uint64 dirty_page_queue_size; + pg_atomic_uint64 dirty_page_queue_head; + pg_atomic_uint32 actual_dirty_page_num; + slock_t queue_lock; + + /* pagewriter thread */ + PageWriterProcs page_writer_procs; + uint64 page_writer_actual_flush; + volatile uint32 page_writer_last_flush; + + /* full checkpoint infomation */ + volatile bool flush_all_dirty_page; + volatile uint64 full_ckpt_expected_flush_loc; + volatile uint64 full_ckpt_redo_ptr; + volatile uint32 current_page_writer_count; + volatile XLogRecPtr page_writer_xlog_flush_loc; + volatile LWLock *backend_wait_lock; + + /* Pagewriter thread need wait shutdown checkpoint finish */ + volatile bool page_writer_can_exit; + + /* checkpoint flush page num except buffers */ + int64 ckpt_clog_flush_num; + int64 ckpt_csnlog_flush_num; + int64 ckpt_multixact_flush_num; + int64 ckpt_predicate_flush_num; + int64 ckpt_twophase_flush_num; + volatile XLogRecPtr ckpt_current_redo_point; + +#ifdef ENABLE_MOT + struct CheckpointCallbackItem* ckptCallback; +#endif + + uint64 pad[TWO_UINT64_SLOT]; +} knl_g_ckpt_context; + +typedef struct knl_g_dw_context { + int fd; + volatile uint32 closed; + + struct LWLock* flush_lock; + volatile uint16 write_pos; /* the copied pages in buffer, updated when mark page */ + uint16 flush_page; /* total number of flushed pages before truncate or reset */ + MemoryContext mem_cxt; + char* unaligned_buf; + char* buf; + dw_file_head_t* file_head; + bool contain_hashbucket; + + /* single flush dw extras information */ + single_slot_pos *single_flush_pos; /* dw single flush slot */ + single_slot_state *single_flush_state; /* dw single flush slot state */ + + /* dw view information */ + dw_stat_info_batch batch_stat_info; + dw_stat_info_single single_stat_info; +} knl_g_dw_context; + +typedef struct knl_g_bgwriter_context { + BgWriterProc *bgwriter_procs; + int bgwriter_num; /* bgwriter thread num*/ + pg_atomic_uint32 curr_bgwriter_num; + Buffer *candidate_buffers; + bool *candidate_free_map; + + /* bgwriter view information*/ + volatile uint64 bgwriter_actual_total_flush; + volatile uint64 get_buf_num_candidate_list; + volatile uint64 get_buf_num_clock_sweep; +}knl_g_bgwriter_context; + +typedef struct { + ThreadId threadId; + uint32 threadState; +} PageRedoWorkerStatus; + +typedef struct { + uint64 preEndPtr; + instr_time preTime; + XLogRecPtr redo_start_ptr; + int64 redo_start_time; + int64 redo_done_time; + int64 current_time; + XLogRecPtr min_recovery_point; + XLogRecPtr read_ptr; + XLogRecPtr last_replayed_end_ptr; + XLogRecPtr recovery_done_ptr; + XLogRecPtr primary_flush_ptr; + RedoWaitInfo wait_info[WAIT_REDO_NUM]; + uint32 speed_according_seg; + XLogRecPtr local_max_lsn; + uint64 oldest_segment; +} RedoPerf; + + +typedef enum{ + DEFAULT_REDO, + PARALLEL_REDO, + EXTREME_REDO, +}RedoType; + + +typedef struct knl_g_parallel_redo_context { + RedoType redoType; + volatile knl_parallel_redo_state state; + slock_t rwlock; /* redo worker starting lock */ + MemoryContext parallelRedoCtx; + uint32 totalNum; + volatile PageRedoWorkerStatus pageRedoThreadStatusList[MAX_RECOVERY_THREAD_NUM]; + RedoPerf redoPf; /* redo Performance statistics */ + pg_atomic_uint32 isRedoFinish; + int pre_enable_switch; + slock_t destroy_lock; /* redo worker destroy lock */ + pg_atomic_uint64 max_page_flush_lsn[NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS]; + pg_atomic_uint32 permitFinishRedo; + pg_atomic_uint32 hotStdby; + char* unali_buf; /* unaligned_buf */ + char* ali_buf; +} knl_g_parallel_redo_context; + +typedef struct knl_g_heartbeat_context { + volatile bool heartbeat_running; +} knl_g_heartbeat_context; + +typedef struct knl_g_csnminsync_context { + bool stop; + bool is_fcn_ccn; /* whether this instance is center cn or the first cn while without ccn */ +} knl_g_csnminsync_context; + +typedef struct knl_g_comm_context { + /* function point, for wake up consumer in executor */ + wakeup_hook_type gs_wakeup_consumer; + /* connection handles at receivers, for listening and receiving data through logic connection */ + struct local_receivers* g_receivers; + /* connection handles at senders, for sending data through logic connection */ + struct local_senders* g_senders; + bool g_delay_survey_switch; + /* the unix path to send startuppacket to postmaster */ + char* g_unix_path; + HaShmemData* g_ha_shm_data; + /* + * filo queue, for keeping the usable stream indexes of each node + * we pop up a stream index for communication and push back after + * the stream is closed + */ + struct mc_queue* g_usable_streamid; + + /* + * sockets (control tcp & sctp sockets) of receiver and sender, for socket management and avaliable checking + * the indexes of the items in the array is the node indexes for each datanode, + * e.g. g_r_node_sock[1] is using to keep socket information of Datanode 1 at receiver in this datanode, maybe + * Datanode 2 or others + */ + struct node_sock* g_r_node_sock; + struct node_sock* g_s_node_sock; + struct libcomm_delay_info* g_delay_info; + /* + * two-dimension array to maintain the information of streams associated to Consumer and Producer, each element + * represent a stream. the first dimension represent node and the second is stream. we call it mailbox, and the node + * index and stream index is the address, e.g. we can get information of a stream at receiver by g_c_mailbox[node + * id][stream id]. + */ + /* Consumer mailboxes at receiver */ + struct c_mailbox** g_c_mailbox; + /* Producer mailboxes at sender */ + struct p_mailbox** g_p_mailbox; + struct pg_tz* libcomm_log_timezone; + + bool g_use_workload_manager; + + knl_g_quota_context quota_cxt; + knl_g_localinfo_context localinfo_cxt; + knl_g_counters_context counters_cxt; + knl_g_tests_context tests_cxt; + knl_g_pollers_context pollers_cxt; + knl_g_reqcheck_context reqcheck_cxt; + knl_g_mctcp_context mctcp_cxt; + knl_g_commutil_context commutil_cxt; + knl_g_parallel_redo_context predo_cxt; /* parallel redo context */ + MemoryContext comm_global_mem_cxt; + bool force_cal_space_info; + bool cal_all_space_info_in_progress; + + HTAB* usedDnSpace; + uint32 current_gsrewind_count; +} knl_g_comm_context; + +typedef struct knl_g_libpq_context { + /* Workaround for Solaris 2.6 brokenness */ + char* pam_passwd; + /* Workaround for passing "Port *port" into pam_passwd_conv_proc */ + struct Port* pam_port_cludge; +#ifdef KRB5 + /* + * Various krb5 state which is not connection specific, and a flag to + * indicate whether we have initialised it yet. + */ + int pg_krb5_initialised; + krb5_context pg_krb5_context; + krb5_keytab pg_krb5_keytab; + krb5_principal pg_krb5_server; +#endif + /* check internal IP, to avoid port injection*/ + List* comm_parsed_hba_lines; +} knl_g_libpq_context; + +#define MIN_CONNECTIONS 1024 + +typedef struct knl_g_shmem_context { + int MaxConnections; + int MaxBackends; + int MaxReserveBackendId; + int ThreadPoolGroupNum; + int numaNodeNum; +} knl_g_shmem_context; + +typedef struct knl_g_executor_context { + HTAB* function_id_hashtbl; +} knl_g_executor_context; + +typedef struct knl_g_xlog_context { + int num_locks_in_group; +#ifdef ENABLE_MOT + struct WALCallbackItem* walCallback; + struct RedoCommitCallbackItem* redoCommitCallback; +#endif +} knl_g_xlog_context; + +struct NumaMemAllocInfo { + void* numaAddr; /* Start address returned from numa_alloc_xxx */ + size_t length; +}; + +typedef struct knl_g_numa_context { + bool inheritThreadPool; // Inherit NUMA node No. from thread pool module + NumaMemAllocInfo* numaAllocInfos; + size_t maxLength; + size_t allocIndex; +} knl_g_numa_context; + +typedef struct knl_g_ts_compaction_context { +#ifdef ENABLE_MULTIPLE_NODES + volatile Compaction::knl_compaction_state state; + volatile TsCompactionWorkerStatus compaction_worker_status_list[Compaction::MAX_TSCOMPATION_NUM]; +#endif + int totalNum; + int* origin_id; + volatile uint32 drop_db_count; + volatile bool compaction_rest; + Oid dropdb_id; + MemoryContext compaction_instance_cxt; +} knl_g_ts_compaction_context; + +typedef struct knl_g_security_policy_context { + MemoryContext policy_instance_cxt; + HTAB* account_table; + LWLock* account_table_lock; +} knl_g_security_policy_context; + +typedef struct knl_g_oid_nodename_mapping_cache +{ + HTAB *s_mapping_hash; + volatile bool s_valid; + pthread_mutex_t s_mutex; +} knl_g_oid_nodename_mapping_cache; + +typedef uint64 XLogSegNo; /* XLogSegNo - physical log file sequence number */ +typedef struct WalInsertStatusEntry WALInsertStatusEntry; +typedef struct WALFlushWaitLockPadded WALFlushWaitLockPadded; +typedef struct WALBufferInitWaitLockPadded WALBufferInitWaitLockPadded; +typedef struct WALInitSegLockPadded WALInitSegLockPadded; +typedef struct knl_g_conn_context { + volatile int CurConnCount; + volatile int CurCMAConnCount; + slock_t ConnCountLock; +} knl_g_conn_context; + +typedef struct knl_g_wal_context { + /* Start address of WAL insert status table that contains WAL_INSERT_STATUS_ENTRIES entries */ + WALInsertStatusEntry* walInsertStatusTable; + WALFlushWaitLockPadded* walFlushWaitLock; + WALBufferInitWaitLockPadded* walBufferInitWaitLock; + WALInitSegLockPadded* walInitSegLock; + volatile bool isWalWriterUp; + XLogRecPtr flushResult; + XLogRecPtr sentResult; + pthread_mutex_t flushResultMutex; + pthread_cond_t flushResultCV; + int XLogFlusherCPU; + volatile bool isWalWriterSleeping; + pthread_mutex_t criticalEntryMutex; + pthread_cond_t criticalEntryCV; + volatile uint32 walWaitFlushCount; /* only for xlog statistics use */ + volatile XLogSegNo globalEndPosSegNo; /* Global variable for init xlog segment files. */ + int lastWalStatusEntryFlushed; + volatile int lastLRCScanned; + int num_locks_in_group; +} knl_g_wal_context; + +typedef struct GlobalSeqInfoHashBucket { + DList* shb_list; + int lock_id; +} GlobalSeqInfoHashBucket; + +typedef struct knl_instance_context { + knl_virtual_role role; + volatile int status; + DemoteMode demotion; + bool fatal_error; + + bool WalSegmentArchSucceed; + + /* + * request to flush buffer log data + * 1. syslogger thread will read this var. if it's true, + * flush all buffered log data and reset this flag. + * 2. the other worker threads will set this flag be true if needed. + * needn't use THR_LOCAL modifier. + */ + volatile sig_atomic_t flush_buf_requested; + + /* True if WAL recovery failed */ + bool recover_error; + pthread_mutex_t gpc_reset_lock; + struct Dllist* backend_list; + struct Backend* backend_array; + + void* t_thrd; + char* prog_name; + int64 start_time; + + bool binaryupgrade; + + bool dummy_standby; + + struct GlobalSeqInfoHashBucket global_seq[NUM_GS_PARTITIONS]; + + struct GlobalPlanCache* plan_cache; + struct GlobalPrepareStmt* prepare_cache; + + struct PROC_HDR* proc_base; + slock_t proc_base_lock; + struct PGPROC** proc_base_all_procs; + struct PGXACT* proc_base_all_xacts; + struct PGPROC** proc_aux_base; + struct PGPROC** proc_preparexact_base; + struct ProcArrayStruct* proc_array_idx; + struct GsSignalBase* signal_base; + struct DistributeTestParam* distribute_test_param_instance; + + /* Set by the -o option */ + char ExtraOptions[MAXPGPATH]; + + /* load ir file count for each session */ + long codegen_IRload_process_count; + + struct HTAB* vec_func_hash; + + MemoryContext instance_context; + MemoryContext error_context; + MemoryContext signal_context; + MemoryContext increCheckPoint_context; + MemoryContext wal_context; + MemoryContext account_context; + MemoryContextGroup* mcxt_group; + + knl_instance_attr_t attr; + knl_g_stat_context stat_cxt; + knl_g_pid_context pid_cxt; + knl_g_cache_context cache_cxt; + knl_g_cost_context cost_cxt; + knl_g_comm_context comm_cxt; + knl_g_conn_context conn_cxt; + knl_g_libpq_context libpq_cxt; + struct knl_g_wlm_context* wlm_cxt; + knl_g_ckpt_context ckpt_cxt; + knl_g_ckpt_context* ckpt_cxt_ctl; + knl_g_bgwriter_context bgwriter_cxt; + struct knl_g_dw_context dw_batch_cxt; + struct knl_g_dw_context dw_single_cxt; + knl_g_shmem_context shmem_cxt; + knl_g_wal_context wal_cxt; + knl_g_executor_context exec_cxt; + knl_g_heartbeat_context heartbeat_cxt; + knl_g_rto_context rto_cxt; + knl_g_xlog_context xlog_cxt; + knl_g_numa_context numa_cxt; + knl_g_ts_compaction_context ts_compaction_cxt; + knl_g_security_policy_context policy_cxt; + knl_g_streaming_context streaming_cxt; + knl_g_csnminsync_context csnminsync_cxt; + knl_g_oid_nodename_mapping_cache oid_nodename_cache; + struct HTAB* ngroup_hash_table; +} knl_instance_context; + +extern void knl_instance_init(); +extern void knl_g_set_redo_finish_status(uint32 status); +extern bool knl_g_get_local_redo_finish_status(); +extern bool knl_g_get_redo_finish_status(); +extern knl_instance_context g_instance; + +extern void add_numa_alloc_info(void* numaAddr, size_t length); + +#define GTM_FREE_MODE (g_instance.attr.attr_storage.enable_gtm_free || \ + g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTMFREE) +#define GTM_MODE (!g_instance.attr.attr_storage.enable_gtm_free && \ + (g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTM)) +#define GTM_LITE_MODE (!g_instance.attr.attr_storage.enable_gtm_free && \ + g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTMLITE) + +#define REDO_FINISH_STATUS_LOCAL 0x00000001 +#define REDO_FINISH_STATUS_CM 0x00000002 + +#define ATOMIC_TRUE 1 +#define ATOMIC_FALSE 0 + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_H_ */ + diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_session.h postgresql-hll-2.14/include/include/knl/knl_session.h --- postgresql-hll-2.14_old/include/include/knl/knl_session.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_session.h 2020-12-12 17:06:43.215347625 +0800 @@ -0,0 +1,2367 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session.h + * Data stucture for session level global variables. + * + * several guidelines for put variables in knl_session.h + * + * variables which related to session only and can be decoupled with thread status + * should put int knl_session.h + * + * pay attention to memory allocation + * allocate runtime session variable in session context, which is highly recommended + * to do that. + * + * variables related to dedicated utility thread(wal, bgwrited, log...) usually put + * in knl_thread.h + * + * all context define below should follow naming rules: + * knl_u_sess->on_xxxx + * + * IDENTIFICATION + * src/include/knl/knl_session.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_H_ + +#include + +#include "c.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "knl/knl_guc.h" +#include "lib/dllist.h" +#include "lib/ilist.h" +#include "lib/stringinfo.h" +#include "libpq/pqcomm.h" +#include "nodes/pg_list.h" +#include "cipher.h" +#include "openssl/ossl_typ.h" +#include "portability/instr_time.h" +#include "storage/backendid.h" +#include "storage/s_lock.h" +#include "storage/shmem.h" +#include "utils/palloc.h" +#include "utils/memgroup.h" + +typedef void (*pg_on_exit_callback)(int code, Datum arg); + +/* all session level attribute which expose to user. */ +typedef struct knl_session_attr { + + knl_session_attr_sql attr_sql; + knl_session_attr_storage attr_storage; + knl_session_attr_security attr_security; + knl_session_attr_network attr_network; + knl_session_attr_memory attr_memory; + knl_session_attr_resource attr_resource; + knl_session_attr_common attr_common; +} knl_session_attr; + +typedef struct knl_u_stream_context { + uint32 producer_dop; + + uint32 smp_id; + + bool in_waiting_quit; + + bool dummy_thread; + + bool enter_sync_point; + + bool inStreamEnv; + + bool stop_mythread; + + ThreadId stop_pid; + + uint64 stop_query_id; + + class StreamNodeGroup* global_obj; + + class StreamProducer* producer_obj; +} knl_u_stream_context; + +typedef struct knl_u_executor_context { + List* remotequery_list; + + bool exec_result_checkqual_fail; + + bool executor_stop_flag; + + bool under_stream_runtime; + bool under_auto_explain; + + /* This variable indicates wheather the prescribed extension is supported */ + bool extension_is_valid; + + uint2* global_bucket_map; + + struct HTAB* vec_func_hash; + + struct PartitionIdentifier* route; + + struct TupleHashTableData* cur_tuple_hash_table; + + class lightProxy* cur_light_proxy_obj; + + /* + * ActivePortal is the currently executing Portal (the most closely nested, + * if there are several). + */ + struct PortalData* ActivePortal; + bool need_track_resource; + int nesting_level; + + HTAB* PortalHashTable; + unsigned int unnamed_portal_count; + /* the single instance for statement retry controll per thread*/ + struct StatementRetryController* RetryController; + + bool hasTempObject; + bool DfsDDLIsTopLevelXact; + /* global variable used to determine if we could cancel redistribution transaction */ + bool could_cancel_redistribution; + + bool g_pgaudit_agent_attached; + /* whether to track sql stats */ + bool pgaudit_track_sqlddl; + + struct HashScanListData* HashScans; + + /* the flag indicate the executor can stop, do not send anything to outer */ + bool executorStopFlag; + + struct OpFusion* CurrentOpFusionObj; + + int global_iteration; + + bool is_exec_trigger_func; + + bool single_shard_stmt; + struct SendRouter* CurrentRouter; + bool is_dn_enable_router; +} knl_u_executor_context; + +typedef struct knl_u_sig_context { + /* + * Flag to mark SIGHUP. Whenever the main loop comes around it + * will reread the configuration file. (Better than doing the + * reading in the signal handler, ey?) + */ + volatile sig_atomic_t got_SIGHUP; + + /* + * like got_PoolReload, but just for the compute pool. + * see CPmonitor_MainLoop for more details. + */ + volatile sig_atomic_t got_PoolReload; + volatile sig_atomic_t cp_PoolReload; +} knl_u_sig_context; + +typedef struct knl_u_SPI_context { +#define BUFLEN 64 +#define XACTMSGLEN 128 + + Oid lastoid; + + char buf[BUFLEN]; + + int _stack_depth; /* allocated size of _SPI_stack */ + + int _connected; + + int _curid; + + struct _SPI_connection* _stack; + + struct _SPI_connection* _current; + + HTAB* SPICacheTable; + + bool is_allow_commit_rollback; + char forbidden_commit_rollback_err_msg[XACTMSGLEN]; + + /* Is Procedure or Function. */ + bool is_stp; + + /* Whether procedure contains option setting guc. */ + bool is_proconfig_set; + + /* Recording the nested exception counts for commit/rollback statement after. */ + int portal_stp_exception_counter; + +} knl_u_SPI_context; + +typedef struct knl_u_index_context { + typedef uint64 XLogRecPtr; + XLogRecPtr counter; +} knl_u_index_context; + +typedef struct knl_u_instrument_context { + bool perf_monitor_enable; + + bool can_record_to_table; + + int operator_plan_number; + + bool OBS_instr_valid; + + bool* p_OBS_instr_valid; + + class StreamInstrumentation* global_instr; + + class ThreadInstrumentation* thread_instr; + + class OBSInstrumentation* obs_instr; + + struct Qpid* gs_query_id; + + struct BufferUsage* pg_buffer_usage; + + int plan_size; +} knl_u_instrument_context; + +typedef struct knl_u_analyze_context { + bool is_under_analyze; + + bool need_autoanalyze; + + MemoryContext analyze_context; + + struct AutoAnaProcess* autoanalyze_process; + + struct StringInfoData* autoanalyze_timeinfo; + + struct BufferAccessStrategyData* vac_strategy; +} knl_u_analyze_context; + +#define PATH_SEED_FACTOR_LEN 3 + +typedef struct knl_u_optimizer_context { + bool disable_dop_change; + + bool enable_nodegroup_explain; + + bool has_obsrel; + + bool is_stream; + + bool is_stream_support; + + bool is_multiple_nodegroup_scenario; + + /* Record the different nodegroup count for multi nodegroup scenario. */ + int different_nodegroup_count; + + bool is_randomfunc_shippable; + + bool is_dngather_support; + + int srvtype; + + int qrw_inlist2join_optmode; + + uint32 plan_current_seed; + + uint32 plan_prev_seed; + + uint16 path_current_seed_factor[PATH_SEED_FACTOR_LEN]; + + double cursor_tuple_fraction; + + /* Global variables used for parallel execution. */ + int query_dop_store; /* Store the dop. */ + + int query_dop; /* Degree of parallel, 1 means not parallel. */ + + double smp_thread_cost; + + /* u_sess->opt_cxt.max_query_dop: + * When used in dynamic smp, this variable set the max limit of dop + * <0 means turned off dynsmp. + * 0 means optimized dop based on query and resources + * 1 is the same as set u_sess->opt_cxt.query_dop=1 + * 2..n means max limit of dop + */ + int max_query_dop; + + int parallel_debug_mode; /* Control the parallel debug mode. */ + + int skew_strategy_opt; + + int op_work_mem; + + MemoryContext ft_context; + + struct Distribution* in_redistribution_group_distribution; + + struct Distribution* compute_permission_group_distribution; + + struct Distribution* query_union_set_group_distribution; + + struct Distribution* single_node_distribution; + + struct DynamicSmpInfo* dynamic_smp_info; + + struct PartitionIdentifier* bottom_seq; + + struct PartitionIdentifier* top_seq; + + struct HTAB* opr_proof_cache_hash; + + struct ShippingInfo* not_shipping_info; + + bool is_under_append_plan; +} knl_u_optimizer_context; + +typedef struct knl_u_parser_context { + bool eaten_begin; + + bool eaten_declare; + + bool has_dollar; + + bool has_placeholder; + + bool stmt_contains_operator_plus; + + List* hint_list; + + List* hint_warning; + + struct HTAB* opr_cache_hash; + + void* param_info; + + StringInfo param_message; + + MemoryContext ddl_pbe_context; +} knl_u_parser_context; + +typedef struct knl_u_trigger_context { + struct HTAB* ri_query_cache; + + struct HTAB* ri_compare_cache; + + bool exec_row_trigger_on_datanode; + + /* How many levels deep into trigger execution are we? */ + int MyTriggerDepth; + List* info_list; + struct AfterTriggersData* afterTriggers; +} knl_u_trigger_context; + +enum guc_choose_strategy { SINGLE_GUC = 0, DISTRIBUTE_GUC, MAX_GUC_STRATEGY}; + +typedef struct knl_u_utils_context { + char suffix_char; + + Oid suffix_collation; + + int test_err_type; + + /* + * While compute_array_stats is running, we keep a pointer to the extra data + * here for use by assorted subroutines. compute_array_stats doesn't + * currently need to be re-entrant, so avoiding this is not worth the extra + * notational cruft that would be needed. + */ + struct ArrayAnalyzeExtraData* array_extra_data; + + struct ItemPointerData* cur_last_tid; + + struct DistributeTestParam* distribute_test_param; + + struct PGLZ_HistEntry** hist_start; + + struct PGLZ_HistEntry* hist_entries; + + char* analysis_options_configure; + + int* guc_new_value; + + int GUC_check_errcode_value; + + TimestampTz lastFailedLoginTime; + + struct StringInfoData* input_set_message; /*Add for set command in transaction*/ + + char* GUC_check_errmsg_string; + + char* GUC_check_errdetail_string; + + char* GUC_check_errhint_string; + + HTAB* set_params_htab; + + struct config_generic** sync_guc_variables; + + struct config_bool* ConfigureNamesBool[MAX_GUC_STRATEGY]; + + struct config_int* ConfigureNamesInt[MAX_GUC_STRATEGY]; + + struct config_real* ConfigureNamesReal[MAX_GUC_STRATEGY]; + + struct config_int64* ConfigureNamesInt64; + + struct config_string* ConfigureNamesString[MAX_GUC_STRATEGY]; + + struct config_enum* ConfigureNamesEnum; + + int size_guc_variables; + + bool guc_dirty; /* TRUE if need to do commit/abort work */ + + bool reporting_enabled; /* TRUE to enable GUC_REPORT */ + + int GUCNestLevel; /* 1 when in main transaction */ + + unsigned int behavior_compat_flags; + + int save_argc; + + char** save_argv; + + /* Hash table to lookup combo cids by cmin and cmax */ + HTAB* comboHash; + + /* + * An array of cmin,cmax pairs, indexed by combo command id. + * To convert a combo cid to cmin and cmax, you do a simple array lookup. + */ + struct ComboCidKeyData* comboCids; + + /* use for stream producer thread */ + struct ComboCidKeyData* StreamParentComboCids; + + int usedComboCids; /* number of elements in comboCids */ + + int sizeComboCids; /* allocated size of array */ + + int StreamParentsizeComboCids; /* allocated size of array for StreamParentComboCids */ + + /* + * CurrentSnapshot points to the only snapshot taken in transaction-snapshot + * mode, and to the latest one taken in a read-committed transaction. + * SecondarySnapshot is a snapshot that's always up-to-date as of the current + * instant, even in transaction-snapshot mode. It should only be used for + * special-purpose code (say, RI checking.) + * + * These SnapshotData structs are static to simplify memory allocation + * (see the hack in GetSnapshotData to avoid repeated malloc/free). + */ + struct SnapshotData* CurrentSnapshotData; + + struct SnapshotData* SecondarySnapshotData; + + struct SnapshotData* CurrentSnapshot; + + struct SnapshotData* SecondarySnapshot; + + struct SnapshotData* CatalogSnapshot; + + struct SnapshotData* HistoricSnapshot; + + /* Staleness detection for CatalogSnapshot. */ + bool CatalogSnapshotStale; + + /* + * These are updated by GetSnapshotData. We initialize them this way + * for the convenience of TransactionIdIsInProgress: even in bootstrap + * mode, we don't want it to say that BootstrapTransactionId is in progress. + * + * RecentGlobalXmin and RecentGlobalDataXmin are initialized to + * InvalidTransactionId, to ensure that no one tries to use a stale + * value. Readers should ensure that it has been set to something else + * before using it. + */ + TransactionId TransactionXmin; + + TransactionId RecentXmin; + + TransactionId RecentGlobalXmin; + + TransactionId RecentGlobalDataXmin; + + /* Global snapshot data */ + bool cn_xc_maintain_mode; + int snapshot_source; + TransactionId gxmin; + TransactionId gxmax; + uint32 GtmTimeline; + struct GTM_SnapshotData* g_GTM_Snapshot; + uint64 g_snapshotcsn; + bool snapshot_need_sync_wait_all; + bool is_autovacuum_snapshot; + + /* (table, ctid) => (cmin, cmax) mapping during timetravel */ + HTAB* tuplecid_data; + + /* Top of the stack of active snapshots */ + struct ActiveSnapshotElt* ActiveSnapshot; + + /* + * How many snapshots is resowner.c tracking for us? + * + * Note: for now, a simple counter is enough. However, if we ever want to be + * smarter about advancing our MyPgXact->xmin we will need to be more + * sophisticated about this, perhaps keeping our own list of snapshots. + */ + int RegisteredSnapshots; + + /* first GetTransactionSnapshot call in a transaction? */ + bool FirstSnapshotSet; + + /* + * Remember the serializable transaction snapshot, if any. We cannot trust + * FirstSnapshotSet in combination with IsolationUsesXactSnapshot(), because + * GUC may be reset before us, changing the value of IsolationUsesXactSnapshot. + */ + struct SnapshotData* FirstXactSnapshot; + + /* Current xact's exported snapshots (a list of Snapshot structs) */ + List* exportedSnapshots; + + uint8_t g_output_version; /* Set the default output schema. */ + + int XactIsoLevel; + + /* a string list parsed from GUC variable (uuncontrolled_memory_context),see more @guc.cpp */ + struct memory_context_list* memory_context_limited_white_list; + +#ifdef ENABLE_QUNIT + int qunit_case_number; +#endif + + bool enable_memory_context_control; + + syscalllock deleMemContextMutex; +} knl_u_utils_context; + +typedef struct knl_u_security_context { + /* + * In common cases the same roleid (ie, the session or current ID) will + * be queried repeatedly. So we maintain a simple one-entry cache for + * the status of the last requested roleid. The cache can be flushed + * at need by watching for cache update events on pg_authid. + */ + Oid last_roleid; /* InvalidOid == cache not valid */ + + bool last_roleid_is_super; + + bool last_roleid_is_sysdba; + + bool last_roleid_is_securityadmin; /* Indicates whether a security admin */ + + bool last_roleid_is_auditadmin; /* Indicates whether an audit admin */ + + bool last_roleid_is_monitoradmin; /* Indicates whether a monitor admin */ + + bool last_roleid_is_operatoradmin; /* Indicates whether a operator admin */ + + bool last_roleid_is_policyadmin; /* Indicates whether a policy admin */ + + bool roleid_callback_registered; +} knl_u_security_context; + +typedef struct knl_u_commands_context { + /* Tablespace usage information management struct */ + struct TableSpaceUsageStruct* TableSpaceUsageArray; + bool isUnderCreateForeignTable; + + Oid CurrentExtensionObject; + + List* PendingLibraryDeletes; + TransactionId OldestXmin; + TransactionId FreezeLimit; + struct SeqTableData* seqtab; /* Head of list of SeqTable items */ + /* + * last_used_seq is updated by nextval() to point to the last used + * sequence. + */ + struct SeqTableData* last_used_seq; + + /* Form of the type created during inplace upgrade */ + char TypeCreateType; + + List* label_provider_list; + /* bulkload_compatible_illegal_chars and bulkload_copy_state are to be deleted */ + bool bulkload_compatible_illegal_chars; + + /* + * This variable ought to be a temperary fix for copy to file encoding bug caused by + * our modification to PGXC copy procejure. + */ + struct CopyStateData* bulkload_copy_state; + int dest_encoding_for_copytofile; + bool need_transcoding_for_copytofile; + MemoryContext OBSParserContext; + List* on_commits; + + /* + * Indicate that the top relation is temporary in my session. + * If it is, also we treat its all subordinate relations as temporary and in my session. + * For an example, if a column relation is temporary in my session, + * also its cudesc, cudesc index, delta are temporary and in my session. + */ + bool topRelatationIsInMyTempSession; + Node bogus_marker; /* marks conflicting defaults */ +} knl_u_commands_context; + +const int ELF_MAGIC_CACHE_LEN = 10; +typedef struct FileSlot { + FILE* file; + /* store header of file to detect a elf file */ + char elf_magic[ELF_MAGIC_CACHE_LEN]; + size_t max_linesize; + int encoding; + int32 id; +} FileSlot; + +typedef struct knl_u_contrib_context { + /* for assigning cursor numbers and prepared statement numbers */ + unsigned int cursor_number; + + int current_context_id; + int file_format; // enum DFSFileType + int file_number; + + struct FileSlot* slots; /* initilaized with zeros */ + int32 slotid; /* next slot id */ + int max_linesize; + char* cur_directory; + +} knl_u_contrib_context; + +#define LC_ENV_BUFSIZE (NAMEDATALEN + 20) + +typedef struct knl_u_locale_context { + /* lc_time localization cache */ + char* localized_abbrev_days[7]; + + char* localized_full_days[7]; + + char* localized_abbrev_months[12]; + + char* localized_full_months[12]; + + bool cur_lc_conv_valid; + + bool cur_lc_time_valid; + + struct lconv* cur_lc_conv; + + int lc_ctype_result; + + int lc_collate_result; + + struct HTAB* collation_cache; + + struct lconv current_lc_conv; +} knl_u_locale_context; + +typedef struct knl_u_log_context { + char* syslog_ident; + + char* module_logging_configure; + /* + * msgbuf is declared as static to save the data to put + * which can be flushed in next put_line() + */ + struct StringInfoData* msgbuf; +} knl_u_log_context; + +typedef struct knl_u_mb_context { + bool insertValuesBind_compatible_illegal_chars; + + List* ConvProcList; /* List of ConvProcInfo */ + + /* + * These variables point to the currently active conversion functions, + * or are NULL when no conversion is needed. + */ + struct FmgrInfo* ToServerConvProc; + + struct FmgrInfo* ToClientConvProc; + + NameData datcollate; /* LC_COLLATE setting */ + NameData datctype; /* LC_CTYPE setting */ + + /* + * These variables track the currently selected FE and BE encodings. + */ + struct pg_enc2name* ClientEncoding; + + struct pg_enc2name* DatabaseEncoding; + + struct pg_enc2name* PlatformEncoding; + + /* + * During backend startup we can't set client encoding because we (a) + * can't look up the conversion functions, and (b) may not know the database + * encoding yet either. So SetClientEncoding() just accepts anything and + * remembers it for InitializeClientEncoding() to apply later. + */ + bool backend_startup_complete; + + int pending_client_encoding; +} knl_u_mb_context; + +typedef struct knl_u_plancache_context { + /* + * This is the head of the backend's list of "saved" CachedPlanSources (i.e., + * those that are in long-lived storage and are examined for sinval events). + * We thread the structs manually instead of using List cells so that we can + * guarantee to save a CachedPlanSource without error. + */ + struct CachedPlanSource* first_saved_plan; + /* the head of plancache list not in gpc on cn. */ + struct CachedPlanSource* ungpc_saved_plan; + + /* + * If an unnamed prepared statement exists, it's stored here. + * We keep it separate from the hashtable kept by commands/prepare.c + * in order to reduce overhead for short-lived queries. + */ + struct CachedPlanSource* unnamed_stmt_psrc; + + /* recode if the query contains params, used in pgxc_shippability_walker */ + bool query_has_params; + + /* + * The hash table in which prepared queries are stored. This is + * per-backend: query plans are not shared between backends. + * The keys for this hash table are the arguments to PREPARE and EXECUTE + * (statement names); the entries are PreparedStatement structs. + */ + HTAB* prepared_queries; + + HTAB* stmt_lightproxy_htab; + + HTAB* lightproxy_objs; + + /* + * The hash table used to find OpFusions. + * The keys are portal names; + * the entries are OpFusion pointers. + */ + HTAB* pn_fusion_htab; + +#ifdef PGXC + /* + * The hash table where Datanode prepared statements are stored. + * The keys are statement names referenced from cached RemoteQuery nodes; the + * entries are DatanodeStatement structs + */ + HTAB* datanode_queries; +#endif + char* cur_stmt_name; /* cngpc non lp need set stmt_name in portal run */ + bool gpc_in_ddl; + bool gpc_remote_msg; + bool gpc_first_send; + bool gpc_in_try_store; +} knl_u_plancache_context; + +typedef struct knl_u_typecache_context { + /* The main type cache hashtable searched by lookup_type_cache */ + struct HTAB* TypeCacheHash; + + struct HTAB* RecordCacheHash; + + struct tupleDesc** RecordCacheArray; + + int32 RecordCacheArrayLen; /* allocated length of array */ + + int32 NextRecordTypmod; /* number of entries used */ +} knl_u_typecache_context; + +typedef struct knl_u_tscache_context { + struct HTAB* TSParserCacheHash; + + struct TSParserCacheEntry* lastUsedParser; + + struct HTAB* TSDictionaryCacheHash; + + struct TSDictionaryCacheEntry* lastUsedDictionary; + + struct HTAB* TSConfigCacheHash; + + struct TSConfigCacheEntry* lastUsedConfig; + + Oid TSCurrentConfigCache; +} knl_u_tscache_context; + +/* + * Description: + * There are three processing modes in POSTGRES. They are + * BootstrapProcessing or "bootstrap," InitProcessing or + * "initialization," and NormalProcessing or "normal." + * + * The first two processing modes are used during special times. When the + * system state indicates bootstrap processing, transactions are all given + * transaction id "one" and are consequently guaranteed to commit. This mode + * is used during the initial generation of template databases. + * + * Initialization mode: used while starting a backend, until all normal + * initialization is complete. Some code behaves differently when executed + * in this mode to enable system bootstrapping. + * + * If a POSTGRES backend process is in normal mode, then all code may be + * executed normally. + */ + +typedef enum ProcessingMode { + BootstrapProcessing, /* bootstrap creation of template database */ + InitProcessing, /* initializing system */ + NormalProcessing, /* normal processing */ + PostUpgradeProcessing /* Post upgrade to run script */ +} ProcessingMode; + +/* + * node group mode + * now we support two mode: common node group and logic cluster group + */ +typedef enum NodeGroupMode { + NG_UNKNOWN = 0, /* unknown mode */ + NG_COMMON, /* common node group */ + NG_LOGIC, /* logic cluster node group */ +} NodeGroupMode; + +typedef struct knl_u_misc_context { + enum ProcessingMode Mode; + + /* Note: we rely on this to initialize as zeroes */ + char socketLockFile[MAXPGPATH]; + char hasocketLockFile[MAXPGPATH]; + + /* ---------------------------------------------------------------- + * User ID state + * + * We have to track several different values associated with the concept + * of "user ID". + * + * AuthenticatedUserId is determined at connection start and never changes. + * + * SessionUserId is initially the same as AuthenticatedUserId, but can be + * changed by SET SESSION AUTHORIZATION (if AuthenticatedUserIsSuperuser). + * This is the ID reported by the SESSION_USER SQL function. + * + * OuterUserId is the current user ID in effect at the "outer level" (outside + * any transaction or function). This is initially the same as SessionUserId, + * but can be changed by SET ROLE to any role that SessionUserId is a + * member of. (XXX rename to something like CurrentRoleId?) + * + * CurrentUserId is the current effective user ID; this is the one to use + * for all normal permissions-checking purposes. At outer level this will + * be the same as OuterUserId, but it changes during calls to SECURITY + * DEFINER functions, as well as locally in some specialized commands. + * + * SecurityRestrictionContext holds flags indicating reason(s) for changing + * CurrentUserId. In some cases we need to lock down operations that are + * not directly controlled by privilege settings, and this provides a + * convenient way to do it. + * ---------------------------------------------------------------- + */ + Oid AuthenticatedUserId; + + Oid SessionUserId; + + Oid OuterUserId; + + Oid CurrentUserId; + + int SecurityRestrictionContext; + + const char* CurrentUserName; + + /* + * logic cluster information every backend. + */ + Oid current_logic_cluster; + + enum NodeGroupMode current_nodegroup_mode; + + bool nodegroup_callback_registered; + + /* + * Pseudo_CurrentUserId always refers to CurrentUserId, except in executing stored procedure, + * in that case, Pseudo_CurrentUserId refers to the user id that created the stored procedure. + */ + Oid* Pseudo_CurrentUserId; + + /* We also have to remember the superuser state of some of these levels */ + bool AuthenticatedUserIsSuperuser; + + bool SessionUserIsSuperuser; + + /* We also remember if a SET ROLE is currently active */ + bool SetRoleIsActive; + + /* Flag telling that we are loading shared_preload_libraries */ + bool process_shared_preload_libraries_in_progress; + + /* Flag telling that authentication already finish */ + bool authentication_finished; +} knl_misc_context; + +typedef struct knl_u_proc_context { + struct Port* MyProcPort; + + char firstChar = ' '; + + Oid MyRoleId; + + Oid MyDatabaseId; + + Oid MyDatabaseTableSpace; + + /* + * DatabasePath is the path (relative to t_thrd.proc_cxt.DataDir) of my database's + * primary directory, ie, its directory in the default tablespace. + */ + char* DatabasePath; + + bool Isredisworker; + bool IsInnerMaintenanceTools; /* inner tool check flag */ + bool clientIsGsrewind; /* gs_rewind tool check flag */ + bool clientIsGsredis; /* gs_redis tool check flag */ + bool clientIsGsdump; /* gs_dump tool check flag */ + bool clientIsGsCtl; /* gs_ctl tool check flag */ + bool clientIsGsBasebackup; /* gs_basebackup tool check flag */ + bool clientIsGsroach; /* gs_roach tool check flag */ + bool clientIsGsRestore; /* gs_restore tool check flag */ + bool IsBinaryUpgrade; + bool IsWLMWhiteList; /* this proc will not be controled by WLM */ + bool gsRewindAddCount; + bool PassConnLimit; +} knl_u_proc_context; + +/* maximum possible number of fields in a date string */ +#define MAXDATEFIELDS 25 + +typedef struct knl_u_time_context { + /* + * DateOrder defines the field order to be assumed when reading an + * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit + * year field first, is taken to be ambiguous): + * DATEORDER_YMD specifies field order yy-mm-dd + * DATEORDER_DMY specifies field order dd-mm-yy ("European" convention) + * DATEORDER_MDY specifies field order mm-dd-yy ("US" convention) + * + * In the Postgres and SQL DateStyles, DateOrder also selects output field + * order: day comes before month in DMY style, else month comes before day. + * + * The user-visible "DateStyle" run-time parameter subsumes both of these. + */ + int DateStyle; + + int DateOrder; + + /* + * u_sess->time_cxt.HasCTZSet is true if user has set timezone as a numeric offset from UTC. + * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish + * sign convention, ie, positive offset is west of UTC, rather than the + * SQL-ish convention that positive is east of UTC). + */ + bool HasCTZSet; + + int CTimeZone; + + int sz_timezone_tktbl; + + /* + * datetktbl holds date/time keywords. + * + * Note that this table must be strictly alphabetically ordered to allow an + * O(ln(N)) search algorithm to be used. + * + * The text field is NOT guaranteed to be NULL-terminated. + * + * To keep this table reasonably small, we divide the lexval for TZ and DTZ + * entries by 15 (so they are on 15 minute boundaries) and truncate the text + * field at TOKMAXLEN characters. + * Formerly, we divided by 10 rather than 15 but there are a few time zones + * which are 30 or 45 minutes away from an even hour, most are on an hour + * boundary, and none on other boundaries. + * + * The static table contains no TZ or DTZ entries, rather those are loaded + * from configuration files and stored in t_thrd.time_cxt.timezone_tktbl, which has the same + * format as the static datetktbl. + */ + struct datetkn* timezone_tktbl; + + const struct datetkn* datecache[MAXDATEFIELDS]; + + const struct datetkn* deltacache[MAXDATEFIELDS]; + + struct HTAB* timezone_cache; +} knl_u_time_context; + +typedef struct knl_u_upgrade_context { + bool InplaceUpgradeSwitch; +#ifndef WIN32 + PGDLLIMPORT Oid binary_upgrade_next_etbl_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_array_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_heap_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_index_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_heap_pg_class_rfoid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_index_pg_class_rfoid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_class_rfoid; +#endif + /* Potentially set by contrib/pg_upgrade_support functions */ + Oid binary_upgrade_next_array_pg_type_oid; + Oid Inplace_upgrade_next_array_pg_type_oid; + + /* Potentially set by contrib/pg_upgrade_support functions */ + Oid binary_upgrade_next_pg_authid_oid; + + Oid binary_upgrade_next_toast_pg_type_oid; + int32 binary_upgrade_max_part_toast_pg_type_oid; + int32 binary_upgrade_cur_part_toast_pg_type_oid; + Oid* binary_upgrade_next_part_toast_pg_type_oid; + Oid binary_upgrade_next_heap_pg_class_oid; + Oid binary_upgrade_next_toast_pg_class_oid; + Oid binary_upgrade_next_heap_pg_class_rfoid; + Oid binary_upgrade_next_toast_pg_class_rfoid; + int32 binary_upgrade_max_part_pg_partition_oid; + int32 binary_upgrade_cur_part_pg_partition_oid; + Oid* binary_upgrade_next_part_pg_partition_oid; + int32 binary_upgrade_max_part_pg_partition_rfoid; + int32 binary_upgrade_cur_part_pg_partition_rfoid; + Oid* binary_upgrade_next_part_pg_partition_rfoid; + int32 binary_upgrade_max_part_toast_pg_class_oid; + int32 binary_upgrade_cur_part_toast_pg_class_oid; + Oid* binary_upgrade_next_part_toast_pg_class_oid; + int32 binary_upgrade_max_part_toast_pg_class_rfoid; + int32 binary_upgrade_cur_part_toast_pg_class_rfoid; + Oid* binary_upgrade_next_part_toast_pg_class_rfoid; + Oid binary_upgrade_next_partrel_pg_partition_oid; + Oid binary_upgrade_next_partrel_pg_partition_rfoid; + Oid Inplace_upgrade_next_heap_pg_class_oid; + Oid Inplace_upgrade_next_toast_pg_class_oid; + Oid binary_upgrade_next_index_pg_class_oid; + Oid binary_upgrade_next_index_pg_class_rfoid; + int32 binary_upgrade_max_part_index_pg_class_oid; + int32 binary_upgrade_cur_part_index_pg_class_oid; + Oid* binary_upgrade_next_part_index_pg_class_oid; + int32 binary_upgrade_max_part_index_pg_class_rfoid; + int32 binary_upgrade_cur_part_index_pg_class_rfoid; + Oid* binary_upgrade_next_part_index_pg_class_rfoid; + int32 bupgrade_max_psort_pg_class_oid; + int32 bupgrade_cur_psort_pg_class_oid; + Oid* bupgrade_next_psort_pg_class_oid; + int32 bupgrade_max_psort_pg_type_oid; + int32 bupgrade_cur_psort_pg_type_oid; + Oid* bupgrade_next_psort_pg_type_oid; + int32 bupgrade_max_psort_array_pg_type_oid; + int32 bupgrade_cur_psort_array_pg_type_oid; + Oid* bupgrade_next_psort_array_pg_type_oid; + int32 bupgrade_max_psort_pg_class_rfoid; + int32 bupgrade_cur_psort_pg_class_rfoid; + Oid* bupgrade_next_psort_pg_class_rfoid; + Oid Inplace_upgrade_next_index_pg_class_oid; + Oid binary_upgrade_next_pg_enum_oid; + Oid Inplace_upgrade_next_general_oid; + int32 bupgrade_max_cudesc_pg_class_oid; + int32 bupgrade_cur_cudesc_pg_class_oid; + Oid* bupgrade_next_cudesc_pg_class_oid; + int32 bupgrade_max_cudesc_pg_type_oid; + int32 bupgrade_cur_cudesc_pg_type_oid; + Oid* bupgrade_next_cudesc_pg_type_oid; + int32 bupgrade_max_cudesc_array_pg_type_oid; + int32 bupgrade_cur_cudesc_array_pg_type_oid; + Oid* bupgrade_next_cudesc_array_pg_type_oid; + int32 bupgrade_max_cudesc_pg_class_rfoid; + int32 bupgrade_cur_cudesc_pg_class_rfoid; + Oid* bupgrade_next_cudesc_pg_class_rfoid; + int32 bupgrade_max_cudesc_index_oid; + int32 bupgrade_cur_cudesc_index_oid; + Oid* bupgrade_next_cudesc_index_oid; + int32 bupgrade_max_cudesc_toast_pg_class_oid; + int32 bupgrade_cur_cudesc_toast_pg_class_oid; + Oid* bupgrade_next_cudesc_toast_pg_class_oid; + int32 bupgrade_max_cudesc_toast_pg_type_oid; + int32 bupgrade_cur_cudesc_toast_pg_type_oid; + Oid* bupgrade_next_cudesc_toast_pg_type_oid; + int32 bupgrade_max_cudesc_toast_index_oid; + int32 bupgrade_cur_cudesc_toast_index_oid; + Oid* bupgrade_next_cudesc_toast_index_oid; + int32 bupgrade_max_cudesc_index_rfoid; + int32 bupgrade_cur_cudesc_index_rfoid; + Oid* bupgrade_next_cudesc_index_rfoid; + int32 bupgrade_max_cudesc_toast_pg_class_rfoid; + int32 bupgrade_cur_cudesc_toast_pg_class_rfoid; + Oid* bupgrade_next_cudesc_toast_pg_class_rfoid; + int32 bupgrade_max_cudesc_toast_index_rfoid; + int32 bupgrade_cur_cudesc_toast_index_rfoid; + Oid* bupgrade_next_cudesc_toast_index_rfoid; + int32 bupgrade_max_delta_toast_pg_class_oid; + int32 bupgrade_cur_delta_toast_pg_class_oid; + Oid* bupgrade_next_delta_toast_pg_class_oid; + int32 bupgrade_max_delta_toast_pg_type_oid; + int32 bupgrade_cur_delta_toast_pg_type_oid; + Oid* bupgrade_next_delta_toast_pg_type_oid; + int32 bupgrade_max_delta_toast_index_oid; + int32 bupgrade_cur_delta_toast_index_oid; + Oid* bupgrade_next_delta_toast_index_oid; + int32 bupgrade_max_delta_toast_pg_class_rfoid; + int32 bupgrade_cur_delta_toast_pg_class_rfoid; + Oid* bupgrade_next_delta_toast_pg_class_rfoid; + int32 bupgrade_max_delta_toast_index_rfoid; + int32 bupgrade_cur_delta_toast_index_rfoid; + Oid* bupgrade_next_delta_toast_index_rfoid; + int32 bupgrade_max_delta_pg_class_oid; + int32 bupgrade_cur_delta_pg_class_oid; + Oid* bupgrade_next_delta_pg_class_oid; + int32 bupgrade_max_delta_pg_type_oid; + int32 bupgrade_cur_delta_pg_type_oid; + Oid* bupgrade_next_delta_pg_type_oid; + int32 bupgrade_max_delta_array_pg_type_oid; + int32 bupgrade_cur_delta_array_pg_type_oid; + Oid* bupgrade_next_delta_array_pg_type_oid; + int32 bupgrade_max_delta_pg_class_rfoid; + int32 bupgrade_cur_delta_pg_class_rfoid; + Oid* bupgrade_next_delta_pg_class_rfoid; + Oid Inplace_upgrade_next_pg_proc_oid; + Oid Inplace_upgrade_next_pg_namespace_oid; + Oid binary_upgrade_next_pg_type_oid; + Oid Inplace_upgrade_next_pg_type_oid; + bool new_catalog_isshared; + bool new_catalog_need_storage; + List* new_shared_catalog_list; +} knl_u_upgrade_context; + +typedef struct knl_u_bootstrap_context { +#define MAXATTR 40 +#define NAMEDATALEN 64 + int num_columns_read; + int yyline; /* line number for error reporting */ + + struct RelationData* boot_reldesc; /* current relation descriptor */ + struct FormData_pg_attribute* attrtypes[MAXATTR]; /* points to attribute info */ + int numattr; /* number of attributes for cur. rel */ + + struct typmap** Typ; + struct typmap* Ap; + + MemoryContext nogc; /* special no-gc mem context */ + struct _IndexList* ILHead; + char newStr[NAMEDATALEN + 1]; /* array type names < NAMEDATALEN long */ +} knl_u_bootstrap_context; + +typedef enum { + IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */ + IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */ + IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */ +} IdentifierLookup; + +typedef struct knl_u_xact_context { + struct XactCallbackItem* Xact_callbacks; + struct SubXactCallbackItem* SubXact_callbacks; +#ifdef PGXC + struct abort_callback_type* dbcleanup_info; +#endif + + /* + * GID to be used for preparing the current transaction. This is also + * global to a whole transaction, so we don't keep it in the state stack. + */ + char* prepareGID; + char* savePrepareGID; + + bool pbe_execute_complete; +} knl_u_xact_context; + +typedef struct knl_u_plpgsql_context { + bool inited; + /* pl_comp.cpp */ + /* A context for func to store in one session. */ + MemoryContext plpgsql_func_cxt; + /* ---------- + * Hash table for compiled functions + * ---------- + */ + HTAB* plpgsql_HashTable; + /* list of functions' cell. */ + DList* plpgsql_dlist_functions; + + int datums_alloc; + int plpgsql_nDatums; + int datums_last; + int plpgsql_IndexErrorVariable; + char* plpgsql_error_funcname; + bool plpgsql_DumpExecTree; + bool plpgsql_check_syntax; + /* A context appropriate for short-term allocs during compilation */ + MemoryContext compile_tmp_cxt; + struct PLpgSQL_stmt_block* plpgsql_parse_result; + struct PLpgSQL_datum** plpgsql_Datums; + struct PLpgSQL_function* plpgsql_curr_compile; + + /* pl_exec.cpp */ + struct EState* simple_eval_estate; + struct SimpleEcontextStackEntry* simple_econtext_stack; + + /* + * "context_array" is allocated from top_transaction_mem_cxt, but the variables inside + * of SQLContext is created under "SQLContext Entry" memory context. + */ + List* context_array; + + /* pl_handler.cpp */ + int plpgsql_variable_conflict; + /* Hook for plugins */ + struct PLpgSQL_plugin** plugin_ptr; + + /* pl_funcs.cpp */ + int dump_indent; + + /* pl_funcs.cpp */ + /* ---------- + * Local variables for namespace handling + * + * The namespace structure actually forms a tree, of which only one linear + * list or "chain" (from the youngest item to the root) is accessible from + * any one plpgsql statement. During initial parsing of a function, ns_top + * points to the youngest item accessible from the block currently being + * parsed. We store the entire tree, however, since at runtime we will need + * to access the chain that's relevant to any one statement. + * + * Block boundaries in the namespace chain are marked by PLPGSQL_NSTYPE_LABEL + * items. + * ---------- + */ + struct PLpgSQL_nsitem* ns_top; + + /* pl_scanner.cpp */ + /* Klugy flag to tell scanner how to look up identifiers */ + IdentifierLookup plpgsql_IdentifierLookup; + /* + * Scanner working state. At some point we might wish to fold all this + * into a YY_EXTRA struct. For the moment, there is no need for plpgsql's + * lexer to be re-entrant, and the notational burden of passing a yyscanner + * pointer around is great enough to not want to do it without need. + */ + + /* The stuff the core lexer needs(core_yyscan_t) */ + void* yyscanner; + struct core_yy_extra_type* core_yy; + + /* The original input string */ + const char* scanorig; + + /* Current token's length (corresponds to plpgsql_yylval and plpgsql_yylloc) */ + int plpgsql_yyleng; + + /* Token pushback stack */ +#define MAX_PUSHBACKS 4 + + int num_pushbacks; + int pushback_token[MAX_PUSHBACKS]; + + /* State for plpgsql_location_to_lineno() */ + const char* cur_line_start; + const char* cur_line_end; + int cur_line_num; + List* goto_labels; + + struct HTAB* rendezvousHash; + + /* dbe.output buffer limit */ + uint32 dbe_output_buffer_limit; + + bool is_delete_function; +} knl_u_plpgsql_context; + +typedef struct knl_u_postgres_context { + /* + * Flags to implement skip-till-Sync-after-error behavior for messages of + * the extended query protocol. + */ + bool doing_extended_query_message; + bool ignore_till_sync; +} knl_u_postgres_context; + +typedef struct knl_u_stat_context { + char* pgstat_stat_filename; + char* pgstat_stat_tmpname; + + struct HTAB* pgStatDBHash; + struct TabStatusArray* pgStatTabList; + + /* + * BgWriter global statistics counters (unused in other processes). + * Stored directly in a stats message structure so it can be sent + * without needing to copy things around. We assume this inits to zeroes. + */ + struct PgStat_MsgBgWriter* BgWriterStats; + + /* + * Hash table for O(1) t_id -> tsa_entry lookup + */ + HTAB* pgStatTabHash; + /* MemoryContext for pgStatTabHash */ + MemoryContext pgStatTabHashContext; + + /* + * Backends store per-function info that's waiting to be sent to the collector + * in this hash table (indexed by function OID). + */ + struct HTAB* pgStatFunctions; + + /* + * Indicates if backend has some function stats that it hasn't yet + * sent to the collector. + */ + bool have_function_stats; + + bool pgStatRunningInCollector; + + struct PgStat_SubXactStatus* pgStatXactStack; + + int pgStatXactCommit; + + int pgStatXactRollback; + + int64 pgStatBlockReadTime; + + int64 pgStatBlockWriteTime; + + struct PgBackendStatus* localBackendStatusTable; + + int localNumBackends; + + /* + * Cluster wide statistics, kept in the stats collector. + * Contains statistics that are not collected per database + * or per table. + */ + struct PgStat_GlobalStats* globalStats; + + /* + * Total time charged to functions so far in the current backend. + * We use this to help separate "self" and "other" time charges. + * (We assume this initializes to zero.) + */ + instr_time total_func_time; + + struct HTAB* analyzeCheckHash; + + union NumericValue* osStatDataArray; + struct OSRunInfoDesc* osStatDescArray; + TimestampTz last_report; + bool isTopLevelPlSql; + int64* localTimeInfoArray; + uint64* localNetInfo; + + MemoryContext pgStatLocalContext; + MemoryContext pgStatCollectThdStatusContext; + + /* Track memory usage in chunks at individual session level */ + int32 trackedMemChunks; + + /* Track memory usage in bytes at individual session level */ + int64 trackedBytes; + + List* hotkeyCandidates; + MemoryContext hotkeySessContext; +} knl_u_stat_context; + +#define MAX_LOCKMETHOD 2 + +typedef uint16 CycleCtr; +typedef void* Block; +typedef struct knl_u_storage_context { + /* + * How many buffers PrefetchBuffer callers should try to stay ahead of their + * ReadBuffer calls by. This is maintained by the assign hook for + * effective_io_concurrency. Zero means "never prefetch". + */ + int target_prefetch_pages; + + volatile bool session_timeout_active; + /* session_fin_time is valid only if session_timeout_active is true */ + TimestampTz session_fin_time; + + /* Number of file descriptors known to be in use by VFD entries. */ + int nfile; + + /* + * Flag to tell whether it's worth scanning VfdCache looking for temp files + * to close + */ + bool have_xact_temporary_files; + /* + * Tracks the total size of all temporary files. Note: when temp_file_limit + * is being enforced, this cannot overflow since the limit cannot be more + * than INT_MAX kilobytes. When not enforcing, it could theoretically + * overflow, but we don't care. + */ + uint64 temporary_files_size; + int numAllocatedDescs; + int maxAllocatedDescs; + struct AllocateDesc* allocatedDescs; + /* + * Number of temporary files opened during the current session; + * this is used in generation of tempfile names. + */ + long tempFileCounter; + /* + * Array of OIDs of temp tablespaces. When numTempTableSpaces is -1, + * this has not been set in the current transaction. + */ + Oid* tempTableSpaces; + int numTempTableSpaces; + int nextTempTableSpace; + /* record how many IO request submit in async mode, because if error happen, + * we should distinguish which IOs has been submit, if not, the resource clean will + * meet error like ref_count, flags + * remember set AsyncSubmitIOCount to 0 after resource clean up sucessfully + */ + int AsyncSubmitIOCount; + + /* + * Virtual File Descriptor array pointer and size. This grows as + * needed. 'File' values are indexes into this array. + * Note that VfdCache[0] is not a usable VFD, just a list header. + */ + struct vfd* VfdCache; + Size SizeVfdCache; + + /* + * Each backend has a hashtable that stores all extant SMgrRelation objects. + * In addition, "unowned" SMgrRelation objects are chained together in a list. + */ + struct HTAB* SMgrRelationHash; + dlist_head unowned_reln; + + MemoryContext MdCxt; /* context for all md.c allocations */ + struct HTAB* pendingOpsTable; + List* pendingUnlinks; + CycleCtr mdsync_cycle_ctr; + CycleCtr mdckpt_cycle_ctr; + bool mdsync_in_progress; + + LocalTransactionId nextLocalTransactionId; + + /* + * Whether current session is holding a session lock after transaction commit. + * This may appear ugly, but since at present all lock information is stored in + * per-thread pgproc, we should not decouple session from thread if session lock + * is held. + * We now set this flag at LockReleaseAll phase during transaction commit or abort. + * As a result, all callbackups for releasing session locks should come before it. + */ + bool holdSessionLock[MAX_LOCKMETHOD]; + + /* true if datanode is within the process of two phase commit */ + bool twoPhaseCommitInProgress; + int32 dumpHashbucketIdNum; + int2 *dumpHashbucketIds; + + /* Pointers to shared state */ + // struct BufferStrategyControl* StrategyControl; + int NLocBuffer; /* until buffers are initialized */ + struct BufferDesc* LocalBufferDescriptors; + Block* LocalBufferBlockPointers; + int32* LocalRefCount; + int nextFreeLocalBuf; + struct HTAB* LocalBufHash; + char* cur_block; + int next_buf_in_block; + int num_bufs_in_block; + int total_bufs_allocated; + MemoryContext LocalBufferContext; +} knl_u_storage_context; + + +typedef struct knl_u_libpq_context { + /* + * LO "FD"s are indexes into the cookies array. + * + * A non-null entry is a pointer to a LargeObjectDesc allocated in the + * LO private memory context "fscxt". The cookies array itself is also + * dynamically allocated in that context. Its current allocated size is + * cookies_len entries, of which any unused entries will be NULL. + */ + struct LargeObjectDesc** cookies; + int cookies_size; + MemoryContext fscxt; + GS_UCHAR* server_key; + + /* + * These variables hold the pre-parsed contents of the ident usermap + * configuration file. ident_lines is a triple-nested list of lines, fields + * and tokens, as returned by tokenize_file. There will be one line in + * ident_lines for each (non-empty, non-comment) line of the file. Note there + * will always be at least one field, since blank lines are not entered in the + * data structure. ident_line_nums is an integer list containing the actual + * line number for each line represented in ident_lines. ident_context is + * the memory context holding all this. + */ + List* ident_lines; + List* ident_line_nums; + MemoryContext ident_context; + bool IsConnFromCmAgent; +#ifdef USE_SSL + bool ssl_loaded_verify_locations; + bool ssl_initialized; + SSL_CTX* SSL_server_context; +#endif +} knl_u_libpq_context; + +typedef struct knl_u_relcache_context { + struct HTAB* RelationIdCache; + + /* + * This flag is false until we have prepared the critical relcache entries + * that are needed to do indexscans on the tables read by relcache building. + * Should be used only by relcache.c and catcache.c + */ + bool criticalRelcachesBuilt; + + /* + * This flag is false until we have prepared the critical relcache entries + * for shared catalogs (which are the tables needed for login). + * Should be used only by relcache.c and postinit.c + */ + bool criticalSharedRelcachesBuilt; + + /* + * This counter counts relcache inval events received since backend startup + * (but only for rels that are actually in cache). Presently, we use it only + * to detect whether data about to be written by write_relcache_init_file() + * might already be obsolete. + */ + long relcacheInvalsReceived; + + /* + * This list remembers the OIDs of the non-shared relations cached in the + * database's local relcache init file. Note that there is no corresponding + * list for the shared relcache init file, for reasons explained in the + * comments for RelationCacheInitFileRemove. + */ + List* initFileRelationIds; + + /* + * This flag lets us optimize away work in AtEO(Sub)Xact_RelationCache(). + */ + bool need_eoxact_work; + + HTAB* OpClassCache; + + struct tupleDesc* pgclassdesc; + + struct tupleDesc* pgindexdesc; + + /* + * BucketMap Cache, consists of a list of BucketMapCache element. + * Location information of every rel cache is actually pointed to these list + * members. + * Attention: we need to invalidate bucket map caches when accepting + * SI messages of tuples in PGXC_GROUP or SI reset messages! + */ + List* g_bucketmap_cache; + uint32 max_bucket_map_size; + + /* + * These three vaiables are used to preserve pointers to old tupleDescs when processing invalid messages. + * Because old tupleDescs maybe referenced by other data structures, we can not free them when process invalid + * messages. So we save them to an array first, and free them in a batch when the transaction ends; + * + * Please refer to RememberToFreeTupleDescAtEOX and AtEOXact_FreeTupleDesc for detailed information. + */ + struct tupleDesc **EOXactTupleDescArray; + int NextEOXactTupleDescNum; + int EOXactTupleDescArrayLen; +} knl_u_relcache_context; + +#if defined(HAVE_SETPROCTITLE) +#define PS_USE_SETPROCTITLE +#elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD) +#define PS_USE_PSTAT +#elif defined(HAVE_PS_STRINGS) +#define PS_USE_PS_STRINGS +#elif (defined(BSD) || defined(__hurd__)) && !defined(__darwin__) +#define PS_USE_CHANGE_ARGV +#elif defined(__linux__) || defined(_AIX) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(ultrix) || \ + defined(__ksr__) || defined(__osf__) || defined(__svr5__) || defined(__darwin__) +#define PS_USE_CLOBBER_ARGV +#elif defined(WIN32) +#define PS_USE_WIN32 +#else +#define PS_USE_NONE +#endif + +typedef struct knl_u_ps_context { +#ifndef PS_USE_CLOBBER_ARGV +/* all but one option need a buffer to write their ps line in */ +#define PS_BUFFER_SIZE 256 + char ps_buffer[PS_BUFFER_SIZE]; + size_t ps_buffer_size; +#else /* PS_USE_CLOBBER_ARGV */ + char* ps_buffer; /* will point to argv area */ + size_t ps_buffer_size; /* space determined at run time */ + size_t last_status_len; /* use to minimize length of clobber */ +#endif /* PS_USE_CLOBBER_ARGV */ + size_t ps_buffer_cur_len; /* nominal strlen(ps_buffer) */ + size_t ps_buffer_fixed_size; /* size of the constant prefix */ + + /* save the original argv[] location here */ + int save_argc; + char** save_argv; +} knl_u_ps_context; + +typedef struct ParctlState { + unsigned char global_reserve; /* global reserve active statement flag */ + unsigned char rp_reserve; /* resource pool reserve active statement flag */ + unsigned char reserve; /* reserve active statement flag */ + unsigned char release; /* release active statement flag */ + unsigned char global_release; /* global release active statement */ + unsigned char rp_release; /* resource pool release active statement */ + unsigned char except; /* a flag to handle exception while the query executing */ + unsigned char special; /* check the query whether is a special query */ + unsigned char transact; /* check the query whether is in a transaction block*/ + unsigned char transact_begin; /* check the query if "begin transaction" */ + unsigned char simple; /* check the query whether is a simple query */ + unsigned char iocomplex; /* check the query whether is a IO simple query */ + unsigned char enqueue; /* check the query whether do global parallel control */ + unsigned char errjmp; /* this is error jump point */ + unsigned char global_waiting; /* waiting in the global list */ + unsigned char respool_waiting; /* waiting in the respool list */ + unsigned char preglobal_waiting; /* waiting in simple global list */ + unsigned char central_waiting; /* waiting in central_waiting */ + unsigned char attach; /* attach cgroup */ + unsigned char subquery; /* check the query whether is in a stored procedure */ + +} ParctlState; + +typedef struct knl_u_relmap_context { + /* + * The currently known contents of the shared map file and our database's + * local map file are stored here. These can be reloaded from disk + * immediately whenever we receive an update sinval message. + */ + struct RelMapFile* shared_map; + struct RelMapFile* local_map; + + /* + * We use the same RelMapFile data structure to track uncommitted local + * changes in the mappings (but note the magic and crc fields are not made + * valid in these variables). Currently, map updates are not allowed within + * subtransactions, so one set of transaction-level changes is sufficient. + * + * The active_xxx variables contain updates that are valid in our transaction + * and should be honored by RelationMapOidToFilenode. The pending_xxx + * variables contain updates we have been told about that aren't active yet; + * they will become active at the next CommandCounterIncrement. This setup + * lets map updates act similarly to updates of pg_class rows, ie, they + * become visible only at the next CommandCounterIncrement boundary. + */ + struct RelMapFile* active_shared_updates; + struct RelMapFile* active_local_updates; + struct RelMapFile* pending_shared_updates; + struct RelMapFile* pending_local_updates; + + /* Hash table for informations about each relfilenode <-> oid pair */ + struct HTAB* RelfilenodeMapHash; +} knl_u_relmap_context; + +typedef struct knl_u_unique_sql_context { + /* each sql should have one unique query id + * limitation: Query* is needed by calculating unique query id, + * and Query * is generated after parsing and + * rewriting SQL, so unique query id only can be used + * after SQL rewrite + */ + uint64 unique_sql_id; + Oid unique_sql_user_id; + uint32 unique_sql_cn_id; + + /* + * storing unique sql start time, + * in PortalRun method, we will update unique sql elapse time, + * use it to store the start time. + * + * Note: as in exec_simple_query, we can get multi parsetree, + * and will generate multi the unique sql id, so we set + * unique_sql_start_time at each LOOP(parsetree) started + * + * exec_simple_query + * + * pg_parse_query(parsetree List) + * + * LOOP start + * ****-> set unique_sql_start_time + * pg_analyze_and_rewrite + * analyze + * rewrite + * pg_plan_queries + * PortalStart + * PortalRun + * ****-> UpdateUniqueSQLStat/UpdateUniqueSQLElapseTime + * PortalDrop + * + * LOOP end + */ + int64 unique_sql_start_time; + + /* unique sql's returned rows counter, only updated on CN */ + uint64 unique_sql_returned_rows_counter; + + /* parse counter, both CN and DN can update the counter */ + uint64 unique_sql_soft_parse; + uint64 unique_sql_hard_parse; + + /* + * last_stat_counter - store pgStatTabList's total counter values when + * exit from pgstat_report_stat last time + * current_table_counter - store current unique sql id's row activity stat + */ + struct PgStat_TableCounts* last_stat_counter; + struct PgStat_TableCounts* current_table_counter; + + /* + * handle multi SQLs case in exec_simple_query function, + * for below case: + * - we send sqls "select * from xx; update xx;" using libpq + * PQexec method(refer to gs_ctl tool) + * - then exec_simple_query will get two SQLs + * - pg_parse_query will generate parsetree list with two nodes + * - then run twice: + * # call unique_sql_post_parse_analyze(generate unique sql id/ + * normalized sql string) + * -- here we get the sql using debug_query_string or ParseState.p_sourcetext + * -- but the two way to get sql string will be two SQLs, not single one + * -- so we need add below two variables to handle this case + * # call PortalDefineQuery + * # call PortalRun -> update unique sql stat + */ + bool is_multi_unique_sql; + char* curr_single_unique_sql; + + /* + * for case unique sql track type is 'UNIQUE_SQL_TRACK_TOP' + * main logic(only happened on CN): + * - postgresmain + * >> is_top_unique_sql = false + * + * - sql parse -> generate unique sql id(top SQL) + * >> is_top_unique_sql = true + * + * - exec_simple_query + * or exec_bind_message + * >> PortalRun -> using TOP SQL's unique sql id(will sned to DN) + * + * - is_top_unique_sql to false + */ + bool is_top_unique_sql; + bool need_update_calls; + + /* sort and hash instrment states */ + struct unique_sql_sorthash_instr* unique_sql_sort_instr; + struct unique_sql_sorthash_instr* unique_sql_hash_instr; + + /* handle nested portal calling */ + uint32 portal_nesting_level; +} knl_u_unique_sql_context; + +typedef struct unique_sql_sorthash_instr { + bool has_sorthash; /* true if query contains sort/hash operation */ + uint64 counts; /* # of operation during unique sql */ + int64 used_work_mem; /* space of used work mem by kbs */ + TimestampTz enter_time; /* time stamp at the start point */ + TimestampTz total_time; /* execution time */ + uint64 spill_counts; /* # of spill times during the operation */ + uint64 spill_size; /* spill size for temp table by kbs */ +} unique_sql_sorthash_instr; + +typedef struct knl_u_percentile_context { + struct SqlRTInfo* LocalsqlRT; + int LocalCounter; +} knl_u_percentile_context; + +#define STATEMENT_SQL_KIND 2 +typedef struct knl_u_statement_context { + int statement_level[STATEMENT_SQL_KIND]; /* diff levels for full or slow SQL */ + + /* basic information, should not be changed during one session */ + char* db_name; /* which database */ + char* user_name; /* client's user name */ + char* client_addr; /* client's IP address */ + int client_port; /* client's port */ + uint64 session_id; /* session's identifier */ + + + void *curStatementMetrics; /* current Statement handler to record metrics */ + int allocatedCxtCnt; /* how many of handers allocated */ + List toFreeStatementList; /* handers to be freed. */ + List suspendStatementList; /* handers to be flushed into system table */ + syscalllock list_protect; /* concurrency control for above two lists */ + MemoryContext stmt_stat_cxt; /* statement stat context */ +} knl_u_statement_context; + +struct Qid_key { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ +}; + +struct SlowQueryInfo { + uint64 unique_sql_id; + uint64 debug_query_sql_id; + int64* localTimeInfoArray; + struct PgStat_TableCounts* current_table_counter; + uint64 n_returned_rows; +}; + + +typedef struct knl_u_slow_query_context { + SlowQueryInfo slow_query; +} knl_u_slow_query_context; + +typedef struct knl_u_user_login_context { + /* + * when user is login, will update the variable in PerformAuthentication, + * and update the user's login counter. + * + * when proc exit, we register the callback function, in the callback + * function, will update the logout counter, and reset CurrentInstrLoginUserOid. + */ + Oid CurrentInstrLoginUserOid; +} knl_u_user_login_context; + +#define MAXINVALMSGS 32 +typedef struct knl_u_inval_context { + int32 deepthInAcceptInvalidationMessage; + + struct TransInvalidationInfo* transInvalInfo; + + union SharedInvalidationMessage* SharedInvalidMessagesArray; + + int numSharedInvalidMessagesArray; + + int maxSharedInvalidMessagesArray; + + struct SYSCACHECALLBACK* syscache_callback_list; + + int syscache_callback_count; + + struct RELCACHECALLBACK* relcache_callback_list; + + int relcache_callback_count; + + struct PARTCACHECALLBACK* partcache_callback_list; + + int partcache_callback_count; + + uint64 SharedInvalidMessageCounter; + + volatile sig_atomic_t catchupInterruptPending; + + union SharedInvalidationMessage* messages; + + volatile int nextmsg; + + volatile int nummsgs; +} knl_u_inval_context; + +typedef struct knl_u_cache_context { + /* num of cached re's(regular expression) */ + int num_res; + + /* cached re's (regular expression) */ + struct cached_re_str* re_array; + + /* + * We frequently need to test whether a given role is a member of some other + * role. In most of these tests the "given role" is the same, namely the + * active current user. So we can optimize it by keeping a cached list of + * all the roles the "given role" is a member of, directly or indirectly. + * The cache is flushed whenever we detect a change in pg_auth_members. + * + * There are actually two caches, one computed under "has_privs" rules + * (do not recurse where rolinherit isn't true) and one computed under + * "is_member" rules (recurse regardless of rolinherit). + * + * Possibly this mechanism should be generalized to allow caching membership + * info for multiple roles? + * + * The has_privs cache is: + * cached_privs_role is the role OID the cache is for. + * cached_privs_roles is an OID list of roles that cached_privs_role + * has the privileges of (always including itself). + * The cache is valid if cached_privs_role is not InvalidOid. + * + * The is_member cache is similarly: + * cached_member_role is the role OID the cache is for. + * cached_membership_roles is an OID list of roles that cached_member_role + * is a member of (always including itself). + * The cache is valid if cached_member_role is not InvalidOid. + */ + Oid cached_privs_role; + + List* cached_privs_roles; + + Oid cached_member_role; + + List* cached_membership_roles; + + struct _SPI_plan* plan_getrulebyoid; + + struct _SPI_plan* plan_getviewrule; + + /* Hash table for informations about each attribute's options */ + struct HTAB* att_opt_cache_hash; + + /* Cache management header --- pointer is NULL until created */ + struct CatCacheHeader* cache_header; + + /* Hash table for information about each tablespace */ + struct HTAB* TableSpaceCacheHash; + + struct HTAB* PartitionIdCache; + + struct HTAB* BucketIdCache; + + struct HTAB* dn_hash_table; + + bool part_cache_need_eoxact_work; + + bool bucket_cache_need_eoxact_work; + +} knl_u_cache_context; + + +typedef struct knl_u_syscache_context { + MemoryContext SysCacheMemCxt; + + struct CatCache** SysCache; + + bool CacheInitialized; + + Oid* SysCacheRelationOid; + +} knl_u_syscache_context; + +namespace dfs { +class DFSConnector; +} +typedef struct knl_u_catalog_context { + bool nulls[4]; + struct PartitionIdentifier* route; + + /* + * If "Create function ... LANGUAGE SQL" include agg function, agg->aggtype + * is the final aggtype. While for "Select agg()", agg->aggtype should be agg->aggtrantype. + * Here we use Parse_sql_language to distinguish these two cases. + */ + bool Parse_sql_language; + struct PendingRelDelete* pendingDeletes; /* head of linked list */ + /* Handle deleting BCM files. + * + * For column relation, one bcm file for each column file. + * For row relation, only one bcm file for the whole relation. + * We have to handle BCM files of some column file during rollback. + * Take an example, ADD COLUMN or SET TABLESPACE, may be canceled by user in some cases. + * Shared buffer must be invalided before BCM files are deleted. + * See also CStoreCopyColumnDataEnd(), RelationDropStorage(), ect. + */ + struct RelFileNodeBackend* ColMainFileNodes; + int ColMainFileNodesMaxNum; + int ColMainFileNodesCurNum; + List* pendingDfsDeletes; + dfs::DFSConnector* delete_conn; + struct StringInfoData* vf_store_root; + Oid currentlyReindexedHeap; + Oid currentlyReindexedIndex; + List* pendingReindexedIndexes; + /* These variables define the actually active state: */ + List* activeSearchPath; + /* default place to create stuff; if InvalidOid, no default */ + Oid activeCreationNamespace; + /* if TRUE, activeCreationNamespace is wrong, it should be temp namespace */ + bool activeTempCreationPending; + /* These variables are the values last derived from namespace_search_path: */ + List* baseSearchPath; + Oid baseCreationNamespace; + bool baseTempCreationPending; + Oid namespaceUser; + /* The above four values are valid only if baseSearchPathValid */ + bool baseSearchPathValid; + List* overrideStack; + bool overrideStackValid; + Oid myTempNamespaceOld; + /* + * myTempNamespace is InvalidOid until and unless a TEMP namespace is set up + * in a particular backend session (this happens when a CREATE TEMP TABLE + * command is first executed). Thereafter it's the OID of the temp namespace. + * + * myTempToastNamespace is the OID of the namespace for my temp tables' toast + * tables. It is set when myTempNamespace is, and is InvalidOid before that. + * + * myTempNamespaceSubID shows whether we've created the TEMP namespace in the + * current subtransaction. The flag propagates up the subtransaction tree, + * so the main transaction will correctly recognize the flag if all + * intermediate subtransactions commit. When it is InvalidSubTransactionId, + * we either haven't made the TEMP namespace yet, or have successfully + * committed its creation, depending on whether myTempNamespace is valid. + */ + Oid myTempNamespace; + Oid myTempToastNamespace; + bool deleteTempOnQuiting; + SubTransactionId myTempNamespaceSubID; + /* stuff for online expansion redis-cancel */ + bool redistribution_cancelable; +} knl_u_catalog_context; + +typedef struct knl_u_pgxc_context { + /* Current size of dn_handles and co_handles */ + int NumDataNodes; + int NumCoords; + int NumStandbyDataNodes; + + /* Number of connections held */ + int datanode_count; + int coord_count; + + /* dn oid matrics for multiple standby deployment */ + Oid** dn_matrics; + int dn_num; + int standby_num; + + /* + * Datanode handles saved in session memory context + * when PostgresMain is launched. + * Those handles are used inside a transaction by Coordinator to Datanodes. + */ + struct pgxc_node_handle* dn_handles; + /* + * Coordinator handles saved in session memory context + * when PostgresMain is launched. + * Those handles are used inside a transaction by Coordinator to Coordinators + */ + struct pgxc_node_handle* co_handles; + + struct RemoteXactState* remoteXactState; + + int PGXCNodeId; + /* + * When a particular node starts up, store the node identifier in this variable + * so that we dont have to calculate it OR do a search in cache any where else + * This will have minimal impact on performance + */ + uint32 PGXCNodeIdentifier; + + /* + * List of PGXCNodeHandle to track readers and writers involved in the + * current transaction + */ + List* XactWriteNodes; + List* XactReadNodes; + char* preparedNodes; + + /* Pool */ + char sock_path[MAXPGPATH]; + int last_reported_send_errno; + bool PoolerResendParams; + struct PGXCNodeConnectionInfo* PoolerConnectionInfo; + struct PoolAgent* poolHandle; + + List* connection_cache; + List* connection_cache_handle; + + bool is_gc_fdw; + bool is_gc_fdw_analyze; + int gc_fdw_current_idx; + int gc_fdw_max_idx; + int gc_fdw_run_version; + struct SnapshotData* gc_fdw_snapshot; +} knl_u_pgxc_context; + +typedef struct knl_u_fmgr_context { + struct df_files_init* file_list_init; + + struct df_files_init* file_init_tail; + +} knl_u_fmgr_context; + +typedef struct knl_u_erand_context { + unsigned short rand48_seed[3]; +} knl_u_erand_context; + +typedef struct knl_u_regex_context { + int pg_regex_strategy; /* enum PG_Locale_Strategy */ + Oid pg_regex_collation; + struct pg_ctype_cache* pg_ctype_cache_list; +} knl_u_regex_context; + +#ifdef ENABLE_MOT +namespace MOT { + class SessionContext; + class TxnManager; +} + +namespace JitExec { + struct JitContext; + struct JitContextPool; +} + +namespace tvm { + class JitIf; + class JitWhile; + class JitDoWhile; +} + +namespace llvm { + class JitIf; + class JitWhile; + class JitDoWhile; +} + +typedef struct knl_u_mot_context { + bool callbacks_set; + + // session attributes + uint32_t session_id; + uint32_t connection_id; + MOT::SessionContext* session_context; + MOT::TxnManager* txn_manager; + + // JIT + JitExec::JitContextPool* jit_session_context_pool; + uint32_t jit_context_count; + llvm::JitIf* jit_llvm_if_stack; + llvm::JitWhile* jit_llvm_while_stack; + llvm::JitDoWhile* jit_llvm_do_while_stack; + tvm::JitIf* jit_tvm_if_stack; + tvm::JitWhile* jit_tvm_while_stack; + tvm::JitDoWhile* jit_tvm_do_while_stack; + JitExec::JitContext* jit_context; + MOT::TxnManager* jit_txn; +} knl_u_mot_context; +#endif + +typedef struct knl_u_gtt_context { + bool gtt_cleaner_exit_registered; + HTAB* gtt_storage_local_hash; + MemoryContext gtt_relstats_context; + + /* relfrozenxid of all gtts in the current session */ + List* gtt_session_relfrozenxid_list; + TransactionId gtt_session_frozenxid; + pg_on_exit_callback gtt_sess_exit; +} knl_u_gtt_context; + +enum knl_ext_fdw_type { + MYSQL_TYPE_FDW, + ORACLE_TYPE_FDW, + POSTGRES_TYPE_FDW, + /* Add new external FDW type before MAX_TYPE_FDW */ + PLDEBUG_TYPE, + MAX_TYPE_FDW +}; + +typedef struct knl_u_ext_fdw_context { + union { + void* connList; /* Connection info to other DB */ + void* pldbg_ctx; /* Pldebugger info */ + }; + pg_on_exit_callback fdwExitFunc; /* Exit callback, will be called when session exit */ +} knl_u_ext_fdw_context; + +enum knl_session_status { + KNL_SESS_FAKE, + KNL_SESS_UNINIT, + KNL_SESS_ATTACH, + KNL_SESS_DETACH, + KNL_SESS_CLOSE, + KNL_SESS_END_PHASE1, + KNL_SESS_CLOSERAW, // not initialize and +}; + +typedef struct sess_orient{ + uint64 cn_sessid; + uint32 cn_timeline; + uint32 cn_nodeid; +}sess_orient; + +typedef struct knl_session_context { + volatile knl_session_status status; + Dlelem elem; + + ThreadId attachPid; + + MemoryContext top_mem_cxt; + MemoryContext cache_mem_cxt; + MemoryContext top_transaction_mem_cxt; + MemoryContext self_mem_cxt; + MemoryContext top_portal_cxt; + MemoryContextGroup* mcxt_group; + /* temp_mem_cxt is a context which will be reset when the session attach to a thread */ + MemoryContext temp_mem_cxt; + int session_ctr_index; + uint64 session_id; + uint64 debug_query_id; + List* ts_cached_queryid; + + //use this to identify which cn connection to. + sess_orient sess_ident; + uint32 cn_session_abort_count; + long cancel_key; + char* prog_name; + + bool ClientAuthInProgress; + + bool need_report_top_xid; + + struct config_generic** guc_variables; + + int num_guc_variables; + + int on_sess_exit_index; + + knl_session_attr attr; + struct knl_u_wlm_context* wlm_cxt; + knl_u_analyze_context analyze_cxt; + knl_u_cache_context cache_cxt; + knl_u_catalog_context catalog_cxt; + knl_u_commands_context cmd_cxt; + knl_u_contrib_context contrib_cxt; + knl_u_erand_context rand_cxt; + knl_u_executor_context exec_cxt; + knl_u_fmgr_context fmgr_cxt; + knl_u_index_context index_cxt; + knl_u_instrument_context instr_cxt; + knl_u_inval_context inval_cxt; + knl_u_locale_context lc_cxt; + knl_u_log_context log_cxt; + knl_u_libpq_context libpq_cxt; + knl_u_mb_context mb_cxt; + knl_u_misc_context misc_cxt; + knl_u_optimizer_context opt_cxt; + knl_u_parser_context parser_cxt; + knl_u_pgxc_context pgxc_cxt; + knl_u_plancache_context pcache_cxt; + knl_u_plpgsql_context plsql_cxt; + knl_u_postgres_context postgres_cxt; + knl_u_proc_context proc_cxt; + knl_u_ps_context ps_cxt; + knl_u_regex_context regex_cxt; + knl_u_xact_context xact_cxt; + knl_u_sig_context sig_cxt; + knl_u_SPI_context SPI_cxt; + knl_u_relcache_context relcache_cxt; + knl_u_relmap_context relmap_cxt; + knl_u_stat_context stat_cxt; + knl_u_storage_context storage_cxt; + knl_u_stream_context stream_cxt; + knl_u_syscache_context syscache_cxt; + knl_u_time_context time_cxt; + knl_u_trigger_context tri_cxt; + knl_u_tscache_context tscache_cxt; + knl_u_typecache_context tycache_cxt; + knl_u_upgrade_context upg_cxt; + knl_u_utils_context utils_cxt; + knl_u_security_context sec_cxt; + +#ifdef ENABLE_MOT + knl_u_mot_context mot_cxt; +#endif + + /* instrumentation */ + knl_u_unique_sql_context unique_sql_cxt; + knl_u_user_login_context user_login_cxt; + knl_u_percentile_context percentile_cxt; + knl_u_statement_context statement_cxt; + + knl_u_slow_query_context slow_query_cxt; + /* external FDW */ + knl_u_ext_fdw_context ext_fdw_ctx[MAX_TYPE_FDW]; + /* GTT */ + knl_u_gtt_context gtt_ctx; +} knl_session_context; + +enum stp_xact_err_type { + STP_XACT_OPEN_FOR, + STP_XACT_USED_AS_EXPR, + STP_XACT_GUC_IN_OPT_CLAUSE, + STP_XACT_OF_SECURE_DEFINER, + STP_XACT_AFTER_TRIGGER_BEGIN, +}; + + +extern void knl_session_init(knl_session_context* sess_cxt); +extern void knl_u_executor_init(knl_u_executor_context* exec_cxt); +extern knl_session_context* create_session_context(MemoryContext parent, uint64 id); +extern void free_session_context(knl_session_context* session); +extern void use_fake_session(); +extern bool stp_set_commit_rollback_err_msg(stp_xact_err_type type); + +extern THR_LOCAL knl_session_context* u_sess; + +inline bool stp_disable_xact_and_set_err_msg(bool *save_commit_rollback_state, stp_xact_err_type type) +{ + *save_commit_rollback_state = u_sess->SPI_cxt.is_allow_commit_rollback; + u_sess->SPI_cxt.is_allow_commit_rollback = false; + return stp_set_commit_rollback_err_msg(type); +} + +inline bool stp_enable_and_get_old_xact_stmt_state() +{ + bool save_commit_rollback_state = u_sess->SPI_cxt.is_allow_commit_rollback; + u_sess->SPI_cxt.is_allow_commit_rollback = true; + return save_commit_rollback_state; +} + +inline void stp_retore_old_xact_stmt_state(bool OldState) +{ + u_sess->SPI_cxt.is_allow_commit_rollback = OldState; +} + +inline void stp_reset_commit_rolback_err_msg() +{ + memset_s(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg, + sizeof(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg), + 0, sizeof(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg)); +} + +inline void stp_reset_opt_values() +{ + u_sess->SPI_cxt.is_allow_commit_rollback = false; + stp_reset_commit_rolback_err_msg(); + u_sess->SPI_cxt.is_stp = true; + u_sess->SPI_cxt.is_proconfig_set = false; + u_sess->SPI_cxt.portal_stp_exception_counter = 0; +} + +inline void stp_reset_xact_state_and_err_msg(bool savedisAllowCommitRollback, bool needResetErrMsg) +{ + stp_retore_old_xact_stmt_state(savedisAllowCommitRollback); + if (needResetErrMsg) { + stp_reset_commit_rolback_err_msg(); + } +} + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_thread.h postgresql-hll-2.14/include/include/knl/knl_thread.h --- postgresql-hll-2.14_old/include/include/knl/knl_thread.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_thread.h 2020-12-12 17:06:43.216347638 +0800 @@ -0,0 +1,2927 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_thread.h + * Data stucture for thread level global variables. + * + * When anyone try to added variable in this file, which means add a thread level + * variable, there are several rules needed to obey: + * + * 1. Only used in one thread. + * If we try to share the variable with all threads, then this variable should be + * added to instance level context rather than thread level context. + * + * 2. Session independent. + * When we use thread pool to server for all sessions, then the thread in + * thread pool should be stateless. So, session related info can not be stored + * in thread level context, for instance, client user, password, cached plans, + * compiled plpgsql, etc. + * + * 3. Transaction level lifecycle. + * The thread will only change to another session when one transaction has + * already finished in current session. So, we can put the variable in thread + * level context if it will be reset at thread transaction finish or start + * time. + * + * 4. Name pattern + * All context define below should follow naming rules: + * knl_t_xxxx + * + * + * IDENTIFICATION + * src/include/knl/knl_thread.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_THRD_H_ +#define SRC_INCLUDE_KNL_KNL_THRD_H_ + +#include + +#include "c.h" +#include "access/sdir.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "gssignal/gs_signal.h" +#include "knl/knl_guc.h" +#include "knl/knl_session.h" +#include "nodes/pg_list.h" +#include "storage/s_lock.h" +#include "utils/palloc.h" +#include "storage/latch.h" +#include "portability/instr_time.h" +#include "cipher.h" +#include "openssl/ossl_typ.h" +#include "workload/qnode.h" +#include "streaming/init.h" +#include "tcop/dest.h" +#include "streaming/init.h" +#include "utils/memgroup.h" +#include "lib/circularqueue.h" + +#define MAX_PATH_LEN 1024 + +#define RESERVE_SIZE 33 + +typedef struct ResourceOwnerData* ResourceOwner; + +typedef struct knl_t_codegen_context { + void* thr_codegen_obj; + + bool g_runningInFmgr; + + long codegen_IRload_thr_count; + +} knl_t_codegen_context; + +typedef struct knl_t_relopt_context { + struct relopt_gen** relOpts; + + bits32 last_assigned_kind; + + int num_custom_options; + + struct relopt_gen** custom_options; + + bool need_initialization; + + int max_custom_options; + +} knl_t_relopt_context; + +typedef struct knl_t_mem_context { + MemoryContext postmaster_mem_cxt; + + MemoryContext msg_mem_cxt; + + MemoryContext cur_transaction_mem_cxt; + + MemoryContext gs_signal_mem_cxt; + + MemoryContext mask_password_mem_cxt; + + MemoryContext row_desc_mem_cxt; + + MemoryContext stream_runtime_mem_cxt; + + /* Shared memory context for in-memory data exchange. */ + MemoryContext data_exchange_mem_cxt; + + /* This is a transient link to the active portal's memory context: */ + MemoryContext portal_mem_cxt; + + /* used to track the memory usage */ + MemoryContext mem_track_mem_cxt; + + /* private memory context for profile logging, it's under t_thrd.top_mem_cxt */ + MemoryContext profile_log_mem_cxt; + + /* gBatchEncodeNumericMemCnxt -- special memory context for encoding batch numeric. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during encoding of each batch of numeric values, and reset after done. + + * Bacause varlena with 1B maybe exist, we have to free them at the + * end. the number of LOOP is always 60000 and releasing space is so + * ineffective. So that use gBatchEncodeNumericMemCnxt. + * Alloc some times, and reset one time. + */ + MemoryContext batch_encode_numeric_mem_cxt; + + /* system auditor memory context. */ + MemoryContext pgAuditLocalContext; +} knl_t_mem_context; + +#ifdef HAVE_INT64_TIMESTAMP +typedef int64 TimestampTz; +#else + +typedef double TimestampTz; +#endif +/* + * During prepare, the state file is assembled in memory before writing it + * to WAL and the actual state file. We use a chain of StateFileChunk blocks + * for that. + */ +typedef struct StateFileChunk { + char* data; + uint32 len; + struct StateFileChunk* next; +} StateFileChunk; + +typedef struct xllist { + StateFileChunk* head; /* first data block in the chain */ + StateFileChunk* tail; /* last block in chain */ + uint32 num_chunks; + uint32 bytes_free; /* free bytes left in tail block */ + uint32 total_len; /* total data bytes in chain */ +} xllist; + +typedef struct knl_t_xact_context { + /* var in transam.cpp */ + typedef uint64 CommitSeqNo; + typedef int CLogXidStatus; + typedef uint64 XLogRecPtr; + /* + * Single-item cache for results of TransactionIdGetCommitSeqNo. It's worth + * having + * such a cache because we frequently find ourselves repeatedly checking the + * same XID, for example when scanning a table just after a bulk insert, + * update, or delete. + */ + TransactionId cachedFetchCSNXid; + CommitSeqNo cachedFetchCSN; + TransactionId latestFetchCSNXid; + CommitSeqNo latestFetchCSN; + + /* Just use for check set hitbit right */ + /* Just use for check set hitbit right */ + TransactionId latestFetchXid; + CLogXidStatus latestFetchXidStatus; + + /* + * Single-item cache for results of TransactionLogFetch. It's worth having + * such a cache because we frequently find ourselves repeatedly checking the + * same XID, for example when scanning a table just after a bulk insert, + * update, or delete. + */ + TransactionId cachedFetchXid; + CLogXidStatus cachedFetchXidStatus; + XLogRecPtr cachedCommitLSN; + + /* var in multixact.cpp*/ + struct mXactCacheEnt* MXactCache; + MemoryContext MXactContext; + + /* var in twophase.cpp*/ + /* + * Global transaction entry currently locked by us, if any. Note that any + * access to the entry pointed to by this variable must be protected by + * TwoPhaseStateLock, though obviously the pointer itself doesn't need to be + * (since it's just local memory). + */ + struct GlobalTransactionData* MyLockedGxact; + bool twophaseExitRegistered; + TransactionId cached_xid; + struct GlobalTransactionData* cached_gxact; + struct TwoPhaseStateData* TwoPhaseState; + xllist records; + + /* var in varsup.cpp*/ + TransactionId cn_xid; + TransactionId next_xid; + bool force_get_xid_from_gtm; + Oid InplaceUpgradeNextOid; + /* pointer to "variable cache" in shared memory (set up by shmem.c) */ + struct VariableCacheData* ShmemVariableCache; + + /* var in xact.cpp */ + bool CancelStmtForReadOnly; + /* + * MyXactAccessedTempRel is set when a temporary relation is accessed. + * We don't allow PREPARE TRANSACTION in that case. (This is global + * so that it can be set from heapam.c.) + */ + /* Kluge for 2PC support */ + bool MyXactAccessedTempRel; + bool MyXactAccessedRepRel; + bool needRemoveTwophaseState; + /* Whether in abort transaction procedure */ + bool bInAbortTransaction; + bool handlesDestroyedInCancelQuery; + /* if true, we do not unlink dropped col files at xact commit or abort */ + bool xactDelayDDL; + /* + * unreportedXids holds XIDs of all subtransactions that have not yet been + * reported in a XLOG_XACT_ASSIGNMENT record. + */ +#define PGPROC_MAX_CACHED_SUBXIDS 64 + int nUnreportedXids; + TransactionId unreportedXids[PGPROC_MAX_CACHED_SUBXIDS]; + /* + * The subtransaction ID and command ID assignment counters are global + * to a whole transaction, so we do not keep them in the state stack. + */ + TransactionId currentSubTransactionId; + CommandId currentCommandId; + bool currentCommandIdUsed; + /* + * Parameters for communication control of Command ID between Postgres-XC nodes. + * isCommandIdReceived is used to determine of a command ID has been received by a remote + * node from a Coordinator. + * sendCommandId is used to determine if a Postgres-XC node needs to communicate its command ID. + * This is possible for both remote nodes and Coordinators connected to applications. + * receivedCommandId is the command ID received on Coordinator from remote node or on remote node + * from Coordinator. + */ + bool isCommandIdReceived; + bool sendCommandId; + CommandId receivedCommandId; + + /* + * xactStartTimestamp is the value of transaction_timestamp(). + * stmtStartTimestamp is the value of statement_timestamp(). + * xactStopTimestamp is the time at which we log a commit or abort WAL record. + * These do not change as we enter and exit subtransactions, so we don't + * keep them inside the TransactionState stack. + */ + TimestampTz xactStartTimestamp; + TimestampTz stmtStartTimestamp; + TimestampTz xactStopTimestamp; + + /* + * PGXC receives from GTM a timestamp value at the same time as a GXID + * This one is set as GTMxactStartTimestamp and is a return value of now(), current_transaction(). + * GTMxactStartTimestamp is also sent to each node with gxid and snapshot and delta is calculated locally. + * GTMdeltaTimestamp is used to calculate current_statement as its value can change + * during a transaction. Delta can have a different value through the nodes of the cluster + * but its uniqueness in the cluster is maintained thanks to the global value GTMxactStartTimestamp. + */ + TimestampTz GTMxactStartTimestamp; + TimestampTz GTMdeltaTimestamp; + bool timestamp_from_cn; + + bool XactLocalNodePrepared; + bool XactReadLocalNode; + bool XactWriteLocalNode; + bool XactLocalNodeCanAbort; + bool XactPrepareSent; + bool AlterCoordinatorStmt; + + /* white-box check TransactionID, when there is no 2pc + * the thread local variable save the executor cn commit(abort) xid + * compare with the remote-commit xid in other CNs and DNs + */ + TransactionId XactXidStoreForCheck; + TransactionId reserved_nextxid_check; + /* + * Some commands want to force synchronous commit. + */ + bool forceSyncCommit; + /* + * Private context for transaction-abort work --- we reserve space for this + * at startup to ensure that AbortTransaction and AbortSubTransaction can work + * when we've run out of memory. + */ + MemoryContext TransactionAbortContext; + struct GTMCallbackItem* GTM_callbacks; + struct GTMCallbackItem* Seq_callbacks; + + LocalTransactionId lxid; + TransactionId stablexid; + + /* var in gtm.cpp */ + TransactionId currentGxid; + struct gtm_conn* conn; + + /* var in slru.cpp */ + typedef int SlruErrorCause; + SlruErrorCause slru_errcause; + int slru_errno; + + /* var in predicate.cpp */ + uint32 ScratchTargetTagHash; + struct LWLock *ScratchPartitionLock; + /* + * The local hash table used to determine when to combine multiple fine- + * grained locks into a single courser-grained lock. + */ + struct HTAB* LocalPredicateLockHash; + /* + * Keep a pointer to the currently-running serializable transaction (if any) + * for quick reference. Also, remember if we have written anything that could + * cause a rw-conflict. + */ + struct SERIALIZABLEXACT* MySerializableXact; + bool MyXactDidWrite; + +#ifdef PGXC + bool useLocalSnapshot; + /* + * Hash bucket map of the group. + * Used only in the DN for DDL operations. + * Allocated from t_thrd.mem_cxt.top_transaction_mem_cxt. + */ + uint2 *PGXCBucketMap; + int PGXCNodeId; + bool inheritFileNode; +#endif +} knl_t_xact_context; + +typedef void (*RedoInterruptCallBackFunc)(void); + +typedef struct knl_t_xlog_context { +#define MAXFNAMELEN 64 + typedef uint32 TimeLineID; + typedef int HotStandbyState; + typedef uint32 pg_crc32; + typedef int RecoveryTargetType; + typedef int ServerMode; + typedef uint64 XLogRecPtr; + typedef uint64 XLogSegNo; + /* + * ThisTimeLineID will be same in all backends --- it identifies current + * WAL timeline for the database system. + */ + TimeLineID ThisTimeLineID; + + /* + * Are we doing recovery from XLOG? + * + * This is only ever true in the startup process; it should be read as meaning + * "this process is replaying WAL records", rather than "the system is in + * recovery mode". It should be examined primarily by functions that need + * to act differently when called from a WAL redo function (e.g., to skip WAL + * logging). To check whether the system is in recovery regardless of which + * process you're running in, use RecoveryInProgress() but only after shared + * memory startup and lock initialization. + */ + bool InRecovery; + /* Are we in Hot Standby mode? Only valid in startup process, see xlog.h */ + + HotStandbyState standbyState; + XLogRecPtr LastRec; + pg_crc32 latestRecordCrc; + /* + * During recovery, lastFullPageWrites keeps track of full_page_writes that + * the replayed WAL records indicate. It's initialized with full_page_writes + * that the recovery starting checkpoint record indicates, and then updated + * each time XLOG_FPW_CHANGE record is replayed. + */ + bool lastFullPageWrites; + /* + * Local copy of SharedRecoveryInProgress variable. True actually means "not + * known, need to check the shared state". + */ + bool LocalRecoveryInProgress; + /* + * Local copy of SharedHotStandbyActive variable. False actually means "not + * known, need to check the shared state". + */ + bool LocalHotStandbyActive; + + /* + * Local state for XLogInsertAllowed(): + * 1: unconditionally allowed to insert XLOG + * 0: unconditionally not allowed to insert XLOG + * -1: must check RecoveryInProgress(); disallow until it is false + * Most processes start with -1 and transition to 1 after seeing that recovery + * is not in progress. But we can also force the value for special cases. + * The coding in XLogInsertAllowed() depends on the first two of these states + * being numerically the same as bool true and false. + */ + int LocalXLogInsertAllowed; + + /* + * When ArchiveRecoveryRequested is set, archive recovery was requested, + * ie. recovery.conf file was present. When InArchiveRecovery is set, we are + * currently recovering using offline XLOG archives. These variables are only + * valid in the startup process. + * + * When ArchiveRecoveryRequested is true, but InArchiveRecovery is false, we're + * currently performing crash recovery using only XLOG files in pg_xlog, but + * will switch to using offline XLOG archives as soon as we reach the end of + * WAL in pg_xlog. + * + * When recovery.conf is configed, it means that we will recover from offline XLOG + * archives, set ArchiveRstoreRequested to true to distinguish archive recovery with + * other recovery scenarios. + */ + bool ArchiveRecoveryRequested; + bool InArchiveRecovery; + bool ArchiveRestoreRequested; + + /* Was the last xlog file restored from archive, or local? */ + bool restoredFromArchive; + + /* options taken from recovery.conf for archive recovery */ + char* recoveryRestoreCommand; + char* recoveryEndCommand; + char* archiveCleanupCommand; + RecoveryTargetType recoveryTarget; + bool recoveryTargetInclusive; + bool recoveryPauseAtTarget; + TransactionId recoveryTargetXid; + TimestampTz recoveryTargetTime; + char* recoveryTargetBarrierId; + char* recoveryTargetName; + XLogRecPtr recoveryTargetLSN; + + /* options taken from recovery.conf for XLOG streaming */ + bool StandbyModeRequested; + char* PrimaryConnInfo; + char* TriggerFile; + + /* are we currently in standby mode? */ + bool StandbyMode; + + /* if trigger has been set in reader for any reason, check it in read record */ + bool recoveryTriggered; + + /* if recoveryStopsHere returns true, it saves actual stop xid/time/name here */ + TransactionId recoveryStopXid; + TimestampTz recoveryStopTime; + XLogRecPtr recoveryStopLSN; + char recoveryStopName[MAXFNAMELEN]; + bool recoveryStopAfter; + + /* + * During normal operation, the only timeline we care about is ThisTimeLineID. + * During recovery, however, things are more complicated. To simplify life + * for rmgr code, we keep ThisTimeLineID set to the "current" timeline as we + * scan through the WAL history (that is, it is the line that was active when + * the currently-scanned WAL record was generated). We also need these + * timeline values: + * + * recoveryTargetTLI: the desired timeline that we want to end in. + * + * recoveryTargetIsLatest: was the requested target timeline 'latest'? + * + * expectedTLIs: an integer list of recoveryTargetTLI and the TLIs of + * its known parents, newest first (so recoveryTargetTLI is always the + * first list member). Only these TLIs are expected to be seen in the WAL + * segments we read, and indeed only these TLIs will be considered as + * candidate WAL files to open at all. + * + * curFileTLI: the TLI appearing in the name of the current input WAL file. + * (This is not necessarily the same as ThisTimeLineID, because we could + * be scanning data that was copied from an ancestor timeline when the current + * file was created.) During a sequential scan we do not allow this value + * to decrease. + */ + TimeLineID recoveryTargetTLI; + bool recoveryTargetIsLatest; + List* expectedTLIs; + TimeLineID curFileTLI; + + /* + * ProcLastRecPtr points to the start of the last XLOG record inserted by the + * current backend. It is updated for all inserts. XactLastRecEnd points to + * end+1 of the last record, and is reset when we end a top-level transaction, + * or start a new one; so it can be used to tell if the current transaction has + * created any XLOG records. + */ + XLogRecPtr ProcLastRecPtr; + + XLogRecPtr XactLastRecEnd; + + /* + * RedoRecPtr is this backend's local copy of the REDO record pointer + * (which is almost but not quite the same as a pointer to the most recent + * CHECKPOINT record). We update this from the shared-memory copy, + * XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we + * hold the Insert lock). See XLogInsertRecord for details. We are also + * allowed to update from XLogCtl->Insert.RedoRecPtr if we hold the info_lck; + * see GetRedoRecPtr. A freshly spawned backend obtains the value during + * InitXLOGAccess. + */ + XLogRecPtr RedoRecPtr; + + /* + * doPageWrites is this backend's local copy of (forcePageWrites || + * fullPageWrites). It is used together with RedoRecPtr to decide whether + * a full-page image of a page need to be taken. + */ + bool doPageWrites; + + /* + * RedoStartLSN points to the checkpoint's REDO location which is specified + * in a backup label file, backup history file or control file. In standby + * mode, XLOG streaming usually starts from the position where an invalid + * record was found. But if we fail to read even the initial checkpoint + * record, we use the REDO location instead of the checkpoint location as + * the start position of XLOG streaming. Otherwise we would have to jump + * backwards to the REDO location after reading the checkpoint record, + * because the REDO record can precede the checkpoint record. + */ + XLogRecPtr RedoStartLSN; + ServerMode server_mode; + bool is_cascade_standby; + + /* Flags to tell if we are in an startup process */ + bool startup_processing; + + /* + * openLogFile is -1 or a kernel FD for an open log file segment. + * When it's open, openLogOff is the current seek offset in the file. + * openLogSegNo identifies the segment. These variables are only + * used to write the XLOG, and so will normally refer to the active segment. + */ + int openLogFile; + XLogSegNo openLogSegNo; + uint32 openLogOff; + + /* + * These variables are used similarly to the ones above, but for reading + * the XLOG. Note, however, that readOff generally represents the offset + * of the page just read, not the seek position of the FD itself, which + * will be just past that page. readLen indicates how much of the current + * page has been read into readBuf, and readSource indicates where we got + * the currently open file from. + */ + int readFile; + XLogSegNo readSegNo; + uint32 readOff; + uint32 readLen; + unsigned int readSource; /* XLOG_FROM_* code */ + + /* + * Keeps track of which sources we've tried to read the current WAL + * record from and failed. + */ + unsigned int failedSources; /* OR of XLOG_FROM_* codes */ + + bool readfrombuffer; + + /* + * These variables track when we last obtained some WAL data to process, + * and where we got it from. (XLogReceiptSource is initially the same as + * readSource, but readSource gets reset to zero when we don't have data + * to process right now.) + */ + TimestampTz XLogReceiptTime; + int XLogReceiptSource; /* XLOG_FROM_* code */ + + /* State information for XLOG reading */ + XLogRecPtr ReadRecPtr; /* start of last record read */ + XLogRecPtr EndRecPtr; /* end+1 of last record read */ + + XLogRecPtr minRecoveryPoint; /* local copy of + * ControlFile->minRecoveryPoint */ + bool updateMinRecoveryPoint; + + /* + * Have we reached a consistent database state? In crash recovery, we have + * to replay all the WAL, so reachedConsistency is never set. During archive + * recovery, the database is consistent once minRecoveryPoint is reached. + */ + bool reachedConsistency; + + bool InRedo; + bool RedoDone; + + /* Have we launched bgwriter during recovery? */ + bool bgwriterLaunched; + bool pagewriter_launched; + + /* Added for XLOG scaling*/ + /* For WALInsertLockAcquire/Release functions */ + int MyLockNo; + bool holdingAllLocks; + + int lockToTry; + uint64 cachedPage; + char* cachedPos; +#ifdef WIN32 + unsigned int deletedcounter; +#endif + +#define STR_TIME_BUF_LEN 128 + char buf[STR_TIME_BUF_LEN]; + XLogRecPtr receivedUpto; + XLogRecPtr lastComplaint; + bool failover_triggered; + bool switchover_triggered; + + struct registered_buffer* registered_buffers; + int max_registered_buffers; /* allocated size */ + int max_registered_block_id; /* highest block_id + 1 + * currently registered */ + + /* + * A chain of XLogRecDatas to hold the "main data" of a WAL record, registered + * with XLogRegisterData(...). + */ + struct XLogRecData* mainrdata_head; + struct XLogRecData* mainrdata_last; + uint32 mainrdata_len; /* total # of bytes in chain */ + + /* + * These are used to hold the record header while constructing a record. + * 'hdr_scratch' is not a plain variable, but is palloc'd at initialization, + * because we want it to be MAXALIGNed and padding bytes zeroed. + * + * For simplicity, it's allocated large enough to hold the headers for any + * WAL record. + */ + struct XLogRecData* ptr_hdr_rdt; + char* hdr_scratch; + + /* + * An array of XLogRecData structs, to hold registered data. + */ + struct XLogRecData* rdatas; + int num_rdatas; /* entries currently used */ + int max_rdatas; /* allocated size */ + + bool begininsert_called; + + /* Should te in-progress insertion log the origin */ + bool include_origin; + + /* Memory context to hold the registered buffer and data references. */ + MemoryContext xloginsert_cxt; + + struct HTAB* invalid_page_tab; + + /* state maintained across calls */ + uint32 sendId; + int sendFile; + XLogSegNo sendSegNo; + uint32 sendOff; + TimeLineID sendTLI; + + List* incomplete_actions; + + MemoryContext spg_opCtx; + MemoryContext gist_opCtx; + MemoryContext gin_opCtx; + + bool redo_oldversion_xlog; + /* + * Statistics for current checkpoint are collected in this global struct. + * Because only the checkpointer or a stand-alone backend can perform + * checkpoints, this will be unused in normal backends. + */ + struct CheckpointStatsData* CheckpointStats; + struct XLogwrtResult* LogwrtResult; + bool needImmediateCkp; + int redoItemIdx; + /* ignore cleanup when startup end. when isIgoreCleanup is true, a standby DN always keep isIgoreCleanup true */ + bool forceFinishHappened; + uint32 invaildPageCnt; + uint32 imcompleteActionCnt; + XLogRecPtr max_page_flush_lsn; + bool permit_finish_redo; + +#ifndef ENABLE_MULTIPLE_NODES + /* redo RM_STANDBY_ID record committing csn's transaction id */ + List* committing_csn_list; +#endif + RedoInterruptCallBackFunc redoInterruptCallBackFunc; +} knl_t_xlog_context; + +typedef struct knl_t_dfs_context { + /* + * Provide a pending-delete like mechanism to allow external routines to release the + * memory stuffs that were NOT allocated in mem-context e.g. those allocated in + * 3rd-party libraries, we have to do so as a none-dfs error-out may miss dropping + * this kind of resources which defintely causing memory leak. + */ + List* pending_free_reader_list; + + List* pending_free_writer_list; + +} knl_t_dfs_context; + +typedef struct knl_t_obs_context { + MemoryContext ObsMemoryContext; + + char* pCAInfo; + + int retrySleepInterval; + + int statusG; + +#define ERROR_DETAIL_LEN 4096 + char errorDetailsG[ERROR_DETAIL_LEN]; + + int uriStyleG; +} knl_t_obs_context; + +typedef struct knl_t_cbm_context { + /* The xlog parsing and bitmap output struct instance */ + struct XlogBitmapStruct* XlogCbmSys; + + /* cbmwriter.cpp */ + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + MemoryContext cbmwriter_context; + MemoryContext cbmwriter_page_context; +} knl_t_cbm_context; + +/* thread local pointer to the shared memory */ +typedef struct knl_t_shemem_ptr_context { + struct ss_scan_locations_t* scan_locations; + struct SlruCtlData* MultiXactOffsetCtl; + struct SlruCtlData* MultiXactMemberCtl; + struct MultiXactStateData* MultiXactState; + MultiXactId* OldestMemberMXactId; + MultiXactId* OldestVisibleMXactId; + + struct SlruCtlData* ClogCtl; + + struct SlruCtlData* CsnlogCtlPtr; + + struct XLogCtlData* XLogCtl; + + union WALInsertLockPadded **GlobalWALInsertLocks; + union WALInsertLockPadded *LocalGroupWALInsertLocks; + + /* + * We maintain an image of pg_control in shared memory. + */ + struct ControlFileData* ControlFile; + + struct LsnXlogFlushData* g_LsnXlogFlushChkFile; + + struct SlruCtlData* OldSerXidSlruCtl; + + struct OldSerXidControlData* oldSerXidControl; + + /* + * When the oldest committed transaction on the "finished" list is moved to + * SLRU, its predicate locks will be moved to this "dummy" transaction, + * collapsing duplicate targets. When a duplicate is found, the later + * commitSeqNo is used. + */ + struct SERIALIZABLEXACT* OldCommittedSxact; + + /* + * This provides a list of objects in order to track transactions + * participating in predicate locking. Entries in the list are fixed size, + * and reside in shared memory. The memory address of an entry must remain + * fixed during its lifetime. The list will be protected from concurrent + * update externally; no provision is made in this code to manage that. The + * number of entries in the list, and the size allowed for each entry is + * fixed upon creation. + */ + struct PredXactListData* PredXact; + + /* + * This provides a pool of RWConflict data elements to use in conflict lists + * between transactions. + */ + struct RWConflictPoolHeaderData* RWConflictPool; + /* + * The predicate locking hash tables are in shared memory. + * Each backend keeps pointers to them. + */ + struct HTAB* SerializableXidHash; + struct HTAB* PredicateLockTargetHash; + struct HTAB* PredicateLockHash; + struct SHM_QUEUE* FinishedSerializableTransactions; + + /* ------------------------------------------------------------ + * Functions for management of the shared-memory PgBackendStatus array + * ------------------------------------------------------------ + */ + PgBackendStatus* BackendStatusArray; + char* BackendClientHostnameBuffer; + char* BackendAppnameBuffer; + char* BackendConninfoBuffer; + char* BackendActivityBuffer; + struct PgStat_WaitCountStatus* WaitCountBuffer; + Size BackendActivityBufferSize; + + PgBackendStatus* MyBEEntry; + + volatile struct SessionLevelStatistic* mySessionStatEntry; + struct SessionLevelStatistic* sessionStatArray; + struct SessionLevelMemory* mySessionMemoryEntry; + struct SessionLevelMemory* sessionMemoryArray; + volatile struct SessionTimeEntry* mySessionTimeEntry; + struct SessionTimeEntry* sessionTimeArray; + + struct ProcSignalSlot* ProcSignalSlots; + + volatile struct ProcSignalSlot* MyProcSignalSlot; // volatile + + struct PGShmemHeader* ShmemSegHdr; /* shared mem segment header */ + + void* ShmemBase; /* start address of shared memory */ + + void* ShmemEnd; /* end+1 address of shared memory */ + + slock_t* ShmemLock; /* spinlock for shared memory and LWLock allocation */ + + struct HTAB* ShmemIndex; /* primary index hashtable for shmem */ + + struct SISeg* shmInvalBuffer; /* pointer to the shared inval buffer */ + + struct PMSignalData* PMSignalState; // volatile + + /* + * This points to the array of LWLocks in shared memory. Backends inherit + * the pointer by fork from the postmaster (except in the EXEC_BACKEND case, + * where we have special measures to pass it down). + */ + union LWLockPadded *mainLWLockArray; + + // for GTT table to track sessions and their usage of GTTs + struct gtt_ctl_data* gtt_shared_ctl; + struct HTAB* active_gtt_shared_hash; +} knl_t_shemem_ptr_context; + +typedef struct knl_t_cstore_context { + /* + * remember all the relation ALTER TABLE SET DATATYPE is applied to. + * note that this object is live in t_thrd.top_mem_cxt. + */ + class CStoreAlterRegister* gCStoreAlterReg; + + /* bulkload_memsize_used + * Remember how many memory has been allocated and used. + * It will be <= partition_max_cache_size. + */ + Size bulkload_memsize_used; + + int cstore_prefetch_count; + + /* local state for aio clean up resource */ + struct AioDispatchCUDesc** InProgressAioCUDispatch; + int InProgressAioCUDispatchCount; +} knl_t_cstore_context; + +typedef struct knl_t_index_context { + typedef uint64 XLogRecPtr; + struct ginxlogInsertDataInternal* ptr_data; + struct ginxlogInsertEntry* ptr_entry; + /* + * ginInsertCtx -- static thread local memory context for gininsert(). + * ginInsertCtx is to avoid create and destory context frequently. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during insert one tuple into gin index, and reset after done. + */ + MemoryContext ginInsertCtx; + struct BTVacInfo* btvacinfo; +} knl_t_index_context; + +typedef struct knl_t_wlmthrd_context { + /* thread level node group */ + struct WLMNodeGroupInfo* thread_node_group; + + /* dynamic workload client structure */ + struct ClientDynamicManager* thread_climgr; + + /* dynamic workload server structure */ + struct ServerDynamicManager* thread_srvmgr; + + /* collect info */ + struct WLMCollectInfo* collect_info; + + /* exception control manager */ + struct ExceptionManager* except_ctl; + + /* dn cpu info detail */ + struct WLMDNRealTimeInfoDetail* dn_cpu_detail; + + /* query node for workload manager */ + WLMQNodeInfo qnode; + + /* the states of query while doing parallel control */ + ParctlState parctl_state; + + /* indicate if it is alrm pending */ + bool wlmalarm_pending; + + /* indicate if alarm timeout is active */ + bool wlmalarm_timeout_active; + + /* indicate if alarm dump is active */ + bool wlmalarm_dump_active; + + /* indicate if transcation is started */ + bool wlm_xact_start; + + /* thread initialization has been finished */ + bool wlm_init_done; + + /*check if current stmt has recorded cursor*/ + bool has_cursor_record; + + /* alarm finish time */ + TimestampTz wlmalarm_fin_time; + + /* latch for wlm */ + Latch wlm_mainloop_latch; + + /* got sigterm signal */ + int wlm_got_sigterm; + + /* wlm thread is got sighup signal */ + int wlm_got_sighup; + + MemoryContext MaskPasswordMemoryContext; + MemoryContext query_resource_track_mcxt; +} knl_t_wlmthrd_context; + +#define RANDOM_LEN 16 +#define NUMBER_OF_SAVED_DERIVEKEYS 48 + +typedef struct knl_t_aes_context { + /* Save several used derive_keys, random_salt and user_key in one thread. */ + bool encryption_function_call; + GS_UCHAR derive_vector_saved[RANDOM_LEN]; + GS_UCHAR mac_vector_saved[RANDOM_LEN]; + GS_UCHAR input_saved[RANDOM_LEN]; + + /* + * Thread-local variables including random_salt, derive_key and key + * will be saved during the thread. + */ + GS_UCHAR random_salt_saved[RANDOM_LEN]; + + /* Save several used derive_keys, random_salt and user_key in one thread. */ + bool decryption_function_call; + GS_UCHAR derive_vector_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR mac_vector_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR random_salt_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR user_input_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UINT64 decryption_count; + + /* + * The usage_frequency is used to decided which random_salt to start comparing with + * The usage_frequency is based on the recent using times of derive_key + */ + GS_UINT32 usage_frequency[NUMBER_OF_SAVED_DERIVEKEYS]; + /* + * The insert_position is used to seperate two different region for usage_frequency + * From 0 to NUMBER_OF_SAVED_DERIVEKEYS/2 -1 , there are derive_keys used many times. + * From NUMBER_OF_SAVED_DERIVEKEYS/2 to NUMBER_OF_SAVED_DERIVEKEYS -1, + * these derive_keys were used only one time. + * Therefore, the newborn derive_key will be saved in insert_position. + */ + GS_UINT32 insert_position; + + /* use saved random salt unless unavailable*/ + GS_UCHAR gs_random_salt_saved[RANDOM_LEN]; + bool random_salt_tag; + GS_UINT64 random_salt_count; +} knl_t_aes_context; + +typedef struct knl_t_time_context { + /* Set at postmaster start */ + TimestampTz pg_start_time; + + /* Set at configuration reload */ + TimestampTz pg_reload_time; + + TimestampTz stmt_system_timestamp; + + bool is_abstimeout_in; + +} knl_t_time_context; + +/* We provide a small stack of ErrorData records for re-entrant cases */ +#define ERRORDATA_STACK_SIZE 5 + +/* buffers for formatted timestamps that might be used by both + * log_line_prefix and csv logs. + */ +#define FORMATTED_TS_LEN 128 + +typedef struct knl_t_log_context { + /* switch a new plog message every 1s */ + struct timeval plog_msg_switch_tm; + + /* for magnetic disk */ + char* plog_md_read_entry; + + char* plog_md_write_entry; + + /* for OBS */ + char* plog_obs_list_entry; + + char* plog_obs_read_entry; + + char* plog_obs_write_entry; + + /* for Hadoop */ + char* plog_hdp_read_entry; + + char* plog_hdp_write_entry; + + char* plog_hdp_open_entry; + + /* for remote datanode */ + char* plog_remote_read_entry; + + char*** g_plog_msgmem_array; + + /* for elog.cpp */ + struct ErrorContextCallback* error_context_stack; + + sigjmp_buf* PG_exception_stack; + + char** thd_bt_symbol; + + bool flush_message_immediately; + + int Log_destination; + + bool disable_log_output; + + bool on_mask_password; + + bool openlog_done; + + bool error_with_nodename; + + struct ErrorData* errordata; + + struct LogControlData* pLogCtl; + + int errordata_stack_depth; /* index of topmost active frame */ + + int recursion_depth; /* to detect actual recursion */ + + char formatted_start_time[FORMATTED_TS_LEN]; + + char formatted_log_time[FORMATTED_TS_LEN]; + + int save_format_errnumber; + + const char* save_format_domain; + + unsigned long syslog_seq; + + /* static counter for line numbers */ + long log_line_number; + + /* has counter been reset in current process? */ + ThreadId log_my_pid; + + /* static counter for line numbers */ + long csv_log_line_number; + + /* has counter been reset in current process? */ + ThreadId csv_log_my_pid; + + /* + * msgbuf is declared as static to save the data to put + * which can be flushed in next put_line() + */ + struct StringInfoData* msgbuf; + + unsigned char* module_logging_configure; + +} knl_t_log_context; + +typedef struct knl_t_format_context { + bool all_digits; + + struct DCHCacheEntry* DCH_cache; + + /* number of entries */ + int n_DCH_cache; + + int DCH_counter; + + struct NUMCacheEntry* NUM_cache; + + /* number of entries */ + int n_NUM_cache; + + int NUM_counter; + + /* see `EarlyBindingTLSVariables` */ + struct NUMCacheEntry* last_NUM_cache_entry; +} knl_t_format_context; + +typedef struct knl_t_audit_context { + bool Audit_delete; + /* + + * Flags set by interrupt handlers for later service in the main loop. + + */ + /* for only sessionid needed by SDBSS */ + TimestampTz user_login_time; + volatile sig_atomic_t need_exit; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t rotation_requested; + uint64 space_beyond_size; /* The static variable for print log when exceeding the space limit */ + uint64 pgaudit_totalspace; + int64 next_rotation_time; + bool pipe_eof_seen; + bool rotation_disabled; + FILE *sysauditFile; + FILE *policyauditFile; + Latch sysAuditorLatch; + time_t last_pgaudit_start_time; + struct AuditIndexTable* audit_indextbl; + char pgaudit_filepath[MAXPGPATH]; +#define NBUFFER_LISTS 256 + List* buffer_lists[NBUFFER_LISTS]; +} knl_stat_context; + +typedef struct knl_t_async_context { + struct AsyncQueueControl* asyncQueueControl; + + /* + * listenChannels identifies the channels we are actually listening to + * (ie, have committed a LISTEN on). It is a simple list of channel names, + * allocated in t_thrd.top_mem_cxt. + */ + List* listenChannels; /* list of C strings */ + List* pendingActions; /* list of ListenAction */ + List* upperPendingActions; /* list of upper-xact lists */ + List* pendingNotifies; /* list of Notifications */ + List* upperPendingNotifies; /* list of upper-xact lists */ + + /* True if we've registered an on_shmem_exit cleanup */ + bool unlistenExitRegistered; + /* True if we're currently registered as a listener in t_thrd.asy_cxt.asyncQueueControl */ + bool amRegisteredListener; + /* has this backend sent notifications in the current transaction? */ + bool backendHasSentNotifications; +} knl_t_async_context; + +typedef struct knl_t_explain_context { + int explain_perf_mode; + bool explain_light_proxy; +} knl_t_explain_context; + +typedef struct knl_t_arch_context { + time_t last_pgarch_start_time; + time_t last_sigterm_time; + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + volatile sig_atomic_t wakened; + volatile sig_atomic_t ready_to_stop; + /* + * Latch used by signal handlers to wake up the sleep in the main loop. + */ + Latch mainloop_latch; + +} knl_t_arch_context; + +/* Maximum length of a timezone name (not including trailing null) */ +#define TZ_STRLEN_MAX 255 +#define LOG_MAX_NODENAME_LEN 64 + +typedef struct knl_t_logger_context { + int64 next_rotation_time; + bool pipe_eof_seen; + bool rotation_disabled; + FILE* syslogFile; + FILE* csvlogFile; + FILE* querylogFile; + char* last_query_log_file_name; + FILE* asplogFile; + int64 first_syslogger_file_time; + char* last_file_name; + char* last_csv_file_name; + char* last_asp_file_name; + Latch sysLoggerLatch; + +#define NBUFFER_LISTS 256 + List* buffer_lists[NBUFFER_LISTS]; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t rotation_requested; +} knl_t_logger_context; + +/***************************************************************************** + * System interrupt and critical section handling + * + * There are two types of interrupts that a running backend needs to accept + * without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM). + * In both cases, we need to be able to clean up the current transaction + * gracefully, so we can't respond to the interrupt instantaneously --- + * there's no guarantee that internal data structures would be self-consistent + * if the code is interrupted at an arbitrary instant. Instead, the signal + * handlers set flags that are checked periodically during execution. + * + * The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots + * where it is normally safe to accept a cancel or die interrupt. In some + * cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that + * might sometimes be called in contexts that do *not* want to allow a cancel + * or die interrupt. The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros + * allow code to ensure that no cancel or die interrupt will be accepted, + * even if CHECK_FOR_INTERRUPTS() gets called in a subroutine. The interrupt + * will be held off until CHECK_FOR_INTERRUPTS() is done outside any + * HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section. + * + * Special mechanisms are used to let an interrupt be accepted when we are + * waiting for a lock or when we are waiting for command input (but, of + * course, only if the interrupt holdoff counter is zero). See the + * related code for details. + * + * A lost connection is handled similarly, although the loss of connection + * does not raise a signal, but is detected when we fail to write to the + * socket. If there was a signal for a broken connection, we could make use of + * it by setting t_thrd.int_cxt.ClientConnectionLost in the signal handler. + * + * A related, but conceptually distinct, mechanism is the "critical section" + * mechanism. A critical section not only holds off cancel/die interrupts, + * but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC) + * --- that is, a system-wide reset is forced. Needless to say, only really + * *critical* code should be marked as a critical section! Currently, this + * mechanism is only used for XLOG-related code. + * + *****************************************************************************/ +typedef struct knl_t_interrupt_context { + /* these are marked volatile because they are set by signal handlers: */ + volatile bool QueryCancelPending; + + volatile bool PoolValidateCancelPending; + + volatile bool ProcDiePending; + + volatile bool ClientConnectionLost; + + volatile bool StreamConnectionLost; + + volatile bool ImmediateInterruptOK; + + /* these are marked volatile because they are examined by signal handlers: */ + volatile uint32 InterruptHoldoffCount; + + volatile uint32 CritSectionCount; + + volatile bool InterruptByCN; + +} knl_t_interrupt_context; + +typedef int64 pg_time_t; +#define INVALID_CANCEL_KEY (0) + +typedef struct knl_t_proc_context { + ThreadId MyProcPid; + + pg_time_t MyStartTime; + + int MyPMChildSlot; + + long MyCancelKey; + + char* MyProgName; + + BackendId MyBackendId; + + /* + * t_thrd.proc_cxt.DataDir is the absolute path to the top level of the PGDATA directory tree. + * Except during early startup, this is also the server's working directory; + * most code therefore can simply use relative paths and not reference t_thrd.proc_cxt.DataDir + * explicitly. + */ + char* DataDir; + + char OutputFileName[MAXPGPATH]; /* debugging output file */ + + char pkglib_path[MAXPGPATH]; /* full path to lib directory */ + + char postgres_exec_path[MAXPGPATH]; /* full path to backend */ + + /* Flag: PostgresMain enter queries loop */ + bool postgres_initialized; + + class PostgresInitializer* PostInit; + + /* + * This flag is set during proc_exit() to change ereport()'s behavior, + * so that an ereport() from an on_proc_exit routine cannot get us out + * of the exit procedure. We do NOT want to go back to the idle loop... + */ + bool proc_exit_inprogress; + bool sess_exit_inprogress; + bool pooler_connection_inprogress; +} knl_t_proc_context; + +typedef struct knl_t_vacuum_context { + int VacuumPageHit; + + int VacuumPageMiss; + + int VacuumPageDirty; + + int VacuumCostBalance; /* working state for vacuum */ + + bool VacuumCostActive; + + /* just for dfs table on "vacuum full" */ + bool vacuum_full_compact; + + /* A few variables that don't seem worth passing around as parameters */ + MemoryContext vac_context; + + bool in_vacuum; + +} knl_t_vacuum_context; + +typedef struct knl_t_autovacuum_context { + /* Flags set by signal handlers */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGUSR2; + volatile sig_atomic_t got_SIGTERM; + + /* Comparison point for determining whether freeze_max_age is exceeded */ + TransactionId recentXid; + + /* Default freeze ages to use for autovacuum (varies by database) */ + int64 default_freeze_min_age; + int64 default_freeze_table_age; + + /* Memory context for long-lived data */ + MemoryContext AutovacMemCxt; + + /* hash table to keep all tuples stat info that fetchs from DataNode */ + HTAB* pgStatAutoVacInfo; + + char* autovacuum_coordinators_string; + int autovac_iops_limits; + struct AutoVacuumShmemStruct* AutoVacuumShmem; + + /* the database list in the launcher, and the context that contains it */ + struct Dllist* DatabaseList; + MemoryContext DatabaseListCxt; + + /* Pointer to my own WorkerInfo, valid on each worker */ + struct WorkerInfoData* MyWorkerInfo; + + /* PID of launcher, valid only in worker while shutting down */ + ThreadId AutovacuumLauncherPid; + + TimestampTz last_read; +} knl_t_autovacuum_context; + +typedef struct knl_t_aiocompleter_context { + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t config_requested; +} knl_t_aiocompleter_context; + +typedef struct knl_t_twophasecleaner_context { + char pgxc_clean_log_path[MAX_PATH_LEN]; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_twophasecleaner_context; + +typedef struct knl_t_bgwriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + int thread_id; + pg_time_t next_flush_time; +} knl_t_bgwriter_context; + +typedef struct knl_t_pagewriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + int page_writer_after; + int pagewriter_id; + pg_time_t next_flush_time; +} knl_t_pagewriter_context; + +#define MAX_SEQ_SCANS 100 + +typedef struct knl_t_dynahash_context { + MemoryContext CurrentDynaHashCxt; + + /* + * We track active hash_seq_search scans here. The need for this mechanism + * comes from the fact that a scan will get confused if a bucket split occurs + * while it's in progress: it might visit entries twice, or even miss some + * entirely (if it's partway through the same bucket that splits). Hence + * we want to inhibit bucket splits if there are any active scans on the + * table being inserted into. This is a fairly rare case in current usage, + * so just postponing the split until the next insertion seems sufficient. + * + * Given present usages of the function, only a few scans are likely to be + * open concurrently; so a finite-size stack of open scans seems sufficient, + * and we don't worry that linear search is too slow. Note that we do + * allow multiple scans of the same hashtable to be open concurrently. + * + * This mechanism can support concurrent scan and insertion in a shared + * hashtable if it's the same backend doing both. It would fail otherwise, + * but locking reasons seem to preclude any such scenario anyway, so we don't + * worry. + * + * This arrangement is reasonably robust if a transient hashtable is deleted + * without notifying us. The absolute worst case is we might inhibit splits + * in another table created later at exactly the same address. We will give + * a warning at transaction end for reference leaks, so any bugs leading to + * lack of notification should be easy to catch. + */ + HTAB* seq_scan_tables[MAX_SEQ_SCANS]; /* tables being scanned */ + + int seq_scan_level[MAX_SEQ_SCANS]; /* subtransaction nest level */ + + int num_seq_scans; +} knl_t_dynahash_context; + +typedef struct knl_t_bulkload_context { + char distExportDataDir[MAX_PATH_LEN]; +#define TIME_STAMP_STR_LEN 15 + char distExportTimestampStr[15]; + TransactionId distExportCurrXid; + uint32 distExportNextSegNo; + int illegal_character_err_cnt; + bool illegal_character_err_threshold_reported; +} knl_t_bulkload_context; + +typedef struct knl_t_job_context { + /* Share memory for job scheudler. */ + struct JobScheduleShmemStruct* JobScheduleShmem; + /* Flags set by signal handlers */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGUSR2; + volatile sig_atomic_t got_SIGTERM; + /* Memory context for long-lived data */ + MemoryContext JobScheduleMemCxt; + /* expired job list at present, and the context that contains it */ + struct Dllist* ExpiredJobList; + MemoryContext ExpiredJobListCtx; + + /* job info */ + struct JobWorkerInfoData* MyWorkerInfo; +} knl_t_job_context; + +typedef uintptr_t Datum; + +typedef struct knl_t_postgres_context { + /* clear key message that may appear in core file for security */ + bool clear_key_memory; + + /* true if create table in create table as select' has been done */ + bool table_created_in_CTAS; + const char* debug_query_string; /* client-supplied query string */ + bool isInResetUserName; + + /* Note: whereToSendOutput is initialized for the bootstrap/standalone case */ + int whereToSendOutput; // enum CommandDest + struct ResourcePool* local_foreign_respool; + + /* max_stack_depth converted to bytes for speed of checking */ + long max_stack_depth_bytes; + + /* mark if the initial password has been changed or not */ + bool password_changed; + + /* + * Stack base pointer -- initialized by PostmasterMain and inherited by + * subprocesses. This is not static because old versions of PL/Java modify + * it directly. Newer versions use set_stack_base(), but we want to stay + * binary-compatible for the time being. + */ + char* stack_base_ptr; + + /* + * Flag to keep track of whether we have started a transaction. + * For extended query protocol this has to be remembered across messages. + */ + bool xact_started; + + /* + * Flag to indicate that we are doing the outer loop's read-from-client, + * as opposed to any random read from client that might happen within + * commands like COPY FROM STDIN. + */ + bool DoingCommandRead; + + /* assorted command-line switches */ + const char* userDoption; /* -D switch */ + bool EchoQuery; + + /* + * people who want to use EOF should #define DONTUSENEWLINE in + * tcop/tcopdebug.h + */ +#ifndef TCOP_DONTUSENEWLINE + int UseNewLine; /* Use newlines query delimiters (the default) */ +#else + int UseNewLine; /* Use EOF as query delimiters */ +#endif /* TCOP_DONTUSENEWLINE */ + + /* whether or not, and why, we were canceled by conflict with recovery */ + bool RecoveryConflictPending; + bool RecoveryConflictRetryable; + int RecoveryConflictReason; // enum ProcSignalReason + + /* reused buffer to pass to SendRowDescriptionMessage() */ + struct StringInfoData* row_description_buf; + const char* clobber_qstr; + + /* + * for delta merge + */ + Datum query_result; + + /* + * It is a list of some relations or columns which have no statistic info. + * we should output them to warning or log if it is not null. + */ + List* g_NoAnalyzeRelNameList; + + /* show real run datanodes of pbe query for explain analyze/performance */ + bool mark_explain_analyze; + + /* + * false if the query is non-explain or explain analyze(performance), true if + * it is simple explain. + */ + bool mark_explain_only; + + /* GUC variable to enable plan cache if stmt_name is not given. */ + bool enable_explicit_stmt_name; + long val; + // struct rusage Save_r; // not define + struct timeval Save_t; + + bool gpc_fisrt_send_clean; // cn send clean to dn for global plan cache +} knl_t_postgres_context; + +typedef struct knl_t_utils_context { + /* to record the sequent count when creating memory context */ + int mctx_sequent_count; + + /* to track the memory context when query is executing */ + struct MemoryTrackData* ExecutorMemoryTrack; + +#ifdef MEMORY_CONTEXT_CHECKING + /* to record the sequent count of GUC setting */ + int memory_track_sequent_count; + + /* to record the plan node id of GUC setting */ + int memory_track_plan_nodeid; + + /* to save the detail allocation information */ + struct StringInfoData* detailTrackingBuf; +#endif + + /* used to track the element count in the output file */ + int track_cnt; + + /* gValueCompareContext -- special memory context for partition value routing. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during each value's partition routing, and reset after done. + */ + MemoryContext gValueCompareContext; + /*ContextUsedCount-- is used to count the number of gValueCompareContext to + * avoid the allocated memory is released early. + */ + int ContextUsedCount; + struct PartitionIdentifier* partId; +#define RANGE_PARTKEYMAXNUM 4 + struct Const* valueItemArr[RANGE_PARTKEYMAXNUM]; + struct ResourceOwnerData* TopResourceOwner; + struct ResourceOwnerData* CurrentResourceOwner; + struct ResourceOwnerData* STPSavedResourceOwner; + struct ResourceOwnerData* CurTransactionResourceOwner; + struct ResourceOwnerData* TopTransactionResourceOwner; + struct ResourceReleaseCallbackItem* ResourceRelease_callbacks; + bool SortColumnOptimize; + struct RelationData* pRelatedRel; + +#ifndef WIN32 + timer_t sigTimerId; +#endif + unsigned int ConfigFileLineno; + const char* GUC_flex_fatal_errmsg; + sigjmp_buf* GUC_flex_fatal_jmp; + + /* Static state for pg_strtok */ + char* pg_strtok_ptr; + /* + * Support for newNode() macro + * + * In a GCC build there is no need for the global variable newNodeMacroHolder. + * However, we create it anyway, to support the case of a non-GCC-built + * loadable module being loaded into a GCC-built backend. + */ + Node* newNodeMacroHolder; + + /* Memory Protecting feature initialization flag */ + bool gs_mp_inited; + + /* Memory Protecting need flag */ + bool memNeedProtect; + + /* Track memory usage in chunks at individual thread level */ + int32 trackedMemChunks; + + /* Track memory usage in bytes at individual thread level */ + int64 trackedBytes; + + /* Per thread/query quota in chunks */ + int32 maxChunksPerThread; /* Will be updated by CostSize */ + + /* Memory Protecting feature initialization flag */ + int32 beyondChunk; + + bool backend_reserved; +} knl_t_utils_context; + +/* Maximum number of preferred Datanodes that can be defined in cluster */ +#define MAX_PREFERRED_NODES 64 + +typedef struct knl_t_pgxc_context { + Oid primary_data_node; + int num_preferred_data_nodes; + Oid preferred_data_node[MAX_PREFERRED_NODES]; + + /* + * Local cache for current installation/redistribution node group, allocated in + * t_thrd.top_mem_cxt at session start-up time + */ + char* current_installation_nodegroup; + char* current_redistribution_nodegroup; + int globalBucketLen; + + /* Global number of nodes. Point to a shared memory block */ + int* shmemNumCoords; + int* shmemNumCoordsInCluster; + int* shmemNumDataNodes; + int* shmemNumDataStandbyNodes; + + /* Shared memory tables of node definitions */ + struct NodeDefinition* coDefs; + struct NodeDefinition* coDefsInCluster; + struct NodeDefinition* dnDefs; + struct NodeDefinition* dnStandbyDefs; + + /* pgxcnode.cpp */ + struct PGXCNodeNetCtlLayer* pgxc_net_ctl; + + struct Instrumentation* GlobalNetInstr; + + /* save the connection to the compute pool */ + struct pgxc_node_handle* compute_pool_handle; + struct pg_conn* compute_pool_conn; + + /* execRemote.cpp */ + + /* + * Flag to track if a temporary object is accessed by the current transaction + */ + bool temp_object_included; + +#ifdef PGXC + struct abort_callback_type* dbcleanup_info; +#endif +#define SOCKET_BUFFER_LEN 256 + char socket_buffer[SOCKET_BUFFER_LEN]; + bool is_gc_fdw; + bool is_gc_fdw_analyze; + int gc_fdw_current_idx; + int gc_fdw_max_idx; + int gc_fdw_run_version; + struct SnapshotData* gc_fdw_snapshot; +#define BEGIN_CMD_BUFF_SIZE 1024 + char begin_cmd[BEGIN_CMD_BUFF_SIZE]; +} knl_t_pgxc_context; + +typedef struct knl_t_conn_context { + /* connector.cpp */ + char* value_drivertype; + char* value_dsn; + char* value_username; + char* value_password; + char* value_sql; + char* value_encoding; + /* + * Extension Connector Controler + */ + class ECControlBasic* ecCtrl; + + /* odbc_connector.cpp */ + + void* dl_handle; + void* _conn; + void* _result; + struct pg_enc2name* _DatabaseEncoding; + const char* _float_inf; +} knl_t_conn_context; + +typedef struct { + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t sleep_long; +} knl_t_page_redo_context; + +typedef struct knl_t_startup_context { + /* + * Flags set by interrupt handlers for later service in the redo loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t failover_triggered; + volatile sig_atomic_t switchover_triggered; + volatile sig_atomic_t primary_triggered; + volatile sig_atomic_t standby_triggered; + + /* + * Flag set when executing a restore command, to tell SIGTERM signal handler + * that it's safe to just proc_exit. + */ + volatile sig_atomic_t in_restore_command; + + struct notifysignaldata* NotifySigState; +} knl_t_startup_context; + +typedef struct knl_t_alarmchecker_context { + /* private variables for alarm checker thread */ + Latch AlarmCheckerLatch; /* the tls latch for alarm checker thread */ + + /* signal handle flags */ + volatile sig_atomic_t gotSighup; /* the signal flag of SIGHUP */ + volatile sig_atomic_t gotSigdie; /* the signal flag of SIGTERM and SIGINT */ +} knl_t_alarmchecker_context; + +typedef struct knl_t_lwlockmoniter_context { + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_lwlockmoniter_context; + +typedef struct knl_t_remoteservice_context { + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + struct RPCServerContext* server_context; +} knl_t_remoteservice_context; + +typedef struct knl_t_walwriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_walwriter_context; + +typedef struct knl_t_walwriterauxiliary_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_walwriterauxiliary_context; + +typedef struct knl_t_poolcleaner_context { + volatile sig_atomic_t shutdown_requested; +} knl_t_poolcleaner_context; + +typedef struct knl_t_catchup_context { + volatile sig_atomic_t catchup_shutdown_requested; +} knl_t_catchup_context; + +/* + * Pointer to a location in the XLOG. These pointers are 64 bits wide, + * because we don't want them ever to overflow. + */ +typedef uint64 XLogRecPtr; + +typedef struct knl_t_checkpoint_context { + struct CheckpointerShmemStruct* CheckpointerShmem; + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t checkpoint_requested; + volatile sig_atomic_t shutdown_requested; + + /* Private state */ + bool ckpt_active; + + /* these values are valid when ckpt_active is true: */ + pg_time_t ckpt_start_time; + XLogRecPtr ckpt_start_recptr; + double ckpt_cached_elapsed; + + pg_time_t last_checkpoint_time; + pg_time_t last_xlog_switch_time; + pg_time_t last_truncate_log_time; + int absorb_counter; + int ckpt_done; +} knl_t_checkpoint_context; + +typedef struct knl_t_snapshot_context { + struct SnapshotData* SnapshotNowData; + struct SnapshotData* SnapshotSelfData; + struct SnapshotData* SnapshotAnyData; + struct SnapshotData* SnapshotToastData; +} knl_t_snapshot_context; + +typedef struct knl_t_comm_context { + /* + *last epoll wait up time of receiver loop thread + */ + uint64 g_receiver_loop_poll_up; + int LibcommThreadType; + /* + * libcomm thread use libcomm_semaphore wake up work thread + * libcomm_semaphore save as mailbox->semaphore + * libcomm_semaphore create by gs_poll_create when work thread call gs_connect/gs_send/gs_wait_poll first time + * libcomm_semaphore destory by gs_poll_close when thread exit + */ + struct binary_semaphore* libcomm_semaphore; + struct mc_poller* g_libcomm_poller_list; + struct mc_poller_hndl_list* g_libcomm_recv_poller_hndl_list; + /* + *last time when consumer thread exit gs_wait_poll + */ + uint64 g_consumer_process_duration; + /* + *last time when producer thread exit gs_send + */ + uint64 g_producer_process_duration; + pid_t MyPid; + uint64 debug_query_id; +} knl_t_comm_context; + +typedef struct knl_t_libpq_context { + /* + * listen socket for unix domain connection + * between receiver flow control thread and postmaster + */ + int listen_fd_for_recv_flow_ctrl; + /* Where the Unix socket file is */ + char sock_path[MAXPGPATH]; + /* Where the Unix socket file for ha port is */ + char ha_sock_path[MAXPGPATH]; + char* PqSendBuffer; + /* Size send buffer */ + int PqSendBufferSize; + /* Next index to store a byte in PqSendBuffer */ + int PqSendPointer; + /* Next index to send a byte in PqSendBuffer */ + int PqSendStart; + char* PqRecvBuffer; + /* Size recv buffer */ + int PqRecvBufferSize; + /* Next index to read a byte from PqRecvBuffer */ + int PqRecvPointer; + /* End of data available in PqRecvBuffer */ + int PqRecvLength; + /* Message status */ + bool PqCommBusy; + bool DoingCopyOut; +#ifdef HAVE_SIGPROCMASK + sigset_t UnBlockSig, BlockSig, StartupBlockSig; +#else + int UnBlockSig, BlockSig, StartupBlockSig; +#endif + + /* variables for save query results to temp file*/ + bool save_query_result_to_disk; + struct TempFileContextInfo* PqTempFileContextInfo; + + /* + * pre-parsed content of HBA config file: list of HbaLine structs. + * parsed_hba_context is the memory context where it lives. + */ + List* parsed_hba_lines; + MemoryContext parsed_hba_context; +} knl_t_libpq_context; + +typedef struct knl_t_contrib_context { + int g_searchletId; + struct S_VectorInfo* vec_info; + bool assert_enabled; + Datum g_log_hostname; + Datum g_log_nodename; + + /* Hash table for caching the results of shippability lookups */ + HTAB* ShippableCacheHash; + + /* + * Valid options for gc_fdw. + * Allocated and filled in InitGcFdwOptions. + */ + struct PgFdwOption* gc_fdw_options; +} knl_t_contrib_context; + +typedef struct knl_t_basebackup_context { + char g_xlog_location[MAXPGPATH]; + + char* buf_block; +} knl_t_basebackup_context; + +typedef struct knl_t_datarcvwriter_context { + HTAB* data_writer_rel_tab; + + /* Data receiver writer flush page error times */ + uint32 dataRcvWriterFlushPageErrorCount; + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t gotSIGHUP; + volatile sig_atomic_t shutdownRequested; + + bool AmDataReceiverForDummyStandby; + + /* max dummy data write file (default: 1GB) */ + uint32 dummy_data_writer_file_num; +} knl_t_datarcvwriter_context; + +typedef struct knl_t_libwalreceiver_context { + /* Current connection to the primary, if any */ + struct pg_conn* streamConn; + + /* Buffer for currently read records */ + char* recvBuf; +} knl_t_libwalreceiver_context; + +typedef struct knl_t_sig_context { + unsigned long signal_handle_cnt; + GsSignalCheckType gs_sigale_check_type; + uint64 session_id; +} knl_t_sig_context; + +typedef struct knl_t_slot_context { + /* Control array for replication slot management */ + struct ReplicationSlotCtlData* ReplicationSlotCtl; + + /* My backend's replication slot in the shared memory array */ + struct ReplicationSlot* MyReplicationSlot; +} knl_t_slot_context; + +typedef struct knl_t_datareceiver_context { + int DataReplFlag; + + /* + * Flags set by interrupt handlers of datareceiver for later service in the + * main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + + struct StandbyDataReplyMessage* reply_message; + + /* Current connection to the primary, if any */ + struct pg_conn* dataStreamingConn; + + /* DummyStandby */ + bool AmDataReceiverForDummyStandby; + + /* Buffer for currently read data */ + char* recvBuf; + + struct DataRcvData* DataRcv; + + /* + * About SIGTERM handling: + * + * We can't just exit(1) within SIGTERM signal handler, because the signal + * might arrive in the middle of some critical operation, like while we're + * holding a spinlock. We also can't just set a flag in signal handler and + * check it in the main loop, because we perform some blocking operations + * like libpqrcv_PQexec(), which can take a long time to finish. + * + * We use a combined approach: When DataRcvImmediateInterruptOK is true, it's + * safe for the signal handler to elog(FATAL) immediately. Otherwise it just + * sets got_SIGTERM flag, which is checked in the main loop when convenient. + * + * This is very much like what regular backends do with t_thrd.int_cxt.ImmediateInterruptOK, + * ProcessInterrupts() etc. + */ + volatile bool DataRcvImmediateInterruptOK; +} knl_t_datareceiver_context; + +typedef struct knl_t_datasender_context { + /* Array of DataSnds in shared memory */ + struct DataSndCtlData* DataSndCtl; + + /* My slot in the shared memory array */ + struct DataSnd* MyDataSnd; + + /* Global state */ + bool am_datasender; /* Am I a datasender process ? */ + + /* + * Buffer for processing reply messages. + */ + struct StringInfoData* reply_message; + + /* + * Buffer for constructing outgoing messages + * (1 + sizeof(DataPageMessageHeader) + MAX_SEND_SIZE bytes) + */ + char* output_message; + + /* + * dummy standby read data file num and offset. + */ + uint32 dummy_data_read_file_num; + FILE* dummy_data_read_file_fd; + + /* + * Timestamp of the last receipt of the reply from the standby. + */ + TimestampTz last_reply_timestamp; + + /* Have we sent a heartbeat message asking for reply, since last reply? */ + bool ping_sent; + + /* Flags set by signal handlers for later service in main loop */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t datasender_shutdown_requested; + volatile sig_atomic_t datasender_ready_to_stop; +} knl_t_datasender_context; + +typedef struct knl_t_walreceiver_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + volatile sig_atomic_t start_switchover; + char gucconf_file[MAXPGPATH]; + char temp_guc_conf_file[MAXPGPATH]; + char gucconf_lock_file[MAXPGPATH]; + /* + * Define guc parameters which would not be synchronized to standby. + * NB: RESERVE_SIZE must be changed at the same time. + */ + char** reserve_item; +#define RESERVE_SIZE 33 + time_t standby_config_modify_time; + time_t Primary_config_modify_time; + TimestampTz last_sendfilereply_timestamp; + int check_file_timeout; + struct WalRcvCtlBlock* walRcvCtlBlock; + struct StandbyReplyMessage* reply_message; + struct StandbyHSFeedbackMessage* feedback_message; + struct StandbySwitchRequestMessage* request_message; + struct ConfigModifyTimeMessage* reply_modify_message; + volatile bool WalRcvImmediateInterruptOK; + bool AmWalReceiverForFailover; + bool AmWalReceiverForStandby; + int control_file_writed; +} knl_t_walreceiver_context; + +typedef struct knl_t_walsender_context { + char* load_cu_buffer; + int load_cu_buffer_size; + /* Array of WalSnds in shared memory */ + struct WalSndCtlData* WalSndCtl; + /* My slot in the shared memory array */ + struct WalSnd* MyWalSnd; + int logical_xlog_advanced_timeout; /* maximum time to write xlog * of logical slot advance */ + typedef int ServerMode; + typedef int DemoteMode; + DemoteMode Demotion; + /* State for WalSndWakeupRequest */ + bool wake_wal_senders; + bool wal_send_completed; + /* + * These variables are used similarly to openLogFile/Id/Seg/Off, + * but for walsender to read the XLOG. + */ + int sendFile; + typedef uint64 XLogSegNo; + XLogSegNo sendSegNo; + uint32 sendOff; + struct WSXLogJustSendRegion* wsXLogJustSendRegion; + /* + * How far have we sent WAL already? This is also advertised in + * MyWalSnd->sentPtr. (Actually, this is the next WAL location to send.) + */ + typedef uint64 XLogRecPtr; + XLogRecPtr sentPtr; + XLogRecPtr catchup_threshold; + /* + * Buffer for processing reply messages. + */ + struct StringInfoData* reply_message; + /* + * Buffer for processing timestamp. + */ + struct StringInfoData* tmpbuf; + /* + * Buffer for constructing outgoing messages + * (1 + sizeof(WalDataMessageHeader) + MAX_SEND_SIZE bytes) + * if with enable_mix_replication being true the new message as the following: + * (1 + sizeof(WalDataMessageHeader) + 1 + sizeof(XLogRecPtr) + MAX_SEND_SIZE bytes) + * 1 --> 'w' + * sizeof(WalDataMessageHeader) --> WalDataMessageHeader + * 1 --> 'w' + * sizeof(XLogRecPtr) -->XLogRecPtr dataStart + * MAX_SEND_SIZE bytes --> wal data bytes + */ + char* output_xlog_message; + Size output_xlog_msg_prefix_len; + /* + * Buffer for constructing outgoing messages + * (sizeof(DataElementHeaderData) + MAX_SEND_SIZE bytes) + * if with enable_mix_replication being true the new message as the following: + * (1 + sizeof(WalDataMessageHeader) + 1 + MAX_SEND_SIZE bytes) + * 1 --> 'd' + * sizeof(WalDataMessageHeader) --> WalDataMessageHeader + * 1 --> 'd' + * MAX_SEND_SIZE bytes --> wal data bytes + */ + char* output_data_message; + /* used to flag the latest length in output_data_message*/ + uint32 output_data_msg_cur_len; + XLogRecPtr output_data_msg_start_xlog; + XLogRecPtr output_data_msg_end_xlog; + /* + * The xlog reader and private info employed for the xlog parsing in wal sender. + */ + struct XLogReaderState* ws_xlog_reader; + /* + * Timestamp of the last receipt of the reply from the standby. + */ + TimestampTz last_reply_timestamp; + /* + * Timestamp of the last logical xlog advanced is written. + */ + TimestampTz last_logical_xlog_advanced_timestamp; + /* Have we sent a heartbeat message asking for reply, since last reply? */ + bool waiting_for_ping_response; + /* Flags set by signal handlers for later service in main loop */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t walsender_shutdown_requested; + volatile sig_atomic_t walsender_ready_to_stop; + volatile sig_atomic_t response_switchover_requested; + ServerMode server_run_mode; + /* for config_file */ + char gucconf_file[MAXPGPATH]; + char gucconf_lock_file[MAXPGPATH]; + /* the dummy data reader fd for the wal streaming */ + FILE* ws_dummy_data_read_file_fd; + uint32 ws_dummy_data_read_file_num; + /* Missing CU checking stuff */ + struct cbmarray* CheckCUArray; + struct LogicalDecodingContext* logical_decoding_ctx; + XLogRecPtr logical_startptr; + int remotePort; +} knl_t_walsender_context; + +typedef struct knl_t_walreceiverfuncs_context { + struct WalRcvData* WalRcv; + int WalReplIndex; +} knl_t_walreceiverfuncs_context; + +typedef struct knl_t_replgram_context { + /* Result of the parsing is returned here */ + struct Node* replication_parse_result; +} knl_t_replgram_context; + +typedef struct knl_t_replscanner_context { + struct yy_buffer_state* scanbufhandle; + struct StringInfoData* litbuf; +} knl_t_replscanner_context; + +typedef struct knl_t_syncrepgram_context { + /* Result of parsing is returned in one of these two variables */ + struct SyncRepConfigData* syncrep_parse_result; +} knl_t_syncrepgram_context; + +typedef struct knl_t_syncrepscanner_context { + struct yy_buffer_state* scanbufhandle; + struct StringInfoData* xdbuf; + int result; +} knl_t_syncrepscanner_context; + +typedef struct knl_t_syncrep_context { + struct SyncRepConfigData* SyncRepConfig; + bool announce_next_takeover; +} knl_t_syncrep_context; + +typedef struct knl_t_logical_context { + int sendFd; + uint64 sendSegNo; + uint32 sendOff; + bool ExportInProgress; + ResourceOwner SavedResourceOwnerDuringExport; +} knl_t_logical_context; + +typedef struct knl_t_dataqueue_context { + struct DataQueueData* DataSenderQueue; + struct DataQueueData* DataWriterQueue; + struct BCMElementData* BCMElementArray; + uint32 BCMElementArrayIndex1; + uint32 BCMElementArrayIndex2; + struct DataQueuePtr* BCMElementArrayOffset1; + struct DataQueuePtr* BCMElementArrayOffset2; + uint32 save_send_dummy_count; + struct HTAB* heap_sync_rel_tab; +} knl_t_dataqueue_context; + +typedef struct knl_t_walrcvwriter_context { + uint64 walStreamWrite; /* last byte + 1 written out in the standby */ + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t gotSIGHUP; + volatile sig_atomic_t shutdownRequested; + + int WAL_WRITE_UNIT_BYTES; + uint32 ws_dummy_data_writer_file_num; +} knl_t_walrcvwriter_context; + +typedef int CacheSlotId_t; +typedef void (*pg_on_exit_callback)(int code, Datum arg); +typedef void (*shmem_startup_hook_type)(void); +typedef struct ONEXIT { + pg_on_exit_callback function; + Datum arg; +} ONEXIT; +#define MAX_ON_EXITS 20 +typedef struct knl_t_storage_context { + /* + * Bookkeeping for tracking emulated transactions in recovery + */ + TransactionId latestObservedXid; + struct RunningTransactionsData* CurrentRunningXacts; + struct VirtualTransactionId* proc_vxids; + + union BufferDescPadded* BufferDescriptors; + char* BufferBlocks; + struct WritebackContext* BackendWritebackContext; + struct HTAB* SharedBufHash; + struct HTAB* BufFreeListHash; + struct BufferDesc* InProgressBuf; + /* local state for StartBufferIO and related functions */ + volatile bool IsForInput; + /* local state for LockBufferForCleanup */ + struct BufferDesc* PinCountWaitBuf; + /* local state for aio clean up resource */ + struct AioDispatchDesc** InProgressAioDispatch; + int InProgressAioDispatchCount; + struct BufferDesc* InProgressAioBuf; + int InProgressAioType; + /* + * When btree split, it will record two xlog: + * 1. page split + * 2. insert new split page to parent + * Since it is an atomic action, don't interrupt above two steps. + * Now use a special flag to remark and dont't ereport error when read buffers. + */ + bool is_btree_split; + /* + * Backend-Private refcount management: + * + * Each buffer also has a private refcount that keeps track of the number of + * times the buffer is pinned in the current process. This is so that the + * shared refcount needs to be modified only once if a buffer is pinned more + * than once by a individual backend. It's also used to check that no buffers + * are still pinned at the end of transactions and when exiting. + * + * + * To avoid - as we used to - requiring an array with g_instance.attr.attr_storage.NBuffers entries to keep + * track of local buffers we use a small sequentially searched array + * (PrivateRefCountArray) and a overflow hash table (PrivateRefCountHash) to + * keep track of backend local pins. + * + * Until no more than REFCOUNT_ARRAY_ENTRIES buffers are pinned at once, all + * refcounts are kept track of in the array; after that, new array entries + * displace old ones into the hash table. That way a frequently used entry + * can't get "stuck" in the hashtable while infrequent ones clog the array. + * + * Note that in most scenarios the number of pinned buffers will not exceed + * REFCOUNT_ARRAY_ENTRIES. + */ + struct PrivateRefCountEntry* PrivateRefCountArray; + struct HTAB* PrivateRefCountHash; + int32 PrivateRefCountOverflowed; + uint32 PrivateRefCountClock; + /* + * Information saved between calls so we can determine the strategy + * point's advance rate and avoid scanning already-cleaned buffers. + */ + bool saved_info_valid; + int prev_strategy_buf_id; + uint32 prev_strategy_passes; + int next_to_clean; + uint32 next_passes; + /* Moving averages of allocation rate and clean-buffer density */ + float smoothed_alloc; + float smoothed_density; + + /* Pointers to shared state */ + struct BufferStrategyControl* StrategyControl; + /* remember global block slot in progress */ + CacheSlotId_t CacheBlockInProgressIO; + CacheSlotId_t CacheBlockInProgressUncompress; + CacheSlotId_t MetaBlockInProgressIO; + + List* RecoveryLockList; + int standbyWait_us; + /* + * All accesses to pg_largeobject and its index make use of a single Relation + * reference, so that we only need to open pg_relation once per transaction. + * To avoid problems when the first such reference occurs inside a + * subtransaction, we execute a slightly klugy maneuver to assign ownership of + * the Relation reference to TopTransactionResourceOwner. + */ + struct RelationData* lo_heap_r; + struct RelationData* lo_index_r; + slock_t dummy_spinlock; + int spins_per_delay; + + /* Workspace for FindLockCycle */ + struct PGPROC** visitedProcs; /* Array of visited procs */ + int nVisitedProcs; + /* Workspace for TopoSort */ + struct PGPROC** topoProcs; /* Array of not-yet-output procs */ + int* beforeConstraints; /* Counts of remaining before-constraints */ + int* afterConstraints; /* List head for after-constraints */ + /* Output area for ExpandConstraints */ + struct WAIT_ORDER* waitOrders; /* Array of proposed queue rearrangements */ + int nWaitOrders; + struct PGPROC** waitOrderProcs; /* Space for waitOrders queue contents */ + /* Current list of constraints being considered */ + struct EDGE* curConstraints; + int nCurConstraints; + int maxCurConstraints; + /* Storage space for results from FindLockCycle */ + struct EDGE* possibleConstraints; + int nPossibleConstraints; + int maxPossibleConstraints; + struct DEADLOCK_INFO* deadlockDetails; + int nDeadlockDetails; + /* PGPROC pointer of all blocking autovacuum worker found and its max size. + * blocking_autovacuum_proc_num is in [0, autovacuum_max_workers]. + * + * Partitioned table has been supported, which maybe have hundreds of partitions. + * When a few autovacuum workers are active and running, partitions of the same partitioned + * table, whose shared lock is hold by these workers, may be handled at the same time. + * So that remember all the blocked autovacuum workers and notify to cancle them. + */ + struct PGPROC** blocking_autovacuum_proc; + int blocking_autovacuum_proc_num; + TimestampTz deadlock_checker_start_time; + const char* conflicting_lock_mode_name; + ThreadId conflicting_lock_thread_id; + bool conflicting_lock_by_holdlock; + /* + * Count of the number of fast path lock slots we believe to be used. This + * might be higher than the real number if another backend has transferred + * our locks to the primary lock table, but it can never be lower than the + * real value, since only we can acquire locks on our own behalf. + */ + int FastPathLocalUseCount; + volatile struct FastPathStrongRelationLockData* FastPathStrongRelationLocks; + /* + * Pointers to hash tables containing lock state + * + * The LockMethodLockHash and LockMethodProcLockHash hash tables are in + * shared memory; LockMethodLocalHash is local to each backend. + */ + struct HTAB* LockMethodLockHash; + struct HTAB* LockMethodProcLockHash; + struct HTAB* LockMethodLocalHash; + /* private state for error cleanup */ + struct LOCALLOCK* StrongLockInProgress; + struct LOCALLOCK* awaitedLock; + struct ResourceOwnerData* awaitedOwner; + /* PGPROC pointer of blocking data redistribution proc. */ + struct PGPROC* blocking_redistribution_proc; + struct VirtualTransactionId* lock_vxids; + + /* if false, this transaction has the same timeout to check deadlock + * with the others. if true, the larger timeout, the lower possibility + * of aborting. the default timeout is defined by *DeadlockTimeout*. + * one case is that, when VACUUM FULL PARTITION is running while another + * transaction is also running, and deadlock maybe happens, so that one + * of them shall abort and rollback. because VACUUM FULL is a heavy work + * and we always want it to work done. so that we can enlarge the timeout + * to check deadlock, then another transaction has the bigger possibility + * to check and rollback. + */ + bool EnlargeDeadlockTimeout; + /* If we are waiting for a lock, this points to the associated LOCALLOCK */ + struct LOCALLOCK* lockAwaited; + /* Mark these volatile because they can be changed by signal handler */ + volatile bool standby_timeout_active; + volatile bool statement_timeout_active; + volatile bool deadlock_timeout_active; + volatile bool lockwait_timeout_active; + volatile int deadlock_state; + volatile bool cancel_from_timeout; + /* timeout_start_time is set when log_lock_waits is true */ + TimestampTz timeout_start_time; + /* statement_fin_time is valid only if statement_timeout_active is true */ + TimestampTz statement_fin_time; + TimestampTz statement_fin_time2; /* valid only in recovery */ + /* global variable */ + char* pageCopy; + + int num_held_lwlocks; + struct LWLockHandle* held_lwlocks; + int lock_addin_request; + bool lock_addin_request_allowed; + int counts_for_pid; + int* block_counts; + /* description, memory context opt */ + MemoryContext remote_function_context; + bool work_env_init; + + shmem_startup_hook_type shmem_startup_hook; + Size total_addin_request; + bool addin_request_allowed; + + /* + * This flag tracks whether we've called atexit() in the current process + * (or in the parent postmaster). + */ + bool atexit_callback_setup; + ONEXIT on_proc_exit_list[MAX_ON_EXITS]; + ONEXIT on_shmem_exit_list[MAX_ON_EXITS]; + ONEXIT before_shmem_exit_list[MAX_ON_EXITS]; + int on_proc_exit_index; + int on_shmem_exit_index; + int before_shmem_exit_index; + + union CmprMetaUnion* cmprMetaInfo; + + /* Thread share file id cache */ + struct HTAB* DataFileIdCache; + + /* + * Maximum number of file descriptors to open for either VFD entries or + * AllocateFile/AllocateDir/OpenTransientFile operations. This is initialized + * to a conservative value, and remains that way indefinitely in bootstrap or + * standalone-backend cases. In normal postmaster operation, the postmaster + * calls set_max_safe_fds() late in initialization to update the value, and + * that value is then inherited by forked subprocesses. * + * Note: the value of max_files_per_process is taken into account while + * setting this variable, and so need not be tested separately. + */ + int max_safe_fds; /* default if not changed */ + /* reserve `1000' for thread-private file id */ + int max_userdatafiles; + +} knl_t_storage_context; + +typedef struct knl_t_port_context { + char cryptresult[21]; /* encrypted result (1 + 4 + 4 + 11 + 1)*/ + char buf[24]; + + bool thread_is_exiting; + struct ThreadArg* m_pThreadArg; + + locale_t save_locale_r; + NameData cur_datcollate; /* LC_COLLATE setting */ + NameData cur_datctype; /* LC_CTYPE setting */ + NameData cur_monetary; /* LC_MONETARY setting */ + NameData cur_numeric; /* LC_NUMERIC setting */ +} knl_t_port_context; + +typedef struct knl_t_tsearch_context { + int nres; + int ntres; +} knl_t_tsearch_context; + +typedef struct knl_t_postmaster_context { +/* Notice: the value is same sa GUC_MAX_REPLNODE_NUM */ +#ifdef ENABLE_MULTIPLE_NODES +#define MAX_REPLNODE_NUM 8 +#else +#define MAX_REPLNODE_NUM 9 +#endif +#define MAXLISTEN 64 +#define IP_LEN 64 + + /* flag when process startup packet for logic conn */ + bool ProcessStartupPacketForLogicConn; + + /* socket and port for recv gs_sock from receiver flow control*/ + int sock_for_libcomm; + struct Port* port_for_libcomm; + bool KeepSocketOpenForStream; + + /* + * Stream replication connection info between primary, standby and secondary. + * + * ReplConn*1 is used to connect primary on standby, or standby on primary, or + * connect primary or standby on secondary. + * ReplConn*2 is used to connect secondary on primary or standby, or connect primary + * or standby on secondary. + */ + struct replconninfo* ReplConnArray[MAX_REPLNODE_NUM]; + bool ReplConnChanged[MAX_REPLNODE_NUM]; + struct hashmemdata* HaShmData; + + /* The socket(s) we're listening to. */ + pgsocket ListenSocket[MAXLISTEN]; + char LocalAddrList[MAXLISTEN][IP_LEN]; + int LocalIpNum; + int listen_sock_type[MAXLISTEN]; /* ori type: enum ListenSocketType */ + gs_thread_t CurExitThread; + + bool IsRPCWorkerThread; + + /* private variables for reaper backend thread */ + Latch ReaperBackendLatch; + + /* Database Security: Support database audit */ + bool audit_primary_start; + bool audit_primary_failover; + bool audit_standby_switchover; + bool senderToDummyStandby; + bool senderToBuildStandby; + bool ReachedNormalRunning; /* T if we've reached PM_RUN */ + bool redirection_done; /* stderr redirected for syslogger? */ + + /* received START_AUTOVAC_LAUNCHER signal */ + volatile sig_atomic_t start_autovac_launcher; + /* the launcher needs to be signalled to communicate some condition */ + volatile bool avlauncher_needs_signal; + /* received PMSIGNAL_START_JOB_SCHEDULER signal */ + volatile sig_atomic_t start_job_scheduler; + /* the jobscheduler needs to be signalled to communicate some condition */ + volatile bool jobscheduler_needs_signal; + + /* + * State for assigning random salts and cancel keys. + * Also, the global t_thrd.proc_cxt.MyCancelKey passes the cancel key assigned to a given + * backend from the postmaster to that backend (via fork). + */ + unsigned int random_seed; + struct timeval random_start_time; + + /* key pair to be used as object id while using advisory lock for backup */ + Datum xc_lockForBackupKey1; + Datum xc_lockForBackupKey2; + + bool forceNoSeparate; + +#ifndef WIN32 + /* + * File descriptors for pipe used to monitor if postmaster is alive. + * First is POSTMASTER_FD_WATCH, second is POSTMASTER_FD_OWN. + */ + int postmaster_alive_fds[2]; +#endif + +#ifndef WIN32 + int syslogPipe[2]; +#endif +} knl_t_postmaster_context; + +#define CACHE_BUFF_LEN 128 + +typedef struct knl_t_buf_context { + char cash_buf[CACHE_BUFF_LEN]; + char config_opt_buf[256]; + char config_opt_reset_buf[256]; + /* this buffer is only used if errno has a bogus value */ + char errorstr_buf[48]; + char pg_rusage_show_buf[100]; + char unpack_sql_state_buf[12]; + char show_enable_dynamic_workload_buf[8]; + char show_enable_memory_limit_buf[8]; + char show_log_file_mode_buf[8]; + char show_memory_detail_tracking_buf[256]; + char show_tcp_keepalives_idle_buf[16]; + char show_tcp_keepalives_interval_buf[16]; + char show_tcp_keepalives_count_buf[16]; + char show_unix_socket_permissions_buf[8]; +} knl_t_buf_context; + +typedef struct knl_t_bootstrap_context { +#define MAXATTR 40 +#define NAMEDATALEN 64 + int num_columns_read; + int yyline; /* line number for error reporting */ + + int MyAuxProcType; /* declared in miscadmin.h */ + struct RelationData* boot_reldesc; /* current relation descriptor */ + struct FormData_pg_attribute* attrtypes[MAXATTR]; /* points to attribute info */ + int numattr; /* number of attributes for cur. rel */ + + struct typmap** Typ; + struct typmap* Ap; + + MemoryContext nogc; /* special no-gc mem context */ + struct _IndexList* ILHead; + char newStr[NAMEDATALEN + 1]; /* array type names < NAMEDATALEN long */ +} knl_t_bootstrap_context; + +typedef struct knl_t_locale_context { + /* Environment variable storage area */ + char lc_collate_envbuf[LC_ENV_BUFSIZE]; + + char lc_ctype_envbuf[LC_ENV_BUFSIZE]; + + char lc_monetary_envbuf[LC_ENV_BUFSIZE]; + + char lc_numeric_envbuf[LC_ENV_BUFSIZE]; + + char lc_time_envbuf[LC_ENV_BUFSIZE]; + +} knl_t_locale_context; + + + +typedef struct knl_t_stat_context { + /* + * thread statistics of bad block + * used for cache current thread statistics of bad block + * update global_bad_block_stat by pgstat_send_badblock_stat() + */ + MemoryContext local_bad_block_mcxt; + HTAB* local_bad_block_stat; + +} knl_t_stat_context; + +typedef struct knl_t_thread_pool_context { + class ThreadPoolGroup* group; + class ThreadPoolListener* listener; + class ThreadPoolWorker* worker; + class ThreadPoolScheduler* scheduler; +#ifdef ENABLE_MULTIPLE_NODES + class ThreadPoolStream* stream; +#endif + bool reaper_dead_session; +} knl_t_thread_pool_context; + +/* percentile sql responese time */ +typedef struct knl_t_percentile_context { + bool need_exit; + volatile bool need_reset_timer; + struct PGXCNodeAllHandles* pgxc_all_handles; + volatile sig_atomic_t got_SIGHUP; +} knl_t_percentile_context; + +typedef struct knl_t_perf_snap_context { + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + time_t last_snapshot_start_time; + + struct pg_conn* connect; /* Cross database query */ + struct pg_result* res; + int cancel_request; /* connection cancel request */ + uint64 curr_table_size; // Current table size + uint64 curr_snapid; // snapid is Increasing + MemoryContext PerfSnapMemCxt; + volatile bool request_snapshot; + volatile bool is_mem_protect; +} knl_t_perf_snap_context; + +typedef struct knl_t_ash_context { + time_t last_ash_start_time; + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + uint32 slot; // the slot of ActiveSessionHistArray + struct wait_event_info* waitEventStr; +} knl_t_ash_context; + +typedef struct knl_t_statement_context { + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + int slow_sql_retention_time; + int full_sql_retention_time; +} knl_t_statement_context; + + +/* Default send interval is 1s */ +const int DEFAULT_SEND_INTERVAL = 1000; +typedef struct knl_t_heartbeat_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + struct heartbeat_state* state; +} knl_t_heartbeat_context; + +/* compaction and compaction worker use */ +typedef struct knl_t_ts_compaction_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t sleep_long; + MemoryContext compaction_mem_cxt; + MemoryContext compaction_data_cxt; +} knl_t_ts_compaction_context; + +typedef struct knl_t_security_policy_context { + MemoryContext policy_audit_context; + MemoryContext policy_mask_context; + MemoryContext policy_rls_context; +} knl_t_security_policy_context; + +typedef struct knl_t_csnmin_sync_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_csnmin_sync_context; + +#ifdef ENABLE_MOT +/* MOT thread attributes */ +#define MOT_MAX_ERROR_MESSAGE 256 +#define MOT_MAX_ERROR_FRAMES 32 + +#define MOT_LOG_BUF_SIZE_KB 1 +#define MOT_MAX_LOG_LINE_LENGTH (MOT_LOG_BUF_SIZE_KB * 1024 - 1) + +namespace MOT { + struct StringBuffer; +} + +struct mot_error_frame { + int m_errorCode; + int m_severity; + const char* m_file; + int m_line; + const char* m_function; + const char* m_entity; + const char* m_context; + char m_errorMessage[MOT_MAX_ERROR_MESSAGE]; +}; + +typedef struct knl_t_mot_context { + // last error + int last_error_code; + int last_error_severity; + mot_error_frame error_stack[MOT_MAX_ERROR_FRAMES]; + int error_frame_count; + + // log line + char log_line[MOT_MAX_LOG_LINE_LENGTH + 1]; + int log_line_pos; + bool log_line_overflow; + MOT::StringBuffer* log_line_buf; + + // misc + uint8_t log_level; + bool init_codegen_once; + + uint16_t currentThreadId; + int currentNumaNodeId; + + int bindPolicy; + unsigned int mbindFlags; +} knl_t_mot_context; +#endif + +/* thread context. */ +typedef struct knl_thrd_context { + knl_thread_role role; + knl_thread_role subrole; /* we need some sub role status. */ + + struct GsSignalSlot* signal_slot; + /* Pointer to this process's PGPROC and PGXACT structs, if any */ + struct PGPROC* proc; + struct PGXACT* pgxact; + struct Backend* bn; + // we need to have a fake session to do some initialize + knl_session_context* fake_session; + + int myLogicTid; + + MemoryContext top_mem_cxt; + MemoryContextGroup* mcxt_group; + + knl_t_aes_context aes_cxt; + knl_t_aiocompleter_context aio_cxt; + knl_t_alarmchecker_context alarm_cxt; + knl_t_arch_context arch; + knl_t_async_context asy_cxt; + knl_t_audit_context audit; + knl_t_autovacuum_context autovacuum_cxt; + knl_t_basebackup_context basebackup_cxt; + knl_t_bgwriter_context bgwriter_cxt; + knl_t_bootstrap_context bootstrap_cxt; + knl_t_pagewriter_context pagewriter_cxt; + knl_t_buf_context buf_cxt; + knl_t_bulkload_context bulk_cxt; + knl_t_cbm_context cbm_cxt; + knl_t_checkpoint_context checkpoint_cxt; + knl_t_codegen_context codegen_cxt; + knl_t_comm_context comm_cxt; + knl_t_conn_context conn_cxt; + knl_t_contrib_context contrib_cxt; + knl_t_cstore_context cstore_cxt; + knl_t_dataqueue_context dataqueue_cxt; + knl_t_datarcvwriter_context datarcvwriter_cxt; + knl_t_datareceiver_context datareceiver_cxt; + knl_t_datasender_context datasender_cxt; + knl_t_dfs_context dfs_cxt; + knl_t_dynahash_context dyhash_cxt; + knl_t_explain_context explain_cxt; + knl_t_format_context format_cxt; + knl_t_index_context index_cxt; + knl_t_interrupt_context int_cxt; + knl_t_job_context job_cxt; + knl_t_libwalreceiver_context libwalreceiver_cxt; + knl_t_locale_context lc_cxt; + knl_t_log_context log_cxt; + knl_t_logger_context logger; + knl_t_logical_context logical_cxt; + knl_t_libpq_context libpq_cxt; + knl_t_lwlockmoniter_context lwm_cxt; + knl_t_mem_context mem_cxt; + knl_t_obs_context obs_cxt; + knl_t_pgxc_context pgxc_cxt; + knl_t_port_context port_cxt; + knl_t_postgres_context postgres_cxt; + knl_t_postmaster_context postmaster_cxt; + knl_t_proc_context proc_cxt; + knl_t_relopt_context relopt_cxt; + knl_t_remoteservice_context rs_cxt; + knl_t_replgram_context replgram_cxt; + knl_t_replscanner_context replscanner_cxt; + knl_t_shemem_ptr_context shemem_ptr_cxt; + knl_t_sig_context sig_cxt; + knl_t_slot_context slot_cxt; + knl_t_snapshot_context snapshot_cxt; + knl_t_startup_context startup_cxt; + knl_t_stat_context stat_cxt; + knl_t_storage_context storage_cxt; + knl_t_syncrep_context syncrep_cxt; + knl_t_syncrepgram_context syncrepgram_cxt; + knl_t_syncrepscanner_context syncrepscanner_cxt; + knl_t_thread_pool_context threadpool_cxt; + knl_t_time_context time_cxt; + knl_t_tsearch_context tsearch_cxt; + knl_t_twophasecleaner_context tpcleaner_cxt; + knl_t_utils_context utils_cxt; + knl_t_vacuum_context vacuum_cxt; + knl_t_walsender_context walsender_cxt; + knl_t_walrcvwriter_context walrcvwriter_cxt; + knl_t_walreceiver_context walreceiver_cxt; + knl_t_walreceiverfuncs_context walreceiverfuncs_cxt; + knl_t_walwriter_context walwriter_cxt; + knl_t_walwriterauxiliary_context walwriterauxiliary_cxt; + knl_t_catchup_context catchup_cxt; + knl_t_wlmthrd_context wlm_cxt; + knl_t_xact_context xact_cxt; + knl_t_xlog_context xlog_cxt; + knl_t_percentile_context percentile_cxt; + knl_t_perf_snap_context perf_snap_cxt; + knl_t_page_redo_context page_redo_cxt; + knl_t_heartbeat_context heartbeat_cxt; + knl_t_security_policy_context security_policy_cxt; + knl_t_poolcleaner_context poolcleaner_cxt; + knl_t_ts_compaction_context ts_compaction_cxt; + knl_t_ash_context ash_cxt; + knl_t_statement_context statement_cxt; + knl_t_streaming_context streaming_cxt; + knl_t_csnmin_sync_context csnminsync_cxt; +#ifdef ENABLE_MOT + knl_t_mot_context mot_cxt; +#endif +} knl_thrd_context; + +#ifdef ENABLE_MOT +extern void knl_thread_mot_init(); +#endif + +extern void knl_thread_init(knl_thread_role role); +extern THR_LOCAL knl_thrd_context t_thrd; + +inline bool StreamThreadAmI() +{ + return (t_thrd.role == STREAM_WORKER || t_thrd.role == THREADPOOL_STREAM); +} + +inline void StreamTopConsumerIam() +{ + t_thrd.subrole = TOP_CONSUMER; +} + +inline bool StreamTopConsumerAmI() +{ + return (t_thrd.subrole == TOP_CONSUMER); +} + +#ifdef ENABLE_MULTIPLE_NODES +#define BUCKETDATALEN (t_thrd.pgxc_cxt.globalBucketLen) +#define BUCKETSTRLEN (6*BUCKETDATALEN) +#endif + +RedoInterruptCallBackFunc RegisterRedoInterruptCallBack(RedoInterruptCallBackFunc func); +void RedoInterruptCallBack(); + +#endif /* SRC_INCLUDE_KNL_KNL_THRD_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/knl/knl_variable.h postgresql-hll-2.14/include/include/knl/knl_variable.h --- postgresql-hll-2.14_old/include/include/knl/knl_variable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/knl/knl_variable.h 2020-12-12 17:06:43.216347638 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_variable.h + * Include file for knl variables. + * + * IDENTIFICATION + * src/include/knl/knl_variable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_BARIABLE_H_ +#define SRC_INCLUDE_KNL_VARIABLE_H_ + +#include "knl/knl_instance.h" +#include "knl/knl_session.h" +#include "knl/knl_thread.h" + +#endif /* SRC_INCLUDE_KNL_VARIABLE_H_ */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/krad.h postgresql-hll-2.14/include/include/krad.h --- postgresql-hll-2.14_old/include/include/krad.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krad.h 2020-12-12 17:06:43.216347638 +0800 @@ -0,0 +1,265 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright 2013 Red Hat, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This API is not considered as stable as the main krb5 API. + * + * - We may make arbitrary incompatible changes between feature releases + * (e.g. from 1.12 to 1.13). + * - We will make some effort to avoid making incompatible changes for + * bugfix releases, but will make them if necessary. + */ + +#ifndef KRAD_H_ +#define KRAD_H_ + +#include +#include +#include +#include + +#define KRAD_PACKET_SIZE_MAX 4096 + +#define KRAD_SERVICE_TYPE_LOGIN 1 +#define KRAD_SERVICE_TYPE_FRAMED 2 +#define KRAD_SERVICE_TYPE_CALLBACK_LOGIN 3 +#define KRAD_SERVICE_TYPE_CALLBACK_FRAMED 4 +#define KRAD_SERVICE_TYPE_OUTBOUND 5 +#define KRAD_SERVICE_TYPE_ADMINISTRATIVE 6 +#define KRAD_SERVICE_TYPE_NAS_PROMPT 7 +#define KRAD_SERVICE_TYPE_AUTHENTICATE_ONLY 8 +#define KRAD_SERVICE_TYPE_CALLBACK_NAS_PROMPT 9 +#define KRAD_SERVICE_TYPE_CALL_CHECK 10 +#define KRAD_SERVICE_TYPE_CALLBACK_ADMINISTRATIVE 11 + +typedef struct krad_attrset_st krad_attrset; +typedef struct krad_packet_st krad_packet; +typedef struct krad_client_st krad_client; +typedef unsigned char krad_code; +typedef unsigned char krad_attr; + +/* Called when a response is received or the request times out. */ +typedef void +(*krad_cb)(krb5_error_code retval, const krad_packet *request, + const krad_packet *response, void *data); + +/* + * Called to iterate over a set of requests. Either the callback will be + * called until it returns NULL, or it will be called with cancel = TRUE to + * terminate in the middle of an iteration. + */ +typedef const krad_packet * +(*krad_packet_iter_cb)(void *data, krb5_boolean cancel); + +/* + * Code + */ + +/* Convert a code name to its number. Only works for codes defined + * by RFC 2875 or 2882. Returns 0 if the name was not found. */ +krad_code +krad_code_name2num(const char *name); + +/* Convert a code number to its name. Only works for attributes defined + * by RFC 2865 or 2882. Returns NULL if the name was not found. */ +const char * +krad_code_num2name(krad_code code); + +/* + * Attribute + */ + +/* Convert an attribute name to its number. Only works for attributes defined + * by RFC 2865. Returns 0 if the name was not found. */ +krad_attr +krad_attr_name2num(const char *name); + +/* Convert an attribute number to its name. Only works for attributes defined + * by RFC 2865. Returns NULL if the name was not found. */ +const char * +krad_attr_num2name(krad_attr type); + +/* + * Attribute set + */ + +/* Create a new attribute set. */ +krb5_error_code +krad_attrset_new(krb5_context ctx, krad_attrset **set); + +/* Create a deep copy of an attribute set. */ +krb5_error_code +krad_attrset_copy(const krad_attrset *set, krad_attrset **copy); + +/* Free an attribute set. */ +void +krad_attrset_free(krad_attrset *set); + +/* Add an attribute to a set. */ +krb5_error_code +krad_attrset_add(krad_attrset *set, krad_attr type, const krb5_data *data); + +/* Add a four-octet unsigned number attribute to the given set. */ +krb5_error_code +krad_attrset_add_number(krad_attrset *set, krad_attr type, krb5_ui_4 num); + +/* Delete the specified attribute. */ +void +krad_attrset_del(krad_attrset *set, krad_attr type, size_t indx); + +/* Get the specified attribute. */ +const krb5_data * +krad_attrset_get(const krad_attrset *set, krad_attr type, size_t indx); + +/* + * Packet + */ + +/* Determine the bytes needed from the socket to get the whole packet. Don't + * cache the return value as it can change! Returns -1 on EBADMSG. */ +ssize_t +krad_packet_bytes_needed(const krb5_data *buffer); + +/* Free a packet. */ +void +krad_packet_free(krad_packet *pkt); + +/* + * Create a new request packet. + * + * This function takes the attributes specified in set and converts them into a + * radius packet. The packet will have a randomized id. If cb is not NULL, it + * will be called passing data as the argument to iterate over a set of + * outstanding requests. In this case, the id will be both random and unique + * across the set of requests. + */ +krb5_error_code +krad_packet_new_request(krb5_context ctx, const char *secret, krad_code code, + const krad_attrset *set, krad_packet_iter_cb cb, + void *data, krad_packet **request); + +/* + * Create a new response packet. + * + * This function is similar to krad_packet_new_requst() except that it crafts a + * packet in response to a request packet. This new packet will borrow values + * from the request such as the id and the authenticator. + */ +krb5_error_code +krad_packet_new_response(krb5_context ctx, const char *secret, krad_code code, + const krad_attrset *set, const krad_packet *request, + krad_packet **response); + +/* + * Decode a request radius packet from krb5_data. + * + * The resulting decoded packet will be a request packet stored in *reqpkt. + * + * If cb is NULL, *duppkt will always be NULL. + * + * If cb is not NULL, it will be called (with the data argument) to iterate + * over a set of requests currently being processed. In this case, if the + * packet is a duplicate of an already received request, the original request + * will be set in *duppkt. + */ +krb5_error_code +krad_packet_decode_request(krb5_context ctx, const char *secret, + const krb5_data *buffer, krad_packet_iter_cb cb, + void *data, const krad_packet **duppkt, + krad_packet **reqpkt); + +/* + * Decode a response radius packet from krb5_data. + * + * The resulting decoded packet will be a response packet stored in *rsppkt. + * + * If cb is NULL, *reqpkt will always be NULL. + * + * If cb is not NULL, it will be called (with the data argument) to iterate + * over a set of requests awaiting responses. In this case, if the response + * packet matches one of these requests, the original request will be set in + * *reqpkt. + */ +krb5_error_code +krad_packet_decode_response(krb5_context ctx, const char *secret, + const krb5_data *buffer, krad_packet_iter_cb cb, + void *data, const krad_packet **reqpkt, + krad_packet **rsppkt); + +/* Encode packet. */ +const krb5_data * +krad_packet_encode(const krad_packet *pkt); + +/* Get the code for the given packet. */ +krad_code +krad_packet_get_code(const krad_packet *pkt); + +/* Get the specified attribute. */ +const krb5_data * +krad_packet_get_attr(const krad_packet *pkt, krad_attr type, size_t indx); + +/* + * Client + */ + +/* Create a new client. */ +krb5_error_code +krad_client_new(krb5_context kctx, verto_ctx *vctx, krad_client **client); + +/* Free the client. */ +void +krad_client_free(krad_client *client); + +/* + * Send a request to a radius server. + * + * The remote host may be specified by one of the following formats: + * - /path/to/unix.socket + * - IPv4 + * - IPv4:port + * - IPv4:service + * - [IPv6] + * - [IPv6]:port + * - [IPv6]:service + * - hostname + * - hostname:port + * - hostname:service + * + * The timeout parameter (milliseconds) is the total timeout across all remote + * hosts (when DNS returns multiple entries) and all retries. For stream + * sockets, the retries parameter is ignored and no retries are performed. + * + * The cb function will be called with the data argument when either a response + * is received or the request times out on all possible remote hosts. + */ +krb5_error_code +krad_client_send(krad_client *rc, krad_code code, const krad_attrset *attrs, + const char *remote, const char *secret, int timeout, + size_t retries, krad_cb cb, void *data); + +#endif /* KRAD_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/ccselect_plugin.h postgresql-hll-2.14/include/include/krb5/ccselect_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/ccselect_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/ccselect_plugin.h 2020-12-12 17:06:43.217347651 +0800 @@ -0,0 +1,105 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2011 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +/* + * Declarations for credential cache selection module implementors. + * + * The ccselect pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * Credential cache selection modules should define a function named + * ccselect__initvt, matching the signature: + * + * krb5_error_code + * ccselect_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_ccselect_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_CCSELECT_PLUGIN_H +#define KRB5_CCSELECT_PLUGIN_H + +#include +#include + +/* An abstract type for credential cache selection module data. */ +typedef struct krb5_ccselect_moddata_st *krb5_ccselect_moddata; + +#define KRB5_CCSELECT_PRIORITY_AUTHORITATIVE 2 +#define KRB5_CCSELECT_PRIORITY_HEURISTIC 1 + +/*** Method type declarations ***/ + +/* + * Mandatory: Initialize module data and set *priority_out to one of the + * KRB5_CCSELECT_PRIORITY constants above. Authoritative modules will be + * consulted before heuristic ones. + */ +typedef krb5_error_code +(*krb5_ccselect_init_fn)(krb5_context context, krb5_ccselect_moddata *data_out, + int *priority_out); + +/* + * Mandatory: Select a cache based on a server principal. Return 0 on success, + * with *cache_out set to the selected cache and *princ_out set to its default + * principal. Return KRB5_PLUGIN_NO_HANDLE to defer to other modules. Return + * KRB5_CC_NOTFOUND with *princ_out set if the client principal can be + * authoritatively determined but no cache exists for it. Return other errors + * as appropriate. + */ +typedef krb5_error_code +(*krb5_ccselect_choose_fn)(krb5_context context, krb5_ccselect_moddata data, + krb5_principal server, krb5_ccache *cache_out, + krb5_principal *princ_out); + +/* Optional: Release resources used by module data. */ +typedef void +(*krb5_ccselect_fini_fn)(krb5_context context, krb5_ccselect_moddata data); + +/*** vtable declarations **/ + +/* Credential cache selection plugin vtable for major version 1. */ +typedef struct krb5_ccselect_vtable_st { + const char *name; /* Mandatory: name of module. */ + krb5_ccselect_init_fn init; + krb5_ccselect_choose_fn choose; + krb5_ccselect_fini_fn fini; + /* Minor version 1 ends here. */ +} *krb5_ccselect_vtable; + +#endif /* KRB5_CCSELECT_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/certauth_plugin.h postgresql-hll-2.14/include/include/krb5/certauth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/certauth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/certauth_plugin.h 2020-12-12 17:06:43.217347651 +0800 @@ -0,0 +1,128 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* include/krb5/certauth_plugin.h - certauth plugin header. */ +/* + * Copyright (C) 2017 by Red Hat, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for certauth plugin module implementors. + * + * The certauth pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * certauth plugin modules should define a function named + * certauth__initvt, matching the signature: + * + * krb5_error_code + * certauth_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_certauth_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_CERTAUTH_PLUGIN_H +#define KRB5_CERTAUTH_PLUGIN_H + +#include +#include + +/* Abstract module data type. */ +typedef struct krb5_certauth_moddata_st *krb5_certauth_moddata; + +/* A module can optionally include to inspect the client principal + * entry when authorizing a request. */ +struct _krb5_db_entry_new; + +/* + * Optional: Initialize module data. + */ +typedef krb5_error_code +(*krb5_certauth_init_fn)(krb5_context context, + krb5_certauth_moddata *moddata_out); + +/* + * Optional: Clean up the module data. + */ +typedef void +(*krb5_certauth_fini_fn)(krb5_context context, krb5_certauth_moddata moddata); + +/* + * Mandatory: + * Return 0 if the DER-encoded cert is authorized for PKINIT authentication by + * princ; otherwise return one of the following error codes: + * - KRB5KDC_ERR_CLIENT_NAME_MISMATCH - incorrect SAN value + * - KRB5KDC_ERR_INCONSISTENT_KEY_PURPOSE - incorrect EKU + * - KRB5KDC_ERR_CERTIFICATE_MISMATCH - other extension error + * - KRB5_PLUGIN_NO_HANDLE - the module has no opinion about cert + * + * - opts is used by built-in modules to receive internal data, and must be + * ignored by other modules. + * - db_entry receives the client principal database entry, and can be ignored + * by modules that do not link with libkdb5. + * - *authinds_out optionally returns a null-terminated list of authentication + * indicator strings upon KRB5_PLUGIN_NO_HANDLE or accepted authorization. + */ +typedef krb5_error_code +(*krb5_certauth_authorize_fn)(krb5_context context, + krb5_certauth_moddata moddata, + const uint8_t *cert, size_t cert_len, + krb5_const_principal princ, const void *opts, + const struct _krb5_db_entry_new *db_entry, + char ***authinds_out); + +/* + * Free indicators allocated by a module. Mandatory if authorize returns + * authentication indicators. + */ +typedef void +(*krb5_certauth_free_indicator_fn)(krb5_context context, + krb5_certauth_moddata moddata, + char **authinds); + +typedef struct krb5_certauth_vtable_st { + const char *name; + krb5_certauth_init_fn init; + krb5_certauth_fini_fn fini; + krb5_certauth_authorize_fn authorize; + krb5_certauth_free_indicator_fn free_ind; +} *krb5_certauth_vtable; + +#endif /* KRB5_CERTAUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/clpreauth_plugin.h postgresql-hll-2.14/include/include/krb5/clpreauth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/clpreauth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/clpreauth_plugin.h 2020-12-12 17:06:43.217347651 +0800 @@ -0,0 +1,346 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (c) 2006 Red Hat, Inc. + * Portions copyright (c) 2006, 2011 Massachusetts Institute of Technology + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Red Hat, Inc., nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for clpreauth plugin module implementors. + * + * The clpreauth interface has a single supported major version, which is + * 1. Major version 1 has a current minor version of 2. clpreauth modules + * should define a function named clpreauth__initvt, matching + * the signature: + * + * krb5_error_code + * clpreauth_modname_initvt(krb5_context context, int maj_ver, + * int min_ver, krb5_plugin_vtable vtable); + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for the interface and maj_ver: + * maj_ver == 1: Cast to krb5_clpreauth_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_CLPREAUTH_PLUGIN_H +#define KRB5_CLPREAUTH_PLUGIN_H + +#include +#include + +/* clpreauth mechanism property flags */ + +/* Provides a real answer which we can send back to the KDC. The client + * assumes that one real answer will be enough. */ +#define PA_REAL 0x00000001 + +/* Doesn't provide a real answer, but must be given a chance to run before any + * REAL mechanism callbacks. */ +#define PA_INFO 0x00000002 + +/* Abstract type for a client request information handle. */ +typedef struct krb5_clpreauth_rock_st *krb5_clpreauth_rock; + +/* Abstract types for module data and per-request module data. */ +typedef struct krb5_clpreauth_moddata_st *krb5_clpreauth_moddata; +typedef struct krb5_clpreauth_modreq_st *krb5_clpreauth_modreq; + +/* Before using a callback after version 1, modules must check the vers + * field of the callback structure. */ +typedef struct krb5_clpreauth_callbacks_st { + int vers; + + /* + * If an AS-REP has been received, return the enctype of the AS-REP + * encrypted part. Otherwise return the enctype chosen from etype-info, or + * the first requested enctype if no etype-info was received. + */ + krb5_enctype (*get_etype)(krb5_context context, krb5_clpreauth_rock rock); + + /* Get a pointer to the FAST armor key, or NULL if the client is not using + * FAST. The returned pointer is an alias and should not be freed. */ + krb5_keyblock *(*fast_armor)(krb5_context context, + krb5_clpreauth_rock rock); + + /* + * Get a pointer to the client-supplied reply key, possibly invoking the + * prompter to ask for a password if this has not already been done. The + * returned pointer is an alias and should not be freed. + */ + krb5_error_code (*get_as_key)(krb5_context context, + krb5_clpreauth_rock rock, + krb5_keyblock **keyblock); + + /* Replace the reply key to be used to decrypt the AS response. */ + krb5_error_code (*set_as_key)(krb5_context context, + krb5_clpreauth_rock rock, + const krb5_keyblock *keyblock); + + /* End of version 1 clpreauth callbacks. */ + + /* + * Get the current time for use in a preauth response. If + * allow_unauth_time is true and the library has been configured to allow + * it, the current time will be offset using unauthenticated timestamp + * information received from the KDC in the preauth-required error, if one + * has been received. Otherwise, the timestamp in a preauth-required error + * will only be used if it is protected by a FAST channel. Only set + * allow_unauth_time if using an unauthenticated time offset would not + * create a security issue. + */ + krb5_error_code (*get_preauth_time)(krb5_context context, + krb5_clpreauth_rock rock, + krb5_boolean allow_unauth_time, + krb5_timestamp *time_out, + krb5_int32 *usec_out); + + /* Set a question to be answered by the responder and optionally provide + * a challenge. */ + krb5_error_code (*ask_responder_question)(krb5_context context, + krb5_clpreauth_rock rock, + const char *question, + const char *challenge); + + /* Get an answer from the responder, or NULL if the question was + * unanswered. */ + const char *(*get_responder_answer)(krb5_context context, + krb5_clpreauth_rock rock, + const char *question); + + /* Indicate interest in the AS key through the responder interface. */ + void (*need_as_key)(krb5_context context, krb5_clpreauth_rock rock); + + /* + * Get a configuration/state item from an input ccache, which may allow it + * to retrace the steps it took last time. The returned data string is an + * alias and should not be freed. + */ + const char *(*get_cc_config)(krb5_context context, + krb5_clpreauth_rock rock, const char *key); + + /* + * Set a configuration/state item which will be recorded to an output + * ccache, if the calling application supplied one. Both key and data + * should be valid UTF-8 text. + */ + krb5_error_code (*set_cc_config)(krb5_context context, + krb5_clpreauth_rock rock, + const char *key, const char *data); + + /* End of version 2 clpreauth callbacks (added in 1.11). */ + + /* + * Prevent further fallbacks to other preauth mechanisms if the KDC replies + * with an error. (The module itself can still respond to errors with its + * tryagain method, or continue after KDC_ERR_MORE_PREAUTH_DATA_REQUIRED + * errors with its process method.) A module should invoke this callback + * from the process method when it generates an authenticated request using + * credentials; often this will be the first or only client message + * generated by the mechanism. + */ + void (*disable_fallback)(krb5_context context, krb5_clpreauth_rock rock); + + /* End of version 3 clpreauth callbacks (added in 1.17). */ +} *krb5_clpreauth_callbacks; + +/* + * Optional: per-plugin initialization/cleanup. The init function is called by + * libkrb5 when the plugin is loaded, and the fini function is called before + * the plugin is unloaded. These may be called multiple times in case the + * plugin is used in multiple contexts. The returned context lives the + * lifetime of the krb5_context. + */ +typedef krb5_error_code +(*krb5_clpreauth_init_fn)(krb5_context context, + krb5_clpreauth_moddata *moddata_out); +typedef void +(*krb5_clpreauth_fini_fn)(krb5_context context, + krb5_clpreauth_moddata moddata); + +/* + * Optional (mandatory before MIT krb5 1.12): pa_type will be a member of the + * vtable's pa_type_list. Return PA_REAL if pa_type is a real + * preauthentication type or PA_INFO if it is an informational type. If this + * function is not defined in 1.12 or later, all pa_type values advertised by + * the module will be assumed to be real. + */ +typedef int +(*krb5_clpreauth_get_flags_fn)(krb5_context context, krb5_preauthtype pa_type); + +/* + * Optional: per-request initialization/cleanup. The request_init function is + * called when beginning to process a get_init_creds request and the + * request_fini function is called when processing of the request is complete. + * This is optional. It may be called multiple times in the lifetime of a + * krb5_context. + */ +typedef void +(*krb5_clpreauth_request_init_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_clpreauth_modreq *modreq_out); +typedef void +(*krb5_clpreauth_request_fini_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_clpreauth_modreq modreq); + +/* + * Optional: process server-supplied data in pa_data and set responder + * questions. + * + * encoded_previous_request may be NULL if there has been no previous request + * in the AS exchange. + */ +typedef krb5_error_code +(*krb5_clpreauth_prep_questions_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_clpreauth_modreq modreq, + krb5_get_init_creds_opt *opt, + krb5_clpreauth_callbacks cb, + krb5_clpreauth_rock rock, + krb5_kdc_req *request, + krb5_data *encoded_request_body, + krb5_data *encoded_previous_request, + krb5_pa_data *pa_data); + +/* + * Mandatory: process server-supplied data in pa_data and return created data + * in pa_data_out. Also called after the AS-REP is received if the AS-REP + * includes preauthentication data of the associated type. + * + * as_key contains the client-supplied key if known, or an empty keyblock if + * not. If it is empty, the module may use gak_fct to fill it in. + * + * encoded_previous_request may be NULL if there has been no previous request + * in the AS exchange. + */ +typedef krb5_error_code +(*krb5_clpreauth_process_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_clpreauth_modreq modreq, + krb5_get_init_creds_opt *opt, + krb5_clpreauth_callbacks cb, + krb5_clpreauth_rock rock, + krb5_kdc_req *request, + krb5_data *encoded_request_body, + krb5_data *encoded_previous_request, + krb5_pa_data *pa_data, + krb5_prompter_fct prompter, void *prompter_data, + krb5_pa_data ***pa_data_out); + +/* + * Optional: Attempt to use error and error_padata to try to recover from the + * given error. To work with both FAST and non-FAST errors, an implementation + * should generally consult error_padata rather than decoding error->e_data. + * For non-FAST errors, it contains the e_data decoded as either pa-data or + * typed-data. + * + * If this function is provided, and it returns 0 and stores data in + * pa_data_out, then the client library will retransmit the request. + */ +typedef krb5_error_code +(*krb5_clpreauth_tryagain_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_clpreauth_modreq modreq, + krb5_get_init_creds_opt *opt, + krb5_clpreauth_callbacks cb, + krb5_clpreauth_rock rock, + krb5_kdc_req *request, + krb5_data *encoded_request_body, + krb5_data *encoded_previous_request, + krb5_preauthtype pa_type, + krb5_error *error, + krb5_pa_data **error_padata, + krb5_prompter_fct prompter, void *prompter_data, + krb5_pa_data ***pa_data_out); + +/* + * Optional: receive krb5_get_init_creds_opt information. The attr and value + * information supplied should be copied into moddata by the module if it + * wishes to reference it after returning from this call. + */ +typedef krb5_error_code +(*krb5_clpreauth_supply_gic_opts_fn)(krb5_context context, + krb5_clpreauth_moddata moddata, + krb5_get_init_creds_opt *opt, + const char *attr, const char *value); + +typedef struct krb5_clpreauth_vtable_st { + /* Mandatory: name of module. */ + char *name; + + /* Mandatory: pointer to zero-terminated list of pa_types which this module + * can provide services for. */ + krb5_preauthtype *pa_type_list; + + /* Optional: pointer to zero-terminated list of enc_types which this module + * claims to add support for. */ + krb5_enctype *enctype_list; + + krb5_clpreauth_init_fn init; + krb5_clpreauth_fini_fn fini; + krb5_clpreauth_get_flags_fn flags; + krb5_clpreauth_request_init_fn request_init; + krb5_clpreauth_request_fini_fn request_fini; + krb5_clpreauth_process_fn process; + krb5_clpreauth_tryagain_fn tryagain; + krb5_clpreauth_supply_gic_opts_fn gic_opts; + /* Minor version 1 ends here. */ + + krb5_clpreauth_prep_questions_fn prep_questions; + /* Minor version 2 ends here. */ +} *krb5_clpreauth_vtable; + +/* + * This function allows a clpreauth plugin to obtain preauth options. The + * preauth_data returned from this function should be freed by calling + * krb5_get_init_creds_opt_free_pa(). + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_get_pa(krb5_context context, + krb5_get_init_creds_opt *opt, + int *num_preauth_data, + krb5_gic_opt_pa_data **preauth_data); + +/* + * This function frees the preauth_data that was returned by + * krb5_get_init_creds_opt_get_pa(). + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_free_pa(krb5_context context, + int num_preauth_data, + krb5_gic_opt_pa_data *preauth_data); + +#endif /* KRB5_CLPREAUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/hostrealm_plugin.h postgresql-hll-2.14/include/include/krb5/hostrealm_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/hostrealm_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/hostrealm_plugin.h 2020-12-12 17:06:43.217347651 +0800 @@ -0,0 +1,135 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2013 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for hostrealm plugin module implementors. + * + * The hostrealm pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * Hostrealm plugin modules should define a function named + * hostrealm__initvt, matching the signature: + * + * krb5_error_code + * hostrealm_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_hostrealm_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_HOSTREALM_PLUGIN_H +#define KRB5_HOSTREALM_PLUGIN_H + +#include +#include + +/* An abstract type for hostrealm module data. */ +typedef struct krb5_hostrealm_moddata_st *krb5_hostrealm_moddata; + +/*** Method type declarations ***/ + +/* Optional: Initialize module data. */ +typedef krb5_error_code +(*krb5_hostrealm_init_fn)(krb5_context context, + krb5_hostrealm_moddata *data); + +/* + * Optional: Determine the possible realms of a hostname, using only secure, + * authoritative mechanisms (ones which should be used prior to trying + * referrals when getting a service ticket). Return success with a + * null-terminated list of realms in *realms_out, KRB5_PLUGIN_NO_HANDLE to + * defer to later modules, or another error to terminate processing. + */ +typedef krb5_error_code +(*krb5_hostrealm_host_realm_fn)(krb5_context context, + krb5_hostrealm_moddata data, + const char *host, char ***realms_out); + +/* + * Optional: Determine the possible realms of a hostname, using heuristic or + * less secure mechanisms (ones which should be used after trying referrals + * when getting a service ticket). Return success with a null-terminated list + * of realms in *realms_out, KRB5_PLUGIN_NO_HANDLE to defer to later modules, + * or another error to terminate processing. + */ +typedef krb5_error_code +(*krb5_hostrealm_fallback_realm_fn)(krb5_context context, + krb5_hostrealm_moddata data, + const char *host, char ***realms_out); + +/* + * Optional: Determine the possible default realms of the local host. Return + * success with a null-terminated list of realms in *realms_out, + * KRB5_PLUGIN_NO_HANDLE to defer to later modules, or another error to + * terminate processing. + */ +typedef krb5_error_code +(*krb5_hostrealm_default_realm_fn)(krb5_context context, + krb5_hostrealm_moddata data, + char ***realms_out); + +/* + * Mandatory (if any of the query methods are implemented): Release the memory + * returned by one of the interface methods. + */ +typedef void +(*krb5_hostrealm_free_list_fn)(krb5_context context, + krb5_hostrealm_moddata data, char **list); + +/* Optional: Release resources used by module data. */ +typedef void +(*krb5_hostrealm_fini_fn)(krb5_context context, krb5_hostrealm_moddata data); + +/* hostrealm vtable for major version 1. */ +typedef struct krb5_hostrealm_vtable_st { + const char *name; /* Mandatory: name of module. */ + krb5_hostrealm_init_fn init; + krb5_hostrealm_fini_fn fini; + krb5_hostrealm_host_realm_fn host_realm; + krb5_hostrealm_fallback_realm_fn fallback_realm; + krb5_hostrealm_default_realm_fn default_realm; + krb5_hostrealm_free_list_fn free_list; + /* Minor version 1 ends here. */ +} *krb5_hostrealm_vtable; + +#endif /* KRB5_HOSTREALM_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/kadm5_auth_plugin.h postgresql-hll-2.14/include/include/krb5/kadm5_auth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/kadm5_auth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/kadm5_auth_plugin.h 2020-12-12 17:06:43.217347651 +0800 @@ -0,0 +1,306 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2017 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for kadm5_auth plugin module implementors. + * + * The kadm5_auth pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * kadm5_auth plugin modules should define a function named + * kadm5_auth__initvt, matching the signature: + * + * krb5_error_code + * kadm5_auth_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_kadm5_auth_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_KADM5_AUTH_PLUGIN_H +#define KRB5_KADM5_AUTH_PLUGIN_H + +#include +#include + +/* An abstract type for kadm5_auth module data. */ +typedef struct kadm5_auth_moddata_st *kadm5_auth_moddata; + +/* + * A module can optionally include to inspect principal or + * policy records from requests that add or modify principals or policies. + * Note that fields of principal and policy structures are only valid if the + * corresponding bit is set in the accompanying mask parameter. + */ +struct _kadm5_principal_ent_t; +struct _kadm5_policy_ent_t; + +/* + * A module can optionally generate restrictions when checking permissions for + * adding or modifying a principal entry. Restriction fields will only be + * honored if the corresponding mask bit is set. The operable mask bits are + * defined in and are: + * + * - KADM5_ATTRIBUTES for require_attrs, forbid_attrs + * - KADM5_POLICY for policy + * - KADM5_POLICY_CLR to require that policy be unset + * - KADM5_PRINC_EXPIRE_TIME for princ_lifetime + * - KADM5_PW_EXPIRATION for pw_lifetime + * - KADM5_MAX_LIFE for max_life + * - KADM5_MAX_RLIFE for max_renewable_life + */ +struct kadm5_auth_restrictions { + long mask; + krb5_flags require_attrs; + krb5_flags forbid_attrs; + krb5_deltat princ_lifetime; + krb5_deltat pw_lifetime; + krb5_deltat max_life; + krb5_deltat max_renewable_life; + char *policy; +}; + +/*** Method type declarations ***/ + +/* + * Optional: Initialize module data. acl_file is the realm's configured ACL + * file, or NULL if none was configured. Return 0 on success, + * KRB5_PLUGIN_NO_HANDLE if the module is inoperable (due to configuration, for + * example), and any other error code to abort kadmind startup. Optionally set + * *data_out to a module data object to be passed to future calls. + */ +typedef krb5_error_code +(*kadm5_auth_init_fn)(krb5_context context, const char *acl_file, + kadm5_auth_moddata *data_out); + +/* Optional: Release resources used by module data. */ +typedef void +(*kadm5_auth_fini_fn)(krb5_context context, kadm5_auth_moddata data); + +/* + * Each check method below should return 0 to explicitly authorize the request, + * KRB5_PLUGIN_NO_HANDLE to neither authorize nor deny the request, and any + * other error code (such as EPERM) to explicitly deny the request. If a check + * method is not defined, the module will neither authorize nor deny the + * request. A request succeeds if at least one kadm5_auth module explicitly + * authorizes the request and none of the modules explicitly deny it. + */ + +/* Optional: authorize an add-principal operation, and optionally generate + * restrictions. */ +typedef krb5_error_code +(*kadm5_auth_addprinc_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target, + const struct _kadm5_principal_ent_t *ent, long mask, + struct kadm5_auth_restrictions **rs_out); + +/* Optional: authorize a modify-principal operation, and optionally generate + * restrictions. */ +typedef krb5_error_code +(*kadm5_auth_modprinc_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target, + const struct _kadm5_principal_ent_t *ent, long mask, + struct kadm5_auth_restrictions **rs_out); + +/* Optional: authorize a set-string operation. */ +typedef krb5_error_code +(*kadm5_auth_setstr_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target, + const char *key, const char *value); + +/* Optional: authorize a change-password operation. */ +typedef krb5_error_code +(*kadm5_auth_cpw_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, krb5_const_principal target); + +/* Optional: authorize a randomize-keys operation. */ +typedef krb5_error_code +(*kadm5_auth_chrand_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a set-key operation. */ +typedef krb5_error_code +(*kadm5_auth_setkey_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a purgekeys operation. */ +typedef krb5_error_code +(*kadm5_auth_purgekeys_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a delete-principal operation. */ +typedef krb5_error_code +(*kadm5_auth_delprinc_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a rename-principal operation. */ +typedef krb5_error_code +(*kadm5_auth_renprinc_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal src, + krb5_const_principal dest); + +/* Optional: authorize a get-principal operation. */ +typedef krb5_error_code +(*kadm5_auth_getprinc_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a get-strings operation. */ +typedef krb5_error_code +(*kadm5_auth_getstrs_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize an extract-keys operation. */ +typedef krb5_error_code +(*kadm5_auth_extract_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, + krb5_const_principal target); + +/* Optional: authorize a list-principals operation. */ +typedef krb5_error_code +(*kadm5_auth_listprincs_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client); + +/* Optional: authorize an add-policy operation. */ +typedef krb5_error_code +(*kadm5_auth_addpol_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, const char *policy, + const struct _kadm5_policy_ent_t *ent, long mask); + +/* Optional: authorize a modify-policy operation. */ +typedef krb5_error_code +(*kadm5_auth_modpol_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, const char *policy, + const struct _kadm5_policy_ent_t *ent, long mask); + +/* Optional: authorize a delete-policy operation. */ +typedef krb5_error_code +(*kadm5_auth_delpol_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, const char *policy); + +/* Optional: authorize a get-policy operation. client_policy is the client + * principal's policy name, or NULL if it does not have one. */ +typedef krb5_error_code +(*kadm5_auth_getpol_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client, const char *policy, + const char *client_policy); + +/* Optional: authorize a list-policies operation. */ +typedef krb5_error_code +(*kadm5_auth_listpols_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client); + +/* Optional: authorize an iprop operation. */ +typedef krb5_error_code +(*kadm5_auth_iprop_fn)(krb5_context context, kadm5_auth_moddata data, + krb5_const_principal client); + +/* + * Optional: receive a notification that the most recent authorized operation + * has ended. If a kadm5_auth module is also a KDB module, it can assume that + * all KDB methods invoked between a kadm5_auth authorization method invocation + * and a kadm5_auth end invocation are performed as part of the authorized + * operation. + * + * The end method may be invoked without a preceding authorization method in + * some cases; the module must be prepared to ignore such calls. + */ +typedef void +(*kadm5_auth_end_fn)(krb5_context context, kadm5_auth_moddata data); + +/* + * Optional: free a restrictions object. This method does not need to be + * defined if the module does not generate restrictions objects, or if it + * returns aliases to restrictions objects contained from within the module + * data. + */ +typedef void +(*kadm5_auth_free_restrictions_fn)(krb5_context context, + kadm5_auth_moddata data, + struct kadm5_auth_restrictions *rs); + +/* kadm5_auth vtable for major version 1. */ +typedef struct kadm5_auth_vtable_st { + const char *name; /* Mandatory: name of module. */ + kadm5_auth_init_fn init; + kadm5_auth_fini_fn fini; + + kadm5_auth_addprinc_fn addprinc; + kadm5_auth_modprinc_fn modprinc; + kadm5_auth_setstr_fn setstr; + kadm5_auth_cpw_fn cpw; + kadm5_auth_chrand_fn chrand; + kadm5_auth_setkey_fn setkey; + kadm5_auth_purgekeys_fn purgekeys; + kadm5_auth_delprinc_fn delprinc; + kadm5_auth_renprinc_fn renprinc; + + kadm5_auth_getprinc_fn getprinc; + kadm5_auth_getstrs_fn getstrs; + kadm5_auth_extract_fn extract; + kadm5_auth_listprincs_fn listprincs; + + kadm5_auth_addpol_fn addpol; + kadm5_auth_modpol_fn modpol; + kadm5_auth_delpol_fn delpol; + kadm5_auth_getpol_fn getpol; + kadm5_auth_listpols_fn listpols; + + kadm5_auth_iprop_fn iprop; + + kadm5_auth_end_fn end; + + kadm5_auth_free_restrictions_fn free_restrictions; + /* Minor version 1 ends here. */ +} *kadm5_auth_vtable; + +#endif /* KRB5_KADM5_AUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/kadm5_hook_plugin.h postgresql-hll-2.14/include/include/krb5/kadm5_hook_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/kadm5_hook_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/kadm5_hook_plugin.h 2020-12-12 17:06:43.218347664 +0800 @@ -0,0 +1,154 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2010 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef H_KRB5_KADM5_HOOK_PLUGIN +#define H_KRB5_KADM5_HOOK_PLUGIN + +/** + * @file krb5/krb5_kadm5_hook_plugin.h + * Provide a plugin interface for kadm5 operations. This interface + * permits a plugin to intercept principal modification, creation and + * change password operations. Operations run at two stages: a + * precommit stage that runs before the operation is committed to the + * database and a postcommit operation that runs after the database + * is updated; see #kadm5_hook_stage for details on semantics. + * + * This interface is based on a proposed extension to Heimdal by Russ + * Allbery; it is likely that Heimdal will adopt an approach based on + * stacked kdb modules rather than this interface. For MIT, writing a + * plugin to this interface is significantly easier than stacking kdb + * modules. Also, the kadm5 interface is significantly more stable + * than the kdb interface, so this approach is more desirable than + * stacked kdb modules. + * + * This interface depends on kadm5/admin.h. As such, the interface + * does not provide strong guarantees of ABI stability. + * + * The kadm5_hook interface currently has only one supported major version, + * which is 1. Major version 1 has a current minor version number of 2. + * + * kadm5_hook plugins should: + * kadm5_hook__initvt, matching the signature: + * + * krb5_error_code + * kadm5_hook_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to kadm5_hook_vftable_1 + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#include +#include +#include + +/** + * Whether the operation is being run before or after the database + * update. + */ +enum kadm5_hook_stage { + /** In this stage, any plugin failure prevents following plugins from + * running and aborts the operation.*/ + KADM5_HOOK_STAGE_PRECOMMIT, + /** In this stage, plugin failures are logged but otherwise ignored.*/ + KADM5_HOOK_STAGE_POSTCOMMIT +}; + +/** Opaque module data pointer. */ +typedef struct kadm5_hook_modinfo_st kadm5_hook_modinfo; + +/** + * Interface for the v1 virtual table for the kadm5_hook plugin. + * All entry points are optional. The name field must be provided. + */ +typedef struct kadm5_hook_vtable_1_st { + + /** A text string identifying the plugin for logging messages. */ + const char *name; + + /** Initialize a plugin module. + * @param modinfo returns newly allocated module info for future + * calls. Cleaned up by the fini() function. + */ + kadm5_ret_t (*init)(krb5_context, kadm5_hook_modinfo **modinfo); + + /** Clean up a module and free @a modinfo. */ + void (*fini)(krb5_context, kadm5_hook_modinfo *modinfo); + + /** Indicates that the password is being changed. + * @param stage is an integer from #kadm5_hook_stage enumeration + * @param keepold is true if existing keys are being kept. + * @param newpass is NULL if the key sare being randomized. + */ + kadm5_ret_t (*chpass)(krb5_context, + kadm5_hook_modinfo *modinfo, + int stage, + krb5_principal, krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + const char *newpass); + + /** Indicate a principal is created. */ + kadm5_ret_t (*create)(krb5_context, + kadm5_hook_modinfo *, + int stage, + kadm5_principal_ent_t, long mask, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + const char *password); + + /** Modify a principal. */ + kadm5_ret_t (*modify)(krb5_context, + kadm5_hook_modinfo *, + int stage, + kadm5_principal_ent_t, long mask); + + /** Indicate a principal is deleted. */ + kadm5_ret_t (*remove)(krb5_context, + kadm5_hook_modinfo *modinfo, + int stage, krb5_principal); + + /* End of minor version 1. */ + + /** Indicate a principal is renamed. */ + kadm5_ret_t (*rename)(krb5_context, + kadm5_hook_modinfo *modinfo, + int stage, krb5_principal, krb5_principal); + + /* End of minor version 2. */ + +} kadm5_hook_vftable_1; + +#endif /*H_KRB5_KADM5_HOOK_PLUGIN*/ diff -uprN postgresql-hll-2.14_old/include/include/krb5/kdcpolicy_plugin.h postgresql-hll-2.14/include/include/krb5/kdcpolicy_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/kdcpolicy_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/kdcpolicy_plugin.h 2020-12-12 17:06:43.218347664 +0800 @@ -0,0 +1,128 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* include/krb5/kdcpolicy_plugin.h - KDC policy plugin interface */ +/* + * Copyright (C) 2017 by Red Hat, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for kdcpolicy plugin module implementors. + * + * The kdcpolicy pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * kdcpolicy plugin modules should define a function named + * kdcpolicy__initvt, matching the signature: + * + * krb5_error_code + * kdcpolicy_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_kdcpolicy_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_POLICY_PLUGIN_H +#define KRB5_POLICY_PLUGIN_H + +#include + +/* Abstract module datatype. */ +typedef struct krb5_kdcpolicy_moddata_st *krb5_kdcpolicy_moddata; + +/* A module can optionally include kdb.h to inspect principal entries when + * authorizing requests. */ +struct _krb5_db_entry_new; + +/* + * Optional: Initialize module data. Return 0 on success, + * KRB5_PLUGIN_NO_HANDLE if the module is inoperable (due to configuration, for + * example), and any other error code to abort KDC startup. Optionally set + * *data_out to a module data object to be passed to future calls. + */ +typedef krb5_error_code +(*krb5_kdcpolicy_init_fn)(krb5_context context, + krb5_kdcpolicy_moddata *data_out); + +/* Optional: Clean up module data. */ +typedef krb5_error_code +(*krb5_kdcpolicy_fini_fn)(krb5_context context, + krb5_kdcpolicy_moddata moddata); + +/* + * Optional: return an error code and set status to an appropriate string + * literal to deny an AS request; otherwise return 0. lifetime_out, if set, + * restricts the ticket lifetime. renew_lifetime_out, if set, restricts the + * ticket renewable lifetime. + */ +typedef krb5_error_code +(*krb5_kdcpolicy_check_as_fn)(krb5_context context, + krb5_kdcpolicy_moddata moddata, + const krb5_kdc_req *request, + const struct _krb5_db_entry_new *client, + const struct _krb5_db_entry_new *server, + const char *const *auth_indicators, + const char **status, krb5_deltat *lifetime_out, + krb5_deltat *renew_lifetime_out); + +/* + * Optional: return an error code and set status to an appropriate string + * literal to deny a TGS request; otherwise return 0. lifetime_out, if set, + * restricts the ticket lifetime. renew_lifetime_out, if set, restricts the + * ticket renewable lifetime. + */ +typedef krb5_error_code +(*krb5_kdcpolicy_check_tgs_fn)(krb5_context context, + krb5_kdcpolicy_moddata moddata, + const krb5_kdc_req *request, + const struct _krb5_db_entry_new *server, + const krb5_ticket *ticket, + const char *const *auth_indicators, + const char **status, krb5_deltat *lifetime_out, + krb5_deltat *renew_lifetime_out); + +typedef struct krb5_kdcpolicy_vtable_st { + const char *name; + krb5_kdcpolicy_init_fn init; + krb5_kdcpolicy_fini_fn fini; + krb5_kdcpolicy_check_as_fn check_as; + krb5_kdcpolicy_check_tgs_fn check_tgs; +} *krb5_kdcpolicy_vtable; + +#endif /* KRB5_POLICY_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/kdcpreauth_plugin.h postgresql-hll-2.14/include/include/krb5/kdcpreauth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/kdcpreauth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/kdcpreauth_plugin.h 2020-12-12 17:06:43.218347664 +0800 @@ -0,0 +1,402 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (c) 2006 Red Hat, Inc. + * Portions copyright (c) 2006, 2011 Massachusetts Institute of Technology + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Red Hat, Inc., nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for kdcpreauth plugin module implementors. + * + * The kdcpreauth interface has a single supported major version, which is 1. + * Major version 1 has a current minor version of 2. kdcpreauth modules should + * define a function named kdcpreauth__initvt, matching the + * signature: + * + * krb5_error_code + * kdcpreauth_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for the interface and maj_ver: + * kdcpreauth, maj_ver == 1: Cast to krb5_kdcpreauth_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_KDCPREAUTH_PLUGIN_H +#define KRB5_KDCPREAUTH_PLUGIN_H + +#include +#include + +/* kdcpreauth mechanism property flags */ + +/* + * Causes the KDC to include this mechanism in a list of supported preauth + * types if the user's DB entry flags the user as requiring hardware-based + * preauthentication. + */ +#define PA_HARDWARE 0x00000004 + +/* + * Causes the KDC to include this mechanism in a list of supported preauth + * types if the user's DB entry flags the user as requiring preauthentication, + * and to fail preauthentication if we can't verify the client data. The + * flipside of PA_SUFFICIENT. + */ +#define PA_REQUIRED 0x00000008 + +/* + * Causes the KDC to include this mechanism in a list of supported preauth + * types if the user's DB entry flags the user as requiring preauthentication, + * and to mark preauthentication as successful if we can verify the client + * data. The flipside of PA_REQUIRED. + */ +#define PA_SUFFICIENT 0x00000010 + +/* + * Marks this preauthentication mechanism as one which changes the key which is + * used for encrypting the response to the client. Modules which have this + * flag have their server_return_fn called before modules which do not, and are + * passed over if a previously-called module has modified the encrypting key. + */ +#define PA_REPLACES_KEY 0x00000020 + +/* + * Not really a padata type, so don't include it in any list of preauth types + * which gets sent over the wire. + */ +#define PA_PSEUDO 0x00000080 + +/* + * Indicates that e_data in non-FAST errors should be encoded as typed data + * instead of padata. + */ +#define PA_TYPED_E_DATA 0x00000100 + +/* Abstract type for a KDC callback data handle. */ +typedef struct krb5_kdcpreauth_rock_st *krb5_kdcpreauth_rock; + +/* Abstract type for module data and per-request module data. */ +typedef struct krb5_kdcpreauth_moddata_st *krb5_kdcpreauth_moddata; +typedef struct krb5_kdcpreauth_modreq_st *krb5_kdcpreauth_modreq; + +/* The verto context structure type (typedef is in verto.h; we want to avoid a + * header dependency for the moment). */ +struct verto_ctx; + +/* Before using a callback after version 1, modules must check the vers + * field of the callback structure. */ +typedef struct krb5_kdcpreauth_callbacks_st { + int vers; + + krb5_deltat (*max_time_skew)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* + * Get an array of krb5_keyblock structures containing the client keys + * matching the request enctypes, terminated by an entry with key type = 0. + * Returns ENOENT if no keys are available for the request enctypes. Free + * the resulting object with the free_keys callback. + */ + krb5_error_code (*client_keys)(krb5_context context, + krb5_kdcpreauth_rock rock, + krb5_keyblock **keys_out); + + /* Free the result of client_keys. */ + void (*free_keys)(krb5_context context, krb5_kdcpreauth_rock rock, + krb5_keyblock *keys); + + /* + * Get the encoded request body, which is sometimes needed for checksums. + * For a FAST request this is the encoded inner request body. The returned + * pointer is an alias and should not be freed. + */ + krb5_data *(*request_body)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* Get a pointer to the FAST armor key, or NULL if the request did not use + * FAST. The returned pointer is an alias and should not be freed. */ + krb5_keyblock *(*fast_armor)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* Retrieve a string attribute from the client DB entry, or NULL if no such + * attribute is set. Free the result with the free_string callback. */ + krb5_error_code (*get_string)(krb5_context context, + krb5_kdcpreauth_rock rock, const char *key, + char **value_out); + + /* Free the result of get_string. */ + void (*free_string)(krb5_context context, krb5_kdcpreauth_rock rock, + char *string); + + /* Get a pointer to the client DB entry (returned as a void pointer to + * avoid a dependency on a libkdb5 type). */ + void *(*client_entry)(krb5_context context, krb5_kdcpreauth_rock rock); + + /* Get a pointer to the verto context which should be used by an + * asynchronous edata or verify method. */ + struct verto_ctx *(*event_context)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* End of version 1 kdcpreauth callbacks. */ + + /* Return true if the client DB entry contains any keys matching the + * request enctypes. */ + krb5_boolean (*have_client_keys)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* End of version 2 kdcpreauth callbacks. */ + + /* + * Get the decrypted client long-term key chosen according to the request + * enctype list, or NULL if no matching key was found. The returned + * pointer is an alias and should not be freed. If invoked from + * return_padata, the result will be the same as the encrypting_key + * parameter if it is not NULL, and will therefore reflect the modified + * reply key if a return_padata handler has replaced the reply key. + */ + const krb5_keyblock *(*client_keyblock)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* Assert an authentication indicator in the AS-REP authdata. Duplicate + * indicators will be ignored. */ + krb5_error_code (*add_auth_indicator)(krb5_context context, + krb5_kdcpreauth_rock rock, + const char *indicator); + + /* + * Read a data value for pa_type from the request cookie, placing it in + * *out. The value placed there is an alias and must not be freed. + * Returns true if a value for pa_type was retrieved, false if not. + */ + krb5_boolean (*get_cookie)(krb5_context context, krb5_kdcpreauth_rock rock, + krb5_preauthtype pa_type, krb5_data *out); + + /* + * Set a data value for pa_type to be sent in a secure cookie in the next + * error response. If pa_type is already present, the value is ignored. + * If the preauth mechanism has different preauth types for requests and + * responses, use the request type. Secure cookies are encrypted in a key + * known only to the KDCs, but can be replayed within a short time window + * for requests using the same client principal. + */ + krb5_error_code (*set_cookie)(krb5_context context, + krb5_kdcpreauth_rock rock, + krb5_preauthtype pa_type, + const krb5_data *data); + + /* End of version 3 kdcpreauth callbacks. */ + + /* + * Return true if princ matches the principal named in the request or the + * client principal (possibly canonicalized). If princ does not match, + * attempt a database lookup of princ with aliases allowed and compare the + * result to the client principal, returning true if it matches. + * Otherwise, return false. + */ + krb5_boolean (*match_client)(krb5_context context, + krb5_kdcpreauth_rock rock, + krb5_principal princ); + + /* + * Get an alias to the client DB entry principal (possibly canonicalized). + */ + krb5_principal (*client_name)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* End of version 4 kdcpreauth callbacks. */ + + /* + * Instruct the KDC to send a freshness token in the method data + * accompanying a PREAUTH_REQUIRED or PREAUTH_FAILED error, if the client + * indicated support for freshness tokens. This callback should only be + * invoked from the edata method. + */ + void (*send_freshness_token)(krb5_context context, + krb5_kdcpreauth_rock rock); + + /* Validate a freshness token sent by the client. Return 0 on success, + * KRB5KDC_ERR_PREAUTH_EXPIRED on error. */ + krb5_error_code (*check_freshness_token)(krb5_context context, + krb5_kdcpreauth_rock rock, + const krb5_data *token); + + /* End of version 5 kdcpreauth callbacks. */ + +} *krb5_kdcpreauth_callbacks; + +/* Optional: preauth plugin initialization function. */ +typedef krb5_error_code +(*krb5_kdcpreauth_init_fn)(krb5_context context, + krb5_kdcpreauth_moddata *moddata_out, + const char **realmnames); + +/* Optional: preauth plugin cleanup function. */ +typedef void +(*krb5_kdcpreauth_fini_fn)(krb5_context context, + krb5_kdcpreauth_moddata moddata); + +/* + * Optional: return the flags which the KDC should use for this module. This + * is a callback instead of a static value because the module may or may not + * wish to count itself as a hardware preauthentication module (in other words, + * the flags may be affected by the configuration, for example if a site + * administrator can force a particular preauthentication type to be supported + * using only hardware). This function is called for each entry entry in the + * server_pa_type_list. + */ +typedef int +(*krb5_kdcpreauth_flags_fn)(krb5_context context, krb5_preauthtype pa_type); + +/* + * Responder for krb5_kdcpreauth_edata_fn. If invoked with a non-zero code, pa + * will be ignored and the padata type will not be included in the hint list. + * If invoked with a zero code and a null pa value, the padata type will be + * included in the list with an empty value. If invoked with a zero code and a + * non-null pa value, pa will be included in the hint list and will later be + * freed by the KDC. + */ +typedef void +(*krb5_kdcpreauth_edata_respond_fn)(void *arg, krb5_error_code code, + krb5_pa_data *pa); + +/* + * Optional: provide pa_data to send to the client as part of the "you need to + * use preauthentication" error. The implementation must invoke the respond + * when complete, whether successful or not, either before returning or + * asynchronously using the verto context returned by cb->event_context(). + * + * This function is not allowed to create a modreq object because we have no + * guarantee that the client will ever make a follow-up request, or that it + * will hit this KDC if it does. + */ +typedef void +(*krb5_kdcpreauth_edata_fn)(krb5_context context, krb5_kdc_req *request, + krb5_kdcpreauth_callbacks cb, + krb5_kdcpreauth_rock rock, + krb5_kdcpreauth_moddata moddata, + krb5_preauthtype pa_type, + krb5_kdcpreauth_edata_respond_fn respond, + void *arg); + +/* + * Responder for krb5_kdcpreauth_verify_fn. Invoke with the arg parameter + * supplied to verify, the error code (0 for success), an optional module + * request state object to be consumed by return_fn or free_modreq_fn, optional + * e_data to be passed to the caller if code is nonzero, and optional + * authorization data to be included in the ticket. In non-FAST replies, + * e_data will be encoded as typed-data if the module sets the PA_TYPED_E_DATA + * flag, and as pa-data otherwise. e_data and authz_data will be freed by the + * KDC. + */ +typedef void +(*krb5_kdcpreauth_verify_respond_fn)(void *arg, krb5_error_code code, + krb5_kdcpreauth_modreq modreq, + krb5_pa_data **e_data, + krb5_authdata **authz_data); + +/* + * Optional: verify preauthentication data sent by the client, setting the + * TKT_FLG_PRE_AUTH or TKT_FLG_HW_AUTH flag in the enc_tkt_reply's "flags" + * field as appropriate. The implementation must invoke the respond function + * when complete, whether successful or not, either before returning or + * asynchronously using the verto context returned by cb->event_context(). + */ +typedef void +(*krb5_kdcpreauth_verify_fn)(krb5_context context, + krb5_data *req_pkt, krb5_kdc_req *request, + krb5_enc_tkt_part *enc_tkt_reply, + krb5_pa_data *data, + krb5_kdcpreauth_callbacks cb, + krb5_kdcpreauth_rock rock, + krb5_kdcpreauth_moddata moddata, + krb5_kdcpreauth_verify_respond_fn respond, + void *arg); + +/* + * Optional: generate preauthentication response data to send to the client as + * part of the AS-REP. If it needs to override the key which is used to + * encrypt the response, it can do so. + */ +typedef krb5_error_code +(*krb5_kdcpreauth_return_fn)(krb5_context context, + krb5_pa_data *padata, + krb5_data *req_pkt, + krb5_kdc_req *request, + krb5_kdc_rep *reply, + krb5_keyblock *encrypting_key, + krb5_pa_data **send_pa_out, + krb5_kdcpreauth_callbacks cb, + krb5_kdcpreauth_rock rock, + krb5_kdcpreauth_moddata moddata, + krb5_kdcpreauth_modreq modreq); + +/* Optional: free a per-request context. */ +typedef void +(*krb5_kdcpreauth_free_modreq_fn)(krb5_context, + krb5_kdcpreauth_moddata moddata, + krb5_kdcpreauth_modreq modreq); + +/* Optional: invoked after init_fn to provide the module with a pointer to the + * verto main loop. */ +typedef krb5_error_code +(*krb5_kdcpreauth_loop_fn)(krb5_context context, + krb5_kdcpreauth_moddata moddata, + struct verto_ctx *ctx); + +typedef struct krb5_kdcpreauth_vtable_st { + /* Mandatory: name of module. */ + char *name; + + /* Mandatory: pointer to zero-terminated list of pa_types which this module + * can provide services for. */ + krb5_preauthtype *pa_type_list; + + krb5_kdcpreauth_init_fn init; + krb5_kdcpreauth_fini_fn fini; + krb5_kdcpreauth_flags_fn flags; + krb5_kdcpreauth_edata_fn edata; + krb5_kdcpreauth_verify_fn verify; + krb5_kdcpreauth_return_fn return_padata; + krb5_kdcpreauth_free_modreq_fn free_modreq; + /* Minor 1 ends here. */ + + krb5_kdcpreauth_loop_fn loop; + /* Minor 2 ends here. */ +} *krb5_kdcpreauth_vtable; + +#endif /* KRB5_KDCPREAUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/krb5.h postgresql-hll-2.14/include/include/krb5/krb5.h --- postgresql-hll-2.14_old/include/include/krb5/krb5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/krb5.h 2020-12-12 17:06:43.221347703 +0800 @@ -0,0 +1,9127 @@ +/* This file is generated, please don't edit it directly. */ +#ifndef KRB5_KRB5_H_INCLUDED +#define KRB5_KRB5_H_INCLUDED +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* General definitions for Kerberos version 5. */ +/* + * Copyright 1989, 1990, 1995, 2001, 2003, 2007, 2011 by the Massachusetts + * Institute of Technology. All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ +/* + * Copyright (C) 1998 by the FundsXpress, INC. + * + * All rights reserved. + * + * Export of this software from the United States of America may require + * a specific license from the United States Government. It is the + * responsibility of any person or organization contemplating export to + * obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of FundsXpress. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. FundsXpress makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef KRB5_GENERAL__ +#define KRB5_GENERAL__ + +/** @defgroup KRB5_H krb5 library API + * @{ + */ + + /* By default, do not expose deprecated interfaces. */ +#ifndef KRB5_DEPRECATED +#define KRB5_DEPRECATED 0 +#endif + +#if defined(__MACH__) && defined(__APPLE__) +# include +# if TARGET_RT_MAC_CFM +# error "Use KfM 4.0 SDK headers for CFM compilation." +# endif +#endif + +#if defined(_MSDOS) || defined(_WIN32) +#include +#endif + +#ifndef KRB5_CONFIG__ +#ifndef KRB5_CALLCONV +#define KRB5_CALLCONV +#define KRB5_CALLCONV_C +#endif /* !KRB5_CALLCONV */ +#endif /* !KRB5_CONFIG__ */ + +#ifndef KRB5_CALLCONV_WRONG +#define KRB5_CALLCONV_WRONG +#endif + +#ifndef THREEPARAMOPEN +#define THREEPARAMOPEN(x,y,z) open(x,y,z) +#endif + +#define KRB5_OLD_CRYPTO + +#include +#include /* for *_MAX */ +#include +#include + +#ifndef KRB5INT_BEGIN_DECLS +#if defined(__cplusplus) +#define KRB5INT_BEGIN_DECLS extern "C" { +#define KRB5INT_END_DECLS } +#else +#define KRB5INT_BEGIN_DECLS +#define KRB5INT_END_DECLS +#endif +#endif + +KRB5INT_BEGIN_DECLS + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(push,2) +#endif + +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 30203 +# define KRB5_ATTR_DEPRECATED __attribute__((deprecated)) +#elif defined _WIN32 +# define KRB5_ATTR_DEPRECATED __declspec(deprecated) +#else +# define KRB5_ATTR_DEPRECATED +#endif + +/* from profile.h */ +struct _profile_t; +/* typedef struct _profile_t *profile_t; */ + +/* + * begin wordsize.h + */ + +/* + * Word-size related definition. + */ + +typedef uint8_t krb5_octet; +typedef int16_t krb5_int16; +typedef uint16_t krb5_ui_2; +typedef int32_t krb5_int32; +typedef uint32_t krb5_ui_4; + +#define VALID_INT_BITS INT_MAX +#define VALID_UINT_BITS UINT_MAX + +#define KRB5_INT32_MAX 2147483647 +/* this strange form is necessary since - is a unary operator, not a sign + indicator */ +#define KRB5_INT32_MIN (-KRB5_INT32_MAX-1) + +#define KRB5_INT16_MAX 65535 +/* this strange form is necessary since - is a unary operator, not a sign + indicator */ +#define KRB5_INT16_MIN (-KRB5_INT16_MAX-1) + +/* + * end wordsize.h + */ + +/* + * begin "base-defs.h" + */ + +/* + * Basic definitions for Kerberos V5 library + */ + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +typedef unsigned int krb5_boolean; +typedef unsigned int krb5_msgtype; +typedef unsigned int krb5_kvno; + +typedef krb5_int32 krb5_addrtype; +typedef krb5_int32 krb5_enctype; +typedef krb5_int32 krb5_cksumtype; +typedef krb5_int32 krb5_authdatatype; +typedef krb5_int32 krb5_keyusage; +typedef krb5_int32 krb5_cryptotype; + +typedef krb5_int32 krb5_preauthtype; /* This may change, later on */ +typedef krb5_int32 krb5_flags; + +/** + * Represents a timestamp in seconds since the POSIX epoch. This legacy type + * is used frequently in the ABI, but cannot represent timestamps after 2038 as + * a positive number. Code which uses this type should cast values of it to + * uint32_t so that negative values are treated as timestamps between 2038 and + * 2106 on platforms with 64-bit time_t. + */ +typedef krb5_int32 krb5_timestamp; + +typedef krb5_int32 krb5_deltat; + +/** + * Used to convey an operation status. The value 0 indicates success; any + * other values are com_err codes. Use krb5_get_error_message() to obtain a + * string describing the error. + */ +typedef krb5_int32 krb5_error_code; + +typedef krb5_error_code krb5_magic; + +typedef struct _krb5_data { + krb5_magic magic; + unsigned int length; + char *data; +} krb5_data; + +/* Originally introduced for PKINIT; now unused. Do not use this. */ +typedef struct _krb5_octet_data { + krb5_magic magic; + unsigned int length; + krb5_octet *data; +} krb5_octet_data; + +/* Originally used to recognize AFS and default salts. No longer used. */ +#define SALT_TYPE_AFS_LENGTH UINT_MAX +#define SALT_TYPE_NO_LENGTH UINT_MAX + +typedef void * krb5_pointer; +typedef void const * krb5_const_pointer; + +typedef struct krb5_principal_data { + krb5_magic magic; + krb5_data realm; + krb5_data *data; /**< An array of strings */ + krb5_int32 length; + krb5_int32 type; +} krb5_principal_data; + +typedef krb5_principal_data * krb5_principal; + +/* + * Per V5 spec on definition of principal types + */ + +#define KRB5_NT_UNKNOWN 0 /**< Name type not known */ +#define KRB5_NT_PRINCIPAL 1 /**< Just the name of the principal + as in DCE, or for users */ +#define KRB5_NT_SRV_INST 2 /**< Service and other unique instance (krbtgt) */ +#define KRB5_NT_SRV_HST 3 /**< Service with host name as instance + (telnet, rcommands) */ +#define KRB5_NT_SRV_XHST 4 /**< Service with host as remaining components */ +#define KRB5_NT_UID 5 /**< Unique ID */ +#define KRB5_NT_X500_PRINCIPAL 6 /**< PKINIT */ +#define KRB5_NT_SMTP_NAME 7 /**< Name in form of SMTP email name */ +#define KRB5_NT_ENTERPRISE_PRINCIPAL 10 /**< Windows 2000 UPN */ +#define KRB5_NT_WELLKNOWN 11 /**< Well-known (special) principal */ +#define KRB5_WELLKNOWN_NAMESTR "WELLKNOWN" /**< First component of + NT_WELLKNOWN principals */ +#define KRB5_NT_MS_PRINCIPAL -128 /**< Windows 2000 UPN and SID */ +#define KRB5_NT_MS_PRINCIPAL_AND_ID -129 /**< NT 4 style name */ +#define KRB5_NT_ENT_PRINCIPAL_AND_ID -130 /**< NT 4 style name and SID */ + +/** Constant version of krb5_principal_data */ +typedef const krb5_principal_data *krb5_const_principal; + +#define krb5_princ_realm(context, princ) (&(princ)->realm) +#define krb5_princ_set_realm(context, princ,value) ((princ)->realm = *(value)) +#define krb5_princ_set_realm_length(context, princ,value) (princ)->realm.length = (value) +#define krb5_princ_set_realm_data(context, princ,value) (princ)->realm.data = (value) +#define krb5_princ_size(context, princ) (princ)->length +#define krb5_princ_type(context, princ) (princ)->type +#define krb5_princ_name(context, princ) (princ)->data +#define krb5_princ_component(context, princ,i) \ + (((i) < krb5_princ_size(context, princ)) \ + ? (princ)->data + (i) \ + : NULL) + +/** Constant for realm referrals. */ +#define KRB5_REFERRAL_REALM "" + +/* + * Referral-specific functions. + */ + +/** + * Check for a match with KRB5_REFERRAL_REALM. + * + * @param [in] r Realm to check + * + * @return @c TRUE if @a r is zero-length, @c FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_is_referral_realm(const krb5_data *r); + +/** + * Return an anonymous realm data. + * + * This function returns constant storage that must not be freed. + * + * @sa #KRB5_ANONYMOUS_REALMSTR + */ +const krb5_data *KRB5_CALLCONV +krb5_anonymous_realm(void); + +/** + * Build an anonymous principal. + * + * This function returns constant storage that must not be freed. + * + * @sa #KRB5_ANONYMOUS_PRINCSTR + */ +krb5_const_principal KRB5_CALLCONV +krb5_anonymous_principal(void); + +#define KRB5_ANONYMOUS_REALMSTR "WELLKNOWN:ANONYMOUS" /**< Anonymous realm */ +#define KRB5_ANONYMOUS_PRINCSTR "ANONYMOUS" /**< Anonymous principal name */ +/* + * end "base-defs.h" + */ + +/* + * begin "hostaddr.h" + */ + +/** Structure for address */ +typedef struct _krb5_address { + krb5_magic magic; + krb5_addrtype addrtype; + unsigned int length; + krb5_octet *contents; +} krb5_address; + +/* per Kerberos v5 protocol spec */ +#define ADDRTYPE_INET 0x0002 +#define ADDRTYPE_CHAOS 0x0005 +#define ADDRTYPE_XNS 0x0006 +#define ADDRTYPE_ISO 0x0007 +#define ADDRTYPE_DDP 0x0010 +#define ADDRTYPE_NETBIOS 0x0014 +#define ADDRTYPE_INET6 0x0018 +/* not yet in the spec... */ +#define ADDRTYPE_ADDRPORT 0x0100 +#define ADDRTYPE_IPPORT 0x0101 + +/* macros to determine if a type is a local type */ +#define ADDRTYPE_IS_LOCAL(addrtype) (addrtype & 0x8000) + +/* + * end "hostaddr.h" + */ + + +struct _krb5_context; +typedef struct _krb5_context * krb5_context; + +struct _krb5_auth_context; +typedef struct _krb5_auth_context * krb5_auth_context; + +struct _krb5_cryptosystem_entry; + +/* + * begin "encryption.h" + */ + +/** Exposed contents of a key. */ +typedef struct _krb5_keyblock { + krb5_magic magic; + krb5_enctype enctype; + unsigned int length; + krb5_octet *contents; +} krb5_keyblock; + +struct krb5_key_st; +/** + * Opaque identifier for a key. + * + * Use with the krb5_k APIs for better performance for repeated operations with + * the same key and usage. Key identifiers must not be used simultaneously + * within multiple threads, as they may contain mutable internal state and are + * not mutex-protected. + */ +typedef struct krb5_key_st *krb5_key; + +#ifdef KRB5_OLD_CRYPTO +typedef struct _krb5_encrypt_block { + krb5_magic magic; + krb5_enctype crypto_entry; /* to call krb5_encrypt_size, you need + this. it was a pointer, but it + doesn't have to be. gross. */ + krb5_keyblock *key; +} krb5_encrypt_block; +#endif + +typedef struct _krb5_checksum { + krb5_magic magic; + krb5_cksumtype checksum_type; /* checksum type */ + unsigned int length; + krb5_octet *contents; +} krb5_checksum; + +typedef struct _krb5_enc_data { + krb5_magic magic; + krb5_enctype enctype; + krb5_kvno kvno; + krb5_data ciphertext; +} krb5_enc_data; + +/** + * Structure to describe a region of text to be encrypted or decrypted. + * + * The @a flags member describes the type of the iov. + * The @a data member points to the memory that will be manipulated. + * All iov APIs take a pointer to the first element of an array of krb5_crypto_iov's + * along with the size of that array. Buffer contents are manipulated in-place; + * data is overwritten. Callers must allocate the right number of krb5_crypto_iov + * structures before calling into an iov API. + */ +typedef struct _krb5_crypto_iov { + krb5_cryptotype flags; /**< @ref KRB5_CRYPTO_TYPE type of the iov */ + krb5_data data; +} krb5_crypto_iov; + +/* per Kerberos v5 protocol spec */ +#define ENCTYPE_NULL 0x0000 +#define ENCTYPE_DES_CBC_CRC 0x0001 /**< DES cbc mode with CRC-32 */ +#define ENCTYPE_DES_CBC_MD4 0x0002 /**< DES cbc mode with RSA-MD4 */ +#define ENCTYPE_DES_CBC_MD5 0x0003 /**< DES cbc mode with RSA-MD5 */ +#define ENCTYPE_DES_CBC_RAW 0x0004 /**< @deprecated DES cbc mode raw */ +#define ENCTYPE_DES3_CBC_SHA 0x0005 /**< @deprecated DES-3 cbc with SHA1 */ +#define ENCTYPE_DES3_CBC_RAW 0x0006 /**< @deprecated DES-3 cbc mode raw */ +#define ENCTYPE_DES_HMAC_SHA1 0x0008 /**< @deprecated */ +/* PKINIT */ +#define ENCTYPE_DSA_SHA1_CMS 0x0009 /**< DSA with SHA1, CMS signature */ +#define ENCTYPE_MD5_RSA_CMS 0x000a /**< MD5 with RSA, CMS signature */ +#define ENCTYPE_SHA1_RSA_CMS 0x000b /**< SHA1 with RSA, CMS signature */ +#define ENCTYPE_RC2_CBC_ENV 0x000c /**< RC2 cbc mode, CMS enveloped data */ +#define ENCTYPE_RSA_ENV 0x000d /**< RSA encryption, CMS enveloped data */ +#define ENCTYPE_RSA_ES_OAEP_ENV 0x000e /**< RSA w/OEAP encryption, CMS enveloped data */ +#define ENCTYPE_DES3_CBC_ENV 0x000f /**< DES-3 cbc mode, CMS enveloped data */ + +#define ENCTYPE_DES3_CBC_SHA1 0x0010 +#define ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011 /**< RFC 3962 */ +#define ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012 /**< RFC 3962 */ +#define ENCTYPE_AES128_CTS_HMAC_SHA256_128 0x0013 /**< RFC 8009 */ +#define ENCTYPE_AES256_CTS_HMAC_SHA384_192 0x0014 /**< RFC 8009 */ +#define ENCTYPE_ARCFOUR_HMAC 0x0017 /**< RFC 4757 */ +#define ENCTYPE_ARCFOUR_HMAC_EXP 0x0018 /**< RFC 4757 */ +#define ENCTYPE_CAMELLIA128_CTS_CMAC 0x0019 /**< RFC 6803 */ +#define ENCTYPE_CAMELLIA256_CTS_CMAC 0x001a /**< RFC 6803 */ +#define ENCTYPE_UNKNOWN 0x01ff + +#define CKSUMTYPE_CRC32 0x0001 +#define CKSUMTYPE_RSA_MD4 0x0002 +#define CKSUMTYPE_RSA_MD4_DES 0x0003 +#define CKSUMTYPE_DESCBC 0x0004 +/* des-mac-k */ +/* rsa-md4-des-k */ +#define CKSUMTYPE_RSA_MD5 0x0007 +#define CKSUMTYPE_RSA_MD5_DES 0x0008 +#define CKSUMTYPE_NIST_SHA 0x0009 +#define CKSUMTYPE_HMAC_SHA1_DES3 0x000c +#define CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f /**< RFC 3962. Used with + ENCTYPE_AES128_CTS_HMAC_SHA1_96 */ +#define CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 /**< RFC 3962. Used with + ENCTYPE_AES256_CTS_HMAC_SHA1_96 */ +#define CKSUMTYPE_HMAC_SHA256_128_AES128 0x0013 /**< RFC 8009 */ +#define CKSUMTYPE_HMAC_SHA384_192_AES256 0x0014 /**< RFC 8009 */ +#define CKSUMTYPE_CMAC_CAMELLIA128 0x0011 /**< RFC 6803 */ +#define CKSUMTYPE_CMAC_CAMELLIA256 0x0012 /**< RFC 6803 */ +#define CKSUMTYPE_MD5_HMAC_ARCFOUR -137 /* Microsoft netlogon */ +#define CKSUMTYPE_HMAC_MD5_ARCFOUR -138 /**< RFC 4757 */ + +/* + * The following are entropy source designations. Whenever + * krb5_C_random_add_entropy is called, one of these source ids is passed in. + * This allows the library to better estimate bits of entropy in the sample and + * to keep track of what sources of entropy have contributed enough entropy. + * Sources marked internal MUST NOT be used by applications outside the + * Kerberos library + */ + +enum { + KRB5_C_RANDSOURCE_OLDAPI = 0, /*calls to krb5_C_RANDOM_SEED (INTERNAL)*/ + KRB5_C_RANDSOURCE_OSRAND = 1, /* /dev/random or equivalent (internal)*/ + KRB5_C_RANDSOURCE_TRUSTEDPARTY = 2, /* From KDC or other trusted party*/ + /* + * This source should be used carefully; data in this category + * should be from a third party trusted to give random bits + * For example keys issued by the KDC in the application server. + */ + KRB5_C_RANDSOURCE_TIMING = 3, /* Timing of operations*/ + KRB5_C_RANDSOURCE_EXTERNAL_PROTOCOL = 4, /*Protocol data possibly from attacker*/ + KRB5_C_RANDSOURCE_MAX = 5 /*Do not use; maximum source ID*/ +}; + +#ifndef krb5_roundup +/* round x up to nearest multiple of y */ +#define krb5_roundup(x, y) ((((x) + (y) - 1)/(y))*(y)) +#endif /* roundup */ + +/* macro function definitions to help clean up code */ + +#if 1 +#define krb5_x(ptr,args) ((ptr)?((*(ptr)) args):(abort(),1)) +#define krb5_xc(ptr,args) ((ptr)?((*(ptr)) args):(abort(),(char*)0)) +#else +#define krb5_x(ptr,args) ((*(ptr)) args) +#define krb5_xc(ptr,args) ((*(ptr)) args) +#endif + +/** + * Encrypt data using a key (operates on keyblock). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] cipher_state Cipher state; specify NULL if not needed + * @param [in] input Data to be encrypted + * @param [out] output Encrypted data + * + * This function encrypts the data block @a input and stores the output into @a + * output. The actual encryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the encryption operation, and + * is updated with the state to be passed as input to the next operation. + * + * @note The caller must initialize @a output and allocate at least enough + * space for the result (using krb5_c_encrypt_length() to determine the amount + * of space needed). @a output->length will be set to the actual length of the + * ciphertext. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_encrypt(krb5_context context, const krb5_keyblock *key, + krb5_keyusage usage, const krb5_data *cipher_state, + const krb5_data *input, krb5_enc_data *output); + +/** + * Decrypt data using a key (operates on keyblock). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] cipher_state Cipher state; specify NULL if not needed + * @param [in] input Encrypted data + * @param [out] output Decrypted data + * + * This function decrypts the data block @a input and stores the output into @a + * output. The actual decryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the decryption operation, and + * is updated with the state to be passed as input to the next operation. + * + * @note The caller must initialize @a output and allocate at least enough + * space for the result. The usual practice is to allocate an output buffer as + * long as the ciphertext, and let krb5_c_decrypt() trim @a output->length. + * For some enctypes, the resulting @a output->length may include padding + * bytes. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_decrypt(krb5_context context, const krb5_keyblock *key, + krb5_keyusage usage, const krb5_data *cipher_state, + const krb5_enc_data *input, krb5_data *output); + +/** + * Compute encrypted data length. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] inputlen Length of the data to be encrypted + * @param [out] length Length of the encrypted data + * + * This function computes the length of the ciphertext produced by encrypting + * @a inputlen bytes including padding, confounder, and checksum. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_encrypt_length(krb5_context context, krb5_enctype enctype, + size_t inputlen, size_t *length); + +/** + * Return cipher block size. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [out] blocksize Block size for @a enctype + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_block_size(krb5_context context, krb5_enctype enctype, + size_t *blocksize); + +/** + * Return length of the specified key in bytes. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [out] keybytes Number of bytes required to make a key + * @param [out] keylength Length of final key + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_keylengths(krb5_context context, krb5_enctype enctype, + size_t *keybytes, size_t *keylength); + +/** + * Initialize a new cipher state. + * + * @param [in] context Library context + * @param [in] key Key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [out] new_state New cipher state + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_init_state(krb5_context context, const krb5_keyblock *key, + krb5_keyusage usage, krb5_data *new_state); + +/** + * Free a cipher state previously allocated by krb5_c_init_state(). + * + * @param [in] context Library context + * @param [in] key Key + * @param [in] state Cipher state to be freed + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_free_state(krb5_context context, const krb5_keyblock *key, + krb5_data *state); + +/** + * Generate enctype-specific pseudo-random bytes. + * + * @param [in] context Library context + * @param [in] keyblock Key + * @param [in] input Input data + * @param [out] output Output data + * + * This function selects a pseudo-random function based on @a keyblock and + * computes its value over @a input, placing the result into @a output. + * The caller must preinitialize @a output and allocate space for the + * result, using krb5_c_prf_length() to determine the required length. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_prf(krb5_context context, const krb5_keyblock *keyblock, + krb5_data *input, krb5_data *output); + +/** + * Get the output length of pseudo-random functions for an encryption type. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [out] len Length of PRF output + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_prf_length(krb5_context context, krb5_enctype enctype, size_t *len); + +/** + * Generate pseudo-random bytes using RFC 6113 PRF+. + * + * @param [in] context Library context + * @param [in] k KDC contribution key + * @param [in] input Input data + * @param [out] output Pseudo-random output buffer + * + * This function fills @a output with PRF+(k, input) as defined in RFC 6113 + * section 5.1. The caller must preinitialize @a output and allocate the + * desired amount of space. The length of the pseudo-random output will match + * the length of @a output. + * + * @note RFC 4402 defines a different PRF+ operation. This function does not + * implement that operation. + * + * @return 0 on success, @c E2BIG if output->length is too large for PRF+ to + * generate, @c ENOMEM on allocation failure, or an error code from + * krb5_c_prf() + */ +krb5_error_code KRB5_CALLCONV +krb5_c_prfplus(krb5_context context, const krb5_keyblock *k, + const krb5_data *input, krb5_data *output); + +/** + * Derive a key using some input data (via RFC 6113 PRF+). + * + * @param [in] context Library context + * @param [in] k KDC contribution key + * @param [in] input Input string + * @param [in] enctype Output key enctype (or @c ENCTYPE_NULL) + * @param [out] out Derived keyblock + * + * This function uses PRF+ as defined in RFC 6113 to derive a key from another + * key and an input string. If @a enctype is @c ENCTYPE_NULL, the output key + * will have the same enctype as the input key. + */ +krb5_error_code KRB5_CALLCONV +krb5_c_derive_prfplus(krb5_context context, const krb5_keyblock *k, + const krb5_data *input, krb5_enctype enctype, + krb5_keyblock **out); + +/** + * Compute the KRB-FX-CF2 combination of two keys and pepper strings. + * + * @param [in] context Library context + * @param [in] k1 KDC contribution key + * @param [in] pepper1 String "PKINIT" + * @param [in] k2 Reply key + * @param [in] pepper2 String "KeyExchange" + * @param [out] out Output key + * + * This function computes the KRB-FX-CF2 function over its inputs and places + * the results in a newly allocated keyblock. This function is simple in that + * it assumes that @a pepper1 and @a pepper2 are C strings with no internal + * nulls and that the enctype of the result will be the same as that of @a k1. + * @a k1 and @a k2 may be of different enctypes. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_fx_cf2_simple(krb5_context context, + const krb5_keyblock *k1, const char *pepper1, + const krb5_keyblock *k2, const char *pepper2, + krb5_keyblock **out); + +/** + * Generate an enctype-specific random encryption key. + * + * @param [in] context Library context + * @param [in] enctype Encryption type of the generated key + * @param [out] k5_random_key An allocated and initialized keyblock + * + * Use krb5_free_keyblock_contents() to free @a k5_random_key when + * no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_make_random_key(krb5_context context, krb5_enctype enctype, + krb5_keyblock *k5_random_key); + +/** + * Generate an enctype-specific key from random data. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] random_data Random input data + * @param [out] k5_random_key Resulting key + * + * This function takes random input data @a random_data and produces a valid + * key @a k5_random_key for a given @a enctype. + * + * @note It is assumed that @a k5_random_key has already been initialized and + * @a k5_random_key->contents has been allocated with the correct length. + * + * @sa krb5_c_keylengths() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_random_to_key(krb5_context context, krb5_enctype enctype, + krb5_data *random_data, krb5_keyblock *k5_random_key); + +/** + * Add entropy to the pseudo-random number generator. + * + * @param [in] context Library context + * @param [in] randsource Entropy source (see KRB5_RANDSOURCE types) + * @param [in] data Data + * + * Contribute entropy to the PRNG used by krb5 crypto operations. This may or + * may not affect the output of the next crypto operation requiring random + * data. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_random_add_entropy(krb5_context context, unsigned int randsource, + const krb5_data *data); + +/** + * Generate pseudo-random bytes. + * + * @param [in] context Library context + * @param [out] data Random data + * + * Fills in @a data with bytes from the PRNG used by krb5 crypto operations. + * The caller must preinitialize @a data and allocate the desired amount of + * space. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_random_make_octets(krb5_context context, krb5_data *data); + +/** + * Collect entropy from the OS if possible. + * + * @param [in] context Library context + * @param [in] strong Strongest available source of entropy + * @param [out] success 1 if OS provides entropy, 0 otherwise + * + * If @a strong is non-zero, this function attempts to use the strongest + * available source of entropy. Setting this flag may cause the function to + * block on some operating systems. Good uses include seeding the PRNG for + * kadmind and realm setup. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_random_os_entropy(krb5_context context, int strong, int *success); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_c_random_seed(krb5_context context, krb5_data *data); + +/** + * Convert a string (such a password) to a key. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] string String to be converted + * @param [in] salt Salt value + * @param [out] key Generated key + * + * This function converts @a string to a @a key of encryption type @a enctype, + * using the specified @a salt. The newly created @a key must be released by + * calling krb5_free_keyblock_contents() when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_string_to_key(krb5_context context, krb5_enctype enctype, + const krb5_data *string, const krb5_data *salt, + krb5_keyblock *key); + +/** + * Convert a string (such as a password) to a key with additional parameters. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] string String to be converted + * @param [in] salt Salt value + * @param [in] params Parameters + * @param [out] key Generated key + * + * This function is similar to krb5_c_string_to_key(), but also takes + * parameters which may affect the algorithm in an enctype-dependent way. The + * newly created @a key must be released by calling + * krb5_free_keyblock_contents() when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_string_to_key_with_params(krb5_context context, + krb5_enctype enctype, + const krb5_data *string, + const krb5_data *salt, + const krb5_data *params, + krb5_keyblock *key); + +/** + * Compare two encryption types. + * + * @param [in] context Library context + * @param [in] e1 First encryption type + * @param [in] e2 Second encryption type + * @param [out] similar @c TRUE if types are similar, @c FALSE if not + * + * This function determines whether two encryption types use the same kind of + * keys. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_enctype_compare(krb5_context context, krb5_enctype e1, krb5_enctype e2, + krb5_boolean *similar); + +/** + * Compute a checksum (operates on keyblock). + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] input Input data + * @param [out] cksum Generated checksum + * + * This function computes a checksum of type @a cksumtype over @a input, using + * @a key if the checksum type is a keyed checksum. If @a cksumtype is 0 and + * @a key is non-null, the checksum type will be the mandatory-to-implement + * checksum type for the key's encryption type. The actual checksum key will + * be derived from @a key and @a usage if key derivation is specified for the + * checksum type. The newly created @a cksum must be released by calling + * krb5_free_checksum_contents() when it is no longer needed. + * + * @note This function is similar to krb5_k_make_checksum(), but operates + * on keyblock @a key. + * + * @sa krb5_c_verify_checksum() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_make_checksum(krb5_context context, krb5_cksumtype cksumtype, + const krb5_keyblock *key, krb5_keyusage usage, + const krb5_data *input, krb5_checksum *cksum); + +/** + * Verify a checksum (operates on keyblock). + * + * @param [in] context Library context + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage @a key usage + * @param [in] data Data to be used to compute a new checksum + * using @a key to compare @a cksum against + * @param [in] cksum Checksum to be verified + * @param [out] valid Non-zero for success, zero for failure + * + * This function verifies that @a cksum is a valid checksum for @a data. If + * the checksum type of @a cksum is a keyed checksum, @a key is used to verify + * the checksum. If the checksum type in @a cksum is 0 and @a key is not NULL, + * the mandatory checksum type for @a key will be used. The actual checksum + * key will be derived from @a key and @a usage if key derivation is specified + * for the checksum type. + * + * @note This function is similar to krb5_k_verify_checksum(), but operates + * on keyblock @a key. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_verify_checksum(krb5_context context, const krb5_keyblock *key, + krb5_keyusage usage, const krb5_data *data, + const krb5_checksum *cksum, krb5_boolean *valid); + +/** + * Return the length of checksums for a checksum type. + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type + * @param [out] length Checksum length + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_checksum_length(krb5_context context, krb5_cksumtype cksumtype, + size_t *length); + +/** + * Return a list of keyed checksum types usable with an encryption type. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [out] count Count of allowable checksum types + * @param [out] cksumtypes Array of allowable checksum types + * + * Use krb5_free_cksumtypes() to free @a cksumtypes when it is no longer + * needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_keyed_checksum_types(krb5_context context, krb5_enctype enctype, + unsigned int *count, krb5_cksumtype **cksumtypes); + +/** @defgroup KRB5_KEYUSAGE KRB5_KEYUSAGE + * @{ + */ +#define KRB5_KEYUSAGE_AS_REQ_PA_ENC_TS 1 +#define KRB5_KEYUSAGE_KDC_REP_TICKET 2 +#define KRB5_KEYUSAGE_AS_REP_ENCPART 3 +#define KRB5_KEYUSAGE_TGS_REQ_AD_SESSKEY 4 +#define KRB5_KEYUSAGE_TGS_REQ_AD_SUBKEY 5 +#define KRB5_KEYUSAGE_TGS_REQ_AUTH_CKSUM 6 +#define KRB5_KEYUSAGE_TGS_REQ_AUTH 7 +#define KRB5_KEYUSAGE_TGS_REP_ENCPART_SESSKEY 8 +#define KRB5_KEYUSAGE_TGS_REP_ENCPART_SUBKEY 9 +#define KRB5_KEYUSAGE_AP_REQ_AUTH_CKSUM 10 +#define KRB5_KEYUSAGE_AP_REQ_AUTH 11 +#define KRB5_KEYUSAGE_AP_REP_ENCPART 12 +#define KRB5_KEYUSAGE_KRB_PRIV_ENCPART 13 +#define KRB5_KEYUSAGE_KRB_CRED_ENCPART 14 +#define KRB5_KEYUSAGE_KRB_SAFE_CKSUM 15 +#define KRB5_KEYUSAGE_APP_DATA_ENCRYPT 16 +#define KRB5_KEYUSAGE_APP_DATA_CKSUM 17 +#define KRB5_KEYUSAGE_KRB_ERROR_CKSUM 18 +#define KRB5_KEYUSAGE_AD_KDCISSUED_CKSUM 19 +#define KRB5_KEYUSAGE_AD_MTE 20 +#define KRB5_KEYUSAGE_AD_ITE 21 + +/* XXX need to register these */ + +#define KRB5_KEYUSAGE_GSS_TOK_MIC 22 +#define KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG 23 +#define KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV 24 + +/* Defined in Integrating SAM Mechanisms with Kerberos draft */ +#define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_CKSUM 25 +/** Note conflict with @ref KRB5_KEYUSAGE_PA_S4U_X509_USER_REQUEST */ +#define KRB5_KEYUSAGE_PA_SAM_CHALLENGE_TRACKID 26 +/** Note conflict with @ref KRB5_KEYUSAGE_PA_S4U_X509_USER_REPLY */ +#define KRB5_KEYUSAGE_PA_SAM_RESPONSE 27 + +/* Defined in [MS-SFU] */ +/** Note conflict with @ref KRB5_KEYUSAGE_PA_SAM_CHALLENGE_TRACKID */ +#define KRB5_KEYUSAGE_PA_S4U_X509_USER_REQUEST 26 +/** Note conflict with @ref KRB5_KEYUSAGE_PA_SAM_RESPONSE */ +#define KRB5_KEYUSAGE_PA_S4U_X509_USER_REPLY 27 + +/* unused */ +#define KRB5_KEYUSAGE_PA_REFERRAL 26 + +#define KRB5_KEYUSAGE_AD_SIGNEDPATH -21 +#define KRB5_KEYUSAGE_IAKERB_FINISHED 42 +#define KRB5_KEYUSAGE_PA_PKINIT_KX 44 +#define KRB5_KEYUSAGE_PA_OTP_REQUEST 45 /**< See RFC 6560 section 4.2 */ +/* define in draft-ietf-krb-wg-preauth-framework*/ +#define KRB5_KEYUSAGE_FAST_REQ_CHKSUM 50 +#define KRB5_KEYUSAGE_FAST_ENC 51 +#define KRB5_KEYUSAGE_FAST_REP 52 +#define KRB5_KEYUSAGE_FAST_FINISHED 53 +#define KRB5_KEYUSAGE_ENC_CHALLENGE_CLIENT 54 +#define KRB5_KEYUSAGE_ENC_CHALLENGE_KDC 55 +#define KRB5_KEYUSAGE_AS_REQ 56 +#define KRB5_KEYUSAGE_CAMMAC 64 +#define KRB5_KEYUSAGE_SPAKE 65 + +/* Key usage values 512-1023 are reserved for uses internal to a Kerberos + * implementation. */ +#define KRB5_KEYUSAGE_PA_FX_COOKIE 513 /**< Used for encrypted FAST cookies */ +#define KRB5_KEYUSAGE_PA_AS_FRESHNESS 514 /**< Used for freshness tokens */ +/** @} */ /* end of KRB5_KEYUSAGE group */ + +/** + * Verify that a specified encryption type is a valid Kerberos encryption type. + * + * @param [in] ktype Encryption type + * + * @return @c TRUE if @a ktype is valid, @c FALSE if not + */ +krb5_boolean KRB5_CALLCONV +krb5_c_valid_enctype(krb5_enctype ktype); + +/** + * Verify that specified checksum type is a valid Kerberos checksum type. + * + * @param [in] ctype Checksum type + * + * @return @c TRUE if @a ctype is valid, @c FALSE if not + */ +krb5_boolean KRB5_CALLCONV +krb5_c_valid_cksumtype(krb5_cksumtype ctype); + +/** + * Test whether a checksum type is collision-proof. + * + * @param [in] ctype Checksum type + * + * @return @c TRUE if @a ctype is collision-proof, @c FALSE if it is not + * collision-proof or not a valid checksum type. + */ +krb5_boolean KRB5_CALLCONV +krb5_c_is_coll_proof_cksum(krb5_cksumtype ctype); + +/** + * Test whether a checksum type is keyed. + * + * @param [in] ctype Checksum type + * + * @return @c TRUE if @a ctype is a keyed checksum type, @c FALSE otherwise. + */ +krb5_boolean KRB5_CALLCONV +krb5_c_is_keyed_cksum(krb5_cksumtype ctype); + +/* AEAD APIs */ +/** @defgroup KRB5_CRYPTO_TYPE KRB5_CRYPTO_TYPE + * @{ + */ +#define KRB5_CRYPTO_TYPE_EMPTY 0 /**< [in] ignored */ +#define KRB5_CRYPTO_TYPE_HEADER 1 /**< [out] header */ +#define KRB5_CRYPTO_TYPE_DATA 2 /**< [in, out] plaintext */ +#define KRB5_CRYPTO_TYPE_SIGN_ONLY 3 /**< [in] associated data */ +#define KRB5_CRYPTO_TYPE_PADDING 4 /**< [out] padding */ +#define KRB5_CRYPTO_TYPE_TRAILER 5 /**< [out] checksum for encrypt */ +#define KRB5_CRYPTO_TYPE_CHECKSUM 6 /**< [out] checksum for MIC */ +#define KRB5_CRYPTO_TYPE_STREAM 7 /**< [in] entire message without + decomposing the structure into + header, data and trailer buffers */ +/** @} */ /* end of KRB5_CRYPTO_TYPE group */ + +/** + * Fill in a checksum element in IOV array (operates on keyblock) + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] data IOV array + * @param [in] num_data Size of @a data + * + * Create a checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element over + * #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY chunks in @a data. + * Only the #KRB5_CRYPTO_TYPE_CHECKSUM region is modified. + * + * @note This function is similar to krb5_k_make_checksum_iov(), but operates + * on keyblock @a key. + * + * @sa krb5_c_verify_checksum_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_make_checksum_iov(krb5_context context, krb5_cksumtype cksumtype, + const krb5_keyblock *key, krb5_keyusage usage, + krb5_crypto_iov *data, size_t num_data); + +/** + * Validate a checksum element in IOV array (operates on keyblock). + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] data IOV array + * @param [in] num_data Size of @a data + * @param [out] valid Non-zero for success, zero for failure + * + * Confirm that the checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element is a + * valid checksum of the #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY + * regions in the iov. + * + * @note This function is similar to krb5_k_verify_checksum_iov(), but operates + * on keyblock @a key. + * + * @sa krb5_c_make_checksum_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_verify_checksum_iov(krb5_context context, krb5_cksumtype cksumtype, + const krb5_keyblock *key, krb5_keyusage usage, + const krb5_crypto_iov *data, size_t num_data, + krb5_boolean *valid); + +/** + * Encrypt data in place supporting AEAD (operates on keyblock). + * + * @param [in] context Library context + * @param [in] keyblock Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] cipher_state Cipher state; specify NULL if not needed + * @param [in,out] data IOV array. Modified in-place. + * @param [in] num_data Size of @a data + * + * This function encrypts the data block @a data and stores the output in-place. + * The actual encryption key will be derived from @a keyblock and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the encryption operation, and + * is updated with the state to be passed as input to the next operation. + * The caller must allocate the right number of krb5_crypto_iov + * structures before calling into this API. + * + * @note On return from a krb5_c_encrypt_iov() call, the @a data->length in the + * iov structure are adjusted to reflect actual lengths of the ciphertext used. + * For example, if the padding length is too large, the length will be reduced. + * Lengths are never increased. + * + * @note This function is similar to krb5_k_encrypt_iov(), but operates + * on keyblock @a keyblock. + * + * @sa krb5_c_decrypt_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_encrypt_iov(krb5_context context, const krb5_keyblock *keyblock, + krb5_keyusage usage, const krb5_data *cipher_state, + krb5_crypto_iov *data, size_t num_data); + +/** + * Decrypt data in place supporting AEAD (operates on keyblock). + * + * @param [in] context Library context + * @param [in] keyblock Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] cipher_state Cipher state; specify NULL if not needed + * @param [in,out] data IOV array. Modified in-place. + * @param [in] num_data Size of @a data + * + * This function decrypts the data block @a data and stores the output in-place. + * The actual decryption key will be derived from @a keyblock and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the decryption operation, and + * is updated with the state to be passed as input to the next operation. + * The caller must allocate the right number of krb5_crypto_iov + * structures before calling into this API. + * + * @note On return from a krb5_c_decrypt_iov() call, the @a data->length in the + * iov structure are adjusted to reflect actual lengths of the ciphertext used. + * For example, if the padding length is too large, the length will be reduced. + * Lengths are never increased. + * + * @note This function is similar to krb5_k_decrypt_iov(), but operates + * on keyblock @a keyblock. + * + * @sa krb5_c_decrypt_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_decrypt_iov(krb5_context context, const krb5_keyblock *keyblock, + krb5_keyusage usage, const krb5_data *cipher_state, + krb5_crypto_iov *data, size_t num_data); + +/** + * Return a length of a message field specific to the encryption type. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] type Type field (See @ref KRB5_CRYPTO_TYPE types) + * @param [out] size Length of the @a type specific to @a enctype + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_crypto_length(krb5_context context, krb5_enctype enctype, + krb5_cryptotype type, unsigned int *size); + +/** + * Fill in lengths for header, trailer and padding in a IOV array. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in,out] data IOV array + * @param [in] num_data Size of @a data + * + * Padding is set to the actual padding required based on the provided + * @a data buffers. Typically this API is used after setting up the data + * buffers and #KRB5_CRYPTO_TYPE_SIGN_ONLY buffers, but before actually + * allocating header, trailer and padding. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_c_crypto_length_iov(krb5_context context, krb5_enctype enctype, + krb5_crypto_iov *data, size_t num_data); + +/** + * Return a number of padding octets. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] data_length Length of the plaintext to pad + * @param [out] size Number of padding octets + * + * This function returns the number of the padding octets required to pad + * @a data_length octets of plaintext. + * + * @retval 0 Success; otherwise - KRB5_BAD_ENCTYPE + */ +krb5_error_code KRB5_CALLCONV +krb5_c_padding_length(krb5_context context, krb5_enctype enctype, + size_t data_length, unsigned int *size); + +/** + * Create a krb5_key from the enctype and key data in a keyblock. + * + * @param [in] context Library context + * @param [in] key_data Keyblock + * @param [out] out Opaque key + * + * The reference count on a key @a out is set to 1. + * Use krb5_k_free_key() to free @a out when it is no longer needed. + * + * @retval 0 Success; otherwise - KRB5_BAD_ENCTYPE + */ +krb5_error_code KRB5_CALLCONV +krb5_k_create_key(krb5_context context, const krb5_keyblock *key_data, + krb5_key *out); + +/** Increment the reference count on a key. */ +void KRB5_CALLCONV +krb5_k_reference_key(krb5_context context, krb5_key key); + +/** Decrement the reference count on a key and free it if it hits zero. */ +void KRB5_CALLCONV +krb5_k_free_key(krb5_context context, krb5_key key); + +/** Retrieve a copy of the keyblock from a krb5_key structure. */ +krb5_error_code KRB5_CALLCONV +krb5_k_key_keyblock(krb5_context context, krb5_key key, + krb5_keyblock **key_data); + +/** Retrieve the enctype of a krb5_key structure. */ +krb5_enctype KRB5_CALLCONV +krb5_k_key_enctype(krb5_context context, krb5_key key); + +/** + * Encrypt data using a key (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] cipher_state Cipher state; specify NULL if not needed + * @param [in] input Data to be encrypted + * @param [out] output Encrypted data + * + * This function encrypts the data block @a input and stores the output into @a + * output. The actual encryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the encryption operation, and + * is updated with the state to be passed as input to the next operation. + * + * @note The caller must initialize @a output and allocate at least enough + * space for the result (using krb5_c_encrypt_length() to determine the amount + * of space needed). @a output->length will be set to the actual length of the + * ciphertext. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_encrypt(krb5_context context, krb5_key key, krb5_keyusage usage, + const krb5_data *cipher_state, const krb5_data *input, + krb5_enc_data *output); + +/** + * Encrypt data in place supporting AEAD (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] cipher_state Cipher state; specify NULL if not needed + * @param [in,out] data IOV array. Modified in-place. + * @param [in] num_data Size of @a data + * + * This function encrypts the data block @a data and stores the output in-place. + * The actual encryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the encryption operation, and + * is updated with the state to be passed as input to the next operation. + * The caller must allocate the right number of krb5_crypto_iov + * structures before calling into this API. + * + * @note On return from a krb5_c_encrypt_iov() call, the @a data->length in the + * iov structure are adjusted to reflect actual lengths of the ciphertext used. + * For example, if the padding length is too large, the length will be reduced. + * Lengths are never increased. + * + * @note This function is similar to krb5_c_encrypt_iov(), but operates + * on opaque key @a key. + * + * @sa krb5_k_decrypt_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_encrypt_iov(krb5_context context, krb5_key key, krb5_keyusage usage, + const krb5_data *cipher_state, krb5_crypto_iov *data, + size_t num_data); + +/** + * Decrypt data using a key (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] cipher_state Cipher state; specify NULL if not needed + * @param [in] input Encrypted data + * @param [out] output Decrypted data + * + * This function decrypts the data block @a input and stores the output into @a + * output. The actual decryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the decryption operation, and + * is updated with the state to be passed as input to the next operation. + * + * @note The caller must initialize @a output and allocate at least enough + * space for the result. The usual practice is to allocate an output buffer as + * long as the ciphertext, and let krb5_c_decrypt() trim @a output->length. + * For some enctypes, the resulting @a output->length may include padding + * bytes. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_decrypt(krb5_context context, krb5_key key, krb5_keyusage usage, + const krb5_data *cipher_state, const krb5_enc_data *input, + krb5_data *output); + +/** + * Decrypt data in place supporting AEAD (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Encryption key + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] cipher_state Cipher state; specify NULL if not needed + * @param [in,out] data IOV array. Modified in-place. + * @param [in] num_data Size of @a data + * + * This function decrypts the data block @a data and stores the output in-place. + * The actual decryption key will be derived from @a key and @a usage + * if key derivation is specified for the encryption type. If non-null, @a + * cipher_state specifies the beginning state for the decryption operation, and + * is updated with the state to be passed as input to the next operation. + * The caller must allocate the right number of krb5_crypto_iov + * structures before calling into this API. + * + * @note On return from a krb5_c_decrypt_iov() call, the @a data->length in the + * iov structure are adjusted to reflect actual lengths of the ciphertext used. + * For example, if the padding length is too large, the length will be reduced. + * Lengths are never increased. + * + * @note This function is similar to krb5_c_decrypt_iov(), but operates + * on opaque key @a key. + * + * @sa krb5_k_encrypt_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_decrypt_iov(krb5_context context, krb5_key key, krb5_keyusage usage, + const krb5_data *cipher_state, krb5_crypto_iov *data, + size_t num_data); +/** + * Compute a checksum (operates on opaque key). + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] input Input data + * @param [out] cksum Generated checksum + * + * This function computes a checksum of type @a cksumtype over @a input, using + * @a key if the checksum type is a keyed checksum. If @a cksumtype is 0 and + * @a key is non-null, the checksum type will be the mandatory-to-implement + * checksum type for the key's encryption type. The actual checksum key will + * be derived from @a key and @a usage if key derivation is specified for the + * checksum type. The newly created @a cksum must be released by calling + * krb5_free_checksum_contents() when it is no longer needed. + * + * @note This function is similar to krb5_c_make_checksum(), but operates + * on opaque @a key. + * + * @sa krb5_c_verify_checksum() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_make_checksum(krb5_context context, krb5_cksumtype cksumtype, + krb5_key key, krb5_keyusage usage, const krb5_data *input, + krb5_checksum *cksum); + +/** + * Fill in a checksum element in IOV array (operates on opaque key) + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in,out] data IOV array + * @param [in] num_data Size of @a data + * + * Create a checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element over + * #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY chunks in @a data. + * Only the #KRB5_CRYPTO_TYPE_CHECKSUM region is modified. + * + * @note This function is similar to krb5_c_make_checksum_iov(), but operates + * on opaque @a key. + * + * @sa krb5_k_verify_checksum_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_make_checksum_iov(krb5_context context, krb5_cksumtype cksumtype, + krb5_key key, krb5_keyusage usage, + krb5_crypto_iov *data, size_t num_data); + +/** + * Verify a checksum (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage @a key usage + * @param [in] data Data to be used to compute a new checksum + * using @a key to compare @a cksum against + * @param [in] cksum Checksum to be verified + * @param [out] valid Non-zero for success, zero for failure + * + * This function verifies that @a cksum is a valid checksum for @a data. If + * the checksum type of @a cksum is a keyed checksum, @a key is used to verify + * the checksum. If the checksum type in @a cksum is 0 and @a key is not NULL, + * the mandatory checksum type for @a key will be used. The actual checksum + * key will be derived from @a key and @a usage if key derivation is specified + * for the checksum type. + * + * @note This function is similar to krb5_c_verify_checksum(), but operates + * on opaque @a key. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_verify_checksum(krb5_context context, krb5_key key, krb5_keyusage usage, + const krb5_data *data, const krb5_checksum *cksum, + krb5_boolean *valid); + +/** + * Validate a checksum element in IOV array (operates on opaque key). + * + * @param [in] context Library context + * @param [in] cksumtype Checksum type (0 for mandatory type) + * @param [in] key Encryption key for a keyed checksum + * @param [in] usage Key usage (see @ref KRB5_KEYUSAGE types) + * @param [in] data IOV array + * @param [in] num_data Size of @a data + * @param [out] valid Non-zero for success, zero for failure + * + * Confirm that the checksum in the #KRB5_CRYPTO_TYPE_CHECKSUM element is a + * valid checksum of the #KRB5_CRYPTO_TYPE_DATA and #KRB5_CRYPTO_TYPE_SIGN_ONLY + * regions in the iov. + * + * @note This function is similar to krb5_c_verify_checksum_iov(), but operates + * on opaque @a key. + * + * @sa krb5_k_make_checksum_iov() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_verify_checksum_iov(krb5_context context, krb5_cksumtype cksumtype, + krb5_key key, krb5_keyusage usage, + const krb5_crypto_iov *data, size_t num_data, + krb5_boolean *valid); + +/** + * Generate enctype-specific pseudo-random bytes (operates on opaque key). + * + * @param [in] context Library context + * @param [in] key Key + * @param [in] input Input data + * @param [out] output Output data + * + * This function selects a pseudo-random function based on @a key and + * computes its value over @a input, placing the result into @a output. + * The caller must preinitialize @a output and allocate space for the + * result. + * + * @note This function is similar to krb5_c_prf(), but operates + * on opaque @a key. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_k_prf(krb5_context context, krb5_key key, krb5_data *input, krb5_data *output); + +#ifdef KRB5_OLD_CRYPTO +/* + * old cryptosystem routine prototypes. These are now layered + * on top of the functions above. + */ +/** @deprecated Replaced by krb5_c_* API family.*/ +krb5_error_code KRB5_CALLCONV +krb5_encrypt(krb5_context context, krb5_const_pointer inptr, + krb5_pointer outptr, size_t size, krb5_encrypt_block *eblock, + krb5_pointer ivec); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_decrypt(krb5_context context, krb5_const_pointer inptr, + krb5_pointer outptr, size_t size, krb5_encrypt_block *eblock, + krb5_pointer ivec); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_process_key(krb5_context context, krb5_encrypt_block *eblock, + const krb5_keyblock * key); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_finish_key(krb5_context context, krb5_encrypt_block * eblock); + +/** @deprecated See krb5_c_string_to_key() */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_key(krb5_context context, const krb5_encrypt_block *eblock, + krb5_keyblock * keyblock, const krb5_data *data, + const krb5_data *salt); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_init_random_key(krb5_context context, const krb5_encrypt_block *eblock, + const krb5_keyblock *keyblock, krb5_pointer *ptr); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_finish_random_key(krb5_context context, const krb5_encrypt_block *eblock, + krb5_pointer *ptr); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_random_key(krb5_context context, const krb5_encrypt_block *eblock, + krb5_pointer ptr, krb5_keyblock **keyblock); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_enctype KRB5_CALLCONV +krb5_eblock_enctype(krb5_context context, const krb5_encrypt_block *eblock); + +/** @deprecated Replaced by krb5_c_* API family. */ +krb5_error_code KRB5_CALLCONV +krb5_use_enctype(krb5_context context, krb5_encrypt_block *eblock, + krb5_enctype enctype); + +/** @deprecated Replaced by krb5_c_* API family. */ +size_t KRB5_CALLCONV +krb5_encrypt_size(size_t length, krb5_enctype crypto); + +/** @deprecated See krb5_c_checksum_length() */ +size_t KRB5_CALLCONV +krb5_checksum_size(krb5_context context, krb5_cksumtype ctype); + +/** @deprecated See krb5_c_make_checksum() */ +krb5_error_code KRB5_CALLCONV +krb5_calculate_checksum(krb5_context context, krb5_cksumtype ctype, + krb5_const_pointer in, size_t in_length, + krb5_const_pointer seed, size_t seed_length, + krb5_checksum * outcksum); + +/** @deprecated See krb5_c_verify_checksum() */ +krb5_error_code KRB5_CALLCONV +krb5_verify_checksum(krb5_context context, krb5_cksumtype ctype, + const krb5_checksum * cksum, krb5_const_pointer in, + size_t in_length, krb5_const_pointer seed, + size_t seed_length); + +#endif /* KRB5_OLD_CRYPTO */ + +/* + * end "encryption.h" + */ + +/* + * begin "fieldbits.h" + */ + +/* kdc_options for kdc_request */ +/* options is 32 bits; each host is responsible to put the 4 bytes + representing these bits into net order before transmission */ +/* #define KDC_OPT_RESERVED 0x80000000 */ +#define KDC_OPT_FORWARDABLE 0x40000000 +#define KDC_OPT_FORWARDED 0x20000000 +#define KDC_OPT_PROXIABLE 0x10000000 +#define KDC_OPT_PROXY 0x08000000 +#define KDC_OPT_ALLOW_POSTDATE 0x04000000 +#define KDC_OPT_POSTDATED 0x02000000 +/* #define KDC_OPT_UNUSED 0x01000000 */ +#define KDC_OPT_RENEWABLE 0x00800000 +/* #define KDC_OPT_UNUSED 0x00400000 */ +/* #define KDC_OPT_RESERVED 0x00200000 */ +/* #define KDC_OPT_RESERVED 0x00100000 */ +/* #define KDC_OPT_RESERVED 0x00080000 */ +/* #define KDC_OPT_RESERVED 0x00040000 */ +#define KDC_OPT_CNAME_IN_ADDL_TKT 0x00020000 +#define KDC_OPT_CANONICALIZE 0x00010000 +#define KDC_OPT_REQUEST_ANONYMOUS 0x00008000 +/* #define KDC_OPT_RESERVED 0x00004000 */ +/* #define KDC_OPT_RESERVED 0x00002000 */ +/* #define KDC_OPT_RESERVED 0x00001000 */ +/* #define KDC_OPT_RESERVED 0x00000800 */ +/* #define KDC_OPT_RESERVED 0x00000400 */ +/* #define KDC_OPT_RESERVED 0x00000200 */ +/* #define KDC_OPT_RESERVED 0x00000100 */ +/* #define KDC_OPT_RESERVED 0x00000080 */ +/* #define KDC_OPT_RESERVED 0x00000040 */ +#define KDC_OPT_DISABLE_TRANSITED_CHECK 0x00000020 +#define KDC_OPT_RENEWABLE_OK 0x00000010 +#define KDC_OPT_ENC_TKT_IN_SKEY 0x00000008 +/* #define KDC_OPT_UNUSED 0x00000004 */ +#define KDC_OPT_RENEW 0x00000002 +#define KDC_OPT_VALIDATE 0x00000001 + +/* + * Mask of ticket flags in the TGT which should be converted into KDC + * options when using the TGT to get derivitive tickets. + * + * New mask = KDC_OPT_FORWARDABLE | KDC_OPT_PROXIABLE | + * KDC_OPT_ALLOW_POSTDATE | KDC_OPT_RENEWABLE + */ +#define KDC_TKT_COMMON_MASK 0x54800000 + +/* definitions for ap_options fields */ + +/** @defgroup AP_OPTS AP_OPTS + * + * ap_options are 32 bits; each host is responsible to put the 4 bytes + * representing these bits into net order before transmission + * @{ + */ +#define AP_OPTS_RESERVED 0x80000000 +#define AP_OPTS_USE_SESSION_KEY 0x40000000 /**< Use session key */ +#define AP_OPTS_MUTUAL_REQUIRED 0x20000000 /**< Perform a mutual + authentication exchange */ +#define AP_OPTS_ETYPE_NEGOTIATION 0x00000002 +#define AP_OPTS_USE_SUBKEY 0x00000001 /**< Generate a subsession key + from the current session key + obtained from the + credentials */ +/* #define AP_OPTS_RESERVED 0x10000000 */ +/* #define AP_OPTS_RESERVED 0x08000000 */ +/* #define AP_OPTS_RESERVED 0x04000000 */ +/* #define AP_OPTS_RESERVED 0x02000000 */ +/* #define AP_OPTS_RESERVED 0x01000000 */ +/* #define AP_OPTS_RESERVED 0x00800000 */ +/* #define AP_OPTS_RESERVED 0x00400000 */ +/* #define AP_OPTS_RESERVED 0x00200000 */ +/* #define AP_OPTS_RESERVED 0x00100000 */ +/* #define AP_OPTS_RESERVED 0x00080000 */ +/* #define AP_OPTS_RESERVED 0x00040000 */ +/* #define AP_OPTS_RESERVED 0x00020000 */ +/* #define AP_OPTS_RESERVED 0x00010000 */ +/* #define AP_OPTS_RESERVED 0x00008000 */ +/* #define AP_OPTS_RESERVED 0x00004000 */ +/* #define AP_OPTS_RESERVED 0x00002000 */ +/* #define AP_OPTS_RESERVED 0x00001000 */ +/* #define AP_OPTS_RESERVED 0x00000800 */ +/* #define AP_OPTS_RESERVED 0x00000400 */ +/* #define AP_OPTS_RESERVED 0x00000200 */ +/* #define AP_OPTS_RESERVED 0x00000100 */ +/* #define AP_OPTS_RESERVED 0x00000080 */ +/* #define AP_OPTS_RESERVED 0x00000040 */ +/* #define AP_OPTS_RESERVED 0x00000020 */ +/* #define AP_OPTS_RESERVED 0x00000010 */ +/* #define AP_OPTS_RESERVED 0x00000008 */ +/* #define AP_OPTS_RESERVED 0x00000004 */ + + +#define AP_OPTS_WIRE_MASK 0xfffffff0 +/** @} */ /* end of AP_OPTS group */ + +/* definitions for ad_type fields. */ +#define AD_TYPE_RESERVED 0x8000 +#define AD_TYPE_EXTERNAL 0x4000 +#define AD_TYPE_REGISTERED 0x2000 + +#define AD_TYPE_FIELD_TYPE_MASK 0x1fff + +/* Ticket flags */ +/* flags are 32 bits; each host is responsible to put the 4 bytes + representing these bits into net order before transmission */ +/* #define TKT_FLG_RESERVED 0x80000000 */ +#define TKT_FLG_FORWARDABLE 0x40000000 +#define TKT_FLG_FORWARDED 0x20000000 +#define TKT_FLG_PROXIABLE 0x10000000 +#define TKT_FLG_PROXY 0x08000000 +#define TKT_FLG_MAY_POSTDATE 0x04000000 +#define TKT_FLG_POSTDATED 0x02000000 +#define TKT_FLG_INVALID 0x01000000 +#define TKT_FLG_RENEWABLE 0x00800000 +#define TKT_FLG_INITIAL 0x00400000 +#define TKT_FLG_PRE_AUTH 0x00200000 +#define TKT_FLG_HW_AUTH 0x00100000 +#define TKT_FLG_TRANSIT_POLICY_CHECKED 0x00080000 +#define TKT_FLG_OK_AS_DELEGATE 0x00040000 +#define TKT_FLG_ENC_PA_REP 0x00010000 +#define TKT_FLG_ANONYMOUS 0x00008000 +/* #define TKT_FLG_RESERVED 0x00004000 */ +/* #define TKT_FLG_RESERVED 0x00002000 */ +/* #define TKT_FLG_RESERVED 0x00001000 */ +/* #define TKT_FLG_RESERVED 0x00000800 */ +/* #define TKT_FLG_RESERVED 0x00000400 */ +/* #define TKT_FLG_RESERVED 0x00000200 */ +/* #define TKT_FLG_RESERVED 0x00000100 */ +/* #define TKT_FLG_RESERVED 0x00000080 */ +/* #define TKT_FLG_RESERVED 0x00000040 */ +/* #define TKT_FLG_RESERVED 0x00000020 */ +/* #define TKT_FLG_RESERVED 0x00000010 */ +/* #define TKT_FLG_RESERVED 0x00000008 */ +/* #define TKT_FLG_RESERVED 0x00000004 */ +/* #define TKT_FLG_RESERVED 0x00000002 */ +/* #define TKT_FLG_RESERVED 0x00000001 */ + +/* definitions for lr_type fields. */ +#define LR_TYPE_THIS_SERVER_ONLY 0x8000 + +#define LR_TYPE_INTERPRETATION_MASK 0x7fff + +/* definitions for msec direction bit for KRB_SAFE, KRB_PRIV */ +#define MSEC_DIRBIT 0x8000 +#define MSEC_VAL_MASK 0x7fff + +/* + * end "fieldbits.h" + */ + +/* + * begin "proto.h" + */ + +/** Protocol version number */ +#define KRB5_PVNO 5 + +/* Message types */ + +#define KRB5_AS_REQ ((krb5_msgtype)10) /**< Initial authentication request */ +#define KRB5_AS_REP ((krb5_msgtype)11) /**< Response to AS request */ +#define KRB5_TGS_REQ ((krb5_msgtype)12) /**< Ticket granting server request */ +#define KRB5_TGS_REP ((krb5_msgtype)13) /**< Response to TGS request */ +#define KRB5_AP_REQ ((krb5_msgtype)14) /**< Auth req to application server */ +#define KRB5_AP_REP ((krb5_msgtype)15) /**< Response to mutual AP request */ +#define KRB5_SAFE ((krb5_msgtype)20) /**< Safe application message */ +#define KRB5_PRIV ((krb5_msgtype)21) /**< Private application message */ +#define KRB5_CRED ((krb5_msgtype)22) /**< Cred forwarding message */ +#define KRB5_ERROR ((krb5_msgtype)30) /**< Error response */ + +/* LastReq types */ +#define KRB5_LRQ_NONE 0 +#define KRB5_LRQ_ALL_LAST_TGT 1 +#define KRB5_LRQ_ONE_LAST_TGT (-1) +#define KRB5_LRQ_ALL_LAST_INITIAL 2 +#define KRB5_LRQ_ONE_LAST_INITIAL (-2) +#define KRB5_LRQ_ALL_LAST_TGT_ISSUED 3 +#define KRB5_LRQ_ONE_LAST_TGT_ISSUED (-3) +#define KRB5_LRQ_ALL_LAST_RENEWAL 4 +#define KRB5_LRQ_ONE_LAST_RENEWAL (-4) +#define KRB5_LRQ_ALL_LAST_REQ 5 +#define KRB5_LRQ_ONE_LAST_REQ (-5) +#define KRB5_LRQ_ALL_PW_EXPTIME 6 +#define KRB5_LRQ_ONE_PW_EXPTIME (-6) +#define KRB5_LRQ_ALL_ACCT_EXPTIME 7 +#define KRB5_LRQ_ONE_ACCT_EXPTIME (-7) + +/* PADATA types */ +#define KRB5_PADATA_NONE 0 +#define KRB5_PADATA_AP_REQ 1 +#define KRB5_PADATA_TGS_REQ KRB5_PADATA_AP_REQ +#define KRB5_PADATA_ENC_TIMESTAMP 2 /**< RFC 4120 */ +#define KRB5_PADATA_PW_SALT 3 /**< RFC 4120 */ +#if 0 /* Not used */ +#define KRB5_PADATA_ENC_ENCKEY 4 /* Key encrypted within itself */ +#endif +#define KRB5_PADATA_ENC_UNIX_TIME 5 /**< timestamp encrypted in key. RFC 4120 */ +#define KRB5_PADATA_ENC_SANDIA_SECURID 6 /**< SecurId passcode. RFC 4120 */ +#define KRB5_PADATA_SESAME 7 /**< Sesame project. RFC 4120 */ +#define KRB5_PADATA_OSF_DCE 8 /**< OSF DCE. RFC 4120 */ +#define KRB5_CYBERSAFE_SECUREID 9 /**< Cybersafe. RFC 4120 */ +#define KRB5_PADATA_AFS3_SALT 10 /**< Cygnus. RFC 4120, 3961 */ +#define KRB5_PADATA_ETYPE_INFO 11 /**< Etype info for preauth. RFC 4120 */ +#define KRB5_PADATA_SAM_CHALLENGE 12 /**< SAM/OTP */ +#define KRB5_PADATA_SAM_RESPONSE 13 /**< SAM/OTP */ +#define KRB5_PADATA_PK_AS_REQ_OLD 14 /**< PKINIT */ +#define KRB5_PADATA_PK_AS_REP_OLD 15 /**< PKINIT */ +#define KRB5_PADATA_PK_AS_REQ 16 /**< PKINIT. RFC 4556 */ +#define KRB5_PADATA_PK_AS_REP 17 /**< PKINIT. RFC 4556 */ +#define KRB5_PADATA_ETYPE_INFO2 19 /**< RFC 4120 */ +#define KRB5_PADATA_USE_SPECIFIED_KVNO 20 /**< RFC 4120 */ +#define KRB5_PADATA_SVR_REFERRAL_INFO 20 /**< Windows 2000 referrals. RFC 6820 */ +#define KRB5_PADATA_SAM_REDIRECT 21 /**< SAM/OTP. RFC 4120 */ +#define KRB5_PADATA_GET_FROM_TYPED_DATA 22 /**< Embedded in typed data. RFC 4120 */ +#define KRB5_PADATA_REFERRAL 25 /**< draft referral system */ +#define KRB5_PADATA_SAM_CHALLENGE_2 30 /**< draft challenge system, updated */ +#define KRB5_PADATA_SAM_RESPONSE_2 31 /**< draft challenge system, updated */ +/* MS-KILE */ +#define KRB5_PADATA_PAC_REQUEST 128 /**< include Windows PAC */ +#define KRB5_PADATA_FOR_USER 129 /**< username protocol transition request */ +#define KRB5_PADATA_S4U_X509_USER 130 /**< certificate protocol transition request */ +#define KRB5_PADATA_AS_CHECKSUM 132 /**< AS checksum */ +#define KRB5_PADATA_FX_COOKIE 133 /**< RFC 6113 */ +#define KRB5_PADATA_FX_FAST 136 /**< RFC 6113 */ +#define KRB5_PADATA_FX_ERROR 137 /**< RFC 6113 */ +#define KRB5_PADATA_ENCRYPTED_CHALLENGE 138 /**< RFC 6113 */ +#define KRB5_PADATA_OTP_CHALLENGE 141 /**< RFC 6560 section 4.1 */ +#define KRB5_PADATA_OTP_REQUEST 142 /**< RFC 6560 section 4.2 */ +#define KRB5_PADATA_OTP_PIN_CHANGE 144 /**< RFC 6560 section 4.3 */ +#define KRB5_PADATA_PKINIT_KX 147 /**< RFC 6112 */ +#define KRB5_ENCPADATA_REQ_ENC_PA_REP 149 /**< RFC 6806 */ +#define KRB5_PADATA_AS_FRESHNESS 150 /**< RFC 8070 */ +#define KRB5_PADATA_SPAKE 151 + +#define KRB5_SAM_USE_SAD_AS_KEY 0x80000000 +#define KRB5_SAM_SEND_ENCRYPTED_SAD 0x40000000 +#define KRB5_SAM_MUST_PK_ENCRYPT_SAD 0x20000000 /**< currently must be zero */ + +/** Transited encoding types */ +#define KRB5_DOMAIN_X500_COMPRESS 1 + +/** alternate authentication types */ +#define KRB5_ALTAUTH_ATT_CHALLENGE_RESPONSE 64 + +/* authorization data types. See RFC 4120 section 5.2.6 */ + +/** @defgroup KRB5_AUTHDATA KRB5_AUTHDATA + * @{ + */ +#define KRB5_AUTHDATA_IF_RELEVANT 1 +#define KRB5_AUTHDATA_KDC_ISSUED 4 +#define KRB5_AUTHDATA_AND_OR 5 +#define KRB5_AUTHDATA_MANDATORY_FOR_KDC 8 +#define KRB5_AUTHDATA_INITIAL_VERIFIED_CAS 9 +#define KRB5_AUTHDATA_OSF_DCE 64 +#define KRB5_AUTHDATA_SESAME 65 +#define KRB5_AUTHDATA_CAMMAC 96 +#define KRB5_AUTHDATA_WIN2K_PAC 128 +#define KRB5_AUTHDATA_ETYPE_NEGOTIATION 129 /**< RFC 4537 */ +#define KRB5_AUTHDATA_SIGNTICKET 512 /**< formerly 142 in krb5 1.8 */ +#define KRB5_AUTHDATA_FX_ARMOR 71 +#define KRB5_AUTHDATA_AUTH_INDICATOR 97 +/** @} */ /* end of KRB5_AUTHDATA group */ + +/* password change constants */ +#define KRB5_KPASSWD_SUCCESS 0 /**< Success */ +#define KRB5_KPASSWD_MALFORMED 1 /**< Malformed request */ +#define KRB5_KPASSWD_HARDERROR 2 /**< Server error */ +#define KRB5_KPASSWD_AUTHERROR 3 /**< Authentication error */ +#define KRB5_KPASSWD_SOFTERROR 4 /**< Password change rejected */ +/* These are Microsoft's extensions in RFC 3244, and it looks like + they'll become standardized, possibly with other additions. */ +#define KRB5_KPASSWD_ACCESSDENIED 5 /**< Not authorized */ +#define KRB5_KPASSWD_BAD_VERSION 6 /**< Unknown RPC version */ +/** The presented credentials were not obtained using a password directly */ +#define KRB5_KPASSWD_INITIAL_FLAG_NEEDED 7 + +/* + * end "proto.h" + */ + +/* Time set */ +/** Ticket start time, end time, and renewal duration. */ +typedef struct _krb5_ticket_times { + krb5_timestamp authtime; /**< Time at which KDC issued the initial ticket that corresponds to this ticket */ + /* XXX ? should ktime in KDC_REP == authtime + in ticket? otherwise client can't get this */ + krb5_timestamp starttime; /**< optional in ticket, if not present, use @a authtime */ + krb5_timestamp endtime; /**< Ticket expiration time */ + krb5_timestamp renew_till; /**< Latest time at which renewal of ticket can be valid */ +} krb5_ticket_times; + +/** Structure for auth data */ +typedef struct _krb5_authdata { + krb5_magic magic; + krb5_authdatatype ad_type; /**< ADTYPE */ + unsigned int length; /**< Length of data */ + krb5_octet *contents; /**< Data */ +} krb5_authdata; + +/** Structure for transited encoding */ +typedef struct _krb5_transited { + krb5_magic magic; + krb5_octet tr_type; /**< Transited encoding type */ + krb5_data tr_contents; /**< Contents */ +} krb5_transited; + +/** Encrypted part of ticket. */ +typedef struct _krb5_enc_tkt_part { + krb5_magic magic; + /* to-be-encrypted portion */ + krb5_flags flags; /**< flags */ + krb5_keyblock *session; /**< session key: includes enctype */ + krb5_principal client; /**< client name/realm */ + krb5_transited transited; /**< list of transited realms */ + krb5_ticket_times times; /**< auth, start, end, renew_till */ + krb5_address **caddrs; /**< array of ptrs to addresses */ + krb5_authdata **authorization_data; /**< auth data */ +} krb5_enc_tkt_part; + +/** + * Ticket structure. + * + * The C representation of the ticket message, with a pointer to the + * C representation of the encrypted part. + */ +typedef struct _krb5_ticket { + krb5_magic magic; + /* cleartext portion */ + krb5_principal server; /**< server name/realm */ + krb5_enc_data enc_part; /**< encryption type, kvno, encrypted encoding */ + krb5_enc_tkt_part *enc_part2; /**< ptr to decrypted version, if available */ +} krb5_ticket; + +/* the unencrypted version */ +/** + * Ticket authenticator. + * + * The C representation of an unencrypted authenticator. + */ +typedef struct _krb5_authenticator { + krb5_magic magic; + krb5_principal client; /**< client name/realm */ + krb5_checksum *checksum; /**< checksum, includes type, optional */ + krb5_int32 cusec; /**< client usec portion */ + krb5_timestamp ctime; /**< client sec portion */ + krb5_keyblock *subkey; /**< true session key, optional */ + krb5_ui_4 seq_number; /**< sequence #, optional */ + krb5_authdata **authorization_data; /**< authoriazation data */ +} krb5_authenticator; + +/** Ticket authentication data. */ +typedef struct _krb5_tkt_authent { + krb5_magic magic; + krb5_ticket *ticket; + krb5_authenticator *authenticator; + krb5_flags ap_options; +} krb5_tkt_authent; + +/** Credentials structure including ticket, session key, and lifetime info. */ +typedef struct _krb5_creds { + krb5_magic magic; + krb5_principal client; /**< client's principal identifier */ + krb5_principal server; /**< server's principal identifier */ + krb5_keyblock keyblock; /**< session encryption key info */ + krb5_ticket_times times; /**< lifetime info */ + krb5_boolean is_skey; /**< true if ticket is encrypted in + another ticket's skey */ + krb5_flags ticket_flags; /**< flags in ticket */ + krb5_address **addresses; /**< addrs in ticket */ + krb5_data ticket; /**< ticket string itself */ + krb5_data second_ticket; /**< second ticket, if related to + ticket (via DUPLICATE-SKEY or + ENC-TKT-IN-SKEY) */ + krb5_authdata **authdata; /**< authorization data */ +} krb5_creds; + +/** Last request entry */ +typedef struct _krb5_last_req_entry { + krb5_magic magic; + krb5_int32 lr_type; /**< LR type */ + krb5_timestamp value; /**< Timestamp */ +} krb5_last_req_entry; + +/** Pre-authentication data */ +typedef struct _krb5_pa_data { + krb5_magic magic; + krb5_preauthtype pa_type; /**< Preauthentication data type */ + unsigned int length; /**< Length of data */ + krb5_octet *contents; /**< Data */ +} krb5_pa_data; + +/* Don't use this; use krb5_pa_data instead. */ +typedef struct _krb5_typed_data { + krb5_magic magic; + krb5_int32 type; + unsigned int length; + krb5_octet *data; +} krb5_typed_data; + +/** C representation of KDC-REQ protocol message, including KDC-REQ-BODY */ +typedef struct _krb5_kdc_req { + krb5_magic magic; + krb5_msgtype msg_type; /**< KRB5_AS_REQ or KRB5_TGS_REQ */ + krb5_pa_data **padata; /**< Preauthentication data */ + /* real body */ + krb5_flags kdc_options; /**< Requested options */ + krb5_principal client; /**< Client principal and realm */ + krb5_principal server; /**< Server principal and realm */ + krb5_timestamp from; /**< Requested start time */ + krb5_timestamp till; /**< Requested end time */ + krb5_timestamp rtime; /**< Requested renewable end time */ + krb5_int32 nonce; /**< Nonce to match request and response */ + int nktypes; /**< Number of enctypes */ + krb5_enctype *ktype; /**< Requested enctypes */ + krb5_address **addresses; /**< Requested addresses (optional) */ + krb5_enc_data authorization_data; /**< Encrypted authz data (optional) */ + krb5_authdata **unenc_authdata; /**< Unencrypted authz data */ + krb5_ticket **second_ticket; /**< Second ticket array (optional) */ +} krb5_kdc_req; + +/** + * C representation of @c EncKDCRepPart protocol message. + * + * This is the cleartext message that is encrypted and inserted in @c KDC-REP. + */ +typedef struct _krb5_enc_kdc_rep_part { + krb5_magic magic; + /* encrypted part: */ + krb5_msgtype msg_type; /**< krb5 message type */ + krb5_keyblock *session; /**< Session key */ + krb5_last_req_entry **last_req; /**< Array of pointers to entries */ + krb5_int32 nonce; /**< Nonce from request */ + krb5_timestamp key_exp; /**< Expiration date */ + krb5_flags flags; /**< Ticket flags */ + krb5_ticket_times times; /**< Lifetime info */ + krb5_principal server; /**< Server's principal identifier */ + krb5_address **caddrs; /**< Array of ptrs to addrs, optional */ + krb5_pa_data **enc_padata; /**< Encrypted preauthentication data */ +} krb5_enc_kdc_rep_part; + +/** Representation of the @c KDC-REP protocol message. */ +typedef struct _krb5_kdc_rep { + krb5_magic magic; + /* cleartext part: */ + krb5_msgtype msg_type; /**< KRB5_AS_REP or KRB5_KDC_REP */ + krb5_pa_data **padata; /**< Preauthentication data from KDC */ + krb5_principal client; /**< Client principal and realm */ + krb5_ticket *ticket; /**< Ticket */ + krb5_enc_data enc_part; /**< Encrypted part of reply */ + krb5_enc_kdc_rep_part *enc_part2; /**< Unencrypted version, if available */ +} krb5_kdc_rep; + +/** Error message structure */ +typedef struct _krb5_error { + krb5_magic magic; + /* some of these may be meaningless in certain contexts */ + krb5_timestamp ctime; /**< Client sec portion; optional */ + krb5_int32 cusec; /**< Client usec portion; optional */ + krb5_int32 susec; /**< Server usec portion */ + krb5_timestamp stime; /**< Server sec portion */ + krb5_ui_4 error; /**< Error code (protocol error #'s) */ + krb5_principal client; /**< Client principal and realm */ + krb5_principal server; /**< Server principal and realm */ + krb5_data text; /**< Descriptive text */ + krb5_data e_data; /**< Additional error-describing data */ +} krb5_error; + +/** Authentication header. */ +typedef struct _krb5_ap_req { + krb5_magic magic; + krb5_flags ap_options; /**< Requested options */ + krb5_ticket *ticket; /**< Ticket */ + krb5_enc_data authenticator; /**< Encrypted authenticator */ +} krb5_ap_req; + +/** + * C representaton of AP-REP message. + * + * The server's response to a client's request for mutual authentication. + */ +typedef struct _krb5_ap_rep { + krb5_magic magic; + krb5_enc_data enc_part; /**< Ciphertext of ApRepEncPart */ +} krb5_ap_rep; + +/** Cleartext that is encrypted and put into @c _krb5_ap_rep. */ +typedef struct _krb5_ap_rep_enc_part { + krb5_magic magic; + krb5_timestamp ctime; /**< Client time, seconds portion */ + krb5_int32 cusec; /**< Client time, microseconds portion */ + krb5_keyblock *subkey; /**< Subkey (optional) */ + krb5_ui_4 seq_number; /**< Sequence number */ +} krb5_ap_rep_enc_part; + +/* Unused */ +typedef struct _krb5_response { + krb5_magic magic; + krb5_octet message_type; + krb5_data response; + krb5_int32 expected_nonce; + krb5_timestamp request_time; +} krb5_response; + +/** Credentials information inserted into @c EncKrbCredPart. */ +typedef struct _krb5_cred_info { + krb5_magic magic; + krb5_keyblock *session; /**< Session key used to encrypt ticket */ + krb5_principal client; /**< Client principal and realm */ + krb5_principal server; /**< Server principal and realm */ + krb5_flags flags; /**< Ticket flags */ + krb5_ticket_times times; /**< Auth, start, end, renew_till */ + krb5_address **caddrs; /**< Array of pointers to addrs (optional) */ +} krb5_cred_info; + +/** Cleartext credentials information. */ +typedef struct _krb5_cred_enc_part { + krb5_magic magic; + krb5_int32 nonce; /**< Nonce (optional) */ + krb5_timestamp timestamp; /**< Generation time, seconds portion */ + krb5_int32 usec; /**< Generation time, microseconds portion */ + krb5_address *s_address; /**< Sender address (optional) */ + krb5_address *r_address; /**< Recipient address (optional) */ + krb5_cred_info **ticket_info; +} krb5_cred_enc_part; + +/** Credentials data structure.*/ +typedef struct _krb5_cred { + krb5_magic magic; + krb5_ticket **tickets; /**< Tickets */ + krb5_enc_data enc_part; /**< Encrypted part */ + krb5_cred_enc_part *enc_part2; /**< Unencrypted version, if available */ +} krb5_cred; + +/* Unused, but here for API compatibility. */ +typedef struct _passwd_phrase_element { + krb5_magic magic; + krb5_data *passwd; + krb5_data *phrase; +} passwd_phrase_element; + +/* Unused, but here for API compatibility. */ +typedef struct _krb5_pwd_data { + krb5_magic magic; + int sequence_count; + passwd_phrase_element **element; +} krb5_pwd_data; + +/* Unused, but here for API compatibility. */ +typedef struct _krb5_pa_svr_referral_data { + /** Referred name, only realm is required */ + krb5_principal principal; +} krb5_pa_svr_referral_data; + +/* Unused, but here for API compatibility. */ +typedef struct _krb5_pa_server_referral_data { + krb5_data *referred_realm; + krb5_principal true_principal_name; + krb5_principal requested_principal_name; + krb5_timestamp referral_valid_until; + krb5_checksum rep_cksum; +} krb5_pa_server_referral_data; + +typedef struct _krb5_pa_pac_req { + /** TRUE if a PAC should be included in TGS-REP */ + krb5_boolean include_pac; +} krb5_pa_pac_req; + +/* + * begin "safepriv.h" + */ + +/** @defgroup KRB5_AUTH_CONTEXT KRB5_AUTH_CONTEXT + * @{ + */ +/** Prevent replays with timestamps and replay cache. */ +#define KRB5_AUTH_CONTEXT_DO_TIME 0x00000001 +/** Save timestamps for application. */ +#define KRB5_AUTH_CONTEXT_RET_TIME 0x00000002 +/** Prevent replays with sequence numbers. */ +#define KRB5_AUTH_CONTEXT_DO_SEQUENCE 0x00000004 +/** Save sequence numbers for application. */ +#define KRB5_AUTH_CONTEXT_RET_SEQUENCE 0x00000008 +#define KRB5_AUTH_CONTEXT_PERMIT_ALL 0x00000010 +#define KRB5_AUTH_CONTEXT_USE_SUBKEY 0x00000020 +/** @} */ /* end of KRB5_AUTH_CONTEXT group */ + +/** + * Replay data. + * + * Sequence number and timestamp information output by krb5_rd_priv() and + * krb5_rd_safe(). + */ +typedef struct krb5_replay_data { + krb5_timestamp timestamp; /**< Timestamp, seconds portion */ + krb5_int32 usec; /**< Timestamp, microseconds portion */ + krb5_ui_4 seq; /**< Sequence number */ +} krb5_replay_data; + +/* Flags for krb5_auth_con_genaddrs(). */ + +/** Generate the local network address. */ +#define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR 0x00000001 +/** Generate the remote network address. */ +#define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR 0x00000002 +/** Generate the local network address and the local port. */ +#define KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR 0x00000004 +/** Generate the remote network address and the remote port. */ +#define KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR 0x00000008 + +/** Type of function used as a callback to generate checksum data for mk_req */ +typedef krb5_error_code +(KRB5_CALLCONV * krb5_mk_req_checksum_func)(krb5_context, krb5_auth_context, + void *, krb5_data **); + +/* + * end "safepriv.h" + */ + + +/* + * begin "ccache.h" + */ + +/** Cursor for sequential lookup */ +typedef krb5_pointer krb5_cc_cursor; + +struct _krb5_ccache; +typedef struct _krb5_ccache *krb5_ccache; +struct _krb5_cc_ops; +typedef struct _krb5_cc_ops krb5_cc_ops; + +struct _krb5_cccol_cursor; +/** Cursor for iterating over all ccaches */ +typedef struct _krb5_cccol_cursor *krb5_cccol_cursor; + +/* Flags for krb5_cc_retrieve_cred. */ +/** The requested lifetime must be at least as great as the time specified. */ +#define KRB5_TC_MATCH_TIMES 0x00000001 +/** The is_skey field must match exactly. */ +#define KRB5_TC_MATCH_IS_SKEY 0x00000002 +/** All the flags set in the match credentials must be set. */ +#define KRB5_TC_MATCH_FLAGS 0x00000004 +/** All the time fields must match exactly. */ +#define KRB5_TC_MATCH_TIMES_EXACT 0x00000008 +/** All the flags must match exactly. */ +#define KRB5_TC_MATCH_FLAGS_EXACT 0x00000010 +/** The authorization data must match. */ +#define KRB5_TC_MATCH_AUTHDATA 0x00000020 +/** Only the name portion of the principal name must match. */ +#define KRB5_TC_MATCH_SRV_NAMEONLY 0x00000040 +/** The second ticket must match. */ +#define KRB5_TC_MATCH_2ND_TKT 0x00000080 +/** The encryption key type must match. */ +#define KRB5_TC_MATCH_KTYPE 0x00000100 +/** The supported key types must match. */ +#define KRB5_TC_SUPPORTED_KTYPES 0x00000200 + +/* Flags for krb5_cc_set_flags and similar. */ +/** Open and close the file for each cache operation. */ +#define KRB5_TC_OPENCLOSE 0x00000001 /**< @deprecated has no effect */ +#define KRB5_TC_NOTICKET 0x00000002 + +/** + * Retrieve the name, but not type of a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * + * @warning Returns the name of the credential cache. The result is an alias + * into @a cache and should not be freed or modified by the caller. This name + * does not include the cache type, so should not be used as input to + * krb5_cc_resolve(). + * + * @return + * On success - the name of the credential cache. + */ +const char * KRB5_CALLCONV +krb5_cc_get_name(krb5_context context, krb5_ccache cache); + +/** + * Retrieve the full name of a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [out] fullname_out Full name of cache + * + * Use krb5_free_string() to free @a fullname_out when it is no longer needed. + * + * @version New in 1.10 + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_get_full_name(krb5_context context, krb5_ccache cache, + char **fullname_out); + +#if KRB5_DEPRECATED +krb5_error_code KRB5_CALLCONV +krb5_cc_gen_new(krb5_context context, krb5_ccache *cache); +#endif /* KRB5_DEPRECATED */ + +/** + * Initialize a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] principal Default principal name + * + * Destroy any existing contents of @a cache and initialize it for the default + * principal @a principal. + * + * @retval + * 0 Success + * @return + * System errors; Permission errors; Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_initialize(krb5_context context, krb5_ccache cache, + krb5_principal principal); + +/** + * Destroy a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * + * This function destroys any existing contents of @a cache and closes the + * handle to it. + * + * @retval + * 0 Success + * @return + * Permission errors + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_destroy(krb5_context context, krb5_ccache cache); + +/** + * Close a credential cache handle. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * + * This function closes a credential cache handle @a cache without affecting + * the contents of the cache. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_close(krb5_context context, krb5_ccache cache); + +/** + * Store credentials in a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] creds Credentials to be stored in cache + * + * This function stores @a creds into @a cache. If @a creds->server and the + * server in the decoded ticket @a creds->ticket differ, the credentials will + * be stored under both server principal names. + * + * @retval + * 0 Success + * @return Permission errors; storage failure errors; Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_store_cred(krb5_context context, krb5_ccache cache, krb5_creds *creds); + +/** + * Retrieve a specified credentials from a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] flags Flags bit mask + * @param [in] mcreds Credentials to match + * @param [out] creds Credentials matching the requested value + * + * This function searches a credential cache for credentials matching @a mcreds + * and returns it if found. + * + * Valid values for @a flags are: + * + * @li #KRB5_TC_MATCH_TIMES The requested lifetime must be at least as + * great as in @a mcreds . + * @li #KRB5_TC_MATCH_IS_SKEY The @a is_skey field much match exactly. + * @li #KRB5_TC_MATCH_FLAGS Flags set in @a mcreds must be set. + * @li #KRB5_TC_MATCH_TIMES_EXACT The requested lifetime must match exactly. + * @li #KRB5_TC_MATCH_FLAGS_EXACT Flags must match exactly. + * @li #KRB5_TC_MATCH_AUTHDATA The authorization data must match. + * @li #KRB5_TC_MATCH_SRV_NAMEONLY Only the name portion of the principal + * name must match, not the realm. + * @li #KRB5_TC_MATCH_2ND_TKT The second tickets must match. + * @li #KRB5_TC_MATCH_KTYPE The encryption key types must match. + * @li #KRB5_TC_SUPPORTED_KTYPES Check all matching entries that have any + * supported encryption type and return the + * one with the encryption type listed earliest. + * + * Use krb5_free_cred_contents() to free @a creds when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_retrieve_cred(krb5_context context, krb5_ccache cache, + krb5_flags flags, krb5_creds *mcreds, + krb5_creds *creds); + +/** + * Get the default principal of a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [out] principal Primary principal + * + * Returns the default client principal of a credential cache as set by + * krb5_cc_initialize(). + * + * Use krb5_free_principal() to free @a principal when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_get_principal(krb5_context context, krb5_ccache cache, + krb5_principal *principal); + +/** + * Prepare to sequentially read every credential in a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [out] cursor Cursor + * + * krb5_cc_end_seq_get() must be called to complete the retrieve operation. + * + * @note If @a cache is modified between the time of the call to this function + * and the time of the final krb5_cc_end_seq_get(), the results are undefined. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_start_seq_get(krb5_context context, krb5_ccache cache, + krb5_cc_cursor *cursor); + +/** + * Retrieve the next entry from the credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] cursor Cursor + * @param [out] creds Next credential cache entry + * + * This function fills in @a creds with the next entry in @a cache and advances + * @a cursor. + * + * Use krb5_free_cred_contents() to free @a creds when it is no longer needed. + * + * @sa krb5_cc_start_seq_get(), krb5_end_seq_get() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_next_cred(krb5_context context, krb5_ccache cache, + krb5_cc_cursor *cursor, krb5_creds *creds); + +/** + * Finish a series of sequential processing credential cache entries. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] cursor Cursor + * + * This function finishes processing credential cache entries and invalidates + * @a cursor. + * + * @sa krb5_cc_start_seq_get(), krb5_cc_next_cred() + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_end_seq_get(krb5_context context, krb5_ccache cache, + krb5_cc_cursor *cursor); + +/** + * Remove credentials from a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] flags Bitwise-ORed search flags + * @param [in] creds Credentials to be matched + * + * @warning This function is not implemented for some cache types. + * + * This function accepts the same flag values as krb5_cc_retrieve_cred(). + * + * @retval KRB5_CC_NOSUPP Not implemented for this cache type + * @return No matches found; Data cannot be deleted; Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_remove_cred(krb5_context context, krb5_ccache cache, krb5_flags flags, + krb5_creds *creds); + +/** + * Set options flags on a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [in] flags Flag bit mask + * + * This function resets @a cache flags to @a flags. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_set_flags(krb5_context context, krb5_ccache cache, krb5_flags flags); + +/** + * Retrieve flags from a credential cache structure. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * @param [out] flags Flag bit mask + * + * @warning For memory credential cache always returns a flag mask of 0. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_get_flags(krb5_context context, krb5_ccache cache, krb5_flags *flags); + +/** + * Retrieve the type of a credential cache. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * + * @return The type of a credential cache as an alias that must not be modified + * or freed by the caller. + */ +const char * KRB5_CALLCONV +krb5_cc_get_type(krb5_context context, krb5_ccache cache); + +/** + * Move a credential cache. + * + * @param [in] context Library context + * @param [in] src The credential cache to move the content from + * @param [in] dst The credential cache to move the content to + * + * This function reinitializes @a dst and populates it with the credentials and + * default principal of @a src; then, if successful, destroys @a src. + * + * @retval + * 0 Success; @a src is closed. + * @return + * Kerberos error codes; @a src is still allocated. + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_move(krb5_context context, krb5_ccache src, krb5_ccache dst); + +/** + * Return a timestamp of the last modification to a credential cache. + * + * @param [in] context Library context + * @param [in] ccache Credential cache handle + * @param [out] change_time The last change time of @a ccache + * + * If an error occurs, @a change_time is set to 0. + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_last_change_time(krb5_context context, krb5_ccache ccache, + krb5_timestamp *change_time); + +/** + * Lock a credential cache. + * + * @param [in] context Library context + * @param [in] ccache Credential cache handle + * + * Use krb5_cc_unlock() to unlock the lock. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_lock(krb5_context context, krb5_ccache ccache); + +/** + * Unlock a credential cache. + * + * @param [in] context Library context + * @param [in] ccache Credential cache handle + * + * This function unlocks the @a ccache locked by krb5_cc_lock(). + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_unlock(krb5_context context, krb5_ccache ccache); + +/** + * Prepare to iterate over the collection of known credential caches. + * + * @param [in] context Library context + * @param [out] cursor Cursor + * + * Get a new cache iteration @a cursor that will iterate over all known + * credential caches independent of type. + * + * Use krb5_cccol_cursor_free() to release @a cursor when it is no longer + * needed. + * + * @sa krb5_cccol_cursor_next() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_cursor_new(krb5_context context, krb5_cccol_cursor *cursor); + +/** + * Get the next credential cache in the collection. + * + * @param [in] context Library context + * @param [in] cursor Cursor + * @param [out] ccache Credential cache handle + * + * @note When all caches are iterated over and the end of the list is reached, + * @a ccache is set to NULL. + * + * Use krb5_cc_close() to close @a ccache when it is no longer needed. + * + * @sa krb5_cccol_cursor_new(), krb5_cccol_cursor_free() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_cursor_next(krb5_context context, krb5_cccol_cursor cursor, + krb5_ccache *ccache); + +/** + * Free a credential cache collection cursor. + * + * @param [in] context Library context + * @param [in] cursor Cursor + * + * @sa krb5_cccol_cursor_new(), krb5_cccol_cursor_next() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_cursor_free(krb5_context context, krb5_cccol_cursor *cursor); + +/** + * Check if the credential cache collection contains any credentials. + * + * @param [in] context Library context + * + * @version New in 1.11 + * + * @retval 0 Credentials are available in the collection + * @retval KRB5_CC_NOTFOUND The collection contains no credentials + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_have_content(krb5_context context); + +/** + * Return a timestamp of the last modification of any known credential cache. + * + * @param [in] context Library context + * @param [out] change_time Last modification timestamp + * + * This function returns the most recent modification time of any known + * credential cache, ignoring any caches which cannot supply a last + * modification time. + * + * If there are no known credential caches, @a change_time is set to 0. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_last_change_time(krb5_context context, krb5_timestamp *change_time); + +/** + * Acquire a global lock for credential caches. + * + * @param [in] context Library context + * + * This function locks the global credential cache collection, ensuring + * that no ccaches are added to or removed from it until the collection + * lock is released. + * + * Use krb5_cccol_unlock() to unlock the lock. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ + +krb5_error_code KRB5_CALLCONV +krb5_cccol_lock(krb5_context context); + +/** + * Release a global lock for credential caches. + * + * @param [in] context Library context + * + * This function unlocks the lock from krb5_cccol_lock(). + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cccol_unlock(krb5_context context); + +/** + * Create a new credential cache of the specified type with a unique name. + * + * @param [in] context Library context + * @param [in] type Credential cache type name + * @param [in] hint Unused + * @param [out] id Credential cache handle + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_new_unique(krb5_context context, const char *type, const char *hint, + krb5_ccache *id); + +/* + * end "ccache.h" + */ + +/* + * begin "rcache.h" + */ + +struct krb5_rc_st; +typedef struct krb5_rc_st *krb5_rcache; + +/* + * end "rcache.h" + */ + +/* + * begin "keytab.h" + */ + + +/* XXX */ +#define MAX_KEYTAB_NAME_LEN 1100 /**< Long enough for MAXPATHLEN + some extra */ + +typedef krb5_pointer krb5_kt_cursor; + +/** A key table entry. */ +typedef struct krb5_keytab_entry_st { + krb5_magic magic; + krb5_principal principal; /**< Principal of this key */ + krb5_timestamp timestamp; /**< Time entry written to keytable */ + krb5_kvno vno; /**< Key version number */ + krb5_keyblock key; /**< The secret key */ +} krb5_keytab_entry; + +struct _krb5_kt; +typedef struct _krb5_kt *krb5_keytab; + +/** + * Return the type of a key table. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * + * @return The type of a key table as an alias that must not be modified or + * freed by the caller. + */ +const char * KRB5_CALLCONV +krb5_kt_get_type(krb5_context context, krb5_keytab keytab); + +/** + * Get a key table name. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * @param [out] name Key table name + * @param [in] namelen Maximum length to fill in name + * + * Fill @a name with the name of @a keytab including the type and delimiter. + * + * @sa MAX_KEYTAB_NAME_LEN + * + * @retval + * 0 Success + * @retval + * KRB5_KT_NAME_TOOLONG Key table name does not fit in @a namelen bytes + * + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name, + unsigned int namelen); + +/** + * Close a key table handle. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * + * @retval 0 + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_close(krb5_context context, krb5_keytab keytab); + +/** + * Get an entry from a key table. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * @param [in] principal Principal name + * @param [in] vno Key version number (0 for highest available) + * @param [in] enctype Encryption type (0 zero for any enctype) + * @param [out] entry Returned entry from key table + * + * Retrieve an entry from a key table which matches the @a keytab, @a + * principal, @a vno, and @a enctype. If @a vno is zero, retrieve the + * highest-numbered kvno matching the other fields. If @a enctype is 0, match + * any enctype. + * + * Use krb5_free_keytab_entry_contents() to free @a entry when it is no longer + * needed. + * + * @note If @a vno is zero, the function retrieves the highest-numbered-kvno + * entry that matches the specified principal. + * + * @retval + * 0 Success + * @retval + * Kerberos error codes on failure + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_get_entry(krb5_context context, krb5_keytab keytab, + krb5_const_principal principal, krb5_kvno vno, + krb5_enctype enctype, krb5_keytab_entry *entry); + +/** + * Start a sequential retrieval of key table entries. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * @param [out] cursor Cursor + * + * Prepare to read sequentially every key in the specified key table. Use + * krb5_kt_end_seq_get() to release the cursor when it is no longer needed. + * + * @sa krb5_kt_next_entry(), krb5_kt_end_seq_get() + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor); + +/** + * Retrieve the next entry from the key table. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * @param [out] entry Returned key table entry + * @param [in] cursor Key table cursor + * + * Return the next sequential entry in @a keytab and advance @a cursor. + * Callers must release the returned entry with krb5_kt_free_entry(). + * + * @sa krb5_kt_start_seq_get(), krb5_kt_end_seq_get() + * + * @retval + * 0 Success + * @retval + * KRB5_KT_END - if the last entry was reached + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_next_entry(krb5_context context, krb5_keytab keytab, + krb5_keytab_entry *entry, krb5_kt_cursor *cursor); + +/** + * Release a keytab cursor. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * @param [out] cursor Cursor + * + * This function should be called to release the cursor created by + * krb5_kt_start_seq_get(). + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor); + +/** + * Check if a keytab exists and contains entries. + * + * @param [in] context Library context + * @param [in] keytab Key table handle + * + * @version New in 1.11 + * + * @retval 0 Keytab exists and contains entries + * @retval KRB5_KT_NOTFOUND Keytab does not contain entries + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_have_content(krb5_context context, krb5_keytab keytab); + +/* + * end "keytab.h" + */ + +/* + * begin "func-proto.h" + */ + +#define KRB5_INIT_CONTEXT_SECURE 0x1 /**< Use secure context configuration */ +#define KRB5_INIT_CONTEXT_KDC 0x2 /**< Use KDC configuration if available */ + +extern void KRB5_CALLCONV krb5_set_profile_path(char *profile_path); +extern void KRB5_CALLCONV krb5_set_cache_path(char *cache_path); +extern void KRB5_CALLCONV krb5_clean_cache_profile_path(); + +/** + * Create a krb5 library context. + * + * @param [out] context Library context + * + * The @a context must be released by calling krb5_free_context() when + * it is no longer needed. + * + * @warning Any program or module that needs the Kerberos code to not trust the + * environment must use krb5_init_secure_context(), or clean out the + * environment. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_context(krb5_context *context); + +/** + * Create a krb5 library context using only configuration files. + * + * @param [out] context Library context + * + * Create a context structure, using only system configuration files. All + * information passed through the environment variables is ignored. + * + * The @a context must be released by calling krb5_free_context() when + * it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_secure_context(krb5_context *context); + +/** + * Create a krb5 library context using a specified profile. + * + * @param [in] profile Profile object (NULL to create default profile) + * @param [in] flags Context initialization flags + * @param [out] context Library context + * + * Create a context structure, optionally using a specified profile and + * initialization flags. If @a profile is NULL, the default profile will be + * created from config files. If @a profile is non-null, a copy of it will be + * made for the new context; the caller should still clean up its copy. Valid + * flag values are: + * + * @li #KRB5_INIT_CONTEXT_SECURE Ignore environment variables + * @li #KRB5_INIT_CONTEXT_KDC Use KDC configuration if creating profile + */ +krb5_error_code KRB5_CALLCONV +krb5_init_context_profile(struct _profile_t *profile, krb5_flags flags, + krb5_context *context); + +/** + * Free a krb5 library context. + * + * @param [in] context Library context + * + * This function frees a @a context that was created by krb5_init_context() + * or krb5_init_secure_context(). + */ +void KRB5_CALLCONV +krb5_free_context(krb5_context context); + +/** + * Copy a krb5_context structure. + * + * @param [in] ctx Library context + * @param [out] nctx_out New context structure + * + * The newly created context must be released by calling krb5_free_context() + * when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_context(krb5_context ctx, krb5_context *nctx_out); + +/** + * Set default TGS encryption types in a krb5_context structure. + * + * @param [in] context Library context + * @param [in] etypes Encryption type(s) to set + * + * This function sets the default enctype list for TGS requests + * made using @a context to @a etypes. + * + * @note This overrides the default list (from config file or built-in). + * + * @retval + * 0 Success + * @retval + * KRB5_PROG_ETYPE_NOSUPP Program lacks support for encryption type + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_set_default_tgs_enctypes(krb5_context context, const krb5_enctype *etypes); + +/** + * Return a list of encryption types permitted for session keys. + * + * @param [in] context Library context + * @param [out] ktypes Zero-terminated list of encryption types + * + * This function returns the list of encryption types permitted for session + * keys within @a context, as determined by configuration or by a previous call + * to krb5_set_default_tgs_enctypes(). + * + * Use krb5_free_enctypes() to free @a ktypes when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_permitted_enctypes(krb5_context context, krb5_enctype **ktypes); + +/** + * Test whether the Kerberos library was built with multithread support. + * + * @retval + * TRUE if the library is threadsafe; FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_is_thread_safe(void); + +/* libkrb.spec */ + +/** + * Decrypt a ticket using the specified key table. + * + * @param [in] context Library context + * @param [in] kt Key table + * @param [in] ticket Ticket to be decrypted + * + * This function takes a @a ticket as input and decrypts it using + * key data from @a kt. The result is placed into @a ticket->enc_part2. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_server_decrypt_ticket_keytab(krb5_context context, const krb5_keytab kt, + krb5_ticket *ticket); + +/** + * Free an array of credential structures. + * + * @param [in] context Library context + * @param [in] tgts Null-terminated array of credentials to free + * + * @note The last entry in the array @a tgts must be a NULL pointer. + */ +void KRB5_CALLCONV +krb5_free_tgt_creds(krb5_context context, krb5_creds **tgts); + +/** @defgroup KRB5_GC KRB5_GC + * @{ + */ +#define KRB5_GC_USER_USER 1 /**< Want user-user ticket */ +#define KRB5_GC_CACHED 2 /**< Want cached ticket only */ +#define KRB5_GC_CANONICALIZE 4 /**< Set canonicalize KDC option */ +#define KRB5_GC_NO_STORE 8 /**< Do not store in credential cache */ +#define KRB5_GC_FORWARDABLE 16 /**< Acquire forwardable tickets */ +#define KRB5_GC_NO_TRANSIT_CHECK 32 /**< Disable transited check */ +#define KRB5_GC_CONSTRAINED_DELEGATION 64 /**< Constrained delegation */ +/** @} */ /* end of KRB5_GC group */ + +/** + * Get an additional ticket. + * + * @param [in] context Library context + * @param [in] options Options + * @param [in] ccache Credential cache handle + * @param [in] in_creds Input credentials + * @param [out] out_creds Output updated credentials + * + * Use @a ccache or a TGS exchange to get a service ticket matching @a + * in_creds. + * + * Valid values for @a options are: + * @li #KRB5_GC_CACHED Search only credential cache for the ticket + * @li #KRB5_GC_USER_USER Return a user to user authentication ticket + * + * @a in_creds must be non-null. @a in_creds->client and @a in_creds->server + * must be filled in to specify the client and the server respectively. If any + * authorization data needs to be requested for the service ticket (such as + * restrictions on how the ticket can be used), specify it in @a + * in_creds->authdata; otherwise set @a in_creds->authdata to NULL. The + * session key type is specified in @a in_creds->keyblock.enctype, if it is + * nonzero. + * + * The expiration date is specified in @a in_creds->times.endtime. + * The KDC may return tickets with an earlier expiration date. + * If @a in_creds->times.endtime is set to 0, the latest possible + * expiration date will be requested. + * + * Any returned ticket and intermediate ticket-granting tickets are stored + * in @a ccache. + * + * Use krb5_free_creds() to free @a out_creds when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_credentials(krb5_context context, krb5_flags options, + krb5_ccache ccache, krb5_creds *in_creds, + krb5_creds **out_creds); + +/** @deprecated Replaced by krb5_get_validated_creds. */ +krb5_error_code KRB5_CALLCONV +krb5_get_credentials_validate(krb5_context context, krb5_flags options, + krb5_ccache ccache, krb5_creds *in_creds, + krb5_creds **out_creds); + +/** @deprecated Replaced by krb5_get_renewed_creds. */ +krb5_error_code KRB5_CALLCONV +krb5_get_credentials_renew(krb5_context context, krb5_flags options, + krb5_ccache ccache, krb5_creds *in_creds, + krb5_creds **out_creds); + +/** + * Create a @c KRB_AP_REQ message. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] ap_req_options @ref AP_OPTS options + * @param [in] service Service name, or NULL to use @c "host" + * @param [in] hostname Host name, or NULL to use local hostname + * @param [in] in_data Application data to be checksummed in the + * authenticator, or NULL + * @param [in] ccache Credential cache used to obtain credentials + * for the desired service. + * @param [out] outbuf @c AP-REQ message + * + * This function is similar to krb5_mk_req_extended() except that it uses a + * given @a hostname, @a service, and @a ccache to construct a service + * principal name and obtain credentials. + * + * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_req(krb5_context context, krb5_auth_context *auth_context, + krb5_flags ap_req_options, const char *service, + const char *hostname, krb5_data *in_data, krb5_ccache ccache, + krb5_data *outbuf); + +/** + * Create a @c KRB_AP_REQ message using supplied credentials. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] ap_req_options @ref AP_OPTS options + * @param [in] in_data Application data to be checksummed in the + * authenticator, or NULL + * @param [in] in_creds Credentials for the service with valid ticket + * and key + * @param [out] outbuf @c AP-REQ message + * + * Valid @a ap_req_options are: + * @li #AP_OPTS_USE_SESSION_KEY - Use the session key when creating the + * request used for user to user + * authentication. + * @li #AP_OPTS_MUTUAL_REQUIRED - Request a mutual authentication packet from + * the reciever. + * @li #AP_OPTS_USE_SUBKEY - Generate a subsession key from the current + * session key obtained from the credentials. + * + * This function creates a KRB_AP_REQ message using supplied credentials @a + * in_creds. @a auth_context may point to an existing auth context or to NULL, + * in which case a new one will be created. If @a in_data is non-null, a + * checksum of it will be included in the authenticator contained in the + * KRB_AP_REQ message. Use krb5_free_data_contents() to free @a outbuf when it + * is no longer needed. + * + * On successful return, the authenticator is stored in @a auth_context with + * the @a client and @a checksum fields nulled out. (This is to prevent + * pointer-sharing problems; the caller should not need these fields anyway, + * since the caller supplied them.) + * + * @sa krb5_mk_req() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_req_extended(krb5_context context, krb5_auth_context *auth_context, + krb5_flags ap_req_options, krb5_data *in_data, + krb5_creds *in_creds, krb5_data *outbuf); + +/** + * Format and encrypt a @c KRB_AP_REP message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] outbuf @c AP-REP message + * + * This function fills in @a outbuf with an AP-REP message using information + * from @a auth_context. + * + * If the flags in @a auth_context indicate that a sequence number should be + * used (either #KRB5_AUTH_CONTEXT_DO_SEQUENCE or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE) and the local sequence number in @a + * auth_context is 0, a new number will be generated with + * krb5_generate_seq_number(). + * + * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_rep(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf); + +/** + * Format and encrypt a @c KRB_AP_REP message for DCE RPC. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] outbuf @c AP-REP message + * + * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_rep_dce(krb5_context context, krb5_auth_context auth_context, krb5_data *outbuf); + +/** + * Parse and decrypt a @c KRB_AP_REP message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] inbuf AP-REP message + * @param [out] repl Decrypted reply message + * + * This function parses, decrypts and verifies a message from @a inbuf and + * fills in @a repl with a pointer to allocated memory containing the fields + * from the encrypted response. + * + * Use krb5_free_ap_rep_enc_part() to free @a repl when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_rep(krb5_context context, krb5_auth_context auth_context, + const krb5_data *inbuf, krb5_ap_rep_enc_part **repl); + +/** + * Parse and decrypt a @c KRB_AP_REP message for DCE RPC. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] inbuf AP-REP message + * @param [out] nonce Sequence number from the decrypted reply + * + * This function parses, decrypts and verifies a message from @a inbuf and + * fills in @a nonce with a decrypted reply sequence number. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_rep_dce(krb5_context context, krb5_auth_context auth_context, + const krb5_data *inbuf, krb5_ui_4 *nonce); + +/** + * Format and encode a @c KRB_ERROR message. + * + * @param [in] context Library context + * @param [in] dec_err Error structure to be encoded + * @param [out] enc_err Encoded error structure + * + * This function creates a @c KRB_ERROR message in @a enc_err. Use + * krb5_free_data_contents() to free @a enc_err when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_error(krb5_context context, const krb5_error *dec_err, + krb5_data *enc_err); + +/** + * Decode a @c KRB-ERROR message. + * + * @param [in] context Library context + * @param [in] enc_errbuf Encoded error message + * @param [out] dec_error Decoded error message + * + * This function processes @c KRB-ERROR message @a enc_errbuf and returns + * an allocated structure @a dec_error containing the error message. + * Use krb5_free_error() to free @a dec_error when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_error(krb5_context context, const krb5_data *enc_errbuf, + krb5_error **dec_error); + +/** + * Process @c KRB-SAFE message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] inbuf @c KRB-SAFE message to be parsed + * @param [out] outbuf Data parsed from @c KRB-SAFE message + * @param [out] outdata Replay data. Specify NULL if not needed + * + * This function parses a @c KRB-SAFE message, verifies its integrity, and + * stores its data into @a outbuf. + * + * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context. + * + * @note @a auth_context must have a remote address set. This address will be + * used to verify the sender address in the KRB-SAFE message. If @a + * auth_context has a local address set, it will be used to verify the + * receiver address in the KRB-SAFE message if the message contains one. + * Both addresses must use type @c ADDRTYPE_ADDRPORT. + * + * If the #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag is set in @a auth_context, the + * sequence number of the KRB-SAFE message is checked against the remote + * sequence number field of @a auth_context. Otherwise, the sequence number is + * not used. + * + * If the #KRB5_AUTH_CONTEXT_DO_TIME flag is set in @a auth_context, + * then two additional checks are performed: + * @li The timestamp in the message must be within the permitted clock skew + * (which is usually five minutes). + * @li The message must not be a replayed message field in @a auth_context. + * + * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_safe(krb5_context context, krb5_auth_context auth_context, + const krb5_data *inbuf, krb5_data *outbuf, + krb5_replay_data *outdata); + +/** + * Process a @c KRB-PRIV message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication structure + * @param [in] inbuf @c KRB-PRIV message to be parsed + * @param [out] outbuf Data parsed from @c KRB-PRIV message + * @param [out] outdata Replay data. Specify NULL if not needed + * + * This function parses a @c KRB-PRIV message, verifies its integrity, and + * stores its unencrypted data into @a outbuf. + * + * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in @a auth_context, @a + * outdata is required. + * + * @note @a auth_context must have a remote address set. This address will be + * used to verify the sender address in the KRB-PRIV message. If @a + * auth_context has a local address set, it will be used to verify the + * receiver address in the KRB-PRIV message if the message contains one. + * Both addresses must use type @c ADDRTYPE_ADDRPORT. + * + * If the #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag is set in @a auth_context, the + * sequence number of the KRB-SAFE message is checked against the remote + * sequence number field of @a auth_context. Otherwise, the sequence number is + * not used. + * + * If the #KRB5_AUTH_CONTEXT_DO_TIME flag is set in @a auth_context, + * then two additional checks are performed: + * @li The timestamp in the message must be within the permitted clock skew + * (which is usually five minutes). + * @li The message must not be a replayed message field in @a auth_context. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_priv(krb5_context context, krb5_auth_context auth_context, + const krb5_data *inbuf, krb5_data *outbuf, + krb5_replay_data *outdata); + +/** + * Convert a string principal name to a krb5_principal structure. + * + * @param [in] context Library context + * @param [in] name String representation of a principal name + * @param [out] principal_out New principal + * + * Convert a string representation of a principal name to a krb5_principal + * structure. + * + * A string representation of a Kerberos name consists of one or more principal + * name components, separated by slashes, optionally followed by the \@ + * character and a realm name. If the realm name is not specified, the local + * realm is used. + * + * To use the slash and \@ symbols as part of a component (quoted) instead of + * using them as a component separator or as a realm prefix), put a backslash + * (\) character in front of the symbol. Similarly, newline, tab, backspace, + * and NULL characters can be included in a component by using @c n, @c t, @c b + * or @c 0, respectively. + * + * @note The realm in a Kerberos @a name cannot contain slash, colon, + * or NULL characters. + * + * Use krb5_free_principal() to free @a principal_out when it is no longer + * needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_parse_name(krb5_context context, const char *name, + krb5_principal *principal_out); + +#define KRB5_PRINCIPAL_PARSE_NO_REALM 0x1 /**< Error if realm is present */ +#define KRB5_PRINCIPAL_PARSE_REQUIRE_REALM 0x2 /**< Error if realm is not present */ +#define KRB5_PRINCIPAL_PARSE_ENTERPRISE 0x4 /**< Create single-component + enterprise principle */ +#define KRB5_PRINCIPAL_PARSE_IGNORE_REALM 0x8 /**< Ignore realm if present */ + +/** + * Convert a string principal name to a krb5_principal with flags. + * + * @param [in] context Library context + * @param [in] name String representation of a principal name + * @param [in] flags Flag + * @param [out] principal_out New principal + * + * Similar to krb5_parse_name(), this function converts a single-string + * representation of a principal name to a krb5_principal structure. + * + * The following flags are valid: + * @li #KRB5_PRINCIPAL_PARSE_NO_REALM - no realm must be present in @a name + * @li #KRB5_PRINCIPAL_PARSE_REQUIRE_REALM - realm must be present in @a name + * @li #KRB5_PRINCIPAL_PARSE_ENTERPRISE - create single-component enterprise + * principal + * @li #KRB5_PRINCIPAL_PARSE_IGNORE_REALM - ignore realm if present in @a name + * + * If @c KRB5_PRINCIPAL_PARSE_NO_REALM or @c KRB5_PRINCIPAL_PARSE_IGNORE_REALM + * is specified in @a flags, the realm of the new principal will be empty. + * Otherwise, the default realm for @a context will be used if @a name does not + * specify a realm. + * + * Use krb5_free_principal() to free @a principal_out when it is no longer + * needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_parse_name_flags(krb5_context context, const char *name, + int flags, krb5_principal *principal_out); + +/** + * Convert a krb5_principal structure to a string representation. + * + * @param [in] context Library context + * @param [in] principal Principal + * @param [out] name String representation of principal name + * + * The resulting string representation uses the format and quoting conventions + * described for krb5_parse_name(). + * + * Use krb5_free_unparsed_name() to free @a name when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_unparse_name(krb5_context context, krb5_const_principal principal, + char **name); + +/** + * Convert krb5_principal structure to string and length. + * + * @param [in] context Library context + * @param [in] principal Principal + * @param [in,out] name String representation of principal name + * @param [in,out] size Size of unparsed name + * + * This function is similar to krb5_unparse_name(), but allows the use of an + * existing buffer for the result. If size is not NULL, then @a name must + * point to either NULL or an existing buffer of at least the size pointed to + * by @a size. The buffer will be allocated or resized if necessary, with the + * new pointer stored into @a name. Whether or not the buffer is resized, the + * necessary space for the result, including null terminator, will be stored + * into @a size. + * + * If size is NULL, this function behaves exactly as krb5_unparse_name(). + * + * @retval + * 0 Success + * @return + * Kerberos error codes. On failure @a name is set to NULL + */ +krb5_error_code KRB5_CALLCONV +krb5_unparse_name_ext(krb5_context context, krb5_const_principal principal, + char **name, unsigned int *size); + +#define KRB5_PRINCIPAL_UNPARSE_SHORT 0x1 /**< Omit realm if it is the local realm */ +#define KRB5_PRINCIPAL_UNPARSE_NO_REALM 0x2 /**< Omit realm always */ +#define KRB5_PRINCIPAL_UNPARSE_DISPLAY 0x4 /**< Don't escape special characters */ + +/** + * Convert krb5_principal structure to a string with flags. + * + * @param [in] context Library context + * @param [in] principal Principal + * @param [in] flags Flags + * @param [out] name String representation of principal name + * + * Similar to krb5_unparse_name(), this function converts a krb5_principal + * structure to a string representation. + * + * The following flags are valid: + * @li #KRB5_PRINCIPAL_UNPARSE_SHORT - omit realm if it is the local realm + * @li #KRB5_PRINCIPAL_UNPARSE_NO_REALM - omit realm + * @li #KRB5_PRINCIPAL_UNPARSE_DISPLAY - do not quote special characters + * + * Use krb5_free_unparsed_name() to free @a name when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes. On failure @a name is set to NULL + */ +krb5_error_code KRB5_CALLCONV +krb5_unparse_name_flags(krb5_context context, krb5_const_principal principal, + int flags, char **name); + +/** + * Convert krb5_principal structure to string format with flags. + * + * @param [in] context Library context + * @param [in] principal Principal + * @param [in] flags Flags + * @param [out] name Single string format of principal name + * @param [out] size Size of unparsed name buffer + * + * @sa krb5_unparse_name() krb5_unparse_name_flags() krb5_unparse_name_ext() + * + * @retval + * 0 Success + * @return + * Kerberos error codes. On failure @a name is set to NULL + */ +krb5_error_code KRB5_CALLCONV +krb5_unparse_name_flags_ext(krb5_context context, krb5_const_principal principal, + int flags, char **name, unsigned int *size); + +/** + * Set the realm field of a principal + * + * @param [in] context Library context + * @param [in] principal Principal name + * @param [in] realm Realm name + * + * Set the realm name part of @a principal to @a realm, overwriting the + * previous realm. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_set_principal_realm(krb5_context context, krb5_principal principal, + const char *realm); + +/** + * Search a list of addresses for a specified address. + * + * @param [in] context Library context + * @param [in] addr Address to search for + * @param [in] addrlist Address list to be searched (or NULL) + * + * @note If @a addrlist contains only a NetBIOS addresses, it will be treated + * as a null list. + * + * @return + * TRUE if @a addr is listed in @a addrlist, or @c addrlist is NULL; FALSE + * otherwise + */ +krb5_boolean KRB5_CALLCONV_WRONG +krb5_address_search(krb5_context context, const krb5_address *addr, + krb5_address *const *addrlist); + +/** + * Compare two Kerberos addresses. + * + * @param [in] context Library context + * @param [in] addr1 First address to be compared + * @param [in] addr2 Second address to be compared + * + * @return + * TRUE if the addresses are the same, FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_address_compare(krb5_context context, const krb5_address *addr1, + const krb5_address *addr2); + +/** + * Return an ordering of the specified addresses. + * + * @param [in] context Library context + * @param [in] addr1 First address + * @param [in] addr2 Second address + * + * @retval + * 0 The two addresses are the same + * @retval + * \< 0 First address is less than second + * @retval + * \> 0 First address is greater than second + */ +int KRB5_CALLCONV +krb5_address_order(krb5_context context, const krb5_address *addr1, + const krb5_address *addr2); + +/** + * Compare the realms of two principals. + * + * @param [in] context Library context + * @param [in] princ1 First principal + * @param [in] princ2 Second principal + * + * @retval + * TRUE if the realm names are the same; FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_realm_compare(krb5_context context, krb5_const_principal princ1, + krb5_const_principal princ2); + +/** + * Compare two principals. + * + * @param [in] context Library context + * @param [in] princ1 First principal + * @param [in] princ2 Second principal + * + * @retval + * TRUE if the principals are the same; FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_principal_compare(krb5_context context, + krb5_const_principal princ1, + krb5_const_principal princ2); + +/** + * Compare two principals ignoring realm components. + * + * @param [in] context Library context + * @param [in] princ1 First principal + * @param [in] princ2 Second principal + * + * Similar to krb5_principal_compare(), but do not compare the realm + * components of the principals. + * + * @retval + * TRUE if the principals are the same; FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_principal_compare_any_realm(krb5_context context, + krb5_const_principal princ1, + krb5_const_principal princ2); + +#define KRB5_PRINCIPAL_COMPARE_IGNORE_REALM 1 /**< ignore realm component */ +#define KRB5_PRINCIPAL_COMPARE_ENTERPRISE 2 /**< UPNs as real principals */ +#define KRB5_PRINCIPAL_COMPARE_CASEFOLD 4 /**< case-insensitive */ +#define KRB5_PRINCIPAL_COMPARE_UTF8 8 /**< treat principals as UTF-8 */ + +/** + * Compare two principals with additional flags. + * + * @param [in] context Library context + * @param [in] princ1 First principal + * @param [in] princ2 Second principal + * @param [in] flags Flags + * + * Valid flags are: + * @li #KRB5_PRINCIPAL_COMPARE_IGNORE_REALM - ignore realm component + * @li #KRB5_PRINCIPAL_COMPARE_ENTERPRISE - UPNs as real principals + * @li #KRB5_PRINCIPAL_COMPARE_CASEFOLD case-insensitive + * @li #KRB5_PRINCIPAL_COMPARE_UTF8 - treat principals as UTF-8 + * + * @sa krb5_principal_compare() + * + * @retval + * TRUE if the principal names are the same; FALSE otherwise + */ +krb5_boolean KRB5_CALLCONV +krb5_principal_compare_flags(krb5_context context, + krb5_const_principal princ1, + krb5_const_principal princ2, + int flags); + +/** + * Initialize an empty @c krb5_keyblock. + * + * @param [in] context Library context + * @param [in] enctype Encryption type + * @param [in] length Length of keyblock (or 0) + * @param [out] out New keyblock structure + * + * Initialize a new keyblock and allocate storage for the contents of the key. + * It is legal to pass in a length of 0, in which case contents are left + * unallocated. Use krb5_free_keyblock() to free @a out when it is no longer + * needed. + * + * @note If @a length is set to 0, contents are left unallocated. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_keyblock(krb5_context context, krb5_enctype enctype, + size_t length, krb5_keyblock **out); + +/** + * Copy a keyblock. + * + * @param [in] context Library context + * @param [in] from Keyblock to be copied + * @param [out] to Copy of keyblock @a from + * + * This function creates a new keyblock with the same contents as @a from. Use + * krb5_free_keyblock() to free @a to when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_keyblock(krb5_context context, const krb5_keyblock *from, + krb5_keyblock **to); + +/** + * Copy the contents of a keyblock. + * + * @param [in] context Library context + * @param [in] from Key to be copied + * @param [out] to Output key + * + * This function copies the contents of @a from to @a to. Use + * krb5_free_keyblock_contents() to free @a to when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_keyblock_contents(krb5_context context, const krb5_keyblock *from, + krb5_keyblock *to); + +/** + * Copy a krb5_creds structure. + * + * @param [in] context Library context + * @param [in] incred Credentials structure to be copied + * @param [out] outcred Copy of @a incred + * + * This function creates a new credential with the contents of @a incred. Use + * krb5_free_creds() to free @a outcred when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_creds(krb5_context context, const krb5_creds *incred, krb5_creds **outcred); + +/** + * Copy a krb5_data object. + * + * @param [in] context Library context + * @param [in] indata Data object to be copied + * @param [out] outdata Copy of @a indata + * + * This function creates a new krb5_data object with the contents of @a indata. + * Use krb5_free_data() to free @a outdata when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_data(krb5_context context, const krb5_data *indata, krb5_data **outdata); + +/** + * Copy a principal. + * + * @param [in] context Library context + * @param [in] inprinc Principal to be copied + * @param [out] outprinc Copy of @a inprinc + * + * This function creates a new principal structure with the contents of @a + * inprinc. Use krb5_free_principal() to free @a outprinc when it is no longer + * needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, + krb5_principal *outprinc); + +/** + * Copy an array of addresses. + * + * @param [in] context Library context + * @param [in] inaddr Array of addresses to be copied + * @param [out] outaddr Copy of array of addresses + * + * This function creates a new address array containing a copy of @a inaddr. + * Use krb5_free_addresses() to free @a outaddr when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_addresses(krb5_context context, krb5_address *const *inaddr, + krb5_address ***outaddr); + +/** + * Copy a krb5_ticket structure. + * + * @param [in] context Library context + * @param [in] from Ticket to be copied + * @param [out] pto Copy of ticket + * + * This function creates a new krb5_ticket structure containing the contents of + * @a from. Use krb5_free_ticket() to free @a pto when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_ticket(krb5_context context, const krb5_ticket *from, krb5_ticket **pto); + +/** + * Copy an authorization data list. + * + * @param [in] context Library context + * @param [in] in_authdat List of @a krb5_authdata structures + * @param [out] out New array of @a krb5_authdata structures + * + * This function creates a new authorization data list containing a copy of @a + * in_authdat, which must be null-terminated. Use krb5_free_authdata() to free + * @a out when it is no longer needed. + * + * @note The last array entry in @a in_authdat must be a NULL pointer. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_authdata(krb5_context context, + krb5_authdata *const *in_authdat, krb5_authdata ***out); + +/** + * Find authorization data elements. + * + * @param [in] context Library context + * @param [in] ticket_authdata Authorization data list from ticket + * @param [in] ap_req_authdata Authorization data list from AP request + * @param [in] ad_type Authorization data type to find + * @param [out] results List of matching entries + * + * This function searches @a ticket_authdata and @a ap_req_authdata for + * elements of type @a ad_type. Either input list may be NULL, in which case + * it will not be searched; otherwise, the input lists must be terminated by + * NULL entries. This function will search inside AD-IF-RELEVANT containers if + * found in either list. Use krb5_free_authdata() to free @a results when it + * is no longer needed. + * + * @version New in 1.10 + */ +krb5_error_code KRB5_CALLCONV +krb5_find_authdata(krb5_context context, krb5_authdata *const *ticket_authdata, + krb5_authdata *const *ap_req_authdata, + krb5_authdatatype ad_type, krb5_authdata ***results); + +/** + * Merge two authorization data lists into a new list. + * + * @param [in] context Library context + * @param [in] inauthdat1 First list of @a krb5_authdata structures + * @param [in] inauthdat2 Second list of @a krb5_authdata structures + * @param [out] outauthdat Merged list of @a krb5_authdata structures + * + * Merge two authdata arrays, such as the array from a ticket + * and authenticator. + * Use krb5_free_authdata() to free @a outauthdat when it is no longer needed. + * + * @note The last array entry in @a inauthdat1 and @a inauthdat2 + * must be a NULL pointer. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_merge_authdata(krb5_context context, + krb5_authdata *const *inauthdat1, + krb5_authdata * const *inauthdat2, + krb5_authdata ***outauthdat); + +/** + * Copy a krb5_authenticator structure. + * + * @param [in] context Library context + * @param [in] authfrom krb5_authenticator structure to be copied + * @param [out] authto Copy of krb5_authenticator structure + * + * This function creates a new krb5_authenticator structure with the content of + * @a authfrom. Use krb5_free_authenticator() to free @a authto when it is no + * longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_authenticator(krb5_context context, const krb5_authenticator *authfrom, + krb5_authenticator **authto); + +/** + * Copy a krb5_checksum structure. + * + * @param [in] context Library context + * @param [in] ckfrom Checksum to be copied + * @param [out] ckto Copy of krb5_checksum structure + * + * This function creates a new krb5_checksum structure with the contents of @a + * ckfrom. Use krb5_free_checksum() to free @a ckto when it is no longer + * needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_copy_checksum(krb5_context context, const krb5_checksum *ckfrom, + krb5_checksum **ckto); + +/** + * Generate a replay cache object for server use and open it. + * + * @param [in] context Library context + * @param [in] piece Unique identifier for replay cache + * @param [out] rcptr Handle to an open rcache + * + * This function generates a replay cache name based on @a piece and opens a + * handle to it. Typically @a piece is the first component of the service + * principal name. Use krb5_rc_close() to close @a rcptr when it is no longer + * needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_server_rcache(krb5_context context, const krb5_data *piece, + krb5_rcache *rcptr); + +/** + * Build a principal name using length-counted strings. + * + * @param [in] context Library context + * @param [out] princ Principal name + * @param [in] rlen Realm name length + * @param [in] realm Realm name + * @param [in] ... List of unsigned int/char * components, followed by 0 + * + * This function creates a principal from a length-counted string and a + * variable-length list of length-counted components. The list of components + * ends with the first 0 length argument (so it is not possible to specify an + * empty component with this function). Call krb5_free_principal() to free + * allocated memory for principal when it is no longer needed. + * + * @code + * Example of how to build principal WELLKNOWN/ANONYMOUS@R + * krb5_build_principal_ext(context, &principal, strlen("R"), "R", + * (unsigned int)strlen(KRB5_WELLKNOWN_NAMESTR), + * KRB5_WELLKNOWN_NAMESTR, + * (unsigned int)strlen(KRB5_ANONYMOUS_PRINCSTR), + * KRB5_ANONYMOUS_PRINCSTR, 0); + * @endcode + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV_C +krb5_build_principal_ext(krb5_context context, krb5_principal * princ, + unsigned int rlen, const char * realm, ...); + +/** + * Build a principal name using null-terminated strings. + * + * @param [in] context Library context + * @param [out] princ Principal name + * @param [in] rlen Realm name length + * @param [in] realm Realm name + * @param [in] ... List of char * components, ending with NULL + * + * Call krb5_free_principal() to free @a princ when it is no longer needed. + * + * @note krb5_build_principal() and krb5_build_principal_alloc_va() perform the + * same task. krb5_build_principal() takes variadic arguments. + * krb5_build_principal_alloc_va() takes a pre-computed @a varargs pointer. + * + * @code + * Example of how to build principal H/S@R + * krb5_build_principal(context, &principal, + * strlen("R"), "R", "H", "S", (char*)NULL); + * @endcode + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV_C +krb5_build_principal(krb5_context context, + krb5_principal * princ, + unsigned int rlen, + const char * realm, ...) +#if __GNUC__ >= 4 + __attribute__ ((sentinel)) +#endif + ; +#if KRB5_DEPRECATED +/** @deprecated Replaced by krb5_build_principal_alloc_va(). */ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_build_principal_va(krb5_context context, + krb5_principal princ, + unsigned int rlen, + const char *realm, + va_list ap); +#endif + +/** + * Build a principal name, using a precomputed variable argument list + * + * @param [in] context Library context + * @param [out] princ Principal structure + * @param [in] rlen Realm name length + * @param [in] realm Realm name + * @param [in] ap List of char * components, ending with NULL + * + * Similar to krb5_build_principal(), this function builds a principal name, + * but its name components are specified as a va_list. + * + * Use krb5_free_principal() to deallocate @a princ when it is no longer + * needed. + * + * @code + * Function usage example: + * va_list ap; + * va_start(ap, realm); + * krb5_build_principal_alloc_va(context, princ, rlen, realm, ap); + * va_end(ap); + * @endcode + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_build_principal_alloc_va(krb5_context context, + krb5_principal *princ, + unsigned int rlen, + const char *realm, + va_list ap); + +/** + * Convert a Kerberos V4 principal to a Kerberos V5 principal. + * + * @param [in] context Library context + * @param [in] name V4 name + * @param [in] instance V4 instance + * @param [in] realm Realm + * @param [out] princ V5 principal + * + * This function builds a @a princ from V4 specification based on given input + * @a name.instance\@realm. + * + * Use krb5_free_principal() to free @a princ when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_425_conv_principal(krb5_context context, const char *name, + const char *instance, const char *realm, + krb5_principal *princ); + +/** + * Convert a Kerberos V5 principal to a Kerberos V4 principal. + * + * @param [in] context Library context + * @param [in] princ V5 Principal + * @param [out] name V4 principal's name to be filled in + * @param [out] inst V4 principal's instance name to be filled in + * @param [out] realm Principal's realm name to be filled in + * + * This function separates a V5 principal @a princ into @a name, @a instance, + * and @a realm. + * + * @retval + * 0 Success + * @retval + * KRB5_INVALID_PRINCIPAL Invalid principal name + * @retval + * KRB5_CONFIG_CANTOPEN Can't open or find Kerberos configuration file + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_524_conv_principal(krb5_context context, krb5_const_principal princ, + char *name, char *inst, char *realm); +/** + *@deprecated + */ +struct credentials; + +/** + * Convert a Kerberos V5 credentials to a Kerberos V4 credentials + * + * @note Not implemented + * + * @retval KRB524_KRB4_DISABLED (always) + */ +int KRB5_CALLCONV +krb5_524_convert_creds(krb5_context context, krb5_creds *v5creds, + struct credentials *v4creds); + +#if KRB5_DEPRECATED +#define krb524_convert_creds_kdc krb5_524_convert_creds +#define krb524_init_ets(x) (0) +#endif + +/* libkt.spec */ + +/** + * Get a handle for a key table. + * + * @param [in] context Library context + * @param [in] name Name of the key table + * @param [out] ktid Key table handle + * + * Resolve the key table name @a name and set @a ktid to a handle identifying + * the key table. Use krb5_kt_close() to free @a ktid when it is no longer + * needed. + * + * @a name must be of the form @c type:residual, where @a type must be a type + * known to the library and @a residual portion should be specific to the + * particular keytab type. If no @a type is given, the default is @c FILE. + * + * If @a name is of type @c FILE, the keytab file is not opened by this call. + * + * @code + * Example: krb5_kt_resolve(context, "FILE:/tmp/filename", &ktid); + * @endcode + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_resolve(krb5_context context, const char *name, krb5_keytab *ktid); + +/** + * Duplicate keytab handle. + * + * @param [in] context Library context + * @param [in] in Key table handle to be duplicated + * @param [out] out Key table handle + * + * Create a new handle referring to the same key table as @a in. The new + * handle and @a in can be closed independently. + * + * @version New in 1.12 + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_dup(krb5_context context, krb5_keytab in, krb5_keytab *out); + +/** + * Get the default key table name. + * + * @param [in] context Library context + * @param [out] name Default key table name + * @param [in] name_size Space available in @a name + * + * Fill @a name with the name of the default key table for @a context. + * + * @sa MAX_KEYTAB_NAME_LEN + * + * @retval + * 0 Success + * @retval + * KRB5_CONFIG_NOTENUFSPACE Buffer is too short + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_default_name(krb5_context context, char *name, int name_size); + +/** + * Resolve the default key table. + * + * @param [in] context Library context + * @param [out] id Key table handle + * + * Set @a id to a handle to the default key table. The key table is not + * opened. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_default(krb5_context context, krb5_keytab *id); + +/** + * Resolve the default client key table. + * + * @param [in] context Library context + * @param [out] keytab_out Key table handle + * + * Fill @a keytab_out with a handle to the default client key table. + * + * @version New in 1.11 + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_client_default(krb5_context context, krb5_keytab *keytab_out); + +/** + * Free the contents of a key table entry. + * + * @param [in] context Library context + * @param [in] entry Key table entry whose contents are to be freed + * + * @note The pointer is not freed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_free_keytab_entry_contents(krb5_context context, krb5_keytab_entry *entry); + +/** @deprecated Use krb5_free_keytab_entry_contents instead. */ +krb5_error_code KRB5_CALLCONV +krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *entry); + + +/* remove and add are functions, so that they can return NOWRITE + if not a writable keytab */ + +/** + * Remove an entry from a key table. + * + * @param [in] context Library context + * @param [in] id Key table handle + * @param [in] entry Entry to remove from key table + * + * @retval + * 0 Success + * @retval + * KRB5_KT_NOWRITE Key table is not writable + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_remove_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry); + +/** + * Add a new entry to a key table. + * + * @param [in] context Library context + * @param [in] id Key table handle + * @param [in] entry Entry to be added + * + * @retval + * 0 Success + * @retval + * ENOMEM Insufficient memory + * @retval + * KRB5_KT_NOWRITE Key table is not writeable + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_add_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry); + +/** + * Convert a principal name into the default salt for that principal. + * + * @param [in] context Library context + * @param [in] pr Principal name + * @param [out] ret Default salt for @a pr to be filled in + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV_WRONG +krb5_principal2salt(krb5_context context, + krb5_const_principal pr, krb5_data *ret); +/* librc.spec--see rcache.h */ + +/* libcc.spec */ + +/** + * Resolve a credential cache name. + * + * @param [in] context Library context + * @param [in] name Credential cache name to be resolved + * @param [out] cache Credential cache handle + * + * Fills in @a cache with a @a cache handle that corresponds to the name in @a + * name. @a name should be of the form @c type:residual, and @a type must be a + * type known to the library. If the @a name does not contain a colon, + * interpret it as a file name. + * + * @code + * Example: krb5_cc_resolve(context, "MEMORY:C_", &cache); + * @endcode + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_resolve(krb5_context context, const char *name, krb5_ccache *cache); + +/** + * Duplicate ccache handle. + * + * @param [in] context Library context + * @param [in] in Credential cache handle to be duplicated + * @param [out] out Credential cache handle + * + * Create a new handle referring to the same cache as @a in. + * The new handle and @a in can be closed independently. + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_dup(krb5_context context, krb5_ccache in, krb5_ccache *out); + +/** + * Return the name of the default credential cache. + * + * @param [in] context Library context + * + * Return a pointer to the default credential cache name for @a context, as + * determined by a prior call to krb5_cc_set_default_name(), by the KRB5CCNAME + * environment variable, by the default_ccache_name profile variable, or by the + * operating system or build-time default value. The returned value must not + * be modified or freed by the caller. The returned value becomes invalid when + * @a context is destroyed krb5_free_context() or if a subsequent call to + * krb5_cc_set_default_name() is made on @a context. + * + * The default credential cache name is cached in @a context between calls to + * this function, so if the value of KRB5CCNAME changes in the process + * environment after the first call to this function on, that change will not + * be reflected in later calls with the same context. The caller can invoke + * krb5_cc_set_default_name() with a NULL value of @a name to clear the cached + * value and force the default name to be recomputed. + * + * @return + * Name of default credential cache for the current user. + */ +const char *KRB5_CALLCONV +krb5_cc_default_name(krb5_context context); + +/** + * Set the default credential cache name. + * + * @param [in] context Library context + * @param [in] name Default credential cache name or NULL + * + * Set the default credential cache name to @a name for future operations using + * @a context. If @a name is NULL, clear any previous application-set default + * name and forget any cached value of the default name for @a context. + * + * Calls to this function invalidate the result of any previous calls to + * krb5_cc_default_name() using @a context. + * + * @retval + * 0 Success + * @retval + * KV5M_CONTEXT Bad magic number for @c _krb5_context structure + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_set_default_name(krb5_context context, const char *name); + +/** + * Resolve the default credential cache name. + * + * @param [in] context Library context + * @param [out] ccache Pointer to credential cache name + * + * Create a handle to the default credential cache as given by + * krb5_cc_default_name(). + * + * @retval + * 0 Success + * @retval + * KV5M_CONTEXT Bad magic number for @c _krb5_context structure + * @retval + * KRB5_FCC_INTERNAL The name of the default credential cache cannot be + * obtained + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_default(krb5_context context, krb5_ccache *ccache); + +/** + * Copy a credential cache. + * + * @param [in] context Library context + * @param [in] incc Credential cache to be copied + * @param [out] outcc Copy of credential cache to be filled in + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_copy_creds(krb5_context context, krb5_ccache incc, krb5_ccache outcc); + +/** + * Get a configuration value from a credential cache. + * + * @param [in] context Library context + * @param [in] id Credential cache handle + * @param [in] principal Configuration for this principal; + * if NULL, global for the whole cache + * @param [in] key Name of config variable + * @param [out] data Data to be fetched + * + * Use krb5_free_data_contents() to free @a data when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_get_config(krb5_context context, krb5_ccache id, + krb5_const_principal principal, + const char *key, krb5_data *data); + +/** + * Store a configuration value in a credential cache. + * + * @param [in] context Library context + * @param [in] id Credential cache handle + * @param [in] principal Configuration for a specific principal; + * if NULL, global for the whole cache + * @param [in] key Name of config variable + * @param [in] data Data to store, or NULL to remove + * + * @note Existing configuration under the same key is over-written. + * + * @warning Before version 1.10 @a data was assumed to be always non-null. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_set_config(krb5_context context, krb5_ccache id, + krb5_const_principal principal, + const char *key, krb5_data *data); + +/** + * Test whether a principal is a configuration principal. + * + * @param [in] context Library context + * @param [in] principal Principal to check + * + * @return + * @c TRUE if the principal is a configuration principal (generated part of + * krb5_cc_set_config()); @c FALSE otherwise. + */ +krb5_boolean KRB5_CALLCONV +krb5_is_config_principal(krb5_context context, krb5_const_principal principal); + +/** + * Make a credential cache the primary cache for its collection. + * + * @param [in] context Library context + * @param [in] cache Credential cache handle + * + * If the type of @a cache supports it, set @a cache to be the primary + * credential cache for the collection it belongs to. + * + * @retval + * 0 Success, or the type of @a cache doesn't support switching + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_switch(krb5_context context, krb5_ccache cache); + +/** + * Determine whether a credential cache type supports switching. + * + * @param [in] context Library context + * @param [in] type Credential cache type + * + * @version New in 1.10 + * + * @retval TRUE if @a type supports switching + * @retval FALSE if it does not or is not a valid credential cache type. + */ +krb5_boolean KRB5_CALLCONV +krb5_cc_support_switch(krb5_context context, const char *type); + +/** + * Find a credential cache with a specified client principal. + * + * @param [in] context Library context + * @param [in] client Client principal + * @param [out] cache_out Credential cache handle + * + * Find a cache within the collection whose default principal is @a client. + * Use @a krb5_cc_close to close @a ccache when it is no longer needed. + * + * @retval 0 Success + * @retval KRB5_CC_NOTFOUND + * + * @sa krb5_cccol_cursor_new + * + * @version New in 1.10 + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_cache_match(krb5_context context, krb5_principal client, + krb5_ccache *cache_out); + +/** + * Select a credential cache to use with a server principal. + * + * @param [in] context Library context + * @param [in] server Server principal + * @param [out] cache_out Credential cache handle + * @param [out] princ_out Client principal + * + * Select a cache within the collection containing credentials most appropriate + * for use with @a server, according to configured rules and heuristics. + * + * Use krb5_cc_close() to release @a cache_out when it is no longer needed. + * Use krb5_free_principal() to release @a princ_out when it is no longer + * needed. Note that @a princ_out is set in some error conditions. + * + * @return + * If an appropriate cache is found, 0 is returned, @a cache_out is set to the + * selected cache, and @a princ_out is set to the default principal of that + * cache. + * + * If the appropriate client principal can be authoritatively determined but + * the cache collection contains no credentials for that principal, then + * KRB5_CC_NOTFOUND is returned, @a cache_out is set to NULL, and @a princ_out + * is set to the appropriate client principal. + * + * If no configured mechanism can determine the appropriate cache or principal, + * KRB5_CC_NOTFOUND is returned and @a cache_out and @a princ_out are set to + * NULL. + * + * Any other error code indicates a fatal error in the processing of a cache + * selection mechanism. + * + * @version New in 1.10 + */ +krb5_error_code KRB5_CALLCONV +krb5_cc_select(krb5_context context, krb5_principal server, + krb5_ccache *cache_out, krb5_principal *princ_out); + +/* krb5_free.c */ +/** + * Free the storage assigned to a principal. + * + * @param [in] context Library context + * @param [in] val Principal to be freed + */ +void KRB5_CALLCONV +krb5_free_principal(krb5_context context, krb5_principal val); + +/** + * Free a krb5_authenticator structure. + * + * @param [in] context Library context + * @param [in] val Authenticator structure to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_authenticator(krb5_context context, krb5_authenticator *val); + +/** + * Free the data stored in array of addresses. + * + * @param [in] context Library context + * @param [in] val Array of addresses to be freed + * + * This function frees the contents of @a val and the array itself. + * + * @note The last entry in the array must be a NULL pointer. + */ +void KRB5_CALLCONV +krb5_free_addresses(krb5_context context, krb5_address **val); + +/** + * Free the storage assigned to array of authentication data. + * + * @param [in] context Library context + * @param [in] val Array of authentication data to be freed + * + * This function frees the contents of @a val and the array itself. + * + * @note The last entry in the array must be a NULL pointer. + */ +void KRB5_CALLCONV +krb5_free_authdata(krb5_context context, krb5_authdata **val); + +/** + * Free a ticket. + * + * @param [in] context Library context + * @param [in] val Ticket to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_ticket(krb5_context context, krb5_ticket *val); + +/** + * Free an error allocated by krb5_read_error() or krb5_sendauth(). + * + * @param [in] context Library context + * @param [in] val Error data structure to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_error(krb5_context context, krb5_error *val); + +/** + * Free a krb5_creds structure. + * + * @param [in] context Library context + * @param [in] val Credential structure to be freed. + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_creds(krb5_context context, krb5_creds *val); + +/** + * Free the contents of a krb5_creds structure. + * + * @param [in] context Library context + * @param [in] val Credential structure to free contents of + * + * This function frees the contents of @a val, but not the structure itself. + */ +void KRB5_CALLCONV +krb5_free_cred_contents(krb5_context context, krb5_creds *val); + +/** + * Free a krb5_checksum structure. + * + * @param [in] context Library context + * @param [in] val Checksum structure to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_checksum(krb5_context context, krb5_checksum *val); + +/** + * Free the contents of a krb5_checksum structure. + * + * @param [in] context Library context + * @param [in] val Checksum structure to free contents of + * + * This function frees the contents of @a val, but not the structure itself. + */ +void KRB5_CALLCONV +krb5_free_checksum_contents(krb5_context context, krb5_checksum *val); + +/** + * Free a krb5_keyblock structure. + * + * @param [in] context Library context + * @param [in] val Keyblock to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_keyblock(krb5_context context, krb5_keyblock *val); + +/** + * Free the contents of a krb5_keyblock structure. + * + * @param [in] context Library context + * @param [in] key Keyblock to be freed + * + * This function frees the contents of @a key, but not the structure itself. + */ +void KRB5_CALLCONV +krb5_free_keyblock_contents(krb5_context context, krb5_keyblock *key); + +/** + * Free a krb5_ap_rep_enc_part structure. + * + * @param [in] context Library context + * @param [in] val AP-REP enc part to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_ap_rep_enc_part(krb5_context context, krb5_ap_rep_enc_part *val); + +/** + * Free a krb5_data structure. + * + * @param [in] context Library context + * @param [in] val Data structure to be freed + * + * This function frees the contents of @a val and the structure itself. + */ +void KRB5_CALLCONV +krb5_free_data(krb5_context context, krb5_data *val); + +/* Free a krb5_octet_data structure (should be unused). */ +void KRB5_CALLCONV +krb5_free_octet_data(krb5_context context, krb5_octet_data *val); + +/** + * Free the contents of a krb5_data structure and zero the data field. + * + * @param [in] context Library context + * @param [in] val Data structure to free contents of + * + * This function frees the contents of @a val, but not the structure itself. + */ +void KRB5_CALLCONV +krb5_free_data_contents(krb5_context context, krb5_data *val); + +/** + * Free a string representation of a principal. + * + * @param [in] context Library context + * @param [in] val Name string to be freed + */ +void KRB5_CALLCONV +krb5_free_unparsed_name(krb5_context context, char *val); + +/** + * Free a string allocated by a krb5 function. + * + * @param [in] context Library context + * @param [in] val String to be freed + * + * @version New in 1.10 + */ +void KRB5_CALLCONV +krb5_free_string(krb5_context context, char *val); + +/** + * Free an array of encryption types. + * + * @param [in] context Library context + * @param [in] val Array of enctypes to be freed + * + * @version New in 1.12 + */ +void KRB5_CALLCONV +krb5_free_enctypes(krb5_context context, krb5_enctype *val); + +/** + * Free an array of checksum types. + * + * @param [in] context Library context + * @param [in] val Array of checksum types to be freed + */ +void KRB5_CALLCONV +krb5_free_cksumtypes(krb5_context context, krb5_cksumtype *val); + +/* From krb5/os, but needed by the outside world */ +/** + * Retrieve the system time of day, in sec and ms, since the epoch. + * + * @param [in] context Library context + * @param [out] seconds System timeofday, seconds portion + * @param [out] microseconds System timeofday, microseconds portion + * + * This function retrieves the system time of day with the context + * specific time offset adjustment. + * + * @sa krb5_crypto_us_timeofday() + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_us_timeofday(krb5_context context, + krb5_timestamp *seconds, krb5_int32 *microseconds); + +/** + * Retrieve the current time with context specific time offset adjustment. + * + * @param [in] context Library context + * @param [out] timeret Timestamp to fill in + * + * This function retrieves the system time of day with the context specific + * time offset adjustment. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_timeofday(krb5_context context, krb5_timestamp *timeret); + +/** + * Check if a timestamp is within the allowed clock skew of the current time. + * + * @param [in] context Library context + * @param [in] date Timestamp to check + * + * This function checks if @a date is close enough to the current time + * according to the configured allowable clock skew. + * + * @version New in 1.10 + * + * @retval 0 Success + * @retval KRB5KRB_AP_ERR_SKEW @a date is not within allowable clock skew + */ +krb5_error_code KRB5_CALLCONV +krb5_check_clockskew(krb5_context context, krb5_timestamp date); + +/** + * Return all interface addresses for this host. + * + * @param [in] context Library context + * @param [out] addr Array of krb5_address pointers, ending with + * NULL + * + * Use krb5_free_addresses() to free @a addr when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_os_localaddr(krb5_context context, krb5_address ***addr); + +/** + * Retrieve the default realm. + * + * @param [in] context Library context + * @param [out] lrealm Default realm name + * + * Retrieves the default realm to be used if no user-specified realm is + * available. + * + * Use krb5_free_default_realm() to free @a lrealm when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_default_realm(krb5_context context, char **lrealm); + +/** + * Override the default realm for the specified context. + * + * @param [in] context Library context + * @param [in] lrealm Realm name for the default realm + * + * If @a lrealm is NULL, clear the default realm setting. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_set_default_realm(krb5_context context, const char *lrealm); + +/** + * Free a default realm string returned by krb5_get_default_realm(). + * + * @param [in] context Library context + * @param [in] lrealm Realm to be freed + */ +void KRB5_CALLCONV +krb5_free_default_realm(krb5_context context, char *lrealm); + +/** + * Canonicalize a hostname, possibly using name service. + * + * @param [in] context Library context + * @param [in] host Input hostname + * @param [out] canonhost_out Canonicalized hostname + * + * This function canonicalizes orig_hostname, possibly using name service + * lookups if configuration permits. Use krb5_free_string() to free @a + * canonhost_out when it is no longer needed. + * + * @version New in 1.15 + */ +krb5_error_code KRB5_CALLCONV +krb5_expand_hostname(krb5_context context, const char *host, + char **canonhost_out); + +/** + * Generate a full principal name from a service name. + * + * @param [in] context Library context + * @param [in] hostname Host name, or NULL to use local host + * @param [in] sname Service name, or NULL to use @c "host" + * @param [in] type Principal type + * @param [out] ret_princ Generated principal + * + * This function converts a @a hostname and @a sname into @a krb5_principal + * structure @a ret_princ. The returned principal will be of the form @a + * sname\/hostname\@REALM where REALM is determined by krb5_get_host_realm(). + * In some cases this may be the referral (empty) realm. + * + * The @a type can be one of the following: + * + * @li #KRB5_NT_SRV_HST canonicalizes the host name before looking up the + * realm and generating the principal. + * + * @li #KRB5_NT_UNKNOWN accepts the hostname as given, and does not + * canonicalize it. + * + * Use krb5_free_principal to free @a ret_princ when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_sname_to_principal(krb5_context context, const char *hostname, const char *sname, + krb5_int32 type, krb5_principal *ret_princ); + +/** + * Test whether a principal matches a matching principal. + * + * @param [in] context Library context + * @param [in] matching Matching principal + * @param [in] princ Principal to test + * + * @note A matching principal is a host-based principal with an empty realm + * and/or second data component (hostname). Profile configuration may cause + * the hostname to be ignored even if it is present. A principal matches a + * matching principal if the former has the same non-empty (and non-ignored) + * components of the latter. + * + * If @a matching is NULL, return TRUE. If @a matching is not a matching + * principal, return the value of krb5_principal_compare(context, matching, + * princ). + * + * @return + * TRUE if @a princ matches @a matching, FALSE otherwise. + */ +krb5_boolean KRB5_CALLCONV +krb5_sname_match(krb5_context context, krb5_const_principal matching, + krb5_const_principal princ); + +/** + * Change a password for an existing Kerberos account. + * + * @param [in] context Library context + * @param [in] creds Credentials for kadmin/changepw service + * @param [in] newpw New password + * @param [out] result_code Numeric error code from server + * @param [out] result_code_string String equivalent to @a result_code + * @param [out] result_string Change password response from the KDC + * + * Change the password for the existing principal identified by @a creds. + * + * The possible values of the output @a result_code are: + * + * @li #KRB5_KPASSWD_SUCCESS (0) - success + * @li #KRB5_KPASSWD_MALFORMED (1) - Malformed request error + * @li #KRB5_KPASSWD_HARDERROR (2) - Server error + * @li #KRB5_KPASSWD_AUTHERROR (3) - Authentication error + * @li #KRB5_KPASSWD_SOFTERROR (4) - Password change rejected + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_change_password(krb5_context context, krb5_creds *creds, + const char *newpw, int *result_code, + krb5_data *result_code_string, krb5_data *result_string); + +/** + * Set a password for a principal using specified credentials. + * + * @param [in] context Library context + * @param [in] creds Credentials for kadmin/changepw service + * @param [in] newpw New password + * @param [in] change_password_for Change the password for this principal + * @param [out] result_code Numeric error code from server + * @param [out] result_code_string String equivalent to @a result_code + * @param [out] result_string Data returned from the remote system + * + * This function uses the credentials @a creds to set the password @a newpw for + * the principal @a change_password_for. It implements the set password + * operation of RFC 3244, for interoperability with Microsoft Windows + * implementations. + * + * @note If @a change_password_for is NULL, the change is performed on the + * current principal. If @a change_password_for is non-null, the change is + * performed on the principal name passed in @a change_password_for. + * + * The error code and strings are returned in @a result_code, + * @a result_code_string and @a result_string. + * + * @sa krb5_set_password_using_ccache() + * + * @retval + * 0 Success and result_code is set to #KRB5_KPASSWD_SUCCESS. + * @return + * Kerberos error codes. + */ +krb5_error_code KRB5_CALLCONV +krb5_set_password(krb5_context context, krb5_creds *creds, const char *newpw, + krb5_principal change_password_for, int *result_code, + krb5_data *result_code_string, krb5_data *result_string); + +/** + * Set a password for a principal using cached credentials. + * + * @param [in] context Library context + * @param [in] ccache Credential cache + * @param [in] newpw New password + * @param [in] change_password_for Change the password for this principal + * @param [out] result_code Numeric error code from server + * @param [out] result_code_string String equivalent to @a result_code + * @param [out] result_string Data returned from the remote system + * + * This function uses the cached credentials from @a ccache to set the password + * @a newpw for the principal @a change_password_for. It implements RFC 3244 + * set password operation (interoperable with MS Windows implementations) using + * the credential cache. + * + * The error code and strings are returned in @a result_code, + * @a result_code_string and @a result_string. + * + * @note If @a change_password_for is set to NULL, the change is performed on + * the default principal in @a ccache. If @a change_password_for is non null, + * the change is performed on the specified principal. + * + * @sa krb5_set_password() + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_set_password_using_ccache(krb5_context context, krb5_ccache ccache, + const char *newpw, + krb5_principal change_password_for, + int *result_code, krb5_data *result_code_string, + krb5_data *result_string); + +/** + * Get a result message for changing or setting a password. + * + * @param [in] context Library context + * @param [in] server_string Data returned from the remote system + * @param [out] message_out A message displayable to the user + * + * This function processes the @a server_string returned in the @a + * result_string parameter of krb5_change_password(), krb5_set_password(), and + * related functions, and returns a displayable string. If @a server_string + * contains Active Directory structured policy information, it will be + * converted into human-readable text. + * + * Use krb5_free_string() to free @a message_out when it is no longer needed. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_chpw_message(krb5_context context, const krb5_data *server_string, + char **message_out); + +/** + * Retrieve configuration profile from the context. + * + * @param [in] context Library context + * @param [out] profile Pointer to data read from a configuration file + * + * This function creates a new @a profile object that reflects profile + * in the supplied @a context. + * + * The @a profile object may be freed with profile_release() function. + * See profile.h and profile API for more details. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_profile(krb5_context context, struct _profile_t ** profile); + +#if KRB5_DEPRECATED +/** @deprecated Replaced by krb5_get_init_creds_password().*/ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_get_in_tkt_with_password(krb5_context context, krb5_flags options, + krb5_address *const *addrs, krb5_enctype *ktypes, + krb5_preauthtype *pre_auth_types, + const char *password, krb5_ccache ccache, + krb5_creds *creds, krb5_kdc_rep **ret_as_reply); + +/** @deprecated Replaced by krb5_get_init_creds(). */ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_get_in_tkt_with_skey(krb5_context context, krb5_flags options, + krb5_address *const *addrs, krb5_enctype *ktypes, + krb5_preauthtype *pre_auth_types, + const krb5_keyblock *key, krb5_ccache ccache, + krb5_creds *creds, krb5_kdc_rep **ret_as_reply); + +/** @deprecated Replaced by krb5_get_init_creds_keytab(). */ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_get_in_tkt_with_keytab(krb5_context context, krb5_flags options, + krb5_address *const *addrs, krb5_enctype *ktypes, + krb5_preauthtype *pre_auth_types, + krb5_keytab arg_keytab, krb5_ccache ccache, + krb5_creds *creds, krb5_kdc_rep **ret_as_reply); + +#endif /* KRB5_DEPRECATED */ + +/** + * Parse and decrypt a @c KRB_AP_REQ message. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] inbuf AP-REQ message to be parsed + * @param [in] server Matching principal for server, or NULL to + * allow any principal in keytab + * @param [in] keytab Key table, or NULL to use the default + * @param [out] ap_req_options If non-null, the AP-REQ flags on output + * @param [out] ticket If non-null, ticket from the AP-REQ message + * + * This function parses, decrypts and verifies a AP-REQ message from @a inbuf + * and stores the authenticator in @a auth_context. + * + * If a keyblock was specified in @a auth_context using + * krb5_auth_con_setuseruserkey(), that key is used to decrypt the ticket in + * AP-REQ message and @a keytab is ignored. In this case, @a server should be + * specified as a complete principal name to allow for proper transited-path + * checking and replay cache selection. + * + * Otherwise, the decryption key is obtained from @a keytab, or from the + * default keytab if it is NULL. In this case, @a server may be a complete + * principal name, a matching principal (see krb5_sname_match()), or NULL to + * match any principal name. The keys tried against the encrypted part of the + * ticket are determined as follows: + * + * - If @a server is a complete principal name, then its entry in @a keytab is + * tried. + * - Otherwise, if @a keytab is iterable, then all entries in @a keytab which + * match @a server are tried. + * - Otherwise, the server principal in the ticket must match @a server, and + * its entry in @a keytab is tried. + * + * The client specified in the decrypted authenticator must match the client + * specified in the decrypted ticket. + * + * If the @a remote_addr field of @a auth_context is set, the request must come + * from that address. + * + * If a replay cache handle is provided in the @a auth_context, the + * authenticator and ticket are verified against it. If no conflict is found, + * the new authenticator is then stored in the replay cache of @a auth_context. + * + * Various other checks are performed on the decoded data, including + * cross-realm policy, clockskew, and ticket validation times. + * + * On success the authenticator, subkey, and remote sequence number of the + * request are stored in @a auth_context. If the #AP_OPTS_MUTUAL_REQUIRED + * bit is set, the local sequence number is XORed with the remote sequence + * number in the request. + * + * Use krb5_free_ticket() to free @a ticket when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_req(krb5_context context, krb5_auth_context *auth_context, + const krb5_data *inbuf, krb5_const_principal server, + krb5_keytab keytab, krb5_flags *ap_req_options, + krb5_ticket **ticket); + +/** + * Retrieve a service key from a key table. + * + * @param [in] context Library context + * @param [in] keyprocarg Name of a key table (NULL to use default name) + * @param [in] principal Service principal + * @param [in] vno Key version number (0 for highest available) + * @param [in] enctype Encryption type (0 for any type) + * @param [out] key Service key from key table + * + * Open and search the specified key table for the entry identified by @a + * principal, @a enctype, and @a vno. If no key is found, return an error code. + * + * The default key table is used, unless @a keyprocarg is non-null. + * @a keyprocarg designates a specific key table. + * + * Use krb5_free_keyblock() to free @a key when it is no longer needed. + * + * @retval + * 0 Success + * @return Kerberos error code if not found or @a keyprocarg is invalid. + */ +krb5_error_code KRB5_CALLCONV +krb5_kt_read_service_key(krb5_context context, krb5_pointer keyprocarg, + krb5_principal principal, krb5_kvno vno, + krb5_enctype enctype, krb5_keyblock **key); + +/** + * Format a @c KRB-SAFE message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] userdata User data in the message + * @param [out] outbuf Formatted @c KRB-SAFE buffer + * @param [out] outdata Replay data. Specify NULL if not needed + * + * This function creates an integrity protected @c KRB-SAFE message + * using data supplied by the application. + * + * Fields in @a auth_context specify the checksum type, the keyblock that + * can be used to seed the checksum, full addresses (host and port) for + * the sender and receiver, and @ref KRB5_AUTH_CONTEXT flags. + * + * The local address in @a auth_context must be set, and is used to form the + * sender address used in the KRB-SAFE message. The remote address is + * optional; if specified, it will be used to form the receiver address used in + * the message. + * + * If #KRB5_AUTH_CONTEXT_DO_TIME flag is set in the @a auth_context, an entry + * describing the message is entered in the replay cache @a + * auth_context->rcache which enables the caller to detect if this message is + * reflected by an attacker. If #KRB5_AUTH_CONTEXT_DO_TIME is not set, the + * replay cache is not used. + * + * If either #KRB5_AUTH_CONTEXT_DO_SEQUENCE or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE is set, the @a auth_context local sequence + * number will be placed in @a outdata as its sequence number. + * + * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context. + * + * Use krb5_free_data_contents() to free @a outbuf when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_safe(krb5_context context, krb5_auth_context auth_context, + const krb5_data *userdata, krb5_data *outbuf, + krb5_replay_data *outdata); + +/** + * Format a @c KRB-PRIV message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] userdata User data for @c KRB-PRIV message + * @param [out] outbuf Formatted @c KRB-PRIV message + * @param [out] outdata Replay cache handle (NULL if not needed) + * + * This function is similar to krb5_mk_safe(), but the message is encrypted and + * integrity-protected, not just integrity-protected. + * + * The local address in @a auth_context must be set, and is used to form the + * sender address used in the KRB-SAFE message. The remote address is + * optional; if specified, it will be used to form the receiver address used in + * the message. + * + * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in @a auth_context, the @a + * outdata is required. + * + * @note The flags from @a auth_context specify whether sequence numbers or + * timestamps will be used to identify the message. Valid values are: + * + * @li #KRB5_AUTH_CONTEXT_DO_TIME - Use timestamps in @a outdata + * @li #KRB5_AUTH_CONTEXT_RET_TIME - Copy timestamp to @a outdata. + * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE - Use local sequence numbers from + * @a auth_context in replay cache. + * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE - Use local sequence numbers from + * @a auth_context as a sequence number + * in the encrypted message @a outbuf. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_priv(krb5_context context, krb5_auth_context auth_context, + const krb5_data *userdata, krb5_data *outbuf, + krb5_replay_data *outdata); + +/** + * Client function for @c sendauth protocol. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] fd File descriptor that describes network socket + * @param [in] appl_version Application protocol version to be matched + * with the receiver's application version + * @param [in] client Client principal + * @param [in] server Server principal + * @param [in] ap_req_options @ref AP_OPTS options + * @param [in] in_data Data to be sent to the server + * @param [in] in_creds Input credentials, or NULL to use @a ccache + * @param [in] ccache Credential cache + * @param [out] error If non-null, contains KRB_ERROR message + * returned from server + * @param [out] rep_result If non-null and @a ap_req_options is + * #AP_OPTS_MUTUAL_REQUIRED, contains the result + * of mutual authentication exchange + * @param [out] out_creds If non-null, the retrieved credentials + * + * This function performs the client side of a sendauth/recvauth exchange by + * sending and receiving messages over @a fd. + * + * Credentials may be specified in three ways: + * + * @li If @a in_creds is NULL, credentials are obtained with + * krb5_get_credentials() using the principals @a client and @a server. @a + * server must be non-null; @a client may NULL to use the default principal of + * @a ccache. + * + * @li If @a in_creds is non-null, but does not contain a ticket, credentials + * for the exchange are obtained with krb5_get_credentials() using @a in_creds. + * In this case, the values of @a client and @a server are unused. + * + * @li If @a in_creds is a complete credentials structure, it used directly. + * In this case, the values of @a client, @a server, and @a ccache are unused. + * + * If the server is using a different application protocol than that specified + * in @a appl_version, an error will be returned. + * + * Use krb5_free_creds() to free @a out_creds, krb5_free_ap_rep_enc_part() to + * free @a rep_result, and krb5_free_error() to free @a error when they are no + * longer needed. + * + * @sa krb5_recvauth() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_sendauth(krb5_context context, krb5_auth_context *auth_context, + krb5_pointer fd, char *appl_version, krb5_principal client, + krb5_principal server, krb5_flags ap_req_options, + krb5_data *in_data, krb5_creds *in_creds, krb5_ccache ccache, + krb5_error **error, krb5_ap_rep_enc_part **rep_result, + krb5_creds **out_creds); + +/** + * Server function for @a sendauth protocol. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] fd File descriptor + * @param [in] appl_version Application protocol version to be matched + * against the client's application version + * @param [in] server Server principal (NULL for any in @a keytab) + * @param [in] flags Additional specifications + * @param [in] keytab Key table containing service keys + * @param [out] ticket Ticket (NULL if not needed) + * + * This function performs the server side of a sendauth/recvauth exchange by + * sending and receiving messages over @a fd. + * + * Use krb5_free_ticket() to free @a ticket when it is no longer needed. + * + * @sa krb5_sendauth() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_recvauth(krb5_context context, krb5_auth_context *auth_context, + krb5_pointer fd, char *appl_version, krb5_principal server, + krb5_int32 flags, krb5_keytab keytab, krb5_ticket **ticket); + +/** + * Server function for @a sendauth protocol with version parameter. + * + * @param [in] context Library context + * @param [in,out] auth_context Pre-existing or newly created auth context + * @param [in] fd File descriptor + * @param [in] server Server principal (NULL for any in @a keytab) + * @param [in] flags Additional specifications + * @param [in] keytab Decryption key + * @param [out] ticket Ticket (NULL if not needed) + * @param [out] version sendauth protocol version (NULL if not needed) + * + * This function is similar to krb5_recvauth() with the additional output + * information place into @a version. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_recvauth_version(krb5_context context, + krb5_auth_context *auth_context, + krb5_pointer fd, + krb5_principal server, + krb5_int32 flags, + krb5_keytab keytab, + krb5_ticket **ticket, + krb5_data *version); + +/** + * Format a @c KRB-CRED message for an array of credentials. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] ppcreds Null-terminated array of credentials + * @param [out] ppdata Encoded credentials + * @param [out] outdata Replay cache information (NULL if not needed) + * + * This function takes an array of credentials @a ppcreds and formats + * a @c KRB-CRED message @a ppdata to pass to krb5_rd_cred(). + * + * @note If the #KRB5_AUTH_CONTEXT_RET_TIME or #KRB5_AUTH_CONTEXT_RET_SEQUENCE + * flag is set in @a auth_context, @a outdata is required. + * + * The message will be encrypted using the send subkey of @a auth_context if it + * is present, or the session key otherwise. + * + * @retval + * 0 Success + * @retval + * ENOMEM Insufficient memory + * @retval + * KRB5_RC_REQUIRED Message replay detection requires @a rcache parameter + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_ncred(krb5_context context, krb5_auth_context auth_context, + krb5_creds **ppcreds, krb5_data **ppdata, + krb5_replay_data *outdata); + +/** + * Format a @c KRB-CRED message for a single set of credentials. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] pcreds Pointer to credentials + * @param [out] ppdata Encoded credentials + * @param [out] outdata Replay cache data (NULL if not needed) + * + * This is a convenience function that calls krb5_mk_ncred() with a single set + * of credentials. + * + * @retval + * 0 Success + * @retval + * ENOMEM Insufficient memory + * @retval + * KRB5_RC_REQUIRED Message replay detection requires @a rcache parameter + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_mk_1cred(krb5_context context, krb5_auth_context auth_context, + krb5_creds *pcreds, krb5_data **ppdata, + krb5_replay_data *outdata); + +/** + * Read and validate a @c KRB-CRED message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] pcreddata @c KRB-CRED message + * @param [out] pppcreds Null-terminated array of forwarded credentials + * @param [out] outdata Replay data (NULL if not needed) + * + * @note The @a outdata argument is required if #KRB5_AUTH_CONTEXT_RET_TIME or + * #KRB5_AUTH_CONTEXT_RET_SEQUENCE flag is set in the @a auth_context.` + * + * @a pcreddata will be decrypted using the receiving subkey if it is present + * in @a auth_context, or the session key if the receiving subkey is not + * present or fails to decrypt the message. + * + * Use krb5_free_tgt_creds() to free @a pppcreds when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_rd_cred(krb5_context context, krb5_auth_context auth_context, + krb5_data *pcreddata, krb5_creds ***pppcreds, + krb5_replay_data *outdata); + +/** + * Get a forwarded TGT and format a @c KRB-CRED message. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] rhost Remote host + * @param [in] client Client principal of TGT + * @param [in] server Principal of server to receive TGT + * @param [in] cc Credential cache handle (NULL to use default) + * @param [in] forwardable Whether TGT should be forwardable + * @param [out] outbuf KRB-CRED message + * + * Get a TGT for use at the remote host @a rhost and format it into a KRB-CRED + * message. If @a rhost is NULL and @a server is of type #KRB5_NT_SRV_HST, + * the second component of @a server will be used. + * + * @retval + * 0 Success + * @retval + * ENOMEM Insufficient memory + * @retval + * KRB5_PRINC_NOMATCH Requested principal and ticket do not match + * @retval + * KRB5_NO_TKT_SUPPLIED Request did not supply a ticket + * @retval + * KRB5_CC_BADNAME Credential cache name or principal name malformed + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_fwd_tgt_creds(krb5_context context, krb5_auth_context auth_context, + const char *rhost, krb5_principal client, + krb5_principal server, krb5_ccache cc, int forwardable, + krb5_data *outbuf); + +/** + * Create and initialize an authentication context. + * + * @param [in] context Library context + * @param [out] auth_context Authentication context + * + * This function creates an authentication context to hold configuration and + * state relevant to krb5 functions for authenticating principals and + * protecting messages once authentication has occurred. + * + * By default, flags for the context are set to enable the use of the replay + * cache (#KRB5_AUTH_CONTEXT_DO_TIME), but not sequence numbers. Use + * krb5_auth_con_setflags() to change the flags. + * + * The allocated @a auth_context must be freed with krb5_auth_con_free() when + * it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_init(krb5_context context, krb5_auth_context *auth_context); + +/** + * Free a krb5_auth_context structure. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context to be freed + * + * This function frees an auth context allocated by krb5_auth_con_init(). + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_free(krb5_context context, krb5_auth_context auth_context); + +/** + * Set a flags field in a krb5_auth_context structure. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] flags Flags bit mask + * + * Valid values for @a flags are: + * @li #KRB5_AUTH_CONTEXT_DO_TIME Use timestamps + * @li #KRB5_AUTH_CONTEXT_RET_TIME Save timestamps + * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE Use sequence numbers + * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE Save sequence numbers + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setflags(krb5_context context, krb5_auth_context auth_context, krb5_int32 flags); + +/** + * Retrieve flags from a krb5_auth_context structure. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] flags Flags bit mask + * + * Valid values for @a flags are: + * @li #KRB5_AUTH_CONTEXT_DO_TIME Use timestamps + * @li #KRB5_AUTH_CONTEXT_RET_TIME Save timestamps + * @li #KRB5_AUTH_CONTEXT_DO_SEQUENCE Use sequence numbers + * @li #KRB5_AUTH_CONTEXT_RET_SEQUENCE Save sequence numbers + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getflags(krb5_context context, krb5_auth_context auth_context, + krb5_int32 *flags); + +/** + * Set a checksum callback in an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] func Checksum callback + * @param [in] data Callback argument + * + * Set a callback to obtain checksum data in krb5_mk_req(). The callback will + * be invoked after the subkey and local sequence number are stored in @a + * auth_context. + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_set_checksum_func( krb5_context context, + krb5_auth_context auth_context, + krb5_mk_req_checksum_func func, + void *data); + +/** + * Get the checksum callback from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] func Checksum callback + * @param [out] data Callback argument + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_get_checksum_func( krb5_context context, + krb5_auth_context auth_context, + krb5_mk_req_checksum_func *func, + void **data); + +/** + * Set the local and remote addresses in an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] local_addr Local address + * @param [in] remote_addr Remote address + * + * This function releases the storage assigned to the contents of the local and + * remote addresses of @a auth_context and then sets them to @a local_addr and + * @a remote_addr respectively. + * + * @sa krb5_auth_con_genaddrs() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV_WRONG +krb5_auth_con_setaddrs(krb5_context context, krb5_auth_context auth_context, + krb5_address *local_addr, krb5_address *remote_addr); + +/** + * Retrieve address fields from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] local_addr Local address (NULL if not needed) + * @param [out] remote_addr Remote address (NULL if not needed) + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getaddrs(krb5_context context, krb5_auth_context auth_context, + krb5_address **local_addr, krb5_address **remote_addr); + +/** + * Set local and remote port fields in an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] local_port Local port + * @param [in] remote_port Remote port + * + * This function releases the storage assigned to the contents of the local and + * remote ports of @a auth_context and then sets them to @a local_port and @a + * remote_port respectively. + * + * @sa krb5_auth_con_genaddrs() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setports(krb5_context context, krb5_auth_context auth_context, + krb5_address *local_port, krb5_address *remote_port); + +/** + * Set the session key in an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] keyblock User key + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, + krb5_keyblock *keyblock); + +/** + * Retrieve the session key from an auth context as a keyblock. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] keyblock Session key + * + * This function creates a keyblock containing the session key from @a + * auth_context. Use krb5_free_keyblock() to free @a keyblock when it is no + * longer needed + * + * @retval 0 Success. Otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getkey(krb5_context context, krb5_auth_context auth_context, + krb5_keyblock **keyblock); + +/** + * Retrieve the session key from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] key Session key + * + * This function sets @a key to the session key from @a auth_context. Use + * krb5_k_free_key() to release @a key when it is no longer needed. + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getkey_k(krb5_context context, krb5_auth_context auth_context, + krb5_key *key); + +/** + * Retrieve the send subkey from an auth context as a keyblock. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [out] keyblock Send subkey + * + * This function creates a keyblock containing the send subkey from @a + * auth_context. Use krb5_free_keyblock() to free @a keyblock when it is no + * longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getsendsubkey(krb5_context ctx, krb5_auth_context ac, krb5_keyblock **keyblock); + +/** + * Retrieve the send subkey from an auth context. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [out] key Send subkey + * + * This function sets @a key to the send subkey from @a auth_context. Use + * krb5_k_free_key() to release @a key when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getsendsubkey_k(krb5_context ctx, krb5_auth_context ac, + krb5_key *key); + +/** + * Retrieve the receiving subkey from an auth context as a keyblock. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [out] keyblock Receiving subkey + * + * This function creates a keyblock containing the receiving subkey from @a + * auth_context. Use krb5_free_keyblock() to free @a keyblock when it is no + * longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getrecvsubkey(krb5_context ctx, krb5_auth_context ac, krb5_keyblock **keyblock); + +/** + * Retrieve the receiving subkey from an auth context as a keyblock. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [out] key Receiving subkey + * + * This function sets @a key to the receiving subkey from @a auth_context. Use + * krb5_k_free_key() to release @a key when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getrecvsubkey_k(krb5_context ctx, krb5_auth_context ac, krb5_key *key); + +/** + * Set the send subkey in an auth context with a keyblock. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [in] keyblock Send subkey + * + * This function sets the send subkey in @a ac to a copy of @a keyblock. + * + * @retval 0 Success. Otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setsendsubkey(krb5_context ctx, krb5_auth_context ac, + krb5_keyblock *keyblock); + +/** + * Set the send subkey in an auth context. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [out] key Send subkey + * + * This function sets the send subkey in @a ac to @a key, incrementing its + * reference count. + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setsendsubkey_k(krb5_context ctx, krb5_auth_context ac, krb5_key key); + +/** + * Set the receiving subkey in an auth context with a keyblock. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [in] keyblock Receiving subkey + * + * This function sets the receiving subkey in @a ac to a copy of @a keyblock. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setrecvsubkey(krb5_context ctx, krb5_auth_context ac, + krb5_keyblock *keyblock); + +/** + * Set the receiving subkey in an auth context. + * + * @param [in] ctx Library context + * @param [in] ac Authentication context + * @param [in] key Receiving subkey + * + * This function sets the receiving subkey in @a ac to @a key, incrementing its + * reference count. + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setrecvsubkey_k(krb5_context ctx, krb5_auth_context ac, + krb5_key key); + +#if KRB5_DEPRECATED +/** @deprecated Replaced by krb5_auth_con_getsendsubkey(). */ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_auth_con_getlocalsubkey(krb5_context context, krb5_auth_context auth_context, + krb5_keyblock **keyblock); + +/** @deprecated Replaced by krb5_auth_con_getrecvsubkey(). */ +KRB5_ATTR_DEPRECATED krb5_error_code KRB5_CALLCONV +krb5_auth_con_getremotesubkey(krb5_context context, krb5_auth_context auth_context, + krb5_keyblock **keyblock); +#endif + +/** + * Retrieve the local sequence number from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] seqnumber Local sequence number + * + * Retrieve the local sequence number from @a auth_context and return it in @a + * seqnumber. The #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag must be set in @a + * auth_context for this function to be useful. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getlocalseqnumber(krb5_context context, krb5_auth_context auth_context, + krb5_int32 *seqnumber); + +/** + * Retrieve the remote sequence number from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] seqnumber Remote sequence number + * + * Retrieve the remote sequence number from @a auth_context and return it in @a + * seqnumber. The #KRB5_AUTH_CONTEXT_DO_SEQUENCE flag must be set in @a + * auth_context for this function to be useful. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getremoteseqnumber(krb5_context context, krb5_auth_context auth_context, + krb5_int32 *seqnumber); + +/** + * Cause an auth context to use cipher state. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * + * Prepare @a auth_context to use cipher state when krb5_mk_priv() or + * krb5_rd_priv() encrypt or decrypt data. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_initivector(krb5_context context, krb5_auth_context auth_context); + +/** + * Set the replay cache in an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] rcache Replay cache haddle + * + * This function sets the replay cache in @a auth_context to @a rcache. @a + * rcache will be closed when @a auth_context is freed, so the caller should + * relinguish that responsibility. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_setrcache(krb5_context context, krb5_auth_context auth_context, + krb5_rcache rcache); + +/** + * Retrieve the replay cache from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] rcache Replay cache handle + * + * This function fetches the replay cache from @a auth_context. The caller + * should not close @a rcache. + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV_WRONG +krb5_auth_con_getrcache(krb5_context context, krb5_auth_context auth_context, + krb5_rcache *rcache); + +/** + * Retrieve the authenticator from an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [out] authenticator Authenticator + * + * Use krb5_free_authenticator() to free @a authenticator when it is no longer + * needed. + * + * @retval 0 Success. Otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_getauthenticator(krb5_context context, krb5_auth_context auth_context, + krb5_authenticator **authenticator); + +/** + * Set checksum type in an an auth context. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] cksumtype Checksum type + * + * This function sets the checksum type in @a auth_context to be used by + * krb5_mk_req() for the authenticator checksum. + * + * @retval 0 Success. Otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_set_req_cksumtype(krb5_context context, krb5_auth_context auth_context, + krb5_cksumtype cksumtype); + +#define KRB5_REALM_BRANCH_CHAR '.' + +/* + * end "func-proto.h" + */ + +/* + * begin stuff from libos.h + */ + +/** + * @brief Read a password from keyboard input. + * + * @param [in] context Library context + * @param [in] prompt First user prompt when reading password + * @param [in] prompt2 Second user prompt (NULL to prompt only once) + * @param [out] return_pwd Returned password + * @param [in,out] size_return On input, maximum size of password; on output, + * size of password read + * + * This function reads a password from keyboard input and stores it in @a + * return_pwd. @a size_return should be set by the caller to the amount of + * storage space available in @a return_pwd; on successful return, it will be + * set to the length of the password read. + * + * @a prompt is printed to the terminal, followed by ": ", and then a password + * is read from the keyboard. + * + * If @a prompt2 is NULL, the password is read only once. Otherwise, @a + * prompt2 is printed to the terminal and a second password is read. If the + * two passwords entered are not identical, KRB5_LIBOS_BADPWDMATCH is returned. + * + * Echoing is turned off when the password is read. + * + * @retval + * 0 Success + * @return + * Error in reading or verifying the password + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_read_password(krb5_context context, + const char *prompt, const char *prompt2, + char *return_pwd, unsigned int *size_return); + +/** + * Convert a principal name to a local name. + * + * @param [in] context Library context + * @param [in] aname Principal name + * @param [in] lnsize_in Space available in @a lname + * @param [out] lname Local name buffer to be filled in + * + * If @a aname does not correspond to any local account, KRB5_LNAME_NOTRANS is + * returned. If @a lnsize_in is too small for the local name, + * KRB5_CONFIG_NOTENUFSPACE is returned. + * + * Local names, rather than principal names, can be used by programs that + * translate to an environment-specific name (for example, a user account + * name). + * + * @retval + * 0 Success + * @retval + * System errors + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_aname_to_localname(krb5_context context, krb5_const_principal aname, + int lnsize_in, char *lname); + +/** + * Get the Kerberos realm names for a host. + * + * @param [in] context Library context + * @param [in] host Host name (or NULL) + * @param [out] realmsp Null-terminated list of realm names + * + * Fill in @a realmsp with a pointer to a null-terminated list of realm names. + * If there are no known realms for the host, a list containing the referral + * (empty) realm is returned. + * + * If @a host is NULL, the local host's realms are determined. + * + * Use krb5_free_host_realm() to release @a realmsp when it is no longer + * needed. + * + * @retval + * 0 Success + * @retval + * ENOMEM Insufficient memory + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_host_realm(krb5_context context, const char *host, char ***realmsp); + +/** + * + * @param [in] context Library context + * @param [in] hdata Host name (or NULL) + * @param [out] realmsp Null-terminated list of realm names + * + * Fill in @a realmsp with a pointer to a null-terminated list of realm names + * obtained through heuristics or insecure resolution methods which have lower + * priority than KDC referrals. + * + * If @a host is NULL, the local host's realms are determined. + * + * Use krb5_free_host_realm() to release @a realmsp when it is no longer + * needed. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_fallback_host_realm(krb5_context context, + krb5_data *hdata, char ***realmsp); + +/** + * Free the memory allocated by krb5_get_host_realm(). + * + * @param [in] context Library context + * @param [in] realmlist List of realm names to be released + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_free_host_realm(krb5_context context, char *const *realmlist); + +/** + * Determine if a principal is authorized to log in as a local user. + * + * @param [in] context Library context + * @param [in] principal Principal name + * @param [in] luser Local username + * + * Determine whether @a principal is authorized to log in as a local user @a + * luser. + * + * @retval + * TRUE Principal is authorized to log in as user; FALSE otherwise. + */ +krb5_boolean KRB5_CALLCONV +krb5_kuserok(krb5_context context, krb5_principal principal, const char *luser); + +/** + * Generate auth context addresses from a connected socket. + * + * @param [in] context Library context + * @param [in] auth_context Authentication context + * @param [in] infd Connected socket descriptor + * @param [in] flags Flags + * + * This function sets the local and/or remote addresses in @a auth_context + * based on the local and remote endpoints of the socket @a infd. The + * following flags determine the operations performed: + * + * @li #KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR Generate local address. + * @li #KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR Generate remote address. + * @li #KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR Generate local address and port. + * @li #KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR Generate remote address and port. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_auth_con_genaddrs(krb5_context context, krb5_auth_context auth_context, + int infd, int flags); + +/** + * Set time offset field in a krb5_context structure. + * + * @param [in] context Library context + * @param [in] seconds Real time, seconds portion + * @param [in] microseconds Real time, microseconds portion + * + * This function sets the time offset in @a context to the difference between + * the system time and the real time as determined by @a seconds and @a + * microseconds. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_set_real_time(krb5_context context, krb5_timestamp seconds, + krb5_int32 microseconds); + +/** + * Return the time offsets from the os context. + * + * @param [in] context Library context + * @param [out] seconds Time offset, seconds portion + * @param [out] microseconds Time offset, microseconds portion + * + * This function returns the time offsets in @a context. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_time_offsets(krb5_context context, krb5_timestamp *seconds, krb5_int32 *microseconds); + +/* str_conv.c */ +/** + * Convert a string to an encryption type. + * + * @param [in] string String to convert to an encryption type + * @param [out] enctypep Encryption type + * + * @retval 0 Success; otherwise - EINVAL + */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_enctype(char *string, krb5_enctype *enctypep); + +/** + * Convert a string to a salt type. + * + * @param [in] string String to convert to an encryption type + * @param [out] salttypep Salt type to be filled in + * + * @retval 0 Success; otherwise - EINVAL + */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_salttype(char *string, krb5_int32 *salttypep); + +/** + * Convert a string to a checksum type. + * + * @param [in] string String to be converted + * @param [out] cksumtypep Checksum type to be filled in + * + * @retval 0 Success; otherwise - EINVAL + */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_cksumtype(char *string, krb5_cksumtype *cksumtypep); + +/** + * Convert a string to a timestamp. + * + * @param [in] string String to be converted + * @param [out] timestampp Pointer to timestamp + * + * @retval 0 Success; otherwise - EINVAL + */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_timestamp(char *string, krb5_timestamp *timestampp); + +/** + * Convert a string to a delta time value. + * + * @param [in] string String to be converted + * @param [out] deltatp Delta time to be filled in + * + * @retval 0 Success; otherwise - KRB5_DELTAT_BADFORMAT + */ +krb5_error_code KRB5_CALLCONV +krb5_string_to_deltat(char *string, krb5_deltat *deltatp); + +/** + * Convert an encryption type to a string. + * + * @param [in] enctype Encryption type + * @param [out] buffer Buffer to hold encryption type string + * @param [in] buflen Storage available in @a buffer + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_enctype_to_string(krb5_enctype enctype, char *buffer, size_t buflen); + +/** + * Convert an encryption type to a name or alias. + * + * @param [in] enctype Encryption type + * @param [in] shortest Flag + * @param [out] buffer Buffer to hold encryption type string + * @param [in] buflen Storage available in @a buffer + * + * If @a shortest is FALSE, this function returns the enctype's canonical name + * (like "aes128-cts-hmac-sha1-96"). If @a shortest is TRUE, it return the + * enctype's shortest alias (like "aes128-cts"). + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_enctype_to_name(krb5_enctype enctype, krb5_boolean shortest, + char *buffer, size_t buflen); + +/** + * Convert a salt type to a string. + * + * @param [in] salttype Salttype to convert + * @param [out] buffer Buffer to receive the converted string + * @param [in] buflen Storage available in @a buffer + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_salttype_to_string(krb5_int32 salttype, char *buffer, size_t buflen); + +/** + * Convert a checksum type to a string. + * + * @param [in] cksumtype Checksum type + * @param [out] buffer Buffer to hold converted checksum type + * @param [in] buflen Storage available in @a buffer + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_cksumtype_to_string(krb5_cksumtype cksumtype, char *buffer, size_t buflen); + +/** + * Convert a timestamp to a string. + * + * @param [in] timestamp Timestamp to convert + * @param [out] buffer Buffer to hold converted timestamp + * @param [in] buflen Storage available in @a buffer + * + * The string is returned in the locale's appropriate date and time + * representation. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_timestamp_to_string(krb5_timestamp timestamp, char *buffer, size_t buflen); + +/** + * Convert a timestamp to a string, with optional output padding + * + * @param [in] timestamp Timestamp to convert + * @param [out] buffer Buffer to hold the converted timestamp + * @param [in] buflen Length of buffer + * @param [in] pad Optional value to pad @a buffer if converted + * timestamp does not fill it + * + * If @a pad is not NULL, @a buffer is padded out to @a buflen - 1 characters + * with the value of *@a pad. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_timestamp_to_sfstring(krb5_timestamp timestamp, char *buffer, + size_t buflen, char *pad); + +/** + * Convert a relative time value to a string. + * + * @param [in] deltat Relative time value to convert + * @param [out] buffer Buffer to hold time string + * @param [in] buflen Storage available in @a buffer + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_deltat_to_string(krb5_deltat deltat, char *buffer, size_t buflen); + +/* The name of the Kerberos ticket granting service... and its size */ +#define KRB5_TGS_NAME "krbtgt" +#define KRB5_TGS_NAME_SIZE 6 + +/* flags for recvauth */ +#define KRB5_RECVAUTH_SKIP_VERSION 0x0001 +#define KRB5_RECVAUTH_BADAUTHVERS 0x0002 +/* initial ticket api functions */ + +/** Text for prompt used in prompter callback function. */ +typedef struct _krb5_prompt { + char *prompt; /**< The prompt to show to the user */ + int hidden; /**< Boolean; informative prompt or hidden (e.g. PIN) */ + krb5_data *reply; /**< Must be allocated before call to prompt routine */ +} krb5_prompt; + +/** Pointer to a prompter callback function. */ +typedef krb5_error_code +(KRB5_CALLCONV *krb5_prompter_fct)(krb5_context context, void *data, + const char *name, const char *banner, + int num_prompts, krb5_prompt prompts[]); + +/** + * Prompt user for password. + * + * @param [in] context Library context + * @param data Unused (callback argument) + * @param [in] name Name to output during prompt + * @param [in] banner Banner to output during prompt + * @param [in] num_prompts Number of prompts in @a prompts + * @param [in] prompts Array of prompts and replies + * + * This function is intended to be used as a prompter callback for + * krb5_get_init_creds_password() or krb5_init_creds_init(). + * + * Writes @a name and @a banner to stdout, each followed by a newline, then + * writes each prompt field in the @a prompts array, followed by ": ", and sets + * the reply field of the entry to a line of input read from stdin. If the + * hidden flag is set for a prompt, then terminal echoing is turned off when + * input is read. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + * + */ +krb5_error_code KRB5_CALLCONV +krb5_prompter_posix(krb5_context context, void *data, const char *name, + const char *banner, int num_prompts, + krb5_prompt prompts[]); + +/** + * Long-term password responder question + * + * This question is asked when the long-term password is needed. It has no + * challenge and the response is simply the password string. + * + * @version New in 1.11 + */ +#define KRB5_RESPONDER_QUESTION_PASSWORD "password" + +/** + * OTP responder question + * + * The OTP responder question is asked when the KDC indicates that an OTP + * value is required in order to complete the authentication. The JSON format + * of the challenge is: + * + * @n { + * @n "service": , + * @n "tokenInfo": [ + * @n { + * @n "flags": , + * @n "vendor": , + * @n "challenge": , + * @n "length": , + * @n "format": , + * @n "tokenID": , + * @n "algID": , + * @n }, + * @n ... + * @n ] + * @n } + * + * The answer to the question MUST be JSON formatted: + * + * @n { + * @n "tokeninfo": , + * @n "value": , + * @n "pin": , + * @n } + * + * For more detail, please see RFC 6560. + * + * @version New in 1.11 + */ +#define KRB5_RESPONDER_QUESTION_OTP "otp" + +/** + * These format constants identify the format of the token value. + */ +#define KRB5_RESPONDER_OTP_FORMAT_DECIMAL 0 +#define KRB5_RESPONDER_OTP_FORMAT_HEXADECIMAL 1 +#define KRB5_RESPONDER_OTP_FORMAT_ALPHANUMERIC 2 + +/** + * This flag indicates that the token value MUST be collected. + */ +#define KRB5_RESPONDER_OTP_FLAGS_COLLECT_TOKEN 0x0001 + +/** + * This flag indicates that the PIN value MUST be collected. + */ +#define KRB5_RESPONDER_OTP_FLAGS_COLLECT_PIN 0x0002 + +/** + * This flag indicates that the token is now in re-synchronization mode with + * the server. The user is expected to reply with the next code displayed on + * the token. + */ +#define KRB5_RESPONDER_OTP_FLAGS_NEXTOTP 0x0004 + +/** + * This flag indicates that the PIN MUST be returned as a separate item. This + * flag only takes effect if KRB5_RESPONDER_OTP_FLAGS_COLLECT_PIN is set. If + * this flag is not set, the responder may either concatenate PIN + token value + * and store it as "value" in the answer or it may return them separately. If + * they are returned separately, they will be concatenated internally. + */ +#define KRB5_RESPONDER_OTP_FLAGS_SEPARATE_PIN 0x0008 + +/** + * PKINIT responder question + * + * The PKINIT responder question is asked when the client needs a password + * that's being used to protect key information, and is formatted as a JSON + * object. A specific identity's flags value, if not zero, is the bitwise-OR + * of one or more of the KRB5_RESPONDER_PKINIT_FLAGS_TOKEN_* flags defined + * below, and possibly other flags to be added later. Any resemblance to + * similarly-named CKF_* values in the PKCS#11 API should not be depended on. + * + * @n { + * @n identity : flags , + * @n ... + * @n } + * + * The answer to the question MUST be JSON formatted: + * + * @n { + * @n identity : password , + * @n ... + * @n } + * + * @version New in 1.12 + */ +#define KRB5_RESPONDER_QUESTION_PKINIT "pkinit" + +/** + * This flag indicates that an incorrect PIN was supplied at least once since + * the last time the correct PIN was supplied. + */ +#define KRB5_RESPONDER_PKINIT_FLAGS_TOKEN_USER_PIN_COUNT_LOW (1 << 0) + +/** + * This flag indicates that supplying an incorrect PIN will cause the token to + * lock itself. + */ +#define KRB5_RESPONDER_PKINIT_FLAGS_TOKEN_USER_PIN_FINAL_TRY (1 << 1) + +/** + * This flag indicates that the user PIN is locked, and you can't log in to the + * token with it. + */ +#define KRB5_RESPONDER_PKINIT_FLAGS_TOKEN_USER_PIN_LOCKED (1 << 2) + +/** + * A container for a set of preauthentication questions and answers + * + * A responder context is supplied by the krb5 authentication system to a @ref + * krb5_responder_fn callback. It contains a list of questions and can receive + * answers. Questions contained in a responder context can be listed using + * krb5_responder_list_questions(), retrieved using + * krb5_responder_get_challenge(), or answered using + * krb5_responder_set_answer(). The form of a question's challenge and + * answer depend on the question name. + * + * @version New in 1.11 + */ +typedef struct krb5_responder_context_st *krb5_responder_context; + +/** + * List the question names contained in the responder context. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * + * Return a pointer to a null-terminated list of question names which are + * present in @a rctx. The pointer is an alias, valid only as long as the + * lifetime of @a rctx, and should not be modified or freed by the caller. A + * question's challenge can be retrieved using krb5_responder_get_challenge() + * and answered using krb5_responder_set_answer(). + * + * @version New in 1.11 + */ +const char * const * KRB5_CALLCONV +krb5_responder_list_questions(krb5_context ctx, krb5_responder_context rctx); + +/** + * Retrieve the challenge data for a given question in the responder context. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] question Question name + * + * Return a pointer to a C string containing the challenge for @a question + * within @a rctx, or NULL if the question is not present in @a rctx. The + * structure of the question depends on the question name, but will always be + * printable UTF-8 text. The returned pointer is an alias, valid only as long + * as the lifetime of @a rctx, and should not be modified or freed by the + * caller. + * + * @version New in 1.11 + */ +const char * KRB5_CALLCONV +krb5_responder_get_challenge(krb5_context ctx, krb5_responder_context rctx, + const char *question); + +/** + * Answer a named question in the responder context. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] question Question name + * @param [in] answer The string to set (MUST be printable UTF-8) + * + * This function supplies an answer to @a question within @a rctx. The + * appropriate form of the answer depends on the question name. + * + * @retval EINVAL @a question is not present within @a rctx + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_responder_set_answer(krb5_context ctx, krb5_responder_context rctx, + const char *question, const char *answer); + +/** + * Responder function for an initial credential exchange. + * + * @param [in] ctx Library context + * @param [in] data Callback data + * @param [in] rctx Responder context + * + * A responder function is like a prompter function, but is used for handling + * questions and answers as potentially complex data types. Client + * preauthentication modules will insert a set of named "questions" into + * the responder context. Each question may optionally contain a challenge. + * This challenge is printable UTF-8, but may be an encoded value. The + * precise encoding and contents of the challenge are specific to the question + * asked. When the responder is called, it should answer all the questions it + * understands. Like the challenge, the answer MUST be printable UTF-8, but + * may contain structured/encoded data formatted to the expected answer format + * of the question. + * + * If a required question is unanswered, the prompter may be called. + */ +typedef krb5_error_code +(KRB5_CALLCONV *krb5_responder_fn)(krb5_context ctx, void *data, + krb5_responder_context rctx); + +typedef struct _krb5_responder_otp_tokeninfo { + krb5_flags flags; + krb5_int32 format; /* -1 when not specified. */ + krb5_int32 length; /* -1 when not specified. */ + char *vendor; + char *challenge; + char *token_id; + char *alg_id; +} krb5_responder_otp_tokeninfo; + +typedef struct _krb5_responder_otp_challenge { + char *service; + krb5_responder_otp_tokeninfo **tokeninfo; +} krb5_responder_otp_challenge; + +/** + * Decode the KRB5_RESPONDER_QUESTION_OTP to a C struct. + * + * A convenience function which parses the KRB5_RESPONDER_QUESTION_OTP + * question challenge data, making it available in native C. The main feature + * of this function is the ability to interact with OTP tokens without parsing + * the JSON. + * + * The returned value must be passed to krb5_responder_otp_challenge_free() to + * be freed. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [out] chl Challenge structure + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_responder_otp_get_challenge(krb5_context ctx, + krb5_responder_context rctx, + krb5_responder_otp_challenge **chl); + +/** + * Answer the KRB5_RESPONDER_QUESTION_OTP question. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] ti The index of the tokeninfo selected + * @param [in] value The value to set, or NULL for none + * @param [in] pin The pin to set, or NULL for none + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_responder_otp_set_answer(krb5_context ctx, krb5_responder_context rctx, + size_t ti, const char *value, const char *pin); + +/** + * Free the value returned by krb5_responder_otp_get_challenge(). + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] chl The challenge to free + * + * @version New in 1.11 + */ +void KRB5_CALLCONV +krb5_responder_otp_challenge_free(krb5_context ctx, + krb5_responder_context rctx, + krb5_responder_otp_challenge *chl); + +typedef struct _krb5_responder_pkinit_identity { + char *identity; + krb5_int32 token_flags; /* 0 when not specified or not applicable. */ +} krb5_responder_pkinit_identity; + +typedef struct _krb5_responder_pkinit_challenge { + krb5_responder_pkinit_identity **identities; +} krb5_responder_pkinit_challenge; + +/** + * Decode the KRB5_RESPONDER_QUESTION_PKINIT to a C struct. + * + * A convenience function which parses the KRB5_RESPONDER_QUESTION_PKINIT + * question challenge data, making it available in native C. The main feature + * of this function is the ability to read the challenge without parsing + * the JSON. + * + * The returned value must be passed to krb5_responder_pkinit_challenge_free() + * to be freed. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [out] chl_out Challenge structure + * + * @version New in 1.12 + */ +krb5_error_code KRB5_CALLCONV +krb5_responder_pkinit_get_challenge(krb5_context ctx, + krb5_responder_context rctx, + krb5_responder_pkinit_challenge **chl_out); + +/** + * Answer the KRB5_RESPONDER_QUESTION_PKINIT question for one identity. + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] identity The identity for which a PIN is being supplied + * @param [in] pin The provided PIN, or NULL for none + * + * @version New in 1.12 + */ +krb5_error_code KRB5_CALLCONV +krb5_responder_pkinit_set_answer(krb5_context ctx, krb5_responder_context rctx, + const char *identity, const char *pin); + +/** + * Free the value returned by krb5_responder_pkinit_get_challenge(). + * + * @param [in] ctx Library context + * @param [in] rctx Responder context + * @param [in] chl The challenge to free + * + * @version New in 1.12 + */ +void KRB5_CALLCONV +krb5_responder_pkinit_challenge_free(krb5_context ctx, + krb5_responder_context rctx, + krb5_responder_pkinit_challenge *chl); + +/** Store options for @c _krb5_get_init_creds */ +typedef struct _krb5_get_init_creds_opt { + krb5_flags flags; + krb5_deltat tkt_life; + krb5_deltat renew_life; + int forwardable; + int proxiable; + krb5_enctype *etype_list; + int etype_list_length; + krb5_address **address_list; + krb5_preauthtype *preauth_list; + int preauth_list_length; + krb5_data *salt; +} krb5_get_init_creds_opt; + +#define KRB5_GET_INIT_CREDS_OPT_TKT_LIFE 0x0001 +#define KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE 0x0002 +#define KRB5_GET_INIT_CREDS_OPT_FORWARDABLE 0x0004 +#define KRB5_GET_INIT_CREDS_OPT_PROXIABLE 0x0008 +#define KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST 0x0010 +#define KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST 0x0020 +#define KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST 0x0040 +#define KRB5_GET_INIT_CREDS_OPT_SALT 0x0080 +#define KRB5_GET_INIT_CREDS_OPT_CHG_PWD_PRMPT 0x0100 +#define KRB5_GET_INIT_CREDS_OPT_CANONICALIZE 0x0200 +#define KRB5_GET_INIT_CREDS_OPT_ANONYMOUS 0x0400 + + +/** + * Allocate a new initial credential options structure. + * + * @param [in] context Library context + * @param [out] opt New options structure + * + * This function is the preferred way to create an options structure for + * getting initial credentials, and is required to make use of certain options. + * Use krb5_get_init_creds_opt_free() to free @a opt when it is no longer + * needed. + * + * @retval 0 - Success; Kerberos errors otherwise. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_alloc(krb5_context context, + krb5_get_init_creds_opt **opt); + +/** + * Free initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options structure to free + * + * @sa krb5_get_init_creds_opt_alloc() + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_free(krb5_context context, + krb5_get_init_creds_opt *opt); + +/** @deprecated Use krb5_get_init_creds_opt_alloc() instead. */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_init(krb5_get_init_creds_opt *opt); + +/** + * Set the ticket lifetime in initial credential options. + * + * @param [in] opt Options structure + * @param [in] tkt_life Ticket lifetime + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt *opt, + krb5_deltat tkt_life); + +/** + * Set the ticket renewal lifetime in initial credential options. + * + * @param [in] opt Pointer to @a options field + * @param [in] renew_life Ticket renewal lifetime + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt *opt, + krb5_deltat renew_life); + +/** + * Set or unset the forwardable flag in initial credential options. + * + * @param [in] opt Options structure + * @param [in] forwardable Whether credentials should be forwardable + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt *opt, + int forwardable); + +/** + * Set or unset the proxiable flag in initial credential options. + * + * @param [in] opt Options structure + * @param [in] proxiable Whether credentials should be proxiable + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt *opt, + int proxiable); + +/** + * Set or unset the canonicalize flag in initial credential options. + * + * @param [in] opt Options structure + * @param [in] canonicalize Whether to canonicalize client principal + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_canonicalize(krb5_get_init_creds_opt *opt, + int canonicalize); + +/** + * Set or unset the anonymous flag in initial credential options. + * + * @param [in] opt Options structure + * @param [in] anonymous Whether to make an anonymous request + * + * This function may be used to request anonymous credentials from the KDC by + * setting @a anonymous to non-zero. Note that anonymous credentials are only + * a request; clients must verify that credentials are anonymous if that is a + * requirement. + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt *opt, + int anonymous); + +/** + * Set allowable encryption types in initial credential options. + * + * @param [in] opt Options structure + * @param [in] etype_list Array of encryption types + * @param [in] etype_list_length Length of @a etype_list + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt *opt, + krb5_enctype *etype_list, + int etype_list_length); + +/** + * Set address restrictions in initial credential options. + * + * @param [in] opt Options structure + * @param [in] addresses Null-terminated array of addresses + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt *opt, + krb5_address **addresses); + +/** + * Set preauthentication types in initial credential options. + * + * @param [in] opt Options structure + * @param [in] preauth_list Array of preauthentication types + * @param [in] preauth_list_length Length of @a preauth_list + * + * This function can be used to perform optimistic preauthentication when + * getting initial credentials, in combination with + * krb5_get_init_creds_opt_set_salt() and krb5_get_init_creds_opt_set_pa(). + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt *opt, + krb5_preauthtype *preauth_list, + int preauth_list_length); + +/** + * Set salt for optimistic preauthentication in initial credential options. + * + * @param [in] opt Options structure + * @param [in] salt Salt data + * + * When getting initial credentials with a password, a salt string it used to + * convert the password to a key. Normally this salt is obtained from the + * first KDC reply, but when performing optimistic preauthentication, the + * client may need to supply the salt string with this function. + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt *opt, + krb5_data *salt); + +/** + * Set or unset change-password-prompt flag in initial credential options. + * + * @param [in] opt Options structure + * @param [in] prompt Whether to prompt to change password + * + * This flag is on by default. It controls whether + * krb5_get_init_creds_password() will react to an expired-password error by + * prompting for a new password and attempting to change the old one. + */ +void KRB5_CALLCONV +krb5_get_init_creds_opt_set_change_password_prompt(krb5_get_init_creds_opt *opt, + int prompt); + +/** Generic preauth option attribute/value pairs */ +typedef struct _krb5_gic_opt_pa_data { + char *attr; + char *value; +} krb5_gic_opt_pa_data; + +/** + * Supply options for preauthentication in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options structure + * @param [in] attr Preauthentication option name + * @param [in] value Preauthentication option value + * + * This function allows the caller to supply options for preauthentication. + * The values of @a attr and @a value are supplied to each preauthentication + * module available within @a context. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_pa(krb5_context context, + krb5_get_init_creds_opt *opt, const char *attr, + const char *value); + +/** + * Set location of FAST armor ccache in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [in] fast_ccache_name Credential cache name + * + * Sets the location of a credential cache containing an armor ticket to + * protect an initial credential exchange using the FAST protocol extension. + * + * In version 1.7, setting an armor ccache requires that FAST be used for the + * exchange. In version 1.8 or later, setting the armor ccache causes FAST to + * be used if the KDC supports it; krb5_get_init_creds_opt_set_fast_flags() + * must be used to require that FAST be used. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_fast_ccache_name(krb5_context context, + krb5_get_init_creds_opt *opt, + const char *fast_ccache_name); + +/** + * Set FAST armor cache in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [in] ccache Credential cache handle + * + * This function is similar to krb5_get_init_creds_opt_set_fast_ccache_name(), + * but uses a credential cache handle instead of a name. + * + * @version New in 1.9 + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_fast_ccache(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_ccache ccache); + +/** + * Set an input credential cache in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [in] ccache Credential cache handle + * + * If an input credential cache is set, then the krb5_get_init_creds family of + * APIs will read settings from it. Setting an input ccache is desirable when + * the application wishes to perform authentication in the same way (using the + * same preauthentication mechanisms, and making the same non-security- + * sensitive choices) as the previous authentication attempt, which stored + * information in the passed-in ccache. + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_in_ccache(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_ccache ccache); + +/** + * Set an output credential cache in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [in] ccache Credential cache handle + * + * If an output credential cache is set, then the krb5_get_init_creds family of + * APIs will write credentials to it. Setting an output ccache is desirable + * both because it simplifies calling code and because it permits the + * krb5_get_init_creds APIs to write out configuration information about the + * realm to the ccache. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_out_ccache(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_ccache ccache); + +/** + * @brief Ask the KDC to include or not include a PAC in the ticket + * + * @param [in] context Library context + * @param [in] opt Options structure + * @param [in] req_pac Whether to request a PAC or not + * + * If this option is set, the AS request will include a PAC-REQUEST pa-data + * item explicitly asking the KDC to either include or not include a privilege + * attribute certificate in the ticket authorization data. By default, no + * request is made; typically the KDC will default to including a PAC if it + * supports them. + * + * @version New in 1.15 + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_pac_request(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_boolean req_pac); + +/** + * Set FAST flags in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [in] flags FAST flags + * + * The following flag values are valid: + * @li #KRB5_FAST_REQUIRED - Require FAST to be used + * + * @retval + * 0 - Success; Kerberos errors otherwise. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_fast_flags(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_flags flags); + +/** + * Retrieve FAST flags from initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options + * @param [out] out_flags FAST flags + * + * @retval + * 0 - Success; Kerberos errors otherwise. + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_get_fast_flags(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_flags *out_flags); + +/* Fast flags*/ +#define KRB5_FAST_REQUIRED 0x0001 /**< Require KDC to support FAST*/ + +typedef void +(KRB5_CALLCONV *krb5_expire_callback_func)(krb5_context context, void *data, + krb5_timestamp password_expiration, + krb5_timestamp account_expiration, + krb5_boolean is_last_req); + +/** + * Set an expiration callback in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options structure + * @param [in] cb Callback function + * @param [in] data Callback argument + * + * Set a callback to receive password and account expiration times. + * + * This option only applies to krb5_get_init_creds_password(). @a cb will be + * invoked if and only if credentials are successfully acquired. The callback + * will receive the @a context from the krb5_get_init_creds_password() call and + * the @a data argument supplied with this API. The remaining arguments should + * be interpreted as follows: + * + * If @a is_last_req is true, then the KDC reply contained last-req entries + * which unambiguously indicated the password expiration, account expiration, + * or both. (If either value was not present, the corresponding argument will + * be 0.) Furthermore, a non-zero @a password_expiration should be taken as a + * suggestion from the KDC that a warning be displayed. + * + * If @a is_last_req is false, then @a account_expiration will be 0 and @a + * password_expiration will contain the expiration time of either the password + * or account, or 0 if no expiration time was indicated in the KDC reply. The + * callback should independently decide whether to display a password + * expiration warning. + * + * Note that @a cb may be invoked even if credentials are being acquired for + * the kadmin/changepw service in order to change the password. It is the + * caller's responsibility to avoid displaying a password expiry warning in + * this case. + * + * @warning Setting an expire callback with this API will cause + * krb5_get_init_creds_password() not to send password expiry warnings to the + * prompter, as it ordinarily may. + * + * @version New in 1.9 + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_expire_callback(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_expire_callback_func cb, + void *data); + +/** + * Set the responder function in initial credential options. + * + * @param [in] context Library context + * @param [in] opt Options structure + * @param [in] responder Responder function + * @param [in] data Responder data argument + * + * @version New in 1.11 + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_opt_set_responder(krb5_context context, + krb5_get_init_creds_opt *opt, + krb5_responder_fn responder, void *data); + +/** + * Get initial credentials using a password. + * + * @param [in] context Library context + * @param [out] creds New credentials + * @param [in] client Client principal + * @param [in] password Password (or NULL) + * @param [in] prompter Prompter function + * @param [in] data Prompter callback data + * @param [in] start_time Time when ticket becomes valid (0 for now) + * @param [in] in_tkt_service Service name of initial credentials (or NULL) + * @param [in] k5_gic_options Initial credential options + * + * This function requests KDC for an initial credentials for @a client using @a + * password. If @a password is NULL, a password will be prompted for using @a + * prompter if necessary. If @a in_tkt_service is specified, it is parsed as a + * principal name (with the realm ignored) and used as the service principal + * for the request; otherwise the ticket-granting service is used. + * + * @sa krb5_verify_init_creds() + * + * @retval + * 0 Success + * @retval + * EINVAL Invalid argument + * @retval + * KRB5_KDC_UNREACH Cannot contact any KDC for requested realm + * @retval + * KRB5_PREAUTH_FAILED Generic Pre-athentication failure + * @retval + * KRB5_LIBOS_PWDINTR Password read interrupted + * @retval + * KRB5_REALM_CANT_RESOLVE Cannot resolve network address for KDC in requested realm + * @retval + * KRB5KDC_ERR_KEY_EXP Password has expired + * @retval + * KRB5_LIBOS_BADPWDMATCH Password mismatch + * @retval + * KRB5_CHPW_PWDNULL New password cannot be zero length + * @retval + * KRB5_CHPW_FAIL Password change failed + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_password(krb5_context context, krb5_creds *creds, + krb5_principal client, const char *password, + krb5_prompter_fct prompter, void *data, + krb5_deltat start_time, + const char *in_tkt_service, + krb5_get_init_creds_opt *k5_gic_options); + +/** + * Retrieve enctype, salt and s2kparams from KDC + * + * @param [in] context Library context + * @param [in] principal Principal whose information is requested + * @param [in] opt Initial credential options + * @param [out] enctype_out The enctype chosen by KDC + * @param [out] salt_out Salt returned from KDC + * @param [out] s2kparams_out String-to-key parameters returned from KDC + * + * Send an initial ticket request for @a principal and extract the encryption + * type, salt type, and string-to-key parameters from the KDC response. If the + * KDC provides no etype-info, set @a enctype_out to @c ENCTYPE_NULL and set @a + * salt_out and @a s2kparams_out to empty. If the KDC etype-info provides no + * salt, compute the default salt and place it in @a salt_out. If the KDC + * etype-info provides no string-to-key parameters, set @a s2kparams_out to + * empty. + * + * @a opt may be used to specify options which affect the initial request, such + * as request encryption types or a FAST armor cache (see + * krb5_get_init_creds_opt_set_etype_list() and + * krb5_get_init_creds_opt_set_fast_ccache_name()). + * + * Use krb5_free_data_contents() to free @a salt_out and @a s2kparams_out when + * they are no longer needed. + * + * @version New in 1.17 + * + * @retval 0 Success + * @return A Kerberos error code + */ +krb5_error_code KRB5_CALLCONV +krb5_get_etype_info(krb5_context context, krb5_principal principal, + krb5_get_init_creds_opt *opt, krb5_enctype *enctype_out, + krb5_data *salt_out, krb5_data *s2kparams_out); + +struct _krb5_init_creds_context; +typedef struct _krb5_init_creds_context *krb5_init_creds_context; + +#define KRB5_INIT_CREDS_STEP_FLAG_CONTINUE 0x1 /**< More responses needed */ + +/** + * Free an initial credentials context. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * + * @a context must be the same as the one passed to krb5_init_creds_init() for + * this initial credentials context. + */ +void KRB5_CALLCONV +krb5_init_creds_free(krb5_context context, krb5_init_creds_context ctx); + +/** + * Acquire credentials using an initial credentials context. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * + * This function synchronously obtains credentials using a context created by + * krb5_init_creds_init(). On successful return, the credentials can be + * retrieved with krb5_init_creds_get_creds(). + * + * @a context must be the same as the one passed to krb5_init_creds_init() for + * this initial credentials context. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_get(krb5_context context, krb5_init_creds_context ctx); + +/** + * Retrieve acquired credentials from an initial credentials context. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [out] creds Acquired credentials + * + * This function copies the acquired initial credentials from @a ctx into @a + * creds, after the successful completion of krb5_init_creds_get() or + * krb5_init_creds_step(). Use krb5_free_cred_contents() to free @a creds when + * it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_get_creds(krb5_context context, krb5_init_creds_context ctx, + krb5_creds *creds); + +/** + * Get the last error from KDC from an initial credentials context. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [out] error Error from KDC, or NULL if none was received + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_get_error(krb5_context context, krb5_init_creds_context ctx, + krb5_error **error); + +/** + * Create a context for acquiring initial credentials. + * + * @param [in] context Library context + * @param [in] client Client principal to get initial creds for + * @param [in] prompter Prompter callback + * @param [in] data Prompter callback argument + * @param [in] start_time Time when credentials become valid (0 for now) + * @param [in] options Options structure (NULL for default) + * @param [out] ctx New initial credentials context + * + * This function creates a new context for acquiring initial credentials. Use + * krb5_init_creds_free() to free @a ctx when it is no longer needed. + * + * Any subsequent calls to krb5_init_creds_step(), krb5_init_creds_get(), or + * krb5_init_creds_free() for this initial credentials context must use the + * same @a context argument as the one passed to this function. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_init(krb5_context context, krb5_principal client, + krb5_prompter_fct prompter, void *data, + krb5_deltat start_time, krb5_get_init_creds_opt *options, + krb5_init_creds_context *ctx); + +/** + * Specify a keytab to use for acquiring initial credentials. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [in] keytab Key table handle + * + * This function supplies a keytab containing the client key for an initial + * credentials request. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_set_keytab(krb5_context context, krb5_init_creds_context ctx, + krb5_keytab keytab); + +/** + * Get the next KDC request for acquiring initial credentials. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [in] in KDC response (empty on the first call) + * @param [out] out Next KDC request + * @param [out] realm Realm for next KDC request + * @param [out] flags Output flags + * + * This function constructs the next KDC request in an initial credential + * exchange, allowing the caller to control the transport of KDC requests and + * replies. On the first call, @a in should be set to an empty buffer; on + * subsequent calls, it should be set to the KDC's reply to the previous + * request. + * + * If more requests are needed, @a flags will be set to + * #KRB5_INIT_CREDS_STEP_FLAG_CONTINUE and the next request will be placed in + * @a out. If no more requests are needed, @a flags will not contain + * #KRB5_INIT_CREDS_STEP_FLAG_CONTINUE and @a out will be empty. + * + * If this function returns @c KRB5KRB_ERR_RESPONSE_TOO_BIG, the caller should + * transmit the next request using TCP rather than UDP. If this function + * returns any other error, the initial credential exchange has failed. + * + * @a context must be the same as the one passed to krb5_init_creds_init() for + * this initial credentials context. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_step(krb5_context context, krb5_init_creds_context ctx, + krb5_data *in, krb5_data *out, krb5_data *realm, + unsigned int *flags); + +/** + * Set a password for acquiring initial credentials. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [in] password Password + * + * This function supplies a password to be used to construct the client key for + * an initial credentials request. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_set_password(krb5_context context, krb5_init_creds_context ctx, + const char *password); + +/** + * Specify a service principal for acquiring initial credentials. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [in] service Service principal string + * + * This function supplies a service principal string to acquire initial + * credentials for instead of the default krbtgt service. @a service is parsed + * as a principal name; any realm part is ignored. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_set_service(krb5_context context, krb5_init_creds_context ctx, + const char *service); + +/** + * Retrieve ticket times from an initial credentials context. + * + * @param [in] context Library context + * @param [in] ctx Initial credentials context + * @param [out] times Ticket times for acquired credentials + * + * The initial credentials context must have completed obtaining credentials + * via either krb5_init_creds_get() or krb5_init_creds_step(). + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_init_creds_get_times(krb5_context context, krb5_init_creds_context ctx, + krb5_ticket_times *times); + +struct _krb5_tkt_creds_context; +typedef struct _krb5_tkt_creds_context *krb5_tkt_creds_context; + +/** + * Create a context to get credentials from a KDC's Ticket Granting Service. + * + * @param[in] context Library context + * @param[in] ccache Credential cache handle + * @param[in] creds Input credentials + * @param[in] options @ref KRB5_GC options for this request. + * @param[out] ctx New TGS request context + * + * This function prepares to obtain credentials matching @a creds, either by + * retrieving them from @a ccache or by making requests to ticket-granting + * services beginning with a ticket-granting ticket for the client principal's + * realm. + * + * The resulting TGS acquisition context can be used asynchronously with + * krb5_tkt_creds_step() or synchronously with krb5_tkt_creds_get(). See also + * krb5_get_credentials() for synchronous use. + * + * Use krb5_tkt_creds_free() to free @a ctx when it is no longer needed. + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_tkt_creds_init(krb5_context context, krb5_ccache ccache, + krb5_creds *creds, krb5_flags options, + krb5_tkt_creds_context *ctx); + +/** + * Synchronously obtain credentials using a TGS request context. + * + * @param[in] context Library context + * @param[in] ctx TGS request context + * + * This function synchronously obtains credentials using a context created by + * krb5_tkt_creds_init(). On successful return, the credentials can be + * retrieved with krb5_tkt_creds_get_creds(). + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_tkt_creds_get(krb5_context context, krb5_tkt_creds_context ctx); + +/** + * Retrieve acquired credentials from a TGS request context. + * + * @param[in] context Library context + * @param[in] ctx TGS request context + * @param[out] creds Acquired credentials + * + * This function copies the acquired initial credentials from @a ctx into @a + * creds, after the successful completion of krb5_tkt_creds_get() or + * krb5_tkt_creds_step(). Use krb5_free_cred_contents() to free @a creds when + * it is no longer needed. + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_tkt_creds_get_creds(krb5_context context, krb5_tkt_creds_context ctx, + krb5_creds *creds); + +/** + * Free a TGS request context. + * + * @param[in] context Library context + * @param[in] ctx TGS request context + * + * @version New in 1.9 + */ +void KRB5_CALLCONV +krb5_tkt_creds_free(krb5_context context, krb5_tkt_creds_context ctx); + +#define KRB5_TKT_CREDS_STEP_FLAG_CONTINUE 0x1 /**< More responses needed */ + +/** + * Get the next KDC request in a TGS exchange. + * + * @param[in] context Library context + * @param[in] ctx TGS request context + * @param[in] in KDC response (empty on the first call) + * @param[out] out Next KDC request + * @param[out] realm Realm for next KDC request + * @param[out] flags Output flags + * + * This function constructs the next KDC request for a TGS exchange, allowing + * the caller to control the transport of KDC requests and replies. On the + * first call, @a in should be set to an empty buffer; on subsequent calls, it + * should be set to the KDC's reply to the previous request. + * + * If more requests are needed, @a flags will be set to + * #KRB5_TKT_CREDS_STEP_FLAG_CONTINUE and the next request will be placed in @a + * out. If no more requests are needed, @a flags will not contain + * #KRB5_TKT_CREDS_STEP_FLAG_CONTINUE and @a out will be empty. + * + * If this function returns @c KRB5KRB_ERR_RESPONSE_TOO_BIG, the caller should + * transmit the next request using TCP rather than UDP. If this function + * returns any other error, the TGS exchange has failed. + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_tkt_creds_step(krb5_context context, krb5_tkt_creds_context ctx, + krb5_data *in, krb5_data *out, krb5_data *realm, + unsigned int *flags); + +/** + * Retrieve ticket times from a TGS request context. + * + * @param[in] context Library context + * @param[in] ctx TGS request context + * @param[out] times Ticket times for acquired credentials + * + * The TGS request context must have completed obtaining credentials via either + * krb5_tkt_creds_get() or krb5_tkt_creds_step(). + * + * @version New in 1.9 + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_tkt_creds_get_times(krb5_context context, krb5_tkt_creds_context ctx, + krb5_ticket_times *times); + +/** + * Get initial credentials using a key table. + * + * @param [in] context Library context + * @param [out] creds New credentials + * @param [in] client Client principal + * @param [in] arg_keytab Key table handle + * @param [in] start_time Time when ticket becomes valid (0 for now) + * @param [in] in_tkt_service Service name of initial credentials (or NULL) + * @param [in] k5_gic_options Initial credential options + * + * This function requests KDC for an initial credentials for @a client using a + * client key stored in @a arg_keytab. If @a in_tkt_service is specified, it + * is parsed as a principal name (with the realm ignored) and used as the + * service principal for the request; otherwise the ticket-granting service is + * used. + * + * @sa krb5_verify_init_creds() + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_init_creds_keytab(krb5_context context, krb5_creds *creds, + krb5_principal client, krb5_keytab arg_keytab, + krb5_deltat start_time, const char *in_tkt_service, + krb5_get_init_creds_opt *k5_gic_options); + +typedef struct _krb5_verify_init_creds_opt { + krb5_flags flags; + int ap_req_nofail; /**< boolean */ +} krb5_verify_init_creds_opt; + +#define KRB5_VERIFY_INIT_CREDS_OPT_AP_REQ_NOFAIL 0x0001 + +/** + * Initialize a credential verification options structure. + * + * @param [in] k5_vic_options Verification options structure + */ +void KRB5_CALLCONV +krb5_verify_init_creds_opt_init(krb5_verify_init_creds_opt *k5_vic_options); + +/** + * Set whether credential verification is required. + * + * @param [in] k5_vic_options Verification options structure + * @param [in] ap_req_nofail Whether to require successful verification + * + * This function determines how krb5_verify_init_creds() behaves if no keytab + * information is available. If @a ap_req_nofail is @c FALSE, verification + * will be skipped in this case and krb5_verify_init_creds() will return + * successfully. If @a ap_req_nofail is @c TRUE, krb5_verify_init_creds() will + * not return successfully unless verification can be performed. + * + * If this function is not used, the behavior of krb5_verify_init_creds() is + * determined through configuration. + */ +void KRB5_CALLCONV +krb5_verify_init_creds_opt_set_ap_req_nofail(krb5_verify_init_creds_opt * k5_vic_options, + int ap_req_nofail); + +/** + * Verify initial credentials against a keytab. + * + * @param [in] context Library context + * @param [in] creds Initial credentials to be verified + * @param [in] server Server principal (or NULL) + * @param [in] keytab Key table (NULL to use default keytab) + * @param [in] ccache Credential cache for fetched creds (or NULL) + * @param [in] options Verification options (NULL for default options) + * + * This function attempts to verify that @a creds were obtained from a KDC with + * knowledge of a key in @a keytab, or the default keytab if @a keytab is NULL. + * If @a server is provided, the highest-kvno key entry for that principal name + * is used to verify the credentials; otherwise, all unique "host" service + * principals in the keytab are tried. + * + * If the specified keytab does not exist, or is empty, or cannot be read, or + * does not contain an entry for @a server, then credential verification may be + * skipped unless configuration demands that it succeed. The caller can + * control this behavior by providing a verification options structure; see + * krb5_verify_init_creds_opt_init() and + * krb5_verify_init_creds_opt_set_ap_req_nofail(). + * + * If @a ccache is NULL, any additional credentials fetched during the + * verification process will be destroyed. If @a ccache points to NULL, a + * memory ccache will be created for the additional credentials and returned in + * @a ccache. If @a ccache points to a valid credential cache handle, the + * additional credentials will be stored in that cache. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_verify_init_creds(krb5_context context, krb5_creds *creds, + krb5_principal server, krb5_keytab keytab, + krb5_ccache *ccache, + krb5_verify_init_creds_opt *options); + +/** + * Get validated credentials from the KDC. + * + * @param [in] context Library context + * @param [out] creds Validated credentials + * @param [in] client Client principal name + * @param [in] ccache Credential cache + * @param [in] in_tkt_service Server principal string (or NULL) + * + * This function gets a validated credential using a postdated credential from + * @a ccache. If @a in_tkt_service is specified, it is parsed (with the realm + * part ignored) and used as the server principal of the credential; + * otherwise, the ticket-granting service is used. + * + * If successful, the validated credential is placed in @a creds. + * + * @sa krb5_get_renewed_creds() + * + * @retval + * 0 Success + * @retval + * KRB5_NO_2ND_TKT Request missing second ticket + * @retval + * KRB5_NO_TKT_SUPPLIED Request did not supply a ticket + * @retval + * KRB5_PRINC_NOMATCH Requested principal and ticket do not match + * @retval + * KRB5_KDCREP_MODIFIED KDC reply did not match expectations + * @retval + * KRB5_KDCREP_SKEW Clock skew too great in KDC reply + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_validated_creds(krb5_context context, krb5_creds *creds, + krb5_principal client, krb5_ccache ccache, + const char *in_tkt_service); + +/** + * Get renewed credential from KDC using an existing credential. + * + * @param [in] context Library context + * @param [out] creds Renewed credentials + * @param [in] client Client principal name + * @param [in] ccache Credential cache + * @param [in] in_tkt_service Server principal string (or NULL) + * + * This function gets a renewed credential using an existing one from @a + * ccache. If @a in_tkt_service is specified, it is parsed (with the realm + * part ignored) and used as the server principal of the credential; otherwise, + * the ticket-granting service is used. + * + * If successful, the renewed credential is placed in @a creds. + * + * @retval + * 0 Success + * @return + * Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_get_renewed_creds(krb5_context context, krb5_creds *creds, + krb5_principal client, krb5_ccache ccache, + const char *in_tkt_service); + +/** + * Decode an ASN.1-formatted ticket. + * + * @param [in] code ASN.1-formatted ticket + * @param [out] rep Decoded ticket information + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_decode_ticket(const krb5_data *code, krb5_ticket **rep); + +/** + * Retrieve a string value from the appdefaults section of krb5.conf. + * + * @param [in] context Library context + * @param [in] appname Application name + * @param [in] realm Realm name + * @param [in] option Option to be checked + * @param [in] default_value Default value to return if no match is found + * @param [out] ret_value String value of @a option + * + * This function gets the application defaults for @a option based on the given + * @a appname and/or @a realm. + * + * @sa krb5_appdefault_boolean() + */ +void KRB5_CALLCONV +krb5_appdefault_string(krb5_context context, const char *appname, + const krb5_data *realm, const char *option, + const char *default_value, char ** ret_value); + +/** + * Retrieve a boolean value from the appdefaults section of krb5.conf. + * + * @param [in] context Library context + * @param [in] appname Application name + * @param [in] realm Realm name + * @param [in] option Option to be checked + * @param [in] default_value Default value to return if no match is found + * @param [out] ret_value Boolean value of @a option + * + * This function gets the application defaults for @a option based on the given + * @a appname and/or @a realm. + * + * @sa krb5_appdefault_string() + */ +void KRB5_CALLCONV +krb5_appdefault_boolean(krb5_context context, const char *appname, + const krb5_data *realm, const char *option, + int default_value, int *ret_value); + +/* + * Prompter enhancements + */ +/** Prompt for password */ +#define KRB5_PROMPT_TYPE_PASSWORD 0x1 +/** Prompt for new password (during password change) */ +#define KRB5_PROMPT_TYPE_NEW_PASSWORD 0x2 +/** Prompt for new password again */ +#define KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN 0x3 +/** Prompt for preauthentication data (such as an OTP value) */ +#define KRB5_PROMPT_TYPE_PREAUTH 0x4 + +typedef krb5_int32 krb5_prompt_type; + +/** + * Get prompt types array from a context. + * + * @param [in] context Library context + * + * @return + * Pointer to an array of prompt types corresponding to the prompter's @a + * prompts arguments. Each type has one of the following values: + * @li #KRB5_PROMPT_TYPE_PASSWORD + * @li #KRB5_PROMPT_TYPE_NEW_PASSWORD + * @li #KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN + * @li #KRB5_PROMPT_TYPE_PREAUTH + */ +krb5_prompt_type* KRB5_CALLCONV +krb5_get_prompt_types(krb5_context context); + +/* Error reporting */ +/** + * Set an extended error message for an error code. + * + * @param [in] ctx Library context + * @param [in] code Error code + * @param [in] fmt Error string for the error code + * @param [in] ... printf(3) style parameters + */ +void KRB5_CALLCONV_C +krb5_set_error_message(krb5_context ctx, krb5_error_code code, const char *fmt, ...) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 4))) +#endif + ; + +/** + * Set an extended error message for an error code using a va_list. + * + * @param [in] ctx Library context + * @param [in] code Error code + * @param [in] fmt Error string for the error code + * @param [in] args List of vprintf(3) style arguments + */ +void KRB5_CALLCONV +krb5_vset_error_message(krb5_context ctx, krb5_error_code code, + const char *fmt, va_list args) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 0))) +#endif + ; + +/** + * Add a prefix to the message for an error code. + * + * @param [in] ctx Library context + * @param [in] code Error code + * @param [in] fmt Format string for error message prefix + * @param [in] ... printf(3) style parameters + * + * Format a message and prepend it to the current message for @a code. The + * prefix will be separated from the old message with a colon and space. + */ +void KRB5_CALLCONV_C +krb5_prepend_error_message(krb5_context ctx, krb5_error_code code, + const char *fmt, ...) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 4))) +#endif + ; + +/** + * Add a prefix to the message for an error code using a va_list. + * + * @param [in] ctx Library context + * @param [in] code Error code + * @param [in] fmt Format string for error message prefix + * @param [in] args List of vprintf(3) style arguments + * + * This function is similar to krb5_prepend_error_message(), but uses a + * va_list instead of variadic arguments. + */ +void KRB5_CALLCONV +krb5_vprepend_error_message(krb5_context ctx, krb5_error_code code, + const char *fmt, va_list args) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 3, 0))) +#endif + ; + +/** + * Add a prefix to a different error code's message. + * + * @param [in] ctx Library context + * @param [in] old_code Previous error code + * @param [in] code Error code + * @param [in] fmt Format string for error message prefix + * @param [in] ... printf(3) style parameters + * + * Format a message and prepend it to the message for @a old_code. The prefix + * will be separated from the old message with a colon and space. Set the + * resulting message as the extended error message for @a code. + */ +void KRB5_CALLCONV_C +krb5_wrap_error_message(krb5_context ctx, krb5_error_code old_code, + krb5_error_code code, const char *fmt, ...) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 4, 5))) +#endif + ; + +/** + * Add a prefix to a different error code's message using a va_list. + * + * @param [in] ctx Library context + * @param [in] old_code Previous error code + * @param [in] code Error code + * @param [in] fmt Format string for error message prefix + * @param [in] args List of vprintf(3) style arguments + * + * This function is similar to krb5_wrap_error_message(), but uses a + * va_list instead of variadic arguments. + */ +void KRB5_CALLCONV +krb5_vwrap_error_message(krb5_context ctx, krb5_error_code old_code, + krb5_error_code code, const char *fmt, va_list args) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 4, 0))) +#endif + ; + +/** + * Copy the most recent extended error message from one context to another. + * + * @param [in] dest_ctx Library context to copy message to + * @param [in] src_ctx Library context with current message + */ +void KRB5_CALLCONV +krb5_copy_error_message(krb5_context dest_ctx, krb5_context src_ctx); + +/** + * Get the (possibly extended) error message for a code. + * + * @param [in] ctx Library context + * @param [in] code Error code + * + * The behavior of krb5_get_error_message() is only defined the first time it + * is called after a failed call to a krb5 function using the same context, and + * only when the error code passed in is the same as that returned by the krb5 + * function. + * + * This function never returns NULL, so its result may be used unconditionally + * as a C string. + * + * The string returned by this function must be freed using + * krb5_free_error_message() + * + * @note Future versions may return the same string for the second + * and following calls. + */ +const char * KRB5_CALLCONV +krb5_get_error_message(krb5_context ctx, krb5_error_code code); + +/** + * Free an error message generated by krb5_get_error_message(). + * + * @param [in] ctx Library context + * @param [in] msg Pointer to error message + */ +void KRB5_CALLCONV +krb5_free_error_message(krb5_context ctx, const char *msg); + +/** + * Clear the extended error message in a context. + * + * @param [in] ctx Library context + * + * This function unsets the extended error message in a context, to ensure that + * it is not mistakenly applied to another occurrence of the same error code. + */ +void KRB5_CALLCONV +krb5_clear_error_message(krb5_context ctx); + +/** + * Unwrap authorization data. + * + * @param [in] context Library context + * @param [in] type @ref KRB5_AUTHDATA type of @a container + * @param [in] container Authorization data to be decoded + * @param [out] authdata List of decoded authorization data + * + * @sa krb5_encode_authdata_container() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_decode_authdata_container(krb5_context context, + krb5_authdatatype type, + const krb5_authdata *container, + krb5_authdata ***authdata); +/** + * Wrap authorization data in a container. + * + * @param [in] context Library context + * @param [in] type @ref KRB5_AUTHDATA type of @a container + * @param [in] authdata List of authorization data to be encoded + * @param [out] container List of encoded authorization data + * + * The result is returned in @a container as a single-element list. + * + * @sa krb5_decode_authdata_container() + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_encode_authdata_container(krb5_context context, + krb5_authdatatype type, + krb5_authdata * const*authdata, + krb5_authdata ***container); + +/* + * AD-KDCIssued + */ +/** + * Encode and sign AD-KDCIssued authorization data. + * + * @param [in] context Library context + * @param [in] key Session key + * @param [in] issuer The name of the issuing principal + * @param [in] authdata List of authorization data to be signed + * @param [out] ad_kdcissued List containing AD-KDCIssued authdata + * + * This function wraps a list of authorization data entries @a authdata in an + * AD-KDCIssued container (see RFC 4120 section 5.2.6.2) signed with @a key. + * The result is returned in @a ad_kdcissued as a single-element list. + */ +krb5_error_code KRB5_CALLCONV +krb5_make_authdata_kdc_issued(krb5_context context, + const krb5_keyblock *key, + krb5_const_principal issuer, + krb5_authdata *const *authdata, + krb5_authdata ***ad_kdcissued); + +/** + * Unwrap and verify AD-KDCIssued authorization data. + * + * @param [in] context Library context + * @param [in] key Session key + * @param [in] ad_kdcissued AD-KDCIssued authorization data to be unwrapped + * @param [out] issuer Name of issuing principal (or NULL) + * @param [out] authdata Unwrapped list of authorization data + * + * This function unwraps an AD-KDCIssued authdatum (see RFC 4120 section + * 5.2.6.2) and verifies its signature against @a key. The issuer field of the + * authdatum element is returned in @a issuer, and the unwrapped list of + * authdata is returned in @a authdata. + */ +krb5_error_code KRB5_CALLCONV +krb5_verify_authdata_kdc_issued(krb5_context context, + const krb5_keyblock *key, + const krb5_authdata *ad_kdcissued, + krb5_principal *issuer, + krb5_authdata ***authdata); + +/* + * Windows PAC + */ + +/* Microsoft defined types of data */ +#define KRB5_PAC_LOGON_INFO 1 /**< Logon information */ +#define KRB5_PAC_CREDENTIALS_INFO 2 /**< Credentials information */ +#define KRB5_PAC_SERVER_CHECKSUM 6 /**< Server checksum */ +#define KRB5_PAC_PRIVSVR_CHECKSUM 7 /**< KDC checksum */ +#define KRB5_PAC_CLIENT_INFO 10 /**< Client name and ticket info */ +#define KRB5_PAC_DELEGATION_INFO 11 /**< Constrained delegation info */ +#define KRB5_PAC_UPN_DNS_INFO 12 /**< User principal name and DNS info */ + +struct krb5_pac_data; +/** PAC data structure to convey authorization information */ +typedef struct krb5_pac_data *krb5_pac; + +/** + * Add a buffer to a PAC handle. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] type Buffer type + * @param [in] data contents + * + * This function adds a buffer of type @a type and contents @a data to @a pac + * if there isn't already a buffer of this type present. + * + * The valid values of @a type is one of the following: + * @li #KRB5_PAC_LOGON_INFO - Logon information + * @li #KRB5_PAC_CREDENTIALS_INFO - Credentials information + * @li #KRB5_PAC_SERVER_CHECKSUM - Server checksum + * @li #KRB5_PAC_PRIVSVR_CHECKSUM - KDC checksum + * @li #KRB5_PAC_CLIENT_INFO - Client name and ticket information + * @li #KRB5_PAC_DELEGATION_INFO - Constrained delegation information + * @li #KRB5_PAC_UPN_DNS_INFO - User principal name and DNS information + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_add_buffer(krb5_context context, krb5_pac pac, krb5_ui_4 type, + const krb5_data *data); + +/** + * Free a PAC handle. + * + * @param [in] context Library context + * @param [in] pac PAC to be freed + * + * This function frees the contents of @a pac and the structure itself. + */ +void KRB5_CALLCONV +krb5_pac_free(krb5_context context, krb5_pac pac); + +/** + * Retrieve a buffer value from a PAC. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] type Type of buffer to retrieve + * @param [out] data Buffer value + * + * Use krb5_free_data_contents() to free @a data when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_get_buffer(krb5_context context, krb5_pac pac, krb5_ui_4 type, + krb5_data *data); + +/** + * Return an array of buffer types in a PAC handle. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [out] len Number of entries in @a types + * @param [out] types Array of buffer types + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_get_types(krb5_context context, krb5_pac pac, size_t *len, + krb5_ui_4 **types); + +/** + * Create an empty Privilege Attribute Certificate (PAC) handle. + * + * @param [in] context Library context + * @param [out] pac New PAC handle + * + * Use krb5_pac_free() to free @a pac when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_init(krb5_context context, krb5_pac *pac); + +/** + * Unparse an encoded PAC into a new handle. + * + * @param [in] context Library context + * @param [in] ptr PAC buffer + * @param [in] len Length of @a ptr + * @param [out] pac PAC handle + * + * Use krb5_pac_free() to free @a pac when it is no longer needed. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_parse(krb5_context context, const void *ptr, size_t len, + krb5_pac *pac); + +/** + * Verify a PAC. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] authtime Expected timestamp + * @param [in] principal Expected principal name (or NULL) + * @param [in] server Key to validate server checksum (or NULL) + * @param [in] privsvr Key to validate KDC checksum (or NULL) + * + * This function validates @a pac against the supplied @a server, @a privsvr, + * @a principal and @a authtime. If @a principal is NULL, the principal and + * authtime are not verified. If @a server or @a privsvr is NULL, the + * corresponding checksum is not verified. + * + * If successful, @a pac is marked as verified. + * + * @note A checksum mismatch can occur if the PAC was copied from a cross-realm + * TGT by an ignorant KDC; also macOS Server Open Directory (as of 10.6) + * generates PACs with no server checksum at all. One should consider not + * failing the whole authentication because of this reason, but, instead, + * treating the ticket as if it did not contain a PAC or marking the PAC + * information as non-verified. + * + * @retval 0 Success; otherwise - Kerberos error codes + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_verify(krb5_context context, const krb5_pac pac, + krb5_timestamp authtime, krb5_const_principal principal, + const krb5_keyblock *server, const krb5_keyblock *privsvr); + +/** + * Verify a PAC, possibly from a specified realm. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] authtime Expected timestamp + * @param [in] principal Expected principal name (or NULL) + * @param [in] server Key to validate server checksum (or NULL) + * @param [in] privsvr Key to validate KDC checksum (or NULL) + * @param [in] with_realm If true, expect the realm of @a principal + * + * This function is similar to krb5_pac_verify(), but adds a parameter + * @a with_realm. If @a with_realm is true, the PAC_CLIENT_INFO field is + * expected to include the realm of @a principal as well as the name. This + * flag is necessary to verify PACs in cross-realm S4U2Self referral TGTs. + * + * @version New in 1.17 + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_verify_ext(krb5_context context, const krb5_pac pac, + krb5_timestamp authtime, krb5_const_principal principal, + const krb5_keyblock *server, const krb5_keyblock *privsvr, + krb5_boolean with_realm); + +/** + * Sign a PAC. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] authtime Expected timestamp + * @param [in] principal Expected principal name (or NULL) + * @param [in] server_key Key for server checksum + * @param [in] privsvr_key Key for KDC checksum + * @param [out] data Signed PAC encoding + * + * This function signs @a pac using the keys @a server_key and @a privsvr_key + * and returns the signed encoding in @a data. @a pac is modified to include + * the server and KDC checksum buffers. Use krb5_free_data_contents() to free + * @a data when it is no longer needed. + * + * @version New in 1.10 + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_sign(krb5_context context, krb5_pac pac, krb5_timestamp authtime, + krb5_const_principal principal, const krb5_keyblock *server_key, + const krb5_keyblock *privsvr_key, krb5_data *data); + +/** + * Sign a PAC, possibly with a specified realm. + * + * @param [in] context Library context + * @param [in] pac PAC handle + * @param [in] authtime Expected timestamp + * @param [in] principal Principal name (or NULL) + * @param [in] server_key Key for server checksum + * @param [in] privsvr_key Key for KDC checksum + * @param [in] with_realm If true, include the realm of @a principal + * @param [out] data Signed PAC encoding + * + * This function is similar to krb5_pac_sign(), but adds a parameter + * @a with_realm. If @a with_realm is true, the PAC_CLIENT_INFO field of the + * signed PAC will include the realm of @a principal as well as the name. This + * flag is necessary to generate PACs for cross-realm S4U2Self referrals. + * + * @version New in 1.17 + */ +krb5_error_code KRB5_CALLCONV +krb5_pac_sign_ext(krb5_context context, krb5_pac pac, krb5_timestamp authtime, + krb5_const_principal principal, + const krb5_keyblock *server_key, + const krb5_keyblock *privsvr_key, krb5_boolean with_realm, + krb5_data *data); + +/** + * Allow the appplication to override the profile's allow_weak_crypto setting. + * + * @param [in] context Library context + * @param [in] enable Boolean flag + * + * This function allows an application to override the allow_weak_crypto + * setting. It is primarily for use by aklog. + * + * @retval 0 (always) + */ +krb5_error_code KRB5_CALLCONV +krb5_allow_weak_crypto(krb5_context context, krb5_boolean enable); + +/** + * A wrapper for passing information to a @c krb5_trace_callback. + * + * Currently, it only contains the formatted message as determined + * the the format string and arguments of the tracing macro, but it + * may be extended to contain more fields in the future. + */ +typedef struct _krb5_trace_info { + const char *message; +} krb5_trace_info; + +typedef void +(KRB5_CALLCONV *krb5_trace_callback)(krb5_context context, + const krb5_trace_info *info, + void *cb_data); + +/** + * Specify a callback function for trace events. + * + * @param [in] context Library context + * @param [in] fn Callback function + * @param [in] cb_data Callback data + * + * Specify a callback for trace events occurring in krb5 operations performed + * within @a context. @a fn will be invoked with @a context as the first + * argument, @a cb_data as the last argument, and a pointer to a + * krb5_trace_info as the second argument. If the trace callback is reset via + * this function or @a context is destroyed, @a fn will be invoked with a NULL + * second argument so it can clean up @a cb_data. Supply a NULL value for @a + * fn to disable trace callbacks within @a context. + * + * @note This function overrides the information passed through the + * @a KRB5_TRACE environment variable. + * + * @version New in 1.9 + * + * @return Returns KRB5_TRACE_NOSUPP if tracing is not supported in the library + * (unless @a fn is NULL). + */ +krb5_error_code KRB5_CALLCONV +krb5_set_trace_callback(krb5_context context, krb5_trace_callback fn, + void *cb_data); + +/** + * Specify a file name for directing trace events. + * + * @param [in] context Library context + * @param [in] filename File name + * + * Open @a filename for appending (creating it, if necessary) and set up a + * callback to write trace events to it. + * + * @note This function overrides the information passed through the + * @a KRB5_TRACE environment variable. + * + * @version New in 1.9 + * + * @retval KRB5_TRACE_NOSUPP Tracing is not supported in the library. + */ +krb5_error_code KRB5_CALLCONV +krb5_set_trace_filename(krb5_context context, const char *filename); + + +/** + * Hook function for inspecting or modifying messages sent to KDCs. + * + * @param [in] context Library context + * @param [in] data Callback data + * @param [in] realm The realm the message will be sent to + * @param [in] message The original message to be sent to the KDC + * @param [out] new_message_out Optional replacement message to be sent + * @param [out] reply_out Optional synthetic reply + * + * If the hook function returns an error code, the KDC communication will be + * aborted and the error code will be returned to the library operation which + * initiated the communication. + * + * If the hook function sets @a reply_out, @a message will not be sent to the + * KDC, and the given reply will used instead. + * + * If the hook function sets @a new_message_out, the given message will be sent + * to the KDC in place of @a message. + * + * If the hook function returns successfully without setting either output, + * @a message will be sent to the KDC normally. + * + * The hook function should use krb5_copy_data() to construct the value for + * @a new_message_out or @a reply_out, to ensure that it can be freed correctly + * by the library. + * + * @version New in 1.15 + * + * @retval 0 Success + * @return A Kerberos error code + */ +typedef krb5_error_code +(KRB5_CALLCONV *krb5_pre_send_fn)(krb5_context context, void *data, + const krb5_data *realm, + const krb5_data *message, + krb5_data **new_message_out, + krb5_data **new_reply_out); + +/** + * Hook function for inspecting or overriding KDC replies. + * + * @param [in] context Library context + * @param [in] data Callback data + * @param [in] code Status of KDC communication + * @param [in] realm The realm the reply was received from + * @param [in] message The message sent to the realm's KDC + * @param [in] reply The reply received from the KDC + * @param [out] new_reply_out Optional replacement reply + * + * If @a code is zero, @a reply contains the reply received from the KDC. The + * hook function may return an error code to simulate an error, may synthesize + * a different reply by setting @a new_reply_out, or may simply return + * successfully to do nothing. + * + * If @a code is non-zero, KDC communication failed and @a reply should be + * ignored. The hook function may return @a code or a different error code, or + * may synthesize a reply by setting @a new_reply_out and return successfully. + * + * The hook function should use krb5_copy_data() to construct the value for + * @a new_reply_out, to ensure that it can be freed correctly by the library. + * + * @version New in 1.15 + * + * @retval 0 Success + * @return A Kerberos error code + */ +typedef krb5_error_code +(KRB5_CALLCONV *krb5_post_recv_fn)(krb5_context context, void *data, + krb5_error_code code, + const krb5_data *realm, + const krb5_data *message, + const krb5_data *reply, + krb5_data **new_reply_out); + +/** + * Set a KDC pre-send hook function. + * + * @param [in] context Library context + * @param [in] send_hook Hook function (or NULL to disable the hook) + * @param [in] data Callback data to be passed to @a send_hook + * + * @a send_hook will be called before messages are sent to KDCs by library + * functions such as krb5_get_credentials(). The hook function may inspect, + * override, or synthesize its own reply to the message. + * + * @version New in 1.15 + */ +void KRB5_CALLCONV +krb5_set_kdc_send_hook(krb5_context context, krb5_pre_send_fn send_hook, + void *data); + +/** + * Set a KDC post-receive hook function. + * + * @param [in] context The library context. + * @param [in] recv_hook Hook function (or NULL to disable the hook) + * @param [in] data Callback data to be passed to @a recv_hook + * + * @a recv_hook will be called after a reply is received from a KDC during a + * call to a library function such as krb5_get_credentials(). The hook + * function may inspect or override the reply. This hook will not be executed + * if the pre-send hook returns a synthetic reply. + * + * @version New in 1.15 + */ +void KRB5_CALLCONV +krb5_set_kdc_recv_hook(krb5_context context, krb5_post_recv_fn recv_hook, + void *data); + +#if defined(TARGET_OS_MAC) && TARGET_OS_MAC +# pragma pack(pop) +#endif + +KRB5INT_END_DECLS + +/* Don't use this! We're going to phase it out. It's just here to keep + applications from breaking right away. */ +#define krb5_const const + +#undef KRB5_ATTR_DEPRECATED + +/** @} */ /* end of KRB5_H group */ + +#endif /* KRB5_GENERAL__ */ +/* + * et-h-krb5_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KRB5KDC_ERR_NONE (-1765328384L) +#define KRB5KDC_ERR_NAME_EXP (-1765328383L) +#define KRB5KDC_ERR_SERVICE_EXP (-1765328382L) +#define KRB5KDC_ERR_BAD_PVNO (-1765328381L) +#define KRB5KDC_ERR_C_OLD_MAST_KVNO (-1765328380L) +#define KRB5KDC_ERR_S_OLD_MAST_KVNO (-1765328379L) +#define KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN (-1765328378L) +#define KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN (-1765328377L) +#define KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE (-1765328376L) +#define KRB5KDC_ERR_NULL_KEY (-1765328375L) +#define KRB5KDC_ERR_CANNOT_POSTDATE (-1765328374L) +#define KRB5KDC_ERR_NEVER_VALID (-1765328373L) +#define KRB5KDC_ERR_POLICY (-1765328372L) +#define KRB5KDC_ERR_BADOPTION (-1765328371L) +#define KRB5KDC_ERR_ETYPE_NOSUPP (-1765328370L) +#define KRB5KDC_ERR_SUMTYPE_NOSUPP (-1765328369L) +#define KRB5KDC_ERR_PADATA_TYPE_NOSUPP (-1765328368L) +#define KRB5KDC_ERR_TRTYPE_NOSUPP (-1765328367L) +#define KRB5KDC_ERR_CLIENT_REVOKED (-1765328366L) +#define KRB5KDC_ERR_SERVICE_REVOKED (-1765328365L) +#define KRB5KDC_ERR_TGT_REVOKED (-1765328364L) +#define KRB5KDC_ERR_CLIENT_NOTYET (-1765328363L) +#define KRB5KDC_ERR_SERVICE_NOTYET (-1765328362L) +#define KRB5KDC_ERR_KEY_EXP (-1765328361L) +#define KRB5KDC_ERR_PREAUTH_FAILED (-1765328360L) +#define KRB5KDC_ERR_PREAUTH_REQUIRED (-1765328359L) +#define KRB5KDC_ERR_SERVER_NOMATCH (-1765328358L) +#define KRB5KDC_ERR_MUST_USE_USER2USER (-1765328357L) +#define KRB5KDC_ERR_PATH_NOT_ACCEPTED (-1765328356L) +#define KRB5KDC_ERR_SVC_UNAVAILABLE (-1765328355L) +#define KRB5PLACEHOLD_30 (-1765328354L) +#define KRB5KRB_AP_ERR_BAD_INTEGRITY (-1765328353L) +#define KRB5KRB_AP_ERR_TKT_EXPIRED (-1765328352L) +#define KRB5KRB_AP_ERR_TKT_NYV (-1765328351L) +#define KRB5KRB_AP_ERR_REPEAT (-1765328350L) +#define KRB5KRB_AP_ERR_NOT_US (-1765328349L) +#define KRB5KRB_AP_ERR_BADMATCH (-1765328348L) +#define KRB5KRB_AP_ERR_SKEW (-1765328347L) +#define KRB5KRB_AP_ERR_BADADDR (-1765328346L) +#define KRB5KRB_AP_ERR_BADVERSION (-1765328345L) +#define KRB5KRB_AP_ERR_MSG_TYPE (-1765328344L) +#define KRB5KRB_AP_ERR_MODIFIED (-1765328343L) +#define KRB5KRB_AP_ERR_BADORDER (-1765328342L) +#define KRB5KRB_AP_ERR_ILL_CR_TKT (-1765328341L) +#define KRB5KRB_AP_ERR_BADKEYVER (-1765328340L) +#define KRB5KRB_AP_ERR_NOKEY (-1765328339L) +#define KRB5KRB_AP_ERR_MUT_FAIL (-1765328338L) +#define KRB5KRB_AP_ERR_BADDIRECTION (-1765328337L) +#define KRB5KRB_AP_ERR_METHOD (-1765328336L) +#define KRB5KRB_AP_ERR_BADSEQ (-1765328335L) +#define KRB5KRB_AP_ERR_INAPP_CKSUM (-1765328334L) +#define KRB5KRB_AP_PATH_NOT_ACCEPTED (-1765328333L) +#define KRB5KRB_ERR_RESPONSE_TOO_BIG (-1765328332L) +#define KRB5PLACEHOLD_53 (-1765328331L) +#define KRB5PLACEHOLD_54 (-1765328330L) +#define KRB5PLACEHOLD_55 (-1765328329L) +#define KRB5PLACEHOLD_56 (-1765328328L) +#define KRB5PLACEHOLD_57 (-1765328327L) +#define KRB5PLACEHOLD_58 (-1765328326L) +#define KRB5PLACEHOLD_59 (-1765328325L) +#define KRB5KRB_ERR_GENERIC (-1765328324L) +#define KRB5KRB_ERR_FIELD_TOOLONG (-1765328323L) +#define KRB5KDC_ERR_CLIENT_NOT_TRUSTED (-1765328322L) +#define KRB5KDC_ERR_KDC_NOT_TRUSTED (-1765328321L) +#define KRB5KDC_ERR_INVALID_SIG (-1765328320L) +#define KRB5KDC_ERR_DH_KEY_PARAMETERS_NOT_ACCEPTED (-1765328319L) +#define KRB5KDC_ERR_CERTIFICATE_MISMATCH (-1765328318L) +#define KRB5KRB_AP_ERR_NO_TGT (-1765328317L) +#define KRB5KDC_ERR_WRONG_REALM (-1765328316L) +#define KRB5KRB_AP_ERR_USER_TO_USER_REQUIRED (-1765328315L) +#define KRB5KDC_ERR_CANT_VERIFY_CERTIFICATE (-1765328314L) +#define KRB5KDC_ERR_INVALID_CERTIFICATE (-1765328313L) +#define KRB5KDC_ERR_REVOKED_CERTIFICATE (-1765328312L) +#define KRB5KDC_ERR_REVOCATION_STATUS_UNKNOWN (-1765328311L) +#define KRB5KDC_ERR_REVOCATION_STATUS_UNAVAILABLE (-1765328310L) +#define KRB5KDC_ERR_CLIENT_NAME_MISMATCH (-1765328309L) +#define KRB5KDC_ERR_KDC_NAME_MISMATCH (-1765328308L) +#define KRB5KDC_ERR_INCONSISTENT_KEY_PURPOSE (-1765328307L) +#define KRB5KDC_ERR_DIGEST_IN_CERT_NOT_ACCEPTED (-1765328306L) +#define KRB5KDC_ERR_PA_CHECKSUM_MUST_BE_INCLUDED (-1765328305L) +#define KRB5KDC_ERR_DIGEST_IN_SIGNED_DATA_NOT_ACCEPTED (-1765328304L) +#define KRB5KDC_ERR_PUBLIC_KEY_ENCRYPTION_NOT_SUPPORTED (-1765328303L) +#define KRB5PLACEHOLD_82 (-1765328302L) +#define KRB5PLACEHOLD_83 (-1765328301L) +#define KRB5PLACEHOLD_84 (-1765328300L) +#define KRB5KRB_AP_ERR_IAKERB_KDC_NOT_FOUND (-1765328299L) +#define KRB5KRB_AP_ERR_IAKERB_KDC_NO_RESPONSE (-1765328298L) +#define KRB5PLACEHOLD_87 (-1765328297L) +#define KRB5PLACEHOLD_88 (-1765328296L) +#define KRB5PLACEHOLD_89 (-1765328295L) +#define KRB5KDC_ERR_PREAUTH_EXPIRED (-1765328294L) +#define KRB5KDC_ERR_MORE_PREAUTH_DATA_REQUIRED (-1765328293L) +#define KRB5PLACEHOLD_92 (-1765328292L) +#define KRB5KDC_ERR_UNKNOWN_CRITICAL_FAST_OPTION (-1765328291L) +#define KRB5PLACEHOLD_94 (-1765328290L) +#define KRB5PLACEHOLD_95 (-1765328289L) +#define KRB5PLACEHOLD_96 (-1765328288L) +#define KRB5PLACEHOLD_97 (-1765328287L) +#define KRB5PLACEHOLD_98 (-1765328286L) +#define KRB5PLACEHOLD_99 (-1765328285L) +#define KRB5KDC_ERR_NO_ACCEPTABLE_KDF (-1765328284L) +#define KRB5PLACEHOLD_101 (-1765328283L) +#define KRB5PLACEHOLD_102 (-1765328282L) +#define KRB5PLACEHOLD_103 (-1765328281L) +#define KRB5PLACEHOLD_104 (-1765328280L) +#define KRB5PLACEHOLD_105 (-1765328279L) +#define KRB5PLACEHOLD_106 (-1765328278L) +#define KRB5PLACEHOLD_107 (-1765328277L) +#define KRB5PLACEHOLD_108 (-1765328276L) +#define KRB5PLACEHOLD_109 (-1765328275L) +#define KRB5PLACEHOLD_110 (-1765328274L) +#define KRB5PLACEHOLD_111 (-1765328273L) +#define KRB5PLACEHOLD_112 (-1765328272L) +#define KRB5PLACEHOLD_113 (-1765328271L) +#define KRB5PLACEHOLD_114 (-1765328270L) +#define KRB5PLACEHOLD_115 (-1765328269L) +#define KRB5PLACEHOLD_116 (-1765328268L) +#define KRB5PLACEHOLD_117 (-1765328267L) +#define KRB5PLACEHOLD_118 (-1765328266L) +#define KRB5PLACEHOLD_119 (-1765328265L) +#define KRB5PLACEHOLD_120 (-1765328264L) +#define KRB5PLACEHOLD_121 (-1765328263L) +#define KRB5PLACEHOLD_122 (-1765328262L) +#define KRB5PLACEHOLD_123 (-1765328261L) +#define KRB5PLACEHOLD_124 (-1765328260L) +#define KRB5PLACEHOLD_125 (-1765328259L) +#define KRB5PLACEHOLD_126 (-1765328258L) +#define KRB5PLACEHOLD_127 (-1765328257L) +#define KRB5_ERR_RCSID (-1765328256L) +#define KRB5_LIBOS_BADLOCKFLAG (-1765328255L) +#define KRB5_LIBOS_CANTREADPWD (-1765328254L) +#define KRB5_LIBOS_BADPWDMATCH (-1765328253L) +#define KRB5_LIBOS_PWDINTR (-1765328252L) +#define KRB5_PARSE_ILLCHAR (-1765328251L) +#define KRB5_PARSE_MALFORMED (-1765328250L) +#define KRB5_CONFIG_CANTOPEN (-1765328249L) +#define KRB5_CONFIG_BADFORMAT (-1765328248L) +#define KRB5_CONFIG_NOTENUFSPACE (-1765328247L) +#define KRB5_BADMSGTYPE (-1765328246L) +#define KRB5_CC_BADNAME (-1765328245L) +#define KRB5_CC_UNKNOWN_TYPE (-1765328244L) +#define KRB5_CC_NOTFOUND (-1765328243L) +#define KRB5_CC_END (-1765328242L) +#define KRB5_NO_TKT_SUPPLIED (-1765328241L) +#define KRB5KRB_AP_WRONG_PRINC (-1765328240L) +#define KRB5KRB_AP_ERR_TKT_INVALID (-1765328239L) +#define KRB5_PRINC_NOMATCH (-1765328238L) +#define KRB5_KDCREP_MODIFIED (-1765328237L) +#define KRB5_KDCREP_SKEW (-1765328236L) +#define KRB5_IN_TKT_REALM_MISMATCH (-1765328235L) +#define KRB5_PROG_ETYPE_NOSUPP (-1765328234L) +#define KRB5_PROG_KEYTYPE_NOSUPP (-1765328233L) +#define KRB5_WRONG_ETYPE (-1765328232L) +#define KRB5_PROG_SUMTYPE_NOSUPP (-1765328231L) +#define KRB5_REALM_UNKNOWN (-1765328230L) +#define KRB5_SERVICE_UNKNOWN (-1765328229L) +#define KRB5_KDC_UNREACH (-1765328228L) +#define KRB5_NO_LOCALNAME (-1765328227L) +#define KRB5_MUTUAL_FAILED (-1765328226L) +#define KRB5_RC_TYPE_EXISTS (-1765328225L) +#define KRB5_RC_MALLOC (-1765328224L) +#define KRB5_RC_TYPE_NOTFOUND (-1765328223L) +#define KRB5_RC_UNKNOWN (-1765328222L) +#define KRB5_RC_REPLAY (-1765328221L) +#define KRB5_RC_IO (-1765328220L) +#define KRB5_RC_NOIO (-1765328219L) +#define KRB5_RC_PARSE (-1765328218L) +#define KRB5_RC_IO_EOF (-1765328217L) +#define KRB5_RC_IO_MALLOC (-1765328216L) +#define KRB5_RC_IO_PERM (-1765328215L) +#define KRB5_RC_IO_IO (-1765328214L) +#define KRB5_RC_IO_UNKNOWN (-1765328213L) +#define KRB5_RC_IO_SPACE (-1765328212L) +#define KRB5_TRANS_CANTOPEN (-1765328211L) +#define KRB5_TRANS_BADFORMAT (-1765328210L) +#define KRB5_LNAME_CANTOPEN (-1765328209L) +#define KRB5_LNAME_NOTRANS (-1765328208L) +#define KRB5_LNAME_BADFORMAT (-1765328207L) +#define KRB5_CRYPTO_INTERNAL (-1765328206L) +#define KRB5_KT_BADNAME (-1765328205L) +#define KRB5_KT_UNKNOWN_TYPE (-1765328204L) +#define KRB5_KT_NOTFOUND (-1765328203L) +#define KRB5_KT_END (-1765328202L) +#define KRB5_KT_NOWRITE (-1765328201L) +#define KRB5_KT_IOERR (-1765328200L) +#define KRB5_NO_TKT_IN_RLM (-1765328199L) +#define KRB5DES_BAD_KEYPAR (-1765328198L) +#define KRB5DES_WEAK_KEY (-1765328197L) +#define KRB5_BAD_ENCTYPE (-1765328196L) +#define KRB5_BAD_KEYSIZE (-1765328195L) +#define KRB5_BAD_MSIZE (-1765328194L) +#define KRB5_CC_TYPE_EXISTS (-1765328193L) +#define KRB5_KT_TYPE_EXISTS (-1765328192L) +#define KRB5_CC_IO (-1765328191L) +#define KRB5_FCC_PERM (-1765328190L) +#define KRB5_FCC_NOFILE (-1765328189L) +#define KRB5_FCC_INTERNAL (-1765328188L) +#define KRB5_CC_WRITE (-1765328187L) +#define KRB5_CC_NOMEM (-1765328186L) +#define KRB5_CC_FORMAT (-1765328185L) +#define KRB5_CC_NOT_KTYPE (-1765328184L) +#define KRB5_INVALID_FLAGS (-1765328183L) +#define KRB5_NO_2ND_TKT (-1765328182L) +#define KRB5_NOCREDS_SUPPLIED (-1765328181L) +#define KRB5_SENDAUTH_BADAUTHVERS (-1765328180L) +#define KRB5_SENDAUTH_BADAPPLVERS (-1765328179L) +#define KRB5_SENDAUTH_BADRESPONSE (-1765328178L) +#define KRB5_SENDAUTH_REJECTED (-1765328177L) +#define KRB5_PREAUTH_BAD_TYPE (-1765328176L) +#define KRB5_PREAUTH_NO_KEY (-1765328175L) +#define KRB5_PREAUTH_FAILED (-1765328174L) +#define KRB5_RCACHE_BADVNO (-1765328173L) +#define KRB5_CCACHE_BADVNO (-1765328172L) +#define KRB5_KEYTAB_BADVNO (-1765328171L) +#define KRB5_PROG_ATYPE_NOSUPP (-1765328170L) +#define KRB5_RC_REQUIRED (-1765328169L) +#define KRB5_ERR_BAD_HOSTNAME (-1765328168L) +#define KRB5_ERR_HOST_REALM_UNKNOWN (-1765328167L) +#define KRB5_SNAME_UNSUPP_NAMETYPE (-1765328166L) +#define KRB5KRB_AP_ERR_V4_REPLY (-1765328165L) +#define KRB5_REALM_CANT_RESOLVE (-1765328164L) +#define KRB5_TKT_NOT_FORWARDABLE (-1765328163L) +#define KRB5_FWD_BAD_PRINCIPAL (-1765328162L) +#define KRB5_GET_IN_TKT_LOOP (-1765328161L) +#define KRB5_CONFIG_NODEFREALM (-1765328160L) +#define KRB5_SAM_UNSUPPORTED (-1765328159L) +#define KRB5_SAM_INVALID_ETYPE (-1765328158L) +#define KRB5_SAM_NO_CHECKSUM (-1765328157L) +#define KRB5_SAM_BAD_CHECKSUM (-1765328156L) +#define KRB5_KT_NAME_TOOLONG (-1765328155L) +#define KRB5_KT_KVNONOTFOUND (-1765328154L) +#define KRB5_APPL_EXPIRED (-1765328153L) +#define KRB5_LIB_EXPIRED (-1765328152L) +#define KRB5_CHPW_PWDNULL (-1765328151L) +#define KRB5_CHPW_FAIL (-1765328150L) +#define KRB5_KT_FORMAT (-1765328149L) +#define KRB5_NOPERM_ETYPE (-1765328148L) +#define KRB5_CONFIG_ETYPE_NOSUPP (-1765328147L) +#define KRB5_OBSOLETE_FN (-1765328146L) +#define KRB5_EAI_FAIL (-1765328145L) +#define KRB5_EAI_NODATA (-1765328144L) +#define KRB5_EAI_NONAME (-1765328143L) +#define KRB5_EAI_SERVICE (-1765328142L) +#define KRB5_ERR_NUMERIC_REALM (-1765328141L) +#define KRB5_ERR_BAD_S2K_PARAMS (-1765328140L) +#define KRB5_ERR_NO_SERVICE (-1765328139L) +#define KRB5_CC_READONLY (-1765328138L) +#define KRB5_CC_NOSUPP (-1765328137L) +#define KRB5_DELTAT_BADFORMAT (-1765328136L) +#define KRB5_PLUGIN_NO_HANDLE (-1765328135L) +#define KRB5_PLUGIN_OP_NOTSUPP (-1765328134L) +#define KRB5_ERR_INVALID_UTF8 (-1765328133L) +#define KRB5_ERR_FAST_REQUIRED (-1765328132L) +#define KRB5_LOCAL_ADDR_REQUIRED (-1765328131L) +#define KRB5_REMOTE_ADDR_REQUIRED (-1765328130L) +#define KRB5_TRACE_NOSUPP (-1765328129L) +#define ERROR_TABLE_BASE_krb5 (-1765328384L) + +extern const struct error_table et_krb5_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_krb5_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_krb5_error_table() +#endif + +#if !defined(_WIN32) +#define init_krb5_err_tbl initialize_krb5_error_table +#define krb5_err_base ERROR_TABLE_BASE_krb5 +#endif +/* + * et-h-k5e1_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KRB5_PLUGIN_VER_NOTSUPP (-1750600192L) +#define KRB5_PLUGIN_BAD_MODULE_SPEC (-1750600191L) +#define KRB5_PLUGIN_NAME_NOTFOUND (-1750600190L) +#define KRB5KDC_ERR_DISCARD (-1750600189L) +#define KRB5_DCC_CANNOT_CREATE (-1750600188L) +#define KRB5_KCC_INVALID_ANCHOR (-1750600187L) +#define KRB5_KCC_UNKNOWN_VERSION (-1750600186L) +#define KRB5_KCC_INVALID_UID (-1750600185L) +#define KRB5_KCM_MALFORMED_REPLY (-1750600184L) +#define KRB5_KCM_RPC_ERROR (-1750600183L) +#define KRB5_KCM_REPLY_TOO_BIG (-1750600182L) +#define KRB5_KCM_NO_SERVER (-1750600181L) +#define ERROR_TABLE_BASE_k5e1 (-1750600192L) + +extern const struct error_table et_k5e1_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_k5e1_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_k5e1_error_table() +#endif + +#if !defined(_WIN32) +#define init_k5e1_err_tbl initialize_k5e1_error_table +#define k5e1_err_base ERROR_TABLE_BASE_k5e1 +#endif +/* + * et-h-kdb5_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KRB5_KDB_RCSID (-1780008448L) +#define KRB5_KDB_INUSE (-1780008447L) +#define KRB5_KDB_UK_SERROR (-1780008446L) +#define KRB5_KDB_UK_RERROR (-1780008445L) +#define KRB5_KDB_UNAUTH (-1780008444L) +#define KRB5_KDB_NOENTRY (-1780008443L) +#define KRB5_KDB_ILL_WILDCARD (-1780008442L) +#define KRB5_KDB_DB_INUSE (-1780008441L) +#define KRB5_KDB_DB_CHANGED (-1780008440L) +#define KRB5_KDB_TRUNCATED_RECORD (-1780008439L) +#define KRB5_KDB_RECURSIVELOCK (-1780008438L) +#define KRB5_KDB_NOTLOCKED (-1780008437L) +#define KRB5_KDB_BADLOCKMODE (-1780008436L) +#define KRB5_KDB_DBNOTINITED (-1780008435L) +#define KRB5_KDB_DBINITED (-1780008434L) +#define KRB5_KDB_ILLDIRECTION (-1780008433L) +#define KRB5_KDB_NOMASTERKEY (-1780008432L) +#define KRB5_KDB_BADMASTERKEY (-1780008431L) +#define KRB5_KDB_INVALIDKEYSIZE (-1780008430L) +#define KRB5_KDB_CANTREAD_STORED (-1780008429L) +#define KRB5_KDB_BADSTORED_MKEY (-1780008428L) +#define KRB5_KDB_NOACTMASTERKEY (-1780008427L) +#define KRB5_KDB_KVNONOMATCH (-1780008426L) +#define KRB5_KDB_STORED_MKEY_NOTCURRENT (-1780008425L) +#define KRB5_KDB_CANTLOCK_DB (-1780008424L) +#define KRB5_KDB_DB_CORRUPT (-1780008423L) +#define KRB5_KDB_BAD_VERSION (-1780008422L) +#define KRB5_KDB_BAD_SALTTYPE (-1780008421L) +#define KRB5_KDB_BAD_ENCTYPE (-1780008420L) +#define KRB5_KDB_BAD_CREATEFLAGS (-1780008419L) +#define KRB5_KDB_NO_PERMITTED_KEY (-1780008418L) +#define KRB5_KDB_NO_MATCHING_KEY (-1780008417L) +#define KRB5_KDB_DBTYPE_NOTFOUND (-1780008416L) +#define KRB5_KDB_DBTYPE_NOSUP (-1780008415L) +#define KRB5_KDB_DBTYPE_INIT (-1780008414L) +#define KRB5_KDB_SERVER_INTERNAL_ERR (-1780008413L) +#define KRB5_KDB_ACCESS_ERROR (-1780008412L) +#define KRB5_KDB_INTERNAL_ERROR (-1780008411L) +#define KRB5_KDB_CONSTRAINT_VIOLATION (-1780008410L) +#define KRB5_LOG_CONV (-1780008409L) +#define KRB5_LOG_UNSTABLE (-1780008408L) +#define KRB5_LOG_CORRUPT (-1780008407L) +#define KRB5_LOG_ERROR (-1780008406L) +#define KRB5_KDB_DBTYPE_MISMATCH (-1780008405L) +#define KRB5_KDB_POLICY_REF (-1780008404L) +#define KRB5_KDB_STRINGS_TOOLONG (-1780008403L) +#define ERROR_TABLE_BASE_kdb5 (-1780008448L) + +extern const struct error_table et_kdb5_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_kdb5_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_kdb5_error_table() +#endif + +#if !defined(_WIN32) +#define init_kdb5_err_tbl initialize_kdb5_error_table +#define kdb5_err_base ERROR_TABLE_BASE_kdb5 +#endif +/* + * et-h-kv5m_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KV5M_NONE (-1760647424L) +#define KV5M_PRINCIPAL (-1760647423L) +#define KV5M_DATA (-1760647422L) +#define KV5M_KEYBLOCK (-1760647421L) +#define KV5M_CHECKSUM (-1760647420L) +#define KV5M_ENCRYPT_BLOCK (-1760647419L) +#define KV5M_ENC_DATA (-1760647418L) +#define KV5M_CRYPTOSYSTEM_ENTRY (-1760647417L) +#define KV5M_CS_TABLE_ENTRY (-1760647416L) +#define KV5M_CHECKSUM_ENTRY (-1760647415L) +#define KV5M_AUTHDATA (-1760647414L) +#define KV5M_TRANSITED (-1760647413L) +#define KV5M_ENC_TKT_PART (-1760647412L) +#define KV5M_TICKET (-1760647411L) +#define KV5M_AUTHENTICATOR (-1760647410L) +#define KV5M_TKT_AUTHENT (-1760647409L) +#define KV5M_CREDS (-1760647408L) +#define KV5M_LAST_REQ_ENTRY (-1760647407L) +#define KV5M_PA_DATA (-1760647406L) +#define KV5M_KDC_REQ (-1760647405L) +#define KV5M_ENC_KDC_REP_PART (-1760647404L) +#define KV5M_KDC_REP (-1760647403L) +#define KV5M_ERROR (-1760647402L) +#define KV5M_AP_REQ (-1760647401L) +#define KV5M_AP_REP (-1760647400L) +#define KV5M_AP_REP_ENC_PART (-1760647399L) +#define KV5M_RESPONSE (-1760647398L) +#define KV5M_SAFE (-1760647397L) +#define KV5M_PRIV (-1760647396L) +#define KV5M_PRIV_ENC_PART (-1760647395L) +#define KV5M_CRED (-1760647394L) +#define KV5M_CRED_INFO (-1760647393L) +#define KV5M_CRED_ENC_PART (-1760647392L) +#define KV5M_PWD_DATA (-1760647391L) +#define KV5M_ADDRESS (-1760647390L) +#define KV5M_KEYTAB_ENTRY (-1760647389L) +#define KV5M_CONTEXT (-1760647388L) +#define KV5M_OS_CONTEXT (-1760647387L) +#define KV5M_ALT_METHOD (-1760647386L) +#define KV5M_ETYPE_INFO_ENTRY (-1760647385L) +#define KV5M_DB_CONTEXT (-1760647384L) +#define KV5M_AUTH_CONTEXT (-1760647383L) +#define KV5M_KEYTAB (-1760647382L) +#define KV5M_RCACHE (-1760647381L) +#define KV5M_CCACHE (-1760647380L) +#define KV5M_PREAUTH_OPS (-1760647379L) +#define KV5M_SAM_CHALLENGE (-1760647378L) +#define KV5M_SAM_CHALLENGE_2 (-1760647377L) +#define KV5M_SAM_KEY (-1760647376L) +#define KV5M_ENC_SAM_RESPONSE_ENC (-1760647375L) +#define KV5M_ENC_SAM_RESPONSE_ENC_2 (-1760647374L) +#define KV5M_SAM_RESPONSE (-1760647373L) +#define KV5M_SAM_RESPONSE_2 (-1760647372L) +#define KV5M_PREDICTED_SAM_RESPONSE (-1760647371L) +#define KV5M_PASSWD_PHRASE_ELEMENT (-1760647370L) +#define KV5M_GSS_OID (-1760647369L) +#define KV5M_GSS_QUEUE (-1760647368L) +#define KV5M_FAST_ARMORED_REQ (-1760647367L) +#define KV5M_FAST_REQ (-1760647366L) +#define KV5M_FAST_RESPONSE (-1760647365L) +#define KV5M_AUTHDATA_CONTEXT (-1760647364L) +#define ERROR_TABLE_BASE_kv5m (-1760647424L) + +extern const struct error_table et_kv5m_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_kv5m_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_kv5m_error_table() +#endif + +#if !defined(_WIN32) +#define init_kv5m_err_tbl initialize_kv5m_error_table +#define kv5m_err_base ERROR_TABLE_BASE_kv5m +#endif +/* + * et-h-krb524_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define KRB524_BADKEY (-1750206208L) +#define KRB524_BADADDR (-1750206207L) +#define KRB524_BADPRINC (-1750206206L) +#define KRB524_BADREALM (-1750206205L) +#define KRB524_V4ERR (-1750206204L) +#define KRB524_ENCFULL (-1750206203L) +#define KRB524_DECEMPTY (-1750206202L) +#define KRB524_NOTRESP (-1750206201L) +#define KRB524_KRB4_DISABLED (-1750206200L) +#define ERROR_TABLE_BASE_k524 (-1750206208L) + +extern const struct error_table et_k524_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_k524_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_k524_error_table() +#endif + +#if !defined(_WIN32) +#define init_k524_err_tbl initialize_k524_error_table +#define k524_err_base ERROR_TABLE_BASE_k524 +#endif +/* + * et-h-asn1_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define ASN1_BAD_TIMEFORMAT (1859794432L) +#define ASN1_MISSING_FIELD (1859794433L) +#define ASN1_MISPLACED_FIELD (1859794434L) +#define ASN1_TYPE_MISMATCH (1859794435L) +#define ASN1_OVERFLOW (1859794436L) +#define ASN1_OVERRUN (1859794437L) +#define ASN1_BAD_ID (1859794438L) +#define ASN1_BAD_LENGTH (1859794439L) +#define ASN1_BAD_FORMAT (1859794440L) +#define ASN1_PARSE_ERROR (1859794441L) +#define ASN1_BAD_GMTIME (1859794442L) +#define ASN1_MISMATCH_INDEF (1859794443L) +#define ASN1_MISSING_EOC (1859794444L) +#define ASN1_OMITTED (1859794445L) +#define ERROR_TABLE_BASE_asn1 (1859794432L) + +extern const struct error_table et_asn1_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_asn1_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_asn1_error_table() +#endif + +#if !defined(_WIN32) +#define init_asn1_err_tbl initialize_asn1_error_table +#define asn1_err_base ERROR_TABLE_BASE_asn1 +#endif +#endif /* KRB5_KRB5_H_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/localauth_plugin.h postgresql-hll-2.14/include/include/krb5/localauth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/localauth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/localauth_plugin.h 2020-12-12 17:06:43.221347703 +0800 @@ -0,0 +1,138 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2013 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Declarations for localauth plugin module implementors. + * + * The localauth pluggable interface currently has only one supported major + * version, which is 1. Major version 1 has a current minor version number of + * 1. + * + * Localauth plugin modules should define a function named + * localauth__initvt, matching the signature: + * + * krb5_error_code + * localauth_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_localauth_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_LOCALAUTH_PLUGIN_H +#define KRB5_LOCALAUTH_PLUGIN_H + +#include +#include + +/* An abstract type for localauth module data. */ +typedef struct krb5_localauth_moddata_st *krb5_localauth_moddata; + +/*** Method type declarations ***/ + +/* Optional: Initialize module data. */ +typedef krb5_error_code +(*krb5_localauth_init_fn)(krb5_context context, + krb5_localauth_moddata *data); + +/* Optional: Release resources used by module data. */ +typedef void +(*krb5_localauth_fini_fn)(krb5_context context, krb5_localauth_moddata data); + +/* + * Optional: Determine whether aname is authorized to log in as the local + * account lname. Return 0 if aname is authorized, EPERM if aname is + * authoritatively not authorized, KRB5_PLUGIN_NO_HANDLE if the module cannot + * determine whether aname is authorized, and any other error code for a + * serious failure to process the request. aname will be considered authorized + * if at least one module returns 0 and all other modules return + * KRB5_PLUGIN_NO_HANDLE. + */ +typedef krb5_error_code +(*krb5_localauth_userok_fn)(krb5_context context, krb5_localauth_moddata data, + krb5_const_principal aname, const char *lname); + +/* + * Optional (mandatory if an2ln_types is set): Determine the local account name + * corresponding to aname. Return 0 and set *lname_out if a mapping can be + * determined; the contents of *lname_out will later be released with a call to + * the module's free_string method. Return KRB5_LNAME_NOTRANS if no mapping + * can be determined. Return any other error code for a serious failure to + * process the request; this will halt the krb5_aname_to_localname operation. + * + * If the module's an2ln_types field is set, this method will only be invoked + * when a profile "auth_to_local" value references one of the module's types. + * type and residual will be set to the type and residual of the auth_to_local + * value. + * + * If the module's an2ln_types field is not set but the an2ln method is + * implemented, this method will be invoked independently of the profile's + * auth_to_local settings, with type and residual set to NULL. If multiple + * modules are registered with an2ln methods but no an2ln_types field, the + * order of invocation is not defined, but all such modules will be consulted + * before the built-in mechanisms are tried. + */ +typedef krb5_error_code +(*krb5_localauth_an2ln_fn)(krb5_context context, krb5_localauth_moddata data, + const char *type, const char *residual, + krb5_const_principal aname, char **lname_out); + +/* + * Optional (mandatory if an2ln is implemented): Release the memory returned by + * an invocation of an2ln. + */ +typedef void +(*krb5_localauth_free_string_fn)(krb5_context context, + krb5_localauth_moddata data, char *str); + +/* localauth vtable for major version 1. */ +typedef struct krb5_localauth_vtable_st { + const char *name; /* Mandatory: name of module. */ + const char **an2ln_types; /* Optional: uppercase auth_to_local types */ + krb5_localauth_init_fn init; + krb5_localauth_fini_fn fini; + krb5_localauth_userok_fn userok; + krb5_localauth_an2ln_fn an2ln; + krb5_localauth_free_string_fn free_string; + /* Minor version 1 ends here. */ +} *krb5_localauth_vtable; + +#endif /* KRB5_LOCALAUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/locate_plugin.h postgresql-hll-2.14/include/include/krb5/locate_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/locate_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/locate_plugin.h 2020-12-12 17:06:43.221347703 +0800 @@ -0,0 +1,61 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright 2006 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +/* + * + * Service location plugin definitions for Kerberos 5. + */ + +#ifndef KRB5_LOCATE_PLUGIN_H_INCLUDED +#define KRB5_LOCATE_PLUGIN_H_INCLUDED +#include + +enum locate_service_type { + locate_service_kdc = 1, + locate_service_master_kdc, + locate_service_kadmin, + locate_service_krb524, + locate_service_kpasswd +}; + +typedef struct krb5plugin_service_locate_ftable { + int minor_version; /* currently 0 */ + /* Per-context setup and teardown. Returned void* blob is + private to the plugin. */ + krb5_error_code (*init)(krb5_context, void **); + void (*fini)(void *); + /* Callback function returns non-zero if the plugin function + should quit and return; this may be because of an error, or may + indicate we've already contacted the service, whatever. The + lookup function should only return an error if it detects a + problem, not if the callback function tells it to quit. */ + krb5_error_code (*lookup)(void *, + enum locate_service_type svc, const char *realm, + int socktype, int family, + int (*cbfunc)(void *,int,struct sockaddr *), + void *cbdata); +} krb5plugin_service_locate_ftable; +/* extern krb5plugin_service_locate_ftable service_locator; */ +#endif diff -uprN postgresql-hll-2.14_old/include/include/krb5/plugin.h postgresql-hll-2.14/include/include/krb5/plugin.h --- postgresql-hll-2.14_old/include/include/krb5/plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/plugin.h 2020-12-12 17:06:43.221347703 +0800 @@ -0,0 +1,46 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2010 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +/* Generic declarations for dynamic modules implementing krb5 plugin + * modules. */ + +#ifndef KRB5_PLUGIN_H +#define KRB5_PLUGIN_H + +/* krb5_plugin_vtable is an abstract type. Module initvt functions will cast + * it to the appropriate interface-specific vtable type. */ +typedef struct krb5_plugin_vtable_st *krb5_plugin_vtable; + +/* + * krb5_plugin_initvt_fn is the type of all module initvt functions. Based on + * the maj_ver argument, the initvt function should cast vtable to the + * appropriate type and then fill it in. If a vtable has been expanded, + * min_ver indicates which version of the vtable is being filled in. + */ +typedef krb5_error_code +(*krb5_plugin_initvt_fn)(krb5_context context, int maj_ver, int min_ver, + krb5_plugin_vtable vtable); + +#endif /* KRB5_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/preauth_plugin.h postgresql-hll-2.14/include/include/krb5/preauth_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/preauth_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/preauth_plugin.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,41 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2012 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* This header includes the clpreauth and kdcpreauth interface declarations, + * for backward compatibility and convenience. */ + +#ifndef KRB5_PREAUTH_PLUGIN_H +#define KRB5_PREAUTH_PLUGIN_H + +#include +#include + +#endif /* KRB5_PREAUTH_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5/pwqual_plugin.h postgresql-hll-2.14/include/include/krb5/pwqual_plugin.h --- postgresql-hll-2.14_old/include/include/krb5/pwqual_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5/pwqual_plugin.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,109 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (C) 2010 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +/* + * Declarations for password quality plugin module implementors. + * + * The password quality pluggable interface currently has only one supported + * major version, which is 1. Major version 1 has a current minor version + * number of 1. + * + * Password quality plugin modules should define a function named + * pwqual__initvt, matching the signature: + * + * krb5_error_code + * pwqual_modname_initvt(krb5_context context, int maj_ver, int min_ver, + * krb5_plugin_vtable vtable); + * + * The initvt function should: + * + * - Check that the supplied maj_ver number is supported by the module, or + * return KRB5_PLUGIN_VER_NOTSUPP if it is not. + * + * - Cast the vtable pointer as appropriate for maj_ver: + * maj_ver == 1: Cast to krb5_pwqual_vtable + * + * - Initialize the methods of the vtable, stopping as appropriate for the + * supplied min_ver. Optional methods may be left uninitialized. + * + * Memory for the vtable is allocated by the caller, not by the module. + */ + +#ifndef KRB5_PWQUAL_PLUGIN_H +#define KRB5_PWQUAL_PLUGIN_H + +#include +#include +#include + +/* An abstract type for password quality module data. */ +typedef struct krb5_pwqual_moddata_st *krb5_pwqual_moddata; + +/*** Method type declarations ***/ + +/* Optional: Initialize module data. dictfile is the realm's configured + * dictionary filename. */ +typedef krb5_error_code +(*krb5_pwqual_open_fn)(krb5_context context, const char *dict_file, + krb5_pwqual_moddata *data); + +/* + * Mandatory: Check a password for the principal princ, which has an associated + * password policy named policy_name (or no associated policy if policy_name is + * NULL). The parameter languages, if not NULL, contains a null-terminated + * list of client-specified language tags as defined in RFC 5646. The method + * should return one of the following errors if the password fails quality + * standards: + * + * - KADM5_PASS_Q_TOOSHORT: password should be longer + * - KADM5_PASS_Q_CLASS: password must have more character classes + * - KADM5_PASS_Q_DICT: password contains dictionary words + * - KADM5_PASS_Q_GENERIC: unspecified quality failure + * + * The module should also set an extended error message with + * krb5_set_error_message(). The message may be localized according to one of + * the language tags in languages. + */ +typedef krb5_error_code +(*krb5_pwqual_check_fn)(krb5_context context, krb5_pwqual_moddata data, + const char *password, const char *policy_name, + krb5_principal princ, const char **languages); + +/* Optional: Release resources used by module data. */ +typedef void +(*krb5_pwqual_close_fn)(krb5_context context, krb5_pwqual_moddata data); + +/*** vtable declarations **/ + +/* Password quality plugin vtable for major version 1. */ +typedef struct krb5_pwqual_vtable_st { + const char *name; /* Mandatory: name of module. */ + krb5_pwqual_open_fn open; + krb5_pwqual_check_fn check; + krb5_pwqual_close_fn close; + /* Minor version 1 ends here. */ +} *krb5_pwqual_vtable; + +#endif /* KRB5_PWQUAL_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/krb5.h postgresql-hll-2.14/include/include/krb5.h --- postgresql-hll-2.14_old/include/include/krb5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/krb5.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,8 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* The MIT Kerberos header file krb5.h used to live here. + + As of the 1.5 release, we're installing multiple Kerberos headers, + so they're all moving to a krb5/ subdirectory. This file is + present just to keep old software still compiling. Please update + your code to use the new path for the header. */ +#include diff -uprN postgresql-hll-2.14_old/include/include/lib/binaryheap.h postgresql-hll-2.14/include/include/lib/binaryheap.h --- postgresql-hll-2.14_old/include/include/lib/binaryheap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/binaryheap.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * binaryheap.h + * A simple binary heap implementation + * + * + * IDENTIFICATION + * src/include/lib/binaryheap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BINARYHEAP_H +#define BINARYHEAP_H + +/* + * For a max-heap, the comparator must return <0 iff a < b, 0 iff a == b, + * and >0 iff a > b. For a min-heap, the conditions are reversed. + */ +typedef int (*binaryheap_comparator)(Datum a, Datum b, void* arg); + +/* + * binaryheap + * + * bh_size how many nodes are currently in "nodes" + * bh_space how many nodes can be stored in "nodes" + * bh_has_heap_property no unordered operations since last heap build + * bh_compare comparison function to define the heap property + * bh_arg user data for comparison function + * bh_nodes variable-length array of "space" nodes + */ +typedef struct binaryheap { + int bh_size; + int bh_space; + bool bh_has_heap_property; /* debugging cross-check */ + binaryheap_comparator bh_compare; + void* bh_arg; + Datum bh_nodes[FLEXIBLE_ARRAY_MEMBER]; +} binaryheap; + +extern binaryheap* binaryheap_allocate(int capacity, binaryheap_comparator compare, void* arg); +extern void binaryheap_reset(binaryheap* heap); +extern void binaryheap_free(binaryheap* heap); +extern void binaryheap_add_unordered(binaryheap* heap, Datum d); +extern void binaryheap_build(binaryheap* heap); +extern void binaryheap_add(binaryheap* heap, Datum d); +extern Datum binaryheap_first(binaryheap* heap); +extern Datum binaryheap_remove_first(binaryheap* heap); +extern void binaryheap_replace_first(binaryheap* heap, Datum d); + +#define binaryheap_empty(h) ((h)->bh_size == 0) + +#endif /* BINARYHEAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/bipartite_match.h postgresql-hll-2.14/include/include/lib/bipartite_match.h --- postgresql-hll-2.14_old/include/include/lib/bipartite_match.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/bipartite_match.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bipartite_match.h + * + * + * + * IDENTIFICATION + * src/include/lib/bipartite_match.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BIPARTITE_MATCH_H +#define BIPARTITE_MATCH_H + +/* + * Given a bipartite graph consisting of nodes U numbered 1..nU, nodes V + * numbered 1..nV, and an adjacency map of undirected edges in the form + * adjacency[u] = [k, v1, v2, v3, ... vk], we wish to find a "maximum + * cardinality matching", which is defined as follows: a matching is a subset + * of the original edges such that no node has more than one edge, and a + * matching has maximum cardinality if there exists no other matching with a + * greater number of edges. + * + * This matching has various applications in graph theory, but the motivating + * example here is Dilworth's theorem: a partially-ordered set can be divided + * into the minimum number of chains (i.e. subsets X where x1 < x2 < x3 ...) by + * a bipartite graph construction. This gives us a polynomial-time solution to + * the problem of planning a collection of grouping sets with the provably + * minimal number of sort operations. + */ +typedef struct BipartiteMatchState { + /* inputs: */ + int u_size; /* size of U */ + int v_size; /* size of V */ + short** adjacency; /* adjacency[u] = [k, v1,v2,v3,...,vk] */ + /* outputs: */ + int matching; /* number of edges in matching */ + short* pair_uv; /* pair_uv[u] -> v */ + short* pair_vu; /* pair_vu[v] -> u */ + /* private state for matching algorithm: */ + short* distance; /* distance[u] */ + short* queue; /* queue storage for breadth search */ +} BipartiteMatchState; + +extern BipartiteMatchState* BipartiteMatch(int u_size, int v_size, short** adjacency); + +extern void BipartiteMatchFree(BipartiteMatchState* state); + +#endif /* BIPARTITE_MATCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/circularqueue.h postgresql-hll-2.14/include/include/lib/circularqueue.h --- postgresql-hll-2.14_old/include/include/lib/circularqueue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/circularqueue.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,55 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * circularQueue.h + * + * + * + * IDENTIFICATION + * src/include/lib/Circularqueue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef Circular_QUEUE_H +#define Circular_QUEUE_H + +#include "postgres.h" + +class CircularQueue : public BaseObject { +public: + CircularQueue(int size, MemoryContext context); + ~CircularQueue(); + + void Init(); + void Destroy(); + bool LockFreeEnQueue(void* elem); /* append elem to the queue */ + + const uint32 GetStart() const; /* get the start */ + void SetStart(uint32 index); /* set the start */ + const uint32 GetEnd() const; /* get the end */ + const bool IsFull(); /* if the queue is full */ + uint32 GetLength(uint32 start, uint32 end); /* get the length of queue */ + void QueueTraverse(); /* traverse the queue */ + void* GetElem(int n); /* get nth element in the queue */ + MemoryContext GetContext(); /* get the memory context of this queue */ +public: + uint32 head; + volatile uint32 tail; + uint32 capacity; + void** queue; + MemoryContext cxt; +}; + +#endif /* Circular_QUEUE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/lib/dllist.h postgresql-hll-2.14/include/include/lib/dllist.h --- postgresql-hll-2.14_old/include/include/lib/dllist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/dllist.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,106 @@ +/* ------------------------------------------------------------------------- + * + * dllist.h + * simple doubly linked list primitives + * the elements of the list are void* so the lists can contain anything + * Dlelem can only be in one list at a time + * + * + * Here's a small example of how to use Dllists: + * + * Dllist *lst; + * Dlelem *elt; + * void *in_stuff; -- stuff to stick in the list + * void *out_stuff + * + * lst = DLNewList(); -- make a new dllist + * DLAddHead(lst, DLNewElem(in_stuff)); -- add a new element to the list + * with in_stuff as the value + * ... + * elt = DLGetHead(lst); -- retrieve the head element + * out_stuff = (void*)DLE_VAL(elt); -- get the stuff out + * DLRemove(elt); -- removes the element from its list + * DLFreeElem(elt); -- free the element since we don't + * use it anymore + * + * + * It is also possible to use Dllist objects that are embedded in larger + * structures instead of being separately malloc'd. To do this, use + * DLInitElem() to initialize a Dllist field within a larger object. + * Don't forget to DLRemove() each field from its list (if any) before + * freeing the larger object! + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/lib/dllist.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef DLLIST_H +#define DLLIST_H + +struct Dllist; +struct Dlelem; + +typedef struct Dlelem { + struct Dlelem* dle_next; /* next element */ + struct Dlelem* dle_prev; /* previous element */ + void* dle_val; /* value of the element */ + struct Dllist* dle_list; /* what list this element is in */ +} Dlelem; + +typedef struct Dllist { + Dlelem *dll_head; + Dlelem *dll_tail; + uint64 dll_len; +} Dllist; + +class DllistWithLock : public BaseObject { +public: + DllistWithLock(); + ~DllistWithLock(); + void Remove(Dlelem* e); + void AddHead(Dlelem* e); + void AddTail(Dlelem* e); + Dlelem* RemoveHead(); + bool IsEmpty(); + + inline uint64 GetLength() + { + return m_list.dll_len; + } + +private: + slock_t m_lock; + Dllist m_list; +}; + +extern Dllist* DLNewList(void); /* allocate and initialize a list header */ +extern void DLInitList(Dllist* list); /* init a header alloced by caller */ +extern void DLFreeList(Dllist* list); /* free up a list and all the nodes in + * it */ +extern Dlelem* DLNewElem(void* val); +extern void DLInitElem(Dlelem* e, void* val); +extern void DLFreeElem(Dlelem* e); +extern void DLRemove(Dlelem* e); /* removes node from list */ +extern void DLAddHead(Dllist* list, Dlelem* node); +extern void DLAddTail(Dllist* list, Dlelem* node); +extern Dlelem* DLRemHead(Dllist* list); /* remove and return the head */ +extern Dlelem* DLRemTail(Dllist* list); +extern void DLMoveToFront(Dlelem* e); /* move node to front of its list */ +extern uint64 DLListLength(Dllist* list); + +/* These are macros for speed */ +#define DLGetHead(list) ((list)->dll_head) +#define DLGetTail(list) ((list)->dll_tail) +#define DLIsNIL(list) ((list)->dll_head == NULL) +#define DLGetSucc(elem) ((elem)->dle_next) +#define DLGetPred(elem) ((elem)->dle_prev) +#define DLGetListHdr(elem) ((elem)->dle_list) + +#define DLE_VAL(elem) ((elem)->dle_val) + +#endif /* DLLIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/hyperloglog.h postgresql-hll-2.14/include/include/lib/hyperloglog.h --- postgresql-hll-2.14_old/include/include/lib/hyperloglog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/hyperloglog.h 2020-12-12 17:06:43.222347716 +0800 @@ -0,0 +1,71 @@ +/* --------------------------------------------------------------------------------------- + * + * hyperloglog.h + * A simple HyperLogLog cardinality estimator implementation + * + * Portions Copyright (c) 2014-2016, PostgreSQL Global Development Group + * + * Based on Hideaki Ohno's C++ implementation. The copyright terms of Ohno's + * original version (the MIT license) follow. + * + * IDENTIFICATION + * src/include/lib/hyperloglog.h + * + * --------------------------------------------------------------------------------------- + */ + +/* + * Copyright (c) 2013 Hideaki Ohno + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the 'Software'), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef HYPERLOGLOG_H +#define HYPERLOGLOG_H + +/* + * HyperLogLog is an approximate technique for computing the number of distinct + * entries in a set. Importantly, it does this by using a fixed amount of + * memory. See the 2007 paper "HyperLogLog: the analysis of a near-optimal + * cardinality estimation algorithm" for more. + * + * hyperLogLogState + * + * registerWidth register width, in bits ("k") + * nRegisters number of registers + * alphaMM alpha * m ^ 2 (see initHyperLogLog()) + * hashesArr array of hashes + * arrSize size of hashesArr + */ +typedef struct hyperLogLogState { + uint8 registerWidth; + Size nRegisters; + double alphaMM; + uint8* hashesArr; + Size arrSize; +} hyperLogLogState; + +extern void initHyperLogLog(hyperLogLogState* cState, uint8 bwidth); +extern void initHyperLogLogError(hyperLogLogState* cState, double error); +extern void addHyperLogLog(hyperLogLogState* cState, uint32 hash); +extern double estimateHyperLogLog(hyperLogLogState* cState); +extern void mergeHyperLogLog(hyperLogLogState* cState, const hyperLogLogState* oState); +extern void freeHyperLogLog(hyperLogLogState* cState); + +#endif /* HYPERLOGLOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/ilist.h postgresql-hll-2.14/include/include/lib/ilist.h --- postgresql-hll-2.14_old/include/include/lib/ilist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/ilist.h 2020-12-12 17:06:43.223347729 +0800 @@ -0,0 +1,703 @@ +/* --------------------------------------------------------------------------------------- + * + * ilist.h + * integrated/inline doubly- and singly-linked lists + * + * + * IDENTIFICATION + * src/include/lib/ilist.h + * + * NOTE + * These list types are useful when there are only a predetermined set of + * lists that an object could be in. List links are embedded directly into + * the objects, and thus no extra memory management overhead is required. + * (Of course, if only a small proportion of existing objects are in a list, + * the link fields in the remainder would be wasted space. But usually, + * it saves space to not have separately-allocated list nodes.) + * + * None of the functions here allocate any memory; they just manipulate + * externally managed memory. The APIs for singly and doubly linked lists + * are identical as far as capabilities of both allow. + * + * Each list has a list header, which exists even when the list is empty. + * An empty singly-linked list has a NULL pointer in its header. + * There are two kinds of empty doubly linked lists: those that have been + * initialized to NULL, and those that have been initialized to circularity. + * (If a dlist is modified and then all its elements are deleted, it will be + * in the circular state.) We prefer circular dlists because there are some + * operations that can be done without branches (and thus faster) on lists + * that use circular representation. However, it is often convenient to + * initialize list headers to zeroes rather than setting them up with an + * explicit initialization function, so we also allow the other case. + * + * EXAMPLES + * + * Here's a simple example demonstrating how this can be used. Let's assume + * we want to store information about the tables contained in a database. + * + * #include "lib/ilist.h" + * + * // Define struct for the databases including a list header that will be + * // used to access the nodes in the table list later on. + * typedef struct my_database + * { + * char *datname; + * dlist_head tables; + * // ... + * } my_database; + * + * // Define struct for the tables. Note the list_node element which stores + * // prev/next list links. The list_node element need not be first. + * typedef struct my_table + * { + * char *tablename; + * dlist_node list_node; + * perm_t permissions; + * // ... + * } my_table; + * + * // create a database + * my_database *db = create_database(); + * + * // and add a few tables to its table list + * dlist_push_head(&db->tables, &create_table(db, "a")->list_node); + * ... + * dlist_push_head(&db->tables, &create_table(db, "b")->list_node); + * + * + * To iterate over the table list, we allocate an iterator variable and use + * a specialized looping construct. Inside a dlist_foreach, the iterator's + * 'cur' field can be used to access the current element. iter.cur points to + * a 'dlist_node', but most of the time what we want is the actual table + * information; dlist_container() gives us that, like so: + * + * dlist_iter iter; + * dlist_foreach(iter, &db->tables) + * { + * my_table *tbl = dlist_container(my_table, list_node, iter.cur); + * printf("we have a table: %s in database %s\n", + * tbl->tablename, db->datname); + * } + * + * + * While a simple iteration is useful, we sometimes also want to manipulate + * the list while iterating. There is a different iterator element and looping + * construct for that. Suppose we want to delete tables that meet a certain + * criterion: + * + * dlist_mutable_iter miter; + * dlist_foreach_modify(miter, &db->tables) + * { + * my_table *tbl = dlist_container(my_table, list_node, miter.cur); + * + * if (!tbl->to_be_deleted) + * continue; // don't touch this one + * + * // unlink the current table from the linked list + * dlist_delete(miter.cur); + * // as these lists never manage memory, we can still access the table + * // after it's been unlinked + * drop_table(db, tbl); + * } + * + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ILIST_H +#define ILIST_H + +/* + * Enable for extra debugging. This is rather expensive, so it's not enabled by + * default even when USE_ASSERT_CHECKING. + */ + +/* + * Node of a doubly linked list. + * + * Embed this in structs that need to be part of a doubly linked list. + */ +struct dlist_node { + dlist_node* prev; + dlist_node* next; +}; +typedef struct dlist_node dlist_node; +/* + * Head of a doubly linked list. + * + * Non-empty lists are internally circularly linked. Circular lists have the + * advantage of not needing any branches in the most common list manipulations. + * An empty list can also be represented as a pair of NULL pointers, making + * initialization easier. + */ +typedef struct dlist_head { + /* + * head.next either points to the first element of the list; to &head if + * it's a circular empty list; or to NULL if empty and not circular. + * + * head.prev either points to the last element of the list; to &head if + * it's a circular empty list; or to NULL if empty and not circular. + */ + dlist_node head; +} dlist_head; + +/* + * Doubly linked list iterator. + * + * Used as state in dlist_foreach() and dlist_reverse_foreach(). To get the + * current element of the iteration use the 'cur' member. + * + * Iterations using this are *not* allowed to change the list while iterating! + * + * NB: We use an extra "end" field here to avoid multiple evaluations of + * arguments in the dlist_foreach() macro. + */ +typedef struct dlist_iter { + dlist_node* cur; /* current element */ + dlist_node* end; /* last node we'll iterate to */ +} dlist_iter; + +/* + * Doubly linked list iterator allowing some modifications while iterating. + * + * Used as state in dlist_foreach_modify(). To get the current element of the + * iteration use the 'cur' member. + * + * Iterations using this are only allowed to change the list at the current + * point of iteration. It is fine to delete the current node, but it is *not* + * fine to insert or delete adjacent nodes. + * + * NB: We need a separate type for mutable iterations so that we can store + * the 'next' node of the current node in case it gets deleted or modified. + */ +typedef struct dlist_mutable_iter { + dlist_node* cur; /* current element */ + dlist_node* next; /* next node we'll iterate to */ + dlist_node* end; /* last node we'll iterate to */ +} dlist_mutable_iter; + +/* + * Node of a singly linked list. + * + * Embed this in structs that need to be part of a singly linked list. + */ +typedef struct slist_node slist_node; +struct slist_node { + slist_node* next; +}; + +/* + * Head of a singly linked list. + * + * Singly linked lists are not circularly linked, in contrast to doubly linked + * lists; we just set head.next to NULL if empty. This doesn't incur any + * additional branches in the usual manipulations. + */ +typedef struct slist_head { + slist_node head; +} slist_head; + +/* + * Singly linked list iterator. + * + * Used as state in slist_foreach(). To get the current element of the + * iteration use the 'cur' member. + * + * It's allowed to modify the list while iterating, with the exception of + * deleting the iterator's current node; deletion of that node requires + * care if the iteration is to be continued afterward. (Doing so and also + * deleting or inserting adjacent list elements might misbehave; also, if + * the user frees the current node's storage, continuing the iteration is + * not safe.) + * + * NB: this wouldn't really need to be an extra struct, we could use an + * slist_node * directly. We prefer a separate type for consistency. + */ +typedef struct slist_iter { + slist_node* cur; +} slist_iter; + +/* + * Singly linked list iterator allowing some modifications while iterating. + * + * Used as state in slist_foreach_modify(). To get the current element of the + * iteration use the 'cur' member. + * + * The only list modification allowed while iterating is to remove the current + * node via slist_delete_current() (*not* slist_delete()). Insertion or + * deletion of nodes adjacent to the current node would misbehave. + */ +typedef struct slist_mutable_iter { + slist_node* cur; /* current element */ + slist_node* next; /* next node we'll iterate to */ + slist_node* prev; /* prev node, for deletions */ +} slist_mutable_iter; + +/* Static initializers */ +#define DLIST_STATIC_INIT(name) \ + { \ + { \ + &(name).head, &(name).head \ + } \ + } +#define SLIST_STATIC_INIT(name) \ + { \ + { \ + NULL \ + } \ + } + +/* Prototypes for functions too big to be inline */ + +/* Caution: this is O(n); consider using slist_delete_current() instead */ +extern void slist_delete(slist_head* head, slist_node* node); + +#ifdef ILIST_DEBUG +extern void dlist_check(dlist_head* head); +extern void slist_check(slist_head* head); +#else +/* + * These seemingly useless casts to void are here to keep the compiler quiet + * about the argument being unused in many functions in a non-debug compile, + * in which functions the only point of passing the list head pointer is to be + * able to run these checks. + */ +#define dlist_check(head) ((void)(head)) +#define slist_check(head) ((void)(head)) +#endif /* ILIST_DEBUG */ + +/* doubly linked list implementation */ + +/* init a doubly linked list node */ +static inline void DListNodeInit(dlist_node* node) +{ + node->next = node->prev = NULL; +} + +/* + * Initialize a doubly linked list. + * Previous state will be thrown away without any cleanup. + */ +static inline void dlist_init(dlist_head* head) +{ + head->head.next = head->head.prev = &head->head; +} + +/* + * Is the list empty? + * + * An empty list has either its first 'next' pointer set to NULL, or to itself. + */ +static inline bool dlist_is_empty(dlist_head* head) +{ + dlist_check(head); + + return head->head.next == NULL || head->head.next == &(head->head); +} + +/* + * Insert a node at the beginning of the list. + */ +static inline void dlist_push_head(dlist_head* head, dlist_node* node) +{ + if (head->head.next == NULL) /* convert NULL header to circular */ + dlist_init(head); + + node->next = head->head.next; + node->prev = &head->head; + node->next->prev = node; + head->head.next = node; + + dlist_check(head); +} + +/* + * Insert a node at the end of the list. + */ +static inline void dlist_push_tail(dlist_head* head, dlist_node* node) +{ + if (head->head.next == NULL) /* convert NULL header to circular */ + dlist_init(head); + + node->next = &head->head; + node->prev = head->head.prev; + node->prev->next = node; + head->head.prev = node; + + dlist_check(head); +} + +/* + * Insert a node after another *in the same list* + */ +static inline void dlist_insert_after(dlist_node* after, dlist_node* node) +{ + node->prev = after; + node->next = after->next; + after->next = node; + node->next->prev = node; +} + +/* + * Insert a node before another *in the same list* + */ +static inline void dlist_insert_before(dlist_node* before, dlist_node* node) +{ + node->prev = before->prev; + node->next = before; + before->prev = node; + node->prev->next = node; +} + +/* + * Delete 'node' from its list (it must be in one). + */ +static inline void dlist_delete(dlist_node* node) +{ + node->prev->next = node->next; + node->next->prev = node->prev; +} + +/* + * Remove and return the first node from a list (there must be one). + */ +static inline dlist_node* dlist_pop_head_node(dlist_head* head) +{ + dlist_node* node = NULL; + + Assert(!dlist_is_empty(head)); + node = head->head.next; + dlist_delete(node); + return node; +} + +/* + * Move element from its current position in the list to the head position in + * the same list. + * + * Undefined behaviour if 'node' is not already part of the list. + */ +static inline void dlist_move_head(dlist_head* head, dlist_node* node) +{ + /* fast path if it's already at the head */ + if (head->head.next == node) + return; + + dlist_delete(node); + dlist_push_head(head, node); + + dlist_check(head); +} + +/* + * Check whether 'node' has a following node. + * Caution: unreliable if 'node' is not in the list. + */ +static inline bool dlist_has_next(dlist_head* head, dlist_node* node) +{ + return node->next != &head->head; +} + +/* + * Check whether 'node' has a preceding node. + * Caution: unreliable if 'node' is not in the list. + */ +static inline bool dlist_has_prev(dlist_head* head, dlist_node* node) +{ + return node->prev != &head->head; +} + +/* + * Return the next node in the list (there must be one). + */ +static inline dlist_node* dlist_next_node(dlist_head* head, dlist_node* node) +{ + Assert(dlist_has_next(head, node)); + return node->next; +} + +/* + * Return previous node in the list (there must be one). + */ +static inline dlist_node* dlist_prev_node(dlist_head* head, dlist_node* node) +{ + Assert(dlist_has_prev(head, node)); + return node->prev; +} + +/* internal support function to get address of head element's struct */ +static inline void* dlist_head_element_off(dlist_head* head, size_t off) +{ + Assert(!dlist_is_empty(head)); + return (char*)head->head.next - off; +} + +/* + * Return the first node in the list (there must be one). + */ +static inline dlist_node* dlist_head_node(dlist_head* head) +{ + return (dlist_node*)dlist_head_element_off(head, 0); +} + +/* internal support function to get address of tail element's struct */ +static inline void* dlist_tail_element_off(dlist_head* head, size_t off) +{ + Assert(!dlist_is_empty(head)); + return (char*)head->head.prev - off; +} + +/* + * Return the last node in the list (there must be one). + */ +static inline dlist_node* dlist_tail_node(dlist_head* head) +{ + return (dlist_node*)dlist_tail_element_off(head, 0); +} + +/* + * Return the containing struct of 'type' where 'membername' is the dlist_node + * pointed at by 'ptr'. + * + * This is used to convert a dlist_node * back to its containing struct. + */ +#define dlist_container(type, membername, ptr) \ + (AssertVariableIsOfTypeMacro(ptr, dlist_node*), \ + AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + ((type*)((char*)(ptr)-offsetof(type, membername)))) + +/* + * Return the address of the first element in the list. + * + * The list must not be empty. + */ +#define dlist_head_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + (type*)dlist_head_element_off(lhead, offsetof(type, membername))) + +/* + * Return the address of the last element in the list. + * + * The list must not be empty. + */ +#define dlist_tail_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + ((type*)dlist_tail_element_off(lhead, offsetof(type, membername)))) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * It is *not* allowed to manipulate the list during iteration. + */ +#define dlist_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->next ? (iter).end->next : (iter).end; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).cur->next) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * Iterations using this are only allowed to change the list at the current + * point of iteration. It is fine to delete the current node, but it is *not* + * fine to insert or delete adjacent nodes. + */ +#define dlist_foreach_modify(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_mutable_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->next ? (iter).end->next : (iter).end, \ + (iter).next = (iter).cur->next; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).next, (iter).next = (iter).cur->next) + +/* + * Iterate through the list in reverse order. + * + * It is *not* allowed to manipulate the list during iteration. + */ +#define dlist_reverse_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->prev ? (iter).end->prev : (iter).end; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).cur->prev) + +/* singly linked list implementation */ + +/* + * Initialize a singly linked list. + * Previous state will be thrown away without any cleanup. + */ +static inline void slist_init(slist_head* head) +{ + head->head.next = NULL; +} + +/* + * Is the list empty? + */ +static inline bool slist_is_empty(slist_head* head) +{ + slist_check(head); + + return head->head.next == NULL; +} + +/* + * Insert a node at the beginning of the list. + */ +static inline void slist_push_head(slist_head* head, slist_node* node) +{ + node->next = head->head.next; + head->head.next = node; + + slist_check(head); +} + +/* + * Insert a node after another *in the same list* + */ +static inline void slist_insert_after(slist_node* after, slist_node* node) +{ + node->next = after->next; + after->next = node; +} + +/* + * Remove and return the first node from a list (there must be one). + */ +static inline slist_node* slist_pop_head_node(slist_head* head) +{ + slist_node* node = NULL; + + Assert(!slist_is_empty(head)); + node = head->head.next; + head->head.next = node->next; + slist_check(head); + return node; +} + +/* + * Check whether 'node' has a following node. + */ +static inline bool slist_has_next(slist_head* head, slist_node* node) +{ + slist_check(head); + + return node->next != NULL; +} + +/* + * Return the next node in the list (there must be one). + */ +static inline slist_node* slist_next_node(slist_head* head, slist_node* node) +{ + Assert(slist_has_next(head, node)); + return node->next; +} + +/* internal support function to get address of head element's struct */ +static inline void* slist_head_element_off(slist_head* head, size_t off) +{ + Assert(!slist_is_empty(head)); + return (char*)head->head.next - off; +} + +/* + * Return the first node in the list (there must be one). + */ +static inline slist_node* slist_head_node(slist_head* head) +{ + return (slist_node*)slist_head_element_off(head, 0); +} + +/* + * Delete the list element the iterator currently points to. + * + * Caution: this modifies iter->cur, so don't use that again in the current + * loop iteration. + */ +static inline void slist_delete_current(slist_mutable_iter* iter) +{ + /* + * Update previous element's forward link. If the iteration is at the + * first list element, iter->prev will point to the list header's "head" + * field, so we don't need a special case for that. + */ + iter->prev->next = iter->next; + + /* + * Reset cur to prev, so that prev will continue to point to the prior + * valid list element after slist_foreach_modify() advances to the next. + */ + iter->cur = iter->prev; +} + +/* + * Return the containing struct of 'type' where 'membername' is the slist_node + * pointed at by 'ptr'. + * + * This is used to convert a slist_node * back to its containing struct. + */ +#define slist_container(type, membername, ptr) \ + (AssertVariableIsOfTypeMacro(ptr, slist_node*), \ + AssertVariableIsOfTypeMacro(((type*)NULL)->membername, slist_node), \ + ((type*)((char*)(ptr)-offsetof(type, membername)))) + +/* + * Return the address of the first element in the list. + * + * The list must not be empty. + */ +#define slist_head_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, slist_node), \ + (type*)slist_head_element_off(lhead, offsetof(type, membername))) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * It's allowed to modify the list while iterating, with the exception of + * deleting the iterator's current node; deletion of that node requires + * care if the iteration is to be continued afterward. (Doing so and also + * deleting or inserting adjacent list elements might misbehave; also, if + * the user frees the current node's storage, continuing the iteration is + * not safe.) + */ +#define slist_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, slist_iter), \ + AssertVariableIsOfTypeMacro(lhead, slist_head*), \ + (iter).cur = (lhead)->head.next; \ + (iter).cur != NULL; \ + (iter).cur = (iter).cur->next) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * The only list modification allowed while iterating is to remove the current + * node via slist_delete_current() (*not* slist_delete()). Insertion or + * deletion of nodes adjacent to the current node would misbehave. + */ +#define slist_foreach_modify(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, slist_mutable_iter), \ + AssertVariableIsOfTypeMacro(lhead, slist_head*), \ + (iter).prev = &(lhead)->head, \ + (iter).cur = (iter).prev->next, \ + (iter).next = (iter).cur ? (iter).cur->next : NULL; \ + (iter).cur != NULL; \ + (iter).prev = (iter).cur, (iter).cur = (iter).next, (iter).next = (iter).next ? (iter).next->next : NULL) + +#endif /* ILIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/lrucache.h postgresql-hll-2.14/include/include/lib/lrucache.h --- postgresql-hll-2.14_old/include/include/lib/lrucache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/lrucache.h 2020-12-12 17:06:43.223347729 +0800 @@ -0,0 +1,147 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * lrucache.h + * + * + * + * IDENTIFICATION + * src/include/lib/lrucache.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LRUCACHE_INCLUDE +#define LRUCACHE_INCLUDE + +#include "postgres.h" + +typedef bool (*CmpFuncType)(void*, void*); +void CleanHotkeyInfo(struct HotkeyInfo* key); + +/* struct with ref count to help release key info */ +struct RefNode : public BaseObject { + void* key; + volatile uint64 refcount; + RefNode() + { + key = NULL; + refcount = 1; + } + ~RefNode() + {} + void Destroy() + { + if (key != NULL) { + CleanHotkeyInfo((HotkeyInfo*)key); + key = NULL; + } + refcount = 0; + } +}; + +/* basic node for lru cache operation */ +struct DllNode : public BaseObject { + RefNode* node; + volatile uint64 value; + double weight; + DllNode* next; + DllNode* prev; + volatile uint32 state; // thread that occupies 0 can operate this Node + MemoryContext cxt; + DllNode(MemoryContext context) + { + value = 0; + weight = 0; + next = NULL; + prev = NULL; + state = 0; + cxt = context; + } + ~DllNode() + {} + void Init() + { + node = New(cxt) RefNode(); + } + void Destroy() + { + if (node != NULL) { + node->Destroy(); + node = NULL; + } + value = 0; + weight = 0; + next = NULL; + prev = NULL; + state = 0; + } +}; + +class LRUCache : public BaseObject { +public: + LRUCache(int size, MemoryContext context); + ~LRUCache(); + + void Init(); + void Destroy(); + void Put(void* node); + bool Contain(void* node, CmpFuncType type); + void AddToTail(RefNode* x); + void Remove(DllNode* n); + void MoveToTail(DllNode* n); + void ReLocate(DllNode* x); + void Clean(); + void DeleteHotkeysInTAB(Oid t_oid); + void DeleteHotkeysInDB(Oid db_oid); + void DestroyNode(DllNode* node); + int GetLength() + { + return len; + } + DllNode* GetFirstElem() + { + return head->next; + } + DllNode* GetLastElem() + { + return tail->prev; + } + DllNode** GetArray() + { + return array; + } + bool IsFull() + { + return len == capacity; + } + bool IsEmpty() + { + return len == 0; + } + pthread_rwlock_t* GetLock() + { + return lock; + } + +private: + int len; + int capacity; + MemoryContext cxt; + DllNode* head; + DllNode* tail; + DllNode** array; + pthread_rwlock_t* lock; +}; +#endif /* LRUCACHE_INCLUDE */ diff -uprN postgresql-hll-2.14_old/include/include/lib/string.h postgresql-hll-2.14/include/include/lib/string.h --- postgresql-hll-2.14_old/include/include/lib/string.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/string.h 2020-12-12 17:06:43.223347729 +0800 @@ -0,0 +1,15 @@ +/* + * string.h + * string handling helpers + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/common/string.h + */ +#ifndef COMMON_STRING_H +#define COMMON_STRING_H + +extern bool pg_str_endswith(const char* str, const char* end); + +#endif /* COMMON_STRING_H */ diff -uprN postgresql-hll-2.14_old/include/include/lib/stringinfo.h postgresql-hll-2.14/include/include/lib/stringinfo.h --- postgresql-hll-2.14_old/include/include/lib/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/lib/stringinfo.h 2020-12-12 17:06:43.223347729 +0800 @@ -0,0 +1,159 @@ +/* ------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/lib/stringinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STRINGINFO_H +#define STRINGINFO_H + +/* ------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + * ------------------------- + */ +typedef struct StringInfoData { + char* data; + int len; + int maxlen; + int cursor; +} StringInfoData; + +typedef StringInfoData* StringInfo; + +/* ------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + * ------------------------- + */ + +/* ------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern StringInfo makeStringInfo(void); + +/* ------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initStringInfo(StringInfo str); + +/* ------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void resetStringInfo(StringInfo str); + +/* ------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendStringInfo(StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/* ------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool appendStringInfoVA(StringInfo str, const char* fmt, va_list args) + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0))); + +/* ------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void appendStringInfoString(StringInfo str, const char* s); + +/* ------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void appendStringInfoChar(StringInfo str, char ch); + +/* ------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/* ------------------------ + * appendStringInfoSpaces + * Append a given number of spaces to str. + */ +extern void appendStringInfoSpaces(StringInfo str, int count); + +/* ------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void appendBinaryStringInfo(StringInfo str, const char* data, int datalen); + +extern void copyStringInfo(StringInfo to, StringInfo from); + +/* ------------------------ + * enlargeBuffer + * Make sure a buffer can hold at least 'needed' more bytes. + */ +void enlargeBuffer(int needed, int len, int* maxlen, char** data); +void enlargeBufferSize(int needed, int len, size_t* maxlen, char** data); + +/* ------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern void enlargeStringInfo(StringInfo str, int needed); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/libcomm/libcomm.h postgresql-hll-2.14/include/include/libcomm/libcomm.h --- postgresql-hll-2.14_old/include/include/libcomm/libcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libcomm/libcomm.h 2020-12-12 17:06:43.223347729 +0800 @@ -0,0 +1,559 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libcomm.h + * + * + * IDENTIFICATION + * src/include/libcomm/libcomm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _GS_LIBCOMM_H_ +#define _GS_LIBCOMM_H_ + +#include +#include +#ifndef WIN32 +#include +#else +#include "pthread-win32.h" +#endif +#include +#include "c.h" + +#define ECOMMTCPARGSINVAL 1001 +#define ECOMMTCPMEMALLOC 1002 +#define ECOMMTCPCVINIT 1003 +#define ECOMMTCPCVDESTROY 1004 +#define ECOMMTCPLOCKINIT 1005 +#define ECOMMTCPLOCKDESTROY 1006 +#define ECOMMTCPNODEIDFD 1007 +#define ECOMMTCPNODEIDXTCPFD 1008 +#define ECOMMTCPSETSTREAMIDX 1009 +#define ECOMMTCPBUFFQSIZE 1010 +#define ECOMMTCPQUTOASZIE 1011 +#define ECOMMTCPSEMINIT 1012 +#define ECOMMTCPSEMPOST 1013 +#define ECOMMTCPSEMWAIT 1014 +#define ECOMMTCPEPOLLINIT 1015 +#define ECOMMTCPEPOLLHNDL 1016 +#define ECOMMTCPSCTPADRINIT 1017 +#define ECOMMTCPSCTPLISTEN 1018 +#define ECOMMTCPCMAILBOXINIT 1019 +#define ECOMMTCPNODEIDXSCTPPORT 1020 +#define ECOMMTCPSTREAMIDX 1021 +#define ECOMMTCPTCPFD 1022 +#define ECOMMTCPEPOLLEVNT 1023 +#define ECOMMTCPCTRLMSG 1024 +#define ECOMMTCPCTRLMSGWR 1025 +#define ECOMMTCPCTRLMSGRD 1026 +#define ECOMMTCPSTREAMIDXINVAL 1027 +#define ECOMMTCPINVALNODEID 1028 +#define ECOMMTCPCTRLMSGSIZE 1029 +#define ECOMMTCPCVSIGNAL 1030 +#define ECOMMTCPEPOLLLST 1031 +#define ECOMMTCPCTRLCONN 1032 +#define ECOMMTCPSND 1033 +#define ECOMMTCPEPOLLCLOSE 1034 +#define ECOMMTCPEPOLLTIMEOUT 1035 +#define ECOMMTCPHASHENTRYDEL 1036 +#define ECOMMTCPTHREADSTOP 1037 +#define ECOMMTCPMAILBOXCLOSE 1038 +#define ECOMMTCPSTREAMSTATE 1039 +#define ECOMMTCPSCTPFDINVAL 1040 +#define ECOMMTCPNODATA 1041 +#define ECOMMTCPTHREADSTART 1042 +#define ECOMMTCPHASHENTRYADD 1043 +#define ECOMMTCPBUILDSCTPASSOC 1044 +#define ECOMMTCPWRONGSTREAMKEY 1045 +#define ECOMMTCPRELEASEMEM 1046 +#define ECOMMTCPTCPDISCONNECT 1047 +#define ECOMMTCPDISCONNECT 1048 +#define ECOMMTCPREMOETECLOSE 1049 +#define ECOMMTCPAPPCLOSE 1050 +#define ECOMMTCPLOCALCLOSEPOLL 1051 +#define ECOMMTCPPEERCLOSEPOLL 1052 +#define ECOMMTCPCONNFAIL 1054 +#define ECOMMTCPSTREAMCONNFAIL 1055 +#define ECOMMTCPREJECTSTREAM 1056 +#define ECOMMTCPCONNTIMEOUT 1057 +#define ECOMMTCPWAITQUOTAFAIL 1058 +#define ECOMMTCPWAITPOLLERROR 1059 +#define ECOMMTCPPEERCHANGED 1060 +#define ECOMMTCPGSSAUTHFAIL 1061 +#define ECOMMTCPSENDTIMEOUT 1062 +#define ECOMMTCPNOTINTERNALIP 1063 + +// Structure definitions. +// Stream key is using to associate producers and consumers +// +#define HOST_ADDRSTRLEN INET6_ADDRSTRLEN +#define HOST_LEN_OF_HTAB 64 +#define NAMEDATALEN 64 +#define MSG_TIME_LEN 30 +#define MAX_DN_NODE_NUM 8192 +#define MAX_CN_NODE_NUM 1024 +#define MAX_CN_DN_NODE_NUM (MAX_DN_NODE_NUM + MAX_CN_NODE_NUM) //(MaxCoords+MaxDataNodes) +#define MIN_CN_DN_NODE_NUM (1 + 1) //(1 CN + 1 DN) + +#define SEC_TO_MICRO_SEC 1000 + +typedef enum { + LIBCOMM_NONE, + LIBCOMM_SEND_CTRL, + LIBCOMM_RECV_CTRL, + LIBCOMM_RECV_LOOP, + LIBCOMM_AUX +} LibcommThreadTypeDef; + +/* send and recv message type */ +typedef enum +{ + SEND_SOME = 0, + SECURE_READ, + SECURE_WRITE, + READ_DATA, + READ_DATA_FROM_LOGIC +} CommMsgOper; + +typedef enum +{ + POSTMASTER = 0, + GS_SEND_flow, + GS_RECV_FLOW, + GS_RECV_LOOP, +} CommThreadUsed; + +typedef struct CommStreamKey { + uint64 queryId; /* Plan id of current query. */ + uint32 planNodeId; /* Plan node id of stream node. */ + uint32 producerSmpId; /* Smp id for producer. */ + uint32 consumerSmpId; /* Smp id for consumer. */ +} TcpStreamKey; + +// struct of libcomm logic addr +// idx gives the node idx of backend +// sid gives the logic conn idx with specific node +// ver gives the version of this logic addr, once it is closed ver++ +// type is GSOCK_TYPE +typedef struct { + uint16 idx; + uint16 sid; + uint16 ver; + uint16 type; +} gsocket; + +struct StreamConnInfo; + +// statistic structure +// +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_id; + const char* stream_state; + int tcp_sock; + uint64 query_id; + TcpStreamKey stream_key; + long quota_size; + unsigned long buff_usize; + long bytes; + long time; + long speed; + unsigned long local_thread_id; + unsigned long peer_thread_id; +} CommRecvStreamStatus; + +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_id; + const char* stream_state; + int tcp_sock; + int packet_count; + int quota_count; + uint64 query_id; + TcpStreamKey stream_key; + long bytes; + long time; + long speed; + long quota_size; + long wait_quota; + long send_overhead; + unsigned long local_thread_id; + unsigned long peer_thread_id; +} CommSendStreamStatus; + +typedef struct { + long recv_speed; + long send_speed; + int recv_count_speed; + int send_count_speed; + long buffer; + long mem_libcomm; + long mem_libpq; + int postmaster; + int gs_sender_flow; + int gs_receiver_flow; + int gs_receiver_loop; + int stream_conn_num; +} CommStat; + + +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_num; + uint32 min_delay; + uint32 dev_delay; + uint32 max_delay; +} CommDelayInfo; + +// sctp address infomation +// +typedef struct libcommaddrinfo { + char* host; // host ip + char nodename[NAMEDATALEN]; // datanode name + int ctrl_port; // control tcp listening port + int listen_port; // listening port + int status; // status of the address info, + // -1:closed, 0:need send, 1:send finish + int nodeIdx; // datanode index, like PGXCNodeId + CommStreamKey streamKey; // stream key, use plan id,plan node id, producer smp id and consumer smp id + unsigned int qid; // query index + bool parallel_send_mode; // this connection use parallel mode to send + int addr_list_size; // how many node in addr info list, only the head node set it + libcommaddrinfo* addr_list_next; // point to next addr info node, libcomm use it to build addr info list + gsocket gs_sock; // libcomm logic addr +} libcomm_addrinfo; + +/* cn and dn send and recv message log */ +typedef struct MessageIpcLog +{ + char type; /* the incomplete message type parsed last time */ + int msg_cursor; + int msg_len; /* When the message parsed last time is incomplete, record the true length of the message */ + + int len_cursor; /* When msglen is parsed to be less than 4 bytes, the received bytes count are recorded */ + uint32 len_cache; + + /* For consecutive parses to the same message, record the msgtype, length, and last parsed time and same message count. */ + char last_msg_type; /* the type of the previous message */ + int last_msg_len; /* the message of the previous message */ + int last_msg_count; /* same message count */ + char last_msg_time[MSG_TIME_LEN]; // the time of the previous message +}MessageIpcLog; + +typedef struct MessageCommLog +{ + MessageIpcLog recv_ipc_log; + MessageIpcLog send_ipc_log; +}MessageCommLog; + +typedef enum { + GSOCK_INVALID, + GSOCK_PRODUCER, + GSOCK_CONSUMER, + GSOCK_DAUL_CHANNEL, +} GSOCK_TYPE; + +extern gsocket gs_invalid_gsock; +#define GS_INVALID_GSOCK gs_invalid_gsock + +void mc_elog(int elevel, const char* fmt, ...) __attribute__((format(printf, 2, 3))); + +#define LIBCOMM_DEBUG_LOG(format, ...) \ + do { \ + ; \ + } while (0) + +// the role of current node +// +typedef enum { ROLE_PRODUCER, ROLE_CONSUMER, ROLE_MAX_TYPE } SctpNodeRole; + +// the connection state of IP+PORT +// +typedef enum { CONNSTATEFAIL, CONNSTATECONNECTING, CONNSTATESUCCEED } ConnectionState; + +// the channel type +// +typedef enum { DATA_CHANNEL, CTRL_CHANNEL } ChannelType; + +typedef bool (*wakeup_hook_type)(TcpStreamKey key, StreamConnInfo connInfo); + +// Set basic initialization information for communication, +// calling by each datanode for initializing the communication layer +// +extern int gs_set_basic_info(const char* local_host, // local ip of the datanode, it can be used "localhost" for simple + const char* local_node_name, // local node name of the datanode, like PGXCNodeName + int node_num, // total number of datanodes, maximum value is 1024, it could be set in postgresql.conf with + // parameter name comm_max_datanode + char* sock_path); // unix domain path + +// Connect to destination datanode, and get the sctp stream index for sending +// called by Sender +// +// return: stream index +// +extern int gs_connect(libcommaddrinfo** sctp_addrinfo, // destination address + int addr_num, // connection number + int timeout // timeout threshold, default is 10 min +); + +// Regist call back function of receiver for waking up Consumer in executor, +// if a sender connect successfully to receiver, wake up the consumer once +// +extern void gs_connect_regist_callback(wakeup_hook_type wakeup_callback); + +// Send message through sctp channel using a sctp stream +// called by Sender +// +// return: transmitted data size +// +extern int gs_send(gsocket* gs_sock, // destination address + char* message, // message to send + int m_len, // message length + int time_out, // timeout threshold, default is -1 + bool block_mode // is wait quota +); + +extern int gs_broadcast_send(struct libcommaddrinfo* sctp_addrinfo, char* message, int m_len, int time_out); + +// Receive message from an array of sctp channels, +// however, we will get message data from just one channel, +// and copy the data into buffer. +// +// return: received data size +// +extern int gs_recv( + gsocket* gs_sock, // array of node index, which labeled the datanodes will send data to this datanode + void* buff, // buffer to copy data message, allocated by caller + int buff_size // size of buffer +); + +// Simulate linux poll interface, +// to notify the Consumer thread data have been received into the inner buffer, you can come to take it +// +// return: the number of mailbox which has data +// +extern int gs_wait_poll(gsocket* gs_sock_array, // array of producers node index + int nproducer, // number of producers + int* producer, // producers number triggers poll + int timeout, // time out in seconds, 0 for block mode + bool close_expected // is logic connection closed by remote is an expected result +); + +/* Handle the same message and print message receiving and sending log */ +extern void gs_comm_ipc_print(MessageIpcLog *ipc_log, char *remotenode, gsocket *gs_sock, CommMsgOper msg_oper); + +/* Send and receive data between nodes, for performance problem location */ +extern MessageCommLog* gs_comm_ipc_performance(MessageCommLog *msgLog, + void *ptr, + int n, + char *remotenode, + gsocket *gs_sock, + CommMsgOper logType); + +// Receiver close sctp stream +// +extern int gs_r_close_stream(int sctp_idx, // node index + int sctp_sid, // stream index + int version // stream key(the plan id and plan node id), associated the pair of Consumer and Producer +); + +// Sender close sctp stream +// +extern int gs_s_close_stream(int sctp_idx, // node index + int sctp_sid, // node index + int version // stream key(the plan id and plan node id), associated the pair of Consumer and Producer +); + +extern void gs_close_gsocket(gsocket* gsock); + +extern void gs_poll_close(); + +extern int gs_close_all_stream_by_debug_id(uint64 query_id); + +extern bool gs_stop_query(gsocket* gsock, uint32 remote_pid); + +// Shudown the communication layer +// +extern void gs_shutdown_comm(); + +// Do internal cancel when cancelling is requested +// +extern void gs_r_cancel(); + +// export communication layer status +// +extern void gs_log_comm_status(); + +// check if the kernel version is reliable +// +extern int gs_check_SLESSP2_version(); + +// get the assigned stream number +// +extern int gs_get_stream_num(); + +// get the error information +// +const char* gs_comm_strerror(); + +// get communication layer stream status at receiver as a tuple for pg_comm_recv_stream +// +extern bool get_next_recv_stream_status(CommRecvStreamStatus* stream_status); + +// get communication layer stream status at sender as a tuple for pg_comm_send_stream +// +extern bool get_next_send_stream_status(CommSendStreamStatus* stream_status); + +// get communication layer stream status as a tuple for pg_comm_status +// +extern bool gs_get_comm_stat(CommStat* comm_stat); + +// get communication layer sctp delay infomation as a tuple for pg_comm_delay +// +extern bool get_next_comm_delay_info(CommDelayInfo* delay_info); + +extern void gs_set_debug_mode(bool mod); + +extern void gs_set_stat_mode(bool mod); + +extern void gs_set_timer_mode(bool mod); + +extern void gs_set_no_delay(bool mod); + +extern void gs_set_ackchk_time(int mod); + +extern void gs_set_libcomm_used_rate(int rate); + +extern void init_libcomm_cpu_rate(); + +// get availabe memory of communication layer +// +extern long gs_get_comm_used_memory(void); + +extern long gs_get_comm_peak_memory(void); + +extern Size gs_get_comm_context_memory(void); + +extern int gs_release_comm_memory(); + +// interface function for postmaster read msg by unix domain +extern int gs_recv_msg_by_unix_domain(int fd, gsocket* gs_sock); + +// check mailbox version for connection reused by poolmgr +extern bool gs_test_libcomm_conn(gsocket* gs_sock); + +// reset cmailbox for pooler reuse +extern void gs_clean_cmailbox(gsocket gs_sock); + +// for capacity expansion +extern void gs_change_capacity(int newval); + +extern int gs_get_cur_node(); + +extern void commSenderFlowMain(); +extern void commReceiverFlowMain(); +extern void commAuxiliaryMain(); +extern void commPoolCleanerMain(); +extern void commReceiverMain(void* tid_callback); + +extern void gs_init_hash_table(); +extern int mc_tcp_connect_nonblock(const char* host, int port); + +/* + * LIBCOMM_CHECK is defined when make commcheck + */ +#ifdef LIBCOMM_CHECK +#define LIBCOMM_FAULT_INJECTION_ENABLE +#define LIBCOMM_SPEED_TEST_ENABLE +#else +#undef LIBCOMM_FAULT_INJECTION_ENABLE +#undef LIBCOMM_SPEED_TEST_ENABLE +#endif + +/* + * Libcomm Speed Test Framework + * Before start: 1, Must run a stream query to get DN connections. + * 2, add new guc params to $GAUSSHOME/bin/cluster_guc.conf + * Start: Use gs_guc reload to set test thread num. + * For example: gs_guc reload -Z datanode -N all -I all -c "comm_test_thread_num=1" + * Stop: Use gs_guc reload to set test thread num=0. + */ +#ifdef LIBCOMM_SPEED_TEST_ENABLE +extern void gs_set_test_thread_num(int newval); +extern void gs_set_test_msg_len(int newval); +extern void gs_set_test_send_sleep(int newval); +extern void gs_set_test_send_once(int newval); +extern void gs_set_test_recv_sleep(int newval); +extern void gs_set_test_recv_once(int newval); +#endif + +/*Libcomm fault injection Framework + * Before start: 1, enable LIBCOMM_FAULT_INJECTION_ENABLE. + * 2, add new guc params to $GAUSSHOME/bin/cluster_guc.conf + * Start: Use gs_guc reload to set FI num. + * For instance: gs_guc reload -Z datanode -N all -I all -c "comm_fault_injection=6" + * Stop: Use gs_guc reload to set comm_fault_injection=0. + */ +#ifdef LIBCOMM_FAULT_INJECTION_ENABLE +typedef enum { + LIBCOMM_FI_NONE, + LIBCOMM_FI_R_TCP_DISCONNECT, + LIBCOMM_FI_R_SCTP_DISCONNECT, + LIBCOMM_FI_S_TCP_DISCONNECT, + LIBCOMM_FI_S_SCTP_DISCONNECT, + LIBCOMM_FI_RELEASE_MEMORY, + LIBCOMM_FI_FAILOVER, // + LIBCOMM_FI_NO_STREAMID, + LIBCOMM_FI_CONSUMER_REJECT, + LIBCOMM_FI_R_APP_CLOSE, // + LIBCOMM_FI_S_APP_CLOSE, // + LIBCOMM_FI_CANCEL_SIGNAL, // + LIBCOMM_FI_CLOSE_BY_VIEW, // + LIBCOMM_FI_GSS_TCP_FAILED, + LIBCOMM_FI_GSS_SCTP_FAILED, + LIBCOMM_FI_R_PACKAGE_SPLIT, + LIBCOMM_FI_MALLOC_FAILED, + LIBCOMM_FI_MC_TCP_READ_FAILED, + LIBCOMM_FI_MC_TCP_READ_BLOCK_FAILED, + LIBCOMM_FI_MC_TCP_READ_NONBLOCK_FAILED, + LIBCOMM_FI_MC_TCP_WRITE_FAILED, + LIBCOMM_FI_MC_TCP_WRITE_NONBLOCK_FAILED, + LIBCOMM_FI_MC_TCP_ACCEPT_FAILED, + LIBCOMM_FI_MC_TCP_LISTEN_FAILED, + LIBCOMM_FI_MC_TCP_CONNECT_FAILED, + LIBCOMM_FI_FD_SOCKETVERSION_FAILED, + LIBCOMM_FI_SOCKID_NODEIDX_FAILED, + LIBCOMM_FI_POLLER_ADD_FD_FAILED, + LIBCOMM_FI_NO_NODEIDX, + LIBCOMM_FI_CREATE_POLL_FAILED, + LIBCOMM_FI_DYNAMIC_CAPACITY_FAILED, + LIBCOMM_FI_MAX +} LibcommFaultInjection; + +extern void gs_set_fault_injection(int newval); +extern void set_comm_fault_injection(int type); +extern bool is_comm_fault_injection(LibcommFaultInjection type); +#endif + +#endif //_GS_LIBCOMM_H_ diff -uprN postgresql-hll-2.14_old/include/include/libpq/auth.h postgresql-hll-2.14/include/include/libpq/auth.h --- postgresql-hll-2.14_old/include/include/libpq/auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/auth.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * auth.h + * Definitions for network authentication routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/auth.h + * + * ------------------------------------------------------------------------- + */ +#ifndef AUTH_H +#define AUTH_H + +#include "libpq/libpq-be.h" +#include "gssapi/gssapi.h" +#include "gssapi/gssapi_krb5.h" + +#define INITIAL_USER_ID 10 +#define PREFIX_LENGTH 8 + +/* The struct for gss kerberos authentication. */ +typedef struct GssConn { + int sock; + + gss_ctx_id_t gctx; /* GSS context */ + gss_name_t gtarg_nam; /* GSS target name */ + gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc goutbuf; /* GSS output token */ +} GssConn; + +extern char* pg_krb_server_hostname; +extern char* pg_krb_realm; + +extern void ClientAuthentication(Port* port); + +/* Main function for gss kerberos client/server authentication. */ +extern int GssServerAuth(int socket, const char* krb_keyfile); +extern int GssClientAuth(int socket, char* server_host); + +/* Hook for plugins to get control in ClientAuthentication() */ +typedef void (*ClientAuthentication_hook_type)(Port*, int); +extern THR_LOCAL PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook; +extern bool IsDSorHaWalSender(); + +#endif /* AUTH_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/be-fsstubs.h postgresql-hll-2.14/include/include/libpq/be-fsstubs.h --- postgresql-hll-2.14_old/include/include/libpq/be-fsstubs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/be-fsstubs.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,54 @@ +/* ------------------------------------------------------------------------- + * + * be-fsstubs.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/be-fsstubs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BE_FSSTUBS_H +#define BE_FSSTUBS_H + +#include "fmgr.h" + +/* + * LO functions available via pg_proc entries + */ +extern Datum lo_import(PG_FUNCTION_ARGS); +extern Datum lo_import_with_oid(PG_FUNCTION_ARGS); +extern Datum lo_export(PG_FUNCTION_ARGS); + +extern Datum lo_creat(PG_FUNCTION_ARGS); +extern Datum lo_create(PG_FUNCTION_ARGS); + +extern Datum lo_open(PG_FUNCTION_ARGS); +extern Datum lo_close(PG_FUNCTION_ARGS); + +extern Datum loread(PG_FUNCTION_ARGS); +extern Datum lowrite(PG_FUNCTION_ARGS); + +extern Datum lo_lseek(PG_FUNCTION_ARGS); +extern Datum lo_tell(PG_FUNCTION_ARGS); +extern Datum lo_unlink(PG_FUNCTION_ARGS); +extern Datum lo_truncate(PG_FUNCTION_ARGS); + +/* + * These are not fmgr-callable, but are available to C code. + * Probably these should have had the underscore-free names, + * but too late now... + */ +extern int lo_read(int fd, char* buf, int len); +extern int lo_write(int fd, const char* buf, int len); + +/* + * Cleanup LOs at xact commit/abort + */ +extern void AtEOXact_LargeObject(bool isCommit); +extern void AtEOSubXact_LargeObject(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); + +#endif /* BE_FSSTUBS_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/cl_state.h postgresql-hll-2.14/include/include/libpq/cl_state.h --- postgresql-hll-2.14_old/include/include/libpq/cl_state.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/cl_state.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cl_state.h + * + * IDENTIFICATION + * src\include\libpq\cl_state.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef CL_STATE_H +#define CL_STATE_H + +/* CLIENT LOGIC STATE */ +#include "guc_vars.h" +#include +#include +#include "client_logic_cache/cache_refresh_type.h" +#include "libpq-fe.h" +#include "postgres_fe.h" +#include "client_logic_processor/raw_values_list.h" + +typedef struct pg_conn PGconn; + +struct ICachedColumns; +typedef struct CopyStateData CopyStateData; +class CStringsMap; +typedef CStringsMap StringArgs; +class StatementData; + +class HookResource; +typedef struct objectFqdn { + char data[NAMEDATALEN * 4]; +} ObjectFqdn; + +class PreparedStatementsList; + +/* + the PGClientLogic class maintains the per session state machine related to the Client Logic feature +*/ +class PGClientLogic { +public: + PGClientLogic(PGconn *conn); + ~PGClientLogic(); + PGconn* m_conn; + bool enable_client_encryption; + bool disable_once; + PreparedStatementsList *preparedStatements; + PreparedStatementsList *pendingStatements; + + char lastStmtName[NAMEDATALEN]; + ObjectFqdn *droppedSchemas; + size_t droppedSchemas_size; + size_t droppedSchemas_allocated; + ObjectFqdn *droppedGlobalSettings; + size_t droppedGlobalSettings_size; + size_t droppedGlobalSettings_allocated; + ObjectFqdn *droppedColumnSettings; + size_t droppedColumnSettings_size; + size_t droppedColumnSettings_allocated; + ExecStatusType m_lastResultStatus; + bool isInvalidOperationOnColumn; + bool isDuringRefreshCacheOnError; + CacheRefreshType cacheRefreshType; + std::unordered_map m_hookResources; + + // GUC params + GucParams gucParams; + GucParams tmpGucParams; + updateGucValues val_to_update; + RawValuesList *rawValuesForReplace; +}; +#endif /* CL_STATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/crypt.h postgresql-hll-2.14/include/include/libpq/crypt.h --- postgresql-hll-2.14_old/include/include/libpq/crypt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/crypt.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,36 @@ +/* ------------------------------------------------------------------------- + * + * crypt.h + * Interface to libpq/crypt.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/crypt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CRYPT_H +#define PG_CRYPT_H + +#include "libpq/libpq-be.h" + +#include "libpq/sha2.h" + +/* the struct for iam token */ +typedef struct iam_token { + char* expires_at; + char* username; + bool role_priv; + char* cluster_id; + char* tenant_id; +} iam_token; + +extern int32 get_password_stored_method(const char* role, char* encrypted_string, int len); +extern int CheckUserValid(Port* port, const char* role); +extern int crypt_verify(const Port* port, const char* user, char* client_pass); +extern int get_stored_iteration(const char* role); +extern char* verify_cms_token(char* token_string); +extern bool parse_token(const char* token_string, iam_token* token); +extern bool check_token(iam_token token, char* rolname); +#endif diff -uprN postgresql-hll-2.14_old/include/include/libpq/guc_vars.h postgresql-hll-2.14/include/include/libpq/guc_vars.h --- postgresql-hll-2.14_old/include/include/libpq/guc_vars.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/guc_vars.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * guc_vars.h + * + * IDENTIFICATION + * src\include\libpq\guc_vars.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include +#include "parser/backslash_quotes.h" + +/* + GUC variables (Grand Unified Configuration variables) + These variables are typically only maintained the server side but some variables the client driver must also keep + track of. Typically used by the parser's lexer component +*/ + +typedef enum updateGucValues { + GUC_NONE = 0x0, + BACKSLASH_QUOTE = 0x1, + CONFORMING = 0x2, + ESCAPE_STRING = 0x4, + SEARCH_PATH = 0x8, + GUC_ROLE = 0x10 +} updateGucValues; + + +inline updateGucValues operator | (updateGucValues lhs, updateGucValues rhs) +{ + using T = std::underlying_type::type; + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +inline updateGucValues operator&(updateGucValues lhs, updateGucValues rhs) +{ + using T = std::underlying_type::type; + return static_cast(static_cast(lhs) & static_cast(rhs)); +} + +inline updateGucValues &operator |= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = lhs | rhs; + return lhs; +} + +inline updateGucValues &operator &= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = lhs & rhs; + return lhs; +} + +inline updateGucValues &operator ^= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = updateGucValues((int)lhs ^ (int)rhs); + return lhs; +} + + +typedef struct GucParams { + GucParams() + : backslash_quote(BACKSLASH_QUOTE_SAFE_ENCODING), + standard_conforming_strings(true), + escape_string_warning(true), + searchpathStr("\"$user\",public") {}; + int backslash_quote; + bool standard_conforming_strings; + bool escape_string_warning; + std::string searchpathStr; + std::string role; +} GucParams; diff -uprN postgresql-hll-2.14_old/include/include/libpq/hba.h postgresql-hll-2.14/include/include/libpq/hba.h --- postgresql-hll-2.14_old/include/include/libpq/hba.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/hba.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,82 @@ +/* ------------------------------------------------------------------------- + * + * hba.h + * Interface to hba.c + * + * + * src/include/libpq/hba.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HBA_H +#define HBA_H + +#include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */ +#include "nodes/pg_list.h" + +typedef enum UserAuth { + uaReject, + uaImplicitReject, + uaKrb5, + uaTrust, + uaIdent, + uaMD5, + uaSHA256, + uaGSS, + uaSSPI, + uaPAM, + uaLDAP, + uaCert, + uaPeer, + uaIAM +} UserAuth; + +typedef enum IPCompareMethod { ipCmpMask, ipCmpSameHost, ipCmpSameNet, ipCmpAll } IPCompareMethod; + +typedef enum ConnType { ctLocal, ctHost, ctHostSSL, ctHostNoSSL } ConnType; + +typedef struct HbaLine { + int linenumber; + ConnType conntype; + List* databases; + List* roles; + struct sockaddr_storage addr; + struct sockaddr_storage mask; + IPCompareMethod ip_cmp_method; + char* hostname; + UserAuth auth_method; + + char* usermap; + char* pamservice; + bool ldaptls; + char* ldapserver; + int ldapport; + char* ldapbinddn; + char* ldapbindpasswd; + char* ldapsearchattribute; + char* ldapbasedn; + char* ldapprefix; + char* ldapsuffix; + bool clientcert; + char* krb_server_hostname; + char* krb_realm; + bool include_realm; + bool remoteTrust; +} HbaLine; + +/* kluge to avoid including libpq/libpq-be.h here */ +typedef struct Port hbaPort; + +extern bool load_hba(void); +extern void load_ident(void); +extern void hba_getauthmethod(hbaPort* port); +extern bool IsLoopBackAddr(Port* port); +extern int check_usermap(const char* usermap_name, const char* pg_role, const char* auth_user, bool case_sensitive); + +extern bool pg_isblank(const char c); +extern bool is_cluster_internal_connection(hbaPort* port); +extern bool is_node_internal_connection(hbaPort* port); +extern bool is_cluster_internal_IP(sockaddr peer_addr); +extern bool check_ip_whitelist(hbaPort* port, char* ip, unsigned int ip_len); + +#endif /* HBA_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/ip.h postgresql-hll-2.14/include/include/libpq/ip.h --- postgresql-hll-2.14_old/include/include/libpq/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/ip.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/libpq/ip.h + * + * ------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "getaddrinfo.h" /* pgrminclude ignore */ +#include "libpq/pqcomm.h" /* pgrminclude ignore */ + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +typedef void (*PgIfAddrCallback)(struct sockaddr* addr, struct sockaddr* netmask, void* cb_data); + +extern int pg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo* ai); + +extern int pg_getnameinfo_all( + const struct sockaddr_storage* addr, int salen, char* node, int nodelen, char* service, int servicelen, int flags); + +extern int pg_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int pg_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +extern int pg_foreach_ifaddr(PgIfAddrCallback callback, void* cb_data); + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq-be.h postgresql-hll-2.14/include/include/libpq/libpq-be.h --- postgresql-hll-2.14_old/include/include/libpq/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq-be.h 2020-12-12 17:06:43.224347741 +0800 @@ -0,0 +1,232 @@ +/* ------------------------------------------------------------------------- + * + * libpq_be.h + * This file contains definitions for structures and externs used + * by the postmaster during client authentication. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq-be.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_BE_H +#define LIBPQ_BE_H + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifdef USE_SSL +#include "openssl/ossl_typ.h" +#endif + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + +#ifdef ENABLE_GSS +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif /* HAVE_GSSAPI_H */ +/* + * GSSAPI brings in headers that set a lot of things in the global namespace on win32, + * that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore, + * but also defines a symbol that simply does not exist. Undefine it again. + */ +#ifdef WIN32_ONLY_COMPILER +#undef HAVE_GETADDRINFO +#endif +#endif /* ENABLE_GSS */ + +#ifdef ENABLE_SSPI +#define SECURITY_WIN32 +#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER) +#include +#endif +#include +#undef SECURITY_WIN32 +#ifndef ENABLE_GSS +/* + * Define a fake structure compatible with GSSAPI on Unix. + */ +typedef struct { + void* value; + int length; +} gss_buffer_desc; +#endif +#endif /* ENABLE_SSPI */ + +#include "datatype/timestamp.h" +#include "libpq/hba.h" +#include "libpq/pqcomm.h" +#include "libpq/sha2.h" +#include "libcomm/libcomm.h" + +typedef enum CAC_state { CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY, CAC_WAITBACKUP } CAC_state; + +/* + * GSSAPI specific state information + */ +#if defined(ENABLE_GSS) | defined(ENABLE_SSPI) +typedef struct { + gss_buffer_desc outbuf; /* GSSAPI output token buffer */ +#ifdef ENABLE_GSS + gss_cred_id_t cred; /* GSSAPI connection cred's */ + gss_ctx_id_t ctx; /* GSSAPI connection context */ + gss_name_t name; /* GSSAPI client name */ +#endif +} pg_gssinfo; +#endif + +/* + * This is used by the postmaster in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMemoryContext, + * so that it survives into PostgresMain execution! + */ + +typedef struct Port { + volatile pgsocket sock; /* File descriptor */ + bool noblock; /* is the socket in non-blocking mode? */ + ProtocolVersion proto; /* FE/BE protocol version */ + SockAddr laddr; /* local addr (postmaster) */ + SockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_hostname; /* name (not ip addr) of remote host, if + * available */ + int remote_hostname_resolv; /* +1 = remote_hostname is known to + * resolve to client's IP address; -1 + * = remote_hostname is known NOT to + * resolve to client's IP address; 0 = + * we have not done the forward DNS + * lookup yet */ + char* remote_port; /* text rep of remote port */ + + // Stream Commucation. Use only between DN. + // + libcommaddrinfo* libcomm_addrinfo; + + gsocket gs_sock; + + CAC_state canAcceptConnections; /* postmaster connection status */ + + /* + * Information that needs to be saved from the startup packet and passed + * into backend execution. "char *" fields are NULL if not set. + * guc_options points to a List of alternating option names and values. + */ + char* database_name; + char* user_name; + char* cmdline_options; + List* guc_options; + + /* + * Information that needs to be held during the authentication cycle. + */ + HbaLine* hba; + char md5Salt[4]; /* Password salt */ + + /* + * Information that really has no business at all being in struct Port, + * but since it gets used by elog.c in the same way as database_name and + * other members of this struct, we may as well keep it here. + */ + TimestampTz SessionStartTime; /* backend start time */ + + /* + * Backend version number of the remote end, if available. + * + * For local backends, they should be launched with the same version + * number as the remote end for compatibility. + */ + uint32 SessionVersionNum; + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + +#if defined(ENABLE_GSS) || defined(ENABLE_SSPI) + + /* + * If GSSAPI is supported, store GSSAPI information. Otherwise, store a + * NULL pointer to make sure offsets in the struct remain the same. + */ + pg_gssinfo* gss; +#else + void* gss; +#endif + + /* + * SSL structures (keep these last so that USE_SSL doesn't affect + * locations of other fields) + */ +#ifdef USE_SSL + SSL* ssl; + X509* peer; + char* peer_cn; + unsigned long count; + +#endif + /* begin RFC 5802 */ + char token[TOKEN_LENGTH * 2 + 1]; + /* end RFC 5802 */ + bool is_logic_conn; + MessageCommLog *msgLog; + + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token buffer */ +#endif +} Port; + +#define STREAM_BUFFER_SIZE 8192 +#define STREAM_BUFFER_SIZE_KB 8 + +typedef struct StreamBuffer { + char PqSendBuffer[STREAM_BUFFER_SIZE]; + int PqSendBufferSize; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + int PqSendStart; + bool PqCommBusy; +} StreamBuffer; + +extern char* tcp_link_addr; +extern THR_LOCAL ProtocolVersion FrontendProtocol; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +extern CAC_state canAcceptConnections(bool isSession); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq-events.h postgresql-hll-2.14/include/include/libpq/libpq-events.h --- postgresql-hll-2.14_old/include/include/libpq/libpq-events.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq-events.h 2020-12-12 17:06:43.225347754 +0800 @@ -0,0 +1,87 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-events.h + * This file contains definitions that are useful to applications + * that invoke the libpq "events" API, but are not interesting to + * ordinary users of libpq. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/libpq/libpq-events.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_EVENTS_H +#define LIBPQ_EVENTS_H + +#include "libpq-fe.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Callback Event Ids */ +typedef enum { + PGEVT_REGISTER, + PGEVT_CONNRESET, + PGEVT_CONNDESTROY, + PGEVT_RESULTCREATE, + PGEVT_RESULTCOPY, + PGEVT_RESULTDESTROY +} PGEventId; + +typedef struct { + PGconn* conn; +} PGEventRegister; + +typedef struct { + PGconn* conn; +} PGEventConnReset; + +typedef struct { + PGconn* conn; +} PGEventConnDestroy; + +typedef struct { + PGconn* conn; + PGresult* result; +} PGEventResultCreate; + +typedef struct { + const PGresult* src; + PGresult* dest; +} PGEventResultCopy; + +typedef struct { + PGresult* result; +} PGEventResultDestroy; + +typedef int (*PGEventProc)(PGEventId evtId, void* evtInfo, void* passThrough); + +/* Registers an event proc with the given PGconn. */ +extern int PQregisterEventProc(PGconn* conn, PGEventProc proc, const char* name, void* passThrough); + +/* Sets the PGconn instance data for the provided proc to data. */ +extern int PQsetInstanceData(PGconn* conn, PGEventProc proc, void* data); + +/* Gets the PGconn instance data for the provided proc. */ +extern void* PQinstanceData(const PGconn* conn, PGEventProc proc); + +/* Sets the PGresult instance data for the provided proc to data. */ +extern int PQresultSetInstanceData(PGresult* result, PGEventProc proc, void* data); + +/* Gets the PGresult instance data for the provided proc. */ +extern void* PQresultInstanceData(const PGresult* result, PGEventProc proc); + +/* Fires RESULTCREATE events for an application-created PGresult. */ +extern int PQfireResultCreateEvents(PGconn* conn, PGresult* res); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_EVENTS_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq-fe.h postgresql-hll-2.14/include/include/libpq/libpq-fe.h --- postgresql-hll-2.14_old/include/include/libpq/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq-fe.h 2020-12-12 17:06:43.225347754 +0800 @@ -0,0 +1,580 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * + * IDENTIFICATION + * src/include/libpq/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_FE_H +#define LIBPQ_FE_H + +#ifdef __cplusplus +extern "C" { +#endif +#ifndef WIN32 +#include +#endif +#include +#include + +/* + * postgres_ext.h defines the backend's externally visible types, + * such as Oid. + */ +#include "postgres_ext.h" +#include "gs_thread.h" + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +#define libpq_free(__p) \ + do { \ + if ((__p) != NULL) { \ + free((__p)); \ + (__p) = NULL; \ + } \ + } while (0) + +#ifndef Assert +#ifndef USE_ASSERT_CHECKING +#define Assert(p) +#else +#define Assert(p) assert(p) +#endif /* USE_ASSERT_CHECKING */ +#endif /* Assert */ + +extern long libpq_used_memory; +extern long libpq_peak_memory; +extern long libcomm_used_memory; +extern long comm_peak_used_memory; + +/* Application-visible enum types */ +/* + * Although it is okay to add to these lists, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + +typedef enum { + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} ConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} PostgresPollingStatusType; + +typedef enum { + PGRES_EMPTY_QUERY = 0, /* empty query string was executed */ + PGRES_COMMAND_OK, /* a query command that doesn't return + * anything was executed properly by the + * backend */ + PGRES_TUPLES_OK, /* a query command that returns tuples was + * executed properly by the backend, PGresult + * contains the result tuples */ + PGRES_COPY_OUT, /* Copy Out data transfer in progress */ + PGRES_COPY_IN, /* Copy In data transfer in progress */ + PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the + * backend */ + PGRES_NONFATAL_ERROR, /* notice or warning message */ + PGRES_FATAL_ERROR, /* query failed */ + PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */ + PGRES_SINGLE_TUPLE /* single tuple from larger resultset */ +} ExecStatusType; + +typedef enum { + PQTRANS_IDLE, /* connection idle */ + PQTRANS_ACTIVE, /* command in progress */ + PQTRANS_INTRANS, /* idle, within transaction block */ + PQTRANS_INERROR, /* idle, within failed transaction */ + PQTRANS_UNKNOWN /* cannot determine status */ +} PGTransactionStatusType; + +typedef enum { + PQERRORS_TERSE, /* single-line error messages */ + PQERRORS_DEFAULT, /* recommended style */ + PQERRORS_VERBOSE /* all the facts, ma'am */ +} PGVerbosity; + +typedef enum { + PQPING_OK, /* server is accepting connections */ + PQPING_REJECT, /* server is alive but rejecting connections */ + PQPING_NO_RESPONSE, /* could not establish connection */ + PQPING_NO_ATTEMPT /* connection not attempted (bad params) */ +} PGPing; + +/* PGconn encapsulates a connection to the backend. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_conn PGconn; + +/* PGresult encapsulates the result of a query (or more precisely, of a single + * SQL command --- a query string given to PQsendQuery can contain multiple + * commands and thus return multiple PGresult objects). + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_result PGresult; + +/* PGcancel encapsulates the information needed to cancel a running + * query on an existing connection. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_cancel PGcancel; + +// ConnPack encapsulates the information needed to connect remote stream threads +// +typedef struct ConnPack ConnPack; + +/* PGnotify represents the occurrence of a NOTIFY message. + * Ideally this would be an opaque typedef, but it's so simple that it's + * unlikely to change. + * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's, + * whereas in earlier versions it was always your own backend's PID. + */ +typedef struct pgNotify { + char* relname; /* notification condition name */ + ThreadId be_pid; /* process ID of notifying server process */ + char* extra; /* notification parameter */ + /* Fields below here are private to libpq; apps should not use 'em */ + struct pgNotify* next; /* list link */ +} PGnotify; + +/* Function types for notice-handling callbacks */ +typedef void (*PQnoticeReceiver)(void* arg, const PGresult* res); +typedef void (*PQnoticeProcessor)(void* arg, const char* message); + +/* Print options for PQprint() */ +typedef char pqbool; + +typedef struct _PQprintOpt { + pqbool header; /* print output field headings and row count */ + pqbool align; /* fill align the fields */ + pqbool standard; /* old brain dead format */ + pqbool html3; /* output html tables */ + pqbool expanded; /* expand tables */ + pqbool pager; /* use pager for output if needed */ + char* fieldSep; /* field separator */ + char* tableOpt; /* insert to HTML */ + char* caption; /* HTML
*/ + char** fieldName; /* null terminated array of replacement field + * names */ +} PQprintOpt; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or PQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. PQconninfoFree() + * will release both the val strings and the PQconninfoOption array itself. + * ---------------- + */ +typedef struct _PQconninfoOption { + char* keyword; /* The keyword of the option */ + char* envvar; /* Fallback environment variable name */ + char* compiled; /* Fallback compiled in default value */ + char* val; /* Option's current value, or NULL */ + char* label; /* Label for field in connect dialog */ + char* dispchar; /* Indicates how to display this field in a + * connect dialog. Values are: "" Display + * entered value as is "*" Password field - + * hide value "D" Debug option - don't show + * by default */ + int dispsize; /* Field size in characters for dialog */ + size_t valsize; /* Value actual length for double check */ +} PQconninfoOption; + +/* ---------------- + * PQArgBlock -- structure for PQfn() arguments + * ---------------- + */ +typedef struct { + int len; + int isint; + union { + int* ptr; /* can't use void (dec compiler barfs) */ + int integer; + } u; +} PQArgBlock; + +/* ---------------- + * PGresAttDesc -- Data about a single attribute (column) of a query result + * ---------------- + */ +typedef struct pgresAttDesc { + char* name; /* column name */ + Oid tableid; /* source table, if known */ + int columnid; /* source column, if known */ + int format; /* format code for value (text/binary) */ + Oid typid; /* type id */ + int typlen; /* type size */ + int atttypmod; /* type-specific modifier info */ +} PGresAttDesc; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +extern char* PQbuildPGconn(const char* conninfo, PGconn** connPtr, int* packetlen); + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern PGconn* PQconnectStart(const char* conninfo); +extern PGconn* PQconnectStartParams(const char* const* keywords, const char* const* values, int expand_dbname); +extern PostgresPollingStatusType PQconnectPoll(PGconn* conn); + +/* Synchronous (blocking) */ +extern PGconn* PQconnectdb(const char* conninfo); +/* connect parallel (no blocking) */ +extern int PQconnectdbParallel(char const* const* conninfo, int count, PGconn* conn[], Oid* nodeid); + +extern PGconn* PQconnectdbParams(const char* const* keywords, const char* const* values, int expand_dbname); +extern PGconn* PQsetdbLogin(const char* pghost, const char* pgport, const char* pgoptions, const char* pgtty, + const char* dbName, const char* login, const char* pwd); + +#define PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME) \ + PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL) + +/* close the current connection and free the PGconn data structure */ +extern void PQfinish(PGconn* conn); + +extern void closePGconn(PGconn* conn); +extern void freePGconn(PGconn* conn); + +/* get info about connection options known to PQconnectdb */ +extern PQconninfoOption* PQconndefaults(void); + +/* parse connection options in same way as PQconnectdb */ +extern PQconninfoOption* PQconninfoParse(const char* conninfo, char** errmsg); + +/* free the data structure returned by PQconndefaults() or PQconninfoParse() */ +extern void PQconninfoFree(PQconninfoOption* connOptions); + +/* + * close the current connection and restablish a new one with the same + * parameters + */ +/* Asynchronous (non-blocking) */ +extern int PQresetStart(PGconn* conn); +extern PostgresPollingStatusType PQresetPoll(PGconn* conn); + +/* Synchronous (blocking) */ +extern void PQreset(PGconn* conn); + +/* request a cancel structure */ +extern PGcancel* PQgetCancel(PGconn* conn); + +/* free a cancel structure */ +extern void PQfreeCancel(PGcancel* cancel); + +/* issue a cancel request */ +extern int PQcancel(PGcancel* cancel, char* errbuf, int errbufsize); +extern int PQcancel_timeout(PGcancel* cancel, char* errbuf, int errbufsize, int timeout); + +/* issue a stop request */ +extern int PQStop(PGcancel* cancel, char* errbuf, int errbufsize, unsigned long query_id); +extern int PQstop_timeout(PGcancel* cancel, char* errbuf, int errbufsize, int timeout, unsigned long query_id); + +/* issue a stream connect request */ +extern int StreamConnect(void* raddr, ConnPack* csp, int packetlen, char* errbuf, int errbufsize); + +/* backwards compatible version of PQcancel; not thread-safe */ +extern int PQrequestCancel(PGconn* conn); + +/* Accessor functions for PGconn objects */ +extern char* PQdb(const PGconn* conn); +extern char* PQuser(const PGconn* conn); +extern char* PQpass(const PGconn* conn); +extern char* PQhost(const PGconn* conn); +extern char* PQport(const PGconn* conn); +extern char* PQtty(const PGconn* conn); +extern char* PQoptions(const PGconn* conn); +extern ConnStatusType PQstatus(const PGconn* conn); +extern PGTransactionStatusType PQtransactionStatus(const PGconn* conn); +extern const char* PQparameterStatus(const PGconn* conn, const char* paramName); +extern int PQprotocolVersion(const PGconn* conn); +extern int PQserverVersion(const PGconn* conn); +extern char* PQerrorMessage(const PGconn* conn); +extern int PQsocket(const PGconn* conn); + +extern struct sockaddr* PQLocalSockaddr(const PGconn* conn); +extern struct sockaddr* PQRemoteSockaddr(const PGconn* conn); + +extern int PQbackendPID(const PGconn* conn); +extern int PQconnectionNeedsPassword(const PGconn* conn); +extern int PQconnectionUsedPassword(const PGconn* conn); +extern int PQclientEncoding(const PGconn* conn); +extern int PQsetClientEncoding(PGconn* conn, const char* encoding); +extern int PQsetRwTimeout(PGconn* conn, int build_receive_timeout); + +/* Get the OpenSSL structure associated with a connection. Returns NULL for + * unencrypted connections or if any other TLS library is in use. */ +extern void* PQgetssl(PGconn* conn); + +/* Tell libpq whether it needs to initialize OpenSSL */ +extern void PQinitSSL(int do_init); + +/* More detailed way to tell libpq whether it needs to initialize OpenSSL */ +extern void PQinitOpenSSL(int do_ssl, int do_crypto); + +/* Set verbosity for PQerrorMessage and PQresultErrorMessage */ +extern PGVerbosity PQsetErrorVerbosity(PGconn* conn, PGVerbosity verbosity); + +/* Enable/disable tracing */ +extern void PQtrace(PGconn* conn, FILE* debug_port); +extern void PQuntrace(PGconn* conn); + +/* Override default notice handling routines */ +extern PQnoticeReceiver PQsetNoticeReceiver(PGconn* conn, PQnoticeReceiver proc, void* arg); +extern PQnoticeProcessor PQsetNoticeProcessor(PGconn* conn, PQnoticeProcessor proc, void* arg); + +/* + * Used to set callback that prevents concurrent access to + * non-thread safe functions that libpq needs. + * The default implementation uses a libpq internal mutex. + * Only required for multithreaded apps that use kerberos + * both within their app and for postgresql connections. + */ +typedef void (*pgthreadlock_t)(int acquire); + +extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler); + +/* === in fe-exec.c === */ + +/* Simple synchronous query */ +extern PGresult* PQexec(PGconn* conn, const char* query); +extern PGresult* PQexecParams(PGconn* conn, const char* command, int nParams, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); +extern PGresult* PQexecParamsBatch(PGconn* conn, const char* command, int nParams, int nBatch, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern PGresult* PQprepare(PGconn* conn, const char* stmtName, const char* query, int nParams, const Oid* paramTypes); +extern PGresult* PQexecPrepared(PGconn* conn, const char* stmtName, int nParams, const char* const* paramValues, + const int* paramLengths, const int* paramFormats, int resultFormat); +extern PGresult* PQexecPreparedBatch(PGconn* conn, const char* stmtName, int nParams, int nBatchCount, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +/* Interface for multiple-result or asynchronous queries */ +extern int PQsendQuery(PGconn* conn, const char* query); +extern int PqSendQueryCheckConnValid(Oid nod_oid, PGconn* conn, const char* query); +extern int PQsendQueryPoolerStatelessReuse(PGconn* conn, const char* query); +extern int PQsendQueryParams(PGconn* conn, const char* command, int nParams, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); +extern int PQsendQueryParamsBatch(PGconn* conn, const char* command, int nParams, int nBatch, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern int PQsendPrepare(PGconn* conn, const char* stmtName, const char* query, int nParams, const Oid* paramTypes); +extern int PQsendQueryPrepared(PGconn* conn, const char* stmtName, int nParams, const char* const* paramValues, + const int* paramLengths, const int* paramFormats, int resultFormat); +extern int PQsendQueryPreparedBatch(PGconn* conn, const char* stmtName, int nParams, int nBatchCount, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern int PQsetSingleRowMode(PGconn* conn); +extern PGresult* PQgetResult(PGconn* conn); + +/* Routines for managing an asynchronous query */ +extern int PQisBusy(PGconn* conn); +extern int PQconsumeInput(PGconn* conn); + +/* LISTEN/NOTIFY support */ +extern PGnotify* PQnotifies(PGconn* conn); + +/* Routines for copy in/out */ +extern int PQputCopyData(PGconn* conn, const char* buffer, int nbytes); +extern int PQputCopyEnd(PGconn* conn, const char* errormsg); +extern int PQgetCopyData(PGconn* conn, char** buffer, int async); + +/* Deprecated routines for copy in/out */ +extern int PQgetline(PGconn* conn, char* string, int length); +extern int PQputline(PGconn* conn, const char* string); +extern int PQgetlineAsync(PGconn* conn, char* buffer, int bufsize); +extern int PQputnbytes(PGconn* conn, const char* buffer, int nbytes); +extern int PQendcopy(PGconn* conn); + +/* Set blocking/nonblocking connection to the backend */ +extern int PQsetnonblocking(PGconn* conn, int arg); +extern int PQisnonblocking(const PGconn* conn); +extern int PQisthreadsafe(void); +extern PGPing PQping(const char* conninfo); +extern PGPing PQpingParams(const char* const* keywords, const char* const* values, int expand_dbname); + +/* Force the write buffer to be written (or at least try) */ +extern int PQflush(PGconn* conn); + +/* + * "Fast path" interface --- not really recommended for application + * use + */ +extern PGresult* PQfn( + PGconn* conn, int fnid, int* result_buf, int* result_len, int result_is_int, const PQArgBlock* args, int nargs); + +/* Accessor functions for PGresult objects */ +extern ExecStatusType PQresultStatus(const PGresult* res); +extern char* PQresStatus(ExecStatusType status); +extern char* PQresultErrorMessage(const PGresult* res); +extern char* PQresultErrorField(const PGresult* res, int fieldcode); +extern int PQntuples(const PGresult* res); +extern int PQnfields(const PGresult* res); +extern int PQbinaryTuples(const PGresult* res); +extern char* PQfname(const PGresult* res, int field_num); +extern int PQfnumber(const PGresult* res, const char* field_name); +extern Oid PQftable(const PGresult* res, int field_num); +extern int PQftablecol(const PGresult* res, int field_num); +extern int PQfformat(const PGresult* res, int field_num); +extern Oid PQftype(const PGresult* res, int field_num); +extern int PQfsize(const PGresult* res, int field_num); +extern int PQfmod(const PGresult* res, int field_num); +extern char* PQcmdStatus(PGresult* res); +extern char* PQoidStatus(const PGresult* res); /* old and ugly */ +extern Oid PQoidValue(const PGresult* res); /* new and improved */ +extern char* PQcmdTuples(PGresult* res); +extern char* PQgetvalue(const PGresult* res, int tup_num, int field_num); +extern int PQgetlength(const PGresult* res, int tup_num, int field_num); +extern int PQgetisnull(const PGresult* res, int tup_num, int field_num); +extern int PQnparams(const PGresult* res); +extern Oid PQparamtype(const PGresult* res, int param_num); + +/* Describe prepared statements and portals */ +extern PGresult* PQdescribePrepared(PGconn* conn, const char* stmt); +extern PGresult* PQdescribePortal(PGconn* conn, const char* portal); +extern int PQsendDescribePrepared(PGconn* conn, const char* stmt); +extern int PQsendDescribePortal(PGconn* conn, const char* portal); + +/* Delete a PGresult */ +extern void PQclear(PGresult* res); + +/* For freeing other alloc'd results, such as PGnotify structs */ +extern void PQfreemem(void* ptr); + +/* Exists for backward compatibility. bjm 2003-03-24 */ +#define PQfreeNotify(ptr) PQfreemem(ptr) + +/* Create and manipulate PGresults */ +extern PGresult* PQmakeEmptyPGresult(PGconn* conn, ExecStatusType status); +extern PGresult* PQcopyResult(const PGresult* src, unsigned int flags); +extern int PQsetResultAttrs(PGresult* res, int numAttributes, PGresAttDesc* attDescs); +extern void* PQresultAlloc(PGresult* res, size_t nBytes); +extern int PQsetvalue(PGresult* res, int tup_num, int field_num, const char* value, int len); + +/* Quoting strings before inclusion in queries. */ +extern size_t PQescapeStringConn(PGconn* conn, char* to, const char* from, size_t length, int* error); +extern char* PQescapeLiteral(PGconn* conn, const char* str, size_t len); +extern char* PQescapeIdentifier(PGconn* conn, const char* str, size_t len); +extern unsigned char *PQescapeByteaConn(PGconn *conn, const unsigned char *from, + size_t from_length, size_t *to_length); +extern unsigned char* PQunescapeBytea(const unsigned char* strtext, size_t* retbuflen); + +/* These forms are deprecated! */ +extern size_t PQescapeString(char* to, const char* from, size_t length); +extern unsigned char* PQescapeBytea(const unsigned char* from, size_t from_length, size_t* to_length); +#ifdef HAVE_CE +extern void checkRefreshCacheOnError(PGconn* conn); +#endif + +/* === in fe-print.c === */ + +extern void PQprint(FILE* fout, /* output stream */ + const PGresult* res, const PQprintOpt* ps); /* option structure */ + +/* + * really old printing routines + */ +extern void PQdisplayTuples(const PGresult* res, FILE* fp, /* where to send the output */ + int fillAlign, /* pad the fields with spaces */ + const char* fieldSep, /* field separator */ + int printHeader, /* display headers? */ + int quiet); + +extern void PQprintTuples(const PGresult* res, FILE* fout, /* output stream */ + int printAttName, /* print attribute names */ + int terseOutput, /* delimiter bars */ + int width); /* width of column, if 0, use variable width */ + +/* === in fe-lobj.c === */ + +/* Large-object access routines */ +extern int lo_open(PGconn* conn, Oid lobjId, int mode); +extern int lo_close(PGconn* conn, int fd); +extern int lo_read(PGconn* conn, int fd, char* buf, size_t len); +extern int lo_write(PGconn* conn, int fd, const char* buf, size_t len); +extern int lo_lseek(PGconn* conn, int fd, int offset, int whence); +extern Oid lo_creat(PGconn* conn, int mode); +extern Oid lo_create(PGconn* conn, Oid lobjId); +extern int lo_tell(PGconn* conn, int fd); +extern int lo_truncate(PGconn* conn, int fd, size_t len); +extern int lo_unlink(PGconn* conn, Oid lobjId); +extern Oid lo_import(PGconn* conn, const char* filename); +extern Oid lo_import_with_oid(PGconn* conn, const char* filename, Oid lobjId); +extern int lo_export(PGconn* conn, Oid lobjId, const char* filename); + +/* === in fe-misc.c === */ + +/* Get the version of the libpq library in use */ +extern int PQlibVersion(void); + +/* Determine length of multibyte encoded char at *s */ +extern int PQmblen(const char* s, int encoding); + +/* Determine display length of multibyte encoded char at *s */ +extern int PQdsplen(const char* s, int encoding); + +/* Get encoding id from environment variable PGCLIENTENCODING */ +extern int PQenv2encoding(void); + +/* === in fe-auth.c === */ + +extern char* PQencryptPassword(const char* passwd, const char* user); + +/* === in encnames.c === */ + +extern int pg_char_to_encoding(const char* name); +extern const char* pg_encoding_to_char(int encoding); +extern int pg_valid_server_encoding_id(int encoding); + +extern void parseInput(PGconn* conn); + +extern PGresult* getCopyResult(PGconn* conn, ExecStatusType copytype); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq-fs.h postgresql-hll-2.14/include/include/libpq/libpq-fs.h --- postgresql-hll-2.14_old/include/include/libpq/libpq-fs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq-fs.h 2020-12-12 17:06:43.225347754 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * libpq-fs.h + * definitions for using Inversion file system routines (ie, large objects) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq-fs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_FS_H +#define LIBPQ_FS_H + +/* + * Read/write mode flags for inversion (large object) calls + */ + +#define INV_WRITE 0x00020000 +#define INV_READ 0x00040000 + +#endif /* LIBPQ_FS_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq.h postgresql-hll-2.14/include/include/libpq/libpq.h --- postgresql-hll-2.14_old/include/include/libpq/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq.h 2020-12-12 17:06:43.225347754 +0800 @@ -0,0 +1,111 @@ +/* ------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_H +#define LIBPQ_H + +#include +#include + +#include "lib/stringinfo.h" +#include "libpq/libpq-be.h" + +/* ---------------- + * PQArgBlock + * Information (pointer to array of this structure) required + * for the PQfn() call. (This probably ought to go somewhere else...) + * ---------------- + */ +typedef struct { + int len; + int isint; + union { + int* ptr; /* can't use void (dec compiler barfs) */ + int integer; + } u; +} PQArgBlock; + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, const char* unixSocketName, + pgsocket ListenSocket[], int MaxListen, bool add_localaddr_flag, + bool is_create_psql_sock, bool is_create_libcomm_sock); +extern int StreamConnection(pgsocket server_fd, Port* port); +extern void StreamClose(pgsocket sock); +extern void TouchSocketFile(void); +extern void pq_init(void); +extern void pq_comm_reset(void); +extern int pq_getbytes(char* s, size_t len); +extern int pq_getstring(StringInfo s); +extern int pq_getmessage(StringInfo s, int maxlen); +extern int pq_getbyte(void); +extern int pq_peekbyte(void); +extern int pq_getbyte_if_available(unsigned char* c); +extern int pq_putbytes(const char* s, size_t len); +extern int pq_flush(void); +extern int pq_flush_if_writable(void); +extern void pq_flush_timedwait(int timeout); +extern bool pq_is_send_pending(void); +extern int pq_putmessage(char msgtype, const char* s, size_t len); +extern int pq_putmessage_noblock(char msgtype, const char* s, size_t len); +extern void pq_startcopyout(void); +extern void pq_endcopyout(bool errorAbort); +extern bool pq_select(int timeout_ms); +extern void pq_abandon_sendbuffer(void); +extern void pq_abandon_recvbuffer(void); +extern void pq_resize_recvbuffer(int size); +extern void pq_revert_recvbuffer(const char* data, int len); +/* + * prototypes for functions in be-secure.c + */ +extern const char* ssl_cipher_file; +extern const char* ssl_rand_file; + +extern bool secure_loaded_verify_locations(void); +extern void secure_destroy(void); +extern int secure_open_server(Port* port); +extern void secure_close(Port* port); +extern ssize_t secure_read(Port* port, void* ptr, size_t len); +extern ssize_t secure_write(Port* port, void* ptr, size_t len); + +/* + * interface for flushing sendbuffer to disk + */ + +typedef enum TempFileState { + TEMPFILE_DEFAULT, + TEMPFILE_CREATED, + TEMPFILE_FLUSHED, + TEMPFILE_ON_SENDING, + TEMPFILE_SENDED, + TEMPFILE_CLOSED, + TEMPFILE_ERROR_CLOSE, + TEMPFILE_ERROR_SEND, +} TempFileState; + +extern void pq_disk_reset_tempfile_contextinfo(void); +extern void pq_disk_discard_temp_file(void); +extern bool pq_disk_is_flushed(void); +extern int pq_disk_send_to_frontend(void); +extern void pq_disk_extract_sendbuffer(void); +extern void pq_disk_enable_temp_file(void); +extern void pq_disk_disable_temp_file(void); +extern bool pq_disk_is_temp_file_enabled(void); +extern bool pq_disk_is_temp_file_created(void); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/libpq-int.h postgresql-hll-2.14/include/include/libpq/libpq-int.h --- postgresql-hll-2.14_old/include/include/libpq/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/libpq-int.h 2020-12-12 17:06:43.226347767 +0800 @@ -0,0 +1,675 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * + * IDENTIFICATION + * src/include/libpq/libpq-int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_INT_H +#define LIBPQ_INT_H + +/* We assume libpq-fe.h has already been included. */ +#include "postgres_fe.h" +#include "libpq-events.h" + +#include +#include +#ifndef WIN32 +#include +#endif + +#include +#include +#include + +#ifdef ENABLE_THREAD_SAFETY +#ifdef WIN32 +#include "pthread-win32.h" +#else +#include +#endif +#include +#endif + +/* include stuff common to fe and be */ +#include "getaddrinfo.h" +#include "libpq/pqcomm.h" +#include "libpq/sha2.h" +/* include stuff found in fe only */ +#include "pqexpbuffer.h" +#include "cipher.h" +#include "../../include/securec.h" +#include "../../include/securec_check.h" +#include "libcomm/libcomm.h" + +#ifdef ENABLE_GSS +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif +#endif + +#ifdef ENABLE_SSPI +#define SECURITY_WIN32 +#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER) +#include +#endif +#include +#undef SECURITY_WIN32 + +#ifndef ENABLE_GSS +/* + * Define a fake structure compatible with GSSAPI on Unix. + */ +typedef struct { + void* value; + int length; +} gss_buffer_desc; +#endif +#endif /* ENABLE_SSPI */ + +#ifdef USE_SSL +#include "openssl/ossl_typ.h" +#endif /* USE_SSL */ + +#ifdef HAVE_CE +#include "cl_state.h" +#endif + +/* + * POSTGRES backend dependent Constants. + */ +#define CMDSTATUS_LEN 64 /* should match COMPLETION_TAG_BUFSIZE */ +#define MAX_ERRMSG_LENGTH 1024 + +/* + * PGresult and the subsidiary types PGresAttDesc, PGresAttValue + * represent the result of a query (or more precisely, of a single SQL + * command --- a query string given to PQexec can contain multiple commands). + * Note we assume that a single command can return at most one tuple group, + * hence there is no need for multiple descriptor sets. + */ + +/* Subsidiary-storage management structure for PGresult. + * See space management routines in fe-exec.c for details. + * Note that space[k] refers to the k'th byte starting from the physical + * head of the block --- it's a union, not a struct! + */ +typedef union pgresult_data PGresult_data; + +union pgresult_data { + PGresult_data* next; /* link to next block, or NULL */ + char space[1]; /* dummy for accessing block as bytes */ +}; + +/* Data about a single parameter of a prepared statement */ +typedef struct pgresParamDesc { + Oid typid; /* type id */ +} PGresParamDesc; + +/* + * Data for a single attribute of a single tuple + * + * We use char* for Attribute values. + * + * The value pointer always points to a null-terminated area; we add a + * null (zero) byte after whatever the backend sends us. This is only + * particularly useful for text values ... with a binary value, the + * value might have embedded nulls, so the application can't use C string + * operators on it. But we add a null anyway for consistency. + * Note that the value itself does not contain a length word. + * + * A NULL attribute is a special case in two ways: its len field is NULL_LEN + * and its value field points to null_field in the owning PGresult. All the + * NULL attributes in a query result point to the same place (there's no need + * to store a null string separately for each one). + */ +#define NULL_LEN (-1) /* pg_result len for NULL value */ + +typedef struct pgresAttValue { + int len; /* length in bytes of the value */ + char* value; /* actual value, plus terminating zero byte */ +} PGresAttValue; + +/* Typedef for message-field list entries */ +typedef struct pgMessageField { + struct pgMessageField* next; /* list link */ + char code; /* field code */ + char contents[1]; /* field value (VARIABLE LENGTH) */ +} PGMessageField; + +/* Fields needed for notice handling */ +typedef struct { + PQnoticeReceiver noticeRec; /* notice message receiver */ + void* noticeRecArg; + PQnoticeProcessor noticeProc; /* notice message processor */ + void* noticeProcArg; +} PGNoticeHooks; + +typedef struct PGEvent { + PGEventProc proc; /* the function to call on events */ + char* name; /* used only for error messages */ + void* passThrough; /* pointer supplied at registration time */ + void* data; /* optional state (instance) data */ + bool resultInitialized; /* T if RESULTCREATE/COPY succeeded */ +} PGEvent; + +struct pg_result { + int ntups; + int numAttributes; + PGresAttDesc* attDescs; + PGresAttValue** tuples; /* each PGresTuple is an array of + * PGresAttValue's */ + int tupArrSize; /* allocated size of tuples array */ + int numParameters; + PGresParamDesc* paramDescs; + ExecStatusType resultStatus; + char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the query */ + int binary; /* binary tuple values if binary == 1, + * otherwise text */ + + /* + * These fields are copied from the originating PGconn, so that operations + * on the PGresult don't have to reference the PGconn. + */ + PGNoticeHooks noticeHooks; + PGEvent* events; + int nEvents; + int client_encoding; /* encoding id */ + + /* + * Error information (all NULL if not an error result). errMsg is the + * "overall" error message returned by PQresultErrorMessage. If we have + * per-field info then it is stored in a linked list. + */ + char* errMsg; /* error message, or NULL if no error */ + PGMessageField* errFields; /* message broken into fields */ + + /* All NULL attributes in the query result point to this null string */ + char null_field[1]; + + /* + * Space management information. Note that attDescs and error stuff, if + * not null, point into allocated blocks. But tuples points to a + * separately malloc'd block, so that we can realloc it. + */ + PGresult_data* curBlock; /* most recently allocated block */ + int curOffset; /* start offset of free space in block */ + int spaceLeft; /* number of free bytes remaining in block */ +}; + +/* PGAsyncStatusType defines the state of the query-execution state machine */ +typedef enum { + PGASYNC_IDLE, /* nothing's happening, dude */ + PGASYNC_BUSY, /* query in progress */ + PGASYNC_READY, /* result ready for PQgetResult */ + PGASYNC_COPY_IN, /* Copy In data transfer in progress */ + PGASYNC_COPY_OUT, /* Copy Out data transfer in progress */ + PGASYNC_COPY_BOTH /* Copy In/Out data transfer in progress */ +} PGAsyncStatusType; + +/* PGQueryClass tracks which query protocol we are now executing */ +typedef enum { + PGQUERY_SIMPLE, /* simple Query protocol (PQexec) */ + PGQUERY_EXTENDED, /* full Extended protocol (PQexecParams) */ + PGQUERY_PREPARE, /* Parse only (PQprepare) */ + PGQUERY_DESCRIBE /* Describe Statement or Portal */ +} PGQueryClass; + +/* PGSetenvStatusType defines the state of the PQSetenv state machine */ +/* (this is used only for 2.0-protocol connections) */ +typedef enum { + SETENV_STATE_CLIENT_ENCODING_SEND, /* About to send an Environment Option */ + SETENV_STATE_CLIENT_ENCODING_WAIT, /* Waiting for above send to complete */ + SETENV_STATE_OPTION_SEND, /* About to send an Environment Option */ + SETENV_STATE_OPTION_WAIT, /* Waiting for above send to complete */ + SETENV_STATE_QUERY1_SEND, /* About to send a status query */ + SETENV_STATE_QUERY1_WAIT, /* Waiting for query to complete */ + SETENV_STATE_QUERY2_SEND, /* About to send a status query */ + SETENV_STATE_QUERY2_WAIT, /* Waiting for query to complete */ + SETENV_STATE_IDLE +} PGSetenvStatusType; + +/* Typedef for the EnvironmentOptions[] array */ +typedef struct PQEnvironmentOption { + const char *envName, /* name of an environment variable */ + *pgName; /* name of corresponding SET variable */ +} PQEnvironmentOption; + +/* Typedef for parameter-status list entries */ +typedef struct pgParameterStatus { + struct pgParameterStatus* next; /* list link */ + char* name; /* parameter name */ + char* value; /* parameter value */ + /* Note: name and value are stored in same malloc block as struct is */ +} pgParameterStatus; + +/* large-object-access data ... allocated only if large-object code is used. */ +typedef struct pgLobjfuncs { + Oid fn_lo_open; /* OID of backend function lo_open */ + Oid fn_lo_close; /* OID of backend function lo_close */ + Oid fn_lo_creat; /* OID of backend function lo_creat */ + Oid fn_lo_create; /* OID of backend function lo_create */ + Oid fn_lo_unlink; /* OID of backend function lo_unlink */ + Oid fn_lo_lseek; /* OID of backend function lo_lseek */ + Oid fn_lo_tell; /* OID of backend function lo_tell */ + Oid fn_lo_truncate; /* OID of backend function lo_truncate */ + Oid fn_lo_read; /* OID of backend function LOread */ + Oid fn_lo_write; /* OID of backend function LOwrite */ +} PGlobjfuncs; + +/* PGdataValue represents a data field value being passed to a row processor. + * It could be either text or binary data; text data is not zero-terminated. + * A SQL NULL is represented by len < 0; then value is still valid but there + * are no data bytes there. + */ +typedef struct pgDataValue { + int len; /* data length in bytes, or <0 if NULL */ + const char* value; /* data value, without zero-termination */ +} PGdataValue; + +/* + * PGconn stores all the state data associated with a single connection + * to a backend. + */ +struct pg_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the numeric IP address of the machine on + * which the server is running. Takes + * precedence over above. */ + char* pgport; /* the server's communication port */ + char* pglocalhost; /* The localhost specified in one conenct channel */ + char* pglocalport; /* The localport specified in one conenct channel */ + char* pgunixsocket; /* the Unix-domain socket that the server is + * listening on; if NULL, uses a default + * constructed from pgport */ + char* pgtty; /* tty on which the backend messages is + * displayed (OBSOLETE, NOT USED) */ + char* connect_timeout; /* connection timeout (numeric string) */ + char* client_encoding_initial; /* encoding to use */ + char* pgoptions; /* options to start the backend with */ + char* appname; /* application name */ + char* fbappname; /* fallback application name */ + char* dbName; /* database name */ + char* replication; /* connect as the replication standby? */ + char* backend_version; /* backend version to be passed to the remote end */ + char* pguser; /* Postgres username and password, if any */ + char* pgpass; + char* keepalives; /* use TCP keepalives? */ + char* keepalives_idle; /* time between TCP keepalives */ + char* keepalives_interval; /* time between TCP keepalive + * retransmits */ + char* keepalives_count; /* maximum number of TCP keepalive + * retransmits */ + char* rw_timeout; /* read-write timeout during idle connection.*/ + char* sslmode; /* SSL mode (require,prefer,allow,disable) */ + char* sslcompression; /* SSL compression (0 or 1) */ + char* sslkey; /* client key filename */ + char* sslcert; /* client certificate filename */ + char* sslrootcert; /* root certificate filename */ + char* sslcrl; /* certificate revocation list filename */ + char* requirepeer; /* required peer credentials for local sockets */ + unsigned char cipher_passwd[CIPHER_LEN + 1]; + +#if defined(KRB5) || defined(ENABLE_GSS) || defined(ENABLE_SSPI) + char* krbsrvname; /* Kerberos service name */ +#endif + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Callback procedures for notice message processing */ + PGNoticeHooks noticeHooks; + + /* Event procs registered via PQregisterEventProc */ + PGEvent* events; /* expandable array of event data */ + int nEvents; /* number of active events */ + int eventArraySize; /* allocated array size */ + + /* Status indicators */ + ConnStatusType status; + PGAsyncStatusType asyncStatus; + PGTransactionStatusType xactStatus; /* never changes to ACTIVE */ + PGQueryClass queryclass; + char* last_query; /* last SQL command, or NULL if unknown */ + char last_sqlstate[6]; /* last reported SQLSTATE */ + bool options_valid; /* true if OK to attempt connection */ + bool nonblocking; /* whether this connection is using nonblock + * sending semantics */ + bool singleRowMode; /* return current query result row-by-row? */ + char copy_is_binary; /* 1 = copy binary, 0 = copy text */ + int copy_already_done; /* # bytes already returned in COPY + * OUT */ + PGnotify* notifyHead; /* oldest unreported Notify msg */ + PGnotify* notifyTail; /* newest unreported Notify msg */ + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + SockAddr laddr; /* Local address */ + SockAddr raddr; /* Remote address */ + char *remote_nodename; /* remote datanode name */ + ProtocolVersion pversion; /* FE/BE protocol version in use */ + int sversion; /* server version, e.g. 70401 for 7.4.1 */ + bool auth_req_received; /* true if any type of auth req + * received */ + bool password_needed; /* true if server demanded a password */ + bool dot_pgpass_used; /* true if used .pgpass */ + bool sigpipe_so; /* have we masked SIGPIPE via SO_NOSIGPIPE? */ + bool sigpipe_flag; /* can we mask SIGPIPE via MSG_NOSIGNAL? */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + PGSetenvStatusType setenv_state; /* for 2.0 protocol only */ + const PQEnvironmentOption* next_eo; + bool send_appname; /* okay to send application_name? */ + + /* Miscellaneous stuff */ + ThreadId be_pid; /* PID of backend --- needed for cancels */ + ThreadId remote_pid; /* remote pid */ + int be_key; /* key of backend --- needed for cancels */ + char md5Salt[4]; /* password salt received from backend */ + /*password stored method on server : md5, sha256 or plain*/ + int32 password_stored_method; + pgParameterStatus* pstatus; /* ParameterStatus data */ + int client_encoding; /* encoding id */ + bool std_strings; /* standard_conforming_strings */ + PGVerbosity verbosity; /* error/notice message verbosity */ + PGlobjfuncs* lobjfuncs; /* private state for large-object access fns */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Row processor interface workspace */ + PGdataValue* rowBuf; /* array for passing values to rowProcessor */ + int rowBufLen; /* number of entries allocated in rowBuf */ + + /* Status for asynchronous result construction */ + PGresult* result; /* result being constructed */ + PGresult* next_result; /* next result (used in single-row mode) */ + + /* Assorted state for SSL, GSS, etc */ +#ifdef USE_SSL + bool allow_ssl_try; /* Allowed to try SSL negotiation */ + bool wait_ssl_try; /* Delay SSL negotiation until after + * attempting normal connection */ + + SSL* ssl; /* SSL status, if have SSL connection */ + X509* peer; /* X509 cert of server */ +#endif /* USE_SSL */ + +#ifdef ENABLE_GSS + gss_ctx_id_t gctx; /* GSS context */ + gss_name_t gtarg_nam; /* GSS target name */ + gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc goutbuf; /* GSS output token */ +#endif + +#ifdef ENABLE_SSPI +#ifndef ENABLE_GSS + gss_buffer_desc ginbuf; /* GSS input token */ +#else + char* gsslib; /* What GSS librart to use ("gssapi" or + * "sspi") */ +#endif + CredHandle* sspicred; /* SSPI credentials handle */ + CtxtHandle* sspictx; /* SSPI context */ + char* sspitarget; /* SSPI target name */ + int usesspi; /* Indicate if SSPI is in use on the + * connection */ +#endif + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + /* begin RFC 5802 */ + char sever_signature[STORED_KEY_LENGTH * 2 + 1]; + char salt[SALT_LENGTH * 2 + 1]; + char token[TOKEN_LENGTH * 2 + 1]; + /* end RFC 5802 */ + + /* Stored the encrypted password and clientkey for gsql parallel execute. */ + char encrypted_passwd[SHA256_PASSWD_LEN + CLIENT_KEY_STRING_LENGTH + 1]; + + /* fenced udf RPC use unix domain socket and special socket file name */ + bool fencedUdfRPCMode; + /* Support adjust iteration to adapt the hardware development for safe reason. */ + int iteration_count; + /* flag to identify the logic connection between cn and dn */ + bool is_logic_conn; + /* logic connection address between cn and dn */ + libcommaddrinfo libcomm_addrinfo; + /* Connection_info is a json string containing driver_name, driver_version, driver_path and os_user. + * If connection_info is not NULL, use connection_info and ignore the value of connection_extra_info. + * If connection_info is NULL: + * generate connection_info strings related to libpq. + * connection_info has only driver_name and driver_version while connection_extra_info is false. + */ + char* connection_info; + bool connection_extra_info; + +#ifdef HAVE_CE + PGClientLogic* client_logic; +#endif +}; + +/* PGcancel stores all data necessary to cancel a connection. A copy of this + * data is required to safely cancel a connection running on a different + * thread. + */ +struct pg_cancel { + SockAddr raddr; /* Remote address */ + ThreadId be_pid; /* PID of backend --- needed for cancels */ + int be_key; /* key of backend --- needed for cancels */ +}; + +/* String descriptions of the ExecStatusTypes. + * direct use of this array is deprecated; call PQresStatus() instead. + */ +extern char* const pgresStatus[]; + +/* ---------------- + * Internal functions of libpq + * Functions declared here need to be visible across files of libpq, + * but are not intended to be called by applications. We use the + * convention "pqXXX" for internal functions, vs. the "PQxxx" names + * used for application-visible routines. + * ---------------- + */ + +/* === in fe-connect.c === */ +extern THR_LOCAL bool g_pq_interrupt_happened; +extern int pqPacketSend(PGconn* conn, char pack_type, const void* buf, size_t buf_len); +extern bool pqGetHomeDirectory(char* buf, int bufsize); + +#define PGTHREAD_ERROR(msg) \ + do { \ + fprintf(stderr, "%s\n", msg); \ + abort(); \ + } while (0) + +#ifdef ENABLE_THREAD_SAFETY +extern pgthreadlock_t pg_g_threadlock; + +#define pglock_thread() pg_g_threadlock(true) +#define pgunlock_thread() pg_g_threadlock(false) +#else +#define pglock_thread() ((void)0) +#define pgunlock_thread() ((void)0) +#endif + +/* === in fe-exec.c === */ + +extern void pqSetResultError(PGresult* res, const char* msg); +extern void pqCatenateResultError(PGresult* res, const char* msg); +extern void* pqResultAlloc(PGresult* res, size_t nBytes, bool isBinary); +extern char* pqResultStrdup(PGresult* res, const char* str); +extern void pqClearAsyncResult(PGconn* conn); +extern void pqSaveErrorResult(PGconn* conn); +extern PGresult* pqPrepareAsyncResult(PGconn* conn); +extern void pqInternalNotice(const PGNoticeHooks* hooks, const char* fmt, ...) + /* This lets gcc check the format string for consistency. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); +extern void pqSaveMessageField(PGresult* res, char code, const char* value, PGconn* conn = NULL); +extern void pqSaveParameterStatus(PGconn* conn, const char* name, const char* value); +extern int pqRowProcessor(PGconn* conn, const char** errmsgp); +extern void pqHandleSendFailure(PGconn* conn); + +/* === in fe-protocol2.c === */ + +extern PostgresPollingStatusType pqSetenvPoll(PGconn* conn); + +extern char* pqBuildStartupPacket2(PGconn* conn, int* packetlen, const PQEnvironmentOption* options); +extern void pqParseInput2(PGconn* conn); +extern int pqGetCopyData2(PGconn* conn, char** buffer, int async); +extern int pqGetline2(PGconn* conn, char* s, int maxlen); +extern int pqGetlineAsync2(PGconn* conn, char* buffer, int bufsize); +extern int pqEndcopy2(PGconn* conn); +extern PGresult* pqFunctionCall2(PGconn* conn, Oid fnid, int* result_buf, int* actual_result_len, int result_is_int, + const PQArgBlock* args, int nargs); + +/* === in fe-protocol3.c === */ + +extern char* pqBuildStartupPacket3(PGconn* conn, int* packetlen, const PQEnvironmentOption* options); +extern void pqParseInput3(PGconn* conn); +extern int pqGetErrorNotice3(PGconn* conn, bool isError); +extern int pqGetCopyData3(PGconn* conn, char** buffer, int async); +extern int pqGetline3(PGconn* conn, char* s, int maxlen); +extern int pqGetlineAsync3(PGconn* conn, char* buffer, int bufsize); +extern int pqEndcopy3(PGconn* conn); +extern PGresult* pqFunctionCall3(PGconn* conn, Oid fnid, int* result_buf, int* actual_result_len, int result_is_int, + const PQArgBlock* args, int nargs); + +/* === in fe-misc.c === */ + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int pqCheckOutBufferSpace(size_t bytes_needed, PGconn* conn); +extern int pqCheckInBufferSpace(size_t bytes_needed, PGconn* conn); +extern int pqGetc(char* result, PGconn* conn); +extern int pqPutc(char c, PGconn* conn); +extern int pqGets(PQExpBuffer buf, PGconn* conn); +extern int pqGets_append(PQExpBuffer buf, PGconn* conn); +extern int pqPuts(const char* s, PGconn* conn); +extern int pqGetnchar(char* s, size_t len, PGconn* conn); +extern int pqSkipnchar(size_t len, PGconn* conn); +extern int pqPutnchar(const char* s, size_t len, PGconn* conn); +extern int pqGetInt(int* result, size_t bytes, PGconn* conn); +extern int64 pqGetInt64(int64 *result, PGconn *conn); +extern int pqPutInt(int value, size_t bytes, PGconn* conn); +extern int pqPutMsgStart(char msg_type, bool force_len, PGconn* conn); +extern int pqPutMsgEnd(PGconn* conn); +extern int pqReadData(PGconn* conn); +extern int pqFlush(PGconn* conn); +extern int pqWait(int forRead, int forWrite, PGconn* conn); +extern int pqWaitTimed(int forRead, int forWrite, PGconn* conn, time_t finish_time); +extern int pqReadReady(PGconn* conn); +extern int pqWriteReady(PGconn* conn); + +/* === in fe-secure.c === */ + +extern int pqsecure_initialize(PGconn*); +extern void pqsecure_destroy(void); +extern PostgresPollingStatusType pqsecure_open_client(PGconn*); +extern void pqsecure_close(PGconn*); +extern ssize_t pqsecure_read(PGconn*, void* ptr, size_t len); +extern ssize_t pqsecure_write(PGconn*, const void* ptr, size_t len); +extern ssize_t pgfdw_pqsecure_read(PGconn*, void* ptr, size_t len); +extern ssize_t pgfdw_pqsecure_write(PGconn*, const void* ptr, size_t len); + +#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) +extern int pq_block_sigpipe(sigset_t* osigset, bool* sigpipe_pending); +extern void pq_reset_sigpipe(sigset_t* osigset, bool sigpipe_pending, bool got_epipe); +#endif + +/* + * this is so that we can check if a connection is non-blocking internally + * without the overhead of a function call + */ +#define pqIsnonblocking(conn) ((conn)->nonblocking) + +#ifdef ENABLE_NLS +extern char* libpq_gettext(const char* msgid) __attribute__((format_arg(1))); +#else +#define libpq_gettext(x) (x) +#endif + +/* + * These macros are needed to let error-handling code be portable between + * Unix and Windows. (ugh) + */ +#ifdef WIN32 +#define SOCK_ERRNO (WSAGetLastError()) +#define SOCK_STRERROR winsock_strerror +#define SOCK_ERRNO_SET(e) WSASetLastError(e) +#else +#define SOCK_ERRNO errno +#define SOCK_STRERROR pqStrerror +#define SOCK_ERRNO_SET(e) (errno = (e)) +#endif + +/* erase the memory pointed by p, with sz bytes */ +#define erase_mem(p, sz) memset((p), 0, (sz)) + +/* Erase the memory of array spcecified by arr */ +#define erase_arr(arr) erase_mem((arr), sizeof(arr)) + +/* Erase the memory of a string specified by s */ +#define erase_string(s) \ + do { \ + int l_to_erase = strlen(s); \ + erase_mem((s), l_to_erase); \ + } while (0) + +#define check_memcpy_s(r) securec_check_c((r), "", "") +#define check_memmove_s(r) securec_check_c((r), "", "") +#define check_memset_s(r) securec_check_c((r), "", "") +#define check_strcpy_s(r) securec_check_c((r), "", "") +#define check_strncpy_s(r) securec_check_c((r), "", "") +#define check_strcat_s(r) securec_check_c((r), "", "") +#define check_strncat_s(r) securec_check_c((r), "", "") +#define check_gets_s(r) securec_check_ss_c((r), "", "") +#define check_sprintf_s(r) securec_check_ss_c((r), "", "") +#define check_snprintf_s(r) securec_check_ss_c((r), "", "") +#define check_scanf_s(r) securec_check_ss_c((r), "", "") + +extern void* libpq_realloc(void* src, size_t old_len, size_t new_len); + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/md5.h postgresql-hll-2.14/include/include/libpq/md5.h --- postgresql-hll-2.14_old/include/include/libpq/md5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/md5.h 2020-12-12 17:06:43.226347767 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * md5.h + * Interface to libpq/md5.c + * + * These definitions are needed by both frontend and backend code to work + * with MD5-encrypted passwords. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/md5.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_MD5_H +#define PG_MD5_H + +#define MD5_PASSWD_CHARSET "0123456789abcdef" +#define MD5_PASSWD_LEN 35 + +#define isMD5(passwd) \ + ((strncmp(passwd, "md5", 3) == 0) && (strlen(passwd) == MD5_PASSWD_LEN) && \ + (strspn(passwd + 3, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN - 3)) + +extern bool pg_md5_hash(const void* buff, size_t len, char* hexsum); +extern bool pg_md5_binary(const void* buff, size_t len, void* outbuf); +extern bool pg_md5_encrypt(const char* passwd, const char* salt, size_t salt_len, char* buf); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/libpq/pqcomm.h postgresql-hll-2.14/include/include/libpq/pqcomm.h --- postgresql-hll-2.14_old/include/include/libpq/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/pqcomm.h 2020-12-12 17:06:43.226347767 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqcomm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQCOMM_H +#define PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE + +#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY +#define ss_family __ss_family +#else +#error struct sockaddr_storage does not provide an ss_family member +#endif +#endif + +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN +#define ss_len __ss_len +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1 +#endif +#else /* !HAVE_STRUCT_SOCKADDR_STORAGE */ + +/* Define a struct sockaddr_storage if we don't have one. */ +struct sockaddr_storage { + union { + struct sockaddr sa; /* get the system-dependent fields */ + int64 ss_align; /* ensures struct is properly aligned */ + char ss_pad[128]; /* ensures struct has desired size */ + } ss_stuff; +}; + +#define ss_family ss_stuff.sa.sa_family +/* It should have an ss_len field if sockaddr has sa_len. */ +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN +#define ss_len ss_stuff.sa.sa_len +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1 +#endif +#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */ + +typedef struct { + struct sockaddr_storage addr; + ACCEPT_TYPE_ARG3 salen; +} SockAddr; + +extern const char* check_client_env(const char* input_env_value); +/* Configure the UNIX socket location for the well known port. */ +#define UNIXSOCK_PATH(path, port, sockdir) \ + do { \ + int rc = 0; \ + const char* unixSocketDir = NULL; \ + const char* pghost = gs_getenv_r("PGHOST"); \ + if (check_client_env(pghost) == NULL) { \ + pghost = NULL; \ + } \ + if (sockdir != NULL && (*sockdir) != '\0') { \ + unixSocketDir = sockdir; \ + } else { \ + if (pghost != NULL && (*pghost) != '\0') { \ + unixSocketDir = pghost; \ + } else { \ + unixSocketDir = DEFAULT_PGSOCKET_DIR; \ + } \ + } \ + rc = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/.s.PGSQL.%d", unixSocketDir, (port)); \ + securec_check_ss_c(rc, "\0", "\0"); \ + } while (0) + +#define UNIXSOCK_FENCED_MASTER_PATH(path, sockdir) \ + do { \ + int rc = 0; \ + const char* unixSocketDir = NULL; \ + const char* pghost = gs_getenv_r("PGHOST"); \ + if (check_client_env(pghost) == NULL) { \ + pghost = NULL; \ + } \ + if (sockdir != NULL && (*sockdir) != '\0') { \ + unixSocketDir = sockdir; \ + } else { \ + if (pghost != NULL && (*pghost) != '\0') { \ + unixSocketDir = pghost; \ + } else { \ + unixSocketDir = DEFAULT_PGSOCKET_DIR; \ + } \ + } \ + rc = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/.s.fencedMaster_unixdomain", unixSocketDir); \ + securec_check_ss_c(rc, "\0", "\0"); \ + } while (0) + +/* + * The maximum workable length of a socket path is what will fit into + * struct sockaddr_un. This is usually only 100 or so bytes :-(. + * + * For consistency, always pass a MAXPGPATH-sized buffer to UNIXSOCK_PATH(), + * then complain if the resulting string is >= UNIXSOCK_PATH_BUFLEN bytes. + * (Because the standard API for getaddrinfo doesn't allow it to complain in + * a useful way when the socket pathname is too long, we have to test for + * this explicitly, instead of just letting the subroutine return an error.) + */ +#define UNIXSOCK_PATH_BUFLEN sizeof(((struct sockaddr_un*)NULL)->sun_path) + +/* + * These manipulate the frontend/backend protocol version number. + * + * The major number should be incremented for incompatible changes. The minor + * number should be incremented for compatible changes (eg. additional + * functionality). + * + * If a backend supports version m.n of the protocol it must actually support + * versions m.[0..n]. Backend support for version m-1 can be dropped after a + * `reasonable' length of time. + * + * A frontend isn't required to support anything other than the current + * version. + */ + +#define PG_PROTOCOL_MAJOR(v) ((v) >> 16) +#define PG_PROTOCOL_MINOR(v) ((v)&0x0000ffff) +#define PG_PROTOCOL(m, n) (((m) << 16) | (n)) + +/* The protocol versions server supported */ +extern const unsigned short protoVersionList[][2]; + +/* The earliest and latest frontend/backend protocol version supported. */ +#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1, 0) +#define PG_PROTOCOL_LATEST PG_PROTOCOL(3, 51) +#define PG_PROTOCOL_GAUSS_BASE 50 + +typedef uint32 ProtocolVersion; /* FE/BE protocol version number */ + +typedef ProtocolVersion MsgType; + +/* + * Packet lengths are 4 bytes in network byte order. + * + * The initial length is omitted from the packet layouts appearing below. + */ + +typedef uint32 PacketLen; + +/* + * Old-style startup packet layout with fixed-width fields. This is used in + * protocol 1.0 and 2.0, but not in later versions. Note that the fields + * in this layout are '\0' terminated only if there is room. + */ + +#define SM_DATABASE 64 +#define SM_USER 32 +#define SM_OPTIONS 64 +#define SM_UNUSED 64 +#define SM_TTY 64 + +typedef struct StartupPacket { + ProtocolVersion protoVersion; /* Protocol version */ + char database[SM_DATABASE]; /* Database name */ + char user[SM_USER]; /* User name */ + char options[SM_OPTIONS]; /* Optional additional args */ + char unused[SM_UNUSED]; /* Unused */ + char tty[SM_TTY]; /* Tty for debug output */ +} StartupPacket; + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +/* These are the authentication request codes sent by the backend. */ +#define AUTH_REQ_OK 0 /* User is authenticated */ +#define AUTH_REQ_KRB4 1 /* Kerberos V4. Not supported any more. */ +#define AUTH_REQ_KRB5 2 /* Kerberos V5 */ +#define AUTH_REQ_PASSWORD 3 /* Password */ +#define AUTH_REQ_CRYPT 4 /* crypt password. Not supported any more. */ +#define AUTH_REQ_MD5 5 /* md5 password */ +#define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */ +#define AUTH_REQ_GSS 7 /* GSSAPI without wrap() */ +#define AUTH_REQ_GSS_CONT 8 /* Continue GSS exchanges */ +#define AUTH_REQ_SSPI 9 /* SSPI negotiate without wrap() */ + +#define AUTH_REQ_SHA256 10 /* sha256 password */ +#define AUTH_REQ_MD5_SHA256 11 /* md5_auth_sha256_stored password */ +#define AUTH_REQ_IAM 12 /* iam token authenication */ + +typedef uint32 AuthRequest; + +/* + * A client can also send a cancel-current-operation request to the postmaster. + * This is uglier than sending it directly to the client's backend, but it + * avoids depending on out-of-band communication facilities. + * + * The cancel request code must not match any protocol version number + * we're ever likely to use. This random choice should do. + */ +#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234, 5678) + +typedef struct CancelRequestPacket { + /* Note that each field is stored in network byte order! */ + MsgType cancelRequestCode; /* code to identify a cancel request */ + uint32 backendPID; /* PID of client's backend */ + uint32 cancelAuthCode; /* secret key to authorize cancel */ +} CancelRequestPacket; + +/* + * A client can also start by sending a SSL negotiation request, to get a + * secure channel. + */ +#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234, 5679) + +/* + * A client can also start by sending stop query request + */ +#define STOP_REQUEST_CODE PG_PROTOCOL(1234, 5681) +typedef struct StopRequestPacket { + /* Note that each field is stored in network byte order! */ + MsgType stopRequestCode; /* code to identify a stop request */ + uint32 backendPID; /* PID of client's backend */ + uint32 query_id_first; /* query id of front 4 bytes */ + uint32 query_id_end; /* query id of back 4 bytes */ +} StopRequestPacket; + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/pqexpbuffer.h postgresql-hll-2.14/include/include/libpq/pqexpbuffer.h --- postgresql-hll-2.14_old/include/include/libpq/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/pqexpbuffer.h 2020-12-12 17:06:43.226347767 +0800 @@ -0,0 +1,204 @@ +/* --------------------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/libpq/pqexpbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PG_PRINTF_ATTRIBUTE +#ifdef WIN32 +#define PG_PRINTF_ATTRIBUTE gnu_printf +#else +#define PG_PRINTF_ATTRIBUTE printf +#endif +#endif + +/*------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + * ------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/*------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + * ------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/*------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + * ------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/*------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + * ------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/*------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + * ------------------------- + */ + +/*------------------------ + * createPQExpBuffer + * Create an empty 'PQExpBufferData' & return a pointer to it. + */ +extern PQExpBuffer createPQExpBuffer(void); + +/*------------------------ + * initPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createPQExpBuffer(). + * + * termPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void destroyPQExpBuffer(PQExpBuffer str); +extern void termPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * resetPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * enlargePQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed); + +#ifndef WIN32 +/*------------------------ + * printfPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetPQExpBuffer() followed by appendPQExpBuffer(). + */ +extern void printfPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/*------------------------ + * appendPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +#else +extern void printfPQExpBuffer(PQExpBuffer str, const char* fmt, ...); +extern void appendPQExpBuffer(PQExpBuffer str, const char* fmt, ...); +#endif +/*------------------------ + * appendPQExpBufferStr + * Append the given string to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendPQExpBufferStr(PQExpBuffer str, const char* data); + +/*------------------------ + * appendPQExpBufferChar + * Append a single byte to str. + * Like appendPQExpBuffer(str, "%c", ch) but much faster. + */ +extern void appendPQExpBufferChar(PQExpBuffer str, char ch); + +/*------------------------ + * appendBinaryPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#ifdef __cplusplus +} +#endif + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/pqformat.h postgresql-hll-2.14/include/include/libpq/pqformat.h --- postgresql-hll-2.14_old/include/include/libpq/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/pqformat.h 2020-12-12 17:06:43.227347780 +0800 @@ -0,0 +1,210 @@ +/* ------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqformat.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "lib/stringinfo.h" +#include "mb/pg_wchar.h" + +extern void pq_beginmessage(StringInfo buf, char msgtype); +extern void pq_beginmessage_reuse(StringInfo buf, char msgtype); +extern void pq_sendbytes(StringInfo buf, const char* data, int datalen); +extern void pq_sendcountedtext(StringInfo buf, const char* str, int slen, bool countincludesself); +extern void pq_sendtext(StringInfo buf, const char* str, int slen); +extern void pq_sendstring(StringInfo buf, const char* str); +extern void pq_send_ascii_string(StringInfo buf, const char* str); +extern void pq_sendfloat4(StringInfo buf, float4 f); +extern void pq_sendfloat8(StringInfo buf, float8 f); +extern void pq_endmessage(StringInfo buf); +extern void pq_endmessage_reuse(StringInfo buf); +extern void pq_endmessage_noblock(StringInfo buf); + +extern void pq_begintypsend(StringInfo buf); +extern bytea* pq_endtypsend(StringInfo buf); + +extern void pq_puttextmessage(char msgtype, const char* str); +extern void pq_puttextmessage_noblock(char msgtype, const char* str); +extern void pq_putemptymessage(char msgtype); +extern void pq_putemptymessage_noblock(char msgtype); + +extern int pq_getmsgbyte(StringInfo msg); +extern unsigned int pq_getmsgint(StringInfo msg, int b); +extern int64 pq_getmsgint64(StringInfo msg); +extern float4 pq_getmsgfloat4(StringInfo msg); +extern float8 pq_getmsgfloat8(StringInfo msg); +extern const char* pq_getmsgbytes(StringInfo msg, int datalen); +extern void pq_copymsgbytes(StringInfo msg, char* buf, int datalen); +extern char* pq_getmsgtext(StringInfo msg, int rawbytes, int* nbytes); +extern const char* pq_getmsgstring(StringInfo msg); +extern void pq_getmsgend(StringInfo msg); + +/* + * Append a [u]int8 to a StringInfo buffer, which already has enough space + * preallocated. + * + * The use of restrict allows the compiler to optimize the code based on the + * assumption that buf, buf->len, buf->data and *buf->data don't + * overlap. Without the annotation buf->len etc cannot be kept in a register + * over subsequent pq_writeintN calls. + * + * The use of StringInfoData * rather than StringInfo is due to MSVC being + * overly picky and demanding a * before a restrict. + */ +static inline void pq_writeint8(StringInfoData* pg_restrict buf, uint8 i) +{ + uint8 ni = i; + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint8), &ni, sizeof(uint8)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint8); +} + +/* + * Append a [u]int16 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint16(StringInfoData* pg_restrict buf, uint16 i) +{ + uint16 ni = htons(i); + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint16), &ni, sizeof(uint16)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint16); +} + +/* + * Append a [u]int32 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint32(StringInfoData* pg_restrict buf, uint32 i) +{ + uint32 ni = htonl(i); + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &ni, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); +} + +/* + * Append a [u]int64 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint64(StringInfoData* pg_restrict buf, uint64 i) +{ + uint32 n32; + errno_t rc = EOK; + + /* High order half first, since we're doing MSB-first */ + n32 = (uint32)(i >> 32); + n32 = htonl(n32); + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &n32, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); + + /* Now the low order half */ + n32 = (uint32)i; + n32 = htonl(n32); + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &n32, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); +} + +/* + * Append a null-terminated text string (with conversion) to a buffer with + * preallocated space. + * + * NB: The pre-allocated space needs to be sufficient for the string after + * converting to client encoding. + * + * NB: passed text string must be null-terminated, and so is the data + * sent to the frontend. + */ +static inline void pq_writestring(StringInfoData* pg_restrict buf, const char* pg_restrict str) +{ + int slen = strlen(str); + char* p = NULL; + errno_t rc = EOK; + + p = pg_server_to_client(str, slen); + if (p != str) /* actual conversion has been done? */ + slen = strlen(p); + + rc = memcpy_s(((char* pg_restrict)buf->data + buf->len), slen + 1, p, slen + 1); + securec_check(rc, "\0", "\0"); + buf->len += slen + 1; + + if (p != str) + pfree(p); +} + +/* append a binary [u]int8 to a StringInfo buffer */ +static inline void pq_sendint8(StringInfo buf, uint8 i) +{ + enlargeStringInfo(buf, sizeof(uint8)); + pq_writeint8(buf, i); +} + +/* append a binary [u]int16 to a StringInfo buffer */ +static inline void pq_sendint16(StringInfo buf, uint16 i) +{ + enlargeStringInfo(buf, sizeof(uint16)); + pq_writeint16(buf, i); +} + +/* append a binary [u]int32 to a StringInfo buffer */ +static inline void pq_sendint32(StringInfo buf, uint32 i) +{ + enlargeStringInfo(buf, sizeof(uint32)); + pq_writeint32(buf, i); +} + +/* append a binary [u]int64 to a StringInfo buffer */ +static inline void pq_sendint64(StringInfo buf, uint64 i) +{ + enlargeStringInfo(buf, sizeof(uint64)); + pq_writeint64(buf, i); +} + +/* append a binary byte to a StringInfo buffer */ +static inline void pq_sendbyte(StringInfo buf, uint8 byt) +{ + pq_sendint8(buf, byt); +} + +/* + * Append a binary integer to a StringInfo buffer + * + * This function is deprecated; prefer use of the functions above. + */ +static inline void pq_sendint(StringInfo buf, uint32 i, int b) +{ + switch (b) { + case 1: + pq_sendint8(buf, (uint8)i); + break; + case 2: + pq_sendint16(buf, (uint16)i); + break; + case 4: + pq_sendint32(buf, (uint32)i); + break; + default: + elog(ERROR, "unsupported integer size %d", b); + break; + } +} + +#endif /* PQFORMAT_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/pqsignal.h postgresql-hll-2.14/include/include/libpq/pqsignal.h --- postgresql-hll-2.14_old/include/include/libpq/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/pqsignal.h 2020-12-12 17:06:43.227347780 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqsignal.h + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * ------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +#ifdef HAVE_SIGPROCMASK +#define PG_SETMASK(mask) pthread_sigmask(SIG_SETMASK, mask, NULL) +#else /* not HAVE_SIGPROCMASK */ + +#ifndef WIN32 +#define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) +#else +#define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) +int pqsigsetmask(int mask); +#endif + +#define sigaddset(set, signum) (*(set) |= (sigmask(signum))) +#define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) +#endif /* not HAVE_SIGPROCMASK */ + +typedef void (*pqsigfunc)(int); + +extern void pqinitmask(void); + +extern pqsigfunc pqsignal(int signo, pqsigfunc func); + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/libpq/sha2.h postgresql-hll-2.14/include/include/libpq/sha2.h --- postgresql-hll-2.14_old/include/include/libpq/sha2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/libpq/sha2.h 2020-12-12 17:06:43.227347780 +0800 @@ -0,0 +1,115 @@ +/* contrib/pgcrypto/sha2.h */ +/* $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $ */ + +/* + * FILE: sha2.h + * AUTHOR: Aaron D. Gifford + * + * Copyright (c) 2000-2001, Aaron D. Gifford + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ + */ + +#ifndef _SHA2_H +#define _SHA2_H + +/* avoid conflict with OpenSSL */ +#define SHA256_Init2 gs_SHA256_Init +#define SHA256_Update2 gs_SHA256_Update +#define SHA256_Final2 gs_SHA256_Final + +/*** SHA-256 Various Length Definitions ***********************/ +#define SHA256_BLOCK_LENGTH 64 +#define SHA256_DIGEST_LENGTH 32 +#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) + +/*** SHA-256 Context Structures *******************************/ +#define K_LENGTH 32 +#define ITERATION_COUNT 10000 +#define CLIENT_STRING_LENGTH 11 +#define SEVER_STRING_LENGTH 10 +#define HMAC_LENGTH 32 +#define HMAC_BYTES_LENGTH 32 +#define HMAC_STRING_LENGTH (HMAC_LENGTH * 2) +#define STORED_KEY_LENGTH 32 +#define STORED_KEY_BYTES_LENGTH STORED_KEY_LENGTH +#define STORED_KEY_STRING_LENGTH (STORED_KEY_LENGTH * 2) +#define CLIENT_KEY_BYTES_LENGTH 32 +#define CLIENT_KEY_STRING_LENGTH (CLIENT_KEY_BYTES_LENGTH * 2) +#define SALT_LENGTH 32 +#define SALT_BYTE_LENGTH 32 +#define SALT_STRING_LENGTH (SALT_LENGTH * 2) +#define H_LENGTH 64 +#define ENCRYPTED_STRING_LENGTH (HMAC_STRING_LENGTH + STORED_KEY_STRING_LENGTH + SALT_STRING_LENGTH) +#define TOKEN_LENGTH 4 +#define SHA256_LENGTH 6 +#define SHA256_PASSWD_LEN (ENCRYPTED_STRING_LENGTH + SHA256_LENGTH) +#define SHA256_MD5_ENCRY_PASSWD_LEN 70 +#define ITERATION_STRING_LEN 11 /* The length of INT_MAX(2147483647) */ +#define SHA256_MD5_COMBINED_LEN (SHA256_PASSWD_LEN + MD5_PASSWD_LEN + ITERATION_STRING_LEN) + +#define isSHA256(passwd) \ + (strncmp(passwd, "sha256", SHA256_LENGTH) == 0 && strlen(passwd) == SHA256_PASSWD_LEN + ITERATION_STRING_LEN) + +/* Check combined password for compatible with PG. */ +#define isCOMBINED(passwd) \ + (strncmp(passwd, "sha256", SHA256_LENGTH) == 0 && strncmp(passwd + SHA256_PASSWD_LEN, "md5", 3) == 0) + +/* Check whether it is encrypted password. */ +#define isPWDENCRYPTED(passwd) (isMD5(passwd) || isSHA256(passwd) || isCOMBINED(passwd)) + +/* The current password stored method are sha256, md5 and combined. */ +#define PLAIN_PASSWORD 0 +#define MD5_PASSWORD 1 +#define SHA256_PASSWORD 2 +#define ERROR_PASSWORD 3 +#define BAD_MEM_ADDR 4 +#define COMBINED_PASSWORD 5 + +typedef struct _SHA256_CTX2 { + uint32 state[8]; + uint64 bitcount; + uint8 buffer[SHA256_BLOCK_LENGTH]; +} SHA256_CTX2; + +void SHA256_Init2(SHA256_CTX2*); +void SHA256_Update2(SHA256_CTX2*, const uint8*, size_t); +void SHA256_Final2(uint8[SHA256_DIGEST_LENGTH], SHA256_CTX2*); + +/* Use the old iteration ITERATION_COUNT as the default iteraion count. */ +extern bool pg_sha256_encrypt(const char* passwd, const char* salt_s, size_t salt_len, char* buf, char* client_key_buf, + int iteration_count = ITERATION_COUNT); +extern int XOR_between_password(const char* password1, const char* password2, char* r, int length); +extern void sha_hex_to_bytes32(char* s, const char b[64]); +extern void sha_hex_to_bytes4(char* s, const char b[8]); +extern void sha_bytes_to_hex8(uint8 b[4], char* s); +extern void sha_bytes_to_hex64(uint8 b[32], char* s); +extern bool pg_sha256_encrypt_for_md5(const char* passwd, const char* salt, size_t salt_len, char* buf); + +#endif /* _SHA2_H */ + diff -uprN postgresql-hll-2.14_old/include/include/mb/pg_wchar.h postgresql-hll-2.14/include/include/mb/pg_wchar.h --- postgresql-hll-2.14_old/include/include/mb/pg_wchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/mb/pg_wchar.h 2020-12-12 17:06:43.227347780 +0800 @@ -0,0 +1,484 @@ +/* ------------------------------------------------------------------------- + * + * pg_wchar.h + * multibyte-character support + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/mb/pg_wchar.h + * + * NOTES + * This is used both by the backend and by libpq, but should not be + * included by libpq client programs. In particular, a libpq client + * should not assume that the encoding IDs used by the version of libpq + * it's linked to match up with the IDs declared here. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_WCHAR_H +#define PG_WCHAR_H + +#ifndef WIN32 +#include +#endif + +/* + * The pg_wchar type + */ +typedef unsigned int pg_wchar; + +/* + * various definitions for EUC + */ +#define SS2 0x8e /* single shift 2 (JIS0201) */ +#define SS3 0x8f /* single shift 3 (JIS0212) */ + +/* + * SJIS validation macros + */ +#define ISSJISHEAD(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc)) +#define ISSJISTAIL(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc)) + +/* + * Leading byte types or leading prefix byte for MULE internal code. + * See http://www.xemacs.org for more details. (there is a doc titled + * "XEmacs Internals Manual", "MULE Character Sets and Encodings" + * section.) + */ +/* + * Is a leading byte for "official" single byte encodings? + */ +#define IS_LC1(c) ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d) +/* + * Is a prefix byte for "private" single byte encodings? + */ +#define LCPRV1_A 0x9a +#define LCPRV1_B 0x9b +#define IS_LCPRV1(c) ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B) +#define IS_LCPRV1_A_RANGE(c) ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf) +#define IS_LCPRV1_B_RANGE(c) ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef) +/* + * Is a leading byte for "official" multibyte encodings? + */ +#define IS_LC2(c) ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99) +/* + * Is a prefix byte for "private" multibyte encodings? + */ +#define LCPRV2_A 0x9c +#define LCPRV2_B 0x9d +#define IS_LCPRV2(c) ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B) +#define IS_LCPRV2_A_RANGE(c) ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4) +#define IS_LCPRV2_B_RANGE(c) ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe) + +/* ---------------------------------------------------- + * leading characters + * ---------------------------------------------------- + */ + +/* + * Official single byte encodings (0x81-0x8e) + */ +#define LC_ISO8859_1 0x81 /* ISO8859 Latin 1 */ +#define LC_ISO8859_2 0x82 /* ISO8859 Latin 2 */ +#define LC_ISO8859_3 0x83 /* ISO8859 Latin 3 */ +#define LC_ISO8859_4 0x84 /* ISO8859 Latin 4 */ +#define LC_TIS620 0x85 /* Thai (not supported yet) */ +#define LC_ISO8859_7 0x86 /* Greek (not supported yet) */ +#define LC_ISO8859_6 0x87 /* Arabic (not supported yet) */ +#define LC_ISO8859_8 0x88 /* Hebrew (not supported yet) */ +#define LC_JISX0201K 0x89 /* Japanese 1 byte kana */ +#define LC_JISX0201R 0x8a /* Japanese 1 byte Roman */ +/* Note that 0x8b seems to be unused as of Emacs 20.7. + * However, there might be a chance that 0x8b could be used + * in later version of Emacs. + */ +#define LC_KOI8_R 0x8b /* Cyrillic KOI8-R */ +#define LC_KOI8_U 0x8b /* Cyrillic KOI8-U */ +#define LC_ISO8859_5 0x8c /* ISO8859 Cyrillic */ +#define LC_ISO8859_9 0x8d /* ISO8859 Latin 5 (not supported yet) */ +/* FREE 0x8e free (unused) */ + +/* + * Unused + */ +#define CONTROL_1 0x8f /* control characters (unused) */ + +/* + * Official multibyte byte encodings (0x90-0x99) + * 0x9a-0x9d are free. 0x9e and 0x9f are reserved. + */ +#define LC_JISX0208_1978 0x90 /* Japanese Kanji, old JIS (not supported) */ +#define LC_GB2312_80 0x91 /* Chinese */ +#define LC_JISX0208 0x92 /* Japanese Kanji (JIS X 0208) */ +#define LC_KS5601 0x93 /* Korean */ +#define LC_JISX0212 0x94 /* Japanese Kanji (JIS X 0212) */ +#define LC_CNS11643_1 0x95 /* CNS 11643-1992 Plane 1 */ +#define LC_CNS11643_2 0x96 /* CNS 11643-1992 Plane 2 */ +/* FREE 0x97 free (unused) */ +#define LC_BIG5_1 0x98 /* Plane 1 Chinese traditional (not supported) */ +#define LC_BIG5_2 0x99 /* Plane 1 Chinese traditional (not supported) */ + +/* + * Private single byte encodings (0xa0-0xef) + */ +#define LC_SISHENG \ + 0xa0 /* Chinese SiSheng characters for \ + * PinYin/ZhuYin (not supported) */ +#define LC_IPA \ + 0xa1 /* IPA (International Phonetic Association) \ + * (not supported) */ +#define LC_VISCII_LOWER \ + 0xa2 /* Vietnamese VISCII1.1 lower-case (not \ + * supported) */ +#define LC_VISCII_UPPER \ + 0xa3 /* Vietnamese VISCII1.1 upper-case (not \ + * supported) */ +#define LC_ARABIC_DIGIT 0xa4 /* Arabic digit (not supported) */ +#define LC_ARABIC_1_COLUMN 0xa5 /* Arabic 1-column (not supported) */ +#define LC_ASCII_RIGHT_TO_LEFT \ + 0xa6 /* ASCII (left half of ISO8859-1) with \ + * right-to-left direction (not \ + * supported) */ +#define LC_LAO \ + 0xa7 /* Lao characters (ISO10646 0E80..0EDF) (not \ + * supported) */ +#define LC_ARABIC_2_COLUMN 0xa8 /* Arabic 1-column (not supported) */ + +/* + * Private multibyte encodings (0xf0-0xff) + */ +#define LC_INDIAN_1_COLUMN \ + 0xf0 /* Indian charset for 1-column width glypps \ + * (not supported) */ +#define LC_TIBETAN_1_COLUMN 0xf1 /* Tibetan 1 column glyph (not supported) */ +#define LC_ETHIOPIC 0xf5 /* Ethiopic characters (not supported) */ +#define LC_CNS11643_3 0xf6 /* CNS 11643-1992 Plane 3 */ +#define LC_CNS11643_4 0xf7 /* CNS 11643-1992 Plane 4 */ +#define LC_CNS11643_5 0xf8 /* CNS 11643-1992 Plane 5 */ +#define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */ +#define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */ +#define LC_INDIAN_2_COLUMN \ + 0xfb /* Indian charset for 2-column width glypps \ + * (not supported) */ +#define LC_TIBETAN 0xfc /* Tibetan (not supported) */ +/* FREE 0xfd free (unused) */ +/* FREE 0xfe free (unused) */ +/* FREE 0xff free (unused) */ + +/* + * PostgreSQL encoding identifiers + * + * WARNING: the order of this enum must be same as order of entries + * in the pg_enc2name_tbl[] array (in mb/encnames.c), and + * in the pg_wchar_table[] array (in mb/wchar.c)! + * + * If you add some encoding don't forget to check + * PG_ENCODING_BE_LAST macro. + * + * PG_SQL_ASCII is default encoding and must be = 0. + * + * XXX We must avoid renumbering any backend encoding until libpq's major + * version number is increased beyond 5; it turns out that the backend + * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and + * psql are concerned. + */ +typedef enum pg_enc { + PG_SQL_ASCII = 0, /* SQL/ASCII */ + PG_EUC_JP, /* EUC for Japanese */ + PG_EUC_CN, /* EUC for Chinese */ + PG_EUC_KR, /* EUC for Korean */ + PG_EUC_TW, /* EUC for Taiwan */ + PG_EUC_JIS_2004, /* EUC-JIS-2004 */ + // supports GBK for server encoding + PG_GBK, /* GBK (Windows-936) */ + PG_UTF8, /* Unicode UTF8 */ + PG_MULE_INTERNAL, /* Mule internal code */ + PG_LATIN1, /* ISO-8859-1 Latin 1 */ + PG_LATIN2, /* ISO-8859-2 Latin 2 */ + PG_LATIN3, /* ISO-8859-3 Latin 3 */ + PG_LATIN4, /* ISO-8859-4 Latin 4 */ + PG_LATIN5, /* ISO-8859-9 Latin 5 */ + PG_LATIN6, /* ISO-8859-10 Latin6 */ + PG_LATIN7, /* ISO-8859-13 Latin7 */ + PG_LATIN8, /* ISO-8859-14 Latin8 */ + PG_LATIN9, /* ISO-8859-15 Latin9 */ + PG_LATIN10, /* ISO-8859-16 Latin10 */ + PG_WIN1256, /* windows-1256 */ + PG_WIN1258, /* Windows-1258 */ + PG_WIN866, /* (MS-DOS CP866) */ + PG_WIN874, /* windows-874 */ + PG_KOI8R, /* KOI8-R */ + PG_WIN1251, /* windows-1251 */ + PG_WIN1252, /* windows-1252 */ + PG_ISO_8859_5, /* ISO-8859-5 */ + PG_ISO_8859_6, /* ISO-8859-6 */ + PG_ISO_8859_7, /* ISO-8859-7 */ + PG_ISO_8859_8, /* ISO-8859-8 */ + PG_WIN1250, /* windows-1250 */ + PG_WIN1253, /* windows-1253 */ + PG_WIN1254, /* windows-1254 */ + PG_WIN1255, /* windows-1255 */ + PG_WIN1257, /* windows-1257 */ + PG_KOI8U, /* KOI8-U */ + /* PG_ENCODING_BE_LAST points to the above entry */ + + /* followings are for client encoding only */ + PG_SJIS, /* Shift JIS (Winindows-932) */ + PG_BIG5, /* Big5 (Windows-950) */ + PG_UHC, /* UHC (Windows-949) */ + PG_GB18030, /* GB18030 */ + PG_JOHAB, /* EUC for Korean JOHAB */ + PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */ + _PG_LAST_ENCODING_ /* mark only */ + +} pg_enc; + +#define PG_ENCODING_BE_LAST PG_KOI8U + +/* + * Please use these tests before access to pg_encconv_tbl[] + * or to other places... + */ +#define PG_VALID_BE_ENCODING(_enc) ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST) + +#define PG_ENCODING_IS_CLIENT_ONLY(_enc) ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_) + +#define PG_VALID_ENCODING(_enc) ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_) + +/* On FE are possible all encodings */ +#define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc) + +/* + * When converting strings between different encodings, we assume that space + * for converted result is 4-to-1 growth in the worst case. The rate for + * currently supported encoding pairs are within 3 (SJIS JIS X0201 half width + * kanna -> UTF8 is the worst case). So "4" should be enough for the moment. + * + * Note that this is not the same as the maximum character width in any + * particular encoding. + */ +#define MAX_CONVERSION_GROWTH 4 + +/* + * Encoding names with all aliases + */ +typedef struct pg_encname { + char* name; + pg_enc encoding; +} pg_encname; + +extern pg_encname pg_encname_tbl[]; +extern unsigned int pg_encname_tbl_sz; + +/* + * Careful: + * + * if (PG_VALID_ENCODING(encoding)) + * pg_enc2name_tbl[ encoding ]; + */ +typedef struct pg_enc2name { + char* name; + pg_enc encoding; +#ifdef WIN32 + unsigned codepage; /* codepage for WIN32 */ +#endif +} pg_enc2name; + +extern pg_enc2name pg_enc2name_tbl[]; + +/* + * Encoding names for gettext + */ +typedef struct pg_enc2gettext { + pg_enc encoding; + const char* name; +} pg_enc2gettext; + +extern pg_enc2gettext pg_enc2gettext_tbl[]; + +/* + * pg_wchar stuff + */ +typedef int (*mb2wchar_with_len_converter)(const unsigned char* from, pg_wchar* to, int len); + +typedef int (*wchar2mb_with_len_converter)(const pg_wchar* from, unsigned char* to, int len); + +typedef int (*mblen_converter)(const unsigned char* mbstr); + +typedef int (*mbdisplaylen_converter)(const unsigned char* mbstr); + +typedef bool (*mbcharacter_incrementer)(unsigned char* mbstr, int len); + +typedef int (*mbverifier)(const unsigned char* mbstr, int len); + +typedef struct { + mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multibyte + * string to a wchar */ + wchar2mb_with_len_converter wchar2mb_with_len; /* convert a wchar + * string to a multibyte */ + mblen_converter mblen; /* get byte length of a char */ + mbdisplaylen_converter dsplen; /* get display width of a char */ + mbverifier mbverify; /* verify multibyte sequence */ + int maxmblen; /* max bytes for a char in this encoding */ +} pg_wchar_tbl; + +extern pg_wchar_tbl pg_wchar_table[]; + +/* + * UTF-8 to local code conversion map + * Note that we limit the max length of UTF-8 to 4 bytes, + * which is UCS-4 00010000-001FFFFF range. + */ +typedef struct { + uint32 utf; /* UTF-8 */ + uint32 code; /* local code */ +} pg_utf_to_local; + +/* + * local code to UTF-8 conversion map + */ +typedef struct { + uint32 code; /* local code */ + uint32 utf; /* UTF-8 */ +} pg_local_to_utf; + +/* + * UTF-8 to local code conversion map(combined characters) + */ +typedef struct { + uint32 utf1; /* UTF-8 code 1 */ + uint32 utf2; /* UTF-8 code 2 */ + uint32 code; /* local code */ +} pg_utf_to_local_combined; + +/* + * local code to UTF-8 conversion map(combined characters) + */ +typedef struct { + uint32 code; /* local code */ + uint32 utf1; /* UTF-8 code 1 */ + uint32 utf2; /* UTF-8 code 2 */ +} pg_local_to_utf_combined; + +/* + * Support macro for encoding conversion functions to validate their + * arguments. (This could be made more compact if we included fmgr.h + * here, but we don't want to do that because this header file is also + * used by frontends.) + */ +#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding) \ + check_encoding_conversion_args( \ + PG_GETARG_INT32(0), PG_GETARG_INT32(1), PG_GETARG_INT32(4), (srcencoding), (destencoding)) + +/* + * These functions are considered part of libpq's exported API and + * are also declared in libpq-fe.h. + */ +extern "C" int pg_char_to_encoding(const char* name); +extern "C" const char* pg_encoding_to_char(int encoding); +extern "C" int pg_valid_server_encoding_id(int encoding); + +/* + * Remaining functions are not considered part of libpq's API, though many + * of them do exist inside libpq. + */ +extern pg_encname* pg_char_to_encname_struct(const char* name); + +extern int pg_mb2wchar(const char* from, pg_wchar* to); +extern int pg_mb2wchar_with_len(const char* from, pg_wchar* to, int len); +extern int pg_encoding_mb2wchar_with_len(int encoding, const char* from, pg_wchar* to, int len); +extern int pg_wchar2mb(const pg_wchar* from, char* to); +extern int pg_wchar2mb_with_len(const pg_wchar* from, char* to, int len); +extern int pg_encoding_wchar2mb_with_len(int encoding, const pg_wchar* from, char* to, int len); +extern int pg_char_and_wchar_strcmp(const char* s1, const pg_wchar* s2); +extern int pg_wchar_strncmp(const pg_wchar* s1, const pg_wchar* s2, size_t n); +extern int pg_char_and_wchar_strncmp(const char* s1, const pg_wchar* s2, size_t n); +extern size_t pg_wchar_strlen(const pg_wchar* wstr); +extern int pg_mblen(const char* mbstr); +extern int pg_dsplen(const char* mbstr); +extern int pg_encoding_mblen(int encoding, const char* mbstr); +extern int pg_encoding_dsplen(int encoding, const char* mbstr); +extern int pg_encoding_verifymb(int encoding, const char* mbstr, int len); +extern int pg_mule_mblen(const unsigned char* mbstr); +extern int pg_mic_mblen(const unsigned char* mbstr); +extern int pg_mbstrlen(const char* mbstr); +extern int pg_mbstrlen_with_len(const char* mbstr, int len); +extern int pg_mbstrlen_with_len_eml(const char* mbstr, int len, int eml); +extern int pg_mbcliplen(const char* mbstr, int len, int limit); +extern int pg_encoding_mbcliplen(int encoding, const char* mbstr, int len, int limit); +extern int pg_mbcharcliplen(const char* mbstr, int len, int imit); +extern int pg_mbcharcliplen_orig(const char* mbstr, int len, int limit); +extern int pg_encoding_max_length(int encoding); +extern int pg_database_encoding_max_length(void); +extern mbcharacter_incrementer pg_database_encoding_character_incrementer(void); + +extern int PrepareClientEncoding(int encoding); +extern int SetClientEncoding(int encoding); +extern void InitializeClientEncoding(void); +extern int pg_get_client_encoding(void); +extern const char* pg_get_client_encoding_name(void); + +extern void SetDatabaseEncoding(int encoding); +extern int GetDatabaseEncoding(void); +extern const char* GetDatabaseEncodingName(void); +extern int GetPlatformEncoding(void); +extern void pg_bind_textdomain_codeset(const char* domainname); + +extern int pg_valid_client_encoding(const char* name); +extern int pg_valid_server_encoding(const char* name); + +extern unsigned char* unicode_to_utf8(pg_wchar c, unsigned char* utf8string); +extern pg_wchar utf8_to_unicode(const unsigned char* c); +extern int pg_utf_mblen(const unsigned char*); +extern unsigned char* pg_do_encoding_conversion(unsigned char* src, int len, int src_encoding, int dest_encoding); + +extern char* pg_client_to_server(const char* s, int len); +extern char* pg_server_to_client(const char* s, int len); +extern char* pg_any_to_server(const char* s, int len, int encoding); +extern char* pg_server_to_any(const char* s, int len, int encoding); +extern bool WillTranscodingBePerformed(int encoding); + +extern unsigned short BIG5toCNS(unsigned short big5, unsigned char* lc); +extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc); + +extern void LocalToUtf(const unsigned char* iso, unsigned char* utf, const pg_local_to_utf* map, + const pg_local_to_utf_combined* cmap, int size1, int size2, int encoding, int len); + +extern void UtfToLocal(const unsigned char* utf, unsigned char* iso, const pg_utf_to_local* map, + const pg_utf_to_local_combined* cmap, int size1, int size2, int encoding, int len); + +extern bool pg_verifymbstr(const char* mbstr, int len, bool noError); +extern bool pg_verify_mbstr(int encoding, const char* mbstr, int len, bool noError); +extern int pg_verify_mbstr_len(int encoding, const char* mbstr, int len, bool noError); + +extern void check_encoding_conversion_args( + int src_encoding, int dest_encoding, int len, int expected_src_encoding, int expected_dest_encoding); + +extern void report_invalid_encoding(int encoding, const char* mbstr, int len); +extern void report_untranslatable_char(int src_encoding, int dest_encoding, const char* mbstr, int len); + +extern void pg_ascii2mic(const unsigned char* l, unsigned char* p, int len); +extern void pg_mic2ascii(const unsigned char* mic, unsigned char* p, int len); +extern void latin2mic(const unsigned char* l, unsigned char* p, int len, int lc, int encoding); +extern void mic2latin(const unsigned char* mic, unsigned char* p, int len, int lc, int encoding); +extern void latin2mic_with_table( + const unsigned char* l, unsigned char* p, int len, int lc, int encoding, const unsigned char* tab); +extern void mic2latin_with_table( + const unsigned char* mic, unsigned char* p, int len, int lc, int encoding, const unsigned char* tab); + +extern bool pg_utf8_islegal(const unsigned char* source, int length); +extern bool pg_gbk_islegal(const unsigned char* source, int length); + +extern char* gs_setlocale_r(int category, const char* locale); +#ifndef WIN32 +extern char* gs_nl_langinfo_r(nl_item item); +#else +extern char* gs_nl_langinfo_r(const char* ctype); +#endif + +#ifdef WIN32 +extern WCHAR* pgwin32_toUTF16(const char* str, int len, int* utf16len); +#endif + +#endif /* PG_WCHAR_H */ diff -uprN postgresql-hll-2.14_old/include/include/miscadmin.h postgresql-hll-2.14/include/include/miscadmin.h --- postgresql-hll-2.14_old/include/include/miscadmin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/miscadmin.h 2020-12-12 17:06:43.228347793 +0800 @@ -0,0 +1,466 @@ +/* ------------------------------------------------------------------------- + * + * miscadmin.h + * This file contains general postgres administration and initialization + * stuff that used to be spread out between the following files: + * globals.h global variables + * pdir.h directory path crud + * pinit.h postgres initialization + * pmod.h processing modes + * Over time, this has also become the preferred place for widely known + * resource-limitation stuff, such as u_sess->attr.attr_memory.work_mem and check_stack_depth(). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/miscadmin.h + * + * NOTES + * some of the information in this file should be moved to other files. + * + * ------------------------------------------------------------------------- + */ +#ifndef MISCADMIN_H +#define MISCADMIN_H + +#ifndef FRONTEND +#include "postgres.h" +#include "knl/knl_variable.h" +#endif +#include "gs_thread.h" +#include "pgtime.h" /* for pg_time_t */ +#include "libpq/libpq-be.h" + +#define PG_BACKEND_VERSIONSTR "gaussdb " DEF_GS_VERSION "\n" + +/***************************************************************************** + * Backend version and inplace upgrade staffs + *****************************************************************************/ + +extern const uint32 GRAND_VERSION_NUM; + +extern const uint32 MATVIEW_VERSION_NUM; +extern const uint32 PARTIALPUSH_VERSION_NUM; +extern const uint32 SUBLINKPULLUP_VERSION_NUM; +extern const uint32 PREDPUSH_VERSION_NUM; +extern const uint32 GTMLITE_VERSION_NUM; +extern const uint32 EXECUTE_DIRECT_ON_MULTI_VERSION_NUM; +extern const uint32 FIX_PBE_CUSTOME_PLAN_BUG_VERSION_NUM; +extern const uint32 FUNCNAME_PUSHDOWN_VERSION_NUM; +extern const uint32 STP_SUPPORT_COMMIT_ROLLBACK; +extern const uint32 SUPPORT_GPI_VERSION_NUM; +extern const uint32 PRIVS_VERSION_NUM; +extern const uint32 ML_OPT_MODEL_VERSION_NUM; + +#define INPLACE_UPGRADE_PRECOMMIT_VERSION 1 + +#define OPT_DISPLAY_LEADING_ZERO 1 +#define OPT_END_MONTH_CALCULATE 2 +#define OPT_COMPAT_ANALYZE_SAMPLE 4 +#define OPT_BIND_SCHEMA_TABLESPACE 8 +#define OPT_RETURN_NS_OR_NULL 16 +#define OPT_BIND_SEARCHPATH 32 +#define OPT_UNBIND_DIVIDE_BOUND 64 +#define OPT_CORRECT_TO_NUMBER 128 +#define OPT_CONCAT_VARIADIC 256 +#define OPT_MEGRE_UPDATE_MULTI 512 +#define OPT_CONVERT_TO_NUMERIC 1024 +#define OPT_MAX 11 + +#define DISPLAY_LEADING_ZERO (u_sess->utils_cxt.behavior_compat_flags & OPT_DISPLAY_LEADING_ZERO) +#define END_MONTH_CALCULATE (u_sess->utils_cxt.behavior_compat_flags & OPT_END_MONTH_CALCULATE) +#define SUPPORT_PRETTY_ANALYZE (!(u_sess->utils_cxt.behavior_compat_flags & OPT_COMPAT_ANALYZE_SAMPLE)) +#define SUPPORT_BIND_TABLESPACE (u_sess->utils_cxt.behavior_compat_flags & OPT_BIND_SCHEMA_TABLESPACE) +#define SUPPORT_BIND_DIVIDE (!(u_sess->utils_cxt.behavior_compat_flags & OPT_UNBIND_DIVIDE_BOUND)) +#define RETURN_NS (u_sess->utils_cxt.behavior_compat_flags & OPT_RETURN_NS_OR_NULL) +#define CORRECT_TO_NUMBER (u_sess->utils_cxt.behavior_compat_flags & OPT_CORRECT_TO_NUMBER) +#define SUPPORT_BIND_SEARCHPATH (u_sess->utils_cxt.behavior_compat_flags & OPT_BIND_SEARCHPATH) +/*CONCAT_VARIADIC controls 1.the variadic type process, and 2. td mode null return process in concat. By default, the + * option is blank and the behavior is new and compatible with current A and C mode, if the option is set, the + * behavior is old and the same as previous GAUSSDB kernel. */ +#define CONCAT_VARIADIC (!(u_sess->utils_cxt.behavior_compat_flags & OPT_CONCAT_VARIADIC)) +#define MEGRE_UPDATE_MULTI (u_sess->utils_cxt.behavior_compat_flags & OPT_MEGRE_UPDATE_MULTI) +#define CONVERT_STRING_DIGIT_TO_NUMERIC (u_sess->utils_cxt.behavior_compat_flags & OPT_CONVERT_TO_NUMERIC) + +/* define database compatibility Attribute */ +typedef struct { + int flag; + char name[256]; +} DB_CompatibilityAttr; +#define DB_CMPT_A 0 +#define DB_CMPT_B 1 +#define DB_CMPT_C 2 + +typedef struct { + char name[32]; +} IntervalStylePack; + +extern DB_CompatibilityAttr g_dbCompatArray[]; +extern IntervalStylePack g_interStyleVal; + +/* in tcop/postgres.c */ +extern void ProcessInterrupts(void); + +#ifndef WIN32 + +#define CHECK_FOR_INTERRUPTS() \ + do { \ + if (InterruptPending) \ + ProcessInterrupts(); \ + } while (0) +#else /* WIN32 */ + +#define CHECK_FOR_INTERRUPTS() \ + do { \ + if (UNBLOCKED_SIGNAL_QUEUE()) \ + pgwin32_dispatch_queued_signals(); \ + if (InterruptPending) \ + ProcessInterrupts(); \ + } while (0) +#endif /* WIN32 */ + +#define HOLD_INTERRUPTS() (t_thrd.int_cxt.InterruptHoldoffCount++) + +#define RESUME_INTERRUPTS() \ + do { \ + Assert(t_thrd.int_cxt.InterruptHoldoffCount > 0); \ + t_thrd.int_cxt.InterruptHoldoffCount--; \ + } while (0) + +#define START_CRIT_SECTION() (t_thrd.int_cxt.CritSectionCount++) + +#define END_CRIT_SECTION() \ + do { \ + Assert(t_thrd.int_cxt.CritSectionCount > 0); \ + t_thrd.int_cxt.CritSectionCount--; \ + } while (0) + +/***************************************************************************** + * globals.h -- * + *****************************************************************************/ +extern bool open_join_children; +extern bool will_shutdown; +extern bool dummyStandbyMode; + +/* + * from utils/init/globals.c + */ +extern THR_LOCAL PGDLLIMPORT volatile bool InterruptPending; + +extern volatile ThreadId PostmasterPid; +extern bool IsPostmasterEnvironment; +extern volatile uint32 WorkingGrandVersionNum; +extern bool InplaceUpgradePrecommit; + +extern THR_LOCAL PGDLLIMPORT bool IsUnderPostmaster; +extern THR_LOCAL PGDLLIMPORT char my_exec_path[]; + +extern int8 ce_cache_refresh_type; + +#define MAX_QUERY_DOP (64) +#define MIN_QUERY_DOP -(MAX_QUERY_DOP) + +extern const uint32 BACKUP_SLOT_VERSION_NUM; + +/* Debug mode. + * 0 - Do not change any thing. + * 1 - For test: Parallel when inExplain. And change the scan limit to MIN_ROWS_L. + * 2 - For llt: Do not parallel when inExplain. And change the scan limit to MIN_ROWS_L. + */ +#define DEFAULT_MODE 0 +#define DEBUG_MODE 1 +#define LLT_MODE 2 + +/* + * Date/Time Configuration + * + * u_sess->time_cxt.DateStyle defines the output formatting choice for date/time types: + * USE_POSTGRES_DATES specifies traditional Postgres format + * USE_ISO_DATES specifies ISO-compliant format + * USE_SQL_DATES specifies A db/Ingres-compliant format + * USE_GERMAN_DATES specifies German-style dd.mm/yyyy + * + */ + +/* valid u_sess->time_cxt.DateStyle values */ +#define USE_POSTGRES_DATES 0 +#define USE_ISO_DATES 1 +#define USE_SQL_DATES 2 +#define USE_GERMAN_DATES 3 +#define USE_XSD_DATES 4 + +/* valid u_sess->time_cxt.DateOrder values */ +#define DATEORDER_YMD 0 +#define DATEORDER_DMY 1 +#define DATEORDER_MDY 2 + +/* + * u_sess->attr.attr_common.IntervalStyles + * INTSTYLE_POSTGRES Like Postgres < 8.4 when u_sess->time_cxt.DateStyle = 'iso' + * INTSTYLE_POSTGRES_VERBOSE Like Postgres < 8.4 when u_sess->time_cxt.DateStyle != 'iso' + * INTSTYLE_SQL_STANDARD SQL standard interval literals + * INTSTYLE_ISO_8601 ISO-8601-basic formatted intervals + */ +#define INTSTYLE_POSTGRES 0 +#define INTSTYLE_POSTGRES_VERBOSE 1 +#define INTSTYLE_SQL_STANDARD 2 +#define INTSTYLE_ISO_8601 3 +#define INTSTYLE_A 4 + +#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */ +#define OPT_MAX_OP_MEM (4 * 1024L * 1024L) /* 4GB, used to restrict operator mem in optimizer */ + +#ifdef PGXC +extern bool useLocalXid; +#endif + +#define DEFUALT_STACK_SIZE 16384 + +/* in tcop/postgres.c */ + +#if defined(__ia64__) || defined(__ia64) +typedef struct { + char* stack_base_ptr; + char* register_stack_base_ptr; +} pg_stack_base_t; +#else +typedef char* pg_stack_base_t; +#endif + +extern pg_stack_base_t set_stack_base(void); +extern void restore_stack_base(pg_stack_base_t base); +extern void check_stack_depth(void); +extern bool stack_is_too_deep(void); + +/* in tcop/utility.c */ +extern void PreventCommandIfReadOnly(const char* cmdname); +extern void PreventCommandDuringRecovery(const char* cmdname); + +extern int trace_recovery(int trace_level); + +/***************************************************************************** + * pdir.h -- * + * POSTGRES directory path definitions. * + *****************************************************************************/ + +/* flags to be OR'd to form sec_context */ +#define SECURITY_LOCAL_USERID_CHANGE 0x0001 +#define SECURITY_RESTRICTED_OPERATION 0x0002 + +/* now in utils/init/miscinit.c */ +extern char* GetUserNameFromId(Oid roleid); +extern char* GetUserNameById(Oid roleid); +extern Oid GetAuthenticatedUserId(void); +extern Oid GetUserId(void); +extern Oid getCurrentNamespace(); +extern Oid GetCurrentUserId(void); +extern Oid GetOuterUserId(void); +extern Oid GetSessionUserId(void); +extern void GetUserIdAndSecContext(Oid* userid, int* sec_context); +extern void SetUserIdAndSecContext(Oid userid, int sec_context); +extern bool InLocalUserIdChange(void); +extern bool InSecurityRestrictedOperation(void); +extern void GetUserIdAndContext(Oid* userid, bool* sec_def_context); +extern void SetUserIdAndContext(Oid userid, bool sec_def_context); +extern void InitializeSessionUserId(const char* rolename); +extern void InitializeSessionUserIdStandalone(void); +extern void SetSessionAuthorization(Oid userid, bool is_superuser); +extern Oid GetCurrentRoleId(void); +extern void SetCurrentRoleId(Oid roleid, bool is_superuser); + +extern Oid get_current_lcgroup_oid(); +extern const char* get_current_lcgroup_name(); +extern bool is_lcgroup_admin(); +extern bool is_logic_cluster(Oid group_id); +extern bool in_logic_cluster(); +extern bool exist_logic_cluster(); +#ifdef ENABLE_MULTIPLE_NODES +extern const char* show_nodegroup_mode(void); +#endif +extern const char* show_lcgroup_name(); +extern Oid get_pgxc_logic_groupoid(Oid roleid); +extern Oid get_pgxc_logic_groupoid(const char* groupname); +extern void Reset_Pseudo_CurrentUserId(void); + +extern void SetDataDir(const char* dir); +extern void ChangeToDataDir(void); +extern char* make_absolute_path(const char* path); + +/* in utils/misc/superuser.c */ +extern bool superuser( + void); /* when privileges separate is used,current user is or superuser or sysdba,if not,current user is superuser*/ +extern bool isRelSuperuser( + void); /*current user is real superuser.if you don't want sysdba to entitle to operate,use it*/ +extern bool initialuser(void); /* current user is initial user. */ +extern bool superuser_arg(Oid roleid); /* given user is superuser */ +extern bool superuser_arg_no_seperation(Oid roleid); /* given user is superuser (no seperation)*/ +extern bool systemDBA_arg(Oid roleid); /* given user is systemdba */ +extern bool isSecurityadmin(Oid roleid); /* given user is security admin */ +extern bool isAuditadmin(Oid roleid); /* given user is audit admin */ +extern bool isMonitoradmin(Oid roleid); /* given user is monitor admin */ +extern bool isOperatoradmin(Oid roleid); /* given user is operator admin */ +extern bool isPolicyadmin(Oid roleid); /* given user is policy admin */ +extern bool CheckExecDirectPrivilege(const char* query); /* check user have privilege to use execute direct */ + +/***************************************************************************** + * pmod.h -- * + * POSTGRES processing mode definitions. * + *****************************************************************************/ + +#define IsBootstrapProcessingMode() (u_sess->misc_cxt.Mode == BootstrapProcessing) +#define IsInitProcessingMode() (u_sess->misc_cxt.Mode == InitProcessing) +#define IsNormalProcessingMode() (u_sess->misc_cxt.Mode == NormalProcessing) +#define IsPostUpgradeProcessingMode() (u_sess->misc_cxt.Mode == PostUpgradeProcessing) + +#define GetProcessingMode() u_sess->misc_cxt.Mode + +#define SetProcessingMode(mode) \ + do { \ + AssertArg((mode) == BootstrapProcessing || (mode) == InitProcessing || (mode) == NormalProcessing || \ + (mode) == PostUpgradeProcessing); \ + u_sess->misc_cxt.Mode = (mode); \ + } while (0) + + +/* + * Auxiliary-process type identifiers. + */ +typedef enum { + NotAnAuxProcess = -1, + CheckerProcess = 0, + BootstrapProcess, + StartupProcess, + BgWriterProcess, + CheckpointerProcess, + WalWriterProcess, + WalWriterAuxiliaryProcess, + WalReceiverProcess, + WalRcvWriterProcess, + DataReceiverProcess, + DataRcvWriterProcess, + HeartbeatProcess, +#ifdef PGXC + TwoPhaseCleanerProcess, + WLMWorkerProcess, + WLMMonitorWorkerProcess, + WLMArbiterWorkerProcess, + CPMonitorProcess, + FaultMonitorProcess, + CBMWriterProcess, + RemoteServiceProcess, +#endif + AsyncIOCompleterProcess, + TpoolSchdulerProcess, + TsCompactionProcess, + TsCompactionAuxiliaryProcess, + NUM_SINGLE_AUX_PROC, /* Sentry for auxiliary type with single thread. */ + + /* + * If anyone want add a new auxiliary thread type, and will create several + * threads for this type, then you must add it below NUM_SINGLE_AUX_PROC. + * Meanwhile, you must update NUM_MULTI_AUX_PROC and GetAuxProcEntryIndex(). + */ + PageWriterProcess, + MultiBgWriterProcess, + PageRedoProcess, + TpoolListenerProcess, + TsCompactionConsumerProcess, + CsnMinSyncProcess, + + NUM_AUXPROCTYPES /* Must be last! */ +} AuxProcType; + +#define AmBootstrapProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == BootstrapProcess) +#define AmStartupProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == StartupProcess) +#define AmPageRedoProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == PageRedoProcess) +#define AmBackgroundWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == BgWriterProcess) +#define AmMulitBackgroundWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == MultiBgWriterProcess) +#define AmCheckpointerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CheckpointerProcess) +#define AmWalWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalWriterProcess) +#define AmWalWriterAuxiliaryProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalWriterAuxiliaryProcess) +#define AmWalReceiverProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalReceiverProcess) +#define AmWalReceiverWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalRcvWriterProcess) +#define AmDataReceiverProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == DataReceiverProcess) +#define AmDataReceiverWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == DataRcvWriterProcess) +#define AmWLMWorkerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMWorkerProcess) +#define AmWLMMonitorProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMMonitorWorkerProcess) +#define AmWLMArbiterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMArbiterWorkerProcess) +#define AmCPMonitorProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CPMonitorProcess) +#define AmCBMWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CBMWriterProcess) +#define AmRemoteServiceProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == RemoteServiceProcess) +#define AmPageWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == PageWriterProcess) +#define AmHeartbeatProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == HeartbeatProcess) +#define AmTsCompactionProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionProcess) +#define AmTsCompactionConsumerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionConsumerProcess) +#define AmTsCompactionAuxiliaryProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionAuxiliaryProcess) +#define AmPageRedoWorker() (t_thrd.bootstrap_cxt.MyAuxProcType == PageRedoProcess) + + + + +/***************************************************************************** + * pinit.h -- * + * POSTGRES initialization and cleanup definitions. * + *****************************************************************************/ + +/* in utils/init/postinit.c */ +extern void pg_split_opts(char** argv, int* argcp, char* optstr); +extern void PostgresResetUsernamePgoption(const char* username); +extern void BaseInit(void); + +/* + * As of 9.1, the contents of the data-directory lock file are: + * + * line # + * 1 postmaster PID (or negative of a standalone backend's PID) + * 2 data directory path + * 3 postmaster start timestamp (time_t representation) + * 4 port number + * 5 socket directory path (empty on Windows) + * 6 first listen_address (IP address or "*"; empty if no TCP port) + * 7 shared memory key (not present on Windows) + * + * Lines 6 and up are added via AddToDataDirLockFile() after initial file + * creation; they have to be ordered according to time of addition. + * + * The socket lock file, if used, has the same contents as lines 1-5. + */ +#define LOCK_FILE_LINE_PID 1 +#define LOCK_FILE_LINE_DATA_DIR 2 +#define LOCK_FILE_LINE_START_TIME 3 +#define LOCK_FILE_LINE_PORT 4 +#define LOCK_FILE_LINE_SOCKET_DIR 5 +#define LOCK_FILE_LINE_LISTEN_ADDR 6 +#define LOCK_FILE_LINE_SHMEM_KEY 7 + +extern void CreateDataDirLockFile(bool amPostmaster); +extern void CreateSocketLockFile(const char* socketfile, bool amPostmaster, bool is_create_psql_sock = true); +extern void TouchSocketLockFile(void); +extern void AddToDataDirLockFile(int target_line, const char* str); +extern void ValidatePgVersion(const char* path); +extern void process_shared_preload_libraries(void); +extern void process_local_preload_libraries(void); +extern void pg_bindtextdomain(const char* domain); +extern bool has_rolreplication(Oid roleid); +extern bool has_rolvcadmin(Oid roleid); + +/* in access/transam/xlog.c */ +extern bool BackupInProgress(void); +extern void CancelBackup(void); + +extern void EarlyBindingTLSVariables(void); + +/* + * converts the 64 bits unsigned integer between host byte order and network byte order. + * Note that the network byte order is BIG ENDIAN. + */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonl64(x) htobe64(x) +#define ntohl64(x) be64toh(x) +#else +#define htonl64(x) (x) +#define ntohl64(x) (x) +#endif + +#define UPSERT_ROW_STORE_VERSION_NUM 92073 /* Version control for UPSERT */ +#endif /* MISCADMIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/bitmapset.h postgresql-hll-2.14/include/include/nodes/bitmapset.h --- postgresql-hll-2.14_old/include/include/nodes/bitmapset.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/bitmapset.h 2020-12-12 17:06:43.228347793 +0800 @@ -0,0 +1,99 @@ +/* ------------------------------------------------------------------------- + * + * bitmapset.h + * PostgreSQL generic bitmap set package + * + * A bitmap set can represent any set of nonnegative integers, although + * it is mainly intended for sets where the maximum value is not large, + * say at most a few hundred. By convention, a NULL pointer is always + * accepted by all operations to represent the empty set. (But beware + * that this is not the only representation of the empty set. Use + * bms_is_empty() in preference to testing for NULL.) + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/bitmapset.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BITMAPSET_H +#define BITMAPSET_H + +/* + * Data representation + */ + +/* The unit size can be adjusted by changing these three declarations: */ +#define BITS_PER_BITMAPWORD 32 +typedef uint32 bitmapword; /* must be an unsigned type */ +typedef int32 signedbitmapword; /* must be the matching signed type */ + +typedef struct Bitmapset { + int nwords; /* number of words in array */ + bitmapword words[FLEXIBLE_ARRAY_MEMBER]; /* really [nwords] */ +} Bitmapset; + +/* result of bms_subset_compare */ +typedef enum { + BMS_EQUAL, /* sets are equal */ + BMS_SUBSET1, /* first set is a subset of the second */ + BMS_SUBSET2, /* second set is a subset of the first */ + BMS_DIFFERENT /* neither set is a subset of the other */ +} BMS_Comparison; + +/* result of bms_membership */ +typedef enum { + BMS_EMPTY_SET, /* 0 members */ + BMS_SINGLETON, /* 1 member */ + BMS_MULTIPLE /* >1 member */ +} BMS_Membership; + +/* + * function prototypes in nodes/bitmapset.c + */ +extern Bitmapset* bms_copy(const Bitmapset* a); +extern bool bms_equal(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_make_singleton(int x); +extern void bms_free(Bitmapset* a); + +#define bms_free_ext(bms) \ + do { \ + if ((bms) != NULL) { \ + bms_free(bms); \ + bms = NULL; \ + } \ + } while (0) + +extern Bitmapset* bms_union(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_intersect(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_difference(const Bitmapset* a, const Bitmapset* b); +extern bool bms_is_subset(const Bitmapset* a, const Bitmapset* b); +extern BMS_Comparison bms_subset_compare(const Bitmapset* a, const Bitmapset* b); +extern bool bms_is_member(int x, const Bitmapset* a); +extern bool bms_overlap(const Bitmapset* a, const Bitmapset* b); +extern bool bms_nonempty_difference(const Bitmapset* a, const Bitmapset* b); +extern int bms_singleton_member(const Bitmapset* a); +extern int bms_num_members(const Bitmapset* a); + +/* optimized tests when we don't need to know exact membership count: */ +extern BMS_Membership bms_membership(const Bitmapset* a); +extern bool bms_is_empty(const Bitmapset* a); + +/* these routines recycle (modify or free) their non-const inputs: */ +extern Bitmapset* bms_add_member(Bitmapset* a, int x); +extern Bitmapset* bms_del_member(Bitmapset* a, int x); +extern Bitmapset* bms_add_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_int_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_del_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_join(Bitmapset* a, Bitmapset* b); + +/* support for iterating through the integer elements of a set: */ +extern int bms_first_member(Bitmapset* a); +extern int bms_next_member(const Bitmapset* a, int prevbit); + +/* support for hashtables using Bitmapsets as keys: */ +extern uint32 bms_hash_value(const Bitmapset* a); + +#endif /* BITMAPSET_H */ + diff -uprN postgresql-hll-2.14_old/include/include/nodes/execnodes.h postgresql-hll-2.14/include/include/nodes/execnodes.h --- postgresql-hll-2.14_old/include/include/nodes/execnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/execnodes.h 2020-12-12 17:06:43.229347806 +0800 @@ -0,0 +1,2474 @@ +/* ------------------------------------------------------------------------- + * + * execnodes.h + * definitions for executor state nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/execnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECNODES_H +#define EXECNODES_H + +// EB: put genam.h first +#include "access/genam.h" +#include "access/relscan.h" +#include "bulkload/dist_fdw.h" +#include "executor/instrument.h" +#include "nodes/params.h" +#include "nodes/plannodes.h" +#include "storage/pagecompress.h" +#include "utils/bloom_filter.h" +#include "utils/reltrigger.h" +#include "utils/sortsupport.h" +#include "utils/tuplesort.h" +#include "utils/tuplestore.h" +#include "vecexecutor/vectorbatch.h" + +#ifdef ENABLE_MOT +// forward declaration for MOT JitContext +namespace JitExec +{ + struct JitContext; +} +#endif + +/* struct for utility statement mem usage */ +typedef struct UtilityDesc { + double cost; /* cost of utility statement */ + int query_mem[2]; /* max and min mem of utility statement */ + int min_mem; /* operator min mem from cost estimation */ + int assigned_mem; /* statement mem assigned by workload manager */ +} UtilityDesc; + +/* ---------------- + * IndexInfo information + * + * this struct holds the information needed to construct new index + * entries for a particular index. Used for both index_build and + * retail creation of index entries. + * + * NumIndexAttrs total number of columns in this index + * NumIndexKeyAttrs number of key columns in index + * KeyAttrNumbers underlying-rel attribute numbers used as keys + * (zeroes indicate expressions). It also contains + * info about included columns. + * Expressions expr trees for expression entries, or NIL if none + * ExpressionsState exec state for expressions, or NIL if none + * Predicate partial-index predicate, or NIL if none + * PredicateState exec state for predicate, or NIL if none + * ExclusionOps Per-column exclusion operators, or NULL if none + * ExclusionProcs Underlying function OIDs for ExclusionOps + * ExclusionStrats Opclass strategy numbers for ExclusionOps + * UniqueOps Theses are like Exclusion*, but for unique indexes + * UniqueProcs + * UniqueStrats + * Unique is it a unique index? + * ReadyForInserts is it valid for inserts? + * Concurrent are we doing a concurrent index build? + * BrokenHotChain did we detect any broken HOT chains? + * + * ii_Concurrent and ii_BrokenHotChain are used only during index build; + * they're conventionally set to false otherwise. + * ---------------- + */ +typedef struct IndexInfo { + NodeTag type; + int ii_NumIndexAttrs; /* total number of columns in index */ + int ii_NumIndexKeyAttrs; /* number of key columns in index */ + AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS]; + List* ii_Expressions; /* list of Expr */ + List* ii_ExpressionsState; /* list of ExprState */ + List* ii_Predicate; /* list of Expr */ + List* ii_PredicateState; /* list of ExprState */ + Oid* ii_ExclusionOps; /* array with one entry per column */ + Oid* ii_ExclusionProcs; /* array with one entry per column */ + uint16* ii_ExclusionStrats; /* array with one entry per column */ + Oid *ii_UniqueOps; /* array with one entry per column */ + Oid *ii_UniqueProcs; /* array with one entry per column */ + uint16 *ii_UniqueStrats; /* array with one entry per column */ + bool ii_Unique; + bool ii_ReadyForInserts; + bool ii_Concurrent; + bool ii_BrokenHotChain; + short ii_PgClassAttrId; + UtilityDesc ii_desc; /* meminfo for index create */ +} IndexInfo; + +/* ---------------- + * ExprContext_CB + * + * List of callbacks to be called at ExprContext shutdown. + * ---------------- + */ +typedef void (*ExprContextCallbackFunction)(Datum arg); + +typedef struct ExprContext_CB { + struct ExprContext_CB* next; + ExprContextCallbackFunction function; + Datum arg; +} ExprContext_CB; + +/* ---------------- + * ExprContext + * + * This class holds the "current context" information + * needed to evaluate expressions for doing tuple qualifications + * and tuple projections. For example, if an expression refers + * to an attribute in the current inner tuple then we need to know + * what the current inner tuple is and so we look at the expression + * context. + * + * There are two memory contexts associated with an ExprContext: + * * ecxt_per_query_memory is a query-lifespan context, typically the same + * context the ExprContext node itself is allocated in. This context + * can be used for purposes such as storing function call cache info. + * * ecxt_per_tuple_memory is a short-term context for expression results. + * As the name suggests, it will typically be reset once per tuple, + * before we begin to evaluate expressions for that tuple. Each + * ExprContext normally has its very own per-tuple memory context. + * + * CurrentMemoryContext should be set to ecxt_per_tuple_memory before + * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). + * ---------------- + */ +struct PLpgSQL_execstate; + +typedef struct ExprContext { + NodeTag type; + + /* Tuples that Var nodes in expression may refer to */ + TupleTableSlot* ecxt_scantuple; + TupleTableSlot* ecxt_innertuple; + TupleTableSlot* ecxt_outertuple; + + /* Memory contexts for expression evaluation --- see notes above */ + MemoryContext ecxt_per_query_memory; + MemoryContext ecxt_per_tuple_memory; + + /* Values to substitute for Param nodes in expression */ + ParamExecData* ecxt_param_exec_vals; /* for PARAM_EXEC params */ + ParamListInfo ecxt_param_list_info; /* for other param types */ + + /* + * Values to substitute for Aggref nodes in the expressions of an Agg + * node, or for WindowFunc nodes within a WindowAgg node. + */ + Datum* ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ + bool* ecxt_aggnulls; /* null flags for aggs/windowfuncs */ + + /* Value to substitute for CaseTestExpr nodes in expression */ + Datum caseValue_datum; + bool caseValue_isNull; + + ScalarVector* caseValue_vector; + + /* Value to substitute for CoerceToDomainValue nodes in expression */ + Datum domainValue_datum; + bool domainValue_isNull; + + /* Link to containing EState (NULL if a standalone ExprContext) */ + struct EState* ecxt_estate; + + /* Functions to call back when ExprContext is shut down */ + ExprContext_CB* ecxt_callbacks; + + // vector specific fields + // consider share space with row fields + // + VectorBatch* ecxt_scanbatch; + VectorBatch* ecxt_innerbatch; + VectorBatch* ecxt_outerbatch; + + // Batch to substitute for Aggref nodes in the expression of an VecAgg node + // + VectorBatch* ecxt_aggbatch; + + /* + * mark the real rows for expression cluster, all the results' m_rows generated by + * vec-expression are aligned by econtext->align_rows + */ + int align_rows; + + bool m_fUseSelection; // Shall we use selection vector? + ScalarVector* qual_results; + ScalarVector* boolVector; + bool is_cursor; + Cursor_Data cursor_data; + int dno; + PLpgSQL_execstate* plpgsql_estate; + /* + * For vector set-result function. + */ + bool have_vec_set_fun; + bool* vec_fun_sel; // selection for vector set-result function. + int current_row; +} ExprContext; + +/* + * Set-result status returned by ExecEvalExpr() + */ +typedef enum { + ExprSingleResult, /* expression does not return a set */ + ExprMultipleResult, /* this result is an element of a set */ + ExprEndResult /* there are no more elements in the set */ +} ExprDoneCond; + +/* + * Return modes for functions returning sets. Note values must be chosen + * as separate bits so that a bitmask can be formed to indicate supported + * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are + * auxiliary flags about SFRM_Materialize mode, rather than separate modes. + */ +typedef enum { + SFRM_ValuePerCall = 0x01, /* one value returned per call */ + SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */ + SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */ + SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */ +} SetFunctionReturnMode; + +/* + * When calling a function that might return a set (multiple rows), + * a node of this type is passed as fcinfo->resultinfo to allow + * return status to be passed back. A function returning set should + * raise an error if no such resultinfo is provided. + */ +typedef struct ReturnSetInfo { + NodeTag type; + /* values set by caller: */ + ExprContext* econtext; /* context function is being called in */ + TupleDesc expectedDesc; /* tuple descriptor expected by caller */ + int allowedModes; /* bitmask: return modes caller can handle */ + /* result status from function (but pre-initialized by caller): */ + SetFunctionReturnMode returnMode; /* actual return mode */ + ExprDoneCond isDone; /* status for ValuePerCall mode */ + /* fields filled by function in Materialize return mode: */ + Tuplestorestate* setResult; /* holds the complete returned tuple set */ + TupleDesc setDesc; /* actual descriptor for returned tuples */ +} ReturnSetInfo; + +/* ---------------- + * ProjectionInfo node information + * + * This is all the information needed to perform projections --- + * that is, form new tuples by evaluation of targetlist expressions. + * Nodes which need to do projections create one of these. + * + * ExecProject() evaluates the tlist, forms a tuple, and stores it + * in the given slot. Note that the result will be a "virtual" tuple + * unless ExecMaterializeSlot() is then called to force it to be + * converted to a physical tuple. The slot must have a tupledesc + * that matches the output of the tlist! + * + * The planner very often produces tlists that consist entirely of + * simple Var references (lower levels of a plan tree almost always + * look like that). And top-level tlists are often mostly Vars too. + * We therefore optimize execution of simple-Var tlist entries. + * The pi_targetlist list actually contains only the tlist entries that + * aren't simple Vars, while those that are Vars are processed using the + * varSlotOffsets/varNumbers/varOutputCols arrays. + * + * The lastXXXVar fields are used to optimize fetching of fields from + * input tuples: they let us do a slot_getsomeattrs() call to ensure + * that all needed attributes are extracted in one pass. + * + * targetlist target list for projection (non-Var expressions only) + * exprContext expression context in which to evaluate targetlist + * slot slot to place projection result in + * itemIsDone workspace array for ExecProject + * directMap true if varOutputCols[] is an identity map + * numSimpleVars number of simple Vars found in original tlist + * varSlotOffsets array indicating which slot each simple Var is from + * varNumbers array containing input attr numbers of simple Vars + * varOutputCols array containing output attr numbers of simple Vars + * lastInnerVar highest attnum from inner tuple slot (0 if none) + * lastOuterVar highest attnum from outer tuple slot (0 if none) + * lastScanVar highest attnum from scan tuple slot (0 if none) + * pi_maxOrmin column table optimize, indicate if get this column's max or min. + * ---------------- + */ +typedef bool (*vectarget_func)(ExprContext* econtext, VectorBatch* pBatch); +typedef struct ProjectionInfo { + NodeTag type; + List* pi_targetlist; + ExprContext* pi_exprContext; + TupleTableSlot* pi_slot; + ExprDoneCond* pi_itemIsDone; + bool pi_directMap; + int pi_numSimpleVars; + int* pi_varSlotOffsets; + int* pi_varNumbers; + int* pi_varOutputCols; + int pi_lastInnerVar; + int pi_lastOuterVar; + int pi_lastScanVar; + List* pi_acessedVarNumbers; + List* pi_sysAttrList; + List* pi_lateAceessVarNumbers; + List* pi_maxOrmin; + List* pi_PackTCopyVars; /* VarList to record those columns what we need to move */ + List* pi_PackLateAccessVarNumbers; /*VarList to record those columns what we need to move in late read cstore + scan.*/ + bool pi_const; + VectorBatch* pi_batch; + vectarget_func jitted_vectarget; /* LLVM function pointer to point to the codegened targetlist expr function */ + VectorBatch* pi_setFuncBatch; +} ProjectionInfo; + +/* + * Function pointer which will be used by LLVM assemble. The created IR functions + * will be added to the actual machine code. + */ +typedef ScalarVector* (*vecqual_func)(ExprContext* econtext); + +/* ---------------- + * JunkFilter + * + * This class is used to store information regarding junk attributes. + * A junk attribute is an attribute in a tuple that is needed only for + * storing intermediate information in the executor, and does not belong + * in emitted tuples. For example, when we do an UPDATE query, + * the planner adds a "junk" entry to the targetlist so that the tuples + * returned to ExecutePlan() contain an extra attribute: the ctid of + * the tuple to be updated. This is needed to do the update, but we + * don't want the ctid to be part of the stored new tuple! So, we + * apply a "junk filter" to remove the junk attributes and form the + * real output tuple. The junkfilter code also provides routines to + * extract the values of the junk attribute(s) from the input tuple. + * + * targetList: the original target list (including junk attributes). + * cleanTupType: the tuple descriptor for the "clean" tuple (with + * junk attributes removed). + * cleanMap: A map with the correspondence between the non-junk + * attribute numbers of the "original" tuple and the + * attribute numbers of the "clean" tuple. + * resultSlot: tuple slot used to hold cleaned tuple. + * junkAttNo: not used by junkfilter code. Can be used by caller + * to remember the attno of a specific junk attribute + * (nodeModifyTable.c keeps the "ctid" or "wholerow" + * attno here). + * ---------------- + */ +typedef struct JunkFilter { + NodeTag type; + List* jf_targetList; + TupleDesc jf_cleanTupType; + AttrNumber* jf_cleanMap; + TupleTableSlot* jf_resultSlot; + AttrNumber jf_junkAttNo; +#ifdef PGXC + /* + * Similar to jf_junkAttNo that is used for ctid, we also need xc_node_id + * and wholerow junk attribute numbers to be saved here. In XC, we need + * multiple junk attributes at the same time, so just jf_junkAttNo is not + * enough. In PG, jf_junkAttNo is used either for ctid or for wholerow, + * it does not need both of them at the same time; ctid is used for physical + * relations while wholerow is used for views. + */ + AttrNumber jf_xc_node_id; + AttrNumber jf_xc_wholerow; + AttrNumber jf_xc_part_id; + AttrNumber jf_xc_bucket_id; + List* jf_primary_keys; +#endif +} JunkFilter; + +typedef struct MergeState { + /* List of MERGE MATCHED action states */ + List* matchedActionStates; + /* List of MERGE NOT MATCHED action states */ + List* notMatchedActionStates; +} MergeState; + +/* ---------------- + * ResultRelInfo information + * + * Whenever we update an existing relation, we have to + * update indices on the relation, and perhaps also fire triggers. + * The ResultRelInfo class is used to hold all the information needed + * about a result relation, including indices.. -cim 10/15/89 + * + * RangeTableIndex result relation's range table index + * RelationDesc relation descriptor for result relation + * NumIndices # of indices existing on result relation + * ri_ContainGPI indices whether contain global parition index + * IndexRelationDescs array of relation descriptors for indices + * IndexRelationInfo array of key/attr info for indices + * TrigDesc triggers to be fired, if any + * TrigFunctions cached lookup info for trigger functions + * TrigWhenExprs array of trigger WHEN expr states + * TrigInstrument optional runtime measurements for triggers + * FdwRoutine FDW callback functions, if foreign table + * FdwState available to save private state of FDW + * ConstraintExprs array of constraint-checking expr states + * junkFilter for removing junk attributes from tuples + * projectReturning for computing a RETURNING list + * updateProj for computing a UPSERT update list + * ---------------- + */ +typedef struct ResultRelInfo { + NodeTag type; + Index ri_RangeTableIndex; + Relation ri_RelationDesc; + int ri_NumIndices; + bool ri_ContainGPI; + RelationPtr ri_IndexRelationDescs; + IndexInfo** ri_IndexRelationInfo; + TriggerDesc* ri_TrigDesc; + FmgrInfo* ri_TrigFunctions; + List** ri_TrigWhenExprs; + Instrumentation* ri_TrigInstrument; + struct FdwRoutine* ri_FdwRoutine; + void* ri_FdwState; + List** ri_ConstraintExprs; + JunkFilter* ri_junkFilter; + AttrNumber ri_partOidAttNum; + AttrNumber ri_bucketIdAttNum; + ProjectionInfo* ri_projectReturning; + + /* for running MERGE on this result relation */ + MergeState* ri_mergeState; + + /* + * While executing MERGE, the target relation is processed twice; once + * as a target relation and once to run a join between the target and the + * source. We generate two different RTEs for these two purposes, one with + * rte->inh set to false and other with rte->inh set to true. + * + * Since the plan re-evaluated by EvalPlanQual uses the join RTE, we must + * install the updated tuple in the scan corresponding to that RTE. The + * following member tracks the index of the second RTE for EvalPlanQual + * purposes. ri_mergeTargetRTI is non-zero only when MERGE is in-progress. + * We use ri_mergeTargetRTI to run EvalPlanQual for MERGE and + * ri_RangeTableIndex elsewhere. + */ + Index ri_mergeTargetRTI; + ProjectionInfo* ri_updateProj; +} ResultRelInfo; + +/* bloom filter controller */ +typedef struct BloomFilterControl { + filter::BloomFilter** bfarray; /* bloom filter array. */ + int array_size; /* bloom filter array size. */ +} BloomFilterControl; + +#define InvalidBktId (-1) /* invalid hash-bucket id */ + +/* ---------------- + * EState information + * + * Master working state for an Executor invocation + * ---------------- + */ +typedef struct EState { + NodeTag type; + + /* Basic state for all query types: */ + ScanDirection es_direction; /* current scan direction */ + Snapshot es_snapshot; /* time qual to use */ + Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ + List* es_range_table; /* List of RangeTblEntry */ + PlannedStmt* es_plannedstmt; /* link to top of plan tree */ + + JunkFilter* es_junkFilter; /* top-level junk filter, if any */ + + /* If query can insert/delete tuples, the command ID to mark them with */ + CommandId es_output_cid; + + /* Info about target table(s) for insert/update/delete queries: */ + ResultRelInfo* es_result_relations; /* array of ResultRelInfos */ + int es_num_result_relations; /* length of array */ + ResultRelInfo* es_result_relation_info; /* currently active array elt */ + + Relation esCurrentPartition; + HTAB* esfRelations; /* do the update,delete , cache the Relation which get from partitionGetRelation */ +#ifdef PGXC + struct PlanState* es_result_remoterel; /* currently active remote rel */ + struct PlanState* es_result_insert_remoterel; /* currently active remote rel */ + struct PlanState* es_result_update_remoterel; /* currently active remote rel */ + struct PlanState* es_result_delete_remoterel; /* currently active remote rel */ +#endif + + /* Stuff used for firing triggers: */ + List* es_trig_target_relations; /* trigger-only ResultRelInfos */ + TupleTableSlot* es_trig_tuple_slot; /* for trigger output tuples */ + TupleTableSlot* es_trig_oldtup_slot; /* for TriggerEnabled */ + TupleTableSlot* es_trig_newtup_slot; /* for TriggerEnabled */ + + /* Parameter info: */ + ParamListInfo es_param_list_info; /* values of external params */ + ParamExecData* es_param_exec_vals; /* values of internal params */ + + /* Other working state: */ + MemoryContext es_query_cxt; /* per-query context in which EState lives */ + MemoryContext es_const_query_cxt; /* const per-query context used to create node context */ + + List* es_tupleTable; /* List of TupleTableSlots */ + + List* es_rowMarks; /* List of ExecRowMarks */ + + uint64 es_processed; /* # of tuples processed */ + + uint64 es_last_processed; /* last value of es_processed for ModifyTable plan*/ + + Oid es_lastoid; /* last oid processed (by INSERT) */ + + int es_top_eflags; /* eflags passed to ExecutorStart */ + int es_instrument; /* OR of InstrumentOption flags */ + bool es_finished; /* true when ExecutorFinish is done */ + + List* es_exprcontexts; /* List of ExprContexts within EState */ + + List* es_subplanstates; /* List of PlanState for SubPlans */ + + List* es_auxmodifytables; /* List of secondary ModifyTableStates */ + + List* es_remotequerystates; /* List of RemoteQueryStates */ + + /* + * this ExprContext is for per-output-tuple operations, such as constraint + * checks and index-value computations. It will be reset for each output + * tuple. Note that it will be created only if needed. + */ + ExprContext* es_per_tuple_exprcontext; + + /* + * These fields are for re-evaluating plan quals when an updated tuple is + * substituted in READ COMMITTED mode. es_epqTuple[] contains tuples that + * scan plan nodes should return instead of whatever they'd normally + * return, or NULL if nothing to return; es_epqTupleSet[] is true if a + * particular array entry is valid; and es_epqScanDone[] is state to + * remember if the tuple has been returned already. Arrays are of size + * list_length(es_range_table) and are indexed by scan node scanrelid - 1. + */ + HeapTuple* es_epqTuple; /* array of EPQ substitute tuples */ + bool* es_epqTupleSet; /* true if EPQ tuple is provided */ + bool* es_epqScanDone; /* true if EPQ tuple has been fetched */ + + List* es_subplan_ids; + bool es_skip_early_free; /* true if we don't apply early free mechanisim, especially for subplan */ + /* true if we don't apply early-free-consumer mechanisim, especially for subplan */ + bool es_skip_early_deinit_consumer; + bool es_under_subplan; /* true if operator is under a subplan */ + List* es_material_of_subplan; /* List of Materialize operator of subplan */ + bool es_recursive_next_iteration; /* true if under recursive-stream and need to rescan. */ + + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + */ + Index dataDestRelIndex; + + BloomFilterControl es_bloom_filter; /* bloom filter controller */ + + bool es_can_realtime_statistics; /* true if can realime statistics */ + bool es_can_history_statistics; /* true if can history statistics */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ +#ifdef ENABLE_MOT + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif +} EState; + +/* + * ExecRowMark - + * runtime representation of FOR UPDATE/SHARE clauses + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we should have an + * ExecRowMark for each non-target relation in the query (except inheritance + * parent RTEs, which can be ignored at runtime). See PlanRowMark for details + * about most of the fields. In addition to fields directly derived from + * PlanRowMark, we store curCtid, which is used by the WHERE CURRENT OF code. + * + * EState->es_rowMarks is a list of these structs. + */ +typedef struct ExecRowMark { + Relation relation; /* opened and suitably locked relation */ + Index rti; /* its range table index */ + Index prti; /* parent range table index, if child */ + Index rowmarkId; /* unique identifier for resjunk columns */ + RowMarkType markType; /* see enum in nodes/plannodes.h */ + bool noWait; /* NOWAIT option */ + ItemPointerData curCtid; /* ctid of currently locked tuple, if any */ + int numAttrs; /* number of attributes in subplan */ +} ExecRowMark; + +/* + * ExecAuxRowMark - + * additional runtime representation of FOR UPDATE/SHARE clauses + * + * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to + * deal with. In addition to a pointer to the related entry in es_rowMarks, + * this struct carries the column number(s) of the resjunk columns associated + * with the rowmark (see comments for PlanRowMark for more detail). In the + * case of ModifyTable, there has to be a separate ExecAuxRowMark list for + * each child plan, because the resjunk columns could be at different physical + * column positions in different subplans. + */ +typedef struct ExecAuxRowMark { + ExecRowMark* rowmark; /* related entry in es_rowMarks */ + AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */ + AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */ + AttrNumber tbidAttNo; /* resno of bucketid junk attribute, if any */ + AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */ +} ExecAuxRowMark; + +/* ---------------------------------------------------------------- + * Tuple Hash Tables + * + * All-in-memory tuple hash tables are used for a number of purposes. + * + * Note: tab_hash_funcs are for the key datatype(s) stored in the table, + * and tab_eq_funcs are non-cross-type equality operators for those types. + * Normally these are the only functions used, but FindTupleHashEntry() + * supports searching a hashtable using cross-data-type hashing. For that, + * the caller must supply hash functions for the LHS datatype as well as + * the cross-type equality operators to use. in_hash_funcs and cur_eq_funcs + * are set to point to the caller's function arrays while doing such a search. + * During LookupTupleHashEntry(), they point to tab_hash_funcs and + * tab_eq_funcs respectively. + * ---------------------------------------------------------------- + */ +typedef struct TupleHashEntryData* TupleHashEntry; +typedef struct TupleHashTableData* TupleHashTable; + +typedef struct TupleHashEntryData { + /* firstTuple must be the first field in this struct! */ + MinimalTuple firstTuple; /* copy of first tuple in this group */ + /* there may be additional data beyond the end of this struct */ +} TupleHashEntryData; /* VARIABLE LENGTH STRUCT */ + +typedef struct TupleHashTableData { + HTAB* hashtab; /* underlying dynahash table */ + int numCols; /* number of columns in lookup key */ + AttrNumber* keyColIdx; /* attr numbers of key columns */ + FmgrInfo* tab_hash_funcs; /* hash functions for table datatype(s) */ + FmgrInfo* tab_eq_funcs; /* equality functions for table datatype(s) */ + MemoryContext tablecxt; /* memory context containing table */ + MemoryContext tempcxt; /* context for function evaluations */ + Size entrysize; /* actual size to make each hash entry */ + TupleTableSlot* tableslot; /* slot for referencing table entries */ + /* The following fields are set transiently for each table search: */ + TupleTableSlot* inputslot; /* current input tuple's slot */ + FmgrInfo* in_hash_funcs; /* hash functions for input datatype(s) */ + FmgrInfo* cur_eq_funcs; /* equality functions for input vs. table */ + int64 width; /* records total width in memory */ + bool add_width; /* if width should be added */ + bool causedBySysRes; /* the batch increase caused by system resources limit? */ +} TupleHashTableData; + +typedef HASH_SEQ_STATUS TupleHashIterator; + +/* + * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan. + * Use ResetTupleHashIterator if the table can be frozen (in this case no + * explicit scan termination is needed). + */ +#define InitTupleHashIterator(htable, iter) hash_seq_init(iter, (htable)->hashtab) +#define TermTupleHashIterator(iter) hash_seq_term(iter) +#define ResetTupleHashIterator(htable, iter) \ + do { \ + hash_freeze((htable)->hashtab); \ + hash_seq_init(iter, (htable)->hashtab); \ + } while (0) +#define ScanTupleHashTable(iter) ((TupleHashEntry)hash_seq_search(iter)) + +/* ---------------------------------------------------------------- + * Expression State Trees + * + * Each executable expression tree has a parallel ExprState tree. + * + * Unlike PlanState, there is not an exact one-for-one correspondence between + * ExprState node types and Expr node types. Many Expr node types have no + * need for node-type-specific run-time state, and so they can use plain + * ExprState or GenericExprState as their associated ExprState node type. + * ---------------------------------------------------------------- + */ + +/* ---------------- + * ExprState node + * + * ExprState is the common superclass for all ExprState-type nodes. + * + * It can also be instantiated directly for leaf Expr nodes that need no + * local run-time state (such as Var, Const, or Param). + * + * To save on dispatch overhead, each ExprState node contains a function + * pointer to the routine to execute to evaluate the node. + * ---------------- + */ +typedef struct ExprState ExprState; + +typedef Datum (*ExprStateEvalFunc)(ExprState* expression, ExprContext* econtext, bool* isNull, ExprDoneCond* isDone); +typedef ScalarVector* (*VectorExprFun)( + ExprState* expression, ExprContext* econtext, bool* selVector, ScalarVector* inputVector, ExprDoneCond* isDone); + +typedef void* (*exprFakeCodeGenSig)(void*); +struct ExprState { + NodeTag type; + Expr* expr; /* associated Expr node */ + ExprStateEvalFunc evalfunc; /* routine to run to execute node */ + + // vectorized evaluator + // + VectorExprFun vecExprFun; + + exprFakeCodeGenSig exprCodeGen; /* routine to run llvm assembler function */ + + ScalarVector tmpVector; + + Oid resultType; +}; + +/* ---------------- + * GenericExprState node + * + * This is used for Expr node types that need no local run-time state, + * but have one child Expr node. + * ---------------- + */ +typedef struct GenericExprState { + ExprState xprstate; + ExprState* arg; /* state of my child node */ +} GenericExprState; + +/* ---------------- + * WholeRowVarExprState node + * ---------------- + */ +typedef struct WholeRowVarExprState { + ExprState xprstate; + struct PlanState* parent; /* parent PlanState, or NULL if none */ + JunkFilter* wrv_junkFilter; /* JunkFilter to remove resjunk cols */ +} WholeRowVarExprState; + +/* ---------------- + * AggrefExprState node + * ---------------- + */ +typedef struct AggrefExprState { + ExprState xprstate; + List* aggdirectargs; /* states of direct-argument expressions */ + List* args; /* states of argument expressions */ + ExprState* aggfilter; /* state of FILTER expression, if any */ + int aggno; /* ID number for agg within its plan node */ + + // Vectorized aggregation fields + // + int m_htbOffset; // offset in the hash table +} AggrefExprState; + +/* ---------------- + * WindowFuncExprState node + * ---------------- + */ +typedef struct WindowFuncExprState { + ExprState xprstate; + List* args; /* states of argument expressions */ + int wfuncno; /* ID number for wfunc within its plan node */ + + // Vectorized aggregation fields + // + ScalarVector* m_resultVector; +} WindowFuncExprState; + +/* ---------------- + * ArrayRefExprState node + * + * Note: array types can be fixed-length (typlen > 0), but only when the + * element type is itself fixed-length. Otherwise they are varlena structures + * and have typlen = -1. In any case, an array type is never pass-by-value. + * ---------------- + */ +typedef struct ArrayRefExprState { + ExprState xprstate; + List* refupperindexpr; /* states for child nodes */ + List* reflowerindexpr; + ExprState* refexpr; + ExprState* refassgnexpr; + int16 refattrlength; /* typlen of array type */ + int16 refelemlength; /* typlen of the array element type */ + bool refelembyval; /* is the element type pass-by-value? */ + char refelemalign; /* typalign of the element type */ +} ArrayRefExprState; + +/* ---------------- + * FuncExprState node + * + * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr, + * and NullIf nodes; be careful to check what xprstate.expr is actually + * pointing at! + * ---------------- + */ +typedef struct FuncExprState { + ExprState xprstate; + List* args; /* states of argument expressions */ + + /* + * Function manager's lookup info for the target function. If func.fn_oid + * is InvalidOid, we haven't initialized it yet (nor any of the following + * fields). + */ + FmgrInfo func; + + /* + * For a set-returning function (SRF) that returns a tuplestore, we keep + * the tuplestore here and dole out the result rows one at a time. The + * slot holds the row currently being returned. + */ + Tuplestorestate* funcResultStore; + TupleTableSlot* funcResultSlot; + + /* + * In some cases we need to compute a tuple descriptor for the function's + * output. If so, it's stored here. + */ + TupleDesc funcResultDesc; + bool funcReturnsTuple; /* valid when funcResultDesc isn't + * NULL */ + + /* + * setArgsValid is true when we are evaluating a set-returning function + * that uses value-per-call mode and we are in the middle of a call + * series; we want to pass the same argument values to the function again + * (and again, until it returns ExprEndResult). This indicates that + * fcinfo_data already contains valid argument data. + */ + bool setArgsValid; + + /* + * Flag to remember whether we found a set-valued argument to the + * function. This causes the function result to be a set as well. Valid + * only when setArgsValid is true or funcResultStore isn't NULL. + */ + bool setHasSetArg; /* some argument returns a set */ + + /* + * Flag to remember whether we have registered a shutdown callback for + * this FuncExprState. We do so only if funcResultStore or setArgsValid + * has been set at least once (since all the callback is for is to release + * the tuplestore or clear setArgsValid). + */ + bool shutdown_reg; /* a shutdown callback is registered */ + + /* + * Call parameter structure for the function. This has been initialized + * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves + * argument values between calls, when setArgsValid is true. + */ + FunctionCallInfoData fcinfo_data; + + ScalarVector* tmpVec; +} FuncExprState; + +/* ---------------- + * ScalarArrayOpExprState node + * + * This is a FuncExprState plus some additional data. + * ---------------- + */ +typedef struct ScalarArrayOpExprState { + FuncExprState fxprstate; + /* Cached info about array element type */ + Oid element_type; + int16 typlen; + bool typbyval; + char typalign; + bool* pSel; /* selection used to fast path of ALL/ANY */ + ScalarVector *tmpVecLeft; + ScalarVector *tmpVecRight; + ScalarVector* tmpVec; +} ScalarArrayOpExprState; + +/* ---------------- + * BoolExprState node + * ---------------- + */ +typedef struct BoolExprState { + ExprState xprstate; + List* args; /* states of argument expression(s) */ + + bool tmpSelection[BatchMaxSize]; // temp selection +} BoolExprState; + +/* ---------------- + * SubPlanState node + * ---------------- + */ +typedef struct SubPlanState { + ExprState xprstate; + struct PlanState* planstate; /* subselect plan's state tree */ + ExprState* testexpr; /* state of combining expression */ + List* args; /* states of argument expression(s) */ + ExprState* row_testexpr; /* for vector hash subplan */ + HeapTuple curTuple; /* copy of most recent tuple from subplan */ + Datum curArray; /* most recent array from ARRAY() subplan */ + /* these are used when hashing the subselect's output: */ + ProjectionInfo* projLeft; /* for projecting lefthand exprs */ + ProjectionInfo* projRight; /* for projecting subselect output */ + TupleHashTable hashtable; /* hash table for no-nulls subselect rows */ + TupleHashTable hashnulls; /* hash table for rows with null(s) */ + bool havehashrows; /* TRUE if hashtable is not empty */ + bool havenullrows; /* TRUE if hashnulls is not empty */ + MemoryContext hashtablecxt; /* memory context containing hash tables */ + MemoryContext hashtempcxt; /* temp memory context for hash tables */ + ExprContext* innerecontext; /* econtext for computing inner tuples */ + AttrNumber* keyColIdx; /* control data for hash tables */ + FmgrInfo* tab_hash_funcs; /* hash functions for table datatype(s) */ + FmgrInfo* tab_eq_funcs; /* equality functions for table datatype(s) */ + FmgrInfo* lhs_hash_funcs; /* hash functions for lefthand datatype(s) */ + FmgrInfo* cur_eq_funcs; /* equality functions for LHS vs. table */ + + /* for vector engine */ + int idx; /* a index to indicate which parameter to be pushed */ + ScalarVector** pParamVectorArray; /* a array to store the param data */ + ScalarVector** pParamVectorTmp; /* a temporary place to store the para data pointer */ + bool* pSel; /* selection used to fast path */ + VectorBatch* outExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* innerExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* scanExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* aggExprBatch; /* a batch for only one row to store the para data for vector expr */ + ScalarVector* tempvector; /* a temp vector for vector expression */ + MemoryContext ecxt_per_batch_memory; /* memory contexts for one batch */ +} SubPlanState; + +/* ---------------- + * AlternativeSubPlanState node + * ---------------- + */ +typedef struct AlternativeSubPlanState { + ExprState xprstate; + List* subplans; /* states of alternative subplans */ + int active; /* list index of the one we're using */ +} AlternativeSubPlanState; + +/* ---------------- + * FieldSelectState node + * ---------------- + */ +typedef struct FieldSelectState { + ExprState xprstate; + ExprState* arg; /* input expression */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} FieldSelectState; + +/* ---------------- + * FieldStoreState node + * ---------------- + */ +typedef struct FieldStoreState { + ExprState xprstate; + ExprState* arg; /* input tuple value */ + List* newvals; /* new value(s) for field(s) */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} FieldStoreState; + +/* ---------------- + * CoerceViaIOState node + * ---------------- + */ +typedef struct CoerceViaIOState { + ExprState xprstate; + ExprState* arg; /* input expression */ + FmgrInfo outfunc; /* lookup info for source output function */ + FmgrInfo infunc; /* lookup info for result input function */ + Oid intypioparam; /* argument needed for input function */ +} CoerceViaIOState; + +/* ---------------- + * ArrayCoerceExprState node + * ---------------- + */ +typedef struct ArrayCoerceExprState { + ExprState xprstate; + ExprState* arg; /* input array value */ + Oid resultelemtype; /* element type of result array */ + FmgrInfo elemfunc; /* lookup info for element coercion function */ + /* use struct pointer to avoid including array.h here */ + struct ArrayMapState* amstate; /* workspace for array_map */ +} ArrayCoerceExprState; + +/* ---------------- + * ConvertRowtypeExprState node + * ---------------- + */ +typedef struct ConvertRowtypeExprState { + ExprState xprstate; + ExprState* arg; /* input tuple value */ + TupleDesc indesc; /* tupdesc for source rowtype */ + TupleDesc outdesc; /* tupdesc for result rowtype */ + /* use "struct" so we needn't include tupconvert.h here */ + struct TupleConversionMap* map; + bool initialized; +} ConvertRowtypeExprState; + +/* ---------------- + * CaseExprState node + * ---------------- + */ +typedef struct CaseExprState { + ExprState xprstate; + ExprState* arg; /* implicit equality comparison argument */ + List* args; /* the arguments (list of WHEN clauses) */ + ExprState* defresult; /* the default result (ELSE clause) */ + bool* matchedResult; + bool* localSel; + ScalarVector* save_vector; +} CaseExprState; + +/* ---------------- + * CaseWhenState node + * ---------------- + */ +typedef struct CaseWhenState { + ExprState xprstate; + ExprState* expr; /* condition expression */ + ExprState* result; /* substitution result */ +} CaseWhenState; + +/* ---------------- + * ArrayExprState node + * + * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length + * arrays. + * ---------------- + */ +typedef struct ArrayExprState { + ExprState xprstate; + List* elements; /* states for child nodes */ + int16 elemlength; /* typlen of the array element type */ + bool elembyval; /* is the element type pass-by-value? */ + char elemalign; /* typalign of the element type */ +} ArrayExprState; + +/* ---------------- + * RowExprState node + * ---------------- + */ +typedef struct RowExprState { + ExprState xprstate; + List* args; /* the arguments */ + TupleDesc tupdesc; /* descriptor for result tuples */ + VectorBatch* rowBatch; /* Save need columns */ +} RowExprState; + +/* ---------------- + * RowCompareExprState node + * ---------------- + */ +typedef struct RowCompareExprState { + ExprState xprstate; + List* largs; /* the left-hand input arguments */ + List* rargs; /* the right-hand input arguments */ + FmgrInfo* funcs; /* array of comparison function info */ + Oid* collations; /* array of collations to use */ + + FunctionCallInfoData* cinfo; + + ScalarVector* left_argvec; /* the left-hand input vector arguments */ + ScalarVector* right_argvec; /* the right-hand input vector arguments */ + ScalarVector* cmpresult; /* vector for compare result */ + bool* pSel; /* vector for marking arguments to calculation */ +} RowCompareExprState; + +/* ---------------- + * CoalesceExprState node + * ---------------- + */ +typedef struct CoalesceExprState { + ExprState xprstate; + List* args; /* the arguments */ + bool* pSel; /* selection used to fast path */ +} CoalesceExprState; + +/* ---------------- + * MinMaxExprState node + * ---------------- + */ +typedef struct MinMaxExprState { + ExprState xprstate; + List* args; /* the arguments */ + FmgrInfo cfunc; /* lookup info for comparison func */ + FunctionCallInfoData cinfo; + + ScalarVector* argvec; /* eval arg results */ + ScalarVector* cmpresult; + bool* pSel; +} MinMaxExprState; + +/* ---------------- + * XmlExprState node + * ---------------- + */ +typedef struct XmlExprState { + ExprState xprstate; + List* named_args; /* ExprStates for named arguments */ + List* args; /* ExprStates for other arguments */ +} XmlExprState; + +/* ---------------- + * NullTestState node + * ---------------- + */ +typedef struct NullTestState { + ExprState xprstate; + ExprState* arg; /* input expression */ + /* used only if input is of composite type: */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} NullTestState; + +/* ---------------- + * HashFilterState node + * ---------------- + */ +typedef struct HashFilterState { + ExprState xprstate; + List* arg; /* input expression */ + uint2* nodelist; /* Node indices where data is located */ + uint2* bucketMap; +} HashFilterState; + +/* ---------------- + * CoerceToDomainState node + * ---------------- + */ +typedef struct CoerceToDomainState { + ExprState xprstate; + ExprState* arg; /* input expression */ + /* Cached list of constraints that need to be checked */ + List* constraints; /* list of DomainConstraintState nodes */ +} CoerceToDomainState; + +/* + * DomainConstraintState - one item to check during CoerceToDomain + * + * Note: this is just a Node, and not an ExprState, because it has no + * corresponding Expr to link to. Nonetheless it is part of an ExprState + * tree, so we give it a name following the xxxState convention. + */ +typedef enum DomainConstraintType { DOM_CONSTRAINT_NOTNULL, DOM_CONSTRAINT_CHECK } DomainConstraintType; + +typedef struct DomainConstraintState { + NodeTag type; + DomainConstraintType constrainttype; /* constraint type */ + char* name; /* name of constraint (for error msgs) */ + ExprState* check_expr; /* for CHECK, a boolean expression */ +} DomainConstraintState; + +typedef struct HbktScanSlot { + int currSlot; +} HbktScanSlot; + +/* ---------------------------------------------------------------- + * Executor State Trees + * + * An executing query has a PlanState tree paralleling the Plan tree + * that describes the plan. + * ---------------------------------------------------------------- + */ +typedef enum { + PST_None = 0, + PST_Norm = 1, + PST_Scan = 2 +} PlanStubType; + +/* ---------------- + * PlanState node + * + * We never actually instantiate any PlanState nodes; this is just the common + * abstract superclass for all PlanState-type nodes. + * ---------------- + */ +typedef struct PlanState { + NodeTag type; + + Plan* plan; /* associated Plan node */ + + EState* state; /* at execution time, states of individual + * nodes point to one EState for the whole + * top-level plan */ + + Instrumentation* instrument; /* Optional runtime stats for this node */ + + /* + * Common structural data for all Plan types. These links to subsidiary + * state trees parallel links in the associated plan tree (except for the + * subPlan list, which does not exist in the plan tree). + */ + List* targetlist; /* target list to be computed at this node */ + List* qual; /* implicitly-ANDed qual conditions */ + struct PlanState* lefttree; /* input plan tree(s) */ + struct PlanState* righttree; + List* initPlan; /* Init SubPlanState nodes (un-correlated expr subselects) */ + List* subPlan; /* SubPlanState nodes in my expressions */ + + /* + * State for management of parameter-change-driven rescanning + */ + Bitmapset* chgParam; /* set of IDs of changed Params */ + HbktScanSlot hbktScanSlot; + + /* + * Other run-time state needed by most if not all node types. + */ + TupleTableSlot* ps_ResultTupleSlot; /* slot for my result tuples */ + ExprContext* ps_ExprContext; /* node's expression-evaluation context */ + ProjectionInfo* ps_ProjInfo; /* info for doing tuple projection */ + bool ps_TupFromTlist; /* state flag for processing set-valued functions in targetlist */ + + bool vectorized; // is vectorized? + + MemoryContext nodeContext; /* Memory Context for this Node */ + + bool earlyFreed; /* node memory already freed? */ + uint8 stubType; /* node stub execution type, see @PlanStubType */ + vectarget_func jitted_vectarget; /* LLVM IR function pointer to point to the codegened targetlist expr. */ + + /* + * Describe issues found in curernt plan node, mainly used for issue de-duplication + * of data skew and inaccurate e-rows + */ + List* plan_issues; + bool recursive_reset; /* node already reset? */ + bool qual_is_inited; + + int64 ps_rownum; /* store current rownum */ +} PlanState; + +static inline bool planstate_need_stub(PlanState* ps) +{ + return ps->stubType != PST_None; +} + +/* ---------------- + * these are defined to avoid confusion problems with "left" + * and "right" and "inner" and "outer". The convention is that + * the "left" plan is the "outer" plan and the "right" plan is + * the inner plan, but these make the code more readable. + * ---------------- + */ +#define innerPlanState(node) (((PlanState*)(node))->righttree) +#define outerPlanState(node) (((PlanState*)(node))->lefttree) + +/* Macros for inline access to certain instrumentation counters */ +#define InstrCountFiltered1(node, delta) \ + do { \ + if (((PlanState*)(node))->instrument) \ + ((PlanState*)(node))->instrument->nfiltered1 += (delta); \ + } while (0) +#define InstrCountFiltered2(node, delta) \ + do { \ + if (((PlanState*)(node))->instrument) \ + ((PlanState*)(node))->instrument->nfiltered2 += (delta); \ + } while (0) + +/* + * EPQState is state for executing an EvalPlanQual recheck on a candidate + * tuple in ModifyTable or LockRows. The estate and planstate fields are + * NULL if inactive. + */ +typedef struct EPQState { + EState* estate; /* subsidiary EState */ + PlanState* planstate; /* plan state tree ready to be executed */ + TupleTableSlot* origslot; /* original output tuple to be rechecked */ + Plan* plan; /* plan tree to be executed */ + List* arowMarks; /* ExecAuxRowMarks (non-locking only) */ + int epqParam; /* ID of Param to force scan node re-eval */ +} EPQState; + +/* ---------------- + * ResultState information + * ---------------- + */ +typedef struct ResultState { + PlanState ps; /* its first field is NodeTag */ + ExprState* resconstantqual; + bool rs_done; /* are we done? */ + bool rs_checkqual; /* do we need to check the qual? */ +} ResultState; + +/* ---------------- + * MergeActionState information + * ---------------- + */ +typedef struct MergeActionState { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + ExprState* whenqual; /* WHEN AND conditions */ + CmdType commandType; /* INSERT/UPDATE/DELETE/DO NOTHING */ + ProjectionInfo* proj; /* tuple projection info */ + TupleDesc tupDesc; /* tuple descriptor for projection */ + JunkFilter* junkfilter; /* junkfilter for UPDATE */ + VectorBatch* scanBatch; /* scan batch for UPDATE */ +} MergeActionState; + +/* ---------------- + * UpsertState information + * ---------------- + */ +typedef struct UpsertState +{ + NodeTag type; + UpsertAction us_action; /* Flags showing DUPLICATE UPDATE NOTHING or SOMETHING */ + TupleTableSlot *us_existing; /* slot to store existing target tuple in */ + List *us_excludedtlist; /* the excluded pseudo relation's tlist */ + TupleTableSlot *us_updateproj; /* slot to update */ +} UpsertState; + +/* ---------------- + * ModifyTableState information + * ---------------- + */ +typedef struct ModifyTableState { + PlanState ps; /* its first field is NodeTag */ + CmdType operation; /* INSERT, UPDATE, or DELETE */ + bool canSetTag; /* do we set the command tag/es_processed? */ + bool mt_done; /* are we done? */ + PlanState** mt_plans; /* subplans (one per target rel) */ +#ifdef PGXC + PlanState** mt_remoterels; /* per-target remote query node */ + PlanState** mt_insert_remoterels; /* per-target remote query node */ + PlanState** mt_update_remoterels; /* per-target remote query node */ + PlanState** mt_delete_remoterels; /* per-target remote query node */ +#endif + int mt_nplans; /* number of plans in the array */ + int mt_whichplan; /* which one is being executed (0..n-1) */ + ResultRelInfo* resultRelInfo; /* per-subplan target relations */ + List** mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ + EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ + bool fireBSTriggers; /* do we need to fire stmt triggers? */ + Relation delete_delta_rel; /* for online expansion's delete data catchup */ + + // For error table + // + Relation errorRel; + ErrorCacheEntry* cacheEnt; + + TupleTableSlot* mt_scan_slot; + TupleTableSlot* mt_update_constr_slot; /* slot to store target tuple in for checking constraints */ + TupleTableSlot* mt_insert_constr_slot; /* slot to store target tuple in for checking constraints */ + TupleTableSlot* mt_mergeproj; /* MERGE action projection target */ + uint32 mt_merge_subcommands; /* Flags showing which subcommands are present INS/UPD/DEL/DO NOTHING */ + UpsertState* mt_upsert; /* DUPLICATE KEY UPDATE evaluation state */ + instr_time first_tuple_modified; /* record the end time for the first tuple inserted, deleted, or updated */ +} ModifyTableState; + +typedef struct CopyFromManagerData* CopyFromManager; + +typedef struct DistInsertSelectState { + ModifyTableState mt; + int rows; + MemoryContext insert_mcxt; + CopyFromManager mgr; + BulkInsertState bistate; + PageCompress* pcState; +} DistInsertSelectState; + +/* ---------------- + * AppendState information + * + * nplans how many plans are in the array + * whichplan which plan is being executed (0 .. n-1) + * ---------------- + */ +typedef struct AppendState { + PlanState ps; /* its first field is NodeTag */ + PlanState** appendplans; /* array of PlanStates for my inputs */ + int as_nplans; + int as_whichplan; +} AppendState; + +/* ---------------- + * MergeAppendState information + * + * nplans how many plans are in the array + * nkeys number of sort key columns + * sortkeys sort keys in SortSupport representation + * slots current output tuple of each subplan + * heap heap of active tuples (represented as array indexes) + * heap_size number of active heap entries + * initialized true if we have fetched first tuple from each subplan + * last_slot last subplan fetched from (which must be re-called) + * ---------------- + */ +typedef struct MergeAppendState { + PlanState ps; /* its first field is NodeTag */ + PlanState** mergeplans; /* array of PlanStates for my inputs */ + int ms_nplans; + int ms_nkeys; + SortSupport ms_sortkeys; /* array of length ms_nkeys */ + TupleTableSlot** ms_slots; /* array of length ms_nplans */ + int* ms_heap; /* array of length ms_nplans */ + int ms_heap_size; /* current active length of ms_heap[] */ + bool ms_initialized; /* are subplans started? */ + int ms_last_slot; /* last subplan slot we returned from */ +} MergeAppendState; + +/* ---------------- + * RecursiveUnionState information + * + * RecursiveUnionState is used for performing a recursive union. + * + * recursing T when we're done scanning the non-recursive term + * intermediate_empty T if intermediate_table is currently empty + * working_table working table (to be scanned by recursive term) + * intermediate_table current recursive output (next generation of WT) + * ---------------- + */ +struct RecursiveUnionController; +typedef struct RecursiveUnionState { + PlanState ps; /* its first field is NodeTag */ + bool recursing; + bool intermediate_empty; + Tuplestorestate* working_table; + Tuplestorestate* intermediate_table; + int iteration; + /* Remaining fields are unused in UNION ALL case */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + MemoryContext tempContext; /* short-term context for comparisons */ + TupleHashTable hashtable; /* hash table for tuples already seen */ + MemoryContext tableContext; /* memory context containing hash table */ + + /* + * MPP with-recursive support + */ + /* Distributed with-recursive execution controller for current RecursiveUnion operator */ + RecursiveUnionController* rucontroller; + + /* record the number of tuples that produced by current iteration step */ + uint64 step_tuple_produced; + + /* + * The share memory context pointer that is used in distributed recursive CTE + * processing where WorkTable is access via different stream threads, we need + * put it on higher level of memory context to persists the whole query runing + * stage. + */ + MemoryContext shareContext; +} RecursiveUnionState; + +/* ---------------- + * BitmapAndState information + * ---------------- + */ +typedef struct BitmapAndState { + PlanState ps; /* its first field is NodeTag */ + PlanState** bitmapplans; /* array of PlanStates for my inputs */ + int nplans; /* number of input plans */ +} BitmapAndState; + +/* ---------------- + * BitmapOrState information + * ---------------- + */ +typedef struct BitmapOrState { + PlanState ps; /* its first field is NodeTag */ + PlanState** bitmapplans; /* array of PlanStates for my inputs */ + int nplans; /* number of input plans */ +} BitmapOrState; + +/* ---------------------------------------------------------------- + * Run time predicate information + * ---------------------------------------------------------------- + */ +typedef struct RunTimeParamPredicateInfo { + ExprState* paraExecExpr; /* internal executor parameter predicate information. */ + Expr* opExpr; /* the operator expression */ + AttrNumber varNoPos; /* an order number in the hdfsScanPredicateArr. */ + int32 typeMod; /* var typmode. */ + Oid datumType; /* the parameter data type. */ + Oid varTypeOid; /* var type oid. */ + int32 paramPosition; /* the parameter predicate position in *hdfsScanPredicateArr. */ +} RunTimeParamPredicateInfo; + +/* ---------------- + * SampleScanInfo information + * ---------------- + */ +typedef struct SampleScanParams { + List* args; /* expr states for TABLESAMPLE params */ + ExprState* repeatable; /* expr state for REPEATABLE expr */ + TableSampleType sampleType; /* sample scan type.*/ + /* use struct pointer to avoid including tsmapi.h here */ + void* tsm_state; /* tablesample method can keep state here */ +} SampleScanParams; + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * ScanState information + * + * ScanState extends PlanState for node types that represent + * scans of an underlying relation. It can also be used for nodes + * that scan the output of an underlying plan node --- in that case, + * only ScanTupleSlot is actually useful, and it refers to the tuple + * retrieved from the subplan. + * + * currentRelation relation being scanned (NULL if none) + * currentScanDesc current scan descriptor for scan (NULL if none) + * ScanTupleSlot pointer to slot in tuple table holding scan tuple + * ---------------- + */ +struct ScanState; +struct SeqScanAccessor; + +/* + * prototypes from functions in execScan.c + */ +typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node); +typedef bool(*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot); + +typedef struct ScanState { + PlanState ps; /* its first field is NodeTag */ + Relation ss_currentRelation; + TableScanDesc ss_currentScanDesc; + TupleTableSlot* ss_ScanTupleSlot; + bool ss_ReScan; + Relation ss_currentPartition; + bool isPartTbl; + int currentSlot; /* current iteration position */ + ScanDirection partScanDirection; + List* partitions; /* list of Partition */ + LOCKMODE lockMode; + List* runTimeParamPredicates; + bool runTimePredicatesReady; + bool is_scan_end; /* @hdfs Mark whether iterator is over or not, if the scan uses informational constraint. */ + SeqScanAccessor* ss_scanaccessor; /* prefetch related */ + int part_id; + int startPartitionId; /* start partition id for parallel threads. */ + int endPartitionId; /* end partition id for parallel threads. */ + RangeScanInRedis rangeScanInRedis; /* if it is a range scan in redistribution time */ + bool isSampleScan; /* identify is it table sample scan or not. */ + SampleScanParams sampleScanInfo; /* TABLESAMPLE params include type/seed/repeatable. */ + ExecScanAccessMtd ScanNextMtd; +} ScanState; + +/* + * SeqScan uses a bare ScanState as its state node, since it needs + * no additional fields. + */ +typedef ScanState SeqScanState; + +/* + * These structs store information about index quals that don't have simple + * constant right-hand sides. See comments for ExecIndexBuildScanKeys() + * for discussion. + */ +typedef struct { + ScanKey scan_key; /* scankey to put value into */ + ExprState* key_expr; /* expr to evaluate to get value */ + bool key_toastable; /* is expr's result a toastable datatype? */ +} IndexRuntimeKeyInfo; + +typedef struct { + ScanKey scan_key; /* scankey to put value into */ + ExprState* array_expr; /* expr to evaluate to get array value */ + int next_elem; /* next array element to use */ + int num_elems; /* number of elems in current array value */ + Datum* elem_values; /* array of num_elems Datums */ + bool* elem_nulls; /* array of num_elems is-null flags */ +} IndexArrayKeyInfo; + +/* ---------------- + * IndexScanState information + * + * indexqualorig execution state for indexqualorig expressions + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * OrderByKeys Skey structures for index ordering operators + * NumOrderByKeys number of OrderByKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * ---------------- + */ +typedef struct IndexScanState { + ScanState ss; /* its first field is NodeTag */ + List* indexqualorig; + ScanKey iss_ScanKeys; + int iss_NumScanKeys; + ScanKey iss_OrderByKeys; + int iss_NumOrderByKeys; + IndexRuntimeKeyInfo* iss_RuntimeKeys; + int iss_NumRuntimeKeys; + bool iss_RuntimeKeysReady; + ExprContext* iss_RuntimeContext; + Relation iss_RelationDesc; + IndexScanDesc iss_ScanDesc; + List* iss_IndexPartitionList; + LOCKMODE lockMode; + Relation iss_CurrentIndexPartition; + int part_id; +} IndexScanState; + +/* ---------------- + * IndexOnlyScanState information + * + * indexqual execution state for indexqual expressions + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * OrderByKeys Skey structures for index ordering operators + * NumOrderByKeys number of OrderByKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * VMBuffer buffer in use for visibility map testing, if any + * HeapFetches number of tuples we were forced to fetch from heap + * ---------------- + */ +typedef struct IndexOnlyScanState { + ScanState ss; /* its first field is NodeTag */ + List* indexqual; + ScanKey ioss_ScanKeys; + int ioss_NumScanKeys; + ScanKey ioss_OrderByKeys; + int ioss_NumOrderByKeys; + IndexRuntimeKeyInfo* ioss_RuntimeKeys; + int ioss_NumRuntimeKeys; + bool ioss_RuntimeKeysReady; + ExprContext* ioss_RuntimeContext; + Relation ioss_RelationDesc; + IndexScanDesc ioss_ScanDesc; + Buffer ioss_VMBuffer; + long ioss_HeapFetches; + List* ioss_IndexPartitionList; + LOCKMODE lockMode; + Relation ioss_CurrentIndexPartition; + int part_id; +} IndexOnlyScanState; + +/* ---------------- + * BitmapIndexScanState information + * + * result bitmap to return output into, or NULL + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * ArrayKeys info about Skeys that come from ScalarArrayOpExprs + * NumArrayKeys number of ArrayKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * ---------------- + */ +typedef struct BitmapIndexScanState { + ScanState ss; /* its first field is NodeTag */ + TIDBitmap* biss_result; + ScanKey biss_ScanKeys; + int biss_NumScanKeys; + IndexRuntimeKeyInfo* biss_RuntimeKeys; + int biss_NumRuntimeKeys; + IndexArrayKeyInfo* biss_ArrayKeys; + int biss_NumArrayKeys; + bool biss_RuntimeKeysReady; + ExprContext* biss_RuntimeContext; + Relation biss_RelationDesc; + IndexScanDesc biss_ScanDesc; + List* biss_IndexPartitionList; + LOCKMODE lockMode; + Relation biss_CurrentIndexPartition; + int part_id; +} BitmapIndexScanState; + +/* ---------------- + * BitmapHeapScanState information + * + * bitmapqualorig execution state for bitmapqualorig expressions + * tbm bitmap obtained from child index scan(s) + * tbmiterator iterator for scanning current pages + * tbmres current-page data + * prefetch_iterator iterator for prefetching ahead of current page + * prefetch_pages # pages prefetch iterator is ahead of current + * prefetch_target target prefetch distance + * ---------------- + */ +typedef struct BitmapHeapScanState { + ScanState ss; /* its first field is NodeTag */ + List* bitmapqualorig; + TIDBitmap* tbm; + TBMIterator* tbmiterator; + TBMIterateResult* tbmres; + TBMIterator* prefetch_iterator; + int prefetch_pages; + int prefetch_target; + GPIScanDesc gpi_scan; /* global partition index scan use information */ + int part_id; +} BitmapHeapScanState; + +/* ---------------- + * TidScanState information + * + * isCurrentOf scan has a CurrentOfExpr qual + * NumTids number of tids in this scan + * TidPtr index of currently fetched tid + * TidList evaluated item pointers (array of size NumTids) + * ---------------- + */ +typedef struct TidScanState { + ScanState ss; /* its first field is NodeTag */ + List* tss_tidquals; /* list of ExprState nodes */ + bool tss_isCurrentOf; + Relation tss_CurrentOf_CurrentPartition; + int tss_NumTids; + int tss_TidPtr; + int tss_MarkTidPtr; + ItemPointerData* tss_TidList; + HeapTupleData tss_htup; + /* put decompressed tuple data into tss_ctbuf_hdr be careful , when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr */ + HeapTupleHeaderData tss_ctbuf_hdr; +} TidScanState; + +#define SizeofTidScanState (offsetof(TidScanState, tss_ctbuf_hdr) + SizeofHeapTupleHeader) + +/* ---------------- + * SubqueryScanState information + * + * SubqueryScanState is used for scanning a sub-query in the range table. + * ScanTupleSlot references the current output tuple of the sub-query. + * ---------------- + */ +typedef struct SubqueryScanState { + ScanState ss; /* its first field is NodeTag */ + PlanState* subplan; +} SubqueryScanState; + +/* ---------------- + * FunctionScanState information + * + * Function nodes are used to scan the results of a + * function appearing in FROM (typically a function returning set). + * + * eflags node's capability flags + * tupdesc expected return tuple description + * tuplestorestate private state of tuplestore.c + * funcexpr state for function expression being evaluated + * ---------------- + */ +typedef struct FunctionScanState { + ScanState ss; /* Its first field is NodeTag */ + int eflags; + TupleDesc tupdesc; + Tuplestorestate* tuplestorestate; + ExprState* funcexpr; + bool atomic; /* Atomic execution context, does not allow transactions */ +} FunctionScanState; + +/* ---------------- + * ValuesScanState information + * + * ValuesScan nodes are used to scan the results of a VALUES list + * + * rowcontext per-expression-list context + * exprlists array of expression lists being evaluated + * array_len size of array + * curr_idx current array index (0-based) + * marked_idx marked position (for mark/restore) + * + * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection + * expressions attached to the node. We create a second ExprContext, + * rowcontext, in which to build the executor expression state for each + * Values sublist. Resetting this context lets us get rid of expression + * state for each row, avoiding major memory leakage over a long values list. + * ---------------- + */ +typedef struct ValuesScanState { + ScanState ss; /* its first field is NodeTag */ + ExprContext* rowcontext; + List** exprlists; + int array_len; + int curr_idx; + int marked_idx; +} ValuesScanState; + +/* ---------------- + * CteScanState information + * + * CteScan nodes are used to scan a CommonTableExpr query. + * + * Multiple CteScan nodes can read out from the same CTE query. We use + * a tuplestore to hold rows that have been read from the CTE query but + * not yet consumed by all readers. + * ---------------- + */ +typedef struct CteScanState { + ScanState ss; /* its first field is NodeTag */ + int eflags; /* capability flags to pass to tuplestore */ + int readptr; /* index of my tuplestore read pointer */ + PlanState* cteplanstate; /* PlanState for the CTE query itself */ + /* Link to the "leader" CteScanState (possibly this same node) */ + struct CteScanState* leader; + /* The remaining fields are only valid in the "leader" CteScanState */ + Tuplestorestate* cte_table; /* rows already read from the CTE query */ + bool eof_cte; /* reached end of CTE query? */ +} CteScanState; + +/* ---------------- + * WorkTableScanState information + * + * WorkTableScan nodes are used to scan the work table created by + * a RecursiveUnion node. We locate the RecursiveUnion node + * during executor startup. + * ---------------- + */ +typedef struct WorkTableScanState { + ScanState ss; /* its first field is NodeTag */ + RecursiveUnionState* rustate; +} WorkTableScanState; + +/* ---------------- + * ForeignScanState information + * + * ForeignScan nodes are used to scan foreign-data tables. + * ---------------- + */ +typedef struct ForeignScanState { + ScanState ss; /* its first field is NodeTag */ + /* use struct pointer to avoid including fdwapi.h here */ + struct FdwRoutine* fdwroutine; + void* fdw_state; /* foreign-data wrapper can keep state here */ + + MemoryContext scanMcxt; + + ForeignOptions* options; +} ForeignScanState; + +/* ---------------- + * ExtensiblePlanState information + * + * ExtensiblePlan nodes are used to execute extensible code within executor. + * + * Core code must avoid assuming that the ExtensiblePlanState is only as large as + * the structure declared here; providers are allowed to make it the first + * element in a larger structure, and typically would need to do so. The + * struct is actually allocated by the CreateExtensiblePlanState method associated + * with the plan node. Any additional fields can be initialized there, or in + * the BeginExtensiblePlan method. + * ---------------- + */ +struct ExplainState; /* avoid including explain.h here */ +struct ExtensiblePlanState; + +typedef struct ExtensibleExecMethods { + const char* ExtensibleName; + + /* Executor methods: mark/restore are optional, the rest are required */ + void (*BeginExtensiblePlan)(struct ExtensiblePlanState* node, EState* estate, int eflags); + TupleTableSlot* (*ExecExtensiblePlan)(struct ExtensiblePlanState* node); + void (*EndExtensiblePlan)(struct ExtensiblePlanState* node); + void (*ReScanExtensiblePlan)(struct ExtensiblePlanState* node); + void (*ExplainExtensiblePlan)(struct ExtensiblePlanState* node, List* ancestors, struct ExplainState* es); +} ExtensibleExecMethods; + +typedef struct ExtensiblePlanState { + ScanState ss; + uint32 flags; /* mask of EXTENSIBLEPATH_* flags, see relation.h */ + List* extensible_ps; /* list of child PlanState nodes, if any */ + const ExtensibleExecMethods* methods; +} ExtensiblePlanState; + +/* ---------------------------------------------------------------- + * Join State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * JoinState information + * + * Superclass for state nodes of join plans. + * ---------------- + */ +typedef struct JoinState { + PlanState ps; + JoinType jointype; + List* joinqual; /* JOIN quals (in addition to ps.qual) */ + List* nulleqqual; +} JoinState; + +/* ---------------- + * NestLoopState information + * + * NeedNewOuter true if need new outer tuple on next call + * MatchedOuter true if found a join match for current outer tuple + * NullInnerTupleSlot prepared null tuple for left outer joins + * ---------------- + */ +typedef struct NestLoopState { + JoinState js; /* its first field is NodeTag */ + bool nl_NeedNewOuter; + bool nl_MatchedOuter; + bool nl_MaterialAll; + TupleTableSlot* nl_NullInnerTupleSlot; +} NestLoopState; + +/* ---------------- + * MergeJoinState information + * + * NumClauses number of mergejoinable join clauses + * Clauses info for each mergejoinable clause + * JoinState current state of ExecMergeJoin state machine + * ExtraMarks true to issue extra Mark operations on inner scan + * ConstFalseJoin true if we have a constant-false joinqual + * FillOuter true if should emit unjoined outer tuples anyway + * FillInner true if should emit unjoined inner tuples anyway + * MatchedOuter true if found a join match for current outer tuple + * MatchedInner true if found a join match for current inner tuple + * OuterTupleSlot slot in tuple table for cur outer tuple + * InnerTupleSlot slot in tuple table for cur inner tuple + * MarkedTupleSlot slot in tuple table for marked tuple + * NullOuterTupleSlot prepared null tuple for right outer joins + * NullInnerTupleSlot prepared null tuple for left outer joins + * OuterEContext workspace for computing outer tuple's join values + * InnerEContext workspace for computing inner tuple's join values + * ---------------- + */ +/* private in nodeMergejoin.c: */ +typedef struct MergeJoinClauseData* MergeJoinClause; + +typedef struct MergeJoinState { + JoinState js; /* its first field is NodeTag */ + int mj_NumClauses; + MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */ + int mj_JoinState; + bool mj_ExtraMarks; + bool mj_ConstFalseJoin; + bool mj_FillOuter; + bool mj_FillInner; + bool mj_MatchedOuter; + bool mj_MatchedInner; + TupleTableSlot* mj_OuterTupleSlot; + TupleTableSlot* mj_InnerTupleSlot; + TupleTableSlot* mj_MarkedTupleSlot; + TupleTableSlot* mj_NullOuterTupleSlot; + TupleTableSlot* mj_NullInnerTupleSlot; + ExprContext* mj_OuterEContext; + ExprContext* mj_InnerEContext; +} MergeJoinState; + +struct MergeJoinShared { + JoinState js; /* its first field is NodeTag */ + int mj_NumClauses; + int mj_JoinState; + bool mj_ExtraMarks; + bool mj_ConstFalseJoin; + bool mj_FillOuter; + bool mj_FillInner; + bool mj_MatchedOuter; + bool mj_MatchedInner; +}; + +/* private in vecmergejoin.cpp: */ +typedef struct VecMergeJoinClauseData* VecMergeJoinClause; + +// Mark the offset of a row in a batch +// It is the same with integer and we rely on compiler to generate efficient +// code for structure copy. +struct MJBatchOffset { + // offset in the batch, starting from zero + uint16 m_offset; + + // Flag: is it actually representing an empty row? + bool m_fEmpty; + // Flag: is the offset pointing to the marked batch? + bool m_fMarked; + // batch sequence: ok to wrap around + int m_batchSeq; +}; + +struct BatchAccessor { + // child query to retrieve data + PlanState* m_plan; + // Current offset. It also points to the batch the offset is against. + // The maxOffset is used to detect the end of the batch. + VectorBatch* m_curBatch; + int m_batchSeq; + int m_curOffset; + int m_maxOffset; +}; + +struct VecMergeJoinState : public MergeJoinShared { + // Vectorization run support + VecMergeJoinClause mj_Clauses; + MJBatchOffset mj_OuterOffset; + MJBatchOffset mj_InnerOffset; + ExprContext* mj_OuterEContext; + ExprContext* mj_InnerEContext; + // Marked batch and offset. We need both to represent a marked row. + MJBatchOffset mj_MarkedOffset; + VectorBatch* mj_MarkedBatch; + + // Input batches (inner: 0, outer: 1). We record current progress on the + // input batches here. + BatchAccessor m_inputs[2]; + + // Previous batch join status. This is needed as some join types need + // to look backward to decide if we shall output current tuples. + MJBatchOffset m_prevInnerOffset; + bool m_prevInnerQualified; + MJBatchOffset m_prevOuterOffset; + bool m_prevOuterQualified; + + // Result batch and intermediate results. pInner and pOuter hold the join + // candiates passed the join key checks. + bool m_fDone; + VectorBatch* m_pInnerMatch; + MJBatchOffset* m_pInnerOffset; + VectorBatch* m_pOuterMatch; + MJBatchOffset* m_pOuterOffset; + VectorBatch* m_pCurrentBatch; + VectorBatch* m_pReturnBatch; + vecqual_func jitted_joinqual; /* LLVM IR function pointer to point to codegened mj_joinqualexpr */ +}; + +/* ---------------- + * HashJoinState information + * + * hashclauses original form of the hashjoin condition + * hj_OuterHashKeys the outer hash keys in the hashjoin condition + * hj_InnerHashKeys the inner hash keys in the hashjoin condition + * hj_HashOperators the join operators in the hashjoin condition + * hj_HashTable hash table for the hashjoin + * (NULL if table not built yet) + * hj_CurHashValue hash value for current outer tuple + * hj_CurBucketNo regular bucket# for current outer tuple + * hj_CurSkewBucketNo skew bucket# for current outer tuple + * hj_CurTuple last inner tuple matched to current outer + * tuple, or NULL if starting search + * (hj_CurXXX variables are undefined if + * OuterTupleSlot is empty!) + * hj_OuterTupleSlot tuple slot for outer tuples + * hj_HashTupleSlot tuple slot for inner (hashed) tuples + * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins + * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins + * hj_FirstOuterTupleSlot first tuple retrieved from outer plan + * hj_JoinState current state of ExecHashJoin state machine + * hj_MatchedOuter true if found a join match for current outer + * hj_OuterNotEmpty true if outer relation known not empty + * ---------------- + */ +/* these structs are defined in executor/hashjoin.h: */ +typedef struct HashJoinTupleData* HashJoinTuple; +typedef struct HashJoinTableData* HashJoinTable; + +typedef struct HashJoinState { + JoinState js; /* its first field is NodeTag */ + List* hashclauses; /* list of ExprState nodes */ + List* hj_OuterHashKeys; /* list of ExprState nodes */ + List* hj_InnerHashKeys; /* list of ExprState nodes */ + List* hj_HashOperators; /* list of operator OIDs */ + HashJoinTable hj_HashTable; + uint32 hj_CurHashValue; + int hj_CurBucketNo; + int hj_CurSkewBucketNo; + HashJoinTuple hj_CurTuple; + /* pointer which follows hj_CurTuple help us to delete matched tuples in HashTable.designed for Right Semi/Anti Join */ + HashJoinTuple hj_PreTuple; + TupleTableSlot* hj_OuterTupleSlot; + TupleTableSlot* hj_HashTupleSlot; + TupleTableSlot* hj_NullOuterTupleSlot; + TupleTableSlot* hj_NullInnerTupleSlot; + TupleTableSlot* hj_FirstOuterTupleSlot; + int hj_JoinState; + bool hj_MatchedOuter; + bool hj_OuterNotEmpty; + bool hj_streamBothSides; + bool hj_rebuildHashtable; +} HashJoinState; + +/* ---------------------------------------------------------------- + * Materialization State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * MaterialState information + * + * materialize nodes are used to materialize the results + * of a subplan into a temporary file. + * + * ss.ss_ScanTupleSlot refers to output of underlying plan. + * ---------------- + */ +typedef struct MaterialState { + ScanState ss; /* its first field is NodeTag */ + int eflags; /* capability flags to pass to tuplestore */ + bool eof_underlying; /* reached end of underlying plan? */ + bool materalAll; + Tuplestorestate* tuplestorestate; +} MaterialState; + +/* ---------------- + * SortState information + * ---------------- + */ +typedef struct SortState { + ScanState ss; /* its first field is NodeTag */ + bool randomAccess; /* need random access to sort output? */ + bool bounded; /* is the result set bounded? */ + int64 bound; /* if bounded, how many tuples are needed */ + bool sort_Done; /* sort completed yet? */ + bool bounded_Done; /* value of bounded we did the sort with */ + int64 bound_Done; /* value of bound we did the sort with */ + void* tuplesortstate; /* private state of tuplesort.c */ + int32 local_work_mem; /* work_mem local for this sort */ + int sortMethodId; /* sort method for explain */ + int spaceTypeId; /* space type for explain */ + long spaceUsed; /* space used for explain */ + int64* space_size; /* spill size for temp table */ +} SortState; + +/* --------------------- + * GroupState information + * ------------------------- + */ +typedef struct GroupState { + ScanState ss; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-field lookup data for equality fns */ + bool grp_done; /* indicates completion of Group scan */ +} GroupState; + +/* --------------------- + * AggState information + * + * ss.ss_ScanTupleSlot refers to output of underlying plan. + * + * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and + * ecxt_aggnulls arrays, which hold the computed agg values for the current + * input group during evaluation of an Agg node's output tuple(s). We + * create a second ExprContext, tmpcontext, in which to evaluate input + * expressions and run the aggregate transition functions. + * ------------------------- + */ +/* these structs are private in nodeAgg.c: */ +typedef struct AggStatePerAggData* AggStatePerAgg; +typedef struct AggStatePerGroupData* AggStatePerGroup; +typedef struct AggStatePerPhaseData* AggStatePerPhase; + +typedef struct AggState { + ScanState ss; /* its first field is NodeTag */ + List* aggs; /* all Aggref nodes in targetlist & quals */ + int numaggs; /* length of list (could be zero!) */ + AggStatePerPhase phase; /* pointer to current phase data */ + int numphases; /* number of phases */ + int current_phase; /* current phase number */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + AggStatePerAgg peragg; /* per-Aggref information */ + MemoryContext* aggcontexts; /* memory context for long-lived data */ + ExprContext* tmpcontext; /* econtext for input expressions */ + AggStatePerAgg curperagg; /* identifies currently active aggregate */ + bool input_done; /* indicates end of input */ + bool agg_done; /* indicates completion of Agg scan */ + int projected_set; /* The last projected grouping set */ + int current_set; /* The current grouping set being evaluated */ + Bitmapset* grouped_cols; /* grouped cols in current projection */ + List* all_grouped_cols; /* list of all grouped cols in DESC order */ + /* These fields are for grouping set phase data */ + int maxsets; /* The max number of sets in any phase */ + AggStatePerPhase phases; /* array of all phases */ + Tuplesortstate* sort_in; /* sorted input to phases > 0 */ + Tuplesortstate* sort_out; /* input is copied here for next phase */ + TupleTableSlot* sort_slot; /* slot for sort results */ + /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */ + AggStatePerGroup pergroup; /* per-Aggref-per-group working state */ + HeapTuple grp_firstTuple; /* copy of first tuple of current group */ + /* these fields are used in AGG_HASHED mode: */ + TupleHashTable hashtable; /* hash table with one entry per group */ + TupleTableSlot* hashslot; /* slot for loading hash table */ + List* hash_needed; /* list of columns needed in hash table */ + bool table_filled; /* hash table filled yet? */ + TupleHashIterator hashiter; /* for iterating through hash table */ +#ifdef PGXC + bool is_final; /* apply the final step for aggregates */ +#endif /* PGXC */ + void* aggTempFileControl; + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ +} AggState; + +/* ---------------- + * WindowAggState information + * ---------------- + */ +/* these structs are private in nodeWindowAgg.c: */ +typedef struct WindowStatePerFuncData* WindowStatePerFunc; +typedef struct WindowStatePerAggData* WindowStatePerAgg; + +typedef struct WindowAggState { + ScanState ss; /* its first field is NodeTag */ + + /* these fields are filled in by ExecInitExpr: */ + List* funcs; /* all WindowFunc nodes in targetlist */ + int numfuncs; /* total number of window functions */ + int numaggs; /* number that are plain aggregates */ + + WindowStatePerFunc perfunc; /* per-window-function information */ + WindowStatePerAgg peragg; /* per-plain-aggregate information */ + FmgrInfo* partEqfunctions; /* equality funcs for partition columns */ + FmgrInfo* ordEqfunctions; /* equality funcs for ordering columns */ + Tuplestorestate* buffer; /* stores rows of current partition */ + int current_ptr; /* read pointer # for current */ + int64 spooled_rows; /* total # of rows in buffer */ + int64 currentpos; /* position of current row in partition */ + int64 frameheadpos; /* current frame head position */ + int64 frametailpos; /* current frame tail position */ + /* use struct pointer to avoid including windowapi.h here */ + struct WindowObjectData* agg_winobj; /* winobj for aggregate fetches */ + int64 aggregatedbase; /* start row for current aggregates */ + int64 aggregatedupto; /* rows before this one are aggregated */ + + int frameOptions; /* frame_clause options, see WindowDef */ + ExprState* startOffset; /* expression for starting bound offset */ + ExprState* endOffset; /* expression for ending bound offset */ + Datum startOffsetValue; /* result of startOffset evaluation */ + Datum endOffsetValue; /* result of endOffset evaluation */ + + MemoryContext partcontext; /* context for partition-lifespan data */ + MemoryContext aggcontext; /* context for each aggregate data */ + ExprContext* tmpcontext; /* short-term evaluation context */ + + bool all_first; /* true if the scan is starting */ + bool all_done; /* true if the scan is finished */ + bool partition_spooled; /* true if all tuples in current partition have been spooled into tuplestore */ + bool more_partitions; /* true if there's more partitions after this one */ + bool framehead_valid; /* true if frameheadpos is known up to date for current row */ + bool frametail_valid; /* true if frametailpos is known up to date for current row */ + + TupleTableSlot* first_part_slot; /* first tuple of current or next partition */ + + /* temporary slots for tuples fetched back from tuplestore */ + TupleTableSlot* agg_row_slot; + TupleTableSlot* temp_slot_1; + TupleTableSlot* temp_slot_2; +} WindowAggState; + +/* ---------------- + * OrderedSetAggState information + * ---------------- + */ +typedef struct OrderedSetAggState { + AggState* aggstate; + Aggref* aggref; /* Keep the agg info for start up used */ + Tuplesortstate* sortstate; /* Used for accumulate sort datum */ + int64 number_of_rows; /* Number of normal datum inside sortstate */ + TupleDesc tupdesc; /* Tuple descriptor for datum inside sortstate */ + + Oid datumtype; /* Datatype of datums being sorted */ + int16 typLen; + bool typByVal; + char typAlign; + Oid eq_operator; /* Equality operator associated with sort operator */ + char sign; /* Sign for orderedSetAggState */ +} OrderedSetAggState; + +/* ---------------- + * UniqueState information + * + * Unique nodes are used "on top of" sort nodes to discard + * duplicate tuples returned from the sort phase. Basically + * all it does is compare the current tuple from the subplan + * with the previously fetched tuple (stored in its result slot). + * If the two are identical in all interesting fields, then + * we just fetch another tuple from the sort and try again. + * ---------------- + */ +typedef struct UniqueState { + PlanState ps; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-field lookup data for equality fns */ + MemoryContext tempContext; /* short-term context for comparisons */ +} UniqueState; + +/* ---------------- + * HashState information + * ---------------- + */ +typedef struct HashState { + PlanState ps; /* its first field is NodeTag */ + HashJoinTable hashtable; /* hash table for the hashjoin */ + List* hashkeys; /* list of ExprState nodes */ + int32 local_work_mem; /* work_mem local for this hash join */ + int64 spill_size; + + /* hashkeys is same as parent's hj_InnerHashKeys */ +} HashState; + +/* ---------------- + * SetOpState information + * + * Even in "sorted" mode, SetOp nodes are more complex than a simple + * Unique, since we have to count how many duplicates to return. But + * we also support hashing, so this is really more like a cut-down + * form of Agg. + * ---------------- + */ +/* this struct is private in nodeSetOp.c: */ +typedef struct SetOpStatePerGroupData* SetOpStatePerGroup; + +typedef struct SetOpState { + PlanState ps; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + bool setop_done; /* indicates completion of output scan */ + long numOutput; /* number of dups left to output */ + MemoryContext tempContext; /* short-term context for comparisons */ + /* these fields are used in SETOP_SORTED mode: */ + SetOpStatePerGroup pergroup; /* per-group working state */ + HeapTuple grp_firstTuple; /* copy of first tuple of current group */ + /* these fields are used in SETOP_HASHED mode: */ + TupleHashTable hashtable; /* hash table with one entry per group */ + MemoryContext tableContext; /* memory context containing hash table */ + bool table_filled; /* hash table filled yet? */ + TupleHashIterator hashiter; /* for iterating through hash table */ + void* TempFileControl; + int64 spill_size; +} SetOpState; + +/* ---------------- + * LockRowsState information + * + * LockRows nodes are used to enforce FOR UPDATE/FOR SHARE locking. + * ---------------- + */ +typedef struct LockRowsState { + PlanState ps; /* its first field is NodeTag */ + List* lr_arowMarks; /* List of ExecAuxRowMarks */ + EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */ +} LockRowsState; + +/* ---------------- + * LimitState information + * + * Limit nodes are used to enforce LIMIT/OFFSET clauses. + * They just select the desired subrange of their subplan's output. + * + * offset is the number of initial tuples to skip (0 does nothing). + * count is the number of tuples to return after skipping the offset tuples. + * If no limit count was specified, count is undefined and noCount is true. + * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet. + * ---------------- + */ +typedef enum { + LIMIT_INITIAL, /* initial state for LIMIT node */ + LIMIT_RESCAN, /* rescan after recomputing parameters */ + LIMIT_EMPTY, /* there are no returnable rows */ + LIMIT_INWINDOW, /* have returned a row in the window */ + LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */ + LIMIT_WINDOWEND, /* stepped off end of window */ + LIMIT_WINDOWSTART /* stepped off beginning of window */ +} LimitStateCond; + +typedef struct LimitState { + PlanState ps; /* its first field is NodeTag */ + ExprState* limitOffset; /* OFFSET parameter, or NULL if none */ + ExprState* limitCount; /* COUNT parameter, or NULL if none */ + int64 offset; /* current OFFSET value */ + int64 count; /* current COUNT, if any */ + bool noCount; /* if true, ignore count */ + LimitStateCond lstate; /* state machine status, as above */ + int64 position; /* 1-based index of last tuple returned */ + TupleTableSlot* subSlot; /* tuple last obtained from subplan */ +} LimitState; + +/* + * Target : data partition + * Brief : structure definition about partition iteration + */ +typedef struct PartIteratorState { + PlanState ps; /* its first field is NodeTag */ + int currentItr; /* the sequence number for processing partition */ +} PartIteratorState; + +struct VecLimitState : public LimitState { + VectorBatch* subBatch; +}; + +/* + * RownumState node: used for computing the pseudo-column ROWNUM + */ +typedef struct RownumState { + ExprState xprstate; + PlanState* ps; /* the value of ROWNUM depends on its parent PlanState */ +} RownumState; + +/* ---------------- + * GroupingFuncExprState node + * + * The list of column numbers refers to the input tuples of the Agg node to + * which the GroupingFunc belongs, and may contain 0 for references to columns + * that are only present in grouping sets processed by different Agg nodes (and + * which are therefore always considered "grouping" here). + * ---------------- + */ +typedef struct GroupingFuncExprState { + ExprState xprstate; + AggState* aggstate; + List* clauses; /* integer list of column numbers */ +} GroupingFuncExprState; + +typedef struct GroupingIdExprState { + ExprState xprstate; + AggState* aggstate; +} GroupingIdExprState; + +/* + * used by CstoreInsert and DfsInsert in nodeModifyTable.h and vecmodifytable.cpp + */ +#define FLUSH_DATA(obj, type) \ + do { \ + ((type*)obj)->SetEndFlag(); \ + ((type*)obj)->BatchInsert((VectorBatch*)NULL, 0); \ + ((type*)obj)->EndBatchInsert(); \ + ((type*)obj)->Destroy(); \ + delete (type*)obj; \ + } while (0) + +/* + * used by TsStoreInsert in nodeModifyTable.h and vecmodifytable.cpp + */ +#define FLUSH_DATA_TSDB(obj, type) \ + do{ \ + ((type*)obj)->BatchInsert((VectorBatch*)NULL, 0); \ + ((type*)obj)->end_batch_insert(); \ + ((type*)obj)->Destroy(); \ + }while(0) +/* + * record the first tuple time used by INSERT, UPDATE and DELETE in ExecModifyTable and ExecVecModifyTable + */ +#define record_first_time() \ + do { \ + if (unlikely(is_first_modified)) { \ + INSTR_TIME_SET_CURRENT(node->first_tuple_modified); \ + is_first_modified = false; \ + } \ + } while (0) + +extern TupleTableSlot* ExecMakeTupleSlot(Tuple tuple, TableScanDesc tableScan, TupleTableSlot* slot, TableAmType tableAm); + +/* + * When the global partition index is used for bitmap scanning, + * checks whether the partition table needs to be + * switched each time an tbmres is obtained. + */ +inline bool BitmapNodeNeedSwitchPartRel(BitmapHeapScanState* node) +{ + return tbm_is_global(node->tbm) && GPIScanCheckPartOid(node->gpi_scan, node->tbmres->partitionOid); +} + +extern RangeScanInRedis reset_scan_qual(Relation currHeapRel, ScanState *node); + +#endif /* EXECNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/include/nodes/feparser_memutils.h postgresql-hll-2.14/include/include/nodes/feparser_memutils.h --- postgresql-hll-2.14_old/include/include/nodes/feparser_memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/feparser_memutils.h 2020-12-12 17:06:43.230347819 +0800 @@ -0,0 +1,23 @@ +/* + * fe_memutils.h + * memory management support for frontend code + * + * Copyright (c) 2003-2015, PostgreSQL Global Development Group + * + * src/include/common/fe_memutils.h + */ +#ifndef FEPARSER_MEMUTILS_H +#define FEPARSER_MEMUTILS_H +#ifdef FRONTEND_PARSER +/* + * "Safe" memory allocation functions --- these exit(1) on failure + */ +char *feparser_strdup(const char *in); +void *feparser_malloc(size_t size); +void *feparser_malloc0(size_t size); +void *feparser_malloc_extended(size_t size, int flags); +void *feparser_realloc(void *pointer, size_t size); +void feparser_free(void *pointer); +void free_memory(); +#endif +#endif /* FEPARSER_MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/makefuncs.h postgresql-hll-2.14/include/include/nodes/makefuncs.h --- postgresql-hll-2.14_old/include/include/nodes/makefuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/makefuncs.h 2020-12-12 17:06:43.230347819 +0800 @@ -0,0 +1,87 @@ +/* ------------------------------------------------------------------------- + * + * makefuncs.h + * prototypes for the creator functions (for primitive nodes) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/makefuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MAKEFUNC_H +#define MAKEFUNC_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#include "nodes/execnodes.h" +#else +#include "datatypes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "nodes/parsenodes_common.h" +#endif /* FRONTEND_PARSER */ + +extern Const *makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, + bool constisnull, bool constbyval, Cursor_Data *cur = NULL); + +#ifndef FRONTEND_PARSER + +extern Var* makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup); + +extern Var* makeVarFromTargetEntry(Index varno, TargetEntry* tle); + +extern Var* makeWholeRowVar(RangeTblEntry* rte, Index varno, Index varlevelsup, bool allowScalar); + +extern TargetEntry* makeTargetEntry(Expr* expr, AttrNumber resno, char* resname, bool resjunk); + +extern TargetEntry* flatCopyTargetEntry(TargetEntry* src_tle); + +extern FromExpr* makeFromExpr(List* fromlist, Node* quals); + +extern ColumnRef* makeColumnRef(char* relname, char* colname, int location); + +extern Const* makeMaxConst(Oid consttype, int32 consttypmod, Oid constcollid); + +extern Node* makeNullAConst(int location); + +extern Const* makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid); + +extern Node* makeBoolConst(bool value, bool isnull); + +extern Expr* makeBoolExpr(BoolExprType boolop, List* args, int location); + +extern Alias* makeAlias(const char* aliasname, List* colnames); + +extern RelabelType* makeRelabelType(Expr* arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat); + +extern TypeName* makeTypeNameFromOid(Oid typeOid, int32 typmod); + +extern FuncExpr* makeFuncExpr( + Oid funcid, Oid rettype, List* args, Oid funccollid, Oid inputcollid, CoercionForm fformat); + +extern NullTest* makeNullTest(NullTestType type, Expr* expr); +extern Expr* makeBoolExprTreeNode(BoolExprType boolop, List* args); +extern HashFilter* makeHashFilter(List* arg, List* typeOidlist, List* nodelist); +extern Node* makeTidConst(ItemPointer item); +extern FuncCall* makeFuncCall(List* funcname, List* args, int location); +extern Param* makeParam( + ParamKind paramkind, int paramid, Oid paramtype, int32 paramtypmod, Oid paramcollid, int location); +extern IndexInfo* makeIndexInfo(int numattrs, List *expressions, List *predicates, + bool unique, bool isready, bool concurrent); + +#endif /* !FRONTEND_PARSER */ +extern A_Expr *makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location); +extern A_Expr *makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location); +extern RangeVar *makeRangeVar(char *schemaname, char *relname, int location); +extern TypeName *makeTypeName(char *typnam); +extern TypeName *makeTypeNameFromNameList(List *names); +extern DefElem *makeDefElem(char *name, Node *arg); +extern DefElem *makeDefElemExtended(char *nameSpace, char *name, Node *arg, DefElemAction defaction); +extern GroupingSet *makeGroupingSet(GroupingSetKind kind, List *content, int location); + +#endif /* MAKEFUNC_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/memnodes.h postgresql-hll-2.14/include/include/nodes/memnodes.h --- postgresql-hll-2.14_old/include/include/nodes/memnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/memnodes.h 2020-12-12 17:06:43.230347819 +0800 @@ -0,0 +1,268 @@ +/* ------------------------------------------------------------------------- + * + * memnodes.h + * POSTGRES memory context node definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/memnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMNODES_H +#define MEMNODES_H + +#include "nodes/nodes.h" +#include "nodes/pg_list.h" + +/* + * MemoryContext + * A logical context in which memory allocations occur. + * + * MemoryContext itself is an abstract type that can have multiple + * implementations, though for now we have only AllocSetContext. + * The function pointers in MemoryContextMethods define one specific + * implementation of MemoryContext --- they are a virtual function table + * in C++ terms. + * + * Node types that are actual implementations of memory contexts must + * begin with the same fields as MemoryContext. + * + * Note: for largely historical reasons, typedef MemoryContext is a pointer + * to the context struct rather than the struct type itself. + */ +typedef struct MemoryContextMethods { + void* (*alloc)(MemoryContext context, Size align, Size size, const char* file, int line); + /* call this free_p in case someone #define's free() */ + void (*free_p)(MemoryContext context, void* pointer); + void* (*realloc)(MemoryContext context, void* pointer, Size align, Size size, const char* file, int line); + void (*init)(MemoryContext context); + void (*reset)(MemoryContext context); + void (*delete_context)(MemoryContext context); + Size (*get_chunk_space)(MemoryContext context, void* pointer); + bool (*is_empty)(MemoryContext context); + void (*stats)(MemoryContext context, int level); +#ifdef MEMORY_CONTEXT_CHECKING + void (*check)(MemoryContext context); +#endif +} MemoryContextMethods; + +typedef struct MemoryTrackData* MemoryTrack; /* forward reference */ + +typedef struct MemoryTrackData { + NodeTag type; /* identifies exact kind of context */ + MemoryTrack parent; /* NULL if no parent (toplevel context) */ + MemoryTrack firstchild; /* head of linked list of children */ + MemoryTrack nextchild; /* next child of same parent */ + char* name; /* context name */ + Size peakSpace; /* the peak bytes allocated by this context */ + Size allBytesPeak; /* the peak bytes allocated by this and its children's context */ + Size allBytesAlloc; /* all bytes allocated by this and its children's context */ + Size allBytesFreed; /* all bytes freed by this and its children's context */ + int sequentCount; /* the sequent count when creating in the thread */ +#ifdef MEMORY_CONTEXT_CHECKING + bool isTracking; /* flag to indicate which is tracked by memory_detail_tracking setting */ +#endif +} MemoryTrackData; + +typedef struct MemoryContextData { + NodeTag type; /* identifies exact kind of context */ + MemoryContextMethods* methods; /* virtual function table */ + MemoryContext parent; /* NULL if no parent (toplevel context) */ + MemoryContext firstchild; /* head of linked list of children */ + MemoryContext prevchild; /* previous child of same parent */ + MemoryContext nextchild; /* next child of same parent */ + char* name; /* context name (just for debugging) */ + pthread_rwlock_t lock; /* lock to protect members if the context is shared */ + bool is_sealed; /* sealed context prevent any memory change */ + bool is_shared; /* context is shared by threads */ + bool isReset; /* T = no space alloced since last reset */ + int level; /* context level */ + uint64 session_id; /* session id of context owner */ + ThreadId thread_id; /* thread id of context owner */ + ListCell cell; /* cell to pointer to this context*/ +} MemoryContextData; + +#define MemoryContextIsShared(context) (((MemoryContextData*)(context))->is_shared) + +#define MemoryContextLock(context) \ + do { \ + START_CRIT_SECTION(); \ + int err = pthread_rwlock_wrlock(&((MemoryContextData*)(context))->lock); \ + if (err != 0) { \ + END_CRIT_SECTION(); \ + ereport(ERROR, \ + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), \ + errmsg("system call failed when lock, errno:%d.", err))); \ + } \ + } while (0) + +#define MemoryContextUnlock(context) \ + do { \ + int unlock_err = pthread_rwlock_unlock(&((MemoryContextData*)(context))->lock); \ + if (unlock_err != 0) { \ + END_CRIT_SECTION(); \ + ereport(PANIC, \ + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), \ + errmsg("system call failed when unlock, errno:%d.", unlock_err))); \ + } \ + END_CRIT_SECTION(); \ + } while (0) + +typedef struct AllocBlockData* AllocBlock; /* forward reference */ +typedef struct AllocChunkData* AllocChunk; +typedef struct AsanBlockData* AsanBlock; +/* + * AllocPointer + * Aligned pointer which may be a member of an allocation set. + */ +typedef void* AllocPointer; + +#define ALLOCSET_NUM_FREELISTS 11 + +/* + * AllocSetContext is our standard implementation of MemoryContext. + * + * Note: header.isReset means there is nothing for AllocSetReset to do. + * This is different from the aset being physically empty (empty blocks list) + * because we may still have a keeper block. It's also different from the set + * being logically empty, because we don't attempt to detect pfree'ing the + * last active chunk. + */ +typedef struct AllocSetContext { + MemoryContextData header; /* Standard memory-context fields */ + /* Info about storage allocated in this context: */ + AllocBlock blocks; /* head of list of blocks in this set */ + AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ + /* Allocation parameters for this context: */ + Size initBlockSize; /* initial block size */ + Size maxBlockSize; /* maximum block size */ + Size nextBlockSize; /* next block size to allocate */ + Size allocChunkLimit; /* effective chunk size limit */ + AllocBlock keeper; /* if not NULL, keep this block over resets */ + Size totalSpace; /* all bytes allocated by this context */ + Size freeSpace; /* all bytes freed by this context */ + + /* maximum memory allocation of MemoryContext.For more information,we could see @StackSetContext too. */ + Size maxSpaceSize; + + MemoryTrack track; /* used to track the memory allocation information */ +} AllocSetContext; + +typedef AllocSetContext* AllocSet; + +/* + * AllocBlock + * An AllocBlock is the unit of memory that is obtained by aset.c + * from malloc(). It contains one or more AllocChunks, which are + * the units requested by palloc() and freed by pfree(). AllocChunks + * cannot be returned to malloc() individually, instead they are put + * on freelists by pfree() and re-used by the next palloc() that has + * a matching request size. + * + * AllocBlockData is the header data for a block --- the usable space + * within the block begins at the next alignment boundary. + */ +typedef struct AllocBlockData { + AllocSet aset; /* aset that owns this block */ + AllocBlock prev; /* prev block in aset's blocks list, if any */ + AllocBlock next; /* next block in aset's blocks list */ + char* freeptr; /* start of free space in this block */ + char* endptr; /* end of space in this block */ + Size allocSize; /* allocated size */ +#ifdef MEMORY_CONTEXT_CHECKING + uint64 magicNum; /* DADA */ +#endif +} AllocBlockData; + +#define ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) +/* AsanSetContext is our asan implementation of MemoryContext. + * Note: + * AsanSetContext's structure must be consistent with AllocSetContext. + * header.isReset means there is nothing for AsanSetContext to do. + * This is different from the aset being physically empty (empty blocks list) + * because we may still have a keeper block. It's also different from the set + * being logically empty, because we don't attempt to detect pfree'ing the * last active chunk. */ +typedef struct AsanSetContext { + MemoryContextData header; /* Standard memory-context fields */ + /* Info about storage allocated in this context: */ + AsanBlock blocks; /* head of list of blocks in this set */ + char* reserve[ALLOCSET_NUM_FREELISTS]; /* Allocation parameters for this context: */ + Size initBlockSize; /* initial block size */ + Size maxBlockSize; /* maximum block size */ + Size nextBlockSize; /* next block size to allocate */ + Size allocChunkLimit; /* effective chunk size limit */ + AsanBlock keeper; /* if not NULL, keep this block over resets */ + Size totalSpace; /* all bytes allocated by this context */ + Size freeSpace; /* all bytes freed by this context */ + /* maximum memory allocation of MemoryContext.For more information,we could see @StackSetContext too. */ + Size maxSpaceSize; + MemoryTrack track; /* used to track the memory allocation information */ +} AsanSetContext; + +typedef AsanSetContext* AsanSet; + +typedef struct AsanBlockData { + AsanSet aset; /* aset that owns this block */ + AsanBlock prev; /* prev block in aset's blocks list, if any */ + AsanBlock next; /* next block in aset's blocks list */ + uint32 requestSize; /* request size */ + int line; /* __LINE__ of palloc/palloc0 call */ + const char* file; /* __FILE__ of palloc/palloc0 call */ +} AsanBlockData; + +#define ASAN_BLOCKHDRSZ MAXALIGN(sizeof(AsanBlockData)) +/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */ +typedef struct StackBlockData* StackBlock; + +typedef struct StackSetContext { + MemoryContextData header; /* Standard memory-context fields */ + StackBlock blocks; + StackBlock freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ + + // Allocation parameters for this context: + // + Size initBlockSize; // initial block size + Size maxBlockSize; // maximum block size + Size nextBlockSize; // next block size + Size allocChunkLimit; // limit chunk + StackBlock keeper; + Size totalSpace; + Size freeSpace; + + /* The parameter named maxSpaceSize is an allocation parameter,but this parameter must be here. + * Otherwise the pointer of MemoryContextMethods will be out-of-order. + * So AllocSetContext is.You can see @AllocSetContext + */ + Size maxSpaceSize; + MemoryTrack track; /* used to track the memory allocation information */ +} StackSetContext; + +typedef struct MemoryProtectFuncDef { + void* (*malloc)(Size sz, bool needProtect); + void (*free)(void* ptr, Size sz); + void* (*realloc)(void* ptr, Size oldsz, Size newsz, bool needProtect); + int (*memalign)(void** memptr, Size alignment, Size sz, bool needProtect); +} MemoryProtectFuncDef; + +extern MemoryProtectFuncDef GenericFunctions; +extern MemoryProtectFuncDef SessionFunctions; +extern MemoryProtectFuncDef SharedFunctions; + +/* + * MemoryContextIsValid + * True iff memory context is valid. + * + * Add new context types to the set accepted by this macro. + */ +#define MemoryContextIsValid(context) \ + ((context) != NULL && \ + (IsA((context), AllocSetContext) || IsA((context), AsanSetContext) || IsA((context), StackAllocSetContext) || \ + IsA((context), SharedAllocSetContext) || IsA((context), MemalignAllocSetContext) || \ + IsA((context), MemalignSharedAllocSetContext))) + +#define AllocSetContextUsedSpace(aset) ((aset)->totalSpace - (aset)->freeSpace) +#endif /* MEMNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/include/nodes/nodeFuncs.h postgresql-hll-2.14/include/include/nodes/nodeFuncs.h --- postgresql-hll-2.14_old/include/include/nodes/nodeFuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/nodeFuncs.h 2020-12-12 17:06:43.230347819 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * nodeFuncs.h + * Various general-purpose manipulations of Node trees + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/nodeFuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFUNCS_H +#define NODEFUNCS_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#else +#include "datatypes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "nodes/parsenodes_common.h" +#endif + +/* flags bits for query_tree_walker and query_tree_mutator */ +#define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */ +#define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */ +#define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */ +#define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */ +#define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */ +#define QTW_EXAMINE_RTES 0x10 /* examine RTEs */ +#define QTW_DONT_COPY_QUERY 0x20 /* do not copy top Query */ +#define QTW_IGNORE_DUMMY 0x40 /* remote dummy */ + +extern Oid exprType(const Node* expr); +extern int32 exprTypmod(const Node* expr); +extern bool exprIsLengthCoercion(const Node* expr, int32* coercedTypmod); +extern Node* relabel_to_typmod(Node* expr, int32 typmod); +extern bool expression_returns_set(Node* clause); + +extern Oid exprCollation(const Node* expr); +extern Oid exprInputCollation(const Node* expr); +extern void exprSetCollation(Node* expr, Oid collation); +extern void exprSetInputCollation(Node* expr, Oid inputcollation); + +extern int exprLocation(const Node* expr); + +extern bool expression_tree_walker(Node* node, bool (*walker)(), void* context); +extern Node* expression_tree_mutator(Node* node, Node* (*mutator)(Node*, void*), void* context, bool isCopy = true); + +#ifndef FRONTEND_PARSER +extern bool query_tree_walker(Query* query, bool (*walker)(), void* context, int flags); +extern Query* query_tree_mutator(Query* query, Node* (*mutator)(Node*, void*), void* context, int flags); +#endif + +extern bool range_table_walker(List* rtable, bool (*walker)(), void* context, int flags); +extern List* range_table_mutator(List* rtable, Node* (*mutator)(Node*, void*), void* context, int flags); + +extern bool query_or_expression_tree_walker(Node* node, bool (*walker)(), void* context, int flags); +extern Node* query_or_expression_tree_mutator(Node* node, Node* (*mutator)(Node*, void*), void* context, int flags); + +extern bool raw_expression_tree_walker(Node* node, bool (*walker)(), void* context); +extern bool is_func_distinct_unshippable(Oid funcid); + +extern bool lockNextvalWalker(Node* node, void* context); + +#endif /* NODEFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/nodes.h postgresql-hll-2.14/include/include/nodes/nodes.h --- postgresql-hll-2.14_old/include/include/nodes/nodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/nodes.h 2020-12-12 17:06:43.231347832 +0800 @@ -0,0 +1,960 @@ +/* ------------------------------------------------------------------------- + * + * nodes.h + * Definitions for tagged nodes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/nodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODES_H +#define NODES_H +#ifdef FRONTEND_PARSER +#include "feparser_memutils.h" +#endif +/* + * The first field of every node is NodeTag. Each node created (with makeNode) + * will have one of the following tags as the value of its first field. + * + * Note that the numbers of the node tags are not contiguous. We left holes + * here so that we can add more tags without changing the existing enum's. + * (Since node tag numbers never exist outside backend memory, there's no + * real harm in renumbering, it just costs a full rebuild ...) + */ +typedef enum NodeTag { + T_Invalid = 0, + + /* + * TAGS FOR EXECUTOR NODES (execnodes.h) + */ + T_IndexInfo = 10, + T_ExprContext, + T_ProjectionInfo, + T_JunkFilter, + T_ResultRelInfo, + T_EState, + T_TupleTableSlot, + + /* + * TAGS FOR PLAN NODES (plannodes.h) + */ + T_Plan = 100, + T_BaseResult, + T_ModifyTable, + T_Append, + T_PartIterator, + T_MergeAppend, + T_RecursiveUnion, + T_BitmapAnd, + T_BitmapOr, + T_Scan, + T_SeqScan, + T_IndexScan, + T_IndexOnlyScan, + T_BitmapIndexScan, + T_BitmapHeapScan, + T_TidScan, + T_SubqueryScan, + T_FunctionScan, + T_ValuesScan, + T_CteScan, + T_WorkTableScan, + T_ForeignScan, + T_ExtensiblePlan, + T_Join, + T_NestLoop, + T_MergeJoin, + T_HashJoin, + T_Material, + T_Sort, + T_Group, + T_Agg, + T_WindowAgg, + T_Unique, + T_Hash, + T_SetOp, + T_LockRows, + T_Limit, + T_Stream, +#ifdef PGXC + /* + * TAGS FOR PGXC NODES + * (planner.h, locator.h, nodemgr.h, groupmgr.h) + */ + T_ExecNodes, + T_SliceBoundary, + T_ExecBoundary, + T_SimpleSort, + T_RemoteQuery, + T_PGXCNodeHandle, + T_AlterNodeStmt, + T_CreateNodeStmt, + T_DropNodeStmt, + T_AlterCoordinatorStmt, + T_CreateGroupStmt, + T_AlterGroupStmt, + T_DropGroupStmt, + T_CreateResourcePoolStmt, + T_AlterResourcePoolStmt, + T_DropResourcePoolStmt, + T_CreateWorkloadGroupStmt, + T_AlterWorkloadGroupStmt, + T_DropWorkloadGroupStmt, + T_CreateAppWorkloadGroupMappingStmt, + T_AlterAppWorkloadGroupMappingStmt, + T_DropAppWorkloadGroupMappingStmt, +#endif + /* these aren't subclasses of Plan: */ + T_NestLoopParam, + T_PartIteratorParam, + T_PlanRowMark, + T_PlanInvalItem, + /* TAGS FOR POLICY LABEL */ + T_PolicyFilterNode, + T_CreatePolicyLabelStmt, + T_AlterPolicyLabelStmt, + T_DropPolicyLabelStmt, + T_CreateAuditPolicyStmt, + T_AlterAuditPolicyStmt, + T_DropAuditPolicyStmt, + T_MaskingPolicyCondition, + T_CreateMaskingPolicyStmt, + T_AlterMaskingPolicyStmt, + T_DropMaskingPolicyStmt, + T_CreateSecurityPolicyStmt, + T_AlterSecurityPolicyStmt, + T_DropSecurityPolicyStmt, + + /* + * TAGS FOR PLAN STATE NODES (execnodes.h) + * + * These should correspond one-to-one with Plan node types. + */ + T_PlanState = 200, + T_ResultState, + T_MergeActionState, + T_ModifyTableState, + T_DistInsertSelectState, + T_AppendState, + T_PartIteratorState, + T_MergeAppendState, + T_RecursiveUnionState, + T_BitmapAndState, + T_BitmapOrState, + T_ScanState, + T_SeqScanState, + T_IndexScanState, + T_IndexOnlyScanState, + T_BitmapIndexScanState, + T_BitmapHeapScanState, + T_TidScanState, + T_SubqueryScanState, + T_FunctionScanState, + T_ValuesScanState, + T_CteScanState, + T_WorkTableScanState, + T_ForeignScanState, + T_ExtensiblePlanState, + T_JoinState, + T_NestLoopState, + T_MergeJoinState, + T_HashJoinState, + T_MaterialState, + T_SortState, + T_GroupState, + T_AggState, + T_WindowAggState, + T_UniqueState, + T_HashState, + T_SetOpState, + T_LockRowsState, + T_LimitState, +#ifdef PGXC + T_RemoteQueryState, +#endif + T_StreamState, + + /* + * TAGS FOR PRIMITIVE NODES (primnodes.h) + */ + T_Alias = 300, + T_RangeVar, + T_Expr, + T_Var, + T_Const, + T_Param, + T_Aggref, + T_GroupingFunc, + T_WindowFunc, + T_InitList, + T_ArrayRef, + T_FuncExpr, + T_NamedArgExpr, + T_OpExpr, + T_DistinctExpr, + T_NullIfExpr, + T_ScalarArrayOpExpr, + T_BoolExpr, + T_SubLink, + T_SubPlan, + T_AlternativeSubPlan, + T_FieldSelect, + T_FieldStore, + T_RelabelType, + T_CoerceViaIO, + T_ArrayCoerceExpr, + T_ConvertRowtypeExpr, + T_CollateExpr, + T_CaseExpr, + T_CaseWhen, + T_CaseTestExpr, + T_ArrayExpr, + T_RowExpr, + T_RowCompareExpr, + T_CoalesceExpr, + T_MinMaxExpr, + T_XmlExpr, + T_NullTest, + T_BooleanTest, + T_CoerceToDomain, + T_CoerceToDomainValue, + T_SetToDefault, + T_CurrentOfExpr, + T_TargetEntry, + T_RangeTblRef, + T_JoinExpr, + T_FromExpr, + T_UpsertExpr, + T_IntoClause, + T_IndexVar, +#ifdef PGXC + T_DistributeBy, + T_PGXCSubCluster, + T_DistState, + T_ListSliceDefState, +#endif + T_HashFilter, + T_EstSPNode, + T_Rownum, + + /* + * TAGS FOR EXPRESSION STATE NODES (execnodes.h) + * + * These correspond (not always one-for-one) to primitive nodes derived + * from Expr. + */ + T_ExprState = 400, + T_GenericExprState, + T_AggrefExprState, + T_GroupingFuncExprState, + T_WindowFuncExprState, + T_ArrayRefExprState, + T_FuncExprState, + T_ScalarArrayOpExprState, + T_BoolExprState, + T_SubPlanState, + T_AlternativeSubPlanState, + T_FieldSelectState, + T_FieldStoreState, + T_CoerceViaIOState, + T_ArrayCoerceExprState, + T_ConvertRowtypeExprState, + T_CaseExprState, + T_CaseWhenState, + T_ArrayExprState, + T_RowExprState, + T_RowCompareExprState, + T_CoalesceExprState, + T_MinMaxExprState, + T_XmlExprState, + T_NullTestState, + T_HashFilterState, + T_CoerceToDomainState, + T_DomainConstraintState, + T_WholeRowVarExprState, /* will be in a more natural position in 9.3 */ + T_RangePartitionDefState, + T_IntervalPartitionDefState, + T_PartitionState, + T_RangePartitionindexDefState, + T_SplitPartitionState, + T_AddPartitionState, + T_RangePartitionStartEndDefState, + T_RownumState, + T_ListPartitionDefState, + T_HashPartitionDefState, + + /* + * TAGS FOR PLANNER NODES (relation.h) + */ + T_PlannerInfo = 500, + T_PlannerGlobal, + T_RelOptInfo, + T_IndexOptInfo, + T_ParamPathInfo, + T_Path, + T_IndexPath, + T_BitmapHeapPath, + T_BitmapAndPath, + T_BitmapOrPath, + T_NestPath, + T_MergePath, + T_HashPath, + T_TidPath, + T_ForeignPath, + T_ExtensiblePath, + T_AppendPath, + T_MergeAppendPath, + T_ResultPath, + T_MaterialPath, + T_UniquePath, + T_PartIteratorPath, + T_EquivalenceClass, + T_EquivalenceMember, + T_PathKey, + T_RestrictInfo, + T_PlaceHolderVar, + T_SpecialJoinInfo, + T_LateralJoinInfo, + T_AppendRelInfo, + T_PlaceHolderInfo, + T_MinMaxAggInfo, + T_PlannerParamItem, +#ifdef PGXC + T_RemoteQueryPath, +#endif /* PGXC */ + T_StreamPath, + T_MergeAction, + T_UpsertState, + T_SubqueryScanPath, + + /* + * TAGS FOR MEMORY NODES (memnodes.h) + */ + T_MemoryContext = 600, + T_AllocSetContext, + T_AsanSetContext, + T_StackAllocSetContext, + T_SharedAllocSetContext, + T_MemalignAllocSetContext, + T_MemalignSharedAllocSetContext, + + T_MemoryTracking, + + /* + * TAGS FOR VALUE NODES (value.h) + */ + T_Value = 650, + T_Integer, + T_Float, + T_String, + T_BitString, + T_Null, + + /* + * TAGS FOR LIST NODES (pg_list.h) + */ + T_List, + T_IntList, + T_OidList, + + /* + * TAGS FOR DOUBLE LIST NODES (pg_list.h) + */ + T_DList, + T_IntDList, + T_OidDList, + + /* + * TAGS FOR STATEMENT NODES (mostly in parsenodes.h) + */ + T_Query = 700, + T_PlannedStmt, + T_InsertStmt, + T_DeleteStmt, + T_UpdateStmt, + T_MergeStmt, + T_SelectStmt, + T_AlterTableStmt, + T_AlterTableCmd, + T_AlterDomainStmt, + T_SetOperationStmt, + T_GrantStmt, + T_GrantRoleStmt, + T_AlterDefaultPrivilegesStmt, + T_ClosePortalStmt, + T_ClusterStmt, + T_CopyStmt, + T_CreateStmt, + T_DefineStmt, + T_DropStmt, +#ifdef ENABLE_MOT + T_DropForeignStmt, +#endif + T_TruncateStmt, + T_CommentStmt, + T_FetchStmt, + T_IndexStmt, + T_CreateFunctionStmt, + T_AlterFunctionStmt, + T_DoStmt, + T_RenameStmt, + T_RuleStmt, + T_NotifyStmt, + T_ListenStmt, + T_UnlistenStmt, + T_TransactionStmt, + T_ViewStmt, + T_LoadStmt, + T_CreateDomainStmt, + T_CreatedbStmt, + T_DropdbStmt, + T_VacuumStmt, + T_ExplainStmt, + T_CreateTableAsStmt, + T_CreateSeqStmt, + T_AlterSeqStmt, + T_VariableSetStmt, + T_VariableShowStmt, + T_ShutdownStmt, + T_DiscardStmt, + T_CreateTrigStmt, + T_CreatePLangStmt, + T_CreateRoleStmt, + T_AlterRoleStmt, + T_DropRoleStmt, + T_LockStmt, + T_ConstraintsSetStmt, + T_ReindexStmt, + T_CheckPointStmt, +#ifdef PGXC + T_BarrierStmt, +#endif + T_CreateSchemaStmt, + T_AlterDatabaseStmt, + T_AlterDatabaseSetStmt, + T_AlterRoleSetStmt, + T_CreateConversionStmt, + T_CreateCastStmt, + T_CreateOpClassStmt, + T_CreateOpFamilyStmt, + T_AlterOpFamilyStmt, + T_PrepareStmt, + T_ExecuteStmt, + T_DeallocateStmt, + T_DeclareCursorStmt, + T_CreateTableSpaceStmt, + T_DropTableSpaceStmt, + T_AlterObjectSchemaStmt, + T_AlterOwnerStmt, + T_DropOwnedStmt, + T_ReassignOwnedStmt, + T_CompositeTypeStmt, + T_CreateEnumStmt, + T_CreateRangeStmt, + T_AlterEnumStmt, + T_AlterTSDictionaryStmt, + T_AlterTSConfigurationStmt, + T_CreateFdwStmt, + T_AlterFdwStmt, + T_CreateForeignServerStmt, + T_AlterForeignServerStmt, + T_CreateUserMappingStmt, + T_AlterUserMappingStmt, + T_DropUserMappingStmt, + T_ExecDirectStmt, + T_CleanConnStmt, + T_AlterTableSpaceOptionsStmt, + T_SecLabelStmt, + T_CreateForeignTableStmt, + T_CreateExtensionStmt, + T_AlterExtensionStmt, + T_AlterExtensionContentsStmt, + T_CreateDataSourceStmt, + T_AlterDataSourceStmt, + T_ReplicaIdentityStmt, + T_CreateDirectoryStmt, + T_DropDirectoryStmt, + T_CreateRlsPolicyStmt, + T_AlterRlsPolicyStmt, + T_RefreshMatViewStmt, +#ifndef ENABLE_MULTIPLE_NODES + T_AlterSystemStmt, +#endif + T_CreateWeakPasswordDictionaryStmt, + T_DropWeakPasswordDictionaryStmt, + + /* + * TAGS FOR PARSE TREE NODES (parsenodes.h) + */ + T_A_Expr = 900, + T_ColumnRef, + T_ParamRef, + T_A_Const, + T_FuncCall, + T_A_Star, + T_A_Indices, + T_A_Indirection, + T_A_ArrayExpr, + T_ResTarget, + T_TypeCast, + T_CollateClause, + T_SortBy, + T_WindowDef, + T_RangeSubselect, + T_RangeFunction, + T_RangeTableSample, + T_TypeName, + T_ColumnDef, + T_IndexElem, + T_Constraint, + T_DefElem, + T_RangeTblEntry, + T_TableSampleClause, + T_SortGroupClause, + T_GroupingSet, + T_WindowClause, + T_PrivGrantee, + T_FuncWithArgs, + T_AccessPriv, + T_CreateOpClassItem, + T_TableLikeClause, + T_FunctionParameter, + T_LockingClause, + T_RowMarkClause, + T_XmlSerialize, + T_WithClause, + T_CommonTableExpr, + T_PruningResult, + T_Position, + T_MergeWhenClause, + T_UpsertClause, + /* + * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h) + */ + T_IdentifySystemCmd, + T_IdentifyVersionCmd, + T_IdentifyModeCmd, + T_IdentifyMaxLsnCmd, + T_IdentifyConsistenceCmd, + T_IdentifyChannelCmd, + T_IdentifyAZCmd, + T_BaseBackupCmd, + T_CreateReplicationSlotCmd, + T_DropReplicationSlotCmd, + T_StartReplicationCmd, + T_StartDataReplicationCmd, + T_FetchMotCheckpointCmd, + + /* + * TAGS FOR RANDOM OTHER STUFF + * + * These are objects that aren't part of parse/plan/execute node tree + * structures, but we give them NodeTags anyway for identification + * purposes (usually because they are involved in APIs where we want to + * pass multiple object types through the same pointer). + */ + T_TriggerData = 960, /* in commands/trigger.h */ + T_ReturnSetInfo, /* in nodes/execnodes.h */ + T_WindowObjectData, /* private in nodeWindowAgg.c */ + T_TIDBitmap, /* in nodes/tidbitmap.h */ + T_InlineCodeBlock, /* in nodes/parsenodes.h */ + T_FdwRoutine, /* in foreign/fdwapi.h */ + + T_DistFdwDataNodeTask, /* in bulkload/dist_fdw.h */ + T_DistFdwFileSegment, /* in bulkload/dist_fdw.h */ + T_SplitInfo, + T_SplitMap, + T_DfsPrivateItem, + T_ErrorCacheEntry, + T_ForeignPartState, + T_RoachRoutine, /* in bulkload/roach_api.h */ + + /* + * Vectorized Plan Nodes + */ + T_VecPlan = 1000, + T_VecResult, + T_VecModifyTable, + T_VecAppend, + T_VecPartIterator, + T_VecMergeAppend, + T_VecRecursiveUnion, + T_VecScan, + T_CStoreScan, + T_DfsScan, +#ifdef ENABLE_MULTIPLE_NODES + T_TsStoreScan, +#endif /* ENABLE_MULTIPLE_NODES */ + T_VecIndexScan, + T_VecIndexOnlyScan, + T_VecBitmapIndexScan, + T_VecBitmapHeapScan, + T_VecSubqueryScan, + T_VecForeignScan, + T_VecNestLoop, + T_VecMergeJoin, + T_VecHashJoin, + T_VecMaterial, + T_VecSort, + T_VecGroup, + T_VecAgg, + T_VecWindowAgg, + T_VecUnique, + T_VecHash, + T_VecSetOp, + T_VecLockRows, + T_VecLimit, + T_VecStream, + T_RowToVec, + T_VecToRow, + T_DfsIndexScan, + T_CStoreIndexScan, + T_CStoreIndexCtidScan, + T_CStoreIndexHeapScan, + T_CStoreIndexAnd, + T_CStoreIndexOr, + T_VecRemoteQuery, + T_CBTreeScanState, + T_CBTreeOnlyScanState, + T_CstoreBitmapIndexScanState, + + /* + * Vectorized Execution Nodes + */ + T_VecToRowState = 2000, + + // this must put first for vector engine runtime state + T_VecStartState, + + T_RowToVecState, + T_VecAggState, + T_VecHashJoinState, + T_VecStreamState, + T_VecSortState, + T_VecForeignScanState, + T_CStoreScanState, + T_DfsScanState, +#ifdef ENABLE_MULTIPLE_NODES + T_TsStoreScanState, +#endif /* ENABLE_MULTIPLE_NODES */ + T_DfsIndexScanState, + T_CStoreIndexScanState, + T_CStoreIndexCtidScanState, + T_CStoreIndexHeapScanState, + T_CStoreIndexAndState, + T_CStoreIndexOrState, + T_VecRemoteQueryState, + T_VecResultState, + T_VecSubqueryScanState, + T_VecModifyTableState, + T_VecPartIteratorState, + T_VecAppendState, + T_VecLimitState, + T_VecGroupState, + T_VecUniqueState, + T_VecSetOpState, + T_VecNestLoopState, + T_VecMaterialState, + T_VecMergeJoinState, + T_VecWindowAggState, + + // this must put last for vector engine runtime state + T_VecEndState, + + /* @hdfs. support HDFS operation */ + T_HDFSTableAnalyze, + T_ForeignTableDesc, + T_AttrMetaData, + T_RelationMetaData, + T_ForeignOptions, + + /* + * @hdfs + * support infotmational constraint. + */ + T_InformationalConstraint, + T_GroupingId, + T_GroupingIdExprState, + T_BloomFilterSet, + /* Hint type. */ + T_HintState, + T_OuterInnerRels, + T_JoinMethodHint, + T_LeadingHint, + T_RowsHint, + T_StreamHint, + T_BlockNameHint, + T_ScanMethodHint, + T_MultiNodeHint, + T_PredpushHint, + T_RewriteHint, + + /* + * pgfdw + */ + T_PgFdwRemoteInfo, + + /* Create table like. */ + T_TableLikeCtx, + T_SkewHint, + + /* Skew Hint Transform Info */ + T_SkewHintTransf, + T_SkewRelInfo, + T_SkewColumnInfo, + T_SkewValueInfo, + + /* Skew Info */ + T_QualSkewInfo, + + /* Synonym */ + T_CreateSynonymStmt, + T_DropSynonymStmt, + + T_BucketInfo, + + /* Encrypted Column */ + T_ClientLogicGlobalParam, + T_CreateClientLogicGlobal, + T_ClientLogicColumnParam, + T_CreateClientLogicColumn, + T_ClientLogicColumnRef, + T_ExprWithComma +} NodeTag; + +/* if you add to NodeTag also need to add nodeTagToString */ +extern char* nodeTagToString(NodeTag tag); + +/* + * The first field of a node of any type is guaranteed to be the NodeTag. + * Hence the type of any node can be gotten by casting it to Node. Declaring + * a variable to be of Node * (instead of void *) can also facilitate + * debugging. + */ +typedef struct Node { + NodeTag type; +} Node; + +#define nodeTag(nodeptr) (((const Node*)(nodeptr))->type) + +/* + * newNode - + * create a new node of the specified size and tag the node with the + * specified tag. + * + * !WARNING!: Avoid using newNode directly. You should be using the + * macro makeNode. eg. to create a Query node, use makeNode(Query) + * + * Note: the size argument should always be a compile-time constant, so the + * apparent risk of multiple evaluation doesn't matter in practice. + */ +#ifdef __GNUC__ + +/* With GCC, we can use a compound statement within an expression */ +#ifndef FRONTEND_PARSER +#define newNode(size, tag) \ + ({ \ + Node* _result; \ + AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \ + _result = (Node*)palloc0fast(size); \ + _result->type = (tag); \ + _result; \ + }) +#else // !FRONTEND_PARSER +#define newNode(size, tag) \ + ({ \ + Node *_result; \ + AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \ + _result = (Node *)feparser_malloc0(size); \ + _result->type = (tag); \ + _result; \ + }) +#endif // !FRONTEND_PARSER +#else + +#define newNode(size, tag) \ + (AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \ + t_thrd.utils_cxt.newNodeMacroHolder = (Node*)palloc0fast(size), \ + t_thrd.utils_cxt.newNodeMacroHolder->type = (tag), \ + t_thrd.utils_cxt.newNodeMacroHolder) +#endif /* __GNUC__ */ + +#define makeNode(_type_) ((_type_*)newNode(sizeof(_type_), T_##_type_)) +#define makeNodeWithSize(_type_, _size) ((_type_*)newNode(_size, T_##_type_)) + +#define NodeSetTag(nodeptr, t) (((Node*)(nodeptr))->type = (t)) + +#define IsA(nodeptr, _type_) (nodeTag(nodeptr) == T_##_type_) + +/* + * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled, + * verifies that the node has the appropriate type (using its nodeTag()). + * + * Use an inline function when assertions are enabled, to avoid multiple + * evaluations of the ptr argument (which could e.g. be a function call). + * iIf inline functions are not available - only a small number of platforms - + * don't Assert, but use the non-checking version. + */ +#if defined(USE_ASSERT_CHECKING) && defined(PG_USE_INLINE) +static inline Node* castNodeImpl(NodeTag type, void* ptr) +{ + Assert(ptr == NULL || nodeTag(ptr) == type); + return (Node*)ptr; +} +#define castNode(_type_, nodeptr) ((_type_*)castNodeImpl(T_##_type_, nodeptr)) +#else +#define castNode(_type_, nodeptr) ((_type_*)(nodeptr)) +#endif /* USE_ASSERT_CHECKING && PG_USE_INLINE */ + +/* ---------------------------------------------------------------- + * extern declarations follow + * ---------------------------------------------------------------- + */ + +/* + * nodes/{outfuncs.c,print.c} + */ +extern char* nodeToString(const void* obj); +extern void appendBitmapsetToString(void* str, void* bms); + +/* + * nodes/{readfuncs.c,read.c} + */ +extern void* stringToNode(char* str); + +extern void* stringToNode_skip_extern_fields(char* str); + +/* + * nodes/copyfuncs.c + */ +extern void* copyObject(const void* obj); + +/* + * nodes/equalfuncs.c + */ +extern bool _equalSimpleVar(void* va, void* vb); +extern bool equal(const void* a, const void* b); + +/* + * Typedefs for identifying qualifier selectivities and plan costs as such. + * These are just plain "double"s, but declaring a variable as Selectivity + * or Cost makes the intent more obvious. + * + * These could have gone into plannodes.h or some such, but many files + * depend on them... + */ +typedef double Selectivity; /* fraction of tuples a qualifier will pass */ +typedef double Cost; /* execution cost (in page-access units) */ + +/* + * CmdType - + * enums for type of operation represented by a Query or PlannedStmt + * + * This is needed in both parsenodes.h and plannodes.h, so put it here... + */ +typedef enum CmdType { + CMD_UNKNOWN, + CMD_SELECT, /* select stmt */ + CMD_UPDATE, /* update stmt */ + CMD_INSERT, /* insert stmt */ + CMD_DELETE, /* delete stmt */ + CMD_MERGE, /* merge stmt */ + CMD_UTILITY, /* cmds like create, destroy, copy, vacuum, + * etc. */ + CMD_PREPARE, /* prepare stmt */ + CMD_DEALLOCATE, /* deallocate stmt*/ + CMD_EXECUTE, /* execure stmt*/ + CMD_TRUNCATE, /* truncate table*/ + CMD_REINDEX, /* reindex table/index*/ + CMD_NOTHING, /* dummy command for instead nothing rules + * with qual */ + CMD_DDL, + CMD_DCL, + CMD_DML, + CMD_TCL +} CmdType; + +/* + * JoinType - + * enums for types of relation joins + * + * JoinType determines the exact semantics of joining two relations using + * a matching qualification. For example, it tells what to do with a tuple + * that has no match in the other relation. + * + * This is needed in both parsenodes.h and plannodes.h, so put it here... + */ +typedef enum JoinType { + /* + * The canonical kinds of joins according to the SQL JOIN syntax. Only + * these codes can appear in parser output (e.g., JoinExpr nodes). + */ + JOIN_INNER, /* matching tuple pairs only */ + JOIN_LEFT, /* pairs + unmatched LHS tuples */ + JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */ + JOIN_RIGHT, /* pairs + unmatched RHS tuples */ + + /* + * Semijoins and anti-semijoins (as defined in relational theory) do not + * appear in the SQL JOIN syntax, but there are standard idioms for + * representing them (e.g., using EXISTS). The planner recognizes these + * cases and converts them to joins. So the planner and executor must + * support these codes. NOTE: in JOIN_SEMI output, it is unspecified + * which matching RHS row is joined to. In JOIN_ANTI output, the row is + * guaranteed to be null-extended. + */ + JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */ + JOIN_ANTI, /* 1 copy of each LHS row that has no match */ + + /* + * These codes are used internally in the planner, but are not supported + * by the executor (nor, indeed, by most of the planner). + */ + JOIN_UNIQUE_OUTER, /* LHS path must be made unique */ + JOIN_UNIQUE_INNER, /* RHS path must be made unique */ + + JOIN_RIGHT_SEMI, /* Right Semi Join */ + JOIN_RIGHT_ANTI, /* Right Anti join */ + + JOIN_LEFT_ANTI_FULL, /* unmatched LHS tuples */ + JOIN_RIGHT_ANTI_FULL /* unmatched RHS tuples */ + + /* + * We might need additional join types someday. + */ +} JoinType; + +/* + * OUTER joins are those for which pushed-down quals must behave differently + * from the join's own quals. This is in fact everything except INNER and + * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols + * since those are temporary proxies for what will eventually be an INNER + * join. + * + * Note: semijoins are a hybrid case, but we choose to treat them as not + * being outer joins. This is okay principally because the SQL syntax makes + * it impossible to have a pushed-down qual that refers to the inner relation + * of a semijoin; so there is no strong need to distinguish join quals from + * pushed-down quals. This is convenient because for almost all purposes, + * quals attached to a semijoin can be treated the same as innerjoin quals. + * + * We treat right semijoins/antijoins as semijoins/antijoins being treated. + */ +#define IS_OUTER_JOIN(jointype) \ + (((1 << (jointype)) & ((1 << JOIN_LEFT) | (1 << JOIN_FULL) | (1 << JOIN_RIGHT) | (1 << JOIN_ANTI) | \ + (1 << JOIN_RIGHT_ANTI) | (1 << JOIN_LEFT_ANTI_FULL) | (1 << JOIN_RIGHT_ANTI_FULL))) != \ + 0) + +typedef enum UpsertAction +{ + UPSERT_NONE, /* No "DUPLICATE KEY UPDATE" clause */ + UPSERT_NOTHING, /* DUPLICATE KEY UPDATE NOTHING */ + UPSERT_UPDATE /* DUPLICATE KEY UPDATE ... */ +}UpsertAction; + +#endif /* NODES_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/params.h postgresql-hll-2.14/include/include/nodes/params.h --- postgresql-hll-2.14_old/include/include/nodes/params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/params.h 2020-12-12 17:06:43.231347832 +0800 @@ -0,0 +1,116 @@ +/* ------------------------------------------------------------------------- + * + * params.h + * Support for finding the values associated with Param nodes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/params.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARAMS_H +#define PARAMS_H + +/* To avoid including a pile of parser headers, reference ParseState thus: */ +struct ParseState; + +/* ---------------- + * ParamListInfo + * + * ParamListInfo arrays are used to pass parameters into the executor + * for parameterized plans. Each entry in the array defines the value + * to be substituted for a PARAM_EXTERN parameter. The "paramid" + * of a PARAM_EXTERN Param can range from 1 to numParams. + * + * Although parameter numbers are normally consecutive, we allow + * ptype == InvalidOid to signal an unused array entry. + * + * pflags is a flags field. Currently the only used bit is: + * PARAM_FLAG_CONST signals the planner that it may treat this parameter + * as a constant (i.e., generate a plan that works only for this value + * of the parameter). + * + * There are two hook functions that can be associated with a ParamListInfo + * array to support dynamic parameter handling. First, if paramFetch + * isn't null and the executor requires a value for an invalid parameter + * (one with ptype == InvalidOid), the paramFetch hook is called to give + * it a chance to fill in the parameter value. Second, a parserSetup + * hook can be supplied to re-instantiate the original parsing hooks if + * a query needs to be re-parsed/planned (as a substitute for supposing + * that the current ptype values represent a fixed set of parameter types). + + * Although the data structure is really an array, not a list, we keep + * the old typedef name to avoid unnecessary code changes. + * ---------------- + */ +#define PARAM_FLAG_CONST 0x0001 /* parameter is constant */ + +typedef struct Cursor_Data { + int row_count; + int cur_dno; + bool is_open; + bool found; + bool not_found; + bool null_open; + bool null_fetch; +} Cursor_Data; + +typedef struct ParamExternData { + Datum value; /* parameter value */ + bool isnull; /* is it NULL? */ + uint16 pflags; /* flag bits, see above */ + Oid ptype; /* parameter's datatype, or 0 */ + Cursor_Data cursor_data; +} ParamExternData; + +typedef struct ParamListInfoData* ParamListInfo; + +typedef void (*ParamFetchHook)(ParamListInfo params, int paramid); + +typedef void (*ParserSetupHook)(struct ParseState* pstate, void* arg); + +typedef struct ParamListInfoData { + ParamFetchHook paramFetch; /* parameter fetch hook */ + void* paramFetchArg; + ParserSetupHook parserSetup; /* parser setup hook */ + void* parserSetupArg; + int numParams; /* number of ParamExternDatas following */ + bool params_need_process; + ParamExternData params[FLEXIBLE_ARRAY_MEMBER]; +} ParamListInfoData; + +/* ---------------- + * ParamExecData + * + * ParamExecData entries are used for executor internal parameters + * (that is, values being passed into or out of a sub-query). The + * paramid of a PARAM_EXEC Param is a (zero-based) index into an + * array of ParamExecData records, which is referenced through + * es_param_exec_vals or ecxt_param_exec_vals. + * + * If execPlan is not NULL, it points to a SubPlanState node that needs + * to be executed to produce the value. (This is done so that we can have + * lazy evaluation of InitPlans: they aren't executed until/unless a + * result value is needed.) Otherwise the value is assumed to be valid + * when needed. + * ---------------- + */ +typedef struct ParamExecData { + void* execPlan; /* should be "SubPlanState *" */ + Oid valueType; + Datum value; + bool isnull; + void* paramVector; + bool isChanged; + bool isConst; /* for init plan , no need to build scalarvector everytime */ +} ParamExecData; + +enum { CURSOR_ISOPEN = 1, CURSOR_FOUND, CURSOR_NOTFOUND, CURSOR_ROWCOUNT }; + +/* Functions found in src/backend/nodes/params.c */ +extern ParamListInfo copyParamList(ParamListInfo from); + +#endif /* PARAMS_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/parsenodes_common.h postgresql-hll-2.14/include/include/nodes/parsenodes_common.h --- postgresql-hll-2.14_old/include/include/nodes/parsenodes_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/parsenodes_common.h 2020-12-12 17:06:43.231347832 +0800 @@ -0,0 +1,1724 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * parsenodes_common.h + * + * IDENTIFICATION + * src\include\nodes\parsenodes_common.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PARSENODES_COMMON_H +#define PARSENODES_COMMON_H + +#ifdef FRONTEND_PARSER +#include "postgres_fe.h" +#endif + +#include "datatypes.h" +#include "nodes/params.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "client_logic/client_logic_enums.h" +/* + * When a command can act on several kinds of objects with only one + * parse structure required, use these constants to designate the + * object type. Note that commands typically don't support all the types. + */ +typedef enum ObjectType { + OBJECT_AGGREGATE, + OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */ + OBJECT_CAST, + OBJECT_COLUMN, + OBJECT_CONSTRAINT, + OBJECT_CONTQUERY, + OBJECT_COLLATION, + OBJECT_CONVERSION, + OBJECT_DATABASE, + OBJECT_DATA_SOURCE, + OBJECT_DOMAIN, + OBJECT_EXTENSION, + OBJECT_FDW, + OBJECT_FOREIGN_SERVER, + OBJECT_FOREIGN_TABLE, + OBJECT_FUNCTION, + OBJECT_INDEX, + OBJECT_INDEX_PARTITION, + OBJECT_INTERNAL, + OBJECT_INTERNAL_PARTITION, + OBJECT_LANGUAGE, + OBJECT_LARGEOBJECT, + OBJECT_MATVIEW, + OBJECT_OPCLASS, + OBJECT_OPERATOR, + OBJECT_OPFAMILY, + OBJECT_PARTITION, + OBJECT_RLSPOLICY, + OBJECT_PARTITION_INDEX, + OBJECT_ROLE, + OBJECT_RULE, + OBJECT_SCHEMA, + OBJECT_SEQUENCE, + OBJECT_STREAM, + OBJECT_SYNONYM, + OBJECT_TABLE, + OBJECT_TABLE_PARTITION, + OBJECT_TABLESPACE, + OBJECT_TRIGGER, + OBJECT_TSCONFIGURATION, + OBJECT_TSDICTIONARY, + OBJECT_TSPARSER, + OBJECT_TSTEMPLATE, + OBJECT_TYPE, + OBJECT_USER, + OBJECT_VIEW, + OBJECT_DIRECTORY, + OBJECT_GLOBAL_SETTING, + OBJECT_COLUMN_SETTING +} ObjectType; + +typedef enum DropBehavior { + DROP_RESTRICT, /* drop fails if any dependent objects */ + DROP_CASCADE /* remove dependent objects too */ +} DropBehavior; +/* ---------------------- + * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement + * ---------------------- + */ + +typedef struct DropStmt { + NodeTag type; + List *objects; /* list of sublists of names (as Values) */ + List *arguments; /* list of sublists of arguments (as Values) */ + ObjectType removeType; /* object type */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing_ok; /* skip error if object is missing? */ + bool concurrent; /* drop index concurrently? */ + bool isProcedure; /* true if it is DROP PROCEDURE */ +} DropStmt; + +/* + * TypeName - specifies a type in definitions + * + * For TypeName structures generated internally, it is often easier to + * specify the type by OID than by name. If "names" is NIL then the + * actual type OID is given by typeOid, otherwise typeOid is unused. + * Similarly, if "typmods" is NIL then the actual typmod is expected to + * be prespecified in typemod, otherwise typemod is unused. + * + * If pct_type is TRUE, then names is actually a field name and we look up + * the type of that field. Otherwise (the normal case), names is a type + * name possibly qualified with schema and database name. + */ +typedef struct TypeName { + NodeTag type; + List *names; /* qualified name (list of Value strings) */ + Oid typeOid; /* type identified by OID */ + bool setof; /* is a set? */ + bool pct_type; /* %TYPE specified? */ + List *typmods; /* type modifier expression(s) */ + int32 typemod; /* prespecified type modifier */ + List *arrayBounds; /* array bounds */ + int location; /* token location, or -1 if unknown */ +} TypeName; + +typedef enum FunctionParameterMode { + /* the assigned enum values appear in pg_proc, don't change 'em! */ + FUNC_PARAM_IN = 'i', /* input only */ + FUNC_PARAM_OUT = 'o', /* output only */ + FUNC_PARAM_INOUT = 'b', /* both */ + FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */ + FUNC_PARAM_TABLE = 't' /* table function output column */ +} FunctionParameterMode; + +typedef struct FunctionParameter { + NodeTag type; + char *name; /* parameter name, or NULL if not given */ + TypeName *argType; /* TypeName for parameter type */ + FunctionParameterMode mode; /* IN/OUT/etc */ + Node *defexpr; /* raw default expr, or NULL if not given */ +} FunctionParameter; + +/* + * Note: FuncWithArgs carries only the types of the input parameters of the + * function. So it is sufficient to identify an existing function, but it + * is not enough info to define a function nor to call it. + */ +typedef struct FuncWithArgs { + NodeTag type; + List *funcname; /* qualified name of function */ + List *funcargs; /* list of Typename nodes */ +} FuncWithArgs; + +/* + * DefElem - a generic "name = value" option definition + * + * In some contexts the name can be qualified. Also, certain SQL commands + * allow a SET/ADD/DROP action to be attached to option settings, so it's + * convenient to carry a field for that too. (Note: currently, it is our + * practice that the grammar allows namespace and action only in statements + * where they are relevant; C code can just ignore those fields in other + * statements.) + */ +typedef enum DefElemAction { + DEFELEM_UNSPEC, /* no action given */ + DEFELEM_SET, + DEFELEM_ADD, + DEFELEM_DROP +} DefElemAction; + +typedef struct DefElem { + NodeTag type; + char *defnamespace; /* NULL if unqualified name */ + char *defname; + Node *arg; /* a (Value *) or a (TypeName *) */ + DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ +} DefElem; + +typedef enum SortByDir { + SORTBY_DEFAULT, + SORTBY_ASC, + SORTBY_DESC, + SORTBY_USING /* not allowed in CREATE INDEX ... */ +} SortByDir; + +typedef enum SortByNulls { + SORTBY_NULLS_DEFAULT, + SORTBY_NULLS_FIRST, + SORTBY_NULLS_LAST +} SortByNulls; + +/* + * SortBy - for ORDER BY clause + */ +typedef struct SortBy { + NodeTag type; + Node *node; /* expression to sort on */ + SortByDir sortby_dir; /* ASC/DESC/USING/default */ + SortByNulls sortby_nulls; /* NULLS FIRST/LAST */ + List *useOp; /* name of op to use, if SORTBY_USING */ + int location; /* operator location, or -1 if none/unknown */ +} SortBy; + +/* + * WindowDef - raw representation of WINDOW and OVER clauses + * + * For entries in a WINDOW list, "name" is the window name being defined. + * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname" + * for the "OVER (window)" syntax, which is subtly different --- the latter + * implies overriding the window frame clause. + */ +typedef struct WindowDef { + NodeTag type; + char *name; /* window's own name */ + char *refname; /* referenced window name, if any */ + List *partitionClause; /* PARTITION BY expression list */ + List *orderClause; /* ORDER BY (list of SortBy) */ + int frameOptions; /* frame_clause options, see below */ + Node *startOffset; /* expression for starting bound, if any */ + Node *endOffset; /* expression for ending bound, if any */ + int location; /* parse location, or -1 if none/unknown */ +} WindowDef; + +/* + * IndexElem - index parameters (used in CREATE INDEX) + * + * For a plain index attribute, 'name' is the name of the table column to + * index, and 'expr' is NULL. For an index expression, 'name' is NULL and + * 'expr' is the expression tree. + */ +typedef struct IndexElem { + NodeTag type; + char *name; /* name of attribute to index, or NULL */ + Node *expr; /* expression to index, or NULL */ + char *indexcolname; /* name for index column; NULL = default */ + List *collation; /* name of collation; NIL = default */ + List *opclass; /* name of desired opclass; NIL = default */ + SortByDir ordering; /* ASC/DESC/default */ + SortByNulls nulls_ordering; /* FIRST/LAST/default */ +} IndexElem; + +/* + * WithClause - + * representation of WITH clause + * + * Note: WithClause does not propagate into the Query representation; + * but CommonTableExpr does. + */ +typedef struct WithClause { + NodeTag type; + List *ctes; /* list of CommonTableExprs */ + bool recursive; /* true = WITH RECURSIVE */ + int location; /* token location, or -1 if unknown */ +} WithClause; + +/* + * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx]) + */ +typedef struct A_Indices { + NodeTag type; + Node *lidx; /* NULL if it's a single subscript */ + Node *uidx; +} A_Indices; + +/* + * ResTarget - + * result target (used in target list of pre-transformed parse trees) + * + * In a SELECT target list, 'name' is the column label from an + * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the + * value expression itself. The 'indirection' field is not used. + * + * INSERT uses ResTarget in its target-column-names list. Here, 'name' is + * the name of the destination column, 'indirection' stores any subscripts + * attached to the destination, and 'val' is not used. + * + * In an UPDATE target list, 'name' is the name of the destination column, + * 'indirection' stores any subscripts attached to the destination, and + * 'val' is the expression to assign. + * + * See A_Indirection for more info about what can appear in 'indirection'. + */ +typedef struct ResTarget { + NodeTag type; + char *name; /* column name or NULL */ + List *indirection; /* subscripts, field names, and '*', or NIL */ + Node *val; /* the value expression to compute or assign */ + int location; /* token location, or -1 if unknown */ +} ResTarget; + +/* + * Describes a context of hint processing. + */ +typedef struct HintState { + NodeTag type; + + int nall_hints; /* Hint num */ + List* join_hint; /* Join hint list */ + List* leading_hint; /* Leading hint list */ + List* row_hint; /* Rows hint list */ + List* stream_hint; /* stream hint list */ + List* block_name_hint; /* block name hint list */ + List* scan_hint; /* scan hint list */ + List* skew_hint; /* skew hint list */ + List* hint_warning; /* hint warning list */ + bool multi_node_hint; /* multinode hint */ + List* predpush_hint; + List* rewrite_hint; /* rewrite hint list */ +} HintState; + +/* ---------------------- + * Insert Statement + * + * The source expression is represented by SelectStmt for both the + * SELECT and VALUES cases. If selectStmt is NULL, then the query + * is INSERT ... DEFAULT VALUES. + * ---------------------- + */ + +typedef struct UpsertClause { + NodeTag type; + List *targetList; + int location; +} UpsertClause; + +typedef struct InsertStmt { + NodeTag type; + RangeVar *relation; /* relation to insert into */ + List *cols; /* optional: names of the target columns */ + Node *selectStmt; /* the source SELECT/VALUES, or NULL */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + UpsertClause *upsertClause; /* DUPLICATE KEY UPDATE clause */ + HintState *hintState; + bool isRewritten; /* is this Stmt created by rewritter or end user? */ +} InsertStmt; + +/* ---------------------- + * Delete Statement + * ---------------------- + */ +typedef struct DeleteStmt { + NodeTag type; + RangeVar *relation; /* relation to delete from */ + List *usingClause; /* optional using clause for more tables */ + Node *whereClause; /* qualifications */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + HintState *hintState; + Node *limitClause; /* limit row count */ +} DeleteStmt; + +/* ---------------------- + * Update Statement + * ---------------------- + */ +typedef struct UpdateStmt { + NodeTag type; + RangeVar *relation; /* relation to update */ + List *targetList; /* the target list (of ResTarget) */ + Node *whereClause; /* qualifications */ + List *fromClause; /* optional from clause for more tables */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + HintState *hintState; +} UpdateStmt; + +/* ---------------------- + * PREPARE Statement + * ---------------------- + */ +typedef struct PrepareStmt { + NodeTag type; + char *name; /* Name of plan, arbitrary */ + List *argtypes; /* Types of parameters (List of TypeName) */ + Node *query; /* The query itself (as a raw parsetree) */ +} PrepareStmt; + + +/* ---------------------- + * EXECUTE Statement + * ---------------------- + */ + +typedef struct ExecuteStmt { + NodeTag type; + char *name; /* The name of the plan to execute */ + List *params; /* Values to assign to parameters */ +} ExecuteStmt; + +/* ---------------------- + * SET Statement (includes RESET) + * + * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we + * preserve the distinction in VariableSetKind for CreateCommandTag(). + * ---------------------- + */ +typedef enum { + VAR_SET_VALUE, /* SET var = value */ + VAR_SET_DEFAULT, /* SET var TO DEFAULT */ + VAR_SET_CURRENT, /* SET var FROM CURRENT */ + VAR_SET_MULTI, /* special case for SET TRANSACTION ... */ + VAR_SET_ROLEPWD, /* special case for SET ROLE PASSWORD... */ + VAR_RESET, /* RESET var */ + VAR_RESET_ALL /* RESET ALL */ +} VariableSetKind; + +typedef struct VariableSetStmt { + NodeTag type; + VariableSetKind kind; + char *name; /* variable to be set */ + List *args; /* List of A_Const nodes */ + bool is_local; /* SET LOCAL? */ +} VariableSetStmt; + +typedef struct AlterRoleSetStmt { + NodeTag type; + char *role; /* role name */ + char *database; /* database name, or NULL */ + VariableSetStmt *setstmt; /* SET or RESET subcommand */ +} AlterRoleSetStmt; + + +typedef struct AlterDatabaseSetStmt { + NodeTag type; + char *dbname; /* database name */ + VariableSetStmt *setstmt; /* SET or RESET subcommand */ +} AlterDatabaseSetStmt; + +/* + * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar + * output. After parse analysis it's set to null, and the Query points to the + * DeclareCursorStmt, not vice versa. + * ---------------------- + */ +#define CURSOR_OPT_BINARY 0x0001 /* BINARY */ +#define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */ +#define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */ +#define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */ +#define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */ +/* these planner-control flags do not correspond to any SQL grammar: */ +#define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */ +#define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */ +#define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */ + +typedef struct DeclareCursorStmt { + NodeTag type; + char *portalname; /* name of the portal (cursor) */ + int options; /* bitmask of options (see above) */ + Node *query; /* the raw SELECT query */ +} DeclareCursorStmt; + +/* ---------------------- + * Select Statement + * + * A "simple" SELECT is represented in the output of gram.y by a single + * SelectStmt node; so is a VALUES construct. A query containing set + * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt + * nodes, in which the leaf nodes are component SELECTs and the internal nodes + * represent UNION, INTERSECT, or EXCEPT operators. Using the same node + * type for both leaf and internal nodes allows gram.y to stick ORDER BY, + * LIMIT, etc, clause values into a SELECT statement without worrying + * whether it is a simple or compound SELECT. + * ---------------------- + */ +typedef enum SetOperation { + SETOP_NONE = 0, + SETOP_UNION, + SETOP_INTERSECT, + SETOP_EXCEPT +} SetOperation; + +typedef struct SelectStmt { + NodeTag type; + + /* + * These fields are used only in "leaf" SelectStmts. + */ + List *distinctClause; /* NULL, list of DISTINCT ON exprs, or + * lcons(NIL,NIL) for all (SELECT DISTINCT) */ + IntoClause *intoClause; /* target for SELECT INTO */ + List *targetList; /* the target list (of ResTarget) */ + List *fromClause; /* the FROM clause */ + Node *whereClause; /* WHERE qualification */ + List *groupClause; /* GROUP BY clauses */ + Node *havingClause; /* HAVING conditional-expression */ + List *windowClause; /* WINDOW window_name AS (...), ... */ + WithClause *withClause; /* WITH clause */ + + /* + * In a "leaf" node representing a VALUES list, the above fields are all + * null, and instead this field is set. Note that the elements of the + * sublists are just expressions, without ResTarget decoration. Also note + * that a list element can be DEFAULT (represented as a SetToDefault + * node), regardless of the context of the VALUES list. It's up to parse + * analysis to reject that where not valid. + */ + List *valuesLists; /* untransformed list of expression lists */ + + /* + * These fields are used in both "leaf" SelectStmts and upper-level + * SelectStmts. + */ + List *sortClause; /* sort clause (a list of SortBy's) */ + Node *limitOffset; /* # of result tuples to skip */ + Node *limitCount; /* # of result tuples to return */ + List *lockingClause; /* FOR UPDATE (list of LockingClause's) */ + HintState *hintState; + + /* + * These fields are used only in upper-level SelectStmts. + */ + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + struct SelectStmt *larg; /* left child */ + struct SelectStmt *rarg; /* right child */ + + /* + * These fields are used by operator "(+)" + */ + bool hasPlus; + /* Eventually add fields for CORRESPONDING spec here */ +} SelectStmt; + +/* + * CollateClause - a COLLATE expression + */ +typedef struct CollateClause { + NodeTag type; + Node *arg; /* input expression */ + List *collname; /* possibly-qualified collation name */ + int location; /* token location, or -1 if unknown */ +} CollateClause; + +/* ---------------------- + * Create Schema Statement + * + * NOTE: the schemaElts list contains raw parsetrees for component statements + * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and + * executed after the schema itself is created. + * ---------------------- + */ +typedef enum TempType { + Temp_None, + Temp_Rel, + Temp_Toast +} TempType; + +typedef struct CreateSchemaStmt { + NodeTag type; + char *schemaname; /* the name of the schema to create */ + char *authid; /* the owner of the created schema */ + List *schemaElts; /* schema components (list of parsenodes) */ + TempType temptype; /* if the schema is temp table's schema */ + List *uuids; /* the list of uuid(only create sequence or table with serial type need) */ +} CreateSchemaStmt; + +/* ---------------------- + * Alter Table + * ---------------------- + */ +typedef struct AlterTableStmt { + NodeTag type; + RangeVar *relation; /* table to work on */ + List *cmds; /* list of subcommands */ + ObjectType relkind; /* type of object */ + bool missing_ok; /* skip error if table missing */ + bool fromCreate; /* from create stmt */ + bool need_rewrite_sql; /* after rewrite rule, need to rewrite query string */ +} AlterTableStmt; + +typedef enum AlterTableType { + AT_AddColumn, /* add column */ + AT_AddColumnRecurse, /* internal to commands/tablecmds.c */ + AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */ + AT_AddPartition, + AT_ColumnDefault, /* alter column default */ + AT_DropNotNull, /* alter column drop not null */ + AT_SetNotNull, /* alter column set not null */ + AT_SetStatistics, /* alter column set statistics */ + AT_AddStatistics, /* alter column add statistics */ + AT_DeleteStatistics, /* alter column delete statistics */ + AT_SetOptions, /* alter column set ( options ) */ + AT_ResetOptions, /* alter column reset ( options ) */ + AT_SetStorage, /* alter column set storage */ + AT_DropColumn, /* drop column */ + AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ + AT_DropPartition, + AT_AddIndex, /* add index */ + AT_ReAddIndex, /* internal to commands/tablecmds.c */ + AT_AddConstraint, /* add constraint */ + AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_ValidateConstraint, /* validate constraint */ + AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_ProcessedConstraint, /* pre-processed add constraint (local in + * parser/parse_utilcmd.c) */ + AT_AddIndexConstraint, /* add constraint using existing index */ + AT_DropConstraint, /* drop constraint */ + AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_AlterColumnType, /* alter column type */ + AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */ + AT_ChangeOwner, /* change owner */ + AT_ClusterOn, /* CLUSTER ON */ + AT_DropCluster, /* SET WITHOUT CLUSTER */ + AT_AddOids, /* SET WITH OIDS */ + AT_AddOidsRecurse, /* internal to commands/tablecmds.c */ + AT_DropOids, /* SET WITHOUT OIDS */ + AT_SetTableSpace, /* SET TABLESPACE */ + AT_SetPartitionTableSpace, /* SET TABLESPACE FOR PARTITION */ + AT_SetRelOptions, /* SET (...) -- AM specific parameters */ + AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */ + AT_ReplaceRelOptions, /* replace reloption list in its entirety */ + AT_UnusableIndex, + AT_UnusableIndexPartition, + AT_UnusableAllIndexOnPartition, + AT_RebuildIndex, + AT_RebuildIndexPartition, + AT_RebuildAllIndexOnPartition, + AT_EnableTrig, /* ENABLE TRIGGER name */ + AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */ + AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */ + AT_DisableTrig, /* DISABLE TRIGGER name */ + AT_EnableTrigAll, /* ENABLE TRIGGER ALL */ + AT_DisableTrigAll, /* DISABLE TRIGGER ALL */ + AT_EnableTrigUser, /* ENABLE TRIGGER USER */ + AT_DisableTrigUser, /* DISABLE TRIGGER USER */ + AT_EnableRule, /* ENABLE RULE name */ + AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */ + AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */ + AT_DisableRule, /* DISABLE RULE name */ + AT_EnableRls, /* ENABLE ROW LEVEL SECURITY */ + AT_DisableRls, /* DISABLE ROW LEVEL SECURITY */ + AT_ForceRls, /* FORCE ROW LEVEL SECURITY */ + AT_NoForceRls, /* NO FORCE ROW LEVEL SECURITY */ + AT_AddInherit, /* INHERIT parent */ + AT_DropInherit, /* NO INHERIT parent */ + AT_AddOf, /* OF */ + AT_DropOf, /* NOT OF */ + AT_ReplicaIdentity, /* REPLICA IDENTITY */ + AT_SET_COMPRESS, /* SET COMPRESS/NOCOMPRESS */ +#ifdef PGXC + AT_DistributeBy, /* DISTRIBUTE BY ... */ + AT_SubCluster, /* TO [ NODE nodelist | GROUP groupname ] */ + AT_AddNodeList, /* ADD NODE nodelist */ + AT_DeleteNodeList, /* DELETE NODE nodelist */ +#endif + AT_GenericOptions, /* OPTIONS (...) */ + AT_EnableRowMoveMent, + AT_DisableRowMoveMent, + AT_TruncatePartition, + AT_ExchangePartition, /* ALTER TABLE EXCHANGE PARTITION WITH TABLE */ + AT_MergePartition, /* MERGE PARTITION */ + AT_SplitPartition, /* SPLIT PARTITION */ + /* this will be in a more natural position in 9.3: */ + AT_ReAddConstraint /* internal to commands/tablecmds.c */ +} AlterTableType; + +typedef enum AlterTableStatProperty { /* Additional Property for AlterTableCmd */ + AT_CMD_WithPercent, /* ALTER TABLE ALTER COLUMN SET STATISTICS PERCENT */ + AT_CMD_WithoutPercent /* ALTER TABLE ALTER COLUMN SET STATISTICS */ +} AlterTableStatProperty; + +typedef struct AlterTableCmd { /* one subcommand of an ALTER TABLE */ + NodeTag type; + AlterTableType subtype; /* Type of table alteration to apply */ + char *name; /* column, constraint, or trigger to act on, + * or new owner or tablespace */ + Node *def; /* definition of new column, index, + * constraint, or parent table */ + DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ + bool missing_ok; /* skip error if missing? */ + RangeVar *exchange_with_rel; /* the ordinary table of exchange with */ + bool check_validation; /* Checking the tuple of ordinary table + whether can insert into the partition */ + bool exchange_verbose; /* When check_validation is true, if tuple + of ordinary table can not insert into + the partition, insert the tuple the right partition */ + char *target_partition_tablespace; /* using in merge partition */ + AlterTableStatProperty additional_property; /* additional property for AlterTableCmd */ + List *bucket_list; /* bucket list to drop */ + bool alterGPI; /* check whether is global partition index alter statement */ +} AlterTableCmd; + +/* ---------------------- + * REINDEX Statement + * ---------------------- + */ + +/* struct for adaptive memory allocation for specific utility */ +typedef struct AdaptMem { + int work_mem; /* estimate mem for the utility */ + int max_mem; /* max spread mem for the utility */ +} AdaptMem; + +typedef struct ReindexStmt { + NodeTag type; + ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_INTERNAL, OBJECT_DATABASE */ + RangeVar *relation; /* Table or index to reindex */ + const char *name; /* name of database to reindex */ + bool do_system; /* include system tables in database case */ + bool do_user; /* include user tables in database case */ + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ +} ReindexStmt; + +typedef struct Position { + NodeTag type; + char *colname; /* name of column */ + int fixedlen; + int position; +} Position; + +/* ------------------------------------------- + * Create Row Level Security Policy Statement + * ------------------------------------------- + */ +typedef struct CreateRlsPolicyStmt { + NodeTag type; + bool isPermissive; /* restrictive or permissive policy */ + bool fromExternal; /* this command from external(user) or internal(system) */ + char *policyName; /* Policy's name */ + RangeVar *relation; /* the table name the policy applies to */ + char *cmdName; /* the command name the policy applies to */ + List *roleList; /* the roles associated with the policy */ + Node *usingQual; /* the policy's condition */ +} CreateRlsPolicyStmt; + +/* ------------------------------------------ + * Alter Row Level Security Policy Statement + * ------------------------------------------ + */ +typedef struct AlterRlsPolicyStmt { + NodeTag type; + char *policyName; /* Policy's name */ + RangeVar *relation; /* the table name the policy applies to */ + List *roleList; /* the roles associated with the policy */ + Node *usingQual; /* the policy's condition */ +} AlterPolicyStmt; + +// CLIENT_LOGIC GLOBAL_SETTINGS +typedef enum class ClientLogicGlobalProperty { + CLIENT_GLOBAL_FUNCTION, + CLIENT_GLOBAL_ARGS, + CMK_KEY_STORE, + CMK_KEY_PATH, + CMK_ALGORITHM +} ClientLogicGlobalProperty; + + +typedef struct ClientLogicGlobalParam { + NodeTag type; + ClientLogicGlobalProperty key; + char *value; + unsigned int len; + int location; /* token location, or -1 if unknown */ +} ClientLogicGlobalParam; + + +typedef struct CreateClientLogicGlobal { + NodeTag type; + List *global_key_name; + List *global_setting_params; +} CreateClientLogicGlobal; + +// CLIENT_LOGIC COLUMN_SETTINGS +typedef enum class ClientLogicColumnProperty { + CLIENT_GLOBAL_SETTING, + CEK_ALGORITHM, + CEK_EXPECTED_VALUE, + COLUMN_ENCRYPTION_TYPE, + COLUMN_COLUMN_FUNCTION, + COLUMN_COLUMN_ARGS +} ClientLogicColumnProperty; + +typedef struct ClientLogicColumnParam { + NodeTag type; + ClientLogicColumnProperty key; + char *value; + unsigned int len; + List *qualname; + int location; /* token location, or -1 if unknown */ +} ClientLogicColumnParam; + +typedef struct CreateClientLogicColumn { + NodeTag type; + List *column_key_name; + List *column_setting_params; +} CreateClientLogicColumn; + +typedef struct ClientLogicColumnRef { + NodeTag type; + EncryptionType columnEncryptionAlgorithmType; + List *column_key_name; + TypeName *orig_typname; /* original type of column */ + TypeName *dest_typname; /* real type of column */ + int location; /* token location, or -1 if unknown */ + Oid encryptionoid; +} ClientLogicColumnRef; +/* + * ColumnDef - column definition (used in various creates) + * + * If the column has a default value, we may have the value expression + * in either "raw" form (an untransformed parse tree) or "cooked" form + * (a post-parse-analysis, executable expression tree), depending on + * how this ColumnDef node was created (by parsing, or by inheritance + * from an existing relation). We should never have both in the same node! + * + * Similarly, we may have a COLLATE specification in either raw form + * (represented as a CollateClause with arg==NULL) or cooked form + * (the collation's OID). + * + * The constraints list may contain a CONSTR_DEFAULT item in a raw + * parsetree produced by gram.y, but transformCreateStmt will remove + * the item and set raw_default instead. CONSTR_DEFAULT items + * should not appear in any subsequent processing. + */ +typedef struct ColumnDef { + NodeTag type; + char *colname; /* name of column */ + TypeName *typname; /* type of column */ + int kvtype; /* kv attribute type if use kv storage */ + int inhcount; /* number of times column is inherited */ + bool is_local; /* column has local (non-inherited) def'n */ + bool is_not_null; /* NOT NULL constraint specified? */ + bool is_from_type; /* column definition came from table type */ + bool is_serial; /* column is serial type or not */ + char storage; /* attstorage setting, or 0 for default */ + int8 cmprs_mode; /* compression method applied to this column */ + Node *raw_default; /* default value (untransformed parse tree) */ + Node *cooked_default; /* default value (transformed expr tree) */ + CollateClause *collClause; /* untransformed COLLATE spec, if any */ + Oid collOid; /* collation OID (InvalidOid if not set) */ + List *constraints; /* other constraints on column */ + List *fdwoptions; /* per-column FDW options */ + ClientLogicColumnRef *clientLogicColumnRef; + Position *position; + Form_pg_attribute dropped_attr; /* strcuture for dropped attribute during create table like OE */ +} ColumnDef; + +/* + * definition of a range partition. + * range partition pattern: PARTITION [partitionName] LESS THAN [boundary] + * + */ +typedef struct RangePartitionDefState { + NodeTag type; + char *partitionName; /* name of range partition */ + List *boundary; /* the boundary of a range partition */ + char *tablespacename; /* table space to use, or NULL */ + Const *curStartVal; + char *partitionInitName; +} RangePartitionDefState; + +typedef struct RangePartitionStartEndDefState { + NodeTag type; + char *partitionName; /* name of range partition */ + List *startValue; /* the start value of a start/end clause */ + List *endValue; /* the end value of a start/end clause */ + List *everyValue; /* the interval value of a start/end clause */ + char *tableSpaceName; /* table space to use, or NULL */ +} RangePartitionStartEndDefState; + +/* * + * definition of a range partition. + * interval pattern: INTERVAL ([interval]) [tablespaceLists] + */ +typedef struct IntervalPartitionDefState { + NodeTag type; + Node *partInterval; /* the interval of table which is a constant expression */ + List *intervalTablespaces; /* list of tablespace */ +} IntervalPartitionDefState; +/* * + * definition of a partitioned table. + */ +typedef enum RowMovementValue { + ROWMOVEMENT_DISABLE, + ROWMOVEMENT_ENABLE, + ROWMOVEMENT_DEFAULT +} RowMovementValue; + +typedef struct PartitionState { + NodeTag type; + char partitionStrategy; + /* + * 'i': interval partition + * 'r': range partition + * 'v': value partition (HDFS table only) + * 'i': interval partition. (unsupported yet) + * 'l': list partition (unsupported yet) + * 'h': hash partition (unsupported yet) + */ + + IntervalPartitionDefState *intervalPartDef; /* interval definition */ + List *partitionKey; /* partition key of partitioned table , which is list of ColumnRef */ + List *partitionList; /* list of partition definition */ + RowMovementValue rowMovement; /* default: for colum-stored table means true, for row-stored means false */ +} PartitionState; + +typedef struct AddPartitionState { /* ALTER TABLE ADD PARTITION */ + NodeTag type; + List *partitionList; + bool isStartEnd; +} AddPartitionState; + +typedef struct SplitPartitionState { /* ALTER TABLE SPLIT PARTITION INTO */ + NodeTag type; + char *src_partition_name; + List *partition_for_values; + List *split_point; + List *dest_partition_define_list; +} SplitPartitionState; + +typedef struct ReplicaIdentityStmt { + NodeTag type; + char identity_type; + char *name; +} ReplicaIdentityStmt; + +/* ---------------------- + * Create Table Statement + * + * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are + * intermixed in tableElts, and constraints is NIL. After parse analysis, + * tableElts contains just ColumnDefs, and constraints contains just + * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present + * implementation). + * ---------------------- + */ + +typedef struct CreateStmt { + NodeTag type; + RangeVar *relation; /* relation to create */ + List *tableElts; /* column definitions (list of ColumnDef) */ + List *inhRelations; /* relations to inherit from (list of + * inhRelation) */ + TypeName *ofTypename; /* OF typename */ + List *constraints; /* constraints (list of Constraint nodes) */ + List *options; /* options from WITH clause */ + List *clusterKeys; /* partial cluster key for table */ + OnCommitAction oncommit; /* what do we do at COMMIT? */ + char *tablespacename; /* table space to use, or NULL */ + bool if_not_exists; /* just do nothing if it already exists? */ + bool ivm; /* incremental view maintenance is used by materialized view */ + int8 row_compress; /* row compression flag */ + PartitionState *partTableState; /* the PartitionState */ +#ifdef PGXC + DistributeBy *distributeby; /* distribution to use, or NULL */ + PGXCSubCluster *subcluster; /* subcluster of table */ +#endif + + List *tableEltsDup; /* Used for cstore constraint check */ + char *internalData; /* Used for create table like */ + + List *uuids; /* list of uuid, used for create sequence(like 'create table t(a serial))' */ + Oid oldBucket; /* bucketoid of resizing table */ + List *oldNode; /* relfilenode of resizing table */ + List *oldToastNode; /* toastnode of resizing table */ + char relkind; /* type of object */ +} CreateStmt; + +/* ---------------------- + * Copy Statement + * + * We support "COPY relation FROM file", "COPY relation TO file", and + * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation" + * and "query" must be non-NULL. + * ---------------------- + */ +typedef struct CopyStmt { + NodeTag type; + RangeVar *relation; /* the relation to copy */ + Node *query; /* the SELECT query to copy */ + List *attlist; /* List of column names (as Strings), or NIL + * for all columns */ + bool is_from; /* TO or FROM */ + char *filename; /* filename, or NULL for STDIN/STDOUT */ + List *options; /* List of DefElem nodes */ + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; + bool encrypted; +} CopyStmt; + +#define ATT_KV_UNDEFINED (0) +#define ATT_KV_TAG (1) +#define ATT_KV_FIELD (2) +#define ATT_KV_TIMETAG (3) +#define ATT_KV_HIDE (4) +// valid value for ColumnDef.cmprs_mode +// +#define ATT_CMPR_UNDEFINED (0x7F) +// +// default value for system tables' attrs. +// modify %PGATTR_DEFAULTS in src/backend/catalog/genbki.pl if you modify this mocro +// +#define ATT_CMPR_NOCOMPRESS (0) +#define ATT_CMPR_DELTA (1) +#define ATT_CMPR_DICTIONARY (2) +#define ATT_CMPR_PREFIX (3) +#define ATT_CMPR_NUMSTR (4) + +/* ---------- + * Definitions for constraints in CreateStmt + * + * Note that column defaults are treated as a type of constraint, + * even though that's a bit odd semantically. + * + * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + * + * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype + * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are + * stored into pg_constraint.confmatchtype. Changing the code values may + * require an initdb! + * + * If skip_validation is true then we skip checking that the existing rows + * in the table satisfy the constraint, and just install the catalog entries + * for the constraint. A new FK constraint is marked as valid iff + * initially_valid is true. (Usually skip_validation and initially_valid + * are inverses, but we can set both true if the table is known empty.) + * + * Constraint attributes (DEFERRABLE etc) are initially represented as + * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes + * a pass through the constraints list to insert the info into the appropriate + * Constraint node. + * ---------- + */ + +typedef enum ConstrType { /* types of constraints */ + CONSTR_NULL, /* not SQL92, but a lot of people expect it */ + CONSTR_NOTNULL, + CONSTR_DEFAULT, + CONSTR_CHECK, + CONSTR_PRIMARY, + CONSTR_UNIQUE, + CONSTR_EXCLUSION, + CONSTR_FOREIGN, + CONSTR_CLUSTER, + CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ + CONSTR_ATTR_NOT_DEFERRABLE, + CONSTR_ATTR_DEFERRED, + CONSTR_ATTR_IMMEDIATE +} ConstrType; + +typedef struct Constraint { + NodeTag type; + ConstrType contype; /* see above */ + + /* Fields used for most/all constraint types: */ + char *conname; /* Constraint name, or NULL if unnamed */ + bool deferrable; /* DEFERRABLE? */ + bool initdeferred; /* INITIALLY DEFERRED? */ + int location; /* token location, or -1 if unknown */ + + /* Fields used for constraints with expressions (CHECK and DEFAULT): */ + bool is_no_inherit; /* is constraint non-inheritable? */ + Node *raw_expr; /* expr, as untransformed parse tree */ + char *cooked_expr; /* expr, as nodeToString representation */ + + /* Fields used for unique constraints (UNIQUE and PRIMARY KEY) or cluster partial key for colstore: */ + List *keys; /* String nodes naming referenced column(s) */ + List *including; /* String nodes naming referenced nonkey column(s) */ + + /* Fields used for EXCLUSION constraints: */ + List *exclusions; /* list of (IndexElem, operator name) pairs */ + + /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */ + List *options; /* options from WITH clause */ + char *indexname; /* existing index to use; otherwise NULL */ + char *indexspace; /* index tablespace; NULL for default */ + /* These could be, but currently are not, used for UNIQUE/PKEY: */ + char *access_method; /* index access method; NULL for default */ + Node *where_clause; /* partial index predicate */ + + /* Fields used for FOREIGN KEY constraints: */ + RangeVar *pktable; /* Primary key table */ + List *fk_attrs; /* Attributes of foreign key */ + List *pk_attrs; /* Corresponding attrs in PK table */ + char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */ + char fk_upd_action; /* ON UPDATE action */ + char fk_del_action; /* ON DELETE action */ + List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */ + Oid old_pktable_oid; /* pg_constraint.confrelid of my former self */ + + /* Fields used for constraints that allow a NOT VALID specification */ + bool skip_validation; /* skip validation of existing rows? */ + bool initially_valid; /* mark the new constraint as valid? */ + + /* + * @hdfs + * Field used for soft constraint, which works on HDFS foreign table. + */ + InformationalConstraint *inforConstraint; +} Constraint; + +/* + * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause + */ +typedef struct TableLikeClause { + NodeTag type; + RangeVar *relation; + bits32 options; /* OR of TableLikeOption flags */ +} TableLikeClause; + +#define MAX_TABLE_LIKE_OPTIONS (9) +typedef enum TableLikeOption { + CREATE_TABLE_LIKE_DEFAULTS = 1 << 0, + CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1, + CREATE_TABLE_LIKE_INDEXES = 1 << 2, + CREATE_TABLE_LIKE_STORAGE = 1 << 3, + CREATE_TABLE_LIKE_COMMENTS = 1 << 4, + CREATE_TABLE_LIKE_PARTITION = 1 << 5, + CREATE_TABLE_LIKE_RELOPTIONS = 1 << 6, + CREATE_TABLE_LIKE_DISTRIBUTION = 1 << 7, + CREATE_TABLE_LIKE_OIDS = 1 << 8, + CREATE_TABLE_LIKE_ALL = 0x7FFFFFFF +} TableLikeOption; + +/* Foreign key matchtype codes */ +#define FKCONSTR_MATCH_FULL 'f' +#define FKCONSTR_MATCH_PARTIAL 'p' +#define FKCONSTR_MATCH_UNSPECIFIED 'u' + +/* Foreign key action codes */ +#define FKCONSTR_ACTION_NOACTION 'a' +#define FKCONSTR_ACTION_RESTRICT 'r' +#define FKCONSTR_ACTION_CASCADE 'c' +#define FKCONSTR_ACTION_SETNULL 'n' +#define FKCONSTR_ACTION_SETDEFAULT 'd' + +/* *************************************************************************** + * Supporting data structures for Parse Trees + * + * Most of these node types appear in raw parsetrees output by the grammar, + * and get transformed to something else by the analyzer. A few of them + * are used as-is in transformed querytrees. + * ************************************************************************** */ +/* + * ColumnRef - specifies a reference to a column, or possibly a whole tuple + * + * The "fields" list must be nonempty. It can contain string Value nodes + * (representing names) and A_Star nodes (representing occurrence of a '*'). + * Currently, A_Star must appear only as the last list element --- the grammar + * is responsible for enforcing this! + * + * Note: any array subscripting or selection of fields from composite columns + * is represented by an A_Indirection node above the ColumnRef. However, + * for simplicity in the normal case, initial field selection from a table + * name is represented within ColumnRef and not by adding A_Indirection. + */ +typedef struct ColumnRef { + NodeTag type; + List *fields; /* field names (Value strings) or A_Star */ + int location; /* token location, or -1 if unknown */ +} ColumnRef; + +/* + * A_Star - '*' representing all columns of a table or compound field + * + * This can appear within ColumnRef.fields, A_Indirection.indirection, and + * ResTarget.indirection lists. + */ +typedef struct A_Star { + NodeTag type; +} A_Star; + +/* + * CommonTableExpr - + * representation of WITH list element + * + * We don't currently support the SEARCH or CYCLE clause. + */ +typedef struct CommonTableExpr { + NodeTag type; + char *ctename; /* query name (never qualified) */ + List *aliascolnames; /* optional list of column names */ + /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */ + Node *ctequery; /* the CTE's subquery */ + int location; /* token location, or -1 if unknown */ + /* These fields are set during parse analysis: */ + bool cterecursive; /* is this CTE actually recursive? */ + int cterefcount; /* number of RTEs referencing this CTE + * (excluding internal self-references) */ + List *ctecolnames; /* list of output column names */ + List *ctecoltypes; /* OID list of output column type OIDs */ + List *ctecoltypmods; /* integer list of output column typmods */ + List *ctecolcollations; /* OID list of column collation OIDs */ + char locator_type; /* the location type of cte */ +} CommonTableExpr; + +/* + * FuncCall - a function or aggregate invocation + * + * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)'. + * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct + * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the + * construct *must* be an aggregate call. Otherwise, it might be either an + * aggregate or some other kind of function. However, if OVER is present + * it had better be an aggregate or window function. + */ +typedef struct FuncCall { + NodeTag type; + List *funcname; /* qualified name of function */ + char *colname; /* column name for the function */ + List *args; /* the arguments (list of exprs) */ + List *agg_order; /* ORDER BY (list of SortBy) */ + bool agg_within_group; + bool agg_star; /* argument was really '*' */ + bool agg_distinct; /* arguments were labeled DISTINCT */ + bool func_variadic; /* last argument was labeled VARIADIC */ + struct WindowDef *over; /* OVER clause, if any */ + int location; /* token location, or -1 if unknown */ + bool call_func; /* call function, false is select function */ +} FuncCall; + +/* + * GroupingSet - + * representation of CUBE, ROLLUP and GROUPING SETS clauses + * + * In a Query with grouping sets, the groupClause contains a flat list of + * SortGroupClause nodes for each distinct expression used. The actual + * structure of the GROUP BY clause is given by the groupingSets tree + * + * In the raw parser output, GroupingSet nodes (of all types except SIMPLE + * which is not used) are potentially mixed in with the expressions in the + * groupClause of the SelectStmt. (An expression can't contain a GroupingSet, + * but a list may mix GroupingSet and expression nodes.) At this stage, the + * content of each node is a list of expressions, some of which may be RowExprs + * which represent sublists rather than actual row constructors, and nested + * GroupingSet nodes where legal in the grammar. The structure directly + * reflects the query syntax. + * + * In parse analysis, the transformed expressions are used to build the tlist + * and groupClause list (of SortGroupClause nodes), and the groupingSets tree + * is eventually reduced to a fixed format: + * + * EMPTY nodes represent (), and obviously have no content + * + * SIMPLE nodes represent a list of one or more expressions to be treated as an + * atom by the enclosing structure; the content is an integer list of + * ressortgroupref values (see SortGroupClause) + * + * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes. + * + * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after + * parse analysis they cannot contain more SETS nodes; enough of the syntactic + * transforms of the spec have been applied that we no longer have arbitrarily + * deep nesting (though we still preserve the use of cube/rollup). + * + * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY + * nodes at the leaves), then the groupClause will be empty, but this is still + * an aggregation query (similar to using aggs or HAVING without GROUP BY). + * + * As an example, the following clause: + * + * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e))) + * + * looks like this after raw parsing: + * + * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) ) + * + * and parse analysis converts it to: + * + * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) ) + */ +typedef enum { + GROUPING_SET_EMPTY, + GROUPING_SET_SIMPLE, + GROUPING_SET_ROLLUP, + GROUPING_SET_CUBE, + GROUPING_SET_SETS +} GroupingSetKind; + +typedef struct GroupingSet { + NodeTag type; + GroupingSetKind kind; + List *content; + int location; +} GroupingSet; + +/* + * LockingClause - raw representation of FOR UPDATE/SHARE options + * + * Note: lockedRels == NIL means "all relations in query". Otherwise it + * is a list of RangeVar nodes. (We use RangeVar mainly because it carries + * a location field --- currently, parse analysis insists on unqualified + * names in LockingClause.) + */ +typedef struct LockingClause { + NodeTag type; + List *lockedRels; /* FOR UPDATE or FOR SHARE relations */ + bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ + bool noWait; /* NOWAIT option */ +} LockingClause; + +/* + * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause + * + * This node, appearing only in raw parse trees, represents + * TABLESAMPLE () REPEATABLE () + * Currently, the can only be a RangeVar, but we might in future + * allow RangeSubselect and other options. Note that the RangeTableSample + * is wrapped around the node representing the , rather than being + * a subfield of it. + */ +typedef struct RangeTableSample { + NodeTag type; + Node *relation; /* relation to be sampled */ + List *method; /* sampling method name (possibly qualified) */ + List *args; /* argument(s) for sampling method */ + Node *repeatable; /* REPEATABLE expression, or NULL if none */ + int location; /* method name location, or -1 if unknown */ +} RangeTableSample; + +/* + * RangeFunction - function call appearing in a FROM clause + */ +typedef struct RangeFunction { + NodeTag type; + bool lateral; /* does it have LATERAL prefix? */ + Node *funccallnode; /* untransformed function call tree */ + Alias *alias; /* table alias & optional column aliases */ + List *coldeflist; /* list of ColumnDef nodes to describe result + * of function returning RECORD */ +} RangeFunction; + +/* + * RangeSubselect - subquery appearing in a FROM clause + */ +typedef struct RangeSubselect { + NodeTag type; + bool lateral; /* does it have LATERAL prefix? */ + Node *subquery; /* the untransformed sub-select clause */ + Alias *alias; /* table alias & optional column aliases */ +} RangeSubselect; + +/* + * A_Expr - infix, prefix, and postfix expressions + */ +typedef enum A_Expr_Kind { + AEXPR_OP, /* normal operator */ + AEXPR_AND, /* booleans - name field is unused */ + AEXPR_OR, + AEXPR_NOT, + AEXPR_OP_ANY, /* scalar op ANY (array) */ + AEXPR_OP_ALL, /* scalar op ALL (array) */ + AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ + AEXPR_NULLIF, /* NULLIF - name must be "=" */ + AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */ + AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */ +} A_Expr_Kind; + +typedef struct A_Expr { + NodeTag type; + A_Expr_Kind kind; /* see above */ + List *name; /* possibly-qualified name of operator */ + Node *lexpr; /* left argument, or NULL if none */ + Node *rexpr; /* right argument, or NULL if none */ + int location; /* token location, or -1 if unknown */ +} A_Expr; + +/* + * ParamRef - specifies a $n parameter reference + */ +typedef struct ParamRef { + NodeTag type; + int number; /* the number of the parameter */ + int location; /* token location, or -1 if unknown */ +} ParamRef; + +/* + * A_Indirection - select a field and/or array element from an expression + * + * The indirection list can contain A_Indices nodes (representing + * subscripting), string Value nodes (representing field selection --- the + * string value is the name of the field to select), and A_Star nodes + * (representing selection of all fields of a composite type). + * For example, a complex selection operation like + * (foo).field1[42][7].field2 + * would be represented with a single A_Indirection node having a 4-element + * indirection list. + * + * Currently, A_Star must appear only as the last list element --- the grammar + * is responsible for enforcing this! + */ +typedef struct A_Indirection { + NodeTag type; + Node *arg; /* the thing being selected from */ + List *indirection; /* subscripts and/or field names and/or * */ +} A_Indirection; + +/* + * A_ArrayExpr - an ARRAY[] construct + */ +typedef struct A_ArrayExpr { + NodeTag type; + List *elements; /* array element expressions */ + int location; /* token location, or -1 if unknown */ +} A_ArrayExpr; + +/* + * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are + * used so that ruleutils.c can tell which properties were specified and + * which were defaulted; the correct behavioral bits must be set either way. + * The START_foo and END_foo options must come in pairs of adjacent bits for + * the convenience of gram.y, even though some of them are useless/invalid. + * We will need more bits (and fields) to cover the full SQL:2008 option set. + */ +#define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */ +#define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */ +#define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */ +#define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */ +#define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */ +#define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */ +#define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */ +#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */ +#define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */ +#define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */ +#define FRAMEOPTION_START_VALUE_PRECEDING 0x00400 /* start is V. P. */ +#define FRAMEOPTION_END_VALUE_PRECEDING 0x00800 /* end is V. P. */ +#define FRAMEOPTION_START_VALUE_FOLLOWING 0x01000 /* start is V. F. */ +#define FRAMEOPTION_END_VALUE_FOLLOWING 0x02000 /* end is V. F. */ + +#define FRAMEOPTION_START_VALUE (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING) +#define FRAMEOPTION_END_VALUE (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING) + +#define FRAMEOPTION_DEFAULTS (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | FRAMEOPTION_END_CURRENT_ROW) + +/* + * XMLSERIALIZE (in raw parse tree only) + */ +typedef struct XmlSerialize { + NodeTag type; + XmlOptionType xmloption; /* DOCUMENT or CONTENT */ + Node *expr; + TypeName *typname; + int location; /* token location, or -1 if unknown */ +} XmlSerialize; + +/* + * TypeCast - a CAST expression + */ +typedef struct TypeCast { + NodeTag type; + Node *arg; /* the expression being casted */ + TypeName *typname; /* the target type */ + int location; /* token location, or -1 if unknown */ +} TypeCast; + +/* + * A_Const - a literal constant + */ +typedef struct A_Const { + NodeTag type; + Value val; /* value (includes type info, see value.h) */ + int location; /* token location, or -1 if unknown */ +} A_Const; + + +/* Possible sources of a Query */ +typedef enum QuerySource { + QSRC_ORIGINAL, /* original parsetree (explicit query) */ + QSRC_PARSER, /* added by parse analysis in MERGE */ + QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */ + QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */ + QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */ +} QuerySource; + +typedef enum TdTruncCastStatus { + UNINVOLVED_QUERY = 0, + NOT_CAST_BECAUSEOF_GUC, + TRUNC_CAST_QUERY +} TdTruncCastStatus; +#define TRUNCAST_VERSION_NUM 92023 + +/* **************************************************************************** + * Query Tree + * *************************************************************************** */ + +/* + * Query - + * Parse analysis turns all statements into a Query tree + * for further processing by the rewriter and planner. + * + * Utility statements (i.e. non-optimizable statements) have the + * utilityStmt field set, and the Query itself is mostly dummy. + * DECLARE CURSOR is a special case: it is represented like a SELECT, + * but the original DeclareCursorStmt is stored in utilityStmt. + * + * Planning converts a Query tree into a Plan tree headed by a PlannedStmt + * node --- the Query structure is not used by the executor. + */ +typedef struct Query { + NodeTag type; + + CmdType commandType; /* select|insert|update|delete|merge|utility */ + + QuerySource querySource; /* where did I come from? */ + + uint64 queryId; /* query identifier (can be set by plugins) */ + + bool canSetTag; /* do I set the command result tag? */ + + Node* utilityStmt; /* non-null if this is DECLARE CURSOR or a + * non-optimizable statement */ + + int resultRelation; /* rtable index of target relation for + * INSERT/UPDATE/DELETE/MERGE; 0 for SELECT */ + + bool hasAggs; /* has aggregates in tlist or havingQual */ + bool hasWindowFuncs; /* has window functions in tlist */ + bool hasSubLinks; /* has subquery SubLink */ + bool hasDistinctOn; /* distinctClause is from DISTINCT ON */ + bool hasRecursive; /* WITH RECURSIVE was specified */ + bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */ + bool hasForUpdate; /* FOR UPDATE or FOR SHARE was specified */ + bool hasRowSecurity; /* rewriter has applied some RLS policy */ + bool hasSynonyms; /* has synonym mapping in rtable */ + + List* cteList; /* WITH list (of CommonTableExpr's) */ + + List* rtable; /* list of range table entries */ + FromExpr* jointree; /* table join tree (FROM and WHERE clauses) */ + + List* targetList; /* target list (of TargetEntry) */ + + List* starStart; /* Corresponding p_star_start in ParseState */ + + List* starEnd; /* Corresponding p_star_end in ParseState */ + + List* starOnly; /* Corresponding p_star_only in ParseState */ + + List* returningList; /* return-values list (of TargetEntry) */ + + List* groupClause; /* a list of SortGroupClause's */ + + List* groupingSets; /* a list of GroupingSet's if present */ + + Node* havingQual; /* qualifications applied to groups */ + + List* windowClause; /* a list of WindowClause's */ + + List* distinctClause; /* a list of SortGroupClause's */ + + List* sortClause; /* a list of SortGroupClause's */ + + Node* limitOffset; /* # of result tuples to skip (int8 expr) */ + Node* limitCount; /* # of result tuples to return (int8 expr) */ + + List* rowMarks; /* a list of RowMarkClause's */ + + Node* setOperations; /* set-operation tree if this is top level of + * a UNION/INTERSECT/EXCEPT query */ + + List *constraintDeps; /* a list of pg_constraint OIDs that the query + * depends on to be semantically valid */ + HintState* hintState; +#ifdef PGXC + /* need this info for PGXC Planner, may be temporary */ + char* sql_statement; /* original query */ + bool is_local; /* enforce query execution on local node + * this is used by EXECUTE DIRECT especially. */ + bool has_to_save_cmd_id; /* true if the query is such an INSERT SELECT + * that inserts into a child by selecting + * from its parent OR a WITH query that + * updates a table in main query and inserts + * a row to the same table in WITH query */ + bool vec_output; /* true if it's vec output. this flag is used in FQS planning */ + TdTruncCastStatus tdTruncCastStatus; /* Auto truncation Cast added, only used for stmt in stored procedure or + prepare stmt. */ + List* equalVars; /* vars appears in UPDATE/DELETE clause */ +#endif + ParamListInfo boundParamsQ; + + int mergeTarget_relation; + List* mergeSourceTargetList; + List* mergeActionList; /* list of actions for MERGE (only) */ + Query* upsertQuery; /* insert query for INSERT ON DUPLICATE KEY UPDATE (only) */ + UpsertExpr* upsertClause; /* DUPLICATE KEY UPDATE [NOTHING | ...] */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ + bool use_star_targets; /* true if use * for targetlist. */ + + bool is_from_full_join_rewrite; /* true if the query is created when doing + * full join rewrite. If true, we should not + * do some expression processing. + * Please refer to subquery_planner. + */ + uint64 uniqueSQLId; /* used by unique sql id */ + bool can_push; + bool unique_check; /* true if the subquery is generated by general + * sublink pullup, and scalar output is needed */ + Oid* fixed_paramTypes; /* For plpy CTAS query. CTAS is a recursive call.CREATE query is the first rewrited. + * thd 2nd rewrited query is INSERT SELECT.whithout this attribute, DB will have + * an error that has no idea about $x when INSERT SELECT query is analyzed. */ + int fixed_numParams; +} Query; + +/* ---------------------- + * {Begin|Commit|Rollback} Transaction Statement + * ---------------------- + */ + +typedef enum TransactionStmtKind { + TRANS_STMT_BEGIN, + TRANS_STMT_START, /* semantically identical to BEGIN */ + TRANS_STMT_COMMIT, + TRANS_STMT_ROLLBACK, + TRANS_STMT_SAVEPOINT, + TRANS_STMT_RELEASE, + TRANS_STMT_ROLLBACK_TO, + TRANS_STMT_PREPARE, + TRANS_STMT_COMMIT_PREPARED, + TRANS_STMT_ROLLBACK_PREPARED +} TransactionStmtKind; + +typedef struct TransactionStmt { + NodeTag type; + TransactionStmtKind kind; /* see above */ + List *options; /* for BEGIN/START and savepoint commands */ + char *gid; /* for two-phase-commit related commands */ + CommitSeqNo csn; /* for gs_clean two-phase-commit related commands */ +} TransactionStmt; +/* ---------------------- + * Create View Statement + * ---------------------- + */ +typedef struct ViewStmt { + NodeTag type; + RangeVar *view; /* the view to be created */ + List *aliases; /* target column names */ + Node *query; /* the SELECT query */ + bool replace; /* replace an existing view? */ + bool ivm; /* incremental materialized view? */ + List *options; /* options from WITH clause */ + char *sql_statement; /* used for resize rule, replace the original statement */ + ObjectType relkind; /* type of object */ + Node* mv_stmt; + char *mv_sql; +#ifdef ENABLE_MULTIPLE_NODES + struct PGXCSubCluster* subcluster; /* subcluster of table */ +#endif +} ViewStmt; + +/* ---------------------- + * Merge Statement + * ---------------------- + */ +typedef struct MergeStmt { + NodeTag type; + RangeVar *relation; /* target relation to merge into */ + Node *source_relation; /* source relation */ + Node *join_condition; /* join condition between source and target */ + List *mergeWhenClauses; /* list of MergeWhenClause(es) */ + bool is_insert_update; /* TRUE if the stmt is from INSERT UPDATE */ + Node *insert_stmt; /* insert stmt from INSERT UPDATE */ + HintState *hintState; +} MergeStmt; + +typedef struct MergeWhenClause { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + CmdType commandType; /* INSERT/UPDATE/DELETE */ + Node *condition; /* WHERE conditions (raw parser) */ + List *targetList; /* INSERT/UPDATE targetlist */ + /* the following members are only useful for INSERT action */ + List *cols; /* optional: names of the target columns */ + List *values; /* VALUES to INSERT, or NULL */ +} MergeWhenClause; + +/* + * WHEN [NOT] MATCHED THEN action info + */ +typedef struct MergeAction { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + Node *qual; /* transformed WHERE conditions */ + CmdType commandType; /* INSERT/UPDATE/DELETE */ + List *targetList; /* the target list (of ResTarget) */ + /* + * the replaced targetlist after simple subquery pullup. In stream plan, + * we don't do the replacement to targetlist and quals, but this pulluped + * targetlist, and then choose distribute key from this pulluped targetlist + */ + List *pulluped_targetList; +} MergeAction; + +/* PGXC_BEGIN */ +typedef enum { + EXEC_DIRECT_ON_LIST, + EXEC_DIRECT_ON_ALL_CN, + EXEC_DIRECT_ON_ALL_DN, + EXEC_DIRECT_ON_ALL_NODES, + EXEC_DIRECT_ON_NONE +} ExecDirectOption; +/* + * EXECUTE DIRECT statement + */ +typedef struct ExecDirectStmt { + NodeTag type; + List *node_names; + ExecDirectOption exec_option; + char *query; + int location; +} ExecDirectStmt; + +#endif /* PARSENODES_COMMONH */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/parsenodes.h postgresql-hll-2.14/include/include/nodes/parsenodes.h --- postgresql-hll-2.14_old/include/include/nodes/parsenodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/parsenodes.h 2020-12-12 17:06:43.232347845 +0800 @@ -0,0 +1,2264 @@ +/* ------------------------------------------------------------------------- + * + * parsenodes.h + * definitions for parse tree nodes + * + * Many of the node types used in parsetrees include a "location" field. + * This is a byte (not character) offset in the original source text, to be + * used for positioning an error cursor when there is an error related to + * the node. Access to the original source text is needed to make use of + * the location. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/parsenodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSENODES_H +#define PARSENODES_H + +#include "nodes/bitmapset.h" +#include "nodes/params.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#ifdef PGXC +#include "access/tupdesc.h" +#include "pgxc/locator.h" +#endif +#include "tcop/dest.h" +#include "nodes/parsenodes_common.h" + +/* + * Relids + * Set of relation identifiers (indexes into the rangetable). + */ +typedef Bitmapset* Relids; + +/* Sort ordering options for ORDER BY and CREATE INDEX */ +typedef enum RoleLockType { DO_NOTHING, LOCK_ROLE, UNLOCK_ROLE } RoleLockType; + +typedef enum RelOrientation { + REL_ORIENT_UNKNOWN, + REL_COL_ORIENTED, /* It represents CU sotre foramt also. */ + REL_ROW_ORIENTED, + REL_PAX_ORIENTED, + REL_TIMESERIES_ORIENTED +} RelOrientation; + +/* + * It keeps file system which the relatoin store. + * LOCAL_STORE represents local file system. + * HDFS_STORE represents Hadoop file system. + */ +typedef enum RelstoreType { LOCAL_STORE, HDFS_STORE } RelstoreType; + +#define SAMPLEARGSNUM 2 +/* Method of tablesample */ +typedef enum TableSampleType { SYSTEM_SAMPLE = 0, BERNOULLI_SAMPLE, HYBRID_SAMPLE } TableSampleType; + +/* + * Grantable rights are encoded so that we can OR them together in a bitmask. + * The present representation of AclItem limits us to 16 distinct rights, + * even though AclMode is defined as uint32. See utils/acl.h. + * + * Caution: changing these codes breaks stored ACLs, hence forces initdb. + */ +typedef uint32 AclMode; /* a bitmask of privilege bits */ + +#define ACL_INSERT (1 << 0) /* for relations */ +#define ACL_SELECT (1 << 1) +#define ACL_UPDATE (1 << 2) +#define ACL_DELETE (1 << 3) +#define ACL_TRUNCATE (1 << 4) +#define ACL_REFERENCES (1 << 5) +#define ACL_TRIGGER (1 << 6) +#define ACL_EXECUTE (1 << 7) /* for functions */ +#define ACL_USAGE \ + (1 << 8) /* for languages, namespaces, FDWs, and \ + * servers */ +#define ACL_CREATE (1 << 9) /* for namespaces and databases */ +#define ACL_CREATE_TEMP (1 << 10) /* for databases */ +#define ACL_CONNECT (1 << 11) /* for databases */ +#define ACL_COMPUTE (1 << 12) /* for node group */ +#define ACL_READ (1 << 13) /* for pg_directory */ +#define ACL_WRITE (1 << 14) /* for pg_directory */ +#define N_ACL_RIGHTS 15 /* 1 plus the last 1<aliasname is required to be present, and should generally be used + * to identify the RTE for error messages etc. + * + * In RELATION RTEs, the colnames in both alias and eref are indexed by + * physical attribute number; this means there must be colname entries for + * dropped columns. When building an RTE we insert empty strings ("") for + * dropped columns. Note however that a stored rule may have nonempty + * colnames for columns dropped since the rule was created (and for that + * matter the colnames might be out of date due to column renamings). + * The same comments apply to FUNCTION RTEs when the function's return type + * is a named composite type. + * + * In JOIN RTEs, the colnames in both alias and eref are one-to-one with + * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when + * those columns are known to be dropped at parse time. Again, however, + * a stored rule might contain entries for columns dropped since the rule + * was created. (This is only possible for columns not actually referenced + * in the rule.) When loading a stored rule, we replace the joinaliasvars + * items for any such columns with NULL Consts. (We can't simply delete + * them from the joinaliasvars list, because that would affect the attnums + * of Vars referencing the rest of the list.) + * + * inh is TRUE for relation references that should be expanded to include + * inheritance children, if the rel has any. This *must* be FALSE for + * RTEs other than RTE_RELATION entries. + * + * inFromCl marks those range variables that are listed in the FROM clause. + * It's false for RTEs that are added to a query behind the scenes, such + * as the NEW and OLD variables for a rule, or the subqueries of a UNION. + * This flag is not used anymore during parsing, since the parser now uses + * a separate "namespace" data structure to control visibility, but it is + * needed by ruleutils.c to determine whether RTEs should be shown in + * decompiled queries. + * + * requiredPerms and checkAsUser specify run-time access permissions + * checks to be performed at query startup. The user must have *all* + * of the permissions that are OR'd together in requiredPerms (zero + * indicates no permissions checking). If checkAsUser is not zero, + * then do the permissions checks using the access rights of that user, + * not the current effective user ID. (This allows rules to act as + * setuid gateways.) Permissions checks only apply to RELATION RTEs. + * + * For SELECT/INSERT/UPDATE permissions, if the user doesn't have + * table-wide permissions then it is sufficient to have the permissions + * on all columns identified in selectedCols (for SELECT) and/or + * modifiedCols (for INSERT/UPDATE; we can tell which from the query type). + * selectedCols and modifiedCols are bitmapsets, which cannot have negative + * integer members, so we subtract FirstLowInvalidHeapAttributeNumber from + * column numbers before storing them in these fields. A whole-row Var + * reference is represented by setting the bit for InvalidAttrNumber. + * -------------------- + */ +typedef enum RTEKind { + RTE_RELATION, /* ordinary relation reference */ + RTE_SUBQUERY, /* subquery in FROM */ + RTE_JOIN, /* join */ + RTE_FUNCTION, /* function in FROM */ + RTE_VALUES, /* VALUES (), (), ... */ + RTE_CTE /* common table expr (WITH list element) */ +#ifdef PGXC + , + RTE_REMOTE_DUMMY /* RTEs created by remote plan reduction */ +#endif /* PGXC */ +} RTEKind; + +typedef struct RangeTblEntry { + NodeTag type; + + RTEKind rtekind; /* see above */ + + /* + * XXX the fields applicable to only some rte kinds should be merged into + * a union. I didn't do this yet because the diffs would impact a lot of + * code that is being actively worked on. + */ + +#ifdef PGXC + char* relname; + List* partAttrNum; +#endif + + /* + * Fields valid for a plain relation RTE (else zero): + */ + Oid relid; /* OID of the relation */ + Oid partitionOid; /* + * OID of a partition if relation is partitioned table. + * Select * from table_name partition (partition_name); + * or select * from table_name partition for (partition_key_value_list) + */ + bool isContainPartition; /* select from caluse whether contains partition + * if contains partition isContainPartition=true, + * otherwise isContainPartition=false + */ + Oid refSynOid; /* OID of synonym object if relation is referenced by some synonym object. */ + List* partid_list; + + char relkind; /* relation kind (see pg_class.relkind) */ + bool isResultRel; /* used in target of SELECT INTO or similar */ + TableSampleClause* tablesample; /* sampling method and parameters */ + + bool ispartrel; /* is it a partitioned table */ + + /* works just for _readRangeTblEntry(). set true if plan is running in the compute pool. */ + bool ignoreResetRelid; + + /* + * Fields valid for a subquery RTE (else NULL): + */ + Query* subquery; /* the sub-query */ + bool security_barrier; /* subquery from security_barrier view */ + + /* + * Fields valid for a join RTE (else NULL/zero): + * + * joinaliasvars is a list of Vars or COALESCE expressions corresponding + * to the columns of the join result. An alias Var referencing column K + * of the join result can be replaced by the K'th element of joinaliasvars + * --- but to simplify the task of reverse-listing aliases correctly, we + * do not do that until planning time. In a Query loaded from a stored + * rule, it is also possible for joinaliasvars items to be NULL Consts, + * denoting columns dropped since the rule was made. + */ + JoinType jointype; /* type of join */ + List* joinaliasvars; /* list of alias-var expansions */ + + /* + * Fields valid for a function RTE (else NULL): + * + * If the function returns RECORD, funccoltypes lists the column types + * declared in the RTE's column type specification, funccoltypmods lists + * their declared typmods, funccolcollations their collations. Otherwise, + * those fields are NIL. + */ + Node* funcexpr; /* expression tree for func call */ + List* funccoltypes; /* OID list of column type OIDs */ + List* funccoltypmods; /* integer list of column typmods */ + List* funccolcollations; /* OID list of column collation OIDs */ + + /* + * Fields valid for a values RTE (else NIL): + */ + List* values_lists; /* list of expression lists */ + List* values_collations; /* OID list of column collation OIDs */ + + /* + * Fields valid for a CTE RTE (else NULL/zero): + */ + char* ctename; /* name of the WITH list item */ + Index ctelevelsup; /* number of query levels up */ + bool self_reference; /* is this a recursive self-reference? */ + List* ctecoltypes; /* OID list of column type OIDs */ + List* ctecoltypmods; /* integer list of column typmods */ + List* ctecolcollations; /* OID list of column collation OIDs */ + char locator_type; /* keep subplan/cte's locator type */ + + /* + * Fields valid in all RTEs: + */ + Alias* alias; /* user-written alias clause, if any */ + Alias* eref; /* expanded reference names */ + Alias* pname; /* partition name, if any */ + List* plist; + bool lateral; /* subquery or function is marked LATERAL? */ + bool inh; /* inheritance requested? */ + bool inFromCl; /* present in FROM clause? */ + AclMode requiredPerms; /* bitmask of required access permissions */ + Oid checkAsUser; /* if valid, check access as this role */ + Bitmapset* selectedCols; /* columns needing SELECT permission */ + Bitmapset* modifiedCols; /* columns needing INSERT/UPDATE permission, not used in current version + * we split it to insertedCols and updatedCols for MERGEINTO + */ + Bitmapset* insertedCols; /* columns needing INSERT permission */ + Bitmapset* updatedCols; /* columns needing UPDATE permission */ + RelOrientation orientation; /* column oriented or row oriented */ + + char* mainRelName; + char* mainRelNameSpace; + List* securityQuals; /* security barrier quals to apply */ + + /* For skew hint */ + bool subquery_pull_up; /* mark that the subquery whether been pull up */ + + /* + * Indicate current RTE is correlated with a Recursive CTE, the flag is set in + * check_plan_correlation() + */ + bool correlated_with_recursive_cte; + /* For hash buckets */ + bool relhasbucket; /* the rel has underlying buckets, get from pg_class */ + bool isbucket; /* the sql only want some buckets from the rel */ + List* buckets; /* the bucket id wanted */ + + bool isexcluded; /* the rel is the EXCLUDED relation for UPSERT */ + /* For sublink in targetlist pull up */ + bool sublink_pull_up; /* mark the subquery is sublink pulled up */ +} RangeTblEntry; + +/* + * SortGroupClause - + * representation of ORDER BY, GROUP BY, PARTITION BY, + * DISTINCT, DISTINCT ON items + * + * You might think that ORDER BY is only interested in defining ordering, + * and GROUP/DISTINCT are only interested in defining equality. However, + * one way to implement grouping is to sort and then apply a "uniq"-like + * filter. So it's also interesting to keep track of possible sort operators + * for GROUP/DISTINCT, and in particular to try to sort for the grouping + * in a way that will also yield a requested ORDER BY ordering. So we need + * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates + * the decision to give them the same representation. + * + * tleSortGroupRef must match ressortgroupref of exactly one entry of the + * query's targetlist; that is the expression to be sorted or grouped by. + * eqop is the OID of the equality operator. + * sortop is the OID of the ordering operator (a "<" or ">" operator), + * or InvalidOid if not available. + * nulls_first means about what you'd expect. If sortop is InvalidOid + * then nulls_first is meaningless and should be set to false. + * hashable is TRUE if eqop is hashable (note this condition also depends + * on the datatype of the input expression). + * + * In an ORDER BY item, all fields must be valid. (The eqop isn't essential + * here, but it's cheap to get it along with the sortop, and requiring it + * to be valid eases comparisons to grouping items.) Note that this isn't + * actually enough information to determine an ordering: if the sortop is + * collation-sensitive, a collation OID is needed too. We don't store the + * collation in SortGroupClause because it's not available at the time the + * parser builds the SortGroupClause; instead, consult the exposed collation + * of the referenced targetlist expression to find out what it is. + * + * In a grouping item, eqop must be valid. If the eqop is a btree equality + * operator, then sortop should be set to a compatible ordering operator. + * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that + * the query presents for the same tlist item. If there is none, we just + * use the default ordering op for the datatype. + * + * If the tlist item's type has a hash opclass but no btree opclass, then + * we will set eqop to the hash equality operator, sortop to InvalidOid, + * and nulls_first to false. A grouping item of this kind can only be + * implemented by hashing, and of course it'll never match an ORDER BY item. + * + * The hashable flag is provided since we generally have the requisite + * information readily available when the SortGroupClause is constructed, + * and it's relatively expensive to get it again later. Note there is no + * need for a "sortable" flag since OidIsValid(sortop) serves the purpose. + * + * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses. + * In SELECT DISTINCT, the distinctClause list is as long or longer than the + * sortClause list, while in SELECT DISTINCT ON it's typically shorter. + * The two lists must match up to the end of the shorter one --- the parser + * rearranges the distinctClause if necessary to make this true. (This + * restriction ensures that only one sort step is needed to both satisfy the + * ORDER BY and set up for the Unique step. This is semantically necessary + * for DISTINCT ON, and presents no real drawback for DISTINCT.) + */ +typedef struct SortGroupClause { + NodeTag type; + Index tleSortGroupRef; /* reference into targetlist */ + Oid eqop; /* the equality operator ('=' op) */ + Oid sortop; /* the ordering operator ('<' op), or 0 */ + bool nulls_first; /* do NULLs come before normal values? */ + bool hashable; /* can eqop be implemented by hashing? */ + bool groupSet; /* It will be set to true If this expr in group clause and not include + in all group clause when groupingSet is not null. It mean it's value can be altered. */ +} SortGroupClause; + +/* + * WindowClause - + * transformed representation of WINDOW and OVER clauses + * + * A parsed Query's windowClause list contains these structs. "name" is set + * if the clause originally came from WINDOW, and is NULL if it originally + * was an OVER clause (but note that we collapse out duplicate OVERs). + * partitionClause and orderClause are lists of SortGroupClause structs. + * winref is an ID number referenced by WindowFunc nodes; it must be unique + * among the members of a Query's windowClause list. + * When refname isn't null, the partitionClause is always copied from there; + * the orderClause might or might not be copied (see copiedOrder); the framing + * options are never copied, per spec. + */ +typedef struct WindowClause { + NodeTag type; + char* name; /* window name (NULL in an OVER clause) */ + char* refname; /* referenced window name, if any */ + List* partitionClause; /* PARTITION BY list */ + List* orderClause; /* ORDER BY list */ + int frameOptions; /* frame_clause options, see WindowDef */ + Node* startOffset; /* expression for starting bound, if any */ + Node* endOffset; /* expression for ending bound, if any */ + Index winref; /* ID referenced by window functions */ + bool copiedOrder; /* did we copy orderClause from refname? */ +} WindowClause; + +/* + * RowMarkClause - + * parser output representation of FOR UPDATE/SHARE clauses + * + * Query.rowMarks contains a separate RowMarkClause node for each relation + * identified as a FOR UPDATE/SHARE target. If FOR UPDATE/SHARE is applied + * to a subquery, we generate RowMarkClauses for all normal and subquery rels + * in the subquery, but they are marked pushedDown = true to distinguish them + * from clauses that were explicitly written at this query level. Also, + * Query.hasForUpdate tells whether there were explicit FOR UPDATE/SHARE + * clauses in the current query level. + */ +typedef struct RowMarkClause { + NodeTag type; + Index rti; /* range table index of target relation */ + bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ + bool noWait; /* NOWAIT option */ + bool pushedDown; /* pushed down from higher query level? */ +} RowMarkClause; + +/* Convenience macro to get the output tlist of a CTE's query */ +#define GetCTETargetList(cte) \ + (AssertMacro(IsA((cte)->ctequery, Query)), \ + ((Query*)(cte)->ctequery)->commandType == CMD_SELECT ? ((Query*)(cte)->ctequery)->targetList \ + : ((Query*)(cte)->ctequery)->returningList) + +/***************************************************************************** + * Optimizable Statements + *****************************************************************************/ + + +/* ---------------------- + * Set Operation node for post-analysis query trees + * + * After parse analysis, a SELECT with set operations is represented by a + * top-level Query node containing the leaf SELECTs as subqueries in its + * range table. Its setOperations field shows the tree of set operations, + * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal + * nodes replaced by SetOperationStmt nodes. Information about the output + * column types is added, too. (Note that the child nodes do not necessarily + * produce these types directly, but we've checked that their output types + * can be coerced to the output column type.) Also, if it's not UNION ALL, + * information about the types' sort/group semantics is provided in the form + * of a SortGroupClause list (same representation as, eg, DISTINCT). + * The resolved common column collations are provided too; but note that if + * it's not UNION ALL, it's okay for a column to not have a common collation, + * so a member of the colCollations list could be InvalidOid even though the + * column has a collatable type. + * ---------------------- + */ +typedef struct SetOperationStmt { + NodeTag type; + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + Node* larg; /* left child */ + Node* rarg; /* right child */ + /* Eventually add fields for CORRESPONDING spec here */ + + /* Fields derived during parse analysis: */ + List* colTypes; /* OID list of output column type OIDs */ + List* colTypmods; /* integer list of output column typmods */ + List* colCollations; /* OID list of output column collation OIDs */ + List* groupClauses; /* a list of SortGroupClause's */ + /* groupClauses is NIL if UNION ALL, but must be set otherwise */ +} SetOperationStmt; + +/***************************************************************************** + * Other Statements (no optimizations required) + * + * These are not touched by parser/analyze.c except to put them into + * the utilityStmt field of a Query. This is eventually passed to + * ProcessUtility (by-passing rewriting and planning). Some of the + * statements do need attention from parse analysis, and this is + * done by routines in parser/parse_utilcmd.c after ProcessUtility + * receives the command for execution. + *****************************************************************************/ + +/* ---------------------- + * Alter Domain + * + * The fields are used in different ways by the different variants of + * this command. + * ---------------------- + */ +typedef struct AlterDomainStmt { + NodeTag type; + char subtype; /*------------ + * T = alter column default + * N = alter column drop not null + * O = alter column set not null + * C = add constraint + * X = drop constraint + * ------------ + */ + List* typname; /* domain to work on */ + char* name; /* column or constraint name to act on */ + Node* def; /* definition of default or constraint */ + DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ + bool missing_ok; /* skip error if missing? */ +} AlterDomainStmt; + +/* ---------------------- + * Grant|Revoke Statement + * ---------------------- + */ +typedef enum GrantTargetType { + ACL_TARGET_OBJECT, /* grant on specific named object(s) */ + ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */ + ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */ +} GrantTargetType; + +typedef enum GrantObjectType { + ACL_OBJECT_COLUMN, /* column */ + ACL_OBJECT_RELATION, /* table, view */ + ACL_OBJECT_SEQUENCE, /* sequence */ + ACL_OBJECT_DATABASE, /* database */ + ACL_OBJECT_DOMAIN, /* domain */ + ACL_OBJECT_FDW, /* foreign-data wrapper */ + ACL_OBJECT_FOREIGN_SERVER, /* foreign server */ + ACL_OBJECT_FUNCTION, /* function */ + ACL_OBJECT_LANGUAGE, /* procedural language */ + ACL_OBJECT_LARGEOBJECT, /* largeobject */ + ACL_OBJECT_NAMESPACE, /* namespace */ + ACL_OBJECT_NODEGROUP, /* nodegroup */ + ACL_OBJECT_TABLESPACE, /* tablespace */ + ACL_OBJECT_TYPE, /* type */ + ACL_OBJECT_DATA_SOURCE, /* data source */ + ACL_OBJECT_GLOBAL_SETTING, /* Global Setting */ + ACL_OBJECT_COLUMN_SETTING, /* Column Setting */ + ACL_OBJECT_DIRECTORY /* directory */ +} GrantObjectType; + +typedef struct GrantStmt { + NodeTag type; + bool is_grant; /* true = GRANT, false = REVOKE */ + GrantTargetType targtype; /* type of the grant target */ + GrantObjectType objtype; /* kind of object being operated on */ + List* objects; /* list of RangeVar nodes, FuncWithArgs nodes, + * or plain names (as Value strings) */ + List* privileges; /* list of AccessPriv nodes */ + /* privileges == NIL denotes ALL PRIVILEGES */ + List* grantees; /* list of PrivGrantee nodes */ + bool grant_option; /* grant or revoke grant option */ + DropBehavior behavior; /* drop behavior (for REVOKE) */ +} GrantStmt; + +typedef struct PrivGrantee { + NodeTag type; + char* rolname; /* if NULL then PUBLIC */ +} PrivGrantee; + +/* + * An access privilege, with optional list of column names + * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list) + * cols == NIL denotes "all columns" + * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not + * an AccessPriv with both fields null. + */ +typedef struct AccessPriv { + NodeTag type; + char* priv_name; /* string name of privilege */ + List* cols; /* list of Value strings */ +} AccessPriv; + +/* ---------------------- + * Grant/Revoke Role Statement + * + * Note: because of the parsing ambiguity with the GRANT + * statement, granted_roles is a list of AccessPriv; the execution code + * should complain if any column lists appear. grantee_roles is a list + * of role names, as Value strings. + * ---------------------- + */ +typedef struct GrantRoleStmt { + NodeTag type; + List* granted_roles; /* list of roles to be granted/revoked */ + List* grantee_roles; /* list of member roles to add/delete */ + bool is_grant; /* true = GRANT, false = REVOKE */ + bool admin_opt; /* with admin option */ + char* grantor; /* set grantor to other than current role */ + DropBehavior behavior; /* drop behavior (for REVOKE) */ +} GrantRoleStmt; + +/* ---------------------- + * Alter Default Privileges Statement + * ---------------------- + */ +typedef struct AlterDefaultPrivilegesStmt { + NodeTag type; + List* options; /* list of DefElem */ + GrantStmt* action; /* GRANT/REVOKE action (with objects=NIL) */ +} AlterDefaultPrivilegesStmt; + +/* ---------------------- + * Show Statement + * ---------------------- + */ +typedef struct VariableShowStmt { + NodeTag type; + char* name; +} VariableShowStmt; + +/* ---------------------- + * Shutdown Statement + * ---------------------- + */ +typedef struct ShutdownStmt { + NodeTag type; + char* mode; +} ShutdownStmt; + +typedef struct ListPartitionDefState { + NodeTag type; + char* partitionName; /* name of list partition */ + List* boundary; /* the boundary of a list partition */ + char* tablespacename; /* table space to use, or NULL */ +} ListPartitionDefState; + +typedef struct HashPartitionDefState { + NodeTag type; + char* partitionName; /* name of hash partition */ + List* boundary; /* the boundary of a hash partition */ + char* tablespacename; /* table space to use, or NULL */ +} HashPartitionDefState; + +typedef struct RangePartitionindexDefState { + NodeTag type; + char* name; + char* tablespace; +} RangePartitionindexDefState; + + +/* ---------- + * Definitions for constraints in CreateStmt + * + * Note that column defaults are treated as a type of constraint, + * even though that's a bit odd semantically. + * + * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + * + * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype + * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are + * stored into pg_constraint.confmatchtype. Changing the code values may + * require an initdb! + * + * If skip_validation is true then we skip checking that the existing rows + * in the table satisfy the constraint, and just install the catalog entries + * for the constraint. A new FK constraint is marked as valid iff + * initially_valid is true. (Usually skip_validation and initially_valid + * are inverses, but we can set both true if the table is known empty.) + * + * Constraint attributes (DEFERRABLE etc) are initially represented as + * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes + * a pass through the constraints list to insert the info into the appropriate + * Constraint node. + * ---------- + */ + +#define CSTORE_SUPPORT_CONSTRAINT(type) \ + ((type) == CONSTR_NULL || (type) == CONSTR_NOTNULL || (type) == CONSTR_DEFAULT || (type) == CONSTR_CLUSTER) + +#define GetConstraintType(type) \ + ({ \ + const char* tname = NULL; \ + switch (type) { \ + case CONSTR_NULL: \ + tname = "NULL"; \ + break; \ + case CONSTR_NOTNULL: \ + tname = "NOT NULL"; \ + break; \ + case CONSTR_DEFAULT: \ + tname = "DEFAULT"; \ + break; \ + case CONSTR_CHECK: \ + tname = "CHECK"; \ + break; \ + case CONSTR_PRIMARY: \ + tname = "PRIMARY KEY"; \ + break; \ + case CONSTR_UNIQUE: \ + tname = "UNIQUE"; \ + break; \ + case CONSTR_EXCLUSION: \ + tname = "EXCLUSION"; \ + break; \ + case CONSTR_FOREIGN: \ + tname = "FOREIGN KEY"; \ + break; \ + case CONSTR_CLUSTER: \ + tname = "CLUSTER"; \ + break; \ + case CONSTR_ATTR_DEFERRABLE: \ + tname = "ATTR DEFERRABLE"; \ + break; \ + case CONSTR_ATTR_NOT_DEFERRABLE: \ + tname = "ATTR NOT DEFERRABLE"; \ + break; \ + case CONSTR_ATTR_DEFERRED: \ + tname = "ATTR DEFERRED"; \ + break; \ + case CONSTR_ATTR_IMMEDIATE: \ + tname = "ATTR IMMEDIATE"; \ + break; \ + } \ + tname; \ + }) + +/* ---------------------- + * Create/Drop Table Space Statements + * ---------------------- + */ +typedef struct CreateTableSpaceStmt { + NodeTag type; + char* tablespacename; + char* owner; + char* location; + char* maxsize; + List* options; + bool relative; /* location is relative to data directory */ +} CreateTableSpaceStmt; + +typedef struct DropTableSpaceStmt { + NodeTag type; + char* tablespacename; + bool missing_ok; /* skip error if missing? */ +} DropTableSpaceStmt; + +typedef struct AlterTableSpaceOptionsStmt { + NodeTag type; + char* tablespacename; + char* maxsize; + List* options; + bool isReset; +} AlterTableSpaceOptionsStmt; + +/* ---------------------- + * Create/Alter Extension Statements + * ---------------------- + */ +typedef struct CreateExtensionStmt { + NodeTag type; + char* extname; + bool if_not_exists; /* just do nothing if it already exists? */ + List* options; /* List of DefElem nodes */ +} CreateExtensionStmt; + +/* Only used for ALTER EXTENSION UPDATE; later might need an action field */ +typedef struct AlterExtensionStmt { + NodeTag type; + char* extname; + List* options; /* List of DefElem nodes */ +} AlterExtensionStmt; + +typedef struct AlterExtensionContentsStmt { + NodeTag type; + char* extname; /* Extension's name */ + int action; /* +1 = add object, -1 = drop object */ + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ +} AlterExtensionContentsStmt; + +/* ---------------------- + * Create/Alter FOREIGN DATA WRAPPER Statements + * ---------------------- + */ +typedef struct CreateFdwStmt { + NodeTag type; + char* fdwname; /* foreign-data wrapper name */ + List* func_options; /* HANDLER/VALIDATOR options */ + List* options; /* generic options to FDW */ +} CreateFdwStmt; + +typedef struct AlterFdwStmt { + NodeTag type; + char* fdwname; /* foreign-data wrapper name */ + List* func_options; /* HANDLER/VALIDATOR options */ + List* options; /* generic options to FDW */ +} AlterFdwStmt; + +/* ---------------------- + * Create Weak Password Statements + * ---------------------- + */ +typedef struct CreateWeakPasswordDictionaryStmt { + NodeTag type; + List* weak_password_string_list; +} CreateWeakPasswordDictionaryStmt; + +/* ---------------------- + * Drop Weak Password Statements + * ---------------------- + */ +typedef struct DropWeakPasswordDictionaryStmt { + NodeTag type; +} DropWeakPasswordDictionaryStmt; + +/* ---------------------- + * Create/Alter FOREIGN SERVER Statements + * ---------------------- + */ +typedef struct CreateForeignServerStmt { + NodeTag type; + char* servername; /* server name */ + char* servertype; /* optional server type */ + char* version; /* optional server version */ + char* fdwname; /* FDW name */ + List* options; /* generic options to server */ +} CreateForeignServerStmt; + +typedef struct AlterForeignServerStmt { + NodeTag type; + char* servername; /* server name */ + char* version; /* optional server version */ + List* options; /* generic options to server */ + bool has_version; /* version specified */ +} AlterForeignServerStmt; + +/* ---------------------- + * Create FOREIGN TABLE Statements + * ---------------------- + */ +typedef struct ForeignPartState { + NodeTag type; + + /* partition key of partitioned table , which is list of ColumnRef */ + List* partitionKey; +} ForeignPartState; + +struct DistributeBy; + +typedef struct CreateForeignTableStmt { + CreateStmt base; + char* servername; + Node* error_relation; + List* options; + List* extOptions; +#ifdef PGXC + DistributeBy* distributeby; +#endif + bool write_only; + ForeignPartState* part_state; +} CreateForeignTableStmt; + +/* ---------------------- + * Create/Drop USER MAPPING Statements + * ---------------------- + */ +typedef struct CreateUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + List* options; /* generic options to server */ +} CreateUserMappingStmt; + +typedef struct AlterUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + List* options; /* generic options to server */ +} AlterUserMappingStmt; + +typedef struct DropUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + bool missing_ok; /* ignore missing mappings */ +} DropUserMappingStmt; + +/* ---------------------- + * Create Synonym Statement + * ---------------------- + */ +typedef struct CreateSynonymStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + List* synName; /* qualified name of synonym */ + List* objName; /* referenced object name, eg. relation, view, function, procedure. */ +} CreateSynonymStmt; + +/* ---------------------- + * Drop Synonym Statement + * ---------------------- + */ +typedef struct DropSynonymStmt { + NodeTag type; + List* synName; /* qualified name of synonym */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing; /* skip error if a synonym is missing? */ +} DropSynonymStmt; + +/* ---------------------- + * Create/Alter DATA SOURCE Statements + * ---------------------- + */ +typedef struct CreateDataSourceStmt { + NodeTag type; + char* srcname; /* source name */ + char* srctype; /* optional source type */ + char* version; /* optional source version */ + List* options; /* generic options to server */ +} CreateDataSourceStmt; + +typedef struct AlterDataSourceStmt { + NodeTag type; + char* srcname; /* source name */ + char* srctype; /* optional source type */ + char* version; /* optional source version */ + List* options; /* generic options to source */ + bool has_version; /* version specified */ +} AlterDataSourceStmt; + +/* ---------------------- + * Create TRIGGER Statement + * ---------------------- + */ +typedef struct CreateTrigStmt { + NodeTag type; + char* trigname; /* TRIGGER's name */ + RangeVar* relation; /* relation trigger is on */ + List* funcname; /* qual. name of function to call */ + List* args; /* list of (T_String) Values or NIL */ + bool row; /* ROW/STATEMENT */ + /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ + int16 timing; /* BEFORE, AFTER, or INSTEAD */ + /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ + int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */ + List* columns; /* column names, or NIL for all columns */ + Node* whenClause; /* qual expression, or NULL if none */ + bool isconstraint; /* This is a constraint trigger */ + /* The remaining fields are only used for constraint triggers */ + bool deferrable; /* [NOT] DEFERRABLE */ + bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ + RangeVar* constrrel; /* opposite relation, if RI trigger */ +} CreateTrigStmt; + +/* ---------------------- + * Create PROCEDURAL LANGUAGE Statements + * ---------------------- + */ +typedef struct CreatePLangStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + char* plname; /* PL name */ + List* plhandler; /* PL call handler function (qual. name) */ + List* plinline; /* optional inline function (qual. name) */ + List* plvalidator; /* optional validator function (qual. name) */ + bool pltrusted; /* PL is trusted */ +} CreatePLangStmt; + +/* ---------------------- + * Create/Alter/Drop Role Statements + * + * Note: these node types are also used for the backwards-compatible + * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases + * there's really no need to distinguish what the original spelling was, + * but for CREATE we mark the type because the defaults vary. + * ---------------------- + */ +typedef enum RoleStmtType { ROLESTMT_ROLE, ROLESTMT_USER, ROLESTMT_GROUP } RoleStmtType; + +typedef struct CreateRoleStmt { + NodeTag type; + RoleStmtType stmt_type; /* ROLE/USER/GROUP */ + char* role; /* role name */ + List* options; /* List of DefElem nodes */ +} CreateRoleStmt; + +typedef struct AlterRoleStmt { + NodeTag type; + char* role; /* role name */ + List* options; /* List of DefElem nodes */ + int action; /* +1 = add members, -1 = drop members */ + RoleLockType lockstatus; +} AlterRoleStmt; + +typedef struct DropRoleStmt { + NodeTag type; + List* roles; /* List of roles to remove */ + bool missing_ok; /* skip error if a role is missing? */ + bool is_user; /* drop user or role */ + bool inherit_from_parent; /* whether user is inherited from parent user */ + DropBehavior behavior; /* CASCADE or RESTRICT */ +} DropRoleStmt; + +/* ---------------------- + * {Create|Alter} SEQUENCE Statement + * ---------------------- + */ + +typedef struct CreateSeqStmt { + NodeTag type; + RangeVar* sequence; /* the sequence to create */ + List* options; + Oid ownerId; /* ID of owner, or InvalidOid for default */ +#ifdef PGXC + bool is_serial; /* Indicates if this sequence is part of SERIAL process */ +#endif + int64 uuid; /* UUID of the sequence, mark unique sequence globally */ + bool canCreateTempSeq; /* create sequence when "create table (like )" */ +} CreateSeqStmt; + +typedef struct AlterSeqStmt { + NodeTag type; + RangeVar* sequence; /* the sequence to alter */ + List* options; + bool missing_ok; /* skip error if a role is missing? */ +#ifdef PGXC + bool is_serial; /* Indicates if this sequence is part of SERIAL process */ +#endif +} AlterSeqStmt; + +/* ---------------------- + * Create {Aggregate|Operator|Type} Statement + * ---------------------- + */ +typedef struct DefineStmt { + NodeTag type; + ObjectType kind; /* aggregate, operator, type */ + bool oldstyle; /* hack to signal old CREATE AGG syntax */ + List* defnames; /* qualified name (list of Value strings) */ + List* args; /* a list of TypeName (if needed) */ + List* definition; /* a list of DefElem */ +} DefineStmt; + +/* ---------------------- + * Create Domain Statement + * ---------------------- + */ +typedef struct CreateDomainStmt { + NodeTag type; + List* domainname; /* qualified name (list of Value strings) */ + TypeName* typname; /* the base type */ + CollateClause* collClause; /* untransformed COLLATE spec, if any */ + List* constraints; /* constraints (list of Constraint nodes) */ +} CreateDomainStmt; + +/* ---------------------- + * Create Operator Class Statement + * ---------------------- + */ +typedef struct CreateOpClassStmt { + NodeTag type; + List* opclassname; /* qualified name (list of Value strings) */ + List* opfamilyname; /* qualified name (ditto); NIL if omitted */ + char* amname; /* name of index AM opclass is for */ + TypeName* datatype; /* datatype of indexed column */ + List* items; /* List of CreateOpClassItem nodes */ + bool isDefault; /* Should be marked as default for type? */ +} CreateOpClassStmt; + +#define OPCLASS_ITEM_OPERATOR 1 +#define OPCLASS_ITEM_FUNCTION 2 +#define OPCLASS_ITEM_STORAGETYPE 3 + +typedef struct CreateOpClassItem { + NodeTag type; + int itemtype; /* see codes above */ + /* fields used for an operator or function item: */ + List* name; /* operator or function name */ + List* args; /* argument types */ + int number; /* strategy num or support proc num */ + List* order_family; /* only used for ordering operators */ + List* class_args; /* only used for functions */ + /* fields used for a storagetype item: */ + TypeName* storedtype; /* datatype stored in index */ +} CreateOpClassItem; + +/* ---------------------- + * Create Operator Family Statement + * ---------------------- + */ +typedef struct CreateOpFamilyStmt { + NodeTag type; + List* opfamilyname; /* qualified name (list of Value strings) */ + char* amname; /* name of index AM opfamily is for */ +} CreateOpFamilyStmt; + +/* ---------------------- + * Alter Operator Family Statement + * ---------------------- + */ +typedef struct AlterOpFamilyStmt { + NodeTag type; + List* opfamilyname; /* qualified name (list of Value strings) */ + char* amname; /* name of index AM opfamily is for */ + bool isDrop; /* ADD or DROP the items? */ + List* items; /* List of CreateOpClassItem nodes */ +} AlterOpFamilyStmt; + + +#ifdef ENABLE_MOT +typedef struct DropForeignStmt { + NodeTag type; + char relkind; + Oid reloid; + Oid indexoid; + char* name; +} DropForeignStmt; +#endif + +/* ---------------------- + * Truncate Table Statement + * ---------------------- + */ +typedef struct TruncateStmt { + NodeTag type; + List* relations; /* relations (RangeVars) to be truncated */ + bool restart_seqs; /* restart owned sequences? */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ +} TruncateStmt; + +/* ---------------------- + * Comment On Statement + * ---------------------- + */ +typedef struct CommentStmt { + NodeTag type; + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ + char* comment; /* Comment to insert, or NULL to remove */ +} CommentStmt; + +/* ---------------------- + * SECURITY LABEL Statement + * ---------------------- + */ +typedef struct SecLabelStmt { + NodeTag type; + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ + char* provider; /* Label provider (or NULL) */ + char* label; /* New security label to be assigned */ +} SecLabelStmt; + +/* ---------------------- + * Close Portal Statement + * ---------------------- + */ +typedef struct ClosePortalStmt { + NodeTag type; + char* portalname; /* name of the portal (cursor) */ + /* NULL means CLOSE ALL */ +} ClosePortalStmt; + +/* ---------------------- + * Fetch Statement (also Move) + * ---------------------- + */ +typedef enum FetchDirection { + /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */ + FETCH_FORWARD, + FETCH_BACKWARD, + /* for these, howMany indicates a position; only one row is fetched */ + FETCH_ABSOLUTE, + FETCH_RELATIVE +} FetchDirection; + +#define FETCH_ALL LONG_MAX + +typedef struct FetchStmt { + NodeTag type; + FetchDirection direction; /* see above */ + long howMany; /* number of rows, or position argument */ + char* portalname; /* name of portal (cursor) */ + bool ismove; /* TRUE if MOVE */ +} FetchStmt; + +/* ---------------------- + * Create Index Statement + * + * This represents creation of an index and/or an associated constraint. + * If isconstraint is true, we should create a pg_constraint entry along + * with the index. But if indexOid isn't InvalidOid, we are not creating an + * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint + * must always be true in this case, and the fields describing the index + * properties are empty. + * ---------------------- + */ +typedef struct IndexStmt { + NodeTag type; + char* schemaname; /* namespace of new index, or NULL for default */ + char* idxname; /* name of new index, or NULL for default */ + RangeVar* relation; /* relation to build index on */ + char* accessMethod; /* name of access method (eg. btree) */ + char* tableSpace; /* tablespace, or NULL for default */ + List* indexParams; /* columns to index: a list of IndexElem */ + List* indexIncludingParams; /* additional columns to index: a list of IndexElem */ + List* options; /* WITH clause options: a list of DefElem */ + Node* whereClause; /* qualification (partial-index predicate) */ + List* excludeOpNames; /* exclusion operator names, or NIL if none */ + char* idxcomment; /* comment to apply to index, or NULL */ + Oid indexOid; /* OID of an existing index, if any */ + Oid oldNode; /* relfilenode of existing storage, if any */ + Oid oldPSortOid; /* oid of existing psort storage for col-storage, if any */ + List* partIndexOldNodes; /* partition relfilenode of existing storage, if any */ + List* partIndexOldPSortOid; /* partition psort oid, if any */ + Node* partClause; /* partition index define */ + + /* @hdfs + * is a partitioned index? The foreign table dose not index. The isPartitioned + * value is false when relation is a foreign table. + */ + bool isPartitioned; + bool isGlobal; /* is GLOBAL partition index */ + bool unique; /* is index unique? */ + bool primary; /* is index a primary key? */ + bool isconstraint; /* is it for a pkey/unique constraint? */ + bool deferrable; /* is the constraint DEFERRABLE? */ + bool initdeferred; /* is the constraint INITIALLY DEFERRED? */ + bool concurrent; /* should this be a concurrent index build? */ + InformationalConstraint* inforConstraint; /* Soft constraint info, Currently only the HDFS foreign table support it + */ + + /* + * Internal_flag is set to true when we use informational constraint feature, + * at the same time not_enforeced is also set to true. + */ + bool internal_flag; + /* + * For memory adapation, we will check the size of table before index create, + * but if it's constraint index during table creation, we don't need to do the size + * check, so set this flag to skip this + */ + bool skip_mem_check; + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; +} IndexStmt; + +/* ---------------------- + * Create Function Statement + * ---------------------- + */ +typedef struct CreateFunctionStmt { + NodeTag type; + bool isOraStyle; /* T => A db compatible function or procedure */ + bool replace; /* T => replace if already exists */ + List* funcname; /* qualified name of function to create */ + List* parameters; /* a list of FunctionParameter */ + TypeName* returnType; /* the return type */ + List* options; /* a list of DefElem */ + List* withClause; /* a list of DefElem */ + bool isProcedure; /* true if it is a procedure */ +} CreateFunctionStmt; + +typedef struct AlterFunctionStmt { + NodeTag type; + FuncWithArgs* func; /* name and args of function */ + List* actions; /* list of DefElem */ +} AlterFunctionStmt; + +/* ---------------------- + * DO Statement + * + * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API + * ---------------------- + */ +typedef struct DoStmt { + NodeTag type; + List* args; /* List of DefElem nodes */ +} DoStmt; + +typedef struct InlineCodeBlock { + NodeTag type; + char* source_text; /* source text of anonymous code block */ + Oid langOid; /* OID of selected language */ + bool langIsTrusted; /* trusted property of the language */ + bool atomic; /* Atomic execution context, does not allow transactions */ +} InlineCodeBlock; + +typedef struct CallContext +{ + NodeTag type; + bool atomic; /* Atomic execution context, does not allow transactions */ +} CallContext; + +/* ---------------------- + * Alter Object Rename Statement + * ---------------------- + */ +typedef struct RenameStmt { + NodeTag type; + ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */ + ObjectType relationType; /* if column name, associated relation type */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* subname; /* name of contained object (column, rule, + * trigger, etc) */ + char* newname; /* the new name */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing_ok; /* skip error if missing? */ +} RenameStmt; + +/* ---------------------- + * ALTER object SET SCHEMA Statement + * ---------------------- + */ +typedef struct AlterObjectSchemaStmt { + NodeTag type; + ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* addname; /* additional name if needed */ + char* newschema; /* the new schema */ + bool missing_ok; /* skip error if missing? */ +} AlterObjectSchemaStmt; + +/* ---------------------- + * Alter Object Owner Statement + * ---------------------- + */ +typedef struct AlterOwnerStmt { + NodeTag type; + ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* addname; /* additional name if needed */ + char* newowner; /* the new owner */ +} AlterOwnerStmt; + +/* ---------------------- + * Create Rule Statement + * ---------------------- + */ +typedef struct RuleStmt { + NodeTag type; + RangeVar* relation; /* relation the rule is for */ + char* rulename; /* name of the rule */ + Node* whereClause; /* qualifications */ + CmdType event; /* SELECT, INSERT, etc */ + bool instead; /* is a 'do instead'? */ + List* actions; /* the action statements */ + bool replace; /* OR REPLACE */ + char* sql_statement; /* used for resize rule */ +} RuleStmt; + +/* ---------------------- + * Notify Statement + * ---------------------- + */ +typedef struct NotifyStmt { + NodeTag type; + char* conditionname; /* condition name to notify */ + char* payload; /* the payload string, or NULL if none */ +} NotifyStmt; + +/* ---------------------- + * Listen Statement + * ---------------------- + */ +typedef struct ListenStmt { + NodeTag type; + char* conditionname; /* condition name to listen on */ +} ListenStmt; + +/* ---------------------- + * Unlisten Statement + * ---------------------- + */ +typedef struct UnlistenStmt { + NodeTag type; + char* conditionname; /* name to unlisten on, or NULL for all */ +} UnlistenStmt; + +/* ---------------------- + * Create Type Statement, composite types + * ---------------------- + */ +typedef struct CompositeTypeStmt { + NodeTag type; + RangeVar* typevar; /* the composite type to be created */ + List* coldeflist; /* list of ColumnDef nodes */ +} CompositeTypeStmt; + +/* ---------------------- + * Create Type Statement, enum types + * ---------------------- + */ +typedef struct CreateEnumStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + List* vals; /* enum values (list of Value strings) */ +} CreateEnumStmt; + +/* ---------------------- + * Create Type Statement, range types + * ---------------------- + */ +typedef struct CreateRangeStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + List* params; /* range parameters (list of DefElem) */ +} CreateRangeStmt; + +/* ---------------------- + * Alter Type Statement, enum types + * ---------------------- + */ +typedef struct AlterEnumStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + char* oldVal; /* old enum value's name, if renaming */ + char* newVal; /* new enum value's name */ + char* newValNeighbor; /* neighboring enum value, if specified */ + bool newValIsAfter; /* place new enum value after neighbor? */ + bool skipIfNewValExists; /* no error if new already exists? */ +} AlterEnumStmt; + +/* ---------------------- + * Load Statement + * ---------------------- + */ +typedef struct LoadStmt { + NodeTag type; + char* filename; /* file to load */ +} LoadStmt; + +/* ---------------------- + * Createdb Statement + * ---------------------- + */ +typedef struct CreatedbStmt { + NodeTag type; + char* dbname; /* name of database to create */ + List* options; /* List of DefElem nodes */ +} CreatedbStmt; + +/* ---------------------- + * Alter Database + * ---------------------- + */ +typedef struct AlterDatabaseStmt { + NodeTag type; + char* dbname; /* name of database to alter */ + List* options; /* List of DefElem nodes */ +} AlterDatabaseStmt; + +/* ---------------------- + * Dropdb Statement + * ---------------------- + */ +typedef struct DropdbStmt { + NodeTag type; + char* dbname; /* database to drop */ + bool missing_ok; /* skip error if db is missing? */ +} DropdbStmt; + +#ifndef ENABLE_MULTIPLE_NODES +/* ---------------------- + * Alter System Statement + * ---------------------- + */ +typedef struct AlterSystemStmt { + NodeTag type; + VariableSetStmt *setstmt; /* SET subcommand */ +} AlterSystemStmt; +#endif +/* ---------------------- + * Cluster Statement (support pbrown's cluster index implementation) + * ---------------------- + */ +typedef struct ClusterStmt { + NodeTag type; + RangeVar* relation; /* relation being indexed, or NULL if all */ + char* indexname; /* original index defined */ + bool verbose; /* print progress info */ + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ +} ClusterStmt; + +/* ---------------------- + * Vacuum and Analyze Statements + * + * Even though these are nominally two statements, it's convenient to use + * just one node type for both. Note that at least one of VACOPT_VACUUM + * and VACOPT_ANALYZE must be set in options. VACOPT_FREEZE is an internal + * convenience for the grammar and is not examined at runtime --- the + * freeze_min_age and freeze_table_age fields are what matter. + * ---------------------- + */ +typedef enum VacuumOption { + VACOPT_VACUUM = 1 << 0, /* do VACUUM */ + VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */ + VACOPT_VERBOSE = 1 << 2, /* print progress info */ + VACOPT_FREEZE = 1 << 3, /* FREEZE option */ + VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */ + VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */ + VACOPT_MERGE = 1 << 6, /* move data from delta table to main table */ + VACOPT_MULTICOLUMN = 1 << 7, + VACOPT_VERIFY = 1 << 8, /* VERITY to check the data file */ + VACOPT_FAST = 1 << 9, /* verify fast option */ + VACOPT_COMPLETE = 1 << 10, /* verify complete option */ +#ifdef ENABLE_MOT + VACOPT_AUTOVAC = 1 << 11, /* mark automatic vacuum initiation */ +#endif + VACOPT_COMPACT = 1 << 30, /* compact hdfs file with invalid data just for DFS table */ + VACOPT_HDFSDIRECTORY = 1 << 31 /* just clean empty hdfs directory */ +} VacuumOption; + +#define DEFAULT_SAMPLE_ROWCNT 30000 +#define ANALYZE_MODE_MAX_NUM 4 +#define GET_ESTTOTALROWCNTS_FLAG ((double)(-1.0)) +#define INVALID_ESTTOTALROWS ((double)(-1.0)) + +/* + * Currently, the HDFS table need collect three statistics information + * in pg_statistic. we define AnalyzeMode enum strunct to realize global + * analyze. + * ANALYZENORMAL: Execute normal analyze command. + * ANALYZEMAIN: Collect only HDFS table information when execute global analyze. + * ANALYZEDELTA: Collect only Delta table information when execute global analyze. + * ANALYZECOMPLEX: Collect HDFS table and Delta table information when execute global analyze. + */ +typedef enum AnalyzeMode { ANALYZENORMAL = 0, ANALYZEMAIN = 1, ANALYZEDELTA = 2, ANALYZECOMPLEX = 3 } AnalyzeMode; + +typedef struct GlobalStatInfoEx { + AnalyzeMode eAnalyzeMode; /* The mode of table whitch will collect stat info, normal table or HDFS table. + It need collect three statistics information for HDFS table. */ + double sampleRate; /* CN compute it and send to DN. */ + double secsamplerows; /* real sample rows num for second sampling. */ + bool isReplication; /* the current relation is replication or not. */ + bool exec_query; /* do query for dfs table and delta table to get sample or not according to the ratio with rows of + complex. */ + double totalRowCnts; /* How many tuples receive from DN. */ + int64 topRowCnts; /* Top tuple numbers receive from DN. */ + int64 topMemSize; /* memory_size(KB)=com_size*oneTupleSize for DN, top memory size of all DNs for CN. */ + int attnum; /* column num for current table. */ + double dn1totalRowCnts; /* reltuples from DN1. */ + double* dndistinct; /* stadndistinct for DN1 */ + double* correlations; /* correlation of stats for DN1 */ + int num_samples; /* how many sample rows receive from DN. */ + HeapTuple* sampleRows; /* sample rows receive from DN. */ + TupleDesc tupleDesc; /* sample row's tuple descriptor. */ +} GlobalStatInfoEx; + +typedef enum HdfsSampleRowsFlag { + SAMPLEFLAG_DFS = 1 << 0, /* sample rows for dfs table. */ + SAMPLEFLAG_DELTA = 1 << 1, /* sample rows for delta table */ +} HdfsSampleRowsFlag; + +/* One sample row of HDFS table. */ +typedef struct { + double totalrows; /* estimate total rows */ + double samplerows; /* real sample rows num for first sampling. */ + double secsamplerows; /* real sample rows num for second sampling. */ + int8* flag; /* Identify which category(main/delta/complex) the sample row belong. */ + HeapTuple* rows; /* sample row data. */ +} HDFS_SAMPLE_ROWS; + +/* All sample rows of HDFS table for global stats. */ +typedef struct { + MemoryContext hdfs_sample_context; /* using to save sample rows. */ + double totalSampleRowCnt; /* total sample row count include dfs table and delta table */ + HDFS_SAMPLE_ROWS stHdfsSampleRows[ANALYZECOMPLEX]; /* sample rows include dfs table and delta table. */ +} GBLSTAT_HDFS_SAMPLE_ROWS; + +struct SplitMap; + +typedef struct VacuumStmt { + NodeTag type; + int options; /* OR of VacuumOption flags */ + int flags; /* flags to distinguish partition or btree */ + /* the values for this flags are in vacuum.h */ + Oid rely_oid; /* for btree, it is the heap btree or it is InvalidOid */ + int freeze_min_age; /* min freeze age, or -1 to use default */ + int freeze_table_age; /* age at which to scan whole table */ + RangeVar* relation; /* single table to process, or NULL */ + List* va_cols; /* list of column names, or NIL for all */ + + Relation onepartrel; /* for tracing the opened relation */ + Partition onepart; /* for tracing the opened partition */ + List* partList; +#ifdef PGXC + void* HDFSDnWorkFlow; /* @hdfs HDFSDnWorkFlow stores analyze operation related information */ +#endif + bool isForeignTables; /* @hdfs This parameter is true when we run "analyze [verbose] foreign table;" command */ + bool isPgFdwForeignTables; /* This parameter is true when the fdw of foreign table is gc_fdw */ +#ifdef ENABLE_MOT + bool isMOTForeignTable; +#endif + + /* + * @hdfs + * parameter totalFileCnt and nodeNo is set by CNSchedulingForAnalyze + * CNSchedulingForAnalyze( int *totalFilesCnt, + * int *nodeNo, + * Oid foreignTableId) + */ + unsigned int totalFileCnt; /* @hdfs The count of file to be sampled in analyze foreign table operation */ + int nodeNo; /* @hdfs Which data node will do analyze operation, + @global stats: Other coordinators will get statistics from which coordinator node. */ + + /* + * @hdfs total number of Data nodes, we use this number to adjust reltuples cnt stored in pg_class + * eg: We do the operation "analyze tablename", we have x data nodes and tablename is a hdfs foreign + * table. Data node finish analyze command, CN get tuples number information from DN. This number + * is 1/x of the total tuples number. We adjust this number to the real one in CN. + */ + unsigned int DnCnt; + + /* + * Add param for global stats. + */ + DestReceiver* dest; /* used to DN send sample rows to CN. */ + int num_samples; /* how many sample rows receive from DN. */ + HeapTuple* sampleRows; /* sample rows receive from DN. */ + TupleDesc tupleDesc; /* sample row's tuple descriptor for normal table. */ + int tableidx; /* set current index which table need to set sample rate or total row counts */ + GlobalStatInfoEx pstGlobalStatEx[ANALYZE_MODE_MAX_NUM - 1]; /* the auxiliary info for global stats, it extend to + identify hdfs table. */ + unsigned int orgCnNodeNo; /* the nodeId identify which CN receive analyze command from client, other CN need to get + stats from it. */ + List* hdfsforeignMapDnList; /* identify some datanodes belone to split map used for CN get total reltuples from + them. */ + bool sampleTableRequired; /* require sample table for get statistic. */ + List* tmpSampleTblNameList; /* identify sample table name if under debugging. */ + bool isAnalyzeTmpTable; /* true if analyze's table is temp table. */ +#ifdef PGXC + DistributionType disttype; /* Distribution type for analyze's table. */ +#endif + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ + Oid curVerifyRel; /* the current relation is for database mode to send remote query */ + bool isCascade; /* used to verify table */ +} VacuumStmt; +/* Only support analyze, can not support vacuum analyze in transaction block. */ +#define IS_ONLY_ANALYZE_TMPTABLE (((stmt)->isAnalyzeTmpTable) && !((stmt)->options & VACOPT_VACUUM)) + +#ifdef PGXC +/* + * ---------------------- + * Barrier Statement + */ +typedef struct BarrierStmt { + NodeTag type; + const char* id; /* User supplied barrier id, if any */ +} BarrierStmt; + +/* + * ---------------------- + * Create Node statement + */ +typedef struct CreateNodeStmt { + NodeTag type; + char* node_name; + List* options; +} CreateNodeStmt; + +/* + * ---------------------- + * Alter Node statement + */ +typedef struct AlterNodeStmt { + NodeTag type; + char* node_name; + List* options; +} AlterNodeStmt; + +typedef struct AlterCoordinatorStmt { + NodeTag type; + char* node_name; + char* set_value; + List* coor_nodes; +} AlterCoordinatorStmt; + +/* + * ---------------------- + * Drop Node statement + */ +typedef struct DropNodeStmt { + NodeTag type; + char* node_name; + bool missing_ok; /* skip error if db is missing? */ + List* remote_nodes; /* specify where to drop node remotely */ +} DropNodeStmt; + +/* + * ---------------------- + * Create Group statement + */ +typedef struct CreateGroupStmt { + NodeTag type; + char* group_name; + char* src_group_name; + List* nodes; + List* buckets; + bool vcgroup; +} CreateGroupStmt; + +/* + * ---------------------- + * Alter Group statement + */ +typedef enum { + AG_SET_DEFAULT, + AG_SET_VCGROUP, + AG_SET_NOT_VCGROUP, + AG_SET_RENAME, + AG_SET_TABLE_GROUP, + AG_SET_BUCKETS, + AG_ADD_NODES, + AG_DELETE_NODES, + AG_RESIZE_GROUP, + AG_CONVERT_VCGROUP, + AG_SET_SEQ_ALLNODES, + AG_SET_SEQ_SELFNODES +} AlterGroupType; + +typedef struct AlterGroupStmt { + NodeTag type; + char* group_name; + char* install_name; + List* nodes; + AlterGroupType alter_type; +} AlterGroupStmt; + +/* + * ---------------------- + * Drop Group statement + */ +typedef struct DropGroupStmt { + NodeTag type; + char* group_name; + char* src_group_name; + bool to_elastic_group; +} DropGroupStmt; + +/* + * ---------------------- + * Create Policy Label statement + */ +typedef struct CreatePolicyLabelStmt { + NodeTag type; + bool if_not_exists; + char* label_type; + char* label_name; + List* label_items; +} CreatePolicyLabelStmt; + +/* + * ---------------------- + * Alter Policy Label statement + */ +typedef struct AlterPolicyLabelStmt { + NodeTag type; + char* stmt_type; + char* label_name; + List* label_items; +} AlterPolicyLabelStmt; + +/* + * ---------------------- + * Drop Policy Label statement + */ +typedef struct DropPolicyLabelStmt { + NodeTag type; + bool if_exists; + List* label_names; +} DropPolicyLabelStmt; + +/* + * ---------------------- + * + */ +typedef struct PolicyFilterNode +{ + NodeTag type; + char *node_type; /* operator or filter node */ + char *op_value; /* for operator type node usage */ + char *filter_type; /* for filter type node usage */ + List *values; /* for filter type node usage */ + bool has_not_operator; /* for filter type node usage */ + Node *left; /* for operator type node usage */ + Node *right; /* for operator type node usage */ +} PolicyFilterNode; + +/* + * ---------------------- + * Create Audit Policy statement + */ +typedef struct CreateAuditPolicyStmt +{ + NodeTag type; + bool if_not_exists; + char *policy_type; + char *policy_name; + List *policy_targets; + List *policy_filters; + bool policy_enabled; +} CreateAuditPolicyStmt; + +/* + * ---------------------- + * Alter Audit Policy statement + */ +typedef struct AlterAuditPolicyStmt +{ + NodeTag type; + bool missing_ok; + char *policy_name; + char *policy_action; + char *policy_type; + List *policy_items; + List *policy_filters; + char *policy_comments; + Node *policy_enabled; +} AlterAuditPolicyStmt; + +/* + * ---------------------- + * Drop Audit Policy statement + */ +typedef struct DropAuditPolicyStmt +{ + NodeTag type; + bool missing_ok; + List *policy_names; +} DropAuditPolicyStmt; + +/* + * ---------------------- + * Masking Policy Condition + */ +typedef struct MaskingPolicyCondition +{ + NodeTag type; + RangeVar *fqdn; + char *_operator; + Node *arg; +} MaskingPolicyCondition; + +/* + * ---------------------- + * Create Masking Policy statement + */ +typedef struct CreateMaskingPolicyStmt +{ + NodeTag type; + bool if_not_exists; + char *policy_name; + List *policy_data; + Node *policy_condition; + List *policy_filters; + bool policy_enabled; +} CreateMaskingPolicyStmt; + +/* + * ---------------------- + * Alter Masking Policy statement + */ +typedef struct AlterMaskingPolicyStmt +{ + NodeTag type; + char *policy_name; + char *policy_action; + List *policy_items; + Node *policy_condition; + List *policy_filters; + char *policy_comments; + Node *policy_enabled; +} AlterMaskingPolicyStmt; + +/* + * ---------------------- + * Drop Masking Policy statement + */ +typedef struct DropMaskingPolicyStmt +{ + NodeTag type; + bool if_exists; + List *policy_names; +} DropMaskingPolicyStmt; + +/* + * ---------------------- + * Create Resource Pool statement + */ +typedef struct CreateResourcePoolStmt { + NodeTag type; + char* pool_name; + List* options; +} CreateResourcePoolStmt; + +/* + * ---------------------- + * Alter Resource Pool statement + */ +typedef struct AlterResourcePoolStmt { + NodeTag type; + char* pool_name; + List* options; +} AlterResourcePoolStmt; + +/* + * ---------------------- + * Drop Resource Pool statement + */ +typedef struct DropResourcePoolStmt { + NodeTag type; + bool missing_ok; + char* pool_name; +} DropResourcePoolStmt; + +/* + * ---------------------- + * Create Workload Group statement + */ +typedef struct CreateWorkloadGroupStmt { + NodeTag type; + char* group_name; + char* pool_name; + List* options; +} CreateWorkloadGroupStmt; + +/* + * ---------------------- + * Alter Workload Group statement + */ +typedef struct AlterWorkloadGroupStmt { + NodeTag type; + char* group_name; + char* pool_name; + List* options; +} AlterWorkloadGroupStmt; + +/* + * ---------------------- + * Drop Workload Group statement + */ +typedef struct DropWorkloadGroupStmt { + NodeTag type; + bool missing_ok; + char* group_name; +} DropWorkloadGroupStmt; + +/* + * ---------------------- + * Create App Workload Group Mapping statement + */ +typedef struct CreateAppWorkloadGroupMappingStmt { + NodeTag type; + char* app_name; + List* options; +} CreateAppWorkloadGroupMappingStmt; + +/* + * ---------------------- + * Alter App Workload Group Mapping statement + */ +typedef struct AlterAppWorkloadGroupMappingStmt { + NodeTag type; + char* app_name; + List* options; +} AlterAppWorkloadGroupMappingStmt; + +/* + * ---------------------- + * Drop App Workload Group Mapping statement + */ +typedef struct DropAppWorkloadGroupMappingStmt { + NodeTag type; + bool missing_ok; + char* app_name; +} DropAppWorkloadGroupMappingStmt; + +#endif + +struct PlanInformation; +/* ---------------------- + * Explain Statement + * + * The "query" field is either a raw parse tree (SelectStmt, InsertStmt, etc) + * or a Query node if parse analysis has been done. Note that rewriting and + * planning of the query are always postponed until execution of EXPLAIN. + * ---------------------- + */ +typedef struct ExplainStmt { + NodeTag type; + Node* statement; /* statement_id for EXPLAIN PLAN */ + Node* query; /* the query (see comments above) */ + List* options; /* list of DefElem nodes */ + PlanInformation* planinfo; +} ExplainStmt; + +/* ---------------------- + * CREATE TABLE AS Statement (a/k/a SELECT INTO) + * + * A query written as CREATE TABLE AS will produce this node type natively. + * A query written as SELECT ... INTO will be transformed to this form during + * parse analysis. + * A query written as CREATE MATERIALIZED view will produce this node type, + * during parse analysis, since it needs all the same data. + * + * The "query" field is handled similarly to EXPLAIN, though note that it + * can be a SELECT or an EXECUTE, but not other DML statements. + * ---------------------- + */ +typedef struct CreateTableAsStmt { + NodeTag type; + Node* query; /* the query (see comments above) */ + IntoClause* into; /* destination table */ + ObjectType relkind; /* type of object */ + bool is_select_into; /* it was written as SELECT INTO */ +#ifdef PGXC + Oid groupid; + void* parserSetup; + void* parserSetupArg; +#endif +} CreateTableAsStmt; + +/* ---------------------- + * REFRESH MATERIALIZED VIEW Statement + * ---------------------- + */ +typedef struct RefreshMatViewStmt +{ + NodeTag type; + bool skipData; /* true for WITH NO DATA */ + bool incremental; /* true for INCREMENTALLY */ + RangeVar *relation; /* relation to insert into */ +} RefreshMatViewStmt; + +/* ---------------------- + * Checkpoint Statement + * ---------------------- + */ +typedef struct CheckPointStmt { + NodeTag type; +} CheckPointStmt; + +/* ---------------------- + * Discard Statement + * ---------------------- + */ +typedef enum DiscardMode { DISCARD_ALL, DISCARD_PLANS, DISCARD_TEMP } DiscardMode; + +typedef struct DiscardStmt { + NodeTag type; + DiscardMode target; +} DiscardStmt; + +/* ---------------------- + * LOCK Statement + * ---------------------- + */ +typedef struct LockStmt { + NodeTag type; + List* relations; /* relations to lock */ + int mode; /* lock mode */ + bool nowait; /* no wait mode */ +} LockStmt; + +/* ---------------------- + * SET CONSTRAINTS Statement + * ---------------------- + */ +typedef struct ConstraintsSetStmt { + NodeTag type; + List* constraints; /* List of names as RangeVars */ + bool deferred; +} ConstraintsSetStmt; + +#ifdef ENABLE_MOT +typedef struct ReindexForeignStmt { + NodeTag type; + char relkind; + Oid reloid; + Oid indexoid; + char* name; +} ReindexForeignStmt; +#endif + +/* ---------------------- + * CREATE CONVERSION Statement + * ---------------------- + */ +typedef struct CreateConversionStmt { + NodeTag type; + List* conversion_name; /* Name of the conversion */ + char* for_encoding_name; /* source encoding name */ + char* to_encoding_name; /* destination encoding name */ + List* func_name; /* qualified conversion function name */ + bool def; /* is this a default conversion? */ +} CreateConversionStmt; + +/* ---------------------- + * CREATE CAST Statement + * ---------------------- + */ +typedef struct CreateCastStmt { + NodeTag type; + TypeName* sourcetype; + TypeName* targettype; + FuncWithArgs* func; + CoercionContext context; + bool inout; +} CreateCastStmt; + +/* ---------------------- + * DEALLOCATE Statement + * ---------------------- + */ +typedef struct DeallocateStmt { + NodeTag type; + char* name; /* The name of the plan to remove */ + /* NULL means DEALLOCATE ALL */ +} DeallocateStmt; + +/* + * DROP OWNED statement + */ +typedef struct DropOwnedStmt { + NodeTag type; + List* roles; + DropBehavior behavior; +} DropOwnedStmt; + +/* + * REASSIGN OWNED statement + */ +typedef struct ReassignOwnedStmt { + NodeTag type; + List* roles; + char* newrole; +} ReassignOwnedStmt; + +/* + * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default + */ +typedef struct AlterTSDictionaryStmt { + NodeTag type; + List* dictname; /* qualified name (list of Value strings) */ + List* options; /* List of DefElem nodes */ +} AlterTSDictionaryStmt; + +/* + * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default + */ +typedef struct AlterTSConfigurationStmt { + NodeTag type; + List* cfgname; /* qualified name (list of Value strings) */ + + /* + * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is + * NIL, but tokentype isn't, DROP MAPPING was specified. + */ + List* tokentype; /* list of Value strings */ + List* dicts; /* list of list of Value strings */ + List* cfoptions; /* list of configuration options */ + bool override; /* if true - remove old variant */ + bool replace; /* if true - replace dictionary by another */ + bool missing_ok; /* for DROP - skip error if missing? */ + bool is_reset; /* if true - reset options */ +} AlterTSConfigurationStmt; + +/* + * CLEAN CONNECTION statement + */ +typedef struct CleanConnStmt { + NodeTag type; + List* nodes; /* list of nodes dropped */ + char* dbname; /* name of database to drop connections */ + char* username; /* name of user whose connections are dropped */ + bool is_coord; /* type of connections dropped */ + bool is_force; /* option force */ + bool is_check; /* option check */ +} CleanConnStmt; + +/* + * CreateTableLike Context + */ +typedef struct TableLikeCtx { + NodeTag type; + bits32 options; /* OR of TableLikeOption flags */ + bool temp_table; /* temporary table or not */ + bool hasoids; /* has oids or not */ + List* columns; /* the list of ColumnDef */ + List* ckconstraints; + List* comments; + List* cluster_keys; + PartitionState* partition; + List* inh_indexes; + List* reloptions; +} TableLikeCtx; + +typedef struct CreateDirectoryStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + char* directoryname; /* the name of directory to create */ + char* owner; /* directory's owner */ + char* location; /* the real path of directory */ +} CreateDirectoryStmt; + +typedef struct AlterDirectoryStmt { + NodeTag type; + char* directoryname; /* the name of directory to create */ + char* owner; /* directory's owner */ + char* location; /* the real path of directory */ + List* options; /* list of options */ +} AlterDirectoryStmt; + +typedef struct DropDirectoryStmt { + NodeTag type; + char* directoryname; /* the name of directory to drop */ + bool missing_ok; /* skip error if db is missing? */ + +} DropDirectoryStmt; +#endif /* PARSENODES_H */ + diff -uprN postgresql-hll-2.14_old/include/include/nodes/pg_list.h postgresql-hll-2.14/include/include/nodes/pg_list.h --- postgresql-hll-2.14_old/include/include/nodes/pg_list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/pg_list.h 2020-12-12 17:06:43.232347845 +0800 @@ -0,0 +1,398 @@ +/* ------------------------------------------------------------------------- + * + * pg_list.h + * interface for PostgreSQL generic linked list package + * + * This package implements singly-linked homogeneous lists. + * + * It is important to have constant-time length, append, and prepend + * operations. To achieve this, we deal with two distinct data + * structures: + * + * 1. A set of "list cells": each cell contains a data field and + * a link to the next cell in the list or NULL. + * 2. A single structure containing metadata about the list: the + * type of the list, pointers to the head and tail cells, and + * the length of the list. + * + * We support three types of lists: + * + * T_List: lists of pointers + * (in practice usually pointers to Nodes, but not always; + * declared as "void *" to minimize casting annoyances) + * T_IntList: lists of integers + * T_OidList: lists of Oids + * + * (At the moment, ints and Oids are the same size, but they may not + * always be so; try to be careful to maintain the distinction.) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/pg_list.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LIST_H +#define PG_LIST_H + +#include "nodes/nodes.h" + +typedef struct ListCell ListCell; + +typedef struct DListCell DListCell; + +typedef struct List { + NodeTag type; /* T_List, T_IntList, or T_OidList */ + int length; + ListCell* head; + ListCell* tail; +} List; + +struct ListCell { + union { + void* ptr_value; + int int_value; + Oid oid_value; + } data; + ListCell* next; +}; + +typedef struct DList { + NodeTag type; + int length; + DListCell* head; + DListCell* tail; +} DList; + +struct DListCell { + union { + void* ptr_value; + int int_value; + Oid oid_value; + } data; + DListCell* next; + DListCell* prev; +}; + +/* + * The *only* valid representation of an empty list is NIL; in other + * words, a non-NIL list is guaranteed to have length >= 1 and + * head/tail != NULL + */ +#define NIL ((List*)NULL) + +/* + * These routines are used frequently. However, we can't implement + * them as macros, since we want to avoid double-evaluation of macro + * arguments. Therefore, we implement them using static inline functions + * if supported by the compiler, or as regular functions otherwise. + */ +#ifdef USE_INLINE + +static inline ListCell* list_head(const List* l) +{ + return l ? l->head : NULL; +} + +static inline ListCell* list_tail(List* l) +{ + return l ? l->tail : NULL; +} + +static inline int list_length(const List* l) +{ + return l ? l->length : 0; +} + +static inline DListCell* dlist_head_cell(const DList* l) +{ + return l ? l->head : NULL; +} + +static inline DListCell* dlist_tail_cell(DList* l) +{ + return l ? l->tail : NULL; +} + +#else + +extern ListCell* list_head(const List* l); +extern ListCell* list_tail(List* l); +extern int list_length(const List* l); + +extern ListCell *dlist_head_cell(const DList *l); +extern ListCell *dlist_tail_cell(DList *l); + +#endif /* USE_INLINE */ + +/* + * NB: There is an unfortunate legacy from a previous incarnation of + * the List API: the macro lfirst() was used to mean "the data in this + * cons cell". To avoid changing every usage of lfirst(), that meaning + * has been kept. As a result, lfirst() takes a ListCell and returns + * the data it contains; to get the data in the first cell of a + * List, use linitial(). Worse, lsecond() is more closely related to + * linitial() than lfirst(): given a List, lsecond() returns the data + * in the second cons cell. + */ +#define lnext(lc) ((lc)->next) +#define lprev(lc) ((lc)->prev) +#define lfirst(lc) ((lc)->data.ptr_value) +#define lfirst_int(lc) ((lc)->data.int_value) +#define lfirst_oid(lc) ((lc)->data.oid_value) +#define lfirst_node(type, lc) castNode(type, lfirst(lc)) + +#define linitial(l) lfirst(list_head(l)) +#define linitial_int(l) lfirst_int(list_head(l)) +#define linitial_oid(l) lfirst_oid(list_head(l)) +#define linitial_node(type, l) castNode(type, linitial(l)) + +#define lsecond(l) lfirst(lnext(list_head(l))) +#define lsecond_int(l) lfirst_int(lnext(list_head(l))) +#define lsecond_oid(l) lfirst_oid(lnext(list_head(l))) +#define lsecond_node(type, l) castNode(type, lsecond(l)) + +#define lthird(l) lfirst(lnext(lnext(list_head(l)))) +#define lthird_int(l) lfirst_int(lnext(lnext(list_head(l)))) +#define lthird_oid(l) lfirst_oid(lnext(lnext(list_head(l)))) +#define lthird_node(type, l) castNode(type, lthird(l)) + +#define lfourth(l) lfirst(lnext(lnext(lnext(list_head(l))))) +#define lfourth_int(l) lfirst_int(lnext(lnext(lnext(list_head(l))))) +#define lfourth_oid(l) lfirst_oid(lnext(lnext(lnext(list_head(l))))) +#define lfourth_node(type, l) castNode(type, lfourth(l)) + +#define llast(l) lfirst(list_tail(l)) +#define llast_int(l) lfirst_int(list_tail(l)) +#define llast_oid(l) lfirst_oid(list_tail(l)) +#define llast_node(type, l) castNode(type, llast(l)) + +/* + * Convenience macros for building fixed-length lists + */ +#define list_make1(x1) lcons(x1, NIL) +#define list_make2(x1, x2) lcons(x1, list_make1(x2)) +#define list_make3(x1, x2, x3) lcons(x1, list_make2(x2, x3)) +#define list_make4(x1, x2, x3, x4) lcons(x1, list_make3(x2, x3, x4)) + +#define list_make1_int(x1) lcons_int(x1, NIL) +#define list_make2_int(x1, x2) lcons_int(x1, list_make1_int(x2)) +#define list_make3_int(x1, x2, x3) lcons_int(x1, list_make2_int(x2, x3)) +#define list_make4_int(x1, x2, x3, x4) lcons_int(x1, list_make3_int(x2, x3, x4)) + +#define list_make1_oid(x1) lcons_oid(x1, NIL) +#define list_make2_oid(x1, x2) lcons_oid(x1, list_make1_oid(x2)) +#define list_make3_oid(x1, x2, x3) lcons_oid(x1, list_make2_oid(x2, x3)) +#define list_make4_oid(x1, x2, x3, x4) lcons_oid(x1, list_make3_oid(x2, x3, x4)) + +/* + * foreach - + * a convenience macro which loops through the list + */ +#define foreach(cell, l) for ((cell) = list_head(l); (cell) != NULL; (cell) = lnext(cell)) + +#define foreach_cell(cell, l) for (ListCell* cell = list_head(l); cell != NULL; cell = lnext(cell)) + +#define dlist_foreach_cell(cell, l) \ + for ((cell) = dlist_head_cell(l); (cell) != NULL; (cell) = lnext(cell)) + +/* + * for_each_cell - + * a convenience macro which loops through a list starting from a + * specified cell + */ +#define for_each_cell(cell, initcell) for ((cell) = (initcell); (cell) != NULL; (cell) = lnext(cell)) + +/* + * forboth - + * a convenience macro for advancing through two linked lists + * simultaneously. This macro loops through both lists at the same + * time, stopping when either list runs out of elements. Depending + * on the requirements of the call site, it may also be wise to + * assert that the lengths of the two lists are equal. + */ +#define forboth(cell1, list1, cell2, list2) \ + for ((cell1) = list_head(list1), (cell2) = list_head(list2); (cell1) != NULL && (cell2) != NULL; \ + (cell1) = lnext(cell1), (cell2) = lnext(cell2)) + +/* + * forthree - + * the same for three lists + */ +#define forthree(cell1, list1, cell2, list2, cell3, list3) \ + for ((cell1) = list_head(list1), (cell2) = list_head(list2), (cell3) = list_head(list3); \ + (cell1) != NULL && (cell2) != NULL && (cell3) != NULL; \ + (cell1) = lnext(cell1), (cell2) = lnext(cell2), (cell3) = lnext(cell3)) + +extern DList* dlappend(DList* dlist, void* datum); + +extern List* lappend(List* list, void* datum); +extern List* lappend2(List* list, ListCell* cell); +extern List* lappend3(List*, List*); +extern List* lappend_int(List* list, int datum); +extern List* lappend_oid(List* list, Oid datum); + +extern ListCell* lappend_cell(List* list, ListCell* prev, void* datum); +extern ListCell* lappend_cell_int(List* list, ListCell* prev, int datum); +extern ListCell* lappend_cell_oid(List* list, ListCell* prev, Oid datum); + +extern List* lcons(void* datum, List* list); +extern List* lcons_int(int datum, List* list); +extern List* lcons_oid(Oid datum, List* list); + +extern List* list_concat(List* list1, List* list2); +extern List* list_truncate(List* list, int new_size); + +extern void* list_nth(const List* list, int n); +extern ListCell* list_nth_cell(const List* list, int n); +extern int list_nth_int(const List* list, int n); +extern Oid list_nth_oid(const List* list, int n); +#define list_nth_node(type, list, n) castNode(type, list_nth(list, n)) + +extern bool list_member(const List* list, const void* datum); +extern bool list_member_ptr(const List* list, const void* datum); +extern bool list_member_int(const List* list, int datum); +extern bool list_member_oid(const List* list, Oid datum); + +extern List* list_delete(List* list, const void* datum); +extern List* list_delete_ptr(List* list, const void* datum); +extern List* list_delete_int(List* list, int datum); +extern List* list_delete_oid(List* list, Oid datum); +extern List* list_delete_first(List* list); +extern List* list_delete_first_nofree(List* list); +extern List* list_delete_cell(List* list, ListCell* cell, ListCell* prev); +extern List* list_delete_cell2(List* list, ListCell* cell); +extern List *list_delete_name(List *list, const char* name); + +extern DList* dlist_delete_cell(DList* dlist, DListCell* cell, bool deep); + +extern List* RemoveListCell(List* list, int pos); + +typedef bool (*NodeMatchFunc)(void* val1, void* val2); +typedef void (*NodeHandler)(void*); +extern List* list_cell_clear(List* list, void* val, NodeMatchFunc is_match); +extern List* list_cell_handle(List* list, NodeHandler handle, bool removed); + +extern List* list_union(const List* list1, const List* list2); +extern List* list_union_ptr(const List* list1, const List* list2); +extern List* list_union_int(const List* list1, const List* list2); +extern List* list_union_oid(const List* list1, const List* list2); +extern List* list_intersection_int(const List* list1, const List* list2); +extern bool list_is_subset(List* list1, List* list2); + +#ifdef PGXC +/* Well... this is used by Postgres-XC */ +extern List* list_intersection_int(const List* list1, const List* list2); +#endif +extern List* list_intersection(const List* list1, const List* list2); + +/* currently, there's no need for list_intersection_int etc */ +extern List* list_difference(const List* list1, const List* list2); +extern List* list_difference_ptr(const List* list1, const List* list2); +extern List* list_difference_int(const List* list1, const List* list2); +extern List* list_difference_oid(const List* list1, const List* list2); + +extern List* list_append_unique(List* list, void* datum); +extern List* list_append_unique_ptr(List* list, void* datum); +extern List* list_append_unique_int(List* list, int datum); +extern List* list_append_unique_oid(List* list, Oid datum); + +extern List* list_concat_unique(List* list1, List* list2); +extern List* list_concat_unique_ptr(List* list1, List* list2); +extern List* list_concat_unique_int(List* list1, List* list2); +extern List* list_concat_unique_oid(List* list1, List* list2); + +extern void dlist_free(DList* list, bool deep); + +extern void list_free(List* list); +extern void list_free_deep(List* list); + +#define list_free_ext(list) \ + do { \ + if ((list) != NIL) { \ + list_free(list); \ + list = NIL; \ + } \ + } while (0) + +extern List* list_copy(const List* list); +extern List* list_copy_tail(const List* list, int nskip); + +extern void dlist_add_tail_cell(DList* dlist, DListCell* cell); +extern List* list_merge_int(List* list1, List* list2); +extern List* list_insert_nth_oid(List *list, int pos, Oid datum); + +/* + * To ease migration to the new list API, a set of compatibility + * macros are provided that reduce the impact of the list API changes + * as far as possible. Until client code has been rewritten to use the + * new list API, the ENABLE_LIST_COMPAT symbol can be defined before + * including pg_list.h + */ +#ifdef ENABLE_LIST_COMPAT + +#define lfirsti(lc) lfirst_int(lc) +#define lfirsto(lc) lfirst_oid(lc) + +#define makeList1(x1) list_make1(x1) +#define makeList2(x1, x2) list_make2(x1, x2) +#define makeList3(x1, x2, x3) list_make3(x1, x2, x3) +#define makeList4(x1, x2, x3, x4) list_make4(x1, x2, x3, x4) + +#define makeListi1(x1) list_make1_int(x1) +#define makeListi2(x1, x2) list_make2_int(x1, x2) + +#define makeListo1(x1) list_make1_oid(x1) +#define makeListo2(x1, x2) list_make2_oid(x1, x2) + +#define lconsi(datum, list) lcons_int(datum, list) +#define lconso(datum, list) lcons_oid(datum, list) + +#define lappendi(list, datum) lappend_int(list, datum) +#define lappendo(list, datum) lappend_oid(list, datum) + +#define nconc(l1, l2) list_concat(l1, l2) + +#define nth(n, list) list_nth(list, n) + +#define member(datum, list) list_member(list, datum) +#define ptrMember(datum, list) list_member_ptr(list, datum) +#define intMember(datum, list) list_member_int(list, datum) +#define oidMember(datum, list) list_member_oid(list, datum) + +/* + * Note that the old lremove() determined equality via pointer + * comparison, whereas the new list_delete() uses equal(); in order to + * keep the same behavior, we therefore need to map lremove() calls to + * list_delete_ptr() rather than list_delete() + */ +#define lremove(elem, list) list_delete_ptr(list, elem) +#define LispRemove(elem, list) list_delete(list, elem) +#define lremovei(elem, list) list_delete_int(list, elem) +#define lremoveo(elem, list) list_delete_oid(list, elem) + +#define ltruncate(n, list) list_truncate(list, n) + +#define set_union(l1, l2) list_union(l1, l2) +#define set_uniono(l1, l2) list_union_oid(l1, l2) +#define set_ptrUnion(l1, l2) list_union_ptr(l1, l2) + +#define set_difference(l1, l2) list_difference(l1, l2) +#define set_differenceo(l1, l2) list_difference_oid(l1, l2) +#define set_ptrDifference(l1, l2) list_difference_ptr(l1, l2) + +#define equali(l1, l2) equal(l1, l2) +#define equalo(l1, l2) equal(l1, l2) + +#define freeList(list) list_free(list) + +#define listCopy(list) list_copy(list) + +extern int length(List* list); +#endif /* ENABLE_LIST_COMPAT */ + +extern int dlength(DList* list); + +#endif /* PG_LIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/plannodes.h postgresql-hll-2.14/include/include/nodes/plannodes.h --- postgresql-hll-2.14_old/include/include/nodes/plannodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/plannodes.h 2020-12-12 17:06:43.233347858 +0800 @@ -0,0 +1,1392 @@ +/* ------------------------------------------------------------------------- + * + * plannodes.h + * definitions for query plan nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/plannodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANNODES_H +#define PLANNODES_H + +#include "access/sdir.h" +#include "foreign/foreign.h" +#include "nodes/bitmapset.h" +#include "nodes/primnodes.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "optimizer/pruning.h" +#include "pgxc/locator.h" +#include "pgxc/nodemgr.h" +#include "bulkload/dist_fdw.h" +#include "utils/bloom_filter.h" + +#define MAX_SPECIAL_BUCKETMAP_NUM 2 +#define BUCKETMAP_DEFAULT_INDEX -1 + +/* + * Determines if query has to be launched + * on Coordinators only (SEQUENCE DDL), + * on Datanodes (normal Remote Queries), + * or on all Postgres-XC nodes (Utilities and DDL). + */ +typedef enum +{ + EXEC_ON_DATANODES, + EXEC_ON_COORDS, + EXEC_ON_ALL_NODES, + EXEC_ON_NONE +} RemoteQueryExecType; + +#define EXEC_CONTAIN_COORDINATOR(exec_type) \ + ((exec_type) == EXEC_ON_ALL_NODES || (exec_type) == EXEC_ON_COORDS) + +#define EXEC_CONTAIN_DATANODE(exec_type) \ + ((exec_type) == EXEC_ON_ALL_NODES || (exec_type) == EXEC_ON_DATANODES) + +/* + * Determines the position where the RemoteQuery node will run. + */ +typedef enum { GATHER, PLAN_ROUTER, SCAN_GATHER } RemoteQueryType; + +/* + * @hdfs + * Determines the optimization mode base on informational constraint. + * Currently, join Scan and foreign scan about on HDFS foreign table + * would be optimized. + */ +typedef enum { INVALID_MODE, SCAN_OPTIMIZE_MODE, JOIN_OPTIMIZE_MODE } OptimizedMode; +/* ---------------------------------------------------------------- + * node definitions + * ---------------------------------------------------------------- + */ + +typedef struct NodeGroupQueryMem { + Oid ng_oid; + char nodegroup[NAMEDATALEN]; + + int query_mem[2]; /* memory in kb */ +} NodeGroupQueryMem; + +/* ---------------- + * PlannedStmt node + * + * The output of the planner is a Plan tree headed by a PlannedStmt node. + * PlannedStmt holds the "one time" information needed by the executor. + * ---------------- + */ +typedef struct PlannedStmt { + NodeTag type; + + CmdType commandType; /* select|insert|update|delete */ + + uint64 queryId; /* query identifier, uniquely indicate this plan in Runtime (copied from Query) */ + + bool hasReturning; /* is it insert|update|delete RETURNING? */ + + bool hasModifyingCTE; /* has insert|update|delete in WITH? */ + + bool canSetTag; /* do I set the command result tag? */ + + bool transientPlan; /* redo plan when TransactionXmin changes? */ + + bool dependsOnRole; /* is plan specific to current role? */ + + Plan* planTree; /* tree of Plan nodes */ + + List* rtable; /* list of RangeTblEntry nodes */ + + /* rtable indexes of target relations for INSERT/UPDATE/DELETE */ + List* resultRelations; /* integer list of RT indexes, or NIL */ + + Node* utilityStmt; /* non-null if this is DECLARE CURSOR */ + + List* subplans; /* Plan trees for SubPlan expressions */ + + Bitmapset* rewindPlanIDs; /* indices of subplans that require REWIND */ + + List* rowMarks; /* a list of PlanRowMark's */ + + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the plan depends on */ + + List* invalItems; /* other dependencies, as PlanInvalItems */ + + int nParamExec; /* number of PARAM_EXEC Params used */ + + int num_streams; /* number of stream exist in plan tree */ + + int max_push_sql_num; /* number of split sql want push DN execute */ + + int gather_count; /* gather_count in query */ + + int num_nodes; /* number of data nodes */ + + NodeDefinition* nodesDefinition; /* all data nodes' defination */ + + int instrument_option; /* used for collect instrument data */ + + int num_plannodes; /* how many plan node in this planstmt */ + + int query_mem[2]; /* how many memory the query can use , memory in kb */ + + int assigned_query_mem[2]; /* how many memory the query is assigned */ + + bool is_dynmaic_smp; + + int dynsmp_max_cpu; /* max avaliable cpu for this dn */ + + int dynsmp_avail_cpu; /* max avaliable cpu for this dn */ + + int dynsmp_cpu_util; + + int dynsmp_active_statement; + + double dynsmp_query_estimate_cpu_usge; + + int dynsmp_plan_optimal_dop; /* the final optimized dop for the plan */ + + int dynsmp_plan_original_dop; + + int dynsmp_dop_mem_limit; /* memory will put a limit on dop */ + + int dynsmp_min_non_spill_dop; /* optimal dop cannot greater than this */ + + int num_bucketmaps; /* Num of special-bucketmap stored in plannedstmt */ + + uint2* bucketMap[MAX_SPECIAL_BUCKETMAP_NUM]; /* the map information need to be get */ + + char* query_string; /* convey the query string to backend/stream thread of DataNode for debug purpose */ + + List* subplan_ids; /* in which plan id subplan should be inited */ + + List* initPlan; /* initplan in top plan node */ + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + */ + Index dataDestRelIndex; + + int MaxBloomFilterNum; + + int query_dop; /* Dop of current query. */ + + double plannertime; /* planner execute time */ + + /* set true in do_query_for_planrouter() for PlannedStmt sent to + * the compute pool + */ + bool in_compute_pool; + + /* true if there is/are ForeignScan node(s) of OBS foreign table + * in plantree. + */ + bool has_obsrel; + + List* plan_hint_warning; /* hint warning during plan generation, only used in CN */ + + List* noanalyze_rellist; /* relations and attributes that have no statistics, only used in CN */ + + int ng_num; /* nodegroup number */ + NodeGroupQueryMem* ng_queryMem; /* each nodegroup's query mem */ + bool ng_use_planA; /* true means I am a planA, default false */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ + bool is_stream_plan; + bool multi_node_hint; + + uint64 uniqueSQLId; +} PlannedStmt; + +typedef struct NodeGroupInfoContext { + Oid groupOids[MAX_SPECIAL_BUCKETMAP_NUM]; + uint2* bucketMap[MAX_SPECIAL_BUCKETMAP_NUM]; + int num_bucketmaps; +} NodeGroupInfoContext; + +/* + * Determine if this plan step needs excution on current dn + * RestoreMode is always considered as 'have to' execute + */ +#define NeedExecute(plan) \ + (isRestoreMode ? true \ + : (plan->exec_nodes == NULL || plan->exec_nodes->nodeList == NULL || \ + list_member_int((plan)->exec_nodes->nodeList, u_sess->pgxc_cxt.PGXCNodeId))) + +/* macro for fetching the Plan associated with a SubPlan node */ +#define exec_subplan_get_plan(plannedstmt, subplan) ((Plan*)list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1)) + +/* ---------------- + * Plan node + * + * All plan nodes "derive" from the Plan structure by having the + * Plan structure as the first field. This ensures that everything works + * when nodes are cast to Plan's. (node pointers are frequently cast to Plan* + * when passed around generically in the executor) + * + * We never actually instantiate any Plan nodes; this is just the common + * abstract superclass for all Plan-type nodes. + * ---------------- + */ +typedef struct Plan { + NodeTag type; + + int plan_node_id; /* node id */ + int parent_node_id; /* parent node id */ + RemoteQueryExecType exec_type; + + /* + * estimated execution costs for plan (see costsize.c for more info) + */ + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + + /* + * planner's estimate of result size of this plan step + */ + double plan_rows; /* number of global rows plan is expected to emit */ + double multiple; + int plan_width; /* average row width in bytes */ + int dop; /* degree of parallelism of current plan */ + + /* + * machine learning model estimations + */ + double pred_rows; + double pred_startup_time; + double pred_total_time; + long pred_max_memory; + /* + * MPPDB Recursive-Union Support + * + * - @recursive_union_plan_nodeid + * Pointing to its belonging RecursiveUnion's plan node id to indate if we are + * under RecursiveUnion + * + * - @recursive_union_controller + * Indicate if current Plan node is controller node in recursive-union steps + * + * - @control_plan_nodeid + * Normally, set on the top-plan node of a producer thread, to indicate which + * control-plan we need syn-up with + * + * - @is_sync_planode + * Indicate the current producer thread is the sync-up thread in recursive union, + * normally set on produer's top plan node + * + * Please note the above four variables is meaningless if a plan node is not under + * recursive-union's recursive part + */ + /* + * plan node id of RecursiveUnion node where current plan node belongs to, 0 for + * not under recursive-union + */ + int recursive_union_plan_nodeid; + + /* flag to indicate if it is controller plan node */ + bool recursive_union_controller; + + /* plan node id of Controller plan node, 0 for not in control */ + int control_plan_nodeid; + + /* flag indicate if the current plan node is the sync node (for multi-stream case) */ + bool is_sync_plannode; + + /* + * Common structural data for all Plan types. + */ + List* targetlist; /* target list to be computed at this node */ + List* qual; /* implicitly-ANDed qual conditions */ + struct Plan* lefttree; /* input plan tree(s) */ + struct Plan* righttree; + + bool ispwj; /* is it special for partitionwisejoin? */ + int paramno; /* the partition'sn that it is scaning */ + + List* initPlan; /* Init Plan nodes (un-correlated expr + * subselects) */ + + List* distributed_keys; /* distributed on which key */ + ExecNodes* exec_nodes; /* List of Datanodes where to execute this plan */ + + /* + * Information for management of parameter-change-driven rescanning + * + * extParam includes the paramIDs of all external PARAM_EXEC params + * affecting this plan node or its children. setParam params from the + * node's initPlans are not included, but their extParams are. + * + * allParam includes all the extParam paramIDs, plus the IDs of local + * params that affect the node (i.e., the setParams of its initplans). + * These are _all_ the PARAM_EXEC params that affect this node. + */ + Bitmapset* extParam; + Bitmapset* allParam; + + // For vectorized engine, plan produce vector output + // + bool vec_output; + /* + * @hdfs + * Mark the foreign scan whether has unique results on one of its + * output columns. + */ + bool hasUniqueResults; + /* + * Mark the plan whether includes delta table or not. + */ + bool isDeltaTable; + + /* used to replace work_mem, maxmem in [0], and minmem in [1] */ + int operatorMemKB[2]; + /* allowed max mem after spread */ + int operatorMaxMem; + + bool parallel_enabled; /* Is it run in parallel? */ + bool hasHashFilter; /* true for this plan has a hashfilter */ + + List* var_list; /* Need bloom filter var list. */ + List* filterIndexList; /* Need used bloomfilter array index. */ + + /* used to replace work_mem */ + int** ng_operatorMemKBArray; /* for multiple logic cluster */ + int ng_num; + double innerdistinct; /* join inner rel distinct estimation value */ + double outerdistinct; /* join outer rel distinct estimation value */ +} Plan; + +/* ---------------- + * these are defined to avoid confusion problems with "left" + * and "right" and "inner" and "outer". The convention is that + * the "left" plan is the "outer" plan and the "right" plan is + * the inner plan, but these make the code more readable. + * ---------------- + */ +#define innerPlan(node) (((Plan*)(node))->righttree) +#define outerPlan(node) (((Plan*)(node))->lefttree) + +/* ---------------- + * Result node - + * If no outer plan, evaluate a variable-free targetlist. + * If outer plan, return tuples from outer plan (after a level of + * projection as shown by targetlist). + * + * If resconstantqual isn't NULL, it represents a one-time qualification + * test (i.e., one that doesn't depend on any variables from the outer plan, + * so needs to be evaluated only once). + * ---------------- + */ +typedef struct BaseResult { + Plan plan; + Node* resconstantqual; +} BaseResult; + +typedef struct VecResult : public BaseResult { +} VecResult; + +/* ---------------- + * ModifyTable node - + * Apply rows produced by subplan(s) to result table(s), + * by inserting, updating, or deleting. + * + * Note that rowMarks and epqParam are presumed to be valid for all the + * subplan(s); they can't contain any info that varies across subplans. + * ---------------- + */ +typedef struct ModifyTable { + Plan plan; + CmdType operation; /* INSERT, UPDATE, or DELETE */ + bool canSetTag; /* do we set the command tag/es_processed? */ + List* resultRelations; /* integer list of RT indexes */ + int resultRelIndex; /* index of first resultRel in plan's list */ + List* plans; /* plan(s) producing source data */ + List* returningLists; /* per-target-table RETURNING tlists */ + List* fdwPrivLists; /* per-target-table FDW private data lists */ + List* rowMarks; /* PlanRowMarks (non-locking only) */ + int epqParam; /* ID of Param for EvalPlanQual re-eval */ + bool partKeyUpdated; /* when update on a partitioned table,true: part key column + is to be updated,false: no part key column is to updated */ +#ifdef PGXC + List* remote_plans; /* per-target-table remote node */ + List* remote_insert_plans; + List* remote_update_plans; + List* remote_delete_plans; +#endif + bool is_dist_insertselect; + + ErrorCacheEntry* cacheEnt; /* Error record cache */ + + Index mergeTargetRelation; /* RT index of the merge target */ + List* mergeSourceTargetList; + List* mergeActionList; /* actions for MERGE */ + + UpsertAction upsertAction; /* DUPLICATE KEY UPDATE action */ + List* updateTlist; /* List of UPDATE target */ + List* exclRelTlist; /* target list of the EXECLUDED pseudo relation */ + Index exclRelRTIndex; /* RTI of the EXCLUDED pseudo relation */ + + OpMemInfo mem_info; /* Memory info for modify node */ +} ModifyTable; + +/* ---------------- + * Append node - + * Generate the concatenation of the results of sub-plans. + * ---------------- + */ +typedef struct Append { + Plan plan; + List* appendplans; +} Append; + +typedef struct VecAppend : public Append { +} VecAppend; +/* ---------------- + * MergeAppend node - + * Merge the results of pre-sorted sub-plans to preserve the ordering. + * ---------------- + */ +typedef struct MergeAppend { + Plan plan; + List* mergeplans; + /* remaining fields are just like the sort-key info in struct Sort */ + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* collations; /* OIDs of collations */ + bool* nullsFirst; /* NULLS FIRST/LAST directions */ +} MergeAppend; + +/* ---------------- + * RecursiveUnion node - + * Generate a recursive union of two subplans. + * + * The "outer" subplan is always the non-recursive term, and the "inner" + * subplan is the recursive term. + * ---------------- + */ +typedef struct RecursiveUnion { + Plan plan; + int wtParam; /* ID of Param representing work table */ + /* Remaining fields are zero/null in UNION ALL case */ + int numCols; /* number of columns to check for + * duplicate-ness */ + AttrNumber* dupColIdx; /* their indexes in the target list */ + Oid* dupOperators; /* equality operators to compare with */ + long numGroups; /* estimated number of groups in input */ + bool has_inner_stream; /* indicate the underlaying plan node has stream operator (on recursive-term) */ + bool has_outer_stream; /* indicate the underlaying plan node has stream operator (on none-recursive side) */ + bool is_used; + bool is_correlated; /* indicate if the recursive union contains correlated term, + * in case of correlated term involved, we need broadcast data + * to one datanode to execute the recursive CTE in one-DN mode */ +} RecursiveUnion; + +/* ---------------- + * BitmapAnd node - + * Generate the intersection of the results of sub-plans. + * + * The subplans must be of types that yield tuple bitmaps. The targetlist + * and qual fields of the plan are unused and are always NIL. + * ---------------- + */ +typedef struct BitmapAnd { + Plan plan; + List* bitmapplans; +} BitmapAnd; + +/* ---------------- + * BitmapOr node - + * Generate the union of the results of sub-plans. + * + * The subplans must be of types that yield tuple bitmaps. The targetlist + * and qual fields of the plan are unused and are always NIL. + * ---------------- + */ +typedef struct BitmapOr { + Plan plan; + List* bitmapplans; +} BitmapOr; + +/* + * ========== + * Scan nodes + * ========== + */ +typedef struct Scan { + Plan plan; + Index scanrelid; /* relid is index into the range table */ + bool isPartTbl; /* Does it scan a partitioned table */ + int itrs; /* table partition's number for scan */ + PruningResult* pruningInfo; /* pruning result for where-clause */ + BucketInfo* bucketInfo; /* pruning result for buckets */ + ScanDirection partScanDirection; /* specifies the scan ordering */ + /* + * @hdfs + * If we use the informational constarint, the following variables will be seted as true. + * If scan_qual_optimized is true, it means that foreign scan will be optimized by using + * scan qual in executor phase. + * If predicate_pushdown_optimized is true, it means that predicate is pushed down and + * foreign scan will be optimized in the executor phase by using the predicate. + */ + bool scan_qual_optimized; + bool predicate_pushdown_optimized; + + /* use struct pointer to avoid including parsenodes.h here */ + TableSampleClause* tablesample; + + /* Memory info for scan node, now it just used on indexscan, indexonlyscan, bitmapscan, dfsindexscan */ + OpMemInfo mem_info; +} Scan; + +/* ---------------- + * sequential scan node + * ---------------- + */ +typedef Scan SeqScan; + +/* + * ========== + * Column Store Scan nodes + * ========== + */ +typedef struct CStoreScan : public Scan { + /* Some optimization information */ + double selectionRatio; /* row output / rows scanned */ + List* cstorequal; /* push predicate down to cstorescan */ + List* minMaxInfo; /* min/max information, mark get this column min or max value. */ + RelstoreType relStoreLocation; /* The store position information. */ + bool is_replica_table; /* Is a replication table? */ +} CStoreScan; + +/* + * ========== + * Dfs Store Scan nodes. When the relation is CU format, we use CstoreScan + * to scan data. + * ========== + */ +typedef struct DfsScan : public Scan { + RelstoreType relStoreLocation; + char* storeFormat; /* The store format, the ORC format only is supported for dfsScan. */ + List* privateData; /* Private data. */ +} DfsScan; + +/* + * ========== + * Time Series Store Scan nodes + * ========== + */ +typedef struct TsStoreScan: public Scan { + /* Some optimization information */ + double selectionRatio; /* row output / rows scanned */ + List *tsstorequal; /* push predicate down to tsstorescan */ + List *minMaxInfo; /* min/max information, mark get this column min or max value.*/ + RelstoreType relStoreLocation; /* The store position information. */ + bool is_replica_table; /* Is a replication table? */ + AttrNumber sort_by_time_colidx; /* If is sort by tstime limit n */ + int limit; /* If is limit n */ + bool is_simple_scan; /* If is sort by tstime limit n */ + bool has_sort; /* If is have sort node */ + int series_func_calls; /* series function calls time */ + int top_key_func_arg; /* second arg of top_key function */ +} TsStoreScan; + +/* ---------------- + * index scan node + * + * indexqualorig is an implicitly-ANDed list of index qual expressions, each + * in the same form it appeared in the query WHERE condition. Each should + * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey). + * The indexkey is a Var or expression referencing column(s) of the index's + * base table. The comparisonval might be any expression, but it won't use + * any columns of the base table. The expressions are ordered by index + * column position (but items referencing the same index column can appear + * in any order). indexqualorig is used at runtime only if we have to recheck + * a lossy indexqual. + * + * indexqual has the same form, but the expressions have been commuted if + * necessary to put the indexkeys on the left, and the indexkeys are replaced + * by Var nodes identifying the index columns (their varno is INDEX_VAR and + * their varattno is the index column number). + * + * indexorderbyorig is similarly the original form of any ORDER BY expressions + * that are being implemented by the index, while indexorderby is modified to + * have index column Vars on the left-hand side. Here, multiple expressions + * must appear in exactly the ORDER BY order, and this is not necessarily the + * index column order. Only the expressions are provided, not the auxiliary + * sort-order information from the ORDER BY SortGroupClauses; it's assumed + * that the sort ordering is fully determinable from the top-level operators. + * indexorderbyorig is unused at run time, but is needed for EXPLAIN. + * (Note these fields are used for amcanorderbyop cases, not amcanorder cases.) + * + * indexorderdir specifies the scan ordering, for indexscans on amcanorder + * indexes (for other indexes it should be "don't care"). + * ---------------- + */ +typedef struct IndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + char* indexname; /* Index name of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + bool usecstoreindex; /* mark the column store index */ + Index indexscan_relid; /* Hack for column store index, treat the index as normal relation */ + List* idx_cstorequal; /* For column store, this contains only quals pushdownable to + storage engine */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* targetlist; /* Hack for column store index, target list to be computed at this node */ + bool index_only_scan; +} IndexScan; + +/* ---------------- + * index-only scan node + * + * IndexOnlyScan is very similar to IndexScan, but it specifies an + * index-only scan, in which the data comes from the index not the heap. + * Because of this, *all* Vars in the plan node's targetlist, qual, and + * index expressions reference index columns and have varno = INDEX_VAR. + * Hence we do not need separate indexqualorig and indexorderbyorig lists, + * since their contents would be equivalent to indexqual and indexorderby. + * + * To help EXPLAIN interpret the index Vars for display, we provide + * indextlist, which represents the contents of the index as a targetlist + * with one TLE per index column. Vars appearing in this list reference + * the base table, and this is the only field in the plan node that may + * contain such Vars. + * ---------------- + */ +typedef struct IndexOnlyScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indextlist; /* TargetEntry list describing index's cols */ + ScanDirection indexorderdir; /* forward or backward or don't care */ +} IndexOnlyScan; + +/* ---------------- + * bitmap index scan node + * + * BitmapIndexScan delivers a bitmap of potential tuple locations; + * it does not access the heap itself. The bitmap is used by an + * ancestor BitmapHeapScan node, possibly after passing through + * intermediate BitmapAnd and/or BitmapOr nodes to combine it with + * the results of other BitmapIndexScans. + * + * The fields have the same meanings as for IndexScan, except we don't + * store a direction flag because direction is uninteresting. + * + * In a BitmapIndexScan plan node, the targetlist and qual fields are + * not used and are always NIL. The indexqualorig field is unused at + * run time too, but is saved for the benefit of EXPLAIN. + * ---------------- + */ +typedef struct BitmapIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + char* indexname; /* name of index to scan */ + List* indexqual; /* list of index quals (OpExprs) */ + List* indexqualorig; /* the same in original form */ +} BitmapIndexScan; + +/* ---------------- + * bitmap sequential scan node + * + * This needs a copy of the qual conditions being used by the input index + * scans because there are various cases where we need to recheck the quals; + * for example, when the bitmap is lossy about the specific rows on a page + * that meet the index condition. + * ---------------- + */ +typedef struct BitmapHeapScan { + Scan scan; + List* bitmapqualorig; /* index quals, in standard expr form */ +} BitmapHeapScan; + +/* ---------------- + * Column Store index scan node + * + * ---------------- + */ +typedef struct CStoreIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + + List* baserelcstorequal; /* for base relation of index */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* indextlist; + RelstoreType relStoreLocation; /* The store position information. */ + bool indexonly; /* flag indicates index only scan */ +} CStoreIndexScan; + +typedef struct CStoreIndexCtidScan : public BitmapIndexScan { + List* indextlist; + List* cstorequal; +} CStoreIndexCtidScan; + +typedef struct CStoreIndexHeapScan : public BitmapHeapScan { +} CStoreIndexHeapScan; + +typedef struct CStoreIndexAnd : public BitmapAnd { +} CStoreIndexAnd; + +typedef struct CStoreIndexOr : public BitmapOr { +} CStoreIndexOr; + +/* ---------------- + * DFS Store index scan node + */ +typedef struct DfsIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indextlist; /* list of index target entry which represents the column of base-relation */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + RelstoreType relStoreLocation; /* The store position information. */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* indexScantlist; /* list of target column for scanning on index table */ + DfsScan* dfsScan; /* the inner object for scanning the base-relation */ + bool indexonly; /* flag indicates index only scan */ +} DfsIndexScan; + +/* ---------------- + * tid scan node + * + * tidquals is an implicitly OR'ed list of qual expressions of the form + * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)". + * ---------------- + */ +typedef struct TidScan { + Scan scan; + List* tidquals; /* qual(s) involving CTID = something */ +} TidScan; + +/* ---------------- + * subquery scan node + * + * SubqueryScan is for scanning the output of a sub-query in the range table. + * We often need an extra plan node above the sub-query's plan to perform + * expression evaluations (which we can't push into the sub-query without + * risking changing its semantics). Although we are not scanning a physical + * relation, we make this a descendant of Scan anyway for code-sharing + * purposes. + * + * Note: we store the sub-plan in the type-specific subplan field, not in + * the generic lefttree field as you might expect. This is because we do + * not want plan-tree-traversal routines to recurse into the subplan without + * knowing that they are changing Query contexts. + * ---------------- + */ +typedef struct SubqueryScan { + Scan scan; + Plan* subplan; +} SubqueryScan; + +typedef struct VecSubqueryScan : public SubqueryScan { +} VecSubqueryScan; + +/* ---------------- + * FunctionScan node + * ---------------- + */ +typedef struct FunctionScan { + Scan scan; + Node* funcexpr; /* expression tree for func call */ + List* funccolnames; /* output column names (string Value nodes) */ + List* funccoltypes; /* OID list of column type OIDs */ + List* funccoltypmods; /* integer list of column typmods */ + List* funccolcollations; /* OID list of column collation OIDs */ +} FunctionScan; + +/* ---------------- + * ValuesScan node + * ---------------- + */ +typedef struct ValuesScan { + Scan scan; + List* values_lists; /* list of expression lists */ +} ValuesScan; + +/* ---------------- + * CteScan node + * ---------------- + */ +typedef struct CteScan { + Scan scan; + int ctePlanId; /* ID of init SubPlan for CTE */ + int cteParam; /* ID of Param representing CTE output */ + RecursiveUnion* subplan; /* subplan of CteScan, must be RecursiveUnion */ +} CteScan; + +/* ---------------- + * WorkTableScan node + * ---------------- + */ +typedef struct WorkTableScan { + Scan scan; + int wtParam; /* ID of Param representing work table */ +} WorkTableScan; + +/* ---------------- + * ForeignScan node + * + * fdw_exprs and fdw_private are both under the control of the foreign-data + * wrapper, but fdw_exprs is presumed to contain expression trees and will + * be post-processed accordingly by the planner; fdw_private won't be. + * Note that everything in both lists must be copiable by copyObject(). + * One way to store an arbitrary blob of bytes is to represent it as a bytea + * Const. Usually, though, you'll be better off choosing a representation + * that can be dumped usefully by nodeToString(). + * ---------------- + */ +typedef struct ForeignScan { + Scan scan; + + Oid scan_relid; /* Oid of the scan relation */ + List* fdw_exprs; /* expressions that FDW may evaluate */ + List* fdw_private; /* private data for FDW */ + bool fsSystemCol; /* true if any "system column" is needed */ + + bool needSaveError; + ErrorCacheEntry* errCache; /* Error record cache */ + + /* This is used in hdfs foreign scan to store prunning information. */ + List* prunningResult; + + RelationMetaData* rel; /* the meta data of the foreign table */ + ForeignOptions* options; /* the configuration options */ + + /* number of files(objects) to be scanned. just valid for planner */ + int64 objectNum; + BloomFilterSet** bloomFilterSet; + int bfNum; /* the number of bloomfilter object. */ + + /* set true in do_query_for_planrouter() for ForeignScan sent to + * the compute pool + */ + bool in_compute_pool; + bool not_use_bloomfilter; /* set true in ExecInitXXXX() of planrouter node */ +} ForeignScan; + +/* ---------------- + * ExtensiblePlan node + * + * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist, + * and fs_relids fields apply equally to ExtensiblePlan's extensible_exprs, + * extensible_data, extensible_plan_tlist, and extensible_relids fields. The + * convention of setting scan.scanrelid to zero for joins applies as well. + * + * Note that since Plan trees can be copied, extensible scan providers *must* + * fit all plan data they need into those fields; embedding ExtensiblePlan in + * a larger struct will not work. + * ---------------- + */ +struct ExtensiblePlan; + +typedef struct ExtensiblePlanMethods { + char* ExtensibleName; + + /* Create execution state (ExtensiblePlanState) from a ExtensiblePlan plan node */ + Node* (*CreateExtensiblePlanState)(struct ExtensiblePlan* cscan); +} ExtensiblePlanMethods; + +typedef struct ExtensiblePlan { + Scan scan; + + uint32 flags; /* mask of EXTENSIBLEPATH_* flags, see relation.h */ + + List* extensible_plans; /* list of Plan nodes, if any */ + + List* extensible_exprs; /* expressions that extensible code may evaluate */ + + List* extensible_private; /* private data for extensible code */ + + List* extensible_plan_tlist; /* optional tlist describing scan + * tuple */ + Bitmapset* extensible_relids; /* RTIs generated by this scan */ + + ExtensiblePlanMethods* methods; +} ExtensiblePlan; +/* + * ========== + * Join nodes + * ========== + */ + +/* ---------------- + * Join node + * + * jointype: rule for joining tuples from left and right subtrees + * joinqual: qual conditions that came from JOIN/ON or JOIN/USING + * (plan.qual contains conditions that came from WHERE) + * + * When jointype is INNER, joinqual and plan.qual are semantically + * interchangeable. For OUTER jointypes, the two are *not* interchangeable; + * only joinqual is used to determine whether a match has been found for + * the purpose of deciding whether to generate null-extended tuples. + * (But plan.qual is still applied before actually returning a tuple.) + * For an outer join, only joinquals are allowed to be used as the merge + * or hash condition of a merge or hash join. + * ---------------- + */ +typedef struct Join { + Plan plan; + JoinType jointype; + List* joinqual; /* JOIN quals (in addition to plan.qual) */ + /* + * @hdfs + * This flag will be set as true if we use informational constraint + * in order to optimize join plan. + */ + bool optimizable; + List* nulleqqual; + + uint32 skewoptimize; +} Join; + +/* ---------------- + * nest loop join node + * + * The nestParams list identifies any executor Params that must be passed + * into execution of the inner subplan carrying values from the current row + * of the outer subplan. Currently we restrict these values to be simple + * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan + * creation, the paramval can actually be a PlaceHolderVar expression; but it + * must be a Var with varno OUTER_VAR by the time it gets to the executor.) + * ---------------- + */ +typedef struct NestLoop { + Join join; + List* nestParams; /* list of NestLoopParam nodes */ + bool materialAll; +} NestLoop; + +typedef struct VecNestLoop : public NestLoop { +} VecNestLoop; + +typedef struct NestLoopParam { + NodeTag type; + int paramno; /* number of the PARAM_EXEC Param to set */ + Var* paramval; /* outer-relation Var to assign to Param */ +} NestLoopParam; + +/* ---------------- + * merge join node + * + * The expected ordering of each mergeable column is described by a btree + * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or + * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides + * of each mergeclause may be of different datatypes, but they are ordered the + * same way according to the common opfamily and collation. The operator in + * each mergeclause must be an equality operator of the indicated opfamily. + * ---------------- + */ +typedef struct MergeJoin { + Join join; + List* mergeclauses; /* mergeclauses as expression trees */ + /* these are arrays, but have the same length as the mergeclauses list: */ + Oid* mergeFamilies; /* per-clause OIDs of btree opfamilies */ + Oid* mergeCollations; /* per-clause OIDs of collations */ + int* mergeStrategies; /* per-clause ordering (ASC or DESC) */ + bool* mergeNullsFirst; /* per-clause nulls ordering */ +} MergeJoin; + +typedef struct VecMergeJoin : public MergeJoin { +} VecMergeJoin; +/* ---------------- + * hash join node + * ---------------- + */ +typedef struct HashJoin { + Join join; + List* hashclauses; + bool streamBothSides; + bool transferFilterFlag; + bool rebuildHashTable; + bool isSonicHash; + OpMemInfo mem_info; /* Memory info for inner hash table */ +} HashJoin; + +/* ---------------- + * materialization node + * ---------------- + */ +typedef struct Material { + Plan plan; + bool materialize_all; /* if all data should be materialized at the first time */ + OpMemInfo mem_info; /* Memory info for material */ +} Material; + +typedef struct VecMaterial : public Material { +} VecMaterial; + +/* ---------------- + * sort node + * ---------------- + */ +typedef struct Sort { + Plan plan; + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* collations; /* OIDs of collations */ + bool* nullsFirst; /* NULLS FIRST/LAST directions */ +#ifdef PGXC + bool srt_start_merge; /* No need to create the sorted runs. The + * underlying plan provides those runs. Merge + * them. + */ +#endif /* PGXC */ + OpMemInfo mem_info; /* Memory info for sort */ +} Sort; + +typedef struct VecSort : public Sort { +} VecSort; + +/* --------------- + * group node - + * Used for queries with GROUP BY (but no aggregates) specified. + * The input must be presorted according to the grouping columns. + * --------------- + */ +typedef struct Group { + Plan plan; + int numCols; /* number of grouping columns */ + AttrNumber* grpColIdx; /* their indexes in the target list */ + Oid* grpOperators; /* equality operators to compare with */ +} Group; + +typedef struct VecGroup : public Group { +} VecGroup; +/* --------------- + * aggregate node + * + * An Agg node implements plain or grouped aggregation. For grouped + * aggregation, we can work with presorted input or unsorted input; + * the latter strategy uses an internal hashtable. + * + * Notice the lack of any direct info about the aggregate functions to be + * computed. They are found by scanning the node's tlist and quals during + * executor startup. (It is possible that there are no aggregate functions; + * this could happen if they get optimized away by constant-folding, or if + * we are using the Agg node to implement hash-based grouping.) + * --------------- + */ +typedef enum AggStrategy { + AGG_PLAIN, /* simple agg across all input rows */ + AGG_SORTED, /* grouped agg, input must be sorted */ + AGG_HASHED /* grouped agg, use internal hashtable */ +} AggStrategy; + +#ifdef STREAMPLAN +typedef enum SAggMethod { + OPTIMAL_AGG, /* 0. chose the optimal hash agg plan according to costs. */ + DN_AGG_CN_AGG, /* 1. */ + DN_REDISTRIBUTE_AGG, /* 2. */ + DN_AGG_REDISTRIBUTE_AGG, /* 3. */ + DN_REDISTRIBUTE_AGG_CN_AGG, /* 1+. according to DN_AGG_CN_AGG */ + DN_REDISTRIBUTE_AGG_REDISTRIBUTE_AGG /* 3+. according to DN_AGG_REDISTRIBUTE_AGG */ +} SAggMethod; + +/* flags bits for SAggMethod choose */ +#define ALLOW_ALL_AGG 0X00 /* Any AggMethod may be selected */ +#define DISALLOW_CN_AGG 0x01 /* disallow DN_AGG_CN_AGG, DN_REDISTRIBUTE_AGG_CN_AGG */ +#define FOREC_SLVL_AGG 0x02 /* force single level agg, actually disallow CN_AGG meanwhile */ + +#endif + +typedef struct Agg { + Plan plan; + AggStrategy aggstrategy; + int numCols; /* number of grouping columns */ + AttrNumber* grpColIdx; /* their indexes in the target list */ + Oid* grpOperators; /* equality operators to compare with */ + long numGroups; /* estimated number of groups in input */ + List* groupingSets; /* grouping sets to use */ + List* chain; /* chained Agg/Sort nodes */ +#ifdef PGXC + bool is_final; /* apply final agg directly on the data received from remote Datanodes */ + bool single_node; /* We can finalise the aggregates on the datanode/s */ +#endif /* PGXC */ + Bitmapset* aggParams; /* IDs of Params used in Aggref inputs */ + OpMemInfo mem_info; /* Memory info for hashagg */ + bool is_sonichash; /* allowed to use sonic hash routine or not */ + bool is_dummy; /* just for coop analysis, if true, agg node does nothing */ + uint32 skew_optimize; /* skew optimize method for agg */ + bool unique_check; /* we will report an error when meet duplicate in unique check mode */ +} Agg; + +/* ---------------- + * window aggregate node + * ---------------- + */ +typedef struct WindowAgg { + Plan plan; + Index winref; /* ID referenced by window functions */ + int partNumCols; /* number of columns in partition clause */ + AttrNumber* partColIdx; /* their indexes in the target list */ + Oid* partOperators; /* equality operators for partition columns */ + int ordNumCols; /* number of columns in ordering clause */ + AttrNumber* ordColIdx; /* their indexes in the target list */ + Oid* ordOperators; /* equality operators for ordering columns */ + int frameOptions; /* frame_clause options, see WindowDef */ + Node* startOffset; /* expression for starting bound, if any */ + Node* endOffset; /* expression for ending bound, if any */ + OpMemInfo mem_info; /* Memory info for window agg with agg func */ +} WindowAgg; + +typedef struct VecWindowAgg : public WindowAgg { +} VecWindowAgg; +/* ---------------- + * unique node + * ---------------- + */ +typedef struct Unique { + Plan plan; + int numCols; /* number of columns to check for uniqueness */ + AttrNumber* uniqColIdx; /* their indexes in the target list */ + Oid* uniqOperators; /* equality operators to compare with */ +} Unique; + +/* ---------------- + * hash build node + * + * If the executor is supposed to try to apply skew join optimization, then + * skewTable/skewColumn/skewInherit identify the outer relation's join key + * column, from which the relevant MCV statistics can be fetched. Also, its + * type information is provided to save a lookup. + * ---------------- + */ +typedef struct Hash { + Plan plan; + Oid skewTable; /* outer join key's table OID, or InvalidOid */ + AttrNumber skewColumn; /* outer join key's column #, or zero */ + bool skewInherit; /* is outer join rel an inheritance tree? */ + Oid skewColType; /* datatype of the outer key column */ + int32 skewColTypmod; /* typmod of the outer key column */ + /* all other info is in the parent HashJoin node */ +} Hash; + +/* ---------------- + * setop node + * ---------------- + */ +typedef enum SetOpCmd { SETOPCMD_INTERSECT, SETOPCMD_INTERSECT_ALL, SETOPCMD_EXCEPT, SETOPCMD_EXCEPT_ALL } SetOpCmd; + +typedef enum SetOpStrategy { + SETOP_SORTED, /* input must be sorted */ + SETOP_HASHED /* use internal hashtable */ +} SetOpStrategy; + +typedef struct SetOp { + Plan plan; + SetOpCmd cmd; /* what to do */ + SetOpStrategy strategy; /* how to do it */ + int numCols; /* number of columns to check for + * duplicate-ness */ + AttrNumber* dupColIdx; /* their indexes in the target list */ + Oid* dupOperators; /* equality operators to compare with */ + AttrNumber flagColIdx; /* where is the flag column, if any */ + int firstFlag; /* flag value for first input relation */ + long numGroups; /* estimated number of groups in input */ + OpMemInfo mem_info; /* Memory info for hashagg set op */ +} SetOp; + +/* ---------------- + * lock-rows node + * + * rowMarks identifies the rels to be locked by this node; it should be + * a subset of the rowMarks listed in the top-level PlannedStmt. + * epqParam is a Param that all scan nodes below this one must depend on. + * It is used to force re-evaluation of the plan during EvalPlanQual. + * ---------------- + */ +typedef struct LockRows { + Plan plan; + List* rowMarks; /* a list of PlanRowMark's */ + int epqParam; /* ID of Param for EvalPlanQual re-eval */ +} LockRows; + +/* ---------------- + * limit node + * + * Note: as of Postgres 8.2, the offset and count expressions are expected + * to yield int8, rather than int4 as before. + * ---------------- + */ +typedef struct Limit { + Plan plan; + Node* limitOffset; /* OFFSET parameter, or NULL if none */ + Node* limitCount; /* COUNT parameter, or NULL if none */ +} Limit; + +typedef struct VecLimit : public Limit { +} VecLimit; + +/* + * RowMarkType - + * enums for types of row-marking operations + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely + * identify all the source rows, not only those from the target relations, so + * that we can perform EvalPlanQual rechecking at need. For plain tables we + * can just fetch the TID, the same as for a target relation. Otherwise (for + * example for VALUES or FUNCTION scans) we have to copy the whole row value. + * The latter is pretty inefficient but fortunately the case is not + * performance-critical in practice. + */ +typedef enum RowMarkType { + ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */ + ROW_MARK_SHARE, /* obtain shared tuple lock */ + ROW_MARK_REFERENCE, /* just fetch the TID */ + ROW_MARK_COPY, /* physically copy the row value */ + ROW_MARK_COPY_DATUM /* physically copy the datum of every row column */ +} RowMarkType; + +#define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_SHARE) + +/* + * PlanRowMark - + * plan-time representation of FOR UPDATE/SHARE clauses + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate + * PlanRowMark node for each non-target relation in the query. Relations that + * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if + * real tables) or ROW_MARK_COPY (if not). + * + * Initially all PlanRowMarks have rti == prti and isParent == false. + * When the planner discovers that a relation is the root of an inheritance + * tree, it sets isParent true, and adds an additional PlanRowMark to the + * list for each child relation (including the target rel itself in its role + * as a child). The child entries have rti == child rel's RT index and + * prti == parent's RT index, and can therefore be recognized as children by + * the fact that prti != rti. + * + * The planner also adds resjunk output columns to the plan that carry + * information sufficient to identify the locked or fetched rows. For + * tables (markType != ROW_MARK_COPY), these columns are named + * tableoid%u OID of table + * ctid%u TID of row + * The tableoid column is only present for an inheritance hierarchy. + * When markType == ROW_MARK_COPY, there is instead a single column named + * wholerow%u whole-row value of relation + * In all three cases, %u represents the rowmark ID number (rowmarkId). + * This number is unique within a plan tree, except that child relation + * entries copy their parent's rowmarkId. (Assigning unique numbers + * means we needn't renumber rowmarkIds when flattening subqueries, which + * would require finding and renaming the resjunk columns as well.) + * Note this means that all tables in an inheritance hierarchy share the + * same resjunk column names. However, in an inherited UPDATE/DELETE the + * columns could have different physical column numbers in each subplan. + */ +typedef struct PlanRowMark { + NodeTag type; + Index rti; /* range table index of markable relation */ + Index prti; /* range table index of parent relation */ + Index rowmarkId; /* unique identifier for resjunk columns */ + RowMarkType markType; /* see enum above */ + bool noWait; /* NOWAIT option */ + bool isParent; /* true if this is a "dummy" parent entry */ + int numAttrs; /* number of attributes in subplan */ + Bitmapset* bms_nodeids; +} PlanRowMark; + +/* + * Plan invalidation info + * + * We track the objects on which a PlannedStmt depends in two ways: + * relations are recorded as a simple list of OIDs, and everything else + * is represented as a list of PlanInvalItems. A PlanInvalItem is designed + * to be used with the syscache invalidation mechanism, so it identifies a + * system catalog entry by cache ID and hash value. + */ +typedef struct PlanInvalItem { + NodeTag type; + int cacheId; /* a syscache ID, see utils/syscache.h */ + uint32 hashValue; /* hash value of object's cache lookup key */ +} PlanInvalItem; +/* + * Target : data partition + * Brief : structure definition about partition iteration + */ +typedef struct PartIteratorParam { + NodeTag type; + int paramno; +} PartIteratorParam; + +typedef struct PartIterator { + Plan plan; + PartitionType partType; /* partition type, range or interval? */ + int itrs; /* the number of the partitions */ + ScanDirection direction; + PartIteratorParam* param; + /* + * Below three variables are used to record starting partition id, ending partition id and number of + * partitions. + */ + int startPartitionId; /* Used in parallel execution to record smp worker starting partition id. */ + int endPartitionId; /* Used in parallel execution to record smp worker ending partition id. */ +} PartIterator; +typedef struct GlobalPartIterator { + int curItrs; + PruningResult* pruningResult; +} GlobalPartIterator; + +typedef struct VecPartIterator : public PartIterator { +} VecPartIterator; +/* + * Vector Plan Nodes. + * + */ + +/* ---------------- + * vector hash join node + * ---------------- + */ + +// comment to avoid g++ warning +// vector aggregation. + +typedef struct HashJoin VecHashJoin; +typedef struct Agg VecAgg; +typedef struct SetOp VecSetOp; +typedef struct Unique VecUnique; + +typedef struct RowToVec { + Plan plan; +} RowToVec; + +typedef struct VecToRow { + Plan plan; +} VecToRow; + +inline bool IsVecOutput(Plan* p) +{ + return p && p->vec_output; +} + +typedef struct VecForeignScan : public ForeignScan { +} VecForeignScan; + +typedef struct VecModifyTable : public ModifyTable { +} VecModifyTable; +#endif /* PLANNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/include/nodes/primnodes.h postgresql-hll-2.14/include/include/nodes/primnodes.h --- postgresql-hll-2.14_old/include/include/nodes/primnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/primnodes.h 2020-12-12 17:06:43.233347858 +0800 @@ -0,0 +1,1403 @@ +/* ------------------------------------------------------------------------- + * + * primnodes.h + * Definitions for "primitive" node types, those that are used in more + * than one of the parse/plan/execute stages of the query pipeline. + * Currently, these are mostly nodes for executable expressions + * and join trees. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/primnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRIMNODES_H +#define PRIMNODES_H + +#include "access/attnum.h" +#include "nodes/pg_list.h" +#include "nodes/params.h" + +/* ---------------------------------------------------------------- + * node definitions + * ---------------------------------------------------------------- + */ + +/* + * Alias - + * specifies an alias for a range variable; the alias might also + * specify renaming of columns within the table. + * + * Note: colnames is a list of Value nodes (always strings). In Alias structs + * associated with RTEs, there may be entries corresponding to dropped + * columns; these are normally empty strings (""). See parsenodes.h for info. + */ +typedef struct Alias { + NodeTag type; + char* aliasname; /* aliased rel name (never qualified) */ + List* colnames; /* optional list of column aliases */ +} Alias; + +typedef enum InhOption { + INH_NO, /* Do NOT scan child tables */ + INH_YES, /* DO scan child tables */ + INH_DEFAULT /* Use current SQL_inheritance option */ +} InhOption; + +/* What to do at commit time for temporary relations */ +typedef enum OnCommitAction { + ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */ + ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */ + ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */ + ONCOMMIT_DROP /* ON COMMIT DROP */ +} OnCommitAction; + +// If enable_compress is off, the table will not be compressed no matter +// which option is specified. +// +typedef enum OptCompress { + COMPRESS_NO = 0, + COMPRESS_LOW, + COMPRESS_MIDDLE, + COMPRESS_HIGH, +} OptCompress; + +/* + * RangeVar - range variable, used in FROM clauses + * + * Also used to represent table names in utility statements; there, the alias + * field is not used, and inhOpt shows whether to apply the operation + * recursively to child tables. In some contexts it is also useful to carry + * a TEMP table indication here. + */ +typedef struct RangeVar { + NodeTag type; + char* catalogname; /* the catalog (database) name, or NULL */ + char* schemaname; /* the schema name, or NULL */ + char* relname; /* the relation/sequence name */ + char* partitionname; /* partition name, if is a partition */ + InhOption inhOpt; /* expand rel by inheritance? recursively act + * on children? */ + char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */ + Alias* alias; /* table alias & optional column aliases */ + int location; /* token location, or -1 if unknown */ + bool ispartition; /* for partition action */ + List* partitionKeyValuesList; + bool isbucket; /* is the RangeVar means a hash bucket id ? */ + List* buckets; /* the corresponding bucketid list */ + int length; +#ifdef ENABLE_MOT + Oid foreignOid; +#endif +} RangeVar; + +/* + * IntoClause - target information for SELECT INTO, CREATE TABLE AS, and + * CREATE MATERIALIZED VIEW + */ +typedef struct IntoClause { + NodeTag type; + + RangeVar* rel; /* target relation name */ + List* colNames; /* column names to assign, or NIL */ + List* options; /* options from WITH clause */ + OnCommitAction onCommit; /* what do we do at COMMIT? */ + int8 row_compress; /* row compression flag */ + char* tableSpaceName; /* table space to use, or NULL */ + bool skipData; /* true for WITH NO DATA */ + bool ivm; /* true for WITH IVM */ + char relkind; /* RELKIND_RELATION or RELKIND_MATVIEW */ +#ifdef PGXC + struct DistributeBy* distributeby; /* distribution to use, or NULL */ + struct PGXCSubCluster* subcluster; /* subcluster node members */ +#endif +} IntoClause; + +/* ---------------------------------------------------------------- + * node types for executable expressions + * ---------------------------------------------------------------- + */ + +/* + * Expr - generic superclass for executable-expression nodes + * + * All node types that are used in executable expression trees should derive + * from Expr (that is, have Expr as their first field). Since Expr only + * contains NodeTag, this is a formality, but it is an easy form of + * documentation. See also the ExprState node types in execnodes.h. + */ +typedef struct Expr { + NodeTag type; +} Expr; + +/* + * Var - expression node representing a variable (ie, a table column) + * + * Note: during parsing/planning, varnoold/varoattno are always just copies + * of varno/varattno. At the tail end of planning, Var nodes appearing in + * upper-level plan nodes are reassigned to point to the outputs of their + * subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR + * and varattno becomes the index of the proper element of that subplan's + * target list. But varnoold/varoattno continue to hold the original values. + * The code doesn't really need varnoold/varoattno, but they are very useful + * for debugging and interpreting completed plans, so we keep them around. + */ +#define INNER_VAR 65000 /* reference to inner subplan */ +#define OUTER_VAR 65001 /* reference to outer subplan */ +#define INDEX_VAR 65002 /* reference to index column */ +#define MERGEJOIN_VAR 65003 /* reference to merge join results */ + +#define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR) + +/* Symbols for the indexes of the special RTE entries in rules */ +#define PRS2_OLD_VARNO 1 +#define PRS2_NEW_VARNO 2 + +typedef struct Var { + Expr xpr; + Index varno; /* index of this var's relation in the range + * table, or INNER_VAR/OUTER_VAR/INDEX_VAR */ + AttrNumber varattno; /* attribute number of this var, or zero for + * all */ + Oid vartype; /* pg_type OID for the type of this var */ + int32 vartypmod; /* pg_attribute typmod value */ + Oid varcollid; /* OID of collation, or InvalidOid if none */ + Index varlevelsup; /* for subquery variables referencing outer + * relations; 0 in a normal var, >0 means N + * levels up */ + Index varnoold; /* original value of varno, for debugging */ + AttrNumber varoattno; /* original value of varattno */ + int location; /* token location, or -1 if unknown */ +} Var; + +/* + * Const + */ +typedef struct Const { + Expr xpr; + Oid consttype; /* pg_type OID of the constant's datatype */ + int32 consttypmod; /* typmod value, if any */ + Oid constcollid; /* OID of collation, or InvalidOid if none */ + int constlen; /* typlen of the constant's datatype */ + Datum constvalue; /* the constant's value */ + bool constisnull; /* whether the constant is null (if true, + * constvalue is undefined) */ + bool constbyval; /* whether this datatype is passed by value. + * If true, then all the information is stored + * in the Datum. If false, then the Datum + * contains a pointer to the information. */ + int location; /* token location, or -1 if unknown */ + bool ismaxvalue; /*is the Const represent maxValue, maxValue is used for partition */ + + Cursor_Data cursor_data; +} Const; + +/* ---------------- + * Param + * paramkind - specifies the kind of parameter. The possible values + * for this field are: + * + * PARAM_EXTERN: The parameter value is supplied from outside the plan. + * Such parameters are numbered from 1 to n. + * + * PARAM_EXEC: The parameter is an internal executor parameter, used + * for passing values into and out of sub-queries or from + * nestloop joins to their inner scans. + * For historical reasons, such parameters are numbered from 0. + * These numbers are independent of PARAM_EXTERN numbers. + * + * PARAM_SUBLINK: The parameter represents an output column of a SubLink + * node's sub-select. The column number is contained in the + * `paramid' field. (This type of Param is converted to + * PARAM_EXEC during planning.) + * + * Note: currently, paramtypmod is valid for PARAM_SUBLINK Params, and for + * PARAM_EXEC Params generated from them; it is always -1 for PARAM_EXTERN + * params, since the APIs that supply values for such parameters don't carry + * any typmod info. + * ---------------- + */ +typedef enum ParamKind { PARAM_EXTERN, PARAM_EXEC, PARAM_SUBLINK } ParamKind; + +typedef struct Param { + Expr xpr; + ParamKind paramkind; /* kind of parameter. See above */ + int paramid; /* numeric ID for parameter */ + Oid paramtype; /* pg_type OID of parameter's datatype */ + int32 paramtypmod; /* typmod value, if known */ + Oid paramcollid; /* OID of collation, or InvalidOid if none */ + int location; /* token location, or -1 if unknown */ +} Param; + +/* + * Aggref + * + * The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes + * (before Postgres 9.0 it was just bare expressions). The non-resjunk TLEs + * represent the aggregate's regular arguments (if any) and resjunk TLEs can + * be added at the end to represent ORDER BY expressions that are not also + * arguments. As in a top-level Query, the TLEs can be marked with + * ressortgroupref indexes to let them be referenced by SortGroupClause + * entries in the aggorder and/or aggdistinct lists. This represents ORDER BY + * and DISTINCT operations to be applied to the aggregate input rows before + * they are passed to the transition function. The grammar only allows a + * simple "DISTINCT" specifier for the arguments, but we use the full + * query-level representation to allow more code sharing. + */ +typedef struct Aggref { + Expr xpr; + Oid aggfnoid; /* pg_proc Oid of the aggregate */ + Oid aggtype; /* type Oid of result of the aggregate */ + Oid aggcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ +#ifdef PGXC + Oid aggtrantype; /* type Oid of transition results */ + bool agghas_collectfn; /* is collection function available */ + int8 aggstage; /* in which stage this aggref is in */ +#endif /* PGXC */ + List* aggdirectargs; /* direct arguments, if an ordered-set agg */ + List* args; /* arguments and sort expressions */ + List* aggorder; /* ORDER BY (list of SortGroupClause) */ + List* aggdistinct; /* DISTINCT (list of SortGroupClause) */ + bool aggstar; /* TRUE if argument list was really '*' */ + bool aggvariadic; /* true if variadic arguments have been + * combined into an array last argument */ + char aggkind; /* aggregate kind (see pg_aggregate.h) */ + Index agglevelsup; /* > 0 if agg belongs to outer query */ + int location; /* token location, or -1 if unknown */ +} Aggref; + +/* + * GroupingFunc + * + * A GroupingFunc is a GROUPING(...) expression, which behaves in many ways + * like an aggregate function (e.g. it "belongs" to a specific query level, + * which might not be the one immediately containing it), but also differs in + * an important respect: it never evaluates its arguments, they merely + * designate expressions from the GROUP BY clause of the query level to which + * it belongs. + * + * The spec defines the evaluation of GROUPING() purely by syntactic + * replacement, but we make it a real expression for optimization purposes so + * that one Agg node can handle multiple grouping sets at once. Evaluating the + * result only needs the column positions to check against the grouping set + * being projected. However, for EXPLAIN to produce meaningful output, we have + * to keep the original expressions around, since expression deparse does not + * give us any feasible way to get at the GROUP BY clause. + * + * Also, we treat two GroupingFunc nodes as equal if they have equal arguments + * lists and agglevelsup, without comparing the refs and cols annotations. + * + * In raw parse output we have only the args list; parse analysis fills in the + * refs list, and the planner fills in the cols list. + */ +typedef struct GroupingFunc { + Expr xpr; + List* args; /* arguments, not evaluated but kept for + * benefit of EXPLAIN etc. */ + List* refs; /* ressortgrouprefs of arguments */ + List* cols; /* actual column positions set by planner */ + Index agglevelsup; /* same as Aggref.agglevelsup */ + int location; /* token location */ +} GroupingFunc; + +typedef struct GroupingId { + Expr xpr; +} GroupingId; + +/* + * WindowFunc + */ +typedef struct WindowFunc { + Expr xpr; + Oid winfnoid; /* pg_proc Oid of the function */ + Oid wintype; /* type Oid of result of the window function */ + Oid wincollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + List* args; /* arguments to the window function */ + Index winref; /* index of associated WindowClause */ + bool winstar; /* TRUE if argument list was really '*' */ + bool winagg; /* is function a simple aggregate? */ + int location; /* token location, or -1 if unknown */ +} WindowFunc; + +/* + * pseudo-column "ROWNUM" + */ +typedef struct Rownum { + Expr xpr; + Oid rownumcollid; /* OID of collation of result */ + int location; /* token location, or -1 if unknown */ +} Rownum; +/* ---------------- + * ArrayRef: describes an array subscripting operation + * + * An ArrayRef can describe fetching a single element from an array, + * fetching a subarray (array slice), storing a single element into + * an array, or storing a slice. The "store" cases work with an + * initial array value and a source value that is inserted into the + * appropriate part of the array; the result of the operation is an + * entire new modified array value. + * + * If reflowerindexpr = NIL, then we are fetching or storing a single array + * element at the subscripts given by refupperindexpr. Otherwise we are + * fetching or storing an array slice, that is a rectangular subarray + * with lower and upper bounds given by the index expressions. + * reflowerindexpr must be the same length as refupperindexpr when it + * is not NIL. + * + * Note: the result datatype is the element type when fetching a single + * element; but it is the array type when doing subarray fetch or either + * type of store. + * ---------------- + */ +typedef struct ArrayRef { + Expr xpr; + Oid refarraytype; /* type of the array proper */ + Oid refelemtype; /* type of the array elements */ + int32 reftypmod; /* typmod of the array (and elements too) */ + Oid refcollid; /* OID of collation, or InvalidOid if none */ + List* refupperindexpr; /* expressions that evaluate to upper array + * indexes */ + List* reflowerindexpr; /* expressions that evaluate to lower array + * indexes */ + Expr* refexpr; /* the expression that evaluates to an array + * value */ + Expr* refassgnexpr; /* expression for the source value, or NULL if + * fetch */ +} ArrayRef; + +/* + * CoercionContext - distinguishes the allowed set of type casts + * + * NB: ordering of the alternatives is significant; later (larger) values + * allow more casts than earlier ones. + */ +typedef enum CoercionContext { + COERCION_IMPLICIT, /* coercion in context of expression */ + COERCION_ASSIGNMENT, /* coercion in context of assignment */ + COERCION_EXPLICIT /* explicit cast operation */ +} CoercionContext; + +/* + * CoercionForm - information showing how to display a function-call node + * + * NB: equal() ignores CoercionForm fields, therefore this *must* not carry + * any semantically significant information. We need that behavior so that + * the planner will consider equivalent implicit and explicit casts to be + * equivalent. In cases where those actually behave differently, the coercion + * function's arguments will be different. + */ +typedef enum CoercionForm { + COERCE_EXPLICIT_CALL, /* display as a function call */ + COERCE_EXPLICIT_CAST, /* display as an explicit cast */ + COERCE_IMPLICIT_CAST, /* implicit cast, so hide it */ + COERCE_DONTCARE /* special case for planner */ +} CoercionForm; + +/* + * FuncExpr - expression node for a function call + */ +typedef struct FuncExpr { + Expr xpr; + Oid funcid; /* PG_PROC OID of the function */ + Oid funcresulttype; /* PG_TYPE OID of result value */ + bool funcretset; /* true if function returns set */ + /* true if variadic arguments have been combined into an array last argument */ + bool funcvariadic; + CoercionForm funcformat; /* how to display this function call */ + Oid funccollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + List* args; /* arguments to the function */ + int location; /* token location, or -1 if unknown */ + Oid refSynOid; /* PG_SYNONYM OID of the referenced synonym */ +} FuncExpr; + +/* + * NamedArgExpr - a named argument of a function + * + * This node type can only appear in the args list of a FuncCall or FuncExpr + * node. We support pure positional call notation (no named arguments), + * named notation (all arguments are named), and mixed notation (unnamed + * arguments followed by named ones). + * + * Parse analysis sets argnumber to the positional index of the argument, + * but doesn't rearrange the argument list. + * + * The planner will convert argument lists to pure positional notation + * during expression preprocessing, so execution never sees a NamedArgExpr. + */ +typedef struct NamedArgExpr { + Expr xpr; + Expr* arg; /* the argument expression */ + char* name; /* the name */ + int argnumber; /* argument's number in positional notation */ + int location; /* argument name location, or -1 if unknown */ +} NamedArgExpr; + +/* + * OpExpr - expression node for an operator invocation + * + * Semantically, this is essentially the same as a function call. + * + * Note that opfuncid is not necessarily filled in immediately on creation + * of the node. The planner makes sure it is valid before passing the node + * tree to the executor, but during parsing/planning opfuncid can be 0. + */ +typedef struct OpExpr { + Expr xpr; + Oid opno; /* PG_OPERATOR OID of the operator */ + Oid opfuncid; /* PG_PROC OID of underlying function */ + Oid opresulttype; /* PG_TYPE OID of result value */ + bool opretset; /* true if operator returns set */ + Oid opcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that operator should use */ + List* args; /* arguments to the operator (1 or 2) */ + int location; /* token location, or -1 if unknown */ +} OpExpr; + +/* + * DistinctExpr - expression node for "x IS DISTINCT FROM y" + * + * Except for the nodetag, this is represented identically to an OpExpr + * referencing the "=" operator for x and y. + * We use "=", not the more obvious "<>", because more datatypes have "=" + * than "<>". This means the executor must invert the operator result. + * Note that the operator function won't be called at all if either input + * is NULL, since then the result can be determined directly. + */ +typedef OpExpr DistinctExpr; + +/* + * NullIfExpr - a NULLIF expression + * + * Like DistinctExpr, this is represented the same as an OpExpr referencing + * the "=" operator for x and y. + */ +typedef OpExpr NullIfExpr; + +/* + * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)" + * + * The operator must yield boolean. It is applied to the left operand + * and each element of the righthand array, and the results are combined + * with OR or AND (for ANY or ALL respectively). The node representation + * is almost the same as for the underlying operator, but we need a useOr + * flag to remember whether it's ANY or ALL, and we don't have to store + * the result type (or the collation) because it must be boolean. + */ +typedef struct ScalarArrayOpExpr { + Expr xpr; + Oid opno; /* PG_OPERATOR OID of the operator */ + Oid opfuncid; /* PG_PROC OID of underlying function */ + bool useOr; /* true for ANY, false for ALL */ + Oid inputcollid; /* OID of collation that operator should use */ + List* args; /* the scalar and array operands */ + int location; /* token location, or -1 if unknown */ +} ScalarArrayOpExpr; + +/* + * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT + * + * Notice the arguments are given as a List. For NOT, of course the list + * must always have exactly one element. For AND and OR, the executor can + * handle any number of arguments. The parser generally treats AND and OR + * as binary and so it typically only produces two-element lists, but the + * optimizer will flatten trees of AND and OR nodes to produce longer lists + * when possible. There are also a few special cases where more arguments + * can appear before optimization. + */ +typedef enum BoolExprType { AND_EXPR, OR_EXPR, NOT_EXPR } BoolExprType; + +typedef struct BoolExpr { + Expr xpr; + BoolExprType boolop; + List* args; /* arguments to this expression */ + int location; /* token location, or -1 if unknown */ +} BoolExpr; + +/* + * SubLink + * + * A SubLink represents a subselect appearing in an expression, and in some + * cases also the combining operator(s) just above it. The subLinkType + * indicates the form of the expression represented: + * EXISTS_SUBLINK EXISTS(SELECT ...) + * ALL_SUBLINK (lefthand) op ALL (SELECT ...) + * ANY_SUBLINK (lefthand) op ANY (SELECT ...) + * ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...) + * EXPR_SUBLINK (SELECT with single targetlist item ...) + * ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...) + * CTE_SUBLINK WITH query (never actually part of an expression) + * For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the + * same length as the subselect's targetlist. ROWCOMPARE will *always* have + * a list with more than one entry; if the subselect has just one target + * then the parser will create an EXPR_SUBLINK instead (and any operator + * above the subselect will be represented separately). Note that both + * ROWCOMPARE and EXPR require the subselect to deliver only one row. + * ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean + * results. ALL and ANY combine the per-row results using AND and OR + * semantics respectively. + * ARRAY requires just one target column, and creates an array of the target + * column's type using any number of rows resulting from the subselect. + * + * SubLink is classed as an Expr node, but it is not actually executable; + * it must be replaced in the expression tree by a SubPlan node during + * planning. + * + * NOTE: in the raw output of gram.y, testexpr contains just the raw form + * of the lefthand expression (if any), and operName is the String name of + * the combining operator. Also, subselect is a raw parsetree. During parse + * analysis, the parser transforms testexpr into a complete boolean expression + * that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the + * output columns of the subselect. And subselect is transformed to a Query. + * This is the representation seen in saved rules and in the rewriter. + * + * In EXISTS, EXPR, and ARRAY SubLinks, testexpr and operName are unused and + * are always null. + * + * The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used + * in SubPlans generated for WITH subqueries. + */ +typedef enum SubLinkType { + EXISTS_SUBLINK, + ALL_SUBLINK, + ANY_SUBLINK, + ROWCOMPARE_SUBLINK, + EXPR_SUBLINK, + ARRAY_SUBLINK, + CTE_SUBLINK /* for SubPlans only */ +} SubLinkType; + +typedef struct SubLink { + Expr xpr; + SubLinkType subLinkType; /* see above */ + Node* testexpr; /* outer-query test for ALL/ANY/ROWCOMPARE */ + List* operName; /* originally specified operator name */ + Node* subselect; /* subselect as Query* or parsetree */ + int location; /* token location, or -1 if unknown */ +} SubLink; + +/* + * SubPlan - executable expression node for a subplan (sub-SELECT) + * + * The planner replaces SubLink nodes in expression trees with SubPlan + * nodes after it has finished planning the subquery. SubPlan references + * a sub-plantree stored in the subplans list of the toplevel PlannedStmt. + * (We avoid a direct link to make it easier to copy expression trees + * without causing multiple processing of the subplan.) + * + * In an ordinary subplan, testexpr points to an executable expression + * (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining + * operator(s); the left-hand arguments are the original lefthand expressions, + * and the right-hand arguments are PARAM_EXEC Param nodes representing the + * outputs of the sub-select. (NOTE: runtime coercion functions may be + * inserted as well.) This is just the same expression tree as testexpr in + * the original SubLink node, but the PARAM_SUBLINK nodes are replaced by + * suitably numbered PARAM_EXEC nodes. + * + * If the sub-select becomes an initplan rather than a subplan, the executable + * expression is part of the outer plan's expression tree (and the SubPlan + * node itself is not, but rather is found in the outer plan's initPlan + * list). In this case testexpr is NULL to avoid duplication. + * + * The planner also derives lists of the values that need to be passed into + * and out of the subplan. Input values are represented as a list "args" of + * expressions to be evaluated in the outer-query context (currently these + * args are always just Vars, but in principle they could be any expression). + * The values are assigned to the global PARAM_EXEC params indexed by parParam + * (the parParam and args lists must have the same ordering). setParam is a + * list of the PARAM_EXEC params that are computed by the sub-select, if it + * is an initplan; they are listed in order by sub-select output column + * position. (parParam and setParam are integer Lists, not Bitmapsets, + * because their ordering is significant.) + * + * Also, the planner computes startup and per-call costs for use of the + * SubPlan. Note that these include the cost of the subquery proper, + * evaluation of the testexpr if any, and any hashtable management overhead. + */ +typedef struct SubPlan { + Expr xpr; + /* Fields copied from original SubLink: */ + SubLinkType subLinkType; /* see above */ + /* The combining operators, transformed to an executable expression: */ + Node* testexpr; /* OpExpr or RowCompareExpr expression tree */ + List* paramIds; /* IDs of Params embedded in the above */ + /* Identification of the Plan tree to use: */ + int plan_id; /* Index (from 1) in PlannedStmt.subplans */ + /* Identification of the SubPlan for EXPLAIN and debugging purposes: */ + char* plan_name; /* A name assigned during planning */ + /* Extra data useful for determining subplan's output type: */ + Oid firstColType; /* Type of first column of subplan result */ + int32 firstColTypmod; /* Typmod of first column of subplan result */ + Oid firstColCollation; /* Collation of first column of subplan result */ + /* Information about execution strategy: */ + /* TRUE to store subselect output in a hash table (implies we are doing "IN") */ + bool useHashTable; + /* TRUE if it's okay to return FALSE when the spec result is UNKNOWN; this allows much simpler handling of null values */ + bool unknownEqFalse; + /* Information for passing params into and out of the subselect: */ + /* setParam and parParam are lists of integers (param IDs) */ + List* setParam; /* initplan subqueries have to set these Params for parent plan */ + List* parParam; /* indices of input Params from parent plan */ + List* args; /* exprs to pass as parParam values */ + /* Estimated execution costs: */ + Cost startup_cost; /* one-time setup cost */ + Cost per_call_cost; /* cost for each subplan evaluation */ +} SubPlan; + +/* + * AlternativeSubPlan - expression node for a choice among SubPlans + * + * The subplans are given as a List so that the node definition need not + * change if there's ever more than two alternatives. For the moment, + * though, there are always exactly two; and the first one is the fast-start + * plan. + */ +typedef struct AlternativeSubPlan { + Expr xpr; + List* subplans; /* SubPlan(s) with equivalent results */ +} AlternativeSubPlan; + +/* ---------------- + * FieldSelect + * + * FieldSelect represents the operation of extracting one field from a tuple + * value. At runtime, the input expression is expected to yield a rowtype + * Datum. The specified field number is extracted and returned as a Datum. + * ---------------- + */ +typedef struct FieldSelect { + Expr xpr; + Expr* arg; /* input expression */ + AttrNumber fieldnum; /* attribute number of field to extract */ + Oid resulttype; /* type of the field (result type of this + * node) */ + int32 resulttypmod; /* output typmod (usually -1) */ + Oid resultcollid; /* OID of collation of the field */ +} FieldSelect; + +/* ---------------- + * FieldStore + * + * FieldStore represents the operation of modifying one field in a tuple + * value, yielding a new tuple value (the input is not touched!). Like + * the assign case of ArrayRef, this is used to implement UPDATE of a + * portion of a column. + * + * A single FieldStore can actually represent updates of several different + * fields. The parser only generates FieldStores with single-element lists, + * but the planner will collapse multiple updates of the same base column + * into one FieldStore. + * ---------------- + */ +typedef struct FieldStore { + Expr xpr; + Expr* arg; /* input tuple value */ + List* newvals; /* new value(s) for field(s) */ + List* fieldnums; /* integer list of field attnums */ + Oid resulttype; /* type of result (same as type of arg) */ + /* Like RowExpr, we deliberately omit a typmod and collation here */ +} FieldStore; + +/* ---------------- + * RelabelType + * + * RelabelType represents a "dummy" type coercion between two binary- + * compatible datatypes, such as reinterpreting the result of an OID + * expression as an int4. It is a no-op at runtime; we only need it + * to provide a place to store the correct type to be attributed to + * the expression result during type resolution. (We can't get away + * with just overwriting the type field of the input expression node, + * so we need a separate node to show the coercion's result type.) + * ---------------- + */ +typedef struct RelabelType { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type of coercion expression */ + int32 resulttypmod; /* output typmod (usually -1) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm relabelformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} RelabelType; + +/* ---------------- + * CoerceViaIO + * + * CoerceViaIO represents a type coercion between two types whose textual + * representations are compatible, implemented by invoking the source type's + * typoutput function then the destination type's typinput function. + * ---------------- + */ +typedef struct CoerceViaIO { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type of coercion */ + /* output typmod is not stored, but is presumed -1 */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm coerceformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} CoerceViaIO; + +/* ---------------- + * ArrayCoerceExpr + * + * ArrayCoerceExpr represents a type coercion from one array type to another, + * which is implemented by applying the indicated element-type coercion + * function to each element of the source array. If elemfuncid is InvalidOid + * then the element types are binary-compatible, but the coercion still + * requires some effort (we have to fix the element type ID stored in the + * array header). + * ---------------- + */ +typedef struct ArrayCoerceExpr { + Expr xpr; + Expr* arg; /* input expression (yields an array) */ + Oid elemfuncid; /* OID of element coercion function, or 0 */ + Oid resulttype; /* output type of coercion (an array type) */ + int32 resulttypmod; /* output typmod (also element typmod) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + bool isExplicit; /* conversion semantics flag to pass to func */ + CoercionForm coerceformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} ArrayCoerceExpr; + +/* ---------------- + * ConvertRowtypeExpr + * + * ConvertRowtypeExpr represents a type coercion from one composite type + * to another, where the source type is guaranteed to contain all the columns + * needed for the destination type plus possibly others; the columns need not + * be in the same positions, but are matched up by name. This is primarily + * used to convert a whole-row value of an inheritance child table into a + * valid whole-row value of its parent table's rowtype. + * ---------------- + */ +typedef struct ConvertRowtypeExpr { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type (always a composite type) */ + /* Like RowExpr, we deliberately omit a typmod and collation here */ + CoercionForm convertformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} ConvertRowtypeExpr; + +/* ---------- + * CollateExpr - COLLATE + * + * The planner replaces CollateExpr with RelabelType during expression + * preprocessing, so execution never sees a CollateExpr. + * ---------- + */ +typedef struct CollateExpr { + Expr xpr; + Expr* arg; /* input expression */ + Oid collOid; /* collation's OID */ + int location; /* token location, or -1 if unknown */ +} CollateExpr; + +/* ---------- + * CaseExpr - a CASE expression + * + * We support two distinct forms of CASE expression: + * CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ] + * CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ] + * These are distinguishable by the "arg" field being NULL in the first case + * and the testexpr in the second case. + * + * In the raw grammar output for the second form, the condition expressions + * of the WHEN clauses are just the comparison values. Parse analysis + * converts these to valid boolean expressions of the form + * CaseTestExpr '=' compexpr + * where the CaseTestExpr node is a placeholder that emits the correct + * value at runtime. This structure is used so that the testexpr need be + * evaluated only once. Note that after parse analysis, the condition + * expressions always yield boolean. + * + * Note: we can test whether a CaseExpr has been through parse analysis + * yet by checking whether casetype is InvalidOid or not. + * ---------- + */ +typedef struct CaseExpr { + Expr xpr; + Oid casetype; /* type of expression result */ + Oid casecollid; /* OID of collation, or InvalidOid if none */ + Expr* arg; /* implicit equality comparison argument */ + List* args; /* the arguments (list of WHEN clauses) */ + Expr* defresult; /* the default result (ELSE clause) */ + int location; /* token location, or -1 if unknown */ +} CaseExpr; + +/* + * CaseWhen - one arm of a CASE expression + */ +typedef struct CaseWhen { + Expr xpr; + Expr* expr; /* condition expression */ + Expr* result; /* substitution result */ + int location; /* token location, or -1 if unknown */ +} CaseWhen; + +/* + * Placeholder node for the test value to be processed by a CASE expression. + * This is effectively like a Param, but can be implemented more simply + * since we need only one replacement value at a time. + * + * We also use this in nested UPDATE expressions. + * See transformAssignmentIndirection(). + */ +typedef struct CaseTestExpr { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ +} CaseTestExpr; + +/* + * ArrayExpr - an ARRAY[] expression + * + * Note: if multidims is false, the constituent expressions all yield the + * scalar type identified by element_typeid. If multidims is true, the + * constituent expressions all yield arrays of element_typeid (ie, the same + * type as array_typeid); at runtime we must check for compatible subscripts. + */ +typedef struct ArrayExpr { + Expr xpr; + Oid array_typeid; /* type of expression result */ + Oid array_collid; /* OID of collation, or InvalidOid if none */ + Oid element_typeid; /* common type of array elements */ + List* elements; /* the array elements or sub-arrays */ + bool multidims; /* true if elements are sub-arrays */ + int location; /* token location, or -1 if unknown */ +} ArrayExpr; + +/* + * RowExpr - a ROW() expression + * + * Note: the list of fields must have a one-for-one correspondence with + * physical fields of the associated rowtype, although it is okay for it + * to be shorter than the rowtype. That is, the N'th list element must + * match up with the N'th physical field. When the N'th physical field + * is a dropped column (attisdropped) then the N'th list element can just + * be a NULL constant. (This case can only occur for named composite types, + * not RECORD types, since those are built from the RowExpr itself rather + * than vice versa.) It is important not to assume that length(args) is + * the same as the number of columns logically present in the rowtype. + * + * colnames provides field names in cases where the names can't easily be + * obtained otherwise. Names *must* be provided if row_typeid is RECORDOID. + * If row_typeid identifies a known composite type, colnames can be NIL to + * indicate the type's cataloged field names apply. Note that colnames can + * be non-NIL even for a composite type, and typically is when the RowExpr + * was created by expanding a whole-row Var. This is so that we can retain + * the column alias names of the RTE that the Var referenced (which would + * otherwise be very difficult to extract from the parsetree). Like the + * args list, colnames is one-for-one with physical fields of the rowtype. + */ +typedef struct RowExpr { + Expr xpr; + List* args; /* the fields */ + Oid row_typeid; /* RECORDOID or a composite type's ID */ + + /* + * Note: we deliberately do NOT store a typmod. Although a typmod will be + * associated with specific RECORD types at runtime, it will differ for + * different backends, and so cannot safely be stored in stored + * parsetrees. We must assume typmod -1 for a RowExpr node. + * + * We don't need to store a collation either. The result type is + * necessarily composite, and composite types never have a collation. + */ + CoercionForm row_format; /* how to display this node */ + List* colnames; /* list of String, or NIL */ + int location; /* token location, or -1 if unknown */ +} RowExpr; + +/* + * RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2) + * + * We support row comparison for any operator that can be determined to + * act like =, <>, <, <=, >, or >= (we determine this by looking for the + * operator in btree opfamilies). Note that the same operator name might + * map to a different operator for each pair of row elements, since the + * element datatypes can vary. + * + * A RowCompareExpr node is only generated for the < <= > >= cases; + * the = and <> cases are translated to simple AND or OR combinations + * of the pairwise comparisons. However, we include = and <> in the + * RowCompareType enum for the convenience of parser logic. + */ +typedef enum RowCompareType { + /* Values of this enum are chosen to match btree strategy numbers */ + ROWCOMPARE_LT = 1, /* BTLessStrategyNumber */ + ROWCOMPARE_LE = 2, /* BTLessEqualStrategyNumber */ + ROWCOMPARE_EQ = 3, /* BTEqualStrategyNumber */ + ROWCOMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */ + ROWCOMPARE_GT = 5, /* BTGreaterStrategyNumber */ + ROWCOMPARE_NE = 6 /* no such btree strategy */ +} RowCompareType; + +typedef struct RowCompareExpr { + Expr xpr; + RowCompareType rctype; /* LT LE GE or GT, never EQ or NE */ + List* opnos; /* OID list of pairwise comparison ops */ + List* opfamilies; /* OID list of containing operator families */ + List* inputcollids; /* OID list of collations for comparisons */ + List* largs; /* the left-hand input arguments */ + List* rargs; /* the right-hand input arguments */ +} RowCompareExpr; + +/* + * CoalesceExpr - a COALESCE expression + */ +typedef struct CoalesceExpr { + Expr xpr; + Oid coalescetype; /* type of expression result */ + Oid coalescecollid; /* OID of collation, or InvalidOid if none */ + List* args; /* the arguments */ + int location; /* token location, or -1 if unknown */ + bool isnvl; /* is CoalesceExpr NVL ? */ +} CoalesceExpr; + +/* + * MinMaxExpr - a GREATEST or LEAST function + */ +typedef enum MinMaxOp { IS_GREATEST, IS_LEAST } MinMaxOp; + +typedef struct MinMaxExpr { + Expr xpr; + Oid minmaxtype; /* common type of arguments and result */ + Oid minmaxcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + MinMaxOp op; /* function to execute */ + List* args; /* the arguments */ + int location; /* token location, or -1 if unknown */ +} MinMaxExpr; + +/* + * XmlExpr - various SQL/XML functions requiring special grammar productions + * + * 'name' carries the "NAME foo" argument (already XML-escaped). + * 'named_args' and 'arg_names' represent an xml_attribute list. + * 'args' carries all other arguments. + * + * Note: result type/typmod/collation are not stored, but can be deduced + * from the XmlExprOp. The type/typmod fields are just used for display + * purposes, and are NOT necessarily the true result type of the node. + * (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.) + */ +typedef enum XmlExprOp { + IS_XMLCONCAT, /* XMLCONCAT(args) */ + IS_XMLELEMENT, /* XMLELEMENT(name, xml_attributes, args) */ + IS_XMLFOREST, /* XMLFOREST(xml_attributes) */ + IS_XMLPARSE, /* XMLPARSE(text, is_doc, preserve_ws) */ + IS_XMLPI, /* XMLPI(name [, args]) */ + IS_XMLROOT, /* XMLROOT(xml, version, standalone) */ + IS_XMLSERIALIZE, /* XMLSERIALIZE(is_document, xmlval) */ + IS_DOCUMENT /* xmlval IS DOCUMENT */ +} XmlExprOp; + +typedef enum { XMLOPTION_DOCUMENT, XMLOPTION_CONTENT } XmlOptionType; + +typedef struct XmlExpr { + Expr xpr; + XmlExprOp op; /* xml function ID */ + char* name; /* name in xml(NAME foo ...) syntaxes */ + List* named_args; /* non-XML expressions for xml_attributes */ + List* arg_names; /* parallel list of Value strings */ + List* args; /* list of expressions */ + XmlOptionType xmloption; /* DOCUMENT or CONTENT */ + Oid type; /* target type/typmod for XMLSERIALIZE */ + int32 typmod; + int location; /* token location, or -1 if unknown */ +} XmlExpr; + +/* ---------------- + * NullTest + * + * NullTest represents the operation of testing a value for NULLness. + * The appropriate test is performed and returned as a boolean Datum. + * + * NOTE: the semantics of this for rowtype inputs are noticeably different + * from the scalar case. We provide an "argisrow" flag to reflect that. + * ---------------- + */ +typedef enum NullTestType { IS_NULL, IS_NOT_NULL } NullTestType; + +typedef struct NullTest { + Expr xpr; + Expr* arg; /* input expression */ + NullTestType nulltesttype; /* IS NULL, IS NOT NULL */ + bool argisrow; /* T if input is of a composite type */ +} NullTest; + +/* + * BooleanTest + * + * BooleanTest represents the operation of determining whether a boolean + * is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations + * are supported. Note that a NULL input does *not* cause a NULL result. + * The appropriate test is performed and returned as a boolean Datum. + */ +typedef enum BoolTestType { IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN } BoolTestType; + +typedef struct BooleanTest { + Expr xpr; + Expr* arg; /* input expression */ + BoolTestType booltesttype; /* test type */ +} BooleanTest; + +/* HashFilter indicate that filter tuple using hash */ +typedef struct HashFilter { + Expr xpr; + List* arg; /* input expression */ + List* typeOids; /* type oid list of var for filter */ + List* nodeList; /* Node indices where data is located */ + // uint2 *bucketMap; +} HashFilter; + +/* + * EstSPNode + * + * For some expression, we can't estimate them though vars under them. Therefore, + * we should keep them and get the vars under them to get an overall estimation. + */ +typedef struct EstSPNode { + Expr xpr; + Node* expr; + List* varlist; +} EstSPNode; + +/* + * CoerceToDomain + * + * CoerceToDomain represents the operation of coercing a value to a domain + * type. At runtime (and not before) the precise set of constraints to be + * checked will be determined. If the value passes, it is returned as the + * result; if not, an error is raised. Note that this is equivalent to + * RelabelType in the scenario where no constraints are applied. + */ +typedef struct CoerceToDomain { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* domain type ID (result type) */ + int32 resulttypmod; /* output typmod (currently always -1) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm coercionformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} CoerceToDomain; + +/* + * Placeholder node for the value to be processed by a domain's check + * constraint. This is effectively like a Param, but can be implemented more + * simply since we need only one replacement value at a time. + * + * Note: the typeId/typeMod/collation will be set from the domain's base type, + * not the domain itself. This is because we shouldn't consider the value + * to be a member of the domain if we haven't yet checked its constraints. + */ +typedef struct CoerceToDomainValue { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ + int location; /* token location, or -1 if unknown */ +} CoerceToDomainValue; + +/* + * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command. + * + * This is not an executable expression: it must be replaced by the actual + * column default expression during rewriting. But it is convenient to + * treat it as an expression node during parsing and rewriting. + */ +typedef struct SetToDefault { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ + int location; /* token location, or -1 if unknown */ +} SetToDefault; + +/* value expressions (changed for client_logic feature) */ +typedef struct ExprWithComma { + NodeTag type; + Expr *xpr; + int comma_before_loc; +} ExprWithComma; + +/* + * Node representing [WHERE] CURRENT OF cursor_name + * + * CURRENT OF is a bit like a Var, in that it carries the rangetable index + * of the target relation being constrained; this aids placing the expression + * correctly during planning. We can assume however that its "levelsup" is + * always zero, due to the syntactic constraints on where it can appear. + * + * The referenced cursor can be represented either as a hardwired string + * or as a reference to a run-time parameter of type REFCURSOR. The latter + * case is for the convenience of plpgsql. + */ +typedef struct CurrentOfExpr { + Expr xpr; + Index cvarno; /* RT index of target relation */ + char* cursor_name; /* name of referenced cursor, or NULL */ + int cursor_param; /* refcursor parameter number, or 0 */ +} CurrentOfExpr; + +/* -------------------- + * TargetEntry - + * a target entry (used in query target lists) + * + * Strictly speaking, a TargetEntry isn't an expression node (since it can't + * be evaluated by ExecEvalExpr). But we treat it as one anyway, since in + * very many places it's convenient to process a whole query targetlist as a + * single expression tree. + * + * In a SELECT's targetlist, resno should always be equal to the item's + * ordinal position (counting from 1). However, in an INSERT or UPDATE + * targetlist, resno represents the attribute number of the destination + * column for the item; so there may be missing or out-of-order resnos. + * It is even legal to have duplicated resnos; consider + * UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ... + * The two meanings come together in the executor, because the planner + * transforms INSERT/UPDATE tlists into a normalized form with exactly + * one entry for each column of the destination table. Before that's + * happened, however, it is risky to assume that resno == position. + * Generally get_tle_by_resno() should be used rather than list_nth() + * to fetch tlist entries by resno, and only in SELECT should you assume + * that resno is a unique identifier. + * + * resname is required to represent the correct column name in non-resjunk + * entries of top-level SELECT targetlists, since it will be used as the + * column title sent to the frontend. In most other contexts it is only + * a debugging aid, and may be wrong or even NULL. (In particular, it may + * be wrong in a tlist from a stored rule, if the referenced column has been + * renamed by ALTER TABLE since the rule was made. Also, the planner tends + * to store NULL rather than look up a valid name for tlist entries in + * non-toplevel plan nodes.) In resjunk entries, resname should be either + * a specific system-generated name (such as "ctid") or NULL; anything else + * risks confusing ExecGetJunkAttribute! + * + * ressortgroupref is used in the representation of ORDER BY, GROUP BY, and + * DISTINCT items. Targetlist entries with ressortgroupref=0 are not + * sort/group items. If ressortgroupref>0, then this item is an ORDER BY, + * GROUP BY, and/or DISTINCT target value. No two entries in a targetlist + * may have the same nonzero ressortgroupref --- but there is no particular + * meaning to the nonzero values, except as tags. (For example, one must + * not assume that lower ressortgroupref means a more significant sort key.) + * The order of the associated SortGroupClause lists determine the semantics. + * + * resorigtbl/resorigcol identify the source of the column, if it is a + * simple reference to a column of a base table (or view). If it is not + * a simple reference, these fields are zeroes. + * + * If resjunk is true then the column is a working column (such as a sort key) + * that should be removed from the final output of the query. Resjunk columns + * must have resnos that cannot duplicate any regular column's resno. Also + * note that there are places that assume resjunk columns come after non-junk + * columns. + * -------------------- + */ +typedef struct TargetEntry { + Expr xpr; + Expr* expr; /* expression to evaluate */ + AttrNumber resno; /* attribute number (see notes above) */ + char* resname; /* name of the column (could be NULL) */ + Index ressortgroupref; /* nonzero if referenced by a sort/group + * clause */ + Oid resorigtbl; /* OID of column's source table */ + AttrNumber resorigcol; /* column's number in source table */ + bool resjunk; /* set to true to eliminate the attribute from + * final target list */ +} TargetEntry; + +/* ---------------------------------------------------------------- + * node types for join trees + * + * The leaves of a join tree structure are RangeTblRef nodes. Above + * these, JoinExpr nodes can appear to denote a specific kind of join + * or qualified join. Also, FromExpr nodes can appear to denote an + * ordinary cross-product join ("FROM foo, bar, baz WHERE ..."). + * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it + * may have any number of child nodes, not just two. + * + * NOTE: the top level of a Query's jointree is always a FromExpr. + * Even if the jointree contains no rels, there will be a FromExpr. + * + * NOTE: the qualification expressions present in JoinExpr nodes are + * *in addition to* the query's main WHERE clause, which appears as the + * qual of the top-level FromExpr. The reason for associating quals with + * specific nodes in the jointree is that the position of a qual is critical + * when outer joins are present. (If we enforce a qual too soon or too late, + * that may cause the outer join to produce the wrong set of NULL-extended + * rows.) If all joins are inner joins then all the qual positions are + * semantically interchangeable. + * + * NOTE: in the raw output of gram.y, a join tree contains RangeVar, + * RangeSubselect, and RangeFunction nodes, which are all replaced by + * RangeTblRef nodes during the parse analysis phase. Also, the top-level + * FromExpr is added during parse analysis; the grammar regards FROM and + * WHERE as separate. + * ---------------------------------------------------------------- + */ + +/* + * RangeTblRef - reference to an entry in the query's rangetable + * + * We could use direct pointers to the RT entries and skip having these + * nodes, but multiple pointers to the same node in a querytree cause + * lots of headaches, so it seems better to store an index into the RT. + */ +typedef struct RangeTblRef { + NodeTag type; + int rtindex; +} RangeTblRef; + +/* ---------- + * JoinExpr - for SQL JOIN expressions + * + * isNatural, usingClause, and quals are interdependent. The user can write + * only one of NATURAL, USING(), or ON() (this is enforced by the grammar). + * If he writes NATURAL then parse analysis generates the equivalent USING() + * list, and from that fills in "quals" with the right equality comparisons. + * If he writes USING() then "quals" is filled with equality comparisons. + * If he writes ON() then only "quals" is set. Note that NATURAL/USING + * are not equivalent to ON() since they also affect the output column list. + * + * alias is an Alias node representing the AS alias-clause attached to the + * join expression, or NULL if no clause. NB: presence or absence of the + * alias has a critical impact on semantics, because a join with an alias + * restricts visibility of the tables/columns inside it. + * + * During parse analysis, an RTE is created for the Join, and its index + * is filled into rtindex. This RTE is present mainly so that Vars can + * be created that refer to the outputs of the join. The planner sometimes + * generates JoinExprs internally; these can have rtindex = 0 if there are + * no join alias variables referencing such joins. + * ---------- + */ +typedef struct JoinExpr { + NodeTag type; + JoinType jointype; /* type of join */ + bool isNatural; /* Natural join? Will need to shape table */ + Node* larg; /* left subtree */ + Node* rarg; /* right subtree */ + List* usingClause; /* USING clause, if any (list of String) */ + Node* quals; /* qualifiers on join, if any */ + Alias* alias; /* user-written alias clause, if any */ + int rtindex; /* RT index assigned for join, or 0 */ +} JoinExpr; + +/* ---------- + * FromExpr - represents a FROM ... WHERE ... construct + * + * This is both more flexible than a JoinExpr (it can have any number of + * children, including zero) and less so --- we don't need to deal with + * aliases and so on. The output column set is implicitly just the union + * of the outputs of the children. + * ---------- + */ +typedef struct FromExpr { + NodeTag type; + List* fromlist; /* List of join subtrees */ + Node* quals; /* qualifiers on join, if any */ +} FromExpr; + +#ifdef PGXC +/* ---------- + * DistributionType - how to distribute the data + * + * ---------- + */ +typedef enum DistributionType { + DISTTYPE_REPLICATION, /* Replicated */ + DISTTYPE_HASH, /* Hash partitioned */ + DISTTYPE_ROUNDROBIN, /* Round Robin */ + DISTTYPE_MODULO, /* Modulo partitioned */ + DISTTYPE_HIDETAG, /* Use a hidden column as distribute column */ + DISTTYPE_LIST, /* List */ + DISTTYPE_RANGE /* Range */ +} DistributionType; + +typedef struct ListSliceDefState { + NodeTag type; + char* name; + List* boundaries; /* list of boundary(multi-values) */ + char* datanode_name; +} ListSliceDefState; + +typedef struct DistState { + NodeTag type; + /* + * 'r' range slice + * 'l' list slice + */ + char strategy; + /* list of slice definition, like: + * ListSliceDefState or RangePartitionDefState or RangePartitionStartEndDefState + */ + List* sliceList; + char* refTableName; +} DistState; + +/* ---------- + * DistributeBy - represents a DISTRIBUTE BY clause in a CREATE TABLE statement + * + * ---------- + */ +typedef struct DistributeBy { + NodeTag type; + DistributionType disttype; /* Distribution type */ + List* colname; /* Distribution column name */ + DistState* distState; /* Slice Definitions */ + Oid referenceoid; /* table oid that slice references, InvalidOid if none */ +} DistributeBy; + +/* ---------- + * SubClusterType - type of subcluster used + * + * ---------- + */ +typedef enum PGXCSubClusterType { SUBCLUSTER_NONE, SUBCLUSTER_NODE, SUBCLUSTER_GROUP } PGXCSubClusterType; + +/* ---------- + * PGXCSubCluster - Subcluster on which a table can be created + * + * ---------- + */ +typedef struct PGXCSubCluster { + NodeTag type; + PGXCSubClusterType clustertype; /* Subcluster type */ + List* members; /* List of nodes or groups */ +} PGXCSubCluster; +#endif + +typedef struct { + NodeTag type; + Oid relid; + AttrNumber attno; + char* relname; + char* attname; + + bool indexcol; + List* indexoids; + bool indexpath; +} IndexVar; + +typedef struct UpsertExpr { + NodeTag type; + UpsertAction upsertAction; /* DO NOTHING or UPDATE? */ + + /* DUPLICATE KEY UPDATE */ + List* updateTlist; /* List of UPDATE TargetEntrys */ + List* exclRelTlist; /* tlist of the 'EXCLUDED' pseudo relation */ + int exclRelIndex; /* RT index of 'EXCLUDED' relation */ +} UpsertExpr; + +#endif /* PRIMNODES_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/print.h postgresql-hll-2.14/include/include/nodes/print.h --- postgresql-hll-2.14_old/include/include/nodes/print.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/print.h 2020-12-12 17:06:43.233347858 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * print.h + * definitions for nodes/print.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/print.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRINT_H +#define PRINT_H + +#include "executor/tuptable.h" + +#define nodeDisplay(x) pprint(x) + +extern void print(const void* obj); +extern void pprint(const void* obj); +extern void elog_node_display(int lev, const char* title, const void* obj, bool pretty); +extern char* format_node_dump(const char* dump); +extern char* pretty_format_node_dump(const char* dump); +extern void print_rt(const List* rtable); +extern void print_expr(const Node* expr, const List* rtable); +extern void print_pathkeys(const List* pathkeys, const List* rtable); +extern void print_tl(const List* tlist, const List* rtable); +extern void print_slot(TupleTableSlot* slot); +extern char* ExprToString(const Node* expr, const List* rtable); + +#endif /* PRINT_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/readfuncs.h postgresql-hll-2.14/include/include/nodes/readfuncs.h --- postgresql-hll-2.14_old/include/include/nodes/readfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/readfuncs.h 2020-12-12 17:06:43.233347858 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * readfuncs.h + * header file for read.c and readfuncs.c. These functions are internal + * to the stringToNode interface and should not be used by anyone else. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/readfuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef READFUNCS_H +#define READFUNCS_H + +#include "nodes/nodes.h" + +/* + * prototypes for functions in read.c (the lisp token parser) + */ +extern char* pg_strtok(int* length, bool chg_org_strok = true); +extern char* debackslash(const char* token, int length); +extern void* nodeRead(char* token, int tok_len); + +/* + * prototypes for functions in readfuncs.c + */ +extern Node* parseNodeString(void); + +extern void* stringToNode_skip_extern_fields(char* str); + +#endif /* READFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/relation.h postgresql-hll-2.14/include/include/nodes/relation.h --- postgresql-hll-2.14_old/include/include/nodes/relation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/relation.h 2020-12-12 17:06:43.234347871 +0800 @@ -0,0 +1,1970 @@ +/* ------------------------------------------------------------------------- + * + * relation.h + * Definitions for planner's internal data structures. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/relation.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELATION_H +#define RELATION_H + +#include "access/sdir.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "storage/block.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" + +#include "optimizer/bucketinfo.h" + +/* + * When looking for a "cheapest path", this enum specifies whether we want + * cheapest startup cost or cheapest total cost. + */ +typedef enum CostSelector { STARTUP_COST, TOTAL_COST } CostSelector; + +/* + * The cost estimate produced by cost_qual_eval() includes both a one-time + * (startup) cost, and a per-tuple cost. + */ +typedef struct QualCost { + Cost startup; /* one-time cost */ + Cost per_tuple; /* per-evaluation cost */ +} QualCost; + +/* + * Costing aggregate function execution requires these statistics about + * the aggregates to be executed by a given Agg node. Note that transCost + * includes the execution costs of the aggregates' input expressions. + */ +typedef struct AggClauseCosts { + int numAggs; /* total number of aggregate functions */ + int numOrderedAggs; /* number that use ORDER BY */ + List* exprAggs; /* expression that use DISTINCT */ + QualCost transCost; /* total per-input-row execution costs */ + Cost finalCost; /* total costs of agg final functions */ + Size transitionSpace; /* space for pass-by-ref transition data */ + bool hasdctDnAggs; /* has agg-once functions in distinct expr */ + bool hasDnAggs; /* has agg-once functions not in distinct expr */ + bool unhashable; /* if distinct node is not hashable */ + bool hasPolymorphicType; /* if aggregate expressions have polymorphic pseudotype */ + int aggWidth; /* total width of agg function */ +} AggClauseCosts; + +/* + * For global path optimization, we should keep all paths with interesting distribute + * keys. There are two kinds of such keys: super set (taking effect for intermediate + * relation and before agg) and exact match (taking effect for intermediate resultset + * with all referenced tables (no group by or subset of group by), or final result set + * after agg). Super set key is used for aggregation redistribution optimization, and + * matching key is used for insert/ delete/ update redistribution optimization. + * Also, we should keep corresponding positions for each interesting key, in order to + * redistribute in positions in sub level, to avoid redistribute in current level + */ +typedef struct ItstDisKey { + List* superset_keys; /* list of superset keys list, several members possible */ + List* matching_keys; /* list of exact matching keys, */ +} ItstDisKey; + +typedef struct { + int bloomfilter_index; /* Current bloomfilter Num */ + bool add_index; /* If bloomfilter_index add 1. To eqClass equal member, it's filter index is alike. */ +} bloomfilter_context; + +typedef struct PlannerContext { + MemoryContext plannerMemContext; + MemoryContext dataSkewMemContext; +} PlannerContext; + +/* + * For query mem-based optimization, we should record current memory usage, + * memory usage with no disk, with maximum disk possible (no severe influence + * to operator. We allow hashjoin and hashagg to use at most 32 disk files, and + * sort 256 files. For materialize, we don't want it to spill to disk unless it exceeds + * memory allowed), and the performance degression ratio between them. + * (Assume it's linear) + */ +typedef struct OpMemInfo { + double opMem; /* u_sess->opt_cxt.op_work_mem in path phase */ + double minMem; /* ideal memory usage with maximum disk */ + double maxMem; /* ideal memory usage without disk */ + double regressCost; /* performance degression ratio between min and max Mem */ +} OpMemInfo; + +#define HASH_MAX_DISK_SIZE 32 +#define SORT_MAX_DISK_SIZE 256 +#define DFS_MIN_MEM_SIZE 128 * 1024 /* 128MB, the unit is kb */ +#define PARTITION_MAX_SIZE (2 * 1024 * 1024L) /* 2GB, the unit is kb */ +#define MAX_BATCH_ROWS 60000 /* default max number of max batch rows, the value can be changed. */ +#define PARTIAL_CLUSTER_ROWS 4200000 /* default vaule for max partialClusterRows, the value can be changed. */ + +/* the min memory for sort is 16MB, the unit is kb. Don't sort in memory when we don't have engough memory. */ +#define SORT_MIM_MEM 16 * 1024 +#define DFSSCAN_MIN_MEM 12 * 1024 /* the min memory for dfsscan is 12MB, the unit is kb. */ +#define MEM_KB 1024L /* 1024kb for caculating mem info */ + +/* PSORT_SPREAD_MAXMEM_RATIO can increase 20% for partition table's one part on extended limit. */ +#define PSORT_SPREAD_MAXMEM_RATIO 1.2 + +/* ---------- + * PlannerGlobal + * Global information for planning/optimization + * + * PlannerGlobal holds state for an entire planner invocation; this state + * is shared across all levels of sub-Queries that exist in the command being + * planned. + * ---------- + */ +typedef struct PlannerGlobal { + NodeTag type; + + ParamListInfo boundParams; /* Param values provided to planner() */ + + List* paramlist; /* unused, will be removed in 9.3 */ + + List* subplans; /* Plans for SubPlan nodes */ + + List* subroots; /* PlannerInfos for SubPlan nodes */ + + Bitmapset* rewindPlanIDs; /* indices of subplans that require REWIND */ + + List* finalrtable; /* "flat" rangetable for executor */ + + List* finalrowmarks; /* "flat" list of PlanRowMarks */ + + List* resultRelations; /* "flat" list of integer RT indexes */ + + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the plan depends on */ + + List* invalItems; /* other dependencies, as PlanInvalItems */ + + Index lastPHId; /* highest PlaceHolderVar ID assigned */ + + Index lastRowMarkId; /* highest PlanRowMark ID assigned */ + + bool transientPlan; /* redo plan when TransactionXmin changes? */ + + bool dependsOnRole; /* is plan specific to current role? */ + + /* Added post-release, will be in a saner place in 9.3: */ + int nParamExec; /* number of PARAM_EXEC Params used */ + bool insideRecursion; /* For sql on hdfs, internal flag. */ + + bloomfilter_context bloomfilter; /* Bloom filter context. */ + bool vectorized; /* whether vector plan be generated, used in join planning phase */ + int minopmem; /* min work mem if query mem is used for planning */ + + int estiopmem; /* estimation of operator mem, used to revise u_sess->opt_cxt.op_work_mem */ + + Cost IOTotalCost; /* total cost */ + + List* hint_warning; /* hint warning list */ + + PlannerContext* plannerContext; + + /* There is a counter attempt to get name for sublinks */ + int sublink_counter; +} PlannerGlobal; + +/* macro for fetching the Plan associated with a SubPlan node */ +#define planner_subplan_get_plan(root, subplan) ((Plan*)list_nth((root)->glob->subplans, (subplan)->plan_id - 1)) + +/* we have to distinguish the different type of subquery */ +#define SUBQUERY_NORMAL 0x1 +#define SUBQUERY_PARAM 0x2 +#define SUBQUERY_RESULT 0x3 +#define SUBQUERY_TYPE_BITMAP 0x3 +#define SUBQUERY_SUBLINK 0x4 + +#define SUBQUERY_IS_NORMAL(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_NORMAL)) +#define SUBQUERY_IS_PARAM(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_PARAM)) +#define SUBQUERY_IS_RESULT(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_RESULT)) + +#define SUBQUERY_IS_SUBLINK(pr) (((pr->subquery_type & SUBQUERY_SUBLINK) == SUBQUERY_SUBLINK)) + +#define SUBQUERY_PREDPUSH(pr) ((SUBQUERY_IS_RESULT(pr)) || (SUBQUERY_IS_PARAM(pr))) + +/* ---------- + * PlannerInfo + * Per-query information for planning/optimization + * + * This struct is conventionally called "root" in all the planner routines. + * It holds links to all of the planner's working state, in addition to the + * original Query. Note that at present the planner extensively modifies + * the passed-in Query data structure; someday that should stop. + * ---------- + */ +typedef struct PlannerInfo { + NodeTag type; + + Query* parse; /* the Query being planned */ + + PlannerGlobal* glob; /* global info for current planner run */ + + Index query_level; /* 1 at the outermost Query */ + + struct PlannerInfo* parent_root; /* NULL at outermost Query */ + + /* + * simple_rel_array holds pointers to "base rels" and "other rels" (see + * comments for RelOptInfo for more info). It is indexed by rangetable + * index (so entry 0 is always wasted). Entries can be NULL when an RTE + * does not correspond to a base relation, such as a join RTE or an + * unreferenced view RTE; or if the RelOptInfo hasn't been made yet. + */ + struct RelOptInfo** simple_rel_array; /* All 1-rel RelOptInfos */ + int simple_rel_array_size; /* allocated size of array */ + + /* + * List of changed var that mutated during cost-based rewrite optimization, the + * element in the list is "struct RewriteVarMapping", for example: + * - inlist2join + * - pushjoin2union (will implemented) + * _ ... + * + */ + List* var_mappings; + Relids var_mapping_rels; /* all the relations that related to inlist2join */ + + /* + * simple_rte_array is the same length as simple_rel_array and holds + * pointers to the associated rangetable entries. This lets us avoid + * rt_fetch(), which can be a bit slow once large inheritance sets have + * been expanded. + */ + RangeTblEntry** simple_rte_array; /* rangetable as an array */ + + /* + * all_baserels is a Relids set of all base relids (but not "other" + * relids) in the query; that is, the Relids identifier of the final join + * we need to form. + */ + Relids all_baserels; + + /* + * join_rel_list is a list of all join-relation RelOptInfos we have + * considered in this planning run. For small problems we just scan the + * list to do lookups, but when there are many join relations we build a + * hash table for faster lookups. The hash table is present and valid + * when join_rel_hash is not NULL. Note that we still maintain the list + * even when using the hash table for lookups; this simplifies life for + * GEQO. + */ + List* join_rel_list; /* list of join-relation RelOptInfos */ + struct HTAB* join_rel_hash; /* optional hashtable for join relations */ + + /* + * When doing a dynamic-programming-style join search, join_rel_level[k] + * is a list of all join-relation RelOptInfos of level k, and + * join_cur_level is the current level. New join-relation RelOptInfos are + * automatically added to the join_rel_level[join_cur_level] list. + * join_rel_level is NULL if not in use. + */ + List** join_rel_level; /* lists of join-relation RelOptInfos */ + int join_cur_level; /* index of list being extended */ + + List* init_plans; /* init SubPlans for query */ + + List* cte_plan_ids; /* per-CTE-item list of subplan IDs */ + + List* eq_classes; /* list of active EquivalenceClasses */ + + List* canon_pathkeys; /* list of "canonical" PathKeys */ + + List* left_join_clauses; /* list of RestrictInfos for + * mergejoinable outer join clauses + * w/nonnullable var on left */ + + List* right_join_clauses; /* list of RestrictInfos for + * mergejoinable outer join clauses + * w/nonnullable var on right */ + + List* full_join_clauses; /* list of RestrictInfos for + * mergejoinable full join clauses */ + + List* join_info_list; /* list of SpecialJoinInfos */ + + List* lateral_info_list; /* list of LateralJoinInfos */ + + List* append_rel_list; /* list of AppendRelInfos */ + + List* rowMarks; /* list of PlanRowMarks */ + + List* placeholder_list; /* list of PlaceHolderInfos */ + + List* query_pathkeys; /* desired pathkeys for query_planner(), and + * actual pathkeys afterwards */ + + List* group_pathkeys; /* groupClause pathkeys, if any */ + List* window_pathkeys; /* pathkeys of bottom window, if any */ + List* distinct_pathkeys; /* distinctClause pathkeys, if any */ + List* sort_pathkeys; /* sortClause pathkeys, if any */ + + List* minmax_aggs; /* List of MinMaxAggInfos */ + + List* initial_rels; /* RelOptInfos we are now trying to join */ + + MemoryContext planner_cxt; /* context holding PlannerInfo */ + + double total_table_pages; /* # of pages in all tables of query */ + + double tuple_fraction; /* tuple_fraction passed to query_planner */ + double limit_tuples; /* limit_tuples passed to query_planner */ + + bool hasInheritedTarget; /* true if parse->resultRelation is an + * inheritance child rel */ + bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */ + bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */ + bool hasHavingQual; /* true if havingQual was non-null */ + bool hasPseudoConstantQuals; /* true if any RestrictInfo has + * pseudoconstant = true */ + bool hasRecursion; /* true if planning a recursive WITH item */ + + /* Note: qualSecurityLevel is zero if there are no securityQuals */ + Index qualSecurityLevel; /* minimum security_level for quals */ + +#ifdef PGXC + /* This field is used only when RemoteScan nodes are involved */ + int rs_alias_index; /* used to build the alias reference */ + + /* + * In Postgres-XC Coordinators are supposed to skip the handling of + * row marks of type ROW_MARK_EXCLUSIVE & ROW_MARK_SHARE. + * In order to do that we simply remove such type + * of row marks from the list rowMarks. Instead they are saved + * in xc_rowMarks list that is then handeled to add + * FOR UPDATE/SHARE in the remote query + */ + List* xc_rowMarks; /* list of PlanRowMarks of type ROW_MARK_EXCLUSIVE & ROW_MARK_SHARE */ +#endif + + /* These fields are used only when hasRecursion is true: */ + int wt_param_id; /* PARAM_EXEC ID for the work table */ + struct Plan* non_recursive_plan; /* plan for non-recursive term */ + + /* These fields are workspace for createplan.c */ + Relids curOuterRels; /* outer rels above current node */ + List* curOuterParams; /* not-yet-assigned NestLoopParams */ + + Index curIteratorParamIndex; + bool isPartIteratorPlanning; + int curItrs; + List* subqueryRestrictInfo; /* Subquery RestrictInfo, which only be used in wondows agg. */ + + /* optional private data for join_search_hook, e.g., GEQO */ + void* join_search_private; + + /* Added post-release, will be in a saner place in 9.3: */ + List* plan_params; /* list of PlannerParamItems, see below */ + + /* For count_distinct, save null info for group by clause */ + List* join_null_info; + /* for GroupingFunc fixup in setrefs */ + AttrNumber* grouping_map; + + /* If current query level is correlated with upper level */ + bool is_correlated; + + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + * The effective value must be greater than 0. + */ + Index dataDestRelIndex; + + /* interesting keys of current query level */ + ItstDisKey dis_keys; + + /* + * indicate if the subquery planning root (PlannerInfo) is under or rooted from + * recursive-cte planning. + */ + bool is_under_recursive_cte; + + /* + * indicate if the subquery planning root (PlannerInfo) is under recursive-cte's + * recursive branch + */ + bool is_under_recursive_tree; + bool has_recursive_correlated_rte; /* true if any RTE correlated with recursive cte */ + + int subquery_type; + Bitmapset *param_upper; + + bool hasRownumQual; +} PlannerInfo; + +/* + * In places where it's known that simple_rte_array[] must have been prepared + * already, we just index into it to fetch RTEs. In code that might be + * executed before or after entering query_planner(), use this macro. + */ +#define planner_rt_fetch(rti, root) \ + ((root)->simple_rte_array ? (root)->simple_rte_array[rti] : rt_fetch(rti, (root)->parse->rtable)) + +/* ---------- + * RelOptInfo + * Per-relation information for planning/optimization + * + * For planning purposes, a "base rel" is either a plain relation (a table) + * or the output of a sub-SELECT or function that appears in the range table. + * In either case it is uniquely identified by an RT index. A "joinrel" + * is the joining of two or more base rels. A joinrel is identified by + * the set of RT indexes for its component baserels. We create RelOptInfo + * nodes for each baserel and joinrel, and store them in the PlannerInfo's + * simple_rel_array and join_rel_list respectively. + * + * Note that there is only one joinrel for any given set of component + * baserels, no matter what order we assemble them in; so an unordered + * set is the right datatype to identify it with. + * + * We also have "other rels", which are like base rels in that they refer to + * single RT indexes; but they are not part of the join tree, and are given + * a different RelOptKind to identify them. Lastly, there is a RelOptKind + * for "dead" relations, which are base rels that we have proven we don't + * need to join after all. + * + * Currently the only kind of otherrels are those made for member relations + * of an "append relation", that is an inheritance set or UNION ALL subquery. + * An append relation has a parent RTE that is a base rel, which represents + * the entire append relation. The member RTEs are otherrels. The parent + * is present in the query join tree but the members are not. The member + * RTEs and otherrels are used to plan the scans of the individual tables or + * subqueries of the append set; then the parent baserel is given Append + * and/or MergeAppend paths comprising the best paths for the individual + * member rels. (See comments for AppendRelInfo for more information.) + * + * At one time we also made otherrels to represent join RTEs, for use in + * handling join alias Vars. Currently this is not needed because all join + * alias Vars are expanded to non-aliased form during preprocess_expression. + * + * Parts of this data structure are specific to various scan and join + * mechanisms. It didn't seem worth creating new node types for them. + * + * relids - Set of base-relation identifiers; it is a base relation + * if there is just one, a join relation if more than one + * rows - estimated number of tuples in the relation after restriction + * clauses have been applied (ie, output rows of a plan for it) + * width - avg. number of bytes per tuple in the relation after the + * appropriate projections have been done (ie, output width) + * reltargetlist - List of Var and PlaceHolderVar nodes for the values + * we need to output from this relation. + * List is in no particular order, but all rels of an + * appendrel set must use corresponding orders. + * NOTE: in a child relation, may contain RowExpr or + * ConvertRowtypeExpr representing a whole-row Var. + * pathlist - List of Path nodes, one for each potentially useful + * method of generating the relation + * ppilist - ParamPathInfo nodes for parameterized Paths, if any + * cheapest_startup_path - the pathlist member with lowest startup cost + * (regardless of its ordering; but must be + * unparameterized) + * cheapest_total_path - the pathlist member with lowest total cost + * (regardless of its ordering; but must be + * unparameterized) + * cheapest_unique_path - for caching cheapest path to produce unique + * (no duplicates) output from relation + * cheapest_parameterized_paths - paths with cheapest total costs for + * their parameterizations; always includes + * cheapest_total_path + * + * If the relation is a base relation it will have these fields set: + * + * relid - RTE index (this is redundant with the relids field, but + * is provided for convenience of access) + * rtekind - distinguishes plain relation, subquery, or function RTE + * min_attr, max_attr - range of valid AttrNumbers for rel + * attr_needed - array of bitmapsets indicating the highest joinrel + * in which each attribute is needed; if bit 0 is set then + * the attribute is needed as part of final targetlist + * attr_widths - cache space for per-attribute width estimates; + * zero means not computed yet + * indexlist - list of IndexOptInfo nodes for relation's indexes + * (always NIL if it's not a table) + * pages - number of disk pages in relation (zero if not a table) + * tuples - number of tuples in relation (not considering restrictions) + * allvisfrac - fraction of disk pages that are marked all-visible + * subplan - plan for subquery (NULL if it's not a subquery) + * subroot - PlannerInfo for subquery (NULL if it's not a subquery) + * fdwroutine - function hooks for FDW, if foreign table (else NULL) + * fdw_private - private state for FDW, if foreign table (else NULL) + * + * Note: for a subquery, tuples, subplan, subroot are not set immediately + * upon creation of the RelOptInfo object; they are filled in when + * set_subquery_pathlist processes the object. Likewise, fdwroutine + * and fdw_private are filled during initial path creation. + * + * For otherrels that are appendrel members, these fields are filled + * in just as for a baserel. + * + * The presence of the remaining fields depends on the restrictions + * and joins that the relation participates in: + * + * baserestrictinfo - List of RestrictInfo nodes, containing info about + * each non-join qualification clause in which this relation + * participates (only used for base rels) + * baserestrictcost - Estimated cost of evaluating the baserestrictinfo + * clauses at a single tuple (only used for base rels) + * baserestrict_min_security - Smallest security_level found among + * clauses in baserestrictinfo + * joininfo - List of RestrictInfo nodes, containing info about each + * join clause in which this relation participates (but + * note this excludes clauses that might be derivable from + * EquivalenceClasses) + * has_eclass_joins - flag that EquivalenceClass joins are possible + * + * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for + * base rels, because for a join rel the set of clauses that are treated as + * restrict clauses varies depending on which sub-relations we choose to join. + * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be + * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but + * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2} + * and should not be processed again at the level of {1 2 3}.) Therefore, + * the restrictinfo list in the join case appears in individual JoinPaths + * (field joinrestrictinfo), not in the parent relation. But it's OK for + * the RelOptInfo to store the joininfo list, because that is the same + * for a given rel no matter how we form it. + * + * We store baserestrictcost in the RelOptInfo (for base relations) because + * we know we will need it at least once (to price the sequential scan) + * and may need it multiple times to price index scans. + * ---------- + */ +typedef enum RelOptKind { RELOPT_BASEREL, RELOPT_JOINREL, RELOPT_OTHER_MEMBER_REL, RELOPT_DEADREL } RelOptKind; + +typedef enum PartitionFlag { PARTITION_NONE, PARTITION_REQURIED, PARTITION_ANCESOR } PartitionFlag; + +/* + * Is the given relation a simple relation i.e a base or "other" member + * relation? + */ +#define IS_SIMPLE_REL(rel) ((rel)->reloptkind == RELOPT_BASEREL || (rel)->reloptkind == RELOPT_OTHER_MEMBER_REL) + +/* Is the given relation a join relation? */ +#define IS_JOIN_REL(rel) ((rel)->reloptkind == RELOPT_JOINREL) + +typedef struct RelOptInfo { + NodeTag type; + + RelOptKind reloptkind; + + /* all relations included in this RelOptInfo */ + Relids relids; /* set of base relids (rangetable indexes) */ + + bool isPartitionedTable; /* is it a partitioned table? it is meaningless unless + it is a 'baserel' (reloptkind = RELOPT_BASEREL) */ + PartitionFlag partflag; + + /* size estimates generated by planner */ + double rows; /* estimated number of global result tuples */ + int width; /* estimated avg width of result tuples */ + int encodedwidth; /* estimated avg width of encoded columns in result tuples */ + AttrNumber encodednum; /* number of encoded column */ + + /* materialization information */ + List* reltargetlist; /* Vars to be output by scan of relation */ + List* distribute_keys; /* distribute key */ + List* pathlist; /* Path structures */ + List* ppilist; /* ParamPathInfos used in pathlist */ + struct Path* cheapest_startup_path; + List* cheapest_total_path; /* contain all cheapest total paths from different distribute key */ + struct Path* cheapest_unique_path; + List* cheapest_parameterized_paths; + + /* information about a base rel (not set for join rels!) */ + Index relid; + Oid reltablespace; /* containing tablespace */ + RTEKind rtekind; /* RELATION, SUBQUERY, or FUNCTION */ + AttrNumber min_attr; /* smallest attrno of rel (often <0) */ + AttrNumber max_attr; /* largest attrno of rel */ + Relids* attr_needed; /* array indexed [min_attr .. max_attr] */ + int32* attr_widths; /* array indexed [min_attr .. max_attr] */ + List* lateral_vars; /* LATERAL Vars and PHVs referenced by rel */ + Relids lateral_relids; /* minimum parameterization of rel */ + List* indexlist; /* list of IndexOptInfo */ + RelPageType pages; /* local size estimates derived from pg_class */ + double tuples; /* global size estimates derived from pg_class */ + double multiple; /* how many dn skewed and biased be influenced by distinct. */ + double allvisfrac; + + struct PruningResult* pruning_result; /* pruning result for partitioned table with + baserestrictinfo,it is meaningless unless it + is a 'baserel' (reloptkind = RELOPT_BASEREL) */ + int partItrs; /* the number of the partitions in pruning_result */ + struct PruningResult* pruning_result_for_index_usable; + int partItrs_for_index_usable; /* the number of the partitions in pruning_result_for_seqscan */ + struct PruningResult* pruning_result_for_index_unusable; + int partItrs_for_index_unusable; /* the number of the partitions in pruning_result_for_seqscan */ + /* information about a partitioned table */ + BucketInfo *bucketInfo; + + /* use "struct Plan" to avoid including plannodes.h here */ + struct Plan* subplan; /* if subquery */ + PlannerInfo* subroot; /* if subquery */ + List *subplan_params; /* if subquery */ + /* use "struct FdwRoutine" to avoid including fdwapi.h here */ + struct FdwRoutine* fdwroutine; /* if foreign table */ + void* fdw_private; /* if foreign table */ + + /* used by various scans and joins: */ + List* baserestrictinfo; /* RestrictInfo structures (if base + * rel) */ + QualCost baserestrictcost; /* cost of evaluating the above */ + Index baserestrict_min_security; /* min security_level found in + * baserestrictinfo */ + List* joininfo; /* RestrictInfo structures for join clauses + * involving this rel */ + bool has_eclass_joins; /* T means joininfo is incomplete */ + RelOrientation orientation; /* the store type of base rel */ + RelstoreType relStoreLocation; /* the relation store location. */ + char locator_type; /* the location type of base rel */ + Oid rangelistOid; /* oid of list/range distributed table, InvalidOid if not list/range table */ + List* subplanrestrictinfo; /* table filter with correlated column involved */ + ItstDisKey rel_dis_keys; /* interesting key info for current relation */ + List* varratio; /* rel tuples ratio after join to different relation */ + List* varEqRatio; + + /* + * The alternative rel for cost-based query rewrite + * + * Note: Only base rel have valid pointer of this fields, set to NULL for alternative rel + */ + List* alternatives; + + /* + * Rel opinter to base rel that in plannerinfo->simple_rel_array[x]. + * + * Note: Only alternative rels has valid pointer of this field, set to NULL for the + * origin rel. + */ + RelOptInfo* base_rel; + + unsigned int num_data_nodes = 0; //number of distributing data nodes +} RelOptInfo; + +/* + * IndexOptInfo + * Per-index information for planning/optimization + * + * indexkeys[], indexcollations[], opfamily[], and opcintype[] + * each have ncolumns entries. + * + * sortopfamily[], reverse_sort[], and nulls_first[] likewise have + * ncolumns entries, if the index is ordered; but if it is unordered, + * those pointers are NULL. + * + * Zeroes in the indexkeys[] array indicate index columns that are + * expressions; there is one element in indexprs for each such column. + * + * For an ordered index, reverse_sort[] and nulls_first[] describe the + * sort ordering of a forward indexscan; we can also consider a backward + * indexscan, which will generate the reverse ordering. + * + * The indexprs and indpred expressions have been run through + * prepqual.c and eval_const_expressions() for ease of matching to + * WHERE clauses. indpred is in implicit-AND form. + * + * indextlist is a TargetEntry list representing the index columns. + * It provides an equivalent base-relation Var for each simple column, + * and links to the matching indexprs element for each expression column. + */ +typedef struct IndexOptInfo { + NodeTag type; + + Oid indexoid; /* OID of the index relation */ + bool ispartitionedindex; /* it is an partitioned index */ + Oid partitionindex; /* the partition index oid for current partition */ + Oid reltablespace; /* tablespace of index (not table) */ + RelOptInfo* rel; /* back-link to index's table */ + + /* statistics from pg_class */ + RelPageType pages; /* number of disk pages in index */ + double tuples; /* number of global index tuples in index */ + + /* index descriptor information */ + int ncolumns; /* number of columns in index */ + int nkeycolumns; /* number of key columns in index */ + int* indexkeys; /* column numbers of index's keys, or 0 */ + Oid* indexcollations; /* OIDs of collations of index columns */ + Oid* opfamily; /* OIDs of operator families for columns */ + Oid* opcintype; /* OIDs of opclass declared input data types */ + Oid* sortopfamily; /* OIDs of btree opfamilies, if orderable */ + bool* reverse_sort; /* is sort order descending? */ + bool* nulls_first; /* do NULLs come first in the sort order? */ + Oid relam; /* OID of the access method (in pg_am) */ + + RegProcedure amcostestimate; /* OID of the access method's cost fcn */ + + List* indexprs; /* expressions for non-simple index columns */ + List* indpred; /* predicate if a partial index, else NIL */ + + List* indextlist; /* targetlist representing index columns */ + + bool isGlobal; /* true if index is global partition index */ + bool predOK; /* true if predicate matches query */ + bool unique; /* true if a unique index */ + bool immediate; /* is uniqueness enforced immediately? */ + bool hypothetical; /* true if index doesn't really exist */ + bool canreturn; /* can index return IndexTuples? */ + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amhasgettuple; /* does AM have amgettuple interface? */ + bool amhasgetbitmap; /* does AM have amgetbitmap interface? */ +} IndexOptInfo; + +/* + * EquivalenceClasses + * + * Whenever we can determine that a mergejoinable equality clause A = B is + * not delayed by any outer join, we create an EquivalenceClass containing + * the expressions A and B to record this knowledge. If we later find another + * equivalence B = C, we add C to the existing EquivalenceClass; this may + * require merging two existing EquivalenceClasses. At the end of the qual + * distribution process, we have sets of values that are known all transitively + * equal to each other, where "equal" is according to the rules of the btree + * operator family(s) shown in ec_opfamilies, as well as the collation shown + * by ec_collation. (We restrict an EC to contain only equalities whose + * operators belong to the same set of opfamilies. This could probably be + * relaxed, but for now it's not worth the trouble, since nearly all equality + * operators belong to only one btree opclass anyway. Similarly, we suppose + * that all or none of the input datatypes are collatable, so that a single + * collation value is sufficient.) + * + * We also use EquivalenceClasses as the base structure for PathKeys, letting + * us represent knowledge about different sort orderings being equivalent. + * Since every PathKey must reference an EquivalenceClass, we will end up + * with single-member EquivalenceClasses whenever a sort key expression has + * not been equivalenced to anything else. It is also possible that such an + * EquivalenceClass will contain a volatile expression ("ORDER BY random()"), + * which is a case that can't arise otherwise since clauses containing + * volatile functions are never considered mergejoinable. We mark such + * EquivalenceClasses specially to prevent them from being merged with + * ordinary EquivalenceClasses. Also, for volatile expressions we have + * to be careful to match the EquivalenceClass to the correct targetlist + * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a. + * So we record the SortGroupRef of the originating sort clause. + * + * We allow equality clauses appearing below the nullable side of an outer join + * to form EquivalenceClasses, but these have a slightly different meaning: + * the included values might be all NULL rather than all the same non-null + * values. See src/backend/optimizer/README for more on that point. + * + * NB: if ec_merged isn't NULL, this class has been merged into another, and + * should be ignored in favor of using the pointed-to class. + */ +typedef struct EquivalenceClass { + NodeTag type; + + List* ec_opfamilies; /* btree operator family OIDs */ + Oid ec_collation; /* collation, if datatypes are collatable */ + List* ec_members; /* list of EquivalenceMembers */ + List* ec_sources; /* list of generating RestrictInfos */ + List* ec_derives; /* list of derived RestrictInfos */ + Relids ec_relids; /* all relids appearing in ec_members */ + bool ec_has_const; /* any pseudoconstants in ec_members? */ + bool ec_has_volatile; /* the (sole) member is a volatile expr */ + bool ec_below_outer_join; /* equivalence applies below an OJ */ + bool ec_group_set; /* if take part in group */ + bool ec_broken; /* failed to generate needed clauses? */ + Index ec_sortref; /* originating sortclause label, or 0 */ + Index ec_min_security; /* minimum security_level in ec_sources */ + Index ec_max_security; /* maximum security_level in ec_sources */ + struct EquivalenceClass* ec_merged; /* set if merged into another EC */ +} EquivalenceClass; + +/* + * If an EC contains a const and isn't below-outer-join, any PathKey depending + * on it must be redundant, since there's only one possible value of the key. + */ +#define EC_MUST_BE_REDUNDANT(eclass) ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join) + +#define IS_EC_FUNC(rte) \ + (rte->rtekind == RTE_FUNCTION && (((FuncExpr*)rte->funcexpr)->funcid == ECEXTENSIONFUNCOID || \ + ((FuncExpr*)rte->funcexpr)->funcid == ECHADOOPFUNCOID)) + +/* + * EquivalenceMember - one member expression of an EquivalenceClass + * + * em_is_child signifies that this element was built by transposing a member + * for an appendrel parent relation to represent the corresponding expression + * for an appendrel child. These members are used for determining the + * pathkeys of scans on the child relation and for explicitly sorting the + * child when necessary to build a MergeAppend path for the whole appendrel + * tree. An em_is_child member has no impact on the properties of the EC as a + * whole; in particular the EC's ec_relids field does NOT include the child + * relation. An em_is_child member should never be marked em_is_const nor + * cause ec_has_const or ec_has_volatile to be set, either. Thus, em_is_child + * members are not really full-fledged members of the EC, but just reflections + * or doppelgangers of real members. Most operations on EquivalenceClasses + * should ignore em_is_child members, and those that don't should test + * em_relids to make sure they only consider relevant members. + * + * em_datatype is usually the same as exprType(em_expr), but can be + * different when dealing with a binary-compatible opfamily; in particular + * anyarray_ops would never work without this. Use em_datatype when + * looking up a specific btree operator to work with this expression. + */ +typedef struct EquivalenceMember { + NodeTag type; + + Expr* em_expr; /* the expression represented */ + Relids em_relids; /* all relids appearing in em_expr */ + Relids em_nullable_relids; /* nullable by lower outer joins */ + bool em_is_const; /* expression is pseudoconstant? */ + bool em_is_child; /* derived version for a child relation? */ + Oid em_datatype; /* the "nominal type" used by the opfamily */ +} EquivalenceMember; + +/* + * PathKeys + * + * The sort ordering of a path is represented by a list of PathKey nodes. + * An empty list implies no known ordering. Otherwise the first item + * represents the primary sort key, the second the first secondary sort key, + * etc. The value being sorted is represented by linking to an + * EquivalenceClass containing that value and including pk_opfamily among its + * ec_opfamilies. The EquivalenceClass tells which collation to use, too. + * This is a convenient method because it makes it trivial to detect + * equivalent and closely-related orderings. (See optimizer/README for more + * information.) + * + * Note: pk_strategy is either BTLessStrategyNumber (for ASC) or + * BTGreaterStrategyNumber (for DESC). We assume that all ordering-capable + * index types will use btree-compatible strategy numbers. + */ +typedef struct PathKey { + NodeTag type; + + EquivalenceClass* pk_eclass; /* the value that is ordered */ + Oid pk_opfamily; /* btree opfamily defining the ordering */ + int pk_strategy; /* sort direction (ASC or DESC) */ + bool pk_nulls_first; /* do NULLs come before normal values? */ +} PathKey; + +/* + * ParamPathInfo + * + * All parameterized paths for a given relation with given required outer rels + * link to a single ParamPathInfo, which stores common information such as + * the estimated rowcount for this parameterization. We do this partly to + * avoid recalculations, but mostly to ensure that the estimated rowcount + * is in fact the same for every such path. + * + * Note: ppi_clauses is only used in ParamPathInfos for base relation paths; + * in join cases it's NIL because the set of relevant clauses varies depending + * on how the join is formed. The relevant clauses will appear in each + * parameterized join path's joinrestrictinfo list, instead. + */ +typedef struct ParamPathInfo { + NodeTag type; + + Relids ppi_req_outer; /* rels supplying parameters used by path */ + double ppi_rows; /* estimated global number of result tuples */ + List* ppi_clauses; /* join clauses available from outer rels */ + Bitmapset* ppi_req_upper; /* param IDs*/ +} ParamPathInfo; + +/* + * Type "Path" is used as-is for sequential-scan paths, as well as some other + * simple plan types that we don't need any extra information in the path for. + * For other path types it is the first component of a larger struct. + * + * "pathtype" is the NodeTag of the Plan node we could build from this Path. + * It is partially redundant with the Path's NodeTag, but allows us to use + * the same Path type for multiple Plan types when there is no need to + * distinguish the Plan type during path processing. + * + * "param_info", if not NULL, links to a ParamPathInfo that identifies outer + * relation(s) that provide parameter values to each scan of this path. + * That means this path can only be joined to those rels by means of nestloop + * joins with this path on the inside. Also note that a parameterized path + * is responsible for testing all "movable" joinclauses involving this rel + * and the specified outer rel(s). + * + * "rows" is the same as parent->rows in simple paths, but in parameterized + * paths and UniquePaths it can be less than parent->rows, reflecting the + * fact that we've filtered by extra join conditions or removed duplicates. + * + * "pathkeys" is a List of PathKey nodes (see above), describing the sort + * ordering of the path's output rows. + */ +typedef struct Path { + NodeTag type; + + NodeTag pathtype; /* tag identifying scan/join method */ + + RelOptInfo* parent; /* the relation this path can build */ + ParamPathInfo* param_info; /* parameterization info, or NULL if none */ + + /* estimated size/costs for path (see costsize.c for more info) */ + double rows; /* estimated number of global result tuples */ + double multiple; + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + Cost stream_cost; /* cost of actions invoked by stream but can't be parallelled in this path */ + + List* pathkeys; /* sort ordering of path's output */ + List* distribute_keys; /* distribute key, Var list */ + char locator_type; + Oid rangelistOid; + int dop; /* degree of parallelism */ + /* pathkeys is a List of PathKey nodes; see above */ + Distribution distribution; + int hint_value; /* Mark this path if be hinted, and hint kind. */ + double innerdistinct; /* join inner rel distinct estimation value */ + double outerdistinct; /* join outer rel distinct estimation value */ +} Path; + +/* Macro for extracting a path's parameterization relids; beware double eval */ +#define PATH_REQ_OUTER(path) ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids)NULL) +#define PATH_REQ_UPPER(path) ((path)->param_info ? (path)->param_info->ppi_req_upper : (Relids)NULL) + +/* ---------- + * IndexPath represents an index scan over a single index. + * + * This struct is used for both regular indexscans and index-only scans; + * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant. + * + * 'indexinfo' is the index to be scanned. + * + * 'indexclauses' is a list of index qualification clauses, with implicit + * AND semantics across the list. Each clause is a RestrictInfo node from + * the query's WHERE or JOIN conditions. An empty list implies a full + * index scan. + * + * 'indexquals' has the same structure as 'indexclauses', but it contains + * the actual index qual conditions that can be used with the index. + * In simple cases this is identical to 'indexclauses', but when special + * indexable operators appear in 'indexclauses', they are replaced by the + * derived indexscannable conditions in 'indexquals'. + * + * 'indexqualcols' is an integer list of index column numbers (zero-based) + * of the same length as 'indexquals', showing which index column each qual + * is meant to be used with. 'indexquals' is required to be ordered by + * index column, so 'indexqualcols' must form a nondecreasing sequence. + * (The order of multiple quals for the same index column is unspecified.) + * + * 'indexorderbys', if not NIL, is a list of ORDER BY expressions that have + * been found to be usable as ordering operators for an amcanorderbyop index. + * The list must match the path's pathkeys, ie, one expression per pathkey + * in the same order. These are not RestrictInfos, just bare expressions, + * since they generally won't yield booleans. Also, unlike the case for + * quals, it's guaranteed that each expression has the index key on the left + * side of the operator. + * + * 'indexorderbycols' is an integer list of index column numbers (zero-based) + * of the same length as 'indexorderbys', showing which index column each + * ORDER BY expression is meant to be used with. (There is no restriction + * on which index column each ORDER BY can be used with.) + * + * 'indexscandir' is one of: + * ForwardScanDirection: forward scan of an ordered index + * BackwardScanDirection: backward scan of an ordered index + * NoMovementScanDirection: scan of an unordered index, or don't care + * (The executor doesn't care whether it gets ForwardScanDirection or + * NoMovementScanDirection for an indexscan, but the planner wants to + * distinguish ordered from unordered indexes for building pathkeys.) + * + * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that + * we need not recompute them when considering using the same index in a + * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath + * itself represent the costs of an IndexScan or IndexOnlyScan plan type. + * ---------- + */ +typedef struct IndexPath { + Path path; + IndexOptInfo* indexinfo; + List* indexclauses; + List* indexquals; + List* indexqualcols; + List* indexorderbys; + List* indexorderbycols; + ScanDirection indexscandir; + Cost indextotalcost; + Selectivity indexselectivity; +} IndexPath; + +typedef struct PartIteratorPath { + Path path; + PartitionType partType; + Path* subPath; + int itrs; + ScanDirection direction; + bool ispwj; + /* the upper boundary list for the partitions in pruning_result, it is meanless unless it is a partitionwise join */ + List* upperboundary; + /* the lower boundary list for the partitions in pruning_result, it is meanless unless it is a partitionwise join */ + List* lowerboundary; +} PartIteratorPath; + +/* + * BitmapHeapPath represents one or more indexscans that generate TID bitmaps + * instead of directly accessing the heap, followed by AND/OR combinations + * to produce a single bitmap, followed by a heap scan that uses the bitmap. + * Note that the output is always considered unordered, since it will come + * out in physical heap order no matter what the underlying indexes did. + * + * The individual indexscans are represented by IndexPath nodes, and any + * logic on top of them is represented by a tree of BitmapAndPath and + * BitmapOrPath nodes. Notice that we can use the same IndexPath node both + * to represent a regular (or index-only) index scan plan, and as the child + * of a BitmapHeapPath that represents scanning the same index using a + * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath + * always represent the costs to use it as a regular (or index-only) + * IndexScan. The costs of a BitmapIndexScan can be computed using the + * IndexPath's indextotalcost and indexselectivity. + */ +typedef struct BitmapHeapPath { + Path path; + Path* bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */ +} BitmapHeapPath; + +/* + * BitmapAndPath represents a BitmapAnd plan node; it can only appear as + * part of the substructure of a BitmapHeapPath. The Path structure is + * a bit more heavyweight than we really need for this, but for simplicity + * we make it a derivative of Path anyway. + */ +typedef struct BitmapAndPath { + Path path; + List* bitmapquals; /* IndexPaths and BitmapOrPaths */ + Selectivity bitmapselectivity; +} BitmapAndPath; + +/* + * BitmapOrPath represents a BitmapOr plan node; it can only appear as + * part of the substructure of a BitmapHeapPath. The Path structure is + * a bit more heavyweight than we really need for this, but for simplicity + * we make it a derivative of Path anyway. + */ +typedef struct BitmapOrPath { + Path path; + List* bitmapquals; /* IndexPaths and BitmapAndPaths */ + Selectivity bitmapselectivity; +} BitmapOrPath; + +/* + * TidPath represents a scan by TID + * + * tidquals is an implicitly OR'ed list of qual expressions of the form + * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)". + * Note they are bare expressions, not RestrictInfos. + */ +typedef struct TidPath { + Path path; + List* tidquals; /* qual(s) involving CTID = something */ +} TidPath; + +/* + * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM + * + * Note that the subpath comes from a different planning domain; for example + * RTE indexes within it mean something different from those known to the + * SubqueryScanPath. path.parent->subroot is the planning context needed to + * interpret the subpath. + * NOTE: GaussDB keep an subplan other than the sub-path + */ +typedef struct SubqueryScanPath +{ + Path path; + List *subplan_params; + PlannerInfo *subroot; + struct Plan *subplan; /* path representing subquery execution */ +} SubqueryScanPath; + +/* + * ForeignPath represents a potential scan of a foreign table + * + * fdw_private stores FDW private data about the scan. While fdw_private is + * not actually touched by the core code during normal operations, it's + * generally a good idea to use a representation that can be dumped by + * nodeToString(), so that you can examine the structure during debugging + * with tools like pprint(). + */ +typedef struct ForeignPath { + Path path; + Path* fdw_outerpath; + List* fdw_private; +} ForeignPath; + +/* + * ExtensiblePath represents a table scan done by some out-of-core extension. + * + * We provide a set of hooks here - which the provider must take care to set + * up correctly - to allow extensions to supply their own methods of scanning + * a relation. For example, a provider might provide GPU acceleration, a + * cache-based scan, or some other kind of logic we haven't dreamed up yet. + * + * ExtensiblePaths can be injected into the planning process for a relation by + * set_rel_pathlist_hook functions. + * + * Core code must avoid assuming that the ExtensiblePath is only as large as + * the structure declared here; providers are allowed to make it the first + * element in a larger structure. (Since the planner never copies Paths, + * this doesn't add any complication.) However, for consistency with the + * FDW case, we provide a "extensible_private" field in ExtensiblePath; providers + * may prefer to use that rather than define another struct type. + */ +struct ExtensiblePath; + +typedef struct ExtensiblePathMethods { + const char* ExtensibleName; + + /* Convert Path to a Plan */ + struct Plan* (*PlanExtensiblePath)(PlannerInfo* root, RelOptInfo* rel, struct ExtensiblePath* best_path, + List* tlist, List* clauses, List* extensible_plans); +} ExtensiblePathMethods; + +typedef struct ExtensiblePath { + Path path; + uint32 flags; /* mask of EXTENSIBLEPATH_* flags */ + List* extensible_paths; /* list of child Path nodes, if any */ + List* extensible_private; + const struct ExtensiblePathMethods* methods; +} ExtensiblePath; +/* + * AppendPath represents an Append plan, ie, successive execution of + * several member plans. + * + * Note: it is possible for "subpaths" to contain only one, or even no, + * elements. These cases are optimized during create_append_plan. + * In particular, an AppendPath with no subpaths is a "dummy" path that + * is created to represent the case that a relation is provably empty. + */ +typedef struct AppendPath { + Path path; + List* subpaths; /* list of component Paths */ +} AppendPath; + +#define IS_DUMMY_PATH(p) (IsA((p), AppendPath) && ((AppendPath*)(p))->subpaths == NIL) + +/* A relation that's been proven empty will have one path that is dummy */ +#define IS_DUMMY_REL(r) ((r)->cheapest_total_path != NIL && IS_DUMMY_PATH(linitial((r)->cheapest_total_path))) + +/* + * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted + * results from several member plans to produce similarly-sorted output. + */ +typedef struct MergeAppendPath { + Path path; + List* subpaths; /* list of component Paths */ + double limit_tuples; /* hard limit on output tuples, or -1 */ + OpMemInfo* mem_info; +} MergeAppendPath; + +/* + * ResultPath represents use of a Result plan node to compute a variable-free + * targetlist with no underlying tables (a "SELECT expressions" query). + * The query could have a WHERE clause, too, represented by "quals". + * + * Note that quals is a list of bare clauses, not RestrictInfos. + */ +typedef struct ResultPath { + Path path; + List* quals; + Path* subpath; + List* pathqual; + bool ispulledupqual; // qual is pulled up from lower path +} ResultPath; + +/* + * MaterialPath represents use of a Material plan node, i.e., caching of + * the output of its subpath. This is used when the subpath is expensive + * and needs to be scanned repeatedly, or when we need mark/restore ability + * and the subpath doesn't have it. + */ +typedef struct MaterialPath { + Path path; + Path* subpath; + bool materialize_all; /* true for materialize above streamed subplan */ + OpMemInfo mem_info; /* Memory info for materialize */ +} MaterialPath; + +/* + * UniquePath represents elimination of distinct rows from the output of + * its subpath. + * + * This is unlike the other Path nodes in that it can actually generate + * different plans: either hash-based or sort-based implementation, or a + * no-op if the input path can be proven distinct already. The decision + * is sufficiently localized that it's not worth having separate Path node + * types. (Note: in the no-op case, we could eliminate the UniquePath node + * entirely and just return the subpath; but it's convenient to have a + * UniquePath in the path tree to signal upper-level routines that the input + * is known distinct.) + */ +typedef enum { + UNIQUE_PATH_NOOP, /* input is known unique already */ + UNIQUE_PATH_HASH, /* use hashing */ + UNIQUE_PATH_SORT /* use sorting */ +} UniquePathMethod; + +typedef struct UniquePath { + Path path; + Path* subpath; + UniquePathMethod umethod; + List* in_operators; /* equality operators of the IN clause */ + List* uniq_exprs; /* expressions to be made unique */ + bool both_method; + bool hold_tlist; + OpMemInfo mem_info; /* Memory info for hashagg or sort */ +} UniquePath; + +/* + * All join-type paths share these fields. + */ +typedef struct JoinPath { + Path path; + + JoinType jointype; + + Path* outerjoinpath; /* path for the outer side of the join */ + Path* innerjoinpath; /* path for the inner side of the join */ + + List* joinrestrictinfo; /* RestrictInfos to apply to join */ + + /* + * See the notes for RelOptInfo and ParamPathInfo to understand why + * joinrestrictinfo is needed in JoinPath, and can't be merged into the + * parent RelOptInfo. + */ + int skewoptimize; +} JoinPath; + +/* + * A nested-loop path needs no special fields. + */ +typedef JoinPath NestPath; + +/* + * A mergejoin path has these fields. + * + * Unlike other path types, a MergePath node doesn't represent just a single + * run-time plan node: it can represent up to four. Aside from the MergeJoin + * node itself, there can be a Sort node for the outer input, a Sort node + * for the inner input, and/or a Material node for the inner input. We could + * represent these nodes by separate path nodes, but considering how many + * different merge paths are investigated during a complex join problem, + * it seems better to avoid unnecessary palloc overhead. + * + * path_mergeclauses lists the clauses (in the form of RestrictInfos) + * that will be used in the merge. + * + * Note that the mergeclauses are a subset of the parent relation's + * restriction-clause list. Any join clauses that are not mergejoinable + * appear only in the parent's restrict list, and must be checked by a + * qpqual at execution time. + * + * outersortkeys (resp. innersortkeys) is NIL if the outer path + * (resp. inner path) is already ordered appropriately for the + * mergejoin. If it is not NIL then it is a PathKeys list describing + * the ordering that must be created by an explicit Sort node. + * + * materialize_inner is TRUE if a Material node should be placed atop the + * inner input. This may appear with or without an inner Sort step. + */ +typedef struct MergePath { + JoinPath jpath; + List* path_mergeclauses; /* join clauses to be used for merge */ + List* outersortkeys; /* keys for explicit sort, if any */ + List* innersortkeys; /* keys for explicit sort, if any */ + bool materialize_inner; /* add Materialize to inner? */ + OpMemInfo outer_mem_info; /* Mem info for outer explicit sort */ + OpMemInfo inner_mem_info; /* Mem info for inner explicit sort */ + OpMemInfo mat_mem_info; /* Mem info for materialization of inner */ +} MergePath; + +/* + * A hashjoin path has these fields. + * + * The remarks above for mergeclauses apply for hashclauses as well. + * + * Hashjoin does not care what order its inputs appear in, so we have + * no need for sortkeys. + */ +typedef struct HashPath { + JoinPath jpath; + List* path_hashclauses; /* join clauses used for hashing */ + int num_batches; /* number of batches expected */ + OpMemInfo mem_info; /* Mem info for hash table */ +} HashPath; + +#ifdef PGXC +/* + * A remotequery path represents the queries to be sent to the datanode/s + * + * When RemoteQuery plan is created from RemoteQueryPath, we build the query to + * be executed at the datanode. For building such a query, it's important to get + * the RHS relation and LHS relation of the JOIN clause. So, instead of storing + * the outer and inner paths, we find out the RHS and LHS paths and store those + * here. + */ +typedef struct RemoteQueryPath { + Path path; + ExecNodes* rqpath_en; /* List of datanodes to execute the query on */ + /* + * If the path represents a JOIN rel, leftpath and rightpath represent the + * RemoteQuery paths for left (outer) and right (inner) side of the JOIN + * resp. jointype and join_restrictlist pertains to such JOINs. + */ + struct RemoteQueryPath* leftpath; + struct RemoteQueryPath* rightpath; + JoinType jointype; + List* join_restrictlist; /* restrict list corresponding to JOINs, + * only considered if rest of + * the JOIN information is + * available + */ + bool rqhas_unshippable_qual; /* TRUE if there is at least + * one qual which can not be + * shipped to the datanodes + */ + bool rqhas_temp_rel; /* TRUE if one of the base relations + * involved in this path is a temporary + * table. + */ + bool rqhas_unshippable_tlist; /* TRUE if there is at least one + * targetlist entry which is + * not completely shippable. + */ +} RemoteQueryPath; +#endif /* PGXC */ + +/* + * Cached bucket selectivity for hashjoin. + * + * Since bucket selectivity is limited by hashjoin bucket size, so we should only use the cache + * when bucket size is the same. + */ +typedef struct BucketSelectivity { + double nbuckets; + Selectivity bucket_size; + double ndistinct; +} BucketSelectivity; + +/* + * Cached bucket selectivity for one side of restrictinfo. + * + * Since bucket selectivity differs among different data georgraphy, so we should cache three + * stream cases for one side of restrictinfo: non-stream, broadcast, redistribute. + */ +typedef struct BucketSize { + BucketSelectivity normal; + BucketSelectivity broadcast; + BucketSelectivity redistribute; +} BucketSize; + +/* + * Restriction clause info. + * + * We create one of these for each AND sub-clause of a restriction condition + * (WHERE or JOIN/ON clause). Since the restriction clauses are logically + * ANDed, we can use any one of them or any subset of them to filter out + * tuples, without having to evaluate the rest. The RestrictInfo node itself + * stores data used by the optimizer while choosing the best query plan. + * + * If a restriction clause references a single base relation, it will appear + * in the baserestrictinfo list of the RelOptInfo for that base rel. + * + * If a restriction clause references more than one base rel, it will + * appear in the joininfo list of every RelOptInfo that describes a strict + * subset of the base rels mentioned in the clause. The joininfo lists are + * used to drive join tree building by selecting plausible join candidates. + * The clause cannot actually be applied until we have built a join rel + * containing all the base rels it references, however. + * + * When we construct a join rel that includes all the base rels referenced + * in a multi-relation restriction clause, we place that clause into the + * joinrestrictinfo lists of paths for the join rel, if neither left nor + * right sub-path includes all base rels referenced in the clause. The clause + * will be applied at that join level, and will not propagate any further up + * the join tree. (Note: the "predicate migration" code was once intended to + * push restriction clauses up and down the plan tree based on evaluation + * costs, but it's dead code and is unlikely to be resurrected in the + * foreseeable future.) + * + * Note that in the presence of more than two rels, a multi-rel restriction + * might reach different heights in the join tree depending on the join + * sequence we use. So, these clauses cannot be associated directly with + * the join RelOptInfo, but must be kept track of on a per-join-path basis. + * + * RestrictInfos that represent equivalence conditions (i.e., mergejoinable + * equalities that are not outerjoin-delayed) are handled a bit differently. + * Initially we attach them to the EquivalenceClasses that are derived from + * them. When we construct a scan or join path, we look through all the + * EquivalenceClasses and generate derived RestrictInfos representing the + * minimal set of conditions that need to be checked for this particular scan + * or join to enforce that all members of each EquivalenceClass are in fact + * equal in all rows emitted by the scan or join. + * + * When dealing with outer joins we have to be very careful about pushing qual + * clauses up and down the tree. An outer join's own JOIN/ON conditions must + * be evaluated exactly at that join node, unless they are "degenerate" + * conditions that reference only Vars from the nullable side of the join. + * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed + * down below the outer join, if they reference any nullable Vars. + * RestrictInfo nodes contain a flag to indicate whether a qual has been + * pushed down to a lower level than its original syntactic placement in the + * join tree would suggest. If an outer join prevents us from pushing a qual + * down to its "natural" semantic level (the level associated with just the + * base rels used in the qual) then we mark the qual with a "required_relids" + * value including more than just the base rels it actually uses. By + * pretending that the qual references all the rels required to form the outer + * join, we prevent it from being evaluated below the outer join's joinrel. + * When we do form the outer join's joinrel, we still need to distinguish + * those quals that are actually in that join's JOIN/ON condition from those + * that appeared elsewhere in the tree and were pushed down to the join rel + * because they used no other rels. That's what the is_pushed_down flag is + * for; it tells us that a qual is not an OUTER JOIN qual for the set of base + * rels listed in required_relids. A clause that originally came from WHERE + * or an INNER JOIN condition will *always* have its is_pushed_down flag set. + * It's possible for an OUTER JOIN clause to be marked is_pushed_down too, + * if we decide that it can be pushed down into the nullable side of the join. + * In that case it acts as a plain filter qual for wherever it gets evaluated. + * (In short, is_pushed_down is only false for non-degenerate outer join + * conditions. Possibly we should rename it to reflect that meaning?) + * + * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true + * if the clause's applicability must be delayed due to any outer joins + * appearing below it (ie, it has to be postponed to some join level higher + * than the set of relations it actually references). + * + * There is also an outer_relids field, which is NULL except for outer join + * clauses; for those, it is the set of relids on the outer side of the + * clause's outer join. (These are rels that the clause cannot be applied to + * in parameterized scans, since pushing it into the join's outer side would + * lead to wrong answers.) + * + * There is also a nullable_relids field, which is the set of rels the clause + * references that can be forced null by some outer join below the clause. + * + * outerjoin_delayed = true is subtly different from nullable_relids != NULL: + * a clause might reference some nullable rels and yet not be + * outerjoin_delayed because it also references all the other rels of the + * outer join(s). A clause that is not outerjoin_delayed can be enforced + * anywhere it is computable. + * + * To handle security-barrier conditions efficiently, we mark RestrictInfo + * nodes with a security_level field, in which higher values identify clauses + * coming from less-trusted sources. The exact semantics are that a clause + * cannot be evaluated before another clause with a lower security_level value + * unless the first clause is leakproof. As with outer-join clauses, this + * creates a reason for clauses to sometimes need to be evaluated higher in + * the join tree than their contents would suggest; and even at a single plan + * node, this rule constrains the order of application of clauses. + * + * In general, the referenced clause might be arbitrarily complex. The + * kinds of clauses we can handle as indexscan quals, mergejoin clauses, + * or hashjoin clauses are limited (e.g., no volatile functions). The code + * for each kind of path is responsible for identifying the restrict clauses + * it can use and ignoring the rest. Clauses not implemented by an indexscan, + * mergejoin, or hashjoin will be placed in the plan qual or joinqual field + * of the finished Plan node, where they will be enforced by general-purpose + * qual-expression-evaluation code. (But we are still entitled to count + * their selectivity when estimating the result tuple count, if we + * can guess what it is...) + * + * When the referenced clause is an OR clause, we generate a modified copy + * in which additional RestrictInfo nodes are inserted below the top-level + * OR/AND structure. This is a convenience for OR indexscan processing: + * indexquals taken from either the top level or an OR subclause will have + * associated RestrictInfo nodes. + * + * The can_join flag is set true if the clause looks potentially useful as + * a merge or hash join clause, that is if it is a binary opclause with + * nonoverlapping sets of relids referenced in the left and right sides. + * (Whether the operator is actually merge or hash joinable isn't checked, + * however.) + * + * The pseudoconstant flag is set true if the clause contains no Vars of + * the current query level and no volatile functions. Such a clause can be + * pulled out and used as a one-time qual in a gating Result node. We keep + * pseudoconstant clauses in the same lists as other RestrictInfos so that + * the regular clause-pushing machinery can assign them to the correct join + * level, but they need to be treated specially for cost and selectivity + * estimates. Note that a pseudoconstant clause can never be an indexqual + * or merge or hash join clause, so it's of no interest to large parts of + * the planner. + * + * When join clauses are generated from EquivalenceClasses, there may be + * several equally valid ways to enforce join equivalence, of which we need + * apply only one. We mark clauses of this kind by setting parent_ec to + * point to the generating EquivalenceClass. Multiple clauses with the same + * parent_ec in the same join are redundant. + */ +typedef struct RestrictInfo { + NodeTag type; + + Expr* clause; /* the represented clause of WHERE or JOIN */ + + bool is_pushed_down; /* TRUE if clause was pushed down in level */ + + bool outerjoin_delayed; /* TRUE if delayed by lower outer join */ + + bool can_join; /* see comment above */ + + bool pseudoconstant; /* see comment above */ + + bool leakproof; /* TRUE if known to contain no leaked Vars */ + + Index security_level; /* Mark RestrictInfo nodes with a security_level */ + + /* The set of relids (varnos) actually referenced in the clause: */ + Relids clause_relids; + + /* The set of relids required to evaluate the clause: */ + Relids required_relids; + + /* If an outer-join clause, the outer-side relations, else NULL: */ + Relids outer_relids; + + /* The relids used in the clause that are nullable by lower outer joins: */ + Relids nullable_relids; + + /* These fields are set for any binary opclause: */ + Relids left_relids; /* relids in left side of clause */ + Relids right_relids; /* relids in right side of clause */ + + /* This field is NULL unless clause is an OR clause: */ + Expr* orclause; /* modified clause with RestrictInfos */ + + /* This field is NULL unless clause is potentially redundant: */ + EquivalenceClass* parent_ec; /* generating EquivalenceClass */ + + /* cache space for cost and selectivity */ + QualCost eval_cost; /* eval cost of clause; -1 if not yet set */ + Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER) + * semantics; -1 if not yet set; >1 means a + * redundant clause */ + Selectivity outer_selec; /* selectivity for outer join semantics; -1 if + * not yet set */ + + /* valid if clause is mergejoinable, else NIL */ + List* mergeopfamilies; /* opfamilies containing clause operator */ + + /* cache space for mergeclause processing; NULL if not yet set */ + EquivalenceClass* left_ec; /* EquivalenceClass containing lefthand */ + EquivalenceClass* right_ec; /* EquivalenceClass containing righthand */ + EquivalenceMember* left_em; /* EquivalenceMember for lefthand */ + EquivalenceMember* right_em; /* EquivalenceMember for righthand */ + List* scansel_cache; /* list of MergeScanSelCache structs */ + + /* transient workspace for use while considering a specific join path */ + bool outer_is_left; /* T = outer var on left, F = on right */ + + /* valid if clause is hashjoinable, else InvalidOid: */ + Oid hashjoinoperator; /* copy of clause operator */ + + /* cache space for hashclause processing; -1 if not yet set */ + BucketSize left_bucketsize; /* avg bucketsize of left side */ + BucketSize right_bucketsize; /* avg bucketsize of right side */ +} RestrictInfo; + +/* + * Since mergejoinscansel() is a relatively expensive function, and would + * otherwise be invoked many times while planning a large join tree, + * we go out of our way to cache its results. Each mergejoinable + * RestrictInfo carries a list of the specific sort orderings that have + * been considered for use with it, and the resulting selectivities. + */ +typedef struct MergeScanSelCache { + /* Ordering details (cache lookup key) */ + Oid opfamily; /* btree opfamily defining the ordering */ + Oid collation; /* collation for the ordering */ + int strategy; /* sort direction (ASC or DESC) */ + bool nulls_first; /* do NULLs come before normal values? */ + /* Results */ + Selectivity leftstartsel; /* first-join fraction for clause left side */ + Selectivity leftendsel; /* last-join fraction for clause left side */ + Selectivity rightstartsel; /* first-join fraction for clause right side */ + Selectivity rightendsel; /* last-join fraction for clause right side */ +} MergeScanSelCache; + +/* + * Placeholder node for an expression to be evaluated below the top level + * of a plan tree. This is used during planning to represent the contained + * expression. At the end of the planning process it is replaced by either + * the contained expression or a Var referring to a lower-level evaluation of + * the contained expression. Typically the evaluation occurs below an outer + * join, and Var references above the outer join might thereby yield NULL + * instead of the expression value. + * + * Although the planner treats this as an expression node type, it is not + * recognized by the parser or executor, so we declare it here rather than + * in primnodes.h. + */ +typedef struct PlaceHolderVar { + Expr xpr; + Expr* phexpr; /* the represented expression */ + Relids phrels; /* base relids syntactically within expr src */ + Index phid; /* ID for PHV (unique within planner run) */ + Index phlevelsup; /* > 0 if PHV belongs to outer query */ +} PlaceHolderVar; + +/* + * "Special join" info. + * + * One-sided outer joins constrain the order of joining partially but not + * completely. We flatten such joins into the planner's top-level list of + * relations to join, but record information about each outer join in a + * SpecialJoinInfo struct. These structs are kept in the PlannerInfo node's + * join_info_list. + * + * Similarly, semijoins and antijoins created by flattening IN (subselect) + * and EXISTS(subselect) clauses create partial constraints on join order. + * These are likewise recorded in SpecialJoinInfo structs. + * + * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility + * of planning for them, because this simplifies make_join_rel()'s API. + * + * min_lefthand and min_righthand are the sets of base relids that must be + * available on each side when performing the special join. lhs_strict is + * true if the special join's condition cannot succeed when the LHS variables + * are all NULL (this means that an outer join can commute with upper-level + * outer joins even if it appears in their RHS). We don't bother to set + * lhs_strict for FULL JOINs, however. + * + * It is not valid for either min_lefthand or min_righthand to be empty sets; + * if they were, this would break the logic that enforces join order. + * + * syn_lefthand and syn_righthand are the sets of base relids that are + * syntactically below this special join. (These are needed to help compute + * min_lefthand and min_righthand for higher joins.) + * + * delay_upper_joins is set TRUE if we detect a pushed-down clause that has + * to be evaluated after this join is formed (because it references the RHS). + * Any outer joins that have such a clause and this join in their RHS cannot + * commute with this join, because that would leave noplace to check the + * pushed-down clause. (We don't track this for FULL JOINs, either.) + * + * join_quals is an implicit-AND list of the quals syntactically associated + * with the join (they may or may not end up being applied at the join level). + * This is just a side list and does not drive actual application of quals. + * For JOIN_SEMI joins, this is cleared to NIL in create_unique_path() if + * the join is found not to be suitable for a uniqueify-the-RHS plan. + * + * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching + * the inputs to make it a LEFT JOIN. So the allowed values of jointype + * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI. + * + * For purposes of join selectivity estimation, we create transient + * SpecialJoinInfo structures for regular inner joins; so it is possible + * to have jointype == JOIN_INNER in such a structure, even though this is + * not allowed within join_info_list. We also create transient + * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for + * cost estimation purposes it is sometimes useful to know the join size under + * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and + * join_quals are not set meaningfully within such structs. + */ +typedef struct SpecialJoinInfo { + NodeTag type; + Relids min_lefthand; /* base relids in minimum LHS for join */ + Relids min_righthand; /* base relids in minimum RHS for join */ + Relids syn_lefthand; /* base relids syntactically within LHS */ + Relids syn_righthand; /* base relids syntactically within RHS */ + JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */ + bool lhs_strict; /* joinclause is strict for some LHS rel */ + bool delay_upper_joins; /* can't commute with upper RHS */ + List* join_quals; /* join quals, in implicit-AND list format */ + bool varratio_cached; /* decide chach selec or not. */ +} SpecialJoinInfo; + +/* + * "Lateral join" info. + * + * Lateral references in subqueries constrain the join order in a way that's + * somewhat like outer joins, though different in detail. We construct one or + * more LateralJoinInfos for each RTE with lateral references, and add them to + * the PlannerInfo node's lateral_info_list. + * + * lateral_rhs is the relid of a baserel with lateral references, and + * lateral_lhs is a set of relids of baserels it references, all of which + * must be present on the LHS to compute a parameter needed by the RHS. + * Typically, lateral_lhs is a singleton, but it can include multiple rels + * if the RHS references a PlaceHolderVar with a multi-rel ph_eval_at level. + * We disallow joining to only part of the LHS in such cases, since that would + * result in a join tree with no convenient place to compute the PHV. + * + * When an appendrel contains lateral references (eg "LATERAL (SELECT x.col1 + * UNION ALL SELECT y.col2)"), the LateralJoinInfos reference the parent + * baserel not the member otherrels, since it is the parent relid that is + * considered for joining purposes. + */ +typedef struct LateralJoinInfo +{ + NodeTag type; + Index lateral_rhs; /* a baserel containing lateral refs */ + Relids lateral_lhs; /* some base relids it references */ +} LateralJoinInfo; + + +/* + * Append-relation info. + * + * When we expand an inheritable table or a UNION-ALL subselect into an + * "append relation" (essentially, a list of child RTEs), we build an + * AppendRelInfo for each child RTE. The list of AppendRelInfos indicates + * which child RTEs must be included when expanding the parent, and each + * node carries information needed to translate Vars referencing the parent + * into Vars referencing that child. + * + * These structs are kept in the PlannerInfo node's append_rel_list. + * Note that we just throw all the structs into one list, and scan the + * whole list when desiring to expand any one parent. We could have used + * a more complex data structure (eg, one list per parent), but this would + * be harder to update during operations such as pulling up subqueries, + * and not really any easier to scan. Considering that typical queries + * will not have many different append parents, it doesn't seem worthwhile + * to complicate things. + * + * Note: after completion of the planner prep phase, any given RTE is an + * append parent having entries in append_rel_list if and only if its + * "inh" flag is set. We clear "inh" for plain tables that turn out not + * to have inheritance children, and (in an abuse of the original meaning + * of the flag) we set "inh" for subquery RTEs that turn out to be + * flattenable UNION ALL queries. This lets us avoid useless searches + * of append_rel_list. + * + * Note: the data structure assumes that append-rel members are single + * baserels. This is OK for inheritance, but it prevents us from pulling + * up a UNION ALL member subquery if it contains a join. While that could + * be fixed with a more complex data structure, at present there's not much + * point because no improvement in the plan could result. + */ +typedef struct AppendRelInfo { + NodeTag type; + + /* + * These fields uniquely identify this append relationship. There can be + * (in fact, always should be) multiple AppendRelInfos for the same + * parent_relid, but never more than one per child_relid, since a given + * RTE cannot be a child of more than one append parent. + */ + Index parent_relid; /* RT index of append parent rel */ + Index child_relid; /* RT index of append child rel */ + + /* + * For an inheritance appendrel, the parent and child are both regular + * relations, and we store their rowtype OIDs here for use in translating + * whole-row Vars. For a UNION-ALL appendrel, the parent and child are + * both subqueries with no named rowtype, and we store InvalidOid here. + */ + Oid parent_reltype; /* OID of parent's composite type */ + Oid child_reltype; /* OID of child's composite type */ + + /* + * The N'th element of this list is a Var or expression representing the + * child column corresponding to the N'th column of the parent. This is + * used to translate Vars referencing the parent rel into references to + * the child. A list element is NULL if it corresponds to a dropped + * column of the parent (this is only possible for inheritance cases, not + * UNION ALL). The list elements are always simple Vars for inheritance + * cases, but can be arbitrary expressions in UNION ALL cases. + * + * Notice we only store entries for user columns (attno > 0). Whole-row + * Vars are special-cased, and system columns (attno < 0) need no special + * translation since their attnos are the same for all tables. + * + * Caution: the Vars have varlevelsup = 0. Be careful to adjust as needed + * when copying into a subquery. + */ + List* translated_vars; /* Expressions in the child's Vars */ + + /* + * We store the parent table's OID here for inheritance, or InvalidOid for + * UNION ALL. This is only needed to help in generating error messages if + * an attempt is made to reference a dropped parent column. + */ + Oid parent_reloid; /* OID of parent relation */ +} AppendRelInfo; + +/* + * For each distinct placeholder expression generated during planning, we + * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list. + * This stores info that is needed centrally rather than in each copy of the + * PlaceHolderVar. The phid fields identify which PlaceHolderInfo goes with + * each PlaceHolderVar. Note that phid is unique throughout a planner run, + * not just within a query level --- this is so that we need not reassign ID's + * when pulling a subquery into its parent. + * + * The idea is to evaluate the expression at (only) the ph_eval_at join level, + * then allow it to bubble up like a Var until the ph_needed join level. + * ph_needed has the same definition as attr_needed for a regular Var. + * + * ph_may_need is an initial estimate of ph_needed, formed using the + * syntactic locations of references to the PHV. We need this in order to + * determine whether the PHV reference forces a join ordering constraint: + * if the PHV has to be evaluated below the nullable side of an outer join, + * and then used above that outer join, we must constrain join order to ensure + * there's a valid place to evaluate the PHV below the join. The final + * actual ph_needed level might be lower than ph_may_need, but we can't + * determine that until later on. Fortunately this doesn't matter for what + * we need ph_may_need for: if there's a PHV reference syntactically + * above the outer join, it's not going to be allowed to drop below the outer + * join, so we would come to the same conclusions about join order even if + * we had the final ph_needed value to compare to. + * + * We create a PlaceHolderInfo only after determining that the PlaceHolderVar + * is actually referenced in the plan tree, so that unreferenced placeholders + * don't result in unnecessary constraints on join order. + */ +typedef struct PlaceHolderInfo { + NodeTag type; + + Index phid; /* ID for PH (unique within planner run) */ + PlaceHolderVar* ph_var; /* copy of PlaceHolderVar tree */ + Relids ph_eval_at; /* lowest level we can evaluate value at */ + Relids ph_needed; /* highest level the value is needed at */ + int32 ph_width; /* estimated attribute width */ +} PlaceHolderInfo; + +/* + * For each potentially index-optimizable MIN/MAX aggregate function, + * root->minmax_aggs stores a MinMaxAggInfo describing it. + */ +typedef struct MinMaxAggInfo { + NodeTag type; + + Oid aggfnoid; /* pg_proc Oid of the aggregate */ + Oid aggsortop; /* Oid of its sort operator */ + Expr* target; /* expression we are aggregating on */ + PlannerInfo* subroot; /* modified "root" for planning the subquery */ + Path* path; /* access path for subquery */ + Cost pathcost; /* estimated cost to fetch first row */ + Param* param; /* param for subplan's output */ + Aggref* aggref; /* used for construct the final agg in distributed env */ +} MinMaxAggInfo; + +/* + * At runtime, PARAM_EXEC slots are used to pass values around from one plan + * node to another. They can be used to pass values down into subqueries (for + * outer references in subqueries), or up out of subqueries (for the results + * of a subplan), or from a NestLoop plan node into its inner relation (when + * the inner scan is parameterized with values from the outer relation). + * The planner is responsible for assigning nonconflicting PARAM_EXEC IDs to + * the PARAM_EXEC Params it generates. + * + * Outer references are managed via root->plan_params, which is a list of + * PlannerParamItems. While planning a subquery, each parent query level's + * plan_params contains the values required from it by the current subquery. + * During create_plan(), we use plan_params to track values that must be + * passed from outer to inner sides of NestLoop plan nodes. + * + * The item a PlannerParamItem represents can be one of three kinds: + * + * A Var: the slot represents a variable of this level that must be passed + * down because subqueries have outer references to it, or must be passed + * from a NestLoop node to its inner scan. The varlevelsup value in the Var + * will always be zero. + * + * A PlaceHolderVar: this works much like the Var case, except that the + * entry is a PlaceHolderVar node with a contained expression. The PHV + * will have phlevelsup = 0, and the contained expression is adjusted + * to match in level. + * + * An Aggref (with an expression tree representing its argument): the slot + * represents an aggregate expression that is an outer reference for some + * subquery. The Aggref itself has agglevelsup = 0, and its argument tree + * is adjusted to match in level. + * + * Note: we detect duplicate Var and PlaceHolderVar parameters and coalesce + * them into one slot, but we do not bother to do that for Aggrefs. + * The scope of duplicate-elimination only extends across the set of + * parameters passed from one query level into a single subquery, or for + * nestloop parameters across the set of nestloop parameters used in a single + * query level. So there is no possibility of a PARAM_EXEC slot being used + * for conflicting purposes. + * + * In addition, PARAM_EXEC slots are assigned for Params representing outputs + * from subplans (values that are setParam items for those subplans). These + * IDs need not be tracked via PlannerParamItems, since we do not need any + * duplicate-elimination nor later processing of the represented expressions. + * Instead, we just record the assignment of the slot number by incrementing + * root->glob->nParamExec. + */ +typedef struct PlannerParamItem { + NodeTag type; + + Node* item; /* the Var, PlaceHolderVar, or Aggref */ + int paramId; /* its assigned PARAM_EXEC slot number */ +} PlannerParamItem; + +/* + * When making cost estimates for a SEMI or ANTI join, there are some + * correction factors that are needed in both nestloop and hash joins + * to account for the fact that the executor can stop scanning inner rows + * as soon as it finds a match to the current outer row. These numbers + * depend only on the selected outer and inner join relations, not on the + * particular paths used for them, so it's worthwhile to calculate them + * just once per relation pair not once per considered path. This struct + * is filled by compute_semi_anti_join_factors and must be passed along + * to the join cost estimation functions. + * + * outer_match_frac is the fraction of the outer tuples that are + * expected to have at least one match. + * match_count is the average number of matches expected for + * outer tuples that have at least one match. + * + * Note: For right-semi/anti join, match_count is the fraction of the inner tuples + * that are expected to have at least one match in outer tuples. + */ +typedef struct SemiAntiJoinFactors { + Selectivity outer_match_frac; + Selectivity match_count; +} SemiAntiJoinFactors; + +/* + * For speed reasons, cost estimation for join paths is performed in two + * phases: the first phase tries to quickly derive a lower bound for the + * join cost, and then we check if that's sufficient to reject the path. + * If not, we come back for a more refined cost estimate. The first phase + * fills a JoinCostWorkspace struct with its preliminary cost estimates + * and possibly additional intermediate values. The second phase takes + * these values as inputs to avoid repeating work. + * + * (Ideally we'd declare this in cost.h, but it's also needed in pathnode.h, + * so seems best to put it here.) + */ +typedef struct JoinCostWorkspace { + /* Preliminary cost estimates --- must not be larger than final ones! */ + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + + /* Fields below here should be treated as private to costsize.c */ + Cost run_cost; /* non-startup cost components */ + + /* private for cost_nestloop code */ + Cost inner_rescan_run_cost; + double outer_matched_rows; + Selectivity inner_scan_frac; + + /* private for cost_mergejoin code */ + Cost inner_run_cost; + double outer_rows; + double inner_rows; + double outer_skip_rows; + double inner_skip_rows; + + /* private for cost_hashjoin code */ + int numbuckets; + int numbatches; + + /* Meminfo for joins */ + OpMemInfo outer_mem_info; + OpMemInfo inner_mem_info; +} JoinCostWorkspace; + +#endif /* RELATION_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/replnodes.h postgresql-hll-2.14/include/include/nodes/replnodes.h --- postgresql-hll-2.14_old/include/include/nodes/replnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/replnodes.h 2020-12-12 17:06:43.234347871 +0800 @@ -0,0 +1,114 @@ +/* ------------------------------------------------------------------------- + * + * replnodes.h + * definitions for replication grammar parse nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/replnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REPLNODES_H +#define REPLNODES_H + +#include "access/xlogdefs.h" +#include "nodes/pg_list.h" + +typedef enum ReplicationKind { REPLICATION_KIND_PHYSICAL, REPLICATION_KIND_LOGICAL } ReplicationKind; + +/* ---------------------- + * IDENTIFY_SYSTEM command + * ---------------------- + */ +typedef struct IdentifySystemCmd { + NodeTag type; +} IdentifySystemCmd; + +typedef struct IdentifyVersionCmd { + NodeTag type; +} IdentifyVersionCmd; + +typedef struct IdentifyModeCmd { + NodeTag type; +} IdentifyModeCmd; + +typedef struct IdentifyMaxLsnCmd { + NodeTag type; +} IdentifyMaxLsnCmd; + +typedef struct IdentifyConsistenceCmd { + NodeTag type; + XLogRecPtr recordptr; +} IdentifyConsistenceCmd; + +typedef struct IdentifyChannelCmd { + NodeTag type; + int channel_identifier; +} IdentifyChannelCmd; + +typedef struct IdentifyAZCmd { + NodeTag type; +} IdentifyAZCmd; + +/* ---------------------- + * BASE_BACKUP command + * ---------------------- + */ +typedef struct BaseBackupCmd { + NodeTag type; + List* options; +} BaseBackupCmd; + +/* ---------------------- + * CREATE_REPLICATION_SLOT command + * ---------------------- + */ +typedef struct CreateReplicationSlotCmd { + NodeTag type; + char* slotname; + ReplicationKind kind; + XLogRecPtr init_slot_lsn; + char* plugin; +} CreateReplicationSlotCmd; + +/* ---------------------- + * DROP_REPLICATION_SLOT command + * ---------------------- + */ +typedef struct DropReplicationSlotCmd { + NodeTag type; + char* slotname; +} DropReplicationSlotCmd; + +/* ---------------------- + * START_REPLICATION command + * ---------------------- + */ +typedef struct StartReplicationCmd { + NodeTag type; + ReplicationKind kind; + char* slotname; + XLogRecPtr startpoint; + List* options; +} StartReplicationCmd; + +/* ---------------------- + * START_REPLICATION(DATA) command + * ---------------------- + */ +typedef struct StartDataReplicationCmd { + NodeTag type; +} StartDataReplicationCmd; + +/* ---------------------- + * FETCH_MOT_CHECKPOINT command + * ---------------------- + */ +typedef struct FetchMotCheckpointCmd { + NodeTag type; +} FetchMotCheckpointCmd; + +#endif /* REPLNODES_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/tidbitmap.h postgresql-hll-2.14/include/include/nodes/tidbitmap.h --- postgresql-hll-2.14_old/include/include/nodes/tidbitmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/tidbitmap.h 2020-12-12 17:06:43.234347871 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * tidbitmap.h + * PostgreSQL tuple-id (TID) bitmap package + * + * This module provides bitmap data structures that are spiritually + * similar to Bitmapsets, but are specially adapted to store sets of + * tuple identifiers (TIDs), or ItemPointers. In particular, the division + * of an ItemPointer into BlockNumber and OffsetNumber is catered for. + * Also, since we wish to be able to store very large tuple sets in + * memory with this data structure, we support "lossy" storage, in which + * we no longer remember individual tuple offsets on a page but only the + * fact that a particular page needs to be visited. + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/tidbitmap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TIDBITMAP_H +#define TIDBITMAP_H + +#include "storage/itemptr.h" + +/* + * Actual bitmap representation is private to tidbitmap.c. Callers can + * do IsA(x, TIDBitmap) on it, but nothing else. + */ +typedef struct TIDBitmap TIDBitmap; + +/* Likewise, TBMIterator is private */ +typedef struct TBMIterator TBMIterator; + +/* Result structure for tbm_iterate */ +typedef struct { + BlockNumber blockno; /* page number containing tuples */ + Oid partitionOid; + int ntuples; /* -1 indicates lossy result */ + bool recheck; /* should the tuples be rechecked? */ + /* Note: recheck is always true if ntuples < 0 */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} TBMIterateResult; + +/* function prototypes in nodes/tidbitmap.c */ +extern TIDBitmap* tbm_create(long maxbytes); +extern void tbm_free(TIDBitmap* tbm); + +extern void tbm_add_tuples( + TIDBitmap* tbm, const ItemPointer tids, int ntids, bool recheck, Oid partitionOid = InvalidOid); +extern void tbm_add_page(TIDBitmap* tbm, BlockNumber pageno, Oid partitionOid = InvalidOid); + +extern void tbm_union(TIDBitmap* a, const TIDBitmap* b); +extern void tbm_intersect(TIDBitmap* a, const TIDBitmap* b); + +extern bool tbm_is_empty(const TIDBitmap* tbm); + +extern TBMIterator* tbm_begin_iterate(TIDBitmap* tbm); +extern TBMIterateResult* tbm_iterate(TBMIterator* iterator); +extern void tbm_end_iterate(TBMIterator* iterator); +extern bool tbm_is_global(const TIDBitmap* tbm); +extern void tbm_set_global(TIDBitmap* tbm, bool isGlobal); +#endif /* TIDBITMAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/nodes/value.h postgresql-hll-2.14/include/include/nodes/value.h --- postgresql-hll-2.14_old/include/include/nodes/value.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/nodes/value.h 2020-12-12 17:06:43.234347871 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * value.h + * interface for Value nodes + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/value.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef VALUE_H +#define VALUE_H +#include "nodes/primnodes.h" +#include "nodes/nodes.h" + +/* ---------------------- + * Value node + * + * The same Value struct is used for five node types: T_Integer, + * T_Float, T_String, T_BitString, T_Null. + * + * Integral values are actually represented by a machine integer, + * but both floats and strings are represented as strings. + * Using T_Float as the node type simply indicates that + * the contents of the string look like a valid numeric literal. + * + * (Before Postgres 7.0, we used a double to represent T_Float, + * but that creates loss-of-precision problems when the value is + * ultimately destined to be converted to NUMERIC. Since Value nodes + * are only used in the parsing process, not for runtime data, it's + * better to use the more general representation.) + * + * Note that an integer-looking string will get lexed as T_Float if + * the value is too large to fit in a 'long'. + * + * Nulls, of course, don't need the value part at all. + * ---------------------- + */ +typedef struct Value { + NodeTag type; /* tag appropriately (eg. T_String) */ + union ValUnion { + long ival; /* machine integer */ + char* str; /* string */ + } val; +} Value; + +#define intVal(v) (((Value*)(v))->val.ival) +#define floatVal(v) atof(((Value*)(v))->val.str) +#define strVal(v) (((Value*)(v))->val.str) + +extern Value* makeInteger(long i); +extern Value* makeFloat(char* numericStr); +extern Value* makeString(char* str); +extern Value* makeBitString(char* str); + +#endif /* VALUE_H */ diff -uprN postgresql-hll-2.14_old/include/include/opfusion/opfusion.h postgresql-hll-2.14/include/include/opfusion/opfusion.h --- postgresql-hll-2.14_old/include/include/opfusion/opfusion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/opfusion/opfusion.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,403 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion.h + * Operator Fusion's definition for bypass. + * + * IDENTIFICATION + * src/include/opfusion/opfusion.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_H_ +#include "auditfuncs.h" +#include "commands/prepare.h" +#include "opfusion/opfusion_util.h" +#include "opfusion/opfusion_scan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +extern void report_qps_type(CmdType commandType); +extern const char* getBypassReason(FusionType result); +extern void BypassUnsupportedReason(FusionType result); +extern void ExecCheckXactReadOnly(PlannedStmt* plannedstmt); +void InitParamInFusionConstruct(const TupleDesc tupDesc, Datum** values, bool** isNull); +extern FusionType getSelectFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getInsertFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getUpdateFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getDeleteFusionType(List* stmt_list, ParamListInfo params); +extern void tpslot_free_heaptuple(TupleTableSlot* reslot); + +typedef struct pnFusionObj { + char portalname[NAMEDATALEN]; + OpFusion *opfusion; +} pnFusionObj; + +#define HASH_TBL_LEN 64 + +class OpFusion : public BaseObject { +public: + OpFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list); + + virtual ~OpFusion(){}; + + static void* FusionFactory( + FusionType type, MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + static FusionType getFusionType(CachedPlan* cplan, ParamListInfo params, List* plantree_list); + + static void setCurrentOpFusionObj(OpFusion* obj); + + static bool process(int op, StringInfo msg, char* completionTag, bool isTopLevel); + + void CopyFormats(int16* formats, int numRFormats); + + void updatePreAllocParamter(StringInfo msg); + + void useOuterParameter(ParamListInfo params); + + void decribe(StringInfo msg); + + virtual bool execute(long max_rows, char* completionTag) + { + Assert(false); + return false; + } + + virtual void close() + { + Assert(false); + return; + } + + void setPreparedDestReceiver(DestReceiver* preparedDest); + + Datum CalFuncNodeVal(Oid functionId, List* args, bool* is_null, Datum* values, bool* isNulls); + + Datum EvalSimpleArg(Node* arg, bool* is_null, Datum* values, bool* isNulls); + + static void tearDown(OpFusion* opfusion); + + static void clearForCplan(OpFusion* opfusion, CachedPlanSource* psrc); + + void checkPermission(); + + void setReceiver(); + + void initParams(ParamListInfo params); + + void executeInit(); + + void executeEnd(const char* portal_name); + + void auditRecord(); + + static bool isQueryCompleted(); + + void bindClearPosition(); + + static void initFusionHtab(); + + void storeFusion(const char *portalname); + + static OpFusion *locateFusion(const char *portalname); + + static void removeFusionFromHtab(const char *portalname); + + static void refreshCurFusion(StringInfo msg); + +public: + struct ParamLoc { + int paramId; + int scanKeyIndx; + }; + + CachedPlanSource* m_psrc; /* to get m_cacheplan in PBE */ + + CachedPlan* m_cacheplan; + + PlannedStmt* m_planstmt; /* m_cacheplan->stmt_list in PBE, plantree in non-PBE */ + + bool m_isFirst; /* be true if is the fisrt execute in PBE */ + + MemoryContext m_context; + + MemoryContext m_tmpContext; /* use for tmp memory allocation. */ + + ParamListInfo m_params; + + ParamListInfo m_outParams; /* use outer side parameter. */ + + int m_paramNum; + + ParamLoc* m_paramLoc; /* location of m_params, include paramId and the location in indexqual */ + + Oid m_reloid; /* relation oid of range table */ + + TupleDesc m_tupDesc; /* tuple descriptor */ + + TupleTableSlot* m_reslot; /* result slot */ + + int16* m_attrno; /* target attribute number, length is m_tupDesc->natts */ + + Datum* m_values; + + bool* m_isnull; + + Datum* m_tmpvals; /* for mapping m_values */ + + bool* m_tmpisnull; /* for mapping m_isnull */ + + DestReceiver* m_receiver; + + bool m_isInsideRec; + + bool m_is_pbe_query; + + int16* m_rformats; + + bool m_isCompleted; + + long m_position; + + const char *m_portalName; + + Snapshot m_snapshot; + +private: +#ifdef ENABLE_MOT + static FusionType GetMotFusionType(PlannedStmt* plannedStmt); +#endif +}; + +class SelectFusion : public OpFusion { +public: + SelectFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SelectFusion(){}; + + bool execute(long max_rows, char* completionTag); + + void close(); + +private: + class ScanFusion* m_scan; + + int64 m_limitCount; + + int64 m_limitOffset; +}; + +class InsertFusion : public OpFusion { +public: + InsertFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~InsertFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + void refreshParameterIfNecessary(); + + EState* m_estate; + + /* for func/op expr calculation */ + FuncExprInfo* m_targetFuncNodes; + + int m_targetFuncNum; + + int m_targetParamNum; + + Datum* m_curVarValue; + + bool* m_curVarIsnull; + + bool m_is_bucket_rel; +}; + +class UpdateFusion : public OpFusion { +public: + UpdateFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~UpdateFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + class ScanFusion* m_scan; + + HeapTuple heapModifyTuple(HeapTuple tuple); + + void refreshTargetParameterIfNecessary(); + + EState* m_estate; + + /* targetlist */ + int m_targetNum; + + int m_targetParamNum; + + Datum* m_targetValues; + + bool* m_targetIsnull; + + Datum* m_curVarValue; + struct VarLoc { + int varNo; + int scanKeyIndx; + }; + + VarLoc* m_targetVarLoc; + + int m_varNum; + + bool* m_curVarIsnull; + + int* m_targetConstLoc; + + ParamLoc* m_targetParamLoc; + + /* for func/op expr calculation */ + FuncExprInfo* m_targetFuncNodes; + + int m_targetFuncNum; + + bool m_is_bucket_rel; +}; + +class DeleteFusion : public OpFusion { +public: + DeleteFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~DeleteFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + class ScanFusion* m_scan; + + EState* m_estate; + + bool m_is_bucket_rel; +}; + +#ifdef ENABLE_MOT +class MotJitSelectFusion : public OpFusion { +public: + MotJitSelectFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params); + + ~MotJitSelectFusion() {}; + + bool execute(long max_rows, char *completionTag); +}; + +class MotJitModifyFusion : public OpFusion { +public: + MotJitModifyFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params); + + ~MotJitModifyFusion() {}; + + bool execute(long max_rows, char *completionTag); + +private: + EState* m_estate; + CmdType m_cmdType; +}; +#endif + +class SelectForUpdateFusion : public OpFusion { +public: + SelectForUpdateFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SelectForUpdateFusion(){}; + + bool execute(long max_rows, char* completionTag); + + void close(); + +private: + class ScanFusion* m_scan; + + int64 m_limitCount; + + EState* m_estate; + + int64 m_limitOffset; + + bool m_is_bucket_rel; +}; + +class AggFusion : public OpFusion { + +public: + AggFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~AggFusion(){}; + + bool execute(long max_rows, char* completionTag); + +protected: + + typedef void (AggFusion::*aggSumFun)(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + /* agg sum function */ + void agg_int2_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_int4_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_int8_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_numeric_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + inline void init_var_from_num(Numeric num, NumericVar *dest) + { + Assert(!NUMERIC_IS_BI(num)); + dest->ndigits = NUMERIC_NDIGITS(num); + dest->weight = NUMERIC_WEIGHT(num); + dest->sign = NUMERIC_SIGN(num); + dest->dscale = NUMERIC_DSCALE(num); + dest->digits = NUMERIC_DIGITS(num); + dest->buf = NULL; /* digits array is not palloc'd */ + } + + class ScanFusion* m_scan; + + aggSumFun m_aggSumFunc; +}; + +class SortFusion: public OpFusion { + +public: + + SortFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SortFusion(){}; + + bool execute(long max_rows, char *completionTag); + +protected: + + class ScanFusion* m_scan; + + TupleDesc m_scanDesc; +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/opfusion/opfusion_scan.h postgresql-hll-2.14/include/include/opfusion/opfusion_scan.h --- postgresql-hll-2.14_old/include/include/opfusion/opfusion_scan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/opfusion/opfusion_scan.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,185 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion_scan.h + * scan operator's definition for bypass executor. + * + * IDENTIFICATION + * src/include/opfusion/opfusion_scan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ +#include "commands/prepare.h" +#include "executor/nodeIndexonlyscan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "storage/buf.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +struct ParamLoc { + int paramId; + int scanKeyIndx; +}; + +class ScanFusion : public BaseObject { +public: + ScanFusion(); + + ScanFusion(ParamListInfo params, PlannedStmt* planstmt); + + static ScanFusion* getScanFusion(Node* node, PlannedStmt* planstmt, ParamListInfo params); + + void refreshParameter(ParamListInfo params); + + virtual void Init(long max_rows) = 0; + + virtual HeapTuple getTuple() = 0; + + virtual void End(bool isCompleted) = 0; + + virtual bool EpqCheck(Datum* values, const bool* isnull) = 0; + + virtual void UpdateCurrentRel(Relation* rel) = 0; + + virtual void setAttrNo() = 0; + + virtual TupleTableSlot* getTupleSlot() = 0; + + ParamListInfo m_params; + + PlannedStmt* m_planstmt; + + Relation m_rel; + + Relation m_parentRel; + + Partition m_partRel; + + TupleTableSlot* m_reslot; + + TupleDesc m_tupDesc; + + ScanDirection* m_direction; +}; + +class IndexFusion : public ScanFusion { +public: + IndexFusion(ParamListInfo params, PlannedStmt* planstmt); + + IndexFusion() + {} + + void refreshParameterIfNecessary(); + + void BuildNullTestScanKey(Expr* clause, Expr* leftop, ScanKey this_scan_key); + + void IndexBuildScanKey(List* indexqual); + + virtual void Init(long max_rows) = 0; + + virtual HeapTuple getTuple() = 0; + + virtual void End(bool isCompleted) = 0; + + void setAttrNo(); + + virtual TupleTableSlot* getTupleSlot() = 0; + + bool EpqCheck(Datum* values, const bool* isnull); + + void UpdateCurrentRel(Relation* rel); + + Relation m_index; /* index relation */ + + Oid m_reloid; /* relation oid of range table */ + + IndexScanDesc m_scandesc; + + List* m_epq_indexqual; /* indexqual list */ + + bool m_keyInit; /* true if m_scanKeys has been initialized */ + + int m_keyNum; /* num of scan key */ + + ScanKey m_scanKeys; + + ParamLoc* m_paramLoc; /* location of m_params, include paramId and the location in indexqual */ + + int m_paramNum; + + Datum* m_values; + + bool* m_isnull; + + Datum* m_tmpvals; /* for mapping m_values */ + + bool* m_tmpisnull; /* for mapping m_isnull */ + + List* m_targetList; + + int16* m_attrno; /* target attribute number, length is m_tupDesc->natts */ + +}; + +class IndexScanFusion : public IndexFusion { +public: + IndexScanFusion() + {} + + ~IndexScanFusion(){}; + + IndexScanFusion(IndexScan* node, PlannedStmt* planstmt, ParamListInfo params); + + void Init(long max_rows); + + HeapTuple getTuple(); + + void End(bool isCompleted); + + TupleTableSlot* getTupleSlot(); + +private: + struct IndexScan* m_node; +}; + +class IndexOnlyScanFusion : public IndexFusion { +public: + IndexOnlyScanFusion() + {} + + ~IndexOnlyScanFusion(){}; + + IndexOnlyScanFusion(IndexOnlyScan* node, PlannedStmt* planstmt, ParamListInfo params); + + void Init(long max_rows); + + HeapTuple getTuple(); + + void End(bool isCompleted); + + TupleTableSlot* getTupleSlot(); + +private: + struct IndexOnlyScan* m_node; + + Buffer m_VMBuffer; +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ */ + diff -uprN postgresql-hll-2.14_old/include/include/opfusion/opfusion_util.h postgresql-hll-2.14/include/include/opfusion/opfusion_util.h --- postgresql-hll-2.14_old/include/include/opfusion/opfusion_util.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/opfusion/opfusion_util.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,240 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion_util.h + * Operator Fusion's definition for bypass. + * + * IDENTIFICATION + * src/include/opfusion/opfusion_util.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ +#include "commands/prepare.h" +#include "opfusion/opfusion_scan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +const int FUSION_EXECUTE = 0; +const int FUSION_DESCRIB = 1; + +extern int namestrcmp(Name name, const char* str); +extern void report_qps_type(CmdType commandType); +void InitOpfusionFunctionId(); + +enum FusionType { + NONE_FUSION, + + SELECT_FUSION, + SELECT_FOR_UPDATE_FUSION, + INSERT_FUSION, + UPDATE_FUSION, + DELETE_FUSION, + AGG_INDEX_FUSION, + SORT_INDEX_FUSION, + + MOT_JIT_SELECT_FUSION, + MOT_JIT_MODIFY_FUSION, + + BYPASS_OK, + + NOBYPASS_NO_CPLAN, + NOBYPASS_NO_SIMPLE_PLAN, + NOBYPASS_NO_QUERY_TYPE, + NOBYPASS_LIMITOFFSET_CONST_LESS_THAN_ZERO, + NOBYPASS_LIMITCOUNT_CONST_LESS_THAN_ZERO, + NOBYPASS_LIMIT_NOT_CONST, + NOBYPASS_INVALID_SELECT_FOR_UPDATE, + NOBYPASS_INVALID_MODIFYTABLE, + NOBYPASS_NO_SIMPLE_INSERT, + NOBYPASS_UPSERT_NOT_SUPPORT, + + NOBYPASS_NO_INDEXSCAN, + NOBYPASS_INDEXSCAN_WITH_ORDERBY, + NOBYPASS_INDEXSCAN_WITH_QUAL, + NOBYPASS_INDEXSCAN_CONDITION_INVALID, + + NOBYPASS_INDEXONLYSCAN_WITH_ORDERBY, + NOBYPASS_INDEXONLYSCAN_WITH_QUAL, + NOBYPASS_INDEXONLYSCAN_CONDITION_INVALID, + + NOBYPASS_TARGET_WITH_SYS_COL, + NOBYPASS_TARGET_WITH_NO_TABLE_COL, + NOBYPASS_NO_TARGETENTRY, + NOBYPASS_PARAM_TYPE_INVALID, + + NOBYPASS_DML_RELATION_NUM_INVALID, + NOBYPASS_DML_RELATION_NOT_SUPPORT, + NOBYPASS_DML_TARGET_TYPE_INVALID, + + NOBYPASS_EXP_NOT_SUPPORT, + NOBYPASS_STREAM_NOT_SUPPORT, + NOBYPASS_NULLTEST_TYPE_INVALID, + + NOBYPASS_INVALID_PLAN, + + NOBYPASS_NOT_PLAIN_AGG, + NOBYPASS_ONE_TARGET_ALLOWED, + NOBYPASS_AGGREF_TARGET_ALLOWED, + NOBYPASS_JUST_SUM_ALLOWED, + NOBYPASS_JUST_VAR_FOR_AGGARGS, + + NOBYPASS_JUST_MERGE_UNSUPPORTED, + NOBYPASS_JUST_VAR_ALLOWED_IN_SORT, + + NOBYPASS_ZERO_PARTITION, + NOBYPASS_MULTI_PARTITION, + NOBYPASS_EXP_NOT_SUPPORT_IN_PARTITION, + NO_BYPASS_PARTITIONKEY_IS_NULL, + NOBYPASS_NO_UPDATE_PARTITIONKEY, + NOBYPASS_NO_INCLUDING_PARTITIONKEY, + NOBYPASS_PARTITION_BYPASS_NOT_OPEN +}; + +enum FusionDebug { + BYPASS_OFF, + BYPASS_LOG, +}; + +const int MAX_OP_FUNCTION_NUM = 2; + +typedef struct FuncExprInfo { + AttrNumber resno; + Oid funcid; + List* args; +} FuncExprInfo; + +const int OPFUSION_FUNCTION_ID_MAX_HASH_SIZE = 200; + +/* length of function_id should not more than OPFUSION_FUNCTION_ID_MAX_HASH_SIZE */ +const Oid function_id[] = { + 311, /* convert float4 to float8 */ + 312, /* convert float8 to float4 */ + 313, /* convert int2 to int4 */ + 314, /* convert int4 to int2 */ + 315, /* int2vectoreq */ + 316, /* convert int4 to float8 */ + 317, /* convert float8 to int4 */ + 318, /* convert int4 to float4 */ + 319, /* convert float4 to int4 */ + 401, /* convert char(n) to text */ + 406, /* convert name to text */ + 407, /* convert text to name */ + 408, /* convert name to char(n) */ + 409, /* convert char(n) to name */ + 668, /* adjust char() to typmod length */ + 669, /* adjust varchar() to typmod length */ + 944, /* convert text to char */ + 946, /* convert char to text */ + 1200, /* adjust interval precision */ + 1400, /* convert varchar to name */ + 1401, /* convert name to varchar */ + 1683, /* convert int4 to bitstring */ + 1684, /* convert bitstring to int4 */ + 1685, /* adjust bit() to typmod length */ + 1687, /* adjust varbit() to typmod length */ + 1703, /* adjust numeric to typmod precision/scale */ + 1705, /* abs */ + 1706, /* sign */ + 1707, /* round */ + 1711, /* ceil */ + 1712, /* floor */ + 1728, /* mod */ + 1740, /* convert int4 to numeric */ + 1742, /* convert float4 to numeric */ + 1743, /* convert float8 to numeric */ + 1744, /* convert numeric to int4 */ + 1745, /* convert numeric to float4 */ + 1746, /* convert numeric to float8 */ + 1768, /* format interval to text */ + 1777, /* convert text to numeric */ + 1778, /* convert text to timestamp with time zone */ + 1780, /* convert text to date */ + 1961, /* adjust timestamp precision */ + 1967, /* adjust timestamptz precision */ + 1968, /* adjust time precision */ + 1969, /* adjust time with time zone precision */ + 2089, /* convert int4 number to hex */ + 2090, /* convert int8 number to hex */ + 2617, /* ceiling */ + 3192, /* convert int4 to bpchar */ + 3207, /* convert text to timestamp without time zone */ + 3811, /* convert int4 to money */ + 3812, /* convert int8 to money */ + 3823, /* convert money to numeric */ + 3824, /* convert numeric to money */ + 3961, /* adjust nvarchar2() to typmod length */ + 3961, /* adjust nvarchar2() to typmod length */ + 4065, /* convert int1 to varchar */ + 4066, /* convert int1 to nvarchar2 */ + 4067, /* convert int1 to bpchar */ + 4068, /* convert int2 to bpchar */ + 4069, /* convert int8 to bpchar */ + 4070, /* convert float4 to bpchar */ + 4071, /* convert float8 to bpchar */ + 4072, /* convert numeric to bpchar */ + 4073, /* convert text to timestamp */ + 4167, /* convert int4 to text */ + 4168, /* convert int8 to text */ + 4169, /* convert float4 to text */ + 4170, /* convert float8 to text */ + 4171, /* convert numeric to text */ + 4172, /* convert bpchar to numeric */ + 4173, /* convert varchar to numeric */ + 4174, /* convert varchar to int4 */ + 4175, /* convert bpchar to int4 */ + 4176, /* convert varchar to int8 */ + 4177, /* convert timestampzone to text */ + 4178, /* convert timestamp to text */ + 4179, /* convert timestamp to text */ + 4180, /* convert int2 to varchar */ + 4181, /* convert int4 to varchar */ + 4182, /* convert int8 to varchar */ + 4183, /* convert numeric to varchar */ + 4184, /* convert float4 to varchar */ + 4185, /* convert float8 to varchar */ + 4186, /* convert varchar to timestamp */ + 4187, /* convert bpchar to timestamp */ + 4188, /* convert text to int1 */ + 4189, /* convert text to int2 */ + 4190, /* convert text to int4 */ + 4191, /* convert text to int8 */ + 4192, /* convert text to float4 */ + 4193, /* convert text to float8 */ + 4194, /* convert text to numeric */ + 4195, /* convert bpchar to int8 */ + 4196, /* convert bpchar to float4 */ + 4197, /* convert bpchar to float8 */ + 4198, /* convert varchar to float4 */ + 4199, /* convert varchar to float8 */ + 5523, /* convert int1 to int2 */ + 5524, /* convert int2 to int1 */ + 5525, /* convert int1 to int4 */ + 5526, /* convert int4 to int1 */ + 5527, /* convert int1 to int8 */ + 5528, /* convert int8 to int1 */ + 5529, /* convert int1 to float4 */ + 5530, /* convert float4 to int1 */ + 5531, /* convert int1 to float8 */ + 5532, /* convert float8 to int1 */ + 5533, /* convert int1 to bool */ + 5534 /* convert bool to int1 */ +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/autoanalyzer.h postgresql-hll-2.14/include/include/optimizer/autoanalyzer.h --- postgresql-hll-2.14_old/include/include/optimizer/autoanalyzer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/autoanalyzer.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * autoanalyzer.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/autoanalyzer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef AUTOANALYZER_H +#define AUTOANALYZER_H + +#include "libpq/libpq-fe.h" +#include "lib/stringinfo.h" +#include "utils/relcache.h" + +/* Auto-Analyze */ +class AutoAnaProcess : public BaseObject { +public: + // constructor + AutoAnaProcess(Relation rel); + + ~AutoAnaProcess(); + + static bool runAutoAnalyze(Relation rel); + + static void cancelAutoAnalyze(); + +protected: + PGconn* m_pgconn; + + PGresult* m_res; + + List* m_query; + +private: + static bool check_conditions(Relation rel); + + bool run(); + + bool executeSQLCommand(char* cmd); + + static void tear_down(); +}; + +#endif /* AUTOANALYZER_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/bucketinfo.h postgresql-hll-2.14/include/include/optimizer/bucketinfo.h --- postgresql-hll-2.14_old/include/include/optimizer/bucketinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/bucketinfo.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * bucketinfo.h + * the basic node defination for hashbucket + * we keep BucketInfo in a seperate file + * + * + * IDENTIFICATION + * src/include/optimizer/bucketinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUCKETINFO_H +#define BUCKETINFO_H + +#include "nodes/nodes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "lib/stringinfo.h" + +typedef struct BucketInfo { + NodeTag type; + List* buckets; /* bukect ids to be scanned, NULL means all buckets */ +} BucketInfo; + +extern char* bucketInfoToString(BucketInfo* bucket_info); +extern bool hasValidBuckets(RangeVar* r); +extern List* RangeVarGetBucketList(RangeVar* rangeVar); +#endif diff -uprN postgresql-hll-2.14_old/include/include/optimizer/bucketpruning.h postgresql-hll-2.14/include/include/optimizer/bucketpruning.h --- postgresql-hll-2.14_old/include/include/optimizer/bucketpruning.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/bucketpruning.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,40 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * bucketpruning.h + * functions related to bucketpruning + * + * IDENTIFICATION + * src/include/optimizer/bucketpruning.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUCKETPRUNING_H +#define BUCKETPRUNING_H + +#include "nodes/relation.h" +#include "nodes/parsenodes.h" +#include "nodes/execnodes.h" +#include "utils/plancache.h" +#include "utils/globalplancache.h" + + +extern void set_rel_bucketinfo(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); +extern double getBucketPruningRatio(BucketInfo* bucket_info); +extern void setPlanBucketId(Plan* plan, ParamListInfo params, MemoryContext cxt); +extern void setCachedPlanBucketId(CachedPlan *cplan, ParamListInfo boundParams); +extern BucketInfo* CalBucketInfo(ScanState* state); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/optimizer/clauses.h postgresql-hll-2.14/include/include/optimizer/clauses.h --- postgresql-hll-2.14_old/include/include/optimizer/clauses.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/clauses.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,130 @@ +/* ------------------------------------------------------------------------- + * + * clauses.h + * prototypes for clauses.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/clauses.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CLAUSES_H +#define CLAUSES_H + +#include "nodes/relation.h" +#include "parser/parse_node.h" +#include "nodes/nodeFuncs.h" + +#define is_opclause(clause) ((clause) != NULL && IsA(clause, OpExpr)) +#define is_funcclause(clause) ((clause) != NULL && IsA(clause, FuncExpr)) + +typedef struct { + int numWindowFuncs; /* total number of WindowFuncs found */ + Index maxWinRef; /* windowFuncs[] is indexed 0 .. maxWinRef */ + List** windowFuncs; /* lists of WindowFuncs for each winref */ + List* activeWindows; +} WindowLists; + +typedef enum { UNIQUE_CONSTRAINT, NOT_NULL_CONSTRAINT } constraintType; + +extern Expr* make_opclause( + Oid opno, Oid opresulttype, bool opretset, Expr* leftop, Expr* rightop, Oid opcollid, Oid inputcollid); +extern Node* get_leftop(const Expr* clause); +extern Node* get_rightop(const Expr* clause); + +extern bool not_clause(Node* clause); +extern Expr* make_notclause(Expr* notclause); +extern Expr* get_notclausearg(Expr* notclause); + +extern bool or_clause(Node* clause); +extern Expr* make_orclause(List* orclauses); + +extern bool and_clause(Node* clause); +extern Expr* make_andclause(List* andclauses); +extern Node* make_and_qual(Node* qual1, Node* qual2); +extern Expr* make_ands_explicit(List* andclauses); +extern List* make_ands_implicit(Expr* clause); + +extern bool contain_agg_clause(Node* clause); +extern bool contain_specified_agg_clause(Node* clause); +extern void count_agg_clauses(PlannerInfo* root, Node* clause, AggClauseCosts* costs); + +extern bool contain_window_function(Node* clause); +extern void free_windowFunc_lists(WindowLists* lists); +extern WindowLists* make_windows_lists(Index maxWinRef); +extern void find_window_functions(Node* clause, WindowLists* lists); + +extern double expression_returns_set_rows(Node* clause); +extern double tlist_returns_set_rows(List* tlist); + +extern bool contain_subplans(Node* clause); + +extern bool contain_mutable_functions(Node* clause); +extern bool contain_volatile_functions(Node* clause); +extern bool contain_specified_function(Node* clause, Oid funcid); +extern bool contain_nonstrict_functions(Node* clause, bool check_agg = false); +extern bool contain_leaky_functions(Node* clause); +extern bool exec_simple_check_mutable_function(Node* clause); + +extern Relids find_nonnullable_rels(Node* clause); +extern List* find_nonnullable_vars(Node* clause); +extern List* find_forced_null_vars(Node* clause); +extern Var* find_forced_null_var(Node* clause); + +extern bool is_pseudo_constant_clause(Node* clause); +extern bool is_pseudo_constant_clause_relids(Node* clause, Relids relids); + +extern int NumRelids(Node* clause); + +extern void CommuteOpExpr(OpExpr* clause); +extern void CommuteRowCompareExpr(RowCompareExpr* clause); + +extern Node* strip_implicit_coercions(Node* node); + +extern Node* eval_const_expressions(PlannerInfo* root, Node* node); + +extern Node* eval_const_expressions_params(PlannerInfo* root, Node* node, ParamListInfo boundParams); + +extern Node* estimate_expression_value(PlannerInfo* root, Node* node, EState* estate = NULL); + +extern Query* inline_set_returning_function(PlannerInfo* root, RangeTblEntry* rte); +extern Query* search_cte_by_parse_tree(Query* parse, RangeTblEntry* rte, bool under_recursive_tree); +extern bool filter_cstore_clause(PlannerInfo* root, Expr* clause); +/* evaluate_expr used to be a static function */ +extern Expr* evaluate_expr(Expr* expr, Oid result_type, int32 result_typmod, Oid result_collation); +extern bool contain_var_unsubstitutable_functions(Node* clause); +extern void distribute_qual_to_rels(PlannerInfo* root, Node* clause, bool is_deduced, bool below_outer_join, + JoinType jointype, Index security_level, Relids qualscope, Relids ojscope, Relids outerjoin_nonnullable, + Relids deduced_nullable_relids, List **postponed_qual_list); +extern void check_plan_correlation(PlannerInfo* root, Node* expr); +extern bool findConstraintByVar(Var* var, Oid relid, constraintType conType); +extern bool is_var_node(Node* node); +extern Node* substitute_var(Node* expr, List* planTargetList); +extern bool treat_as_join_clause(Node* clause, RestrictInfo* rinfo, int varRelid, SpecialJoinInfo* sjinfo); +extern List* extract_function_outarguments(Oid funcid, List* parameters, List* funcname); +extern bool need_adjust_agg_inner_func_type(Aggref* aggref); + +#ifndef ENABLE_MULTIPLE_NODES +extern bool contain_rownum_walker(Node *node, void *context); + +static inline bool contain_rownum_expr(Node *node) +{ + return contain_rownum_walker(node, NULL); +} + +/* Check if it includes Rownum */ +static inline void ExcludeRownumExpr(ParseState* pstate, Node* expr) +{ + if (contain_rownum_expr(expr)) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("specified ROWNUM is not allowed here."), + parser_errposition(pstate, exprLocation(expr)))); +} + +extern List* get_quals_lists(Node *jtnode); +#endif +#endif /* CLAUSES_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/comm.h postgresql-hll-2.14/include/include/optimizer/comm.h --- postgresql-hll-2.14_old/include/include/optimizer/comm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/comm.h 2020-12-12 17:06:43.235347883 +0800 @@ -0,0 +1,64 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * comm.h + * + * IDENTIFICATION + * src/include/optimizer/comm.h + * + * DESCRIPTION + * Declaration of externel APIs of Code/src/backend/utils/learn/comm.cpp + * + * ------------------------------------------------------------------------- + */ + +#ifndef COMM_H +#define COMM_H + +#include + +#define CURL_BUF_SIZE 4096 +/* For ssl certificates */ +#define CAHOME "/CA" +#define CA_PATH "/CA/demoCA/cacert.pem" +#define CERT_PATH "/CA/client.crt" +#define KEY_PATH "/CA/client.key" + +typedef struct AiEngineConnInfo { + bool accessible; + char* host; + char* port; + char* url; + char* request_api; + char* file_tag; + char* file_path; + char* header; + char* json_string; +} AiEngineConnInfo; + +typedef struct AiConn { + CURL* curl; // the connection handler + char* rec_buf; // the buffer of receive data + int rec_len; // the length of the buffer + int rec_cursor; // the end of current data in the buffer +} AiConn; + +extern AiConn* MakeAiConnHandle(); +extern bool InitAiConnHandle(AiConn* connHandle); +extern void SetOptForCurl(AiConn* connHandle, AiEngineConnInfo* conninfo, int timeout); +extern void DestoryAiHandle(AiConn* connHandle); +extern bool TryConnectRemoteServer(AiEngineConnInfo* conninfo, char** buf); +extern void DestroyConnInfo(AiEngineConnInfo* conninfo); +#endif /* COMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/cost.h postgresql-hll-2.14/include/include/optimizer/cost.h --- postgresql-hll-2.14_old/include/include/optimizer/cost.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/cost.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,327 @@ +/* ------------------------------------------------------------------------- + * + * cost.h + * prototypes for costsize.c and clausesel.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/cost.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COST_H +#define COST_H + +#include "executor/nodeHash.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/planmain.h" +#include "utils/aset.h" +#include "utils/extended_statistics.h" + +#define STREAM_COST_THRESHOLD 100000.0 + +/* + * For columnar scan, the cpu cost is less than seq scan, so + * we are definition that the cost of scanning one tuple is 1/10 times. + */ +#define COL_TUPLE_COST_MULTIPLIER 10 + +/* + * Estimate the overhead per hashtable entry at 64 bytes (same as in + * planner.c). + */ +#define HASH_ENTRY_OVERHEAD 64 + +/* defaults for costsize.c's Cost parameters */ +/* NB: cost-estimation code should use the variables, not these constants! */ +/* If you change these, update backend/utils/misc/postgresql.sample.conf */ +#define DEFAULT_SEQ_PAGE_COST 1.0 +#define DEFAULT_RANDOM_PAGE_COST 4.0 +#define DEFAULT_CPU_TUPLE_COST 0.01 +#define DEFAULT_CPU_INDEX_TUPLE_COST 0.005 +#define DEFAULT_CPU_OPERATOR_COST 0.0025 +#define DEFAULT_CPU_HASH_COST 0.02 +#define DEFAULT_SEND_KDATA_COST 2.0 +#define DEFAULT_RECEIVE_KDATA_COST 2.0 +#define DEFAULT_ALLOCATE_MEM_COST 0.0 +#define LOCAL_SEND_KDATA_COST 1.3 /* The send cost for local stream */ +#define LOCAL_RECEIVE_KDATA_COST 1.3 /* The receive cost for local stream */ +#define DEFAULT_SMP_THREAD_COST 1000 /* The cost for add a new thread */ +#define DEFAULT_STREAM_MULTIPLE 1.0 + +#define DEFAULT_EFFECTIVE_CACHE_SIZE 16384 /* measured in pages */ + +#define COST_ALTERNATIVE_NEQ 0x00000001 +#define COST_ALTERNATIVE_CONJUNCT 0x00000002 +#define COST_ALTERNATIVE_MERGESORT 0x00000004 /* disable mergesort option */ +#define COST_ALTERNATIVE_EQUALRANGE_NOTINMCV 0x00000008 /* filter has equal range but the const not in mcv */ + +#define SIZE_COL_VALUE 16 + +#define TUPLE_OVERHEAD(colorsort) ((colorsort) ? 24 : 8) + +typedef enum { + CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */ + CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */ + CONSTRAINT_EXCLUSION_PARTITION /* apply c_e to otherrels only */ +} ConstraintExclusionType; + +extern void init_plan_cost(Plan* plan); +extern void cost_insert(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); +extern void cost_delete(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); +extern void cost_update(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); + +extern double clamp_row_est(double nrows); +extern double index_pages_fetched( + double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo* root, bool ispartitionedindex); +extern void cost_seqscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_samplescan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_cstorescan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_dfsscan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +#ifdef ENABLE_MULTIPLE_NODES +extern void cost_tsstorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel); +#endif /* ENABLE_MULTIPLE_NODES */ +extern void cost_index(IndexPath* path, PlannerInfo* root, double loop_count); +extern void cost_bitmap_heap_scan( + Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info, Path* bitmapqual, double loop_count); +extern void cost_bitmap_and_node(BitmapAndPath* path, PlannerInfo* root); +extern void cost_bitmap_or_node(BitmapOrPath* path, PlannerInfo* root); +extern void cost_bitmap_tree_node(Path* path, Cost* cost, Selectivity* selec); +extern void cost_tidscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, List* tidquals); +extern void cost_subqueryscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_functionscan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_valuesscan(Path* path, PlannerInfo* root, RelOptInfo* baserels); +#ifdef PGXC +extern void cost_remotequery(RemoteQueryPath* rqpath, PlannerInfo* root, RelOptInfo* rel); +#endif +extern void cost_ctescan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_recursive_union(Plan* runion, Plan* nrterm, Plan* rterm); +extern void cost_sort(Path* path, List* pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, + int sort_mem, double limit_tuples, bool col_store, int dop = 1, OpMemInfo* mem_info = NULL, + bool index_sort = false); +extern void cost_merge_append(Path* path, PlannerInfo* root, List* pathkeys, int n_streams, Cost input_startup_cost, + Cost input_total_cost, double tuples); +extern void cost_material(Path* path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width); +extern void cost_agg(Path* path, PlannerInfo* root, AggStrategy aggstrategy, const AggClauseCosts* aggcosts, + int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples, + int input_width = 0, int hash_entry_size = 0, int dop = 1, OpMemInfo* mem_info = NULL); +extern void cost_windowagg(Path* path, PlannerInfo* root, List* windowFuncs, int numPartCols, int numOrderCols, + Cost input_startup_cost, Cost input_total_cost, double input_tuples); +extern void cost_group(Path* path, PlannerInfo* root, int numGroupCols, double numGroups, Cost input_startup_cost, + Cost input_total_cost, double input_tuples); +extern void cost_limit(Plan* plan, Plan* lefttree, int64 offset_est, int64 count_est); +extern void initial_cost_nestloop(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, Path* outer_path, + Path* inner_path, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, int dop); +extern void final_cost_nestloop(PlannerInfo* root, NestPath* path, JoinCostWorkspace* workspace, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, bool hasalternative, int dop); +extern void initial_cost_mergejoin(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, + List* mergeclauses, Path* outer_path, Path* inner_path, List* outersortkeys, List* innersortkeys, + SpecialJoinInfo* sjinfo); +extern void final_cost_mergejoin( + PlannerInfo* root, MergePath* path, JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, bool hasalternative); +extern void initial_cost_hashjoin(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, List* hashclauses, + Path* outer_path, Path* inner_path, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, int dop); +extern void final_cost_hashjoin(PlannerInfo* root, HashPath* path, JoinCostWorkspace* workspace, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, bool hasalternative, int dop); +extern void cost_rescan(PlannerInfo* root, Path* path, Cost* rescan_startup_cost, /* output parameters */ + Cost* rescan_total_cost, OpMemInfo* mem_info); +extern Cost cost_rescan_material(double rows, int width, OpMemInfo* mem_info, bool vectorized, int dop); +extern void cost_subplan(PlannerInfo* root, SubPlan* subplan, Plan* plan); +extern void cost_qual_eval(QualCost* cost, List* quals, PlannerInfo* root); +extern void cost_qual_eval_node(QualCost* cost, Node* qual, PlannerInfo* root); +extern void compute_semi_anti_join_factors(PlannerInfo* root, RelOptInfo* outerrel, RelOptInfo* innerrel, + JoinType jointype, SpecialJoinInfo* sjinfo, List* restrictlist, SemiAntiJoinFactors* semifactors); +extern void set_baserel_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern double get_parameterized_baserel_size(PlannerInfo* root, RelOptInfo* rel, List* param_clauses); +extern double get_parameterized_joinrel_size(PlannerInfo* root, RelOptInfo* rel, double outer_rows, double inner_rows, + SpecialJoinInfo* sjinfo, List* restrict_clauses); +extern void set_joinrel_size_estimates(PlannerInfo* root, RelOptInfo* rel, RelOptInfo* outer_rel, RelOptInfo* inner_rel, + SpecialJoinInfo* sjinfo, List* restrictlist); +extern void set_joinpath_multiple_for_EC(PlannerInfo* root, Path* path, Path* outer_path, Path* inner_path); +extern void set_subquery_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_function_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_values_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_cte_size_estimates(PlannerInfo* root, RelOptInfo* rel, Plan* cteplan); +extern void set_foreign_size_estimates(PlannerInfo* root, RelOptInfo* rel); + +/* + * prototypes for clausesel.c + * routines to compute clause selectivities + */ +extern Selectivity clauselist_selectivity(PlannerInfo* root, List* clauses, int varRelid, JoinType jointype, + SpecialJoinInfo* sjinfo, bool varratio_cached = true); +extern Selectivity clause_selectivity(PlannerInfo* root, Node* clause, int varRelid, JoinType jointype, + SpecialJoinInfo* sjinfo, bool varratio_cached = true, bool check_scalarop = false); + +extern void set_rel_width(PlannerInfo* root, RelOptInfo* rel); +extern void restore_hashjoin_cost(Path* path); +extern void finalize_dml_cost(ModifyTable* plan); +extern void copy_mem_info(OpMemInfo* dest, OpMemInfo* src); +extern int columnar_get_col_width(int typid, int width, bool aligned = false); +extern int get_path_actual_total_width(Path* path, bool vectorized, OpType type, int newcol = 0); + +extern void bernoulli_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern void system_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern void hybrid_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern double cost_page_size(double tuples, int width); +extern bool can_use_possion(VariableStatData* vardata, SpecialJoinInfo* sjinfo, double* ratio); +extern void set_equal_varratio(VariableStatData* vardata, Relids other_relids, double ratio, SpecialJoinInfo* sjinfo); +extern double estimate_hash_num_distinct(PlannerInfo* root, List* hashkey, Path* inner_path, VariableStatData* vardata, + double local_ndistinct, double global_ndistinct, bool* usesinglestats); +extern RelOptInfo* find_join_input_rel(PlannerInfo* root, Relids relids); +extern double compute_sort_disk_cost(double input_bytes, double sort_mem_bytes); + +extern double approx_tuple_count(PlannerInfo* root, JoinPath* path, List* quals); +extern void set_rel_path_rows(Path* path, RelOptInfo* rel, ParamPathInfo* param_info); +extern Selectivity compute_bucket_size(PlannerInfo* root, RestrictInfo* restrictinfo, double virtualbuckets, + Path* inner_path, bool left, SpecialJoinInfo* sjinfo, double* ndistinct); +extern double page_size(double tuples, int width); +extern bool has_complicate_hashkey(List* hashclauses, Relids inner_relids); +extern bool has_indexed_join_quals(NestPath* joinpath); +extern double relation_byte_size( + double tuples, int width, bool vectorized, bool aligned = true, bool issort = true, bool indexsort = false); +extern MergeScanSelCache* cached_scansel(PlannerInfo* root, RestrictInfo* rinfo, PathKey* pathkey); + +extern double apply_random_page_cost_mod(double rand_page_cost, double seq_page_cost, int num_of_page); + +#define ES_DEBUG_LEVEL DEBUG2 /* debug level for extended statistic in optimizor */ + +#define RANDOM_PAGE_COST(use_mod, rand_cost, seq_cost, pages) (use_mod ? \ + apply_random_page_cost_mod(rand_cost, seq_cost, pages) : rand_cost) + +/* Logistic function */ +#define LOGISTIC_FUNC(variable, threshold, max_func_value, min_func_value, slope_factor) \ + ((variable > threshold && variable > 0) ? max_func_value : \ + 2 * (max_func_value - min_func_value) / (1 + exp(-1 * slope_factor * variable)) \ + - (max_func_value - 2 * min_func_value)) + +enum es_type { ES_EMPTY = 0, ES_EQSEL = 1, ES_EQJOINSEL, ES_GROUPBY, ES_COMPUTEBUCKETSIZE }; + +struct es_bucketsize { + Bitmapset* left_relids; + Bitmapset* right_relids; + RelOptInfo* left_rel; + RelOptInfo* right_rel; + float4 left_distinct; + float4 right_distinct; + float4 left_dndistinct; + float4 right_dndistinct; + double left_mcvfreq; + double right_mcvfreq; + List* left_hashkeys; + List* right_hashkeys; +}; + +struct es_candidate { + es_type tag; + Bitmapset* relids; + Bitmapset* left_relids; /* for eqsel and groupby clause, only use left_XXX */ + Bitmapset* right_relids; + Bitmapset* left_attnums; + Bitmapset* right_attnums; + float4 left_stadistinct; /* will be transfer to absolute value */ + float4 right_stadistinct; + double left_first_mcvfreq; /* frequency of fist mcv, to calculate skew or bucket size */ + double right_first_mcvfreq; + RelOptInfo* left_rel; + RelOptInfo* right_rel; + RangeTblEntry* left_rte; + RangeTblEntry* right_rte; + List* clause_group; + List* clause_map; + ExtendedStats* left_extended_stats; + ExtendedStats* right_extended_stats; /* read from pg_statistic, where distinct value + * could be negative. (-1 means unique.) + */ + List* pseudo_clause_list; /* save the clause build by equivalence class and + * the original clause. + */ + bool has_null_clause; /* if "is null" used in the clauses */ +}; + +/* + * calculate selectivity using extended statistics + */ +class ES_SELECTIVITY : public BaseObject { +public: + List* es_candidate_list; + List* unmatched_clause_group; + PlannerInfo* root; /* root from input */ + SpecialJoinInfo* sjinfo; /* sjinfo from input */ + List* origin_clauses; /* clauselist from input */ + JoinPath* path; /* path from input */ + List* bucketsize_list; /* list of bucket size */ + + /* a simplified structure from clause */ + struct es_clause_map { + int left_attnum; + int right_attnum; + Var* left_var; + Var* right_var; + }; + + ES_SELECTIVITY(); + virtual ~ES_SELECTIVITY(); + Selectivity calculate_selectivity(PlannerInfo* root_input, List* clauses_input, SpecialJoinInfo* sjinfo_input, + JoinType jointype, JoinPath* path_input, es_type action, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL); + void clear(); + void print_clauses(List* clauselist) const; + Selectivity estimate_hash_bucketsize( + es_bucketsize* es_bucket, double* distinctnum, bool left, Path* inner_path, double nbuckets); + +private: + bool add_attnum(RestrictInfo* clause, es_candidate* temp) const; + void add_attnum_for_eqsel(es_candidate* temp, int attnum, Node* arg) const; + void add_clause_map(es_candidate* es, int left_attnum, int right_attnum, Node* left_arg, Node* right_arg) const; + bool build_es_candidate(RestrictInfo* clause, es_type type); + bool build_es_candidate_for_eqsel(es_candidate* es, Node* var, int attnum, bool left, RestrictInfo* clause); + void build_pseudo_varinfo(es_candidate* es, STATS_EST_TYPE eType); + void cal_bucket_size(es_candidate* es, es_bucketsize* bucket) const; + Selectivity cal_eqsel(es_candidate* es); + Selectivity cal_eqjoinsel(es_candidate* es, JoinType jointype); + Selectivity cal_eqjoinsel_inner(es_candidate* es); + Selectivity cal_eqjoinsel_semi(es_candidate* es, RelOptInfo* inner_rel, bool inner_on_left); + void cal_stadistinct_eqsel(es_candidate* es); + bool cal_stadistinct_eqjoinsel(es_candidate* es); + void clear_extended_stats(ExtendedStats* extended_stats) const; + void clear_extended_stats_list(List* stats_list) const; + ExtendedStats* copy_stats_ptr(ListCell* l) const; + void debug_print(); + double estimate_local_numdistinct(es_bucketsize* bucket, bool left, Path* path); + void group_clauselist(List* clauses); + void group_clauselist_groupby(List* varinfos); + void init_candidate(es_candidate* es) const; + void load_eqsel_clause(RestrictInfo* clause); + void load_eqjoinsel_clause(RestrictInfo* clause); + Bitmapset* make_attnums_by_clause_map(es_candidate* es, Bitmapset* attnums, bool left) const; + void match_extended_stats(es_candidate* es, List* stats_list, bool left); + bool match_pseudo_clauselist(List* clauses, es_candidate* es, List* origin_clause); + void modify_distinct_by_possion_model(es_candidate* es, bool left, SpecialJoinInfo* sjinfo) const; + char* print_expr(const Node* expr, const List* rtable) const; + void print_rel(RangeTblEntry* rel) const; + void print_relids(Bitmapset* relids, const char* str) const; + int read_attnum(Node* node) const; + void read_rel_rte(Node* node, RelOptInfo** rel, RangeTblEntry** rte); + void read_statistic(); + void read_statistic_eqjoinsel(es_candidate* es); + void read_statistic_eqsel(es_candidate* es); + void recheck_candidate_list(); + void remove_candidate(es_candidate* es); + void remove_attnum(es_candidate* es, int dump_attnum); + void remove_members_without_es_stats(int max_matched, int num_members, es_candidate* es); + void replace_clause(Datum* old_clause, Datum* new_clause) const; + void report_no_stats(Oid relid_oid, Bitmapset* attnums) const; + void save_selectivity( + es_candidate* es, double left_join_ratio, double right_join_ratio, bool save_semi_join = false); + void set_up_attnum_order(es_candidate* es, int* attnum_order, bool left) const; + bool try_equivalence_class(es_candidate* es); + void setup_es(es_candidate* es, es_type type, RestrictInfo* clause); +}; + +#endif /* COST_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/dataskew.h postgresql-hll-2.14/include/include/optimizer/dataskew.h --- postgresql-hll-2.14_old/include/include/optimizer/dataskew.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/dataskew.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,456 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataskew.h + * functions for dataskew solution in GaussDB + * + * + * IDENTIFICATION + * src/include/optimizer/dataskew.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATASKEW_H +#define DATASKEW_H +#include "nodes/execnodes.h" +#include "nodes/relation.h" +#include "optimizer/streamplan.h" +#include "parser/parse_hint.h" + +#define SKEW_RES_NONE 0x00 /* No skew optimization path if create. */ +#define SKEW_RES_STAT 0x01 /* Create skew optimization by statistic. */ +#define SKEW_RES_RULE 0x02 /* Create skew optimization by rule. */ +#define SKEW_RES_HINT 0x04 /* Create skew optimization by hint. */ + +typedef enum { + SKEW_NONE, /* Initial value. */ + SKEW_AGG, /* Skew info for agg. */ + SKEW_JOIN /* Skew info for join. */ +} SkewType; + +typedef enum { + PART_NONE = 0, /* Noe hybrid stream. */ + PART_REDISTRIBUTE_PART_BROADCAST, /* Do broadcast for some special data, and redistribute the rest. */ + PART_REDISTRIBUTE_PART_ROUNDROBIN, /* Do roundrobin for some special data, and redistribute the rest. */ + PART_REDISTRIBUTE_PART_LOCAL, /* Do local send for some special data, and redistribute the rest. */ + PART_LOCAL_PART_BROADCAST /* Do broadcast for some special data, and send the rest to local DN. */ +} SkewStreamType; + +typedef struct ColSkewInfo { + Node* var; /* Skew var of distribute keys. */ + Const* value; /* Skew value of this column. */ + double mcv_ratio; /* The proportion of data equal to the skew value. */ + double mcv_op_ratio; /* The proportion of data equal to skew value at the none skew side. */ + bool is_null; /* If this is null skew value. */ +} ColSkewInfo; + +typedef struct MultiColSkewInfo { + List* vars; /* Var list for distribute keys. */ + List* values; /* Skew value lists. */ + double mcv_ratio; /* The proportion of data equal to the skew value. */ + double mcv_op_ratio; /* The proportion of data equal to skew value at the none skew side. */ + bool is_null; /* If this is null skew value. */ +} MultiColSkewInfo; + +typedef struct QualSkewInfo { + NodeTag type; /* Node tag of qual skew info. */ + SkewStreamType skew_stream_type; /* Stream type for this skew qual. */ + List* skew_quals; /* Qual list for skew value. */ + QualCost qual_cost; /* Qual Cost for skew value. */ + double broadcast_ratio; /* Record ratio for broadcast data. */ +} QualSkewInfo; + +typedef struct QualSkewState { + SkewStreamType skew_stream_type; /* Stream type for this skew qual. */ + List* skew_quals_state; /* Qual State for skew value. */ +} QualSkewState; + +class SkewInfo : public BaseObject { +public: + SkewInfo(PlannerInfo* root); + + ~SkewInfo(); + + /* Get skew info. */ + uint32 getSkewInfo() const; + +protected: + /* Find skew value for single column distribute key. */ + List* findSingleColSkewValues(); + + /* Find skew value for single column distribute key from statistic info. */ + List* findSingleColSkewValuesFromStatistic(); + + /* Find skew value for single column distribute key from hint info. */ + List* findSingleColSkewValuesFromHint(); + + /* Find skew value for multi columns distribute key. */ + List* findMultiColSkewValues(); + + /* Find skew value for multi columns distribute key from statistic info. */ + List* findMultiColSkewValuesFromStatistic(); + + /* Find skew value for multi columns distribute key from single column statistic info. */ + List* findMultiColSkewValuesFromSingleStatistic(); + + /* Find skew value for multi columns distribute key from multi column statistic info. */ + List* findMultiColSkewValuesFromMultiStatistic(); + + /* Find skew value for multi columns distribute key from hint. */ + List* findMultiColSkewValuesFromHint(); + + /* Try to get single column statistic info. */ + List* getSingleColumnStatistics(Node* node); + + /* Try to get multi column statistic info. */ + List* getMultiColumnStatistics(); + + /* Find skew value from MCV. */ + List* findMcvValue(Node* var, int mcv_num, Datum* mcv_values, float4* mcv_ratios) const; + + /* Make const for skew value. */ + Const* makeConstForSkew(Var* var, Datum value) const; + + /* Create equal expression to identify skew values. */ + OpExpr* createEqualExprForSkew(Node* expr, Const* con) const; + + /* Get join clause from join path. */ + List* getJoinClause(Path* jpath) const; + + /* Find the column at may add null value in outer join. */ + List* findNullCols(List* target_list, List* subtarget_list, List* join_clauses) const; + + /* Check if the skew value can pass the restriction. */ + List* checkRestrict(List* baseSkewList); + + /* Check if the skew value of single column can pass the restriction. */ + List* checkRestrictForSingleCol(List* baseSkewList); + + /* Check if the skew value of multi column can pass the restriction. */ + List* checkRestrictForMultiCol(List* baseSkewList); + + /* Check if the current relation equal relation in skew hint. */ + bool checkSkewRelEqualHintRel(List* skewRelHint); + + /* Check if the distribute key is compitable to hint key. */ + bool checkEqualKey(Node* node, SkewColumnInfo* colHint) const; + + /* Check if the current column equal column in skew hint. */ + bool checkSkewColEqualHintCol(Node* node, SkewColumnInfo* colHint); + + /* Get skew value for hint. */ + bool getSkewKeys(List* skewHints, int* colLoc, int colLen); + + /* Get skew value for statistic. */ + bool getSkewKeys(); + + /* Get real skew value after type tranfer. */ + Const* getRealSkewValue(Node* diskey, Node* skewkey, Const* value); + + /* Process skew value for type tranfer. */ + void processSkewValue(List* skewlist); + + /* Check if the current distribute keys are simple var. */ + bool checkDistributekeys(List* distributekeys); + + /* Check if the restriction include this distribute keys. */ + bool isColInRestrict(List* distributekeys, Node* clause) const; + + /* Execute the equal expression actually. */ + bool ExecSkewvalExpr(Expr* expr, TupleTableSlot* slot); + + /* Check if the skew value can pass restriction. */ + bool canValuePassQual(List* varList, List* valueList, Expr* expr); + + /* Check if skew values can equal for single col. */ + bool isSingleColSkewValueEqual(ColSkewInfo* cs_inner, ColSkewInfo* cs_outer); + + /* Check if skew values can equal for multi col. */ + bool isMultiColSkewValueEqual(MultiColSkewInfo* mcs_inner, MultiColSkewInfo* mcs_outer); + + /* Updata the skewness for multi column distirbute keys. */ + void updateMultiColSkewness(StreamInfo* sinfo, List* skew_list) const; + + /* Generate a bitmap for rel in skew hint. */ + Relids generateRelidsFromRelList(List* skewRelHint); + + /* Compare two rels are the same one. */ + bool compareRelByRTE(RangeTblEntry* rte1, RangeTblEntry* rte2) const; + + /* Check if we need broadcast the non skew side. */ + bool needPartBroadcast(ColSkewInfo* csinfo) const; + + /* Check if we need broadcast the non skew side. */ + bool needPartBroadcast(MultiColSkewInfo* mcsinfo) const; + + /* Print detail info of skew oprimization info. */ + void printSkewOptimizeDetail(const char* msg); + +protected: + /* Planner info of current query level. */ + PlannerInfo* m_root; + + /* Reloptinfo of current path. */ + RelOptInfo* m_rel; + + /* Reloptinfo of subpath. */ + RelOptInfo* m_subrel; + + /* Distribute keys for this stream. */ + List* m_distributeKeys; + + /* Base skew keys. */ + List* m_skewKeys; + + /* Consumer parallel degree. */ + int m_dop; + + /* Skew type */ + SkewType m_skewType; + + /* Flag to identify if the distribute key include multi-columns. */ + bool m_isMultiCol; + + /* Original memory context. */ + MemoryContext m_oldContext; + + /* Memory context for skew optimization process. */ + MemoryContext m_context; + + /* Find skew info from statistic. */ + bool m_hasStatSkew; + + /* Find skew info from hint. */ + bool m_hasHintSkew; + + /* Find skew info from rule. */ + bool m_hasRuleSkew; +}; + +class JoinSkewInfo : public SkewInfo { +public: + JoinSkewInfo(PlannerInfo* root, RelOptInfo* rel, List* join_clause, JoinType join_type, JoinType save_join_type); + + ~JoinSkewInfo(); + + /* Find skew info for join. */ + uint32 findStreamSkewInfo(); + + /* Set stream info to find skew info for join. */ + void setStreamInfo(StreamInfo* inner_stream_info, StreamInfo* outer_stream_info, Distribution* distribution); + + /* Reset skew info for next use. */ + void resetSkewInfo(); + +private: + /* Find skew info from base relation. */ + void findBaseSkewInfo(); + + /* Find skew info caused by outer join. */ + void findNullSkewInfo(); + + /* Add qual cost. */ + void addQualSkewInfo(); + + /* Add the skew info to stream info. */ + void addToStreamInfo(); + + /* Find skew values for base rel. */ + void findBaseSkewValues(bool stream_outer); + + /* Find null skew from sub outer join. */ + void findSubNullSkew(bool is_outer); + + /* Add skew info to both stream side when we detect skew values. */ + void addSkewInfoBothSides(); + + /* Create quals for skew values. */ + List* createSkewQuals(bool is_stream_outer); + + /* Create quals of single distribute key. */ + List* createSingleColSkewQuals(bool is_stream_outer); + + /* Create quals of multi distribute keys. */ + List* createMultiColSkewQuals(bool is_stream_outer); + + /* Add skew info to the opposite side of skew side. */ + List* addSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Add skew info for single column to the opposite side of skew side. */ + List* addSingleColSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Add skew info for multi column to the opposite side of skew side. */ + List* addMultiColSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Choose suitable skew stream type for none skew side of join. */ + SkewStreamType chooseStreamForNoSkewSide(StreamInfo* sinfo) const; + + /* Delete duplicate skew values at both sides of join. */ + void deleteDuplicateSkewValue(); + + /* Delete duplicate skew values for single column at both sides of join. */ + void deleteDuplicateSingleColSkewValue(); + + /* Delete duplicate skew values for multi column at both sides of join. */ + void deleteDuplicateMultiColSkewValue(); + + /* Find out which side has more skew data or which is set by hint. */ + bool findMoreSkewSideForSingleCol(ColSkewInfo* cs1, ColSkewInfo* cs2) const; + + /* Find out which side has more skew data or which is set by hint. */ + bool findMoreSkewSideForMultiCol(MultiColSkewInfo* mcs1, MultiColSkewInfo* mcs2) const; + + /* Delete if we can not handle this skew situation. */ + void deleteUnoptimzeSkew(bool is_outer); + + /* Traverse the sub path to find null skew. */ + void traverseSubPath(Path* path); + + /* Check if current distribute keys are included in outer join's null column. */ + bool checkOuterJoinNulls(Path* jpath); + + /* Get all target list of join's input. */ + List* getSubTargetList(JoinPath* jpath) const; + + /* Add skew qual cost. */ + void addQualCost(bool is_outer); + + /* Check if this join may have skew problem. */ + bool checkSkewPossibility(bool is_outer); + + /* Check if we can optimize this skew problem. */ + bool checkSkewOptimization(bool is_outer); + + /* Check if we have create redundant skew optimization stream. */ + bool checkRedundant(bool is_outer); + + /* Travers sub path to find redundant skew stream. */ + bool checkPathRedundant(List* streamKeys, Path* path); + + /* Find key for the none skew side. */ + List* findOtherSidekeys(bool is_outer_skew); + + /* Find equal var list. */ + List* findEqualVarList(List* skewList, RelOptInfo* rel); + + /* Find equal vae. */ + Node* findEqualVar(Node* var, RelOptInfo* rel); + +private: + /* Join Type. */ + JoinType m_joinType; + + /* Save Join Type. */ + JoinType m_saveJoinType; + + /* Join clause. */ + List* m_joinClause; + + /* Target distribution. */ + Distribution* m_distribution; + + /* Stream info of join's inner side. */ + StreamInfo* m_innerStreamInfo; + + /* Stream info of join's outer side. */ + StreamInfo* m_outerStreamInfo; + + /* Skew info for join inner side. */ + List* m_innerSkewInfo; + + /* Skew Info for join outer side. */ + List* m_outerSkewInfo; + + /* Skew info. */ + List** m_skewInfo; + + /* If this is a outer stream. */ + bool m_isOuterStream; +}; + +class AggSkewInfo : public SkewInfo { +public: + AggSkewInfo(PlannerInfo* root, Plan* subplan, RelOptInfo* rel_info); + + ~AggSkewInfo(); + + /* Find stream skew info for agg. */ + void findStreamSkewInfo(); + + /* Set the distribute keys for agg. */ + void setDistributeKeys(List* distribute_keys); + +private: + /* Reset skew info for later use. */ + void resetSkewInfo(); + + /* Find skew info from hint. */ + void findHintSkewInfo(); + + /* Find skew info from statistic. */ + void findStatSkewInfo(); + + /* Find skew info from outer join' null side. */ + void findNullSkewInfo(); + + /* traverse subplan to find outer join's null skew. */ + void traverseSubPlan(Plan* subplan); + + /* Get the target list that may contain null column. */ + List* getSubTargetListByPlan(Plan* plan) const; + + /* Check if the distribute keys of agg are included in the null columns. */ + bool checkOuterJoinNullsForAgg(Plan* jplan) const; + +private: + /* Subplan of agg. */ + Plan* m_subplan; +}; + +class StreamSkew : public BaseObject { +public: + StreamSkew(List* ssinfo, bool isVec); + + ~StreamSkew(); + + /* Do initial work for skew stream. */ + void init(bool isVec); + + /* Choose suitable stream type for the skew stream. */ + int chooseStreamType(TupleTableSlot* tuple); + + /* Choose suitable stream type for the skew vecstream. */ + void chooseVecStreamType(VectorBatch* batch, int* skewStream); + +public: + /* The node id of local DN */ + int m_localNodeId; + +private: + /* Skew info list. */ + List* m_ssinfo; + + /* Skew qual state list. */ + List* m_skewQual; + + /* EState for skew quals. */ + EState* m_estate; + + /* Expr context for skew quals. */ + ExprContext* m_econtext; +}; + +extern List* find_skew_join_distribute_keys(Plan* plan); +#endif diff -uprN postgresql-hll-2.14_old/include/include/optimizer/dynsmp.h postgresql-hll-2.14/include/include/optimizer/dynsmp.h --- postgresql-hll-2.14_old/include/include/optimizer/dynsmp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/dynsmp.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,103 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dynsmp.h + * functions related to dynamic smp. + * + * + * IDENTIFICATION + * src/include/optimizer/dynsmp.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DYNSMP_H +#define DYNSMP_H + +#include "nodes/plannodes.h" + +extern void OptimizePlanDop(PlannedStmt* plannedStmt); +extern void InitDynamicSmp(); +extern bool IsDynamicSmpEnabled(); +extern void ChooseStartQueryDop(int hashTableCount); +extern void CheckQueryDopValue(); + +typedef struct GMNSDConext { + int max_non_spill_dop; /* the max dop we can use without spill to disk */ + bool already_spilled; /* if the plan is already spilled to disk ? */ + bool spill_if_use_higher_dop; /* if we +1 dop and the plan will spill to disk? */ + List* mem_info_list; /* the mem info we have to adjust later */ +} GMNSDConext; + +/* + * This struct holds the resource info needed by Dynamic Smp. + * For constant value, we only init once. + * For volatile value, we have to refreash from query to query. + */ +typedef struct DynamicSmpInfo { + /*-------CONSTANT----------------------------------- + * + * those variable does not change during one session + * + * -------------------------------------------------- + */ + /* how many dn installed in one physical machine */ + int num_of_dn_in_one_machine; + + /* how many cpu installed in one physical machine */ + int num_of_cpu_in_one_machine; + + /* how many cpu can be used for one dn */ + int num_of_cpu_for_one_dn; + + /*-------VOLATILE----------------------------------- + * + * those variable changes from query to query + * + * -------------------------------------------------- + */ + /* how many sql is running concurrently */ + int active_statement; + + /* the cpu util when planning this query */ + int cpu_util; + + int64 free_mem; + + int num_of_machine; +} DynamicSmpInfo; + +#define DYNMSP_ALREADY_SPILLED -1 +#define DYNMSP_SPILL_IF_USE_HIGHER_DOP -2 + +#define DS_LOG_PREFIX "[dynamic smp]" +#define UNKNOWN_NUM_OF_DN_IN_ONE_MACHINE -1 +#define DEFAULT_NUM_OF_DN_IN_ONE_MACHINE 2 +#define UNKNOWN_NUM_OF_CPU_IN_ONE_MACHINE -1 +#define DEFAULT_NUM_OF_CPU_IN_ONE_MACHINE 4 +#define UNKNOWN_NUM_OF_CPU_FOR_ONE_DN -1 +#define DEFAULT_NUM_OF_CPU_FOR_ONE_DN 2 +#define UNKNOWN_ACTIVE_STATEMENT -1 +#define DEFAULT_ACTIVE_STATEMENT 0 +#define UNKNOWN_CPU_UTIL -1 +#define DEFAULT_CPU_UTIL 40 +#define UNKNOWN_FREE_MEM -1 +#define DEFAULT_FREE_MEM 256 * 1024 /* in kb: 256MB * 1024 */ +#define UNKNOWN_NUM_OF_MACHINE -1 +#define DEFAULT_NUM_OF_MACHINE 1 +#define MAX_STREAM_MEM_RATIO 0.25 +#define MIN_STREAM_MEM_RATIO 0.05 +#define MIN_OPTIMAL_DOP 2 + +#endif diff -uprN postgresql-hll-2.14_old/include/include/optimizer/encoding.h postgresql-hll-2.14/include/include/optimizer/encoding.h --- postgresql-hll-2.14_old/include/include/optimizer/encoding.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/encoding.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * encoding.h + * + * IDENTIFICATION + * src/include/optimizer/encoding.h + * + * DESCRIPTION + * Declaration of externel APIs of Code/src/backend/utils/learn/encoding.cpp + * + * ------------------------------------------------------------------------- + */ + +#ifndef ENCODING_H +#define ENCODING_H + +#include "postgres.h" + +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" + +extern void PHGetPlanNodeText(Plan* plan, char** pname, bool* isRow, char** strategy, char** optionData); +extern void SaveDataToFile(const char* filename); +extern OperatorPlanInfo* ExtractOperatorPlanInfo(PlanState* result_plan, PlannedStmt* pstmt); + +#endif /* ENCODING_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_copy.h postgresql-hll-2.14/include/include/optimizer/geqo_copy.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_copy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_copy.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_copy.h + * prototypes for copy functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_copy.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_COPY_H +#define GEQO_COPY_H + +#include "optimizer/geqo.h" + +extern void geqo_copy(PlannerInfo* root, Chromosome* chromo1, Chromosome* chromo2, int string_length); + +#endif /* GEQO_COPY_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_gene.h postgresql-hll-2.14/include/include/optimizer/geqo_gene.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_gene.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_gene.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,42 @@ +/* ------------------------------------------------------------------------- + * + * geqo_gene.h + * genome representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_gene.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_GENE_H +#define GEQO_GENE_H + +#include "nodes/nodes.h" + +/* we presume that int instead of Relid + is o.k. for Gene; so don't change it! */ +typedef int Gene; + +typedef struct Chromosome { + Gene* string; + Cost worth; +} Chromosome; + +typedef struct Pool { + Chromosome* data; + int size; + int string_length; +} Pool; + +#endif /* GEQO_GENE_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo.h postgresql-hll-2.14/include/include/optimizer/geqo.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * geqo.h + * prototypes for various files in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_H +#define GEQO_H + +#include "nodes/relation.h" +#include "optimizer/geqo_gene.h" + +/* GEQO debug flag */ +/* recombination mechanism */ +#define ERX + +/* + * Configuration options + * + * If you change these, update backend/utils/misc/postgresql.conf.sample + */ +#define DEFAULT_GEQO_EFFORT 5 +#define MIN_GEQO_EFFORT 1 +#define MAX_GEQO_EFFORT 10 + +#define DEFAULT_GEQO_SELECTION_BIAS 2.0 +#define MIN_GEQO_SELECTION_BIAS 1.5 +#define MAX_GEQO_SELECTION_BIAS 2.0 + +/* + * Private state for a GEQO run --- accessible via root->join_search_private + */ +typedef struct { + List* initial_rels; /* the base relations we are joining */ + unsigned short random_state[3]; /* state for pg_erand48() */ +} GeqoPrivateData; + +/* routines in geqo_main.c */ +extern RelOptInfo* geqo(PlannerInfo* root, int number_of_rels, List* initial_rels); + +/* routines in geqo_eval.c */ +extern Cost geqo_eval(PlannerInfo* root, Gene* tour, int num_gene); +extern RelOptInfo* gimme_tree(PlannerInfo* root, Gene* tour, int num_gene); + +#endif /* GEQO_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_misc.h postgresql-hll-2.14/include/include/optimizer/geqo_misc.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_misc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_misc.h 2020-12-12 17:06:43.236347896 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * geqo_misc.h + * prototypes for printout routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_misc.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MISC_H +#define GEQO_MISC_H + +#include "optimizer/geqo_recombination.h" + +#ifdef GEQO_DEBUG + +extern void print_pool(FILE* fp, Pool* pool, int start, int stop); +extern void print_gen(FILE* fp, Pool* pool, int generation); +extern void print_edge_table(FILE* fp, Edge* edge_table, int num_gene); +#endif /* GEQO_DEBUG */ + +#endif /* GEQO_MISC_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_mutation.h postgresql-hll-2.14/include/include/optimizer/geqo_mutation.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_mutation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_mutation.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_mutation.h + * prototypes for mutation functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_mutation.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MUTATION_H +#define GEQO_MUTATION_H + +#include "optimizer/geqo.h" + +extern void geqo_mutation(PlannerInfo* root, Gene* tour, int num_gene); + +#endif /* GEQO_MUTATION_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_pool.h postgresql-hll-2.14/include/include/optimizer/geqo_pool.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_pool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_pool.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * geqo_pool.h + * pool representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_pool.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_POOL_H +#define GEQO_POOL_H + +#include "optimizer/geqo.h" + +extern Pool* alloc_pool(PlannerInfo* root, int pool_size, int string_length); +extern void free_pool(PlannerInfo* root, Pool* pool); + +extern void random_init_pool(PlannerInfo* root, Pool* pool); +extern Chromosome* alloc_chromo(PlannerInfo* root, int string_length); +extern void free_chromo(PlannerInfo* root, Chromosome* chromo); + +extern void spread_chromo(PlannerInfo* root, Chromosome* chromo, Pool* pool); + +extern void sort_pool(PlannerInfo* root, Pool* pool); + +#endif /* GEQO_POOL_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_random.h postgresql-hll-2.14/include/include/optimizer/geqo_random.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_random.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_random.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * geqo_random.h + * random number generator + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_random.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RANDOM_H +#define GEQO_RANDOM_H + +#include + +#include "optimizer/geqo.h" + +extern void geqo_set_seed(PlannerInfo* root, double seed); + +/* geqo_rand returns a random float value between 0 and 1 inclusive */ +extern double geqo_rand(PlannerInfo* root); + +/* geqo_randint returns integer value between lower and upper inclusive */ +#define geqo_randint(root, upper, lower) ((int)floor(geqo_rand(root) * (((upper) - (lower)) + 0.999999)) + (lower)) + +#endif /* GEQO_RANDOM_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_recombination.h postgresql-hll-2.14/include/include/optimizer/geqo_recombination.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_recombination.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_recombination.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,73 @@ +/* ------------------------------------------------------------------------- + * + * geqo_recombination.h + * prototypes for recombination in the genetic query optimizer + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_recombination.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RECOMBINATION_H +#define GEQO_RECOMBINATION_H + +#include "optimizer/geqo.h" + +extern void init_tour(PlannerInfo* root, Gene* tour, int num_gene); + +/* edge recombination crossover [ERX] */ +typedef struct Edge { + Gene edge_list[4]; /* list of edges */ + int total_edges; + int unused_edges; +} Edge; + +extern Edge* alloc_edge_table(PlannerInfo* root, int num_gene); +extern void free_edge_table(PlannerInfo* root, Edge* edge_table); + +extern float gimme_edge_table(PlannerInfo* root, Gene* tour1, Gene* tour2, int num_gene, Edge* edge_table); + +extern int gimme_tour(PlannerInfo* root, Edge* edge_table, Gene* new_gene, int num_gene); + +/* partially matched crossover [PMX] */ +#define DAD 1 /* indicator for gene from dad */ +#define MOM 0 /* indicator for gene from mom */ + +extern void pmx(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene); + +typedef struct City { + int tour2_position; + int tour1_position; + int used; + int select_list; +} City; + +extern City* alloc_city_table(PlannerInfo* root, int num_gene); +extern void free_city_table(PlannerInfo* root, City* city_table); + +/* cycle crossover [CX] */ +extern int cx(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene, City* city_table); + +/* position crossover [PX] */ +extern void px(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene, City* city_table); + +/* order crossover [OX1] according to Davis */ +extern void ox1(PlannerInfo* root, Gene* mom, Gene* dad, Gene* offspring, int num_gene, City* city_table); + +/* order crossover [OX2] according to Syswerda */ +extern void ox2(PlannerInfo* root, Gene* mom, Gene* dad, Gene* offspring, int num_gene, City* city_table); + +#endif /* GEQO_RECOMBINATION_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/geqo_selection.h postgresql-hll-2.14/include/include/optimizer/geqo_selection.h --- postgresql-hll-2.14_old/include/include/optimizer/geqo_selection.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/geqo_selection.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_selection.h + * prototypes for selection routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_selection.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_SELECTION_H +#define GEQO_SELECTION_H + +#include "optimizer/geqo.h" + +extern void geqo_selection(PlannerInfo* root, Chromosome* momma, Chromosome* daddy, Pool* pool, double bias); + +#endif /* GEQO_SELECTION_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/gtmfree.h postgresql-hll-2.14/include/include/optimizer/gtmfree.h --- postgresql-hll-2.14_old/include/include/optimizer/gtmfree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/gtmfree.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,10 @@ +#ifndef GTMFREE_H +#define GTMFREE_H + +typedef enum { + PERFECT_SHARDING_TYPE, + NOT_PERFECT_SHARDING_TYPE +} application_type_param; + +#endif + diff -uprN postgresql-hll-2.14_old/include/include/optimizer/joininfo.h postgresql-hll-2.14/include/include/optimizer/joininfo.h --- postgresql-hll-2.14_old/include/include/optimizer/joininfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/joininfo.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * joininfo.h + * prototypes for joininfo.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/joininfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef JOININFO_H +#define JOININFO_H + +#include "nodes/relation.h" + +extern bool have_relevant_joinclause(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); + +extern void add_join_clause_to_rels(PlannerInfo* root, RestrictInfo* restrictinfo, Relids join_relids); +extern void remove_join_clause_from_rels(PlannerInfo* root, RestrictInfo* restrictinfo, Relids join_relids); + +#endif /* JOININFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/learn.h postgresql-hll-2.14/include/include/optimizer/learn.h --- postgresql-hll-2.14_old/include/include/optimizer/learn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/learn.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,229 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * learn.h + * + * IDENTIFICATION + * src/include/optimizer/learn.h + * + * DESCRIPTION + * Public resources of Code/src/backend/utils/learn/ + * + * ------------------------------------------------------------------------- + */ + +#ifndef LEARN_H +#define LEARN_H + +#include "postgres.h" +#include "catalog/gs_opt_model.h" +#include "stdlib.h" + +#define RLSTM_TEMPLATE_NAME "rlstm" + +#define MAX_LEN_ONE_HOT 1024 +#define MAX_LEN_ROW 4096 +#define MAX_LEN_TEXT 100 +#define DOP_MAX_LEN 10 + +#define CONDITION_LEN 8 + +/* information of table gs_wlm_plan_operator_info */ +#define PLAN_OPT_TABLE_COL_NUM 16 +#define PLAN_OPT_TABLE_NAME "gs_wlm_plan_operator_info" + +/* The encoding map for operator name, this should be kept in the alphabatical order */ +#define LEN_ENCODE_OPTNAME 20 +#define TEXT_OPTNAME_ADAPTOR "ADAPTOR" +#define TEXT_OPTNAME_AGG "AGG" +#define TEXT_OPTNAME_APPEND "APPEND" +#define TEXT_OPTNAME_BITMAP "BITMAP" +#define TEXT_OPTNAME_EXTENSIBLE "EXTENSIBLE" +#define TEXT_OPTNAME_GROUP "GROUP" +#define TEXT_OPTNAME_HASH "HASH" +#define TEXT_OPTNAME_JOIN "JOIN" +#define TEXT_OPTNAME_LIMIT "LIMIT" +#define TEXT_OPTNAME_LOCKROWS "LOCKROWS" +#define TEXT_OPTNAME_MATERIALIZE "MATERIALIZE" +#define TEXT_OPTNAME_MODIFY_TABLE "MODIFY_TABLE" +#define TEXT_OPTNAME_PART_ITER "PART_ITER" +#define TEXT_OPTNAME_RECURSIVE_UNION "RECURSIVE_UNION" +#define TEXT_OPTNAME_RESULT "RESULT" +#define TEXT_OPTNAME_SCAN "SCAN" +#define TEXT_OPTNAME_SET_OP "SET_OP" +#define TEXT_OPTNAME_SORT "SORT" +#define TEXT_OPTNAME_STREAM "STREAM" +#define TEXT_OPTNAME_UNIQUE "UNIQUE" + +#define LEN_ENCODE_ORIENTATION 2 +#define TEXT_ORIENTATION_ROW "ROW" +#define TEXT_ORIENTATION_COL "COL" + +#define LEN_ENCODE_STRATEGY 13 +#define LEN_ENCODE_STRATEGY_ADAPTOR 0 +#define LEN_ENCODE_STRATEGY_AGG 4 +#define LEN_ENCODE_STRATEGY_APPEND 2 +#define LEN_ENCODE_STRATEGY_BITMAP 2 +#define LEN_ENCODE_STRATEGY_EXTENSIBLE 0 +#define LEN_ENCODE_STRATEGY_GROUP 0 +#define LEN_ENCODE_STRATEGY_HASH 0 +#define LEN_ENCODE_STRATEGY_JOIN 3 +#define LEN_ENCODE_STRATEGY_LIMIT 0 +#define LEN_ENCODE_STRATEGY_LOCKROWS 0 +#define LEN_ENCODE_STRATEGY_MATERIALIZE 0 +#define LEN_ENCODE_STRATEGY_MODIFY_TABLE 4 +#define LEN_ENCODE_STRATEGY_PART_ITER 0 +#define LEN_ENCODE_STRATEGY_RECURSIVE_UNION 0 +#define LEN_ENCODE_STRATEGY_RESULT 0 +#define LEN_ENCODE_STRATEGY_SCAN 13 +#define LEN_ENCODE_STRATEGY_SET_OP 2 +#define LEN_ENCODE_STRATEGY_SORT 0 +#define LEN_ENCODE_STRATEGY_STREAM 7 +#define LEN_ENCODE_STRATEGY_UNIQUE 0 +#define TEXT_STRATEGY_AGG_PLAIN "PLAIN" +#define TEXT_STRATEGY_AGG_SORTED "SORTED" +#define TEXT_STRATEGY_AGG_HASHED "HASHED" +#define TEXT_STRATEGY_AGG_WINDOW "WINDOW" +#define TEXT_STRATEGY_APPEND_PLAIN "PLAIN" +#define TEXT_STRATEGY_APPEND_MERGE "MERGE" +#define TEXT_STRATEGY_BITMAP_AND "AND" +#define TEXT_STRATEGY_BITMAP_OR "OR" +#define TEXT_STRATEGY_JOIN_NESTED_LOOP "NESTED_LOOP" +#define TEXT_STRATEGY_JOIN_MERGE "MERGE" +#define TEXT_STRATEGY_JOIN_HASH "HASH" +#define TEXT_STRATEGY_MODIFY_TABLE_INSERT "INSERT" +#define TEXT_STRATEGY_MODIFY_TABLE_UPDATE "UPDATE" +#define TEXT_STRATEGY_MODIFY_TABLE_DELETE "DELETE" +#define TEXT_STRATEGY_MODIFY_TABLE_MERGE "MERGE" +#define TEXT_STRATEGY_SCAN_SEQ "SEQ" +#define TEXT_STRATEGY_SCAN_INDEX "INDEX" +#define TEXT_STRATEGY_SCAN_INDEX_ONLY "INDEX_ONLY" +#define TEXT_STRATEGY_SCAN_BITMAP_INDEX "BITMAP_INDEX" +#define TEXT_STRATEGY_SCAN_BITMAP_HEAP "BITMAP_HEAP" +#define TEXT_STRATEGY_SCAN_TID "TID" +#define TEXT_STRATEGY_SCAN_SUBQUERY "SUBQUERY" +#define TEXT_STRATEGY_SCAN_FOREIGN "FOREIGN" +#define TEXT_STRATEGY_SCAN_DATA_NODE "DATA_NODE" +#define TEXT_STRATEGY_SCAN_FUNCTION "FUNCTION" +#define TEXT_STRATEGY_SCAN_VALUES "VALUES" +#define TEXT_STRATEGY_SCAN_CTE "CTE" +#define TEXT_STRATEGY_SCAN_WORK_TABLE "WORK_TABLE" +#define TEXT_STRATEGY_SET_OP_SORTED "SORTED" +#define TEXT_STRATEGY_SET_OP_HASHED "HASHED" +#define TEXT_STRATEGY_STREAM_BROADCAST "BROADCAST" +#define TEXT_STRATEGY_STREAM_REDISTRIBUTE "REDISTRIBUTE" +#define TEXT_STRATEGY_STREAM_GATHER "GATHER" +#define TEXT_STRATEGY_STREAM_ROUND_ROBIN "ROUND_ROBIN" +#define TEXT_STRATEGY_STREAM_SCAN_GATHER "SCAN_GATHER" +#define TEXT_STRATEGY_STREAM_PLAN_ROUTER "PLAN_ROUTER" +#define TEXT_STRATEGY_STREAM_HYBRID "HYBRID" + + +#define LEN_ENCODE_OPTION 7 +#define LEN_ENCODE_OPTION_ADAPTOR 0 +#define LEN_ENCODE_OPTION_AGG 0 +#define LEN_ENCODE_OPTION_APPEND 0 +#define LEN_ENCODE_OPTION_BITMAP 0 +#define LEN_ENCODE_OPTION_EXTENSIBLE 0 +#define LEN_ENCODE_OPTION_GROUP 0 +#define LEN_ENCODE_OPTION_HASH 0 +#define LEN_ENCODE_OPTION_JOIN 7 +#define LEN_ENCODE_OPTION_LIMIT 0 +#define LEN_ENCODE_OPTION_LOCKROWS 0 +#define LEN_ENCODE_OPTION_MATERIALIZE 0 +#define LEN_ENCODE_OPTION_MODIFY_TABLE 0 +#define LEN_ENCODE_OPTION_PART_ITER 0 +#define LEN_ENCODE_OPTION_RECURSIVE_UNION 0 +#define LEN_ENCODE_OPTION_RESULT 0 +#define LEN_ENCODE_OPTION_SCAN 3 +#define LEN_ENCODE_OPTION_SET_OP 0 +#define LEN_ENCODE_OPTION_SORT 0 +#define LEN_ENCODE_OPTION_STREAM 2 +#define LEN_ENCODE_OPTION_UNIQUE 0 +#define TEXT_OPTION_JOIN_INNER "INNER" +#define TEXT_OPTION_JOIN_LEFT "LEFT" +#define TEXT_OPTION_JOIN_FULL "FULL" +#define TEXT_OPTION_JOIN_RIGHT "RIGHT" +#define TEXT_OPTION_JOIN_SEMI "SEMI" +#define TEXT_OPTION_JOIN_ANTI "ANTI" +#define TEXT_OPTION_JOIN_UNIQUE "UNIQUE" +#define TEXT_OPTION_SCAN_PARTITIONED "PARTITIONED" +#define TEXT_OPTION_SCAN_DFS "DFS" +#define TEXT_OPTION_SCAN_SAMPLE "SAMPLE" +#define TEXT_OPTION_STREAM_LOCAL "LOCAL" +#define TEXT_OPTION_STREAM_SPLIT "SPLIT" + +#define LEN_ENCODE_CONDITION 12 +#define LEN_ENCODE_PROJECTION 12 + +#define TEXT_UNKNOWN "???" + +/* For python APIs */ +#define PORT_LEN 6 +#define PYTHON_SERVER_ROUTE_PRETRAIN "/configure" +#define PYTHON_SERVER_ROUTE_TRAIN "/train" +#define PYTHON_SERVER_ROUTE_PREPREDICT "/model_setup" +#define PYTHON_SERVER_ROUTE_PREDICT "/predict" +#define PYTHON_SERVER_ROUTE_POSTPREDICT "/model_release" +#define PYTHON_SERVER_ROUTE_TRACK "/track_process" +#define PYTHON_SERVER_HEADER_JSON "Content-Type: application/json" +#define TRAIN_DATASET_FILEPATH "/tmp/gs_encoding.csv" +#define PRED_DATASET_FILEPATH "/tmp/gs_pred.csv" +#define MAX_LEN_JSON 4096 + +typedef struct { + int64 query_id; + int32 plan_node_id; + int32 parent_node_id; + int64 startup_time; + int64 total_time; + int64 rows; + int32 peak_memory; + text encode[1]; +} TreeEncData; + +typedef TreeEncData *TreeEncPtr; + +typedef struct { + char optname[MAX_LEN_TEXT]; + int len_strategy; + char strategy[LEN_ENCODE_STRATEGY][MAX_LEN_TEXT]; + int len_option; + char options[LEN_ENCODE_OPTION][MAX_LEN_TEXT]; +} OptText; + +typedef struct { + int length; + int64 *startup_time; + int64 *total_time; + int64 *rows; + int64 *peak_memory; +} ModelPredictInfo; + +typedef struct { + int feature_size; + bool available; + int4 max[gs_opt_model_label_length]; + float4 acc[gs_opt_model_label_length]; +} ModelTrainInfo; + +typedef struct { + double startup_time_accuracy; + double total_time_accuracy; + double rows_accuracy; + double peak_memory_accuracy; +} ModelAccuracy; + +#endif /* LEARN_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/ml_model.h postgresql-hll-2.14/include/include/optimizer/ml_model.h --- postgresql-hll-2.14_old/include/include/optimizer/ml_model.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/ml_model.h 2020-12-12 17:06:43.237347909 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * ml_model.h + * + * IDENTIFICATION + * src/include/optimizer/ml_model.h + * + * DESCRIPTION + * Declaration of externel APIs of Code/src/backend/utils/learn/ml_model.cpp + * + * ------------------------------------------------------------------------- + */ + +#ifndef ML_MODEL_H +#define ML_MODEL_H + +#include "postgres.h" + +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" +#include "optimizer/learn.h" + +extern Form_gs_opt_model CheckModelTargets(const char* templateName, const char* modelName, char** labels, int* nLabel); +extern void ModelPredictForExplain(PlanState* root, char* fileName, const char* modelName); +extern char* PreModelPredict(PlanState* resultPlan, PlannedStmt* pstmt); +extern void SetNullPrediction(PlanState* resultPlan); +extern bool PredictorIsValid(const char* modelName); + +#endif /* ML_MODEL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/nodegroups.h postgresql-hll-2.14/include/include/optimizer/nodegroups.h --- postgresql-hll-2.14_old/include/include/optimizer/nodegroups.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/nodegroups.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,295 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodegroups.h + * Variables and functions used in multiple node group optimizer + * + * + * IDENTIFICATION + * src/include/optimizer/nodegroups.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEGROUPS_H +#define NODEGROUPS_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "nodes/bitmapset.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "nodes/pg_list.h" +#include "nodes/relation.h" +#include "pgxc/locator.h" +#include "optimizer/streamplan.h" +/* + * Computing node group options + */ +#define CNG_OPTION_OPTIMAL "optimal" +#define CNG_OPTION_QUERY "query" +#define CNG_OPTION_INSTALLATION "installation" + +/* + * virtual cluster node group options + */ +#define VNG_OPTION_ELASTIC_GROUP "elastic_group" + +/* + * Forbidden cost for agg and join unique + */ +#define NG_FORBIDDEN_COST -100.0 + +typedef struct NGroupInfo +{ + Oid oid; + Bitmapset* bms_nodeids; +}NGroupInfo; + +/* + * Modes for computing node group + * (1) optimal : the optimal mode in compute permission scale + * (2) query : the cost based mode in query scale + * (3) expect : the cost based mode with a expect node group + * (4) force : forced mode which compute in a specific node group + */ +typedef enum ComputingNodeGroupMode { + CNG_MODE_COSTBASED_OPTIMAL, + CNG_MODE_COSTBASED_QUERY, + CNG_MODE_COSTBASED_EXPECT, + CNG_MODE_FORCE +} ComputingNodeGroupMode; + +/*-------------------------------------------------------------------------*/ +/* Variables */ +/*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------*/ +/* Public functions */ +/* including: */ +/* (1) General functions */ +/* (2) Get general node groups */ +/* (3) Get distribution information of a node group */ +/* (4) Get distribution information of a base relation */ +/* (5) Get distribution information of a path or a plan */ +/* (6) Distribution data structure management */ +/* (7) Convert functions */ +/* (8) Heuristic methods */ +/* (9) Cost based algorithms */ +/* (10) Distribution management for specific operators */ +/* (11) Do shuffle between node groups if needed */ +/* (12) Compare functions, judge functions */ +/* (13) Other functions */ +/*-------------------------------------------------------------------------*/ + +/* ---------- + * General functions + * ---------- + */ +extern void ng_init_nodegroup_optimizer(Query* query); +extern void ng_backup_nodegroup_options(bool* p_is_multiple_nodegroup_scenario, + int* p_different_nodegroup_count, Distribution** p_in_redistribution_group_distribution, + Distribution** p_compute_permission_group_distribution, Distribution** p_query_union_set_group_distribution, + Distribution** p_single_node_distribution); +extern void ng_restore_nodegroup_options(bool p_is_multiple_nodegroup_scenario, + int p_different_nodegroup_count, Distribution* p_in_redistribution_group_distribution, + Distribution* p_compute_permission_group_distribution, Distribution* p_query_union_set_group_distribution, + Distribution* p_single_node_distribution); +extern ComputingNodeGroupMode ng_get_computing_nodegroup_mode(); + +/* ---------- + * Get general node groups + * ---------- + */ +/* installation group */ +extern char* ng_get_installation_group_name(); +extern Oid ng_get_installation_group_oid(); +extern Bitmapset* ng_get_installation_group_nodeids(); +extern Distribution* ng_get_installation_group_distribution(); +extern ExecNodes* ng_get_installation_group_exec_node(); +/* compute permission group */ +extern Distribution* ng_get_compute_permission_group_distribution(); +/* query union set group */ +extern Distribution* ng_get_query_union_set_group_distribution(List* baserel_rte_list, bool* baserels_in_same_group); +extern Distribution* ng_get_query_union_set_group_distribution(); +/* expected computing group */ +extern Distribution* ng_get_expected_computing_group_distribution(); +/* in_redistribution group */ +extern Oid ng_get_in_redistribution_group_oid(); +extern Distribution* ng_get_in_redistribution_group_distribution(); +extern Oid ng_get_redist_dest_group_oid(); +/* functional node group */ +extern Distribution* ng_get_default_computing_group_distribution(); +extern ExecNodes* ng_get_default_computing_group_exec_node(); +extern Distribution* ng_get_correlated_subplan_group_distribution(); +extern Distribution* ng_get_max_computable_group_distribution(); +extern Distribution* ng_get_single_node_distribution(); +/* ---------- + * Get distribution information of a node group + * ---------- + */ +extern Oid ng_get_group_groupoid(const char* group_name); +extern char* ng_get_group_group_name(Oid group_oid); +extern char* ng_get_dist_group_name(Distribution *distribution); +extern Bitmapset* ng_get_group_nodeids(const Oid groupoid); +extern Distribution* ng_get_group_distribution(const Oid groupoid); +extern Distribution* ng_get_group_distribution(const char* group_name); + +/* ---------- + * Get distribution information of a base relation + * ---------- + */ +extern Oid ng_get_baserel_groupoid(Oid tableoid, char relkind); +extern Bitmapset* ng_get_baserel_data_nodeids(Oid tableoid, char relkind); +extern Distribution* ng_get_baserel_data_distribution(Oid tableoid, char relkind); +extern unsigned int ng_get_baserel_num_data_nodes(Oid tableoid, char relkind); + +/* ---------- + * Get distribution information of a path or a plan + * ---------- + */ +/* distribution of Path */ +extern Bitmapset* ng_get_dest_nodeids(Path* path); +extern Distribution* ng_get_dest_distribution(Path* path); +/* distribution of Plan */ +extern Bitmapset* ng_get_dest_nodeids(Plan* plan); +extern Distribution* ng_get_dest_distribution(Plan* plan); +extern ExecNodes* ng_get_dest_execnodes(Plan* plan); +/* number of data nodes of Path, Plan and RelOptInfo */ +extern unsigned int ng_get_dest_num_data_nodes(Path* path); +extern unsigned int ng_get_dest_num_data_nodes(Plan* plan); +extern unsigned int ng_get_dest_num_data_nodes(RelOptInfo* rel); +extern unsigned int ng_get_dest_num_data_nodes(PlannerInfo* root, RelOptInfo* rel); +/* other information of Plan */ +extern char ng_get_dest_locator_type(Plan* plan); +extern List* ng_get_dest_distribute_keys(Plan* plan); + +/* ---------- + * Distribution data structure management + * ---------- + */ +extern Distribution* ng_copy_distribution(Distribution* src_distribution); +extern void ng_copy_distribution(Distribution* dest_distribution, const Distribution* src_distribution); +extern void ng_set_distribution(Distribution* dest_distribution, Distribution* src_distribution); +extern Distribution* ng_get_overlap_distribution(Distribution* distribution_1, Distribution* distribution_2); +extern Distribution* ng_get_union_distribution(Distribution* distribution_1, Distribution* distribution_2); +extern Distribution* ng_get_union_distribution_recycle(Distribution* distribution_1, + Distribution* distribution_2); +extern Distribution* ng_get_random_single_dn_distribution(Distribution* distribution); + +/* ---------- + * Convert functions + * ---------- + */ +/* node id (index) and node oid */ +extern int ng_convert_to_nodeid(Oid nodeoid); +extern Oid ng_convert_to_nodeoid(int nodeid); +/* node list */ +extern List* ng_convert_to_nodeid_list(Bitmapset* bms_nodeids); +/* nodeids */ +extern Bitmapset* ng_convert_to_nodeids(ExecNodes* exec_nodes); +extern Bitmapset* ng_convert_to_nodeids(List* nodeid_list); +/* Distribution */ +extern Distribution* ng_convert_to_distribution(List* nodeid_list); +extern Distribution* ng_convert_to_distribution(ExecNodes* exec_nodes); +/* ExecNodes */ +extern ExecNodes* ng_convert_to_exec_nodes( + Distribution* distribution, char locator_type, RelationAccessType access_type); + + +/* For geting suited candidate distributions to reduce search spaces. example: + * Single node distribution is not good for big data computing. + * Multi node distribution is not good for small data computing. + */ +enum DistrbutionPreferenceType { + DPT_ALL, + DPT_SHUFFLE, + DPT_SINGLE +}; + +/* + * Heuristic methods + */ +/* Join */ +extern List* ng_get_join_candidate_distribution_list(Path* outer_path, Path* inner_path, DistrbutionPreferenceType type); +extern List* ng_get_join_candidate_distribution_list(Path* outer_path, Path* inner_path, bool is_correlated, DistrbutionPreferenceType type); +/* Agg */ +extern List* ng_get_agg_candidate_distribution_list(Plan* plan, bool is_correlated, DistrbutionPreferenceType type); +/* SetOp */ +extern List* ng_get_setop_candidate_distribution_list(List* subPlans, bool is_correlated); + +/* + * Cost based algorithms + */ +extern double ng_get_nodegroup_stream_weight(unsigned int producer_num_dn, unsigned int consumer_num_dn); +extern Cost ng_calculate_setop_branch_stream_cost( + Plan* subPlan, unsigned int producer_num_datanodes, unsigned int consumer_num_datanodes); + +/* + * Distribution management for specific operators + */ +/* Join */ +extern Distribution* ng_get_join_distribution(Path* outer_path, Path* inner_path); +extern Distribution* ng_get_join_data_distribution(Plan* lefttree, Plan* righttree, List* nodeid_list); +/* SetOp */ +extern Distribution* ng_get_union_distribution_for_union_all(List* subPlans); +extern Distribution* ng_get_best_setop_distribution(List* subPlans, bool isUnionAll, bool is_correlated); + +/* + * Do shuffle between node groups if needed + */ +extern void ng_stream_side_paths_for_replicate(PlannerInfo* root, Path** outer_path, Path** inner_path, + JoinType jointype, bool is_mergejoin, Distribution* target_distribution); +extern Path* ng_stream_non_broadcast_side_for_join(PlannerInfo* root, Path* non_stream_path, JoinType save_jointype, + List* non_stream_pathkeys, bool is_replicate, bool stream_outer, Distribution* target_distribution); +extern Plan* ng_agg_force_shuffle(PlannerInfo* root, List* groupcls, Plan* subplan, List* tlist, Path* subpath); + +/* + * Compare functions, judge functions + */ +extern bool ng_is_multiple_nodegroup_scenario(); +extern bool ng_is_all_in_installation_nodegroup_scenario(); +extern bool ng_enable_nodegroup_explain(); +extern bool ng_is_valid_group_name(const char* group_name); +extern bool ng_is_special_group(Distribution* distribution); +extern bool ng_is_same_group(Bitmapset* bms_nodeids_1, Bitmapset* bms_nodeids_2); +extern bool ng_is_same_group(List* nodeid_list_1, List* nodeid_list_2); +extern bool ng_is_same_group(ExecNodes* exec_nodes, Bitmapset* bms_nodeids); +extern bool ng_is_same_group(Distribution* distribution_1, Distribution* distribution_2); +extern bool ng_is_exec_on_subset_nodes(ExecNodes* en1, ExecNodes* en2); +extern bool ng_is_shuffle_needed(Distribution* current_distribution, Distribution* target_distribution); +extern bool ng_is_shuffle_needed(PlannerInfo* root, Path* path, Distribution* target_distribution); +extern bool ng_is_distribute_key_valid(PlannerInfo* root, List* distribute_key, List* target_list); + +/* + * node group cache hash table interface + */ +extern void ngroup_info_hash_create(); +extern Bitmapset* ngroup_info_hash_search(Oid ngroup_oid); +extern void ngroup_info_hash_insert(Oid ngroup_oid, Bitmapset * bms_node_ids); +extern void ngroup_info_hash_delete(Oid ngroup_oid); + +/* + * Other functions + */ +extern Bitmapset* ng_get_single_node_group_nodeids(); +extern Distribution* ng_get_single_node_group_distribution(); +extern ExecNodes* ng_get_single_node_group_exec_node(); +extern char* dist_to_str(Distribution *distribution); +extern void _outBitmapset(StringInfo str, Bitmapset* bms); +extern bool ng_is_single_node_group_distribution(Distribution* distribution); +extern int ng_get_different_nodegroup_count(); +#endif /* NODEGROUPS_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/optimizerdebug.h postgresql-hll-2.14/include/include/optimizer/optimizerdebug.h --- postgresql-hll-2.14_old/include/include/optimizer/optimizerdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/optimizerdebug.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * optimizerdebug.h + * prototypes for optimizerdebug.h + * + * + * IDENTIFICATION + * src/include/optimizer/optimizerdebug.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OPTIMIZERDEBUG_H +#define OPTIMIZERDEBUG_H + +#include "nodes/relation.h" +#include "nodes/print.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" + +extern char* debug1_print_relids(Relids relids, List* rtable); + +extern void debug1_print_rel(PlannerInfo* root, RelOptInfo* rel); +extern char* debug1_print_path(PlannerInfo* root, Path* path, int indent); +extern void debug_print_hashjoin_detail(PlannerInfo* root, HashPath* path, double virtualbuckets, + Selectivity innerbucketsize, double outer_scan_ratio, Cost startup_cost, Cost total_cost); +extern void debug_print_agg_detail(PlannerInfo* root, AggStrategy aggstrategy, SAggMethod aggmethod, Path* path1, + Path* path2 = NULL, Path* path3 = NULL, Path* path4 = NULL, Path* path5 = NULL); + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); +#define OPT_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_OPT)) { \ + ereport(level, (errmodule(MOD_OPT), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#endif /* OPTIMIZERDEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pathnode.h postgresql-hll-2.14/include/include/optimizer/pathnode.h --- postgresql-hll-2.14_old/include/include/optimizer/pathnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pathnode.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,211 @@ +/* ------------------------------------------------------------------------- + * + * pathnode.h + * prototypes for pathnode.c, relnode.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/pathnode.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PATHNODE_H +#define PATHNODE_H + +#include "nodes/relation.h" +#include "optimizer/streamplan.h" + +/* global path */ +#define MAX_PATH_NUM 10 /* the maximum path number of super set distribute key */ + +/* To keep the plan stability, we should compare path costs with fuzzy factor */ +#define FUZZY_FACTOR 1.01 +#define SMALL_FUZZY_FACTOR 1.0000000001 + +typedef enum { + COSTS_EQUAL, /* path costs are fuzzily equal */ + COSTS_BETTER1, /* first path is cheaper than second */ + COSTS_BETTER2, /* second path is cheaper than first */ + COSTS_DIFFERENT /* neither path dominates the other on cost */ +} PathCostComparison; + +typedef enum SJoinUniqueMethod { + REDISTRIBUTE_UNIQUE, + UNIQUE_REDISTRIBUTE, + UNIQUE_REDISTRIBUTE_UNIQUE, + REDISTRIBUTE_UNIQUE_REDISTRIBUTE_UNIQUE +} SJoinUniqueMethod; + +/* + * prototypes for pathnode.c + */ +extern int compare_path_costs(Path* path1, Path* path2, CostSelector criterion); +extern int compare_fractional_path_costs(Path* path1, Path* path2, double fraction); +extern void set_cheapest(RelOptInfo* parent_rel, PlannerInfo* root = NULL); +extern Path* get_cheapest_path(PlannerInfo* root, RelOptInfo* rel, const double* agg_groups, bool has_groupby); +extern Path* find_hinted_path(Path* current_path); +extern void add_path(PlannerInfo* root, RelOptInfo* parent_rel, Path* new_path); +extern bool add_path_precheck( + RelOptInfo* parent_rel, Cost startup_cost, Cost total_cost, List* pathkeys, Relids required_outer); + +extern Path* create_seqscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer, int dop = 1); +extern Path* create_cstorescan_path(PlannerInfo* root, RelOptInfo* rel, int dop = 1); +#ifdef ENABLE_MULTIPLE_NODES +extern Path *create_tsstorescan_path(PlannerInfo * root,RelOptInfo * rel, int dop = 1); +#endif /* ENABLE_MULTIPLE_NODES */ +extern IndexPath* create_index_path(PlannerInfo* root, IndexOptInfo* index, List* indexclauses, List* indexclausecols, + List* indexorderbys, List* indexorderbycols, List* pathkeys, ScanDirection indexscandir, bool indexonly, + Relids required_outer, Bitmapset *upper_params, double loop_count); +extern Path* build_seqScanPath_by_indexScanPath(PlannerInfo* root, Path* index_path); +extern bool CheckBitmapQualIsGlobalIndex(Path* bitmapqual); +extern bool CheckBitmapHeapPathContainGlobalOrLocal(Path* bitmapqual); +extern bool check_bitmap_heap_path_index_unusable(Path* bitmapqual, RelOptInfo* baserel); +extern bool is_partitionIndex_Subpath(Path* subpath); +extern bool is_pwj_path(Path* pwjpath); +extern BitmapHeapPath* create_bitmap_heap_path(PlannerInfo* root, RelOptInfo* rel, Path* bitmapqual, + Relids required_outer, Bitmapset* required_upper, double loop_count); +extern BitmapAndPath* create_bitmap_and_path(PlannerInfo* root, RelOptInfo* rel, List* bitmapquals); +extern BitmapOrPath* create_bitmap_or_path(PlannerInfo* root, RelOptInfo* rel, List* bitmapquals); +extern TidPath* create_tidscan_path(PlannerInfo* root, RelOptInfo* rel, List* tidquals); +extern AppendPath* create_append_path(PlannerInfo* root, RelOptInfo* rel, List* subpaths, Relids required_outer); +extern MergeAppendPath* create_merge_append_path( + PlannerInfo* root, RelOptInfo* rel, List* subpaths, List* pathkeys, Relids required_outer); +extern ResultPath* create_result_path(PlannerInfo *root, RelOptInfo *rel, List* quals, Path* subpath = NULL, Bitmapset *upper_params = NULL); +extern MaterialPath* create_material_path(Path* subpath, bool materialize_all = false); +extern UniquePath* create_unique_path(PlannerInfo* root, RelOptInfo* rel, Path* subpath, SpecialJoinInfo* sjinfo); +extern Path* create_subqueryscan_path(PlannerInfo* root, RelOptInfo* rel, List* pathkeys, Relids required_outer, List *subplan_params); +extern Path* create_subqueryscan_path_reparam(PlannerInfo* root, RelOptInfo* rel, List* pathkeys, Relids required_outer, List *subplan_params); +extern Path* create_functionscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer); +extern Path* create_valuesscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer); +extern Path* create_ctescan_path(PlannerInfo* root, RelOptInfo* rel); +extern Path* create_worktablescan_path(PlannerInfo* root, RelOptInfo* rel); +extern ForeignPath* create_foreignscan_path(PlannerInfo* root, RelOptInfo* rel, Cost startup_cost, Cost total_cost, + List* pathkeys, Relids required_outer, List* fdw_private, int dop = 1); +extern Relids calc_nestloop_required_outer(Path* outer_path, Path* inner_path); +extern Relids calc_non_nestloop_required_outer(Path* outer_path, Path* inner_path); + +extern NestPath* create_nestloop_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, List* pathkeys, Relids required_outer, int dop = 1); + +extern MergePath* create_mergejoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, Path* outer_path, Path* inner_path, List* restrict_clauses, + List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, List* innersortkeys); + +extern HashPath* create_hashjoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, Relids required_outer, List* hashclauses, int dop = 1); + +extern Path* reparameterize_path(PlannerInfo* root, Path* path, Relids required_outer, double loop_count); + +/* + * prototypes for relnode.c + */ +extern void setup_simple_rel_arrays(PlannerInfo* root); +extern RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind); +extern RelOptInfo* find_base_rel(PlannerInfo* root, int relid); +extern RelOptInfo* find_join_rel(PlannerInfo* root, Relids relids); +extern void remove_join_rel(PlannerInfo *root, RelOptInfo *rel); +extern RelOptInfo* build_join_rel(PlannerInfo* root, Relids joinrelids, RelOptInfo* outer_rel, RelOptInfo* inner_rel, + SpecialJoinInfo* sjinfo, List** restrictlist_ptr); +extern AppendRelInfo* find_childrel_appendrelinfo(PlannerInfo* root, RelOptInfo* rel); +extern ParamPathInfo* get_baserel_parampathinfo(PlannerInfo* root, RelOptInfo* baserel, Relids required_outer, Bitmapset *upper_params = NULL); +extern ParamPathInfo* get_subquery_parampathinfo(PlannerInfo* root, RelOptInfo* baserel, Relids required_outer, Bitmapset *upper_params = NULL); +extern ParamPathInfo* get_joinrel_parampathinfo(PlannerInfo* root, RelOptInfo* joinrel, Path* outer_path, + Path* inner_path, SpecialJoinInfo* sjinfo, Relids required_outer, List** restrict_clauses); +extern ParamPathInfo* get_appendrel_parampathinfo(RelOptInfo* appendrel, Relids required_outer, Bitmapset* upper_params); +extern void get_distribute_keys(PlannerInfo* root, List* joinclauses, Path* outer_path, Path* inner_path, + double* skew_outer, double* skew_inner, List** distribute_keys_outer, List** distribute_keys_inner, + List* desired_keys, bool exact_match); +extern bool is_distribute_need_on_joinclauses(PlannerInfo* root, List* side_distkeys, List* joinclauses, + const RelOptInfo* side_rel, const RelOptInfo* other_rel, List** rrinfo); + +extern void add_hashjoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrictlist, Relids required_outer, List* hashclauses, Distribution* target_distribution); + +extern void add_nestloop_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, List* pathkeys, Relids required_outer, Distribution* target_distribution); + +extern void add_mergejoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, Path* outer_path, Path* inner_path, List* restrict_clauses, + List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, List* innersortkeys, + Distribution* target_distribution); +extern bool equal_distributekey(PlannerInfo* root, List* distribute_key1, List* distribute_key2); +extern bool judge_node_compatible(PlannerInfo* root, Node* n1, Node* n2); +extern List* build_superset_keys_for_rel( + PlannerInfo* root, RelOptInfo* rel, RelOptInfo* outerrel, RelOptInfo* innerrel, JoinType jointype); +extern List* remove_duplicate_superset_keys(List* join_dis_key_list); +extern List* generate_join_implied_equalities_normal( + PlannerInfo* root, EquivalenceClass* ec, Relids join_relids, Relids outer_relids, Relids inner_relids); + +#ifdef STREAMPLAN +/* + * Determine which distributekey can be treated as the joinpath's distributekey + * 1. outer path's distributekey can be treated as the joinpath's distributekey if LHS_join returns true + * 2. inner path's distributekey can be treated as the joinpath's distributekey if RHS_join returns true + */ +#define LHS_join(jointype) \ + (JOIN_INNER == jointype || JOIN_LEFT == jointype || JOIN_SEMI == jointype || JOIN_ANTI == jointype || \ + JOIN_LEFT_ANTI_FULL == jointype) +#define RHS_join(jointype) \ + (JOIN_INNER == jointype || JOIN_RIGHT_ANTI == jointype || JOIN_RIGHT == jointype || JOIN_RIGHT_SEMI == jointype || \ + JOIN_RIGHT_ANTI_FULL == jointype) + +/* + * Check if we can broadcast side path + * 1. inner path can be broadcast if can_broadcast_inner returns true + * 2. outer path can be broadcast if can_broadcast_outer returns true + */ +#define can_broadcast_inner(jointype, save_jointype, replicate_outer, diskeys_outer, path_outer) \ + (LHS_join(jointype) && (save_jointype != JOIN_UNIQUE_OUTER || replicate_outer)) +#define can_broadcast_outer(jointype, save_jointype, replicate_inner, diskeys_inner, path_inner) \ + (RHS_join(jointype) && (save_jointype != JOIN_UNIQUE_INNER || replicate_inner)) + +extern bool find_ec_memeber_for_var(EquivalenceClass* ec, Node* key); +extern double get_skew_ratio(double distinct_value); +extern Path* stream_side_path(PlannerInfo* root, Path* path, JoinType jointype, bool is_replicate, + StreamType stream_type, List* distribute_key, List* pathkeys, bool is_inner, double skew, + Distribution* target_distribution, ParallelDesc* smpDesc = NULL); +extern double get_node_mcf(PlannerInfo* root, Node* v, double rows); +extern bool needs_agg_stream(PlannerInfo* root, List* tlist, List* distribute_targetlist, Distribution* distribution = NULL); +extern bool is_replicated_path(Path* path); +extern void adjust_rows_according_to_hint(HintState* hstate, RelOptInfo* rel, Relids subrelids = NULL); + +extern bool is_subplan_exec_on_coordinator(Path* path); +extern void set_hint_value(RelOptInfo* join_rel, Path* new_path, HintState* hstate); +extern void debug1_print_new_path(PlannerInfo* root, Path* path, bool small_fuzzy_factor_is_used); +extern void debug1_print_compare_result(PathCostComparison costcmp, PathKeysComparison keyscmp, BMS_Comparison outercmp, + double rowscmp, PlannerInfo* root, Path* path, bool small_fuzzy_factor_is_used); +extern PathCostComparison compare_path_costs_fuzzily(Path* path1, Path* path2, double fuzz_factor); +extern Node* get_distribute_node(PlannerInfo* root, RestrictInfo* rinfo, RelOptInfo* parent_rel, bool local_left, + double* skew_multiple, List* desired_keys, Node** exact_match_keys); +extern bool is_exact_match_keys_full(Node** match_keys, int length); +extern List* locate_distribute_key(JoinType jointype, List* outer_distributekey, List* inner_distributekey, + List* desired_key = NIL, bool exact_match = false); +extern SJoinUniqueMethod get_optimal_join_unique_path(PlannerInfo* root, Path* path, StreamType stream_type, + List* distribute_key, List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc); +extern Node* join_clause_get_join_key(Node* join_clause, bool is_var_on_left); + +extern Path* get_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, bool cost_only = false); + +extern Path* get_unique_redist(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc); + +extern Path* get_unique_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, bool cost_only = false); + +extern Path* get_redist_unique_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, + List* distribute_key, List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, + bool cost_only = false); + +extern bool equivalence_class_overlap(PlannerInfo* root, Relids outer_relids, Relids inner_relids); + +extern void debug3_print_two_relids(Relids first_relids, Relids second_relids, PlannerInfo* root, StringInfoData* buf); + +#endif +#endif /* PATHNODE_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/paths.h postgresql-hll-2.14/include/include/optimizer/paths.h --- postgresql-hll-2.14_old/include/include/optimizer/paths.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/paths.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,170 @@ +/* ------------------------------------------------------------------------- + * + * paths.h + * prototypes for various files in optimizer/path + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/paths.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PATHS_H +#define PATHS_H + +#include "nodes/relation.h" + +typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *rel, + Index rti, + RangeTblEntry *rte); +extern THR_LOCAL PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook; + +typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + SpecialJoinInfo *sjinfo, + Relids param_source_rels, + SemiAntiJoinFactors *semifactors, + List *restrictlist); +extern THR_LOCAL PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook; + +extern RelOptInfo* make_one_rel(PlannerInfo* root, List* joinlist); +extern RelOptInfo* standard_join_search(PlannerInfo* root, int levels_needed, List* initial_rels); + +extern void set_rel_size(PlannerInfo* root, RelOptInfo* rel, Index rti, RangeTblEntry* rte); + +#ifdef OPTIMIZER_DEBUG +extern void debug_print_rel(PlannerInfo* root, RelOptInfo* rel); +#endif + +/* + * indxpath.c + * routines to generate index paths + */ +extern void create_index_paths(PlannerInfo* root, RelOptInfo* rel); +extern List* generate_bitmap_or_paths( + PlannerInfo* root, RelOptInfo* rel, List* clauses, List* other_clauses, bool restriction_only); +extern List* GenerateBitmapOrPathsUseGPI( + PlannerInfo* root, RelOptInfo* rel, const List* clauses, List* other_clauses, bool restriction_only); +extern bool relation_has_unique_index_for( + PlannerInfo* root, RelOptInfo* rel, List* restrictlist, List* exprlist, List* oprlist); +extern bool eclass_member_matches_indexcol( + EquivalenceClass* ec, EquivalenceMember* em, IndexOptInfo* index, int indexcol); +extern bool match_index_to_operand(Node* operand, int indexcol, IndexOptInfo* index); +extern void expand_indexqual_conditions( + IndexOptInfo* index, List* indexclauses, List* indexclausecols, List** indexquals_p, List** indexqualcols_p); +extern void check_partial_indexes(PlannerInfo* root, RelOptInfo* rel); +extern Expr* adjust_rowcompare_for_index( + RowCompareExpr* clause, IndexOptInfo* index, int indexcol, List** indexcolnos, bool* var_on_left_p); +/* + * Check index path whether use global partition index to scan + */ +inline bool CheckIndexPathUseGPI(IndexPath* ipath) +{ + return ipath->indexinfo->isGlobal; +} + + +/* + * orindxpath.c + * additional routines for indexable OR clauses + */ +extern bool create_or_index_quals(PlannerInfo* root, RelOptInfo* rel); + +/* + * tidpath.h + * routines to generate tid paths + */ +extern void create_tidscan_paths(PlannerInfo* root, RelOptInfo* rel); + +/* + * joinpath.c + * routines to create join paths + */ +extern void add_paths_to_joinrel(PlannerInfo* root, RelOptInfo* joinrel, RelOptInfo* outerrel, RelOptInfo* innerrel, + JoinType jointype, SpecialJoinInfo* sjinfo, List* restrictlist); +extern bool clause_sides_match_join(RestrictInfo* rinfo, RelOptInfo* outerrel, RelOptInfo* innerrel); + +#ifdef PGXC +/* + * rquerypath.c + * routines to create RemoteQuery paths + */ +extern bool create_plainrel_rqpath(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); +extern void create_joinrel_rqpath(PlannerInfo* root, RelOptInfo* joinrel, RelOptInfo* outerrel, RelOptInfo* innerrel, + List* restrictlist, JoinType jointype, SpecialJoinInfo* sjinfo); +#endif /* PGXC */ + +/* + * joinrels.c + * routines to determine which relations to join + */ +extern void join_search_one_level(PlannerInfo* root, int level); +extern RelOptInfo* make_join_rel(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); +extern bool have_join_order_restriction(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); + +/* + * equivclass.c + * routines for managing EquivalenceClasses + */ +extern bool process_equivalence(PlannerInfo* root, RestrictInfo* restrictinfo, bool below_outer_join); +extern Expr* canonicalize_ec_expression(Expr* expr, Oid req_type, Oid req_collation); +extern void reconsider_outer_join_clauses(PlannerInfo* root); +extern EquivalenceClass* get_eclass_for_sort_expr(PlannerInfo* root, Expr* expr, List* opfamilies, Oid opcintype, + Oid collation, Index sortref, bool groupSet, Relids rel, bool create_it); +extern void generate_base_implied_equalities(PlannerInfo* root); +extern void generate_base_implied_qualities(PlannerInfo* root); +extern List* generate_join_implied_equalities( + PlannerInfo* root, Relids join_relids, Relids outer_relids, RelOptInfo* inner_rel); +extern List* generate_join_implied_equalities_for_ecs( + PlannerInfo* root, List* eclasses, Relids join_relids, Relids outer_relids, RelOptInfo* inner_rel); +extern bool exprs_known_equal(PlannerInfo* root, Node* item1, Node* item2); +extern void add_child_rel_equivalences( + PlannerInfo* root, AppendRelInfo* appinfo, RelOptInfo* parent_rel, RelOptInfo* child_rel); +extern void mutate_eclass_expressions(PlannerInfo* root, Node* (*mutator)(), void* context, bool include_child_exprs); +extern List* generate_implied_equalities_for_indexcol(PlannerInfo* root, IndexOptInfo* index, int indexcol, Relids prohibited_rels); +extern bool have_relevant_eclass_joinclause(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); +extern bool has_relevant_eclass_joinclause(PlannerInfo* root, RelOptInfo* rel1); +extern bool eclass_useful_for_merging(EquivalenceClass* eclass, RelOptInfo* rel); +extern bool is_redundant_derived_clause(RestrictInfo* rinfo, List* clauselist); + +/* + * pathkeys.c + * utilities for matching and building path keys + */ +typedef enum { + PATHKEYS_EQUAL, /* pathkeys are identical */ + PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */ + PATHKEYS_BETTER2, /* vice versa */ + PATHKEYS_DIFFERENT /* neither pathkey includes the other */ +} PathKeysComparison; + +extern List* canonicalize_pathkeys(PlannerInfo* root, List* pathkeys); +extern PathKeysComparison compare_pathkeys(List* keys1, List* keys2); +extern bool pathkeys_contained_in(List* keys1, List* keys2); +extern Path* get_cheapest_path_for_pathkeys( + List* paths, List* pathkeys, Relids required_outer, CostSelector cost_criterion); +extern Path* get_cheapest_fractional_path_for_pathkeys( + List* paths, List* pathkeys, Relids required_outer, double fraction); +extern List* build_index_pathkeys(PlannerInfo* root, IndexOptInfo* index, ScanDirection scandir); +extern List* convert_subquery_pathkeys(PlannerInfo* root, RelOptInfo* rel, List* subquery_pathkeys); +extern List* build_join_pathkeys(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, List* outer_pathkeys); +extern List* make_pathkeys_for_sortclauses(PlannerInfo* root, List* sortclauses, List* tlist, bool canonicalize); +extern void initialize_mergeclause_eclasses(PlannerInfo* root, RestrictInfo* restrictinfo); +extern void update_mergeclause_eclasses(PlannerInfo* root, RestrictInfo* restrictinfo); +extern List* find_mergeclauses_for_outer_pathkeys(PlannerInfo* root, List* pathkeys, List* restrictinfos); +extern List* select_outer_pathkeys_for_merge(PlannerInfo* root, List* mergeclauses, RelOptInfo* joinrel); +extern List* make_inner_pathkeys_for_merge(PlannerInfo* root, List* mergeclauses, List* outer_pathkeys); +extern List* trim_mergeclauses_for_inner_pathkeys(PlannerInfo* root, List* mergeclauses, List* pathkeys); + +extern List* truncate_useless_pathkeys(PlannerInfo* root, RelOptInfo* rel, List* pathkeys); +extern bool has_useful_pathkeys(PlannerInfo* root, RelOptInfo* rel); +extern void set_path_rows(Path* path, double rows, double multiple = 1); +extern EquivalenceClass* get_expr_eqClass(PlannerInfo* root, Expr* expr); +extern void delete_eq_member(PlannerInfo* root, List* tlist, List* collectiveGroupExpr); +#endif /* PATHS_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pgxcplan.h postgresql-hll-2.14/include/include/optimizer/pgxcplan.h --- postgresql-hll-2.14_old/include/include/optimizer/pgxcplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pgxcplan.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * pgxcplan.h + * Postgres-XC specific planner interfaces and structures. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxcplan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXCPLANNER_H +#define PGXCPLANNER_H + +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "nodes/primnodes.h" +#include "pgxc/locator.h" +#include "tcop/dest.h" +#include "nodes/relation.h" +#include "optimizer/pgxc_plan_remote.h" + +typedef struct VecRemoteQuery : public RemoteQuery { +} VecRemoteQuery; + +extern PlannedStmt* pgxc_planner(Query* query, int cursorOptions, ParamListInfo boundParams); +extern List* AddRemoteQueryNode(List* stmts, const char* queryString, RemoteQueryExecType remoteExecType, bool is_temp); +extern bool pgxc_query_contains_temp_tables(List* queries); +extern bool pgxc_query_contains_utility(List* queries); +extern void pgxc_rqplan_adjust_tlist(PlannerInfo* root, RemoteQuery* rqplan, bool gensql = true); + +extern Plan* pgxc_make_modifytable(PlannerInfo* root, Plan* topplan); +extern RangeTblEntry* make_dummy_remote_rte(char* relname, Alias* alias); +extern List* pgxc_get_dist_var(Index varno, RangeTblEntry* rte, List* tlist); +extern CombineType get_plan_combine_type(CmdType commandType, char baselocatortype); +extern ExecNodes* pgxc_is_join_shippable(ExecNodes* inner_en, ExecNodes* outer_en, bool inner_unshippable_tlist, + bool outer_shippable_tlist, JoinType jointype, Node* join_quals); +extern bool contains_temp_tables(List* rtable); +extern List* process_agg_targetlist(PlannerInfo* root, List** local_tlist); +extern bool containing_ordinary_table(Node* node); +extern Param* pgxc_make_param(int param_num, Oid param_type); +extern Query* pgxc_build_shippable_query_recurse( + PlannerInfo* root, RemoteQueryPath* rqpath, List** unshippable_quals, List** rep_tlist); + +extern void preprocess_const_params(PlannerInfo* root, Node* jtnode); + +#endif /* PGXCPLANNER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pgxc_plan_remote.h postgresql-hll-2.14/include/include/optimizer/pgxc_plan_remote.h --- postgresql-hll-2.14_old/include/include/optimizer/pgxc_plan_remote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pgxc_plan_remote.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_plan_remote.h + * Postgres-XC specific planner interfaces and structures for remote query. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxc_plan_remote.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_PLANN_REMOTE_H +#define PGXC_PLANN_REMOTE_H + +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "nodes/primnodes.h" +#include "pgxc/locator.h" +#include "tcop/dest.h" +#include "nodes/relation.h" + +/* For sorting within RemoteQuery handling */ +/* + * It is pretty much like Sort, but without Plan. We may use Sort later. + */ +typedef struct { + NodeTag type; + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* sortCollations; + bool* nullsFirst; /* NULLS FIRST/LAST directions */ + bool sortToStore; /* If should store tuples in sortstore into tuplestore. */ + /* For with hold cursor, we should do so. */ +} SimpleSort; + +typedef enum { + COMBINE_TYPE_NONE, /* it is known that no row count, do not parse */ + COMBINE_TYPE_SUM, /* sum row counts (partitioned, round robin) */ + COMBINE_TYPE_SAME /* expect all row counts to be the same (replicated write) */ +} CombineType; + +typedef enum { + EXEC_DIRECT_NONE, + EXEC_DIRECT_LOCAL, + EXEC_DIRECT_LOCAL_UTILITY, + EXEC_DIRECT_UTILITY, + EXEC_DIRECT_SELECT, + EXEC_DIRECT_INSERT, + EXEC_DIRECT_UPDATE, + EXEC_DIRECT_DELETE +} ExecDirectType; + +/* + * Contains instructions on processing a step of a query. + * In the prototype this will be simple, but it will eventually + * evolve into a GridSQL-style QueryStep. + */ +typedef struct { + Scan scan; + ExecDirectType exec_direct_type; /* track if remote query is execute direct and what type it is */ + char* sql_statement; + char* execute_statement; /* execute statement */ + ExecNodes* exec_nodes; /* List of Datanodes where to launch query */ + CombineType combine_type; + bool read_only; /* do not use 2PC when committing read only steps */ + bool force_autocommit; /* some commands like VACUUM require autocommit mode */ + char* statement; /* if specified use it as a PreparedStatement name on Datanodes */ + int stmt_idx; /* for cngpc, save idx of stmt_name in CachedPlan */ + char* cursor; /* if specified use it as a Portal name on Datanodes */ + int rq_num_params; /* number of parameters present in remote statement */ + Oid* rq_param_types; /* parameter types for the remote statement */ + bool rq_params_internal; /* Do the query params refer to the source data + * plan as against user-supplied params ? + */ + + RemoteQueryExecType exec_type; + bool is_temp; /* determine if this remote node is based + * on a temporary objects (no 2PC) */ + + bool rq_finalise_aggs; /* Aggregates should be finalised at the + * Datanode + */ + bool rq_sortgroup_colno; /* Use resno for sort group references + * instead of expressions + */ + Query* remote_query; /* Query structure representing the query to be + * sent to the datanodes + */ + List* base_tlist; /* the targetlist representing the result of + * the query to be sent to the datanode + */ + /* + * Reference targetlist of Vars to match the Vars in the plan nodes on + * coordinator to the corresponding Vars in the remote_query. These + * targetlists are used to while replacing/adding targetlist and quals in + * the remote_query. + */ + List* coord_var_tlist; + List* query_var_tlist; + bool has_row_marks; /* Did SELECT had FOR UPDATE/SHARE? */ + bool rq_save_command_id; /* Save the command ID to be used in + * some special cases */ + + bool is_simple; /* true if generate by gauss distributed framework, act as gather node in coordinator, + false if generate by pgxc distributed framework */ + bool rq_need_proj; /* @hdfs + * if is_simple is false, this value is always true; if is_simple is true, rq_need_proj + * is true for hdfs foreign table and false on other conditions. + */ + bool mergesort_required; /* true if the underlying node is sorted, default false; */ + bool spool_no_data; /* true if it do not need buffer all the data from data node */ + + bool poll_multi_channel; /* poll receive data from multi channel randomly */ + + int num_stream; /* num of stream below remote query */ + + int num_gather; /* num of gather(scan_gather plan_router) below remote query */ + + SimpleSort* sort; + + /* @hdfs + * The variable rte_ref will be used when the remotequery is executed by converting to stream. + * this variable store RangeTblRef struct, every of which corresponds the rte order number in + * rtable of root(PlannerInfo). + */ + List* rte_ref; + + RemoteQueryType position; /* the position where the RemoteQuery node will run. */ + bool is_send_bucket_map; /* send bucket map to dn or not */ + /* If execute direct on multi nodes, ExecRemoteQuery will call function query next according to this flag */ + bool is_remote_function_query; + bool isCustomPlan = false; + bool isFQS = false; +} RemoteQuery; + +extern Plan* create_remote_mergeinto_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp, MergeAction* action); +extern void pgxc_rqplan_adjust_tlist(PlannerInfo* root, RemoteQuery* rqplan, bool gensql); +extern void pgxc_rqplan_build_statement(RemoteQuery* rqplan); + +extern Plan* create_remotegrouping_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotedml_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp); +extern Plan* create_remotelimit_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotequery_plan(PlannerInfo* root, RemoteQueryPath* best_path); +extern Plan* create_remotesort_plan(PlannerInfo* root, Plan* local_plan, List* pathkeys); + +#endif /* PGXC_PLANN_REMOTE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pgxcship.h postgresql-hll-2.14/include/include/optimizer/pgxcship.h --- postgresql-hll-2.14_old/include/include/optimizer/pgxcship.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pgxcship.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------------- + * + * pgxcship.h + * Functionalities for the evaluation of expression shippability + * to remote nodes + * + * + * Portions Copyright (c) 1996-2012 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxcship.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PGXCSHIP_H +#define PGXCSHIP_H + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "nodes/nodeFuncs.h" +#include "pgxc/locator.h" +#include "utils/plpgsql.h" + +/* Insert select shippability flags */ +#define INSEL_SHIPPABLE_NCOL 0 +#define INSEL_SHIPPABLE_DCOL 1 +#define INSEL_UNSHIPPABLE_COL 2 + +typedef struct { + bool is_randomfunc_shippable; + bool is_nextval_shippable; + bool allow_func_in_targetlist; + bool is_ecfunc_shippable; + bool disallow_volatile_func_shippable; + bool disable_dn_gather; + List* query_list; + uint8 query_count; + bool query_shippable; /* backward compatible */ + bool current_shippable; /* current query can push */ + bool global_shippable; /* the whole query can push */ +} shipping_context; + +typedef struct { + List* funcids; /* List of func Oid */ + List* func_exprs; /* List of FuncExpr we have found */ + + /* true means find all func specified by funcids, false means once find any func then return */ + bool find_all; +} contain_func_context; + +typedef struct { + List* subquery_exprs; +} contain_subquery_context; + +/* Determine if query is shippable */ +extern ExecNodes* pgxc_is_query_shippable( + Query* query, int query_level, bool light_proxy, bool* contain_column_store = NULL, bool* use_star_up = NULL); +/* Determine if an expression is shippable */ +extern bool pgxc_is_expr_shippable(Expr* node, bool* has_aggs); +extern bool pgxc_is_funcRTE_shippable(Expr* node); +/* Determine if given function is shippable */ +extern bool pgxc_is_func_shippable(Oid funcid, shipping_context* context = NULL); +/* Determine if given function is shippable and the args conctains ANY type */ +extern bool pgxc_is_shippable_func_contain_any(Oid funcid); +extern bool pgxc_is_internal_agg_final_func(Oid funcid); +extern bool is_avg_func(Oid funcid); +/* Check equijoin conditions on given relations */ +extern List* pgxc_find_dist_equijoin_qual(List* dist_vars1, List* dist_vars2, Node* quals); +/* Merge given execution nodes based on join shippability conditions */ +extern ExecNodes* pgxc_merge_exec_nodes(ExecNodes* en1, ExecNodes* en2, int join_type = -1); +/* Check if given Query includes distribution column */ +extern bool pgxc_query_has_distcolgrouping(Query* query, ExecNodes* exec_nodes); +/* Check the shippability of an index */ +extern bool pgxc_check_index_shippability(RelationLocInfo* relLocInfo, bool is_primary, bool is_unique, + bool is_exclusion, List* indexAttrs, List* indexExprs); +/* Check the shippability of a parent-child constraint */ +extern bool pgxc_check_fk_shippability( + RelationLocInfo* parentLocInfo, RelationLocInfo* childLocInfo, List* parentRefs, List* childRefs); +extern bool pgxc_check_triggers_shippability(Oid relid, int commandType, bool* hasTrigger); +extern bool pgxc_find_nonshippable_row_trig( + Relation rel, int16 tgtype_event, int16 tgtype_timing, bool ignore_timing, bool* hasTrigger = NULL); +extern bool pgxc_query_contains_foreign_table(List* rtable); +extern bool pgxc_check_dynamic_param(List* dynamicExpr, ParamListInfo params); + +/* For online expansion, we need some user defined function to be shippable to DN */ +extern bool redis_func_shippable(Oid funcid); +extern bool vector_search_func_shippable(Oid funcid); + +/* For trigger shippable check */ +extern bool pgxc_is_query_shippable_in_trigger(PLpgSQL_expr* expr); +extern bool pgxc_find_statement_trigger(Oid relid, int commandType); + +/* For params, subquery walker */ +extern List* contains_subquery(Node* node, contain_subquery_context* context); +extern contain_subquery_context init_contain_subquery_context(); + +/* Get var from nodes */ +extern Var* get_var_from_node(Node* node); +#endif diff -uprN postgresql-hll-2.14_old/include/include/optimizer/placeholder.h postgresql-hll-2.14/include/include/optimizer/placeholder.h --- postgresql-hll-2.14_old/include/include/optimizer/placeholder.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/placeholder.h 2020-12-12 17:06:43.238347922 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * placeholder.h + * prototypes for optimizer/util/placeholder.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/placeholder.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLACEHOLDER_H +#define PLACEHOLDER_H + +#include "nodes/relation.h" + +extern PlaceHolderVar* make_placeholder_expr(PlannerInfo* root, Expr* expr, Relids phrels); +extern PlaceHolderInfo* find_placeholder_info(PlannerInfo* root, PlaceHolderVar* phv, bool create_new_ph); +extern void find_placeholders_in_jointree(PlannerInfo* root); +extern void update_placeholder_eval_levels(PlannerInfo* root, SpecialJoinInfo* new_sjinfo); +extern void fix_placeholder_input_needed_levels(PlannerInfo* root); +extern void add_placeholders_to_base_rels(PlannerInfo* root); +extern void add_placeholders_to_joinrel(PlannerInfo* root, RelOptInfo* joinrel); + +#endif /* PLACEHOLDER_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/plancat.h postgresql-hll-2.14/include/include/optimizer/plancat.h --- postgresql-hll-2.14_old/include/include/optimizer/plancat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/plancat.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * plancat.h + * prototypes for plancat.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/plancat.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANCAT_H +#define PLANCAT_H + +#include "nodes/relation.h" +#include "utils/relcache.h" + +/* Hook for plugins to get control in get_relation_info() */ +typedef void (*get_relation_info_hook_type) (PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel); +extern THR_LOCAL PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook; + +extern List* build_index_tlist(PlannerInfo* root, IndexOptInfo* index, Relation heapRelation); + +extern void get_relation_info(PlannerInfo* root, Oid relationObjectId, bool inhparent, RelOptInfo* rel); + +extern void estimate_rel_size(Relation rel, int32* attr_widths, RelPageType* pages, double* tuples, double* allvisfrac, + List** sampledPartitionIds); + +extern int32 get_relation_data_width(Oid relid, Oid partitionid, int32* attr_widths, bool vectorized = false); + +extern int32 getPartitionDataWidth(Relation partRel, int32* attr_widths); + +extern int32 getIdxDataWidth(Relation rel, IndexInfo* info, bool vectorized); + +extern bool relation_excluded_by_constraints(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); + +extern List* build_physical_tlist(PlannerInfo* root, RelOptInfo* rel); + +extern bool has_unique_index(RelOptInfo* rel, AttrNumber attno); + +extern Selectivity restriction_selectivity( + PlannerInfo* root, Oid operatorid, List* args, Oid inputcollid, int varRelid); + +extern Selectivity join_selectivity( + PlannerInfo* root, Oid operatorid, List* args, Oid inputcollid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern void estimatePartitionSize( + Relation relation, Oid partitionid, int32* attr_widths, RelPageType* pages, double* tuples, double* allvisfrac); + +#endif /* PLANCAT_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/planmain.h postgresql-hll-2.14/include/include/optimizer/planmain.h --- postgresql-hll-2.14_old/include/include/optimizer/planmain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/planmain.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,191 @@ +/* ------------------------------------------------------------------------- + * + * planmain.h + * prototypes for various files in optimizer/plan + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planmain.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANMAIN_H +#define PLANMAIN_H + +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/clauses.h" +#include "optimizer/streamplan.h" +#include "utils/selfuncs.h" + +/* GUC parameters */ +#define DEFAULT_CURSOR_TUPLE_FRACTION 0.1 + +typedef enum { OP_HASHJOIN, OP_HASHAGG, OP_SORT, OP_MATERIAL } OpType; + +typedef enum AggOrientation { + AGG_LEVEL_1_INTENT, /* single level in normal case for hashagg */ + AGG_LEVEL_2_1_INTENT, /* first level in two-level hashagg */ + AGG_LEVEL_2_2_INTENT, /* second level in two-level hashagg */ + DISTINCT_INTENT, /* distinct case, no nested agg needed */ + UNIQUE_INTENT /* this is special for SMP to record unique agg type */ +} AggOrientation; + +/* row threshold to apply having filter */ +#define HAVING_THRESHOLD 1e6 + +/* + * prototypes for plan/planmain.c + */ +extern void query_planner(PlannerInfo* root, List* tlist, double tuple_fraction, double limit_tuples, + Path** cheapest_path, Path** sorted_path, double* num_groups, List* rollup_groupclauses = NULL, + List* rollup_lists = NULL); + +/* + * prototypes for plan/planagg.c + */ +extern void preprocess_minmax_aggregates(PlannerInfo* root, List* tlist); +extern Plan* optimize_minmax_aggregates( + PlannerInfo* root, List* tlist, const AggClauseCosts* aggcosts, Path* best_path); + +/* + * prototypes for plan/createplan.c + */ +extern void set_plan_rows(Plan* plan, double globalRows, double multiple = 1.0); +extern Plan* create_plan(PlannerInfo* root, Path* best_path); +extern void disuse_physical_tlist(Plan* plan, Path* path); +extern void copy_plan_costsize(Plan* dest, Plan* src); +extern SubqueryScan* make_subqueryscan(List* qptlist, List* qpqual, Index scanrelid, Plan* subplan); +extern ForeignScan* make_foreignscan(List* qptlist, List* qpqual, Index scanrelid, List* fdw_exprs, List* fdw_private, + RemoteQueryExecType type = EXEC_ON_ALL_NODES); +extern Append* make_append(List* appendplans, List* tlist); +extern RecursiveUnion* make_recursive_union( + List* tlist, Plan* lefttree, Plan* righttree, int wtParam, List* distinctList, long numGroups); +extern Sort* make_sort_from_pathkeys( + PlannerInfo* root, Plan* lefttree, List* pathkeys, double limit_tuples, bool can_parallel = false); +extern Sort* make_sort_from_sortclauses(PlannerInfo* root, List* sortcls, Plan* lefttree); +extern Sort* make_sort_from_groupcols(PlannerInfo* root, List* groupcls, AttrNumber* grpColIdx, Plan* lefttree); +extern Sort* make_sort_from_targetlist(PlannerInfo* root, Plan* lefttree, double limit_tuples); +extern Sort* make_sort(PlannerInfo* root, Plan* lefttree, int numCols, AttrNumber* sortColIdx, Oid* sortOperators, + Oid* collations, bool* nullsFirst, double limit_tuples); +extern Agg* make_agg(PlannerInfo* root, List* tlist, List* qual, AggStrategy aggstrategy, + const AggClauseCosts* aggcosts, int numGroupCols, AttrNumber* grpColIdx, Oid* grpOperators, long numGroups, + Plan* lefttree, WindowLists* wflists, bool need_stream, bool trans_agg, List* groupingSets = NIL, + Size hash_entry_size = 0, bool add_width = false, AggOrientation agg_orientation = AGG_LEVEL_1_INTENT, + bool unique_check = true); +extern WindowAgg* make_windowagg(PlannerInfo* root, List* tlist, List* windowFuncs, Index winref, int partNumCols, + AttrNumber* partColIdx, Oid* partOperators, int ordNumCols, AttrNumber* ordColIdx, Oid* ordOperators, + int frameOptions, Node* startOffset, Node* endOffset, Plan* lefttree); +extern Group* make_group(PlannerInfo* root, List* tlist, List* qual, int numGroupCols, AttrNumber* grpColIdx, + Oid* grpOperators, double numGroups, Plan* lefttree); +extern Plan* materialize_finished_plan(Plan* subplan, bool materialize_above_stream = false, bool vectorized = false); +extern Unique* make_unique(Plan* lefttree, List* distinctList); +extern LockRows* make_lockrows(PlannerInfo* root, Plan* lefttree); +extern Limit* make_limit(PlannerInfo* root, Plan* lefttree, Node* limitOffset, Node* limitCount, int64 offset_est, + int64 count_est, bool enable_parallel = true); +extern void pick_single_node_plan_for_replication(Plan* plan); +extern Plan* make_stream_limit(PlannerInfo* root, Plan* lefttree, Node* limitOffset, Node* limitCount, int64 offset_est, + int64 count_est, double limit_tuples, bool needs_sort); +extern Plan* make_stream_sort(PlannerInfo* root, Plan* lefttree); +extern SetOp* make_setop(SetOpCmd cmd, SetOpStrategy strategy, Plan* lefttree, List* distinctList, + AttrNumber flagColIdx, int firstFlag, long numGroups, double outputRows, OpMemInfo* memInfo); +extern Plan* create_direct_scan( + PlannerInfo* root, List* tlist, RangeTblEntry* realResultRTE, Index src_idx, Index scanrelid); +extern Plan* create_direct_righttree( + PlannerInfo* root, Plan* subplan, List* distinctList, List* uniq_exprs, ExecNodes* target_exec_nodes); +extern HashJoin* create_direct_hashjoin( + PlannerInfo* root, Plan* outerPlan, Plan* innerPlan, List* tlist, List* joinClauses, JoinType joinType); +extern BaseResult* make_result(PlannerInfo* root, List* tlist, Node* resconstantqual, Plan* subplan, List* qual = NIL); +extern Material* make_material(Plan* lefttree, bool materialize_all = false); +extern int find_node_in_targetlist(Node* node, List* targetlist); +extern Node* find_qualify_equal_class(PlannerInfo* root, Node* expr, List* targetlist); +extern List* confirm_distribute_key(PlannerInfo* root, Plan* plan, List* distribute_keys); +extern bool check_dsitribute_key_in_targetlist(PlannerInfo* root, List* distribute_keys, List* targetlist); +extern int get_plan_actual_total_width(Plan* plan, bool vectorized, OpType type, int newcol = 0); +#ifdef STREAMPLAN +extern Plan* make_modifytable(PlannerInfo* root, CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, Index mergeTargetRelation, + List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause, bool isDfsStore = false); +extern Plan* make_modifytables(PlannerInfo* root, CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, bool isDfsStore, + Index mergeTargetRelation, List* mergeSourceTargetList, List *mergeActionList, UpsertExpr *upsertClause); +extern Plan* make_redistribute_for_agg(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple, + Distribution* distribution = NULL, bool is_local_redistribute = false); +extern Plan* make_stream_plan(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple, + Distribution* target_distribution = NULL); +#else +extern ModifyTable* make_modifytable(CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, Index mergeTargetRelation, + List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause, bool isDfsStore = false); +extern ModifyTable* make_modifytables(CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, bool isDfsStore, + Index mergeTargetRelation, List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause); +#endif + +extern bool is_projection_capable_plan(Plan* plan); +extern RowToVec* make_rowtovec(Plan* lefttree); +extern VecToRow* make_vectorow(Plan* lefttree); +extern bool isEqualExpr(Node* node); +extern bool check_subplan_in_qual(List* tlist, List* qual); +extern bool check_subplan_exec_datanode(PlannerInfo* root, Node* node); + +extern void add_base_rels_to_query(PlannerInfo* root, Node* jtnode); +extern void build_base_rel_tlists(PlannerInfo* root, List* final_tlist); +extern void add_vars_to_targetlist(PlannerInfo* root, List* vars, Relids where_needed, bool create_new_ph); +extern void find_lateral_references(PlannerInfo *root); +extern void create_lateral_join_info(PlannerInfo *root); +extern void add_lateral_info(PlannerInfo *root, Index rhs, Relids lhs); +extern List* deconstruct_jointree(PlannerInfo* root); +extern void distribute_restrictinfo_to_rels(PlannerInfo* root, RestrictInfo* restrictinfo); +extern void process_security_clause_appendrel(PlannerInfo *root); +extern void process_implied_equality(PlannerInfo* root, Oid opno, Oid collation, Expr* item1, Expr* item2, + Relids qualscope, Relids nullable_relids, Index security_level, bool below_outer_join, bool both_const); +extern void process_implied_quality(PlannerInfo* root, Node* node, Relids relids, bool below_outer_join); +extern RestrictInfo* build_implied_join_equality( + Oid opno, Oid collation, Expr* item1, Expr* item2, Relids qualscope, Relids nullable_relids, Index security_level); + +extern bool useInformationalConstraint(PlannerInfo* root, List* qualClause, Relids relids); + +/* + * prototypes for plan/analyzejoins.c + */ +extern List* remove_useless_joins(PlannerInfo* root, List* joinlist); +extern bool query_supports_distinctness(Query* query); +extern bool query_is_distinct_for(Query* query, List* colnos, List* opids); + +/* + * prototypes for plan/setrefs.c + */ +extern Plan* set_plan_references(PlannerInfo* root, Plan* plan); +extern void fix_opfuncids(Node* node); +extern void set_opfuncid(OpExpr* opexpr); +extern void set_sa_opfuncid(ScalarArrayOpExpr* opexpr); +extern void record_plan_function_dependency(PlannerInfo* root, Oid funcid); +extern void extract_query_dependencies( + Node* query, List** relationOids, List** invalItems, bool* hasRowSecurity, bool* hasHdfs); +extern double calc_num_groups(PlannerInfo* root, List* groupClause, double input_rows); + +#ifdef PGXC +/* + * prototypes for plan/pgxcplan.c + */ +extern Plan* create_remotedml_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp); +extern Plan* create_remote_mergeinto_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp, MergeAction* action); +extern Plan* create_remotegrouping_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotequery_plan(PlannerInfo* root, RemoteQueryPath* best_path); +extern Plan* create_remotesort_plan(PlannerInfo* root, Plan* local_plan, List* pathkeys = NIL); +extern Plan* create_remotelimit_plan(PlannerInfo* root, Plan* local_plan); +extern List* pgxc_order_qual_clauses(PlannerInfo* root, List* clauses); +extern List* pgxc_build_relation_tlist(RelOptInfo* rel); +extern void pgxc_copy_path_costsize(Plan* dest, Path* src); +extern Plan* pgxc_create_gating_plan(PlannerInfo* root, Plan* plan, List* quals); +#endif +extern void expand_dfs_tables(PlannerInfo* root); +extern void expand_internal_rtentry(PlannerInfo* root, RangeTblEntry* rte, Index rti); +extern List* find_all_internal_tableOids(Oid parentOid); +extern bool check_agg_optimizable(Aggref* aggref, int16* strategy); +extern void check_hashjoinable(RestrictInfo* restrictinfo); + +#endif /* PLANMAIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/planmem_walker.h postgresql-hll-2.14/include/include/optimizer/planmem_walker.h --- postgresql-hll-2.14_old/include/include/optimizer/planmem_walker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/planmem_walker.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * planmem_walker.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/planmem_walker.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PLANWALKER_H +#define PLANWALKER_H + +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" + +typedef bool (*MethodWalker)(); +typedef bool (*MethodP2Walker)(Node*, void*); + +/* Traverse flag during plan tree walker */ +#define UNDER_STREAM 0x01 /* this flag indicates that current plan node is under stream */ +#define UNDER_MULTI_GROUP_OP \ + 0x02 /* this flag indicates that current plan node is \ + under node with multiple group, like join, or append */ + +/* + * The plan associated with a SubPlan is found in a list. During planning this is in + * the global structure found through the root PlannerInfo. After planning this is in + * the PlannedStmt. + * + * Structure plan_tree_base_prefix carries the appropriate pointer for general plan + * tree walker/mutator framework. All users of the framework must prefix their context + * structure with a plan_tree_base_prefix and initialize it appropriately. + */ +typedef struct plan_tree_base_prefix { + Node* node; /* PlannerInfo* or PlannedStmt* */ + List* init_plans; /* with all traversed init plan saved, and below nodes can find reference from it */ + bool* traverse_flag; /* flag that indicates whether the subplan is traversed, to prevent duplicate traverse */ +} plan_tree_base_prefix; + +/* Memory calculation and control phase */ +typedef enum { + ASSIGN_MEM = 0, /* memory assignment phase, give memory to each plan node */ + DECREASE_MEM, /* memory decrease phase, only happens when query mem exceeds threshold */ + ADJUST_MEM, /* memory adjust phase, to prevent huge initial memory allocation or early disk spill */ + SPREAD_ADJUST_MEM /* memory spread calculation and adjust phase, to calculate maximum memory to spread */ +} TraversePhase; + +#define ADJ_PHASE(context) ((context)->phase == ADJUST_MEM || (context)->phase == SPREAD_ADJUST_MEM) + +/* each nodegroup's OperatorGroup mem */ +typedef struct OperatorGroupNodeMem { + /* + * The following memory usage are all arrays, and we use the first one for normal memory + * usage, and second one for min memory usage if not equal to normal one, else 0 + */ + /* The memory limit for this group and its child groups */ + int groupMemKB[2]; + /* The memory limit for the operators visible to this group */ + int groupBlockedOpMemKB[2]; + /* The memory limit during the group execution */ + int groupConcMemKB[2]; + /* The memory limit for child groups below stream */ + int belowStreamConcMemKB[2]; + /* The memory limit of operators in this group */ + int groupOpMemKB[2]; + + /* memory that need to decreased */ + int decreaseMemKB; + /* memory that group operator need to decrease */ + int groupOpDMemKB; + /* memory that group top node need to decrease */ + int topNodeDMemKB; +} OperatorGroupNodeMem; + +/* + * OperatorGroupNode + * Store the information regarding an operator group. + * See details in memctl.cpp + */ +typedef struct OperatorGroupNode { + /* The id and top node for this group */ + int groupId; + Plan* topNode; + + /* The list of child groups */ + List* childGroups; + + /* The parent group */ + struct OperatorGroupNode* parentGroup; + + List* belowStreamGroups; /* list of virtual groups below + stream, which are the real co-exist groups */ + + bool virtualGroup; /* groups with memory non-intensive operator as top node */ + bool underStreamGroup; /* virtual group that under stream node */ + + int childLevel; /* number of children group levels below */ + int outerLevel; /* number of children group levels for hash join outer side */ + + /* The memory info for each nodegroup in this operator group node */ + OperatorGroupNodeMem* ng_groupMemKBArray; + int ng_num; +} OperatorGroupNode; + +typedef struct QueryMemKB { + int queryMemKB; /* the query memory limit */ + int minQueryMemKB; /* the minimum query memory limit */ + int currQueryMemKB; /* the query memory limit of current plan */ + int minCurrQueryMemKB; /* the minimum query memory limit of current plan */ + + int availMemKB; /* total expected memory for the query */ + int streamTotalMemKB; /* total memory consumption of stream, which can't be decrease */ + + int assigned_query_mem_1; /* assigned_query_mem[1] for each nodegroup */ +} QueryMemKB; + +/* + * MethodEarlyFreeContext + * Store the intermediate states during the tree walking for the optimize + * memory distribution policy. + */ +typedef struct MethodPlanWalkerContext { + plan_tree_base_prefix base; + + TraversePhase phase; /* Traverse phase */ + bool dnExec; /* current node is executed on datanode */ + OperatorGroupNode* groupTree; /* the root of the group tree */ + OperatorGroupNode* groupNode; /* the current group node in the group tree */ + + int nextGroupId; /* the group id for a new group node */ + + PlannedStmt* plannedStmt; /* pointer to the planned statement */ + + unsigned int status; /* current op is under stream */ + List* groupTreeList; /* list of group trees of a query */ + int groupTreeIdx; /* current group tree index when re-traverse a plan tree */ + bool use_tenant; /* multi-tenant scenario, and we don't allow auto spread in this case */ + + List* ng_distributionList; /* related nodegroup list for logic cluster scenario */ + int ng_num; /* 1 plus number of logic clusters */ + QueryMemKB* ng_queryMemKBArray; /* query memory for each nodegroup */ +} MethodPlanWalkerContext; + +typedef struct PredpushPlanWalkerContext { + MethodPlanWalkerContext mpwc; + + bool predpush_stream; /* is predpush meet a stream */ +} PredpushPlanWalkerContext; + +extern void exec_init_plan_tree_base(plan_tree_base_prefix* base, PlannedStmt* stmt); + +extern Plan* plan_tree_base_subplan_get_plan(plan_tree_base_prefix* base, SubPlan* subplan); + +extern bool walk_plan_node_fields(Plan* plan, MethodWalker walker, void* context); + +extern bool plan_tree_walker(Node* node, MethodWalker walker, void* context); + +extern bool IsBlockedJoinNode(Plan* node); + +#endif /* PLANWALKER_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/planner.h postgresql-hll-2.14/include/include/optimizer/planner.h --- postgresql-hll-2.14_old/include/include/optimizer/planner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/planner.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,185 @@ +/* ------------------------------------------------------------------------- + * + * planner.h + * prototypes for planner.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planner.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANNER_H +#define PLANNER_H + +#include "executor/execdesc.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/clauses.h" +#include "nodes/parsenodes.h" +#include "utils/selfuncs.h" + +#define INSTALLATION_MODE "installation" + +/* Expression kind codes for preprocess_expression */ +#define EXPRKIND_QUAL 0 +#define EXPRKIND_TARGET 1 +#define EXPRKIND_RTFUNC 2 +#define EXPRKIND_RTFUNC_LATERAL 3 +#define EXPRKIND_VALUES 4 +#define EXPRKIND_VALUES_LATERAL 5 +#define EXPRKIND_LIMIT 6 +#define EXPRKIND_APPINFO 7 +#define EXPRKIND_PHV 8 +#define EXPRKIND_TABLESAMPLE 9 + +/* + * @hdfs + * Optimize clause type by using informational constraint. + */ +typedef enum { GROUPBY_CLAUSE_TYPE, DISTINCT_CLAUSE_TYPE, SCAN_QUAL_CLAUSE_TYPE, JOIN_QUAL_CLAUSE_TYPE } ClauseType; + +/* Context for mark agg func and denserank in WindowAgg */ +typedef struct { + bool has_agg; + bool has_denserank; +} DenseRank_context; + +extern ExecNodes* getExecNodesByGroupName(const char* gname); +extern PlannedStmt* planner(Query* parse, int cursorOptions, ParamListInfo boundParams); +extern PlannedStmt* standard_planner(Query* parse, int cursorOptions, ParamListInfo boundParams); + +typedef PlannedStmt *(*planner_hook_type) (Query* parse, int cursorOptions, ParamListInfo boundParams); + +extern Plan* subquery_planner(PlannerGlobal* glob, Query* parse, PlannerInfo* parent_root, bool hasRecursion, + double tuple_fraction, PlannerInfo** subroot, int options = SUBQUERY_NORMAL, ItstDisKey* diskeys = NULL, + List* subqueryRestrictInfo = NIL); + +extern void add_tlist_costs_to_plan(PlannerInfo* root, Plan* plan, List* tlist); + +extern bool is_dummy_plan(Plan* plan); + +extern bool is_single_baseresult_plan(Plan* plan); + +extern Expr* expression_planner(Expr* expr); + +extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr); + +extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid); + +extern bool ContainRecursiveUnionSubplan(PlannedStmt* pstmt); + +extern void preprocess_qual_conditions(PlannerInfo* root, Node* jtnode); + +typedef enum { + /* + * Disable "inlist2join" rewrite optimization + */ + QRW_INLIST2JOIN_DISABLE = -1, + + /* + * Enable "inlist2join" rewrite optimization in cost-base mode, and this is default + * behavior in optimizer. + */ + QRW_INLIST2JOIN_CBO = 0, + + /* + * Enable "inlist2join" rewrite optimization in rule-base mode and without consider + * the num of elements specified in "In-List" or "= ANY[]" clause. + * + * We are considering it as a force mode, more likely it is to help DFX improvement + * to evaluate Inlist2Join is correct for query result (developer basis) + */ + QRW_INLIST2JOIN_FORCE = 1, + + /* + * Other values that greater than 2, inlist2join rewrite optimization runs in extended + * rule-base mode, where the GUC value plays as the element num of inlist threshold + * for inlist2join conversion + */ +} QrwInlist2JoinOptMode; + +typedef struct RewriteVarMapping { + Var* old_var; + Var* new_var; + bool need_fix; /* the var is needed to fix when create plan */ +} RewriteVarMapping; + +extern void fix_vars_plannode(PlannerInfo* root, Plan* plan); +extern void inlist2join_qrw_optimization(PlannerInfo* root, int rti); +extern void find_inlist2join_path(PlannerInfo* root, Path* best_path); + +extern bool planClusterPartitionUseSort(Relation partRel, Oid indexOid, PlannerInfo* root, RelOptInfo* relOptInfo); +extern void select_active_windows(PlannerInfo* root, WindowLists* wflists); +extern List* make_pathkeys_for_window(PlannerInfo* root, WindowClause* wc, List* tlist, bool canonicalize); + +extern List* get_distributekey_from_tlist( + PlannerInfo* root, List* tlist, List* groupcls, double rows, double* result_multiple, void* skew_info = NULL); +extern Plan* try_vectorize_plan(Plan* top_plan, Query* parse, bool from_subplan, PlannerInfo* subroot = NULL); +extern bool is_vector_scan(Plan* plan); + +extern bool vector_engine_unsupport_expression_walker(Node* node); + +extern void adjust_all_pathkeys_by_agg_tlist(PlannerInfo* root, List* tlist, WindowLists* wflists); +extern void get_multiple_from_exprlist(PlannerInfo* root, List* exprList, double rows, bool* useskewmultiple, + bool usebiasmultiple, double* skew_multiple, double* bias_multiple); +extern double get_bias_from_varlist(PlannerInfo* root, List* varlist, double rows, bool isCoalesceExpr = false); +extern ExecNodes* getDefaultPlannerExecNodes(PlannerInfo* root); +extern ExecNodes* getRelationExecNodes(Oid tableoid); +extern Bitmapset* get_base_rel_indexes(Node* jtnode); +extern Size get_hash_entry_size(int width, int numAggs = 0); + +typedef enum QueryIssueType { + /* Query not plan shipping */ + QueryShipping = 0, + + /* Large relation Broadcast */ + LargeTableBroadCast, + + /* Large relation is the inner relation when deal with Hashjoin */ + LargeTableAsHashJoinInner, + + /* Large relation in nestloop with equal join condition */ + LargeTableWithEqualCondInNestLoop, + + /* Data Skew */ + DataSkew, + + /* Not Collect Statistics */ + StatsNotCollect, + + /* Estimation rows is inaccurate */ + InaccurateEstimationRowNum, + + /* Unsuitable Scan Method */ + UnsuitableScanMethod +} QueryIssueType; + +/* + * Data structure to represent query issues + */ +typedef struct QueryPlanIssueDesc { + QueryIssueType issue_type; + const PlanState* issue_plannode; + StringInfo issue_suggestion; +} QueryPlanIssueDesc; + +extern List* PlanAnalyzerQuery(QueryDesc* querydesc); +extern List* PlanAnalyzerOperator(QueryDesc* querydesc, PlanState* planstate); +extern void GetPlanNodePlainText( + Plan* plan, char** pname, char** sname, char** strategy, char** operation, char** pt_operation, char** pt_options); +extern void RecordQueryPlanIssues(const List* results); +extern bool enable_check_implicit_cast(); +extern void check_gtm_free_plan(PlannedStmt *stmt, int elevel); +extern THR_LOCAL List* g_index_vars; +extern bool PreprocessOperator(Node* node, void* context); +extern void check_plan_mergeinto_replicate(PlannedStmt* stmt, int elevel); +extern void check_entry_mergeinto_replicate(Query* parse); +extern List* get_plan_list(Plan* plan); +extern RelOptInfo* build_alternative_rel(const RelOptInfo* origin, RTEKind rtekind); +extern Plan* get_foreign_scan(Plan* plan); +extern uint64 adjust_plsize(Oid relid, uint64 plan_width, uint64 pl_size, uint64* width); + +#endif /* PLANNER_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/plan_tree_model.h postgresql-hll-2.14/include/include/optimizer/plan_tree_model.h --- postgresql-hll-2.14_old/include/include/optimizer/plan_tree_model.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/plan_tree_model.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * plan_tree_model.h + * + * IDENTIFICATION + * src/include/optimizer/ml_model.h + * + * DESCRIPTION + * Declaration of externel APIs of Code/src/backend/utils/learn/plan_tree_model.cpp + * + * ------------------------------------------------------------------------- + */ +#ifndef PLAN_TREE_MODEL_H +#define PLAN_TREE_MODEL_H + +#include "postgres.h" + +extern char* TreeModelTrain(Form_gs_opt_model modelinfo, char* labels); +extern char* TreeModelPredict(const char* modelName, char* filepath, const char* ip, int port); + +#define ParseConfigBuf(buf, conninfo, msg_str) \ + do { \ + pfree_ext(buf); \ + DestroyConnInfo(conninfo); \ + ereport(ERROR, (errmodule(MOD_OPT_AI), errcode(ERRCODE_UNEXPECTED_NODE_STATE), errmsg(msg_str))); \ + } while (0) + +#define ParseResBuf(buf, filename, msg_str) \ + do { \ + pfree_ext(buf); \ + if ((filename) != NULL) { \ + Unlinkfile(filename); \ + } \ + ereport(ERROR, (errmodule(MOD_OPT_AI), errcode(ERRCODE_UNEXPECTED_NODE_STATE), errmsg(msg_str))); \ + } while (0) + +#endif /* PLAN_TREE_MODEL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/predtest.h postgresql-hll-2.14/include/include/optimizer/predtest.h --- postgresql-hll-2.14_old/include/include/optimizer/predtest.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/predtest.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * predtest.h + * prototypes for predtest.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/predtest.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDTEST_H +#define PREDTEST_H + +#include "nodes/primnodes.h" + +extern bool predicate_implied_by(List* predicate_list, List* restrictinfo_list); +extern bool predicate_refuted_by(List* predicate_list, List* restrictinfo_list, bool weakRefute); + +#endif /* PREDTEST_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/prep.h postgresql-hll-2.14/include/include/optimizer/prep.h --- postgresql-hll-2.14_old/include/include/optimizer/prep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/prep.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------------- + * + * prep.h + * prototypes for files in optimizer/prep/ + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/prep.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREP_H +#define PREP_H + +#include "nodes/plannodes.h" +#include "nodes/parsenodes.h" +#include "nodes/relation.h" + +#include "utils/guc.h" +#include "catalog/pg_operator.h" +#include "optimizer/clauses.h" + +typedef enum UNIONALL_SHIPPING_TYPE +{ + SHIPPING_NONE, + SHIPPING_PARTIAL, + SHIPPING_ALL +}UNIONALL_SHIPPING_TYPE; + +/* + * prototypes for prepjointree.c + */ +extern void pull_up_sublinks(PlannerInfo* root); +extern void substitute_ctes_with_subqueries(PlannerInfo* root, Query* parse, bool under_recursive_tree); +extern void inline_set_returning_functions(PlannerInfo* root); +extern Node* pull_up_subqueries(PlannerInfo* root, Node* jtnode); +extern void flatten_simple_union_all(PlannerInfo* root); +extern void removeNotNullTest(PlannerInfo* root); +extern void reduce_outer_joins(PlannerInfo* root); +extern void reduce_inequality_fulljoins(PlannerInfo* root); +extern Relids get_relids_in_jointree(Node* jtnode, bool include_joins); +extern Relids get_relids_for_join(PlannerInfo* root, int joinrelid); +extern void pull_up_subquery_hint(PlannerInfo* root, Query* parse, HintState* hint_state); +#ifndef ENABLE_MULTIPLE_NODES +extern void preprocess_rownum(PlannerInfo *root, Query *parse); +#endif + +/* + * prototypes for prepnonjointree.cpp + */ +extern bool get_real_rte_varno_attno( + Query* parse, Index* varno, AttrNumber* varattno, const Index targetVarno = InvalidOid); +extern bool is_join_inner_side( + const Node* fromNode, const Index targetRTEIndex, const bool isParentInnerSide, bool* isFound); +extern Query* lazyagg_main(Query* parse); +extern void reduce_orderby(Query* query, bool reduce); + +extern Node* get_real_rte_varno_attno_or_node(Query* parse, Index* varno, AttrNumber* varattno); + +/* + * prototypes for prepqual.c + */ +extern Node* negate_clause(Node* node); +extern Expr* canonicalize_qual(Expr* qual); + +/* + * prototypes for preptlist.c + */ +extern List* preprocess_targetlist(PlannerInfo* root, List* tlist); +extern List* preprocess_upsert_targetlist(List* tlist, int result_relation, List* range_table); +extern PlanRowMark* get_plan_rowmark(List* rowmarks, Index rtindex); + +/* + * prototypes for prepunion.c + */ +extern Plan* plan_set_operations(PlannerInfo* root, double tuple_fraction, List** sortClauses); + +extern void expand_inherited_tables(PlannerInfo* root); +extern void make_inh_translation_list( + Relation oldrelation, Relation newrelation, Index newvarno, List** translated_vars); +extern Bitmapset* translate_col_privs(const Bitmapset* parent_privs, List* translated_vars); + +extern Node* adjust_appendrel_attrs(PlannerInfo* root, Node* node, AppendRelInfo* appinfo); + +extern void mark_parent_child_pushdown_flag(Query *parent, Query *child); +extern bool check_base_rel_in_fromlist(Query *parse, Node *jtnode); +extern UNIONALL_SHIPPING_TYPE precheck_shipping_union_all(Query *subquery, Node *setOp); +#ifndef ENABLE_MULTIPLE_NODES +/* judge if it is possible to optimize ROWNUM */ +static inline bool contain_rownum_qual(Query *parse) +{ + if (!IsA(parse->jointree, FromExpr)) { + return false; + } + + return contain_rownum_walker(((FromExpr *)parse->jointree)->quals, NULL); +} +#endif +#endif /* PREP_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pruningboundary.h postgresql-hll-2.14/include/include/optimizer/pruningboundary.h --- postgresql-hll-2.14_old/include/include/optimizer/pruningboundary.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pruningboundary.h 2020-12-12 17:06:43.239347935 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruningboundary.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/pruningboundary.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PRUNINGBOUNDARY_H_ +#define PRUNINGBOUNDARY_H_ + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "utils/relcache.h" + +extern void destroyPruningBoundary(PruningBoundary* boundary); +extern PruningBoundary* makePruningBoundary(int partKeyNum); +extern PruningBoundary* copyBoundary(PruningBoundary* boundary); + +#endif /* PRUNINGBOUNDARY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/pruning.h postgresql-hll-2.14/include/include/optimizer/pruning.h --- postgresql-hll-2.14_old/include/include/optimizer/pruning.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/pruning.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,101 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruning.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/pruning.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PRUNING_H_ +#define PRUNING_H_ + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "utils/relcache.h" + +typedef PartitionMap* (*GetPartitionMapFunc)(Relation relation); + +typedef enum PruningType { + PruningPartition = 0, + PruningSlice, +} PruningType; + +typedef struct PruningContext { + PruningType pruningType; + GetPartitionMapFunc GetPartitionMap; + + PlannerInfo* root; + RangeTblEntry* rte; + EState* estate; + Relation relation; + + /* used for slice pruning */ + Index varno; + ParamListInfo boundParams; +} PruningContext; + +typedef enum PartKeyColumnRangeMode { + PARTKEY_RANGE_MODE_POINT = 0, + PARTKEY_RANGE_MODE_INCREASE, + PARTKEY_RANGE_MODE_RANGE, + PARTKEY_RANGE_MODE_UNION +} PartKeyColumnRangeMode; + +typedef enum IndexesUsableType { + INDEXES_FULL_USABLE = 0, + INDEXES_PARTIAL_USABLE, + INDEXES_NONE_USABLE +} IndexesUsableType; + +typedef struct PartKeyColumnRange { + PartKeyColumnRangeMode mode; + Const* prev; + Const* next; +} PartKeyColumnRange; + +typedef struct PartKeyRange { + int num; + PartKeyColumnRange columnRanges[4]; +} PartKeyRange; +extern IndexesUsableType eliminate_partition_index_unusable(Oid IndexOid, PruningResult* inputPruningResult, + PruningResult** indexUsablePruningResult, PruningResult** indexUnusablePruningResult); +PruningResult* getFullPruningResult(Relation relation); +void destroyPruningResult(PruningResult* pruningResult); +void partitionPruningFromBoundary(PruningContext *context, PruningResult* pruningResult); +void generateListFromPruningBM(PruningResult* result); +PruningResult* partitionPruningWalker(Expr* expr, PruningContext* pruningCtx); +PruningResult* partitionPruningForExpr(PlannerInfo* root, RangeTblEntry* rte, Relation rel, Expr* expr); +PruningResult* partitionPruningForRestrictInfo( + PlannerInfo* root, RangeTblEntry* rte, Relation rel, List* restrictInfoList); +PruningResult* singlePartitionPruningForRestrictInfo(Oid partitionOid, Relation rel); +extern PruningResult* copyPruningResult(PruningResult* srcPruningResult); +extern Oid getPartitionOidFromSequence(Relation relation, int partSeq); +extern int varIsInPartitionKey(int attrNo, int2vector* partKeyAttrs, int partKeyNum); +extern bool checkPartitionIndexUnusable(Oid indexOid, int partItrs, PruningResult* pruning_result); + +extern PruningResult* GetPartitionInfo(PruningResult* result, EState* estate, Relation current_relation); +static inline PartitionMap* GetPartitionMap(PruningContext *context) +{ + return context->GetPartitionMap(context->relation); +} + +#endif /* PRUNING_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/randomplan.h postgresql-hll-2.14/include/include/optimizer/randomplan.h --- postgresql-hll-2.14_old/include/include/optimizer/randomplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/randomplan.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * randomplan.h + * prototypes for randomplan.c + * + * + * IDENTIFICATION + * src/include/optimizer/randomplan.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RANDOMPLAN_H +#define RANDOMPLAN_H + +#include "nodes/relation.h" + +#define OPTIMIZE_PLAN 0 +#define RANDOM_PLAN_DEFAULT -1 + +extern int choose_random_option(int optionnum); +extern void set_inital_plan_seed(); +extern uint32 get_inital_plan_seed(); +extern List* get_random_path(RelOptInfo* parent_rel, Path** cheapest_startup_path, Path** cheapest_total_path); +extern char* get_random_plan_string(); + +#endif /* RANDOMPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/restrictinfo.h postgresql-hll-2.14/include/include/optimizer/restrictinfo.h --- postgresql-hll-2.14_old/include/include/optimizer/restrictinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/restrictinfo.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,35 @@ +/* ------------------------------------------------------------------------- + * + * restrictinfo.h + * prototypes for restrictinfo.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/restrictinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RESTRICTINFO_H +#define RESTRICTINFO_H + +#include "nodes/relation.h" + +/* Convenience macro for the common case of a valid-everywhere qual */ +#define make_simple_restrictinfo(clause) make_restrictinfo(clause, true, false, false, 0, NULL, NULL, NULL) + +extern RestrictInfo* make_restrictinfo(Expr* clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, + Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids); +extern List* make_restrictinfo_from_bitmapqual(Path* bitmapqual, bool is_pushed_down, bool include_predicates); +extern List* make_restrictinfos_from_actual_clauses(PlannerInfo* root, List* clause_list); +extern bool restriction_is_or_clause(RestrictInfo* restrictinfo); +extern bool restriction_is_securely_promotable(RestrictInfo* restrictinfo, RelOptInfo* rel); +extern List* get_actual_clauses(List* restrictinfo_list); +extern List* get_all_actual_clauses(List* restrictinfo_list); +extern List* extract_actual_clauses(List* restrictinfo_list, bool pseudoconstant); +extern void extract_actual_join_clauses(List* restrictinfo_list, List** joinquals, List** otherquals); +extern bool join_clause_is_movable_to(RestrictInfo* rinfo, Index baserelid); +extern bool join_clause_is_movable_into(RestrictInfo* rinfo, Relids currentrelids, Relids current_and_outer); +extern void initialize_bucket_size(RestrictInfo* info); +#endif /* RESTRICTINFO_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/stream_check.h postgresql-hll-2.14/include/include/optimizer/stream_check.h --- postgresql-hll-2.14_old/include/include/optimizer/stream_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/stream_check.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,47 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_check.h + * prototypes for stream plan for checking. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_check.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_CHECK_H +#define STREAM_CHECK_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "optimizer/stream_cost.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +typedef struct underStreamContext { + Index reslutIndex; + bool underStream; +} underStreamContext; + +extern Plan* mark_distribute_dml( + PlannerInfo* root, Plan** sourceplan, ModifyTable* mt_plan, List** resultRelations, List* mergeActionList); +extern List* check_op_list_template(Plan* result_plan, List* (*check_eval)(Node*)); +extern bool judge_lockrows_need_redistribute( + PlannerInfo* root, Plan* subplan, Form_pgxc_class target_classForm, Index result_rte_idx); +extern bool judge_redistribute_setop_support(PlannerInfo* root, List* subplanlist, Bitmapset* redistributePlanSet); +extern void mark_query_canpush_flag(Node *query); +extern void mark_stream_unsupport(); +extern List* check_random_expr(Plan* result_plan); +extern List* check_func_list(Plan* result_plan); +extern bool check_stream_support(); +extern List* check_subplan_list(Plan* result_plan); +extern List* check_vartype_list(Plan* result_plan); +extern ExecNodes* get_plan_max_ExecNodes(Plan* lefttree, List* subplans); +extern List* get_max_nodeList(List** nodeList, Plan* result_plan); + +#endif /* STREAM_CHECK_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/stream_cost.h postgresql-hll-2.14/include/include/optimizer/stream_cost.h --- postgresql-hll-2.14_old/include/include/optimizer/stream_cost.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/stream_cost.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,97 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_cost.h + * prototypes used to calculate stream plan costs. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_cost.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_COST_H +#define STREAM_COST_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +typedef enum { + STREAM_GATHER = 0, + STREAM_BROADCAST, + STREAM_REDISTRIBUTE, + STREAM_ROUNDROBIN, + STREAM_HYBRID, + STREAM_LOCAL, + STREAM_NONE +} StreamType; + +typedef enum { + PARALLEL_NONE = 0, /* Default value, means no parallelization. */ + REMOTE_DISTRIBUTE, /* Distribute data to all nodes. */ + REMOTE_DIRECT_DISTRIBUTE,/* Distribute data to one specific nodes. */ + REMOTE_SPLIT_DISTRIBUTE, /* Distribute data to all parallel threads at all nodes. */ + REMOTE_BROADCAST, /* Broadcast data to all nodes. */ + REMOTE_SPLIT_BROADCAST, /* Broadcast data to all parallel threads all nodes. */ + REMOTE_HYBRID, /* Hybrid send data. */ + LOCAL_DISTRIBUTE, /* Distribute data to all threads at local node. */ + LOCAL_BROADCAST, /* Broadcast data to all threads at local node. */ + LOCAL_ROUNDROBIN /* Roundrobin data to all threads at local node. */ +} SmpStreamType; + +typedef struct ParallelDesc { + int consumerDop; /* DOP of consumer side. */ + int producerDop; /* DOP of producer side. */ + SmpStreamType distriType; /* Tag the data distribution type. */ +} ParallelDesc; + +/* + * All stream-type paths share these fields. + */ +typedef struct StreamPath { + Path path; + StreamType type; + Path* subpath; + ParallelDesc* smpDesc; /* the parallel description of the stream. */ + Distribution consumer_distribution; + List* skew_list; +} StreamPath; + +typedef struct Stream { + Scan scan; + StreamType type; /* indicate it's Redistribute/Broadcast. */ + char* plan_statement; + ExecNodes* consumer_nodes; /* indicate nodes group that send to. */ + List* distribute_keys; + bool is_sorted; /* true if the underlying node is sorted, default false. */ + SimpleSort* sort; /* do the merge sort if producer is sorted */ + bool is_dummy; /* is dummy means the stream thread init by this stream node + * will end asap and init a child stream thread. */ + + ParallelDesc smpDesc; /* the parallel description of the stream. */ + char* jitted_serialize; /* jitted serialize function for vecstream */ + List* skew_list; + int stream_level; /* number of stream level (starts from 1), normally + * used for recursive sql execution that under recursive-union operator. */ + ExecNodes* origin_consumer_nodes; + bool is_recursive_local; /* LOCAL GATHER for recursive */ +} Stream; + +extern void compute_stream_cost(StreamType type, char locator_type, double subrows, double subgblrows, + double skew_ratio, int width, bool isJoin, List* distribute_keys, Cost* total_cost, double* gblrows, + unsigned int producer_num_dn, unsigned int consumer_num_dn, ParallelDesc* smpDesc = NULL, List* ssinfo = NIL); +extern void cost_stream(StreamPath* stream, int width, bool isJoin = false); +extern List* get_max_cost_distkey_for_hasdistkey(PlannerInfo* root, List* subPlans, int subPlanNum, + List** subPlanKeyArray, Cost* subPlanCostArray, Bitmapset** redistributePlanSetCopy); +extern List* get_max_cost_distkey_for_nulldistkey( + PlannerInfo* root, List* subPlans, int subPlanNum, Cost* subPlanCostArray); +extern void parallel_stream_info_print(ParallelDesc* smpDesc, StreamType type); +extern List* make_distkey_for_append(PlannerInfo* root, Plan* subPlan); + +#endif /* STREAM_COST_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/streampath.h postgresql-hll-2.14/include/include/optimizer/streampath.h --- postgresql-hll-2.14_old/include/include/optimizer/streampath.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/streampath.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,356 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streampath.h + * functions for distribute join path generation in GaussDB + * + * + * IDENTIFICATION + * src/include/optimizer/streampath.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAMPATH_H +#define STREAMPATH_H + +#include "nodes/relation.h" +#include "optimizer/dataskew.h" +#include "optimizer/streamplan.h" + +class PathGen : public BaseObject { +public: + PathGen(PlannerInfo* root, RelOptInfo* rel); + + virtual ~PathGen(); + + /* Add a path to path list. */ + void addPath(Path* new_path); + +protected: + /* PlannerInfo for this path. */ + PlannerInfo* m_root; + + /* Rel info for this path. */ + RelOptInfo* m_rel; +}; + +class JoinPathGen : public PathGen { +public: + JoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, List* joinclauses, List* restrictinfo, + Path* outer_path, Path* inner_path, Relids required_outer); + + virtual ~JoinPathGen(); + +protected: + /* Init member variable. */ + void init(); + + /* Init if we need stream. */ + void initDistribution(); + + /* special process for list/range distributed table */ + void initRangeListDistribution(); + + /* Reset member variable for later use. */ + void reset(); + + /* Check if we can create parallel join path. */ + const bool isParallelEnable(); + + /* check if is a nestloop parameter path */ + const bool is_param_path(); + + /* Add join path to path list. */ + void addJoinPath(Path* path, List* desired_key, bool exact_match); + + /* Create stream path for join. */ + void addJoinStreamPath(); + + /* Add stream info for join. */ + void addJoinStreamInfo(); + + /* Add stream info for MPP structure. */ + void addStreamMppInfo(); + + /* Add stream info for multi node group execution. */ + void addStreamNodeGroupInfo(); + + /* Add stream info for parallel execution. */ + void addStreamParallelInfo(); + + /* Add stream info for skew optimization. */ + void addStreamSkewInfo(); + + /* Add parallel info for join. */ + bool addJoinParallelInfo(); + + /* Set base stream info. */ + void setStreamBaseInfo(StreamType inner_type, StreamType outer_type, List* inner_keys, List* outer_keys); + + /* Set stream info for multi nodegroup. */ + bool setStreamNodeGroupInfo(bool stream_outer); + + /* Set stream skew optimization info. */ + uint32 setStreamSkewInfo(); + + /* Set stream parallel execution info. */ + void setStreamParallelInfo(bool stream_outer, SmpStreamType sstype = PARALLEL_NONE); + + /* Check if we need local redistribute, */ + void parallelLocalRedistribute(bool* inner_can_local_distribute, bool* outer_can_local_distribute, + bool* inner_need_local_distribute, bool* outer_need_local_distribute); + + /* Find distribute keys for one join side. */ + List* getOthersideKey(bool stream_outer); + + /* Get distribute keys for join. */ + void getDistributeKeys( + List** distribute_keys_outer, List** distribute_keys_inner, List* desired_keys, bool exact_match); + + /* Check if we can alteer join method. */ + bool checkJoinMethodAlternative(bool* try_eq_related_indirectly); + + /* Check if the replicate path can do redistribute. */ + bool isReplicateJoinCanRedistribute(); + + /* Create stream path for join. */ + Path* streamSidePath(bool stream_outer); + + /* Create unique join path. */ + Path* makeJoinUniquePath(bool stream_outer, List* pathkeys); + + /* create a unique path for unique join with skewness at the no-unique side */ + Path* makeJoinSkewUniquePath(bool stream_outer, List* pathkeys); + + /* set distribute keys for join path. */ + const bool setJoinDistributeKeys(JoinPath* joinpath, List* desired_key = NIL, bool exact_match = false); + + /* create a new stream info pair from the old one. */ + void newStreamInfoPair(StreamInfoPair* streamInfoPair); + + /* Confirm the distribute keys in the target list of subpath. */ + void confirmDistributeKeys(StreamInfo* sinfo); + +protected: + /* Join method. */ + NodeTag m_joinmethod; + + /* Join type. */ + JoinType m_jointype; + + /* Save join type. */ + JoinType m_saveJointype; + + /* Cost work space for join. */ + JoinCostWorkspace* m_workspace; + + /* Special join info. */ + SpecialJoinInfo* m_sjinfo; + + /* Join facctors for semi and anti join. */ + SemiAntiJoinFactors* m_semifactors; + + /* Join clauses list. */ + List* m_joinClauses; + + /* Join restrict list. */ + List* m_joinRestrictinfo; + + /* path keys of the join. */ + List* m_pathkeys; + + /* Outer path of join. */ + Path* m_outerPath; + + /* Inner path of join. */ + Path* m_innerPath; + + /* Outer stream path created for join. */ + Path* m_outerStreamPath; + + /* Inner Stream path created for join. */ + Path* m_innerStreamPath; + + /* Outer rel info. */ + RelOptInfo* m_outerRel; + + /* Inner rel info. */ + RelOptInfo* m_innerRel; + + /* The set of required outer rels. */ + Relids m_requiredOuter; + + /* Resource owner for join generation. */ + ResourceOwner m_resourceOwner; + + /* The target distibution of node group. */ + Distribution* m_targetDistribution; + + /* The restrictinfo on which we can join directly. */ + List* m_rrinfoInner; + + /* The restrictinfo on which we can join directly. */ + List* m_rrinfoOuter; + + /* Distribute keys of inner stream. */ + List* m_distributeKeysInner; + + /* Distribute keys of outer stream. */ + List* m_distributeKeysOuter; + + /* Stream info pair. */ + StreamInfoPair* m_streamInfoPair; + + /* Stream info list for the join. */ + List* m_streamInfoList; + + /* Skew optimization info for join. */ + JoinSkewInfo* m_skewInfo; + + /* Skew mutiple for inner redistribute. */ + double m_multipleInner; + + /* Skew multiple for outer redistribute */ + double m_multipleOuter; + + /* Parallel degree for this join. */ + int m_dop; + + /* If the inner path is replicate. */ + bool m_replicateInner; + + /* If the outer path is replicate. */ + bool m_replicateOuter; + + /* If the inner path is rangelist. */ + bool m_rangelistInner; + + /* If the outer path is rangelist. */ + bool m_rangelistOuter; + + /* true if outer and inner path's rangelist boundary same. */ + bool m_sameBoundary; + + /* If we should redistribute the inner side. */ + bool m_redistributeInner; + + /* If we should redistribute the outer side. */ + bool m_redistributeOuter; + + /* If we can broadcast the inner side. */ + bool m_canBroadcastInner; + + /* If we can broadcast the outer side. */ + bool m_canBroadcastOuter; + + /* If we need shuffle the inner side. */ + bool m_needShuffleInner; + + /* If we need shuffle the outer side. */ + bool m_needShuffleOuter; +}; + +class HashJoinPathGen : public JoinPathGen { +public: + HashJoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrictlist, Relids required_outer, List* hashclauses); + + virtual ~HashJoinPathGen(); + + /* Create Hash join path and add it to path list. */ + void addHashJoinPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add hash join path to path list. */ + void addHashjoinPathToList(); + + /* Initial the cost of hash join. */ + void initialCostHashjoin(); + + /* Finalize the cost of hash join. */ + void finalCostHashjoin(HashPath* path, bool hasalternative); + + /* Create hash join path. */ + Path* createHashJoinPath(); + +private: + /* Hash clauses for hash join. */ + List* m_hashClauses; +}; + +class NestLoopPathGen : public JoinPathGen { +public: + NestLoopPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrictlist, List* pathkeys, Relids required_outer); + + virtual ~NestLoopPathGen(); + + /* Create nest loop path and add it to path list. */ + void addNestLoopPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add nest loop path to path list. */ + void addNestloopPathToList(); + + /* Initial the cost of nest loop join. */ + void initialCostNestloop(); + + /* Finalize the cost of nest loop join. */ + void finalCostNestloop(NestPath* path, bool hasalternative); + + /* Create nest loop path. */ + Path* createNestloopPath(); +}; + +class MergeJoinPathGen : public JoinPathGen { +public: + MergeJoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrict_clauses, List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, + List* innersortkeys); + + virtual ~MergeJoinPathGen(); + + /* Create merge join path and add to path list. */ + void addMergeJoinPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add merge join path to path list. */ + void addMergejoinPathToList(); + + /* Initial the cost of merge join. */ + void initialCostMergejoin(); + + /* Finalize the cost of merge join. */ + void finalCostMergejoin(MergePath* path, bool hasalternative); + + /* Create mergejoin path. */ + Path* createMergejoinPath(); + +private: + /* Merge clauses for merge join. */ + List* m_mergeClauses; + + /* Sort key of inner path. */ + List* m_innerSortKeys; + + /* Sort key of outer path. */ + List* m_outerSortKeys; +}; + +#endif /* STREAMPATH_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/streamplan.h postgresql-hll-2.14/include/include/optimizer/streamplan.h --- postgresql-hll-2.14_old/include/include/optimizer/streamplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/streamplan.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,187 @@ +/* --------------------------------------------------------------------------------------- + * + * streamplan.h + * prototypes for stream plan. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/streamplan.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAMPLAN_H +#define STREAMPLAN_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "optimizer/stream_check.h" +#include "optimizer/stream_cost.h" +#include "optimizer/stream_util.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +#define NOTPLANSHIPPING_LENGTH 256 + +typedef struct ShippingInfo { + bool need_log; + char not_shipping_reason[NOTPLANSHIPPING_LENGTH]; +} ShippingInfo; + +#ifndef STREAMPLAN +#define STREAMPLAN +#endif + +#define IS_STREAM (u_sess->opt_cxt.is_stream && !IsConnFromCoord()) +/* Is stream come from datanode for the scene of gpu acceleration. */ +#define IS_STREAM_DATANODE (u_sess->opt_cxt.is_stream && IsConnFromDatanode()) +#define INITIAL_PLAN_NODE_ID 1 +#define INITIAL_PARENT_NODE_ID 0 +#define FLAG_SERIALIZED_PLAN 'Z' +#define IS_STREAM_PLAN (IS_PGXC_COORDINATOR && IS_STREAM && check_stream_support()) +#define STREAM_IS_LOCAL_NODE(type) (type == LOCAL_DISTRIBUTE || type == LOCAL_ROUNDROBIN || type == LOCAL_BROADCAST) +#define SET_DOP(dop) (dop > 1 ? dop : 1) + +#define RANDOM_SHIPPABLE (u_sess->opt_cxt.is_randomfunc_shippable && IS_STREAM_PLAN) + +extern THR_LOCAL ShippingInfo notshippinginfo; + +#define STREAM_RECURSIVECTE_SUPPORTED (IS_STREAM_PLAN && u_sess->attr.attr_sql.enable_stream_recursive) + +#define NO_FORM_CLAUSE(query) ((!query->jointree || !query->jointree->fromlist) && (!query->setOperations)) + +extern char* StreamTypeToString(StreamType type); + +extern char* SmpStreamTypeToString(SmpStreamType type); + +typedef struct StreamInfo { + StreamType type; /* Stream type. */ + Path* subpath; /* Subpath for this stream path. */ + List* stream_keys; /* Distribute keys for this stream. */ + List* ssinfo; /* Skew info list. */ + ParallelDesc smpDesc; /* Parallel execution info. */ + double multiple; /* Skew multiple for redistribution. */ +} StreamInfo; + +typedef struct StreamInfoPair { + StreamInfo inner_info; /* Stream info for inner side of join. */ + StreamInfo outer_info; /* Stream info for outer side of join. */ + uint32 skew_optimize; +} StreamInfoPair; + +typedef enum StreamReason { + STREAMREASON_NONE = 0x00, + STREAMREASON_DISTRIBUTEKEY = 0x01, + STREAMREASON_NODEGROUP = 0x02 +} StreamReason; + +typedef Stream VecStream; + +typedef struct { + short nodeid; + volatile uint32 seed; + volatile bool initialized; +} IdGen; + +typedef struct { + short nodeid; + volatile uint64 seed; + volatile bool initialized; +} Id64Gen; + +extern Id64Gen gt_queryId; + +extern Plan* create_stream_plan(PlannerInfo* root, StreamPath* best_path); +extern uint32 generate_unique_id(IdGen* gen); +extern uint64 generate_unique_id64(Id64Gen* gen); +extern void set_default_stream(); +extern void set_stream_off(); +extern bool stream_walker(Node* node, void* context); +extern contain_func_context init_contain_func_context(List* funcids, bool find_all = false); +extern int2vector* get_baserel_distributekey_no(Oid relid); +extern List* build_baserel_distributekey(RangeTblEntry* rte, int relindex); +extern char locator_type_join(char inner_locator_type, char outer_locator_type); +extern void ProcessRangeListJoinType(Path* joinPath, Path* outerPath, Path* innerPath); +extern Plan* make_simple_RemoteQuery( + Plan* lefttree, PlannerInfo* root, bool is_subplan, ExecNodes* target_exec_nodes = NULL); +extern void add_remote_subplan(PlannerInfo* root, RemoteQuery* result_node); +extern void build_remote_subplanOrSQL(PlannerInfo* root, RemoteQuery* result_node); +extern ExecNodes* get_random_data_nodes(char locatortype, Plan* plan); +extern void inherit_plan_locator_info(Plan* plan, Plan* subplan); +extern void inherit_path_locator_info(Path* path, Path* subpath); +extern Path* create_stream_path(PlannerInfo* root, RelOptInfo* rel, StreamType type, List* distribute_keys, + List* pathkeys, Path* subpath, double skew, Distribution* target_distribution = NULL, ParallelDesc* smp_desc = NULL, + List* ssinfo = NIL); +extern bool is_execute_on_coordinator(Plan* plan); +extern bool is_execute_on_datanodes(Plan* plan); +extern bool is_execute_on_allnodes(Plan* plan); +extern bool is_replicated_plan(Plan* plan); +extern bool is_hashed_plan(Plan* plan); +extern bool is_rangelist_plan(Plan* plan); +extern ExecNodes* stream_merge_exec_nodes(Plan* lefttree, Plan* righttree); +extern ExecNodes* get_all_data_nodes(char locatortype); +extern void pushdown_execnodes(Plan* plan, ExecNodes* exec_nodes, bool add_node = false, bool only_nodelist = false); +extern void stream_join_plan(PlannerInfo* root, Plan* join_plan, JoinPath* join_path); +extern NodeDefinition* get_all_datanodes_def(); +extern List* distributeKeyIndex(PlannerInfo* root, List* distributed_keys, List* targetlist); +extern List* make_groupcl_for_append(PlannerInfo* root, List* targetlist); +extern bool is_broadcast_stream(Stream* stream); +extern bool is_redistribute_stream(Stream* stream); +extern bool is_gather_stream(Stream* stream); +extern bool is_hybid_stream(Stream* stream); +extern void mark_distribute_setop(PlannerInfo* root, Node* node, bool isunionall, bool canDiskeyChange); + +extern void foreign_qual_context_init(foreign_qual_context* context); +extern void foreign_qual_context_free(foreign_qual_context* context); +extern bool is_foreign_expr(Node* node, foreign_qual_context* context); +extern char get_locator_type(Plan* plan); +extern bool is_compatible_type(Oid type1, Oid type2); +extern bool is_args_type_compatible(OpExpr* op_expr); +extern void materialize_remote_query(Plan* result_plan, bool* materialized, bool sort_to_store); +extern Var* locate_distribute_var(Expr* node); +extern bool add_hashfilter_for_replication(PlannerInfo* root, Plan* plan, List* distribute_keys); +extern bool IsModifyTableForDfsTable(Plan* AppendNode); +extern void confirm_parallel_info(Plan* plan, int dop); +extern bool trivial_subqueryscan(SubqueryScan* plan); +extern Plan* add_broacast_under_local_sort(PlannerInfo* root, PlannerInfo* subroot, Plan* plan); +extern void disable_unshipped_log(Query* query, shipping_context* context); +extern void output_unshipped_log(); +extern void stream_walker_context_init(shipping_context *context); + +/* Function for smp. */ +extern ParallelDesc* create_smpDesc(int consumer_dop, int producer_dop, SmpStreamType smp_type); +extern Plan* create_local_gather(Plan* plan); +extern Plan* create_local_redistribute(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple); +extern uint2* get_bucketmap_by_execnode(ExecNodes* exec_node, PlannedStmt* plannedstmt); +extern Oid get_oridinary_or_foreign_relid(List* rtable); +extern uint2* GetGlobalStreamBucketMap(PlannedStmt* planned_stmt); +extern int pickup_random_datanode_from_plan(Plan* plan); +extern bool canSeparateComputeAndStorageGroupForDelete(PlannerInfo* root); +extern bool isAllParallelized(List* subplans); +extern List* getSubPlan(Plan* node, List* subplans, List* initplans); +extern char* GetStreamTypeStrOf(StreamPath* path); +extern void GetHashTableCount(Query* parse, List* cteList, int* ccontext); +extern bool IsBucketmapNeeded(PlannedStmt* pstmt); + +/* Macros for LZ4 error handle */ +#define validate_LZ4_compress_result(res, module, hint) \ + do { \ + if (unlikely(res < 0)) { \ + /* should never happen, otherwise bugs inside LZ4 */ \ + ereport(ERROR, \ + (errcode(ERRCODE_DATA_CORRUPTED), \ + errmodule(module), \ + errmsg("%s : LZ4_compress_default failed trying to compress the data", hint))); \ + } else if (unlikely(res == 0)) { \ + /* should never happen, otherwise bugs inside LZ4_COMPRESSBOUND */ \ + ereport(ERROR, \ + (errcode(ERRCODE_DATA_CORRUPTED), \ + errmodule(module), \ + errmsg("%s : LZ4_compress_default destination buffer couldn't hold all the information", hint))); \ + } \ + } while (0) +#endif /* STREAMPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/stream_remove.h postgresql-hll-2.14/include/include/optimizer/stream_remove.h --- postgresql-hll-2.14_old/include/include/optimizer/stream_remove.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/stream_remove.h 2020-12-12 17:06:43.240347948 +0800 @@ -0,0 +1,12 @@ +/** + * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved. + * + */ +#ifndef STREAM_REMOVE_H +#define STREAM_REMOVE_H +#include "nodes/plannodes.h" +#include "optimizer/pgxcplan.h" +void delete_redundant_streams_of_append_plan(const Append *append); +void delete_redundant_streams_of_remotequery(RemoteQuery *top_plan); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/stream_util.h postgresql-hll-2.14/include/include/optimizer/stream_util.h --- postgresql-hll-2.14_old/include/include/optimizer/stream_util.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/stream_util.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,85 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_util.h + * prototypes for stream plan utilities. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_util.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_UTIL_H +#define STREAM_UTIL_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +#define update_scan_list(root, lst, fromRTI, toRTI, rtiSize) \ + ((List*)update_scan_expr(root, (Node*)(lst), fromRTI, toRTI, rtiSize)) + +typedef struct { + Relids outer_relids; /* relids to judge if supplying parameters in subpath */ + Bitmapset *upper_params; + bool only_check_stream; /* if we should only check stream or also check paramterized path */ + bool under_materialize_all; /* if traversing under rescan-avoid materialize */ + bool has_stream; /* if there's stream node in the path */ + bool has_parameterized_path; /* If parameter is passed in the path */ + bool has_cstore_index_delta; /* if there is cstore index scan with delta data */ +} ContainStreamContext; + +typedef enum { + CPLN_DEFAULT = 0x00, + CPLN_ONE_WAY = 0x01, /* Search in one way without go into operators with many branchs */ + CPLN_NO_IGNORE_MATERIAL = 0x10 /* search all plannode, including material */ +} ContainPlanNodeMode; + +typedef struct { + bool collect_vars; + List* aggs; + List* vars; +} foreign_qual_context; + +/* the context for all subplans referenced by current node. */ +typedef struct { + List* org_subplans; /* subplans for planned stmt */ + List* org_initPlan; /* initPlan for planned stmt */ + List* subplan_plan_ids; /* subplans referenced by current node */ +} set_node_ref_subplan_context; + +typedef struct { + PlannerInfo* root; + Index* fromRTIs; + Index* toRTIs; + int rtiSize; +} update_scan_expr_context; + +extern void finalize_node_id(Plan* result_plan, int* plan_node_id, int* parent_node_id, int* num_streams, + int* num_plannodes, int* total_num_streams, int* max_push_sql_num, int* gather_count, List* subplans, + List* subroots, List** initplans, int* subplan_ids, bool is_under_stream, bool is_under_ctescan, + bool is_data_node_exec, bool is_read_only, NodeGroupInfoContext* node_group_info_context); +extern bool has_subplan( + Plan* result_plan, Plan* parent, ListCell* cell, bool is_left, List** initplans, bool is_search); +extern void stream_path_walker(Path* path, ContainStreamContext* context); +extern bool contain_special_plan_node(Plan* plan, NodeTag planTag, ContainPlanNodeMode mode = CPLN_DEFAULT); +extern void SerializePlan(Plan* node, PlannedStmt* planned_stmt, StringInfoData* str, int num_stream, int num_gather, + bool push_subplan = true); +extern char* DecompressSerializedPlan(const char* comp_plan_string, int cLen, int oLen); +extern char* CompressSerializedPlan(const char* plan_string, int* cLen); +extern List* contains_specified_func(Node* node, contain_func_context* context); +extern bool is_local_redistribute_needed(Plan* subplan); +extern bool foreign_qual_walker(Node* node, foreign_qual_context* context); +extern Oid get_hash_type(Oid type_in); +extern bool is_type_cast_hash_compatible(FuncExpr* func); +extern Plan* update_plan_refs(PlannerInfo* root, Plan* plan, Index* fromRTI, Index* toRTI, int rtiSize); +extern void set_node_ref_subplan_walker(Plan* result_plan, set_node_ref_subplan_context* context); +extern void StreamPlanWalker(PlannedStmt *pstmt, Plan *plan, bool *need); + +#endif /* STREAM_UTIL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/optimizer/subselect.h postgresql-hll-2.14/include/include/optimizer/subselect.h --- postgresql-hll-2.14_old/include/include/optimizer/subselect.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/subselect.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * subselect.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/subselect.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SUBSELECT_H +#define SUBSELECT_H + +#include "nodes/plannodes.h" +#include "nodes/relation.h" + +#define SUBLINK_COUNTER 100 + +typedef struct +{ + List *aggFuncsList; +} fetch_agg_funcs_context; + +extern void SS_process_ctes(PlannerInfo* root); +extern JoinExpr* convert_ANY_sublink_to_join( + PlannerInfo* root, SubLink* sublink, bool under_not, Relids available_rels); +extern JoinExpr* convert_EXISTS_sublink_to_join( + PlannerInfo* root, SubLink* sublink, bool under_not, Relids available_rels); +extern Node* convert_EXPR_sublink_to_join(PlannerInfo* root, Node** jtlink1, Node* inout_quals, SubLink* sublink, + Relids *available_rels, Node* all_quals, const char *refname = NULL); + +extern void convert_OREXISTS_to_join( + PlannerInfo* root, BoolExpr* or_clause, SubLink* exists_sublink, Node** jtlink1, Relids available_rels1, bool isnull); +extern void convert_ORANY_to_join( + PlannerInfo* root, BoolExpr* or_clause, SubLink* any_sublink, Node** jtlink1, Relids available_rels); + +extern Node* convert_OREXPR_to_join(PlannerInfo* root, BoolExpr* or_clause, OpExpr* op_expr, SubLink* expr_sublink, + Node** jtlink1, Relids *available_rels); + +extern void convert_ORCLAUSE_to_join(PlannerInfo* root, BoolExpr* or_clause, Node** jtlink1, Relids *available_rels1); +extern Node* SS_replace_correlation_vars(PlannerInfo* root, Node* expr); +extern Node* SS_process_sublinks(PlannerInfo* root, Node* expr, bool isQual); +extern void SS_finalize_plan(PlannerInfo* root, Plan* plan, bool attach_initplans); +extern Param* SS_make_initplan_from_plan( + PlannerInfo* root, Plan* plan, Oid resulttype, int32 resulttypmod, Oid resultcollation); +extern Param* assign_nestloop_param_var(PlannerInfo* root, Var* var); +extern Param* assign_nestloop_param_placeholdervar(PlannerInfo* root, PlaceHolderVar* phv); +extern int assignPartIteratorParam(PlannerInfo* root); + +extern int SS_assign_special_param(PlannerInfo* root); +extern bool check_var_nonnullable(Query* query, Node* node); + +#ifdef STREAMPLAN +extern void convert_multi_count_distinct(PlannerInfo* root); +#endif +extern List* pull_sublink(Node* node, int flag, bool is_name, bool recurse = false); +extern List* pull_opExpr(Node* node); +#endif /* SUBSELECT_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/tlist.h postgresql-hll-2.14/include/include/optimizer/tlist.h --- postgresql-hll-2.14_old/include/include/optimizer/tlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/tlist.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * tlist.h + * prototypes for tlist.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/tlist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TLIST_H +#define TLIST_H + +#include "optimizer/var.h" + +extern TargetEntry* tlist_member(Node* node, List* targetlist); +extern TargetEntry* tlist_member_ignore_relabel(Node* node, List* targetlist); +#ifdef STREAMPLAN +extern TargetEntry* tlist_member_except_aggref( + Node* node, List* targetlist, bool* nested_agg, bool* nested_relabeltype); +#endif + +extern List* flatten_tlist(List* tlist, PVCAggregateBehavior aggbehavior, PVCPlaceHolderBehavior phbehavior); +extern List* add_to_flat_tlist(List* tlist, List* exprs); + +extern List* get_tlist_exprs(List* tlist, bool includeJunk); +extern bool tlist_same_datatypes(List* tlist, List* colTypes, bool junkOK); +extern bool tlist_same_collations(List* tlist, List* colCollations, bool junkOK); + +extern TargetEntry* get_sortgroupref_tle(Index sortref, List* targetList, bool report_error = true); +extern TargetEntry* get_sortgroupclause_tle(SortGroupClause* sgClause, List* targetList, bool report_error = true); +extern Node* get_sortgroupclause_expr(SortGroupClause* sgClause, List* targetList); +extern List* get_sortgrouplist_exprs(List* sgClauses, List* targetList); + +extern SortGroupClause* get_sortgroupref_clause(Index sortref, List* clauses); +extern Oid* extract_grouping_ops(List* groupClause); +extern AttrNumber* extract_grouping_cols(List* groupClause, List* tlist); +extern bool grouping_is_sortable(List* groupClause); +extern bool grouping_is_hashable(List* groupClause); +extern bool grouping_is_distributable(List* groupClause, List* targetlist); +extern int get_grouping_column_index(Query* parse, TargetEntry* tle, List* groupClause); +extern List* make_agg_var_list(PlannerInfo* root, List* tlist, List** duplicate_tlist); +extern void get_tlist_group_vars_split(Query* parse, List* tlist, List** group_cols, List** non_group_cols); +extern List* get_dependency_var_list(Query* parse, List* group_cols, List* non_group_vars); +extern bool var_from_dependency_rel(Query* parse, Var* var, List* dep_oids); +extern bool var_from_sublink_pulluped(Query *parse, Var *var); +#endif /* TLIST_H */ diff -uprN postgresql-hll-2.14_old/include/include/optimizer/var.h postgresql-hll-2.14/include/include/optimizer/var.h --- postgresql-hll-2.14_old/include/include/optimizer/var.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/optimizer/var.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * var.h + * prototypes for optimizer/util/var.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/var.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VAR_H +#define VAR_H + +#include "nodes/relation.h" + +typedef enum { + PVC_REJECT_AGGREGATES, /* throw error if Aggref found */ + PVC_INCLUDE_AGGREGATES, /* include Aggrefs in output list */ + PVC_INCLUDE_AGGREGATES_OR_WINAGGS, + PVC_RECURSE_AGGREGATES /* recurse into Aggref arguments */ +} PVCAggregateBehavior; + +typedef enum { + PVC_REJECT_PLACEHOLDERS, /* throw error if PlaceHolderVar found */ + PVC_INCLUDE_PLACEHOLDERS, /* include PlaceHolderVars in output list */ + PVC_RECURSE_PLACEHOLDERS /* recurse into PlaceHolderVar arguments */ +} PVCPlaceHolderBehavior; + +/* + * When we evaluate distinct number and biase of exprs, we meet some special + * exprs that hard to give an accurate estimation + */ +typedef enum { + PVC_REJECT_SPECIAL_EXPR, /* skip if special exprs found */ + PVC_INCLUDE_SPECIAL_EXPR, /* include special nodes in output list */ + PVC_RECURSE_SPECIAL_EXPR /* recurse into special expr nodes */ +} PVCSPExprBehavior; + +/* + * Used by replace_node_clause as behavior flag. + * To mark wheather (1) go into Aggref, (2) copy non-leaf nodes, + * (3) only replace first target we meet. + */ +typedef enum { + RNC_NONE = 0x00u, + RNC_RECURSE_AGGREF = 0x01u, + RNC_COPY_NON_LEAF_NODES = 0x02u, + RNC_REPLACE_FIRST_ONLY = 0x04u +} ReplaceNodeClauseBehavior; + +extern Relids pull_varnos(Node* node, int level = 0, bool isSkip = false); +extern Relids pull_varnos_of_level(Node *node, int levelsup); +extern void pull_varattnos(Node* node, Index varno, Bitmapset** varattnos); +extern List *pull_vars_of_level(Node *node, int levelsup); +extern bool contain_var_clause(Node* node); +extern bool contain_vars_of_level(Node* node, int levelsup); +extern int locate_var_of_level(Node* node, int levelsup); +extern int locate_var_of_relation(Node* node, int relid, int levelsup); +extern int find_minimum_var_level(Node* node); +extern List* pull_var_clause(Node* node, PVCAggregateBehavior aggbehavior, PVCPlaceHolderBehavior phbehavior, + PVCSPExprBehavior spbehavior = PVC_RECURSE_SPECIAL_EXPR, bool includeUpperVars = false, + bool includeUpperAggrefs = false); +extern Node* flatten_join_alias_vars(PlannerInfo* root, Node* node); +extern Node* replace_node_clause_for_equality(Node* clause, List* src_list, Node* dest); +extern Node* replace_node_clause(Node* node, Node* src_list, Node* dest_list, uint32 rncbehavior); +extern bool check_node_clause(Node* clause, Node* node); +extern bool contain_vars_of_level_or_above(Node* node, int levelsup); + +extern bool check_param_clause(Node* clause); +extern Bitmapset* collect_param_clause(Node* clause); +extern bool check_param_expr(Node* node); +extern List* check_random_expr(Node* node); + +extern List* check_subplan_expr(Node* node, bool recurseSubPlan = false); +extern bool check_varno(Node* qual, int varno, int varlevelsup); +extern List* check_vartype(Node* node); +#endif /* VAR_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/analyze.h postgresql-hll-2.14/include/include/parser/analyze.h --- postgresql-hll-2.14_old/include/include/parser/analyze.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/analyze.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,94 @@ +/* ------------------------------------------------------------------------- + * + * analyze.h + * parse analysis for optimizable statements + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/analyze.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ANALYZE_H +#define ANALYZE_H + +#ifndef FRONTEND_PARSER +#include "parser/parse_node.h" +#include "utils/plancache.h" + +extern const char* const ANALYZE_TEMP_TABLE_PREFIX; + +/* Hook for plugins to get control at end of parse analysis */ +typedef void (*post_parse_analyze_hook_type)(ParseState* pstate, Query* query); + +extern THR_LOCAL PGDLLIMPORT post_parse_analyze_hook_type post_parse_analyze_hook; + +extern Query* parse_analyze(Node* parseTree, const char* sourceText, Oid* paramTypes, int numParams, + bool isFirstNode = true, bool isCreateView = false); +extern Query* parse_analyze_varparams(Node* parseTree, const char* sourceText, Oid** paramTypes, int* numParams); + +extern Query* parse_sub_analyze(Node* parseTree, ParseState* parentParseState, CommonTableExpr* parentCTE, + bool locked_from_parent, bool resolve_unknowns); + +extern List* transformInsertRow(ParseState* pstate, List* exprlist, List* stmtcols, List* icolumns, List* attrnos); +extern Query* transformTopLevelStmt( + ParseState* pstate, Node* parseTree, bool isFirstNode = true, bool isCreateView = false); +extern Query* transformStmt(ParseState* pstate, Node* parseTree, bool isFirstNode = true, bool isCreateView = false); + +extern bool analyze_requires_snapshot(Node* parseTree); + +extern void CheckSelectLocking(Query* qry); +extern void applyLockingClause(Query* qry, Index rtindex, bool forUpdate, bool noWait, bool pushedDown); +#ifdef ENABLE_MOT +extern void CheckTablesStorageEngine(Query* qry, StorageEngineType* type); +extern bool CheckMotIndexedColumnUpdate(Query* qry); + +typedef struct RTEDetectorContext { + bool isMotTable; + bool isPageTable; + List* queryNodes; + int sublevelsUp; +} RTEDetectorContext; + +typedef struct UpdateDetectorContext { + bool isIndexedColumnUpdate; + List* queryNodes; + int sublevelsUp; +} UpdateDetectorContext; +#endif + +/* Record the rel name and corresponding columan name info */ +typedef struct RelColumnInfo { + char* relname; + List* colnames; +} RelColumnInfo; + +typedef struct PlusJoinRTEItem { + RangeTblEntry* rte; /* The RTE that the column referennce */ + bool hasplus; /* Does the Expr contains ''(+)" ? */ +} PlusJoinRTEItem; + +typedef struct OperatorPlusProcessContext { + List* jointerms; /* List of Jointerm */ + bool contain_plus_outerjoin; + ParseState* ps; /* ParseState of Current level */ + Node** whereClause; + bool in_orclause; + bool contain_joinExpr; +} OperatorPlusProcessContext; + +extern void transformOperatorPlus(ParseState* pstate, Node** whereClause); +extern bool IsColumnRefPlusOuterJoin(const ColumnRef* cf); +extern PlusJoinRTEItem* makePlusJoinRTEItem(RangeTblEntry* rte, bool hasplus); +extern void setIgnorePlusFlag(ParseState* pstate, bool ignore); +extern void resetOperatorPlusFlag(); + +extern void fixResTargetNameWithTableNameRef(Relation rd, RangeVar* rel, ResTarget* res); +extern void fixResTargetListWithTableNameRef(Relation rd, RangeVar* rel, List* clause_list); +#endif /* !FRONTEND_PARSER */ + +extern bool getOperatorPlusFlag(); + +#endif /* ANALYZE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/backslash_quotes.h postgresql-hll-2.14/include/include/parser/backslash_quotes.h --- postgresql-hll-2.14_old/include/include/parser/backslash_quotes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/backslash_quotes.h 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * backslash_quotes.h + * + * IDENTIFICATION + * src\include\parser\backslash_quotes.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +typedef enum { + BACKSLASH_QUOTE_OFF, + BACKSLASH_QUOTE_ON, + BACKSLASH_QUOTE_SAFE_ENCODING +} BackslashQuoteType; diff -uprN postgresql-hll-2.14_old/include/include/parser/gram.hpp postgresql-hll-2.14/include/include/parser/gram.hpp --- postgresql-hll-2.14_old/include/include/parser/gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/gram.hpp 2020-12-12 17:06:43.241347961 +0800 @@ -0,0 +1,753 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_BASE_YY_GRAM_HPP_INCLUDED +# define YY_BASE_YY_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int base_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + IDENT = 258, + FCONST = 259, + SCONST = 260, + BCONST = 261, + XCONST = 262, + Op = 263, + CmpOp = 264, + COMMENTSTRING = 265, + ICONST = 266, + PARAM = 267, + TYPECAST = 268, + ORA_JOINOP = 269, + DOT_DOT = 270, + COLON_EQUALS = 271, + PARA_EQUALS = 272, + ABORT_P = 273, + ABSOLUTE_P = 274, + ACCESS = 275, + ACCOUNT = 276, + ACTION = 277, + ADD_P = 278, + ADMIN = 279, + AFTER = 280, + AGGREGATE = 281, + ALGORITHM = 282, + ALL = 283, + ALSO = 284, + ALTER = 285, + ALWAYS = 286, + ANALYSE = 287, + ANALYZE = 288, + AND = 289, + ANY = 290, + APP = 291, + ARRAY = 292, + AS = 293, + ASC = 294, + ASSERTION = 295, + ASSIGNMENT = 296, + ASYMMETRIC = 297, + AT = 298, + ATTRIBUTE = 299, + AUDIT = 300, + AUTHID = 301, + AUTHORIZATION = 302, + AUTOEXTEND = 303, + AUTOMAPPED = 304, + BACKWARD = 305, + BARRIER = 306, + BEFORE = 307, + BEGIN_NON_ANOYBLOCK = 308, + BEGIN_P = 309, + BETWEEN = 310, + BIGINT = 311, + BINARY = 312, + BINARY_DOUBLE = 313, + BINARY_INTEGER = 314, + BIT = 315, + BLOB_P = 316, + BOGUS = 317, + BOOLEAN_P = 318, + BOTH = 319, + BUCKETS = 320, + BY = 321, + BYTEAWITHOUTORDER = 322, + BYTEAWITHOUTORDERWITHEQUAL = 323, + CACHE = 324, + CALL = 325, + CALLED = 326, + CASCADE = 327, + CASCADED = 328, + CASE = 329, + CAST = 330, + CATALOG_P = 331, + CHAIN = 332, + CHAR_P = 333, + CHARACTER = 334, + CHARACTERISTICS = 335, + CHECK = 336, + CHECKPOINT = 337, + CLASS = 338, + CLEAN = 339, + CLIENT = 340, + CLIENT_MASTER_KEY = 341, + CLIENT_MASTER_KEYS = 342, + CLOB = 343, + CLOSE = 344, + CLUSTER = 345, + COALESCE = 346, + COLLATE = 347, + COLLATION = 348, + COLUMN = 349, + COLUMN_ARGS = 350, + COLUMN_ENCRYPTION_KEY = 351, + COLUMN_ENCRYPTION_KEYS = 352, + COLUMN_FUNCTION = 353, + COMMENT = 354, + COMMENTS = 355, + COMMIT = 356, + COMMITTED = 357, + COMPACT = 358, + COMPATIBLE_ILLEGAL_CHARS = 359, + COMPLETE = 360, + COMPRESS = 361, + CONCURRENTLY = 362, + CONDITION = 363, + CONFIGURATION = 364, + CONNECTION = 365, + CONSTRAINT = 366, + CONSTRAINTS = 367, + CONTENT_P = 368, + CONTINUE_P = 369, + CONTQUERY = 370, + CONVERSION_P = 371, + COORDINATOR = 372, + COORDINATORS = 373, + COPY = 374, + COST = 375, + CREATE = 376, + CROSS = 377, + CSV = 378, + CUBE = 379, + CURRENT_P = 380, + CURRENT_CATALOG = 381, + CURRENT_DATE = 382, + CURRENT_ROLE = 383, + CURRENT_SCHEMA = 384, + CURRENT_TIME = 385, + CURRENT_TIMESTAMP = 386, + CURRENT_USER = 387, + CURSOR = 388, + CYCLE = 389, + DATA_P = 390, + DATABASE = 391, + DATAFILE = 392, + DATANODE = 393, + DATANODES = 394, + DATATYPE_CL = 395, + DATE_P = 396, + DATE_FORMAT_P = 397, + DAY_P = 398, + DBCOMPATIBILITY_P = 399, + DEALLOCATE = 400, + DEC = 401, + DECIMAL_P = 402, + DECLARE = 403, + DECODE = 404, + DEFAULT = 405, + DEFAULTS = 406, + DEFERRABLE = 407, + DEFERRED = 408, + DEFINER = 409, + DELETE_P = 410, + DELIMITER = 411, + DELIMITERS = 412, + DELTA = 413, + DELTAMERGE = 414, + DESC = 415, + DETERMINISTIC = 416, + DICTIONARY = 417, + DIRECT = 418, + DIRECTORY = 419, + DISABLE_P = 420, + DISCARD = 421, + DISTINCT = 422, + DISTRIBUTE = 423, + DISTRIBUTION = 424, + DO = 425, + DOCUMENT_P = 426, + DOMAIN_P = 427, + DOUBLE_P = 428, + DROP = 429, + DUPLICATE = 430, + DISCONNECT = 431, + EACH = 432, + ELASTIC = 433, + ELSE = 434, + ENABLE_P = 435, + ENCODING = 436, + ENCRYPTED = 437, + ENCRYPTED_VALUE = 438, + ENCRYPTION = 439, + ENCRYPTION_TYPE = 440, + END_P = 441, + ENFORCED = 442, + ENUM_P = 443, + ERRORS = 444, + ESCAPE = 445, + EOL = 446, + ESCAPING = 447, + EVERY = 448, + EXCEPT = 449, + EXCHANGE = 450, + EXCLUDE = 451, + EXCLUDED = 452, + EXCLUDING = 453, + EXCLUSIVE = 454, + EXECUTE = 455, + EXISTS = 456, + EXPIRED_P = 457, + EXPLAIN = 458, + EXTENSION = 459, + EXTERNAL = 460, + EXTRACT = 461, + FALSE_P = 462, + FAMILY = 463, + FAST = 464, + FENCED = 465, + FETCH = 466, + FILEHEADER_P = 467, + FILL_MISSING_FIELDS = 468, + FILTER = 469, + FIRST_P = 470, + FIXED_P = 471, + FLOAT_P = 472, + FOLLOWING = 473, + FOR = 474, + FORCE = 475, + FOREIGN = 476, + FORMATTER = 477, + FORWARD = 478, + FREEZE = 479, + FROM = 480, + FULL = 481, + FUNCTION = 482, + FUNCTIONS = 483, + GLOBAL = 484, + GLOBAL_FUNCTION = 485, + GRANT = 486, + GRANTED = 487, + GREATEST = 488, + GROUP_P = 489, + GROUPING_P = 490, + HANDLER = 491, + HAVING = 492, + HDFSDIRECTORY = 493, + HEADER_P = 494, + HOLD = 495, + HOUR_P = 496, + IDENTIFIED = 497, + IDENTITY_P = 498, + IF_P = 499, + IGNORE_EXTRA_DATA = 500, + ILIKE = 501, + IMMEDIATE = 502, + IMMUTABLE = 503, + IMPLICIT_P = 504, + IN_P = 505, + INCLUDE = 506, + INCLUDING = 507, + INCREMENT = 508, + INCREMENTAL = 509, + INDEX = 510, + INDEXES = 511, + INHERIT = 512, + INHERITS = 513, + INITIAL_P = 514, + INITIALLY = 515, + INITRANS = 516, + INLINE_P = 517, + INNER_P = 518, + INOUT = 519, + INPUT_P = 520, + INSENSITIVE = 521, + INSERT = 522, + INSTEAD = 523, + INT_P = 524, + INTEGER = 525, + INTERNAL = 526, + INTERSECT = 527, + INTERVAL = 528, + INTO = 529, + INVOKER = 530, + IP = 531, + IS = 532, + ISNULL = 533, + ISOLATION = 534, + JOIN = 535, + KEY = 536, + KILL = 537, + KEY_PATH = 538, + KEY_STORE = 539, + LABEL = 540, + LANGUAGE = 541, + LARGE_P = 542, + LAST_P = 543, + LC_COLLATE_P = 544, + LC_CTYPE_P = 545, + LEADING = 546, + LEAKPROOF = 547, + LEAST = 548, + LESS = 549, + LEFT = 550, + LEVEL = 551, + LIKE = 552, + LIMIT = 553, + LIST = 554, + LISTEN = 555, + LOAD = 556, + LOCAL = 557, + LOCALTIME = 558, + LOCALTIMESTAMP = 559, + LOCATION = 560, + LOCK_P = 561, + LOG_P = 562, + LOGGING = 563, + LOGIN_ANY = 564, + LOGIN_FAILURE = 565, + LOGIN_SUCCESS = 566, + LOGOUT = 567, + LOOP = 568, + MAPPING = 569, + MASKING = 570, + MASTER = 571, + MATCH = 572, + MATERIALIZED = 573, + MATCHED = 574, + MAXEXTENTS = 575, + MAXSIZE = 576, + MAXTRANS = 577, + MAXVALUE = 578, + MERGE = 579, + MINUS_P = 580, + MINUTE_P = 581, + MINVALUE = 582, + MINEXTENTS = 583, + MODE = 584, + MODIFY_P = 585, + MONTH_P = 586, + MOVE = 587, + MOVEMENT = 588, + NAME_P = 589, + NAMES = 590, + NATIONAL = 591, + NATURAL = 592, + NCHAR = 593, + NEXT = 594, + NLSSORT = 595, + NO = 596, + NOCOMPRESS = 597, + NOCYCLE = 598, + NODE = 599, + NOLOGGING = 600, + NOMAXVALUE = 601, + NOMINVALUE = 602, + NONE = 603, + NOT = 604, + NOTHING = 605, + NOTIFY = 606, + NOTNULL = 607, + NOWAIT = 608, + NULL_P = 609, + NULLIF = 610, + NULLS_P = 611, + NUMBER_P = 612, + NUMERIC = 613, + NUMSTR = 614, + NVARCHAR2 = 615, + NVL = 616, + OBJECT_P = 617, + OF = 618, + OFF = 619, + OFFSET = 620, + OIDS = 621, + ON = 622, + ONLY = 623, + OPERATOR = 624, + OPTIMIZATION = 625, + OPTION = 626, + OPTIONS = 627, + OR = 628, + ORDER = 629, + OUT_P = 630, + OUTER_P = 631, + OVER = 632, + OVERLAPS = 633, + OVERLAY = 634, + OWNED = 635, + OWNER = 636, + PACKAGE = 637, + PARSER = 638, + PARTIAL = 639, + PARTITION = 640, + PARTITIONS = 641, + PASSING = 642, + PASSWORD = 643, + PCTFREE = 644, + PER_P = 645, + PERCENT = 646, + PERFORMANCE = 647, + PERM = 648, + PLACING = 649, + PLAN = 650, + PLANS = 651, + POLICY = 652, + POSITION = 653, + POOL = 654, + PRECEDING = 655, + PRECISION = 656, + PREFERRED = 657, + PREFIX = 658, + PRESERVE = 659, + PREPARE = 660, + PREPARED = 661, + PRIMARY = 662, + PRIVATE = 663, + PRIOR = 664, + PRIVILEGES = 665, + PRIVILEGE = 666, + PROCEDURAL = 667, + PROCEDURE = 668, + PROFILE = 669, + QUERY = 670, + QUOTE = 671, + RANDOMIZED = 672, + RANGE = 673, + RAW = 674, + READ = 675, + REAL = 676, + REASSIGN = 677, + REBUILD = 678, + RECHECK = 679, + RECURSIVE = 680, + REDISANYVALUE = 681, + REF = 682, + REFERENCES = 683, + REFRESH = 684, + REINDEX = 685, + REJECT_P = 686, + RELATIVE_P = 687, + RELEASE = 688, + RELOPTIONS = 689, + REMOTE_P = 690, + REMOVE = 691, + RENAME = 692, + REPEATABLE = 693, + REPLACE = 694, + REPLICA = 695, + RESET = 696, + RESIZE = 697, + RESOURCE = 698, + RESTART = 699, + RESTRICT = 700, + RETURN = 701, + RETURNING = 702, + RETURNS = 703, + REUSE = 704, + REVOKE = 705, + RIGHT = 706, + ROLE = 707, + ROLES = 708, + ROLLBACK = 709, + ROLLUP = 710, + ROW = 711, + ROWNUM = 712, + ROWS = 713, + RULE = 714, + SAVEPOINT = 715, + SCHEMA = 716, + SCROLL = 717, + SEARCH = 718, + SECOND_P = 719, + SECURITY = 720, + SELECT = 721, + SEQUENCE = 722, + SEQUENCES = 723, + SERIALIZABLE = 724, + SERVER = 725, + SESSION = 726, + SESSION_USER = 727, + SET = 728, + SETS = 729, + SETOF = 730, + SHARE = 731, + SHIPPABLE = 732, + SHOW = 733, + SHUTDOWN = 734, + SIMILAR = 735, + SIMPLE = 736, + SIZE = 737, + SLICE = 738, + SMALLDATETIME = 739, + SMALLDATETIME_FORMAT_P = 740, + SMALLINT = 741, + SNAPSHOT = 742, + SOME = 743, + SOURCE_P = 744, + SPACE = 745, + SPILL = 746, + SPLIT = 747, + STABLE = 748, + STANDALONE_P = 749, + START = 750, + STATEMENT = 751, + STATEMENT_ID = 752, + STATISTICS = 753, + STDIN = 754, + STDOUT = 755, + STORAGE = 756, + STORE_P = 757, + STREAM = 758, + STRICT_P = 759, + STRIP_P = 760, + SUBSTRING = 761, + SYMMETRIC = 762, + SYNONYM = 763, + SYSDATE = 764, + SYSID = 765, + SYSTEM_P = 766, + SYS_REFCURSOR = 767, + TABLE = 768, + TABLES = 769, + TABLESAMPLE = 770, + TABLESPACE = 771, + TEMP = 772, + TEMPLATE = 773, + TEMPORARY = 774, + TEXT_P = 775, + THAN = 776, + THEN = 777, + TIME = 778, + TIME_FORMAT_P = 779, + TIMESTAMP = 780, + TIMESTAMP_FORMAT_P = 781, + TIMESTAMPDIFF = 782, + TINYINT = 783, + TO = 784, + TRAILING = 785, + TRANSACTION = 786, + TREAT = 787, + TRIGGER = 788, + TRIM = 789, + TRUE_P = 790, + TRUNCATE = 791, + TRUSTED = 792, + TSFIELD = 793, + TSTAG = 794, + TSTIME = 795, + TYPE_P = 796, + TYPES_P = 797, + UNBOUNDED = 798, + UNCOMMITTED = 799, + UNENCRYPTED = 800, + UNION = 801, + UNIQUE = 802, + UNKNOWN = 803, + UNLIMITED = 804, + UNLISTEN = 805, + UNLOCK = 806, + UNLOGGED = 807, + UNTIL = 808, + UNUSABLE = 809, + UPDATE = 810, + USER = 811, + USING = 812, + VACUUM = 813, + VALID = 814, + VALIDATE = 815, + VALIDATION = 816, + VALIDATOR = 817, + VALUE_P = 818, + VALUES = 819, + VARCHAR = 820, + VARCHAR2 = 821, + VARIADIC = 822, + VARRAY = 823, + VARYING = 824, + VCGROUP = 825, + VERBOSE = 826, + VERIFY = 827, + VERSION_P = 828, + VIEW = 829, + VOLATILE = 830, + WEAK = 831, + WHEN = 832, + WHERE = 833, + WHITESPACE_P = 834, + WINDOW = 835, + WITH = 836, + WITHIN = 837, + WITHOUT = 838, + WORK = 839, + WORKLOAD = 840, + WRAPPER = 841, + WRITE = 842, + XML_P = 843, + XMLATTRIBUTES = 844, + XMLCONCAT = 845, + XMLELEMENT = 846, + XMLEXISTS = 847, + XMLFOREST = 848, + XMLPARSE = 849, + XMLPI = 850, + XMLROOT = 851, + XMLSERIALIZE = 852, + YEAR_P = 853, + YES_P = 854, + ZONE = 855, + NULLS_FIRST = 856, + NULLS_LAST = 857, + WITH_TIME = 858, + INCLUDING_ALL = 859, + RENAME_PARTITION = 860, + PARTITION_FOR = 861, + ADD_PARTITION = 862, + DROP_PARTITION = 863, + REBUILD_PARTITION = 864, + MODIFY_PARTITION = 865, + NOT_ENFORCED = 866, + VALID_BEGIN = 867, + DECLARE_CURSOR = 868, + PARTIAL_EMPTY_PREC = 869, + POSTFIXOP = 870, + UMINUS = 871 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 227 "gram.y" + + core_YYSTYPE core_yystype; + /* these fields must match core_YYSTYPE: */ + int ival; + char *str; + const char *keyword; + + char chr; + bool boolean; + JoinType jtype; + DropBehavior dbehavior; + OnCommitAction oncommit; + List *list; + Node *node; + Value *value; + ObjectType objtype; + TypeName *typnam; + FunctionParameter *fun_param; + FunctionParameterMode fun_param_mode; + FuncWithArgs *funwithargs; + DefElem *defelt; + SortBy *sortby; + WindowDef *windef; + JoinExpr *jexpr; + IndexElem *ielem; + Alias *alias; + RangeVar *range; + IntoClause *into; + WithClause *with; + A_Indices *aind; + ResTarget *target; + struct PrivTarget *privtarget; + AccessPriv *accesspriv; + InsertStmt *istmt; + VariableSetStmt *vsetstmt; +/* PGXC_BEGIN */ + DistributeBy *distby; + PGXCSubCluster *subclus; +/* PGXC_END */ + ForeignPartState *foreignpartby; + MergeWhenClause *mergewhen; + UpsertClause *upsert; + EncryptionType algtype; + + +/* Line 2058 of yacc.c */ +#line 719 "gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int base_yyparse (void *YYPARSE_PARAM); +#else +int base_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int base_yyparse (core_yyscan_t yyscanner); +#else +int base_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_BASE_YY_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/include/parser/gramparse.h postgresql-hll-2.14/include/include/parser/gramparse.h --- postgresql-hll-2.14_old/include/include/parser/gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/gramparse.h 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,165 @@ +/* ------------------------------------------------------------------------- + * + * gramparse.h + * Shared definitions for the "raw" parser (flex and bison phases only) + * + * NOTE: this file is only meant to be included in the core parsing files, + * ie, parser.c, gram.y, scan.l, and keywords.c. Definitions that are needed + * outside the core parser should be in parser.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/gramparse.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GRAMPARSE_H +#define GRAMPARSE_H + +#include "parser/scanner.h" + +/* + * NB: include gram.h only AFTER including scanner.h, because scanner.h + * is what #defines YYLTYPE. + */ + +#ifndef FRONTEND_PARSER +#ifdef PARSE_HINT_h +#include "parser/hint_gram.hpp" +#else +#include "parser/gram.hpp" +#endif +#else +#include "nodes/value.h" +#include "frontend_parser/gram.hpp" +#endif /* FRONTEND_PARSER */ + +/* When dealing with DECLARE foo CURSOR case, we must look ahead 2 token after DECLARE to meet CURSOR */ +#define MAX_LOOKAHEAD_NUM 2 + +/* + * The YY_EXTRA data that a flex scanner allows us to pass around. Private + * state needed for raw parsing/lexing goes here. + */ +typedef struct base_yy_extra_type { + /* + * Fields used by the core scanner. + */ + core_yy_extra_type core_yy_extra; + + /* + * State variables for base_yylex(). + */ + int lookahead_num; /* lookahead num. Currently can be:0,1,2 */ + int lookahead_token[MAX_LOOKAHEAD_NUM]; /* token lookahead type */ + core_YYSTYPE lookahead_yylval[MAX_LOOKAHEAD_NUM]; /* yylval for lookahead token */ + YYLTYPE lookahead_yylloc[MAX_LOOKAHEAD_NUM]; /* yylloc for lookahead token */ + + /* + * State variables that belong to the grammar. + */ + List* parsetree; /* final parse result is delivered here */ +} base_yy_extra_type; + +#ifdef FRONTEND_PARSER +typedef struct fe_base_yy_extra_type { + /* + * Fields used by the core scanner. + */ + fe_core_yy_extra_type core_yy_extra; + + /* + * State variables for base_yylex(). + */ + int lookahead_num; /* lookahead num. Currently can be:0,1,2 */ + int lookahead_token[MAX_LOOKAHEAD_NUM]; /* token lookahead type */ + core_YYSTYPE lookahead_yylval[MAX_LOOKAHEAD_NUM]; /* yylval for lookahead token */ + YYLTYPE lookahead_yylloc[MAX_LOOKAHEAD_NUM]; /* yylloc for lookahead token */ + + /* + * State variables that belong to the grammar. + */ + List *parsetree; /* final parse result is delivered here */ +} fe_base_yy_extra_type; + +#endif /* FRONTEND_PARSER */ + +typedef struct hint_yy_extra_type { + /* + * The string the scanner is physically scanning. We keep this mainly so + * that we can cheaply compute the offset of the current token (yytext). + */ + char* scanbuf; + Size scanbuflen; + + /* + * The keyword list to use. + */ + const ScanKeyword* keywords; + int num_keywords; + + /* + * literalbuf is used to accumulate literal values when multiple rules are + * needed to parse a single literal. Call startlit() to reset buffer to + * empty, addlit() to add text. NOTE: the string in literalbuf is NOT + * necessarily null-terminated, but there always IS room to add a trailing + * null at offset literallen. We store a null only when we need it. + */ + char* literalbuf; /* palloc'd expandable buffer */ + int literallen; /* actual current string length */ + int literalalloc; /* current allocated buffer size */ + + int xcdepth; /* depth of nesting in slash-star comments */ + char* dolqstart; /* current $foo$ quote start string */ + + /* first part of UTF16 surrogate pair for Unicode escapes */ + int32 utf16_first_part; + + /* state variables for literal-lexing warnings */ + bool warn_on_first_escape; + bool saw_non_ascii; + bool ident_quoted; + bool warnOnTruncateIdent; + + /* record the message need by multi-query. */ + List* query_string_locationlist; /* record the end location of each single query */ + bool in_slash_proc_body; /* check whether it's in a slash proc body */ + int paren_depth; /* record the current depth in the '(' and ')' */ + bool is_createstmt; /* check whether it's a create statement. */ + bool is_hint_str; /* current identifier is in hint comment string */ + List* parameter_list; /* placeholder parameter list */ +} hint_yy_extra_type; + +#ifdef PARSE_HINT_h +extern int yylex(YYSTYPE* lvalp, yyscan_t yyscanner); +extern int yyparse(yyscan_t yyscanner); +#else + +/* + * In principle we should use yyget_extra() to fetch the yyextra field + * from a yyscanner struct. However, flex always puts that field first, + * and this is sufficiently performance-critical to make it seem worth + * cheating a bit to use an inline macro. + */ +#define pg_yyget_extra(yyscanner) (*((base_yy_extra_type**)(yyscanner))) + +#ifdef FRONTEND_PARSER +#define fe_pg_yyget_extra(yyscanner) (*((fe_base_yy_extra_type **) (yyscanner))) +#endif /* FRONTEND_PARSER */ + +/* from parser.c */ +extern int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner); + +/* from gram.y */ +extern void parser_init(base_yy_extra_type* yyext); +extern int base_yyparse(core_yyscan_t yyscanner); + +#ifdef FRONTEND_PARSER +extern void fe_parser_init(fe_base_yy_extra_type *yyext); +#endif /* FRONTEND_PARSER */ + +#endif + +#endif /* GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/hint_gram.hpp postgresql-hll-2.14/include/include/parser/hint_gram.hpp --- postgresql-hll-2.14_old/include/include/parser/hint_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/hint_gram.hpp 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,113 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_YY_HINT_GRAM_HPP_INCLUDED +# define YY_YY_HINT_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + IDENT = 258, + FCONST = 259, + SCONST = 260, + BCONST = 261, + XCONST = 262, + ICONST = 263, + NestLoop_P = 264, + MergeJoin_P = 265, + HashJoin_P = 266, + No_P = 267, + Leading_P = 268, + Rows_P = 269, + Broadcast_P = 270, + Redistribute_P = 271, + BlockName_P = 272, + TableScan_P = 273, + IndexScan_P = 274, + IndexOnlyScan_P = 275, + Skew_P = 276, + HINT_MULTI_NODE_P = 277, + NULL_P = 278, + TRUE_P = 279, + FALSE_P = 280, + Predpush_P = 281, + Rewrite_P = 282 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 41 "hint_gram.y" + + int ival; + char *str; + List *list; + Node *node; + + +/* Line 2058 of yacc.c */ +#line 92 "hint_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (yyscan_t yyscanner); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_YY_HINT_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/include/parser/keywords.h postgresql-hll-2.14/include/include/parser/keywords.h --- postgresql-hll-2.14_old/include/include/parser/keywords.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/keywords.h 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * keywords.h + * lexical token lookup for key words in PostgreSQL + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/keywords.h + * + * ------------------------------------------------------------------------- + */ +#ifndef KEYWORDS_H +#define KEYWORDS_H + +/* Keyword categories --- should match lists in gram.y */ +#define UNRESERVED_KEYWORD 0 +#define COL_NAME_KEYWORD 1 +#define TYPE_FUNC_NAME_KEYWORD 2 +#define RESERVED_KEYWORD 3 + +typedef struct ScanKeyword { + const char* name; /* in lower case */ + int16 value; /* grammar's token code */ + int16 category; /* see codes above */ +} ScanKeyword; + +extern PGDLLIMPORT const ScanKeyword ScanKeywords[]; +extern PGDLLIMPORT const int NumScanKeywords; + +/* Globals from keywords.c */ +extern const ScanKeyword SQLScanKeywords[]; +extern const int NumSQLScanKeywords; + +extern const ScanKeyword* ScanKeywordLookup(const char* text, const ScanKeyword* keywords, int num_keywords); + +#endif /* KEYWORDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/kwlist.h postgresql-hll-2.14/include/include/parser/kwlist.h --- postgresql-hll-2.14_old/include/include/parser/kwlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/kwlist.h 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,625 @@ +/* ------------------------------------------------------------------------- + * + * kwlist.h + * + * The keyword list is kept in its own source file for possible use by + * automatic tools. The exact representation of a keyword is determined + * by the PG_KEYWORD macro, which is not defined in this file; it can + * be defined by the caller for special purposes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/parser/kwlist.h + * + * ------------------------------------------------------------------------- + */ + +/* there is deliberately not an #ifndef KWLIST_H here */ + +/* + * List of keyword (name, token-value, category) entries. + * + * !!WARNING!!: This list must be sorted by ASCII name, because binary + * search is used to locate entries. + */ + +/* name, value, category */ +PG_KEYWORD("abort", ABORT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("absolute", ABSOLUTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("access", ACCESS, UNRESERVED_KEYWORD) +PG_KEYWORD("account", ACCOUNT, UNRESERVED_KEYWORD) +PG_KEYWORD("action", ACTION, UNRESERVED_KEYWORD) +PG_KEYWORD("add", ADD_P, UNRESERVED_KEYWORD) +PG_KEYWORD("admin", ADMIN, UNRESERVED_KEYWORD) +PG_KEYWORD("after", AFTER, UNRESERVED_KEYWORD) +PG_KEYWORD("aggregate", AGGREGATE, UNRESERVED_KEYWORD) +PG_KEYWORD("algorithm", ALGORITHM, UNRESERVED_KEYWORD) +PG_KEYWORD("all", ALL, RESERVED_KEYWORD) +PG_KEYWORD("also", ALSO, UNRESERVED_KEYWORD) +PG_KEYWORD("alter", ALTER, UNRESERVED_KEYWORD) +PG_KEYWORD("always", ALWAYS, UNRESERVED_KEYWORD) +PG_KEYWORD("analyse", ANALYSE, RESERVED_KEYWORD) /* British spelling */ +PG_KEYWORD("analyze", ANALYZE, RESERVED_KEYWORD) +PG_KEYWORD("and", AND, RESERVED_KEYWORD) +PG_KEYWORD("any", ANY, RESERVED_KEYWORD) +PG_KEYWORD("app", APP, UNRESERVED_KEYWORD) +PG_KEYWORD("array", ARRAY, RESERVED_KEYWORD) +PG_KEYWORD("as", AS, RESERVED_KEYWORD) +PG_KEYWORD("asc", ASC, RESERVED_KEYWORD) +PG_KEYWORD("assertion", ASSERTION, UNRESERVED_KEYWORD) +PG_KEYWORD("assignment", ASSIGNMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("asymmetric", ASYMMETRIC, RESERVED_KEYWORD) +PG_KEYWORD("at", AT, UNRESERVED_KEYWORD) +PG_KEYWORD("attribute", ATTRIBUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("audit", AUDIT, UNRESERVED_KEYWORD) +PG_KEYWORD("authid", AUTHID, RESERVED_KEYWORD) +PG_KEYWORD("authorization", AUTHORIZATION, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("autoextend", AUTOEXTEND, UNRESERVED_KEYWORD) +PG_KEYWORD("automapped", AUTOMAPPED, UNRESERVED_KEYWORD) +PG_KEYWORD("backward", BACKWARD, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("barrier", BARRIER, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("before", BEFORE, UNRESERVED_KEYWORD) +PG_KEYWORD("begin", BEGIN_P, UNRESERVED_KEYWORD) +PG_KEYWORD("begin_non_anoyblock", BEGIN_NON_ANOYBLOCK, UNRESERVED_KEYWORD) +PG_KEYWORD("between", BETWEEN, COL_NAME_KEYWORD) +PG_KEYWORD("bigint", BIGINT, COL_NAME_KEYWORD) +PG_KEYWORD("binary", BINARY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("binary_double", BINARY_DOUBLE, COL_NAME_KEYWORD) +PG_KEYWORD("binary_integer", BINARY_INTEGER, COL_NAME_KEYWORD) +PG_KEYWORD("bit", BIT, COL_NAME_KEYWORD) +PG_KEYWORD("blob", BLOB_P, UNRESERVED_KEYWORD) +PG_KEYWORD("boolean", BOOLEAN_P, COL_NAME_KEYWORD) +PG_KEYWORD("both", BOTH, RESERVED_KEYWORD) +PG_KEYWORD("buckets", BUCKETS, RESERVED_KEYWORD) +PG_KEYWORD("by", BY, UNRESERVED_KEYWORD) +PG_KEYWORD("byteawithoutorder", BYTEAWITHOUTORDER, COL_NAME_KEYWORD) +PG_KEYWORD("byteawithoutorderwithequal", BYTEAWITHOUTORDERWITHEQUAL, COL_NAME_KEYWORD) +PG_KEYWORD("cache", CACHE, UNRESERVED_KEYWORD) +PG_KEYWORD("call", CALL, UNRESERVED_KEYWORD) +PG_KEYWORD("called", CALLED, UNRESERVED_KEYWORD) +PG_KEYWORD("cascade", CASCADE, UNRESERVED_KEYWORD) +PG_KEYWORD("cascaded", CASCADED, UNRESERVED_KEYWORD) +PG_KEYWORD("case", CASE, RESERVED_KEYWORD) +PG_KEYWORD("cast", CAST, RESERVED_KEYWORD) +PG_KEYWORD("catalog", CATALOG_P, UNRESERVED_KEYWORD) +PG_KEYWORD("chain", CHAIN, UNRESERVED_KEYWORD) +PG_KEYWORD("char", CHAR_P, COL_NAME_KEYWORD) +PG_KEYWORD("character", CHARACTER, COL_NAME_KEYWORD) +PG_KEYWORD("characteristics", CHARACTERISTICS, UNRESERVED_KEYWORD) +PG_KEYWORD("check", CHECK, RESERVED_KEYWORD) +PG_KEYWORD("checkpoint", CHECKPOINT, UNRESERVED_KEYWORD) +PG_KEYWORD("class", CLASS, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("clean", CLEAN, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("client", CLIENT, UNRESERVED_KEYWORD) +PG_KEYWORD("client_master_key", CLIENT_MASTER_KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("client_master_keys", CLIENT_MASTER_KEYS, UNRESERVED_KEYWORD) +PG_KEYWORD("clob", CLOB, UNRESERVED_KEYWORD) +PG_KEYWORD("close", CLOSE, UNRESERVED_KEYWORD) +PG_KEYWORD("cluster", CLUSTER, UNRESERVED_KEYWORD) +PG_KEYWORD("coalesce", COALESCE, COL_NAME_KEYWORD) +PG_KEYWORD("collate", COLLATE, RESERVED_KEYWORD) +PG_KEYWORD("collation", COLLATION, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("column", COLUMN, RESERVED_KEYWORD) +PG_KEYWORD("column_args", COLUMN_ARGS, UNRESERVED_KEYWORD) +PG_KEYWORD("column_encryption_key", COLUMN_ENCRYPTION_KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("column_encryption_keys", COLUMN_ENCRYPTION_KEYS, UNRESERVED_KEYWORD) +PG_KEYWORD("column_function", COLUMN_FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("comment", COMMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("comments", COMMENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("commit", COMMIT, UNRESERVED_KEYWORD) +PG_KEYWORD("committed", COMMITTED, UNRESERVED_KEYWORD) +PG_KEYWORD("compact", COMPACT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("compatible_illegal_chars", COMPATIBLE_ILLEGAL_CHARS, UNRESERVED_KEYWORD) +PG_KEYWORD("complete", COMPLETE, UNRESERVED_KEYWORD) +PG_KEYWORD("compress", COMPRESS, UNRESERVED_KEYWORD) +PG_KEYWORD("concurrently", CONCURRENTLY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("condition", CONDITION, UNRESERVED_KEYWORD) +PG_KEYWORD("configuration", CONFIGURATION, UNRESERVED_KEYWORD) +PG_KEYWORD("connection", CONNECTION, UNRESERVED_KEYWORD) +PG_KEYWORD("constraint", CONSTRAINT, RESERVED_KEYWORD) +PG_KEYWORD("constraints", CONSTRAINTS, UNRESERVED_KEYWORD) +PG_KEYWORD("content", CONTENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("continue", CONTINUE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("contquery", CONTQUERY, RESERVED_KEYWORD) +PG_KEYWORD("conversion", CONVERSION_P, UNRESERVED_KEYWORD) +PG_KEYWORD("coordinator", COORDINATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("coordinators", COORDINATORS, UNRESERVED_KEYWORD) +PG_KEYWORD("copy", COPY, UNRESERVED_KEYWORD) +PG_KEYWORD("cost", COST, UNRESERVED_KEYWORD) +PG_KEYWORD("create", CREATE, RESERVED_KEYWORD) +PG_KEYWORD("cross", CROSS, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("csv", CSV, UNRESERVED_KEYWORD) +PG_KEYWORD("cube", CUBE, UNRESERVED_KEYWORD) +PG_KEYWORD("current", CURRENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD) +PG_KEYWORD("current_date", CURRENT_DATE, RESERVED_KEYWORD) +PG_KEYWORD("current_role", CURRENT_ROLE, RESERVED_KEYWORD) +PG_KEYWORD("current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("current_time", CURRENT_TIME, RESERVED_KEYWORD) +PG_KEYWORD("current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD) +PG_KEYWORD("current_user", CURRENT_USER, RESERVED_KEYWORD) +PG_KEYWORD("cursor", CURSOR, UNRESERVED_KEYWORD) +PG_KEYWORD("cycle", CYCLE, UNRESERVED_KEYWORD) +PG_KEYWORD("data", DATA_P, UNRESERVED_KEYWORD) +PG_KEYWORD("database", DATABASE, UNRESERVED_KEYWORD) +PG_KEYWORD("datafile", DATAFILE, UNRESERVED_KEYWORD) +PG_KEYWORD("datanode", DATANODE, UNRESERVED_KEYWORD) +PG_KEYWORD("datanodes", DATANODES, UNRESERVED_KEYWORD) +PG_KEYWORD("datatype_cl", DATATYPE_CL, UNRESERVED_KEYWORD) +PG_KEYWORD("date", DATE_P, COL_NAME_KEYWORD) +PG_KEYWORD("date_format", DATE_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("day", DAY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("dbcompatibility", DBCOMPATIBILITY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("deallocate", DEALLOCATE, UNRESERVED_KEYWORD) +PG_KEYWORD("dec", DEC, COL_NAME_KEYWORD) +PG_KEYWORD("decimal", DECIMAL_P, COL_NAME_KEYWORD) +PG_KEYWORD("declare", DECLARE, UNRESERVED_KEYWORD) +PG_KEYWORD("decode", DECODE, COL_NAME_KEYWORD) +PG_KEYWORD("default", DEFAULT, RESERVED_KEYWORD) +PG_KEYWORD("defaults", DEFAULTS, UNRESERVED_KEYWORD) +PG_KEYWORD("deferrable", DEFERRABLE, RESERVED_KEYWORD) +PG_KEYWORD("deferred", DEFERRED, UNRESERVED_KEYWORD) +PG_KEYWORD("definer", DEFINER, UNRESERVED_KEYWORD) +PG_KEYWORD("delete", DELETE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("delimiter", DELIMITER, UNRESERVED_KEYWORD) +PG_KEYWORD("delimiters", DELIMITERS, UNRESERVED_KEYWORD) +PG_KEYWORD("delta", DELTA, UNRESERVED_KEYWORD) +PG_KEYWORD("deltamerge", DELTAMERGE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("desc", DESC, RESERVED_KEYWORD) +PG_KEYWORD("deterministic", DETERMINISTIC, UNRESERVED_KEYWORD) +PG_KEYWORD("dictionary", DICTIONARY, UNRESERVED_KEYWORD) +PG_KEYWORD("direct", DIRECT, UNRESERVED_KEYWORD) +PG_KEYWORD("directory", DIRECTORY, UNRESERVED_KEYWORD) +PG_KEYWORD("disable", DISABLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("discard", DISCARD, UNRESERVED_KEYWORD) +PG_KEYWORD("disconnect", DISCONNECT, UNRESERVED_KEYWORD) +PG_KEYWORD("distinct", DISTINCT, RESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("distribute", DISTRIBUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("distribution", DISTRIBUTION, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("do", DO, RESERVED_KEYWORD) +PG_KEYWORD("document", DOCUMENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("domain", DOMAIN_P, UNRESERVED_KEYWORD) +PG_KEYWORD("double", DOUBLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("drop", DROP, UNRESERVED_KEYWORD) +PG_KEYWORD("duplicate", DUPLICATE, UNRESERVED_KEYWORD) +PG_KEYWORD("each", EACH, UNRESERVED_KEYWORD) +PG_KEYWORD("elastic", ELASTIC, UNRESERVED_KEYWORD) +PG_KEYWORD("else", ELSE, RESERVED_KEYWORD) +PG_KEYWORD("enable", ENABLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("encoding", ENCODING, UNRESERVED_KEYWORD) +PG_KEYWORD("encrypted", ENCRYPTED, UNRESERVED_KEYWORD) +PG_KEYWORD("encrypted_value", ENCRYPTED_VALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("encryption", ENCRYPTION, UNRESERVED_KEYWORD) +PG_KEYWORD("encryption_type", ENCRYPTION_TYPE, UNRESERVED_KEYWORD) +PG_KEYWORD("end", END_P, RESERVED_KEYWORD) +PG_KEYWORD("enforced", ENFORCED, UNRESERVED_KEYWORD) +PG_KEYWORD("enum", ENUM_P, UNRESERVED_KEYWORD) +PG_KEYWORD("eol", EOL, UNRESERVED_KEYWORD) +PG_KEYWORD("errors", ERRORS, UNRESERVED_KEYWORD) +PG_KEYWORD("escape", ESCAPE, UNRESERVED_KEYWORD) +PG_KEYWORD("escaping", ESCAPING, UNRESERVED_KEYWORD) +PG_KEYWORD("every", EVERY, UNRESERVED_KEYWORD) +PG_KEYWORD("except", EXCEPT, RESERVED_KEYWORD) +PG_KEYWORD("exchange", EXCHANGE, UNRESERVED_KEYWORD) +PG_KEYWORD("exclude", EXCLUDE, UNRESERVED_KEYWORD) +#ifndef ENABLE_MULTIPLE_NODES +PG_KEYWORD("excluded", EXCLUDED, RESERVED_KEYWORD) +#endif +PG_KEYWORD("excluding", EXCLUDING, UNRESERVED_KEYWORD) +PG_KEYWORD("exclusive", EXCLUSIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("execute", EXECUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("exists", EXISTS, COL_NAME_KEYWORD) +PG_KEYWORD("expired", EXPIRED_P, UNRESERVED_KEYWORD) +PG_KEYWORD("explain", EXPLAIN, UNRESERVED_KEYWORD) +PG_KEYWORD("extension", EXTENSION, UNRESERVED_KEYWORD) +PG_KEYWORD("external", EXTERNAL, UNRESERVED_KEYWORD) +PG_KEYWORD("extract", EXTRACT, COL_NAME_KEYWORD) +PG_KEYWORD("false", FALSE_P, RESERVED_KEYWORD) +PG_KEYWORD("family", FAMILY, UNRESERVED_KEYWORD) +PG_KEYWORD("fast", FAST, UNRESERVED_KEYWORD) +PG_KEYWORD("fenced", FENCED, RESERVED_KEYWORD) +PG_KEYWORD("fetch", FETCH, RESERVED_KEYWORD) +PG_KEYWORD("fileheader", FILEHEADER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("fill_missing_fields", FILL_MISSING_FIELDS, UNRESERVED_KEYWORD) +PG_KEYWORD("filter", FILTER, UNRESERVED_KEYWORD) +PG_KEYWORD("first", FIRST_P, UNRESERVED_KEYWORD) +PG_KEYWORD("fixed", FIXED_P, UNRESERVED_KEYWORD) +PG_KEYWORD("float", FLOAT_P, COL_NAME_KEYWORD) +PG_KEYWORD("following", FOLLOWING, UNRESERVED_KEYWORD) +PG_KEYWORD("for", FOR, RESERVED_KEYWORD) +PG_KEYWORD("force", FORCE, UNRESERVED_KEYWORD) +PG_KEYWORD("foreign", FOREIGN, RESERVED_KEYWORD) +PG_KEYWORD("formatter", FORMATTER, UNRESERVED_KEYWORD) +PG_KEYWORD("forward", FORWARD, UNRESERVED_KEYWORD) +PG_KEYWORD("freeze", FREEZE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("from", FROM, RESERVED_KEYWORD) +PG_KEYWORD("full", FULL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("function", FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("functions", FUNCTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("global", GLOBAL, UNRESERVED_KEYWORD) +PG_KEYWORD("global_function", GLOBAL_FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("grant", GRANT, RESERVED_KEYWORD) +PG_KEYWORD("granted", GRANTED, UNRESERVED_KEYWORD) +PG_KEYWORD("greatest", GREATEST, COL_NAME_KEYWORD) +PG_KEYWORD("group", GROUP_P, RESERVED_KEYWORD) +PG_KEYWORD("grouping", GROUPING_P, COL_NAME_KEYWORD) +PG_KEYWORD("handler", HANDLER, UNRESERVED_KEYWORD) +PG_KEYWORD("having", HAVING, RESERVED_KEYWORD) +PG_KEYWORD("hdfsdirectory", HDFSDIRECTORY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("header", HEADER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("hold", HOLD, UNRESERVED_KEYWORD) +PG_KEYWORD("hour", HOUR_P, UNRESERVED_KEYWORD) +/* new key-word for ALTER ROLE */ +PG_KEYWORD("identified", IDENTIFIED, UNRESERVED_KEYWORD) +PG_KEYWORD("identity", IDENTITY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("if", IF_P, UNRESERVED_KEYWORD) +PG_KEYWORD("ignore_extra_data", IGNORE_EXTRA_DATA, UNRESERVED_KEYWORD) +PG_KEYWORD("ilike", ILIKE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("immediate", IMMEDIATE, UNRESERVED_KEYWORD) +PG_KEYWORD("immutable", IMMUTABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("implicit", IMPLICIT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("in", IN_P, RESERVED_KEYWORD) +PG_KEYWORD("include", INCLUDE, UNRESERVED_KEYWORD) +PG_KEYWORD("including", INCLUDING, UNRESERVED_KEYWORD) +PG_KEYWORD("increment", INCREMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("incremental", INCREMENTAL, UNRESERVED_KEYWORD) +PG_KEYWORD("index", INDEX, UNRESERVED_KEYWORD) +PG_KEYWORD("indexes", INDEXES, UNRESERVED_KEYWORD) +PG_KEYWORD("inherit", INHERIT, UNRESERVED_KEYWORD) +PG_KEYWORD("inherits", INHERITS, UNRESERVED_KEYWORD) +PG_KEYWORD("initial", INITIAL_P, UNRESERVED_KEYWORD) +PG_KEYWORD("initially", INITIALLY, RESERVED_KEYWORD) +PG_KEYWORD("initrans", INITRANS, UNRESERVED_KEYWORD) +PG_KEYWORD("inline", INLINE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("inner", INNER_P, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("inout", INOUT, COL_NAME_KEYWORD) +PG_KEYWORD("input", INPUT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("insensitive", INSENSITIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("insert", INSERT, UNRESERVED_KEYWORD) +PG_KEYWORD("instead", INSTEAD, UNRESERVED_KEYWORD) +PG_KEYWORD("int", INT_P, COL_NAME_KEYWORD) +PG_KEYWORD("integer", INTEGER, COL_NAME_KEYWORD) +PG_KEYWORD("internal", INTERNAL, UNRESERVED_KEYWORD) +PG_KEYWORD("intersect", INTERSECT, RESERVED_KEYWORD) +PG_KEYWORD("interval", INTERVAL, COL_NAME_KEYWORD) +PG_KEYWORD("into", INTO, RESERVED_KEYWORD) +PG_KEYWORD("invoker", INVOKER, UNRESERVED_KEYWORD) +PG_KEYWORD("ip", IP, UNRESERVED_KEYWORD) +PG_KEYWORD("is", IS, RESERVED_KEYWORD) +PG_KEYWORD("isnull", ISNULL, UNRESERVED_KEYWORD) +PG_KEYWORD("isolation", ISOLATION, UNRESERVED_KEYWORD) +PG_KEYWORD("join", JOIN, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("key", KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("key_path", KEY_PATH, UNRESERVED_KEYWORD) +PG_KEYWORD("key_store", KEY_STORE, UNRESERVED_KEYWORD) +PG_KEYWORD("kill", KILL, UNRESERVED_KEYWORD) +PG_KEYWORD("label", LABEL, UNRESERVED_KEYWORD) +PG_KEYWORD("language", LANGUAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("large", LARGE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("last", LAST_P, UNRESERVED_KEYWORD) +PG_KEYWORD("lc_collate", LC_COLLATE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("lc_ctype", LC_CTYPE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("leading", LEADING, RESERVED_KEYWORD) +PG_KEYWORD("leakproof", LEAKPROOF, UNRESERVED_KEYWORD) +PG_KEYWORD("least", LEAST, COL_NAME_KEYWORD) +PG_KEYWORD("left", LEFT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("less", LESS, RESERVED_KEYWORD) +PG_KEYWORD("level", LEVEL, UNRESERVED_KEYWORD) +PG_KEYWORD("like", LIKE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("limit", LIMIT, RESERVED_KEYWORD) +PG_KEYWORD("list", LIST, UNRESERVED_KEYWORD) +PG_KEYWORD("listen", LISTEN, UNRESERVED_KEYWORD) +PG_KEYWORD("load", LOAD, UNRESERVED_KEYWORD) +PG_KEYWORD("local", LOCAL, UNRESERVED_KEYWORD) +PG_KEYWORD("localtime", LOCALTIME, RESERVED_KEYWORD) +PG_KEYWORD("localtimestamp", LOCALTIMESTAMP, RESERVED_KEYWORD) +PG_KEYWORD("location", LOCATION, UNRESERVED_KEYWORD) +PG_KEYWORD("lock", LOCK_P, UNRESERVED_KEYWORD) +PG_KEYWORD("log", LOG_P, UNRESERVED_KEYWORD) +PG_KEYWORD("logging", LOGGING, UNRESERVED_KEYWORD) +PG_KEYWORD("login_any", LOGIN_ANY, UNRESERVED_KEYWORD) +PG_KEYWORD("login_failure", LOGIN_FAILURE, UNRESERVED_KEYWORD) +PG_KEYWORD("login_success", LOGIN_SUCCESS, UNRESERVED_KEYWORD) +PG_KEYWORD("logout", LOGOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("loop", LOOP, UNRESERVED_KEYWORD) +PG_KEYWORD("mapping", MAPPING, UNRESERVED_KEYWORD) +PG_KEYWORD("masking", MASKING, UNRESERVED_KEYWORD) +PG_KEYWORD("master", MASTER, UNRESERVED_KEYWORD) +PG_KEYWORD("match", MATCH, UNRESERVED_KEYWORD) +PG_KEYWORD("matched", MATCHED, UNRESERVED_KEYWORD) +PG_KEYWORD("materialized", MATERIALIZED, UNRESERVED_KEYWORD) +PG_KEYWORD("maxextents", MAXEXTENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("maxsize", MAXSIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("maxtrans", MAXTRANS, UNRESERVED_KEYWORD) +PG_KEYWORD("maxvalue", MAXVALUE, RESERVED_KEYWORD) +PG_KEYWORD("merge", MERGE, UNRESERVED_KEYWORD) +PG_KEYWORD("minextents", MINEXTENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("minus", MINUS_P, RESERVED_KEYWORD) +PG_KEYWORD("minute", MINUTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("minvalue", MINVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("mode", MODE, UNRESERVED_KEYWORD) +PG_KEYWORD("modify", MODIFY_P, RESERVED_KEYWORD) +PG_KEYWORD("month", MONTH_P, UNRESERVED_KEYWORD) +PG_KEYWORD("move", MOVE, UNRESERVED_KEYWORD) +PG_KEYWORD("movement", MOVEMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("name", NAME_P, UNRESERVED_KEYWORD) +PG_KEYWORD("names", NAMES, UNRESERVED_KEYWORD) +PG_KEYWORD("national", NATIONAL, COL_NAME_KEYWORD) +PG_KEYWORD("natural", NATURAL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("nchar", NCHAR, COL_NAME_KEYWORD) +PG_KEYWORD("next", NEXT, UNRESERVED_KEYWORD) +PG_KEYWORD("nlssort", NLSSORT, RESERVED_KEYWORD) +PG_KEYWORD("no", NO, UNRESERVED_KEYWORD) +PG_KEYWORD("nocompress", NOCOMPRESS, UNRESERVED_KEYWORD) +PG_KEYWORD("nocycle", NOCYCLE, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("node", NODE, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("nologging", NOLOGGING, UNRESERVED_KEYWORD) +PG_KEYWORD("nomaxvalue", NOMAXVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("nominvalue", NOMINVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("none", NONE, COL_NAME_KEYWORD) +PG_KEYWORD("not", NOT, RESERVED_KEYWORD) +PG_KEYWORD("nothing", NOTHING, UNRESERVED_KEYWORD) +PG_KEYWORD("notify", NOTIFY, UNRESERVED_KEYWORD) +PG_KEYWORD("notnull", NOTNULL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("nowait", NOWAIT, UNRESERVED_KEYWORD) +PG_KEYWORD("null", NULL_P, RESERVED_KEYWORD) +PG_KEYWORD("nullif", NULLIF, COL_NAME_KEYWORD) +PG_KEYWORD("nulls", NULLS_P, UNRESERVED_KEYWORD) +PG_KEYWORD("number", NUMBER_P, COL_NAME_KEYWORD) +PG_KEYWORD("numeric", NUMERIC, COL_NAME_KEYWORD) +PG_KEYWORD("numstr", NUMSTR, UNRESERVED_KEYWORD) +PG_KEYWORD("nvarchar2", NVARCHAR2, COL_NAME_KEYWORD) +PG_KEYWORD("nvl", NVL, COL_NAME_KEYWORD) +PG_KEYWORD("object", OBJECT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("of", OF, UNRESERVED_KEYWORD) +PG_KEYWORD("off", OFF, UNRESERVED_KEYWORD) +PG_KEYWORD("offset", OFFSET, RESERVED_KEYWORD) +PG_KEYWORD("oids", OIDS, UNRESERVED_KEYWORD) +PG_KEYWORD("on", ON, RESERVED_KEYWORD) +PG_KEYWORD("only", ONLY, RESERVED_KEYWORD) +PG_KEYWORD("operator", OPERATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("optimization", OPTIMIZATION, UNRESERVED_KEYWORD) +PG_KEYWORD("option", OPTION, UNRESERVED_KEYWORD) +PG_KEYWORD("options", OPTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("or", OR, RESERVED_KEYWORD) +PG_KEYWORD("order", ORDER, RESERVED_KEYWORD) +PG_KEYWORD("out", OUT_P, COL_NAME_KEYWORD) +PG_KEYWORD("outer", OUTER_P, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("over", OVER, UNRESERVED_KEYWORD) +PG_KEYWORD("overlaps", OVERLAPS, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("overlay", OVERLAY, COL_NAME_KEYWORD) +PG_KEYWORD("owned", OWNED, UNRESERVED_KEYWORD) +PG_KEYWORD("owner", OWNER, UNRESERVED_KEYWORD) +PG_KEYWORD("package", PACKAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("parser", PARSER, UNRESERVED_KEYWORD) +PG_KEYWORD("partial", PARTIAL, UNRESERVED_KEYWORD) +PG_KEYWORD("partition", PARTITION, UNRESERVED_KEYWORD) +PG_KEYWORD("partitions", PARTITIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("passing", PASSING, UNRESERVED_KEYWORD) +PG_KEYWORD("password", PASSWORD, UNRESERVED_KEYWORD) +PG_KEYWORD("pctfree", PCTFREE, UNRESERVED_KEYWORD) +PG_KEYWORD("per", PER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("percent", PERCENT, UNRESERVED_KEYWORD) +PG_KEYWORD("performance", PERFORMANCE, RESERVED_KEYWORD) +PG_KEYWORD("perm", PERM, UNRESERVED_KEYWORD) +PG_KEYWORD("placing", PLACING, RESERVED_KEYWORD) +PG_KEYWORD("plan", PLAN, UNRESERVED_KEYWORD) +PG_KEYWORD("plans", PLANS, UNRESERVED_KEYWORD) +PG_KEYWORD("policy", POLICY, UNRESERVED_KEYWORD) +PG_KEYWORD("pool", POOL, UNRESERVED_KEYWORD) +PG_KEYWORD("position", POSITION, COL_NAME_KEYWORD) +PG_KEYWORD("preceding", PRECEDING, UNRESERVED_KEYWORD) +PG_KEYWORD("precision", PRECISION, COL_NAME_KEYWORD) +/* PGXC_BEGIN */ +PG_KEYWORD("preferred", PREFERRED, UNRESERVED_KEYWORD) +/* PGXC_END */ +PG_KEYWORD("prefix", PREFIX, UNRESERVED_KEYWORD) +PG_KEYWORD("prepare", PREPARE, UNRESERVED_KEYWORD) +PG_KEYWORD("prepared", PREPARED, UNRESERVED_KEYWORD) +PG_KEYWORD("preserve", PRESERVE, UNRESERVED_KEYWORD) +PG_KEYWORD("primary", PRIMARY, RESERVED_KEYWORD) +PG_KEYWORD("prior", PRIOR, UNRESERVED_KEYWORD) +PG_KEYWORD("private", PRIVATE, UNRESERVED_KEYWORD) +PG_KEYWORD("privilege", PRIVILEGE, UNRESERVED_KEYWORD) +PG_KEYWORD("privileges", PRIVILEGES, UNRESERVED_KEYWORD) +PG_KEYWORD("procedural", PROCEDURAL, UNRESERVED_KEYWORD) +PG_KEYWORD("procedure", PROCEDURE, RESERVED_KEYWORD) +PG_KEYWORD("profile", PROFILE, UNRESERVED_KEYWORD) +PG_KEYWORD("query", QUERY, UNRESERVED_KEYWORD) +PG_KEYWORD("quote", QUOTE, UNRESERVED_KEYWORD) +PG_KEYWORD("randomized", RANDOMIZED, UNRESERVED_KEYWORD) +PG_KEYWORD("range", RANGE, UNRESERVED_KEYWORD) +PG_KEYWORD("raw", RAW, UNRESERVED_KEYWORD) +PG_KEYWORD("read", READ, UNRESERVED_KEYWORD) +PG_KEYWORD("real", REAL, COL_NAME_KEYWORD) +PG_KEYWORD("reassign", REASSIGN, UNRESERVED_KEYWORD) +PG_KEYWORD("rebuild", REBUILD, UNRESERVED_KEYWORD) +PG_KEYWORD("recheck", RECHECK, UNRESERVED_KEYWORD) +PG_KEYWORD("recursive", RECURSIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("redisanyvalue", REDISANYVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("ref", REF, UNRESERVED_KEYWORD) +PG_KEYWORD("references", REFERENCES, RESERVED_KEYWORD) +PG_KEYWORD("refresh", REFRESH, UNRESERVED_KEYWORD) +PG_KEYWORD("reindex", REINDEX, UNRESERVED_KEYWORD) +PG_KEYWORD("reject", REJECT_P, RESERVED_KEYWORD) +PG_KEYWORD("relative", RELATIVE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("release", RELEASE, UNRESERVED_KEYWORD) +PG_KEYWORD("reloptions", RELOPTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("remote", REMOTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("remove", REMOVE, UNRESERVED_KEYWORD) +PG_KEYWORD("rename", RENAME, UNRESERVED_KEYWORD) +PG_KEYWORD("repeatable", REPEATABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("replace", REPLACE, UNRESERVED_KEYWORD) +PG_KEYWORD("replica", REPLICA, UNRESERVED_KEYWORD) +PG_KEYWORD("reset", RESET, UNRESERVED_KEYWORD) +PG_KEYWORD("resize", RESIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("resource", RESOURCE, UNRESERVED_KEYWORD) +PG_KEYWORD("restart", RESTART, UNRESERVED_KEYWORD) +PG_KEYWORD("restrict", RESTRICT, UNRESERVED_KEYWORD) +PG_KEYWORD("return", RETURN, UNRESERVED_KEYWORD) +PG_KEYWORD("returning", RETURNING, RESERVED_KEYWORD) +PG_KEYWORD("returns", RETURNS, UNRESERVED_KEYWORD) +PG_KEYWORD("reuse", REUSE, UNRESERVED_KEYWORD) +PG_KEYWORD("revoke", REVOKE, UNRESERVED_KEYWORD) +PG_KEYWORD("right", RIGHT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("role", ROLE, UNRESERVED_KEYWORD) +PG_KEYWORD("roles", ROLES, UNRESERVED_KEYWORD) +PG_KEYWORD("rollback", ROLLBACK, UNRESERVED_KEYWORD) +PG_KEYWORD("rollup", ROLLUP, UNRESERVED_KEYWORD) +PG_KEYWORD("row", ROW, COL_NAME_KEYWORD) +#ifndef ENABLE_MULTIPLE_NODES +PG_KEYWORD("rownum", ROWNUM, RESERVED_KEYWORD) +#endif +PG_KEYWORD("rows", ROWS, UNRESERVED_KEYWORD) +PG_KEYWORD("rule", RULE, UNRESERVED_KEYWORD) +PG_KEYWORD("savepoint", SAVEPOINT, UNRESERVED_KEYWORD) +PG_KEYWORD("schema", SCHEMA, UNRESERVED_KEYWORD) +PG_KEYWORD("scroll", SCROLL, UNRESERVED_KEYWORD) +PG_KEYWORD("search", SEARCH, UNRESERVED_KEYWORD) +PG_KEYWORD("second", SECOND_P, UNRESERVED_KEYWORD) +PG_KEYWORD("security", SECURITY, UNRESERVED_KEYWORD) +PG_KEYWORD("select", SELECT, RESERVED_KEYWORD) +PG_KEYWORD("sequence", SEQUENCE, UNRESERVED_KEYWORD) +PG_KEYWORD("sequences", SEQUENCES, UNRESERVED_KEYWORD) +PG_KEYWORD("serializable", SERIALIZABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("server", SERVER, UNRESERVED_KEYWORD) +PG_KEYWORD("session", SESSION, UNRESERVED_KEYWORD) +PG_KEYWORD("session_user", SESSION_USER, RESERVED_KEYWORD) +PG_KEYWORD("set", SET, UNRESERVED_KEYWORD) +PG_KEYWORD("setof", SETOF, COL_NAME_KEYWORD) +PG_KEYWORD("sets", SETS, UNRESERVED_KEYWORD) +PG_KEYWORD("share", SHARE, UNRESERVED_KEYWORD) +PG_KEYWORD("shippable", SHIPPABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("show", SHOW, UNRESERVED_KEYWORD) +PG_KEYWORD("shutdown", SHUTDOWN, UNRESERVED_KEYWORD) +PG_KEYWORD("similar", SIMILAR, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("simple", SIMPLE, UNRESERVED_KEYWORD) +PG_KEYWORD("size", SIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("slice", SLICE, UNRESERVED_KEYWORD) +PG_KEYWORD("smalldatetime", SMALLDATETIME, COL_NAME_KEYWORD) +PG_KEYWORD("smalldatetime_format", SMALLDATETIME_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("smallint", SMALLINT, COL_NAME_KEYWORD) +PG_KEYWORD("snapshot", SNAPSHOT, UNRESERVED_KEYWORD) +PG_KEYWORD("some", SOME, RESERVED_KEYWORD) +PG_KEYWORD("source", SOURCE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("space", SPACE, UNRESERVED_KEYWORD) +PG_KEYWORD("spill", SPILL, UNRESERVED_KEYWORD) +PG_KEYWORD("split", SPLIT, UNRESERVED_KEYWORD) +PG_KEYWORD("stable", STABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("standalone", STANDALONE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("start", START, UNRESERVED_KEYWORD) +PG_KEYWORD("statement", STATEMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("statement_id", STATEMENT_ID, UNRESERVED_KEYWORD) +PG_KEYWORD("statistics", STATISTICS, UNRESERVED_KEYWORD) +PG_KEYWORD("stdin", STDIN, UNRESERVED_KEYWORD) +PG_KEYWORD("stdout", STDOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("storage", STORAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("store", STORE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("stream", STREAM, RESERVED_KEYWORD) +PG_KEYWORD("strict", STRICT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("strip", STRIP_P, UNRESERVED_KEYWORD) +PG_KEYWORD("substring", SUBSTRING, COL_NAME_KEYWORD) +PG_KEYWORD("symmetric", SYMMETRIC, RESERVED_KEYWORD) +PG_KEYWORD("synonym", SYNONYM, UNRESERVED_KEYWORD) +PG_KEYWORD("sys_refcursor", SYS_REFCURSOR, UNRESERVED_KEYWORD) +PG_KEYWORD("sysdate", SYSDATE, RESERVED_KEYWORD) +PG_KEYWORD("sysid", SYSID, UNRESERVED_KEYWORD) +PG_KEYWORD("system", SYSTEM_P, UNRESERVED_KEYWORD) +PG_KEYWORD("table", TABLE, RESERVED_KEYWORD) +PG_KEYWORD("tables", TABLES, UNRESERVED_KEYWORD) +PG_KEYWORD("tablesample", TABLESAMPLE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("tablespace", TABLESPACE, UNRESERVED_KEYWORD) +PG_KEYWORD("temp", TEMP, UNRESERVED_KEYWORD) +PG_KEYWORD("template", TEMPLATE, UNRESERVED_KEYWORD) +PG_KEYWORD("temporary", TEMPORARY, UNRESERVED_KEYWORD) +PG_KEYWORD("text", TEXT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("than", THAN, UNRESERVED_KEYWORD) +PG_KEYWORD("then", THEN, RESERVED_KEYWORD) +PG_KEYWORD("time", TIME, COL_NAME_KEYWORD) +PG_KEYWORD("time_format", TIME_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("timestamp", TIMESTAMP, COL_NAME_KEYWORD) +PG_KEYWORD("timestamp_format", TIMESTAMP_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("timestampdiff", TIMESTAMPDIFF, COL_NAME_KEYWORD) +PG_KEYWORD("tinyint", TINYINT, COL_NAME_KEYWORD) +PG_KEYWORD("to", TO, RESERVED_KEYWORD) +PG_KEYWORD("trailing", TRAILING, RESERVED_KEYWORD) +PG_KEYWORD("transaction", TRANSACTION, UNRESERVED_KEYWORD) +PG_KEYWORD("treat", TREAT, COL_NAME_KEYWORD) +PG_KEYWORD("trigger", TRIGGER, UNRESERVED_KEYWORD) +PG_KEYWORD("trim", TRIM, COL_NAME_KEYWORD) +PG_KEYWORD("true", TRUE_P, RESERVED_KEYWORD) +PG_KEYWORD("truncate", TRUNCATE, UNRESERVED_KEYWORD) +PG_KEYWORD("trusted", TRUSTED, UNRESERVED_KEYWORD) +PG_KEYWORD("tsfield", TSFIELD, UNRESERVED_KEYWORD) +PG_KEYWORD("tstag", TSTAG, UNRESERVED_KEYWORD) +PG_KEYWORD("tstime", TSTIME, UNRESERVED_KEYWORD) +PG_KEYWORD("type", TYPE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("types", TYPES_P, UNRESERVED_KEYWORD) +PG_KEYWORD("unbounded", UNBOUNDED, UNRESERVED_KEYWORD) +PG_KEYWORD("uncommitted", UNCOMMITTED, UNRESERVED_KEYWORD) +PG_KEYWORD("unencrypted", UNENCRYPTED, UNRESERVED_KEYWORD) +PG_KEYWORD("union", UNION, RESERVED_KEYWORD) +PG_KEYWORD("unique", UNIQUE, RESERVED_KEYWORD) +PG_KEYWORD("unknown", UNKNOWN, UNRESERVED_KEYWORD) +PG_KEYWORD("unlimited", UNLIMITED, UNRESERVED_KEYWORD) +PG_KEYWORD("unlisten", UNLISTEN, UNRESERVED_KEYWORD) +PG_KEYWORD("unlock", UNLOCK, UNRESERVED_KEYWORD) +PG_KEYWORD("unlogged", UNLOGGED, UNRESERVED_KEYWORD) +PG_KEYWORD("until", UNTIL, UNRESERVED_KEYWORD) +PG_KEYWORD("unusable", UNUSABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("update", UPDATE, UNRESERVED_KEYWORD) +PG_KEYWORD("user", USER, RESERVED_KEYWORD) +PG_KEYWORD("using", USING, RESERVED_KEYWORD) +PG_KEYWORD("vacuum", VACUUM, UNRESERVED_KEYWORD) +PG_KEYWORD("valid", VALID, UNRESERVED_KEYWORD) +PG_KEYWORD("validate", VALIDATE, UNRESERVED_KEYWORD) +PG_KEYWORD("validation", VALIDATION, UNRESERVED_KEYWORD) +PG_KEYWORD("validator", VALIDATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("value", VALUE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("values", VALUES, COL_NAME_KEYWORD) +PG_KEYWORD("varchar", VARCHAR, COL_NAME_KEYWORD) +PG_KEYWORD("varchar2", VARCHAR2, COL_NAME_KEYWORD) +PG_KEYWORD("variadic", VARIADIC, RESERVED_KEYWORD) +PG_KEYWORD("varying", VARYING, UNRESERVED_KEYWORD) +PG_KEYWORD("vcgroup", VCGROUP, UNRESERVED_KEYWORD) +PG_KEYWORD("verbose", VERBOSE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("verify", VERIFY, RESERVED_KEYWORD) +PG_KEYWORD("version", VERSION_P, UNRESERVED_KEYWORD) +PG_KEYWORD("view", VIEW, UNRESERVED_KEYWORD) +PG_KEYWORD("volatile", VOLATILE, UNRESERVED_KEYWORD) +PG_KEYWORD("weak", WEAK, UNRESERVED_KEYWORD) +PG_KEYWORD("when", WHEN, RESERVED_KEYWORD) +PG_KEYWORD("where", WHERE, RESERVED_KEYWORD) +PG_KEYWORD("whitespace", WHITESPACE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("window", WINDOW, RESERVED_KEYWORD) +PG_KEYWORD("with", WITH, RESERVED_KEYWORD) +PG_KEYWORD("within", WITHIN, UNRESERVED_KEYWORD) +PG_KEYWORD("without", WITHOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("work", WORK, UNRESERVED_KEYWORD) +PG_KEYWORD("workload", WORKLOAD, UNRESERVED_KEYWORD) +PG_KEYWORD("wrapper", WRAPPER, UNRESERVED_KEYWORD) +PG_KEYWORD("write", WRITE, UNRESERVED_KEYWORD) +PG_KEYWORD("xml", XML_P, UNRESERVED_KEYWORD) +PG_KEYWORD("xmlattributes", XMLATTRIBUTES, COL_NAME_KEYWORD) +PG_KEYWORD("xmlconcat", XMLCONCAT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlelement", XMLELEMENT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlexists", XMLEXISTS, COL_NAME_KEYWORD) +PG_KEYWORD("xmlforest", XMLFOREST, COL_NAME_KEYWORD) +PG_KEYWORD("xmlparse", XMLPARSE, COL_NAME_KEYWORD) +PG_KEYWORD("xmlpi", XMLPI, COL_NAME_KEYWORD) +PG_KEYWORD("xmlroot", XMLROOT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlserialize", XMLSERIALIZE, COL_NAME_KEYWORD) +PG_KEYWORD("year", YEAR_P, UNRESERVED_KEYWORD) +PG_KEYWORD("yes", YES_P, UNRESERVED_KEYWORD) +PG_KEYWORD("zone", ZONE, UNRESERVED_KEYWORD) diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_agg.h postgresql-hll-2.14/include/include/parser/parse_agg.h --- postgresql-hll-2.14_old/include/include/parser/parse_agg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_agg.h 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * parse_agg.h + * handle aggregates and window functions in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_agg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_AGG_H +#define PARSE_AGG_H + +#include "parser/parse_node.h" + +extern void transformAggregateCall(ParseState* pstate, Aggref* agg, List* args, List* aggorder, bool agg_distinct); +extern void transformWindowFuncCall(ParseState* pstate, WindowFunc* wfunc, WindowDef* windef); + +extern void parseCheckAggregates(ParseState* pstate, Query* qry); +extern void parseCheckWindowFuncs(ParseState* pstate, Query* qry); +extern Node* transformGroupingFunc(ParseState* pstate, GroupingFunc* g); + +extern List* expand_grouping_sets(List* groupingSets, int limit); + +extern List* extract_rollup_sets(List* groupingSets); + +extern List* reorder_grouping_sets(List* groupingSets, List* sortclause); + +extern List* preprocess_groupclause(PlannerInfo* root, List* force); + +extern void build_aggregate_fnexprs(Oid* agg_input_types, int agg_num_inputs, Oid agg_state_type, Oid agg_result_type, + Oid agg_input_collation, Oid transfn_oid, Oid finalfn_oid, Expr** transfnexpr, Expr** finalfnexpr); + +extern bool check_windowagg_can_shuffle(List* partitionClause, List* targetList); + +extern void build_trans_aggregate_fnexprs(int agg_num_inputs, int agg_num_direct_inputs, bool agg_ordered_set, + bool agg_variadic, Oid agg_state_type, Oid* agg_input_types, Oid agg_result_type, Oid agg_input_collation, + Oid transfn_oid, Oid finalfn_oid, Expr** transfnexpr, Expr** finalfnexpr); + +extern int get_aggregate_argtypes(Aggref* aggref, Oid* inputTypes, int func_max_args); + +extern Oid resolve_aggregate_transtype(Oid aggfuncid, Oid aggtranstype, Oid* inputTypes, int numArguments); + +#endif /* PARSE_AGG_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_clause.h postgresql-hll-2.14/include/include/parser/parse_clause.h --- postgresql-hll-2.14_old/include/include/parser/parse_clause.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_clause.h 2020-12-12 17:06:43.242347974 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * parse_clause.h + * handle clauses in parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_clause.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_CLAUSE_H +#define PARSE_CLAUSE_H + +#include "nodes/relation.h" +#include "parser/parse_node.h" + +extern void transformFromClause(ParseState* pstate, List* frmList, bool isFirstNode = true, bool isCreateView = false); +extern int setTargetTable(ParseState* pstate, RangeVar* relation, bool inh, bool alsoSource, AclMode requiredPerms); +extern bool interpretInhOption(InhOption inhOpt); +extern bool interpretOidsOption(List* defList); + +extern Node* transformFromClauseItem(ParseState* pstate, Node* n, RangeTblEntry** top_rte, int* top_rti, + RangeTblEntry** right_rte, int* right_rti, List** relnamespace, bool isFirstNode = true, + bool isCreateView = false, bool isMergeInto = false); + +extern Node* transformJoinOnClause(ParseState* pstate, JoinExpr* j, RangeTblEntry* l_rte, RangeTblEntry* r_rte, + List* relnamespace); +extern Node* transformWhereClause(ParseState* pstate, Node* clause, const char* constructName); +extern Node* transformLimitClause(ParseState* pstate, Node* clause, const char* constructName); +extern List* transformGroupClause( + ParseState* pstate, List* grouplist, List** groupingSets, List** targetlist, List* sortClause, bool useSQL99); +extern List* transformSortClause( + ParseState* pstate, List* orderlist, List** targetlist, bool resolveUnknown, bool useSQL99); + +extern List* transformWindowDefinitions(ParseState* pstate, List* windowdefs, List** targetlist); + +extern List* transformDistinctClause(ParseState* pstate, List** targetlist, List* sortClause, bool is_agg); +extern List* transformDistinctOnClause(ParseState* pstate, List* distinctlist, List** targetlist, List* sortClause); + +extern Index assignSortGroupRef(TargetEntry* tle, List* tlist); +extern bool targetIsInSortList(TargetEntry* tle, Oid sortop, List* sortList); + +extern List* addTargetToSortList( + ParseState* pstate, TargetEntry* tle, List* sortlist, List* targetlist, SortBy* sortby, bool resolveUnknown); +extern ParseNamespaceItem *makeNamespaceItem(RangeTblEntry *rte, bool lateral_only, bool lateral_ok); + +#endif /* PARSE_CLAUSE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_coerce.h postgresql-hll-2.14/include/include/parser/parse_coerce.h --- postgresql-hll-2.14_old/include/include/parser/parse_coerce.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_coerce.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * parse_coerce.h + * Routines for type coercion. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_coerce.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_COERCE_H +#define PARSE_COERCE_H + +#include "parser/parse_node.h" + +/* Setup error traceback support for ereport() */ +#define ELOG_FIELD_NAME_START(fieldname) \ + ErrorContextCallback errcontext; \ + errcontext.callback = expression_error_callback; \ + errcontext.arg = (void*)(fieldname); \ + errcontext.previous = t_thrd.log_cxt.error_context_stack; \ + t_thrd.log_cxt.error_context_stack = &errcontext; + +#define ELOG_FIELD_NAME_END t_thrd.log_cxt.error_context_stack = errcontext.previous; + +/* Type categories (see TYPCATEGORY_xxx symbols in catalog/pg_type.h) */ +typedef char TYPCATEGORY; + +/* Result codes for find_coercion_pathway */ +typedef enum CoercionPathType { + COERCION_PATH_NONE, /* failed to find any coercion pathway */ + COERCION_PATH_FUNC, /* apply the specified coercion function */ + COERCION_PATH_RELABELTYPE, /* binary-compatible cast, no function */ + COERCION_PATH_ARRAYCOERCE, /* need an ArrayCoerceExpr node */ + COERCION_PATH_COERCEVIAIO /* need a CoerceViaIO node */ +} CoercionPathType; + +extern bool IsBinaryCoercible(Oid srctype, Oid targettype); +extern bool IsPreferredType(TYPCATEGORY category, Oid type); +extern TYPCATEGORY TypeCategory(Oid type); + +extern Node* coerce_to_target_type(ParseState* pstate, Node* expr, Oid exprtype, Oid targettype, int32 targettypmod, + CoercionContext ccontext, CoercionForm cformat, int location); +extern bool can_coerce_type(int nargs, Oid* input_typeids, Oid* target_typeids, CoercionContext ccontext); +extern Node* coerce_type(ParseState* pstate, Node* node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, + CoercionContext ccontext, CoercionForm cformat, int location); +extern Node* coerce_to_domain(Node* arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionForm cformat, + int location, bool hideInputCoercion, bool lengthCoercionDone); + +extern Node* coerce_to_boolean(ParseState* pstate, Node* node, const char* constructName); +extern Node* coerce_to_specific_type(ParseState* pstate, Node* node, Oid targetTypeId, const char* constructName); + +extern int parser_coercion_errposition(ParseState* pstate, int coerce_location, Node* input_expr); + +extern Oid select_common_type(ParseState* pstate, List* exprs, const char* context, Node** which_expr); +extern Node* coerce_to_common_type(ParseState* pstate, Node* node, Oid targetTypeId, const char* context); + +extern bool check_generic_type_consistency(Oid* actual_arg_types, Oid* declared_arg_types, int nargs); +extern Oid enforce_generic_type_consistency( + Oid* actual_arg_types, Oid* declared_arg_types, int nargs, Oid rettype, bool allow_poly); +extern Oid resolve_generic_type(Oid declared_type, Oid context_actual_type, Oid context_declared_type); + +extern CoercionPathType find_coercion_pathway( + Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid* funcid); +extern CoercionPathType find_typmod_coercion_function(Oid typeId, Oid* funcid); + +extern void expression_error_callback(void* arg); + +#endif /* PARSE_COERCE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_collate.h postgresql-hll-2.14/include/include/parser/parse_collate.h --- postgresql-hll-2.14_old/include/include/parser/parse_collate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_collate.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * parse_collate.h + * Routines for assigning collation information. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_collate.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_COLLATE_H +#define PARSE_COLLATE_H + +#include "parser/parse_node.h" + +extern void assign_query_collations(ParseState* pstate, Query* query); + +extern void assign_list_collations(ParseState* pstate, List* exprs); + +extern void assign_expr_collations(ParseState* pstate, Node* expr); + +extern Oid select_common_collation(ParseState* pstate, List* exprs, bool none_ok); + +#endif /* PARSE_COLLATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_cte.h postgresql-hll-2.14/include/include/parser/parse_cte.h --- postgresql-hll-2.14_old/include/include/parser/parse_cte.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_cte.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * parse_cte.h + * handle CTEs (common table expressions) in parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_cte.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_CTE_H +#define PARSE_CTE_H + +#include "parser/parse_node.h" + +extern List* transformWithClause(ParseState* pstate, WithClause* withClause); + +extern void analyzeCTETargetList(ParseState* pstate, CommonTableExpr* cte, List* tlist); + +#endif /* PARSE_CTE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_expr.h postgresql-hll-2.14/include/include/parser/parse_expr.h --- postgresql-hll-2.14_old/include/include/parser/parse_expr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_expr.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * parse_expr.h + * handle expressions in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_expr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_EXPR_H +#define PARSE_EXPR_H + +#include "parser/parse_node.h" +#include "utils/plpgsql.h" + +extern Node* transformExpr(ParseState* pstate, Node* expr); +extern Expr* make_distinct_op(ParseState* pstate, List* opname, Node* ltree, Node* rtree, int location); +extern Oid getMultiFuncInfo(char* fun_expr, PLpgSQL_expr* expr); +extern void lockSeqForNextvalFunc(Node* node); +#endif /* PARSE_EXPR_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_func.h postgresql-hll-2.14/include/include/parser/parse_func.h --- postgresql-hll-2.14_old/include/include/parser/parse_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_func.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * parse_func.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_func.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSER_FUNC_H +#define PARSER_FUNC_H + +#include "catalog/namespace.h" +#include "parser/parse_node.h" + +/* + * This structure is used to explore the inheritance hierarchy above + * nodes in the type tree in order to disambiguate among polymorphic + * functions. + */ +typedef struct _InhPaths { + int nsupers; /* number of superclasses */ + Oid self; /* this class */ + Oid* supervec; /* vector of superclasses */ +} InhPaths; + +/* Result codes for func_get_detail */ +typedef enum { + FUNCDETAIL_NOTFOUND, /* no matching function */ + FUNCDETAIL_MULTIPLE, /* too many matching functions */ + FUNCDETAIL_NORMAL, /* found a matching regular function */ + FUNCDETAIL_AGGREGATE, /* found a matching aggregate function */ + FUNCDETAIL_WINDOWFUNC, /* found a matching window function */ + FUNCDETAIL_COERCION /* it's a type coercion request */ +} FuncDetailCode; + +extern Node* ParseFuncOrColumn( + ParseState* pstate, List* funcname, List* fargs, FuncCall* fn, int location, bool call_func = false); + +extern FuncDetailCode func_get_detail(List* funcname, List* fargs, List* fargnames, int nargs, Oid* argtypes, + bool expand_variadic, bool expand_defaults, Oid* funcid, Oid* rettype, bool* retset, int* nvargs, Oid* vatype, + Oid** true_typeids, List** argdefaults, bool call_func = false, Oid* refSynOid = NULL); + +extern int func_match_argtypes( + int nargs, Oid* input_typeids, FuncCandidateList raw_candidates, FuncCandidateList* candidates); + +extern FuncCandidateList func_select_candidate(int nargs, Oid* input_typeids, FuncCandidateList candidates); + +extern void make_fn_arguments(ParseState* pstate, List* fargs, Oid* actual_arg_types, Oid* declared_arg_types); + +extern const char* funcname_signature_string(const char* funcname, int nargs, List* argnames, const Oid* argtypes); +extern const char* func_signature_string(List* funcname, int nargs, List* argnames, const Oid* argtypes); + +extern Oid LookupFuncName(List* funcname, int nargs, const Oid* argtypes, bool noError); +extern Oid LookupFuncNameTypeNames(List* funcname, List* argtypes, bool noError); +extern Oid LookupFuncNameOptTypeNames(List* funcname, List* argtypes, bool noError); +extern Oid LookupAggNameTypeNames(List* aggname, List* argtypes, bool noError); + +extern void check_pg_get_expr_args(ParseState* pstate, Oid fnoid, List* args); +extern int GetPriority(Oid typeoid); +#endif /* PARSE_FUNC_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_hint.h postgresql-hll-2.14/include/include/parser/parse_hint.h --- postgresql-hll-2.14_old/include/include/parser/parse_hint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_hint.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,257 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * parse_hint.h + * Table parse hint header file, include struct member declaration. + * + * + * IDENTIFICATION + * src/include/parser/parse_hint.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARSE_HINT_h +#define PARSE_HINT_h + +#include "optimizer/streamplan.h" +#include "parser/parse_node.h" +#include "tcop/dest.h" +#include "utils/guc.h" + +/* hint keywords */ +#define HINT_NESTLOOP "NestLoop" +#define HINT_MERGEJOIN "MergeJoin" +#define HINT_HASHJOIN "HashJoin" +#define HINT_NO "No" +#define HINT_LEADING "Leading" +#define HINT_ROWS "Rows" +#define HINT_BROADCAST "Broadcast" +#define HINT_REDISTRIBUTE "Redistribute" +#define HINT_BLOCKNAME "BlockName" +#define HINT_TABLESCAN "TableScan" +#define HINT_INDEXSCAN "IndexScan" +#define HINT_INDEXONLYSCAN "IndexOnlyScan" +#define HINT_SKEW "Skew" +#define HINT_MULTI_NODE "MultiNode" +#define HINT_NULL "Null" +#define HINT_TRUE "True" +#define HINT_FALSE "False" +#define HINT_PRED_PUSH "Predpush" +#define HINT_REWRITE "Rewrite_rule" + +#define BLOCK_COMMENT_START "/*" +#define BLOCK_COMMENT_END "*/" +#define HINT_COMMENT_KEYWORD "+" +#define HINT_START BLOCK_COMMENT_START HINT_COMMENT_KEYWORD +#define HINT_END BLOCK_COMMENT_END + +typedef struct pull_hint_warning_context { + List* warning; +} pull_qual_vars_context; + +#define append_warning_to_list(root, hint, format, ...) \ + do { \ + StringInfoData buf; \ + char* hint_string = descHint(hint); \ + initStringInfo(&buf); \ + appendStringInfo(&buf, format, ##__VA_ARGS__); \ + root->glob->hint_warning = lappend(root->glob->hint_warning, makeString(buf.data)); \ + pfree(hint_string); \ + } while (0) + +extern THR_LOCAL List* hint_list; +extern THR_LOCAL List* hint_warning; + +/* hint keyword of enum type*/ +typedef enum HintKeyword { + HINT_KEYWORD_NESTLOOP = 0, + HINT_KEYWORD_MERGEJOIN, + HINT_KEYWORD_HASHJOIN, + HINT_KEYWORD_LEADING, + HINT_KEYWORD_ROWS, + HINT_KEYWORD_BROADCAST, + HINT_KEYWORD_REDISTRIBUTE, + HINT_KEYWORD_BLOCKNAME, + HINT_KEYWORD_TABLESCAN, + HINT_KEYWORD_INDEXSCAN, + HINT_KEYWORD_INDEXONLYSCAN, + HINT_KEYWORD_SKEW, + HINT_KEYWORD_PREDPUSH, + HINT_KEYWORD_REWRITE, +} HintKeyword; + +/* hint status */ +typedef enum HintStatus { + HINT_STATE_NOTUSED = 0, /* specified relation not used in query */ + HINT_STATE_USED, /* hint is used */ + HINT_STATE_DUPLICATION /* specified hint duplication */ +} HintStatus; + +/* common data for all hints. */ +struct Hint { + NodeTag type; /* Hint type */ + List* relnames; /* relation name list */ + HintKeyword hint_keyword; /* Hint Keyword */ + HintStatus state; /* hint used state */ +}; + +typedef struct LeadingHint { + Hint base; /* Base hint */ + bool join_order_hint; /* If join order is hinted */ +} LeadingHint; + +/* join method hints */ +typedef struct JoinMethodHint { + Hint base; /* Base hint */ + bool negative; /* Positive or negative? */ + Relids joinrelids; /* Join relids */ + Relids inner_joinrelids; /* Inner relids */ +} JoinMethodHint; + +/* rows hints kind */ +typedef enum RowsValueType { + RVT_ABSOLUTE, /* Rows(... #1000) absolute rows */ + RVT_ADD, /* Rows(... +1000) add rows */ + RVT_SUB, /* Rows(... -1000) subtract rows */ + RVT_MULTI /* Rows(... *1.2) multiply rows */ +} RowsValueType; + +/* rows hint */ +typedef struct RowsHint { + Hint base; /* base hint */ + Relids joinrelids; /* Join relids */ + char* rows_str; /* Row string */ + RowsValueType value_type; /* hints kind */ + double rows; /* Rows */ +} RowsHint; + +typedef struct StreamHint { + Hint base; /* base hint */ + bool negative; /* Positive or negative? */ + Relids joinrelids; /* Join relids */ + StreamType stream_type; /* Stream type, redistribute or broadcast */ +} StreamHint; + +typedef struct BlockNameHint { + Hint base; /* base hint */ + /* Block name will be stored in base.relname. */ +} BlockNameHint; + +/* scan method hints */ +typedef struct ScanMethodHint { + Hint base; + bool negative; + Relids relid; + List* indexlist; +} ScanMethodHint; + +/* skew hints */ +typedef struct SkewHint { + Hint base; /* base hint */ + Relids relid; /* skew relation relids */ + List* column_list; /* skew column list */ + List* value_list; /* skew value list */ +} SkewHint; + +/* multinode hints */ +typedef struct MultiNodeHint { + Hint base; /* base hint */ + bool multi_node_hint; +} MultiNodeHint; + +/* relation information from RangeTblEntry and pg_class */ +typedef struct SkewRelInfo { + NodeTag type; + char* relation_name; /* relation name */ + Oid relation_oid; /* relation`s oid */ + RangeTblEntry* rte; /* relation`s rte */ + RangeTblEntry* parent_rte; /* if relation comes from subquery, then it`s subquery`s rte */ +} SkewRelInfo; + +/* column information from PG_ATTRIBUTE or targetEntry */ +typedef struct SkewColumnInfo { + NodeTag type; + Oid relation_Oid; /* table`s oid */ + char* column_name; /* column`s name */ + AttrNumber attnum; /* column's location in relation */ + Oid column_typid; /* column`s type oid */ + Expr* expr; /* expr that column comes from */ +} SkewColumnInfo; + +/* make skew value to Const */ +typedef struct SkewValueInfo { + NodeTag type; + bool support_redis; /* column type whether support redistribution, if not the const_value will be null */ + Const* const_value; /* skew value */ +} SkewValueInfo; + +/* SkewHint structure after transform */ +typedef struct SkewHintTransf { + NodeTag type; + SkewHint* before; /* skew hint struct before transform */ + List* rel_info_list; /* relation info list after transform */ + List* column_info_list; /* column info list after transform */ + List* value_info_list; /* value info list after transform */ +} SkewHintTransf; + +/* prompts which predicates can be pushdown */ +typedef struct PredpushHint { + Hint base; /* base hint */ + bool negative; + char *dest_name; + int dest_id; + Relids candidates; /* which one will be push down */ +} PredpushHint; + +/* Enable/disable rewrites with hint */ +typedef struct RewriteHint { + Hint base; /* base hint */ + List* param_names; /* rewrite parameters */ + unsigned int param_bits; +} RewriteHint; + +typedef struct hintKeyword { + const char* name; + int value; +} hintKeyword; + +extern HintState* HintStateCreate(); +extern HintState* create_hintstate(const char* hints); +extern List* find_specific_join_hint( + HintState* hstate, Relids joinrelids, Relids innerrelids, HintKeyword keyWord, bool leading = true); +extern List* find_specific_scan_hint(HintState* hstate, Relids relids, HintKeyword keyWord); +extern ScanMethodHint* find_scan_hint(HintState* hstate, Relids relid, HintKeyword keyWord); +extern char* descHint(Hint* hint); +extern void hintDelete(Hint* hint); +extern void desc_hint_in_state(PlannerInfo* root, HintState* hstate); + +extern void transform_hints(PlannerInfo* root, Query* parse, HintState* hstate); + +extern void check_scan_hint_validity(PlannerInfo* root); +extern void adjust_scanhint_relid(HintState* hstate, Index oldIdx, Index newIdx); +extern bool pull_hint_warning_walker(Node* node, pull_qual_vars_context* context); +extern List* retrieve_query_hint_warning(Node* parse); +extern void output_utility_hint_warning(Node* query, int lev); +extern void output_hint_warning(List* warning, int lev); +extern void HintStateDelete(HintState* hintState); +extern bool permit_predpush(PlannerInfo *root); +extern bool permit_from_rewrite_hint(PlannerInfo *root, unsigned int params); +extern Relids predpush_candidates_same_level(PlannerInfo *root); + +#define skip_space(str) \ + while (isspace(*str)) \ + str++; +#endif diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_merge.h postgresql-hll-2.14/include/include/parser/parse_merge.h --- postgresql-hll-2.14_old/include/include/parser/parse_merge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_merge.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * parse_merge.h + * handle merge-stmt in parser + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/parser/parse_merge.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARSE_MERGE_H +#define PARSE_MERGE_H + +#include "parser/parse_node.h" +extern Query* transformMergeStmt(ParseState* pstate, MergeStmt* stmt); +extern List* expandTargetTL(List* te_list, Query* parsetree); +extern List* expandActionTL(List* te_list, Query* parsetree); +extern List* expandQualTL(List* te_list, Query* parsetree); +extern bool check_unique_constraint(List*& index_list); +#endif diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_node.h postgresql-hll-2.14/include/include/parser/parse_node.h --- postgresql-hll-2.14_old/include/include/parser/parse_node.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_node.h 2020-12-12 17:06:43.243347987 +0800 @@ -0,0 +1,204 @@ +/* ------------------------------------------------------------------------- + * + * parse_node.h + * Internal definitions for parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_node.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_NODE_H +#define PARSE_NODE_H + +#include "nodes/parsenodes.h" +#include "parser/analyze.h" +#include "utils/relcache.h" + +typedef struct PlusJoinRTEInfo { + bool needrecord; /* need record the RTE info for plus join? only in WhereClause is true for now */ + List* info; /* List of PlusJoinRTEItem we record */ +} PlusJoinRTEInfo; + +/* + * Function signatures for parser hooks + */ +typedef struct ParseState ParseState; + +typedef Node* (*PreParseColumnRefHook)(ParseState* pstate, ColumnRef* cref); +typedef Node* (*PostParseColumnRefHook)(ParseState* pstate, ColumnRef* cref, Node* var); +typedef Node* (*ParseParamRefHook)(ParseState* pstate, ParamRef* pref); +typedef Node* (*CoerceParamHook)(ParseState* pstate, Param* param, Oid targetTypeId, int32 targetTypeMod, int location); + +/* + * State information used during parse analysis + * + * parentParseState: NULL in a top-level ParseState. When parsing a subquery, + * links to current parse state of outer query. + * + * p_sourcetext: source string that generated the raw parsetree being + * analyzed, or NULL if not available. (The string is used only to + * generate cursor positions in error messages: we need it to convert + * byte-wise locations in parse structures to character-wise cursor + * positions.) + * + * p_rtable: list of RTEs that will become the rangetable of the query. + * Note that neither relname nor refname of these entries are necessarily + * unique; searching the rtable by name is a bad idea. + * + * p_joinexprs: list of JoinExpr nodes associated with p_rtable entries. + * This is one-for-one with p_rtable, but contains NULLs for non-join + * RTEs, and may be shorter than p_rtable if the last RTE(s) aren't joins. + * + * p_joinlist: list of join items (RangeTblRef and JoinExpr nodes) that + * will become the fromlist of the query's top-level FromExpr node. + * + * p_relnamespace: list of RTEs that represents the current namespace for + * table lookup, ie, those RTEs that are accessible by qualified names. + * This may be just a subset of the rtable + joinlist, and/or may contain + * entries that are not yet added to the main joinlist. + * + * p_varnamespace: list of RTEs that represents the current namespace for + * column lookup, ie, those RTEs that are accessible by unqualified names. + * This is different from p_relnamespace because a JOIN without an alias does + * not hide the contained tables (so they must still be in p_relnamespace) + * but it does hide their columns (unqualified references to the columns must + * refer to the JOIN, not the member tables). Other special RTEs such as + * NEW/OLD for rules may also appear in just one of these lists. + * + * p_ctenamespace: list of CommonTableExprs (WITH items) that are visible + * at the moment. This is different from p_relnamespace because you have + * to make an RTE before you can access a CTE. + * + * p_future_ctes: list of CommonTableExprs (WITH items) that are not yet + * visible due to scope rules. This is used to help improve error messages. + * + * p_parent_cte: CommonTableExpr that immediately contains the current query, + * if any. + * + * p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses. + * We collect these while transforming expressions and then transform them + * afterwards (so that any resjunk tlist items needed for the sort/group + * clauses end up at the end of the query tlist). A WindowDef's location in + * this list, counting from 1, is the winref number to use to reference it. + */ +struct ParseState { + struct ParseState* parentParseState; /* stack link */ + const char* p_sourcetext; /* source text, or NULL if not available */ + List* p_rtable; /* range table so far */ + List* p_joinexprs; /* JoinExprs for RTE_JOIN p_rtable entries */ + List* p_joinlist; /* join items so far (will become FromExpr + node's fromlist) */ + List* p_relnamespace; /* current namespace for relations */ + List* p_varnamespace; /* current namespace for columns */ + bool p_lateral_active; /* p_lateral_only items visible? */ + List* p_ctenamespace; /* current namespace for common table exprs */ + List* p_future_ctes; /* common table exprs not yet in namespace */ + CommonTableExpr* p_parent_cte; /* this query's containing CTE */ + List* p_windowdefs; /* raw representations of window clauses */ + int p_next_resno; /* next targetlist resno to assign */ + List* p_locking_clause; /* raw FOR UPDATE/FOR SHARE info */ + Node* p_value_substitute; /* what to replace VALUE with, if any */ + bool p_hasAggs; + bool p_hasWindowFuncs; + bool p_hasSubLinks; + bool p_hasModifyingCTE; + bool p_is_insert; + bool p_locked_from_parent; + bool p_resolve_unknowns; /* resolve unknown-type SELECT outputs as type text */ + bool p_hasSynonyms; + Relation p_target_relation; + RangeTblEntry* p_target_rangetblentry; + + /* + * Optional hook functions for parser callbacks. These are null unless + * set up by the caller of make_parsestate. + */ + PreParseColumnRefHook p_pre_columnref_hook; + PostParseColumnRefHook p_post_columnref_hook; + ParseParamRefHook p_paramref_hook; + CoerceParamHook p_coerce_param_hook; + void* p_ref_hook_state; /* common passthrough link for above */ + List* p_target_list; + + /* + * star flag info + * + * create table t1(a int, b int); + * create table t2(a int, b int); + * + * For query: select * from t1 + * star_start = 1; + * star_end = 2; + * star_only = 1; + * + * For query: select t1.*, t2.* from t1, t2 + * star_start = 1, 3; + * star_end = 2, 4; + * star_only = -1, -1; + */ + List* p_star_start; + List* p_star_end; + List* p_star_only; + + /* + * The p_is_in_insert will indicate the sub link is under one top insert statement. + * When p_is_in_insert is true, then we will check if sub link include foreign table, + * If foreign is found, we will set top level insert ParseState's p_is_foreignTbl_exist to true. + * Finially, we will set p_is_td_compatible_truncation to true if the td_compatible_truncation guc + * parameter is on, no foreign table involved in this insert statement. + */ + bool p_is_foreignTbl_exist; /* make there is foreign table founded. */ + bool p_is_in_insert; /* mark the subquery is under one insert statement. */ + bool p_is_td_compatible_truncation; /* mark the auto truncation for insert statement is enabled. */ + TdTruncCastStatus tdTruncCastStatus; /* Auto truncation Cast added, only used for stmt in stored procedure or + prepare stmt. */ + bool isAliasReplace; /* Mark if permit replace. */ + + /* + * Fields for transform "(+)" to outerjoin + */ + bool ignoreplus; /* + * Whether ignore "(+)" during transform stmt? False is default, + * report error when found "(+)". Only true when transform WhereClause + * in SelectStmt. + */ + + PlusJoinRTEInfo* p_plusjoin_rte_info; /* The RTE info while processing "(+)" */ +}; + +/* An element of p_relnamespace or p_varnamespace */ +typedef struct ParseNamespaceItem +{ + RangeTblEntry *p_rte; /* The relation's rangetable entry */ + bool p_lateral_only; /* Is only visible to LATERAL expressions? */ + bool p_lateral_ok; /* If so, does join type allow use? */ +} ParseNamespaceItem; + +/* Support for parser_errposition_callback function */ +typedef struct ParseCallbackState { + ParseState* pstate; + int location; +#ifndef FRONTEND + ErrorContextCallback errcontext; +#endif +} ParseCallbackState; + +extern ParseState* make_parsestate(ParseState* parentParseState); +extern void free_parsestate(ParseState* pstate); +extern int parser_errposition(ParseState* pstate, int location); + +extern void setup_parser_errposition_callback(ParseCallbackState* pcbstate, ParseState* pstate, int location); +extern void cancel_parser_errposition_callback(ParseCallbackState* pcbstate); + +extern Var* make_var(ParseState* pstate, RangeTblEntry* rte, int attrno, int location); +extern Var* ts_make_var(ParseState* pstate, RangeTblEntry* rte, int attrno, int location); +extern Oid transformArrayType(Oid* arrayType, int32* arrayTypmod); +extern ArrayRef* transformArraySubscripts(ParseState* pstate, Node* arrayBase, Oid arrayType, Oid elementType, + int32 arrayTypMod, List* indirection, Node* assignFrom); +extern Const* make_const(ParseState* pstate, Value* value, int location); + +#endif /* PARSE_NODE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_oper.h postgresql-hll-2.14/include/include/parser/parse_oper.h --- postgresql-hll-2.14_old/include/include/parser/parse_oper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_oper.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * parse_oper.h + * handle operator things for parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_oper.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_OPER_H +#define PARSE_OPER_H + +#include "access/htup.h" +#include "parser/parse_node.h" + +typedef HeapTuple Operator; + +/* Routines to look up an operator given name and exact input type(s) */ +extern Oid LookupOperName(ParseState* pstate, List* opername, Oid oprleft, Oid oprright, bool noError, int location); +extern Oid LookupOperNameTypeNames( + ParseState* pstate, List* opername, TypeName* oprleft, TypeName* oprright, bool noError, int location); + +/* Routines to find operators matching a name and given input types */ +/* NB: the selected operator may require coercion of the input types! */ +extern Operator oper( + ParseState* pstate, List* op, Oid arg1, Oid arg2, bool noError, int location, bool inNumeric = false); +extern Operator right_oper(ParseState* pstate, List* op, Oid arg, bool noError, int location); +extern Operator left_oper(ParseState* pstate, List* op, Oid arg, bool noError, int location); + +/* Routines to find operators that DO NOT require coercion --- ie, their */ +/* input types are either exactly as given, or binary-compatible */ +extern Operator compatible_oper(ParseState* pstate, List* op, Oid arg1, Oid arg2, bool noError, int location); + +/* currently no need for compatible_left_oper/compatible_right_oper */ +/* Routines for identifying "<", "=", ">" operators for a type */ +extern void get_sort_group_operators( + Oid argtype, bool needLT, bool needEQ, bool needGT, Oid* ltOpr, Oid* eqOpr, Oid* gtOpr, bool* isHashable); + +/* Convenience routines for common calls on the above */ +extern Oid compatible_oper_opid(List* op, Oid arg1, Oid arg2, bool noError); + +/* Extract operator OID or underlying-function OID from an Operator tuple */ +extern Oid oprid(Operator op); +extern Oid oprfuncid(Operator op); + +extern bool IsIntType(Oid typeoid); +extern bool IsCharType(Oid typeoid); + +/* Build expression tree for an operator invocation */ +extern Expr* make_op(ParseState* pstate, List* opname, Node* ltree, Node* rtree, int location, bool inNumeric = false); +extern Expr* make_scalar_array_op(ParseState* pstate, List* opname, bool useOr, Node* ltree, Node* rtree, int location); +extern Oid OperatorLookup(List* operatorName, Oid leftObjectId, Oid rightObjectId, bool* defined); +extern void InvalidateOprCacheCallBack(Datum arg, int cacheid, uint32 hashvalue); +#endif /* PARSE_OPER_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_param.h postgresql-hll-2.14/include/include/parser/parse_param.h --- postgresql-hll-2.14_old/include/include/parser/parse_param.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_param.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * parse_param.h + * handle parameters in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_param.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_PARAM_H +#define PARSE_PARAM_H + +#include "parser/parse_node.h" + +extern void parse_fixed_parameters(ParseState* pstate, Oid* paramTypes, int numParams); +extern void parse_variable_parameters(ParseState* pstate, Oid** paramTypes, int* numParams); +extern void check_variable_parameters(ParseState* pstate, Query* query); + +#endif /* PARSE_PARAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_relation.h postgresql-hll-2.14/include/include/parser/parse_relation.h --- postgresql-hll-2.14_old/include/include/parser/parse_relation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_relation.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * parse_relation.h + * prototypes for parse_relation.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_relation.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_RELATION_H +#define PARSE_RELATION_H + +#include "parser/parse_node.h" + +extern RangeTblEntry* refnameRangeTblEntry( + ParseState* pstate, const char* schemaname, const char* refname, int location, int* sublevels_up); +extern CommonTableExpr* scanNameSpaceForCTE(ParseState* pstate, const char* refname, Index* ctelevelsup); +extern void checkNameSpaceConflicts(ParseState* pstate, List* namespace1, List* namespace2); +extern int RTERangeTablePosn(ParseState* pstate, RangeTblEntry* rte, int* sublevels_up); +extern RangeTblEntry* GetRTEByRangeTablePosn(ParseState* pstate, int varno, int sublevels_up); +extern CommonTableExpr* GetCTEForRTE(ParseState* pstate, RangeTblEntry* rte, int rtelevelsup); +extern Node* scanRTEForColumn(ParseState* pstate, RangeTblEntry* rte, char* colname, int location, bool omit = false); +extern Node* colNameToVar( + ParseState* pstate, char* colname, bool localonly, int location, RangeTblEntry** final_rte = NULL); +extern void markVarForSelectPriv(ParseState* pstate, Var* var, RangeTblEntry* rte); +extern Relation parserOpenTable(ParseState* pstate, const RangeVar* relation, int lockmode, bool isFirstNode = true, + bool isCreateView = false, bool isSupportSynonym = false); +extern RangeTblEntry* addRangeTableEntry(ParseState* pstate, RangeVar* relation, Alias* alias, bool inh, bool inFromCl, + bool isFirstNode = true, bool isCreateView = false, bool isSupportSynonym = false); +extern RangeTblEntry* addRangeTableEntryForRelation( + ParseState* pstate, Relation rel, Alias* alias, bool inh, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForSubquery( + ParseState* pstate, Query* subquery, Alias* alias, bool lateral, bool inFromCl, bool sublinkPullUp = false); +extern RangeTblEntry* addRangeTableEntryForFunction( + ParseState* pstate, char* funcname, Node* funcexpr, RangeFunction* rangefunc, bool lateral, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForValues( + ParseState* pstate, List* exprs, List* collations, Alias* alias, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForJoin( + ParseState* pstate, List* colnames, JoinType jointype, List* aliasvars, Alias* alias, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForCTE( + ParseState* pstate, CommonTableExpr* cte, Index levelsup, RangeVar* rv, bool inFromCl); +extern RangeTblEntry* getRangeTableEntryByRelation(Relation rel); +extern bool isLockedRefname(ParseState* pstate, const char* refname); +extern void addRTEtoQuery( + ParseState* pstate, RangeTblEntry* rte, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace); +extern void errorMissingRTE(ParseState* pstate, RangeVar* relation, bool hasplus = false); +extern void errorMissingColumn(ParseState *pstate, char *relname, char *colname, int location); +extern void expandRTE(RangeTblEntry* rte, int rtindex, int sublevels_up, int location, bool include_dropped, + List** colnames, List** colvars); +extern List* expandRelAttrs(ParseState* pstate, RangeTblEntry* rte, int rtindex, int sublevels_up, int location); +extern int attnameAttNum(Relation rd, const char* attname, bool sysColOK); +extern Name attnumAttName(Relation rd, int attid); +extern Oid attnumTypeId(Relation rd, int attid); +extern Oid attnumCollationId(Relation rd, int attid); + +#ifdef PGXC +extern int specialAttNum(const char* attname); +#endif + +#endif /* PARSE_RELATION_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parser.h postgresql-hll-2.14/include/include/parser/parser.h --- postgresql-hll-2.14_old/include/include/parser/parser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parser.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * parser.h + * Definitions for the "raw" parser (flex and bison phases only) + * + * This is the external API for the raw lexing/parsing functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parser.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSER_H +#define PARSER_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#else +#include "nodes/parsenodes_common.h" +#endif /* FRONTEND_PARSER */ + +#include "parser/backslash_quotes.h" + +#define UPSERT_TO_MERGE_VERSION_NUM 92022 + +/* Primary entry point for the raw parsing functions */ +extern List* raw_parser(const char* str, List** query_string_locationlist = NULL); + +#ifdef FRONTEND_PARSER + +class PGClientLogic; + +extern List *fe_raw_parser(PGClientLogic*, const char *str, List **query_string_locationlist = NULL); +#endif /* FRONTEND_PARSER */ + +/* Utility functions exported by gram.y (perhaps these should be elsewhere) */ +extern List* SystemFuncName(char* name); +extern TypeName* SystemTypeName(char* name); +extern Node* makeBoolAConst(bool state, int location); +extern char** get_next_snippet( + char** query_string_single, const char* query_string, List* query_string_locationlist, int* stmt_num); + +extern void fixResTargetNameWithAlias(List* clause_list, const char* aliasname); + +#endif /* PARSER_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_target.h postgresql-hll-2.14/include/include/parser/parse_target.h --- postgresql-hll-2.14_old/include/include/parser/parse_target.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_target.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * parse_target.h + * handle target lists + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_target.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_TARGET_H +#define PARSE_TARGET_H + +#include "parser/parse_node.h" + +extern List* transformTargetList(ParseState* pstate, List* targetlist); +extern List* transformExpressionList(ParseState* pstate, List* exprlist); +extern void markTargetListOrigins(ParseState* pstate, List* targetlist); +extern void resolveTargetListUnknowns(ParseState* pstate, List* targetlist); +extern TargetEntry* transformTargetEntry(ParseState* pstate, Node* node, Node* expr, char* colname, bool resjunk); +extern Expr* transformAssignedExpr( + ParseState* pstate, Expr* expr, char* colname, int attrno, List* indirection, int location); +extern void updateTargetListEntry( + ParseState* pstate, TargetEntry* tle, char* colname, int attrno, List* indirection, int location); +extern List* checkInsertTargets(ParseState* pstate, List* cols, List** attrnos); +extern TupleDesc expandRecordVariable(ParseState* pstate, Var* var, int levelsup); +extern char* FigureColname(Node* node); +extern char* FigureIndexColname(Node* node); + +#endif /* PARSE_TARGET_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parsetree.h postgresql-hll-2.14/include/include/parser/parsetree.h --- postgresql-hll-2.14_old/include/include/parser/parsetree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parsetree.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * parsetree.h + * Routines to access various components and subcomponents of + * parse trees. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parsetree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSETREE_H +#define PARSETREE_H + +#include "nodes/parsenodes.h" + +/* ---------------- + * range table operations + * ---------------- + */ +/* + * rt_fetch + * + * NB: this will crash and burn if handed an out-of-range RT index + */ +#define rt_fetch(rangetable_index, rangetable) ((RangeTblEntry*)list_nth(rangetable, (rangetable_index)-1)) + +/* + * getrelid + * + * Given the range index of a relation, return the corresponding + * relation OID. Note that InvalidOid will be returned if the + * RTE is for a non-relation-type RTE. + */ +#define getrelid(rangeindex, rangetable) (rt_fetch(rangeindex, rangetable)->relid) + +/* + * Given an RTE and an attribute number, return the appropriate + * variable name or alias for that attribute of that RTE. + */ +extern char* get_rte_attribute_name(RangeTblEntry* rte, AttrNumber attnum); + +/* + * Given an RTE and an attribute number, return the appropriate + * type and typemod info for that attribute of that RTE. + */ +extern void get_rte_attribute_type( + RangeTblEntry* rte, AttrNumber attnum, Oid* vartype, int32* vartypmod, Oid* varcollid, int* kvtype = NULL); + +/* + * Check whether an attribute of an RTE has been dropped (note that + * get_rte_attribute_type will fail on such an attr) + */ +extern bool get_rte_attribute_is_dropped(RangeTblEntry* rte, AttrNumber attnum); + +/* ---------------- + * target list operations + * ---------------- + */ +extern TargetEntry* get_tle_by_resno(List* tlist, AttrNumber resno); + +/* ---------------- + * FOR UPDATE/SHARE info + * ---------------- + */ +extern RowMarkClause* get_parse_rowmark(Query* qry, Index rtindex); + +#endif /* PARSETREE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_type.h postgresql-hll-2.14/include/include/parser/parse_type.h --- postgresql-hll-2.14_old/include/include/parser/parse_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_type.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * parse_type.h + * handle type operations for parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_type.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_TYPE_H +#define PARSE_TYPE_H + +#include "access/htup.h" +#include "parser/parse_node.h" + +typedef HeapTuple Type; + +extern Type LookupTypeName(ParseState* pstate, const TypeName* typname, int32* typmod_p, bool print_notice = true); +extern Type typenameType(ParseState* pstate, const TypeName* typname, int32* typmod_p); +extern Oid typenameTypeId(ParseState* pstate, const TypeName* typname); +extern void typenameTypeIdAndMod(ParseState* pstate, const TypeName* typname, Oid* typeid_p, int32* typmod_p); + +extern char* TypeNameToString(const TypeName* typname); +extern char* TypeNameListToString(List* typenames); + +extern Oid LookupCollation(ParseState* pstate, List* collnames, int location); +extern Oid GetColumnDefCollation(ParseState* pstate, ColumnDef* coldef, Oid typeOid); + +extern Type typeidType(Oid id); + +extern Oid typeTypeId(Type tp); +extern int16 typeLen(Type t); +extern bool typeByVal(Type t); +extern char* typeTypeName(Type t); +extern Oid typeTypeRelid(Type typ); +extern Oid typeTypeCollation(Type typ); +extern Datum stringTypeDatum(Type tp, char* string, int32 atttypmod); + +extern Oid typeidTypeRelid(Oid type_id); +extern bool IsTypeSupportedByCStore(_in_ Oid typeOid, _in_ int32 typeMod); +extern bool IsTypeSupportedByORCRelation(_in_ Oid typeOid); +extern bool IsTypeSupportedByTsStore(_in_ int kvtype, _in_ Oid typeOid); + +extern void parseTypeString(const char* str, Oid* typeid_p, int32* typmod_p); +extern bool IsTypeTableInInstallationGroup(const Type type_tup); +#define ISCOMPLEX(typeid) (typeidTypeRelid(typeid) != InvalidOid) + +#endif /* PARSE_TYPE_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/parse_utilcmd.h postgresql-hll-2.14/include/include/parser/parse_utilcmd.h --- postgresql-hll-2.14_old/include/include/parser/parse_utilcmd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/parse_utilcmd.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------- + * + * parse_utilcmd.h + * parse analysis for utility commands + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/parser/parse_utilcmd.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_UTILCMD_H +#define PARSE_UTILCMD_H + +#include "parser/parse_node.h" + +extern void checkPartitionSynax(CreateStmt *stmt); +extern List* transformCreateStmt(CreateStmt* stmt, const char* queryString, const List* uuids, + bool preCheck, bool isFirstNode = true); +extern List* transformAlterTableStmt(Oid relid, AlterTableStmt* stmt, const char* queryString); +extern IndexStmt* transformIndexStmt(Oid relid, IndexStmt* stmt, const char* queryString); +extern void transformRuleStmt(RuleStmt* stmt, const char* queryString, List** actions, Node** whereClause); +extern List* transformCreateSchemaStmt(CreateSchemaStmt* stmt); +extern void transformRangePartitionValue(ParseState* pstate, Node* rangePartDef, bool needCheck); +extern List* transformListPartitionValue(ParseState* pstate, List* boundary, bool needCheck, bool needFree); +extern List* transformRangePartitionValueInternal(ParseState* pstate, List* boundary, + bool needCheck, bool needFree, bool isPartition = true); +extern Node* transformIntoConst(ParseState* pstate, Node* maxElem, bool isPartition = true); + +#ifdef PGXC +extern bool CheckLocalIndexColumn(char loctype, char* partcolname, char* indexcolname); +#endif +extern Oid generateClonedIndex(Relation source_idx, Relation source_relation, char* tempIndexName, Oid targetTblspcOid, + bool skip_build, bool partitionedIndex); +extern void checkPartitionName(List* partitionList, bool isPartition = true); + +extern Oid searchSeqidFromExpr(Node* cooked_default); +extern bool is_start_end_def_list(List* def_list); +extern void get_range_partition_name_prefix(char* namePrefix, char* srcName, bool printNotice, bool isPartition); +extern List* transformRangePartStartEndStmt(ParseState* pstate, List* partitionList, List* pos, + Form_pg_attribute* attrs, int32 existPartNum, Const* lowBound, Const* upBound, bool needFree, + bool isPartition = true); +extern bool check_contains_tbllike_in_multi_nodegroup(CreateStmt* stmt); +extern bool is_multi_nodegroup_createtbllike(PGXCSubCluster* subcluster, Oid oid); + +#endif /* PARSE_UTILCMD_H */ diff -uprN postgresql-hll-2.14_old/include/include/parser/scanner.h postgresql-hll-2.14/include/include/parser/scanner.h --- postgresql-hll-2.14_old/include/include/parser/scanner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/scanner.h 2020-12-12 17:06:43.244347999 +0800 @@ -0,0 +1,149 @@ +/* ------------------------------------------------------------------------- + * + * scanner.h + * API for the core scanner (flex machine) + * + * The core scanner is also used by PL/pgsql, so we provide a public API + * for it. However, the rest of the backend is only expected to use the + * higher-level API provided by parser.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/scanner.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCANNER_H +#define SCANNER_H + +#include "nodes/parsenodes_common.h" +#include "parser/keywords.h" + +#ifdef FRONTEND_PARSER +#include +#define ereport(a, b) fe_rethrow(yyscanner) +#endif + +/* + * The scanner returns extra data about scanned tokens in this union type. + * Note that this is a subset of the fields used in YYSTYPE of the bison + * parsers built atop the scanner. + */ +typedef union core_YYSTYPE { + int ival; /* for integer literals */ + char* str; /* for identifiers and non-integer literals */ + const char* keyword; /* canonical spelling of keywords */ +} core_YYSTYPE; + +/* + * We track token locations in terms of byte offsets from the start of the + * source string, not the column number/line number representation that + * bison uses by default. Also, to minimize overhead we track only one + * location (usually the first token location) for each construct, not + * the beginning and ending locations as bison does by default. It's + * therefore sufficient to make YYLTYPE an int. + */ +#define YYLTYPE int + +/* + * Another important component of the scanner's API is the token code numbers. + * However, those are not defined in this file, because bison insists on + * defining them for itself. The token codes used by the core scanner are + * the ASCII characters plus these: + * %token IDENT FCONST SCONST BCONST XCONST Op + * %token ICONST PARAM + * %token TYPECAST DOT_DOT COLON_EQUALS PARA_EQUALS + * The above token definitions *must* be the first ones declared in any + * bison parser built atop this scanner, so that they will have consistent + * numbers assigned to them (specifically, IDENT = 258 and so on). + */ + +/* + * The YY_EXTRA data that a flex scanner allows us to pass around. + * Private state needed by the core scanner goes here. Note that the actual + * yy_extra struct may be larger and have this as its first component, thus + * allowing the calling parser to keep some fields of its own in YY_EXTRA. + */ +typedef struct core_yy_extra_type { + /* + * The string the scanner is physically scanning. We keep this mainly so + * that we can cheaply compute the offset of the current token (yytext). + */ + char* scanbuf; + Size scanbuflen; + + /* + * The keyword list to use. + */ + const ScanKeyword* keywords; + int num_keywords; + + /* + * literalbuf is used to accumulate literal values when multiple rules are + * needed to parse a single literal. Call startlit() to reset buffer to + * empty, addlit() to add text. NOTE: the string in literalbuf is NOT + * necessarily null-terminated, but there always IS room to add a trailing + * null at offset literallen. We store a null only when we need it. + */ + char* literalbuf; /* palloc'd expandable buffer */ + int literallen; /* actual current string length */ + int literalalloc; /* current allocated buffer size */ + + int xcdepth; /* depth of nesting in slash-star comments */ + char* dolqstart; /* current $foo$ quote start string */ + + /* first part of UTF16 surrogate pair for Unicode escapes */ + int32 utf16_first_part; + + /* state variables for literal-lexing warnings */ + bool warn_on_first_escape; + bool saw_non_ascii; + bool ident_quoted; + bool warnOnTruncateIdent; + + /* record the message need by multi-query. */ + List* query_string_locationlist; /* record the end location of each single query */ + bool in_slash_proc_body; /* check whether it's in a slash proc body */ + int paren_depth; /* record the current depth in the '(' and ')' */ + bool is_createstmt; /* check whether it's a create statement. */ + bool is_hint_str; /* current identifier is in hint comment string */ + List* parameter_list; /* placeholder parameter list */ +} core_yy_extra_type; + +#ifdef FRONTEND_PARSER + +class PGClientLogic; + +void fe_rethrow(void *yyscanner); +struct fe_core_yy_extra_type : public core_yy_extra_type { +public: + jmp_buf jump_buffer; + PGClientLogic *m_clientLogic; +}; +#endif /* FRONTEND_PARSER */ + +/* + * The type of yyscanner is opaque outside scan.l. + */ +typedef void* core_yyscan_t; +typedef void* yyscan_t; + +/* Entry points in parser/scan.l */ +extern core_yyscan_t scanner_init( + const char* str, core_yy_extra_type* yyext, const ScanKeyword* keywords, int num_keywords); + +#ifdef FRONTEND_PARSER +extern core_yyscan_t fe_scanner_init(const char *str, fe_core_yy_extra_type *yyext, + const ScanKeyword *keywords, int num_keywords); +#endif /* FRONTEND_PARSER */ + +extern void scanner_finish(core_yyscan_t yyscanner); +extern int core_yylex(core_YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner); +extern int scanner_errposition(int location, core_yyscan_t yyscanner); +extern void scanner_yyerror(const char* message, core_yyscan_t yyscanner); + +#endif /* SCANNER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/parser/scansup.h postgresql-hll-2.14/include/include/parser/scansup.h --- postgresql-hll-2.14_old/include/include/parser/scansup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/parser/scansup.h 2020-12-12 17:06:43.245348013 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * scansup.h + * scanner support routines. used by both the bootstrap lexer + * as well as the normal lexer + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/scansup.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCANSUP_H +#define SCANSUP_H + +extern char* scanstr(const char* s); + +extern char* downcase_truncate_identifier(const char* ident, int len, bool warn); + +extern void truncate_identifier(char* ident, int len, bool warn); + +extern bool scanner_isspace(char ch); + +#endif /* SCANSUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgaudit.h postgresql-hll-2.14/include/include/pgaudit.h --- postgresql-hll-2.14_old/include/include/pgaudit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgaudit.h 2020-12-12 17:06:43.245348013 +0800 @@ -0,0 +1,154 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pgaudit.h + * + * + * + * IDENTIFICATION + * src/include/pgaudit.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PGAUDIT_H +#define _PGAUDIT_H + +#include "fmgr.h" + +extern THR_LOCAL bool Audit_delete; + +#define AUDIT_EXEC_ENABLED (u_sess->attr.attr_security.Audit_enabled && u_sess->attr.attr_security.Audit_Exec) +#define AUDIT_COPY_ENABLED (u_sess->attr.attr_security.Audit_enabled && u_sess->attr.attr_security.Audit_Copy) +#define CHECK_AUDIT_DDL(type) ((unsigned int)u_sess->attr.attr_security.Audit_DDL & (1 << (type))) +#define CHECK_AUDIT_LOGIN(type) (unsigned int)u_sess->attr.attr_security.Audit_Session & (1 << (type)); +#define PG_QUERY_AUDIT_ARGS_MAX 3 + +extern THR_LOCAL bool am_sysauditor; + +#ifndef WIN32 +extern int sysauditPipe[2]; +#else +extern HANDLE sysauditPipe[2]; +#endif + +extern ThreadId pgaudit_start(void); +extern void allow_immediate_pgaudit_restart(void); + +#ifdef EXEC_BACKEND +extern void PgAuditorMain(); +#endif + +/* ---------- + * Functions called from backends, the sequence is relevent to struct AuditTypeDescs which should be changed in the same time + * ---------- + */ + +typedef enum { + AUDIT_UNKNOWN_TYPE = 0, + AUDIT_LOGIN_SUCCESS, + AUDIT_LOGIN_FAILED, + AUDIT_USER_LOGOUT, + AUDIT_SYSTEM_START, + AUDIT_SYSTEM_STOP, + AUDIT_SYSTEM_RECOVER, + AUDIT_SYSTEM_SWITCH, + AUDIT_LOCK_USER, + AUDIT_UNLOCK_USER, + AUDIT_GRANT_ROLE, + AUDIT_REVOKE_ROLE, + AUDIT_USER_VIOLATION, + AUDIT_DDL_DATABASE, + AUDIT_DDL_DIRECTORY, + AUDIT_DDL_TABLESPACE, + AUDIT_DDL_SCHEMA, + AUDIT_DDL_USER, + AUDIT_DDL_TABLE, + AUDIT_DDL_INDEX, + AUDIT_DDL_VIEW, + AUDIT_DDL_TRIGGER, + AUDIT_DDL_FUNCTION, + AUDIT_DDL_RESOURCEPOOL, + AUDIT_DDL_WORKLOAD, + AUDIT_DDL_SERVERFORHADOOP, + AUDIT_DDL_DATASOURCE, + AUDIT_DDL_NODEGROUP, + AUDIT_DDL_ROWLEVELSECURITY, + AUDIT_DDL_SYNONYM, + AUDIT_DDL_TYPE, + AUDIT_DDL_TEXTSEARCH, + AUDIT_DML_ACTION, + AUDIT_DML_ACTION_SELECT, + AUDIT_INTERNAL_EVENT, + AUDIT_FUNCTION_EXEC, + AUDIT_COPY_TO, + AUDIT_COPY_FROM, + AUDIT_SET_PARAMETER, + AUDIT_POLICY_EVENT, + MASKING_POLICY_EVENT, + SECURITY_EVENT, + AUDIT_DDL_SEQUENCE // ddl_sequence in struct AuditTypeDescs +} AuditType; + +typedef enum { + DDL_DATABASE = 0, + DDL_SCHEMA, + DDL_USER, + DDL_TABLE, + DDL_INDEX, + DDL_VIEW, + DDL_TRIGGER, + DDL_FUNCTION, + DDL_TABLESPACE, + DDL_RESOURCEPOOL, + DDL_WORKLOAD, + DDL_SERVERFORHADOOP, + DDL_DATASOURCE, + DDL_NODEGROUP, + DDL_ROWLEVELSECURITY, + DDL_TYPE, + DDL_TEXTSEARCH, + DDL_DIRECTORY, + DDL_SYNONYM, + DDL_SEQUENCE +} DDLType; + +typedef enum { AUDIT_UNKNOWN = 0, AUDIT_OK, AUDIT_FAILED } AuditResult; + +typedef enum { AUDIT_FUNC_QUERY = 0, AUDIT_FUNC_DELETE } AuditFuncType; + +typedef enum { STD_AUDIT_TYPE = 0, UNIFIED_AUDIT_TYPE } AuditClassType; +extern void audit_report(AuditType type, AuditResult result, const char* object_name, const char* detail_info, AuditClassType ctype = STD_AUDIT_TYPE); + +extern Datum pg_query_audit(PG_FUNCTION_ARGS); + +extern Datum pg_delete_audit(PG_FUNCTION_ARGS); + +/* define a macro about the return value of security function */ +#define check_intval(errno, express, retval, file, line) \ + { \ + if (errno == -1) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_intval(val, express, retval) check_intval(val, express, retval, __FILE__, __LINE__) + +#endif /* _PGAUDIT_H */ diff -uprN postgresql-hll-2.14_old/include/include/pg_config.h postgresql-hll-2.14/include/include/pg_config.h --- postgresql-hll-2.14_old/include/include/pg_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pg_config.h 2020-12-12 17:06:43.245348013 +0800 @@ -0,0 +1,906 @@ +/* src/include/pg_config.h. Generated from pg_config.h.in by configure. */ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to the type of arg 1 of 'accept' */ +#define ACCEPT_TYPE_ARG1 int + +/* Define to the type of arg 2 of 'accept' */ +#define ACCEPT_TYPE_ARG2 struct sockaddr * + +/* Define to the type of arg 3 of 'accept' */ +#define ACCEPT_TYPE_ARG3 socklen_t + +/* Define to the return type of 'accept' */ +#define ACCEPT_TYPE_RETURN int + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* The normal alignment of `double', in bytes. */ +#define ALIGNOF_DOUBLE 8 + +/* The normal alignment of `int', in bytes. */ +#define ALIGNOF_INT 4 + +/* The normal alignment of `long', in bytes. */ +#define ALIGNOF_LONG 8 + +/* The normal alignment of `long long int', in bytes. */ +/* #undef ALIGNOF_LONG_LONG_INT */ + +/* The normal alignment of `short', in bytes. */ +#define ALIGNOF_SHORT 2 + +/* Size of a disk block --- this also limits the size of a tuple. You can set + it bigger if you need bigger tuples (although TOAST should reduce the need + to have large tuples, since fields can be spread across multiple tuples). + BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is + currently 2^15 (32768). This is determined by the 15-bit widths of the + lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h). + Changing BLCKSZ requires an initdb. */ +#define BLCKSZ 8192 + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#define DEF_PGPORT 5432 + +/* Define to the default TCP port number as a string constant. */ +#define DEF_PGPORT_STR "5432" + +/* Define to build with GSSAPI support. (--with-gssapi) */ +#define ENABLE_GSS 1 + +/* Define to build with PYTHON support. (--with-python) */ +/* #undef ENABLE_PYTHON2 */ +/* #undef ENABLE_PYTHON3 */ + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +/* #undef ENABLE_NLS */ + +/* Define to 1 if you want to generate gauss product as multiple nodes. (--enable-multiple-nodes) */ +#define ENABLE_MULTIPLE_NODES 1 + +/* Define to 1 if you want to check memory. (--enable-memory-check) */ +/* #undef ENABLE_MEMORY_CHECK */ + +/* Define to 1 if you want to check thread. (--enable-thread-check) */ +/* #undef ENABLE_THREAD_CHECK */ + +/* Define to 1 if you want to use default gcc. (--enable-default-gcc) */ +/* #undef ENABLE_DEFAULT_GCC */ + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#define ENABLE_THREAD_SAFETY 1 + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#define FLEXIBLE_ARRAY_MEMBER /**/ + +/* float4 values are passed by value if 'true', by reference if 'false' */ +#define FLOAT4PASSBYVAL true + +/* float8, int8, and related values are passed by value if 'true', by + reference if 'false' */ +#define FLOAT8PASSBYVAL true + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +#define GETPWUID_R_5ARG /**/ + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +/* #undef GETTIMEOFDAY_1ARG */ + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `append_history' function. */ +/* #undef HAVE_APPEND_HISTORY */ + +/* Define to 1 if you have the `cbrt' function. */ +#define HAVE_CBRT 1 + +/* Define to 1 if you have the `class' function. */ +/* #undef HAVE_CLASS */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRTDEFS_H */ + +/* Define to 1 if you have the `crypt' function. */ +#define HAVE_CRYPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_CRYPT_H 1 + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#define HAVE_DECL_FDATASYNC 1 + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#define HAVE_DECL_F_FULLFSYNC 0 + +/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you + don't. */ +#define HAVE_DECL_POSIX_FADVISE 1 + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#define HAVE_DECL_SNPRINTF 1 + +/* Define to 1 if you have the declaration of `strlcat', and to 0 if you + don't. */ +#define HAVE_DECL_STRLCAT 0 + +/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you + don't. */ +#define HAVE_DECL_STRLCPY 0 + +/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you + don't. */ +#define HAVE_DECL_SYS_SIGLIST 1 + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#define HAVE_DECL_VSNPRINTF 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLD_H */ + +/* Define to 1 if you have the `dlopen' function. */ +#define HAVE_DLOPEN 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_READLINE_H */ + +/* Define to 1 if you have the `fdatasync' function. */ +#define HAVE_FDATASYNC 1 + +/* Define to 1 if you have the `fls' function. */ +/* #undef HAVE_FLS */ + +/* Define to 1 if you have the `fpclass' function. */ +/* #undef HAVE_FPCLASS */ + +/* Define to 1 if you have the `fp_class' function. */ +/* #undef HAVE_FP_CLASS */ + +/* Define to 1 if you have the `fp_class_d' function. */ +/* #undef HAVE_FP_CLASS_D */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FP_CLASS_H */ + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#define HAVE_FSEEKO 1 + +/* Define to 1 if your compiler understands __func__. */ +#define HAVE_FUNCNAME__FUNC 1 + +/* Define to 1 if your compiler understands __FUNCTION__. */ +/* #undef HAVE_FUNCNAME__FUNCTION */ + +/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */ +#define HAVE_GCC_INT_ATOMICS 1 + +/* Define to 1 if you have the `getaddrinfo' function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if you have the `gethostbyname_r' function. */ +#define HAVE_GETHOSTBYNAME_R 1 + +/* Define to 1 if you have the `getifaddrs' function. */ +#define HAVE_GETIFADDRS 1 + +/* Define to 1 if you have the `getopt' function. */ +#define HAVE_GETOPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpeereid' function. */ +/* #undef HAVE_GETPEEREID */ + +/* Define to 1 if you have the `getpeerucred' function. */ +/* #undef HAVE_GETPEERUCRED */ + +/* Define to 1 if you have the `getpwuid_r' function. */ +#define HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#define HAVE_GETRLIMIT 1 + +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +/* #undef HAVE_GETTIMEOFDAY */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GSSAPI_GSSAPI_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GSSAPI_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_HISTORY_H */ + +/* Define to 1 if you have the `history_truncate_file' function. */ +/* #undef HAVE_HISTORY_TRUNCATE_FILE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEEFP_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_IFADDRS_H 1 + +/* Define to 1 if you have the `inet_aton' function. */ +#define HAVE_INET_ATON 1 + +/* Define to 1 if the system has the type `int64'. */ +/* #undef HAVE_INT64 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* Define to 1 if the system has the type `intptr_t'. */ +#define HAVE_INTPTR_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the global variable 'int opterr'. */ +#define HAVE_INT_OPTERR 1 + +/* Define to 1 if you have the global variable 'int optreset'. */ +/* #undef HAVE_INT_OPTRESET */ + +/* Define to 1 if you have the global variable 'int timezone'. */ +#define HAVE_INT_TIMEZONE /**/ + +/* Define to 1 if you have support for IPv6. */ +#define HAVE_IPV6 1 + +/* Define to 1 if you have isinf(). */ +#define HAVE_ISINF 1 + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_E_DATA */ + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_TEXT_DATA */ + +/* Define to 1 if you have krb5_free_unparsed_name. */ +/* #undef HAVE_KRB5_FREE_UNPARSED_NAME */ + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_CLIENT */ + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_ENC_PART2 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LANGINFO_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LDAP_H */ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +/* #undef HAVE_LIBCRYPTO */ + +/* Define to 1 if you have the `ldap' library (-lldap). */ +/* #undef HAVE_LIBLDAP */ + +/* Define to 1 if you have the `ldap_r' library (-lldap_r). */ +/* #undef HAVE_LIBLDAP_R */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `pam' library (-lpam). */ +/* #undef HAVE_LIBPAM */ + +/* Define if you have a function readline library */ +/* #undef HAVE_LIBREADLINE */ + +/* Define to 1 if you have the `selinux' library (-lselinux). */ +/* #undef HAVE_LIBSELINUX */ + +/* Define to 1 if you have the `ssl' library (-lssl). */ +/* #undef HAVE_LIBSSL */ + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +/* #undef HAVE_LIBWLDAP32 */ + +/* Define to 1 if you have the `xml2' library (-lxml2). */ +/* #undef HAVE_LIBXML2 */ + +/* Define to 1 if you have the `xslt' library (-lxslt). */ +/* #undef HAVE_LIBXSLT */ + +/* Define to 1 if you have the `z' library (-lz). */ +#define HAVE_LIBZ 1 + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +/* #undef HAVE_LL_CONSTANTS */ + +/* Define to 1 if the system has the type `locale_t'. */ +#define HAVE_LOCALE_T 1 + +/* Define to 1 if `long int' works and is 64 bits. */ +#define HAVE_LONG_INT_64 1 + +/* Define to 1 if the system has the type `long long int'. */ +#define HAVE_LONG_LONG_INT 1 + +/* Define to 1 if `long long int' works and is 64 bits. */ +/* #undef HAVE_LONG_LONG_INT_64 */ + +/* Define to 1 if you have the `mbstowcs_l' function. */ +/* #undef HAVE_MBSTOWCS_L */ + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +/* #undef HAVE_MINIDUMP_TYPE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_OSSP_UUID_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PAM_PAM_APPL_H */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `posix_fadvise' function. */ +#define HAVE_POSIX_FADVISE 1 + +/* Define to 1 if you have the POSIX signal interface. */ +#define HAVE_POSIX_SIGNALS /**/ + +/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */ +/* #undef HAVE_PPC_LWARX_MUTEX_HINT */ + +/* Define to 1 if you have the `pstat' function. */ +/* #undef HAVE_PSTAT */ + +/* Define to 1 if the PS_STRINGS thing exists. */ +/* #undef HAVE_PS_STRINGS */ + +/* Define if you have POSIX threads libraries and header files. */ +/* #undef HAVE_PTHREAD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* Define to 1 if you have the `random' function. */ +#define HAVE_RANDOM 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_READLINE_H */ + +/* Define to 1 if you have the `readlink' function. */ +#define HAVE_READLINK 1 + +/* Define to 1 if you have the `rint' function. */ +#define HAVE_RINT 1 + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +/* #undef HAVE_RL_COMPLETION_APPEND_CHARACTER */ + +/* Define to 1 if you have the `rl_completion_matches' function. */ +/* #undef HAVE_RL_COMPLETION_MATCHES */ + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +/* #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SECURITY_PAM_APPL_H */ + +/* Define to 1 if you have the `setproctitle' function. */ +/* #undef HAVE_SETPROCTITLE */ + +/* Define to 1 if you have the `setsid' function. */ +#define HAVE_SETSID 1 + +/* Define to 1 if you have the `sigprocmask' function. */ +#define HAVE_SIGPROCMASK 1 + +/* Define to 1 if you have sigsetjmp(). */ +#define HAVE_SIGSETJMP 1 + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have spinlocks. */ +#define HAVE_SPINLOCKS 1 + +/* Define to 1 if you have the `srandom' function. */ +#define HAVE_SRANDOM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#define HAVE_STRERROR_R 1 + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#define HAVE_STRINGIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strlcat' function. */ +/* #undef HAVE_STRLCAT */ + +/* Define to 1 if you have the `strlcpy' function. */ +/* #undef HAVE_STRLCPY */ + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `strtoq' function. */ +/* #undef HAVE_STRTOQ */ + +/* Define to 1 if you have the `strtoull' function. */ +#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the `strtouq' function. */ +/* #undef HAVE_STRTOUQ */ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +/* #undef HAVE_STRUCT_CMSGCRED */ + +/* Define to 1 if the system has the type `struct option'. */ +#define HAVE_STRUCT_OPTION 1 + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +#define HAVE_STRUCT_TM_TM_ZONE 1 + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* Define to 1 if you have the `sync_file_range' function. */ +#define HAVE_SYNC_FILE_RANGE 1 + +/* Define to 1 if you have the syslog interface. */ +#define HAVE_SYSLOG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IPC_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PSTAT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SEM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SHM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOCKIO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_TAS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UCRED_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +#define HAVE_TM_ZONE 1 + +/* Define to 1 if you have the `towlower' function. */ +#define HAVE_TOWLOWER 1 + +/* Define to 1 if you have the external array `tzname'. */ +/* #undef HAVE_TZNAME */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UCRED_H */ + +/* Define to 1 if the system has the type `uint64'. */ +/* #undef HAVE_UINT64 */ + +/* Define to 1 if the system has the type `uint8'. */ +/* #undef HAVE_UINT8 */ + +/* Define to 1 if the system has the type `uintptr_t'. */ +#define HAVE_UINTPTR_T 1 + +/* Define to 1 if the system has the type `union semun'. */ +/* #undef HAVE_UNION_SEMUN */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have unix sockets. */ +#define HAVE_UNIX_SOCKETS 1 + +/* Define to 1 if you have the `unsetenv' function. */ +#define HAVE_UNSETENV 1 + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +#define HAVE_UTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UUID_H */ + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `waitpid' function. */ +#define HAVE_WAITPID 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the `wcstombs' function. */ +#define HAVE_WCSTOMBS 1 + +/* Define to 1 if you have the `wcstombs_l' function. */ +/* #undef HAVE_WCSTOMBS_L */ + +/* Define to 1 if you have the header file. */ +#define HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINLDAP_H */ + +/* Define to the appropriate snprintf format for 64-bit ints. */ +#define INT64_FORMAT "%ld" + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +/* #undef KRB5 */ + +/* Define to 1 if you have __cpuid. */ +/* #undef HAVE__CPUID */ + +/* Define to 1 if you have __get_cpuid. */ +#define HAVE__GET_CPUID 1 + +/* Define to 1 if `locale_t' requires . */ +/* #undef LOCALE_T_IN_XLOCALE */ + +/* Define as the maximum alignment requirement of any C data type. */ +#define MAXIMUM_ALIGNOF 8 + +/* Define bytes to use libc memset(). */ +#define MEMSET_LOOP_LIMIT 1024 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "community@opengauss.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Postgres-XC" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Postgres-XC 1.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "postgres-xc" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.1" + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#define PG_KRB_SRVNAM "postgres" + +/* PostgreSQL major version as a string */ +#define PG_MAJORVERSION "9.2" + +/* PostgreSQL version as a string */ +#define PG_VERSION "9.2.4" + +/* Gaussdb version as a string*/ +#define DEF_GS_VERSION "(GaussDB Kernel V500R001C20 build 98130c06) compiled at 2020-12-05 14:55:29 commit 1093 last mr 1760 debug" + +/* PostgreSQL version as a number */ +#define PG_VERSION_NUM 90204 + +/* Postgres-XC major version as a string */ +#define PGXC_MAJORVERSION "1.1" + +/* Postgres-XC version as a string */ +#define PGXC_VERSION "1.1" + +/* Postgres-XC version as a number */ +#define PGXC_VERSION_NUM + +/* A string containing the version number, platform, and C compiler */ +#define PG_VERSION_STR "PostgreSQL 9.2.4 (GaussDB Kernel V500R001C20 build 98130c06) compiled at 2020-12-05 14:55:29 commit 1093 last mr 1760 debug on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit" + +/* A string containing the version number of Postgres-XC, platform, and C compiler */ +#define PGXC_VERSION_STR "Postgres-XC 1.1 on x86_64-unknown-linux-gnu, based on PostgreSQL 9.2.4, compiled by g++ (GCC) 7.3.0, 64-bit" + +/* Define to 1 to allow profiling output to be saved separately for each + process. */ +/* #undef PROFILE_PID_DIR */ + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus, + the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger + than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be + less than your OS' limit on file size. This is often 2 GB or 4GB in a + 32-bit operating system, unless you have large file support enabled. By + default, we make the limit 1 GB to avoid any possible integer-overflow + problems within the OS. A limit smaller than necessary only means we divide + a large relation into more chunks than necessary, so it seems best to err + in the direction of a small limit. A power-of-2 value is recommended to + save a few cycles in md.c, but is not absolutely required. Changing + RELSEG_SIZE requires an initdb. */ +#define RELSEG_SIZE 131072 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `off_t', as computed by sizeof. */ +#define SIZEOF_OFF_T 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if strerror_r() returns a int. */ +/* #undef STRERROR_R_INT */ + +/* Define to 1 if your declares `struct tm'. */ +/* #undef TM_IN_SYS_TIME */ + +/* Define to the appropriate snprintf format for unsigned 64-bit ints. */ +#define UINT64_FORMAT "%lu" + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +#define USE_ASSERT_CHECKING 1 + +/* Define to 1 to enable llt test. (--enable-llt) */ +/* #undef ENABLE_LLT */ + +/* Define to 1 to enable llvm test. (--enable-llvm) */ +#define ENABLE_LLVM_COMPILE 1 + +/* Define to 1 to enable ut test. (--enable-ut) */ +/* #undef ENABLE_UT */ + +/* Define to 1 to enable qunit test. (--enable-qunit) */ +/* #undef ENABLE_QUNIT */ + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +/* #undef USE_BONJOUR */ + +/* Define to 1 if you want float4 values to be passed by value. + (--enable-float4-byval) */ +#define USE_FLOAT4_BYVAL 1 + +/* Define to 1 if you want float8, int8, etc values to be passed by value. + (--enable-float8-byval) */ +#define USE_FLOAT8_BYVAL 1 + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#define USE_INLINE 1 + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +#define USE_INTEGER_DATETIMES 1 + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +/* #undef USE_LDAP */ + +/* Define to 1 to build with XML support. (--with-libxml) */ +/* #undef USE_LIBXML */ + +/* Define to 1 to use XSLT support when building contrib/xml2. + (--with-libxslt) */ +/* #undef USE_LIBXSLT */ + +/* Define to select named POSIX semaphores. */ +/* #undef USE_NAMED_POSIX_SEMAPHORES */ + +/* Define to 1 to build with PAM support. (--with-pam) */ +/* #undef USE_PAM */ + +/* Use replacement snprintf() functions. */ +/* #undef USE_REPL_SNPRINTF */ + +/* Define to 1 to use slicing-by-8 algorithm. */ +/* #undef USE_SLICING_BY_8_CRC32C */ + +/* Define to 1 use Intel SSE 4.2 CRC instructions. */ +/* #undef USE_SSE42_CRC32C */ + +/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */ +#define USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1 + +/* Define to build with (Open)SSL support. (--with-openssl) */ +#define USE_SSL 1 + +/* Define to select SysV-style semaphores. */ +#define USE_SYSV_SEMAPHORES 1 + +/* Define to select SysV-style shared memory. */ +#define USE_SYSV_SHARED_MEMORY 1 + +/* Define to select unnamed POSIX semaphores. */ +/* #undef USE_UNNAMED_POSIX_SEMAPHORES */ + +/* Define to select Win32-style semaphores. */ +/* #undef USE_WIN32_SEMAPHORES */ + +/* Define to select Win32-style shared memory. */ +/* #undef USE_WIN32_SHARED_MEMORY */ + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Size of a WAL file block. This need have no particular relation to BLCKSZ. + XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O, + XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O + buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb. + */ +#define XLOG_BLCKSZ 8192 + +/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 + and larger than XLOG_BLCKSZ (preferably, a great deal larger than + XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */ +#define XLOG_SEG_SIZE (16 * 1024 * 1024) + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +/* #undef _LARGEFILE_SOURCE */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to the type of a signed integer type wide enough to hold a pointer, + if such a type exists, and if the system does not define it. */ +/* #undef intptr_t */ + +/* Define to empty if the C compiler does not understand signed types. */ +/* #undef signed */ + +/* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ +/* #undef uintptr_t */ + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +/* #undef volatile */ + diff -uprN postgresql-hll-2.14_old/include/include/pg_config.h.in postgresql-hll-2.14/include/include/pg_config.h.in --- postgresql-hll-2.14_old/include/include/pg_config.h.in 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pg_config.h.in 2020-12-12 17:06:43.245348013 +0800 @@ -0,0 +1,909 @@ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to the type of arg 1 of 'accept' */ +#undef ACCEPT_TYPE_ARG1 + +/* Define to the type of arg 2 of 'accept' */ +#undef ACCEPT_TYPE_ARG2 + +/* Define to the type of arg 3 of 'accept' */ +#undef ACCEPT_TYPE_ARG3 + +/* Define to the return type of 'accept' */ +#undef ACCEPT_TYPE_RETURN + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* The normal alignment of `double', in bytes. */ +#undef ALIGNOF_DOUBLE + +/* The normal alignment of `int', in bytes. */ +#undef ALIGNOF_INT + +/* The normal alignment of `long', in bytes. */ +#undef ALIGNOF_LONG + +/* The normal alignment of `long long int', in bytes. */ +#undef ALIGNOF_LONG_LONG_INT + +/* The normal alignment of `short', in bytes. */ +#undef ALIGNOF_SHORT + +/* Size of a disk block --- this also limits the size of a tuple. You can set + it bigger if you need bigger tuples (although TOAST should reduce the need + to have large tuples, since fields can be spread across multiple tuples). + BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is + currently 2^15 (32768). This is determined by the 15-bit widths of the + lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h). + Changing BLCKSZ requires an initdb. */ +#undef BLCKSZ + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#undef DEF_PGPORT + +/* Define to the default TCP port number as a string constant. */ +#undef DEF_PGPORT_STR + +/* Define to build with GSSAPI support. (--with-gssapi) */ +#undef ENABLE_GSS + +/* Define to build with PYTHON support. (--with-python) */ +#undef ENABLE_PYTHON2 +#undef ENABLE_PYTHON3 + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +#undef ENABLE_NLS + +/* Define to 1 if you want to generate gauss product as multiple nodes. (--enable-multiple-nodes) */ +#undef ENABLE_MULTIPLE_NODES + +/* Define to 1 if you want MOT support. (--enable-mot). + Supported only in single_node mode, not supported with (--enable-multiple-nodes) */ +#undef ENABLE_MOT + +/* Define to 1 if you want to check memory. (--enable-memory-check) */ +#undef ENABLE_MEMORY_CHECK + +/* Define to 1 if you want to check thread. (--enable-thread-check) */ +#undef ENABLE_THREAD_CHECK + +/* Define to 1 if you want to use default gcc. (--enable-default-gcc) */ +#undef ENABLE_DEFAULT_GCC + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#undef ENABLE_THREAD_SAFETY + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#undef FLEXIBLE_ARRAY_MEMBER + +/* float4 values are passed by value if 'true', by reference if 'false' */ +#undef FLOAT4PASSBYVAL + +/* float8, int8, and related values are passed by value if 'true', by + reference if 'false' */ +#undef FLOAT8PASSBYVAL + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +#undef GETPWUID_R_5ARG + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +#undef GETTIMEOFDAY_1ARG + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `append_history' function. */ +#undef HAVE_APPEND_HISTORY + +/* Define to 1 if you have the `cbrt' function. */ +#undef HAVE_CBRT + +/* Define to 1 if you have the `class' function. */ +#undef HAVE_CLASS + +/* Define to 1 if you have the header file. */ +#undef HAVE_CRTDEFS_H + +/* Define to 1 if you have the `crypt' function. */ +#undef HAVE_CRYPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_CRYPT_H + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#undef HAVE_DECL_FDATASYNC + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#undef HAVE_DECL_F_FULLFSYNC + +/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you + don't. */ +#undef HAVE_DECL_POSIX_FADVISE + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#undef HAVE_DECL_SNPRINTF + +/* Define to 1 if you have the declaration of `strlcat', and to 0 if you + don't. */ +#undef HAVE_DECL_STRLCAT + +/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you + don't. */ +#undef HAVE_DECL_STRLCPY + +/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you + don't. */ +#undef HAVE_DECL_SYS_SIGLIST + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#undef HAVE_DECL_VSNPRINTF + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLD_H + +/* Define to 1 if you have the `dlopen' function. */ +#undef HAVE_DLOPEN + +/* Define to 1 if you have the header file. */ +#undef HAVE_EDITLINE_HISTORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_EDITLINE_READLINE_H + +/* Define to 1 if you have the `fdatasync' function. */ +#undef HAVE_FDATASYNC + +/* Define to 1 if you have the `fls' function. */ +#undef HAVE_FLS + +/* Define to 1 if you have the `fpclass' function. */ +#undef HAVE_FPCLASS + +/* Define to 1 if you have the `fp_class' function. */ +#undef HAVE_FP_CLASS + +/* Define to 1 if you have the `fp_class_d' function. */ +#undef HAVE_FP_CLASS_D + +/* Define to 1 if you have the header file. */ +#undef HAVE_FP_CLASS_H + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#undef HAVE_FSEEKO + +/* Define to 1 if your compiler understands __func__. */ +#undef HAVE_FUNCNAME__FUNC + +/* Define to 1 if your compiler understands __FUNCTION__. */ +#undef HAVE_FUNCNAME__FUNCTION + +/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */ +#undef HAVE_GCC_INT_ATOMICS + +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + +/* Define to 1 if you have the `gethostbyname_r' function. */ +#undef HAVE_GETHOSTBYNAME_R + +/* Define to 1 if you have the `getifaddrs' function. */ +#undef HAVE_GETIFADDRS + +/* Define to 1 if you have the `getopt' function. */ +#undef HAVE_GETOPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_GETOPT_H + +/* Define to 1 if you have the `getopt_long' function. */ +#undef HAVE_GETOPT_LONG + +/* Define to 1 if you have the `getpeereid' function. */ +#undef HAVE_GETPEEREID + +/* Define to 1 if you have the `getpeerucred' function. */ +#undef HAVE_GETPEERUCRED + +/* Define to 1 if you have the `getpwuid_r' function. */ +#undef HAVE_GETPWUID_R + +/* Define to 1 if you have the `getrlimit' function. */ +#undef HAVE_GETRLIMIT + +/* Define to 1 if you have the `getrusage' function. */ +#undef HAVE_GETRUSAGE + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the header file. */ +#undef HAVE_GSSAPI_GSSAPI_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GSSAPI_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_HISTORY_H + +/* Define to 1 if you have the `history_truncate_file' function. */ +#undef HAVE_HISTORY_TRUNCATE_FILE + +/* Define to 1 if you have the header file. */ +#undef HAVE_IEEEFP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_IFADDRS_H + +/* Define to 1 if you have the `inet_aton' function. */ +#undef HAVE_INET_ATON + +/* Define to 1 if the system has the type `int64'. */ +#undef HAVE_INT64 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* Define to 1 if the system has the type `intptr_t'. */ +#undef HAVE_INTPTR_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the global variable 'int opterr'. */ +#undef HAVE_INT_OPTERR + +/* Define to 1 if you have the global variable 'int optreset'. */ +#undef HAVE_INT_OPTRESET + +/* Define to 1 if you have the global variable 'int timezone'. */ +#undef HAVE_INT_TIMEZONE + +/* Define to 1 if you have support for IPv6. */ +#undef HAVE_IPV6 + +/* Define to 1 if you have isinf(). */ +#undef HAVE_ISINF + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +#undef HAVE_KRB5_ERROR_E_DATA + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +#undef HAVE_KRB5_ERROR_TEXT_DATA + +/* Define to 1 if you have krb5_free_unparsed_name. */ +#undef HAVE_KRB5_FREE_UNPARSED_NAME + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +#undef HAVE_KRB5_TICKET_CLIENT + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +#undef HAVE_KRB5_TICKET_ENC_PART2 + +/* Define to 1 if you have the header file. */ +#undef HAVE_LANGINFO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LDAP_H + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#undef HAVE_LIBCRYPTO + +/* Define to 1 if you have the `ldap' library (-lldap). */ +#undef HAVE_LIBLDAP + +/* Define to 1 if you have the `ldap_r' library (-lldap_r). */ +#undef HAVE_LIBLDAP_R + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the `pam' library (-lpam). */ +#undef HAVE_LIBPAM + +/* Define if you have a function readline library */ +#undef HAVE_LIBREADLINE + +/* Define to 1 if you have the `selinux' library (-lselinux). */ +#undef HAVE_LIBSELINUX + +/* Define to 1 if you have the `ssl' library (-lssl). */ +#undef HAVE_LIBSSL + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +#undef HAVE_LIBWLDAP32 + +/* Define to 1 if you have the `xml2' library (-lxml2). */ +#undef HAVE_LIBXML2 + +/* Define to 1 if you have the `xslt' library (-lxslt). */ +#undef HAVE_LIBXSLT + +/* Define to 1 if you have the `z' library (-lz). */ +#undef HAVE_LIBZ + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +#undef HAVE_LL_CONSTANTS + +/* Define to 1 if the system has the type `locale_t'. */ +#undef HAVE_LOCALE_T + +/* Define to 1 if `long int' works and is 64 bits. */ +#undef HAVE_LONG_INT_64 + +/* Define to 1 if the system has the type `long long int'. */ +#undef HAVE_LONG_LONG_INT + +/* Define to 1 if `long long int' works and is 64 bits. */ +#undef HAVE_LONG_LONG_INT_64 + +/* Define to 1 if you have the `mbstowcs_l' function. */ +#undef HAVE_MBSTOWCS_L + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +#undef HAVE_MINIDUMP_TYPE + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_TCP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NET_IF_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_OSSP_UUID_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_PAM_PAM_APPL_H + +/* Define to 1 if you have the `poll' function. */ +#undef HAVE_POLL + +/* Define to 1 if you have the header file. */ +#undef HAVE_POLL_H + +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + +/* Define to 1 if you have the POSIX signal interface. */ +#undef HAVE_POSIX_SIGNALS + +/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */ +#undef HAVE_PPC_LWARX_MUTEX_HINT + +/* Define to 1 if you have the `pstat' function. */ +#undef HAVE_PSTAT + +/* Define to 1 if the PS_STRINGS thing exists. */ +#undef HAVE_PS_STRINGS + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_PWD_H + +/* Define to 1 if you have the `random' function. */ +#undef HAVE_RANDOM + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_HISTORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_READLINE_H + +/* Define to 1 if you have the `readlink' function. */ +#undef HAVE_READLINK + +/* Define to 1 if you have the `rint' function. */ +#undef HAVE_RINT + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +#undef HAVE_RL_COMPLETION_APPEND_CHARACTER + +/* Define to 1 if you have the `rl_completion_matches' function. */ +#undef HAVE_RL_COMPLETION_MATCHES + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +#undef HAVE_RL_FILENAME_COMPLETION_FUNCTION + +/* Define to 1 if you have the header file. */ +#undef HAVE_SECURITY_PAM_APPL_H + +/* Define to 1 if you have the `setproctitle' function. */ +#undef HAVE_SETPROCTITLE + +/* Define to 1 if you have the `setsid' function. */ +#undef HAVE_SETSID + +/* Define to 1 if you have the `sigprocmask' function. */ +#undef HAVE_SIGPROCMASK + +/* Define to 1 if you have sigsetjmp(). */ +#undef HAVE_SIGSETJMP + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#undef HAVE_SIG_ATOMIC_T + +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + +/* Define to 1 if you have spinlocks. */ +#undef HAVE_SPINLOCKS + +/* Define to 1 if you have the `srandom' function. */ +#undef HAVE_SRANDOM + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the `strerror_r' function. */ +#undef HAVE_STRERROR_R + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#undef HAVE_STRINGIZE + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strlcat' function. */ +#undef HAVE_STRLCAT + +/* Define to 1 if you have the `strlcpy' function. */ +#undef HAVE_STRLCPY + +/* Define to 1 if you have the `strtoll' function. */ +#undef HAVE_STRTOLL + +/* Define to 1 if you have the `strtoq' function. */ +#undef HAVE_STRTOQ + +/* Define to 1 if you have the `strtoull' function. */ +#undef HAVE_STRTOULL + +/* Define to 1 if you have the `strtouq' function. */ +#undef HAVE_STRTOUQ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#undef HAVE_STRUCT_ADDRINFO + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +#undef HAVE_STRUCT_CMSGCRED + +/* Define to 1 if the system has the type `struct option'. */ +#undef HAVE_STRUCT_OPTION + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +#undef HAVE_STRUCT_SOCKADDR_SA_LEN + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +#undef HAVE_STRUCT_TM_TM_ZONE + +/* Define to 1 if you have the `symlink' function. */ +#undef HAVE_SYMLINK + +/* Define to 1 if you have the `sync_file_range' function. */ +#undef HAVE_SYNC_FILE_RANGE + +/* Define to 1 if you have the syslog interface. */ +#undef HAVE_SYSLOG + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IPC_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_POLL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PSTAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_RESOURCE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SEM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SHM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKIO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TAS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UCRED_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +#undef HAVE_TM_ZONE + +/* Define to 1 if you have the `towlower' function. */ +#undef HAVE_TOWLOWER + +/* Define to 1 if you have the external array `tzname'. */ +#undef HAVE_TZNAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_UCRED_H + +/* Define to 1 if the system has the type `uint64'. */ +#undef HAVE_UINT64 + +/* Define to 1 if the system has the type `uint8'. */ +#undef HAVE_UINT8 + +/* Define to 1 if the system has the type `uintptr_t'. */ +#undef HAVE_UINTPTR_T + +/* Define to 1 if the system has the type `union semun'. */ +#undef HAVE_UNION_SEMUN + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have unix sockets. */ +#undef HAVE_UNIX_SOCKETS + +/* Define to 1 if you have the `unsetenv' function. */ +#undef HAVE_UNSETENV + +/* Define to 1 if you have the `utime' function. */ +#undef HAVE_UTIME + +/* Define to 1 if you have the `utimes' function. */ +#undef HAVE_UTIMES + +/* Define to 1 if you have the header file. */ +#undef HAVE_UTIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UUID_H + +/* Define to 1 if you have the `vsnprintf' function. */ +#undef HAVE_VSNPRINTF + +/* Define to 1 if you have the `waitpid' function. */ +#undef HAVE_WAITPID + +/* Define to 1 if you have the header file. */ +#undef HAVE_WCHAR_H + +/* Define to 1 if you have the `wcstombs' function. */ +#undef HAVE_WCSTOMBS + +/* Define to 1 if you have the `wcstombs_l' function. */ +#undef HAVE_WCSTOMBS_L + +/* Define to 1 if you have the header file. */ +#undef HAVE_WCTYPE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINLDAP_H + +/* Define to the appropriate snprintf format for 64-bit ints. */ +#undef INT64_FORMAT + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +#undef KRB5 + +/* Define to 1 if you have __cpuid. */ +#undef HAVE__CPUID + +/* Define to 1 if you have __get_cpuid. */ +#undef HAVE__GET_CPUID + +/* Define to 1 if `locale_t' requires . */ +#undef LOCALE_T_IN_XLOCALE + +/* Define as the maximum alignment requirement of any C data type. */ +#undef MAXIMUM_ALIGNOF + +/* Define bytes to use libc memset(). */ +#undef MEMSET_LOOP_LIMIT + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#undef PG_KRB_SRVNAM + +/* PostgreSQL major version as a string */ +#undef PG_MAJORVERSION + +/* PostgreSQL version as a string */ +#undef PG_VERSION + +/* Gaussdb version as a string*/ +#undef DEF_GS_VERSION + +/* PostgreSQL version as a number */ +#undef PG_VERSION_NUM + +/* Postgres-XC major version as a string */ +#undef PGXC_MAJORVERSION + +/* Postgres-XC version as a string */ +#undef PGXC_VERSION + +/* Postgres-XC version as a number */ +#undef PGXC_VERSION_NUM + +/* A string containing the version number, platform, and C compiler */ +#undef PG_VERSION_STR + +/* A string containing the version number of Postgres-XC, platform, and C compiler */ +#undef PGXC_VERSION_STR + +/* Define to 1 to allow profiling output to be saved separately for each + process. */ +#undef PROFILE_PID_DIR + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus, + the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger + than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be + less than your OS' limit on file size. This is often 2 GB or 4GB in a + 32-bit operating system, unless you have large file support enabled. By + default, we make the limit 1 GB to avoid any possible integer-overflow + problems within the OS. A limit smaller than necessary only means we divide + a large relation into more chunks than necessary, so it seems best to err + in the direction of a small limit. A power-of-2 value is recommended to + save a few cycles in md.c, but is not absolutely required. Changing + RELSEG_SIZE requires an initdb. */ +#undef RELSEG_SIZE + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `off_t', as computed by sizeof. */ +#undef SIZEOF_OFF_T + +/* The size of `size_t', as computed by sizeof. */ +#undef SIZEOF_SIZE_T + +/* The size of `void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if strerror_r() returns a int. */ +#undef STRERROR_R_INT + +/* Define to 1 if your declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Define to the appropriate snprintf format for unsigned 64-bit ints. */ +#undef UINT64_FORMAT + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +#undef USE_ASSERT_CHECKING + +/* Define to 1 to enable llt test. (--enable-llt) */ +#undef ENABLE_LLT + +/* Define to 1 to enable llvm test. (--enable-llvm) */ +#undef ENABLE_LLVM_COMPILE + +/* Define to 1 to enable ut test. (--enable-ut) */ +#undef ENABLE_UT + +/* Define to 1 to enable qunit test. (--enable-qunit) */ +#undef ENABLE_QUNIT + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +#undef USE_BONJOUR + +/* Define to 1 if you want float4 values to be passed by value. + (--enable-float4-byval) */ +#undef USE_FLOAT4_BYVAL + +/* Define to 1 if you want float8, int8, etc values to be passed by value. + (--enable-float8-byval) */ +#undef USE_FLOAT8_BYVAL + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#undef USE_INLINE + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +#undef USE_INTEGER_DATETIMES + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +#undef USE_LDAP + +/* Define to 1 to build with XML support. (--with-libxml) */ +#undef USE_LIBXML + +/* Define to 1 to use XSLT support when building contrib/xml2. + (--with-libxslt) */ +#undef USE_LIBXSLT + +/* Define to select named POSIX semaphores. */ +#undef USE_NAMED_POSIX_SEMAPHORES + +/* Define to 1 to build with PAM support. (--with-pam) */ +#undef USE_PAM + +/* Use replacement snprintf() functions. */ +#undef USE_REPL_SNPRINTF + +/* Define to 1 to use slicing-by-8 algorithm. */ +#undef USE_SLICING_BY_8_CRC32C + +/* Define to 1 use Intel SSE 4.2 CRC instructions. */ +#undef USE_SSE42_CRC32C + +/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */ +#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK + +/* Define to build with (Open)SSL support. (--with-openssl) */ +#undef USE_SSL + +/* Define to select SysV-style semaphores. */ +#undef USE_SYSV_SEMAPHORES + +/* Define to select SysV-style shared memory. */ +#undef USE_SYSV_SHARED_MEMORY + +/* Define to select unnamed POSIX semaphores. */ +#undef USE_UNNAMED_POSIX_SEMAPHORES + +/* Define to select Win32-style semaphores. */ +#undef USE_WIN32_SEMAPHORES + +/* Define to select Win32-style shared memory. */ +#undef USE_WIN32_SHARED_MEMORY + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Size of a WAL file block. This need have no particular relation to BLCKSZ. + XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O, + XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O + buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb. + */ +#undef XLOG_BLCKSZ + +/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 + and larger than XLOG_BLCKSZ (preferably, a great deal larger than + XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */ +#undef XLOG_SEG_SIZE + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#undef _LARGEFILE_SOURCE + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to the type of a signed integer type wide enough to hold a pointer, + if such a type exists, and if the system does not define it. */ +#undef intptr_t + +/* Define to empty if the C compiler does not understand signed types. */ +#undef signed + +/* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ +#undef uintptr_t + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +#undef volatile + diff -uprN postgresql-hll-2.14_old/include/include/pg_config.h.win32 postgresql-hll-2.14/include/include/pg_config.h.win32 --- postgresql-hll-2.14_old/include/include/pg_config.h.win32 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pg_config.h.win32 2020-12-12 17:06:43.246348025 +0800 @@ -0,0 +1,682 @@ +/* src/include/pg_config.h. Generated by configure. */ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* This file is generated from MingW ./configure, and with the following + * changes to be valid for Visual C++ (and compatible): + * + * HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_GETOPT, HAVE_GETOPT_H, HAVE_INTTYPES_H, + * HAVE_GETOPT_LONG, HAVE_LOCALE_T, HAVE_RINT, HAVE_STRINGS_H, HAVE_STRTOLL, + * HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY, + * USE_INLINE, inline + */ + +/* Define to the type of arg 1 of 'accept' */ +#define ACCEPT_TYPE_ARG1 unsigned int + +/* Define to the type of arg 2 of 'accept' */ +#define ACCEPT_TYPE_ARG2 struct sockaddr * + +/* Define to the type of arg 3 of 'accept' */ +#define ACCEPT_TYPE_ARG3 int + +/* Define to the return type of 'accept' */ +#define ACCEPT_TYPE_RETURN unsigned int PASCAL + +/* The alignment requirement of a `double'. */ +#define ALIGNOF_DOUBLE 8 + +/* The alignment requirement of a `int'. */ +#define ALIGNOF_INT 4 + +/* The alignment requirement of a `long'. */ +#define ALIGNOF_LONG 4 + +/* The alignment requirement of a `long long int'. */ +#define ALIGNOF_LONG_LONG_INT 8 + +/* The alignment requirement of a `short'. */ +#define ALIGNOF_SHORT 2 + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#define DEF_PGPORT 5432 + +/* Define to the default TCP port number as a string constant. */ +#define DEF_PGPORT_STR "5432" + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#define FLEXIBLE_ARRAY_MEMBER + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +/* #undef ENABLE_NLS */ + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#define ENABLE_THREAD_SAFETY 1 + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +/* #undef GETPWUID_R_5ARG */ + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +/* #undef GETTIMEOFDAY_1ARG */ + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `cbrt' function. */ +//#define HAVE_CBRT 1 + +/* Define to 1 if you have the `class' function. */ +/* #undef HAVE_CLASS */ + +/* Define to 1 if you have the `crypt' function. */ +/* #undef HAVE_CRYPT */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRYPT_H */ + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#define HAVE_DECL_FDATASYNC 0 + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#define HAVE_DECL_F_FULLFSYNC 0 + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#define HAVE_DECL_SNPRINTF 1 + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#define HAVE_DECL_VSNPRINTF 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLD_H */ + +/* Define to 1 if you have the `dlopen' function. */ +/* #undef HAVE_DLOPEN */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_READLINE_H */ + +/* Define to 1 if you have the `fcvt' function. */ +#define HAVE_FCVT 1 + +/* Define to 1 if you have the `fdatasync' function. */ +/* #undef HAVE_FDATASYNC */ + +/* Define to 1 if you have finite(). */ +#define HAVE_FINITE 1 + +/* Define to 1 if you have the `fpclass' function. */ +/* #undef HAVE_FPCLASS */ + +/* Define to 1 if you have the `fp_class' function. */ +/* #undef HAVE_FP_CLASS */ + +/* Define to 1 if you have the `fp_class_d' function. */ +/* #undef HAVE_FP_CLASS_D */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FP_CLASS_H */ + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#define HAVE_FSEEKO 1 + +/* Define to 1 if your compiler understands __func__. */ +//#define HAVE_FUNCNAME__FUNC 1 + +/* Define to 1 if your compiler understands __FUNCTION__. */ +#define HAVE_FUNCNAME__FUNCTION 1 + +/* Define to 1 if you have getaddrinfo(). */ +/* #undef HAVE_GETADDRINFO */ + +/* Define to 1 if you have the `gethostbyname_r' function. */ +/* #undef HAVE_GETHOSTBYNAME_R */ + +/* Define to 1 if you have the `getopt' function. */ +//#define HAVE_GETOPT 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +//#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpeereid' function. */ +/* #undef HAVE_GETPEEREID */ + +/* Define to 1 if you have the `getpwuid_r' function. */ +/* #undef HAVE_GETPWUID_R */ + +/* Define to 1 if you have the `getrusage' function. */ +/* #undef HAVE_GETRUSAGE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEEFP_H */ + +/* Define to 1 if you have the `inet_aton' function. */ +/* #undef HAVE_INET_ATON */ + +/* Define to 1 if the system has the type `int64'. */ +/* #undef HAVE_INT64 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* Define to 1 if you have the header file. */ +//#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the global variable 'int timezone'. */ +#define HAVE_INT_TIMEZONE + +/* Define to 1 if you have support for IPv6. */ +#define HAVE_IPV6 1 + +/* Define to 1 if you have isinf(). */ +#define HAVE_ISINF 1 + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_E_DATA */ + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_TEXT_DATA */ + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_CLIENT */ + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_ENC_PART2 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LANGINFO_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LDAP_H */ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +/* #undef HAVE_LIBCRYPTO */ + +/* Define to 1 if you have the `ldap' library (-lldap). */ +/* #undef HAVE_LIBLDAP */ + +/* Define to 1 if you have the `pam' library (-lpam). */ +/* #undef HAVE_LIBPAM */ + +/* Define if you have a function readline library */ +/* #undef HAVE_LIBREADLINE */ + +/* Define to 1 if you have the `ssl' library (-lssl). */ +/* #undef HAVE_LIBSSL */ + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +/* #undef HAVE_LIBWLDAP32 */ + +/* Define to 1 if you have the `z' library (-lz). */ +/* #undef HAVE_LIBZ */ + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +#if (_MSC_VER > 1200) +#define HAVE_LL_CONSTANTS 1 +#endif + +/* Define to 1 if the system has the type `locale_t'. */ +#define HAVE_LOCALE_T 1 + +/* Define to 1 if `long int' works and is 64 bits. */ +/* #undef HAVE_LONG_INT_64 */ + +/* Define to 1 if `long long int' works and is 64 bits. */ +#if (_MSC_VER > 1200) +#define HAVE_LONG_LONG_INT_64 +#endif + +/* Define to 1 if you have the `mbstowcs_l' function. */ +#define HAVE_MBSTOWCS_L 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +#define HAVE_MINIDUMP_TYPE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NETINET_TCP_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PAM_PAM_APPL_H */ + +/* Define to 1 if you have the `poll' function. */ +/* #undef HAVE_POLL */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_POLL_H */ + +/* Define to 1 if you have the POSIX signal interface. */ +/* #undef HAVE_POSIX_SIGNALS */ + +/* Define to 1 if you have the `pstat' function. */ +/* #undef HAVE_PSTAT */ + +/* Define to 1 if the PS_STRINGS thing exists. */ +/* #undef HAVE_PS_STRINGS */ + +/* Define if you have POSIX threads libraries and header files. */ +/* #undef HAVE_PTHREAD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* Define to 1 if you have the `random' function. */ +/* #undef HAVE_RANDOM */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_READLINE_H */ + +/* Define to 1 if you have the `readlink' function. */ +/* #undef HAVE_READLINK */ + +/* Define to 1 if you have the `rint' function. */ +/*#define HAVE_RINT 1*/ + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +/* #undef HAVE_RL_COMPLETION_APPEND_CHARACTER */ + +/* Define to 1 if you have the `rl_completion_matches' function. */ +/* #undef HAVE_RL_COMPLETION_MATCHES */ + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +/* #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SECURITY_PAM_APPL_H */ + +/* Define to 1 if you have the `setproctitle' function. */ +/* #undef HAVE_SETPROCTITLE */ + +/* Define to 1 if you have the `setsid' function. */ +/* #undef HAVE_SETSID */ + +/* Define to 1 if you have the `sigprocmask' function. */ +/* #undef HAVE_SIGPROCMASK */ + +/* Define to 1 if you have sigsetjmp(). */ +/* #undef HAVE_SIGSETJMP */ + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if you have the `snprintf' function. */ +/* #undef HAVE_SNPRINTF */ + +/* Define to 1 if you have spinlocks. */ +#define HAVE_SPINLOCKS 1 + +/* Define to 1 if you have the `srandom' function. */ +/* #undef HAVE_SRANDOM */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STDINT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#ifndef HAVE_STRERROR +#define HAVE_STRERROR 1 +#endif + +/* Define to 1 if you have the `strerror_r' function. */ +/* #undef HAVE_STRERROR_R */ + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#define HAVE_STRINGIZE 1 + +/* Define to 1 if you have the header file. */ +/*#define HAVE_STRINGS_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strtoll' function. */ +//#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `strtoq' function. */ +/* #undef HAVE_STRTOQ */ + +/* Define to 1 if you have the `strtoull' function. */ +//#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the `strtouq' function. */ +/* #undef HAVE_STRTOUQ */ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_ADDRINFO 1 +#endif + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +/* #undef HAVE_STRUCT_CMSGCRED */ + +/* Define to 1 if the system has the type `struct option'. */ +//#define HAVE_STRUCT_OPTION 1 + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 +#endif + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 +#endif + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +/* #undef HAVE_STRUCT_SOCKADDR_UN */ + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +/* #undef HAVE_STRUCT_TM_TM_ZONE */ + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* Define to 1 if you have the `sysconf' function. */ +/* #undef HAVE_SYSCONF */ + +/* Define to 1 if you have the syslog interface. */ +/* #undef HAVE_SYSLOG */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_IPC_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_POLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PSTAT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SELECT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SEM_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SHM_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UCRED_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UN_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_TERMIOS_H */ + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +/* #undef HAVE_TM_ZONE */ + +/* Define to 1 if you have the `towlower' function. */ +#define HAVE_TOWLOWER 1 + +/* Define to 1 if you have the external array `tzname'. */ +/* #undef HAVE_TZNAME */ + +/* Define to 1 if the system has the type `uint64'. */ +/* #undef HAVE_UINT64 */ + +/* Define to 1 if the system has the type `uint8'. */ +/* #undef HAVE_UINT8 */ + +/* Define to 1 if the system has the type `union semun'. */ +/* #undef HAVE_UNION_SEMUN */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have unix sockets. */ +/* #undef HAVE_UNIX_SOCKETS */ + +/* Define to 1 if you have the `unsetenv' function. */ +/* #undef HAVE_UNSETENV */ + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +/* #undef HAVE_UTIMES */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `waitpid' function. */ +/* #undef HAVE_WAITPID */ + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the `wcstombs' function. */ +#define HAVE_WCSTOMBS 1 + +/* Define to 1 if you have the `wcstombs_l' function. */ +#define HAVE_WCSTOMBS_L 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINLDAP_H */ + +/* Define to the appropriate snprintf format for 64-bit ints, if any. */ +#define INT64_FORMAT "%lld" + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +/* #undef KRB5 */ + +/* Define to 1 if `locale_t' requires . */ +/* #undef LOCALE_T_IN_XLOCALE */ + +/* Define to the location of locale files. */ +/* #undef LOCALEDIR */ + +/* Define as the maximum alignment requirement of any C data type. */ +#define MAXIMUM_ALIGNOF 8 + +/* Define bytes to use libc memset(). */ +#define MEMSET_LOOP_LIMIT 1024 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "postgres-xc-bugs@lists.sourceforge.net" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Postgres-XC" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Postgres-XC 1.1beta" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "9.2.4" + +/* PostgreSQL version as a string */ +#define PG_VERSION "9.2.4" + +/* PostgreSQL version as a number */ +#define PG_VERSION_NUM 90204 + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "postgres-xc" + +/* Postgres-XC version as a string */ +#define PGXC_VERSION "1.1devel" + +/* Postgres-XC version as a number */ +#define PGXC_VERSION_NUM 10100 + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#define PG_KRB_SRVNAM "postgres" + +/* A string containing the version number, platform, and C compiler */ +#define PG_VERSION_STR "Uninitialized version string (win32)" + +/* A string containing the version number, platform, and C compiler */ +#define PGXC_VERSION_STR "Uninitialized version string (win32)" + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#ifndef _WIN64 +#define SIZEOF_SIZE_T 4 +#else +#define SIZEOF_SIZE_T 8 +#endif + +/* The size of `void *', as computed by sizeof. */ +#ifndef _WIN64 +#define SIZEOF_VOID_P 4 +#else +#define SIZEOF_VOID_P 8 +#endif + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if strerror_r() returns a int. */ +/* #undef STRERROR_R_INT */ + +/* Define to 1 if your declares `struct tm'. */ +/* #undef TM_IN_SYS_TIME */ + +/* Define to the appropriate snprintf format for unsigned 64-bit ints, if any. + */ +#define UINT64_FORMAT "%llu" + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +/* #undef USE_ASSERT_CHECKING */ + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +/* #undef USE_BONJOUR */ + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#define USE_INLINE 1 + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +/* #undef USE_INTEGER_DATETIMES */ + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +/* #undef USE_LDAP */ + +/* Define to select named POSIX semaphores. */ +/* #undef USE_NAMED_POSIX_SEMAPHORES */ + +/* Define to 1 to build with PAM support. (--with-pam) */ +/* #undef USE_PAM */ + +/* Use replacement snprintf() functions. */ +#define USE_REPL_SNPRINTF 1 + +/* Define to build with (Open)SSL support. (--with-openssl) */ +/* #undef USE_SSL */ + +/* Define to select SysV-style semaphores. */ +/* #undef USE_SYSV_SEMAPHORES */ + +/* Define to select SysV-style shared memory. */ +#define USE_SYSV_SHARED_MEMORY 1 + +/* Define to select unnamed POSIX semaphores. */ +/* #undef USE_UNNAMED_POSIX_SEMAPHORES */ + +/* Define to select Win32-style semaphores. */ +#define USE_WIN32_SEMAPHORES + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +/* #undef _LARGEFILE_SOURCE */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#define inline __inline +#endif + +/* Define to empty if the C compiler does not understand signed types. */ +/* #undef signed */ + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +/* #undef volatile */ diff -uprN postgresql-hll-2.14_old/include/include/pg_config_manual.h postgresql-hll-2.14/include/include/pg_config_manual.h --- postgresql-hll-2.14_old/include/include/pg_config_manual.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pg_config_manual.h 2020-12-12 17:06:43.246348025 +0800 @@ -0,0 +1,313 @@ +/* ------------------------------------------------------------------------ + * PostgreSQL manual configuration settings + * + * This file contains various configuration symbols and limits. In + * all cases, changing them is only useful in very rare situations or + * for developers. If you edit any of these, be sure to do a *full* + * rebuild (and an initdb if noted). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/pg_config_manual.h + * ------------------------------------------------------------------------ + */ + +/* + * Maximum length for identifiers (e.g. table names, column names, + * function names). Names actually are limited to one less byte than this, + * because the length must include a trailing zero byte. + * + * Changing this requires an initdb. + */ +#define NAMEDATALEN 64 +#ifndef ENABLE_MULTIPLE_NODES +#define BUCKETDATALEN 16384 +#define BUCKETSTRLEN 6 * BUCKETDATALEN +#endif +#define NODEIDLEN 4 +#define MAX_NODE_DIG 5 // datanode number <= 4096 +#define MAX_DATANODE_NUM 4096 // this value should be same as MaxDataNodes +/* + * Maximum number of arguments to a function. + * + * The minimum value is 8 (GIN indexes use 8-argument support functions). + * The maximum possible value is around 600 (limited by index tuple size in + * pg_proc's index; BLCKSZ larger than 8K would allow more). Values larger + * than needed will waste memory and processing time, but do not directly + * cost disk space. + * + * Changing this does not require an initdb, but it does require a full + * backend recompile (including any user-defined C functions). + */ +#define FUNC_MAX_ARGS 666 + +/* + * Maximum number of columns in an index. There is little point in making + * this anything but a multiple of 32, because the main cost is associated + * with index tuple header size (see access/itup.h). + * + * Changing this requires an initdb. + */ +#define INDEX_MAX_KEYS 32 + +/* + * Set the upper and lower bounds of sequence values. + */ +#define SEQ_MAXVALUE INT64CONST(0x7FFFFFFFFFFFFFFF) +#define SEQ_MINVALUE (-SEQ_MAXVALUE) + +/* + * Number of spare LWLocks to allocate for user-defined add-on code. + */ +#define NUM_USER_DEFINED_LWLOCKS 4 + +/* + * Define this if you want to allow the lo_import and lo_export SQL + * functions to be executed by ordinary users. By default these + * functions are only available to the Postgres superuser. CAUTION: + * These functions are SECURITY HOLES since they can read and write + * any file that the PostgreSQL server has permission to access. If + * you turn this on, don't say we didn't warn you. + * define ALLOW_DANGEROUS_LO_FUNCTIONS + */ + +/* + * MAXPGPATH: standard size of a pathname buffer in PostgreSQL (hence, + * maximum usable pathname length is one less). + * + * We'd use a standard system header symbol for this, if there weren't + * so many to choose from: MAXPATHLEN, MAX_PATH, PATH_MAX are all + * defined by different "standards", and often have different values + * on the same platform! So we just punt and use a reasonably + * generous setting here. + */ +#define MAXPGPATH 1024 + +/* + * PG_SOMAXCONN: maximum accept-queue length limit passed to + * listen(2). You'd think we should use SOMAXCONN from + * , but on many systems that symbol is much smaller + * than the kernel's actual limit. In any case, this symbol need be + * twiddled only if you have a kernel that refuses large limit values, + * rather than silently reducing the value to what it can handle + * (which is what most if not all Unixen do). + */ +#define PG_SOMAXCONN 65535 + +#define PG_SOMINCONN 1024 + + +/* + * You can try changing this if you have a machine with bytes of + * another size, but no guarantee... + */ +#define BITS_PER_BYTE 8 + +/* + * Preferred alignment for disk I/O buffers. On some CPUs, copies between + * user space and kernel space are significantly faster if the user buffer + * is aligned on a larger-than-MAXALIGN boundary. Ideally this should be + * a platform-dependent value, but for now we just hard-wire it. + * + * Direct I/O requires 512 byte alignment of buffers (32 byte is typical otherwise) + */ +#define ALIGNOF_BUFFER 512 + +/* + * Disable UNIX sockets for certain operating systems. + */ +#if defined(WIN32) +#undef HAVE_UNIX_SOCKETS +#endif + +/* + * Define this if your operating system supports link() + */ +#if !defined(WIN32) && !defined(__CYGWIN__) +#define HAVE_WORKING_LINK 1 +#endif + +/* + * USE_POSIX_FADVISE controls whether Postgres will attempt to use the + * posix_fadvise() kernel call. Usually the automatic configure tests are + * sufficient, but some older Linux distributions had broken versions of + * posix_fadvise(). If necessary you can remove the #define here. + */ +#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE) +#define USE_POSIX_FADVISE +#endif + +/* + * USE_PREFETCH code should be compiled only if we have a way to implement + * prefetching. (This is decoupled from USE_POSIX_FADVISE because there + * might in future be support for alternative low-level prefetch APIs.) + */ +#ifdef USE_POSIX_FADVISE +#define USE_PREFETCH +#endif + +/* + * Default and maximum values for backend_flush_after, bgwriter_flush_after + * and checkpoint_flush_after; measured in blocks. Currently, these are + * enabled by default if sync_file_range() exists, ie, only on Linux. Perhaps + * we could also enable by default if we have mmap and msync(MS_ASYNC)? + */ +#ifdef HAVE_SYNC_FILE_RANGE +#define DEFAULT_BACKEND_FLUSH_AFTER 0 /* never enabled by default */ +#define DEFAULT_BGWRITER_FLUSH_AFTER 64 +#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32 +#else +#define DEFAULT_BACKEND_FLUSH_AFTER 0 +#define DEFAULT_BGWRITER_FLUSH_AFTER 0 +#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0 +#endif +/* upper limit for all three variables */ +#define WRITEBACK_MAX_PENDING_FLUSHES 256 + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * The random() function is expected to yield values between 0 and + * MAX_RANDOM_VALUE. Currently, all known implementations yield + * 0..2^31-1, so we just hardwire this constant. We could do a + * configure test if it proves to be necessary. CAUTION: Think not to + * replace this with RAND_MAX. RAND_MAX defines the maximum value of + * the older rand() function, which is often different from --- and + * considerably inferior to --- random(). + */ +#define MAX_RANDOM_VALUE (0x7FFFFFFF) + +/* + * Set the format style used by gcc to check printf type functions. We really + * want the "gnu_printf" style set, which includes what glibc uses, such + * as %m for error strings and %lld for 64 bit long longs. But not all gcc + * compilers are known to support it, so we just use "printf" which all + * gcc versions alive are known to support, except on Windows where + * using "gnu_printf" style makes a dramatic difference. Maybe someday + * we'll have a configure test for this, if we ever discover use of more + * variants to be necessary. + */ +#ifdef WIN32 +#define PG_PRINTF_ATTRIBUTE gnu_printf +#else +#define PG_PRINTF_ATTRIBUTE printf +#endif + +/* + * On PPC machines, decide whether to use the mutex hint bit in LWARX + * instructions. Setting the hint bit will slightly improve spinlock + * performance on POWER6 and later machines, but does nothing before that, + * and will result in illegal-instruction failures on some pre-POWER4 + * machines. By default we use the hint bit when building for 64-bit PPC, + * which should be safe in nearly all cases. You might want to override + * this if you are building 32-bit code for a known-recent PPC machine. + */ +#ifdef HAVE_PPC_LWARX_MUTEX_HINT /* must have assembler support in any case */ +#if defined(__ppc64__) || defined(__powerpc64__) +#define USE_PPC_LWARX_MUTEX_HINT +#endif +#endif + +/* + * On PPC machines, decide whether to use LWSYNC instructions in place of + * ISYNC and SYNC. This provides slightly better performance, but will + * result in illegal-instruction failures on some pre-POWER4 machines. + * By default we use LWSYNC when building for 64-bit PPC, which should be + * safe in nearly all cases. + */ +#if defined(__ppc64__) || defined(__powerpc64__) +#define USE_PPC_LWSYNC +#endif + +/* + * Assumed cache line size. This doesn't affect correctness, but can be used + * for low-level optimizations. Currently, this is used to pad some data + * structures in xlog.c, to ensure that highly-contended fields are on + * different cache lines. Too small a value can hurt performance due to false + * sharing, while the only downside of too large a value is a few bytes of + * wasted memory. The default is 128, which should be large enough for all + * supported platforms. + */ +#define PG_CACHE_LINE_SIZE 128 + +/* + * ------------------------------------------------------------------------ + * The following symbols are for enabling debugging code, not for + * controlling user-visible features or resource limits. + * ------------------------------------------------------------------------ + */ + +/* + * Define this to cause pfree()'d memory to be cleared immediately, to + * facilitate catching bugs that refer to already-freed values. + * Right now, this gets defined automatically if --enable-cassert. + */ +#ifdef USE_ASSERT_CHECKING +#define CLOBBER_FREED_MEMORY +#endif + +/* + * Define this to check memory allocation errors (scribbling on more + * bytes than were allocated). Right now, this gets defined + * automatically if --enable-cassert. + */ +#ifdef USE_ASSERT_CHECKING +#define MEMORY_CONTEXT_CHECKING +#endif + +/* + * Define this to cause palloc()'d memory to be filled with random data, to + * facilitate catching code that depends on the contents of uninitialized + * memory. Caution: this is horrendously expensive. + * define RANDOMIZE_ALLOCATED_MEMORY + */ + +/* + * Define this to force all parse and plan trees to be passed through + * copyObject(), to facilitate catching errors and omissions in + * copyObject(). + * define COPY_PARSE_PLAN_TREES + */ + +/* + * Enable debugging print statements for lock-related operations. + * define LOCK_DEBUG + */ + +/* + * Enable debugging print statements for WAL-related operations; see + * also the wal_debug GUC var. + * define WAL_DEBUG + */ + +/* + * Enable debugging print for data replication operations. + * define DATA_DEBUG + */ + +/* + * Enable tracing of resource consumption during sort operations; + * see also the trace_sort GUC var. For 8.1 this is enabled by default. + */ +#define TRACE_SORT 1 + +/* + * Enable tracing of syncscan operations (see also the trace_syncscan GUC var). + * define TRACE_SYNCSCAN + */ + +/* + * Other debug #defines (documentation, anyone?) + * define HEAPDEBUGALL + * define ACLDEBUG + * define RTDEBUG + */ diff -uprN postgresql-hll-2.14_old/include/include/pgstat.h postgresql-hll-2.14/include/include/pgstat.h --- postgresql-hll-2.14_old/include/include/pgstat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgstat.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,2536 @@ +/* ---------- + * pgstat.h + * + * Definitions for the PostgreSQL statistics collector daemon. + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/pgstat.h + * ---------- + */ +#ifndef PGSTAT_H +#define PGSTAT_H + +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "gtm/gtm_c.h" +#include "libpq/pqcomm.h" +#include "mb/pg_wchar.h" +#include "portability/instr_time.h" +#include "storage/barrier.h" +#include "utils/hsearch.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/memutils.h" +#include "pgtime.h" +#include "pgxc/execRemote.h" +#include "storage/lwlock.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "workload/workload.h" +#include "access/multi_redo_settings.h" +#include "instruments/instr_event.h" +#include "instruments/unique_sql_basic.h" +#include "knl/knl_instance.h" + +/* Values for track_functions GUC variable --- order is significant! */ +typedef enum TrackFunctionsLevel { TRACK_FUNC_OFF, TRACK_FUNC_PL, TRACK_FUNC_ALL } TrackFunctionsLevel; + +/* ---------- + * The types of backend -> collector messages + * ---------- + */ +typedef enum StatMsgType { + PGSTAT_MTYPE_DUMMY, + PGSTAT_MTYPE_INQUIRY, + PGSTAT_MTYPE_TABSTAT, + PGSTAT_MTYPE_TABPURGE, + PGSTAT_MTYPE_DROPDB, + PGSTAT_MTYPE_RESETCOUNTER, + PGSTAT_MTYPE_RESETSHAREDCOUNTER, + PGSTAT_MTYPE_RESETSINGLECOUNTER, + PGSTAT_MTYPE_AUTOVAC_START, + PGSTAT_MTYPE_VACUUM, + PGSTAT_MTYPE_TRUNCATE, + PGSTAT_MTYPE_ANALYZE, + PGSTAT_MTYPE_BGWRITER, + PGSTAT_MTYPE_FUNCSTAT, + PGSTAT_MTYPE_FUNCPURGE, + PGSTAT_MTYPE_RECOVERYCONFLICT, + PGSTAT_MTYPE_TEMPFILE, + PGSTAT_MTYPE_DEADLOCK, + PGSTAT_MTYPE_AUTOVAC_STAT, + PGSTAT_MTYPE_FILE, + PGSTAT_MTYPE_DATA_CHANGED, + PGSTAT_MTYPE_MEMRESERVED, + PGSTAT_MTYPE_BADBLOCK, + PGSTAT_MTYPE_COLLECTWAITINFO, + PGSTAT_MTYPE_RESPONSETIME, + PGSTAT_MTYPE_PROCESSPERCENTILE, + PGSTAT_MTYPE_CLEANUPHOTKEYS +} StatMsgType; + +/* ---------- + * The data type used for counters. + * ---------- + */ +typedef int64 PgStat_Counter; + +/* ---------- + * PgStat_TableCounts The actual per-table counts kept by a backend + * + * This struct should contain only actual event counters, because we memcmp + * it against zeroes to detect whether there are any counts to transmit. + * It is a component of PgStat_TableStatus (within-backend state) and + * PgStat_TableEntry (the transmitted message format). + * + * Note: for a table, tuples_returned is the number of tuples successfully + * fetched by heap_getnext, while tuples_fetched is the number of tuples + * successfully fetched by heap_fetch under the control of bitmap indexscans. + * For an index, tuples_returned is the number of index entries returned by + * the index AM, while tuples_fetched is the number of tuples successfully + * fetched by heap_fetch under the control of simple indexscans for this index. + * + * tuples_inserted/updated/deleted/hot_updated count attempted actions, + * regardless of whether the transaction committed. delta_live_tuples, + * delta_dead_tuples, and changed_tuples are set depending on commit or abort. + * Note that delta_live_tuples and delta_dead_tuples can be negative! + * ---------- + */ +typedef struct PgStat_TableCounts { + PgStat_Counter t_numscans; + + PgStat_Counter t_tuples_returned; + PgStat_Counter t_tuples_fetched; + + PgStat_Counter t_tuples_inserted; + PgStat_Counter t_tuples_updated; + PgStat_Counter t_tuples_deleted; + PgStat_Counter t_tuples_hot_updated; + bool t_truncated; + + PgStat_Counter t_tuples_inserted_post_truncate; + PgStat_Counter t_tuples_updated_post_truncate; + PgStat_Counter t_tuples_deleted_post_truncate; + + PgStat_Counter t_delta_live_tuples; + PgStat_Counter t_delta_dead_tuples; + PgStat_Counter t_changed_tuples; + + PgStat_Counter t_blocks_fetched; + PgStat_Counter t_blocks_hit; + + PgStat_Counter t_cu_mem_hit; + PgStat_Counter t_cu_hdd_sync; + PgStat_Counter t_cu_hdd_asyn; +} PgStat_TableCounts; + +/* Possible targets for resetting cluster-wide shared values */ +typedef enum PgStat_Shared_Reset_Target { RESET_BGWRITER } PgStat_Shared_Reset_Target; + +/* Possible object types for resetting single counters */ +typedef enum PgStat_Single_Reset_Type { RESET_TABLE, RESET_FUNCTION } PgStat_Single_Reset_Type; + +/* ------------------------------------------------------------ + * Structures kept in backend local memory while accumulating counts + * ------------------------------------------------------------ + */ + +/* ---------- + * PgStat_TableStatus Per-table status within a backend + * + * Many of the event counters are nontransactional, ie, we count events + * in committed and aborted transactions alike. For these, we just count + * directly in the PgStat_TableStatus. However, delta_live_tuples, + * delta_dead_tuples, and changed_tuples must be derived from event counts + * with awareness of whether the transaction or subtransaction committed or + * aborted. Hence, we also keep a stack of per-(sub)transaction status + * records for every table modified in the current transaction. At commit + * or abort, we propagate tuples_inserted/updated/deleted up to the + * parent subtransaction level, or out to the parent PgStat_TableStatus, + * as appropriate. + * ---------- + */ +typedef struct PgStat_TableStatus { + Oid t_id; /* table's OID */ + bool t_shared; /* is it a shared catalog? */ + /* + * if t_id is a parition oid , then t_statFlag is the corresponding partitioned table oid; + * fi t_id is a non-parition oid, then t_statFlag is InvlaidOId + */ + uint32 t_statFlag; + struct PgStat_TableXactStatus* trans; /* lowest subxact's counts */ + PgStat_TableCounts t_counts; /* event counts to be sent */ +} PgStat_TableStatus; + +/* ---------- + * PgStat_TableXactStatus Per-table, per-subtransaction status + * ---------- + */ +typedef struct PgStat_TableXactStatus { + PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */ + PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */ + PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */ + bool truncated; /* relation truncated in this (sub)xact */ + PgStat_Counter inserted_pre_trunc; /* tuples inserted prior to truncate */ + PgStat_Counter updated_pre_trunc; /* tuples updated prior to truncate */ + PgStat_Counter deleted_pre_trunc; /* tuples deleted prior to truncate */ + int nest_level; /* subtransaction nest level */ + /* links to other structs for same relation: */ + struct PgStat_TableXactStatus* upper; /* next higher subxact if any */ + PgStat_TableStatus* parent; /* per-table status */ + /* structs of same subxact level are linked here: */ + struct PgStat_TableXactStatus* next; /* next of same subxact */ +} PgStat_TableXactStatus; + +/* ------------------------------------------------------------ + * Message formats follow + * ------------------------------------------------------------ + */ + +/* ---------- + * PgStat_MsgHdr The common message header + * ---------- + */ +typedef struct PgStat_MsgHdr { + StatMsgType m_type; + int m_size; +} PgStat_MsgHdr; + +/* ---------- + * Space available in a message. This will keep the UDP packets below 1K, + * which should fit unfragmented into the MTU of the lo interface on most + * platforms. Does anybody care for platforms where it doesn't? + * ---------- + */ +#define PGSTAT_MSG_PAYLOAD (1000 - sizeof(PgStat_MsgHdr)) + +/* ---------- + * PgStat_MsgDummy A dummy message, ignored by the collector + * ---------- + */ +typedef struct PgStat_MsgDummy { + PgStat_MsgHdr m_hdr; +} PgStat_MsgDummy; + +/* ---------- + * PgStat_MsgInquiry Sent by a backend to ask the collector + * to write the stats file. + * ---------- + */ + +typedef struct PgStat_MsgInquiry { + PgStat_MsgHdr m_hdr; + TimestampTz inquiry_time; /* minimum acceptable file timestamp */ +} PgStat_MsgInquiry; + +/* ---------- + * PgStat_TableEntry Per-table info in a MsgTabstat + * ---------- + */ +typedef struct PgStat_TableEntry { + Oid t_id; + uint32 t_statFlag; + PgStat_TableCounts t_counts; +} PgStat_TableEntry; + +/* ---------- + * PgStat_MsgTabstat Sent by the backend to report table + * and buffer access statistics. + * ---------- + */ +#define PGSTAT_NUM_TABENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int)) / sizeof(PgStat_TableEntry)) + +typedef struct PgStat_MsgTabstat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + int m_xact_commit; + int m_xact_rollback; + PgStat_Counter m_block_read_time; /* times in microseconds */ + PgStat_Counter m_block_write_time; + PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES]; +} PgStat_MsgTabstat; + +/* ---------- + * PgStat_MsgTabpurge Sent by the backend to tell the collector + * about dead tables. + * ---------- + */ +typedef struct PgStat_MsgTabEntry { + Oid m_tableid; + uint32 m_statFlag; +} PgStat_MsgTabEntry; +#define PGSTAT_NUM_TABPURGE ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(PgStat_MsgTabEntry)) + +typedef struct PgStat_MsgTabpurge { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + PgStat_MsgTabEntry m_entry[PGSTAT_NUM_TABPURGE]; +} PgStat_MsgTabpurge; + +/* ---------- + * PgStat_MsgDropdb Sent by the backend to tell the collector + * about a dropped database + * ---------- + */ +typedef struct PgStat_MsgDropdb { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgDropdb; + +/* ---------- + * PgStat_MsgResetcounter Sent by the backend to tell the collector + * to reset counters + * ---------- + */ +typedef struct PgStat_MsgResetcounter { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgResetcounter; + +typedef struct PgStat_MsgCleanupHotkeys { + PgStat_MsgHdr m_hdr; + Oid m_databaseOid; + Oid m_tableOid; +} PgStat_MsgCleanupHotkeys; + +/* ---------- + * PgStat_MsgResetsharedcounter Sent by the backend to tell the collector + * to reset a shared counter + * ---------- + */ +typedef struct PgStat_MsgResetsharedcounter { + PgStat_MsgHdr m_hdr; + PgStat_Shared_Reset_Target m_resettarget; +} PgStat_MsgResetsharedcounter; + +/* ---------- + * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector + * to reset a single counter + * ---------- + */ +typedef struct PgStat_MsgResetsinglecounter { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + PgStat_Single_Reset_Type m_resettype; + Oid m_objectid; + Oid p_objectid; /* parentted objectid if m_objectid is a partition objectid */ +} PgStat_MsgResetsinglecounter; + +/* ---------- + * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal + * that a database is going to be processed + * ---------- + */ +typedef struct PgStat_MsgAutovacStart { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + TimestampTz m_start_time; +} PgStat_MsgAutovacStart; + +/* ---------- + * PgStat_MsgVacuum Sent by the backend or autovacuum daemon + * after VACUUM + * ---------- + */ +typedef struct PgStat_MsgVacuum { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + bool m_autovacuum; + TimestampTz m_vacuumtime; + PgStat_Counter m_tuples; +} PgStat_MsgVacuum; + +/* ---------- + * PgStat_MsgIUD Sent by the insert/delete/update + * ---------- + */ +typedef struct PgStat_MsgDataChanged { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + TimestampTz m_changed_time; +} PgStat_MsgDataChanged; + +/* ---------- + * PgStat_MsgAvStat Sent autovac stat to collector + * Reset by + * ---------- + */ +#define AV_TIMEOUT (1 << 0) /* autovac have been canceled due to timeout */ +#define AV_ANALYZE (1 << 1) /* is doing auto-analyze */ +#define AV_VACUUM (1 << 2) /* is doing auto-vacuum */ + +typedef struct PgStat_MsgAutovacStat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + int64 m_autovacStat; +} PgStat_MsgAutovacStat; + +/* ---------- + * PgStat_MsgTruncate Sent by the truncate + * ---------- + */ + +typedef struct PgStat_MsgTruncate { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + /* + * if m_tableoid is partition oid, then m_statFlag is the corresponding + * partitioned table oid, else it is InvalidOId + */ + uint32 m_statFlag; +} PgStat_MsgTruncate; + +/* ---------- + * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon + * after ANALYZE + * ---------- + */ +typedef struct PgStat_MsgAnalyze { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + bool m_autovacuum; + TimestampTz m_analyzetime; + PgStat_Counter m_live_tuples; + PgStat_Counter m_dead_tuples; +} PgStat_MsgAnalyze; + +/* ---------- + * PgStat_MsgBgWriter Sent by the bgwriter to update statistics. + * ---------- + */ +typedef struct PgStat_MsgBgWriter { + PgStat_MsgHdr m_hdr; + + PgStat_Counter m_timed_checkpoints; + PgStat_Counter m_requested_checkpoints; + PgStat_Counter m_buf_written_checkpoints; + PgStat_Counter m_buf_written_clean; + PgStat_Counter m_maxwritten_clean; + PgStat_Counter m_buf_written_backend; + PgStat_Counter m_buf_fsync_backend; + PgStat_Counter m_buf_alloc; + PgStat_Counter m_checkpoint_write_time; /* times in milliseconds */ + PgStat_Counter m_checkpoint_sync_time; +} PgStat_MsgBgWriter; + +/* ---------- + * PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict + * ---------- + */ +typedef struct PgStat_MsgRecoveryConflict { + PgStat_MsgHdr m_hdr; + + Oid m_databaseid; + int m_reason; +} PgStat_MsgRecoveryConflict; + +/* ---------- + * PgStat_MsgTempFile Sent by the backend upon creating a temp file + * ---------- + */ +typedef struct PgStat_MsgTempFile { + PgStat_MsgHdr m_hdr; + + Oid m_databaseid; + size_t m_filesize; +} PgStat_MsgTempFile; + +/* ---------- + * PgStat_MsgMemReserved Sent by the backend upon succeeding in reserving memory + * ---------- + */ +typedef struct PgStat_MsgMemReserved { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int64 m_memMbytes; + int m_reserve_or_release; +} PgStat_MsgMemReserved; + +/* ---------- + * PgStat_FunctionCounts The actual per-function counts kept by a backend + * + * This struct should contain only actual event counters, because we memcmp + * it against zeroes to detect whether there are any counts to transmit. + * + * Note that the time counters are in instr_time format here. We convert to + * microseconds in PgStat_Counter format when transmitting to the collector. + * ---------- + */ +typedef struct PgStat_FunctionCounts { + PgStat_Counter f_numcalls; + instr_time f_total_time; + instr_time f_self_time; +} PgStat_FunctionCounts; + +/* ---------- + * PgStat_BackendFunctionEntry Entry in backend's per-function hash table + * ---------- + */ +typedef struct PgStat_BackendFunctionEntry { + Oid f_id; + PgStat_FunctionCounts f_counts; +} PgStat_BackendFunctionEntry; + +/* ---------- + * PgStat_FunctionEntry Per-function info in a MsgFuncstat + * ---------- + */ +typedef struct PgStat_FunctionEntry { + Oid f_id; + PgStat_Counter f_numcalls; + PgStat_Counter f_total_time; /* times in microseconds */ + PgStat_Counter f_self_time; +} PgStat_FunctionEntry; + +/* ---------- + * PgStat_MsgFuncstat Sent by the backend to report function + * usage statistics. + * ---------- + */ +#define PGSTAT_NUM_FUNCENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(PgStat_FunctionEntry)) + +typedef struct PgStat_MsgFuncstat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]; +} PgStat_MsgFuncstat; + +/* ---------- + * PgStat_MsgFuncpurge Sent by the backend to tell the collector + * about dead functions. + * ---------- + */ +#define PGSTAT_NUM_FUNCPURGE ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(Oid)) + +typedef struct PgStat_MsgFuncpurge { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + Oid m_functionid[PGSTAT_NUM_FUNCPURGE]; +} PgStat_MsgFuncpurge; + +/* ---------- + * PgStat_MsgDeadlock Sent by the backend to tell the collector + * about a deadlock that occurred. + * ---------- + */ +typedef struct PgStat_MsgDeadlock { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgDeadlock; + +/* ---------- + * PgStat_MsgFile Sent by the backend upon reading/writing a data file + * ---------- + */ +typedef struct PgStat_MsgFile { + PgStat_MsgHdr m_hdr; + + Oid dbid; + Oid spcid; + Oid fn; + char rw; + PgStat_Counter cnt; + PgStat_Counter blks; + PgStat_Counter tim; + PgStat_Counter lsttim; + PgStat_Counter mintim; + PgStat_Counter maxtim; +} PgStat_MsgFile; + +/* + * PgStat_MsgBadBlock Sent by the backend where read bad page / cu + */ + +typedef struct BadBlockHashKey { + RelFileNode relfilenode; + ForkNumber forknum; +} BadBlockHashKey; + +typedef struct BadBlockHashEnt { + BadBlockHashKey key; + int error_count; + TimestampTz first_time; + TimestampTz last_time; +} BadBlockHashEnt; + +#define PGSTAT_NUM_BADBLOCK_ENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(int)) / sizeof(BadBlockHashEnt)) + +typedef struct PgStat_MsgBadBlock { + PgStat_MsgHdr m_hdr; + int m_nentries; + BadBlockHashEnt m_entry[PGSTAT_NUM_BADBLOCK_ENTRIES]; +} PgStat_MsgBadBlock; + +const int MAX_SQL_RT_INFO_COUNT = 100000; + +typedef struct SqlRTInfo { + uint64 UniqueSQLId; + int64 start_time; + int64 rt; +} SqlRTInfo; + +typedef struct SqlRTInfoArray { + volatile int32 sqlRTIndex; + bool isFull; + SqlRTInfo sqlRT[MAX_SQL_RT_INFO_COUNT]; +} SqlRTInfoArray; + +typedef struct PgStat_SqlRT { + PgStat_MsgHdr m_hdr; + SqlRTInfo sqlRT; +} PgStat_SqlRT; +const int MAX_SQL_RT_INFO_COUNT_REMOTE = MaxAllocSize / sizeof(SqlRTInfo); + +typedef struct PgStat_PrsPtl { + PgStat_MsgHdr m_hdr; + int64 now; +} PgStat_PrsPtl; + +/* ---------- + * PgStat_Msg Union over all possible messages. + * ---------- + */ +typedef union PgStat_Msg { + PgStat_MsgHdr msg_hdr; + PgStat_MsgDummy msg_dummy; + PgStat_MsgInquiry msg_inquiry; + PgStat_MsgTabstat msg_tabstat; + PgStat_MsgTabpurge msg_tabpurge; + PgStat_MsgDropdb msg_dropdb; + PgStat_MsgResetcounter msg_resetcounter; + PgStat_MsgResetsharedcounter msg_resetsharedcounter; + PgStat_MsgResetsinglecounter msg_resetsinglecounter; + PgStat_MsgAutovacStart msg_autovacuum; + PgStat_MsgVacuum msg_vacuum; + PgStat_MsgTruncate msg_truncate; + PgStat_MsgAnalyze msg_analyze; + PgStat_MsgBgWriter msg_bgwriter; + PgStat_MsgFuncstat msg_funcstat; + PgStat_MsgFuncpurge msg_funcpurge; + PgStat_MsgRecoveryConflict msg_recoveryconflict; + PgStat_MsgDeadlock msg_deadlock; + PgStat_MsgFile msg_file; + PgStat_SqlRT msg_sqlrt; + PgStat_PrsPtl msg_prosqlrt; +} PgStat_Msg; + +/* ------------------------------------------------------------ + * Statistic collector data structures follow + * + * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these + * data structures change. + * ------------------------------------------------------------ + */ + +#define PGSTAT_FILE_FORMAT_ID 0x01A5BC9B + +/* ---------- + * PgStat_StatDBEntry The collector's data per database + * ---------- + */ +typedef struct PgStat_StatDBEntry { + Oid databaseid; + PgStat_Counter n_xact_commit; + PgStat_Counter n_xact_rollback; + PgStat_Counter n_blocks_fetched; + PgStat_Counter n_blocks_hit; + + PgStat_Counter n_cu_mem_hit; + PgStat_Counter n_cu_hdd_sync; + PgStat_Counter n_cu_hdd_asyn; + + PgStat_Counter n_tuples_returned; + PgStat_Counter n_tuples_fetched; + PgStat_Counter n_tuples_inserted; + PgStat_Counter n_tuples_updated; + PgStat_Counter n_tuples_deleted; + TimestampTz last_autovac_time; + PgStat_Counter n_conflict_tablespace; + PgStat_Counter n_conflict_lock; + PgStat_Counter n_conflict_snapshot; + PgStat_Counter n_conflict_bufferpin; + PgStat_Counter n_conflict_startup_deadlock; + PgStat_Counter n_temp_files; + PgStat_Counter n_temp_bytes; + PgStat_Counter n_deadlocks; + PgStat_Counter n_block_read_time; /* times in microseconds */ + PgStat_Counter n_block_write_time; + PgStat_Counter n_mem_mbytes_reserved; + + TimestampTz stat_reset_timestamp; + + /* + * tables and functions must be last in the struct, because we don't write + * the pointers out to the stats file. + */ + HTAB* tables; + HTAB* functions; +} PgStat_StatDBEntry; + +typedef enum PgStat_StatTabType { + STATFLG_RELATION = 0, /* stat info for relation */ + STATFLG_PARTITION = 1, /* stat info for partition */ +} PgStat_StatTabType; + +/* + * stat table key + * if tableid is a relation oid, statFlag is invalidoid + * if tableid is a partition oid, statFlag is the corresponding + * partitioned table's oid + */ +typedef struct PgStat_StatTabKey { + Oid tableid; + uint32 statFlag; +} PgStat_StatTabKey; + +/* ---------- + * PgStat_StatTabEntry The collector's data per table (or index) + * ---------- + */ +#define CONTINUED_TIMEOUT_BITMAP 0X00000000000000FF +#define MAX_CONTINUED_TIMEOUT_COUNT CONTINUED_TIMEOUT_BITMAP +#define CONTINUED_TIMEOUT_COUNT(status) (0X00000000000000FF & (status)) +#define reset_continued_timeout(status) \ + do { \ + (status) = ((~CONTINUED_TIMEOUT_BITMAP) & (status)); \ + } while (0); + +#define increase_continued_timeout(status) \ + do { \ + if (CONTINUED_TIMEOUT_COUNT(status) < MAX_CONTINUED_TIMEOUT_COUNT) \ + (status)++; \ + } while (0); + +#define TOTAL_TIMEOUT_BITMAP 0X0000000000FFFF00 +#define MAX_TOTAL_TIMEOUT_COUNT TOTAL_TIMEOUT_BITMAP >> 16 +#define TOTAL_TIMEOUT_COUNT(status) (((status)&TOTAL_TIMEOUT_BITMAP) >> 16) +#define increase_toatl_timeout(status) \ + do { \ + if (TOTAL_TIMEOUT_COUNT(status) < MAX_TOTAL_TIMEOUT_COUNT) \ + status = status + 0X0000000000000100; \ + } while (0); + +typedef struct PgStat_StatTabEntry { + PgStat_StatTabKey tablekey; + + PgStat_Counter numscans; + + PgStat_Counter tuples_returned; + PgStat_Counter tuples_fetched; + + PgStat_Counter tuples_inserted; + PgStat_Counter tuples_updated; + PgStat_Counter tuples_deleted; + PgStat_Counter tuples_hot_updated; + + PgStat_Counter n_live_tuples; + PgStat_Counter n_dead_tuples; + PgStat_Counter changes_since_analyze; + + PgStat_Counter blocks_fetched; + PgStat_Counter blocks_hit; + + PgStat_Counter cu_mem_hit; + PgStat_Counter cu_hdd_sync; + PgStat_Counter cu_hdd_asyn; + + TimestampTz vacuum_timestamp; /* user initiated vacuum */ + PgStat_Counter vacuum_count; + TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_vacuum_count; + TimestampTz analyze_timestamp; /* user initiated */ + PgStat_Counter analyze_count; + TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_analyze_count; + TimestampTz data_changed_timestamp; /* start to insert/delete/upate */ + uint64 autovac_status; +} PgStat_StatTabEntry; + +/* ---------- + * PgStat_StatFuncEntry The collector's data per function + * ---------- + */ +typedef struct PgStat_StatFuncEntry { + Oid functionid; + + PgStat_Counter f_numcalls; + + PgStat_Counter f_total_time; /* times in microseconds */ + PgStat_Counter f_self_time; +} PgStat_StatFuncEntry; + +/* + * Global statistics kept in the stats collector + */ +typedef struct PgStat_GlobalStats { + TimestampTz stats_timestamp; /* time of stats file update */ + PgStat_Counter timed_checkpoints; + PgStat_Counter requested_checkpoints; + PgStat_Counter checkpoint_write_time; /* times in milliseconds */ + PgStat_Counter checkpoint_sync_time; + PgStat_Counter buf_written_checkpoints; + PgStat_Counter buf_written_clean; + PgStat_Counter maxwritten_clean; + PgStat_Counter buf_written_backend; + PgStat_Counter buf_fsync_backend; + PgStat_Counter buf_alloc; + TimestampTz stat_reset_timestamp; +} PgStat_GlobalStats; + +/* ---------- + * Backend states + * ---------- + */ +typedef enum BackendState { + STATE_UNDEFINED, + STATE_IDLE, + STATE_RUNNING, + STATE_IDLEINTRANSACTION, + STATE_FASTPATH, + STATE_IDLEINTRANSACTION_ABORTED, + STATE_DISABLED, + STATE_RETRYING, + STATE_COUPLED, + STATE_DECOUPLED, +} BackendState; + +/* ---------- + * Backend waiting states + * NOTE: if you add a WaitState enum value, remember to add it's description in WaitStateDesc. + * ---------- + */ +typedef enum WaitState { + STATE_WAIT_UNDEFINED = 0, + STATE_WAIT_LWLOCK, + STATE_WAIT_LOCK, + STATE_WAIT_IO, + STATE_WAIT_COMM, + STATE_WAIT_POOLER_GETCONN, + STATE_WAIT_POOLER_ABORTCONN, + STATE_WAIT_POOLER_CLEANCONN, + STATE_POOLER_CREATE_CONN, + STATE_POOLER_WAIT_GETCONN, + STATE_POOLER_WAIT_SETCMD, + STATE_POOLER_WAIT_RESETCMD, + STATE_POOLER_WAIT_CANCEL, + STATE_POOLER_WAIT_STOP, + STATE_WAIT_NODE, + STATE_WAIT_XACTSYNC, + STATE_WAIT_WALSYNC, + STATE_WAIT_DATASYNC, + STATE_WAIT_DATASYNC_QUEUE, + STATE_WAIT_FLUSH_DATA, + STATE_STREAM_WAIT_CONNECT_NODES, + STATE_STREAM_WAIT_PRODUCER_READY, + STATE_STREAM_WAIT_THREAD_SYNC_QUIT, + STATE_STREAM_WAIT_NODEGROUP_DESTROY, + STATE_WAIT_ACTIVE_STATEMENT, + STATE_WAIT_MEMORY, + STATE_EXEC_SORT, + STATE_EXEC_SORT_WRITE_FILE, + STATE_EXEC_MATERIAL, + STATE_EXEC_MATERIAL_WRITE_FILE, + STATE_EXEC_HASHJOIN_BUILD_HASH, + STATE_EXEC_HASHJOIN_WRITE_FILE, + STATE_EXEC_HASHAGG_BUILD_HASH, + STATE_EXEC_HASHAGG_WRITE_FILE, + STATE_EXEC_HASHSETOP_BUILD_HASH, + STATE_EXEC_HASHSETOP_WRITE_FILE, + STATE_EXEC_NESTLOOP, + STATE_CREATE_INDEX, + STATE_ANALYZE, + STATE_VACUUM, + STATE_VACUUM_FULL, + STATE_GTM_CONNECT, + STATE_GTM_RESET_XMIN, + STATE_GTM_GET_XMIN, + STATE_GTM_GET_GXID, + STATE_GTM_GET_CSN, + STATE_GTM_GET_SNAPSHOT, + STATE_GTM_BEGIN_TRANS, + STATE_GTM_COMMIT_TRANS, + STATE_GTM_ROLLBACK_TRANS, + STATE_GTM_START_PREPARE_TRANS, + STATE_GTM_PREPARE_TRANS, + STATE_GTM_OPEN_SEQUENCE, + STATE_GTM_CLOSE_SEQUENCE, + STATE_GTM_CREATE_SEQUENCE, + STATE_GTM_ALTER_SEQUENCE, + STATE_GTM_SEQUNCE_GET_NEXT_VAL, + STATE_GTM_SEQUENCE_SET_VAL, + STATE_GTM_DROP_SEQUENCE, + STATE_GTM_RENAME_SEQUENCE, + STATE_WAIT_SYNC_CONSUMER_NEXT_STEP, + STATE_WAIT_SYNC_PRODUCER_NEXT_STEP, + STATE_WAIT_NUM // MUST be last, DO NOT use this value. +} WaitState; + +/* ---------- + * Backend phase for "wait node" status + * NOTE: if you add a WaitStatePhase enum value, remember to add it's description in WaitStatePhaseDesc. + * ---------- + */ +typedef enum WaitStatePhase { + PHASE_NONE = 0, + PHASE_BEGIN, + PHASE_COMMIT, + PHASE_ROLLBACK, + PHASE_WAIT_QUOTA, + PHASE_AUTOVACUUM +} WaitStatePhase; + +/* ---------- + * Wait Event Classes + * ---------- + */ +#define WAIT_EVENT_END 0x00000000U +#define PG_WAIT_LWLOCK 0x01000000U +#define PG_WAIT_LOCK 0x03000000U +#define PG_WAIT_IO 0x0A000000U +#define PG_WAIT_SQL 0x0B000000U + +/* ---------- + * Wait Events - IO + * + * Use this category when a process is waiting for a IO. + * ---------- + */ +typedef enum WaitEventIO { + WAIT_EVENT_BUFFILE_READ = PG_WAIT_IO, + WAIT_EVENT_BUFFILE_WRITE, + WAIT_EVENT_BUF_HASH_SEARCH, + WAIT_EVENT_BUF_STRATEGY_GET, + WAIT_EVENT_CONTROL_FILE_READ, + WAIT_EVENT_CONTROL_FILE_SYNC, + WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE, + WAIT_EVENT_CONTROL_FILE_WRITE, + WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE, + WAIT_EVENT_COPY_FILE_READ, + WAIT_EVENT_COPY_FILE_WRITE, + WAIT_EVENT_DATA_FILE_EXTEND, + WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC, + WAIT_EVENT_DATA_FILE_PREFETCH, + WAIT_EVENT_DATA_FILE_READ, + WAIT_EVENT_DATA_FILE_SYNC, + WAIT_EVENT_DATA_FILE_TRUNCATE, + WAIT_EVENT_DATA_FILE_WRITE, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE, + WAIT_EVENT_LOCK_FILE_CREATE_READ, + WAIT_EVENT_LOCK_FILE_CREATE_SYNC, + WAIT_EVENT_LOCK_FILE_CREATE_WRITE, + WAIT_EVENT_RELATION_MAP_READ, + WAIT_EVENT_RELATION_MAP_SYNC, + WAIT_EVENT_RELATION_MAP_WRITE, + WAIT_EVENT_REPLICATION_SLOT_READ, + WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC, + WAIT_EVENT_REPLICATION_SLOT_SYNC, + WAIT_EVENT_REPLICATION_SLOT_WRITE, + WAIT_EVENT_SLRU_FLUSH_SYNC, + WAIT_EVENT_SLRU_READ, + WAIT_EVENT_SLRU_SYNC, + WAIT_EVENT_SLRU_WRITE, + WAIT_EVENT_TWOPHASE_FILE_READ, + WAIT_EVENT_TWOPHASE_FILE_SYNC, + WAIT_EVENT_TWOPHASE_FILE_WRITE, + WAIT_EVENT_WAL_BOOTSTRAP_SYNC, + WAIT_EVENT_WAL_BOOTSTRAP_WRITE, + WAIT_EVENT_WAL_COPY_READ, + WAIT_EVENT_WAL_COPY_SYNC, + WAIT_EVENT_WAL_COPY_WRITE, + WAIT_EVENT_WAL_INIT_SYNC, + WAIT_EVENT_WAL_INIT_WRITE, + WAIT_EVENT_WAL_READ, + WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN, + WAIT_EVENT_WAL_WRITE, + WAIT_EVENT_WAL_BUFFER_ACCESS, + WAIT_EVENT_WAL_BUFFER_FULL, + WAIT_EVENT_DW_READ, + WAIT_EVENT_DW_WRITE, + WAIT_EVENT_DW_SINGLE_POS, + WAIT_EVENT_DW_SINGLE_WRITE, + WAIT_EVENT_PREDO_PROCESS_PENDING, + WAIT_EVENT_PREDO_APPLY, + WAIT_EVENT_DISABLE_CONNECT_FILE_READ, + WAIT_EVENT_DISABLE_CONNECT_FILE_SYNC, + WAIT_EVENT_DISABLE_CONNECT_FILE_WRITE, + WAIT_EVENT_MPFL_INIT, + WAIT_EVENT_MPFL_READ, + WAIT_EVENT_MPFL_WRITE, + WAIT_EVENT_OBS_LIST, + WAIT_EVENT_OBS_READ, + WAIT_EVENT_OBS_WRITE, + WAIT_EVENT_LOGCTRL_SLEEP, + IO_EVENT_NUM = WAIT_EVENT_LOGCTRL_SLEEP - WAIT_EVENT_BUFFILE_READ + 1 // MUST be last, DO NOT use this value. +} WaitEventIO; + +/* ---------- + * Wait Events - SQL + * + * Using this to indicate the type of SQL DML event. + * ---------- + */ +typedef enum WaitEventSQL { + WAIT_EVENT_SQL_SELECT = PG_WAIT_SQL, + WAIT_EVENT_SQL_UPDATE, + WAIT_EVENT_SQL_INSERT, + WAIT_EVENT_SQL_DELETE, + WAIT_EVENT_SQL_MERGEINTO, + WAIT_EVENT_SQL_DDL, + WAIT_EVENT_SQL_DML, + WAIT_EVENT_SQL_DCL, + WAIT_EVENT_SQL_TCL +} WaitEventSQL; + +/* ---------- + * WAIT_COUNT_ARRAY_SIZE Size of the array used for user`s sql count + * ---------- + */ +#define WAIT_COUNT_ARRAY_SIZE 128 + +typedef struct { + uint64 total_time; /* total time for sql */ + uint64 avg_time; /* avg time for sql */ + uint64 min_time; /* min time for sql */ + uint64 max_time; /* max time for sql */ +} ElapseTime; +/* ---------- + * PgStat_WaitCount The sql count result used for QPS + * ---------- + */ +typedef struct PgStat_WaitCount { + uint64 wc_sql_select; + uint64 wc_sql_update; + uint64 wc_sql_insert; + uint64 wc_sql_delete; + uint64 wc_sql_mergeinto; + uint64 wc_sql_ddl; + uint64 wc_sql_dml; + uint64 wc_sql_dcl; + uint64 wc_sql_tcl; + ElapseTime insertElapse; + ElapseTime updateElapse; + ElapseTime selectElapse; + ElapseTime deleteElapse; +} PgStat_WaitCount; + +/* ---------- + * PgStat_WaitCountStatus The sql count result for per user + * ---------- + */ +typedef struct PgStat_WaitCountStatus { + PgStat_WaitCount wc_cnt; + uint32 userid; +} PgStat_WaitCountStatus; + +/* ---------- + * PgStat_WaitCountStatusCell The data cell of WaitCountStatusList + * ---------- + */ +typedef struct PgStat_WaitCountStatusCell { + PgStat_WaitCountStatus WaitCountArray[WAIT_COUNT_ARRAY_SIZE]; +} PgStat_WaitCountStatusCell; + +/* ---------- + * WaitCountHashValue The value when find WaitCountHashTbl + * ---------- + */ +typedef struct WaitCountHashValue { + Oid userid; + int idx; +} WaitCountHashValue; + +/* ---------- + * The data type used for performance monitor. + * ---------- + */ +typedef enum WorkloadManagerIOState { + IOSTATE_NONE = 0, + IOSTATE_READ, + IOSTATE_WRITE, + IOSTATE_VACUUM +} WorkloadManagerIOState; + +typedef enum WorkloadManagerStmtTag { STMTTAG_NONE = 0, STMTTAG_READ, STMTTAG_WRITE } WorkloadManagerStmtTag; + +/* ---------- + * Workload manager states + * ---------- + */ +typedef enum WorkloadManagerEnqueueState { + STATE_NO_ENQUEUE, + STATE_MEMORY, + STATE_ACTIVE_STATEMENTS, +} WorkloadManagerEnqueueState; + +typedef struct RemoteInfo { + char remote_name[NAMEDATALEN]; + char remote_ip[MAX_IP_STR_LEN]; + char remote_port[MAX_PORT_LEN]; + int socket; + int logic_id; +} RemoteInfo; + +/* ---------- + * Shared-memory data structures + * ---------- + */ + +/* Reserve 2 additional 3rd plugin lwlocks.*/ +#define LWLOCK_EVENT_NUM (LWTRANCHE_NATIVE_TRANCHE_NUM + 2) +typedef struct WaitStatisticsInfo { + int64 max_duration; + int64 min_duration; + int64 total_duration; + int64 avg_duration; + uint64 counter; + uint64 failed_counter; + TimestampTz last_updated; +} WaitStatisticsInfo; + +typedef struct WaitStatusInfo { + int64 start_time; // current wait starttime + WaitStatisticsInfo statistics_info[STATE_WAIT_NUM + 1]; +} WaitStatusInfo; + +typedef struct WaitEventInfo { + int64 start_time; // current wait starttime + int64 duration; // current wait duration + WaitStatisticsInfo io_info[IO_EVENT_NUM]; + WaitStatisticsInfo lock_info[LOCK_EVENT_NUM]; + WaitStatisticsInfo lwlock_info[LWLOCK_EVENT_NUM]; +} WaitEventInfo; + +typedef struct WaitInfo { + WaitEventInfo event_info; + WaitStatusInfo status_info; +} WaitInfo; + +/* ---------- + * PgBackendStatus + * + * Each live backend maintains a PgBackendStatus struct in shared memory + * showing its current activity. (The structs are allocated according to + * BackendId, but that is not critical.) Note that the collector process + * has no involvement in, or even access to, these structs. + * ---------- + */ +typedef struct PgBackendStatus { + /* + * To avoid locking overhead, we use the following protocol: a backend + * increments st_changecount before modifying its entry, and again after + * finishing a modification. A would-be reader should note the value of + * st_changecount, copy the entry into private memory, then check + * st_changecount again. If the value hasn't changed, and if it's even, + * the copy is valid; otherwise start over. This makes updates cheap + * while reads are potentially expensive, but that's the tradeoff we want. + * + * The above protocol needs the memory barriers to ensure that + * the apparent order of execution is as it desires. Otherwise, + * for example, the CPU might rearrange the code so that st_changecount + * is incremented twice before the modification on a machine with + * weak memory ordering. This surprising result can lead to bugs. + */ + int st_changecount; + + /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */ + ThreadId st_procpid; + /* The entry is valid when one session is coupled to a thread pool worker */ + uint64 st_sessionid; + + /* Times when current backend, transaction, and activity started */ + TimestampTz st_proc_start_timestamp; + TimestampTz st_xact_start_timestamp; + TimestampTz st_activity_start_timestamp; + TimestampTz st_state_start_timestamp; + + /* Database OID, owning user's OID, connection client address */ + Oid st_databaseid; + Oid st_userid; + SockAddr st_clientaddr; + char* st_clienthostname; /* MUST be null-terminated */ + + void* st_connect_info; /* pool connection state */ + + /* current state */ + BackendState st_state; + + /* application name; MUST be null-terminated */ + char* st_appname; + + /* connection info; */ + char* st_conninfo; + + /* current command string; MUST be null-terminated */ + char* st_activity; + + /* which resource waiting on? */ + WorkloadManagerEnqueueState st_waiting_on_resource; + + /* workload info */ + TimestampTz st_block_start_time; /* block start time */ + TimestampTz st_elapsed_start_time; /* elapsed start time */ + WLMStatistics st_backstat; /* workload backend state */ + void* st_debug_info; /* workload debug info */ + char* st_cgname; /* workload cgroup name */ + WorkloadManagerIOState st_io_state; /* 0: none 1: read: 2: write */ + WorkloadManagerStmtTag st_stmttag; /* 0: none 1: read: 2: write */ + + uint64 st_queryid; /* debug query id of current query */ + UniqueSQLKey st_unique_sql_key; /* get unique sql key */ + pid_t st_tid; /* thread ID */ + uint64 st_parent_sessionid; /* parent session ID, equals parent pid under non thread pool mode */ + int st_thread_level; /* thread level, mark with plan node id of Stream node */ + uint32 st_smpid; /* smp worker id, used for parallel execution */ + WaitState st_waitstatus; /* backend waiting states */ + int st_waitnode_count; /* count of waiting nodes */ + int st_nodeid; /* maybe for nodeoid/nodeidx */ + int st_plannodeid; /* indentify which consumer is receiving data for SCTP */ + int st_numnodes; /* nodes number when reporting waitstatus in case it changed */ + uint32 st_waitevent; /* backend's wait event */ + int st_stmtmem; /* statment mem for query */ + uint64 st_xid; /* for transaction id, fit for 64-bit */ + WaitStatePhase st_waitstatus_phase; /* detailed phase for wait status, now only for 'wait node' status */ + char* st_relname; /* relation name, for analyze, vacuum, .etc.*/ + Oid st_libpq_wait_nodeid; /* for libpq, point to libpq_wait_node*/ + int st_libpq_wait_nodecount; /* for libpq, point to libpq_wait_nodecount*/ + uint32 st_tempid; /* tempid for temp table */ + uint32 st_timelineid; /* timeline id for temp table */ + int4 st_jobid; /* job work id */ + + /* Latest connected GTM host index and time line */ + GtmHostIndex st_gtmhost; + GTM_Timeline st_gtmtimeline; + slock_t use_mutex; /* protect above variables */ + + /* lwlock deadlock check */ + /* +1 before waiting; +1 after holding */ + int lw_count; + /* lwlock object now requiring */ + LWLock* lw_want_lock; + + /* all lwlocks held by this thread */ + int* lw_held_num; /* point to num_held_lwlocks */ + void* lw_held_locks; /* point to held_lwlocks[] */ + volatile bool st_lw_access_flag; /* valid flag */ + volatile bool st_lw_is_cleanning_flag; /* is cleanning lw ptr */ + + RemoteInfo remote_info; + WaitInfo waitInfo; + LOCALLOCKTAG locallocktag; /* locked object */ + /* The entry is valid if st_block_sessionid > 0, unused if st_block_sessionid == 0 */ + volatile uint64 st_block_sessionid; /* block session */ + syscalllock statement_cxt_lock; /* mutex for statement context(between session and statement flush thread) */ + void* statement_cxt; /* statement context of full sql */ +} PgBackendStatus; + +typedef struct PgBackendStatusNode { + PgBackendStatus* data; + NameData database_name; + PgBackendStatusNode* next; +} PgBackendStatusNode; + +typedef struct ThreadWaitStatusInfo { + ParallelFunctionState* state; + TupleTableSlot* slot; +} ThreadWaitStatusInfo; + +typedef struct CommInfoParallel { + ParallelFunctionState* state; + TupleTableSlot* slot; +} CommInfoParallel; + +extern CommInfoParallel* getGlobalCommStatus(TupleDesc tuple_desc, char* queryString); +extern ThreadWaitStatusInfo* getGlobalThreadWaitStatus(TupleDesc tuple_desc); + +extern PgBackendStatus* PgBackendStatusArray; + +/* + * Macros to load and store st_changecount with the memory barriers. + * + * pgstat_increment_changecount_before() and + * pgstat_increment_changecount_after() need to be called before and after + * PgBackendStatus entries are modified, respectively. This makes sure that + * st_changecount is incremented around the modification. + * + * Also pgstat_save_changecount_before() and pgstat_save_changecount_after() + * need to be called before and after PgBackendStatus entries are copied into + * private memory, respectively. + */ +#define pgstat_increment_changecount_before(beentry) \ + do { \ + beentry->st_changecount++; \ + pg_write_barrier(); \ + } while (0) + +#define pgstat_increment_changecount_after(beentry) \ + do { \ + pg_write_barrier(); \ + beentry->st_changecount++; \ + Assert((beentry->st_changecount & 1) == 0); \ + } while (0) + +#define pgstat_save_changecount_before(beentry, save_changecount) \ + do { \ + save_changecount = beentry->st_changecount; \ + pg_read_barrier(); \ + } while (0) + +#define pgstat_save_changecount_after(beentry, save_changecount) \ + do { \ + pg_read_barrier(); \ + save_changecount = beentry->st_changecount; \ + } while (0) + +extern char* getThreadWaitStatusDesc(PgBackendStatus* beentry); +extern const char* pgstat_get_waitstatusdesc(uint32 wait_event_info); +extern const char* pgstat_get_waitstatusname(uint32 wait_event_info); +extern const char* PgstatGetWaitstatephasename(uint32 waitPhaseInfo); +extern pthread_mutex_t nodeDefCopyLock; + +/* + * Working state needed to accumulate per-function-call timing statistics. + */ +typedef struct PgStat_FunctionCallUsage { + /* Link to function's hashtable entry (must still be there at exit!) */ + /* NULL means we are not tracking the current function call */ + PgStat_FunctionCounts* fs; + /* Total time previously charged to function, as of function start */ + instr_time save_f_total_time; + /* Backend-wide total time as of function start */ + instr_time save_total; + /* system clock as of function start */ + instr_time f_start; +} PgStat_FunctionCallUsage; + +extern THR_LOCAL volatile Oid* libpq_wait_nodeid; +extern THR_LOCAL volatile int* libpq_wait_nodecount; + +/* ---------- + * Functions called from postmaster + * ---------- + */ +extern Size BackendStatusShmemSize(void); +extern void CreateSharedBackendStatus(void); + +extern void pgstat_init(void); +extern ThreadId pgstat_start(void); +extern void pgstat_reset_all(void); +extern void allow_immediate_pgstat_restart(void); +extern void PgstatCollectorMain(); + +/* ---------- + * Functions called from backends + * ---------- + */ +const int NUM_PERCENTILE = 2; +extern void pgstat_ping(void); +extern void UpdateWaitStatusStat(volatile WaitInfo* InstrWaitInfo, uint32 waitstatus, int64 duration); +extern void UpdateWaitEventStat(volatile WaitInfo* InstrWaitInfo, uint32 wait_event_info, int64 duration); +extern void UpdateWaitEventFaildStat(volatile WaitInfo* InstrWaitInfo, uint32 wait_event_info); +extern void CollectWaitInfo(WaitInfo* gsInstrWaitInfo, WaitStatusInfo status_info, WaitEventInfo event_info); +extern void InstrWaitEventInitLastUpdated(PgBackendStatus* current_entry, TimestampTz current_time); +extern void pgstat_report_stat(bool force); +extern void pgstat_vacuum_stat(void); +extern void pgstat_drop_database(Oid databaseid); + +extern void pgstat_clear_snapshot(void); +extern void pgstat_reset_counters(void); +extern void pgstat_reset_shared_counters(const char*); +extern void pgstat_reset_single_counter(Oid p_objoid, Oid objectid, PgStat_Single_Reset_Type type); + +extern void pgstat_report_autovac(Oid dboid); +extern void pgstat_report_autovac_timeout(Oid tableoid, uint32 statFlag, bool shared); +extern void pgstat_report_vacuum(Oid tableoid, uint32 statFlag, bool shared, PgStat_Counter tuples); +extern void pgstat_report_truncate(Oid tableoid, uint32 statFlag, bool shared); +extern void pgstat_report_data_changed(Oid tableoid, uint32 statFlag, bool shared); + +extern void pgstat_report_sql_rt(uint64 UniqueSQLId, int64 start_time, int64 rt); +extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples); + +extern void pgstat_report_recovery_conflict(int reason); +extern void pgstat_report_deadlock(void); +const char* remote_conn_type_string(int remote_conn_type); +extern void pgstat_initialize(void); +extern void pgstat_bestart(void); +extern void pgstat_initialize_session(void); +extern void pgstat_deinitialize_session(void); +extern void pgstat_couple_decouple_session(bool is_couple); +extern void pgstat_beshutdown_session(int ctrl_index); + +extern const char* pgstat_get_wait_io(WaitEventIO w); +extern void pgstat_report_activity(BackendState state, const char* cmd_str); +extern void pgstat_report_tempfile(size_t filesize); +extern void pgstat_report_memReserved(int4 memReserved, int reserve_or_release); +extern void pgstat_report_statement_wlm_status(); +extern void pgstat_refresh_statement_wlm_time(volatile PgBackendStatus* beentry); +extern void pgstat_report_wait_count(uint32 wait_event_info); +extern void pgstat_report_appname(const char* appname); +extern void pgstat_report_conninfo(const char* conninfo); +extern void pgstat_report_xact_timestamp(TimestampTz tstamp); +extern void pgstat_report_waiting_on_resource(WorkloadManagerEnqueueState waiting); +extern void pgstat_report_queryid(uint64 queryid); +extern void pgstat_report_jobid(uint64 jobid); +extern void pgstat_report_parent_sessionid(uint64 sessionid, uint32 level = 0); +extern void pgstat_report_smpid(uint32 smpid); +extern void pgstat_report_blocksid(void* waitLockThrd, uint64 blockSessionId); +extern bool pgstat_get_waitlock(uint32 wait_event_info); +extern const char* pgstat_get_wait_event(uint32 wait_event_info); +extern const char* pgstat_get_backend_current_activity(ThreadId pid, bool checkUser); +extern const char* pgstat_get_crashed_backend_activity(ThreadId pid, char* buffer, int buflen); + +extern PgStat_TableStatus* find_tabstat_entry(Oid rel_id, uint32 statFlag); +extern PgStat_BackendFunctionEntry* find_funcstat_entry(Oid func_id); +extern void pgstat_initstats(Relation rel); + +extern void pgstat_report_connected_gtm_host(GtmHostIndex gtm_host); +extern void pgstat_report_connected_gtm_timeline(GTM_Timeline gtm_timeline); +extern void pgstat_cancel_invalid_gtm_conn(void); +extern void pgstat_reply_percentile_record_count(); +extern void pgstat_reply_percentile_record(); +extern int pgstat_fetch_sql_rt_info_counter(); +extern void pgstat_fetch_sql_rt_info_internal(SqlRTInfo* sqlrt); +extern void processCalculatePercentile(void); +void pgstat_update_responstime_singlenode(uint64 UniqueSQLId, int64 start_time, int64 rt); +void pgstate_update_percentile_responsetime(void); + +#define IS_PGSTATE_TRACK_UNDEFINE \ + (!u_sess->attr.attr_common.pgstat_track_activities || !t_thrd.shemem_ptr_cxt.MyBEEntry) + +/* + * Simple way, only updates wait status and return the last wait status + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus(WaitState waitstatus, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + WaitState oldwaitstatus; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + pgstat_increment_changecount_before(beentry); + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + oldwaitstatus = beentry->st_waitstatus; + beentry->st_waitstatus = waitstatus; + if (t_thrd.role == THREADPOOL_WORKER) { + t_thrd.threadpool_cxt.worker->m_waitState = waitstatus; + } + + /* If it switches into STATE_POOLER_CREATE_CONN, point to global thread local parameters. */ + if (STATE_POOLER_CREATE_CONN == waitstatus) { + libpq_wait_nodeid = &(beentry->st_libpq_wait_nodeid); + libpq_wait_nodecount = &(beentry->st_libpq_wait_nodecount); + } + + /* If it is restored to STATE_WAIT_UNDEFINED, restore the related parameters. */ + if (STATE_WAIT_UNDEFINED == waitstatus) { + beentry->st_xid = 0; + beentry->st_nodeid = -1; + beentry->st_waitnode_count = 0; + beentry->st_plannodeid = -1; + beentry->st_numnodes = -1; + beentry->st_relname[0] = '\0'; + beentry->st_relname[NAMEDATALEN * 2 - 1] = '\0'; + beentry->st_libpq_wait_nodecount = 0; + beentry->st_libpq_wait_nodeid = InvalidOid; + } + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) { + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + } else if (u_sess->attr.attr_common.enable_instr_track_wait && + (uint32)oldwaitstatus != (uint32)STATE_WAIT_UNDEFINED && waitstatus == STATE_WAIT_UNDEFINED) { + int64 duration = GetCurrentTimestamp() - beentry->waitInfo.status_info.start_time; + UpdateWaitStatusStat(&beentry->waitInfo, (uint32)oldwaitstatus, duration); + beentry->waitInfo.status_info.start_time = 0; + } + + pgstat_increment_changecount_after(beentry); + + return oldStatus; +} + +/* + * For 64-bit xid, report waitstatus and xid, then return the last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_xid(WaitState waitstatus, uint64 xid, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + beentry->st_xid = xid; + + return oldStatus; +} + +/* + * For status related to relation, eg.vacuum, analyze, etc. report waitstatus and relname. + * Then, return the last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_relname(WaitState waitstatus, char* relname, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + int len = 0; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + /* This should be unnecessary if GUC did its job, but be safe */ + if (relname != NULL) { + len = pg_mbcliplen(relname, strlen(relname), NAMEDATALEN * 2 - 1); + } + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + if (relname != NULL) { + errno_t rc = memcpy_s((char*)beentry->st_relname, NAMEDATALEN * 2, relname, len); + securec_check(rc, "\0", "\0"); + + pfree(relname); + relname = NULL; + } + beentry->st_relname[len] = '\0'; + + return oldStatus; +} + +/* + * For wait status with wait node info, update node info and return last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_comm(WaitState waitstatus, int nodeId = -1, int waitnode_count = -1, + int plannodeid = -1, int numnodes = -1, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + beentry->st_nodeid = nodeId; + beentry->st_waitnode_count = waitnode_count; + beentry->st_plannodeid = plannodeid; + beentry->st_numnodes = numnodes; + + return oldStatus; +} + +/* + * For wait status which needs to focus its phase, update phase info and return the last wait phase. + * Note. when isOnlyFetch is flaged true, only fetch last phase. + */ +static inline WaitStatePhase pgstat_report_waitstatus_phase(WaitStatePhase waitstatus_phase, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return PHASE_NONE; + + WaitStatePhase oldPhase = beentry->st_waitstatus_phase; + + if (isOnlyFetch) + return oldPhase; + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus_phase = waitstatus_phase; + return oldPhase; +} + +static inline void pgstat_report_wait_lock_failed(uint32 wait_event_info) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + if (!u_sess->attr.attr_common.pgstat_track_activities || !u_sess->attr.attr_common.enable_instr_track_wait || + !beentry) + return; + pgstat_increment_changecount_before(beentry); + uint32 old_wait_event_info = beentry->st_waitevent; + UpdateWaitEventFaildStat(&beentry->waitInfo, old_wait_event_info); + pgstat_increment_changecount_after(beentry); +} + +/* ---------- + * pgstat_report_waitevent() - + * + * Called from places where server process needs to wait. This is called + * to report wait event information. The wait information is stored + * as 4-bytes where first byte represents the wait event class (type of + * wait, for different types of wait, refer WaitClass) and the next + * 3-bytes represent the actual wait event. Currently 2-bytes are used + * for wait event which is sufficient for current usage, 1-byte is + * reserved for future usage. + * + * ---------- + */ +static inline void pgstat_report_waitevent(uint32 wait_event_info) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return; + + pgstat_increment_changecount_before(beentry); + /* + * Since this is a four-byte field which is always read and written as + * four-bytes, updates are atomic. + */ + uint32 old_wait_event_info = beentry->st_waitevent; + beentry->st_waitevent = wait_event_info; + + if (u_sess->attr.attr_common.enable_instr_track_wait && wait_event_info != WAIT_EVENT_END) { + beentry->waitInfo.event_info.start_time = GetCurrentTimestamp(); + } else if (u_sess->attr.attr_common.enable_instr_track_wait && old_wait_event_info != WAIT_EVENT_END && + wait_event_info == WAIT_EVENT_END) { + int64 duration = GetCurrentTimestamp() - beentry->waitInfo.event_info.start_time; + UpdateWaitEventStat(&beentry->waitInfo, old_wait_event_info, duration); + beentry->waitInfo.event_info.start_time = 0; + beentry->waitInfo.event_info.duration = duration; + } + + pgstat_increment_changecount_after(beentry); +} + +static inline void pgstat_report_waitevent_count(uint32 wait_event_info) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return; + + pgstat_increment_changecount_before(beentry); + /* + * Since this is a four-byte field which is always read and written as + * four-bytes, updates are atomic. + */ + if (u_sess->attr.attr_common.enable_instr_track_wait && wait_event_info != WAIT_EVENT_END) { + beentry->st_waitevent = WAIT_EVENT_END; + UpdateWaitEventStat(&beentry->waitInfo, wait_event_info, 0); + } + + pgstat_increment_changecount_after(beentry); +} + +static inline void pgstat_reset_waitStatePhase(WaitState waitstatus, WaitStatePhase waitstatus_phase) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return; + + beentry->st_waitstatus = waitstatus; + beentry->st_waitstatus_phase = waitstatus_phase; + + beentry->st_xid = 0; + beentry->st_nodeid = -1; + beentry->st_waitnode_count = 0; + beentry->st_plannodeid = -1; + beentry->st_numnodes = -1; + beentry->st_relname[0] = '\0'; + beentry->st_relname[NAMEDATALEN * 2 - 1] = '\0'; + beentry->st_libpq_wait_nodeid = InvalidOid; + beentry->st_libpq_wait_nodecount = 0; +} + +/* nontransactional event counts are simple enough to inline */ +#define pgstat_count_heap_scan(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_numscans++; \ + pgstatCountHeapScan4SessionLevel(); \ + } while (0) +#define pgstat_count_heap_getnext(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_returned++; \ + } while (0) +#define pgstat_count_heap_fetch(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_fetched++; \ + } while (0) +#define pgstat_count_index_scan(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_numscans++; \ + pgstatCountIndexScan4SessionLevel(); \ + } while (0) +#define pgstat_count_index_tuples(rel, n) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \ + } while (0) +#define pgstat_count_buffer_read(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_blocks_fetched++; \ + } while (0) +#define pgstat_count_buffer_hit(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_blocks_hit++; \ + } while (0) +#define pgstat_count_buffer_read_time(n) (u_sess->stat_cxt.pgStatBlockReadTime += (n)) +#define pgstat_count_buffer_write_time(n) (u_sess->stat_cxt.pgStatBlockWriteTime += (n)) + +#define pgstat_count_cu_mem_hit(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_mem_hit++; \ + } while (0) +#define pgstat_count_cu_hdd_sync(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_hdd_sync++; \ + } while (0) +#define pgstat_count_cu_hdd_asyn(rel, n) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_hdd_asyn += (n); \ + } while (0) + +extern void pgstat_count_heap_insert(Relation rel, int n); +extern void pgstat_count_heap_update(Relation rel, bool hot); +extern void pgstat_count_heap_delete(Relation rel); +extern void pgstat_count_truncate(Relation rel); +extern void pgstat_update_heap_dead_tuples(Relation rel, int delta); + +extern void pgstat_count_cu_update(Relation rel, int n); +extern void pgstat_count_cu_delete(Relation rel, int n); + +#define pgstat_count_cu_insert(rel, n) \ + do { \ + pgstat_count_heap_insert(rel, n); \ + } while (0) + +#define pgstat_count_dfs_insert(rel, n) \ + do { \ + pgstat_count_cu_insert(rel, n); \ + } while (0) +#define pgstat_count_dfs_update(rel, n) \ + do { \ + pgstat_count_cu_update(rel, n); \ + } while (0) +#define pgstat_count_dfs_delete(rel, n) \ + do { \ + pgstat_count_cu_delete(rel, n); \ + } while (0) + +extern void pgstat_init_function_usage(FunctionCallInfoData* fcinfo, PgStat_FunctionCallUsage* fcu); +extern void pgstat_end_function_usage(PgStat_FunctionCallUsage* fcu, bool finalize); + +extern void AtEOXact_PgStat(bool isCommit); +extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth); + +extern void AtPrepare_PgStat(void); +extern void PostPrepare_PgStat(void); + +extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void pgstat_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern void pgstat_send_bgwriter(void); + +/* ---------- + * Support functions for the SQL-callable functions to + * generate the pgstat* views. + * ---------- + */ +extern PgStat_StatDBEntry* pgstat_fetch_stat_dbentry(Oid dbid); +extern PgStat_StatTabEntry* pgstat_fetch_stat_tabentry(PgStat_StatTabKey* tabkey); +extern PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry(Oid funcid); +extern PgStat_GlobalStats* pgstat_fetch_global(void); +extern PgStat_WaitCountStatus* pgstat_fetch_waitcount(void); + +extern void pgstat_initstats_partition(Partition part); + +typedef enum StatisticsLevel { + STAT_LEVEL_OFF = 0, + STAT_LEVEL_BASIC, + STAT_LEVEL_TYPICAL, + STAT_LEVEL_ALL +} StatisticsLevel; + +/* Values for stat_view --- order is significant! */ +typedef enum STAT_VIEW { + PV_CONFIG_PARAMETER = 0, + PV_ACTIVITY, + PV_LOCK, + PV_SESSION_STAT, + PV_DB_STAT, + PV_INSTANCE_STAT, + PV_STAT_NAME, + PV_OS_RUN_INFO, + PV_BASIC_LEVEL, /*Above are at basic level,defaut on*/ + + PV_LIGHTWEIGHT_LOCK, + PV_WAIT_TYPE, + PV_SESSION_WAIT, + PV_SESSION_WAIT_SUMMARY, + PV_DB_WAIT_SUMMARY, + PV_INSTANCE_WAIT_SUMMARY, + PV_SESSION_MEMORY_INFO, + PV_SESSION_TIME, + PV_DB_TIME, + PV_INSTANCE_TIME, + PV_REDO_STAT, + PV_TYPICAL_LEVEL, /*Above are at typical level,defaut off*/ + + PV_STATEMENT, + PV_FILE_STAT, + PV_IOSTAT_NETWORK, + PV_SHARE_MEMORY_INFO, + PV_PLAN, + PV_ALL_LEVEL /*Above are at all level,defaut off*/ +} STAT_VIEW; + +// static StatisticsLevel viewLevel[]={ +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, /*Above are at basic level,defaut on*/ +// +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL,/*Above are at typical level,defaut off*/ +// +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL +// }; + +typedef enum OSRunInfoTypes { + /*cpu numbers*/ + NUM_CPUS = 0, + NUM_CPU_CORES, + NUM_CPU_SOCKETS, + + /*cpu times*/ + IDLE_TIME, + BUSY_TIME, + USER_TIME, + SYS_TIME, + IOWAIT_TIME, + NICE_TIME, + + /*avg cpu times*/ + AVG_IDLE_TIME, + AVG_BUSY_TIME, + AVG_USER_TIME, + AVG_SYS_TIME, + AVG_IOWAIT_TIME, + AVG_NICE_TIME, + + /*virtual memory page in/out data*/ + VM_PAGE_IN_BYTES, + VM_PAGE_OUT_BYTES, + + /*os run load*/ + RUNLOAD, + + /*physical memory size*/ + PHYSICAL_MEMORY_BYTES, + + TOTAL_OS_RUN_INFO_TYPES +} OSRunInfoTypes; + +/* + *this is used to represent the numbers of cpu time we should read from file.BUSY_TIME will be + *calculate by USER_TIME plus SYS_TIME,so it wouldn't be counted. + */ +#define NumOfCpuTimeReads (AVG_IDLE_TIME - IDLE_TIME - 1) + +/*the type we restore our collected data. It is a union of all the possible data types of the os run info*/ +typedef union NumericValue { + uint64 int64Value; /*cpu times,vm pgin/pgout size,total memory etc.*/ + float8 float8Value; /*load*/ + uint32 int32Value; /*cpu numbers*/ +} NumericValue; + +/* + *description of the os run info fields. For a particluar field, all the members except got + *are fixed. + */ +typedef struct OSRunInfoDesc { + /*hook to convert our data to Datum type, it decides by the data type the field*/ + Datum (*getDatum)(NumericValue data); + + char* name; /*field name*/ + bool cumulative; /*represent whether the field is cumulative*/ + + /* + *it represent whether we successfully get data of this field. Because some fields may be subject to the + *os platform on which the database is running, or not available in some exception cases. I don't think + *it's a big deal, we just show the infomation we can get. + */ + bool got; + char* comments; /*field comments*/ +} OSRunInfoDesc; + +extern const OSRunInfoDesc osStatDescArrayOrg[TOTAL_OS_RUN_INFO_TYPES]; + +extern int64 getCpuTime(void); +extern int64 JiffiesToSec(uint64); +extern void getCpuNums(void); +extern void getCpuTimes(void); +extern void getVmStat(void); +extern void getTotalMem(void); +extern void getOSRunLoad(void); + +extern Datum Int64GetNumberDatum(NumericValue value); +extern Datum Float8GetNumberDatum(NumericValue value); +extern Datum Int32GetNumberDatum(NumericValue value); + +static inline ssize_t gs_getline(char** lineptr, size_t* n, FILE* stream) +{ + *lineptr = (char*)palloc0(4096); + *n = 4096; + return getline(lineptr, n, stream); +} + +#define SESSION_ID_LEN 32 +extern void getSessionID(char* sessid, pg_time_t startTime, ThreadId Threadid); +extern void getThrdID(char* thrdid, pg_time_t startTime, ThreadId Threadid); + +#define NUM_MOT_SESSION_MEMORY_DETAIL_ELEM 4 + +typedef struct MotSessionMemoryDetail { + ThreadId threadid; + pg_time_t threadStartTime; + int64 totalSize; + int64 freeSize; + int64 usedSize; +} MotSessionMemoryDetail; + +typedef struct MotSessionMemoryDetailPad { + uint32 nelements; + MotSessionMemoryDetail* sessionMemoryDetail; +} MotSessionMemoryDetailPad; + +typedef struct MotMemoryDetail { + int64 numaNode; + int64 reservedMemory; + int64 usedMemory; +} MotMemoryDetail; + +typedef struct MotMemoryDetailPad { + uint32 nelements; + MotMemoryDetail* memoryDetail; +} MotMemoryDetailPad; + +extern MotSessionMemoryDetail* GetMotSessionMemoryDetail(uint32* num); +extern MotMemoryDetail* GetMotMemoryDetail(uint32* num, bool isGlobal); + +#ifdef MEMORY_CONTEXT_CHECKING +typedef enum { STANDARD_DUMP, SHARED_DUMP } DUMP_TYPE; + +extern void DumpMemoryContext(DUMP_TYPE type); +#endif + +extern void getThreadMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc, uint32* procIdx); +extern void getSharedMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc); + +typedef enum TimeInfoType { + DB_TIME = 0, /*total elapsed time while dealing user command.*/ + CPU_TIME, /*total cpu time used while dealing user command.*/ + + /*statistics of specific execution stage.*/ + EXECUTION_TIME, /*total elapsed time of execution stage.*/ + PARSE_TIME, /*total elapsed time of parse stage.*/ + PLAN_TIME, /*total elapsed time of plan stage.*/ + REWRITE_TIME, /*total elapsed time of rewrite stage.*/ + + /*statistics for plpgsql especially*/ + PL_EXECUTION_TIME, /*total elapsed time of plpgsql exection.*/ + PL_COMPILATION_TIME, /*total elapsed time of plpgsql compilation.*/ + + NET_SEND_TIME, + DATA_IO_TIME, + + TOTAL_TIME_INFO_TYPES +} TimeInfoType; + +typedef struct SessionTimeEntry { + /* + *protect the rest part of the entry. + */ + uint32 changeCount; + + bool isActive; + + uint64 sessionid; + pg_time_t myStartTime; + + int64 array[TOTAL_TIME_INFO_TYPES]; +} SessionTimeEntry; + +/* + *this macro is used to read a entry from global array to a local buffer. we use changeCount to + *ensure data consistency. + */ +#define READ_AN_ENTRY(dest, src, changeCount, type) \ + do { \ + for (;;) { \ + uint32 saveChangeCount = changeCount; \ + errno_t rc = 0; \ + rc = memcpy_s(dest, sizeof(type), src, sizeof(type)); \ + securec_check(rc, "\0", "\0"); \ + if ((saveChangeCount & 1) == 0 && saveChangeCount == changeCount) \ + break; \ + CHECK_FOR_INTERRUPTS(); \ + } \ + } while (0) + +#define SessionTimeArraySize (BackendStatusArray_size) + +#define PGSTAT_INIT_TIME_RECORD() int64 startTime = 0; + +#define PGSTAT_START_TIME_RECORD() \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ + startTime = GetCurrentTimestamp(); \ + } while (0) + +#define PGSTAT_END_TIME_RECORD(stage) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ + u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ + } while (0) + +#define PGSTAT_START_PLSQL_TIME_RECORD() \ + do { \ + if (u_sess->stat_cxt.isTopLevelPlSql && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + startTime = GetCurrentTimestamp(); \ + u_sess->stat_cxt.isTopLevelPlSql = false; \ + needRecord = true; \ + } \ + } while (0) + +#define PGSTAT_END_PLSQL_TIME_RECORD(stage) \ + do { \ + if (needRecord == true && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.isTopLevelPlSql = true; \ + } \ + } while (0) + +extern const char* TimeInfoTypeName[TOTAL_TIME_INFO_TYPES]; + +extern Size sessionTimeShmemSize(void); +extern void sessionTimeShmemInit(void); + +extern void timeInfoRecordStart(void); +extern void timeInfoRecordEnd(void); + +extern SessionTimeEntry* getSessionTimeStatus(uint32* num); +extern SessionTimeEntry* getInstanceTimeStatus(); + +typedef struct PgStat_RedoEntry { + PgStat_Counter writes; + PgStat_Counter writeBlks; + PgStat_Counter writeTime; + PgStat_Counter avgIOTime; + PgStat_Counter lstIOTime; + PgStat_Counter minIOTime; + PgStat_Counter maxIOTime; +} PgStat_RedoEntry; + +extern PgStat_RedoEntry redoStatistics; +// extern LWLock* redoStatLock; + +extern void reportRedoWrite(PgStat_Counter blks, PgStat_Counter tim); + +typedef struct PgStat_FileEntry { + int changeCount; + + Oid dbid; + Oid spcid; + Oid fn; + + PgStat_Counter reads; + PgStat_Counter writes; + PgStat_Counter readBlks; + PgStat_Counter readTime; + PgStat_Counter writeBlks; + PgStat_Counter writeTime; + PgStat_Counter avgIOTime; + PgStat_Counter lstIOTime; + PgStat_Counter minIOTime; + PgStat_Counter maxIOTime; +} PgStat_FileEntry; + +#define NUM_FILES 2000 +#define STAT_MSG_BATCH 100 // reduce message frequence by count 100 times. + +extern PgStat_FileEntry pgStatFileArray[NUM_FILES]; +extern uint32 fileStatCount; +extern void reportFileStat(PgStat_MsgFile* msg); + +typedef enum SessionStatisticType { + N_COMMIT_SESSION_LEVEL = 0, + N_ROLLBACK_SESSION_LEVEL, + N_SQL_SESSION_LEVEL, + + N_TABLE_SCAN_SESSION_LEVEL, + + N_BLOCKS_FETCHED_SESSION_LEVEL, + N_PHYSICAL_READ_OPERATION_SESSION_LEVEL, /*it is equal to N_BLOCKS_FETCHED_SESSION_LEVEL now*/ + N_SHARED_BLOCKS_DIRTIED_SESSION_LEVEL, + N_LOCAL_BLOCKS_DIRTIED_SESSION_LEVEL, + N_SHARED_BLOCKS_READ_SESSION_LEVEL, + N_LOCAL_BLOCKS_READ_SESSION_LEVEL, + T_BLOCKS_READ_TIME_SESSION_LEVEL, + T_BLOCKS_WRITE_TIME_SESSION_LEVEL, + + N_SORT_IN_MEMORY_SESSION_LEVEL, + N_SORT_IN_DISK_SESSION_LEVEL, + + N_CU_MEM_HIT, + N_CU_HDD_SYNC_READ, + N_CU_HDD_ASYN_READ, + + N_TOTAL_SESSION_STATISTICS_TYPES +} SessionStatisticType; + +typedef struct SessionLevelStatistic { + pg_time_t sessionStartTime; + uint64 sessionid; + bool isValid; + + PgStat_Counter array[N_TOTAL_SESSION_STATISTICS_TYPES]; +} SessionLevelStatistic; + +#define SessionStatArraySize (BackendStatusArray_size) + +#define pgstatCountTransactionCommit4SessionLevel(isCommit) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + if (isCommit) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_COMMIT_SESSION_LEVEL]++; \ + } else { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_ROLLBACK_SESSION_LEVEL]++; \ + } \ + } \ + } while (0) + +#define pgstatCountSQL4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SQL_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountIndexScan4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_TABLE_SCAN_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountHeapScan4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_TABLE_SCAN_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountBlocksFetched4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_BLOCKS_FETCHED_SESSION_LEVEL]++; \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_PHYSICAL_READ_OPERATION_SESSION_LEVEL]++; \ + } \ + } while (0) + +#define pgstatCountSharedBlocksDirtied4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SHARED_BLOCKS_DIRTIED_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountLocalBlocksDirtied4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_LOCAL_BLOCKS_DIRTIED_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountSharedBlocksRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SHARED_BLOCKS_READ_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountLocalBlocksRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_LOCAL_BLOCKS_READ_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountBlocksReadTime4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[T_BLOCKS_READ_TIME_SESSION_LEVEL] += value; \ + } while (0) + +#define pgstatCountBlocksWriteTime4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[T_BLOCKS_WRITE_TIME_SESSION_LEVEL] += value; \ + } while (0) + +#define pgstatCountSort4SessionLevel(isSortInMemory) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + if (isSortInMemory) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SORT_IN_MEMORY_SESSION_LEVEL]++; \ + } else { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SORT_IN_DISK_SESSION_LEVEL]++; \ + } \ + } \ + } while (0) + +#define pgstatCountCUMemHit4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_MEM_HIT]++; \ + } while (0) + +#define pgstatCountCUHDDSyncRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_HDD_SYNC_READ]++; \ + } while (0) + +#define pgstatCountCUHDDAsynRead4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_HDD_ASYN_READ] += (value); \ + } while (0) + +extern void DumpLWLockInfoToServerLog(void); +extern SessionLevelStatistic* getSessionStatistics(uint32* num); +extern Size sessionStatShmemSize(void); +extern void sessionStatShmemInit(void); + +#define NUM_BUFFERCACHE_PAGES_ELEM 9 + +#define CONNECTIONINFO_LEN 8192 /* Maximum length of GUC parameter connection_info */ + +/* + * Record structure holding the to-be-exposed cache data. + */ +typedef struct { + uint32 bufferid; + Oid relfilenode; + int2 bucketnode; + Oid reltablespace; + Oid reldatabase; + ForkNumber forknum; + BlockNumber blocknum; + bool isvalid; + bool isdirty; + uint16 usagecount; +} BufferCachePagesRec; + +/* + * Function context for data persisting over repeated calls. + */ +typedef struct { + TupleDesc tupdesc; + BufferCachePagesRec* record; +} BufferCachePagesContext; + +/* Function context for table distribution over repeated calls. */ +typedef struct TableDistributionInfo { + ParallelFunctionState* state; + TupleTableSlot* slot; +} TableDistributionInfo; + +typedef struct SessionLevelMemory { + pg_time_t threadStartTime; /* thread start time */ + uint64 sessionid; /* session id */ + bool isValid; /* is valid */ + bool iscomplex; /* is complex query */ + + int initMemInChunks; /* initialize memory */ + int queryMemInChunks; /* query used memory */ + int peakChunksQuery; /* peak memory */ + + int spillCount; /* dn spill count */ + int64 spillSize; /* dn spill size */ + int64 broadcastSize; /* broadcast size */ + int64 estimate_time; /* estimate total time */ + int estimate_memory; /* estimate total memory, unit is MB */ + uint32 warning; /* warning info */ + char* query_plan_issue; /* query plan warning info */ + char* query_plan; /* query plan */ + TimestampTz dnStartTime; /* start time on dn */ + TimestampTz dnEndTime; /* end time on dn */ + uint64 plan_size; +} SessionLevelMemory; + +extern SessionLevelMemory* getSessionMemory(uint32* num); +extern Size sessionMemoryShmemSize(void); +extern void sessionMemoryShmemInit(void); + +extern int pgstat_get_current_active_numbackends(void); +extern PgBackendStatus* pgstat_get_backend_single_entry(ThreadId tid); +extern void pgstat_increase_session_spill(); +extern void pgstat_increase_session_spill_size(int64 size); +extern void pgstat_add_warning_early_spill(); +extern void pgstat_add_warning_spill_on_memory_spread(); +extern void pgstat_add_warning_hash_conflict(); +extern void pgstat_set_io_state(WorkloadManagerIOState iostate); +extern void pgstat_set_stmt_tag(WorkloadManagerStmtTag stmttag); +extern ThreadId* pgstat_get_user_io_entry(Oid userid, int* num); +extern ThreadId* pgstat_get_stmttag_write_entry(int* num); +extern List* pgstat_get_user_backend_entry(Oid userid); +extern void pgstat_reset_current_status(void); +extern WaitInfo* read_current_instr_wait_info(void); +extern TableDistributionInfo* getTableDataDistribution( + TupleDesc tuple_desc, char* schema_name = NULL, char* table_name = NULL); +extern TableDistributionInfo* getTableStat( + TupleDesc tuple_desc, int dirty_pecent, int n_tuples, char* schema_name = NULL); +extern TableDistributionInfo* get_remote_stat_pagewriter(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_ckpt(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_bgwriter(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_single_flush_dw_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_double_write(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_redo(TupleDesc tuple_desc); +extern TableDistributionInfo* get_rto_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_recovery_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_node_xid_csn(TupleDesc tuple_desc); + +#define SessionMemoryArraySize (BackendStatusArray_size) + +/* Code Area for LWLock deadlock monitor */ + +#define CHANGECOUNT_IS_EVEN(_x) (((_x)&1) == 0) + +typedef struct { + ThreadId thread_id; + uint64 st_sessionid; +} lock_entry_id; + +typedef struct { + /* thread id for backend */ + lock_entry_id entry_id; + /* light weight change count */ + int lw_count; +} lwm_light_detect; + +typedef struct { + lock_entry_id holder_tid; + LWLockMode lock_sx; +} holding_lockmode; + +typedef struct { + lock_entry_id be_tid; /* thread id */ + int be_idx; /* backend position */ + LWLockAddr want_lwlock; /* lock to acquire */ + int lwlocks_num; /* number of locks held */ + lwlock_id_mode* held_lwlocks; /* held lwlocks */ +} lwm_lwlocks; + +typedef struct FileIOStat { + unsigned int changeCount; + PgStat_Counter reads; /* read count of file */ + PgStat_Counter writes; /* write count of file */ + PgStat_Counter readBlks; /* num of read blocks */ + PgStat_Counter writeBlks; /* num of write blocks */ +} FileIOStat; + +extern lwm_light_detect* pgstat_read_light_detect(void); +extern lwm_lwlocks* pgstat_read_diagnosis_data( + lwm_light_detect* light_det, const int* candidates_idx, int num_candidates); +extern TimestampTz pgstat_read_xact_start_tm(int be_index); + +extern THR_LOCAL HTAB* analyzeCheckHash; +extern void pgstat_read_analyzed(); +typedef struct PgStat_AnaCheckEntry { + Oid tableid; + bool is_analyzed; +} PgStat_AnaCheckEntry; + +extern HTAB* global_bad_block_stat; +extern void initLocalBadBlockStat(); +extern void addBadBlockStat(const RelFileNode* relfilenode, ForkNumber forknum); +extern void resetBadBlockStat(); + +extern bool CalcSQLRowStatCounter( + PgStat_TableCounts* last_total_counter, PgStat_TableCounts* current_sql_table_counter); +extern void GetCurrentTotalTableCounter(PgStat_TableCounts* total_table_counter); + +typedef struct XLogStatCollect { + double entryScanTime; + double IOTime; + double memsetTime; + double entryUpdateTime; + uint64 writeBytes; + uint64 scanEntryCount; + uint64 writeSomethingCount; + uint64 flushWaitCount; + double xlogFlushWaitTime; + uint32 walAuxWakeNum; + XLogRecPtr writeRqstPtr; + XLogRecPtr minCopiedPtr; + double IONotificationTime; + double sendBufferTime; + double memsetNotificationTime; + uint32 remoteFlushWaitCount; +} XLogStatCollect; + +extern THR_LOCAL XLogStatCollect *g_xlog_stat_shared; + +extern void XLogStatShmemInit(void); +extern Size XLogStatShmemSize(void); +extern bool CheckUserExist(Oid userId, bool removeCount); +extern PgBackendStatusNode* gs_stat_read_current_status(uint32* maxCalls); +extern void pgstat_setup_memcxt(void); +extern PgBackendStatus* gs_stat_fetch_stat_beentry(int32 beid); +extern void pgstat_send(void* msg, int len); + +typedef struct PgStat_NgMemSize { + int* ngmemsize; + char** ngname; + uint32 cnti; + uint32 cntj; + uint32 allcnt; +} PgStat_NgMemSize; + +typedef enum NetInfoType { + NET_SEND_TIMES, + NET_SEND_N_CALLS, + NET_SEND_SIZE, + + NET_RECV_TIMES, + NET_RECV_N_CALLS, + NET_RECV_SIZE, + + NET_STREAM_SEND_TIMES, + NET_STREAM_SEND_N_CALLS, + NET_STREAM_SEND_SIZE, + + NET_STREAM_RECV_TIMES, + NET_STREAM_RECV_N_CALLS, + NET_STREAM_RECV_SIZE, + + TOTAL_NET_INFO_TYPES +} NetInfoType; + +#define END_NET_SEND_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_SEND_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_SEND_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_STREAM_SEND_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_RECV_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_RECV_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_RECV_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_STREAM_RECV_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_SIZE] += str_len; \ + } \ + } while (0) + +#endif /* PGSTAT_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgtime.h postgresql-hll-2.14/include/include/pgtime.h --- postgresql-hll-2.14_old/include/include/pgtime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgtime.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pgtime.h + * PostgreSQL internal timezone library + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/pgtime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PGTIME_H +#define _PGTIME_H + +#include "gs_threadlocal.h" + +/* + * The API of this library is generally similar to the corresponding + * C library functions, except that we use pg_time_t which (we hope) is + * 64 bits wide, and which is most definitely signed not unsigned. + */ + +typedef int64 pg_time_t; + +struct pg_tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; /* origin 0, not 1 */ + int tm_year; /* relative to 1900 */ + int tm_wday; + int tm_yday; + int tm_isdst; + long int tm_gmtoff; + const char* tm_zone; +}; + +typedef struct pg_tz pg_tz; +typedef struct pg_tzenum pg_tzenum; + +/* Maximum length of a timezone name (not including trailing null) */ +#define TZ_STRLEN_MAX 255 + +/* these functions are in localtime.c */ + +extern struct pg_tm* pg_localtime(const pg_time_t* timep, const pg_tz* tz); +extern struct pg_tm* pg_gmtime(const pg_time_t* timep); +extern int pg_next_dst_boundary(const pg_time_t* timep, long int* before_gmtoff, int* before_isdst, pg_time_t* boundary, + long int* after_gmtoff, int* after_isdst, const pg_tz* tz); +extern size_t pg_strftime(char* s, size_t max, const char* format, const struct pg_tm* tm); + +extern bool pg_get_timezone_offset(const pg_tz* tz, long int* gmtoff); +extern const char* pg_get_timezone_name(pg_tz* tz); +extern const char* pg_get_abbrevs_name(pg_time_t* timep, pg_tz* tz); + +extern bool pg_tz_acceptable(pg_tz* tz); + +/* these functions and variables are in pgtz.c */ + +extern THR_LOCAL pg_tz* session_timezone; +extern THR_LOCAL pg_tz* log_timezone; + +extern void pg_timezone_initialize(void); +extern pg_tz* pg_tzset(const char* tzname); + +extern pg_tzenum* pg_tzenumerate_start(void); +extern pg_tz* pg_tzenumerate_next(pg_tzenum* dir); +extern void pg_tzenumerate_end(pg_tzenum* dir); + +#endif /* _PGTIME_H */ diff -uprN postgresql-hll-2.14_old/include/include/pg_trace.h postgresql-hll-2.14/include/include/pg_trace.h --- postgresql-hll-2.14_old/include/include/pg_trace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pg_trace.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,17 @@ +/* ---------- + * pg_trace.h + * + * Definitions for the PostgreSQL tracing framework + * + * Copyright (c) 2006-2012, PostgreSQL Global Development Group + * + * src/include/pg_trace.h + * ---------- + */ + +#ifndef PG_TRACE_H +#define PG_TRACE_H + +#include "utils/probes.h" /* pgrminclude ignore */ + +#endif /* PG_TRACE_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/barrier.h postgresql-hll-2.14/include/include/pgxc/barrier.h --- postgresql-hll-2.14_old/include/include/pgxc/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/barrier.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * + * Definitions for the PITR barrier handling + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/barrier.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef XC_BARRIER_H +#define XC_BARRIER_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +#define CREATE_BARRIER_PREPARE 'P' +#define CREATE_BARRIER_EXECUTE 'X' +#define CREATE_BARRIER_END 'E' + +#define CREATE_BARRIER_PREPARE_DONE 'p' +#define CREATE_BARRIER_EXECUTE_DONE 'x' + +#define BARRIER_LSN_FILE "barrier_lsn" +#define BARRIER_LSN_FILE_LENGTH 17 + +#define XLOG_BARRIER_CREATE 0x00 + +extern void ProcessCreateBarrierPrepare(const char* id); +extern void ProcessCreateBarrierEnd(const char* id); +extern void ProcessCreateBarrierExecute(const char* id); + +extern void RequestBarrier(const char* id, char* completionTag); +extern void barrier_redo(XLogReaderState* record); +extern void barrier_desc(StringInfo buf, XLogReaderState* record); +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/bucketmap.h postgresql-hll-2.14/include/include/pgxc/bucketmap.h --- postgresql-hll-2.14_old/include/include/pgxc/bucketmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/bucketmap.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,35 @@ +#ifndef BUCKETMAP_H +#define BUCKETMAP_H + +#include "c.h" + +#include "access/htup.h" +#include "nodes/parsenodes.h" +#include "storage/itemptr.h" +#include "utils/relcache.h" + +/* + * The element data structure of bucketmap cache, where store the bucketmap that + * palloc-ed form t_thrd.top_mem_cxt, it is created on its first being used + */ +typedef struct BucketMapCache { + /* Search key of bucketmap cache */ + Oid groupoid; + ItemPointerData ctid; + char* groupname; + + /* bucketmap content, palloc()-ed form top memory context */ + uint2* bucketmap; +} NodeGroupBucketMap; + +#define BUCKET_MAP_SIZE 32 +#define BUCKETMAP_MODE_DEFAULT 0 +#define BUCKETMAP_MODE_REMAP 1 + +extern void GenerateConsistentHashBucketmap(CreateGroupStmt* stmt, oidvector* nodes_array, + Relation pgxc_group_rel, HeapTuple tuple, uint2* bucket_ptr, int bucketmap_mode); +extern void BucketMapCacheRemoveEntry(Oid groupoid); +extern char* GetBucketString(uint2* bucket_ptr); +extern void PgxcCopyBucketsFromNew(const char* group_name, const char* src_group_name); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/copyops.h postgresql-hll-2.14/include/include/pgxc/copyops.h --- postgresql-hll-2.14_old/include/include/pgxc/copyops.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/copyops.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,27 @@ +/* -------------------------------------------------------------------------- + * + * copyops.h + * Routines for manipulation of remote COPY data + * + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/copyops.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef COPYOPS_H +#define COPYOPS_H + +#include "access/tupdesc.h" + +/* Type of data delimiter used for data redistribution using remote COPY */ +#define COPYOPS_DELIMITER '\t' + +extern char** CopyOps_RawDataToArrayField(TupleDesc tupdesc, char* message, int len); +extern char* CopyOps_BuildOneRowTo(TupleDesc tupdesc, Datum* values, const bool* nulls, int* len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/csnminsync.h postgresql-hll-2.14/include/include/pgxc/csnminsync.h --- postgresql-hll-2.14_old/include/include/pgxc/csnminsync.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/csnminsync.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------- + * + * csnminsync.h + * Synchronize the global min csn between all nodes, head file + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/pgxc/csnminsync.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef CSNMINSYNC_H +#define CSNMINSYNC_H + +#define DEFAULT_CLEANUP_TIME 50000 + +extern void csnminsync_main(void); +extern void csnminsync_thread_shutdown(void); + +#endif /* CSNMINSYNC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/pgxc/execRemote.h postgresql-hll-2.14/include/include/pgxc/execRemote.h --- postgresql-hll-2.14_old/include/include/pgxc/execRemote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/execRemote.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,269 @@ +/* ------------------------------------------------------------------------- + * + * execRemote.h + * + * Functions to execute commands on multiple Datanodes + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/execRemote.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef EXECREMOTE_H +#define EXECREMOTE_H +#include "locator.h" +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "access/tupdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "nodes/pg_list.h" +#include "optimizer/pgxcplan.h" +#include "pgxc/remoteCombiner.h" +#include "tcop/dest.h" +#include "tcop/pquery.h" +#include "tcop/utility.h" +#include "utils/lsyscache.h" +#include "utils/snapshot.h" +#include "utils/rowstore.h" + +#define LPROXY_CONTINUE 0 +#define LPROXY_FINISH 1 +#define LPROXY_ERROR 2 + +/* Outputs of handle_response() */ +#define RESPONSE_EOF EOF +#define RESPONSE_COMPLETE 0 +#define RESPONSE_SUSPENDED 1 +#define RESPONSE_TUPDESC 2 +#define RESPONSE_DATAROW 3 +#define RESPONSE_COPY 4 +#define RESPONSE_BARRIER_OK 5 +#define RESPONSE_PLANID_OK 6 +#define RESPONSE_ANALYZE_ROWCNT 7 + +#define REMOTE_CHECKMSG_LEN 8 /* it equals to the count of bytes added in AddCheckMessage when is_stream is false */ +#define STREAM_CHECKMSG_LEN 20 /* it equals to the count of bytes added in AddCheckMessage when is_stream is true */ + +/* with-recursive added messages */ +#define RESPONSE_RECURSIVE_SYNC_R 98 +#define RESPONSE_RECURSIVE_SYNC_F 99 + +#ifdef WIN32 +#define SOCK_ERRNO (WSAGetLastError()) +#define SOCK_STRERROR winsock_strerror +#define SOCK_ERRNO_SET(e) WSASetLastError(e) +#else +#define SOCK_ERRNO errno +#define SOCK_STRERROR pqStrerror +#define SOCK_ERRNO_SET(e) (errno = (e)) +#endif + +#define ERROR_CHECK_TIMEOUT 3 /* time out for checking some normal communication error(s) */ + +/* Add Skewness alarm retry count in case something fails. default 2*/ +#define ALARM_RETRY_COUNT 2 + +/* Combines results of INSERT statements using multiple values */ +typedef struct CombineTag { + CmdType cmdType; /* DML command type */ + char data[COMPLETION_TAG_BUFSIZE]; /* execution result combination data */ +} CombineTag; + +typedef void (*xact_callback)(bool isCommit, const void* args); +typedef void (*strategy_func)(ParallelFunctionState*); + +typedef enum RemoteXactNodeStatus { + RXACT_NODE_NONE, /* Initial state */ + RXACT_NODE_PREPARE_SENT, /* PREPARE request sent */ + RXACT_NODE_PREPARE_FAILED, /* PREPARE failed on the node */ + RXACT_NODE_PREPARED, /* PREPARED successfully on the node */ + RXACT_NODE_COMMIT_SENT, /* COMMIT sent successfully */ + RXACT_NODE_COMMIT_FAILED, /* failed to COMMIT on the node */ + RXACT_NODE_COMMITTED, /* COMMITTed successfully on the node */ + RXACT_NODE_ABORT_SENT, /* ABORT sent successfully */ + RXACT_NODE_ABORT_FAILED, /* failed to ABORT on the node */ + RXACT_NODE_ABORTED /* ABORTed successfully on the node */ +} RemoteXactNodeStatus; + +typedef enum RemoteXactStatus { + RXACT_NONE, /* Initial state */ + RXACT_PREPARE_FAILED, /* PREPARE failed */ + RXACT_PREPARED, /* PREPARED succeeded on all nodes */ + RXACT_COMMIT_FAILED, /* COMMIT failed on all the nodes */ + RXACT_PART_COMMITTED, /* COMMIT failed on some and succeeded on other nodes */ + RXACT_COMMITTED, /* COMMIT succeeded on all the nodes */ + RXACT_ABORT_FAILED, /* ABORT failed on all the nodes */ + RXACT_PART_ABORTED, /* ABORT failed on some and succeeded on other nodes */ + RXACT_ABORTED /* ABORT succeeded on all the nodes */ +} RemoteXactStatus; + +typedef struct RemoteXactState { + /* Current status of the remote 2PC */ + RemoteXactStatus status; + + /* + * Information about all the nodes involved in the transaction. We track + * the number of writers and readers. The first numWriteRemoteNodes entries + * in the remoteNodeHandles and remoteNodeStatus correspond to the writer + * connections and rest correspond to the reader connections. + */ + int numWriteRemoteNodes; + int numReadRemoteNodes; + int maxRemoteNodes; + PGXCNodeHandle** remoteNodeHandles; + RemoteXactNodeStatus* remoteNodeStatus; + + bool preparedLocalNode; + bool need_primary_dn_commit; + char prepareGID[256]; /* GID used for internal 2PC */ +} RemoteXactState; + +#ifdef PGXC +typedef struct abort_callback_type { + xact_callback function; + void* fparams; +} abort_callback_type; +#endif + +static inline char* GetIndexNameForStat(Oid indid, char* relname) +{ + char* indname = get_rel_name(indid); + if (indname == NULL) { + ereport(LOG, + (errmsg("Analyze can not get index name by index id %u on table %s and will skip this index.", + indid, relname))); + } + return indname; +} + +/* Copy command just involves Datanodes */ +extern PGXCNodeHandle** DataNodeCopyBegin(const char* query, List* nodelist, Snapshot snapshot); +extern int DataNodeCopyIn(const char* data_row, int len, const char* eol, ExecNodes* exec_nodes, + PGXCNodeHandle** copy_connections, bool is_binary = false); +extern uint64 DataNodeCopyOut(ExecNodes* exec_nodes, PGXCNodeHandle** copy_connections, TupleDesc tupleDesc, + FILE* copy_file, Tuplestorestate* store, RemoteCopyType remoteCopyType); +extern void DataNodeCopyFinish(PGXCNodeHandle** copy_connections, int n_copy_connections, int primary_dn_index, + CombineType combine_type, Relation rel); +extern bool DataNodeCopyEnd(PGXCNodeHandle* handle, bool is_error); +extern int DataNodeCopyInBinaryForAll(const char* msg_buf, int len, PGXCNodeHandle** copy_connections); + +extern int ExecCountSlotsRemoteQuery(RemoteQuery* node); +extern RemoteQueryState* ExecInitRemoteQuery(RemoteQuery* node, EState* estate, int eflags, bool row_plan = true); +extern TupleTableSlot* ExecRemoteQuery(RemoteQueryState* step); +extern void ExecEndRemoteQuery(RemoteQueryState* step, bool pre_end = false); +extern void FreeParallelFunctionState(ParallelFunctionState* state); +extern void StrategyFuncSum(ParallelFunctionState* state); +extern ParallelFunctionState* RemoteFunctionResultHandler(char* sql_statement, ExecNodes* exec_nodes, + strategy_func function, bool read_only = true, RemoteQueryExecType exec_type = EXEC_ON_DATANODES, + bool non_check_count = false, bool need_tran_block = false, bool need_transform_anyarray = false, + bool active_nodes_only = false); +extern void ExecRemoteUtility(RemoteQuery* node); + +extern void ExecRemoteUtility_ParallelDDLMode(RemoteQuery* node, const char* FirstExecNode); +extern RemoteQueryState* CreateResponseCombinerForBarrier(int nodeCount, CombineType combineType); +extern void CloseCombinerForBarrier(RemoteQueryState* combiner); + +extern HeapTuple* ExecRemoteUtilityWithResults( + VacuumStmt* stmt, RemoteQuery* node, ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); + +extern HeapTuple* RecvRemoteSampleMessage( + VacuumStmt* stmt, RemoteQuery* node, ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); +extern int handle_response(PGXCNodeHandle* conn, RemoteQueryState* combiner, bool isdummy = false); +extern bool is_data_node_ready(PGXCNodeHandle* conn); +extern void HandleCmdComplete(CmdType commandType, CombineTag* combine, const char* msg_body, size_t len); +extern bool FetchTuple( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate = NULL); +extern bool FetchTupleSimple(RemoteQueryState* combiner, TupleTableSlot* slot); +template +extern bool FetchTupleByMultiChannel( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate = NULL); +extern bool FetchBatch(RemoteQueryState* combiner, VectorBatch* batch); + +extern void BufferConnection(PGXCNodeHandle* conn, bool cachedata = true); + +extern void ExecRemoteQueryReScan(RemoteQueryState* node, ExprContext* exprCtxt); + +extern void SetDataRowForExtParams(ParamListInfo params, RemoteQueryState* rq_state); + +extern void ExecCloseRemoteStatement(const char* stmt_name, List* nodelist); + +/* Flags related to temporary objects included in query */ +extern void ExecSetTempObjectIncluded(void); +extern bool ExecIsTempObjectIncluded(void); +extern TupleTableSlot* ExecProcNodeDMLInXC(EState* estate, TupleTableSlot* sourceDataSlot, TupleTableSlot* newDataSlot); + +extern void pgxc_all_success_nodes(ExecNodes** d_nodes, ExecNodes** c_nodes, char** failednodes_msg); +extern int PackConnections(RemoteQueryState* node); +extern void AtEOXact_DBCleanup(bool isCommit); + +extern void set_dbcleanup_callback(xact_callback function, const void* paraminfo, int paraminfo_size); + +extern void do_query(RemoteQueryState* node, bool vectorized = false); +extern bool do_query_for_planrouter(RemoteQueryState* node, bool vectorized = false); +extern void do_query_for_scangather(RemoteQueryState* node, bool vectorized = false); +extern void do_query_for_first_tuple(RemoteQueryState* node, bool vectorized, int regular_conn_count, + PGXCNodeHandle** connections, PGXCNodeHandle* primaryconnection, List* dummy_connections); + +extern void free_RemoteXactState(void); +extern char* repairObjectName(const char* relname); +extern char* repairTempNamespaceName(char* schemaname); + +extern void pgxc_node_report_error(RemoteQueryState* combiner, int elevel = 0); +extern void setSocketError(const char*, const char*); +extern char* getSocketError(int* errcode); +extern int getStreamSocketError(const char* str); + +extern int FetchStatistics4WLM(const char* sql, void* info, Size size, strategy_func func); +extern void FetchGlobalStatistics(VacuumStmt* stmt, Oid relid, RangeVar* parentRel, bool isReplication = false); + +extern bool IsInheritor(Oid relid); +extern Tuplesortstate* tuplesort_begin_merge(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, void* combiner, int workMem); + +extern void pgxc_node_remote_savepoint( + const char* cmdString, RemoteQueryExecType exec_type, bool bNeedXid, bool bNeedBegin, + GlobalTransactionId transactionId = InvalidTransactionId); +extern bool pgxc_start_command_on_connection(PGXCNodeHandle* connection, RemoteQueryState* remotestate, + Snapshot snapshot, const char* compressPlan = NULL, int cLen = 0); +extern PGXCNodeAllHandles* connect_compute_pool(int srvtype); +extern char* generate_begin_command(void); +extern PGXCNodeAllHandles* get_exec_connections( + RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); +extern void send_local_csn_min_to_ccn(); +extern void csnminsync_get_global_csn_min(int conn_count, PGXCNodeHandle** connections); +extern void SendPGXCNodeCommitCsn(uint64 commit_csn); +extern void NotifyDNSetCSN2CommitInProgress(); +extern void AssembleDataRow(StreamState* node); +extern bool isInLargeUpgrade(); +extern uint64 get_datasize(Plan* plan, int srvtype, int* filenum); +extern void report_table_skewness_alarm(AlarmType alarmType, const char* tableName); +extern bool InternalDoQueryForPlanrouter(RemoteQueryState* node, bool vectorized); +extern List* TryGetNeededDNNum(uint64 dnneeded); +extern List* GetDnlistForHdfs(int fnum); +extern void MakeNewSpiltmap(Plan* plan, SplitMap* map); +extern List* ReassignSplitmap(Plan* plan, int dn_num); +extern int ComputeNodeBegin(int conn_count, PGXCNodeHandle** connections, GlobalTransactionId gxid); +extern void sendQuery(const char* sql, const PGXCNodeAllHandles* pgxc_handles, + int conn_count, bool isCoordinator, + RemoteQueryState* remotestate, const Snapshot snapshot); + +StringInfo* SendExplainToDNs(ExplainState*, RemoteQuery*, int*, const char*); +bool CheckPrepared(RemoteQuery* rq, Oid nodeoid); +void FindExecNodesInPBE(RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); +#endif + +#ifdef ENABLE_UT +#include "workload/cpwlm.h" +extern THR_LOCAL List* XactWriteNodes; +extern THR_LOCAL List* XactReadNodes; +extern PGXCNodeAllHandles* connect_compute_pool_for_HDFS(); +extern PGXCNodeAllHandles* make_cp_conn(ComputePoolConfig** configs, int cnum, int srvtype, const char* dbname); +extern List* get_dnlist_for_hdfs(int fnum); +extern void ReloadTransactionNodes(void); +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/globalStatistic.h postgresql-hll-2.14/include/include/pgxc/globalStatistic.h --- postgresql-hll-2.14_old/include/include/pgxc/globalStatistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/globalStatistic.h 2020-12-12 17:06:43.247348038 +0800 @@ -0,0 +1,18 @@ + +#ifndef GLOBAL_STAISTTIC_H +#define GLOBAL_STAISTTIC_H + +typedef enum StatisticKind { + StatisticNone, + StatisticPageAndTuple, + StatisticHistogram, + StatisticMultiHistogram, + StatisticPartitionPageAndTuple +} StatisticKind; + +extern char* construct_fetch_statistics_query(const char* schemaname, const char* relname, List* va_cols, + StatisticKind kind, VacuumStmt* stmt, Oid relid, RangeVar* parentRel); +extern void FetchGlobalStatisticsFromCN(int cn_conn_count, PGXCNodeHandle** pgxc_connections, + RemoteQueryState* remotestate, StatisticKind kind, VacuumStmt* stmt, Oid relid, PGFDWTableAnalyze* info); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/groupmgr.h postgresql-hll-2.14/include/include/pgxc/groupmgr.h --- postgresql-hll-2.14_old/include/include/pgxc/groupmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/groupmgr.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * groupmgr.h + * Routines for PGXC node group management + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/groupmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GROUPMGR_H +#define GROUPMGR_H + +#include "c.h" +#include "nodes/parsenodes.h" + +typedef struct nodeinfo { + Oid node_id; + uint2 old_node_index; + uint2 new_node_index; + int old_buckets_num; +#ifdef USE_ASSERT_CHECKING + int new_buckets_num; +#endif + bool deleted; +} nodeinfo; + +/* installation mode for storage node group */ +#define INSTALLATION_MODE "installation" + +#define BUCKETMAPLEN_CONFIG_NAME "buckets_len" +#define MIN_BUCKETMAPLEN 32 +#define MAX_BUCKETMAPLEN 16384 +#define CHAR_BUF_SIZE 512 + +extern void PgxcGroupCreate(CreateGroupStmt* stmt); +extern void PgxcGroupAlter(AlterGroupStmt* stmt); +extern void PgxcGroupRemove(DropGroupStmt* stmt); +extern char* PgxcGroupGetInstallationGroup(); +extern char* PgxcGroupGetInRedistributionGroup(); +extern char* PgxcGroupGetCurrentLogicCluster(); +extern Oid PgxcGroupGetRedistDestGroupOid(); +extern char* PgxcGroupGetStmtExecGroupInRedis(); +extern bool CanPgxcGroupRemove(Oid group_oid, bool ignore_pmk = false); +extern int GetTableCountByDatabase(const char* database_name, char* query); +extern bool GetExecnodeIsInstallationGroup(Oid groupoid); +extern void InitNodeGroupStatus(void); +extern void CleanNodeGroupStatus(void); +extern List* GetNodeGroupOidCompute(Oid role_id); +extern uint2* GetBucketMapByGroupName(const char* groupname); +extern char* DeduceGroupByNodeList(Oid* nodeoids, int numnodes); +extern void PgxcGroupAddNode(Oid group_oid, Oid nodeid); +extern void PgxcGroupRemoveNode(Oid group_oid, Oid nodeid); +extern bool IsNodeInLogicCluster(Oid* oid_array, int count, Oid excluded); +extern bool IsLogicClusterRedistributed(const char* group_name); +extern char* PgxcGroupGetFirstLogicCluster(); +extern bool PgxcGroup_Resizing(); +extern oidvector* GetGroupMemberRef(HeapTuple tup, bool* need_free); +extern char GetGroupKind(HeapTuple tup); + +/* Routines for bucketmap cache */ +extern uint2* BucketMapCacheGetBucketmap(Oid groupoid); +extern uint2* BucketMapCacheGetBucketmap(const char* groupname); +extern void BucketMapCacheDestroy(void); + +extern int GsGlobalConfigGetBucketMapLen(void); +extern void CheckBucketMapLenValid(void); + +#endif /* GROUPMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/groupnodes.h postgresql-hll-2.14/include/include/pgxc/groupnodes.h --- postgresql-hll-2.14_old/include/include/pgxc/groupnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/groupnodes.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,18 @@ +#ifndef GROUP_NODES_H +#define GROUP_NODES_H + +#include "c.h" +#include "pgxc/locator.h" + +extern oidvector* exclude_nodes(oidvector* nodes, oidvector* excluded); +extern bool oidvector_eq(oidvector* oid1, oidvector* oid2); +extern oidvector* oidvector_add(oidvector* nodes, oidvector* added); +extern oidvector* oidvector_remove(oidvector* nodes, oidvector* removed); +extern ExecNodes* create_exec_nodes(oidvector* gmember); +extern void delete_exec_nodes(ExecNodes* exec_nodes); +extern oidvector* get_group_member(Oid group_oid); +extern void PgxcOpenGroupRelation(Relation* pgxc_group_rel); +extern void PgxcChangeGroupMember(Oid group_oid, oidvector* gmember); +extern bool PgxcGroupResizing(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/groupredis.h postgresql-hll-2.14/include/include/pgxc/groupredis.h --- postgresql-hll-2.14_old/include/include/pgxc/groupredis.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/groupredis.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,13 @@ +#ifndef GROUP_REDIS_H +#define GROUP_REDIS_H + +#include "c.h" + +extern void PgxcChangeRedistribution(Oid group_oid, char in_redistribution); +extern oidvector* PgxcGetRedisNodes(Relation rel, char redist_kind); +extern void PgxcUpdateRedistSrcGroup(Relation rel, oidvector* gmember, + text* bucket_str, char* group_name); +extern void PgxcGroupResize(const char* src_group_name, const char* dest_group_name); +extern void PgxcGroupResizeComplete(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/locator.h postgresql-hll-2.14/include/include/pgxc/locator.h --- postgresql-hll-2.14_old/include/include/pgxc/locator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/locator.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,247 @@ +/* ------------------------------------------------------------------------- + * + * locator.h + * Externally declared locator functions + * + * + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/locator.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCATOR_H +#define LOCATOR_H + +#define LOCATOR_TYPE_REPLICATED 'R' +#define LOCATOR_TYPE_HASH 'H' +#define LOCATOR_TYPE_RANGE 'G' +#define LOCATOR_TYPE_RROBIN 'N' +#define LOCATOR_TYPE_CUSTOM 'C' +#define LOCATOR_TYPE_MODULO 'M' +#define LOCATOR_TYPE_LIST 'L' +#define LOCATOR_TYPE_NONE 'O' +#define LOCATOR_TYPE_DISTRIBUTED \ + 'D' /* for distributed table without specific \ + * scheme, e.g. result of JOIN of \ + * replicated and distributed table */ +/* We may consider the following type as future use */ +/* Maximum number of preferred Datanodes that can be defined in cluster */ +#define MAX_PREFERRED_NODES 64 + +#define HASH_SIZE 4096 +#define HASH_MASK 0x00000FFF; + +#define IsLocatorNone(x) ((x) == LOCATOR_TYPE_NONE) +#define IsLocatorReplicated(x) ((x) == LOCATOR_TYPE_REPLICATED) +#define IsLocatorColumnDistributed(x) \ + ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_RROBIN || \ + (x) == LOCATOR_TYPE_MODULO || (x) == LOCATOR_TYPE_DISTRIBUTED || \ + (x) == LOCATOR_TYPE_LIST || (x) == LOCATOR_TYPE_RANGE) +#define IsLocatorDistributedByValue(x) ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_MODULO || \ + (x) == LOCATOR_TYPE_RANGE || (x) == LOCATOR_TYPE_LIST) + +#define IsLocatorDistributedByHash(x) ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_RROBIN) +#define IsLocatorDistributedBySlice(x) ((x) == LOCATOR_TYPE_RANGE || (x) == LOCATOR_TYPE_LIST) + +#include "nodes/primnodes.h" +#include "utils/relcache.h" +#include "utils/partitionmap.h" +#include "nodes/nodes.h" +#include "nodes/params.h" + +/* + * How relation is accessed in the query + */ +typedef enum { + RELATION_ACCESS_READ, /* SELECT */ + RELATION_ACCESS_READ_FOR_UPDATE, /* SELECT FOR UPDATE */ + RELATION_ACCESS_UPDATE, /* UPDATE OR DELETE */ + RELATION_ACCESS_INSERT /* INSERT */ +} RelationAccessType; + +/* @hdfs + * Struct stores the information of each file for hdfs foreign scan schedule. + */ +typedef struct SplitInfo { + NodeTag type; + char* filePath; /* Absolute path of the file or folder. */ + char* fileName; /* The name of the file or folder. */ + List* partContentList; /* the partition column value list. */ + int64 ObjectSize; + char* eTag; + int prefixSlashNum; +} SplitInfo; + +/* @hdfs + * Struct stores the mapping of datanode id and list of split assigned to it. + */ +typedef struct SplitMap { + NodeTag type; + int nodeId; /* DataNode Id */ + char locatorType; /* Location type of rel */ + int64 totalSize; /* Total size of objects */ + int fileNums; /* the number of files */ + char* downDiskFilePath; /* the absolute path of down disk file, store in memory if it is null */ + List* lengths; /* the length for each part */ + List* splits; /* Splits to read */ +} SplitMap; + +/*@dfs + * Struct stores the items which will be sent from CN to DN for hdfs foreign scan. + */ +typedef struct DfsPrivateItem { + NodeTag type; + List* columnList; /* The list of all the target columns and the + * restriction columns of the relation. + */ + List* targetList; /* The list of all the target columns. */ + List* restrictColList; /* The list of columns in the restriction. */ + List* partList; /* The list of all the partition columns. */ + /* + * The list of the primitive restrictions, but inputcollid of the OpExpr is + * C_COLLATION_OID. we do not care colation in coarse filter. + */ + List* opExpressionList; + List* dnTask; /* The task list assigned to dn. */ + List* hdfsQual; /* The list of restrictions to push down. */ + int colNum; /* The number of the columns. */ + double* selectivity; /* The array of selectivities for each column. */ +} DfsPrivateItem; + +typedef struct { + Oid relid; /* OID of relation */ + char locatorType; /* locator type, see above */ + List* partAttrNum; /* Distribution column attribute */ + List* nodeList; /* Node indices where data is located */ + ListCell* roundRobinNode; /* Index of the next node to use */ + NameData gname; /* Group name */ + + /* + * Caution!!! don't invoke pfree() + * + * Because we introduce the bucketmap cache where a gaussdb persistent global memory + * area is allocated to hold the bucketmap content, just do pointer-assignment. + */ + uint2* buckets_ptr; /* pointer to local bucket-node mapping */ +} RelationLocInfo; + +#define IsRelationReplicated(rel_loc) IsLocatorReplicated((rel_loc)->locatorType) +#define IsRelationColumnDistributed(rel_loc) IsLocatorColumnDistributed((rel_loc)->locatorType) +#define IsRelationDistributedByValue(rel_loc) IsLocatorDistributedByValue((rel_loc)->locatorType) +#define InvalidateBuckets(rel_loc) ((rel_loc)->buckets_ptr = NULL) + +/* + * Distribution information related with node group + */ +typedef struct Distribution { + Oid group_oid; + Bitmapset* bms_data_nodeids; +} Distribution; + +/* + * list/range distributed table's slice boundaries, + * used for dispatching row/batch in datanode StreamProducer + */ +typedef struct SliceBoundary { + NodeTag type; + int nodeIdx; + int len; + Const *boundary[RANGE_PARTKEYMAXNUM]; +} SliceBoundary; + +typedef struct ExecBoundary { + NodeTag type; + char locatorType; + int32 count; + SliceBoundary **eles; +} ExecBoundary; + +/* + * Nodes to execute on + * primarynodelist is for replicated table writes, where to execute first. + * If it succeeds, only then should it be executed on nodelist. + * primarynodelist should be set to NULL if not doing replicated write operations + * Note on dist_vars: + * dist_vars is a list of Var nodes indicating the columns by which the + * relations (result of query) are distributed. The result of equi-joins between + * distributed relations, can be considered to be distributed by distribution + * columns of either of relation. Hence a list. dist_vars is ignored in case of + * distribution types other than HASH or MODULO. + */ +typedef struct { + NodeTag type; + List* primarynodelist; /* Primary node list indexes */ + List* nodeList; /* Node list indexes */ + Distribution distribution; + char baselocatortype; /* Locator type, see above */ + List* en_expr; /* Expression to evaluate at execution time + * if planner can not determine execution + * nodes */ + Oid en_relid; /* Relation to determine execution nodes */ + + Oid rangelistOid; /* list/range table oid that slice map references */ + bool need_range_prune; /* flag for list/range dynamic slice pruning */ + Index en_varno; /* relation varno */ + ExecBoundary* boundaries; /* slice boundaries that used for list/range redistribution in DML */ + + RelationAccessType accesstype; /* Access type to determine execution + * nodes */ + List* en_dist_vars; /* See above for details */ + int bucketmapIdx; /* the index of bucketmap + * (1) the value -1 means that the bucketmap is generated + * as default way "hashvalue % member_count + * (2) the others values means the index of + * the struct PlannedStmt -> bucketMap */ + bool nodelist_is_nil; /* true if nodeList is NIL when initialization */ + List* original_nodeList; /* used to keep original nodeList when explain analyze pbe */ + List* dynamic_en_expr; /* dynamic judge en_expr that should be judged later */ + /* runtime pbe purning for hashbucket, we keep another copy for safe */ + int bucketid; /* bucket id where the data should be in */ + List *bucketexpr; /* exprs which can be used for bucket purning */ + Oid bucketrelid; /* relid of the purning relation */ + List* hotkeys; /* List of HotkeyInfo */ +} ExecNodes; + +#define INVALID_BUCKET_ID -1 + +#define IsExecNodesReplicated(en) IsLocatorReplicated((en)->baselocatortype) +#define IsExecNodesColumnDistributed(en) IsLocatorColumnDistributed((en)->baselocatortype) +#define IsExecNodesDistributedByValue(en) IsLocatorDistributedByValue((en)->baselocatortype) + +/* Function for RelationLocInfo building and management */ +extern void RelationBuildLocator(Relation rel); +extern RelationLocInfo* GetRelationLocInfo(Oid relid); +extern RelationLocInfo* GetRelationLocInfoDN(Oid relid); +extern RelationLocInfo* CopyRelationLocInfo(RelationLocInfo* srcInfo); +extern void FreeRelationLocInfo(RelationLocInfo* relationLocInfo); +extern List* GetRelationDistribColumn(RelationLocInfo* locInfo); +extern char GetLocatorType(Oid relid); +extern List* GetPreferredReplicationNode(List* relNodes); +extern bool IsTableDistOnPrimary(RelationLocInfo* locInfo); +extern bool IsLocatorInfoEqual(RelationLocInfo* locInfo1, RelationLocInfo* locInfo2); +extern bool IsSliceInfoEqualByOid(Oid tabOid1, Oid tabOid2); +extern int GetRoundRobinNode(Oid relid); +extern bool IsTypeDistributable(Oid colType); +extern bool IsTypeDistributableForSlice(Oid colType); +extern bool IsDistribColumn(Oid relid, AttrNumber attNum); + +extern ExecNodes* GetRelationNodes(RelationLocInfo* rel_loc_info, Datum* values, const bool* nulls, Oid* attr, + List* idx_dist_by_col, RelationAccessType accessType, bool needDistribution = true, bool use_bucketmap = true); +extern ExecNodes* GetRelationNodesByQuals(void* query, Oid reloid, Index varno, Node* quals, + RelationAccessType relaccess, ParamListInfo boundParams, bool useDynamicReduce = false); +/* Global locator data */ +extern Distribution* NewDistribution(); +extern void DestroyDistribution(Distribution* distribution); +extern void FreeExecNodes(ExecNodes** exec_nodes); +extern List* GetAllDataNodes(void); +extern List* GetAllCoordNodes(void); +List* GetNodeGroupNodeList(Oid* members, int nmembers); + +extern int compute_modulo(unsigned int numerator, unsigned int denominator); +extern int get_node_from_modulo(int modulo, List* nodeList); +extern int GetMinDnNum(); +extern Expr* pgxc_check_distcol_opexpr(Index varno, AttrNumber attrNum, OpExpr* opexpr); +extern void PruningDatanode(ExecNodes* execNodes, ParamListInfo boundParams); + +#endif /* LOCATOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/nodemgr.h postgresql-hll-2.14/include/include/pgxc/nodemgr.h --- postgresql-hll-2.14_old/include/include/pgxc/nodemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/nodemgr.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------------- + * + * nodemgr.h + * Routines for node management + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/nodemgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMGR_H +#define NODEMGR_H + +#include "nodes/parsenodes.h" + +#define PGXC_NODENAME_LENGTH 64 + +/* Node definition */ +typedef struct NodeDefinition { + Oid nodeoid; + int nodeid; + NameData nodename; + NameData nodehost; + int nodeport; + int nodectlport; + int nodesctpport; + NameData nodehost1; + int nodeport1; + int nodectlport1; + int nodesctpport1; + bool hostisprimary; + bool nodeisprimary; + bool nodeispreferred; + bool nodeis_central; + bool nodeis_active; + Oid shard_oid; +} NodeDefinition; + +typedef struct { + int num_nodes; /* number of data nodes */ + NodeDefinition* nodesDefinition; /* all data nodes' defination */ +} GlobalNodeDefinition; + +/* Connection statistics info */ +typedef struct { + Oid primaryNodeId; /* original primary nodeid */ + int nodeIndex; /* original primary node subscript */ + bool isSucceed; /* link setup success flag */ + Oid *nodeList; /* nodeid about all nodes in the same segment */ +} NodeRelationInfo; + +typedef struct DNInfo { + Oid oid; + int idx; /* the sequence id of dn */ +}DNInfo; + +extern GlobalNodeDefinition* global_node_definition; + +extern void NodeTablesShmemInit(void); +extern Size NodeTablesShmemSize(void); + +extern void PgxcNodeListAndCount(void); +extern void PgxcNodeGetOids(Oid** coOids, Oid** dnOids, int* num_coords, int* num_dns, bool update_preferred); +extern void PgxcNodeGetStandbyOids(int* num_dns); +extern NodeDefinition* PgxcNodeGetDefinition(Oid node); +extern void PgxcNodeAlter(AlterNodeStmt* stmt); +extern void PgxcNodeCreate(CreateNodeStmt* stmt); +extern char PgxcNodeRemove(DropNodeStmt* stmt); +extern void PgxcCoordinatorAlter(AlterCoordinatorStmt* stmt); + +extern List* PgxcNodeGetAllDataNodeNames(void); +extern List* PgxcNodeGetDataNodeNames(List* nodeList); +extern List* PgxcNodeGetDataNodeOids(List* nodeList); +extern int pickup_random_datanode(int numnodes); +extern List* PgxcGetCoordlist(bool exclude_self); +extern bool PgxcIsCentralCoordinator(const char* NodeName); +extern void PgxcGetNodeName(int node_idx, char* nodenamebuf, int len); +extern int PgxcGetNodeIndex(const char* nodename); +extern Oid PgxcGetNodeOid(int node_idx); +extern int PgxcGetCentralNodeIndex(); + +extern void PgxcNodeFreeDnMatric(void); +extern void PgxcNodeInitDnMatric(void); +extern bool PgxcNodeCheckDnMatric(Oid oid1, Oid oid2); +extern bool PgxcNodeCheckPrimaryHost(Oid oid, const char* host); +extern Oid PgxcNodeGetPrimaryDNFromMatric(Oid oid1); +extern void PgxcNodeCount(int* numCoords, int* numDns); + +extern bool set_dnoid_info_from_matric(NodeRelationInfo *needCreateNode, bool *isMatricVisited); + +/* interface of dataNode to use hash table */ +extern void dn_info_local_hash_create(); +extern int dn_info_hash_search(Oid dn_oid); +extern void dn_info_hash_insert(Oid dn_oid, int row); +extern void dn_info_hash_delete(Oid dn_oid); +extern void dn_info_hash_destory(); + +#endif /* NODEMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/pgFdwRemote.h postgresql-hll-2.14/include/include/pgxc/pgFdwRemote.h --- postgresql-hll-2.14_old/include/include/pgxc/pgFdwRemote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/pgFdwRemote.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,67 @@ + +#ifndef PG_FDW_REMOTE_H +#define PG_FDW_REMOTE_H + +#include "c.h" +#include "nodes/nodes.h" +#include "utils/snapshot.h" + +typedef enum PgFdwMessageTag { + PGFDW_GET_TABLE_INFO = 0, + PGFDW_ANALYZE_TABLE, + PGFDW_QUERY_PARAM, + PGFDW_GET_VERSION, + PGFDW_GET_ENCODE +} PgFdwMessageTag; + +typedef enum PgFdwCheckResult { + PGFDW_CHECK_OK = 0, + PGFDW_CHECK_TABLE_FAIL, + PGFDW_CHECK_RELKIND_FAIL, + PGFDW_CHECK_COLUNM_FAIL +} PgFdwCheckResult; + +/* + * the cooperation analysis version control + * if modify the message which is sended and received, u need do such step + * 1.enmu GcFdwVersion, need add version, + * e.g. GCFDW_VERSION_V1R8C10_1 = 101 GCFDW_VERSION_V1R9C00 = 200 + * 2.modify GCFDW_VERSION, the value need be set the lastest version. + * 3.new logic, need use if conditon with new version + * e.g. if (gc_fdw_run_version >= GCFDW_VERSION_V1R8C10_1) + * { pq_sendint64(&retbuf, u_sess->debug_query_id); } + */ +typedef enum GcFdwVersion { + GCFDW_VERSION_V1R8C10 = 100, /* the first version */ + GCFDW_VERSION_V1R8C10_1 = 101, /* add foreign table option : encode type */ + GCFDW_VERSION_V1R9C00 = 200 +} GcFdwVersion; + +#define GCFDW_VERSION GCFDW_VERSION_V1R8C10_1 + +typedef struct PgFdwRemoteInfo { + NodeTag type; + char reltype; /* relation type */ + int datanodenum; /* datanode num */ + Size snapsize; /* the really size of snapshot */ + Snapshot snapshot; /* snapshot */ +} PgFdwRemoteInfo; + +extern bool PgfdwGetRelAttnum(int2vector* keys, PGFDWTableAnalyze* info); +extern bool PgfdwGetRelAttnum(TupleTableSlot* slot, PGFDWTableAnalyze* info); +extern void pgfdw_send_query(PGXCNodeAllHandles* pgxc_handles, char* query, RemoteQueryState** remotestate); +extern void PgFdwReportError(PgFdwCheckResult check_result); +extern void pgfdw_node_report_error(RemoteQueryState* combiner); +extern void PgFdwSendSnapshot(StringInfo buf, Snapshot snapshot); +extern void PgFdwSendSnapshot(StringInfo buf, Snapshot snapshot, Size snap_size); +extern Snapshot PgFdwRecvSnapshot(StringInfo buf); +extern void PgFdwRemoteSender(PGXCNodeAllHandles* pgxc_handles, const char* keystr, int len, PgFdwMessageTag tag); +extern void PgFdwRemoteReply(StringInfo msg); +extern void PgFdwRemoteReceiver(PGXCNodeAllHandles* pgxc_handles, void* info, int size); +extern bool PgfdwGetTuples(int cn_conn_count, PGXCNodeHandle** pgxc_connections, + RemoteQueryState* remotestate, TupleTableSlot* scanSlot); +extern void FetchGlobalPgfdwStatistics(VacuumStmt* stmt, bool has_var, PGFDWTableAnalyze* info); + +#endif + + diff -uprN postgresql-hll-2.14_old/include/include/pgxc/pgxc.h postgresql-hll-2.14/include/include/pgxc/pgxc.h --- postgresql-hll-2.14_old/include/include/pgxc/pgxc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/pgxc.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * pgxc.h + * Postgres-XC flags and connection control information + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/pgxc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_H +#define PGXC_H + +#include "storage/lwlock.h" +#include "postgres.h" +#include "knl/knl_variable.h" +extern bool isRestoreMode; + +// @Temp Table. Normally we only execute "drop schema pg_temp_XXX" on coordinator, +// but initdb use some temp tables too, whose we must do dropping in this case, +extern bool isSingleMode; + +extern bool isSecurityMode; + +typedef enum { + REMOTE_CONN_APP, + REMOTE_CONN_COORD, + REMOTE_CONN_DATANODE, + REMOTE_CONN_GTM, + REMOTE_CONN_GTM_PROXY, + REMOTE_CONN_INTERNAL_TOOL, + REMOTE_CONN_GTM_TOOL +} RemoteConnTypes; + +#ifdef ENABLE_MULTIPLE_NODES +#define IS_PGXC_COORDINATOR (g_instance.role == VCOORDINATOR && !is_streaming_engine()) +#define IS_PGXC_DATANODE (g_instance.role == VDATANODE || g_instance.role == VSINGLENODE || is_streaming_engine()) +#else +#define IS_PGXC_COORDINATOR (g_instance.role == VCOORDINATOR) +#define IS_PGXC_DATANODE (g_instance.role == VDATANODE || g_instance.role == VSINGLENODE) +#endif +#define IS_SINGLE_NODE (g_instance.role == VSINGLENODE) +#define REMOTE_CONN_TYPE u_sess->attr.attr_common.remoteConnType +#define COORDINATOR_NOT_SINGLE (g_instance.role == VDATANODE && g_instance.role != VSINGLENODE) + +#define IsConnFromApp() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_APP) +#define IsConnFromCoord() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_COORD) +#define IsConnFromDatanode() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_DATANODE) +#define IsConnFromGtm() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM) +#define IsConnFromGtmProxy() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM_PROXY) +#define IsConnFromInternalTool() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_INTERNAL_TOOL) +#define IsConnFromGTMTool() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM_TOOL) + +/* Is the CN receive SQL statement ? */ +#define IS_MAIN_COORDINATOR (IS_PGXC_COORDINATOR && !IsConnFromCoord()) + +/* key pair to be used as object id while using advisory lock for backup */ +#define XC_LOCK_FOR_BACKUP_KEY_1 0xFFFF +#define XC_LOCK_FOR_BACKUP_KEY_2 0xFFFF + +#endif /* PGXC_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/pgxcnode.h postgresql-hll-2.14/include/include/pgxc/pgxcnode.h --- postgresql-hll-2.14_old/include/include/pgxc/pgxcnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/pgxcnode.h 2020-12-12 17:06:43.248348051 +0800 @@ -0,0 +1,324 @@ +/* ------------------------------------------------------------------------- + * + * pgxcnode.h + * + * Utility functions to communicate to Datanodes and Coordinators + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group ? + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/pgxcnode.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PGXCNODE_H +#define PGXCNODE_H +#include "postgres.h" +#include "knl/knl_variable.h" +#include "gtm/gtm_c.h" +#include "utils/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/globalplancache.h" +#include "utils/snapshot.h" +#include "libcomm/libcomm.h" +#include "getaddrinfo.h" +#include + +#define NO_SOCKET -1 + +/* Message type code of bucket map and dn node index */ +#define MSG_TYPE_PGXC_BUCKET_MAP 'G' + +/* for logic connection sock is useless, type of gstock gives whether current logic connection is ok */ +#define IS_VALID_CONNECTION(handle) \ + ((handle->is_logic_conn) ? (handle->gsock.type != GSOCK_INVALID) : (handle->sock != NO_SOCKET)) + +#define DDL_PBE_VERSION_NUM 92067 /* Version control for DDL PBE */ + +struct StreamNetCtl; +/* Connection to Datanode maintained by Pool Manager */ +typedef struct pg_conn NODE_CONNECTION; +typedef struct pg_cancel NODE_CANCEL; + +/* Helper structure to access Datanode from Session */ +typedef enum { + DN_CONNECTION_STATE_IDLE, /* idle, ready for query */ + DN_CONNECTION_STATE_QUERY, /* query is sent, response expected */ + DN_CONNECTION_STATE_ERROR_FATAL, /* fatal error */ + DN_CONNECTION_STATE_COPY_IN, + DN_CONNECTION_STATE_COPY_OUT +} DNConnectionState; + +typedef enum { HANDLE_IDLE, HANDLE_ERROR, HANDLE_DEFAULT } PGXCNode_HandleRequested; + +/* + * Enumeration for two purposes + * 1. To indicate to the HandleCommandComplete function whether response checking is required or not + * 2. To enable HandleCommandComplete function to indicate whether the response was a ROLLBACK or not + * Response checking is required in case of PREPARE TRANSACTION and should not be done for the rest + * of the cases for performance reasons, hence we have an option to ignore response checking. + * The problem with PREPARE TRANSACTION is that it can result in a ROLLBACK response + * yet Coordinator would think it got done on all nodes. + * If we ignore ROLLBACK response then we would try to COMMIT a transaction that + * never got prepared, which in an incorrect behavior. + */ +typedef enum { + RESP_ROLLBACK_IGNORE, /* Ignore response checking */ + RESP_ROLLBACK_CHECK, /* Check whether response was ROLLBACK */ + RESP_ROLLBACK_RECEIVED, /* Response is ROLLBACK */ + RESP_ROLLBACK_NOT_RECEIVED /* Response is NOT ROLLBACK */ +} RESP_ROLLBACK; + +/* To identify the different uses of CSN */ +typedef enum { + FETCH_CSN, /* A flag to fecth csn from other nodes */ + GLOBAL_CSN_MIN /* The global min csn between all nodes */ +} CsnType; + +#define DN_CONNECTION_STATE_ERROR(dnconn) \ + ((dnconn)->state == DN_CONNECTION_STATE_ERROR_FATAL || (dnconn)->transaction_status == 'E') + +#define HAS_MESSAGE_BUFFERED(conn) \ + ((conn)->inCursor + 4 < (conn)->inEnd && \ + (conn)->inCursor + ntohl(*((uint32_t*)((conn)->inBuffer + (conn)->inCursor + 1))) < (conn)->inEnd) + +/* + * Represents a DataRow message received from a remote node. + * Contains originating node number and message body in DataRow format without + * message code and length. Length is separate field + */ +typedef struct RemoteDataRowData { + char* msg; /* last data row message */ + int msglen; /* length of the data row message */ + int msgnode; /* node number of the data row message */ +} RemoteDataRowData; +typedef RemoteDataRowData* RemoteDataRow; + +struct pgxc_node_handle { + Oid nodeoid; + + /* fd of the connection */ + int sock; + + /* tcp connection */ + int tcpCtlPort; + int listenPort; + /* logic connection socket between cn and dn */ + gsocket gsock; + + char transaction_status; + DNConnectionState state; + struct RemoteQueryState* combiner; + struct StreamState* stream; +#ifdef DN_CONNECTION_DEBUG + bool have_row_desc; +#endif + char* error; + char* hint; + /* Output buffer */ + char* outBuffer; + size_t outSize; + size_t outEnd; + uint64 outNum; + /* Input buffer */ + char* inBuffer; + size_t inSize; + size_t inStart; + size_t inEnd; + size_t inCursor; + + /* + * Have a variable to enable/disable response checking and + * if enable then read the result of response checking + * + * For details see comments of RESP_ROLLBACK + */ + RESP_ROLLBACK ck_resp_rollback; + + char* remoteNodeName; + int nodeIdx; /* datanode index, like t_thrd.postmaster_cxt.PGXCNodeId */ + knl_virtual_role remote_node_type; + PoolConnInfo connInfo; + /* flag to identify logic connection between cn and dn */ + bool is_logic_conn; + NODE_CONNECTION* pg_conn; + MessageCommLog *msgLog; + TransactionId remote_top_txid; +}; +typedef struct pgxc_node_handle PGXCNodeHandle; + +/* + * Because the number of node handles is identical to the number of nodes, + * so here we combine both CN and DN handles together for better maitanences + */ +typedef struct PGXCNodeHandleGroup { + PGXCNodeHandle* nodeHandles; + uint32 nodeHandleNums; + + /* dn and cn slots often process together, so need offset to indicate real postion */ + uint32 offset; +} PGXCNodeHandleGroup; + +typedef struct PGXCNodeNetCtlLayer { + int conn_num; /* size of array */ + struct pollfd* ufds; /* physic poll fds. */ + int* datamarks; /* producer number triggers poll. */ + int* poll2conn; /* poll idx to connection idx. */ + gsocket* gs_sock; /* logic poll gs_sock. */ +} PGXCNodeNetCtlLayer; + +/* Structure used to get all the handles involved in a transaction */ +typedef struct PGXCNodeAllHandles { + PGXCNodeHandle* primary_handle; /* Primary connection to PGXC node */ + int dn_conn_count; /* number of Datanode Handles including primary handle */ + PGXCNodeHandle** datanode_handles; /* an array of Datanode handles */ + List* dummy_datanode_handles; /* only valid for replicate table dml */ + int co_conn_count; /* number of Coordinator handles */ + PGXCNodeHandle** coord_handles; /* an array of Coordinator handles */ +} PGXCNodeAllHandles; + +typedef struct { + int* fds; + gsocket* gsock; + PoolConnInfo* connInfos; + NODE_CONNECTION** pgConn; + int pgConnCnt; +} PoolConnDef; + +extern void InitMultinodeExecutor(bool is_force); + +/* Open/close connection routines (invoked from Pool Manager) */ +extern char *PGXCNodeConnStr(const char *host, int port, const char *dbname, const char *user, + const char *pgoptions, const char *remote_type, int proto_type, const char *remote_nodename); + +extern NODE_CONNECTION* PGXCNodeConnect(char* connstr); +extern int PGXCNodeSendSetQuery(NODE_CONNECTION* conn, const char* sql_command); +extern int PGXCNodeSetQueryGetResult(NODE_CONNECTION* conn); +extern int PGXCNodeSendSetQueryPoolerStatelessReuse(NODE_CONNECTION* conn, const char* sql_command); +extern void PGXCNodeClose(NODE_CONNECTION* conn); +extern int PGXCNodeConnected(NODE_CONNECTION* conn); +extern int PGXCNodeConnClean(NODE_CONNECTION* conn); +extern void PGXCNodeCleanAndRelease(int code, Datum arg); +extern void PGXCConnClean(int code, Datum arg); + +/* Look at information cached in node handles */ +extern int PGXCNodeGetNodeId(Oid nodeoid, char node_type); +extern Oid PGXCNodeGetNodeOid(int nodeid, char node_type); +extern int PGXCNodeGetNodeIdFromName(const char* node_name, char node_type); +extern char* PGXCNodeGetNodeNameFromId(int nodeid, char node_type); +extern int LibcommPacketSend(NODE_CONNECTION* conn, char pack_type, const void* buf, size_t buf_len); +extern bool LibcommCancelOrStop(NODE_CONNECTION* conn, char* errbuf, int errbufsize, int timeout, uint32 request_code); +extern bool LibcommStopQuery(NODE_CONNECTION* conn); +extern int LibcommSendSome(NODE_CONNECTION* conn, int len); +extern int LibcommPutMsgEnd(NODE_CONNECTION* conn); +extern int LibcommFlush(NODE_CONNECTION* conn); +extern int LibcommSendQuery(NODE_CONNECTION* conn, const char* query); +extern int LibcommReadData(NODE_CONNECTION* conn); +extern PGXCNodeAllHandles* get_handles( + List* datanodelist, List* coordlist, bool is_query_coord_only, List* dummydatanodelist = NIL); +extern void pfree_pgxc_all_handles(PGXCNodeAllHandles* handles); + +extern void release_pgxc_handles(PGXCNodeAllHandles* pgxc_handles); +extern void release_handles(void); +extern void destroy_handles(void); +extern void reset_handles_at_abort(void); +extern void cancel_query(void); +extern void cancel_query_without_read(void); +extern void stop_query(void); +extern void clear_all_data(void); + +extern int get_transaction_nodes( + PGXCNodeHandle** connections, char client_conn_type, PGXCNode_HandleRequested type_requested); +extern char* collect_pgxcnode_names( + char* nodestring, int conn_count, PGXCNodeHandle** connections, char client_conn_type); +extern char* collect_localnode_name(char* nodestring); +extern int get_active_nodes(PGXCNodeHandle** connections); + +extern void ensure_in_buffer_capacity(size_t bytes_needed, PGXCNodeHandle* handle); +extern void ensure_out_buffer_capacity(size_t bytes_needed, PGXCNodeHandle* handle); + +extern int pgxc_node_send_threadid(PGXCNodeHandle* handle, uint32 threadid); +extern int pgxc_node_send_queryid(PGXCNodeHandle* handle, uint64 queryid); +extern int pgxc_node_send_cn_identifier(PGXCNodeHandle *handle, PGXCNode_HandleGPC handle_type); + +extern int pgxc_node_send_unique_sql_id(PGXCNodeHandle* handle); +extern int pgxc_node_send_query(PGXCNodeHandle* handle, const char* query, bool isPush = false, + bool trigger_ship = false, bool check_gtm_mode = false, const char *compressPlan = NULL, int cLen = 0); +extern void pgxc_node_send_gtm_mode(PGXCNodeHandle* handle); +extern int pgxc_node_send_plan_with_params(PGXCNodeHandle* handle, const char* query, short num_params, + Oid* param_types, int paramlen, const char* params, int fetch_size); +extern int pgxc_node_send_describe(PGXCNodeHandle* handle, bool is_statement, const char* name); +extern int pgxc_node_send_execute(PGXCNodeHandle* handle, const char* portal, int fetch); +extern int pgxc_node_send_close(PGXCNodeHandle* handle, bool is_statement, const char* name); +extern int pgxc_node_send_sync(PGXCNodeHandle* handle); +extern int pgxc_node_send_bind( + PGXCNodeHandle* handle, const char* portal, const char* statement, int paramlen, const char* params); +extern int pgxc_node_send_parse( + PGXCNodeHandle* handle, const char* statement, const char* query, short num_params, Oid* param_types); +extern int pgxc_node_send_query_extended(PGXCNodeHandle* handle, const char* query, const char* statement, + const char* portal, int num_params, Oid* param_types, int paramlen, const char* params, bool send_describe, + int fetch_size); +extern int pgxc_node_send_gxid(PGXCNodeHandle* handle, GlobalTransactionId gxid, bool isforcheck); +extern int pgxc_node_send_commit_csn(PGXCNodeHandle* handle, uint64 commit_csn); +extern int pgxc_node_send_csn(PGXCNodeHandle* handle, uint64 commit_csn, CsnType csn_type); +extern int pgxc_node_notify_commit(PGXCNodeHandle* handle); +extern int pgxc_node_send_cmd_id(PGXCNodeHandle* handle, CommandId cid); +extern int pgxc_node_send_wlm_cgroup(PGXCNodeHandle* handle); +extern int pgxc_node_dywlm_send_params_for_jobs(PGXCNodeHandle* handle, int tag, const char* keystr); +extern int pgxc_node_dywlm_send_params(PGXCNodeHandle* handle, const void* info); +extern int pgxc_node_dywlm_send_record(PGXCNodeHandle* handle, int tag, const char* infostr); +extern int pgxc_node_send_pgfdw(PGXCNodeHandle* handle, int tag, const char* keystr, int len); +extern int pgxc_node_send_snapshot(PGXCNodeHandle* handle, Snapshot snapshot, int max_push_sqls = 1); +extern int pgxc_node_send_ddl_params(PGXCNodeHandle* handle); +extern int pgxc_node_send_timestamp( + PGXCNodeHandle* handle, TimestampTz gtmstart_timestamp, TimestampTz stmtsys_timestamp); +extern int pgxc_node_send_pushschema(PGXCNodeHandle* handle, bool* isPush); +extern int pgxc_node_send_popschema(PGXCNodeHandle* handle); +extern int pgxc_node_is_data_enqueued(PGXCNodeHandle* conn); +extern int send_some(PGXCNodeHandle* handle, int len); +extern int pgxc_node_flush(PGXCNodeHandle* handle); +extern bool pgxc_node_flush_read(PGXCNodeHandle* handle); +extern int pgxc_all_handles_send_gxid(PGXCNodeAllHandles* pgxc_handles, GlobalTransactionId gxid, bool stop_at_error); +extern int pgxc_all_handles_send_query(PGXCNodeAllHandles* pgxc_handles, const char* buffer, bool stop_at_error); +extern void add_error_message(PGXCNodeHandle* handle, const char *message, ...); +extern char get_message(PGXCNodeHandle *conn, int *len, char **msg); +extern Datum pgxc_execute_on_nodes(int numnodes, Oid* nodelist, char* query); +extern bool pgxc_node_receive(const int conn_count, PGXCNodeHandle** connections, struct timeval* timeout); +extern bool datanode_receive_from_physic_conn( +const int conn_count, PGXCNodeHandle** connections, struct timeval* timeout); +extern bool datanode_receive_from_logic_conn( +const int conn_count, PGXCNodeHandle** connections, StreamNetCtl* ctl, int time_out); + +extern bool pgxc_node_validate(PGXCNodeHandle *conn); +extern int pgxc_node_read_data(PGXCNodeHandle* conn, bool close_if_error, bool StreamConnection = false); +extern int pgxc_node_read_data_from_logic_conn(PGXCNodeHandle* conn, bool close_if_error); +extern void ResetHandleOutBuffer(PGXCNodeHandle* handle); +extern void connect_server( + const char* conn_str, PGXCNodeHandle** handle, const char* host, int port, const char* log_conn_str); +extern void release_conn_to_compute_pool(); +extern void release_pgfdw_conn(); + +extern int pgxc_node_send_userpl(PGXCNodeHandle* handle, int userpl); +extern int pgxc_node_send_userpl(PGXCNodeHandle* handle, int64 userpl); +extern int pgxc_node_send_cpconf(PGXCNodeHandle* handle, char* data); +extern int pgxc_send_bucket_map(PGXCNodeHandle* handle, uint2* bucketMap, int dnNodeIdx); + +extern bool light_node_receive(PGXCNodeHandle* handle); +extern bool light_node_receive_from_logic_conn(PGXCNodeHandle* handle); +extern int pgxc_node_pgstat_send(PGXCNodeHandle* handle, char tag); +extern void pgxc_node_free(PGXCNodeHandle* handle); +extern void pgxc_node_init(PGXCNodeHandle* handle, int sock); +extern void pgxc_node_free_def(PoolConnDef* result); +extern void pgxc_palloc_net_ctl(int conn_num); +extern int ts_get_tag_colnum(Oid relid, bool need_index = false, List** idx_list = NULL); + +#endif /* PGXCNODE_H */ + +#ifdef ENABLE_UT +extern char* getNodenameByIndex(int index); +extern int LibcommSendQueryPoolerStatelessReuse(NODE_CONNECTION* conn, const char* query); +extern int LibcommWaitpoll(NODE_CONNECTION* conn); +extern int light_node_read_data(PGXCNodeHandle* conn); +#endif /* USE_UT */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/pgxcXact.h postgresql-hll-2.14/include/include/pgxc/pgxcXact.h --- postgresql-hll-2.14_old/include/include/pgxc/pgxcXact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/pgxcXact.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,26 @@ + +#ifndef PGXC_TRANS_H +#define PGXC_TRANS_H + +#include "c.h" +#include "pgxc/pgxcnode.h" + +extern int pgxc_node_begin(int conn_count, PGXCNodeHandle** connections, + GlobalTransactionId gxid, bool need_tran_block, + bool readOnly, char node_type, bool need_send_queryid = false); +extern bool pgxc_node_remote_prepare(const char* prepareGID, bool WriteCnLocalNode); +extern void pgxc_node_remote_commit(bool barrierLockHeld); +extern int pgxc_node_remote_abort(void); +extern int pgxc_node_receive_responses(const int conn_count, PGXCNodeHandle** connections, + struct timeval* timeout, RemoteQueryState* combiner, bool checkerror = true); +extern List* GetWriterHandles(); +extern List* GetReaderHandles(); +extern void PreCommit_Remote(char* prepareGID, bool barrierLockHeld); +extern void SubXactCancel_Remote(void); +extern char* PrePrepare_Remote(const char* prepareGID, bool implicit, bool WriteCnLocalNode); +extern void PostPrepare_Remote(char* prepareGID, char* nodestring, bool implicit); +extern bool PreAbort_Remote(bool PerfectRollback); +extern void AtEOXact_Remote(void); +extern bool IsTwoPhaseCommitRequired(bool localWrite); +extern void reset_remote_handle_xid(void); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/pgxc/poolcomm.h postgresql-hll-2.14/include/include/pgxc/poolcomm.h --- postgresql-hll-2.14_old/include/include/pgxc/poolcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/poolcomm.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * poolcomm.h + * + * Definitions for the Pooler-Seesion communications. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolcomm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POOLCOMM_H +#define POOLCOMM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "libcomm/libcomm.h" +#include "pgxc/pgxcnode.h" + +#define POOL_BUFFER_SIZE 1024 +#define Socket(port) (port).fdsock + +typedef struct { + /* file descriptors */ + int fdsock; + /* receive buffer */ + int RecvLength; + int RecvPointer; + char RecvBuffer[POOL_BUFFER_SIZE]; + /* send buffer */ + int SendPointer; + char SendBuffer[POOL_BUFFER_SIZE]; +} PoolPort; + +extern int pool_listen(unsigned short port, const char* unixSocketName); +extern int pool_connect(unsigned short port, const char* unixSocketName); +extern int pool_getbyte(PoolPort* port); +extern int pool_pollbyte(PoolPort* port); +extern int pool_getmessage(PoolPort* port, StringInfo s, int maxlen); +extern int pool_getbytes(PoolPort* port, char* s, size_t len); +extern int pool_putmessage(PoolPort* port, char msgtype, const char* s, size_t len); +extern int pool_putbytes(PoolPort* port, const char* s, size_t len); +extern int pool_flush(PoolPort* port); +extern int pool_sendconnDefs(PoolPort* port, PoolConnDef* connDef, int count); +extern int pool_recvconnDefs(PoolPort* port, PoolConnDef* connDef, int count); +extern int pool_sendres(PoolPort* port, int res); +extern int pool_recvres(PoolPort* port); +extern int pool_sendpids(PoolPort* port, ThreadId* pids, int count); +extern int pool_recvpids(PoolPort* port, ThreadId** pids); + +#endif /* POOLCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/poolmgr.h postgresql-hll-2.14/include/include/pgxc/poolmgr.h --- postgresql-hll-2.14_old/include/include/pgxc/poolmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/poolmgr.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,406 @@ +/* ------------------------------------------------------------------------- + * + * poolmgr.h + * + * Definitions for the Datanode connection pool. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolmgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POOLMGR_H +#define POOLMGR_H +#include +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "poolcomm.h" +#include "storage/pmsignal.h" +#include "utils/hsearch.h" +#include "executor/execStream.h" + +#define MAX_IDLE_TIME 60 +#define ENABLE_STATELESS_REUSE g_instance.attr.attr_network.PoolerStatelessReuse +/* The handle status is normal, send back socket to the pool */ +#define CONN_STATE_NORMAL 'n' +/* The handle status has an error, drop the socket */ +#define CONN_STATE_ERROR 'e' +/* param number */ +#define FOUR_ARGS (4) +#define FIVE_ARGS (5) +#define SIX_ARGS (6) + +/* + * List of flags related to pooler connection clean up when disconnecting + * a session or relaeasing handles. + * When Local SET commands (POOL_CMD_LOCAL_SET) are used, local parameter + * string is cleaned by the node commit itself. + * When global SET commands (POOL_CMD_GLOBAL_SET) are used, "RESET ALL" + * command is sent down to activated nodes to at session end. At the end + * of a transaction, connections using global SET commands are not sent + * back to pool. + * When temporary object commands are used (POOL_CMD_TEMP), "DISCARD ALL" + * query is sent down to nodes whose connection is activated at the end of + * a session. + * At the end of a transaction, a session using either temporary objects + * or global session parameters has its connections not sent back to pool. + * + * Local parameters are used to change within current transaction block. + * They are sent to remote nodes invloved in the transaction after sending + * BEGIN TRANSACTION using a special firing protocol. + * They cannot be sent when connections are obtained, making them having no + * effect as BEGIN is sent by backend after connections are obtained and + * obtention confirmation has been sent back to backend. + * SET CONSTRAINT, SET LOCAL commands are in this category. + * + * Global parmeters are used to change the behavior of current session. + * They are sent to the nodes when the connections are obtained. + * SET GLOBAL, general SET commands are in this category. + */ +typedef enum { + POOL_CMD_TEMP, /* Temporary object flag */ + POOL_CMD_LOCAL_SET, /* Local SET flag, current transaction block only */ + POOL_CMD_GLOBAL_SET /* Global SET flag */ +} PoolCommandType; + +typedef enum { + POOL_NODE_CN, /* node type: coordinator */ + POOL_NODE_DN /* node type: datanode */ +} PoolNodeType; + +typedef enum { + POOL_NODE_NONE = 0, /* no node mode */ + POOL_NODE_PRIMARY, /* node mode: primary */ + POOL_NODE_STANDBY /* node mode: standby */ +} PoolNodeMode; + +/* Connection pool entry */ +typedef struct PGXCNodePoolSlot { + /* In pooler stateless reuse mode, user_name and pgoptions save in slot to check whether to send params */ + char* user_name; + char* pgoptions; /* Connection options */ + char* session_params; + bool need_validate; + Oid userid; + struct timeval released; + NODE_CONNECTION* conn; + NODE_CANCEL* xc_cancelConn; + pthread_mutex_t slot_lock; + union { + uint32 node_count; /* for list head: numbers of node */ + uint32 used_count; /* for list node: counting the times of the slot be used */ + }; + struct PGXCNodePoolSlot* next; +} PGXCNodePoolSlot; + +/* Pool of connections to specified pgxc node */ +typedef struct { + Oid nodeoid; /* Node Oid related to this pool, Hash key (must be first!) */ + char* connstr; + char* connstr1; + int freeSize; /* available connections */ + int size; /* total pool size */ + bool valid; /* ensure atom initialization of node pool */ + pthread_mutex_t lock; + PGXCNodePoolSlot** slot; /* use in not ENABLE_STATELESS_REUSE */ + HTAB* useridSlotsHash; /* hash table: key(userid), value(PGXCNodePoolSlot*), use in ENABLE_STATELESS_REUSE */ +} PGXCNodePool; + +/* All pools for specified database */ +typedef struct databasepool { + char* database; + char* user_name; + Oid userId; + char* pgoptions; /* Connection options */ + HTAB* nodePools; /* Hashtable of PGXCNodePool, one entry for each Coordinator or DataNode */ + /* lock for nodePools to add/find/remove */ + pthread_mutex_t nodePoolsLock; + MemoryContext mcxt; + struct databasepool* next; /* Reference to next to organize linked list */ +} DatabasePool; + +typedef struct PoolerCleanParams { + DatabasePool **dbPool; + List *nodeList; + Oid *nodeOids; + int totalCleanNums; + int needCleanNumsPerNode; + int totalNodes; + struct timeval *currVal; +} PoolerCleanParams; + +typedef struct { + ThreadId pid; /* Process ID of postmaster child process associated to pool agent */ + int num_invalid_node; /* the num of nodes that connection is invalid */ + int num_connections; /* num of the node connections */ + int result_offset; /* offset of result */ + int* invalid_nodes; /* the nodes that connection is invalid */ + Oid* conn_oids; /* connection id for each node */ + PGXCNodePoolSlot** connections; /* connection for each node */ + DatabasePool* dbpool; /* database pool */ + char* session_params; /* session params */ + char* temp_namespace; /* @Temp table. temp namespace name of session related to this agent. */ + PoolNodeType node_type; /* node type, dn or dn */ + PoolNodeMode* node_mode; /* node mode: primary, standby or none */ + PoolConnDef* conndef; /* pool conn def */ + bool is_retry; /* retry to connect */ + PoolAgent* agent; /* reference to local PoolAgent struct */ +} PoolGeneralInfo; + +/* + * The number of conn slots is recorded based on the number of connSlotNums + * So we bind the two values together to maintain integrity + */ +typedef struct PoolSlotGroup { + PGXCNodePoolSlot** connSlots; + Oid* connOids; + uint32 connSlotNums; + + /* dn and cn slots often process together, so need offset to indicate real postion */ + uint32 offset; +} PoolSlotGroup; + +/* + * Agent of client session (Pool Manager side) + * Acts as a session manager, grouping connections together + * and managing session parameters + */ +typedef struct PoolAgent { + /* Process ID of postmaster child process associated to pool agent */ + ThreadId pid; + /* communication channel */ + PoolPort port; + DatabasePool* pool; + + /* In pooler stateless reuse mode, user_name and pgoptions save in PoolAgent */ + char* user_name; + char* pgoptions; /* Connection options */ + bool has_check_params; // Deal with the situations where SET GUC commands are run within a Transaction block + bool is_thread_pool_session; // use for thread pool + uint64 session_id; /* user session id(when thread pool disabled, equal to pid) */ + + MemoryContext mcxt; + int num_dn_connections; + int num_coord_connections; + int params_set; /* param is set */ + int localParamsSet; /* local param is set */ + int reuse; /* connection reuse flag */ + Oid* dn_conn_oids; /* one for each Datanode */ + Oid* coord_conn_oids; /* one for each Coordinator */ + Oid* dn_connecting_oids; /* current connection dn oids */ + int dn_connecting_cnt; /* current connection dn count */ + Oid* coord_connecting_oids; /* current connection cn oids */ + int coord_connecting_cnt; /* current connection cn count */ + PGXCNodePoolSlot** dn_connections; /* one for each Datanode */ + PGXCNodePoolSlot** coord_connections; /* one for each Coordinator */ + char* session_params; + char* local_params; + char* temp_namespace; /* @Temp table. temp namespace name of session related to this agent. */ + List* params_list; /* session params list */ + List* localParamsList; /* local params list */ + pthread_mutex_t lock; /* protect agent in mutilthread */ +} PoolAgent; + +/* + * Invalid backend entry + * Collect info from pooler and pgxc_node. An invalid backend + * may hold several invalid connections to different node. + */ +typedef struct { + ThreadId tid; + char** node_name; + bool is_thread_pool_session; + + /* + * used to send signal. + * if IS_THREAD_POOL_WORKER, set to session_ctr_index; + * else is MyProcPid + */ + ThreadId send_sig_pid; + + int num_nodes; + int total_len; + bool is_connecting; +} InvalidBackendEntry; + +/* + * PoolConnectionInfo entry for pg_pooler_status view + */ +typedef struct { + char* database; + char* user_name; + ThreadId tid; + char* pgoptions; + bool in_use; + Oid nodeOid; + char *session_params; + int fdsock; + ThreadId remote_pid; + uint32 used_count; /*counting the times of the slot be used*/ +} PoolConnectionInfo; + +/* + * ConnectionStatus entry for pg_conn_status view + */ +typedef struct { + char *remote_name; + char *remote_host; + int remote_port; + bool is_connected; + int sock; +} ConnectionStatus; + +/* Connection information cached */ +typedef struct PGXCNodeConnectionInfo { + Oid nodeoid; + char* host; + int port; + int64 cn_connect_time; + int64 dn_connect_time; +} PGXCNodeConnectionInfo; + +/* Connection statistics info */ +typedef struct { + int count; + int free_count; + int64 memory_size; + int64 free_memory_size; + int dbpool_count; + int nodepool_count; +} PoolConnStat; + +typedef struct DatanodeShardInfo +{ + Oid s_nodeoid; + NameData s_data_shardname; + Oid s_primary_nodeoid; + NameData s_primary_nodename; +} DatanodeShardInfo; + +typedef PoolAgent PoolHandle; + +/* Status inquiry functions */ +extern void PGXCPoolerProcessIam(void); +extern bool IsPGXCPoolerProcess(void); + +/* Initialize internal structures */ +extern int PoolManagerInit(void); + +/* Destroy internal structures */ +extern int PoolManagerDestroy(void); + +/* + * Get handle to pool manager. This function should be called just before + * forking off new session. It creates PoolHandle, PoolAgent and a pipe between + * them. PoolAgent is stored within Postmaster's memory context and Session + * closes it later. PoolHandle is returned and should be store in a local + * variable. After forking off it can be stored in global memory, so it will + * only be accessible by the process running the session. + */ +extern PoolHandle* GetPoolManagerHandle(void); + +/* + * Called from Postmaster(Coordinator) after fork. Close one end of the pipe and + * free memory occupied by PoolHandler + */ +extern void PoolManagerCloseHandle(PoolHandle* handle); + +/* + * Gracefully close connection to the PoolManager + */ +extern void PoolManagerDisconnect(void); + +extern char* session_options(void); + +/* + * Called from Session process after fork(). Associate handle with session + * for subsequent calls. Associate session with specified database and + * initialize respective connection pool + */ +extern void PoolManagerConnect(PoolHandle* handle, const char* database, const char* user_name, const char* pgoptions); + +/* + * Reconnect to pool manager + * This simply does a disconnection followed by a reconnection. + */ +extern void PoolManagerReconnect(void); + +/* + * Save a SET command in Pooler. + * This command is run on existent agent connections + * and stored in pooler agent to be replayed when new connections + * are requested. + */ +extern int PoolManagerSetCommand(PoolCommandType command_type, const char* set_command, const char* name = NULL); + +/* Get pooled connection status */ +extern bool PoolManagerConnectionStatus(List* datanodelist, List* coordlist); + +/* Get pooled connections */ +extern PoolConnDef* PoolManagerGetConnections(List* datanodelist, List* coordlist); + +/* Clean pool connections */ +extern bool PoolManagerCleanConnection( + List* datanodelist, List* coordlist, const char* dbname, const char* username, bool is_missing = false); + +/* Check consistency of connection information cached in pooler with catalogs */ +extern bool PoolManagerCheckConnectionInfo(void); + +/* Reload connection data in pooler and drop all the existing connections of pooler */ +extern void PoolManagerReloadConnectionInfo(void); + +/* Send Abort signal to transactions being run */ +extern int PoolManagerAbortTransactions( + const char* dbname, const char* username, ThreadId** proc_pids, bool** isthreadpool); + +/* Return connections back to the pool, for both Coordinator and Datanode connections */ +extern void PoolManagerReleaseConnections(const char* status_array, int array_size, bool has_error); + +/* return (canceled) invalid backend entry */ +extern InvalidBackendEntry* PoolManagerValidateConnection(bool clear, const char* co_node_name, uint32& count); + +/* Cancel a running query on Datanodes as well as on other Coordinators */ +extern int PoolManagerCancelQuery(int dn_count, const int* dn_list, int co_count, const int* co_list); + +// stop a running query. +extern int PoolManagerStopQuery(int dn_count, const int* dn_list); + +/* Check if pool has a handle */ +extern bool IsPoolHandle(void); + +extern bool test_conn(PGXCNodePoolSlot* slot, Oid nodeid); +extern PoolAgent* get_poolagent(void); + +extern void release_connection(PoolAgent* agent, PGXCNodePoolSlot** ptrSlot, Oid node, bool force_destroy); + +/* Send commands to alter the behavior of current transaction */ +extern int PoolManagerSendLocalCommand(int dn_count, const int* dn_list, int co_count, const int* co_list); + +extern int* StreamConnectNodes(List* datanodelist, int consumerDop, int distrType, NodeDefinition* nodeDef, + struct addrinfo** addrArray, StreamKey key, Oid nodeoid); +extern int* StreamConnectNodes(libcommaddrinfo** addrArray, int connNum); + +extern void PoolManagerInitPoolerAgent(); +extern int get_pool_connection_info(PoolConnectionInfo** connectionEntry); +extern int check_connection_status(ConnectionStatus **connectionEntry); +extern void set_pooler_ping(bool mod); +extern void pooler_get_connection_statinfo(PoolConnStat* conn_stat); +extern int register_pooler_session_param(const char* name, const char* queryString, PoolCommandType command_type); +extern int delete_pooler_session_params(const char* name); +extern void agent_reset_session(PoolAgent* agent, bool need_reset); +extern const char* GetNodeNameByOid(Oid nodeOid); +extern void InitOidNodeNameMappingCache(); +extern void CleanOidNodeNameMappingCache(); +#endif + +#ifdef ENABLE_UT +extern THR_LOCAL PoolHandle* poolHandle; +extern void free_user_name_pgoptions(PGXCNodePoolSlot* slot); +extern void reload_user_name_pgoptions(PoolGeneralInfo* info, PoolAgent* agent, PGXCNodePoolSlot* slot); +extern PGXCNodePoolSlot* alloc_slot_mem(DatabasePool* dbpool); +extern int agent_wait_send_connection_params_pooler_reuse(NODE_CONNECTION* conn); +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/poolutils.h postgresql-hll-2.14/include/include/pgxc/poolutils.h --- postgresql-hll-2.14_old/include/include/pgxc/poolutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/poolutils.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * poolutils.h + * + * Utilities for Postgres-XC Pooler + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolutils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POOLUTILS_H +#define POOLUTILS_H + +#include "nodes/parsenodes.h" + +#define TIMEOUT_CLEAN_LOOP 15 /* Wait 15s for all the transactions to shutdown */ + +/* Error codes for connection cleaning */ +#define CLEAN_CONNECTION_COMPLETED 0 +#define CLEAN_CONNECTION_NOT_COMPLETED 1 +#define CLEAN_CONNECTION_TX_REMAIN 2 +#define CLEAN_CONNECTION_EOF -1 + +/* Results for pooler connection info check */ +#define POOL_CHECK_SUCCESS 0 +#define POOL_CHECK_FAILED 1 + +void CleanConnection(CleanConnStmt* stmt); +void DropDBCleanConnection(const char* dbname); +void DropRoleCleanConnection(const char* username); + +/* Handle pooler connection reload */ +void processPoolerReload(void); + +#define ResetSessionExecutorInfo(is_force) \ + do { \ + MemoryContext old_context = MemoryContextSwitchTo( \ + SESS_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR)); \ + InitMultinodeExecutor(is_force); \ + PoolManagerReconnect(); \ + MemoryContextSwitchTo(old_context); \ + } while (0) + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/pruningslice.h postgresql-hll-2.14/include/include/pgxc/pruningslice.h --- postgresql-hll-2.14_old/include/include/pgxc/pruningslice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/pruningslice.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruningslice.h + * some routines that be used for slice pruning for list/range distributed table. + * + * + * IDENTIFICATION + * src/include/pgxc/pruningslice.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef PRUNINGSLICE_H_ +#define PRUNINGSLICE_H_ + +void PruningSliceForExecNodes(ExecNodes* exec_nodes, ParamListInfo boundParams); +void PruningSliceForQuals(ExecNodes* execNodes, Index varno, Node* quals, ParamListInfo boundParams); + +void InitDistColIndexMap(int* colMap, List* distColIdxList); +Oid GetRangeNodeFromValue(RelationLocInfo* relLocInfo, Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len); +Oid GetListNodeFromValue(RelationLocInfo* relLocInfo, Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len); + +void PruningRangeSlice(ExecNodes* execNodes, RelationLocInfo* relLocInfo, Index varno, RelationAccessType relaccess, + ListCell* lastDistcolCell, Node* quals, ParamListInfo boundParams, bool useDynReduce); + +void ConstructConstFromValues(Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len, Const* consts, Const** constPointers); +void ConstructSliceBoundary(ExecNodes* en); +uint2 GetTargetConsumerNodeIdx(ExecBoundary* enBoundary, Const** distValues, int distLen); + + +#endif /* PRUNINGSLICE_H_ */ + diff -uprN postgresql-hll-2.14_old/include/include/pgxc/redistrib.h postgresql-hll-2.14/include/include/pgxc/redistrib.h --- postgresql-hll-2.14_old/include/include/pgxc/redistrib.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/redistrib.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,115 @@ +/* ------------------------------------------------------------------------- + * + * redistrib.h + * Routines related to online data redistribution + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/redistrib.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef REDISTRIB_H +#define REDISTRIB_H + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "utils/tuplestore.h" +#include "storage/itemptr.h" + +/* + * Type of data redistribution operations. + * Online data redistribution is made of one or more of those operations. + */ +typedef enum RedistribOperation { + DISTRIB_NONE, /* Default operation */ + DISTRIB_DELETE_HASH, /* Perform a DELETE with hash value check */ + DISTRIB_DELETE_MODULO, /* Perform a DELETE with modulo value check */ + DISTRIB_COPY_TO, /* Perform a COPY TO */ + DISTRIB_COPY_FROM, /* Perform a COPY FROM */ + DISTRIB_TRUNCATE, /* Truncate relation */ + DISTRIB_REINDEX /* Reindex relation */ +} RedistribOperation; + +/* + * Determine if operation can be done before or after + * catalog update on local node. + */ +typedef enum RedistribCatalog { + CATALOG_UPDATE_NONE, /* Default state */ + CATALOG_UPDATE_AFTER, /* After catalog update */ + CATALOG_UPDATE_BEFORE, /* Before catalog update */ + CATALOG_UPDATE_BOTH /* Before and after catalog update */ +} RedistribCatalog; + +/* + * Redistribution command + * This contains the tools necessary to perform a redistribution operation. + */ +typedef struct RedistribCommand { + RedistribOperation type; /* Operation type */ + ExecNodes* execNodes; /* List of nodes where to perform operation */ + RedistribCatalog updateState; /* Flag to determine if operation can be done before or after catalog update */ +} RedistribCommand; + +/* + * Redistribution operation state + * Maintainer of redistribution state having the list of commands + * to be performed during redistribution. + * For the list of commands, we use an array and not a simple list as operations + * might need to be done in a certain order. + */ +typedef struct RedistribState { + Oid relid; /* Oid of relation redistributed */ + List* commands; /* List of commands */ + Tuplestorestate* store; /* Tuple store used for temporary data storage */ +} RedistribState; + +extern void PGXCRedistribTable(RedistribState* distribState, RedistribCatalog type); +extern void PGXCRedistribCreateCommandList(RedistribState* distribState, RelationLocInfo* newLocInfo); +extern RedistribCommand* makeRedistribCommand(RedistribOperation type, + RedistribCatalog updateState, ExecNodes* nodes); +extern RedistribState* makeRedistribState(Oid relOid); +extern void FreeRedistribState(RedistribState* state); +extern void FreeRedistribCommand(RedistribCommand* command); + +extern List* AlterTableSetRedistribute(Relation rel, RedisRelAction action, char *merge_list); +extern void AlterTableSetPartRelOptions( + Relation rel, List* defList, AlterTableType operation, LOCKMODE lockmode, char *merge_list, RedisRelAction action); +extern void RelationGetCtids(Relation rel, ItemPointer start_ctid, ItemPointer end_ctid); +extern uint32 RelationGetEndBlock(Relation rel); +extern void get_redis_rel_ctid( + const char* rel_name, const char* partition_name, RedisCtidType ctid_type, ItemPointer result); +#ifdef ENABLE_MULTIPLE_NODES +extern void CheckRedistributeOption(List* options, Oid* rel_cn_oid, + RedisHtlAction* action, char **merge_list, Relation rel); +#else +extern void CheckRedistributeOption(List* options, Oid* rel_cn_oid, + RedisHtlAction* action, Relation rel); +#endif + + +extern bool set_proc_redis(void); +extern bool reset_proc_redis(void); + +extern void RemoveRedisRelOptionsFromList(List** reloptions); +extern Node* eval_redis_func_direct(Relation rel, bool is_func_get_start_ctid, int num_of_slice = 0, int slice_index = 0); +extern List* add_ctid_string_to_reloptions(List *def_list, const char *item_name, ItemPointer ctid); +extern ItemPointer eval_redis_func_direct_slice(ItemPointer start_ctid, ItemPointer end_ctid, bool is_func_get_start_ctid, int num_of_slices, int slice_index); + +/* + * ItemPointerGetBlockNumber + * Returns the block number of a disk item pointer. + */ +#define RedisCtidGetBlockNumber(pointer) (AssertMacro((pointer) != NULL), BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetOffsetNumber + * Returns the offset number of a disk item pointer. + */ +#define RedisCtidGetOffsetNumber(pointer) (AssertMacro((pointer) != NULL), (pointer)->ip_posid) + +#endif /* REDISTRIB_H */ diff -uprN postgresql-hll-2.14_old/include/include/pgxc/remoteCombiner.h postgresql-hll-2.14/include/include/pgxc/remoteCombiner.h --- postgresql-hll-2.14_old/include/include/pgxc/remoteCombiner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/remoteCombiner.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,157 @@ + +#ifndef REMOTE_COMBINER_H +#define REMOTE_COMBINER_H + +#include "locator.h" +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "access/tupdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "nodes/pg_list.h" +#include "optimizer/pgxcplan.h" +#include "tcop/dest.h" +#include "tcop/pquery.h" +#include "tcop/utility.h" +#include "utils/lsyscache.h" +#include "utils/snapshot.h" +#include "utils/rowstore.h" + +typedef enum { + REQUEST_TYPE_NOT_DEFINED, /* not determined yet */ + REQUEST_TYPE_COMMAND, /* OK or row count response */ + REQUEST_TYPE_QUERY, /* Row description response */ + REQUEST_TYPE_COPY_IN, /* Copy In response */ + REQUEST_TYPE_COPY_OUT, /* Copy Out response */ + REQUEST_TYPE_COMMITING /* Commiting response */ +} RequestType; + +/* + * Type of requests associated to a remote COPY OUT + */ +typedef enum { + REMOTE_COPY_NONE, /* Not defined yet */ + REMOTE_COPY_STDOUT, /* Send back to client */ + REMOTE_COPY_FILE, /* Write in file */ + REMOTE_COPY_TUPLESTORE /* Store data in tuplestore */ +} RemoteCopyType; + +typedef struct NodeIdxInfo { + Oid nodeoid; + int nodeidx; +} NodeIdxInfo; + +typedef enum { + PBE_NONE = 0, /* no pbe or for initialization */ + PBE_ON_ONE_NODE, /* pbe running on one datanode for now */ + PBE_ON_MULTI_NODES /* pbe running on more than one datanode */ +} PBERunStatus; + +typedef struct ParallelFunctionState { + char* sql_statement; + ExecNodes* exec_nodes; + TupleDesc tupdesc; + Tuplestorestate* tupstore; + int64 result; + void* resultset; + MemoryContext slotmxct; + bool read_only; + bool need_tran_block; + /* if anyarray data received from remote nodes and need store in tuple, this flag shoud be true. + * because remote nodes use anyarry_out transform anyarray to string, so transform string to + * anyarray in local node is required */ + bool need_transform_anyarray; + /* this flag is for execute direct on multi nodes, if set this to true, executer will only get active + * nodes connections. */ + bool active_nodes_only; +} ParallelFunctionState; + +typedef bool (*fetchTupleFun)( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate); + +typedef struct RemoteQueryState { + ScanState ss; /* its first field is NodeTag */ + int node_count; /* total count of participating nodes */ + PGXCNodeHandle** connections; /* Datanode connections being combined */ + int conn_count; /* count of active connections */ + int current_conn; /* used to balance load when reading from connections */ + CombineType combine_type; /* see CombineType enum */ + int command_complete_count; /* count of received CommandComplete messages */ + RequestType request_type; /* see RequestType enum */ + TupleDesc tuple_desc; /* tuple descriptor to be referenced by emitted tuples */ + int description_count; /* count of received RowDescription messages */ + int copy_in_count; /* count of received CopyIn messages */ + int copy_out_count; /* count of received CopyOut messages */ + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + char* hint; /* hint message to send back to client */ + char* query; /* query message to send back to client */ + int cursorpos; /* cursor index into query string */ + bool is_fatal_error; /* mark if it is a FATAL error */ + bool query_Done; /* query has been sent down to Datanodes */ + RemoteDataRowData currentRow; /* next data ro to be wrapped into a tuple */ + RowStoreManager row_store; /* buffer where rows are stored when connection + should be cleaned for reuse by other RemoteQuery*/ + /* + * To handle special case - if this RemoteQuery is feeding sorted data to + * Sort plan and if the connection fetching data from the Datanode + * is buffered. If EOF is reached on a connection it should be removed from + * the array, but we need to know node number of the connection to find + * messages in the buffer. So we store nodenum to that array if reach EOF + * when buffering + */ + int* tapenodes; + RemoteCopyType remoteCopyType; /* Type of remote COPY operation */ + FILE* copy_file; /* used if remoteCopyType == REMOTE_COPY_FILE */ + uint64 processed; /* count of data rows when running CopyOut */ + /* cursor support */ + char* cursor; /* cursor name */ + char* update_cursor; /* throw this cursor current tuple can be updated */ + int cursor_count; /* total count of participating nodes */ + PGXCNodeHandle** cursor_connections; /* Datanode connections being combined */ + /* Support for parameters */ + char* paramval_data; /* parameter data, format is like in BIND */ + int paramval_len; /* length of parameter values data */ + Oid* rqs_param_types; /* Types of the remote params */ + int rqs_num_params; + + int eflags; /* capability flags to pass to tuplestore */ + bool eof_underlying; /* reached end of underlying plan? */ + Tuplestorestate* tuplestorestate; + CommandId rqs_cmd_id; /* Cmd id to use in some special cases */ + uint64 rqs_processed; /* Number of rows processed (only for DMLs) */ + uint64 rqs_cur_processed; /* Number of rows processed for currently processed DN */ + + void* tuplesortstate; /* for merge tuplesort */ + void* batchsortstate; /* for merge batchsort */ + fetchTupleFun fetchTuple; + bool need_more_data; + RemoteErrorData remoteErrData; /* error data from remote */ + bool need_error_check; /* if need check other errors? */ + int64 analyze_totalrowcnt[ANALYZEDELTA]; /* save total row count received from dn under analyzing. */ + int64 analyze_memsize[ANALYZEDELTA]; /* save processed row count from dn under analyzing. */ + int valid_command_complete_count; /* count of valid complete count */ + + RemoteQueryType position; /* the position where the RemoteQuery node will run. */ + bool* switch_connection; /* mark if connection reused by other RemoteQuery */ + bool refresh_handles; + NodeIdxInfo* nodeidxinfo; + PBERunStatus pbe_run_status; /* record running status of a pbe remote query */ + + bool resource_error; /* true if error from the compute pool */ + char* previousNodeName; /* previous DataNode that rowcount is different from current DataNode */ + char* serializedPlan; /* the serialized plan tree */ + ParallelFunctionState* parallel_function_state; +} RemoteQueryState; + +extern RemoteQueryState* CreateResponseCombiner(int node_count, CombineType combine_type); +extern RemoteQueryState* CreateResponseCombinerForBarrier(int nodeCount, CombineType combineType); +extern bool validate_combiner(RemoteQueryState* combiner); +extern void CloseCombiner(RemoteQueryState* combiner); +extern void CloseCombinerForBarrier(RemoteQueryState* combiner); +extern bool ValidateAndCloseCombiner(RemoteQueryState* combiner); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/remotecopy.h postgresql-hll-2.14/include/include/pgxc/remotecopy.h --- postgresql-hll-2.14_old/include/include/pgxc/remotecopy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/remotecopy.h 2020-12-12 17:06:43.249348064 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * remotecopy.h + * Routines for extension of COPY command for cluster management + * + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/remotecopy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REMOTECOPY_H +#define REMOTECOPY_H + +#include "nodes/parsenodes.h" +#include "commands/formatter.h" + +/* + * This contains the set of data necessary for remote COPY control. + */ +typedef struct RemoteCopyData { + /* COPY FROM/TO? */ + bool is_from; + + /* + * On Coordinator we need to rewrite query. + * While client may submit a copy command dealing with file, Datanodes + * always send/receive data to/from the Coordinator. So we can not use + * original statement and should rewrite statement, specifing STDIN/STDOUT + * as copy source or destination + */ + StringInfoData query_buf; + + /* Execution nodes for COPY */ + ExecNodes* exec_nodes; + + /* Locator information */ + RelationLocInfo* rel_loc; /* the locator key */ + List* idx_dist_by_col; /* index of the distributed by column */ + + PGXCNodeHandle** connections; /* Involved Datanode connections */ +} RemoteCopyData; + +/* + * List of all the options used for query deparse step + * As CopyStateData stays private in copy.c and in order not to + * make Postgres-XC code too much intrusive in PostgreSQL code, + * this intermediate structure is used primarily to generate remote + * COPY queries based on deparsed options. + */ +typedef struct RemoteCopyOptions { + bool rco_oids; /* include OIDs? */ + bool rco_freeze; + bool rco_without_escaping; + bool rco_ignore_extra_data; + char* rco_delim; /* column delimiter (must be 1 byte) */ + char* rco_null_print; /* NULL marker string (server encoding!) */ + char* rco_quote; /* CSV quote char (must be 1 byte) */ + char* rco_escape; /* CSV escape char (must be 1 byte) */ + char* rco_eol; /* user defined EOL string */ + List* rco_force_quote; /* list of column names */ + List* rco_force_notnull; /* list of column names */ + Formatter* rco_formatter; + FileFormat rco_format; + int rco_eol_type; + char* rco_date_format; /* customed date format */ + char* rco_time_format; /* customed time format */ + char* rco_timestamp_format; /* customed timestamp format */ + char* rco_smalldatetime_format; /* customed smalldatetime format */ + bool rco_compatible_illegal_chars; /* compatible illegal chars conversion flag */ + bool rco_fill_missing_fields; /* fill missing fields */ +} RemoteCopyOptions; + +extern void RemoteCopy_BuildStatement( + RemoteCopyData* state, Relation rel, RemoteCopyOptions* options, List* attnamelist, List* attnums); +extern void RemoteCopy_GetRelationLoc(RemoteCopyData* state, Relation rel, List* attnums); +extern RemoteCopyOptions* makeRemoteCopyOptions(void); +extern void FreeRemoteCopyData(RemoteCopyData* state); +extern void FreeRemoteCopyOptions(RemoteCopyOptions* options); +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/remoteHandler.h postgresql-hll-2.14/include/include/pgxc/remoteHandler.h --- postgresql-hll-2.14_old/include/include/pgxc/remoteHandler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/remoteHandler.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,11 @@ +#ifndef REMOTE_HANDLER_H +#define REMOTE_HANDLER_H + +#include "pgxcnode.h" +#include "executor/lightProxy.h" + +extern int light_handle_response(PGXCNodeHandle* conn, lightProxyMsgCtl* msgctl, lightProxy* lp); +extern void light_node_report_error(lightProxyErrData* combiner); +extern void HandleCmdComplete(CmdType commandType, CombineTag* combine, const char* msg_body, size_t len); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/pgxc/route.h postgresql-hll-2.14/include/include/pgxc/route.h --- postgresql-hll-2.14_old/include/include/pgxc/route.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/pgxc/route.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,68 @@ +/*--------------------------------------------------------------------------------------- + * + * route.h + * + * route + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/executor/route.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef SENDROUTER_HEADER +#define SENDROUTER_HEADER + +#include "catalog/pg_type.h" +#include "postgres.h" +#include "utils/relcache.h" +#include "utils/guc.h" +#include "nodes/pg_list.h" +#include "pgxcnode.h" + +#define HAS_ROUTER (u_sess->attr.attr_common.enable_router && u_sess->exec_cxt.CurrentRouter != NULL && \ + IS_PGXC_COORDINATOR && IsConnFromApp()) +#define ENABLE_ROUTER(cmdtype) (HAS_ROUTER && ((cmdtype) == CMD_SELECT || (cmdtype) == CMD_UPDATE || \ + (cmdtype) == CMD_INSERT || (cmdtype) == CMD_DELETE || (cmdtype) == CMD_MERGE)) +#define ENABLE_ROUTER_DN (IS_PGXC_DATANODE && u_sess->attr.attr_common.enable_router \ + && u_sess->exec_cxt.is_dn_enable_router) + +extern bool check_router_attr(char** newval, void** extra, GucSource source); +extern void assign_router_attr(const char* newval, void* extra); + +typedef struct RouteMsg { + char* table_name; + List* key_vals; + int key_num; +} RouteMsg; + +class SendRouter : public BaseObject { +public: + SendRouter() + { + m_table_oid = InvalidOid; + m_node_id = -1; + }; + SendRouter(Oid table_oid, int node_id); + ~SendRouter() {}; +public: + static bool ParseRouterAttr(const char* newval, RouteMsg* attr); + static Oid GetRelationOid(const char* table_name); + static int CountNodeId(struct RouteMsg* attr); + int GetRouterNodeId(); + void Destory(); + +private: + Oid m_table_oid; + int m_node_id; +}; + + +#endif /* SENDROUTER_HEADER */ diff -uprN postgresql-hll-2.14_old/include/include/port/aix.h postgresql-hll-2.14/include/include/port/aix.h --- postgresql-hll-2.14_old/include/include/port/aix.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/aix.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,5 @@ +/* + * src/include/port/aix.h + */ +#define CLASS_CONFLICT +#define DISABLE_XOPEN_NLS diff -uprN postgresql-hll-2.14_old/include/include/port/cygwin.h postgresql-hll-2.14/include/include/port/cygwin.h --- postgresql-hll-2.14_old/include/include/port/cygwin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/cygwin.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,22 @@ +/* src/include/port/cygwin.h */ + +#include + +/* + * Check for b20.1 and disable AF_UNIX family socket support. + */ +#if CYGWIN_VERSION_DLL_MAJOR < 1001 +#undef HAVE_UNIX_SOCKETS +#endif + +#if __GNUC__ && !defined(__declspec) +#error You need egcs 1.1 or newer for compiling! +#endif + +#ifdef BUILDING_DLL +#define PGDLLIMPORT __declspec(dllexport) +#else +#define PGDLLIMPORT __declspec(dllimport) +#endif + +#define PGDLLEXPORT diff -uprN postgresql-hll-2.14_old/include/include/port/darwin.h postgresql-hll-2.14/include/include/port/darwin.h --- postgresql-hll-2.14_old/include/include/port/darwin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/darwin.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,12 @@ +/* src/include/port/darwin.h */ +#ifndef PORT_DARWIN_H +#define PORT_DARWIN_H + +#define __darwin__ 1 + +#if HAVE_DECL_F_FULLFSYNC /* not present before OS X 10.3 */ +#define HAVE_FSYNC_WRITETHROUGH + +#endif + +#endif /* PORT_DARWIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/freebsd.h postgresql-hll-2.14/include/include/port/freebsd.h --- postgresql-hll-2.14_old/include/include/port/freebsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/freebsd.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/freebsd.h */ +#ifndef PORT_FREEBSD_H +#define PORT_FREEBSD_H + +#endif /* PORT_FREEBSD_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/hpux.h postgresql-hll-2.14/include/include/port/hpux.h --- postgresql-hll-2.14_old/include/include/port/hpux.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/hpux.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/hpux.h */ +#ifndef PORT_HPUX_H +#define PORT_HPUX_H + +/* nothing needed */ +#endif /* PORT_HPUX_H */ + diff -uprN postgresql-hll-2.14_old/include/include/port/irix.h postgresql-hll-2.14/include/include/port/irix.h --- postgresql-hll-2.14_old/include/include/port/irix.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/irix.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,12 @@ +/* src/include/port/irix.h */ + +#ifndef PORT_IRIX_H +#define PORT_IRIX_H + +/* + * IRIX 6.5.26f and 6.5.22f (at least) have a strtod() that accepts + * "infinity", but leaves endptr pointing to "inity". + */ +#define HAVE_BUGGY_IRIX_STRTOD + +#endif /* PORT_IRIX_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/linux.h postgresql-hll-2.14/include/include/port/linux.h --- postgresql-hll-2.14_old/include/include/port/linux.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/linux.h 2020-12-12 17:06:43.250348077 +0800 @@ -0,0 +1,26 @@ +/* src/include/port/linux.h */ + +/* + * As of July 2007, all known versions of the Linux kernel will sometimes + * return EIDRM for a shmctl() operation when EINVAL is correct (it happens + * when the low-order 15 bits of the supplied shm ID match the slot number + * assigned to a newer shmem segment). We deal with this by assuming that + * EIDRM means EINVAL in PGSharedMemoryIsInUse(). This is reasonably safe + * since in fact Linux has no excuse for ever returning EIDRM; it doesn't + * track removed segments in a way that would allow distinguishing them from + * private ones. But someday that code might get upgraded, and we'd have + * to have a kernel version test here. + */ +#ifndef LINUX_H +#define LINUX_H + +#define HAVE_LINUX_EIDRM_BUG + +/* + * Set the default wal_sync_method to fdatasync. With recent Linux versions, + * xlogdefs.h's normal rules will prefer open_datasync, which (a) doesn't + * perform better and (b) causes outright failures on ext4 data=journal + * filesystems, because those don't support O_DIRECT. + */ +#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#endif diff -uprN postgresql-hll-2.14_old/include/include/port/netbsd.h postgresql-hll-2.14/include/include/port/netbsd.h --- postgresql-hll-2.14_old/include/include/port/netbsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/netbsd.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/netbsd.h */ +#ifndef PORT_NETBSD_H +#define PORT_NETBSD_H + +#endif /* PORT_NETBSD_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/openbsd.h postgresql-hll-2.14/include/include/port/openbsd.h --- postgresql-hll-2.14_old/include/include/port/openbsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/openbsd.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/openbsd.h */ +#ifndef PORT_OPENBSD_H +#define PORT_OPENBSD_H + +#endif /* PORT_OPENBSD_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/osf.h postgresql-hll-2.14/include/include/port/osf.h --- postgresql-hll-2.14_old/include/include/port/osf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/osf.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,4 @@ +/* src/include/port/osf.h */ + +#define NOFIXADE +#define DISABLE_XOPEN_NLS diff -uprN postgresql-hll-2.14_old/include/include/port/pg_bswap.h postgresql-hll-2.14/include/include/port/pg_bswap.h --- postgresql-hll-2.14_old/include/include/port/pg_bswap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/pg_bswap.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,65 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_bswap.h + * Byte swapping. + * + * Macros for reversing the byte order of 32-bit and 64-bit unsigned integers. + * For example, 0xAABBCCDD becomes 0xDDCCBBAA. These are just wrappers for + * built-in functions provided by the compiler where support exists. + * + * Note that the GCC built-in functions __builtin_bswap32() and + * __builtin_bswap64() are documented as accepting single arguments of type + * uint32_t and uint64_t respectively (these are also the respective return + * types). Use caution when using these wrapper macros with signed integers. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Copyright (c) 2015-2016, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/port/pg_bswap.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_BSWAP_H +#define PG_BSWAP_H + +#ifdef HAVE__BUILTIN_BSWAP32 +#define BSWAP32(x) __builtin_bswap32(x) +#else +#define BSWAP32(x) \ + (((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | ((x >> 24) & 0x000000ff)) +#endif /* HAVE__BUILTIN_BSWAP32 */ + +#ifdef HAVE__BUILTIN_BSWAP64 +#define BSWAP64(x) __builtin_bswap64(x) +#else +#define BSWAP64(x) \ + (((x << 56) & 0xff00000000000000UL) | ((x << 40) & 0x00ff000000000000UL) | ((x << 24) & 0x0000ff0000000000UL) | \ + ((x << 8) & 0x000000ff00000000UL) | ((x >> 8) & 0x00000000ff000000UL) | ((x >> 24) & 0x0000000000ff0000UL) | \ + ((x >> 40) & 0x000000000000ff00UL) | ((x >> 56) & 0x00000000000000ffUL)) +#endif /* HAVE__BUILTIN_BSWAP64 */ + +/* + * Rearrange the bytes of a Datum from big-endian order into the native byte + * order. On big-endian machines, this does nothing at all. Note that the C + * type Datum is an unsigned integer type on all platforms. + * + * One possible application of the DatumBigEndianToNative() macro is to make + * bitwise comparisons cheaper. A simple 3-way comparison of Datums + * transformed by the macro (based on native, unsigned comparisons) will return + * the same result as a memcmp() of the corresponding original Datums, but can + * be much cheaper. It's generally safe to do this on big-endian systems + * without any special transformation occurring first. + */ +#ifdef WORDS_BIGENDIAN +#define DatumBigEndianToNative(x) (x) +#else /* !WORDS_BIGENDIAN */ +#if SIZEOF_DATUM == 8 +#define DatumBigEndianToNative(x) BSWAP64(x) +#else /* SIZEOF_DATUM != 8 */ +#define DatumBigEndianToNative(x) BSWAP32(x) +#endif /* SIZEOF_DATUM == 8 */ +#endif /* WORDS_BIGENDIAN */ + +#endif /* PG_BSWAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/pg_crc32c.h postgresql-hll-2.14/include/include/port/pg_crc32c.h --- postgresql-hll-2.14_old/include/include/port/pg_crc32c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/pg_crc32c.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,103 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_crc32c.h + * Routines for computing CRC-32C checksums. + * + * The speed of CRC-32C calculation has a big impact on performance, so we + * jump through some hoops to get the best implementation for each + * platform. Some CPU architectures have special instructions for speeding + * up CRC calculations (e.g. Intel SSE 4.2), on other platforms we use the + * Slicing-by-8 algorithm which uses lookup tables. + * + * The public interface consists of four macros: + * + * INIT_CRC32C(crc) + * Initialize a CRC accumulator + * + * COMP_CRC32C(crc, data, len) + * Accumulate some (more) bytes into a CRC + * + * FIN_CRC32C(crc) + * Finish a CRC calculation + * + * EQ_CRC32C(c1, c2) + * Check for equality of two CRCs. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/port/pg_crc32c.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_CRC32C_H +#define PG_CRC32C_H + +#include "port/pg_bswap.h" + +typedef uint32 pg_crc32c; + +/* The INIT and EQ macros are the same for all implementations. */ +#define INIT_CRC32C(crc) ((crc) = 0xFFFFFFFF) +#define EQ_CRC32C(c1, c2) ((c1) == (c2)) + +#if defined(__aarch64__) && defined(__GNUC__) +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32 pg_crc32c_hardware(uint32 crc, const void* data, Size len); + +#ifdef __cplusplus +} +#endif + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC32C(crc, data, len) \ + do { \ + (crc) = pg_crc32c_hardware((uint32)(crc), (const void*)(data), (Size)(len)); \ + } while (0) + +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +#elif defined(USE_SSE42_CRC32C) +/* Use SSE4.2 instructions. */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c_sse42((crc), (data), (len))) +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void* data, size_t len); + +#elif defined(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK) +/* + * Use SSE4.2 instructions, but perform a runtime check first to check that + * they are available. + */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c((crc), (data), (len))) +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void* data, size_t len); +extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void* data, size_t len); +extern pg_crc32c (*pg_comp_crc32c)(pg_crc32c crc, const void* data, size_t len); + +#else +/* + * Use slicing-by-8 algorithm. + * + * On big-endian systems, the intermediate value is kept in reverse byte + * order, to avoid byte-swapping during the calculation. FIN_CRC32C reverses + * the bytes to the final order. + */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c_sb8((crc), (data), (len))) +#ifdef WORDS_BIGENDIAN +#define FIN_CRC32C(crc) ((crc) = pg_bswap32(crc) ^ 0xFFFFFFFF) +#else +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) +#endif + +extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void* data, size_t len); + +#endif + +#endif /* PG_CRC32C_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/sco.h postgresql-hll-2.14/include/include/port/sco.h --- postgresql-hll-2.14_old/include/include/port/sco.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/sco.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,7 @@ +/* + * src/include/port/sco.h + * + * see src/backend/libpq/pqcomm.c */ +#define SCO_ACCEPT_BUG + +#define USE_UNIVEL_CC diff -uprN postgresql-hll-2.14_old/include/include/port/solaris.h postgresql-hll-2.14/include/include/port/solaris.h --- postgresql-hll-2.14_old/include/include/port/solaris.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/solaris.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,42 @@ +/* src/include/port/solaris.h */ + +/* + * Sort this out for all operating systems some time. The __xxx + * symbols are defined on both GCC and Solaris CC, although GCC + * doesn't document them. The __xxx__ symbols are only on GCC. + */ +#ifndef SRC_INCLUDE_PORT_SOLARIS_H +#define SRC_INCLUDE_PORT_SOLARIS_H +#if defined(__i386) && !defined(__i386__) +#define __i386__ +#endif + +#if defined(__amd64) && !defined(__amd64__) +#define __amd64__ +#endif + +#if defined(__x86_64) && !defined(__x86_64__) +#define __x86_64__ +#endif + +#if defined(__sparc) && !defined(__sparc__) +#define __sparc__ +#endif + +#if defined(__i386__) +#include +#endif + +/* + * Many versions of Solaris have broken strtod() --- see bug #4751182. + * This has been fixed in current versions of Solaris: + * + * http://sunsolve.sun.com/search/document.do?assetkey=1-21-108993-62-1&searchclause=108993-62 + * http://sunsolve.sun.com/search/document.do?assetkey=1-21-112874-34-1&searchclause=112874-34 + * + * However, many people might not have patched versions, so + * still use our own fix for the buggy version. + */ +#define HAVE_BUGGY_SOLARIS_STRTOD + +#endif // SRC_INCLUDE_PORT_SOLARIS_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/port/unixware.h postgresql-hll-2.14/include/include/port/unixware.h --- postgresql-hll-2.14_old/include/include/port/unixware.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/unixware.h 2020-12-12 17:06:43.251348090 +0800 @@ -0,0 +1,11 @@ +/* + * src/include/port/unixware.h + * + * see src/backend/libpq/pqcomm.c */ +#define SCO_ACCEPT_BUG + +/*************************************** + * Define this if you are compiling with + * the native UNIXWARE C compiler. + ***************************************/ +#define USE_UNIVEL_CC diff -uprN postgresql-hll-2.14_old/include/include/port/win32/arpa/inet.h postgresql-hll-2.14/include/include/port/win32/arpa/inet.h --- postgresql-hll-2.14_old/include/include/port/win32/arpa/inet.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/arpa/inet.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/win32/arpa/inet.h */ +#ifndef WIN32_ARPA_INET_H +#define WIN32_ARPA_INET_H + +#include + +#endif /* WIN32_ARPA_INET_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/dlfcn.h postgresql-hll-2.14/include/include/port/win32/dlfcn.h --- postgresql-hll-2.14_old/include/include/port/win32/dlfcn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/dlfcn.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/dlfcn.h */ +#ifndef PORT_WIN32_DLFCN_H +#define PORT_WIN32_DLFCN_H + +#endif /* PORT_WIN32_DLFCN_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/grp.h postgresql-hll-2.14/include/include/port/win32/grp.h --- postgresql-hll-2.14_old/include/include/port/win32/grp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/grp.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/grp.h */ +#ifndef PORT_WIN32_GRP_H +#define PORT_WIN32_GRP_H + +#endif /* PORT_WIN32_GRP_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/netdb.h postgresql-hll-2.14/include/include/port/win32/netdb.h --- postgresql-hll-2.14_old/include/include/port/win32/netdb.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/netdb.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/netdb.h */ +#ifndef PORT_WIN32_NETDB_H +#define PORT_WIN32_NETDB_H + +#endif /* PORT_WIN32_NETDB_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/netinet/in.h postgresql-hll-2.14/include/include/port/win32/netinet/in.h --- postgresql-hll-2.14_old/include/include/port/win32/netinet/in.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/netinet/in.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/win32/netinet/in.h */ +#ifndef WIN32_NETINET_IN_H +#define WIN32_NETINET_IN_H + +#include + +#endif /* WIN32_NETINET_IN_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/pwd.h postgresql-hll-2.14/include/include/port/win32/pwd.h --- postgresql-hll-2.14_old/include/include/port/win32/pwd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/pwd.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,8 @@ +/* + * src/include/port/win32/pwd.h + */ + +#ifndef PORT_WIN32_PWD_H +#define PORT_WIN32_PWD_H + +#endif /* PORT_WIN32_PWD_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/sys/socket.h postgresql-hll-2.14/include/include/port/win32/sys/socket.h --- postgresql-hll-2.14_old/include/include/port/win32/sys/socket.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/sys/socket.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,34 @@ +/* + * src/include/port/win32/sys/socket.h + */ +#ifndef WIN32_SYS_SOCKET_H +#define WIN32_SYS_SOCKET_H + +/* + * Unfortunately, of VC++ also defines ERROR. + * To avoid the conflict, we include here and undefine ERROR + * immediately. + * + * Note: Don't include directly. It causes compile errors. + */ +#include +#include +#define _WINSOCKAPI_ +#include + +#undef ERROR +#undef small + +/* Restore old ERROR value */ +#ifdef PGERROR +#define ERROR PGERROR +#endif + +/* + * we can't use the windows gai_strerror{AW} functions because + * they are defined inline in the MS header files. So we'll use our + * own + */ +#undef gai_strerror + +#endif /* WIN32_SYS_SOCKET_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32/sys/wait.h postgresql-hll-2.14/include/include/port/win32/sys/wait.h --- postgresql-hll-2.14_old/include/include/port/win32/sys/wait.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32/sys/wait.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,7 @@ +/* + * src/include/port/win32/sys/wait.h + */ +#ifndef PORT_WIN32SYS_WAIT_H +#define PORT_WIN32SYS_WAIT_H + +#endif /* PORT_WIN32SYS_WAIT_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32.h postgresql-hll-2.14/include/include/port/win32.h --- postgresql-hll-2.14_old/include/include/port/win32.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,469 @@ +/* src/include/port/win32.h */ + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define WIN32_ONLY_COMPILER +#endif + +/* + * Make sure _WIN32_WINNT has the minimum required value. + * Leave a higher value in place. + */ +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501 +#undef _WIN32_WINNT +#endif +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif +/* + * Always build with SSPI support. Keep it as a #define in case + * we want a switch to disable it sometime in the future. + */ +#ifndef __BORLANDC__ +#define ENABLE_SSPI 1 +#endif + +/* undefine and redefine after #include */ +#undef mkdir + +#undef ERROR + +/* + * The Mingw64 headers choke if this is already defined - they + * define it themselves. + */ +#if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER) +#define _WINSOCKAPI_ +#endif +#include +#include +#define _WINSOCKAPI_ +#include +#undef small +#include +#include +#include +#include +#ifndef __BORLANDC__ +#include /* for non-unicode version */ +#endif +#undef near + +/* Must be here to avoid conflicting with prototype in windows.h */ +#define mkdir(a, b) mkdir(a) + +#define ftruncate(a, b) chsize(a, b) + +/* Windows doesn't have fsync() as such, use _commit() */ +#define fsync(fd) _commit(fd) + +/* + * For historical reasons, we allow setting wal_sync_method to + * fsync_writethrough on Windows, even though it's really identical to fsync + * (both code paths wind up at _commit()). + */ +#define HAVE_FSYNC_WRITETHROUGH +#define FSYNC_WRITETHROUGH_IS_FSYNC + +#define USES_WINSOCK + +/* defines for dynamic linking on Win32 platform */ +#if defined(WIN32) || defined(__CYGWIN__) + +#if __GNUC__ && !defined(__declspec) +#error You need egcs 1.1 or newer for compiling! +#endif + +#ifdef BUILDING_DLL +#define PGDLLIMPORT __declspec(dllexport) +#else /* not BUILDING_DLL */ +#define PGDLLIMPORT __declspec(dllimport) +#endif + +#ifdef _MSC_VER +#define PGDLLEXPORT __declspec(dllexport) +#else +#define PGDLLEXPORT +#endif +#else /* not CYGWIN, not MSVC, not MingW */ +#define PGDLLIMPORT +#define PGDLLEXPORT +#endif + +/* + * IPC defines + */ +#undef HAVE_UNION_SEMUN +#define HAVE_UNION_SEMUN 1 + +#define IPC_RMID 256 +#define IPC_CREAT 512 +#define IPC_EXCL 1024 +#define IPC_PRIVATE 234564 +#define IPC_NOWAIT 2048 +#define IPC_STAT 4096 + +#define EACCESS 2048 +#ifndef EIDRM +#define EIDRM 4096 +#endif + +#define SETALL 8192 +#define GETNCNT 16384 +#define GETVAL 65536 +#define SETVAL 131072 +#define GETPID 262144 + +/* + * Signal stuff + * + * For WIN32, there is no wait() call so there are no wait() macros + * to interpret the return value of system(). Instead, system() + * return values < 0x100 are used for exit() termination, and higher + * values are used to indicated non-exit() termination, which is + * similar to a unix-style signal exit (think SIGSEGV == + * STATUS_ACCESS_VIOLATION). Return values are broken up into groups: + * + * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx + * + * NT_SUCCESS 0 - 0x3FFFFFFF + * NT_INFORMATION 0x40000000 - 0x7FFFFFFF + * NT_WARNING 0x80000000 - 0xBFFFFFFF + * NT_ERROR 0xC0000000 - 0xFFFFFFFF + * + * Effectively, we don't care on the severity of the return value from + * system(), we just need to know if it was because of exit() or generated + * by the system, and it seems values >= 0x100 are system-generated. + * See this URL for a list of WIN32 STATUS_* values: + * + * Wine (URL used in our error messages) - + * http://source.winehq.org/source/include/ntstatus.h + * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt + * MS SDK - http://www.nologs.com/ntstatus.html + * + * It seems the exception lists are in both ntstatus.h and winnt.h, but + * ntstatus.h has a more comprehensive list, and it only contains + * exception values, rather than winnt, which contains lots of other + * things: + * + * http://www.microsoft.com/msj/0197/exception/exception.aspx + * + * The ExceptionCode parameter is the number that the operating system + * assigned to the exception. You can see a list of various exception codes + * in WINNT.H by searching for #defines that start with "STATUS_". For + * example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is + * 0xC0000005. A more complete set of exception codes can be found in + * NTSTATUS.H from the Windows NT DDK. + * + * Some day we might want to print descriptions for the most common + * exceptions, rather than printing an include file name. We could use + * RtlNtStatusToDosError() and pass to FormatMessage(), which can print + * the text of error values, but MinGW does not support + * RtlNtStatusToDosError(). + */ +#define WIFEXITED(w) (((w)&0XFFFFFF00) == 0) +#define WIFSIGNALED(w) (!WIFEXITED(w)) +#define WEXITSTATUS(w) (w) +#define WTERMSIG(w) (w) + +#define sigmask(sig) (1 << ((sig)-1)) + +/* Signal function return values */ +#undef SIG_DFL +#undef SIG_ERR +#undef SIG_IGN +#define SIG_DFL ((pqsigfunc)0) +#define SIG_ERR ((pqsigfunc)-1) +#define SIG_IGN ((pqsigfunc)1) + +/* Some extra signals */ +#define SIGHUP 1 +#define SIGQUIT 3 +#define SIGTRAP 5 +#define SIGABRT 22 /* Set to match W32 value -- not UNIX value */ +#define SIGKILL 9 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */ +#define SIGWINCH 28 +#ifndef __BORLANDC__ +#define SIGUSR1 30 +#define SIGUSR2 31 +#endif + +/* + * New versions of mingw have gettimeofday() and also declare + * struct timezone to support it. + */ +#ifndef HAVE_GETTIMEOFDAY +struct timezone { + int tz_minuteswest; /* Minutes west of GMT. */ + int tz_dsttime; /* Nonzero if DST is ever in effect. */ +}; +#endif + +/* for setitimer in backend/port/win32/timer.c */ +#define ITIMER_REAL 0 +struct itimerval { + struct timeval it_interval; + struct timeval it_value; +}; + +int setitimer(int which, const struct itimerval* value, struct itimerval* ovalue); + +/* + * WIN32 does not provide 64-bit off_t, but does provide the functions operating + * with 64-bit offsets. + */ +#define pgoff_t __int64 +#ifdef WIN32_ONLY_COMPILER +#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin) +#define ftello(stream) _ftelli64(stream) +#else +#ifndef fseeko +#define fseeko(stream, offset, origin) fseeko64(stream, offset, origin) +#endif +#ifndef ftello +#define ftello(stream) ftello64(stream) +#endif +#endif + +/* + * Supplement to . + * + * Perl already has typedefs for uid_t and gid_t. + */ +#ifndef PLPERL_HAVE_UID_GID +typedef int uid_t; +typedef int gid_t; +#endif +typedef long key_t; + +#ifdef WIN32_ONLY_COMPILER +typedef int pid_t; +#endif + +/* + * Supplement to . + */ +#define lstat(path, sb) stat((path), (sb)) + +/* + * Supplement to . + * This is the same value as _O_NOINHERIT in the MS header file. This is + * to ensure that we don't collide with a future definition. It means + * we cannot use _O_NOINHERIT ourselves. + */ +#define O_DSYNC 0x0080 + +/* + * Supplement to . + */ +#undef EAGAIN +#undef EINTR +#define EINTR WSAEINTR +#define EAGAIN WSAEWOULDBLOCK +#ifndef EMSGSIZE +#define EMSGSIZE WSAEMSGSIZE +#endif +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef ECONNRESET +#define ECONNRESET WSAECONNRESET +#endif +#ifndef EINPROGRESS +#define EINPROGRESS WSAEINPROGRESS +#endif +#ifndef ENOBUFS +#define ENOBUFS WSAENOBUFS +#endif +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#endif +#ifndef ECONNREFUSED +#define ECONNREFUSED WSAECONNREFUSED +#endif +#ifndef EBADFD +#define EBADFD WSAENOTSOCK +#endif +#ifndef EOPNOTSUPP +#define EOPNOTSUPP WSAEOPNOTSUPP +#endif + +/* + * For Microsoft Visual Studio 2010 and above we intentionally redefine + * the regular Berkeley error constants and set them to the WSA constants. + * Note that this will break if those constants are used for anything else + * than Windows Sockets errors. + */ +#if _MSC_VER >= 1600 +#pragma warning(disable : 4005) +#define EMSGSIZE WSAEMSGSIZE +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ECONNRESET WSAECONNRESET +#define EINPROGRESS WSAEINPROGRESS +#define ENOBUFS WSAENOBUFS +#define ECONNREFUSED WSAECONNREFUSED +#define EOPNOTSUPP WSAEOPNOTSUPP +#pragma warning(default : 4005) +#endif + +/* + * Extended locale functions with gratuitous underscore prefixes. + * (These APIs are nevertheless fully documented by Microsoft.) + */ +#define locale_t _locale_t +#define tolower_l _tolower_l +#define toupper_l _toupper_l +#define towlower_l _towlower_l +#define towupper_l _towupper_l +#define isdigit_l _isdigit_l +#define iswdigit_l _iswdigit_l +#define isalpha_l _isalpha_l +#define iswalpha_l _iswalpha_l +#define isalnum_l _isalnum_l +#define iswalnum_l _iswalnum_l +#define isupper_l _isupper_l +#define iswupper_l _iswupper_l +#define islower_l _islower_l +#define iswlower_l _iswlower_l +#define isgraph_l _isgraph_l +#define iswgraph_l _iswgraph_l +#define isprint_l _isprint_l +#define iswprint_l _iswprint_l +#define ispunct_l _ispunct_l +#define iswpunct_l _iswpunct_l +#define isspace_l _isspace_l +#define iswspace_l _iswspace_l +#define strcoll_l _strcoll_l +#define wcscoll_l _wcscoll_l +#define wcstombs_l _wcstombs_l +#define mbstowcs_l _mbstowcs_l + +/* In backend/port/win32/signal.c */ +extern PGDLLIMPORT volatile int pg_signal_queue; +extern PGDLLIMPORT int pg_signal_mask; +extern HANDLE pgwin32_signal_event; +extern HANDLE pgwin32_initial_signal_pipe; + +#define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask) + +void pgwin32_signal_initialize(void); +HANDLE pgwin32_create_signal_listener(pid_t pid); +void pgwin32_dispatch_queued_signals(void); +void pg_queue_signal(int signum); + +/* In backend/port/win32/socket.c */ +#ifndef FRONTEND +#define socket(af, type, protocol) pgwin32_socket(af, type, protocol) +#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen) +#define connect(s, name, namelen) pgwin32_connect(s, name, namelen) +#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout) +#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags) +#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags) + +SOCKET pgwin32_socket(int af, int type, int protocol); +SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen); +int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen); +int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout); +int pgwin32_recv(SOCKET s, char* buf, int len, int flags); +int pgwin32_send(SOCKET s, const void* buf, int len, int flags); + +const char* pgwin32_socket_strerror(int err); +int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout); + +extern int pgwin32_noblock; + +/* in backend/port/win32/security.c */ +extern int pgwin32_is_admin(void); +extern int pgwin32_is_service(void); +#endif + +/* in backend/port/win32_shmem.c */ +extern int pgwin32_ReserveSharedMemoryRegion(HANDLE); + +/* in backend/port/win32/crashdump.c */ +extern void pgwin32_install_crashdump_handler(void); + +/* in port/win32error.c */ +extern void _dosmaperr(unsigned long); + +/* in port/win32env.c */ +extern int pgwin32_putenv(const char*); +extern void pgwin32_unsetenv(const char*); + +#define putenv(x) pgwin32_putenv(x) +#define unsetenv(x) pgwin32_unsetenv(x) + +/* Things that exist in MingW headers, but need to be added to MSVC & BCC */ +#ifdef WIN32_ONLY_COMPILER + +#ifndef _WIN64 +typedef long ssize_t; +#else +typedef __int64 ssize_t; +#endif + +#ifndef __BORLANDC__ +typedef unsigned short mode_t; + +#define S_IRUSR _S_IREAD +#define S_IWUSR _S_IWRITE +#define S_IXUSR _S_IEXEC +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +/* see also S_IRGRP etc below */ +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#endif /* __BORLANDC__ */ + +#define F_OK 0 +#define X_OK 1 /* test for execute or search permission */ +#define W_OK 2 +#define R_OK 4 + +#define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF)) +#define isnan(x) _isnan(x) + +/* Pulled from Makefile.port in mingw */ +#define DLSUFFIX ".dll" + +#ifdef __BORLANDC__ + +/* for port/dirent.c */ +#ifndef INVALID_FILE_ATTRIBUTES +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + +/* for port/open.c */ +#ifndef O_RANDOM +#define O_RANDOM 0x0010 /* File access is primarily random */ +#define O_SEQUENTIAL 0x0020 /* File access is primarily sequential */ +#define O_TEMPORARY 0x0040 /* Temporary file bit */ +#define O_SHORT_LIVED 0x1000 /* Temporary storage file, try not to flush */ +#define _O_SHORT_LIVED O_SHORT_LIVED +#endif /* ifndef O_RANDOM */ +#endif /* __BORLANDC__ */ +#endif /* WIN32_ONLY_COMPILER */ + +/* These aren't provided by either MingW or MSVC */ +#ifndef __BORLANDC__ +#define S_IRGRP 0 +#define S_IWGRP 0 +#define S_IXGRP 0 +#define S_IRWXG 0 +#define S_IROTH 0 +#define S_IWOTH 0 +#define S_IXOTH 0 +#define S_IRWXO 0 + +#endif /* __BORLANDC__ */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/dirent.h postgresql-hll-2.14/include/include/port/win32_msvc/dirent.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/dirent.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/dirent.h 2020-12-12 17:06:43.252348103 +0800 @@ -0,0 +1,27 @@ +/* + * Headers for port/dirent.c, win32 native implementation of dirent functions + * + * src/include/port/win32_msvc/dirent.h + */ + +#ifndef _WIN32VC_DIRENT_H +#define _WIN32VC_DIRENT_H + +#ifdef WIN32 +#define MAX_PATH 256 +#endif + +struct dirent { + long d_ino; + unsigned short d_reclen; + unsigned short d_namlen; + char d_name[MAX_PATH]; +}; + +typedef struct DIR DIR; + +DIR* opendir(const char*); +struct dirent* readdir(DIR*); +int closedir(DIR*); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/file.h postgresql-hll-2.14/include/include/port/win32_msvc/sys/file.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/file.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/sys/file.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/file.h */ +#ifndef PORT_32MSVC_SYS_FILE_H +#define PORT_32MSVC_SYS_FILE_H + +#endif /* PORT_32MSVC_SYS_FILE_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/param.h postgresql-hll-2.14/include/include/port/win32_msvc/sys/param.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/param.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/sys/param.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/param.h */ +#ifndef PORT_MSVC_SYS_PARAM_H +#define PORT_MSVC_SYS_PARAM_H + +#endif /* PORT_MSVC_SYS_PARAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/time.h postgresql-hll-2.14/include/include/port/win32_msvc/sys/time.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/sys/time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/sys/time.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/time.h */ +#ifndef PORT_32MSVC_SYS_TIME_H +#define PORT_32MSVC_SYS_TIME_H + +#endif /* PORT_32MSVC_SYS_TIME_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/unistd.h postgresql-hll-2.14/include/include/port/win32_msvc/unistd.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/unistd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/unistd.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/unistd.h */ +#ifndef PORT_32MSVC_UNISTD_H +#define PORT_32MSVC_UNISTD_H + +#endif /* PORT_32MSVC_UNISTD_H */ diff -uprN postgresql-hll-2.14_old/include/include/port/win32_msvc/utime.h postgresql-hll-2.14/include/include/port/win32_msvc/utime.h --- postgresql-hll-2.14_old/include/include/port/win32_msvc/utime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port/win32_msvc/utime.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/utime.h */ +#ifndef PORT_32MSVC_UTIME_H +#define PORT_32MSVC_UTIME_H + +#endif /* PORT_32MSVC_UTIME_H */ diff -uprN postgresql-hll-2.14_old/include/include/portability/instr_time.h postgresql-hll-2.14/include/include/portability/instr_time.h --- postgresql-hll-2.14_old/include/include/portability/instr_time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/portability/instr_time.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,154 @@ +/* ------------------------------------------------------------------------- + * + * instr_time.h + * portable high-precision interval timing + * + * This file provides an abstraction layer to hide portability issues in + * interval timing. On Unix we use gettimeofday(), but on Windows that + * gives a low-precision result so we must use QueryPerformanceCounter() + * instead. These macros also give some breathing room to use other + * high-precision-timing APIs on yet other platforms. + * + * The basic data type is instr_time, which all callers should treat as an + * opaque typedef. instr_time can store either an absolute time (of + * unspecified reference time) or an interval. The operations provided + * for it are: + * + * INSTR_TIME_IS_ZERO(t) is t equal to zero? + * + * INSTR_TIME_SET_ZERO(t) set t to zero (memset is acceptable too) + * + * INSTR_TIME_SET_CURRENT(t) set t to current time + * + * INSTR_TIME_ADD(x, y) x += y + * + * INSTR_TIME_SUBTRACT(x, y) x -= y + * + * INSTR_TIME_ACCUM_DIFF(x, y, z) x += (y - z) + * + * INSTR_TIME_GET_DOUBLE(t) convert t to double (in seconds) + * + * INSTR_TIME_GET_MILLISEC(t) convert t to double (in milliseconds) + * + * INSTR_TIME_GET_MICROSEC(t) convert t to uint64 (in microseconds) + * + * Note that INSTR_TIME_SUBTRACT and INSTR_TIME_ACCUM_DIFF convert + * absolute times to intervals. The INSTR_TIME_GET_xxx operations are + * only useful on intervals. + * + * When summing multiple measurements, it's recommended to leave the + * running sum in instr_time form (ie, use INSTR_TIME_ADD or + * INSTR_TIME_ACCUM_DIFF) and convert to a result format only at the end. + * + * Beware of multiple evaluations of the macro arguments. + * + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/portability/instr_time.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_TIME_H +#define INSTR_TIME_H + +#ifndef WIN32 + +#include + +typedef struct timeval instr_time; + +#define INSTR_TIME_IS_ZERO(t) ((t).tv_usec == 0 && (t).tv_sec == 0) + +#define INSTR_TIME_IS_INTMAX(t) ((t).tv_usec == LONG_MAX && (t).tv_sec == LONG_MAX) + +#define INSTR_TIME_INITIAL_MIN(t) ((t).tv_usec = LONG_MAX, (t).tv_sec = LONG_MAX) + +#define INSTR_TIME_IS_BIGGER(x, y) ((x).tv_sec >= (y).tv_sec && (x).tv_usec >= (y).tv_usec) + +#define INSTR_TIME_SET_ZERO(t) ((t).tv_sec = 0, (t).tv_usec = 0) + +#define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) + +#define INSTR_TIME_ADD(x, y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define INSTR_TIME_SUBTRACT(x, y) \ + do { \ + (x).tv_sec -= (y).tv_sec; \ + (x).tv_usec -= (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + } while (0) + +#define INSTR_TIME_ACCUM_DIFF(x, y, z) \ + do { \ + (x).tv_sec += (y).tv_sec - (z).tv_sec; \ + (x).tv_usec += (y).tv_usec - (z).tv_usec; \ + /* Normalize after each add to avoid overflow/underflow of tv_usec */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define INSTR_TIME_GET_DOUBLE(t) (((double)(t).tv_sec) + ((double)(t).tv_usec) / 1000000.0) + +#define INSTR_TIME_GET_MILLISEC(t) (((double)(t).tv_sec * 1000.0) + ((double)(t).tv_usec) / 1000.0) + +#define INSTR_TIME_GET_MICROSEC(t) (((uint64)(t).tv_sec * (uint64)1000000) + (uint64)(t).tv_usec) +#else /* WIN32 */ + +typedef LARGE_INTEGER instr_time; + +#define INSTR_TIME_IS_ZERO(t) ((t).QuadPart == 0) + +#define INSTR_TIME_IS_INTMAX(t) ((t).QuadPart == LONG_MAX) + +#define INSTR_TIME_SET_ZERO(t) ((t).QuadPart = 0) + +#define INSTR_TIME_INITIAL_MAX(t) ((t).QuadPart = -1) + +#define INSTR_TIME_INITIAL_MIN(t) ((t).QuadPart = LONG_MAX) + +#define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t)) + +#define INSTR_TIME_ADD(x, y) ((x).QuadPart += (y).QuadPart) + +#define INSTR_TIME_IS_BIGGER(x, y) ((x).QuadPart >= (y).QuadPart) + +#define INSTR_TIME_SUBTRACT(x, y) ((x).QuadPart -= (y).QuadPart) + +#define INSTR_TIME_ACCUM_DIFF(x, y, z) ((x).QuadPart += (y).QuadPart - (z).QuadPart) + +#define INSTR_TIME_GET_DOUBLE(t) (((double)(t).QuadPart) / GetTimerFrequency()) + +#define INSTR_TIME_GET_MILLISEC(t) (((double)(t).QuadPart * 1000.0) / GetTimerFrequency()) + +#define INSTR_TIME_GET_MICROSEC(t) ((uint64)(((double)(t).QuadPart * 1000000.0) / GetTimerFrequency())) + +static inline double GetTimerFrequency(void) +{ + LARGE_INTEGER f; + + QueryPerformanceFrequency(&f); + return (double)f.QuadPart; +} +#endif /* WIN32 */ + +#endif /* INSTR_TIME_H */ diff -uprN postgresql-hll-2.14_old/include/include/port.h postgresql-hll-2.14/include/include/port.h --- postgresql-hll-2.14_old/include/include/port.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/port.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,431 @@ +/* ------------------------------------------------------------------------- + * + * port.h + * Header for src/port/ compatibility functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/port.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PORT_H +#define PG_PORT_H + +#include +#include +#include +#include +#include +#include +#include "gs_threadlocal.h" + +/* socket has a different definition on WIN32 */ +#ifndef WIN32 +typedef int pgsocket; + +#define PGINVALID_SOCKET (-1) +#else +typedef SOCKET pgsocket; + +#define PGINVALID_SOCKET INVALID_SOCKET +#endif + +/* non-blocking */ +extern bool pg_set_noblock(pgsocket sock); +extern bool pg_set_block(pgsocket sock); + +/* Portable path handling for Unix/Win32 (in path.c) */ + +extern bool has_drive_prefix(const char* filename); +extern char* first_dir_separator(const char* filename); +extern char* last_dir_separator(const char* filename); +extern char* first_path_var_separator(const char* pathlist); +extern void join_path_components(char* ret_path, const char* head, const char* tail); +extern void canonicalize_path(char* path); +extern void make_native_path(char* path); +extern bool path_contains_parent_reference(const char* path); +extern bool path_is_relative_and_below_cwd(const char* path); +extern bool path_is_prefix_of_path(const char* path1, const char* path2); +extern const char* get_progname(const char* argv0); +extern void get_share_path(const char* my_exec_path, char* ret_path); +extern void get_etc_path(const char* my_exec_path, char* ret_path, size_t ret_path_len); +extern void get_include_path(const char* my_exec_path, char* ret_path); +extern void get_pkginclude_path(const char* my_exec_path, char* ret_path); +extern void get_includeserver_path(const char* my_exec_path, char* ret_path); +extern void get_lib_path(const char* my_exec_path, char* ret_path); +extern void get_pkglib_path(const char* my_exec_path, char* ret_path); +extern void get_locale_path(const char* my_exec_path, char* ret_path); +extern void get_doc_path(const char* my_exec_path, char* ret_path); +extern void get_html_path(const char* my_exec_path, char* ret_path); +extern void get_man_path(const char* my_exec_path, char* ret_path); +extern bool get_home_path(char* ret_path, size_t sz); +extern void get_parent_directory(char* path); +extern char* pg_strtolower(char* str); +extern int mask_single_passwd(char* passwd); + +/* port/dirmod.c */ +extern char** pgfnames(const char* path); +extern void pgfnames_cleanup(char** filenames); + +/* + * is_absolute_path + * + * By making this a macro we avoid needing to include path.c in libpq. + */ +#ifndef WIN32 +#define IS_DIR_SEP(ch) ((ch) == '/') + +#define is_absolute_path(filename) (IS_DIR_SEP((filename)[0])) +#else +#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') + +/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */ +#define is_absolute_path(filename) \ + (IS_DIR_SEP((filename)[0]) || \ + (isalpha((unsigned char)((filename)[0])) && (filename)[1] == ':' && IS_DIR_SEP((filename)[2]))) +#endif + +/* Portable locale initialization (in exec.c) */ +extern void set_pglocale_pgservice(const char* argv0, const char* app); + +/* Portable way to find binaries (in exec.c) */ +extern int find_my_exec(const char* argv0, char* retpath); +extern int find_other_exec(const char* argv0, const char* target, const char* versionstr, char* retpath); + +/* Windows security token manipulation (in exec.c) */ +#ifdef WIN32 +extern BOOL AddUserToTokenDacl(HANDLE hToken); +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +#define EXE ".exe" +#else +#define EXE "" +#endif + +#if defined(WIN32) && !defined(__CYGWIN__) +#define DEVNULL "nul" +#else +#define DEVNULL "/dev/null" +#endif + +/* + * Win32 needs double quotes at the beginning and end of system() + * strings. If not, it gets confused with multiple quoted strings. + * It also requires double-quotes around the executable name and + * any files used for redirection. Other args can use single-quotes. + * + * Generated using Win32 "CMD /?": + * + * 1. If all of the following conditions are met, then quote characters + * on the command line are preserved: + * + * - no /S switch + * - exactly two quote characters + * - no special characters between the two quote characters, where special + * is one of: &<>()@^| + * - there are one or more whitespace characters between the two quote + * characters + * - the string between the two quote characters is the name of an + * executable file. + * + * 2. Otherwise, old behavior is to see if the first character is a quote + * character and if so, strip the leading character and remove the last + * quote character on the command line, preserving any text after the last + * quote character. + */ +#if defined(WIN32) && !defined(__CYGWIN__) +#define SYSTEMQUOTE "\"" +#else +#define SYSTEMQUOTE "" +#endif + +/* Portable delay handling */ +extern void pg_usleep(long microsec); +extern void pg_usleep_retry(long microsec, int retry_times); + +/* Portable SQL-like case-independent comparisons and conversions */ +extern int pg_strcasecmp(const char* s1, const char* s2); +extern int pg_strncasecmp(const char* s1, const char* s2, size_t n); +extern unsigned char pg_toupper(unsigned char ch); +extern unsigned char pg_tolower(unsigned char ch); +extern unsigned char pg_ascii_toupper(unsigned char ch); +extern unsigned char pg_ascii_tolower(unsigned char ch); +#ifndef WIN32 +extern bool IsMyPostmasterPid(pid_t pid, const char* data); +#endif + +#if defined(WIN32) +/* + * Versions of libintl >= 0.18? try to replace setlocale() with a macro + * to their own versions. Remove the macro, if it exists, because it + * ends up calling the wrong version when the backend and libintl use + * different versions of msvcrt. + */ +#if defined(setlocale) +#undef setlocale +#endif + +/* + * Define our own wrapper macro around setlocale() to work around bugs in + * Windows' native setlocale() function. + */ +extern char* pgwin32_setlocale(int category, const char* locale); + +#define setlocale(a, b) pgwin32_setlocale(a, b) +#endif /* WIN32 */ + +/* Portable prompt handling */ +extern char* simple_prompt(const char* prompt, int maxlen, bool echo); + +#ifdef WIN32 +#define PG_SIGNAL_COUNT 32 +#define kill(pid, sig) pgkill(pid, sig) +extern int pgkill(int pid, int sig); +#endif + +extern int pclose_check(FILE* stream); + +/* Global variable holding time zone information. */ +#ifndef __CYGWIN__ +#define TIMEZONE_GLOBAL timezone +#define TZNAME_GLOBAL tzname +#else +#define TIMEZONE_GLOBAL _timezone +#define TZNAME_GLOBAL _tzname +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +/* + * Win32 doesn't have reliable rename/unlink during concurrent access. + */ +extern int pgrename(const char* from, const char* to); +extern int pgunlink(const char* path); + +/* Include this first so later includes don't see these defines */ +#ifdef WIN32_ONLY_COMPILER +#include +#endif + +#define rename(from, to) pgrename(from, to) +#define unlink(path) pgunlink(path) +#endif /* defined(WIN32) || defined(__CYGWIN__) */ + +/* + * Win32 also doesn't have symlinks, but we can emulate them with + * junction points on newer Win32 versions. + * + * Cygwin has its own symlinks which work on Win95/98/ME where + * junction points don't, so use those instead. We have no way of + * knowing what type of system Cygwin binaries will be run on. + * Note: Some CYGWIN includes might #define WIN32. + */ +#if defined(WIN32) && !defined(__CYGWIN__) +extern int pgreadlink(const char* path, char* buf, size_t size); +extern bool pgwin32_is_junction(char* path); + +#define readlink(path, buf, size) pgreadlink(path, buf, size) +#endif + +extern bool rmtree(const char* path, bool rmtopdir, bool noent_ok = false); + +/* + * stat() is not guaranteed to set the st_size field on win32, so we + * redefine it to our own implementation that is. + * + * We must pull in sys/stat.h here so the system header definition + * goes in first, and we redefine that, and not the other way around. + * + * Some frontends don't need the size from stat, so if UNSAFE_STAT_OK + * is defined we don't bother with this. + */ +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK) +#include +extern int pgwin32_safestat(const char* path, struct stat* buf); + +#define stat(a, b) pgwin32_safestat(a, b) +#endif + +#if defined(WIN32) && !defined(__CYGWIN__) + +/* + * open() and fopen() replacements to allow deletion of open files and + * passing of other special options. + */ +#define O_DIRECT 0x80000000 +extern int pgwin32_open(const char*, int, ...); +extern FILE* pgwin32_fopen(const char*, const char*); + +#ifndef FRONTEND +#define open(a, b, c) pgwin32_open(a, b, c) +#define fopen(a, b) pgwin32_fopen(a, b) +#endif + +#ifndef popen +#define popen(a, b) _popen(a, b) +#endif +#ifndef pclose +#define pclose(a) _pclose(a) +#endif + +/* New versions of MingW have gettimeofday, old mingw and msvc don't */ +#ifndef HAVE_GETTIMEOFDAY +/* Last parameter not used */ +extern int gettimeofday(struct timeval* tp, struct timezone* tzp); +#endif +#else /* !WIN32 */ + +/* + * Win32 requires a special close for sockets and pipes, while on Unix + * close() does them all. + */ +#define closesocket close +#endif /* WIN32 */ + +/* + * Default "extern" declarations or macro substitutes for library routines. + * When necessary, these routines are provided by files in src/port/. + */ +#ifndef HAVE_CRYPT +extern char* crypt(const char* key, const char* setting); +#endif + +/* WIN32 handled in port/win32.h */ +#ifndef WIN32 +#define pgoff_t off_t +#ifdef __NetBSD__ +extern int fseeko(FILE* stream, off_t offset, int whence); +extern off_t ftello(FILE* stream); +#endif +#endif + +extern double pg_erand48(unsigned short xseed[3]); +extern long pg_lrand48(void); +extern void pg_srand48(long seed); +extern long free_list_lrand48(void); +extern void free_list_srand48(long seed); +extern void pg_reset_srand48(unsigned short xseed[3]); +extern unsigned short* pg_get_srand48(); + +#ifndef HAVE_FLS +extern int fls(int mask); +#endif + +#ifndef HAVE_FSEEKO +#define fseeko(a, b, c) fseek(a, b, c) +#define ftello(a) ftell(a) +#endif + +#ifndef HAVE_GETOPT +extern int getopt(int nargc, char* const* nargv, const char* ostr); +#endif + +#if !defined(HAVE_GETPEEREID) && !defined(WIN32) +extern int getpeereid(int sock, uid_t* uid, gid_t* gid); +#endif + +#ifndef HAVE_ISINF +extern int isinf(double x); +#endif + +#ifndef HAVE_RINT +extern double rint(double x); +#endif + +#ifndef HAVE_INET_ATON +#include +#include +extern int inet_aton(const char* cp, struct in_addr* addr); +#endif + +#if !HAVE_DECL_STRLCAT +extern size_t strlcat(char* dst, const char* src, size_t siz); +#endif + +#if !HAVE_DECL_STRLCPY +extern size_t strlcpy(char* dst, const char* src, size_t siz); +#endif + +#if !defined(HAVE_RANDOM) && !defined(__BORLANDC__) +extern long random(void); +#endif + +#ifndef HAVE_UNSETENV +extern void unsetenv(const char* name); +#endif + +#ifndef HAVE_SRANDOM +extern void srandom(unsigned int seed); +#endif + +#define gs_random() pg_lrand48() +#define gs_srandom(seed) pg_srand48((long int)(seed)) + + +/* thread.h */ +extern char* pqStrerror(int errnum, char* strerrbuf, size_t buflen); + +#if !defined(WIN32) || defined(__CYGWIN__) +extern int pqGetpwuid(uid_t uid, struct passwd* resultbuf, char* buffer, size_t buflen, struct passwd** result); +#endif + +extern int pqGethostbyname( + const char* name, struct hostent* resultbuf, char* buffer, size_t buflen, struct hostent** result, int* herrno); + +extern void pg_qsort(void* base, size_t nel, size_t elsize, int (*cmp)(const void*, const void*)); + +#define qsort(a, b, c, d) pg_qsort(a, b, c, d) + +typedef int (*qsort_arg_comparator)(const void* a, const void* b, void* arg); + +extern void qsort_arg(void* base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void* arg); + +/* port/chklocale.c */ +extern int pg_get_encoding_from_locale(const char* ctype, bool write_message); + +/* port/inet_net_ntop.c */ + +/* port/pgcheckdir.c */ +extern int pg_check_dir(const char* dir); + +/* port/pgmkdirp.c */ +extern int pg_mkdir_p(char* path, int omode); +extern int pg_mkdir_p_used_by_gaussdb(char* path, int omode); + +typedef struct OptParseContext { + char* place; + int opterr; + int optind; + int optopt; + char* optarg; +} OptParseContext; + +extern void initOptParseContext(OptParseContext* pOptCtxt); +extern int getopt_r(int nargc, char* const* nargv, const char* ostr, OptParseContext* pOptArgs); + +/* port/gs_system.c */ +extern int gs_system(const char* command); + +/* port/gs_system_security */ +extern int gs_system_security(const char* command); +extern FILE* popen_security(const char* command, char type); +extern int pclose_security(FILE* fp); +extern int gs_popen_security(const char* command); + +/* port/gs_strerror.c */ + +extern THR_LOCAL char gs_error_buf[]; +extern char* gs_strerror(int errnum); + +/* port/gs_readdir.c */ + +extern THR_LOCAL char gs_dir_buf[]; +extern struct dirent* gs_readdir(DIR* dir); + +/*env thread safe version*/ +extern int gs_putenv_r(char* envvar); +extern char* gs_getenv_r(const char* name); + +#endif /* PG_PORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/postgres_ext.h postgresql-hll-2.14/include/include/postgres_ext.h --- postgresql-hll-2.14_old/include/include/postgres_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postgres_ext.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * postgres_ext.h + * + * This file contains declarations of things that are visible everywhere + * in PostgreSQL *and* are visible to clients of frontend interface libraries. + * For example, the Oid type is part of the API of libpq and other libraries. + * + * Declarations which are specific to a particular interface should + * go in the header file for that interface (such as libpq-fe.h). This + * file is only for fundamental Postgres declarations. + * + * User-written C functions don't count as "external to Postgres." + * Those function much as local modifications to the backend itself, and + * use header files that are otherwise internal to Postgres to interface + * with the backend. + * + * src/include/postgres_ext.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POSTGRES_EXT_H +#define POSTGRES_EXT_H + +#include "gs_thread.h" +/* + * Object ID is a fundamental type in Postgres. + */ +typedef unsigned int Oid; + +#ifdef __cplusplus +#define InvalidOid (Oid(0)) +#else +#define InvalidOid ((Oid)0) +#endif + +#define VirtualBktOid (Oid(1)) +#define InvalidBktId (-1) + +#define DIR_BUCKET_ID (-2) // relfilenode points to a bucket dir +#define BUCKET_ID_IS_DIR(bucket_node) ((bucket_node) == DIR_BUCKET_ID) +#define BUCKET_NODE_IS_VALID(bucket_node) ((bucket_node) > InvalidBktId) + +#define OID_MAX UINT_MAX + +/* you will need to include to use the above #define */ + +/* + * Identifiers of error message fields. Kept here to keep common + * between frontend and backend, and also to export them to libpq + * applications. + */ +#define PG_DIAG_SEVERITY 'S' +#define PG_DIAG_SQLSTATE 'C' +#define PG_DIAG_INTERNEL_ERRCODE 'c' +#define PG_DIAG_MESSAGE_PRIMARY 'M' +#define PG_DIAG_MESSAGE_DETAIL 'D' +#define PG_DIAG_MESSAGE_HINT 'H' +#define PG_DIAG_STATEMENT_POSITION 'P' +#define PG_DIAG_INTERNAL_POSITION 'p' +#define PG_DIAG_INTERNAL_QUERY 'q' +#define PG_DIAG_CONTEXT 'W' +#define PG_DIAG_SOURCE_FILE 'F' +#define PG_DIAG_SOURCE_LINE 'L' +#define PG_DIAG_SOURCE_FUNCTION 'R' +#define PG_DIAG_MESSAGE_ONLY 'm' +#define PG_DIAG_MODULE_ID 'd' + +#endif diff -uprN postgresql-hll-2.14_old/include/include/postgres_fe.h postgresql-hll-2.14/include/include/postgres_fe.h --- postgresql-hll-2.14_old/include/include/postgres_fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postgres_fe.h 2020-12-12 17:06:43.253348116 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * postgres_fe.h + * Primary include file for PostgreSQL client-side .c files + * + * This should be the first file included by PostgreSQL client libraries and + * application programs --- but not by backend modules, which should include + * postgres.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1995, Regents of the University of California + * + * src/include/postgres_fe.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POSTGRES_FE_H +#define POSTGRES_FE_H + +#ifndef FRONTEND +#define FRONTEND 1 +#endif + +#include "c.h" +#include "securec.h" +#include "securec_check.h" +#include + +#ifndef Assert +#ifndef USE_ASSERT_CHECKING +#define Assert(p) +#else +#define Assert(p) assert(p) +#endif /* USE_ASSERT_CHECKING */ +#endif /* Assert */ + + +#ifndef AssertMacro +#define AssertMacro Assert +#endif + +#ifndef BoolGetDatum +#define BoolGetDatum(X) /*lint -e506*/ ((Datum)((X) ? 1 : 0)) /*lint +e506*/ +#endif + +#ifndef PointerGetDatum +#define PointerGetDatum(X) ((Datum)(X)) +#endif + +#ifndef HAVE_DATABASE_TYPE +#define HAVE_DATABASE_TYPE +/* Type of database; increase for sql compatibility */ +typedef enum { + ORA_FORMAT, + TD_FORMAT +} DatabaseType; +#endif // HAVE_DATABASE_TYPE + +#endif /* POSTGRES_FE_H */ diff -uprN postgresql-hll-2.14_old/include/include/postgres.h postgresql-hll-2.14/include/include/postgres.h --- postgresql-hll-2.14_old/include/include/postgres.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postgres.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,914 @@ +/* ------------------------------------------------------------------------- + * + * postgres.h + * Primary include file for PostgreSQL server .c files + * + * This should be the first file included by PostgreSQL backend modules. + * Client-side code should include postgres_fe.h instead. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1995, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/postgres.h + * + * ------------------------------------------------------------------------- + */ +/* + * ---------------------------------------------------------------- + * TABLE OF CONTENTS + * + * When adding stuff to this file, please try to put stuff + * into the relevant section, or add new sections as appropriate. + * + * section description + * ------- ------------------------------------------------ + * 1) variable-length datatypes (TOAST support) + * 2) datum type + support macros + * 3) exception handling definitions + * + * NOTES + * + * In general, this file should contain declarations that are widely needed + * in the backend environment, but are of no interest outside the backend. + * + * Simple type definitions live in c.h, where they are shared with + * postgres_fe.h. We do that since those type definitions are needed by + * frontend modules that want to deal with binary data transmission to or + * from the backend. Type definitions in this file should be for + * representations that never escape the backend, such as Datum or + * TOASTed varlena objects. + * + * ---------------------------------------------------------------- + */ +#ifndef POSTGRES_H +#define POSTGRES_H + +#ifdef PC_LINT +#define THR_LOCAL +#endif + +#include "c.h" +#include "utils/elog.h" +#include "utils/palloc.h" +#include "storage/spin.h" + +#ifndef WIN32 +#include +#endif /* win-odbc */ + +#ifndef HDFS_FDW +#define HDFS_FDW "hdfs_fdw" +#endif + +#ifndef HDFS +#define HDFS "hdfs" +#endif + +#ifndef OBS +#define OBS "obs" +#endif + +#ifndef DIST_FDW +#define DIST_FDW "dist_fdw" +#endif + +#ifndef MYSQL_FDW +#define MYSQL_FDW "mysql_fdw" +#endif + +#ifndef ORACLE_FDW +#define ORACLE_FDW "oracle_fdw" +#endif + +#ifndef POSTGRES_FDW +#define POSTGRES_FDW "postgres_fdw" +#endif + +#ifndef MOT_FDW +#define MOT_FDW "mot_fdw" +#endif + +#ifndef MOT_FDW_SERVER +#define MOT_FDW_SERVER "mot_server" +#endif + +#ifndef DFS_FDW +#define DFS_FDW "dfs_fdw" +#endif + +#ifndef LOG_FDW +#define LOG_FDW "log_fdw" +#define LOG_SRV "log_srv" +#endif /* LOG_FDW */ + +#ifndef GC_FDW +#define GC_FDW "gc_fdw" +#endif + +#include "securec.h" +#include "securec_check.h" + +#define AUXILIARY_BACKENDS 20 +/* the maximum number of autovacuum launcher thread */ +#define AV_LAUNCHER_PROCS 2 + +#define STREAM_RESERVE_PROC_TIMES (16) +/* this struct is used to store connection info got from pool */ +typedef struct { + /* hostname of the connection */ + nameData host; + /* port of the connection */ + int port; +} PoolConnInfo; + +/* this enum type is used to mark om online operation. */ +typedef enum { OM_ONLINE_EXPANSION, OM_ONLINE_NODE_REPLACE } OM_ONLINE_STATE; + +extern void reload_configfile(void); +extern void reload_online_pooler(void); +extern OM_ONLINE_STATE get_om_online_state(void); + +/* ---------------------------------------------------------------- + * Section 1: variable-length datatypes (TOAST support) + * ---------------------------------------------------------------- + */ + +/* + * struct varatt_external is a "TOAST pointer", that is, the information + * needed to fetch a stored-out-of-line Datum. The data is compressed + * if and only if va_extsize < va_rawsize - VARHDRSZ. This struct must not + * contain any padding, because we sometimes compare pointers using memcmp. + * + * Note that this information is stored unaligned within actual tuples, so + * you need to memcpy from the tuple into a local struct variable before + * you can look at these fields! (The reason we use memcmp is to avoid + * having to do that just to detect equality of two TOAST pointers...) + */ +typedef struct varatt_external { + int32 va_rawsize; /* Original data size (includes header) */ + int32 va_extsize; /* External saved size (doesn't) */ + Oid va_valueid; /* Unique ID of value within TOAST table */ + Oid va_toastrelid; /* RelID of TOAST table containing it */ +} varatt_external; + +/* + * Out-of-line Datum thats stored in memory in contrast to varatt_external + * pointers which points to data in an external toast relation. + * + * Note that just as varatt_external's this is stored unaligned within the + * tuple. + */ +typedef struct varatt_indirect { + struct varlena* pointer; /* Pointer to in-memory varlena */ +} varatt_indirect; + +/* + * Type of external toast datum stored. The peculiar value for VARTAG_ONDISK + * comes from the requirement for on-disk compatibility with the older + * definitions of varattrib_1b_e where v_tag was named va_len_1be... + */ +typedef enum vartag_external { VARTAG_INDIRECT = 1, VARTAG_BUCKET = 8, VARTAG_ONDISK = 18 } vartag_external; + +#define VARTAG_SIZE(tag) \ + ((tag) == VARTAG_INDIRECT ? sizeof(varatt_indirect) : \ + (tag) == VARTAG_ONDISK ? sizeof(varatt_external) : \ + (tag) == VARTAG_BUCKET ? sizeof(varatt_external) + sizeof(int2) : \ + TrapMacro(true, "unknown vartag")) + +/* + * These structs describe the header of a varlena object that may have been + * TOASTed. Generally, don't reference these structs directly, but use the + * macros below. + * + * We use separate structs for the aligned and unaligned cases because the + * compiler might otherwise think it could generate code that assumes + * alignment while touching fields of a 1-byte-header varlena. + */ +typedef union { + struct /* Normal varlena (4-byte length) */ + { + uint32 va_header; + char va_data[FLEXIBLE_ARRAY_MEMBER]; + } va_4byte; + struct /* Compressed-in-line format */ + { + uint32 va_header; + uint32 va_rawsize; /* Original data size (excludes header) */ + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Compressed data */ + } va_compressed; +} varattrib_4b; + +typedef struct { + uint8 va_header; + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Data begins here */ +} varattrib_1b; + +#define TRY_LOCK_ACCOUNT 0 +#define TRY_UNLOCK_ACCOUNT 1 +#define MAX_USER_NUM 100 +typedef struct accounttask { + Oid roleid; + int failedcount; +} AccountTask; + +/* inline portion of a short varlena pointing to an external resource */ +typedef struct { + uint8 va_header; /* Always 0x80 or 0x01 */ + uint8 va_tag; /* Type of datum */ + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Type-specific data */ +} varattrib_1b_e; + +#ifndef HAVE_DATABASE_TYPE +#define HAVE_DATABASE_TYPE +/*Type of database; increase for sql compatibility*/ +typedef enum { A_FORMAT, B_FORMAT, C_FORMAT } DatabaseType; +#endif /* HAVE_DATABASE_TYPE */ + +typedef enum { EXPLAIN_NORMAL, EXPLAIN_PRETTY, EXPLAIN_SUMMARY, EXPLAIN_RUN } ExplainStyle; + +typedef enum { SKEW_OPT_OFF, SKEW_OPT_NORMAL, SKEW_OPT_LAZY } SkewStrategy; + +typedef enum { RESOURCE_TRACK_NONE, RESOURCE_TRACK_QUERY, RESOURCE_TRACK_OPERATOR } ResourceTrackOption; + +typedef enum { + CODEGEN_PARTIAL, /* allow to call c-function in codegen */ + CODEGEN_PURE /* do not allow to call c-function in codegen */ +} CodegenStrategy; + +typedef enum { + MEMORY_TRACKING_NONE, /* not to track the memory usage */ + MEMORY_TRACKING_NORMAL, /* just update the peak information internal */ + MEMORY_TRACKING_EXECUTOR, /* to logging the memory information in executor */ + MEMORY_TRACKING_FULLEXEC /* to logging the all memory context information in executor */ +} MemoryTrackingStyle; + +/* + * Bit layouts for varlena headers on big-endian machines: + * + * 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G) + * 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G) + * 10000000 1-byte length word, unaligned, TOAST pointer + * 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b) + * + * Bit layouts for varlena headers on little-endian machines: + * + * xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G) + * xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G) + * 00000001 1-byte length word, unaligned, TOAST pointer + * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b) + * + * The "xxx" bits are the length field (which includes itself in all cases). + * In the big-endian case we mask to extract the length, in the little-endian + * case we shift. Note that in both cases the flag bits are in the physically + * first byte. Also, it is not possible for a 1-byte length word to be zero; + * this lets us disambiguate alignment padding bytes from the start of an + * unaligned datum. (We now *require* pad bytes to be filled with zero!) + */ + +/* + * Endian-dependent macros. These are considered internal --- use the + * external macros below instead of using these directly. + * + * Note: IS_1B is true for external toast records but VARSIZE_1B will return 0 + * for such records. Hence you should usually check for IS_EXTERNAL before + * checking for IS_1B. + */ + +#ifdef WORDS_BIGENDIAN + +#define VARATT_IS_4B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x80) == 0x00) +#define VARATT_IS_4B_U(PTR) ((((varattrib_1b*)(PTR))->va_header & 0xC0) == 0x00) +#define VARATT_IS_4B_C(PTR) ((((varattrib_1b*)(PTR))->va_header & 0xC0) == 0x40) +#define VARATT_IS_1B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x80) == 0x80) +#define VARATT_IS_1B_E(PTR) ((((varattrib_1b*)(PTR))->va_header) == 0x80) +#define VARATT_NOT_PAD_BYTE(PTR) (*((uint8*)(PTR)) != 0) + +/* VARSIZE_4B() should only be used on known-aligned data */ +#define VARSIZE_4B(PTR) (((varattrib_4b*)(PTR))->va_4byte.va_header & 0x3FFFFFFF) +#define VARSIZE_1B(PTR) (((varattrib_1b*)(PTR))->va_header & 0x7F) +#define VARSIZE_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_len_1be) + +#define SET_VARSIZE_4B(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (len)&0x3FFFFFFF) +#define SET_VARSIZE_4B_C(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = ((len)&0x3FFFFFFF) | 0x40000000) +#define SET_VARSIZE_1B(PTR, len) (((varattrib_1b*)(PTR))->va_header = (len) | 0x80) +#define SET_VARTAG_1B_E(PTR, tag) (((varattrib_1b_e*)(PTR))->va_header = 0x80, ((varattrib_1b_e*)(PTR))->va_tag = (tag)) +#else /* !WORDS_BIGENDIAN */ + +#define VARATT_IS_4B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x01) == 0x00) +#define VARATT_IS_4B_U(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x03) == 0x00) +#define VARATT_IS_4B_C(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x03) == 0x02) +#define VARATT_IS_1B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x01) == 0x01) +#define VARATT_IS_1B_E(PTR) ((((varattrib_1b*)(PTR))->va_header) == 0x01) +#define VARATT_NOT_PAD_BYTE(PTR) (*((uint8*)(PTR)) != 0) + +/* VARSIZE_4B() should only be used on known-aligned data */ +#define VARSIZE_4B(PTR) ((((varattrib_4b*)(PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF) +#define VARSIZE_1B(PTR) ((((varattrib_1b*)(PTR))->va_header >> 1) & 0x7F) +#define VARTAG_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_tag) +#define SET_VARSIZE_4B(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (((uint32)(len)) << 2)) +#define SET_VARSIZE_4B_C(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (((uint32)(len)) << 2) | 0x02) +#define SET_VARSIZE_1B(PTR, len) (((varattrib_1b*)(PTR))->va_header = (((uint8)(len)) << 1) | 0x01) +#define SET_VARTAG_1B_E(PTR, tag) (((varattrib_1b_e*)(PTR))->va_header = 0x01, ((varattrib_1b_e*)(PTR))->va_tag = (tag)) +#endif /* WORDS_BIGENDIAN */ + +#define VARHDRSZ_SHORT offsetof(varattrib_1b, va_data) +#define VARATT_SHORT_MAX 0x7F +#define VARATT_CAN_MAKE_SHORT(PTR) \ + (VARATT_IS_4B_U(PTR) && (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX) +#define VARATT_CONVERTED_SHORT_SIZE(PTR) (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) + +#define VARHDRSZ_EXTERNAL offsetof(varattrib_1b_e, va_data) + +#define VARDATA_4B(PTR) (((varattrib_4b*)(PTR))->va_4byte.va_data) +#define VARDATA_4B_C(PTR) (((varattrib_4b*)(PTR))->va_compressed.va_data) +#define VARDATA_1B(PTR) (((varattrib_1b*)(PTR))->va_data) +#define VARDATA_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_data) + +#define VARRAWSIZE_4B_C(PTR) (((varattrib_4b*)(PTR))->va_compressed.va_rawsize) + +/* Externally visible macros */ + +/* + * VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code + * for varlena datatypes. Note that they only work on untoasted, + * 4-byte-header Datums! + * + * Code that wants to use 1-byte-header values without detoasting should + * use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY. The other macros here + * should usually be used only by tuple assembly/disassembly code and + * code that specifically wants to work with still-toasted Datums. + * + * WARNING: It is only safe to use VARDATA_ANY() -- typically with + * PG_DETOAST_DATUM_PACKED() -- if you really don't care about the alignment. + * Either because you're working with something like text where the alignment + * doesn't matter or because you're not going to access its constituent parts + * and just use things like memcpy on it anyways. + */ +#define VARDATA(PTR) VARDATA_4B(PTR) +#define VARSIZE(PTR) VARSIZE_4B(PTR) + +#define VARSIZE_SHORT(PTR) VARSIZE_1B(PTR) +#define VARDATA_SHORT(PTR) VARDATA_1B(PTR) + +#define VARTAG_EXTERNAL(PTR) VARTAG_1B_E(PTR) +#define VARSIZE_EXTERNAL(PTR) (VARHDRSZ_EXTERNAL + VARTAG_SIZE(VARTAG_EXTERNAL(PTR))) +#define VARDATA_EXTERNAL(PTR) VARDATA_1B_E(PTR) + +#define VARATT_IS_COMPRESSED(PTR) VARATT_IS_4B_C(PTR) +#define VARATT_IS_EXTERNAL(PTR) VARATT_IS_1B_E(PTR) +#define VARATT_IS_EXTERNAL_ONDISK(PTR) (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_ONDISK) +#define VARATT_IS_EXTERNAL_INDIRECT(PTR) (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_INDIRECT) +#define VARATT_IS_EXTERNAL_BUCKET(PTR) \ + (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_BUCKET) +#define VARATT_IS_EXTERNAL_ONDISK_B(PTR) \ + (VARATT_IS_EXTERNAL_ONDISK(PTR) || VARATT_IS_EXTERNAL_BUCKET(PTR)) + +#define VARATT_IS_SHORT(PTR) VARATT_IS_1B(PTR) +#define VARATT_IS_EXTENDED(PTR) (!VARATT_IS_4B_U(PTR)) + +#define SET_VARSIZE(PTR, len) SET_VARSIZE_4B(PTR, len) +#define SET_VARSIZE_SHORT(PTR, len) SET_VARSIZE_1B(PTR, len) +#define SET_VARSIZE_COMPRESSED(PTR, len) SET_VARSIZE_4B_C(PTR, len) +#define SET_VARTAG_EXTERNAL(PTR, tag) SET_VARTAG_1B_E(PTR, tag) + +#define VARSIZE_ANY(PTR) \ + (VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR) : (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : VARSIZE_4B(PTR))) + +#define VARSIZE_ANY_EXHDR(PTR) \ + (VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR) - VARHDRSZ_EXTERNAL \ + : (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) - VARHDRSZ_SHORT : VARSIZE_4B(PTR) - VARHDRSZ)) + +/* caution: this will not work on an external or compressed-in-line Datum */ +/* caution: this will return a possibly unaligned pointer */ +#define VARDATA_ANY(PTR) (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR)) + +/* ---------------------------------------------------------------- + * Section 2: datum type + support macros + * ---------------------------------------------------------------- + */ + +/* + * Port Notes: + * Postgres makes the following assumptions about datatype sizes: + * + * sizeof(Datum) == sizeof(void *) == 4 or 8 + * sizeof(char) == 1 + * sizeof(short) == 2 + * + * When a type narrower than Datum is stored in a Datum, we place it in the + * low-order bits and are careful that the DatumGetXXX macro for it discards + * the unused high-order bits (as opposed to, say, assuming they are zero). + * This is needed to support old-style user-defined functions, since depending + * on architecture and compiler, the return value of a function returning char + * or short may contain garbage when called as if it returned Datum. + */ + +typedef uintptr_t Datum; + +#define SIZEOF_DATUM SIZEOF_VOID_P + +typedef Datum* DatumPtr; + +#define GET_1_BYTE(datum) (((Datum)(datum)) & 0x000000ff) +#define GET_2_BYTES(datum) (((Datum)(datum)) & 0x0000ffff) +#define GET_4_BYTES(datum) (((Datum)(datum)) & 0xffffffff) +#if SIZEOF_DATUM == 8 +#define GET_8_BYTES(datum) ((Datum)(datum)) +#endif +#define SET_1_BYTE(value) (((Datum)(value)) & 0x000000ff) +#define SET_2_BYTES(value) (((Datum)(value)) & 0x0000ffff) +#define SET_4_BYTES(value) (((Datum)(value)) & 0xffffffff) +#if SIZEOF_DATUM == 8 +#define SET_8_BYTES(value) ((Datum)(value)) +#endif + +/* + * DatumGetBool + * Returns boolean value of a datum. + * + * Note: any nonzero value will be considered TRUE, but we ignore bits to + * the left of the width of bool, per comment above. + */ + +#define DatumGetBool(X) ((bool)(((bool)(X)) != 0)) + +/* + * BoolGetDatum + * Returns datum representation for a boolean. + * + * Note: any nonzero value will be considered TRUE. + */ +#ifndef BoolGetDatum +#define BoolGetDatum(X) ((Datum)((X) ? 1 : 0)) +#endif +/* + * DatumGetChar + * Returns character value of a datum. + */ + +#define DatumGetChar(X) ((char)GET_1_BYTE(X)) + +/* + * CharGetDatum + * Returns datum representation for a character. + */ + +#define CharGetDatum(X) ((Datum)SET_1_BYTE((unsigned char)(X))) + +/* + * Int8GetDatum + * Returns datum representation for an 8-bit integer. + */ + +#define Int8GetDatum(X) ((Datum)SET_1_BYTE((uint8)X)) + +/* + * DatumGetInt8 + * Returns 8-bit integer value of a datum. + */ +#define DatumGetInt8(X) ((int8)GET_1_BYTE(X)) + +/* + * DatumGetUInt8 + * Returns 8-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt8(X) ((uint8)GET_1_BYTE(X)) + +/* + * UInt8GetDatum + * Returns datum representation for an 8-bit unsigned integer. + */ + +#define UInt8GetDatum(X) ((Datum)SET_1_BYTE((uint8)(X))) + +/* + * DatumGetInt16 + * Returns 16-bit integer value of a datum. + */ + +#define DatumGetInt16(X) ((int16)GET_2_BYTES(X)) + +/* + * Int16GetDatum + * Returns datum representation for a 16-bit integer. + */ + +#define Int16GetDatum(X) ((Datum)SET_2_BYTES((uint16)(X))) + +/* + * DatumGetUInt16 + * Returns 16-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt16(X) ((uint16)GET_2_BYTES(X)) + +/* + * UInt16GetDatum + * Returns datum representation for a 16-bit unsigned integer. + */ + +#define UInt16GetDatum(X) ((Datum)SET_2_BYTES(X)) + +/* + * DatumGetInt32 + * Returns 32-bit integer value of a datum. + */ + +#define DatumGetInt32(X) ((int32)GET_4_BYTES(X)) + +/* + * Int32GetDatum + * Returns datum representation for a 32-bit integer. + */ + +#define Int32GetDatum(X) ((Datum)SET_4_BYTES((uint32)(X))) + +/* + * DatumGetUInt32 + * Returns 32-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt32(X) ((uint32)GET_4_BYTES(X)) + +/* + * UInt32GetDatum + * Returns datum representation for a 32-bit unsigned integer. + */ + +#define UInt32GetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetObjectId + * Returns object identifier value of a datum. + */ + +#define DatumGetObjectId(X) ((Oid)GET_4_BYTES(X)) + +/* + * ObjectIdGetDatum + * Returns datum representation for an object identifier. + */ + +#define ObjectIdGetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetTransactionId + * Returns transaction identifier value of a datum. + */ + +#define DatumGetTransactionId(X) (DatumGetUInt64(X)) +#define DatumGetShortTransactionId(X) ((ShortTransactionId)GET_4_BYTES(X)) +/* + * TransactionIdGetDatum + * Returns datum representation for a transaction identifier. + */ + +#define TransactionIdGetDatum(X) (UInt64GetDatum(X)) +#define ShortTransactionIdGetDatum(X) ((Datum)SET_4_BYTES((X))) +/* + * DatumGetCommandId + * Returns command identifier value of a datum. + */ + +#define DatumGetCommandId(X) ((CommandId)GET_4_BYTES(X)) + +/* + * CommandIdGetDatum + * Returns datum representation for a command identifier. + */ + +#define CommandIdGetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetPointer + * Returns pointer value of a datum. + */ + +#define DatumGetPointer(X) ((Pointer)(X)) + +/* + * PointerGetDatum + * Returns datum representation for a pointer. + */ +#ifndef PointerGetDatum +#define PointerGetDatum(X) ((Datum)(X)) +#endif +/* + * DatumGetCString + * Returns C string (null-terminated string) value of a datum. + * + * Note: C string is not a full-fledged Postgres type at present, + * but type input functions use this conversion for their inputs. + */ + +#define DatumGetCString(X) ((char*)DatumGetPointer(X)) + +/* + * CStringGetDatum + * Returns datum representation for a C string (null-terminated string). + * + * Note: C string is not a full-fledged Postgres type at present, + * but type output functions use this conversion for their outputs. + * Note: CString is pass-by-reference; caller must ensure the pointed-to + * value has adequate lifetime. + */ + +#define CStringGetDatum(X) PointerGetDatum(X) + +/* + * DatumGetName + * Returns name value of a datum. + */ + +#define DatumGetName(X) ((Name)DatumGetPointer(X)) + +/* + * NameGetDatum + * Returns datum representation for a name. + * + * Note: Name is pass-by-reference; caller must ensure the pointed-to + * value has adequate lifetime. + */ + +#define NameGetDatum(X) PointerGetDatum(X) + +/* + * DatumGetInt64 + * Returns 64-bit integer value of a datum. + * + * Note: this macro hides whether int64 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +#define DatumGetInt64(X) ((int64)GET_8_BYTES(X)) +#else +#define DatumGetInt64(X) (*((int64*)DatumGetPointer(X))) +#endif + +#define BatchMaxSize 1000 +/* + * Int64GetDatum + * Returns datum representation for a 64-bit integer. + * + * Note: if int64 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +#ifdef USE_FLOAT8_BYVAL +#define Int64GetDatum(X) ((Datum)SET_8_BYTES(X)) +#else +extern Datum Int64GetDatum(int64 X); +#endif + +/* + * DatumGetUInt64 + * Returns 64-bit unsigned integer value of a datum. + * + * Note: this macro hides whether int64 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +#define DatumGetUInt64(X) ((uint64)GET_8_BYTES(X)) +#else +#define DatumGetUInt64(X) (*((uint64*)DatumGetPointer(X))) +#endif + +/* + * UInt64GetDatum + * Returns datum representation for a 64-bit unsigned integer. + * + * Note: if int64 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +#ifdef USE_FLOAT8_BYVAL +#define UInt64GetDatum(X) ((Datum)SET_8_BYTES(X)) +#else +#define UInt64GetDatum(X) Int64GetDatum((int64)(X)) +#endif + +/* + * DatumGetFloat4 + * Returns 4-byte floating point value of a datum. + * + * Note: this macro hides whether float4 is pass by value or by reference. + */ + +#ifdef USE_FLOAT4_BYVAL +extern float4 DatumGetFloat4(Datum X); +#else +#define DatumGetFloat4(X) (*((float4*)DatumGetPointer(X))) +#endif + +/* + * Float4GetDatum + * Returns datum representation for a 4-byte floating point number. + * + * Note: if float4 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +extern Datum Float4GetDatum(float4 X); + +/* + * DatumGetFloat8 + * Returns 8-byte floating point value of a datum. + * + * Note: this macro hides whether float8 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +extern float8 DatumGetFloat8(Datum X); +#else +#define DatumGetFloat8(X) (*((float8*)DatumGetPointer(X))) +#endif + +/* + * Float8GetDatum + * Returns datum representation for an 8-byte floating point number. + * + * Note: if float8 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +extern Datum Float8GetDatum(float8 X); + +/* + * Int64GetDatumFast + * Float8GetDatumFast + * Float4GetDatumFast + * + * These macros are intended to allow writing code that does not depend on + * whether int64, float8, float4 are pass-by-reference types, while not + * sacrificing performance when they are. The argument must be a variable + * that will exist and have the same value for as long as the Datum is needed. + * In the pass-by-ref case, the address of the variable is taken to use as + * the Datum. In the pass-by-val case, these will be the same as the non-Fast + * macros. + */ + +#ifdef USE_FLOAT8_BYVAL +#define Int64GetDatumFast(X) Int64GetDatum(X) +#define Float8GetDatumFast(X) Float8GetDatum(X) +#else +#define Int64GetDatumFast(X) PointerGetDatum(&(X)) +#define Float8GetDatumFast(X) PointerGetDatum(&(X)) +#endif + +#ifdef USE_FLOAT4_BYVAL +#define Float4GetDatumFast(X) Float4GetDatum(X) +#else +#define Float4GetDatumFast(X) PointerGetDatum(&(X)) +#endif + +#ifdef HAVE_INT64_TIMESTAMP +#define TimeGetDatum(X) Int64GetDatum(X) +#else +#define TimeGetDatum(X) Float8GetDatum(X) +#endif + +/* ---------------------------------------------------------------- + * Section 3: exception handling definitions + * Assert, Trap, etc macros + * ---------------------------------------------------------------- + */ + +#ifdef WIN32 +extern THR_LOCAL bool assert_enabled; +#else +extern THR_LOCAL PGDLLIMPORT bool assert_enabled; +#endif + +/* + * USE_ASSERT_CHECKING, if defined, turns on all the assertions. + * - plai 9/5/90 + * + * It should _NOT_ be defined in releases or in benchmark copies + */ + +/* + * Trap + * Generates an exception if the given condition is true. + */ +#define Trap(condition, errorType) \ + do { \ + if ((assert_enabled) && (condition)) \ + ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__); \ + } while (0) + +/* + * TrapMacro is the same as Trap but it's intended for use in macros: + * + * #define foo(x) (AssertMacro(x != 0), bar(x)) + * + * Isn't CPP fun? + */ +#define TrapMacro(condition, errorType) \ + ((bool)((!assert_enabled) || !(condition) || \ + (ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__), 0))) + +#ifdef Assert +#undef Assert +#endif +#ifdef PC_LINT +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#ifndef AssertMacro +#define AssertMacro Assert +#endif +#define AssertArg Assert +#define DBG_ASSERT Assert +#define AssertState Assert + +#else +#ifndef USE_ASSERT_CHECKING +#define Assert(condition) +#ifndef AssertMacro +#define AssertMacro(condition) ((void)true) +#endif /* AssertMacro */ +#define AssertArg(condition) +#define DBG_ASSERT(condition) +#define AssertState(condition) + +#elif defined(FRONTEND) + +#include +#define Assert(p) assert(p) +#ifndef AssertMacro +#define AssertMacro(p) ((void)assert(p)) +#endif +#define AssertArg(condition) assert(condition) +#define DBG_ASSERT(condition) +#define AssertState(condition) assert(condition) +#define AssertPointerAlignment(ptr, bndr) ((void)true) +#else /* USE_ASSERT_CHECKING && !FRONTEND */ + +#define Assert(condition) Trap(!(condition), "FailedAssertion") + +#ifndef AssertMacro +#define AssertMacro(condition) ((void)TrapMacro(!(condition), "FailedAssertion")) +#endif /* AssertMacro */ + +#define AssertArg(condition) Trap(!(condition), "BadArgument") + +#define AssertState(condition) Trap(!(condition), "BadState") +#define DBG_ASSERT Assert +#endif /* USE_ASSERT_CHECKING */ +#endif /* PC_LINT */ + +extern void ExceptionalCondition(const char* conditionName, const char* errorType, const char* fileName, int lineNumber) + __attribute__((noreturn)); + +extern void ConnFree(void* conn); + +extern THR_LOCAL bool IsInitdb; + +extern size_t mmap_threshold; + +/* Set the pooler reload flag when signaled by SIGUSR1 */ +void HandlePoolerReload(void); +void HandleMemoryContextDump(void); +void HandleExecutorFlag(void); + +extern void start_xact_command(void); +extern void finish_xact_command(void); +extern void exec_init_poolhandles(void); + +extern void InitVecFuncMap(void); + +/* load ir file count for each process */ +extern long codegenIRloadProcessCount; + +/* Job worker Process, execute procedure */ +extern void execute_simple_query(const char* query_string); + +/* check the value from environment variablethe to prevent command injection. */ +extern void check_backend_env(const char* input_env_value); +extern bool backend_env_valid(const char* input_env_value, const char* stamp); + +extern void CleanSystemCaches(bool is_in_read_command); + +/*Audit user logout*/ +extern void audit_processlogout_unified(); +extern void audit_processlogout(int code, Datum arg); + +/* free the pointer malloced by cJSON_internal_malloc.*/ +extern void cJSON_internal_free(void* pointer); + +extern void InitThreadLocalWhenSessionExit(); +extern void RemoveTempNamespace(); + +#define CacheIsProcNameArgNsp(cache) ((cache)->id == PROCNAMEARGSNSP) +#define CacheIsProcOid(cache) ((cache)->id == PROCOID) +#define IsBootingPgProc(rel) IsProcRelation(rel) +#define BootUsingBuiltinFunc true + +#define MSG_A_REPEAT_NUM_MAX 1024 +#define OVERRIDE_STACK_LENGTH_MAX 1024 +#endif /* POSTGRES_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/aiocompleter.h postgresql-hll-2.14/include/include/postmaster/aiocompleter.h --- postgresql-hll-2.14_old/include/include/postmaster/aiocompleter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/aiocompleter.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,121 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aiocompleter.h + * Exports from postmaster/aiocompleter.c. + * + * + * IDENTIFICATION + * src/include/postmaster/aiocompleter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _AIOCOMPLETER_H +#define _AIOCOMPLETER_H + +#include "storage/block.h" +#include "storage/bufmgr.h" +#include "storage/buf_internals.h" +#include "storage/relfilenode.h" +#include "storage/smgr.h" +#include + +/* + * requests/completers types + */ +typedef enum { + // PageRangePrefetchType=0, + PageListPrefetchType = 0, + // PageRangeBackWriteType, + PageListBackWriteType, + CUListPrefetchType, + CUListWriteType, + NUM_AIOCOMPLTR_TYPES /* Number of types, must be last */ +} AioCompltrType; + +/* + * request priorities (io nice values) + */ +typedef enum { DefaultPri = 0, HighPri = 1, MediumPri = 2, LowPri = 3 } AioPriority; + +typedef enum { AioRead = 0, AioWrite = 1, AioVacummFull = 2, AioUnkown } AioDescType; + +/* + * Context for Page AIO completion + */ +typedef struct BlockDesc { + SMgrRelation smgrReln; + ForkNumber forkNum; + BlockNumber blockNum; + Block buffer; + int32 blockSize; + BufferDesc* bufHdr; + AioCompltrType reqType; + AioDescType descType; +} BlockDesc_t; + +typedef struct AioCUDesc { + char* buf; + uint64 offset; // use uint64 instead of CUPointer for not include + int size; // read: align cu_size; write: cu_size + int fd; + bool* io_error; + int slotId; // read means slotId of cucache; write means cuid + volatile int io_finish; // used for which has no cucache, ep write; + uint64 cu_pointer; // only used for async write, + AioCompltrType reqType; +} AioCUDesc_t; + +/* + * The system iocb and BlockDesc_t are allocated together in an + * AioDispatchDesc. + */ +typedef struct AioDispatchDesc { + struct iocb aiocb; + BlockDesc_t blockDesc; +} AioDispatchDesc_t; + +typedef struct AioDispatchCUDesc { + struct iocb aiocb; + AioCUDesc_t cuDesc; +} AioDispatchCUDesc_t; + +/* GUC options */ +extern int AioCompltrSets; +extern int AioCompltrEvents; + +extern void AioCompltrMain(int ac, char** av); +extern void AioCompltrStop(int signal); +extern int AioCompltrStart(void); +extern bool AioCompltrIsReady(void); +extern io_context_t CompltrContext(AioCompltrType reqType, int h); +extern short CompltrPriority(AioCompltrType reqType); + +/* + * These Storage Manager AIO prototypes would normally + * go in smgr.h, and that file would include this one. + * because the prototypes require the AioDispatchDesc_t. + * However, it is not possible because this file must + * include smgr.h itself. + */ +extern void smgrasyncread(SMgrRelation reln, ForkNumber forknum, AioDispatchDesc_t** dList, int32 dn); +extern void smgrasyncwrite(SMgrRelation reln, ForkNumber forknum, AioDispatchDesc_t** dList, int32 dn); + +extern void mdasyncread(SMgrRelation reln, ForkNumber forkNum, AioDispatchDesc_t** dList, int32 dn); +extern void mdasyncwrite(SMgrRelation reln, ForkNumber forkNumber, AioDispatchDesc_t** dList, int32 dn); + +extern void AioResourceInitialize(void); + +#endif /* _AIOCOMPLETER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/alarmchecker.h postgresql-hll-2.14/include/include/postmaster/alarmchecker.h --- postgresql-hll-2.14_old/include/include/postmaster/alarmchecker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/alarmchecker.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarmchecker.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/postmaster/alarmchecker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ALARMCHECKER_H +#define ALARMCHECKER_H +#include "alarm/alarm.h" + +extern bool enable_alarm; + +extern bool isDirExist(const char* dir); +extern ThreadId startAlarmChecker(void); +extern NON_EXEC_STATIC void AlarmCheckerMain(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/postmaster/autovacuum.h postgresql-hll-2.14/include/include/postmaster/autovacuum.h --- postgresql-hll-2.14_old/include/include/postmaster/autovacuum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/autovacuum.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * autovacuum.h + * header file for integrated autovacuum daemon + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/postmaster/autovacuum.h + * + * ------------------------------------------------------------------------- + */ +#include "utils/guc.h" + +#ifndef AUTOVACUUM_H +#define AUTOVACUUM_H + +#include "utils/guc.h" + +#ifdef PGXC /* PGXC_DATANODE */ +#define IsAutoVacuumAnalyzeWorker() (IsAutoVacuumWorkerProcess() && !(MyProc->vacuumFlags & PROC_IN_VACUUM)) + +#define UINT32_MASK ((uint64)((1UL << 32) - 1)) + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); +#define AUTOVAC_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_AUTOVAC)) { \ + ereport(level, (errmodule(MOD_AUTOVAC), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +typedef enum { + AUTOVACUUM_DO_ANALYZE, /* just do auto-analyze when autovacuum = true */ + AUTOVACUUM_DO_VACUUM, /* just do auto-vacuum when autovacuum = true */ + AUTOVACUUM_DO_ANALYZE_VACUUM, /* do auto-vacuum and auto-analyze when autovacuum = true */ + AUTOVACUUM_DO_NONE /* do neither auto-vacuum or auto-analyze when autovacuum = true */ +} AutoVacuumModeType; + +#endif + +/* Status inquiry functions */ +extern bool AutoVacuumingActive(void); +extern bool IsAutoVacuumLauncherProcess(void); +extern bool IsAutoVacuumWorkerProcess(void); +extern AutoVacOpts* extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc); + +#define IsAnyAutoVacuumProcess() (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess()) + +/* Functions to start autovacuum process, called from postmaster */ +extern void autovac_init(void); + +/* called from postmaster when a worker could not be forked */ +extern void AutoVacWorkerFailed(void); + +/* autovacuum cost-delay balancer */ +extern void AutoVacuumUpdateDelay(void); + +#ifdef EXEC_BACKEND +extern void AutoVacLauncherMain(); +extern void AutoVacWorkerMain(); +extern void AutovacuumWorkerIAm(void); +extern void AutovacuumLauncherIAm(void); +#endif + +/* shared memory stuff */ +extern Size AutoVacuumShmemSize(void); +extern void AutoVacuumShmemInit(void); + +extern bool check_autovacuum_coordinators(char** newval, void** extra, GucSource source); +extern void assign_autovacuum_coordinators(const char* newval, void* extra); +extern void relation_support_autoavac( + HeapTuple tuple, bool* enable_analyze, bool* enable_vacuum, bool* is_internal_relation); + +#endif /* AUTOVACUUM_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/bgwriter.h postgresql-hll-2.14/include/include/postmaster/bgwriter.h --- postgresql-hll-2.14_old/include/include/postmaster/bgwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/bgwriter.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * bgwriter.h + * Exports from postmaster/bgwriter.c and postmaster/checkpointer.c. + * + * The bgwriter process used to handle checkpointing duties too. Now + * there is a separate process, but we did not bother to split this header. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/bgwriter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _BGWRITER_H +#define _BGWRITER_H + +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "postmaster/pagewriter.h" + +typedef struct CkptSortItem CkptSortItem; + +#ifdef ENABLE_MOT +typedef enum { + EVENT_CHECKPOINT_CREATE_SNAPSHOT, + EVENT_CHECKPOINT_SNAPSHOT_READY, + EVENT_CHECKPOINT_BEGIN_CHECKPOINT, + EVENT_CHECKPOINT_ABORT +} CheckpointEvent; + +typedef void (*CheckpointCallback)(CheckpointEvent checkpointEvent, XLogRecPtr lsn, void* arg); + +extern void RegisterCheckpointCallback(CheckpointCallback callback, void* arg); +extern void CallCheckpointCallback(CheckpointEvent checkpointEvent, XLogRecPtr lsn); +#endif + +extern void BackgroundWriterMain(void); +extern void CheckpointerMain(void); + +extern void RequestCheckpoint(int flags); +extern void CheckpointWriteDelay(int flags, double progress); + +extern bool ForwardFsyncRequest(const RelFileNode rnode, ForkNumber forknum, BlockNumber segno); +extern void AbsorbFsyncRequests(void); + +extern Size CheckpointerShmemSize(void); +extern void CheckpointerShmemInit(void); + +extern bool FirstCallSinceLastCheckpoint(void); +extern bool IsBgwriterProcess(void); + +/* incremental checkpoint bgwriter thread */ +const int INCRE_CKPT_BGWRITER_VIEW_COL_NUM = 6; +extern const incre_ckpt_view_col g_bgwriter_view_col[INCRE_CKPT_BGWRITER_VIEW_COL_NUM]; +extern void candidate_buf_init(void); +extern void incre_ckpt_bgwriter_cxt_init(); +extern void incre_ckpt_background_writer_main(void); +extern void ckpt_shutdown_bgwriter(); +extern int get_bgwriter_thread_id(void); +extern bool candidate_buf_pop(int *bufId, int threadId); + +typedef struct BgWriterProc { + PGPROC *proc; + CkptSortItem *dirty_buf_list; + uint32 dirty_list_size; + int *cand_buf_list; /* thread candidate buffer list */ + volatile int cand_list_size; /* thread candidate list max size */ + volatile int buf_id_start; /* buffer id start loc */ + pg_atomic_uint64 head; + pg_atomic_uint64 tail; + bool need_flush; + ThrdDwCxt thrd_dw_cxt; /* thread double writer cxt */ + volatile uint32 thread_last_flush; + int32 next_scan_loc; +} BgWriterProc; +#endif /* _BGWRITER_H */ + diff -uprN postgresql-hll-2.14_old/include/include/postmaster/cbmwriter.h postgresql-hll-2.14/include/include/postmaster/cbmwriter.h --- postgresql-hll-2.14_old/include/include/postmaster/cbmwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/cbmwriter.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbmwriter.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/cbmwriter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _CBMWRITER_H +#define _CBMWRITER_H + +extern void CBMWriterMain(void); + +#endif /* _CBMWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/fencedudf.h postgresql-hll-2.14/include/include/postmaster/fencedudf.h --- postgresql-hll-2.14_old/include/include/postmaster/fencedudf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/fencedudf.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * fencedudf.h + * The header file of implementing to run UDF in fenced mode + * + * The core design is to implement a RPC server and client, run udf in RPC server. + * User defined C function is not safe, because if the UDF has some bugs which can + * cause coredump or memory leak in gaussdb, So we need provide an fenced mode for udf. + * When we run fenecd udf, it will run in RPC server. If UDF cause coredump, there is not + * any impact for gaussdb process. + * + * + * IDENTIFICATION + * src/include/postmaster/fencedudf.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef FENCEDUDF_H +#define FENCEDUDF_H +#include "access/htup.h" + +extern void FencedUDFMasterMain(int argc, char* argv[]); +extern bool RPCInitFencedUDFIfNeed(Oid functionId, FmgrInfo* finfo, HeapTuple procedureTuple); +template +extern Datum RPCFencedUDF(FunctionCallInfo fcinfo); +extern void InitFuncCallUDFInfo(FunctionCallInfoData* finfo, int batchRows, int argN, bool batchMode); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/postmaster/fork_process.h postgresql-hll-2.14/include/include/postmaster/fork_process.h --- postgresql-hll-2.14_old/include/include/postmaster/fork_process.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/fork_process.h 2020-12-12 17:06:43.254348129 +0800 @@ -0,0 +1,17 @@ +/* ------------------------------------------------------------------------- + * + * fork_process.h + * Exports from postmaster/fork_process.c. + * + * Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/fork_process.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FORK_PROCESS_H +#define FORK_PROCESS_H + +extern pid_t fork_process(void); + +#endif /* FORK_PROCESS_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/licensechecker.h postgresql-hll-2.14/include/include/postmaster/licensechecker.h --- postgresql-hll-2.14_old/include/include/postmaster/licensechecker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/licensechecker.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * licensechecker.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/licensechecker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef POSTMASTER_LICENSECHECKER_H +#define POSTMASTER_LICENSECHECKER_H + +extern void LicenseCheckerMain(char* str); + +#endif /* POSTMASTER_LICENSECHECKER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/lwlockmonitor.h postgresql-hll-2.14/include/include/postmaster/lwlockmonitor.h --- postgresql-hll-2.14_old/include/include/postmaster/lwlockmonitor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/lwlockmonitor.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lwlockmonitor.h + * Automatically clean two-phase transaction + * + * + * IDENTIFICATION + * src/include/postmaster/lwlockmonitor.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _LWLOCKMONITOR_H +#define _LWLOCKMONITOR_H + +extern void FaultMonitorMain(); + +#endif /* _LWLOCKMONITOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/pagewriter.h postgresql-hll-2.14/include/include/postmaster/pagewriter.h --- postgresql-hll-2.14_old/include/include/postmaster/pagewriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/pagewriter.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,99 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pagewriter.h + * Data struct to store pagewriter thread variables. + * + * + * IDENTIFICATION + * src/include/postmaster/pagewriter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PAGEWRITER_H +#define _PAGEWRITER_H +#include "storage/buf.h" + +typedef struct PGPROC PGPROC; +typedef struct BufferDesc BufferDesc; + +typedef struct ThrdDwCxt { + char* dw_buf; + uint16 write_pos; + volatile int dw_page_idx; /* -1 means data files have been flushed. */ + bool contain_hashbucket; +} ThrdDwCxt; + +typedef struct PageWriterProc { + PGPROC* proc; + volatile uint32 start_loc; + volatile uint32 end_loc; + volatile bool need_flush; + volatile uint32 actual_flush_num; +} PageWriterProc; + +typedef struct PageWriterProcs { + PageWriterProc* writer_proc; + volatile int num; /* number of pagewriter thread */ + pg_atomic_uint32 running_num; /* number of pagewriter thread which flushing dirty page */ + ThrdDwCxt thrd_dw_cxt; +} PageWriterProcs; + +typedef struct DirtyPageQueueSlot { + volatile int buffer; + pg_atomic_uint32 slot_state; +} DirtyPageQueueSlot; + +typedef Datum (*incre_ckpt_view_get_data_func)(); + +const int INCRE_CKPT_VIEW_NAME_LEN = 128; + +typedef struct incre_ckpt_view_col { + char name[INCRE_CKPT_VIEW_NAME_LEN]; + Oid data_type; + incre_ckpt_view_get_data_func get_val; +} incre_ckpt_view_col; + +/* + * The slot location is pre-occupied. When the slot buffer is set, the state will set + * to valid. when remove dirty page form queue, don't change the state, only when move + * the dirty page head, need set the slot state is invalid. + */ +const int SLOT_VALID = 1; + +extern bool IsPagewriterProcess(void); +extern void incre_ckpt_pagewriter_cxt_init(); +extern void ckpt_pagewriter_main(void); + +extern bool push_pending_flush_queue(Buffer buffer); +extern void remove_dirty_page_from_queue(BufferDesc* buf); +extern int64 get_dirty_page_num(); +extern uint64 get_dirty_page_queue_tail(); +extern int get_pagewriter_thread_id(void); +extern bool is_dirty_page_queue_full(BufferDesc* buf); +extern int get_dirty_page_queue_head_buffer(); +/* Shutdown all the page writer threads. */ +extern void ckpt_shutdown_pagewriter(); +extern uint64 get_dirty_page_queue_rec_lsn(); +extern XLogRecPtr ckpt_get_min_rec_lsn(void); +extern uint32 calculate_thread_max_flush_num(bool is_pagewriter); + +const int PAGEWRITER_VIEW_COL_NUM = 8; +const int INCRE_CKPT_VIEW_COL_NUM = 7; + +extern const incre_ckpt_view_col g_ckpt_view_col[INCRE_CKPT_VIEW_COL_NUM]; +extern const incre_ckpt_view_col g_pagewriter_view_col[PAGEWRITER_VIEW_COL_NUM]; + +#endif /* _PAGEWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/pgarch.h postgresql-hll-2.14/include/include/postmaster/pgarch.h --- postgresql-hll-2.14_old/include/include/postmaster/pgarch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/pgarch.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * pgarch.h + * Exports from postmaster/pgarch.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/pgarch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PGARCH_H +#define _PGARCH_H + +/* ---------- + * Functions called from postmaster + * ---------- + */ +extern ThreadId pgarch_start(void); + +#ifdef EXEC_BACKEND +extern void PgArchiverMain(); +#endif + +#endif /* _PGARCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/postmaster.h postgresql-hll-2.14/include/include/postmaster/postmaster.h --- postgresql-hll-2.14_old/include/include/postmaster/postmaster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/postmaster.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * postmaster.h + * Exports from postmaster/postmaster.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/postmaster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _POSTMASTER_H +#define _POSTMASTER_H + +#include "replication/replicainternal.h" + +extern THR_LOCAL bool comm_client_bind; + +extern bool FencedUDFMasterMode; + +/* the logicTid index for nonProc thread*/ +#define POSTMASTER_LID 1 +#define PGSTAT_LID 2 +#define PGARCH_LID 3 +#define SYSLOGGER_LID 4 + +/* Startup/shutdown state */ +#define NoShutdown 0 +#define SmartShutdown 1 +#define FastShutdown 2 +#define ImmediateShutdown 3 + +extern volatile int Shutdown; + +extern uint32 noProcLogicTid; +extern THR_LOCAL bool stop_mythread; +extern THR_LOCAL ThreadId stop_threadid; + +extern pthread_mutex_t bt_lock; +extern pthread_rwlock_t hba_rwlock; + +typedef enum ReplicationType { + RT_WITH_DUMMY_STANDBY, + RT_WITH_MULTI_STANDBY, + RT_WITHOUT_STANDBY, + RT_NUM +} ReplicationType; + +#define IS_DN_MULTI_STANDYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITH_MULTI_STANDBY) +#define IS_DN_DUMMY_STANDYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITH_DUMMY_STANDBY) +#define IS_DN_WITHOUT_STANDBYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITHOUT_STANDBY) + +/* + * We use a simple state machine to control startup, shutdown, and + * crash recovery (which is rather like shutdown followed by startup). + * + * After doing all the postmaster initialization work, we enter PM_STARTUP + * state and the startup process is launched. The startup process begins by + * reading the control file and other preliminary initialization steps. + * In a normal startup, or after crash recovery, the startup process exits + * with exit code 0 and we switch to PM_RUN state. However, archive recovery + * is handled specially since it takes much longer and we would like to support + * hot standby during archive recovery. + * + * When the startup process is ready to start archive recovery, it signals the + * postmaster, and we switch to PM_RECOVERY state. The background writer and + * checkpointer are launched, while the startup process continues applying WAL. + * If Hot Standby is enabled, then, after reaching a consistent point in WAL + * redo, startup process signals us again, and we switch to PM_HOT_STANDBY + * state and begin accepting connections to perform read-only queries. When + * archive recovery is finished, the startup process exits with exit code 0 + * and we switch to PM_RUN state. + * + * Normal child backends can only be launched when we are in PM_RUN or + * PM_HOT_STANDBY state. (We also allow launch of normal + * child backends in PM_WAIT_BACKUP state, but only for superusers.) + * In other states we handle connection requests by launching "dead_end" + * child processes, which will simply send the client an error message and + * quit. (We track these in the g_instance.backend_list so that we can know when they + * are all gone; this is important because they're still connected to shared + * memory, and would interfere with an attempt to destroy the shmem segment, + * possibly leading to SHMALL failure when we try to make a new one.) + * In PM_WAIT_DEAD_END state we are waiting for all the dead_end children + * to drain out of the system, and therefore stop accepting connection + * requests at all until the last existing child has quit (which hopefully + * will not be very long). + * + * Notice that this state variable does not distinguish *why* we entered + * states later than PM_RUN --- g_instance.status and g_instance.fatal_error must be consulted + * to find that out. g_instance.fatal_error is never true in PM_RECOVERY_* or PM_RUN + * states, nor in PM_SHUTDOWN states (because we don't enter those states + * when trying to recover from a crash). It can be true in PM_STARTUP state, + * because we don't clear it until we've successfully started WAL redo. + * Similarly, RecoveryError means that we have crashed during recovery, and + * should not try to restart. + */ +typedef enum { + PM_INIT, /* postmaster starting */ + PM_STARTUP, /* waiting for startup subprocess */ + PM_RECOVERY, /* in archive recovery mode */ + PM_HOT_STANDBY, /* in hot standby mode */ + PM_RUN, /* normal "database is alive" state */ + PM_WAIT_BACKUP, /* waiting for online backup mode to end */ + PM_WAIT_READONLY, /* waiting for read only backends to exit */ + PM_WAIT_BACKENDS, /* waiting for live backends to exit */ + PM_SHUTDOWN, /* waiting for checkpointer to do shutdown + * ckpt */ + PM_SHUTDOWN_2, /* waiting for archiver and walsenders to + * finish */ + PM_WAIT_DEAD_END, /* waiting for dead_end children to exit */ + PM_NO_CHILDREN /* all important children have exited */ +} PMState; + +extern volatile PMState pmState; + +#define MAX_PMSTATE_MSG_LEN 100 +typedef struct PMStateInfo { + PMState pmState; /* PM state */ + char pmStateMsg[MAX_PMSTATE_MSG_LEN]; /* PM state message */ +} PMStateInfo; + +extern const char* GetPMState(const PMState pmState); + +/* + * Constants that represent which of postmaster_alive_fds is held by + * postmaster, and which is used in children to check for postmaster death. + */ +#define POSTMASTER_FD_WATCH \ + 0 /* used in children to check for \ + * postmaster death */ +#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */ + +#define AmPostmasterProcess() (t_thrd.proc_cxt.MyProcPid == PostmasterPid) + +extern const char* progname; + +extern int PostmasterMain(int argc, char* argv[]); +extern void ClosePostmasterPorts(bool am_syslogger); +extern void ExitPostmaster(int status); + +extern int MaxLivePostmasterChildren(void); + +extern Size CBMShmemSize(void); +extern void CBMShmemInit(void); + +extern Size HaShmemSize(void); +extern void HaShmemInit(void); +#ifdef EXEC_BACKEND +extern Size ShmemBackendArraySize(void); +extern void ShmemBackendArrayAllocation(void); +extern int SubPostmasterMain(int argc, char* argv[]); + +#endif +#define MAX_BACKENDS 0x3FFFF +extern void KillGraceThreads(void); + +#define MAX_IPADDR_LEN 32 +#define MAX_PORT_LEN 6 +#define MAX_LISTEN_ENTRY 64 +#define MAX_IP_STR_LEN 64 +#define MAX_UNIX_PATH_LEN 1024 +#define LOCAL_HOST "localhost" +#define LOOP_IP_STRING "127.0.0.1" +#define LOOP_IPV6_IP "::1" + +#define NO_NEED_UN_TCPIP (0x00) +#define NEED_CREATE_UN (0x0F) +#define NEED_CREATE_TCPIP (0xF0) +#define NEED_CREATE_UN_TCPIP (0xFF) + +typedef struct LISTEN_ENTRY { + char ipaddr[MAX_IPADDR_LEN]; + int portnum; + int createmodel; /* type of the socket to be created */ +} LISTEN_ENTRY; + +typedef struct LISTEN_ADDRS { + int usedNum; + LISTEN_ENTRY lsnArray[MAX_LISTEN_ENTRY]; +} LISTEN_ADDRS; + +typedef struct DnUsedSpaceHashEntry { + uint64 query_id; + uint64 dnUsedSpace; +} DnUsedSpaceHashEntry; + +extern void CreateServerSocket( + char* ipaddr, int portNumber, int enCreatemode, int* success, bool add_localaddr_flag, bool is_create_psql_sock); +extern bool CheckSockAddr(struct sockaddr* sock_addr, const char* szIP, int port); + +extern DbState get_local_dbstate(void); +extern const char* wal_get_db_state_string(DbState db_state); + +extern void socket_close_on_exec(void); +extern void HandleChildCrash(ThreadId pid, int exitstatus, const char* procname); + +/* for ReaperBackend thread */ +extern volatile ThreadId ReaperBackendPID; + +extern bool IsCBMWriterRunning(void); + +void SetFlagForGetLCName(bool falg); + +extern ServerMode GetServerMode(); +/* set disable connection */ +extern void set_disable_conn_mode(void); +/* Defines the position where the signal "disable_conn_primary" is saved. */ +#define disable_conn_file "disable_conn_file" +#define POLLING_CONNECTION_STR "polling_connection" +#define SPECIFY_CONNECTION_STR "specify_connection" +#define PROHIBIT_CONNECTION_STR "prohibit_connection" + +#ifdef ENABLE_MULTIPLE_NODES +#define IsConnPortFromCoord(port) \ + ((port)->cmdline_options != NULL && strstr((port)->cmdline_options, "remotetype=coordinator") != NULL) +#else +#define IsConnPortFromCoord(port) false +#endif + +bool IsFromLocalAddr(Port* port); +extern bool IsHASocketAddr(struct sockaddr* sock_addr); +extern bool IsHAPort(Port* port); +extern ThreadId initialize_util_thread(knl_thread_role role, void* payload = NULL); +extern ThreadId initialize_worker_thread(knl_thread_role role, Port* port, void* payload = NULL); +extern void startup_die(SIGNAL_ARGS); +extern void PortInitialize(Port* port, knl_thread_arg* arg); +extern void PreClientAuthorize(); +extern int ClientConnInitilize(Port* port); +extern void CheckClientIp(Port* port); +extern Backend* GetBackend(int slot); +extern Backend* AssignFreeBackEnd(int slot); +extern long PostmasterRandom(void); +extern void signal_child(ThreadId pid, int signal, int be_mode); +extern void GenerateCancelKey(bool isThreadPoolSession); +extern bool SignalCancelAllBackEnd(); +extern bool IsLocalAddr(Port* port); +extern uint64_t mc_timers_us(void); +extern bool SetDBStateFileState(DbState state, bool optional); +extern void GPCResetAll(); +#endif /* _POSTMASTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/remoteservice.h postgresql-hll-2.14/include/include/postmaster/remoteservice.h --- postgresql-hll-2.14_old/include/include/postmaster/remoteservice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/remoteservice.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remoteservice.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/remoteservice.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REMOTESERVICE_H +#define _REMOTESERVICE_H + +extern void RemoteServiceMain(void); + +#endif /* _REMOTESERVICE_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/startup.h postgresql-hll-2.14/include/include/postmaster/startup.h --- postgresql-hll-2.14_old/include/include/postmaster/startup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/startup.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,42 @@ +/* ------------------------------------------------------------------------- + * + * startup.h + * Exports from postmaster/startup.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/startup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _STARTUP_H +#define _STARTUP_H + +typedef enum { NOTIFY_PRIMARY = 0, NOTIFY_STANDBY, NOTIFY_FAILOVER, NOTIFY_SWITCHOVER, NUM_NOTIFYS } NotifyReason; + +/* + * Save the notify signal reason in the share memory. + * NotifySignalFlags include primary signal, standby signal and promote signal. + */ +typedef struct notifysignaldata { + sig_atomic_t NotifySignalFlags[NUM_NOTIFYS]; +} NotifySignalData; + +extern void StartupProcessMain(void); +extern void PreRestoreCommand(void); +extern void PostRestoreCommand(void); + +extern bool IsFailoverTriggered(void); +extern bool IsSwitchoverTriggered(void); +extern bool IsPrimaryTriggered(void); +extern bool IsStandbyTriggered(void); +extern void ResetSwitchoverTriggered(void); +extern void ResetFailoverTriggered(void); +extern void ResetPrimaryTriggered(void); +extern void ResetStandbyTriggered(void); + +extern Size NotifySignalShmemSize(void); +extern void NotifySignalShmemInit(void); +extern void SendNotifySignal(NotifyReason reason, ThreadId ProcPid); +extern bool CheckNotifySignal(NotifyReason reason); +#endif /* _STARTUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/syslogger.h postgresql-hll-2.14/include/include/postmaster/syslogger.h --- postgresql-hll-2.14_old/include/include/postmaster/syslogger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/syslogger.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,179 @@ +/* ------------------------------------------------------------------------- + * + * syslogger.h + * Exports from postmaster/syslogger.c. + * + * Copyright (c) 2004-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/syslogger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _SYSLOGGER_H +#define _SYSLOGGER_H + +#include /* for PIPE_BUF */ + +/* + * Primitive protocol structure for writing to syslogger pipe(s). The idea + * here is to divide long messages into chunks that are not more than + * PIPE_BUF bytes long, which according to POSIX spec must be written into + * the pipe atomically. The pipe reader then uses the protocol headers to + * reassemble the parts of a message into a single string. The reader can + * also cope with non-protocol data coming down the pipe, though we cannot + * guarantee long strings won't get split apart. + * + * We use non-nul bytes in is_last to make the protocol a tiny bit + * more robust against finding a false double nul byte prologue. But + * we still might find it in the len and/or pid bytes unless we're careful. + */ + +#ifdef PIPE_BUF +/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */ +#if PIPE_BUF > 65536 +#define LOGPIPE_CHUNK_SIZE 65536 +#else +#define LOGPIPE_CHUNK_SIZE ((int)PIPE_BUF) +#endif +#else /* not defined */ +/* POSIX says the value of PIPE_BUF must be at least 512, so use that */ +#define LOGPIPE_CHUNK_SIZE 512 +#endif + +#define PROFILE_LOG_TAG "gs_profile" +#define PROFILE_LOG_SUFFIX ".prf" +#define SLOWQUERY_LOG_TAG "sql_monitor" +#define ASP_LOG_TAG "asp_data" +#define PERF_JOB_TAG "pg_perf" + +enum LogType { + /* error log */ + LOG_TYPE_ELOG = 0, + + /* profiling log */ + LOG_TYPE_PLOG, + + /* slow query monitor log */ + LOG_TYPE_PLAN_LOG, + /* active session profile log */ + LOG_TYPE_ASP_LOG, + + /* a solider flag, LOG_TYPE_MAXVALID should be <= LOG_TYPE_UPLIMIT */ + LOG_TYPE_MAXVALID, + + /* + * max value of log type. + * it's stored by CHAR datatype. see LogPipeProtoHeader::logtype + */ + LOG_TYPE_UPLIMIT = 127 +}; + +typedef struct LogControlData { + bool inited; + uint16 ver; + + /* rotation request */ + volatile sig_atomic_t rotation_requested; + + /* to flush buffer request */ + volatile sig_atomic_t flush_requested; + + /* log directory */ + char* log_dir; + + /* pattern of log file name */ + char* filename_pattern; + char* file_suffix; + + /* current log file name and its fd */ + char* now_file_name; + FILE* now_file_fd; + + /* log chunk buffer */ + char* log_buf; + int cur_len; + int max_len; +} LogControlData; + +/* + * max length of this node name. this is a arbitrary value. + * just keep it the same with struct NameData. + */ +#define LOG_MAX_NODENAME_LEN 64 + +#define LOG_MAGICNUM 0x2017091810170000 +#define PROTO_HEADER_MAGICNUM 0x123456789ABCDEF0 +/* + * current log version about profile log + * advance it when log struct is modified each time. + */ +#define PROFILE_LOG_VERSION 1 + +/* header data in each binary log file */ +typedef struct { + /* must be the first */ + unsigned long fst_magic; + + uint16 version; + uint8 hostname_len; + uint8 nodename_len; + uint16 timezone_len; + + /* + * part1: hostname <- hostname_len + * part2: nodename <- nodename_len + * part3: timezone <- timezone_len + */ + + /* must be the last */ + unsigned long lst_magic; +} LogFileHeader; + +typedef struct { + char nuls[2]; /* always \0\0 */ + uint16 len; /* size of this chunk (counts data only) */ + char logtype; /* which log type, see LogType */ + char is_last; /* last chunk of message? 't' or 'f' ('T' or + * 'F' for CSV case) */ + /* writer's pid. be placed the last, and make data 8 bytes alligned */ + ThreadId pid; + uint64 magic; /* magic number to check the proto header */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */ +} LogPipeProtoHeader; + +typedef union { + LogPipeProtoHeader proto; + char filler[LOGPIPE_CHUNK_SIZE]; +} LogPipeProtoChunk; + +#define LOGPIPE_HEADER_SIZE offsetof(LogPipeProtoHeader, data) +#define LOGPIPE_MAX_PAYLOAD ((int)(LOGPIPE_CHUNK_SIZE - LOGPIPE_HEADER_SIZE)) + +extern THR_LOCAL bool am_syslogger; + +#ifndef WIN32 + +#else +extern THR_LOCAL HANDLE syslogPipe[2]; +#endif + +extern ThreadId SysLogger_Start(void); + +extern void SysLoggerClose(void); + +extern void write_syslogger_file(char* buffer, int count, int dest); + +#ifdef EXEC_BACKEND +extern void SysLoggerMain(int fd); +#endif + +extern void LogCtlLastFlushBeforePMExit(void); +extern void set_flag_to_flush_buffer(void); +extern void* SQMOpenLogFile(bool *doOpen); +extern void SQMCloseLogFile(); + +extern void* ASPOpenLogFile(bool *doOpen); +extern void ASPCloseLogFile(); +extern void init_instr_log_directory(bool include_nodename, const char* logid); + +#endif /* _SYSLOGGER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/twophasecleaner.h postgresql-hll-2.14/include/include/postmaster/twophasecleaner.h --- postgresql-hll-2.14_old/include/include/postmaster/twophasecleaner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/twophasecleaner.h 2020-12-12 17:06:43.255348141 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * twophasecleaner.h + * Automatically clean two-phase transaction + * + * + * IDENTIFICATION + * src/include/postmaster/twophasecleaner.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _TWOPHASECLEANER_H +#define _TWOPHASECLEANER_H + +extern bool bSyncXactsCallGsclean; + +extern PGPROC* twoPhaseCleanerProc; + +extern void TwoPhaseCleanerMain(); + +#endif /* _TWOPHASECLEANER_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/walwriterauxiliary.h postgresql-hll-2.14/include/include/postmaster/walwriterauxiliary.h --- postgresql-hll-2.14_old/include/include/postmaster/walwriterauxiliary.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/walwriterauxiliary.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * ------------------------------------------------------------------------- + * + * walwriterauxiliary.h + * Exports from postmaster/walwriterauxiliary.c. + * + * IDENTIFICATION + * src/include/postmaster/walwriterauxiliary.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALWRITERAUXILIARY_H +#define _WALWRITERAUXILIARY_H + +extern void WalWriterAuxiliaryMain(void); + +#endif /* _WALWRITERAUXILIARY_H */ diff -uprN postgresql-hll-2.14_old/include/include/postmaster/walwriter.h postgresql-hll-2.14/include/include/postmaster/walwriter.h --- postgresql-hll-2.14_old/include/include/postmaster/walwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/postmaster/walwriter.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * walwriter.h + * Exports from postmaster/walwriter.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/walwriter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALWRITER_H +#define _WALWRITER_H + +#ifdef ENABLE_MOT +typedef void (*WALCallback)(void* arg); + +extern void RegisterWALCallback(WALCallback callback, void* arg); +extern void CallWALCallback(); +#endif + +extern void WalWriterMain(void); + +#endif /* _WALWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/include/profile.h postgresql-hll-2.14/include/include/profile.h --- postgresql-hll-2.14_old/include/include/profile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/profile.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,355 @@ +/* + * profile.h + */ + +#ifndef _KRB5_PROFILE_H +#define _KRB5_PROFILE_H + +#if defined(_WIN32) +#include +#endif + +#if defined(__MACH__) && defined(__APPLE__) +# include +# if TARGET_RT_MAC_CFM +# error "Use KfM 4.0 SDK headers for CFM compilation." +# endif +#endif + +#ifndef KRB5_CALLCONV +#define KRB5_CALLCONV +#define KRB5_CALLCONV_C +#endif + +typedef struct _profile_t *profile_t; + +/* Used by profile_init_flags(). */ +#define PROFILE_INIT_ALLOW_MODULE 0x0001 /* Allow module declaration */ + +/* + * Used by the profile iterator in prof_get.c + */ +#define PROFILE_ITER_LIST_SECTION 0x0001 +#define PROFILE_ITER_SECTIONS_ONLY 0x0002 +#define PROFILE_ITER_RELATIONS_ONLY 0x0004 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef char* profile_filespec_t; /* path as C string */ +typedef char* profile_filespec_list_t; /* list of : separated paths, C string */ +typedef const char * const_profile_filespec_t; /* path as C string */ +typedef const char * const_profile_filespec_list_t; /* list of : separated paths, C string */ + +long KRB5_CALLCONV profile_init + (const_profile_filespec_t *files, profile_t *ret_profile); + +long KRB5_CALLCONV profile_init_flags + (const_profile_filespec_t *files, int flags, profile_t *ret_profile); + +long KRB5_CALLCONV profile_init_path + (const_profile_filespec_list_t filelist, profile_t *ret_profile); + +long KRB5_CALLCONV profile_flush + (profile_t profile); +long KRB5_CALLCONV profile_flush_to_file + (profile_t profile, const_profile_filespec_t outfile); +long KRB5_CALLCONV profile_flush_to_buffer + (profile_t profile, char **bufp); +void KRB5_CALLCONV profile_free_buffer + (profile_t profile, char *buf); + +long KRB5_CALLCONV profile_is_writable + (profile_t profile, int *writable); +long KRB5_CALLCONV profile_is_modified + (profile_t profile, int *modified); + +void KRB5_CALLCONV profile_abandon + (profile_t profile); + +void KRB5_CALLCONV profile_release + (profile_t profile); + +long KRB5_CALLCONV profile_get_values + (profile_t profile, const char *const *names, char ***ret_values); + +void KRB5_CALLCONV profile_free_list + (char **list); + +long KRB5_CALLCONV profile_get_string + (profile_t profile, const char *name, const char *subname, + const char *subsubname, const char *def_val, + char **ret_string); +long KRB5_CALLCONV profile_get_integer + (profile_t profile, const char *name, const char *subname, + const char *subsubname, int def_val, + int *ret_default); + +long KRB5_CALLCONV profile_get_boolean + (profile_t profile, const char *name, const char *subname, + const char *subsubname, int def_val, + int *ret_default); + +long KRB5_CALLCONV profile_get_relation_names + (profile_t profile, const char **names, char ***ret_names); + +long KRB5_CALLCONV profile_get_subsection_names + (profile_t profile, const char **names, char ***ret_names); + +long KRB5_CALLCONV profile_iterator_create + (profile_t profile, const char *const *names, + int flags, void **ret_iter); + +void KRB5_CALLCONV profile_iterator_free + (void **iter_p); + +long KRB5_CALLCONV profile_iterator + (void **iter_p, char **ret_name, char **ret_value); + +void KRB5_CALLCONV profile_release_string (char *str); + +long KRB5_CALLCONV profile_update_relation + (profile_t profile, const char **names, + const char *old_value, const char *new_value); + +long KRB5_CALLCONV profile_clear_relation + (profile_t profile, const char **names); + +long KRB5_CALLCONV profile_rename_section + (profile_t profile, const char **names, + const char *new_name); + +long KRB5_CALLCONV profile_add_relation + (profile_t profile, const char **names, + const char *new_value); + +/* + * profile_init_vtable allows a caller to create a profile-compatible object + * with a different back end. + */ + +/* + * Mandatory: Look up all of the relations for names, placing the resulting + * values in *ret_values. If no relations exist, return PROF_NO_RELATION, or + * PROF_NO_SECTION to indicate that one of the intermediate names does not + * exist as a section. The list will be freed with free_values. + */ +typedef long +(*profile_get_values_fn)(void *cbdata, const char *const *names, + char ***ret_values); + +/* Mandatory: Free a list of strings returned by get_values. */ +typedef void +(*profile_free_values_fn)(void *cbdata, char **values); + +/* Optional: Release any data associated with the profile. */ +typedef void +(*profile_cleanup_fn)(void *cbdata); + +/* + * Optional (mandatory if cleanup is defined): Generate a new cbdata pointer + * for a copy of the profile. If not implemented, the new profile will receive + * the same cbdata pointer as the old one. + */ +typedef long +(*profile_copy_fn)(void *cbdata, void **ret_cbdata); + +/* + * Optional: Create an iterator handle. + * + * If flags contains PROFILE_ITER_LIST_SECTION, iterate over all of the + * relations and sections within names. Otherwise, iterate over the relation + * values for names, or produce a single section result if names is a section. + * + * If flags contains PROFILE_ITER_SECTIONS_ONLY, produce only sections. + * + * If flags contains PROFILE_ITER_RELATIONS_ONLY, produce only relations. + */ +typedef long +(*profile_iterator_create_fn)(void *cbdata, const char *const *names, + int flags, void **ret_iter); + +/* + * Optional (mandatory if iterator_create is defined): Produce the next + * relation or section in an iteration. If producing a section result, set + * *ret_value to NULL. The returned strings will be freed with free_string. + */ +typedef long +(*profile_iterator_fn)(void *cbdata, void *iter, char **ret_name, + char **ret_value); + +/* + * Optional (mandatory if iterator_create is defined): Free the memory for an + * iterator. + */ +typedef void +(*profile_iterator_free_fn)(void *cbdata, void *iter); + +/* Optional (mandatory if iterator is defined): Free a string value. */ +typedef void +(*profile_free_string_fn)(void *cbdata, char *string); + +/* + * Optional: Determine if a profile is writable. If not implemented, the + * profile is never writable. + */ +typedef long +(*profile_writable_fn)(void *cbdata, int *writable); + +/* + * Optional: Determine if a profile is modified in memory relative to the + * persistent store. If not implemented, the profile is assumed to never be + * modified. + */ +typedef long +(*profile_modified_fn)(void *cbdata, int *modified); + +/* + * Optional: Change the value of a relation, or remove it if new_value is NULL. + * If old_value is set and the relation does not have that value, return + * PROF_NO_RELATION. + */ +typedef long +(*profile_update_relation_fn)(void *cbdata, const char **names, + const char *old_value, const char *new_value); + +/* + * Optional: Rename a section to new_name, or remove the section if new_name is + * NULL. + */ +typedef long +(*profile_rename_section_fn)(void *cbdata, const char **names, + const char *new_name); + +/* + * Optional: Add a new relation, or a new section if new_value is NULL. Add + * any intermediate sections as necessary. + */ +typedef long +(*profile_add_relation_fn)(void *cbdata, const char **names, + const char *new_value); + +/* + * Optional: Flush any pending memory updates to the persistent store. If + * implemented, this function will be called by profile_release as well as + * profile_flush, so make sure it's not inefficient to flush an unmodified + * profile. + */ +typedef long +(*profile_flush_fn)(void *cbdata); + +struct profile_vtable { + int minor_ver; /* Set to structure minor version (currently 1) + * if calling profile_init_vtable. */ + + /* Methods needed for a basic read-only non-iterable profile (cleanup is + * optional). */ + profile_get_values_fn get_values; + profile_free_values_fn free_values; + profile_cleanup_fn cleanup; + profile_copy_fn copy; + + /* Methods for iterable profiles. */ + profile_iterator_create_fn iterator_create; + profile_iterator_fn iterator; + profile_iterator_free_fn iterator_free; + profile_free_string_fn free_string; + + /* Methods for writable profiles. */ + profile_writable_fn writable; + profile_modified_fn modified; + profile_update_relation_fn update_relation; + profile_rename_section_fn rename_section; + profile_add_relation_fn add_relation; + profile_flush_fn flush; + + /* End of minor version 1. */ +}; + +/* + * Create a profile object whose operations will be performed using the + * function pointers in vtable. cbdata will be supplied to each vtable + * function as the first argument. + */ +long KRB5_CALLCONV profile_init_vtable + (struct profile_vtable *vtable, void *cbdata, profile_t *ret_profile); + +/* + * Dynamically loadable profile modules should define a function named + * "profile_module_init" matching the following signature. The function should + * initialize the methods of the provided vtable structure, stopping at the + * field corresponding to vtable->minor_ver. Do not change the value of + * vtable->minor_ver. Unimplemented methods can be left uninitialized. The + * function should supply a callback data pointer in *cb_ret; this pointer can + * be cleaned up via the vtable cleanup method. + */ +typedef long +(*profile_module_init_fn)(const char *residual, struct profile_vtable *vtable, + void **cb_ret); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _KRB5_PROFILE_H */ +/* + * et-h-prof_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define PROF_VERSION (-1429577728L) +#define PROF_MAGIC_NODE (-1429577727L) +#define PROF_NO_SECTION (-1429577726L) +#define PROF_NO_RELATION (-1429577725L) +#define PROF_ADD_NOT_SECTION (-1429577724L) +#define PROF_SECTION_WITH_VALUE (-1429577723L) +#define PROF_BAD_LINK_LIST (-1429577722L) +#define PROF_BAD_GROUP_LVL (-1429577721L) +#define PROF_BAD_PARENT_PTR (-1429577720L) +#define PROF_MAGIC_ITERATOR (-1429577719L) +#define PROF_SET_SECTION_VALUE (-1429577718L) +#define PROF_EINVAL (-1429577717L) +#define PROF_READ_ONLY (-1429577716L) +#define PROF_SECTION_NOTOP (-1429577715L) +#define PROF_SECTION_SYNTAX (-1429577714L) +#define PROF_RELATION_SYNTAX (-1429577713L) +#define PROF_EXTRA_CBRACE (-1429577712L) +#define PROF_MISSING_OBRACE (-1429577711L) +#define PROF_MAGIC_PROFILE (-1429577710L) +#define PROF_MAGIC_SECTION (-1429577709L) +#define PROF_TOPSECTION_ITER_NOSUPP (-1429577708L) +#define PROF_INVALID_SECTION (-1429577707L) +#define PROF_END_OF_SECTIONS (-1429577706L) +#define PROF_BAD_NAMESET (-1429577705L) +#define PROF_NO_PROFILE (-1429577704L) +#define PROF_MAGIC_FILE (-1429577703L) +#define PROF_FAIL_OPEN (-1429577702L) +#define PROF_EXISTS (-1429577701L) +#define PROF_BAD_BOOLEAN (-1429577700L) +#define PROF_BAD_INTEGER (-1429577699L) +#define PROF_MAGIC_FILE_DATA (-1429577698L) +#define PROF_FAIL_INCLUDE_FILE (-1429577697L) +#define PROF_FAIL_INCLUDE_DIR (-1429577696L) +#define PROF_UNSUPPORTED (-1429577695L) +#define PROF_MAGIC_NODE_ITERATOR (-1429577694L) +#define PROF_MODULE (-1429577693L) +#define PROF_MODULE_SYNTAX (-1429577692L) +#define PROF_MODULE_INVALID (-1429577691L) +#define ERROR_TABLE_BASE_prof (-1429577728L) + +extern const struct error_table et_prof_error_table; + +#if !defined(_WIN32) +/* for compatibility with older versions... */ +extern void initialize_prof_error_table (void) /*@modifies internalState@*/; +#else +#define initialize_prof_error_table() +#endif + +#if !defined(_WIN32) +#define init_prof_err_tbl initialize_prof_error_table +#define prof_err_base ERROR_TABLE_BASE_prof +#endif diff -uprN postgresql-hll-2.14_old/include/include/regex/regcustom.h postgresql-hll-2.14/include/include/regex/regcustom.h --- postgresql-hll-2.14_old/include/include/regex/regcustom.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/regex/regcustom.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regcustom.h + */ + +/* headers if any */ +#include "postgres.h" +#include "knl/knl_variable.h" + +#include +#include + +/* + * towlower() and friends should be in , but some pre-C99 systems + * declare them in . + */ +#ifdef HAVE_WCHAR_H +#include +#endif +#ifdef HAVE_WCTYPE_H +#include +#endif + +#include "mb/pg_wchar.h" + +/* overrides for regguts.h definitions, if any */ +#define FUNCPTR(name, args) (*name) args +#define MALLOC(n) selfpalloc(n) +#define FREE(p) selfpfree(VS(p)) +#define REALLOC(p, n) selfrepalloc(VS(p), n) +#ifndef assert +#define assert(x) Assert(x) +#endif + +/* internal character type and related */ +typedef pg_wchar chr; /* the type itself */ +typedef unsigned uchr; /* unsigned type that will hold a chr */ +typedef int celt; /* type to hold chr, or NOCELT */ + +#define NOCELT (-1) /* celt value which is not valid chr */ +#define CHR(c) ((unsigned char)(c)) /* turn char literal into chr literal */ +#define DIGITVAL(c) ((c) - '0') /* turn chr digit into its value */ +#define CHRBITS 32 /* bits in a chr; must not use sizeof */ +#define CHR_MIN 0x00000000 /* smallest and largest chr; the value */ +#define CHR_MAX \ + 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and \ + * CHR_MAX+1 must fit in both chr and celt */ + +/* functions operating on chr */ +#define iscalnum(x) pg_wc_isalnum(x) +#define iscalpha(x) pg_wc_isalpha(x) +#define iscdigit(x) pg_wc_isdigit(x) +#define iscspace(x) pg_wc_isspace(x) + +/* and pick up the standard header */ +#include "regex.h" diff -uprN postgresql-hll-2.14_old/include/include/regex/regerrs.h postgresql-hll-2.14/include/include/regex/regerrs.h --- postgresql-hll-2.14_old/include/include/regex/regerrs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/regex/regerrs.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,45 @@ +/* + * src/include/regex/regerrs.h + */ +#ifndef REGERRS_H +#define REGERRS_H + +{REG_OKAY, "REG_OKAY", "no errors detected"}, + + {REG_NOMATCH, "REG_NOMATCH", "failed to match"}, + + {REG_BADPAT, "REG_BADPAT", "invalid regexp (reg version 0.8)"}, + + {REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"}, + + {REG_ECTYPE, "REG_ECTYPE", "invalid character class"}, + + {REG_EESCAPE, "REG_EESCAPE", "invalid escape \\ sequence"}, + + {REG_ESUBREG, "REG_ESUBREG", "invalid backreference number"}, + + {REG_EBRACK, "REG_EBRACK", "brackets [] not balanced"}, + + {REG_EPAREN, "REG_EPAREN", "parentheses () not balanced"}, + + {REG_EBRACE, "REG_EBRACE", "braces {} not balanced"}, + + {REG_BADBR, "REG_BADBR", "invalid repetition count(s)"}, + + {REG_ERANGE, "REG_ERANGE", "invalid character range"}, + + {REG_ESPACE, "REG_ESPACE", "out of memory"}, + + {REG_BADRPT, "REG_BADRPT", "quantifier operand invalid"}, + + {REG_ASSERT, "REG_ASSERT", "\"cannot happen\" -- you found a bug"}, + + {REG_INVARG, "REG_INVARG", "invalid argument to regex function"}, + + {REG_MIXED, "REG_MIXED", "character widths of regex and string differ"}, + + {REG_BADOPT, "REG_BADOPT", "invalid embedded option"}, + + {REG_ETOOBIG, "REG_ETOOBIG", "regular expression is too complex"}, + +#endif /* REGERRS_H */ diff -uprN postgresql-hll-2.14_old/include/include/regex/regex.h postgresql-hll-2.14/include/include/regex/regex.h --- postgresql-hll-2.14_old/include/include/regex/regex.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/regex/regex.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,179 @@ +#ifndef _REGEX_H_ +#define _REGEX_H_ /* never again */ +/* + * regular expressions + * + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regex.h + */ + +/* + * Add your own defines, if needed, here. + */ +#include "mb/pg_wchar.h" + +/* + * interface types etc. + */ + +/* + * regoff_t has to be large enough to hold either off_t or ssize_t, + * and must be signed; it's only a guess that long is suitable. + */ +typedef long regoff_t; + +/* + * other interface types + */ + +/* the biggie, a compiled RE (or rather, a front end to same) */ +typedef struct { + int re_magic; /* magic number */ + size_t re_nsub; /* number of subexpressions */ + long re_info; /* information about RE */ +#define REG_UBACKREF 000001 +#define REG_ULOOKAROUND 000002 +#define REG_UBOUNDS 000004 +#define REG_UBRACES 000010 +#define REG_UBSALNUM 000020 +#define REG_UPBOTCH 000040 +#define REG_UBBS 000100 +#define REG_UNONPOSIX 000200 +#define REG_UUNSPEC 000400 +#define REG_UUNPORT 001000 +#define REG_ULOCALE 002000 +#define REG_UEMPTYMATCH 004000 +#define REG_UIMPOSSIBLE 010000 +#define REG_USHORTEST 020000 + int re_csize; /* sizeof(character) */ + char* re_endp; /* backward compatibility kludge */ + Oid re_collation; /* Collation that defines LC_CTYPE behavior */ + /* the rest is opaque pointers to hidden innards */ + char* re_guts; /* `char *' is more portable than `void *' */ + char* re_fns; +} regex_t; + +/* result reporting (may acquire more fields later) */ +typedef struct { + regoff_t rm_so; /* start of substring */ + regoff_t rm_eo; /* end of substring */ +} regmatch_t; + +/* supplementary control and reporting */ +typedef struct { + regmatch_t rm_extend; /* see REG_EXPECT */ +} rm_detail_t; + +/* + * regex compilation flags + */ +#define REG_BASIC 000000 /* BREs (convenience) */ +#define REG_EXTENDED 000001 /* EREs */ +#define REG_ADVF 000002 /* advanced features in EREs */ +#define REG_ADVANCED 000003 /* AREs (which are also EREs) */ +#define REG_QUOTE 000004 /* no special characters, none */ +#define REG_NOSPEC REG_QUOTE /* historical synonym */ +#define REG_ICASE 000010 /* ignore case */ +#define REG_NOSUB 000020 /* don't care about subexpressions */ +#define REG_EXPANDED 000040 /* expanded format, white space & comments */ +#define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */ +#define REG_NLANCH 000200 /* ^ matches after \n, $ before */ +#define REG_NEWLINE 000300 /* newlines are line terminators */ +#define REG_PEND 000400 /* ugh -- backward-compatibility hack */ +#define REG_EXPECT 001000 /* report details on partial/limited matches */ +#define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */ +#define REG_DUMP 004000 /* none of your business :-) */ +#define REG_FAKE 010000 /* none of your business :-) */ +#define REG_PROGRESS 020000 /* none of your business :-) */ + +/* + * regex execution flags + */ +#define REG_NOTBOL 0001 /* BOS is not BOL */ +#define REG_NOTEOL 0002 /* EOS is not EOL */ +#define REG_STARTEND 0004 /* backward compatibility kludge */ +#define REG_FTRACE 0010 /* none of your business */ +#define REG_MTRACE 0020 /* none of your business */ +#define REG_SMALL 0040 /* none of your business */ + +/* + * error reporting + * Be careful if modifying the list of error codes -- the table used by + * regerror() is generated automatically from this file! + */ +#define REG_OKAY 0 /* no errors detected */ +#define REG_NOMATCH 1 /* failed to match */ +#define REG_BADPAT 2 /* invalid regexp */ +#define REG_ECOLLATE 3 /* invalid collating element */ +#define REG_ECTYPE 4 /* invalid character class */ +#define REG_EESCAPE 5 /* invalid escape \ sequence */ +#define REG_ESUBREG 6 /* invalid backreference number */ +#define REG_EBRACK 7 /* brackets [] not balanced */ +#define REG_EPAREN 8 /* parentheses () not balanced */ +#define REG_EBRACE 9 /* braces {} not balanced */ +#define REG_BADBR 10 /* invalid repetition count(s) */ +#define REG_ERANGE 11 /* invalid character range */ +#define REG_ESPACE 12 /* out of memory */ +#define REG_BADRPT 13 /* quantifier operand invalid */ +#define REG_ASSERT 15 /* "can't happen" -- you found a bug */ +#define REG_INVARG 16 /* invalid argument to regex function */ +#define REG_MIXED 17 /* character widths of regex and string differ */ +#define REG_BADOPT 18 /* invalid embedded option */ +#define REG_ETOOBIG 19 /* regular expression is too complex */ +/* two specials for debugging and testing */ +#define REG_ATOI 101 /* convert error-code name to number */ +#define REG_ITOA 102 /* convert error-code number to name */ +/* non-error result codes for pg_regprefix */ +#define REG_PREFIX (-1) /* identified a common prefix */ +#define REG_EXACT (-2) /* identified an exact match */ + +/* this is the maximum number of cached regular expressions */ +#ifndef MAX_CACHED_RES +#define MAX_CACHED_RES 32 +#endif + +/* this structure describes one cached regular expression */ +typedef struct cached_re_str { + char* cre_pat; /* original RE (not null terminated!) */ + int cre_pat_len; /* length of original RE, in bytes */ + int cre_flags; /* compile flags: extended,icase etc */ + Oid cre_collation; /* collation to use */ + regex_t cre_re; /* the compiled regular expression */ +} cached_re_str; + +/* + * the prototypes for exported functions + */ +extern int pg_regcomp(regex_t*, const pg_wchar*, size_t, int, Oid); +extern int pg_regexec(regex_t*, const pg_wchar*, size_t, size_t, rm_detail_t*, size_t, regmatch_t[], int); +extern int pg_regprefix(regex_t*, pg_wchar**, size_t*); +extern void pg_regfree(regex_t*); +extern size_t pg_regerror(int, const regex_t*, char*, size_t); +extern void pg_set_regex_collation(Oid collation); + +#endif /* _REGEX_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/regex/regguts.h postgresql-hll-2.14/include/include/regex/regguts.h --- postgresql-hll-2.14_old/include/include/regex/regguts.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/regex/regguts.h 2020-12-12 17:06:43.256348154 +0800 @@ -0,0 +1,459 @@ +/* + * Internal interface definitions, etc., for the reg package + * + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regguts.h + */ + +/* + * Environmental customization. It should not (I hope) be necessary to + * alter the file you are now reading -- regcustom.h should handle it all, + * given care here and elsewhere. + */ +#include "regcustom.h" + +/* + * Things that regcustom.h might override. + */ + +/* assertions */ +#ifndef assert +#ifndef REG_DEBUG +#define NDEBUG /* no assertions */ +#endif +#include +#endif + +/* voids */ +#ifndef DISCARD +#define DISCARD void /* for throwing values away */ +#endif +#ifndef VS +#define VS(x) ((void*)(x)) /* cast something to generic ptr */ +#endif + +/* function-pointer declarator */ +#ifndef FUNCPTR +#define FUNCPTR(name, args) (*(name)) args +#endif + +/* memory allocation */ +#ifndef MALLOC +#define MALLOC(n) selfpalloc(n) +#endif +#ifndef REALLOC +#define REALLOC(p, n) selfrepalloc(VS(p), n) +#endif +#ifndef FREE +#define FREE(p) selfpfree(VS(p)) +#endif + +/* want size of a char in bits, and max value in bounded quantifiers */ +#ifndef CHAR_BIT +#include +#endif +#ifndef _POSIX2_RE_DUP_MAX +#define _POSIX2_RE_DUP_MAX 255 /* normally from */ +#endif + +/* + * misc + */ + +#define NOTREACHED 0 + +#define DUPMAX _POSIX2_RE_DUP_MAX +#ifdef INFINITY +#undef INFINITY +#endif +#define INFINITY (DUPMAX + 1) + +#define REMAGIC 0xfed7 /* magic number for main struct */ + +/* Type codes for lookaround constraints */ +#define LATYPE_AHEAD_POS 03 /* positive lookahead */ +#define LATYPE_AHEAD_NEG 02 /* negative lookahead */ +#define LATYPE_BEHIND_POS 01 /* positive lookbehind */ +#define LATYPE_BEHIND_NEG 00 /* negative lookbehind */ +#define LATYPE_IS_POS(la) ((la)&01) +#define LATYPE_IS_AHEAD(la) ((la)&02) + +/* + * debugging facilities + */ +#ifdef REG_DEBUG +/* FDEBUG does finite-state tracing */ +#define FDEBUG(arglist) \ + { \ + if (v->eflags & REG_FTRACE) \ + printf arglist; \ + } +/* MDEBUG does higher-level tracing */ +#define MDEBUG(arglist) \ + { \ + if (v->eflags & REG_MTRACE) \ + printf arglist; \ + } +#else +#define FDEBUG(arglist) \ + {} +#define MDEBUG(arglist) \ + {} +#endif + +/* + * bitmap manipulation + */ +#define UBITS (CHAR_BIT * sizeof(unsigned)) +#define BSET(uv, sn) ((uv)[(sn) / UBITS] |= (unsigned)1 << ((sn) % UBITS)) +#define ISBSET(uv, sn) ((uv)[(sn) / UBITS] & ((unsigned)1 << ((sn) % UBITS))) + +/* + * We dissect a chr into byts for colormap table indexing. Here we define + * a byt, which will be the same as a byte on most machines... The exact + * size of a byt is not critical, but about 8 bits is good, and extraction + * of 8-bit chunks is sometimes especially fast. + */ +#ifndef BYTBITS +#define BYTBITS 8 /* bits in a byt */ +#endif +#define BYTTAB (1 << BYTBITS) /* size of table with one entry per byt value */ +#define BYTMASK (BYTTAB - 1) /* bit mask for byt */ +#define NBYTS ((CHRBITS + BYTBITS - 1) / BYTBITS) +/* the definition of GETCOLOR(), below, assumes NBYTS <= 4 */ + +/* + * As soon as possible, we map chrs into equivalence classes -- "colors" -- + * which are of much more manageable number. + */ +typedef short color; /* colors of characters */ +typedef int pcolor; /* what color promotes to */ + +#define COLORLESS (-1) /* impossible color */ +#define WHITE 0 /* default color, parent of all others */ + +/* + * A colormap is a tree -- more precisely, a DAG -- indexed at each level + * by a byt of the chr, to map the chr to a color efficiently. Because + * lower sections of the tree can be shared, it can exploit the usual + * sparseness of such a mapping table. The tree is always NBYTS levels + * deep (in the past it was shallower during construction but was "filled" + * to full depth at the end of that); areas that are unaltered as yet point + * to "fill blocks" which are entirely WHITE in color. + */ + +/* the tree itself */ +struct colors { + color ccolor[BYTTAB]; +}; +struct ptrs { + union tree* pptr[BYTTAB]; +}; +union tree { + struct colors colors; + struct ptrs ptrs; +}; + +#define tcolor colors.ccolor +#define tptr ptrs.pptr + +/* + * Per-color data structure for the compile-time color machinery + * + * If "sub" is not NOSUB then it is the number of the color's current + * subcolor, i.e. we are in process of dividing this color (character + * equivalence class) into two colors. See src/backend/regex/README for + * discussion of subcolors. + * + * Currently-unused colors have the FREECOL bit set and are linked into a + * freelist using their "sub" fields, but only if their color numbers are + * less than colormap.max. Any array entries beyond "max" are just garbage. + */ +struct colordesc { + uchr nchrs; /* number of chars of this color */ + color sub; /* open subcolor, if any; or free-chain ptr */ +#define NOSUB COLORLESS /* value of "sub" when no open subcolor */ + struct arc* arcs; /* chain of all arcs of this color */ + chr firstchr; /* char first assigned to this color */ + int flags; /* bit values defined next */ +#define FREECOL 01 /* currently free */ +#define PSEUDO 02 /* pseudocolor, no real chars */ +#define UNUSEDCOLOR(cd) ((cd)->flags & FREECOL) + union tree* block; /* block of solid color, if any */ +}; + +/* + * The color map itself + * + * Much of the data in the colormap struct is only used at compile time. + * However, the bulk of the space usage is in the "tree" structure, so it's + * not clear that there's much point in converting the rest to a more compact + * form when compilation is finished. + */ +struct colormap { + int magic; +#define CMMAGIC 0x876 + struct vars* v; /* for compile error reporting */ + size_t ncds; /* allocated length of colordescs array */ + size_t max; /* highest color number currently in use */ + color free; /* beginning of free chain (if non-0) */ + struct colordesc* cd; /* pointer to array of colordescs */ +#define CDEND(cm) (&(cm)->cd[(cm)->max + 1]) + /* If we need up to NINLINECDS, we store them here to save a malloc */ +#define NINLINECDS ((size_t)10) + struct colordesc cdspace[NINLINECDS]; + union tree tree[NBYTS]; /* tree top, plus lower-level fill blocks */ +}; + +/* optimization magic to do fast chr->color mapping */ +#define B0(c) ((c)&BYTMASK) +#define B1(c) (((c) >> BYTBITS) & BYTMASK) +#define B2(c) (((c) >> (2 * BYTBITS)) & BYTMASK) +#define B3(c) (((c) >> (3 * BYTBITS)) & BYTMASK) +#if NBYTS == 1 +#define GETCOLOR(cm, c) ((cm)->tree->tcolor[B0(c)]) +#endif +/* beware, for NBYTS>1, GETCOLOR() is unsafe -- 2nd arg used repeatedly */ +#if NBYTS == 2 +#define GETCOLOR(cm, c) ((cm)->tree->tptr[B1(c)]->tcolor[B0(c)]) +#endif +#if NBYTS == 4 +#define GETCOLOR(cm, c) ((cm)->tree->tptr[B3(c)]->tptr[B2(c)]->tptr[B1(c)]->tcolor[B0(c)]) +#endif + +/* + * Interface definitions for locale-interface functions in regc_locale.c. + */ + +/* + * Representation of a set of characters. chrs[] represents individual + * code points, ranges[] represents ranges in the form min..max inclusive. + * + * Note that in cvecs gotten from newcvec() and intended to be freed by + * freecvec(), both arrays of chrs are after the end of the struct, not + * separately malloc'd; so chrspace and rangespace are effectively immutable. + */ +struct cvec { + int nchrs; /* number of chrs */ + int chrspace; /* number of chrs allocated in chrs[] */ + chr* chrs; /* pointer to vector of chrs */ + int nranges; /* number of ranges (chr pairs) */ + int rangespace; /* number of ranges allocated in ranges[] */ + chr* ranges; /* pointer to vector of chr pairs */ +}; + +/* + * definitions for NFA internal representation + * + * Having a "from" pointer within each arc may seem redundant, but it + * saves a lot of hassle. + */ +struct state; + +struct arc { + int type; /* 0 if free, else an NFA arc type code */ + color co; + struct state* from; /* where it's from (and contained within) */ + struct state* to; /* where it's to */ + struct arc* outchain; /* link in *from's outs chain or free chain */ + struct arc* outchainRev; /* back-link in *from's outs chain */ +#define freechain outchain /* we do not maintain "freechainRev" */ + struct arc* inchain; /* link in *to's ins chain */ + struct arc* inchainRev; /* back-link in *to's ins chain */ + struct arc* colorchain; /* link in color's arc chain */ + struct arc* colorchainRev; /* back-link in color's arc chain */ +}; + +struct arcbatch { /* for bulk allocation of arcs */ + struct arcbatch* next; +#define ABSIZE 10 + struct arc a[ABSIZE]; +}; + +struct state { + int no; +#define FREESTATE (-1) + char flag; /* marks special states */ + int nins; /* number of inarcs */ + struct arc* ins; /* chain of inarcs */ + int nouts; /* number of outarcs */ + struct arc* outs; /* chain of outarcs */ + struct arc* free; /* chain of free arcs */ + struct state* tmp; /* temporary for traversal algorithms */ + struct state* next; /* chain for traversing all */ + struct state* prev; /* back chain */ + struct arcbatch oas; /* first arcbatch, avoid malloc in easy case */ + int noas; /* number of arcs used in first arcbatch */ +}; + +struct nfa { + struct state* pre; /* pre-initial state */ + struct state* init; /* initial state */ + struct state* final; /* final state */ + struct state* post; /* post-final state */ + int nstates; /* for numbering states */ + struct state* states; /* state-chain header */ + struct state* slast; /* tail of the chain */ + struct state* free; /* free list */ + struct colormap* cm; /* the color map */ + color bos[2]; /* colors, if any, assigned to BOS and BOL */ + color eos[2]; /* colors, if any, assigned to EOS and EOL */ + struct vars* v; /* simplifies compile error reporting */ + struct nfa* parent; /* parent NFA, if any */ +}; + +/* + * definitions for compacted NFA + * + * The main space savings in a compacted NFA is from making the arcs as small + * as possible. We store only the transition color and next-state number for + * each arc. The list of out arcs for each state is an array beginning at + * cnfa.states[statenumber], and terminated by a dummy carc struct with + * co == COLORLESS. + * + * The non-dummy carc structs are of two types: plain arcs and LACON arcs. + * Plain arcs just store the transition color number as "co". LACON arcs + * store the lookaround constraint number plus cnfa.ncolors as "co". LACON + * arcs can be distinguished from plain by testing for co >= cnfa.ncolors. + */ +struct carc { + color co; /* COLORLESS is list terminator */ + int to; /* next-state number */ +}; + +struct cnfa { + int nstates; /* number of states */ + int ncolors; /* number of colors (max color in use + 1) */ + int flags; +#define HASLACONS 01 /* uses lookaround constraints */ + int pre; /* setup state number */ + int post; /* teardown state number */ + color bos[2]; /* colors, if any, assigned to BOS and BOL */ + color eos[2]; /* colors, if any, assigned to EOS and EOL */ + char* stflags; /* vector of per-state flags bytes */ +#define CNFA_NOPROGRESS 01 /* flag bit for a no-progress state */ + struct carc** states; /* vector of pointers to outarc lists */ + /* states[n] are pointers into a single malloc'd array of arcs */ + struct carc* arcs; /* the area for the lists */ +}; + +#define ZAPCNFA(cnfa) ((cnfa).nstates = 0) +#define NULLCNFA(cnfa) ((cnfa).nstates == 0) + +/* + * This symbol limits the transient heap space used by the regex compiler, + * and thereby also the maximum complexity of NFAs that we'll deal with. + * Currently we only count NFA states and arcs against this; the other + * transient data is generally not large enough to notice compared to those. + * Note that we do not charge anything for the final output data structures + * (the compacted NFA and the colormap). + */ +#ifndef REG_MAX_COMPILE_SPACE +#define REG_MAX_COMPILE_SPACE (100000 * sizeof(struct state) + 100000 * sizeof(struct arcbatch)) +#endif + +/* + * subexpression tree + * + * "op" is one of: + * '=' plain regex without interesting substructure (implemented as DFA) + * 'b' back-reference (has no substructure either) + * '(' capture node: captures the match of its single child + * '.' concatenation: matches a match for left, then a match for right + * '|' alternation: matches a match for left or a match for right + * '*' iteration: matches some number of matches of its single child + * + * Note: the right child of an alternation must be another alternation or + * NULL; hence, an N-way branch requires N alternation nodes, not N-1 as you + * might expect. This could stand to be changed. Actually I'd rather see + * a single alternation node with N children, but that will take revising + * the representation of struct subre. + * + * Note: when a backref is directly quantified, we stick the min/max counts + * into the backref rather than plastering an iteration node on top. This is + * for efficiency: there is no need to search for possible division points. + */ +struct subre { + char op; /* see type codes above */ + char flags; +#define LONGER 01 /* prefers longer match */ +#define SHORTER 02 /* prefers shorter match */ +#define MIXED 04 /* mixed preference below */ +#define CAP 010 /* capturing parens below */ +#define BACKR 020 /* back reference below */ +#define INUSE 0100 /* in use in final tree */ +#define LOCAL 03 /* bits which may not propagate up */ +#define LMIX(f) ((f) << 2) /* LONGER -> MIXED */ +#define SMIX(f) ((f) << 1) /* SHORTER -> MIXED */ +#define UP(f) (((f) & ~LOCAL) | (LMIX(f) & SMIX(f) & MIXED)) +#define MESSY(f) ((f) & (MIXED | CAP | BACKR)) +#define PREF(f) ((f)&LOCAL) +#define PREF2(f1, f2) ((PREF(f1) != 0) ? PREF(f1) : PREF(f2)) +#define COMBINE(f1, f2) (UP((f1) | (f2)) | PREF2(f1, f2)) + short id; /* ID of subre (1..ntree-1) */ + int subno; /* subexpression number (for 'b' and '('), or + * LATYPE code for lookaround constraint */ + short min; /* min repetitions for iteration or backref */ + short max; /* max repetitions for iteration or backref */ + struct subre* left; /* left child, if any (also freelist chain) */ + struct subre* right; /* right child, if any */ + struct state* begin; /* outarcs from here... */ + struct state* end; /* ...ending in inarcs here */ + struct cnfa cnfa; /* compacted NFA, if any */ + struct subre* chain; /* for bookkeeping and error cleanup */ +}; + +/* + * table of function pointers for generic manipulation functions + * A regex_t's re_fns points to one of these. + */ +struct fns { + void FUNCPTR(pfree, (regex_t*)); + int FUNCPTR(stack_too_deep, (void)); +}; + +#define STACK_TOO_DEEP(re) ((*((struct fns*)(re)->re_fns)->stack_too_deep)()) + +/* + * the insides of a regex_t, hidden behind a void * + */ +struct guts { + int magic; +#define GUTSMAGIC 0xfed9 + int cflags; /* copy of compile flags */ + long info; /* copy of re_info */ + size_t nsub; /* copy of re_nsub */ + struct subre* tree; + struct cnfa search; /* for fast preliminary search */ + int ntree; /* number of subre's, less one */ + struct colormap cmap; + int FUNCPTR(compare, (const chr*, const chr*, size_t)); + struct subre* lacons; /* lookaround-constraint vector */ + int nlacons; /* size of lacons[]; note that only slots + * numbered 1 .. nlacons-1 are used */ +}; diff -uprN postgresql-hll-2.14_old/include/include/replication/basebackup.h postgresql-hll-2.14/include/include/replication/basebackup.h --- postgresql-hll-2.14_old/include/include/replication/basebackup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/basebackup.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * basebackup.h + * Exports from replication/basebackup.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/basebackup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _BASEBACKUP_H +#define _BASEBACKUP_H + +#include "nodes/replnodes.h" + +/* + * Maximum file size for a tar member: The limit inherent in the + * format is 2^33-1 bytes (nearly 8 GB). But we don't want to exceed + * what we can represent in pgoff_t. + */ +#define MAX_TAR_MEMBER_FILELEN (((int64)1 << Min(33, sizeof(pgoff_t) * 8 - 1)) - 1) + +#define MAX_FILE_SIZE_LIMIT ((0x80000000)) + +typedef struct { + char* oid; + char* path; + char* relativePath; + int64 size; +} tablespaceinfo; + +extern XLogRecPtr XlogCopyStartPtr; + +extern void SendBaseBackup(BaseBackupCmd* cmd); +extern int64 sendTablespace(const char* path, bool sizeonly); +extern bool is_row_data_file(const char* filePath, int* segNo); +#ifdef ENABLE_MOT +extern void PerformMotCheckpointFetch(); +#endif + +/* ut test */ +extern void ut_save_xlogloc(const char* xloglocation); +#endif /* _BASEBACKUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/bcm.h postgresql-hll-2.14/include/include/replication/bcm.h --- postgresql-hll-2.14_old/include/include/replication/bcm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/bcm.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,171 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bcm.h + * bcm map interface + * + * + * IDENTIFICATION + * src/include/replication/bcm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BCM_H +#define BCM_H + +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +typedef uint32 BCMBitStatus; + +#define SYNCED 0U +#define NOTSYNCED 1 +#define BACKUP 0 +#define NOTBACKUP 1 + +typedef struct BCMHeader { + StorageEngine type; + RelFileNode node; + int32 blockSize; /* one bit corresponding size */ +} BCMHeader; + +/* + * Size of the bitmap on each bcm map page, in bytes. There's no + * extra headers, so the whole page minus the standard page header is + * used for the bitmap. + */ +#define BCMMAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData)) + +/* Number of bits allocated for each heap block. */ +#define BCM_BITS_PER_BLOCK 2 + +/* Number of heap blocks we can represent in one byte. */ +#define BCM_BLOCKS_PER_BYTE 4 + +/* Number of blocks we can represent in one bcm map page. */ +#define BCM_BLOCKS_PER_PAGE (BCMMAPSIZE * BCM_BLOCKS_PER_BYTE) + +/* 10 */ +#define BCM_SYNC_BITMASK 2U +/* 01 */ +#define BCM_BACKUP_BITMASK 1 + +/* max continous bits which should be no more than max CU load sizes */ +#define MAXCONTIBITS ((512 * 1024) / ALIGNOF_CUSIZE) + +/* 1000 */ +#define META_SYNC0_BITMASK 8U +/* 0100 */ +#define META_BACKUP0_BITMASK 4 +/* 0010 */ +#define META_SYNC1_BITMASK 2U +/* 0001 */ +#define META_BACKUP1_BITMASK 1 + +/* Number of bits allocated for each bcm block. */ +#define META_BITS_PER_BLOCK 4 + +/* Number of bcm blocks we can represent in one byte. */ +#define META_BLOCKS_PER_BYTE 2 + +/* Number of blocks we can represent in one mata page. */ +#define META_BLOCKS_PER_PAGE (BCMMAPSIZE * META_BLOCKS_PER_BYTE) + +/* + * Mapping from bcm block number to the right bit in the right bcm meta page + * Page0 is for bcm file header, so logically the bcm file is just like as follow: + * Page0-Meta1-Page11-Page12-...Page1N-Meta2-Page21-Page22... + */ +#define BCMBLK_TO_BCMGROUP(x) (((x)-1) / (META_BLOCKS_PER_PAGE + 1)) +#define BCMBLK_TO_METABLOCK(x) (BCMBLK_TO_BCMGROUP(x) * (META_BLOCKS_PER_PAGE + 1) + 1) +#define BCMBLK_TO_METABYTE(x) (((x)-BCMBLK_TO_METABLOCK(x) - 1) / META_BLOCKS_PER_BYTE) +#define BCMBLK_TO_METABIT(x) (((x)-BCMBLK_TO_METABLOCK(x) - 1) % META_BLOCKS_PER_BYTE) + +/* Mapping from heap block number to the right bit in the BCM map */ +/* Page 0 is for bcm file header, Page 1 is for meta page, so we begin from page 2 */ +#define UNITBLK_TO_BCMGROUP(x) ((x) / BCM_BLOCKS_PER_PAGE / META_BLOCKS_PER_PAGE) +#define HEAPBLK_TO_BCMBLOCK(x) (((x) / BCM_BLOCKS_PER_PAGE) + UNITBLK_TO_BCMGROUP(x) + 2) +#define HEAPBLK_TO_BCMBYTE(x) (((x) % BCM_BLOCKS_PER_PAGE) / BCM_BLOCKS_PER_BYTE) +#define HEAPBLK_TO_BCMBIT(x) ((x) % BCM_BLOCKS_PER_BYTE) + +#define SET_SYNC_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(BCM_SYNC_BITMASK << bshift); \ + byteval |= (status << (bshift + 1)); \ + byte = byteval; \ + } while (0) + +#define SET_SYNC0_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(META_SYNC0_BITMASK << bshift); \ + byteval |= (status << (bshift + 3)); \ + byte = byteval; \ + } while (0) + +#define SET_SYNC1_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(META_SYNC1_BITMASK << bshift); \ + byteval |= (status << (bshift + 1)); \ + byte = byteval; \ + } while (0) + +/* + * The algorithm is very clear, we devide this into two parts: + * 1. the total heap blocks in previous actual bcm pages. + * 2. the total heap blocks in current bcm page + */ +#define GET_HEAP_BLOCK(block, byte, bshift) \ + ((block - BCMBLK_TO_BCMGROUP(block) - 2) * BCM_BLOCKS_PER_PAGE + (byte)*BCM_BLOCKS_PER_BYTE + (bshift)) + +/* Here the block should be meta block */ +#define GET_BCM_BLOCK(block, byte, bshift) (block + (byte)*META_BLOCKS_PER_BYTE + (bshift) + 1) + +/* Create a bcm file and init the file header */ +extern void createBCMFile(Relation rel); + +/* record one bcm xlog for cu */ +extern void BCMLogCU(Relation rel, uint64 offset, int col, BCMBitStatus status, int count); + +/* Set the corresponding bit of the block as status */ +extern void BCMSetStatusBit(Relation rel, uint64 heapBlk, Buffer buf, BCMBitStatus status, int col = 0); + +/* BCM clear */ +extern void BCMClearRel(Relation rel, int col = 0); +extern void BCM_truncate(Relation rel); + +/* BCM Traversal */ +extern void GetBcmFileList(bool clear); +extern void GetIncrementalBcmFileList(); + +/* BCM xlog for setStatusBit is (RM_HEAP2_ID, XLOG_HEAP2_BCM) type */ +/* Functions in heapam.cpp: log_heap_bcm(...);heap_xlog_bcm(...)*/ + +/* BCM pin */ +extern void BCM_pin(Relation rel, BlockNumber heapBlk, Buffer* bcmbuf); + +extern void BCM_CStore_pin(Relation rel, int col, uint64 offset, Buffer* buf); + +extern void check_cu_block(char* mem, int size, int alignSize); + +extern uint64 cstore_offset_to_cstoreblock(uint64 offset, uint64 align_size); + +extern uint64 cstore_offset_to_bcmblock(uint64 offset, uint64 align_size); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/catchup.h postgresql-hll-2.14/include/include/replication/catchup.h --- postgresql-hll-2.14_old/include/include/replication/catchup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/catchup.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * catchup.h + * Exports from replication/data/catchup.cpp. + * + * + * IDENTIFICATION + * src/include/replication/catchup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CATCHUP_H +#define CATCHUP_H + +#include + +typedef enum { CATCHUP_NONE = 0, CATCHUP_STARTING, CATCHUP_SEARCHING, RECEIVED_OK, RECEIVED_NONE } CatchupState; + +extern volatile bool catchup_online; +extern volatile bool catchupDone; +extern CatchupState catchupState; + +extern bool IsCatchupProcess(void); +extern ThreadId StartCatchup(void); +extern void CatchupShutdownIfNoDataSender(void); + +#ifdef EXEC_BACKEND +extern void CatchupMain(); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/dataprotocol.h postgresql-hll-2.14/include/include/replication/dataprotocol.h --- postgresql-hll-2.14_old/include/include/replication/dataprotocol.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/dataprotocol.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,153 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataprotocol.h + * Definitions relevant to the streaming DATA transmission protocol. + * + * + * IDENTIFICATION + * src/include/replication/dataprotocol.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATAPROTOCOL_H +#define _DATAPROTOCOL_H + +#include "access/xlogdefs.h" +#include "replication/dataqueuedefs.h" +#include "replication/replicainternal.h" +#include "datatype/timestamp.h" + +/* + * All messages from DataSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct { + DataQueuePtr sendPosition; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; + bool catchup; +} DataSndMessage; + +/* + * Header for a data replication message (message type 'd'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual data page. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* data start location of the data queue included in this message */ + DataQueuePtr dataStart; + + /* data end location of the data queue included in this message */ + DataQueuePtr dataEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + bool catchup; +} DataPageMessageHeader; + +/* + * Keepalive message from primary (message type 'k'). (lowercase k) + * This is wrapped within a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef DataSndMessage DataSndKeepaliveMessage; + +/*Notify message structure for dummy scan incremental files for catchup */ +typedef struct { + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} NotifyDummyCatchupMessage; + +/* + * Refence :PrimaryKeepaliveMessage + */ +typedef struct EndDataMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + int percent; +} EndDataMessage; + +/* + * Refence :PrimaryKeepaliveMessage + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct RmDataMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} RmDataMessage; + +/* + * Reply message from standby (message type 'r'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyDataReplyMessage { + DataQueuePtr receivePosition; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the server should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} StandbyDataReplyMessage; + +/* + * Maximum data payload in data message. Must be >= XLOG_BLCKSZ. + * + * We don't have a good idea of what a good value would be; there's some + * overhead per message in both walsender and walreceiver, but on the other + * hand sending large batches makes walsender less responsive to signals + * because signals are checked only between messages. 128kB (with + * default 8k blocks) seems like a reasonable guess for now. + */ +#define MAX_SEND_SIZE (XLOG_BLCKSZ * 16) + +#endif /* _DATAPROTOCOL_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/dataqueuedefs.h postgresql-hll-2.14/include/include/replication/dataqueuedefs.h --- postgresql-hll-2.14_old/include/include/replication/dataqueuedefs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/dataqueuedefs.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataqueuedefs.h + * Data replication queue pointer r definitions + * + * + * IDENTIFICATION + * src/include/replication/dataqueuedefs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATAQUEUE_DEFS_H +#define DATAQUEUE_DEFS_H + +/* Pointer to a location in the queue. */ +typedef struct DataQueuePtr { + uint32 queueid; /* data queue id, 0 based */ + uint32 queueoff; /* byte offset of location in current queue */ +} DataQueuePtr; + +/* + * Macros for comparing DataQueuePtrs + * + * Beware of passing expressions with side-effects to these macros, + * since the arguments may be evaluated multiple times. + */ +#define DQByteLT(a, b) ((a).queueid < (b).queueid || ((a).queueid == (b).queueid && (a).queueoff < (b).queueoff)) +#define DQByteLE(a, b) ((a).queueid < (b).queueid || ((a).queueid == (b).queueid && (a).queueoff <= (b).queueoff)) +#define DQByteEQ(a, b) ((a).queueid == (b).queueid && (a).queueoff == (b).queueoff) + +#define DataQueuePtrIsInvalid(r) ((r).queueoff == 0) + +/* + * Macro for advancing a queue pointer by the specified number of bytes. + */ +#define DQByteAdvance(queueptr, nbytes) \ + do { \ + if (queueptr.queueoff > (uint32)g_instance.attr.attr_storage.DataQueueBufSize * 1024 - nbytes) { \ + queueptr.queueid += 1; \ + queueptr.queueoff = \ + (uint32)(queueptr.queueoff + nbytes - (uint32)g_instance.attr.attr_storage.DataQueueBufSize * 1024); \ + } else \ + queueptr.queueoff += nbytes; \ + } while (0) + +#endif /* DATAQUEU_DEFS_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/dataqueue.h postgresql-hll-2.14/include/include/replication/dataqueue.h --- postgresql-hll-2.14_old/include/include/replication/dataqueue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/dataqueue.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,119 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataqueue.h + * + * + * + * IDENTIFICATION + * src/include/replication/dataqueue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATAQUEUE_H +#define _DATAQUEUE_H + +#include "c.h" +#include "gs_threadlocal.h" +#include "replication/dataqueuedefs.h" +#include "replication/bcm.h" +#include "storage/s_lock.h" +#include "utils/hsearch.h" +#include "utils/pg_crc.h" + +#define WS_MAX_DATA_QUEUE_SIZE (uint32)(g_instance.attr.attr_storage.DataQueueBufSize * 1024) + +#define GETATTID(attid) ((attid) & 0xffff) +#define GETBUCKETID(attid) (((uint)(attid) >> 16) - 1) + +/* + *------------------------------------------------------ + * |****************| |**************| | + * ----------------------------------------------------- + * 0 use_tail1 use_head2 use_tail2 tail + * + * From use_tail1 to use_head2 and from use_tail2 to tail are freespace + */ +typedef struct DataQueueData { + uint32 size; /* memory size */ + + DataQueuePtr use_tail1; + DataQueuePtr use_head2; /* from use_head2 to use_tail2 are elements */ + DataQueuePtr use_tail2; + slock_t use_mutex; /* protect above variables */ + + char* pages; +} DataQueueData, *DataQueue; + +typedef struct DataElementHeaderData { + RelFileNodeOld rnode; + BlockNumber blocknum; + int attid; /* column storage id */ + StorageEngine type; + + uint64 offset; /* offset the element to be written */ + uint32 data_size; /* element size */ + DataQueuePtr queue_offset; /* current page offset in queue */ + + XLogRecPtr ref_rec_ptr; /* the associated ref xlog ptr */ + +#ifdef DATA_DEBUG + pg_crc32 data_crc; /* CRC for current page */ +#endif +} DataElementHeaderData, *DataElementHeader; + +typedef struct BCMElementData { + RelFileNodeOld rnode; + BlockNumber blocknum; + int attid; /* column storage id */ + StorageEngine type; + uint64 offset; /* offset the element to be written */ + uint32 data_size; /* element size */ + bool is_vaild; /* is this block vaild ? */ +} BCMElementData, *BCMElement; + +typedef struct heap_sync_rel_key { + Oid rd_id; /* the relation */ +} heap_sync_rel_key; + +typedef struct heap_sync_rel { + heap_sync_rel_key key; /* hash key ... must be first */ +} heap_sync_rel; + +extern Size DataQueueShmemSize(void); +extern void DataSenderQueueShmemInit(void); +extern void DataWriterQueueShmemInit(void); + +extern DataQueuePtr PushToSenderQueue(const RelFileNode& rnode, BlockNumber blockNum, StorageEngine type, + const char* mem, uint32 data_len, int attid, uint64 offset); +extern DataQueuePtr PushToWriterQueue(const char* mem, uint32 mem_len); + +extern uint32 GetFromDataQueue( + char*& buf, int bufsize, DataQueuePtr& startptr, DataQueuePtr& endptr, bool amIWriter, DataQueueData* data_queue); +extern void PopFromDataQueue(const DataQueuePtr& position, DataQueueData* data_queue); +extern void PushCUToDataQueue(Relation rel, int col, const char* mem, _in_ uint64 offset, _in_ int size, bool setbcm); +extern void ResetDataQueue(DataQueueData* data_queue); +extern bool DataQueueIsEmpty(DataQueueData* data_queue); +extern void CStoreCUReplication( + _in_ Relation rel, _in_ int attrId, _in_ char* cuData, _in_ int cuSize, _in_ uint64 cuFileOffset); +extern bool BCMArrayIsEmpty(void); +extern void ResetBCMArray(void); +extern void ClearBCMArray(void); +extern void BCMArrayDropAllBlocks(const RelFileNode& dropnode); +extern void HeapSyncHashSearch(Oid rd_id, HASHACTION action); +extern void AtAbort_RelationSync(void); +extern void AtCommit_RelationSync(void); +extern void PallocBCMBCMElementArray(void); +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/datareceiver.h postgresql-hll-2.14/include/include/replication/datareceiver.h --- postgresql-hll-2.14_old/include/include/replication/datareceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/datareceiver.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,149 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datareceiver.h + * + * + * + * IDENTIFICATION + * src/include/replication/datareceiver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATARECEIVER_H +#define _DATARECEIVER_H + +#include "storage/latch.h" +#include "storage/spin.h" +#include "storage/custorage.h" +#include "pgtime.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "replication/bcm.h" +#include "replication/dataqueuedefs.h" +#include "replication/walreceiver.h" + +/* + * MAXCONNINFO: maximum size of a connection string. + * + * XXX: Should this move to pg_config_manual.h? + */ +#define MAXCONNINFO 1024 +#define DUMMY_STANDBY_DATADIR "base/dummy_standby" + +/* + * Values for DataRcv->dataRcvState. + */ +typedef enum { + DATARCV_STOPPED, /* stopped and mustn't start up again */ + DATARCV_STARTING, /* launched, but the process hasn't + * initialized yet */ + DATARCV_RUNNING, /* datareceiver is running */ + DATARCV_STOPPING /* requested to stop, but still running */ +} DataRcvState; + +/* Shared memory area for management of datareceiver process */ +typedef struct DataRcvData { + /* + * PID of currently active datareceiver process, its current state and + * start time (actually, the time at which it was requested to be + * started). + */ + ThreadId pid; + ThreadId writerPid; + int lwpId; + DataRcvState dataRcvState; + pg_time_t startTime; + + bool isRuning; + + /* + * Time of send and receive of any message received. + */ + TimestampTz lastMsgSendTime; + TimestampTz lastMsgReceiptTime; + + /* + * Latest reported end of Data on the sender + */ + TimestampTz latestDataEndTime; + + DataQueuePtr sendPosition; /* sender sent queue position (remote queue) */ + DataQueuePtr receivePosition; /* recvwriter write queue position (remote queue) */ + DataQueuePtr localWritePosition; /* recvwriter write queue position (local queue) */ + + int dummyStandbySyncPercent; + + /* + * connection string; is used for datareceiver to connect with the primary. + */ + char conninfo[MAXCONNINFO]; + ReplConnTarget conn_target; + + Latch* datarcvWriterLatch; + + slock_t mutex; /* locks shared variables shown above */ +} DataRcvData; + +typedef struct data_writer_rel_key { + RelFileNode node; /* the relation */ + ForkNumber forkno; /* the fork number */ + int attid; /* colum id */ + StorageEngine type; +} data_writer_rel_key; + +typedef struct data_writer_rel { + data_writer_rel_key key; /* hash key ... must be first */ + Relation reln; + CUStorage* cuStorage; +} data_writer_rel; + +extern bool dummy_data_writer_use_file; + +/* prototypes for functions in datareceiver.cpp */ +extern void DataReceiverMain(void); + +extern Size DataRcvShmemSize(void); +extern void DataRcvShmemInit(void); + +extern bool DataRcvInProgress(void); +extern void ShutdownDataRcv(void); +extern void StartupDataStreaming(void); +extern void RequestDataStreaming(const char* conninfo, ReplConnTarget conn_target); +extern void InitDummyDataNum(void); + +extern void WakeupDataRcvWriter(void); +extern void wakeupWalRcvWriter(void); + +/* Receive writer */ +extern bool DataRcvWriterInProgress(void); +extern void DataRcvDataCleanup(void); +extern void walRcvDataCleanup(void); + +/* prototypes for functions in datarcvreceiver.cpp */ +extern void DataRcvWriterMain(void); +extern int DataRcvWrite(void); +extern void DataRcvSendReply(bool force, bool requestReply); + +extern void SetDataRcvDummyStandbySyncPercent(int percent); +extern int GetDataRcvDummyStandbySyncPercent(void); +extern void SetDataRcvWriterPID(ThreadId tid); +extern void ProcessDataRcvInterrupts(void); +extern void CloseDataFile(void); + +/* write data to disk */ +extern uint32 DoDataWrite(char* buf, uint32 nbytes); + +#endif /* _DATARECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/datasender.h postgresql-hll-2.14/include/include/replication/datasender.h --- postgresql-hll-2.14_old/include/include/replication/datasender.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/datasender.h 2020-12-12 17:06:43.257348167 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasender.h + * Exports from replication/datasender.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasender.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASENDER_H +#define _DATASENDER_H + +#include +#include + +#include "fmgr.h" +#include "replication/replicainternal.h" + +#define AmDataSenderToDummyStandby() (t_thrd.datasender_cxt.MyDataSnd->sendRole == SNDROLE_PRIMARY_DUMMYSTANDBY) + +#define AmDataSenderOnDummyStandby() (t_thrd.datasender_cxt.MyDataSnd->sendRole == SNDROLE_DUMMYSTANDBY_STANDBY) + +typedef struct { + char* receivedFileList; /* Buffer where we store the file list*/ + int msgLength; /* File list length we got from dummy */ + slock_t mutex; +} GlobalIncrementalBcmDefinition; + +/* user-settable parameters */ +extern volatile uint32 send_dummy_count; +extern GlobalIncrementalBcmDefinition g_incrementalBcmInfo; + +extern int DataSenderMain(void); +extern void DataSndSignals(void); +extern Size DataSndShmemSize(void); +extern void DataSndShmemInit(void); + +extern void DataSndWakeup(void); +extern bool DataSndInProgress(int type); + +extern Datum pg_stat_get_data_senders(PG_FUNCTION_ARGS); + +bool DataSndInSearching(void); +void ReplaceOrFreeBcmFileListBuffer(char* file_list, int msglength); +void InitGlobalBcm(void); + +#endif /* _DATASENDER_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/datasender_private.h postgresql-hll-2.14/include/include/replication/datasender_private.h --- postgresql-hll-2.14_old/include/include/replication/datasender_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/datasender_private.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,84 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasender_private.h + * Private definitions from replication/datasender.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasender_private.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASENDER_PRIVATE_H +#define _DATASENDER_PRIVATE_H + +#include "nodes/nodes.h" +#include "replication/syncrep.h" +#include "replication/walsender_private.h" +#include "replication/repl_gramparse.h" +#include "storage/latch.h" +#include "storage/shmem.h" +#include "storage/spin.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +typedef enum DataSndState { DATASNDSTATE_STARTUP = 0, DATASNDSTATE_CATCHUP, DATASNDSTATE_STREAMING } DataSndState; + +/* + * Each datasender has a DataSnd struct in shared memory. + */ +typedef struct DataSnd { + ThreadId pid; /* this datasender's process id, or 0 */ + int lwpId; + DataSndState state; /* this datasender's state */ + TimestampTz catchupTime[2]; /* time stamp of this datasender's catchup */ + SndRole sendRole; /* role of sender */ + bool sendKeepalive; /* do we send keepalives on this connection? */ + bool sending; /* true if sending to standby/dummystandby */ + + DataQueuePtr sendPosition; /* data in queue has been sent up to this position */ + DataQueuePtr receivePosition; /* receiver received queue position */ + + /* Protects shared variables shown above. */ + slock_t mutex; + + /* + * Latch used by backends to wake up this datasender when it has work to + * do. + */ + Latch latch; +} DataSnd; + +/* There is one DataSndCtl struct for the whole database cluster */ +typedef struct DataSndCtlData { + /* + * Synchronous replication queue with one queue per request type. + * Protected by SyncRepLock. + */ + SHM_QUEUE SyncRepQueue; + + /* the queue_offset is to release the waiting queue and transaction */ + DataQueuePtr queue_offset; + + /* Protects shared variables of all datalsnd */ + slock_t mutex; + + DataSnd datasnds[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} DataSndCtlData; + +extern void DataSndSetState(DataSndState state); + +#endif /* _DATASENDER_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/datasyncrep.h postgresql-hll-2.14/include/include/replication/datasyncrep.h --- postgresql-hll-2.14_old/include/include/replication/datasyncrep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/datasyncrep.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasyncrep.h + * Exports from replication/datasyncrep.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasyncrep.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASYNCREP_H +#define _DATASYNCREP_H + +extern void WaitForDataSync(void); +extern void DataSyncRepReleaseWaiters(void); + +#endif /* _DATASYNCREP_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/decode.h postgresql-hll-2.14/include/include/replication/decode.h --- postgresql-hll-2.14_old/include/include/replication/decode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/decode.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * decode.h + * PostgreSQL WAL to logical transformation + * + * Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/decode.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DECODE_H +#define DECODE_H + +#include "access/xlogreader.h" +#include "replication/reorderbuffer.h" +#include "replication/logical.h" + +void LogicalDecodingProcessRecord(LogicalDecodingContext* ctx, XLogReaderState* record); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_client.h postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_client.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_client.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_client.h + * Heartbeat client. + * + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_client.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_CLIENT_H +#define _HEARTBEAT_CLIENT_H +#include "replication/heartbeat/heartbeat_conn.h" + +class HeartbeatClient { +public: + HeartbeatClient(int epollfd); + ~HeartbeatClient(); + bool Connect(); + void DisConnect(); + bool IsConnect() const; + bool SendBeatHeartPacket(); + +private: + bool InitConnection(HeartbeatConnection* con, int remotePort); + bool SendStartupPacket(const HeartbeatConnection* con) const; + +private: + int epollfd_; + bool isConnect_; + HeartbeatConnection* hbConn_; +}; + +#endif /* _HEARTBEAT_CLIENT_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_conn.h postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_conn.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_conn.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,81 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_conn.h + * Data struct to store heartbeat connection. + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_conn.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_CONN_H +#define _HEARTBEAT_CONN_H +#include "utils/timestamp.h" +#include "replication/heartbeat/libpq/libpq-be.h" + +const int INVALID_CHANNEL_ID = -1; +const int AF_INET6_MAX_BITS = 128; +const int AF_INET_MAX_BITS = 32; +const int START_REPLNODE_NUM = 1; + +typedef PureLibpq::Port PurePort; + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) \ + do { \ + if (NULL != (ptr)) { \ + pfree(ptr); \ + (ptr) = NULL; \ + } \ + } while (0) +#endif + +typedef struct HeartbeatStartupPacket { + int channelIdentifier; /* Use local heart beat listening port for channel identifier */ + TimestampTz sendTime; +} HeartbeatStartupPacket; + +typedef struct HeartbeatPacket { + TimestampTz sendTime; +} HeartbeatPacket; + +/* releasedConnPtr keeps the connection ptr freed by callback */ +typedef void (*PCallback)(int fd, int events, void* arg, void** releasedConnPtr); + +typedef struct HeartbeatConnection { + int fd; + int epHandle; + int events; + int channelIdentifier; /* use remote heartbeat port for channel identifier. */ + PurePort* port; + char* remoteHost; + TimestampTz lastActiveTime; + PCallback callback; + void* arg; +} HeartbeatConnection; + +HeartbeatConnection* MakeConnection(int fd, PurePort* port); +int EventAdd(int epoll_handle, int events, HeartbeatConnection* conn); +void EventDel(int epollFd, HeartbeatConnection* conn); +bool SendHeartbeatPacket(const HeartbeatConnection* conn); +bool SendPacket(const HeartbeatConnection* con, const char* buf, size_t len); +PurePort* ConnectCreate(int serverFd); +void ConnCloseAndFree(HeartbeatConnection* conn); +void RemoveConn(HeartbeatConnection* con); +void UpdateLastHeartbeatTime(const char* remoteHost, int remotePort, TimestampTz timestamp); + +#endif /* _HEARTBEAT_CONN_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_server.h postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_server.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/heartbeat_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/heartbeat_server.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_server.h + * Heartbeat server. + * + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_SERVER_H +#define _HEARTBEAT_SERVER_H +#include "replication/heartbeat/heartbeat_conn.h" + +class HeartbeatServer { +public: + HeartbeatServer(int epollfd); + ~HeartbeatServer(); + bool Start(); + void Stop(); + bool Restart(); + bool AddConnection(HeartbeatConnection* conn, HeartbeatConnection** releasedConnPtr); + void RemoveConnection(HeartbeatConnection* conn); + void AddUnidentifiedConnection(HeartbeatConnection* conn, HeartbeatConnection** releasedConnPtr); + void RemoveUnidentifiedConnection(HeartbeatConnection* conn); + +private: + bool InitListenConnections(); + bool IsAlreadyListen(const char* ip, int port) const; + void ClearListenConnections(); + int ReleaseOldestUnidentifiedConnection(HeartbeatConnection** releasedConnPtr); + void CloseListenSockets(); + +private: + int epollfd_; + bool started_; + /* serverListenSocket_ is redundant, keep it for adapt ugly libpq interface */ + int serverListenSocket_[MAX_REPLNODE_NUM]; + HeartbeatConnection* listenConns_[MAX_REPLNODE_NUM]; + /* holds accepted and identified connections */ + HeartbeatConnection* identifiedConns_[MAX_REPLNODE_NUM]; + /* holds accepted but unindentified connections */ + HeartbeatConnection* unidentifiedConns_[MAX_REPLNODE_NUM]; +}; + +#endif /* _HEARTBEAT_SERVER_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq-be.h postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq-be.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq-be.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-be.h + * This file contains definitions for structures and externs used + * by the cm server during client coonect. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq-be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_BE_H +#define CM_LIBPQ_BE_H + +#include "replication/heartbeat/libpq/pqcomm.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +namespace PureLibpq { + +typedef enum PortLastCall { + LastCall_NONE = 0, + LastCall_SEND, + LastCall_RECV, +} PortLastCall; + +/* + * The Port structure maintains the tcp channel information, + * and is kept in palloc'd memory. + * TCP keepalive settings such as keepalives_idle,keepalives_interval + * and keepalives_count art use the default values of system. + */ +typedef struct Port { + int sock; /* File descriptor */ + SockAddr laddr; /* local addr */ + SockAddr raddr; /* remote addr */ + PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ +#define PQ_BUFFER_SIZE (16 * 1024) + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ +} Port; + +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); +extern int pq_getbyte(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int SetSocketNoBlock(int isocketId); +extern void CloseAndFreePort(Port* port); + +} // namespace PureLibpq + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq-fe.h postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq-fe.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq-fe.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_FE_H +#define CM_LIBPQ_FE_H + +#include "replication/heartbeat/libpq/libpq-be.h" + +namespace PureLibpq { + +/* Synchronous (blocking) */ +extern Port* PQconnect(const char* conninfo); + +} // namespace PureLibpq + +#endif /* CM_LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq.h postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/libpq/libpq.h 2020-12-12 17:06:43.258348180 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_H +#define CM_LIBPQ_H + +#include +#include +#include "replication/heartbeat/libpq/libpq-be.h" + +namespace PureLibpq { +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); + +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len); + +extern int pq_getbyte(Port* myport); + +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_putbytes(Port* myport, const char* s, size_t len); +} // namespace PureLibpq +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/pqcomm.h postgresql-hll-2.14/include/include/replication/heartbeat/libpq/pqcomm.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat/libpq/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat/libpq/pqcomm.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/pqcomm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_PQCOMM_H +#define CM_PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +namespace PureLibpq { + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} SockAddr; + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +} // namespace PureLibpq + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/heartbeat.h postgresql-hll-2.14/include/include/replication/heartbeat.h --- postgresql-hll-2.14_old/include/include/replication/heartbeat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/heartbeat.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,53 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat.h + * Data struct to store heartbeat thread variables. + * + * + * IDENTIFICATION + * src/include/replication/heartbeat.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_H +#define _HEARTBEAT_H + +const int MAX_EVENTS = 512; + +typedef struct channel_info { + TimestampTz connect_time; + TimestampTz last_reply_timestamp; +} channel_info; + +/* + * Heartbeat struct in shared memory. + */ +typedef struct heartbeat_state { + ThreadId pid; /* this heartbeat's process id, or 0 */ + int lwpId; + + channel_info channel_array[MAX_REPLNODE_NUM]; + + /* Protects shared variables shown above. */ + slock_t mutex; +} heartbeat_state; + +extern void heartbeat_main(void); +extern TimestampTz get_last_reply_timestamp(int replindex); +void heartbeat_shmem_init(void); +Size heartbeat_shmem_size(void); + +#endif /* _HEARTBEAT_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/libpqwalreceiver.h postgresql-hll-2.14/include/include/replication/libpqwalreceiver.h --- postgresql-hll-2.14_old/include/include/replication/libpqwalreceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/libpqwalreceiver.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpqwalreceiver.h + * libpqwalreceiver init for WalreceiverMain. + * + * + * IDENTIFICATION + * src/include/replication/libpqwalreceiver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LIBPQWALRECEIVER_H +#define LIBPQWALRECEIVER_H + +extern int32 pg_atoi(char* s, int size, int c); +extern int32 pg_strtoint32(const char* s); +/* Prototypes for interface functions */ +extern bool libpqrcv_connect_for_TLI(TimeLineID* timeLineID, char* conninfo); +extern bool libpqrcv_connect(char* conninfo, XLogRecPtr* startpoint, char* slotname, int channel_identifier); +extern bool libpqrcv_receive(int timeout, unsigned char* type, char** buffer, int* len); +extern void libpqrcv_send(const char* buffer, int nbytes); +extern void libpqrcv_disconnect(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/logicalfuncs.h postgresql-hll-2.14/include/include/replication/logicalfuncs.h --- postgresql-hll-2.14_old/include/include/replication/logicalfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/logicalfuncs.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,30 @@ +/* --------------------------------------------------------------------------------------- + * + * logicalfuncs.h + * PostgreSQL WAL to logical transformation support functions + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/logicalfuncs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LOGICALFUNCS_H +#define LOGICALFUNCS_H + +#include "replication/logical.h" + +extern int logical_read_local_xlog_page(XLogReaderState* state, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* cur_page, TimeLineID* pageTLI); + +extern bool AssignLsn(XLogRecPtr* lsn_ptr, const char* input); +extern Datum pg_logical_slot_get_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_get_binary_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_peek_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_peek_binary_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_peek_changes(PG_FUNCTION_ARGS); +extern void check_permissions(bool for_backup = false); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/logical.h postgresql-hll-2.14/include/include/replication/logical.h --- postgresql-hll-2.14_old/include/include/replication/logical.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/logical.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,105 @@ +/* --------------------------------------------------------------------------------------- + * + * logical.h + * PostgreSQL logical decoding coordination + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/logical.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LOGICAL_H +#define LOGICAL_H + +#include "replication/slot.h" + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "replication/output_plugin.h" + +struct LogicalDecodingContext; + +typedef void (*LogicalOutputPluginWriterWrite)( + struct LogicalDecodingContext* lr, XLogRecPtr Ptr, TransactionId xid, bool last_write); + +typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite; + +typedef struct LogicalDecodingContext { + /* memory context this is all allocated in */ + MemoryContext context; + + /* infrastructure pieces */ + XLogReaderState* reader; + ReplicationSlot* slot; + struct ReorderBuffer* reorder; + struct SnapBuild* snapshot_builder; + /* + * Marks the logical decoding context as fast forward decoding one. + * Such a context does not have plugin loaded so most of the the following + * properties are unused. + */ + bool fast_forward; + + OutputPluginCallbacks callbacks; + OutputPluginOptions options; + + /* + * User specified options + */ + List* output_plugin_options; + + /* + * User-Provided callback for writing/streaming out data. + */ + LogicalOutputPluginWriterPrepareWrite prepare_write; + LogicalOutputPluginWriterWrite write; + + /* + * Output buffer. + */ + StringInfo out; + + /* + * Private data pointer of the output plugin. + */ + void* output_plugin_private; + + /* + * Private data pointer for the data writer. + */ + void* output_writer_private; + + /* + * State for writing output. + */ + bool accept_writes; + bool prepared_write; + XLogRecPtr write_location; + TransactionId write_xid; + + bool random_mode; +} LogicalDecodingContext; + +extern void CheckLogicalDecodingRequirements(Oid databaseId); + +extern LogicalDecodingContext* CreateInitDecodingContext(const char* plugin, List* output_plugin_options, + bool need_full_snapshot, XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write); +extern LogicalDecodingContext* CreateInitDecodingContextInternal(char* plugin, List* output_plugin_options, + XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write, bool set_xmin_horizon, ReplicationSlot* slot); +extern LogicalDecodingContext* CreateDecodingContext(XLogRecPtr start_lsn, List* output_plugin_options, + bool fast_forward, XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write); +extern void DecodingContextFindStartpoint(LogicalDecodingContext* ctx); +extern bool DecodingContextReady(LogicalDecodingContext* ctx); +extern void FreeDecodingContext(LogicalDecodingContext* ctx); + +extern void LogicalIncreaseXminForSlot(XLogRecPtr lsn, TransactionId xmin); +extern void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart_lsn); +extern void LogicalConfirmReceivedLocation(XLogRecPtr lsn); +extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext* ctx, RepOriginId origin_id); +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/output_plugin.h postgresql-hll-2.14/include/include/replication/output_plugin.h --- postgresql-hll-2.14_old/include/include/replication/output_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/output_plugin.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,91 @@ +/* --------------------------------------------------------------------------------------- + * + * output_plugin.h + * PostgreSQL Logical Decode Plugin Interface + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/output_plugin.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OUTPUT_PLUGIN_H +#define OUTPUT_PLUGIN_H + +#include "replication/reorderbuffer.h" + +struct LogicalDecodingContext; +struct OutputPluginCallbacks; + +typedef enum OutputPluginOutputType { + OUTPUT_PLUGIN_BINARY_OUTPUT, + OUTPUT_PLUGIN_TEXTUAL_OUTPUT +} OutputPluginOutputType; + +/* + * Options set by the output plugin, in the startup callback. + */ +typedef struct OutputPluginOptions { + OutputPluginOutputType output_type; +} OutputPluginOptions; + +/* + * Type of the shared library symbol _PG_output_plugin_init that is looked up + * when loading an output plugin shared library. + */ +typedef void (*LogicalOutputPluginInit)(struct OutputPluginCallbacks* cb); + +/* + * Callback that gets called in a user-defined plugin. ctx->private_data can + * be set to some private data. + * + * "is_init" will be set to "true" if the decoding slot just got defined. When + * the same slot is used from there one, it will be "false". + */ +typedef void (*LogicalDecodeStartupCB)(struct LogicalDecodingContext* ctx, OutputPluginOptions* options, bool is_init); + +/* + * Callback called for every (explicit or implicit) BEGIN of a successful + * transaction. + */ +typedef void (*LogicalDecodeBeginCB)(struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn); + +/* + * Callback for every individual change in a successful transaction. + */ +typedef void (*LogicalDecodeChangeCB)( + struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn, Relation relation, ReorderBufferChange* change); + +/* + * Called for every (explicit or implicit) COMMIT of a successful transaction. + */ +typedef void (*LogicalDecodeCommitCB)(struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn, XLogRecPtr commit_lsn); + +/* + * Called to shutdown an output plugin. + */ +typedef void (*LogicalDecodeShutdownCB)(struct LogicalDecodingContext* ctx); + +/* + * Filter changes by origin. + */ +typedef bool (*LogicalDecodeFilterByOriginCB)(struct LogicalDecodingContext* ctx, RepOriginId origin_id); + +/* + * Output plugin callbacks + */ +typedef struct OutputPluginCallbacks { + LogicalDecodeStartupCB startup_cb; + LogicalDecodeBeginCB begin_cb; + LogicalDecodeChangeCB change_cb; + LogicalDecodeCommitCB commit_cb; + LogicalDecodeShutdownCB shutdown_cb; + LogicalDecodeFilterByOriginCB filter_by_origin_cb; +} OutputPluginCallbacks; + +extern void OutputPluginPrepareWrite(struct LogicalDecodingContext* ctx, bool last_write); +extern void OutputPluginWrite(struct LogicalDecodingContext* ctx, bool last_write); + +#endif /* OUTPUT_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/reorderbuffer.h postgresql-hll-2.14/include/include/replication/reorderbuffer.h --- postgresql-hll-2.14_old/include/include/replication/reorderbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/reorderbuffer.h 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,382 @@ +/* --------------------------------------------------------------------------------------- + * + * reorderbuffer.h + * PostgreSQL logical replay/reorder buffer management. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/reorderbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REORDERBUFFER_H +#define REORDERBUFFER_H + +#include "lib/ilist.h" + +#include "storage/sinval.h" + +#include "utils/hsearch.h" +#include "utils/rel.h" +#include "utils/snapshot.h" +#include "utils/timestamp.h" + +/* an individual tuple, stored in one chunk of memory */ +typedef struct ReorderBufferTupleBuf { + /* position in preallocated list */ + slist_node node; + + /* tuple header, the interesting bit for users of logical decoding */ + HeapTupleData tuple; + /* pre-allocated size of tuple buffer, different from tuple size */ + Size alloc_tuple_size; + + /* actual tuple data follows */ +} ReorderBufferTupleBuf; +/* pointer to the data stored in a TupleBuf */ +#define ReorderBufferTupleBufData(p) ((HeapTupleHeader)MAXALIGN(((char*)p) + sizeof(ReorderBufferTupleBuf))) + +/* + * Types of the change passed to a 'change' callback. + * + * For efficiency and simplicity reasons we want to keep Snapshots, CommandIds + * and ComboCids in the same list with the user visible INSERT/UPDATE/DELETE + * changes. Users of the decoding facilities will never see changes with + * *_INTERNAL_* actions. + */ +enum ReorderBufferChangeType { + REORDER_BUFFER_CHANGE_INSERT, + REORDER_BUFFER_CHANGE_UPDATE, + REORDER_BUFFER_CHANGE_DELETE, + REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT, + REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID, + REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID +}; + +/* + * a single 'change', can be an insert (with one tuple), an update (old, new), + * or a delete (old). + * + * The same struct is also used internally for other purposes but that should + * never be visible outside reorderbuffer.c. + */ +typedef struct ReorderBufferChange { + XLogRecPtr lsn; + + /* The type of change. */ + enum ReorderBufferChangeType action; + + RepOriginId origin_id; + + /* + * Context data for the change, which part of the union is valid depends + * on action/action_internal. + */ + union { + /* Old, new tuples when action == *_INSERT|UPDATE|DELETE */ + struct { + /* relation that has been changed */ + RelFileNode relnode; + /* no previously reassembled toast chunks are necessary anymore */ + bool clear_toast_afterwards; + + /* valid for DELETE || UPDATE */ + ReorderBufferTupleBuf* oldtuple; + /* valid for INSERT || UPDATE */ + ReorderBufferTupleBuf* newtuple; + } tp; + + /* New snapshot, set when action == *_INTERNAL_SNAPSHOT */ + Snapshot snapshot; + + /* + * New command id for existing snapshot in a catalog changing tx. Set + * when action == *_INTERNAL_COMMAND_ID. + */ + CommandId command_id; + + /* + * New cid mapping for catalog changing transaction, set when action + * == *_INTERNAL_TUPLECID. + */ + struct { + RelFileNode node; + ItemPointerData tid; + CommandId cmin; + CommandId cmax; + CommandId combocid; + } tuplecid; + } data; + + /* + * While in use this is how a change is linked into a transactions, + * otherwise it's the preallocated list. + */ + dlist_node node; +} ReorderBufferChange; + +typedef struct ReorderBufferTXN { + /* + * The transactions transaction id, can be a toplevel or sub xid. + */ + TransactionId xid; + + /* did the TX have catalog changes */ + bool has_catalog_changes; + + /* Do we know this is a subxact? Xid of top-level txn if so */ + bool is_known_as_subxact; + + TransactionId toplevel_xid; + + /* + * LSN of the first data carrying, WAL record with knowledge about this + * xid. This is allowed to *not* be first record adorned with this xid, if + * the previous records aren't relevant for logical decoding. + */ + XLogRecPtr first_lsn; + + /* ---- + * LSN of the record that lead to this xact to be committed or + * aborted. This can be a + * * plain commit record + * * plain commit record, of a parent transaction + * * prepared transaction commit + * * plain abort record + * * prepared transaction abort + * * error during decoding + * ---- + */ + XLogRecPtr final_lsn; + + /* + * LSN pointing to the end of the commit record + 1. + */ + XLogRecPtr end_lsn; + + /* + * LSN of the last lsn at which snapshot information reside, so we can + * restart decoding from there and fully recover this transaction from + * WAL. + */ + XLogRecPtr restart_decoding_lsn; + + /* origin of the change that caused this transaction */ + RepOriginId origin_id; + + /* The csn of the transaction */ + CommitSeqNo csn; + + /* + * Commit time, only known when we read the actual commit record. + */ + TimestampTz commit_time; + + /* + * Base snapshot or NULL. + * The base snapshot is used to decode all changes until either this + * transaction modifies the catalog, or another catalog-modifying + * transaction commits. + */ + Snapshot base_snapshot; + XLogRecPtr base_snapshot_lsn; + dlist_node base_snapshot_node; /* link in txns_by_base_snapshot_lsn */ + + /* + * How many ReorderBufferChange's do we have in this txn. + * + * Changes in subtransactions are *not* included but tracked separately. + */ + uint64 nentries; + + /* + * How many of the above entries are stored in memory in contrast to being + * spilled to disk. + */ + uint64 nentries_mem; + + /* + * Has this transaction been spilled to disk? It's not always possible to + * deduce that fact by comparing nentries with nentries_mem, because + * e.g. subtransactions of a large transaction might get serialized + * together with the parent - if they're restored to memory they'd have + * nentries_mem == nentries. + */ + bool serialized; + + /* + * List of ReorderBufferChange structs, including new Snapshots and new + * CommandIds + */ + dlist_head changes; + + /* + * List of (relation, ctid) => (cmin, cmax) mappings for catalog tuples. + * Those are always assigned to the toplevel transaction. (Keep track of + * #entries to create a hash of the right size) + */ + dlist_head tuplecids; + uint64 ntuplecids; + + /* + * On-demand built hash for looking up the above values. + */ + HTAB* tuplecid_hash; + + /* + * Hash containing (potentially partial) toast entries. NULL if no toast + * tuples have been found for the current change. + */ + HTAB* toast_hash; + + /* + * non-hierarchical list of subtransactions that are *not* aborted. Only + * used in toplevel transactions. + */ + dlist_head subtxns; + uint32 nsubtxns; + + /* + * Stored cache invalidations. This is not a linked list because we get + * all the invalidations at once. + */ + uint32 ninvalidations; + SharedInvalidationMessage* invalidations; + + /* --- + * Position in one of three lists: + * * list of subtransactions if we are *known* to be subxact + * * list of toplevel xacts (can be a as-yet unknown subxact) + * * list of preallocated ReorderBufferTXNs + * --- + */ + dlist_node node; + +} ReorderBufferTXN; + +/* so we can define the callbacks used inside struct ReorderBuffer itself */ +typedef struct ReorderBuffer ReorderBuffer; + +/* change callback signature */ +typedef void (*ReorderBufferApplyChangeCB)( + ReorderBuffer* rb, ReorderBufferTXN* txn, Relation relation, ReorderBufferChange* change); + +/* begin callback signature */ +typedef void (*ReorderBufferBeginCB)(ReorderBuffer* rb, ReorderBufferTXN* txn); + +/* commit callback signature */ +typedef void (*ReorderBufferCommitCB)(ReorderBuffer* rb, ReorderBufferTXN* txn, XLogRecPtr commit_lsn); + +struct ReorderBuffer { + /* + * xid => ReorderBufferTXN lookup table + */ + HTAB* by_txn; + + /* + * Transactions that could be a toplevel xact, ordered by LSN of the first + * record bearing that xid.. + */ + dlist_head toplevel_by_lsn; + + /* + * Transactions and subtransactions that have a base snapshot, ordered by + * LSN of the record which caused us to first obtain the base snapshot. + * This is not the same as toplevel_by_lsn, because we only set the base + * snapshot on the first logical-decoding-relevant record (eg. heap + * writes), whereas the initial LSN could be set by other operations. + */ + dlist_head txns_by_base_snapshot_lsn; + + /* + * one-entry sized cache for by_txn. Very frequently the same txn gets + * looked up over and over again. + */ + TransactionId by_txn_last_xid; + ReorderBufferTXN* by_txn_last_txn; + + /* + * Callacks to be called when a transactions commits. + */ + ReorderBufferBeginCB begin; + ReorderBufferApplyChangeCB apply_change; + ReorderBufferCommitCB commit; + + /* + * Pointer that will be passed untouched to the callbacks. + */ + void* private_data; + + /* + * Private memory context. + */ + MemoryContext context; + + /* + * Data structure slab cache. + * + * We allocate/deallocate some structures very frequently, to avoid bigger + * overhead we cache some unused ones here. + * + * The maximum number of cached entries is controlled by const variables + * ontop of reorderbuffer.c + */ + + /* cached ReorderBufferTXNs */ + dlist_head cached_transactions; + Size nr_cached_transactions; + + /* cached ReorderBufferChanges */ + dlist_head cached_changes; + Size nr_cached_changes; + + /* cached ReorderBufferTupleBufs */ + slist_head cached_tuplebufs; + Size nr_cached_tuplebufs; + + XLogRecPtr current_restart_decoding_lsn; + + /* buffer for disk<->memory conversions */ + char* outbuf; + Size outbufsize; +}; + +ReorderBuffer* ReorderBufferAllocate(void); +void ReorderBufferFree(ReorderBuffer*); + +ReorderBufferTupleBuf* ReorderBufferGetTupleBuf(ReorderBuffer*, Size tuple_len); +void ReorderBufferReturnTupleBuf(ReorderBuffer*, ReorderBufferTupleBuf* tuple); +ReorderBufferChange* ReorderBufferGetChange(ReorderBuffer*); +void ReorderBufferReturnChange(ReorderBuffer*, ReorderBufferChange*); + +void ReorderBufferQueueChange(ReorderBuffer*, TransactionId, XLogRecPtr lsn, ReorderBufferChange*); +void ReorderBufferCommit(ReorderBuffer*, TransactionId, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, + RepOriginId origin_id, CommitSeqNo csn, TimestampTz commit_time); +void ReorderBufferAssignChild(ReorderBuffer*, TransactionId, TransactionId, XLogRecPtr commit_lsn); +void ReorderBufferCommitChild(ReorderBuffer*, TransactionId, TransactionId, XLogRecPtr commit_lsn, XLogRecPtr end_lsn); +void ReorderBufferAbort(ReorderBuffer*, TransactionId, XLogRecPtr lsn); +void ReorderBufferAbortOld(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +void ReorderBufferForget(ReorderBuffer*, TransactionId, XLogRecPtr lsn); + +void ReorderBufferSetBaseSnapshot(ReorderBuffer*, TransactionId, XLogRecPtr lsn, struct SnapshotData* snap); +void ReorderBufferAddSnapshot(ReorderBuffer*, TransactionId, XLogRecPtr lsn, struct SnapshotData* snap); +void ReorderBufferAddNewCommandId(ReorderBuffer*, TransactionId, XLogRecPtr lsn, CommandId cid); +void ReorderBufferAddNewTupleCids(ReorderBuffer*, TransactionId, XLogRecPtr lsn, const RelFileNode& node, + const ItemPointerData& pt, CommandId cmin, CommandId cmax, CommandId combocid); +void ReorderBufferAddInvalidations( + ReorderBuffer*, TransactionId, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage* msgs); +TransactionId ReorderBufferGetOldestXmin(ReorderBuffer* rb); + +void ReorderBufferProcessXid(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +void ReorderBufferXidSetCatalogChanges(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +bool ReorderBufferXidHasCatalogChanges(ReorderBuffer*, TransactionId xid); +bool ReorderBufferXidHasBaseSnapshot(ReorderBuffer*, TransactionId xid); + +ReorderBufferTXN* ReorderBufferGetOldestTXN(ReorderBuffer*); + +void ReorderBufferSetRestartPoint(ReorderBuffer*, XLogRecPtr ptr); + +void StartupReorderBuffer(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/replication/repl_gram.hpp postgresql-hll-2.14/include/include/replication/repl_gram.hpp --- postgresql-hll-2.14_old/include/include/replication/repl_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/repl_gram.hpp 2020-12-12 17:06:43.259348193 +0800 @@ -0,0 +1,132 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED +# define YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int replication_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + SCONST = 258, + IDENT = 259, + RECPTR = 260, + ICONST = 261, + K_BASE_BACKUP = 262, + K_IDENTIFY_SYSTEM = 263, + K_IDENTIFY_VERSION = 264, + K_IDENTIFY_MODE = 265, + K_IDENTIFY_MAXLSN = 266, + K_IDENTIFY_CONSISTENCE = 267, + K_IDENTIFY_CHANNEL = 268, + K_IDENTIFY_AZ = 269, + K_LABEL = 270, + K_PROGRESS = 271, + K_FAST = 272, + K_NOWAIT = 273, + K_WAL = 274, + K_TABLESPACE_MAP = 275, + K_DATA = 276, + K_START_REPLICATION = 277, + K_FETCH_MOT_CHECKPOINT = 278, + K_CREATE_REPLICATION_SLOT = 279, + K_DROP_REPLICATION_SLOT = 280, + K_PHYSICAL = 281, + K_LOGICAL = 282, + K_SLOT = 283 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 60 "repl_gram.y" + + replication_scanner_YYSTYPE yy_core; + char *str; + bool boolval; + int ival; + + XLogRecPtr recptr; + Node *node; + List *list; + DefElem *defelt; + + +/* Line 2058 of yacc.c */ +#line 98 "repl_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int replication_yyparse (void *YYPARSE_PARAM); +#else +int replication_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int replication_yyparse (replication_scanner_yyscan_t yyscanner); +#else +int replication_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/include/replication/repl_gramparse.h postgresql-hll-2.14/include/include/replication/repl_gramparse.h --- postgresql-hll-2.14_old/include/include/replication/repl_gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/repl_gramparse.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,31 @@ +/* --------------------------------------------------------------------------------------- + * + * repl_gramparse.h + * Shared definitions for the "raw" syncrep_parser (flex and bison phases only) + * + * NOTE: this file is only meant to be includedd in the core parsing files. + * copy from parser/gramparse.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/replication/repl_gramparse.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPL_GRAMPARSE_H +#define _REPL_GRAMPARSE_H + +#include "repl.h" +#include "repl_gram.hpp" + +extern int replication_yyparse(replication_scanner_yyscan_t yyscanner); +extern int replication_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, replication_scanner_yyscan_t yyscanner); +extern void replication_yyerror(YYLTYPE* yylloc, replication_scanner_yyscan_t yyscanner, const char* msg); +extern replication_scanner_yyscan_t replication_scanner_init(const char* query_string); +extern void replication_scanner_finish(replication_scanner_yyscan_t yyscanner); +extern void replication_scanner_yyerror(const char* message, replication_scanner_yyscan_t yyscanner); + +#endif /* _SYNCREP_GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/repl.h postgresql-hll-2.14/include/include/replication/repl.h --- postgresql-hll-2.14_old/include/include/replication/repl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/repl.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,37 @@ +/* --------------------------------------------------------------------------------------- + * + * repl.h + * MPPDB High Available internal declarations + * + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/repl.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPL_H +#define _REPL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlogdefs.h" + +typedef void* replication_scanner_yyscan_t; + +typedef union replication_scanner_YYSTYPE { + char* str; + bool boolval; + int ival; + XLogRecPtr recptr; + Node* node; + List* list; + DefElem* defelt; +} replication_scanner_YYSTYPE; + +extern int replication_scanner_yylex( + replication_scanner_YYSTYPE* lvalp, YYLTYPE* llocp, replication_scanner_yyscan_t yyscanner); +extern void replication_scanner_yyerror(const char* message, replication_scanner_yyscan_t yyscanner); + +#endif /* _REPLICA_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/replicainternal.h postgresql-hll-2.14/include/include/replication/replicainternal.h --- postgresql-hll-2.14_old/include/include/replication/replicainternal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/replicainternal.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,151 @@ +/* --------------------------------------------------------------------------------------- + * + * replicainternal.h + * MPPDB High Available internal declarations + * + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/replicainternal.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPLICA_INTERNAL_H +#define _REPLICA_INTERNAL_H + +#ifdef EXEC_BACKEND +#include "storage/spin.h" +#endif + +#define IP_LEN 64 +#define PG_PROTOCOL_VERSION "MPPDB" + +/* Notice: the value is same sa GUC_MAX_REPLNODE_NUM */ +#ifdef ENABLE_MULTIPLE_NODES +#define MAX_REPLNODE_NUM 8 +#else +#define MAX_REPLNODE_NUM 9 +#endif + +#define REPL_IDX_PRIMARY 1 +#define REPL_IDX_STANDBY 2 + +typedef enum { NoDemote = 0, SmartDemote, FastDemote } DemoteMode; + +typedef enum { UNUSED_LISTEN_SOCKET = 0, PSQL_LISTEN_SOCKET, HA_LISTEN_SOCKET } ListenSocketType; + +typedef enum { + UNKNOWN_MODE = 0, + NORMAL_MODE, + PRIMARY_MODE, + STANDBY_MODE, + CASCADE_STANDBY_MODE, + PENDING_MODE +} ServerMode; + +typedef enum { + UNKNOWN_STATE = 0, + NORMAL_STATE, + NEEDREPAIR_STATE, + STARTING_STATE, + WAITING_STATE, + DEMOTING_STATE, + PROMOTING_STATE, + BUILDING_STATE, + CATCHUP_STATE, + COREDUMP_STATE +} DbState; + +typedef enum { + NONE_REBUILD = 0, + WALSEGMENT_REBUILD, + CONNECT_REBUILD, + TIMELINE_REBUILD, + SYSTEMID_REBUILD, + VERSION_REBUILD, + MODE_REBUILD +} HaRebuildReason; + +typedef enum { NONE_BUILD = 0, AUTO_BUILD, FULL_BUILD, INC_BUILD } BuildMode; + +typedef struct buildstate { + BuildMode build_mode; + uint64 total_done; + uint64 total_size; + int process_schedule; + int estimated_time; +} BuildState; + +typedef struct gaussstate { + ServerMode mode; + int conn_num; + DbState state; + bool sync_stat; + uint64 lsn; + uint64 term; + BuildState build_info; + HaRebuildReason ha_rebuild_reason; +} GaussState; + +#ifdef EXEC_BACKEND +/* + * Indicate one connect channel + */ +typedef struct replconninfo { + char localhost[IP_LEN]; + int localport; + int localservice; + int localheartbeatport; + char remotehost[IP_LEN]; + int remoteport; + int remoteservice; + int remoteheartbeatport; +} ReplConnInfo; + +/* + * HA share memory struct + */ +typedef struct hashmemdata { + ServerMode current_mode; + bool is_cascade_standby; + HaRebuildReason repl_reason[MAX_REPLNODE_NUM]; + int disconnect_count[MAX_REPLNODE_NUM]; + int current_repl; + int repl_list_num; + int loop_find_times; + slock_t mutex; +} HaShmemData; + +/* + * state of the node in the high availability cluster + * NOTES: NODESTATE_XXX_DEMOTE_REQUEST should equal to XXXDemote + */ +typedef enum ClusterNodeState { + NODESTATE_NORMAL = 0, + NODESTATE_SMART_DEMOTE_REQUEST, + NODESTATE_FAST_DEMOTE_REQUEST, + NODESTATE_STANDBY_WAITING, + NODESTATE_PRIMARY_DEMOTING, + NODESTATE_PROMOTE_APPROVE, + NODESTATE_STANDBY_REDIRECT, + NODESTATE_STANDBY_PROMOTING, + NODESTATE_STANDBY_FAILOVER_PROMOTING, + NODESTATE_PRIMARY_DEMOTING_WAIT_CATCHUP, + NODESTATE_DEMOTE_FAILED +} ClusterNodeState; +#endif + +/* + * Rec crc for wal's handshake + */ +typedef enum { + NONE_REC_CRC = 0, + IGNORE_REC_CRC +} PredefinedRecCrc; + +extern bool data_catchup; +extern bool wal_catchup; + +#endif /* _REPLICA_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/rto_statistic.h postgresql-hll-2.14/include/include/replication/rto_statistic.h --- postgresql-hll-2.14_old/include/include/replication/rto_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/rto_statistic.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,64 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rto_statistic.h + * + * + * + * IDENTIFICATION + * src/include/replication/rto_statistic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RTO_STATISTIC_H +#define RTO_STATISTIC_H + +#include "gs_thread.h" +#include "knl/knl_session.h" + +static const uint32 RTO_VIEW_NAME_SIZE = 32; +static const uint32 RTO_VIEW_COL_SIZE = 2; +static const uint32 MAX_WAL_SENDER = 100; +static const uint32 RTO_INFO_BUFFER_SIZE = 2048 * (1 + MAX_WAL_SENDER); +static const uint32 STANDBY_NAME_SIZE = 1024; +static const uint32 RECOVERY_RTO_VIEW_COL = 9; + +typedef Datum (*GetViewDataFunc)(); + +typedef struct RTOStatsViewObj { + char name[RTO_VIEW_NAME_SIZE]; + Oid data_type; + GetViewDataFunc get_data; +} RTOStatsViewObj; + +/* RTO statistics */ +typedef struct RTOStandbyData { + char id[STANDBY_NAME_SIZE]; + char source_ip[IP_LEN]; + char dest_ip[IP_LEN]; + int source_port; + int dest_port; + int64 current_rto; + int target_rto; + int64 current_sleep_time; +} RTOStandbyData; + +typedef struct knl_g_rto_context { + RTOStandbyData rto_standby_data[MAX_WAL_SENDER]; +} knl_g_rto_context; + +extern const RTOStatsViewObj g_rtoViewArr[RTO_VIEW_COL_SIZE]; +RTOStandbyData* GetRTOStat(uint32* num); +#endif /* RTO_STATISTIC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/replication/slot.h postgresql-hll-2.14/include/include/replication/slot.h --- postgresql-hll-2.14_old/include/include/replication/slot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/slot.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,257 @@ +/* --------------------------------------------------------------------------------------- + * + * slot.h + * Replication slot management. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * + * IDENTIFICATION + * src/include/replication/slot.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SLOT_H +#define SLOT_H + +#include "fmgr.h" +#include "access/xlog.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "storage/spin.h" +extern const uint32 EXTRA_SLOT_VERSION_NUM; + +/* + * Behaviour of replication slots, upon release or crash. + * + * Slots marked as PERSISTENT are crashsafe and will not be dropped when + * released. Slots marked as EPHEMERAL will be dropped when released or after + * restarts. BACKUP is basically similar to PERSISTENT, except that such slots are + * taken into consideration when computing restart_lsn or delay_ddl_lsn even if inactive. + * + * EPHEMERAL slots can be made PERSISTENT by calling ReplicationSlotPersist(). + */ +typedef enum ReplicationSlotPersistency { RS_PERSISTENT, RS_EPHEMERAL, RS_BACKUP } ReplicationSlotPersistency; + +/* + * On-Disk data of a replication slot, preserved across restarts. + */ + +typedef struct ReplicationSlotPersistentData { + /* The slot's identifier */ + NameData name; + + /* database the slot is active on */ + Oid database; + /* + * The slot's behaviour when being dropped (or restored after a crash). + */ + /* !!!!!!!!!!!!!!!!!!we steal two bytes from persistency for extra content length in new version */ + ReplicationSlotPersistency persistency; + bool isDummyStandby; + + /* + * xmin horizon for data + * + * NB: This may represent a value that hasn't been written to disk yet; + * see notes for effective_xmin, below. + */ + TransactionId xmin; + /* + * xmin horizon for catalog tuples + * + * NB: This may represent a value that hasn't been written to disk yet; + * see notes for effective_xmin, below. + */ + TransactionId catalog_xmin; + + /* oldest LSN that might be required by this replication slot */ + XLogRecPtr restart_lsn; + /* oldest LSN that the client has acked receipt for */ + XLogRecPtr confirmed_flush; + /* plugin name */ + NameData plugin; +} ReplicationSlotPersistentData; + +/* + * Replication slot on-disk data structure. + */ +typedef struct ReplicationSlotOnDisk { + /* first part of this struct needs to be version independent */ + + /* data not covered by checksum */ + uint32 magic; + pg_crc32c checksum; + + /* data covered by checksum */ + uint32 version; + uint32 length; + + ReplicationSlotPersistentData slotdata; +} ReplicationSlotOnDisk; + +typedef struct ObsArchiveConfig { + char *obs_address; + char *obs_bucket; + char *obs_ak; + char *obs_sk; +} ObsArchiveConfig; + +/* + * Shared memory state of a single replication slot. + */ +typedef struct ReplicationSlot { + /* lock, on same cacheline as effective_xmin */ + slock_t mutex; + + /* is this slot defined */ + bool in_use; + + /* is somebody streaming out changes for this slot */ + bool active; + + /* any outstanding modifications? */ + bool just_dirtied; + bool dirty; + + /* + * For logical decoding, it's extremely important that we never remove any + * data that's still needed for decoding purposes, even after a crash; + * otherwise, decoding will produce wrong answers. Ordinary streaming + * replication also needs to prevent old row versions from being removed + * too soon, but the worst consequence we might encounter there is unwanted + * query cancellations on the standby. Thus, for logical decoding, + * this value represents the latest xmin that has actually been + * written to disk, whereas for streaming replication, it's just the + * same as the persistent value (data.xmin). + */ + TransactionId effective_xmin; + TransactionId effective_catalog_xmin; + + /* data surviving shutdowns and crashes */ + ReplicationSlotPersistentData data; + + /* is somebody performing io on this slot? */ + LWLock *io_in_progress_lock; + + /* all the remaining data is only used for logical slots */ + + /* ---- + * When the client has confirmed flushes >= candidate_xmin_lsn we can + * advance the catalog xmin, when restart_valid has been passed, + * restart_lsn can be increased. + * ---- + */ + TransactionId candidate_catalog_xmin; + XLogRecPtr candidate_xmin_lsn; + XLogRecPtr candidate_restart_valid; + XLogRecPtr candidate_restart_lsn; + ObsArchiveConfig* archive_obs; + char* extra_content; +} ReplicationSlot; + + +#define ReplicationSlotPersistentDataConstSize sizeof(ReplicationSlotPersistentData) +/* size of the part of the slot that is version independent */ +#define ReplicationSlotOnDiskConstantSize offsetof(ReplicationSlotOnDisk, slotdata) +/* size of the slots that is not version indepenent */ +#define ReplicationSlotOnDiskDynamicSize sizeof(ReplicationSlotOnDisk) - ReplicationSlotOnDiskConstantSize +#define SLOT_MAGIC 0x1051CA1 /* format identifier */ +#define SLOT_VERSION 1 /* version for new files */ +#define SLOT_VERSION_TWO 2 /* version for new files */ + + +#define XLOG_SLOT_CREATE 0x00 +#define XLOG_SLOT_ADVANCE 0x10 +#define XLOG_SLOT_DROP 0x20 +#define XLOG_SLOT_CHECK 0x30 +#define XLOG_TERM_LOG 0x40 +#define INT32_HIGH_MASK 0xFF00 +#define INT32_LOW_MASK 0x00FF + +/* we steal two bytes from persistency for updagrade */ +#define GET_SLOT_EXTRA_DATA_LENGTH(data) (((int)((data).persistency)) >> 16) +#define SET_SLOT_EXTRA_DATA_LENGTH(data, length) ((data).persistency = (ReplicationSlotPersistency)((int)(((data).persistency) & INT32_LOW_MASK) | ((length) << 16))) +#define GET_SLOT_PERSISTENCY(data) (ReplicationSlotPersistency(int16((data).persistency))) +#define SET_SLOT_PERSISTENCY(data, mypersistency) ((data).persistency = (ReplicationSlotPersistency)((int)(((data).persistency) & INT32_HIGH_MASK) | (int16(mypersistency)))) +/* + * Shared memory control area for all of replication slots. + */ +typedef struct ReplicationSlotCtlData { + ReplicationSlot replication_slots[1]; +} ReplicationSlotCtlData; +/* + * ret for computing all of replication slots. + */ +typedef struct ReplicationSlotState { + XLogRecPtr min_required; + XLogRecPtr max_required; + bool exist_in_use; +} ReplicationSlotState; +/* + * Shared memory control area for all of replication slots. + */ +typedef struct LogicalPersistentData { + int SlotNum; + ReplicationSlotPersistentData replication_slots[FLEXIBLE_ARRAY_MEMBER]; +} LogicalPersistentData; + +/* shmem initialization functions */ +extern Size ReplicationSlotsShmemSize(void); +extern void ReplicationSlotsShmemInit(void); + +/* management of individual slots */ +extern void ReplicationSlotCreate(const char* name, ReplicationSlotPersistency persistency, bool isDummyStandby, + Oid databaseId, XLogRecPtr restart_lsn, char* extra_content = NULL); +extern void ReplicationSlotPersist(void); +extern void ReplicationSlotDrop(const char* name, bool for_backup = false); +extern void ReplicationSlotAcquire(const char* name, bool isDummyStandby); +bool ReplicationSlotFind(const char* name); +extern void ReplicationSlotRelease(void); +extern void ReplicationSlotSave(void); +extern void ReplicationSlotMarkDirty(void); +extern void CreateSlotOnDisk(ReplicationSlot* slot); + +/* misc stuff */ +extern bool ReplicationSlotValidateName(const char* name, int elevel); +extern void ValidateName(const char* name); +extern void ReplicationSlotsComputeRequiredXmin(bool already_locked); +extern void ReplicationSlotsComputeRequiredLSN(ReplicationSlotState* repl_slt_state); +extern XLogRecPtr ReplicationSlotsComputeConfirmedLSN(void); +extern void ReplicationSlotReportRestartLSN(void); +extern void StartupReplicationSlots(); +extern void CheckPointReplicationSlots(void); +extern void SetDummyStandbySlotLsnInvalid(void); +extern XLogRecPtr slot_advance_confirmed_lsn(const char *slotname, XLogRecPtr target_lsn); +extern bool slot_reset_confirmed_lsn(const char *slotname, XLogRecPtr *start_lsn); +extern void CheckSlotRequirements(void); + +/* SQL callable functions */ +extern Datum pg_get_replication_slots(PG_FUNCTION_ARGS); +extern void create_logical_replication_slot( + Name name, Name plugin, bool isDummyStandby, NameData* databaseName, char* str_tmp_lsn); +extern XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN(void); +extern bool ReplicationSlotsCountDBSlots(Oid dboid, int* nslots, int* nactive); +extern Datum pg_create_physical_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_create_physical_replication_slot_extern(PG_FUNCTION_ARGS); +extern Datum pg_create_logical_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_drop_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_get_replication_slot_name(PG_FUNCTION_ARGS); + +/* slot redo */ +extern void slot_redo(XLogReaderState* record); +extern void slot_desc(StringInfo buf, XLogReaderState* record); +extern void redo_slot_advance(const ReplicationSlotPersistentData* slotInfo); +extern void log_slot_advance(const ReplicationSlotPersistentData* slotInfo); +extern void log_slot_drop(const char* name); +extern void LogCheckSlot(); +extern Size GetAllLogicalSlot(LogicalPersistentData*& LogicalSlot); +extern char* get_my_slot_name(); +extern ObsArchiveConfig* formObsConfigFromStr(char *content, bool encrypted); +extern char *formObsConfigStringFromStruct(ObsArchiveConfig *obs_config); +extern bool is_archive_slot(ReplicationSlotPersistentData data); +extern void log_slot_create(const ReplicationSlotPersistentData *slotInfo, char* extra_content = NULL); +extern void redo_slot_reset_for_backup(const ReplicationSlotPersistentData *xlrec); + +#endif /* SLOT_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/snapbuild.h postgresql-hll-2.14/include/include/replication/snapbuild.h --- postgresql-hll-2.14_old/include/include/replication/snapbuild.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/snapbuild.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,84 @@ +/* --------------------------------------------------------------------------------------- + * + * snapbuild.h + * Exports from replication/logical/snapbuild.c. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/snapbuild.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SNAPBUILD_H +#define SNAPBUILD_H + +#include "access/xlogdefs.h" +#include "utils/snapmgr.h" + +typedef enum { + /* + * Initial state, we can't do much yet. + */ + SNAPBUILD_START = -1, + /* + * Collecting committed transactions, to build the initial catalog + * snapshot. + */ + SNAPBUILD_BUILDING_SNAPSHOT = 0, + + /* + * We have collected enough information to decode tuples in transactions + * that started after this. + * + * yet, because they might be based on transactions that were still running + * when FULL_SNAPSHOT was reached. + */ + SNAPBUILD_FULL_SNAPSHOT = 1, + + /* + * Found a point after SNAPBUILD_FULL_SNAPSHOT where all transactions that + * were running at that point finished. Till we reach that we hold off + * calling any commit callbacks. + */ + SNAPBUILD_CONSISTENT = 2 +} SnapBuildState; + +/* forward declare so we don't have to expose the struct to the public */ +struct SnapBuild; +typedef struct SnapBuild SnapBuild; + +/* forward declare so we don't have to include reorderbuffer.h */ +struct ReorderBuffer; + +/* forward declare so we don't have to include heapam_xlog.h */ +struct xl_heap_new_cid; +struct xl_running_xacts; + +extern void CheckPointSnapBuild(void); + +extern SnapBuild* AllocateSnapshotBuilder( + struct ReorderBuffer* cache, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot); +extern void FreeSnapshotBuilder(SnapBuild* cache); + +extern void SnapBuildSnapDecRefcount(Snapshot snap); + +extern const char* SnapBuildExportSnapshot(SnapBuild* snapstate); +extern void SnapBuildClearExportedSnapshot(void); + +extern SnapBuildState SnapBuildCurrentState(SnapBuild* snapstate); + +extern bool SnapBuildXactNeedsSkip(SnapBuild* snapstate, XLogRecPtr ptr); + +extern void SnapBuildCommitTxn( + SnapBuild* builder, XLogRecPtr lsn, TransactionId xid, int nsubxacts, TransactionId* subxacts); +extern bool SnapBuildProcessChange(SnapBuild* builder, TransactionId xid, XLogRecPtr lsn); +extern void SnapBuildProcessNewCid(SnapBuild* builder, TransactionId xid, XLogRecPtr lsn, + struct xl_heap_new_cid* cid, int bucket_id); +extern void SnapBuildProcessRunningXacts(SnapBuild* builder, XLogRecPtr lsn, struct xl_running_xacts* running); +extern void SnapBuildSerializationPoint(SnapBuild* builder, XLogRecPtr lsn); + +extern void SnapBuildSetInitXmin(SnapBuild* builder, TransactionId xmin); +extern void SnapBuildSetState(SnapBuild* builder, SnapBuildState s_state); +#endif /* SNAPBUILD_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/syncrep_gram.hpp postgresql-hll-2.14/include/include/replication/syncrep_gram.hpp --- postgresql-hll-2.14_old/include/include/replication/syncrep_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/syncrep_gram.hpp 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,106 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED +# define YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int syncrep_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + NAME = 258, + NUM = 259, + JUNK = 260, + ANY = 261, + FIRST = 262 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 60 "syncrep_gram.y" + + syncrep_scanner_YYSTYPE yy_core; + char *str; + List *list; + SyncRepConfigData *config; + + +/* Line 2058 of yacc.c */ +#line 72 "syncrep_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int syncrep_yyparse (void *YYPARSE_PARAM); +#else +int syncrep_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int syncrep_yyparse (syncrep_scanner_yyscan_t yyscanner); +#else +int syncrep_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/include/replication/syncrep_gramparse.h postgresql-hll-2.14/include/include/replication/syncrep_gramparse.h --- postgresql-hll-2.14_old/include/include/replication/syncrep_gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/syncrep_gramparse.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,29 @@ +/* --------------------------------------------------------------------------------------- + * + * syncrep_gramparse.h + * Shared definitions for the "raw" syncrep_parser (flex and bison phases only) + * + * NOTE: this file is only meant to be includedd in the core parsing files. + * copy from parser/gramparse.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/replication/syncrep_gramparse.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _SYNCREP_GRAMPARSE_H +#define _SYNCREP_GRAMPARSE_H + +#include "syncrep.h" +#include "syncrep_gram.hpp" + +extern int syncrep_yyparse(syncrep_scanner_yyscan_t yyscanner); +extern int syncrep_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, syncrep_scanner_yyscan_t yyscanner); +extern syncrep_scanner_yyscan_t syncrep_scanner_init(const char* query_string); +extern void syncrep_scanner_finish(syncrep_scanner_yyscan_t yyscanner); + +#endif /* _SYNCREP_GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/syncrep.h postgresql-hll-2.14/include/include/replication/syncrep.h --- postgresql-hll-2.14_old/include/include/replication/syncrep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/syncrep.h 2020-12-12 17:06:43.260348206 +0800 @@ -0,0 +1,103 @@ +/* ------------------------------------------------------------------------- + * + * syncrep.h + * Exports from replication/syncrep.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/syncrep.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _SYNCREP_H +#define _SYNCREP_H + +#include "access/xlogdefs.h" +#include "utils/guc.h" +#include "replication/replicainternal.h" + +#define SyncRepRequested() \ + (g_instance.attr.attr_storage.max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH) + +/* SyncRepWaitMode */ +#define SYNC_REP_NO_WAIT -1 +#define SYNC_REP_WAIT_RECEIVE 0 +#define SYNC_REP_WAIT_WRITE 1 +#define SYNC_REP_WAIT_FLUSH 2 +#define SYNC_REP_WAIT_APPLY 3 + +#define NUM_SYNC_REP_WAIT_MODE 4 + +/* syncRepState */ +#define SYNC_REP_NOT_WAITING 0 +#define SYNC_REP_WAITING 1 +#define SYNC_REP_WAIT_COMPLETE 2 + +/* syncrep_method of SyncRepConfigData */ +#define SYNC_REP_PRIORITY 0 +#define SYNC_REP_QUORUM 1 + +extern volatile bool most_available_sync; + +#define SyncStandbysDefined() \ + (u_sess->attr.attr_storage.SyncRepStandbyNames != NULL && u_sess->attr.attr_storage.SyncRepStandbyNames[0] != '\0') + +/* + * Struct for the configuration of synchronous replication. + * + * Note: this must be a flat representation that can be held in a single + * chunk of malloc'd memory, so that it can be stored as the "extra" data + * for the synchronous_standby_names GUC. + */ +typedef struct SyncRepConfigData { + int config_size; /* total size of this struct, in bytes */ + int num_sync; /* number of sync standbys that we need to wait for */ + uint8 syncrep_method; /* method to choose sync standbys */ + int nmembers; /* number of members in the following list */ + /* member_names contains nmembers consecutive nul-terminated C strings */ + char member_names[FLEXIBLE_ARRAY_MEMBER]; +} SyncRepConfigData; + +/* called by user backend */ +extern void SyncRepWaitForLSN(XLogRecPtr XactCommitLSN); + +/* called at backend exit */ +extern void SyncRepCleanupAtProcExit(void); + +/* called by wal sender */ +extern void SyncRepInitConfig(void); +extern void SyncRepReleaseWaiters(void); + +/* called by wal writer */ +extern void SyncRepUpdateSyncStandbysDefined(void); + +/* called by wal sender, check if any synchronous standby is alive */ +extern void SyncRepCheckSyncStandbyAlive(void); + +/* called by wal sender and user backend */ +extern List* SyncRepGetSyncStandbys(bool* am_sync, List** catchup_standbys = NULL); + +extern bool check_synchronous_standby_names(char** newval, void** extra, GucSource source); +extern void assign_synchronous_standby_names(const char* newval, void* extra); +extern void assign_synchronous_commit(int newval, void* extra); + +/* + * Internal functions for parsing synchronous_standby_names grammar, + * in syncrep_gram.y and syncrep_scanner.l + */ +#define YYLTYPE int +typedef void* syncrep_scanner_yyscan_t; + +typedef union syncrep_scanner_YYSTYPE { + char* str; + List* list; + SyncRepConfigData* config; +} syncrep_scanner_YYSTYPE; + +extern int syncrep_scanner_yylex(syncrep_scanner_YYSTYPE* lvalp, YYLTYPE* llocp, syncrep_scanner_yyscan_t yyscanner); +extern void syncrep_scanner_yyerror(const char* message, syncrep_scanner_yyscan_t yyscanner); +extern bool SyncRepGetSyncRecPtr(XLogRecPtr* receivePtr, XLogRecPtr* writePtr, XLogRecPtr* flushPtr, XLogRecPtr* replayPtr, bool* am_sync, bool check_am_sync = true); + + +#endif /* _SYNCREP_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/walprotocol.h postgresql-hll-2.14/include/include/replication/walprotocol.h --- postgresql-hll-2.14_old/include/include/replication/walprotocol.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/walprotocol.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * walprotocol.h + * Definitions relevant to the streaming WAL transmission protocol. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walprotocol.h + * + * We tried to expand the traditional WAL protocol to transfer the separated replication data with + * the specified #ref_xlog which could benefit from both the xlog synchronization and the I/O reducing. + * ------------------------------------------------------------------------- + */ +#ifndef _WALPROTOCOL_H +#define _WALPROTOCOL_H + +#include "access/xlogdefs.h" +#include "datatype/timestamp.h" +#include "replication/replicainternal.h" + +/* + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct ConfigModifyTimeMessage { + time_t config_modify_time; +} ConfigModifyTimeMessage; + +/* + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct { + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + ServerMode peer_role; + DbState peer_state; + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; + bool catchup; +} WalSndrMessage; + +/* + * Refence :PrimaryKeepaliveMessage + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct RmXLogMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} RmXLogMessage; + +/* + * Refence :PrimaryKeepaliveMessage + */ +typedef struct EndXLogMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + int percent; +} EndXLogMessage; + +/* + * Header for a WAL data message (message type 'w'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual WAL data. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* WAL start location of the data included in this message */ + XLogRecPtr dataStart; + + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + + bool catchup; +} WalDataMessageHeader; + +/* + * Header for a data replication message (message type 'd'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual data page. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* the corresponding data_start_ptr and data_end_ptr */ + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} WalDataPageMessageHeader; + +/* + * Keepalive message from primary (message type 'k'). (lowercase k) + * This is wrapped within a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef WalSndrMessage PrimaryKeepaliveMessage; + +/* + * switchover response + */ +typedef enum { + SWITCHOVER_NONE = 0, + SWITCHOVER_PROMOTE_REQUEST, + SWITCHOVER_DEMOTE_FAILED, + SWITCHOVER_DEMOTE_CATCHUP_EXIST +} SwitchResponseCode; + +/* + * switchover response message from primary (message type 'p'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct { + int switchResponse; + + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} PrimarySwitchResponseMessage; + +/* + * Reply message from standby (message type 'r'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyReplyMessage { + /* + * The xlog locations that have been received, written, flushed, and applied by + * standby-side. These may be invalid if the standby-side is unable to or + * chooses not to report these. + */ + XLogRecPtr receive; + XLogRecPtr write; + XLogRecPtr flush; + XLogRecPtr apply; + XLogRecPtr applyRead; + + /* local role on walreceiver, they will be sent to walsender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the server should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} StandbyReplyMessage; + +/* + * Hot Standby feedback from standby (message type 'h'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyHSFeedbackMessage { + /* + * The current xmin and epoch from the standby, for Hot Standby feedback. + * This may be invalid if the standby-side does not support feedback, or + * Hot Standby is not yet available. + */ + TransactionId xmin; + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} StandbyHSFeedbackMessage; + +/* + * @@GaussDB@@ + * switchover request message from standby (message type 's'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbySwitchRequestMessage { + /* primary demote mode */ + int demoteMode; + + /* receiver's system clock at the time of transmission */ + TimestampTz sendTime; +} StandbySwitchRequestMessage; + +/* + * Maximum data payload in a WAL data message. Must be >= XLOG_BLCKSZ. + * + * We don't have a good idea of what a good value would be; there's some + * overhead per message in both walsender and walreceiver, but on the other + * hand sending large batches makes walsender less responsive to signals + * because signals are checked only between messages. 128kB (with + * default 8k blocks) seems like a reasonable guess for now. + */ +#define MAX_SEND_SIZE (XLOG_BLCKSZ * 16) + +#endif /* _WALPROTOCOL_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/walreceiver.h postgresql-hll-2.14/include/include/replication/walreceiver.h --- postgresql-hll-2.14_old/include/include/replication/walreceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/walreceiver.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,263 @@ +/* ------------------------------------------------------------------------- + * + * walreceiver.h + * Exports from replication/walreceiverfuncs.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walreceiver.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALRECEIVER_H +#define _WALRECEIVER_H + +#include "access/xlog.h" +#include "access/xlogdefs.h" +#include "lib/stringinfo.h" +#include "fmgr.h" +#include "pgtime.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "replication/dataqueuedefs.h" +#include "replication/replicainternal.h" +#include "storage/latch.h" +#include "storage/spin.h" + +/* + * MAXCONNINFO: maximum size of a connection string. + * + * XXX: Should this move to pg_config_manual.h? + */ +#define MAXCONNINFO 1024 +#define HIGHEST_PERCENT 100 +#define STREAMING_START_PERCENT 90 + +#define DUMMY_STANDBY_DATADIR "base/dummy_standby" + +/* Can we allow the standby to accept replication connection from another standby? */ +#define AllowCascadeReplication() \ + (g_instance.attr.attr_storage.EnableHotStandby && g_instance.attr.attr_storage.max_wal_senders > 0) + +#define SETXLOGLOCATION(a, b) \ + do { \ + a = b; \ + } while (0); + +/* + * Values for WalRcv->walRcvState. + */ +typedef enum { + WALRCV_STOPPED, /* stopped and mustn't start up again */ + WALRCV_STARTING, /* launched, but the process hasn't initialized yet */ + WALRCV_RUNNING, /* walreceiver is running */ + WALRCV_STOPPING /* requested to stop, but still running */ +} WalRcvState; + +/* + * @@GaussDB@@ + * Brief : Indicate the connect error of server try to connect the primary. + * Description : NONE_ERROR (first try to connect the primary) + * CHANNEL_ERROR (server should try next channel) + * REPL_INFO_ERROR (server should try next replconnlist) + */ +typedef enum { NONE_ERROR, CHANNEL_ERROR, REPL_INFO_ERROR } WalRcvConnError; + +typedef struct WalRcvCtlBlock { + XLogRecPtr receivePtr; /* last byte + 1 received in the standby. */ + XLogRecPtr writePtr; /* last byte + 1 written out in the standby */ + XLogRecPtr flushPtr; /* last byte + 1 flushed in the standby */ + XLogRecPtr walStart; + XLogRecPtr lastReadPtr; + int64 walWriteOffset; + int64 walFreeOffset; + int64 walReadOffset; + bool walIsWriting; + slock_t mutex; + + char walReceiverBuffer[FLEXIBLE_ARRAY_MEMBER]; +} WalRcvCtlBlock; + +typedef enum { REPCONNTARGET_DEFAULT, REPCONNTARGET_PRIMARY, REPCONNTARGET_DUMMYSTANDBY, REPCONNTARGET_STANDBY } ReplConnTarget; + +/* Shared memory area for management of walreceiver process */ +typedef struct WalRcvData { + /* + * PID of currently active walreceiver process, its current state and + * start time (actually, the time at which it was requested to be + * started). + */ + ThreadId pid; + ThreadId writerPid; + int lwpId; + WalRcvState walRcvState; + ClusterNodeState node_state; /* state of the node in the cluster */ + pg_time_t startTime; + + ServerMode peer_role; + bool isRuning; + /*walsender and walreceiver xlog locations*/ + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + + DbState peer_state; + + /* + * receiveStart is the first byte position that will be received. When + * startup process starts the walreceiver, it sets receiveStart to the + * point where it wants the streaming to begin. + */ + XLogRecPtr receiveStart; + + /* + * receivedUpto-1 is the last byte position that has already been + * received. At the first startup of walreceiver, receivedUpto is set to + * receiveStart. After that, walreceiver updates this whenever it flushes + * the received WAL to disk. + */ + XLogRecPtr receivedUpto; + + /* + * The xlog locations is used for counting sync percentage in function GetSyncPercent. + */ + XLogRecPtr syncPercentCountStart; + + /* + * latestChunkStart is the starting byte position of the current "batch" + * of received WAL. It's actually the same as the previous value of + * receivedUpto before the last flush to disk. Startup process can use + * this to detect whether it's keeping up or not. + */ + XLogRecPtr latestChunkStart; + + /* + * position and crc of the latest valid WAL record on the receiver. + */ + XLogRecPtr latestValidRecord; + pg_crc32 latestRecordCrc; + + /* + * Time of send and receive of any message received. + */ + TimestampTz lastMsgSendTime; + TimestampTz lastMsgReceiptTime; + + /* + * Latest reported end of WAL on the sender + */ + XLogRecPtr latestWalEnd; + TimestampTz latestWalEndTime; + + /* recvwriter write queue position (local queue) */ + DataQueuePtr local_write_pos; + + int dummyStandbySyncPercent; + /* Flag if failed to connect to dummy when failover */ + bool dummyStandbyConnectFailed; + + /* + * connection string; is used for walreceiver to connect with the primary. + */ + char conninfo[MAXCONNINFO]; + int ntries; + + /* + * replication slot name; is also used for walreceiver to connect with + * the primary + */ + char slotname[NAMEDATALEN]; + + WalRcvConnError conn_errno; + ReplConnInfo conn_channel; + ReplConnTarget conn_target; + + Latch* walrcvWriterLatch; + WalRcvCtlBlock* walRcvCtlBlock; + + slock_t mutex; /* locks shared variables shown above */ + slock_t exitLock; +} WalRcvData; + +extern XLogRecPtr latestValidRecord; +extern pg_crc32 latestRecordCrc; + +extern const char *g_reserve_param[RESERVE_SIZE]; +extern bool ws_dummy_data_writer_use_file; +extern THR_LOCAL uint32 ws_dummy_data_read_file_num; + +/* prototypes for functions in walreceiver.c */ +extern void WalReceiverMain(void); +extern void walrcvWriterMain(void); + +/* prototypes for functions in walrcvwriter.cpp */ +extern int WalDataRcvWrite(void); + +extern void WSDataRcvCheck(char* data_buf, Size nbytes); + +/* prototypes for functions in walreceiverfuncs.c */ +extern Size WalRcvShmemSize(void); +extern void WalRcvShmemInit(void); +extern void ShutdownWalRcv(void); +extern bool WalRcvInProgress(void); +extern void connect_dn_str(char* conninfo, int replIndex); +extern void RequestXLogStreaming( + XLogRecPtr* recptr, const char* conninfo, ReplConnTarget conn_target, const char* slotname); +extern StringInfo get_rcv_slot_name(void); +extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr* latestChunkStart); +extern XLogRecPtr GetWalStartPtr(); +extern bool WalRcvAllReplayIsDone(); +extern bool WalRcvIsDone(); +extern int GetReplicationApplyDelay(void); +extern int GetReplicationTransferLatency(void); +extern int GetWalRcvDummyStandbySyncPercent(void); +extern void SetWalRcvDummyStandbySyncPercent(int percent); +extern void CloseWSDataFileOnDummyStandby(void); +extern void InitWSDataNumOnDummyStandby(void); + +extern WalRcvCtlBlock* getCurrentWalRcvCtlBlock(void); +extern int walRcvWrite(WalRcvCtlBlock* walrcb); +extern int WSWalRcvWrite(WalRcvCtlBlock* walrcb, char* buf, Size nbytes, XLogRecPtr start_ptr); +extern void WalRcvXLogClose(void); +extern bool WalRcvIsShutdown(void); + +extern void ProcessWSRmXLog(void); +extern void ProcessWSRmData(void); +extern void SetWalRcvWriterPID(ThreadId tid); +extern bool WalRcvWriterInProgress(void); +extern bool walRcvCtlBlockIsEmpty(void); +extern void ProcessWalRcvInterrupts(void); +extern ReplConnInfo* GetRepConnArray(int* cur_idx); +extern void XLogWalRcvSendReply(bool force, bool requestReply); +extern int GetSyncPercent(XLogRecPtr startLsn, XLogRecPtr maxLsn, XLogRecPtr nowLsn); +extern const char* wal_get_role_string(ServerMode mode, bool getPeerRole = false); +extern const char* wal_get_rebuild_reason_string(HaRebuildReason reason); +extern Datum pg_stat_get_stream_replications(PG_FUNCTION_ARGS); +extern void GetPrimaryServiceAddress(char* address, size_t address_len); +extern void MakeDebugLog(TimestampTz sendTime, TimestampTz lastMsgReceiptTime, const char* msgFmt); +extern void WalRcvSetPercentCountStartLsn(XLogRecPtr startLsn); +extern void clean_failover_host_conninfo_for_dummy(void); +extern void set_failover_host_conninfo_for_dummy(const char *remote_host, int remote_port); +extern void get_failover_host_conninfo_for_dummy(int *repl); +extern void set_wal_rcv_write_rec_ptr(XLogRecPtr rec_ptr); + + +static inline void WalRcvCtlAcquireExitLock(void) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile WalRcvData *walrcv = t_thrd.walreceiverfuncs_cxt.WalRcv; + SpinLockAcquire(&walrcv->exitLock); +} + +static inline void WalRcvCtlReleaseExitLock(void) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile WalRcvData *walrcv = t_thrd.walreceiverfuncs_cxt.WalRcv; + SpinLockRelease(&walrcv->exitLock); +} +#endif /* _WALRECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/walsender.h postgresql-hll-2.14/include/include/replication/walsender.h --- postgresql-hll-2.14_old/include/include/replication/walsender.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/walsender.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,88 @@ +/* ------------------------------------------------------------------------- + * + * walsender.h + * Exports from replication/walsender.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walsender.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALSENDER_H +#define _WALSENDER_H + +#include + +#include "fmgr.h" +#include "alarm/alarm.h" +#include "replication/replicainternal.h" +#include "utils/tuplestore.h" + +#define WS_MAX_SEND_SIZE (uint32)(g_instance.attr.attr_storage.MaxSendSize * 1024) +#define WS_CU_SEND_SLICE_SIZE (512 * 1024) +#define WS_XLOG_HDR_SIZE (sizeof(uint32) + 1 + sizeof(XLogRecPtr)) +#define WS_DATA_HDR_SIZE sizeof(DataElementHeaderData) +#define WS_DATA_MSG_HDR_SIZE sizeof(WalDataPageMessageHeader) +#define WS_DATA_MSG_PREFIX_LEN (sizeof(uint32) + 1 + sizeof(XLogRecPtr) * 2) +#define AM_WAL_NORMAL_SENDER (t_thrd.role == WAL_NORMAL_SENDER) +#define AM_WAL_STANDBY_SENDER (t_thrd.role == WAL_STANDBY_SENDER) +#define AM_WAL_DB_SENDER (t_thrd.role == WAL_DB_SENDER) +#define AM_WAL_SENDER (AM_WAL_NORMAL_SENDER || AM_WAL_STANDBY_SENDER || AM_WAL_DB_SENDER) + +typedef struct WSXLogJustSendRegion { + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; +} WSXLogJustSendRegion; + +extern int WalSenderMain(void); +extern void GetPMstateAndRecoveryInProgress(void); +extern void WalSndSignals(void); +extern Size WalSndShmemSize(void); +extern void WalSndShmemInit(void); +extern void WalSndWakeup(void); +extern void WalSndRqstFileReload(void); +extern bool WalSndInProgress(int type); +extern void StandbyOrSecondaryIsAlive(void); +extern void StopAliveBuildSender(void); +extern bool IsAllBuildSenderExit(); + +extern bool WalSegmemtRemovedhappened; +extern AlarmCheckResult WalSegmentsRemovedChecker(Alarm* alarm, AlarmAdditionalParam* additionalParam); +extern Datum pg_stat_get_wal_senders(PG_FUNCTION_ARGS); +extern Tuplestorestate* BuildTupleResult(FunctionCallInfo fcinfo, TupleDesc* tupdesc); + +extern void GetFastestReplayStandByServiceAddress( + char* fastest_remote_address, char* second_fastest_remote_address, size_t address_len); +extern bool IsPrimaryStandByReadyToRemoteRead(void); +extern void IdentifyMode(void); +extern bool WalSndAllInProgress(int type); +extern bool WalSndQuorumInProgress(int type); +extern XLogSegNo WalGetSyncCountWindow(void); + +/* + * Remember that we want to wakeup walsenders later + * + * This is separated from doing the actual wakeup because the writeout is done + * while holding contended locks. + */ +#define WalSndWakeupRequest() \ + do { \ + t_thrd.walsender_cxt.wake_wal_senders = true; \ + } while (0) + +/* + * wakeup walsenders if there is work to be done + */ +#define WalSndWakeupProcessRequests() \ + do { \ + if (t_thrd.walsender_cxt.wake_wal_senders) { \ + t_thrd.walsender_cxt.wake_wal_senders = false; \ + if (g_instance.attr.attr_storage.max_wal_senders > 0) \ + WalSndWakeup(); \ + } \ + } while (0) + +#define MAX_XLOG_RECORD(a, b) ((XLByteLT((a), (b))) ? (b) : (a)) + +#endif /* _WALSENDER_H */ diff -uprN postgresql-hll-2.14_old/include/include/replication/walsender_private.h postgresql-hll-2.14/include/include/replication/walsender_private.h --- postgresql-hll-2.14_old/include/include/replication/walsender_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/replication/walsender_private.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,172 @@ +/* ------------------------------------------------------------------------- + * + * walsender_private.h + * Private definitions from replication/walsender.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walsender_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALSENDER_PRIVATE_H +#define _WALSENDER_PRIVATE_H + +#include "access/xlog.h" +#include "nodes/nodes.h" +#include "replication/replicainternal.h" +#include "replication/syncrep.h" +#include "replication/repl_gramparse.h" +#include "storage/latch.h" +#include "storage/shmem.h" +#include "storage/spin.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +typedef enum WalSndState { + WALSNDSTATE_STARTUP = 0, + WALSNDSTATE_BACKUP, + WALSNDSTATE_CATCHUP, + WALSNDSTATE_STREAMING +} WalSndState; + +typedef enum SndRole { + SNDROLE_PRIMARY_STANDBY = 1, /* primary to standby */ + SNDROLE_PRIMARY_BUILDSTANDBY = 2, /* primary to gs_ctl when run build command */ + SNDROLE_PRIMARY_DUMMYSTANDBY = 4, /* primary to dummy standby */ + SNDROLE_DUMMYSTANDBY_STANDBY = 8 /* dummy standby to standby */ +} SndRole; + +typedef struct WSXLogPageReadPrivate { + TimeLineID tli; + XLogSegNo xlogreadlogsegno; + int xlogreadfd; +} WSXLogPageReadPrivate; + +/* For log ctrl. Willing let standby flush and apply log under RTO seconds */ +typedef struct LogCtrlData { + int64 sleep_time; + int64 balance_sleep_time; + int64 prev_RTO; + int64 current_RTO; + uint64 sleep_count; + int64 sleep_count_limit; + XLogRecPtr prev_flush; + XLogRecPtr prev_apply; + TimestampTz prev_reply_time; + uint64 pre_rate1; + uint64 pre_rate2; +} LogCtrlData; + +/* + * Each walsender has a WalSnd struct in shared memory. + */ +typedef struct WalSnd { + ThreadId pid; /* this walsender's process id, or 0 */ + int lwpId; + WalSndState state; /* this walsender's state */ + TimestampTz catchupTime[2]; /* time stamp of this walsender's catchup */ + ClusterNodeState node_state; /* state of the node in the cluster */ + SndRole sendRole; /* role of sender */ + XLogRecPtr sentPtr; /* WAL has been sent up to this point */ + bool needreload; /* does currently-open file need to be + * reloaded? */ + bool sendKeepalive; /* do we send keepalives on this connection? */ + bool replSender; /* is the walsender a normal replication or building */ + + ServerMode peer_role; + DbState peer_state; + /* + * The xlog locations that have been received, written, flushed, and applied by + * standby-side. These may be invalid if the standby-side has not offered + * values yet. + */ + XLogRecPtr receive; + XLogRecPtr write; + XLogRecPtr flush; + XLogRecPtr apply; + + /* if valid means all the required replication data already flushed on the standby */ + XLogRecPtr data_flush; + /* + * The xlog locations is used for counting sync percentage in function GetSyncPercent. + */ + XLogRecPtr syncPercentCountStart; + + ReplConnInfo wal_sender_channel; + int channel_get_replc; + + /* Protects shared variables shown above. */ + slock_t mutex; + + /* + * Latch used by backends to wake up this walsender when it has work to + * do. + */ + Latch latch; + + /* + * The priority order of the standby managed by this WALSender, as listed + * in synchronous_standby_names, or 0 if not-listed. Protected by + * SyncRepLock. + */ + int sync_standby_priority; + int index; + + LogCtrlData log_ctrl; +} WalSnd; + +extern THR_LOCAL WalSnd* MyWalSnd; + +/* There is one WalSndCtl struct for the whole database cluster */ +typedef struct WalSndCtlData { + /* + * Synchronous replication queue with one queue per request type. + * Protected by SyncRepLock. + */ + SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]; + + /* + * Current location of the head of the queue. All waiters should have a + * waitLSN that follows this value. Protected by SyncRepLock. + */ + XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE]; + + /* + * Are any sync standbys defined? Waiting backends can't reload the + * config file safely, so checkpointer updates this value as needed. + * Protected by SyncRepLock. + */ + bool sync_standbys_defined; + + /* + * Whether master is allowed to switched to standalone if no synchronous + * Standbys are available. This is copy of GUC variable most_available_sync. + */ + bool most_available_sync; + + /* + * Indicates the current running mode of master node. If it is true means + * there is no synchronous standby available so it is running in standalone + * mode. + */ + bool sync_master_standalone; + + /* + * The demotion of postmaster Also indicates that all the walsenders + * should reject any demote requests if postmaster is doning domotion. + */ + DemoteMode demotion; + + /* Protects shared variables of all walsnds. */ + slock_t mutex; + + WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} WalSndCtlData; + +extern THR_LOCAL WalSndCtlData* WalSndCtl; +extern volatile bool bSyncStat; +extern volatile bool bSyncStatStatBefore; +extern void WalSndSetState(WalSndState state); + +#endif /* _WALSENDER_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/prs2lock.h postgresql-hll-2.14/include/include/rewrite/prs2lock.h --- postgresql-hll-2.14_old/include/include/rewrite/prs2lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/prs2lock.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * prs2lock.h + * data structures for POSTGRES Rule System II (rewrite rules only) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/prs2lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRS2LOCK_H +#define PRS2LOCK_H + +#include "access/attnum.h" +#include "nodes/pg_list.h" + +/* + * RewriteRule - + * holds a info for a rewrite rule + * + */ +typedef struct RewriteRule { + Oid ruleId; + CmdType event; + AttrNumber attrno; + Node* qual; + List* actions; + char enabled; + bool isInstead; +} RewriteRule; + +/* + * RuleLock - + * all rules that apply to a particular relation. Even though we only + * have the rewrite rule system left and these are not really "locks", + * the name is kept for historical reasons. + */ +typedef struct RuleLock { + int numLocks; + RewriteRule** rules; +} RuleLock; + +#endif /* REWRITE_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteDefine.h postgresql-hll-2.14/include/include/rewrite/rewriteDefine.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteDefine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteDefine.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,36 @@ +/* ------------------------------------------------------------------------- + * + * rewriteDefine.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteDefine.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEDEFINE_H +#define REWRITEDEFINE_H + +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +#define RULE_FIRES_ON_ORIGIN 'O' +#define RULE_FIRES_ALWAYS 'A' +#define RULE_FIRES_ON_REPLICA 'R' +#define RULE_DISABLED 'D' + +extern void DefineRule(RuleStmt* stmt, const char* queryString); + +extern void DefineQueryRewrite( + char* rulename, Oid event_relid, Node* event_qual, CmdType event_type, bool is_instead, bool replace, List* action); + +extern void RenameRewriteRule(Oid owningRel, const char* oldName, const char* newName); + +extern void setRuleCheckAsUser(Node* node, Oid userid); + +extern void EnableDisableRule(Relation rel, const char* rulename, char fires_when); + +#endif /* REWRITEDEFINE_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteHandler.h postgresql-hll-2.14/include/include/rewrite/rewriteHandler.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteHandler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteHandler.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * rewriteHandler.h + * External interface to query rewriter. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteHandler.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEHANDLER_H +#define REWRITEHANDLER_H + +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +extern List* QueryRewrite(Query* parsetree); +extern void AcquireRewriteLocks(Query* parsetree, bool forUpdatePushedDown); +extern Node* build_column_default(Relation rel, int attrno, bool isInsertCmd = false); +extern List* pull_qual_vars(Node* node, int varno = 0, int flags = 0, bool nonRepeat = false); +extern void rewriteTargetListMerge(Query* parsetree, Index result_relation, List* range_table); + +#ifdef PGXC +extern List* QueryRewriteCTAS(Query* parsetree); +extern List* QueryRewriteRefresh(Query *parsetree); +#endif + +#endif /* REWRITEHANDLER_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteManip.h postgresql-hll-2.14/include/include/rewrite/rewriteManip.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteManip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteManip.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,62 @@ +/* ------------------------------------------------------------------------- + * + * rewriteManip.h + * Querytree manipulation subroutines for query rewriter. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteManip.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEMANIP_H +#define REWRITEMANIP_H + +#include "nodes/parsenodes.h" + +typedef struct replace_rte_variables_context replace_rte_variables_context; + +typedef Node* (*replace_rte_variables_callback)(Var* var, replace_rte_variables_context* context); + +struct replace_rte_variables_context { + replace_rte_variables_callback callback; /* callback function */ + void* callback_arg; /* context data for callback function */ + int target_varno; /* RTE index to search for */ + int sublevels_up; /* (current) nesting depth */ + bool inserted_sublink; /* have we inserted a SubLink? */ +}; + +extern void OffsetVarNodes(Node* node, int offset, int sublevels_up); +extern void ChangeVarNodes(Node* node, int old_varno, int new_varno, int sublevels_up); +extern void IncrementVarSublevelsUp(Node* node, int delta_sublevels_up, int min_sublevels_up); +extern void IncrementVarSublevelsUp_rtable(List* rtable, int delta_sublevels_up, int min_sublevels_up); + +extern bool rangeTableEntry_used(Node* node, int rt_index, int sublevels_up); +extern bool attribute_used(Node* node, int rt_index, int attno, int sublevels_up); + +extern Query* getInsertSelectQuery(Query* parsetree, Query*** subquery_ptr); + +extern void AddQual(Query* parsetree, Node* qual); +extern void AddInvertedQual(Query* parsetree, Node* qual); + +extern bool contain_aggs_of_level_or_above(Node* node, int levelsup); +extern bool contain_aggs_of_level(Node* node, int levelsup); +extern int locate_agg_of_level(Node* node, int levelsup); +extern int locate_windowfunc(Node* node); +extern bool checkExprHasAggs(Node* node); +extern bool checkExprHasWindowFuncs(Node* node); +extern bool checkExprHasSubLink(Node* node); + +extern Node* replace_rte_variables(Node* node, int target_varno, int sublevels_up, + replace_rte_variables_callback callback, void* callback_arg, bool* outer_hasSubLinks); +extern Node* replace_rte_variables_mutator(Node* node, replace_rte_variables_context* context); + +extern Node* map_variable_attnos( + Node* node, int target_varno, int sublevels_up, const AttrNumber* attno_map, int map_length, bool* found_whole_row); + +extern Node* ResolveNew(Node* node, int target_varno, int sublevels_up, RangeTblEntry* target_rte, List* targetlist, + int event, int update_varno, bool* outer_hasSubLinks); + +#endif /* REWRITEMANIP_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteRemove.h postgresql-hll-2.14/include/include/rewrite/rewriteRemove.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteRemove.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteRemove.h 2020-12-12 17:06:43.261348219 +0800 @@ -0,0 +1,21 @@ +/* ------------------------------------------------------------------------- + * + * rewriteRemove.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteRemove.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEREMOVE_H +#define REWRITEREMOVE_H + +#include "nodes/parsenodes.h" + +extern void RemoveRewriteRuleById(Oid ruleOid); + +#endif /* REWRITEREMOVE_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteRlsPolicy.h postgresql-hll-2.14/include/include/rewrite/rewriteRlsPolicy.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteRlsPolicy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteRlsPolicy.h 2020-12-12 17:06:43.262348232 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rewriteRlsPolicy.h + * External interface to row level security rewriter. + * + * + * + * IDENTIFICATION + * src/include/rewrite/rewriteRlsPolicy.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REWRITERLSPOLICY_H +#define REWRITERLSPOLICY_H + +#include "nodes/parsenodes.h" +#include "utils/array.h" + +/* + * The struct that can describe Row Level Security Policy. + * Aleady know the relation information, no need to store relation info. + */ +typedef struct RlsPolicy { + Oid policyOid; /* Policy's oid */ + char cmdName; /* the command name the policy applies to */ + bool isPermissive; /* restrictive or permissive policy */ + bool hasSubLink; /* policy quals include sublink or not */ + char* policyName; /* Policy's name */ + ArrayType* roles; /* the roles associated with the policy */ + Expr* usingExpr; /* the policy's condition */ +} RlsPolicy; + +/* + * The struct describe the Row-Level-Security policies related with current relation. + */ +typedef struct RlsPoliciesDesc { + MemoryContext rlsCxt; /* row level security memory context */ + List* rlsPolicies; /* list of row level security policies */ +} RlsPoliciesDesc; + +enum RlsPolicyCheckResult { RLS_POLICY_MATCH, RLS_POLICY_MISMATCH }; + +enum RelationRlsStatus { + RELATION_RLS_DISABLE, + RELATION_RLS_ENABLE, + RELATION_RLS_FORCE_DISABLE, + RELATION_RLS_FORCE_ENABLE +}; + +extern void GetRlsPolicies(const Query* query, const RangeTblEntry* rte, const Relation relation, List** rlsQuals, + int rtIndex, bool& hasRowSecurity, bool& hasSubLink); + +#endif /* REWRITERLSPOLICY_H */ diff -uprN postgresql-hll-2.14_old/include/include/rewrite/rewriteSupport.h postgresql-hll-2.14/include/include/rewrite/rewriteSupport.h --- postgresql-hll-2.14_old/include/include/rewrite/rewriteSupport.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rewrite/rewriteSupport.h 2020-12-12 17:06:43.262348232 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * rewriteSupport.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteSupport.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITESUPPORT_H +#define REWRITESUPPORT_H + +/* The ON SELECT rule of a view is always named this: */ +#define ViewSelectRuleName "_RETURN" + +extern bool IsDefinedRewriteRule(Oid owningRel, const char* ruleName); + +extern void SetRelationRuleStatus(Oid relationId, bool relHasRules, bool relIsBecomingView); + +extern Oid get_rewrite_oid(Oid relid, const char* rulename, bool missing_ok); +extern Oid get_rewrite_oid_without_relid(const char* rulename, Oid* relid, bool missing_ok); +extern char* get_rewrite_rulename(Oid ruleid, bool missing_ok); +extern bool rel_has_rule(Oid relid, char ev_type); + + +#endif /* REWRITESUPPORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/rusagestub.h postgresql-hll-2.14/include/include/rusagestub.h --- postgresql-hll-2.14_old/include/include/rusagestub.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/rusagestub.h 2020-12-12 17:06:43.262348232 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * rusagestub.h + * Stubs for getrusage(3). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rusagestub.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RUSAGESTUB_H +#define RUSAGESTUB_H + +#include /* for struct timeval */ +#ifndef WIN32 +#include /* for struct tms */ +#endif +#include /* for CLK_TCK */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN (-1) + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ +}; + +extern int getrusage(int who, struct rusage* rusage); + +#ifndef WIN32 +extern List* get_operator_name(Oid operid, Oid arg1, Oid arg2); +#endif + +#endif /* RUSAGESTUB_H */ diff -uprN postgresql-hll-2.14_old/include/include/securec_check.h postgresql-hll-2.14/include/include/securec_check.h --- postgresql-hll-2.14_old/include/include/securec_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/securec_check.h 2020-12-12 17:06:43.262348232 +0800 @@ -0,0 +1,117 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * securec_check.h + * + * + * + * IDENTIFICATION + * src/include/securec_check.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _SECUREC_CHECK_H_ +#define _SECUREC_CHECK_H_ + +#include "securectype.h" +#include +/* free space for error function operator with exit-function mechanism */ +#define freeSecurityFuncSpace_c(str1, str2) \ + { \ + if (str1 != NULL && strlen(str1) > 0) \ + free((char*)str1); \ + if (str2 != NULL && strlen(str2) > 0) \ + free((char*)str2); \ + } + +#ifndef GDS_SERVER +/* gds using gds_securec_check and gds_securec_check_ss */ +#define securec_check_c(errno, str1, str2) \ + { \ + errno_t e_for_securec_check_c = (errno); \ + if (EOK != e_for_securec_check_c) { \ + freeSecurityFuncSpace_c(str1, str2); \ + switch (e_for_securec_check_c) { \ + case EINVAL: \ + printf("ERROR at %s : %d : The destination buffer is NULL or not terminated. The second case " \ + "only occures in function strcat_s/strncat_s.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + printf("ERROR at %s : %d : The source buffer is NULL.\n", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + printf("ERROR at %s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + printf("ERROR at %s : %d : The parameter destMax is too small or parameter count is larger than " \ + "macro parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + printf("ERROR at %s : %d : The destination buffer and source buffer are overlapped.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + printf("ERROR at %s : %d : Unrecognized return type.\n", __FILE__, __LINE__); \ + break; \ + } \ + exit(1); \ + } \ + } + +#define securec_check_ss_c(errno, str1, str2) \ + do { \ + if (errno == -1) { \ + freeSecurityFuncSpace_c(str1, str2); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) +#endif + +/* define a macro about the return value of security function */ +#define securec_check_intval_core(val, express) \ + if (val == -1) { \ + fprintf(stderr, \ + "WARNING: %s:%d failed on calling " \ + "security function.\n", \ + __FILE__, \ + __LINE__); \ + express; \ + } + +#define securec_check_for_sscanf_s(ret, min_num, str1, str2) \ + do { \ + if ((ret) < (min_num)) { \ + freeSecurityFuncSpace_c(str1, str2); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) +#endif diff -uprN postgresql-hll-2.14_old/include/include/securec.h postgresql-hll-2.14/include/include/securec.h --- postgresql-hll-2.14_old/include/include/securec.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/securec.h 2020-12-12 17:06:43.262348232 +0800 @@ -0,0 +1,624 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. + * Description: The user of this secure c library should include this header file in you source code. + * This header file declare all supported API prototype of the library, + * such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on. + * Author: lishunda + * Create: 2014-02-25 + * Notes: Do not modify this file by yourself. + * History: 2018-09-27 zhaozhijian Code base quality improvement + */ + +#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 +#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 + +#include "securectype.h" +#ifndef SECUREC_HAVE_STDARG_H +#define SECUREC_HAVE_STDARG_H 1 +#endif + +#if SECUREC_HAVE_STDARG_H +#include +#endif + +#ifndef SECUREC_HAVE_ERRNO_H +#define SECUREC_HAVE_ERRNO_H 1 +#endif + +/* EINVAL ERANGE may defined in errno.h */ +#if SECUREC_HAVE_ERRNO_H +#if SECUREC_IN_KERNEL +#include +#else +#include +#endif +#endif + +/* Define error code */ +#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ + (defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__)) +#ifndef SECUREC_DEFINED_ERRNO_TYPE +#define SECUREC_DEFINED_ERRNO_TYPE +/* Just check whether macrodefinition exists. */ +#ifndef errno_t +typedef int errno_t; +#endif +#endif +#endif + +/* Success */ +#ifndef EOK +#define EOK 0 +#endif + +#ifndef EINVAL +/* The src buffer is not correct and destination buffer cant not be reset */ +#define EINVAL 22 +#endif + +#ifndef EINVAL_AND_RESET +/* Once the error is detected, the dest buffer must be reseted! Value is 22 xor 128 */ +#define EINVAL_AND_RESET 150 +#endif + +#ifndef ERANGE +/* The destination buffer is not long enough and destination buffer can not be reset */ +#define ERANGE 34 +#endif + +#ifndef ERANGE_AND_RESET +/* Once the error is detected, the dest buffer must be reseted! Value is 34 xor 128 */ +#define ERANGE_AND_RESET 162 +#endif + +#ifndef EOVERLAP_AND_RESET +/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 xor 128 */ +#define EOVERLAP_AND_RESET 182 +#endif + +/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */ +#ifndef SECUREC_API +#if defined(SECUREC_DLL_EXPORT) +#define SECUREC_API __declspec(dllexport) +#elif defined(SECUREC_DLL_IMPORT) +#define SECUREC_API __declspec(dllimport) +#else +/* + * Standardized function declaration. If a security function is declared in the your code, + * it may cause a compilation alarm,Please delete the security function you declared. + * Adding extern under windows will cause the system to have inline functions to expand, + * so do not add the extern in default + */ +#if defined(_MSC_VER) +#define SECUREC_API +#else +#define SECUREC_API extern +#endif +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + /* + * Description: The GetHwSecureCVersion function get SecureC Version string and version number. + * Parameter: verNumber - to store version number (for example value is 0x500 | 0xa) + * Return: version string + */ + SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); + +#if SECUREC_ENABLE_MEMSET + /* + * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of + * the first count characters of the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: c - the value to be copied + * Parameter: count - copies count bytes of value to dest + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); +#endif + +#ifndef SECUREC_ONLY_DECLARE_MEMSET +#define SECUREC_ONLY_DECLARE_MEMSET 0 +#endif + +#if !SECUREC_ONLY_DECLARE_MEMSET + +#if SECUREC_ENABLE_MEMMOVE + /* + * Description: The memmove_s function copies n characters from the object pointed to by src + * into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count); +#endif + +#if SECUREC_ENABLE_MEMCPY + /* + * Description: The memcpy_s function copies n characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count); +#endif + +#if SECUREC_ENABLE_STRCPY + /* + * Description: The strcpy_s function copies the string pointed to by strSrc (including + * the terminating null character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCPY + /* + * Description: The strncpy_s function copies not more than n successive characters (not including + * the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRCAT + /* + * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including + * the terminating null character) to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCAT + /* + * Description: The strncat_s function appends not more than n successive characters (not including + * the terminating null character) + * from the array pointed to by strSrc to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_VSPRINTF + /* + * Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); +#endif + +#if SECUREC_ENABLE_SPRINTF + /* + * Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4); +#endif + +#if SECUREC_ENABLE_VSNPRINTF + /* + * Description: The vsnprintf_s function is equivalent to the vsnprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + va_list argList) SECUREC_ATTRIBUTE(4, 0); +#endif + +#if SECUREC_ENABLE_SNPRINTF + /* + * Description: The snprintf_s function is equivalent to the snprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + ...) SECUREC_ATTRIBUTE(4, 5); +#endif + +#if SECUREC_SNPRINTF_TRUNCATED + /* + * Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); + + /* + * Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax, + const char *format, ...) SECUREC_ATTRIBUTE(3, 4); +#endif + +#if SECUREC_ENABLE_SCANF + /* + * Description: The scanf_s function is equivalent to fscanf_s with the argument stdin + * interposed before the arguments to scanf_s + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int scanf_s(const char *format, ...); +#endif + +#if SECUREC_ENABLE_VSCANF + /* + * Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vscanf_s(const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SSCANF + /* + * Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a + * string (specified by the argument buffer) rather than from a stream + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int sscanf_s(const char *buffer, const char *format, ...); +#endif + +#if SECUREC_ENABLE_VSSCANF + /* + * Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list + * replaced by argList + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_FSCANF + /* + * Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers + * apply to a pair of arguments (unless assignment suppression is indicated by a*) + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fscanf_s(FILE *stream, const char *format, ...); +#endif + +#if SECUREC_ENABLE_VFSCANF + /* + * Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list + * replaced by argList + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_STRTOK + /* + * Description: The strtok_s function parses a string into a sequence of strToken, + * replace all characters in strToken string that match to strDelimit set with 0. + * On the first call to strtok_s the string to be parsed should be specified in strToken. + * In each subsequent call that should parse the same string, strToken should be NULL + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned. + * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call, + * return NULL if the *context string length is equal 0, otherwise return *context. + */ + SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context); +#endif + +#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL + /* + * Description: The gets_s function reads at most one less than the number of characters specified + * by destMax from the stream pointed to by stdin, into the array pointed to by buffer + * Parameter: buffer - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL. + */ + SECUREC_API char *gets_s(char *buffer, size_t destMax); +#endif + +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_MEMCPY + /* + * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); +#endif + +#if SECUREC_ENABLE_MEMMOVE + /* + * Description: The wmemmove_s function copies n successive wide characters from the object + * pointed to by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); +#endif + +#if SECUREC_ENABLE_STRCPY + /* + * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating + * null wide character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCPY + /* + * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRCAT + /* + * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the + * terminating null wide character) to the end of the wide string pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCAT + /* + * Description: The wcsncat_s function appends not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to + * by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRTOK + /* + * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: a pointer to the first character of a token, or a null pointer if there is no token + * or there is a runtime-constraint violation. + */ + SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); +#endif + +#if SECUREC_ENABLE_VSPRINTF + /* + * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SPRINTF + + /* + * Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_FSCANF + /* + * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VFSCANF + /* + * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SCANF + /* + * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int wscanf_s(const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VSCANF + /* + * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SSCANF + /* + * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VSSCANF + /* + * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList); +#endif +#endif /* SECUREC_ENABLE_WCHAR_FUNC */ +#endif + + /* Those functions are used by macro ,must declare hare , also for without function declaration warning */ + extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count); + extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); + +#if SECUREC_WITH_PERFORMANCE_ADDONS + /* Those functions are used by macro */ + extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); + extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); + extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count); + extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count); + +/* The strcpy_sp is a macro, not a function in performance optimization mode. */ +#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCPY_SM((dest), (destMax), (src)) : \ + strcpy_s((dest), (destMax), (src))) + +/* The strncpy_sp is a macro, not a function in performance optimization mode. */ +#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \ + strncpy_s((dest), (destMax), (src), (count))) + +/* The strcat_sp is a macro, not a function in performance optimization mode. */ +#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCAT_SM((dest), (destMax), (src)) : \ + strcat_s((dest), (destMax), (src))) + +/* The strncat_sp is a macro, not a function in performance optimization mode. */ +#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \ + strncat_s((dest), (destMax), (src), (count))) + +/* The memcpy_sp is a macro, not a function in performance optimization mode. */ +#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \ + memcpy_sOptAsm((dest), (destMax), (src), (count)))) + +/* The memset_sp is a macro, not a function in performance optimization mode. */ +#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \ + memset_sOptAsm((dest), (destMax), (c), (count)))) + +#endif + +#ifdef __cplusplus +} +#endif +#endif + diff -uprN postgresql-hll-2.14_old/include/include/securectype.h postgresql-hll-2.14/include/include/securectype.h --- postgresql-hll-2.14_old/include/include/securectype.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/securectype.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,569 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. + * Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS + * will be determined in this header file, which is a switch for part + * of code. Some macro are used to supress warning by MS compiler. + * Author: lishunda + * Create: 2014-02-25 + * Notes: User can change the value of SECUREC_STRING_MAX_LEN and SECUREC_MEM_MAX_LEN + * macro to meet their special need, but The maximum value should not exceed 2G. + * History: 2018-09-27 zhaozhijian Code base quality improvement + */ +/* + * [Standardize-exceptions]: Performance-sensitive + * [reason]: Strict parameter verification has been done before use + */ + +#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 +#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 + +#ifndef SECUREC_USING_STD_SECURE_LIB +#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__) +/* Security functions have been provided since vs2005, default use of system library functions */ +#define SECUREC_USING_STD_SECURE_LIB 0 +#else +#define SECUREC_USING_STD_SECURE_LIB 1 +#endif +#else +#define SECUREC_USING_STD_SECURE_LIB 0 +#endif +#endif + +/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB) +#ifndef SECUREC_DISABLE_CRT_FUNC +#define SECUREC_DISABLE_CRT_FUNC 1 +#endif +#ifndef SECUREC_DISABLE_CRT_IMP +#define SECUREC_DISABLE_CRT_IMP 1 +#endif +#else /* MSC VER */ +#ifndef SECUREC_DISABLE_CRT_FUNC +#define SECUREC_DISABLE_CRT_FUNC 0 +#endif +#ifndef SECUREC_DISABLE_CRT_IMP +#define SECUREC_DISABLE_CRT_IMP 0 +#endif +#endif + +#if SECUREC_DISABLE_CRT_FUNC +#ifdef __STDC_WANT_SECURE_LIB__ +#undef __STDC_WANT_SECURE_LIB__ +#endif +#define __STDC_WANT_SECURE_LIB__ 0 +#endif + +#if SECUREC_DISABLE_CRT_IMP +#ifdef _CRTIMP_ALTERNATIVE +#undef _CRTIMP_ALTERNATIVE +#endif +#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ +#endif + +/* Compile in kernel under macro control */ +#ifndef SECUREC_IN_KERNEL +#ifdef __KERNEL__ +#define SECUREC_IN_KERNEL 1 +#else +#define SECUREC_IN_KERNEL 0 +#endif +#endif + +#if SECUREC_IN_KERNEL +#ifndef SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF_FILE 0 +#endif +#ifndef SECUREC_ENABLE_WCHAR_FUNC +#define SECUREC_ENABLE_WCHAR_FUNC 0 +#endif +#else /* SECUREC_IN_KERNEL */ +#ifndef SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF_FILE 1 +#endif +#ifndef SECUREC_ENABLE_WCHAR_FUNC +#define SECUREC_ENABLE_WCHAR_FUNC 1 +#endif +#endif + +/* Default secure function declaration, default declarations for non-standard functions */ +#ifndef SECUREC_SNPRINTF_TRUNCATED +#define SECUREC_SNPRINTF_TRUNCATED 1 +#endif + +#if SECUREC_USING_STD_SECURE_LIB +#if defined(_MSC_VER) && _MSC_VER >= 1400 +/* Declare secure functions that are not available in the VS compiler */ +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 1 +#endif +/* VS 2005 have vsnprintf_s function */ +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */ +#define snprintf_s _snprintf_s +#define SECUREC_ENABLE_SNPRINTF 0 +#endif +/* Before VS 2010 do not have v functions */ +#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS) +#ifndef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSCANF +#define SECUREC_ENABLE_VSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 1 +#endif +#endif + +#else /* MSC VER */ +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 0 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +#define SECUREC_ENABLE_SNPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_MEMMOVE +#define SECUREC_ENABLE_MEMMOVE 0 +#endif +#ifndef SECUREC_ENABLE_MEMCPY +#define SECUREC_ENABLE_MEMCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRCPY +#define SECUREC_ENABLE_STRCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRNCPY +#define SECUREC_ENABLE_STRNCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRCAT +#define SECUREC_ENABLE_STRCAT 0 +#endif +#ifndef SECUREC_ENABLE_STRNCAT +#define SECUREC_ENABLE_STRNCAT 0 +#endif +#ifndef SECUREC_ENABLE_SPRINTF +#define SECUREC_ENABLE_SPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_VSPRINTF +#define SECUREC_ENABLE_VSPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_SSCANF +#define SECUREC_ENABLE_SSCANF 0 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 0 +#endif +#ifndef SECUREC_ENABLE_SCANF +#define SECUREC_ENABLE_SCANF 0 +#endif +#ifndef SECUREC_ENABLE_VSCANF +#define SECUREC_ENABLE_VSCANF 0 +#endif + +#ifndef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif +#ifndef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#ifndef SECUREC_ENABLE_STRTOK +#define SECUREC_ENABLE_STRTOK 0 +#endif +#ifndef SECUREC_ENABLE_GETS +#define SECUREC_ENABLE_GETS 0 +#endif + +#else /* SECUREC USE STD SECURE LIB */ + +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 1 +#endif +#ifndef SECUREC_ENABLE_MEMMOVE +#define SECUREC_ENABLE_MEMMOVE 1 +#endif +#ifndef SECUREC_ENABLE_MEMCPY +#define SECUREC_ENABLE_MEMCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRCPY +#define SECUREC_ENABLE_STRCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRNCPY +#define SECUREC_ENABLE_STRNCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRCAT +#define SECUREC_ENABLE_STRCAT 1 +#endif +#ifndef SECUREC_ENABLE_STRNCAT +#define SECUREC_ENABLE_STRNCAT 1 +#endif +#ifndef SECUREC_ENABLE_SPRINTF +#define SECUREC_ENABLE_SPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_VSPRINTF +#define SECUREC_ENABLE_VSPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +#define SECUREC_ENABLE_SNPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_SSCANF +#define SECUREC_ENABLE_SSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 1 +#endif +#ifndef SECUREC_ENABLE_SCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF 1 +#else +#define SECUREC_ENABLE_SCANF 0 +#endif +#endif +#ifndef SECUREC_ENABLE_VSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_VSCANF 1 +#else +#define SECUREC_ENABLE_VSCANF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_FSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_FSCANF 1 +#else +#define SECUREC_ENABLE_FSCANF 0 +#endif +#endif +#ifndef SECUREC_ENABLE_VFSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_VFSCANF 1 +#else +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_STRTOK +#define SECUREC_ENABLE_STRTOK 1 +#endif +#ifndef SECUREC_ENABLE_GETS +#define SECUREC_ENABLE_GETS 1 +#endif +#endif /* SECUREC_USE_STD_SECURE_LIB */ + +#if !SECUREC_ENABLE_SCANF_FILE +#if SECUREC_ENABLE_FSCANF +#undef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif +#if SECUREC_ENABLE_VFSCANF +#undef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#if SECUREC_ENABLE_SCANF +#undef SECUREC_ENABLE_SCANF +#define SECUREC_ENABLE_SCANF 0 +#endif +#if SECUREC_ENABLE_FSCANF +#undef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif + +#endif + +#if SECUREC_IN_KERNEL +#include +#include +#else +#ifndef SECUREC_HAVE_STDIO_H +#define SECUREC_HAVE_STDIO_H 1 +#endif +#ifndef SECUREC_HAVE_STRING_H +#define SECUREC_HAVE_STRING_H 1 +#endif +#ifndef SECUREC_HAVE_STDLIB_H +#define SECUREC_HAVE_STDLIB_H 1 +#endif +#if SECUREC_HAVE_STDIO_H +#include +#endif +#if SECUREC_HAVE_STRING_H +#include +#endif +#if SECUREC_HAVE_STDLIB_H +#include +#endif +#endif + +/* + * If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable. + * The macro is automatically closed on the windows platform and linux kernel + */ +#ifndef SECUREC_WITH_PERFORMANCE_ADDONS +#if SECUREC_IN_KERNEL +#define SECUREC_WITH_PERFORMANCE_ADDONS 0 +#else +#define SECUREC_WITH_PERFORMANCE_ADDONS 1 +#endif +#endif + +/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */ +#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT) +#ifndef SECUREC_COMPATIBLE_WIN_FORMAT +#define SECUREC_COMPATIBLE_WIN_FORMAT +#endif +#endif + +#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) +/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */ +/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */ +#ifdef SECUREC_WITH_PERFORMANCE_ADDONS +#undef SECUREC_WITH_PERFORMANCE_ADDONS +#define SECUREC_WITH_PERFORMANCE_ADDONS 0 +#endif +#endif + +#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \ + defined(SECUREC_VXWORKS_VERSION_5_4) +#ifndef SECUREC_VXWORKS_PLATFORM +#define SECUREC_VXWORKS_PLATFORM +#endif +#endif + +/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */ +#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM) +#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT +#define SECUREC_COMPATIBLE_LINUX_FORMAT +#endif +#endif + +#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT +#ifndef SECUREC_HAVE_STDDEF_H +#define SECUREC_HAVE_STDDEF_H 1 +#endif +/* Some system may no stddef.h */ +#if SECUREC_HAVE_STDDEF_H +#if !SECUREC_IN_KERNEL +#include +#endif +#endif +#endif + +/* + * Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2. + * Default does not check the format is that the same data type in the actual code. + * In the product is different in the original data type definition of VxWorks and Linux. + */ +#ifndef SECUREC_SUPPORT_FORMAT_WARNING +#define SECUREC_SUPPORT_FORMAT_WARNING 0 +#endif + +#if SECUREC_SUPPORT_FORMAT_WARNING +#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y)))) +#else +#define SECUREC_ATTRIBUTE(x, y) +#endif + +/* + * Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if complier can not support __builtin_expect. + */ +#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT +#define SECUREC_SUPPORT_BUILTIN_EXPECT 1 +#endif + +#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) +/* + * This is a built-in function that can be used without a declaration, if warning for declaration not found occurred, + * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options + */ +#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE +long __builtin_expect(long exp, long c); +#endif + +#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1) +#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define SECUREC_LIKELY(x) (x) +#define SECUREC_UNLIKELY(x) (x) +#endif + +/* Define the max length of the string */ +#ifndef SECUREC_STRING_MAX_LEN +#define SECUREC_STRING_MAX_LEN 0x7fffffffUL +#endif +#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t)) + +/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */ +#ifndef SECUREC_MEM_MAX_LEN +#define SECUREC_MEM_MAX_LEN 0x7fffffffUL +#endif +#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t)) + +#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL +#error "max string is 2G" +#endif + +#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__)) +#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8) +#error "unsupported system" +#endif +#endif + +#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64) +#define SECUREC_ON_64BITS +#endif + +#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__)) +#if __SIZEOF_POINTER__ == 8 +#define SECUREC_ON_64BITS +#endif +#endif + +#if defined(__SVR4) || defined(__svr4__) +#define SECUREC_ON_SOLARIS +#endif + +#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS)) +#define SECUREC_ON_UNIX +#endif + +/* + * Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default, + * and strtold. + * The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can + * not support these functions. Here provides a macro to open these functions: + * SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used + */ +#ifndef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 0 +#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) +#if defined(__USE_ISOC99) || \ + (defined(_AIX) && defined(_ISOC99_SOURCE)) || \ + (defined(__hpux) && defined(__ia64)) || \ + (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ + defined(_STDC_C99) || defined(__EXTENSIONS__)) +#undef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 1 +#endif +#endif +#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_))) +#undef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 0 +#endif +#endif + +#if SECUREC_WITH_PERFORMANCE_ADDONS + +#ifndef SECUREC_TWO_MIN +#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +/* For strncpy_s performance optimization */ +#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \ + (((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \ + (memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count)))) + +#define SECUREC_STRCPY_SM(dest, destMax, src) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \ + (strcpy_error((dest), (destMax), (src)))) + +/* For strcat_s performance optimization */ +#if defined(__GNUC__) +#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \ + int catRet_ = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *catTmpDst_ = (char *)(dest); \ + size_t catRestSize_ = (destMax); \ + while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \ + ++catTmpDst_; \ + --catRestSize_; \ + } \ + if (catRestSize_ == 0) { \ + catRet_ = EINVAL; \ + } else if ((strlen(src) + 1) <= catRestSize_) { \ + memcpy(catTmpDst_, (src), strlen(src) + 1); \ + catRet_ = EOK; \ + } else { \ + catRet_ = ERANGE; \ + } \ + if (catRet_ != EOK) { \ + catRet_ = strcat_s((dest), (destMax), (src)); \ + } \ + } else { \ + catRet_ = strcat_s((dest), (destMax), (src)); \ + } \ + catRet_; \ +}) +#else +#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src)) +#endif + +/* For strncat_s performance optimization */ +#if defined(__GNUC__) +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \ + int ncatRet_ = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *ncatTmpDest_ = (char *)(dest); \ + size_t ncatRestSize_ = (size_t)(destMax); \ + while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \ + ++ncatTmpDest_; \ + --ncatRestSize_; \ + } \ + if (ncatRestSize_ == 0) { \ + ncatRet_ = EINVAL; \ + } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \ + if ((size_t)(count) < strlen(src)) { \ + memcpy(ncatTmpDest_, (src), (count)); \ + *(ncatTmpDest_ + (count)) = '\0'; \ + } else { \ + memcpy(ncatTmpDest_, (src), strlen(src) + 1); \ + } \ + } else { \ + ncatRet_ = ERANGE; \ + } \ + if (ncatRet_ != EOK) { \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ + } \ + } else { \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ + } \ + ncatRet_; \ +}) +#else +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count)) +#endif + +/* This macro do not check buffer overlap by default */ +#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \ + (!(((size_t)(destMax) == 0) || \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \ + (memcpy((dest), (src), (count)), EOK) : \ + (memcpy_s((dest), (destMax), (src), (count)))) + +#define SECUREC_MEMSET_SM(dest, destMax, c, count) \ + (!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \ + (memset((dest), (c), (count)), EOK) : \ + (memset_s((dest), (destMax), (c), (count)))) + +#endif +#endif + diff -uprN postgresql-hll-2.14_old/include/include/service/rpc_client.h postgresql-hll-2.14/include/include/service/rpc_client.h --- postgresql-hll-2.14_old/include/include/service/rpc_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/service/rpc_client.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rpc_client.h + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * IDENTIFICATION + * src/include/service/rpc_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef RPC_CLIENT_H +#define RPC_CLIENT_H + +#include "c.h" + +#include +#include "storage/remote_adapter.h" + +extern std::shared_ptr GetSSlCredential(TlsCertPath clientCert); + +extern int RemoteGetCU(const char* remote_address, uint32 spcnode, uint32 dbnode, uint32 relnode, int32 colid, + uint64 offset, int32 size, uint64 lsn, char* cu_data); + +extern int RemoteGetPage(const char* remote_address, uint32 spcnode, uint32 dbnode, uint32 relnode, int2 bucketnode, + int32 forknum, uint32 blocknum, uint32 blocksize, uint64 lsn, char* page_data); + +#endif /* RPC_CLIENT_H */ diff -uprN postgresql-hll-2.14_old/include/include/service/rpc_server.h postgresql-hll-2.14/include/include/service/rpc_server.h --- postgresql-hll-2.14_old/include/include/service/rpc_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/service/rpc_server.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rpc_server.h + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * IDENTIFICATION + * src/include/service/rpc_server.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef RPC_SERVER_H +#define RPC_SERVER_H + +typedef struct RPCServerContext RPCServerContext; + +extern RPCServerContext* BuildAndStartServer(const char* listen_address); + +extern void ShutdownAndReleaseServer(RPCServerContext* server_context); + +extern void ForceReleaseServer(RPCServerContext* server_context); + +#endif /* RPC_SERVER_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/header.h postgresql-hll-2.14/include/include/snowball/header.h --- postgresql-hll-2.14_old/include/include/snowball/header.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/header.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * header.h + * Replacement header file for Snowball stemmer modules + * + * The Snowball stemmer modules do #include "header.h", and think they + * are including snowball/libstemmer/header.h. We adjust the CPPFLAGS + * so that this file is found instead, and thereby we can modify the + * headers they see. The main point here is to ensure that pg_config.h + * is included before any system headers such as ; without that, + * we have portability issues on some platforms due to variation in + * largefile options across different modules in the backend. + * + * NOTE: this file should not be included into any non-snowball sources! + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/snowball/header.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNOWBALL_HEADR_H +#define SNOWBALL_HEADR_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +/* Some platforms define MAXINT and/or MININT, causing conflicts */ +#ifdef MAXINT +#undef MAXINT +#endif +#ifdef MININT +#undef MININT +#endif + +/* Now we can include the original Snowball header.h */ +#include "snowball/libstemmer/header.h" /* pgrminclude ignore */ + +/* + * Redefine standard memory allocation interface to pgsql's one. + * This allows us to control where the Snowball code allocates stuff. + */ +#ifdef malloc +#undef malloc +#endif +#define malloc(a) palloc(a) + +#ifdef calloc +#undef calloc +#endif +#define calloc(a, b) palloc0((a) * (b)) + +#ifdef realloc +#undef realloc +#endif +#define realloc(a, b) repalloc(a, b) + +#ifdef free +#undef free +#endif +#define free(a) pfree(a) + +#endif /* SNOWBALL_HEADR_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/api.h postgresql-hll-2.14/include/include/snowball/libstemmer/api.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/api.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,32 @@ +#ifndef API_H +#define API_H + +typedef unsigned char symbol; + +/* Or replace 'char' above with 'short' for 16 bit characters. + + More precisely, replace 'char' with whatever type guarantees the + character width you need. Note however that sizeof(symbol) should divide + HEAD, defined in header.h as 2*sizeof(int), without remainder, otherwise + there is an alignment problem. In the unlikely event of a problem here, + consult Martin Porter. + +*/ +struct SN_env { + symbol* p; + int c; + int l; + int lb; + int bra; + int ket; + symbol** S; + int* I; + unsigned char* B; +}; + +extern struct SN_env* SN_create_env(int S_size, int I_size, int B_size); +extern void SN_close_env(struct SN_env* z, int S_size); + +extern int SN_set_current(struct SN_env* z, int size, const symbol* s); + +#endif /* API_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/header.h postgresql-hll-2.14/include/include/snowball/libstemmer/header.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/header.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/header.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,57 @@ + +#include + +#include "api.h" + +#define MAXINT INT_MAX +#define MININT INT_MIN + +#define HEAD 2 * sizeof(int) + +#define SIZE(p) ((int*)(p))[-1] +#define SET_SIZE(p, n) ((int*)(p))[-1] = n +#define CAPACITY(p) ((int*)(p))[-2] + +struct among { + int s_size; /* number of chars in string */ + const symbol* s; /* search string */ + int substring_i; /* index to longest matching substring */ + int result; /* result of the lookup */ + int (*function)(struct SN_env*); +}; + +extern symbol* create_s(void); +extern void lose_s(symbol* p); + +extern int skip_utf8(const symbol* p, int c, int lb, int l, int n); + +extern int in_grouping_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int in_grouping_b_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_b_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); + +extern int in_grouping(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int in_grouping_b(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_b(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); + +extern int eq_s(struct SN_env* z, int s_size, const symbol* s); +extern int eq_s_b(struct SN_env* z, int s_size, const symbol* s); +extern int eq_v(struct SN_env* z, const symbol* p); +extern int eq_v_b(struct SN_env* z, const symbol* p); + +extern int find_among(struct SN_env* z, const struct among* v, int v_size); +extern int find_among_b(struct SN_env* z, const struct among* v, int v_size); + +extern int replace_s(struct SN_env* z, int c_bra, int c_ket, int s_size, const symbol* s, int* adjustment); +extern int slice_from_s(struct SN_env* z, int s_size, const symbol* s); +extern int slice_from_v(struct SN_env* z, const symbol* p); +extern int slice_del(struct SN_env* z); + +extern int insert_s(struct SN_env* z, int bra, int ket, int s_size, const symbol* s); +extern int insert_v(struct SN_env* z, int bra, int ket, const symbol* p); + +extern symbol* slice_to(struct SN_env* z, symbol* p); +extern symbol* assign_to(struct SN_env* z, symbol* p); + +extern void debug(struct SN_env* z, int number, int line_count); diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_danish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_danish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_danish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_danish.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_DANISH_H +#define STEM_ISO_8859_1_DANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* danish_ISO_8859_1_create_env(void); +extern void danish_ISO_8859_1_close_env(struct SN_env* z); + +extern int danish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_DANISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_DUTCH_H +#define STEM_ISO_8859_1_DUTCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* dutch_ISO_8859_1_create_env(void); +extern void dutch_ISO_8859_1_close_env(struct SN_env* z); + +extern int dutch_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_DUTCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_english.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_english.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_english.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_english.h 2020-12-12 17:06:43.263348245 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_ENGLISH_H +#define STEM_ISO_8859_1_ENGLISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* english_ISO_8859_1_create_env(void); +extern void english_ISO_8859_1_close_env(struct SN_env* z); + +extern int english_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_ENGLISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_FINNISH_H +#define STEM_ISO_8859_1_FINNISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* finnish_ISO_8859_1_create_env(void); +extern void finnish_ISO_8859_1_close_env(struct SN_env* z); + +extern int finnish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_FINNISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_french.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_french.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_french.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_french.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_FRENCH_H +#define STEM_ISO_8859_1_FRENCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* french_ISO_8859_1_create_env(void); +extern void french_ISO_8859_1_close_env(struct SN_env* z); + +extern int french_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_FRENCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_german.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_german.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_german.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_german.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_GERMAN_H +#define STEM_ISO_8859_1_GERMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* german_ISO_8859_1_create_env(void); +extern void german_ISO_8859_1_close_env(struct SN_env* z); + +extern int german_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_GERMAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_HUNGARIAN_H +#define STEM_ISO_8859_1_HUNGARIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* hungarian_ISO_8859_1_create_env(void); +extern void hungarian_ISO_8859_1_close_env(struct SN_env* z); + +extern int hungarian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_HUNGARIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_italian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_italian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_italian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_italian.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_ITALIAN_H +#define STEM_ISO_8859_1_ITALIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* italian_ISO_8859_1_create_env(void); +extern void italian_ISO_8859_1_close_env(struct SN_env* z); + +extern int italian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_ITALIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_NORWEGIAN_H +#define STEM_ISO_8859_1_NORWEGIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* norwegian_ISO_8859_1_create_env(void); +extern void norwegian_ISO_8859_1_close_env(struct SN_env* z); + +extern int norwegian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_NORWEGIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_porter.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_porter.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_porter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_porter.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_PORTER_H +#define STEM_ISO_8859_1_PORTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* porter_ISO_8859_1_create_env(void); +extern void porter_ISO_8859_1_close_env(struct SN_env* z); + +extern int porter_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_PORTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_PORTUGUESE_H +#define STEM_ISO_8859_1_PORTUGUESE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* portuguese_ISO_8859_1_create_env(void); +extern void portuguese_ISO_8859_1_close_env(struct SN_env* z); + +extern int portuguese_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_PORTUGUESE_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_SPANISH_H +#define STEM_ISO_8859_1_SPANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* spanish_ISO_8859_1_create_env(void); +extern void spanish_ISO_8859_1_close_env(struct SN_env* z); + +extern int spanish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_SPANISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_SWEDISH_H +#define STEM_ISO_8859_1_SWEDISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* swedish_ISO_8859_1_create_env(void); +extern void swedish_ISO_8859_1_close_env(struct SN_env* z); + +extern int swedish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_SWEDISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h 2020-12-12 17:06:43.264348258 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_2_ROMANIAN_H +#define STEM_ISO_8859_2_ROMANIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* romanian_ISO_8859_2_create_env(void); +extern void romanian_ISO_8859_2_close_env(struct SN_env* z); + +extern int romanian_ISO_8859_2_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_2_ROMANIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_KOI8_R_russian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_KOI8_R_russian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_KOI8_R_russian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_KOI8_R_russian.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_KOI8_R_RUSSIAN_H +#define STEM_KOI8_R_RUSSIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* russian_KOI8_R_create_env(void); +extern void russian_KOI8_R_close_env(struct SN_env* z); + +extern int russian_KOI8_R_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_KOI8_R_RUSSIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_danish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_danish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_danish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_danish.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_DANISH_H +#define STEM_UTF_8_DANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* danish_UTF_8_create_env(void); +extern void danish_UTF_8_close_env(struct SN_env* z); + +extern int danish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_DANISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_dutch.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_dutch.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_dutch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_dutch.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_DUTCH_H +#define STEM_UTF_8_DUTCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* dutch_UTF_8_create_env(void); +extern void dutch_UTF_8_close_env(struct SN_env* z); + +extern int dutch_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_DUTCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_english.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_english.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_english.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_english.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ENGLISH_H +#define STEM_UTF_8_ENGLISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* english_UTF_8_create_env(void); +extern void english_UTF_8_close_env(struct SN_env* z); + +extern int english_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ENGLISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_finnish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_finnish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_finnish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_finnish.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_FINNISH_H +#define STEM_UTF_8_FINNISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* finnish_UTF_8_create_env(void); +extern void finnish_UTF_8_close_env(struct SN_env* z); + +extern int finnish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_FINNISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_french.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_french.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_french.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_french.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_FRENCH_H +#define STEM_UTF_8_FRENCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* french_UTF_8_create_env(void); +extern void french_UTF_8_close_env(struct SN_env* z); + +extern int french_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_FRENCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_german.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_german.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_german.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_german.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_GERMAN_H +#define STEM_UTF_8_GERMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* german_UTF_8_create_env(void); +extern void german_UTF_8_close_env(struct SN_env* z); + +extern int german_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_GERMAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_hungarian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_hungarian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_hungarian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_hungarian.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_HUNGARIAN_H +#define STEM_UTF_8_HUNGARIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* hungarian_UTF_8_create_env(void); +extern void hungarian_UTF_8_close_env(struct SN_env* z); + +extern int hungarian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_HUNGARIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_italian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_italian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_italian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_italian.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ITALIAN_H +#define STEM_UTF_8_ITALIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* italian_UTF_8_create_env(void); +extern void italian_UTF_8_close_env(struct SN_env* z); + +extern int italian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ITALIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_norwegian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_norwegian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_norwegian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_norwegian.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_NORWEGIAN_H +#define STEM_UTF_8_NORWEGIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* norwegian_UTF_8_create_env(void); +extern void norwegian_UTF_8_close_env(struct SN_env* z); + +extern int norwegian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_NORWEGIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_porter.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_porter.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_porter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_porter.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_PORTER_H +#define STEM_UTF_8_PORTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* porter_UTF_8_create_env(void); +extern void porter_UTF_8_close_env(struct SN_env* z); + +extern int porter_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_PORTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_portuguese.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_portuguese.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_portuguese.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_portuguese.h 2020-12-12 17:06:43.265348271 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_PORTUGUESE_H +#define STEM_UTF_8_PORTUGUESE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* portuguese_UTF_8_create_env(void); +extern void portuguese_UTF_8_close_env(struct SN_env* z); + +extern int portuguese_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_PORTUGUESE_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_romanian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_romanian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_romanian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_romanian.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ROMANIAN_H +#define STEM_UTF_8_ROMANIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* romanian_UTF_8_create_env(void); +extern void romanian_UTF_8_close_env(struct SN_env* z); + +extern int romanian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ROMANIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_russian.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_russian.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_russian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_russian.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_RUSSIAN_H +#define STEM_UTF_8_RUSSIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* russian_UTF_8_create_env(void); +extern void russian_UTF_8_close_env(struct SN_env* z); + +extern int russian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_RUSSIAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_spanish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_spanish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_spanish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_spanish.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_SPANISH_H +#define STEM_UTF_8_SPANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* spanish_UTF_8_create_env(void); +extern void spanish_UTF_8_close_env(struct SN_env* z); + +extern int spanish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_SPANISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_swedish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_swedish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_swedish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_swedish.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_SWEDISH_H +#define STEM_UTF_8_SWEDISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* swedish_UTF_8_create_env(void); +extern void swedish_UTF_8_close_env(struct SN_env* z); + +extern int swedish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_SWEDISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_turkish.h postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_turkish.h --- postgresql-hll-2.14_old/include/include/snowball/libstemmer/stem_UTF_8_turkish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/snowball/libstemmer/stem_UTF_8_turkish.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_TURKISH_H +#define STEM_UTF_8_TURKISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* turkish_UTF_8_create_env(void); +extern void turkish_UTF_8_close_env(struct SN_env* z); + +extern int turkish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_TURKISH_H */ diff -uprN postgresql-hll-2.14_old/include/include/ssl/gs_openssl_client.h postgresql-hll-2.14/include/include/ssl/gs_openssl_client.h --- postgresql-hll-2.14_old/include/include/ssl/gs_openssl_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/ssl/gs_openssl_client.h 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_openssl_client.h + * initialize the ssl system of client which is based on the openssl library + * + * IDENTIFICATION + * src/include/ssl/gs_openssl_client.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef GS_openssl_CLIENT +#define GS_openssl_CLIENT + +#include "cipher.h" + +#include "openssl/ossl_typ.h" +#include "openssl/err.h" +#include "openssl/err.h" +#include "openssl/ssl.h" +#include "openssl/bio.h" +#include "openssl/conf.h" +#include "openssl/crypto.h" +#include "openssl/evp.h" +#include "openssl/rand.h" + +#define OPENSSL_CLI_EXCEPTTION (-4) +#define OPENSSL_CLI_BAD_SOCKET (-3) +#define OPENSSL_CLI_EAGAIN (-2) + +typedef struct gs_openssl_client* gs_openssl_cli; + +extern void gs_openssl_cli_init_system(void); + +/* create a gs_openssl_client object */ +extern gs_openssl_cli gs_openssl_cli_create(void); +/* destroy a gs_openssl_client object */ +extern void gs_openssl_cli_destroy(gs_openssl_cli cli); +/* set the certificate file names before loading them */ +extern void gs_openssl_cli_setfiles( + gs_openssl_cli cli, const char* ssl_dir, const char* rootcert, const char* client_key, const char* clientcert); + +/* the main function of initialize the ssl system of client using openssl */ +extern int gs_openssl_cli_initialize_SSL(gs_openssl_cli cli, int sock_id); + +/* read && write interface */ +extern int gs_openssl_cli_read(gs_openssl_cli cli, char* obuf, int maxlen); +extern int gs_openssl_cli_write(gs_openssl_cli cli, const char* buf, int len); + +#ifdef ENABLE_UT +extern int ossl_init_client_ssl_passwd(SSL_CTX* pstContext, const char* cert_file_dir, GS_UCHAR* cipher_passwd); +extern const char* ossl_error_message(void); +#endif /* ENABLE_UT */ + +#endif /* GS_openssl_CLIENT */ diff -uprN postgresql-hll-2.14_old/include/include/ssl/openssl_etcd.cnf postgresql-hll-2.14/include/include/ssl/openssl_etcd.cnf --- postgresql-hll-2.14_old/include/include/ssl/openssl_etcd.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/ssl/openssl_etcd.cnf 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,72 @@ +# etcd OpenSSL configuration file. +SAN = "IP:127.0.0.1" +dir = . + +[ ca ] +default_ca = etcd_ca + +[ etcd_ca ] +certs = $dir/certs +certificate = $dir/certs/etcd-ca.crt +crl = $dir/crl.pem +crl_dir = $dir/crl +crlnumber = $dir/crlnumber +database = $dir/index.txt +email_in_dn = no +new_certs_dir = $dir/newcerts +private_key = $dir/private/etcd-ca.key +serial = $dir/serial +RANDFILE = $dir/private/.rand +name_opt = ca_default +cert_opt = ca_default +default_days = 7300 +default_crl_days = 30 +default_md = sha512 +preserve = no +policy = policy_etcd + +[ policy_etcd ] +organizationName = optional +commonName = supplied + +[ req ] +default_bits = 4096 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca +string_mask = utf8only +req_extensions = etcd_client + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = US +countryName_min = 2 +countryName_max = 2 +commonName = Common Name (FQDN) +0.organizationName = Organization Name (eg, company) +0.organizationName_default = etcd-ca + +[ req_attributes ] + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = keyCertSign,cRLSign +subjectKeyIdentifier = hash + +[ etcd_client ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth +keyUsage = digitalSignature, keyEncipherment + +[ etcd_peer ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth, serverAuth +keyUsage = digitalSignature, keyEncipherment +subjectAltName = ${ENV::SAN} + +[ etcd_server ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth, serverAuth +keyUsage = digitalSignature, keyEncipherment +subjectAltName = ${ENV::SAN} diff -uprN postgresql-hll-2.14_old/include/include/ssl/openssl_grpc.cnf postgresql-hll-2.14/include/include/ssl/openssl_grpc.cnf --- postgresql-hll-2.14_old/include/include/ssl/openssl_grpc.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/ssl/openssl_grpc.cnf 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,147 @@ +# +# grpc OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +# x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +default_days = 7300 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha512 # which md to use. +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString. +# utf8only: only UTF8Strings. +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings +# so use this option with caution! +string_mask = nombstr + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (eg, YOUR name) +commonName_default = grpc +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ alt_names ] +DNS.1 = localhost + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = cRLSign, keyCertSign +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer +subjectAltName = @alt_names + +[ server ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer +subjectAltName = @alt_names + +[ client ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer +subjectAltName = @alt_names diff -uprN postgresql-hll-2.14_old/include/include/ssl/openssl_gsql.cnf postgresql-hll-2.14/include/include/ssl/openssl_gsql.cnf --- postgresql-hll-2.14_old/include/include/ssl/openssl_gsql.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/ssl/openssl_gsql.cnf 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,139 @@ +# +# gsql OpenSSL configuration file. +# This is mostly being used for generation of certificate requests. +# + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +# x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +default_days = 7300 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha256 # use SHA-256 by default +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (e.g. server FQDN or YOUR name) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = cRLSign, keyCertSign +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer + +[ server ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer + +[ client ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer diff -uprN postgresql-hll-2.14_old/include/include/ssl/openssl_om.cnf postgresql-hll-2.14/include/include/ssl/openssl_om.cnf --- postgresql-hll-2.14_old/include/include/ssl/openssl_om.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/ssl/openssl_om.cnf 2020-12-12 17:06:43.266348283 +0800 @@ -0,0 +1,352 @@ +# +# OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +# This definition stops the following lines choking if HOME isn't +# defined. +HOME = . +RANDFILE = $ENV::HOME/.rnd + +# Extra OBJECT IDENTIFIER info: +#oid_file = $ENV::HOME/.oid +oid_section = new_oids + +# To use this configuration file with the "-extfile" option of the +# "openssl x509" utility, name here the section containing the +# X.509v3 extensions to use: +# extensions = +# (Alternatively, use a configuration file that has only +# X.509v3 extensions in its main [= default] section.) + +[ new_oids ] + +# We can add new OIDs in here for use by 'ca', 'req' and 'ts'. +# Add a simple OID like this: +# testoid1=1.2.3.4 +# Or use config file substitution like this: +# testoid2=${testoid1}.5.6 + +# Policies used by the TSA examples. +tsa_policy1 = 1.2.3.4.1 +tsa_policy2 = 1.2.3.4.5.6 +tsa_policy3 = 1.2.3.4.5.7 + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several ctificates with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key +RANDFILE = $dir/private/.rand # private random number file + +x509_extensions = usr_cert # The extentions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +# Extension copying option: use with caution. +# copy_extensions = copy + +# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs +# so this is commented out by default to leave a V1 CRL. +# crlnumber must also be commented out to leave a V1 CRL. +# crl_extensions = crl_ext + +default_days = 365 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha256 # use SHA-256 by default +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_md = sha256 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extentions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +# req_extensions = v3_req # The extensions to add to a certificate request + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = XX +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +#stateOrProvinceName_default = Default Province + +localityName = Locality Name (eg, city) +localityName_default = Default City + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Default Company Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (eg, your name or your server\'s hostname) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ usr_cert ] + +# These extensions are added when 'ca' signs a request. + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This is required for TSA certificates. +# extendedKeyUsage = critical,timeStamping + +[ v3_req ] + +# Extensions to add to a certificate request + +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +[ v3_ca ] + + +# Extensions for a typical CA + + +# PKIX recommendation. + +subjectKeyIdentifier=hash + +authorityKeyIdentifier=keyid:always,issuer + +# This is what PKIX recommends but some broken software chokes on critical +# extensions. +#basicConstraints = critical,CA:true +# So we do this instead. +basicConstraints = CA:TRUE + +# Key usage: this is typical for a CA certificate. However since it will +# prevent it being used as an test self-signed certificate it is best +# left out by default. +# keyUsage = cRLSign, keyCertSign + +# Some might want this also +# nsCertType = sslCA, emailCA + +# Include email address in subject alt name: another PKIX recommendation +# subjectAltName=email:copy +# Copy issuer details +# issuerAltName=issuer:copy + +# DER hex encoding of an extension: beware experts only! +# obj=DER:02:03 +# Where 'obj' is a standard or added object +# You can even override a supported extension: +# basicConstraints= critical, DER:30:03:01:01:FF + +[ crl_ext ] + +# CRL extensions. +# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. + +# issuerAltName=issuer:copy +authorityKeyIdentifier=keyid:always + +[ proxy_cert_ext ] +# These extensions should be added when creating a proxy certificate + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This really needs to be in place for it to be a proxy certificate. +proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo + +#################################################################### +[ tsa ] + +default_tsa = tsa_config1 # the default TSA section + +[ tsa_config1 ] + +# These are used by the TSA reply generation only. +dir = ./demoCA # TSA root directory +serial = $dir/tsaserial # The current serial number (mandatory) +crypto_device = builtin # OpenSSL engine to use for signing +signer_cert = $dir/tsacert.pem # The TSA signing certificate + # (optional) +certs = $dir/cacert.pem # Certificate chain to include in reply + # (optional) +signer_key = $dir/private/tsakey.pem # The TSA private key (optional) + +default_policy = tsa_policy1 # Policy if request did not specify it + # (optional) +other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) +digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory) +accuracy = secs:1, millisecs:500, microsecs:100 # (optional) +clock_precision_digits = 0 # number of digits after dot. (optional) +ordering = yes # Is ordering defined for timestamps? + # (optional, default: no) +tsa_name = yes # Must the TSA name be included in the reply? + # (optional, default: no) +ess_cert_id_chain = no # Must the ESS cert id chain be included? + # (optional, default: no) diff -uprN postgresql-hll-2.14_old/include/include/stamp-h postgresql-hll-2.14/include/include/stamp-h --- postgresql-hll-2.14_old/include/include/stamp-h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/stamp-h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1 @@ + diff -uprN postgresql-hll-2.14_old/include/include/storage/backendid.h postgresql-hll-2.14/include/include/storage/backendid.h --- postgresql-hll-2.14_old/include/include/storage/backendid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/backendid.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * backendid.h + * POSTGRES backend id communication definitions + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/backendid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BACKENDID_H +#define BACKENDID_H + +/* ---------------- + * -cim 8/17/90 + * ---------------- + */ +typedef int BackendId; /* unique currently active backend identifier */ + +#define InvalidBackendId (-1) + +#endif /* BACKENDID_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/barrier.h postgresql-hll-2.14/include/include/storage/barrier.h --- postgresql-hll-2.14_old/include/include/storage/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/barrier.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * Memory barrier operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/barrier.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BARRIER_H +#define BARRIER_H + +#include "storage/s_lock.h" + +/* + * A compiler barrier need not (and preferably should not) emit any actual + * machine code, but must act as an optimization fence: the compiler must not + * reorder loads or stores to main memory around the barrier. However, the + * CPU may still reorder loads or stores at runtime, if the architecture's + * memory model permits this. + * + * A memory barrier must act as a compiler barrier, and in addition must + * guarantee that all loads and stores issued prior to the barrier are + * completed before any loads or stores issued after the barrier. Unless + * loads and stores are totally ordered (which is not the case on most + * architectures) this requires issuing some sort of memory fencing + * instruction. + * + * A read barrier must act as a compiler barrier, and in addition must + * guarantee that any loads issued prior to the barrier are completed before + * any loads issued after the barrier. Similarly, a write barrier acts + * as a compiler barrier, and also orders stores. Read and write barriers + * are thus weaker than a full memory barrier, but stronger than a compiler + * barrier. In practice, on machines with strong memory ordering, read and + * write barriers may require nothing more than a compiler barrier. + * + * For an introduction to using memory barriers within the PostgreSQL backend, + * see src/backend/storage/lmgr/README.barrier + */ + +#if defined(DISABLE_BARRIERS) + +/* + * Fall through to the spinlock-based implementation. + */ +#elif defined(__INTEL_COMPILER) + +/* + * icc defines __GNUC__, but doesn't support gcc's inline asm syntax + */ +#define pg_memory_barrier() _mm_mfence() +#define pg_compiler_barrier() __memory_barrier() +#elif defined(__GNUC__) + +/* This works on any architecture, since it's only talking to GCC itself. */ +#define pg_compiler_barrier() __asm__ __volatile__("" : : : "memory") + +#if defined(__i386__) + +/* + * i386 does not allow loads to be reordered with other loads, or stores to be + * reordered with other stores, but a load can be performed before a subsequent + * store. + * + * "lock; addl" has worked for longer than "mfence". + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__x86_64__) /* 64 bit x86 */ + +/* + * x86_64 has similar ordering characteristics to i386. + * + * Technically, some x86-ish chips support uncached memory access and/or + * special instructions that are weakly ordered. In those cases we'd need + * the read and write barriers to be lfence and sfence. But since we don't + * do those things, a compiler barrier should be enough. + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%rsp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__aarch64__) +/* + * aarch64 architecure memory barrier. In order to minimize the impact on + * performance, here use dmb memory barrier. + */ +#define pg_memory_barrier_dsb(opt) __asm__ __volatile__("DMB " #opt::: "memory") + +#ifndef ENABLE_THREAD_CHECK + +#define pg_memory_barrier() pg_memory_barrier_dsb(ish) +#define pg_read_barrier() pg_memory_barrier_dsb(ishld) +#define pg_write_barrier() pg_memory_barrier_dsb(ishst) + +#else + +#include "tsan_annotation.h" + +#define pg_memory_barrier() do { \ + TsAnnotateReadBarrier(); \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ish); \ +} while (0) + +#define pg_read_barrier() do { \ + TsAnnotateReadBarrier(); \ + pg_memory_barrier_dsb(ishld); \ +} while (0) + +#define pg_write_barrier() do { \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ishst); \ +} while (0) + +#endif +#elif defined(__ia64__) || defined(__ia64) + +/* + * Itanium is weakly ordered, so read and write barriers require a full + * fence. + */ +#define pg_memory_barrier() __asm__ __volatile__("mf" : : : "memory") +#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) + +/* + * lwsync orders loads with respect to each other, and similarly with stores. + * But a load can be performed before a subsequent store, so sync must be used + * for a full memory barrier. + */ +#define pg_memory_barrier() __asm__ __volatile__("sync" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#elif defined(__alpha) || defined(__alpha__) /* Alpha */ + +/* + * Unlike all other known architectures, Alpha allows dependent reads to be + * reordered, but we don't currently find it necessary to provide a conditional + * read barrier to cover that case. We might need to add that later. + */ +#define pg_memory_barrier() __asm__ __volatile__("mb" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("rmb" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("wmb" : : : "memory") +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) + +/* + * If we're on GCC 4.1.0 or higher, we should be able to get a memory + * barrier out of this compiler built-in. But we prefer to rely on our + * own definitions where possible, and use this only as a fallback. + */ +#define pg_memory_barrier() __sync_synchronize() +#endif +#elif defined(__ia64__) || defined(__ia64) + +#define pg_compiler_barrier() _Asm_sched_fence() +#define pg_memory_barrier() _Asm_mf() +#elif defined(WIN32_ONLY_COMPILER) + +/* Should work on both MSVC and Borland. */ +#include +#pragma intrinsic(_ReadWriteBarrier) +#define pg_compiler_barrier() _ReadWriteBarrier() +#define pg_memory_barrier() MemoryBarrier() +#endif + +/* + * If we have no memory barrier implementation for this architecture, we + * fall back to acquiring and releasing a spinlock. This might, in turn, + * fall back to the semaphore-based spinlock implementation, which will be + * amazingly slow. + * + * It's not self-evident that every possible legal implementation of a + * spinlock acquire-and-release would be equivalent to a full memory barrier. + * For example, I'm not sure that Itanium's acq and rel add up to a full + * fence. But all of our actual implementations seem OK in this regard. + */ +#if !defined(pg_memory_barrier) +#define pg_memory_barrier(x) \ + do { \ + S_LOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + S_UNLOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + } while (0) +#endif + +/* + * If read or write barriers are undefined, we upgrade them to full memory + * barriers. + * + * If a compiler barrier is unavailable, you probably don't want a full + * memory barrier instead, so if you have a use case for a compiler barrier, + * you'd better use #ifdef. + */ +#if !defined(pg_read_barrier) +#define pg_read_barrier() pg_memory_barrier() +#endif +#if !defined(pg_write_barrier) +#define pg_write_barrier() pg_memory_barrier() +#endif + +#endif /* BARRIER_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/block.h postgresql-hll-2.14/include/include/storage/block.h --- postgresql-hll-2.14_old/include/include/storage/block.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/block.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,126 @@ +/* ------------------------------------------------------------------------- + * + * block.h + * POSTGRES disk block definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/block.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BLOCK_H +#define BLOCK_H + +/* + * BlockNumber: + * + * each data file (heap or index) is divided into postgres disk blocks + * (which may be thought of as the unit of i/o -- a postgres buffer + * contains exactly one disk block). the blocks are numbered + * sequentially, 0 to 0xFFFFFFFE. + * + * InvalidBlockNumber is the same thing as P_NEW in buf.h. + * + * the access methods, the buffer manager and the storage manager are + * more or less the only pieces of code that should be accessing disk + * blocks directly. + */ +typedef uint32 BlockNumber; + +#define InvalidBlockNumber ((BlockNumber)0xFFFFFFFF) + +#define MaxBlockNumber ((BlockNumber)0xFFFFFFFE) + +typedef double RelPageType; + +/* + * BlockId: + * + * this is a storage type for BlockNumber. in other words, this type + * is used for on-disk structures (e.g., in HeapTupleData) whereas + * BlockNumber is the type on which calculations are performed (e.g., + * in access method code). + * + * there doesn't appear to be any reason to have separate types except + * for the fact that BlockIds can be SHORTALIGN'd (and therefore any + * structures that contains them, such as ItemPointerData, can also be + * SHORTALIGN'd). this is an important consideration for reducing the + * space requirements of the line pointer (ItemIdData) array on each + * page and the header of each heap or index tuple, so it doesn't seem + * wise to change this without good reason. + */ +typedef struct BlockIdData { + uint16 bi_hi; + uint16 bi_lo; +} BlockIdData; + +typedef BlockIdData* BlockId; /* block identifier */ + +/* Data structure for Algorithm S from Knuth 3.4.2 */ +typedef struct { + BlockNumber N; /* number of blocks, known in advance */ + int n; /* desired sample size */ + BlockNumber t; /* current block number */ + int m; /* blocks selected so far */ +} BlockSamplerData; + +typedef BlockSamplerData* BlockSampler; + +void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks, int samplesize); +bool BlockSampler_HasMore(BlockSampler bs); +BlockNumber BlockSampler_Next(BlockSampler bs); + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * BlockNumberIsValid + * True iff blockNumber is valid. + */ +#define BlockNumberIsValid(blockNumber) ((bool)((BlockNumber)(blockNumber) != InvalidBlockNumber)) + +/* + * BlockIdIsValid + * True iff the block identifier is valid. + */ +#define BlockIdIsValid(blockId) ((bool)PointerIsValid(blockId)) + +/* + * BlockIdSet + * Sets a block identifier to the specified value. + */ +#define BlockIdSet(blockId, blockNumber) \ + (AssertMacro(PointerIsValid(blockId)), \ + (blockId)->bi_hi = (blockNumber) >> 16, \ + (blockId)->bi_lo = (blockNumber)&0xffff) + +/* + * BlockIdCopy + * Copy a block identifier. + */ +#define BlockIdCopy(toBlockId, fromBlockId) \ + (AssertMacro(PointerIsValid(toBlockId)), \ + AssertMacro(PointerIsValid(fromBlockId)), \ + (toBlockId)->bi_hi = (fromBlockId)->bi_hi, \ + (toBlockId)->bi_lo = (fromBlockId)->bi_lo) + +/* + * BlockIdEquals + * Check for block number equality. + */ +#define BlockIdEquals(blockId1, blockId2) \ + ((blockId1)->bi_hi == (blockId2)->bi_hi && (blockId1)->bi_lo == (blockId2)->bi_lo) + +/* + * BlockIdGetBlockNumber + * Retrieve the block number from a block identifier. + */ +#define BlockIdGetBlockNumber(blockId) \ + (AssertMacro(BlockIdIsValid(blockId)), (BlockNumber)(((blockId)->bi_hi << 16) | ((uint16)(blockId)->bi_lo))) + +#endif /* BLOCK_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/buffile.h postgresql-hll-2.14/include/include/storage/buffile.h --- postgresql-hll-2.14_old/include/include/storage/buffile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/buffile.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * buffile.h + * Management of large buffered files, primarily temporary files. + * + * The BufFile routines provide a partial replacement for stdio atop + * virtual file descriptors managed by fd.c. Currently they only support + * buffered access to a virtual file, without any of stdio's formatting + * features. That's enough for immediate needs, but the set of facilities + * could be expanded if necessary. + * + * BufFile also supports working with temporary files that exceed the OS + * file size limit and/or the largest offset representable in an int. + * It might be better to split that out as a separately accessible module, + * but currently we have no need for oversize temp files without buffered + * access. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buffile.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef BUFFILE_H +#define BUFFILE_H + +/* BufFile is an opaque type whose details are not known outside buffile.c. */ + +typedef struct BufFile BufFile; + +/* + * prototypes for functions in buffile.c + */ + +extern BufFile* BufFileCreateTemp(bool interXact); +extern void BufFileClose(BufFile* file); +extern size_t BufFileRead(BufFile* file, void* ptr, size_t size); +extern size_t BufFileWrite(BufFile* file, void* ptr, size_t size); +extern int BufFileSeek(BufFile* file, int fileno, off_t offset, int whence); +extern void BufFileTell(BufFile* file, int* fileno, off_t* offset); +extern int BufFileSeekBlock(BufFile* file, long blknum); + +#endif /* BUFFILE_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/buf.h postgresql-hll-2.14/include/include/storage/buf.h --- postgresql-hll-2.14_old/include/include/storage/buf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/buf.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * buf.h + * Basic buffer manager data types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buf.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUF_H +#define BUF_H + +/* + * Buffer identifiers. + * + * Zero is invalid, positive is the index of a shared buffer (1..NBuffers), + * negative is the index of a local buffer (-1 .. -NLocBuffer). + */ +typedef int Buffer; + +#define InvalidBuffer 0 + +/* + * BufferIsInvalid + * True iff the buffer is invalid. + */ +#define BufferIsInvalid(buffer) ((buffer) == InvalidBuffer) + +/* + * BufferIsLocal + * True iff the buffer is local (not visible to other backends). + */ +#define BufferIsLocal(buffer) ((buffer) < 0) + +/* + * Buffer access strategy objects. + */ +typedef struct BufferAccessStrategyData* BufferAccessStrategy; + +#endif /* BUF_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/buf_internals.h postgresql-hll-2.14/include/include/storage/buf_internals.h --- postgresql-hll-2.14_old/include/include/storage/buf_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/buf_internals.h 2020-12-12 17:06:43.267348296 +0800 @@ -0,0 +1,325 @@ +/* ------------------------------------------------------------------------- + * + * buf_internals.h + * Internal definitions for buffer manager and the buffer replacement + * strategy. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buf_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFMGR_INTERNALS_H +#define BUFMGR_INTERNALS_H + +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/latch.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "storage/smgr.h" +#include "storage/spin.h" +#include "utils/relcache.h" +#include "utils/atomic.h" +#include "access/xlogdefs.h" + +/* + * Buffer state is a single 32-bit variable where following data is combined. + * + * - 18 bits refcount + * - 4 bits usage count + * - 10 bits of flags + * + * Combining these values allows to perform some operations without locking + * the buffer header, by modifying them together with a CAS loop. + * + * The definition of buffer state components is below. + */ +#define BUF_REFCOUNT_ONE 1 +#define BUF_REFCOUNT_MASK ((1U << 18) - 1) +#define BUF_USAGECOUNT_MASK 0x003C0000U +#define BUF_USAGECOUNT_ONE (1U << 18) +#define BUF_USAGECOUNT_SHIFT 18 +#define BUF_FLAG_MASK 0xFFC00000U + +/* Get refcount and usagecount from buffer state */ +#define BUF_STATE_GET_REFCOUNT(state) ((state)&BUF_REFCOUNT_MASK) +#define BUF_STATE_GET_USAGECOUNT(state) (((state)&BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) + +/* + * Flags for buffer descriptors + * + * Note: TAG_VALID essentially means that there is a buffer hashtable + * entry associated with the buffer's tag. + */ +#define BM_LOCKED (1U << 22) /* buffer header is locked */ +#define BM_DIRTY (1U << 23) /* data needs writing */ +#define BM_VALID (1U << 24) /* data is valid */ +#define BM_TAG_VALID (1U << 25) /* tag is assigned */ +#define BM_IO_IN_PROGRESS (1U << 26) /* read or write in progress */ +#define BM_IO_ERROR (1U << 27) /* previous I/O failed */ +#define BM_JUST_DIRTIED (1U << 28) /* dirtied since write started */ +#define BM_PIN_COUNT_WAITER (1U << 29) /* have waiter for sole pin */ +#define BM_CHECKPOINT_NEEDED (1U << 30) /* must write for checkpoint */ +#define BM_PERMANENT \ + (1U << 31) /* permanent relation (not \ + * unlogged, or init fork) ) */ +/* + * The maximum allowed value of usage_count represents a tradeoff between + * accuracy and speed of the clock-sweep buffer management algorithm. A + * large value (comparable to NBuffers) would approximate LRU semantics. + * But it can take as many as BM_MAX_USAGE_COUNT+1 complete cycles of + * clock sweeps to find a free buffer, so in practice we don't want the + * value to be very large. + */ +#define BM_MAX_USAGE_COUNT 5 + +/* + * Buffer tag identifies which disk block the buffer contains. + * + * Note: the BufferTag data must be sufficient to determine where to write the + * block, without reference to pg_class or pg_tablespace entries. It's + * possible that the backend flushing the buffer doesn't even believe the + * relation is visible yet (its xact may have started before the xact that + * created the rel). The storage manager must be able to cope anyway. + * + * Note: if there's any pad bytes in the struct, INIT_BUFFERTAG will have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct buftag { + RelFileNode rnode; /* physical relation identifier */ + ForkNumber forkNum; + BlockNumber blockNum; /* blknum relative to begin of reln */ +} BufferTag; + +typedef struct buftagnohbkt { + RelFileNodeOld rnode; /* physical relation identifier */ + ForkNumber forkNum; + BlockNumber blockNum; /* blknum relative to begin of reln */ +} BufferTagFirstVer; + + +#define CLEAR_BUFFERTAG(a) \ + ((a).rnode.spcNode = InvalidOid, \ + (a).rnode.dbNode = InvalidOid, \ + (a).rnode.relNode = InvalidOid, \ + (a).rnode.bucketNode = -1,\ + (a).forkNum = InvalidForkNumber, \ + (a).blockNum = InvalidBlockNumber) + +#define INIT_BUFFERTAG(a, xx_rnode, xx_forkNum, xx_blockNum) \ + ((a).rnode = (xx_rnode), (a).forkNum = (xx_forkNum), (a).blockNum = (xx_blockNum)) + +#define BUFFERTAGS_EQUAL(a, b) \ + (RelFileNodeEquals((a).rnode, (b).rnode) && (a).blockNum == (b).blockNum && (a).forkNum == (b).forkNum) + +#define BUFFERTAGS_PTR_EQUAL(a, b) \ + (RelFileNodeEquals((a)->rnode, (b)->rnode) && (a)->blockNum == (b)->blockNum && (a)->forkNum == (b)->forkNum) + +#define BUFFERTAGS_PTR_SET(a, b) \ + ((a)->rnode.spcNode = (b)->rnode.spcNode, \ + (a)->rnode.dbNode = (b)->rnode.dbNode, \ + (a)->rnode.relNode = (b)->rnode.relNode, \ + (a)->rnode.bucketNode = (b)->rnode.bucketNode,\ + (a)->forkNum = (b)->forkNum, \ + (a)->blockNum = (b)->blockNum) + +/* + * The shared buffer mapping table is partitioned to reduce contention. + * To determine which partition lock a given tag requires, compute the tag's + * hash code with BufTableHashCode(), then apply BufMappingPartitionLock(). + * NB: NUM_BUFFER_PARTITIONS must be a power of 2! + */ +#define BufTableHashPartition(hashcode) ((hashcode) % NUM_BUFFER_PARTITIONS) +#define BufMappingPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstBufMappingLock + \ + BufTableHashPartition(hashcode)].lock) +#define BufMappingPartitionLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstBufMappingLock + (i)].lock) + +/* + * BufferDesc -- shared descriptor/state data for a single shared buffer. + * + * Note: Buffer header lock (BM_LOCKED flag) must be held to examine or change + * the tag, state or wait_backend_pid fields. In general, buffer header lock + * is a spinlock which is combined with flags, refcount and usagecount into + * single atomic variable. This layout allow us to do some operations in a + * single atomic operation, without actually acquiring and releasing spinlock; + * for instance, increase or decrease refcount. buf_id field never changes + * after initialization, so does not need locking. The LWLock can take care + * of itself. The buffer header lock is *not* used to control access to the + * data in the buffer! + * + * It's assumed that nobody changes the state field while buffer header lock + * is held. Thus buffer header lock holder can do complex updates of the + * state variable in single write, simultaneously with lock release (cleaning + * BM_LOCKED flag). On the other hand, updating of state without holding + * buffer header lock is restricted to CAS, which insure that BM_LOCKED flag + * is not set. Atomic increment/decrement, OR/AND etc. are not allowed. + * + * An exception is that if we have the buffer pinned, its tag can't change + * underneath us, so we can examine the tag without locking the buffer header. + * Also, in places we do one-time reads of the flags without bothering to + * lock the buffer header; this is generally for situations where we don't + * expect the flag bit being tested to be changing. + * + * We can't physically remove items from a disk page if another backend has + * the buffer pinned. Hence, a backend may need to wait for all other pins + * to go away. This is signaled by storing its own PID into + * wait_backend_pid and setting flag bit BM_PIN_COUNT_WAITER. At present, + * there can be only one such waiter per buffer. + * + * We use this same struct for local buffer headers, but the lock fields + * are not used and not all of the flag bits are useful either. + */ +typedef struct BufferDesc { + BufferTag tag; /* ID of page contained in buffer */ + /* state of the tag, containing flags, refcount and usagecount */ + pg_atomic_uint32 state; + + int buf_id; /* buffer's index number (from 0) */ + + ThreadId wait_backend_pid; /* backend PID of pin-count waiter */ + + LWLock* io_in_progress_lock; /* to wait for I/O to complete */ + LWLock* content_lock; /* to lock access to buffer contents */ + + /* below fields are used for incremental checkpoint */ + pg_atomic_uint64 rec_lsn; /* recovery LSN */ + volatile uint64 dirty_queue_loc; /* actual loc of dirty page queue */ +} BufferDesc; + +/* + * Concurrent access to buffer headers has proven to be more efficient if + * they're cache line aligned. So we force the start of the BufferDescriptors + * array to be on a cache line boundary and force the elements to be cache + * line sized. + * + * XXX: As this is primarily matters in highly concurrent workloads which + * probably all are 64bit these days, and the space wastage would be a bit + * more noticeable on 32bit systems, we don't force the stride to be cache + * line sized on those. If somebody does actual performance testing, we can + * reevaluate. + * + * Note that local buffer descriptors aren't forced to be aligned - as there's + * no concurrent access to those it's unlikely to be beneficial. + * + * We use 64bit as the cache line size here, because that's the most common + * size. Making it bigger would be a waste of memory. Even if running on a + * platform with either 32 or 128 byte line sizes, it's good to align to + * boundaries and avoid false sharing. + */ +#define BUFFERDESC_PAD_TO_SIZE (SIZEOF_VOID_P == 8 ? 128 : 1) + +typedef union BufferDescPadded { + BufferDesc bufferdesc; + char pad[BUFFERDESC_PAD_TO_SIZE]; +} BufferDescPadded; + +#define GetBufferDescriptor(id) (&t_thrd.storage_cxt.BufferDescriptors[(id)].bufferdesc) +#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1) + +/* + * Functions for acquiring/releasing a shared buffer header's spinlock. Do + * not apply these to local buffers! + */ +extern uint32 LockBufHdr(BufferDesc* desc); + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#else +#define TsAnnotateHappensBefore(addr) +#endif + +#define UnlockBufHdr(desc, s) \ + do { \ + /* ENABLE_THREAD_CHECK only, release semantic */ \ + TsAnnotateHappensBefore(&desc->state); \ + pg_write_barrier(); \ + pg_atomic_write_u32(&(desc)->state, (s) & (~BM_LOCKED)); \ + } while (0) + +extern bool retryLockBufHdr(BufferDesc* desc, uint32* buf_state); +/* + * The PendingWriteback & WritebackContext structure are used to keep + * information about pending flush requests to be issued to the OS. + */ +typedef struct PendingWriteback { + /* could store different types of pending flushes here */ + BufferTag tag; +} PendingWriteback; + +/* struct forward declared in bufmgr.h */ +typedef struct WritebackContext { + /* pointer to the max number of writeback requests to coalesce */ + int* max_pending; + + /* current number of pending writeback requests */ + int nr_pending; + + /* pending requests */ + PendingWriteback pending_writebacks[WRITEBACK_MAX_PENDING_FLUSHES]; +} WritebackContext; + +/* in bufmgr.c */ + +/* + * Structure to sort buffers per file on checkpoints. + * + * This structure is allocated per buffer in shared memory, so it should be + * kept as small as possible. + */ +typedef struct CkptSortItem { + Oid tsId; + Oid relNode; + int2 bucketNode; + ForkNumber forkNum; + BlockNumber blockNum; + int buf_id; +} CkptSortItem; + +/* + * Internal routines: only called by bufmgr + */ +/* bufmgr.c */ +extern void WritebackContextInit(WritebackContext* context, int* max_pending); +extern void IssuePendingWritebacks(WritebackContext* context); +extern void ScheduleBufferTagForWriteback(WritebackContext* context, BufferTag* tag); + +/* freelist.c */ +extern BufferDesc *StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state); + +extern void StrategyFreeBuffer(volatile BufferDesc* buf); +extern bool StrategyRejectBuffer(BufferAccessStrategy strategy, BufferDesc* buf); + +extern int StrategySyncStart(uint32* complete_passes, uint32* num_buf_alloc); +extern void StrategyNotifyBgWriter(int bgwprocno); + +extern Size StrategyShmemSize(void); +extern void StrategyInitialize(bool init); + +/* buf_table.c */ +extern Size BufTableShmemSize(int size); +extern void InitBufTable(int size); +extern uint32 BufTableHashCode(BufferTag* tagPtr); +extern int BufTableLookup(BufferTag* tagPtr, uint32 hashcode); +extern int BufTableInsert(BufferTag* tagPtr, uint32 hashcode, int buf_id); +extern void BufTableDelete(BufferTag* tagPtr, uint32 hashcode); + +/* localbuf.c */ +extern void LocalPrefetchBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum); +extern BufferDesc* LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool* foundPtr); +extern void MarkLocalBufferDirty(Buffer buffer); +extern void DropRelFileNodeLocalBuffers(const RelFileNode& rnode, ForkNumber forkNum, BlockNumber firstDelBlock); +extern void DropRelFileNodeAllLocalBuffers(const RelFileNode& rnode); +extern void AtEOXact_LocalBuffers(bool isCommit); +extern void update_wait_lockid(LWLock* lock); +extern void FlushBuffer(void* buf, SMgrRelation reln, ReadBufferMethod flushmethod = WITH_NORMAL_CACHE); +extern void LocalBufferFlushAllBuffer(); +#endif /* BUFMGR_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/bufmgr.h postgresql-hll-2.14/include/include/storage/bufmgr.h --- postgresql-hll-2.14_old/include/include/storage/bufmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/bufmgr.h 2020-12-12 17:06:43.268348309 +0800 @@ -0,0 +1,310 @@ +/* ------------------------------------------------------------------------- + * + * bufmgr.h + * POSTGRES buffer manager definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/bufmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFMGR_H +#define BUFMGR_H + +#include "knl/knl_variable.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/bufpage.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +typedef void* Block; + +typedef struct PrivateRefCountEntry { + Buffer buffer; + int32 refcount; +} PrivateRefCountEntry; + +/* 64 bytes, about the size of a cache line on common systems */ +#define REFCOUNT_ARRAY_ENTRIES 8 + +/* Possible arguments for GetAccessStrategy() */ +typedef enum BufferAccessStrategyType { + BAS_NORMAL, /* Normal random access */ + BAS_BULKREAD, /* Large read-only scan (hint bit updates are + * ok) */ + BAS_BULKWRITE, /* Large multi-block write (e.g. COPY IN) */ + BAS_VACUUM /* VACUUM */ +} BufferAccessStrategyType; + +/* Possible modes for ReadBufferExtended() */ +typedef enum { + RBM_NORMAL, /* Normal read */ + RBM_ZERO_AND_LOCK, /* Don't read from disk, caller will + * initialize */ + RBM_ZERO_AND_CLEANUP_LOCK, /* Like RBM_ZERO_AND_LOCK, but locks the page + * in "cleanup" mode */ + RBM_ZERO_ON_ERROR, /* Read, but return an all-zeros page on error */ + RBM_NORMAL_NO_LOG, /* Don't log page as invalid during WAL + * replay; otherwise same as RBM_NORMAL */ + RBM_FOR_REMOTE /* Like RBM_NORMAL, but not remote read again when PageIsVerified failed. */ +} ReadBufferMode; + +typedef enum +{ + WITH_NORMAL_CACHE = 0, /* Normal read */ + WITH_LOCAL_CACHE, /* Add for batchredo , the same as localbuf */ + WITH_OUT_CACHE /* without buf, read or write directly */ +} ReadBufferMethod; + +/* + * Private (non-shared) state for managing a ring of shared buffers to re-use. + * This is currently the only kind of BufferAccessStrategy object, but someday + * we might have more kinds. + */ +typedef struct BufferAccessStrategyData { + /* Overall strategy type */ + BufferAccessStrategyType btype; + /* Number of elements in buffers[] array */ + int ring_size; + + /* + * Index of the "current" slot in the ring, ie, the one most recently + * returned by GetBufferFromRing. + */ + int current; + + /* Number of elements to flush behind current */ + int flush_rate; + + /* + * True if the buffer just returned by StrategyGetBuffer had been in the + * ring already. + */ + bool current_was_in_ring; + + /* + * Array of buffer numbers. InvalidBuffer (that is, zero) indicates we + * have not yet selected a buffer for this ring slot. For allocation + * simplicity this is palloc'd together with the fixed fields of the + * struct. + */ + Buffer buffers[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE SIZE ARRAY */ +} BufferAccessStrategyData; + +/* forward declared, to avoid having to expose buf_internals.h here */ +struct WritebackContext; + +/* special block number for ReadBuffer() */ +#define P_NEW InvalidBlockNumber /* grow the file to get a new page */ + +/* Bits in SyncOneBuffer's return value */ +#define BUF_WRITTEN 0x01 +#define BUF_REUSABLE 0x02 +#define BUF_SKIPPED 0x04 + +/* + * Buffer content lock modes (mode argument for LockBuffer()) + */ +#define BUFFER_LOCK_UNLOCK 0 +#define BUFFER_LOCK_SHARE 1 +#define BUFFER_LOCK_EXCLUSIVE 2 + +#define MAX_PREFETCH_REQSIZ 512 +#define MAX_BACKWRITE_REQSIZ 64 + +/* + * BufferIsPinned + * True iff the buffer is pinned (also checks for valid buffer number). + * + * NOTE: what we check here is that *this* backend holds a pin on + * the buffer. We do not care whether some other backend does. + */ +#define BufferIsPinned(bufnum) \ + (!BufferIsValid(bufnum) ? false \ + : BufferIsLocal(bufnum) ? (u_sess->storage_cxt.LocalRefCount[-(bufnum)-1] > 0) \ + : (GetPrivateRefCount(bufnum) > 0)) + +/* + * These routines are beaten on quite heavily, hence the macroization. + */ + +/* + * BufferIsValid + * True iff the given buffer number is valid (either as a shared + * or local buffer). + * + * Note: For a long time this was defined the same as BufferIsPinned, + * that is it would say False if you didn't hold a pin on the buffer. + * I believe this was bogus and served only to mask logic errors. + * Code should always know whether it has a buffer reference, + * independently of the pin state. + * + * Note: For a further long time this was not quite the inverse of the + * BufferIsInvalid() macro, in that it also did sanity checks to verify + * that the buffer number was in range. Most likely, this macro was + * originally intended only to be used in assertions, but its use has + * since expanded quite a bit, and the overhead of making those checks + * even in non-assert-enabled builds can be significant. Thus, we've + * now demoted the range checks to assertions within the macro itself. + */ +#define BufferIsValid(bufnum) \ + (AssertMacro((bufnum) <= g_instance.attr.attr_storage.NBuffers && (bufnum) >= -u_sess->storage_cxt.NLocBuffer), \ + (bufnum) != InvalidBuffer) + +/* + * BufferGetBlock + * Returns a reference to a disk page image associated with a buffer. + * + * Note: + * Assumes buffer is valid. + */ +#define BufferGetBlock(buffer) \ + (AssertMacro(BufferIsValid(buffer)), \ + BufferIsLocal(buffer) ? u_sess->storage_cxt.LocalBufferBlockPointers[-(buffer)-1] \ + : (Block)(t_thrd.storage_cxt.BufferBlocks + ((Size)((uint)(buffer)-1)) * BLCKSZ)) + +/* + * BufferGetPageSize + * Returns the page size within a buffer. + * + * Notes: + * Assumes buffer is valid. + * + * The buffer can be a raw disk block and need not contain a valid + * (formatted) disk page. + */ +/* XXX should dig out of buffer descriptor */ +#define BufferGetPageSize(buffer) (AssertMacro(BufferIsValid(buffer)), (Size)BLCKSZ) + +/* + * BufferGetPage + * Returns the page associated with a buffer. + */ +#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer)) + +/* Note: these two macros only work on shared buffers, not local ones! */ +#define BufHdrGetBlock(bufHdr) ((Block)(t_thrd.storage_cxt.BufferBlocks + ((Size)(uint32)(bufHdr)->buf_id) * BLCKSZ)) +#define BufferGetLSN(bufHdr) (PageGetLSN(BufHdrGetBlock(bufHdr))) + +/* Note: this macro only works on local buffers, not shared ones! */ +#define LocalBufHdrGetBlock(bufHdr) u_sess->storage_cxt.LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] +#define LocalBufGetLSN(bufHdr) (PageGetLSN(LocalBufHdrGetBlock(bufHdr))) + +/* + * prototypes for functions in bufmgr.c + */ +extern void PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum); +extern void PageRangePrefetch( + Relation reln, ForkNumber forkNum, BlockNumber blockNum, int32 n, uint32 flags, uint32 col); +extern void PageListPrefetch( + Relation reln, ForkNumber forkNum, BlockNumber* blockList, int32 n, uint32 flags, uint32 col); +extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); +extern Buffer ReadBufferExtended( + Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy); +extern Buffer ReadBufferWithoutRelcache( + const RelFileNode& rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy); +extern Buffer ReadBufferForRemote(const RelFileNode& rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, + BufferAccessStrategy strategy, bool* hit); + +extern void ReleaseBuffer(Buffer buffer); +extern void UnlockReleaseBuffer(Buffer buffer); +extern void MarkBufferDirty(Buffer buffer); +extern void IncrBufferRefCount(Buffer buffer); +extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum); + +extern void InitBufferPool(void); +extern void InitBufferPoolAccess(void); +extern void InitBufferPoolBackend(void); +extern void AtEOXact_Buffers(bool isCommit); +extern void PrintBufferLeakWarning(Buffer buffer); +extern void CheckPointBuffers(int flags, bool doFullCheckpoint); +extern BlockNumber BufferGetBlockNumber(Buffer buffer); +extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum, bool estimate = false); +extern void FlushRelationBuffers(Relation rel, HTAB *hashtbl = NULL); +extern void FlushDatabaseBuffers(Oid dbid); + +extern void DropRelFileNodeBuffers(const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber firstDelBlock); +extern void DropTempRelFileNodeAllBuffers(const RelFileNodeBackend& rnode); + + +#define DROP_BUFFER_USING_HASH_DEL_REL_NUM_THRESHOLD 20 +#define IS_DEL_RELS_OVER_HASH_THRESHOLD(ndelrels) ((ndelrels) > DROP_BUFFER_USING_HASH_DEL_REL_NUM_THRESHOLD) + +extern void DropRelFileNodeAllBuffersUsingHash(HTAB* relfilenode_hashtbl); +extern void DropRelFileNodeAllBuffersUsingScan(RelFileNode* rnode, int rnode_len); + +extern void DropDatabaseBuffers(Oid dbid); + +extern BlockNumber PartitionGetNumberOfBlocksInFork(Relation relation, Partition partition, ForkNumber forkNum); + +#define RelationGetNumberOfBlocks(reln) RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM) + +/* + * PartitionGetNumberOfBlocks + * Determines the current number of pages in the partition. + */ +#define PartitionGetNumberOfBlocks(rel, part) PartitionGetNumberOfBlocksInFork(rel, part, MAIN_FORKNUM) + +extern bool BufferIsPermanent(Buffer buffer); + +extern void RemoteReadBlock(const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber blockNum, char* buf); + +#ifdef NOT_USED +extern void PrintPinnedBufs(void); +#endif +extern Size BufferShmemSize(void); +extern void BufferGetTag(Buffer buffer, RelFileNode* rnode, ForkNumber* forknum, BlockNumber* blknum); + +void PinBuffer_Locked(volatile BufferDesc* buf); +void UnpinBuffer(BufferDesc* buf, bool fixOwner); +extern void MarkBufferDirtyHint(Buffer buffer, bool buffer_std); +extern void FlushOneBuffer(Buffer buffer); +extern void UnlockBuffers(void); +extern void LockBuffer(Buffer buffer, int mode); +extern bool ConditionalLockBuffer(Buffer buffer); +extern void LockBufferForCleanup(Buffer buffer); +extern bool ConditionalLockBufferForCleanup(Buffer buffer); +extern bool HoldingBufferPinThatDelaysRecovery(void); +extern void AsyncUnpinBuffer(volatile void* bufHdr, bool forgetBuffer); +extern void AsyncCompltrPinBuffer(volatile void* bufHdr); +extern void AsyncCompltrUnpinBuffer(volatile void* bufHdr); +extern void TerminateBufferIO(volatile BufferDesc* buf, bool clear_dirty, uint32 set_flag_bits); + +extern void AsyncTerminateBufferIO(void* bufHdr, bool clear_dirty, uint32 set_flag_bits); +extern void AsyncAbortBufferIO(void* buf, bool isForInput); +extern void AsyncTerminateBufferIOByVacuum(void* buffer); +extern void AsyncAbortBufferIOByVacuum(void* buffer); +extern void AbortBufferIO(void); +extern void AbortBufferIO_common(BufferDesc* buf, bool isForInput); +extern void AbortAsyncListIO(void); +extern void CheckIOState(volatile void* bufHdr); +extern void BufmgrCommit(void); +extern bool BgBufferSync(struct WritebackContext* wb_context); +extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer); +extern void AtProcExit_Buffers(int code, Datum arg); +extern void AtProcExit_LocalBuffers(void); + +/* in freelist.c */ +extern BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype); +extern void FreeAccessStrategy(BufferAccessStrategy strategy); + +/* dirty page manager */ +extern int ckpt_buforder_comparator(const void* pa, const void* pb); +extern void clean_buf_need_flush_flag(BufferDesc *buf_desc); +extern void ckpt_flush_dirty_page(int thread_id, WritebackContext wb_context); + +extern uint32 SyncOneBuffer( + int buf_id, bool skip_recently_used, WritebackContext* flush_context, bool get_candition_lock = false); + +extern Buffer ReadBuffer_common_for_direct(RelFileNode rnode, char relpersistence, ForkNumber forkNum, + BlockNumber blockNum, ReadBufferMode mode); +extern Buffer ReadBuffer_common_for_localbuf(RelFileNode rnode, char relpersistence, ForkNumber forkNum, + BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy, bool *hit); +extern void DropRelFileNodeShareBuffers(RelFileNode node, ForkNumber forkNum, BlockNumber firstDelBlock); +extern int GetThreadBufferLeakNum(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/bufpage.h postgresql-hll-2.14/include/include/storage/bufpage.h --- postgresql-hll-2.14_old/include/include/storage/bufpage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/bufpage.h 2020-12-12 17:06:43.268348309 +0800 @@ -0,0 +1,487 @@ +/* ------------------------------------------------------------------------- + * + * bufpage.h + * Standard POSTGRES buffer page definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/bufpage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFPAGE_H +#define BUFPAGE_H + +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/item.h" +#include "storage/off.h" +#include "storage/buf.h" + +/* + * A postgres disk page is an abstraction layered on top of a postgres + * disk block (which is simply a unit of i/o, see block.h). + * + * specifically, while a disk block can be unformatted, a postgres + * disk page is always a slotted page of the form: + * + * +----------------+---------------------------------+ + * | PageHeaderData | linp1 linp2 linp3 ... | + * +-----------+----+---------------------------------+ + * | ... linpN | | + * +-----------+--------------------------------------+ + * | ^ pd_lower | + * | | + * | v pd_upper | + * +-------------+------------------------------------+ + * | | tupleN ... | + * +-------------+------------------+-----------------+ + * | ... tuple3 tuple2 tuple1 | "special space" | + * +--------------------------------+-----------------+ + * ^ pd_special + * + * a page is full when nothing can be added between pd_lower and + * pd_upper. + * + * all blocks written out by an access method must be disk pages. + * + * EXCEPTIONS: + * + * obviously, a page is not formatted before it is initialized by + * a call to PageInit. + * + * NOTES: + * + * linp1..N form an ItemId array. ItemPointers point into this array + * rather than pointing directly to a tuple. Note that OffsetNumbers + * conventionally start at 1, not 0. + * + * tuple1..N are added "backwards" on the page. because a tuple's + * ItemPointer points to its ItemId entry rather than its actual + * byte-offset position, tuples can be physically shuffled on a page + * whenever the need arises. + * + * AM-generic per-page information is kept in PageHeaderData. + * + * AM-specific per-page data (if any) is kept in the area marked "special + * space"; each AM has an "opaque" structure defined somewhere that is + * stored as the page trailer. an access method should always + * initialize its pages with PageInit and then set its own opaque + * fields. + */ + +typedef Pointer Page; + +/* + * location (byte offset) within a page. + * + * note that this is actually limited to 2^15 because we have limited + * ItemIdData.lp_off and ItemIdData.lp_len to 15 bits (see itemid.h). + */ +typedef uint16 LocationIndex; + +/* + * For historical reasons, the 64-bit LSN value is stored as two 32-bit + * values. + */ +typedef struct { + uint32 xlogid; /* high bits */ + uint32 xrecoff; /* low bits */ +} PageXLogRecPtr; + +/* + * disk page organization + * + * space management information generic to any page + * + * pd_lsn - identifies xlog record for last change to this page. + * pd_checksum - page checksum, if set. + * pd_flags - flag bits. + * pd_lower - offset to start of free space. + * pd_upper - offset to end of free space. + * pd_special - offset to start of special space. + * pd_pagesize_version - size in bytes and page layout version number. + * pd_prune_xid - oldest XID among potentially prunable tuples on page. + * + * The LSN is used by the buffer manager to enforce the basic rule of WAL: + * "thou shalt write xlog before data". A dirty buffer cannot be dumped + * to disk until xlog has been flushed at least as far as the page's LSN. + * + * pd_checksum stores the page checksum, if it has been set for this page; + * zero is a valid value for a checksum. If a checksum is not in use then + * we leave the field unset. This will typically mean the field is zero + * though non-zero values may also be present if databases have been + * pg_upgraded from releases prior to 9.3, when the same byte offset was + * used to store the current timelineid when the page was last updated. + * Note that there is no indication on a page as to whether the checksum + * is valid or not, a deliberate design choice which avoids the problem + * of relying on the page contents to decide whether to verify it. Hence + * there are no flag bits relating to checksums. + * + * pd_prune_xid is a hint field that helps determine whether pruning will be + * useful. It is currently unused in index pages. + * + * The page version number and page size are packed together into a single + * uint16 field. This is for historical reasons: before PostgreSQL 7.3, + * there was no concept of a page version number, and doing it this way + * lets us pretend that pre-7.3 databases have page version number zero. + * We constrain page sizes to be multiples of 256, leaving the low eight + * bits available for a version number. + * + * Minimum possible page size is perhaps 64B to fit page header, opaque space + * and a minimal tuple; of course, in reality you want it much bigger, so + * the constraint on pagesize mod 256 is not an important restriction. + * On the high end, we can only support pages up to 32KB because lp_off/lp_len + * are 15 bits. + */ +typedef struct { + /* XXX LSN is member of *any* block, not only page-organized ones */ + PageXLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog + * record for last change to this page */ + uint16 pd_checksum; /* checksum */ + uint16 pd_flags; /* flag bits, see below */ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + uint16 pd_pagesize_version; + ShortTransactionId pd_prune_xid; /* oldest prunable XID, or zero if none */ + ItemIdData pd_linp[FLEXIBLE_ARRAY_MEMBER]; /* beginning of line pointer array */ +} PageHeaderData; + +typedef PageHeaderData* PageHeader; + +/* + * HeapPageHeaderData -- data that stored at the begin of each new version heap page. + * pd_xid_base - base value for transaction IDs on page + * pd_multi_base - base value for multixact IDs on page + * + */ +typedef struct { + /* XXX LSN is member of *any* block, not only page-organized ones */ + PageXLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog + * record for last change to this page */ + uint16 pd_checksum; /* checksum */ + uint16 pd_flags; /* flag bits, see below */ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + uint16 pd_pagesize_version; + ShortTransactionId pd_prune_xid; /* oldest prunable XID, or zero if none */ + TransactionId pd_xid_base; /* base value for transaction IDs on page */ + TransactionId pd_multi_base; /* base value for multixact IDs on page */ + ItemIdData pd_linp[FLEXIBLE_ARRAY_MEMBER]; /* beginning of line pointer array */ +} HeapPageHeaderData; + +typedef HeapPageHeaderData* HeapPageHeader; + +#define GetPageHeaderSize(page) (PageIs8BXidHeapVersion(page) ? SizeOfHeapPageHeaderData : SizeOfPageHeaderData) + +#define SizeOfHeapPageUpgradeData MAXALIGN(offsetof(HeapPageHeaderData, pd_linp) - offsetof(PageHeaderData, pd_linp)) + +#define PageXLogRecPtrGet(val) \ + ((uint64) (val).xlogid << 32 | (val).xrecoff) +#define PageXLogRecPtrSet(ptr, lsn) \ + ((ptr).xlogid = (uint32) ((lsn) >> 32), (ptr).xrecoff = (uint32) (lsn)) + +/* + * pd_flags contains the following flag bits. Undefined bits are initialized + * to zero and may be used in the future. + * + * PD_HAS_FREE_LINES is set if there are any LP_UNUSED line pointers before + * pd_lower. This should be considered a hint rather than the truth, since + * changes to it are not WAL-logged. + * + * PD_PAGE_FULL is set if an UPDATE doesn't find enough free space in the + * page for its new tuple version; this suggests that a prune is needed. + * Again, this is just a hint. + */ +#define PD_HAS_FREE_LINES 0x0001 /* are there any unused line pointers? */ +#define PD_PAGE_FULL 0x0002 /* not enough free space for new tuple? */ +#define PD_ALL_VISIBLE 0x0004 /* all tuples on page are visible to everyone */ +#define PD_COMPRESSED_PAGE 0x0008 /* compressed page flag */ +#define PD_LOGICAL_PAGE 0x0010 /* logical page flag used by bulkload or copy */ +#define PD_ENCRYPT_PAGE 0x0020 /* is a encryt cluster */ +#define PD_CHECKSUM_FNV1A 0x0040 /* page checksum using FNV-1a hash */ +#define PD_JUST_AFTER_FPW 0x0080 /* page just after redo full page write */ + +#define PD_VALID_FLAG_BITS 0x00FF /* OR of all valid pd_flags bits */ + +/* + * Page layout version number 0 is for pre-7.3 Postgres releases. + * Releases 7.3 and 7.4 use 1, denoting a new HeapTupleHeader layout. + * Release 8.0 uses 2; it changed the HeapTupleHeader layout again. + * Release 8.1 uses 3; it redefined HeapTupleHeader infomask bits. + * Release 8.3 uses 4; it changed the HeapTupleHeader layout again, and + * added the pd_flags field (by stealing some bits from pd_tli), + * as well as adding the pd_prune_xid field (which enlarges the header). + * + * As of Release 9.3, the checksum version must also be considered when + * handling pages. + */ +#define PG_HEAP_PAGE_LAYOUT_VERSION 6 +#define PG_COMM_PAGE_LAYOUT_VERSION 5 +#define PG_PAGE_4B_LAYOUT_VERSION 4 + +/* ---------------------------------------------------------------- + * page support macros + * ---------------------------------------------------------------- + */ + +/* + * PageIsValid + * True iff page is valid. + */ +#define PageIsValid(page) PointerIsValid(page) + +/* + * line pointer(s) do not count as part of header + */ +#define SizeOfPageHeaderData (offsetof(PageHeaderData, pd_linp)) +#define SizeOfHeapPageHeaderData (offsetof(HeapPageHeaderData, pd_linp)) + +/* + * PageIsEmpty + * returns true iff no itemid has been allocated on the page + */ +#define PageIsEmpty(page) (((PageHeader)(page))->pd_lower <= GetPageHeaderSize(page)) + +/* + * PageIsNew + * returns true iff page has not been initialized (by PageInit) + */ +#define PageIsNew(page) (((PageHeader)(page))->pd_upper == 0) + +/* + * PageGetItemId + * Returns an item identifier of a page. + */ +#define PageGetItemId(page, offsetNumber) \ + (PageIs8BXidHeapVersion(page) ? ((ItemId)(&((HeapPageHeader)(page))->pd_linp[(offsetNumber)-1])) \ + : ((ItemId)(&((PageHeader)(page))->pd_linp[(offsetNumber)-1]))) + +/* + * PageGetContents + * To be used in case the page does not contain item pointers. + * + * Note: prior to 8.3 this was not guaranteed to yield a MAXALIGN'd result. + * Now it is. Beware of old code that might think the offset to the contents + * is just SizeOfPageHeaderData rather than MAXALIGN(SizeOfPageHeaderData). + */ +#define PageGetContents(page) ((char*)(page) + MAXALIGN(GetPageHeaderSize(page))) + +/* ---------------- + * macros to access page size info + * ---------------- + */ + +/* + * PageSizeIsValid + * True iff the page size is valid. + */ +#define PageSizeIsValid(pageSize) ((pageSize) == BLCKSZ) + +/* + * PageGetPageSize + * Returns the page size of a page. + * + * this can only be called on a formatted page (unlike + * BufferGetPageSize, which can be called on an unformatted page). + * however, it can be called on a page that is not stored in a buffer. + */ +#define PageGetPageSize(page) ((Size)(((PageHeader)(page))->pd_pagesize_version & (uint16)0xFF00)) + +/* + * PageGetPageLayoutVersion + * Returns the page layout version of a page. + */ +#define PageGetPageLayoutVersion(page) (((PageHeader)(page))->pd_pagesize_version & 0x00FF) + +#define PageIs8BXidVersion(page) (PageGetPageLayoutVersion(page) == PG_COMM_PAGE_LAYOUT_VERSION) + +#define PageIs4BXidVersion(page) (PageGetPageLayoutVersion(page) == PG_PAGE_4B_LAYOUT_VERSION) + +#define PageIs8BXidHeapVersion(page) (PageGetPageLayoutVersion(page) == PG_HEAP_PAGE_LAYOUT_VERSION) + +/* + * PageSetPageSizeAndVersion + * Sets the page size and page layout version number of a page. + * + * We could support setting these two values separately, but there's + * no real need for it at the moment. + */ +#define PageSetPageSizeAndVersion(page, size, version) \ + (AssertMacro(((size)&0xFF00) == (size)), \ + AssertMacro(((version)&0x00FF) == (version)), \ + ((PageHeader)(page))->pd_pagesize_version = (size) | (version)) + +/* ---------------- + * page special data macros + * ---------------- + */ +/* + * PageGetSpecialSize + * Returns size of special space on a page. + */ +#define PageGetSpecialSize(page) ((uint16)(PageGetPageSize(page) - ((PageHeader)(page))->pd_special)) + +/* + * PageGetSpecialPointer + * Returns pointer to special space on a page. + */ +#define PageGetSpecialPointer(page) \ + (AssertMacro(PageIsValid(page)), (char*)((char*)(page) + ((PageHeader)(page))->pd_special)) + +#define BTPageGetSpecial(page) \ + (PageIs8BXidVersion(page) \ + ? (AssertMacro(((PageHeader)page)->pd_special == BLCKSZ - MAXALIGN(sizeof(BTPageOpaqueData))), \ + (BTPageOpaque)((Pointer)page + BLCKSZ - MAXALIGN(sizeof(BTPageOpaqueData)))) \ + : NULL) + +#define HeapPageSetPruneXid(page, xid) \ + (((PageHeader)(page))->pd_prune_xid = NormalTransactionIdToShort( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, (xid))) + +#define HeapPageGetPruneXid(page) \ + (ShortTransactionIdToNormal( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, ((PageHeader)(page))->pd_prune_xid)) + +/* + * PageGetItem + * Retrieves an item on the given page. + * + * Note: + * This does not change the status of any of the resources passed. + * The semantics may change in the future. + */ +#define PageGetItem(page, itemId) \ + (AssertMacro(PageIsValid(page)), \ + AssertMacro(ItemIdHasStorage(itemId)), \ + (Item)(((char*)(page)) + ItemIdGetOffset(itemId))) + +/* + * PageGetMaxOffsetNumber + * Returns the maximum offset number used by the given page. + * Since offset numbers are 1-based, this is also the number + * of items on the page. + * + * NOTE: if the page is not initialized (pd_lower == 0), we must + * return zero to ensure sane behavior. Accept double evaluation + * of the argument so that we can ensure this. + */ +inline OffsetNumber PageGetMaxOffsetNumber(char* pghr) +{ + OffsetNumber maxoff = InvalidOffsetNumber; + Size pageheadersize = GetPageHeaderSize(pghr); + + if (((PageHeader)pghr)->pd_lower <= pageheadersize) + maxoff = 0; + else + maxoff = (((PageHeader)pghr)->pd_lower - pageheadersize) / sizeof(ItemIdData); + + return maxoff; +} + +/* + * Additional macros for access to page headers + */ +#define PageGetLSN(page) (((uint64)((PageHeader)(page))->pd_lsn.xlogid << 32) | ((PageHeader)(page))->pd_lsn.xrecoff) +#define PageSetLSNInternal(page, lsn) \ + (((PageHeader)(page))->pd_lsn.xlogid = (uint32)((lsn) >> 32), ((PageHeader)(page))->pd_lsn.xrecoff = (uint32)(lsn)) + +inline void PageSetLSN(Page page, XLogRecPtr LSN, bool check = true) +{ + if (check && XLByteLT(LSN, PageGetLSN(page))) { + elog(PANIC, "The Page's LSN[%lu] bigger than want set LSN [%lu]", PageGetLSN(page), LSN); + } + PageSetLSNInternal(page, LSN); +} + +#define PageHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags & PD_HAS_FREE_LINES) +#define PageSetHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags |= PD_HAS_FREE_LINES) +#define PageClearHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags &= ~PD_HAS_FREE_LINES) + +#define PageIsFull(page) (((PageHeader)(page))->pd_flags & PD_PAGE_FULL) +#define PageSetFull(page) (((PageHeader)(page))->pd_flags |= PD_PAGE_FULL) +#define PageClearFull(page) (((PageHeader)(page))->pd_flags &= ~PD_PAGE_FULL) + +#define PageIsAllVisible(page) (((PageHeader)(page))->pd_flags & PD_ALL_VISIBLE) +#define PageSetAllVisible(page) (((PageHeader)(page))->pd_flags |= PD_ALL_VISIBLE) +#define PageClearAllVisible(page) (((PageHeader)(page))->pd_flags &= ~PD_ALL_VISIBLE) + +#define PageIsCompressed(page) ((bool)(((PageHeader)(page))->pd_flags & PD_COMPRESSED_PAGE)) +#define PageSetCompressed(page) (((PageHeader)(page))->pd_flags |= PD_COMPRESSED_PAGE) +#define PageClearCompressed(page) (((PageHeader)(page))->pd_flags &= ~PD_COMPRESSED_PAGE) + +#define PageIsLogical(page) (((PageHeader)(page))->pd_flags & PD_LOGICAL_PAGE) +#define PageSetLogical(page) (((PageHeader)(page))->pd_flags |= PD_LOGICAL_PAGE) +#define PageClearLogical(page) (((PageHeader)(page))->pd_flags &= ~PD_LOGICAL_PAGE) + +#define PageIsEncrypt(page) (((PageHeader)(page))->pd_flags & PD_ENCRYPT_PAGE) +#define PageSetEncrypt(page) (((PageHeader)(page))->pd_flags |= PD_ENCRYPT_PAGE) +#define PageClearEncrypt(page) (((PageHeader)(page))->pd_flags &= ~PD_ENCRYPT_PAGE) + +#define PageIsChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags & PD_CHECKSUM_FNV1A) +#define PageSetChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags |= PD_CHECKSUM_FNV1A) +#define PageClearChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags &= ~PD_CHECKSUM_FNV1A) + +#define PageIsJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags & PD_JUST_AFTER_FPW) +#define PageSetJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags |= PD_JUST_AFTER_FPW) +#define PageClearJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags &= ~PD_JUST_AFTER_FPW) + +#define PageIsPrunable(page, oldestxmin) \ + (AssertMacro(TransactionIdIsNormal(oldestxmin)), \ + TransactionIdIsValid(HeapPageGetPruneXid(page)) && \ + TransactionIdPrecedes(HeapPageGetPruneXid(page), oldestxmin)) +#define PageSetPrunable(page, xid) \ + do { \ + Assert(TransactionIdIsNormal(xid)); \ + if (!TransactionIdIsValid(HeapPageGetPruneXid(page)) || TransactionIdPrecedes(xid, HeapPageGetPruneXid(page))) \ + HeapPageSetPruneXid(page, xid); \ + } while (0) +#define PageClearPrunable(page) (HeapPageSetPruneXid(page, InvalidTransactionId)) + +#define GlobalTempRelationPageIsNotInitialized(rel, page) \ + ((rel)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP && PageIsNew(page)) + +const int PAGE_INDEX_CAN_TUPLE_DELETE = 2; + +/* ---------------------------------------------------------------- + * extern declarations + * --------------------------TerminateBufferIO-------------------------------------- + */ +typedef struct { + int offsetindex; /* linp array index */ + int itemoff; /* page offset of item data */ + Size alignedlen; /* MAXALIGN(item data len) */ + ItemIdData olditemid; /* used only in PageIndexMultiDelete */ +} itemIdSortData; +typedef itemIdSortData* itemIdSort; + +extern void PageInit(Page page, Size pageSize, Size specialSize, bool isheap = false); +extern bool PageIsVerified(Page page, BlockNumber blkno); +extern bool PageHeaderIsValid(PageHeader page); +extern OffsetNumber PageAddItem( + Page page, Item item, Size size, OffsetNumber offsetNumber, bool overwrite, bool is_heap); +extern Page PageGetTempPage(Page page); +extern Page PageGetTempPageCopy(Page page); +extern Page PageGetTempPageCopySpecial(Page page, bool isbtree); +extern void PageRestoreTempPage(Page tempPage, Page oldPage); +extern void PageRepairFragmentation(Page page); +extern Size PageGetFreeSpace(Page page); +extern Size PageGetExactFreeSpace(Page page); +extern Size PageGetHeapFreeSpace(Page page); +extern void PageIndexTupleDelete(Page page, OffsetNumber offset); +extern void PageIndexMultiDelete(Page page, OffsetNumber* itemnos, int nitems); + +extern void PageReinitWithDict(Page page, Size dictSize); +extern bool PageFreeDict(Page page); +extern char* PageDataEncryptIfNeed(Page page); +extern void PageDataDecryptIfNeed(Page page); +extern char* PageSetChecksumCopy(Page page, BlockNumber blkno); +extern void PageSetChecksumInplace(Page page, BlockNumber blkno); + +extern void PageLocalUpgrade(Page page); +extern void DumpPageInfo(Page page, XLogRecPtr newLsn); +#endif /* BUFPAGE_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/cache_mgr.h postgresql-hll-2.14/include/include/storage/cache_mgr.h --- postgresql-hll-2.14_old/include/include/storage/cache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cache_mgr.h 2020-12-12 17:06:43.268348309 +0800 @@ -0,0 +1,288 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cache_mgr.h + * routines to support common cache + * + * + * + * IDENTIFICATION + * src/include/storage/cache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CacheMgr_H +#define CacheMgr_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "utils/hsearch.h" +#include "storage/lwlock.h" +#include "storage/spin.h" + +// CU Cache Pool sizes. +// + +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * (int)(!!(condition))])) + +typedef int CacheSlotId_t; + +// Cache Block flags +typedef unsigned char CacheFlags; // Modified by CUSlotDesc and CacheMgr +const unsigned char CACHE_BLOCK_NEW = 0x00; // Slot is not on any list +const unsigned char CACHE_BLOCK_VALID = 0x01; // In Hashtable and contains valid data +const unsigned char CACHE_BLOCK_INFREE = 0x02; // slot is in free state +const unsigned char CACHE_BLOCK_FREE = 0x04; // Slot is on the free list +const unsigned char CACHE_BLOCK_IOBUSY = 0x08; // Slot buf r/w in progress +const unsigned char CACHE_BLOCK_ERROR = 0x10; // Slot buf error + +// Special Slot Index values +const int CACHE_BLOCK_INVALID_IDX = -1; // Invalid index -end of this list +const int CACHE_BLOCK_NO_LIST = -2; // Invalid index -not in any list + +#define IsValidCacheSlotID(x) ((x) != CACHE_BLOCK_INVALID_IDX) + +// Max usage count for CLOCK cache strategy +const uint16 CACHE_BLOCK_MAX_USAGE = 5; + +/* common buffer cache function for cu cache and orc cache */ +#define MAX_CACHE_TAG_LEN (32) + +typedef enum CacheType { + /*only used for init cache type, for not exist type*/ + CACHE_TYPE_NONE = 0, + + /* data block*/ + CACHE_COlUMN_DATA, + CACHE_ORC_DATA, + CACHE_OBS_DATA, + CACHE_CARBONDATA_DATA, + + /*index block*/ + CACHE_ORC_INDEX, + + /* metadata block */ + CACHE_CARBONDATA_METADATA +} CacheType; + +typedef enum MgrCacheType { + /* cache manager type */ + MGR_CACHE_TYPE_DATA, + MGR_CACHE_TYPE_INDEX +} MgrCacheType; + +typedef struct CacheTag { + /*cu + RelFileNode rnode; + int32 col_id; + int32 cu_id; + uint32 padding; + CUPointer offset; + */ + + /*orc compress data + RelFileNode m_rnode; + int32 m_fileId; + uint64 m_offset; + uint64 m_length; + */ + + /*orc meta data + RelFileNode fileNode; + int32 fileID; + uint32 stripeID; + uint32 columnID; + */ + + /*common cache tag*/ + int32 type; + char key[MAX_CACHE_TAG_LEN]; +} CacheTag; + +typedef struct CacheDesc { + uint16 m_usage_count; + uint16 m_ring_count; + uint32 m_refcount; + CacheTag m_cache_tag; + + CacheSlotId_t m_slot_id; + CacheSlotId_t m_freeNext; + + /* Light wight lock: i/o busy lock */ + LWLock *m_iobusy_lock; + + /* + * Light wight lock: used for CU + * compress/uncompress busy lock. + * If there are two or more threads + * read one CU where is uncompressing + * we must wait. + */ + LWLock *m_compress_lock; + + /*The data size in the one slot.*/ + int m_datablock_size; + + /* + * This flag used in OBS foreign table. + * Think a scenario, a file located on OBS and + * touched by DW through foreign table. We + * cached part of this file. Now two threads + * want to read this cache and find the file + * eTag has changed, it is this session's responsibility + * to update this cache. There must be a machnism + * to avoid two or more threads to update it concurrently. + * If thread find m_refreshing is yes. It not wait for + * updating finish, but read data from OBS directly. + */ + bool m_refreshing; + + slock_t m_slot_hdr_lock; + + CacheFlags m_flag; +} CacheDesc; + +int CacheMgrNumLocks(int64 cache_size, uint32 each_block_size); +int64 CacheMgrCalcSizeByType(MgrCacheType type); + +/* + * This class is to manage Common Cache. + */ +class CacheMgr : public BaseObject { +public: + CacheMgr(){}; + ~CacheMgr(){}; + void Init(int64 cache_size, uint32 each_block_size, MgrCacheType type, uint32 each_slot_length); + void Destroy(void); + + /* operate cache block */ + void InitCacheBlockTag(CacheTag* cacheTag, int32 type, const void* key, int32 length) const; + CacheSlotId_t FindCacheBlock(CacheTag* cacheTag, bool first_enter_block); + void InvalidateCacheBlock(CacheTag* cacheTag); + void DeleteCacheBlock(CacheTag* cacheTag); + CacheSlotId_t ReserveCacheBlock(CacheTag* cacheTag, int size, bool& hasFound); + bool ReserveCacheBlockWithSlotId(CacheSlotId_t slotId); + bool ReserveCstoreCacheBlockWithSlotId(CacheSlotId_t slotId); + void* GetCacheBlock(CacheSlotId_t slotId); + const CacheTag* GetCacheBlockTag(CacheSlotId_t slotId, uint32* refcount) const; + bool PinCacheBlock(CacheSlotId_t slotId); + void UnPinCacheBlock(CacheSlotId_t slotId); + + /* Manage I/O busy cache block */ + bool IsIOBusy(CacheSlotId_t cuSlotId); + bool WaitIO(CacheSlotId_t slotId); + void CompleteIO(CacheSlotId_t cuSlotId); + + /* async lock used by adio */ + bool LockHeldByMe(CacheSlotId_t slotId); + void LockOwn(CacheSlotId_t slotId); + void LockDisown(CacheSlotId_t slotId); + + /* compress lock */ + void AcquireCompressLock(CacheSlotId_t slotId); + void RealeseCompressLock(CacheSlotId_t slotId); + + /* ring strategy, not used for now */ + void IncRingCount(CacheSlotId_t slotId); + void DecRingCount(CacheSlotId_t slotId); + + /* memory operate */ + int64 GetCurrentMemSize(); + void ReleaseCacheMem(int size); + bool CompressLockHeldByMe(CacheSlotId_t slotId); + + /* IO lock */ + void AcquireCstoreIOLock(CacheSlotId_t slotId); + void RealeseCstoreIOLock(CacheSlotId_t slotId); + bool CstoreIOLockHeldByMe(CacheSlotId_t slotId); + void AdjustCacheMem(CacheSlotId_t slotId, int oldSize, int newSize); + + /* error handle */ + void AbortCacheBlock(CacheSlotId_t slotId); + void SetCacheBlockErrorState(CacheSlotId_t slotId); + + /* + * get the number of cache slot now used. + * notice the number will be bigger and bigger, not smaller. + */ + int GetUsedCacheSlotNum(void) + { + return m_CaccheSlotMax; + } + void CopyCacheBlockTag(CacheSlotId_t slotId, CacheTag* outTag); + + char* m_CacheSlots; + +#ifndef ENABLE_UT +private: +#endif // ENABLE_UT + + uint32 GetHashCode(CacheTag* cacheTag); + + /* internal block operate */ + CacheSlotId_t EvictCacheBlock(int size, int retryNum); + CacheSlotId_t GetFreeCacheBlock(int size); + + /* memory operate */ + bool ReserveCacheMem(int size); + void FreeCacheBlockMem(CacheSlotId_t slotId); + int GetCacheBlockMemSize(CacheSlotId_t slotId); + + /* free list */ + bool CacheFreeListEmpty() const; + int GetFreeListCache(); + void PutFreeListCache(CacheSlotId_t freeSlotIdx); + + /* lock */ + LWLock *LockHashPartion(uint32 hashCode, LWLockMode lockMode) const; + void UnLockHashPartion(uint32 hashCode) const; + void LockCacheDescHeader(CacheSlotId_t slot); + void UnLockCacheDescHeader(CacheSlotId_t slot); + void LockSweep(); + void UnlockSweep(); + + bool CacheBlockIsPinned(CacheSlotId_t slotId) const; + void PinCacheBlock_Locked(CacheSlotId_t slotId); + + CacheSlotId_t AllocateBlockFromCache(CacheTag* cacheTag, uint32 hashCode, int size, bool& hasFound); + void AllocateBlockFromCacheWithSlotId(CacheSlotId_t slotId); + void WaitEvictSlot(CacheSlotId_t slotId); + + MgrCacheType m_cache_type; + HTAB* m_hash; + uint32 m_slot_length; + CacheDesc* m_CacheDesc; + + int m_CacheSlotsNum; /* total slot num */ + int m_CaccheSlotMax; /* used max slot id */ + + int64 m_cstoreMaxSize; + int64 m_cstoreCurrentSize; + + int m_freeListHead; + int m_freeListTail; + slock_t m_freeList_lock; + + int m_csweep; + LWLock *m_csweep_lock; + + int m_partition_lock; + + /* protect memory size counter */ + slock_t m_memsize_lock; +}; + +#endif // define diff -uprN postgresql-hll-2.14_old/include/include/storage/checksum.h postgresql-hll-2.14/include/include/storage/checksum.h --- postgresql-hll-2.14_old/include/include/storage/checksum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/checksum.h 2020-12-12 17:06:43.268348309 +0800 @@ -0,0 +1,26 @@ +/* --------------------------------------------------------------------------------------- + * + * checksum.h + * Checksum implementation for data pages. + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/storage/checksum.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CHECKSUM_H +#define CHECKSUM_H + +#include "storage/block.h" + +/* + * Compute the checksum for a Postgres page. The page must be aligned on a + * 4-byte boundary. + */ +extern uint16 pg_checksum_page(char* page, BlockNumber blkno); + +#endif /* CHECKSUM_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/checksum_impl.h postgresql-hll-2.14/include/include/storage/checksum_impl.h --- postgresql-hll-2.14_old/include/include/storage/checksum_impl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/checksum_impl.h 2020-12-12 17:06:43.268348309 +0800 @@ -0,0 +1,164 @@ +/* --------------------------------------------------------------------------------------- + * + * checksum_impl.h + * Checksum implementation for data pages. + * + * This file exists for the benefit of external programs that may wish to + * check Postgres page checksums. They can #include this to get the code + * referenced by storage/checksum.h. (Note: you may need to redefine + * Assert() as empty to compile this successfully externally.) + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/storage/checksum_impl.h + * + * The algorithm used to checksum pages is chosen for very fast calculation. + * Workloads where the database working set fits into OS file cache but not + * into shared buffers can read in pages at a very fast pace and the checksum + * algorithm itself can become the largest bottleneck. + * + * The checksum algorithm itself is based on the FNV-1a hash (FNV is shorthand + * for Fowler/Noll/Vo). The primitive of a plain FNV-1a hash folds in data 1 + * byte at a time according to the formula: + * + * hash = (hash ^ value) * FNV_PRIME + * + * FNV-1a algorithm is described at http://www.isthe.com/chongo/tech/comp/fnv/ + * + * PostgreSQL doesn't use FNV-1a hash directly because it has bad mixing of + * high bits - high order bits in input data only affect high order bits in + * output data. To resolve this we xor in the value prior to multiplication + * shifted right by 17 bits. The number 17 was chosen because it doesn't + * have common denominator with set bit positions in FNV_PRIME and empirically + * provides the fastest mixing for high order bits of final iterations quickly + * avalanche into lower positions. For performance reasons we choose to combine + * 4 bytes at a time. The actual hash formula used as the basis is: + * + * hash = (hash ^ value) * FNV_PRIME ^ ((hash ^ value) >> 17) + * + * The main bottleneck in this calculation is the multiplication latency. To + * hide the latency and to make use of SIMD parallelism multiple hash values + * are calculated in parallel. The page is treated as a 32 column two + * dimensional array of 32 bit values. Each column is aggregated separately + * into a partial checksum. Each partial checksum uses a different initial + * value (offset basis in FNV terminology). The initial values actually used + * were chosen randomly, as the values themselves don't matter as much as that + * they are different and don't match anything in real data. After initializing + * partial checksums each value in the column is aggregated according to the + * above formula. Finally two more iterations of the formula are performed with + * value 0 to mix the bits of the last value added. + * + * The partial checksums are then folded together using xor to form a single + * 32-bit checksum. The caller can safely reduce the value to 16 bits + * using modulo 2^16-1. That will cause a very slight bias towards lower + * values but this is not significant for the performance of the + * checksum. + * + * The algorithm choice was based on what instructions are available in SIMD + * instruction sets. This meant that a fast and good algorithm needed to use + * multiplication as the main mixing operator. The simplest multiplication + * based checksum primitive is the one used by FNV. The prime used is chosen + * for good dispersion of values. It has no known simple patterns that result + * in collisions. Test of 5-bit differentials of the primitive over 64bit keys + * reveals no differentials with 3 or more values out of 100000 random keys + * colliding. Avalanche test shows that only high order bits of the last word + * have a bias. Tests of 1-4 uncorrelated bit errors, stray 0 and 0xFF bytes, + * overwriting page from random position to end with 0 bytes, and overwriting + * random segments of page with 0x00, 0xFF and random data all show optimal + * 2e-16 false positive rate within margin of error. + * + * Vectorization of the algorithm requires 32bit x 32bit -> 32bit integer + * multiplication instruction. As of 2013 the corresponding instruction is + * available on x86 SSE4.1 extensions (pmulld) and ARM NEON (vmul.i32). + * Vectorization requires a compiler to do the vectorization for us. For recent + * GCC versions the flags -msse4.1 -funroll-loops -ftree-vectorize are enough + * to achieve vectorization. + * + * The optimal amount of parallelism to use depends on CPU specific instruction + * latency, SIMD instruction width, throughput and the amount of registers + * available to hold intermediate state. Generally, more parallelism is better + * up to the point that state doesn't fit in registers and extra load-store + * instructions are needed to swap values in/out. The number chosen is a fixed + * part of the algorithm because changing the parallelism changes the checksum + * result. + * + * The parallelism number 32 was chosen based on the fact that it is the + * largest state that fits into architecturally visible x86 SSE registers while + * leaving some free registers for intermediate values. For future processors + * with 256bit vector registers this will leave some performance on the table. + * When vectorization is not available it might be beneficial to restructure + * the computation to calculate a subset of the columns at a time and perform + * multiple passes to avoid register spilling. This optimization opportunity + * is not used. Current coding also assumes that the compiler has the ability + * to unroll the inner loop to avoid loop overhead and minimize register + * spilling. For less sophisticated compilers it might be beneficial to + * manually unroll the inner loop. + * --------------------------------------------------------------------------------------- + */ + +#include "c.h" +#include "storage/bufpage.h" + +/* number of checksums to calculate in parallel */ +#define N_SUMS 32 +/* prime multiplier of FNV-1a hash */ +#define FNV_PRIME 16777619 + +static const uint32 CHECKSUM_CACL_ROUNDS = 2; + +/* + * Base offsets to initialize each of the parallel FNV hashes into a + * different initial state. + */ +static const uint32 g_checksumBaseOffsets[N_SUMS] = {0x5B1F36E9, + 0xB8525960, + 0x02AB50AA, + 0x1DE66D2A, + 0x79FF467A, + 0x9BB9F8A3, + 0x217E7CD2, + 0x83E13D2C, + 0xF8D4474F, + 0xE39EB970, + 0x42C6AE16, + 0x993216FA, + 0x7B093B5D, + 0x98DAFF3C, + 0xF718902A, + 0x0B1C9CDB, + 0xE58F764B, + 0x187636BC, + 0x5D7B3BB1, + 0xE73DE7DE, + 0x92BEC979, + 0xCCA6C0B2, + 0x304A0979, + 0x85AA43D4, + 0x783125BB, + 0x6CA8EAA2, + 0xE407EAC6, + 0x4B5CFC3E, + 0x9FBF8C76, + 0x15CA20BE, + 0xF2CA9FD3, + 0x959BD756}; + +/* + * Calculate one round of the checksum. + */ +#define CHECKSUM_COMP(checksum, value) \ + do { \ + uint32 __tmp = (checksum) ^ (value); \ + (checksum) = __tmp * FNV_PRIME ^ (__tmp >> 17); \ + } while (0) + +/* + * Block checksum algorithm. The data argument must be aligned on a 4-byte + * boundary. + */ +uint32 pg_checksum_block(char* data, uint32 size); + +uint16 pg_checksum_page(char* page, BlockNumber blkno); diff -uprN postgresql-hll-2.14_old/include/include/storage/compress_kits.h postgresql-hll-2.14/include/include/storage/compress_kits.h --- postgresql-hll-2.14_old/include/include/storage/compress_kits.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/compress_kits.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,468 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * compress_kits.h + * kits/tools/implement for compression methods + * + * + * IDENTIFICATION + * src/include/storage/compress_kits.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMPRESS_KITS_H +#define COMPRESS_KITS_H + +#include "c.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "zlib.h" + +enum BufMallocType { + Unknown, // buffer is not valid + FromMemCnxt, // buffer is from PG memory context + FromMemProt, // buffer is so big and from protect manager +}; + +typedef struct { + char* buf; + // remember the current buffer size. + Size bufSize; + BufMallocType bufType; +} BufferHelper; + +extern void BufferHelperMalloc(BufferHelper* p, Size s); +extern void BufferHelperRemalloc(BufferHelper* p, Size s); +extern void BufferHelperFree(BufferHelper* p); +void write_data_by_size(_in_ char* inbuf, unsigned int* pos, int64 data, const short size); +int64 read_data_by_size(_in_ char* inbuf, unsigned int* pos, short size); + +// when decompress some extra bytes are appended to the outbuf. +// +#define ZLIB_EXTRA_SIZE 30 + +/// Given the min-value and max-value, return how many bytes needed +/// to remember their difference value. it's byte bound. +extern inline short DeltaGetBytesNum(_in_ int64 mindata, _in_ int64 maxdata) +{ + Assert(mindata <= maxdata); + uint64 diff = maxdata - mindata; + + if ((0 == diff) || (1 == diff)) + return 1; // byte bound + + const uint64 masks[8] = {0x00000000000000FF, + 0x000000000000FF00, + 0x0000000000FF0000, + 0x00000000FF000000, + 0x000000FF00000000, + 0x0000FF0000000000, + 0x00FF000000000000, + 0xFF00000000000000}; + short i = 7; + while (0 == (diff & masks[i])) { + --i; + Assert(i >= 0); + } + return (i + 1); // byte bound +} + +/// judge whether delta can be applied to. +/// if so, store the needed bytes of difference value and return true. +/// otherwise, do nothing and return false. +extern inline bool DeltaCanBeApplied(short* deltaBytes, int64 minVal, int64 maxVal, short valueBytes) +{ + short dltBytes = DeltaGetBytesNum(minVal, maxVal); + if (dltBytes < valueBytes) { + *deltaBytes = dltBytes; + return true; + } + return false; +} + +/// get memory bound for Delta compression. +extern inline int DeltaGetBound(int nValues, short newSize) +{ + return (newSize * nValues); +} + +/// get memory bound for Delta compression. +extern inline int64 RleGetBound1(int inSize, short eachSize) +{ + Assert((eachSize >= (short)sizeof(int8)) && (eachSize <= (short)sizeof(int64))); + Assert(inSize % eachSize == 0); + return (1 + inSize + (((uint32)(inSize / eachSize)) >> 1)); +} + +/// get memory bound for Delta compression. +/// the same to RleGetBound1() but different means for +/// the first input argument. +extern inline int64 RleGetBound2(int nVals, short eachSize) +{ + Assert((eachSize >= (short)sizeof(int8)) && (eachSize <= (short)sizeof(int64))); + Assert(nVals > 0); + return (1 + (eachSize * nVals) + ((uint32)nVals >> 1)); +} + +// RleCoder compress && decompress +// +class RleCoder : public BaseObject { +public: + /// RLE_v1 constructor. + RleCoder(short oneValSize) + { + m_eachValSize = m_markersize = oneValSize; + m_minRepeats = RleMinRepeats_v1; + } + /// RLE_v2 constructor. + /// *minRepeats* is from *RleMinRepeats_v2* + RleCoder(short oneValSize, unsigned int minRepeats) + { + m_eachValSize = m_markersize = oneValSize; + m_minRepeats = minRepeats; + } + virtual ~RleCoder() + {} + + /* + * Given each value' size and input buffer' size, the upmost memory under the worst condition can be computed. + * so before RLE compression, get the upmost memory by calling CompressGetBound(). + * And caller should remember the size of raw data, pass that value during RLE decompressing. + * + * the common steps of compressing are: + * step1: RleCoder rel(each value size); + * step2: int64 outBufSize = rel.CompressGetBound(your input buffer size); + * step3: char* outBufPrt = (char*) malloc(outBufSize); + * step4: int results = rel.Compress(in, outBufPrt, insize, outBufSize); + * + * if results=0, that means raw data cannot be RLE compressed, and you should read + * raw data directly instead of outBufPtr. + * caller must check results returned, and this rule is also applied to Decompress. + */ + int Compress(_in_ char* inbuf, __inout char* outbuf, _in_ const int insize, _in_ const int outsize); + int Decompress(_in_ char* inbuf, __inout char* outbuf, _in_ const int insize, _in_ const int outsize); + + /* + * after RLE compression values has the following three storage formats: + * 1) plain values + * 2) RLE MARKER + REPEATS + SYMBOL (REPEATS >= RleMinRepeats) + * 3) RLE MARKER + REPEATS(1B) (REPEATS < RleMinRepeats) + * the first format doesn't expand extra memory. and the second format will save some memory. so + * that only the third format can expand and hold extra space. the worst case is like: + * ...... + * MARKER1 SYMBOL(NON-MARKER) + * MARKER1 SYMBOL(NON-MARKER) + * ...... + * ...... + * so we know the upmost memory is computed by: + * + * insize + (insize / m_eachValSize) * (1/2) + 1 + */ + FORCE_INLINE + int64 CompressGetBound(const int insize) + { + return RleGetBound1(insize, m_eachValSize); + } + +private: + template + void WriteNonRuns(char* outbuf, unsigned int* outpos, int64 symbol, unsigned int repeat = 1); + + template + void WriteRuns(char* outbuf, unsigned int* outpos, int64 symbol, unsigned int repeat); + +#ifdef USE_ASSERT_CHECKING + int16 NonRunsNeedSpace(bool equalToMarker, int16 repeats = 1); + int16 RunsNeedSpace(int16 repeats); +#endif + + template + int InnerCompress(char* inbuf, char* outbuf, const int insize, const int outsize); + + template + int InnerDecompress(char* inbuf, char* outbuf, const int insize, const int outsize); + +private: + /// RLE_v1 members start here. + short m_eachValSize; + short m_markersize; + /// RLE_v2 members start here. + unsigned int m_minRepeats; + +private: + /// RLE_v1 always uses the constant min-repeats, + /// which is defined by *RleMinRepeats_v1*. + static const int64 RleMarker[sizeof(int64) + 1]; + static const unsigned int RleMinRepeats_v1; + static const unsigned int RleMaxRepeats; + +public: + /// RLE_v2 uses different min-repeats for different + /// value size. it's just an optimization to + /// *RleMinRepeats_v1* in RLE_v1. + /// Don't worry about upgrading. they appear in different cases. + /// we can get better compression ratio from RLE_v2 than RLE_v1. + static const unsigned int RleMinRepeats_v2[sizeof(int64) + 1]; +}; + +class DeltaCoder : public BaseObject { +public: + // for Compress, extra means the max data. + // for Decompress, extra meas the size of decompressed data, or raw data size. + // + DeltaCoder(int64 mindata, int64 extra, bool willCompress); + virtual ~DeltaCoder() + {} + + // this method is shared by Compress and Decompress. it should be called ahead so that + // the memory needed is enough. + // + FORCE_INLINE uint64 GetBound(uint64 dataNum) + { + Assert(m_outValSize > 0); + return (m_outValSize * dataNum); + } + + // for Compress, min/max data are passed by constructor method, and the raw datasize + // is provided with of method Compress(). at the most case, compressed + // datasize is different from raw datasize, which is fetched by calling GetOutValSize() + // + int64 Compress(char* inbuf, char* outbuf, int insize, int outsize, short inDataSize); + FORCE_INLINE short GetOutValSize(void) + { + return m_outValSize; + } + + // for Decompress, mindata && uncompressed datasize are passed by constructor method. + // this method only just need compressed datasize, that's . + // + int64 Decompress(char* inbuf, char* outbuf, int insize, int outsize, short inDataSize); + +private: + template + int DoDeltaOperation(_in_ char* inbuf, _out_ char* outbuf, _in_ int insize, _in_ short outValSize); + + template + int doDeltaOperation(_in_ char* inbuf, _out_ char* outbuf, _in_ int insize); + + int64 m_mindata; +#ifdef USE_ASSERT_CHECKING + int64 m_maxdata; +#endif + short m_outValSize; +}; + +typedef uint16 DicCodeType; + +/* Dictionary Data In Disk + * + * m_totalSize: including this header and items data + * m_itemsCount: holds how many dictionary items after this header + * array of string data(items data) follows this header. + */ +typedef struct DictHeader { + uint32 m_totalSize; + uint32 m_itemsCount; +} DictHeader; + +/* + * Dictionary Data In Memory + * + * m_itemsMaxSize: the max size holding all items data. + * m_itemUsedSize: used size by items data, it must be <= m_itemsMaxSize. + * m_curItemCount: the count of current used slots. + * m_maxItemCount: + * for global dictionary, it is GLOBAL_DIC_SIZE. + * for local dictionary, it will be doubled once it is full; + * m_itemOffset: remembers offsets of each raw value in dict + * data[1]: includes two parts, + * (part 1) + * (part 2) indexes of the string data array, which size is m_maxItemCount*2, and the type is + * uint32 DicDataHashSlot[1]. 0xFFFF means available. + */ +typedef struct DictDataInMemory { + uint32 m_itemsMaxSize; + uint32 m_itemUsedSize; + DicCodeType m_maxItemCount; + DicCodeType m_curItemCount; + uint32* m_itemOffset; + DicCodeType* m_slots; + char* m_data; + DictHeader* m_header; +} DicData; + +// dictionary compress && decompress +// +class DicCoder : public BaseObject { +public: + virtual ~DicCoder(); + DictHeader* GetHeader(void) + { + return m_dictData.m_header; + } + + // compression methods + // + DicCoder(char* inBuf, int inSize, int numVals, int maxItemCnt); + DicCoder(int dataLen, int maxItemCnt); + + int CompressGetBound(void) const; + int Compress(_out_ char* outBuf); + + bool EncodeOneValue(_in_ Datum datum, _out_ DicCodeType& result); + + // decompression methods + // + DicCoder(char* dictInDisk); + int Decompress(char* inBuf, int inBufSize, char* outBuf, int outBufSize); + void DecodeOneValue(_in_ DicCodeType itemIndx, _out_ Datum* result) const; + +private: + int GetHashSlotsCount(void) + { + return (m_dictData.m_maxItemCount * 2); + } + int ComputeDictMaxSize(int itemsMaxSize, int itemsMaxCount) + { + return (sizeof(DictHeader) + itemsMaxSize + sizeof(DicCodeType) * (itemsMaxCount * 2)); + } + bool IsEnoughToAppend(int appendSize) + { + // both space size and item number must be enough to hold extra one + // + return (((m_dictData.m_itemUsedSize + appendSize) <= m_dictData.m_itemsMaxSize) && + (m_dictData.m_curItemCount < m_dictData.m_maxItemCount)); + } + + void InitDictData(int itemsMaxSize, int itemsMaxCount); + +private: + int m_dataLen; + char* m_inBuf; + int m_inSize; + int m_numVals; + DicData m_dictData; +}; + +// LZ4 && LZ4 HC compress and decompress +// +class LZ4Wrapper : public BaseObject { +public: + /* + * compression level is [0, 16] + * the more compression level, the better compression ratio, the lowest decompression; + * the least compression level, the worst compression ratio, the fastest decompression; + */ + static const int8 lz4_min_level = 0; + static const int8 lz4hc_min_level = 1; + static const int8 lz4hc_recommend_level = 9; + static const int8 lz4hc_level_step = 2; + static const int8 lz4hc_max_level = 16; + + typedef struct Lz4Header { + int rawLen; + int compressLen; + char data[FLEXIBLE_ARRAY_MEMBER]; + } Lz4Header; + +public: + LZ4Wrapper() : m_compressionLevel(LZ4Wrapper::lz4hc_min_level) + {} + virtual ~LZ4Wrapper() + {} + + void SetCompressionLevel(int8 level); + int CompressGetBound(int insize) const; + int Compress(const char* source, char* dest, int sourceSize) const; + + int DecompressGetBound(const char* source) const; + int DecompressGetCmprSize(const char* source) const; + int Decompress(const char* source, char* dest, int sourceSize) const; + +private: +#define SizeOfLz4Header offsetof(LZ4Wrapper::Lz4Header, data) + + bool Benefited(const int& outsize, const int& srcsize) const + { + return (outsize > 0 && (((int)SizeOfLz4Header + outsize) < srcsize)); + } + +private: + int8 m_compressionLevel; +}; + +// ZLIB compress && decompress +// +class ZlibEncoder : public BaseObject { +public: + /* the other compression level macro: + * Z_NO_COMPRESSION: no compress + * Z_DEFAULT_COMPRESSION: -1 + * Z_BEST_SPEED: + */ + static const int8 zlib_recommend_level = 6; + static const int8 zlib_max_level = Z_BEST_COMPRESSION; /* level 9 */ + static const int8 zlib_level_step = 1; + +public: + virtual ~ZlibEncoder(); + ZlibEncoder(); + + /* + * Solution 1: + * step 1: call Reset() to set input-buffer and size; + * step 2: char* outbuf[fixedSize]; outsize = fixedSize; + * step 2: done = false + * while ( !done && Compress(outbuf, outsize, done) >= 0 ) { + * store the compressed outbuf data; + * } + * handle the exception cases; + * + * Solution 2: + * step 1: call Reset() to set input-buffer and size; + * step 2: outsize = CompressGetBound(); so that the outsize is enough to Compress; + * char* outbuf = palloc(outsize); + * step 3: Compress(outbuf, outsize, done); Assert(true == done); + */ + void Prepare(int level = Z_DEFAULT_COMPRESSION); + void Reset(unsigned char* inbuf, const int insize); + int CompressGetBound(int insize); + int Compress(unsigned char* outbuf, const int outsize, bool& done); + +private: + z_stream m_strm; + int m_errno; + int m_flush; +}; + +class ZlibDecoder : public BaseObject { +public: + virtual ~ZlibDecoder(); + ZlibDecoder(); + + // step 1: call Prepare() first to set input buffer. + // step 2: call Decompress() again and again, until done is true, or returned value < 0, + // that means some errors happen. + // + int Prepare(unsigned char* inbuf, const int insize); + int Decompress(unsigned char* outbuf, const int outsize, bool& done, bool bufIsEnough = false); + +private: + z_stream m_strm; + int m_errno; + int m_flush; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/copydir.h postgresql-hll-2.14/include/include/storage/copydir.h --- postgresql-hll-2.14_old/include/include/storage/copydir.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/copydir.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * copydir.h + * Copy a directory. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/copydir.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COPYDIR_H +#define COPYDIR_H + +extern bool copydir(char* fromdir, char* todir, bool recurse, int elevel); +extern void copy_file(char* fromfile, char* tofile); +extern void copy_file_internal(char* fromfile, char* tofile, bool trunc_file); + +extern void fsync_fname(const char* fname, bool isdir); +extern int durable_rename(const char* oldfile, const char* newfile, int elevel); +extern int durable_link_or_rename(const char* oldfile, const char* newfile, int elevel); + +#endif /* COPYDIR_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/cstorealloc.h postgresql-hll-2.14/include/include/storage/cstorealloc.h --- postgresql-hll-2.14_old/include/include/storage/cstorealloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cstorealloc.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstorealloc.h + * + * + * + * IDENTIFICATION + * src/include/storage/cstorealloc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_ALLOC_H +#define CSTORE_ALLOC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/relfilenode.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "cstore.h" + +typedef struct { + uint64 beginOffset; + uint64 size; +} CStoreFreeSpaceDesc; + +typedef CFileNode CStoreColumnFileTag; +typedef CStoreFreeSpaceDesc CStoreSpaceDesc; + +#define DEFAULT_NUM_OF_FREE_SPACE_SLOTS 2000 +#define InvalidCStoreFreeSpace 0xffffffffffffffff +#define InvalidCStoreOffset InvalidCStoreFreeSpace +#define MinAvailableCStoreFSMSize 1024 + +/*Defines max number of holds in column. + * If there are too many holds, we should exec vacuum and do not use the free space. + */ +#define MaxNumOfHoleFSM (100 * 1024 * 1024 / 16) + +#define IsValidCStoreFreeSpaceDesc(desc) ((desc)->size != InvalidCStoreFreeSpace) + +extern Size CStoreAllocatorShmSize(); + +class CStoreFreeSpace : public BaseObject { +public: + CStoreFreeSpace(int maxSize) + { + Initialize(maxSize); + }; + CStoreFreeSpace() + { + Initialize(DEFAULT_NUM_OF_FREE_SPACE_SLOTS); + }; + virtual ~CStoreFreeSpace(); + virtual void Destroy(); + + void Push(_in_ const CStoreFreeSpaceDesc& desc); + + void PopDescWithMaxSize(_out_ CStoreFreeSpaceDesc& desc); + + void GetDescWithMaxSize(_out_ CStoreFreeSpaceDesc& desc); + + bool IsEmpty() + { + return m_descNum == 0; + } + + bool IsFull() + { + return m_descNum == m_maxSize; + } + + bool HasEnoughSpace(Size size); + +public: // STATIC METHODS + static void ComputeFreeSpace(_in_ AttrNumber attno, _in_ Relation cudescIndexRel, _in_ Relation cudescHeapRel, + __inout CStoreFreeSpace* fspace); + +private: + void Initialize(int maxSize); + + CStoreFreeSpaceDesc* m_descs; + int m_descNum; + int m_maxSize; +}; + +class CStoreAllocator : public BaseObject { + +private: + CStoreAllocator(); + virtual ~CStoreAllocator(); + +public: + static void InitColSpaceCache(void); + static void ResetColSpaceCache(void); + + static uint32 GetNextCUID(Relation rel); + + // Now we need lock the relation before acquire space. + static void LockRelForAcquireSpace(Relation rel); + + static void ReleaseRelForAcquireSpace(Relation rel); + + static uint32 AcquireFileSpace(const CFileNode& cnode, uint64 extend_offset, uint64 cu_offset, uint32 cu_size); + // Acquire space for CU + static uint64 AcquireSpace(const CFileNode& cnode, Size size, int align_size); + + // Acquire space for CU from free space + static uint64 TryAcquireSpaceFromFSM(CStoreFreeSpace* fsm, Size size, int align_size); + + // Invalid column cache + static void InvalidColSpaceCache(const CFileNode& cnode); + + static void BuildColSpaceCacheForRel(const CFileNode* cnodes, int nColumn, uint64* offsets, uint32 maxCUID); + static void BuildColSpaceCacheForRel( + _in_ Relation heapRel, _in_ AttrNumber* attrIds, _in_ int attrNum, _in_ List* btreeIndex = NIL); + + static bool ColSpaceCacheExist(const CFileNode* cnodes, int nColumn); + + static uint64 GetExtendOffset(uint64 max_offset); + static uint32 CalcExtendSize(uint64 cu_offset, uint32 cu_size, uint64 extend_offset); + static uint32 recheck_max_cuid(Relation m_rel, uint32 max_cuid, int index_num, Relation* m_idxRelation); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/cstore_compress.h postgresql-hll-2.14/include/include/storage/cstore_compress.h --- postgresql-hll-2.14_old/include/include/storage/cstore_compress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cstore_compress.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,388 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_compress.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cstore_compress.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GSCSTORE_COMPRESS_H +#define GSCSTORE_COMPRESS_H + +#include "storage/compress_kits.h" + +// CU_INFOMASK1 >>>> +// +#define CU_DeltaCompressed 0x0001 +#define CU_DicEncode 0x0002 +// CU_CompressExtend is used for extended compression. +// For compression added afterwards, it can be defined as CU_CompressExtend + 0x0001~0x0008 +#define CU_CompressExtend 0x0004 // Used for extended compression +#define CU_Delta2Compressed 0x0005 // CU_Delta2Compressed equals CU_CompressExtend plus 0x0001 +#define CU_XORCompressed 0x0006 // CU_XORCompressed equals CU_CompressExtend plus 0x0002 +#define CU_RLECompressed 0x0008 +#define CU_LzCompressed 0x0010 +#define CU_ZlibCompressed 0x0020 +#define CU_BitpackCompressed 0x0040 +#define CU_IntLikeCompressed 0x0080 + +extern bool NeedToRecomputeMinMax(Oid typeOid); +extern int64 ConvertToInt64Data(_in_ const char* inBuf, _in_ const short eachValSize); +extern void Int64DataConvertTo(_in_ int64 inVal, _in_ short eachValSize, _out_ char* outBuf); + +#define GLOBAL_DICT_SIZE 4096 + +/* compression filter. + * step 1: sample. use the first CU data to sample, and detect + * what compression methods to adopt; + * step 2: apply these filter to subsequent compressing. + */ +struct compression_options { + /* sampling flag */ + bool m_sampling_fihished; + + /* the followings are adopt-compression-method flags */ + + /* flags for numeric to integer */ + bool m_adopt_numeric2int_ascale_rle; + bool m_adopt_numeric2int_int32_rle; + bool m_adopt_numeric2int_int64_rle; + + /* common flags */ + bool m_adopt_dict; /* Dictionary encoding */ + bool m_adopt_rle; /* RLE encoding */ + + void reset(void); + void set_numeric_flags(uint16 modes); + void set_common_flags(uint32 modes); +}; + +// input arguments for compression && +// output arguments for decompression +// +typedef struct { + // shared var by both IntegerCoder && StringCoder + // + char* buf; + int sz; + /* compressing modes include compression and compress level. */ + int16 mode; + /* here int16 padding */ + + // only just for StringCoder, whether to use dictionary + // + void* globalDict; + int numVals; + bool useDict; + bool useGlobalDict; + bool buildGlobalDict; +} CompressionArg1; + +// output arguments for compression && +// input arguments for decompression +// +typedef struct { + char* buf; + int sz; + uint16 modes; +} CompressionArg2; + +class IntegerCoder : public BaseObject { +public: + virtual ~IntegerCoder() + {} + + IntegerCoder(short eachValSize); + void SetMinMaxVal(int64 min, int64 max); + int Compress(_in_ const CompressionArg1& in, _out_ CompressionArg2& out); + int Decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + + /* optimizing flags */ + bool m_adopt_rle; + +private: + void InsertMinMaxVal(char* buf, int* usedSize); + + /* inner implement for compress API */ + template + int CompressInner(const CompressionArg1& in, CompressionArg2& out); + +private: + // m_isValid = true, min/max is passed in by SetMinMaxVal(). + // m_isValid = false, min/max should be computed innerly. + // + int64 m_minVal; + int64 m_maxVal; + bool m_isValid; + short m_eachValSize; +}; + +class StringCoder : public BaseObject { +public: + virtual ~StringCoder() + {} + + StringCoder() : m_adopt_rle(true), m_adopt_dict(true), m_dicCodes(NULL), m_dicCodesNum(0) + {} + + int Compress(_in_ CompressionArg1& in, _in_ CompressionArg2& out); + int Decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + + /* optimizing flags */ + bool m_adopt_rle; + bool m_adopt_dict; + +private: + /* inner implement for compress api */ + template + int CompressInner(CompressionArg1& in, CompressionArg2& out); + + // compress/decompress directly using lz4/zlib but without global/local dictionary + // + int CompressWithoutDict(_in_ char* inBuf, _in_ int inBufSize, _in_ int compressing_modes, _out_ char* outBuf, + _in_ int outBufSize, _out_ int& mode); + int DecompressWithoutDict( + _in_ char* inBuf, _in_ int inBufSize, _in_ uint16 mode, _out_ char* outBuf, _out_ int outBufSize); + + int CompressNumbers( + _in_ int max, _in_ int compressing_modes, __inout char* outBuf, _in_ int outBufSize, _out_ uint16& mode); + void DecompressNumbers( + _in_ char* inBuf, _in_ int inBufSize, _in_ uint16 mode, _out_ char* outBuf, _in_ int outBufSize); + +private: + DicCodeType* m_dicCodes; + DicCodeType m_dicCodesNum; +}; + +/// light-weight implementation for Delta-RLE compression. +class DeltaPlusRLEv2 : public BaseObject { +public: + DeltaPlusRLEv2(int64 minVal, int64 maxVal, int32 nVals, short valueBytes) + { + m_minVal = minVal; + m_nValues = nVals; + m_valueBytes = valueBytes; + + /// m_maxVal is not used during decompression. + /// so that you can skip it. + m_maxVal = maxVal; + + /// m_deltaBytes will be updated later. + m_deltaBytes = valueBytes; + + m_adopt_rle = true; + } + virtual ~DeltaPlusRLEv2() + { /* don't create or destroy any resource. */ + } + + /// API about compressing. + int GetBound(); + int Compress(char** outBuf, int outBufSize, uint16* outModes, char* inBuf, int inBufSize); + + /// API about decompressing. + void SetDltValSize(short dltBytes) + { + /// if delta is used, m_deltaBytes < m_valueBytes. + /// otherwise, they should be equal to. + Assert(dltBytes < m_valueBytes); + m_deltaBytes = dltBytes; + } + int Decompress(char** outBuf, int outBufSize, char* inBuf, int inBufSize, uint16 modes); + + /* optimizing flags */ + bool m_adopt_rle; + +private: + int64 m_minVal; + int64 m_maxVal; + int32 m_nValues; + short m_valueBytes; + short m_deltaBytes; + + /* inner implement for compress API */ + template + int CompressInner(char** out, int outSize, uint16* outModes, char* in, int inSize); +}; + +/// +/// compress the batch of numeric +/// + +// int32 integer: +// ascales in [-2, 2] <--> encoding val [1, 5] +// int64 integer: +// ascales in [-4, 4] <--> encoding val [6, 14] +// we represent status codes with 4 bits, and 0 means that it +// fails to compress. so 15 is unused. +// +#define FAILED_ENCODING 0 +#define MAX_INT32_ASCALE_ENCODING 5 +#define MAX_INT64_ASCALE_ENCODING 14 +#define DIFF_INT32_ASCALE_ENCODING 3 +#define DIFF_INT64_ASCALE_ENCODING 10 + +// dsacle +// 2 bits flag for dscale encoding +#define NUMERIC_DSCALE_ENCODING 0 +#define INT32_DSCALE_ENCODING 1 +#define INT64_DSCALE_ENCODING 2 + +/// bit flags for NUMERIC compressed head info +#define NUMERIC_FLAG_EXIST_OTHERS 0x0001 +#define NUMERIC_FLAG_OTHER_WITH_LZ4 0x0002 +#define NUMERIC_FLAG_EXIST_INT32_VAL 0x0004 +#define NUMERIC_FLAG_INT32_SAME_VAL 0x0008 +#define NUMERIC_FLAG_INT32_SAME_ASCALE 0x0010 +#define NUMERIC_FLAG_INT32_WITH_DELTA 0x0020 +#define NUMERIC_FLAG_INT32_WITH_RLE 0x0040 +#define NUMERIC_FLAG_EXIST_INT64_VAL 0x0080 +#define NUMERIC_FLAG_INT64_SAME_VAL 0x0100 +#define NUMERIC_FLAG_INT64_SAME_ASCALE 0x0200 +#define NUMERIC_FLAG_INT64_WITH_DELTA 0x0400 +#define NUMERIC_FLAG_INT64_WITH_RLE 0x0800 +#define NUMERIC_FLAG_SCALE_WITH_RLE 0x1000 +/// notice: add new bit flag above +#define NUMERIC_FLAG_SIZE (2) // use byte as unit + +/// function type definition. +typedef void (*SetNullNumericFunc)(int which, void* memobj); + +/// struct type definition +typedef struct { + bool* success; /// treat null value as failed. + char* ascale_codes; + int64* int64_values; + int32* int32_values; + + int64 int64_minval; + int64 int64_maxval; + int32 int32_minval; + int32 int32_maxval; + int int64_n_values; + int int32_n_values; + int n_notnull; + int failed_cnt; + int failed_size; + + /// it's needed and used to malloc exact memory during decompressing. + int original_size; + + bool int64_ascales_are_same; + bool int64_values_are_same; + /// valid only when int64_ascales_are_same is true. + char int64_same_ascale; + bool int32_ascales_are_same; + bool int32_values_are_same; + /// valid only when int32_ascales_are_same is true. + char int32_same_ascale; +} numerics_statistics_out; + +typedef struct { + CompressionArg2 int64_out_args; + CompressionArg2 int32_out_args; + int int64_cmpr_size; + int int32_cmpr_size; + + char* other_srcbuf; + char* other_outbuf; + int other_cmpr_size; + bool other_apply_lz4; + + /* compression filter */ + compression_options* filter; +} numerics_cmprs_out; + +/// maybe these values cannot use any compression +/// method. so during decompression we can directly +/// access the memory of compressed data, needn't +/// to copy again, and reduce the number of memcpy() +/// calls. +typedef struct { + char* int64_addr_ref; + char* int32_addr_ref; + char* other_addr_ref; +} numerics_decmprs_addr_ref; + +typedef struct { + Datum* values; + char* nulls; /* nulls bitmap */ + int rows; + + /// *func* and *mobj* must be set if *hasNull* is true. + bool hasNull; + SetNullNumericFunc func; + /// the second argument of *func*. + void* mobj; +} BatchNumeric; + +/// configure the failed ratio. +/// valid value is 1~100. +extern void NumericConfigFailedRatio(int failed_ratio); + +/// given one batch of numeric values, try to compress them. +/// you must set both *setnull* if there are nulls. +/// return the not-exact size of compressed data if compress successfully. +/// otherwise return false, and *compressed_datasize* is undefined. +/// +extern bool NumericCompressBatchValues( + BatchNumeric* batch, numerics_statistics_out* out1, numerics_cmprs_out* out2, int* compressed_datasize, int align_size); + +/// copy the data after compress successfully. +extern char* NumericCopyCompressedBatchValues(char* ptr, numerics_statistics_out* out1, numerics_cmprs_out* out2); +extern void NumericCompressReleaseResource(numerics_statistics_out* statOut, numerics_cmprs_out* cmprOut); + +/// decompress APIs +extern char* NumericDecompressParseHeader( + char* ptr, uint16* out_flags, numerics_statistics_out* out1, numerics_cmprs_out* out2); +extern char* NumericDecompressParseAscales(char* ptr, numerics_statistics_out* out1, uint16 flags); +extern char* NumericDecompressParseEachPart( + char* ptr, numerics_statistics_out* out1, numerics_cmprs_out* out2, numerics_decmprs_addr_ref* out3); +extern char* NumericDecompressParseDscales(char* ptr, numerics_statistics_out* out1, uint16 flags); + +template +extern void NumericDecompressRestoreValues(char* outBuf, int typeMode, numerics_statistics_out* stat_out, + numerics_cmprs_out* cmpr_out, numerics_decmprs_addr_ref* in3); +extern void NumericDecompressReleaseResources( + numerics_statistics_out* decmprStatOut, numerics_cmprs_out* decmprOut, numerics_decmprs_addr_ref* addrRef); + +// fill bitmap according to values[n_values] +// bit should be set to 0 if it's equal to *valueIfUnset*, +// otherwise bit should be set to 1. +template +extern void FillBitmap(char* buf, const T* values, int nValues, T valueIfUnset) +{ + unsigned char* byteBuf = (unsigned char*)(buf - 1); + uint32 bitMask = HIGHBIT; + + for (int cnt = 0; cnt < nValues; ++cnt) { + if (bitMask != HIGHBIT) { + bitMask <<= 1; + } else { + byteBuf++; + *byteBuf = 0x00; + bitMask = 1; + } + if (valueIfUnset == values[cnt]) { + continue; + } + *byteBuf |= bitMask; + } +} +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/cstore_mem_alloc.h postgresql-hll-2.14/include/include/storage/cstore_mem_alloc.h --- postgresql-hll-2.14_old/include/include/storage/cstore_mem_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cstore_mem_alloc.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,76 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_mem_alloc.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cstore_mem_alloc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORE_MEM_ALLOC_H +#define CSTORE_MEM_ALLOC_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#define MaxPointersArryLen 512U +#define MaxPtrNodeCacheLen 256U + +typedef struct PointerNode { + void* ptr; + PointerNode* next; + + void Reset() + { + ptr = NULL; + next = NULL; + } +} PointerNode; + +typedef struct PointerList { + PointerNode* header; + PointerNode* tail; +} NodeList; + +// CStoreMemAlloc +// It manages the memory pointer from malloc +// When transaction occurs erro, the memory from malloc can be reset in abortTransaction +// When transaction commit, the memory from malloc can be reset +// +class CStoreMemAlloc { +public: + static void* Palloc(Size size, bool toRegister = true); + static void Pfree(void* pointer, bool registered = true); + static void* Repalloc(void* pointer, Size size, Size old_size, bool registered = true); + static void Register(void* pointer); + static void Unregister(const void* pointer); + static void Reset(); + static void Init(); + +private: + static void* AllocPointerNode(); + static void FreePointerNode(PointerNode* pointer); + + static THR_LOCAL PointerList m_tab[MaxPointersArryLen]; + static THR_LOCAL uint64 m_count; + + static THR_LOCAL uint32 m_ptrNodeCacheCount; + static THR_LOCAL PointerNode* m_ptrNodeCache[MaxPtrNodeCacheLen]; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/cucache_mgr.h postgresql-hll-2.14/include/include/storage/cucache_mgr.h --- postgresql-hll-2.14_old/include/include/storage/cucache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cucache_mgr.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cucache_mgr.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cucache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CUCACHEMGR_H +#define CUCACHEMGR_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/relfilenode.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/hsearch.h" +#include "storage/lwlock.h" +#include "storage/spin.h" +#include "storage/shmem.h" +#include "storage/cu.h" +#include "storage/cache_mgr.h" +#include "storage/custorage.h" + +#define CUCache (DataCacheMgr::GetInstance()) +#define ORCCache (DataCacheMgr::GetInstance()) +#define OBSCache (DataCacheMgr::GetInstance()) + +int DataCacheMgrNumLocks(); + +// MAX_CACHE_TAG_LEN is max slot tag size +typedef struct CUSlotTag { + RelFileNodeOld m_rnode; + int m_colId; + int32 m_CUId; + uint32 m_padding; + CUPointer m_cuPtr; +} CUSlotTag; + +typedef struct ORCSlotTag { + RelFileNodeOld m_rnode; + int32 m_fileId; + uint64 m_offset; + uint64 m_length; +} ORCSlotTag; + +/* + * be careful, the length of OBSSlotTag + * shoud be <= 32 bytes. The + * max length is defined by macro + * MAX_CACHE_TAG_LEN. + */ +typedef struct OBSSlotTag { + uint32 m_serverHash; + uint32 m_bucketHash; + uint32 m_fileFirstHash; + uint32 m_fileSecondHash; + + uint64 m_offset; + uint64 m_length; +} OBSSlotTag; + +typedef union DataSlotTagKey { + CUSlotTag cuSlotTag; + ORCSlotTag orcSlotTag; + OBSSlotTag obsSlotTag; +} DataSlotTagKey; + +typedef struct DataSlotTag { + DataSlotTagKey slotTag; + CacheType slotType; +} DataSlotTag; + +typedef struct OrcDataValue { + void* value; + uint64 size; +} OrcDataValue; + +/* returned code about uncompressing CU data in CU cache */ +enum CUUncompressedRetCode { CU_OK = 0, CU_ERR_CRC, CU_ERR_MAGIC, CU_ERR_ADIO, CU_RELOADING, CU_ERR_MAX }; + +/* + * This class is to manage Data Cache. + * For integer CU, we should store compressed data. + * For string CU, because the speed of decompressing data is low, + * so store source data. + */ +class DataCacheMgr : public BaseObject { +public: + static DataCacheMgr* GetInstance(void); + static void NewSingletonInstance(void); + + DataSlotTag InitCUSlotTag(RelFileNodeOld* rnode, int colid, uint32 cuid, CUPointer cuPtr); + DataSlotTag InitORCSlotTag(RelFileNode* rnode, int32 fileid, uint64 offset, uint64 length); + DataSlotTag InitOBSSlotTag(uint32 hostNameHash, uint32 bucketNameHash, uint32 fileFirstHalfHash, + uint32 fileSecondHalfHash, uint64 offset, uint64 length) const; + CacheSlotId_t FindDataBlock(DataSlotTag* dataSlotTag, bool first_enter_block); + int ReserveDataBlock(DataSlotTag* dataSlotTag, int size, bool& hasFound); + bool ReserveDataBlockWithSlotId(int slotId); + bool ReserveCstoreDataBlockWithSlotId(int slotId); + CU* GetCUBuf(int cuSlotId); + OrcDataValue* GetORCDataBuf(int cuSlotId); + void UnPinDataBlock(int cuSlotId); + /* Manage I/O busy CUs */ + bool DataBlockWaitIO(int cuSlotId); + void DataBlockCompleteIO(int cuSlotId); + int64 GetCurrentMemSize(); + void PrintDataCacheSlotLeakWarning(CacheSlotId_t slotId); + + void AbortCU(CacheSlotId_t slot); + void TerminateCU(bool abort); + void TerminateVerifyCU(); + void InvalidateCU(RelFileNodeOld* rnode, int colId, uint32 cuId, CUPointer cuPtr); + void DropRelationCUCache(const RelFileNode& rnode); + CUUncompressedRetCode StartUncompressCU(CUDesc* cuDescPtr, CacheSlotId_t slotId, int planNodeId, bool timing, int align_size); + + // async lock used by adio + bool CULWLockHeldByMe(CacheSlotId_t slotId); + void CULWLockOwn(CacheSlotId_t slotId); + void CULWLockDisown(CacheSlotId_t slotId); + + void LockPrivateCache(); + void UnLockPrivateCache(); + + void SetORCDataBlockValue(CacheSlotId_t slotId, const void* buffer, uint64 size); + void SetOBSDataBlockValue( + CacheSlotId_t slotId, const void* buffer, uint64 size, const char* prefix, const char* dataDNA); + + void AcquireCompressLock(CacheSlotId_t slotId); + void RealeseCompressLock(CacheSlotId_t slotId); + + int64 m_cstoreMaxSize; + +#ifndef ENABLE_UT +private: +#endif // ENABLE_UT + + DataCacheMgr() + {} + ~DataCacheMgr() + {} + + static DataCacheMgr* m_data_cache; + CacheMgr* m_cache_mgr; + slock_t m_adio_write_cache_lock; // write private cache, not cucache. I add here because spinlock need init once + // for cstore module +}; + +/* interface for orc data read */ +void ReleaseORCBlock(CacheSlotId_t slot); +CacheSlotId_t ORCCacheAllocBlock( + RelFileNode* rnode, int32 fileid, uint64 offset, uint64 length, bool& found, bool& err_found); +CacheSlotId_t OBSCacheAllocBlock(const char* hostName, const char* bucketName, const char* prefixName, uint64 offset, + uint64 length, bool& found, bool& err_found); +bool OBSCacheRenewBlock(CacheSlotId_t slotID); +OrcDataValue* ORCCacheGetBlock(CacheSlotId_t slot); +void ORCCacheSetBlock(CacheSlotId_t slotId, const void* buffer, uint64 size); +void OBSCacheSetBlock(CacheSlotId_t slotId, const void* buffer, uint64 size, const char* prefix, const char* dataDNA); + +#endif // define diff -uprN postgresql-hll-2.14_old/include/include/storage/cu.h postgresql-hll-2.14/include/include/storage/cu.h --- postgresql-hll-2.14_old/include/include/storage/cu.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/cu.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,549 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cu.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cu.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CU_H +#define CU_H + +#include "vecexecutor/vectorbatch.h" +#include "cstore.h" +#include "storage/cstore_mem_alloc.h" +#include "utils/datum.h" +#include "storage/lwlock.h" + + +#define ATT_IS_CHAR_TYPE(atttypid) (atttypid == BPCHAROID || atttypid == VARCHAROID || atttypid == NVARCHAR2OID) +#define ATT_IS_NUMERIC_TYPE(atttypid) (atttypid == NUMERICOID) + +// max uint64 value length 19, set 24 for 8 bit align +#define MAX_LEN_CHAR_TO_BIGINT_BUF (24) +#define MAX_LEN_CHAR_TO_BIGINT (19) + +// CU size always is alligned to ALIGNOF_CU +// + +// ADIO requires minimum CU size of 8192 and 512 block alignment +#define ALIGNOF_CUSIZE (8192) +#define ALIGNOF_TIMESERIES_CUSIZE (2) + +enum {TS_COLUMN_ID_BASE = 2000}; + +#define ALLIGN_CUSIZE2(_LEN) TYPEALIGN(2, (_LEN)) +#define ALIGNOF_CUSIZE512(_LEN) TYPEALIGN(512, (_LEN)) +#define ALLIGN_CUSIZE32(_LEN) TYPEALIGN(32, (_LEN)) +#define ALLIGN_CUSIZE(_LEN) TYPEALIGN(ALIGNOF_CUSIZE, (_LEN)) + +#define ASSERT_CUSIZE(_LEN) \ + Assert((_LEN) == ALLIGN_CUSIZE(_LEN) || (_LEN) == ALLIGN_CUSIZE32(_LEN) \ + || (_LEN) == ALIGNOF_CUSIZE512(_LEN) || (_LEN) == ALLIGN_CUSIZE2(_LEN)) + +class CUAlignUtils { +public: + static uint32 AlignCuSize(int len, int align_size); + static int GetCuAlignSizeColumnId(int columnId); +}; + +#define PADDING_CU(_PTR, _LEN) \ + do { \ + char* p = (char*)(_PTR); \ + int len = (_LEN); \ + for (int i = 0; i < len; ++i, ++p) \ + *p = 0; \ + } while (0) + +#define MIN_MAX_LEN 32 + +// CU_INFOMASK1 has all the compression mode info. +// CU_INFOMASK2 has the other data attribute info. +// +#define CU_INFOMASK1 0x00FF +#define CU_INFOMASK2 0xFF00 + +// CU_INFOMASK1 is in file storage/cstore_compress.h +// CU_INFOMASK2 is working for the following +// +#define CU_DSCALE_NUMERIC 0x0100 // flag for numeric dscale compress +#define CU_HasNULL 0x0400 +// indicate that this CRC is just one magic data, and +// CRC computation can be ignored during query. +#define CU_IgnoreCRC 0x0800 +// using CRC32C for checksum +#define CU_CRC32C 0x1000 +// CU is encrypt +#define CU_ENCRYPT 0x2000 + +// the CU_mode of CUDesc +// +#define CU_NORMAL 0x01 +#define CU_FULL_NULL 0x02 +#define CU_SAME_VAL 0x03 +#define CU_NO_MINMAX_CU 0x04 +#define CU_HAS_NULL 0x08 + +// The mask of CU_NORMAL, CU_FULL_NULL, +// CU_SAME_VAL, CU_NO_MINMAX_CU +// +#define CU_MODE_LOWMASK 0x0f + +// how many bits are set 1 in an unsigned byte +// +const uint8 NumberOfBit1Set[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, + 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, + 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, + 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, + 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, + 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, + 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; + +struct CUDesc : public BaseObject { + TransactionId xmin; + /* + * serial-number of CU + */ + uint32 cu_id; + + // The min value of CU + // If type is fixed-length, cu_min stores the value. + // If type is variable-length, cu_min store len and value + // Format: len (1byte) value (len <= MIN_MAX_LEN) + // + char cu_min[MIN_MAX_LEN]; + + // The max value of CU + // If type is fixed-length, cu_max store the value. + // If type is variable-length, cu_max store len and value + // Format: len (1byte) value (len <= MIN_MAX_LEN) + // + char cu_max[MIN_MAX_LEN]; + + /* + * The row number of CU + */ + int row_count; + + /* + * The CU data size + */ + int cu_size; + + /* + * The CU information mask + */ + int cu_mode; + + /* + * The pointer of CU in CU Storage + */ + CUPointer cu_pointer; + + /* + * magic number is used to check CU Data valid + */ + uint32 magic; + +public: + CUDesc(); + ~CUDesc(); + + void SetNullCU(); + bool IsNullCU() const; + void SetNormalCU(); + void SetSameValCU(); + bool IsNormalCU() const; + bool IsSameValCU() const; + void SetNoMinMaxCU(); + bool IsNoMinMaxCU() const; + void SetCUHasNull(); + bool CUHasNull() const; + + void Reset(); + void Destroy() + {} +}; + +/* temp info about CU compression + * because CU data cache exists, we should control used memory and + * reduce as much as possible. So all temp data during compressing + * will be placed together. + */ +struct cu_tmp_compress_info { + /* CU compression options, which type is compression_options */ + void* m_options; + + /* min/max value for integer compression. + * m_valid_minmax indicates whether the two are valid. + */ + int64 m_min_value; + int64 m_max_value; + bool m_valid_minmax; +}; + +/* CU struct: + * before compressing + * + * +------------------------+ <-- m_srcBuf - + * | | | + * | Header Info | m_srcBufSize + * | | | + * +------------------------+ <-- m_nulls - | + * | | | | + * | Null Bitmap | m_bpNullRawSize | + * | | | | + * +------------------------+ <-- m_srcData - | + * | | | | + * | Compressed Data | m_srcDataSize | + * | | | | + * +------------------------+ - | + * | Padding Data | | + * +------------------------+ - + */ +class CU : public BaseObject { +public: + /* Source buffer: nulls bitmap + source data. */ + char* m_srcBuf; + + /* The pointer of Null value in m_srcBuf. */ + unsigned char* m_nulls; + + /* The pointer of source data in m_srcBuf. */ + char* m_srcData; + + /* Compressed buffer: compressed header + compressed data */ + char* m_compressedBuf; + + /* support with accessing datum randomly after loading CU data */ + int32* m_offset; + + /* temp info about CU compression */ + cu_tmp_compress_info* m_tmpinfo; + + /* adio load cu, compressbuf + padding */ + char* m_compressedLoadBuf; + int m_head_padding_size; + + /* the number of m_offset items */ + int32 m_offsetSize; + + /* source buffer size. */ + uint32 m_srcBufSize; + + /* source data size */ + uint32 m_srcDataSize; + + /* Compressed buffer size */ + uint32 m_compressedBufSize; + + /* CU size, including padding data */ + uint32 m_cuSize; + + /* compressed CU size, excluding padding data */ + uint32 m_cuSizeExcludePadding; + + /* CRC check code */ + uint32 m_crc; + + /* magic number is used to check CU Data valid */ + uint32 m_magic; + + /* some information for compressing integer type + * m_eachValSize: the size of each value. -1 or -2 means varlena type. + * m_typeMode: type mode from attribute' typmode. for numeric it has + * precision and scale info. + */ + int m_eachValSize; + int m_typeMode; + + /* + * Nulls Bitmap Size about compressed && uncompressed + * m_bpNullCompressedSize is 0 if the CU has no Nulls. + * otherwise, it's stored in CU header. see FillCompressBufHeader(). + * m_bpNullRawSize can be computed if row count is given. + * it's initialized by InitMem(). + */ + uint16 m_bpNullRawSize; + uint16 m_bpNullCompressedSize; + + /* + * Some information. + * whether has NULL value, compressed mode and so on. + */ + uint16 m_infoMode; + + /* column type id , used for distinguish char and varchar */ + uint32 m_atttypid; + + bool m_adio_error; /* error occur in ADIO mode */ + bool m_cache_compressed; /* describe whether CU compressed in CU cache or not, + * ADIO load cu into memory which compressed, + * when scan use the CU, it should compress first. + */ + bool m_inCUCache; /* whether in CU cache */ + + bool m_numericIntLike; /* whether all data in the numeric CU can be transformed to Int64 */ + +public: + CU(); + CU(int typeLen, int typeMode, uint32 atttypid); + ~CU(); + void Destroy(); + + /* + * Check CRC code + */ + bool CheckCrc(); + + /* + * Generate CRC code + */ + uint32 GenerateCrc(uint16 info_mode) const; + + /* + * Append value + */ + void AppendValue(Datum val, int size); + + /* + * Append value + */ + void AppendValue(const char* val, int size); + + /* + * Append Null value + */ + void AppendNullValue(int row); + + static void AppendCuData(_in_ Datum value, _in_ int repeat, _in_ Form_pg_attribute attr, __inout CU* cu); + + // Compress data + // + int16 GetCUHeaderSize(void) const; + void Compress(int valCount, int16 compress_modes, int align_size); + void FillCompressBufHeader(void); + char* CompressNullBitmapIfNeed(_in_ char* buf); + bool CompressData(_out_ char* outBuf, _in_ int nVals, _in_ int16 compressOption, int align_size); + + // Uncompress data + // + char* UnCompressHeader(_in_ uint32 magic, int align_size); + void UnCompress(_in_ int rowCount, _in_ uint32 magic, int align_size); + char* UnCompressNullBitmapIfNeed(const char* buf, int rowCount); + void UnCompressData(_in_ char* buf, _in_ int rowCount); + template + void UncompressNumeric(char* inBuf, int nNotNulls, int typmode); + + // access datum randomly in CU + // + template + void FormValuesOffset(int rows); + + template + ScalarValue GetValue(int rowIdx); + + /* + * CU to Vector + */ + template + int ToVector(_out_ ScalarVector* vec, _in_ int leftRows, _in_ int rowCursorInCU, __inout int& curScanPos, + _out_ int& deadRows, _in_ uint8* cuDelMask); + + /* + * CU to Vector + */ + template + int ToVectorT(_out_ ScalarVector* vec, _in_ int leftRows, _in_ int rowCursorInCU, __inout int& curScanPos, + _out_ int& deadRows, _in_ uint8* cuDelMask); + + template + int ToVectorLateRead(_in_ ScalarVector* tids, _out_ ScalarVector* vec); + + // GET method is used to set the CUDesc info after compressing CU. + // SET method is used to set the CU info during decompressing CU data. + // + int GetCUSize() const; + void SetCUSize(int cuSize); + + int GetCompressBufSize() const; + + int GetUncompressBufSize() const; + + bool CheckMagic(uint32 magic) const; + void SetMagic(uint32 magic); + uint32 GetMagic() const; + + bool IsVerified(uint32 magic); + + /* + * Is NULL value + */ + bool IsNull(uint32 row) const; + + /* + * The number of NULL before rows. + */ + int CountNullValuesBefore(int rows) const; + + void FreeCompressBuf(); + void FreeSrcBuf(); + + void Reset(); + void SetTypeLen(int typeLen); + void SetTypeMode(int typeMode); + void SetAttTypeId(uint32 atttypid); + void SetAttInfo(int typeLen, int typeMode, uint32 atttypid); + bool HasNullValue() const; + + void InitMem(uint32 initialSize, int rowCount, bool hasNull); + void ReallocMem(Size size); + + template + void FreeMem(); + + /* timeseries function */ + void copy_nullbuf_to_cu(const char* bitmap, uint16 null_size); + uint32 init_field_mem(const int reserved_cu_byte); + uint32 init_time_mem(const int reserved_cu_byte); + void check_cu_consistence(const CUDesc* cudesc) const; + +private: + template + void DeFormNumberStringCU(); + + bool IsNumericDscaleCompress() const; + + // encrypt cu data + void CUDataEncrypt(char* buf); + // decrypt cu data + void CUDataDecrypt(char* buf); +}; + +template +ScalarValue CU::GetValue(int rowIdx) +{ + // Notice: this function don't handle the case where it's a + // NULL value. caller must be sure this prerequisite. + Assert(!(HasNullValue() && IsNull(rowIdx))); + Assert(!hasNull || (hasNull && m_offset && m_offsetSize > 0)); + + ScalarValue destVal; + switch (attlen) { + case sizeof(uint8): { + if (!hasNull) + destVal = *((uint8*)m_srcData + rowIdx); + else + destVal = *(uint8*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint16): { + if (!hasNull) + destVal = *((uint16*)m_srcData + rowIdx); + else + destVal = *(uint16*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint32): { + if (!hasNull) + destVal = *((uint32*)m_srcData + rowIdx); + else + destVal = *(uint32*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint64): { + if (!hasNull) + destVal = *((uint64*)m_srcData + rowIdx); + else + destVal = *(uint64*)(m_srcData + m_offset[rowIdx]); + break; + } + case 12: { + if (!hasNull) + destVal = (ScalarValue)((uint8*)m_srcData + (12 * rowIdx)); + else + destVal = (ScalarValue)(m_srcData + m_offset[rowIdx]); + break; + } + case 16: { + if (!hasNull) + destVal = (ScalarValue)((uint8*)m_srcData + (16 * rowIdx)); + else + destVal = (ScalarValue)(m_srcData + m_offset[rowIdx]); + break; + } + case -1: + case -2: + destVal = (ScalarValue)((uint8*)m_srcData + m_offset[rowIdx]); + break; + default: + ereport(ERROR, (errmsg("unsupported datatype branch"))); + break; + } + return destVal; +} + +template +void CU::FreeMem() +{ + if (this->m_srcBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_srcBuf, !this->m_inCUCache); + } else { + free(this->m_srcBuf); + } + this->m_srcBuf = NULL; + this->m_srcBufSize = 0; + } + if (this->m_compressedLoadBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_compressedLoadBuf, !this->m_inCUCache); + } else { + free(this->m_compressedLoadBuf); + } + this->m_compressedBuf = NULL; + this->m_compressedBufSize = 0; + this->m_compressedLoadBuf = NULL; + this->m_head_padding_size = 0; + } else { + if (this->m_compressedBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_compressedBuf, !this->m_inCUCache); + } else { + free(this->m_compressedBuf); + } + this->m_compressedBuf = NULL; + this->m_compressedBufSize = 0; + this->m_compressedLoadBuf = NULL; + this->m_head_padding_size = 0; + } + } + if (this->m_offset) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_offset, !this->m_inCUCache); + } else { + free(this->m_offset); + } + this->m_offset = NULL; + this->m_offsetSize = 0; + } +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/custorage.h postgresql-hll-2.14/include/include/storage/custorage.h --- postgresql-hll-2.14_old/include/include/storage/custorage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/custorage.h 2020-12-12 17:06:43.269348322 +0800 @@ -0,0 +1,172 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * custorage.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/custorage.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CU_STORAGE_H +#define CU_STORAGE_H + +#include "storage/cu.h" +#include "storage/relfilenode.h" +#include "storage/fd.h" +#include "storage/cstorealloc.h" + +class CUFile; + +class CUStorage : public BaseObject { +public: + CUStorage(const CFileNode& cFileNode, CStoreAllocateStrategy strategy = APPEND_ONLY); + virtual ~CUStorage(); + virtual void Destroy(); + + friend class CUFile; + + // Write CU data into storage + // + void SaveCU(_in_ char* write_buf, _in_ uint64 offset, _in_ int size, bool direct_flag, bool for_extension = false); + + void OverwriteCU( + _in_ char* write_buf, _in_ uint64 offset, _in_ int size, bool direct_flag, bool for_extension = false); + + // Load CU data from storage + // + void LoadCU(_in_ CU* cuPtr, _in_ uint64 offset, _in_ int size, bool direct_flag, bool inCUCache); + + void RemoteLoadCU(_in_ CU* cuPtr, _in_ uint64 offset, _in_ int size, bool direct_flag, bool inCUCache); + + // Load data from file into outbuf + // + void Load(_in_ uint64 offset, _in_ int size, __inout char* outbuf, bool direct_flag); + + int WSLoad(_in_ uint64 offset, _in_ int size, __inout char* outbuf, bool direct_flag); + + void GetFileName(_out_ char* fileName, _in_ const size_t capacity, _in_ const int fileId) const; + bool IsDataFileExist(int fileId) const; + + void GetBcmFileName(_out_ char* bcmfile, _in_ int fileId) const; + bool IsBcmFileExist(_in_ int fileId) const; + + const char* GetColumnFileName() const; + + uint64 AllocSpace(_in_ int size); + + void FlushDataFile() const; + + void SetAllocateStrategy(CStoreAllocateStrategy strategy) + { + m_strategy = strategy; + }; + + void SetFreeSpace(CStoreFreeSpace* fspace) + { + Assert(fspace != NULL); + m_freespace = fspace; + }; + + FORCE_INLINE CStoreFreeSpace* GetFreeSpace() + { + return m_freespace; + }; + + void CreateStorage(int fileId, bool isRedo) const; + + File GetCUFileFd(uint64 offset); + uint64 GetCUOffsetInFile(uint64 offset) const; + bool IsCUStoreInOneFile(uint64 offset, int size) const; + uint64 GetAlignCUOffset(uint64 offset) const; + int GetAlignCUSize(int size) const; + void FastExtendFile(uint64 extend_offset, uint32 size, bool keep_size); + void TruncateDataFile(); + void TruncateBcmFile(); + void Set2ByteAlign(bool is_2byte_align); + bool Is2ByteAlign(); + +private: + void InitFileNamePrefix(_in_ const CFileNode& cFileNode); + File CreateFile(_in_ char* file_name, _in_ int fileId, bool isRedo) const; + File OpenFile(_in_ char* file_name, _in_ int fileId, bool direct_flag); + File WSOpenFile(_in_ char* file_name, _in_ int fileId, bool direct_flag); + void InitCstoreFreeSpace(CStoreAllocateStrategy strategy); + void CloseFile(_in_ File fd) const; + +public: + CFileNode m_cnode; + +private: + // The common prefix of column file name + char m_fileNamePrefix[MAXPGPATH]; + + // The column file name + char m_fileName[MAXPGPATH]; + + // free space alloctor. + CStoreFreeSpace* m_freespace; + + // Currently read/write fd + File m_fd; + + // allocate strategy: append; reuse + CStoreAllocateStrategy m_strategy; + + bool append_only; + + bool is_2byte_align; +}; + +// Notice: the following functions are in physical/low level. +// they don't know CU's concept, and just load data from file. +// +class CUFile : public BaseObject { +public: + CUFile(const RelFileNode& fileNode, int col); + virtual void Destroy(); + virtual ~CUFile(); + char* Read(uint64 offset, int wantSize, int* realSize, int align_size); + +private: + CUStorage* m_colStorage; + +// private buffer +// +#define CUFILE_MAX_BUF_SIZE (512 * 1024) + char* m_buffer; + int m_maxpos; + + // we have to remember the total size and current offset about the physical file. + // that's because neither CU nor CU desc exists, and we cannot know the valid + // offset and size to read. + // + int m_fileId; + uint32 m_maxFileSize; + uint32 m_curFileOffset; +}; + +extern uint64 GetColDataFileSize(Relation rel, int attid); + +extern const uint64 MAX_FILE_SIZE; +// get file id and offset in this file +#define CU_FILE_ID(__pos) ((__pos) / MAX_FILE_SIZE) +#define CU_FILE_OFFSET(__pos) ((__pos) % MAX_FILE_SIZE) + +#define relcolpath(custorage_ptr) ((custorage_ptr)->GetColumnFileName()) + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/dfs/dfscache_mgr.h postgresql-hll-2.14/include/include/storage/dfs/dfscache_mgr.h --- postgresql-hll-2.14_old/include/include/storage/dfs/dfscache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/dfs/dfscache_mgr.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfscache_mgr.h + * routines to support dfs + * + * + * IDENTIFICATION + * src/include/storage/dfs/dfscache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef METACACHEMGR_H +#define METACACHEMGR_H + +#include +#include "orc_proto.pb.h" +#include "storage/cache_mgr.h" +#include "storage/relfilenode.h" + +#define MetaCache (MetaCacheMgr::GetInstance()) + +typedef struct OrcMetadataTag { + RelFileNodeOld fileNode; + int32 fileID; + uint32 stripeID; + uint32 columnID; + uint64 padding; +} OrcMetadataTag; + +typedef struct OrcMetadataValue { + /* + * The value of element pointer could be de-referenced into 'DfsInsert *' or + * 'PartitionStagingFile *' + */ + /* type 1 metadeta, file level, only need relID,fileID */ + uint64 footerStart; + std::string* postScript; + std::string* fileFooter; + + /* type 2 metadata, column and stripe level */ + std::string* stripeFooter; + std::string* rowIndex; + + int size; + + /* used in OBS file */ + char* fileName; + + /* data DNA, used in OBS foreign table file */ + char* dataDNA; +} OrcMetadataValue; + +typedef struct CarbonMetadataTag { + RelFileNodeOld fileNode; + int32 fileID; + uint32 BlockletID; + uint32 columnID; + uint64 padding; +} CarbonMetadataTag; + +typedef struct CarbonMetadataValue { + /* type 1 metadeta, file level, only need relID,fileID */ + uint64 headerSize; + uint64 footerSize; + unsigned char* fileHeader; + unsigned char* fileFooter; + + uint64 size; + + /* used in OBS file */ + char* fileName; + + /* data DNA, used in OBS foreign table file */ + char* dataDNA; +} CarbonMetadataValue; + +typedef union MetadataTag { + OrcMetadataTag OrcMetaTag; + CarbonMetadataTag CarbonMetaTag; +} MetadataTag; + +typedef struct MetadataTagKey { + CacheType type; + MetadataTag key; +} MetadataTagKey; + +/* Partition search cache support */ +typedef struct OrcMetadataEntry { + /* key of cache entry */ + OrcMetadataTag key; + int32 slot_id; +} OrcMetadataEntry; + +int MetaCacheMgrNumLocks(); +void ReleaseMetaBlock(CacheSlotId_t slotId); +bool MetaCacheRenewBlock(CacheSlotId_t slotId); +OrcMetadataValue* OrcMetaCacheGetBlock(CacheSlotId_t slotId); +CarbonMetadataValue* CarbonMetaCacheGetBlock(CacheSlotId_t slotId); +int OrcMetaCacheGetBlockSize(CacheSlotId_t slotId); +int CarbonMetaCacheGetBlockSize(CacheSlotId_t slotId); +void MetaCacheSetBlockWithFileName(CacheSlotId_t slotId, const char* fileName); +CacheSlotId_t MetaCacheAllocBlock( + RelFileNodeOld* fileNode, int32 fileID, uint32 stripeOrBlocketID, uint32 columnID, bool& found, int type); +void OrcMetaCacheSetBlock(CacheSlotId_t slotId, uint64 footerStart, const orc::proto::PostScript* postScript, + const orc::proto::Footer* fileFooter, const orc::proto::StripeFooter* stripeFooter, + const orc::proto::RowIndex* rowIndex, const char* fileName, const char* dataDNA); +void CarbonMetaCacheSetBlock(CacheSlotId_t slotId, uint64 headerSize, uint64 footerSize, unsigned char* fileHeader, + unsigned char* fileFooter, const char* fileName, const char* dataDNA); + +class MetaCacheMgr : public BaseObject { +public: + virtual ~MetaCacheMgr() + {} + static MetaCacheMgr* GetInstance(void); + static void NewSingletonInstance(void); + bool ReserveMetaBlockWithSlotId(CacheSlotId_t slotId); + void UnPinMetaBlock(CacheSlotId_t slotId); + + int64 GetCurrentMemSize(); + + void AbortMetaBlock(CacheSlotId_t slotId); + /* Manage I/O busy CUs */ + bool MetaBlockWaitIO(int slotId); + void MetaBlockCompleteIO(int slotId); + int GetOrcMetaBlockSize(CacheSlotId_t slotId); + int GetCarbonMetaBlockSize(CacheSlotId_t slotId); + void SetOrcMetaBlockValue(CacheSlotId_t slotId, uint64 footerStart, const orc::proto::PostScript* postScript, + const orc::proto::Footer* fileFooter, const orc::proto::StripeFooter* stripeFooter, + const orc::proto::RowIndex* rowIndex, const char* fileName, const char* dataDNA); + void SetCarbonMetaBlockValue(CacheSlotId_t slotId, uint64 headerSize, uint64 footerSize, unsigned char* fileHeader, + unsigned char* fileFooter, const char* fileName, const char* dataDNA); + + CacheSlotId_t FindMetaBlock(CacheTag cacheTag); + OrcMetadataValue* GetOrcMetaBlock(CacheSlotId_t slotId); + CarbonMetadataValue* GetCarbonMetaBlock(CacheSlotId_t slotId); + CacheSlotId_t ReserveMetaBlock(CacheTag cacheTag, bool& hasFound); + void PrintMetaCacheSlotLeakWarning(CacheSlotId_t slotId); + void ReleaseMetadataValue(CarbonMetadataValue* nvalue); + OrcMetadataTag InitOrcMetadataTag(RelFileNodeOld* fileNode, int32 fileID, uint32 stripeID, uint32 columnID); + CarbonMetadataTag InitCarbonMetadataTag(RelFileNodeOld* fileNode, int32 fileID, uint32 stripeID, uint32 columnID); + int64 m_cstoreMaxSize; + +private: + MetaCacheMgr() + {} + int CalcOrcMetaBlockSize(OrcMetadataValue* nvalue) const; + int CalcCarbonMetaBlockSize(CarbonMetadataValue* nvalue) const; + void SetOrcMetaBlockSize(CacheSlotId_t slotId, int size); + void SetCarbonMetaBlockSize(CacheSlotId_t slotId, int size); + void ReleaseOrcMetadataValue(OrcMetadataValue* nvalue) const; + void ReleaseCarbonMetadataValue(CarbonMetadataValue* nvalue) const; + static MetaCacheMgr* m_meta_cache; + CacheMgr* m_cache_mgr; +}; + +#endif /* define */ diff -uprN postgresql-hll-2.14_old/include/include/storage/dfs/dfs_connector.h postgresql-hll-2.14/include/include/storage/dfs/dfs_connector.h --- postgresql-hll-2.14_old/include/include/storage/dfs/dfs_connector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/dfs/dfs_connector.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,287 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_connector.h + * + * + * + * IDENTIFICATION + * src/include/storage/dfs/dfs_connector.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_CONNECTOR_H +#define DFS_CONNECTOR_H + +#include +#include "dfs_config.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "foreign/foreign.h" +#include "miscadmin.h" +#include "nodes/pg_list.h" + +#define DEFAULT_PERM_MOD (384) + +/* + * DfsSrvOptions holds the option values to be used + * when connecting external server. + */ +typedef struct DfsSrvOptions { + char* filesystem; + char* address; + char* cfgPath; + char* storePath; +} DfsSrvOptions; + +/* + * conn + */ +enum ConnectorType { HDFS_CONNECTOR = 0, OBS_CONNECTOR = 1, UNKNOWN_CONNECTOR }; + +namespace dfs { +/* Store the block information of the file of dfs system. */ +class DFSBlockInfo : public BaseObject { +public: + virtual ~DFSBlockInfo() + {} + + /* Get the number of replications of the current file. */ + virtual int getNumOfReplica() const = 0; + /* + * Get the string including IP:xferPort for accessing the block in the node. + * @_in_param blockIdx: The index of the block to search of the file. + * @_in_param nodeIdx: The index of the node on which to seatch the block. + * @return the string including IP:xferPort. + */ + virtual const char* getNames(int blockIdx, int nodeIdx) const = 0; + + /* + * get whether the location is cached + * @_in_param blockIdx: The index of the block to search of the file. + * @_in_param nodeIdx: The index of the node on which to search the block. + * @return cached-true uncached - false. + */ + virtual bool isCached(int blockIdx, int nodeIdx) const = 0; +}; + +class DFSConnector : public BaseObject { +public: + virtual ~DFSConnector() + {} + + /* + * Check if the path in hdfs is a file not directory, log error if the path does not + * exist. + * @_in param filePath: the path of the hdfs file/directory. + * @return Return true: the path is a file; false: the path is not a file but a directory. + */ + virtual bool isDfsFile(const char* filePath) = 0; + virtual bool isDfsFile(const char* filePath, bool throw_error) = 0; + + /* Check if the path is a empty file, log error if the path does not exist. */ + virtual bool isDfsEmptyFile(const char* filePath) = 0; + + /* + * Get the file size of the path. Return -1 if the path does not exist. + * @_in_param filePath: the path of the hdfs file/directory + * @return Return the size. + */ + virtual int64_t getFileSize(const char* filePath) = 0; + + /* Get the handler to connect the DFS system. */ + virtual void* getHandler() const = 0; + + /* + * Get list of files/directories for a given directory-path. + * hdfsFreeFileInfo is called internally to deallocate memory. + * Log error if the path does not exist. + * @_in_param folderPath: The path of the directory. + * @return Return a list of filepath. Return NULL on error. + */ + virtual List* listDirectory(char* folderPath) = 0; + virtual List* listDirectory(char* folderPath, bool throw_error) = 0; + + virtual List* listObjectsStat(char* searchPath, const char* prefix = NULL) = 0; + + /* + * Get the block information of the file path. + * Log error if the path does not exist. + * @_in_param filePath: The path of the file. + * @return Return a pointer to DFSBlockInfo. + */ + virtual DFSBlockInfo* getBlockLocations(char* filePath) = 0; + + /* + * Drop directory. Return 0 if the path does not exist. + * @_in_param path The path of the directory. + * @_in_param recursive if path is a directory and set to + * non-zero, the directory is deleted else throws an exception. In + * case of a file the recursive argument is irrelevant. + * @return Returns 0 on success, -1 on error. + */ + virtual int dropDirectory(const char* path, int recursive) = 0; + + /* + * Make a directory using the given path. + * @_in_param path The path of the directory. + * @return Returns 0 on success, -1 on error. + */ + virtual int createDirectory(const char* path) = 0; + + /* + * Make a file using the given path. + * @_in_param path The path of the file to make. + * @_in_param flags - an | of bits/fcntl.h file flags - supported flags + * are O_RDONLY, O_WRONLY (meaning create or overwrite i.e., implies O_TRUNCAT), + * O_WRONLY|O_APPEND and O_SYNC. Other flags are generally ignored other than + * (O_RDWR || (O_EXCL & O_CREAT)) which return NULL and set errno equal ENOTSUP. + * return Returns 0 on success, -1 on error. + */ + virtual int openFile(const char* path, int flag) = 0; + + /* Delete the file using the given file path. Before calling this + * function, pathExists must be checked. + * @_in_param path The path of the file. + * @_in_param recursive if path is a directory and set to + * non-zero, the directory is deleted else throws an exception. In + * case of a file the recursive argument is irrelevant. + * @return Returns 0 on success, -1 on error. + */ + virtual int deleteFile(const char* path, int recursive) = 0; + + /* + * pathExists - Checks if a given path exsits on the filesystem + * @param path The path to look for + * @return Returns 0 on success, -1 on error. + */ + virtual bool pathExists(const char* filePath) = 0; + + virtual bool existsFile(const char* path) = 0; + + /* + * check if the current connector has a valid hdfs file handler. + * @return true if the file handler is valid, false on invalid. + */ + virtual bool hasValidFile() const = 0; + + /* + * Write the buffer into the current file according to the length. + * @_in_param buffer: The content to be write to file. + * @_in_param length: The length of the byte to write. + * @return Return the bytes actually write, -1 on error. + */ + virtual int writeCurrentFile(const char* buffer, int length) = 0; + + /* + * Read fixed size from the offset of the file into the buffer. + * @_out_param buffer: The buffer to be filled. + * @_in_param length: The size of bytes expected. + * @_in_param offset: The offset at which the reading starts. + * @return the bytes actually read, -1 on error. + */ + virtual int readCurrentFileFully(char* buffer, int length, int64 offset) = 0; + + /* + * Flush out the data in client's user buffer. After the return of this call, + * new readers will see the data. + * @return 0 on success, -1 on error and sets errno + */ + virtual int flushCurrentFile() = 0; + + /* + * Close the current file. + */ + virtual void closeCurrentFile() = 0; + + /* + * change the file's authority. + * @_in_param filePath: The absolute path of the file to be set. + * @_in_param mode: The mode of the authority like 600 or 755. + * Return 0 if succeed. Return 1 if fail. + */ + virtual int chmod(const char* filePath, short mode) = 0; + + /* + * Set the label expression on dfs file. + * @_in_param filePath: The absolute path of the file to be set. + * @_in_param expression: The label string like "labelA,labelB". + * Return 0 if succeed. Return 1 if fail. + */ + virtual int setLabelExpression(const char* filePath, const char* expression) = 0; + + /* + * Get the timestamp of the last modification. + */ + virtual int64 getLastModifyTime(const char* filePath) = 0; + + /* + * Fetch the configure value from the config file. + */ + virtual const char* getValue(const char* key, const char* defValue) const = 0; + + /* + * Get connection type + */ + virtual int getType() = 0; +}; + +/* + * Construct a connector of DFS which wrappers all the approaches to the DFS. + * @_in_param ctx: The memory context on which to create the connector(not used for now). + * @_in_param foreignTableId: The oid of the relation for which we create the connector. + * @return the constructed connector. + */ +DFSConnector* createConnector(MemoryContext ctx, Oid foreignTableId); +DFSConnector* createTempConnector(MemoryContext ctx, Oid foreignTableId); +DFSConnector* createConnector(MemoryContext ctx, ServerTypeOption srvType, void* options); + +/* + * Construct a connector of DFS which wrappers all the approaches to the DFS. + * @_in_param ctx: The memory context on which to create the connector(not used for now). + * @_in_param srvOptions: information of the server option. + * @_in_param tablespaceOid: tablespace oid. + * @return the constructed connector. + */ +DFSConnector* createConnector(MemoryContext ctx, DfsSrvOptions* srvOptions, Oid tablespaceOid); +DFSConnector* createTempConnector(MemoryContext ctx, DfsSrvOptions* srvOptions, Oid tablespaceOid); + +/* Initialize the global hdfs connector cache hash table. */ +void InitHDFSConnectorCacheLock(); + +/* Remove the connector entry of the hdfs cache according to the server oid. */ +void InvalidHDFSConnectorCache(Oid serverOid); + +/* Initialize the global obs connector cache hash table. */ +void InitOBSConnectorCacheLock(); + +/* + * Remove the connector entry of the obs cache according to the server oid. + * return true if clean it successfully, otherwise return false. + */ +bool InvalidOBSConnectorCache(Oid serverOid); + +/* Clean the thread local variables in kerberos. */ +void clearKerberosObjs(); + +} // namespace dfs + +/* check file path should skip */ +bool checkFileShouldSkip(char* fileName); + +/* check file path should skip */ +bool checkPathShouldSkip(char* pathName); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/fd.h postgresql-hll-2.14/include/include/storage/fd.h --- postgresql-hll-2.14_old/include/include/storage/fd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/fd.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,165 @@ +/* ------------------------------------------------------------------------- + * + * fd.h + * Virtual file descriptor definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fd.h + * + * ------------------------------------------------------------------------- + */ + +/* + * calls: + * + * File {Close, Read, Write, Seek, Tell, Sync} + * {Path Name Open, Allocate, Free} File + * + * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES. + * Use them for all file activity... + * + * File fd; + * fd = FilePathOpenFile("foo", O_RDONLY, 0600); + * + * AllocateFile(); + * FreeFile(); + * + * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then + * use FreeFile, not fclose, to close it. AVOID using stdio for files + * that you intend to hold open for any length of time, since there is + * no way for them to share kernel file descriptors with other files. + * + * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate + * open directories (DIR*), and OpenTransientFile/CloseTransient File for an + * unbuffered file descriptor. + */ +#ifndef FD_H +#define FD_H + +#include +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "postmaster/aiocompleter.h" + +/* + * FileSeek uses the standard UNIX lseek(2) flags. + */ + +typedef char* FileName; + +typedef int File; + +#define FILE_INVALID (-1) + +typedef struct DataFileIdCacheEntry { + /* key field */ + RelFileNodeForkNum dbfid; /* file id */ + /* the following are setted in runtime */ + int fd; + int refcount; +} DataFileIdCacheEntry; + +enum FileExistStatus { FILE_EXIST, FILE_NOT_EXIST, FILE_NOT_REG }; + +/* + * prototypes for functions in fd.c + */ + +/* Operations on virtual Files --- equivalent to Unix kernel file ops */ +extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode, File file = FILE_INVALID); +extern File OpenTemporaryFile(bool interXact); +extern void FileClose(File file); +extern void FileCloseWithThief(File file); +extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info = 0); +extern int FileSync(File file, uint32 wait_event_info = 0); +extern off_t FileSeek(File file, off_t offset, int whence); +extern int FileTruncate(File file, off_t offset, uint32 wait_event_info = 0); +extern void FileWriteback(File file, off_t offset, off_t nbytes); +extern char* FilePathName(File file); + +extern void FileAsyncCUClose(File* vfdList, int32 vfdnum); +extern int FileAsyncRead(AioDispatchDesc_t** dList, int32 dn); +extern int FileAsyncWrite(AioDispatchDesc_t** dList, int32 dn); +extern int FileAsyncCURead(AioDispatchCUDesc_t** dList, int32 dn); +extern int FileAsyncCUWrite(AioDispatchCUDesc_t** dList, int32 dn); +extern void FileFastExtendFile(File file, uint32 offset, uint32 size, bool keep_size); +extern int FileRead(File file, char* buffer, int amount); +extern int FileWrite(File file, const char* buffer, int amount, off_t offset); + +// Threading virtual files IO interface, using pread() / pwrite() +// +extern int FilePRead(File file, char* buffer, int amount, off_t offset, uint32 wait_event_info = 0); +extern int FilePWrite(File file, const char* buffer, int amount, off_t offset, uint32 wait_event_info = 0); + +extern int AllocateSocket(const char* ipaddr, int port); +extern int FreeSocket(int sockfd); + +/* Operations that allow use of regular stdio --- USE WITH CAUTION */ +extern FILE* AllocateFile(const char* name, const char* mode); +extern int FreeFile(FILE* file); + +extern File OpenCacheFile(const char* pathname, bool unlink_owner); +extern void UnlinkCacheFile(const char* pathname); + +/* Operations to allow use of the library routines */ +extern DIR* AllocateDir(const char* dirname); +extern struct dirent* ReadDir(DIR* dir, const char* dirname); +extern int FreeDir(DIR* dir); +/* Operations to allow use of a plain kernel FD, with automatic cleanup */ +extern int OpenTransientFile(FileName fileName, int fileFlags, int fileMode); +extern int CloseTransientFile(int fd); +/* If you've really really gotta have a plain kernel FD, use this */ +extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode); + +/* Miscellaneous support routines */ +extern void InitFileAccess(void); +extern void set_max_safe_fds(void); +extern void CloseGaussPidDir(void); +extern void closeAllVfds(void); +extern void SetTempTablespaces(Oid* tableSpaces, int numSpaces); +extern bool TempTablespacesAreSet(void); +extern Oid GetNextTempTableSpace(void); +extern void AtEOXact_Files(void); +extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern void AtProcExit_Files(int code, Datum arg); +extern void RemovePgTempFiles(void); + +extern void RemoveErrorCacheFiles(); +extern int FileFd(File file); + +extern int pg_fsync(int fd); +extern int pg_fsync_no_writethrough(int fd); +extern int pg_fsync_writethrough(int fd); +extern int pg_fdatasync(int fd); +extern void pg_flush_data(int fd, off_t offset, off_t amount); +extern void DestroyAllVfds(void); + +extern void InitDataFileIdCache(void); +extern Size DataFileIdCacheSize(void); +extern File DataFileIdOpenFile( + FileName fileName, const RelFileNodeForkNum& fileNode, int fileFlags, int fileMode, File file = FILE_INVALID); + +extern RelFileNodeForkNum RelFileNodeForkNumFill( + const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber segno); + +extern void FreeAllAllocatedDescs(void); +extern void GetFdGlobalVariables(void*** global_VfdCache, Size** global_SizeVfdCache); +extern void SwitchToGlobalVfdCache(void** vfd, Size* vfd_size); +extern void ResetToLocalVfdCache(); + +extern int data_sync_elevel(int elevel); + +extern bool FdRefcntIsZero(SMgrRelation reln, ForkNumber forkNum); +extern FileExistStatus CheckFileExists(const char* path); + +/* Filename components for OpenTemporaryFile */ +// Note that this macro must be the same to macro in initdb.cpp +// If you change it, you must also change initdb.cpp +// +#define PG_TEMP_FILES_DIR "pgsql_tmp" +#define PG_TEMP_FILE_PREFIX "pgsql_tmp" + +#endif /* FD_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/freespace.h postgresql-hll-2.14/include/include/storage/freespace.h --- postgresql-hll-2.14_old/include/include/storage/freespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/freespace.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * freespace.h + * POSTGRES free space map for quickly finding free space in relations + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/freespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FREESPACE_H_ +#define FREESPACE_H_ + +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef uint64 XLogRecPtr; + + +/* + * We use just one byte to store the amount of free space on a page, so we + * divide the amount of free space a page can have into 256 different + * categories. The highest category, 255, represents a page with at least + * MaxFSMRequestSize bytes of free space, and the second highest category + * represents the range from 254 * FSM_CAT_STEP, inclusive, to + * MaxFSMRequestSize, exclusive. + * + * MaxFSMRequestSize depends on the architecture and BLCKSZ, but assuming + * default 8k BLCKSZ, and that MaxFSMRequestSize is 24 bytes, the categories + * look like this + * + * + * Range Category + * 0 - 31 0 + * 32 - 63 1 + * ... ... ... + * 8096 - 8127 253 + * 8128 - 8163 254 + * 8164 - 8192 255 + * + * The reason that MaxFSMRequestSize is special is that if MaxFSMRequestSize + * isn't equal to a range boundary, a page with exactly MaxFSMRequestSize + * bytes of free space wouldn't satisfy a request for MaxFSMRequestSize + * bytes. If there isn't more than MaxFSMRequestSize bytes of free space on a + * completely empty page, that would mean that we could never satisfy a + * request of exactly MaxFSMRequestSize bytes. + */ +#define FSM_CATEGORIES 256 +#define FSM_CAT_STEP (BLCKSZ / FSM_CATEGORIES) +#define MaxFSMRequestSize MaxHeapTupleSize + +/* + * Depth of the on-disk tree. We need to be able to address 2^32-1 blocks, + * and 1626 is the smallest number that satisfies X^3 >= 2^32-1. Likewise, + * 216 is the smallest number that satisfies X^4 >= 2^32-1. In practice, + * this means that 4096 bytes is the smallest BLCKSZ that we can get away + * with a 3-level tree, and 512 is the smallest we support. + */ +#define FSM_TREE_DEPTH ((SlotsPerFSMPage >= 1626) ? 3 : 4) + +#define FSM_ROOT_LEVEL (FSM_TREE_DEPTH - 1) +#define FSM_BOTTOM_LEVEL 0 + +/* + * The internal FSM routines work on a logical addressing scheme. Each + * level of the tree can be thought of as a separately addressable file. + */ +typedef struct { + int level; /* level */ + int logpageno; /* page number within the level */ +} FSMAddress; + + + +/* prototypes for public functions in freespace.c */ +extern Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk); +extern BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded); +extern BlockNumber RecordAndGetPageWithFreeSpace( + Relation rel, BlockNumber oldPage, Size oldSpaceAvail, Size spaceNeeded); +extern void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail); +extern void XLogRecordPageWithFreeSpace(const RelFileNode& rnode, BlockNumber heapBlk, Size spaceAvail); + +extern void FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks); +extern void FreeSpaceMapVacuum(Relation rel); +extern void UpdateFreeSpaceMap(Relation rel, BlockNumber firtsBlkNum, BlockNumber lastBlkNum, Size freespace); +extern BlockNumber FreeSpaceMapCalTruncBlkNo(BlockNumber relBlkNo); +extern void XLogBlockTruncateRelFSM(Relation rel, BlockNumber nblocks); +extern FSMAddress fsm_get_location(BlockNumber heapblk, uint16* slot); +extern BlockNumber fsm_logical_to_physical(const FSMAddress& addr); +extern uint8 fsm_space_avail_to_cat(Size avail); +extern bool fsm_set_avail(Page page, int slot, uint8 value); + +#endif /* FREESPACE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/storage/fsm_internals.h postgresql-hll-2.14/include/include/storage/fsm_internals.h --- postgresql-hll-2.14_old/include/include/storage/fsm_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/fsm_internals.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,68 @@ +/* ------------------------------------------------------------------------- + * + * fsm_internal.h + * internal functions for free space map + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fsm_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FSM_INTERNALS_H +#define FSM_INTERNALS_H + +#include "storage/buf.h" +#include "storage/bufpage.h" + +/* + * Structure of a FSM page. See src/backend/storage/freespace/README for + * details. + */ +typedef struct { + /* + * fsm_search_avail() tries to spread the load of multiple backends by + * returning different pages to different backends in a round-robin + * fashion. fp_next_slot points to the next slot to be returned (assuming + * there's enough space on it for the request). It's defined as an int, + * because it's updated without an exclusive lock. uint16 would be more + * appropriate, but int is more likely to be atomically + * fetchable/storable. + */ + int fp_next_slot; + + /* + * fp_nodes contains the binary tree, stored in array. The first + * NonLeafNodesPerPage elements are upper nodes, and the following + * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero. + */ + uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]; +} FSMPageData; + +typedef FSMPageData* FSMPage; + +/* + * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page. + * These definitions are internal to fsmpage.c. + */ +#define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - offsetof(FSMPageData, fp_nodes)) + +#define NonLeafNodesPerPage (BLCKSZ / 2 - 1) +#define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage) + +/* + * Number of FSM "slots" on a FSM page. This is what should be used + * outside fsmpage.c. + */ +#define SlotsPerFSMPage LeafNodesPerPage + +/* Prototypes for functions in fsmpage.c */ +extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext, bool exclusive_lock_held); +extern uint8 fsm_get_avail(Page page, int slot); +extern uint8 fsm_get_max_avail(Page page); +extern bool fsm_truncate_avail(Page page, int nslots); +extern bool fsm_rebuild_page(Page page); + +#endif /* FSM_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/gds_utils.h postgresql-hll-2.14/include/include/storage/gds_utils.h --- postgresql-hll-2.14_old/include/include/storage/gds_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/gds_utils.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + *--------------------------------------------------------------------------------------- + * + * gds_utils.h + * + * IDENTIFICATION + * src/bin/gds/gds_utils.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GDS_UTILS_H +#define GDS_UTILS_H + +#ifndef WIN32 +#include +#else +#include +#endif + +typedef struct { + struct sockaddr_storage mask; + struct sockaddr_storage addr; +} listen_addr; + +bool check_ip(struct sockaddr_storage* raddr, struct sockaddr* addr, struct sockaddr* mask); + +int sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); +void TrimDirectory(char* path); +void CanonicalizePath(char* path); +int PGMkdirP(char* path, int omode); +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/indexfsm.h postgresql-hll-2.14/include/include/storage/indexfsm.h --- postgresql-hll-2.14_old/include/include/storage/indexfsm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/indexfsm.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * indexfsm.h + * POSTGRES free space map for quickly finding an unused page in index + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/indexfsm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEXFSM_H_ +#define INDEXFSM_H_ + +#include "storage/block.h" +#include "utils/relcache.h" + +extern BlockNumber GetFreeIndexPage(Relation rel); +extern void RecordFreeIndexPage(Relation rel, BlockNumber page); +extern void RecordUsedIndexPage(Relation rel, BlockNumber page); + +extern void IndexFreeSpaceMapVacuum(Relation rel); + +#endif /* INDEXFSM_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/storage/ipc.h postgresql-hll-2.14/include/include/storage/ipc.h --- postgresql-hll-2.14_old/include/include/storage/ipc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/ipc.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * ipc.h + * POSTGRES inter-process communication definitions. + * + * This file is misnamed, as it no longer has much of anything directly + * to do with IPC. The functionality here is concerned with managing + * exit-time cleanup for either a postmaster or a backend. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/ipc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef IPC_H +#define IPC_H + +typedef void (*pg_on_exit_callback)(int code, Datum arg); +typedef void (*shmem_startup_hook_type)(void); + +extern volatile unsigned int alive_threads_waitted; + +#define DEC_NUM_ALIVE_THREADS_WAITTED() alive_threads_waitted-- + +extern void WaitGraceThreadsExit(void); + +/* ---------- + * API for handling cleanup that must occur during either ereport(ERROR) + * or ereport(FATAL) exits from a block of code. (Typical examples are + * undoing transient changes to shared-memory state.) + * + * PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg); + * { + * ... code that might throw ereport(ERROR) or ereport(FATAL) ... + * } + * PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg); + * + * where the cleanup code is in a function declared per pg_on_exit_callback. + * The Datum value "arg" can carry any information the cleanup function + * needs. + * + * This construct ensures that cleanup_function() will be called during + * either ERROR or FATAL exits. It will not be called on successful + * exit from the controlled code. (If you want it to happen then too, + * call the function yourself from just after the construct.) + * + * Note: the macro arguments are multiply evaluated, so avoid side-effects. + * ---------- + */ +#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \ + do { \ + on_shmem_exit(cleanup_function, arg); \ + PG_TRY() + +#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \ + cancel_shmem_exit(cleanup_function, arg); \ + PG_CATCH(); \ + { \ + cancel_shmem_exit(cleanup_function, arg); \ + cleanup_function(0, arg); \ + PG_RE_THROW(); \ + } \ + PG_END_TRY(); \ + } \ + while (0) + +struct knl_session_context; +extern void CloseClientSocket(knl_session_context* context, bool closesock); +extern void proc_exit(int code); +extern void sess_exit(int code); +extern void shmem_exit(int code); +extern void on_proc_exit(pg_on_exit_callback function, Datum arg); +extern void on_shmem_exit(pg_on_exit_callback function, Datum arg); +extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg); +extern void on_exit_reset(void); + +/* ipci.c */ +extern pthread_mutex_t gLocaleMutex; + +extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port); + +extern void cancelShmemExit(pg_on_exit_callback function, Datum arg); +#endif /* IPC_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/item.h postgresql-hll-2.14/include/include/storage/item.h --- postgresql-hll-2.14_old/include/include/storage/item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/item.h 2020-12-12 17:06:43.270348335 +0800 @@ -0,0 +1,19 @@ +/* ------------------------------------------------------------------------- + * + * item.h + * POSTGRES disk item definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/item.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEM_H +#define ITEM_H + +typedef Pointer Item; + +#endif /* ITEM_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/itemid.h postgresql-hll-2.14/include/include/storage/itemid.h --- postgresql-hll-2.14_old/include/include/storage/itemid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/itemid.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * itemid.h + * Standard POSTGRES buffer page item identifier definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/itemid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEMID_H +#define ITEMID_H + +/* + * An item pointer (also called line pointer) on a buffer page + * + * In some cases an item pointer is "in use" but does not have any associated + * storage on the page. By convention, lp_len == 0 in every item pointer + * that does not have storage, independently of its lp_flags state. + */ +typedef struct ItemIdData { + unsigned lp_off : 15, /* offset to tuple (from start of page) */ + lp_flags : 2, /* state of item pointer, see below */ + lp_len : 15; /* byte length of tuple */ +} ItemIdData; + +typedef ItemIdData* ItemId; + +/* + * lp_flags has these possible states. An UNUSED line pointer is available + * for immediate re-use, the other states are not. + */ +#define LP_UNUSED 0 /* unused (should always have lp_len=0) */ +#define LP_NORMAL 1 /* used (should always have lp_len>0) */ +#define LP_REDIRECT 2 /* HOT redirect (should have lp_len=0) */ +#define LP_DEAD 3 /* dead, may or may not have storage */ + +/* + * Item offsets and lengths are represented by these types when + * they're not actually stored in an ItemIdData. + */ +typedef uint16 ItemOffset; +typedef uint16 ItemLength; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * ItemIdGetLength + */ +#define ItemIdGetLength(itemId) ((itemId)->lp_len) + +/* + * ItemIdGetOffset + */ +#define ItemIdGetOffset(itemId) ((itemId)->lp_off) + +/* + * ItemIdGetFlags + */ +#define ItemIdGetFlags(itemId) ((itemId)->lp_flags) + +/* + * ItemIdGetRedirect + * In a REDIRECT pointer, lp_off holds the link to the next item pointer + */ +#define ItemIdGetRedirect(itemId) ((itemId)->lp_off) + +/* + * ItemIdIsValid + * True iff item identifier is valid. + * This is a pretty weak test, probably useful only in Asserts. + */ +#define ItemIdIsValid(itemId) PointerIsValid(itemId) + +/* + * ItemIdIsUsed + * True iff item identifier is in use. + */ +#define ItemIdIsUsed(itemId) ((itemId)->lp_flags != LP_UNUSED) + +/* + * ItemIdIsNormal + * True iff item identifier is in state NORMAL. + */ +#define ItemIdIsNormal(itemId) ((itemId)->lp_flags == LP_NORMAL) + +/* + * ItemIdIsRedirected + * True iff item identifier is in state REDIRECT. + */ +#define ItemIdIsRedirected(itemId) ((itemId)->lp_flags == LP_REDIRECT) + +/* + * ItemIdIsDead + * True iff item identifier is in state DEAD. + */ +#define ItemIdIsDead(itemId) ((itemId)->lp_flags == LP_DEAD) + +/* + * ItemIdHasStorage + * True iff item identifier has associated storage. + */ +#define ItemIdHasStorage(itemId) ((itemId)->lp_len != 0) + +/* + * ItemIdSetUnused + * Set the item identifier to be UNUSED, with no storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetUnused(itemId) ((itemId)->lp_flags = LP_UNUSED, (itemId)->lp_off = 0, (itemId)->lp_len = 0) + +/* + * ItemIdSetNormal + * Set the item identifier to be NORMAL, with the specified storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetNormal(itemId, off, len) \ + ((itemId)->lp_flags = LP_NORMAL, (itemId)->lp_off = (off), (itemId)->lp_len = (len)) + +/* + * ItemIdSetRedirect + * Set the item identifier to be REDIRECT, with the specified link. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetRedirect(itemId, link) \ + ((itemId)->lp_flags = LP_REDIRECT, (itemId)->lp_off = (link), (itemId)->lp_len = 0) + +/* + * ItemIdSetDead + * Set the item identifier to be DEAD, with no storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetDead(itemId) ((itemId)->lp_flags = LP_DEAD, (itemId)->lp_off = 0, (itemId)->lp_len = 0) + +/* + * ItemIdMarkDead + * Set the item identifier to be DEAD, keeping its existing storage. + * + * Note: in indexes, this is used as if it were a hint-bit mechanism; + * we trust that multiple processors can do this in parallel and get + * the same result. + */ +#define ItemIdMarkDead(itemId) ((itemId)->lp_flags = LP_DEAD) + +#endif /* ITEMID_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/itemptr.h postgresql-hll-2.14/include/include/storage/itemptr.h --- postgresql-hll-2.14_old/include/include/storage/itemptr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/itemptr.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,223 @@ +/* ------------------------------------------------------------------------- + * + * itemptr.h + * POSTGRES disk item pointer definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/itemptr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEMPTR_H +#define ITEMPTR_H + +#include "storage/block.h" +#include "storage/off.h" + +/* + * ItemPointer: + * + * This is a pointer to an item within a disk page of a known file + * (for example, a cross-link from an index to its parent table). + * blkid tells us which block, posid tells us which entry in the linp + * (ItemIdData) array we want. + * + * Note: because there is an item pointer in each tuple header and index + * tuple header on disk, it's very important not to waste space with + * structure padding bytes. The struct is designed to be six bytes long + * (it contains three int16 fields) but a few compilers will pad it to + * eight bytes unless coerced. We apply appropriate persuasion where + * possible, and to cope with unpersuadable compilers, we try to use + * "SizeOfIptrData" rather than "sizeof(ItemPointerData)" when computing + * on-disk sizes. + */ +typedef struct ItemPointerData { + BlockIdData ip_blkid; + OffsetNumber ip_posid; +} + +#ifdef __arm__ +__attribute__((packed)) /* Appropriate whack upside the head for ARM */ +#endif +ItemPointerData; + +#define SizeOfIptrData (offsetof(ItemPointerData, ip_posid) + sizeof(OffsetNumber)) + +typedef ItemPointerData* ItemPointer; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * ItemPointerIsValid + * True iff the disk item pointer is not NULL. + */ +#define ItemPointerIsValid(pointer) ((bool)(PointerIsValid(pointer) && ((pointer)->ip_posid != 0))) + +/* + * ItemPointerGetBlockNumber + * Returns the block number of a disk item pointer. + */ +#define ItemPointerGetBlockNumber(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetBlockNumberNoCheck + * Returns the block number of a disk item pointer. + */ +#define ItemPointerGetBlockNumberNoCheck(pointer) (BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetOffsetNumberNoCheck + * Returns the offset number of a disk item pointer. + */ +#define ItemPointerGetOffsetNumberNoCheck(pointer) ((pointer)->ip_posid) + +/* + * ItemPointerGetOffsetNumber + * Returns the offset number of a disk item pointer. + */ +#define ItemPointerGetOffsetNumber(pointer) (AssertMacro(ItemPointerIsValid(pointer)), (pointer)->ip_posid) + +/* + * ItemPointerSet + * Sets a disk item pointer to the specified block and offset. + */ +#define ItemPointerSet(pointer, blockNumber, offNum) \ + (AssertMacro(PointerIsValid(pointer)), \ + BlockIdSet(&((pointer)->ip_blkid), blockNumber), \ + (pointer)->ip_posid = offNum) + +/* + * ItemPointerZero + * Sets a disk item pointer to zero. + */ +#define ItemPointerZero(pointer) \ + (AssertMacro(PointerIsValid(pointer)), \ + (pointer)->ip_blkid.bi_hi = 0, \ + (pointer)->ip_blkid.bi_lo = 0, \ + (pointer)->ip_posid = 0) + +/* + * ItemPointerSetBlockNumber + * Sets a disk item pointer to the specified block. + */ +#define ItemPointerSetBlockNumber(pointer, blockNumber) \ + (AssertMacro(PointerIsValid(pointer)), BlockIdSet(&((pointer)->ip_blkid), blockNumber)) + +/* + * ItemPointerSetOffsetNumber + * Sets a disk item pointer to the specified offset. + */ +#define ItemPointerSetOffsetNumber(pointer, offsetNumber) \ + (AssertMacro(PointerIsValid(pointer)), (pointer)->ip_posid = (offsetNumber)) + +/* + * ItemPointerCopy + * Copies the contents of one disk item pointer to another. + * + * Should there ever be padding in an ItemPointer this would need to be handled + * differently as it's used as hash key. + */ +#define ItemPointerCopy(fromPointer, toPointer) \ + (AssertMacro(PointerIsValid(toPointer)), AssertMacro(PointerIsValid(fromPointer)), *(toPointer) = *(fromPointer)) + +/* + * ItemPointerSetInvalid + * Sets a disk item pointer to be invalid. + */ +#define ItemPointerSetInvalid(pointer) \ + (AssertMacro(PointerIsValid(pointer)), \ + BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber), \ + (pointer)->ip_posid = InvalidOffsetNumber) + +/* ---------------- + * externs + * ---------------- + */ + +extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2); +extern int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2); + +/* -------------------------------------------------------- + * support macros for dfs ItemPointer + * + * ------------------------------------- + * | 0 | 1 | 2 | 3 | 4 | 5 | memory address(low->high) + * ------------------------------------- + * | ip_blkid | ip_posid | \ + * ------------------------------------- ItemPointerData + * | bi_hi | bi_lo | ip_posid | / + * ------------------------------------- + * | file_id | offset | layout of ItemPointerData for dfs + * ------------------------------------- + * + * for compatibility, only 23 bits of "offset" is dedicated for position in file, + * the highest bit of "ip_posid" is always 1 for valid dfs tid, so the low 8 bit + * of bi_lo and the low 15 bit of ip_posid are used for offset. + * + * Just get/set macros are provided here, the design of tid for dfs provides the + * most compatibility with others macro and function of tid of row and column + * storage. For example, you can use ItemPointerIsValid() to check dfs tid. + * -------------------------------------------------------- + */ + +#define DfsInvalidBlockNumber ((BlockNumber)0x00FFFFFF) +#define DfsMaxBlockNumber ((BlockNumber)0x00FFFFFE) + +#define DfsInvalidOffsetNumber ((uint32)0) +#define DfsFirstOffsetNumber ((uint32)1) +#define DfsMaxOffset (0x007fffff) + +/* + * DfsItemPointerGetFileId + * Returns the file id of a dfs item pointer. + */ +#define DfsItemPointerGetFileId(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), \ + (BlockNumber)(((pointer)->ip_blkid).bi_hi << 8) | (BlockNumber)(((pointer)->ip_blkid).bi_lo >> 8)) + +/* + * DfsItemPointerGetOffset + * Returns the offset in file of a dfs item pointer. + */ +#define DfsItemPointerGetOffset(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), \ + (uint32)((((pointer)->ip_blkid).bi_lo & 0x00ff) << 15) | ((pointer)->ip_posid & 0x7fff)) + +/* + * DfsItemPointerSetFileId + * Sets a dfs item pointer to the specified file id. + */ +#define DfsItemPointerSetFileId(pointer, fileId) \ + (AssertMacro(PointerIsValid(pointer)), \ + ((pointer)->ip_blkid).bi_hi = ((fileId) << 8) >> 16, \ + ((pointer)->ip_blkid).bi_lo &= 0x00ff, \ + ((pointer)->ip_blkid).bi_lo |= (((fileId) << 8) & 0xff00)) + +/* + * DfsItemPointerSetOffset + * Sets a dfs item pointer to the specified offset. + */ +#define DfsItemPointerSetOffset(pointer, offset) \ + (AssertMacro(PointerIsValid(pointer)), \ + (pointer)->ip_posid = 0x8000, \ + (pointer)->ip_posid |= ((offset)&0x7fff), \ + ((pointer)->ip_blkid).bi_lo &= 0xff00, \ + ((pointer)->ip_blkid).bi_lo |= (((offset) >> 15) & 0x00ff)) + +/* + * DfsItemPointerSet + * Sets a dfs item pointer to the specified file id and offset. + */ +#define DfsItemPointerSet(pointer, fileId, offset) \ + (AssertMacro(PointerIsValid(pointer)), \ + DfsItemPointerSetFileId(pointer, fileId), \ + DfsItemPointerSetOffset(pointer, offset)) + +#endif /* ITEMPTR_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/large_object.h postgresql-hll-2.14/include/include/storage/large_object.h --- postgresql-hll-2.14_old/include/include/storage/large_object.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/large_object.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,88 @@ +/* ------------------------------------------------------------------------- + * + * large_object.h + * Declarations for PostgreSQL large objects. POSTGRES 4.2 supported + * zillions of large objects (internal, external, jaquith, inversion). + * Now we only support inversion. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/large_object.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LARGE_OBJECT_H +#define LARGE_OBJECT_H + +#include "utils/snapshot.h" + +/* ---------- + * Data about a currently-open large object. + * + * id is the logical OID of the large object + * snapshot is the snapshot to use for read/write operations + * subid is the subtransaction that opened the desc (or currently owns it) + * offset is the current seek offset within the LO + * flags contains some flag bits + * + * NOTE: before 7.1, we also had to store references to the separate table + * and index of a specific large object. Now they all live in pg_largeobject + * and are accessed via a common relation descriptor. + * ---------- + */ +typedef struct LargeObjectDesc { + Oid id; /* LO's identifier */ + Snapshot snapshot; /* snapshot to use */ + SubTransactionId subid; /* owning subtransaction ID */ + uint32 offset; /* current seek pointer */ + int flags; /* locking info, etc */ + +/* flag bits: */ +#define IFS_RDLOCK (1 << 0) +#define IFS_WRLOCK (1 << 1) + +} LargeObjectDesc; + +/* + * Each "page" (tuple) of a large object can hold this much data + * + * We could set this as high as BLCKSZ less some overhead, but it seems + * better to make it a smaller value, so that not as much space is used + * up when a page-tuple is updated. Note that the value is deliberately + * chosen large enough to trigger the tuple toaster, so that we will + * attempt to compress page tuples in-line. (But they won't be moved off + * unless the user creates a toast-table for pg_largeobject...) + * + * Also, it seems to be a smart move to make the page size be a power of 2, + * since clients will often be written to send data in power-of-2 blocks. + * This avoids unnecessary tuple updates caused by partial-page writes. + */ +#define LOBLKSIZE (BLCKSZ / 4) + +/* compatible with C code for pljava, otherwise pljava will met compile error */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function definitions... + */ + +/* inversion stuff in inv_api.c */ +extern void close_lo_relation(bool isCommit); +extern Oid inv_create(Oid lobjId); +extern LargeObjectDesc* inv_open(Oid lobjId, int flags, MemoryContext mcxt); +extern void inv_close(LargeObjectDesc* obj_desc); +extern int inv_drop(Oid lobjId); +extern int inv_seek(LargeObjectDesc* obj_desc, int offset, int whence); +extern int inv_tell(LargeObjectDesc* obj_desc); +extern int inv_read(LargeObjectDesc* obj_desc, char* buf, int nbytes); +extern int inv_write(LargeObjectDesc* obj_desc, const char* buf, int nbytes); +extern void inv_truncate(LargeObjectDesc* obj_desc, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* LARGE_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/latch.h postgresql-hll-2.14/include/include/storage/latch.h --- postgresql-hll-2.14_old/include/include/storage/latch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/latch.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,132 @@ +/* ------------------------------------------------------------------------- + * + * latch.h + * Routines for interprocess latches + * + * A latch is a boolean variable, with operations that let processes sleep + * until it is set. A latch can be set from another process, or a signal + * handler within the same process. + * + * The latch interface is a reliable replacement for the common pattern of + * using pg_usleep() or select() to wait until a signal arrives, where the + * signal handler sets a flag variable. Because on some platforms an + * incoming signal doesn't interrupt sleep, and even on platforms where it + * does there is a race condition if the signal arrives just before + * entering the sleep, the common pattern must periodically wake up and + * poll the flag variable. The pselect() system call was invented to solve + * this problem, but it is not portable enough. Latches are designed to + * overcome these limitations, allowing you to sleep without polling and + * ensuring quick response to signals from other processes. + * + * There are two kinds of latches: local and shared. A local latch is + * initialized by InitLatch, and can only be set from the same process. + * A local latch can be used to wait for a signal to arrive, by calling + * SetLatch in the signal handler. A shared latch resides in shared memory, + * and must be initialized at postmaster startup by InitSharedLatch. Before + * a shared latch can be waited on, it must be associated with a process + * with OwnLatch. Only the process owning the latch can wait on it, but any + * process can set it. + * + * There are three basic operations on a latch: + * + * SetLatch - Sets the latch + * ResetLatch - Clears the latch, allowing it to be set again + * WaitLatch - Waits for the latch to become set + * + * WaitLatch includes a provision for timeouts (which should be avoided + * when possible, as they incur extra overhead) and a provision for + * postmaster child processes to wake up immediately on postmaster death. + * See unix_latch.c for detailed specifications for the exported functions. + * + * The correct pattern to wait for event(s) is: + * + * for (;;) + * { + * ResetLatch(); + * if (work to do) + * Do Stuff(); + * WaitLatch(); + * } + * + * It's important to reset the latch *before* checking if there's work to + * do. Otherwise, if someone sets the latch between the check and the + * ResetLatch call, you will miss it and Wait will incorrectly block. + * + * To wake up the waiter, you must first set a global flag or something + * else that the wait loop tests in the "if (work to do)" part, and call + * SetLatch *after* that. SetLatch is designed to return quickly if the + * latch is already set. + * + * On some platforms, signals will not interrupt the latch wait primitive + * by themselves. Therefore, it is critical that any signal handler that + * is meant to terminate a WaitLatch wait calls SetLatch. + * + * Note that use of the process latch (PGPROC.procLatch) is generally better + * than an ad-hoc shared latch for signaling auxiliary processes. This is + * because generic signal handlers will call SetLatch on the process latch + * only, so using any latch other than the process latch effectively precludes + * use of any generic handler. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/latch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LATCH_H +#define LATCH_H + +#include + +/* + * Latch structure should be treated as opaque and only accessed through + * the public functions. It is defined here to allow embedding Latches as + * part of bigger structs. + */ +typedef struct { + sig_atomic_t is_set; + bool is_shared; + ThreadId owner_pid; +#ifdef WIN32 + HANDLE event; +#endif +} Latch; + +/* Bitmasks for events that may wake-up WaitLatch() clients */ +#define WL_LATCH_SET (1 << 0) +#define WL_SOCKET_READABLE (1 << 1) +#define WL_SOCKET_WRITEABLE (1 << 2) +#define WL_TIMEOUT (1 << 3) +#define WL_POSTMASTER_DEATH (1 << 4) + +/* + * prototypes for functions in latch.c + */ +extern void InitializeLatchSupport(void); +extern void InitLatch(volatile Latch* latch); +extern void InitSharedLatch(volatile Latch* latch); +extern void OwnLatch(volatile Latch* latch); +extern void DisownLatch(volatile Latch* latch); +extern int WaitLatch(volatile Latch* latch, int wakeEvents, long timeout); +extern int WaitLatchOrSocket(volatile Latch* latch, int wakeEvents, pgsocket sock, long timeout); +extern void SetLatch(volatile Latch* latch); +extern void ResetLatch(volatile Latch* latch); + +extern void ClosePipesAtThreadExit(void); + +/* beware of memory ordering issues if you use this macro! */ +#define TestLatch(latch) (((volatile Latch*)(latch))->is_set) + +/* + * Unix implementation uses SIGUSR1 for inter-process signaling. + * Win32 doesn't need this. + */ +#ifndef WIN32 +extern void latch_sigusr1_handler(void); +#else +#define latch_sigusr1_handler() ((void)0) +#endif + +#endif /* LATCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/lmgr.h postgresql-hll-2.14/include/include/storage/lmgr.h --- postgresql-hll-2.14_old/include/include/storage/lmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lmgr.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,108 @@ +/* ------------------------------------------------------------------------- + * + * lmgr.h + * POSTGRES lock manager definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LMGR_H +#define LMGR_H + +#include "lib/stringinfo.h" +#include "storage/itemptr.h" +#include "storage/lock.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/partcache.h" +#include "utils/partitionmap_gs.h" + +extern void RelationInitLockInfo(Relation relation); + +/* Lock a relation */ +extern void LockRelationOid(Oid relid, LOCKMODE lockmode); +extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode); +extern void UnlockRelationId(LockRelId* relid, LOCKMODE lockmode); +extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode); + +extern void LockRelFileNode(const RelFileNode& rnode, LOCKMODE lockmode); +extern void UnlockRelFileNode(const RelFileNode& rnode, LOCKMODE lockmode); + +extern void LockRelation(Relation relation, LOCKMODE lockmode); +extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode); +extern void UnlockRelation(Relation relation, LOCKMODE lockmode); +extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode); + +extern void LockRelationIdForSession(LockRelId* relid, LOCKMODE lockmode); +extern void UnlockRelationIdForSession(LockRelId* relid, LOCKMODE lockmode); + +/* Lock a relation for extension */ +extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern int RelationExtensionLockWaiterCount(Relation relation); + +extern void LockRelFileNodeForExtension(const RelFileNode& rnode, LOCKMODE lockmode); +extern void UnlockRelFileNodeForExtension(const RelFileNode& rnode, LOCKMODE lockmode); + +/* Lock a page (currently only used within indexes) */ +extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); +extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); +extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); + +/* Lock a tuple (see heap_lock_tuple before assuming you understand this) */ +extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode, bool allow_con_update = false); +extern bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); +extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); + +/* Lock an XID (used to wait for a transaction to finish) */ +extern void XactLockTableInsert(TransactionId xid); +extern void XactLockTableDelete(TransactionId xid); +extern void XactLockTableWait(TransactionId xid, bool allow_con_update = false); +extern bool ConditionalXactLockTableWait(TransactionId xid, bool waitparent = true, bool bCareNextxid = false); + +/* Lock a general object (other than a relation) of the current database */ +extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); + +/* Lock a shared-across-databases object (other than a relation) */ +extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); + +extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void PartitionInitLockInfo(Partition partition); + +/* Describe a locktag for error messages */ +extern void LockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); +extern bool ConditionalLockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); +extern void UnlockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); + +extern void LockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); +extern bool ConditionalLockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); +extern void UnlockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); + +extern void LockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); +extern bool ConditionalLockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); +extern void UnlockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); + +extern bool ConditionalLockPartitionWithRetry(Relation relation, Oid partitionId, LOCKMODE lockmode); + +/* for vacuum partition */ +void LockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +bool ConditionalLockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +void UnLockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +void LockPartitionVacuumForSession(PartitionIdentifier* partIdtf, Oid partrelid, Oid partid, LOCKMODE lockmode); +void UnLockPartitionVacuumForSession(PartitionIdentifier* partIdtf, Oid partrelid, Oid partid, LOCKMODE lockmode); + +extern void DescribeLockTag(StringInfo buf, const LOCKTAG* tag); + +extern bool ConditionalLockCStoreFreeSpace(Relation relation); +extern void UnlockCStoreFreeSpace(Relation relation); +extern const char* GetLockNameFromTagType(uint16 locktag_type); +#endif /* LMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/lock.h postgresql-hll-2.14/include/include/storage/lock.h --- postgresql-hll-2.14_old/include/include/storage/lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lock.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,565 @@ +/* ------------------------------------------------------------------------- + * + * lock.h + * POSTGRES low-level lock mechanism + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCK_H_ +#define LOCK_H_ + +#include "storage/backendid.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "gs_thread.h" + +typedef struct PROC_QUEUE { + SHM_QUEUE links; /* head of list of PGPROC objects */ + int size; /* number of entries in list */ +} PROC_QUEUE; + +/* + * Top-level transactions are identified by VirtualTransactionIDs comprising + * the BackendId of the backend running the xact, plus a locally-assigned + * LocalTransactionId. These are guaranteed unique over the short term, + * but will be reused after a database restart; hence they should never + * be stored on disk. + * + * Note that struct VirtualTransactionId can not be assumed to be atomically + * assignable as a whole. However, type LocalTransactionId is assumed to + * be atomically assignable, and the backend ID doesn't change often enough + * to be a problem, so we can fetch or assign the two fields separately. + * We deliberately refrain from using the struct within PGPROC, to prevent + * coding errors from trying to use struct assignment with it; instead use + * GET_VXID_FROM_PGPROC(). + */ +typedef struct VirtualTransactionId { + BackendId backendId; /* determined at backend startup */ + LocalTransactionId localTransactionId; /* backend-local transaction + * id */ +} VirtualTransactionId; + +#define InvalidLocalTransactionId 0 +#define LocalTransactionIdIsValid(lxid) ((lxid) != InvalidLocalTransactionId) +#define VirtualTransactionIdIsValid(vxid) \ + (((vxid).backendId != InvalidBackendId) && LocalTransactionIdIsValid((vxid).localTransactionId)) +#define VirtualTransactionIdEquals(vxid1, vxid2) \ + ((vxid1).backendId == (vxid2).backendId && (vxid1).localTransactionId == (vxid2).localTransactionId) +#define SetInvalidVirtualTransactionId(vxid) \ + ((vxid).backendId = InvalidBackendId, (vxid).localTransactionId = InvalidLocalTransactionId) +#define GET_VXID_FROM_PGPROC(vxid, proc) ((vxid).backendId = (proc).backendId, (vxid).localTransactionId = (proc).lxid) + +/* + * LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit + * mask indicating a set of held or requested lock types (the bit 1<> 32), \ + (locktag).locktag_field3 = 0, \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_TRANSACTION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_VIRTUALTRANSACTION(locktag, vxid) \ + ((locktag).locktag_field1 = (vxid).backendId, \ + (locktag).locktag_field2 = (uint32)((vxid).localTransactionId & 0xFFFFFFFF),\ + (locktag).locktag_field3 = (uint32)((vxid).localTransactionId >> 32), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_VIRTUALTRANSACTION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (classoid), \ + (locktag).locktag_field3 = (objoid), \ + (locktag).locktag_field4 = (objsubid), \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_OBJECT, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_ADVISORY(locktag, id1, id2, id3, id4) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = (id4), \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_ADVISORY, \ + (locktag).locktag_lockmethodid = USER_LOCKMETHOD) + +#define SET_LOCKTAG_PARTITION(locktag, id1, id2, id3) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_PARTITION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_PARTITION_SEQUENCE(locktag, id1, id2, id3) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_PARTITION_SEQUENCE, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_CSTORE_FREESPACE(locktag, id1, id2) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = 0, \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_CSTORE_FREESPACE, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +/* + * Per-locked-object lock information: + * + * tag -- uniquely identifies the object being locked + * grantMask -- bitmask for all lock types currently granted on this object. + * waitMask -- bitmask for all lock types currently awaited on this object. + * procLocks -- list of PROCLOCK objects for this lock. + * waitProcs -- queue of processes waiting for this lock. + * requested -- count of each lock type currently requested on the lock + * (includes requests already granted!!). + * nRequested -- total requested locks of all types. + * granted -- count of each lock type currently granted on the lock. + * nGranted -- total granted locks of all types. + * + * Note: these counts count 1 for each backend. Internally to a backend, + * there may be multiple grabs on a particular lock, but this is not reflected + * into shared memory. + */ +typedef struct LOCK { + /* hash key */ + LOCKTAG tag; /* unique identifier of lockable object */ + + /* data */ + LOCKMASK grantMask; /* bitmask for lock types already granted */ + LOCKMASK waitMask; /* bitmask for lock types awaited */ + SHM_QUEUE procLocks; /* list of PROCLOCK objects assoc. with lock */ + PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */ + int requested[MAX_LOCKMODES]; /* counts of requested locks */ + int nRequested; /* total of requested[] array */ + int granted[MAX_LOCKMODES]; /* counts of granted locks */ + int nGranted; /* total of granted[] array */ +} LOCK; + +#define LOCK_LOCKMETHOD(lock) ((LOCKMETHODID)(lock).tag.locktag_lockmethodid) + +/* + * We may have several different backends holding or awaiting locks + * on the same lockable object. We need to store some per-holder/waiter + * information for each such holder (or would-be holder). This is kept in + * a PROCLOCK struct. + * + * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the + * proclock hashtable. A PROCLOCKTAG value uniquely identifies the combination + * of a lockable object and a holder/waiter for that object. (We can use + * pointers here because the PROCLOCKTAG need only be unique for the lifespan + * of the PROCLOCK, and it will never outlive the lock or the proc.) + * + * Internally to a backend, it is possible for the same lock to be held + * for different purposes: the backend tracks transaction locks separately + * from session locks. However, this is not reflected in the shared-memory + * state: we only track which backend(s) hold the lock. This is OK since a + * backend can never block itself. + * + * The holdMask field shows the already-granted locks represented by this + * proclock. Note that there will be a proclock object, possibly with + * zero holdMask, for any lock that the process is currently waiting on. + * Otherwise, proclock objects whose holdMasks are zero are recycled + * as soon as convenient. + * + * releaseMask is workspace for LockReleaseAll(): it shows the locks due + * to be released during the current call. This must only be examined or + * set by the backend owning the PROCLOCK. + * + * Each PROCLOCK object is linked into lists for both the associated LOCK + * object and the owning PGPROC object. Note that the PROCLOCK is entered + * into these lists as soon as it is created, even if no lock has yet been + * granted. A PGPROC that is waiting for a lock to be granted will also be + * linked into the lock's waitProcs queue. + */ +typedef struct PROCLOCKTAG { + /* NB: we assume this struct contains no padding! */ + LOCK* myLock; /* link to per-lockable-object information */ + PGPROC* myProc; /* link to PGPROC of owning backend */ +} PROCLOCKTAG; + +typedef struct PROCLOCK { + /* tag */ + PROCLOCKTAG tag; /* unique identifier of proclock object */ + + /* data */ + LOCKMASK holdMask; /* bitmask for lock types currently held */ + LOCKMASK releaseMask; /* bitmask for lock types to be released */ + SHM_QUEUE lockLink; /* list link in LOCK's list of proclocks */ + SHM_QUEUE procLink; /* list link in PGPROC's list of proclocks */ +} PROCLOCK; + +#define PROCLOCK_LOCKMETHOD(proclock) LOCK_LOCKMETHOD(*((proclock).tag.myLock)) + +/* + * Each backend also maintains a local hash table with information about each + * lock it is currently interested in. In particular the local table counts + * the number of times that lock has been acquired. This allows multiple + * requests for the same lock to be executed without additional accesses to + * shared memory. We also track the number of lock acquisitions per + * ResourceOwner, so that we can release just those locks belonging to a + * particular ResourceOwner. + * + * When holding a lock taken "normally", the lock and proclock fields always + * point to the associated objects in shared memory. However, if we acquired + * the lock via the fast-path mechanism, the lock and proclock fields are set + * to NULL, since there probably aren't any such objects in shared memory. + * (If the lock later gets promoted to normal representation, we may eventually + * update our locallock's lock/proclock fields after finding the shared + * objects.) + * + * Caution: a locallock object can be left over from a failed lock acquisition + * attempt. In this case its lock/proclock fields are untrustworthy, since + * the shared lock object is neither held nor awaited, and hence is available + * to be reclaimed. If nLocks > 0 then these pointers must either be valid or + * NULL, but when nLocks == 0 they should be considered garbage. + */ +typedef struct LOCALLOCKTAG { + LOCKTAG lock; /* identifies the lockable object */ + LOCKMODE mode; /* lock mode for this table entry */ +} LOCALLOCKTAG; + +typedef struct LOCALLOCKOWNER { + /* + * Note: if owner is NULL then the lock is held on behalf of the session; + * otherwise it is held on behalf of my current transaction. + * + * Must use a forward struct reference to avoid circularity. + */ + struct ResourceOwnerData* owner; + int64 nLocks; /* # of times held by this owner */ +} LOCALLOCKOWNER; + +typedef struct LOCALLOCK { + /* tag */ + LOCALLOCKTAG tag; /* unique identifier of locallock entry */ + + /* data */ + LOCK* lock; /* associated LOCK object, if any */ + PROCLOCK* proclock; /* associated PROCLOCK object, if any */ + uint32 hashcode; /* copy of LOCKTAG's hash value */ + int64 nLocks; /* total number of times lock is held */ + int numLockOwners; /* # of relevant ResourceOwners */ + int maxLockOwners; /* allocated size of array */ + bool holdsStrongLockCount; /* bumped FastPathStrongRelatonLocks */ + LOCALLOCKOWNER* lockOwners; /* dynamically resizable array */ +} LOCALLOCK; + +#define LOCALLOCK_LOCKMETHOD(llock) ((llock).tag.lock.locktag_lockmethodid) + +/* + * These structures hold information passed from lmgr internals to the lock + * listing user-level functions (in lockfuncs.c). + */ + +typedef struct LockInstanceData { + LOCKTAG locktag; /* locked object */ + LOCKMASK holdMask; /* locks held by this PGPROC */ + LOCKMODE waitLockMode; /* lock awaited by this PGPROC, if any */ + BackendId backend; /* backend ID of this PGPROC */ + LocalTransactionId lxid; /* local transaction ID of this PGPROC */ + ThreadId pid; /* pid of this PGPROC */ + uint64 sessionid; /* session id of this PGPROC */ + bool fastpath; /* taken via fastpath? */ +} LockInstanceData; + +typedef struct LockData { + int nelements; /* The length of the array */ + LockInstanceData* locks; +} LockData; + +/* Result codes for LockAcquire() */ +typedef enum { + LOCKACQUIRE_NOT_AVAIL, /* lock not available, and dontWait=true */ + LOCKACQUIRE_OK, /* lock successfully acquired */ + LOCKACQUIRE_ALREADY_HELD /* incremented count for lock already held */ +} LockAcquireResult; + +/* Deadlock states identified by DeadLockCheck() */ +typedef enum { + DS_NOT_YET_CHECKED, /* no deadlock check has run yet */ + DS_LOCK_TIMEOUT, /* lock acuqire timeout */ + DS_NO_DEADLOCK, /* no deadlock detected */ + DS_SOFT_DEADLOCK, /* deadlock avoided by queue rearrangement */ + DS_HARD_DEADLOCK, /* deadlock, no way out but ERROR */ + DS_BLOCKED_BY_AUTOVACUUM, /* no deadlock; queue blocked by autovacuum worker */ + DS_BLOCKED_BY_REDISTRIBUTION /* no deadlock; queue blocked by data redistribution */ +} DeadLockState; + +/* + * The lockmgr's shared hash tables are partitioned to reduce contention. + * To determine which partition a given locktag belongs to, compute the tag's + * hash code with LockTagHashCode(), then apply one of these macros. + * NB: NUM_LOCK_PARTITIONS must be a power of 2! + */ +#define LockHashPartition(hashcode) ((hashcode) % NUM_LOCK_PARTITIONS) +#define LockHashPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstLockMgrLock + LockHashPartition(hashcode)].lock) + +/* + * function prototypes + */ +extern void InitLocks(void); +extern LockMethod GetLocksMethodTable(const LOCK *lock); +extern uint32 LockTagHashCode(const LOCKTAG *locktag); +extern LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, + bool allow_con_update = false); +extern bool LockIncrementIfExists(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock); +extern LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, + bool report_memory_error, bool allow_con_update = false); +extern void AbortStrongLockAcquire(void); +extern bool LockRelease(const LOCKTAG* locktag, LOCKMODE lockmode, bool sessionLock); +extern void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks); +extern void Check_FastpathBit(); + +extern void LockReleaseSession(LOCKMETHODID lockmethodid); +extern void LockReleaseCurrentOwner(void); +extern void LockReassignCurrentOwner(void); +extern bool LockHasWaiters(const LOCKTAG* locktag, LOCKMODE lockmode, bool sessionLock); +extern VirtualTransactionId* GetLockConflicts(const LOCKTAG* locktag, LOCKMODE lockmode); +extern void AtPrepare_Locks(void); +extern void PostPrepare_Locks(TransactionId xid); +extern int LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock, + PGPROC *proc); +extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode); +extern void GrantAwaitedLock(void); +extern void RemoveFromWaitQueue(PGPROC* proc, uint32 hashcode); +extern Size LockShmemSize(void); +extern LockData* GetLockStatusData(void); + +extern void ReportLockTableError(bool report); + +typedef struct xl_standby_lock { + TransactionId xid; /* xid of holder of AccessExclusiveLock */ + Oid dbOid; + Oid relOid; +} xl_standby_lock; + +extern xl_standby_lock* GetRunningTransactionLocks(int* nlocks); +extern const char* GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode); + +extern void lock_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_standby_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern DeadLockState DeadLockCheck(PGPROC* proc); +extern PGPROC* GetBlockingAutoVacuumPgproc(void); +extern PGPROC* GetBlockingRedistributionPgproc(void); +extern void DeadLockReport(void); +extern void RememberSimpleDeadLock(PGPROC* proc1, LOCKMODE lockmode, LOCK* lock, PGPROC* proc2); +extern void InitDeadLockChecking(void); + +extern int LockWaiterCount(const LOCKTAG* locktag); +extern bool IsOtherProcRedistribution(PGPROC* otherProc); +#if defined(LOCK_DEBUG) || defined(USE_ASSERT_CHECKING) +extern void DumpLocks(PGPROC* proc); +extern void DumpAllLocks(void); +#endif + +/* Lock a VXID (used to wait for a transaction to finish) */ +extern void VirtualXactLockTableInsert(const VirtualTransactionId& vxid); +extern void VirtualXactLockTableCleanup(void); +extern bool VirtualXactLock(const VirtualTransactionId& vxid, bool wait); +extern char* LocktagToString(LOCKTAG locktag); + +#endif /* LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/lwlock_be.h postgresql-hll-2.14/include/include/storage/lwlock_be.h --- postgresql-hll-2.14_old/include/include/storage/lwlock_be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lwlock_be.h 2020-12-12 17:06:43.271348348 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lwlock_be.h + * bridge between lwlock.h and pgstat.h + * + * + * IDENTIFICATION + * src/include/storage/lwlock_be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_STORAGE_LWLOCK_BE_H +#define SRC_INCLUDE_STORAGE_LWLOCK_BE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/lwlock.h" + +extern void remember_lwlock_acquire(LWLock* lockid); +extern void forget_lwlock_acquire(void); + +#endif // SRC_INCLUDE_STORAGE_LWLOCK_BE_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/storage/lwlock.h postgresql-hll-2.14/include/include/storage/lwlock.h --- postgresql-hll-2.14_old/include/include/storage/lwlock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lwlock.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,356 @@ +/* ------------------------------------------------------------------------- + * + * lwlock.h + * Lightweight lock manager + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lwlock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LWLOCK_H +#define LWLOCK_H + +#include "lib/ilist.h" +#include "storage/s_lock.h" +#include "utils/atomic.h" +#include "gs_thread.h" + +typedef volatile uint32 pg_atomic_uint32; +typedef volatile uint64 pg_atomic_uint64; + +/* Names for fixed lwlocks and NUM_INDIVIDUAL_LWLOCKS */ +#ifndef WIN32 +#include "storage/lwlocknames.h" +#endif +extern const char *const MainLWLockNames[]; + +/* + * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS + * here, but we need them to figure out offsets within MainLWLockArray, and having + * this file include lock.h or bufmgr.h would be backwards. + */ + +/* Number of partitions of the shared operator-level statistics hashtable */ +#define NUM_OPERATOR_REALTIME_PARTITIONS 32 + +#define NUM_OPERATOR_HISTORY_PARTITIONS 64 + +/* Number of partitions of the shared buffer mapping hashtable */ +#define NUM_BUFFER_PARTITIONS 4096 + +/* change 1024 ->2048 for two cache(compress data cache and meta cache) */ +#define NUM_CACHE_BUFFER_PARTITIONS 2048 + +/* Number of partitions of the shared session-level statistics hashtable */ +#define NUM_SESSION_REALTIME_PARTITIONS 32 + +#define NUM_SESSION_HISTORY_PARTITIONS 64 + +/* Number of partitions of the shared instance statistics hashtable */ +#define NUM_INSTANCE_REALTIME_PARTITIONS 32 + +/* CSN log partitions */ +#define NUM_CSNLOG_PARTITIONS 512 + +/* Clog partitions */ +#define NUM_CLOG_PARTITIONS 256 + +/* Number of partitions the shared lock tables are divided into */ +#define LOG2_NUM_LOCK_PARTITIONS 4 +#define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS) + +/* Number of partitions the shared predicate lock tables are divided into */ +#define LOG2_NUM_PREDICATELOCK_PARTITIONS 4 +#define NUM_PREDICATELOCK_PARTITIONS (1 << LOG2_NUM_PREDICATELOCK_PARTITIONS) + +/* Number of partions the shared unique SQL hashtable */ +#define NUM_UNIQUE_SQL_PARTITIONS 64 + +/* Number of partions the shared instr user hashtable */ +#define NUM_INSTR_USER_PARTITIONS 64 + +/* Number of partions the global plan cache hashtable */ +#define NUM_GPC_PARTITIONS 128 + +/* Number of partions normalized query hashtable */ +#define NUM_NORMALIZED_SQL_PARTITIONS 64 + +/* Number of partions the max page flush lsn file */ +#define NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS 1024 + +/* Number of partions the ngroup info hash table */ +#define NUM_NGROUP_INFO_PARTITIONS 256 + +/* Number of partions the io state hashtable */ +#define NUM_IO_STAT_PARTITIONS 128 + +/* Number of partions the global sequence hashtable */ +#define NUM_GS_PARTITIONS 1024 + +#ifdef WIN32 +#define NUM_INDIVIDUAL_LWLOCKS 100 +#endif +/* + * WARNING---Please keep the order of LWLockTrunkOffset and BuiltinTrancheIds consistent!!! +*/ + +/* Offsets for various chunks of preallocated lwlocks in main array. */ +enum LWLockTrunkOffset { + FirstBufMappingLock = NUM_INDIVIDUAL_LWLOCKS, + FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, + FirstPredicateLockMgrLock = FirstLockMgrLock + NUM_LOCK_PARTITIONS, + FirstOperatorRealTLock = FirstPredicateLockMgrLock+ NUM_PREDICATELOCK_PARTITIONS, + FirstOperatorHistLock = FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS, + FirstSessionRealTLock = FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS, + FirstSessionHistLock = FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS, + FirstInstanceRealTLock = FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS, + /* Cache Mgr lock IDs */ + FirstCacheSlotMappingLock = FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS, + FirstCSNBufMappingLock = FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS, + FirstCBufMappingLock = FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS, + /* Instrumentaion */ + FirstUniqueSQLMappingLock = FirstCBufMappingLock + NUM_CLOG_PARTITIONS, + FirstInstrUserLock = FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS, + /* global plan cache */ + FirstGPCMappingLock = FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS, + FirstGPCPrepareMappingLock = FirstGPCMappingLock + NUM_GPC_PARTITIONS, + /* ASP */ + FirstASPMappingLock = FirstGPCPrepareMappingLock + NUM_GPC_PARTITIONS, + /* global sequence */ + FirstGlobalSeqLock = FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS, + + FirstNormalizedSqlLock = FirstGlobalSeqLock + NUM_GS_PARTITIONS, + FirstMPFLLock = FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS, + + FirstNGroupMappingLock = FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS, + FirstIOStatLock = FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS, + + /* must be last: */ + NumFixedLWLocks = FirstIOStatLock + NUM_IO_STAT_PARTITIONS +}; + +/* + * WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!! + * + * Every tranche ID less than NUM_INDIVIDUAL_LWLOCKS is reserved; also, + * we reserve additional tranche IDs for builtin tranches not included in + * the set of individual LWLocks. A call to LWLockNewTrancheId(to be added in future) will never + * return a value less than LWTRANCHE_NATIVE_TRANCHE_NUM. + */ +enum BuiltinTrancheIds +{ + LWTRANCHE_BUFMAPPING = NUM_INDIVIDUAL_LWLOCKS, + LWTRANCHE_LOCK_MANAGER, + LWTRANCHE_PREDICATE_LOCK_MANAGER, + LWTRANCHE_OPERATOR_REAL_TIME, + LWTRANCHE_OPERATOR_HISTORY, + LWTRANCHE_SESSION_REAL_TIME, + LWTRANCHE_SESSION_HISTORY, + LWTRANCHE_INSTANCE_REAL_TIME, + LWTRANCHE_CACHE_SLOT_MAPPING, + LWTRANCHE_CSN_BUFMAPPING, + LWTRANCHE_CLOG_BUFMAPPING, + LWTRANCHE_UNIQUE_SQLMAPPING, + LWTRANCHE_INSTR_USER, + LWTRANCHE_GPC_MAPPING, + LWTRANCHE_GPC_PREPARE_MAPPING, + LWTRANCHE_ASP_MAPPING, + LWTRANCHE_GlobalSeq, + LWTRANCHE_NORMALIZED_SQL, + LWTRANCHE_BUFFER_IO_IN_PROGRESS, + LWTRANCHE_BUFFER_CONTENT, + LWTRANCHE_DATA_CACHE, + LWTRANCHE_META_CACHE, + LWTRANCHE_PROC, + LWTRANCHE_REPLICATION_SLOT, + LWTRANCHE_ASYNC_CTL, + LWTRANCHE_CLOG_CTL, + LWTRANCHE_CSNLOG_CTL, + LWTRANCHE_MULTIXACTOFFSET_CTL, + LWTRANCHE_MULTIXACTMEMBER_CTL, + LWTRANCHE_OLDSERXID_SLRU_CTL, + LWTRANCHE_WAL_INSERT, + LWTRANCHE_DOUBLE_WRITE, + LWTRANCHE_DW_SINGLE_POS, + LWTRANCHE_DW_SINGLE_WRITE, + LWTRANCHE_ACCOUNT_TABLE, + LWTRANCHE_EXTEND, // For general 3rd plugin + LWTRANCHE_MPFL, + LWTRANCHE_GTT_CTL, // For GTT + LWTRANCHE_PLDEBUG, // For Pldebugger + LWTRANCHE_NGROUP_MAPPING, + LWTRANCHE_MATVIEW_SEQNO, + LWTRANCHE_IO_STAT, + LWTRANCHE_WAL_FLUSH_WAIT, + LWTRANCHE_WAL_BUFFER_INIT_WAIT, + LWTRANCHE_WAL_INIT_SEGMENT, + /* + * Each trancheId above should have a corresponding item in BuiltinTrancheNames; + */ + LWTRANCHE_NATIVE_TRANCHE_NUM, + LWTRANCHE_UNKNOWN = 65535 +}; + +#ifndef cpu_relax +// New lock +#if defined(__x86_64__) || defined(__x86__) +#define cpu_relax() asm volatile("pause\n": : :"memory") +#else // some web says yield:::memory +#define cpu_relax() asm volatile("" : : : "memory") // equivalent to "rep; nop" +#endif +#endif + +typedef enum LWLockMode { + LW_EXCLUSIVE, + LW_SHARED, + LW_WAIT_UNTIL_FREE /* A special mode used in PGPROC->lwlockMode, + * when waiting for lock to become free. Not + * to be used as LWLockAcquire argument */ +} LWLockMode; + +/* To avoid pointer misuse during hash search, we wrapper the LWLock* in the following structure. */ +struct LWLock; +typedef struct { + LWLock* lock; +} LWLockAddr; + +typedef struct { + LWLockAddr lock_addr; + LWLockMode lock_sx; +} lwlock_id_mode; + +struct PGPROC; + +typedef struct LWLock { + uint16 tranche; /* tranche ID */ + pg_atomic_uint32 state; /* state of exlusive/nonexclusive lockers */ + dlist_head waiters; /* list of waiting PGPROCs */ +#ifdef LOCK_DEBUG + pg_atomic_uint32 nwaiters; /* number of waiters */ + struct PGPROC* owner; /* last exlusive owner of the lock */ +#endif +#ifdef ENABLE_THREAD_CHECK + pg_atomic_uint32 rwlock; + pg_atomic_uint32 listlock; +#endif +} LWLock; + +/* + * All the LWLock structs are allocated as an array in shared memory. + * (LWLockIds are indexes into the array.) We force the array stride to + * be a power of 2, which saves a few cycles in indexing, but more + * importantly also ensures that individual LWLocks don't cross cache line + * boundaries. This reduces cache contention problems, especially on AMD + * Opterons. (Of course, we have to also ensure that the array start + * address is suitably aligned.) + * + * On a 32-bit platforms a LWLock will these days fit into 16 bytes, but since + * that didn't use to be the case and cramming more lwlocks into a cacheline + * might be detrimental performancewise we still use 32 byte alignment + * there. So, both on 32 and 64 bit platforms, it should fit into 32 bytes + * unless slock_t is really big. We allow for that just in case. + * + * Add even more padding so that each LWLock takes up an entire cache line; + * this is useful, for example, in the main LWLock array, where the overall number of + * locks is small but some are heavily contended. + * + * In future, the LWLock should be devided into two parts: One uses LWLockPadded, + * the other uses LWLockMinimallyPadded. This should relax the requirement for the single global array. + */ +#ifdef __aarch64__ +#define LWLOCK_PADDED_SIZE PG_CACHE_LINE_SIZE +#else +#define LWLOCK_PADDED_SIZE (sizeof(LWLock) <= 32 ? 32 : 64) +#endif + +typedef union LWLockPadded { + LWLock lock; + char pad[LWLOCK_PADDED_SIZE]; +} LWLockPadded; + +extern PGDLLIMPORT LWLockPadded *MainLWLockArray; + +/* + * We use this structure to keep track of locked LWLocks for release + * during error recovery. The maximum size could be determined at runtime + * if necessary, but it seems unlikely that more than a few locks could + * ever be held simultaneously. + */ +#define MAX_SIMUL_LWLOCKS 4224 + +/* struct representing the LWLocks we're holding */ +typedef struct LWLockHandle { + LWLock* lock; + LWLockMode mode; +} LWLockHandle; + +#define GetMainLWLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[i].lock) + +extern void DumpLWLockInfo(); +extern LWLock* LWLockAssign(int trancheId); +extern void LWLockInitialize(LWLock* lock, int tranche_id); +extern bool LWLockAcquire(LWLock* lock, LWLockMode mode, bool need_update_lockid = false); +extern bool LWLockConditionalAcquire(LWLock* lock, LWLockMode mode); +extern bool LWLockAcquireOrWait(LWLock* lock, LWLockMode mode); +extern void LWLockRelease(LWLock* lock); +extern void LWLockReleaseClearVar(LWLock* lock, uint64* valptr, uint64 val); +extern void LWLockReleaseAll(void); +extern bool LWLockHeldByMe(LWLock* lock); +extern bool LWLockHeldByMeInMode(LWLock* lock, LWLockMode mode); +extern void LWLockReset(LWLock* lock); + +extern void LWLockOwn(LWLock* lock); +extern void LWLockDisown(LWLock* lock); + +extern bool LWLockWaitForVar(LWLock* lock, uint64* valptr, uint64 oldval, uint64* newval); +extern void LWLockUpdateVar(LWLock* lock, uint64* valptr, uint64 value); + +extern int NumLWLocks(void); +extern Size LWLockShmemSize(void); +extern void CreateLWLocks(void); + +extern void RequestAddinLWLocks(int n); +extern const char* GetBuiltInTrancheName(int trancheId); + +/* + * There is another, more flexible method of obtaining lwlocks. First, call + * LWLockNewTrancheId just once to obtain a tranche ID; this allocates from + * a shared counter. Next, each individual process using the tranche should + * call LWLockRegisterTranche() to associate that tranche ID with a name. + * Finally, LWLockInitialize should be called just once per lwlock, passing + * the tranche ID as an argument. + * + * It may seem strange that each process using the tranche must register it + * separately, but dynamic shared memory segments aren't guaranteed to be + * mapped at the same address in all coordinating backends, so storing the + * registration in the main shared memory segment wouldn't work for that case. + */ +extern void LWLockRegisterTranche(int tranche_id, const char *tranche_name); + +extern void wakeup_victim(LWLock *lock, ThreadId victim_tid); +extern int *get_held_lwlocks_num(void); +extern uint32 get_held_lwlocks_maxnum(void); +extern void* get_held_lwlocks(void); +extern void copy_held_lwlocks(void* heldlocks, lwlock_id_mode* dst, int num_heldlocks); +extern const char* GetLWLockIdentifier(uint32 classId, uint16 eventId); +extern LWLockMode GetHeldLWLockMode(LWLock* lock); + +extern const char** LWLockTrancheArray; +extern int LWLockTranchesAllocated; + +#define T_NAME(lock) \ + ((lock) ? (LWLockTrancheArray[(lock)->tranche]) : ("")) + +/* + * Peviously, we used an enum type called LWLockId to refer + * to LWLocks. New code should instead use LWLock *. However, for the + * convenience of third-party code, we include the following typedef. + */ +//typedef LWLock *LWLockId; // Uncomment it later. Now should disable to find bugs + +#endif /* LWLOCK_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/lwlocknames.h postgresql-hll-2.14/include/include/storage/lwlocknames.h --- postgresql-hll-2.14_old/include/include/storage/lwlocknames.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lwlocknames.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,106 @@ +/* autogenerated from src/gausskernel/storage/lmgr/lwlocknames.txt, do not edit */ +/* there is deliberately not an #ifndef LWLOCKNAMES_H here */ + +#define BufFreelistLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[0].lock) +#define CUSlotListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[1].lock) +#define ShmemIndexLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[2].lock) +#define OidGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[3].lock) +#define XidGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[4].lock) +#define ProcArrayLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[5].lock) +#define SInvalReadLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[6].lock) +#define SInvalWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[7].lock) +#define WALBufMappingLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[8].lock) +#define WALWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[9].lock) +#define ControlFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[10].lock) +#define CheckpointLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[11].lock) +#define CLogControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[12].lock) +#define SubtransControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[13].lock) +#define MultiXactGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[14].lock) +#define MultiXactOffsetControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[15].lock) +#define MultiXactMemberControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[16].lock) +#define RelCacheInitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[17].lock) +#define CheckpointerCommLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[18].lock) +#define TwoPhaseStateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[19].lock) +#define TablespaceCreateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[20].lock) +#define BtreeVacuumLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[21].lock) +#define AddinShmemInitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[22].lock) +#define AutovacuumLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[23].lock) +#define AutovacuumScheduleLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[24].lock) +#define AutoanalyzeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[25].lock) +#define SyncScanLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[26].lock) +#define BarrierLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[27].lock) +#define NodeTableLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[28].lock) +#define PoolerLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[29].lock) +#define AlterPortLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[30].lock) +#define RelationMappingLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[31].lock) +#define AsyncCtlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[32].lock) +#define AsyncQueueLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[33].lock) +#define SerializableXactHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[34].lock) +#define SerializableFinishedListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[35].lock) +#define SerializablePredicateLockListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[36].lock) +#define OldSerXidLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[37].lock) +#define FileStatLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[38].lock) +#define SyncRepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[39].lock) +#define DataSyncRepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[40].lock) +#define DataFileIdCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[41].lock) +#define CStoreColspaceCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[42].lock) +#define CStoreCUCacheSweepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[43].lock) +#define MetaCacheSweepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[44].lock) +#define FdwPartitionCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[45].lock) +#define DfsConnectorCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[46].lock) +#define dummyServerInfoCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[47].lock) +#define ExtensionConnectorLibLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[48].lock) +#define SearchServerLibLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[49].lock) +#define DfsUserLoginLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[50].lock) +#define DfsSpaceCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[51].lock) +#define LsnXlogChkFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[52].lock) +#define GTMHostInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[53].lock) +#define ReplicationSlotAllocationLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[54].lock) +#define ReplicationSlotControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[55].lock) +#define FullBuildXlogCopyStartPtrLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[56].lock) +#define LogicalReplicationSlotPersistentDataLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[57].lock) +#define ResourcePoolHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[58].lock) +#define WorkloadStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[59].lock) +#define WorkloadIoStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[60].lock) +#define WorkloadCGroupHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[61].lock) +#define WorkloadSessionInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[62].lock) +#define OBSGetPathLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[63].lock) +#define WorkloadUserInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[64].lock) +#define WorkloadRecordLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[65].lock) +#define WorkloadIOUtilLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[66].lock) +#define WorkloadNodeGroupLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[67].lock) +#define JobShmemLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[68].lock) +#define OBSRuntimeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[69].lock) +#define LLVMDumpIRLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[70].lock) +#define LLVMParseIRLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[71].lock) +#define RPNumberLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[72].lock) +#define ClusterRPLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[73].lock) +#define WaitCountHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[74].lock) +#define InstrWorkloadLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[75].lock) +#define PgfdwLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[76].lock) +#define CBMParseXlogLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[77].lock) +#define DelayDDLLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[78].lock) +#define RelfilenodeReuseLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[79].lock) +#define BadBlockStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[80].lock) +#define RowPageReplicationLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[81].lock) +#define RcvWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[82].lock) +#define InstanceTimeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[83].lock) +#define PercentileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[84].lock) +#define XlogRemoveSegLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[85].lock) +#define DnUsedSpaceHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[86].lock) +#define CsnMinLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[87].lock) +#define GPCCommitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[88].lock) +#define GPCClearLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[89].lock) +#define GPCTimelineLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[90].lock) +#define TsTagsCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[91].lock) +#define MaxPageFlushLsnFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[92].lock) +#define CaptureViewFileHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[93].lock) +#define StreamingEngineConnLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[94].lock) +#define StreamingEngineExecLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[95].lock) +#define PartIdCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[96].lock) +#define PartOidCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[97].lock) +#define DeleteCompactionLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[98].lock) +#define DeleteConsumerLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[99].lock) +#define ConsumerStateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[100].lock) + +#define NUM_INDIVIDUAL_LWLOCKS 101 diff -uprN postgresql-hll-2.14_old/include/include/storage/lz4_file.h postgresql-hll-2.14/include/include/storage/lz4_file.h --- postgresql-hll-2.14_old/include/include/storage/lz4_file.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/lz4_file.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lz4_file.h + * All interface of LZ4 compress and write file + * + * IDENTIFICATION + * src/include/storage/lz4_file.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LZ4FILE_H +#define LZ4FILE_H + +#define LZ4FileSrcBufSize (BLCKSZ * 8) + +typedef struct LZ4File { + File file; + off_t readOffset; + int compressBufSize; + int srcDataSize; + char* srcBuf; /* a temporary buffer for writing data. */ + char* compressBuf; /* a temporary buffer for compress data. */ + off_t curOffset; /* next read/write position in buffer */ + +public: + void Reset() + { + file = FILE_INVALID; + readOffset = 0; + srcDataSize = 0; + srcBuf = NULL; + compressBuf = NULL; + compressBufSize = 0; + curOffset = 0; + } +} LZ4File; + +extern LZ4File* LZ4FileCreate(bool interXact); +extern size_t LZ4FileWrite(LZ4File* lz4File, char* buffer, size_t size); +extern size_t LZ4FileRead(LZ4File* lz4File, char* buffer, size_t size); +extern void LZ4FileClose(LZ4File* lz4File); +extern void LZ4FileRewind(LZ4File* lz4File); +extern void LZ4FileClearBuffer(LZ4File* lz4File); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/mot/jit_def.h postgresql-hll-2.14/include/include/storage/mot/jit_def.h --- postgresql-hll-2.14_old/include/include/storage/mot/jit_def.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/mot/jit_def.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,196 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * jit_def.h + * Jit execution constants. + * + * IDENTIFICATION + * src/include/storage/mot/jit_def.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JIT_DEF_H +#define JIT_DEF_H + +#include + +/** @define Impose a hard coded limit on depth of parsed expression. */ +#define MOT_JIT_MAX_EXPR_DEPTH 10 + +/** @define We support up to 8 arguments for NULL management in expressions. */ +#define MOT_JIT_EXPR_ARG_COUNT 8 + +/** @define The maximum number of registers used in a pseudo-function execution. */ +#define MOT_JIT_MAX_FUNC_REGISTERS 4096 + +/** @define The maximum number of arguments in a Boolean expression. */ +#define MOT_JIT_MAX_BOOL_EXPR_ARGS 2 + +/** @define The maximum number of arguments in a function call expression. */ +#define MOT_JIT_MAX_FUNC_EXPR_ARGS 3 + +namespace JitExec { + +// To debug JIT execution, #define MOT_JIT_DEBUG +// To use advanced WHERE clause operators, #define MOT_JIT_ADVANCED_WHERE_OP +// To enable features required for JIT testing, #define MOT_JIT_TEST + +/** @enum JitCommandType Command types supported by jitted queries. */ +enum JitCommandType : uint8_t { + /** @var Invalid command type. */ + JIT_COMMAND_INVALID, + + /** @var Simple insert command. */ + JIT_COMMAND_INSERT, + + /** @var Simple (point-query) update command. */ + JIT_COMMAND_UPDATE, + + /** @var Simple (point-query) select command. */ + JIT_COMMAND_SELECT, + + /** @var Simple (point-query) delete command. */ + JIT_COMMAND_DELETE, + + /** @var Range update command. */ + JIT_COMMAND_RANGE_UPDATE, + + /** @var Unordered range select command. */ + JIT_COMMAND_RANGE_SELECT, + + /** @var Unordered full-scan select command. */ + JIT_COMMAND_FULL_SELECT, + + /** @var Aggregate range select command. */ + JIT_COMMAND_AGGREGATE_RANGE_SELECT, + + /** @var Join command resulting in a single tuple. */ + JIT_COMMAND_POINT_JOIN, + + /** @var Join range select command. */ + JIT_COMMAND_RANGE_JOIN, + + /** @var Join aggregate command. */ + JIT_COMMAND_AGGREGATE_JOIN, + + /** @var Compound select command (point-select with sub-queries). */ + JIT_COMMAND_COMPOUND_SELECT +}; + +/** @enum JIT context usage constants. */ +enum JitContextUsage : uint8_t { + /** @var JIT context is used in global context. */ + JIT_CONTEXT_GLOBAL, + + /** @var JIT context is used in session-local context. */ + JIT_CONTEXT_LOCAL +}; + +/** @enum Constants for classifying operators in WHERE clause. */ +enum JitWhereOperatorClass : uint8_t { + /** @var Invalid where operator class. */ + JIT_WOC_INVALID, + + /** @var "Equals" where operator class. */ + JIT_WOC_EQUALS, + + /** @var "Less than" where operator class. */ + JIT_WOC_LESS_THAN, + + /* @var "Greater than" where operator class. */ + JIT_WOC_GREATER_THAN, + + /** @var "Less than" or "equals to" where operator class. */ + JIT_WOC_LESS_EQUALS, + + /** @var "Greater than" or "equals to" where operator class */ + JIT_WOC_GREATER_EQUALS +}; + +/** @enum Integer-comparison operator types. */ +enum JitICmpOp { + /** @var Designates "equals" operator. */ + JIT_ICMP_EQ, + + /** @var Designates "not-equals" operator. */ + JIT_ICMP_NE, + + /** @var Designates "greater-than" operator. */ + JIT_ICMP_GT, + + /** @var Designates "greater-equals" operator. */ + JIT_ICMP_GE, + + /** @var Designates "less-than" operator. */ + JIT_ICMP_LT, + + /** @var Designates "less-equals" operator. */ + JIT_ICMP_LE, +}; + +/** @enum Range scan type constants. */ +enum JitRangeScanType { + /** @var No range scan. */ + JIT_RANGE_SCAN_NONE, + + /** @var Main range scan. In JOIN queries this designates the outer loop scan. */ + JIT_RANGE_SCAN_MAIN, + + /** @var Designates inner loop range scan. Can be specified only on JOIN queries.*/ + JIT_RANGE_SCAN_INNER, + + /** @var Sub-query range scan. */ + JIT_RANGE_SCAN_SUB_QUERY +}; + +/** @enum Range bound mode constants. */ +enum JitRangeBoundMode { + /** @var Designates no range bound mode specification. */ + JIT_RANGE_BOUND_NONE, + + /** @var Designates to include the range bound in the range scan. */ + JIT_RANGE_BOUND_INCLUDE, + + /** @var Designates to exclude the range bound from the range scan. */ + JIT_RANGE_BOUND_EXCLUDE +}; + +/** @enum Range iterator type. */ +enum JitRangeIteratorType { + /** @var Designated no range iterator specification. */ + JIT_RANGE_ITERATOR_NONE, + + /** @var Designates the iterator pointing to the start of the range. */ + JIT_RANGE_ITERATOR_START, + + /** @var Designates the iterator pointing to the end of the range. */ + JIT_RANGE_ITERATOR_END +}; + +/** @enum Query sort order */ +enum JitQuerySortOrder { + /** @var Invalid query sort order. */ + JIT_QUERY_SORT_INVALID, + + /** @var Ascending query sort order. */ + JIT_QUERY_SORT_ASCENDING, + + /** @var Descending query sort order. */ + JIT_QUERY_SORT_DESCENDING +}; +} // namespace JitExec + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/mot/jit_exec.h postgresql-hll-2.14/include/include/storage/mot/jit_exec.h --- postgresql-hll-2.14_old/include/include/storage/mot/jit_exec.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/mot/jit_exec.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * jit_exec.h + * Interface for jit execution. + * + * IDENTIFICATION + * src/include/storage/mot/jit_exec.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JIT_EXEC_H +#define JIT_EXEC_H + +#include "postgres.h" +#include "nodes/params.h" +#include "executor/tuptable.h" +#include "nodes/parsenodes.h" + +#include "jit_def.h" + +namespace JitExec { + +// forward declaration +struct JitContext; +struct JitContextPool; +struct JitPlan; + +/** @brief Initializes the JIT module for MOT. */ +extern bool JitInitialize(); + +/** @brief Destroys the JIT module for MOT. */ +extern void JitDestroy(); + +/** @brief Queries whether MOT JIT compilation and execution is enabled. */ +extern bool IsMotCodegenEnabled(); + +/** @brief Quereis whether pseudo-LLVM is forced on platforms where LLVM is natively supported. */ +extern bool IsMotPseudoCodegenForced(); + +/** @brief Queries whether informative printing is enabled for MOT JIT compilation. */ +extern bool IsMotCodegenPrintEnabled(); + +/** @brief Queries for the per-session limit of JIT queries. */ +extern uint32_t GetMotCodegenLimit(); + +/** + * @brief Queries whether a SQL query to be executed by MM Engine is jittable. + * @param query The parsed SQL query to examine. + * @param queryString The query text. + * @return The JIT plan if the query is jittable, otherwise NULL. + */ +extern JitPlan* IsJittable(Query* query, const char* queryString); + +/** + * @brief Generate jitted code for a query. + * @param query The parsed SQL query for which jitted code is to be generated. + * @param queryString The query text. + * @param jitPlan The JIT plan produced during the call to @ref IsJittable(). + * @return The context of the jitted code required for later execution. + */ +extern JitContext* JitCodegenQuery(Query* query, const char* queryString, JitPlan* jitPlan); + +/** @brief Resets the scan iteration counter for the JIT context. */ +extern void JitResetScan(JitContext* jitContext); + +/** + * @brief Executed a previously jitted query. + * @param jitContext The context produced by a previous call to @ref JitCodegenQuery(). + * @param params The list of bound parameters passed to the query. + * @param[out] slot The slot used for reporting select result. + * @param[out] tuplesProcessed The variable used to report the number of processed tuples. + * @param[out] scanEnded The variable used to report if a range scan ended. + * @return Zero if succeeded, otherwise an error code. + * @note This function may cause transaction abort. + */ +extern int JitExecQuery( + JitContext* jitContext, ParamListInfo params, TupleTableSlot* slot, uint64_t* tuplesProcessed, int* scanEnded); + +/** + * @brief Purges the global cache of JIT source stencils from all entries that refer the given relation id. + * @param relationId The external identifier of the relation to be purged. + * @param purgeOnly Specifies whether to just purge all keys/indexes referring to the given relation, or should the JIT + * context also be set as expired (which triggers re-compilation of the JIT function). + */ +extern void PurgeJitSourceCache(uint64_t relationId, bool purgeOnly); + +// externalize functions defined elsewhere + +/** @brief Destroys a jit context produced by a previous call to JitCodegenQuery. */ +extern void DestroyJitContext(JitContext* jitContext); + +/** @brief De-allocates a jit context pool for a specific session. */ +extern void FreeSessionJitContextPool(JitContextPool* jitContextPool); + +/** @brief Releases all resources associated with a plan.*/ +extern void JitDestroyPlan(JitPlan* plan); +} // namespace JitExec + +#endif // JIT_EXEC_H diff -uprN postgresql-hll-2.14_old/include/include/storage/mot/mot_fdw.h postgresql-hll-2.14/include/include/storage/mot/mot_fdw.h --- postgresql-hll-2.14_old/include/include/storage/mot/mot_fdw.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/mot/mot_fdw.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * mot_fdw.h + * MOT Foreign Data Wrapper interfaces used by the envelop during + * initialization, recovery, etc. + * + * IDENTIFICATION + * src/include/storage/mot/mot_fdw.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MOT_FDW_H +#define MOT_FDW_H + +#include + +/** @brief Initializes MOT engine. */ +extern void InitMOT(); + +/** @brief Shutdown the MOT engine. */ +extern void TermMOT(); + +/** + * @brief Initializes the thread level and recovers the data from MOT checkpoint. + * Should be called before XLOG recovery in the envelop. + */ +extern void MOTRecover(); + +/** + * @brief Cleans up the resources and finishes the recovery. + * Should be called at the end of recovery in the envelop. + */ +extern void MOTRecoveryDone(); + +/** + * @brief Initializes the thread level resources for MOT redo recovery. + * If the MOT redo recovery is done in a separate thread other than the main thread which calls MOTRecover(), + * this API should be called to initialize the thread before performing redo recovery. + */ +extern void MOTBeginRedoRecovery(); + +/** + * @brief Cleans up the thread level resources. Used with MOTBeginRedoRecovery(). + * Should be called at the end of the thread after finishing redo recovery. + */ +extern void MOTEndRedoRecovery(); + +/** + * @brief Performs a commit or abort on an in-process two-phase transaction. Invoked from gs_clean. + * @param txid Transaction ID + * @param isCommit Specifies to commit or abort the transaction. + */ +extern void MOTProcessRecoveredTransaction(uint64_t txid, bool isCommit); + +/** + * @brief Notification from thread pool that a session ended (only when thread pool is ENABLED). + */ +extern void MOTOnSessionClose(); + +/** + * The following helpers APIs are used by base backup to fetch and send the MOT checkpoint files. + */ +extern void MOTCheckpointFetchLock(); +extern void MOTCheckpointFetchUnlock(); + +/** + * @brief Checks if an MOT checkpoint exists and returns its paths. + * @param ctrlFilePath a buffer to hold the MOT ctrl file path. + * @param ctrlLen the length of the given ctrl file path buffer. + * @param checkpointDir a buffer to hold the checkpoint path. + * @param checkpointLen the length of the given checkpoint path buffer. + * @param basePathLen the length of the base path. + * @return True if an MOT checkpoint exists, False indicates that no MOT checkpoint is present. + */ +extern bool MOTCheckpointExists( + char* ctrlFilePath, size_t ctrlLen, char* checkpointDir, size_t checkpointLen, size_t& basePathLen); + +#endif // MOT_FDW_H diff -uprN postgresql-hll-2.14_old/include/include/storage/mot/mot_xlog.h postgresql-hll-2.14/include/include/storage/mot/mot_xlog.h --- postgresql-hll-2.14_old/include/include/storage/mot/mot_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/mot/mot_xlog.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * mot_xlog.h + * Definitions of MOT xlog interface + * + * IDENTIFICATION + * src/include/storage/mot/mot_xlog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MOT_XLOG_H +#define MOT_XLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +extern void MOTRedo(XLogReaderState *record); +extern void MOTDesc(StringInfo buf, XLogReaderState *record); + +#endif /* MOT_XLOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/off.h postgresql-hll-2.14/include/include/storage/off.h --- postgresql-hll-2.14_old/include/include/storage/off.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/off.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * off.h + * POSTGRES disk "offset" definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/off.h + * + * ------------------------------------------------------------------------- + */ +#ifndef OFF_H +#define OFF_H + +#include "storage/itemid.h" +/* + * OffsetNumber: + * + * this is a 1-based index into the linp (ItemIdData) array in the + * header of each disk page. + */ +typedef uint16 OffsetNumber; + +#define InvalidOffsetNumber ((OffsetNumber)0) +#define FirstOffsetNumber ((OffsetNumber)1) +#define MaxOffsetNumber ((OffsetNumber)(BLCKSZ / sizeof(ItemIdData))) +#define OffsetNumberMask (0xffff) /* valid uint16 bits */ + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * OffsetNumberIsValid + * True iff the offset number is valid. + */ +#define OffsetNumberIsValid(offsetNumber) \ + ((bool)((offsetNumber != InvalidOffsetNumber) && (offsetNumber <= MaxOffsetNumber))) + +/* + * OffsetNumberNext + * OffsetNumberPrev + * Increments/decrements the argument. These macros look pointless + * but they help us disambiguate the different manipulations on + * OffsetNumbers (e.g., sometimes we subtract one from an + * OffsetNumber to move back, and sometimes we do so to form a + * real C array index). + */ +#define OffsetNumberNext(offsetNumber) ((OffsetNumber)(1 + (offsetNumber))) +#define OffsetNumberPrev(offsetNumber) ((OffsetNumber)(-1 + (offsetNumber))) + +#endif /* OFF_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/pagecompress.h postgresql-hll-2.14/include/include/storage/pagecompress.h --- postgresql-hll-2.14_old/include/include/storage/pagecompress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/pagecompress.h 2020-12-12 17:06:43.272348361 +0800 @@ -0,0 +1,300 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pagecompress.h + * page compression manager routines + * + * + * IDENTIFICATION + * src/include/storage/pagecompress.h + * + * mixed compression methods will be used, including delta/prefix/dict compression. + * delta compression would apply to data types: number; datetime; timestamp; number string; + * prefix compression would apply to data types: string; + * dictionary compression can apply to all the data types. + * one column only use the single one compression method. + * compressed tuples will be placed into one page with compression meta data. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PAGE_COMPRESS_H +#define PAGE_COMPRESS_H + +#include "c.h" +#include "access/htup.h" +#include "utils/relcache.h" +#include "storage/bufpage.h" +#include "utils/hsearch.h" + +/* Compression Mode + * + * CMPR_NUMSTR is a special kind of CMPR_DELTA. + * chars ('0'-'9') can be handled by delta-compression based on '0'. + * so that each number would be storaged in 4bits, and compression ratio is 2:1. + * !!! Note that You must also change ATT_CMPR_UNDEFINED and others in parsenode.h + * Description: we should refine code to remove these redundancy macro + */ +#define CMPR_DELTA 1 +#define CMPR_DICT 2 +#define CMPR_PREFIX 3 +#define CMPR_NUMSTR 4 +#define CMPR_NONE 0 +#define CMPR_UNDEF 0x7F + +typedef struct DictItemData { + char* itemData; + int16 itemSize; +} DictItemData; + +struct ColArray { + Datum* val; + bool* nulls; + int num; +}; + +struct DeltaCmprMeta { + Datum MinVal; + Datum MaxVal; + int bytes; +}; + +class DictCmprMeta { +public: + typedef struct { + DictItemData item; + unsigned char id; + } ItemEntry; + + void BuildHashTbl(MemoryContext memCxt); + unsigned char GetDictItemId(DictItemData* key, bool& found); + void Destroy(); + void GetDictItems(char* buf) const; + + int dictItemNum; + + /* MAX dictionary item number <= MAX_DICITEMID */ + DictItemData dictItems[256]; + int totalBytes; + + HTAB* m_hash; +}; + +struct PrefixCmprMeta { + char* prefixStr; + int len; +}; + +typedef union CmprMetaUnion { + DeltaCmprMeta deltaInfo; + DictCmprMeta dicInfo; + PrefixCmprMeta prefixInfo; +} CmprMetaUnion; + +typedef int (*CompareFuncPtr)(Datum, Datum); +typedef int64 (*MinusFuncPtr)(Datum, Datum); +typedef Datum (*PlusFuncPtr)(Datum, int64); + +typedef struct { + Oid typeOid; + CompareFuncPtr compare; + MinusFuncPtr minus; + PlusFuncPtr plus; +} NumberTypeOpt; + +typedef struct { + DictItemData key; + int16 hitCount; + bool beChoose; +} DictItemEntry; + +/* + * PageCompress + * Compress one page using multiple compression method. + * 1. Dictonary compression. + * 2. Delta value encoding. + * 3. Prefix compression. + */ +class PageCompress : public BaseObject { +public: + PageCompress(Relation rel, MemoryContext memCtx); + virtual ~PageCompress(); + + /* compress api */ + void SetBatchTuples(HeapTuple* tups, int ntups, bool last); + bool CompressOnePage(void); + + HeapTuple* GetOutputTups(void) + { + return m_outputTups; + } + int GetOutputCount(void) + { + return m_outputTupsNum; + } + const char* GetCmprHeaderData(void) + { + return m_cmprHeaderData; + } + int GetCmprHeaderSize(void) + { + return m_cmprHeaderSize; + } + int Remains(void) + { + return (m_inTupsNum - m_current); + } + const MemoryContext SelfMemCnxt(void) + { + return m_pageMemCnxt; + } + void BackWrite(void); + void ForwardWrite(void); + + /* decompress api */ + static void* FetchAttrCmprMeta(char* metaStart, const int attrRawLen, int* metaSize, char* mode); + static int GetAttrCmprValSize(char mode, int attlen, void* metaInfo, const char* attrStart); + static bool NeedExternalBuf(char mode); + static int UncompressOneAttr(char mode, char attalign, int attlen, void* metaInfo, char* attrStart, + int* attrCmprsValSize, char* uncmprValBuf); + static Datum UncompressOneAttr( + char mode, void* metaInfo, Oid typeOid, int attlen, char* attrStart, int* attrCmprsValSize); + +private: + /* compress methods */ + void CompressOneAttr(Datum val, bool null, FormCmprTupleData* formTuple, int col); + ColArray* DeformTups(HeapTuple* tups, int ntups); + + /* Choose compression method for each column */ + void ChooseMethodForFixedLenType(ColArray* colArray, int col); + void ChooseMethodForVaryLenType(ColArray* colArray, int col); + void ChooseCmprMethod(ColArray* colArray); + bool SetCmprMethod(ColArray* colArray, int col, int mode); + + /* delta compress methods */ + DeltaCmprMeta* DeltaGetCmprMeta(ColArray* colArray, const NumberTypeOpt* opt) const; + bool DeltaCompress(DeltaCmprMeta* deltaInfo, const NumberTypeOpt* opt, Datum val, unsigned char* deltaBuf) const; + static Datum DeltaUncompress(DeltaCmprMeta* delta, const NumberTypeOpt* opt, unsigned char* start); + + /* prefix compress methods */ + template + int PrefixLen(Datum str1, Datum str2); + template + char* PrefixGetCmprMeta(ColArray* colArray, int& prefixLen); + template + bool PrefixCompress(PrefixCmprMeta* prefix, Datum val, Datum& cmprsVal, int& cmprsValSize); + static Datum PrefixUncompress(int attlen, PrefixCmprMeta* prefix, char* start, int* valSize, + char* uncmprValBuf = NULL, int* dataLenWithPadding = NULL, char attalign = 'c'); + + /* dictionary compress methods */ + template + void FillHashKey(DictItemData& key, const int& attlen, const Datum& attval); + template + DictCmprMeta* DictGetCmprMeta(ColArray* colArray, int col, int attlen); + bool DictCompress(int col, Datum val, unsigned char& dictItemId); + static Datum DictUncompress(DictCmprMeta* metaInfo, const char* compressBuf, int attlen); + + /* number string compress mothods */ + template + bool NumstrEvaluate(ColArray* colArray); + template + static Datum NumstrCompress(Datum src, int& outSize); + static Datum NumstrUncompress(Datum src, int attlen, int& cmprValSize, char* uncmprValBuf = NULL, + int* dataLenWithPadding = NULL, char attalign = 'c'); + + /* write compression meta data and set its size*/ + void SetCmprHeaderData(void); + + /* dispatch tuples during compression */ + bool Dispatch(HeapTuple raw, HeapTuple cmpr, int& nowSize, const int& blksize); + bool Dispatch(HeapTuple raw, int& nowSize, const int& blksize); + void OutputRawTupsBeforeCmpr(int nToasts); + void OutputRawTupsAfterCmpr(int nToasts); + void OutputCmprTups(int nToasts); + void OutputToasts(void); + + /* memory context */ + void ResetPerPage(void); + void ResetCmprMeta(void); + +#ifdef USE_ASSERT_CHECKING + void CheckCmprDatum(Datum arg1, Datum arg2, Form_pg_attribute attr); + void CheckCmprAttr(Datum rawVal, bool rawNull, int col, FormCmprTupleData* formTuple); + void CheckCmprTuple(HeapTuple rawTup, HeapTuple cmprTup); + void CheckCmprHeaderData(void); + void CheckOutputTups(HeapTuple* cmpr, int nCmpr, HeapTuple* uncmpr, int nUncmpr, int nToasts); +#endif + +#ifdef TRACE_COMPRESS + void TraceCmprPage( + int flag, HeapTuple* cmpr, HeapTuple* mapped, int nCmpr, HeapTuple* uncmpr, int nUncmpr, int nToasts); + int nLoops; +#endif + + /* Output compressed tuples */ + char* m_cmprHeaderData; + HeapTuple* m_outputTups; + int m_outputTupsNum; + int m_cmprHeaderSize; + + /* + * input original tuples + * if not the last batch, maybe wait for continuing to read more tuples. + * but for the last, all tuples must be handled and written into pages. + */ + Relation m_rel; + HeapTuple* m_inTups; + int m_inTupsNum; + int m_current; + bool m_last; + + Datum* m_deformVals; + bool* m_deformNulls; + + /* compression mode && meta info && number type func */ + char* m_cmprMode; + void** m_cmprMeta; + + /* + * Each element represents for miss times when try to + * choose dictionary compression method for each column + */ + uint32* m_dictMiss; + unsigned char* m_dictItemId; + + const NumberTypeOpt** m_numTypeOpt; + + /* local memory context */ + MemoryContext m_pageMemCnxt; + MemoryContext m_parentMemCxt; + + /* handle toast tuples */ + HeapTuple* m_toastTups; + HeapTuple* m_mappedTups; + HeapTuple* m_cmprTups; + int m_toastTupsNum; + int m_mappedTupsNum; + int m_cmprTupsNum; + int m_uncmprTupIdx; + bool m_nextBatch; +}; + +/* -------------------------------- + * Page Compression Macros + * -------------------------------- + */ + +#define getPageDict(page) (AssertMacro(PageIsCompressed(page)), (PageGetSpecialPointer(page))) + +#endif /* PAGE_COMPRESS_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/parser.h postgresql-hll-2.14/include/include/storage/parser.h --- postgresql-hll-2.14_old/include/include/storage/parser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/parser.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,464 @@ +/* + * 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. + *--------------------------------------------------------------------------------------- + * + * parser.h + * + * IDENTIFICATION + * src/bin/gds/parser.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARSER_H +#define PARSER_H + +#include +#include +#include +#include + +#include "event.h" +#include "bulkload/utils.h" +#ifdef OBS_SERVER +#include "access/obs/obs_am.h" +#include "commands/copy.h" +#include "lib/stringinfo.h" +#endif + +using std::string; +using std::vector; + +typedef vector FileList; + +// for destructor function use +#define IGNORE_EXCEPTION(A) \ + try { \ + A; \ + } catch (...) { \ + } + +#define ROW_HEADER_SIZE 8 + +#ifndef USE_ASSERT_CHECKING +#define ASSERT(condition) +#else +#define ASSERT(condition) assert(condition) +#endif + +namespace GDS { +class LineBuffer { +public: + LineBuffer() + { + m_buf = NULL; + m_buf_len = 0; + m_used_len = 0; + + m_row_num = 0; + m_cur_line = NULL; + m_cur_line_len = 0; + m_cur_line_completed = true; + + m_output = NULL; +#ifdef OBS_SERVER + m_read_pos = 0; + m_overload_buf = NULL; + m_overload_buf_completed = false; +#endif + } + + ~LineBuffer() + { + if (m_buf != NULL) { + free(m_buf); + m_buf = NULL; + } + } + +#ifdef OBS_SERVER + + /* Get (via copy) next line reffered by m_read_pos */ + bool GetNextLine(StringInfo output_line); + + /* force mark the last line completed */ + void MarkLastLineCompleted(); + + /* Check if the m_read_pos has shift to last completed line in LineBuffer */ + inline bool NoMoreProcessed() + { + /* check if overload buffer has data to process */ + if (m_overload_buf->len) + return false; + + /* check if m_buf has data to process */ + int read_end_pos = m_cur_line_completed ? m_used_len : (m_cur_line - m_buf); + + if (m_read_pos >= read_end_pos) { + return true; + } + + return false; + }; + + /* + * Check if data in overload buffer and current line is completed + * return TRUE for overload buffer has data and the line is completed in overload buffer + */ + inline bool IsInOverloadBufferAndCompleted() + { + if (m_overload_buf->len != 0 && m_overload_buf_completed) + return true; + + return false; + } +#endif + inline int HasEnoughSpace(int buf_len) + { + if (m_cur_line_completed) + return m_buf_len - m_used_len - ROW_HEADER_SIZE - buf_len; + else + return m_buf_len - m_used_len - buf_len; + } + + inline int GetBufferUsedLen() + { + return m_used_len; + } + + inline int GetCompletedRowLen() + { + return m_cur_line - m_buf; + } + + inline int GetCurRowLen() + { + return m_cur_line_len; + } + + inline void ResetRowNum() + { + m_row_num = 0; + } + + inline bool IsCurRowCompleted() + { + return m_cur_line_completed; + } + + /* Set the current output evbuffer using the current connection output evbuffer. + * + * @param output the current connection output evbuffer + * @return void + */ + inline void SetOutput(struct evbuffer* output) + { + m_output = output; + } + + void Init(); + inline void Clean() + { + if (m_buf != NULL) + free(m_buf); + + m_buf = NULL; + } + void Reset(); + int AppendLine(const char* buf, int buf_len, bool isComplete); +#ifdef GDS_SERVER + + int PackData(evbuffer* dest, bool isFlush); + /*Send a overloaded buffer crossing multi packages. + * For supporting this scenrio some changes occur: + * (1) If a un-completed segment of line is sent, which uses speficied 0 line number to indicate; + * (2) If a un-completed segment of line is sent, wich length is the current segment length. + * + * @param dest the current connection output evbuffer + * @return int >=0 if success, <0 if fails. + */ + int SendOverloadBuf(evbuffer* dest, const char* buf, int buf_len, bool isComplete); +#endif +private: + char* m_buf; + int m_buf_len; + int m_used_len; + unsigned int m_row_num; + + char* m_cur_line; + int m_cur_line_len; + bool m_cur_line_completed; + + /* + * all members about overload buffer + */ + struct evbuffer* m_output; +#ifdef OBS_SERVER + StringInfo m_overload_buf; + int m_read_pos; + bool m_overload_buf_completed; + + /* save overload buffer to stringinfo for obs */ + void SaveOverloadBuf(StringInfo dest, const char* buf, int buf_len, bool isComplete); +#endif +}; + +class Source; + +typedef size_t (*SourceReadProc)(Source* self, void* buffer, size_t len); + +typedef bool (*SourceNextProc)(Source* self); +typedef enum { SOURCE_TYPE_UNKNOWN, SOURCE_TYPE_FILE, SOURCE_TYPE_OBS } SourceType; + +class Source { +public: + const static size_t MAX_BUFFER_SIZE = 1024 * 1024; + + Source() + { + m_fd = NULL; + m_fifo = -1; + m_current = 0; + m_woffset = 0; + m_wused = 0; + m_writeBuf = NULL; + SourceRead = NULL; + SourceNext = NULL; +#ifdef OBS_SERVER + m_obs_options = NULL; + m_obs_end = false; + m_rwhandler = NULL; +#endif + /* + * The source type indicator is referred as UNKNOWN first, in constructor + * we first set its value to unknown and initialize to proper 'source type' + * at initialization time. + */ + m_sourcetype = SOURCE_TYPE_UNKNOWN; + } + + ~Source() + { + if (m_fd != NULL) { + fclose(m_fd); + m_fd = NULL; + } + +#ifndef WIN32 + if (m_fifo != -1) { + close(m_fifo); + m_fifo = -1; + } +#endif + if (m_writeBuf != NULL) { + free(m_writeBuf); + m_writeBuf = NULL; + } + + SourceRead = NULL; + SourceNext = NULL; + } +#ifdef GDS_SERVER + void SourceWrite(evbuffer* buffer, size_t len); +#endif + void SourceWrite(const char* buffer, size_t len); + + SourceReadProc SourceRead; + + SourceNextProc SourceNext; + + inline size_t GetWriteOffset() + { + return m_woffset; + } + + void GenerateNewFile(const char* prefix, const char* suffix = NULL); + void GenerateNewFileForExport(const char* prefix, const char* suffix); + void SourceFlush(); + + FileList* GetFileList() + { + return &m_files; + } + + void SetFileList(const FileList& files) + { + m_files = files; + } + inline void SetSourceType(SourceType sourcetype) + { + m_sourcetype = sourcetype; + }; +#ifdef OBS_SERVER + inline OBSReadWriteHandler* GetOBSReadWriteHandler(void) + { + return m_rwhandler; + }; + + inline void SetOBSReadWriteHandler(OBSReadWriteHandler* handler) + { + m_rwhandler = handler; + }; +#endif + void SetPath(const string& path) + { + m_path = path; + } + + string GetCurrentFilename() + { + return m_filename; + } + + void SourceInit(bool isWrite); + + void CloseCurrentFile(); + void CloseCurrentFileNoFlush(); + + FILE* m_fd; + int m_fifo; + FileList m_files; + int m_current; + string m_filename; +#ifdef OBS_SERVER + OBSReadWriteHandler* m_rwhandler; + bool m_obs_end; + ObsCopyOptions* m_obs_options; +#endif +private: + inline size_t SourceWriteInternal(const void* buffer, size_t len); + + size_t m_woffset; + char* m_writeBuf; + size_t m_wused; + string m_path; + /* new added from DWS */ + SourceType m_sourcetype; +}; + +typedef enum { RESULT_SUCCESS, RESULT_NEW_ONE, RESULT_EOF, RESULT_BUFFER_FULL } ParserResult; + +struct Parser; +/* + * Parser + */ +typedef void (*ParserInitProc)(Parser* self, CmdBegin* cmd, const FileList* files, SourceType sourcetype); +#ifdef GDS_SERVER +typedef ParserResult (*ParserReadLineProc)(Parser* self, struct evbuffer& buf); +#else +typedef ParserResult (*ParserReadLineProc)(Parser* self); +#endif +typedef ParserResult (*ParserWriteLineProc)(Parser* self, struct evbuffer& buf, int len); +typedef void (*ParserDestroyProc)(Parser* self); + +struct Parser { + ParserInitProc init; /*initialize*/ + ParserReadLineProc readlines; /* read one line */ + ParserWriteLineProc writelines; + ParserDestroyProc destroy; + ParserDestroyProc cleanup; + + Source* source; + + evbuffer* line_buffer; + + bool hasHeader; + + char* prefix; + + LineBuffer line_buffers; + + char* eol; +}; + +struct ReadableParser : public Parser { + + /** + * @brief Record Buffer. + * + * This buffer stores the data read from the input file. + */ + char* rec_buf; + + /** + * @brief Size of the record buffer. + */ + int buf_len; + + /** + * @brief Actual size in the record buffer, excluding the trailing NULL. + */ + int used_len; + + /** + * @brief Pointer to the current record in the record buffer. + */ + int cur; + + /** + * @brief Pointer to the current position of eol string read in the record buffer. + */ + int eol_cur; + + /** + * @brief Pointer to the position of eol string read in the last record buffer. + */ + int eol_cur_saved; + + /** + * @brief Pointer to the current record in the record buffer, for two situations: + * If the current parsed lines alreadily flushed to LineBuffer the same as cur; + * if not, the records between [cur, cur_need_flush] need be flushed to LineBuffer + * before next parse operation to avoid redundant parse operation. + */ + int cur_need_flush; + + /** + * @brief flag to show whether the current record in the record buffer is a + * completed line or not. If true means completed, false means not. + */ + bool is_cur_line_completed; + + /** + * @brief Flag indicating EOF has been encountered in the input file. + */ + bool eof; + + unsigned int row_num; +}; + +struct CSVParser : public ReadableParser { + char quote; /**< quotation string */ + char escape; /**< escape letter */ + + bool in_quote; /* current position is in quote */ + bool lastWasEsc; /* prev position is esc */ + bool in_cr; /* current position is after \r */ +}; + +struct FixParser : public ReadableParser { + int rowSize; +}; + +struct WritableParser : public Parser { + char* fileheader; + int headerSize; +}; +}; // namespace GDS +extern GDS::Parser* CreateParser(FileFormat format); + +#ifdef WIN32 +extern void LinuxPathToWin(char* path); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/pg_sema.h postgresql-hll-2.14/include/include/storage/pg_sema.h --- postgresql-hll-2.14_old/include/include/storage/pg_sema.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/pg_sema.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_sema.h + * Platform-independent API for semaphores. + * + * PostgreSQL requires counting semaphores (the kind that keep track of + * multiple unlock operations, and will allow an equal number of subsequent + * lock operations before blocking). The underlying implementation is + * not the same on every platform. This file defines the API that must + * be provided by each port. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pg_sema.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SEMA_H +#define PG_SEMA_H + +/* + * PGSemaphoreData and pointer type PGSemaphore are the data structure + * representing an individual semaphore. The contents of PGSemaphoreData + * vary across implementations and must never be touched by platform- + * independent code. PGSemaphoreData structures are always allocated + * in shared memory (to support implementations where the data changes during + * lock/unlock). + * + * pg_config.h must define exactly one of the USE_xxx_SEMAPHORES symbols. + */ + +#ifdef USE_NAMED_POSIX_SEMAPHORES + +#include + +typedef sem_t* PGSemaphoreData; +#endif + +#ifdef USE_UNNAMED_POSIX_SEMAPHORES + +#include + +typedef sem_t PGSemaphoreData; +#endif + +#ifdef USE_SYSV_SEMAPHORES + +typedef struct PGSemaphoreData { + int semId; /* semaphore set identifier */ + int semNum; /* semaphore number within set */ +} PGSemaphoreData; +#endif + +#ifdef USE_WIN32_SEMAPHORES + +typedef HANDLE PGSemaphoreData; +#endif + +typedef PGSemaphoreData* PGSemaphore; + +/* concurrent control for locale */ +extern PGSemaphoreData g_locale_sem; + +/* Module initialization (called during postmaster start or shmem reinit) */ +extern void PGReserveSemaphores(int maxSemas, int port); + +/* Initialize a PGSemaphore structure to represent a sema with count 1 */ +extern void PGSemaphoreCreate(PGSemaphore sema); + +/* Reset a previously-initialized PGSemaphore to have count 0 */ +extern void PGSemaphoreReset(PGSemaphore sema); + +/* Lock a semaphore (decrement count), blocking if count would be < 0 */ +extern void PGSemaphoreLock(PGSemaphore sema, bool interruptOK); + +/* Unlock a semaphore (increment count) */ +extern void PGSemaphoreUnlock(PGSemaphore sema); + +/* Lock a semaphore only if able to do so without blocking */ +extern bool PGSemaphoreTryLock(PGSemaphore sema); + +extern void cancelSemphoreRelease(void); + +#endif /* PG_SEMA_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/pg_shmem.h postgresql-hll-2.14/include/include/storage/pg_shmem.h --- postgresql-hll-2.14_old/include/include/storage/pg_shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/pg_shmem.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_shmem.h + * Platform-independent API for shared memory support. + * + * Every port is expected to support shared memory with approximately + * SysV-ish semantics; in particular, a memory block is not anonymous + * but has an ID, and we must be able to tell whether there are any + * remaining processes attached to a block of a specified ID. + * + * To simplify life for the SysV implementation, the ID is assumed to + * consist of two unsigned long values (these are key and ID in SysV + * terms). Other platforms may ignore the second value if they need + * only one ID number. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pg_shmem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHMEM_H +#define PG_SHMEM_H + +typedef struct PGShmemHeader /* standard header for all Postgres shmem */ { + int32 magic; /* magic # to identify Postgres segments */ +#define PGShmemMagic 679834894 + ThreadId creatorPID; /* PID of creating process */ + Size totalsize; /* total size of segment */ + Size freeoffset; /* offset to first free space */ + void* index; /* pointer to ShmemIndex table */ +#ifndef WIN32 /* Windows doesn't have useful inode#s */ + dev_t device; /* device data directory is on */ + ino_t inode; /* inode number of data directory */ +#endif +} PGShmemHeader; + +#ifdef EXEC_BACKEND +#ifndef WIN32 +extern THR_LOCAL unsigned long UsedShmemSegID; +#else +extern THR_LOCAL HANDLE UsedShmemSegID; +#endif +extern THR_LOCAL void* UsedShmemSegAddr; + +extern void PGSharedMemoryReAttach(void); +#endif + +extern THR_LOCAL void* UsedShmemSegAddr; + +#define PGSharedMemoryAttached() (NULL != UsedShmemSegAddr) + +extern PGShmemHeader* PGSharedMemoryCreate(Size size, bool makePrivate, int port); +extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2); +extern void PGSharedMemoryDetach(void); +extern void cancelIpcMemoryDetach(void); + +#endif /* PG_SHMEM_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/pmsignal.h postgresql-hll-2.14/include/include/storage/pmsignal.h --- postgresql-hll-2.14_old/include/include/storage/pmsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/pmsignal.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,75 @@ +/* ------------------------------------------------------------------------- + * + * pmsignal.h + * routines for signaling the postmaster from its child processes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pmsignal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PMSIGNAL_H +#define PMSIGNAL_H + +/* + * Reasons for signaling the postmaster. We can cope with simultaneous + * signals for different reasons. If the same reason is signaled multiple + * times in quick succession, however, the postmaster is likely to observe + * only one notification of it. This is okay for the present uses. + */ +typedef enum { + PMSIGNAL_RECOVERY_STARTED, /* recovery has started */ + PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */ + PMSIGNAL_LOCAL_RECOVERY_DONE, /* local recovery has done */ + PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */ + PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */ + PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */ + PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */ + PMSIGNAL_START_CATCHUP, /* start a data catchup worker */ + PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */ + PMSIGNAL_START_DATARECEIVER, /* start a datareceiver */ + PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */ + PMSIGNAL_DEMOTE_PRIMARY, /* start to demote primary */ + PMSIGNAL_PROMOTE_STANDBY, /* start to promote standby */ + PMSIGNAL_UPDATE_WAITING, /* update waiting status to gaussdb.state */ + PMSIGNAL_UPDATE_PROMOTING, /* update promoting status to gaussdb.state */ + PMSIGNAL_UPDATE_HAREBUILD_REASON, /* update ha rebuild reason to gaussdb.state */ + PMSIGNAL_UPDATE_NORMAL, /* update normal status to gaussdb.state */ + PMSIGNAL_START_JOB_SCHEDULER, /* start a job scheduler */ + PMSIGNAL_START_JOB_WORKER, /* start a job worker */ + PMSIGNAL_ROLLBACK_STANDBY_PROMOTE, /* roll back standby promoting */ + PMSIGNAL_START_PAGE_WRITER, /* start a new page writer thread */ + PMSIGNAL_START_THREADPOOL_WORKER, /* start thread pool woker */ + NUM_PMSIGNALS /* Must be last value of enum! */ +} PMSignalReason; + +/* PMSignalData is an opaque struct, details known only within pmsignal.c */ +typedef struct PMSignalData PMSignalData; + +/* + * prototypes for functions in pmsignal.c + */ +extern Size PMSignalShmemSize(void); +extern void PMSignalShmemInit(void); +extern void SendPostmasterSignal(PMSignalReason reason); +extern bool CheckPostmasterSignal(PMSignalReason reason); +extern int AssignPostmasterChildSlot(void); +extern bool ReleasePostmasterChildSlot(int slot); +extern bool IsPostmasterChildWalSender(int slot); +extern bool IsPostmasterChildDataSender(int slot); +extern void MarkPostmasterChildActive(void); +extern void MarkPostmasterChildInactive(void); +extern void MarkPostmasterChildWalSender(void); +extern void MarkPostmasterChildDataSender(void); +extern void MarkPostmasterChildNormal(void); +extern bool PostmasterIsAlive(void); +extern void MarkPostmasterChildUnuseForStreamWorker(void); + +extern bool IsPostmasterChildSuspect(int slot); +extern void MarkPostmasterChildSusPect(void); +extern void MarkPostmasterTempBackend(void); +extern bool IsPostmasterChildTempBackend(int slot); +#endif /* PMSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/pos.h postgresql-hll-2.14/include/include/storage/pos.h --- postgresql-hll-2.14_old/include/include/storage/pos.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/pos.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * pos.h + * POSTGRES "position" definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pos.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POS_H +#define POS_H + +/* + * a 'position' used to be in postgres. this has + * been changed to just as the notion of having multiple pages + * within a block has been removed. + * + * the 'offset' abstraction is somewhat confusing. it is NOT a byte + * offset within the page; instead, it is an offset into the line + * pointer array contained on every page that store (heap or index) + * tuples. + */ +typedef bits16 PositionIdData; +typedef PositionIdData* PositionId; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * PositionIdIsValid + * True iff the position identifier is valid. + */ +#define PositionIdIsValid(positionId) PointerIsValid(positionId) + +/* + * PositionIdSetInvalid + * Make an invalid position. + */ +#define PositionIdSetInvalid(positionId) *(positionId) = (bits16)0 + +/* + * PositionIdSet + * Sets a position identifier to the specified value. + */ +#define PositionIdSet(positionId, offsetNumber) *(positionId) = (offsetNumber) + +/* + * PositionIdGetOffsetNumber + * Retrieve the offset number from a position identifier. + */ +#define PositionIdGetOffsetNumber(positionId) ((OffsetNumber) * (positionId)) + +#endif /* POS_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/predicate.h postgresql-hll-2.14/include/include/storage/predicate.h --- postgresql-hll-2.14_old/include/include/storage/predicate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/predicate.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * predicate.h + * POSTGRES public predicate locking definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/predicate.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDICATE_H +#define PREDICATE_H + +#include "utils/relcache.h" +#include "utils/snapshot.h" + +/* Number of SLRU buffers to use for predicate locking */ +#define NUM_OLDSERXID_BUFFERS 16 + +/* + * function prototypes + */ + +/* housekeeping for shared memory predicate lock structures */ +extern void InitPredicateLocks(void); +extern Size PredicateLockShmemSize(void); + +extern void CheckPointPredicate(void); + +/* predicate lock reporting */ +extern bool PageIsPredicateLocked(Relation relation, BlockNumber blkno); + +/* predicate lock maintenance */ +extern Snapshot GetSerializableTransactionSnapshot(Snapshot snapshot); +extern void SetSerializableTransactionSnapshot(Snapshot snapshot, TransactionId sourcexid); +extern void RegisterPredicateLockingXid(TransactionId xid); +extern void PredicateLockRelation(Relation relation, Snapshot snapshot); +extern void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot); +extern void PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot); +extern void PredicateLockPageSplit(Relation relation, BlockNumber oldblkno, BlockNumber newblkno); +extern void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno); +extern void TransferPredicateLocksToHeapRelation(Relation relation); +extern void ReleasePredicateLocks(bool isCommit); + +/* conflict detection (may also trigger rollback) */ +extern void CheckForSerializableConflictOut( + bool valid, Relation relation, HeapTuple tuple, Buffer buffer, Snapshot snapshot); +extern void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer); +extern void CheckTableForSerializableConflictIn(Relation relation); + +/* final rollback checking */ +extern void PreCommit_CheckForSerializationFailure(void); + +/* two-phase commit support */ +extern void AtPrepare_PredicateLocks(void); +extern void PostPrepare_PredicateLocks(TransactionId xid); +extern void PredicateLockTwoPhaseFinish(TransactionId xid, bool isCommit); +extern void predicatelock_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); + +#endif /* PREDICATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/predicate_internals.h postgresql-hll-2.14/include/include/storage/predicate_internals.h --- postgresql-hll-2.14_old/include/include/storage/predicate_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/predicate_internals.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,444 @@ +/* ------------------------------------------------------------------------- + * + * predicate_internals.h + * POSTGRES internal predicate locking definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/predicate_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDICATE_INTERNALS_H +#define PREDICATE_INTERNALS_H + +#include "storage/lock.h" + +/* + * Commit number. + */ +typedef uint64 SerCommitSeqNo; + +/* + * Reserved commit sequence numbers: + * - 0 is reserved to indicate a non-existent SLRU entry; it cannot be + * used as a SerCommitSeqNo, even an invalid one + * - InvalidSerCommitSeqNo is used to indicate a transaction that + * hasn't committed yet, so use a number greater than all valid + * ones to make comparison do the expected thing + * - RecoverySerCommitSeqNo is used to refer to transactions that + * happened before a crash/recovery, since we restart the sequence + * at that point. It's earlier than all normal sequence numbers, + * and is only used by recovered prepared transactions + */ +#define InvalidSerCommitSeqNo ((SerCommitSeqNo)UINT64CONST(0xFFFFFFFFFFFFFFFF)) +#define RecoverySerCommitSeqNo ((SerCommitSeqNo)1) +#define FirstNormalSerCommitSeqNo ((SerCommitSeqNo)2) + +/* + * The SERIALIZABLEXACT struct contains information needed for each + * serializable database transaction to support SSI techniques. + * + * A home-grown list is maintained in shared memory to manage these. + * An entry is used when the serializable transaction acquires a snapshot. + * Unless the transaction is rolled back, this entry must generally remain + * until all concurrent transactions have completed. (There are special + * optimizations for READ ONLY transactions which often allow them to be + * cleaned up earlier.) A transaction which is rolled back is cleaned up + * as soon as possible. + * + * Eligibility for cleanup of committed transactions is generally determined + * by comparing the transaction's finishedBefore field to + * SerializableGlobalXmin. + */ +typedef struct SERIALIZABLEXACT { + VirtualTransactionId vxid; /* The executing process always has one of + * these. */ + + /* + * We use two numbers to track the order that transactions commit. Before + * commit, a transaction is marked as prepared, and prepareSeqNo is set. + * Shortly after commit, it's marked as committed, and commitSeqNo is set. + * This doesn't give a strict commit order, but these two values together + * are good enough for us, as we can always err on the safe side and + * assume that there's a conflict, if we can't be sure of the exact + * ordering of two commits. + * + * Note that a transaction is marked as prepared for a short period during + * commit processing, even if two-phase commit is not used. But with + * two-phase commit, a transaction can stay in prepared state for some + * time. + */ + SerCommitSeqNo prepareSeqNo; + SerCommitSeqNo commitSeqNo; + + /* these values are not both interesting at the same time */ + union { + SerCommitSeqNo earliestOutConflictCommit; /* when committed with conflict out */ + SerCommitSeqNo lastCommitBeforeSnapshot; /* when not committed or no conflict out */ + } SeqNo; + SHM_QUEUE outConflicts; /* list of write transactions whose data we couldn't read. */ + SHM_QUEUE inConflicts; /* list of read transactions which couldn't see our write. */ + SHM_QUEUE predicateLocks; /* list of associated PREDICATELOCK objects */ + SHM_QUEUE finishedLink; /* list link in FinishedSerializableTransactions */ + + /* + * for r/o transactions: list of concurrent r/w transactions that we could + * potentially have conflicts with, and vice versa for r/w transactions + */ + SHM_QUEUE possibleUnsafeConflicts; + + TransactionId topXid; /* top level xid for the transaction, if one exists; else invalid */ + TransactionId finishedBefore; /* invalid means still running; else the struct expires when no + * serializable xids are before this. */ + TransactionId xmin; /* the transaction's snapshot xmin */ + uint32 flags; /* OR'd combination of values defined below */ + ThreadId pid; /* pid of associated process */ +} SERIALIZABLEXACT; + +#define SXACT_FLAG_COMMITTED 0x00000001 /* already committed */ +#define SXACT_FLAG_PREPARED 0x00000002 /* about to commit */ +#define SXACT_FLAG_ROLLED_BACK 0x00000004 /* already rolled back */ +#define SXACT_FLAG_DOOMED 0x00000008 /* will roll back */ +/* + * The following flag actually means that the flagged transaction has a + * conflict out *to a transaction which committed ahead of it*. It's hard + * to get that into a name of a reasonable length. + */ +#define SXACT_FLAG_CONFLICT_OUT 0x00000010 +#define SXACT_FLAG_READ_ONLY 0x00000020 +#define SXACT_FLAG_DEFERRABLE_WAITING 0x00000040 +#define SXACT_FLAG_RO_SAFE 0x00000080 +#define SXACT_FLAG_RO_UNSAFE 0x00000100 +#define SXACT_FLAG_SUMMARY_CONFLICT_IN 0x00000200 +#define SXACT_FLAG_SUMMARY_CONFLICT_OUT 0x00000400 + +/* + * The following types are used to provide an ad hoc list for holding + * SERIALIZABLEXACT objects. An HTAB is overkill, since there is no need to + * access these by key -- there are direct pointers to these objects where + * needed. If a shared memory list is created, these types can probably be + * eliminated in favor of using the general solution. + */ +typedef struct PredXactListElementData { + SHM_QUEUE link; + SERIALIZABLEXACT sxact; +} PredXactListElementData; + +typedef struct PredXactListElementData* PredXactListElement; + +#define PredXactListElementDataSize ((Size)MAXALIGN(sizeof(PredXactListElementData))) + +typedef struct PredXactListData { + SHM_QUEUE availableList; + SHM_QUEUE activeList; + + /* + * These global variables are maintained when registering and cleaning up + * serializable transactions. They must be global across all backends, + * but are not needed outside the predicate.c source file. Protected by + * SerializableXactHashLock. + */ + TransactionId SxactGlobalXmin; /* global xmin for active serializable + * transactions */ + int SxactGlobalXminCount; /* how many active serializable + * transactions have this xmin */ + int WritableSxactCount; /* how many non-read-only serializable + * transactions are active */ + SerCommitSeqNo LastSxactCommitSeqNo; /* a strictly monotonically + * increasing number for + * commits of serializable + * transactions */ + /* Protected by SerializableXactHashLock. */ + SerCommitSeqNo CanPartialClearThrough; /* can clear predicate locks + * and inConflicts for + * committed transactions + * through this seq no */ + /* Protected by SerializableFinishedListLock. */ + SerCommitSeqNo HavePartialClearedThrough; /* have cleared through this + * seq no */ + SERIALIZABLEXACT* OldCommittedSxact; /* shared copy of dummy sxact */ + + PredXactListElement element; +} PredXactListData; + +typedef struct PredXactListData* PredXactList; + +#define PredXactListDataSize ((Size)MAXALIGN(sizeof(PredXactListData))) + +/* + * The following types are used to provide lists of rw-conflicts between + * pairs of transactions. Since exactly the same information is needed, + * they are also used to record possible unsafe transaction relationships + * for purposes of identifying safe snapshots for read-only transactions. + * + * When a RWConflictData is not in use to record either type of relationship + * between a pair of transactions, it is kept on an "available" list. The + * outLink field is used for maintaining that list. + */ +typedef struct RWConflictData { + SHM_QUEUE outLink; /* link for list of conflicts out from a sxact */ + SHM_QUEUE inLink; /* link for list of conflicts in to a sxact */ + SERIALIZABLEXACT* sxactOut; + SERIALIZABLEXACT* sxactIn; +} RWConflictData; + +typedef struct RWConflictData* RWConflict; + +#define RWConflictDataSize ((Size)MAXALIGN(sizeof(RWConflictData))) + +typedef struct RWConflictPoolHeaderData { + SHM_QUEUE availableList; + RWConflict element; +} RWConflictPoolHeaderData; + +typedef struct RWConflictPoolHeaderData* RWConflictPoolHeader; + +#define RWConflictPoolHeaderDataSize ((Size)MAXALIGN(sizeof(RWConflictPoolHeaderData))) + +/* + * The SERIALIZABLEXIDTAG struct identifies an xid assigned to a serializable + * transaction or any of its subtransactions. + */ +typedef struct SERIALIZABLEXIDTAG { + TransactionId xid; +} SERIALIZABLEXIDTAG; + +/* + * The SERIALIZABLEXID struct provides a link from a TransactionId for a + * serializable transaction to the related SERIALIZABLEXACT record, even if + * the transaction has completed and its connection has been closed. + * + * These are created as new top level transaction IDs are first assigned to + * transactions which are participating in predicate locking. This may + * never happen for a particular transaction if it doesn't write anything. + * They are removed with their related serializable transaction objects. + * + * The SubTransGetTopmostTransaction method is used where necessary to get + * from an XID which might be from a subtransaction to the top level XID. + */ +typedef struct SERIALIZABLEXID { + /* hash key */ + SERIALIZABLEXIDTAG tag; + + /* data */ + SERIALIZABLEXACT* myXact; /* pointer to the top level transaction data */ +} SERIALIZABLEXID; + +/* + * The PREDICATELOCKTARGETTAG struct identifies a database object which can + * be the target of predicate locks. + * + * Note that the hash function being used doesn't properly respect tag + * length -- it will go to a four byte boundary past the end of the tag. + * If you change this struct, make sure any slack space is initialized, + * so that any random bytes in the middle or at the end are not included + * in the hash. + * + * If we always use the same fields for the same type of value, we + * should rename these. Holding off until it's clear there are no exceptions. + * Since indexes are relations with blocks and tuples, it's looking likely that + * the rename will be possible. If not, we may need to divide the last field + * and use part of it for a target type, so that we know how to interpret the + * data.. + */ +typedef struct PREDICATELOCKTARGETTAG { + uint32 locktag_field1; /* a 32-bit ID field */ + uint32 locktag_field2; /* a 32-bit ID field */ + uint32 locktag_field3; /* a 32-bit ID field */ + uint32 locktag_field4; /* a 32-bit ID field */ + uint32 locktag_field5; /* a 32-bit ID field */ +} PREDICATELOCKTARGETTAG; + +/* + * The PREDICATELOCKTARGET struct represents a database object on which there + * are predicate locks. + * + * A hash list of these objects is maintained in shared memory. An entry is + * added when a predicate lock is requested on an object which doesn't + * already have one. An entry is removed when the last lock is removed from + * its list. + * + * Because a particular target might become obsolete, due to update to a new + * version, before the reading transaction is obsolete, we need some way to + * prevent errors from reuse of a tuple ID. Rather than attempting to clean + * up the targets as the related tuples are pruned or vacuumed, we check the + * xmin on access. This should be far less costly. + */ +typedef struct PREDICATELOCKTARGET { + /* hash key */ + PREDICATELOCKTARGETTAG tag; /* unique identifier of lockable object */ + + /* data */ + SHM_QUEUE predicateLocks; /* list of PREDICATELOCK objects assoc. with + * predicate lock target */ +} PREDICATELOCKTARGET; + +/* + * The PREDICATELOCKTAG struct identifies an individual predicate lock. + * + * It is the combination of predicate lock target (which is a lockable + * object) and a serializable transaction which has acquired a lock on that + * target. + */ +typedef struct PREDICATELOCKTAG { + PREDICATELOCKTARGET* myTarget; + SERIALIZABLEXACT* myXact; +} PREDICATELOCKTAG; + +/* + * The PREDICATELOCK struct represents an individual lock. + * + * An entry can be created here when the related database object is read, or + * by promotion of multiple finer-grained targets. All entries related to a + * serializable transaction are removed when that serializable transaction is + * cleaned up. Entries can also be removed when they are combined into a + * single coarser-grained lock entry. + */ +typedef struct PREDICATELOCK { + /* hash key */ + PREDICATELOCKTAG tag; /* unique identifier of lock */ + + /* data */ + SHM_QUEUE targetLink; /* list link in PREDICATELOCKTARGET's list of + * predicate locks */ + SHM_QUEUE xactLink; /* list link in SERIALIZABLEXACT's list of + * predicate locks */ + SerCommitSeqNo commitSeqNo; /* only used for summarized predicate locks */ +} PREDICATELOCK; + +/* + * The LOCALPREDICATELOCK struct represents a local copy of data which is + * also present in the PREDICATELOCK table, organized for fast access without + * needing to acquire a LWLock. It is strictly for optimization. + * + * Each serializable transaction creates its own local hash table to hold a + * collection of these. This information is used to determine when a number + * of fine-grained locks should be promoted to a single coarser-grained lock. + * The information is maintained more-or-less in parallel to the + * PREDICATELOCK data, but because this data is not protected by locks and is + * only used in an optimization heuristic, it is allowed to drift in a few + * corner cases where maintaining exact data would be expensive. + * + * The hash table is created when the serializable transaction acquires its + * snapshot, and its memory is released upon completion of the transaction. + */ +typedef struct LOCALPREDICATELOCK { + /* hash key */ + PREDICATELOCKTARGETTAG tag; /* unique identifier of lockable object */ + + /* data */ + bool held; /* is lock held, or just its children? */ + int childLocks; /* number of child locks currently held */ +} LOCALPREDICATELOCK; + +/* + * The types of predicate locks which can be acquired. + */ +typedef enum PredicateLockTargetType { + PREDLOCKTAG_RELATION, + PREDLOCKTAG_PAGE, + PREDLOCKTAG_TUPLE + /* Other types may be needed for index locking */ +} PredicateLockTargetType; + +/* + * This structure is used to quickly capture a copy of all predicate + * locks. This is currently used only by the pg_lock_status function, + * which in turn is used by the pg_locks view. + */ +typedef struct PredicateLockData { + int nelements; + PREDICATELOCKTARGETTAG* locktags; + SERIALIZABLEXACT* xacts; +} PredicateLockData; + +/* + * These macros define how we map logical IDs of lockable objects into the + * physical fields of PREDICATELOCKTARGETTAG. Use these to set up values, + * rather than accessing the fields directly. Note multiple eval of target! + */ +#define SET_PREDICATELOCKTARGETTAG_RELATION(locktag, dboid, reloid) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = InvalidBlockNumber, \ + (locktag).locktag_field4 = InvalidOffsetNumber, \ + (locktag).locktag_field5 = InvalidTransactionId) + +#define SET_PREDICATELOCKTARGETTAG_PAGE(locktag, dboid, reloid, blocknum) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = (blocknum), \ + (locktag).locktag_field4 = InvalidOffsetNumber, \ + (locktag).locktag_field5 = InvalidTransactionId) + +#define SET_PREDICATELOCKTARGETTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum, xmin) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = (blocknum), \ + (locktag).locktag_field4 = (offnum), \ + (locktag).locktag_field5 = (xmin)) + +#define GET_PREDICATELOCKTARGETTAG_DB(locktag) ((Oid)(locktag).locktag_field1) +#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag) ((Oid)(locktag).locktag_field2) +#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag) ((BlockNumber)(locktag).locktag_field3) +#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag) ((OffsetNumber)(locktag).locktag_field4) +#define GET_PREDICATELOCKTARGETTAG_XMIN(locktag) ((TransactionId)(locktag).locktag_field5) +#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag) \ + (((locktag).locktag_field4 != InvalidOffsetNumber) \ + ? PREDLOCKTAG_TUPLE \ + : (((locktag).locktag_field3 != InvalidBlockNumber) ? PREDLOCKTAG_PAGE : PREDLOCKTAG_RELATION)) + +/* + * Two-phase commit statefile records. There are two types: for each + * transaction, we generate one per-transaction record and a variable + * number of per-predicate-lock records. + */ +typedef enum TwoPhasePredicateRecordType { + TWOPHASEPREDICATERECORD_XACT, + TWOPHASEPREDICATERECORD_LOCK +} TwoPhasePredicateRecordType; + +/* + * Per-transaction information to reconstruct a SERIALIZABLEXACT. Not + * much is needed because most of it not meaningful for a recovered + * prepared transaction. + * + * In particular, we do not record the in and out conflict lists for a + * prepared transaction because the associated SERIALIZABLEXACTs will + * not be available after recovery. Instead, we simply record the + * existence of each type of conflict by setting the transaction's + * summary conflict in/out flag. + */ +typedef struct TwoPhasePredicateXactRecord { + TransactionId xmin; + uint32 flags; +} TwoPhasePredicateXactRecord; + +/* Per-lock state */ +typedef struct TwoPhasePredicateLockRecord { + PREDICATELOCKTARGETTAG target; +} TwoPhasePredicateLockRecord; + +typedef struct TwoPhasePredicateRecord { + TwoPhasePredicateRecordType type; + union { + TwoPhasePredicateXactRecord xactRecord; + TwoPhasePredicateLockRecord lockRecord; + } data; +} TwoPhasePredicateRecord; + +/* + * Define a macro to use for an "empty" SERIALIZABLEXACT reference. + */ +#define InvalidSerializableXact ((SERIALIZABLEXACT*)NULL) + +/* + * Function definitions for functions needing awareness of predicate + * locking internals. + */ +extern PredicateLockData* GetPredicateLockStatusData(void); + +#endif /* PREDICATE_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/procarray.h postgresql-hll-2.14/include/include/storage/procarray.h --- postgresql-hll-2.14_old/include/include/storage/procarray.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/procarray.h 2020-12-12 17:06:43.273348374 +0800 @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------------- + * + * procarray.h + * POSTGRES process array definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/storage/procarray.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCARRAY_H +#define PROCARRAY_H + +#include "storage/standby.h" +#include "utils/snapshot.h" +#include "pgstat.h" + +// EB: removed "static" qualifier +extern void SyncLocalXidWait(TransactionId xid); + +extern Size ProcArrayShmemSize(void); +extern void CreateSharedProcArray(void); +extern void ProcArrayAdd(PGPROC* proc); +extern void ProcArrayRemove(PGPROC* proc, TransactionId latestXid); + +extern Size RingBufferShmemSize(void); +extern void CreateSharedRingBuffer(void); + +extern void ProcArrayEndTransaction(PGPROC* proc, TransactionId latestXid, bool isCommit = true); +extern void ProcArrayClearTransaction(PGPROC* proc); +extern bool TransactionIdIsInProgress( + TransactionId xid, uint32* needSync = NULL, bool shortcutByRecentXmin = false, bool bCareNextxid = false); + +#ifdef PGXC /* PGXC_DATANODE */ +extern void SetGlobalSnapshotData( + TransactionId xmin, TransactionId xmax, uint64 scn, GTM_Timeline timeline, bool ss_need_sync_wait_all); +extern void UnsetGlobalSnapshotData(void); +extern void ReloadConnInfoOnBackends(void); +#endif /* PGXC */ +extern char dump_memory_context_name[MEMORY_CONTEXT_NAME_LEN]; +extern void DumpMemoryCtxOnBackend(ThreadId tid, const char* mem_ctx); +extern void ProcArrayInitRecovery(TransactionId initializedUptoXID); +extern void ProcArrayApplyRecoveryInfo(RunningTransactions running); + +extern int GetMaxSnapshotXidCount(void); +extern int GetMaxSnapshotSubxidCount(void); + +#ifndef ENABLE_MULTIPLE_NODES +Snapshot GetSnapshotData(Snapshot snapshot, bool force_local_snapshot, bool forHSFeedBack = false); +#else +extern Snapshot GetSnapshotData(Snapshot snapshot, bool force_local_snapshot); +#endif + +extern Snapshot GetLocalSnapshotData(Snapshot snapshot); +extern void ReleaseSnapshotData(Snapshot snapshot); + +extern bool ProcArrayInstallImportedXmin(TransactionId xmin, TransactionId sourcexid); +extern RunningTransactions GetRunningTransactionData(void); + +extern bool TransactionIdIsActive(TransactionId xid); +extern TransactionId GetRecentGlobalXmin(void); +extern TransactionId GetOldestXmin(Relation rel, bool bFixRecentGlobalXmin = false); +extern void CheckCurrentTimeline(GTM_Timeline timeline); +extern TransactionId GetOldestActiveTransactionId(TransactionId *globalXmin); +extern void FixCurrentSnapshotByGxid(TransactionId gxid); +extern void CheckSnapshotIsValidException(Snapshot snapshot, const char* location); +extern TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly); +extern void CheckSnapshotTooOldException(Snapshot snapshot, const char* location); + +extern VirtualTransactionId* GetVirtualXIDsDelayingChkpt(int* nvxids); +extern bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId* vxids, int nvxids); + +extern PGPROC* BackendPidGetProc(ThreadId pid); +extern int BackendXidGetPid(TransactionId xid); +extern bool IsBackendPid(ThreadId pid); + +extern VirtualTransactionId* GetCurrentVirtualXIDs( + TransactionId limitXmin, bool excludeXmin0, bool allDbs, int excludeVacuum, int* nvxids); +extern VirtualTransactionId* GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid); +extern ThreadId CancelVirtualTransaction(const VirtualTransactionId& vxid, ProcSignalReason sigmode); + +extern bool MinimumActiveBackends(int min); +extern int CountDBBackends(Oid database_oid); +extern int CountDBActiveBackends(Oid database_oid); +extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending); +extern int CountUserBackends(Oid roleid); +extern bool CountOtherDBBackends(Oid databaseId, int* nbackends, int* nprepared); + +extern void XidCacheRemoveRunningXids(TransactionId xid, int nxids, const TransactionId* xids, TransactionId latestXid); +extern void SetPgXactXidInvalid(void); + +extern void ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin, bool already_locked); + +extern void ProcArrayGetReplicationSlotXmin(TransactionId* xmin, TransactionId* catalog_xmin); +extern TransactionId GetGlobal2pcXmin(); + +extern void CSNLogRecordAssignedTransactionId(TransactionId newXid); + +#ifdef PGXC +typedef enum { + SNAPSHOT_UNDEFINED, /* Coordinator has not sent snapshot or not yet connected */ + SNAPSHOT_LOCAL, /* Coordinator has instructed Datanode to build up snapshot from the local procarray */ + SNAPSHOT_COORDINATOR, /* Coordinator has sent snapshot data */ + SNAPSHOT_DIRECT, /* Datanode obtained directly from GTM */ + SNAPSHOT_DATANODE /* obtained directly from other thread in the same datanode*/ +} SnapshotSource; + +extern CommitSeqNo set_proc_csn_and_check( + const char* func, CommitSeqNo csn_min, GTM_SnapshotType gtm_snapshot_type, SnapshotSource from); +#endif + +extern void PrintCurrentSnapshotInfo(int logelevel, TransactionId xid, Snapshot snapshot, const char* action); +extern void ProcSubXidCacheClean(); +extern void InitProcSubXidCacheContext(); +extern void ProcArrayResetXmin(PGPROC* proc); +extern uint64 GetCommitCsn(); +extern void setCommitCsn(uint64 commit_csn); +extern void SyncWaitXidEnd(TransactionId xid, Buffer buffer); +extern CommitSeqNo calculate_local_csn_min(); +extern void proc_cancel_invalid_gtm_lite_conn(); +extern void forward_recent_global_xmin(void); + +extern void UpdateCSNLogAtTransactionEND( + TransactionId xid, int nsubxids, TransactionId* subXids, CommitSeqNo csn, bool isCommit); + +#endif /* PROCARRAY_H */ + +#ifdef ENABLE_UT +extern void ResetProcXidCache(PGPROC* proc, bool needlock); +#endif /* USE_UT */ + +// For GTT +extern TransactionId ListAllThreadGttFrozenxids(int maxSize, ThreadId *pids, TransactionId *xids, int *n); diff -uprN postgresql-hll-2.14_old/include/include/storage/proc.h postgresql-hll-2.14/include/include/storage/proc.h --- postgresql-hll-2.14_old/include/include/storage/proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/proc.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,439 @@ +/* ------------------------------------------------------------------------- + * + * proc.h + * per-process shared memory data structures + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/proc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PROC_H_ +#define _PROC_H_ + +#include "access/clog.h" +#include "access/xlog.h" +#include "datatype/timestamp.h" +#include "storage/latch.h" +#include "storage/lock.h" +#include "storage/pg_sema.h" +#include "threadpool/threadpool.h" +#include "replication/dataqueuedefs.h" +#include "utils/syscall_lock.h" +#include "pgtime.h" +#include "gtm/gtm_c.h" +#include "alarm/alarm.h" +#include "utils/atomic.h" +#include "access/multi_redo_settings.h" + + +/* + * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds + * for non-aborted subtransactions of its current top transaction. These + * have to be treated as running XIDs by other backends. + * + * We also keep track of whether the cache overflowed (ie, the transaction has + * generated at least one subtransaction that didn't fit in the cache). + * If none of the caches have overflowed, we can assume that an XID that's not + * listed anywhere in the PGPROC array is not a running transaction. Else we + * have to look at pg_subtrans. + */ +#define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */ + +#define PGPROC_INIT_CACHED_SUBXIDS 64 + +struct XidCache { + int maxNumber; /* max number of sub xids */ + TransactionId* xids; /* pointer to sub xids, memory allocate in g_instance.instance_context */ +}; + +/* Flags for PGXACT->vacuumFlags */ +#define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */ +#define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */ +#define PROC_IN_ANALYZE 0x04 /* currently running analyze */ +/* flags reset at EOXact */ +#define PROC_VACUUM_STATE_MASK (PROC_IN_VACUUM | PROC_IN_ANALYZE) +/* + * Flags reused to mark data redistribution xact at online expansion time + * we do not want to introduce a new field in PGXACT for data + * redistribution which increases the sizeof(PGXACT) and possiblely make + * it not fit into CPU cacheline. Please see the comments below for PGXACT + */ +#define PROC_IS_REDIST 0x10 /* currently running data redistribution */ +#define PROC_IN_LOGICAL_DECODING 0x20 /* currently doing logical decoding */ + +#define XACT_NOT_IN_USE 0 +#define XACT_IN_USE 1 + +/* + * We allow a small number of "weak" relation locks (AccesShareLock, + * RowShareLock, RowExclusiveLock) to be recorded in the PGPROC structure + * rather than the main lock table. This eases contention on the lock + * manager LWLocks. See storage/lmgr/README for additional details. + */ +#define FP_LOCK_SLOTS_PER_BACKEND 20 + +typedef struct FastPathTag { + uint32 dbid; + uint32 relid; + uint32 partitionid; +} FastPathTag; + +#define FAST_PATH_TAG_EQUALS(tag1, tag2) \ + (((tag1).dbid == (tag2).dbid) && ((tag1).relid == (tag2).relid) && ((tag1).partitionid == (tag2).partitionid)) + +/* + * An invalid pgprocno. Must be larger than the maximum number of PGPROC + * structures we could possibly have. See comments for MAX_BACKENDS. + */ +#define INVALID_PGPROCNO PG_INT32_MAX + +/* + * Each backend has a PGPROC struct in shared memory. There is also a list of + * currently-unused PGPROC structs that will be reallocated to new backends. + * + * links: list link for any list the PGPROC is in. When waiting for a lock, + * the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC + * is linked into ProcGlobal's freeProcs list. + * + * Note: twophase.c also sets up a dummy PGPROC struct for each currently + * prepared transaction. These PGPROCs appear in the ProcArray data structure + * so that the prepared transactions appear to be still running and are + * correctly shown as holding locks. A prepared transaction PGPROC can be + * distinguished from a real one at need by the fact that it has pid == 0. + * The semaphore and lock-activity fields in a prepared-xact PGPROC are unused, + * but its myProcLocks[] lists are valid. + */ +struct PGPROC { + /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */ + SHM_QUEUE links; /* list link if process is in a list */ + + PGSemaphoreData sem; /* ONE semaphore to sleep on */ + int waitStatus; /* STATUS_WAITING, STATUS_OK or STATUS_ERROR */ + /* STATUS_BLOCKING for update block session */ + + Latch procLatch; /* generic latch for process */ + + LocalTransactionId lxid; /* local id of top-level transaction currently + * being executed by this proc, if running; + * else InvalidLocalTransactionId */ + ThreadId pid; /* Backend's process ID; 0 if prepared xact */ + /* + * session id in mySessionMemoryEntry + * stream works share SessionMemoryEntry with their parent sessions, + * so sessMemorySessionid is their parent's as well. + */ + ThreadId sessMemorySessionid; + uint64 sessionid; /* if not zero, session id in thread pool*/ + int logictid; /*logic thread id*/ + TransactionId gtt_session_frozenxid; /* session level global temp table relfrozenxid */ + + int pgprocno; + int nodeno; + + /* These fields are zero while a backend is still starting up: */ + BackendId backendId; /* This backend's backend ID (if assigned) */ + Oid databaseId; /* OID of database this backend is using */ + Oid roleId; /* OID of role using this backend */ + + /* Backend or session working version number. */ + uint32 workingVersionNum; + + /* + * While in hot standby mode, shows that a conflict signal has been sent + * for the current transaction. Set/cleared while holding ProcArrayLock, + * though not required. Accessed without lock, if needed. + */ + bool recoveryConflictPending; + + /* Info about LWLock the process is currently waiting for, if any. */ + bool lwWaiting; /* true if waiting for an LW lock */ + uint8 lwWaitMode; /* lwlock mode being waited for */ + bool lwIsVictim; /* force to give up LWLock acquire */ + dlist_node lwWaitLink; /* next waiter for same LW lock */ + + /* Info about lock the process is currently waiting for, if any. */ + /* waitLock and waitProcLock are NULL if not currently waiting. */ + LOCK* waitLock; /* Lock object we're sleeping on ... */ + PROCLOCK* waitProcLock; /* Per-holder info for awaited lock */ + LOCKMODE waitLockMode; /* type of lock we're waiting for */ + LOCKMASK heldLocks; /* bitmask for lock types already held on this + * lock object by this backend */ + + /* + * Info to allow us to wait for synchronous replication, if needed. + * waitLSN is InvalidXLogRecPtr if not waiting; set only by user backend. + * syncRepState must not be touched except by owning process or WALSender. + * syncRepLinks used only while holding SyncRepLock. + */ + XLogRecPtr waitLSN; /* waiting for this LSN or higher */ + int syncRepState; /* wait state for sync rep */ + bool syncRepInCompleteQueue; /* waiting in complete queue */ + SHM_QUEUE syncRepLinks; /* list link if process is in syncrep queue */ + + DataQueuePtr waitDataSyncPoint; /* waiting for this data sync point */ + int dataSyncRepState; /* wait state for data sync rep */ + SHM_QUEUE dataSyncRepLinks; /* list link if process is in datasyncrep queue */ + + MemoryContext topmcxt; /*top memory context of this backend.*/ + char myProgName[64]; + pg_time_t myStartTime; + syscalllock deleMemContextMutex; + + /* + * All PROCLOCK objects for locks held or awaited by this backend are + * linked into one of these lists, according to the partition number of + * their lock. + */ + SHM_QUEUE myProcLocks[NUM_LOCK_PARTITIONS]; + + /* Support for group XID clearing. */ + /* true, if member of ProcArray group waiting for XID clear */ + bool procArrayGroupMember; + /* next ProcArray group member waiting for XID clear */ + pg_atomic_uint32 procArrayGroupNext; + /* + * latest transaction id among the transaction's main XID and + * subtransactions + */ + TransactionId procArrayGroupMemberXid; + + /* commit sequence number send down */ + CommitSeqNo commitCSN; + + /* Support for group transaction status update. */ + bool clogGroupMember; /* true, if member of clog group */ + pg_atomic_uint32 clogGroupNext; /* next clog group member */ + TransactionId clogGroupMemberXid; /* transaction id of clog group member */ + CLogXidStatus clogGroupMemberXidStatus; /* transaction status of clog + * group member */ + int64 clogGroupMemberPage; /* clog page corresponding to + * transaction id of clog group member */ + XLogRecPtr clogGroupMemberLsn; /* WAL location of commit record for clog + * group member */ +#ifdef __aarch64__ + /* Support for group xlog insert. */ + bool xlogGroupMember; + pg_atomic_uint32 xlogGroupNext; + XLogRecData* xlogGrouprdata; + XLogRecPtr xlogGroupfpw_lsn; + XLogRecPtr* xlogGroupProcLastRecPtr; + XLogRecPtr* xlogGroupXactLastRecEnd; + void* xlogGroupCurrentTransactionState; + XLogRecPtr* xlogGroupRedoRecPtr; + void* xlogGroupLogwrtResult; + XLogRecPtr xlogGroupReturntRecPtr; + TimeLineID xlogGroupTimeLineID; + bool* xlogGroupDoPageWrites; + bool xlogGroupIsFPW; + uint64 snap_refcnt_bitmap; +#endif + + LWLock* subxidsLock; + struct XidCache subxids; /* cache for subtransaction XIDs */ + + volatile GtmHostIndex my_gtmhost; + GtmHostIndex suggested_gtmhost; + pg_atomic_uint32 signal_cancel_gtm_conn_flag; + + /* Per-backend LWLock. Protects fields below. */ + LWLock* backendLock; /* protects the fields below */ + + /* Lock manager data, recording fast-path locks taken by this backend. */ + uint64 fpLockBits; /* lock modes held for each fast-path slot */ + FastPathTag fpRelId[FP_LOCK_SLOTS_PER_BACKEND]; /* slots for rel oids */ + bool fpVXIDLock; /* are we holding a fast-path VXID lock? */ + LocalTransactionId fpLocalTransactionId; /* lxid for fast-path VXID + * lock */ + /* The proc which block cur proc */ + PROCLOCK* blockProcLock; + + /* knl_thrd_context who is waiting for lock. Only valid when itself is in ProcSleep() now. */ + void *waitLockThrd; + char *dw_unaligned_buf; + char *dw_buf; + volatile int32 dw_pos; +}; + +/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */ + +/* the offset of the last padding if exists*/ +#define PGXACT_PAD_OFFSET 55 + +/* + * Prior to PostgreSQL 9.2, the fields below were stored as part of the + * PGPROC. However, benchmarking revealed that packing these particular + * members into a separate array as tightly as possible sped up GetSnapshotData + * considerably on systems with many CPU cores, by reducing the number of + * cache lines needing to be fetched. Thus, think very carefully before adding + * anything else here. + */ +typedef struct PGXACT { + GTM_TransactionHandle handle; /* txn handle in GTM */ + TransactionId xid; /* id of top-level transaction currently being + * executed by this proc, if running and XID + * is assigned; else InvalidTransactionId */ + TransactionId prepare_xid; + + TransactionId xmin; /* minimal running XID as it was when we were + * starting our xact, excluding LAZY VACUUM: + * vacuum must not remove tuples deleted by + * xid >= xmin ! */ + CommitSeqNo csn_min; /* local csn min */ + TransactionId next_xid; /* xid sent down from CN */ + int nxids; /* use int replace uint8, avoid overflow when sub xids >= 256 */ + uint8 vacuumFlags; /* vacuum-related flags, see above */ + + uint32 needToSyncXid; /* At GTM mode, there's a window between CSN log set and proc array remove. + * In this window, we can get CSN but TransactionIdIsInProgress returns true, + * So we need to sync at this window. + */ + bool delayChkpt; /* true if this proc delays checkpoint start; + * previously called InCommit */ +#ifdef __aarch64__ + char padding[PG_CACHE_LINE_SIZE - PGXACT_PAD_OFFSET]; /*padding to 128 bytes*/ +#endif +} PGXACT; + +/* the offset of the last padding if exists*/ +#define PROC_HDR_PAD_OFFSET 112 + +/* + * There is one ProcGlobal struct for the whole database cluster. + */ +typedef struct PROC_HDR { + /* Array of PGPROC structures (not including dummies for prepared txns) */ + PGPROC** allProcs; + /* Array of PGXACT structures (not including dummies for prepared txns) */ + PGXACT* allPgXact; + /* Length of allProcs array */ + uint32 allProcCount; + /* Length of all non-prepared Procs */ + uint32 allNonPreparedProcCount; + /* Head of list of free PGPROC structures */ + PGPROC* freeProcs; + /* Head of list of autovacuum's free PGPROC structures */ + PGPROC* autovacFreeProcs; + /* Head of list of cm agent's free PGPROC structures */ + PGPROC* cmAgentFreeProcs; + /* Head of list of pg_job's free PGPROC structures */ + PGPROC* pgjobfreeProcs; + /* First pgproc waiting for group XID clear */ + pg_atomic_uint32 procArrayGroupFirst; + /* First pgproc waiting for group transaction status update */ + pg_atomic_uint32 clogGroupFirst; + /* WALWriter process's latch */ + Latch* walwriterLatch; + /* WALWriterAuxiliary process's latch */ + Latch* walwriterauxiliaryLatch; + /* Checkpointer process's latch */ + Latch* checkpointerLatch; + /* BCMWriter process's latch */ + Latch* cbmwriterLatch; + /* Current shared estimate of appropriate spins_per_delay value */ + int spins_per_delay; + /* The proc of the Startup process, since not in ProcArray */ + PGPROC* startupProc; + ThreadId startupProcPid; + /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ + int startupBufferPinWaitBufId; +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - PROC_HDR_PAD_OFFSET]; +#endif +} PROC_HDR; + +/* + * We set aside some extra PGPROC structures for auxiliary processes, + * ie things that aren't full-fledged backends but need shmem access. + * + * Background writer, checkpointer and WAL writer run during normal operation. + * Startup process and WAL receiver also consume 2 slots, but WAL writer is + * launched only after startup has exited, so we only need 4 slots. + * + * PGXC needs another slot for the pool manager process + */ +const int MAX_PAGE_WRITER_THREAD_NUM = 8; +const int MAX_BG_WRITER_THREAD_NUM = 8; +const int MAX_COMPACTION_THREAD_NUM = 100; + +/* number of multi auxiliary threads. */ +#define NUM_MULTI_AUX_PROC \ + (MAX_PAGE_WRITER_THREAD_NUM + \ + MAX_RECOVERY_THREAD_NUM + \ + MAX_BG_WRITER_THREAD_NUM + \ + g_instance.shmem_cxt.ThreadPoolGroupNum + \ + MAX_COMPACTION_THREAD_NUM) + +#define NUM_AUXILIARY_PROCS (NUM_SINGLE_AUX_PROC + NUM_MULTI_AUX_PROC) + +/* max number of CMA's connections */ +#define NUM_CMAGENT_PROCS (10) + +#define GLOBAL_ALL_PROCS \ + (g_instance.shmem_cxt.MaxBackends + \ + NUM_CMAGENT_PROCS + NUM_AUXILIARY_PROCS + g_instance.attr.attr_storage.max_prepared_xacts) + +#define GLOBAL_MAX_SESSION_NUM (2 * g_instance.shmem_cxt.MaxBackends) +#define GLOBAL_RESERVE_SESSION_NUM (g_instance.shmem_cxt.MaxReserveBackendId) +#define MAX_SESSION_SLOT_COUNT (GLOBAL_MAX_SESSION_NUM + GLOBAL_RESERVE_SESSION_NUM) +#define MAX_BACKEND_SLOT \ + (g_instance.attr.attr_common.enable_thread_pool ? MAX_SESSION_SLOT_COUNT : g_instance.shmem_cxt.MaxBackends) +#define MAX_SESSION_TIMEOUT 24 * 60 * 60 /* max session timeout value. */ + +#define BackendStatusArray_size (MAX_BACKEND_SLOT + NUM_AUXILIARY_PROCS) + +extern AlarmCheckResult ConnectionOverloadChecker(Alarm* alarm, AlarmAdditionalParam* additionalParam); + +/* + * Function Prototypes + */ +extern int ProcGlobalSemas(void); +extern Size ProcGlobalShmemSize(void); +extern void InitNuma(void); +extern void InitProcGlobal(void); +extern void InitProcess(void); +extern void InitProcessPhase2(void); +extern void InitAuxiliaryProcess(void); + +extern int GetAuxProcEntryIndex(int baseIdx); +extern void PublishStartupProcessInformation(void); + +extern bool HaveNFreeProcs(int n); +extern void ProcReleaseLocks(bool isCommit); +extern int GetUsedConnectionCount(void); +extern int GetUsedInnerToolConnCount(void); + +extern void ProcQueueInit(PROC_QUEUE* queue); +extern int ProcSleep(LOCALLOCK* locallock, LockMethod lockMethodTable, bool allow_con_update); +extern PGPROC* ProcWakeup(PGPROC* proc, int waitStatus); +extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK* lock, const PROCLOCK* proclock = NULL); +extern bool IsWaitingForLock(void); +extern void LockErrorCleanup(void); + +extern void ProcWaitForSignal(void); +extern void ProcSendSignal(ThreadId pid); + +extern TimestampTz GetStatementFinTime(); + +extern bool enable_sig_alarm(int delayms, bool is_statement_timeout); +extern bool enable_lockwait_sig_alarm(int delayms); +extern bool enable_session_sig_alarm(int delayms); +extern bool disable_session_sig_alarm(void); + +extern bool disable_sig_alarm(bool is_statement_timeout); +extern void handle_sig_alarm(SIGNAL_ARGS); + +extern bool enable_standby_sig_alarm(TimestampTz now, TimestampTz fin_time, bool deadlock_only); +extern bool disable_standby_sig_alarm(void); +extern void handle_standby_sig_alarm(SIGNAL_ARGS); + +extern ThreadId getThreadIdFromLogicThreadId(int logictid); +extern int getLogicThreadIdFromThreadId(ThreadId tid); + +extern bool IsRedistributionWorkerProcess(void); + +void CancelBlockedRedistWorker(LOCK* lock, LOCKMODE lockmode); +#endif /* PROC_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/procsignal.h postgresql-hll-2.14/include/include/storage/procsignal.h --- postgresql-hll-2.14_old/include/include/storage/procsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/procsignal.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * procsignal.h + * Routines for interprocess signalling + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/procsignal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCSIGNAL_H +#define PROCSIGNAL_H + +#include "storage/backendid.h" + +/* + * Reasons for signalling a Postgres child process (a backend or an auxiliary + * process, like checkpointer). We can cope with concurrent signals for different + * reasons. However, if the same reason is signaled multiple times in quick + * succession, the process is likely to observe only one notification of it. + * This is okay for the present uses. + * + * Also, because of race conditions, it's important that all the signals be + * defined so that no harm is done if a process mistakenly receives one. + */ +#ifdef PGXC +/* + * In the case of Postgres-XC, it may be possible that this backend is + * signaled during a pool manager reload process. In this case it means that + * remote node connection has been changed inside pooler, so backend has to + * abort its current transaction, reconnect to pooler and update its session + * information regarding remote node handles. + */ +#endif +typedef enum { + PROCSIG_CATCHUP_INTERRUPT, /* sinval catchup interrupt */ + PROCSIG_NOTIFY_INTERRUPT, /* listen/notify interrupt */ + PROCSIG_DEFAULTXACT_READONLY, /* default transaction read only */ +#ifdef PGXC + PROCSIG_PGXCPOOL_RELOAD, /* abort current transaction and reconnect to pooler */ + PROCSIG_MEMORYCONTEXT_DUMP, /* dump memory context on all backends */ + PROCSIG_UPDATE_WORKLOAD_DATA, /* update workload data */ + PROCSIG_SPACE_LIMIT, /* space limitation */ +#endif + + /* Recovery conflict reasons */ + PROCSIG_RECOVERY_CONFLICT_DATABASE, + PROCSIG_RECOVERY_CONFLICT_TABLESPACE, + PROCSIG_RECOVERY_CONFLICT_LOCK, + PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, + PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, + PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, + PROCSIG_EXECUTOR_FLAG, + + NUM_PROCSIGNALS /* Must be last! */ +} ProcSignalReason; + +/* + * prototypes for functions in procsignal.c + */ +extern Size ProcSignalShmemSize(void); +extern void ProcSignalShmemInit(void); + +extern void ProcSignalInit(int pss_idx); +extern int SendProcSignal(ThreadId pid, ProcSignalReason reason, BackendId backendId); + +extern void procsignal_sigusr1_handler(SIGNAL_ARGS); + +#endif /* PROCSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/reinit.h postgresql-hll-2.14/include/include/storage/reinit.h --- postgresql-hll-2.14_old/include/include/storage/reinit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/reinit.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * reinit.h + * Reinitialization of unlogged relations + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fd.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef REINIT_H +#define REINIT_H + +extern void ResetUnloggedRelations(int op); + +#define UNLOGGED_RELATION_CLEANUP 0x0001 +#define UNLOGGED_RELATION_INIT 0x0002 + +#endif /* REINIT_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/relfilenode.h postgresql-hll-2.14/include/include/storage/relfilenode.h --- postgresql-hll-2.14_old/include/include/storage/relfilenode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/relfilenode.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,253 @@ +/* ------------------------------------------------------------------------- + * + * relfilenode.h + * Physical access information for relations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/relfilenode.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELFILENODE_H +#define RELFILENODE_H + +#include "storage/backendid.h" +#include "storage/block.h" + +/* + * The physical storage of a relation consists of one or more forks. The + * main fork is always created, but in addition to that there can be + * additional forks for storing various metadata. ForkNumber is used when + * we need to refer to a specific fork in a relation. + */ +typedef int ForkNumber; + +#define PAX_DFS_TRUNCATE_FORKNUM -4 +#define PAX_DFS_FORKNUM -3 +#define DFS_FORKNUM -2 +#define InvalidForkNumber -1 +#define MAIN_FORKNUM 0 +#define FSM_FORKNUM 1 +#define VISIBILITYMAP_FORKNUM 2 +#define BCM_FORKNUM 3 +#define INIT_FORKNUM 4 + +/* + * NOTE: if you add a new fork, change MAX_FORKNUM below and update the + * forkNames array in catalog.c + */ +#define MAX_FORKNUM INIT_FORKNUM + +/* + * RelFileNode must provide all that we need to know to physically access + * a relation, with the exception of the backend ID, which can be provided + * separately. Note, however, that a "physical" relation is comprised of + * multiple files on the filesystem, as each fork is stored as a separate + * file, and each fork can be divided into multiple segments. See md.c. + * + * spcNode identifies the tablespace of the relation. It corresponds to + * pg_tablespace.oid. + * + * dbNode identifies the database of the relation. It is zero for + * "shared" relations (those common to all databases of a cluster). + * Nonzero dbNode values correspond to pg_database.oid. + * + * relNode identifies the specific relation. relNode corresponds to + * pg_class.relfilenode (NOT pg_class.oid, because we need to be able + * to assign new physical files to relations in some situations). + * Notice that relNode is only unique within a particular database. + * + * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is + * zero. We support shared relations only in the "global" tablespace. + * + * Note: in pg_class we allow reltablespace == 0 to denote that the + * relation is stored in its database's "default" tablespace (as + * identified by pg_database.dattablespace). However this shorthand + * is NOT allowed in RelFileNode structs --- the real tablespace ID + * must be supplied when setting spcNode. + * + * Note: in pg_class, relfilenode can be zero to denote that the relation + * is a "mapped" relation, whose current true filenode number is available + * from relmapper.c. Again, this case is NOT allowed in RelFileNodes. + * + * Note: various places use RelFileNode in hashtable keys. Therefore, + * there *must not* be any unused padding bytes in this struct. That + * should be safe as long as all the fields are of type Oid. + */ +typedef struct RelFileNode { + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ + int4 bucketNode; /* bucket */ +} RelFileNode; + +/*RelFileNodeOld: Old version relfilenode. Compatible with older versions of relfilenode.*/ + +typedef struct RelFileNodeOld +{ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ +} RelFileNodeOld; + +#define RelFileNodeRelCopy(relFileNodeRel, relFileNode) \ + do { \ + (relFileNodeRel).spcNode = (relFileNode).spcNode; \ + (relFileNodeRel).dbNode = (relFileNode).dbNode; \ + (relFileNodeRel).relNode = (relFileNode).relNode; \ + } while(0) + +#define RelFileNodeCopy(relFileNode, relFileNodeRel, bucketid) \ + do { \ + (relFileNode).spcNode = (relFileNodeRel).spcNode; \ + (relFileNode).dbNode = (relFileNodeRel).dbNode; \ + (relFileNode).relNode = (relFileNodeRel).relNode; \ + (relFileNode).bucketNode = bucketid; \ + } while(0) + +/*This struct used for remove duplicated file list where we scan part of BCM files*/ +typedef struct RelFileNodeKey { + RelFileNode relfilenode; /*relfilenode*/ + int columnid; /*column for CU store*/ +} RelFileNodeKey; + +typedef struct RelFileNodeKeyEntry { + RelFileNodeKey key; + int number; /*Times the relfilenode occurence*/ +} RelFileNodeKeyEntry; + +/* + * Augmenting a relfilenode with the backend ID provides all the information + * we need to locate the physical storage. The backend ID is InvalidBackendId + * for regular relations (those accessible to more than one backend), or the + * owning backend's ID for backend-local relations. Backend-local relations + * are always transient and removed in case of a database crash; they are + * never WAL-logged or fsync'd. + */ +typedef struct RelFileNodeBackend { + RelFileNode node; + BackendId backend; +} RelFileNodeBackend; + +typedef enum StorageEngine { ROW_STORE = 0, COLUMN_STORE } StorageEngine; + +#define IsSupportSE(se) (ROW_STORE <= se && se <= COLUMN_STORE) + +// key to identify data file +// +typedef struct RelFileNodeForkNum { + RelFileNodeBackend rnode; + BlockNumber segno; + ForkNumber forknumber; + StorageEngine storage; +} RelFileNodeForkNum; + +#define RelFileNodeBackendIsTemp(rnode) ((rnode).backend != InvalidBackendId) + +/* + * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first + * since that is most likely to be different in two unequal RelFileNodes. It + * is probably redundant to compare spcNode if the other fields are found equal, + * but do it anyway to be sure. Likewise for checking the backend ID in + * RelFileNodeBackendEquals. + */ +#define RelFileNodeEquals(node1, node2) \ + ((node1).relNode == (node2).relNode && (node1).dbNode == (node2).dbNode && (node1).spcNode == (node2).spcNode && \ + (node1).bucketNode == (node2).bucketNode) + +#define BucketRelFileNodeEquals(tarnode, srcnode) \ + ((tarnode).relNode == (srcnode).relNode && (tarnode).dbNode == (srcnode).dbNode && (tarnode).spcNode == (srcnode).spcNode && \ + (((tarnode).bucketNode == DIR_BUCKET_ID) || ((tarnode).bucketNode == (srcnode).bucketNode))) + +#define RelFileNodeRelEquals(node1, node2) \ + ((node1).relNode == (node2).relNode && \ + (node1).dbNode == (node2).dbNode && \ + (node1).spcNode == (node2).spcNode) + +#define RelFileNodeBackendEquals(node1, node2) \ + ((node1).node.relNode == (node2).node.relNode && (node1).node.dbNode == (node2).node.dbNode && \ + (node1).backend == (node2).backend && (node1).node.spcNode == (node2).node.spcNode && \ + (node1).node.bucketNode == (node2).node.bucketNode) + +// keep [MAX_FORKNUM, FirstColumnForkNum) unused. +// try my best to reduce the effect on updating. +#define FirstColForkNum (MAX_FORKNUM) + +// ColForkNum include column id information +// +#define IsValidColForkNum(forkNum) ((forkNum) > FirstColForkNum) + +#define IsValidDfsForkNum(forkNum) ((forkNum) == DFS_FORKNUM) + +#define IsValidPaxDfsForkNum(forkNum) ((forkNum) == PAX_DFS_FORKNUM) + +#define IsTruncateDfsForkNum(forkNum) ((forkNum) == PAX_DFS_TRUNCATE_FORKNUM) + +#define ColForkNum2ColumnId(forkNum) (AssertMacro(IsValidColForkNum(forkNum)), ((forkNum)-FirstColForkNum)) + +#define ColumnId2ColForkNum(attid) (AssertMacro(AttrNumberIsForUserDefinedAttr(attid)), (FirstColForkNum + (attid))) + +// fetch column number from forknum given. +#define GetColumnNum(forkNum) (IsValidColForkNum(forkNum) ? ColForkNum2ColumnId(forkNum) : 0) + +typedef struct { + RelFileNode filenode; + // for row table, *forknum* <= MAX_FORKNUM. + // for column table, *forknum* > FirstColForkNum. + ForkNumber forknum; + // relation's owner id + Oid ownerid; +} ColFileNode; + +typedef struct { + RelFileNodeOld filenode; + // for row table, *forknum* <= MAX_FORKNUM. + // for column table, *forknum* > FirstColForkNum. + ForkNumber forknum; + // relation's owner id + Oid ownerid; +} ColFileNodeRel; + +/* + * 1) ForkNumber type should be must be 32-bit; + * 2) forknum value occupies the lower 16-bit; + * 3) bucketid value occupies the upper 16-bit; + * If the upper three condition changes, please consider this function again. + */ +static inline void forknum_add_bucketid(ForkNumber& forknum, int4 bucketid) +{ + forknum = (ForkNumber)(((uint2)forknum) | (((uint2)(bucketid + 1)) << 16)); +} + +/* + * 1) converse ForkNumber to uint to make sure logic right-shift + * 2) converse the logic-right-shift result to int2 to ensure the negative bucketid value + */ +static inline int4 forknum_get_bucketid(const ForkNumber& forknum) +{ + return (int2)((((uint)forknum >> 16) & 0xffff) - 1); +} + +/* + * 1) converse ForkNumber to uint to make sure the bit-operation safe + * 2) converse the lower 16-bit to int2 to ensure the negative forknum + */ +static inline ForkNumber forknum_get_forknum(const ForkNumber& forknum) +{ + return (int2)((uint)forknum & 0xffff); +} + +#define ColFileNodeCopy(colFileNode, colFileNodeRel) \ + do { \ + (colFileNode)->filenode.spcNode = (colFileNodeRel)->filenode.spcNode; \ + (colFileNode)->filenode.dbNode = (colFileNodeRel)->filenode.dbNode; \ + (colFileNode)->filenode.relNode = (colFileNodeRel)->filenode.relNode; \ + (colFileNode)->filenode.bucketNode = forknum_get_bucketid((colFileNodeRel)->forknum); \ + (colFileNode)->forknum = forknum_get_forknum((colFileNodeRel)->forknum); \ + (colFileNode)->ownerid= (colFileNodeRel)->ownerid; \ + } while(0) + +#endif /* RELFILENODE_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/remote_adapter.h postgresql-hll-2.14/include/include/storage/remote_adapter.h --- postgresql-hll-2.14_old/include/include/storage/remote_adapter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/remote_adapter.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remote_adapter.h + * + * + * + * IDENTIFICATION + * src/include/storage/remote_adapter.h + * + * NOTE + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef REMOTE_ADAPTER_H +#define REMOTE_ADAPTER_H + +#include "c.h" + +#include "storage/remote_read.h" + +#define Free(x) \ + do { \ + if ((x)) \ + free((x)); \ + (x) = NULL; \ + } while (0) + +typedef struct TlsCertPath { + char caPath[MAX_PATH_LEN]; + char keyPath[MAX_PATH_LEN]; + char certPath[MAX_PATH_LEN]; +} TlsCertPath; + +typedef struct RemoteReadContext RemoteReadContext; + +extern RemoteReadContext* InitRemoteReadContext(); + +extern void ReleaseRemoteReadContext(RemoteReadContext* context); + +extern int StandbyReadCUforPrimary(uint32 spcnode, uint32 dbnode, uint32 relnode, int32 colid, uint64 offset, + int32 size, uint64 lsn, RemoteReadContext* context, char** cudata); + +extern int StandbyReadPageforPrimary(uint32 spcnode, uint32 dbnode, uint32 relnode, int16 bucketnode, int32 forknum, uint32 blocknum, + uint32 blocksize, uint64 lsn, RemoteReadContext* context, char** pagedata); + +extern void CleanWorkEnv(); + +extern bool GetCertEnv(const char* envName, char* outputEnvStr, size_t envValueLen); + +extern char* GetCertStr(char* path, int* len); + +extern int GetRemoteReadMode(); + +extern void OutputMsgforRPC(int elevel, const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +#endif /* REMOTE_ADAPTER_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/remote_read.h postgresql-hll-2.14/include/include/storage/remote_read.h --- postgresql-hll-2.14_old/include/include/storage/remote_read.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/remote_read.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remote_read.h + * + * + * + * IDENTIFICATION + * src/include/storage/remote_read.h + * + * NOTE + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef REMOTE_READ_H +#define REMOTE_READ_H + +#include "c.h" + +typedef enum { + REMOTE_READ_OFF = 0, /* not allow reomte read */ + REMOTE_READ_NON_AUTH, /* remote read no ssl */ + REMOTE_READ_AUTH /* remote read with SSL */ +} remote_read_param; + +#define REMOTE_READ_OK 0 +#define REMOTE_READ_NEED_WAIT 1 +#define REMOTE_READ_CRC_ERROR 2 +#define REMOTE_READ_RPC_ERROR 3 +#define REMOTE_READ_SIZE_ERROR 4 +#define REMOTE_READ_IO_ERROR 5 +#define REMOTE_READ_RPC_TIMEOUT 6 +#define REMOTE_READ_BLCKSZ_NOT_SAME 7 +#define REMOTE_READ_MEMCPY_ERROR 8 + +#define MAX_PATH_LEN 1024 + +#define MAX_IPADDR_LEN 32 + +extern const char* RemoteReadErrMsg(int error_code); + +extern void GetRemoteReadAddress(char* first_address, char* second_address, size_t address_len); + +extern void GetIPAndPort(char* address, char* ip, char* port, size_t len); + +extern void GetHostnamebyIP(const char* ip, char* hostname, size_t hostnameLen); + +extern bool CanRemoteRead(); + +extern bool IsRemoteReadModeAuth(); + +extern bool IsRemoteReadModeOn(); +extern int SetRemoteReadModeOffAndGetOldMode(); +extern void SetRemoteReadMode(int mode); + +#endif /* REMOTE_READ_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/shmem.h postgresql-hll-2.14/include/include/storage/shmem.h --- postgresql-hll-2.14_old/include/include/storage/shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/shmem.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * shmem.h + * shared memory management structures + * + * Historical note: + * A long time ago, Postgres' shared memory region was allowed to be mapped + * at a different address in each process, and shared memory "pointers" were + * passed around as offsets relative to the start of the shared memory region. + * That is no longer the case: each process must map the shared memory region + * at the same address. This means shared memory pointers can be passed + * around directly between different processes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/shmem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SHMEM_H +#define SHMEM_H + +#include "utils/hsearch.h" + +/* shmqueue.c */ +typedef struct SHM_QUEUE { + struct SHM_QUEUE* prev; + struct SHM_QUEUE* next; +} SHM_QUEUE; + +/* shmem.c */ +extern void InitShmemAccess(void* seghdr); +extern void InitShmemAllocation(void); +extern void* ShmemAlloc(Size size); +extern bool ShmemAddrIsValid(const void* addr); +extern void InitShmemIndex(void); +extern HTAB* ShmemInitHash(const char* name, long init_size, long max_size, HASHCTL* infoP, int hash_flags); +extern void* ShmemInitStruct(const char* name, Size size, bool* foundPtr); +extern Size add_size(Size s1, Size s2); +extern Size mul_size(Size s1, Size s2); + +/* ipci.c */ +extern void RequestAddinShmemSpace(Size size); + +/* size constants for the shmem index table */ +/* max size of data structure string name */ +#define SHMEM_INDEX_KEYSIZE (48) +/* estimated size of the shmem index table (not a hard limit) */ +#define SHMEM_INDEX_SIZE (64) + +/* this is a hash bucket in the shmem index table */ +typedef struct { + char key[SHMEM_INDEX_KEYSIZE]; /* string name */ + void* location; /* location in shared mem */ + Size size; /* # bytes allocated for the structure */ +} ShmemIndexEnt; + +/* + * prototypes for functions in shmqueue.c + */ +extern void SHMQueueInit(SHM_QUEUE* queue); +extern void SHMQueueElemInit(SHM_QUEUE* queue); +extern void SHMQueueDelete(SHM_QUEUE* queue); +extern void SHMQueueInsertBefore(SHM_QUEUE* queue, SHM_QUEUE* elem); +extern void SHMQueueInsertAfter(SHM_QUEUE* queue, SHM_QUEUE* elem); +extern Pointer SHMQueueNext(const SHM_QUEUE* queue, const SHM_QUEUE* curElem, Size linkOffset); +extern Pointer SHMQueuePrev(const SHM_QUEUE* queue, const SHM_QUEUE* curElem, Size linkOffset); +extern bool SHMQueueEmpty(const SHM_QUEUE* queue); +extern bool SHMQueueIsDetached(const SHM_QUEUE* queue); + +// Heap memory allocation +// +extern void* HeapMemAlloc(Size size); +extern HTAB* HeapMemInitHash(const char* name, long init_size, long max_size, HASHCTL* infoP, int hash_flags); +extern void HeapMemResetHash(HTAB* hashtbl, const char* tabname); + +#endif /* SHMEM_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/sinvaladt.h postgresql-hll-2.14/include/include/storage/sinvaladt.h --- postgresql-hll-2.14_old/include/include/storage/sinvaladt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/sinvaladt.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,43 @@ +/* ------------------------------------------------------------------------- + * + * sinvaladt.h + * POSTGRES shared cache invalidation data manager. + * + * The shared cache invalidation manager is responsible for transmitting + * invalidation messages between backends. Any message sent by any backend + * must be delivered to all already-running backends before it can be + * forgotten. (If we run out of space, we instead deliver a "RESET" + * message to backends that have fallen too far behind.) + * + * The struct type SharedInvalidationMessage, defining the contents of + * a single message, is defined in sinval.h. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/sinvaladt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SINVALADT_H +#define SINVALADT_H + +#include "storage/proc.h" +#include "storage/sinval.h" + +/* + * prototypes for functions in sinvaladt.c + */ +extern Size SInvalShmemSize(void); +extern void CreateSharedInvalidationState(void); +extern void CleanupWorkSessionInvalidation(void); +extern void SharedInvalBackendInit(bool sendOnly, bool worksession); +extern PGPROC* BackendIdGetProc(int backendID); + +extern void SIInsertDataEntries(const SharedInvalidationMessage* data, int n); +extern int SIGetDataEntries(SharedInvalidationMessage* data, int datasize); +extern void SICleanupQueue(bool callerHasWriteLock, int minFree); + +extern LocalTransactionId GetNextLocalTransactionId(void); + +#endif /* SINVALADT_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/sinval.h postgresql-hll-2.14/include/include/storage/sinval.h --- postgresql-hll-2.14_old/include/include/storage/sinval.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/sinval.h 2020-12-12 17:06:43.274348387 +0800 @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------------- + * + * sinval.h + * POSTGRES shared cache invalidation communication definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/sinval.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SINVAL_H +#define SINVAL_H + +#include + +#include "storage/relfilenode.h" + +/* + * We support several types of shared-invalidation messages: + * * invalidate a specific tuple in a specific catcache + * * invalidate all catcache entries from a given system catalog + * * invalidate a relcache entry for a specific logical relation + * * invalidate an smgr cache entry for a specific physical relation + * * invalidate the mapped-relation mapping for a given database + * More types could be added if needed. The message type is identified by + * the first "int8" field of the message struct. Zero or positive means a + * specific-catcache inval message (and also serves as the catcache ID field). + * Negative values identify the other message types, as per codes below. + * + * Catcache inval events are initially driven by detecting tuple inserts, + * updates and deletions in system catalogs (see CacheInvalidateHeapTuple). + * An update can generate two inval events, one for the old tuple and one for + * the new, but this is reduced to one event if the tuple's hash key doesn't + * change. Note that the inval events themselves don't actually say whether + * the tuple is being inserted or deleted. Also, since we transmit only a + * hash key, there is a small risk of unnecessary invalidations due to chance + * matches of hash keys. + * + * Note that some system catalogs have multiple caches on them (with different + * indexes). On detecting a tuple invalidation in such a catalog, separate + * catcache inval messages must be generated for each of its caches, since + * the hash keys will generally be different. + * + * Catcache and relcache invalidations are transactional, and so are sent + * to other backends upon commit. Internally to the generating backend, + * they are also processed at CommandCounterIncrement so that later commands + * in the same transaction see the new state. The generating backend also + * has to process them at abort, to flush out any cache state it's loaded + * from no-longer-valid entries. + * + * smgr and relation mapping invalidations are non-transactional: they are + * sent immediately when the underlying file change is made. + */ + +typedef struct { + int8 id; /* cache ID --- must be first */ + Oid dbId; /* database ID, or 0 if a shared relation */ + uint32 hashValue; /* hash value of key for this catcache */ +} SharedInvalCatcacheMsg; + +#define SHAREDINVALCATALOG_ID (-1) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 if a shared catalog */ + Oid catId; /* ID of catalog whose contents are invalid */ +} SharedInvalCatalogMsg; + +#define SHAREDINVALRELCACHE_ID (-2) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 if a shared relation */ + Oid relId; /* relation ID */ +} SharedInvalRelcacheMsg; + +#define SHAREDINVALSMGR_ID (-3) + +typedef struct { + /* note: field layout chosen to pack into 16 bytes */ + int8 id; /* type field --- must be first */ + int8 backend_hi; /* high bits of backend ID, if temprel */ + uint16 backend_lo; /* low bits of backend ID, if temprel */ + RelFileNodeOld rnode; /* spcNode, dbNode, relNode */ +} SharedInvalSmgrMsg; + +#define SHAREDINVALRELMAP_ID (-4) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 for shared catalogs */ +} SharedInvalRelmapMsg; + +#define SHAREDINVALPARTCACHE_ID (-5) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID */ + Oid partId; /* partition ID */ +} SharedInvalPartcacheMsg; + +#define SHAREDINVALHBKTSMGR_ID (-6) + +typedef struct { + /* note: field layout chosen to pack into 16 bytes */ + int8 id; /* type field --- must be first */ + int16 bucketId; /* bucketId */ + RelFileNodeOld rnode; /* spcNode, dbNode, relNode */ +} SharedInvalHbktSmgrMsg; + +#define SHAREDINVALFUNC_ID (-7) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID */ + Oid funcOid; /* function ID */ +} SharedInvalFuncMsg; + +typedef union SharedInvalidationMessage { + int8 id; /* type field --- must be first */ + SharedInvalCatcacheMsg cc; + SharedInvalCatalogMsg cat; + SharedInvalRelcacheMsg rc; + SharedInvalPartcacheMsg pc; + SharedInvalSmgrMsg sm; + SharedInvalHbktSmgrMsg hbksm; + SharedInvalRelmapMsg rm; + SharedInvalFuncMsg fm; +} SharedInvalidationMessage; + +/* Counter of messages processed; don't worry about overflow. */ +extern THR_LOCAL volatile sig_atomic_t catchupInterruptPending; + +extern void SendSharedInvalidMessages(const SharedInvalidationMessage* msgs, int n); +extern void ReceiveSharedInvalidMessages( + void (*invalFunction)(SharedInvalidationMessage* msg), void (*resetFunction)(void)); + +/* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */ +extern void HandleCatchupInterrupt(void); + +/* + * enable/disable processing of catchup events directly from signal handler. + * The enable routine first performs processing of any catchup events that + * have occurred since the last disable. + */ +extern void ProcessCatchupInterrupt(void); + +extern int xactGetCommittedInvalidationMessages(SharedInvalidationMessage** msgs, bool* RelcacheInitFileInval); +extern void ProcessCommittedInvalidationMessages( + SharedInvalidationMessage* msgs, int nmsgs, bool RelcacheInitFileInval, Oid dbid, Oid tsid); +extern void LocalExecuteInvalidationMessage(SharedInvalidationMessage* msg); +#endif /* SINVAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/s_lock.h postgresql-hll-2.14/include/include/storage/s_lock.h --- postgresql-hll-2.14_old/include/include/storage/s_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/s_lock.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,1134 @@ +/* ------------------------------------------------------------------------- + * + * s_lock.h + * Hardware-dependent implementation of spinlocks. + * + * NOTE: none of the macros in this file are intended to be called directly. + * Call them through the hardware-independent macros in spin.h. + * + * The following hardware-dependent macros must be provided for each + * supported platform: + * + * void S_INIT_LOCK(slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void S_LOCK(slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void S_UNLOCK(slock_t *lock) + * Unlock a previously acquired lock. + * + * bool S_LOCK_FREE(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * void SPIN_DELAY(void) + * Delay operation to occur inside spinlock wait loop. + * + * Note to implementors: there are default implementations for all these + * macros at the bottom of the file. Check if your platform can use + * these or needs to override them. + * + * Usually, S_LOCK() is implemented in terms of even lower-level macros + * TAS() and TAS_SPIN(): + * + * int TAS(slock_t *lock) + * Atomic test-and-set instruction. Attempt to acquire the lock, + * but do *not* wait. Returns 0 if successful, nonzero if unable + * to acquire the lock. + * + * int TAS_SPIN(slock_t *lock) + * Like TAS(), but this version is used when waiting for a lock + * previously found to be contended. By default, this is the + * same as TAS(), but on some architectures it's better to poll a + * contended lock using an unlocked instruction and retry the + * atomic test-and-set only when it appears free. + * + * TAS() and TAS_SPIN() are NOT part of the API, and should never be called + * directly. + * + * CAUTION: on some platforms TAS() and/or TAS_SPIN() may sometimes report + * failure to acquire a lock even when the lock is not locked. For example, + * on Alpha TAS() will "fail" if interrupted. Therefore a retry loop must + * always be used, even if you are certain the lock is free. + * + * It is the responsibility of these macros to make sure that the compiler + * does not re-order accesses to shared memory to precede the actual lock + * acquisition, or follow the lock release. Prior to PostgreSQL 9.5, this + * was the caller's responsibility, which meant that callers had to use + * volatile-qualified pointers to refer to both the spinlock itself and the + * shared data being accessed within the spinlocked critical section. This + * was notationally awkward, easy to forget (and thus error-prone), and + * prevented some useful compiler optimizations. For these reasons, we + * now require that the macros themselves prevent compiler re-ordering, + * so that the caller doesn't need to take special precautions. + * + * On platforms with weak memory ordering, the TAS(), TAS_SPIN(), and + * S_UNLOCK() macros must further include hardware-level memory fence + * instructions to prevent similar re-ordering at the hardware level. + * TAS() and TAS_SPIN() must guarantee that loads and stores issued after + * the macro are not executed until the lock has been obtained. Conversely, + * S_UNLOCK() must guarantee that loads and stores issued before the macro + * have been executed before the lock is released. + * + * On most supported platforms, TAS() uses a tas() function written + * in assembly language to execute a hardware atomic-test-and-set + * instruction. Equivalent OS-supplied mutex routines could be used too. + * + * If no system-specific TAS() is available (ie, HAVE_SPINLOCKS is not + * defined), then we fall back on an emulation that uses SysV semaphores + * (see spin.c). This emulation will be MUCH MUCH slower than a proper TAS() + * implementation, because of the cost of a kernel call per lock or unlock. + * An old report is that Postgres spends around 40% of its time in semop(2) + * when using the SysV semaphore code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/s_lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef S_LOCK_H +#define S_LOCK_H + +#include "storage/pg_sema.h" + +#if !defined(ENABLE_THREAD_CHECK) || defined(__aarch64__) + +#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +/************************************************************************* + * All the gcc inlines + * Gcc consistently defines the CPU as __cpu__. + * Other compilers use __cpu or __cpu__ so we test for both in those cases. + */ + +/* ---------- + * Standard gcc asm format (assuming "volatile slock_t *lock"): + + __asm__ __volatile__( + " instruction \n" + " instruction \n" + " instruction \n" +: "=r"(_res), "+m"(*lock) // return register, in/out lock value +: "r"(lock) // lock pointer, in input register +: "memory", "cc"); // show clobbered registers here + + * The output-operands list (after first colon) should always include + * "+m"(*lock), whether or not the asm code actually refers to this + * operand directly. This ensures that gcc believes the value in the + * lock variable is used and set by the asm code. Also, the clobbers + * list (after third colon) should always include "memory"; this prevents + * gcc from thinking it can cache the values of shared-memory fields + * across the asm code. Add "cc" if your asm code changes the condition + * code register, and also list any temp registers the code uses. + * ---------- + */ + +#ifdef __i386__ /* 32-bit i386 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * Use a non-locking test before asserting the bus lock. Note that the + * extra test appears to be a small loss on some x86 platforms and a small + * win on others; it's by no means clear that we should keep it. + */ + __asm__ __volatile__(" cmpb $0,%1 \n" + " jne 1f \n" + " lock \n" + " xchgb %0,%1 \n" + "1: \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * This sequence is equivalent to the PAUSE instruction ("rep" is + * ignored by old IA32 processors if the following instruction is + * not a string operation); the IA-32 Architecture Software + * Developer's Manual, Vol. 3, Section 7.7.2 describes why using + * PAUSE in the inner loop of a spin lock is necessary for good + * performance: + * + * The PAUSE instruction improves the performance of IA-32 + * processors supporting Hyper-Threading Technology when + * executing spin-wait loops and other routines where one + * thread is accessing a shared lock or semaphore in a tight + * polling loop. When executing a spin-wait loop, the + * processor can suffer a severe performance penalty when + * exiting the loop because it detects a possible memory order + * violation and flushes the core processor's pipeline. The + * PAUSE instruction provides a hint to the processor that the + * code sequence is a spin-wait loop. The processor uses this + * hint to avoid the memory order violation and prevent the + * pipeline flush. In addition, the PAUSE instruction + * de-pipelines the spin-wait loop to prevent it from + * consuming execution resources excessively. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __i386__ */ + +#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * On Opteron, using a non-locking test before the locking instruction + * is a huge loss. On EM64T, it appears to be a wash or small loss, + * so we needn't bother to try to distinguish the sub-architectures. + */ + __asm__ __volatile__(" lock \n" + " xchgb %0,%1 \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * Adding a PAUSE in the spin delay loop is demonstrably a no-op on + * Opteron, but it may be of some use on EM64T, so we keep it. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __x86_64__ */ + +#if defined(__ia64__) || defined(__ia64) +/* + * Intel Itanium, gcc or Intel's compiler. + * + * Itanium has weak memory ordering, but we rely on the compiler to enforce + * strict ordering of accesses to volatile data. In particular, while the + * xchg instruction implicitly acts as a memory barrier with 'acquire' + * semantics, we do not have an explicit memory fence instruction in the + * S_UNLOCK macro. We use a regular assignment to clear the spinlock, and + * trust that the compiler marks the generated store instruction with the + * ".rel" opcode. + * + * Testing shows that assumption to hold on gcc, although I could not find + * any explicit statement on that in the gcc manual. In Intel's compiler, + * the -m[no-]serialize-volatile option controls that, and testing shows that + * it is enabled by default. + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +#ifndef __INTEL_COMPILER + +static __inline__ int tas(volatile slock_t* lock) +{ + long int ret; + + __asm__ __volatile__(" xchg4 %0=%1,%2 \n" : "=r"(ret), "+m"(*lock) : "r"(1) : "memory"); + return (int)ret; +} + +#else /* __INTEL_COMPILER */ + +static __inline__ int tas(volatile slock_t* lock) +{ + int ret; + + ret = _InterlockedExchange(lock, 1); /* this is a xchg asm macro */ + + return ret; +} + +#endif /* __INTEL_COMPILER */ +#endif /* __ia64__ || __ia64 */ + +/* + * On ARM64, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ + +#if defined(__aarch64__) || defined(__aarch64) + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); + void AnnotateHappensAfter(const char *f, int l, uintptr_t addr); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateHappensAfter(addr) AnnotateHappensAfter(__FILE__, __LINE__, (uintptr_t)addr) +#else +#define TsAnnotateHappensBefore(addr) +#define TsAnnotateHappensAfter(addr) +#endif /* endif ENABLE_THREAD_CHECK */ + +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int +tas(volatile slock_t *lock) +{ + int ret = __sync_lock_test_and_set(lock, 1); + TsAnnotateHappensAfter(lock); + return ret; +} + +extern int (*arm_tas_spin)(volatile slock_t *lock); + +#define S_UNLOCK(lock) do { \ + TsAnnotateHappensBefore(lock); \ + __sync_lock_release(lock); \ +} while(0) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile register slock_t* ulAddr = lock; + register slock_t _res = 1; + unsigned int tmp = 0; + + __asm__ volatile("// __xchg4\n" + "1: ldaxr %w0, %2\n" + " stlxr %w1, %w3, %2\n" + " cbnz %w1, 1b\n" + : "=&r"(_res), "=&r"(tmp), "+Q"(*ulAddr) + : "r"(_res) + : "cc", "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __aarch64__ */ + +/* + * On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ +#if defined(__arm__) || defined(__arm) +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned char slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + __asm__ __volatile__(" swpb %0, %0, [%2] \n" : "+r"(_res), "+m"(*lock) : "r"(lock) : "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __arm__ */ + +/* S/390 and S/390x Linux (32- and 64-bit zSeries) */ +#if defined(__s390__) || defined(__s390x__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + int _res = 0; + + __asm__ __volatile__(" cs %0,%3,0(%2) \n" : "+d"(_res), "+m"(*lock) : "a"(lock), "d"(1) : "memory", "cc"); + return _res; +} + +#endif /* __s390__ || __s390x__ */ + +#if defined(__sparc__) /* Sparc */ +/* + * Solaris has always run sparc processors in TSO (total store) mode, but + * linux didn't use to and the *BSDs still don't. So, be careful about + * acquire/release semantics. The CPU will treat superflous membars as NOPs, + * so it's just code space. + */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + /* + * See comment in /pg/backend/port/tas/solaris_sparc.s for why this + * uses "ldstub", and that file uses "cas". gcc currently generates + * sparcv7-targeted binaries, so "cas" use isn't possible. + */ + __asm__ __volatile__(" ldstub [%2], %0 \n" : "=r"(_res), "+m"(*lock) : "r"(lock) : "memory"); +#if defined(__sparcv7) + /* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. + */ +#elif defined(__sparcv8) + /* stbar is available (and required for both PSO, RMO), membar isn't */ + __asm__ __volatile__("stbar \n" ::: "memory"); +#else + /* + * #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire + * barrier for sparcv8+ upwards. + */ + __asm__ __volatile__("membar #LoadStore | #LoadLoad \n" ::: "memory"); +#endif + return (int)_res; +} + +#if defined(__sparcv7) +/* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. We fall through to the default gcc definition of + * S_UNLOCK in this case. + */ +#elif defined(__sparcv8) +/* stbar is available (and required for both PSO, RMO), membar isn't */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("stbar \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#else +/* + * #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate + * release barrier for sparcv8+ upwards. + */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("membar #LoadStore | #StoreStore \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#endif + +#endif /* __sparc__ */ + +/* PowerPC */ +#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On PPC, it's a win to use a non-locking test before the lwarx */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +/* + * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002, + * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop. + * On newer machines, we can use lwsync instead for better performance. + */ +static __inline__ int tas(volatile slock_t* lock) +{ + slock_t _t; + int _res; + + __asm__ __volatile__( +#ifdef USE_PPC_LWARX_MUTEX_HINT + " lwarx %0,0,%3,1 \n" +#else + " lwarx %0,0,%3 \n" +#endif + " cmpwi %0,0 \n" + " bne 1f \n" + " addi %0,%0,1 \n" + " stwcx. %0,0,%3 \n" + " beq 2f \n" + "1: li %1,1 \n" + " b 3f \n" + "2: \n" +#ifdef USE_PPC_LWSYNC + " lwsync \n" +#else + " isync \n" +#endif + " li %1,0 \n" + "3: \n" + + : "=&r"(_t), "=r"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "cc"); + return _res; +} + +/* + * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction. + * On newer machines, we can use lwsync instead for better performance. + */ +#ifdef USE_PPC_LWSYNC +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" lwsync \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#else +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" sync \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#endif /* USE_PPC_LWSYNC */ + +#endif /* powerpc */ + +/* Linux Motorola 68k */ +#if (defined(__mc68000__) || defined(__m68k__)) && defined(__linux__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int rv; + + __asm__ __volatile__(" clrl %0 \n" + " tas %1 \n" + " sne %0 \n" + : "=d"(rv), "+m"(*lock) + : + : "memory", "cc"); + return rv; +} + +#endif /* (__mc68000__ || __m68k__) && __linux__ */ + +/* + * VAXen -- even multiprocessor ones + * (thanks to Tom Ivar Helbekkmo) + */ +#if defined(__vax__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" movl $1, %0 \n" + " bbssi $0, (%2), 1f \n" + " clrl %0 \n" + "1: \n" + : "=&r"(_res), "+m"(*lock) + : "r"(lock) + : "memory"); + return _res; +} + +#endif /* __vax__ */ + +#if defined(__ns32k__) /* National Semiconductor 32K */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" sbitb 0, %1 \n" + " sfsd %0 \n" + : "=r"(_res), "+m"(*lock) + : + : "memory"); + return _res; +} + +#endif /* __ns32k__ */ + +#if defined(__alpha) || defined(__alpha__) /* Alpha */ +/* + * Correct multi-processor locking methods are explained in section 5.5.3 + * of the Alpha AXP Architecture Handbook, which at this writing can be + * found at ftp://ftp.netbsd.org/pub/NetBSD/misc/dec-docs/index.html. + * For gcc we implement the handbook's code directly with inline assembler. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + __asm__ __volatile__(" ldq $0, %1 \n" + " bne $0, 2f \n" + " ldq_l %0, %1 \n" + " bne %0, 2f \n" + " mov 1, $0 \n" + " stq_c $0, %1 \n" + " beq $0, 2f \n" + " mb \n" + " br 3f \n" + "2: mov 1, %0 \n" + "3: \n" + : "=&r"(_res), "+m"(*lock) + : + : "memory", "0"); + return (int)_res; +} + +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" mb \n"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) + +#endif /* __alpha || __alpha__ */ + +#if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ +/* Note: on SGI we use the OS' mutex ABI, see below */ +/* Note: R10000 processors require a separate SYNC */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register volatile slock_t* _l = lock; + register int _res; + register int _tmp; + + __asm__ __volatile__(" .set push \n" + " .set mips2 \n" + " .set noreorder \n" + " .set nomacro \n" + " ll %0, %2 \n" + " or %1, %0, 1 \n" + " sc %1, %2 \n" + " xori %1, 1 \n" + " or %0, %0, %1 \n" + " sync \n" + " .set pop " + : "=&r"(_res), "=&r"(_tmp), "+R"(*_l) + : + : "memory"); + return _res; +} + +/* MIPS S_UNLOCK is almost standard but requires a "sync" instruction */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set mips2 \n" \ + " .set noreorder \n" \ + " .set nomacro \n" \ + " sync \n" \ + " .set pop " +: +: "memory"); +*((volatile slock_t*)(lock)) = 0; +} +while (0) + +#endif /* __mips__ && !__sgi */ + +#if defined(__m32r__) && defined(HAVE_SYS_TAS_H) /* Renesas' M32R */ +#define HAS_TEST_AND_SET + +#include + + typedef int slock_t; + +#define TAS(lock) tas(lock) + +#endif /* __m32r__ */ + +#if defined(__sh__) /* Renesas' SuperH */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + /* + * This asm is coded as if %0 could be any register, but actually SuperH + * restricts the target of xor-immediate to be R0. That's handled by + * the "z" constraint on _res. + */ + __asm__ __volatile__(" tas.b @%2 \n" + " movt %0 \n" + " xor #1,%0 \n" + : "=z"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "t"); + return _res; +} + +#endif /* __sh__ */ + +/* These live in s_lock.c, but only for gcc */ + +#if defined(__m68k__) && !defined(__linux__) /* non-Linux Motorola 68k */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +/* + * Note that this implementation is unsafe for any platform that can speculate + * a memory access (either load or store) after a following store. That + * happens not to be possible x86 and most legacy architectures (some are + * single-processor!), but many modern systems have weaker memory ordering. + * Those that do must define their own version S_UNLOCK() rather than relying + * on this one. + */ +#if !defined(S_UNLOCK) +#if defined(__INTEL_COMPILER) +#define S_UNLOCK(lock) \ + do { \ + __memory_barrier(); \ + *(lock) = 0; \ + } while (0) +#else +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("" : : : "memory"); \ + *(lock) = 0; \ + } while (0) +#endif +#endif + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +/* + * --------------------------------------------------------------------- + * Platforms that use non-gcc inline assembly: + * --------------------------------------------------------------------- + */ + +#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ + +#if defined(USE_UNIVEL_CC) /* Unixware compiler */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +asm int tas(volatile slock_t* s_lock) +{ + /* UNIVEL wants %mem in column 1, so we don't pg_indent this file */ + % mem s_lock pushl % ebx movl s_lock, % ebx movl $255, % eax lock xchgb % al, (% ebx) popl % ebx +} + +#endif /* defined(USE_UNIVEL_CC) */ + +#if defined(__alpha) || defined(__alpha__) /* Tru64 Unix Alpha compiler */ +/* + * The Tru64 compiler doesn't support gcc-style inline asm, but it does + * have some builtin functions that accomplish much the same results. + * For simplicity, slock_t is defined as long (ie, quadword) on Alpha + * regardless of the compiler in use. LOCK_LONG and UNLOCK_LONG only + * operate on an int (ie, longword), but that's OK as long as we define + * S_INIT_LOCK to zero out the whole quadword. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include +#define S_INIT_LOCK(lock) (*(lock) = 0) +#define TAS(lock) (__LOCK_LONG_RETRY((lock), 1) == 0) +#define S_UNLOCK(lock) __UNLOCK_LONG(lock) + +#endif /* __alpha || __alpha__ */ + +#if defined(__hppa) || defined(__hppa__) /* HP PA-RISC, GCC and HP compilers */ +/* + * HP's PA-RISC + * + * See src/backend/port/hpux/tas.c.template for details about LDCWX. Because + * LDCWX requires a 16-byte-aligned address, we declare slock_t as a 16-byte + * struct. The active word in the struct is whichever has the aligned address; + * the other three words just sit at -1. + * + * When using gcc, we can inline the required assembly code. + */ +#define HAS_TEST_AND_SET + +typedef struct { + int sema[4]; +} slock_t; + +#define TAS_ACTIVE_WORD(lock) ((volatile int*)(((uintptr_t)(lock) + 15) & ~15)) + +#if defined(__GNUC__) + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile int* lockword = TAS_ACTIVE_WORD(lock); + register int lockval; + + __asm__ __volatile__(" ldcwx 0(0,%2),%0 \n" : "=r"(lockval), "+m"(*lockword) : "r"(lockword) : "memory"); + return (lockval == 0); +} + +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("" : : : "memory"); \ + *TAS_ACTIVE_WORD(lock) = -1; \ + } while (0) + +#endif /* __GNUC__ */ + +#define S_INIT_LOCK(lock) \ + do { \ + volatile slock_t* lock_ = (lock); \ + lock_->sema[0] = -1; \ + lock_->sema[1] = -1; \ + lock_->sema[2] = -1; \ + lock_->sema[3] = -1; \ + } while (0) + +#define S_LOCK_FREE(lock) (*TAS_ACTIVE_WORD(lock) != 0) + +#endif /* __hppa || __hppa__ */ + +#if defined(__hpux) && defined(__ia64) && !defined(__GNUC__) +/* + * HP-UX on Itanium, non-gcc compiler + * + * We assume that the compiler enforces strict ordering of loads/stores on + * volatile data (see comments on the gcc-version earlier in this file). + * Note that this assumption does *not* hold if you use the + * +Ovolatile=__unordered option on the HP-UX compiler, so don't do that. + * + * See also Implementing Spinlocks on the Intel Itanium Architecture and + * PA-RISC, by Tor Ekqvist and David Graves, for more information. As of + * this writing, version 1.0 of the manual is available at: + * http://h21007.www2.hp.com/portal/download/files/unprot/itanium/spinlocks.pdf + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#include +#define TAS(lock) _Asm_xchg(_SZ_W, lock, 1, _LDHINT_NONE) +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) +#define S_UNLOCK(lock) \ + do { \ + _Asm_sched_fence(); (*(lock)) = 0); \ + } while (0) + +#endif /* HPUX on IA64, non gcc */ + +#if defined(__sgi) /* SGI compiler */ +/* + * SGI IRIX 5 + * slock_t is defined as a unsigned long. We use the standard SGI + * mutex API. + * + * The following comment is left for historical reasons, but is probably + * not a good idea since the mutex ABI is supported. + * + * This stuff may be supplemented in the future with Masato Kataoka's MIPS-II + * assembly from his NECEWS SVR4 port, but we probably ought to retain this + * for the R3000 chips out there. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include "mutex.h" +#define TAS(lock) (test_and_set(lock, 1)) +#define S_UNLOCK(lock) (test_then_and(lock, 0)) +#define S_INIT_LOCK(lock) (test_then_and(lock, 0)) +#define S_LOCK_FREE(lock) (test_then_add(lock, 0) == 0) +#endif /* __sgi */ + +#if defined(sinix) /* Sinix */ +/* + * SINIX / Reliant UNIX + * slock_t is defined as a struct abilock_t, which has a single unsigned long + * member. (Basically same as SGI) + */ +#define HAS_TEST_AND_SET + +#include "abi_mutex.h" +typedef abilock_t slock_t; + +#define TAS(lock) (!acquire_lock(lock)) +#define S_UNLOCK(lock) release_lock(lock) +#define S_INIT_LOCK(lock) init_lock(lock) +#define S_LOCK_FREE(lock) (stat_lock(lock) == UNLOCKED) +#endif /* sinix */ + +#if defined(_AIX) /* AIX */ +/* + * AIX (POWER) + */ +#define HAS_TEST_AND_SET + +#include + +typedef int slock_t; + +#define TAS(lock) _check_lock((slock_t*)(lock), 0, 1) +#define S_UNLOCK(lock) _clear_lock((slock_t*)(lock), 0) +#endif /* _AIX */ + +/* These are in s_lock.c */ + +#if defined(sun3) /* Sun3 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +#if defined(__SUNPRO_C) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) +#define HAS_TEST_AND_SET + +#if defined(__i386) || defined(__x86_64__) || defined(__sparcv9) || defined(__sparcv8plus) +typedef unsigned int slock_t; +#else +typedef unsigned char slock_t; +#endif + +extern slock_t pg_atomic_cas(volatile slock_t* lock, slock_t with, slock_t cmp); + +#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0) +#endif + +#ifdef WIN32_ONLY_COMPILER +typedef LONG slock_t; + +#define HAS_TEST_AND_SET +#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) + +#define SPIN_DELAY() spin_delay() + +/* If using Visual C++ on Win64, inline assembly is unavailable. + * Use a _mm_pause instrinsic instead of rep nop. + */ +#if defined(_WIN64) +static __forceinline void spin_delay(void) +{ + _mm_pause(); +} +#else +static __forceinline void spin_delay(void) +{ + /* See comment for gcc code. Same code, MASM syntax */ + __asm rep nop; +} +#endif + +#include +#pragma intrinsic(_ReadWriteBarrier) + +#define S_UNLOCK(lock) \ + do { \ + _ReadWriteBarrier(); \ + (*(lock)) = 0; \ + } while (0) + +#endif + +#endif /* !defined(HAS_TEST_AND_SET) */ + +/* Blow up if we didn't have any way to do spinlocks */ +#ifndef HAS_TEST_AND_SET +#error PostgreSQL does not have native spinlock support on this platform. To continue the compilation, rerun configure using --disable-spinlocks. However, performance will be poor. Please report this to pgsql-bugs@postgresql.org. +#endif + +#else /* !HAVE_SPINLOCKS */ + +/* + * Fake spinlock implementation using semaphores --- slow and prone + * to fall foul of kernel limits on number of semaphores, so don't use this + * unless you must! The subroutines appear in spin.c. + */ +typedef PGSemaphoreData slock_t; + +extern bool s_lock_free_sema(volatile slock_t* lock); +extern void s_unlock_sema(volatile slock_t* lock); +extern void s_init_lock_sema(volatile slock_t* lock); +extern int tas_sema(volatile slock_t* lock); + +#define S_LOCK_FREE(lock) s_lock_free_sema(lock) +#define S_UNLOCK(lock) s_unlock_sema(lock) +#define S_INIT_LOCK(lock) s_init_lock_sema(lock) +#define TAS(lock) tas_sema(lock) + +#endif /* HAVE_SPINLOCKS */ + +/* + * Default Definitions - override these above as needed. + */ + +#if !defined(S_LOCK) +#define S_LOCK(lock) \ + do { \ + if (TAS(lock)) \ + s_lock((lock), __FILE__, __LINE__); \ + } while (0) +#endif /* S_LOCK */ + +#if !defined(S_LOCK_FREE) +#define S_LOCK_FREE(lock) (*(lock) == 0) +#endif /* S_LOCK_FREE */ + +#if !defined(S_UNLOCK) +/* + * Our default implementation of S_UNLOCK is essentially *(lock) = 0. This + * is unsafe if the platform can speculate a memory access (either load or + * store) after a following store; platforms where this is possible must + * define their own S_UNLOCK. But CPU reordering is not the only concern: + * if we simply defined S_UNLOCK() as an inline macro, the compiler might + * reorder instructions from inside the critical section to occur after the + * lock release. Since the compiler probably can't know what the external + * function s_unlock is doing, putting the same logic there should be adequate. + * A sufficiently-smart globally optimizing compiler could break that + * assumption, though, and the cost of a function call for every spinlock + * release may hurt performance significantly, so we use this implementation + * only for platforms where we don't know of a suitable intrinsic. For the + * most part, those are relatively obscure platform/compiler combinations to + * which the PostgreSQL project does not have access. + */ +#define USE_DEFAULT_S_UNLOCK +extern void s_unlock(volatile slock_t* lock); +#define S_UNLOCK(lock) s_unlock(lock) +#endif /* S_UNLOCK */ + +#if !defined(S_INIT_LOCK) +#define S_INIT_LOCK(lock) S_UNLOCK(lock) +#endif /* S_INIT_LOCK */ + +#if !defined(SPIN_DELAY) +#define SPIN_DELAY() ((void)0) +#endif /* SPIN_DELAY */ + +#if !defined(TAS) +extern int tas(volatile slock_t* lock); /* in port/.../tas.s, or + * s_lock.c */ + +#define TAS(lock) tas(lock) +#endif /* TAS */ + +#if !defined(TAS_SPIN) +#define TAS_SPIN(lock) TAS(lock) +#endif /* TAS_SPIN */ + +#else /* ENABLE_THREAD_CHECK */ +#include +typedef pthread_mutex_t slock_t; + +#define S_INIT_LOCK(lock) pthread_mutex_init((pthread_mutex_t*)lock, NULL) +#define S_LOCK(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_UNLOCK(lock) pthread_mutex_unlock((pthread_mutex_t*)lock) +#define S_LOCK_FREE(lock) pthread_mutex_destroy((pthread_mutex_t*)lock) +#define TAS(lock) (!S_LOCK(lock)) +#endif +/* + * Platform-independent out-of-line support routines + */ +extern int s_lock(volatile slock_t* lock, const char* file, int line); + +/* Support for dynamic adjustment of spins_per_delay */ +#define DEFAULT_SPINS_PER_DELAY 100 + +extern void set_spins_per_delay(int shared_spins_per_delay); +extern int update_spins_per_delay(int shared_spins_per_delay); + +/* + * Support for spin delay which is useful in various places where + * spinlock-like procedures take place. + */ +typedef struct { + int spins; + int delays; + int cur_delay; + void* ptr; + const char* file; + int line; +} SpinDelayStatus; + +#define init_spin_delay(ptr) \ + { \ + 0, 0, 0, (ptr), __FILE__, __LINE__ \ + } +void perform_spin_delay(SpinDelayStatus* status); +void finish_spin_delay(SpinDelayStatus* status); + +#endif /* S_LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/smgr.h postgresql-hll-2.14/include/include/storage/smgr.h --- postgresql-hll-2.14_old/include/include/storage/smgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/smgr.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * smgr.h + * storage manager switch public interface declarations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/smgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SMGR_H +#define SMGR_H + +#include "fmgr.h" +#include "lib/ilist.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "vecexecutor/vectorbatch.h" +#include "nodes/bitmapset.h" + + +/* + * smgr.c maintains a table of SMgrRelation objects, which are essentially + * cached file handles. An SMgrRelation is created (if not already present) + * by smgropen(), and destroyed by smgrclose(). Note that neither of these + * operations imply I/O, they just create or destroy a hashtable entry. + * (But smgrclose() may release associated resources, such as OS-level file + * descriptors.) + * + * An SMgrRelation may have an "owner", which is just a pointer to it from + * somewhere else; smgr.c will clear this pointer if the SMgrRelation is + * closed. We use this to avoid dangling pointers from relcache to smgr + * without having to make the smgr explicitly aware of relcache. There + * can't be more than one "owner" pointer per SMgrRelation, but that's + * all we need. + * + * SMgrRelations that do not have an "owner" are considered to be transient, + * and are deleted at end of transaction. + */ +typedef struct SMgrRelationData { + /* rnode is the hashtable lookup key, so it must be first! */ + RelFileNodeBackend smgr_rnode; /* relation physical identifier */ + + /* pointer to owning pointer, or NULL if none */ + struct SMgrRelationData** smgr_owner; + + /* + * These next three fields are not actually used or manipulated by smgr, + * except that they are reset to InvalidBlockNumber upon a cache flush + * event (in particular, upon truncation of the relation). Higher levels + * store cached state here so that it will be reset when truncation + * happens. In all three cases, InvalidBlockNumber means "unknown". + */ + BlockNumber smgr_targblock; /* current insertion target block */ + BlockNumber smgr_fsm_nblocks; /* last known size of fsm fork */ + BlockNumber smgr_vm_nblocks; /* last known size of vm fork */ + + int smgr_bcmarry_size; + BlockNumber* smgr_bcm_nblocks; /* last known size of bcm fork */ + + /* additional public fields may someday exist here */ + + /* + * Fields below here are intended to be private to smgr.c and its + * submodules. Do not touch them from elsewhere. + */ + int smgr_which; /* storage manager selector */ + + + /* for md.c; NULL for forks that are not open */ + int md_fdarray_size; + struct _MdfdVec** md_fd; + + /* hash table storing specific bucket node's smgr pointer */ + HTAB* bucketnodes_smgrhash; + + /* if unowned, list link in list of all unowned SMgrRelations */ + dlist_node node; +} SMgrRelationData; + + +typedef SMgrRelationData* SMgrRelation; + +#define SmgrIsTemp(smgr) RelFileNodeBackendIsTemp((smgr)->smgr_rnode) + +extern void smgrinit(void); +extern SMgrRelation smgropen(const RelFileNode& rnode, BackendId backend, int col = 0, const oidvector* bucketlist = NULL); +extern bool smgrexists(SMgrRelation reln, ForkNumber forknum); +extern void smgrsetowner(SMgrRelation* owner, SMgrRelation reln); +extern void smgrclearowner(SMgrRelation* owner, SMgrRelation reln); +extern void smgrclose(SMgrRelation reln); +extern void smgrcloseall(void); +extern void smgrclosenode(const RelFileNodeBackend& rnode); +extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo ); +extern void smgrdounlink(SMgrRelation reln, bool isRedo); +extern void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo); +extern void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum); +extern bool smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char* buffer); +extern void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks); +extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum); +extern void smgrtruncatefunc(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum); +extern void smgrpreckpt(void); +extern void smgrsync(void); +extern void smgrpostckpt(void); + +extern void AtEOXact_SMgr(void); + +/* internals: move me elsewhere -- ay 7/94 */ + +/* in md.c */ +extern void mdinit(void); +extern void mdclose(SMgrRelation reln, ForkNumber forknum); +extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); +extern void smgrcreatebuckets(SMgrRelation reln, ForkNumber forknum, bool isRedo); + +extern bool mdexists(SMgrRelation reln, ForkNumber forknum); +extern void mdunlink(const RelFileNodeBackend& rnode, ForkNumber forknum, bool isRedo); +extern void mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum); +extern bool mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char* buffer); +extern void mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks); +extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum); +extern void mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum); +extern void mdpreckpt(void); +extern void mdsync(void); +extern void mdpostckpt(void); +extern char* mdsegpath(const RelFileNode& rnode, ForkNumber forknum, BlockNumber blkno); + +extern void SetForwardFsyncRequests(void); +extern void RememberFsyncRequest(const RelFileNode& rnode, ForkNumber forknum, BlockNumber segno); +extern void ForgetRelationFsyncRequests(const RelFileNode& rnode, ForkNumber forknum); +extern void ForgetDatabaseFsyncRequests(Oid dbid); +extern void smgrsync_for_dw(void); +extern void smgrsync_with_absorption(void); + +/* smgrtype.c */ +extern Datum smgrout(PG_FUNCTION_ARGS); +extern Datum smgrin(PG_FUNCTION_ARGS); +extern Datum smgreq(PG_FUNCTION_ARGS); +extern Datum smgrne(PG_FUNCTION_ARGS); + +extern void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend& filenode); +extern ScalarToDatum GetTransferFuncByTypeOid(Oid attTypeOid); +#endif /* SMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/spin.h postgresql-hll-2.14/include/include/storage/spin.h --- postgresql-hll-2.14_old/include/include/storage/spin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/spin.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * spin.h + * Hardware-independent implementation of spinlocks. + * + * + * The hardware-independent interface to spinlocks is defined by the + * typedef "slock_t" and these macros: + * + * void SpinLockInit(volatile slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void SpinLockAcquire(volatile slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void SpinLockRelease(volatile slock_t *lock) + * Unlock a previously acquired lock. + * + * bool SpinLockFree(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * Callers must beware that the macro argument may be evaluated multiple + * times! + * + * CAUTION: Care must be taken to ensure that loads and stores of + * shared memory values are not rearranged around spinlock acquire + * and release. This is done using the "volatile" qualifier: the C + * standard states that loads and stores of volatile objects cannot + * be rearranged *with respect to other volatile objects*. The + * spinlock is always written through a volatile pointer by the + * spinlock macros, but this is not sufficient by itself: code that + * protects shared data with a spinlock MUST reference that shared + * data through a volatile pointer. + * + * Keep in mind the coding rule that spinlocks must not be held for more + * than a few instructions. In particular, we assume it is not possible + * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so + * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros. + * + * These macros are implemented in terms of hardware-dependent macros + * supplied by s_lock.h. There is not currently any extra functionality + * added by this header, but there has been in the past and may someday + * be again. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/spin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPIN_H +#define SPIN_H + +#include "storage/s_lock.h" + +#define SpinLockInit(lock) S_INIT_LOCK(lock) + +#define SpinLockAcquire(lock) S_LOCK(lock) + +#define SpinLockRelease(lock) S_UNLOCK(lock) + +#define SpinLockFree(lock) S_LOCK_FREE(lock) + +extern int SpinlockSemas(void); + +#endif /* SPIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/standby.h postgresql-hll-2.14/include/include/storage/standby.h --- postgresql-hll-2.14_old/include/include/storage/standby.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/standby.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,133 @@ +/* ------------------------------------------------------------------------- + * + * standby.h + * Definitions for hot standby mode. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/standby.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STANDBY_H +#define STANDBY_H + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/lock.h" +#include "storage/procsignal.h" +#include "storage/relfilenode.h" + +extern void InitRecoveryTransactionEnvironment(void); +extern void ShutdownRecoveryTransactionEnvironment(void); + +extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, const RelFileNode& node); +extern void ResolveRecoveryConflictWithTablespace(Oid tsid); +extern void ResolveRecoveryConflictWithDatabase(Oid dbid); + +extern void ResolveRecoveryConflictWithBufferPin(void); +extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason); +extern void CheckRecoveryConflictDeadlock(void); + +/* + * Standby Rmgr (RM_STANDBY_ID) + * + * Standby recovery manager exists to perform actions that are required + * to make hot standby work. That includes logging AccessExclusiveLocks taken + * by transactions and running-xacts snapshots. + */ +extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid); +extern void StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId* subxids); +extern void StandbyReleaseAllLocks(void); +extern void StandbyReleaseOldLocks(TransactionId oldestRunningXid); +extern bool HasStandbyLocks(); + +extern bool standbyWillTouchStandbyLocks(XLogReaderState* record); + +/* + * XLOG message types + */ +#define XLOG_STANDBY_LOCK 0x00 +#define XLOG_RUNNING_XACTS 0x10 +#define XLOG_STANDBY_UNLOCK 0x20 +#define XLOG_STANDBY_CSN 0x30 +#ifndef ENABLE_MULTIPLE_NODES +#define XLOG_STANDBY_CSN_COMMITTING 0x40 +#define XLOG_STANDBY_CSN_ABORTED 0x50 +#endif + +typedef struct xl_standby_locks { + int nlocks; /* number of entries in locks array */ + xl_standby_lock locks[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_standby_locks; + +#define MinSizeOfXactStandbyLocks offsetof(xl_standby_locks, locks) + +/* + * When we write running xact data to WAL, we use this structure. + */ +typedef struct xl_running_xacts { + int xcnt; /* # of xact ids in xids[] */ + int subxcnt; /* # of subxact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + TransactionId oldestRunningXid; /* *not* oldestXmin */ + TransactionId latestCompletedXid; /* so we can set xmax */ + + TransactionId xids[FLEXIBLE_ARRAY_MEMBER]; +} xl_running_xacts; + + +#define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids) +/* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */ +extern void standby_redo(XLogReaderState* record); +extern void standby_desc(StringInfo buf, XLogReaderState* record); +#ifndef ENABLE_MULTIPLE_NODES +extern void StandbyXlogStartup(void); +extern void StandbyXlogCleanup(void); +extern bool StandbySafeRestartpoint(void); +extern bool RemoveCommittedCsnInfo(TransactionId xid); +#endif +typedef struct xl_running_xacts_old { + int xcnt; /* # of xact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + ShortTransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + ShortTransactionId oldestRunningXid; /* *not* oldestXmin */ + ShortTransactionId latestCompletedXid; /* so we can set xmax */ + ShortTransactionId xids[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_running_xacts_old; +/* + * Declarations for GetRunningTransactionData(). Similar to Snapshots, but + * not quite. This has nothing at all to do with visibility on this server, + * so this is completely separate from snapmgr.c and snapmgr.h. + * This data is important for creating the initial snapshot state on a + * standby server. We need lots more information than a normal snapshot, + * hence we use a specific data structure for our needs. This data + * is written to WAL as a separate record immediately after each + * checkpoint. That means that wherever we start a standby from we will + * almost immediately see the data we need to begin executing queries. + */ + +typedef struct RunningTransactionsData { + int xcnt; /* # of xact ids in xids[] */ + int subxcnt; /* # of subxact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + TransactionId oldestRunningXid; /* *not* oldestXmin */ + TransactionId globalXmin; /* running xacts's snapshot xmin */ + TransactionId latestCompletedXid; /* copy of ShmemVariableCache-> latestCompletedXid*/ + TransactionId* xids; /* array of (sub)xids still running */ + +} RunningTransactionsData; + +typedef RunningTransactionsData* RunningTransactions; + +extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid); +extern void LogAccessExclusiveLockPrepare(void); +extern void LogReleaseAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid); + +extern XLogRecPtr LogStandbySnapshot(void); +#endif /* STANDBY_H */ diff -uprN postgresql-hll-2.14_old/include/include/storage/time_series_compress.h postgresql-hll-2.14/include/include/storage/time_series_compress.h --- postgresql-hll-2.14_old/include/include/storage/time_series_compress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/time_series_compress.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,132 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * time_series_compress.h + * Data structure for delta-delta compression and XOR compression. + * + * + * IDENTIFICATION + * src/include/storage/time_series_compress.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SERIES_COMPRESS_H +#define SERIES_COMPRESS_H + +#include "c.h" +#include "storage/cstore_compress.h" + +const int DELTA2_RANGE = 8; +const int MAX_COMPRESSLEVEL = 3; + +const unsigned short DELTA2_KEY_MAX = 0x8; + +const int CU_COMPRESS_MASK1 = 0x000F; + +#define ATT_IS_DELTA2_SUPPORT(atttypid) \ + (atttypid == DATEOID || atttypid == TIMESTAMPOID || atttypid == INT4RANGEOID || atttypid == INT2OID || \ + atttypid == INT4OID || atttypid == INT8OID) + +#define ATT_IS_TIMESTAMP(atttypid) (atttypid == TIMESTAMPOID || atttypid == TIMESTAMPTZOID) + +#define ATT_IS_FLOAT(atttypid) (atttypid == FLOAT4OID || atttypid == FLOAT8OID) + +typedef struct Delta2KeyMap { + long unsigned int min; + long unsigned int max; + unsigned short key_suffix; + unsigned short byte_len; +} Delta2KeyMap; + +class Delta2Codec : public BaseObject { +public: + Delta2Codec(int64 extra, bool beCompress); + virtual ~Delta2Codec() + {} + + int64 compress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + + int64 decompress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size) const; + +private: + void write_value(int64 value, unsigned int buf_len, char* outbuf, unsigned int* pos); + int64 read_value(char* inbuf, unsigned int* pos, unsigned int buf_len) const; + short value_size; + short key_idx; + static const short DELTA2_KEY_MASK = 0xFF; + static const short DELTA2_KEY_SIGN_MASK = 0x7; + static const short DELTA2_BYTE_LEN_MASK = 0x8; + static const unsigned int DELTA2_KEY_LEN = 1; /* delta key len--1 byte */ +}; + +class SequenceCodec : public BaseObject { +public: + SequenceCodec(short valSize, uint32 dataType); + virtual ~SequenceCodec() + {} + + int lz4_compress( + int8 compression, int8 compress_level, Size bound_size, BufferHelper* tmpOutBuf, _out_ CompressionArg2& out); + int zlib_compress( + int8 compression, int8 compress_level, Size bound_size, BufferHelper* tmpOutBuf, _out_ CompressionArg2& out); + int compress(_in_ const CompressionArg1& in, _out_ CompressionArg2& out); + int decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + +private: + short value_size; + uint32 data_type; +}; + +class XORCodec : public BaseObject { +public: + XORCodec(); + virtual ~XORCodec() + {} + + int64 compress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + + int64 decompress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + +private: + // write compress value to write buffer + void appendValue(int64 value, char* outbuf, unsigned int& out_pos); + void addValueToBitString( + uint64_t value, uint64_t bitsInValue, uint32_t& numBits, char* outbuf, unsigned int& out_pos); + void flushBitString(const uint32_t& numBits, char* outbuf, unsigned int& out_pos); + void flushLastBitString(char* outbuf, unsigned int& out_pos); + + // read compress value to read buffer + int64 readNextValue(uint64_t& bitPos, uint64_t& previousValue, uint64_t& previousLeadingZeros, + uint64_t& previousTrailingZeros, char* inbuf, unsigned int& in_pos); + uint64_t readValueFromBitString(uint64_t& bitPos, uint32_t bitsToRead, char* inbuf, unsigned int& in_pos); + + static constexpr uint32_t kLeadingZerosLengthBits = 5; + static constexpr uint32_t kBlockSizeLengthBits = 6; + static constexpr uint32_t kMaxLeadingZerosLength = (1 << kLeadingZerosLengthBits) - 1; + static constexpr uint32_t kBlockSizeAdjustment = 1; + + uint64_t previousValue_; + uint32_t numBits_; + uint8_t previousValueLeadingZeros_; + uint8_t previousValueTrailingZeros_; + char bitsStore_; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/storage/vfd.h postgresql-hll-2.14/include/include/storage/vfd.h --- postgresql-hll-2.14_old/include/include/storage/vfd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/storage/vfd.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,39 @@ +/* --------------------------------------------------------------------------------------- + * + * vfd.h + * Virtual file descriptor definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/storage/vfd.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VFD_H +#define VFD_H + +#include +#include "utils/resowner.h" +#include "storage/relfilenode.h" + +typedef struct vfd { + int fd; /* current FD, or VFD_CLOSED if none */ + unsigned short fdstate; /* bitflags for VFD's state */ + ResourceOwner resowner; /* owner, for automatic cleanup */ + File nextFree; /* link to next free VFD, if in freelist */ + File lruMoreRecently; /* doubly linked recency-of-use list */ + File lruLessRecently; + off_t seekPos; /* current logical file position */ + off_t fileSize; /* current size of file (0 if not temporary) */ + char* fileName; /* name of file, or NULL for unused VFD */ + bool infdCache; /* true if in fd cache */ + /* NB: fileName is malloc'd, and must be free'd when closing the VFD */ + int fileFlags; /* open(2) flags for (re)opening the file */ + int fileMode; /* mode to pass to open(2) */ + RelFileNodeForkNum fileNode; /* current logical file node */ +} Vfd; + +#endif /* VFD_H */ diff -uprN postgresql-hll-2.14_old/include/include/streaming/dictcache.h postgresql-hll-2.14/include/include/streaming/dictcache.h --- postgresql-hll-2.14_old/include/include/streaming/dictcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/streaming/dictcache.h 2020-12-12 17:06:43.275348399 +0800 @@ -0,0 +1,80 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * connection.h + * Head file for streaming engine connection. + * + * + * IDENTIFICATION + * src/distribute/kernel/extension/streaming/include/connection.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ +#define CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ + +#include "streaming/init.h" +#include "knl/knl_thread.h" +#include "knl/knl_variable.h" + +#define OIDTYPE 0 +#define TEXTTYPE 1 + +#define Natts_dict 2 + +#define Anum_dict_id 1 +#define Anum_dict_value 2 + +#define DICT_SQL_MAX_LEN 1024 +#define DICT_HASH_NELEM 32 + +void init_dict(void); +HeapTuple dict_cache_lookup(int id, Datum key, int type); +#define AEXPR_TO_SUBLINK_SQL "select distinct id from %s where value='%s'" +#define RESTARGET_TO_SUBLINK_SQL "select distinct value from %s where %s=id" + +/* + * Definition of dictionary mapping hash entry + */ +typedef struct DictEntry +{ + uint32 id; /* hash key of DictEntry */ + HeapTuple tuple; /* dict mapping tuple */ + bool valid; /* valid flag*/ +} DictEntry; + +typedef struct DictAnalyzeContext +{ + List *a_exprs; + List *rels; + List *cqtabs; + List *cols; +} DictAnalyzeContext; + +DictAnalyzeContext *make_dict_analyze_context(); + +bool collect_aexprs(Node *node, DictAnalyzeContext *context); +void init_dict(void); +//Oid dict_table_insert(Relation rel, HeapTuple tup); +Oid dict_table_insert(int id, HeapTuple tup, Datum key); +HeapTuple dict_cache_lookup(int id, Datum key, int type); +Datum dict_get_attr(int id, HeapTuple tup, AttrNumber attr, bool *isnull); +int get_id_by_dictrelid(Oid dictrelid); +bool is_contquery_with_dict(Node* node); +bool collect_rels(Node *node, DictAnalyzeContext *context); +bool collect_cols(Node *node, DictAnalyzeContext *context); +void transform_contquery_selectstmt_with_dict(SelectStmt * selectstmt); +#endif /* CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/streaming/init.h postgresql-hll-2.14/include/include/streaming/init.h --- postgresql-hll-2.14_old/include/include/streaming/init.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/streaming/init.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,140 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * init.h + * Head file for streaming engine init. + * + * + * IDENTIFICATION + * src/include/streaming/init.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_STREAMING_INIT_H_ +#define SRC_INCLUDE_STREAMING_INIT_H_ + +#include "gs_thread.h" +#include "streaming/launcher.h" +#include "access/tupdesc.h" + +typedef int StreamingThreadSeqNum; + +typedef struct StreamingBatchStats { + union { + struct { // coordinator stats + volatile uint64 worker_in_rows; /* worker input rows */ + volatile uint64 worker_in_bytes; /* worker input bytes */ + volatile uint64 worker_out_rows; /* worker output rows */ + volatile uint64 worker_out_bytes; /* worker output bytes */ + volatile uint64 worker_pending_times; /* worker pending times */ + volatile uint64 worker_error_times; /* worker error times */ + }; + struct { // datanode stats + volatile uint64 router_in_rows; /* router input rows */ + volatile uint64 router_in_bytes; /* router input bytes */ + volatile uint64 router_out_rows; /* router output rows */ + volatile uint64 router_out_bytes; /* router output bytes */ + volatile uint64 router_error_times; /* router error times */ + volatile uint64 collector_in_rows; /* collector input rows */ + volatile uint64 collector_in_bytes; /* collector input bytes */ + volatile uint64 collector_out_rows; /* collector output rows */ + volatile uint64 collector_out_bytes; /* collector output bytes */ + volatile uint64 collector_pending_times; /* collector pending times */ + volatile uint64 collector_error_times; /* collector error times */ + }; + }; +} StreamingBatchStats; + +typedef struct StreamingSharedMetaData { + volatile uint32 client_push_conn_atomic; /* round robin client push connection atomic */ + void *conn_hash_tbl; /* connection hash table for streaming threads */ + StreamingBatchStats *batch_stats; /* streaming engine microbatch statistics */ +}StreamingSharedMetaData; + +typedef struct StreamingThreadMetaData { + ThreadId tid; + knl_thread_role subrole; + StreamingThreadSeqNum tseq; +}StreamingThreadMetaData; + +typedef struct DictDesc +{ + char *nspname; + char *relname; + char *indname; + Oid relid; + Oid indrelid; + TupleDesc desc; + int nkeys; + int key; +} DictDesc; + +#define DICT_CACHE_SIZE 1024 + +typedef struct knl_t_streaming_context { + volatile bool is_streaming_engine; + volatile bool loaded; /* streaming engine loaded flag */ + void *save_utility_hook; + void *save_post_parse_analyze_hook; + StreamingBackendServerLoopFunc streaming_backend_serverloop_hook; + StreamingBackendShutdownFunc streaming_backend_shutdown_hook; + void *streaming_planner_hook; + volatile bool got_SIGHUP; + volatile bool got_SIGTERM; + int client_push_conn_id; + StreamingThreadMetaData *thread_meta; /* streaming current thread meta */ + unsigned int streaming_context_flags; + TransactionId cont_query_cache_xid; + MemoryContext cont_query_cache_cxt; + void *cont_query_cache; + int current_cont_query_id; + Oid streaming_exec_lock_oid; + MemoryContext ContQueryTransactionContext; + MemoryContext ContQueryBatchContext; + + HTAB *dict_htable[DICT_CACHE_SIZE]; + MemoryContext dict_context; + bool dict_inited; + DictDesc dictdesc[DICT_CACHE_SIZE]; +} knl_t_streaming_context; + +typedef struct knl_g_streaming_context { + MemoryContext meta_cxt; /* streaming engine meta context */ + MemoryContext conn_cxt; /* streaming engine conn context */ + StreamingSharedMetaData *shared_meta; /* streaming shared meta */ + StreamingThreadMetaData *thread_metas; /* streaming thread metas */ + char *krb_server_keyfile; /* kerberos server keyfile */ + volatile bool got_SIGHUP; /* SIGHUP comm with nanomsg auth */ + bool enable; /* streaming engine enable flag */ + int router_port; /* the port router thread listens on */ + int routers; /* number of router threads */ + int workers; /* number of worker threads */ + int combiners; /* number of combiner threads */ + int queues; /* number of queue threads */ + int reapers; /* number of reaper threads */ + int batch_size; /* max number of tuples for streaming microbatch */ + int batch_mem; /* max size (KB) for streaming microbatch */ + int batch_wait; /* receive timeout (ms) for streaming microbatch */ + int flush_mem; /* max size (KB) for streaming disk flush */ + int flush_wait; /* receive timeout (ms) for streaming disk flush */ + volatile bool exec_lock_flag; /* get exec lock flag */ + int gather_window_interval; /* interval (min) of gather window */ +}knl_g_streaming_context; + +bool is_streaming_engine_available(); +void validate_streaming_engine_status(Node *stmt); + +#endif /* SRC_INCLUDE_STREAMING_INIT_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/streaming/launcher.h postgresql-hll-2.14/include/include/streaming/launcher.h --- postgresql-hll-2.14_old/include/include/streaming/launcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/streaming/launcher.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hashfuncs.h + * Head file for streaming engine launcher. + * + * + * IDENTIFICATION + * src/include/streaming/launcher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_STREAMING_LAUNCHER_H_ +#define SRC_INCLUDE_STREAMING_LAUNCHER_H_ + +#include "gs_thread.h" + +typedef enum { + STREAMING_BACKEND_INIT = 1, + STREAMING_BACKEND_REAP, + STREAMING_BACKEND_SIGTERM, + STREAMING_BACKEND_SIGHUP, + STREAMING_BACKEND_SHUTDOWN +} StreamingBackendManagerType; + +typedef void (*StreamingBackendServerLoopFunc)(); +typedef void (*StreamingBackendShutdownFunc)(); + +bool is_streaming_engine(); +int streaming_get_thread_count(); +void streaming_backend_main(knl_thread_arg* arg); +extern bool streaming_backend_manager(StreamingBackendManagerType mtype, const void *info = NULL); +bool is_streaming_backend_terminating(); + +#endif /* SRC_INCLUDE_STREAMING_LAUNCHER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/streaming/planner.h postgresql-hll-2.14/include/include/streaming/planner.h --- postgresql-hll-2.14_old/include/include/streaming/planner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/streaming/planner.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * planner.h + * Head file for the entance of stream to modify the plan tree. + * + * + * IDENTIFICATION + * src/include/streaming/planner.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMING_PLANNER_H +#define STREAMING_PLANNER_H + +#include + +bool is_insert_stream_query(Query *query); +bool is_streaming_hash_group_func(const char* funcname, Oid funcnamespace); +bool is_streaming_invisible_obj(Oid oid); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/streaming/streaming_catalog.h postgresql-hll-2.14/include/include/streaming/streaming_catalog.h --- postgresql-hll-2.14_old/include/include/streaming/streaming_catalog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/streaming/streaming_catalog.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,119 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cont_query.h + * Head file for streaming engine cont_query. + * + * + * IDENTIFICATION + * src/distribute/kernel/extension/streaming/include/cont_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMING_INCLUDE_STREAMING_CATALOG_H_ +#define STREAMING_INCLUDE_STREAMING_CATALOG_H_ + +#include "postgres.h" +#include "nodes/primnodes.h" +#include "nodes/parsenodes.h" + +#define CVNAMELEN 80 +const char TTL_OPTION[] = "ttl_interval"; +const char WINDOW_OPTION[] = "sw_interval"; +const char COLUMN_OPTION[] = "time_column"; +const char ORIENT_OPTION[] = "orientation"; +const char COMPRESS_OPTION[] = "compression"; +const char GATHER_OPTION[] = "gather_interval"; +const char PERIOD_OPTION[] = "partition_interval"; +const char DEACTIVE_TIME_OPTION[] = "deactive_time"; +const char STRING_OPTIMIZE_OPTION[] = "string_optimize"; + +const char ORIENT_COLUMN = 'c'; /* streaming_cont_query: type = 'c' */ +const char ORIENT_ROW = 'r'; /* streaming_cont_query: type = 'r' */ +const char ORIENT_COLUMN_PARTITION = 'p'; /* streaming_cont_query: type = 'p' */ +const int16 TUMBLING_WINDOW = 0; /* streaming_cont_query: step_factor = 0 */ +const int16 SLIDING_WINDOW = 1; /* streaming_cont_query: step_factor = 1 */ +const char STRING_OPTIMIZE_ON[] = "on"; +const char STRING_OPTIMIZE_OFF[] = "off"; + +const int MAX_VERSIONS = 10; +const char INIT_VERSION = '0'; +const int MIN_TTL = 5; +const int MAX_CQS = 1024; +const int STREAMING_EXEC_CONTINUOUS = 0x100000; +const int DEFAULT_PARTITION_NUM = 10; /* default partition numbers when partition table is created */ +const int DEFAULT_NAME_LEN = 64; /* default and auto partition name length */ +const int PERIOD_OFF = -1; /* represention for no partition_interval parameter */ +const int PERIOD_MULT = 5; /* detection interval for auto-partition */ +const int GATHER_OFF = -1; /* represention for no gather_interval parameter */ +const int PARTITION_INTERVAL_MAX = 1; /* partition_interval max value (day) */ +const int PARTITION_INTERVAL_MIN = 30; /* partition_interval min value (minute) */ +const int MSECS_PER_SECS = 1000; /* Milliseconds per second */ + +typedef struct ContQuery { + Oid id; /*CV ID*/ + RangeVar *name; /*CV name*/ + Oid oid; /*tuple oid*/ + bool active; /*is this CV active*/ + + Oid relid; /*overlay view oid*/ + Oid defrelid; /*definiton view oid*/ + char *sql; /*cont query's plain sql*/ + Query *cvdef; /*def view's query tree*/ + Oid matrelid; /*matrel oid*/ + Oid streamrelid; /*stream oid*/ + Oid dictrelid; /*stream oid*/ + + RangeVar *matrel; /*matrel name*/ + Oid lookupidxid; /*group lookupidx oid*/ + AttrNumber ttl_attno; /*ttl attrNumber*/ + int ttl; /*ttl*/ + int period; /*period*/ + int gather; /* gather (second) */ + int gather_window_interval; /* gather_window_interval (min) */ + + FuncExpr *hash; /*func expr*/ + char type; /*CV type*/ +} ContQuery; + +Query *get_cont_query_def(Oid def_relid); +ContQuery *get_cont_query_for_id(Oid id); +Oid get_defrelid_by_tab_relid(Oid tab_relid); +Oid get_dictrelid_by_tab_relid(Oid tab_relid); +bool rangevar_is_cq_with_dict(RangeVar *rv); +bool is_streaming_thread(); +Oid get_cqid_by_dict_relid(Oid relid); +Oid get_dictrelid_by_cqid(Oid cqid); + +void streaming_context_set_is_ddl(void); +bool streaming_context_is_ddl(void); +void streaming_context_set_is_def_rel(bool); +void streaming_context_set_group_search(void); +bool streaming_context_is_group_search(void); +bool is_def_rel(void); + +bool is_group_column_by_colname(char *colname, Oid relid); +bool is_group_column_by_attrnum(int attrnum, Oid relid); +bool is_rte_cq(List *rtable); +bool is_streaming_string_optimze_on(Oid relid); + +bool relid_is_stream(Oid relid); +bool range_var_is_stream(const RangeVar *rv, bool missing_ok); +bool range_var_is_cont_view(RangeVar *name); +bool relid_is_cv_tab(Oid relid); + +char *cv_name_to_mrel_name(char *cvname); +#endif diff -uprN postgresql-hll-2.14_old/include/include/tcop/dest.h postgresql-hll-2.14/include/include/tcop/dest.h --- postgresql-hll-2.14_old/include/include/tcop/dest.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/dest.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,169 @@ +/* ------------------------------------------------------------------------- + * + * dest.h + * support for communication destinations + * + * Whenever the backend executes a query that returns tuples, the results + * have to go someplace. For example: + * + * - stdout is the destination only when we are running a + * standalone backend (no postmaster) and are returning results + * back to an interactive user. + * + * - a remote process is the destination when we are + * running a backend with a frontend and the frontend executes + * PQexec() or PQfn(). In this case, the results are sent + * to the frontend via the functions in backend/libpq. + * + * - DestNone is the destination when the system executes + * a query internally. The results are discarded. + * + * dest.c defines three functions that implement destination management: + * + * BeginCommand: initialize the destination at start of command. + * CreateDestReceiver: return a pointer to a struct of destination-specific + * receiver functions. + * EndCommand: clean up the destination at end of command. + * + * BeginCommand/EndCommand are executed once per received SQL query. + * + * CreateDestReceiver returns a receiver object appropriate to the specified + * destination. The executor, as well as utility statements that can return + * tuples, are passed the resulting DestReceiver* pointer. Each executor run + * or utility execution calls the receiver's rStartup method, then the + * receiveSlot method (zero or more times), then the rShutdown method. + * The same receiver object may be re-used multiple times; eventually it is + * destroyed by calling its rDestroy method. + * + * In some cases, receiver objects require additional parameters that must + * be passed to them after calling CreateDestReceiver. Since the set of + * parameters varies for different receiver types, this is not handled by + * this module, but by direct calls from the calling code to receiver type + * specific functions. + * + * The DestReceiver object returned by CreateDestReceiver may be a statically + * allocated object (for destination types that require no local state), + * in which case rDestroy is a no-op. Alternatively it can be a palloc'd + * object that has DestReceiver as its first field and contains additional + * fields (see printtup.c for an example). These additional fields are then + * accessible to the DestReceiver functions by casting the DestReceiver* + * pointer passed to them. The palloc'd object is pfree'd by the rDestroy + * method. Note that the caller of CreateDestReceiver should take care to + * do so in a memory context that is long-lived enough for the receiver + * object not to disappear while still needed. + * + * Special provision: None_Receiver is a permanently available receiver + * object for the DestNone destination. This avoids useless creation/destroy + * calls in portal and cursor manipulations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/dest.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEST_H +#define DEST_H + +#ifndef FRONTEND_PARSER +#include "executor/tuptable.h" + +/* buffer size to use for command completion tags */ +#define COMPLETION_TAG_BUFSIZE 64 + +/* ---------------- + * CommandDest is a simplistic means of identifying the desired + * destination. Someday this will probably need to be improved. + * + * Note: only the values DestNone, DestDebug, DestRemote are legal for the + * global variable whereToSendOutput. The other values may be used + * as the destination for individual commands. + * ---------------- + */ +typedef enum { + DestNone, /* results are discarded */ + DestDebug, /* results go to debugging output */ + DestRemote, /* results sent to frontend process */ + DestRemoteExecute, /* sent to frontend, in Execute command */ + DestSPI, /* results sent to SPI manager */ + DestTuplestore, /* results sent to Tuplestore */ + DestIntoRel, /* results sent to relation (SELECT INTO) */ + DestCopyOut, /* results sent to COPY TO code */ + DestSQLFunction, /* results sent to SQL-language func mgr */ + DestSPITupleAnalyze, /* results sent to SPI manager when analyze for table sample */ + + DestTupleBroadCast, /* results send to consumer thread in a broadcast way */ + DestTupleLocalBroadCast, /* results send to consumer thread in a local broadcast way */ + DestTupleRedistribute, /* results send to consumer thread in a redistribute way */ + DestTupleLocalRedistribute, /* results send to consumer thread in a local redistribute way */ + DestTupleLocalRoundRobin, /* results send to consumer thread in a local roundrobin way */ + + DestTupleHybrid, + + DestBatchBroadCast, /* results send to consumer thread in a broadcast way */ + DestBatchLocalBroadCast, /* results send to consumer thread in a local broadcast way */ + DestBatchRedistribute, /* results send to consumer thread in a redistribute way */ + DestBatchLocalRedistribute, /* results send to consumer thread in a local redistribute way */ + DestBatchLocalRoundRobin, /* results send to consumer thread in a local roundrobin way */ + + DestBatchHybrid, + DestTransientRel /* results sent to transient relation */ + +} CommandDest; + +class VectorBatch; + +/* ---------------- + * DestReceiver is a base type for destination-specific local state. + * In the simplest cases, there is no state info, just the function + * pointers that the executor must call. + * + * Note: the receiveSlot routine must be passed a slot containing a TupleDesc + * identical to the one given to the rStartup routine. + * ---------------- + */ +typedef struct _DestReceiver DestReceiver; + +struct _DestReceiver { + /* Called for each tuple to be output: */ + void (*receiveSlot)(TupleTableSlot* slot, DestReceiver* self); + /* Per-executor-run initialization and shutdown: */ + void (*rStartup)(DestReceiver* self, int operation, TupleDesc typeinfo); + void (*rShutdown)(DestReceiver* self); + /* Destroy the receiver object itself (if dynamically allocated) */ + void (*rDestroy)(DestReceiver* self); + /* CommandDest code for this receiver */ + CommandDest mydest; + /* Private fields might appear beyond this point... */ + + /* Send batch*/ + void (*sendBatch)(VectorBatch* batch, DestReceiver* self); + + void (*finalizeLocalStream)(DestReceiver* self); + + /* send sample tuple to coordinator for analyze */ + bool forAnalyzeSampleTuple; + + MemoryContext tmpContext; +}; + +extern DestReceiver* None_Receiver; /* permanent receiver for DestNone */ + +/* The primary destination management functions */ + +extern void BeginCommand(const char* commandTag, CommandDest dest); +extern DestReceiver* CreateDestReceiver(CommandDest dest); +extern DestReceiver* CreateReceiverForMerge(CommandDest dest); +extern void EndCommand(const char* commandTag, CommandDest dest); +extern void EndCommand_noblock(const char* commandTag, CommandDest dest); + +/* Additional functions that go with destination management, more or less. */ + +extern void NullCommand(CommandDest dest); +extern void ReadyForQuery(CommandDest dest); +extern void ReadyForQuery_noblock(CommandDest dest, int timeout); + +#endif /* !FRONTEND_PARSER */ +#endif /* DEST_H */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/fastpath.h postgresql-hll-2.14/include/include/tcop/fastpath.h --- postgresql-hll-2.14_old/include/include/tcop/fastpath.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/fastpath.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * fastpath.h + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/fastpath.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FASTPATH_H +#define FASTPATH_H + +#include "lib/stringinfo.h" + +#define MAX_ARG_SIZE 107374182 + +extern int HandleFunctionRequest(StringInfo msgBuf); + +#endif /* FASTPATH_H */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/pquery.h postgresql-hll-2.14/include/include/tcop/pquery.h --- postgresql-hll-2.14_old/include/include/tcop/pquery.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/pquery.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * pquery.h + * prototypes for pquery.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/pquery.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQUERY_H +#define PQUERY_H + +#include "nodes/parsenodes.h" +#include "utils/portal.h" + +extern THR_LOCAL PGDLLIMPORT Portal ActivePortal; + +extern PortalStrategy ChoosePortalStrategy(List* stmts); + +extern List* FetchPortalTargetList(Portal portal); + +extern List* FetchStatementTargetList(Node* stmt); + +extern void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot); + +extern void PortalSetResultFormat(Portal portal, int nFormats, int16* formats); + +extern bool PortalRun( + Portal portal, long count, bool isTopLevel, DestReceiver* dest, DestReceiver* altdest, char* completionTag); + +extern long PortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver* dest); + +#endif /* PQUERY_H */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/stmt_retry.h postgresql-hll-2.14/include/include/tcop/stmt_retry.h --- postgresql-hll-2.14_old/include/include/tcop/stmt_retry.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/stmt_retry.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,417 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * stmt_retry.h + * support for statement retry + * + * + * IDENTIFICATION + * src/include/tcop/stmt_retry.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STMT_RETRY_H +#define STMT_RETRY_H + +#include "c.h" + +#include "lib/stringinfo.h" +#include "utils/palloc.h" +#include "utils/elog.h" +#include "utils/hsearch.h" + +/* + * test stub usage + */ +const uint16 RETRY_STUB_CASE_SIZE = 256; +const uint16 RETRY_STUB_CASE_ECODE_SIZE = 21; + +typedef enum { STUB_DO_RETRY, STUB_PASS } RETRY_STUB_MARKER; + +/* + * log usage + */ +const char* const STUB_PRINT_PREFIX = " [retry stub] "; +const char* const STUB_PRINT_PREFIX_ALERT = " [retry stub alert] "; +const char* const STUB_PRINT_PREFIX_TYPE_S = " ~special path~ "; +const char* const STUB_PRINT_PREFIX_TYPE_R = " ~retry path~ "; +const char* const PRINT_PREFIX_TYPE_ALERT = " alert : "; +const char* const PRINT_PREFIX_TYPE_PATH = " retry path : "; + +/* + * marco for statement retry + */ +#define STMT_RETRY_ENABLED \ + (u_sess->attr.attr_common.max_query_retry_times > 0 && !u_sess->attr.attr_sql.enable_hadoop_env) + +/*message types which retry is supported*/ +const char Q_MESSAGE = 'Q'; +const char P_MESSAGE = 'P'; +const char B_MESSAGE = 'B'; +const char E_MESSAGE = 'E'; +const char D_MESSAGE = 'D'; +const char C_MESSAGE = 'C'; +const char S_MESSAGE = 'S'; +const char U_MESSAGE = 'U'; +const char F_MESSAGE = 'F'; +const char INVALID_MESSAGE = '0'; + +const char* const STMT_TOKEN = ";"; + +inline bool IsExtendQueryMessage(char msg_type) +{ + return ((msg_type == P_MESSAGE) || (msg_type == B_MESSAGE) || (msg_type == E_MESSAGE) || (msg_type == D_MESSAGE) || + (msg_type == C_MESSAGE) || (msg_type == S_MESSAGE) || (msg_type == U_MESSAGE) || (msg_type == F_MESSAGE)) + ? true + : false; +} + +inline bool IsSimpleQueryMessage(char msg_type) +{ + return (msg_type == Q_MESSAGE); +} + +inline bool IsQueryMessage(char msg_type) +{ + return (IsSimpleQueryMessage(msg_type) || IsExtendQueryMessage(msg_type)); +} + +inline bool IsMessageTypeMatchWithProtocol(bool is_extend_query, char msg_type) +{ + return is_extend_query ? IsExtendQueryMessage(msg_type) : IsSimpleQueryMessage(msg_type); +} + +/* + * QueryMessageContext is used to cache retry message context info for now + * in the future. + */ +class QueryMessageContext : public BaseObject { +public: + QueryMessageContext(MemoryContext mem_context) : context_(mem_context) + { + + MemoryContext old_context = MemoryContextSwitchTo(context_); + initStringInfo(&cached_msg_); + (void)MemoryContextSwitchTo(old_context); + } + + ~QueryMessageContext(void) + {} + +public: + void CacheMessage(char msg_type, StringInfo msg_data); + + int MessageSize(void) const + { + return cached_msg_.len; + } + + void DumpHistoryCommandsToPqBuffer(void); + + void Reset(void); + char PeekFirstChar(void) const + { + return cached_msg_.data[0]; + }; + +private: + /* disallow copy*/ + QueryMessageContext(const QueryMessageContext&); + QueryMessageContext& operator=(const QueryMessageContext&); + +private: + StringInfoData cached_msg_; /* If 'P' 'B' 'E''D', msg cached from input_message, If 'Q' cached from + * debug_query string */ + MemoryContext context_; +}; + +typedef enum { + STMT_RETRY_DEFAULT, /*default status of retry, meaning retry is not triggered*/ + STMT_RETRY_SIMPLE_QUREY_RETRYING, /*indicate we are in simple query retry flow*/ + STMT_RETRY_EXTEND_QUREY_RETRYING, /*indicate we are in pbe retry flow*/ +} StatementRetryPhase; + +typedef StatementRetryPhase CombinedStatementRetryPhase; + +typedef struct MessageInfo { + char type; + int len; + + MessageInfo(char _type, int _len) : type(_type), len(_len) + {} +} MessageInfo; + +/* + * since pbe messages in extend query executed in a continues way, for example messages flow can be + * combination of "p-b-d-e-b-e-s", in extend query retry, we treat pbe message flow as a whole, + * PBEFlowTracker track pbe flow and using tracked pbe flow info to check retrying pbe execution if + * retry happens. + */ +class PBEFlowTracker : public BaseObject { +public: + PBEFlowTracker(MemoryContext mem_context) + { + MemoryContext old_context = MemoryContextSwitchTo(mem_context); + + initStringInfo(&pbe_flow_); + initStringInfo(&history_pbe_flow_); + + (void)MemoryContextSwitchTo(old_context); + } + ~PBEFlowTracker(void) + {} + + void Reset(void) + { + resetStringInfo(&pbe_flow_); + resetStringInfo(&history_pbe_flow_); + } + +public: + void TrackPBE(char type) + { + appendStringInfoChar(&pbe_flow_, type); + } + + void InitValidating(void) + { + if (pbe_flow_.len > 0) { + copyStringInfo(&history_pbe_flow_, &pbe_flow_); + resetStringInfo(&pbe_flow_); + } + } + void Validate(char type); + + const char* PBEFlowStr(void) + { + return pbe_flow_.data; + } + +private: + StringInfoData pbe_flow_; /* recording executed pbe message flow */ + StringInfoData history_pbe_flow_; /* recording executed pbe message flow before retrying */ +}; + +/* + * stub for statement retry, use it to Manually construct sql retry both in extended query and simple query + */ +class StatementRetryStub { +public: + StatementRetryStub(void) + { + InitECodeMarker(); + Reset(); + } + ~StatementRetryStub(void) + {} + + void Reset(void); + +public: + void StartOneStubTest(char msg_type); + bool OnStubTest(void) const + { + return on_stub_test; + } + void CloseOneStub(void); + void FinishStubTest(const char* info); + + void InitECodeMarker(void); + void ECodeStubTest(void); + void ECodeValidate(void); + +private: + /* disallow copy*/ + StatementRetryStub(const StatementRetryStub&); + StatementRetryStub& operator=(const StatementRetryStub&); + +private: + uint8 stub_marker[RETRY_STUB_CASE_SIZE]; + int ecode_marker[RETRY_STUB_CASE_ECODE_SIZE]; + uint16 stub_pos; + uint16 ecode_pos; + bool on_stub_test; +}; + +/* + * this is the main class of statement retry control + * 1.A StatementRetryController will track a simple query or a extend query(PBE flow) + * during query execution, tracking behave like cache query string in simple query, + * record p message pointer in extend query. + * 2.once query retry is triggerd, StatementRetryController will control the retry routine, + * such as how to settle the read/send buffer between cn and client, how to ReadCommand and so on + */ +class StatementRetryController : public BaseObject { +public: + StatementRetryController(MemoryContext mem_context) + : retry_id(0), is_retry_enabled(false), cached_msg_context(mem_context), pbe_tracker(mem_context) + { + + MemoryContext old_context = MemoryContextSwitchTo(mem_context); + initStringInfo(&prepared_stmt_name); + (void)MemoryContextSwitchTo(old_context); + + Reset(); + } + ~StatementRetryController(void) + {} + + void Reset(void); + +public: + /* common usage */ + void EnableRetry(void); + void DisableRetry(void); + bool IsRetryEnabled(void) + { + return is_retry_enabled; + } + bool IsExtendQueryRetrying(void) const + { + return STMT_RETRY_EXTEND_QUREY_RETRYING == retry_phase; + } + bool IsSimpleQueryRetrying(void) const + { + return STMT_RETRY_SIMPLE_QUREY_RETRYING == retry_phase; + } + bool IsQueryRetrying(void) const + { + return (IsExtendQueryRetrying() || IsSimpleQueryRetrying()); + } + bool IsTrackedQueryMessageInfoValid(bool is_extend_query); + void TriggerRetry(bool is_extend_query); + void FinishRetry(void); + void CleanPreparedStmt(void); + + void LogTraceInfo(MessageInfo info) + { + if (retry_phase > STMT_RETRY_DEFAULT) { + ereport(DEBUG3, + (errmodule(MOD_CN_RETRY), errmsg("retrying \"%c\" message, length \"%d\"", info.type, info.len))); + } else { + ereport(DEBUG3, + (errmodule(MOD_CN_RETRY), errmsg("executing \"%c\" message, length \"%d\"", info.type, info.len))); + } + } + + /* message caching */ + void CacheCommand(char type, StringInfo data) + { + cached_msg_context.CacheMessage(type, data); + } + void TrackMessageOnExecuting(char type) + { +#if USE_ASSERT_CHECKING + if (IsExtendQueryMessage(type)) + pbe_tracker.TrackPBE(type); +#endif + executing_msg_type = type; + } + void CacheStmtName(const char* stmt_name) + { + appendStringInfoString(&prepared_stmt_name, stmt_name); + appendStringInfoString(&prepared_stmt_name, STMT_TOKEN); + } + char MessageOnExecuting(void) const + { + return executing_msg_type; + } + + /* pbe flow tracking */ + void ValidateExecuting(char type) + { + pbe_tracker.Validate(type); + } + const char* PBEFlowStr(void) + { + return pbe_tracker.PBEFlowStr(); + } + +public: /*in order to compatible with legacy code, declaring all data member as public here */ + uint64 retry_id; /* id for retrying query */ + int retry_times; /* mark current retry times */ + int error_code; /* recording error code that trigger long jump */ + bool is_trans; /* if the query within either a transaction or a transaction block, + * it is not allowed to retry */ + bool is_tempfile_size_exceeded; /* if true, meaning tempfile for caching query result is exceeded, + * so there is no way to make sure the query result can be exact, + * in this situation retry can not be allowed */ + bool is_unsupported_query_type; /* if true, meaning query type can't retry for now */ + bool is_retry_enabled; /* if true, meaning retry feature is enabled, + * now StatementRetryController will track query and trigger retry at long jump point */ + bool is_transaction_committed; /* if true, meaning current transaction is committed, if error happens between + transaction committed and finish, we disallow retry during this period */ + CombinedStatementRetryPhase retry_phase; /* recording current retry phase */ + QueryMessageContext cached_msg_context; /* cached statement context store statement info of a statement to + * be retry subsequently */ + +#ifdef USE_RETRY_STUB + StatementRetryStub stub_; /* test stub for auto trigger sql retry */ +#endif + +private: + char executing_msg_type; /* tracking msg on executing */ + PBEFlowTracker pbe_tracker; /* tracking pbe flow execution */ + StringInfoData prepared_stmt_name; /* caching prepared statement name */ +}; + +/* + *statement retry common usage + */ +extern StatementRetryController* StmtRetryInitController(void); +extern void StmtRetryResetController(void); +extern void StmtRetrySetFileExceededFlag(void); +extern void StmtRetrySetQuerytUnsupportedFlag(void); +extern void StmtRetrySetTransactionCommitFlag(bool flag); +extern void StmtRetryValidate(StatementRetryController* controller); +extern void StmtRetryDisable(void); + +extern bool IsStmtRetryEnabled(void); +extern bool IsStmtRetryQueryRetrying(void); +extern bool IsStmtRetryAvaliable(int elevel, int sqlErrCode); +extern bool IsStmtRetryCapable(StatementRetryController* controller, bool is_extend_query); +extern bool IsStmtNeedRetryByErrCode(const char* ecode_str, int errlevel); + +/* + * lnline functions + */ + +/* + * @Description: check if the sql statement need to retry by error code. + * @in ecode - error code type + * @in elevel - elevel type + * @return - true, statement retry is needed by error code. + */ +inline bool IsStmtNeedRetryByErrCode(int ecode, int errlevel) +{ + char* ecode_str = unpack_sql_state(ecode); + return IsStmtNeedRetryByErrCode(ecode_str, errlevel); +} + +/* + * @Description: filter statement retry by application name, filtering sql from application such as cm_agent and + gs_clean, not to retry. + * @in name - application name + * @return + */ +inline bool IsStmtNeedRetryByApplicationName(const char* name) +{ + return ((name != NULL) && (strcmp(name, "cm_agent") != 0) && (strcmp(name, "gs_clean") != 0) && + (strcmp(name, "gc_fdw") != 0)); +} + +#endif + +/*file end stmt_retry.h */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/tcopdebug.h postgresql-hll-2.14/include/include/tcop/tcopdebug.h --- postgresql-hll-2.14_old/include/include/tcop/tcopdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/tcopdebug.h 2020-12-12 17:06:43.276348413 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * tcopdebug.h + * #defines governing debugging behaviour in the traffic cop + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/tcopdebug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TCOPDEBUG_H +#define TCOPDEBUG_H + +/* ---------------------------------------------------------------- + * debugging defines. + * + * If you want certain debugging behaviour, then #define + * the variable to 1, else #undef it. -cim 10/26/89 + * ---------------------------------------------------------------- + */ + +/* ---------------- + * TCOP_SHOWSTATS controls whether or not buffer and + * access method statistics are shown for each query. -cim 2/9/89 + * ---------------- + */ +#undef TCOP_SHOWSTATS + +/* ---------------- + * TCOP_DONTUSENEWLINE controls the default setting of + * the UseNewLine variable in postgres.c + * ---------------- + */ +#undef TCOP_DONTUSENEWLINE + +/* ---------------------------------------------------------------- + * #defines controlled by above definitions + * ---------------------------------------------------------------- + */ + +#endif /* TCOPDEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/tcopprot.h postgresql-hll-2.14/include/include/tcop/tcopprot.h --- postgresql-hll-2.14_old/include/include/tcop/tcopprot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/tcopprot.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * tcopprot.h + * prototypes for postgres.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/tcopprot.h + * + * OLD COMMENTS + * This file was created so that other c files could get the two + * function prototypes without having to include tcop.h which single + * handedly includes the whole f*cking tree -- mer 5 Nov. 1991 + * + * ------------------------------------------------------------------------- + */ +#ifndef TCOPPROT_H +#define TCOPPROT_H + +#include "executor/execdesc.h" +#include "nodes/parsenodes.h" +#include "storage/procsignal.h" +#include "utils/guc.h" + +/* Required daylight between max_stack_depth and the kernel limit, in bytes */ +#define STACK_DEPTH_SLOP (640 * 1024L) + +/* GUC-configurable parameters */ + +typedef enum { + LOGSTMT_NONE, /* log no statements */ + LOGSTMT_DDL, /* log data definition statements */ + LOGSTMT_MOD, /* log modification statements, plus DDL */ + LOGSTMT_ALL /* log all statements */ +} LogStmtLevel; + +extern List* pg_parse_query(const char* query_string, List** query_string_locationlist = NULL); +extern List* pg_analyze_and_rewrite(Node* parsetree, const char* query_string, Oid* paramTypes, int numParams); +extern List* pg_analyze_and_rewrite_params( + Node* parsetree, const char* query_string, ParserSetupHook parserSetup, void* parserSetupArg); +extern PlannedStmt* pg_plan_query( + Query* querytree, int cursorOptions, ParamListInfo boundParams, bool underExplain = false); +extern List* pg_plan_queries(List* querytrees, int cursorOptions, ParamListInfo boundParams); + +extern bool check_max_stack_depth(int* newval, void** extra, GucSource source); +extern void assign_max_stack_depth(int newval, void* extra); + +extern void die(SIGNAL_ARGS); +extern void quickdie(SIGNAL_ARGS); +extern void StatementCancelHandler(SIGNAL_ARGS); +extern void FloatExceptionHandler(SIGNAL_ARGS); +extern void RecoveryConflictInterrupt(ProcSignalReason reason); /* called from SIGUSR1 + * handler */ +extern void prepare_for_client_read(void); +extern void client_read_ended(void); +extern void prepare_for_logic_conn_read(void); +extern void logic_conn_read_check_ended(void); +extern void process_postgres_switches(int argc, char* argv[], GucContext ctx, const char** dbname); +extern int PostgresMain(int argc, char* argv[], const char* dbname, const char* username); +extern long get_stack_depth_rlimit(void); +extern void ResetUsage(void); +extern void ShowUsage(const char* title); +extern int check_log_duration(char* msec_str, bool was_logged); +extern void set_debug_options(int debug_flag, GucContext context, GucSource source); +extern bool set_plan_disabling_options(const char* arg, GucContext context, GucSource source); +extern const char* get_stats_option_name(const char* arg); + +#endif /* TCOPPROT_H */ diff -uprN postgresql-hll-2.14_old/include/include/tcop/utility.h postgresql-hll-2.14/include/include/tcop/utility.h --- postgresql-hll-2.14_old/include/include/tcop/utility.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tcop/utility.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,196 @@ +/* ------------------------------------------------------------------------- + * + * utility.h + * prototypes for utility.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/utility.h + * + * ------------------------------------------------------------------------- + */ +#ifndef UTILITY_H +#define UTILITY_H + +#include "pgxc/pgxcnode.h" +#include "tcop/tcopprot.h" + +#define CHOOSE_EXEC_NODES(is_temp) ((is_temp) ? EXEC_ON_DATANODES : EXEC_ON_ALL_NODES) + +#define TRANSFER_DISABLE_DDL(namespaceOid) \ + do { \ + if (!IsInitdb && \ + IS_PGXC_COORDINATOR && !IsConnFromCoord() && \ + IsSchemaInDistribution(namespaceOid) && \ + (u_sess->attr.attr_common.application_name == NULL || \ + strncmp(u_sess->attr.attr_common.application_name, "gs_redis", strlen("gs_redis")) != 0)) { \ + ereport(ERROR, (errcode(ERRCODE_INVALID_OPERATION), \ + errmsg("Disallow DDL while schema transfering."))); \ + } \ + } while(0) \ + +/* Hook for plugins to get control in ProcessUtility() */ +typedef void (*ProcessUtility_hook_type)(Node* parsetree, const char* queryString, ParamListInfo params, + bool isTopLevel, DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); +extern THR_LOCAL PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook; + +extern void ProcessUtility(Node* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, + DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); +extern void standard_ProcessUtility(Node* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, + DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); + +extern char* find_first_exec_cn(); +extern bool find_hashbucket_options(List* stmts); + +#ifdef PGXC +extern void CreateCommand( + CreateStmt* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, bool sentToRemote); +#else +extern void CreateCommand(CreateStmt* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel); +#endif + +extern void ReindexCommand(ReindexStmt* stmt, bool isTopLevel); + +extern bool UtilityReturnsTuples(Node* parsetree); + +extern TupleDesc UtilityTupleDescriptor(Node* parsetree); + +extern Query* UtilityContainsQuery(Node* parsetree); + +extern const char* CreateCommandTag(Node* parsetree); + +extern LogStmtLevel GetCommandLogLevel(Node* parsetree); + +extern bool CommandIsReadOnly(Node* parsetree); + +#ifdef PGXC + +typedef enum { + ARQ_TYPE_TOTALROWCNTS, + ARQ_TYPE_SAMPLE, /* include sample rows or sample table. */ +} ANALYZE_RQTYPE; + +extern void pgxc_lock_for_utility_stmt(Node* parsetree, bool is_temp); +extern void ExecUtilityStmtOnNodes(const char* queryString, ExecNodes* nodes, bool sentToRemote, bool force_autocommit, + RemoteQueryExecType exec_type, bool is_temp, Node* parsetree = NULL); +extern HeapTuple* ExecRemoteVacuumStmt(VacuumStmt* stmt, const char* queryString, bool sentToRemote, + ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL, Oid relid = InvalidOid); + +extern void ExecUtilityStmtOnNodes_ParallelDDLMode(const char* queryString, ExecNodes* nodes, bool sentToRemote, + bool force_autocommit, RemoteQueryExecType exec_type, bool is_temp, const char* FirstExecNode = NULL, + Node* parsetree = NULL); + +extern HeapTuple* ExecUtilityStmtOnNodesWithResults(VacuumStmt* stmt, const char* queryString, bool sentToRemote, + ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); +extern void CheckObjectInBlackList(ObjectType objtype, const char* queryString); +extern bool CheckExtensionInWhiteList(const char* extensionName, uint32 hashvalue, bool hashCheck); +/* @hdfs Judge if a foreign table support analyze operation. */ +bool IsHDFSTableAnalyze(Oid foreignTableId); +/* @pgfdw judge if is a gc_fdw foreign table support analysis operation. */ +bool IsPGFDWTableAnalyze(Oid foreignTableId); +#ifdef ENABLE_MOT +/* @MOT IsMOTForeignTbale */ +bool IsMOTForeignTable(Oid foreignTableId); +#endif +/* @hdfs IsForeignTableAnalyze function is called by standard_ProcessUtility */ +bool IsHDFSForeignTableAnalyzable(VacuumStmt* stmt); +void global_stats_set_samplerate(AnalyzeMode eAnalyzeMode, VacuumStmt* stmt, const double* NewSampleRate); +bool check_analyze_permission(Oid rel); + +extern ExecNodes* RelidGetExecNodes(Oid relid, bool isutility = true); +extern bool ObjectsInSameNodeGroup(List* objects, NodeTag stmttype); +extern void EstIdxMemInfo( + Relation rel, RangeVar* relation, UtilityDesc* desc, IndexInfo* info, const char* accessMethod); +extern void AdjustIdxMemInfo(AdaptMem* operatorMem, UtilityDesc* desc); + +/* + * @hdfs The struct HDFSTableAnalyze is used to store datanode work infomation + */ +typedef struct HDFSTableAnalyze { + NodeTag type; + List* DnWorkFlow; + int DnCnt; + bool isHdfsStore; /* the flag identify whether or not the relation for analyze is Dfs store */ + double sampleRate[ANALYZE_MODE_MAX_NUM - 1]; /* There are three sampleRate values for HDFS table, include + main/delta/complex. */ + unsigned int orgCnNodeNo; /* the nodeId identify which CN receive analyze command from client, other CN need to get + stats from it. */ + bool isHdfsForeignTbl; /* the current analyze table is hdfs foreign table or not. */ + bool sampleTableRequired; /* require sample table for get statistic. */ + List* tmpSampleTblNameList; /* identify sample table name if under debugging. */ + DistributionType disttype; /* Distribution type for analyze's table. */ + AdaptMem memUsage; /* meminfo that should pass down to dn */ +} HDFSTableAnalyze; + +typedef struct PGFDWTableAnalyze { + Oid relid; + PGXCNodeAllHandles* pgxc_handles; + + int natts_pg_statistic; + int natts_pg_statistic_ext; + + int natts; + char** attname; + int* attnum; + + bool has_analyze; +} PGFDWTableAnalyze; + +/* + * @hdfs The struct ForeignTableDesc is used to represent foreign table + */ +typedef struct ForeignTableDesc { + NodeTag type; + char* tableName; + char* schemaName; + Oid tableOid; +} ForeignTableDesc; + +/* The struct for verify information*/ +typedef struct VerifyDesc { + bool isCudesc; /* judge cudesc relation and its toast\index relation */ + bool isCudescDamaged; /*judge the relation data corrupt*/ +} VerifyDesc; + +enum FOREIGNTABLEFILETYPE_ { + HDFS_ORC = 1, + MOT_ORC = 2, + MYSQL_ORC = 3, + ORACLE_ORC = 4, + POSTGRES_ORC = 5 +}; + +typedef enum FOREIGNTABLEFILETYPE_ FOREIGNTABLEFILETYPE; + +#endif + +extern void BlockUnsupportedDDL(const Node* parsetree); +extern const char* CreateAlterTableCommandTag(const AlterTableType subtype); + +extern void SetSortMemInfo(UtilityDesc* desc, int rowCnt, int width, bool vectorized, bool indexSort, Size defaultSize, + Relation copyRel = NULL); +extern char* ConstructMesageWithMemInfo(const char* queryString, AdaptMem memInfo); + +extern void AssembleHybridMessage(char** queryStringWithInfo, const char* queryString, const char* schedulingMessage); + +extern void ClearCreateSeqStmtUUID(CreateSeqStmt* stmt); +extern void ClearCreateStmtUUIDS(CreateStmt* stmt); +extern bool IsSchemaInDistribution(const Oid namespaceOid); +extern Oid GetNamespaceIdbyRelId(const Oid relid); + + +#endif /* UTILITY_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_controler.h postgresql-hll-2.14/include/include/threadpool/threadpool_controler.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_controler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_controler.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_controler.h + * Controler for thread pool. Class ThreadPoolControler is defined to + * initilize thread pool's worker and listener threads, and dispatch + * new session from postmaster thread to suitable thread group. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_controler.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_CONTROLER_H +#define THREAD_POOL_CONTROLER_H + +#include "utils/memutils.h" +#include "threadpool_group.h" +#include "knl/knl_variable.h" + +class ThreadPoolSessControl; + +enum CPUBindType { NO_CPU_BIND, ALL_CPU_BIND, NODE_BIND, CPU_BIND }; + +typedef struct CPUInfo { + int totalCpuNum; + int activeCpuNum; + int totalNumaNum; + int activeNumaNum; + int* cpuArrSize; + int** cpuArr; + + CPUBindType bindType; + bool* isBindCpuArr; + bool* isBindNumaArr; + bool* isMcsCpuArr; +} CPUInfo; + +typedef struct ThreadPoolAttr { + int threadNum; + int groupNum; + char* bindCpu; +} ThreadPoolAttr; + +class ThreadPoolControler : public BaseObject { +public: + ThreadPoolSessControl* m_sessCtrl; + + ThreadPoolControler(); + ~ThreadPoolControler(); + + void Init(bool enableNumaDistribute); + void ShutDownThreads(bool forceWait = false); + int DispatchSession(Port* port); + void AddWorkerIfNecessary(); + void SetThreadPoolInfo(); + int GetThreadNum(); + ThreadPoolStat* GetThreadPoolStat(uint32* num); + bool StayInAttachMode(); + void CloseAllSessions(); + bool CheckNumaDistribute(int numaNodeNum) const; + CPUBindType GetCpuBindType() const; + void ShutDownListeners(bool forceWait); + void ShutDownScheduler(bool forceWait); + inline ThreadPoolSessControl* GetSessionCtrl() + { + return m_sessCtrl; + } + inline ThreadPoolScheduler* GetScheduler() + { + return m_scheduler; + } + inline int GetGroupNum() + { + return m_groupNum; + } + + inline MemoryContext GetMemCxt() + { + return m_threadPoolContext; + } + + void BindThreadToAllAvailCpu(ThreadId thread) const; + +private: + ThreadPoolGroup* FindThreadGroupWithLeastSession(); + void ParseAttr(); + void ParseBindCpu(); + int ParseRangeStr(char* attr, bool* arr, int totalNum, char* bindtype); + void GetMcsCpuInfo(); + void GetSysCpuInfo(); + void InitCpuInfo(); + void GetCpuAndNumaNum(); + bool IsActiveCpu(int cpuid, int numaid); + void SetGroupAndThreadNum(); + void ConstrainThreadNum(); + void GetInstanceBind(); + bool CheckCpuBind() const; + +private: + MemoryContext m_threadPoolContext; + ThreadPoolGroup** m_groups; + ThreadPoolScheduler* m_scheduler; + CPUInfo m_cpuInfo; + ThreadPoolAttr m_attr; + cpu_set_t m_cpuset; + int m_groupNum; + int m_threadNum; + int m_maxPoolSize; +}; + +#endif /* THREAD_POOL_CONTROLER_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_group.h postgresql-hll-2.14/include/include/threadpool/threadpool_group.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_group.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_group.h + * Thread pool group controls listener and worker threads. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_group.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_GROUP_H +#define THREAD_POOL_GROUP_H + +#include "c.h" +#include "utils/memutils.h" +#include "knl/knl_variable.h" + +#define NUM_THREADPOOL_STATUS_ELEM 8 +#define STATUS_INFO_SIZE 256 + +typedef enum { THREAD_SLOT_UNUSE = 0, THREAD_SLOT_INUSE } ThreadSlotStatus; + +struct ThreadSentryStatus { + int spawntick; + TimestampTz lastSpawnTime; + ThreadSlotStatus slotStatus; +}; + +struct ThreadWorkerSentry { + ThreadSentryStatus stat; + ThreadPoolWorker* worker; + pthread_mutex_t mutex; + pthread_cond_t cond; +}; + +#ifdef ENABLE_MULTIPLE_NODES +struct ThreadStreamSentry { + ThreadSentryStatus stat; + ThreadPoolStream* stream; + pthread_mutex_t mutex; + pthread_cond_t cond; +}; +#endif + +typedef struct ThreadPoolStat { + int groupId; + int numaId; + int bindCpuNum; + int listenerNum; + char workerInfo[STATUS_INFO_SIZE]; + char sessionInfo[STATUS_INFO_SIZE]; + char streamInfo[STATUS_INFO_SIZE]; +} ThreadPoolStat; + +class ThreadPoolGroup : public BaseObject { +public: + ThreadPoolListener* m_listener; + + ThreadPoolGroup(int maxWorkerNum, int expectWorkerNum, int maxStreamNum, + int groupId, int numaId, int cpuNum, int* cpuArr); + ~ThreadPoolGroup(); + void Init(bool enableNumaDistribute); + void InitWorkerSentry(); + void ReleaseWorkerSlot(int i); + void AddWorker(int i); + ThreadId AddStream(StreamProducer* producer); + void ShutDownThreads(); + void AddWorkerIfNecessary(); + bool EnlargeWorkers(int enlargeNum); + void ReduceWorkers(int reduceNum); + void ShutDownPendingWorkers(); + void ReduceStreams(); + void WaitReady(); + float4 GetSessionPerThread(); + void GetThreadPoolGroupStat(ThreadPoolStat* stat); + bool IsGroupHang(); + + inline ThreadPoolListener* GetListener() + { + return m_listener; + } + + inline int GetGroupId() + { + return m_groupId; + } + + inline int GetNumaId() + { + return m_numaId; + } + + inline bool AllSessionClosed() + { + return (m_sessionCount <= 0); + } + + inline bool AllThreadShutDown() + { + return (m_workerNum <= 0); + } + +#ifdef ENABLE_MULTIPLE_NODES + ThreadId GetStreamFromPool(StreamProducer* producer); + void ReturnStreamToPool(Dlelem* elem); + void RemoveStreamFromPool(Dlelem* elem, int idx); + void InitStreamSentry(); + + inline bool HasFreeStream() + { + return (m_idleStreamNum > 0); + } +#endif + + friend class ThreadPoolWorker; + friend class ThreadPoolListener; + friend class ThreadPoolScheduler; + +private: + void AttachThreadToCPU(ThreadId thread, int cpu); + void AttachThreadToNodeLevel(ThreadId thread) const; + +private: + int m_maxWorkerNum; + int m_maxStreamNum; + int m_defaultWorkerNum; + volatile int m_workerNum; + volatile int m_listenerNum; + volatile int m_expectWorkerNum; + volatile int m_idleWorkerNum; + volatile int m_pendingWorkerNum; + volatile int m_streamNum; + volatile int m_idleStreamNum; + volatile int m_sessionCount; // all session count; + volatile int m_waitServeSessionCount; // wait for worker to server + volatile int m_processTaskCount; + + int m_groupId; + int m_numaId; + int m_groupCpuNum; + int* m_groupCpuArr; + bool m_enableNumaDistribute; + cpu_set_t m_nodeCpuSet; /* for numa node distribution only */ + + ThreadWorkerSentry* m_workers; + MemoryContext m_context; + pthread_mutex_t m_mutex; + +#ifdef ENABLE_MULTIPLE_NODES + ThreadStreamSentry* m_streams; + DllistWithLock* m_freeStreamList; +#endif +}; + +#endif /* THREAD_POOL_GROUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool.h postgresql-hll-2.14/include/include/threadpool/threadpool.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool.h + * Include all thread pool header file. + * + * IDENTIFICATION + * src/include/threadpool/threadpool.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_H +#define THREAD_POOL_H + +#include "threadpool/threadpool_controler.h" +#include "threadpool/threadpool_group.h" +#include "threadpool/threadpool_listener.h" +#include "threadpool/threadpool_sessctl.h" +#include "threadpool/threadpool_worker.h" +#include "threadpool/threadpool_scheduler.h" +#include "threadpool/threadpool_stream.h" + +#define ENABLE_THREAD_POOL (g_threadPoolControler != NULL) +#define IS_THREAD_POOL_WORKER (t_thrd.role == THREADPOOL_WORKER) +#define IS_THREAD_POOL_LISTENER (t_thrd.role == THREADPOOL_LISTENER) +#define IS_THREAD_POOL_SCHEDULER (t_thrd.role == THREADPOOL_SCHEDULER) +#define IS_THREAD_POOL_STREAM (t_thrd.role == THREADPOOL_STREAM) +#define IS_THREAD_POOL_SESSION (u_sess->session_id > 0) +#define BackendIdForTempRelations (ENABLE_THREAD_POOL ? (BackendId)u_sess->session_ctr_index : t_thrd.proc_cxt.MyBackendId) +#define THREAD_CORE_RATIO 1 +#define DEFAULT_THREAD_POOL_SIZE 16 +#define DEFAULT_THREAD_POOL_GROUPS 2 +#define MAX_THREAD_POOL_SIZE 4096 +#define MAX_STREAM_POOL_SIZE 16384 +#define MAX_THREAD_POOL_GROUPS 64 + +extern ThreadPoolControler* g_threadPoolControler; + +extern void BackendWorkerIAm(); + +/* Interface for thread pool listener */ +extern void TpoolListenerMain(ThreadPoolListener* listener); +extern void ThreadPoolListenerIAm(); + +extern void PreventSignal(); +extern void AllowSignal(); + +#endif /* THREAD_POOL_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_listener.h postgresql-hll-2.14/include/include/threadpool/threadpool_listener.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_listener.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_listener.h 2020-12-12 17:06:43.277348425 +0800 @@ -0,0 +1,81 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_listener.h + * Listener thread epoll all connections belongs to this thread group, and + * dispatch active session to a free worker. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_listener.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_LISTENER_H +#define THREAD_POOL_LISTENER_H + +#include +#include "lib/dllist.h" +#include "knl/knl_variable.h" + +class ThreadPoolListener : public BaseObject { +public: + ThreadPoolGroup* m_group; + volatile bool m_reaperAllSession; + + ThreadPoolListener(ThreadPoolGroup* group); + ~ThreadPoolListener(); + int StartUp(); + void CreateEpoll(); + void NotifyReady(); + bool TryFeedWorker(ThreadPoolWorker* worker); + void AddNewSession(knl_session_context* session); + void WaitTask(); + void DelSessionFromEpoll(knl_session_context* session); + void RemoveWorkerFromList(ThreadPoolWorker* worker); + void AddEpoll(knl_session_context* session); + void SendShutDown(); + void ReaperAllSession(); + void ShutDown() const; + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + inline ThreadId GetThreadId() + { + return m_tid; + } + inline void ResetThreadId() + { + m_tid = 0; + } +private: + void HandleConnEvent(int nevets); + knl_session_context* GetSessionBaseOnEvent(struct epoll_event* ev); + void DispatchSession(knl_session_context* session); + +private: + ThreadId m_tid; + int m_epollFd; + struct epoll_event* m_epollEvents; + + DllistWithLock* m_freeWorkerList; + DllistWithLock* m_readySessionList; + DllistWithLock* m_idleSessionList; +}; + +#endif /* THREAD_POOL_LISTENER_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_scheduler.h postgresql-hll-2.14/include/include/threadpool/threadpool_scheduler.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_scheduler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_scheduler.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,62 @@ +/*--------------------------------------------------------------------------------------- + * + * threadpool_scheduler.h + * + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2019, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/threadpool/threadpool_scheduler.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_SCHEDULER_CONTROL_H +#define THREAD_POOL_SCHEDULER_CONTROL_H + +class ThreadPoolScheduler : public BaseObject{ +public: + ThreadPoolScheduler(int groupNum, ThreadPoolGroup** groups); + ~ThreadPoolScheduler(); + int StartUp(); + void DynamicAdjustThreadPool(); + void GPCScheduleCleaner(int* gpc_count); + void CNGPCScheduleCleaner(int* gpc_count); + void ShutDown() const; + inline ThreadId GetThreadId() + { + return m_tid; + } + inline void SetShutDown(bool has_shutdown) + { + m_has_shutdown = has_shutdown; + } + inline bool HasShutDown() + { + return m_has_shutdown; + } +private: + void AdjustWorkerPool(int idx); + void AdjustStreamPool(int idx); + void ReduceWorkerIfNecessary(int groupIdx); + void EnlargeWorkerIfNecessage(int groupIdx); +private: + ThreadId m_tid; + int m_groupNum; + ThreadPoolGroup** m_groups; + uint* m_hangTestCount; + uint* m_freeTestCount; + uint* m_freeStreamCount; + volatile bool m_has_shutdown; +}; + +#define THREAD_SCHEDULER_STEP 8 + +extern void TpoolSchedulerMain(ThreadPoolScheduler* scheduler); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_sessctl.h postgresql-hll-2.14/include/include/threadpool/threadpool_sessctl.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_sessctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_sessctl.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_sessctl.h + * Class ThreadPoolSessControl is used to control all session info in thread pool. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_sessctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_SESSION_CONTROL_H +#define THREAD_POOL_SESSION_CONTROL_H + +#include "storage/procsignal.h" +#include "knl/knl_variable.h" +#include "utils/tuplestore.h" + +#define MEMORY_CONTEXT_NAME_LEN 64 +#define PROC_NAME_LEN 64 +#define NUM_SESSION_MEMORY_DETAIL_ELEM 8 +#define NUM_THREAD_MEMORY_DETAIL_ELEM 9 +#define NUM_SHARED_MEMORY_DETAIL_ELEM 6 + + +typedef struct knl_sess_control { + Dlelem elem; + int idx; // session array index; + knl_session_context* sess; + volatile sig_atomic_t lock; +} knl_sess_control; + +class ThreadPoolSessControl : public BaseObject { +public: + ThreadPoolSessControl(MemoryContext context); + ~ThreadPoolSessControl(); + knl_session_context* CreateSession(Port* port); + knl_sess_control* AllocateSlot(knl_session_context* sc); + void FreeSlot(int ctrl_index); + void MarkAllSessionClose(); + int SendSignal(int ctrl_index, int signal); + void SendProcSignal(int ctrl_index, ProcSignalReason reason, uint64 query_id); + int CountDBSessions(Oid dbId); + void SigHupHandler(); + void HandlePoolerReload(); + void CheckSessionTimeout(); + void CheckPermissionForSendSignal(knl_session_context* sess); + void getSessionMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc, knl_sess_control** sess); + knl_session_context* GetSessionByIdx(int idx); + int FindCtrlIdxBySessId(uint64 id); + TransactionId ListAllSessionGttFrozenxids(int maxSize, ThreadId *pids, TransactionId *xids, int *n); + + inline int GetActiveSessionCount() + { + return m_activeSessionCount; + } + +private: + void recursiveSessMemCxt( + knl_session_context* sess, const MemoryContext context, Tuplestorestate* tupStore, TupleDesc tupDesc); + void calculateSessMemCxtStats( + knl_session_context* sess, const MemoryContext context, Tuplestorestate* tupStore, TupleDesc tupDesc); + + inline bool IsValidCtrlIndex(int ctrl_index) + { + if (ctrl_index < m_maxReserveSessionCount || ctrl_index - m_maxReserveSessionCount >= m_maxActiveSessionCount) { + ereport(WARNING, + (errmsg("Invalid session control index %d, " + "maxReserveSessionCount %d, m_maxActiveSessionCount %d", + ctrl_index, + m_maxReserveSessionCount, + m_maxActiveSessionCount))); + return false; + } else { + return true; + } + } + +private: + /* session id generate */ + uint64 m_sessionId; + /* current session count. */ + volatile int m_activeSessionCount; + /* max session count we can accept. */ + int m_maxActiveSessionCount; + int m_maxReserveSessionCount; + /* session control structure. */ + knl_sess_control* m_base; + Dllist m_freelist; + Dllist m_activelist; + pthread_mutex_t m_sessCtrlock; + + MemoryContext m_context; +}; + +#endif /* THREAD_POOL_SESSION_CONTROL_H */ diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_stream.h postgresql-hll-2.14/include/include/threadpool/threadpool_stream.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_stream.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- +* +* threadpool_stream.h +* stream thread pool Interface +* +* Portions Copyright (c) 2020 Huawei +* IDENTIFICATION +* src/include/distributelayer/threadpool_stream.h +* +* NOTES +* +* ------------------------------------------------------------------------- +*/ + +#ifndef THREAD_POOL_STREAM_H +#define THREAD_POOL_STREAM_H + +#ifdef ENABLE_MULTIPLE_NODES + +#include "knl/knl_variable.h" + +class ThreadPoolStream : public BaseObject { +public: + ThreadPoolStream(); + ~ThreadPoolStream(); + int StartUp(int idx, StreamProducer* producer, ThreadPoolGroup* group, + pthread_mutex_t* mutex, pthread_cond_t* cond); + void WaitMission(); + void WakeUpToWork(StreamProducer* producer); + void WakeUpToUpdate(ThreadStatus status); + void CleanUp(); + void ShutDown(); + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + + inline ThreadId GetThreadId() + { + return m_tid; + } + + inline StreamProducer* GetProducer() + { + return m_producer; + } + +private: + void InitStream(); + +private: + int m_idx; + ThreadId m_tid; + Dlelem m_elem; + ThreadStatus m_threadStatus; + StreamProducer* m_producer; + ThreadPoolGroup* m_group; + + pthread_mutex_t* m_mutex; + pthread_cond_t* m_cond; +}; + +#endif +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/threadpool/threadpool_worker.h postgresql-hll-2.14/include/include/threadpool/threadpool_worker.h --- postgresql-hll-2.14_old/include/include/threadpool/threadpool_worker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/threadpool/threadpool_worker.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,146 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_worker.h + * ThreadPoolWorker will get an active session from ThreadPoolListener, + * read command from the session and execute the command. This class is + * also response to init and free session. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_worker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_WORKER_H +#define THREAD_POOL_WORKER_H + +#include "lib/dllist.h" +#include "knl/knl_variable.h" + +#define THRD_SIGTERM 0x00000001 +#define THRD_EXIT 0x00000010 +extern void SetThreadLocalGUC(knl_session_context* session); +/* + * List of active backends (or child processes anyway; we don't actually + * know whether a given child has become a backend or is still in the + * authorization phase). This is used mainly to keep track of how many + * children we have and send them appropriate signals when necessary. + * + * "Special" children such as the startup, bgwriter and autovacuum launcher + * tasks are not in this list Autovacuum worker and walsender processes are + * in it. Also, "dead_end" children are in it: these are children launched just + * for the purpose of sending a friendly rejection message to a would-be + * client. We must track them because they are attached to shared memory, + * but we know they will never become live backends. dead_end children are + * not assigned a PMChildSlot. + */ +typedef struct Backend { + ThreadId pid; /* process id of backend */ + long cancel_key; /* cancel key for cancels for this backend */ + int child_slot; /* PMChildSlot for this backend, if any */ + bool is_autovacuum; /* is it an autovacuum process? */ + volatile bool dead_end; /* is it going to send an quit? */ + volatile int flag; + Dlelem elem; /* list link in BackendList */ +} Backend; + +typedef enum { + THREAD_UNINIT = 0, + THREAD_RUN, + THREAD_PENDING, + THREAD_EXIT, // set by PM , as PM down. +} ThreadStatus; + +typedef enum { + TWORKER_HOLDSESSIONLOCK = 0, + TWORKER_TWOPHASECOMMIT, + TWORKER_HOLDLWLOCK, + TWORKER_GETNEXTXID, + TWORKER_STILLINTRANS, + TWORKER_UNCONSUMEMESSAGE, + TWORKER_CANSEEKNEXTSESSION, + TWORKER_PREDEADSESSION +} ThreadStayReason; + +class ThreadPoolGroup; +class ThreadPoolWorker : public BaseObject { +public: + ThreadPoolWorker(uint idx, ThreadPoolGroup* group, pthread_mutex_t* mutex, pthread_cond_t* m_cond); + ~ThreadPoolWorker(); + int StartUp(); + void ShutDown(); + void NotifyReady(); + void WaitMission(); + void CleanUpSession(bool threadexit); + void CleanUpSessionWithLock(); + bool WakeUpToWork(knl_session_context* session); + void WakeUpToUpdate(ThreadStatus status); + + friend class ThreadPoolListener; + + inline knl_session_context* GetAttachSession() + { + return m_currentSession; + } + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + + inline ThreadId GetThreadId() + { + return m_tid; + } + + inline void SetSession(knl_session_context* session) + { + m_currentSession = session; + } + + static Backend* CreateBackend(); + static void AddBackend(Backend* bn); + +public: + volatile int m_waitState; + +private: + void CleanThread(); + bool AttachSessionToThread(); + void DetachSessionFromThread(); + void WaitNextSession(); + bool InitPort(Port* port); + void FreePort(Port* port); + void Pending(); + void ShutDownIfNecessary(); + void RestoreSessionVariable(); + void RestoreThreadVariable(); + void RestoreLocaleInfo(); + void SetSessionInfo(); + +private: + ThreadId m_tid; + uint m_idx; + knl_session_context* m_currentSession; + volatile ThreadStatus m_threadStatus; + ThreadStayReason m_reason; + Dlelem m_elem; + ThreadPoolGroup* m_group; + pthread_mutex_t* m_mutex; + pthread_cond_t* m_cond; +}; + +#endif /* THREAD_POOL_WORKER_H */ diff -uprN postgresql-hll-2.14_old/include/include/tsan_annotation.h postgresql-hll-2.14/include/include/tsan_annotation.h --- postgresql-hll-2.14_old/include/include/tsan_annotation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsan_annotation.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,38 @@ +#ifndef TSAN_ANNOTATION_H +#define TSAN_ANNOTATION_H + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); + void AnnotateHappensAfter(const char *f, int l, uintptr_t addr); + void AnnotateRWLockCreate(char *f, int l, uintptr_t m); + void AnnotateRWLockDestroy(char *f, int l, uintptr_t m); + void AnnotateRWLockAcquired(char *f, int l, uintptr_t m, uintptr_t is_w); + void AnnotateRWLockReleased(char *f, int l, uintptr_t m, uintptr_t is_w); + void AnnotateBenignRaceSized(char *f, int l, uintptr_t m, uintptr_t size, char *desc); + void AnnotateReadBarrier(); + void AnnotateWriteBarrier(); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateHappensAfter(addr) AnnotateHappensAfter(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateRWLockCreate(m) AnnotateRWLockCreate(__FILE__, __LINE__, (uintptr_t)m) +#define TsAnnotateRWLockDestroy(m) AnnotateRWLockDestroy(__FILE__, __LINE__, (uintptr_t)m) +#define TsAnnotateRWLockAcquired(m, is_w) AnnotateRWLockAcquired(__FILE__, __LINE__, (uintptr_t)m, is_w) +#define TsAnnotateRWLockReleased(m, is_w) AnnotateRWLockReleased(__FILE__, __LINE__, (uintptr_t)m, is_w) +#define TsAnnotateBenignRaceSized(m, size) AnnotateBenignRaceSized(__FILE__, __LINE__, (uintptr_t)m, size, NULL) +#define TsAnnotateWriteBarrier() AnnotateWriteBarrier() +#define TsAnnotateReadBarrier() AnnotateReadBarrier() +#else +#define TsAnnotateHappensBefore(addr) +#define TsAnnotateHappensAfter(addr) +#define TsAnnotateRWLockCreate(m) +#define TsAnnotateRWLockDestroy(m) +#define TsAnnotateRWLockAcquired(m, is_w) +#define TsAnnotateRWLockReleased(m, is_w) +#define TsAnnotateBenignRaceSized(m, size) +#define TsAnnotateWriteBarrier() +#define TsAnnotateReadBarrier() + +#endif /* endif ENABLE_THREAD_CHECK */ + +#endif // TSAN_ANNOTATION_H diff -uprN postgresql-hll-2.14_old/include/include/tsearch/dicts/regis.h postgresql-hll-2.14/include/include/tsearch/dicts/regis.h --- postgresql-hll-2.14_old/include/include/tsearch/dicts/regis.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/dicts/regis.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * regis.h + * + * Declarations for fast regex subset, used by ISpell + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/dicts/regis.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef __REGIS_H__ +#define __REGIS_H__ + +typedef struct RegisNode { + uint32 type : 2, len : 16, unused : 14; + struct RegisNode* next; + unsigned char data[FLEXIBLE_ARRAY_MEMBER]; +} RegisNode; + +#define RNHDRSZ (offsetof(RegisNode, data)) + +#define RSF_ONEOF 1 +#define RSF_NONEOF 2 + +typedef struct Regis { + RegisNode* node; + uint32 issuffix : 1, nchar : 16, unused : 15; +} Regis; + +bool RS_isRegis(const char* str); + +void RS_compile(Regis* r, bool issuffix, const char* str); +void RS_free(Regis* r); + +/* returns true if matches */ +bool RS_execute(Regis* r, char* str); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/tsearch/dicts/spell.h postgresql-hll-2.14/include/include/tsearch/dicts/spell.h --- postgresql-hll-2.14_old/include/include/tsearch/dicts/spell.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/dicts/spell.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------- + * + * spell.h + * + * Declarations for ISpell dictionary + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/dicts/spell.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef __SPELL_H__ +#define __SPELL_H__ + +#include "regex/regex.h" +#include "tsearch/dicts/regis.h" +#include "tsearch/ts_public.h" + +/* + * SPNode and SPNodeData are used to represent prefix tree (Trie) to store + * a words list. + */ +struct SPNode; + +typedef struct { + uint32 val : 8, isword : 1, + /* Stores compound flags listed below */ + compoundflag : 4, + /* Reference to an entry of the AffixData field */ + affix : 19; + struct SPNode* node; +} SPNodeData; + +/* + * Names of FF_ are correlated with Hunspell options in affix file + * http://hunspell.sourceforge.net/ + */ +#define FF_COMPOUNDONLY 0x01 +#define FF_COMPOUNDBEGIN 0x02 +#define FF_COMPOUNDMIDDLE 0x04 +#define FF_COMPOUNDLAST 0x08 +#define FF_COMPOUNDFLAG (FF_COMPOUNDBEGIN | FF_COMPOUNDMIDDLE | FF_COMPOUNDLAST) +#define FF_COMPOUNDFLAGMASK 0x0f + +typedef struct SPNode { + uint32 length; + SPNodeData data[FLEXIBLE_ARRAY_MEMBER]; +} SPNode; + +#define SPNHDRSZ (offsetof(SPNode, data)) + +/* + * Represents an entry in a words list. + */ +typedef struct spell_struct { + union { + /* + * flag is filled in by NIImportDictionary(). After NISortDictionary(), + * d is used instead of flag. + */ + char* flag; + /* d is used in mkSPNode() */ + struct { + /* Reference to an entry of the AffixData field */ + int affix; + /* Length of the word */ + int len; + } d; + } p; + char word[FLEXIBLE_ARRAY_MEMBER]; /* variable length, null-terminated */ +} SPELL; + +#define SPELLHDRSZ (offsetof(SPELL, word)) + +/* + * Represents an entry in an affix list. + */ +typedef struct aff_struct { + char* flag; + /* FF_SUFFIX or FF_PREFIX */ + uint32 type : 1, flagflags : 7, issimple : 1, isregis : 1, replen : 14; + char* find; + char* repl; + union { + regex_t regex; + Regis regis; + } reg; +} AFFIX; + +/* + * affixes use dictionary flags too + */ +#define FF_COMPOUNDPERMITFLAG 0x10 +#define FF_COMPOUNDFORBIDFLAG 0x20 +#define FF_CROSSPRODUCT 0x40 + +/* + * Don't change the order of these. Initialization sorts by these, + * and expects prefixes to come first after sorting. + */ +#define FF_SUFFIX 1 +#define FF_PREFIX 0 + +/* + * AffixNode and AffixNodeData are used to represent prefix tree (Trie) to store + * an affix list. + */ +struct AffixNode; + +typedef struct { + uint32 val : 8, naff : 24; + AFFIX** aff; + struct AffixNode* node; +} AffixNodeData; + +typedef struct AffixNode { + uint32 isvoid : 1, length : 31; + AffixNodeData data[FLEXIBLE_ARRAY_MEMBER]; +} AffixNode; + +#define ANHRDSZ (offsetof(AffixNode, data)) + +typedef struct { + char* affix; + int len; + bool issuffix; +} CMPDAffix; + +/* + * Type of encoding affix flags in Hunspel dictionaries + */ +typedef enum { + FM_CHAR, /* one character (like ispell) */ + FM_LONG, /* two characters */ + FM_NUM /* number, >= 0 and < 65536 */ +} FlagMode; + +/* + * Structure to store Hunspell options. Flag representation depends on flag + * type. These flags are about support of compound words. + */ +typedef struct CompoundAffixFlag { + union { + /* Flag name if flagMode is FM_CHAR or FM_LONG */ + char* s; + /* Flag name if flagMode is FM_NUM */ + uint32 i; + } flag; + /* we don't have a bsearch_arg version, so, copy FlagMode */ + FlagMode flagMode; + uint32 value; +} CompoundAffixFlag; + +#define FLAGCHAR_MAXSIZE (1 << 8) +#define FLAGNUM_MAXSIZE (1 << 16) + +typedef struct { + int maffixes; + int naffixes; + AFFIX* Affix; + + AffixNode* Suffix; + AffixNode* Prefix; + + SPNode* Dictionary; + /* Array of sets of affixes */ + char** AffixData; + int lenAffixData; + int nAffixData; + bool useFlagAliases; + + CMPDAffix* CompoundAffix; + + bool usecompound; + FlagMode flagMode; + + /* + * All follow fields are actually needed only for initialization + */ + + /* Array of Hunspell options in affix file */ + CompoundAffixFlag* CompoundAffixFlags; + /* number of entries in CompoundAffixFlags array */ + int nCompoundAffixFlag; + /* allocated length of CompoundAffixFlags array */ + int mCompoundAffixFlag; + + /* + * Remaining fields are only used during dictionary construction; they are + * set up by NIStartBuild and cleared by NIFinishBuild. + */ + MemoryContext buildCxt; /* temp context for construction */ + + /* Temporary array of all words in the dict file */ + SPELL** Spell; + int nspell; /* number of valid entries in Spell array */ + int mspell; /* allocated length of Spell array */ + + /* These are used to allocate "compact" data without palloc overhead */ + char* firstfree; /* first free address (always maxaligned) */ + size_t avail; /* free space remaining at firstfree */ +} IspellDict; + +extern TSLexeme* NINormalizeWord(IspellDict* Conf, char* word); + +extern void NIStartBuild(IspellDict* Conf); +extern void NIImportAffixes(IspellDict* Conf, const char* filename); +extern void NIImportDictionary(IspellDict* Conf, const char* filename); +extern void NISortDictionary(IspellDict* Conf); +extern void NISortAffixes(IspellDict* Conf); +extern void NIFinishBuild(IspellDict* Conf); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_cache.h postgresql-hll-2.14/include/include/tsearch/ts_cache.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_cache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_cache.h 2020-12-12 17:06:43.278348438 +0800 @@ -0,0 +1,84 @@ +/* ------------------------------------------------------------------------- + * + * ts_cache.h + * Tsearch related object caches. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tsearch/ts_cache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TS_CACHE_H +#define TS_CACHE_H + +#include "tsearch/ts_public.h" +#include "utils/guc.h" + +/* + * All TS*CacheEntry structs must share this common header + * (see InvalidateTSCacheCallBack) + */ +typedef struct TSAnyCacheEntry { + Oid objId; + bool isvalid; +} TSAnyCacheEntry; + +typedef struct TSParserCacheEntry { + /* prsId is the hash lookup key and MUST BE FIRST */ + Oid prsId; /* OID of the parser */ + bool isvalid; + + Oid startOid; + Oid tokenOid; + Oid endOid; + Oid headlineOid; + Oid lextypeOid; + + /* + * Pre-set-up fmgr call of most needed parser's methods + */ + FmgrInfo prsstart; + FmgrInfo prstoken; + FmgrInfo prsend; + FmgrInfo prsheadline; +} TSParserCacheEntry; + +typedef struct TSDictionaryCacheEntry { + /* dictId is the hash lookup key and MUST BE FIRST */ + Oid dictId; + bool isvalid; + + /* most frequent fmgr call */ + Oid lexizeOid; + FmgrInfo lexize; + + MemoryContext dictCtx; /* memory context to store private data */ + void* dictData; +} TSDictionaryCacheEntry; + +typedef struct ListDictionary { + int len; + Oid* dictIds; +} ListDictionary; + +typedef struct TSConfigCacheEntry { + /* cfgId is the hash lookup key and MUST BE FIRST */ + Oid cfgId; + bool isvalid; + Oid prsId; + int lenmap; + ListDictionary* map; + ParserCfOpts* opts; /* add configuration options */ +} TSConfigCacheEntry; + +extern TSParserCacheEntry* lookup_ts_parser_cache(Oid prsId); +extern TSDictionaryCacheEntry* lookup_ts_dictionary_cache(Oid dictId); +extern TSConfigCacheEntry* lookup_ts_config_cache(Oid cfgId); + +extern Oid getTSCurrentConfig(bool emitError); +extern bool check_TSCurrentConfig(char** newval, void** extra, GucSource source); +extern void assign_TSCurrentConfig(const char* newval, void* extra); + +#endif /* TS_CACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_locale.h postgresql-hll-2.14/include/include/tsearch/ts_locale.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_locale.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_locale.h 2020-12-12 17:06:43.279348451 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * ts_locale.h + * locale compatibility layer for tsearch + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_locale.h + * + * ------------------------------------------------------------------------- + */ +#ifndef __TSLOCALE_H__ +#define __TSLOCALE_H__ + +#include +#include + +#include "utils/pg_locale.h" +#include "mb/pg_wchar.h" + +/* + * towlower() and friends should be in , but some pre-C99 systems + * declare them in . + */ +#ifdef HAVE_WCHAR_H +#include +#endif +#ifdef HAVE_WCTYPE_H +#include +#endif + +/* working state for tsearch_readline (should be a local var in caller) */ +typedef struct { + FILE* fp; + const char* filename; + int lineno; + char* curline; + ErrorContextCallback cb; +} tsearch_readline_state; + +#define TOUCHAR(x) (*((const unsigned char*)(x))) + +#ifdef USE_WIDE_UPPER_LOWER + +extern int t_isdigit(const char* ptr); +extern int t_isspace(const char* ptr); +extern int t_isalpha(const char* ptr); +extern int t_isprint(const char* ptr); + +/* The second argument of t_iseq() must be a plain ASCII character */ +#define t_iseq(x, c) (TOUCHAR(x) == (unsigned char)(c)) + +#define COPYCHAR(d, s) \ + do { \ + int rc = memcpy_s(d, pg_mblen(s), s, pg_mblen(s)); \ + securec_check(rc, "", ""); \ + } while (0) + +#else /* not USE_WIDE_UPPER_LOWER */ + +#define t_isdigit(x) isdigit(TOUCHAR(x)) +#define t_isspace(x) isspace(TOUCHAR(x)) +#define t_isalpha(x) isalpha(TOUCHAR(x)) +#define t_isprint(x) isprint(TOUCHAR(x)) +#define t_iseq(x, c) (TOUCHAR(x) == (unsigned char)(c)) + +#define COPYCHAR(d, s) (*((unsigned char*)(d)) = TOUCHAR(s)) +#endif /* USE_WIDE_UPPER_LOWER */ + +extern char* lowerstr(const char* str); +extern char* lowerstr_with_len(const char* str, int len); + +extern bool tsearch_readline_begin(tsearch_readline_state* stp, const char* filename); +extern char* tsearch_readline(tsearch_readline_state* stp); +extern void tsearch_readline_end(tsearch_readline_state* stp); + +extern char* t_readline(FILE* fp); + +#endif /* __TSLOCALE_H__ */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_public.h postgresql-hll-2.14/include/include/tsearch/ts_public.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_public.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_public.h 2020-12-12 17:06:43.279348451 +0800 @@ -0,0 +1,177 @@ +/* ------------------------------------------------------------------------- + * + * ts_public.h + * Public interface to various tsearch modules, such as + * parsers and dictionaries. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_public.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TS_PUBLIC_H_ +#define _PG_TS_PUBLIC_H_ + +#include "nodes/pg_list.h" +#include "pgxc/pgxc.h" +#include "tsearch/ts_type.h" + +#define DICT_SEPARATOR ('_') + +#define FILE_POSTFIX_DICT ("dict") +#define FILE_POSTFIX_AFFIX ("affix") +#define FILE_POSTFIX_STOP ("stop") +#define FILE_POSTFIX_SYN ("syn") +#define FILE_POSTFIX_THS ("ths") + +#define skipLoad(ddlsql) ((ddlsql) && IsConnFromCoord()) + +/* + * Parser's framework + */ + +/* + * returning type for prslextype method of parser + */ +typedef struct { + int lexid; + char* alias; + char* descr; +} LexDescr; + +/* + * Interface to headline generator + */ +typedef struct { + uint32 selected : 1, in : 1, replace : 1, repeated : 1, skip : 1, unused : 3, type : 8, len : 16; + char* word; + QueryOperand* item; +} HeadlineWordEntry; + +typedef struct { + HeadlineWordEntry* words; + int4 lenwords; + int4 curwords; + char* startsel; + char* stopsel; + char* fragdelim; + int2 startsellen; + int2 stopsellen; + int2 fragdelimlen; +} HeadlineParsedText; + +/* + * Common useful things for tsearch subsystem + */ +extern char* get_tsearch_config_filename(const char* basename, char* pathname, const char* extension, bool newfile); +extern char* get_tsfile_prefix_internal(); +extern List* get_tsfile_postfix(List* filenames, char sep); +extern List* copy_tsfile_to_local(List* filenames, List* postfixes, const char* dictprefix); +extern void copy_tsfile_to_remote(List* filenames, List* postfixes); +extern void copy_tsfile_to_backup(List* filenames); +extern void delete_tsfile_internal(const char* dictprefix, Oid tmplId); +extern bool inCluster(); + +/* + * Often useful stopword list management + */ +typedef struct { + int len; + char** stop; +} StopList; + +extern void readstoplist(const char* fname, StopList* s, char* (*wordop)(const char*)); +extern bool searchstoplist(StopList* s, const char* key); +extern void ts_check_feature_disable(); + +/* + * Interface with dictionaries + */ + +/* return struct for any lexize function */ +typedef struct { + /* ---------- + * Number of current variant of split word. For example the Norwegian + * word 'fotballklubber' has two variants to split: ( fotball, klubb ) + * and ( fot, ball, klubb ). So, dictionary should return: + * + * nvariant lexeme + * 1 fotball + * 1 klubb + * 2 fot + * 2 ball + * 2 klubb + * + * In general, a TSLexeme will be considered to belong to the same split + * variant as the previous one if they have the same nvariant value. + * The exact values don't matter, only changes from one lexeme to next. + * ---------- + */ + uint16 nvariant; + + uint16 flags; /* See flag bits below */ + + char* lexeme; /* C string */ +} TSLexeme; + +/* Flag bits that can appear in TSLexeme.flags */ +#define TSL_ADDPOS 0x01 +#define TSL_PREFIX 0x02 +#define TSL_FILTER 0x04 + +/* + * Struct for supporting complex dictionaries like thesaurus. + * 4th argument for dictlexize method is a pointer to this + */ +typedef struct { + bool isend; /* in: marks for lexize_info about text end is + * reached */ + bool getnext; /* out: dict wants next lexeme */ + void* private_state; /* internal dict state between calls with + * getnext == true */ +} DictSubState; + +/* + * generic superclass for configuration options nodes, and the only one filed + * meas the length of the configuration option struncate + */ +typedef struct ParserCfOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ +} ParserCfOpts; + +/* + * configuration option struncate specail for ngram parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct NgramCfOpts { + int32 vl_len_; + int gram_size; + bool punctuation_ignore; + bool grapsymbol_ignore; +} NgramCfOpts; + +/* + * configuration option struncate specail for ngram parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct PoundCfOpts { + int32 vl_len_; + char* split_flag; +} PoundCfOpts; + +/* + * configuration option struncate specail for Zhparser parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct ZhparserCfOpts { + int32 vl_len_; + bool punctuation_ignore; + bool seg_with_duality; + bool multi_short; + bool multi_duality; + bool multi_zmain; + bool multi_zall; +} ZhparserCfOpts; + +#endif /* _PG_TS_PUBLIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_type.h postgresql-hll-2.14/include/include/tsearch/ts_type.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_type.h 2020-12-12 17:06:43.279348451 +0800 @@ -0,0 +1,279 @@ +/* ------------------------------------------------------------------------- + * + * ts_type.h + * Definitions for the tsvector and tsquery types + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_type.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TSTYPE_H_ +#define _PG_TSTYPE_H_ + +#include "fmgr.h" +#include "utils/memutils.h" +#include "utils/pg_crc.h" + +/* + * TSVector type. + * + * Structure of tsvector datatype: + * 1) standard varlena header + * 2) int4 size - number of lexemes (WordEntry array entries) + * 3) Array of WordEntry - one per lexeme; must be sorted according to + * tsCompareString() (ie, memcmp of lexeme strings). + * WordEntry->pos gives the number of bytes from end of WordEntry + * array to start of lexeme's string, which is of length len. + * 4) Per-lexeme data storage: + * lexeme string (not null-terminated) + * if haspos is true: + * padding byte if necessary to make the position data 2-byte aligned + * uint16 number of positions that follow + * WordEntryPos[] positions + * + * The positions for each lexeme must be sorted. + * + * Note, tsvectorsend/recv believe that sizeof(WordEntry) == 4 + */ +typedef struct { + uint32 haspos : 1, len : 11, /* MAX 2Kb */ + pos : 20; /* MAX 1Mb */ +} WordEntry; + +#define MAXSTRLEN ((1 << 11) - 1) +#define MAXSTRPOS ((1 << 20) - 1) + +/* + * Equivalent to + * typedef struct { + * uint16 + * weight:2, + * pos:14; + * } + */ +typedef uint16 WordEntryPos; + +typedef struct { + uint16 npos; + WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER]; /* variable length */ +} WordEntryPosVector; + +#define WEP_GETWEIGHT(x) ((x) >> 14) +#define WEP_GETPOS(x) ((x)&0x3fff) + +#define WEP_SETWEIGHT(x, v) ((x) = ((v) << 14) | ((x)&0x3fff)) +#define WEP_SETPOS(x, v) ((x) = ((x)&0xc000) | ((v)&0x3fff)) + +#define MAXENTRYPOS (1 << 14) +#define MAXNUMPOS (256) +#define LIMITPOS(x) (((x) >= MAXENTRYPOS) ? (MAXENTRYPOS - 1) : (x)) + +/* This struct represents a complete tsvector datum */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 size; + WordEntry entries[FLEXIBLE_ARRAY_MEMBER]; /* variable length */ + /* lexemes follow the entries[] array */ +} TSVectorData; + +typedef TSVectorData* TSVector; + +#define DATAHDRSIZE (offsetof(TSVectorData, entries)) +#define CALCDATASIZE(nentries, lenstr) (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr)) + +/* pointer to start of a tsvector's WordEntry array */ +#define ARRPTR(x) ((x)->entries) + +/* pointer to start of a tsvector's lexeme storage */ +#define STRPTR(x) ((char*)&(x)->entries[(x)->size]) + +#define _POSVECPTR(x, e) ((WordEntryPosVector*)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len))) +#define POSDATALEN(x, e) (((e)->haspos) ? (_POSVECPTR(x, e)->npos) : 0) +#define POSDATAPTR(x, e) (_POSVECPTR(x, e)->pos) + +/* + * fmgr interface macros + */ +#define DatumGetTSVector(X) ((TSVector)PG_DETOAST_DATUM(X)) +#define DatumGetTSVectorCopy(X) ((TSVector)PG_DETOAST_DATUM_COPY(X)) +#define TSVectorGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_TSVECTOR(n) DatumGetTSVector(PG_GETARG_DATUM(n)) +#define PG_GETARG_TSVECTOR_COPY(n) DatumGetTSVectorCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_TSVECTOR(x) return TSVectorGetDatum(x) + +/* + * I/O + */ +extern Datum tsvectorin(PG_FUNCTION_ARGS); +extern Datum tsvectorout(PG_FUNCTION_ARGS); +extern Datum tsvectorsend(PG_FUNCTION_ARGS); +extern Datum tsvectorrecv(PG_FUNCTION_ARGS); + +/* + * operations with tsvector + */ +extern Datum tsvector_lt(PG_FUNCTION_ARGS); +extern Datum tsvector_le(PG_FUNCTION_ARGS); +extern Datum tsvector_eq(PG_FUNCTION_ARGS); +extern Datum tsvector_ne(PG_FUNCTION_ARGS); +extern Datum tsvector_ge(PG_FUNCTION_ARGS); +extern Datum tsvector_gt(PG_FUNCTION_ARGS); +extern Datum tsvector_cmp(PG_FUNCTION_ARGS); + +extern Datum tsvector_length(PG_FUNCTION_ARGS); +extern Datum tsvector_strip(PG_FUNCTION_ARGS); +extern Datum tsvector_setweight(PG_FUNCTION_ARGS); +extern Datum tsvector_concat(PG_FUNCTION_ARGS); +extern Datum tsvector_update_trigger_byid(PG_FUNCTION_ARGS); +extern Datum tsvector_update_trigger_bycolumn(PG_FUNCTION_ARGS); + +extern Datum ts_match_vq(PG_FUNCTION_ARGS); +extern Datum ts_match_qv(PG_FUNCTION_ARGS); +extern Datum ts_match_tt(PG_FUNCTION_ARGS); +extern Datum ts_match_tq(PG_FUNCTION_ARGS); + +extern Datum ts_stat1(PG_FUNCTION_ARGS); +extern Datum ts_stat2(PG_FUNCTION_ARGS); + +extern Datum ts_rank_tt(PG_FUNCTION_ARGS); +extern Datum ts_rank_wtt(PG_FUNCTION_ARGS); +extern Datum ts_rank_ttf(PG_FUNCTION_ARGS); +extern Datum ts_rank_wttf(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_tt(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_wtt(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_ttf(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_wttf(PG_FUNCTION_ARGS); + +extern Datum tsmatchsel(PG_FUNCTION_ARGS); +extern Datum tsmatchjoinsel(PG_FUNCTION_ARGS); + +extern Datum ts_typanalyze(PG_FUNCTION_ARGS); + +/* + * TSQuery + */ +typedef int8 QueryItemType; + +/* Valid values for QueryItemType: */ +#define QI_VAL 1 +#define QI_OPR 2 +#define QI_VALSTOP \ + 3 /* This is only used in an intermediate stack \ + * representation in parse_tsquery. It's not a \ + * legal type elsewhere. */ +/* + * QueryItem is one node in tsquery - operator or operand. + */ +typedef struct { + QueryItemType type; /* operand or kind of operator (ts_tokentype) */ + uint8 weight; /* weights of operand to search. It's a + * bitmask of allowed weights. if it =0 then + * any weight are allowed. Weights and bit + * map: A: 1<<3 B: 1<<2 C: 1<<1 D: 1<<0 */ + bool prefix; /* true if it's a prefix search */ + int32 valcrc; /* XXX: pg_crc32 would be a more appropriate + * data type, but we use comparisons to signed + * integers in the code. They would need to be + * changed as well. */ + + /* pointer to text value of operand, must correlate with WordEntry */ + uint32 length : 12, distance : 20; +} QueryOperand; + +/* Legal values for QueryOperator.operator */ +#define OP_NOT 1 +#define OP_AND 2 +#define OP_OR 3 + +typedef struct { + QueryItemType type; + int8 oper; /* see above */ + uint32 left; /* pointer to left operand. Right operand is + * item + 1, left operand is placed + * item+item->left */ +} QueryOperator; + +/* + * Note: TSQuery is 4-bytes aligned, so make sure there's no fields + * inside QueryItem requiring 8-byte alignment, like int64. + */ +typedef union { + QueryItemType type; + QueryOperator qoperator; + QueryOperand qoperand; +} QueryItem; + +/* + * Storage: + * (len)(size)(array of QueryItem)(operands as '\0'-terminated c-strings) + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int4 size; /* number of QueryItems */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* data starts here */ +} TSQueryData; + +typedef TSQueryData* TSQuery; + +#define HDRSIZETQ (VARHDRSZ + sizeof(int4)) + +/* Computes the size of header and all QueryItems. size is the number of + * QueryItems, and lenofoperand is the total length of all operands + */ +#define COMPUTESIZE(size, lenofoperand) (HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand)) +#define TSQUERY_TOO_BIG(size, lenofoperand) \ + ((int)(size) > (int)((MaxAllocSize - HDRSIZETQ - (lenofoperand)) / sizeof(QueryItem))) + +/* Returns a pointer to the first QueryItem in a TSQuery */ +#define GETQUERY(x) ((QueryItem*)((char*)(x) + HDRSIZETQ)) + +/* Returns a pointer to the beginning of operands in a TSQuery */ +#define GETOPERAND(x) ((char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem)) + +/* + * fmgr interface macros + * Note, TSQuery type marked as plain storage, so it can't be toasted + * but PG_DETOAST_DATUM_COPY is used for simplicity + */ +#define DatumGetTSQuery(X) ((TSQuery)DatumGetPointer(X)) +#define DatumGetTSQueryCopy(X) ((TSQuery)PG_DETOAST_DATUM_COPY(X)) +#define TSQueryGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_TSQUERY(n) DatumGetTSQuery(PG_GETARG_DATUM(n)) +#define PG_GETARG_TSQUERY_COPY(n) DatumGetTSQueryCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_TSQUERY(x) return TSQueryGetDatum(x) + +/* + * I/O + */ +extern Datum tsqueryin(PG_FUNCTION_ARGS); +extern Datum tsqueryout(PG_FUNCTION_ARGS); +extern Datum tsquerysend(PG_FUNCTION_ARGS); +extern Datum tsqueryrecv(PG_FUNCTION_ARGS); + +/* + * operations with tsquery + */ +extern Datum tsquery_lt(PG_FUNCTION_ARGS); +extern Datum tsquery_le(PG_FUNCTION_ARGS); +extern Datum tsquery_eq(PG_FUNCTION_ARGS); +extern Datum tsquery_ne(PG_FUNCTION_ARGS); +extern Datum tsquery_ge(PG_FUNCTION_ARGS); +extern Datum tsquery_gt(PG_FUNCTION_ARGS); +extern Datum tsquery_cmp(PG_FUNCTION_ARGS); + +extern Datum tsquerytree(PG_FUNCTION_ARGS); +extern Datum tsquery_numnode(PG_FUNCTION_ARGS); + +extern Datum tsquery_and(PG_FUNCTION_ARGS); +extern Datum tsquery_or(PG_FUNCTION_ARGS); +extern Datum tsquery_not(PG_FUNCTION_ARGS); + +extern Datum tsquery_rewrite(PG_FUNCTION_ARGS); +extern Datum tsquery_rewrite_query(PG_FUNCTION_ARGS); + +extern Datum tsq_mcontains(PG_FUNCTION_ARGS); +extern Datum tsq_mcontained(PG_FUNCTION_ARGS); + +#endif /* _PG_TSTYPE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_utils.h postgresql-hll-2.14/include/include/tsearch/ts_utils.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_utils.h 2020-12-12 17:06:43.279348451 +0800 @@ -0,0 +1,261 @@ +/* ------------------------------------------------------------------------- + * + * ts_utils.h + * helper utilities for tsearch + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_utils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TS_UTILS_H_ +#define _PG_TS_UTILS_H_ + +#include "tsearch/ts_public.h" +#include "tsearch/ts_type.h" +#include "tsearch/ts_zh_ngram.h" +#include "tsearch/ts_zh_pound.h" +#include "nodes/pg_list.h" + +/* + * Common parse definitions for tsvector and tsquery + */ +/* tsvector parser support. */ +struct TSVectorParseStateData; /* opaque struct in tsvector_parser.c */ +typedef struct TSVectorParseStateData* TSVectorParseState; + +extern TSVectorParseState init_tsvector_parser(char* input, bool oprisdelim, bool is_tsquery); +extern void reset_tsvector_parser(TSVectorParseState state, char* input); +extern bool gettoken_tsvector( + TSVectorParseState state, char** token, int* len, WordEntryPos** pos, int* poslen, char** endptr); +extern void close_tsvector_parser(TSVectorParseState state); + +/* parse_tsquery */ +struct TSQueryParserStateData; /* private in backend/utils/adt/tsquery.c */ +typedef struct TSQueryParserStateData* TSQueryParserState; + +typedef void (*PushFunction)(Datum opaque, TSQueryParserState state, const char* token, int tokenlen, + int2 tokenweights, /* bitmap as described + * in QueryOperand + * struct */ + bool prefix); + +extern TSQuery parse_tsquery(char* buf, PushFunction pushval, Datum opaque, bool isplain); + +/* Functions for use by PushFunction implementations */ +extern void pushValue(TSQueryParserState state, const char* strval, int lenval, int2 weight, bool prefix); +extern void pushStop(TSQueryParserState state); +extern void pushOperator(TSQueryParserState state, int8 oper); + +/* + * parse plain text and lexize words + */ +typedef struct { + uint16 len; + uint16 nvariant; + union { + uint16 pos; + + /* + * When apos array is used, apos[0] is the number of elements in the + * array (excluding apos[0]), and alen is the allocated size of the + * array. + */ + uint16* apos; + } pos; + uint16 flags; /* currently, only TSL_PREFIX */ + char* word; + uint32 alen; +} ParsedWord; + +typedef struct { + ParsedWord* words; + int4 lenwords; + int4 curwords; + int4 pos; +} ParsedText; + +extern void parsetext(Oid cfgId, ParsedText* prs, const char* buf, int4 buflen); + +/* + * headline framework, flow in common to generate: + * 1 parse text with hlparsetext + * 2 parser-specific function to find part + * 3 generateHeadline to generate result text + */ +extern void hlparsetext(Oid cfgId, HeadlineParsedText* prs, TSQuery query, const char* buf, int4 buflen); +extern text* generateHeadline(HeadlineParsedText* prs); + +/* + * Common check function for tsvector @@ tsquery + */ +extern bool TS_execute( + QueryItem* curitem, void* checkval, bool calcnot, bool (*chkcond)(const void* checkval, QueryOperand* val)); +extern bool tsquery_requires_match(QueryItem* curitem); + +/* + * to_ts* - text transformation to tsvector, tsquery + */ +extern TSVector make_tsvector(ParsedText* prs); +extern int32 tsCompareString(const char* a, int lena, const char* b, int lenb, bool prefix); + +extern Datum to_tsvector_byid(PG_FUNCTION_ARGS); +extern Datum to_tsvector(PG_FUNCTION_ARGS); +extern Datum to_tsquery_byid(PG_FUNCTION_ARGS); +extern Datum to_tsquery(PG_FUNCTION_ARGS); +extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS); +extern Datum plainto_tsquery(PG_FUNCTION_ARGS); + +/* + * GiST support function + */ +extern Datum gtsvector_compress(PG_FUNCTION_ARGS); +extern Datum gtsvector_decompress(PG_FUNCTION_ARGS); +extern Datum gtsvector_consistent(PG_FUNCTION_ARGS); +extern Datum gtsvector_union(PG_FUNCTION_ARGS); +extern Datum gtsvector_same(PG_FUNCTION_ARGS); +extern Datum gtsvector_penalty(PG_FUNCTION_ARGS); +extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS); + +/* + * IO functions for pseudotype gtsvector + * used internally in tsvector GiST opclass + */ +extern Datum gtsvectorin(PG_FUNCTION_ARGS); +extern Datum gtsvectorout(PG_FUNCTION_ARGS); + +/* + * GIN support function + */ +extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS); +extern Datum gin_cmp_tslexeme(PG_FUNCTION_ARGS); +extern Datum gin_cmp_prefix(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsquery(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_consistent(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_triconsistent(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsvector_2args(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS); + +/* + * Possible strategy numbers for indexes + * TSearchStrategyNumber - (tsvector|text) @@ tsquery + * TSearchWithClassStrategyNumber - tsvector @@@ tsquery + */ +#define TSearchStrategyNumber 1 +#define TSearchWithClassStrategyNumber 2 + +/* + * TSQuery Utilities + */ +extern QueryItem* clean_NOT(QueryItem* ptr, int4* len); +extern QueryItem* clean_fakeval(QueryItem* ptr, int4* len); + +typedef struct QTNode { + QueryItem* valnode; + uint32 flags; + int4 nchild; + char* word; + uint32 sign; + struct QTNode** child; +} QTNode; + +/* bits in QTNode.flags */ +#define QTN_NEEDFREE 0x01 +#define QTN_NOCHANGE 0x02 +#define QTN_WORDFREE 0x04 + +typedef uint64 TSQuerySign; + +#define TSQS_SIGLEN (sizeof(TSQuerySign) * BITS_PER_BYTE) + +#define TSQuerySignGetDatum(X) Int64GetDatum((int64)(X)) +#define DatumGetTSQuerySign(X) ((TSQuerySign)DatumGetInt64(X)) +#define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X) +#define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n)) + +extern QTNode* QT2QTN(QueryItem* in, char* operand); +extern TSQuery QTN2QT(QTNode* in); +extern void QTNFree(QTNode* in); +extern void QTNSort(QTNode* in); +extern void QTNTernary(QTNode* in); +extern void QTNBinary(QTNode* in); +extern int QTNodeCompare(QTNode* an, QTNode* bn); +extern QTNode* QTNCopy(QTNode* in); +extern void QTNClearFlags(QTNode* in, uint32 flags); +extern bool QTNEq(QTNode* a, QTNode* b); +extern TSQuerySign makeTSQuerySign(TSQuery a); +extern QTNode* findsubquery(QTNode* root, QTNode* ex, QTNode* subs, bool* isfind); + +/* + * TSQuery GiST support + */ +extern Datum gtsquery_compress(PG_FUNCTION_ARGS); +extern Datum gtsquery_decompress(PG_FUNCTION_ARGS); +extern Datum gtsquery_consistent(PG_FUNCTION_ARGS); +extern Datum gtsquery_union(PG_FUNCTION_ARGS); +extern Datum gtsquery_same(PG_FUNCTION_ARGS); +extern Datum gtsquery_penalty(PG_FUNCTION_ARGS); +extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS); + +/* + * Parser interface to SQL + */ +extern Datum ts_token_type_byid(PG_FUNCTION_ARGS); +extern Datum ts_token_type_byname(PG_FUNCTION_ARGS); +extern Datum ts_parse_byid(PG_FUNCTION_ARGS); +extern Datum ts_parse_byname(PG_FUNCTION_ARGS); + +/* + * Default word parser + */ +extern Datum prsd_start(PG_FUNCTION_ARGS); +extern Datum prsd_nexttoken(PG_FUNCTION_ARGS); +extern Datum prsd_end(PG_FUNCTION_ARGS); +extern Datum prsd_headline(PG_FUNCTION_ARGS); +extern Datum prsd_lextype(PG_FUNCTION_ARGS); + +/* + * Dictionary interface to SQL + */ +extern Datum ts_lexize(PG_FUNCTION_ARGS); + +/* + * Simple built-in dictionary + */ +extern Datum dsimple_init(PG_FUNCTION_ARGS); +extern Datum dsimple_lexize(PG_FUNCTION_ARGS); + +/* + * Synonym built-in dictionary + */ +extern Datum dsynonym_init(PG_FUNCTION_ARGS); +extern Datum dsynonym_lexize(PG_FUNCTION_ARGS); + +/* + * ISpell dictionary + */ +extern Datum dispell_init(PG_FUNCTION_ARGS); +extern Datum dispell_lexize(PG_FUNCTION_ARGS); + +/* + * Thesaurus + */ +extern Datum thesaurus_init(PG_FUNCTION_ARGS); +extern Datum thesaurus_lexize(PG_FUNCTION_ARGS); + +/* + * headline + */ +extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS); +extern Datum ts_headline_byid(PG_FUNCTION_ARGS); +extern Datum ts_headline(PG_FUNCTION_ARGS); +extern Datum ts_headline_opt(PG_FUNCTION_ARGS); + +/* + * current cfg + */ +extern Datum get_current_ts_config(PG_FUNCTION_ARGS); + +#endif /* _PG_TS_UTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_zh_ngram.h postgresql-hll-2.14/include/include/tsearch/ts_zh_ngram.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_zh_ngram.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_zh_ngram.h 2020-12-12 17:06:43.279348451 +0800 @@ -0,0 +1,293 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_ngram.h + * N-gram algorithm functions for full-text search of Chinese + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_ngram.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TS_ZH_NGRAM_H +#define TS_ZH_NGRAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" +#include "mb/pg_wchar.h" + +#define MAX_CHAR_LEN 8 +#define MAX_CACHED_CHAR 256 + +typedef uint8 (*zhParser)(const char* ch, uint8* len); + +typedef struct { + zhParser parser; /* text search parser */ + char* str; /* text to parse */ + int len; /* text length */ + char* next; /* next char pointer */ + int post; /* position of parsed string */ + + char* cache; /* pointe to parsed but not returned token */ + int max_cached_num; /* cached char number */ + uint8* char_width; /* array record each char length */ + uint8* char_flag; /* array record each char type */ + int cached_size; /* already dealt bytes in cache */ + int cached_counter; /* already dealt chars in cache */ + bool cached; /* if cahced tokens */ + + char* token; /* token pointer to return */ + int char_size; /* bytes number to return */ + int char_counter; /* char number to return */ + int token_type; /* token type to renturn */ +} ZhParserState; + +/* char type defined for text search */ +#define CHAR_ILLEGALCHAR 0 +#define CHAR_ZHWORD 1 +#define CHAR_DIGHT 2 +#define CHAR_ENLETTER 3 +#define CHAR_BLANK 4 +#define CHAR_RADIXPOINT 5 +#define CHAR_PUNCTUATION 6 +#define CHAR_GRAPSYMBOL 7 + +/* Output token categories */ +#define ZHWORDS 1 +#define ENWORD 2 +#define NUMERIC 3 +#define ALNUM 4 +#define GRAPSYMBOL 5 +#define MULTISYMBOL 6 + +const char* const zh_tok_alias[] = {"", "zh_words", "en_word", "numeric", "alnum", "grapsymbol", "multisymbol"}; + +const char* const zh_lex_descr[] = { + "", "chinese words", "english word", "numeric data", "alnum string", "graphic symbol", "multiple symbol"}; + +extern uint8 ascii_matrix[8][16]; + +extern uint8 gbk_high_byte_matrix[8][16]; + +extern uint8 gbk_zh_word_matrix[3][16][16]; + +extern uint8 gbk_grap_symbol_matrix[10][16][16]; + +extern uint8 utf8_symbols_punctuation_matrix[4][16]; + +extern uint8 fullwidth_ascii_variants_matrix[4][4][16]; + +#define to_unsigned(ch) ((unsigned char)(*(ch))) +#define HFB(ch) ((to_unsigned(ch) & 0x00F0) >> 4) /* hight 4-bit value in a byte */ +#define LFB(ch) (to_unsigned(ch) & 0x0F) /* low 4-bit value in a byte */ + +/* maps to chinese word region if return true */ +#define GBK_ZH_REGION(L, R) (gbk_high_byte_matrix[L][R] & 0x0F) + +/* maps to graphic symbol region if return true */ +#define GBK_GP_REGION(L, R) ((gbk_high_byte_matrix[L][R] & 0x00F0) >> 4) + +/* + * @Description: map a dword char to char type + * + * @in ch: dword char + * @return: predefined char type + */ +inline uint8 gbk_dword_parser(const char* ch) +{ + uint8 HL = HFB(ch) & 0x07; /* (the fist byte's high-4-bit value) - 8 */ + uint8 HR = LFB(ch); /* fist byte's low-4-bit value */ + uint8 LL = HFB(ch + 1); /* second byte's high-4-bit value */ + uint8 LR = LFB(ch + 1); /* second byte's low-4-bit value */ + + if (likely(GBK_ZH_REGION(HL, HR))) /* in chinese word region */ + return gbk_zh_word_matrix[GBK_ZH_REGION(HL, HR)][LL][LR]; + + if (GBK_GP_REGION(HL, HR)) /* in graphic symbol region */ + return gbk_grap_symbol_matrix[GBK_GP_REGION(HL, HR)][LL][LR]; + + return CHAR_ILLEGALCHAR; +} + +/**************************** UTF-8 Encoding Info *****************************/ +/* + * Unicode 8.0 Character Code Charts + */ + +/* + * General Punctuation + * Unnicode Range: 2000 - 206F + * binary: (00100000 00000000 ~ 00100000 01101111) + * + * UTF8 Range: 0xE28080 - 0xE281AF + * binary: (11100010 10000000 10000000 ~ 11100010 10000001 10101111) + */ +#define GENERAL_PUNCTUATION_LOWER 0xE28080 +#define GENERAL_PUNCTUATION_UPPER 0xE281AF + +/* + * CJK Symbols and Punctuation + * Unnicode Range: 3000 - 303F + * binary: (00110000 00000000 ~ 0011 0000 00111111) + * + * UTF8 Range: 0xE38080 - 0xE380BF + * binary: (11100011 10000000 10000000 ~ 11100011 10000000 10111111) + * + * Last byte's range is 10 00 0000 ~ 10 11 1111 + */ +#define CJK_SYMBOLS_AND_PUNCTUATION_LOWER 0xE38080 +#define CJK_SYMBOLS_AND_PUNCTUATION_UPPER 0xE380BF + +#define UTF8_SYMBOLS_PUNCTUATION_REGION(ch) (utf8_symbols_punctuation_matrix[HFB(ch + 2) & 0x03][LFB(ch + 2)]) + +/* + * UTF8 Chinese word region description + * + * CJK Unified Ideographs (3 bytes) + * Unnicode Range: 4E00 - 9FD5 + * binary: (01001110 00000000 ~ 10011111 11010101) + * UTF8 Range: 0xE4B880 - 0xE9BF95 + * binary: (11100100 10111000 10000000 ~ 11101001 10111111 10010101) + * + * CJK Extension-A (3 bytes) + * Unnicode Range: 0x3400 - 0x4DB5 + * binary: (00110100 00000000 ~ 01001101 10110101) + * UTF8 Range: 0xE39080 - 0xE4B6B5 + * binary: (11100011 10010000 10000000 ~ 11100100 10110110 10110101) + * + * CJK Extension-B (4 bytes) + * Unnicode Range: 0x20000 - 0x2A6D6 + * binary: (00000010 00000000 00000000 ~ 00000010 10100110 11010110) + * UTF8 Range: 0xF0A08080 - 0xF0AA9B96 + * binary: (11110000 10100000 10000000 10000000 ~ 11110000 10101010 10011011 10010110) + */ +#define CJK_UNIFIED_IDEOGRAPHS_LOWER 0xE4B880 +#define CJK_UNIFIED_IDEOGRAPHS_UPPER 0xE9BF95 + +#define CJK_EXTENSION_A_LOWER 0xE39080 +#define CJK_EXTENSION_A_UPPER 0xE4B6B5 + +#define CJK_EXTENSION_B_LOWER 0xF0A08080 +#define CJK_EXTENSION_B_UPPER 0xF0AA9B96 + +/* + * + * Halfwidth and Fullwidth Forms description: + * Unnicode Range: FF00 - FFEF + * binary:(11111111 00000000 ~ 11111111 11101111) + * Fullwidth Dight:FF10-FF19 + * binary: (11111111 00010000 ~ 11111111 00011001) + * Fullwidth Uppercase:FF21-FF3A + * binary: (11111111 00100001 ~ 11111111 00111010) + * Fullwidth Lowercase:FF41-FF5A + * binary: (11111111 01000001 ~ 11111111 01011010) + * + * UTF8 Range: 0xEFBC80 - 0xEFBFAF + * binary: (11101111 10111100 10000000 ~ 11101111 10111111 10101111) + * Fullwidth Dight:0xEFBC90-0xEFBC99 + * binary: (11101111 10111100 10010000 ~ 11101111 10111100 10011001) + * Fullwidth Uppercase:0xEFBCA1-0xEFBCBA + * binary: (11101111 10111100 10100001 ~ 11101111 10111100 10111010) + * Fullwidth Lowercase:0xEFBE81-0xEFBD9A + * binary: (11101111 10111101 10000001 ~ 11101111 10111101 10011010) + * + * Last 2-byte's rang is 00 00 0000 ~ 11 10 1111 + * + */ +#define HALFWIDTH_AND_FULLWIDTH_FORMS_LOWER 0xEFBC80 +#define HALFWIDTH_AND_FULLWIDTH_FORMS_UPPER 0xEFBFAF + +#define UTF8_FULLWIDTH_ASCII_VARIANTS_REGION(ch) \ + fullwidth_ascii_variants_matrix[LFB(ch + 1) & 0x03][HFB(ch + 2) & 0x03][LFB(ch + 2)] + +#define utf8_len(value, mask, ch) (value == (mask & to_unsigned(ch))) +/* + * @Description: maps to char type for a UTF8 endcoding char + * + * @in ch: UTF8 endcoding char pointer to parser + * @out len: UTF8 char length + * @return: char type defined in front + */ +inline uint8 utf8_parser(const char* ch, uint8* len) +{ + if (likely(utf8_len(0xC0, 0xE0, ch))) { /* 2 byte */ + *len = 2; + return CHAR_GRAPSYMBOL; + } else if (likely(utf8_len(0xE0, 0xF0, ch))) { /* 3 byte */ + pg_wchar wchar = 0x00FFFFFF; + *len = 3; + wchar = wchar & ((to_unsigned(ch) << 16) | (to_unsigned(ch + 1) << 8) | to_unsigned(ch + 2)); + + if (unlikely(wchar < GENERAL_PUNCTUATION_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar < GENERAL_PUNCTUATION_UPPER)) { + return CHAR_PUNCTUATION; + } else if (unlikely(wchar < CJK_SYMBOLS_AND_PUNCTUATION_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_SYMBOLS_AND_PUNCTUATION_UPPER)) { /* in CJK Symbols and Punctuation Region */ + return UTF8_SYMBOLS_PUNCTUATION_REGION(ch); + } else if (unlikely(wchar < CJK_EXTENSION_A_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_EXTENSION_A_UPPER)) { /* in CJK Extension-A Region */ + return CHAR_ZHWORD; + } else if (unlikely(wchar < CJK_UNIFIED_IDEOGRAPHS_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_UNIFIED_IDEOGRAPHS_UPPER)) { /* in CJK Unified Ideographs Region */ + return CHAR_ZHWORD; + } else if (unlikely(wchar < HALFWIDTH_AND_FULLWIDTH_FORMS_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= HALFWIDTH_AND_FULLWIDTH_FORMS_UPPER)) { /* in Halfwidth and Fullwidth Forms region */ + return UTF8_FULLWIDTH_ASCII_VARIANTS_REGION(ch); + } else { + return CHAR_GRAPSYMBOL; + } + } else if (utf8_len(0xF0, 0xF8, ch)) { /* 4 byte */ + pg_wchar wchar = + ((to_unsigned(ch) << 24) | (to_unsigned(ch + 1) << 16) | (to_unsigned(ch + 2) << 8) | to_unsigned(ch + 3)); + *len = 4; + + if (unlikely(wchar < CJK_EXTENSION_B_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (wchar <= CJK_EXTENSION_B_UPPER) { + return CHAR_ZHWORD; + } else { + return CHAR_GRAPSYMBOL; + } +#ifdef NOT_USED + } else if (unlikely(utf8_len(0xF8, 0xFC, ch))) { /* 5 byte */ + *len = 5; + return CHAR_GRAPSYMBOL; + } else if (unlikely(utf8_len(0xFC, 0xFE, ch))) { /* 6 byte */ + *len = 6; + return CHAR_GRAPSYMBOL; +#endif + } else { + *len = 1; + return CHAR_GRAPSYMBOL; + } +} + +extern void zhParserStateInit(char* str, int len, ZhParserState* parserState); +extern void zhParserStateDestroy(ZhParserState* parserState); + +/* ngram parser functions for chinese */ +extern Datum ngram_start(PG_FUNCTION_ARGS); +extern Datum ngram_nexttoken(PG_FUNCTION_ARGS); +extern Datum ngram_end(PG_FUNCTION_ARGS); +extern Datum ngram_lextype(PG_FUNCTION_ARGS); + +#endif /* TS_ZH_NGRAM_H */ diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_zh_pound.h postgresql-hll-2.14/include/include/tsearch/ts_zh_pound.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_zh_pound.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_zh_pound.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_pound.h + * '#' split functions for full-text search of Chinese + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_pound.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TS_ZH_POUND_H +#define TS_ZH_POUND_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" + +/* pound parser functions for chinese */ +extern Datum pound_start(PG_FUNCTION_ARGS); +extern Datum pound_nexttoken(PG_FUNCTION_ARGS); +extern Datum pound_end(PG_FUNCTION_ARGS); +extern Datum pound_lextype(PG_FUNCTION_ARGS); + +#endif /* TS_ZH_POUND_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/tsearch/ts_zh_zhparser.h postgresql-hll-2.14/include/include/tsearch/ts_zh_zhparser.h --- postgresql-hll-2.14_old/include/include/tsearch/ts_zh_zhparser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/tsearch/ts_zh_zhparser.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,27 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_zhparser.h + * + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_zhparser.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ZHPARSER_H +#define ZHPARSER_H +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/acl.h postgresql-hll-2.14/include/include/utils/acl.h --- postgresql-hll-2.14_old/include/include/utils/acl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/acl.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,378 @@ +/* ------------------------------------------------------------------------- + * + * acl.h + * Definition of (and support for) access control list data structures. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/acl.h + * + * NOTES + * An ACL array is simply an array of AclItems, representing the union + * of the privileges represented by the individual items. A zero-length + * array represents "no privileges". There are no assumptions about the + * ordering of the items, but we do expect that there are no two entries + * in the array with the same grantor and grantee. + * + * For backward-compatibility purposes we have to allow null ACL entries + * in system catalogs. A null ACL will be treated as meaning "default + * protection" (i.e., whatever acldefault() returns). + * ------------------------------------------------------------------------- + */ +#ifndef ACL_H +#define ACL_H + +#include "nodes/parsenodes.h" +#include "utils/array.h" +#include "utils/guc.h" +#include "utils/snapshot.h" + +/* + * typedef AclMode is declared in parsenodes.h, also the individual privilege + * bit meanings are defined there + */ + +#define ACL_ID_PUBLIC 0 /* placeholder for id in a PUBLIC acl item */ + +/* + * AclItem + * + * Note: must be same size on all platforms, because the size is hardcoded + * in the pg_type.h entry for aclitem. + */ +typedef struct AclItem { + Oid ai_grantee; /* ID that this item grants privs to */ + Oid ai_grantor; /* grantor of privs */ + AclMode ai_privs; /* privilege bits */ +} AclItem; + +/* type of privileges */ +typedef enum { DML_PRIVS_INDEX = 0, DDL_PRIVS_INDEX } PRIVS_INDEX; +#define PRIVS_ATTR_NUM 2 + +/* + * The upper 16 bits of the ai_privs field of an AclItem are the grant option + * bits, and the lower 16 bits are the actual privileges. We use "rights" + * to mean the combined grant option and privilege bits fields. + */ +#define ACLITEM_GET_PRIVS(item) ((item).ai_privs & 0xFFFF) +#define ACLITEM_GET_GOPTIONS(item) (((item).ai_privs >> 16) & 0xFFFF) +#define ACLITEM_GET_RIGHTS(item) ((item).ai_privs) + +#define ACL_GRANT_OPTION_FOR(privs) (((AclMode)(privs)&0xFFFF) << 16) +#define ACL_OPTION_TO_PRIVS(privs) (((AclMode)(privs) >> 16) & 0xFFFF) + +#define ACLMODE_FOR_DDL(privs) (((privs) & FLAG_FOR_DDL_ACL) == 0 ? false : true) +/* remove ddl privileges flag from Aclitem */ +#define REMOVE_DDL_FLAG(privs) ((privs) & (~((AclMode)FLAG_FOR_DDL_ACL & 0xFFFF))) +/* add ddl privileges flag to Aclitem */ +#define ADD_DDL_FLAG(privs) ((privs) | ((AclMode)FLAG_FOR_DDL_ACL & 0xFFFF)) + +#define ACLITEM_SET_PRIVS(item, privs) \ + ((item).ai_privs = ((item).ai_privs & ~((AclMode)0xFFFF)) | ((AclMode)(privs)&0xFFFF)) +#define ACLITEM_SET_GOPTIONS(item, goptions) \ + ((item).ai_privs = ((item).ai_privs & ~(((AclMode)0xFFFF) << 16)) | (((AclMode)(goptions)&0xFFFF) << 16)) +#define ACLITEM_SET_RIGHTS(item, rights) ((item).ai_privs = (AclMode)(rights)) + +#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions) \ + ((item).ai_privs = ((AclMode)(privs)&0xFFFF) | (((AclMode)(goptions)&0xFFFF) << 16)) + +#define ACLITEM_ALL_PRIV_BITS ((AclMode)0xFFFF) +#define ACLITEM_ALL_GOPTION_BITS ((AclMode)0xFFFF << 16) + +/* + * Definitions for convenient access to Acl (array of AclItem). + * These are standard PostgreSQL arrays, but are restricted to have one + * dimension and no nulls. We also ignore the lower bound when reading, + * and set it to one when writing. + * + * CAUTION: as of PostgreSQL 7.1, these arrays are toastable (just like all + * other array types). Therefore, be careful to detoast them with the + * macros provided, unless you know for certain that a particular array + * can't have been toasted. + */ + +/* + * Acl a one-dimensional array of AclItem + */ +typedef ArrayType Acl; + +#define ACL_NUM(ACL) (ARR_DIMS(ACL)[0]) +#define ACL_DAT(ACL) ((AclItem*)ARR_DATA_PTR(ACL)) +#define ACL_N_SIZE(N) (ARR_OVERHEAD_NONULLS(1) + ((N) * sizeof(AclItem))) +#define ACL_SIZE(ACL) ARR_SIZE(ACL) + +/* + * fmgr macros for these types + */ +#define DatumGetAclItemP(X) ((AclItem*)DatumGetPointer(X)) +#define PG_GETARG_ACLITEM_P(n) DatumGetAclItemP(PG_GETARG_DATUM(n)) +#define PG_RETURN_ACLITEM_P(x) PG_RETURN_POINTER(x) + +#define DatumGetAclP(X) ((Acl*)PG_DETOAST_DATUM(X)) +#define DatumGetAclPCopy(X) ((Acl*)PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_ACL_P(n) DatumGetAclP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ACL_P_COPY(n) DatumGetAclPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_ACL_P(x) PG_RETURN_POINTER(x) + +/* + * ACL modification opcodes for aclupdate + */ +#define ACL_MODECHG_ADD 1 +#define ACL_MODECHG_DEL 2 +#define ACL_MODECHG_EQL 3 + +/* + * External representations of the privilege bits --- aclitemin/aclitemout + * represent each possible privilege bit with a distinct 1-character code + */ +#define ACL_INSERT_CHR 'a' /* formerly known as "append" */ +#define ACL_SELECT_CHR 'r' /* formerly known as "read" */ +#define ACL_UPDATE_CHR 'w' /* formerly known as "write" */ +#define ACL_DELETE_CHR 'd' +#define ACL_TRUNCATE_CHR 'D' /* super-delete, as it were */ +#define ACL_REFERENCES_CHR 'x' +#define ACL_TRIGGER_CHR 't' +#define ACL_EXECUTE_CHR 'X' +#define ACL_USAGE_CHR 'U' +#define ACL_CREATE_CHR 'C' +#define ACL_CREATE_TEMP_CHR 'T' +#define ACL_CONNECT_CHR 'c' +#define ACL_COMPUTE_CHR 'p' +#define ACL_READ_CHR 'R' +#define ACL_WRITE_CHR 'W' + +/* string holding all privilege code chars, in order by bitmask position */ +#define ACL_ALL_RIGHTS_STR "arwdDxtXUCTcpRW" + +/* + * Bitmasks defining "all rights" for each supported object type + */ +#define ACL_ALL_RIGHTS_COLUMN (ACL_INSERT | ACL_SELECT | ACL_UPDATE | ACL_REFERENCES) +#define ACL_ALL_RIGHTS_RELATION \ + (ACL_INSERT | ACL_SELECT | ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE | ACL_REFERENCES | ACL_TRIGGER) +#define ACL_ALL_RIGHTS_SEQUENCE (ACL_USAGE | ACL_SELECT | ACL_UPDATE) +#define ACL_ALL_RIGHTS_DATABASE (ACL_CREATE | ACL_CREATE_TEMP | ACL_CONNECT) +#define ACL_ALL_RIGHTS_FDW (ACL_USAGE) +#define ACL_ALL_RIGHTS_FOREIGN_SERVER (ACL_USAGE) +#define ACL_ALL_RIGHTS_FUNCTION (ACL_EXECUTE) +#define ACL_ALL_RIGHTS_LANGUAGE (ACL_USAGE) +#define ACL_ALL_RIGHTS_LARGEOBJECT (ACL_SELECT | ACL_UPDATE) +#define ACL_ALL_RIGHTS_NAMESPACE (ACL_USAGE | ACL_CREATE) +#define ACL_ALL_RIGHTS_NODEGROUP (ACL_CREATE | ACL_USAGE | ACL_COMPUTE) +#define ACL_ALL_RIGHTS_TABLESPACE (ACL_CREATE) +#define ACL_ALL_RIGHTS_TYPE (ACL_USAGE) +#define ACL_ALL_RIGHTS_DATA_SOURCE (ACL_USAGE) +#define ACL_ALL_RIGHTS_DIRECTORY (ACL_READ | ACL_WRITE) +#define ACL_ALL_RIGHTS_KEY (ACL_USAGE) + +/* External representations of the ddl privilege bits --- aclitemin/aclitemout */ +#define ACL_ALTER_CHR 'A' /* known as "modify" */ +#define ACL_DROP_CHR 'P' /* known as "remove" */ +#define ACL_COMMENT_CHR 'm' /* known as "statement" */ +#define ACL_INDEX_CHR 'i' +#define ACL_VACUUM_CHR 'v' + +/* string holding all ddl privilege code chars, in order by bitmask position */ +#define ACL_ALL_DDL_RIGHTS_STR "APmiv" + +/* Bitmasks defining "all ddl rights" for each supported object type */ +#define ACL_ALL_DDL_RIGHTS_COLUMN (ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_RELATION (ACL_ALTER | ACL_DROP | ACL_COMMENT | ACL_INDEX | ACL_VACUUM) +#define ACL_ALL_DDL_RIGHTS_SEQUENCE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_NODEGROUP (ACL_ALTER | ACL_DROP) +#define ACL_ALL_DDL_RIGHTS_DATABASE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_TABLESPACE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_NAMESPACE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FUNCTION (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_TYPE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FOREIGN_SERVER (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FDW (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DATA_SOURCE (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DIRECTORY (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_LARGEOBJECT (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_LANGUAGE (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DOMAIN (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_KEY (ACL_DROP) + +/* operation codes for pg_*_aclmask */ +typedef enum { + ACLMASK_ALL, /* normal case: compute all bits */ + ACLMASK_ANY /* return when result is known nonzero */ +} AclMaskHow; + +/* result codes for pg_*_aclcheck */ +typedef enum { ACLCHECK_OK = 0, ACLCHECK_NO_PRIV, ACLCHECK_NOT_OWNER } AclResult; + +typedef struct { + const char* name; + AclMode value; +} priv_map; + +/* this enum covers all object types that can have privilege errors */ +/* currently it's only used to tell aclcheck_error what to say */ +typedef enum AclObjectKind { + ACL_KIND_COLUMN, /* pg_attribute */ + ACL_KIND_CLASS, /* pg_class */ + ACL_KIND_SEQUENCE, /* pg_sequence */ + ACL_KIND_DATABASE, /* pg_database */ + ACL_KIND_PROC, /* pg_proc */ + ACL_KIND_OPER, /* pg_operator */ + ACL_KIND_TYPE, /* pg_type */ + ACL_KIND_LANGUAGE, /* pg_language */ + ACL_KIND_LARGEOBJECT, /* pg_largeobject */ + ACL_KIND_NAMESPACE, /* pg_namespace */ + ACL_KIND_NODEGROUP, /* pgxc_group */ + ACL_KIND_OPCLASS, /* pg_opclass */ + ACL_KIND_OPFAMILY, /* pg_opfamily */ + ACL_KIND_COLLATION, /* pg_collation */ + ACL_KIND_CONVERSION, /* pg_conversion */ + ACL_KIND_TABLESPACE, /* pg_tablespace */ + ACL_KIND_TSDICTIONARY, /* pg_ts_dict */ + ACL_KIND_TSCONFIGURATION, /* pg_ts_config */ + ACL_KIND_FDW, /* pg_foreign_data_wrapper */ + ACL_KIND_FOREIGN_SERVER, /* pg_foreign_server */ + ACL_KIND_EXTENSION, /* pg_extension */ + ACL_KIND_DATA_SOURCE, /* data source */ + ACL_KIND_DIRECTORY, /* pg_directory */ + ACL_KIND_COLUMN_SETTING, /* column setting */ + ACL_KIND_GLOBAL_SETTING, /* master client key */ + MAX_ACL_KIND /* MUST BE LAST */ +} AclObjectKind; + +/* + * routines used internally + */ +extern Acl* acldefault(GrantObjectType objtype, Oid ownerId, Oid objId = InvalidOid); +extern Acl* get_user_default_acl(GrantObjectType objtype, Oid ownerId, Oid nsp_oid); + +extern Acl* aclupdate(const Acl* old_acl, const AclItem* mod_aip, int modechg, Oid ownerId, DropBehavior behavior); +extern Acl* aclnewowner(const Acl* old_acl, Oid oldOwnerId, Oid newOwnerId); +extern Acl* make_empty_acl(void); +extern Acl* aclcopy(const Acl* orig_acl); +extern Acl* aclconcat(const Acl* left_acl, const Acl* right_acl); +extern Acl* aclmerge(const Acl* left_acl, const Acl* right_acl, Oid ownerId); +extern void aclitemsort(Acl* acl); +extern bool aclequal(const Acl* left_acl, const Acl* right_acl); + +extern AclMode aclmask(const Acl* acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how); +extern AclMode aclmask_dbe_perf(const Acl* acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how); +extern int aclmembers(const Acl* acl, Oid** roleids); + +extern bool has_privs_of_role(Oid member, Oid role); +extern bool is_member_of_role(Oid member, Oid role); +extern bool is_member_of_role_nosuper(Oid member, Oid role); +extern bool is_admin_of_role(Oid member, Oid role); +extern void check_is_member_of_role(Oid member, Oid role); +extern Oid get_role_oid(const char* rolname, bool missing_ok); + +extern void select_best_grantor( + Oid roleId, AclMode privileges, AclMode ddl_privileges, const Acl* acl, Oid ownerId, + Oid* grantorId, AclMode* grantOptions, AclMode* ddl_grantOptions, bool is_dbe_perf = false); + +extern void initialize_acl(void); + +/* + * SQL functions (from acl.c) + */ +extern Datum aclitemin(PG_FUNCTION_ARGS); +extern Datum aclitemout(PG_FUNCTION_ARGS); +extern Datum aclinsert(PG_FUNCTION_ARGS); +extern Datum aclremove(PG_FUNCTION_ARGS); +extern Datum aclcontains(PG_FUNCTION_ARGS); +extern Datum makeaclitem(PG_FUNCTION_ARGS); +extern Datum aclitem_eq(PG_FUNCTION_ARGS); +extern Datum hash_aclitem(PG_FUNCTION_ARGS); +extern Datum acldefault_sql(PG_FUNCTION_ARGS); +extern Datum aclexplode(PG_FUNCTION_ARGS); + +/* + * prototypes for functions in aclchk.c + */ +extern List* GrantStmtGetObjectOids(GrantStmt* stmt); +extern void ExecuteGrantStmt(GrantStmt* stmt); +extern void ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt* stmt); + +extern void RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid); +extern void RemoveDefaultACLById(Oid defaclOid); + +extern AclMode pg_attribute_aclmask(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_class_aclmask(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_database_aclmask(Oid db_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_directory_aclmask(Oid dir_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_proc_aclmask(Oid proc_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_language_aclmask(Oid lang_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_largeobject_aclmask_snapshot( + Oid lobj_oid, Oid roleid, AclMode mask, AclMaskHow how, Snapshot snapshot); +extern AclMode pg_namespace_aclmask(Oid nsp_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_nodegroup_aclmask(Oid group_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_tablespace_aclmask(Oid spc_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_foreign_data_wrapper_aclmask(Oid fdw_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_foreign_server_aclmask(Oid srv_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_extension_data_source_aclmask(Oid src_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_type_aclmask(Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode gs_sec_cmk_aclmask(Oid key_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode gs_sec_cek_aclmask(Oid key_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); + +extern AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode); +extern AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how); +extern AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode); +extern AclResult pg_directory_aclcheck(Oid dir_oid, Oid roleid, AclMode mode); +extern AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode); +extern AclResult pg_largeobject_aclcheck_snapshot(Oid lang_oid, Oid roleid, AclMode mode, Snapshot snapshot); +extern AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_nodegroup_aclcheck(Oid group_oid, Oid roleid, AclMode mode); +extern AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode); +extern AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode); +extern AclResult pg_foreign_server_aclcheck(Oid srv_oid, Oid roleid, AclMode mode); +extern AclResult pg_extension_data_source_aclcheck(Oid src_oid, Oid roleid, AclMode mode); +extern AclResult pg_type_aclcheck(Oid type_oid, Oid roleid, AclMode mode); +extern AclResult gs_sec_cmk_aclcheck(Oid key_oid, Oid roleid, AclMode mode, bool check_nodegroup = false); +extern AclResult gs_sec_cek_aclcheck(Oid key_oid, Oid roleid, AclMode mode, bool check_nodegroup = false); + +extern void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char* objectname); + +extern void aclcheck_error_col(AclResult aclerr, AclObjectKind objectkind, const char* objectname, const char* colname); + +extern void aclcheck_error_type(AclResult aclerr, Oid typeOid); + +/* ownercheck routines just return true (owner) or false (not) */ +extern bool pg_class_ownercheck(Oid class_oid, Oid roleid); +extern bool pg_type_ownercheck(Oid type_oid, Oid roleid); +extern bool pg_oper_ownercheck(Oid oper_oid, Oid roleid); +extern bool pg_proc_ownercheck(Oid proc_oid, Oid roleid); +extern bool pg_language_ownercheck(Oid lan_oid, Oid roleid); +extern bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid); +extern bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid); +extern bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid); +extern bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid); +extern bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid); +extern bool pg_database_ownercheck(Oid db_oid, Oid roleid); +extern bool pg_directory_ownercheck(Oid dir_oid, Oid roleid); +extern bool pg_collation_ownercheck(Oid coll_oid, Oid roleid); +extern bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid); +extern bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid); +extern bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid); +extern bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid); +extern bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid); +extern bool pg_extension_ownercheck(Oid ext_oid, Oid roleid); +extern bool gs_sec_cmk_ownercheck(Oid key_oid, Oid roleid); +extern bool gs_sec_cek_ownercheck(Oid key_oid, Oid roleid); +extern bool pg_extension_data_source_ownercheck(Oid src_oid, Oid roleid); +extern bool pg_synonym_ownercheck(Oid synOid, Oid roleId); +extern bool has_createrole_privilege(Oid roleid); +extern bool has_auditadmin_privilege(Oid roleid); +extern Acl* getAclNodeGroup(); +extern void grantNodeGroupToRole(Oid group_id, Oid roleid, AclMode privileges, bool is_grant); +extern void check_nodegroup_privilege(Oid roleid, Oid ownerId, AclMode mode); +extern Oid get_nodegroup_member_of(Oid roleid); +extern Oid get_nodegroup_privs_of(Oid roleid); +extern bool is_role_independent(Oid roleid); +extern bool is_role_iamauth(Oid roleid); +extern bool independent_priv_aclcheck(AclMode mask, char relkind); +extern bool is_trust_language(Oid lang_oid); +#endif /* ACL_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/aes.h postgresql-hll-2.14/include/include/utils/aes.h --- postgresql-hll-2.14_old/include/include/utils/aes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/aes.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aes.h + * AES encryption algorithm + * Interfaces of the AES encryption algorithm + * + * + * IDENTIFICATION + * src/include/utils/aes.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef AES_H +#define AES_H + +#include "c.h" +#include "cipher.h" + +#define MAX_DECRYPT_BUFF_LEN 1024 +#define AES_GROUP_LEN 16 +#define AES_MIX_LEN 4 +#define KEY_MAX_LEN 32 +#define KEY_LEN 16 + +#define AES_TRANSFORM_LEN 2 + +#define CleanupBuffer(buffer, bufflen) \ + do { \ + int rc = memset_s(buffer, bufflen, 0, bufflen); \ + securec_check_c(rc, "", ""); \ + } while (0) + +#define AES_OUTPUT_LEN(inputStrLen) \ + (((inputStrLen + AES_GROUP_LEN - 1) / AES_GROUP_LEN) * AES_GROUP_LEN * AES_TRANSFORM_LEN + 1) +#define AES_ENCRYPT_LEN(inputlen) \ + ((inputlen % AES_GROUP_LEN) ? ((inputlen / AES_GROUP_LEN) * AES_GROUP_LEN + AES_GROUP_LEN) : inputlen) + +typedef struct decrypt_struct { + unsigned char* decryptBuff; + + char currLine[MAX_DECRYPT_BUFF_LEN]; + unsigned char Key[KEY_MAX_LEN]; + bool isCurrLineProcess; + bool encryptInclude; + + /* Encrypt gs_dump file through OpenSSL function */ + bool randget; + unsigned char rand[RANDOM_LEN + 1]; +} DecryptInfo; + +extern void initDecryptInfo(DecryptInfo* pDecryptInfo); +extern char* getLineFromAesEncryptFile(FILE* source, DecryptInfo* pDecryptInfo); +extern bool writeFileAfterEncryption( + FILE* pf, char* inputstr, int inputstrlen, int writeBufflen, unsigned char Key[], unsigned char* rand); +extern bool check_key(const char* key, int NUM); +extern void aesEncrypt(char* inputstr, unsigned long inputstrlen, char* outputstr, unsigned char Key[]); +extern void aesDecrypt(char* inputstr, unsigned long inputstrlen, char* outputstr, unsigned char Key[], bool isBinary); +extern void init_aes_vector(GS_UCHAR* aes_vector); +extern bool init_aes_vector_random(GS_UCHAR* aes_vector, size_t vector_len); +extern bool aes128Encrypt(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UINT32 keylen, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern bool aes128EncryptSpeed(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern bool aes128Decrypt(GS_UCHAR* CipherText, GS_UINT32 CipherLen, GS_UCHAR* Key, GS_UINT32 keylen, + GS_UCHAR* RandSalt, GS_UCHAR* PlainText, GS_UINT32* PlainLen); +extern bool aes128DecryptSpeed(GS_UCHAR* CipherText, GS_UINT32 CipherLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* PlainText, GS_UINT32* PlainLen); +extern GS_UINT32 aes_ctr_enc_full_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, GS_UCHAR* key, GS_UCHAR* iv); +extern GS_UINT32 aes_ctr_dec_full_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, GS_UCHAR* key, GS_UCHAR* iv); + +#endif /* AES_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/aiomem.h postgresql-hll-2.14/include/include/utils/aiomem.h --- postgresql-hll-2.14_old/include/include/utils/aiomem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/aiomem.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aiomem.h + * memory function for adio + * + * + * IDENTIFICATION + * src/include/utils/aiomem.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _AIOMEM_H +#define _AIOMEM_H + +extern MemoryContext AdioSharedContext; +#define adio_share_alloc(buf_size) MemoryContextAlloc(AdioSharedContext, (buf_size)) +#define adio_share_free(ptr) pfree((ptr)) + +// /sys/block/sda/queue/logical_block_size +#define SYS_LOGICAL_BLOCK_SIZE (512) +#define adio_align_alloc(size) mem_align_alloc(SYS_LOGICAL_BLOCK_SIZE, size) +#define adio_align_free(ptr) mem_align_free(ptr) + +#endif /* _AIOMEM_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/anls_opt.h postgresql-hll-2.14/include/include/utils/anls_opt.h --- postgresql-hll-2.14_old/include/include/utils/anls_opt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/anls_opt.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * anls_opt.h + * analysis option information, used to show details in performance and + * context information check. + * + * + * IDENTIFICATION + * src/include/utils/anls_opt.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_ANLS_OPT_H +#define SRC_INCLUDE_UTILS_ANLS_OPT_H + +/* + * Add your analysis options as follows: + * 1. add your analysis option before ANLS_MAX in AnalysisOpt; + * 2. fill up anls_map[] about analysis option name, and keep their ordering; + * + */ +enum AnalysisOpt { + /* fastpath for all modules on/off */ + ANLS_ALL = 0, + + /* add your module id following */ + ANLS_LLVM_COMPILE, /* print LLVM compilation time */ + ANLS_HASH_CONFLICT, /* print length of hash link and hash confilct */ + ANLS_STREAM_DATA_CHECK, /* check buffer context after streaming */ + + /* add your analysis option above */ + ANLS_MAX +}; + +#define ANLS_OPT_IS_VALID(_id) ((_id) >= ANLS_ALL && (_id) < ANLS_MAX) +#define ALL_OPTIONS(_id) (ANLS_ALL == (_id)) + +/* 1 bit <--> 1 analysis option, including ANLS_MAX. its size is + * ((ANLS_MAX+1)+7)/8 = ANLS_MAX/8 + 1 + */ +#define ANLS_BEMD_BITMAP_SIZE (1 + (ANLS_MAX / 8)) + +/* max length of analysis option name */ +#define ANLS_OPT_NAME_MAXLEN (32) + +/* delimiter of dfx option list about GUC parameter */ +#define OPTION_DELIMITER ',' + +/* map about analysis option id and its name */ +typedef struct anls_opt_data { + AnalysisOpt anls_opt; + const char option_name[ANLS_OPT_NAME_MAXLEN]; +} dfx_option_data; + +/******************* analysis option id <--> analysis option name **********************/ +extern AnalysisOpt get_anls_opt_id(const char* dfx_name); + +/* Notice: + * declaration here only for the following inline functions, + * never use it within the other files directly. + */ +extern const anls_opt_data anls_map[]; + +/* + * @Description : find the analysis option name according to the option id. + * @in dfx_opt : analysis option id + * @return : analysis option name + */ +inline const char* get_valid_anls_opt_name(AnalysisOpt dfx_opt) +{ + return anls_map[dfx_opt].option_name; +} + +/******************* analysis options **********************/ +extern bool check_anls_opt_unique(void); +extern void anls_opt_batch_set(AnalysisOpt* options, int nopts, bool turn_on, bool apply_all_opts); +extern bool anls_opt_is_on(AnalysisOpt dfx_opt); + +#endif /* SRC_INCLUDE_UTILS_ANLS_OPT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/array.h postgresql-hll-2.14/include/include/utils/array.h --- postgresql-hll-2.14_old/include/include/utils/array.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/array.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * array.h + * Declarations for Postgres arrays. + * + * A standard varlena array has the following internal structure: + * - standard varlena header word + * - number of dimensions of the array + * - offset to stored data, or 0 if no nulls bitmap + * - element type OID + * - length of each array axis (C array of int) + * - lower boundary of each dimension (C array of int) + * - bitmap showing locations of nulls (OPTIONAL) + * - whatever is the stored data + * + * The and arrays each have ndim elements. + * + * The may be omitted if the array contains no NULL elements. + * If it is absent, the field is zero and the offset to the + * stored data must be computed on-the-fly. If the bitmap is present, + * is nonzero and is equal to the offset from the array start + * to the first data element (including any alignment padding). The bitmap + * follows the same conventions as tuple null bitmaps, ie, a 1 indicates + * a non-null entry and the LSB of each bitmap byte is used first. + * + * The actual data starts on a MAXALIGN boundary. Individual items in the + * array are aligned as specified by the array element type. They are + * stored in row-major order (last subscript varies most rapidly). + * + * NOTE: it is important that array elements of toastable datatypes NOT be + * toasted, since the tupletoaster won't know they are there. (We could + * support compressed toasted items; only out-of-line items are dangerous. + * However, it seems preferable to store such items uncompressed and allow + * the toaster to compress the whole array as one input.) + * + * + * The OIDVECTOR and INT2VECTOR datatypes are storage-compatible with + * generic arrays, but they support only one-dimensional arrays with no + * nulls (and no null bitmap). + * + * There are also some "fixed-length array" datatypes, such as NAME and + * POINT. These are simply a sequence of a fixed number of items each + * of a fixed-length datatype, with no overhead; the item size must be + * a multiple of its alignment requirement, because we do no padding. + * We support subscripting on these types, but array_in() and array_out() + * only work with varlena arrays. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/array.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ARRAY_H +#define ARRAY_H + +#include "fmgr.h" + +/* + * Arrays are varlena objects, so must meet the varlena convention that + * the first int32 of the object contains the total object size in bytes. + * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though! + * + * CAUTION: if you change the header for ordinary arrays you will also + * need to change the headers for oidvector and int2vector! + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int ndim; /* # of dimensions */ + int32 dataoffset; /* offset to data, or 0 if no bitmap */ + Oid elemtype; /* element type OID */ +} ArrayType; + +/* + * working state for accumArrayResult() and friends + */ +typedef struct ArrayBuildState { + MemoryContext mcontext; /* where all the temp stuff is kept */ + Datum* dvalues; /* array of accumulated Datums */ + bool* dnulls; /* array of is-null flags for Datums */ + int alen; /* allocated length of above arrays */ + int nelems; /* number of valid entries in above arrays */ + Oid element_type; /* data type of the Datums */ + int16 typlen; /* needed info about datatype */ + bool typbyval; + char typalign; +} ArrayBuildState; + +/* + * structure to cache type metadata needed for array manipulation + */ +typedef struct ArrayMetaState { + Oid element_type; + int16 typlen; + bool typbyval; + char typalign; + char typdelim; + Oid typioparam; + Oid typiofunc; + FmgrInfo proc; +} ArrayMetaState; + +/* + * private state needed by array_map (here because caller must provide it) + */ +typedef struct ArrayMapState { + ArrayMetaState inp_extra; + ArrayMetaState ret_extra; +} ArrayMapState; + +/* ArrayIteratorData is private in arrayfuncs.c */ +typedef struct ArrayIteratorData* ArrayIterator; + +/* + * fmgr macros for array objects + */ +#define DatumGetArrayTypeP(X) ((ArrayType*)PG_DETOAST_DATUM(X)) +#define DatumGetArrayTypePCopy(X) ((ArrayType*)PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x) + +/* + * Access macros for array header fields. + * + * ARR_DIMS returns a pointer to an array of array dimensions (number of + * elements along the various array axes). + * + * ARR_LBOUND returns a pointer to an array of array lower bounds. + * + * That is: if the third axis of an array has elements 5 through 8, then + * ARR_DIMS(a)[2] == 4 and ARR_LBOUND(a)[2] == 5. + * + * Unlike C, the default lower bound is 1. + */ +#define ARR_SIZE(a) VARSIZE(a) +#define ARR_NDIM(a) ((a)->ndim) +#define ARR_HASNULL(a) ((a)->dataoffset != 0) +#define ARR_ELEMTYPE(a) ((a)->elemtype) + +#define ARR_DIMS(a) ((int*)(((char*)(a)) + sizeof(ArrayType))) +#define ARR_LBOUND(a) ((int*)(((char*)(a)) + sizeof(ArrayType) + sizeof(int) * ARR_NDIM(a))) + +#define ARR_NULLBITMAP(a) \ + (ARR_HASNULL(a) ? (bits8*)(((char*)(a)) + sizeof(ArrayType) + 2 * sizeof(int) * ARR_NDIM(a)) : (bits8*)NULL) + +/* + * The total array header size (in bytes) for an array with the specified + * number of dimensions and total number of items. + */ +#define ARR_OVERHEAD_NONULLS(ndims) MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims)) +#define ARR_OVERHEAD_WITHNULLS(ndims, nitems) \ + MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims) + ((nitems) + 7) / 8) + +#define ARR_DATA_OFFSET(a) (ARR_HASNULL(a) ? (a)->dataoffset : ARR_OVERHEAD_NONULLS(ARR_NDIM(a))) + +/* + * Returns a pointer to the actual array data. + */ +#define ARR_DATA_PTR(a) (((char*)(a)) + ARR_DATA_OFFSET(a)) + +/* + * prototypes for functions defined in arrayfuncs.c + */ +extern Datum array_in(PG_FUNCTION_ARGS); +extern Datum array_out(PG_FUNCTION_ARGS); +extern Datum array_recv(PG_FUNCTION_ARGS); +extern Datum array_send(PG_FUNCTION_ARGS); +extern Datum array_eq(PG_FUNCTION_ARGS); +extern Datum array_ne(PG_FUNCTION_ARGS); +extern Datum array_lt(PG_FUNCTION_ARGS); +extern Datum array_gt(PG_FUNCTION_ARGS); +extern Datum array_le(PG_FUNCTION_ARGS); +extern Datum array_ge(PG_FUNCTION_ARGS); +extern Datum btarraycmp(PG_FUNCTION_ARGS); +extern Datum hash_array(PG_FUNCTION_ARGS); +extern Datum arrayoverlap(PG_FUNCTION_ARGS); +extern Datum arraycontains(PG_FUNCTION_ARGS); +extern Datum arraycontained(PG_FUNCTION_ARGS); +extern Datum array_ndims(PG_FUNCTION_ARGS); +extern Datum array_dims(PG_FUNCTION_ARGS); +extern Datum array_lower(PG_FUNCTION_ARGS); +extern Datum array_upper(PG_FUNCTION_ARGS); +extern Datum array_extend(PG_FUNCTION_ARGS); +extern Datum array_length(PG_FUNCTION_ARGS); +extern Datum array_larger(PG_FUNCTION_ARGS); +extern Datum array_smaller(PG_FUNCTION_ARGS); +extern Datum generate_subscripts(PG_FUNCTION_ARGS); +extern Datum generate_subscripts_nodir(PG_FUNCTION_ARGS); +extern Datum array_fill(PG_FUNCTION_ARGS); +extern Datum array_fill_with_lower_bounds(PG_FUNCTION_ARGS); +extern Datum array_unnest(PG_FUNCTION_ARGS); + +extern Datum array_ref(ArrayType* array, int nSubscripts, const int* indx, int arraytyplen, int elmlen, bool elmbyval, + char elmalign, bool* isNull); +extern ArrayType* array_set(ArrayType* array, int nSubscripts, const int* indx, Datum dataValue, bool isNull, + int arraytyplen, int elmlen, bool elmbyval, char elmalign); +extern ArrayType* array_get_slice(ArrayType* array, int nSubscripts, int* upperIndx, int* lowerIndx, int arraytyplen, + int elmlen, bool elmbyval, char elmalign); +extern ArrayType* array_set_slice(ArrayType* array, int nSubscripts, int* upperIndx, int* lowerIndx, + ArrayType* srcArray, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign); + +extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType, ArrayMapState* amstate); + +extern void array_bitmap_copy(bits8* destbitmap, int destoffset, const bits8* srcbitmap, int srcoffset, int nitems); +extern void CopyArrayEls(ArrayType* array, Datum* values, const bool* nulls, int nitems, int typlen, bool typbyval, + char typalign, bool freedata); + +extern ArrayType* construct_array(Datum* elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign); +extern ArrayType* construct_md_array(Datum* elems, bool* nulls, int ndims, int* dims, const int* lbs, Oid elmtype, + int elmlen, bool elmbyval, char elmalign); +extern ArrayType* construct_empty_array(Oid elmtype); +extern void deconstruct_array(ArrayType* array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum** elemsp, + bool** nullsp, int* nelemsp); +extern bool array_contains_nulls(ArrayType* array); +extern ArrayBuildState* accumArrayResult( + ArrayBuildState* astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext); +extern Datum makeArrayResult(ArrayBuildState* astate, MemoryContext rcontext); +extern Datum makeMdArrayResult( + ArrayBuildState* astate, int ndims, int* dims, int* lbs, MemoryContext rcontext, bool release); + +extern ArrayIterator array_create_iterator(ArrayType* arr, int slice_ndim); +extern bool array_iterate(ArrayIterator iterator, Datum* value, bool* isnull); +extern void array_free_iterator(ArrayIterator iterator); + +extern int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char* dest); + +/* + * prototypes for functions defined in arrayutils.c + */ +extern int ArrayGetOffset(int n, const int* dim, const int* lb, const int* indx); +extern int ArrayGetOffset0(int n, const int* tup, const int* scale); +extern int ArrayGetNItems(int ndim, const int* dims); +extern void mda_get_range(int n, int* span, const int* st, const int* endp); +extern void mda_get_prod(int n, const int* range, int* prod); +extern void mda_get_offset_values(int n, int* dist, const int* prod, const int* span); +extern int mda_next_tuple(int n, int* curr, const int* span); +extern int32* ArrayGetIntegerTypmods(ArrayType* arr, int* n); + +/* + * prototypes for functions defined in array_userfuncs.c + */ +extern Datum array_push(PG_FUNCTION_ARGS); +extern Datum array_cat(PG_FUNCTION_ARGS); + +extern ArrayType* create_singleton_array( + FunctionCallInfo fcinfo, Oid element_type, Datum element, bool isNull, int ndims); + +extern Datum array_agg_transfn(PG_FUNCTION_ARGS); +extern Datum array_agg_finalfn(PG_FUNCTION_ARGS); + +/* + * prototypes for functions defined in array_typanalyze.c + */ +extern Datum array_typanalyze(PG_FUNCTION_ARGS); +extern float8* check_float8_array(ArrayType* transarray, const char* caller, int n); + +#endif /* ARRAY_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/ascii.h postgresql-hll-2.14/include/include/utils/ascii.h --- postgresql-hll-2.14_old/include/include/utils/ascii.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/ascii.h 2020-12-12 17:06:43.280348464 +0800 @@ -0,0 +1,22 @@ +/* ----------------------------------------------------------------------- + * ascii.h + * + * Portions Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * src/include/utils/ascii.h + * + * ----------------------------------------------------------------------- + */ + +#ifndef _ASCII_H_ +#define _ASCII_H_ + +#include "fmgr.h" + +extern Datum to_ascii_encname(PG_FUNCTION_ARGS); +extern Datum to_ascii_enc(PG_FUNCTION_ARGS); +extern Datum to_ascii_default(PG_FUNCTION_ARGS); + +extern void ascii_safe_strlcpy(char* dest, const char* src, size_t destsiz); + +#endif /* _ASCII_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/aset.h postgresql-hll-2.14/include/include/utils/aset.h --- postgresql-hll-2.14_old/include/include/utils/aset.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/aset.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,228 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aset.h + * + * + * + * IDENTIFICATION + * src/include/utils/aset.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ASET_H_ +#define ASET_H_ +#include "postgres.h" +#include "utils/memutils.h" + +// GUC variables for uncontrolled_memory_context which limit memory alloctations. +typedef struct memory_context_list { + char* value; + struct memory_context_list* next; +} memory_context_list; + +/* + * list all templated value used by method function + */ +extern volatile ThreadId ReaperBackendPID; +typedef enum { IS_PROTECT = 0x0001, IS_SHARED = 0x0010, IS_TRACKED = 0x0100 } template_value; + +typedef enum { + MEM_THRD, + MEM_SESS, + MEM_SHRD, +} MemType; + +class GenericMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class AsanMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class AlignMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +// a stack-based memory allocator which +// 1) do not support single pointer free +// 2) more efficient than index-based memory allocator +// 3) do not contain header overhead. +class StackMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc( + _in_ MemoryContext context, _in_ Size align, _in_ Size size, _in_ const char* file, _in_ int line); + + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + static void* AllocSetRealloc(_in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, + _in_ const char* file, _in_ int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class MemoryProtectFunctions { +public: + template + static void* gs_memprot_malloc(Size sz, bool needProtect); + + template + static void gs_memprot_free(void* ptr, Size sz); + + template + static void* gs_memprot_realloc(void* ptr, Size sz, Size newsz, bool needProtect); + + template + static int gs_posix_memalign(void** memptr, Size alignment, Size sz, bool needProtect); +}; + +extern int alloc_trunk_size(int width); + +#endif /* ASET_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/atomic_arm.h postgresql-hll-2.14/include/include/utils/atomic_arm.h --- postgresql-hll-2.14_old/include/include/utils/atomic_arm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/atomic_arm.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,90 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * atomic_arm.h + * Assembly implementation of 128bit exclusive CAS and atomic operations + * leverage ARMv8.1-a large system extension(LSE), which is faster than + * legacy exclusive mode APIs of GNU Built-in functions. + * Create on: 2020-01-11 + * + * + * IDENTIFICATION + * src/include/utils/atomic_arm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ATOMIC_ARM_H +#define ATOMIC_ARM_H +#include "c.h" +#include "elog.h" + +#ifdef __aarch64__ + +/* + * Exclusive load/store 2 uint64_t variables to fullfil 128bit atomic compare and swap + * */ +static inline uint128_u __excl_compare_and_swap_u128(volatile uint128_u *ptr, uint128_u oldval, uint128_u newval) +{ + uint64_t tmp, ret; + uint128_u old; + asm volatile("1: ldxp %0, %1, %4\n" + " eor %2, %0, %5\n" + " eor %3, %1, %6\n" + " orr %2, %3, %2\n" + " cbnz %2, 2f\n" + " stlxp %w2, %7, %8, %4\n" + " cbnz %w2, 1b\n" + " b 3f\n" + "2:" + " stlxp %w2, %0, %1, %4\n" + " cbnz %w2, 1b\n" + "3:" + " dmb ish\n" + : "=&r"(old.u64[0]), "=&r"(old.u64[1]), "=&r"(ret), "=&r"(tmp), + "+Q"(ptr->u128) + : "r"(oldval.u64[0]), "r"(oldval.u64[1]), "r"(newval.u64[0]), "r"(newval.u64[1]) + : "memory"); + return old; +} + + +/* + * using CASP instinct to atomically compare and swap 2 uint64_t variables to fullfil + * 128bit atomic compare and swap + * */ +static inline uint128_u __lse_compare_and_swap_u128(volatile uint128_u *ptr, uint128_u oldval, uint128_u newval) +{ \ + uint128_u old; \ + register unsigned long x0 asm ("x0") = oldval.u64[0]; \ + register unsigned long x1 asm ("x1") = oldval.u64[1]; \ + register unsigned long x2 asm ("x2") = newval.u64[0]; \ + register unsigned long x3 asm ("x3") = newval.u64[1]; \ + \ + asm volatile(".arch_extension lse\n" \ + " caspal %[old_low], %[old_high], %[new_low], %[new_high], %[v]\n" \ + : [old_low] "+&r" (x0), [old_high] "+&r" (x1), \ + [v] "+Q" (*(ptr)) \ + : [new_low] "r" (x2), [new_high] "r" (x3) \ + : "x30", "memory"); \ + \ + old.u64[0] = x0; \ + old.u64[1] = x1; \ + return old; +} + +#endif /* __aarch64__ */ + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/atomic.h postgresql-hll-2.14/include/include/utils/atomic.h --- postgresql-hll-2.14_old/include/include/utils/atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/atomic.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,516 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * atomic.h + * + * IDENTIFICATION + * src/include/utils/atomic.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATOMIC_H +#define ATOMIC_H + +#include +#include "c.h" +#include "storage/barrier.h" +#include "utils/atomic_arm.h" + +typedef volatile uint32 pg_atomic_uint32; +typedef volatile uint64 pg_atomic_uint64; + +#ifndef WIN32 + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline int32 gs_atomic_add_32(volatile int32* ptr, int32 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the incremented value. + * @IN ptr: int64 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline int64 gs_atomic_add_64(int64* ptr, int64 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic set val into *ptr in a 32-bit address, and return the previous pointed by ptr + * @IN ptr: int32 pointer + * @IN val: value to set + * @Return: old value + * @See also: + */ +static inline int32 gs_lock_test_and_set(volatile int32* ptr, int32 val) +{ + return __sync_lock_test_and_set(ptr, val); +} + +/* + * @Description: Atomic set val into *ptr in a 32-bit address, and return the previous pointed by ptr + * @IN ptr: int64 pointer + * @IN val: value to set + * @Return: old value + * @See also: + */ +static inline int64 gs_lock_test_and_set_64(volatile int64* ptr, int64 val) +{ + return __sync_lock_test_and_set(ptr, val); +} + +/* + * @Description: Atomic compare and set val into *ptr in a 32-bit address, and return compare ok or not + * @IN ptr: int32 pointer + * @IN oldval: value to compare + * @IN newval: value to set + * @Return: true: dest is equal to the old value false: not equal + * @See also: + */ +static inline bool gs_compare_and_swap_32(int32* dest, int32 oldval, int32 newval) +{ + if (oldval == newval) + return true; + + volatile bool res = __sync_bool_compare_and_swap(dest, oldval, newval); + + return res; +} + +/* + * @Description: Atomic compare and set val into *ptr in a 64-bit address, and return compare ok or not + * @IN ptr: int64 pointer + * @IN oldval: value to compare + * @IN newval: value to set + * @Return: true: dest is equal to the old value false: not equal + * @See also: + */ +static inline bool gs_compare_and_swap_64(int64* dest, int64 oldval, int64 newval) +{ + if (oldval == newval) + return true; + + return __sync_bool_compare_and_swap(dest, oldval, newval); +} + +static inline uint32 gs_compare_and_swap_u32(volatile uint32* ptr, uint32 oldval, uint32 newval) +{ + return (uint32)__sync_val_compare_and_swap(ptr, oldval, newval); +} + +static inline uint64 gs_compare_and_swap_u64(volatile uint64* ptr, uint64 oldval, uint64 newval) +{ + return (uint64)__sync_val_compare_and_swap(ptr, oldval, newval); +} + +/* + * @Description: Atomic init in a 32-bit address. + * @IN ptr: int32 pointer + * @IN inc: int32 value + * @Return: void + * @See also: + */ +static inline void pg_atomic_init_u32(volatile uint32* ptr, uint32 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_read_u32(volatile uint32* ptr) +{ + return *ptr; +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_or_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_or(ptr, inc); +} + +/* + * @Description: Atomic and in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: and value + * @Return: oid value + * @See also: + */ +static inline uint32 pg_atomic_fetch_and_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_and(ptr, inc); +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_add_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_add(ptr, inc); +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_add_fetch_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic decrement in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: decrease value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_sub_u32(volatile uint32* ptr, int32 inc) +{ + return __sync_fetch_and_sub(ptr, inc); +} + +/* + * @Description: Atomic decrement in a 32-bit address, and return the decremented value. + * @IN ptr: int32 pointer + * @IN inc: decrease value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_sub_fetch_u32(volatile uint32* ptr, int32 inc) +{ + return __sync_fetch_and_sub(ptr, inc) - inc; +} + +/* + * @Description: Atomic change to given value newval in a 32-bit address, + * if *ptr is equal to *expected. + * @IN ptr: int32 pointer + * @IN expected: int32 pointer, expected value + * @IN newval: new value + * @Return: true if *ptr is equal to *expected. otherwise return false. + * @See also: + */ +static inline bool pg_atomic_compare_exchange_u32(volatile uint32* ptr, uint32* expected, uint32 newval) +{ + bool ret = false; + uint32 current; + current = __sync_val_compare_and_swap(ptr, *expected, newval); + ret = current == *expected; + *expected = current; + return ret; +} + +/* + * @Description: Atomic write in a 32-bit address. + * @IN ptr: int32 pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_u32(volatile uint32* ptr, uint32 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic change to the value newval in a 32-bit address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: int32 pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_exchange_u32(volatile uint32* ptr, uint32 newval) +{ + uint32 old; + while (true) { + old = pg_atomic_read_u32(ptr); + if (pg_atomic_compare_exchange_u32(ptr, &old, newval)) + break; + } + return old; +} + +/* + * @Description: Atomic init in a 64-bit address. + * @IN ptr: int64 pointer + * @IN inc: int64 value + * @Return: void + * @See also: + */ +static inline void pg_atomic_init_u64(volatile uint64* ptr, uint64 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic read in a 64-bit address, and return the int64 pointer. + * @IN ptr: int64 pointer + * @Return: int64 pointer + * @See also: + */ +static inline uint64 pg_atomic_read_u64(volatile uint64* ptr) +{ + return *ptr; +} + +/* + * @Description: Atomic or in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: or value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_or_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_or(ptr, inc); +} + +/* + * @Description: Atomic and in a 64-bit address, and return the old result. + * @IN ptr: int64 pointer + * @IN inc: and value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_and_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_and(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: incremented value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_add_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_add(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the incremented value. + * @IN ptr: int64 pointer + * @IN inc: incremented value + * @Return: new value + * @See also: + */ +static inline uint64 pg_atomic_add_fetch_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: delcrease value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_sub_u64(volatile uint64* ptr, int64 inc) +{ + return __sync_fetch_and_sub(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the decremented value. + * @IN ptr: int64 pointer + * @IN inc: decrease value + * @Return: new value + * @See also: + */ +static inline uint64 pg_atomic_sub_fetch_u64(volatile uint64* ptr, int64 inc) +{ + return __sync_fetch_and_sub(ptr, inc) - inc; +} + +/* + * @Description: Atomic change to the given value newval in a 64-bit address, + * if *ptr is equal to *expected. + * @IN ptr: int64 pointer + * @IN expected: int64 pointer, expected value + * @IN newval: new value + * @Return: true if *ptr is equal to *expected. otherwise return false. + * @See also: + */ +static inline bool pg_atomic_compare_exchange_u64(volatile uint64* ptr, uint64* expected, uint64 newval) +{ + bool ret = false; + uint64 current; + current = __sync_val_compare_and_swap(ptr, *expected, newval); + ret = current == *expected; + *expected = current; + return ret; +} + +/* + * @Description: Atomic write in a 34-bit address. + * @IN ptr: int64 pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_u64(volatile uint64* ptr, uint64 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic change to the value newval in a 64-bit address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: int64 pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_exchange_u64(volatile uint64* ptr, uint64 newval) +{ + uint64 old; + while (true) { + old = pg_atomic_read_u64(ptr); + if (pg_atomic_compare_exchange_u64(ptr, &old, newval)) + break; + } + return old; +} + +#ifdef __aarch64__ +/* + * This static function implements an atomic compare and exchange operation of + * 128bit width variable. This compares the contents of *ptr with the contents of + * *old and if equal, writes newval into *ptr. If they are not equal, the + * current contents of *ptr is written into *old. + * This API is an alternative implementation of __sync_val_compare_and_swap for + * 128bit on ARM64 platforms. + * + * @IN ptr: uint128_u pointer shold be 128bit(16bytes) aligned + * @IN oldval: old value, should be 128bit(16bytes) aligned. + * @IN newval: new value, should be 128bit(16bytes) aligned + * @Return: old value + */ +static inline uint128_u arm_compare_and_swap_u128(volatile uint128_u* ptr, uint128_u oldval, uint128_u newval) +{ +#ifdef __ARM_LSE + return __lse_compare_and_swap_u128(ptr, oldval, newval); +#else + return __excl_compare_and_swap_u128(ptr, oldval, newval); +#endif +} +#endif + +static inline void pg_atomic_init_uintptr(volatile uintptr_t* ptr, uintptr_t val) +{ + pg_atomic_init_u64(ptr, (uint64)val); +} + +static inline uintptr_t pg_atomic_read_uintptr(volatile uintptr_t* ptr) +{ + return (uintptr_t)pg_atomic_read_u64(ptr); +} + +static inline bool pg_atomic_compare_exchange_uintptr(volatile uintptr_t* ptr, uintptr_t* expected, uintptr_t newval) +{ + return pg_atomic_compare_exchange_u64(ptr, (uint64*)expected, (uint64)newval); +} + +/* + * @Description: Atomic write in a uintptr_t address. + * @IN ptr: uintptr_t pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_uintptr(volatile uintptr_t* ptr, uintptr_t val) +{ + pg_atomic_write_u64(ptr, (uint64)val); +} + +/* + * @Description: Atomic change to the value newval in a uintptr_t address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: uintptr_t pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uintptr_t pg_atomic_exchange_uintptr(volatile uintptr_t* ptr, uintptr_t newval) +{ + return (uintptr_t)pg_atomic_exchange_u64(ptr, (uint64)newval); +} + +/* + * @Description: Atomic load acquire the value in a uint64 address, + * @IN ptr: uint64 pointer + * @Return: the value of pointer + * @See also: + */ +static inline uint64 pg_atomic_barrier_read_u64(volatile uint64* ptr) +{ + return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); +} + +/* + * @Description This API is an unified wrapper of __sync_val_compare_and_swap for + * 128bit on ARM64 platforms and X86. + * + * @IN ptr: uint128_t pointer shold be 128bit(16bytes) aligned + * @IN oldval: old value, should be 128bit(16bytes) aligned. + * @IN newval: new value, should be 128bit(16bytes) aligned + * @Return: old value + */ +static inline uint128_u atomic_compare_and_swap_u128( + volatile uint128_u* ptr, + uint128_u oldval = uint128_u{0}, + uint128_u newval = uint128_u{0}) +{ +#ifdef __aarch64__ + return arm_compare_and_swap_u128(ptr, oldval, newval); +#else + uint128_u ret; + ret.u128 = __sync_val_compare_and_swap(&ptr->u128, oldval.u128, newval.u128); + return ret; +#endif +} +#endif + +#endif /* ATOMIC_H */ + diff -uprN postgresql-hll-2.14_old/include/include/utils/attoptcache.h postgresql-hll-2.14/include/include/utils/attoptcache.h --- postgresql-hll-2.14_old/include/include/utils/attoptcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/attoptcache.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * attoptcache.h + * Attribute options cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/attoptcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATTOPTCACHE_H +#define ATTOPTCACHE_H + +/* + * Attribute options. + */ +typedef struct AttributeOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ + float8 n_distinct; + float8 n_distinct_inherited; +} AttributeOpts; + +AttributeOpts* get_attribute_options(Oid spcid, int attnum); + +#endif /* ATTOPTCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/batchsort.h postgresql-hll-2.14/include/include/utils/batchsort.h --- postgresql-hll-2.14_old/include/include/utils/batchsort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/batchsort.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,574 @@ +/* --------------------------------------------------------------------------------------- + * + * batchsort.h + * Generalized tuple sorting routines. + * + * This module handles sorting of heap tuples, index tuples, or single + * Datums (and could easily support other kinds of sortable objects, + * if necessary). It works efficiently for both small and large amounts + * of data. Small amounts are sorted in-memory using qsort(). Large + * amounts are sorted using temporary files and a standard external sort + * algorithm. + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/batchsort.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BATCHSORT_H +#define BATCHSORT_H + +#include "access/itup.h" +#include "executor/tuptable.h" +#include "fmgr.h" +#ifdef PGXC +#include "pgxc/execRemote.h" +#include "vecexecutor/vecnodes.h" +#endif +#include "utils/elog.h" +#include "utils/relcache.h" +#include "vecexecutor/vecstore.h" +#include "utils/logtape.h" +#include "utils/pg_rusage.h" + +extern THR_LOCAL int vsort_mem; +extern const int MINORDER; + +/* + * Possible states of a BatchSort object. + */ +typedef enum { + BS_INITIAL = 0, + BS_BOUNDED, + BS_BUILDRUNS, + BS_SORTEDINMEM, + BS_SORTEDONTAPE, + BS_FINALMERGE +} BatchSortStatus; + +/* + * Private state of a batchsort operation. + */ +class Batchsortstate : public VecStore { +public: + // Memory context for main allocation + MemoryContext sortcontext; + + /* + * enumerated value as shown above + */ + BatchSortStatus m_status; + +#ifdef PGXC + RemoteQueryState* combiner; + VectorBatch** m_connDNBatch; + + int* m_datanodeFetchCursor; + + // merge sort + VecStreamState* streamstate; +#endif + /* + * number of columns in sort key + */ + int m_nKeys; + + /* + * Scan keys + */ + ScanKey m_scanKeys; + + /* + * The sortKeys variable is used by every case other than the hash index + * case; it is set by tuplesort_begin_xxx. + */ + SortSupport sortKeys; /* array of length nKeys */ + + /* + * Additional state for managing "abbreviated key" sortsupport routines + * (which currently may be used by all cases except the hash index case). + * Tracks the intervals at which the optimization's effectiveness is + * tested. + */ + int64 abbrevNext; /* Tuple # at which to next check + * applicability */ + + /* + * did caller request random access? + */ + bool m_randomAccess; + + /* + * did caller specify a maximum number of tuples to return + */ + bool m_bounded; + + /* + * Top N sort + */ + bool m_boundUsed; + + /* + * if bounded, the maximum number of tuples + */ + int m_bound; + + MultiColumnsData m_unsortColumns; + + bool* m_isSortKey; + + long m_lastBlock; + + int m_lastOffset; + + /* + * variables which relate to external sort + */ + int m_maxTapes; + + int m_tapeRange; + + LogicalTapeSet* m_tapeset; + + /* + * While building initial runs, this is the current output run number + * (starting at 0). Afterwards, it is the number of initial runs we made. + */ + int m_curRun; + + /* + * Unless otherwise noted, all pointer variables below are pointers to + * arrays of length maxTapes, holding per-tape data. + */ + + /* + * These variables are only used during merge passes. mergeactive[i] is + * true if we are reading an input run from (actual) tape number i and + * have not yet exhausted that run. mergenext[i] is the memtuples index + * of the next pre-read tuple (next to be loaded into the heap) for tape + * i, or 0 if we are out of pre-read tuples. mergelast[i] similarly + * points to the last pre-read tuple from each tape. mergeavailslots[i] + * is the number of unused memtuples[] slots reserved for tape i, and + * mergeavailmem[i] is the amount of unused space allocated for tape i. + * mergefreelist and mergefirstfree keep track of unused locations in the + * memtuples[] array. The memtuples[].tupindex fields link together + * pre-read tuples for each tape as well as recycled locations in + * mergefreelist. It is OK to use 0 as a null link in these lists, because + * memtuples[0] is part of the merge heap and is never a pre-read tuple. + */ + bool* m_mergeActive; /* active input run source? */ + int* m_mergeNext; /* first preread tuple for each source */ + int* m_mergeLast; /* last preread tuple for each source */ + int* m_mergeAvailslots; /* slots left for prereading each tape */ + long* m_mergeAvailmem; /* availMem for prereading each tape */ + int m_mergeFreeList; /* head of freelist of recycled slots */ + int m_mergeFirstFree; /* first slot never used in this merge */ + + /* + * Variables for Algorithm D. Note that destTape is a "logical" tape + * number, ie, an index into the tp_xxx[] arrays. Be careful to keep + * "logical" and "actual" tape numbers straight! + */ + int m_level; /* Knuth's l */ + int m_destTape; /* current output tape (Knuth's j, less 1) */ + int* m_tpFib; /* Target Fibonacci run counts (A[]) */ + int* m_tpRuns; /* # of real runs on each tape */ + int* m_tpDummy; /* # of dummy runs for each tape (D[]) */ + int* m_tpNum; /* Actual tape numbers (TAPE[]) */ + int m_activeTapes; /* # of active input tapes in merge pass */ + + /* + * These variables are used after completion of sorting to keep track of + * the next tuple to return. (In the tape case, the tape's current read + * position is also critical state.) + */ + int m_resultTape; /* actual tape number of finished output */ + bool m_eofReached; /* reached EOF (needed for cursors) */ + + /* markpos_xxx holds marked position for mark and restore */ + long m_markposBlock; /* tape block# (only used if SORTEDONTAPE) */ + int m_markposOffset; /* saved "current", or offset in tape block */ + bool m_markposEof; /* saved "eof_reached" */ + long m_lastFileBlocks; /* last file blocks used in underlying file */ + + int64 peakMemorySize; /* memory size before writeMultiColumn*/ + + // Resource snapshot for time of sort start. + // +#ifdef TRACE_SORT + PGRUsage m_ruStart; +#endif + + char* jitted_CompareMultiColumn; /* jitted function for CompareMultiColumn */ + char* jitted_CompareMultiColumn_TOPN; /* jitted function for CompareMultiColumn used by Top N sort */ + + /* + * Initialize variables. + */ + + void InitCommon(int64 workMem, bool randomAccess); + + /* + * Based on hyper log log estimation, consider wheather exit abbreviate + * mode or not. + */ + bool ConsiderAbortCommon(); + + void SortInMem(); + + int GetSortMergeOrder(); + + void InitTapes(); + + void DumpMultiColumn(bool all); + + int HeapCompare(MultiColumns* a, MultiColumns* b, bool checkIdx); + + template + int THeapCompare(MultiColumns* a, MultiColumns* b); + + template + void BatchSortHeapInsert(MultiColumns* multiColumn, int multiColumnIdx); + + template + void BatchSortHeapSiftup(); + + void MarkRunEnd(int tapenum); + + void SelectNewTape(); + + void MergeRuns(); + + void BeginMerge(); + + void MergeOneRun(); + + void MergePreReadDone(int srcTape); + + void MergePreRead(); + void GetBatch(bool forward, VectorBatch* batch); + + void (Batchsortstate::*m_getBatchFun)(bool forward, VectorBatch* batch); + + void GetBatchInMemory(bool forward, VectorBatch* batch); + + void GetBatchDisk(bool forward, VectorBatch* batch); + + void GetBatchFinalMerge(bool forward, VectorBatch* batch); + + void BindingGetBatchFun(); + + inline void ReverseDirectionHeap(); + + void MakeBoundedHeap(); + + void SortBoundedHeap(); + + void DumpUnsortColumns(bool all); + + /* + * These function pointers decouple the routines that must know what kind + * of tuple we are sorting from the routines that don't need to know it. + * They are set up by the tuplesort_begin_xxx routines. + * + * Function to compare two tuples; result is per qsort() convention, ie: + * <0, 0, >0 according as ab. The API must match + * qsort_arg_comparator. + */ + int (*compareMultiColumn)(const MultiColumns* a, const MultiColumns* b, Batchsortstate* state); + + /* + * Function to copy a supplied input tuple into palloc'd space and set up + * its SortTuple representation (ie, set tuple/datum1/isnull1). Also, + * state->availMem must be decreased by the amount of space used for the + * tuple copy (note the SortTuple struct itself is not counted). + */ + void (*copyMultiColumn)(Batchsortstate* state, MultiColumns* stup, void* tup); + + /* + * Function to write a stored tuple onto tape. The representation of the + * tuple on tape need not be the same as it is in memory; requirements on + * the tape representation are given below. After writing the tuple, + * pfree() the out-of-line data (not the SortTuple struct!), and increase + * state->availMem by the amount of memory space thereby released. + */ + void (*writeMultiColumn)(Batchsortstate* state, int tapenum, MultiColumns* stup); + + /* + * Function to read a stored tuple from tape back into memory. 'len' is + * the already-read length of the stored tuple. Create a palloc'd copy, + * initialize tuple/datum1/isnull1 in the target SortTuple struct, and + * decrease state->availMem by the amount of memory space consumed. + */ + void (*readMultiColumn)(Batchsortstate* state, MultiColumns& stup, int tapenum, unsigned int len); + +#ifdef PGXC + /* + * Function to read length of next stored tuple. + * Used as 'len' parameter for readtup function. + */ + unsigned int (*getlen)(Batchsortstate* state, int tapenum, bool eofOK); +#endif + + /* + * Function to reverse the sort direction from its current state. (We + * could dispense with this if we wanted to enforce that all variants + * represent the sort key information alike.) + */ + void (*reversedirection)(Batchsortstate* state); + + /* + * Function to accept one batch while collecting input data for sort. + * Note that the input data is always copied; the caller need not save it. + * + * We choose batchsort_putbatch for normal case, choose + * batchsort_putbatch for fast abbreviate comparison function for sort. + * So we need to implement different function of batchsort_putbatch. + */ + void (*sort_putbatch)(Batchsortstate* state, VectorBatch* batch, int start, int end); +}; + +extern Batchsortstate* batchsort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, int64 workMem, bool randomAccess, int64 maxMem = 0, + int planId = 0, int dop = 1); +#ifdef PGXC +extern Batchsortstate* batchsort_begin_merge(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, void* combiner, int64 workMem); +#endif + +extern void batchsort_set_bound(Batchsortstate* state, int64 bound); + +/* + * abbreSortOptimize used to mark whether allocate one more Datum for + * fast compare of two data(text or numeric type) + */ +template +void putbatch(Batchsortstate* state, VectorBatch* batch, int start, int end) +{ + int64 memorySize = 0; + for (int row = start; row < end; ++row) { + MultiColumns multiColumn = state->CopyMultiColumn(batch, row); + + if (abbrevSortOptimize) { + if (state->sortKeys->abbrev_converter && !IS_NULL(multiColumn.m_nulls[state->sortKeys->ssup_attno - 1]) && + !state->ConsiderAbortCommon()) + /* Store abbreviated key representation */ + multiColumn.m_values[batch->m_cols] = state->sortKeys->abbrev_converter( + multiColumn.m_values[state->sortKeys->ssup_attno - 1], state->sortKeys); + else + multiColumn.m_values[batch->m_cols] = multiColumn.m_values[state->sortKeys->ssup_attno - 1]; + } + + switch (state->m_status) { + case BS_INITIAL: + + if ((!state->HasFreeSlot() || state->m_availMem <= 0) && + state->m_storeColumns.m_memRowNum >= MINORDER * 2) { + /* if mem is used up, then adjust capacity */ + if (state->m_availMem <= 0) + state->m_storeColumns.m_capacity = state->m_storeColumns.m_memRowNum + 1; + state->GrowMemValueSlots("VecSort", state->m_planId, state->sortcontext); + } + state->PutValue(multiColumn); + + /* + * Check if it's time to switch over to a bounded heapsort. We do + * so if the input tuple count exceeds twice the desired tuple + * count (this is a heuristic for where heapsort becomes cheaper + * than a quicksort), or if we've just filled workMem and have + * enough tuples to meet the bound. + * + * Note that once we enter TSS_BOUNDED state we will always try to + * complete the sort that way. In the worst case, if later input + * tuples are larger than earlier ones, this might cause us to + * exceed workMem significantly. + */ + if (state->m_bounded && (state->m_storeColumns.m_memRowNum > state->m_bound * 2 || + (state->m_storeColumns.m_memRowNum > state->m_bound && state->LackMem()))) { +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) { + elog(LOG, + "switching to bounded heapsort at %d tuples: %s", + state->m_storeColumns.m_memRowNum, + pg_rusage_show(&state->m_ruStart)); + } +#endif + if (state->m_storeColumns.m_memRowNum > 0) { + state->m_colWidth /= state->m_storeColumns.m_memRowNum; + state->m_addWidth = false; + } + state->MakeBoundedHeap(); + continue; + } + + /* + * Once we do not have enough memory, we will turn to external sort. But before we do + * InitTapes, we should have at least MINORDER * 2 MultiColumns in MultiColumnsData. + * Since the minimal number of tapes we need in external sort is MINORDER. + */ + while (state->LackMem() && (state->m_storeColumns.m_memRowNum < MINORDER * 2)) { + state->m_availMem += state->m_allowedMem; + } + + /* + * Done if we still fit in available memory and have at least MINORDER * 2 array slots. + */ + if ((state->m_storeColumns.m_memRowNum < state->m_storeColumns.m_capacity && !state->LackMem()) || + state->m_storeColumns.m_memRowNum < MINORDER * 2) + continue; + + if (state->m_storeColumns.m_memRowNum > 0) { + state->m_colWidth /= state->m_storeColumns.m_memRowNum; + state->m_addWidth = false; + } + + if (state->LackMem()) { + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling Warning: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); + } + + state->InitTapes(); + + /* + * Cache memory size info Batchsortstate before write to tapes. + * If the memory size has been cached during previous dump, + * do not update the size with current context size. + * note: state->peakMemorySize is only used to log memory size before dump for now. + * Keep caution once it is adopted for other cases in the future.. + */ + if (state->peakMemorySize <= 0) { + memorySize = 0; + CalculateContextSize(state->sortcontext, &memorySize); + state->peakMemorySize = memorySize; + } + +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling LOG: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); +#endif + + state->m_storeColumns.m_capacity = state->m_storeColumns.m_memRowNum; + + /* + * If we are over the memory limit, dump tuples till we're under. + */ + state->DumpMultiColumn(false); + +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling LOG: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); +#endif + + break; + + case BS_BOUNDED: + + if (state->compareMultiColumn(&multiColumn, state->m_storeColumns.m_memValues, state) <= 0) { + state->FreeMultiColumn(&multiColumn); + } else { + state->FreeMultiColumn(state->m_storeColumns.m_memValues); + state->BatchSortHeapSiftup(); + state->BatchSortHeapInsert(&multiColumn, 0); + } + break; + + case BS_BUILDRUNS: + + if (state->compareMultiColumn(&multiColumn, &state->m_storeColumns.m_memValues[0], state) >= 0) { + state->BatchSortHeapInsert(&multiColumn, state->m_curRun); + } else { + state->BatchSortHeapInsert(&multiColumn, state->m_curRun + 1); + } + + /* + * If we are over the memory limit, dump tuples till we're under. + */ + state->DumpMultiColumn(false); + + break; + + default: + elog(ERROR, "invalid BatchSort state"); + break; + } + } +} + +/* + * Accept one tuple while collecting input data for sort. + * Note that the input data is always copied; the caller need not save it. + * + * When the first column of order_by_columns is text or numeric type, we + * use bttextcmp_abbrev or numeric_cmp_abbrev to speed up compare operation, + * meanwhile we need to allocate one more Datum to store prefix info, so + * set abbreSortOptimize to be true. For other case set abbreSortOptimize + * to be false. + */ +template +void batchsort_putbatch(Batchsortstate* state, VectorBatch* batch, int start, int end) +{ + MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext); + + /* + * it is only initialized once. + */ + if (!state->m_colInfo) { + state->InitColInfo(batch); + } + + putbatch(state, batch, start, end); + + MemoryContextSwitchTo(oldcontext); +} + +extern void batchsort_performsort(Batchsortstate* state); + +extern void batchsort_getbatch(Batchsortstate* state, bool forward, VectorBatch* batch); + +extern void batchsort_end(Batchsortstate* state); + +extern void batchsort_get_stats(Batchsortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +/* + * These routines may only be called if randomAccess was specified 'true'. + * Likewise, backwards scan in gettuple/getdatum is only allowed if + * randomAccess was specified. + */ + +extern void batchsort_rescan(Batchsortstate* state); + +extern void batchsort_markpos(Batchsortstate* state); +extern void batchsort_restorepos(Batchsortstate* state); + +extern void batchsort_get_stats(Batchsortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +#endif /* BATCHSORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/batchstore.h postgresql-hll-2.14/include/include/utils/batchstore.h --- postgresql-hll-2.14_old/include/include/utils/batchstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/batchstore.h 2020-12-12 17:06:43.281348477 +0800 @@ -0,0 +1,184 @@ +/* --------------------------------------------------------------------------------------- + * + * batchstore.h + * Generalized routines for temporary tuple storage. + * + * This module handles temporary storage of tuples for purposes such + * as Materialize nodes, hashjoin batch files, etc. It is essentially + * a dumbed-down version of tuplesort.c; it does no sorting of tuples + * but can only store and regurgitate a sequence of tuples. However, + * because no sort is required, it is allowed to start reading the sequence + * before it has all been written. This is particularly useful for cursors, + * because it allows random access within the already-scanned portion of + * a query without having to process the underlying scan to completion. + * Also, it is possible to support multiple independent read pointers. + * + * A temporary file is used to handle the data if it exceeds the + * space limit specified by the caller. + * + * Beginning in Postgres 8.2, what is stored is just MinimalTuples; + * callers cannot expect valid system columns in regurgitated tuples. + * Also, we have changed the API to return tuples in TupleTableSlots, + * so that there is a check to prevent attempted access to system columns. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/batchstore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BATCHSTORE_H +#define BATCHSTORE_H + +#include "executor/tuptable.h" +#include "vecexecutor/vecstore.h" + +/* BatchStore is an opaque type whose details are not known outside + * batchstore.cpp. + */ + +/* + * Possible states of a Tuplestore object. These denote the states that + * persist between calls of Tuplestore routines. + */ +typedef enum { + BSS_INMEM, /* batch still fit in memory */ + BSS_WRITEFILE, /* Writing to temp file */ + BSS_READFILE /* Reading from temp file */ +} BatchStoreStatus; + +/* + * State for a single read pointer. If we are in state INMEM then all the + * read pointers' "current" fields denote the read positions. In state + * WRITEFILE, the file/offset fields denote the read positions. In state + * READFILE, inactive read pointers have valid file/offset, but the active + * read pointer implicitly has position equal to the temp file's seek position. + * + * Special case: if eof_reached is true, then the pointer's read position is + * implicitly equal to the write position, and current/file/offset aren't + * maintained. This way we need not update all the read pointers each time + * we write. + */ +typedef struct BSReadPointer { + int eflags; /* capability flags */ + bool eof_reached; /* read has reached EOF */ + int file; /* temp file# */ + off_t offset; /* byte offset in file */ +} BSReadPointer; + +class BatchStore : public VecStore { + +public: + // Memory context for main allocation + MemoryContext m_storecontext; + + /* + * enumerated value as shown above + */ + BatchStoreStatus m_status; + bool m_backward; /* store extra length words in file? */ + int m_eflags; /* capability flags (OR of pointers' flags) */ + + /* + * remaining memory allowed, in bytes + */ + int m_memtupdeleted; + + BufFile* m_myfile; /* underlying file, or NULL if none */ + + ResourceOwner m_resowner; /* resowner for holding temp files */ + bool m_interXact; /* keep open through transactions? */ + + bool m_eofReached; /* reached EOF (needed for cursors) */ + + /* + * These variables are used to keep track of the current positions. + * + * In state WRITEFILE, the current file seek position is the write point; + * in state READFILE, the write position is remembered in writepos_xxx. + * (The write position is the same as EOF, but since BufFileSeek doesn't + * currently implement SEEK_END, we have to remember it explicitly.) + */ + BSReadPointer* m_readptrs; /* array of read pointers */ + int m_activeptr; /* index of the active read pointer */ + int m_readptrcount; /* number of pointers currently valid */ + int m_readptrsize; /* allocated length of readptrs array */ + + int writepos_file; /* file# (valid if READFILE state) */ + off_t writepos_offset; /* offset (valid if READFILE state) */ + int m_markposOffset; /* saved "current", or offset in tape block */ + int m_lastbatchnum; + int m_lastfile_num; + + int m_lastwritebatchnum; + off_t m_lastwritefile_offset; + + off_t m_lastfile_offset; + bool m_windowagg_use; /* a flag used in windowagg */ + + /* + * Initialize variables. + */ + + void DumpMultiColumn(); + + void GetBatch(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + void PutBatch(VectorBatch* batch); + + void GetBatchInMemory(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + + void GetBatchReadFile(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + void GetBatchWriteFile(bool forward, VectorBatch* batch); + + void PutBatchToMemory(MultiColumns* multiColumn); + + void PutBatchReadFile(MultiColumns* multiColumn); + void PutBatchWriteFile(MultiColumns* multiColumn); + + void WriteMultiColumn(MultiColumns* stup); + + /* + * Function to read a stored tuple from tape back into memory. 'len' is + * the already-read length of the stored tuple. Create a palloc'd copy, + * initialize tuple/datum1/isnull1 in the target SortTuple struct, and + * decrease state->availMem by the amount of memory space consumed. + */ + void (*readMultiColumn)(BatchStore* state, MultiColumns& stup, unsigned int len); + +#ifdef PGXC + /* + * Function to read length of next stored tuple. + * Used as 'len' parameter for readtup function. + */ + unsigned int (*getlen)(BatchStore* state, bool eofOK); +#endif +}; + +/* + * Currently we only need to store MinimalTuples, but it would be easy + * to support the same behavior for IndexTuples and/or bare Datums. + */ + +extern BatchStore* batchstore_begin_heap( + TupleDesc tupDesc, bool randomAccess, bool interXact, int64 maxKBytes, int maxMem = 0, int planId = 0, int dop = 1); + +extern void batchstore_set_eflags(BatchStore* state, int eflags); + +extern void batchstore_putbatch(BatchStore* state, VectorBatch* batch); + +extern int batchstore_alloc_read_pointer(BatchStore* state, int eflags); + +extern void batchstore_trim(BatchStore* state, bool from_memory); +extern void batchstore_restrpos(BatchStore* state); +extern void batchstore_markpos(BatchStore* state, bool from_mem); +extern bool batchstore_getbatch(BatchStore* state, bool forward, VectorBatch* batch); +extern bool batchstore_ateof(BatchStore* state); +extern void batchstore_rescan(BatchStore* state); +extern void batchstore_end(BatchStore* state); +extern void ReadMultiColumn(BatchStore* state, MultiColumns& multiColumn, unsigned int len); + +unsigned int GetLen(BatchStore* state, bool eofOK); + +#endif /* TUPLESTORE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/be_module.h postgresql-hll-2.14/include/include/utils/be_module.h --- postgresql-hll-2.14_old/include/include/utils/be_module.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/be_module.h 2020-12-12 17:06:43.282348490 +0800 @@ -0,0 +1,168 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * be_module.h + * + * + * + * IDENTIFICATION + * src/include/utils/be_module.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_BE_MODULE_H +#define SRC_INCLUDE_UTILS_BE_MODULE_H + +/* + * How to add your module id ? + * 1. add your module id before MOD_MAX in ModuleId; + * 2. fill up module_map[] about module name, and keep their ordering; + * + */ +enum ModuleId { + /* fastpath for all modules on/off */ + MOD_ALL = 0, + /* add your module id following */ + + MOD_DFS, /* DFS */ + MOD_GUC, /* GUC */ + MOD_HDFS, /* HDFS feature */ + MOD_ORC, /* ORC storage format */ + MOD_SLRU, /* Simple LRU buffering manager */ + MOD_MEM, /* Memory Manager */ + MOD_AUTOVAC, /* auto-vacuum */ + MOD_CACHE, /* cache manager include data cache(cu , dfs) ,index cache(dfs)*/ + MOD_ADIO, /* ADIO feature */ + MOD_SSL, /* SSL */ + MOD_GDS, /* GDS */ + MOD_TBLSPC, /* Tablespace */ + MOD_WLM, /* workload manager*/ + MOD_OBS, /* OBS */ + MOD_EXECUTOR, /* Row Executor */ + MOD_OPFUSION, /* Bypass Opfusion */ + MOD_GPC, /* Global plancache */ + MOD_VEC_EXECUTOR, /* Vector Executor */ + MOD_STREAM, /* Stream */ + MOD_LLVM, /* LLVM */ + MOD_OPT, /* Optimizer default module */ + MOD_OPT_REWRITE, /* Optimizer sub-module:rewrite */ + MOD_OPT_JOIN, /* Optimizer sub-module:join */ + MOD_OPT_AGG, /* Optimizer sub-module:agg */ + MOD_OPT_SUBPLAN, /* Optimizer sub-module:subplan */ + MOD_OPT_SETOP, /* Optimizer sub-module:setop */ + MOD_OPT_SKEW, /* Optimizer sub-module:data skew */ + MOD_UDF, /* fenced udf */ + MOD_COOP_ANALYZE, /* cooperation analyze */ + MOD_WLM_CP, /* wlm for the comupte pool */ + MOD_ACCELERATE, /* accelerate with comptue pool */ + MOD_MOT, /* MOT */ + MOD_PLANHINT, /* plan hint */ + MOD_PARQUET, /* Parquet storage format */ + MOD_CARBONDATA, /* Carbondata storage format */ + + /* MODULE FOR TRANSACTION LOG CONTROL , USE LOG LEVEL*/ + MOD_TRANS_SNAPSHOT, /* Snapshot */ + MOD_TRANS_XACT, /* Xact Finite-State-Machine(FSM) */ + MOD_TRANS_HANDLE, /* Handle for Transaction */ + MOD_TRANS_CLOG, /* Clog Write */ + + MOD_EC, /* Extension Connector */ + MOD_REMOTE, /* remote read */ + MOD_CN_RETRY, /* cn retry */ + MOD_PLSQL, /* plpgsql */ + MOD_TS, /* TEXT SEARCH */ + MOD_SEQ, /* sequence */ + MOD_REDO, /* redo log */ + MOD_FUNCTION, /* internal function */ + MOD_PARSER, /* parser module*/ + MOD_INSTR, /* Instrumentation */ + MOD_INCRE_CKPT, /* incremental checkpoint */ + MOD_INCRE_BG, /* incremental checkpoint bgwriter */ + MOD_DW, /* double write */ + MOD_RTO, /* log control */ + MOD_HEARTBEAT, /* heartbeat */ + MOD_COMM_IPC, /* comm ipc performance */ + MOD_COMM_PARAM, /* comm session params */ + MOD_TIMESERIES, /* timeseries feature */ + MOD_SCHEMA, /* schema search */ + MOD_LIGHTPROXY, /* lightProxy */ + MOD_HOTKEY, /* hotkey */ + MOD_OPT_AI, /* ai optimizer */ + + /* add your module id above */ + MOD_MAX +}; + +/* 1 bit <--> 1 module, including MOD_MAX. its size is + * ((MOD_MAX+1)+7)/8 = MOD_MAX/8 + 1 + */ +#define BEMD_BITMAP_SIZE (1 + (MOD_MAX / 8)) + +#define MODULE_ID_IS_VALID(_id) ((_id) >= MOD_ALL && (_id) < MOD_MAX) +#define ALL_MODULES(_id) (MOD_ALL == (_id)) + +/* Is it a valid and signle module id ? */ +#define VALID_SINGLE_MODULE(_id) ((_id) > MOD_ALL && (_id) < MOD_MAX) + +/* max length of module name */ +#define MODULE_NAME_MAXLEN (16) + +/* delimiter of module name list about GUC parameter */ +#define MOD_DELIMITER ',' + +/* map about module id and its name */ +typedef struct module_data { + ModuleId mod_id; + const char mod_name[MODULE_NAME_MAXLEN]; +} module_data; + +/******************* be-module id <--> name **********************/ +extern ModuleId get_module_id(const char* module_name); + +/* Notice: + * declaration here only for the following inline functions, + * never use it within the other files directly. + */ +extern const module_data module_map[]; + +/* + * @Description: get the default module name. normally + * this module is not defined in ModuleId. + * @Return: default module name + * @See also: + */ +inline const char* get_default_module_name(void) +{ + return module_map[MOD_MAX].mod_name; +} + +/* + * @Description: find a module's name according to its id. + * @IN module_id: module id + * @Return: module name + * @See also: + */ +inline const char* get_valid_module_name(ModuleId module_id) +{ + return module_map[module_id].mod_name; +} + +/******************* be-module logging **********************/ +extern bool check_module_name_unique(void); +extern void module_logging_batch_set(ModuleId* mods, int nmods, bool turn_on, bool apply_all_modules); +extern bool module_logging_is_on(ModuleId module_id); +extern void module_logging_enable_comm(ModuleId module_id); + +#endif /* SRC_INCLUDE_UTILS_BE_MODULE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/biginteger.h postgresql-hll-2.14/include/include/utils/biginteger.h --- postgresql-hll-2.14_old/include/include/utils/biginteger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/biginteger.h 2020-12-12 17:06:43.282348490 +0800 @@ -0,0 +1,281 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * biginteger.h + * Definitions for the big integer data type + * + * Big integer(int64/int128) is one implementation of numeric data + * type, the purpose is to increase speed of numeric operators. + * + * IDENTIFICATION + * src/include/utils/biginteger.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_BIGINTERGER_H_ +#define SRC_INCLUDE_UTILS_BIGINTERGER_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "c.h" +#include "catalog/pg_type.h" +#include "fmgr.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/array.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" + +/* + * int32 integer: + * int32 value must in [-2147483648, 2147483647] + * abs(int32_value) < 10^11, so the max dscale of int32 can represent is 10. + * + * int64 integer: + * int64 value must in [-9223372036854775808, 9223372036854775807] + * abs(int64_value) < 10^20, so the max dscale of int64 can represent is 19. + * + * int128 integer: + * int128 value must in [-170141183460469231731687303715884105728, + * 170141183460469231731687303715884105727] + * abs(int128_value) < 10^40, so the max dscale of int128 can represent is + * 39, but some numbers with 39 digits can't be stored by int128, so just + * choose 38 instead because one number with 38 digits must can be stored + * by int128. + */ +#define MAXINT32DIGIT 10 +#define MAXINT64DIGIT 19 +#define MAXINT128DIGIT 38 + +/* the flag of failed dscale encoding */ +#define FAILED_DSCALE_ENCODING -1 + +/* the value of 10^18, it is used for print int128 data */ +#define P10_INT64 1000000000000000000LL /* 18 zeroes */ + +/* this macro represents the first dimension index of BiAggFunMatrix */ +#define BI_AGG_ADD 0 +#define BI_AGG_SMALLER 1 +#define BI_AGG_LARGER 2 + +/* + * determine whether one num can convert to int64 or int128 by the + * num's scale, this macro is used for both executor and storage modules. + */ +#define CAN_CONVERT_BI64(whole_scale) ((whole_scale) <= (MAXINT64DIGIT - 1)) +#define CAN_CONVERT_BI128(whole_scale) ((whole_scale) <= MAXINT128DIGIT) + +/* jduge whether int64 data can be transformed to int8 */ +#define INT64_INT8_EQ(data) ((data) == (int64)((int8)(data))) + +/* jduge whether int64 data can be transformed to int16 */ +#define INT64_INT16_EQ(data) ((data) == (int64)((int16)(data))) + +/* jduge whether int64 data can be transformed to int32 */ +#define INT64_INT32_EQ(data) ((data) == (int64)((int32)(data))) + +/* jduge whether int128 data can be transformed to int64 */ +#define INT128_INT64_EQ(data) ((data) == (int128)((int64)(data))) + +/* + * align two int64 vals by dscale, multipler is factorial of 10. + * set ScaleMultipler[i] = 10^i, i is between 0 and 18. + * 10^19 is out of int64 bound, so set ScaleMultipler[19] to 0. + */ +extern const int64 ScaleMultipler[20]; + +/* + * fast compare whether the result of arg * ScaleMultipler[i] + * is out of int64 bound. + * Int64MultiOutOfBound[i] = INT64_MIN / ScaleMultipler[i] + */ +extern const int64 Int64MultiOutOfBound[20]; + +/* + * @Description: calculates the factorial of 10, align two int128 + * vals by dscale, multipler is factorial of 10, set + * values[i] = 10^i, i is between 0 and 38. + * @IN scale: the scale'th power + * @Return: the factorial of 10 + */ +inline int128 getScaleMultiplier(int scale) +{ + Assert(scale >= 0 && scale <= MAXINT128DIGIT); + static const int128 values[] = {static_cast(1LL), + static_cast(10LL), + static_cast(100LL), + static_cast(1000LL), + static_cast(10000LL), + static_cast(100000LL), + static_cast(1000000LL), + static_cast(10000000LL), + static_cast(100000000LL), + static_cast(1000000000LL), + static_cast(10000000000LL), + static_cast(100000000000LL), + static_cast(1000000000000LL), + static_cast(10000000000000LL), + static_cast(100000000000000LL), + static_cast(1000000000000000LL), + static_cast(10000000000000000LL), + static_cast(100000000000000000LL), + static_cast(1000000000000000000LL), + static_cast(1000000000000000000LL) * 10LL, + static_cast(1000000000000000000LL) * 100LL, + static_cast(1000000000000000000LL) * 1000LL, + static_cast(1000000000000000000LL) * 10000LL, + static_cast(1000000000000000000LL) * 100000LL, + static_cast(1000000000000000000LL) * 1000000LL, + static_cast(1000000000000000000LL) * 10000000LL, + static_cast(1000000000000000000LL) * 100000000LL, + static_cast(1000000000000000000LL) * 1000000000LL, + static_cast(1000000000000000000LL) * 10000000000LL, + static_cast(1000000000000000000LL) * 100000000000LL, + static_cast(1000000000000000000LL) * 1000000000000LL, + static_cast(1000000000000000000LL) * 10000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000LL, + static_cast(1000000000000000000LL) * 1000000000000000LL, + static_cast(1000000000000000000LL) * 10000000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 10LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 100LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 1000LL}; + return values[scale]; +} + +/* + * @Description: fast compare whether the result of arg * getScaleMultiplier(i) + * is out of int128 bound. getScaleQuotient(i) equals to + * INT128_MIN / getScaleMultiplier(i) + * @IN scale: num between 0 and MAXINT128DIGIT + * @Return: values[scale] + */ +inline int128 getScaleQuotient(int scale) +{ + Assert(scale >= 0 && scale <= MAXINT128DIGIT); + static const int128 values[] = {INT128_MIN, + INT128_MIN / getScaleMultiplier(1), + INT128_MIN / getScaleMultiplier(2), + INT128_MIN / getScaleMultiplier(3), + INT128_MIN / getScaleMultiplier(4), + INT128_MIN / getScaleMultiplier(5), + INT128_MIN / getScaleMultiplier(6), + INT128_MIN / getScaleMultiplier(7), + INT128_MIN / getScaleMultiplier(8), + INT128_MIN / getScaleMultiplier(9), + INT128_MIN / getScaleMultiplier(10), + INT128_MIN / getScaleMultiplier(11), + INT128_MIN / getScaleMultiplier(12), + INT128_MIN / getScaleMultiplier(13), + INT128_MIN / getScaleMultiplier(14), + INT128_MIN / getScaleMultiplier(15), + INT128_MIN / getScaleMultiplier(16), + INT128_MIN / getScaleMultiplier(17), + INT128_MIN / getScaleMultiplier(18), + INT128_MIN / getScaleMultiplier(19), + INT128_MIN / getScaleMultiplier(20), + INT128_MIN / getScaleMultiplier(21), + INT128_MIN / getScaleMultiplier(22), + INT128_MIN / getScaleMultiplier(23), + INT128_MIN / getScaleMultiplier(24), + INT128_MIN / getScaleMultiplier(25), + INT128_MIN / getScaleMultiplier(26), + INT128_MIN / getScaleMultiplier(27), + INT128_MIN / getScaleMultiplier(28), + INT128_MIN / getScaleMultiplier(29), + INT128_MIN / getScaleMultiplier(30), + INT128_MIN / getScaleMultiplier(31), + INT128_MIN / getScaleMultiplier(32), + INT128_MIN / getScaleMultiplier(33), + INT128_MIN / getScaleMultiplier(34), + INT128_MIN / getScaleMultiplier(35), + INT128_MIN / getScaleMultiplier(36), + INT128_MIN / getScaleMultiplier(37), + INT128_MIN / getScaleMultiplier(38)}; + return values[scale]; +} + +/* + * big integer common operators, we implement corresponding + * functions of big integer for higher performance. + */ +enum biop { + BIADD = 0, // + + BISUB, // - + BIMUL, // * + BIDIV, // / + BIEQ, // = + BINEQ, // != + BILE, // <= + BILT, // < + BIGE, // >= + BIGT, // > + BICMP // > || == || < +}; + +/* + * when adjust scale for two big integer(int64 or int128) data, + * determine the result whether out of bound. + */ +enum BiAdjustScale { BI_AJUST_TRUE = 0, BI_LEFT_OUT_OF_BOUND, BI_RIGHT_OUT_OF_BOUND }; + +/* + * this struct is used for numeric agg function. + * use vechashtable::CopyVarP to decrease memory application. + */ +struct bictl { + Datum store_pos; + MemoryContext context; +}; + +/* + * Function to compute two big integer data(int64 or int128); + * include four operations and comparison operations. + */ +typedef Datum (*biopfun)(Numeric larg, Numeric rarg, bictl* ctl); + +/* + * three dimensional arrays: BiFunMatrix + * this array is used for fast locate the corresponding operation + * functions by operator and type(int64 or int128) + */ +extern const biopfun BiFunMatrix[11][2][2]; + +/* + * three dimensional arrays: BiAggFunMatrix + * this array is used for fast locate the corresponding agg + * functions by operator and type(int64 or int128) + */ +extern const biopfun BiAggFunMatrix[3][2][2]; + +/* convert big integer data to numeric */ +extern Numeric bitonumeric(Datum arg); +/* convert int(int1/int2/int4/int8) to big integer type */ +extern Datum int1_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int2_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int4_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int8_numeric_bi(PG_FUNCTION_ARGS); +/* hash function for big integer(int64/int128/numeric) */ +extern Datum hash_bi(PG_FUNCTION_ARGS); +/* replace numeric hash function and equal function for VecHashAgg/VecHashJoin Node */ +extern void replace_numeric_hash_to_bi(int numCols, FmgrInfo* hashFunctions); +/* bi64 and bi128 output function */ +Datum bi64_out(int64 data, int scale); +Datum bi128_out(int128 data, int scale); + +Datum Simplebi64div64(Numeric larg, Numeric rarg); + +void Int128GetVal(bool is_int128, int128* val, Numeric* arg); + +#endif /* SRC_INCLUDE_UTILS_BIGINTERGER_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/bloom_filter.h postgresql-hll-2.14/include/include/utils/bloom_filter.h --- postgresql-hll-2.14_old/include/include/utils/bloom_filter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/bloom_filter.h 2020-12-12 17:06:43.282348490 +0800 @@ -0,0 +1,465 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bloom_filter.h + * + * + * + * IDENTIFICATION + * src/include/utils/bloom_filter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BLOOM_FILTER_H_ +#define BLOOM_FILTER_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "nodes/nodes.h" + +#define SATISFY_BLOOM_FILTER(dataType) \ + (dataType == INT2OID || dataType == INT4OID || dataType == INT8OID || dataType == FLOAT4OID || \ + dataType == FLOAT8OID || dataType == VARCHAROID || dataType == BPCHAROID || dataType == TEXTOID || \ + dataType == CLOBOID) +#define DEFAULT_ORC_BLOOM_FILTER_ENTRIES 10000 +#define MAX_HASH_FUNCTIONS 4 +#define LSB_IDENTIFY 6 +#define DEFAULT_FPP 0.05 // false positive + +typedef enum { + EQUAL_BLOOM_FILTER, /* for '=' predicate */ + HASHJOIN_BLOOM_FILTER, /* for hashjoin */ + IN_BLOOM_FILTER /* for in/any array */ +} BloomFilterType; + +typedef struct ValueBit { + uint16 position[MAX_HASH_FUNCTIONS]; +} ValueBit; + +/* + * Define the following struct in order to pushdown bloomfilter to computing pool. + * Thr bloomfilter to be stored type is HASHJOIN_BLOOM_FILTER . + */ +typedef struct BloomFilterSet { + NodeTag type; + /* store the BitSet info. */ + uint64* data; + uint64 length; + /* store the BloomFilterImpl info */ + uint64 numBits; + uint64 numHashFunctions; + uint64 numValues; + uint64 maxNumValues; + uint64 startupEntries; + ValueBit* valuePositions; + int64 minIntValue; /* data type to be storeed is one of int2, int4, int8. */ + float8 minFloatValue; /* data type to be storeed is one float4, float8. */ + char* minStringValue; /* data type to be stored is one of varcha, bpchar, text, clob. */ + int64 maxIntValue; /* data type to be storeed is one of int2, int4, int8. */ + float8 maxFloatValue; /* data type to be storeed is one float4, float8. */ + char* maxStringValue; /* data type to be stored is one of varcha, bpchar, text, clob. */ + bool addMinMax; + bool hasMM; + BloomFilterType bfType; + Oid dataType; + int32 typeMod; + Oid collation; +} BloomFilterSet; + +namespace filter { +class BloomFilter : public BaseObject { +public: + virtual ~BloomFilter(); + + /* Get the length of the uint64 array. */ + virtual uint64 getLength() const = 0; + + /* Get the number of bits in the inner set. */ + virtual uint64 getBitSize() const = 0; + + /* Get the number of hash functions used in the current bloom filter. */ + virtual uint64 getNumHashFunctions() const = 0; + + /* Get the number of values added into the current bloom filter. */ + virtual uint64 getNumValues() const = 0; + + /* Get the bitset(uint64 array) in the current bloom filter. */ + virtual const uint64* getBitSet() const = 0; + + /* Get the data type of the current bloom filter. */ + virtual Oid getDataType() const = 0; + virtual int32 getTypeMod() const = 0; + + /* + * Get the type of the current bloom filter: EQUAL_BLOOM_FILTER, + * HASHJOIN_BLOOM_FILTER or IN_BLOOM_FILTER. + */ + virtual BloomFilterType getType() const = 0; + + /* + * Get the flag which indicates whether the current bloom filter + * has min/max statistics. + */ + virtual bool hasMinMax() const = 0; + + /* + * Get the minimum value of all the values added to the + * current blomm filter. + */ + virtual Datum getMin() const = 0; + + /* + * Get the maximum value of all the values added to the + * current blomm filter. + */ + virtual Datum getMax() const = 0; + + /* + * Add a datum into the current bloom filter. + * @_in_param val: The datum to be added. + */ + virtual void addDatum(Datum val) = 0; + + /* + * Add a value of any supported data type into the current + * bloom filter. + * @_in_param value: The value to be added. + */ + template + void addValue(T value) + {} + + /* + * Check if the current bloom filter includes another datum. + * @_in_param value: The datum to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeDatum(Datum value) const = 0; + + /* + * Check if the current bloom filter includes a value of any + * supported data type. + * @_in_param value: The value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + template + bool includeValue(T value) const + { + return true; + } + + /* + * Check if the inner bloom filter is included in a bit set. + * If there is only one value stored in the inner bloom filter, call the + * native singleIncludedIn function. The single value is included in the + * bit set only when all the four bits of the value are set 1 in the bit + * set. If there are mulitple values stored in the inner bloom filter, + * check each of the values to see if there is at least one which is + * included in the bit set. The inner bloom filter does not refute the bit + * set unless on one match. + * @_in_param that: The bit set to be checked. + * @return true if the inner bloom filter is included in the bit set. + */ + virtual bool includedIn(const uint64* that) const = 0; + + /* + * Check if the inner bloom fitler is included in another bloom filter(we + * name it the outer bloom fitler here for easy). + * If there is only one value stored in the inner bloom filter, call the + * native singleIncludedIn function. The single value is included in the + * outer bloom filter only when all the four bits of the value are set 1 in + * the outer bloom filter. If there are mulitple values stored in the inner + * bloom filter, check each of the values to see if there is at least one + * which is included in the outer bloom fitler. The inner bloom filter does + * not refute the outer bloom filter unless on one match. + * @_in_param that: The bloom filter to be checked. + * @return true if the inner bloom filter is included in the outer one. + */ + virtual bool includedIn(const BloomFilter& that) const = 0; + + /* Union another bloom filter with the current bloom filter. */ + virtual void unionAll(const BloomFilter& that) = 0; + + /* Intersect another bloom filter with the current one. */ + virtual void intersectAll(const BloomFilter& that) = 0; + + /* Reset the current bloom filter. */ + virtual void reset() = 0; + /* make one bloomfilterSet struct in order to pushdown bloomfilter inot to computing pool.*/ + virtual BloomFilterSet* makeBloomFilterSet() = 0; + /* Fill the bloomfilter element by bloomFilterSet. */ + virtual void rebuildBloomFilterValue(BloomFilterSet* bloomFilterSet) = 0; + + /* Function pointer point to jitted_bf_addLong machine code */ + char* jitted_bf_addLong; + + /* Function pointer point to jitted_bf_includeLong machine code */ + char* jitted_bf_incLong; + + /* + * Check if the current bloom filter includes an int64 value. + * @_in_param value: The int64 value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeLong(int64 value) const = 0; + +protected: + /* Add an int64 value into the inner bloom filter. */ + virtual void addLong(int64 val) = 0; + + /* Add a double value into the inner bloom filter. */ + virtual void addDouble(double val) = 0; + + /* Add a string into the inner bloom filter. */ + virtual void addString(const char* val) = 0; + + /* + * Check if the current bloom filter includes a double value. + * @_in_param value: The double value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeDouble(double value) const = 0; + + /* + * Check if the current bloom filter includes a string value. + * @_in_param value: The string value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeString(const char* value) const = 0; +}; + +/* + * Bare metal bit set implementation. For performance reasons, this implementation does not check + * for index bounds nor expand the bit set size if the specified index is greater than the size. + */ +class BitSet : public BaseObject { +public: + BitSet(const MemoryContext& ctx, const uint64 bits); + BitSet(uint64* _data, uint64 _length); + virtual ~BitSet(); + void set(uint64 index); + bool get(uint64 index) const; + uint64 getLength() const; + const uint64* getData() const; + void unionAll(const uint64* array); + void intersectAll(const uint64* array); + void clear(); + +public: + uint64* data; + uint64 length; +}; + +template +class BloomFilterImpl : public BloomFilter { +public: + BloomFilterImpl(MemoryContext& ctx, Oid dataType, int32 typeMod, Oid collation, BloomFilterType type, + int64 expectedEntries, double fpp, bool addMinMax); + BloomFilterImpl(MemoryContext& ctx, BloomFilterSet* bloomFilterSet); + virtual ~BloomFilterImpl(); + +private: + uint64 getLength() const; + uint64 getBitSize() const; + uint64 getNumHashFunctions() const; + uint64 getNumValues() const; + const uint64* getBitSet() const; + Oid getDataType() const; + BloomFilterType getType() const; + int32 getTypeMod() const; + bool hasMinMax() const; + Datum getMin() const; + Datum getMax() const; + void addDatum(Datum val) + {} + void addLong(int64 val) + {} + void addDouble(double val) + {} + void addString(const char* val) + {} + bool includeDatum(Datum value) const + { + return true; + } + bool includeLong(int64 value) const + { + return true; + } + bool includeDouble(double value) const + { + return true; + } + bool includeString(const char* value) const + { + return true; + } + bool includedIn(const uint64* that) const; + bool includedIn(const BloomFilter& that) const; + void unionAll(const BloomFilter& that); + void intersectAll(const BloomFilter& that); + void reset(); + + BloomFilterSet* makeBloomFilterSet(); + /* rebuild the element of BloomFilter. */ + void rebuildBloomFilterValue(BloomFilterSet* bloomFilterSet); + + /* set the min/max value by bloomFilterSet in the bloom filter. */ + void setMinMaxValueByBloomFilterSet(BloomFilterSet* bloomFilterSet){}; + /* set the min/max value for bloomFilterSet by bloom filter object. */ + void setMinMaxValueForBloomFilterSet(BloomFilterSet* bloomFilterSet){}; + + /* Convert data from float into int32. */ + int32 floatToInt32(float x) const; + + /* Store the min max value in the bloom filter. */ + void setMinMax(baseType val); + + /* Add a value which has been hashed in the bloom filter. */ + void addHash(int64 hash64); + + /* + * For integer(long) and float(double) data types, they are all converted + * to long type before been hashed. + */ + void addLongInternal(int64 val); + + /* Calucate the number of functions for hash. */ + uint64 optimalNumOfHashFunctions(int64 n, int m) const; + + /* Calculate the size of bit set which store the value. */ + uint64 optimalNumOfBits(int64 n, double p) const; + + /* Convert data from double into int64. */ + int64 doubleToInt64(double x) const; + + /* Thomas Wang's integer hash function */ + int64 getLongHash(int64 key) const; + + /* Check if a hashed value is included in the bloom filter. */ + bool includeHashInternal(int64 hash64) const; + + /* + * Check if the current bloom filter which has only one element + * is included in the other bitset. + */ + bool singleIncludedIn(const uint64* that) const; + + /* + * Check if the current bloom filter which has more than one elements + * is included in the other bitset. + */ + bool multiInCludedIn(const uint64* that) const; + + /* Convert raw value into datum. */ + Datum valueToDatum(baseType value) const + { + return 0; + } + + /* Convert datum into raw value. */ + baseType datumToValue(Datum datum) const + { + return 0; + } + + /* + * Compare two raw values, return 1 if left is bigger than right, + * return -1 if left is smaller than right, or return 0 if left + * is equal to right. + */ + int compareValue(baseType left, baseType right) const; + + /* + * Use min/max value to check if the current bloom filter + * is included in the other bloom filter. + */ + bool minMaxCheck(const BloomFilter& that) const; + +public: + BitSet* bitSet; + uint64 numBits; + uint64 numHashFunctions; + uint64 numValues; + uint64 maxNumValues; + uint64 startupEntries; + ValueBit* valuePositions; + baseType minValue; + baseType maxValue; + bool addMinMax; + bool hasMM; + BloomFilterType type; + Oid dataType; + int32 typeMod; + Oid collation; + MemoryContext context; +}; + +template <> +inline void BloomFilter::addValue(int64 value) +{ + addLong(value); +} + +template <> +inline void BloomFilter::addValue(double value) +{ + addDouble(value); +} + +template <> +inline void BloomFilter::addValue(char* value) +{ + addString(value); +} + +template <> +inline bool BloomFilter::includeValue(int64 value) const +{ + return includeLong(value); +} + +template <> +inline bool BloomFilter::includeValue(double value) const +{ + return includeDouble(value); +} + +template <> +inline bool BloomFilter::includeValue(char* value) const +{ + return includeString(value); +} + +/* + * Create a new bloom filter with special datatype, typemod, collation, max + * number of values to be added and the flag controlling if min/max statistics + * need to be added. + */ +BloomFilter* createBloomFilter( + Oid dataType, int32 typeMod, Oid collation, BloomFilterType type, int64 maxNumValues, bool addMinMax); +/* + * Create a new bloom filter object with bloomFilterSet struct. + */ +BloomFilter* createBloomFilter(BloomFilterSet* bloomFilterSet); + +} // namespace filter +#endif /* ORC_QUERY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/builtins.h postgresql-hll-2.14/include/include/utils/builtins.h --- postgresql-hll-2.14_old/include/include/utils/builtins.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/builtins.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,1564 @@ +/* ------------------------------------------------------------------------- + * + * builtins.h + * Declarations for operations on built-in types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/builtins.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUILTINS_H +#define BUILTINS_H + +#ifndef FRONTEND_PARSER +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#ifdef PGXC +#include "lib/stringinfo.h" +#endif +#include "utils/sortsupport.h" + +/* + * Defined in adt/ + */ + +/* acl.c */ +extern Datum has_any_column_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id(PG_FUNCTION_ARGS); + +/* bool.c */ +extern Datum boolin(PG_FUNCTION_ARGS); +extern Datum boolout(PG_FUNCTION_ARGS); +extern Datum boolrecv(PG_FUNCTION_ARGS); +extern Datum boolsend(PG_FUNCTION_ARGS); +extern Datum booltext(PG_FUNCTION_ARGS); +extern Datum booleq(PG_FUNCTION_ARGS); +extern Datum boolne(PG_FUNCTION_ARGS); +extern Datum boollt(PG_FUNCTION_ARGS); +extern Datum boolgt(PG_FUNCTION_ARGS); +extern Datum boolle(PG_FUNCTION_ARGS); +extern Datum boolge(PG_FUNCTION_ARGS); +extern Datum disable_conn(PG_FUNCTION_ARGS); +extern Datum read_disable_conn_file(void); +extern Datum booland_statefunc(PG_FUNCTION_ARGS); +extern Datum boolor_statefunc(PG_FUNCTION_ARGS); +extern bool parse_bool(const char* value, bool* result); +extern bool parse_bool_with_len(const char* value, size_t len, bool* result); + +/* char.c */ +extern Datum charin(PG_FUNCTION_ARGS); +extern Datum charout(PG_FUNCTION_ARGS); +extern Datum charrecv(PG_FUNCTION_ARGS); +extern Datum charsend(PG_FUNCTION_ARGS); +extern Datum chareq(PG_FUNCTION_ARGS); +extern Datum charne(PG_FUNCTION_ARGS); +extern Datum charlt(PG_FUNCTION_ARGS); +extern Datum charle(PG_FUNCTION_ARGS); +extern Datum chargt(PG_FUNCTION_ARGS); +extern Datum charge(PG_FUNCTION_ARGS); +extern Datum chartoi4(PG_FUNCTION_ARGS); +extern Datum i4tochar(PG_FUNCTION_ARGS); +extern Datum text_char(PG_FUNCTION_ARGS); +extern Datum char_text(PG_FUNCTION_ARGS); + +/* domains.c */ +extern Datum domain_in(PG_FUNCTION_ARGS); +extern Datum domain_recv(PG_FUNCTION_ARGS); +extern void domain_check(Datum value, bool isnull, Oid domainType, void** extra, MemoryContext mcxt); + +/* encode.c */ +extern Datum binary_encode(PG_FUNCTION_ARGS); +extern Datum binary_decode(PG_FUNCTION_ARGS); +extern unsigned hex_encode(const char* src, unsigned len, char* dst); +extern unsigned hex_decode(const char* src, unsigned len, char* dst); + +/* enum.c */ +extern Datum enum_in(PG_FUNCTION_ARGS); +extern Datum enum_out(PG_FUNCTION_ARGS); +extern Datum enum_recv(PG_FUNCTION_ARGS); +extern Datum enum_send(PG_FUNCTION_ARGS); +extern Datum enum_lt(PG_FUNCTION_ARGS); +extern Datum enum_le(PG_FUNCTION_ARGS); +extern Datum enum_eq(PG_FUNCTION_ARGS); +extern Datum enum_ne(PG_FUNCTION_ARGS); +extern Datum enum_ge(PG_FUNCTION_ARGS); +extern Datum enum_gt(PG_FUNCTION_ARGS); +extern Datum enum_cmp(PG_FUNCTION_ARGS); +extern Datum enum_smaller(PG_FUNCTION_ARGS); +extern Datum enum_larger(PG_FUNCTION_ARGS); +extern Datum enum_first(PG_FUNCTION_ARGS); +extern Datum enum_last(PG_FUNCTION_ARGS); +extern Datum enum_range_bounds(PG_FUNCTION_ARGS); +extern Datum enum_range_all(PG_FUNCTION_ARGS); + +/* int.c */ +extern Datum int2in(PG_FUNCTION_ARGS); +extern Datum int2out(PG_FUNCTION_ARGS); +extern Datum int2recv(PG_FUNCTION_ARGS); +extern Datum int2send(PG_FUNCTION_ARGS); +extern Datum int2vectorin(PG_FUNCTION_ARGS); +extern Datum int2vectorout(PG_FUNCTION_ARGS); +extern Datum int2vectorrecv(PG_FUNCTION_ARGS); +extern Datum int2vectorsend(PG_FUNCTION_ARGS); +extern Datum int2vectoreq(PG_FUNCTION_ARGS); +extern Datum int4in(PG_FUNCTION_ARGS); +extern Datum int4out(PG_FUNCTION_ARGS); +extern Datum int4recv(PG_FUNCTION_ARGS); +extern Datum int4send(PG_FUNCTION_ARGS); +extern Datum i2toi4(PG_FUNCTION_ARGS); +extern Datum i4toi2(PG_FUNCTION_ARGS); +extern Datum int4_bool(PG_FUNCTION_ARGS); +extern Datum bool_int4(PG_FUNCTION_ARGS); +extern Datum int2_bool(PG_FUNCTION_ARGS); +extern Datum bool_int2(PG_FUNCTION_ARGS); +extern Datum int4eq(PG_FUNCTION_ARGS); +extern Datum int4ne(PG_FUNCTION_ARGS); +extern Datum int4lt(PG_FUNCTION_ARGS); +extern Datum int4le(PG_FUNCTION_ARGS); +extern Datum int4gt(PG_FUNCTION_ARGS); +extern Datum int4ge(PG_FUNCTION_ARGS); +extern Datum int2eq(PG_FUNCTION_ARGS); +extern Datum int2ne(PG_FUNCTION_ARGS); +extern Datum int2lt(PG_FUNCTION_ARGS); +extern Datum int2le(PG_FUNCTION_ARGS); +extern Datum int2gt(PG_FUNCTION_ARGS); +extern Datum int2ge(PG_FUNCTION_ARGS); +extern Datum int24eq(PG_FUNCTION_ARGS); +extern Datum int24ne(PG_FUNCTION_ARGS); +extern Datum int24lt(PG_FUNCTION_ARGS); +extern Datum int24le(PG_FUNCTION_ARGS); +extern Datum int24gt(PG_FUNCTION_ARGS); +extern Datum int24ge(PG_FUNCTION_ARGS); +extern Datum int42eq(PG_FUNCTION_ARGS); +extern Datum int42ne(PG_FUNCTION_ARGS); +extern Datum int42lt(PG_FUNCTION_ARGS); +extern Datum int42le(PG_FUNCTION_ARGS); +extern Datum int42gt(PG_FUNCTION_ARGS); +extern Datum int42ge(PG_FUNCTION_ARGS); +extern Datum int4um(PG_FUNCTION_ARGS); +extern Datum int4up(PG_FUNCTION_ARGS); +extern Datum int4pl(PG_FUNCTION_ARGS); +extern Datum int4mi(PG_FUNCTION_ARGS); +extern Datum int4mul(PG_FUNCTION_ARGS); +extern Datum int4div(PG_FUNCTION_ARGS); +extern Datum int4abs(PG_FUNCTION_ARGS); +extern Datum int4inc(PG_FUNCTION_ARGS); +extern Datum int2um(PG_FUNCTION_ARGS); +extern Datum int2up(PG_FUNCTION_ARGS); +extern Datum int2pl(PG_FUNCTION_ARGS); +extern Datum int2mi(PG_FUNCTION_ARGS); +extern Datum int2mul(PG_FUNCTION_ARGS); +extern Datum int2div(PG_FUNCTION_ARGS); +extern Datum int2abs(PG_FUNCTION_ARGS); +extern Datum int24pl(PG_FUNCTION_ARGS); +extern Datum int24mi(PG_FUNCTION_ARGS); +extern Datum int24mul(PG_FUNCTION_ARGS); +extern Datum int24div(PG_FUNCTION_ARGS); +extern Datum int42pl(PG_FUNCTION_ARGS); +extern Datum int42mi(PG_FUNCTION_ARGS); +extern Datum int42mul(PG_FUNCTION_ARGS); +extern Datum int42div(PG_FUNCTION_ARGS); +extern Datum int4mod(PG_FUNCTION_ARGS); +extern Datum int2mod(PG_FUNCTION_ARGS); +extern Datum int2larger(PG_FUNCTION_ARGS); +extern Datum int2smaller(PG_FUNCTION_ARGS); +extern Datum int4larger(PG_FUNCTION_ARGS); +extern Datum int4smaller(PG_FUNCTION_ARGS); +extern Datum int1in(PG_FUNCTION_ARGS); +extern Datum int1out(PG_FUNCTION_ARGS); +extern Datum int1recv(PG_FUNCTION_ARGS); +extern Datum int1send(PG_FUNCTION_ARGS); +extern Datum int1eq(PG_FUNCTION_ARGS); +extern Datum int1ne(PG_FUNCTION_ARGS); +extern Datum int1lt(PG_FUNCTION_ARGS); +extern Datum int1le(PG_FUNCTION_ARGS); +extern Datum int1gt(PG_FUNCTION_ARGS); +extern Datum int1ge(PG_FUNCTION_ARGS); +extern Datum int1cmp(PG_FUNCTION_ARGS); +extern Datum i1toi2(PG_FUNCTION_ARGS); +extern Datum i2toi1(PG_FUNCTION_ARGS); +extern Datum i1toi4(PG_FUNCTION_ARGS); +extern Datum i4toi1(PG_FUNCTION_ARGS); +extern Datum i1toi8(PG_FUNCTION_ARGS); +extern Datum i8toi1(PG_FUNCTION_ARGS); +extern Datum i1tof4(PG_FUNCTION_ARGS); +extern Datum f4toi1(PG_FUNCTION_ARGS); +extern Datum i1tof8(PG_FUNCTION_ARGS); +extern Datum f8toi1(PG_FUNCTION_ARGS); +extern Datum int1_bool(PG_FUNCTION_ARGS); +extern Datum bool_int1(PG_FUNCTION_ARGS); +extern Datum int4_bpchar(PG_FUNCTION_ARGS); +extern Datum int1_bpchar(PG_FUNCTION_ARGS); +extern Datum int2_bpchar(PG_FUNCTION_ARGS); +extern Datum float4_bpchar(PG_FUNCTION_ARGS); +extern Datum float8_bpchar(PG_FUNCTION_ARGS); +extern Datum numeric_bpchar(PG_FUNCTION_ARGS); +extern Datum int1and(PG_FUNCTION_ARGS); +extern Datum int1or(PG_FUNCTION_ARGS); +extern Datum int1xor(PG_FUNCTION_ARGS); +extern Datum int1not(PG_FUNCTION_ARGS); +extern Datum int1shl(PG_FUNCTION_ARGS); +extern Datum int1shr(PG_FUNCTION_ARGS); +extern Datum int1um(PG_FUNCTION_ARGS); +extern Datum int1up(PG_FUNCTION_ARGS); +extern Datum int1pl(PG_FUNCTION_ARGS); +extern Datum int1mi(PG_FUNCTION_ARGS); +extern Datum int1mul(PG_FUNCTION_ARGS); +extern Datum int1div(PG_FUNCTION_ARGS); +extern Datum int1abs(PG_FUNCTION_ARGS); +extern Datum int1mod(PG_FUNCTION_ARGS); +extern Datum int1larger(PG_FUNCTION_ARGS); +extern Datum int1smaller(PG_FUNCTION_ARGS); +extern Datum int1inc(PG_FUNCTION_ARGS); + +extern Datum int4and(PG_FUNCTION_ARGS); +extern Datum int4or(PG_FUNCTION_ARGS); +extern Datum int4xor(PG_FUNCTION_ARGS); +extern Datum int4not(PG_FUNCTION_ARGS); +extern Datum int4shl(PG_FUNCTION_ARGS); +extern Datum int4shr(PG_FUNCTION_ARGS); +extern Datum int2and(PG_FUNCTION_ARGS); +extern Datum int2or(PG_FUNCTION_ARGS); +extern Datum int2xor(PG_FUNCTION_ARGS); +extern Datum int2not(PG_FUNCTION_ARGS); +extern Datum int2shl(PG_FUNCTION_ARGS); +extern Datum int2shr(PG_FUNCTION_ARGS); +extern Datum generate_series_int4(PG_FUNCTION_ARGS); +extern Datum generate_series_step_int4(PG_FUNCTION_ARGS); +extern int2vector* buildint2vector(const int2* int2s, int n); +extern int2vector* int2vectorCopy(int2vector* from); +/* encoding.cpp */ +extern Datum encode_plan_node(PG_FUNCTION_ARGS); +/* ml_model.cpp */ +extern Datum model_train_opt(PG_FUNCTION_ARGS); +extern Datum track_model_train_opt(PG_FUNCTION_ARGS); + +/* lsyscache.cpp */ +extern Datum node_oid_name(PG_FUNCTION_ARGS); +/* tablespace.cpp */ +extern Datum tablespace_oid_name(PG_FUNCTION_ARGS); +/* namespace.cpp */ +extern Datum get_schema_oid(PG_FUNCTION_ARGS); +/* name.c */ +extern Datum namein(PG_FUNCTION_ARGS); +extern Datum nameout(PG_FUNCTION_ARGS); +extern Datum namerecv(PG_FUNCTION_ARGS); +extern Datum namesend(PG_FUNCTION_ARGS); +extern Datum nameeq(PG_FUNCTION_ARGS); +extern Datum nameeq_withhead(PG_FUNCTION_ARGS); +extern Datum namene(PG_FUNCTION_ARGS); +extern Datum namelt(PG_FUNCTION_ARGS); +extern Datum namele(PG_FUNCTION_ARGS); +extern Datum namegt(PG_FUNCTION_ARGS); +extern Datum namege(PG_FUNCTION_ARGS); +extern int namestrcpy(Name name, const char* str); +extern int namestrcmp(Name name, const char* str); +extern Datum current_user(PG_FUNCTION_ARGS); +extern Datum session_user(PG_FUNCTION_ARGS); +extern Datum current_schema(PG_FUNCTION_ARGS); +extern Datum current_schemas(PG_FUNCTION_ARGS); +extern Datum pseudo_current_user(PG_FUNCTION_ARGS); +extern uint64 pg_strtouint64(const char* str, char** endptr, int base); + +/* numutils.c */ +extern int32 pg_atoi(char* s, int size, int c); +extern int16 pg_strtoint16(const char* s); +extern int32 pg_strtoint32(const char* s); +extern void pg_itoa(int16 i, char* a); +extern void pg_ltoa(int32 l, char* a); +extern void pg_ctoa(uint8 i, char* a); +extern void pg_lltoa(int64 ll, char* a); + +/* + * Per-opclass comparison functions for new btrees. These are + * stored in pg_amproc; most are defined in access/nbtree/nbtcompare.c + */ +extern Datum btboolcmp(PG_FUNCTION_ARGS); +extern Datum btint2cmp(PG_FUNCTION_ARGS); +extern Datum btint4cmp(PG_FUNCTION_ARGS); +extern Datum btint8cmp(PG_FUNCTION_ARGS); +extern Datum btfloat4cmp(PG_FUNCTION_ARGS); +extern Datum btfloat8cmp(PG_FUNCTION_ARGS); +extern Datum btint48cmp(PG_FUNCTION_ARGS); +extern Datum btint84cmp(PG_FUNCTION_ARGS); +extern Datum btint24cmp(PG_FUNCTION_ARGS); +extern Datum btint42cmp(PG_FUNCTION_ARGS); +extern Datum btint28cmp(PG_FUNCTION_ARGS); +extern Datum btint82cmp(PG_FUNCTION_ARGS); +extern Datum btfloat48cmp(PG_FUNCTION_ARGS); +extern Datum btfloat84cmp(PG_FUNCTION_ARGS); +extern Datum btoidcmp(PG_FUNCTION_ARGS); +extern Datum btoidvectorcmp(PG_FUNCTION_ARGS); +extern Datum btabstimecmp(PG_FUNCTION_ARGS); +extern Datum btreltimecmp(PG_FUNCTION_ARGS); +extern Datum bttintervalcmp(PG_FUNCTION_ARGS); +extern Datum btcharcmp(PG_FUNCTION_ARGS); +extern Datum btnamecmp(PG_FUNCTION_ARGS); +extern Datum bttextcmp(PG_FUNCTION_ARGS); +extern Datum bpchar_sortsupport(PG_FUNCTION_ARGS); +extern Datum bttextsortsupport(PG_FUNCTION_ARGS); +/* + * Per-opclass sort support functions for new btrees. Like the + * functions above, these are stored in pg_amproc; most are defined in + * access/nbtree/nbtcompare.c + */ +extern Datum btint2sortsupport(PG_FUNCTION_ARGS); +extern Datum btint4sortsupport(PG_FUNCTION_ARGS); +extern Datum btint8sortsupport(PG_FUNCTION_ARGS); +extern Datum btfloat4sortsupport(PG_FUNCTION_ARGS); +extern Datum btfloat8sortsupport(PG_FUNCTION_ARGS); +extern Datum btoidsortsupport(PG_FUNCTION_ARGS); +extern Datum btnamesortsupport(PG_FUNCTION_ARGS); + +extern double get_float8_infinity(void); +extern float get_float4_infinity(void); +extern double get_float8_nan(void); +extern float get_float4_nan(void); +extern int is_infinite(double val); + +extern Datum float4in(PG_FUNCTION_ARGS); +extern Datum float4out(PG_FUNCTION_ARGS); +extern Datum float4recv(PG_FUNCTION_ARGS); +extern Datum float4send(PG_FUNCTION_ARGS); +extern Datum float8in(PG_FUNCTION_ARGS); +extern Datum float8out(PG_FUNCTION_ARGS); +extern Datum float8recv(PG_FUNCTION_ARGS); +extern Datum float8send(PG_FUNCTION_ARGS); +extern Datum float4abs(PG_FUNCTION_ARGS); +extern Datum float4um(PG_FUNCTION_ARGS); +extern Datum float4up(PG_FUNCTION_ARGS); +extern Datum float4larger(PG_FUNCTION_ARGS); +extern Datum float4smaller(PG_FUNCTION_ARGS); +extern Datum float8abs(PG_FUNCTION_ARGS); +extern Datum float8um(PG_FUNCTION_ARGS); +extern Datum float8up(PG_FUNCTION_ARGS); +extern Datum float8larger(PG_FUNCTION_ARGS); +extern Datum float8smaller(PG_FUNCTION_ARGS); +extern Datum float4pl(PG_FUNCTION_ARGS); +extern Datum float4mi(PG_FUNCTION_ARGS); +extern Datum float4mul(PG_FUNCTION_ARGS); +extern Datum float4div(PG_FUNCTION_ARGS); +extern Datum float8pl(PG_FUNCTION_ARGS); +extern Datum float8mi(PG_FUNCTION_ARGS); +extern Datum float8mul(PG_FUNCTION_ARGS); +extern Datum float8div(PG_FUNCTION_ARGS); +extern Datum float4eq(PG_FUNCTION_ARGS); +extern Datum float4ne(PG_FUNCTION_ARGS); +extern Datum float4lt(PG_FUNCTION_ARGS); +extern Datum float4le(PG_FUNCTION_ARGS); +extern Datum float4gt(PG_FUNCTION_ARGS); +extern Datum float4ge(PG_FUNCTION_ARGS); +extern Datum float8eq(PG_FUNCTION_ARGS); +extern Datum float8ne(PG_FUNCTION_ARGS); +extern Datum float8lt(PG_FUNCTION_ARGS); +extern Datum float8le(PG_FUNCTION_ARGS); +extern Datum float8gt(PG_FUNCTION_ARGS); +extern Datum float8ge(PG_FUNCTION_ARGS); +extern Datum ftod(PG_FUNCTION_ARGS); +extern Datum i4tod(PG_FUNCTION_ARGS); +extern Datum i2tod(PG_FUNCTION_ARGS); +extern Datum dtof(PG_FUNCTION_ARGS); +extern Datum dtoi4(PG_FUNCTION_ARGS); +extern Datum dtoi2(PG_FUNCTION_ARGS); +extern Datum i4tof(PG_FUNCTION_ARGS); +extern Datum i2tof(PG_FUNCTION_ARGS); +extern Datum ftoi4(PG_FUNCTION_ARGS); +extern Datum ftoi2(PG_FUNCTION_ARGS); +extern Datum dround(PG_FUNCTION_ARGS); +extern Datum dceil(PG_FUNCTION_ARGS); +extern Datum dfloor(PG_FUNCTION_ARGS); +extern Datum dsign(PG_FUNCTION_ARGS); +extern Datum dtrunc(PG_FUNCTION_ARGS); +extern Datum dsqrt(PG_FUNCTION_ARGS); +extern Datum dcbrt(PG_FUNCTION_ARGS); +extern Datum dpow(PG_FUNCTION_ARGS); +extern Datum dexp(PG_FUNCTION_ARGS); +extern Datum dlog1(PG_FUNCTION_ARGS); +extern Datum dlog10(PG_FUNCTION_ARGS); +extern Datum dacos(PG_FUNCTION_ARGS); +extern Datum dasin(PG_FUNCTION_ARGS); +extern Datum datan(PG_FUNCTION_ARGS); +extern Datum datan2(PG_FUNCTION_ARGS); +extern Datum dcos(PG_FUNCTION_ARGS); +extern Datum dcot(PG_FUNCTION_ARGS); +extern Datum dsin(PG_FUNCTION_ARGS); +extern Datum dtan(PG_FUNCTION_ARGS); +extern Datum degrees(PG_FUNCTION_ARGS); +extern Datum dpi(PG_FUNCTION_ARGS); +extern Datum radians(PG_FUNCTION_ARGS); +extern Datum drandom(PG_FUNCTION_ARGS); +extern Datum setseed(PG_FUNCTION_ARGS); +extern Datum float8_accum(PG_FUNCTION_ARGS); +extern Datum float4_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum float8_collect(PG_FUNCTION_ARGS); +#endif +extern Datum float8_avg(PG_FUNCTION_ARGS); +extern Datum float8_var_pop(PG_FUNCTION_ARGS); +extern Datum float8_var_samp(PG_FUNCTION_ARGS); +extern Datum float8_stddev_pop(PG_FUNCTION_ARGS); +extern Datum float8_stddev_samp(PG_FUNCTION_ARGS); +extern Datum float8_regr_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum float8_regr_collect(PG_FUNCTION_ARGS); +#endif +extern Datum float8_regr_sxx(PG_FUNCTION_ARGS); +extern Datum float8_regr_syy(PG_FUNCTION_ARGS); +extern Datum float8_regr_sxy(PG_FUNCTION_ARGS); +extern Datum float8_regr_avgx(PG_FUNCTION_ARGS); +extern Datum float8_regr_avgy(PG_FUNCTION_ARGS); +extern Datum float8_covar_pop(PG_FUNCTION_ARGS); +extern Datum float8_covar_samp(PG_FUNCTION_ARGS); +extern Datum float8_corr(PG_FUNCTION_ARGS); +extern Datum float8_regr_r2(PG_FUNCTION_ARGS); +extern Datum float8_regr_slope(PG_FUNCTION_ARGS); +extern Datum float8_regr_intercept(PG_FUNCTION_ARGS); +extern Datum float48pl(PG_FUNCTION_ARGS); +extern Datum float48mi(PG_FUNCTION_ARGS); +extern Datum float48mul(PG_FUNCTION_ARGS); +extern Datum float48div(PG_FUNCTION_ARGS); +extern Datum float84pl(PG_FUNCTION_ARGS); +extern Datum float84mi(PG_FUNCTION_ARGS); +extern Datum float84mul(PG_FUNCTION_ARGS); +extern Datum float84div(PG_FUNCTION_ARGS); +extern Datum float48eq(PG_FUNCTION_ARGS); +extern Datum float48ne(PG_FUNCTION_ARGS); +extern Datum float48lt(PG_FUNCTION_ARGS); +extern Datum float48le(PG_FUNCTION_ARGS); +extern Datum float48gt(PG_FUNCTION_ARGS); +extern Datum float48ge(PG_FUNCTION_ARGS); +extern Datum float84eq(PG_FUNCTION_ARGS); +extern Datum float84ne(PG_FUNCTION_ARGS); +extern Datum float84lt(PG_FUNCTION_ARGS); +extern Datum float84le(PG_FUNCTION_ARGS); +extern Datum float84gt(PG_FUNCTION_ARGS); +extern Datum float84ge(PG_FUNCTION_ARGS); +extern Datum width_bucket_float8(PG_FUNCTION_ARGS); +Datum float8_multiply_text(PG_FUNCTION_ARGS); +Datum text_multiply_float8(PG_FUNCTION_ARGS); + +/* dbsize.c */ +extern Datum pg_tablespace_size_oid(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_size_name(PG_FUNCTION_ARGS); +extern Datum pg_database_size_oid(PG_FUNCTION_ARGS); +extern Datum pg_database_size_name(PG_FUNCTION_ARGS); +extern Datum get_db_source_datasize(PG_FUNCTION_ARGS); +extern Datum pg_switch_relfilenode_name(PG_FUNCTION_ARGS); +extern Datum pg_relation_size(PG_FUNCTION_ARGS); +extern Datum pg_total_relation_size(PG_FUNCTION_ARGS); +extern Datum pg_size_pretty(PG_FUNCTION_ARGS); +extern Datum pg_size_pretty_numeric(PG_FUNCTION_ARGS); +extern Datum pg_table_size(PG_FUNCTION_ARGS); +extern Datum pg_partition_size(PG_FUNCTION_ARGS); +extern Datum pg_partition_indexes_size(PG_FUNCTION_ARGS); +extern Datum pg_indexes_size(PG_FUNCTION_ARGS); +extern Datum pg_relation_filenode(PG_FUNCTION_ARGS); +extern Datum pg_filenode_relation(PG_FUNCTION_ARGS); +extern Datum pg_relation_filepath(PG_FUNCTION_ARGS); +extern Datum pg_relation_is_scannable(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pg_relation_with_compression(PG_FUNCTION_ARGS); +extern Datum pg_relation_compression_ratio(PG_FUNCTION_ARGS); +#endif +extern Datum pg_partition_filenode(PG_FUNCTION_ARGS); +extern Datum pg_partition_filepath(PG_FUNCTION_ARGS); +/* regioninfo.cpp */ +extern Datum pg_clean_region_info(PG_FUNCTION_ARGS); + +/* genfile.c */ +extern bytea* read_binary_file( + const char* filename, int64 seek_offset, int64 bytes_to_read, bool missing_ok, bool need_check = false); +extern Datum pg_stat_file(PG_FUNCTION_ARGS); +extern Datum pg_read_file(PG_FUNCTION_ARGS); +extern Datum pg_read_file_all(PG_FUNCTION_ARGS); +extern Datum pg_read_binary_file(PG_FUNCTION_ARGS); +extern Datum pg_read_binary_file_all(PG_FUNCTION_ARGS); +extern Datum pg_ls_dir(PG_FUNCTION_ARGS); +extern Datum pg_stat_file_recursive(PG_FUNCTION_ARGS); + +/* misc.c */ +extern Datum current_database(PG_FUNCTION_ARGS); +extern Datum current_query(PG_FUNCTION_ARGS); +extern Datum pg_cancel_backend(PG_FUNCTION_ARGS); +extern Datum pg_cancel_invalid_query(PG_FUNCTION_ARGS); +extern Datum pg_terminate_backend(PG_FUNCTION_ARGS); +extern Datum pg_terminate_session(PG_FUNCTION_ARGS); +extern Datum pg_reload_conf(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_location(PG_FUNCTION_ARGS); +extern Datum pg_rotate_logfile(PG_FUNCTION_ARGS); +extern Datum pg_sleep(PG_FUNCTION_ARGS); +extern Datum pg_get_keywords(PG_FUNCTION_ARGS); +extern Datum pg_typeof(PG_FUNCTION_ARGS); +extern Datum pg_collation_for(PG_FUNCTION_ARGS); +extern Datum pg_sync_cstore_delta(PG_FUNCTION_ARGS); +extern Datum pg_sync_all_cstore_delta(PG_FUNCTION_ARGS); +extern Datum pg_test_err_contain_err(PG_FUNCTION_ARGS); + +/* oid.c */ +extern Datum oidin(PG_FUNCTION_ARGS); +extern Datum oidout(PG_FUNCTION_ARGS); +extern Datum oidrecv(PG_FUNCTION_ARGS); +extern Datum oidsend(PG_FUNCTION_ARGS); +extern Datum oideq(PG_FUNCTION_ARGS); +extern Datum oidne(PG_FUNCTION_ARGS); +extern Datum oidlt(PG_FUNCTION_ARGS); +extern Datum oidle(PG_FUNCTION_ARGS); +extern Datum oidge(PG_FUNCTION_ARGS); +extern Datum oidgt(PG_FUNCTION_ARGS); +extern Datum oidlarger(PG_FUNCTION_ARGS); +extern Datum oidsmaller(PG_FUNCTION_ARGS); +extern Datum oidvectorin(PG_FUNCTION_ARGS); +extern Datum oidvectorout(PG_FUNCTION_ARGS); +extern Datum oidvectorrecv(PG_FUNCTION_ARGS); +extern Datum oidvectorsend(PG_FUNCTION_ARGS); +extern Datum oidvectoreq(PG_FUNCTION_ARGS); +extern Datum oidvectorne(PG_FUNCTION_ARGS); +extern Datum oidvectorlt(PG_FUNCTION_ARGS); +extern Datum oidvectorle(PG_FUNCTION_ARGS); +extern Datum oidvectorge(PG_FUNCTION_ARGS); +extern Datum oidvectorgt(PG_FUNCTION_ARGS); +extern oidvector* buildoidvector(const Oid* oids, int n); +extern Oid oidparse(Node* node); + +/* pseudotypes.c */ +extern Datum cstring_in(PG_FUNCTION_ARGS); +extern Datum cstring_out(PG_FUNCTION_ARGS); +extern Datum cstring_recv(PG_FUNCTION_ARGS); +extern Datum cstring_send(PG_FUNCTION_ARGS); +extern Datum any_in(PG_FUNCTION_ARGS); +extern Datum any_out(PG_FUNCTION_ARGS); +extern Datum anyarray_in(PG_FUNCTION_ARGS); +extern Datum anyarray_out(PG_FUNCTION_ARGS); +extern Datum anyarray_recv(PG_FUNCTION_ARGS); +extern Datum anyarray_send(PG_FUNCTION_ARGS); +extern Datum anynonarray_in(PG_FUNCTION_ARGS); +extern Datum anynonarray_out(PG_FUNCTION_ARGS); +extern Datum anyenum_in(PG_FUNCTION_ARGS); +extern Datum anyenum_out(PG_FUNCTION_ARGS); +extern Datum anyrange_in(PG_FUNCTION_ARGS); +extern Datum anyrange_out(PG_FUNCTION_ARGS); +extern Datum void_in(PG_FUNCTION_ARGS); +extern Datum void_out(PG_FUNCTION_ARGS); +extern Datum void_recv(PG_FUNCTION_ARGS); +extern Datum void_send(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pgxc_node_str(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_backup(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_sp_database(PG_FUNCTION_ARGS); +extern Datum pgxc_unlock_for_sp_database(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_transfer(PG_FUNCTION_ARGS); +extern Datum pgxc_unlock_for_transfer(PG_FUNCTION_ARGS); +#endif +extern Datum trigger_in(PG_FUNCTION_ARGS); +extern Datum trigger_out(PG_FUNCTION_ARGS); +extern Datum language_handler_in(PG_FUNCTION_ARGS); +extern Datum language_handler_out(PG_FUNCTION_ARGS); +extern Datum fdw_handler_in(PG_FUNCTION_ARGS); +extern Datum fdw_handler_out(PG_FUNCTION_ARGS); +extern Datum internal_in(PG_FUNCTION_ARGS); +extern Datum internal_out(PG_FUNCTION_ARGS); +extern Datum opaque_in(PG_FUNCTION_ARGS); +extern Datum opaque_out(PG_FUNCTION_ARGS); +extern Datum anyelement_in(PG_FUNCTION_ARGS); +extern Datum anyelement_out(PG_FUNCTION_ARGS); +extern Datum shell_in(PG_FUNCTION_ARGS); +extern Datum shell_out(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_in(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_out(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_recv(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_send(PG_FUNCTION_ARGS); + +/* regexp.c */ +extern Datum textregexsubstr_enforce_a(PG_FUNCTION_ARGS); +extern Datum nameregexeq(PG_FUNCTION_ARGS); +extern Datum nameregexne(PG_FUNCTION_ARGS); +extern Datum textregexeq(PG_FUNCTION_ARGS); +extern Datum textregexne(PG_FUNCTION_ARGS); +extern Datum nameicregexeq(PG_FUNCTION_ARGS); +extern Datum nameicregexne(PG_FUNCTION_ARGS); +extern Datum texticregexeq(PG_FUNCTION_ARGS); +extern Datum texticregexne(PG_FUNCTION_ARGS); +extern Datum textregexsubstr(PG_FUNCTION_ARGS); +extern Datum textregexreplace_noopt(PG_FUNCTION_ARGS); +extern Datum textregexreplace(PG_FUNCTION_ARGS); +extern Datum similar_escape(PG_FUNCTION_ARGS); +extern Datum regexp_matches(PG_FUNCTION_ARGS); +extern Datum regexp_matches_no_flags(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_table(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_table_no_flags(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_array(PG_FUNCTION_ARGS); +extern Datum regexp_match_to_array(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_array_no_flags(PG_FUNCTION_ARGS); +extern char* regexp_fixed_prefix(text* text_re, bool case_insensitive, Oid collation, bool* exact); + +/* regproc.c */ +extern Datum regprocin(PG_FUNCTION_ARGS); +extern Datum regprocout(PG_FUNCTION_ARGS); +extern Datum regprocrecv(PG_FUNCTION_ARGS); +extern Datum regprocsend(PG_FUNCTION_ARGS); +extern Datum regprocedurein(PG_FUNCTION_ARGS); +extern Datum regprocedureout(PG_FUNCTION_ARGS); +extern Datum regprocedurerecv(PG_FUNCTION_ARGS); +extern Datum regproceduresend(PG_FUNCTION_ARGS); +extern Datum regoperin(PG_FUNCTION_ARGS); +extern Datum regoperout(PG_FUNCTION_ARGS); +extern Datum regoperrecv(PG_FUNCTION_ARGS); +extern Datum regopersend(PG_FUNCTION_ARGS); +extern Datum regoperatorin(PG_FUNCTION_ARGS); +extern Datum regoperatorout(PG_FUNCTION_ARGS); +extern Datum regoperatorrecv(PG_FUNCTION_ARGS); +extern Datum regoperatorsend(PG_FUNCTION_ARGS); +extern Datum regclassin(PG_FUNCTION_ARGS); +extern Datum regclassout(PG_FUNCTION_ARGS); +extern Datum regclassrecv(PG_FUNCTION_ARGS); +extern Datum regclasssend(PG_FUNCTION_ARGS); +extern Datum regtypein(PG_FUNCTION_ARGS); +extern Datum regtypeout(PG_FUNCTION_ARGS); +extern Datum regtyperecv(PG_FUNCTION_ARGS); +extern Datum regtypesend(PG_FUNCTION_ARGS); +extern Datum regconfigin(PG_FUNCTION_ARGS); +extern Datum regconfigout(PG_FUNCTION_ARGS); +extern Datum regconfigrecv(PG_FUNCTION_ARGS); +extern Datum regconfigsend(PG_FUNCTION_ARGS); +extern Datum regdictionaryin(PG_FUNCTION_ARGS); +extern Datum regdictionaryout(PG_FUNCTION_ARGS); +extern Datum regdictionaryrecv(PG_FUNCTION_ARGS); +extern Datum regdictionarysend(PG_FUNCTION_ARGS); +extern Datum text_regclass(PG_FUNCTION_ARGS); +extern List* stringToQualifiedNameList(const char* string); +extern char* format_procedure(Oid procedure_oid); +extern char* format_operator(Oid operator_oid); + +/* rowtypes.c */ +extern Datum record_in(PG_FUNCTION_ARGS); +extern Datum record_out(PG_FUNCTION_ARGS); +extern Datum record_recv(PG_FUNCTION_ARGS); +extern Datum record_send(PG_FUNCTION_ARGS); +extern Datum record_eq(PG_FUNCTION_ARGS); +extern Datum record_ne(PG_FUNCTION_ARGS); +extern Datum record_lt(PG_FUNCTION_ARGS); +extern Datum record_gt(PG_FUNCTION_ARGS); +extern Datum record_le(PG_FUNCTION_ARGS); +extern Datum record_ge(PG_FUNCTION_ARGS); +extern Datum btrecordcmp(PG_FUNCTION_ARGS); + +/* ruleutils.c */ +extern Datum pg_get_ruledef(PG_FUNCTION_ARGS); +extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_wrap(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_name(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_name_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_indexdef(PG_FUNCTION_ARGS); +extern Datum pg_get_indexdef_ext(PG_FUNCTION_ARGS); +extern char* pg_get_indexdef_string(Oid indexrelid); +extern char* pg_get_indexdef_columns(Oid indexrelid, bool pretty); +extern Datum pg_get_triggerdef(PG_FUNCTION_ARGS); +extern Datum pg_get_triggerdef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_constraintdef(PG_FUNCTION_ARGS); +extern Datum pg_get_constraintdef_ext(PG_FUNCTION_ARGS); +extern char* pg_get_constraintdef_string(Oid constraintId); +extern Datum pg_get_expr(PG_FUNCTION_ARGS); +extern Datum pg_get_expr_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_userbyid(PG_FUNCTION_ARGS); +extern Datum pg_get_serial_sequence(PG_FUNCTION_ARGS); +extern Datum pg_get_functiondef(PG_FUNCTION_ARGS); +extern Datum pg_get_function_arguments(PG_FUNCTION_ARGS); +extern Datum pg_get_function_identity_arguments(PG_FUNCTION_ARGS); +extern Datum pg_get_function_result(PG_FUNCTION_ARGS); +extern char* deparse_expression( + Node* expr, List* dpcontext, bool forceprefix, bool showimplicit, bool no_alias = false); +extern char* deparse_create_sequence(Node* stmt, bool owned_by_none = false); +extern char* deparse_alter_sequence(Node* stmt, bool owned_by_none = false); + +#ifdef PGXC +extern void deparse_query(Query* query, StringInfo buf, List* parentnamespace, bool finalise_aggs, bool sortgroup_colno, + void* parserArg = NULL, bool qrw_phase = false, bool is_fqs = false); +extern void deparse_targetlist(Query* query, List* targetList, StringInfo buf); +#endif +extern List* deparse_context_for(const char* aliasname, Oid relid); +extern List* deparse_context_for_planstate(Node* planstate, List* ancestors, List* rtable); +#ifdef PGXC +extern List* deparse_context_for_plan(Node* plan, List* ancestors, List* rtable); +#endif +extern const char* quote_identifier(const char* ident); +extern char* quote_qualified_identifier(const char* qualifier, const char* ident); +extern char* generate_collation_name(Oid collid); +extern void get_utility_stmt_def(AlterTableStmt* stmt, StringInfo buf); + +/* tid.c */ +extern Datum tidin(PG_FUNCTION_ARGS); +extern Datum tidout(PG_FUNCTION_ARGS); +extern Datum tidrecv(PG_FUNCTION_ARGS); +extern Datum tidsend(PG_FUNCTION_ARGS); +extern Datum tideq(PG_FUNCTION_ARGS); +extern Datum tidne(PG_FUNCTION_ARGS); +extern Datum tidlt(PG_FUNCTION_ARGS); +extern Datum tidle(PG_FUNCTION_ARGS); +extern Datum tidgt(PG_FUNCTION_ARGS); +extern Datum tidge(PG_FUNCTION_ARGS); +extern Datum bttidcmp(PG_FUNCTION_ARGS); +extern Datum tidlarger(PG_FUNCTION_ARGS); +extern Datum tidsmaller(PG_FUNCTION_ARGS); +extern Datum bigint_tid(PG_FUNCTION_ARGS); +extern Datum cstore_tid_out(PG_FUNCTION_ARGS); +extern Datum currtid_byreloid(PG_FUNCTION_ARGS); +extern Datum currtid_byrelname(PG_FUNCTION_ARGS); + +/* varchar.c */ +extern Datum bpcharlenb(PG_FUNCTION_ARGS); +extern Datum bpcharin(PG_FUNCTION_ARGS); +extern Datum bpcharout(PG_FUNCTION_ARGS); +extern Datum bpcharrecv(PG_FUNCTION_ARGS); +extern Datum bpcharsend(PG_FUNCTION_ARGS); +extern Datum bpchartypmodin(PG_FUNCTION_ARGS); +extern Datum bpchartypmodout(PG_FUNCTION_ARGS); +extern Datum bpchar(PG_FUNCTION_ARGS); +extern Datum char_bpchar(PG_FUNCTION_ARGS); +extern Datum name_bpchar(PG_FUNCTION_ARGS); +extern Datum bpchar_name(PG_FUNCTION_ARGS); +extern Datum bpchareq(PG_FUNCTION_ARGS); +extern Datum bpcharne(PG_FUNCTION_ARGS); +extern Datum bpcharlt(PG_FUNCTION_ARGS); +extern Datum bpcharle(PG_FUNCTION_ARGS); +extern Datum bpchargt(PG_FUNCTION_ARGS); +extern Datum bpcharge(PG_FUNCTION_ARGS); +extern Datum bpcharcmp(PG_FUNCTION_ARGS); +extern Datum bpchar_larger(PG_FUNCTION_ARGS); +extern Datum bpchar_smaller(PG_FUNCTION_ARGS); +extern int bpchartruelen(const char* s, int len); +extern Datum bpcharlen(PG_FUNCTION_ARGS); +extern int bcTruelen(BpChar* arg); +extern Datum bpcharoctetlen(PG_FUNCTION_ARGS); +extern Datum hashbpchar(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_lt(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_le(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_gt(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_ge(PG_FUNCTION_ARGS); +extern Datum btbpchar_pattern_cmp(PG_FUNCTION_ARGS); + +extern Datum varcharin(PG_FUNCTION_ARGS); +extern Datum varcharout(PG_FUNCTION_ARGS); +extern Datum varcharrecv(PG_FUNCTION_ARGS); +extern Datum varcharsend(PG_FUNCTION_ARGS); +extern Datum varchartypmodin(PG_FUNCTION_ARGS); +extern Datum varchartypmodout(PG_FUNCTION_ARGS); +extern Datum varchar_transform(PG_FUNCTION_ARGS); +extern Datum varchar(PG_FUNCTION_ARGS); + +extern Datum nvarchar2in(PG_FUNCTION_ARGS); +extern Datum nvarchar2out(PG_FUNCTION_ARGS); +extern Datum nvarchar2recv(PG_FUNCTION_ARGS); +extern Datum nvarchar2send(PG_FUNCTION_ARGS); +extern Datum nvarchar2typmodin(PG_FUNCTION_ARGS); +extern Datum nvarchar2typmodout(PG_FUNCTION_ARGS); +extern Datum nvarchar2(PG_FUNCTION_ARGS); + +/* varlena.c */ +extern text* cstring_to_text(const char* s); +extern text* cstring_to_text_with_len(const char* s, size_t len); +extern bytea *cstring_to_bytea_with_len(const char *s, int len); +extern char* text_to_cstring(const text* t); +extern void text_to_cstring_buffer(const text* src, char* dst, size_t dst_len); +extern int text_instr_3args(text* textStr, text* textStrToSearch, int32 beginIndex); +extern int text_instr_4args(text* textStr, text* textStrToSearch, int32 beginIndex, int occurTimes); +extern int32 text_length(Datum str); +extern int text_cmp(text* arg1, text* arg2, Oid collid); +extern text* text_substring(Datum str, int32 start, int32 length, bool length_not_specified); +extern Datum instr_3args(PG_FUNCTION_ARGS); +extern Datum instr_4args(PG_FUNCTION_ARGS); +extern Datum byteain(PG_FUNCTION_ARGS); +extern void text_to_bktmap(text* gbucket, uint2* bktmap, int len); + +#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s)) +#define TextDatumGetCString(d) text_to_cstring((text*)DatumGetPointer(d)) + +#define CStringGetByteaDatum(s, len) PointerGetDatum(cstring_to_bytea_with_len(s, len)) + +extern Datum rawin(PG_FUNCTION_ARGS); +extern Datum rawout(PG_FUNCTION_ARGS); +extern Datum rawtotext(PG_FUNCTION_ARGS); +extern Datum texttoraw(PG_FUNCTION_ARGS); +extern Datum raweq(PG_FUNCTION_ARGS); +extern Datum rawne(PG_FUNCTION_ARGS); +extern Datum rawlt(PG_FUNCTION_ARGS); +extern Datum rawle(PG_FUNCTION_ARGS); +extern Datum rawgt(PG_FUNCTION_ARGS); +extern Datum rawge(PG_FUNCTION_ARGS); +extern Datum rawcmp(PG_FUNCTION_ARGS); +extern Datum rawcat(PG_FUNCTION_ARGS); +extern Datum rawlike(PG_FUNCTION_ARGS); +extern Datum rawnlike(PG_FUNCTION_ARGS); +extern Datum textin(PG_FUNCTION_ARGS); +extern Datum textout(PG_FUNCTION_ARGS); +extern Datum textrecv(PG_FUNCTION_ARGS); +extern Datum textsend(PG_FUNCTION_ARGS); +extern Datum textcat(PG_FUNCTION_ARGS); +extern Datum texteq(PG_FUNCTION_ARGS); +extern Datum textne(PG_FUNCTION_ARGS); +extern Datum text_lt(PG_FUNCTION_ARGS); +extern Datum text_le(PG_FUNCTION_ARGS); +extern Datum text_gt(PG_FUNCTION_ARGS); +extern Datum text_ge(PG_FUNCTION_ARGS); +extern Datum text_larger(PG_FUNCTION_ARGS); +extern Datum text_smaller(PG_FUNCTION_ARGS); +extern Datum text_pattern_lt(PG_FUNCTION_ARGS); +extern Datum text_pattern_le(PG_FUNCTION_ARGS); +extern Datum text_pattern_gt(PG_FUNCTION_ARGS); +extern Datum text_pattern_ge(PG_FUNCTION_ARGS); +extern Datum bttext_pattern_cmp(PG_FUNCTION_ARGS); +extern Datum textlen(PG_FUNCTION_ARGS); +extern Datum textoctetlen(PG_FUNCTION_ARGS); +extern Datum textpos(PG_FUNCTION_ARGS); +extern Datum text_substr(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len(PG_FUNCTION_ARGS); +extern Datum text_substr_null(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len_null(PG_FUNCTION_ARGS); +extern Datum text_substr_orclcompat(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len_orclcompat(PG_FUNCTION_ARGS); +extern Datum bytea_substr_orclcompat(PG_FUNCTION_ARGS); +extern Datum bytea_substr_no_len_orclcompat(PG_FUNCTION_ARGS); +extern Datum textoverlay(PG_FUNCTION_ARGS); +extern Datum textoverlay_no_len(PG_FUNCTION_ARGS); +extern Datum name_text(PG_FUNCTION_ARGS); +extern Datum text_name(PG_FUNCTION_ARGS); +extern int varstr_cmp(char* arg1, int len1, char* arg2, int len2, Oid collid); +extern void varstr_sortsupport(SortSupport ssup, Oid collid, bool bpchar); +extern List* textToQualifiedNameList(text* textval); +extern bool SplitIdentifierString(char* rawstring, char separator, List** namelist, bool downCase = true, bool truncateToolong = true); +extern bool SplitIdentifierInteger(char* rawstring, char separator, List** namelist); +extern Datum replace_text(PG_FUNCTION_ARGS); +extern text* replace_text_regexp(text* src_text, void* regexp, text* replace_text, bool glob); +extern Datum split_text(PG_FUNCTION_ARGS); +extern Datum text_to_array(PG_FUNCTION_ARGS); +extern Datum array_to_text(PG_FUNCTION_ARGS); +extern Datum text_to_array_null(PG_FUNCTION_ARGS); +extern Datum array_to_text_null(PG_FUNCTION_ARGS); +extern Datum to_hex32(PG_FUNCTION_ARGS); +extern Datum to_hex64(PG_FUNCTION_ARGS); +extern Datum md5_text(PG_FUNCTION_ARGS); +extern Datum md5_bytea(PG_FUNCTION_ARGS); + +extern Datum unknownin(PG_FUNCTION_ARGS); +extern Datum unknownout(PG_FUNCTION_ARGS); +extern Datum unknownrecv(PG_FUNCTION_ARGS); +extern Datum unknownsend(PG_FUNCTION_ARGS); + +extern Datum pg_column_size(PG_FUNCTION_ARGS); +extern Datum datalength(PG_FUNCTION_ARGS); + +extern Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS); +extern Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum string_agg_transfn(PG_FUNCTION_ARGS); +extern Datum string_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum checksumtext_agg_transfn(PG_FUNCTION_ARGS); + +extern Datum list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum list_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int2_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int2_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int4_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int4_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int8_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int8_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum float4_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum float4_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum float8_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum float8_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum numeric_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum numeric_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum date_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum date_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum timestamp_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum timestamp_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum timestamptz_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum timestamptz_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum interval_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum interval_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); + +extern Datum text_concat(PG_FUNCTION_ARGS); +extern Datum text_concat_ws(PG_FUNCTION_ARGS); +extern Datum text_left(PG_FUNCTION_ARGS); +extern Datum text_right(PG_FUNCTION_ARGS); +extern Datum text_reverse(PG_FUNCTION_ARGS); +extern Datum text_format(PG_FUNCTION_ARGS); +extern Datum text_format_nv(PG_FUNCTION_ARGS); + +/* byteawithoutorderwithequalcol.cpp */ +extern Datum byteawithoutordercolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoltypmodin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoltypmodout(PG_FUNCTION_ARGS); + +/* version.c */ +extern Datum pgsql_version(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pgxc_version(PG_FUNCTION_ARGS); +#endif + +/* xid.c */ +extern Datum xidin(PG_FUNCTION_ARGS); +extern Datum xidout(PG_FUNCTION_ARGS); +extern Datum xidrecv(PG_FUNCTION_ARGS); +extern Datum xidsend(PG_FUNCTION_ARGS); +extern Datum xideq(PG_FUNCTION_ARGS); +extern Datum xidlt(PG_FUNCTION_ARGS); +extern Datum xid_age(PG_FUNCTION_ARGS); +extern Datum xidin4(PG_FUNCTION_ARGS); +extern Datum xidout4(PG_FUNCTION_ARGS); +extern Datum xidrecv4(PG_FUNCTION_ARGS); +extern Datum xidsend4(PG_FUNCTION_ARGS); +extern Datum xideq4(PG_FUNCTION_ARGS); +extern Datum xidlt4(PG_FUNCTION_ARGS); +extern int xidComparator(const void* arg1, const void* arg2); +extern Datum cidin(PG_FUNCTION_ARGS); +extern Datum cidout(PG_FUNCTION_ARGS); +extern Datum cidrecv(PG_FUNCTION_ARGS); +extern Datum cidsend(PG_FUNCTION_ARGS); +extern Datum cideq(PG_FUNCTION_ARGS); +extern int RemoveRepetitiveXids(TransactionId* xids, int nxid); + +/* like.c */ +#define LIKE_TRUE 1 +#define LIKE_FALSE 0 +#define LIKE_ABORT (-1) + +extern Datum namelike(PG_FUNCTION_ARGS); +extern Datum namenlike(PG_FUNCTION_ARGS); +extern Datum nameiclike(PG_FUNCTION_ARGS); +extern Datum nameicnlike(PG_FUNCTION_ARGS); +extern Datum textlike(PG_FUNCTION_ARGS); +extern Datum textnlike(PG_FUNCTION_ARGS); +extern Datum texticlike(PG_FUNCTION_ARGS); +extern Datum texticnlike(PG_FUNCTION_ARGS); +extern Datum bytealike(PG_FUNCTION_ARGS); +extern Datum byteanlike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollikebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlikebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollikebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlikebyteal(PG_FUNCTION_ARGS); +extern Datum like_escape(PG_FUNCTION_ARGS); +extern Datum like_escape_bytea(PG_FUNCTION_ARGS); +extern int GenericMatchText(char* s, int slen, char* p, int plen); + +/* a_compat.c */ +extern Datum lower(PG_FUNCTION_ARGS); +extern Datum upper(PG_FUNCTION_ARGS); +extern Datum initcap(PG_FUNCTION_ARGS); +extern Datum lpad(PG_FUNCTION_ARGS); +extern Datum rpad(PG_FUNCTION_ARGS); +extern Datum btrim(PG_FUNCTION_ARGS); +extern Datum btrim1(PG_FUNCTION_ARGS); +extern Datum byteatrim(PG_FUNCTION_ARGS); +extern Datum ltrim(PG_FUNCTION_ARGS); +extern Datum ltrim1(PG_FUNCTION_ARGS); +extern Datum rtrim(PG_FUNCTION_ARGS); +extern Datum rtrim1(PG_FUNCTION_ARGS); +extern Datum translate(PG_FUNCTION_ARGS); +extern Datum chr(PG_FUNCTION_ARGS); +extern Datum repeat(PG_FUNCTION_ARGS); +extern Datum ascii(PG_FUNCTION_ARGS); + +/* inet_cidr_ntop.c */ +extern char* inet_cidr_ntop(int af, const void* src, int bits, char* dst, size_t size); + +/* inet_net_pton.c */ +extern int inet_net_pton(int af, const char* src, void* dst, size_t size); + +/* network.c */ +extern Datum inet_in(PG_FUNCTION_ARGS); +extern Datum inet_out(PG_FUNCTION_ARGS); +extern Datum inet_recv(PG_FUNCTION_ARGS); +extern Datum inet_send(PG_FUNCTION_ARGS); +extern Datum cidr_in(PG_FUNCTION_ARGS); +extern Datum cidr_out(PG_FUNCTION_ARGS); +extern Datum cidr_recv(PG_FUNCTION_ARGS); +extern Datum cidr_send(PG_FUNCTION_ARGS); +extern Datum network_cmp(PG_FUNCTION_ARGS); +extern Datum network_lt(PG_FUNCTION_ARGS); +extern Datum network_le(PG_FUNCTION_ARGS); +extern Datum network_eq(PG_FUNCTION_ARGS); +extern Datum network_ge(PG_FUNCTION_ARGS); +extern Datum network_gt(PG_FUNCTION_ARGS); +extern Datum network_ne(PG_FUNCTION_ARGS); +extern Datum hashinet(PG_FUNCTION_ARGS); +extern Datum network_sub(PG_FUNCTION_ARGS); +extern Datum network_subeq(PG_FUNCTION_ARGS); +extern Datum network_sup(PG_FUNCTION_ARGS); +extern Datum network_supeq(PG_FUNCTION_ARGS); +extern Datum network_network(PG_FUNCTION_ARGS); +extern Datum network_netmask(PG_FUNCTION_ARGS); +extern Datum network_hostmask(PG_FUNCTION_ARGS); +extern Datum network_masklen(PG_FUNCTION_ARGS); +extern Datum network_family(PG_FUNCTION_ARGS); +extern Datum network_broadcast(PG_FUNCTION_ARGS); +extern Datum network_host(PG_FUNCTION_ARGS); +extern Datum network_show(PG_FUNCTION_ARGS); +extern Datum inet_abbrev(PG_FUNCTION_ARGS); +extern Datum cidr_abbrev(PG_FUNCTION_ARGS); +extern double convert_network_to_scalar(Datum value, Oid typid); +extern Datum inet_to_cidr(PG_FUNCTION_ARGS); +extern Datum inet_set_masklen(PG_FUNCTION_ARGS); +extern Datum cidr_set_masklen(PG_FUNCTION_ARGS); +extern Datum network_scan_first(Datum in); +extern Datum network_scan_last(Datum in); +extern Datum inet_client_addr(PG_FUNCTION_ARGS); +extern Datum inet_client_port(PG_FUNCTION_ARGS); +extern Datum inet_server_addr(PG_FUNCTION_ARGS); +extern Datum inet_server_port(PG_FUNCTION_ARGS); +extern Datum inetnot(PG_FUNCTION_ARGS); +extern Datum inetand(PG_FUNCTION_ARGS); +extern Datum inetor(PG_FUNCTION_ARGS); +extern Datum inetpl(PG_FUNCTION_ARGS); +extern Datum inetmi_int8(PG_FUNCTION_ARGS); +extern Datum inetmi(PG_FUNCTION_ARGS); +extern void clean_ipv6_addr(int addr_family, char* addr); + +/* mac.c */ +extern Datum macaddr_in(PG_FUNCTION_ARGS); +extern Datum macaddr_out(PG_FUNCTION_ARGS); +extern Datum macaddr_recv(PG_FUNCTION_ARGS); +extern Datum macaddr_send(PG_FUNCTION_ARGS); +extern Datum macaddr_cmp(PG_FUNCTION_ARGS); +extern Datum macaddr_lt(PG_FUNCTION_ARGS); +extern Datum macaddr_le(PG_FUNCTION_ARGS); +extern Datum macaddr_eq(PG_FUNCTION_ARGS); +extern Datum macaddr_ge(PG_FUNCTION_ARGS); +extern Datum macaddr_gt(PG_FUNCTION_ARGS); +extern Datum macaddr_ne(PG_FUNCTION_ARGS); +extern Datum macaddr_not(PG_FUNCTION_ARGS); +extern Datum macaddr_and(PG_FUNCTION_ARGS); +extern Datum macaddr_or(PG_FUNCTION_ARGS); +extern Datum macaddr_trunc(PG_FUNCTION_ARGS); +extern Datum hashmacaddr(PG_FUNCTION_ARGS); + +/* numeric.c */ +extern Datum numeric_in(PG_FUNCTION_ARGS); +extern Datum numeric_out(PG_FUNCTION_ARGS); +extern Datum numeric_recv(PG_FUNCTION_ARGS); +extern Datum numeric_send(PG_FUNCTION_ARGS); +extern Datum numerictypmodin(PG_FUNCTION_ARGS); +extern Datum numerictypmodout(PG_FUNCTION_ARGS); +extern Datum numeric_transform(PG_FUNCTION_ARGS); +extern Datum numeric(PG_FUNCTION_ARGS); +extern Datum numeric_abs(PG_FUNCTION_ARGS); +extern Datum numeric_uminus(PG_FUNCTION_ARGS); +extern Datum numeric_uplus(PG_FUNCTION_ARGS); +extern Datum numeric_sign(PG_FUNCTION_ARGS); +extern Datum numeric_round(PG_FUNCTION_ARGS); +extern Datum numeric_trunc(PG_FUNCTION_ARGS); +extern Datum numeric_ceil(PG_FUNCTION_ARGS); +extern Datum numeric_floor(PG_FUNCTION_ARGS); +extern Datum numeric_cmp(PG_FUNCTION_ARGS); +extern Datum numeric_eq(PG_FUNCTION_ARGS); +extern Datum numeric_ne(PG_FUNCTION_ARGS); +extern Datum numeric_gt(PG_FUNCTION_ARGS); +extern Datum numeric_ge(PG_FUNCTION_ARGS); +extern Datum numeric_lt(PG_FUNCTION_ARGS); +extern Datum numeric_le(PG_FUNCTION_ARGS); +extern Datum numeric_add(PG_FUNCTION_ARGS); +extern Datum numeric_sub(PG_FUNCTION_ARGS); +extern Datum numeric_mul(PG_FUNCTION_ARGS); +extern Datum numeric_div(PG_FUNCTION_ARGS); +extern Datum numeric_div_trunc(PG_FUNCTION_ARGS); +extern Datum numeric_mod(PG_FUNCTION_ARGS); +extern Datum numeric_inc(PG_FUNCTION_ARGS); +extern Datum numeric_smaller(PG_FUNCTION_ARGS); +extern Datum numeric_larger(PG_FUNCTION_ARGS); +extern Datum numeric_fac(PG_FUNCTION_ARGS); +extern Datum numeric_sqrt(PG_FUNCTION_ARGS); +extern Datum numeric_exp(PG_FUNCTION_ARGS); +extern Datum numeric_ln(PG_FUNCTION_ARGS); +extern Datum numeric_log(PG_FUNCTION_ARGS); +extern Datum numeric_power(PG_FUNCTION_ARGS); +extern Datum int4_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int4(PG_FUNCTION_ARGS); +extern Datum int8_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int8(PG_FUNCTION_ARGS); +extern Datum int2_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int2(PG_FUNCTION_ARGS); +extern Datum int1_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int1(PG_FUNCTION_ARGS); +extern Datum float8_numeric(PG_FUNCTION_ARGS); +extern Datum float8_interval(PG_FUNCTION_ARGS); +extern Datum numeric_float8(PG_FUNCTION_ARGS); +extern Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS); +extern Datum float4_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_float4(PG_FUNCTION_ARGS); +extern Datum numeric_accum(PG_FUNCTION_ARGS); +extern Datum numeric_avg_accum(PG_FUNCTION_ARGS); +extern Datum int2_accum(PG_FUNCTION_ARGS); +extern Datum int4_accum(PG_FUNCTION_ARGS); +extern Datum int8_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum numeric_collect(PG_FUNCTION_ARGS); +#endif +extern Datum int8_avg_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum numeric_avg_collect(PG_FUNCTION_ARGS); +#endif +extern Datum numeric_avg(PG_FUNCTION_ARGS); +extern Datum numeric_var_pop(PG_FUNCTION_ARGS); +extern Datum numeric_var_samp(PG_FUNCTION_ARGS); +extern Datum numeric_stddev_pop(PG_FUNCTION_ARGS); +extern Datum numeric_stddev_samp(PG_FUNCTION_ARGS); +extern Datum int2_sum(PG_FUNCTION_ARGS); +extern Datum int4_sum(PG_FUNCTION_ARGS); +extern Datum int8_sum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum int8_sum_to_int8(PG_FUNCTION_ARGS); +#endif +extern Datum int1_avg_accum(PG_FUNCTION_ARGS); +extern Datum int2_avg_accum(PG_FUNCTION_ARGS); +extern Datum int4_avg_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum int8_avg_collect(PG_FUNCTION_ARGS); +#endif +extern Datum int8_avg(PG_FUNCTION_ARGS); +extern Datum width_bucket_numeric(PG_FUNCTION_ARGS); +extern Datum hash_numeric(PG_FUNCTION_ARGS); +extern Datum numtodsinterval(PG_FUNCTION_ARGS); +extern Datum numeric_interval(PG_FUNCTION_ARGS); +extern Datum int1_interval(PG_FUNCTION_ARGS); +extern Datum int2_interval(PG_FUNCTION_ARGS); +extern Datum int4_interval(PG_FUNCTION_ARGS); + +/* ri_triggers.c */ +extern Datum RI_FKey_check_ins(PG_FUNCTION_ARGS); +extern Datum RI_FKey_check_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_noaction_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_noaction_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_cascade_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_cascade_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_restrict_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_restrict_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setnull_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setnull_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setdefault_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setdefault_upd(PG_FUNCTION_ARGS); + +/* trigfuncs.c */ +extern Datum suppress_redundant_updates_trigger(PG_FUNCTION_ARGS); + +/* encoding support functions */ +extern Datum getdatabaseencoding(PG_FUNCTION_ARGS); +extern Datum database_character_set(PG_FUNCTION_ARGS); +extern Datum pg_client_encoding(PG_FUNCTION_ARGS); +extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS); +extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS); +extern Datum PG_character_set_name(PG_FUNCTION_ARGS); +extern Datum PG_character_set_id(PG_FUNCTION_ARGS); +extern Datum pg_convert(PG_FUNCTION_ARGS); +extern Datum pg_convert_to(PG_FUNCTION_ARGS); +extern Datum pg_convert_nocase(PG_FUNCTION_ARGS); +extern Datum pg_convert_to_nocase(PG_FUNCTION_ARGS); +extern Datum pg_convert_from(PG_FUNCTION_ARGS); +extern Datum length_in_encoding(PG_FUNCTION_ARGS); +extern Datum pg_encoding_max_length_sql(PG_FUNCTION_ARGS); + +/* format_type.c */ +extern Datum format_type(PG_FUNCTION_ARGS); +extern char* format_type_be(Oid type_oid); +extern char* format_type_with_typemod(Oid type_oid, int32 typemod); +extern Datum oidvectortypes(PG_FUNCTION_ARGS); +extern int32 type_maximum_size(Oid type_oid, int32 typemod); + +/* quote.c */ +extern Datum quote_ident(PG_FUNCTION_ARGS); +extern Datum quote_literal(PG_FUNCTION_ARGS); +extern char* quote_literal_cstr(const char* rawstr); +extern Datum quote_nullable(PG_FUNCTION_ARGS); + +/* guc.c */ +extern Datum show_config_by_name(PG_FUNCTION_ARGS); +extern Datum set_config_by_name(PG_FUNCTION_ARGS); +extern Datum show_all_settings(PG_FUNCTION_ARGS); + +/* lockfuncs.c */ +extern Datum pg_lock_status(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_all(PG_FUNCTION_ARGS); + +/* txid.c */ +extern Datum txid_snapshot_in(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_out(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_recv(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_send(PG_FUNCTION_ARGS); +extern Datum txid_current(PG_FUNCTION_ARGS); +extern Datum txid_current_snapshot(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xmin(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xmax(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xip(PG_FUNCTION_ARGS); +extern Datum txid_visible_in_snapshot(PG_FUNCTION_ARGS); +extern Datum pgxc_snapshot_status(PG_FUNCTION_ARGS); + +/* uuid.c */ +extern Datum uuid_in(PG_FUNCTION_ARGS); +extern Datum uuid_out(PG_FUNCTION_ARGS); +extern Datum uuid_send(PG_FUNCTION_ARGS); +extern Datum uuid_recv(PG_FUNCTION_ARGS); +extern Datum uuid_lt(PG_FUNCTION_ARGS); +extern Datum uuid_le(PG_FUNCTION_ARGS); +extern Datum uuid_eq(PG_FUNCTION_ARGS); +extern Datum uuid_ge(PG_FUNCTION_ARGS); +extern Datum uuid_gt(PG_FUNCTION_ARGS); +extern Datum uuid_ne(PG_FUNCTION_ARGS); +extern Datum uuid_cmp(PG_FUNCTION_ARGS); +extern Datum uuid_hash(PG_FUNCTION_ARGS); + +/* windowfuncs.c */ +extern Datum window_row_number(PG_FUNCTION_ARGS); +extern Datum window_rank(PG_FUNCTION_ARGS); +extern Datum window_dense_rank(PG_FUNCTION_ARGS); +extern Datum window_percent_rank(PG_FUNCTION_ARGS); +extern Datum window_cume_dist(PG_FUNCTION_ARGS); +extern Datum window_ntile(PG_FUNCTION_ARGS); +extern Datum window_lag(PG_FUNCTION_ARGS); +extern Datum window_lag_with_offset(PG_FUNCTION_ARGS); +extern Datum window_lag_with_offset_and_default(PG_FUNCTION_ARGS); +extern Datum window_lead(PG_FUNCTION_ARGS); +extern Datum window_lead_with_offset(PG_FUNCTION_ARGS); +extern Datum window_lead_with_offset_and_default(PG_FUNCTION_ARGS); +extern Datum window_first_value(PG_FUNCTION_ARGS); +extern Datum window_last_value(PG_FUNCTION_ARGS); +extern Datum window_nth_value(PG_FUNCTION_ARGS); +extern Datum window_delta(PG_FUNCTION_ARGS); + +/* access/spgist/spgquadtreeproc.c */ +extern Datum spg_quad_config(PG_FUNCTION_ARGS); +extern Datum spg_quad_choose(PG_FUNCTION_ARGS); +extern Datum spg_quad_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_quad_inner_consistent(PG_FUNCTION_ARGS); +extern Datum spg_quad_leaf_consistent(PG_FUNCTION_ARGS); + +/* access/spgist/spgkdtreeproc.c */ +extern Datum spg_kd_config(PG_FUNCTION_ARGS); +extern Datum spg_kd_choose(PG_FUNCTION_ARGS); +extern Datum spg_kd_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_kd_inner_consistent(PG_FUNCTION_ARGS); + +/* access/spgist/spgtextproc.c */ +extern Datum spg_text_config(PG_FUNCTION_ARGS); +extern Datum spg_text_choose(PG_FUNCTION_ARGS); +extern Datum spg_text_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_text_inner_consistent(PG_FUNCTION_ARGS); +extern Datum spg_text_leaf_consistent(PG_FUNCTION_ARGS); + +/* access/gin/ginarrayproc.c */ +extern Datum ginarrayextract(PG_FUNCTION_ARGS); +extern Datum ginarrayextract_2args(PG_FUNCTION_ARGS); +extern Datum ginqueryarrayextract(PG_FUNCTION_ARGS); +extern Datum ginarrayconsistent(PG_FUNCTION_ARGS); +extern Datum ginarraytriconsistent(PG_FUNCTION_ARGS); + +/* storage/ipc/procarray.c */ +extern Datum pg_get_running_xacts(PG_FUNCTION_ARGS); +extern Datum pgxc_gtm_snapshot_status(PG_FUNCTION_ARGS); +extern Datum get_gtm_lite_status(PG_FUNCTION_ARGS); + +/* access/transam/twophase.c */ +extern Datum pg_prepared_xact(PG_FUNCTION_ARGS); +extern Datum pg_parse_clog(PG_FUNCTION_ARGS); + +/* postmaster.c */ +extern Datum pg_log_comm_status(PG_FUNCTION_ARGS); +extern Datum set_working_grand_version_num_manually(PG_FUNCTION_ARGS); + +/* access/transam/varsup.c */ +extern Datum pg_check_xidlimit(PG_FUNCTION_ARGS); +extern Datum pg_get_xidlimit(PG_FUNCTION_ARGS); +extern Datum pg_get_variable_info(PG_FUNCTION_ARGS); + +/* catalogs/dependency.c */ +extern Datum pg_describe_object(PG_FUNCTION_ARGS); + +/* commands/constraint.c */ +extern Datum unique_key_recheck(PG_FUNCTION_ARGS); + +/* commands/extension.c */ +extern Datum pg_available_extensions(PG_FUNCTION_ARGS); +extern Datum pg_available_extension_versions(PG_FUNCTION_ARGS); +extern Datum pg_extension_update_paths(PG_FUNCTION_ARGS); +extern Datum pg_extension_config_dump(PG_FUNCTION_ARGS); + +/* commands/prepare.c */ +extern Datum pg_prepared_statement(PG_FUNCTION_ARGS); + +/* utils/mmgr/portalmem.c */ +extern Datum pg_cursor(PG_FUNCTION_ARGS); + +/* utils/adt/pgstatfuncs.c */ +extern Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_changed(PG_FUNCTION_ARGS); + +#ifdef PGXC +/* backend/pgxc/pool/poolutils.c */ +extern Datum pgxc_pool_check(PG_FUNCTION_ARGS); +extern Datum pgxc_pool_reload(PG_FUNCTION_ARGS); +extern Datum pgxc_pool_connection_status(PG_FUNCTION_ARGS); +extern Datum pg_pool_validate(PG_FUNCTION_ARGS); +extern Datum pg_pool_ping(PG_FUNCTION_ARGS); +extern Datum comm_check_connection_status(PG_FUNCTION_ARGS); +#endif + +/* backend/access/transam/transam.c */ +#ifdef PGXC +extern Datum pgxc_is_committed(PG_FUNCTION_ARGS); +extern Datum pgxc_get_csn(PG_FUNCTION_ARGS); +#endif + +/*adapt A db's empty_blob*/ +extern Datum get_empty_blob(PG_FUNCTION_ARGS); +/*adapt A db's substr*/ +extern Datum substrb_with_lenth(PG_FUNCTION_ARGS); +extern Datum substrb_without_lenth(PG_FUNCTION_ARGS); +/*aes encrypt/decrypt function*/ +extern Datum gs_encrypt_aes128(PG_FUNCTION_ARGS); +extern Datum gs_decrypt_aes128(PG_FUNCTION_ARGS); +extern ScalarVector* vtimestamp_part(PG_FUNCTION_ARGS); +extern ScalarVector* vint4mul(PG_FUNCTION_ARGS); +extern ScalarVector* vint4mi(PG_FUNCTION_ARGS); +extern ScalarVector* vint4pl(PG_FUNCTION_ARGS); +extern ScalarVector* vtextlike(PG_FUNCTION_ARGS); +extern ScalarVector* vtextnlike(PG_FUNCTION_ARGS); +extern ScalarVector* vtextne(PG_FUNCTION_ARGS); +extern ScalarVector* vlower(PG_FUNCTION_ARGS); +extern ScalarVector* vupper(PG_FUNCTION_ARGS); +extern ScalarVector* vlpad(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vsnumeric_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_abs(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_fac(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_ne(PG_FUNCTION_ARGS); +extern ScalarVector* vinterval_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vcash_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vintervalpl(PG_FUNCTION_ARGS); +extern ScalarVector* vbpcharlen(PG_FUNCTION_ARGS); + +extern Datum int1_text(PG_FUNCTION_ARGS); +extern Datum int2_text(PG_FUNCTION_ARGS); +extern Datum int4_text(PG_FUNCTION_ARGS); +extern Datum int8_text(PG_FUNCTION_ARGS); +extern Datum float4_text(PG_FUNCTION_ARGS); +extern Datum float8_text(PG_FUNCTION_ARGS); +extern Datum numeric_text(PG_FUNCTION_ARGS); +extern Datum bpchar_numeric(PG_FUNCTION_ARGS); +extern Datum varchar_numeric(PG_FUNCTION_ARGS); +extern Datum varchar_int4(PG_FUNCTION_ARGS); +extern Datum bpchar_int4(PG_FUNCTION_ARGS); +extern Datum varchar_int8(PG_FUNCTION_ARGS); +extern Datum timestampzone_text(PG_FUNCTION_ARGS); +extern Datum timestamp_text(PG_FUNCTION_ARGS); +extern Datum timestamp_varchar(PG_FUNCTION_ARGS); +extern Datum timestamp_diff(PG_FUNCTION_ARGS); +extern Datum int1_varchar(PG_FUNCTION_ARGS); +extern Datum int2_varchar(PG_FUNCTION_ARGS); +extern Datum int4_varchar(PG_FUNCTION_ARGS); +extern Datum int8_varchar(PG_FUNCTION_ARGS); +extern Datum int8_bpchar(PG_FUNCTION_ARGS); +extern Datum numeric_varchar(PG_FUNCTION_ARGS); +extern Datum numeric_bpchar(PG_FUNCTION_ARGS); +extern Datum float4_varchar(PG_FUNCTION_ARGS); +extern Datum float8_varchar(PG_FUNCTION_ARGS); +extern Datum int1_nvarchar2(PG_FUNCTION_ARGS); +extern Datum varchar_timestamp(PG_FUNCTION_ARGS); +extern Datum bpchar_timestamp(PG_FUNCTION_ARGS); +extern Datum text_int1(PG_FUNCTION_ARGS); +extern Datum text_int2(PG_FUNCTION_ARGS); +extern Datum text_int4(PG_FUNCTION_ARGS); +extern Datum text_int8(PG_FUNCTION_ARGS); +extern Datum text_float4(PG_FUNCTION_ARGS); +extern Datum text_float8(PG_FUNCTION_ARGS); +extern Datum text_numeric(PG_FUNCTION_ARGS); +extern Datum getDistributeKey(PG_FUNCTION_ARGS); +extern Datum text_timestamp(PG_FUNCTION_ARGS); +extern void encryptOBS(char* srcplaintext, char destciphertext[], uint32 destcipherlength); +extern void decryptOBS( + const char* srcciphertext, char destplaintext[], uint32 destplainlength, const char* obskey = NULL); +extern void encryptECString(char* src_plain_text, char* dest_cipher_text, uint32 dest_cipher_length); +extern void decryptECString(const char* src_cipher_text, char* dest_plain_text, uint32 dest_plain_length); +extern bool IsECEncryptedString(const char* src_cipher_text); + +/* fencedudf.cpp */ +extern Datum fenced_udf_process(PG_FUNCTION_ARGS); +extern Datum gs_extend_library(PG_FUNCTION_ARGS); + +/* cstore_am.cpp */ +extern Datum cupointer_bigint(PG_FUNCTION_ARGS); +extern void encryptBlockOrCUData( + const char* plainText, const size_t plainLength, char* cipherText, size_t* cipherLength); +extern void decryptBlockOrCUData( + const char* cipherText, const size_t cipherLength, char* plainText, size_t* plainLength); +extern bool isEncryptedCluster(); + +/* pg_lsn.cpp */ +extern Datum pg_lsn_in(PG_FUNCTION_ARGS); + +// template function implementation +// + +/* client logic */ +extern Datum globalsettingin(PG_FUNCTION_ARGS); +extern Datum columnsettingin(PG_FUNCTION_ARGS); + +/* tsdb */ +extern Datum add_job_class_depend_internal(PG_FUNCTION_ARGS); +extern Datum remove_job_class_depend_internal(PG_FUNCTION_ARGS); +extern Datum series_internal(PG_FUNCTION_ARGS); +extern Datum top_key_internal(PG_FUNCTION_ARGS); +extern Datum job_cancel(PG_FUNCTION_ARGS); +extern void job_update(PG_FUNCTION_ARGS); +extern Datum submit_job_on_nodes(PG_FUNCTION_ARGS); +extern Datum isubmit_job_on_nodes(PG_FUNCTION_ARGS); +extern Datum isubmit_job_on_nodes_internal(PG_FUNCTION_ARGS); + +/* AI */ +extern Datum gs_index_advise(PG_FUNCTION_ARGS); +extern Datum hypopg_create_index(PG_FUNCTION_ARGS); +extern Datum hypopg_display_index(PG_FUNCTION_ARGS); +extern Datum hypopg_drop_index(PG_FUNCTION_ARGS); +extern Datum hypopg_estimate_size(PG_FUNCTION_ARGS); +extern Datum hypopg_reset_index(PG_FUNCTION_ARGS); + +/* MOT */ +extern Datum mot_global_memory_detail(PG_FUNCTION_ARGS); +extern Datum mot_local_memory_detail(PG_FUNCTION_ARGS); +extern Datum mot_session_memory_detail(PG_FUNCTION_ARGS); + +#endif /* !FRONTEND_PARSER */ +#endif /* BUILTINS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/bytea.h postgresql-hll-2.14/include/include/utils/bytea.h --- postgresql-hll-2.14_old/include/include/utils/bytea.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/bytea.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * bytea.h + * Declarations for BYTEA data type support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/bytea.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BYTEA_H +#define BYTEA_H + +#include "fmgr.h" + +typedef enum { BYTEA_OUTPUT_ESCAPE, BYTEA_OUTPUT_HEX } ByteaOutputType; + +/* functions are in utils/adt/varlena.c */ +extern Datum byteain(PG_FUNCTION_ARGS); +extern Datum byteaout(PG_FUNCTION_ARGS); +extern Datum bytearecv(PG_FUNCTION_ARGS); +extern Datum byteasend(PG_FUNCTION_ARGS); +extern Datum byteaoctetlen(PG_FUNCTION_ARGS); +extern Datum byteaGetByte(PG_FUNCTION_ARGS); +extern Datum byteaGetBit(PG_FUNCTION_ARGS); +extern Datum byteaSetByte(PG_FUNCTION_ARGS); +extern Datum byteaSetBit(PG_FUNCTION_ARGS); +extern Datum byteaeq(PG_FUNCTION_ARGS); +extern Datum byteane(PG_FUNCTION_ARGS); +extern Datum bytealt(PG_FUNCTION_ARGS); +extern Datum byteale(PG_FUNCTION_ARGS); +extern Datum byteagt(PG_FUNCTION_ARGS); +extern Datum byteage(PG_FUNCTION_ARGS); +extern Datum byteacmp(PG_FUNCTION_ARGS); +extern Datum bytea_sortsupport(PG_FUNCTION_ARGS); +extern Datum byteacat(PG_FUNCTION_ARGS); +extern Datum byteapos(PG_FUNCTION_ARGS); +extern Datum bytea_substr(PG_FUNCTION_ARGS); +extern Datum bytea_substr_no_len(PG_FUNCTION_ARGS); +extern Datum byteaoverlay(PG_FUNCTION_ARGS); +extern Datum byteaoverlay_no_len(PG_FUNCTION_ARGS); + +#endif /* BYTEA_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/cash.h postgresql-hll-2.14/include/include/utils/cash.h --- postgresql-hll-2.14_old/include/include/utils/cash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/cash.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,77 @@ +/* + * src/include/utils/cash.h + * + * + * cash.h + * Written by D'Arcy J.M. Cain + * + * Functions to allow input and output of money normally but store + * and handle it as 64 bit integer. + */ + +#ifndef CASH_H +#define CASH_H + +#include "fmgr.h" + +typedef int64 Cash; + +/* Cash is pass-by-reference if and only if int64 is */ +#define DatumGetCash(X) ((Cash)DatumGetInt64(X)) +#define CashGetDatum(X) Int64GetDatum(X) +#define PG_GETARG_CASH(n) DatumGetCash(PG_GETARG_DATUM(n)) +#define PG_RETURN_CASH(x) return CashGetDatum(x) + +extern Datum cash_in(PG_FUNCTION_ARGS); +extern Datum cash_out(PG_FUNCTION_ARGS); +extern Datum cash_recv(PG_FUNCTION_ARGS); +extern Datum cash_send(PG_FUNCTION_ARGS); + +extern Datum cash_eq(PG_FUNCTION_ARGS); +extern Datum cash_ne(PG_FUNCTION_ARGS); +extern Datum cash_lt(PG_FUNCTION_ARGS); +extern Datum cash_le(PG_FUNCTION_ARGS); +extern Datum cash_gt(PG_FUNCTION_ARGS); +extern Datum cash_ge(PG_FUNCTION_ARGS); +extern Datum cash_cmp(PG_FUNCTION_ARGS); + +extern Datum cash_pl(PG_FUNCTION_ARGS); +extern Datum cash_mi(PG_FUNCTION_ARGS); +extern Datum cash_div_cash(PG_FUNCTION_ARGS); + +extern Datum cash_mul_flt8(PG_FUNCTION_ARGS); +extern Datum flt8_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_flt8(PG_FUNCTION_ARGS); + +extern Datum cash_mul_flt4(PG_FUNCTION_ARGS); +extern Datum flt4_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_flt4(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int8(PG_FUNCTION_ARGS); +extern Datum int8_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int8(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int4(PG_FUNCTION_ARGS); +extern Datum int4_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int4(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int2(PG_FUNCTION_ARGS); +extern Datum int2_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int2(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int1(PG_FUNCTION_ARGS); +extern Datum int1_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int1(PG_FUNCTION_ARGS); + +extern Datum cashlarger(PG_FUNCTION_ARGS); +extern Datum cashsmaller(PG_FUNCTION_ARGS); + +extern Datum cash_words(PG_FUNCTION_ARGS); + +extern Datum cash_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_cash(PG_FUNCTION_ARGS); + +extern Datum int4_cash(PG_FUNCTION_ARGS); +extern Datum int8_cash(PG_FUNCTION_ARGS); + +#endif /* CASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/catcache.h postgresql-hll-2.14/include/include/utils/catcache.h --- postgresql-hll-2.14_old/include/include/utils/catcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/catcache.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------------- + * + * catcache.h + * Low-level catalog cache definitions. + * + * NOTE: every catalog cache must have a corresponding unique index on + * the system table that it caches --- ie, the index must match the keys + * used to do lookups in this cache. All cache fetches are done with + * indexscans (under normal conditions). The index should be unique to + * guarantee that there can only be one matching row for a key combination. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/catcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATCACHE_H +#define CATCACHE_H + +#include "access/htup.h" +#include "access/skey.h" +#include "lib/dllist.h" +#include "utils/relcache.h" + +/* + * struct catctup: individual tuple in the cache. + * struct catclist: list of tuples matching a partial key. + * struct catcache: information for managing a cache. + * struct catcacheheader: information for managing all the caches. + */ + +#define CATCACHE_MAXKEYS 4 + +/* function computing a datum's hash */ +typedef uint32 (*CCHashFN)(Datum datum); + +/* function computing equality of two datums */ +typedef bool (*CCFastEqualFN)(Datum a, Datum b); + +typedef struct CatCache { + int id; /* cache identifier --- see syscache.h */ + int cc_nbuckets; /* # of hash buckets in this cache */ + CatCache* cc_next; /* link to next catcache */ + const char* cc_relname; /* name of relation the tuples come from */ + TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */ + CCHashFN cc_hashfunc[CATCACHE_MAXKEYS]; /* hash function for each key */ + CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS]; /* fast equal function for each key */ + Oid cc_reloid; /* OID of relation the tuples come from */ + Oid cc_indexoid; /* OID of index matching cache keys */ + int cc_ntup; /* # of tuples currently in this cache */ + int cc_nkeys; /* # of keys (1..CATCACHE_MAXKEYS) */ + int cc_keyno[CATCACHE_MAXKEYS]; /* AttrNumber of each key */ + bool cc_relisshared; /* is relation shared across databases? */ + Dllist cc_lists; /* list of CatCList structs */ + ScanKeyData cc_skey[CATCACHE_MAXKEYS]; /* precomputed key info for + * heap scans */ +#ifdef CATCACHE_STATS + long cc_searches; /* total # searches against this cache */ + long cc_hits; /* # of matches against existing entry */ + long cc_neg_hits; /* # of matches against negative entry */ + long cc_newloads; /* # of successful loads of new entry */ + + /* + * cc_searches - (cc_hits + cc_neg_hits + cc_newloads) is number of failed + * searches, each of which will result in loading a negative entry + */ + long cc_invals; /* # of entries invalidated from cache */ + long cc_lsearches; /* total # list-searches */ + long cc_lhits; /* # of matches against existing lists */ +#endif + Dllist cc_bucket[FLEXIBLE_ARRAY_MEMBER]; /* hash buckets --- VARIABLE LENGTH ARRAY */ +} CatCache; /* VARIABLE LENGTH STRUCT */ + +typedef struct catctup { + int ct_magic; /* for identifying CatCTup entries */ +#define CT_MAGIC 0x57261502 + + uint32 hash_value; /* hash value for this tuple's keys */ + + /* + * Lookup keys for the entry. By-reference datums point into the tuple for + * positive cache entries, and are separately allocated for negative ones. + */ + Datum keys[CATCACHE_MAXKEYS]; + + /* + * Each tuple in a cache is a member of a Dllist that stores the elements + * of its hash bucket. We keep each Dllist in LRU order to speed repeated + * lookups. + */ + Dlelem cache_elem; /* list member of per-bucket list */ + + /* + * A tuple marked "dead" must not be returned by subsequent searches. + * However, it won't be physically deleted from the cache until its + * refcount goes to zero. (If it's a member of a CatCList, the list's + * refcount must go to zero, too; also, remember to mark the list dead at + * the same time the tuple is marked.) + * + * A negative cache entry is an assertion that there is no tuple matching + * a particular key. This is just as useful as a normal entry so far as + * avoiding catalog searches is concerned. Management of positive and + * negative entries is identical. + */ + int refcount; /* number of active references */ + bool dead; /* dead but not yet removed? */ + bool negative; /* negative cache entry? */ + bool isnailed; /* indicate if we can reomve this cattup from syscache or not */ + HeapTupleData tuple; /* tuple management header */ + + /* + * The tuple may also be a member of at most one CatCList. (If a single + * catcache is list-searched with varying numbers of keys, we may have to + * make multiple entries for the same tuple because of this restriction. + * Currently, that's not expected to be common, so we accept the potential + * inefficiency.) + */ + struct catclist* c_list; /* containing CatCList, or NULL if none */ + CatCache* my_cache; /* link to owning catcache */ +} CatCTup; + +/* + * A CatCList describes the result of a partial search, ie, a search using + * only the first K key columns of an N-key cache. We form the keys used + * into a tuple (with other attributes NULL) to represent the stored key + * set. The CatCList object contains links to cache entries for all the + * table rows satisfying the partial key. (Note: none of these will be + * negative cache entries.) + * + * A CatCList is only a member of a per-cache list; we do not currently + * divide them into hash buckets. + * + * A list marked "dead" must not be returned by subsequent searches. + * However, it won't be physically deleted from the cache until its + * refcount goes to zero. (A list should be marked dead if any of its + * member entries are dead.) + * + * If "ordered" is true then the member tuples appear in the order of the + * cache's underlying index. This will be true in normal operation, but + * might not be true during bootstrap or recovery operations. (namespace.c + * is able to save some cycles when it is true.) + */ +typedef struct catclist { + int cl_magic; /* for identifying CatCList entries */ +#define CL_MAGIC 0x52765103 + + uint32 hash_value; /* hash value for lookup keys */ + + Dlelem cache_elem; /* list member of per-catcache list */ + + /* + * Lookup keys for the entry, with the first nkeys elements being valid. + * All by-reference are separately allocated. + */ + Datum keys[CATCACHE_MAXKEYS]; + + int refcount; /* number of active references */ + bool dead; /* dead but not yet removed? */ + bool isnailed; /* indicate if we can reomve this catlist from syscache or not */ + bool ordered; /* members listed in index order? */ + short nkeys; /* number of lookup keys specified */ + int n_members; /* number of member tuples */ + CatCache* my_cache; /* link to owning catcache */ + CatCTup* members[FLEXIBLE_ARRAY_MEMBER]; /* members --- VARIABLE LENGTH ARRAY */ +} CatCList; /* VARIABLE LENGTH STRUCT */ + +typedef struct CatCacheHeader { + CatCache* ch_caches; /* head of list of CatCache structs */ + int ch_ntup; /* # of tuples in all caches */ +} CatCacheHeader; + +extern void AtEOXact_CatCache(bool isCommit); + +extern CatCache* InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int* key, int nbuckets); +extern void InitCatCachePhase2(CatCache* cache, bool touch_index); + +extern HeapTuple SearchCatCache(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4, int level); +extern HeapTuple SearchCatCache1(CatCache* cache, Datum v1); +extern HeapTuple SearchCatCache2(CatCache* cache, Datum v1, Datum v2); +extern HeapTuple SearchCatCache3(CatCache* cache, Datum v1, Datum v2, Datum v3); +extern HeapTuple SearchCatCache4(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4); + +extern void ReleaseCatCache(HeapTuple tuple); + +extern uint32 GetCatCacheHashValue(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4); + +extern CatCList* SearchCatCacheList(CatCache* cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4); +extern void ReleaseCatCacheList(CatCList* list); + +extern void ReleaseTempCatList(const List* volatile ctlist, CatCache* cache); + +extern void ResetCatalogCaches(void); +extern void CatalogCacheFlushCatalog(Oid catId); +extern void CatalogCacheIdInvalidate(int cacheId, uint32 hashValue); +extern void PrepareToInvalidateCacheTuple( + Relation relation, HeapTuple tuple, HeapTuple newtuple, void (*function)(int, uint32, Oid)); + +extern void PrintCatCacheLeakWarning(HeapTuple tuple); +extern void PrintCatCacheListLeakWarning(CatCList* list); +extern bool RelationInvalidatesSnapshotsOnly(Oid); +extern bool RelationHasSysCache(Oid); +extern void InsertBuiltinFuncInBootstrap(); +#endif /* CATCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/clientlogic_bytea.h postgresql-hll-2.14/include/include/utils/clientlogic_bytea.h --- postgresql-hll-2.14_old/include/include/utils/clientlogic_bytea.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/clientlogic_bytea.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * clientlogic_bytea.h + * + * IDENTIFICATION + * src\include\utils\clientlogic_bytea.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include "fmgr.h" + +typedef enum { + ENCRYPTEDCOL_OUTPUT_ESCAPE, + ENCRYPTEDCOL_OUTPUT_HEX +} EncryptedColOutputType; + +extern THR_LOCAL int byteawithoutorderwithequalcol_output; /* ByteaOutputType, but int for GUC enum */ + +/* functions are in utils/adt/varlena.c */ +extern Datum byteawithoutorderwithequalcolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolout(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolrecv(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolsend(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloctetlen(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolGetByte(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolGetBit(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolSetByte(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolSetBit(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleq(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolne(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollt(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolle(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgt(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolge(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmp(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleqbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolltbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgtbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmpbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleqbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolltbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgtbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmpbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_sortsupport(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolpos(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_substr(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_substr_no_len(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloverlay(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloverlay_no_len(PG_FUNCTION_ARGS); diff -uprN postgresql-hll-2.14_old/include/include/utils/combocid.h postgresql-hll-2.14/include/include/utils/combocid.h --- postgresql-hll-2.14_old/include/include/utils/combocid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/combocid.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * combocid.h + * Combo command ID support routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/combocid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COMBOCID_H +#define COMBOCID_H + +/* + * HeapTupleHeaderGetCmin and HeapTupleHeaderGetCmax function prototypes + * are in access/htup.h, because that's where the macro definitions that + * those functions replaced used to be. + */ + +extern void AtEOXact_ComboCid(void); + +extern void StreamTxnContextSaveComboCid(void* stc); +extern void StreamTxnContextRestoreComboCid(void* stc); + +#endif /* COMBOCID_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/date.h postgresql-hll-2.14/include/include/utils/date.h --- postgresql-hll-2.14_old/include/include/utils/date.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/date.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------- + * + * date.h + * Definitions for the SQL92 "date" and "time" types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/date.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATE_H +#define DATE_H + +#include + +#include "fmgr.h" +#include "timestamp.h" + +typedef int32 DateADT; + +#ifdef HAVE_INT64_TIMESTAMP +typedef int64 TimeADT; +#else +typedef float8 TimeADT; +#endif + +typedef struct { + TimeADT time; /* all time units other than months and years */ + int32 zone; /* numeric time zone, in seconds */ +} TimeTzADT; + +/* + * Infinity and minus infinity must be the max and min values of DateADT. + * We could use INT_MIN and INT_MAX here, but seems better to not assume that + * int32 == int. + */ +#define DATEVAL_NOBEGIN ((DateADT)(-0x7fffffff - 1)) +#define DATEVAL_NOEND ((DateADT)0x7fffffff) + +#define DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN) +#define DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN) +#define DATE_NOEND(j) ((j) = DATEVAL_NOEND) +#define DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND) +#define DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j)) + +/* + * Macros for fmgr-callable functions. + * + * For TimeADT, we make use of the same support routines as for float8 or int64. + * Therefore TimeADT is pass-by-reference if and only if float8 or int64 is! + */ +#ifdef HAVE_INT64_TIMESTAMP + +#define MAX_TIME_PRECISION 6 + +#define DatumGetDateADT(X) ((DateADT)DatumGetInt32(X)) +#define DatumGetTimeADT(X) ((TimeADT)DatumGetInt64(X)) +#define DatumGetTimeTzADTP(X) ((TimeTzADT*)DatumGetPointer(X)) + +#define DateADTGetDatum(X) Int32GetDatum(X) +#define TimeADTGetDatum(X) Int64GetDatum(X) +#define TimeTzADTPGetDatum(X) PointerGetDatum(X) +#else /* !HAVE_INT64_TIMESTAMP */ + +#define MAX_TIME_PRECISION 10 + +/* round off to MAX_TIME_PRECISION decimal places */ +#define TIME_PREC_INV 10000000000.0 +#define TIMEROUND(j) (rint(((double)(j)) * TIME_PREC_INV) / TIME_PREC_INV) + +#define DatumGetDateADT(X) ((DateADT)DatumGetInt32(X)) +#define DatumGetTimeADT(X) ((TimeADT)DatumGetFloat8(X)) +#define DatumGetTimeTzADTP(X) ((TimeTzADT*)DatumGetPointer(X)) + +#define DateADTGetDatum(X) Int32GetDatum(X) +#define TimeADTGetDatum(X) Float8GetDatum(X) +#define TimeTzADTPGetDatum(X) PointerGetDatum(X) +#endif /* HAVE_INT64_TIMESTAMP */ + +#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x) +#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x) +#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x) + +/* date.c */ +extern double date2timestamp_no_overflow(DateADT dateVal); + +extern Datum date_in(PG_FUNCTION_ARGS); +extern Datum date_out(PG_FUNCTION_ARGS); +extern Datum date_recv(PG_FUNCTION_ARGS); +extern Datum date_send(PG_FUNCTION_ARGS); +extern Datum date_eq(PG_FUNCTION_ARGS); +extern Datum date_ne(PG_FUNCTION_ARGS); +extern Datum date_lt(PG_FUNCTION_ARGS); +extern Datum date_le(PG_FUNCTION_ARGS); +extern Datum date_gt(PG_FUNCTION_ARGS); +extern Datum date_ge(PG_FUNCTION_ARGS); +extern Datum date_cmp(PG_FUNCTION_ARGS); +extern Datum date_sortsupport(PG_FUNCTION_ARGS); +extern Datum date_finite(PG_FUNCTION_ARGS); +extern Datum date_larger(PG_FUNCTION_ARGS); +extern Datum date_smaller(PG_FUNCTION_ARGS); +extern Datum date_mi(PG_FUNCTION_ARGS); +extern Datum date_pli(PG_FUNCTION_ARGS); +extern Datum date_mii(PG_FUNCTION_ARGS); +extern Datum date_eq_timestamp(PG_FUNCTION_ARGS); +extern Datum date_ne_timestamp(PG_FUNCTION_ARGS); +extern Datum date_lt_timestamp(PG_FUNCTION_ARGS); +extern Datum date_le_timestamp(PG_FUNCTION_ARGS); +extern Datum date_gt_timestamp(PG_FUNCTION_ARGS); +extern Datum date_ge_timestamp(PG_FUNCTION_ARGS); +extern Datum date_cmp_timestamp(PG_FUNCTION_ARGS); +extern Datum date_eq_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_ne_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_lt_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_le_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_gt_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_ge_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_cmp_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_eq_date(PG_FUNCTION_ARGS); +extern Datum timestamp_ne_date(PG_FUNCTION_ARGS); +extern Datum timestamp_lt_date(PG_FUNCTION_ARGS); +extern Datum timestamp_le_date(PG_FUNCTION_ARGS); +extern Datum timestamp_gt_date(PG_FUNCTION_ARGS); +extern Datum timestamp_ge_date(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_eq_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_ne_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_lt_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_le_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_gt_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_ge_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_cmp_date(PG_FUNCTION_ARGS); +extern Datum date_pl_interval(PG_FUNCTION_ARGS); +extern Datum date_mi_interval(PG_FUNCTION_ARGS); +extern Datum date_timestamp(PG_FUNCTION_ARGS); +extern Datum date_text(PG_FUNCTION_ARGS); +extern Datum date_varchar(PG_FUNCTION_ARGS); +extern Datum date_bpchar(PG_FUNCTION_ARGS); +extern Datum varchar_date(PG_FUNCTION_ARGS); +extern Datum bpchar_date(PG_FUNCTION_ARGS); +extern Datum text_date(PG_FUNCTION_ARGS); + +extern Datum timestamp2date(Timestamp timestamp); +extern Datum timestamp_date(PG_FUNCTION_ARGS); +extern Datum date_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamptz_date(PG_FUNCTION_ARGS); +extern Datum datetime_timestamp(PG_FUNCTION_ARGS); +extern Datum abstime_date(PG_FUNCTION_ARGS); +extern Timestamp date2timestamp(DateADT dateVal); + +extern Datum time_in(PG_FUNCTION_ARGS); +extern Datum time_out(PG_FUNCTION_ARGS); +extern Datum time_recv(PG_FUNCTION_ARGS); +extern Datum time_send(PG_FUNCTION_ARGS); +extern Datum timetypmodin(PG_FUNCTION_ARGS); +extern Datum timetypmodout(PG_FUNCTION_ARGS); +extern Datum time_transform(PG_FUNCTION_ARGS); +extern Datum time_scale(PG_FUNCTION_ARGS); +extern Datum time_eq(PG_FUNCTION_ARGS); +extern Datum time_ne(PG_FUNCTION_ARGS); +extern Datum time_lt(PG_FUNCTION_ARGS); +extern Datum time_le(PG_FUNCTION_ARGS); +extern Datum time_gt(PG_FUNCTION_ARGS); +extern Datum time_ge(PG_FUNCTION_ARGS); +extern Datum time_cmp(PG_FUNCTION_ARGS); +extern Datum time_hash(PG_FUNCTION_ARGS); +extern Datum overlaps_time(PG_FUNCTION_ARGS); +extern Datum time_larger(PG_FUNCTION_ARGS); +extern Datum time_smaller(PG_FUNCTION_ARGS); +extern Datum time_mi_time(PG_FUNCTION_ARGS); +extern Datum timestamp_time(PG_FUNCTION_ARGS); +extern Datum timestamptz_time(PG_FUNCTION_ARGS); +extern Datum time_interval(PG_FUNCTION_ARGS); +extern Datum interval_time(PG_FUNCTION_ARGS); +extern Datum time_pl_interval(PG_FUNCTION_ARGS); +extern Datum time_mi_interval(PG_FUNCTION_ARGS); +extern Datum time_part(PG_FUNCTION_ARGS); + +extern Datum timetz_in(PG_FUNCTION_ARGS); +extern Datum timetz_out(PG_FUNCTION_ARGS); +extern Datum timetz_recv(PG_FUNCTION_ARGS); +extern Datum timetz_send(PG_FUNCTION_ARGS); +extern Datum timetztypmodin(PG_FUNCTION_ARGS); +extern Datum timetztypmodout(PG_FUNCTION_ARGS); +extern Datum timetz_scale(PG_FUNCTION_ARGS); +extern Datum timetz_eq_withhead(PG_FUNCTION_ARGS); +extern Datum timetz_eq(PG_FUNCTION_ARGS); +extern Datum timetz_ne(PG_FUNCTION_ARGS); +extern Datum timetz_lt(PG_FUNCTION_ARGS); +extern Datum timetz_le(PG_FUNCTION_ARGS); +extern Datum timetz_gt(PG_FUNCTION_ARGS); +extern Datum timetz_ge(PG_FUNCTION_ARGS); +extern Datum timetz_cmp(PG_FUNCTION_ARGS); +extern Datum timetz_hash(PG_FUNCTION_ARGS); +extern Datum overlaps_timetz(PG_FUNCTION_ARGS); +extern Datum timetz_larger(PG_FUNCTION_ARGS); +extern Datum timetz_smaller(PG_FUNCTION_ARGS); +extern Datum timetz_time(PG_FUNCTION_ARGS); +extern Datum time_timetz(PG_FUNCTION_ARGS); +extern Datum timestamptz_timetz(PG_FUNCTION_ARGS); +extern Datum datetimetz_timestamptz(PG_FUNCTION_ARGS); +extern Datum timetz_part(PG_FUNCTION_ARGS); +extern Datum timetz_zone(PG_FUNCTION_ARGS); +extern Datum timetz_izone(PG_FUNCTION_ARGS); +extern Datum timetz_pl_interval(PG_FUNCTION_ARGS); +extern Datum timetz_mi_interval(PG_FUNCTION_ARGS); + +#endif /* DATE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/datetime.h postgresql-hll-2.14/include/include/utils/datetime.h --- postgresql-hll-2.14_old/include/include/utils/datetime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/datetime.h 2020-12-12 17:06:43.283348503 +0800 @@ -0,0 +1,309 @@ +/* ------------------------------------------------------------------------- + * + * datetime.h + * Definitions for date/time support code. + * The support code is shared with other date data types, + * including abstime, reltime, date, and time. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/datetime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATETIME_H +#define DATETIME_H + +#include "nodes/nodes.h" +#include "utils/timestamp.h" + +/* this struct is declared in utils/tzparser.h: */ +struct tzEntry; + +/* ---------------------------------------------------------------- + * time types + support macros + * + * String definitions for standard time quantities. + * + * These strings are the defaults used to form output time strings. + * Other alternative forms are hardcoded into token tables in datetime.c. + * ---------------------------------------------------------------- + */ + +#define DAGO "ago" +#define DCURRENT "current" +#define EPOCH "epoch" +#define INVALID "invalid" +#define EARLY "-infinity" +#define LATE "infinity" +#define NOW "now" +#define TODAY "today" +#define TOMORROW "tomorrow" +#define YESTERDAY "yesterday" +#define ZULU "zulu" + +#define DMICROSEC "usecond" +#define DMILLISEC "msecond" +#define DSECOND "second" +#define DMINUTE "minute" +#define DHOUR "hour" +#define DDAY "day" +#define DWEEK "week" +#define DMONTH "month" +#define DQUARTER "quarter" +#define DYEAR "year" +#define DDECADE "decade" +#define DCENTURY "century" +#define DMILLENNIUM "millennium" +#define DA_D "ad" +#define DB_C "bc" +#define DTIMEZONE "timezone" + +/* + * Fundamental time field definitions for parsing. + * + * Meridian: am, pm, or 24-hour style. + * Millennium: ad, bc + */ + +#define AM 0 +#define PM 1 +#define HR24 2 + +#define AD 0 +#define BC 1 + +/* + * Fields for time decoding. + * + * Can't have more of these than there are bits in an unsigned int + * since these are turned into bit masks during parsing and decoding. + * + * Furthermore, the values for YEAR, MONTH, DAY, HOUR, MINUTE, SECOND + * must be in the range 0..14 so that the associated bitmasks can fit + * into the left half of an INTERVAL's typmod value. Since those bits + * are stored in typmods, you can't change them without initdb! + */ + +#define RESERV 0 +#define MONTH 1 +#define YEAR 2 +#define DAY 3 +#define JULIAN 4 +#define TZ 5 +#define DTZ 6 +#define DTZMOD 7 +#define IGNORE_DTF 8 +#define AMPM 9 +#define HOUR 10 +#define MINUTE 11 +#define SECOND 12 +#define MILLISECOND 13 +#define MICROSECOND 14 +#define DOY 15 +#define DOW 16 +#define UNITS 17 +#define ADBC 18 +/* these are only for relative dates */ +#define AGO 19 +#define ABS_BEFORE 20 +#define ABS_AFTER 21 +/* generic fields to help with parsing */ +#define ISODATE 22 +#define ISOTIME 23 +/* these are only for parsing intervals */ +#define WEEK 24 +#define DECADE 25 +#define CENTURY 26 +#define MILLENNIUM 27 +/* reserved for unrecognized string values */ +#define UNKNOWN_FIELD 31 + +/* + * Token field definitions for time parsing and decoding. + * These need to fit into the datetkn table type. + * At the moment, that means keep them within [-127,127]. + * These are also used for bit masks in DecodeDateDelta() + * so actually restrict them to within [0,31] for now. + * - thomas 97/06/19 + * Not all of these fields are used for masks in DecodeDateDelta + * so allow some larger than 31. - thomas 1997-11-17 + */ + +#define DTK_NUMBER 0 +#define DTK_STRING 1 + +#define DTK_DATE 2 +#define DTK_TIME 3 +#define DTK_TZ 4 +#define DTK_AGO 5 + +#define DTK_SPECIAL 6 +#define DTK_INVALID 7 +#define DTK_CURRENT 8 +#define DTK_EARLY 9 +#define DTK_LATE 10 +#define DTK_EPOCH 11 +#define DTK_NOW 12 +#define DTK_YESTERDAY 13 +#define DTK_TODAY 14 +#define DTK_TOMORROW 15 +#define DTK_ZULU 16 + +#define DTK_DELTA 17 +#define DTK_SECOND 18 +#define DTK_MINUTE 19 +#define DTK_HOUR 20 +#define DTK_DAY 21 +#define DTK_WEEK 22 +#define DTK_MONTH 23 +#define DTK_QUARTER 24 +#define DTK_YEAR 25 +#define DTK_DECADE 26 +#define DTK_CENTURY 27 +#define DTK_MILLENNIUM 28 +#define DTK_MILLISEC 29 +#define DTK_MICROSEC 30 +#define DTK_JULIAN 31 + +#define DTK_DOW 32 +#define DTK_DOY 33 +#define DTK_TZ_HOUR 34 +#define DTK_TZ_MINUTE 35 +#define DTK_ISOYEAR 36 +#define DTK_ISODOW 37 + +/* + * Bit mask definitions for time parsing. + */ + +#define DTK_M(t) (0x01 << (t)) + +/* Convenience: a second, plus any fractional component */ +#define DTK_ALL_SECS_M (DTK_M(SECOND) | DTK_M(MILLISECOND) | DTK_M(MICROSECOND)) +#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY)) +#define DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_ALL_SECS_M) + +/* + * Working buffer size for input and output of interval, timestamp, etc. + * Inputs that need more working space will be rejected early. Longer outputs + * will overrun buffers, so this must suffice for all possible output. As of + * this writing, interval_out() needs the most space at ~90 bytes. + */ +#define MAXDATELEN 128 +/* only this many chars are stored in datetktbl */ +#define TOKMAXLEN 10 + +/* keep this struct small; it gets used a lot */ +typedef struct datetkn { + char token[TOKMAXLEN + 1]; + char type; + char value; /* this may be unsigned, alas */ +} datetkn; + +/* one of its uses is in tables of time zone abbreviations */ +typedef struct TimeZoneAbbrevTable { + int numabbrevs; + datetkn abbrevs[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} TimeZoneAbbrevTable; + +/* FMODULO() + * Macro to replace modf(), which is broken on some platforms. + * t = input and remainder + * q = integer part + * u = divisor + */ +#define FMODULO(t, q, u) \ + do { \ + (q) = (((t) < 0) ? ceil((t) / (u)) : floor((t) / (u))); \ + if ((q) != 0) \ + (t) -= rint((q) * (u)); \ + } while (0) + +/* TMODULO() + * Like FMODULO(), but work on the timestamp datatype (either int64 or float8). + * We assume that int64 follows the C99 semantics for division (negative + * quotients truncate towards zero). + */ +#ifdef HAVE_INT64_TIMESTAMP +#define TMODULO(t, q, u) \ + do { \ + (q) = ((t) / (u)); \ + if ((q) != 0) \ + (t) -= ((q) * (u)); \ + } while (0) +#else +#define TMODULO(t, q, u) \ + do { \ + (q) = (((t) < 0) ? ceil((t) / (u)) : floor((t) / (u))); \ + if ((q) != 0) \ + (t) -= rint((q) * (u)); \ + } while (0) +#endif + +/* + * Date/time validation + * Include check for leap year. + */ + +extern const int day_tab[2][13]; + +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) + +/* + * Datetime input parsing routines (ParseDateTime, DecodeDateTime, etc) + * return zero or a positive value on success. On failure, they return + * one of these negative code values. DateTimeParseError may be used to + * produce a correct ereport. + */ +#define DTERR_BAD_FORMAT (-1) +#define DTERR_FIELD_OVERFLOW (-2) +#define DTERR_MD_FIELD_OVERFLOW (-3) /* triggers hint about u_sess->time_cxt.DateStyle */ +#define DTERR_INTERVAL_OVERFLOW (-4) +#define DTERR_TZDISP_OVERFLOW (-5) + +#ifndef FRONTEND_PARSER +extern void GetCurrentDateTime(struct pg_tm* tm); +extern void GetCurrentTimeUsec(struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern void j2date(int jd, int* year, int* month, int* day); +extern int date2j(int year, int month, int day); + +extern int ParseDateTime( + const char* timestr, char* workbuf, size_t buflen, char** field, int* ftype, int maxfields, int* numfields); +extern int DecodeDateTime(char** field, int* ftype, int nf, int* dtype, struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern int DecodeTimeOnly(char** field, int* ftype, int nf, int* dtype, struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern int DecodeInterval( + char** field, const int* ftype, int nf, int range, int* dtype, struct pg_tm* tm, fsec_t* fsec); +extern int DecodeISO8601Interval(char* str, int* dtype, struct pg_tm* tm, fsec_t* fsec); + +extern void DateTimeParseError(int dterr, const char* str, const char* datatype); + +extern int DetermineTimeZoneOffset(struct pg_tm* tm, pg_tz* tzp); + +extern void EncodeDateOnly(struct pg_tm* tm, int style, char* str); +extern void EncodeTimeOnly(struct pg_tm* tm, fsec_t fsec, bool print_tz, int tz, int style, char* str); +extern void EncodeDateTime(struct pg_tm* tm, fsec_t fsec, bool print_tz, int tz, const char* tzn, int style, char* str); +extern void EncodeInterval(struct pg_tm* tm, fsec_t fsec, int style, char* str); + +extern int DecodeSpecial(int field, const char* lowtoken, int* val); +extern int DecodeUnits(int field, const char* lowtoken, int* val); + +extern int j2day(int jd); + +extern Node* TemporalTransform(int32 max_precis, Node* node); + +extern bool CheckDateTokenTables(void); + +extern void ConvertTimeZoneAbbrevs(TimeZoneAbbrevTable* tbl, struct tzEntry* abbrevs, int n); +extern void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable* tbl); + +extern Datum pg_timezone_abbrevs(PG_FUNCTION_ARGS); +extern Datum pg_timezone_names(PG_FUNCTION_ARGS); + +extern Interval *char_to_interval(char *str, int32 typmod); +#endif // !FRONTEND_PARSER + +#endif /* DATETIME_H */ + diff -uprN postgresql-hll-2.14_old/include/include/utils/datum.h postgresql-hll-2.14/include/include/utils/datum.h --- postgresql-hll-2.14_old/include/include/utils/datum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/datum.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * datum.h + * POSTGRES Datum (abstract data type) manipulation routines. + * + * These routines are driven by the 'typbyval' and 'typlen' information, + * which must previously have been obtained by the caller for the datatype + * of the Datum. (We do it this way because in most situations the caller + * can look up the info just once and use it for many per-datum operations.) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/datum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATUM_H +#define DATUM_H + +/* + * datumGetSize - find the "real" length of a datum + */ +extern Size datumGetSize(Datum value, bool typByVal, int typLen); + +/* + * datumCopy - make a copy of a datum. + * + * If the datatype is pass-by-reference, memory is obtained with palloc(). + */ +extern Datum datumCopy(Datum value, bool typByVal, int typLen); + +/* + * datumFree - free a datum previously allocated by datumCopy, if any. + * + * Does nothing if datatype is pass-by-value. + */ +extern void datumFree(Datum value, bool typByVal, int typLen); + +/* + * datumIsEqual + * return true if two datums of the same type are equal, false otherwise. + * + * XXX : See comments in the code for restrictions! + */ +extern bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen); + +#endif /* DATUM_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/dfs_vector.h postgresql-hll-2.14/include/include/utils/dfs_vector.h --- postgresql-hll-2.14_old/include/include/utils/dfs_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/dfs_vector.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,306 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_vector.h + * + * + * + * IDENTIFICATION + * src/include/utils/dfs_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECTOR_H_ +#define VECTOR_H_ + +#include "postgres.h" +#include "securec.h" +#include "securec_check.h" + +/* stands for non-int type */ +struct __type_true {}; + +/* stands for int type */ +struct __type_false {}; + +template +struct _type_traits { + typedef __type_false is_POD_type; +}; + +template <> +struct _type_traits { + typedef __type_true is_POD_type; +}; + +/* + * Afford the dynamic array function. + */ +template +class Vector { +public: + typedef T value_type; + typedef value_type* iterator; + typedef typename _type_traits::is_POD_type is_POD; + + /* Return the start iterator. */ + iterator begin() + { + if (currentSize == 0) { + return 0; + } + + return iterator(vectorHead); + } + + /* Return the last iterator. */ + iterator end() + { + return iterator(vectorHead + currentSize); + } + + /* constructor */ + Vector(int n = 0) : currentSize(n), currentCapacity(n > VECTOR_INIT_SIZE ? n : VECTOR_INIT_SIZE) + { + vectorHead = allocateMemory(is_POD()); + } + + /* constructor */ + Vector(int n, T val) : currentSize(n), currentCapacity(n > VECTOR_INIT_SIZE ? n : VECTOR_INIT_SIZE) + { + vectorHead = allocateMemory(is_POD()); + for (int i = 0; i < n; i++) + vectorHead[i] = val; + } + + /* constructor */ + Vector(const Vector& b) : currentSize(b.currentSize), currentCapacity(b.currentCapacity) + { + errno_t rc = EOK; + + vectorHead = allocateMemory(is_POD()); + if (NULL == vectorHead) { + elog(ERROR, "memory alloc failed!\n"); + } + + rc = memcpy_s(vectorHead, currentCapacity * sizeof(T), b.vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + } + + ~Vector() + { + freeVectorHead(is_POD()); + } + + /* Add a element into the vector. */ + void push_back(T val) + { + /* Current capacity is enough. */ + if (currentSize < currentCapacity) { + vectorHead[currentSize++] = val; + } + /* Enlarge the capacity of vector. */ + else { + currentCapacity = currentCapacity + CAPICITY_INCREASE_STEP; + T* newAllocated = allocateMemory(is_POD()); + errno_t rc = EOK; + rc = memcpy_s(newAllocated, currentCapacity * sizeof(T), vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + newAllocated[currentSize++] = val; + freeVectorHead(is_POD()); + vectorHead = newAllocated; + } + } + + /* Pop off a element from the tail. */ + void pop_back() + { + if (currentSize) + currentSize--; + } + + /* Return the first one. */ + const T& front() const + { + return vectorHead[0]; + } + + /* Return the last one. */ + const T& back() const + { + return vectorHead[currentSize - 1]; + } + + /* Implement the array visit operator. */ + const T& operator[](int i) const + { + return vectorHead[i]; + } + + /* Implement the array visit operator. */ + T& operator[](int i) + { + return vectorHead[i]; + } + + /* Return the size of the current vector. */ + int size() + { + return currentSize; + } + + /* Return the size of the current vector. */ + int size() const + { + return currentSize; + } + + /* Resize the current vector and fill it with the special value. */ + void resize(uint32 new_size, T x) + { + /* Current capacity is enough. */ + if (new_size < currentCapacity) { + if (currentSize < new_size) { + for (uint32 i = currentSize; i < new_size; i++) { + vectorHead[i] = x; + } + } + currentSize = new_size; + } + /* Need to enlarge the capacity. */ + else { + currentCapacity = new_size; + T* newAllocated = allocateMemory(is_POD()); + + if (NULL == newAllocated) { + elog(ERROR, "memory alloc failed!\n"); + } + + errno_t rc = EOK; + + rc = memcpy_s(newAllocated, currentCapacity * sizeof(T), vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + + for (uint32 i = currentSize; i < currentCapacity; i++) { + newAllocated[i] = x; + } + freeVectorHead(is_POD()); + vectorHead = newAllocated; + currentSize = new_size; + } + } + + /* Resize the current vector and fill it with NULL. */ + void resize(int new_size) + { + resize(new_size, (T)0); + } + + /* Return the capacity of the current vector. */ + int capacity() + { + return currentCapacity; + } + + /* Implement the equal check operator. */ + bool operator==(const Vector& b) const + { + for (int i = 0; i < std::min(currentSize, b.currentSize); i++) { + if (!(vectorHead[i] == b.vectorHead[i])) + return false; + } + + return currentSize == b.currentSize; + } + + /* Implement the non-equal check operator. */ + bool operator!=(const Vector& b) const + { + return !(*this == b); + } + + /* Clear the dynamic arrays. */ + void clear() + { + errno_t errNo = EOK; + errNo = ::memset_s(vectorHead, sizeof(T) * currentCapacity, 0, sizeof(T) * currentCapacity); + if (EOK != errNo) { + elog(ERROR, "Initialize memory failed."); + } + currentSize = 0; + } + + /* Erase the element on the special position. */ + iterator erase(iterator postion) + { + if (postion < iterator(vectorHead)) { + return vectorHead; + } + + if (postion >= iterator(vectorHead + currentSize)) { + return vectorHead + currentSize; + } + + T* succeedor = postion + 1; + errno_t errNo = EOK; + errNo = ::memmove_s(postion, end() - succeedor, succeedor, end() - succeedor); + if (EOK != errNo) { + elog(ERROR, "Initialize memory failed."); + } + currentSize--; + + return succeedor; + } + +private: + T* allocateMemory(__type_false) + { + if (currentCapacity == 0) { + return 0; + } + T* newAllocated = new T[currentCapacity]; + return newAllocated; + } + + T* allocateMemory(__type_true) + { + if (currentCapacity == 0) { + return 0; + } + T* newAllocated = (T*)palloc(currentCapacity * sizeof(T)); + return newAllocated; + } + + void freeVectorHead(__type_false) + { + delete[] vectorHead; + vectorHead = NULL; + } + void freeVectorHead(__type_true) + { + pfree(vectorHead); + } + +private: + enum { VECTOR_INIT_SIZE = 25 }; + enum { CAPICITY_INCREASE_STEP = 15 }; + + uint32 currentSize; // size + uint32 currentCapacity; // capacity + T* vectorHead; // value array +}; + +#endif /* VECTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/distribute_test.h postgresql-hll-2.14/include/include/utils/distribute_test.h --- postgresql-hll-2.14_old/include/include/utils/distribute_test.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/distribute_test.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,174 @@ +/* --------------------------------------------------------------------------------------- + * + * distribute_test.h + * Routines for distributed test framework. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/utils/distribute_test.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DISTRIBUTE_TEST_H +#define DISTRIBUTE_TEST_H + +#include "utils/guc.h" +#include "utils/elog.h" + +// work as a switch to enable the macro TEST_STUB +#ifdef USE_ASSERT_CHECKING +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_DISTRIBUTE_TEST +#endif + +#define MAX_GID_STR_LEN (1024) +#define MAX_NAME_STR_LEN (256) +#define DEFAULT_PROBABILITY (0.004) + +/* white-box log handle */ +#define ereport_whitebox_domain(elevel, file, line, func, domain, rest) \ + (errstart(elevel, file, line, func, domain) ? (errfinish rest) : (void)0) + +#define ereport_whitebox(elevel, file, line, func, rest) \ + ereport_whitebox_domain(elevel, file, line, func, TEXTDOMAIN, rest) + +#define WHITEBOX_LOC __FILE__, __LINE__, PG_FUNCNAME_MACRO + +typedef struct DistributeTestParam { + /* use as the guc-control white-box-fault probability + * range [0, 100000], probability 0, 1/100000 -> 1 + */ + int guc_probability; + + /* act as the white-box checkpoint tag, + * eg. "WHITE_BOX_ALL_RANDOM_FAILED" + */ + char test_stub_name[MAX_NAME_STR_LEN]; + + /* fault level, support ERROR and PANIC */ + int elevel; + + /* when white-box fault is WHITEBOX_WAIT, guc can provide "sleep_time" + * for sleep time control, if guc not contain this field, use the default value 30s + */ + int sleep_time; +} DistributeTestParam; + +/* white-box failure injection type definition */ +typedef enum WhiteboxFaillueType { + WHITEBOX_DEFAULT = 0, + WHITEBOX_WAIT, + WHITEBOX_REPEAT, + WHITEBOX_USERDEFINE, + WHITEBOX_BUTT +} WhiteboxFaillueType; + +/* struct created for white-box tesing, support expansion */ +typedef struct WhiteBoxInjectStruct { + /* test location record */ + char filename[MAX_NAME_STR_LEN]; + int lineno; + char funcname[MAX_NAME_STR_LEN]; + + /* failure type, defined above */ + int failureType; + + /* trigger as the probability, 0 -1, if set as 1, definitely trigger */ + double triggerProbability; + + /* white box test info needed */ + TransactionId currentXid; + char currentGid[MAX_GID_STR_LEN]; +} WhiteBoxInjectStruct; + +typedef void (*on_whitebox_callback)(WhiteBoxInjectStruct* wbinfo); +typedef void (*on_add_stub_callback)(void); + +extern bool check_distribute_test_param(char** newval, void** extra, GucSource source); +extern void assign_distribute_test_param(const char* newval, void* extra); +extern bool distribute_test_stub_activator(const char* name, on_add_stub_callback function); +extern void default_error_emit(void); +extern void twophase_default_error_emit(void); +extern bool distribute_whitebox_activator( + const char* name, WhiteBoxInjectStruct* wbinfo, on_whitebox_callback WbCallbackFunc); +extern void default_whitebox_emit(WhiteBoxInjectStruct* wbinfo); +extern bool execute_whitebox( + const char* filename, int lineno, const char* funcname, const char* gid, int failureType, double probability); +extern DistributeTestParam* get_distribute_test_param(); +extern void stub_sleep_emit(void); + +#define TEST_WHITEBOX(_stub_name, _white_box_info, _call_back_func) \ + distribute_whitebox_activator((_stub_name), (_white_box_info), (_call_back_func)) +#define TEST_STUB(_stub_name, _call_back_func) distribute_test_stub_activator((_stub_name), (_call_back_func)) + +/* White-Box Handle Definition */ +#define WHITE_BOX_ALL_RANDOM_FAILED "WHITE_BOX_ALL_RANDOM_FAILED" + +/* GTM exception scenes */ +#define CN_LOCAL_PREPARED_FAILED_A "CN_LOCAL_PREPARED_FAILED_A" +#define CN_LOCAL_PREPARED_FAILED_B "CN_LOCAL_PREPARED_FAILED_B" +#define CN_LOCAL_PREPARED_XLOG_FAILED "CN_LOCAL_PREPARED_XLOG_FAILED" +#define CN_LOCAL_PREPARED_CLOG_FAILED "CN_LOCAL_PREPARED_CLOG_FAILED" +#define CN_PREPARED_SEND_ALL_FAILED "CN_PREPARED_SEND_ALL_FAILED" +#define CN_PREPARED_SEND_PART_FAILED "CN_PREPARED_SEND_PART_FAILED" +#define CN_PREPARED_RESPONSE_FAILED "CN_PREPARED_RESPONSE_FAILED" +#define DN_PREPARED_FAILED "DN_PREPARED_FAILED" +#define CN_PREPARED_MESSAGE_REPEAT "CN_PREPARED_MESSAGE_REPEAT" +#define CN_COMMIT_PREPARED_FAILED "CN_COMMIT_PREPARED_FAILED" +#define DN_COMMIT_PREPARED_FAILED "DN_COMMIT_PREPARED_FAILED" +#define CN_COMMIT_PREPARED_SEND_ALL_FAILED "CN_COMMIT_PREPARED_SEND_ALL_FAILED" +#define CN_COMMIT_PREPARED_SEND_PART_FAILED "CN_COMMIT_PREPARED_SEND_PART_FAILED" +#define CN_COMMIT_PREPARED_RESPONSE_FAILED "CN_COMMIT_PREPARED_RESPONSE_FAILED" +#define CN_COMMIT_PREPARED_MESSAGE_REPEAT "CN_COMMIT_PREPARED_MESSAGE_REPEAT" +#define CN_ABORT_AFTER_ALL_COMMITTED "CN_ABORT_AFTER_ALL_COMMITTED" + +#define CN_ABORT_PREPARED_FAILED "CN_ABORT_PREPARED_FAILED" +#define CN_ABORT_PREPARED_SEND_ALL_FAILED "CN_ABORT_PREPARED_SEND_ALL_FAILED" +#define CN_ABORT_PREPARED_SEND_PART_FAILED "CN_ABORT_PREPARED_SEND_PART_FAILED" +#define CN_ABORT_PREPARED_RESPONSE_FAILED "CN_ABORT_PREPARED_RESPONSE_FAILED" +#define DN_ABORT_PREPARED_FAILED "DN_ABORT_PREPARED_FAILED" + +#define CN_COMMIT_PREPARED_SLEEP "CN_COMMIT_PREPARED_SLEEP" +#define CN_PREPARED_SLEEP "CN_PREPARED_SLEEP" +#define DN_COMMIT_PREPARED_SLEEP "DN_COMMIT_PREPARED_SLEEP" + +/* Exception during subTransaction process */ +#define NON_EXEC_CN_IS_DOWN "NON_EXEC_CN_IS_DOWN" +#define CN_SAVEPOINT_SEND_ALL_FAILED "CN_SAVEPOINT_SEND_ALL_FAILED" +#define CN_SAVEPOINT_SEND_PART_FAILED "CN_SAVEPOINT_SEND_PART_FAILED" +#define CN_SAVEPOINT_RESPONSE_ALL_FAILED "CN_SAVEPOINT_RESPONSE_ALL_FAILED" +#define CN_SAVEPOINT_RESPONSE_PART_FAILED "CN_SAVEPOINT_RESPONSE_PART_FAILED" +#define CN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED "CN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED" +#define DN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED "DN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED" +#define CN_SAVEPOINT_BEFORE_PUSHXACT_FAILED "CN_SAVEPOINT_BEFORE_PUSHXACT_FAILED" +#define DN_SAVEPOINT_BEFORE_PUSHXACT_FAILED "DN_SAVEPOINT_BEFORE_PUSHXACT_FAILED" +#define CN_SAVEPOINT_AFTER_PUSHXACT_FAILED "CN_SAVEPOINT_AFTER_PUSHXACT_FAILED" +#define DN_SAVEPOINT_AFTER_PUSHXACT_FAILED "DN_SAVEPOINT_AFTER_PUSHXACT_FAILED" + +#define CN_ROLLBACKTOSAVEPOINT_BEFORE_SEND_FAILED "CN_ROLLBACKTOSAVEPOINT_BEFORE_SEND_FAILED" +#define DN_ROLLBACKTOSAVEPOINT_AFTER_LOCAL_DEAL_FAILED "DN_ROLLBACKTOSAVEPOINT_AFTER_LOCAL_DEAL_FAILED" + +#define CN_RELEASESAVEPOINT_BEFORE_SEND_FAILED "CN_RELEASESAVEPOINT_BEFORE_SEND_FAILED" +#define DN_RELEASESAVEPOINT_AFTER_LOCAL_DEAL_FAILED "DN_RELEASESAVEPOINT_AFTER_LOCAL_DEAL_FAILED" +#define CN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED "CN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED" +#define DN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED "DN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED" + +#define CN_COMMIT_SUBXACT_BEFORE_SEND_GTM_FAILED "CN_COMMIT_SUBXACT_BEFORE_SEND_GTM_FAILED" +#define CN_COMMIT_SUBXACT_AFTER_SEND_GTM_FAILED "CN_COMMIT_SUBXACT_AFTER_SEND_GTM_FAILED" + +#define CN_CANCEL_SUBQUERY_FLUSH_FAILED "CN_CANCEL_SUBQUERY_FLUSH_FAILED" +#define CN_COMMIT_BEFORE_GTM_FAILED_AND_CANCEL_FLUSH_FAILED "CN_COMMIT_BEFORE_GTM_FAILED_AND_CANCEL_FLUSH_FAILED" + +#define DN_STANDBY_SLEEPIN_SYNCCOMMIT "DN_STANDBY_SLEEPIN_SYNCCOMMIT" +#define DN_XLOGFLUSH "DN_XLOGFLUSH" +#define DN_WALSEND_MAINLOOP "DN_WALSEND_MAINLOOP" +#define DN_WALRECEIVE_MAINLOOP "DN_WALRECEIVE_MAINLOOP" +#define DN_CM_NEW_CONN "DN_CM_NEW_CONN" +#define DN_PRIMARY_CHECKPOINT_KEEPXLOG "DN_PRIMARY_CHECKPOINT_KEEPXLOG" +#define DN_SLAVE_CHECKPOINT_KEEPXLOG "DN_SLAVE_CHECKPOINT_KEEPXLOG" + +#endif /* DEBUG */ +#endif /* DISTRIBUTE_TEST_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/dynahash.h postgresql-hll-2.14/include/include/utils/dynahash.h --- postgresql-hll-2.14_old/include/include/utils/dynahash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/dynahash.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,124 @@ +/* ------------------------------------------------------------------------- + * + * dynahash + * POSTGRES dynahash.h file definitions + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/dynahash.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DYNAHASH_H +#define DYNAHASH_H + +#include "storage/buf_internals.h" +#include "storage/s_lock.h" +#include "utils/hsearch.h" + +/* Number of freelists to be used for a partitioned hash table. */ +#define NUM_FREELISTS 32 + +/* A hash bucket is a linked list of HASHELEMENTs */ +typedef HASHELEMENT* HASHBUCKET; + +/* A hash segment is an array of bucket headers */ +typedef HASHBUCKET* HASHSEGMENT; + +/* + * Using array of FreeListData instead of separate arrays of mutexes, nentries + * and freeLists prevents, at least partially, sharing one cache line between + * different mutexes (see below). + */ +typedef struct { + slock_t mutex; /* spinlock */ + long nentries; /* number of entries */ + HASHELEMENT* freeList; /* list of free elements */ +} FreeListData; + +/* + * Header structure for a hash table --- contains all changeable info + * + * In a shared-memory hash table, the HASHHDR is in shared memory, while + * each backend has a local HTAB struct. For a non-shared table, there isn't + * any functional difference between HASHHDR and HTAB, but we separate them + * anyway to share code between shared and non-shared tables. + */ +struct HASHHDR { + /* + * The freelist can become a point of contention on high-concurrency hash + * tables, so we use an array of freelist, each with its own mutex and + * nentries count, instead of just a single one. + * + * If hash table is not partitioned only freeList[0] is used and spinlocks + * are not used at all. + */ + FreeListData freeList[NUM_FREELISTS]; + + /* These fields can change, but not in a partitioned table */ + /* Also, dsize can't change in a shared table, even if unpartitioned */ + long dsize; /* directory size */ + long nsegs; /* number of allocated segments (<= dsize) */ + uint32 max_bucket; /* ID of maximum bucket in use */ + uint32 high_mask; /* mask to modulo into entire table */ + uint32 low_mask; /* mask to modulo into lower half of table */ + + /* These fields are fixed at hashtable creation */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + long num_partitions; /* # partitions (must be power of 2), or 0 */ + long ffactor; /* target fill factor */ + long max_dsize; /* 'dsize' limit if directory is fixed size */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ + int nelem_alloc; /* number of entries to allocate at once */ + +#ifdef HASH_STATISTICS + + /* + * Count statistics here. NB: stats code doesn't bother with mutex, so + * counts could be corrupted a bit in a partitioned table. + */ + long accesses; + long collisions; +#endif +}; + +/* the offset of the last padding if exists*/ +#define HTAB_PAD_OFFSET 104 + +/* + * Top control structure for a hashtable --- in a shared table, each backend + * has its own copy (OK since no fields change at runtime) + */ +struct HTAB { + HASHHDR* hctl; /* => shared control information */ + HASHSEGMENT* dir; /* directory of segment starts */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context if default allocator used */ + char* tabname; /* table name (for error messages) */ + bool isshared; /* true if table is in shared memory */ + bool isfixed; /* if true, don't enlarge */ + + /* freezing a shared table isn't allowed, so we can keep state here */ + bool frozen; /* true = no more inserts allowed */ + + /* We keep local copies of these fixed values to reduce contention */ + Size keysize; /* hash key length in bytes */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - HTAB_PAD_OFFSET]; +#endif +}; + +extern int my_log2(long num); +template +void* buf_hash_operate(HTAB* hashp, const BufferTag* keyPtr, uint32 hashvalue, bool* foundPtr); +#endif /* DYNAHASH_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/dynamic_loader.h postgresql-hll-2.14/include/include/utils/dynamic_loader.h --- postgresql-hll-2.14_old/include/include/utils/dynamic_loader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/dynamic_loader.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * dynamic_loader.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/dynamic_loader.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DYNAMIC_LOADER_H +#define DYNAMIC_LOADER_H + +#include "fmgr.h" + +extern void* pg_dlopen(char* filename); +extern PGFunction pg_dlsym(void* handle, char* funcname); +extern void pg_dlclose(void* handle); +extern char* pg_dlerror(void); + +#endif /* DYNAMIC_LOADER_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/elog.h postgresql-hll-2.14/include/include/utils/elog.h --- postgresql-hll-2.14_old/include/include/utils/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/elog.h 2020-12-12 17:06:43.284348516 +0800 @@ -0,0 +1,614 @@ +/* ------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/elog.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include +#ifdef __GNUC__ +#include +#endif /* __GNUC__ */ + +#include "c.h" +#include "gs_threadlocal.h" +#include "gstrace/gstrace_infra.h" +#include "utils/be_module.h" +#include "utils/syscall_lock.h" +#include "securec.h" +#include "securec_check.h" + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ +#define DEBUG4 11 +#define DEBUG3 12 +#define DEBUG2 13 +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ +#define COMMERROR \ + 16 /* Client communication problems; same as LOG \ + * for server reporting, but never sent to \ + * client. */ +#define INFO \ + 17 /* Messages specifically requested by user (eg \ + * VACUUM VERBOSE output); always sent to \ + * client regardless of client_min_messages, \ + * but by default not sent to server log. */ +#define NOTICE \ + 18 /* Helpful messages to users about query \ + * operation; sent to client and server log by \ + * default. */ +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define VERBOSEMESSAGE \ + 9 /* indicates to show verbose info for CN and DNs; \ + * for DNs means to send info back to CN */ +/* Save ERROR value in PGERROR so it can be restored when Win32 includes + * modify it. We have to use a constant rather than ERROR because macros + * are expanded only when referenced outside macros. + */ +#ifdef WIN32 +#define PGERROR 20 +#endif +#define FATAL 21 /* fatal error - abort process */ +#define PANIC 22 /* take down the other backends with me */ + +/* MAKE_SQLSTATE('P', '1', '0' , '0', '0')=96 */ +#define CUSTOM_ERRCODE_P1 96 + +/* macros for representing SQLSTATE strings compactly */ +#define PGSIXBIT(ch) (((ch) - '0') & 0x3F) +#define PGUNSIXBIT(val) (((val)&0x3F) + '0') + +#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5) \ + (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24)) + +/* These macros depend on the fact that '0' becomes a zero in SIXBIT */ +#define ERRCODE_TO_CATEGORY(ec) ((ec) & ((1 << 12) - 1)) +#define ERRCODE_IS_CATEGORY(ec) (((ec) & ~((1 << 12) - 1)) == 0) + +/* SQLSTATE codes for errors are defined in a separate file */ +#include "utils/errcodes.h" + +/* Which __func__ symbol do we have, if any? */ +#ifdef HAVE_FUNCNAME__FUNC +#define PG_FUNCNAME_MACRO __func__ +#else +#ifdef HAVE_FUNCNAME__FUNCTION +#define PG_FUNCNAME_MACRO __FUNCTION__ +#else +#define PG_FUNCNAME_MACRO NULL +#endif +#endif + +/* ---------- + * New-style error reporting API: to be used in this way: + * ereport(ERROR, + * (errcode(ERRCODE_UNDEFINED_CURSOR), + * errmsg("portal \"%s\" not found", stmt->portalname), + * ... other errxxx() fields as needed ...)); + * + * The error level is required, and so is a primary error message (errmsg + * or errmsg_internal). All else is optional. errcode() defaults to + * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING + * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is + * NOTICE or below. + * + * ereport_domain() allows a message domain to be specified, for modules that + * wish to use a different message catalog from the backend's. To avoid having + * one copy of the default text domain per .o file, we define it as NULL here + * and have errstart insert the default text domain. Modules can either use + * ereport_domain() directly, or preferably they can override the TEXTDOMAIN + * macro. + * ---------- + */ +#define ereport_domain(elevel, domain, rest) \ + (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? (errfinish rest) : (void)0) + +#ifdef PC_LINT +#define ereport(elevel, rest) \ + do { \ + if (elevel >= ERROR) \ + exit((int)(rest)); \ + } while (0) + +#else +#define ereport(elevel, rest) ereport_domain(elevel, TEXTDOMAIN, rest) +#endif /*PCLINT_CHECK*/ + +#define TEXTDOMAIN NULL + +extern bool errstart(int elevel, const char* filename, int lineno, const char* funcname, const char* domain); +extern void errfinish(int dummy, ...); +#ifdef PC_LINT +#define errcode(sqlerrcode) (1 == (int)(sqlerrcode)) +#else +#if !defined(WIN32) +extern int errcode(int sqlerrcode); +#endif +#endif +extern int errcode_for_file_access(void); +extern int errcode_for_socket_access(void); + +/* set error module */ +extern int errmodule(ModuleId id); + +extern char* maskPassword(const char* query_string); + +#define MASK_PASSWORD_START(mask_string, query_string) \ + do { \ + mask_string = maskPassword(query_string); \ + if (NULL == mask_string) \ + mask_string = (char*)query_string; \ + } while (0) + +#define MASK_PASSWORD_END(mask_string, query_string) \ + do { \ + if (mask_string != query_string) \ + selfpfree(mask_string); \ + } while (0) + +extern int errmsg(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errmsg_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errmsg_plural(const char* fmt_singular, const char* fmt_plural, unsigned long n, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4))) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4))); + +extern int errdetail(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_log(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_plural(const char* fmt_singular, const char* fmt_plural, unsigned long n, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4))) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4))); + +extern int errhint(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errquery(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errcontext(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errhidestmt(bool hide_stmt); + +extern int errhideprefix(bool hide_prefix); + +extern int errposition(int cursorpos); + +extern int internalerrposition(int cursorpos); +extern int internalerrquery(const char* query); + +extern int geterrcode(void); +extern int geterrposition(void); +extern int getinternalerrposition(void); + +extern void save_error_message(void); + +extern int handle_in_client(bool handle); +extern int ignore_interrupt(bool ignore); + +/* ---------- + * Old-style error reporting API: to be used in this way: + * elog(ERROR, "portal \"%s\" not found", stmt->portalname); + * ---------- + */ + +#ifdef PC_LINT +#define elog(level, ...) \ + do { \ + if (level >= ERROR) \ + exit(0); \ + } while (0) +#else +#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish +#endif /* PCLINT_CHECK */ + +extern void elog_start(const char* filename, int lineno, const char* funcname); +extern void elog_finish(int elevel, const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/* Support for constructing error strings separately from ereport() calls */ + +extern void pre_format_elog_string(int errnumber, const char* domain); +extern char* format_elog_string(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +/* Support for attaching context information to error reports */ + +typedef struct ErrorContextCallback { + struct ErrorContextCallback* previous; + void (*callback)(void* arg); + void* arg; +} ErrorContextCallback; + +#ifndef FRONTEND +#define securec_check(errno, charList, ...) \ + { \ + if (EOK != errno) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + switch (errno) { \ + case EINVAL: \ + elog(ERROR, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(ERROR, "%s : %d : The Source Buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(ERROR, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } + +#else + +#define securec_check(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace_c(charList, ##__VA_ARGS__); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } + +#endif + +/* Only used in sprintf_s or scanf_s cluster function */ +#define securec_check_ss(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + elog(ERROR, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } + +/* ---------- + * API for catching ereport(ERROR) exits. Use these macros like so: + * + * PG_TRY(); + * { + * ... code that might throw ereport(ERROR) ... + * } + * PG_CATCH(); + * { + * ... error recovery code ... + * } + * PG_END_TRY(); + * + * (The braces are not actually necessary, but are recommended so that + * pg_indent will indent the construct nicely.) The error recovery code + * can optionally do PG_RE_THROW() to propagate the same error outwards. + * + * Note: while the system will correctly propagate any new ereport(ERROR) + * occurring in the recovery section, there is a small limit on the number + * of levels this will work for. It's best to keep the error recovery + * section simple enough that it can't generate any new errors, at least + * not before popping the error stack. + * + * Note: an ereport(FATAL) will not be caught by this construct; control will + * exit straight through proc_exit(). Therefore, do NOT put any cleanup + * of non-process-local resources into the error recovery section, at least + * not without taking thought for what will happen during ereport(FATAL). + * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be + * helpful in such cases. + * + * Note: Don't execute statements such as break, continue, goto, or return in + * PG_TRY. If you need to use these statements, you must recovery + * PG_exception_stack first. + * ---------- + */ +#define PG_TRY() \ + do { \ + sigjmp_buf* save_exception_stack = t_thrd.log_cxt.PG_exception_stack; \ + ErrorContextCallback* save_context_stack = t_thrd.log_cxt.error_context_stack; \ + sigjmp_buf local_sigjmp_buf; \ + int tryCounter, *oldTryCounter = NULL; \ + if (sigsetjmp(local_sigjmp_buf, 0) == 0) { \ + t_thrd.log_cxt.PG_exception_stack = &local_sigjmp_buf; \ + oldTryCounter = gstrace_tryblock_entry(&tryCounter) + +#define PG_CATCH() \ + } \ + else \ + { \ + t_thrd.log_cxt.PG_exception_stack = save_exception_stack; \ + t_thrd.log_cxt.error_context_stack = save_context_stack; \ + gstrace_tryblock_exit(true, oldTryCounter) + +#define PG_END_TRY() \ + } \ + t_thrd.log_cxt.PG_exception_stack = save_exception_stack; \ + t_thrd.log_cxt.error_context_stack = save_context_stack; \ + gstrace_tryblock_exit(false, oldTryCounter); \ + } \ + while (0) + +// ADIO means async direct io +#define ADIO_RUN() if (g_instance.attr.attr_storage.enable_adio_function) { + +#define ADIO_ELSE() \ + } \ + else \ + { + +#define ADIO_END() } + +// BFIO means buffer io +#define BFIO_RUN() if (!g_instance.attr.attr_storage.enable_adio_function) { + +#define BFIO_ELSE() \ + } \ + else \ + { + +#define BFIO_END() } + +#define ADIO_LOG_DB(A) \ + do { \ + if (u_sess->attr.attr_storage.enable_adio_debug) { \ + A; \ + } \ + } while (0) + +/* + * gcc understands __attribute__((noreturn)); for other compilers, insert + * a useless exit() call so that the compiler gets the point. + */ +#ifdef __GNUC__ +#define PG_RE_THROW() pg_re_throw() +#else +#define PG_RE_THROW() (pg_re_throw(), exit(1)) // no need to change exit to pthread_exit +#endif + +/* Stuff that error handlers might want to use */ + +/* + * ErrorData holds the data accumulated during any one ereport() cycle. + * Any non-NULL pointers must point to palloc'd data. + * (The const pointers are an exception; we assume they point at non-freeable + * constant strings.) + */ +typedef struct ErrorData { + int elevel; /* error level */ + bool output_to_server; /* will report to server log? */ + bool output_to_client; /* will report to client? */ + bool handle_in_client; /* true to report to client and also handle in client */ + bool show_funcname; /* true to force funcname inclusion */ + bool hide_stmt; /* true to prevent STATEMENT: inclusion */ + bool hide_prefix; /* true to prevent line prefix inclusion */ + char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + char* funcname; /* __func__ of ereport() call */ + const char* domain; /* message domain */ + int sqlerrcode; /* encoded ERRSTATE */ + ModuleId mod_id; /* which module */ + char* message; /* primary error message */ + char* detail; /* detail error message */ + char* detail_log; /* detail error message for server log only */ + char* hint; /* hint message */ + char* context; /* context message */ + int cursorpos; /* cursor index into query string */ + int internalpos; /* cursor index into internalquery */ + char* internalquery; /* text of internally-generated query */ + int saved_errno; /* errno at entry */ + char* backtrace_log; /* the buffer for backtrace */ + int internalerrcode; /* mppdb internal encoded */ + bool verbose; /* the flag to indicate VACUUM FULL VERBOSE/ANALYZE VERBOSE message */ + bool ignore_interrupt; /* true to ignore interrupt when writing server log */ +} ErrorData; + +/* The error data from remote */ +typedef struct RemoteErrorData { + int internalerrcode; /* mppdb internal encoded */ + char* errorfuncname; /* __func__ of ereport() call */ + char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + ModuleId mod_id; +} RemoteErrorData; + +extern int combiner_errdata(RemoteErrorData* pErrData); +extern void EmitErrorReport(void); +extern void stream_send_message_to_server_log(void); +extern void stream_send_message_to_consumer(void); +extern ErrorData* CopyErrorData(void); +extern void UpdateErrorData(ErrorData* edata, ErrorData* newData); +extern void FreeErrorData(ErrorData* edata); +extern void FlushErrorState(void); +extern void FlushErrorStateWithoutDeleteChildrenContext(void); +extern void ReThrowError(ErrorData* edata) __attribute__((noreturn)); +extern void pg_re_throw(void) __attribute__((noreturn)); + +/* GUC-configurable parameters */ + +typedef enum { + PGERROR_TERSE, /* single-line error messages */ + PGERROR_DEFAULT, /* recommended style */ + PGERROR_VERBOSE /* all the facts, ma'am */ +} PGErrorVerbosity; + +/* Log destination bitmap */ +#define LOG_DESTINATION_STDERR 1 +#define LOG_DESTINATION_SYSLOG 2 +#define LOG_DESTINATION_EVENTLOG 4 +#define LOG_DESTINATION_CSVLOG 8 +#define LOG_DESTINATION_QUERYLOG 16 +#define LOG_DESTINATION_ASPLOG 32 + +/* Other exported functions */ +extern void DebugFileOpen(void); +extern char* unpack_sql_state(int sql_state); +extern bool in_error_recursion_trouble(void); + +#ifdef HAVE_SYSLOG +extern void set_syslog_parameters(const char* ident, int facility); +#endif + +#ifndef WIN32 +/* + * @Description: according to module logging rules, + * check this module logging is enable or disable. + * @IN elevel: error level + * @IN mod_id: module id + * @Return: true, enable server log to write; false, disable server logging. + * @See also: send_message_to_server_log() + */ +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id) +{ + return (elevel >= LOG || module_logging_is_on(mod_id)); +} + +extern inline int defence_errlevel(void) +{ +#ifdef USE_ASSERT_CHECKING + return PANIC; +#else + return ERROR; +#endif +} + +#endif + +/* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used + * safely (memory context, GUC load etc) + */ +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern void getElevelAndSqlstate(int* eLevel, int* sqlState); + +void freeSecurityFuncSpace(char* charList, ...); + +extern void SimpleLogToServer(int elevel, bool silent, const char* fmt, ...) + __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4))); + +/* helpful macro */ +#define AssertEreport(condition, module, msg) \ + do { \ + Assert(condition); \ + if (unlikely(!(condition))) \ + ereport(ERROR, \ + (errmodule(module), \ + errcode(ERRORCODE_ASSERT_FAILED), \ + errmsg("failed on assertion in %s line %d. %s", __FILE__, __LINE__, msg))); \ + } while (0) + +/* This Macro reports an error when touching distributed features in single node DB */ +#define DISTRIBUTED_FEATURE_NOT_SUPPORTED() \ + do { \ + ereport(ERROR, \ + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \ + errmsg("Un-support feature"), \ + errdetail("The distributed capability is not supported currently."))); \ + } while (0) + +#define IPC_PERFORMANCE_LOG_OUTPUT(errorMessage) \ + do \ + if (module_logging_is_on(MOD_COMM_IPC) && \ + (t_thrd.proc && t_thrd.proc->workingVersionNum >= 92060)) { \ + ereport(LOG, (errmodule(MOD_COMM_IPC), errmsg((char*)errorMessage))); \ + } \ + while (0) + +#define IPC_PERFORMANCE_LOG_COLLECT(msgLog, buffer, bufferLen, remoteNode, fd, msgOpr) \ + do \ + if (module_logging_is_on(MOD_COMM_IPC) && bufferLen > 0 && \ + (t_thrd.proc && t_thrd.proc->workingVersionNum >= 92060)) { \ + msgLog = gs_comm_ipc_performance(msgLog, buffer, bufferLen, remoteNode, fd, msgOpr); \ + } \ + while (0) + +#define MODULE_LOG_TRACE(trace_mode, ...) \ + do \ + if (module_logging_is_on(trace_mode)) { \ + ereport(LOG, (errmodule(trace_mode), errmsg(__VA_ARGS__))); \ + } \ + while (0) \ + +#endif /* ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/errcodes.h postgresql-hll-2.14/include/include/utils/errcodes.h --- postgresql-hll-2.14_old/include/include/utils/errcodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/errcodes.h 2020-12-12 17:06:43.285348529 +0800 @@ -0,0 +1,454 @@ +/* autogenerated from src/backend/utils/errcodes.txt, do not edit */ +/* there is deliberately not an #ifndef ERRCODES_H here */ + +/* Class 00 - Successful Completion */ +#define ERRCODE_SUCCESSFUL_COMPLETION MAKE_SQLSTATE('0','0','0','0','0') + +/* Class 01 - Warning */ +#define ERRCODE_WARNING MAKE_SQLSTATE('0','1','0','0','0') +#define ERRCODE_WARNING_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','1','0','0','C') +#define ERRCODE_WARNING_IMPLICIT_ZERO_BIT_PADDING MAKE_SQLSTATE('0','1','0','0','8') +#define ERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION MAKE_SQLSTATE('0','1','0','0','3') +#define ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED MAKE_SQLSTATE('0','1','0','0','7') +#define ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED MAKE_SQLSTATE('0','1','0','0','6') +#define ERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('0','1','0','0','4') +#define ERRCODE_WARNING_DEPRECATED_FEATURE MAKE_SQLSTATE('0','1','P','0','1') + +/* Class 02 - No Data (this is also a warning class per the SQL standard) */ +#define ERRCODE_NO_DATA MAKE_SQLSTATE('0','2','0','0','0') +#define ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','2','0','0','1') +#define ERRCODE_INVALID_OPTION MAKE_SQLSTATE('0','2','0','0','2') + +/* Class 03 - SQL Statement Not Yet Complete */ +#define ERRCODE_SQL_STATEMENT_NOT_YET_COMPLETE MAKE_SQLSTATE('0','3','0','0','0') + +/* Class 08 - Connection Exception */ +#define ERRCODE_CONNECTION_EXCEPTION MAKE_SQLSTATE('0','8','0','0','0') +#define ERRCODE_CONNECTION_DOES_NOT_EXIST MAKE_SQLSTATE('0','8','0','0','3') +#define ERRCODE_CONNECTION_FAILURE MAKE_SQLSTATE('0','8','0','0','6') +#define ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION MAKE_SQLSTATE('0','8','0','0','1') +#define ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION MAKE_SQLSTATE('0','8','0','0','4') +#define ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN MAKE_SQLSTATE('0','8','0','0','7') +#define ERRCODE_PROTOCOL_VIOLATION MAKE_SQLSTATE('0','8','P','0','1') + +/* Class 09 - Triggered Action Exception */ +#define ERRCODE_TRIGGERED_ACTION_EXCEPTION MAKE_SQLSTATE('0','9','0','0','0') + +/* Class 0A - Feature Not Supported */ +#define ERRCODE_FEATURE_NOT_SUPPORTED MAKE_SQLSTATE('0','A','0','0','0') +#define ERRCODE_STREAM_NOT_SUPPORTED MAKE_SQLSTATE('0','A','1','0','0') + +/* Class 0B - Invalid Transaction Initiation */ +#define ERRCODE_INVALID_TRANSACTION_INITIATION MAKE_SQLSTATE('0','B','0','0','0') + +/* Class 0F - Locator Exception */ +#define ERRCODE_LOCATOR_EXCEPTION MAKE_SQLSTATE('0','F','0','0','0') +#define ERRCODE_L_E_INVALID_SPECIFICATION MAKE_SQLSTATE('0','F','0','0','1') + +/* Class 0L - Invalid Grantor */ +#define ERRCODE_INVALID_GRANTOR MAKE_SQLSTATE('0','L','0','0','0') +#define ERRCODE_INVALID_GRANT_OPERATION MAKE_SQLSTATE('0','L','P','0','1') + +/* Class 0P - Invalid Role Specification */ +#define ERRCODE_INVALID_ROLE_SPECIFICATION MAKE_SQLSTATE('0','P','0','0','0') + +/* Class 0Z - Diagnostics Exception */ +#define ERRCODE_DIAGNOSTICS_EXCEPTION MAKE_SQLSTATE('0','Z','0','0','0') +#define ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER MAKE_SQLSTATE('0','Z','0','0','2') + +/* Class 20 - Case Not Found */ +#define ERRCODE_CASE_NOT_FOUND MAKE_SQLSTATE('2','0','0','0','0') + +/* Class 21 - Cardinality Violation */ +#define ERRCODE_CARDINALITY_VIOLATION MAKE_SQLSTATE('2','1','0','0','0') + +/* Class 22 - Data Exception */ +#define ERRCODE_DATA_EXCEPTION MAKE_SQLSTATE('2','2','0','0','0') +#define ERRCODE_ARRAY_ELEMENT_ERROR MAKE_SQLSTATE('2','2','0','0','E') +#define ERRCODE_ARRAY_SUBSCRIPT_ERROR MAKE_SQLSTATE('2','2','0','2','E') +#define ERRCODE_CHARACTER_NOT_IN_REPERTOIRE MAKE_SQLSTATE('2','2','0','2','1') +#define ERRCODE_DATETIME_FIELD_OVERFLOW MAKE_SQLSTATE('2','2','0','0','8') +#define ERRCODE_DATETIME_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','2','0') +#define ERRCODE_DIVISION_BY_ZERO MAKE_SQLSTATE('2','2','0','1','2') +#define ERRCODE_ERROR_IN_ASSIGNMENT MAKE_SQLSTATE('2','2','0','0','5') +#define ERRCODE_ESCAPE_CHARACTER_CONFLICT MAKE_SQLSTATE('2','2','0','0','B') +#define ERRCODE_INDICATOR_OVERFLOW MAKE_SQLSTATE('2','2','0','2','2') +#define ERRCODE_INTERVAL_FIELD_OVERFLOW MAKE_SQLSTATE('2','2','0','1','5') +#define ERRCODE_INVALID_ARGUMENT_FOR_LOG MAKE_SQLSTATE('2','2','0','1','E') +#define ERRCODE_INVALID_ARGUMENT_FOR_NTILE MAKE_SQLSTATE('2','2','0','1','4') +#define ERRCODE_INVALID_ARGUMENT_FOR_NTH_VALUE MAKE_SQLSTATE('2','2','0','1','6') +#define ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION MAKE_SQLSTATE('2','2','0','1','F') +#define ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION MAKE_SQLSTATE('2','2','0','1','G') +#define ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST MAKE_SQLSTATE('2','2','0','1','8') +#define ERRCODE_INVALID_DATETIME_FORMAT MAKE_SQLSTATE('2','2','0','0','7') +#define ERRCODE_INVALID_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','0','1','9') +#define ERRCODE_INVALID_ESCAPE_OCTET MAKE_SQLSTATE('2','2','0','0','D') +#define ERRCODE_INVALID_ESCAPE_SEQUENCE MAKE_SQLSTATE('2','2','0','2','5') +#define ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','P','0','6') +#define ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE MAKE_SQLSTATE('2','2','0','1','0') +#define ERRCODE_INVALID_PARAMETER_VALUE MAKE_SQLSTATE('2','2','0','2','3') +#define ERRCODE_INVALID_REGULAR_EXPRESSION MAKE_SQLSTATE('2','2','0','1','B') +#define ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE MAKE_SQLSTATE('2','2','0','1','W') +#define ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE MAKE_SQLSTATE('2','2','0','1','X') +#define ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE MAKE_SQLSTATE('2','2','0','0','9') +#define ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','0','0','C') +#define ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH MAKE_SQLSTATE('2','2','0','0','G') +#define ERRCODE_NULL_VALUE_NOT_ALLOWED MAKE_SQLSTATE('2','2','0','0','4') +#define ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER MAKE_SQLSTATE('2','2','0','0','2') +#define ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','0','3') +#define ERRCODE_DOP_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','1','7') +#define ERRCODE_STRING_DATA_LENGTH_MISMATCH MAKE_SQLSTATE('2','2','0','2','6') +#define ERRCODE_REGEXP_MISMATCH MAKE_SQLSTATE('2','2','0','2','8') +#define ERRCODE_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('2','2','0','0','1') +#define ERRCODE_SUBSTRING_ERROR MAKE_SQLSTATE('2','2','0','1','1') +#define ERRCODE_TRIM_ERROR MAKE_SQLSTATE('2','2','0','2','7') +#define ERRCODE_UNTERMINATED_C_STRING MAKE_SQLSTATE('2','2','0','2','4') +#define ERRCODE_ZERO_LENGTH_CHARACTER_STRING MAKE_SQLSTATE('2','2','0','0','F') +#define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2','P','0','1') +#define ERRCODE_INVALID_TEXT_REPRESENTATION MAKE_SQLSTATE('2','2','P','0','2') +#define ERRCODE_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2','P','0','3') +#define ERRCODE_BAD_COPY_FILE_FORMAT MAKE_SQLSTATE('2','2','P','0','4') +#define ERRCODE_UNTRANSLATABLE_CHARACTER MAKE_SQLSTATE('2','2','P','0','5') +#define ERRCODE_NOT_AN_XML_DOCUMENT MAKE_SQLSTATE('2','2','0','0','L') +#define ERRCODE_INVALID_XML_DOCUMENT MAKE_SQLSTATE('2','2','0','0','M') +#define ERRCODE_INVALID_XML_CONTENT MAKE_SQLSTATE('2','2','0','0','N') +#define ERRCODE_INVALID_XML_ERROR_CONTEXT MAKE_SQLSTATE('2','2','0','0','O') +#define ERRCODE_INVALID_XML_COMMENT MAKE_SQLSTATE('2','2','0','0','S') +#define ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION MAKE_SQLSTATE('2','2','0','0','T') + +/* Class 23 - Integrity Constraint Violation */ +#define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('2','3','0','0','0') +#define ERRCODE_RESTRICT_VIOLATION MAKE_SQLSTATE('2','3','0','0','1') +#define ERRCODE_NOT_NULL_VIOLATION MAKE_SQLSTATE('2','3','5','0','2') +#define ERRCODE_FOREIGN_KEY_VIOLATION MAKE_SQLSTATE('2','3','5','0','3') +#define ERRCODE_UNIQUE_VIOLATION MAKE_SQLSTATE('2','3','5','0','5') +#define ERRCODE_CHECK_VIOLATION MAKE_SQLSTATE('2','3','5','1','4') +#define ERRCODE_EXCLUSION_VIOLATION MAKE_SQLSTATE('2','3','P','0','1') + +/* Class 24 - Invalid Cursor State */ +#define ERRCODE_INVALID_CURSOR_STATE MAKE_SQLSTATE('2','4','0','0','0') + +/* Class 25 - Invalid Transaction State */ +#define ERRCODE_INVALID_TRANSACTION_STATE MAKE_SQLSTATE('2','5','0','0','0') +#define ERRCODE_ACTIVE_SQL_TRANSACTION MAKE_SQLSTATE('2','5','0','0','1') +#define ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE MAKE_SQLSTATE('2','5','0','0','2') +#define ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL MAKE_SQLSTATE('2','5','0','0','8') +#define ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','3') +#define ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','4') +#define ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','5') +#define ERRCODE_READ_ONLY_SQL_TRANSACTION MAKE_SQLSTATE('2','5','0','0','6') +#define ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED MAKE_SQLSTATE('2','5','0','0','7') +#define ERRCODE_RUN_TRANSACTION_DURING_RECOVERY MAKE_SQLSTATE('2','5','0','0','9') +#define ERRCODE_GXID_DOES_NOT_EXIST MAKE_SQLSTATE('2','5','0','1','0') +#define ERRCODE_NO_ACTIVE_SQL_TRANSACTION MAKE_SQLSTATE('2','5','P','0','1') +#define ERRCODE_IN_FAILED_SQL_TRANSACTION MAKE_SQLSTATE('2','5','P','0','2') + +/* Class 26 - Invalid SQL Statement Name */ +#define ERRCODE_INVALID_SQL_STATEMENT_NAME MAKE_SQLSTATE('2','6','0','0','0') +#define ERRCODE_SLOW_QUERY MAKE_SQLSTATE('2','6','0','0','1') +#define ERRCODE_ACTIVE_SESSION_PROFILE MAKE_SQLSTATE('2','6','0','0','2') + +/* Class 27 - Triggered Data Change Violation */ +#define ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION MAKE_SQLSTATE('2','7','0','0','0') +#define ERRCODE_TRIGGERED_INVALID_TUPLE MAKE_SQLSTATE('2','7','0','0','1') + +/* Class 28 - Invalid Authorization Specification */ +#define ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION MAKE_SQLSTATE('2','8','0','0','0') +#define ERRCODE_INVALID_PASSWORD MAKE_SQLSTATE('2','8','P','0','1') +#define ERRCODE_INITIAL_PASSWORD_NOT_MODIFIED MAKE_SQLSTATE('2','8','P','0','2') + +/* Class 29 - Invalid or Unexpected Status */ +#define ERRCODE_INVALID_STATUS MAKE_SQLSTATE('2','9','0','0','0') +#define ERRCODE_INVALID_TABLESAMPLE_ARGUMENT MAKE_SQLSTATE('2','9','0','0','1') +#define ERRCODE_INVALID_TABLESAMPLE_REPEAT MAKE_SQLSTATE('2','9','0','0','2') +#define ERRORCODE_ASSERT_FAILED MAKE_SQLSTATE('2','9','0','0','3') +#define ERRCODE_CACHE_LOOKUP_FAILED MAKE_SQLSTATE('2','9','P','0','1') +#define ERRCODE_FETCH_DATA_FAILED MAKE_SQLSTATE('2','9','P','0','2') +#define ERRCODE_FLUSH_DATA_SIZE_MISMATCH MAKE_SQLSTATE('2','9','P','0','3') +#define ERRCODE_RELATION_OPEN_ERROR MAKE_SQLSTATE('2','9','P','0','4') +#define ERRCODE_RELATION_CLOSE_ERROR MAKE_SQLSTATE('2','9','P','0','5') +#define ERRCODE_INVALID_CACHE_PLAN MAKE_SQLSTATE('2','9','P','0','6') + +/* Class 2B - Dependent Privilege Descriptors Still Exist */ +#define ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST MAKE_SQLSTATE('2','B','0','0','0') +#define ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST MAKE_SQLSTATE('2','B','P','0','1') + +/* Class 2D - Invalid Transaction Termination */ +#define ERRCODE_INVALID_TRANSACTION_TERMINATION MAKE_SQLSTATE('2','D','0','0','0') + +/* Class 2F - SQL Routine Exception */ +#define ERRCODE_SQL_ROUTINE_EXCEPTION MAKE_SQLSTATE('2','F','0','0','0') +#define ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT MAKE_SQLSTATE('2','F','0','0','5') +#define ERRCODE_S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('2','F','0','0','2') +#define ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED MAKE_SQLSTATE('2','F','0','0','3') +#define ERRCODE_S_R_E_READING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('2','F','0','0','4') + +/* Class 34 - Invalid Cursor Name */ +#define ERRCODE_INVALID_CURSOR_NAME MAKE_SQLSTATE('3','4','0','0','0') + +/* Class 38 - External Routine Exception */ +#define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION MAKE_SQLSTATE('3','8','0','0','0') +#define ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','1') +#define ERRCODE_E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','2') +#define ERRCODE_E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED MAKE_SQLSTATE('3','8','0','0','3') +#define ERRCODE_E_R_E_READING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','4') + +/* Class 39 - External Routine Invocation Exception */ +#define ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION MAKE_SQLSTATE('3','9','0','0','0') +#define ERRCODE_E_R_I_E_INVALID_SQLSTATE_RETURNED MAKE_SQLSTATE('3','9','0','0','1') +#define ERRCODE_E_R_I_E_NULL_VALUE_NOT_ALLOWED MAKE_SQLSTATE('3','9','0','0','4') +#define ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED MAKE_SQLSTATE('3','9','P','0','1') +#define ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED MAKE_SQLSTATE('3','9','P','0','2') + +/* Class 3B - Savepoint Exception */ +#define ERRCODE_SAVEPOINT_EXCEPTION MAKE_SQLSTATE('3','B','0','0','0') +#define ERRCODE_S_E_INVALID_SPECIFICATION MAKE_SQLSTATE('3','B','0','0','1') + +/* Class 3D - Invalid Catalog Name */ +#define ERRCODE_INVALID_CATALOG_NAME MAKE_SQLSTATE('3','D','0','0','0') + +/* Class 3F - Invalid Schema Name */ +#define ERRCODE_INVALID_SCHEMA_NAME MAKE_SQLSTATE('3','F','0','0','0') + +/* Class 40 - Transaction Rollback */ +#define ERRCODE_TRANSACTION_ROLLBACK MAKE_SQLSTATE('4','0','0','0','0') +#define ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('4','0','0','0','2') +#define ERRCODE_T_R_SERIALIZATION_FAILURE MAKE_SQLSTATE('4','0','0','0','1') +#define ERRCODE_T_R_STATEMENT_COMPLETION_UNKNOWN MAKE_SQLSTATE('4','0','0','0','3') +#define ERRCODE_T_R_DEADLOCK_DETECTED MAKE_SQLSTATE('4','0','P','0','1') + +/* Class 42 - Syntax Error or Access Rule Violation */ +#define ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION MAKE_SQLSTATE('4','2','0','0','0') +#define ERRCODE_SYNTAX_ERROR MAKE_SQLSTATE('4','2','6','0','1') +#define ERRCODE_INSUFFICIENT_PRIVILEGE MAKE_SQLSTATE('4','2','5','0','1') +#define ERRCODE_CANNOT_COERCE MAKE_SQLSTATE('4','2','8','4','6') +#define ERRCODE_GROUPING_ERROR MAKE_SQLSTATE('4','2','8','0','3') +#define ERRCODE_WINDOWING_ERROR MAKE_SQLSTATE('4','2','P','2','0') +#define ERRCODE_INVALID_RECURSION MAKE_SQLSTATE('4','2','P','1','9') +#define ERRCODE_INVALID_FOREIGN_KEY MAKE_SQLSTATE('4','2','8','3','0') +#define ERRCODE_INVALID_NAME MAKE_SQLSTATE('4','2','6','0','2') +#define ERRCODE_NAME_TOO_LONG MAKE_SQLSTATE('4','2','6','2','2') +#define ERRCODE_RESERVED_NAME MAKE_SQLSTATE('4','2','9','3','9') +#define ERRCODE_DATATYPE_MISMATCH MAKE_SQLSTATE('4','2','8','0','4') +#define ERRCODE_INDETERMINATE_DATATYPE MAKE_SQLSTATE('4','2','P','3','8') +#define ERRCODE_COLLATION_MISMATCH MAKE_SQLSTATE('4','2','P','2','1') +#define ERRCODE_INDETERMINATE_COLLATION MAKE_SQLSTATE('4','2','P','2','2') +#define ERRCODE_WRONG_OBJECT_TYPE MAKE_SQLSTATE('4','2','8','0','9') +#define ERRCODE_PARTITION_ERROR MAKE_SQLSTATE('4','2','P','2','3') +#define ERRCODE_INVALID_ATTRIBUTE MAKE_SQLSTATE('4','2','P','2','4') +#define ERRCODE_INVALID_AGG MAKE_SQLSTATE('4','2','P','2','5') +#define ERRCODE_RESOURCE_POOL_ERROR MAKE_SQLSTATE('4','2','P','2','6') +#define ERRCODE_PLAN_PARENT_NOT_FOUND MAKE_SQLSTATE('4','2','P','2','7') +#define ERRCODE_MODIFY_CONFLICTS MAKE_SQLSTATE('4','2','P','2','8') +#define ERRCODE_DISTRIBUTION_ERROR MAKE_SQLSTATE('4','2','P','2','9') +#define ERRCODE_UNDEFINED_COLUMN MAKE_SQLSTATE('4','2','7','0','3') +#define ERRCODE_UNDEFINED_CURSOR MAKE_SQLSTATE('3','4','0','0','1') +#define ERRCODE_UNDEFINED_DATABASE MAKE_SQLSTATE('3','D','0','0','0') +#define ERRCODE_UNDEFINED_FUNCTION MAKE_SQLSTATE('4','2','8','8','3') +#define ERRCODE_UNDEFINED_PSTATEMENT MAKE_SQLSTATE('2','6','0','1','0') +#define ERRCODE_UNDEFINED_SCHEMA MAKE_SQLSTATE('3','F','0','0','1') +#define ERRCODE_UNDEFINED_TABLE MAKE_SQLSTATE('4','2','P','0','1') +#define ERRCODE_UNDEFINED_PARAMETER MAKE_SQLSTATE('4','2','P','0','2') +#define ERRCODE_UNDEFINED_OBJECT MAKE_SQLSTATE('4','2','7','0','4') +#define ERRCODE_DUPLICATE_COLUMN MAKE_SQLSTATE('4','2','7','0','1') +#define ERRCODE_DUPLICATE_CURSOR MAKE_SQLSTATE('4','2','P','0','3') +#define ERRCODE_DUPLICATE_DATABASE MAKE_SQLSTATE('4','2','P','0','4') +#define ERRCODE_DUPLICATE_FUNCTION MAKE_SQLSTATE('4','2','7','2','3') +#define ERRCODE_DUPLICATE_PSTATEMENT MAKE_SQLSTATE('4','2','P','0','5') +#define ERRCODE_DUPLICATE_SCHEMA MAKE_SQLSTATE('4','2','P','0','6') +#define ERRCODE_DUPLICATE_TABLE MAKE_SQLSTATE('4','2','P','0','7') +#define ERRCODE_DUPLICATE_ALIAS MAKE_SQLSTATE('4','2','7','1','2') +#define ERRCODE_DUPLICATE_OBJECT MAKE_SQLSTATE('4','2','7','1','0') +#define ERRCODE_AMBIGUOUS_COLUMN MAKE_SQLSTATE('4','2','7','0','2') +#define ERRCODE_AMBIGUOUS_FUNCTION MAKE_SQLSTATE('4','2','7','2','5') +#define ERRCODE_AMBIGUOUS_PARAMETER MAKE_SQLSTATE('4','2','P','0','8') +#define ERRCODE_AMBIGUOUS_ALIAS MAKE_SQLSTATE('4','2','P','0','9') +#define ERRCODE_INVALID_COLUMN_REFERENCE MAKE_SQLSTATE('4','2','P','1','0') +#define ERRCODE_INVALID_COLUMN_DEFINITION MAKE_SQLSTATE('4','2','6','1','1') +#define ERRCODE_INVALID_CURSOR_DEFINITION MAKE_SQLSTATE('4','2','P','1','1') +#define ERRCODE_INVALID_DATABASE_DEFINITION MAKE_SQLSTATE('4','2','P','1','2') +#define ERRCODE_INVALID_FUNCTION_DEFINITION MAKE_SQLSTATE('4','2','P','1','3') +#define ERRCODE_INVALID_PSTATEMENT_DEFINITION MAKE_SQLSTATE('4','2','P','1','4') +#define ERRCODE_INVALID_SCHEMA_DEFINITION MAKE_SQLSTATE('4','2','P','1','5') +#define ERRCODE_INVALID_TABLE_DEFINITION MAKE_SQLSTATE('4','2','P','1','6') +#define ERRCODE_INVALID_OBJECT_DEFINITION MAKE_SQLSTATE('4','2','P','1','7') +#define ERRCODE_INVALID_TEMP_OBJECTS MAKE_SQLSTATE('4','2','P','1','8') +#define ERRCODE_UNDEFINED_KEY MAKE_SQLSTATE('4','2','7','0','5') +#define ERRCODE_DUPLICATE_KEY MAKE_SQLSTATE('4','2','7','1','1') +#define ERRCODE_UNDEFINED_CL_COLUMN MAKE_SQLSTATE('4','2','7','1','3') + +/* Class 44 - WITH CHECK OPTION Violation */ +#define ERRCODE_WITH_CHECK_OPTION_VIOLATION MAKE_SQLSTATE('4','4','0','0','0') + +/* Class 53 - Insufficient Resources */ +#define ERRCODE_INSUFFICIENT_RESOURCES MAKE_SQLSTATE('5','3','0','0','0') +#define ERRCODE_DISK_FULL MAKE_SQLSTATE('5','3','1','0','0') +#define ERRCODE_OUT_OF_MEMORY MAKE_SQLSTATE('5','3','2','0','0') +#define ERRCODE_TOO_MANY_CONNECTIONS MAKE_SQLSTATE('5','3','3','0','0') +#define ERRCODE_CONFIGURATION_LIMIT_EXCEEDED MAKE_SQLSTATE('5','3','4','0','0') +#define ERRCODE_OUT_OF_BUFFER MAKE_SQLSTATE('5','3','5','0','0') + +/* Class 54 - Program Limit Exceeded */ +#define ERRCODE_PROGRAM_LIMIT_EXCEEDED MAKE_SQLSTATE('5','4','0','0','0') +#define ERRCODE_STATEMENT_TOO_COMPLEX MAKE_SQLSTATE('5','4','0','0','1') +#define ERRCODE_TOO_MANY_COLUMNS MAKE_SQLSTATE('5','4','0','1','1') +#define ERRCODE_TOO_MANY_ARGUMENTS MAKE_SQLSTATE('5','4','0','2','3') + +/* Class 55 - Object Not In Prerequisite State */ +#define ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE MAKE_SQLSTATE('5','5','0','0','0') +#define ERRCODE_OBJECT_IN_USE MAKE_SQLSTATE('5','5','0','0','6') +#define ERRCODE_CANT_CHANGE_RUNTIME_PARAM MAKE_SQLSTATE('5','5','P','0','2') +#define ERRCODE_LOCK_NOT_AVAILABLE MAKE_SQLSTATE('5','5','P','0','3') + +/* Class 57 - Operator Intervention */ +#define ERRCODE_OPERATOR_INTERVENTION MAKE_SQLSTATE('5','7','0','0','0') +#define ERRCODE_QUERY_CANCELED MAKE_SQLSTATE('5','7','0','1','4') +#define ERRCODE_QUERY_INTERNAL_CANCEL MAKE_SQLSTATE('5','7','0','1','5') +#define ERRCODE_ADMIN_SHUTDOWN MAKE_SQLSTATE('5','7','P','0','1') +#define ERRCODE_CRASH_SHUTDOWN MAKE_SQLSTATE('5','7','P','0','2') +#define ERRCODE_CANNOT_CONNECT_NOW MAKE_SQLSTATE('5','7','P','0','3') +#define ERRCODE_DATABASE_DROPPED MAKE_SQLSTATE('5','7','P','0','4') +#define ERRCODE_RU_STOP_QUERY MAKE_SQLSTATE('5','7','P','0','5') + +/* Class 58 - System Error (errors external to PostgreSQL itself) */ +#define ERRCODE_SYSTEM_ERROR MAKE_SQLSTATE('5','8','0','0','0') +#define ERRCODE_IO_ERROR MAKE_SQLSTATE('5','8','0','3','0') +#define ERRCODE_UNDEFINED_FILE MAKE_SQLSTATE('5','8','P','0','1') +#define ERRCODE_DUPLICATE_FILE MAKE_SQLSTATE('5','8','P','0','2') +#define ERRCODE_FILE_READ_FAILED MAKE_SQLSTATE('5','8','P','0','3') +#define ERRCODE_FILE_WRITE_FAILED MAKE_SQLSTATE('5','8','P','0','4') +#define ERRCODE_INVALID_ENCRYPTED_COLUMN_DATA MAKE_SQLSTATE('2','2','0','0','Z') + +/* Class F0 - Configuration File Error */ +#define ERRCODE_CONFIG_FILE_ERROR MAKE_SQLSTATE('F','0','0','0','0') +#define ERRCODE_LOCK_FILE_EXISTS MAKE_SQLSTATE('F','0','0','0','1') + +/* Class HV - Foreign Data Wrapper Error (SQL/MED) */ +#define ERRCODE_FDW_ERROR MAKE_SQLSTATE('H','V','0','0','0') +#define ERRCODE_FDW_COLUMN_NAME_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','5') +#define ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED MAKE_SQLSTATE('H','V','0','0','2') +#define ERRCODE_FDW_FUNCTION_SEQUENCE_ERROR MAKE_SQLSTATE('H','V','0','1','0') +#define ERRCODE_FDW_INCONSISTENT_DESCRIPTOR_INFORMATION MAKE_SQLSTATE('H','V','0','2','1') +#define ERRCODE_FDW_INVALID_ATTRIBUTE_VALUE MAKE_SQLSTATE('H','V','0','2','4') +#define ERRCODE_FDW_INVALID_COLUMN_NAME MAKE_SQLSTATE('H','V','0','0','7') +#define ERRCODE_FDW_INVALID_COLUMN_NUMBER MAKE_SQLSTATE('H','V','0','0','8') +#define ERRCODE_FDW_INVALID_DATA_TYPE MAKE_SQLSTATE('H','V','0','0','4') +#define ERRCODE_FDW_INVALID_DATA_TYPE_DESCRIPTORS MAKE_SQLSTATE('H','V','0','0','6') +#define ERRCODE_FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER MAKE_SQLSTATE('H','V','0','9','1') +#define ERRCODE_FDW_INVALID_HANDLE MAKE_SQLSTATE('H','V','0','0','B') +#define ERRCODE_FDW_INVALID_OPTION_INDEX MAKE_SQLSTATE('H','V','0','0','C') +#define ERRCODE_FDW_INVALID_OPTION_NAME MAKE_SQLSTATE('H','V','0','0','D') +#define ERRCODE_FDW_INVALID_OPTOIN_DATA MAKE_SQLSTATE('H','V','0','0','E') +#define ERRCODE_FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH MAKE_SQLSTATE('H','V','0','9','0') +#define ERRCODE_FDW_INVALID_STRING_FORMAT MAKE_SQLSTATE('H','V','0','0','A') +#define ERRCODE_FDW_INVALID_USE_OF_NULL_POINTER MAKE_SQLSTATE('H','V','0','0','9') +#define ERRCODE_FDW_TOO_MANY_HANDLES MAKE_SQLSTATE('H','V','0','1','4') +#define ERRCODE_FDW_OUT_OF_MEMORY MAKE_SQLSTATE('H','V','0','0','1') +#define ERRCODE_FDW_NO_SCHEMAS MAKE_SQLSTATE('H','V','0','0','P') +#define ERRCODE_FDW_OPTION_NAME_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','J') +#define ERRCODE_FDW_REPLY_HANDLE MAKE_SQLSTATE('H','V','0','0','K') +#define ERRCODE_FDW_SCHEMA_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','Q') +#define ERRCODE_FDW_TABLE_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','R') +#define ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION MAKE_SQLSTATE('H','V','0','0','L') +#define ERRCODE_FDW_UNABLE_TO_CREATE_REPLY MAKE_SQLSTATE('H','V','0','0','M') +#define ERRCODE_FDW_UNABLE_TO_ESTABLISH_CONNECTION MAKE_SQLSTATE('H','V','0','0','N') +#define ERRCODE_FDW_INVALID_LIST_LENGTH MAKE_SQLSTATE('H','V','0','0','O') +#define ERRCODE_FDW_INVALID_SERVER_TYPE MAKE_SQLSTATE('H','V','0','0','S') +#define ERRCODE_FDW_OPERATION_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','5') +#define ERRCODE_FDW_CROSS_STORAGE_ENGINE_TRANSACTION_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','6') +#define ERRCODE_FDW_CROSS_STORAGE_ENGINE_QUERY_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','7') +#define ERRCODE_FDW_UPDATE_INDEXED_FIELD_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','8') +#define ERRCODE_FDW_TOO_MANY_INDEXES MAKE_SQLSTATE('H','V','0','2','9') +#define ERRCODE_FDW_KEY_SIZE_EXCEEDS_MAX_ALLOWED MAKE_SQLSTATE('H','V','0','3','0') +#define ERRCODE_FDW_DDL_IN_TRANSACTION_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','1') +#define ERRCODE_FDW_TOO_MANY_INDEX_COLUMNS MAKE_SQLSTATE('H','V','0','3','2') +#define ERRCODE_FDW_INDEX_ON_NULLABLE_COLUMN_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','3') +#define ERRCODE_FDW_TOO_MANY_DDL_CHANGES_IN_TRANSACTION_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','4') + +/* Class P0 - PL/pgSQL Error */ +#define ERRCODE_PLPGSQL_ERROR MAKE_SQLSTATE('P','0','0','0','0') +#define ERRCODE_RAISE_EXCEPTION MAKE_SQLSTATE('P','0','0','0','1') +#define ERRCODE_NO_DATA_FOUND MAKE_SQLSTATE('P','0','0','0','2') +#define ERRCODE_TOO_MANY_ROWS MAKE_SQLSTATE('P','0','0','0','3') +#define ERRCODE_FORALL_NEED_DML MAKE_SQLSTATE('P','0','0','0','4') + +/* Class XX - Internal Error */ +#define ERRCODE_INTERNAL_ERROR MAKE_SQLSTATE('X','X','0','0','0') +#define ERRCODE_DATA_CORRUPTED MAKE_SQLSTATE('X','X','0','0','1') +#define ERRCODE_INDEX_CORRUPTED MAKE_SQLSTATE('X','X','0','0','2') +#define ERRCODE_STREAM_REMOTE_CLOSE_SOCKET MAKE_SQLSTATE('X','X','0','0','3') +#define ERRCODE_UNRECOGNIZED_NODE_TYPE MAKE_SQLSTATE('X','X','0','0','4') +#define ERRCODE_UNEXPECTED_NULL_VALUE MAKE_SQLSTATE('X','X','0','0','5') +#define ERRCODE_UNEXPECTED_NODE_STATE MAKE_SQLSTATE('X','X','0','0','6') +#define ERRCODE_NULL_JUNK_ATTRIBUTE MAKE_SQLSTATE('X','X','0','0','7') +#define ERRCODE_OPTIMIZER_INCONSISTENT_STATE MAKE_SQLSTATE('X','X','0','0','8') +#define ERRCODE_STREAM_DUPLICATE_QUERY_ID MAKE_SQLSTATE('X','X','0','0','9') +#define ERRCODE_INVALID_BUFFER MAKE_SQLSTATE('X','X','0','1','0') +#define ERRCODE_INVALID_BUFFER_REFERENCE MAKE_SQLSTATE('X','X','0','1','1') +#define ERRCODE_NODE_ID_MISSMATCH MAKE_SQLSTATE('X','X','0','1','2') +#define ERRCODE_CANNOT_MODIFY_XIDBASE MAKE_SQLSTATE('X','X','0','1','3') +#define ERRCODE_UNEXPECTED_CHUNK_VALUE MAKE_SQLSTATE('X','X','0','1','4') +#define ERRCODE_CN_RETRY_STUB MAKE_SQLSTATE('X','X','0','1','5') + +/* Class CG - CodeGen Error */ +#define ERRCODE_CODEGEN_ERROR MAKE_SQLSTATE('C','G','0','0','0') +#define ERRCODE_LOAD_IR_FUNCTION_FAILED MAKE_SQLSTATE('C','G','0','0','1') +#define ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED MAKE_SQLSTATE('C','G','0','0','2') + +/* Class YY - SQL Retry Error */ +#define ERRCODE_CONNECTION_RESET_BY_PEER MAKE_SQLSTATE('Y','Y','0','0','1') +#define ERRCODE_STREAM_CONNECTION_RESET_BY_PEER MAKE_SQLSTATE('Y','Y','0','0','2') +#define ERRCODE_LOCK_WAIT_TIMEOUT MAKE_SQLSTATE('Y','Y','0','0','3') +#define ERRCODE_CONNECTION_TIMED_OUT MAKE_SQLSTATE('Y','Y','0','0','4') +#define ERRCODE_SET_QUERY MAKE_SQLSTATE('Y','Y','0','0','5') +#define ERRCODE_OUT_OF_LOGICAL_MEMORY MAKE_SQLSTATE('Y','Y','0','0','6') +#define ERRCODE_SCTP_MEMORY_ALLOC MAKE_SQLSTATE('Y','Y','0','0','7') +#define ERRCODE_SCTP_NO_DATA_IN_BUFFER MAKE_SQLSTATE('Y','Y','0','0','8') +#define ERRCODE_SCTP_RELEASE_MEMORY_CLOSE MAKE_SQLSTATE('Y','Y','0','0','9') +#define ERRCODE_SCTP_TCP_DISCONNECT MAKE_SQLSTATE('Y','Y','0','1','0') +#define ERRCODE_SCTP_DISCONNECT MAKE_SQLSTATE('Y','Y','0','1','1') +#define ERRCODE_SCTP_REMOTE_CLOSE MAKE_SQLSTATE('Y','Y','0','1','2') +#define ERRCODE_SCTP_WAIT_POLL_UNKNOW MAKE_SQLSTATE('Y','Y','0','1','3') +#define ERRCODE_SNAPSHOT_INVALID MAKE_SQLSTATE('Y','Y','0','1','4') +#define ERRCODE_CONNECTION_RECEIVE_WRONG MAKE_SQLSTATE('Y','Y','0','1','5') +#define ERRCODE_STREAM_CONCURRENT_UPDATE MAKE_SQLSTATE('Y','Y','0','1','6') + +/* Class SI - SPI Interface Error */ +#define ERRCODE_SPI_ERROR MAKE_SQLSTATE('S','P','0','0','0') +#define ERRCODE_SPI_CONNECTION_FAILURE MAKE_SQLSTATE('S','P','0','0','1') +#define ERRCODE_SPI_FINISH_FAILURE MAKE_SQLSTATE('S','P','0','0','2') +#define ERRCODE_SPI_PREPARE_FAILURE MAKE_SQLSTATE('S','P','0','0','3') +#define ERRCODE_SPI_CURSOR_OPEN_FAILURE MAKE_SQLSTATE('S','P','0','0','4') +#define ERRCODE_SPI_EXECUTE_FAILURE MAKE_SQLSTATE('S','P','0','0','5') +#define ERRORCODE_SPI_IMPROPER_CALL MAKE_SQLSTATE('S','P','0','0','6') +#define ERRCODE_PLDEBUGGER_ERROR MAKE_SQLSTATE('D','0','0','0','0') +#define ERRCODE_DUPLICATE_BREAKPOINT MAKE_SQLSTATE('D','0','0','0','1') +#define ERRCODE_FUNCTION_HASH_NOT_INITED MAKE_SQLSTATE('D','0','0','0','2') +#define ERRCODE_BREAKPOINT_NOT_PRESENT MAKE_SQLSTATE('D','0','0','0','3') +#define ERRCODE_TARGET_SERVER_ALREADY_ATTACHED MAKE_SQLSTATE('D','0','0','0','4') +#define ERRCODE_TARGET_SERVER_NOT_ATTACHED MAKE_SQLSTATE('D','0','0','0','5') +#define ERRCODE_DEBUG_SERVER_ALREADY_SYNC MAKE_SQLSTATE('D','0','0','0','6') +#define ERRCODE_DEBUG_TARGET_SERVERS_NOT_IN_SYNC MAKE_SQLSTATE('D','0','0','0','7') +#define ERRCODE_TARGET_SERVER_ALREADY_SYNC MAKE_SQLSTATE('D','0','0','0','8') +#define ERRCODE_NONEXISTANT_VARIABLE MAKE_SQLSTATE('D','0','0','0','9') +#define ERRCODE_INVALID_TARGET_SESSION_ID MAKE_SQLSTATE('D','0','0','1','0') +#define ERRCODE_INVALID_OPERATION MAKE_SQLSTATE('D','0','0','1','1') +#define ERRCODE_MAX_DEBUG_SESSIONS_REACHED MAKE_SQLSTATE('D','0','0','1','2') +#define ERRCODE_MAX_BREAKPOINTS_REACHED MAKE_SQLSTATE('D','0','0','1','3') +#define ERRCODE_INITIALIZE_FAILED MAKE_SQLSTATE('D','0','0','1','4') +#define ERRCODE_RBTREE_INVALID_NODE_STATE MAKE_SQLSTATE('R','B','0','0','1') +#define ERRCODE_RBTREE_INVALID_ITERATOR_ORDER MAKE_SQLSTATE('R','B','0','0','2') +#define ERRCODE_DEBUG MAKE_SQLSTATE('D','B','0','0','1') +#define ERRCODE_LOG MAKE_SQLSTATE('D','B','0','1','0') +#define ERRCODE_OPERATE_FAILED MAKE_SQLSTATE('O','P','0','0','1') +#define ERRCODE_OPERATE_RESULT_NOT_EXPECTED MAKE_SQLSTATE('O','P','0','0','2') +#define ERRCODE_OPERATE_NOT_SUPPORTED MAKE_SQLSTATE('O','P','0','0','3') +#define ERRCODE_OPERATE_INVALID_PARAM MAKE_SQLSTATE('O','P','0','A','3') +#define ERRCODE_INDEX_OPERATOR_MISMATCH MAKE_SQLSTATE('O','P','0','0','4') +#define ERRCODE_NO_FUNCTION_PROVIDED MAKE_SQLSTATE('O','P','0','0','5') +#define ERRCODE_LOGICAL_DECODE_ERROR MAKE_SQLSTATE('L','L','0','0','1') +#define ERRCODE_RELFILENODEMAP MAKE_SQLSTATE('L','L','0','0','2') + +/* Class TS - Timeseries Error */ +#define ERRCODE_TS_COMMON_ERROR MAKE_SQLSTATE('T','S','0','0','0') +#define ERRCODE_TS_KEYTYPE_MISMATCH MAKE_SQLSTATE('T','S','0','0','1') diff -uprN postgresql-hll-2.14_old/include/include/utils/evp_cipher.h postgresql-hll-2.14/include/include/utils/evp_cipher.h --- postgresql-hll-2.14_old/include/include/utils/evp_cipher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/evp_cipher.h 2020-12-12 17:06:43.285348529 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * evp_cipher.h + * SM4 encryption algorithm + * Interfaces of the AES encryption algorithm + * + * + * IDENTIFICATION + * src/include/utils/evp_cipher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SM4_H +#define SM4_H + +#include + +unsigned long sm4_ctr_enc_partial_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, unsigned char* key, unsigned char* iv); +unsigned long sm4_ctr_dec_partial_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, unsigned char* key, unsigned char* iv); +unsigned long aes_ctr_enc_partial_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, unsigned char* key, unsigned char* iv); +unsigned long aes_ctr_dec_partial_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, unsigned char* key, unsigned char* iv); + +#endif /* SM4_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/extended_statistics.h postgresql-hll-2.14/include/include/utils/extended_statistics.h --- postgresql-hll-2.14_old/include/include/utils/extended_statistics.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/extended_statistics.h 2020-12-12 17:06:43.285348529 +0800 @@ -0,0 +1,130 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * extended_statistics.h + * Extended statistics and selectivity estimation functions. + * + * + * IDENTIFICATION + * src/include/utils/extended_statistics.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef EXTENDED_STATISTICS_H +#define EXTENDED_STATISTICS_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "catalog/pg_statistic.h" +#include "commands/vacuum.h" +#include "nodes/parsenodes.h" +#include "utils/catcache.h" +#include "utils/relcache.h" + +#define ES_LOGLEVEL DEBUG3 +#define ES_COMMIT_VERSION 91112 + +#define ES_MULTI_COLUMN_STATS_ATTNUM -101 +#define MAX_NUM_MULTI_COLUMN_STATS 1000 +#define ES_MAX_FETCH_NUM_OF_INSTANCE 100 + +typedef enum ES_STATISTIC_KIND { + ES_SEARCH = 0x00u, + ES_NULLFRAC = 0x01u, + ES_WIDTH = 0x02u, + ES_DISTINCT = 0x04u, + ES_DNDISTINCT = 0x08u, + ES_MCV = 0x10u, + ES_NULL_MCV = 0x20u, + ES_ALL = 0x3fu +} ES_STATISTIC_KIND; + +typedef enum ES_COLUMN_NAME_ALIAS { ES_COLUMN_NAME = 0x01u, ES_COLUMN_ALIAS = 0x02u } ES_COLUMN_NAME_ALIAS; + +typedef struct ExtendedStats { + Bitmapset* bms_attnum; + float4 nullfrac; + int4 width; + float4 distinct; + float4 dndistinct; + Datum* mcv_values = NULL; + bool* mcv_nulls = NULL; + int mcv_nvalues; + float4* mcv_numbers = NULL; + int mcv_nnumbers; + float4* other_mcv_numbers = NULL; + int other_mcv_nnumbers; +} ExtendedStats; + +extern void es_free_extendedstats(ExtendedStats* es); +extern void es_free_extendedstats_list(List* es_list); + +extern char es_get_starelkind(); +extern bool es_get_stainherit(); + +extern List* es_attnum_bmslist_add_unique_item(List* bmslist, Bitmapset* bms_attnum); + +extern Form_pg_type es_get_attrtype(Oid typeoid); +extern void es_get_column_typid_typmod(Oid relid, int2 attnum, Oid* atttypid, int* atttypmod); +extern void es_get_columns_typid_typmod( + Oid relid, int2vector* stakey, Oid** p_atttypid_array, int** p_atttypmod_array, unsigned int* p_num_column); +extern Oid es_get_typinput(Oid typeoid); + +extern void es_get_attnum_of_statistic_items( + Relation rel, VacuumStmt* vacstmt, Bitmapset** p_bms_single_column, List** p_list_multi_column); +extern void es_check_alter_table_statistics(Relation rel, AlterTableCmd* cmd); +extern Bitmapset* es_get_attnums_to_analyze(VacAttrStats** vacattrstats, int vacattrstats_size); + +extern VacAttrStats* es_make_vacattrstats(unsigned int num_attrs); + +extern bool es_is_valid_column_to_analyze(Form_pg_attribute attr); +extern bool es_is_type_supported_by_cstore(VacAttrStats* stats); +extern bool es_is_type_distributable(VacAttrStats* stats); + +extern void es_check_availability_for_table(VacuumStmt* stmt, Relation rel, bool inh, bool* replicate_needs_extstats); + +extern bool es_is_variable_width(VacAttrStats* stats); +extern bool es_is_not_null(AnalyzeSampleTableSpecInfo* spec); +extern bool es_is_distributekey_contained_in_multi_column(Oid relid, VacAttrStats* stats); + +/* + * Analyze query + */ +extern char* es_get_column_name_alias(AnalyzeSampleTableSpecInfo* spec, uint32 name_alias_flag, + const char* separator = ", ", const char* prefix = "", const char* postfix = ""); + +/* + * System table + */ +extern Bitmapset* es_get_multi_column_attnum(HeapTuple tuple, Relation relation); +extern List* es_explore_declared_stats(Oid relid, VacuumStmt* vacstmt, bool inh); +extern Datum es_mcv_slot_cstring_array_to_array_array( + Datum cstring_array, unsigned int num_column, const Oid* atttypid_array, const int* atttypmod_array); +extern VacAttrStats** es_build_vacattrstats_array( + Relation rel, List* bmslist_multicolumn, bool add_or_delete, int* array_length, bool inh); +extern ArrayType* es_construct_mcv_value_array(VacAttrStats* stats, int mcv_slot_index); +extern bool es_is_multicolumn_stats_exists(Oid relid, char relkind, bool inh, Bitmapset* bms_attnums); + +/* + * Interfaces for optimizer + */ +extern float4 es_get_multi_column_distinct(Oid relid, char relkind, bool inh, Bitmapset* bms_attnums); +extern ExtendedStats* es_get_multi_column_stats( + Oid relid, char relkind, bool inh, Bitmapset* bms_attnums, bool has_null = false); +extern List* es_get_multi_column_stats(Oid relid, char relkind, bool inh, int* num_stats, bool has_null = false); +extern void es_split_multi_column_stats(List* va_list, List** va_cols, List** va_cols_multi); + +#endif /* EXTENDED_STATISTICS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/fmgroids.h postgresql-hll-2.14/include/include/utils/fmgroids.h --- postgresql-hll-2.14_old/include/include/utils/fmgroids.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/fmgroids.h 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,2834 @@ +/*------------------------------------------------------------------------- + * + * fmgroids.h + * Macros that define the OIDs of built-in functions. + * + * These macros can be used to avoid a catalog lookup when a specific + * fmgr-callable function needs to be referenced. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * NOTES + * ****************************** + * *** DO NOT EDIT THIS FILE! *** + * ****************************** + * + * It has been GENERATED by Gen_fmgrtab.pl + * from ../../../../src/common/backend/catalog/builtin_funcs.ini + * + *------------------------------------------------------------------------- + */ +#ifndef FMGROIDS_H +#define FMGROIDS_H + +/* + * Constant macros for the OIDs of entries in pg_proc. + * + * NOTE: macros are named after the prosrc value, ie the actual C name + * of the implementing function, not the proname which may be overloaded. + * For example, we want to be able to assign different macro names to both + * char_text() and name_text() even though these both appear with proname + * 'text'. If the same C function appears in more than one pg_proc entry, + * its equivalent macro will be defined with the lowest OID among those + * entries. + */ +#define F_RI_FKEY_CASCADE_DEL 1646 +#define F_RI_FKEY_CASCADE_UPD 1647 +#define F_RI_FKEY_CHECK_INS 1644 +#define F_RI_FKEY_CHECK_UPD 1645 +#define F_RI_FKEY_NOACTION_DEL 1654 +#define F_RI_FKEY_NOACTION_UPD 1655 +#define F_RI_FKEY_RESTRICT_DEL 1648 +#define F_RI_FKEY_RESTRICT_UPD 1649 +#define F_RI_FKEY_SETDEFAULT_DEL 1652 +#define F_RI_FKEY_SETDEFAULT_UPD 1653 +#define F_RI_FKEY_SETNULL_DEL 1650 +#define F_RI_FKEY_SETNULL_UPD 1651 +#define F_INET_ABBREV 598 +#define F_CIDR_ABBREV 599 +#define F_FLOAT4ABS 1394 +#define F_FLOAT8ABS 1395 +#define F_INT8ABS 1396 +#define F_INT4ABS 1397 +#define F_INT2ABS 1398 +#define F_NUMERIC_ABS 1705 +#define F_TIMESTAMPTZ_ABSTIME 1180 +#define F_TIMESTAMP_ABSTIME TIMESTAMP2ABSTIMEFUNCOID +#define F_ABSTIMEEQ 251 +#define F_ABSTIMEGE 256 +#define F_ABSTIMEGT 254 +#define F_ABSTIMEIN ABSTIMEINFUNCOID +#define F_ABSTIMELE 255 +#define F_ABSTIMELT 253 +#define F_ABSTIMENE 252 +#define F_ABSTIMEOUT ABSTIMEOUTFUNCOID +#define F_ABSTIMERECV 2462 +#define F_ABSTIMESEND 2463 +#define F_ACLCONTAINS 1037 +#define F_ACLDEFAULT_SQL 3943 +#define F_ACLEXPLODE 1689 +#define F_ACLINSERT 1035 +#define F_ACLITEM_EQ 1062 +#define F_ACLITEMIN 1031 +#define F_ACLITEMOUT 1032 +#define F_ACLREMOVE 1036 +#define F_DACOS 1601 +#define F_ADD_JOB_CLASS_DEPEND_INTERNAL 6004 +#define F_ADD_MONTHS 4074 +#define F_XID_AGE 1181 +#define F_TIMESTAMPTZ_AGE 1199 +#define F_TIMESTAMP_AGE 2058 +#define F_ANY_IN 2294 +#define F_ANY_OUT 2295 +#define F_ANYARRAY_IN ANYARRAYINFUNCOID +#define F_ANYARRAY_OUT 2297 +#define F_ANYARRAY_RECV 2502 +#define F_ANYARRAY_SEND 2503 +#define F_ANYELEMENT_IN 2312 +#define F_ANYELEMENT_OUT 2313 +#define F_ANYENUM_IN 3504 +#define F_ANYENUM_OUT 3505 +#define F_ANYNONARRAY_IN 2777 +#define F_ANYNONARRAY_OUT 2778 +#define F_ANYRANGE_IN 3832 +#define F_ANYRANGE_OUT 3833 +#define F_BOX_AREA 975 +#define F_PATH_AREA 979 +#define F_CIRCLE_AREA 1468 +#define F_AREAJOINSEL 140 +#define F_AREASEL 139 +#define F_AGGREGATE_DUMMY ARRAYAGGFUNCOID +#define F_ARRAY_AGG_FINALFN 2334 +#define F_ARRAY_AGG_TRANSFN 2333 +#define F_ARRAY_PUSH 378 +#define F_ARRAY_CAT 383 +#define F_ARRAY_DIMS 747 +#define F_ARRAY_EQ 744 +#define F_ARRAY_EXTEND 3179 +#define F_ARRAY_FILL 1193 +#define F_ARRAY_FILL_WITH_LOWER_BOUNDS 1286 +#define F_ARRAY_GE 396 +#define F_ARRAY_GT 392 +#define F_ARRAY_IN 750 +#define F_ARRAY_LARGER 515 +#define F_ARRAY_LE 393 +#define F_ARRAY_LENGTH 2176 +#define F_ARRAY_LOWER 2091 +#define F_ARRAY_LT 391 +#define F_ARRAY_NDIMS 748 +#define F_ARRAY_NE 390 +#define F_ARRAY_OUT 751 +#define F_ARRAY_RECV 2400 +#define F_ARRAY_SEND 2401 +#define F_ARRAY_SMALLER 516 +#define F_ARRAY_TO_JSON 3153 +#define F_ARRAY_TO_JSON_PRETTY 3154 +#define F_ARRAY_TO_TEXT_NULL ARRAYTOSTRINGNULLFUNCOID +#define F_ARRAY_TO_TEXT ARRAYTOSTRINGFUNCOID +#define F_ARRAY_TYPANALYZE 3816 +#define F_ARRAY_UPPER 2092 +#define F_ARRAYCONTAINED 2749 +#define F_ARRAYCONTAINS 2748 +#define F_ARRAYCONTJOINSEL 3818 +#define F_ARRAYCONTSEL 3817 +#define F_ARRAYOVERLAP 2747 +#define F_ASCII 1620 +#define F_DASIN ARCSINEFUNCOID +#define F_DATAN 1602 +#define F_DATAN2 1603 +#define F_BIGINT_TID 3214 +#define F_BITFROMINT4 1683 +#define F_BIT 1685 +#define F_BITFROMINT8 2075 +#define F_BIT_IN 1564 +#define F_BIT_OUT 1565 +#define F_BIT_RECV 2456 +#define F_BIT_SEND 2457 +#define F_BIT_AND 1673 +#define F_BITCAT 1679 +#define F_BITCMP 1596 +#define F_BITEQ 1581 +#define F_BITGE 1592 +#define F_BITGT 1593 +#define F_BITLE 1594 +#define F_BITLT 1595 +#define F_BITNE 1582 +#define F_BITNOT 1676 +#define F_BIT_OR 1674 +#define F_BITSHIFTLEFT 1677 +#define F_BITSHIFTRIGHT 1678 +#define F_BITTYPMODIN 2919 +#define F_BITTYPMODOUT 2920 +#define F_BITXOR 1675 +#define F_INT4_BOOL 2557 +#define F_BOOL_INT1 5534 +#define F_BOOL_INT2 3181 +#define F_BOOL_INT8 3178 +#define F_BOOLAND_STATEFUNC 2515 +#define F_BOOLEQ 60 +#define F_BOOLGE 1692 +#define F_BOOLGT 57 +#define F_BOOLIN 1242 +#define F_BOOLLE 1691 +#define F_BOOLLT 56 +#define F_BOOLNE 84 +#define F_BOOLOR_STATEFUNC 2516 +#define F_BOOLOUT 1243 +#define F_BOOLRECV 2436 +#define F_BOOLSEND 2437 +#define F_POINTS_BOX 1421 +#define F_POLY_BOX 1446 +#define F_CIRCLE_BOX 1480 +#define F_BOX_ABOVE 2565 +#define F_BOX_ABOVE_EQ 115 +#define F_BOX_ADD 1422 +#define F_BOX_BELOW 2562 +#define F_BOX_BELOW_EQ 116 +#define F_BOX_CENTER 138 +#define F_BOX_CONTAIN 187 +#define F_BOX_CONTAIN_PT 193 +#define F_BOX_CONTAINED 192 +#define F_BOX_DISTANCE 978 +#define F_BOX_DIV 1425 +#define F_BOX_EQ 128 +#define F_BOX_GE 126 +#define F_BOX_GT 127 +#define F_BOX_IN 123 +#define F_BOX_INTERSECT 980 +#define F_BOX_LE 130 +#define F_BOX_LEFT 188 +#define F_BOX_LT 129 +#define F_BOX_MUL 1424 +#define F_BOX_OUT 124 +#define F_BOX_OVERABOVE 2564 +#define F_BOX_OVERBELOW 2563 +#define F_BOX_OVERLAP 125 +#define F_BOX_OVERLEFT 189 +#define F_BOX_OVERRIGHT 190 +#define F_BOX_RECV 2484 +#define F_BOX_RIGHT 191 +#define F_BOX_SAME 186 +#define F_BOX_SEND 2485 +#define F_BOX_SUB 1423 +#define F_NAME_BPCHAR 408 +#define F_BPCHAR 668 +#define F_CHAR_BPCHAR 860 +#define F_BPCHAR_DATE 4163 +#define F_BPCHAR_FLOAT4 4196 +#define F_BPCHAR_FLOAT8 4197 +#define F_BPCHAR_INT4 4175 +#define F_BPCHAR_INT8 4195 +#define F_BPCHAR_LARGER 1063 +#define F_BPCHAR_NUMERIC 4172 +#define F_BPCHAR_PATTERN_GE 2177 +#define F_BPCHAR_PATTERN_GT 2178 +#define F_BPCHAR_PATTERN_LE 2175 +#define F_BPCHAR_PATTERN_LT 2174 +#define F_BPCHAR_SMALLER 1064 +#define F_BPCHAR_SORTSUPPORT 3256 +#define F_BPCHAR_TIMESTAMP 4187 +#define F_BPCHARCMP 1078 +#define F_BPCHAREQ 1048 +#define F_BPCHARGE 1052 +#define F_BPCHARGT 1051 +#define F_TEXTICLIKE 1660 +#define F_TEXTICNLIKE 1661 +#define F_TEXTICREGEXEQ 1656 +#define F_TEXTICREGEXNE 1657 +#define F_BPCHARIN 1044 +#define F_BPCHARLE 1050 +#define F_TEXTLIKE 1631 +#define F_BPCHARLT 1049 +#define F_BPCHARNE 1053 +#define F_TEXTNLIKE 1632 +#define F_BPCHAROUT 1045 +#define F_BPCHARRECV 2430 +#define F_TEXTREGEXEQ 1658 +#define F_TEXTREGEXNE 1659 +#define F_BPCHARSEND 2431 +#define F_BPCHARTYPMODIN 2913 +#define F_BPCHARTYPMODOUT 2914 +#define F_NETWORK_BROADCAST 698 +#define F_BTABSTIMECMP 357 +#define F_BTARRAYCMP 382 +#define F_BTBEGINSCAN 333 +#define F_BTBOOLCMP 1693 +#define F_BTBPCHAR_PATTERN_CMP 2180 +#define F_BTBUILD 338 +#define F_BTBUILDEMPTY 328 +#define F_BTBULKDELETE 332 +#define F_BTCANRETURN 276 +#define F_BTCHARCMP 358 +#define F_BTCOSTESTIMATE 1268 +#define F_BTENDSCAN 335 +#define F_BTFLOAT48CMP 2194 +#define F_BTFLOAT4CMP 354 +#define F_BTFLOAT4SORTSUPPORT 3132 +#define F_BTFLOAT84CMP 2195 +#define F_BTFLOAT8CMP 355 +#define F_BTFLOAT8SORTSUPPORT 3133 +#define F_BTGETBITMAP 636 +#define F_BTGETTUPLE 330 +#define F_BTINSERT 331 +#define F_BTINT24CMP 2190 +#define F_BTINT28CMP 2192 +#define F_BTINT2CMP 350 +#define F_BTINT2SORTSUPPORT 3129 +#define F_BTINT42CMP 2191 +#define F_BTINT48CMP 2188 +#define F_BTINT4CMP 351 +#define F_BTINT4SORTSUPPORT 3130 +#define F_BTINT82CMP 2193 +#define F_BTINT84CMP 2189 +#define F_BTINT8CMP 842 +#define F_BTINT8SORTSUPPORT 3131 +#define F_BTMARKPOS 336 +#define F_BTMERGE 3184 +#define F_BTNAMECMP 359 +#define F_BTNAMESORTSUPPORT 3135 +#define F_BTOIDCMP 356 +#define F_BTOIDSORTSUPPORT 3134 +#define F_BTOIDVECTORCMP 404 +#define F_BTOPTIONS 2785 +#define F_BTRECORDCMP 2987 +#define F_BTRELTIMECMP 380 +#define F_BTRESCAN 334 +#define F_BTRESTRPOS 337 +#define F_BTRIM BTRIMPARAFUNCOID +#define F_BTRIM1 BTRIMFUNCOID +#define F_BYTEATRIM 2015 +#define F_BTTEXT_PATTERN_CMP 2166 +#define F_BTTEXTCMP 360 +#define F_BTTEXTSORTSUPPORT 3255 +#define F_BTTIDCMP 2794 +#define F_BTTINTERVALCMP 381 +#define F_BTVACUUMCLEANUP 972 +#define F_BUCKETABSTIME 4136 +#define F_BUCKETBOOL 4146 +#define F_BUCKETBPCHAR 4107 +#define F_BUCKETBYTEA 4142 +#define F_BUCKETCASH 4140 +#define F_BUCKETCHAR 4109 +#define F_BUCKETDATE 4113 +#define F_BUCKETFLOAT4 4156 +#define F_BUCKETFLOAT8 4158 +#define F_BUCKETINT1 4125 +#define F_BUCKETINT2 4103 +#define F_BUCKETINT2VECTOR 4150 +#define F_BUCKETINT4 4101 +#define F_BUCKETINT8 4105 +#define F_BUCKETINTERVAL 4121 +#define F_BUCKETNAME 4148 +#define F_BUCKETNUMERIC 4132 +#define F_BUCKETNVARCHAR2 4129 +#define F_BUCKETOID 4134 +#define F_BUCKETOIDVECTOR 4154 +#define F_BUCKETRAW 4144 +#define F_BUCKETRELTIME 4138 +#define F_BUCKETSMALLDATETIME 4127 +#define F_BUCKETTEXT 4152 +#define F_BUCKETTIME 4115 +#define F_BUCKETTIMESTAMP 4117 +#define F_BUCKETTIMESTAMPTZ 4123 +#define F_BUCKETTIMETZ 4119 +#define F_BUCKETUUID 6001 +#define F_BUCKETVARCHAR 4111 +#define F_BYTEA_SORTSUPPORT 3452 +#define F_BYTEA_STRING_AGG_FINALFN 3544 +#define F_BYTEA_STRING_AGG_TRANSFN 3543 +#define F_BYTEACAT 2011 +#define F_BYTEACMP 1954 +#define F_BYTEAEQ 1948 +#define F_BYTEAGE 1952 +#define F_BYTEAGT 1951 +#define F_BYTEAIN 1244 +#define F_BYTEALE 1950 +#define F_BYTEALIKE 2005 +#define F_BYTEALT 1949 +#define F_BYTEANE 1953 +#define F_BYTEANLIKE 2006 +#define F_BYTEAOUT 31 +#define F_BYTEARECV 2412 +#define F_BYTEASEND 2413 +#define F_BYTEAWITHOUTORDERCOLIN 4423 +#define F_BYTEAWITHOUTORDERCOLOUT 4428 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMP 4418 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMPBYTEAL 4463 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMPBYTEAR 4456 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQ 4412 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQBYTEAL 4457 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQBYTEAR 4447 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLIN 4440 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNE 4417 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNEBYTEAL 4561 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNEBYTEAR 4460 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLOUT 4446 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLRECV 4444 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLSEND 4451 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLTYPMODIN 4449 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLTYPMODOUT 4450 +#define F_CAPTURE_VIEW_TO_JSON 5719 +#define F_CASH_CMP 377 +#define F_CASH_DIV_CASH 3822 +#define F_CASH_DIV_FLT4 847 +#define F_CASH_DIV_FLT8 897 +#define F_CASH_DIV_INT1 3351 +#define F_CASH_DIV_INT2 867 +#define F_CASH_DIV_INT4 865 +#define F_CASH_DIV_INT8 3345 +#define F_CASH_EQ 888 +#define F_CASH_GE 893 +#define F_CASH_GT 892 +#define F_CASH_IN CASHINFUNCOID +#define F_CASH_LE 891 +#define F_CASH_LT 890 +#define F_CASH_MI 895 +#define F_CASH_MUL_FLT4 846 +#define F_CASH_MUL_FLT8 896 +#define F_CASH_MUL_INT1 3350 +#define F_CASH_MUL_INT2 866 +#define F_CASH_MUL_INT4 864 +#define F_CASH_MUL_INT8 3344 +#define F_CASH_NE 889 +#define F_CASH_OUT CASHOUTFUNCOID +#define F_CASH_PL 894 +#define F_CASH_RECV 2492 +#define F_CASH_SEND 2493 +#define F_CASH_WORDS 935 +#define F_CASHLARGER 898 +#define F_CASHSMALLER 899 +#define F_DCBRT 1345 +#define F_CBTREEBUILD 4240 +#define F_CBTREECANRETURN 4245 +#define F_CBTREECOSTESTIMATE 4243 +#define F_CBTREEGETBITMAP 4246 +#define F_CBTREEGETTUPLE 4242 +#define F_CBTREEOPTIONS 4241 +#define F_NUMERIC_CEIL 1711 +#define F_DCEIL 2308 +#define F_CIRCLE_CENTER 1543 +#define F_CGINBUILD 4400 +#define F_CGINGETBITMAP 4401 +#define F_I4TOCHAR 78 +#define F_TEXT_CHAR 944 +#define F_BPCHARLEN 1372 +#define F_TEXTLEN CHARLENFUNCOID +#define F_CHAREQ 61 +#define F_CHARGE 74 +#define F_CHARGT 73 +#define F_CHARIN 1245 +#define F_CHARLE 72 +#define F_CHARLT 1246 +#define F_CHARNE 70 +#define F_CHAROUT 33 +#define F_CHARRECV 2434 +#define F_CHARSEND 2435 +#define F_CHECK_ENGINE_STATUS 3466 +#define F_CHECKSUMTEXT_AGG_TRANSFN 4601 +#define F_CHR 1621 +#define F_CIDEQ 69 +#define F_CIDIN 52 +#define F_CIDOUT 53 +#define F_INET_TO_CIDR 1715 +#define F_CIDR_IN 1267 +#define F_CIDR_OUT 1427 +#define F_CIDR_RECV 2498 +#define F_CIDR_SEND 2499 +#define F_CIDRECV 2442 +#define F_CIDSEND 2443 +#define F_CR_CIRCLE 1473 +#define F_POLY_CIRCLE 1474 +#define F_BOX_CIRCLE 1479 +#define F_CIRCLE_ABOVE 1461 +#define F_CIRCLE_ADD_PT 1146 +#define F_CIRCLE_BELOW 1460 +#define F_CIRCLE_CONTAIN 1453 +#define F_CIRCLE_CONTAIN_PT 1477 +#define F_CIRCLE_CONTAINED 1458 +#define F_CIRCLE_DISTANCE 1471 +#define F_CIRCLE_DIV_PT 1149 +#define F_CIRCLE_EQ 1462 +#define F_CIRCLE_GE 1467 +#define F_CIRCLE_GT 1465 +#define F_CIRCLE_IN 1450 +#define F_CIRCLE_LE 1466 +#define F_CIRCLE_LEFT 1454 +#define F_CIRCLE_LT 1464 +#define F_CIRCLE_MUL_PT 1148 +#define F_CIRCLE_NE 1463 +#define F_CIRCLE_OUT 1451 +#define F_CIRCLE_OVERABOVE 2588 +#define F_CIRCLE_OVERBELOW 2587 +#define F_CIRCLE_OVERLAP 1459 +#define F_CIRCLE_OVERLEFT 1455 +#define F_CIRCLE_OVERRIGHT 1456 +#define F_CIRCLE_RECV 2490 +#define F_CIRCLE_RIGHT 1457 +#define F_CIRCLE_SAME 1452 +#define F_CIRCLE_SEND 2491 +#define F_CIRCLE_SUB_PT 1147 +#define F_CLOCK_TIMESTAMP 2649 +#define F_CLOSE_LB 963 +#define F_CLOSE_LS 1488 +#define F_CLOSE_LSEG 1489 +#define F_CLOSE_PB 367 +#define F_CLOSE_PL 961 +#define F_CLOSE_PS 366 +#define F_CLOSE_SB 368 +#define F_CLOSE_SL 962 +#define F_COMM_CHECK_CONNECTION_STATUS 1982 +#define F_COMM_CLIENT_INFO 1991 +#define F_COMPLEX_ARRAY_IN 756 +#define F_TEXT_CONCAT CONCATFUNCOID +#define F_TEXT_CONCAT_WS CONCATWSFUNCOID +#define F_CONTJOINSEL 1303 +#define F_CONTSEL 1302 +#define F_PG_CONVERT CONVERTFUNCOID +#define F_PG_CONVERT_FROM CONVERTFROMFUNCOID +#define F_PG_CONVERT_TO CONVERTTOFUNCOID +#define F_PG_CONVERT_TO_NOCASE 3198 +#define F_DCOS COSINEFUNCOID +#define F_DCOT 1607 +#define F_CREATE_WDR_SNAPSHOT 5711 +#define F_CSTORE_TID_OUT 3215 +#define F_CSTRING_IN 2292 +#define F_CSTRING_OUT 2293 +#define F_CSTRING_RECV 2500 +#define F_CSTRING_SEND 2501 +#define F_WINDOW_CUME_DIST 3104 +#define F_CUPOINTER_BIGINT 3217 +#define F_CURRENT_DATABASE CURRENTDATABASEFUNCOID +#define F_CURRENT_QUERY 817 +#define F_CURRENT_SCHEMA CURRENTSCHEMAFUNCOID +#define F_CURRENT_SCHEMAS 1403 +#define F_SHOW_CONFIG_BY_NAME 2077 +#define F_CURRENT_USER CURRENTUSERFUNCOID +#define F_CURRTID_BYRELOID 1293 +#define F_CURRTID_BYRELNAME 1294 +#define F_CURRVAL_OID CURRVALFUNCOID +#define F_CURSOR_TO_XML 2925 +#define F_CURSOR_TO_XMLSCHEMA 2928 +#define F_DATABASE_TO_XML 2936 +#define F_DATABASE_TO_XML_AND_XMLSCHEMA 2938 +#define F_DATABASE_TO_XMLSCHEMA 2937 +#define F_DATALENGTH 8050 +#define F_TIMESTAMPTZ_DATE TIMESTAMPTZ2DATEFUNCOID +#define F_ABSTIME_DATE ABSTIME2DATEFUNCOID +#define F_TIMESTAMP_DATE TIMESTAMP2DATEOID +#define F_DATE_BPCHAR 4160 +#define F_DATE_CMP 1092 +#define F_DATE_CMP_TIMESTAMP 2344 +#define F_DATE_CMP_TIMESTAMPTZ DATECMPTIMESTAMPTZFUNCOID +#define F_DATE_EQ 1086 +#define F_DATE_EQ_TIMESTAMP 2340 +#define F_DATE_EQ_TIMESTAMPTZ DATEEQTIMESTAMPTZFUNCOID +#define F_DATE_GE 1090 +#define F_DATE_GE_TIMESTAMP 2342 +#define F_DATE_GE_TIMESTAMPTZ DATEGETIMESTAMPTZFUNCOID +#define F_DATE_GT 1089 +#define F_DATE_GT_TIMESTAMP 2341 +#define F_DATE_GT_TIMESTAMPTZ DATEGTTIMESTAMPTZFUNCOID +#define F_DATE_IN DATEINFUNCOID +#define F_DATE_LARGER 1138 +#define F_DATE_LE 1088 +#define F_DATE_LE_TIMESTAMP 2339 +#define F_DATE_LE_TIMESTAMPTZ DATELETIMESTAMPTZFUNCOID +#define F_DATE_LIST_AGG_NOARG2_TRANSFN 3581 +#define F_DATE_LIST_AGG_TRANSFN 3579 +#define F_DATE_LT 1087 +#define F_DATE_LT_TIMESTAMP 2338 +#define F_DATE_LT_TIMESTAMPTZ DATELTTIMESTAMPTZFUNCOID +#define F_DATE_MI 1140 +#define F_DATE_MI_INTERVAL 2072 +#define F_DATE_MII 1142 +#define F_DATE_NE 1091 +#define F_DATE_NE_TIMESTAMP 2343 +#define F_DATE_NE_TIMESTAMPTZ DATENETIMESTAMPTZFUNCOID +#define F_DATE_OUT DATEOUTFUNCOID +#define F_TIMESTAMPTZ_PART TIMESTAMPTZPARTFUNCOID +#define F_INTERVAL_PART INTERVALPARTFUNCOID +#define F_TIMETZ_PART TIMEZPARTFUNCOID +#define F_TIME_PART TIMEPARTFUNCOID +#define F_TIMESTAMP_PART TIMESTAMPPARTFUNCOID +#define F_DATE_PL_INTERVAL 2071 +#define F_DATE_PLI 1141 +#define F_DATE_RECV 2468 +#define F_DATE_SEND 2469 +#define F_DATE_SMALLER 1139 +#define F_DATE_SORTSUPPORT 3136 +#define F_DATE_TEXT 4159 +#define F_TIMESTAMPTZ_TRUNC TIMESTAMPTZTRUNCFUNCOID +#define F_INTERVAL_TRUNC INTERVALTRUNCFUNCOID +#define F_TIMESTAMP_TRUNC TIMESTAMPTRUNCFUNCOID +#define F_DATE_VARCHAR 4161 +#define F_RANGE_CONSTRUCTOR2 3941 +#define F_RANGE_CONSTRUCTOR3 3942 +#define F_DATERANGE_CANONICAL 3915 +#define F_DATERANGE_SUBDIFF 3925 +#define F_DATETIME_TIMESTAMP 1272 +#define F_DATETIMETZ_TIMESTAMPTZ 1297 +#define F_BINARY_DECODE 1947 +#define F_PSEUDO_CURRENT_USER 3216 +#define F_DEGREES 1608 +#define F_WINDOW_DELTA 4805 +#define F_WINDOW_DENSE_RANK DENSERANKFUNCOID +#define F_DEXP 233 +#define F_BOX_DIAGONAL 981 +#define F_CIRCLE_DIAMETER 1469 +#define F_DISABLE_CONN 4221 +#define F_DISPELL_INIT 3731 +#define F_DISPELL_LEXIZE 3732 +#define F_DIST_CPOLY 728 +#define F_DIST_LB 726 +#define F_DIST_PB 364 +#define F_DIST_PC 1476 +#define F_DIST_PL 725 +#define F_DIST_PPATH 371 +#define F_DIST_PS 363 +#define F_DIST_SB 365 +#define F_DIST_SL 727 +#define F_NUMERIC_DIV_TRUNC 1973 +#define F_DLOG1 234 +#define F_DLOG10 1339 +#define F_DOMAIN_IN 2597 +#define F_DOMAIN_RECV 2598 +#define F_DPOW 232 +#define F_DROUND 228 +#define F_DSIMPLE_INIT 3725 +#define F_DSIMPLE_LEXIZE 3726 +#define F_DSQRT 230 +#define F_DSYNONYM_INIT 3728 +#define F_DSYNONYM_LEXIZE 3729 +#define F_DTRUNC 229 +#define F_ELEM_CONTAINED_BY_RANGE 3860 +#define F_GET_EMPTY_BLOB 3814 +#define F_BINARY_ENCODE 1946 +#define F_ENCODE_PLAN_NODE 3467 +#define F_ENUM_CMP 3514 +#define F_ENUM_EQ 3508 +#define F_ENUM_FIRST 3528 +#define F_ENUM_GE 3513 +#define F_ENUM_GT 3511 +#define F_ENUM_IN 3506 +#define F_ENUM_LARGER 3525 +#define F_ENUM_LAST 3529 +#define F_ENUM_LE 3512 +#define F_ENUM_LT 3510 +#define F_ENUM_NE 3509 +#define F_ENUM_OUT 3507 +#define F_ENUM_RANGE_BOUNDS 3530 +#define F_ENUM_RANGE_ALL 3531 +#define F_ENUM_RECV 3532 +#define F_ENUM_SEND 3533 +#define F_ENUM_SMALLER 3524 +#define F_EQJOINSEL 105 +#define F_EQSEL EQSELRETURNOID +#define F_EXEC_HADOOP_SQL ECHADOOPFUNCOID +#define F_EXEC_ON_EXTENSION ECEXTENSIONFUNCOID +#define F_NUMERIC_EXP 1732 +#define F_F4TOI1 5530 +#define F_F8TOI1 5532 +#define F_NUMERIC_FAC 1376 +#define F_NETWORK_FAMILY 711 +#define F_FDW_HANDLER_IN 3116 +#define F_FDW_HANDLER_OUT 3117 +#define F_FENCED_UDF_PROCESS 4207 +#define F_WINDOW_FIRST_VALUE 3112 +#define F_I2TOF 236 +#define F_DTOF 312 +#define F_I4TOF 318 +#define F_I8TOF 652 +#define F_NUMERIC_FLOAT4 1745 +#define F_FLOAT48DIV 280 +#define F_FLOAT48EQ 299 +#define F_FLOAT48GE 304 +#define F_FLOAT48GT 303 +#define F_FLOAT48LE 302 +#define F_FLOAT48LT 301 +#define F_FLOAT48MI 282 +#define F_FLOAT48MUL 279 +#define F_FLOAT48NE 300 +#define F_FLOAT48PL 281 +#define F_FLOAT4_ACCUM 208 +#define F_FLOAT4_BPCHAR 4070 +#define F_FLOAT4_LIST_AGG_NOARG2_TRANSFN 3569 +#define F_FLOAT4_LIST_AGG_TRANSFN 3567 +#define F_FLOAT4_TEXT 4169 +#define F_FLOAT4_VARCHAR 4184 +#define F_FLOAT4DIV 203 +#define F_FLOAT4EQ 287 +#define F_FLOAT4GE 292 +#define F_FLOAT4GT 291 +#define F_FLOAT4IN 200 +#define F_FLOAT4LARGER 209 +#define F_FLOAT4LE 290 +#define F_FLOAT4LT 289 +#define F_FLOAT4MI 205 +#define F_FLOAT4MUL 202 +#define F_FLOAT4NE 288 +#define F_FLOAT4OUT 201 +#define F_FLOAT4PL 204 +#define F_FLOAT4RECV 2424 +#define F_FLOAT4SEND 2425 +#define F_FLOAT4SMALLER 211 +#define F_FLOAT4UM 206 +#define F_FLOAT4UP 1913 +#define F_I2TOD 235 +#define F_FTOD 311 +#define F_I4TOD INT4TOFLOAT8FUNCOID +#define F_I8TOD 482 +#define F_NUMERIC_FLOAT8 NUMTOFLOAT8FUNCOID +#define F_FLOAT84DIV 284 +#define F_FLOAT84EQ 305 +#define F_FLOAT84GE 310 +#define F_FLOAT84GT 309 +#define F_FLOAT84LE 308 +#define F_FLOAT84LT 307 +#define F_FLOAT84MI 286 +#define F_FLOAT84MUL 283 +#define F_FLOAT84NE 306 +#define F_FLOAT84PL 285 +#define F_FLOAT8_ACCUM 222 +#define F_FLOAT8_AVG 1830 +#define F_FLOAT8_BPCHAR 4071 +#define F_FLOAT8_COLLECT 2966 +#define F_FLOAT8_CORR 2817 +#define F_FLOAT8_COVAR_POP 2815 +#define F_FLOAT8_COVAR_SAMP 2816 +#define F_FLOAT8_INTERVAL 4229 +#define F_FLOAT8_LIST_AGG_NOARG2_TRANSFN 3573 +#define F_FLOAT8_LIST_AGG_TRANSFN 3571 +#define F_FLOAT8_REGR_ACCUM 2806 +#define F_FLOAT8_REGR_AVGX 2810 +#define F_FLOAT8_REGR_AVGY 2811 +#define F_FLOAT8_REGR_COLLECT 2995 +#define F_FLOAT8_REGR_INTERCEPT 2814 +#define F_FLOAT8_REGR_R2 2812 +#define F_FLOAT8_REGR_SLOPE 2813 +#define F_FLOAT8_REGR_SXX 2807 +#define F_FLOAT8_REGR_SXY 2809 +#define F_FLOAT8_REGR_SYY 2808 +#define F_FLOAT8_STDDEV_POP 2513 +#define F_FLOAT8_STDDEV_SAMP 1832 +#define F_FLOAT8_TEXT 4170 +#define F_FLOAT8_VAR_POP 2512 +#define F_FLOAT8_VAR_SAMP 1831 +#define F_FLOAT8_VARCHAR 4185 +#define F_FLOAT8DIV 217 +#define F_FLOAT8EQ 293 +#define F_FLOAT8GE 298 +#define F_FLOAT8GT 297 +#define F_FLOAT8IN 214 +#define F_FLOAT8LARGER 223 +#define F_FLOAT8LE 296 +#define F_FLOAT8LT 295 +#define F_FLOAT8MI 219 +#define F_FLOAT8MUL 216 +#define F_FLOAT8NE 294 +#define F_FLOAT8OUT 215 +#define F_FLOAT8PL 218 +#define F_FLOAT8RECV 2426 +#define F_FLOAT8SEND 2427 +#define F_FLOAT8SMALLER 224 +#define F_FLOAT8UM 220 +#define F_FLOAT8UP 1914 +#define F_NUMERIC_FLOOR 1712 +#define F_DFLOOR 2309 +#define F_FLT4_MUL_CASH 848 +#define F_FLT8_MUL_CASH 919 +#define F_FMGR_C_VALIDATOR 2247 +#define F_FMGR_INTERNAL_VALIDATOR 2246 +#define F_FMGR_SQL_VALIDATOR 2248 +#define F_TEXT_FORMAT ANYTOTEXTFORMATFUNCOID +#define F_TEXT_FORMAT_NV DEFAULTFORMATFUNCOID +#define F_FORMAT_TYPE 1081 +#define F_GENERATE_SERIES_TIMESTAMP 938 +#define F_GENERATE_SERIES_TIMESTAMPTZ GENERATESERIESFUNCOID +#define F_GENERATE_SERIES_STEP_INT4 1066 +#define F_GENERATE_SERIES_INT4 1067 +#define F_GENERATE_SERIES_STEP_INT8 1068 +#define F_GENERATE_SERIES_INT8 1069 +#define F_GENERATE_SERIES_STEP_NUMERIC 1070 +#define F_GENERATE_SERIES_NUMERIC 1071 +#define F_GENERATE_SUBSCRIPTS 1191 +#define F_GENERATE_SUBSCRIPTS_NODIR 1192 +#define F_GENERATE_WDR_REPORT 5703 +#define F_BYTEAGETBIT 723 +#define F_BITGETBIT 3032 +#define F_BYTEAGETBYTE 721 +#define F_GET_CURRENT_TS_CONFIG 3759 +#define F_GET_DB_SOURCE_DATASIZE 4208 +#define F_GET_GTM_LITE_STATUS 5999 +#define F_GET_HOSTNAME 3977 +#define F_GET_INSTR_RT_PERCENTILE 5712 +#define F_GET_INSTR_UNIQUE_SQL 5702 +#define F_GET_INSTR_USER_LOGIN 5706 +#define F_GET_INSTR_WAIT_EVENT 5705 +#define F_GET_INSTR_WORKLOAD_INFO 5000 +#define F_GET_LOCAL_ACTIVE_SESSION 5721 +#define F_GET_LOCAL_PREPARED_XACT 3332 +#define F_GET_LOCAL_REL_IOSTAT 5708 +#define F_GET_NODE_STAT_RESET_TIME 5720 +#define F_PG_GET_NODENAME 5015 +#define F_GET_PREPARED_PENDING_XID 3199 +#define F_GET_REMOTE_PREPARED_XACTS 3333 +#define F_GET_SCHEMA_OID 3953 +#define F_GET_WAIT_EVENT_INFO 5723 +#define F_GETBUCKET 4046 +#define F_GETDATABASEENCODING 1039 +#define F_GETDISTRIBUTEKEY 4047 +#define F_GIN_CLEAN_PENDING_LIST 3989 +#define F_GIN_CMP_PREFIX 2700 +#define F_GIN_CMP_TSLEXEME 3724 +#define F_GIN_EXTRACT_TSQUERY_5ARGS 3087 +#define F_GIN_EXTRACT_TSQUERY 3657 +#define F_GIN_EXTRACT_TSVECTOR_2ARGS 3077 +#define F_GIN_EXTRACT_TSVECTOR 3656 +#define F_GIN_TSQUERY_CONSISTENT_6ARGS 3088 +#define F_GIN_TSQUERY_CONSISTENT 3658 +#define F_GIN_TSQUERY_TRICONSISTENT 3921 +#define F_GINARRAYCONSISTENT 2744 +#define F_GINARRAYEXTRACT 2743 +#define F_GINARRAYEXTRACT_2ARGS 3076 +#define F_GINARRAYTRICONSISTENT 3920 +#define F_GINBEGINSCAN 2733 +#define F_GINBUILD 2738 +#define F_GINBUILDEMPTY 325 +#define F_GINBULKDELETE 2739 +#define F_GINCOSTESTIMATE 2741 +#define F_GINENDSCAN 2735 +#define F_GINGETBITMAP 2731 +#define F_GININSERT 2732 +#define F_GINMARKPOS 2736 +#define F_GINMERGE 3186 +#define F_GINOPTIONS 2788 +#define F_GINQUERYARRAYEXTRACT 2774 +#define F_GINRESCAN 2734 +#define F_GINRESTRPOS 2737 +#define F_GINVACUUMCLEANUP 2740 +#define F_GIST_BOX_COMPRESS 2579 +#define F_GIST_BOX_CONSISTENT 2578 +#define F_GIST_BOX_DECOMPRESS 2580 +#define F_GIST_BOX_PENALTY 2581 +#define F_GIST_BOX_PICKSPLIT 2582 +#define F_GIST_BOX_SAME 2584 +#define F_GIST_BOX_UNION 2583 +#define F_GIST_CIRCLE_COMPRESS 2592 +#define F_GIST_CIRCLE_CONSISTENT 2591 +#define F_GIST_POINT_COMPRESS 1030 +#define F_GIST_POINT_CONSISTENT 2179 +#define F_GIST_POINT_DISTANCE 3064 +#define F_GIST_POLY_COMPRESS 2586 +#define F_GIST_POLY_CONSISTENT 2585 +#define F_GISTBEGINSCAN 777 +#define F_GISTBUILD 782 +#define F_GISTBUILDEMPTY 326 +#define F_GISTBULKDELETE 776 +#define F_GISTCOSTESTIMATE 772 +#define F_GISTENDSCAN 779 +#define F_GISTGETBITMAP 638 +#define F_GISTGETTUPLE 774 +#define F_GISTINSERT 775 +#define F_GISTMARKPOS 780 +#define F_GISTMERGE 3187 +#define F_GISTOPTIONS 2787 +#define F_GISTRESCAN 778 +#define F_GISTRESTRPOS 781 +#define F_GISTVACUUMCLEANUP 2561 +#define F_GLOBAL_CLEAN_PREPARED_XACTS 3334 +#define F_GLOBAL_COMM_GET_CLIENT_INFO 1992 +#define F_GLOBAL_COMM_GET_RECV_STREAM 1988 +#define F_GLOBAL_COMM_GET_SEND_STREAM 1989 +#define F_GLOBAL_COMM_GET_STATUS 1990 +#define F_GLOBAL_STAT_CLEAN_HOTKEYS 3900 +#define F_GLOBAL_STAT_GET_HOTKEYS_INFO 3903 +#define F_GS_ALL_CONTROL_GROUP_INFO 4502 +#define F_GS_ALL_NODEGROUP_CONTROL_GROUP_INFO 4504 +#define F_GS_CGROUP_MAP_NG_CONF 4503 +#define F_GS_CONTROL_GROUP_INFO 4500 +#define F_GS_DECRYPT_AES128 3465 +#define F_GS_ENCRYPT_AES128 GSENCRYPTAES128FUNCOID +#define F_GS_EXTEND_LIBRARY 4210 +#define F_GS_FAULT_INJECT 4000 +#define F_GS_GET_GLOBAL_BARRIER_STATUS 9032 +#define F_GS_GET_LOCAL_BARRIER_STATUS 9033 +#define F_GS_GET_NEXT_XID_CSN 6224 +#define F_GS_GET_NODEGROUP_TABLECOUNT 5027 +#define F_GS_INDEX_ADVISE 4888 +#define F_GS_PASSWORD_DEADLINE 3469 +#define F_GS_PASSWORD_NOTIFYTIME 3470 +#define F_GS_RESPOOL_EXCEPTION_INFO 4501 +#define F_GS_ROACH_DISABLE_DELAY_DDL_RECYCLE 2202 +#define F_GS_ROACH_ENABLE_DELAY_DDL_RECYCLE 2201 +#define F_GS_ROACH_STOP_BACKUP 2200 +#define F_GS_ROACH_SWITCH_XLOG 2203 +#define F_GS_SET_OBS_DELETE_LOCATION 9031 +#define F_GS_STAT_ACTIVITY_TIMEOUT 4520 +#define F_GS_STAT_CLEAN_HOTKEYS 3805 +#define F_GS_STAT_GET_HOTKEYS_INFO 3803 +#define F_GS_STAT_GET_WLM_PLAN_OPERATOR_INFO 5033 +#define F_PG_SWITCH_RELFILENODE_NAME 4049 +#define F_GS_TOTAL_NODEGROUP_MEMORY_DETAIL 2847 +#define F_PG_STAT_GET_RESOURCE_POOL_INFO 5004 +#define F_PG_WLM_GET_SESSION_INFO 5009 +#define F_PG_STAT_GET_WLM_USER_INFO 5007 +#define F_PG_WLM_GET_USER_SESSION_INFO 5020 +#define F_PG_STAT_GET_WORKLOAD_RECORDS 5018 +#define F_GS_WLM_NODE_CLEAN 5016 +#define F_GS_WLM_NODE_RECOVER 5017 +#define F_GS_WLM_READJUST_USER_SPACE 5011 +#define F_GS_WLM_READJUST_USER_SPACE_THROUGH_USERNAME 5030 +#define F_GS_WLM_READJUST_USER_SPACE_WITH_RESET_FLAG 5029 +#define F_GS_WLM_REBUILD_USER_RESOURCE_POOL 5006 +#define F_PG_STAT_GET_SESSION_RESPOOL 5021 +#define F_GS_WLM_SWITCH_CGROUP 5005 +#define F_PG_STAT_GET_WLM_USER_RESOURCE_INFO 5012 +#define F_GTSQUERY_COMPRESS 3695 +#define F_GTSQUERY_CONSISTENT 3701 +#define F_GTSQUERY_DECOMPRESS 3696 +#define F_GTSQUERY_PENALTY 3700 +#define F_GTSQUERY_PICKSPLIT 3697 +#define F_GTSQUERY_SAME 3699 +#define F_GTSQUERY_UNION 3698 +#define F_GTSVECTOR_COMPRESS 3648 +#define F_GTSVECTOR_CONSISTENT 3654 +#define F_GTSVECTOR_DECOMPRESS 3649 +#define F_GTSVECTOR_PENALTY 3653 +#define F_GTSVECTOR_PICKSPLIT 3650 +#define F_GTSVECTOR_SAME 3652 +#define F_GTSVECTOR_UNION 3651 +#define F_GTSVECTORIN 3646 +#define F_GTSVECTOROUT 3647 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME_NAME 3024 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME_ID 3025 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID_NAME 3026 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID_ID 3027 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME 3028 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID 3029 +#define F_HAS_CEK_PRIVILEGE_NAME_NAME 9130 +#define F_HAS_CEK_PRIVILEGE_NAME_ID 9131 +#define F_HAS_CEK_PRIVILEGE_ID_NAME 9132 +#define F_HAS_CEK_PRIVILEGE_ID_ID 9133 +#define F_HAS_CEK_PRIVILEGE_NAME 9134 +#define F_HAS_CEK_PRIVILEGE_ID 9135 +#define F_HAS_CMK_PRIVILEGE_NAME_NAME 9024 +#define F_HAS_CMK_PRIVILEGE_NAME_ID 9025 +#define F_HAS_CMK_PRIVILEGE_ID_NAME 9026 +#define F_HAS_CMK_PRIVILEGE_ID_ID 9027 +#define F_HAS_CMK_PRIVILEGE_NAME 9028 +#define F_HAS_CMK_PRIVILEGE_ID 9029 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME_NAME 3012 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME_ATTNUM 3013 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ID_NAME 3014 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ID_ATTNUM 3015 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME_NAME 3016 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME_ATTNUM 3017 +#define F_HAS_COLUMN_PRIVILEGE_ID_ID_NAME 3018 +#define F_HAS_COLUMN_PRIVILEGE_ID_ID_ATTNUM 3019 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME 3020 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ATTNUM 3021 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME 3022 +#define F_HAS_COLUMN_PRIVILEGE_ID_ATTNUM 3023 +#define F_HAS_DATABASE_PRIVILEGE_NAME_NAME 2250 +#define F_HAS_DATABASE_PRIVILEGE_NAME_ID 2251 +#define F_HAS_DATABASE_PRIVILEGE_ID_NAME 2252 +#define F_HAS_DATABASE_PRIVILEGE_ID_ID 2253 +#define F_HAS_DATABASE_PRIVILEGE_NAME 2254 +#define F_HAS_DATABASE_PRIVILEGE_ID 2255 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME_NAME 4700 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME_ID 4701 +#define F_HAS_DIRECTORY_PRIVILEGE_ID_NAME 4702 +#define F_HAS_DIRECTORY_PRIVILEGE_ID_ID 4703 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME 4704 +#define F_HAS_DIRECTORY_PRIVILEGE_ID 4705 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME_NAME 3000 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME_ID 3001 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID_NAME 3002 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID_ID 3003 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME 3004 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID 3005 +#define F_HAS_FUNCTION_PRIVILEGE_NAME_NAME 2256 +#define F_HAS_FUNCTION_PRIVILEGE_NAME_ID 2257 +#define F_HAS_FUNCTION_PRIVILEGE_ID_NAME 2258 +#define F_HAS_FUNCTION_PRIVILEGE_ID_ID 2259 +#define F_HAS_FUNCTION_PRIVILEGE_NAME 2260 +#define F_HAS_FUNCTION_PRIVILEGE_ID 2261 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME_NAME 2262 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME_ID 2263 +#define F_HAS_LANGUAGE_PRIVILEGE_ID_NAME 2264 +#define F_HAS_LANGUAGE_PRIVILEGE_ID_ID 2265 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME 2266 +#define F_HAS_LANGUAGE_PRIVILEGE_ID 2267 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME_NAME 4201 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME_ID 4202 +#define F_HAS_NODEGROUP_PRIVILEGE_ID_NAME 4203 +#define F_HAS_NODEGROUP_PRIVILEGE_ID_ID 4204 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME 4205 +#define F_HAS_NODEGROUP_PRIVILEGE_ID 4206 +#define F_HAS_SCHEMA_PRIVILEGE_NAME_NAME 2268 +#define F_HAS_SCHEMA_PRIVILEGE_NAME_ID 2269 +#define F_HAS_SCHEMA_PRIVILEGE_ID_NAME 2270 +#define F_HAS_SCHEMA_PRIVILEGE_ID_ID 2271 +#define F_HAS_SCHEMA_PRIVILEGE_NAME 2272 +#define F_HAS_SCHEMA_PRIVILEGE_ID 2273 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME_NAME 2181 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME_ID 2182 +#define F_HAS_SEQUENCE_PRIVILEGE_ID_NAME 2183 +#define F_HAS_SEQUENCE_PRIVILEGE_ID_ID 2184 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME 2185 +#define F_HAS_SEQUENCE_PRIVILEGE_ID 2186 +#define F_HAS_SERVER_PRIVILEGE_NAME_NAME 3006 +#define F_HAS_SERVER_PRIVILEGE_NAME_ID 3007 +#define F_HAS_SERVER_PRIVILEGE_ID_NAME 3008 +#define F_HAS_SERVER_PRIVILEGE_ID_ID 3009 +#define F_HAS_SERVER_PRIVILEGE_NAME 3010 +#define F_HAS_SERVER_PRIVILEGE_ID 3011 +#define F_HAS_TABLE_PRIVILEGE_NAME_NAME 1922 +#define F_HAS_TABLE_PRIVILEGE_NAME_ID 1923 +#define F_HAS_TABLE_PRIVILEGE_ID_NAME 1924 +#define F_HAS_TABLE_PRIVILEGE_ID_ID 1925 +#define F_HAS_TABLE_PRIVILEGE_NAME 1926 +#define F_HAS_TABLE_PRIVILEGE_ID 1927 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME_NAME 2390 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME_ID 2391 +#define F_HAS_TABLESPACE_PRIVILEGE_ID_NAME 2392 +#define F_HAS_TABLESPACE_PRIVILEGE_ID_ID 2393 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME 2394 +#define F_HAS_TABLESPACE_PRIVILEGE_ID 2395 +#define F_HAS_TYPE_PRIVILEGE_NAME_NAME 3138 +#define F_HAS_TYPE_PRIVILEGE_NAME_ID 3139 +#define F_HAS_TYPE_PRIVILEGE_ID_NAME 3140 +#define F_HAS_TYPE_PRIVILEGE_ID_ID 3141 +#define F_HAS_TYPE_PRIVILEGE_NAME 3142 +#define F_HAS_TYPE_PRIVILEGE_ID 3143 +#define F_HASH_ACLITEM 329 +#define F_HASH_ARRAY 626 +#define F_HASH_NUMERIC 432 +#define F_HASH_RANGE 3902 +#define F_HASHBEGINSCAN 443 +#define F_HASHBPCHAR HASHBPCHAROID +#define F_HASHBUILD 448 +#define F_HASHBUILDEMPTY 327 +#define F_HASHBULKDELETE 442 +#define F_HASHCHAR 454 +#define F_HASHCOSTESTIMATE 438 +#define F_HASHENDSCAN 445 +#define F_HASHENUM 3515 +#define F_HASHFLOAT4 451 +#define F_HASHFLOAT8 452 +#define F_HASHGETBITMAP 637 +#define F_HASHGETTUPLE 440 +#define F_HASHINET 422 +#define F_HASHINSERT 441 +#define F_HASHINT1 5520 +#define F_HASHINT2 449 +#define F_HASHINT2VECTOR 398 +#define F_HASHINT4 HASHINT4OID +#define F_HASHINT8 HASHINT8OID +#define F_HASHMACADDR 399 +#define F_HASHMARKPOS 446 +#define F_HASHMERGE 3185 +#define F_HASHNAME 455 +#define F_HASHOID 453 +#define F_HASHOIDVECTOR 457 +#define F_HASHOPTIONS 2786 +#define F_HASHRESCAN 444 +#define F_HASHRESTRPOS 447 +#define F_HASHTEXT HASHTEXTOID +#define F_HASHVACUUMCLEANUP 425 +#define F_HASHVARLENA 456 +#define F_BOX_HEIGHT 977 +#define F_TEXTTORAW 4038 +#define F_HLL 4311 +#define F_HLL_ADD 4322 +#define F_HLL_ADD_REV 4323 +#define F_HLL_ADD_TRANS0 4351 +#define F_HLL_ADD_TRANS1 4336 +#define F_HLL_ADD_TRANS2 4337 +#define F_HLL_ADD_TRANS3 4338 +#define F_HLL_ADD_TRANS4 4360 +#define F_HLL_CARDINALITY 4320 +#define F_HLL_EMPTY0 4325 +#define F_HLL_EMPTY1 4326 +#define F_HLL_EMPTY2 4327 +#define F_HLL_EMPTY3 4328 +#define F_HLL_EMPTY4 4329 +#define F_HLL_EQ 4318 +#define F_HLL_EXPTHRESH 4334 +#define F_HLL_HASH_ANY 4345 +#define F_HLL_HASH_ANYS 4359 +#define F_HLL_HASH_8BYTE 4342 +#define F_HLL_HASH_8BYTES 4356 +#define F_HLL_HASH_1BYTE 4339 +#define F_HLL_HASH_1BYTES 4353 +#define F_HLL_HASH_VARLENA 4343 +#define F_HLL_HASH_VARLENAS 4357 +#define F_HLL_HASH_4BYTE 4341 +#define F_HLL_HASH_4BYTES 4355 +#define F_HLL_HASH_2BYTE 4340 +#define F_HLL_HASH_2BYTES 4354 +#define F_HLL_HASHVAL 4316 +#define F_HLL_HASHVAL_EQ 4314 +#define F_HLL_HASHVAL_IN 4312 +#define F_HLL_HASHVAL_INT4 4317 +#define F_HLL_HASHVAL_NE 4315 +#define F_HLL_HASHVAL_OUT 4313 +#define F_HLL_IN 4305 +#define F_HLL_LOG2M 4332 +#define F_HLL_NE 4319 +#define F_HLL_OUT 4306 +#define F_HLL_PACK 4352 +#define F_HLL_PRINT 4324 +#define F_HLL_RECV 4307 +#define F_HLL_REGWIDTH 4333 +#define F_HLL_SCHEMA_VERSION 4330 +#define F_HLL_SEND 4308 +#define F_HLL_SPARSEON 4335 +#define F_HLL_TRANS_IN 4364 +#define F_HLL_TRANS_OUT 4365 +#define F_HLL_TRANS_RECV 4362 +#define F_HLL_TRANS_SEND 4363 +#define F_HLL_TYPE 4331 +#define F_HLL_TYPMOD_IN 4309 +#define F_HLL_TYPMOD_OUT 4310 +#define F_HLL_UNION 4321 +#define F_HLL_UNION_COLLECT 4348 +#define F_HLL_UNION_TRANS 4346 +#define F_NETWORK_HOST 699 +#define F_NETWORK_HOSTMASK 1362 +#define F_HYPOPG_CREATE_INDEX 4889 +#define F_HYPOPG_DISPLAY_INDEX 4890 +#define F_HYPOPG_DROP_INDEX 4891 +#define F_HYPOPG_ESTIMATE_SIZE 4892 +#define F_HYPOPG_RESET_INDEX 4893 +#define F_I1TOF4 5529 +#define F_I1TOF8 5531 +#define F_I1TOI2 5523 +#define F_I1TOI4 5525 +#define F_I1TOI8 5527 +#define F_I2TOI1 5524 +#define F_I4TOI1 5526 +#define F_I8TOI1 5528 +#define F_ICLIKEJOINSEL 1816 +#define F_ICLIKESEL 1814 +#define F_ICNLIKEJOINSEL 1817 +#define F_ICNLIKESEL 1815 +#define F_ICREGEXEQJOINSEL 1826 +#define F_ICREGEXEQSEL 1820 +#define F_ICREGEXNEJOINSEL 1829 +#define F_ICREGEXNESEL 1823 +#define F_INET_CLIENT_ADDR 2196 +#define F_INET_CLIENT_PORT 2197 +#define F_INET_IN 910 +#define F_INET_OUT 911 +#define F_INET_RECV 2496 +#define F_INET_SEND 2497 +#define F_INET_SERVER_ADDR 2198 +#define F_INET_SERVER_PORT 2199 +#define F_INETAND 2628 +#define F_INETMI 2633 +#define F_INETMI_INT8 2632 +#define F_INETNOT 2627 +#define F_INETOR 2629 +#define F_INETPL 2630 +#define F_INITCAP 872 +#define F_TEXTPOS INSTR2FUNCOID +#define F_INSTR_3ARGS INSTR3FUNCOID +#define F_INSTR_4ARGS INSTR4FUNCOID +#define F_INT1_AVG_ACCUM 5548 +#define F_INT1_BOOL 5533 +#define F_INT1_BPCHAR 4067 +#define F_INT1_MUL_CASH 3348 +#define F_INT1_NUMERIC 5521 +#define F_INT1_NVARCHAR2 4066 +#define F_INT1_TEXT 4165 +#define F_INT1_VARCHAR 4065 +#define F_INT1ABS 6113 +#define F_INT1AND 6101 +#define F_INT1CMP 5519 +#define F_INT1DIV 6112 +#define F_INT1EQ 5547 +#define F_INT1GE 5512 +#define F_INT1GT 5511 +#define F_INT1IN 5541 +#define F_INT1INC 6117 +#define F_INT1LARGER 6115 +#define F_INT1LE 5510 +#define F_INT1LT 5509 +#define F_INT1MI 6110 +#define F_INT1MOD 6114 +#define F_INT1MUL 6111 +#define F_INT1NE 5508 +#define F_INT1NOT 6104 +#define F_INT1OR 6102 +#define F_INT1OUT 5542 +#define F_INT1PL 6109 +#define F_INT1RECV 5543 +#define F_INT1SEND 5544 +#define F_INT1SHL 6105 +#define F_INT1SHR 6106 +#define F_INT1SMALLER 6116 +#define F_INT1UM 6108 +#define F_INT1UP 6107 +#define F_INT1XOR 6103 +#define F_DTOI2 237 +#define F_FTOI2 238 +#define F_I4TOI2 314 +#define F_INT82 714 +#define F_NUMERIC_INT2 1783 +#define F_INT24DIV 172 +#define F_INT24EQ 158 +#define F_INT24GE 168 +#define F_INT24GT 162 +#define F_INT24LE 166 +#define F_INT24LT 160 +#define F_INT24MI 182 +#define F_INT24MUL 170 +#define F_INT24NE 164 +#define F_INT24PL 178 +#define F_INT28DIV 948 +#define F_INT28EQ 1850 +#define F_INT28GE 1855 +#define F_INT28GT 1853 +#define F_INT28LE 1854 +#define F_INT28LT 1852 +#define F_INT28MI 942 +#define F_INT28MUL 943 +#define F_INT28NE 1851 +#define F_INT28PL 841 +#define F_INT2_ACCUM 1834 +#define F_INT2_AVG_ACCUM 1962 +#define F_INT2_BOOL 3180 +#define F_INT2_BPCHAR 4068 +#define F_INT2_LIST_AGG_NOARG2_TRANSFN 3557 +#define F_INT2_LIST_AGG_TRANSFN 3555 +#define F_INT2_MUL_CASH 863 +#define F_INT2_SUM 1840 +#define F_INT2_TEXT 4166 +#define F_INT2_VARCHAR 4180 +#define F_INT2AND 1892 +#define F_INT2DIV 153 +#define F_INT2EQ 63 +#define F_INT2GE 151 +#define F_INT2GT 146 +#define F_INT2IN 38 +#define F_INT2LARGER 770 +#define F_INT2LE 148 +#define F_INT2LT 64 +#define F_INT2MI 180 +#define F_INT2MOD 155 +#define F_INT2MUL 152 +#define F_INT2NE 145 +#define F_INT2NOT 1895 +#define F_INT2OR 1893 +#define F_INT2OUT 39 +#define F_INT2PL 176 +#define F_INT2RECV 2404 +#define F_INT2SEND 2405 +#define F_INT2SHL 1896 +#define F_INT2SHR 1897 +#define F_INT2SMALLER 771 +#define F_INT2UM 213 +#define F_INT2UP 1911 +#define F_INT2VECTOREQ 315 +#define F_INT2VECTORIN 40 +#define F_INT2VECTOROUT 41 +#define F_INT2VECTORRECV 2410 +#define F_INT2VECTORSEND 2411 +#define F_INT2XOR 1894 +#define F_CHARTOI4 77 +#define F_I2TOI4 313 +#define F_DTOI4 317 +#define F_FTOI4 319 +#define F_INT84 480 +#define F_BITTOINT4 1684 +#define F_NUMERIC_INT4 1744 +#define F_BOOL_INT4 2558 +#define F_INT42DIV 173 +#define F_INT42EQ 159 +#define F_INT42GE 169 +#define F_INT42GT 163 +#define F_INT42LE 167 +#define F_INT42LT 161 +#define F_INT42MI 183 +#define F_INT42MUL 171 +#define F_INT42NE 165 +#define F_INT42PL 179 +#define F_INT48DIV 1281 +#define F_INT48EQ 852 +#define F_INT48GE 857 +#define F_INT48GT 855 +#define F_INT48LE 856 +#define F_INT48LT 854 +#define F_INT48MI 1279 +#define F_INT48MUL 1280 +#define F_INT48NE 853 +#define F_INT48PL 1278 +#define F_INT4_ACCUM 1835 +#define F_INT4_AVG_ACCUM 1963 +#define F_INT4_BPCHAR 3192 +#define F_INT4_LIST_AGG_NOARG2_TRANSFN 3561 +#define F_INT4_LIST_AGG_TRANSFN 3559 +#define F_INT4_MUL_CASH 862 +#define F_INT4_SUM 1841 +#define F_INT4_TEXT 4167 +#define F_INT4_VARCHAR 4181 +#define F_INT4AND 1898 +#define F_INT4DIV 154 +#define F_INT4EQ 65 +#define F_INT4GE 150 +#define F_INT4GT 147 +#define F_INT4IN 42 +#define F_INT4INC 766 +#define F_INT4LARGER 768 +#define F_INT4LE 149 +#define F_INT4LT 66 +#define F_INT4MI 181 +#define F_INT4MOD 156 +#define F_INT4MUL 141 +#define F_INT4NE 144 +#define F_INT4NOT 1901 +#define F_INT4OR 1899 +#define F_INT4OUT 43 +#define F_INT4PL 177 +#define F_INT4RANGE_CANONICAL 3914 +#define F_INT4RANGE_SUBDIFF 3922 +#define F_INT4RECV 2406 +#define F_INT4SEND 2407 +#define F_INT4SHL 1902 +#define F_INT4SHR 1903 +#define F_INT4SMALLER 769 +#define F_INT4UM 212 +#define F_INT4UP 1912 +#define F_INT4XOR 1900 +#define F_INT48 481 +#define F_DTOI8 483 +#define F_FTOI8 653 +#define F_INT28 754 +#define F_OIDTOI8 1288 +#define F_NUMERIC_INT8 1779 +#define F_BITTOINT8 2076 +#define F_INT82DIV 840 +#define F_INT82EQ 1856 +#define F_INT82GE 1861 +#define F_INT82GT 1859 +#define F_INT82LE 1860 +#define F_INT82LT 1858 +#define F_INT82MI 838 +#define F_INT82MUL 839 +#define F_INT82NE 1857 +#define F_INT82PL 837 +#define F_INT84DIV 1277 +#define F_INT84EQ 474 +#define F_INT84GE 479 +#define F_INT84GT 477 +#define F_INT84LE 478 +#define F_INT84LT 476 +#define F_INT84MI 1275 +#define F_INT84MUL 1276 +#define F_INT84NE 475 +#define F_INT84PL 1274 +#define F_INT8_ACCUM 1836 +#define F_INT8_AVG 1964 +#define F_INT8_AVG_ACCUM 2746 +#define F_INT8_AVG_COLLECT 2965 +#define F_INT8_BOOL 3177 +#define F_INT8_BPCHAR 4069 +#define F_INT8_LIST_AGG_NOARG2_TRANSFN 3565 +#define F_INT8_LIST_AGG_TRANSFN 3563 +#define F_INT8_MUL_CASH 3343 +#define F_INT8_SUM 1842 +#define F_INT8_SUM_TO_INT8 2996 +#define F_INT8_TEXT 4168 +#define F_INT8_VARCHAR 4182 +#define F_INT8AND 1904 +#define F_INT8DIV 466 +#define F_INT8EQ 467 +#define F_INT8GE 472 +#define F_INT8GT 470 +#define F_INT8IN 460 +#define F_INT8INC 1219 +#define F_INT8INC_ANY 2804 +#define F_INT8INC_FLOAT8_FLOAT8 2805 +#define F_INT8LARGER 1236 +#define F_INT8LE 471 +#define F_INT8LT 469 +#define F_INT8MI 464 +#define F_INT8MOD 945 +#define F_INT8MUL 465 +#define F_INT8NE 468 +#define F_INT8NOT 1907 +#define F_INT8OR 1905 +#define F_INT8OUT 461 +#define F_INT8PL 463 +#define F_INT8RANGE_CANONICAL 3928 +#define F_INT8RANGE_SUBDIFF 3923 +#define F_INT8RECV 2408 +#define F_INT8SEND 2409 +#define F_INT8SHL 1908 +#define F_INT8SHR 1909 +#define F_INT8SMALLER 1237 +#define F_INT8UM 462 +#define F_INT8UP 1910 +#define F_INT8XOR 1906 +#define F_INTER_LB 278 +#define F_INTER_SB 373 +#define F_INTER_SL 277 +#define F_INTERNAL_IN 2304 +#define F_INTERNAL_OUT 2305 +#define F_RELTIME_INTERVAL 1177 +#define F_INTERVAL_SCALE 1200 +#define F_TIME_INTERVAL 1370 +#define F_INTERVAL_ACCUM INTERVALACCUMFUNCOID +#define F_INTERVAL_AVG INTERVALAVGFUNCOID +#define F_INTERVAL_CMP 1315 +#define F_INTERVAL_COLLECT 2967 +#define F_INTERVAL_DIV 1326 +#define F_INTERVAL_EQ 1162 +#define F_INTERVAL_GE 1166 +#define F_INTERVAL_GT 1167 +#define F_INTERVAL_HASH 1697 +#define F_INTERVAL_IN INTERVALINFUNCOID +#define F_INTERVAL_LARGER 1198 +#define F_INTERVAL_LE 1165 +#define F_INTERVAL_LIST_AGG_NOARG2_TRANSFN 4507 +#define F_INTERVAL_LIST_AGG_TRANSFN 4505 +#define F_INTERVAL_LT 1164 +#define F_INTERVAL_MI 1170 +#define F_INTERVAL_MUL 1618 +#define F_INTERVAL_NE 1163 +#define F_INTERVAL_OUT 1161 +#define F_INTERVAL_PL 1169 +#define F_INTERVAL_RECV 2478 +#define F_INTERVAL_SEND 2479 +#define F_INTERVAL_SMALLER 1197 +#define F_INTERVAL_TRANSFORM 3918 +#define F_INTERVAL_UM 1168 +#define F_INTERVALTYPMODIN 2903 +#define F_INTERVALTYPMODOUT 2904 +#define F_INTINTERVAL 248 +#define F_PATH_ISCLOSED 1430 +#define F_RANGE_EMPTY 3850 +#define F_ABSTIME_FINITE 275 +#define F_DATE_FINITE 1373 +#define F_TIMESTAMP_FINITE 1389 +#define F_INTERVAL_FINITE 1390 +#define F_POINT_HORIZ 1407 +#define F_LSEG_HORIZONTAL 1411 +#define F_LINE_HORIZONTAL 1415 +#define F_PATH_ISOPEN 1431 +#define F_LSEG_PARALLEL 1408 +#define F_LINE_PARALLEL 1412 +#define F_LSEG_PERP 1409 +#define F_LINE_PERP 1413 +#define F_ISUBMIT_JOB_ON_NODES 5718 +#define F_ISUBMIT_JOB_ON_NODES_INTERNAL 6007 +#define F_POINT_VERT 1406 +#define F_LSEG_VERTICAL 1410 +#define F_LINE_VERTICAL 1414 +#define F_JOB_CANCEL 4800 +#define F_JOB_FINISH 4801 +#define F_JOB_SUBMIT 4802 +#define F_JOB_UPDATE 4803 +#define F_JSON_IN 321 +#define F_JSON_OUT 322 +#define F_JSON_RECV 323 +#define F_JSON_SEND 324 +#define F_INTERVAL_JUSTIFY_DAYS 1295 +#define F_INTERVAL_JUSTIFY_HOURS 1175 +#define F_INTERVAL_JUSTIFY_INTERVAL 2711 +#define F_KILL_SNAPSHOT 5714 +#define F_WINDOW_LAG 3106 +#define F_WINDOW_LAG_WITH_OFFSET 3107 +#define F_WINDOW_LAG_WITH_OFFSET_AND_DEFAULT 3108 +#define F_LANGUAGE_HANDLER_IN 2302 +#define F_LANGUAGE_HANDLER_OUT 2303 +#define F_LAST_DAY 4075 +#define F_WINDOW_LAST_VALUE 3113 +#define F_LASTVAL LASTVALFUNCOID +#define F_WINDOW_LEAD 3109 +#define F_WINDOW_LEAD_WITH_OFFSET 3110 +#define F_WINDOW_LEAD_WITH_OFFSET_AND_DEFAULT 3111 +#define F_TEXT_LEFT 3060 +#define F_LSEG_LENGTH 1530 +#define F_PATH_LENGTH 1531 +#define F_BITLENGTH 1681 +#define F_LENGTH_IN_ENCODING 1713 +#define F_BYTEAOCTETLEN 2010 +#define F_TSVECTOR_LENGTH 3711 +#define F_TEXTOCTETLEN TEXTOCTLENFUNCOID +#define F_BPCHARLENB BPOCTLENFUNCOID +#define F_NAMELIKE 1571 +#define F_LIKE_ESCAPE 1637 +#define F_LIKE_ESCAPE_BYTEA 2009 +#define F_LIKEJOINSEL 1825 +#define F_LIKESEL 1819 +#define F_LINE_CONSTRUCT_PP 1493 +#define F_LINE_DISTANCE 239 +#define F_LINE_EQ 1492 +#define F_LINE_IN 1490 +#define F_LINE_INTERPT 1494 +#define F_LINE_INTERSECT 1495 +#define F_LINE_OUT 1491 +#define F_LINE_RECV 2488 +#define F_LINE_SEND 2489 +#define F_LIST_AGG_FINALFN 3551 +#define F_LIST_AGG_NOARG2_TRANSFN 3553 +#define F_LIST_AGG_TRANSFN 3550 +#define F_NUMERIC_LN 1734 +#define F_LO_CLOSE 953 +#define F_LO_CREAT 957 +#define F_LO_CREATE 715 +#define F_LO_EXPORT 765 +#define F_LO_IMPORT 764 +#define F_LO_IMPORT_WITH_OID 767 +#define F_LO_LSEEK 956 +#define F_LO_OPEN 952 +#define F_LO_TELL 958 +#define F_LO_TRUNCATE 1004 +#define F_LO_UNLINK 964 +#define F_LOCAL_BGWRITER_STAT 4373 +#define F_LOCAL_CKPT_STAT 4371 +#define F_LOCAL_DOUBLE_WRITE_STAT 4384 +#define F_LOCAL_PAGEWRITER_STAT 4361 +#define F_LOCAL_RECOVERY_STATUS 3250 +#define F_LOCAL_REDO_STAT 4388 +#define F_LOCAL_RTO_STAT 3299 +#define F_LOCAL_SINGLE_FLUSH_DW_STAT 4375 +#define F_LOCKTAG_DECODE 5730 +#define F_NUMERIC_LOG 1736 +#define F_LOREAD 954 +#define F_LOWER 870 +#define F_RANGE_LOWER 3848 +#define F_RANGE_LOWER_INC 3851 +#define F_RANGE_LOWER_INF 3853 +#define F_LOWRITE 955 +#define F_LPAD LPADFUNCOID +#define F_LSEG_CONSTRUCT 993 +#define F_LSEG_CENTER 225 +#define F_LSEG_DISTANCE 361 +#define F_LSEG_EQ 999 +#define F_LSEG_GE 1486 +#define F_LSEG_GT 1485 +#define F_LSEG_IN 119 +#define F_LSEG_INTERPT 362 +#define F_LSEG_INTERSECT 994 +#define F_LSEG_LE 1484 +#define F_LSEG_LT 1483 +#define F_LSEG_NE 1482 +#define F_LSEG_OUT 120 +#define F_LSEG_RECV 2480 +#define F_LSEG_SEND 2481 +#define F_LTRIM LTRIMFUNCOID +#define F_LTRIM1 LTRIMPARAFUNCOID +#define F_MACADDR_AND 3145 +#define F_MACADDR_CMP 836 +#define F_MACADDR_EQ 830 +#define F_MACADDR_GE 834 +#define F_MACADDR_GT 833 +#define F_MACADDR_IN 436 +#define F_MACADDR_LE 832 +#define F_MACADDR_LT 831 +#define F_MACADDR_NE 835 +#define F_MACADDR_NOT 3144 +#define F_MACADDR_OR 3146 +#define F_MACADDR_OUT 437 +#define F_MACADDR_RECV 2494 +#define F_MACADDR_SEND 2495 +#define F_MAKEACLITEM 1365 +#define F_NETWORK_MASKLEN 697 +#define F_MD5_TEXT 2311 +#define F_MD5_BYTEA 2321 +#define F_MEDIAN_FLOAT8_FINALFN 5557 +#define F_MEDIAN_INTERVAL_FINALFN 5558 +#define F_MEDIAN_TRANSFN 5559 +#define F_MKTINTERVAL 676 +#define F_NUMERIC_MOD 1728 +#define F_MODE_FINAL 4462 +#define F_MODEL_TRAIN_OPT 3481 +#define F_INT4_CASH INTEGER2CASHFUNCOID +#define F_INT8_CASH BIGINT2CASHFUNCOID +#define F_NUMERIC_CASH NUMERIC2CASHFUNCOID +#define F_MOT_GLOBAL_MEMORY_DETAIL 6201 +#define F_MOT_LOCAL_MEMORY_DETAIL 6202 +#define F_MOT_SESSION_MEMORY_DETAIL 6200 +#define F_MUL_D_INTERVAL 1624 +#define F_TEXT_MULTIPLY_FLOAT8 3170 +#define F_FLOAT8_MULTIPLY_TEXT 3171 +#define F_TEXT_NAME 407 +#define F_BPCHAR_NAME 409 +#define F_NAMEEQ 62 +#define F_NAMEGE 658 +#define F_NAMEGT 657 +#define F_NAMEICLIKE 1635 +#define F_NAMEICNLIKE 1636 +#define F_NAMEICREGEXEQ 1240 +#define F_NAMEICREGEXNE 1241 +#define F_NAMEIN 34 +#define F_NAMELE 656 +#define F_NAMELT 655 +#define F_NAMENE 659 +#define F_NAMENLIKE 859 +#define F_NAMEOUT 35 +#define F_NAMERECV 2422 +#define F_NAMEREGEXEQ 79 +#define F_NAMEREGEXNE 1252 +#define F_NAMESEND 2423 +#define F_NEQJOINSEL 106 +#define F_NEQSEL NEQSELRETURNOID +#define F_NETWORK_NETMASK 696 +#define F_NETWORK_NETWORK 683 +#define F_NETWORK_CMP 926 +#define F_NETWORK_EQ 920 +#define F_NETWORK_GE 924 +#define F_NETWORK_GT 923 +#define F_NETWORK_LE 922 +#define F_NETWORK_LT 921 +#define F_NETWORK_NE 925 +#define F_NETWORK_SUB 927 +#define F_NETWORK_SUBEQ 928 +#define F_NETWORK_SUP 929 +#define F_NETWORK_SUPEQ 930 +#define F_NEXT_DAY_INT 4076 +#define F_NEXT_DAY_STR 4077 +#define F_NEXTVAL_OID NEXTVALFUNCOID +#define F_NGRAM_END 3788 +#define F_NGRAM_LEXTYPE 3789 +#define F_NGRAM_NEXTTOKEN 3787 +#define F_NGRAM_START 3786 +#define F_NLIKEJOINSEL 1828 +#define F_NLIKESEL 1822 +#define F_NODE_OID_NAME 3950 +#define F_NOW NOWFUNCOID +#define F_PATH_NPOINTS 1545 +#define F_POLY_NPOINTS 1556 +#define F_WINDOW_NTH_VALUE 3114 +#define F_WINDOW_NTILE 3105 +#define F_NUMERIC 1703 +#define F_INT4_NUMERIC 1740 +#define F_FLOAT4_NUMERIC 1742 +#define F_FLOAT8_NUMERIC 1743 +#define F_INT8_NUMERIC 1781 +#define F_INT2_NUMERIC 1782 +#define F_CASH_NUMERIC CASH2NUMERICFUNCOID +#define F_NUMERIC_ACCUM 1833 +#define F_NUMERIC_ADD 1724 +#define F_NUMERIC_AVG 1837 +#define F_NUMERIC_AVG_ACCUM 2858 +#define F_NUMERIC_AVG_COLLECT 2964 +#define F_NUMERIC_BPCHAR 4072 +#define F_NUMERIC_CMP 1769 +#define F_NUMERIC_COLLECT 2968 +#define F_NUMERIC_DIV 1727 +#define F_NUMERIC_EQ 1718 +#define F_NUMERIC_GE 1721 +#define F_NUMERIC_GT 1720 +#define F_NUMERIC_IN 1701 +#define F_NUMERIC_INC 1764 +#define F_NUMERIC_INT1 5522 +#define F_NUMERIC_LARGER 1767 +#define F_NUMERIC_LE 1723 +#define F_NUMERIC_LIST_AGG_NOARG2_TRANSFN 3577 +#define F_NUMERIC_LIST_AGG_TRANSFN 3575 +#define F_NUMERIC_LT 1722 +#define F_NUMERIC_MUL 1726 +#define F_NUMERIC_NE 1719 +#define F_NUMERIC_OUT 1702 +#define F_NUMERIC_POWER 1739 +#define F_NUMERIC_RECV 2460 +#define F_NUMERIC_SEND 2461 +#define F_NUMERIC_SMALLER 1766 +#define F_NUMERIC_SORTSUPPORT 3283 +#define F_NUMERIC_SQRT 1731 +#define F_NUMERIC_STDDEV_POP 2596 +#define F_NUMERIC_STDDEV_SAMP 1839 +#define F_NUMERIC_SUB 1725 +#define F_NUMERIC_TEXT 4171 +#define F_NUMERIC_TRANSFORM 3157 +#define F_NUMERIC_UMINUS 1771 +#define F_NUMERIC_UPLUS 1915 +#define F_NUMERIC_VAR_POP 2514 +#define F_NUMERIC_VAR_SAMP 1838 +#define F_NUMERIC_VARCHAR 4183 +#define F_NUMERICTYPMODIN 2917 +#define F_NUMERICTYPMODOUT 2918 +#define F_TSQUERY_NUMNODE 3672 +#define F_NUMRANGE_SUBDIFF 3924 +#define F_INT1_INTERVAL 3189 +#define F_INT2_INTERVAL 3190 +#define F_INT4_INTERVAL 3191 +#define F_NUMERIC_INTERVAL 3842 +#define F_NUMTODSINTERVAL 3172 +#define F_NVARCHAR2 3961 +#define F_NVARCHAR2IN 3962 +#define F_NVARCHAR2OUT 3963 +#define F_NVARCHAR2RECV 3966 +#define F_NVARCHAR2SEND 3967 +#define F_NVARCHAR2TYPMODIN 3964 +#define F_NVARCHAR2TYPMODOUT 3965 +#define F_BPCHAROCTETLEN 1375 +#define F_BITOCTETLENGTH 1682 +#define F_I8TOOID 1287 +#define F_OIDEQ 184 +#define F_OIDGE 1639 +#define F_OIDGT 1638 +#define F_OIDIN 1798 +#define F_OIDLARGER 1965 +#define F_OIDLE 717 +#define F_OIDLT 716 +#define F_OIDNE 185 +#define F_OIDOUT 1799 +#define F_OIDRECV 2418 +#define F_OIDSEND 2419 +#define F_OIDSMALLER 1966 +#define F_OIDVECTOREQ 679 +#define F_OIDVECTORGE 680 +#define F_OIDVECTORGT 681 +#define F_OIDVECTORIN 54 +#define F_OIDVECTORIN_EXTEND 91 +#define F_OIDVECTORLE 678 +#define F_OIDVECTORLT 677 +#define F_OIDVECTORNE 619 +#define F_OIDVECTOROUT 55 +#define F_OIDVECTOROUT_EXTEND 92 +#define F_OIDVECTORRECV 2420 +#define F_OIDVECTORRECV_EXTEND 3122 +#define F_OIDVECTORSEND 2421 +#define F_OIDVECTORSEND_EXTEND 3123 +#define F_OIDVECTORTYPES 1349 +#define F_ON_PB 136 +#define F_ON_PL 959 +#define F_ON_PPATH 137 +#define F_ON_PS 369 +#define F_ON_SB 372 +#define F_ON_SL 960 +#define F_OPAQUE_IN 2306 +#define F_OPAQUE_OUT 2307 +#define F_ORDERED_SET_TRANSITION 4448 +#define F_OVERLAPS_TIMETZ 1271 +#define F_OVERLAPS_TIMESTAMP 1304 +#define F_OVERLAPS_TIME 1308 +#define F_BYTEAOVERLAY 749 +#define F_BYTEAOVERLAY_NO_LEN 752 +#define F_TEXTOVERLAY 1404 +#define F_TEXTOVERLAY_NO_LEN 1405 +#define F_BITOVERLAY 3030 +#define F_BITOVERLAY_NO_LEN 3031 +#define F_POLY_PATH 1447 +#define F_PATH_ADD 1435 +#define F_PATH_ADD_PT 1436 +#define F_PATH_CENTER 226 +#define F_PATH_DISTANCE 370 +#define F_PATH_DIV_PT 1439 +#define F_PATH_IN 121 +#define F_PATH_INTER 973 +#define F_PATH_MUL_PT 1438 +#define F_PATH_N_EQ 984 +#define F_PATH_N_GE 986 +#define F_PATH_N_GT 983 +#define F_PATH_N_LE 985 +#define F_PATH_N_LT 982 +#define F_PATH_OUT 122 +#define F_PATH_RECV 2482 +#define F_PATH_SEND 2483 +#define F_PATH_SUB_PT 1437 +#define F_PATH_CLOSE 1433 +#define F_WINDOW_PERCENT_RANK 3103 +#define F_PERCENTILE_CONT_FLOAT8_FINAL 4453 +#define F_PERCENTILE_CONT_INTERVAL_FINAL 4455 +#define F_PG_ADVISORY_LOCK_INT8 2880 +#define F_PG_ADVISORY_LOCK_INT4 2886 +#define F_PG_ADVISORY_LOCK_SP_DB_INT4 9016 +#define F_PG_ADVISORY_LOCK_SHARED_INT8 2881 +#define F_PG_ADVISORY_LOCK_SHARED_INT4 2887 +#define F_PG_ADVISORY_UNLOCK_INT8 2884 +#define F_PG_ADVISORY_UNLOCK_INT4 2890 +#define F_PG_ADVISORY_UNLOCK_SP_DB_INT4 9015 +#define F_PG_ADVISORY_UNLOCK_ALL 2892 +#define F_PG_ADVISORY_UNLOCK_SHARED_INT8 2885 +#define F_PG_ADVISORY_UNLOCK_SHARED_INT4 2891 +#define F_PG_ADVISORY_XACT_LOCK_INT8 3089 +#define F_PG_ADVISORY_XACT_LOCK_INT4 3093 +#define F_PG_ADVISORY_XACT_LOCK_SHARED_INT8 3090 +#define F_PG_ADVISORY_XACT_LOCK_SHARED_INT4 3094 +#define F_PG_AUTOVAC_COORDINATOR 4081 +#define F_PG_AUTOVAC_STATUS 3223 +#define F_PG_AUTOVAC_TIMEOUT 4080 +#define F_PG_AVAILABLE_EXTENSION_VERSIONS 3083 +#define F_PG_AVAILABLE_EXTENSIONS 3082 +#define F_PG_BACKEND_PID PGBACKENDPIDFUNCOID +#define F_PG_BUFFERCACHE_PAGES 4130 +#define F_PG_CANCEL_BACKEND 2171 +#define F_PG_CANCEL_INVALID_QUERY 3213 +#define F_PG_CBM_FORCE_TRACK 4655 +#define F_PG_CBM_GET_CHANGED_BLOCK 4653 +#define F_PG_CBM_GET_MERGED_FILE 4652 +#define F_PG_CBM_RECYCLE_FILE 4654 +#define F_PG_CBM_ROTATE_FILE 4660 +#define F_PG_CBM_TRACKED_LOCATION 4651 +#define F_PG_CHAR_TO_ENCODING PGCHARTOENCODINGFUNCOID +#define F_PG_CHECK_AUTHID PGCHECKAUTHIDFUNCOID +#define F_PG_CHECK_XIDLIMIT 1999 +#define F_PG_CLEAN_REGION_INFO 4209 +#define F_PG_CLIENT_ENCODING PGCLIENTENCODINGFUNCOID +#define F_PG_COLLATION_FOR 3162 +#define F_PG_COLLATION_IS_VISIBLE 3815 +#define F_PG_COLUMN_SIZE PGCOLUMNSIZEFUNCOID +#define F_PG_COMM_DELAY 1987 +#define F_PG_COMM_RECV_STREAM 1984 +#define F_PG_COMM_SEND_STREAM 1985 +#define F_PG_COMM_STATUS 1986 +#define F_PG_CONF_LOAD_TIME 2034 +#define F_PG_CONTROL_GROUP_CONFIG 3843 +#define F_PG_CONVERSION_IS_VISIBLE 2093 +#define F_PG_CREATE_LOGICAL_REPLICATION_SLOT 4215 +#define F_PG_CREATE_PHYSICAL_REPLICATION_SLOT 3779 +#define F_PG_CREATE_PHYSICAL_REPLICATION_SLOT_EXTERN 3790 +#define F_PG_CREATE_RESTORE_POINT 3098 +#define F_PG_CURRENT_SESSID 3267 +#define F_PG_CURRENT_SESSIONID 3266 +#define F_PG_CURRENT_USERID 3265 +#define F_PG_CURRENT_XLOG_INSERT_LOCATION 2852 +#define F_PG_CURRENT_XLOG_LOCATION 2849 +#define F_PG_CURSOR 2511 +#define F_PG_DATABASE_SIZE_NAME 2168 +#define F_PG_DATABASE_SIZE_OID 2324 +#define F_PG_DELETE_AUDIT 3781 +#define F_PG_DESCRIBE_OBJECT 3537 +#define F_PG_DISABLE_DELAY_DDL_RECYCLE 4657 +#define F_PG_DISABLE_DELAY_XLOG_RECYCLE 4659 +#define F_PG_DROP_REPLICATION_SLOT 3783 +#define F_PG_ENABLE_DELAY_DDL_RECYCLE 4656 +#define F_PG_ENABLE_DELAY_XLOG_RECYCLE 4658 +#define F_PG_ENCODING_MAX_LENGTH_SQL 2319 +#define F_PG_ENCODING_TO_CHAR PGENCODINGTOCHARFUNCOID +#define F_PG_EXPORT_SNAPSHOT 3809 +#define F_PG_EXPORT_SNAPSHOT_AND_CSN 4396 +#define F_PG_EXTENSION_CONFIG_DUMP 3086 +#define F_PG_EXTENSION_UPDATE_PATHS 3084 +#define F_PG_FILENODE_RELATION 3454 +#define F_PG_FUNCTION_IS_VISIBLE 2081 +#define F_PG_GET_CONSTRAINTDEF 1387 +#define F_PG_GET_CONSTRAINTDEF_EXT 2508 +#define F_PG_GET_EXPR 1716 +#define F_PG_GET_EXPR_EXT 2509 +#define F_PG_GET_FLUSH_LSN 3316 +#define F_PG_GET_FUNCTION_ARGUMENTS 2162 +#define F_PG_GET_FUNCTION_IDENTITY_ARGUMENTS 2232 +#define F_PG_GET_FUNCTION_RESULT 2165 +#define F_PG_GET_FUNCTIONDEF 2098 +#define F_PG_GET_GTT_RELSTATS 3596 +#define F_PG_GET_GTT_STATISTICS 3597 +#define F_PG_GET_INDEXDEF 1643 +#define F_PG_GET_INDEXDEF_EXT 2507 +#define F_PG_GET_KEYWORDS 1686 +#define F_PG_GET_REPLICATION_SLOT_NAME 6003 +#define F_PG_GET_REPLICATION_SLOTS 3784 +#define F_PG_GET_RULEDEF 1573 +#define F_PG_GET_RULEDEF_EXT 2504 +#define F_PG_GET_RUNNING_XACTS 1998 +#define F_PG_GET_SERIAL_SEQUENCE 1665 +#define F_PG_GET_SYNC_FLUSH_LSN 3317 +#define F_PG_GET_TABLEDEF_EXT 4443 +#define F_PG_GET_TRIGGERDEF 1662 +#define F_PG_GET_TRIGGERDEF_EXT 2730 +#define F_PG_GET_USERBYID 1642 +#define F_PG_GET_VARIABLE_INFO 2097 +#define F_PG_GET_VIEWDEF_NAME 1640 +#define F_PG_GET_VIEWDEF 1641 +#define F_PG_GET_VIEWDEF_NAME_EXT 2505 +#define F_PG_GET_VIEWDEF_EXT 2506 +#define F_PG_GET_VIEWDEF_WRAP 3159 +#define F_PG_GET_XIDLIMIT 2000 +#define F_PG_GTT_ATTACHED_PID 3598 +#define F_PG_HAS_ROLE_NAME_NAME 2705 +#define F_PG_HAS_ROLE_NAME_ID 2706 +#define F_PG_HAS_ROLE_ID_NAME 2707 +#define F_PG_HAS_ROLE_ID_ID 2708 +#define F_PG_HAS_ROLE_NAME 2709 +#define F_PG_HAS_ROLE_ID 2710 +#define F_PG_INDEXES_SIZE 2998 +#define F_PG_IS_IN_RECOVERY 3810 +#define F_PG_IS_OTHER_TEMP_SCHEMA 2855 +#define F_PG_IS_XLOG_REPLAY_PAUSED 3073 +#define F_PG_LAST_XACT_REPLAY_TIMESTAMP 3830 +#define F_PG_LAST_XLOG_RECEIVE_LOCATION 3820 +#define F_PG_LAST_XLOG_REPLAY_LOCATION 3821 +#define F_PG_LIST_GTT_RELFROZENXIDS 3599 +#define F_PG_LISTENING_CHANNELS 3035 +#define F_PG_LOCK_STATUS 1371 +#define F_PG_LOG_COMM_STATUS 1983 +#define F_PG_LOGICAL_SLOT_GET_BINARY_CHANGES 4217 +#define F_PG_LOGICAL_SLOT_GET_CHANGES 4216 +#define F_PG_LOGICAL_SLOT_PEEK_BINARY_CHANGES 4219 +#define F_PG_LOGICAL_SLOT_PEEK_CHANGES 4218 +#define F_PG_LS_DIR 2625 +#define F_PG_MY_TEMP_SCHEMA 2854 +#define F_PG_NODE_TREE_IN 195 +#define F_PG_NODE_TREE_OUT 196 +#define F_PG_NODE_TREE_RECV 197 +#define F_PG_NODE_TREE_SEND 198 +#define F_PG_NOTIFY 3036 +#define F_PG_OPCLASS_IS_VISIBLE 2083 +#define F_PG_OPERATOR_IS_VISIBLE 2082 +#define F_PG_OPFAMILY_IS_VISIBLE 3829 +#define F_PG_OPTIONS_TO_TABLE 2289 +#define F_PG_PARSE_CLOG 3212 +#define F_PG_PARTITION_FILENODE 3197 +#define F_PG_PARTITION_FILEPATH 3220 +#define F_PG_PARTITION_INDEXES_SIZE_NAME 3195 +#define F_PG_PARTITION_INDEXES_SIZE_OID 3196 +#define F_PG_PARTITION_SIZE_NAME 3193 +#define F_PG_PARTITION_SIZE_OID 3194 +#define F_PG_POOL_PING 3472 +#define F_PG_POOL_VALIDATE 3471 +#define F_PG_POSTMASTER_START_TIME 2560 +#define F_PG_PREPARED_STATEMENT 2510 +#define F_PG_PREPARED_XACT 1065 +#define F_PG_QUERY_AUDIT 3780 +#define F_PG_READ_BINARY_FILE 3827 +#define F_PG_READ_BINARY_FILE_ALL 3828 +#define F_PG_READ_FILE 2624 +#define F_PG_READ_FILE_ALL 3826 +#define F_PG_RELATION_COMPRESSION_RATIO 3211 +#define F_PG_RELATION_FILENODE 2999 +#define F_PG_RELATION_FILEPATH 3034 +#define F_PG_RELATION_SIZE 2332 +#define F_PG_RELATION_WITH_COMPRESSION 3210 +#define F_PG_RELOAD_CONF 2621 +#define F_PG_REPLICATION_SLOT_ADVANCE 4220 +#define F_PG_RESUME_BKP_FLAG 4445 +#define F_PG_ROTATE_LOGFILE 2622 +#define F_PG_SEQUENCE_PARAMETERS 3078 +#define F_PG_SHARED_MEMCTX_DETAIL 3987 +#define F_PG_SHARED_MEMORY_DETAIL 3986 +#define F_SHOW_ALL_SETTINGS 2084 +#define F_PG_SIZE_PRETTY 2288 +#define F_PG_SIZE_PRETTY_NUMERIC 3166 +#define F_PG_SLEEP 2626 +#define F_PG_START_BACKUP 2172 +#define F_PG_STAT_BAD_BLOCK 3218 +#define F_PG_STAT_BAD_BLOCK_CLEAR 3219 +#define F_PG_STAT_CLEAR_SNAPSHOT 2230 +#define F_PG_STAT_FILE 2623 +#define F_PG_STAT_FILE_RECURSIVE 6321 +#define F_PG_STAT_GET_ACTIVITY 2022 +#define F_PG_STAT_GET_ACTIVITY_FOR_TEMPTABLE 4213 +#define F_PG_STAT_GET_ACTIVITY_NG 5549 +#define F_PG_STAT_GET_ACTIVITY_WITH_CONNINFO 4212 +#define F_PG_STAT_GET_ANALYZE_COUNT 3056 +#define F_PG_STAT_GET_AUTOANALYZE_COUNT 3057 +#define F_PG_STAT_GET_AUTOVACUUM_COUNT 3055 +#define F_PG_STAT_GET_BACKEND_ACTIVITY 1940 +#define F_PG_STAT_GET_BACKEND_ACTIVITY_START 2094 +#define F_PG_STAT_GET_BACKEND_CLIENT_ADDR 1392 +#define F_PG_STAT_GET_BACKEND_CLIENT_PORT 1393 +#define F_PG_STAT_GET_BACKEND_DBID 1938 +#define F_PG_STAT_GET_BACKEND_IDSET 1936 +#define F_PG_STAT_GET_BACKEND_PID PGSTATGETBACKENDPIDFUNCOID +#define F_PG_STAT_GET_BACKEND_START 1391 +#define F_PG_STAT_GET_BACKEND_USERID 1939 +#define F_PG_STAT_GET_BACKEND_WAITING 2853 +#define F_PG_STAT_GET_BACKEND_XACT_START 2857 +#define F_PG_STAT_GET_BGWRITER_BUF_WRITTEN_CHECKPOINTS 2771 +#define F_PG_STAT_GET_BGWRITER_BUF_WRITTEN_CLEAN 2772 +#define F_PG_STAT_GET_BGWRITER_MAXWRITTEN_CLEAN 2773 +#define F_PG_STAT_GET_BGWRITER_REQUESTED_CHECKPOINTS 2770 +#define F_PG_STAT_GET_BGWRITER_STAT_RESET_TIME 3075 +#define F_PG_STAT_GET_BGWRITER_TIMED_CHECKPOINTS 2769 +#define F_PG_STAT_GET_BLOCKS_FETCHED 1934 +#define F_PG_STAT_GET_BLOCKS_HIT 1935 +#define F_PG_STAT_GET_BUF_ALLOC 2859 +#define F_PG_STAT_GET_BUF_FSYNC_BACKEND 3063 +#define F_PG_STAT_GET_BUF_WRITTEN_BACKEND 2775 +#define F_PG_STAT_GET_CGROUP_INFO 5008 +#define F_PG_STAT_GET_CHECKPOINT_SYNC_TIME 3161 +#define F_PG_STAT_GET_CHECKPOINT_WRITE_TIME 3160 +#define F_PG_STAT_GET_CU_HDD_ASYN 3484 +#define F_PG_STAT_GET_CU_HDD_SYNC 3483 +#define F_PG_STAT_GET_CU_MEM_HIT 3480 +#define F_PG_STAT_GET_DATA_SENDERS 3785 +#define F_PG_STAT_GET_DB_BLK_READ_TIME 2844 +#define F_PG_STAT_GET_DB_BLK_WRITE_TIME 2845 +#define F_PG_STAT_GET_DB_BLOCKS_FETCHED 1944 +#define F_PG_STAT_GET_DB_BLOCKS_HIT 1945 +#define F_PG_STAT_GET_DB_CONFLICT_ALL 3070 +#define F_PG_STAT_GET_DB_CONFLICT_BUFFERPIN 3068 +#define F_PG_STAT_GET_DB_CONFLICT_LOCK 3066 +#define F_PG_STAT_GET_DB_CONFLICT_SNAPSHOT 3067 +#define F_PG_STAT_GET_DB_CONFLICT_STARTUP_DEADLOCK 3069 +#define F_PG_STAT_GET_DB_CONFLICT_TABLESPACE 3065 +#define F_PG_STAT_GET_DB_CU_HDD_ASYN 3489 +#define F_PG_STAT_GET_DB_CU_HDD_SYNC 3488 +#define F_PG_STAT_GET_DB_CU_MEM_HIT 3485 +#define F_PG_STAT_GET_DB_DEADLOCKS 3152 +#define F_PG_STAT_GET_DB_NUMBACKENDS 1941 +#define F_PG_STAT_GET_DB_STAT_RESET_TIME 3074 +#define F_PG_STAT_GET_DB_TEMP_BYTES 3151 +#define F_PG_STAT_GET_DB_TEMP_FILES 3150 +#define F_PG_STAT_GET_DB_TUPLES_DELETED 2762 +#define F_PG_STAT_GET_DB_TUPLES_FETCHED 2759 +#define F_PG_STAT_GET_DB_TUPLES_INSERTED 2760 +#define F_PG_STAT_GET_DB_TUPLES_RETURNED 2758 +#define F_PG_STAT_GET_DB_TUPLES_UPDATED 2761 +#define F_PG_STAT_GET_DB_XACT_COMMIT 1942 +#define F_PG_STAT_GET_DB_XACT_ROLLBACK 1943 +#define F_PG_STAT_GET_DEAD_TUPLES 2879 +#define F_PG_STAT_GET_ENV 3982 +#define F_PG_STAT_GET_FILE_STAT 3975 +#define F_PG_STAT_GET_FUNCTION_CALLS 2978 +#define F_PG_STAT_GET_FUNCTION_SELF_TIME 2980 +#define F_PG_STAT_GET_FUNCTION_TOTAL_TIME 2979 +#define F_PG_STAT_GET_LAST_ANALYZE_TIME 2783 +#define F_PG_STAT_GET_LAST_AUTOANALYZE_TIME 2784 +#define F_PG_STAT_GET_LAST_AUTOVACUUM_TIME 2782 +#define F_PG_STAT_GET_LAST_DATA_CHANGED_TIME 5600 +#define F_PG_STAT_GET_LAST_VACUUM_TIME 2781 +#define F_PG_STAT_GET_LIVE_TUPLES 2878 +#define F_PG_STAT_GET_MEM_MBYTES_RESERVED 2846 +#define F_PG_STAT_GET_NUMSCANS 1928 +#define F_PG_STAT_GET_PARTITION_DEAD_TUPLES 4087 +#define F_PG_STAT_GET_PARTITION_LIVE_TUPLES 4092 +#define F_PG_STAT_GET_PARTITION_TUPLES_CHANGED 4086 +#define F_PG_STAT_GET_PARTITION_TUPLES_DELETED 4090 +#define F_PG_STAT_GET_PARTITION_TUPLES_HOT_UPDATED 4091 +#define F_PG_STAT_GET_PARTITION_TUPLES_INSERTED 4088 +#define F_PG_STAT_GET_PARTITION_TUPLES_UPDATED 4089 +#define F_PG_STAT_GET_POOLER_STATUS 3955 +#define F_PG_STAT_GET_REALTIME_INFO_INTERNAL 3500 +#define F_PG_STAT_GET_REDO_STAT 3973 +#define F_GS_GET_ROLE_NAME 5010 +#define F_PG_STAT_GET_SESSION_WLMSTAT 3502 +#define F_PG_STAT_GET_SQL_COUNT 3947 +#define F_PG_STAT_GET_STATUS 3980 +#define F_PG_STAT_GET_STREAM_REPLICATIONS 3499 +#define F_PG_STAT_GET_THREAD 3981 +#define F_PG_STAT_GET_TUPLES_CHANGED 3221 +#define F_PG_STAT_GET_TUPLES_DELETED 1933 +#define F_PG_STAT_GET_TUPLES_FETCHED 1930 +#define F_PG_STAT_GET_TUPLES_HOT_UPDATED 1972 +#define F_PG_STAT_GET_TUPLES_INSERTED 1931 +#define F_PG_STAT_GET_TUPLES_RETURNED 1929 +#define F_PG_STAT_GET_TUPLES_UPDATED 1932 +#define F_PG_STAT_GET_VACUUM_COUNT 3054 +#define F_PG_STAT_GET_WAL_RECEIVER 3819 +#define F_PG_STAT_GET_WAL_SENDERS 3099 +#define F_PG_STAT_GET_WLM_EC_OPERATOR_INFO 5024 +#define F_PG_STAT_GET_WLM_INSTANCE_INFO 5031 +#define F_PG_STAT_GET_WLM_INSTANCE_INFO_WITH_CLEANUP 5032 +#define F_PG_STAT_GET_WLM_NODE_RESOURCE_INFO 5019 +#define F_PG_STAT_GET_WLM_OPERATOR_INFO 5023 +#define F_PG_STAT_GET_WLM_REALTIME_EC_OPERATOR_INFO 5025 +#define F_PG_STAT_GET_WLM_REALTIME_OPERATOR_INFO 5022 +#define F_PG_STAT_GET_WLM_REALTIME_SESSION_INFO 5003 +#define F_PG_STAT_GET_WLM_SESSION_INFO 5002 +#define F_PG_STAT_GET_WLM_SESSION_INFO_INTERNAL 5001 +#define F_PG_STAT_GET_WLM_SESSION_IOSTAT_INFO 5014 +#define F_PG_STAT_GET_WLM_STATISTICS 3501 +#define F_PG_STAT_GET_WORKLOAD_STRUCT_INFO 5026 +#define F_PG_STAT_GET_XACT_BLOCKS_FETCHED 3044 +#define F_PG_STAT_GET_XACT_BLOCKS_HIT 3045 +#define F_PG_STAT_GET_XACT_FUNCTION_CALLS 3046 +#define F_PG_STAT_GET_XACT_FUNCTION_SELF_TIME 3048 +#define F_PG_STAT_GET_XACT_FUNCTION_TOTAL_TIME 3047 +#define F_PG_STAT_GET_XACT_NUMSCANS 3037 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_DELETED 4093 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_HOT_UPDATED 4096 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_INSERTED 4094 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_UPDATED 4095 +#define F_PG_STAT_GET_XACT_TUPLES_DELETED 3042 +#define F_PG_STAT_GET_XACT_TUPLES_FETCHED 3039 +#define F_PG_STAT_GET_XACT_TUPLES_HOT_UPDATED 3043 +#define F_PG_STAT_GET_XACT_TUPLES_INSERTED 3040 +#define F_PG_STAT_GET_XACT_TUPLES_RETURNED 3038 +#define F_PG_STAT_GET_XACT_TUPLES_UPDATED 3041 +#define F_PG_STAT_RESET 2274 +#define F_PG_STAT_RESET_SHARED 3775 +#define F_PG_STAT_RESET_SINGLE_FUNCTION_COUNTERS 3777 +#define F_PG_STAT_RESET_SINGLE_TABLE_COUNTERS 3776 +#define F_PG_STAT_SET_LAST_DATA_CHANGED_TIME 5601 +#define F_PG_STOP_BACKUP 2173 +#define F_PG_SWITCH_XLOG 2848 +#define F_PG_SYNC_CSTORE_DELTA 3164 +#define F_PG_SYNC_ALL_CSTORE_DELTA 3534 +#define F_PG_SYSTEM_TIMESTAMP PGSYSTIMESTAMPFUNCOID +#define F_PG_TABLE_IS_VISIBLE 2079 +#define F_PG_TABLE_SIZE 2997 +#define F_PG_TABLESPACE_DATABASES 2556 +#define F_PG_TABLESPACE_LOCATION 3778 +#define F_PG_TABLESPACE_SIZE_OID 2322 +#define F_PG_TABLESPACE_SIZE_NAME 2323 +#define F_PG_TDE_INFO 3999 +#define F_PG_TERMINATE_BACKEND 2096 +#define F_PG_TERMINATE_SESSION 2099 +#define F_PG_TEST_ERR_CONTAIN_ERR 9999 +#define F_PG_TIMEZONE_ABBREVS 2599 +#define F_PG_TIMEZONE_NAMES 2856 +#define F_PG_TOTAL_AUTOVAC_TUPLES 3222 +#define F_PG_TOTAL_RELATION_SIZE 2286 +#define F_PG_TRIGGER_DEPTH 3163 +#define F_PG_TRY_ADVISORY_LOCK_INT8 2882 +#define F_PG_TRY_ADVISORY_LOCK_INT4 2888 +#define F_PG_TRY_ADVISORY_LOCK_SHARED_INT8 2883 +#define F_PG_TRY_ADVISORY_LOCK_SHARED_INT4 2889 +#define F_PG_TRY_ADVISORY_XACT_LOCK_INT8 3091 +#define F_PG_TRY_ADVISORY_XACT_LOCK_INT4 3095 +#define F_PG_TRY_ADVISORY_XACT_LOCK_SHARED_INT8 3092 +#define F_PG_TRY_ADVISORY_XACT_LOCK_SHARED_INT4 3096 +#define F_PG_TS_CONFIG_IS_VISIBLE 3758 +#define F_PG_TS_DICT_IS_VISIBLE 3757 +#define F_PG_TS_PARSER_IS_VISIBLE 3756 +#define F_PG_TS_TEMPLATE_IS_VISIBLE 3768 +#define F_PG_TYPE_IS_VISIBLE 2080 +#define F_PG_TYPEOF PGTYPEOFFUNCOID +#define F_PG_STAT_GET_WLM_USER_IOSTAT_INFO 5013 +#define F_PG_WLM_JUMP_QUEUE 3503 +#define F_PG_XLOG_LOCATION_DIFF 3165 +#define F_PG_XLOG_REPLAY_PAUSE 3071 +#define F_PG_XLOG_REPLAY_RESUME 3072 +#define F_PG_XLOGFILE_NAME 2851 +#define F_PG_XLOGFILE_NAME_OFFSET 2850 +#define F_PGXC_GET_CSN 3960 +#define F_PGXC_STAT_GET_STATUS 3591 +#define F_PGXC_GTM_SNAPSHOT_STATUS 2095 +#define F_PGXC_IS_COMMITTED 3203 +#define F_PGXC_LOCK_FOR_BACKUP 3204 +#define F_PGXC_LOCK_FOR_SP_DATABASE 9014 +#define F_PGXC_LOCK_FOR_TRANSFER 9018 +#define F_PGXC_MAX_DATANODE_SIZE_NAME 5028 +#define F_PGXC_NODE_STR 3202 +#define F_PGXC_POOL_CHECK 3200 +#define F_PGXC_POOL_CONNECTION_STATUS 3954 +#define F_PGXC_POOL_RELOAD 3201 +#define F_PGXC_SNAPSHOT_STATUS 2949 +#define F_PGXC_STAT_ALL_DIRTY_TABLES 4410 +#define F_PGXC_STAT_SCHEMA_DIRTY_TABLES 4411 +#define F_PGXC_UNLOCK_FOR_SP_DATABASE 9017 +#define F_PGXC_UNLOCK_FOR_TRANSFER 9019 +#define F_PGXC_VERSION 90 +#define F_DPI 1610 +#define F_PLAINTO_TSQUERY_BYID 3747 +#define F_PLAINTO_TSQUERY 3751 +#define F_GET_PLAN_SEED 4200 +#define F_GPCPLANCLEAN 3958 +#define F_GS_GLOBALPLANCACHE_STATUS 3957 +#define F_CONSTRUCT_POINT 1440 +#define F_POLY_CENTER 1540 +#define F_POINT_ABOVE 131 +#define F_POINT_ADD 1441 +#define F_POINT_BELOW 134 +#define F_POINT_DISTANCE 991 +#define F_POINT_DIV 1444 +#define F_POINT_EQ 135 +#define F_POINT_IN 117 +#define F_POINT_LEFT 132 +#define F_POINT_MUL 1443 +#define F_POINT_NE 988 +#define F_POINT_OUT 118 +#define F_POINT_RECV 2428 +#define F_POINT_RIGHT 133 +#define F_POINT_SEND 2429 +#define F_POINT_SUB 1442 +#define F_POLY_ABOVE 2569 +#define F_POLY_BELOW 2566 +#define F_POLY_CONTAIN 340 +#define F_POLY_CONTAIN_PT 1428 +#define F_POLY_CONTAINED 345 +#define F_POLY_DISTANCE 729 +#define F_POLY_IN 347 +#define F_POLY_LEFT 341 +#define F_POLY_OUT 348 +#define F_POLY_OVERABOVE 2568 +#define F_POLY_OVERBELOW 2567 +#define F_POLY_OVERLAP 346 +#define F_POLY_OVERLEFT 342 +#define F_POLY_OVERRIGHT 343 +#define F_POLY_RECV 2486 +#define F_POLY_RIGHT 344 +#define F_POLY_SAME 339 +#define F_POLY_SEND 2487 +#define F_BOX_POLY 1448 +#define F_PATH_POLY 1449 +#define F_CIRCLE_POLY 1475 +#define F_PATH_OPEN 1434 +#define F_BITPOSITION BITPOSITIONFUNCOID +#define F_BYTEAPOS BYTEAPOSFUNCOID +#define F_POSITIONJOINSEL 1301 +#define F_POSITIONSEL 1300 +#define F_POSTGRESQL_FDW_VALIDATOR 2316 +#define F_POUND_END 3800 +#define F_POUND_LEXTYPE 3801 +#define F_POUND_NEXTTOKEN 3799 +#define F_POUND_START 3798 +#define F_GS_GLOBALPLANCACHE_PREPARE_STATUS 3959 +#define F_PRSD_END 3719 +#define F_PRSD_HEADLINE 3720 +#define F_PRSD_LEXTYPE 3721 +#define F_PRSD_NEXTTOKEN 3718 +#define F_PRSD_START 3717 +#define F_PSORTBUILD 4040 +#define F_PSORTCANRETURN 4045 +#define F_PSORTCOSTESTIMATE 4044 +#define F_PSORTGETBITMAP 4043 +#define F_PSORTGETTUPLE 4042 +#define F_PSORTOPTIONS 4041 +#define F_PT_CONTAINED_CIRCLE 1478 +#define F_PT_CONTAINED_POLY 1429 +#define F_PV_BUILTIN_FUNCTIONS 5345 +#define F_PV_COMPUTE_POOL_WORKLOAD 4300 +#define F_PV_INSTANCE_TIME 3969 +#define F_PV_OS_RUN_INFO 3970 +#define F_PV_SESSION_MEMCTX_DETAIL 3983 +#define F_PV_SESSION_MEMORY 3984 +#define F_PV_SESSION_MEMORY_DETAIL 3971 +#define F_PV_SESSION_STAT 3974 +#define F_PV_SESSION_TIME 3972 +#define F_PV_THREAD_MEMORY_DETAIL 3968 +#define F_PV_TOTAL_MEMORY_DETAIL 3985 +#define F_QUERY_TO_XML 2924 +#define F_QUERY_TO_XML_AND_XMLSCHEMA 2930 +#define F_QUERY_TO_XMLSCHEMA 2927 +#define F_TSQUERYTREE 3673 +#define F_QUOTE_IDENT 1282 +#define F_QUOTE_LITERAL 1283 +#define F_QUOTE_NULLABLE 1289 +#define F_RADIANS 1609 +#define F_CIRCLE_RADIUS 1470 +#define F_DRANDOM RANDOMFUNCOID +#define F_RANGE_ADJACENT 3862 +#define F_RANGE_AFTER 3864 +#define F_RANGE_BEFORE 3863 +#define F_RANGE_CMP 3870 +#define F_RANGE_CONTAINED_BY 3861 +#define F_RANGE_CONTAINS 3859 +#define F_RANGE_CONTAINS_ELEM 3858 +#define F_RANGE_EQ 3855 +#define F_RANGE_GE 3873 +#define F_RANGE_GIST_COMPRESS 3877 +#define F_RANGE_GIST_CONSISTENT 3875 +#define F_RANGE_GIST_DECOMPRESS 3878 +#define F_RANGE_GIST_PENALTY 3879 +#define F_RANGE_GIST_PICKSPLIT 3880 +#define F_RANGE_GIST_SAME 3881 +#define F_RANGE_GIST_UNION 3876 +#define F_RANGE_GT 3874 +#define F_RANGE_IN 3834 +#define F_RANGE_INTERSECT 3868 +#define F_RANGE_LE 3872 +#define F_RANGE_LT 3871 +#define F_RANGE_MINUS 3869 +#define F_RANGE_NE 3856 +#define F_RANGE_OUT 3835 +#define F_RANGE_OVERLAPS 3857 +#define F_RANGE_OVERLEFT 3865 +#define F_RANGE_OVERRIGHT 3866 +#define F_RANGE_RECV 3836 +#define F_RANGE_SEND 3837 +#define F_RANGE_TYPANALYZE 3916 +#define F_RANGE_UNION 3867 +#define F_WINDOW_RANK RANKFUNCOID +#define F_RAWCAT 3478 +#define F_RAWCMP 3475 +#define F_RAWEQ 3931 +#define F_RAWGE 3939 +#define F_RAWGT 3936 +#define F_RAWIN 4035 +#define F_RAWLE 3935 +#define F_RAWLIKE 3476 +#define F_RAWLT 3932 +#define F_RAWNE 3940 +#define F_RAWNLIKE 3477 +#define F_RAWOUT 4036 +#define F_RAWTOTEXT 4037 +#define F_READ_DISABLE_CONN_FILE 4222 +#define F_RECORD_EQ 2981 +#define F_RECORD_GE 2986 +#define F_RECORD_GT 2984 +#define F_RECORD_IN 2290 +#define F_RECORD_LE 2985 +#define F_RECORD_LT 2983 +#define F_RECORD_NE 2982 +#define F_RECORD_OUT 2291 +#define F_RECORD_RECV 2402 +#define F_RECORD_SEND 2403 +#define F_TEXT_REGCLASS 1079 +#define F_REGCLASSIN 2218 +#define F_REGCLASSOUT 2219 +#define F_REGCLASSRECV 2452 +#define F_REGCLASSSEND 2453 +#define F_REGCONFIGIN 3736 +#define F_REGCONFIGOUT 3737 +#define F_REGCONFIGRECV 3738 +#define F_REGCONFIGSEND 3739 +#define F_REGDICTIONARYIN 3771 +#define F_REGDICTIONARYOUT 3772 +#define F_REGDICTIONARYRECV 3773 +#define F_REGDICTIONARYSEND 3774 +#define F_REGEXEQJOINSEL 1824 +#define F_REGEXEQSEL 1818 +#define F_REGEXNEJOINSEL 1827 +#define F_REGEXNESEL 1821 +#define F_REGEXP_MATCHES_NO_FLAGS 2763 +#define F_REGEXP_MATCHES 2764 +#define F_TEXTREGEXREPLACE_NOOPT 2284 +#define F_TEXTREGEXREPLACE 2285 +#define F_REGEXP_SPLIT_TO_ARRAY_NO_FLAGS 2767 +#define F_REGEXP_SPLIT_TO_ARRAY 2768 +#define F_REGEXP_SPLIT_TO_TABLE_NO_FLAGS 2765 +#define F_REGEXP_SPLIT_TO_TABLE 2766 +#define F_REGOPERATORIN 2216 +#define F_REGOPERATOROUT 2217 +#define F_REGOPERATORRECV 2450 +#define F_REGOPERATORSEND 2451 +#define F_REGOPERIN 2214 +#define F_REGOPEROUT 2215 +#define F_REGOPERRECV 2448 +#define F_REGOPERSEND 2449 +#define F_REGPROCEDUREIN 2212 +#define F_REGPROCEDUREOUT 2213 +#define F_REGPROCEDURERECV 2446 +#define F_REGPROCEDURESEND 2447 +#define F_REGPROCIN 44 +#define F_REGPROCOUT 45 +#define F_REGPROCRECV 2444 +#define F_REGPROCSEND 2445 +#define F_REGTYPEIN 2220 +#define F_REGTYPEOUT 2221 +#define F_REGTYPERECV 2454 +#define F_REGTYPESEND 2455 +#define F_INTERVAL_RELTIME 1194 +#define F_RELTIMEEQ 257 +#define F_RELTIMEGE 262 +#define F_RELTIMEGT 260 +#define F_RELTIMEIN RELTIMEINFUNCOID +#define F_RELTIMELE 261 +#define F_RELTIMELT 259 +#define F_RELTIMENE 258 +#define F_RELTIMEOUT RELTIMEOUTFUNCOID +#define F_RELTIMERECV 2464 +#define F_RELTIMESEND 2465 +#define F_REMOTE_BGWRITER_STAT 4374 +#define F_REMOTE_CKPT_STAT 4372 +#define F_REMOTE_DOUBLE_WRITE_STAT 4385 +#define F_REMOTE_PAGEWRITER_STAT 4368 +#define F_REMOTE_RECOVERY_STATUS 4999 +#define F_REMOTE_REDO_STAT 4389 +#define F_REMOTE_RTO_STAT 4789 +#define F_REMOTE_SINGLE_FLUSH_DW_STAT 4376 +#define F_REMOVE_JOB_CLASS_DEPEND_INTERNAL 6005 +#define F_REPEAT 1622 +#define F_REPLACE_TEXT 2087 +#define F_RESET_UNIQUE_SQL 5716 +#define F_TEXT_REVERSE 3062 +#define F_TEXT_RIGHT 3061 +#define F_NUMERIC_ROUND 1707 +#define F_WINDOW_ROW_NUMBER ROWNUMBERFUNCOID +#define F_ROW_TO_JSON 3155 +#define F_ROW_TO_JSON_PRETTY 3156 +#define F_RPAD RPADFUNCOID +#define F_RTRIM RTRIMFUNCOID +#define F_RTRIM1 RTRIMPARAFUNCOID +#define F_SCALARGTJOINSEL 108 +#define F_SCALARGTSEL 104 +#define F_SCALARLTJOINSEL 107 +#define F_SCALARLTSEL 103 +#define F_SCHEMA_TO_XML 2933 +#define F_SCHEMA_TO_XML_AND_XMLSCHEMA 2935 +#define F_SCHEMA_TO_XMLSCHEMA 2934 +#define F_SERIES_INTERNAL 6006 +#define F_SESSION_USER SESSIONUSERFUNCOID +#define F_SESSIONID_TO_PID 3978 +#define F_BYTEASETBIT 724 +#define F_BITSETBIT 3033 +#define F_BYTEASETBYTE 722 +#define F_SET_CONFIG_BY_NAME 2078 +#define F_SET_HASHBUCKET_INFO 6118 +#define F_INET_SET_MASKLEN 605 +#define F_CIDR_SET_MASKLEN 635 +#define F_SET_WORKING_GRAND_VERSION_NUM_MANUALLY 7998 +#define F_SETSEED 1599 +#define F_SETVAL_OID SETVAL1FUNCOID +#define F_SETVAL3_OID SETVAL3FUNCOID +#define F_TSVECTOR_SETWEIGHT 3624 +#define F_SHELL_IN 2398 +#define F_SHELL_OUT 2399 +#define F_NUMERIC_SIGN 1706 +#define F_DSIGN 2310 +#define F_SIMILAR_ESCAPE 1623 +#define F_DSIN SINEFUNCOID +#define F_POINT_SLOPE 992 +#define F_SMALLDATETIME_CMP 5586 +#define F_SMALLDATETIME_EQ 5580 +#define F_SMALLDATETIME_GE 5584 +#define F_SMALLDATETIME_GT 5585 +#define F_SMALLDATETIME_HASH 5587 +#define F_SMALLDATETIME_IN SMALLDATETIMEINFUNCOID +#define F_SMALLDATETIME_LARGER 9012 +#define F_SMALLDATETIME_LE 5583 +#define F_SMALLDATETIME_LT 5582 +#define F_SMALLDATETIME_NE 5581 +#define F_SMALLDATETIME_OUT SMALLDATETIMEOUTFUNCOID +#define F_SMALLDATETIME_RECV 9007 +#define F_SMALLDATETIME_SEND 9008 +#define F_SMALLDATETIME_SMALLER 9011 +#define F_SMGREQ 762 +#define F_SMGRIN 760 +#define F_SMGRNE 763 +#define F_SMGROUT 761 +#define F_SPG_KD_CHOOSE 4024 +#define F_SPG_KD_CONFIG 4023 +#define F_SPG_KD_INNER_CONSISTENT 4026 +#define F_SPG_KD_PICKSPLIT 4025 +#define F_SPG_QUAD_CHOOSE 4019 +#define F_SPG_QUAD_CONFIG 4018 +#define F_SPG_QUAD_INNER_CONSISTENT 4021 +#define F_SPG_QUAD_LEAF_CONSISTENT 4022 +#define F_SPG_QUAD_PICKSPLIT 4020 +#define F_SPG_TEXT_CHOOSE 4028 +#define F_SPG_TEXT_CONFIG 4027 +#define F_SPG_TEXT_INNER_CONSISTENT 4030 +#define F_SPG_TEXT_LEAF_CONSISTENT 4031 +#define F_SPG_TEXT_PICKSPLIT 4029 +#define F_SPGBEGINSCAN 4004 +#define F_SPGBUILD 4009 +#define F_SPGBUILDEMPTY 4010 +#define F_SPGBULKDELETE 4011 +#define F_SPGCANRETURN 4032 +#define F_SPGCOSTESTIMATE 4013 +#define F_SPGENDSCAN 4006 +#define F_SPGGETBITMAP 4002 +#define F_SPGGETTUPLE 4001 +#define F_SPGINSERT 4003 +#define F_SPGMARKPOS 4007 +#define F_SPGMERGE 3188 +#define F_SPGOPTIONS 4014 +#define F_SPGRESCAN 4005 +#define F_SPGRESTRPOS 4008 +#define F_SPGVACUUMCLEANUP 4012 +#define F_SPLIT_TEXT 2088 +#define F_STATEMENT_DETAIL_DECODE 5732 +#define F_STATEMENT_TIMESTAMP STATEMENTTIMESTAMPFUNCOID +#define F_STRING_AGG_FINALFN 3536 +#define F_STRING_AGG_TRANSFN STRINGAGGTRANSFNFUNCOID +#define F_TEXT_TO_ARRAY_NULL 376 +#define F_TEXT_TO_ARRAY 394 +#define F_TSVECTOR_STRIP 3623 +#define F_SUBMIT_JOB_ON_NODES 5717 +#define F_TEXT_SUBSTR_ORCLCOMPAT SUBSTRFUNCOID +#define F_TEXT_SUBSTR_NO_LEN_ORCLCOMPAT SUBSTRNOLENFUNCOID +#define F_BYTEA_SUBSTR_ORCLCOMPAT BYTEASUBSTRFUNCOID +#define F_BYTEA_SUBSTR_NO_LEN_ORCLCOMPAT BYTEASUBSTRNOLENFUNCOID +#define F_SUBSTRB_WITH_LENTH SUBSTRBWITHLENFUNCOID +#define F_SUBSTRB_WITHOUT_LENTH SUBSTRBNOLENFUNCOID +#define F_TEXT_SUBSTR_NULL TEXTSUBSTRINGFUNCOID +#define F_TEXT_SUBSTR_NO_LEN_NULL TEXTSUBSTRINGNOLENFUNCOID +#define F_BITSUBSTR BITSUBSTRINGFUNOID +#define F_BITSUBSTR_NO_LEN BITSUBSTRINGNOLENFUNCOID +#define F_BYTEA_SUBSTR BYTEASUBSTRINGFUNCOID +#define F_BYTEA_SUBSTR_NO_LEN BYTEASUBSTRINGNOLENOID +#define F_TEXTREGEXSUBSTR TEXTREGEXSUBSTRINGOID +#define F_TEXT_SUBSTR SUBSTRINNFUNCOID +#define F_TEXT_SUBSTR_NO_LEN SUBSTRINNNOLENFUNCOID +#define F_SUPPRESS_REDUNDANT_UPDATES_TRIGGER 1291 +#define F_TABLE_DATA_SKEWNESS TESTSKEWNESSRETURNTYPE +#define F_ALL_TABLE_DISTRIBUTION 4441 +#define F_SINGLE_TABLE_DISTRIBUTION 4442 +#define F_TABLE_TO_XML 2923 +#define F_TABLE_TO_XML_AND_XMLSCHEMA 2929 +#define F_TABLE_TO_XMLSCHEMA 2926 +#define F_TABLESPACE_OID_NAME 3952 +#define F_DTAN 1606 +#define F_NAME_TEXT 406 +#define F_NETWORK_SHOW 730 +#define F_CHAR_TEXT 946 +#define F_XMLTOTEXT 2922 +#define F_BOOLTEXT 2971 +#define F_TEXT_DATE 4164 +#define F_TEXT_FLOAT4 4192 +#define F_TEXT_FLOAT8 4193 +#define F_TEXT_GE 743 +#define F_TEXT_GT 742 +#define F_TEXT_INT1 4188 +#define F_TEXT_INT2 4189 +#define F_TEXT_INT4 4190 +#define F_TEXT_INT8 4191 +#define F_TEXT_LARGER 458 +#define F_TEXT_LE 741 +#define F_TEXT_LT 740 +#define F_TEXT_NUMERIC 4194 +#define F_TEXT_PATTERN_GE 2163 +#define F_TEXT_PATTERN_GT 2164 +#define F_TEXT_PATTERN_LE 2161 +#define F_TEXT_PATTERN_LT 2160 +#define F_TEXT_SMALLER 459 +#define F_TEXT_TIMESTAMP 4073 +#define F_TEXTCAT 1258 +#define F_TEXTEQ 67 +#define F_TEXTIN 46 +#define F_TEXTNE 157 +#define F_TEXTOUT 47 +#define F_TEXTRECV 2414 +#define F_TEXTSEND 2415 +#define F_THESAURUS_INIT 3740 +#define F_THESAURUS_LEXIZE 3741 +#define F_GS_THREADPOOL_STATUS 3956 +#define F_TIDEQ 1292 +#define F_TIDGE 2792 +#define F_TIDGT 2790 +#define F_TIDIN 48 +#define F_TIDLARGER 2795 +#define F_TIDLE 2793 +#define F_TIDLT 2791 +#define F_TIDNE 1265 +#define F_TIDOUT 49 +#define F_TIDRECV 2438 +#define F_TIDSEND 2439 +#define F_TIDSMALLER 2796 +#define F_TIMESTAMP_TIME 1316 +#define F_INTERVAL_TIME 1419 +#define F_TIME_SCALE 1968 +#define F_TIMESTAMPTZ_TIME TIMESTAMPTZ2TIMEFUNCOID +#define F_TIMETZ_TIME 2046 +#define F_TIME_CMP 1107 +#define F_TIME_EQ 1145 +#define F_TIME_GE 1105 +#define F_TIME_GT 1104 +#define F_TIME_HASH 1688 +#define F_TIME_IN TIMEINFUNCOID +#define F_TIME_LARGER 1377 +#define F_TIME_LE 1103 +#define F_TIME_LT 1102 +#define F_TIME_MI_INTERVAL 1748 +#define F_TIME_MI_TIME 1690 +#define F_TIME_NE 1106 +#define F_TIME_OUT TIMEOUTFUNCOID +#define F_TIME_PL_INTERVAL 1747 +#define F_TIME_RECV 2470 +#define F_TIME_SEND 2471 +#define F_TIME_SMALLER 1378 +#define F_TIME_TRANSFORM 3944 +#define F_TIMEMI 245 +#define F_TIMENOW TIMENOWFUNCOID +#define F_TIMEOFDAY 274 +#define F_TIMEPL 244 +#define F_TIMESTAMP_SCALE 1961 +#define F_ABSTIME_TIMESTAMP ABSTIMETIMESTAMPFUNCOID +#define F_DATE_TIMESTAMP 2024 +#define F_TIMESTAMPTZ_TIMESTAMP TIMESTAMPTZ2TIMESTAMPFUNCOID +#define F_TIMESTAMP_CMP 2045 +#define F_TIMESTAMP_CMP_DATE 2370 +#define F_TIMESTAMP_CMP_TIMESTAMPTZ TIMESTAMPCMPTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_DIFF 3227 +#define F_TIMESTAMP_EQ 2052 +#define F_TIMESTAMP_EQ_DATE 2366 +#define F_TIMESTAMP_EQ_TIMESTAMPTZ TIMESTAMPEQTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_GE 2056 +#define F_TIMESTAMP_GE_DATE 2368 +#define F_TIMESTAMP_GE_TIMESTAMPTZ TIMESTAMPGETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_GT 2057 +#define F_TIMESTAMP_GT_DATE 2367 +#define F_TIMESTAMP_GT_TIMESTAMPTZ TIMESTAMPGTTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_HASH TIMESTAMPHASHOID +#define F_TIMESTAMP_IN TIMESTAMPINFUNCOID +#define F_TIMESTAMP_LARGER 2036 +#define F_TIMESTAMP_LE 2055 +#define F_TIMESTAMP_LE_DATE 2365 +#define F_TIMESTAMP_LE_TIMESTAMPTZ TIMESTAMPLETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_LIST_AGG_NOARG2_TRANSFN 3585 +#define F_TIMESTAMP_LIST_AGG_TRANSFN 3583 +#define F_TIMESTAMP_LT 2054 +#define F_TIMESTAMP_LT_DATE 2364 +#define F_TIMESTAMP_LT_TIMESTAMPTZ TIMESTAMPLTTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_MI 2031 +#define F_TIMESTAMP_MI_INTERVAL 2033 +#define F_TIMESTAMP_NE 2053 +#define F_TIMESTAMP_NE_DATE 2369 +#define F_TIMESTAMP_NE_TIMESTAMPTZ TIMESTAMPNETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_OUT TIMESTAMPOUTFUNCOID +#define F_TIMESTAMP_PL_INTERVAL 2032 +#define F_TIMESTAMP_RECV 2474 +#define F_TIMESTAMP_SEND 2475 +#define F_TIMESTAMP_SMALLER 2035 +#define F_TIMESTAMP_SORTSUPPORT 3137 +#define F_TIMESTAMP_TEXT 4178 +#define F_TIMESTAMP_TRANSFORM 3917 +#define F_TIMESTAMP_VARCHAR 4179 +#define F_TIMESTAMPTYPMODIN 2905 +#define F_TIMESTAMPTYPMODOUT 2906 +#define F_ABSTIME_TIMESTAMPTZ 1173 +#define F_DATE_TIMESTAMPTZ DATETIMESTAMPTZFUNCOID +#define F_TIMESTAMPTZ_SCALE 1967 +#define F_TIMESTAMP_TIMESTAMPTZ TIMESTAMP2TIMESTAMPTZFUNCOID +#define F_TIMESTAMPTZ_CMP_DATE TIMESTAMPTZCMPDATEFUNCOID +#define F_TIMESTAMPTZ_CMP_TIMESTAMP TIMESTAMPTZCMPTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_EQ_DATE TIMESTAMPTZEQDATEFUNCOID +#define F_TIMESTAMPTZ_EQ_TIMESTAMP TIMESTAMPTZEQTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_GE_DATE TIMESTAMPTZGEDATEFUNCOID +#define F_TIMESTAMPTZ_GE_TIMESTAMP TIMESTAMPTZGETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_GT_DATE TIMESTAMPTZGTDATEFUNCOID +#define F_TIMESTAMPTZ_GT_TIMESTAMP TIMESTAMPTZGTTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_IN TIMESTAMPTZINFUNCOID +#define F_TIMESTAMPTZ_LE_DATE TIMESTAMPTZLEDATEFUNCOID +#define F_TIMESTAMPTZ_LE_TIMESTAMP TIMESTAMPTZLETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_LIST_AGG_NOARG2_TRANSFN 3589 +#define F_TIMESTAMPTZ_LIST_AGG_TRANSFN 3587 +#define F_TIMESTAMPTZ_LT_DATE TIMESTAMPTZLTDATEFUNCOID +#define F_TIMESTAMPTZ_LT_TIMESTAMP TIMESTAMPTZLTTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_MI_INTERVAL TIMESTAMPTZMIINTERVALFUNCOID +#define F_TIMESTAMPTZ_NE_DATE TIMESTAMPTZNEDATEFUNCOID +#define F_TIMESTAMPTZ_NE_TIMESTAMP TIMESTAMPTZNETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_OUT TIMESTAMPTZOUTFUNCOID +#define F_TIMESTAMPTZ_PL_INTERVAL TIMESTAMPTZPLINTERVALFUNCOID +#define F_TIMESTAMPTZ_RECV 2476 +#define F_TIMESTAMPTZ_SEND 2477 +#define F_TIMESTAMPTZTYPMODIN 2907 +#define F_TIMESTAMPTZTYPMODOUT 2908 +#define F_TIMESTAMPZONE_TEXT 4177 +#define F_TIMETYPMODIN 2909 +#define F_TIMETYPMODOUT 2910 +#define F_TIMESTAMPTZ_TIMETZ TIMESTAMPTZ2TIMETZFUNCOID +#define F_TIMETZ_SCALE 1969 +#define F_TIME_TIMETZ TIME2TIMETZFUNCOID +#define F_TIMETZ_CMP 1358 +#define F_TIMETZ_EQ 1352 +#define F_TIMETZ_GE 1356 +#define F_TIMETZ_GT 1357 +#define F_TIMETZ_HASH 1696 +#define F_TIMETZ_IN TIMETZINFUNCOID +#define F_TIMETZ_LARGER 1379 +#define F_TIMETZ_LE 1355 +#define F_TIMETZ_LT 1354 +#define F_TIMETZ_MI_INTERVAL 1750 +#define F_TIMETZ_NE 1353 +#define F_TIMETZ_OUT 1351 +#define F_TIMETZ_PL_INTERVAL 1749 +#define F_TIMETZ_RECV 2472 +#define F_TIMETZ_SEND 2473 +#define F_TIMETZ_SMALLER 1380 +#define F_TIMETZTYPMODIN 2911 +#define F_TIMETZTYPMODOUT 2912 +#define F_TIMESTAMPTZ_IZONE 1026 +#define F_TIMESTAMPTZ_ZONE 1159 +#define F_TIMETZ_ZONE TIMEZONETZFUNCOID +#define F_TIMETZ_IZONE 2038 +#define F_TIMESTAMP_ZONE 2069 +#define F_TIMESTAMP_IZONE 2070 +#define F_TINTERVALCT 264 +#define F_TINTERVALEND 273 +#define F_TINTERVALEQ 784 +#define F_TINTERVALGE 789 +#define F_TINTERVALGT 787 +#define F_TINTERVALIN TINTERVALINFUNCOID +#define F_TINTERVALLE 788 +#define F_TINTERVALLENEQ 266 +#define F_TINTERVALLENGE 271 +#define F_TINTERVALLENGT 269 +#define F_TINTERVALLENLE 270 +#define F_TINTERVALLENLT 268 +#define F_TINTERVALLENNE 267 +#define F_TINTERVALLT 786 +#define F_TINTERVALNE 785 +#define F_TINTERVALOUT TINTERVALOUTFUNCOID +#define F_TINTERVALOV 265 +#define F_TINTERVALRECV 2466 +#define F_TINTERVALREL 249 +#define F_TINTERVALSAME 263 +#define F_TINTERVALSEND 2467 +#define F_TINTERVALSTART 272 +#define F_TO_ASCII_DEFAULT 1845 +#define F_TO_ASCII_ENC 1846 +#define F_TO_ASCII_ENCNAME 1847 +#define F_INTERVAL_TO_CHAR INTERVALTOCHARFUNCOID +#define F_TIMESTAMPTZ_TO_CHAR TIMESTAMPTZ2CHARFUNCOID +#define F_NUMERIC_TO_CHAR NUMERIC2CHARFUNCOID +#define F_INT4_TO_CHAR INTEGER2CHARFUNCOID +#define F_INT8_TO_CHAR BIGINT2CHARFUNCOID +#define F_FLOAT4_TO_CHAR FLOAT4TOCHARFUNCOID +#define F_FLOAT8_TO_CHAR FLOAT8TOCHARFUNCOID +#define F_TIMESTAMP_TO_CHAR TIMESTAMP2CHARFUNCOID +#define F_TIMESTAMP_TO_CHAR_DEFAULT_FORMAT DEFAULTFORMATTIMESTAMP2CHARFUNCOID +#define F_TIMESTAMPTZ_TO_CHAR_DEFAULT_FORMAT DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID +#define F_TO_TIMESTAMP TODATEFUNCOID +#define F_TO_DATE_DEFAULT_FORMAT TODATEDEFAULTFUNCOID +#define F_TO_HEX32 2089 +#define F_TO_HEX64 2090 +#define F_NUMERIC_TO_NUMBER TONUMBERFUNCOID +#define F_TO_TIMESTAMP_DEFAULT_FORMAT TOTIMESTAMPDEFAULTFUNCOID +#define F_TO_TSQUERY_BYID 3746 +#define F_TO_TSQUERY 3750 +#define F_TO_TSVECTOR_BYID 3745 +#define F_TO_TSVECTOR 3749 +#define F_TOP_KEY_INTERNAL 6008 +#define F_TOTAL_CPU 3976 +#define F_TOTAL_MEMORY 3979 +#define F_TRACK_MEMORY_CONTEXT 3988 +#define F_TRACK_MEMORY_CONTEXT_DETAIL 3990 +#define F_TRACK_MODEL_TRAIN_OPT 3468 +#define F_TRANSLATE 878 +#define F_TRIGGER_IN 2300 +#define F_TRIGGER_OUT 2301 +#define F_MACADDR_TRUNC 753 +#define F_NUMERIC_TRUNC 1709 +#define F_TS_HEADLINE_BYID_OPT 3743 +#define F_TS_HEADLINE_BYID 3744 +#define F_TS_HEADLINE_OPT 3754 +#define F_TS_HEADLINE 3755 +#define F_TS_LEXIZE 3723 +#define F_TS_MATCH_QV 3635 +#define F_TS_MATCH_TQ 3761 +#define F_TS_MATCH_TT 3760 +#define F_TS_MATCH_VQ 3634 +#define F_TS_PARSE_BYID 3715 +#define F_TS_PARSE_BYNAME 3716 +#define F_TS_RANK_WTTF 3703 +#define F_TS_RANK_WTT 3704 +#define F_TS_RANK_TTF 3705 +#define F_TS_RANK_TT 3706 +#define F_TS_RANKCD_WTTF 3707 +#define F_TS_RANKCD_WTT 3708 +#define F_TS_RANKCD_TTF 3709 +#define F_TS_RANKCD_TT 3710 +#define F_TSQUERY_REWRITE 3684 +#define F_TSQUERY_REWRITE_QUERY 3685 +#define F_TS_STAT1 3689 +#define F_TS_STAT2 3690 +#define F_TS_TOKEN_TYPE_BYID 3713 +#define F_TS_TOKEN_TYPE_BYNAME 3714 +#define F_TS_TYPANALYZE 3688 +#define F_TSMATCHJOINSEL 3687 +#define F_TSMATCHSEL 3686 +#define F_TSQ_MCONTAINED 3692 +#define F_TSQ_MCONTAINS 3691 +#define F_TSQUERY_AND 3669 +#define F_TSQUERY_CMP 3668 +#define F_TSQUERY_EQ 3664 +#define F_TSQUERY_GE 3666 +#define F_TSQUERY_GT 3667 +#define F_TSQUERY_LE 3663 +#define F_TSQUERY_LT 3662 +#define F_TSQUERY_NE 3665 +#define F_TSQUERY_NOT 3671 +#define F_TSQUERY_OR 3670 +#define F_TSQUERYIN 3612 +#define F_TSQUERYOUT 3613 +#define F_TSQUERYRECV 3641 +#define F_TSQUERYSEND 3640 +#define F_TSRANGE_SUBDIFF 3929 +#define F_TSTZRANGE_SUBDIFF 3930 +#define F_TSVECTOR_CMP 3622 +#define F_TSVECTOR_CONCAT 3625 +#define F_TSVECTOR_EQ 3618 +#define F_TSVECTOR_GE 3620 +#define F_TSVECTOR_GT 3621 +#define F_TSVECTOR_LE 3617 +#define F_TSVECTOR_LT 3616 +#define F_TSVECTOR_NE 3619 +#define F_TSVECTOR_UPDATE_TRIGGER_BYID 3752 +#define F_TSVECTOR_UPDATE_TRIGGER_BYCOLUMN 3753 +#define F_TSVECTORIN 3610 +#define F_TSVECTOROUT 3611 +#define F_TSVECTORRECV 3639 +#define F_TSVECTORSEND 3638 +#define F_TXID_CURRENT 2943 +#define F_TXID_CURRENT_SNAPSHOT 2944 +#define F_TXID_SNAPSHOT_IN 2939 +#define F_TXID_SNAPSHOT_OUT 2940 +#define F_TXID_SNAPSHOT_RECV 2941 +#define F_TXID_SNAPSHOT_SEND 2942 +#define F_TXID_SNAPSHOT_XIP 2947 +#define F_TXID_SNAPSHOT_XMAX 2946 +#define F_TXID_SNAPSHOT_XMIN 2945 +#define F_TXID_VISIBLE_IN_SNAPSHOT 2948 +#define F_UNIQUE_KEY_RECHECK 1250 +#define F_UNKNOWNIN 109 +#define F_UNKNOWNOUT 110 +#define F_UNKNOWNRECV 2416 +#define F_UNKNOWNSEND 2417 +#define F_ARRAY_UNNEST 2331 +#define F_SYN_UPDATE_PG_JOB 3998 +#define F_UPPER 871 +#define F_RANGE_UPPER 3849 +#define F_RANGE_UPPER_INC 3852 +#define F_RANGE_UPPER_INF 3854 +#define F_UUID_CMP 2960 +#define F_UUID_EQ 2956 +#define F_UUID_GE 2957 +#define F_UUID_GT 2958 +#define F_UUID_HASH 2963 +#define F_UUID_IN 2952 +#define F_UUID_LE 2955 +#define F_UUID_LT 2954 +#define F_UUID_NE 2959 +#define F_UUID_OUT 2953 +#define F_UUID_RECV 2961 +#define F_UUID_SEND 2962 +#define F_VARBIT 1687 +#define F_VARBIT_IN 1579 +#define F_VARBIT_OUT 1580 +#define F_VARBIT_RECV 2458 +#define F_VARBIT_SEND 2459 +#define F_VARBIT_TRANSFORM 3158 +#define F_VARBITTYPMODIN 2902 +#define F_VARBITTYPMODOUT 2921 +#define F_VARCHAR 669 +#define F_VARCHAR_DATE 4162 +#define F_VARCHAR_FLOAT4 4198 +#define F_VARCHAR_FLOAT8 4199 +#define F_VARCHAR_INT4 4174 +#define F_VARCHAR_INT8 4176 +#define F_VARCHAR_NUMERIC 4173 +#define F_VARCHAR_TIMESTAMP 4186 +#define F_VARCHAR_TRANSFORM 3097 +#define F_VARCHARIN 1046 +#define F_VARCHAROUT 1047 +#define F_VARCHARRECV 2432 +#define F_VARCHARSEND 2433 +#define F_VARCHARTYPMODIN 2915 +#define F_VARCHARTYPMODOUT 2916 +#define F_PGSQL_VERSION 89 +#define F_VOID_IN 2298 +#define F_VOID_OUT 2299 +#define F_VOID_RECV 3120 +#define F_VOID_SEND 3121 +#define F_WDR_XDB_QUERY 5713 +#define F_BOX_WIDTH 976 +#define F_WIDTH_BUCKET_FLOAT8 320 +#define F_WIDTH_BUCKET_NUMERIC 2170 +#define F_WORKING_VERSION_NUM 5731 +#define F_XIDEQ 68 +#define F_XIDEQ4 71 +#define F_XIDIN 50 +#define F_XIDIN4 58 +#define F_XIDLT 1320 +#define F_XIDLT4 1322 +#define F_XIDOUT 51 +#define F_XIDOUT4 59 +#define F_XIDRECV 2440 +#define F_XIDRECV4 2779 +#define F_XIDSEND 2441 +#define F_XIDSEND4 2780 +#define F_TEXTTOXML 2896 +#define F_XML_IN 2893 +#define F_XML_IS_WELL_FORMED 3051 +#define F_XML_IS_WELL_FORMED_CONTENT 3053 +#define F_XML_IS_WELL_FORMED_DOCUMENT 3052 +#define F_XML_OUT 2894 +#define F_XML_RECV 2898 +#define F_XML_SEND 2899 +#define F_XMLCOMMENT 2895 +#define F_XMLCONCAT2 2900 +#define F_XMLEXISTS 2614 +#define F_XMLVALIDATE 2897 +#define F_XPATH 2931 +#define F_XPATH_EXISTS 3049 +#define F_ZHPRS_END 3794 +#define F_ZHPRS_GETLEXEME 3793 +#define F_ZHPRS_LEXTYPE 3795 +#define F_ZHPRS_START 3792 + +#define nBuiltinFuncs 3155 + +#define NFMGRFUNCS 3105 + +#endif /* FMGROIDS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/fmgrtab.h postgresql-hll-2.14/include/include/utils/fmgrtab.h --- postgresql-hll-2.14_old/include/include/utils/fmgrtab.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/fmgrtab.h 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,204 @@ +/* ------------------------------------------------------------------------- + * + * fmgrtab.h + * The function manager's table of internal functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/fmgrtab.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FMGRTAB_H +#define FMGRTAB_H + +#include "fmgr.h" +#include "catalog/genbki.h" +#include "catalog/pg_proc.h" +#include "c.h" +#include "utils/fmgroids.h" + +/* + * This table stores info about all the built-in functions (ie, functions + * that are compiled into the Postgres executable). The table entries are + * required to appear in Oid order, so that binary search can be used. + */ + +typedef struct { + Oid foid; /* OID of the function */ + const char* funcName; /* C name of the function */ + short nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable count */ + bool strict; /* T if function is "strict" */ + bool retset; /* T if function returns a set */ + PGFunction func; /* pointer to compiled function */ + Oid rettype; // OID of result type +} FmgrBuiltin; + +/* This table stores all info of all builtin function. It inherits from FmgrBuiltin, but + * unlike FmgrBuiltin, its table entries are required to be ordered by funcName, so that + * binary search on funcName can be used when accessing the function info by function name. + * Caution: the order of argmentes in the strunct cannot be changed!*/ +typedef struct { + Oid foid; /* [ 0] */ + const char* funcName; /* [ 1] C name of the function or procedure name */ + int2 nargs; /* [ 2] number of arguments, 0..FUNC_MAX_ARGS, or -1 if variable count */ + bool strict; /* [ 3] strict with respect to NULLs? */ + bool retset; /* [ 4] returns a set? */ + PGFunction func; /* [ 5] pointer to compiled function */ + Oid rettype; /* [ 6] OID of result type */ + Oid pronamespace; /* [ 7] OID of namespace containing this proc */ + Oid proowner; /* [ 8] procedure owner */ + Oid prolang; /* [ 9] OID of pg_language entry, 12 for internal, 14 for SQL statement */ + float4 procost; /* [10] estimated execution cost */ + float4 prorows; /* [11] estimated # of rows out (if proretset) */ + Oid provariadic; /* [12] element type of variadic array, or 0 */ + regproc protransform; /* [13] transforms calls to it during planning */ + bool proisagg; /* [14] is it an aggregate? */ + bool proiswindow; /* [15] is it a window function? */ + bool prosecdef; /* [16] security definer */ + bool proleakproof; /* [17] is it a leak-proof function? */ + char provolatile; /* [18] see PROVOLATILE_ categories below */ + int2 pronargdefaults; /* [19] number of arguments with defaults */ + + /* variable-length fields start here */ + ArrayOid proargtypes; /* [20] parameter types (excludes OUT params) */ + + /* nullable fields start here, they are defined by pointer, if one of them + * is null pointer, it means it has SQL NULL value */ + ArrayOid* proallargtypes; /* [21] all param types (NULL if IN only) */ + ArrayChar* proargmodes; /* [22] parameter modes (NULL if IN only) */ + ArrayCStr* proargnames; /* [23] parameter names (NULL if no names) */ + const char* proargdefaults; /* [24] list of expression trees for argument defaults (NULL if none) */ + const char* prosrc; /* [25] procedure source text */ + const char* probin; /* [26] secondary procedure info (can be NULL) */ + ArrayCStr* proconfig; /* [27] procedure-local GUC settings */ + ArrayAcl* proacl; /* [28] access permissions */ + ArrayInt2* prodefaultargpos; /* [29] */ + bool* fencedmode; /* [30] */ + bool* proshippable; /* [31] if provolatile is not 'i', proshippable will determine if the func can be shipped */ + bool* propackage; /* [32] */ + const char* descr; /* [33] description */ + char prokind; /* [34] f:function, p:procedure*/ +} Builtin_func; + +/* The function has the same names are put in one group */ +typedef struct { + const char* funcName; + int fnums; /* number of functions in this group */ + Builtin_func* funcs; +} FuncGroup; + +static_assert(sizeof(NULL) == sizeof(void*), "NULL must be a 8 byte-length pointer"); + +/* is null indicator? NULL pointer has size 8 */ +#define isnull_indicator(ind) (sizeof(ind) == sizeof(NULL)) + +/* get the number of arguments from a indicator */ +#define GET_ARGNUMS(ind) DatumGetInt32((Datum)ind) + +#define _SetField(field, value) .field = value +#define _SetPointerField(field, ind, value) .field = (isnull_indicator(ind) ? NULL : (value)) + +/* The following _i(value) Macro is used to set the i-th field of Builtin_func */ +#define _0(funcid) _SetField(foid, funcid) +#define _1(fname) _SetField(funcName, fname) +#define _2(fnargs) _SetField(nargs, fnargs) +#define _3(is_strict) _SetField(strict, is_strict) +#define _4(is_retset) _SetField(retset, is_retset) +#define _5(func_ptr) _SetField(func, func_ptr) +#define _6(ret_oid_type) _SetField(rettype, ret_oid_type) +#define _7(namespace_oid) _SetField(pronamespace, namespace_oid) +#define _8(owner_oid) _SetField(proowner, owner_oid) +#define _9(lang_oid) _SetField(prolang, lang_oid) +#define _10(cost) _SetField(procost, cost) +#define _11(rows) _SetField(prorows, rows) +#define _12(vari_oid) _SetField(provariadic, vari_oid) +#define _13(tansf_oid) _SetField(protransform, tansf_oid) +#define _14(is_agg) _SetField(proisagg, is_agg) +#define _15(is_window) _SetField(proiswindow, is_window) +#define _16(is_secdef) _SetField(prosecdef, is_secdef) +#define _17(is_leakproof) _SetField(proleakproof, is_leakproof) + +/* the set provolatile field, 'i', 's', 'v' */ +#define _18(volt_type) _SetField(provolatile, volt_type) + +#define _19(nargdefaults) _SetField(pronargdefaults, nargdefaults) + +/* Set the value for proargtypes, which is an array, The argument cnt of the Macro + * means the number of elements that are used to initialize the array, + * e.g., _20(3, oid1, oid2, oid3), means the array field hash 3 elements oid1, oid2, and oid3 */ +#define _20(cnt, ...) _SetField(proargtypes, MakeArrayOid(cnt, __VA_ARGS__)) + +/* The following Macros are used for initializing nullable fields. + * For an array field, its initializer is like _xx(ind_cnt, ...), e.g., _21, _22, + * it has two ways to initialize the fields: + * _xx(NULL): indicates the array field is NULL + * _xx(3, e1, e2, e3): indicates the fields is a 3-elements array. + * + * For a single-value field, its initializer is like _xx(ind_ff), e.g., _30, _31, + * it has also two ways to initialize the fields: + * _xx(NULL): indicates the field is NULL + * _xx(fvalue): means the field has the value *fvalue* + * */ +/* Set the proallargtypes field. The input must be an array of Oids, e.g., _21(4, oid1, oid2, oid3, oid4) */ +#define _21(ind_cnt, ...) _SetPointerField(proallargtypes, ind_cnt, MakeArrayOidPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* Set the proargmodes field, The input must be an array of chars: 'i', 'o', 'b', 'v', 't' + * the usage is: _22(3, 'i', 'b', 'o') */ +#define _22(ind_cnt, ...) _SetPointerField(proargmodes, ind_cnt, MakeArrayCharPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* The input must be an array of c-string, e.g., _23(3, "argname1", "argname2", "argname3") */ +#define _23(ind_cnt, ...) _SetPointerField(proargnames, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +#define _24(arg_default_expr_str) _SetField(proargdefaults, arg_default_expr_str) +#define _25(proc_src) _SetField(prosrc, proc_src) +#define _26(bin_info) _SetField(probin, bin_info) + +#define _27(ind_cnt, ...) _SetPointerField(proconfig, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) +#define _28(ind_cnt, ...) _SetPointerField(proacl, ind_cnt, MakeArrayInt4Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) +#define _29(ind_cnt, ...) \ + _SetPointerField(prodefaultargpos, ind_cnt, MakeArrayInt2Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* .fencedmode = ((ind_fmode) == NVL ? NULL : (bool[1]) { ind_fmode }) */ +#define _30(ind_fmode) _SetPointerField(fencedmode, ind_fmode, MakeSingleValuePtr(bool, ind_fmode)) +#define _31(ind_shippable) _SetPointerField(proshippable, ind_shippable, MakeSingleValuePtr(bool, ind_shippable)) +#define _32(ind_is_pkg) _SetPointerField(propackage, ind_is_pkg, MakeSingleValuePtr(bool, ind_is_pkg)) +#define _33(desc_str) _SetField(descr, desc_str) +#define _34(c_prokind) _SetField(prokind, c_prokind) +/* Use Marcos _index() to initialize a built-in function, the indices between 0 ~ 20 are necessary, + * and indices between 21 ~ 32 are optional */ +#define AddBuiltinFunc(...) \ + { \ + __VA_ARGS__ \ + } + +#define AddFuncGroup(groupName, nelem, ...) \ + { \ + .funcName = groupName, .fnums = nelem, .funcs = (Builtin_func[nelem]) \ + { \ + __VA_ARGS__ \ + } \ + } + +extern const FmgrBuiltin fmgr_builtins[]; +extern const FmgrBuiltin* fmgr_isbuiltin(Oid id); + +extern const int fmgr_nbuiltins; /* number of entries in table */ + +/* Store all built-in functions ordered by function oid. Actually, it stores the + * function pointers to g_func_groups for saving memories. */ +extern const Builtin_func* g_sorted_funcs[nBuiltinFuncs]; +extern const FmgrBuiltin* g_fmgr_sorted_builtins[NFMGRFUNCS]; + +/* Store all built-in functions, that are grouped by function name in alphabetical + * order with lower case comparison (see pg_strcasecmp). */ +extern FuncGroup g_func_groups[]; + +extern const int g_nfuncgroups; /* number of function groups */ + +void initBuiltinFuncs(); + +const FuncGroup* SearchBuiltinFuncByName(const char* funcname); +const Builtin_func* SearchBuiltinFuncByOid(Oid id); +#endif /* FMGRTAB_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/formatting.h postgresql-hll-2.14/include/include/utils/formatting.h --- postgresql-hll-2.14_old/include/include/utils/formatting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/formatting.h 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,143 @@ +/* ----------------------------------------------------------------------- + * formatting.h + * + * src/include/utils/formatting.h + * + * + * Portions Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * The PostgreSQL routines for a DateTime/int/float/numeric formatting, + * inspire with A db TO_CHAR() / TO_DATE() / TO_NUMBER() routines. + * + * Karel Zak + * + * ----------------------------------------------------------------------- + */ + +#ifndef _FORMATTING_H_ +#define _FORMATTING_H_ + +#include "fmgr.h" + +#define NUM_CACHE_SIZE 64 +#define NUM_CACHE_FIELDS 16 +#define DCH_CACHE_SIZE 128 +#define DCH_CACHE_FIELDS 16 + +/* ---------- + * FromCharDateMode + * ---------- + * + * This value is used to nominate one of several distinct (and mutually + * exclusive) date conventions that a keyword can belong to. + */ +typedef enum { + FROM_CHAR_DATE_NONE = 0, /* Value does not affect date mode. */ + FROM_CHAR_DATE_GREGORIAN, /* Gregorian (day, month, year) style date */ + FROM_CHAR_DATE_ISOWEEK /* ISO 8601 week date */ +} FromCharDateMode; + +typedef struct { + const char* name; + int len; + int id; + bool is_digit; + FromCharDateMode date_mode; +} KeyWord; + +/* ---------- + * Number description struct + * ---------- + */ +typedef struct { + int pre, /* (count) numbers before decimal */ + post, /* (count) numbers after decimal */ + lsign, /* want locales sign */ + flag, /* number parameters */ + pre_lsign_num, /* tmp value for lsign */ + multi, /* multiplier for 'V' */ + zero_start, /* position of first zero */ + zero_end, /* position of last zero */ + need_locale; /* needs it locale */ +} NUMDesc; + +typedef struct FormatNode { + int type; /* node type */ + const KeyWord* key; /* if node type is KEYWORD */ + char character; /* if node type is CHAR */ + int suffix; /* keyword suffix */ +} FormatNode; + +typedef struct DCHCacheEntry { + FormatNode format[DCH_CACHE_SIZE + 1]; + char str[DCH_CACHE_SIZE + 1]; + int age; +} DCHCacheEntry; + +typedef struct NUMCacheEntry { + FormatNode format[NUM_CACHE_SIZE + 1]; + char str[NUM_CACHE_SIZE + 1]; + int age; + NUMDesc Num; +} NUMCacheEntry; + +extern char* str_tolower(const char* buff, size_t nbytes, Oid collid); +extern char* str_toupper(const char* buff, size_t nbytes, Oid collid); +extern char* str_toupper_for_raw(const char* buff, size_t nbytes, Oid collid); +extern char* str_initcap(const char* buff, size_t nbytes, Oid collid); + +extern char* asc_tolower(const char* buff, size_t nbytes); +extern char* asc_toupper(const char* buff, size_t nbytes); +extern char* asc_initcap(const char* buff, size_t nbytes); + +extern Datum timestamp_to_char(PG_FUNCTION_ARGS); +extern Datum timestamptz_to_char(PG_FUNCTION_ARGS); +extern Datum interval_to_char(PG_FUNCTION_ARGS); +extern Datum to_timestamp(PG_FUNCTION_ARGS); +extern Datum to_date(PG_FUNCTION_ARGS); +extern Datum numeric_to_number(PG_FUNCTION_ARGS); +extern Datum numeric_to_char(PG_FUNCTION_ARGS); +extern Datum int4_to_char(PG_FUNCTION_ARGS); +extern Datum int8_to_char(PG_FUNCTION_ARGS); +extern Datum float4_to_char(PG_FUNCTION_ARGS); +extern Datum float8_to_char(PG_FUNCTION_ARGS); +#include "pgtime.h" +#include "datatype/timestamp.h" +extern Datum to_timestamp_default_format(PG_FUNCTION_ARGS); +typedef struct TmToChar { + struct pg_tm tm; /* classic 'tm' struct */ + fsec_t fsec; /* fractional seconds */ + const char* tzn; /* timezone */ +} TmToChar; +#define tmtcTm(_X) (&(_X)->tm) +#define tmtcTzn(_X) ((_X)->tzn) +#define tmtcFsec(_X) ((_X)->fsec) + +extern void Init_NUM_cache(void); + +#define ZERO_tm(_X) \ + do { \ + (_X)->tm_sec = (_X)->tm_year = (_X)->tm_min = (_X)->tm_wday = (_X)->tm_hour = (_X)->tm_yday = (_X)->tm_isdst = \ + 0; \ + (_X)->tm_mday = (_X)->tm_mon = 1; \ + } while (0) + +#define ZERO_tmtc(_X) \ + do { \ + ZERO_tm(tmtcTm(_X)); \ + tmtcFsec(_X) = 0; \ + tmtcTzn(_X) = NULL; \ + } while (0) +extern Datum timestamp_to_char_default_format(PG_FUNCTION_ARGS); +extern Datum timestamptz_to_char_default_format(PG_FUNCTION_ARGS); +extern text* datetime_to_char_body(TmToChar* tmtc, text* fmt, bool is_interval, Oid collid); + +extern void check_datetime_format(char* fmt); +extern void* get_time_format(char* fmt_str); +extern void to_timestamp_from_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* format); +#ifdef ENABLE_UT +extern void general_to_timestamp_from_user_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* in_format); +extern void optimized_to_timestamp_from_user_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* in_format); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/geo_decls.h postgresql-hll-2.14/include/include/utils/geo_decls.h --- postgresql-hll-2.14_old/include/include/utils/geo_decls.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/geo_decls.h 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,420 @@ +/* ------------------------------------------------------------------------- + * + * geo_decls.h - Declarations for various 2D constructs. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/geo_decls.h + * + * NOTE + * These routines do *not* use the float types from adt/. + * + * XXX These routines were not written by a numerical analyst. + * + * XXX I have made some attempt to flesh out the operators + * and data types. There are still some more to do. - tgl 97/04/19 + * + * ------------------------------------------------------------------------- + */ +#ifndef GEO_DECLS_H +#define GEO_DECLS_H + +#include + +#include "fmgr.h" + +/* -------------------------------------------------------------------- + * Useful floating point utilities and constants. + * ------------------------------------------------------------------- */ + +#define EPSILON 1.0E-06 + +#ifdef EPSILON +#define FPzero(A) (fabs(A) <= EPSILON) +#define FPeq(A, B) (fabs((A) - (B)) <= EPSILON) +#define FPne(A, B) (fabs((A) - (B)) > EPSILON) +#define FPlt(A, B) ((B) - (A) > EPSILON) +#define FPle(A, B) ((A) - (B) <= EPSILON) +#define FPgt(A, B) ((A) - (B) > EPSILON) +#define FPge(A, B) ((B) - (A) <= EPSILON) +#else +#define FPzero(A) ((A) == 0) +#define FPeq(A, B) ((A) == (B)) +#define FPne(A, B) ((A) != (B)) +#define FPlt(A, B) ((A) < (B)) +#define FPle(A, B) ((A) <= (B)) +#define FPgt(A, B) ((A) > (B)) +#define FPge(A, B) ((A) >= (B)) +#endif + +#define HYPOT(A, B) pg_hypot(A, B) + +/* --------------------------------------------------------------------- + * Point - (x,y) + * ------------------------------------------------------------------- */ +typedef struct { + double x, y; +} Point; + +/* --------------------------------------------------------------------- + * LSEG - A straight line, specified by endpoints. + * ------------------------------------------------------------------- */ +typedef struct { + Point p[2]; + + double m; /* precomputed to save time, not in tuple */ +} LSEG; + +/* --------------------------------------------------------------------- + * PATH - Specified by vertex points. + * ------------------------------------------------------------------- */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 npts; + int32 closed; /* is this a closed polygon? */ + int32 dummy; /* padding to make it double align */ + Point p[FLEXIBLE_ARRAY_MEMBER]; /* variable length array of POINTs */ +} PATH; + +/* --------------------------------------------------------------------- + * LINE - Specified by its general equation (Ax+By+C=0). + * If there is a y-intercept, it is C, which + * incidentally gives a freebie point on the line + * (if B=0, then C is the x-intercept). + * Slope m is precalculated to save time; if + * the line is not vertical, m == A. + * ------------------------------------------------------------------- */ +typedef struct { + double A, B, C; + + double m; +} LINE; + +/* --------------------------------------------------------------------- + * BOX - Specified by two corner points, which are + * sorted to save calculation time later. + * ------------------------------------------------------------------- */ +typedef struct { + Point high, low; /* corner POINTs */ +} BOX; + +/* --------------------------------------------------------------------- + * POLYGON - Specified by an array of doubles defining the points, + * keeping the number of points and the bounding box for + * speed purposes. + * ------------------------------------------------------------------- */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 npts; + BOX boundbox; + Point p[FLEXIBLE_ARRAY_MEMBER]; /* variable length array of POINTs */ +} POLYGON; + +/* --------------------------------------------------------------------- + * CIRCLE - Specified by a center point and radius. + * ------------------------------------------------------------------- */ +typedef struct { + Point center; + double radius; +} CIRCLE; + +/* + * fmgr interface macros + * + * Path and Polygon are toastable varlena types, the others are just + * fixed-size pass-by-reference types. + */ + +#define DatumGetPointP(X) ((Point*)DatumGetPointer(X)) +#define PointPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_POINT_P(n) DatumGetPointP(PG_GETARG_DATUM(n)) +#define PG_RETURN_POINT_P(x) return PointPGetDatum(x) + +#define DatumGetLsegP(X) ((LSEG*)DatumGetPointer(X)) +#define LsegPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_LSEG_P(n) DatumGetLsegP(PG_GETARG_DATUM(n)) +#define PG_RETURN_LSEG_P(x) return LsegPGetDatum(x) + +#define DatumGetPathP(X) ((PATH*)PG_DETOAST_DATUM(X)) +#define DatumGetPathPCopy(X) ((PATH*)PG_DETOAST_DATUM_COPY(X)) +#define PathPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_PATH_P(n) DatumGetPathP(PG_GETARG_DATUM(n)) +#define PG_GETARG_PATH_P_COPY(n) DatumGetPathPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_PATH_P(x) return PathPGetDatum(x) + +#define DatumGetLineP(X) ((LINE*)DatumGetPointer(X)) +#define LinePGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_LINE_P(n) DatumGetLineP(PG_GETARG_DATUM(n)) +#define PG_RETURN_LINE_P(x) return LinePGetDatum(x) + +#define DatumGetBoxP(X) ((BOX*)DatumGetPointer(X)) +#define BoxPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_BOX_P(n) DatumGetBoxP(PG_GETARG_DATUM(n)) +#define PG_RETURN_BOX_P(x) return BoxPGetDatum(x) + +#define DatumGetPolygonP(X) ((POLYGON*)PG_DETOAST_DATUM(X)) +#define DatumGetPolygonPCopy(X) ((POLYGON*)PG_DETOAST_DATUM_COPY(X)) +#define PolygonPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_POLYGON_P(n) DatumGetPolygonP(PG_GETARG_DATUM(n)) +#define PG_GETARG_POLYGON_P_COPY(n) DatumGetPolygonPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_POLYGON_P(x) return PolygonPGetDatum(x) + +#define DatumGetCircleP(X) ((CIRCLE*)DatumGetPointer(X)) +#define CirclePGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_CIRCLE_P(n) DatumGetCircleP(PG_GETARG_DATUM(n)) +#define PG_RETURN_CIRCLE_P(x) return CirclePGetDatum(x) + +/* + * in geo_ops.h + */ + +/* public point routines */ +extern Datum point_in(PG_FUNCTION_ARGS); +extern Datum point_out(PG_FUNCTION_ARGS); +extern Datum point_recv(PG_FUNCTION_ARGS); +extern Datum point_send(PG_FUNCTION_ARGS); +extern Datum construct_point(PG_FUNCTION_ARGS); +extern Datum point_left(PG_FUNCTION_ARGS); +extern Datum point_right(PG_FUNCTION_ARGS); +extern Datum point_above(PG_FUNCTION_ARGS); +extern Datum point_below(PG_FUNCTION_ARGS); +extern Datum point_vert(PG_FUNCTION_ARGS); +extern Datum point_horiz(PG_FUNCTION_ARGS); +extern Datum point_eq(PG_FUNCTION_ARGS); +extern Datum point_ne(PG_FUNCTION_ARGS); +extern Datum point_distance(PG_FUNCTION_ARGS); +extern Datum point_slope(PG_FUNCTION_ARGS); +extern Datum point_add(PG_FUNCTION_ARGS); +extern Datum point_sub(PG_FUNCTION_ARGS); +extern Datum point_mul(PG_FUNCTION_ARGS); +extern Datum point_div(PG_FUNCTION_ARGS); + +/* private routines */ +extern double point_dt(Point* pt1, Point* pt2); +extern double point_sl(Point* pt1, Point* pt2); +extern double pg_hypot(double x, double y); + +/* public lseg routines */ +extern Datum lseg_in(PG_FUNCTION_ARGS); +extern Datum lseg_out(PG_FUNCTION_ARGS); +extern Datum lseg_recv(PG_FUNCTION_ARGS); +extern Datum lseg_send(PG_FUNCTION_ARGS); +extern Datum lseg_intersect(PG_FUNCTION_ARGS); +extern Datum lseg_parallel(PG_FUNCTION_ARGS); +extern Datum lseg_perp(PG_FUNCTION_ARGS); +extern Datum lseg_vertical(PG_FUNCTION_ARGS); +extern Datum lseg_horizontal(PG_FUNCTION_ARGS); +extern Datum lseg_eq(PG_FUNCTION_ARGS); +extern Datum lseg_ne(PG_FUNCTION_ARGS); +extern Datum lseg_lt(PG_FUNCTION_ARGS); +extern Datum lseg_le(PG_FUNCTION_ARGS); +extern Datum lseg_gt(PG_FUNCTION_ARGS); +extern Datum lseg_ge(PG_FUNCTION_ARGS); +extern Datum lseg_construct(PG_FUNCTION_ARGS); +extern Datum lseg_length(PG_FUNCTION_ARGS); +extern Datum lseg_distance(PG_FUNCTION_ARGS); +extern Datum lseg_center(PG_FUNCTION_ARGS); +extern Datum lseg_interpt(PG_FUNCTION_ARGS); +extern Datum dist_pl(PG_FUNCTION_ARGS); +extern Datum dist_ps(PG_FUNCTION_ARGS); +extern Datum dist_ppath(PG_FUNCTION_ARGS); +extern Datum dist_pb(PG_FUNCTION_ARGS); +extern Datum dist_sl(PG_FUNCTION_ARGS); +extern Datum dist_sb(PG_FUNCTION_ARGS); +extern Datum dist_lb(PG_FUNCTION_ARGS); +extern Datum close_lseg(PG_FUNCTION_ARGS); +extern Datum close_pl(PG_FUNCTION_ARGS); +extern Datum close_ps(PG_FUNCTION_ARGS); +extern Datum close_pb(PG_FUNCTION_ARGS); +extern Datum close_sl(PG_FUNCTION_ARGS); +extern Datum close_sb(PG_FUNCTION_ARGS); +extern Datum close_ls(PG_FUNCTION_ARGS); +extern Datum close_lb(PG_FUNCTION_ARGS); +extern Datum on_pl(PG_FUNCTION_ARGS); +extern Datum on_ps(PG_FUNCTION_ARGS); +extern Datum on_pb(PG_FUNCTION_ARGS); +extern Datum on_ppath(PG_FUNCTION_ARGS); +extern Datum on_sl(PG_FUNCTION_ARGS); +extern Datum on_sb(PG_FUNCTION_ARGS); +extern Datum inter_sl(PG_FUNCTION_ARGS); +extern Datum inter_sb(PG_FUNCTION_ARGS); +extern Datum inter_lb(PG_FUNCTION_ARGS); + +/* public line routines */ +extern Datum line_in(PG_FUNCTION_ARGS); +extern Datum line_out(PG_FUNCTION_ARGS); +extern Datum line_recv(PG_FUNCTION_ARGS); +extern Datum line_send(PG_FUNCTION_ARGS); +extern Datum line_interpt(PG_FUNCTION_ARGS); +extern Datum line_distance(PG_FUNCTION_ARGS); +extern Datum line_construct_pp(PG_FUNCTION_ARGS); +extern Datum line_intersect(PG_FUNCTION_ARGS); +extern Datum line_parallel(PG_FUNCTION_ARGS); +extern Datum line_perp(PG_FUNCTION_ARGS); +extern Datum line_vertical(PG_FUNCTION_ARGS); +extern Datum line_horizontal(PG_FUNCTION_ARGS); +extern Datum line_eq(PG_FUNCTION_ARGS); + +/* public box routines */ +extern Datum box_in(PG_FUNCTION_ARGS); +extern Datum box_out(PG_FUNCTION_ARGS); +extern Datum box_recv(PG_FUNCTION_ARGS); +extern Datum box_send(PG_FUNCTION_ARGS); +extern Datum box_same(PG_FUNCTION_ARGS); +extern Datum box_overlap(PG_FUNCTION_ARGS); +extern Datum box_left(PG_FUNCTION_ARGS); +extern Datum box_overleft(PG_FUNCTION_ARGS); +extern Datum box_right(PG_FUNCTION_ARGS); +extern Datum box_overright(PG_FUNCTION_ARGS); +extern Datum box_below(PG_FUNCTION_ARGS); +extern Datum box_overbelow(PG_FUNCTION_ARGS); +extern Datum box_above(PG_FUNCTION_ARGS); +extern Datum box_overabove(PG_FUNCTION_ARGS); +extern Datum box_contained(PG_FUNCTION_ARGS); +extern Datum box_contain(PG_FUNCTION_ARGS); +extern Datum box_contain_pt(PG_FUNCTION_ARGS); +extern Datum box_below_eq(PG_FUNCTION_ARGS); +extern Datum box_above_eq(PG_FUNCTION_ARGS); +extern Datum box_lt(PG_FUNCTION_ARGS); +extern Datum box_gt(PG_FUNCTION_ARGS); +extern Datum box_eq(PG_FUNCTION_ARGS); +extern Datum box_le(PG_FUNCTION_ARGS); +extern Datum box_ge(PG_FUNCTION_ARGS); +extern Datum box_area(PG_FUNCTION_ARGS); +extern Datum box_width(PG_FUNCTION_ARGS); +extern Datum box_height(PG_FUNCTION_ARGS); +extern Datum box_distance(PG_FUNCTION_ARGS); +extern Datum box_center(PG_FUNCTION_ARGS); +extern Datum box_intersect(PG_FUNCTION_ARGS); +extern Datum box_diagonal(PG_FUNCTION_ARGS); +extern Datum points_box(PG_FUNCTION_ARGS); +extern Datum box_add(PG_FUNCTION_ARGS); +extern Datum box_sub(PG_FUNCTION_ARGS); +extern Datum box_mul(PG_FUNCTION_ARGS); +extern Datum box_div(PG_FUNCTION_ARGS); + +/* public path routines */ +extern Datum path_area(PG_FUNCTION_ARGS); +extern Datum path_in(PG_FUNCTION_ARGS); +extern Datum path_out(PG_FUNCTION_ARGS); +extern Datum path_recv(PG_FUNCTION_ARGS); +extern Datum path_send(PG_FUNCTION_ARGS); +extern Datum path_n_lt(PG_FUNCTION_ARGS); +extern Datum path_n_gt(PG_FUNCTION_ARGS); +extern Datum path_n_eq(PG_FUNCTION_ARGS); +extern Datum path_n_le(PG_FUNCTION_ARGS); +extern Datum path_n_ge(PG_FUNCTION_ARGS); +extern Datum path_inter(PG_FUNCTION_ARGS); +extern Datum path_distance(PG_FUNCTION_ARGS); +extern Datum path_length(PG_FUNCTION_ARGS); + +extern Datum path_isclosed(PG_FUNCTION_ARGS); +extern Datum path_isopen(PG_FUNCTION_ARGS); +extern Datum path_npoints(PG_FUNCTION_ARGS); + +extern Datum path_close(PG_FUNCTION_ARGS); +extern Datum path_open(PG_FUNCTION_ARGS); +extern Datum path_add(PG_FUNCTION_ARGS); +extern Datum path_add_pt(PG_FUNCTION_ARGS); +extern Datum path_sub_pt(PG_FUNCTION_ARGS); +extern Datum path_mul_pt(PG_FUNCTION_ARGS); +extern Datum path_div_pt(PG_FUNCTION_ARGS); + +extern Datum path_center(PG_FUNCTION_ARGS); +extern Datum path_poly(PG_FUNCTION_ARGS); + +/* public polygon routines */ +extern Datum poly_in(PG_FUNCTION_ARGS); +extern Datum poly_out(PG_FUNCTION_ARGS); +extern Datum poly_recv(PG_FUNCTION_ARGS); +extern Datum poly_send(PG_FUNCTION_ARGS); +extern Datum poly_left(PG_FUNCTION_ARGS); +extern Datum poly_overleft(PG_FUNCTION_ARGS); +extern Datum poly_right(PG_FUNCTION_ARGS); +extern Datum poly_overright(PG_FUNCTION_ARGS); +extern Datum poly_below(PG_FUNCTION_ARGS); +extern Datum poly_overbelow(PG_FUNCTION_ARGS); +extern Datum poly_above(PG_FUNCTION_ARGS); +extern Datum poly_overabove(PG_FUNCTION_ARGS); +extern Datum poly_same(PG_FUNCTION_ARGS); +extern Datum poly_overlap(PG_FUNCTION_ARGS); +extern Datum poly_contain(PG_FUNCTION_ARGS); +extern Datum poly_contained(PG_FUNCTION_ARGS); +extern Datum poly_contain_pt(PG_FUNCTION_ARGS); +extern Datum pt_contained_poly(PG_FUNCTION_ARGS); +extern Datum poly_distance(PG_FUNCTION_ARGS); +extern Datum poly_npoints(PG_FUNCTION_ARGS); +extern Datum poly_center(PG_FUNCTION_ARGS); +extern Datum poly_box(PG_FUNCTION_ARGS); +extern Datum poly_path(PG_FUNCTION_ARGS); +extern Datum box_poly(PG_FUNCTION_ARGS); + +/* public circle routines */ +extern Datum circle_in(PG_FUNCTION_ARGS); +extern Datum circle_out(PG_FUNCTION_ARGS); +extern Datum circle_recv(PG_FUNCTION_ARGS); +extern Datum circle_send(PG_FUNCTION_ARGS); +extern Datum circle_same(PG_FUNCTION_ARGS); +extern Datum circle_overlap(PG_FUNCTION_ARGS); +extern Datum circle_overleft(PG_FUNCTION_ARGS); +extern Datum circle_left(PG_FUNCTION_ARGS); +extern Datum circle_right(PG_FUNCTION_ARGS); +extern Datum circle_overright(PG_FUNCTION_ARGS); +extern Datum circle_contained(PG_FUNCTION_ARGS); +extern Datum circle_contain(PG_FUNCTION_ARGS); +extern Datum circle_below(PG_FUNCTION_ARGS); +extern Datum circle_above(PG_FUNCTION_ARGS); +extern Datum circle_overbelow(PG_FUNCTION_ARGS); +extern Datum circle_overabove(PG_FUNCTION_ARGS); +extern Datum circle_eq(PG_FUNCTION_ARGS); +extern Datum circle_ne(PG_FUNCTION_ARGS); +extern Datum circle_lt(PG_FUNCTION_ARGS); +extern Datum circle_gt(PG_FUNCTION_ARGS); +extern Datum circle_le(PG_FUNCTION_ARGS); +extern Datum circle_ge(PG_FUNCTION_ARGS); +extern Datum circle_contain_pt(PG_FUNCTION_ARGS); +extern Datum pt_contained_circle(PG_FUNCTION_ARGS); +extern Datum circle_add_pt(PG_FUNCTION_ARGS); +extern Datum circle_sub_pt(PG_FUNCTION_ARGS); +extern Datum circle_mul_pt(PG_FUNCTION_ARGS); +extern Datum circle_div_pt(PG_FUNCTION_ARGS); +extern Datum circle_diameter(PG_FUNCTION_ARGS); +extern Datum circle_radius(PG_FUNCTION_ARGS); +extern Datum circle_distance(PG_FUNCTION_ARGS); +extern Datum dist_pc(PG_FUNCTION_ARGS); +extern Datum dist_cpoly(PG_FUNCTION_ARGS); +extern Datum circle_center(PG_FUNCTION_ARGS); +extern Datum cr_circle(PG_FUNCTION_ARGS); +extern Datum box_circle(PG_FUNCTION_ARGS); +extern Datum circle_box(PG_FUNCTION_ARGS); +extern Datum poly_circle(PG_FUNCTION_ARGS); +extern Datum circle_poly(PG_FUNCTION_ARGS); +extern Datum circle_area(PG_FUNCTION_ARGS); + +/* support routines for the GiST access method (access/gist/gistproc.c) */ +extern Datum gist_box_compress(PG_FUNCTION_ARGS); +extern Datum gist_box_decompress(PG_FUNCTION_ARGS); +extern Datum gist_box_union(PG_FUNCTION_ARGS); +extern Datum gist_box_picksplit(PG_FUNCTION_ARGS); +extern Datum gist_box_consistent(PG_FUNCTION_ARGS); +extern Datum gist_box_penalty(PG_FUNCTION_ARGS); +extern Datum gist_box_same(PG_FUNCTION_ARGS); +extern Datum gist_poly_compress(PG_FUNCTION_ARGS); +extern Datum gist_poly_consistent(PG_FUNCTION_ARGS); +extern Datum gist_circle_compress(PG_FUNCTION_ARGS); +extern Datum gist_circle_consistent(PG_FUNCTION_ARGS); +extern Datum gist_point_compress(PG_FUNCTION_ARGS); +extern Datum gist_point_consistent(PG_FUNCTION_ARGS); +extern Datum gist_point_distance(PG_FUNCTION_ARGS); + +/* geo_selfuncs.c */ +extern Datum areasel(PG_FUNCTION_ARGS); +extern Datum areajoinsel(PG_FUNCTION_ARGS); +extern Datum positionsel(PG_FUNCTION_ARGS); +extern Datum positionjoinsel(PG_FUNCTION_ARGS); +extern Datum contsel(PG_FUNCTION_ARGS); +extern Datum contjoinsel(PG_FUNCTION_ARGS); + +#endif /* GEO_DECLS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/.gitignore postgresql-hll-2.14/include/include/utils/.gitignore --- postgresql-hll-2.14_old/include/include/utils/.gitignore 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/.gitignore 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,3 @@ +errcodes.h +fmgroids.h +probes.h diff -uprN postgresql-hll-2.14_old/include/include/utils/globalplancache.h postgresql-hll-2.14/include/include/utils/globalplancache.h --- postgresql-hll-2.14_old/include/include/utils/globalplancache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/globalplancache.h 2020-12-12 17:06:43.286348541 +0800 @@ -0,0 +1,88 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 2002-2007, PostgreSQL Global Development Group + * + * 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. + * ------------------------------------------------------------------------- + * + * globalplancache.h + * + * IDENTIFICATION + * src/include/utils/globalplancache.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPLANCACHE_H +#define GLOBALPLANCACHE_H + +#include "knl/knl_variable.h" + +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/globalplancore.h" +#include "executor/spi.h" + + +class GlobalPlanCache : public BaseObject +{ +public: + GlobalPlanCache(); + ~GlobalPlanCache(); + + /* global plan cache htab control */ + void Init(); + CachedPlanSource* Fetch(const char *query_string, uint32 query_len, int num_params, SPISign* spi_sign_ptr); + void DropInvalid(); + void AddInvalidList(CachedPlanSource* plansource); + void RemoveEntry(uint32 htblIdx, GPCEntry *entry); + void RemovePlanSourceInRecreate(CachedPlanSource* plansource); + bool TryStore(CachedPlanSource *plansource, PreparedStatement *ps); + Datum PlanClean(); + /* cnretry and pool reload invalid */ + void InvalidPlanSourceForCNretry(CachedPlanSource* plansource); + void InvalidPlanSourceForReload(CachedPlanSource* plansource, char* stmt_name); + + /* cache invalid */ + void InvalMsg(const SharedInvalidationMessage *msgs, int n); + + /* transaction */ + void RecreateCachePlan(PreparedStatement *entry, const char* stmt_name); + void Commit(); + bool CheckRecreateCachePlan(PreparedStatement *entry); + + void CNCommit(); + void DNCommit(); + + /* system function */ + void* GetStatus(uint32 *num); + + static bool MsgCheck(const SharedInvalidationMessage *msg); + static bool NeedDropEntryByLocalMsg(CachedPlanSource* plansource, int tot, const int *idx, const SharedInvalidationMessage *msgs); + static void GetSchemaName(GPCEnv *env); + static void EnvFill(GPCEnv *env, bool depends_on_role); + static void FillClassicEnvSignatures(GPCEnv *env); + static void FillEnvSignatures(GPCEnv *env); + + /* for spi */ + void SPICommit(CachedPlanSource* plansource); + void SPITryStore(CachedPlanSource* plansource, SPIPlanPtr spi_plan, int nth); + bool CheckRecreateSPICachePlan(SPIPlanPtr spi_plan); + void RecreateSPICachePlan(SPIPlanPtr spi_plan); + void RemovePlanCacheInSPIPlan(SPIPlanPtr plan); + +private: + + GPCHashCtl *m_array; + + DList *m_invalid_list; +}; +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/globalplancore.h postgresql-hll-2.14/include/include/utils/globalplancore.h --- postgresql-hll-2.14_old/include/include/utils/globalplancore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/globalplancore.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,273 @@ +/*--------------------------------------------------------------------------------------- + * + * globalplancore.h + * + * global plan cache kernel header + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/utils/globalplancore.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPLANCORE_H +#define GLOBALPLANCORE_H + +#include "executor/spi.h" +#include "executor/spi_priv.h" +#include "knl/knl_variable.h" +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/plancache.h" + +#define GPC_NUM_OF_BUCKETS (128) +#define GPC_HTAB_SIZE (128) +#define GLOBALPLANCACHEKEY_MAGIC (953717831) +#define CAS_SLEEP_DURATION (2) +#define MAX_PREPARE_WAIING_TIME \ + (u_sess->attr.attr_common.SessionTimeout > 1200 ? u_sess->attr.attr_common.SessionTimeout * 2 : 1200 * 2) + +#define ENABLE_GPC (g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) + +#define ENABLE_DN_GPC (IS_PGXC_DATANODE && \ + (!(IS_SINGLE_NODE)) && \ + g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) + +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_CN_GPC (IS_PGXC_COORDINATOR && \ + g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) +#else +#define ENABLE_CN_GPC (g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) +#endif + +typedef enum PGXCNode_HandleGPC +{ + HANDLE_RUN, + HANDLE_FIRST_SEND +} PGXCNode_HandleGPC; + + +typedef struct GPCHashCtl +{ + int count; + int lockId; + HTAB *hash_tbl; + MemoryContext context; +} GPCHashCtl; + +typedef struct GPCPlainEnv +{ + Oid database_id; + uint16 env_signature_pgxc; + // stores the bool GUC parameters + uint32 env_signature; + uint32 env_signature2; + int best_agg_plan; // QUERY_TUNING_METHOD + int query_dop_tmp; // QUERY_TUNING + int rewrite_rule; // QUERY_TUNING + int codegen_strategy; // QUERY_TUNING + int plan_mode_seed; // QUERY_TUNING_METHOD + int effective_cache_size; // QUERY_TUNING_COST + int codegen_cost_threshold; // QUERY_TUNING_COST + int geqo_threshold; // QUERY_TUNING_GEQO + int Geqo_effort; // QUERY_TUNING_GEQO + int Geqo_pool_size; // QUERY_TUNING_GEQO + int Geqo_generations; // QUERY_TUNING_GEQO + int default_statistics_target; // QUERY_TUNING_OTHER + int from_collapse_limit; // QUERY_TUNING_OTHER + int join_collapse_limit; // QUERY_TUNING_OTHER + int cost_param; // QUERY_TUNING_OTHER + int schedule_splits_threshold; // QUERY_TUNING_OTHER + int hashagg_table_size; // QUERY_TUNING_OTHER + int constraint_exclusion; // QUERY_TUNING_OTHER + int qrw_inlist2join_optmode;// QUERY_TUNING_OTHER2 + int skew_strategy_store;// QUERY_TUNING_OTHER2 + unsigned int behavior_compat_flags; + int datestyle; + int dateorder; + int plancachemode; // QUERY_TUNING_OTHER + int sql_beta_feature; // QUERY_TUNING + + double seq_page_cost; // QUERY_TUNING_COST + double random_page_cost; // QUERY_TUNING_COST + double cpu_tuple_cost; // QUERY_TUNING_COST + double allocate_mem_cost; // QUERY_TUNING_COST + double cpu_index_tuple_cost; // QUERY_TUNING_COST + double cpu_operator_cost; // QUERY_TUNING_COST + double stream_multiple; // QUERY_TUNING_COST + double default_limit_rows; // QUERY_TUNING_COST + double Geqo_selection_bias; // QUERY_TUNING_GEQO + double Geqo_seed; // QUERY_TUNING_GEQO + double cursor_tuple_fraction; // QUERY_TUNING_OTHER +}GPCPlainEnv; + +typedef struct GPCEnv +{ + bool filled; + GPCPlainEnv plainenv; + + /* vary name.*/ + int num_params; + struct OverrideSearchPath* search_path; + char schema_name[NAMEDATALEN]; + char expected_computing_nodegroup[NAMEDATALEN]; // QUERY_TUNING_METHOD + char default_storage_nodegroup[NAMEDATALEN]; // QUERY_TUNING_METHOD + /* row security */ + bool depends_on_role; + Oid user_oid; /* only check if has row security */ +} GPCEnv; + +typedef struct GPCKey +{ + uint32 query_length; + const char *query_string; + GPCEnv env; + SPISign spi_signature; +} GPCKey; + +typedef struct GPCVal +{ + CachedPlanSource* plansource; +}GPCVal; + +typedef struct GPCEntry +{ + /* + * We will hash the query_string and its length to find the hash bucket + */ + GPCKey key; + GPCVal val; + +} GPCEntry; + +typedef struct GPCViewStatus +{ + char *query; + //int option; + int refcount; + bool valid; + Oid DatabaseID; + char *schema_name; + int params_num; + Oid func_id; +} GPCViewStatus; + + +/* + * The data structure representing a prepared statement. This is now just + * a thin veneer over a plancache entry --- the main addition is that of + * a name. + * + * Note: all subsidiary storage lives in the referenced plancache entry. + */ +typedef struct PreparedStatement +{ + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + CachedPlanSource *plansource; /* the actual cached plan */ + bool from_sql; /* prepared via SQL, not FE/BE protocol? */ + TimestampTz prepare_time; /* the time when the stmt was prepared */ +} PreparedStatement; + +typedef struct GPCPreparedStatement +{ + sess_orient key; + instr_time last_used_time; + bool sess_detach; + DList* prepare_statement_list; /*the list of the prepare statements of the different queries with the same gid, + *we assume the amount of different prepare statements wont be huge, so we chose + *linked list instead of HTAB*/ +} GPCPreparedStatement; + + +typedef struct GPCPrepareStatus +{ + char *statement_name; + char *query; + int refcount; + uint64 cn_sessid; + uint32 cn_node_id; + uint32 cn_time_line; + bool is_shared; +} GPCPrepareStatus; + +typedef struct TimelineEntry +{ + uint32 node_id; //CN index + uint32 timeline; +} TimelineEntry; + +/* for gpc, help to locate plancache and spiplan */ +typedef struct SPIPlanCacheEnt { + uint32 key; + Oid func_oid; + List* SPIplan_list; + bool is_all_shared; // for gpc, flag for indicate each plancache in this entry is shared + bool is_valid; // invalid or not +} plpgsql_SPIPlanCacheEnt; + +inline uint32 GetBucket(uint32 hashvalue) +{ + return (hashvalue % GPC_NUM_OF_BUCKETS); +} + +extern Datum GPCPlanClean(PG_FUNCTION_ARGS); +extern void GPCResetAll(); +void GPCCleanDatanodeStatement(const CachedPlanSource *plansource, const char* stmt_name); +void GPCReGplan(CachedPlanSource* plansource); +void CNGPCCleanUpSession(); + +/* for HTAB SPICacheTable, global procedure plancache */ +extern SPIPlanCacheEnt* SPIPlanCacheTableLookup(uint32 key); +extern void SPIPlanCacheTableDeletePlan(uint32 key, SPIPlanPtr plan); +extern void SPIPlanCacheTableDelete(uint32 key); +extern void SPIPlanCacheTableDeleteFunc(Oid func_oid); +extern void SPICacheTableInit(); +extern void SPICacheTableInsert(uint32 key, Oid func_oid); +extern void SPICacheTableInsertPlan(uint32 key, SPIPlanPtr spi_plan); +extern uint32 SPICacheHashFunc(const void *key, Size keysize); +/* set unique id for each PLpgSQL_expr in func */ +extern void set_func_expr_unique_id(PLpgSQL_function* func); + +inline void gpc_record_log(const char* action, const char* filename, int lineno, + CachedPlanSource* plansource, const char* stmtname) +{ + ereport(DEBUG3, (errmodule(MOD_GPC), errcode(ERRCODE_LOG), + errmsg("GPC (%lu,%u,%u), (Action:%s, Location %s,%d), (dn_session:%lu), plansource %p, stmt: %s ", + u_sess->sess_ident.cn_sessid, u_sess->sess_ident.cn_timeline, u_sess->sess_ident.cn_nodeid, + action, filename, lineno, u_sess->session_id, plansource, stmtname))); +} + +#define GPC_LOG(action, plansource, stmt) \ + (gpc_record_log(action, __FILE__, __LINE__, plansource, stmt)) + +inline void cn_gpc_record_log(const char* action, const char* filename, int lineno, + CachedPlanSource* plansource, const char* stmtname) +{ + ereport(DEBUG3, (errmodule(MOD_GPC), errcode(ERRCODE_LOG), + errmsg("CNGPC (Action:%s, Location %s,%d), (cn_session:%lu), plansource %p, stmt: %s ", + action, filename, lineno, u_sess->session_id, plansource, stmtname))); +} + +#define CN_GPC_LOG(action, plansource, stmt) \ + (cn_gpc_record_log(action, __FILE__, __LINE__, plansource, stmt)) + +inline void GPCCheckGuc() +{ + if (unlikely((u_sess->sess_ident.cn_sessid == 0 && u_sess->sess_ident.cn_timeline == 0 && + u_sess->sess_ident.cn_nodeid == 0 && !IS_PGXC_COORDINATOR))) + ereport(ERROR, (errmodule(MOD_GPC), errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cn does not set enable_global_plancache but %s set", g_instance.attr.attr_common.PGXCNodeName))); +} + +#endif /* GLOBALPLANCORE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/globalpreparestmt.h postgresql-hll-2.14/include/include/utils/globalpreparestmt.h --- postgresql-hll-2.14_old/include/include/utils/globalpreparestmt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/globalpreparestmt.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------------------- + * + * globalplancache.h + * + * global plan cache + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/utils/globalplancache.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPRESTMT_H +#define GLOBALPRESTMT_H + +#include "knl/knl_variable.h" + +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/globalplancore.h" + +class GlobalPrepareStmt : public BaseObject +{ +public: + GlobalPrepareStmt(); + ~GlobalPrepareStmt(); + + /* cache invalid */ + + void Init(); + void InitCnTimelineHTAB(); + void Store(const char *stmt_name,CachedPlanSource *plansource, bool from_sql, bool is_share); + PreparedStatement *Fetch(const char *stmt_name, bool throwError); + void Drop(const char *stmt_name, bool showError); + void DropAll(sess_orient* key, bool need_lock); + void Clean(uint32 cn_id); + + /* transaction */ + void PrepareCleanUpByTime(bool needCheckTime); + void CleanSessionGPC(knl_session_context* currentSession); + void UpdateUseTime(sess_orient* key, bool sess_detach); + + + void CheckTimeline(); + + /* system function */ + + void* GetStatus(uint32 *num); + +private: + + GPCHashCtl *m_array; + HTAB* m_cn_timeline; +}; + + +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/gs_bitmap.h postgresql-hll-2.14/include/include/utils/gs_bitmap.h --- postgresql-hll-2.14_old/include/include/utils/gs_bitmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/gs_bitmap.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_bitmap.h + * about null bitmap set/query actions + * 1. bitmap_size + * 2. bitmap_been_set + * 3. bitmap_set + * + * + * IDENTIFICATION + * src/include/utils/gs_bitmap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CODE_SRC_INCLUDE_NULL_BITMAP_H +#define CODE_SRC_INCLUDE_NULL_BITMAP_H + +/* + * bitmap_size + * Return the bitmap byte-size of x number. + */ +#define bitmap_size(x) (((x) + 7) / 8) + +/* + * @Description: query the value is null or not. + * @IN bitmap: null bitmap + * @IN which: which bit + * @Return: true, if this bit is set to 1; + * false, if this bit is set to 0; + * @See also: BitmapSize() + */ +static inline bool bitmap_been_set(char* bitmap, int which) +{ + return (bitmap[which / 8] & (1 << (which % 8))); +} + +/* + * @Description: set NULL bit in bitmap. + * caller must reset the whole bitmap to 0 first. + * @IN/OUT bitmap: NULL bitmap + * @IN which: which value is null + * @See also: + */ +static inline void bitmap_set(char* bitmap, int which) +{ + bitmap[which / 8] |= (1 << (which % 8)); +} + +#endif /* CODE_SRC_INCLUDE_NULL_BITMAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/guc.h postgresql-hll-2.14/include/include/utils/guc.h --- postgresql-hll-2.14_old/include/include/utils/guc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/guc.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,434 @@ +/* -------------------------------------------------------------------- + * guc.h + * + * External declarations pertaining to backend/utils/misc/guc.c and + * backend/utils/misc/guc-file.l + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * + * src/include/utils/guc.h + * -------------------------------------------------------------------- + */ +#ifndef GUC_H +#define GUC_H + +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "utils/array.h" + +/* upper limit for GUC variables measured in kilobytes of memory */ +/* note that various places assume the byte size fits in a "long" variable */ +#if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4 +#define MAX_KILOBYTES INT_MAX +#else +#define MAX_KILOBYTES (INT_MAX / 1024) +#endif + +/* + * Certain options can only be set at certain times. The rules are + * like this: + * + * INTERNAL options cannot be set by the user at all, but only through + * internal processes ("server_version" is an example). These are GUC + * variables only so they can be shown by SHOW, etc. + * + * POSTMASTER options can only be set when the postmaster starts, + * either from the configuration file or the command line. + * + * SIGHUP options can only be set at postmaster startup or by changing + * the configuration file and sending the HUP signal to the postmaster + * or a backend process. (Notice that the signal receipt will not be + * evaluated immediately. The postmaster and the backend check it at a + * certain point in their main loop. It's safer to wait than to read a + * file asynchronously.) + * + * BACKEND options can only be set at postmaster startup, from the + * configuration file, or by client request in the connection startup + * packet (e.g., from libpq's PGOPTIONS variable). Furthermore, an + * already-started backend will ignore changes to such an option in the + * configuration file. The idea is that these options are fixed for a + * given backend once it's started, but they can vary across backends. + * + * SUSET options can be set at postmaster startup, with the SIGHUP + * mechanism, or from SQL if you're a superuser. + * + * USERSET options can be set by anyone any time. + */ +typedef enum { PGC_INTERNAL, PGC_POSTMASTER, PGC_SIGHUP, PGC_BACKEND, PGC_SUSET, PGC_USERSET } GucContext; + +/* + * The following type records the source of the current setting. A + * new setting can only take effect if the previous setting had the + * same or lower level. (E.g, changing the config file doesn't + * override the postmaster command line.) Tracking the source allows us + * to process sources in any convenient order without affecting results. + * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well + * as the current value. Note that source == PGC_S_OVERRIDE should be + * used when setting a PGC_INTERNAL option. + * + * PGC_S_INTERACTIVE isn't actually a source value, but is the + * dividing line between "interactive" and "non-interactive" sources for + * error reporting purposes. + * + * PGC_S_TEST is used when testing values to be stored as per-database or + * per-user defaults ("doit" will always be false, so this never gets stored + * as the actual source of any value). This is an interactive case, but + * it needs its own source value because some assign hooks need to make + * different validity checks in this case. + * + * NB: see GucSource_Names in guc.c if you change this. + */ +typedef enum { + PGC_S_DEFAULT, /* hard-wired default ("boot_val") */ + PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */ + PGC_S_ENV_VAR, /* postmaster environment variable */ + PGC_S_FILE, /* postgresql.conf */ + PGC_S_ARGV, /* postmaster command line */ + PGC_S_DATABASE, /* per-database setting */ + PGC_S_USER, /* per-user setting */ + PGC_S_DATABASE_USER, /* per-user-and-database setting */ + PGC_S_CLIENT, /* from client connection request */ + PGC_S_OVERRIDE, /* special case to forcibly set default */ + PGC_S_INTERACTIVE, /* dividing line for error reporting */ + PGC_S_TEST, /* test per-database or per-user setting */ + PGC_S_SESSION /* SET command */ +} GucSource; + +/* + * Parsing the configuration file will return a list of name-value pairs + * with source location info. + */ +typedef struct ConfigVariable { + char* name; + char* value; + char* filename; + int sourceline; + struct ConfigVariable* next; +} ConfigVariable; + +extern bool ParseConfigFile(const char* config_file, const char* calling_file, bool strict, int depth, int elevel, + ConfigVariable** head_p, ConfigVariable** tail_p); +extern bool ParseConfigFp( + FILE* fp, const char* config_file, int depth, int elevel, ConfigVariable** head_p, ConfigVariable** tail_p); +extern void FreeConfigVariables(ConfigVariable* list); + +/* + * The possible values of an enum variable are specified by an array of + * name-value pairs. The "hidden" flag means the value is accepted but + * won't be displayed when guc.c is asked for a list of acceptable values. + */ +struct config_enum_entry { + const char* name; + int val; + bool hidden; +}; + +/* + * Signatures for per-variable check/assign/show hook functions + */ +typedef bool (*GucBoolCheckHook)(bool* newval, void** extra, GucSource source); +typedef bool (*GucIntCheckHook)(int* newval, void** extra, GucSource source); +typedef bool (*GucInt64CheckHook)(int64* newval, void** extra, GucSource source); +typedef bool (*GucRealCheckHook)(double* newval, void** extra, GucSource source); +typedef bool (*GucStringCheckHook)(char** newval, void** extra, GucSource source); +typedef bool (*GucEnumCheckHook)(int* newval, void** extra, GucSource source); + +typedef void (*GucBoolAssignHook)(bool newval, void* extra); +typedef void (*GucIntAssignHook)(int newval, void* extra); +typedef void (*GucInt64AssignHook)(int64 newval, void* extra); +typedef void (*GucRealAssignHook)(double newval, void* extra); +typedef void (*GucStringAssignHook)(const char* newval, void* extra); +typedef void (*GucEnumAssignHook)(int newval, void* extra); + +typedef const char* (*GucShowHook)(void); + +/* + * Miscellaneous + */ +typedef enum { + /* Types of set_config_option actions */ + GUC_ACTION_SET, /* regular SET command */ + GUC_ACTION_LOCAL, /* SET LOCAL command */ + GUC_ACTION_SAVE /* function SET option, or temp assignment */ +} GucAction; + +/* set params entry */ +typedef struct { + char name[NAMEDATALEN]; /* param name */ + char* query; /* set query string */ +} GucParamsEntry; + +#define GUC_QUALIFIER_SEPARATOR '.' + +/* + * bit values in "flags" of a GUC variable + */ +#define GUC_LIST_INPUT 0x0001 /* input can be list format */ +#define GUC_LIST_QUOTE 0x0002 /* double-quote list elements */ +#define GUC_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */ +#define GUC_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */ +#define GUC_REPORT 0x0010 /* auto-report changes to client */ +#define GUC_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */ +#define GUC_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */ +#define GUC_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */ +#define GUC_SUPERUSER_ONLY 0x0100 /* show only to superusers */ +#define GUC_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */ + +#define GUC_UNIT_KB 0x0400 /* value is in kilobytes */ +#define GUC_UNIT_BLOCKS 0x0800 /* value is in blocks */ +#define GUC_UNIT_XBLOCKS 0x0C00 /* value is in xlog blocks */ +#define GUC_UNIT_MEMORY 0x0C00 /* mask for KB, BLOCKS, XBLOCKS */ + +#define GUC_UNIT_MS 0x1000 /* value is in milliseconds */ +#define GUC_UNIT_S 0x2000 /* value is in seconds */ +#define GUC_UNIT_MIN 0x4000 /* value is in minutes */ +#define GUC_UNIT_HOUR 0x5000 /* value is in hour */ +#define GUC_UNIT_TIME 0x7000 /* mask for MS, S, MIN */ + +#define GUC_NOT_WHILE_SEC_REST 0x8000 /* can't set if security restricted */ + +extern THR_LOCAL int log_min_messages; +extern THR_LOCAL bool force_backtrace_messages; +extern THR_LOCAL int client_min_messages; +extern THR_LOCAL int comm_ackchk_time; + +#define SHOW_DEBUG_MESSAGE() (SECUREC_UNLIKELY(log_min_messages <= DEBUG1)) + +/* + * Functions exported by guc.c + */ +extern void SetConfigOption(const char* name, const char* value, GucContext context, GucSource source); + +extern void DefineCustomBoolVariable(const char* name, const char* short_desc, const char* long_desc, bool* valueAddr, + bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, + GucShowHook show_hook); + +extern void DefineCustomIntVariable(const char* name, const char* short_desc, const char* long_desc, int* valueAddr, + int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, + GucIntAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomInt64Variable(const char* name, const char* short_desc, const char* long_desc, int64* valueAddr, + int64 bootValue, int64 minValue, int64 maxValue, GucContext context, int flags, GucInt64CheckHook check_hook, + GucInt64AssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomRealVariable(const char* name, const char* short_desc, const char* long_desc, double* valueAddr, + double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, + GucRealAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomStringVariable(const char* name, const char* short_desc, const char* long_desc, + char** valueAddr, const char* bootValue, GucContext context, int flags, GucStringCheckHook check_hook, + GucStringAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomEnumVariable(const char* name, const char* short_desc, const char* long_desc, int* valueAddr, + int bootValue, const struct config_enum_entry* options, GucContext context, int flags, GucEnumCheckHook check_hook, + GucEnumAssignHook assign_hook, GucShowHook show_hook); + +extern void EmitWarningsOnPlaceholders(const char* className); + +extern const char* GetConfigOption(const char* name, bool missing_ok, bool restrict_superuser); +extern const char* GetConfigOptionResetString(const char* name); +extern void ProcessConfigFile(GucContext context); +extern void InitializeGUCOptions(void); +extern void InitializePostmasterGUC(); +extern void init_sync_guc_variables(void); +extern void repair_guc_variables(void); +extern bool SelectConfigFiles(const char* userDoption, const char* progname); +extern void ResetAllOptions(void); +extern void AtStart_GUC(void); +extern int NewGUCNestLevel(void); +extern void AtEOXact_GUC(bool isCommit, int nestLevel); +extern char* GetGucName(const char *command, char *target_guc_name); +extern void BeginReportingGUCOptions(void); +extern void ParseLongOption(const char* string, char** name, char** value); +extern bool parse_int(const char* value, int* result, int flags, const char** hintmsg); +extern bool parse_int64(const char* value, int64* result, const char** hintmsg); +extern bool parse_real(const char* value, double* result); +extern int set_config_option(const char* name, const char* value, GucContext context, GucSource source, + GucAction action, bool changeVal, int elevel, bool isReload = false); +#ifndef ENABLE_MULTIPLE_NODES +extern void AlterSystemSetConfigFile(AlterSystemStmt* setstmt); +#endif +extern char* GetConfigOptionByName(const char* name, const char** varname); +extern void GetConfigOptionByNum(int varnum, const char** values, bool* noshow); +extern int GetNumConfigOptions(void); + +extern void SetPGVariable(const char* name, List* args, bool is_local); +extern void GetPGVariable(const char* name, DestReceiver* dest); +extern TupleDesc GetPGVariableResultDesc(const char* name); + +#ifdef PGXC +extern char* RewriteBeginQuery(char* query_string, const char* name, List* args); +#endif + +extern void ExecSetVariableStmt(VariableSetStmt* stmt); +extern char* ExtractSetVariableArgs(VariableSetStmt* stmt); + +extern void ProcessGUCArray(ArrayType* array, GucContext context, GucSource source, GucAction action); +extern ArrayType* GUCArrayAdd(ArrayType* array, const char* name, const char* value); +extern ArrayType* GUCArrayDelete(ArrayType* array, const char* name); +extern ArrayType* GUCArrayReset(ArrayType* array); + +#ifdef EXEC_BACKEND +extern void write_nondefault_variables(GucContext context); +extern void read_nondefault_variables(void); +#endif + +extern void GUC_check_errcode(int sqlerrcode); + +#define GUC_check_errmsg \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errmsg_string = format_elog_string + +#define GUC_check_errdetail \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errdetail_string = format_elog_string + +#define GUC_check_errhint \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errhint_string = format_elog_string + +#define guc_free(p) \ + do { \ + if (p != NULL) { \ + free(p); \ + p = NULL; \ + } \ + } while (0) + +/* + * The following functions are not in guc.c, but are declared here to avoid + * having to include guc.h in some widely used headers that it really doesn't + * belong in. + */ + +/* in commands/tablespace.c */ +extern bool check_default_tablespace(char** newval, void** extra, GucSource source); +extern bool check_temp_tablespaces(char** newval, void** extra, GucSource source); +extern void assign_temp_tablespaces(const char* newval, void* extra); + +/* in catalog/namespace.c */ +extern bool check_search_path(char** newval, void** extra, GucSource source); +extern void assign_search_path(const char* newval, void* extra); +extern bool check_percentile(char** newval, void** extra, GucSource source); +extern bool check_numa_distribute_mode(char** newval, void** extra, GucSource source); +extern bool check_asp_flush_mode(char** newval, void** extra, GucSource source); + +/* in access/transam/xlog.c */ +extern bool check_wal_buffers(int* newval, void** extra, GucSource source); +extern void assign_xlog_sync_method(int new_sync_method, void* extra); + +/* in tcop/stmt_retry.cpp */ +extern bool check_errcode_list(char** newval, void** extra, GucSource source); +#define RESERVE_SIZE 33 + +/* + * Error code for config file + */ +typedef enum { + CODE_OK = 0, /* success */ + CODE_UNKNOW_CONFFILE_PATH, /* fail to get the specified config file */ + CODE_OPEN_CONFFILE_FAILED, /* fail to open config file */ + CODE_CLOSE_CONFFILE_FAILED, /* fail to close config file */ + CODE_READE_CONFFILE_ERROR, /* fail to read config file */ + CODE_WRITE_CONFFILE_ERROR, /* fail to write config file */ + CODE_LOCK_CONFFILE_FAILED, + CODE_UNLOCK_CONFFILE_FAILED, + CODE_INTERNAL_ERROR +} ErrCode; + +typedef enum { + NO_REWRITE = 0, /* not allow lazy agg and magic set rewrite*/ + LAZY_AGG = 1, /* allow lazy agg */ + MAGIC_SET = 2, /* allow query qual push */ + PARTIAL_PUSH = 4, /* allow partial push */ + SUBLINK_PULLUP_WITH_UNIQUE_CHECK = 8, /* allow pull sublink with unqiue check */ + SUBLINK_PULLUP_DISABLE_REPLICATED = 16, /* disable pull up sublink with replicated table */ + SUBLINK_PULLUP_IN_TARGETLIST = 32, /* allow pull sublink in targetlist */ + PRED_PUSH = 64, /* push predicate into subquery block */ + PRED_PUSH_NORMAL = 128, + PRED_PUSH_FORCE = 256, +} rewrite_param; + +typedef enum { + NO_BETA_FEATURE = 0, + SEL_SEMI_POISSON = 1, /* use poisson distribution model to calibrate semi join selectivity */ + SEL_EXPR_INSTR = 2, /* use pattern sel to calibrate instr() related base rel selectivity */ + PARAM_PATH_GEN = 4, /* Parametrized Path Generation */ + RAND_COST_OPT = 8, /* Optimizing sc_random_page_cost */ + PARAM_PATH_OPT = 16, /* Parametrized Path Optimization. */ + PAGE_EST_OPT = 32 /* More accurate (rowstored) index pages estimation */ +} sql_beta_param; + +#define ENABLE_PRED_PUSH(root) \ + ((PRED_PUSH & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_NORMAL(root) \ + ((PRED_PUSH_NORMAL & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_FORCE(root) \ + ((PRED_PUSH_FORCE & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_ALL(root) \ + ((ENABLE_PRED_PUSH(root) || ENABLE_PRED_PUSH_NORMAL(root) || ENABLE_PRED_PUSH_FORCE(root)) && permit_predpush(root)) + +#define ENABLE_SQL_BETA_FEATURE(feature) \ + ((bool)((uint)u_sess->attr.attr_sql.sql_beta_feature & feature)) + +typedef enum { + SUMMARY = 0, /* not collect multi column statistics info */ + DETAIL = 1, /* collect multi column statistics info */ +} resource_track_log_param; + +typedef struct { + FILE* fp; + size_t size; +} ConfFileLock; + +#define PG_LOCKFILE_SIZE 1024 +extern void* pg_malloc(size_t size); +extern char* xstrdup(const char* s); + +extern char** read_guc_file(const char* path); +extern ErrCode write_guc_file(const char* path, char** lines); +extern int find_guc_option( + char** optlines, const char* opt_name, int* name_offset, int* name_len, int* value_offset, int* value_len); + +extern void modify_guc_lines(char*** optlines, const char** opt_name, char** copy_from_line); +extern ErrCode copy_guc_lines(char** copy_to_line, char** optlines, const char** opt_name); +extern ErrCode copy_asyn_lines(char* path, char** copy_to_line, const char** opt_name); + +extern ErrCode generate_temp_file(char* buf, char* temppath, size_t size); +extern ErrCode update_temp_file(char* tempfilepath, char** copy_to_line, const char** opt_name); +extern ErrCode get_file_lock(const char* path, ConfFileLock* filelock); +extern void release_file_lock(ConfFileLock* filelock); + +extern void comment_guc_lines(char** optlines, const char** opt_name); +extern int add_guc_optlines_to_buffer(char** optlines, char** buffer); + +/*Add for set command in transaction*/ +extern char* get_set_string(); +extern void reset_set_message(bool); +extern void append_set_message(const char* str); + +extern void init_set_params_htab(void); +extern void make_set_message(void); +extern int check_set_message_to_send(const VariableSetStmt* stmt, const char* queryString); + +#define TRANS_ENCRYPT_SAMPLE_RNDM "1234567890ABCDEF" +#define TRANS_ENCRYPT_SAMPLE_STRING "TRANS_ENCRY_SAMPLE_STRING" + +/* For transparent encryption. For more information, + * see the definition of this variable. + */ +extern THR_LOCAL char* transparent_encrypted_string; +extern THR_LOCAL char* transparent_encrypt_kms_url; +extern THR_LOCAL char* transparent_encrypt_kms_region; + +extern void release_opt_lines(char** opt_lines); +extern char** alloc_opt_lines(int opt_lines_num); + +#ifdef ENABLE_QUNIT +extern void set_qunit_case_number_hook(int newval, void* extra); +#endif + +extern GucContext get_guc_context(); + +#endif /* GUC_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/guc_mn.h postgresql-hll-2.14/include/include/utils/guc_mn.h --- postgresql-hll-2.14_old/include/include/utils/guc_mn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/guc_mn.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,22 @@ +/* -------------------------------------------------------------------- + * guc.h + * + * External declarations pertaining to backend/utils/misc/guc.c and + * backend/utils/misc/guc-file.l + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * + * src/include/utils/guc.h + * -------------------------------------------------------------------- + */ +#ifndef GUC_MN_H +#define GUC_MN_H + +extern void InitConfigureNamesBoolMultipleNode(); +extern void InitConfigureNamesIntMultipleNode(); +extern void InitConfigureNamesRealMultipleNode(); +extern void InitConfigureNamesStringMultipleNode(); +extern bool check_enable_gtm_free(bool* newval, void** extra, GucSource source); + +#endif /* GUC_MN_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/guc_tables.h postgresql-hll-2.14/include/include/utils/guc_tables.h --- postgresql-hll-2.14_old/include/include/utils/guc_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/guc_tables.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,279 @@ +/* ------------------------------------------------------------------------- + * + * guc_tables.h + * Declarations of tables used by GUC. + * + * See src/backend/utils/misc/README for design notes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/utils/guc_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GUC_TABLES_H +#define GUC_TABLES_H 1 + +#include "utils/guc.h" + +/* + * GUC supports these types of variables: + */ +enum config_type { PGC_BOOL, PGC_INT, PGC_INT64, PGC_REAL, PGC_STRING, PGC_ENUM }; + +union config_var_val { + bool boolval; + int intval; + int64 int64val; + double realval; + char* stringval; + int enumval; +}; + +/* + * The actual value of a GUC variable can include a malloc'd opaque struct + * "extra", which is created by its check_hook and used by its assign_hook. + */ +typedef struct config_var_value { + union config_var_val val; + void* extra; +} config_var_value; + +/* + * Groupings to help organize all the run-time options for display + */ +enum config_group { + UNGROUPED, + FILE_LOCATIONS, + CONN_AUTH, + CONN_AUTH_SETTINGS, + CONN_AUTH_SECURITY, + RESOURCES, + RESOURCES_MEM, + RESOURCES_DISK, + RESOURCES_KERNEL, + RESOURCES_VACUUM_DELAY, + RESOURCES_BGWRITER, + RESOURCES_ASYNCHRONOUS, + RESOURCES_RECOVERY, + RESOURCES_WORKLOAD, + WAL, + WAL_SETTINGS, + WAL_CHECKPOINTS, + WAL_ARCHIVING, + REPLICATION, + REPLICATION_SENDING, + REPLICATION_MASTER, + REPLICATION_STANDBY, + QUERY_TUNING, + QUERY_TUNING_METHOD, + QUERY_TUNING_COST, + QUERY_TUNING_GEQO, + QUERY_TUNING_OTHER, + LOGGING, + LOGGING_WHERE, + LOGGING_WHEN, + LOGGING_WHAT, + /* add audit config group. */ + AUDIT_OPTIONS, + STATS, + STATS_MONITORING, + STATS_COLLECTOR, + STREAMING, + AUTOVACUUM, + JOB, + CLIENT_CONN, + CLIENT_CONN_STATEMENT, + CLIENT_CONN_LOCALE, + CLIENT_CONN_OTHER, + LOCK_MANAGEMENT, + COMPAT_OPTIONS, + COMPAT_OPTIONS_PREVIOUS, + COMPAT_OPTIONS_CLIENT, + ERROR_HANDLING_OPTIONS, + PRESET_OPTIONS, + CUSTOM_OPTIONS, + TEXT_SEARCH, + DEVELOPER_OPTIONS, + UPGRADE_OPTIONS, + TSDB, + INSTRUMENTS_OPTIONS, + CE_OPTIONS, +#ifdef PGXC + DATA_NODES, + GTM, + COORDINATORS, + XC_HOUSEKEEPING_OPTIONS +#endif +}; + +/* + * Stack entry for saving the state a variable had prior to an uncommitted + * transactional change + */ +typedef enum { + /* This is almost GucAction, but we need a fourth state for SET+LOCAL */ + GUC_SAVE, /* entry caused by function SET option */ + GUC_SET, /* entry caused by plain SET command */ + GUC_LOCAL, /* entry caused by SET LOCAL command */ + GUC_SET_LOCAL /* entry caused by SET then SET LOCAL */ +} GucStackState; + +typedef struct guc_stack { + struct guc_stack* prev; /* previous stack item, if any */ + int nest_level; /* nesting depth at which we made entry */ + GucStackState state; /* see enum above */ + GucSource source; /* source of the prior value */ + /* masked value's source must be PGC_S_SESSION, so no need to store it */ + GucContext scontext; /* context that set the prior value */ + GucContext masked_scontext; /* context that set the masked value */ + config_var_value prior; /* previous value of variable */ + config_var_value masked; /* SET value in a GUC_SET_LOCAL entry */ +} GucStack; + +/* + * Generic fields applicable to all types of variables + * + * The short description should be less than 80 chars in length. Some + * applications may use the long description as well, and will append + * it to the short description. (separated by a newline or '. ') + * + * Note that sourcefile/sourceline are kept here, and not pushed into stacked + * values, although in principle they belong with some stacked value if the + * active value is session- or transaction-local. This is to avoid bloating + * stack entries. We know they are only relevant when source == PGC_S_FILE. + */ +struct config_generic { + /* constant fields, must be set correctly in initial value: */ + const char* name; /* name of variable - MUST BE FIRST */ + GucContext context; /* context required to set the variable */ + enum config_group group; /* to help organize variables by function */ + const char* short_desc; /* short desc. of this variable's purpose */ + const char* long_desc; /* long desc. of this variable's purpose */ + int flags; /* flag bits, see guc.h */ + /* variable fields, initialized at runtime: */ + enum config_type vartype; /* type of variable (set only at startup) */ + int status; /* status bits, see below */ + GucSource source; /* source of the current actual value */ + GucSource reset_source; /* source of the reset_value */ + GucContext scontext; /* context that set the current value */ + GucContext reset_scontext; /* context that set the reset value */ + GucStack* stack; /* stacked prior values */ + void* extra; /* "extra" pointer for current actual value */ + char* sourcefile; /* file current setting is from (NULL if not + * set in config file) */ + int sourceline; /* line in source file */ +}; + +extern const char* sync_guc_variable_namelist[]; + +/* bit values in status field */ +#define GUC_IS_IN_FILE 0x0001 /* found it in config file */ +/* + * Caution: the GUC_IS_IN_FILE bit is transient state for ProcessConfigFile. + * Do not assume that its value represents useful information elsewhere. + */ + +/* GUC records for specific variable types */ + +struct config_bool { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + bool* variable; + bool boot_val; + GucBoolCheckHook check_hook; + GucBoolAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + bool reset_val; + void* reset_extra; +}; + +struct config_int { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + int min; + int max; + GucIntCheckHook check_hook; + GucIntAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +struct config_int64 { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int64* variable; + int64 boot_val; + int64 min; + int64 max; + GucInt64CheckHook check_hook; + GucInt64AssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int64 reset_val; + void* reset_extra; +}; + +struct config_real { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + double* variable; + double boot_val; + double min; + double max; + GucRealCheckHook check_hook; + GucRealAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + double reset_val; + void* reset_extra; +}; + +struct config_string { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + char** variable; + const char* boot_val; + GucStringCheckHook check_hook; + GucStringAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + char* reset_val; + void* reset_extra; +}; + +struct config_enum { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + const struct config_enum_entry* options; + GucEnumCheckHook check_hook; + GucEnumAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +/* constant tables corresponding to enums above and in guc.h */ +extern const char* const config_group_names[]; +extern const char* const config_type_names[]; +extern const char* const GucContext_Names[]; +extern const char* const GucSource_Names[]; + +/* get the current set of variables */ +extern struct config_generic** get_guc_variables(void); + +extern void build_guc_variables(void); + +/* search in enum options */ +extern const char* config_enum_lookup_by_value(struct config_enum* record, int val); +extern bool config_enum_lookup_by_name(struct config_enum* record, const char* value, int* retval); + +#endif /* GUC_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/hashutils.h postgresql-hll-2.14/include/include/utils/hashutils.h --- postgresql-hll-2.14_old/include/include/utils/hashutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/hashutils.h 2020-12-12 17:06:43.287348554 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hashutils.h + * Utilities for working with hash values. + * + * + * IDENTIFICATION + * src/include/utils/hashutils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HASHUTILS_H +#define HASHUTILS_H + +/* + * Simple inline murmur hash implementation hashing a 32 bit integer, for + * performance. + */ +static inline uint32 murmurhash32(uint32 data) +{ + uint32 h = data; + + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + return h; +} + +#endif /* HASHUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/help_config.h postgresql-hll-2.14/include/include/utils/help_config.h --- postgresql-hll-2.14_old/include/include/utils/help_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/help_config.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,17 @@ +/* ------------------------------------------------------------------------- + * + * help_config.h + * Interface to the --help-config option of main.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/utils/help_config.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HELP_CONFIG_H +#define HELP_CONFIG_H 1 + +extern int GucInfoMain(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/hotkey.h postgresql-hll-2.14/include/include/utils/hotkey.h --- postgresql-hll-2.14_old/include/include/utils/hotkey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/hotkey.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,103 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * hotkey.h + * + * + * + * IDENTIFICATION + * src/include/utils/hotkey.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_HOTKEYS_H +#define SRC_INCLUDE_UTILS_HOTKEYS_H + +#include "postgres.h" +#include "pgstat.h" +#include "pgxc/locator.h" +#include "nodes/nodes.h" +#include "nodes/pg_list.h" +#include "lib/lrucache.h" + +const int LRU_QUEUE_LENGTH = 16; +const int HOTKEYS_QUEUE_LENGTH = 500; +const int FIFO_QUEUE_LENGTH = 32; + +/* basic hotkey info to be present */ +typedef struct HotkeyValue { + char* databaseName; + char* schemaName; + char* relName; + List* constValues; /* List of const nodes */ + Size totalLength; /* Total length of values */ +} HotkeyValue; + +/* missing hotkey info for DFX */ +typedef struct HotkeyMissInfo { + char* databaseName; + char* schemaName; + char* relName; + char* missInfo; +} HotkeyMissInfo; + +/* Hotkey candidates collected from plan */ +typedef struct HotkeyCandidate { + Oid relid; + uint32 hashValue; + HotkeyValue* hotkeyValue; +} HotkeyCandidate; + +/* HotkeyInfo structure */ +typedef struct HotkeyInfo { + uint64 count; /* counter of key */ + Oid relationOid; /* OID of relation the queries depend on */ + Oid databaseOid; /* database oid */ + uint32 hashValue; /* hash value of key */ + HotkeyValue* hotkeyValue; +} HotkeyInfo; + +/* Hotkey statistics info present to caller */ +typedef struct HotkeyGeneralInfo { + char* database; + char* schema; + char* table; + char* value; + uint32 hashValue; + uint64 count; +} HotkeyGeneralInfo; + +extern void CleanHotkeyCandidates(bool deep); +extern bool CmdtypeSupportsHotkey(CmdType commandType); +extern bool ExecOnSingleNode(List* nodeList); +extern void InsertKeysToLRU(HotkeyInfo** temp, int length); +extern void ReportHotkeyCandidate(RelationLocInfo* rel_loc_info, RelationAccessType accessType, List* idx_dist_by_col, + const bool* nulls, Oid* attr, Datum* values, uint32 hashValue); +extern void SendHotkeyToPgstat(); +extern Datum gs_stat_get_hotkeys_info(PG_FUNCTION_ARGS); +extern Datum gs_stat_clean_hotkeys(PG_FUNCTION_ARGS); +extern Datum global_stat_get_hotkeys_info(PG_FUNCTION_ARGS); +extern Datum global_stat_clean_hotkeys(PG_FUNCTION_ARGS); +extern void pgstat_recv_cleanup_hotkeys(PgStat_MsgCleanupHotkeys* msg, int len); +extern void pgstat_send_cleanup_hotkeys(Oid db_oid, Oid t_oid); +extern void PgstatUpdateHotkeys(); +extern bool IsEqual(CmpFuncType fp, void* t1, void* t2); +extern bool IsHotkeyEqual(void* t1, void* t2); +extern void CleanHotkeyInfo(HotkeyInfo* keyInfo); +extern HotkeyInfo* MakeHotkeyInfo(const Oid relationOid, uint32 hashvalue, HotkeyValue* hotkeyValue, MemoryContext cxt); +extern List* CopyHotKeys(List* srcHotKeys); +extern void CheckHotkeys(RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); + +#endif /* SRC_INCLUDE_UTILS_HOTKEYS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/utils/hsearch.h postgresql-hll-2.14/include/include/utils/hsearch.h --- postgresql-hll-2.14_old/include/include/utils/hsearch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/hsearch.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,154 @@ +/* ------------------------------------------------------------------------- + * + * hsearch.h + * exported definitions for utils/hash/dynahash.c; see notes therein + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/hsearch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HSEARCH_H +#define HSEARCH_H + +/* + * Hash functions must have this signature. + */ +typedef uint32 (*HashValueFunc)(const void* key, Size keysize); + +/* + * Key comparison functions must have this signature. Comparison functions + * return zero for match, nonzero for no match. (The comparison function + * definition is designed to allow memcmp() and strncmp() to be used directly + * as key comparison functions.) + */ +typedef int (*HashCompareFunc)(const void* key1, const void* key2, Size keysize); + +/* + * Key copying functions must have this signature. The return value is not + * used. (The definition is set up to allow memcpy() and strncpy() to be + * used directly.) + */ +typedef void* (*HashCopyFunc)(void* dest, const void* src, Size keysize); + +/* + * Space allocation function for a hashtable --- designed to match malloc(). + * Note: there is no free function API; can't destroy a hashtable unless you + * use the default allocator. + */ +typedef void* (*HashAllocFunc)(Size request); + +/* + * Space deallocation function for a hashtable --- designed to match allocator(). + * Note: it's a free function API; you must use it with allocator you defined. + */ +typedef void (*HashDeallocFunc)(void* pointer); + +/* + * HASHELEMENT is the private part of a hashtable entry. The caller's data + * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key + * is expected to be at the start of the caller's hash entry data structure. + */ +typedef struct HASHELEMENT { + struct HASHELEMENT* link; /* link to next entry in same bucket */ + uint32 hashvalue; /* hash function result for this entry */ +} HASHELEMENT; + +/* Hash table header struct is an opaque type known only within dynahash.c */ +typedef struct HASHHDR HASHHDR; + +/* Hash table control struct is an opaque type known only within dynahash.c */ +typedef struct HTAB HTAB; + +/* Parameter data structure for hash_create */ +/* Only those fields indicated by hash_flags need be set */ +typedef struct HASHCTL { + long num_partitions; /* # partitions (must be power of 2) */ + long ssize; /* segment size */ + long dsize; /* (initial) directory size */ + long max_dsize; /* limit to dsize if dir size is limited */ + long ffactor; /* fill factor */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context to use for allocations */ + HASHHDR* hctl; /* location of header in shared mem */ +} HASHCTL; + +/* Flags to indicate which parameters are supplied */ +#define HASH_PARTITION 0x001 /* Hashtable is used w/partitioned locking */ +#define HASH_SEGMENT 0x002 /* Set segment size */ +#define HASH_DIRSIZE 0x004 /* Set directory size (initial and max) */ +#define HASH_FFACTOR 0x008 /* Set fill factor */ +#define HASH_FUNCTION 0x010 /* Set user defined hash function */ +#define HASH_ELEM 0x020 /* Set keysize and entrysize */ +#define HASH_SHARED_MEM 0x040 /* Hashtable is in shared memory */ +#define HASH_ATTACH 0x080 /* Do not initialize hctl */ +#define HASH_ALLOC 0x100 /* Set memory allocator */ +#define HASH_CONTEXT 0x200 /* Set memory allocation context */ +#define HASH_COMPARE 0x400 /* Set user defined comparison function */ +#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */ +#define HASH_FIXED_SIZE 0x1000 /* Initial size is a hard limit */ +#define HASH_HEAP_MEM 0x2000 /* Hashtable is in heap memory */ +#define HASH_EXTERN_CONTEXT 0x4000 /* use extern context directly */ +#define HASH_SHRCTX 0x8000 /* Set shared memory allocation context */ +#define HASH_DEALLOC 0x10000 /* Set memory deallocator */ +#define HASH_BLOBS 0x20000 /* Select support functions for binary keys */ +#define HASH_NOEXCEPT 0x40000 /* Do not throw exception when malloc memory */ + +/* max_dsize value to indicate expansible directory */ +#define NO_MAX_DSIZE (-1) + +/* hash_search operations */ +typedef enum { HASH_FIND, HASH_ENTER, HASH_REMOVE, HASH_ENTER_NULL } HASHACTION; + +/* hash_seq status (should be considered an opaque type by callers) */ +typedef struct { + HTAB* hashp; + uint32 curBucket; /* index of current bucket */ + HASHELEMENT* curEntry; /* current entry in bucket */ +} HASH_SEQ_STATUS; + +/* + * prototypes for functions in dynahash.c + */ +extern HTAB* hash_create(const char* tabname, long nelem, HASHCTL* info, int flags); +extern void hash_destroy(HTAB* hashp); +extern void hash_remove(HTAB* hashp); +extern void hash_stats(const char* where, HTAB* hashp); +extern void* hash_search(HTAB* hashp, const void* keyPtr, HASHACTION action, bool* foundPtr); +extern uint32 get_hash_value(HTAB* hashp, const void* keyPtr); +extern void* hash_search_with_hash_value( + HTAB* hashp, const void* keyPtr, uint32 hashvalue, HASHACTION action, bool* foundPtr); +extern long hash_get_num_entries(HTAB* hashp); +extern void hash_seq_init(HASH_SEQ_STATUS* status, HTAB* hashp); +extern void* hash_seq_search(HASH_SEQ_STATUS* status); +extern void hash_seq_term(HASH_SEQ_STATUS* status); +extern void hash_freeze(HTAB* hashp); +extern Size hash_estimate_size(long num_entries, Size entrysize); +extern long hash_select_dirsize(long num_entries); +extern Size hash_get_shared_size(HASHCTL* info, int flags); +extern void AtEOXact_HashTables(bool isCommit); +extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth); +extern int hash_get_seq_num(); +extern void release_all_seq_scan(); +extern MemoryContext hash_get_current_dynacxt(void); + +/* + * prototypes for functions in hashfn.c + */ +extern uint32 string_hash(const void* key, Size keysize); +extern uint32 tag_hash(const void* key, Size keysize); +extern uint32 uint32_hash(const void *key, Size keysize); +extern uint32 oid_hash(const void* key, Size keysize); +extern uint32 bitmap_hash(const void* key, Size keysize); +extern int bitmap_match(const void* key1, const void* key2, Size keysize); + +#endif /* HSEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/inet.h postgresql-hll-2.14/include/include/utils/inet.h --- postgresql-hll-2.14_old/include/include/utils/inet.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/inet.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------------- + * + * inet.h + * Declarations for operations on INET datatypes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/inet.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INET_H +#define INET_H + +#include "fmgr.h" + +/* + * This is the internal storage format for IP addresses + * (both INET and CIDR datatypes): + */ +typedef struct { + unsigned char family; /* PGSQL_AF_INET or PGSQL_AF_INET6 */ + unsigned char bits; /* number of bits in netmask */ + unsigned char ipaddr[16]; /* up to 128 bits of address */ +} inet_struct; + +/* + * Referencing all of the non-AF_INET types to AF_INET lets us work on + * machines which may not have the appropriate address family (like + * inet6 addresses when AF_INET6 isn't present) but doesn't cause a + * dump/reload requirement. Existing databases used AF_INET for the family + * type on disk. + */ +#define PGSQL_AF_INET (AF_INET + 0) +#define PGSQL_AF_INET6 (AF_INET + 1) + +/* + * Both INET and CIDR addresses are represented within Postgres as varlena + * objects, ie, there is a varlena header in front of the struct type + * depicted above. This struct depicts what we actually have in memory + * in "uncompressed" cases. Note that since the maximum data size is only + * 18 bytes, INET/CIDR will invariably be stored into tuples using the + * 1-byte-header varlena format. However, we have to be prepared to cope + * with the 4-byte-header format too, because various code may helpfully + * try to "decompress" 1-byte-header datums. + */ +typedef struct { + char vl_len_[4]; /* Do not touch this field directly! */ + inet_struct inet_data; +} inet; + +/* + * This is the internal storage format for MAC addresses: + */ +typedef struct macaddr { + unsigned char a; + unsigned char b; + unsigned char c; + unsigned char d; + unsigned char e; + unsigned char f; +} macaddr; + +/* + * fmgr interface macros + */ +#define DatumGetInetP(X) ((inet*)PG_DETOAST_DATUM(X)) +#define DatumGetInetPP(X) ((inet*)PG_DETOAST_DATUM_PACKED(X)) +#define InetPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) +#define PG_GETARG_INET_PP(n) DatumGetInetPP(PG_GETARG_DATUM(n)) +#define PG_RETURN_INET_P(x) return InetPGetDatum(x) +/* macaddr is a fixed-length pass-by-reference datatype */ +#define DatumGetMacaddrP(X) ((macaddr*)DatumGetPointer(X)) +#define MacaddrPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n)) +#define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x) + +#endif /* INET_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/int8.h postgresql-hll-2.14/include/include/utils/int8.h --- postgresql-hll-2.14_old/include/include/utils/int8.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/int8.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------------- + * + * int8.h + * Declarations for operations on 64-bit integers. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/int8.h + * + * NOTES + * These data types are supported on all 64-bit architectures, and may + * be supported through libraries on some 32-bit machines. If your machine + * is not currently supported, then please try to make it so, then post + * patches to the postgresql.org hackers mailing list. + * + * ------------------------------------------------------------------------- + */ +#ifndef INT8_H +#define INT8_H + +#include "fmgr.h" + +extern bool scanint8(const char* str, bool errorOK, int64* result); + +extern Datum int8in(PG_FUNCTION_ARGS); +extern Datum int8out(PG_FUNCTION_ARGS); +extern Datum int8recv(PG_FUNCTION_ARGS); +extern Datum int8send(PG_FUNCTION_ARGS); + +extern Datum int8eq(PG_FUNCTION_ARGS); +extern Datum int8ne(PG_FUNCTION_ARGS); +extern Datum int8lt(PG_FUNCTION_ARGS); +extern Datum int8gt(PG_FUNCTION_ARGS); +extern Datum int8le(PG_FUNCTION_ARGS); +extern Datum int8ge(PG_FUNCTION_ARGS); + +extern Datum int84eq(PG_FUNCTION_ARGS); +extern Datum int84ne(PG_FUNCTION_ARGS); +extern Datum int84lt(PG_FUNCTION_ARGS); +extern Datum int84gt(PG_FUNCTION_ARGS); +extern Datum int84le(PG_FUNCTION_ARGS); +extern Datum int84ge(PG_FUNCTION_ARGS); + +extern Datum int48eq(PG_FUNCTION_ARGS); +extern Datum int48ne(PG_FUNCTION_ARGS); +extern Datum int48lt(PG_FUNCTION_ARGS); +extern Datum int48gt(PG_FUNCTION_ARGS); +extern Datum int48le(PG_FUNCTION_ARGS); +extern Datum int48ge(PG_FUNCTION_ARGS); + +extern Datum int82eq(PG_FUNCTION_ARGS); +extern Datum int82ne(PG_FUNCTION_ARGS); +extern Datum int82lt(PG_FUNCTION_ARGS); +extern Datum int82gt(PG_FUNCTION_ARGS); +extern Datum int82le(PG_FUNCTION_ARGS); +extern Datum int82ge(PG_FUNCTION_ARGS); + +extern Datum int28eq(PG_FUNCTION_ARGS); +extern Datum int28ne(PG_FUNCTION_ARGS); +extern Datum int28lt(PG_FUNCTION_ARGS); +extern Datum int28gt(PG_FUNCTION_ARGS); +extern Datum int28le(PG_FUNCTION_ARGS); +extern Datum int28ge(PG_FUNCTION_ARGS); + +extern Datum int8um(PG_FUNCTION_ARGS); +extern Datum int8up(PG_FUNCTION_ARGS); +extern Datum int8pl(PG_FUNCTION_ARGS); +extern Datum int8mi(PG_FUNCTION_ARGS); +extern Datum int8mul(PG_FUNCTION_ARGS); +extern Datum int8div(PG_FUNCTION_ARGS); +extern Datum int8abs(PG_FUNCTION_ARGS); +extern Datum int8mod(PG_FUNCTION_ARGS); +extern Datum int8inc(PG_FUNCTION_ARGS); +extern Datum int8inc_any(PG_FUNCTION_ARGS); +extern Datum int8inc_float8_float8(PG_FUNCTION_ARGS); +extern Datum int8larger(PG_FUNCTION_ARGS); +extern Datum int8smaller(PG_FUNCTION_ARGS); + +extern Datum int8and(PG_FUNCTION_ARGS); +extern Datum int8or(PG_FUNCTION_ARGS); +extern Datum int8xor(PG_FUNCTION_ARGS); +extern Datum int8not(PG_FUNCTION_ARGS); +extern Datum int8shl(PG_FUNCTION_ARGS); +extern Datum int8shr(PG_FUNCTION_ARGS); + +extern Datum int84pl(PG_FUNCTION_ARGS); +extern Datum int84mi(PG_FUNCTION_ARGS); +extern Datum int84mul(PG_FUNCTION_ARGS); +extern Datum int84div(PG_FUNCTION_ARGS); + +extern Datum int48pl(PG_FUNCTION_ARGS); +extern Datum int48mi(PG_FUNCTION_ARGS); +extern Datum int48mul(PG_FUNCTION_ARGS); +extern Datum int48div(PG_FUNCTION_ARGS); + +extern Datum int82pl(PG_FUNCTION_ARGS); +extern Datum int82mi(PG_FUNCTION_ARGS); +extern Datum int82mul(PG_FUNCTION_ARGS); +extern Datum int82div(PG_FUNCTION_ARGS); + +extern Datum int28pl(PG_FUNCTION_ARGS); +extern Datum int28mi(PG_FUNCTION_ARGS); +extern Datum int28mul(PG_FUNCTION_ARGS); +extern Datum int28div(PG_FUNCTION_ARGS); + +extern Datum int48(PG_FUNCTION_ARGS); +extern Datum int84(PG_FUNCTION_ARGS); + +extern Datum int28(PG_FUNCTION_ARGS); +extern Datum int82(PG_FUNCTION_ARGS); + +extern Datum i8tod(PG_FUNCTION_ARGS); +extern Datum dtoi8(PG_FUNCTION_ARGS); + +extern Datum i8tof(PG_FUNCTION_ARGS); +extern Datum ftoi8(PG_FUNCTION_ARGS); + +extern Datum i8tooid(PG_FUNCTION_ARGS); +extern Datum oidtoi8(PG_FUNCTION_ARGS); + +extern Datum int8_bool(PG_FUNCTION_ARGS); +extern Datum bool_int8(PG_FUNCTION_ARGS); + +extern Datum generate_series_int8(PG_FUNCTION_ARGS); +extern Datum generate_series_step_int8(PG_FUNCTION_ARGS); + +#ifndef MADLIB +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/int8.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/int4.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/float.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl" +#endif + +#endif /* INT8_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/inval.h postgresql-hll-2.14/include/include/utils/inval.h --- postgresql-hll-2.14_old/include/include/utils/inval.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/inval.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * inval.h + * POSTGRES cache invalidation dispatcher definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/inval.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INVAL_H +#define INVAL_H + +#include "access/htup.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef void (*SyscacheCallbackFunction)(Datum arg, int cacheid, uint32 hashvalue); +typedef void (*RelcacheCallbackFunction)(Datum arg, Oid relid); +typedef void (*PartcacheCallbackFunction)(Datum arg, Oid partid); + +/* + * Dynamically-registered callback functions. Current implementation + * assumes there won't be very many of these at once; could improve if needed. + */ + +#define MAX_SYSCACHE_CALLBACKS 20 +#define MAX_RELCACHE_CALLBACKS 5 +#define MAX_PARTCACHE_CALLBACKS 5 + +typedef struct SYSCACHECALLBACK { + int16 id; /* cache number */ + SyscacheCallbackFunction function; + Datum arg; +} SYSCACHECALLBACK; + +typedef struct RELCACHECALLBACK { + RelcacheCallbackFunction function; + Datum arg; +} RELCACHECALLBACK; + +typedef struct PARTCACHECALLBACK { + PartcacheCallbackFunction function; + Datum arg; +} PARTCACHECALLBACK; + +extern void AcceptInvalidationMessages(void); + +extern void AtStart_Inval(void); + +extern void AtSubStart_Inval(void); + +extern void AtEOXact_Inval(bool isCommit); + +extern void AtEOSubXact_Inval(bool isCommit); + +extern void AtPrepare_Inval(void); + +extern void PostPrepare_Inval(void); + +extern void CommandEndInvalidationMessages(void); + +extern void CacheInvalidateHeapTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple); + +extern void CacheInvalidateFunction(Oid funcOid); + +extern void CacheInvalidateCatalog(Oid catalogId); + +extern void CacheInvalidateRelcache(Relation relation); + +extern void CacheInvalidateRelcacheByTuple(HeapTuple classTuple); + +extern void CacheInvalidateRelcacheByRelid(Oid relid); + +extern void CacheInvalidateSmgr(RelFileNodeBackend rnode); + +extern void CacheInvalidateRelmap(Oid databaseId); + +extern void CacheInvalidateHeapTupleInplace(Relation relation, HeapTuple tuple); + +extern void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg); + +extern void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg); + +extern void CallSyscacheCallbacks(int cacheid, uint32 hashvalue); + +extern void inval_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void CacheRegisterPartcacheCallback(PartcacheCallbackFunction func, Datum arg); +extern void CacheInvalidatePartcache(Partition partition); +extern void CacheInvalidatePartcacheByTuple(HeapTuple partitionTuple); +extern void CacheInvalidatePartcacheByPartid(Oid partid); + +extern void InvalidateSystemCaches(void); + +#endif /* INVAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/json.h postgresql-hll-2.14/include/include/utils/json.h --- postgresql-hll-2.14_old/include/include/utils/json.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/json.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * json.h + * Declarations for JSON data type support. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/json.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JSON_H +#define JSON_H + +#include "fmgr.h" +#include "lib/stringinfo.h" + +extern Datum json_in(PG_FUNCTION_ARGS); +extern Datum json_out(PG_FUNCTION_ARGS); +extern Datum json_recv(PG_FUNCTION_ARGS); +extern Datum json_send(PG_FUNCTION_ARGS); +extern Datum array_to_json(PG_FUNCTION_ARGS); +extern Datum array_to_json_pretty(PG_FUNCTION_ARGS); +extern Datum row_to_json(PG_FUNCTION_ARGS); +extern Datum row_to_json_pretty(PG_FUNCTION_ARGS); +extern void escape_json(StringInfo buf, const char* str); + +#endif /* JSON_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/logtape.h postgresql-hll-2.14/include/include/utils/logtape.h --- postgresql-hll-2.14_old/include/include/utils/logtape.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/logtape.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * logtape.h + * Management of "logical tapes" within temporary files. + * + * See logtape.c for explanations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/logtape.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef LOGTAPE_H +#define LOGTAPE_H + +/* LogicalTapeSet is an opaque type whose details are not known outside logtape.c. */ + +typedef struct LogicalTapeSet LogicalTapeSet; + +/* + * prototypes for functions in logtape.c + */ + +extern LogicalTapeSet* LogicalTapeSetCreate(int ntapes); +extern void LogicalTapeSetClose(LogicalTapeSet* lts); +extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet* lts); +extern size_t LogicalTapeRead(LogicalTapeSet* lts, int tapenum, void* ptr, size_t size); +extern void LogicalTapeWrite(LogicalTapeSet* lts, int tapenum, void* ptr, size_t size); +extern void LogicalTapeRewind(LogicalTapeSet* lts, int tapenum, bool forWrite); +extern void LogicalTapeFreeze(LogicalTapeSet* lts, int tapenum); +extern bool LogicalTapeBackspace(LogicalTapeSet* lts, int tapenum, size_t size); +extern bool LogicalTapeSeek(LogicalTapeSet* lts, int tapenum, long blocknum, int offset); +extern void LogicalTapeTell(LogicalTapeSet* lts, int tapenum, long* blocknum, int* offset); +extern long LogicalTapeSetBlocks(LogicalTapeSet* lts); + +#endif /* LOGTAPE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/lsyscache.h postgresql-hll-2.14/include/include/utils/lsyscache.h --- postgresql-hll-2.14_old/include/include/utils/lsyscache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/lsyscache.h 2020-12-12 17:06:43.288348567 +0800 @@ -0,0 +1,219 @@ +/* ------------------------------------------------------------------------- + * + * lsyscache.h + * Convenience routines for common queries in the system catalog cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/lsyscache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LSYSCACHE_H +#define LSYSCACHE_H + +#include "access/htup.h" +#include "nodes/primnodes.h" +#include "catalog/pg_resource_pool.h" +#include "catalog/pg_workload_group.h" +#include "catalog/pg_app_workloadgroup_mapping.h" +#include "catalog/pgxc_node.h" + +/* Result list element for get_op_btree_interpretation */ +typedef struct OpBtreeInterpretation { + Oid opfamily_id; /* btree opfamily containing operator */ + int strategy; /* its strategy number */ + Oid oplefttype; /* declared left input datatype */ + Oid oprighttype; /* declared right input datatype */ +} OpBtreeInterpretation; + +/* I/O function selector for get_type_io_data */ +typedef enum IOFuncSelector { IOFunc_input, IOFunc_output, IOFunc_receive, IOFunc_send } IOFuncSelector; + +extern bool op_in_opfamily(Oid opno, Oid opfamily); +extern int get_op_opfamily_strategy(Oid opno, Oid opfamily); +extern Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily); +extern void get_op_opfamily_properties( + Oid opno, Oid opfamily, bool ordering_op, int* strategy, Oid* lefttype, Oid* righttype); +extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy); +extern bool get_ordering_op_properties(Oid opno, Oid* opfamily, Oid* opcintype, int16* strategy); +extern bool get_compare_function_for_ordering_op(Oid opno, Oid* cmpfunc, bool* reverse); +extern bool get_sort_function_for_ordering_op(Oid opno, Oid* sortfunc, bool* issupport, bool* reverse); +extern Oid get_equality_op_for_ordering_op(Oid opno, bool* reverse); +extern Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type); +extern List* get_mergejoin_opfamilies(Oid opno); +extern bool get_compatible_hash_operators(Oid opno, Oid* lhs_opno, Oid* rhs_opno); +extern bool get_op_hash_functions(Oid opno, RegProcedure* lhs_procno, RegProcedure* rhs_procno); +extern List* get_op_btree_interpretation(Oid opno); +extern bool equality_ops_are_compatible(Oid opno1, Oid opno2); +extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum); +extern char* get_attname(Oid relid, AttrNumber attnum); +extern char* get_relid_attribute_name(Oid relid, AttrNumber attnum); +extern AttrNumber get_attnum(Oid relid, const char* attname); +extern Oid get_atttype(Oid relid, AttrNumber attnum); +extern int32 get_atttypmod(Oid relid, AttrNumber attnum); +extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid* typid, int32* typmod, Oid* collid); +extern char* get_collation_name(Oid colloid); +extern char* get_constraint_name(Oid conoid); +extern Oid get_opclass_family(Oid opclass); +extern Oid get_opclass_input_type(Oid opclass); +extern RegProcedure get_opcode(Oid opno); +extern char* get_opname(Oid opno); +extern void op_input_types(Oid opno, Oid* lefttype, Oid* righttype); +extern bool op_mergejoinable(Oid opno, Oid inputtype); +extern bool op_hashjoinable(Oid opno, Oid inputtype); +extern bool op_strict(Oid opno); +extern char op_volatile(Oid opno); +extern Oid get_commutator(Oid opno); +extern Oid get_equal(Oid opno); +extern Oid get_negator(Oid opno); +extern RegProcedure get_oprrest(Oid opno); +extern RegProcedure get_oprjoin(Oid opno); +extern char* get_func_name(Oid funcid); +extern Oid get_func_namespace(Oid funcid); +extern Oid get_func_rettype(Oid funcid); +extern int get_func_nargs(Oid funcid); +extern Oid get_func_signature(Oid funcid, Oid** argtypes, int* nargs); +extern Oid get_func_variadictype(Oid funcid); +extern bool get_func_retset(Oid funcid); +extern bool func_strict(Oid funcid); +extern char func_volatile(Oid funcid); +extern bool get_func_proshippable(Oid funcid); +extern bool get_func_leakproof(Oid funcid); +extern float4 get_func_cost(Oid funcid); +extern float4 get_func_rows(Oid funcid); +extern Oid get_func_lang(Oid funcid); +extern Oid get_relname_relid(const char* relname, Oid relnamespace); +extern char* get_relname_relid_extend( + const char* relname, Oid relnamespace, Oid* relOid, bool isSupportSynonym, Oid* refSynOid); + +#ifdef PGXC +extern int get_relnatts(Oid relid); +#endif +extern char* get_rel_name(Oid relid); +extern char* getPartitionName(Oid partid, bool missing_ok); +extern Oid get_rel_namespace(Oid relid); +extern char get_rel_persistence(Oid relid); +extern bool is_sys_table(Oid relid); +extern Oid get_rel_type_id(Oid relid); +extern char get_rel_relkind(Oid relid); +extern Oid get_rel_tablespace(Oid relid); +extern bool get_typisdefined(Oid typid); +extern int16 get_typlen(Oid typid); +extern bool get_typbyval(Oid typid); +extern void get_typlenbyval(Oid typid, int16* typlen, bool* typbyval); +extern void get_typlenbyvalalign(Oid typid, int16* typlen, bool* typbyval, char* typalign); +extern Oid getTypeIOParam(HeapTuple typeTuple); +extern void get_type_io_data(Oid typid, IOFuncSelector which_func, int16* typlen, bool* typbyval, char* typalign, + char* typdelim, Oid* typioparam, Oid* func); +extern char get_typstorage(Oid typid); +extern Node* get_typdefault(Oid typid); +extern char get_typtype(Oid typid); +extern bool type_is_rowtype(Oid typid); +extern bool type_is_enum(Oid typid); +extern bool type_is_range(Oid typid); +extern void get_type_category_preferred(Oid typid, char* typcategory, bool* typispreferred); +extern Oid get_typ_typrelid(Oid typid); +extern Oid get_element_type(Oid typid); +extern Oid get_array_type(Oid typid); +extern Oid get_base_element_type(Oid typid); +extern void getTypeInputInfo(Oid type, Oid* typInput, Oid* typIOParam); +extern void getTypeOutputInfo(Oid type, Oid* typOutput, bool* typIsVarlena); +extern void getTypeBinaryInputInfo(Oid type, Oid* typReceive, Oid* typIOParam); +extern void getTypeBinaryOutputInfo(Oid type, Oid* typSend, bool* typIsVarlena); +extern Oid get_typmodin(Oid typid); +extern Oid get_typcollation(Oid typid); +extern bool type_is_collatable(Oid typid); +extern Oid getBaseType(Oid typid); +extern Oid getBaseTypeAndTypmod(Oid typid, int32* typmod); +#ifdef PGXC +extern char* get_cfgname(Oid cfgid); +extern char* get_typename(Oid typid); +extern char* get_enumlabelname(Oid enumlabelid); +extern char* get_exprtypename(Oid enumlabelid); +extern char* get_typename_with_namespace(Oid typid); +extern Oid get_typeoid_with_namespace(const char* typname); +extern char* get_pgxc_nodename(Oid nodeoid, NameData* namedata = NULL); +extern char* get_pgxc_nodename_noexcept(Oid nodeoid, NameData *nodename = NULL); +extern Oid get_pgxc_nodeoid(const char* nodename); +extern Oid get_pgxc_datanodeoid(const char* nodename, bool missingOK); +extern bool check_pgxc_node_name_is_exist( + const char* nodename, const char* host, int port, int comm_sctp_port, int comm_control_port); +extern Oid get_pgxc_primary_datanode_oid(Oid nodeoid); +extern char* get_pgxc_node_name_by_node_id(int4 node_id, bool handle_error = true); +extern uint32 get_pgxc_node_id(Oid nodeid); +extern void get_node_info(const char* nodename, bool* node_is_ccn, ItemPointer tuple_pos); +extern bool is_pgxc_central_nodeid(Oid nodeid); +extern bool is_pgxc_central_nodename(const char*); +extern Oid get_pgxc_central_nodeid(void); +extern char get_pgxc_nodetype(Oid nodeid); +extern char get_pgxc_nodetype_refresh_cache(Oid nodeid); +extern int get_pgxc_nodeport(Oid nodeid); +extern int get_pgxc_nodesctpport(Oid nodeid); +extern int get_pgxc_nodestrmctlport(Oid nodeid); +extern char* get_pgxc_nodehost(Oid nodeid); +extern int get_pgxc_nodeport1(Oid nodeid); +extern int get_pgxc_nodesctpport1(Oid nodeid); +extern int get_pgxc_nodestrmctlport1(Oid nodeid); +extern char* get_pgxc_groupname(Oid groupoid, char* groupname = NULL); +extern char* get_pgxc_nodehost1(Oid nodeid); +extern char* get_pgxc_node_formdata(const char* nodename); +extern bool is_pgxc_nodepreferred(Oid nodeid); +extern bool is_pgxc_nodeprimary(Oid nodeid); +extern bool is_pgxc_nodeactive(Oid nodeid); +extern bool is_pgxc_hostprimary(Oid nodeid); +extern bool node_check_host(const char* host, Oid nodeid); +extern Oid get_pgxc_groupoid(const char* groupname, bool missing_ok = true); +extern char get_pgxc_groupkind(Oid group_oid); +extern int get_pgxc_groupmembers(Oid groupid, Oid** members); +extern int get_pgxc_groupmembers_redist(Oid groupid, Oid** members); +extern char get_pgxc_group_redistributionstatus(Oid groupid); +extern DistributeBy* getTableDistribution(Oid srcRelid); +extern DistributeBy* getTableHBucketDistribution(Relation rel); +extern int get_pgxc_classnodes(Oid tableid, Oid** nodes); +extern Oid get_pgxc_class_groupoid(Oid tableoid); +extern Oid get_resource_pool_oid(const char* poolname); +extern char* get_resource_pool_name(Oid poolid); +extern Form_pg_resource_pool get_resource_pool_param(Oid poolid, Form_pg_resource_pool rp); +extern char* get_resource_pool_ngname(Oid poolid); +extern bool is_resource_pool_foreign(Oid poolid); +extern Oid get_workload_group_oid(const char* groupname); +extern char* get_workload_group_name(Oid groupid); +extern Oid get_application_mapping_oid(const char* appname); +extern char* get_application_mapping_name(Oid appoid); +#endif +extern int32 get_typavgwidth(Oid typid, int32 typmod); +extern int32 get_attavgwidth(Oid relid, AttrNumber attnum, bool ispartition); +extern bool get_attstatsslot(HeapTuple statstuple, Oid atttype, int32 atttypmod, int reqkind, Oid reqop, Oid* actualop, + Datum** values, int* nvalues, float4** numbers, int* nnumbers); +extern bool get_attmultistatsslot(HeapTuple statstuple, Oid atttype, int32 atttypmod, int reqkind, Oid reqop, + Oid* actualop, Datum** values, int* nvalues, float4** numbers, int* nnumbers, bool** nulls = NULL); +extern double get_attstadndistinct(HeapTuple statstuple); +extern void free_attstatsslot(Oid atttype, Datum* values, int nvalues, float4* numbers, int nnumbers); +extern char* get_namespace_name(Oid nspid); +extern Oid get_range_subtype(Oid rangeOid); +extern char* get_cfgnamespace(Oid cfgid); +extern char* get_typenamespace(Oid typid); +extern char* get_enumtypenamespace(Oid enumlabelid); +extern Oid get_typeoid(Oid namespaceId, const char* typname); +extern Oid get_enumlabeloid(Oid enumtypoid, const char* enumlabelname); +extern Oid get_operator_oid(const char* operatorName, Oid operatorNamespace, Oid leftObjectId, Oid rightObjectId); +extern void get_oper_name_namespace_oprs(Oid operid, char** oprname, char** nspname, Oid* oprleft, Oid* oprright); +extern Oid get_func_oid(const char* funcname, Oid funcnamespace, Expr* expr); +extern Oid get_func_oid_ext(const char* funcname, Oid funcnamespace, Oid funcrettype, int funcnargs, Oid* funcargstype); +extern Oid get_my_temp_schema(); +extern bool check_rel_is_partitioned(Oid relid); +extern Oid partid_get_parentid(Oid partid); +extern bool is_not_strict_agg(Oid funcOid); +extern bool is_pgxc_class_table(Oid tableoid); +extern Oid get_valid_relname_relid(const char* relnamespace, const char* relname); +extern bool get_func_iswindow(Oid funcid); + +#define type_is_array(typid) (get_element_type(typid) != InvalidOid) +/* type_is_array_domain accepts both plain arrays and domains over arrays */ +#define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid) + +#define TypeIsToastable(typid) (get_typstorage(typid) != 'p') + +#endif /* LSYSCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/median_aggs.h postgresql-hll-2.14/include/include/utils/median_aggs.h --- postgresql-hll-2.14_old/include/include/utils/median_aggs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/median_aggs.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * median_aggs.h + * Aggregate for computing the statistical median + * + * IDENTIFICATION + * src/include/utils/median_aggs.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MEDIAN_AGGS_H +#define MEDIAN_AGGS_H + +#include "fmgr.h" + +extern Datum median_transfn(PG_FUNCTION_ARGS); +extern Datum median_float8_finalfn(PG_FUNCTION_ARGS); +extern Datum median_interval_finalfn(PG_FUNCTION_ARGS); + +#endif /* MEDIAN_AGGS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/utils/memgroup.h postgresql-hll-2.14/include/include/utils/memgroup.h --- postgresql-hll-2.14_old/include/include/utils/memgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/memgroup.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * memgroup.h + * Add memory context group + * + * IDENTIFICATION + * src/include/utils/memgroup.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MEMGROUP_H +#define MEMGROUP_H + +#include "utils/palloc.h" + +typedef enum { + MEMORY_CONTEXT_CBB, + MEMORY_CONTEXT_COMMUNICATION, + MEMORY_CONTEXT_DEFAULT, + MEMORY_CONTEXT_DFX, + MEMORY_CONTEXT_EXECUTOR, + MEMORY_CONTEXT_NUMA, + MEMORY_CONTEXT_OPTIMIZER, + MEMORY_CONTEXT_SECURITY, + MEMORY_CONTEXT_STORAGE, + MEMORY_CONTEXT_TSDB, + MEMORY_CONTEXT_STREAMING, + MEMORY_CONTEXT_MAX +} MemoryGroupType; + +class MemoryContextGroup : public BaseObject { +public: + MemoryContextGroup(); + ~MemoryContextGroup() {} + void Init(MemoryContext parent, bool is_shared = false); + MemoryContext const GetMemCxtGroup(MemoryGroupType type); + +private: + MemoryContext memory_context_group[MEMORY_CONTEXT_MAX]; + static const char* memory_context_group_name[MEMORY_CONTEXT_MAX]; +}; + +#endif /* MEMGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/memprot.h postgresql-hll-2.14/include/include/utils/memprot.h --- postgresql-hll-2.14_old/include/include/utils/memprot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/memprot.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,106 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memprot.h + * + * + * + * IDENTIFICATION + * src/include/utils/memprot.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMPROT_H +#define MEMPROT_H + +#include "c.h" +#include "utils/aset.h" + +#define BITS_IN_MB 20 +#define BITS_IN_KB 10 + +#define MIN_PROCESS_LIMIT (2 * 1024 * 1024) // 2GB +#define MEMPROT_INIT_SIZE 200 // 200MB for initialization memory + +#define CHUNKS_TO_MB(chunks) ((chunks) << (chunkSizeInBits - BITS_IN_MB)) +#define MB_TO_CHUNKS(mb) ((mb) >> (chunkSizeInBits - BITS_IN_MB)) +#define CHUNKS_TO_BYTES(chunks) (((int64)chunks) << chunkSizeInBits) +#define BYTES_TO_CHUNKS(bytes) ((bytes) >> chunkSizeInBits) +#define BYTES_TO_MB(bytes) ((bytes) >> BITS_IN_MB) + +#define HIGH_PROCMEM_MARK 80 // 80% of total node memory +#define LOW_PROCMEM_MARK 60 // 60% of total node memory + +#define LOW_WORKMEM_CHUNK 256 + +#define MAX_MEMORY_FAULT_PERCENT (INT_MAX) + +#define SELF_SHARED_MEMCTX_LIMITATION (100 * 1024 * 1024) // 100MB +#define SELF_GENRIC_MEMCTX_LIMITATION (10 * 1024 * 1024) // 10MB +#define MAX_SHARED_MEMCTX_LIMITATION (2 * 1024) // 2GB +#define MAX_GENRIC_MEMCTX_LIMITATION (100 * 1024 * 1024) // 100MB +#define MAX_SHARED_MEMCTX_SIZE (10 * 1024) // 10GB + +#define MAX_COMM_USED_SIZE (4 * 1024) // 4GB +#define SELF_QUERY_LIMITATION (300) // 300MB + +#define PROCMEM_HIGHWATER_THRESHOLD (5 * 1024) // 5G + +/* 200* 1024 kB */ +/* Must be same as UDF_DEFAULT_MEMORY in agent_main.cpp and udf_memory_limit in cluster_guc.conf */ +#define UDF_DEFAULT_MEMORY (200 * 1024) + +extern unsigned int chunkSizeInBits; + +extern int32 maxChunksPerProcess; +extern int32 processMemInChunks; +extern int32 peakChunksPerProcess; +extern int32 shareTrackedMemChunks; +extern int32 peakChunksSharedContext; +extern int32 maxChunksPerQuery; +extern int32 comm_original_memory; +extern int32 maxSharedMemory; +extern int32 dynmicTrackedMemChunks; +extern int64 storageTrackedBytes; +extern int32 backendReservedMemInChunk; +extern int32 backendUsedMemInChunk; + +/* functions from memprot.cpp */ +#ifdef MEMORY_CONTEXT_CHECKING +extern bool gs_memory_enjection(void); +#endif + +extern bool gs_sysmemory_busy(int64 used, bool strict); + +extern bool gs_sysmemory_avail(int64 requestedBytes); + +extern void gs_memprot_thread_init(void); + +extern void gs_memprot_init(Size size); + +extern void gs_memprot_process_gpu_memory(uint32 size); + +extern void gs_memprot_reset_beyondchunk(void); + +#define GS_MEMPROT_MALLOC(sz, needProtect) MemoryProtectFunctions::gs_memprot_malloc(sz, needProtect) +#define GS_MEMPROT_FREE(ptr, sz) MemoryProtectFunctions::gs_memprot_free(ptr, sz) +#define GS_MEMPROT_REALLOC(ptr, sz, newsz, needProtect) MemoryProtectFunctions::gs_memprot_realloc(ptr, sz, newsz, needProtect) +#define GS_MEMPROT_MEMALIGN(ptr, align, sz, needProtect) MemoryProtectFunctions::gs_posix_memalign(ptr, align, sz, needProtect) +#define GS_MEMPROT_SHARED_MALLOC(sz) MemoryProtectFunctions::gs_memprot_malloc(sz) +#define GS_MEMPROT_SHARED_FREE(ptr, sz) MemoryProtectFunctions::gs_memprot_free(ptr, sz) + +extern int getSessionMemoryUsageMB(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/memtrace.h postgresql-hll-2.14/include/include/utils/memtrace.h --- postgresql-hll-2.14_old/include/include/utils/memtrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/memtrace.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memtrace.h + * + * IDENTIFICATION + * src/include/utils/memtrace.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMTRACE_H +#define MEMTRACE_H + +#include "c.h" +#include "utils/aset.h" +#include "nodes/memnodes.h" + +typedef struct MemoryAllocInfo { + void* pointer; + const char* file; + int line; + Size size; + MemoryContext context; + char context_name[NAMEDATALEN]; +} MemoryAllocInfo; + +typedef struct MemoryAllocDetailKey { + char name[NAMEDATALEN]; + const char* file; + int line; +} MemoryAllocDetailKey; + +typedef struct MemoryAllocDetail { + MemoryAllocDetailKey detail_key; + Size size; +} MemoryAllocDetail; + +typedef struct MemoryAllocDetailList { + MemoryAllocDetail* entry; + MemoryAllocDetailList* next; +} MemoryAllocDetailList; + +extern Datum track_memory_context(PG_FUNCTION_ARGS); +extern bool MemoryContextShouldTrack(const char* name); +extern void InsertTrackMemoryInfo(const void* pointer, const MemoryContext context, const char* file, int line, Size size); +extern void RemoveTrackMemoryInfo(const void* pointer); +extern void RemoveTrackMemoryContext(const MemoryContext context); +extern MemoryAllocDetailList* GetMemoryTrackInfo(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/memtrack.h postgresql-hll-2.14/include/include/utils/memtrack.h --- postgresql-hll-2.14_old/include/include/utils/memtrack.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/memtrack.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memtrack.h + * This file contains declarations for memory tracking utility functions. + * The relative GUC to trigger the memory tracking feature is listed: + * enable_memory_tracking: the GUC must be set as ON; + * enable_memory_logging: to generate the file with memory context information + * memory_detail_logging: to generate the file with debug allocation information + * + * + * IDENTIFICATION + * src/include/utils/memtrack.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMTRACK_H +#define MEMTRACK_H + +#include "c.h" +#include "utils/aset.h" +#include "nodes/memnodes.h" + +extern THR_LOCAL int guc_memory_tracking_mode; + +extern THR_LOCAL char mctx_track_name[256]; + +extern THR_LOCAL long mctx_track_value; + +extern void MemoryTrackingInit(void); +extern void MemoryTrackingCreate(MemoryContext set, MemoryContext parent); +extern void MemoryTrackingAllocInfo(MemoryContext context, Size size); +extern void MemoryTrackingFreeInfo(MemoryContext context, Size size); +extern void MemoryTrackingLoggingToFile(MemoryTrack track, int key); +extern void MemoryTrackingNodeFree(MemoryTrack track); +extern void MemoryTrackingOutputFile(void); + +#ifdef MEMORY_CONTEXT_CHECKING + +extern void MemoryTrackingParseGUC(const char* val); + +extern void MemoryTrackingDetailInfo(MemoryContext context, Size reqSize, Size chunkSize, const char* file, int line); + +extern void MemoryTrackingDetailInfoToFile(void); + +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/memutils.h postgresql-hll-2.14/include/include/utils/memutils.h --- postgresql-hll-2.14_old/include/include/utils/memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/memutils.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,196 @@ +/* ------------------------------------------------------------------------- + * + * memutils.h + * This file contains declarations for memory allocation utility + * functions. These are functions that are not quite widely used + * enough to justify going in utils/palloc.h, but are still part + * of the API of the memory management subsystem. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/memutils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMUTILS_H +#define MEMUTILS_H + +#include "nodes/memnodes.h" +#include "pgtime.h" +#include "storage/proc.h" + +enum MemoryContextType { + STANDARD_CONTEXT, // postgres orignal context + STACK_CONTEXT, // a simple context, do not support free single pointer + SHARED_CONTEXT, // shared context used by different threads + MEMALIGN_CONTEXT, // the context only used to allocate the aligned memory + MEMALIGN_SHRCTX, // the shared context only used to allocate the aligned memory +}; + +/* + * MaxAllocSize + * Quasi-arbitrary limit on size of allocations. + * + * Note: + * There is no guarantee that allocations smaller than MaxAllocSize + * will succeed. Allocation requests larger than MaxAllocSize will + * be summarily denied. + * + * XXX This is deliberately chosen to correspond to the limiting size + * of varlena objects under TOAST. See VARSIZE_4B() and related macros + * in postgres.h. Many datatypes assume that any allocatable size can + * be represented in a varlena header. + * + * XXX Also, various places in aset.c assume they can compute twice an + * allocation's size without overflow, so beware of raising this. + */ +#define MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define MaxBuildAllocSize ((Size)0x3ffffff) /* 64MB - 1 */ + +#define AllocSizeIsValid(size) ((Size)(size) <= MaxAllocSize) + +#define MaxAllocHugeSize ((Size)-1 >> 1) /* SIZE_MAX / 2 */ + +#define AllocHugeSizeIsValid(size) ((Size)(size) <= MaxAllocHugeSize) + +/* + * All chunks allocated by any memory context manager are required to be + * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. + * A currently-allocated chunk must contain a backpointer to its owning + * context as well as the allocated size of the chunk. The backpointer is + * used by pfree() and repalloc() to find the context to call. The allocated + * size is not absolutely essential, but it's expected to be needed by any + * reasonable implementation. + */ +typedef struct StandardChunkHeader { + MemoryContext context; /* owning context */ + Size size; /* size of data space allocated in chunk */ +#ifdef MEMORY_CONTEXT_CHECKING + /* when debugging memory usage, also store actual requested size */ + Size requested_size; + const char* file; + int line; +#endif +} StandardChunkHeader; + +#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader)) + +// Process wise memory context +// +extern MemoryContext AdioSharedContext; +extern MemoryContext ProcSubXidCacheContext; +extern MemoryContext PmTopMemoryContext; +extern MemoryContext StreamInfoContext; + +extern THR_LOCAL PGDLLIMPORT MemoryContext ErrorContext; + +/* + * Memory-context-type-independent functions in mcxt.c + */ +extern void MemoryContextInit(void); +extern void MemoryContextReset(MemoryContext context); +extern void MemoryContextDelete(MemoryContext context); +extern void MemoryContextResetChildren(MemoryContext context); +extern void MemoryContextDeleteChildren(MemoryContext context, List* context_list = NULL); +extern void MemoryContextDestroyAtThreadExit(MemoryContext context); +extern void MemoryContextResetAndDeleteChildren(MemoryContext context); +extern void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent); +extern Size GetMemoryChunkSpace(void* pointer); +extern MemoryContext GetMemoryChunkContext(void* pointer); +extern MemoryContext MemoryContextGetParent(MemoryContext context); +extern bool MemoryContextIsEmpty(MemoryContext context); +extern void MemoryContextStats(MemoryContext context); +extern void MemoryContextSeal(MemoryContext context); +extern void MemoryContextUnSeal(MemoryContext context); +extern void MemoryContextUnSealChildren(MemoryContext context); + +#ifdef MEMORY_CONTEXT_CHECKING +extern void MemoryContextCheck(MemoryContext context, bool own_by_session); +#define MemoryContextCheck2(mctx) +#endif + +extern bool MemoryContextContains(MemoryContext context, void* pointer); + +extern MemoryContext MemoryContextOriginal(const char* node); + +/* + * This routine handles the context-type-independent part of memory + * context creation. It's intended to be called from context-type- + * specific creation routines, and noplace else. + */ +extern MemoryContext MemoryContextCreate( + NodeTag tag, Size size, MemoryContext parent, const char* name, const char* file, int line); + +/* Interface for PosgGIS and has the same structure with PG's MemoryContextCreate*/ +extern MemoryContext MemoryContextCreate( + NodeTag tag, Size size, MemoryContextMethods* methods, MemoryContext parent, const char* name); + +/* + * Memory-context-type-specific functions + */ +#define DEFAULT_MEMORY_CONTEXT_MAX_SIZE 0 /* 0 MB as default value for AllocSetContextCreat function */ +#define SHARED_MEMORY_CONTEXT_MAX_SIZE (100 * 1024 * 1024) /* 100 MB */ +/* aset.c */ +extern MemoryContext AllocSetContextCreate(MemoryContext parent, const char* name, Size minContextSize, + Size initBlockSize, Size maxBlockSize, MemoryContextType type = STANDARD_CONTEXT, + Size maxSize = DEFAULT_MEMORY_CONTEXT_MAX_SIZE, bool isSession = false); + +/* + * Recommended default alloc parameters, suitable for "ordinary" contexts + * that might hold quite a lot of data. + */ +#define ALLOCSET_DEFAULT_MINSIZE 0 +#define ALLOCSET_DEFAULT_INITSIZE (1 * 1024) +#define ALLOCSET_DEFAULT_MAXSIZE (1 * 1024 * 1024) +#define ALLOCSET_DEFAULT_SIZES ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE + +/* + * Recommended alloc parameters for "small" contexts that are not expected + * to contain much data (for example, a context to contain a query plan). + */ +#define ALLOCSET_SMALL_MINSIZE 0 +#define ALLOCSET_SMALL_INITSIZE (1 * 1024) +#define ALLOCSET_SMALL_MAXSIZE (8 * 1024) + +/* default grow ratio for sort and materialize when it spreads */ +#define DEFAULT_GROW_RATIO 2.0 + +/* default auto spread min ratio, and memory spread under this ratio is abondaned */ +#define MEM_AUTO_SPREAD_MIN_RATIO 0.1 + +// AutoContextSwitch +// Auto object for memoryContext switch +// +class AutoContextSwitch { +public: + AutoContextSwitch(MemoryContext memContext) + { + if (memContext == NULL) { + m_oldMemContext = CurrentMemoryContext; + } else { + m_oldMemContext = MemoryContextSwitchTo(memContext); + } + }; + + ~AutoContextSwitch() + { + MemoryContextSwitchTo(m_oldMemContext); + } + +private: + MemoryContext m_oldMemContext; +}; + +/* In case we haven't init u_sess->when we try to create memory context and alloc memory */ +#define IS_USESS_AVAILABLE (likely(u_sess != NULL)) +#define GS_MP_INITED (t_thrd.utils_cxt.gs_mp_inited) +#define MEMORY_TRACKING_MODE (IS_USESS_AVAILABLE ? u_sess->attr.attr_memory.memory_tracking_mode : 0) +#define ENABLE_MEMORY_CONTEXT_CONTROL \ + (IS_USESS_AVAILABLE ? u_sess->attr.attr_memory.enable_memory_context_control : false) +#define MEMORY_FAULT_PERCENT (IS_USESS_AVAILABLE ? u_sess->attr.attr_resource.memory_fault_percent : 0) +#define STATEMENT_MAX_MEM (IS_USESS_AVAILABLE ? u_sess->attr.attr_sql.statement_max_mem : 0) + +#endif /* MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/mmpool.h postgresql-hll-2.14/include/include/utils/mmpool.h --- postgresql-hll-2.14_old/include/include/utils/mmpool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/mmpool.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,121 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * mmpool.h + * + * + * + * IDENTIFICATION + * src/include/utils/mmpool.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_UTILS_MMPOOL_H_ +#define SRC_INCLUDE_UTILS_MMPOOL_H_ + +#include "postgres.h" +#include "utils/memutils.h" +#include "nodes/pg_list.h" + +struct MemoryBlock { + int64 blkSize; + bool isFree; + + MemoryBlock* prev; + MemoryBlock* next; +}; + +#define MEMORY_BLOCK_HEADER TYPEALIGN(ALIGNOF_LONG, sizeof(MemoryBlock)) +#define MEMORY_BLOCK_MIN_SIZE (2 * MEMORY_BLOCK_HEADER) + +struct MemoryBlockListHeader { + MemoryBlock* start; + MemoryBlock* end; +}; + +#define POOL_INIT_SUCCESS 0 +#define POOL_INIT_FAIL 1 + +class MemoryPool { +public: + // constructor + MemoryPool(); + + // destructor + ~MemoryPool(); + + // init the memory pool. + int CreatePool(); + + // release the memory pool. + void ReleasePool(); + + // Malloc the memory from memory pool. + void* Malloc(int64 sizeBytes); + + // Realloc the memory + void* Realloc(void* addr, int64 sizeBytes); + + // Free the memory + void Free(void* addr); + + // pool is ready? + inline bool Ready() + { + return m_ready; + } + + // static function to init/deinit the memory pool + static int Init(); + + static void Deinit(); + +private: + // Split a block for fit the size + bool SplitFreeList(int idx); + + // Merge block and its buddy + void MergeBlock(void* addr, MemoryBlock* block, MemoryBlock* blockBuddy, int idx); + + MemoryBlock* FindBuddy(MemoryBlock* block, int64 size); + + void AddLast(int idx, MemoryBlock* blk); + + void AddFirst(int idx, MemoryBlock* blk); + + void Remove(int idx, MemoryBlock* blk); + +private: + // the memory buffer + char* m_buf; // + + // memory buffer size + int64 m_size; + + // the usage size of memory buffer + int64 m_use; + + // concurrency control for mutex + pthread_mutex_t m_mutex; // lock + + // free list for the memory pool. + MemoryBlockListHeader m_freeList[64]; + + // flag to indicate the pool is ready + volatile bool m_ready; +}; + +#endif /* SRC_INCLUDE_UTILS_MMPOOL_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/nabstime.h postgresql-hll-2.14/include/include/utils/nabstime.h --- postgresql-hll-2.14_old/include/include/utils/nabstime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/nabstime.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,161 @@ +/* ------------------------------------------------------------------------- + * + * nabstime.h + * Definitions for the "new" abstime code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/nabstime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NABSTIME_H +#define NABSTIME_H + +#include + +#include "fmgr.h" +#include "pgtime.h" + +/* ---------------------------------------------------------------- + * + * time types + support macros + * + * ---------------------------------------------------------------- + */ + +/* + * Although time_t generally is a long int on 64 bit systems, these two + * types must be 4 bytes, because that's what pg_type.h assumes. They + * should be yanked (long) before 2038 and be replaced by timestamp and + * interval. + */ +typedef int32 AbsoluteTime; +typedef int32 RelativeTime; + +typedef struct { + int32 status; + AbsoluteTime data[2]; +} TimeIntervalData; + +typedef TimeIntervalData* TimeInterval; + +/* + * Macros for fmgr-callable functions. + */ +#define DatumGetAbsoluteTime(X) ((AbsoluteTime)DatumGetInt32(X)) +#define DatumGetRelativeTime(X) ((RelativeTime)DatumGetInt32(X)) +#define DatumGetTimeInterval(X) ((TimeInterval)DatumGetPointer(X)) + +#define AbsoluteTimeGetDatum(X) Int32GetDatum(X) +#define RelativeTimeGetDatum(X) Int32GetDatum(X) +#define TimeIntervalGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n)) +#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n)) + +#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x) +#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x) +#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x) + +/* + * Reserved values + * Epoch is Unix system time zero, but needs to be kept as a reserved + * value rather than converting to time since timezone calculations + * might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20 + * + * Pre-v6.1 code had large decimal numbers for reserved values. + * These were chosen as special 32-bit bit patterns, + * so redefine them explicitly using these bit patterns. - tgl 97/02/24 + */ +#define INVALID_ABSTIME ((AbsoluteTime)0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ +#define NOEND_ABSTIME ((AbsoluteTime)0x7FFFFFFC) /* 2147483645 (2^31 - 3) */ +#define NOSTART_ABSTIME ((AbsoluteTime)INT_MIN) /* -2147483648 */ + +#define INVALID_RELTIME ((RelativeTime)0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ + +#define AbsoluteTimeIsValid(time) ((bool)((time) != INVALID_ABSTIME)) + +/* + * Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any + * AbsoluteTime values less than it. Therefore, we can code the test + * "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids + * compiler bugs on some platforms. --- tgl & az, 11/2000 + */ +#define AbsoluteTimeIsReal(time) \ + ((bool)(((AbsoluteTime)(time)) < NOEND_ABSTIME && ((AbsoluteTime)(time)) != NOSTART_ABSTIME)) + +#define RelativeTimeIsValid(time) ((bool)(((RelativeTime)(time)) != INVALID_RELTIME)) + +/* + * nabstime.c prototypes + */ +extern Datum abstimein(PG_FUNCTION_ARGS); +extern Datum abstimeout(PG_FUNCTION_ARGS); +extern Datum abstimerecv(PG_FUNCTION_ARGS); +extern Datum abstimesend(PG_FUNCTION_ARGS); + +extern Datum abstimeeq(PG_FUNCTION_ARGS); +extern Datum abstimene(PG_FUNCTION_ARGS); +extern Datum abstimelt(PG_FUNCTION_ARGS); +extern Datum abstimegt(PG_FUNCTION_ARGS); +extern Datum abstimele(PG_FUNCTION_ARGS); +extern Datum abstimege(PG_FUNCTION_ARGS); +extern Datum abstime_finite(PG_FUNCTION_ARGS); + +extern Datum timestamp_abstime(PG_FUNCTION_ARGS); +extern Datum abstime_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_abstime(PG_FUNCTION_ARGS); +extern Datum abstime_timestamptz(PG_FUNCTION_ARGS); + +extern Datum reltimein(PG_FUNCTION_ARGS); +extern Datum reltimeout(PG_FUNCTION_ARGS); +extern Datum reltimerecv(PG_FUNCTION_ARGS); +extern Datum reltimesend(PG_FUNCTION_ARGS); +extern Datum tintervalin(PG_FUNCTION_ARGS); +extern Datum tintervalout(PG_FUNCTION_ARGS); +extern Datum tintervalrecv(PG_FUNCTION_ARGS); +extern Datum tintervalsend(PG_FUNCTION_ARGS); +extern Datum interval_reltime(PG_FUNCTION_ARGS); +extern Datum reltime_interval(PG_FUNCTION_ARGS); +extern Datum mktinterval(PG_FUNCTION_ARGS); +extern Datum timepl(PG_FUNCTION_ARGS); +extern Datum timemi(PG_FUNCTION_ARGS); + +extern Datum intinterval(PG_FUNCTION_ARGS); +extern Datum tintervalrel(PG_FUNCTION_ARGS); +extern Datum timenow(PG_FUNCTION_ARGS); +extern Datum reltimeeq(PG_FUNCTION_ARGS); +extern Datum reltimene(PG_FUNCTION_ARGS); +extern Datum reltimelt(PG_FUNCTION_ARGS); +extern Datum reltimegt(PG_FUNCTION_ARGS); +extern Datum reltimele(PG_FUNCTION_ARGS); +extern Datum reltimege(PG_FUNCTION_ARGS); +extern Datum tintervalsame(PG_FUNCTION_ARGS); +extern Datum tintervaleq_withhead(PG_FUNCTION_ARGS); +extern Datum tintervaleq(PG_FUNCTION_ARGS); +extern Datum tintervalne(PG_FUNCTION_ARGS); +extern Datum tintervallt(PG_FUNCTION_ARGS); +extern Datum tintervalgt(PG_FUNCTION_ARGS); +extern Datum tintervalle(PG_FUNCTION_ARGS); +extern Datum tintervalge(PG_FUNCTION_ARGS); +extern Datum tintervalleneq(PG_FUNCTION_ARGS); +extern Datum tintervallenne(PG_FUNCTION_ARGS); +extern Datum tintervallenlt(PG_FUNCTION_ARGS); +extern Datum tintervallengt(PG_FUNCTION_ARGS); +extern Datum tintervallenle(PG_FUNCTION_ARGS); +extern Datum tintervallenge(PG_FUNCTION_ARGS); +extern Datum tintervalct(PG_FUNCTION_ARGS); +extern Datum tintervalov(PG_FUNCTION_ARGS); +extern Datum tintervalstart(PG_FUNCTION_ARGS); +extern Datum tintervalend(PG_FUNCTION_ARGS); +extern Datum timeofday(PG_FUNCTION_ARGS); + +/* non-fmgr-callable support routines */ +extern AbsoluteTime GetCurrentAbsoluteTime(void); +extern void abstime2tm(AbsoluteTime time, int* tzp, struct pg_tm* tm, char** tzn); + +#endif /* NABSTIME_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/numeric_gs.h postgresql-hll-2.14/include/include/utils/numeric_gs.h --- postgresql-hll-2.14_old/include/include/utils/numeric_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/numeric_gs.h 2020-12-12 17:06:43.289348580 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * numeric_gs.h + * Definitions for the exact numeric data type of Postgres + * + * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/utils/numeric_gs.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef _PG_NUMERIC_GS_H_ +#define _PG_NUMERIC_GS_H_ + +#include "fmgr.h" + +#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(uint16) + sizeof(int16)) +#define NUMERIC_HDRSZ_SHORT (VARHDRSZ + sizeof(uint16)) + +#define NUMERIC_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_SIGN_MASK) +#define NUMERIC_NB_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_BI_MASK) // nan or biginteger + +#define NUMERIC_IS_NAN(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_NAN) +#define NUMERIC_IS_SHORT(n) (NUMERIC_FLAGBITS(n) == NUMERIC_SHORT) + +/* + * big integer macro + * determine the type of numeric + * verify whether a numeric data is NAN or BI by it's flag. + */ +#define NUMERIC_FLAG_IS_NAN(n) (n == NUMERIC_NAN) +#define NUMERIC_FLAG_IS_NANORBI(n) (n >= NUMERIC_NAN) +#define NUMERIC_FLAG_IS_BI(n) (n > NUMERIC_NAN) +#define NUMERIC_FLAG_IS_BI64(n) (n == NUMERIC_64) +#define NUMERIC_FLAG_IS_BI128(n) (n == NUMERIC_128) + +/* + * big integer macro + * determine the type of numeric + * verify whether a numeric data is NAN or BI by itself. + */ +#define NUMERIC_IS_NANORBI(n) (NUMERIC_NB_FLAGBITS(n) >= NUMERIC_NAN) +#define NUMERIC_IS_BI(n) (NUMERIC_NB_FLAGBITS(n) > NUMERIC_NAN) +#define NUMERIC_IS_BI64(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_64) +#define NUMERIC_IS_BI128(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_128) + +/* + * big integer macro + * the size of bi64 or bi128 is fixed. + * the size of bi64 is: + * 4 bytes(vl_len_) + 2 bytes(n_header) + 8 bytes(int64) = 14 bytes + * the size of bi128 is: + * 4 bytes(vl_len_) + 2 bytes(n_header) + 16 bytes(int128) = 22 bytes + */ +#define NUMERIC_64SZ (NUMERIC_HDRSZ_SHORT + sizeof(int64)) +#define NUMERIC_128SZ (NUMERIC_HDRSZ_SHORT + sizeof(int128)) + +/* + * big integer macro + * get the scale of bi64 or bi128. + * scale = n_header & NUMERIC_BI_SCALEMASK + * get the value of bi64 or bi128 + * convert NumericBi.n_data to int64 or int128 pointer, then + * assign value. + */ +#define NUMERIC_BI_SCALE(n) ((n)->choice.n_header & NUMERIC_BI_SCALEMASK) +#define NUMERIC_64VALUE(n) (*((int64*)((n)->choice.n_bi.n_data))) + +/* + * If the flag bits are NUMERIC_SHORT or NUMERIC_NAN, we want the short header; + * otherwise, we want the long one. Instead of testing against each value, we + * can just look at the high bit, for a slight efficiency gain. + */ +#define NUMERIC_HEADER_SIZE(n) (VARHDRSZ + sizeof(uint16) + (((NUMERIC_FLAGBITS(n) & 0x8000) == 0) ? sizeof(int16) : 0)) + +/* + * Short format definitions. + */ +#define NUMERIC_SHORT_SIGN_MASK 0x2000 +#define NUMERIC_SHORT_DSCALE_MASK 0x1F80 +#define NUMERIC_SHORT_DSCALE_SHIFT 7 +#define NUMERIC_SHORT_DSCALE_MAX (NUMERIC_SHORT_DSCALE_MASK >> NUMERIC_SHORT_DSCALE_SHIFT) +#define NUMERIC_SHORT_WEIGHT_SIGN_MASK 0x0040 +#define NUMERIC_SHORT_WEIGHT_MASK 0x003F +#define NUMERIC_SHORT_WEIGHT_MAX NUMERIC_SHORT_WEIGHT_MASK +#define NUMERIC_SHORT_WEIGHT_MIN (-(NUMERIC_SHORT_WEIGHT_MASK + 1)) + +/* + * Extract sign, display scale, weight. + */ +#define NUMERIC_DSCALE_MASK 0x3FFF + +#define NUMERIC_SIGN(n) \ + (NUMERIC_IS_SHORT(n) ? (((n)->choice.n_short.n_header & NUMERIC_SHORT_SIGN_MASK) ? NUMERIC_NEG : NUMERIC_POS) \ + : NUMERIC_FLAGBITS(n)) +#define NUMERIC_DSCALE(n) \ + (NUMERIC_IS_SHORT((n)) ? ((n)->choice.n_short.n_header & NUMERIC_SHORT_DSCALE_MASK) >> NUMERIC_SHORT_DSCALE_SHIFT \ + : ((n)->choice.n_long.n_sign_dscale & NUMERIC_DSCALE_MASK)) +#define NUMERIC_WEIGHT(n) \ + (NUMERIC_IS_SHORT((n)) \ + ? (((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_SIGN_MASK ? ~NUMERIC_SHORT_WEIGHT_MASK : 0) | \ + ((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_MASK)) \ + : ((n)->choice.n_long.n_weight)) +#define NUMERIC_DIGITS(num) (NUMERIC_IS_SHORT(num) ? (num)->choice.n_short.n_data : (num)->choice.n_long.n_data) +#define NUMERIC_NDIGITS(num) ((VARSIZE(num) - NUMERIC_HEADER_SIZE(num)) / sizeof(NumericDigit)) + +/* + * @Description: copy bi64 to ptr, this operation no need to allocate memory + * @IN ptr: the numeric pointer + * @IN value: the value of bi64 + * @IN scale: the scale of bi64 + */ +#define MAKE_NUMERIC64(ptr, value, scale) \ + do { \ + Numeric result = (Numeric)(ptr); \ + SET_VARSIZE(result, NUMERIC_64SZ); \ + result->choice.n_header = NUMERIC_64 + (scale); \ + *((int64*)(result->choice.n_bi.n_data)) = (value); \ + } while (0) + +/* + * @Description: copy bi128 to ptr, this operation no need to allocate memory + * @IN ptr: the numeric pointer + * @IN value: the value of bi128 + * @IN scale: the scale of bi128 + */ +#define MAKE_NUMERIC128(ptr, value, scale) \ + do { \ + Numeric result = (Numeric)(ptr); \ + SET_VARSIZE(result, NUMERIC_128SZ); \ + result->choice.n_header = NUMERIC_128 + (scale); \ + errno_t rc = EOK; \ + rc = memcpy_s(result->choice.n_bi.n_data, sizeof(int128), (&value), sizeof(int128)); \ + securec_check(rc, "\0", "\0"); \ + } while (0) + +/* + * the header size of short numeric is 6 bytes. + * the same to NUMERIC_HEADER_SIZE but for short numeric. + */ +#define SHORT_NUMERIC_HEADER_SIZE (VARHDRSZ + sizeof(uint16)) + +/* + * the same to NUMERIC_NDIGITS but for short numeric. + */ +#define SHORT_NUMERIC_NDIGITS(num) \ + (AssertMacro(NUMERIC_IS_SHORT(num)), ((VARSIZE(num) - SHORT_NUMERIC_HEADER_SIZE) / sizeof(NumericDigit))) + +/* + * the same to NUMERIC_DIGITS but for short numeric. + */ +#define SHORT_NUMERIC_DIGITS(num) (AssertMacro(NUMERIC_IS_SHORT(num)), (num)->choice.n_short.n_data) + +/* + * @Description: allocate memory for bi64, and assign value to it + * @IN value: the value of bi64 + * @IN scale: the scale of bi64 + */ +inline Datum makeNumeric64(int64 value, uint8 scale) +{ + Numeric result; + result = (Numeric)palloc(NUMERIC_64SZ); + SET_VARSIZE(result, NUMERIC_64SZ); + result->choice.n_header = NUMERIC_64 + scale; + *((int64*)(result->choice.n_bi.n_data)) = value; + return (Datum)result; +} + +/* + * @Description: allocate memory for bi128, and assign value to it + * @IN value: the value of bi128 + * @IN scale: the scale of bi128 + */ +inline Datum makeNumeric128(int128 value, uint8 scale) +{ + Numeric result; + result = (Numeric)palloc(NUMERIC_128SZ); + SET_VARSIZE(result, NUMERIC_128SZ); + result->choice.n_header = NUMERIC_128 + scale; + errno_t rc = EOK; + rc = memcpy_s(result->choice.n_bi.n_data, sizeof(int128), &value, sizeof(int128)); + securec_check(rc, "\0", "\0") return (Datum)result; +} + +/* Convert bi64 or bi128 to short numeric */ +extern Numeric convert_int64_to_numeric(int64 data, uint8 scale); +extern Numeric convert_int128_to_numeric(int128 data, int scale); + +/* + * @Description: convert bi64 or bi128 to numeric type + * @IN val: the bi64 or bi128 data + * @Return: the result of numeric type + */ +inline Numeric makeNumericNormal(Numeric val) +{ + Assert(NUMERIC_IS_BI(val)); + + if (NUMERIC_IS_BI64(val)) { + return convert_int64_to_numeric(NUMERIC_64VALUE(val), NUMERIC_BI_SCALE(val)); + } + + else if (NUMERIC_IS_BI128(val)) { + int128 tmp_data = 0; + errno_t rc = EOK; + rc = memcpy_s(&tmp_data, sizeof(int128), val->choice.n_bi.n_data, sizeof(int128)); + securec_check(rc, "\0", "\0"); + return convert_int128_to_numeric(tmp_data, NUMERIC_BI_SCALE(val)); + } + + else { + elog(ERROR, "unrecognized big integer numeric format"); + } + return NULL; +} + +/* + * @Description: Detoast column numeric data. Column numeric is + * a short-header type. + * @IN num: input numeric data + * @return: Numeric - detoast numeric data + */ +inline Numeric DatumGetBINumericShort(Datum num) +{ + /* + * unlikely this is a short-header varlena --- convert to 4-byte header format + */ + struct varlena* new_attr = NULL; + struct varlena* old_attr = (struct varlena*)num; + Size data_size = VARSIZE_SHORT(old_attr) - VARHDRSZ_SHORT; + Size new_size = data_size + VARHDRSZ; + errno_t rc = EOK; + + new_attr = (struct varlena*)palloc(new_size); + SET_VARSIZE(new_attr, new_size); + rc = memcpy_s(VARDATA(new_attr), new_size, VARDATA_SHORT(old_attr), data_size); + securec_check(rc, "", ""); + old_attr = new_attr; + return (Numeric)old_attr; +} + +/* + * @Description: Detoast column numeric data. Column numeric is unlikely + * a short-header type, simplify macro DatumGetNumeric + * + * @IN num: input numeric data + * @return: Numeric - detoast numeric data + */ +inline Numeric DatumGetBINumeric(Datum num) +{ + if (likely(!VARATT_IS_SHORT(num))) { + return (Numeric)num; + } else { + return DatumGetBINumericShort(num); + } +} + +#endif /* _PG_NUMERIC_GS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/numeric.h postgresql-hll-2.14/include/include/utils/numeric.h --- postgresql-hll-2.14_old/include/include/utils/numeric.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/numeric.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,306 @@ +/* ------------------------------------------------------------------------- + * + * numeric.h + * Definitions for the exact numeric data type of Postgres + * + * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/utils/numeric.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_NUMERIC_H_ +#define _PG_NUMERIC_H_ + +#include "fmgr.h" + +/* ---------- + * Uncomment the following to enable compilation of dump_numeric() + * and dump_var() and to get a dump of any result produced by make_result(). + * ---------- +#define NUMERIC_DEBUG + */ + +/* ---------- + * Local data types + * + * Numeric values are represented in a base-NBASE floating point format. + * Each "digit" ranges from 0 to NBASE-1. The type NumericDigit is signed + * and wide enough to store a digit. We assume that NBASE*NBASE can fit in + * an int. Although the purely calculational routines could handle any even + * NBASE that's less than sqrt(INT_MAX), in practice we are only interested + * in NBASE a power of ten, so that I/O conversions and decimal rounding + * are easy. Also, it's actually more efficient if NBASE is rather less than + * sqrt(INT_MAX), so that there is "headroom" for mul_var and div_var_fast to + * postpone processing carries. + * + * Values of NBASE other than 10000 are considered of historical interest only + * and are no longer supported in any sense; no mechanism exists for the client + * to discover the base, so every client supporting binary mode expects the + * base-10000 format. If you plan to change this, also note the numeric + * abbreviation code, which assumes NBASE=10000. + * ---------- + */ + +#if 1 +#define NBASE 10000 +#define HALF_NBASE 5000 +#define DEC_DIGITS 4 /* decimal digits per NBASE digit */ +#define NUMERIC_SCALE_ADJUST(scale) ((int64)(scale + DEC_DIGITS - 1) / DEC_DIGITS) +#define MUL_GUARD_DIGITS 2 /* these are measured in NBASE digits */ +#define DIV_GUARD_DIGITS 4 + +typedef int16 NumericDigit; +#endif + +/* + * The Numeric type as stored on disk. + * + * If the high bits of the first word of a NumericChoice (n_header, or + * n_short.n_header, or n_long.n_sign_dscale) are NUMERIC_SHORT, then the + * numeric follows the NumericShort format; if they are NUMERIC_POS or + * NUMERIC_NEG, it follows the NumericLong format. If they are NUMERIC_NAN, + * it is a NaN. We currently always store a NaN using just two bytes (i.e. + * only n_header), but previous releases used only the NumericLong format, + * so we might find 4-byte NaNs on disk if a database has been migrated using + * pg_upgrade. In either case, when the high bits indicate a NaN, the + * remaining bits are never examined. Currently, we always initialize these + * to zero, but it might be possible to use them for some other purpose in + * the future. + * + * In the NumericShort format, the remaining 14 bits of the header word + * (n_short.n_header) are allocated as follows: 1 for sign (positive or + * negative), 6 for dynamic scale, and 7 for weight. In practice, most + * commonly-encountered values can be represented this way. + * + * In the NumericLong format, the remaining 14 bits of the header word + * (n_long.n_sign_dscale) represent the display scale; and the weight is + * stored separately in n_weight. + * + * NOTE: by convention, values in the packed form have been stripped of + * all leading and trailing zero digits (where a "digit" is of base NBASE). + * In particular, if the value is zero, there will be no digits at all! + * The weight is arbitrary in that case, but we normally set it to zero. + */ + +struct NumericShort { + uint16 n_header; /* Sign + display scale + weight */ + NumericDigit n_data[1]; /* Digits */ +}; + +struct NumericLong { + uint16 n_sign_dscale; /* Sign + display scale */ + int16 n_weight; /* Weight of 1st digit */ + NumericDigit n_data[1]; /* Digits */ +}; + +/* + * NumericBi is used for big integer(bi64 or bi128) + * n_header stores mark bits and scale of big integer, first 4 bits to + * distinguish bi64 and bi128, next 4 bits are not used, the last 8 bits + * store the scale of bit integer, scale value is between 0 and 38. + * n_data store big integer value(int64 or int128) + * + */ +struct NumericBi { + uint16 n_header; + uint8 n_data[1]; +}; + +/* + * Add NumericBi struct to NumericChoice + */ +union NumericChoice { + uint16 n_header; /* Header word */ + struct NumericLong n_long; /* Long form (4-byte header) */ + struct NumericShort n_short; /* Short form (2-byte header) */ + struct NumericBi n_bi; /* Short form (2-byte header) */ +}; + +struct NumericData { + int32 vl_len_; /* varlena header (do not touch directly!) */ + union NumericChoice choice; /* choice of format */ +}; + +/* The actual contents of Numeric are private to numeric.c */ +struct NumericData; +typedef struct NumericData* Numeric; + +/* + * Interpretation of high bits. + */ + +#define NUMERIC_SIGN_MASK 0xC000 +#define NUMERIC_POS 0x0000 +#define NUMERIC_NEG 0x4000 +#define NUMERIC_SHORT 0x8000 +#define NUMERIC_NAN 0xC000 + +/* + * big integer macro + * n_header is the mark bits of numeric struct, when numeric is NAN, n_header + * marked 0xC000. To distinguish bi64, bi128 and numeric, we use 0xD000 to mark + * bi64, 0xE000 marks bi128, others are numeric type. + */ +#define NUMERIC_64 0xD000 +#define NUMERIC_128 0xE000 +#define NUMERIC_BI_MASK 0xF000 +#define NUMERIC_BI_SCALEMASK 0x00FF +/* + * Hardcoded precision limit - arbitrary, but must be small enough that + * dscale values will fit in 14 bits. + */ +#define NUMERIC_MAX_PRECISION 1000 + +/* + * Internal limits on the scales chosen for calculation results + */ +#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION +#define NUMERIC_MIN_DISPLAY_SCALE 0 + +#define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2) + +/* + * For inherently inexact calculations such as division and square root, + * we try to get at least this many significant digits; the idea is to + * deliver a result no worse than float8 would. + */ +#define NUMERIC_MIN_SIG_DIGITS 16 + +/* + * numeric nan data length exclude header + */ +#define NUMERIC_NAN_DATALENGTH 0 +#define NUMERIC_ZERO_DATALENGTH 2 + +/* + * fmgr interface macros + * DatumGetNumeric function rebuild + */ +#define DatumGetNumeric(X) ((Numeric)PG_DETOAST_DATUM(X)) +#define DatumGetNumericCopy(X) ((Numeric)PG_DETOAST_DATUM_COPY(X)) +#define NumericGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n)) +#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x) + +/* + * Utility functions in numeric.c + */ +extern bool numeric_is_nan(Numeric num); +int32 numeric_maximum_size(int32 typmod); +extern char* numeric_out_sci(Numeric num, int scale); +extern Datum numtodsinterval(PG_FUNCTION_ARGS); +extern int cmp_numerics(Numeric num1, Numeric num2); + +// +// Numeric Compression Codes Area +// +#define INT32_MIN_ASCALE (-2) +#define INT32_MAX_ASCALE (2) +#define INT64_MIN_ASCALE (-4) +#define INT64_MAX_ASCALE (4) + +extern const int16 INT16_MIN_VALUE; +extern const int16 INT16_MAX_VALUE; +extern const int32 INT32_MIN_VALUE; +extern const int32 INT32_MAX_VALUE; +extern const int64 INT64_MIN_VALUE; +extern const int64 INT64_MAX_VALUE; + +#ifdef ENABLE_UT +extern void test_dump_numeric_to_file(_out_ FILE* fd, _in_ const char* str, _in_ Numeric num); +extern bool test_numeric_dscale_equal(_in_ Numeric v1, _in_ Numeric v2); +extern void test_dump_compressed_numeric_to_file(_out_ FILE* fd, _in_ const char* str, _in_ int64 v, _in_ char ascale); +extern char number_of_tail_zeros[10000]; +#endif + +/* + * convert functions between int32|int64|int128 and numerc + * convert numeric to int32, int64 or int128 + * convert int32, int64, int128 to numeric + */ +extern bool convert_short_numeric_to_int32(_in_ int64 v, _in_ char ascale); +extern bool convert_short_numeric_to_int64(_in_ char* inBuf, _out_ int64* v, _out_ char* ascale); +extern int convert_int64_to_short_numeric(_out_ char* outBuf, _in_ int64 v, _in_ char ascale, _in_ int32 typmod); +extern int batch_convert_short_numeric_to_int64(_in_ Datum* batchValues, _in_ char* batchNulls, _in_ int batchRows, + _in_ bool hasNull, _out_ int64* outInt, _out_ char* outAscales, _out_ bool* outSuccess, _out_ int* outNullCount); +extern int convert_int64_to_short_numeric_byscale( + _out_ char* outBuf, _in_ __int128_t v, _in_ int32 typmod, _in_ int32 vscale); +extern int convert_int128_to_short_numeric_byscale( + _out_ char* outBuf, _in_ int128 v, _in_ int32 typmod, _in_ int32 vscale); +extern Datum convert_short_numeric_to_int64(_in_ Numeric inNum, _out_ bool* outSuccess); +extern Datum convert_short_numeric_to_int128(_in_ Numeric inNum, _out_ bool* outSuccess); +extern Datum try_convert_numeric_normal_to_fast(Datum value); +extern int64 convert_short_numeric_to_int64_byscale(_in_ Numeric n, _in_ int scale); +extern void convert_short_numeric_to_int128_byscale(_in_ Numeric n, _in_ int scale, _out_ int128& result); +extern int32 get_ndigit_from_numeric(_in_ Numeric num); + +/* ---------- + * NumericVar is the format we use for arithmetic. The digit-array part + * is the same as the NumericData storage format, but the header is more + * complex. + * + * The value represented by a NumericVar is determined by the sign, weight, + * ndigits, and digits[] array. + * Note: the first digit of a NumericVar's value is assumed to be multiplied + * by NBASE ** weight. Another way to say it is that there are weight+1 + * digits before the decimal point. It is possible to have weight < 0. + * + * buf points at the physical start of the palloc'd digit buffer for the + * NumericVar. digits points at the first digit in actual use (the one + * with the specified weight). We normally leave an unused digit or two + * (preset to zeroes) between buf and digits, so that there is room to store + * a carry out of the top digit without reallocating space. We just need to + * decrement digits (and increment weight) to make room for the carry digit. + * (There is no such extra space in a numeric value stored in the database, + * only in a NumericVar in memory.) + * + * If buf is NULL then the digit buffer isn't actually palloc'd and should + * not be freed --- see the constants below for an example. + * + * dscale, or display scale, is the nominal precision expressed as number + * of digits after the decimal point (it must always be >= 0 at present). + * dscale may be more than the number of physically stored fractional digits, + * implying that we have suppressed storage of significant trailing zeroes. + * It should never be less than the number of stored digits, since that would + * imply hiding digits that are present. NOTE that dscale is always expressed + * in *decimal* digits, and so it may correspond to a fractional number of + * base-NBASE digits --- divide by DEC_DIGITS to convert to NBASE digits. + * + * rscale, or result scale, is the target precision for a computation. + * Like dscale it is expressed as number of *decimal* digits after the decimal + * point, and is always >= 0 at present. + * Note that rscale is not stored in variables --- it's figured on-the-fly + * from the dscales of the inputs. + * + * While we consistently use "weight" to refer to the base-NBASE weight of + * a numeric value, it is convenient in some scale-related calculations to + * make use of the base-10 weight (ie, the approximate log10 of the value). + * To avoid confusion, such a decimal-units weight is called a "dweight". + * + * NB: All the variable-level functions are written in a style that makes it + * possible to give one and the same variable as argument and destination. + * This is feasible because the digit buffer is separate from the variable. + * ---------- + */ +typedef struct NumericVar { + int ndigits; /* # of digits in digits[] - can be 0! */ + int weight; /* weight of first digit */ + int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */ + int dscale; /* display scale */ + NumericDigit* buf; /* start of palloc'd space for digits[] */ + NumericDigit* digits; /* base-NBASE digits */ +} NumericVar; + +#define init_var(v) MemSetAligned(v, 0, sizeof(NumericVar)) +Numeric makeNumeric(NumericVar* var); +extern Numeric make_result(NumericVar *var); +extern void free_var(NumericVar *var); +extern void int64_to_numericvar(int64 val, NumericVar *var); +extern void add_var(NumericVar *var1, NumericVar *var2, NumericVar *result); + + +#endif /* _PG_NUMERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/palloc.h postgresql-hll-2.14/include/include/utils/palloc.h --- postgresql-hll-2.14_old/include/include/utils/palloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/palloc.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,261 @@ +/* ------------------------------------------------------------------------- + * + * palloc.h + * POSTGRES memory allocator definitions. + * + * This file contains the basic memory allocation interface that is + * needed by almost every backend module. It is included directly by + * postgres.h, so the definitions here are automatically available + * everywhere. Keep it lean! + * + * Memory allocation occurs within "contexts". Every chunk obtained from + * palloc()/MemoryContextAlloc() is allocated within a specific context. + * The entire contents of a context can be freed easily and quickly by + * resetting or deleting the context --- this is both faster and less + * prone to memory-leakage bugs than releasing chunks individually. + * We organize contexts into context trees to allow fine-grain control + * over chunk lifetime while preserving the certainty that we will free + * everything that should be freed. See utils/mmgr/README for more info. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/palloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PALLOC_H +#define PALLOC_H +#ifndef FRONTEND_PARSER + +/* + * Type MemoryContextData is declared in nodes/memnodes.h. Most users + * of memory allocation should just treat it as an abstract type, so we + * do not provide the struct contents here. + */ +typedef struct MemoryContextData* MemoryContext; + +/* + * CurrentMemoryContext is the default allocation context for palloc(). + * We declare it here so that palloc() can be a macro. Avoid accessing it + * directly! Instead, use MemoryContextSwitchTo() to change the setting. + */ +#ifdef WIN32 +extern THR_LOCAL MemoryContext CurrentMemoryContext; +extern THR_LOCAL MemoryContext SelfMemoryContext; +extern THR_LOCAL MemoryContext TopMemoryContext; +#else +extern THR_LOCAL PGDLLIMPORT MemoryContext CurrentMemoryContext; +extern THR_LOCAL PGDLLIMPORT MemoryContext SelfMemoryContext; +extern THR_LOCAL PGDLLIMPORT MemoryContext TopMemoryContext; +#endif /* WIN32 */ + +/* + * Flags for MemoryContextAllocExtended. + */ +#define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +#define ENABLE_MEMORY_PROTECT() (t_thrd.utils_cxt.memNeedProtect = true) +#define DISABLE_MEMORY_PROTECT() (t_thrd.utils_cxt.memNeedProtect = false) + +/* Definition for the unchanged interfaces */ +#define MemoryContextAlloc(context, size) MemoryContextAllocDebug(context, size, __FILE__, __LINE__) +#define MemoryContextAllocZero(context, size) MemoryContextAllocZeroDebug(context, size, __FILE__, __LINE__) +#define MemoryContextAllocZeroAligned(context, size) \ + MemoryContextAllocZeroAlignedDebug(context, size, __FILE__, __LINE__) +#define MemoryContextStrdup(context, size) MemoryContextStrdupDebug(context, size, __FILE__, __LINE__) +#define repalloc(pointer, size) repallocDebug(pointer, size, __FILE__, __LINE__) +#define repalloc_noexcept(pointer, size) repalloc_noexcept_Debug(pointer, size, __FILE__, __LINE__) +#define pnstrdup(in, len) pnstrdupDebug(in, len, __FILE__, __LINE__) + +#define INSTANCE_GET_MEM_CXT_GROUP g_instance.mcxt_group->GetMemCxtGroup +#define THREAD_GET_MEM_CXT_GROUP t_thrd.mcxt_group->GetMemCxtGroup +#define SESS_GET_MEM_CXT_GROUP u_sess->mcxt_group->GetMemCxtGroup + +/* + * Fundamental memory-allocation operations (more are in utils/memutils.h) + */ +extern void* MemoryContextAllocDebug(MemoryContext context, Size size, const char* file, int line); +extern void* MemoryContextAllocHugeDebug(MemoryContext context, Size size, const char* file, int line); +extern void* repallocHugeDebug(void* pointer, Size size, const char* file, int line); +extern void* MemoryContextAllocZeroDebug(MemoryContext context, Size size, const char* file, int line); +extern void* MemoryContextAllocZeroAlignedDebug(MemoryContext context, Size size, const char* file, int line); +extern char* MemoryContextStrdupDebug(MemoryContext context, const char* string, const char* file, int line); +extern void* MemoryContextMemalignAllocDebug(MemoryContext context, Size align, Size size, const char* file, int line); +extern void MemoryContextMemalignFree(MemoryContext context, void* pointer); +#ifndef FRONTEND +extern void* palloc_extended(Size size, int flags); +extern void* palloc0_noexcept(Size size); +#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz)) +#endif +#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz)) + +#define palloc_huge(context, size) MemoryContextAllocHugeDebug(context, size, __FILE__, __LINE__) + +#define repalloc_huge(pointer, size) repallocHugeDebug(pointer, size, __FILE__, __LINE__) + +#define selfpalloc(sz) MemoryContextAlloc(SelfMemoryContext, (sz)) + +#define selfpalloc0(sz) MemoryContextAllocZero(SelfMemoryContext, (sz)) + +#define selfpfree(ptr) pfree((ptr)) + +#define selfrepalloc(ptr, sz) repalloc((ptr), (sz)) + +#define selfpstrdup(str) MemoryContextStrdup(SelfMemoryContext, (str)) + +extern THR_LOCAL MemoryContext AlignMemoryContext; +#define mem_align_alloc(align, size) \ + MemoryContextMemalignAllocDebug(AlignMemoryContext, (align), (size), __FILE__, __LINE__) +#define mem_align_free(ptr) MemoryContextMemalignFree(AlignMemoryContext, (ptr)) + +/* + * The result of palloc() is always word-aligned, so we can skip testing + * alignment of the pointer when deciding which MemSet variant to use. + * Note that this variant does not offer any advantage, and should not be + * used, unless its "sz" argument is a compile-time constant; therefore, the + * issue that it evaluates the argument multiple times isn't a problem in + * practice. + */ +#define palloc0fast(sz) \ + (MemSetTest(0, sz) ? MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) \ + : MemoryContextAllocZero(CurrentMemoryContext, sz)) + +extern void pfree(void* pointer); + +template +bool isConst(T& x) +{ + return false; +} + +template +bool isConst(T const& x) +{ + return true; +} + +#define FREE_POINTER(ptr) \ + do { \ + if ((ptr) != NULL) { \ + pfree((void*)ptr); \ + if (!isConst(ptr)) \ + (ptr) = NULL; \ + } \ + } while (0) + +// call pfree() and set pointer to be NULL. +#define pfree_ext(__p) FREE_POINTER(__p) + +extern void* repallocDebug(void* pointer, Size size, const char* file, int line); +extern void* repalloc_noexcept_Debug(void* pointer, Size size, const char* file, int line); + +/* + * MemoryContextSwitchTo can't be a macro in standard C compilers. + * But we can make it an inline function if the compiler supports it. + * + * This file has to be includable by some non-backend code such as + * pg_resetxlog, so don't expose the CurrentMemoryContext reference + * if FRONTEND is defined. + */ +#if defined(USE_INLINE) && !defined(FRONTEND) + +static inline MemoryContext MemoryContextSwitchTo(MemoryContext context) +{ + MemoryContext old = CurrentMemoryContext; + + CurrentMemoryContext = context; + return old; +} +#else + +extern MemoryContext MemoryContextSwitchTo(MemoryContext context); +#endif /* USE_INLINE && !FRONTEND */ + +/* + * These are like standard strdup() except the copied string is + * allocated in a context, not with malloc(). + */ +extern char* MemoryContextStrdupDebug(MemoryContext context, const char* string, const char* file, int line); + +#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str)) + +#define pstrdup_ext(str) \ + (((str) == NULL) ? NULL : (pstrdup((const char*)(str)))) + +extern char* pnstrdupDebug(const char* in, Size len, const char* file, int line); + +extern void AllocSetCheckPointer(void* pointer); + +#if defined(WIN32) || defined(__CYGWIN__) +extern void* pgport_palloc(Size sz); +extern char* pgport_pstrdup(const char* str); +extern void pgport_pfree(void* pointer); +#endif + +#define New(pmc) new (pmc, __FILE__, __LINE__) + +// BaseObject is a basic class +// All other class should inherit from BaseObject class which +// override operator new/delete. +// +class BaseObject { +public: + ~BaseObject() + {} + + void* operator new(size_t size, MemoryContextData* pmc, const char* file, int line) + { + return MemoryContextAllocDebug(pmc, size, file, line); + } + + void* operator new[](size_t size, MemoryContextData* pmc, const char* file, int line) + { + return MemoryContextAllocDebug(pmc, size, file, line); + } + + void operator delete(void* p) + { + pfree(p); + } + + void operator delete[](void* p) + { + pfree(p); + } +}; + +/* + *It is used for delete object whose destructor is null and free memory in Destroy() + *_objptr can't include type change, for example (A*)b, that will lead to compile error in (_objptr) = NULL + *If _objptr include type change, please use DELETE_EX_TYPE to complete it. + *It is supplied easily for developers to refactor destructor in the future + */ +#define DELETE_EX(_objptr) \ + do { \ + (_objptr)->Destroy(); \ + delete (_objptr); \ + (_objptr) = NULL; \ + } while (0) + +// used for _objptr need to change to another type +#define DELETE_EX_TYPE(_objptr, _type) \ + do { \ + ((_type*)(_objptr))->Destroy(); \ + delete (_type*)(_objptr); \ + (_objptr) = NULL; \ + } while (0) + +#define DELETE_EX2(_objptr) \ + do { \ + if ((_objptr) != nullptr) { \ + delete (_objptr); \ + (_objptr) = NULL; \ + } \ + } while (0) + +#endif /* !FRONTEND_PARSER */ +#endif /* PALLOC_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/partcache.h postgresql-hll-2.14/include/include/utils/partcache.h --- postgresql-hll-2.14_old/include/include/utils/partcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/partcache.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,100 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partcache.h + * + * + * + * IDENTIFICATION + * src/include/utils/partcache.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTCACHE_H +#define PARTCACHE_H +#include "access/tupdesc.h" +#include "nodes/bitmapset.h" +#include "utils/relcache.h" + +#define PARTITIONTYPE(partition) (partition->pd_part->parttype) + +#define PartitionIsPartitionedTable(partition) (PART_OBJ_TYPE_PARTED_TABLE == (partition)->pd_part->parttype) + +#define PartitionIsToastTable(partition) (PART_OBJ_TYPE_TOAST_TABLE == (partition)->pd_part->parttype) + +#define PartitionIsTablePartition(partition) (PART_OBJ_TYPE_TABLE_PARTITION == (partition)->pd_part->parttype) + +#define PartitionIsBucket(partition) ((partition)->pd_node.bucketNode > InvalidBktId) + +#define PartitionIsIndexPartition(partition) (PART_OBJ_TYPE_INDEX_PARTITION == (partition)->pd_part->parttype) + +/* + * Routines to open (lookup) and close a partcache entry + */ +extern Partition PartitionIdGetPartition(Oid partitionId, bool isbucket); +extern void PartitionClose(Partition partition); +extern char* PartitionOidGetName(Oid partOid); +extern Oid PartitionOidGetTablespace(Oid partOid); +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void PartitionForgetPartition(Oid partid); +/* + * Routines for backend startup + */ +extern void PartitionCacheInitialize(void); +extern void PartitionCacheInitializePhase2(void); +extern void PartitionCacheInitializePhase3(void); +/* + * Routine to create a partcache entry for an about-to-be-created relation + */ +Partition PartitionBuildLocalPartition(const char* relname, Oid partid, Oid partfilenode, Oid parttablespace); +/* + * Routines for backend startup + */ +extern void PartitionCacheInitialize(void); + +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void PartitionCacheInvalidateEntry(Oid partitionId); +extern void PartitionCacheInvalidate(void); +extern void PartitionCloseSmgrByOid(Oid partitionId); +extern void AtEOXact_PartitionCache(bool isCommit); +extern void AtEOSubXact_PartitionCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern Relation partitionGetRelation(Relation rel, Partition part); + +void releaseDummyRelation(Relation* relation); + +extern void PartitionSetNewRelfilenode(Relation parent, Partition part, TransactionId freezeXid); + +/* + * Routines for global partition index open partition + */ +extern PartStatus PartitionGetMetadataStatus(Oid partOid, bool vacuumFlag); +extern Datum SetWaitCleanGpiRelOptions(Datum oldOptions, bool enable); +extern void PartitionedSetWaitCleanGpi(const char* parentName, Oid parentPartOid, bool enable, bool inplace); +extern void PartitionSetWaitCleanGpi(Oid partOid, bool enable, bool inplace); +extern bool PartitionInvisibleMetadataKeep(Datum datumRelOptions); +extern void PartitionedSetEnabledClean(Oid parentOid); +extern void PartitionSetEnabledClean( + Oid parentOid, const Bitmapset* cleanedParts, const Bitmapset* invisibleParts, bool updatePartitioned); +extern void PartitionSetAllEnabledClean(Oid parentOid); +extern void PartitionGetAllInvisibleParts(Oid parentOid, Bitmapset** invisibleParts); +extern bool PartitionMetadataDisabledClean(Relation pgPartition); + +#endif /* RELCACHE_H */ + diff -uprN postgresql-hll-2.14_old/include/include/utils/partitionkey.h postgresql-hll-2.14/include/include/utils/partitionkey.h --- postgresql-hll-2.14_old/include/include/utils/partitionkey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/partitionkey.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionkey.h + * + * + * + * IDENTIFICATION + * src/include/utils/partitionkey.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONKEY_H +#define PARTITIONKEY_H + +#include "nodes/pg_list.h" + +/* + * @@GaussDB@@ + * Brief + * Description : transform the list of maxvalue + * (partition's boundary, Const node form) into TEXT array + * input : List of Const + * return value : TEXT array + */ +extern Datum transformPartitionBoundary(List* maxValueList, const bool* isTimestamptz); + +extern Datum transformListBoundary(List* maxValueList, const bool* isTimestamptz); + +/* + * @@GaussDB@@ + * Brief + * Description : transform TEXT array into a list of Value + * input : TEXT Array + * return value : List of Value + * Note : + */ +extern List* untransformPartitionBoundary(Datum options); + +/* + * @@GaussDB@@ + * Brief + * Description : Check if given attnum pos is satisfied with value partitioned policy + * input : atts array and position(attno) of partitioned columns + * return value : None- + * Note : + */ +extern void CheckValuePartitionKeyType(Form_pg_attribute* attrs, List* pos); +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/partitionmap_gs.h postgresql-hll-2.14/include/include/utils/partitionmap_gs.h --- postgresql-hll-2.14_old/include/include/utils/partitionmap_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/partitionmap_gs.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,456 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionmap_gs.h + * + * this file separates from partitionmap.h, extract major code from partitionmap.h + * to here + * + * IDENTIFICATION + * src/include/utils/partitionmap_gs.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONMAP_GS_H_ +#define PARTITIONMAP_GS_H_ + +#include "postgres.h" +#include "access/heapam.h" +#include "knl/knl_variable.h" +#include "access/htup.h" +#include "catalog/pg_type.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "utils/hsearch.h" +#include "utils/rel.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/partitionmap.h" + +typedef enum PartitionArea { + PART_AREA_NONE = 0, + PART_AREA_RANGE, + PART_AREA_INTERVAL, + PART_AREA_LIST, + PART_AREA_HASH +} PartitionArea; + +/* + * Partition position in partitioned-table + * partition sequence is numbered in range area and interval area separately. + * partition sequec start with 0 + */ +typedef struct PartitionIdentifier { + PartitionArea partArea; + int partSeq; + bool fileExist; + Oid partitionId; +} PartitionIdentifier; + +/** + *partition map is used to find which partition a record is mapping to. + *and pruning the unused partition when querying.the map has two part: + *and range part and interval part. + *range part is a array of RangeElement which is sorted by RangeElement.boundary + *interval part is array of IntervalElement which is sorted by IntervalElement.sequenceNum + *binary search is used to routing in range part of map , and in interval part + *we use (recordValue-lowBoundary_of_interval)/interval to get the sequenceNum of + *a interval partition + * + */ +typedef struct RangeElement { + Oid partitionOid; /*the oid of partition*/ + int len; /*the length of partition key number*/ + Const* boundary[RANGE_PARTKEYMAXNUM]; /*upper bond of partition */ + bool isInterval; /* is interval partition */ +} RangeElement; + +typedef struct IntervalElement { + Oid partitionOid; /* the oid of partition */ + int sequenceNum; /* the logic number of interval partition. */ +} IntervalElement; + +typedef struct ListPartElement { + Oid partitionOid; /* the oid of partition */ + int len; /* the length of values */ + Const** boundary; /* list values */ +} ListPartElement; + +typedef struct HashPartElement { + Oid partitionOid; /* the oid of partition */ + Const* boundary[1]; /* hash bucket */ +} HashPartElement; + +// describe partition info of Value Partitioned-Table +typedef struct ValuePartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + List* partList; /* List Partition key List */ +} ValuePartitionMap; + +// describe partition info of Range Partitioned-Table +typedef struct RangePartitionMap { + PartitionMap type; + Oid relid; /*oid of partitioned table*/ + int2vector* partitionKey; /*partition key*/ + Oid* partitionKeyDataType; /*the data type of partition key*/ + /*section 1: range partition specific*/ + int rangeElementsNum; /* the number of range partition*/ + RangeElement* rangeElements; /* array of RangeElement */ + Interval* intervalValue; /* valid for interval partition */ + oidvector* intervalTablespace; /* valid for interval partition */ +} RangePartitionMap; + +bool ValueSatisfyLowBoudary(Const** partKeyValue, RangeElement* partition, Interval* intervalValue, bool topClosed); +extern int2vector* GetPartitionKey(const PartitionMap* partMap); + +typedef struct ListPartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + int2vector* partitionKey; /* partition key */ + Oid* partitionKeyDataType; /* the data type of partition key */ + /* section 1: list partition specific */ + int listElementsNum; /* the number of list partition */ + ListPartElement* listElements; /* array of listElement */ +} ListPartitionMap; + +typedef struct HashPartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + int2vector* partitionKey; /* partition key */ + Oid* partitionKeyDataType; /* the data type of partition key */ + /* section 1: hash partition specific */ + int hashElementsNum; /* the number of hash partition */ + HashPartElement* hashElements; /* array of hashElement */ +} HashPartitionMap; + +#define PartitionkeyTypeGetIntervalType(type) \ + do { \ + if (DATEOID == (type) || TIMESTAMPOID == (type) || TIMESTAMPTZOID == (type)) { \ + (type) = INTERVALOID; \ + } \ + } while (0) + +#define partitionRoutingForTuple(rel, tuple, partIdentfier) \ + do { \ + TupleDesc tuple_desc = NULL; \ + int2vector* partkey_column = NULL; \ + int partkey_column_n = 0; \ + static THR_LOCAL Const consts[PARTITION_PARTKEYMAXNUM]; \ + static THR_LOCAL Const* values[PARTITION_PARTKEYMAXNUM]; \ + bool isnull = false; \ + Datum column_raw; \ + int i = 0; \ + partkey_column = GetPartitionKey((rel)->partMap); \ + partkey_column_n = partkey_column->dim1; \ + tuple_desc = (rel)->rd_att; \ + for (i = 0; i < partkey_column_n; i++) { \ + isnull = false; \ + column_raw = fastgetattr((tuple), partkey_column->values[i], tuple_desc, &isnull); \ + values[i] = \ + transformDatum2Const((rel)->rd_att, partkey_column->values[i], column_raw, isnull, &consts[i]); \ + } \ + if (PartitionMapIsInterval((rel)->partMap) && values[0]->constisnull) { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), \ + errmsg("inserted partition key does not map to any partition"), \ + errdetail("inserted partition key cannot be NULL for interval-partitioned table"))); \ + } \ + partitionRoutingForValue((rel), values, partkey_column_n, true, false, (partIdentfier)); \ + } while (0) + +#define partitionRoutingForValue(rel, keyValue, valueLen, topClosed, missIsOk, result) \ + do { \ + if ((rel)->partMap->type == PART_TYPE_RANGE || (rel)->partMap->type == PART_TYPE_INTERVAL) { \ + if ((rel)->partMap->type == PART_TYPE_RANGE) { \ + (result)->partArea = PART_AREA_RANGE; \ + } else { \ + Assert((valueLen) == 1); \ + (result)->partArea = PART_AREA_INTERVAL; \ + } \ + (result)->partitionId = getRangePartitionOid((rel)->partMap, (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + RangePartitionMap* partMap = (RangePartitionMap*)((rel)->partMap); \ + if (partMap->rangeElements[(result)->partSeq].isInterval && \ + !ValueSatisfyLowBoudary( \ + keyValue, &partMap->rangeElements[(result)->partSeq], partMap->intervalValue, topClosed)) { \ + (result)->partSeq = -1; \ + (result)->partitionId = InvalidOid; \ + (result)->fileExist = false; \ + } \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_LIST) { \ + (result)->partArea = PART_AREA_LIST; \ + (result)->partitionId = getListPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_HASH) { \ + (result)->partArea = PART_AREA_HASH; \ + (result)->partitionId = getHashPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (rel)->partMap->type))); \ + } \ + } while (0) + +/* + * search >/>= keyValue partition if direction is true + * search type == PART_TYPE_RANGE) { \ + (result)->partArea = PART_AREA_RANGE; \ + } else if ((GetPartitionMap(cxt))->type == PART_TYPE_INTERVAL) { \ + Assert((valueLen) == 1); \ + (result)->partArea = PART_AREA_INTERVAL; \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (GetPartitionMap(cxt))->type))); \ + } \ + (result)->partitionId = getRangePartitionOid((GetPartitionMap(cxt)), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + RangePartitionMap* partMap = (RangePartitionMap*)(GetPartitionMap(cxt)); \ + if (partMap->rangeElements[(result)->partSeq].isInterval && !direction && \ + !ValueSatisfyLowBoudary( \ + keyValue, &partMap->rangeElements[(result)->partSeq], partMap->intervalValue, topClosed)) { \ + --((result)->partSeq); \ + (result)->partitionId = partMap->rangeElements[(result)->partSeq].partitionOid; \ + } \ + } \ + } while (0) + +#define partitionRoutingForValueEqual(rel, keyValue, valueLen, topClosed, result) \ + do { \ + if ((rel)->partMap->type == PART_TYPE_LIST) { \ + (result)->partArea = PART_AREA_LIST; \ + (result)->partitionId = getListPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_HASH) { \ + (result)->partArea = PART_AREA_HASH; \ + (result)->partitionId = getHashPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (rel)->partMap->type))); \ + } \ + } while (0) + +typedef enum PruningResultState { PRUNING_RESULT_EMPTY, PRUNING_RESULT_SUBSET, PRUNING_RESULT_FULL } PruningResultState; + +/* + * PruningBoundary is NULL if pruning result is EMPTY, + * all min item and max item are NULLs if pruning result is FULL. + */ +typedef struct PruningBoundary { + PruningResultState state; + int partitionKeyNum; + Datum* min; + bool* minClose; + Datum* max; + bool* maxClose; +} PruningBoundary; + +/* + * hash table that index the fakeRelation cache + */ + +typedef struct partrelidcachekey { + Oid partoid; + int4 bucketid; +} PartRelIdCacheKey; + +typedef struct partrelidcacheent { + Oid partoid; + int4 bucketid; + Relation reldesc; + Partition partdesc; +} PartRelIdCacheEnt; + +#define searchFakeReationForPartitionOid(fakeRels, cxt, rel, partOid, fakeRelation, partition, lmode) \ + do { \ + PartRelIdCacheKey _key = {partOid, -1}; \ + if (PointerIsValid(partition)) { \ + break; \ + } \ + if (RelationIsNonpartitioned(rel)) { \ + fakeRelation = NULL; \ + partition = NULL; \ + break; \ + } \ + if (PointerIsValid(fakeRels)) { \ + FakeRelationIdCacheLookup(fakeRels, _key, fakeRelation, partition); \ + if (!RelationIsValid(fakeRelation)) { \ + partition = partitionOpen(rel, partOid, lmode); \ + fakeRelation = partitionGetRelation(rel, partition); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, partition, -1); \ + } \ + } else { \ + HASHCTL ctl; \ + errno_t errorno = EOK; \ + errorno = memset_s(&ctl, sizeof(ctl), 0, sizeof(ctl)); \ + securec_check_c(errorno, "\0", "\0"); \ + ctl.keysize = sizeof(PartRelIdCacheKey); \ + ctl.entrysize = sizeof(PartRelIdCacheEnt); \ + ctl.hash = tag_hash; \ + ctl.hcxt = cxt; \ + fakeRels = hash_create( \ + "fakeRelationCache by OID", FAKERELATIONCACHESIZE, &ctl, HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); \ + partition = partitionOpen(rel, partOid, lmode); \ + fakeRelation = partitionGetRelation(rel, partition); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, partition, -1); \ + } \ + } while (0) + +#define searchHBucketFakeRelation(fakeRels, cxt, rel, bucketid, fakeRelation) \ + do { \ + PartRelIdCacheKey _key = {(rel->rd_id), bucketid}; \ + Partition partition; \ + Relation parentRel = rel; \ + Assert(RELATION_OWN_BUCKET(rel)); \ + if (bucketid == -1) { \ + ereport(ERROR, \ + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ + errmsg("Invaild Oid when open hash bucket relation, the target bucket may not exist on current datanode"))); \ + } \ + if (PointerIsValid(fakeRels)) { \ + FakeRelationIdCacheLookup(fakeRels, _key, fakeRelation, partition); \ + if (!RelationIsValid(fakeRelation)) { \ + fakeRelation = bucketGetRelation(parentRel, NULL, bucketid); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, NULL, bucketid); \ + } \ + } else { \ + HASHCTL ctl; \ + errno_t errorno = EOK; \ + errorno = memset_s(&ctl, sizeof(ctl), 0, sizeof(ctl)); \ + securec_check_c(errorno, "\0", "\0"); \ + ctl.keysize = sizeof(PartRelIdCacheKey); \ + ctl.entrysize = sizeof(PartRelIdCacheEnt); \ + ctl.hash = tag_hash; \ + ctl.hcxt = cxt; \ + fakeRels = hash_create("fakeRelationCache by OID", \ + FAKERELATIONCACHESIZE, \ + &ctl, \ + HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); \ + fakeRelation = bucketGetRelation(parentRel, NULL, bucketid); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, NULL, bucketid); \ + } \ + } while (0) + +#define FakeRelationIdCacheLookup(CACHE, KEY, RELATION, PARTITION) \ + do { \ + PartRelIdCacheEnt* hentry; \ + hentry = (PartRelIdCacheEnt*)hash_search(CACHE, (void*)&(KEY), HASH_FIND, NULL);\ + if (hentry) { \ + RELATION = hentry->reldesc; \ + PARTITION = hentry->partdesc; \ + } else { \ + RELATION = NULL; \ + PARTITION = NULL; \ + } \ + } while (0) + +#define FakeRelationCacheInsert(CACHE, RELATION, PARTITION, BUCKET) \ + do { \ + PartRelIdCacheEnt* idhentry; \ + bool found; \ + PartRelIdCacheKey key={(RELATION->rd_id), BUCKET}; \ + idhentry = (PartRelIdCacheEnt*)hash_search(CACHE, (void*)&(key), HASH_ENTER, &found); \ + /* used to give notice if found -- now just keep quiet */ \ + idhentry->reldesc = RELATION; \ + idhentry->partdesc = PARTITION; \ + } while (0) + +#define FakeRelationCacheDestroy(HTAB) \ + do { \ + HASH_SEQ_STATUS status; \ + PartRelIdCacheEnt* idhentry; \ + Relation parentRelation = NULL; \ + hash_seq_init(&status, (HTAB)); \ + while ((idhentry = (PartRelIdCacheEnt*)hash_seq_search(&status)) != NULL) { \ + if (idhentry->bucketid == InvalidBktId) { \ + parentRelation = relation_open(idhentry->reldesc->parentId, NoLock);\ + releaseDummyRelation(&idhentry->reldesc); \ + partitionClose(parentRelation, idhentry->partdesc, NoLock); \ + relation_close(parentRelation, NoLock); \ + } else { \ + bucketCloseRelation(idhentry->reldesc); \ + } \ + } \ + hash_destroy((HTAB)); \ + (HTAB) = NULL; \ + } while (0) + +typedef struct PruningResult { + NodeTag type; + PruningResultState state; + PruningBoundary* boundary; + Bitmapset* bm_rangeSelectedPartitions; + int intervalOffset; /*the same as intervalMinSeq*/ + /*if interval partitions is empty, intervalOffset=-1*/ + Bitmapset* intervalSelectedPartitions; + List* ls_rangeSelectedPartitions; + Param* paramArg; + OpExpr* exprPart; + Expr* expr; +} PruningResult; + +extern Oid partIDGetPartOid(Relation relation, PartitionIdentifier* partID); +extern PartitionIdentifier* partOidGetPartID(Relation rel, Oid partOid); + +extern void RebuildPartitonMap(PartitionMap* oldMap, PartitionMap* newMap); +extern void RebuildRangePartitionMap(RangePartitionMap* oldMap, RangePartitionMap* newMap); + +bool isPartKeyValuesInPartition(RangePartitionMap* partMap, Const** partKeyValues, int partkeyColumnNum, int partSeq); + +extern int comparePartitionKey(RangePartitionMap* partMap, Const** values1, Const** values2, int partKeyNum); + +extern int lookupHBucketid(oidvector *buckets, int low, int2 bucket_id); + +extern int2 computeTupleBucketId(Relation rel, HeapTuple tuple); + +extern Oid GetNeedDegradToRangePartOid(Relation rel, Oid partOid); +extern RangeElement* CopyRangeElementsWithoutBoundary(const RangeElement* src, int elementNum); +extern char* ReadIntervalStr(HeapTuple tuple, TupleDesc tupleDesc); +extern oidvector* ReadIntervalTablespace(HeapTuple tuple, TupleDesc tupleDesc); +int ValueCmpLowBoudary(Const** partKeyValue, const RangeElement* partition, Interval* intervalValue); +extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval); +extern RangeElement* copyRangeElements(RangeElement* src, int elementNum, int partkeyNum); +extern int rangeElementCmp(const void* a, const void* b); +extern void DestroyListElements(ListPartElement* src, int elementNum); +#endif /* PARTITIONMAP_GS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/partitionmap.h postgresql-hll-2.14/include/include/utils/partitionmap.h --- postgresql-hll-2.14_old/include/include/utils/partitionmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/partitionmap.h 2020-12-12 17:06:43.290348593 +0800 @@ -0,0 +1,142 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionmap.h + * + * + * + * IDENTIFICATION + * src/include/utils/partitionmap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONMAP_H_ +#define PARTITIONMAP_H_ + +#include "postgres.h" +#include "access/htup.h" +#include "catalog/pg_type.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "utils/hsearch.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef enum PartitionType { + PART_TYPE_NONE = 0, + PART_TYPE_RANGE, + PART_TYPE_INTERVAL, + PART_TYPE_HASH, + PART_TYPE_LIST, + PART_TYPE_VALUE +} PartitionType; + +// describe abstract partition map +typedef struct PartitionMap { + PartitionType type; + int refcount; + bool isDirty; +} PartitionMap; + +// describe range partition +#define RANGE_PARTKEYMAXNUM 4 +#define PARTITION_PARTKEYMAXNUM 4 +#define VALUE_PARTKEYMAXNUM 4 +#define INTERVAL_PARTKEYMAXNUM 1 + +#define PartitionLogicalExist(partitionIdentifier) ((partitionIdentifier)->partSeq >= 0) + +#define PartitionPhysicalExist(partitionIdentifier) \ + ((partitionIdentifier)->partArea != PART_AREA_NONE && ((partitionIdentifier)->fileExist) + +void incre_partmap_refcount(PartitionMap* map); +void decre_partmap_refcount(PartitionMap* map); + +#define PartitionMapGetKey(partmap) (((RangePartitionMap*)(partmap))->partitionKey) + +#define PartitionMapGetType(partmap) (((RangePartitionMap*)(partmap))->partitionKeyDataType) + +#define PartitionMapIsRange(partmap) (PART_TYPE_RANGE == ((RangePartitionMap*)(partmap))->type.type) + +#define PartitionMapIsList(partmap) (PART_TYPE_LIST == ((ListPartitionMap*)(partmap))->type.type) + +#define PartitionMapIsHash(partmap) (PART_TYPE_HASH == ((HashPartitionMap*)(partmap))->type.type) + +#define PartitionMapIsInterval(partmap) (PART_TYPE_INTERVAL == ((RangePartitionMap*)(partmap))->type.type) + +#define FAKERELATIONCACHESIZE 100 + +#define BoundaryIsNull(boundary) !(PointerIsValid(boundary)) + +#define BoundaryIsFull(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_FULL) + +#define BoundaryIsEmpty(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_EMPTY) + +#define BoundaryIsSubset(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_SUBSET) + +#define PruningResultIsFull(pruningRes) (PointerIsValid(pruningRes) && (pruningRes)->state == PRUNING_RESULT_FULL) + +#define PruningResultIsEmpty(pruningRes) (!PointerIsValid(pruningRes) || (pruningRes)->state == PRUNING_RESULT_EMPTY) + +#define PruningResultIsSubset(pruningRes) (PointerIsValid(pruningRes) && (pruningRes)->state == PRUNING_RESULT_SUBSET) + +extern List* relationGetPartitionOidList(Relation rel); +extern void RelationInitPartitionMap(Relation relation); + +extern int partOidGetPartSequence(Relation rel, Oid partOid); +extern Oid getListPartitionOid(Relation relation, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid getHashPartitionOid(Relation relation, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid getRangePartitionOid(PartitionMap* partitionmap, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid GetPartitionOidByParam(Relation relation, Param *paramArg, ParamExternData *prm); +extern List* getPartitionBoundaryList(Relation rel, int sequence); +extern Oid partitionKeyValueListGetPartitionOid(Relation rel, List* partKeyValueList, bool topClosed); +extern int getNumberOfRangePartitions(Relation rel); +extern int getNumberOfListPartitions(Relation rel); +extern int getNumberOfHashPartitions(Relation rel); +extern int getNumberOfPartitions(Relation rel); +extern Const* transformDatum2Const(TupleDesc tupledesc, int16 attnum, Datum datumValue, bool isnull, Const* cnst); + +extern List* relationGetPartitionList(Relation relation, LOCKMODE lockmode); +extern List* indexGetPartitionOidList(Relation indexRelation); +extern List* indexGetPartitionList(Relation indexRelation, LOCKMODE lockmode); +extern void releasePartitionList(Relation relation, List** partList, LOCKMODE lockmode); + +extern List* relationGetPartitionOidList(Relation rel); +extern void releasePartitionOidList(List** partList); + +extern int2vector* getPartitionKeyAttrNo( + Oid** typeOids, HeapTuple pg_part_tup, TupleDesc tupledsc, TupleDesc rel_tupledsc); +extern void unserializePartitionStringAttribute(Const** outMax, int outMaxLen, Oid* partKeyType, int partKeyTypeLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); +extern void unserializeListPartitionAttribute(int *len, Const*** listValues, Oid* partKeyType, int partKeyTypeLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); +extern void unserializeHashPartitionAttribute(Const** outMax, int outMaxLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); + +extern int partitonKeyCompare(Const** value1, Const** value2, int len); +extern int getPartitionNumber(PartitionMap* map); + +extern bool targetListHasPartitionKey(List* targetList, Oid partitiondtableid); + +extern int constCompare_constType(Const* value1, Const* value2); + +extern bool tupleLocateThePartition(Relation partTableRel, int partSeq, TupleDesc tupleDesc, void* tuple); + +extern bool partitionHasToast(Oid partOid); + +extern void constCompare(Const* value1, Const* value2, int& compare); + +#endif /* PARTITIONMAP_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_crc.h postgresql-hll-2.14/include/include/utils/pg_crc.h --- postgresql-hll-2.14_old/include/include/utils/pg_crc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_crc.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,182 @@ +/* + * pg_crc.h + * + * PostgreSQL CRC support + * + * See Ross Williams' excellent introduction + * A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from + * http://www.ross.net/crc/ or several other net sites. + * + * We use a normal (not "reflected", in Williams' terms) CRC, using initial + * all-ones register contents and a final bit inversion. + * + * The 64-bit variant is not used as of PostgreSQL 8.1, but we retain the + * code for possible future use. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_crc.h + */ +#ifndef PG_CRC_H +#define PG_CRC_H + +/* ugly hack to let this be used in frontend and backend code on Cygwin */ +#ifdef FRONTEND +#define CRCDLLIMPORT +#else +#define CRCDLLIMPORT PGDLLIMPORT +#endif + +typedef uint32 pg_crc32; + +/* + * The CRC algorithm used for WAL et al in pre-9.5 versions. + * + * This closely resembles the normal CRC-32 algorithm, but is subtly + * different. Using Williams' terms, we use the "normal" table, but with + * "reflected" code. That's bogus, but it was like that for years before + * anyone noticed. It does not correspond to any polynomial in a normal CRC + * algorithm, so it's not clear what the error-detection properties of this + * algorithm actually are. + * + * We still need to carry this around because it is used in a few on-disk + * structures that need to be pg_upgradeable. It should not be used in new + * code. + * + * Deprecated + * + * using CRC32C instead + */ +#define INIT_TRADITIONAL_CRC32(crc) ((crc) = 0xFFFFFFFF) +#define FIN_TRADITIONAL_CRC32(crc) ((crc) ^= 0xFFFFFFFF) +/* Initialize a CRC accumulator */ +#define INIT_CRC32(crc) ((crc) = 0xFFFFFFFF) + +/* Finish a CRC calculation */ +#define FIN_CRC32(crc) ((crc) ^= 0xFFFFFFFF) + +/* Check for equality of two CRCs */ +#define EQ_CRC32(c1, c2) ((c1) == (c2)) +#define EQ_TRADITIONAL_CRC32(c1, c2) ((c1) == (c2)) +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC32(crc, data, len) \ + do { \ + const unsigned char* __data = (const unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)((crc) >> 24) ^ *__data++) & 0xFF; \ + (crc) = pg_crc32_table[__tab_index] ^ ((crc) << 8); \ + } \ + } while (0) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT uint32 pg_crc32_table[]; + +#define COMP_TRADITIONAL_CRC32(crc, data, len) \ + COMP_CRC32_NORMAL_TABLE(crc, data, len, pg_crc32_table) + +/* Sarwate's algorithm, for use with a "normal" lookup table */ +#define COMP_CRC32_NORMAL_TABLE(crc, data, len, table) \ +do { \ + const unsigned char *__data = (const unsigned char *) (data); \ + uint32 __len = (len); \ +\ + while (__len-- > 0) \ + { \ + int __tab_index = ((int) (crc) ^ *__data++) & 0xFF; \ + (crc) = table[__tab_index] ^ ((crc) >> 8); \ + } \ +} while (0) + + +#ifdef PROVIDE_64BIT_CRC + +/* + * If we use a 64-bit integer type, then a 64-bit CRC looks just like the + * usual sort of implementation. However, we can also fake it with two + * 32-bit registers. Experience has shown that the two-32-bit-registers code + * is as fast as, or even much faster than, the 64-bit code on all but true + * 64-bit machines. We use SIZEOF_VOID_P to check the native word width. + */ + +#if SIZEOF_VOID_P < 8 + +/* + * crc0 represents the LSBs of the 64-bit value, crc1 the MSBs. Note that + * with crc0 placed first, the output of 32-bit and 64-bit implementations + * will be bit-compatible only on little-endian architectures. If it were + * important to make the two possible implementations bit-compatible on + * all machines, we could do a configure test to decide how to order the + * two fields, but it seems not worth the trouble. + */ +typedef struct pg_crc64 { + uint32 crc0; + uint32 crc1; +} pg_crc64; + +/* Initialize a CRC accumulator */ +#define INIT_CRC64(crc) ((crc).crc0 = 0xffffffff, (crc).crc1 = 0xffffffff) + +/* Finish a CRC calculation */ +#define FIN_CRC64(crc) ((crc).crc0 ^= 0xffffffff, (crc).crc1 ^= 0xffffffff) + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC64(crc, data, len) \ + do { \ + uint32 __crc0 = (crc).crc0; \ + uint32 __crc1 = (crc).crc1; \ + unsigned char* __data = (unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)(__crc1 >> 24) ^ *__data++) & 0xFF; \ + __crc1 = pg_crc64_table1[__tab_index] ^ ((__crc1 << 8) | (__crc0 >> 24)); \ + __crc0 = pg_crc64_table0[__tab_index] ^ (__crc0 << 8); \ + } \ + (crc).crc0 = __crc0; \ + (crc).crc1 = __crc1; \ + } while (0) + +/* Check for equality of two CRCs */ +#define EQ_CRC64(c1, c2) ((c1).crc0 == (c2).crc0 && (c1).crc1 == (c2).crc1) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT const uint32 pg_crc64_table0[]; +extern CRCDLLIMPORT const uint32 pg_crc64_table1[]; +#else /* use int64 implementation */ + +typedef struct pg_crc64 { + uint64 crc0; +} pg_crc64; + +/* Initialize a CRC accumulator */ +#define INIT_CRC64(crc) ((crc).crc0 = UINT64CONST(0xffffffffffffffff)) + +/* Finish a CRC calculation */ +#define FIN_CRC64(crc) ((crc).crc0 ^= UINT64CONST(0xffffffffffffffff)) + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC64(crc, data, len) \ + do { \ + uint64 __crc0 = (crc).crc0; \ + unsigned char* __data = (unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)(__crc0 >> 56) ^ *__data++) & 0xFF; \ + __crc0 = pg_crc64_table[__tab_index] ^ (__crc0 << 8); \ + } \ + (crc).crc0 = __crc0; \ + } while (0) + +/* Check for equality of two CRCs */ +#define EQ_CRC64(c1, c2) ((c1).crc0 == (c2).crc0) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT const uint64 pg_crc64_table[]; +#endif /* SIZEOF_VOID_P < 8 */ +#endif /* PROVIDE_64BIT_CRC */ +#endif /* PG_CRC_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_crc_tables.h postgresql-hll-2.14/include/include/utils/pg_crc_tables.h --- postgresql-hll-2.14_old/include/include/utils/pg_crc_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_crc_tables.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,1083 @@ +/* ------------------------------------------------------------------------- + * + * pg_crc_tables.h + * Polynomial lookup tables for CRC macros + * + * We make these tables available as a .h file so that programs not linked + * with libpgport can still use the macros in pg_crc.h. They just need + * to #include this header as well. + * + * See Ross Williams' excellent introduction + * A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from + * http://www.ross.net/crc/download/crc_v3.txt or several other net sites. + * + * We use a normal (not "reflected", in Williams' terms) CRC, using initial + * all-ones register contents and a final bit inversion. + * + * The 64-bit variant is not used as of PostgreSQL 8.1, but we retain the + * code for possible future use. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_crc_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CRC_TABLES_H +#define PG_CRC_TABLES_H + +/* + * This table is based on the polynomial + * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + * (This is the same polynomial used in Ethernet checksums, for instance.) + */ +uint32 pg_crc32_table[256] = {0x00000000, + 0x77073096, + 0xEE0E612C, + 0x990951BA, + 0x076DC419, + 0x706AF48F, + 0xE963A535, + 0x9E6495A3, + 0x0EDB8832, + 0x79DCB8A4, + 0xE0D5E91E, + 0x97D2D988, + 0x09B64C2B, + 0x7EB17CBD, + 0xE7B82D07, + 0x90BF1D91, + 0x1DB71064, + 0x6AB020F2, + 0xF3B97148, + 0x84BE41DE, + 0x1ADAD47D, + 0x6DDDE4EB, + 0xF4D4B551, + 0x83D385C7, + 0x136C9856, + 0x646BA8C0, + 0xFD62F97A, + 0x8A65C9EC, + 0x14015C4F, + 0x63066CD9, + 0xFA0F3D63, + 0x8D080DF5, + 0x3B6E20C8, + 0x4C69105E, + 0xD56041E4, + 0xA2677172, + 0x3C03E4D1, + 0x4B04D447, + 0xD20D85FD, + 0xA50AB56B, + 0x35B5A8FA, + 0x42B2986C, + 0xDBBBC9D6, + 0xACBCF940, + 0x32D86CE3, + 0x45DF5C75, + 0xDCD60DCF, + 0xABD13D59, + 0x26D930AC, + 0x51DE003A, + 0xC8D75180, + 0xBFD06116, + 0x21B4F4B5, + 0x56B3C423, + 0xCFBA9599, + 0xB8BDA50F, + 0x2802B89E, + 0x5F058808, + 0xC60CD9B2, + 0xB10BE924, + 0x2F6F7C87, + 0x58684C11, + 0xC1611DAB, + 0xB6662D3D, + 0x76DC4190, + 0x01DB7106, + 0x98D220BC, + 0xEFD5102A, + 0x71B18589, + 0x06B6B51F, + 0x9FBFE4A5, + 0xE8B8D433, + 0x7807C9A2, + 0x0F00F934, + 0x9609A88E, + 0xE10E9818, + 0x7F6A0DBB, + 0x086D3D2D, + 0x91646C97, + 0xE6635C01, + 0x6B6B51F4, + 0x1C6C6162, + 0x856530D8, + 0xF262004E, + 0x6C0695ED, + 0x1B01A57B, + 0x8208F4C1, + 0xF50FC457, + 0x65B0D9C6, + 0x12B7E950, + 0x8BBEB8EA, + 0xFCB9887C, + 0x62DD1DDF, + 0x15DA2D49, + 0x8CD37CF3, + 0xFBD44C65, + 0x4DB26158, + 0x3AB551CE, + 0xA3BC0074, + 0xD4BB30E2, + 0x4ADFA541, + 0x3DD895D7, + 0xA4D1C46D, + 0xD3D6F4FB, + 0x4369E96A, + 0x346ED9FC, + 0xAD678846, + 0xDA60B8D0, + 0x44042D73, + 0x33031DE5, + 0xAA0A4C5F, + 0xDD0D7CC9, + 0x5005713C, + 0x270241AA, + 0xBE0B1010, + 0xC90C2086, + 0x5768B525, + 0x206F85B3, + 0xB966D409, + 0xCE61E49F, + 0x5EDEF90E, + 0x29D9C998, + 0xB0D09822, + 0xC7D7A8B4, + 0x59B33D17, + 0x2EB40D81, + 0xB7BD5C3B, + 0xC0BA6CAD, + 0xEDB88320, + 0x9ABFB3B6, + 0x03B6E20C, + 0x74B1D29A, + 0xEAD54739, + 0x9DD277AF, + 0x04DB2615, + 0x73DC1683, + 0xE3630B12, + 0x94643B84, + 0x0D6D6A3E, + 0x7A6A5AA8, + 0xE40ECF0B, + 0x9309FF9D, + 0x0A00AE27, + 0x7D079EB1, + 0xF00F9344, + 0x8708A3D2, + 0x1E01F268, + 0x6906C2FE, + 0xF762575D, + 0x806567CB, + 0x196C3671, + 0x6E6B06E7, + 0xFED41B76, + 0x89D32BE0, + 0x10DA7A5A, + 0x67DD4ACC, + 0xF9B9DF6F, + 0x8EBEEFF9, + 0x17B7BE43, + 0x60B08ED5, + 0xD6D6A3E8, + 0xA1D1937E, + 0x38D8C2C4, + 0x4FDFF252, + 0xD1BB67F1, + 0xA6BC5767, + 0x3FB506DD, + 0x48B2364B, + 0xD80D2BDA, + 0xAF0A1B4C, + 0x36034AF6, + 0x41047A60, + 0xDF60EFC3, + 0xA867DF55, + 0x316E8EEF, + 0x4669BE79, + 0xCB61B38C, + 0xBC66831A, + 0x256FD2A0, + 0x5268E236, + 0xCC0C7795, + 0xBB0B4703, + 0x220216B9, + 0x5505262F, + 0xC5BA3BBE, + 0xB2BD0B28, + 0x2BB45A92, + 0x5CB36A04, + 0xC2D7FFA7, + 0xB5D0CF31, + 0x2CD99E8B, + 0x5BDEAE1D, + 0x9B64C2B0, + 0xEC63F226, + 0x756AA39C, + 0x026D930A, + 0x9C0906A9, + 0xEB0E363F, + 0x72076785, + 0x05005713, + 0x95BF4A82, + 0xE2B87A14, + 0x7BB12BAE, + 0x0CB61B38, + 0x92D28E9B, + 0xE5D5BE0D, + 0x7CDCEFB7, + 0x0BDBDF21, + 0x86D3D2D4, + 0xF1D4E242, + 0x68DDB3F8, + 0x1FDA836E, + 0x81BE16CD, + 0xF6B9265B, + 0x6FB077E1, + 0x18B74777, + 0x88085AE6, + 0xFF0F6A70, + 0x66063BCA, + 0x11010B5C, + 0x8F659EFF, + 0xF862AE69, + 0x616BFFD3, + 0x166CCF45, + 0xA00AE278, + 0xD70DD2EE, + 0x4E048354, + 0x3903B3C2, + 0xA7672661, + 0xD06016F7, + 0x4969474D, + 0x3E6E77DB, + 0xAED16A4A, + 0xD9D65ADC, + 0x40DF0B66, + 0x37D83BF0, + 0xA9BCAE53, + 0xDEBB9EC5, + 0x47B2CF7F, + 0x30B5FFE9, + 0xBDBDF21C, + 0xCABAC28A, + 0x53B39330, + 0x24B4A3A6, + 0xBAD03605, + 0xCDD70693, + 0x54DE5729, + 0x23D967BF, + 0xB3667A2E, + 0xC4614AB8, + 0x5D681B02, + 0x2A6F2B94, + 0xB40BBE37, + 0xC30C8EA1, + 0x5A05DF1B, + 0x2D02EF8D}; + +#ifdef PROVIDE_64BIT_CRC + +/* + * This table is based on the polynomial + * + * x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 + + * x^40 + x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 + + * x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 + + * x^7 + x^4 + x + 1 + * + * which is borrowed from the DLT1 spec + * (ECMA-182, available from http://www.ecma.ch/ecma1/STAND/ECMA-182.HTM) + */ + +#if SIZEOF_VOID_P < 8 /* this test must match the one in pg_crc.h */ + +const uint32 pg_crc64_table0[256] = {0x00000000, + 0xA9EA3693, + 0x53D46D26, + 0xFA3E5BB5, + 0x0E42ECDF, + 0xA7A8DA4C, + 0x5D9681F9, + 0xF47CB76A, + 0x1C85D9BE, + 0xB56FEF2D, + 0x4F51B498, + 0xE6BB820B, + 0x12C73561, + 0xBB2D03F2, + 0x41135847, + 0xE8F96ED4, + 0x90E185EF, + 0x390BB37C, + 0xC335E8C9, + 0x6ADFDE5A, + 0x9EA36930, + 0x37495FA3, + 0xCD770416, + 0x649D3285, + 0x8C645C51, + 0x258E6AC2, + 0xDFB03177, + 0x765A07E4, + 0x8226B08E, + 0x2BCC861D, + 0xD1F2DDA8, + 0x7818EB3B, + 0x21C30BDE, + 0x88293D4D, + 0x721766F8, + 0xDBFD506B, + 0x2F81E701, + 0x866BD192, + 0x7C558A27, + 0xD5BFBCB4, + 0x3D46D260, + 0x94ACE4F3, + 0x6E92BF46, + 0xC77889D5, + 0x33043EBF, + 0x9AEE082C, + 0x60D05399, + 0xC93A650A, + 0xB1228E31, + 0x18C8B8A2, + 0xE2F6E317, + 0x4B1CD584, + 0xBF6062EE, + 0x168A547D, + 0xECB40FC8, + 0x455E395B, + 0xADA7578F, + 0x044D611C, + 0xFE733AA9, + 0x57990C3A, + 0xA3E5BB50, + 0x0A0F8DC3, + 0xF031D676, + 0x59DBE0E5, + 0xEA6C212F, + 0x438617BC, + 0xB9B84C09, + 0x10527A9A, + 0xE42ECDF0, + 0x4DC4FB63, + 0xB7FAA0D6, + 0x1E109645, + 0xF6E9F891, + 0x5F03CE02, + 0xA53D95B7, + 0x0CD7A324, + 0xF8AB144E, + 0x514122DD, + 0xAB7F7968, + 0x02954FFB, + 0x7A8DA4C0, + 0xD3679253, + 0x2959C9E6, + 0x80B3FF75, + 0x74CF481F, + 0xDD257E8C, + 0x271B2539, + 0x8EF113AA, + 0x66087D7E, + 0xCFE24BED, + 0x35DC1058, + 0x9C3626CB, + 0x684A91A1, + 0xC1A0A732, + 0x3B9EFC87, + 0x9274CA14, + 0xCBAF2AF1, + 0x62451C62, + 0x987B47D7, + 0x31917144, + 0xC5EDC62E, + 0x6C07F0BD, + 0x9639AB08, + 0x3FD39D9B, + 0xD72AF34F, + 0x7EC0C5DC, + 0x84FE9E69, + 0x2D14A8FA, + 0xD9681F90, + 0x70822903, + 0x8ABC72B6, + 0x23564425, + 0x5B4EAF1E, + 0xF2A4998D, + 0x089AC238, + 0xA170F4AB, + 0x550C43C1, + 0xFCE67552, + 0x06D82EE7, + 0xAF321874, + 0x47CB76A0, + 0xEE214033, + 0x141F1B86, + 0xBDF52D15, + 0x49899A7F, + 0xE063ACEC, + 0x1A5DF759, + 0xB3B7C1CA, + 0x7D3274CD, + 0xD4D8425E, + 0x2EE619EB, + 0x870C2F78, + 0x73709812, + 0xDA9AAE81, + 0x20A4F534, + 0x894EC3A7, + 0x61B7AD73, + 0xC85D9BE0, + 0x3263C055, + 0x9B89F6C6, + 0x6FF541AC, + 0xC61F773F, + 0x3C212C8A, + 0x95CB1A19, + 0xEDD3F122, + 0x4439C7B1, + 0xBE079C04, + 0x17EDAA97, + 0xE3911DFD, + 0x4A7B2B6E, + 0xB04570DB, + 0x19AF4648, + 0xF156289C, + 0x58BC1E0F, + 0xA28245BA, + 0x0B687329, + 0xFF14C443, + 0x56FEF2D0, + 0xACC0A965, + 0x052A9FF6, + 0x5CF17F13, + 0xF51B4980, + 0x0F251235, + 0xA6CF24A6, + 0x52B393CC, + 0xFB59A55F, + 0x0167FEEA, + 0xA88DC879, + 0x4074A6AD, + 0xE99E903E, + 0x13A0CB8B, + 0xBA4AFD18, + 0x4E364A72, + 0xE7DC7CE1, + 0x1DE22754, + 0xB40811C7, + 0xCC10FAFC, + 0x65FACC6F, + 0x9FC497DA, + 0x362EA149, + 0xC2521623, + 0x6BB820B0, + 0x91867B05, + 0x386C4D96, + 0xD0952342, + 0x797F15D1, + 0x83414E64, + 0x2AAB78F7, + 0xDED7CF9D, + 0x773DF90E, + 0x8D03A2BB, + 0x24E99428, + 0x975E55E2, + 0x3EB46371, + 0xC48A38C4, + 0x6D600E57, + 0x991CB93D, + 0x30F68FAE, + 0xCAC8D41B, + 0x6322E288, + 0x8BDB8C5C, + 0x2231BACF, + 0xD80FE17A, + 0x71E5D7E9, + 0x85996083, + 0x2C735610, + 0xD64D0DA5, + 0x7FA73B36, + 0x07BFD00D, + 0xAE55E69E, + 0x546BBD2B, + 0xFD818BB8, + 0x09FD3CD2, + 0xA0170A41, + 0x5A2951F4, + 0xF3C36767, + 0x1B3A09B3, + 0xB2D03F20, + 0x48EE6495, + 0xE1045206, + 0x1578E56C, + 0xBC92D3FF, + 0x46AC884A, + 0xEF46BED9, + 0xB69D5E3C, + 0x1F7768AF, + 0xE549331A, + 0x4CA30589, + 0xB8DFB2E3, + 0x11358470, + 0xEB0BDFC5, + 0x42E1E956, + 0xAA188782, + 0x03F2B111, + 0xF9CCEAA4, + 0x5026DC37, + 0xA45A6B5D, + 0x0DB05DCE, + 0xF78E067B, + 0x5E6430E8, + 0x267CDBD3, + 0x8F96ED40, + 0x75A8B6F5, + 0xDC428066, + 0x283E370C, + 0x81D4019F, + 0x7BEA5A2A, + 0xD2006CB9, + 0x3AF9026D, + 0x931334FE, + 0x692D6F4B, + 0xC0C759D8, + 0x34BBEEB2, + 0x9D51D821, + 0x676F8394, + 0xCE85B507}; + +const uint32 pg_crc64_table1[256] = {0x00000000, + 0x42F0E1EB, + 0x85E1C3D7, + 0xC711223C, + 0x49336645, + 0x0BC387AE, + 0xCCD2A592, + 0x8E224479, + 0x9266CC8A, + 0xD0962D61, + 0x17870F5D, + 0x5577EEB6, + 0xDB55AACF, + 0x99A54B24, + 0x5EB46918, + 0x1C4488F3, + 0x663D78FF, + 0x24CD9914, + 0xE3DCBB28, + 0xA12C5AC3, + 0x2F0E1EBA, + 0x6DFEFF51, + 0xAAEFDD6D, + 0xE81F3C86, + 0xF45BB475, + 0xB6AB559E, + 0x71BA77A2, + 0x334A9649, + 0xBD68D230, + 0xFF9833DB, + 0x388911E7, + 0x7A79F00C, + 0xCC7AF1FF, + 0x8E8A1014, + 0x499B3228, + 0x0B6BD3C3, + 0x854997BA, + 0xC7B97651, + 0x00A8546D, + 0x4258B586, + 0x5E1C3D75, + 0x1CECDC9E, + 0xDBFDFEA2, + 0x990D1F49, + 0x172F5B30, + 0x55DFBADB, + 0x92CE98E7, + 0xD03E790C, + 0xAA478900, + 0xE8B768EB, + 0x2FA64AD7, + 0x6D56AB3C, + 0xE374EF45, + 0xA1840EAE, + 0x66952C92, + 0x2465CD79, + 0x3821458A, + 0x7AD1A461, + 0xBDC0865D, + 0xFF3067B6, + 0x711223CF, + 0x33E2C224, + 0xF4F3E018, + 0xB60301F3, + 0xDA050215, + 0x98F5E3FE, + 0x5FE4C1C2, + 0x1D142029, + 0x93366450, + 0xD1C685BB, + 0x16D7A787, + 0x5427466C, + 0x4863CE9F, + 0x0A932F74, + 0xCD820D48, + 0x8F72ECA3, + 0x0150A8DA, + 0x43A04931, + 0x84B16B0D, + 0xC6418AE6, + 0xBC387AEA, + 0xFEC89B01, + 0x39D9B93D, + 0x7B2958D6, + 0xF50B1CAF, + 0xB7FBFD44, + 0x70EADF78, + 0x321A3E93, + 0x2E5EB660, + 0x6CAE578B, + 0xABBF75B7, + 0xE94F945C, + 0x676DD025, + 0x259D31CE, + 0xE28C13F2, + 0xA07CF219, + 0x167FF3EA, + 0x548F1201, + 0x939E303D, + 0xD16ED1D6, + 0x5F4C95AF, + 0x1DBC7444, + 0xDAAD5678, + 0x985DB793, + 0x84193F60, + 0xC6E9DE8B, + 0x01F8FCB7, + 0x43081D5C, + 0xCD2A5925, + 0x8FDAB8CE, + 0x48CB9AF2, + 0x0A3B7B19, + 0x70428B15, + 0x32B26AFE, + 0xF5A348C2, + 0xB753A929, + 0x3971ED50, + 0x7B810CBB, + 0xBC902E87, + 0xFE60CF6C, + 0xE224479F, + 0xA0D4A674, + 0x67C58448, + 0x253565A3, + 0xAB1721DA, + 0xE9E7C031, + 0x2EF6E20D, + 0x6C0603E6, + 0xF6FAE5C0, + 0xB40A042B, + 0x731B2617, + 0x31EBC7FC, + 0xBFC98385, + 0xFD39626E, + 0x3A284052, + 0x78D8A1B9, + 0x649C294A, + 0x266CC8A1, + 0xE17DEA9D, + 0xA38D0B76, + 0x2DAF4F0F, + 0x6F5FAEE4, + 0xA84E8CD8, + 0xEABE6D33, + 0x90C79D3F, + 0xD2377CD4, + 0x15265EE8, + 0x57D6BF03, + 0xD9F4FB7A, + 0x9B041A91, + 0x5C1538AD, + 0x1EE5D946, + 0x02A151B5, + 0x4051B05E, + 0x87409262, + 0xC5B07389, + 0x4B9237F0, + 0x0962D61B, + 0xCE73F427, + 0x8C8315CC, + 0x3A80143F, + 0x7870F5D4, + 0xBF61D7E8, + 0xFD913603, + 0x73B3727A, + 0x31439391, + 0xF652B1AD, + 0xB4A25046, + 0xA8E6D8B5, + 0xEA16395E, + 0x2D071B62, + 0x6FF7FA89, + 0xE1D5BEF0, + 0xA3255F1B, + 0x64347D27, + 0x26C49CCC, + 0x5CBD6CC0, + 0x1E4D8D2B, + 0xD95CAF17, + 0x9BAC4EFC, + 0x158E0A85, + 0x577EEB6E, + 0x906FC952, + 0xD29F28B9, + 0xCEDBA04A, + 0x8C2B41A1, + 0x4B3A639D, + 0x09CA8276, + 0x87E8C60F, + 0xC51827E4, + 0x020905D8, + 0x40F9E433, + 0x2CFFE7D5, + 0x6E0F063E, + 0xA91E2402, + 0xEBEEC5E9, + 0x65CC8190, + 0x273C607B, + 0xE02D4247, + 0xA2DDA3AC, + 0xBE992B5F, + 0xFC69CAB4, + 0x3B78E888, + 0x79880963, + 0xF7AA4D1A, + 0xB55AACF1, + 0x724B8ECD, + 0x30BB6F26, + 0x4AC29F2A, + 0x08327EC1, + 0xCF235CFD, + 0x8DD3BD16, + 0x03F1F96F, + 0x41011884, + 0x86103AB8, + 0xC4E0DB53, + 0xD8A453A0, + 0x9A54B24B, + 0x5D459077, + 0x1FB5719C, + 0x919735E5, + 0xD367D40E, + 0x1476F632, + 0x568617D9, + 0xE085162A, + 0xA275F7C1, + 0x6564D5FD, + 0x27943416, + 0xA9B6706F, + 0xEB469184, + 0x2C57B3B8, + 0x6EA75253, + 0x72E3DAA0, + 0x30133B4B, + 0xF7021977, + 0xB5F2F89C, + 0x3BD0BCE5, + 0x79205D0E, + 0xBE317F32, + 0xFCC19ED9, + 0x86B86ED5, + 0xC4488F3E, + 0x0359AD02, + 0x41A94CE9, + 0xCF8B0890, + 0x8D7BE97B, + 0x4A6ACB47, + 0x089A2AAC, + 0x14DEA25F, + 0x562E43B4, + 0x913F6188, + 0xD3CF8063, + 0x5DEDC41A, + 0x1F1D25F1, + 0xD80C07CD, + 0x9AFCE626}; +#else /* use int64 implementation */ + +const uint64 pg_crc64_table[256] = {UINT64CONST(0x0000000000000000), + UINT64CONST(0x42F0E1EBA9EA3693), + UINT64CONST(0x85E1C3D753D46D26), + UINT64CONST(0xC711223CFA3E5BB5), + UINT64CONST(0x493366450E42ECDF), + UINT64CONST(0x0BC387AEA7A8DA4C), + UINT64CONST(0xCCD2A5925D9681F9), + UINT64CONST(0x8E224479F47CB76A), + UINT64CONST(0x9266CC8A1C85D9BE), + UINT64CONST(0xD0962D61B56FEF2D), + UINT64CONST(0x17870F5D4F51B498), + UINT64CONST(0x5577EEB6E6BB820B), + UINT64CONST(0xDB55AACF12C73561), + UINT64CONST(0x99A54B24BB2D03F2), + UINT64CONST(0x5EB4691841135847), + UINT64CONST(0x1C4488F3E8F96ED4), + UINT64CONST(0x663D78FF90E185EF), + UINT64CONST(0x24CD9914390BB37C), + UINT64CONST(0xE3DCBB28C335E8C9), + UINT64CONST(0xA12C5AC36ADFDE5A), + UINT64CONST(0x2F0E1EBA9EA36930), + UINT64CONST(0x6DFEFF5137495FA3), + UINT64CONST(0xAAEFDD6DCD770416), + UINT64CONST(0xE81F3C86649D3285), + UINT64CONST(0xF45BB4758C645C51), + UINT64CONST(0xB6AB559E258E6AC2), + UINT64CONST(0x71BA77A2DFB03177), + UINT64CONST(0x334A9649765A07E4), + UINT64CONST(0xBD68D2308226B08E), + UINT64CONST(0xFF9833DB2BCC861D), + UINT64CONST(0x388911E7D1F2DDA8), + UINT64CONST(0x7A79F00C7818EB3B), + UINT64CONST(0xCC7AF1FF21C30BDE), + UINT64CONST(0x8E8A101488293D4D), + UINT64CONST(0x499B3228721766F8), + UINT64CONST(0x0B6BD3C3DBFD506B), + UINT64CONST(0x854997BA2F81E701), + UINT64CONST(0xC7B97651866BD192), + UINT64CONST(0x00A8546D7C558A27), + UINT64CONST(0x4258B586D5BFBCB4), + UINT64CONST(0x5E1C3D753D46D260), + UINT64CONST(0x1CECDC9E94ACE4F3), + UINT64CONST(0xDBFDFEA26E92BF46), + UINT64CONST(0x990D1F49C77889D5), + UINT64CONST(0x172F5B3033043EBF), + UINT64CONST(0x55DFBADB9AEE082C), + UINT64CONST(0x92CE98E760D05399), + UINT64CONST(0xD03E790CC93A650A), + UINT64CONST(0xAA478900B1228E31), + UINT64CONST(0xE8B768EB18C8B8A2), + UINT64CONST(0x2FA64AD7E2F6E317), + UINT64CONST(0x6D56AB3C4B1CD584), + UINT64CONST(0xE374EF45BF6062EE), + UINT64CONST(0xA1840EAE168A547D), + UINT64CONST(0x66952C92ECB40FC8), + UINT64CONST(0x2465CD79455E395B), + UINT64CONST(0x3821458AADA7578F), + UINT64CONST(0x7AD1A461044D611C), + UINT64CONST(0xBDC0865DFE733AA9), + UINT64CONST(0xFF3067B657990C3A), + UINT64CONST(0x711223CFA3E5BB50), + UINT64CONST(0x33E2C2240A0F8DC3), + UINT64CONST(0xF4F3E018F031D676), + UINT64CONST(0xB60301F359DBE0E5), + UINT64CONST(0xDA050215EA6C212F), + UINT64CONST(0x98F5E3FE438617BC), + UINT64CONST(0x5FE4C1C2B9B84C09), + UINT64CONST(0x1D14202910527A9A), + UINT64CONST(0x93366450E42ECDF0), + UINT64CONST(0xD1C685BB4DC4FB63), + UINT64CONST(0x16D7A787B7FAA0D6), + UINT64CONST(0x5427466C1E109645), + UINT64CONST(0x4863CE9FF6E9F891), + UINT64CONST(0x0A932F745F03CE02), + UINT64CONST(0xCD820D48A53D95B7), + UINT64CONST(0x8F72ECA30CD7A324), + UINT64CONST(0x0150A8DAF8AB144E), + UINT64CONST(0x43A04931514122DD), + UINT64CONST(0x84B16B0DAB7F7968), + UINT64CONST(0xC6418AE602954FFB), + UINT64CONST(0xBC387AEA7A8DA4C0), + UINT64CONST(0xFEC89B01D3679253), + UINT64CONST(0x39D9B93D2959C9E6), + UINT64CONST(0x7B2958D680B3FF75), + UINT64CONST(0xF50B1CAF74CF481F), + UINT64CONST(0xB7FBFD44DD257E8C), + UINT64CONST(0x70EADF78271B2539), + UINT64CONST(0x321A3E938EF113AA), + UINT64CONST(0x2E5EB66066087D7E), + UINT64CONST(0x6CAE578BCFE24BED), + UINT64CONST(0xABBF75B735DC1058), + UINT64CONST(0xE94F945C9C3626CB), + UINT64CONST(0x676DD025684A91A1), + UINT64CONST(0x259D31CEC1A0A732), + UINT64CONST(0xE28C13F23B9EFC87), + UINT64CONST(0xA07CF2199274CA14), + UINT64CONST(0x167FF3EACBAF2AF1), + UINT64CONST(0x548F120162451C62), + UINT64CONST(0x939E303D987B47D7), + UINT64CONST(0xD16ED1D631917144), + UINT64CONST(0x5F4C95AFC5EDC62E), + UINT64CONST(0x1DBC74446C07F0BD), + UINT64CONST(0xDAAD56789639AB08), + UINT64CONST(0x985DB7933FD39D9B), + UINT64CONST(0x84193F60D72AF34F), + UINT64CONST(0xC6E9DE8B7EC0C5DC), + UINT64CONST(0x01F8FCB784FE9E69), + UINT64CONST(0x43081D5C2D14A8FA), + UINT64CONST(0xCD2A5925D9681F90), + UINT64CONST(0x8FDAB8CE70822903), + UINT64CONST(0x48CB9AF28ABC72B6), + UINT64CONST(0x0A3B7B1923564425), + UINT64CONST(0x70428B155B4EAF1E), + UINT64CONST(0x32B26AFEF2A4998D), + UINT64CONST(0xF5A348C2089AC238), + UINT64CONST(0xB753A929A170F4AB), + UINT64CONST(0x3971ED50550C43C1), + UINT64CONST(0x7B810CBBFCE67552), + UINT64CONST(0xBC902E8706D82EE7), + UINT64CONST(0xFE60CF6CAF321874), + UINT64CONST(0xE224479F47CB76A0), + UINT64CONST(0xA0D4A674EE214033), + UINT64CONST(0x67C58448141F1B86), + UINT64CONST(0x253565A3BDF52D15), + UINT64CONST(0xAB1721DA49899A7F), + UINT64CONST(0xE9E7C031E063ACEC), + UINT64CONST(0x2EF6E20D1A5DF759), + UINT64CONST(0x6C0603E6B3B7C1CA), + UINT64CONST(0xF6FAE5C07D3274CD), + UINT64CONST(0xB40A042BD4D8425E), + UINT64CONST(0x731B26172EE619EB), + UINT64CONST(0x31EBC7FC870C2F78), + UINT64CONST(0xBFC9838573709812), + UINT64CONST(0xFD39626EDA9AAE81), + UINT64CONST(0x3A28405220A4F534), + UINT64CONST(0x78D8A1B9894EC3A7), + UINT64CONST(0x649C294A61B7AD73), + UINT64CONST(0x266CC8A1C85D9BE0), + UINT64CONST(0xE17DEA9D3263C055), + UINT64CONST(0xA38D0B769B89F6C6), + UINT64CONST(0x2DAF4F0F6FF541AC), + UINT64CONST(0x6F5FAEE4C61F773F), + UINT64CONST(0xA84E8CD83C212C8A), + UINT64CONST(0xEABE6D3395CB1A19), + UINT64CONST(0x90C79D3FEDD3F122), + UINT64CONST(0xD2377CD44439C7B1), + UINT64CONST(0x15265EE8BE079C04), + UINT64CONST(0x57D6BF0317EDAA97), + UINT64CONST(0xD9F4FB7AE3911DFD), + UINT64CONST(0x9B041A914A7B2B6E), + UINT64CONST(0x5C1538ADB04570DB), + UINT64CONST(0x1EE5D94619AF4648), + UINT64CONST(0x02A151B5F156289C), + UINT64CONST(0x4051B05E58BC1E0F), + UINT64CONST(0x87409262A28245BA), + UINT64CONST(0xC5B073890B687329), + UINT64CONST(0x4B9237F0FF14C443), + UINT64CONST(0x0962D61B56FEF2D0), + UINT64CONST(0xCE73F427ACC0A965), + UINT64CONST(0x8C8315CC052A9FF6), + UINT64CONST(0x3A80143F5CF17F13), + UINT64CONST(0x7870F5D4F51B4980), + UINT64CONST(0xBF61D7E80F251235), + UINT64CONST(0xFD913603A6CF24A6), + UINT64CONST(0x73B3727A52B393CC), + UINT64CONST(0x31439391FB59A55F), + UINT64CONST(0xF652B1AD0167FEEA), + UINT64CONST(0xB4A25046A88DC879), + UINT64CONST(0xA8E6D8B54074A6AD), + UINT64CONST(0xEA16395EE99E903E), + UINT64CONST(0x2D071B6213A0CB8B), + UINT64CONST(0x6FF7FA89BA4AFD18), + UINT64CONST(0xE1D5BEF04E364A72), + UINT64CONST(0xA3255F1BE7DC7CE1), + UINT64CONST(0x64347D271DE22754), + UINT64CONST(0x26C49CCCB40811C7), + UINT64CONST(0x5CBD6CC0CC10FAFC), + UINT64CONST(0x1E4D8D2B65FACC6F), + UINT64CONST(0xD95CAF179FC497DA), + UINT64CONST(0x9BAC4EFC362EA149), + UINT64CONST(0x158E0A85C2521623), + UINT64CONST(0x577EEB6E6BB820B0), + UINT64CONST(0x906FC95291867B05), + UINT64CONST(0xD29F28B9386C4D96), + UINT64CONST(0xCEDBA04AD0952342), + UINT64CONST(0x8C2B41A1797F15D1), + UINT64CONST(0x4B3A639D83414E64), + UINT64CONST(0x09CA82762AAB78F7), + UINT64CONST(0x87E8C60FDED7CF9D), + UINT64CONST(0xC51827E4773DF90E), + UINT64CONST(0x020905D88D03A2BB), + UINT64CONST(0x40F9E43324E99428), + UINT64CONST(0x2CFFE7D5975E55E2), + UINT64CONST(0x6E0F063E3EB46371), + UINT64CONST(0xA91E2402C48A38C4), + UINT64CONST(0xEBEEC5E96D600E57), + UINT64CONST(0x65CC8190991CB93D), + UINT64CONST(0x273C607B30F68FAE), + UINT64CONST(0xE02D4247CAC8D41B), + UINT64CONST(0xA2DDA3AC6322E288), + UINT64CONST(0xBE992B5F8BDB8C5C), + UINT64CONST(0xFC69CAB42231BACF), + UINT64CONST(0x3B78E888D80FE17A), + UINT64CONST(0x7988096371E5D7E9), + UINT64CONST(0xF7AA4D1A85996083), + UINT64CONST(0xB55AACF12C735610), + UINT64CONST(0x724B8ECDD64D0DA5), + UINT64CONST(0x30BB6F267FA73B36), + UINT64CONST(0x4AC29F2A07BFD00D), + UINT64CONST(0x08327EC1AE55E69E), + UINT64CONST(0xCF235CFD546BBD2B), + UINT64CONST(0x8DD3BD16FD818BB8), + UINT64CONST(0x03F1F96F09FD3CD2), + UINT64CONST(0x41011884A0170A41), + UINT64CONST(0x86103AB85A2951F4), + UINT64CONST(0xC4E0DB53F3C36767), + UINT64CONST(0xD8A453A01B3A09B3), + UINT64CONST(0x9A54B24BB2D03F20), + UINT64CONST(0x5D45907748EE6495), + UINT64CONST(0x1FB5719CE1045206), + UINT64CONST(0x919735E51578E56C), + UINT64CONST(0xD367D40EBC92D3FF), + UINT64CONST(0x1476F63246AC884A), + UINT64CONST(0x568617D9EF46BED9), + UINT64CONST(0xE085162AB69D5E3C), + UINT64CONST(0xA275F7C11F7768AF), + UINT64CONST(0x6564D5FDE549331A), + UINT64CONST(0x279434164CA30589), + UINT64CONST(0xA9B6706FB8DFB2E3), + UINT64CONST(0xEB46918411358470), + UINT64CONST(0x2C57B3B8EB0BDFC5), + UINT64CONST(0x6EA7525342E1E956), + UINT64CONST(0x72E3DAA0AA188782), + UINT64CONST(0x30133B4B03F2B111), + UINT64CONST(0xF7021977F9CCEAA4), + UINT64CONST(0xB5F2F89C5026DC37), + UINT64CONST(0x3BD0BCE5A45A6B5D), + UINT64CONST(0x79205D0E0DB05DCE), + UINT64CONST(0xBE317F32F78E067B), + UINT64CONST(0xFCC19ED95E6430E8), + UINT64CONST(0x86B86ED5267CDBD3), + UINT64CONST(0xC4488F3E8F96ED40), + UINT64CONST(0x0359AD0275A8B6F5), + UINT64CONST(0x41A94CE9DC428066), + UINT64CONST(0xCF8B0890283E370C), + UINT64CONST(0x8D7BE97B81D4019F), + UINT64CONST(0x4A6ACB477BEA5A2A), + UINT64CONST(0x089A2AACD2006CB9), + UINT64CONST(0x14DEA25F3AF9026D), + UINT64CONST(0x562E43B4931334FE), + UINT64CONST(0x913F6188692D6F4B), + UINT64CONST(0xD3CF8063C0C759D8), + UINT64CONST(0x5DEDC41A34BBEEB2), + UINT64CONST(0x1F1D25F19D51D821), + UINT64CONST(0xD80C07CD676F8394), + UINT64CONST(0x9AFCE626CE85B507)}; +#endif /* SIZEOF_VOID_P < 8 */ +#endif /* PROVIDE_64BIT_CRC */ + +#endif /* PG_CRC_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_locale.h postgresql-hll-2.14/include/include/utils/pg_locale.h --- postgresql-hll-2.14_old/include/include/utils/pg_locale.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_locale.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,78 @@ +/* ----------------------------------------------------------------------- + * + * PostgreSQL locale utilities + * + * src/include/utils/pg_locale.h + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * ----------------------------------------------------------------------- + */ + +#ifndef _PG_LOCALE_ +#define _PG_LOCALE_ + +#include +#ifdef LOCALE_T_IN_XLOCALE +#include +#endif + +#include "utils/guc.h" + +extern bool check_locale_messages(char** newval, void** extra, GucSource source); +extern void assign_locale_messages(const char* newval, void* extra); +extern bool check_locale_monetary(char** newval, void** extra, GucSource source); +extern void assign_locale_monetary(const char* newval, void* extra); +extern bool check_locale_numeric(char** newval, void** extra, GucSource source); +extern void assign_locale_numeric(const char* newval, void* extra); +extern bool check_locale_time(char** newval, void** extra, GucSource source); +extern void assign_locale_time(const char* newval, void* extra); + +extern bool check_locale(int category, const char* locale, char** canonname); +extern char* pg_perm_setlocale(int category, const char* locale); + +extern bool lc_collate_is_c(Oid collation); +extern bool lc_ctype_is_c(Oid collation); + +/* + * Return the POSIX lconv struct (contains number/money formatting + * information) with locale information for all categories. + */ +extern struct lconv* PGLC_localeconv(void); + +/* + * Free memory pointed by internal members of u_sess->lc_cxt.cur_lc_conv. These memory + * are allocated by strdup in PGLC_localeconv. + * + * NOT free the memory pointed by u_sess->lc_cxt.cur_lc_conv itself. So we did not set + * u_sess->lc_cxt.cur_lc_conv to NULL. u_sess->lc_cxt.cur_lc_conv is allocated by + * palloc0 in knl_u_locale_init. + */ +extern void localeconv_deinitialize_session(void); + +extern void cache_locale_time(void); + +void freeLocaleCacheAtThreadExit(void); + +/* + * We define our own wrapper around locale_t so we can keep the same + * function signatures for all builds, while not having to create a + * fake version of the standard type locale_t in the global namespace. + * The fake version of pg_locale_t can be checked for truth; that's + * about all it will be needed for. + */ +#ifdef HAVE_LOCALE_T +typedef locale_t pg_locale_t; +#else +typedef int pg_locale_t; +#endif + +extern pg_locale_t pg_newlocale_from_collation(Oid collid); + +/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ +#ifdef USE_WIDE_UPPER_LOWER +extern size_t wchar2char(char* to, const wchar_t* from, size_t tolen, pg_locale_t locale); +extern size_t char2wchar(wchar_t* to, size_t tolen, const char* from, size_t fromlen, pg_locale_t locale); +#endif + +#endif /* _PG_LOCALE_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_lsn.h postgresql-hll-2.14/include/include/utils/pg_lsn.h --- postgresql-hll-2.14_old/include/include/utils/pg_lsn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_lsn.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,28 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_lsn.h + * Declarations for operations on log sequence numbers (LSNs) of + * PostgreSQL. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/pg_lsn.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_LSN_H +#define PG_LSN_H + +#include "fmgr.h" +#include "access/xlogdefs.h" + +#define DatumGetLSN(X) ((XLogRecPtr)DatumGetInt64(X)) +#define LSNGetDatum(X) (Int64GetDatum((int64)(X))) + +#define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n)) +#define PG_RETURN_LSN(x) return LSNGetDatum(x) + +#endif /* PG_LSN_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_lzcompress.h postgresql-hll-2.14/include/include/utils/pg_lzcompress.h --- postgresql-hll-2.14_old/include/include/utils/pg_lzcompress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_lzcompress.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,130 @@ +/* ---------- + * pg_lzcompress.h - + * + * Definitions for the builtin LZ compressor + * + * src/include/utils/pg_lzcompress.h + * ---------- + */ + +#ifndef _PG_LZCOMPRESS_H_ +#define _PG_LZCOMPRESS_H_ + +/* ---------- + * PGLZ_Header - + * + * The information at the start of the compressed data. + * ---------- + */ +typedef struct PGLZ_Header { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 rawsize; +} PGLZ_Header; + +/* ---------- + * PGLZ_MAX_OUTPUT - + * + * Macro to compute the buffer size required by pglz_compress(). + * We allow 4 bytes for overrun before detecting compression failure. + * ---------- + */ +#define PGLZ_MAX_OUTPUT(_dlen) ((_dlen) + 4 + sizeof(PGLZ_Header)) + +/* ---------- + * PGLZ_RAW_SIZE - + * + * Macro to determine the uncompressed data size contained + * in the entry. + * ---------- + */ +#define PGLZ_RAW_SIZE(_lzdata) ((_lzdata)->rawsize) + +/* ---------- + * PGLZ_Strategy - + * + * Some values that control the compression algorithm. + * + * min_input_size Minimum input data size to consider compression. + * + * max_input_size Maximum input data size to consider compression. + * + * min_comp_rate Minimum compression rate (0-99%) to require. + * Regardless of min_comp_rate, the output must be + * smaller than the input, else we don't store + * compressed. + * + * first_success_by Abandon compression if we find no compressible + * data within the first this-many bytes. + * + * match_size_good The initial GOOD match size when starting history + * lookup. When looking up the history to find a + * match that could be expressed as a tag, the + * algorithm does not always walk back entirely. + * A good match fast is usually better than the + * best possible one very late. For each iteration + * in the lookup, this value is lowered so the + * longer the lookup takes, the smaller matches + * are considered good. + * + * match_size_drop The percentage by which match_size_good is lowered + * after each history check. Allowed values are + * 0 (no change until end) to 100 (only check + * latest history entry at all). + * ---------- + */ +typedef struct PGLZ_Strategy { + int32 min_input_size; + int32 max_input_size; + int32 min_comp_rate; + int32 first_success_by; + int32 match_size_good; + int32 match_size_drop; +} PGLZ_Strategy; + +/* ---------- + * Local definitions + * ---------- + */ +#define PGLZ_HISTORY_LISTS 8192 /* must be power of 2 */ +#define PGLZ_HISTORY_MASK (PGLZ_HISTORY_LISTS - 1) +#define PGLZ_HISTORY_SIZE 4096 +#define PGLZ_MAX_MATCH 273 + +/* ---------- + * PGLZ_HistEntry - + * + * Linked list for the backward history lookup + * + * All the entries sharing a hash key are linked in a doubly linked list. + * This makes it easy to remove an entry when it's time to recycle it + * (because it's more than 4K positions old). + * ---------- + */ +typedef struct PGLZ_HistEntry { + struct PGLZ_HistEntry* next; /* links for my hash key's list */ + struct PGLZ_HistEntry* prev; + int hindex; /* my current hash key */ + const char* pos; /* my input position */ +} PGLZ_HistEntry; + +/* ---------- + * The standard strategies + * + * PGLZ_strategy_default Recommended default strategy for TOAST. + * + * PGLZ_strategy_always Try to compress inputs of any length. + * Fallback to uncompressed storage only if + * output would be larger than input. + * ---------- + */ +extern const PGLZ_Strategy* const PGLZ_strategy_default; +extern const PGLZ_Strategy* const PGLZ_strategy_always; + +/* ---------- + * Global function declarations + * ---------- + */ +extern bool pglz_compress(const char* source, int32 slen, PGLZ_Header* dest, const PGLZ_Strategy* strategy); +extern void pglz_decompress(const PGLZ_Header* source, char* dest); + +#endif /* _PG_LZCOMPRESS_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/pg_rusage.h postgresql-hll-2.14/include/include/utils/pg_rusage.h --- postgresql-hll-2.14_old/include/include/utils/pg_rusage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/pg_rusage.h 2020-12-12 17:06:43.291348606 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * pg_rusage.h + * header file for resource usage measurement support routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_rusage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_RUSAGE_H +#define PG_RUSAGE_H + +#include + +#ifdef HAVE_SYS_RESOURCE_H +#include +#else +#include "rusagestub.h" +#endif + +/* State structure for pg_rusage_init/pg_rusage_show */ +typedef struct PGRUsage { + struct timeval tv; + struct rusage ru; +} PGRUsage; + +extern void pg_rusage_init(PGRUsage* ru0); +extern const char* pg_rusage_show(const PGRUsage* ru0); + +#endif /* PG_RUSAGE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/plancache.h postgresql-hll-2.14/include/include/utils/plancache.h --- postgresql-hll-2.14_old/include/include/utils/plancache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/plancache.h 2020-12-12 17:06:43.292348619 +0800 @@ -0,0 +1,424 @@ +/* ------------------------------------------------------------------------- + * + * plancache.h + * Plan cache definitions. + * + * See plancache.c for comments. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/plancache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANCACHE_H +#define PLANCACHE_H + +#include "access/tupdesc.h" +#include "nodes/params.h" +#include "utils/atomic.h" +#ifdef PGXC +#include "pgxc/locator.h" +#include "nodes/plannodes.h" +#endif + +#ifdef ENABLE_MOT +// forward declaration for MOT JitContext +namespace JitExec +{ + struct JitContext; +} +#endif + +#define CACHEDPLANSOURCE_MAGIC 195726186 +#define CACHEDPLAN_MAGIC 953717834 + +#ifdef ENABLE_MOT +/* different storage engine types that might be used by a query */ +typedef enum { + SE_TYPE_UNSPECIFIED = 0, /* unspecified storage engine */ + SE_TYPE_MOT, /* MOT storage engine */ + SE_TYPE_PAGE_BASED, /* Page Based storage engine */ + SE_TYPE_MIXED /* Mixed (MOT & Page Based) storage engines */ +} StorageEngineType; +#endif + +/* possible values for plan_cache_mode */ +typedef enum { + PLAN_CACHE_MODE_AUTO, + PLAN_CACHE_MODE_FORCE_GENERIC_PLAN, + PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN +} PlanCacheMode; + +typedef enum { + GPC_PRIVATE, + GPC_SHARED, + GPC_CPLAN, // generate cplan + GPC_UNSHARED, // not satisfied share condition, like stream plan +} GPCSourceKind; + +typedef enum { + GPC_SHARE_IN_LOCAL_SAVE_PLAN_LIST, + GPC_SHARE_IN_LOCAL_UNGPC_PLAN_LIST, // contains GPC_PRIVATE, GPC_UNSHARED and GPC_CPLAN plancache + GPC_SHARE_IN_PREPARE_STATEMENT, + GPC_SHARE_IN_SHARE_TABLE, + GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST, +} GPCSourceSharedLoc; + +typedef enum { + GPC_VALID, + GPC_INVALID, +} GPCSourceSharedStatus; + +class GPCPlanStatus +{ +public: + GPCPlanStatus() { + m_kind = GPC_PRIVATE; + m_location = GPC_SHARE_IN_PREPARE_STATEMENT; + m_status = GPC_VALID; + m_refcount = 0; + } + + inline void ShareInit() + { + m_kind = GPC_SHARED; + m_location = GPC_SHARE_IN_PREPARE_STATEMENT; + m_status = GPC_VALID; + m_refcount = 0; + } + // NOTE: can not reset to GPC_PRIVATE + inline void SetKind(GPCSourceKind kind) + { + Assert(kind != GPC_PRIVATE); + pg_memory_barrier(); + m_kind = kind; + } + inline void SetLoc(GPCSourceSharedLoc location) + { + pg_memory_barrier(); + m_location = location; + } + + inline void SetStatus(GPCSourceSharedStatus status) + { + pg_memory_barrier(); + m_status = status; + } + + inline bool IsPrivatePlan() + { + pg_memory_barrier(); + return m_kind == GPC_PRIVATE; + } + + inline bool IsSharePlan() + { + pg_memory_barrier(); + return m_kind == GPC_SHARED; + } + + inline bool IsUnSharedPlan() + { + pg_memory_barrier(); + return m_kind == GPC_UNSHARED; + } + + inline bool IsUnShareCplan() + { + pg_memory_barrier(); + return m_kind == GPC_CPLAN; + } + + inline bool InSavePlanList(GPCSourceKind kind) + { + pg_memory_barrier(); + return m_kind == kind && m_location == GPC_SHARE_IN_LOCAL_SAVE_PLAN_LIST; + } + + inline bool InUngpcPlanList() + { + pg_memory_barrier(); + return (m_kind != GPC_SHARED) && m_location == GPC_SHARE_IN_LOCAL_UNGPC_PLAN_LIST; + } + + inline bool InPrepareStmt() + { + pg_memory_barrier(); + return m_location == GPC_SHARE_IN_PREPARE_STATEMENT; + } + + inline bool InShareTable() + { + pg_memory_barrier(); + return m_kind == GPC_SHARED && (m_location == GPC_SHARE_IN_SHARE_TABLE || m_location == GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST); + } + + inline bool InShareTableInvalidList() + { + pg_memory_barrier(); + return (m_kind == GPC_SHARED && m_location == GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST); + } + + inline bool IsValid() + { + pg_memory_barrier(); + return m_status == GPC_VALID; + } + + inline bool NeedDropSharedGPC() + { + Assert (m_kind == GPC_SHARED); + pg_memory_barrier(); + return m_location == GPC_SHARE_IN_SHARE_TABLE && m_status == GPC_INVALID; + } + + inline void AddRefcount() + { + pg_atomic_fetch_add_u32((volatile uint32*)&m_refcount, 1); + } + + inline void SubRefCount() + { + pg_atomic_fetch_sub_u32((volatile uint32*)&m_refcount, 1); + } + + inline bool RefCountZero() + { + /* if is same as 0 then set 0 and return true, if is different then do nothing and return false */ + uint32 expect = 0; + return pg_atomic_compare_exchange_u32((volatile uint32*)&m_refcount, &expect, 0); + } + + inline int GetRefCount() + { + return m_refcount; + } + + inline bool CheckRefCount() + { + /* m_refcount can not less than 0 */ + int val = (int)pg_atomic_fetch_add_u32((volatile uint32*)&m_refcount, 0); + return val >= 0; + } + +private: + volatile GPCSourceKind m_kind; + volatile GPCSourceSharedLoc m_location; + volatile GPCSourceSharedStatus m_status; + volatile int m_refcount; +}; + +typedef struct GPCSource +{ + GPCPlanStatus status; + struct GPCKey* key; //remember when we generate the plan. +} GPCSource; + +typedef struct SPISign +{ + uint32 spi_key; /* hash value of PLpgSQL_function's fn_hashkey */ + Oid func_oid; + uint32 spi_id; /* spi idx to PLpgSQL_expr, same as plansource's spi_id */ + int plansource_id; /* plansource idx in spiplan's plancache_list */ +} SPISign; + +/* + * CachedPlanSource (which might better have been called CachedQuery) + * represents a SQL query that we expect to use multiple times. It stores + * the query source text, the raw parse tree, and the analyzed-and-rewritten + * query tree, as well as adjunct data. Cache invalidation can happen as a + * result of DDL affecting objects used by the query. In that case we discard + * the analyzed-and-rewritten query tree, and rebuild it when next needed. + * + * An actual execution plan, represented by CachedPlan, is derived from the + * CachedPlanSource when we need to execute the query. The plan could be + * either generic (usable with any set of plan parameters) or custom (for a + * specific set of parameters). plancache.c contains the logic that decides + * which way to do it for any particular execution. If we are using a generic + * cached plan then it is meant to be re-used across multiple executions, so + * callers must always treat CachedPlans as read-only. + * + * Once successfully built and "saved", CachedPlanSources typically live + * for the life of the backend, although they can be dropped explicitly. + * CachedPlans are reference-counted and go away automatically when the last + * reference is dropped. A CachedPlan can outlive the CachedPlanSource it + * was created from. + * + * An "unsaved" CachedPlanSource can be used for generating plans, but it + * lives in transient storage and will not be updated in response to sinval + * events. + * + * CachedPlans made from saved CachedPlanSources are likewise in permanent + * storage, so to avoid memory leaks, the reference-counted references to them + * must be held in permanent data structures or ResourceOwners. CachedPlans + * made from unsaved CachedPlanSources are in children of the caller's + * memory context, so references to them should not be longer-lived than + * that context. (Reference counting is somewhat pro forma in that case, + * though it may be useful if the CachedPlan can be discarded early.) + * + * A CachedPlanSource has two associated memory contexts: one that holds the + * struct itself, the query source text and the raw parse tree, and another + * context that holds the rewritten query tree and associated data. This + * allows the query tree to be discarded easily when it is invalidated. + * + * Some callers wish to use the CachedPlan API even with one-shot queries + * that have no reason to be saved at all. We therefore support a "oneshot" + * variant that does no data copying or invalidation checking. In this case + * there are no separate memory contexts: the CachedPlanSource struct and + * all subsidiary data live in the caller's CurrentMemoryContext, and there + * is no way to free memory short of clearing that entire context. A oneshot + * plan is always treated as unsaved. + * + * Note: the string referenced by commandTag is not subsidiary storage; + * it is assumed to be a compile-time-constant string. As with portals, + * commandTag shall be NULL if and only if the original query string (before + * rewriting) was an empty string. + */ +typedef struct CachedPlanSource { + int magic; /* should equal CACHEDPLANSOURCE_MAGIC */ + Node* raw_parse_tree; /* output of raw_parser() */ + const char* query_string; /* source text of query */ + const char* commandTag; /* command tag (a constant!), or NULL */ + Oid* param_types; /* array of parameter type OIDs, or NULL */ + int num_params; /* length of param_types array */ + ParserSetupHook parserSetup; /* alternative parameter spec method */ + void* parserSetupArg; + int cursor_options; /* cursor options used for planning */ + Oid rewriteRoleId; /* Role ID we did rewriting for */ + bool dependsOnRole; /* is rewritten query specific to role? */ + bool fixed_result; /* disallow change in result tupdesc? */ + TupleDesc resultDesc; /* result type; NULL = doesn't return tuples */ + MemoryContext context; /* memory context holding all above */ + /* These fields describe the current analyzed-and-rewritten query tree: */ + List* query_list; /* list of Query nodes, or NIL if not valid */ + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the queries depend on */ + List* invalItems; /* other dependencies, as PlanInvalItems */ + struct OverrideSearchPath* search_path; /* search_path used for + * parsing and planning */ + MemoryContext query_context; /* context holding the above, or NULL */ + /* If we have a generic plan, this is a reference-counted link to it: */ + struct CachedPlan* gplan; /* generic plan, or NULL if not valid */ + /* Some state flags: */ + bool is_complete; /* has CompleteCachedPlan been done? */ + bool is_saved; /* has CachedPlanSource been "saved"? */ + bool is_valid; /* is the query_list currently valid? */ + bool is_oneshot; /* is it a "oneshot" plan? */ +#ifdef ENABLE_MOT + StorageEngineType storageEngineType; /* which storage engine is used*/ + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif + int generation; /* increments each time we create a plan */ + /* If CachedPlanSource has been saved, it is a member of a global list */ + struct CachedPlanSource* next_saved; /* list link, if so */ + /* State kept to help decide whether to use custom or generic plans: */ + double generic_cost; /* cost of generic plan, or -1 if not known */ + double total_custom_cost; /* total cost of custom plans so far */ + int num_custom_plans; /* number of plans included in total */ + + GPCSource gpc; /* share plan cache */ + SPISign spi_signature; + bool is_support_gplan; /* true if generate gplan */ +#ifdef PGXC + char* stmt_name; /* If set, this is a copy of prepared stmt name */ + bool stream_enabled; /* true if the plan is made with stream operator enabled */ + struct CachedPlan* cplan; /* custom plan, or NULL if not valid */ + ExecNodes* single_exec_node; + bool is_read_only; + void* lightProxyObj; /* light cn object */ + + void* opFusionObj; /* operator fusion object */ + bool is_checked_opfusion; + + bool gplan_is_fqs; /* if gplan is a fqs plan, use generic plan if + so when enable_pbe_optimization is on */ + bool force_custom_plan; /* force to use custom plan */ + bool single_shard_stmt; /* single shard stmt? */ +#endif +} CachedPlanSource; + +/* + * CachedPlan represents an execution plan derived from a CachedPlanSource. + * The reference count includes both the link from the parent CachedPlanSource + * (if any), and any active plan executions, so the plan can be discarded + * exactly when refcount goes to zero. Both the struct itself and the + * subsidiary data live in the context denoted by the context field. + * This makes it easy to free a no-longer-needed cached plan. (However, + * if is_oneshot is true, the context does not belong solely to the CachedPlan + * so no freeing is possible.) + */ +typedef struct CachedPlan { + int magic; /* should equal CACHEDPLAN_MAGIC */ + List* stmt_list; /* list of statement nodes (PlannedStmts and + * bare utility statements) */ + bool is_saved; /* is CachedPlan in a long-lived context? */ + bool is_valid; /* is the stmt_list currently valid? */ + bool is_oneshot; /* is it a "oneshot" plan? */ +#ifdef ENABLE_MOT + StorageEngineType storageEngineType; /* which storage engine is used*/ + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif + bool dependsOnRole; /* is plan specific to that role? */ + Oid planRoleId; /* Role ID the plan was created for */ + TransactionId saved_xmin; /* if valid, replan when TransactionXmin + * changes from this value */ + int generation; /* parent's generation number for this plan */ + int refcount; /* count of live references to this struct */ + bool single_shard_stmt; /* single shard stmt? */ + MemoryContext context; /* context containing this CachedPlan */ + + volatile int global_refcount; + volatile bool is_share; /* is it gpc share plan? */ + int dn_stmt_num; /* datanode statment num */ + inline bool isShared() + { + pg_memory_barrier(); + return is_share; + } +} CachedPlan; + +extern void InitPlanCache(void); +extern void ResetPlanCache(void); + +extern CachedPlanSource* CreateCachedPlan(Node* raw_parse_tree, const char* query_string, +#ifdef PGXC + const char* stmt_name, +#endif + const char* commandTag, + bool enable_spi_gpc = false); +extern CachedPlanSource* CreateOneShotCachedPlan( + Node* raw_parse_tree, const char* query_string, const char* commandTag); +extern void CompleteCachedPlan(CachedPlanSource* plansource, List* querytree_list, MemoryContext querytree_context, + Oid* param_types, int num_params, ParserSetupHook parserSetup, void* parserSetupArg, int cursor_options, + bool fixed_result, const char* stmt_name, ExecNodes* single_exec_node = NULL, bool is_read_only = false); + +extern void SaveCachedPlan(CachedPlanSource* plansource); +extern void DropCachedPlan(CachedPlanSource* plansource); + +extern void CachedPlanSetParentContext(CachedPlanSource* plansource, MemoryContext newcontext); + +extern CachedPlanSource *CopyCachedPlan(CachedPlanSource *plansource, bool is_share); + +extern bool CachedPlanIsValid(CachedPlanSource* plansource); + +extern List* CachedPlanGetTargetList(CachedPlanSource* plansource); + +extern CachedPlan* GetCachedPlan(CachedPlanSource* plansource, ParamListInfo boundParams, bool useResOwner); +extern void ReleaseCachedPlan(CachedPlan* plan, bool useResOwner); +extern void DropCachedPlanInternal(CachedPlanSource* plansource); +extern List* RevalidateCachedQuery(CachedPlanSource* plansource, bool has_lp = false); + +extern void CheckRelDependency(CachedPlanSource *plansource, Oid relid); +extern void CheckInvalItemDependency(CachedPlanSource *plansource, int cacheid, uint32 hashvalue); +extern void ResetPlanCache(CachedPlanSource *plansource); + +extern void PlanCacheRelCallback(Datum arg, Oid relid); +extern void PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue); +extern void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue); + +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/plog.h postgresql-hll-2.14/include/include/utils/plog.h --- postgresql-hll-2.14_old/include/include/utils/plog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/plog.h 2020-12-12 17:06:43.292348619 +0800 @@ -0,0 +1,360 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * plog.h + * + * + * + * IDENTIFICATION + * src/include/utils/plog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_UTILS_PLOG_H_ +#define SRC_INCLUDE_UTILS_PLOG_H_ + +#include "c.h" +#include "miscadmin.h" +#include "portability/instr_time.h" +#include "postmaster/syslogger.h" +#include "replication/replicainternal.h" + +#define RET_TYPE_OK 1 +#define RET_TYPE_FAIL 0 +#define PLOG_ENTRY_MAGICNUM (0xFFFFFFFF) + +enum DataSourceType { + /* magnetic disk */ + DS_MD = 0, + + /* OBS data source */ + DS_OBS, + + /* Hadoop data source */ + DS_HADOOP, + + /* remote datanode */ + DS_REMOTE_DATANODE, + + /* current number of valid data source, maybe equal to DS_UPLIMIT */ + DS_VALID_NUM, + + /* max value of data source */ + DS_UPLIMIT = 127 +}; + +/* data resource require type */ +enum DataResReqType { + /* OBS LIST */ + DSRQ_LIST = 0, + + /* read data from data source */ + DSRQ_READ, + + /* write data to data source */ + DSRQ_WRITE, + + /* OBS OPEN */ + DSRQ_OPEN, + + /* current number of valid requiring type */ + DSRQ_VALID_NUM, + + /* max value of requiring data source */ + DSRQ_UPLIMIT = 127 +}; + +/* + * Add plog_magic to distinguish 32 bits u_sess->debug_query_id + * from 64 bits u_sess->debug_query_id in log files of gs_profile. + * In case of 32 bits u_sess->debug_query_id, gxid and gqid form a 8 byte, and align with 8-byte tid. + * In case of 64 bits u_sess->debug_query_id, gxid and plog_magic form a 8 byte, and align with 8-byte tid. + * Thus, plog_magic can be used to tell us which type of u_sess->debug_query_id is read from the log files. + * Here, byte alignment feature is used. So be careful to maintain this byte alignment + * when revising PLogEntryMeta. + */ +typedef struct { + struct timeval req_time; /* record's time */ + ThreadId tid; /* thread id */ + uint32 gxid; /* global transaction id */ + uint32 plog_magic; /* PLogEntryMeta MAGICNUM */ + uint64 gqid; /* debug query id */ +} PLogEntryMeta; /* 8byte alligned */ + +typedef struct { + uint8 data_src; + uint8 req_type; + uint8 ret_type; /* 1, success; 0, failed */ + uint8 item_num; /* <= PLOG_MD_ITEM_MAX_NUM */ +} PLogEntryHead; /* 4byte alligned */ + +typedef struct { + uint32 sum_count; + uint32 sum_size; /* how many data */ + uint32 sum_usec; /* time to run, upmost is 1 hour */ +} PLogEntryItem; /* 4byte alligned */ + +typedef struct { + uint8 data_src; + uint8 req_type; + + /* RET_TYPE_OK or RET_TYPE_FAIL */ + uint8 ret_type; + + /* + * if ret_type is RET_TYPE_OK, + * dat_size means the real data amount offered by disk/OBS, etc + * if ret_type is RET_TYPE_FAIL, + * dat_size means the data amount required by caller + * + * req_usec always mean the used time to require and server. + */ + uint32 dat_size; /* data size */ + uint32 req_usec; /* required time with us */ +} IndicatorItem; + +typedef struct { + PLogEntryMeta meta; + PLogEntryHead head; + PLogEntryItem item[FLEXIBLE_ARRAY_MEMBER]; + /* the other items */ +} PLogEntry; + +typedef struct { + PLogEntry basic; +} PLogBasicEntry; + +typedef struct { + /* message protocol head */ + char msghead[LOGPIPE_HEADER_SIZE]; + union { + PLogBasicEntry entry; + } msgbody; +} PLogMsg; + +extern void aggregate_profile_logs(IndicatorItem* new_item, struct timeval* nowtm); +extern void flush_plog(void); + +#define SKIPPED_MODE() \ + (t_thrd.xlog_cxt.InRecovery || (t_thrd.postmaster_cxt.HaShmData == NULL) || \ + (t_thrd.postmaster_cxt.HaShmData->current_mode != PRIMARY_MODE && \ + t_thrd.postmaster_cxt.HaShmData->current_mode != NORMAL_MODE)) + +/* if plog is enable */ +#define ENABLE_PLOG() \ + (IsUnderPostmaster && g_instance.attr.attr_common.Logging_collector && \ + u_sess->attr.attr_storage.plog_merge_age > 0 && !SKIPPED_MODE()) + +#define PROFILING_START_TIMER() \ + instr_time __startTime; \ + bool enable_plog = ENABLE_PLOG(); \ + if (enable_plog) { \ + (void)INSTR_TIME_SET_CURRENT(__startTime); \ + } + +#define PROFILING_END_TIMER() \ + instr_time __endTime; \ + instr_time __difTime; \ + (void)INSTR_TIME_SET_CURRENT(__endTime); \ + __difTime = __endTime; \ + INSTR_TIME_SUBTRACT(__difTime, __startTime) + +/* time X > time Y ? */ +#define TM_IS_BIGGER(x, y) (((x).tv_sec == (y).tv_sec) ? ((x).tv_usec > (y).tv_usec) : ((x).tv_sec > (y).tv_sec)) + +/* interface macro about MD(magetic disk) IO monitor */ +#define PROFILING_MDIO_START() PROFILING_START_TIMER() + +#define PROFILING_MDIO_END_READ(__reqsize, __retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_MD; \ + new_item.req_type = DSRQ_READ; \ + if ((__retsize) >= 0) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_MDIO_END_WRITE(__reqsize, __retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_MD; \ + new_item.req_type = DSRQ_WRITE; \ + if ((__retsize) >= 0) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about OBS(Object Storage Service) IO monitor */ +#define PROFILING_OBS_ERROR(__reqsize, __reqtype) \ + do { \ + IndicatorItem new_item; \ + instr_time __nowtime; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = (__reqtype); \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + new_item.req_usec = 0; \ + (void)INSTR_TIME_SET_CURRENT(__nowtime); \ + aggregate_profile_logs(&new_item, &(__nowtime)); \ + } while (0) + +#define PROFILING_OBS_START() PROFILING_START_TIMER() + +#define PROFILING_OBS_END_LIST(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_LIST; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_OBS_END_READ(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_READ; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_OBS_END_WRITE(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_WRITE; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about Hadoop IO monitor */ + +#define PROFILING_HDP_ERROR(__reqsize, __reqtype) \ + do { \ + IndicatorItem new_item; \ + instr_time __nowtime; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = (__reqtype); \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + new_item.req_usec = 0; \ + (void)INSTR_TIME_SET_CURRENT(__nowtime); \ + aggregate_profile_logs(&new_item, &(__nowtime)); \ + } while (0) + +#define PROFILING_HDP_START() PROFILING_START_TIMER() + +#define PROFILING_HDP_END_OPEN(__rettype) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_OPEN; \ + new_item.ret_type = (__rettype); \ + new_item.dat_size = 1; /* only one file */ \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_HDP_END_READ(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_READ; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_HDP_END_WRITE(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_WRITE; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about remote datanode read monitor */ +#define PROFILING_REMOTE_START() PROFILING_START_TIMER() + +#define PROFILING_REMOTE_END_READ(__reqsize, __is_success) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_REMOTE_DATANODE; \ + new_item.req_type = DSRQ_READ; \ + if (__is_success) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__reqsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +extern void init_plog_global_mem(void); + +#endif /* SRC_INCLUDE_UTILS_PLOG_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/plpgsql.h postgresql-hll-2.14/include/include/utils/plpgsql.h --- postgresql-hll-2.14_old/include/include/utils/plpgsql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/plpgsql.h 2020-12-12 17:06:43.292348619 +0800 @@ -0,0 +1,1008 @@ +/*--------------------------------------------------------------------------------------- + * + * plpgsql.h + * Definitions for the PL/pgSQL procedural language + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/plpgsql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PLPGSQL_H +#define PLPGSQL_H + +#include "postgres.h" + +#include "access/xact.h" +#include "catalog/namespace.h" +#include "commands/trigger.h" +#include "executor/spi.h" + +/********************************************************************** + * Definitions + **********************************************************************/ + +/* define our text domain for translations */ +#undef TEXTDOMAIN +#define TEXTDOMAIN PG_TEXTDOMAIN("plpgsql") + +#undef _ +#define _(x) dgettext(TEXTDOMAIN, x) + +/* ---------- + * Compiler's namespace item types + * ---------- + */ +enum { + PLPGSQL_NSTYPE_LABEL, + PLPGSQL_NSTYPE_VAR, + PLPGSQL_NSTYPE_ROW, + PLPGSQL_NSTYPE_REC, + PLPGSQL_NSTYPE_RECORD, + PLPGSQL_NSTYPE_REFCURSOR, + PLPGSQL_NSTYPE_VARRAY +}; + +/* ---------- + * Datum array node types + * ---------- + */ +enum { + PLPGSQL_DTYPE_VAR, + PLPGSQL_DTYPE_ROW, + PLPGSQL_DTYPE_REC, + PLPGSQL_DTYPE_RECORD, + PLPGSQL_DTYPE_RECFIELD, + PLPGSQL_DTYPE_ARRAYELEM, + PLPGSQL_DTYPE_EXPR +}; + +// enums token flag +enum { + PLPGSQL_TOK_REFCURSOR, + PLPGSQL_TOK_VARRAY, + PLPGSQL_TOK_VARRAY_FIRST, + PLPGSQL_TOK_VARRAY_LAST, + PLPGSQL_TOK_VARRAY_COUNT, + PLPGSQL_TOK_VARRAY_EXTEND, + PLPGSQL_TOK_VARRAY_VAR, + PLPGSQL_TOK_RECORD +}; + +/* ---------- + * Variants distinguished in PLpgSQL_type structs + * ---------- + */ +enum { + PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */ + PLPGSQL_TTYPE_ROW, /* composite types */ + PLPGSQL_TTYPE_REC, /* RECORD pseudotype */ + PLPGSQL_TTYPE_RECORD, /* RECORD pseudotype complitable A db */ + PLPGSQL_TTYPE_PSEUDO /* other pseudotypes */ +}; + +/* ---------- + * Execution tree node types + * ---------- + */ +enum PLpgSQL_stmt_types { + PLPGSQL_STMT_BLOCK, + PLPGSQL_STMT_ASSIGN, + PLPGSQL_STMT_IF, + PLPGSQL_STMT_GOTO, + PLPGSQL_STMT_CASE, + PLPGSQL_STMT_LOOP, + PLPGSQL_STMT_WHILE, + PLPGSQL_STMT_FORI, + PLPGSQL_STMT_FORS, + PLPGSQL_STMT_FORC, + PLPGSQL_STMT_FOREACH_A, + PLPGSQL_STMT_EXIT, + PLPGSQL_STMT_RETURN, + PLPGSQL_STMT_RETURN_NEXT, + PLPGSQL_STMT_RETURN_QUERY, + PLPGSQL_STMT_RAISE, + PLPGSQL_STMT_EXECSQL, + PLPGSQL_STMT_DYNEXECUTE, + PLPGSQL_STMT_DYNFORS, + PLPGSQL_STMT_GETDIAG, + PLPGSQL_STMT_OPEN, + PLPGSQL_STMT_FETCH, + PLPGSQL_STMT_CLOSE, + PLPGSQL_STMT_PERFORM, + PLPGSQL_STMT_COMMIT, + PLPGSQL_STMT_ROLLBACK, + PLPGSQL_STMT_NULL +}; + +/* ---------- + * Execution node return codes + * ---------- + */ +enum { PLPGSQL_RC_OK, PLPGSQL_RC_EXIT, PLPGSQL_RC_RETURN, PLPGSQL_RC_CONTINUE, PLPGSQL_RC_GOTO_UNRESOLVED }; + +/* ---------- + * GET DIAGNOSTICS information items + * ---------- + */ +enum { + PLPGSQL_GETDIAG_ROW_COUNT, + PLPGSQL_GETDIAG_RESULT_OID, + PLPGSQL_GETDIAG_ERROR_CONTEXT, + PLPGSQL_GETDIAG_ERROR_DETAIL, + PLPGSQL_GETDIAG_ERROR_HINT, + PLPGSQL_GETDIAG_RETURNED_SQLSTATE, + PLPGSQL_GETDIAG_MESSAGE_TEXT +}; + +/* -------- + * RAISE statement options + * -------- + */ +enum { PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_DETAIL, PLPGSQL_RAISEOPTION_HINT }; + +/* -------- + * Behavioral modes for plpgsql variable resolution + * -------- + */ +typedef enum { + PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */ + PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */ + PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */ +} PLpgSQL_resolve_option; + +/* -------- + * State of cursor found/notfound variable + * -------- + */ +typedef enum { PLPGSQL_TRUE, PLPGSQL_FALSE, PLPGSQL_NULL } PLpgSQL_state; + +/********************************************************************** + * Node and structure definitions + **********************************************************************/ +/* + * PLpgSQL_datum is the common supertype for PLpgSQL_expr, PLpgSQL_var, + * PLpgSQL_row, PLpgSQL_rec, PLpgSQL_recfield, and PLpgSQL_arrayelem + */ +typedef struct PLpgSQL_datum { /* Generic datum array item */ + int dtype; + int dno; +} PLpgSQL_datum; + +/* + * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these + * fields + */ +typedef struct { /* Scalar or composite variable */ + int dtype; + int dno; + char* refname; + int lineno; +} PLpgSQL_variable; + +typedef struct PLpgSQL_expr { /* SQL Query to plan and execute */ + int dtype; + int dno; + char* query; + SPIPlanPtr plan; + Bitmapset* paramnos; /* all dnos referenced by this query */ + + /* function containing this expr (not set until we first parse query) */ + struct PLpgSQL_function* func; + + /* namespace chain visible to this expr */ + struct PLpgSQL_nsitem* ns; + + /* fields for "simple expression" fast-path execution: */ + Expr* expr_simple_expr; /* NULL means not a simple expr */ + int expr_simple_generation; /* plancache generation we checked */ + Oid expr_simple_type; /* result type Oid, if simple */ + bool expr_simple_need_snapshot; /* true means need snapshot */ + + /* + * if expr is simple AND prepared in current transaction, + * expr_simple_state and expr_simple_in_use are valid. Test validity by + * seeing if expr_simple_lxid matches current LXID. (If not, + * expr_simple_state probably points at garbage!) + */ + ExprState* expr_simple_state; /* eval tree for expr_simple_expr */ + bool expr_simple_in_use; /* true if eval tree is active */ + LocalTransactionId expr_simple_lxid; + bool isouttype; /*the parameter will output*/ + uint32 idx; + bool is_cachedplan_shared; +} PLpgSQL_expr; + +typedef struct { /* Postgres data type */ + int dtype; + int dno; + char* typname; /* (simple) name of the type */ + Oid typoid; /* OID of the data type */ + int ttype; /* PLPGSQL_TTYPE_ code */ + int16 typlen; /* stuff copied from its pg_type entry */ + bool typbyval; + Oid typrelid; + Oid typioparam; + Oid collation; /* from pg_type, but can be overridden */ + FmgrInfo typinput; /* lookup info for typinput function */ + int32 atttypmod; /* typmod (taken from someplace else) */ +} PLpgSQL_type; + +typedef struct { /* Scalar variable */ + int dtype; + int dno; + char* refname; + int lineno; + + PLpgSQL_type* datatype; + int isconst; + int notnull; + PLpgSQL_expr* default_val; + PLpgSQL_expr* cursor_explicit_expr; + int cursor_explicit_argrow; + int cursor_options; + + Datum value; + bool isnull; + bool freeval; + bool is_cursor_var; + bool is_cursor_open; +} PLpgSQL_var; + +typedef struct { /* Row variable */ + int dtype; + int dno; + char* refname; + int lineno; + + TupleDesc rowtupdesc; + + /* + * Note: TupleDesc is only set up for named rowtypes, else it is NULL. + * + * Note: if the underlying rowtype contains a dropped column, the + * corresponding fieldnames[] entry will be NULL, and there is no + * corresponding var (varnos[] will be -1). + */ + int nfields; + char** fieldnames; + int* varnos; + int customErrorCode; /* only for exception variable. */ + + int intoplaceholders; /* number of placeholders, for anonymous block in dynamic stmt */ + PLpgSQL_datum** intodatums; +} PLpgSQL_row; + +typedef struct { + char* attrname; + PLpgSQL_type* type; + bool notnull; + PLpgSQL_expr* defaultvalue; +} PLpgSQL_rec_attr; + +typedef struct { + int dtype; + int dno; + char* typname; /* (simple) name of the type */ + Oid typoid; /* OID of the data type */ + int ttype; /* PLPGSQL_TTYPE_ code */ + int16 typlen; /* stuff copied from its pg_type entry */ + bool typbyval; + Oid typrelid; + Oid typioparam; + Oid collation; /* from pg_type, but can be overridden */ + FmgrInfo typinput; /* lookup info for typinput function */ + int32 atttypmod; /* typmod (taken from someplace else) */ + int attrnum; + char** attrnames; + PLpgSQL_type** types; + bool* notnulls; + PLpgSQL_expr** defaultvalues; +} PLpgSQL_rec_type; + +typedef struct { /* Record variable (non-fixed structure) */ + int dtype; + int dno; + char* refname; + int lineno; + + HeapTuple tup; + TupleDesc tupdesc; + bool freetup; + bool freetupdesc; +} PLpgSQL_rec; + +typedef struct { /* Field in record */ + int dtype; + int dno; + char* fieldname; + int recparentno; /* dno of parent record */ +} PLpgSQL_recfield; + +typedef struct { /* Element of array variable */ + int dtype; + int dno; + PLpgSQL_expr* subscript; + int arrayparentno; /* dno of parent array variable */ + /* Remaining fields are cached info about the array variable's type */ + Oid parenttypoid; /* type of array variable; 0 if not yet set */ + int32 parenttypmod; /* typmod of array variable */ + Oid arraytypoid; /* OID of actual array type */ + int32 arraytypmod; /* typmod of array (and its elements too) */ + int16 arraytyplen; /* typlen of array type */ + Oid elemtypoid; /* OID of array element type */ + int16 elemtyplen; /* typlen of element type */ + bool elemtypbyval; /* element type is pass-by-value? */ + char elemtypalign; /* typalign of element type */ +} PLpgSQL_arrayelem; + +typedef struct PLpgSQL_nsitem { /* Item in the compilers namespace tree */ + int itemtype; + int itemno; + struct PLpgSQL_nsitem* prev; + char name[FLEXIBLE_ARRAY_MEMBER]; /* actually, as long as needed */ +} PLpgSQL_nsitem; + +typedef struct { /* Generic execution node */ + int cmd_type; + int lineno; +} PLpgSQL_stmt; + +typedef PLpgSQL_stmt PLpgSQL_stmt_null; + +extern THR_LOCAL List* goto_labels; + +typedef struct { + char* label; + PLpgSQL_stmt* stmt; +} PLpgSQL_gotoLabel; + +typedef struct PLpgSQL_condition { /* One EXCEPTION condition name */ + int sqlerrstate; /* SQLSTATE code */ + char* condname; /* condition name (for debugging) */ + struct PLpgSQL_condition* next; +} PLpgSQL_condition; + +typedef struct { + int sqlstate_varno; + int sqlerrm_varno; + List* exc_list; /* List of WHEN clauses */ +} PLpgSQL_exception_block; + +typedef struct { /* One EXCEPTION ... WHEN clause */ + int lineno; + PLpgSQL_condition* conditions; + List* action; /* List of statements */ +} PLpgSQL_exception; + +typedef struct PLpgSQL_stmt_block { /* Block of statements */ + int cmd_type; + int lineno; + char* label; + List* body; /* List of statements */ + int n_initvars; + int* initvarnos; + PLpgSQL_exception_block* exceptions; +} PLpgSQL_stmt_block; + +typedef struct { /* Assign statement */ + int cmd_type; + int lineno; + int varno; + PLpgSQL_expr* expr; +} PLpgSQL_stmt_assign; + +typedef struct { /* PERFORM statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; +} PLpgSQL_stmt_perform; + +typedef struct { /* Get Diagnostics item */ + int kind; /* id for diagnostic value desired */ + int target; /* where to assign it */ +} PLpgSQL_diag_item; + +typedef struct { /* Get Diagnostics statement */ + int cmd_type; + int lineno; + bool is_stacked; /* STACKED or CURRENT diagnostics area? */ + List* diag_items; /* List of PLpgSQL_diag_item */ +} PLpgSQL_stmt_getdiag; + +typedef struct { /* IF statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* cond; /* boolean expression for THEN */ + List* then_body; /* List of statements */ + List* elsif_list; /* List of PLpgSQL_if_elsif structs */ + List* else_body; /* List of statements */ +} PLpgSQL_stmt_if; + +typedef struct { /* GOTO statement */ + int cmd_type; + int lineno; + char* label; +} PLpgSQL_stmt_goto; + +typedef struct /* one ELSIF arm of IF statement */ +{ + int lineno; + PLpgSQL_expr* cond; /* boolean expression for this case */ + List* stmts; /* List of statements */ +} PLpgSQL_if_elsif; + +typedef struct /* CASE statement */ +{ + int cmd_type; + int lineno; + PLpgSQL_expr* t_expr; /* test expression, or NULL if none */ + int t_varno; /* var to store test expression value into */ + List* case_when_list; /* List of PLpgSQL_case_when structs */ + bool have_else; /* flag needed because list could be empty */ + List* else_stmts; /* List of statements */ +} PLpgSQL_stmt_case; + +typedef struct /* one arm of CASE statement */ +{ + int lineno; + PLpgSQL_expr* expr; /* boolean expression for this case */ + List* stmts; /* List of statements */ +} PLpgSQL_case_when; + +typedef struct { /* Unconditional LOOP statement */ + int cmd_type; + int lineno; + char* label; + List* body; /* List of statements */ +} PLpgSQL_stmt_loop; + +typedef struct { /* WHILE cond LOOP statement */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_expr* cond; + List* body; /* List of statements */ +} PLpgSQL_stmt_while; + +typedef struct { /* FOR statement with integer loopvar */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_var* var; + PLpgSQL_expr* lower; + PLpgSQL_expr* upper; + PLpgSQL_expr* step; /* NULL means default (ie, BY 1) */ + int reverse; + List* body; /* List of statements */ +} PLpgSQL_stmt_fori; + +/* + * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query. + * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc + * and PLpgSQL_dynfors. + */ +typedef struct { + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ +} PLpgSQL_stmt_forq; + +typedef struct { /* FOR statement running over SELECT */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + PLpgSQL_expr* query; +} PLpgSQL_stmt_fors; + +typedef struct { /* FOR statement running over cursor */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + int curvar; + PLpgSQL_expr* argquery; /* cursor arguments if any */ +} PLpgSQL_stmt_forc; + +typedef struct { /* FOR statement running over EXECUTE */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + PLpgSQL_expr* query; + List* params; /* USING expressions */ +} PLpgSQL_stmt_dynfors; + +typedef struct { /* FOREACH item in array loop */ + int cmd_type; + int lineno; + char* label; + int varno; /* loop target variable */ + int slice; /* slice dimension, or 0 */ + PLpgSQL_expr* expr; /* array expression */ + List* body; /* List of statements */ +} PLpgSQL_stmt_foreach_a; + +typedef struct { /* OPEN a curvar */ + int cmd_type; + int lineno; + int curvar; + int cursor_options; + PLpgSQL_row* returntype; + PLpgSQL_expr* argquery; + PLpgSQL_expr* query; + PLpgSQL_expr* dynquery; + List* params; /* USING expressions */ +} PLpgSQL_stmt_open; + +typedef struct { /* FETCH or MOVE statement */ + int cmd_type; + int lineno; + PLpgSQL_rec* rec; /* target, as record or row */ + PLpgSQL_row* row; + int curvar; /* cursor variable to fetch from */ + FetchDirection direction; /* fetch direction */ + long how_many; /* count, if constant (expr is NULL) */ + PLpgSQL_expr* expr; /* count, if expression */ + bool is_move; /* is this a fetch or move? */ + bool returns_multiple_rows; /* can return more than one row? */ +} PLpgSQL_stmt_fetch; + +typedef struct { /* CLOSE curvar */ + int cmd_type; + int lineno; + int curvar; +} PLpgSQL_stmt_close; + +typedef struct { /* EXIT or CONTINUE statement */ + int cmd_type; + int lineno; + bool is_exit; /* Is this an exit or a continue? */ + char* label; /* NULL if it's an unlabelled EXIT/CONTINUE */ + PLpgSQL_expr* cond; +} PLpgSQL_stmt_exit; + +typedef struct { /* RETURN statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; + int retvarno; +} PLpgSQL_stmt_return; + +typedef struct { /* RETURN NEXT statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; + int retvarno; +} PLpgSQL_stmt_return_next; + +typedef struct { /* RETURN QUERY statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* query; /* if static query */ + PLpgSQL_expr* dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */ + List* params; /* USING arguments for dynamic query */ +} PLpgSQL_stmt_return_query; + +typedef struct { /* RAISE statement */ + int cmd_type; + int lineno; + int elog_level; + char* condname; /* condition name, SQLSTATE, or NULL */ + char* message; /* old-style message format literal, or NULL */ + List* params; /* list of expressions for old-style message */ + List* options; /* list of PLpgSQL_raise_option */ +} PLpgSQL_stmt_raise; + +typedef struct { /* RAISE statement option */ + int opt_type; + PLpgSQL_expr* expr; +} PLpgSQL_raise_option; + +typedef struct { /* Generic SQL statement to execute */ + int cmd_type; + int lineno; + PLpgSQL_expr* sqlstmt; + bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE? */ + /* note: mod_stmt is set when we plan the query */ + bool into; /* INTO supplied? */ + bool strict; /* INTO STRICT flag */ + PLpgSQL_rec* rec; /* INTO target, if record */ + PLpgSQL_row* row; /* INTO target, if row */ + // A db function invoke feature + int placeholders; + bool multi_func; +} PLpgSQL_stmt_execsql; + +// Added USING IN/OUT/IN OUT for plpgsql +typedef struct { /* Dynamic SQL string to execute */ + int cmd_type; + int lineno; + PLpgSQL_expr* query; /* string expression */ + bool into; /* INTO supplied? */ + bool strict; /* INTO STRICT flag */ + PLpgSQL_rec* rec; /* INTO target, if record */ + union { + PLpgSQL_row* row; /* INTO target, if row */ + PLpgSQL_row* out_row; /* USING output */ + }; + List* params; /* USING expressions */ + bool isinouttype; /* IN OUT parameters, differ from INTO statment */ + bool isanonymousblock; /* check if it is anonymous block */ + void* ppd; /* IN or IN OUT parameters */ +} PLpgSQL_stmt_dynexecute; + +typedef struct PLpgSQL_func_hashkey { /* Hash lookup key for functions */ + Oid funcOid; + + bool isTrigger; /* true if called as a trigger */ + + /* be careful that pad bytes in this struct get zeroed! */ + + /* + * For a trigger function, the OID of the relation triggered on is part of + * the hash key --- we want to compile the trigger separately for each + * relation it is used with, in case the rowtype is different. Zero if + * not called as a trigger. + */ + Oid trigrelOid; + + /* + * We must include the input collation as part of the hash key too, + * because we have to generate different plans (with different Param + * collations) for different collation settings. + */ + Oid inputCollation; + + /* + * We include actual argument types in the hash key to support polymorphic + * PLpgSQL functions. Be careful that extra positions are zeroed! + */ + Oid argtypes[FUNC_MAX_ARGS]; +} PLpgSQL_func_hashkey; + +typedef struct PLpgSQL_function { /* Complete compiled function */ + char* fn_signature; + Oid fn_oid; + OverrideSearchPath* fn_searchpath; + Oid fn_owner; + TransactionId fn_xmin; + ItemPointerData fn_tid; + bool fn_is_trigger; + Oid fn_input_collation; + PLpgSQL_func_hashkey* fn_hashkey; /* back-link to hashtable key */ + MemoryContext fn_cxt; + + Oid fn_rettype; + int fn_rettyplen; + bool fn_retbyval; + FmgrInfo fn_retinput; + Oid fn_rettypioparam; + bool fn_retistuple; + bool fn_retset; + bool fn_readonly; + + int fn_nargs; + int fn_argvarnos[FUNC_MAX_ARGS]; + int out_param_varno; + int found_varno; + + // magic variables' varno for implicit cursor attributes + int sql_cursor_found_varno; + int sql_notfound_varno; + int sql_isopen_varno; + int sql_rowcount_varno; + + // the magic sqlcode no + int sqlcode_varno; + int new_varno; + int old_varno; + int tg_name_varno; + int tg_when_varno; + int tg_level_varno; + int tg_op_varno; + int tg_relid_varno; + int tg_relname_varno; + int tg_table_name_varno; + int tg_table_schema_varno; + int tg_nargs_varno; + int tg_argv_varno; + + PLpgSQL_resolve_option resolve_option; + + int ndatums; + PLpgSQL_datum** datums; + PLpgSQL_stmt_block* action; + List* goto_labels; + + /* these fields change when the function is used */ + struct PLpgSQL_execstate* cur_estate; + unsigned long use_count; + + /* these fields are used during trigger pre-parsing */ + bool pre_parse_trig; + Relation tg_relation; +} PLpgSQL_function; + +typedef struct PLpgSQL_execstate { /* Runtime execution data */ + PLpgSQL_function* func; /* function being executed */ + + Datum retval; + bool retisnull; + Oid rettype; /* type of current retval */ + + Oid fn_rettype; /* info about declared function rettype */ + bool retistuple; + bool retisset; + + bool readonly_func; + + TupleDesc rettupdesc; + char* exitlabel; /* the "target" label of the current EXIT or + * CONTINUE stmt, if any */ + ErrorData* cur_error; /* current exception handler's error */ + + Tuplestorestate* tuple_store; /* SRFs accumulate results here */ + MemoryContext tuple_store_cxt; + ResourceOwner tuple_store_owner; + ReturnSetInfo* rsi; + + int found_varno; + + /* + * The execute state variable estate->rowcount keeps + * the current rowcount while executing store procedure + */ + int32 rowcount; + + /* magic variables' varno for implicit cursor attributes */ + int sql_cursor_found_varno; + int sql_notfound_varno; + int sql_isopen_varno; + int sql_rowcount_varno; + int sqlcode_varno; + int ndatums; + PLpgSQL_datum** datums; + + /* temporary state for results from evaluation of query or expr */ + SPITupleTable* eval_tuptable; + uint32 eval_processed; + Oid eval_lastoid; + ExprContext* eval_econtext; /* for executing simple expressions */ + PLpgSQL_expr* cur_expr; /* current query/expr being evaluated */ + + /* status information for error context reporting */ + PLpgSQL_stmt* err_stmt; /* current stmt */ + const char* err_text; /* additional state info */ + + void* plugin_info; /* reserved for use by optional plugin */ + + /* support GOTO */ + List* goto_labels; + char* goto_target_label; + PLpgSQL_stmt* goto_target_stmt; /* current GOTO */ + int block_level; /* block level, 0 for topmost */ + Cursor_Data* cursor_return_data; +} PLpgSQL_execstate; + +/* + * A PLpgSQL_plugin structure represents an instrumentation plugin. + * To instrument PL/pgSQL, a plugin library must access the rendezvous + * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct. + * Typically the struct could just be static data in the plugin library. + * We expect that a plugin would do this at library load time (_PG_init()). + * It must also be careful to set the rendezvous variable back to NULL + * if it is unloaded (_PG_fini()). + * + * This structure is basically a collection of function pointers --- at + * various interesting points in pl_exec.c, we call these functions + * (if the pointers are non-NULL) to give the plugin a chance to watch + * what we are doing. + * + * func_setup is called when we start a function, before we've initialized + * the local variables defined by the function. + * + * func_beg is called when we start a function, after we've initialized + * the local variables. + * + * func_end is called at the end of a function. + * + * stmt_beg and stmt_end are called before and after (respectively) each + * statement. + * + * Also, immediately before any call to func_setup, PL/pgSQL fills in the + * error_callback and assign_expr fields with pointers to its own + * plpgsql_exec_error_callback and exec_assign_expr functions. This is + * a somewhat ad-hoc expedient to simplify life for debugger plugins. + */ + +typedef struct PLpgSQL_plugin { + /* Function pointers set up by the plugin */ + void (*func_setup)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*func_beg)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*func_end)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*stmt_beg)(PLpgSQL_execstate* estate, PLpgSQL_stmt* stmt); + void (*stmt_end)(PLpgSQL_execstate* estate, PLpgSQL_stmt* stmt); + + /* Function pointers set by PL/pgSQL itself */ + void (*error_callback)(void* arg); + void (*assign_expr)(PLpgSQL_execstate* estate, PLpgSQL_datum* target, PLpgSQL_expr* expr); + Datum (*eval_expr)(PLpgSQL_execstate* estate, PLpgSQL_expr* expr, bool* isNull, Oid* rettype); + void (*assign_value)(PLpgSQL_execstate* estate, PLpgSQL_datum* target, Datum value, Oid valtype, bool* isNull); + void (*eval_cleanup)(PLpgSQL_execstate* estate); + int (*validate_line)(PLpgSQL_stmt_block* block, int linenum); +} PLpgSQL_plugin; + +/* Struct types used during parsing */ + +typedef struct { + char* ident; /* palloc'd converted identifier */ + bool quoted; /* Was it double-quoted? */ +} PLword; + +typedef struct { + List* idents; /* composite identifiers (list of String) */ +} PLcword; + +typedef struct { + PLpgSQL_datum* datum; /* referenced variable */ + char* ident; /* valid if simple name */ + bool quoted; + List* idents; /* valid if composite name */ +} PLwdatum; + +/********************************************************************** + * Function declarations + **********************************************************************/ + +/* ---------- + * Functions in pl_comp.c + * ---------- + */ + +typedef struct plpgsql_hashent { + PLpgSQL_func_hashkey key; + PLpgSQL_function* function; + DListCell* cell; /* Dlist cell for delete function compile results. */ +} plpgsql_HashEnt; + +extern PLpgSQL_function* plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator); +extern PLpgSQL_function* plpgsql_compile_nohashkey(FunctionCallInfo fcinfo); /* parse trigger func */ +extern PLpgSQL_function* plpgsql_compile_inline(char* proc_source); +extern void plpgsql_parser_setup(struct ParseState* pstate, PLpgSQL_expr* expr); +extern bool plpgsql_parse_word(char* word1, const char* yytxt, PLwdatum* wdatum, PLword* word, int* tok_flag); +extern bool plpgsql_parse_dblword(char* word1, char* word2, PLwdatum* wdatum, PLcword* cword, int* nsflag); +extern bool plpgsql_parse_tripword(char* word1, char* word2, char* word3, PLwdatum* wdatum, PLcword* cword); +extern PLpgSQL_type* plpgsql_parse_wordtype(char* ident); +extern PLpgSQL_type* plpgsql_parse_cwordtype(List* idents); +extern PLpgSQL_type* plpgsql_parse_wordrowtype(char* ident); +extern PLpgSQL_type* plpgsql_parse_cwordrowtype(List* idents); +extern PLpgSQL_type* plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation); +extern PLpgSQL_variable* plpgsql_build_variable( + const char* refname, int lineno, PLpgSQL_type* dtype, bool add2namespace, const char* varname = NULL); +PLpgSQL_variable* plpgsql_build_varrayType(const char* refname, int lineno, PLpgSQL_type* dtype, bool add2namespace); +extern PLpgSQL_rec_type* plpgsql_build_rec_type(const char* typname, int lineno, List* list, bool add2namespace); +extern PLpgSQL_rec* plpgsql_build_record(const char* refname, int lineno, bool add2namespace); +extern int plpgsql_recognize_err_condition(const char* condname, bool allow_sqlstate); +extern PLpgSQL_condition* plpgsql_parse_err_condition(char* condname); +extern void plpgsql_adddatum(PLpgSQL_datum* newm); +extern int plpgsql_add_initdatums(int** varnos); +extern void plpgsql_HashTableInit(void); +extern PLpgSQL_row* build_row_from_rec_type(const char* rowname, int lineno, PLpgSQL_rec_type* type); +extern bool plpgsql_check_colocate(Query* query, RangeTblEntry* rte, void* plpgsql_func); +extern void plpgsql_HashTableDeleteAll(); +extern void plpgsql_HashTableDeleteFunc(Oid func_oid); +extern void plpgsql_HashTableDelete(PLpgSQL_function* func); + +/* ---------- + * Functions in pl_handler.c + * ---------- + */ +extern "C" void _PG_init(void); +extern "C" Datum plpgsql_call_handler(PG_FUNCTION_ARGS); +extern "C" Datum plpgsql_inline_handler(PG_FUNCTION_ARGS); +extern "C" Datum plpgsql_validator(PG_FUNCTION_ARGS); + +/* --- --- --- + * Functions in plsql_packages.c + * --- --- + */ +extern "C" { +Datum regexp_substr(PG_FUNCTION_ARGS); +Datum intervaltonum(PG_FUNCTION_ARGS); +Datum rawtohex(PG_FUNCTION_ARGS); +Datum report_application_error(PG_FUNCTION_ARGS); +} + +extern THR_LOCAL PLpgSQL_execstate* plpgsql_estate; + +/* ---------- + * Functions in pl_exec.c + * ---------- + */ +extern Datum plpgsql_exec_function(PLpgSQL_function* func, FunctionCallInfo fcinfo, bool dynexec_anonymous_block); +extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function* func, TriggerData* trigdata); +extern void plpgsql_xact_cb(XactEvent event, void* arg); +extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void* arg); +extern Oid exec_get_datum_type(PLpgSQL_execstate* estate, PLpgSQL_datum* datum); +extern void exec_get_datum_type_info(PLpgSQL_execstate* estate, PLpgSQL_datum* datum, Oid* typid, int32* typmod, + Oid* collation, PLpgSQL_function* func = NULL); +extern Datum exec_simple_cast_datum( + PLpgSQL_execstate* estate, Datum value, Oid valtype, Oid reqtype, int32 reqtypmod, bool isnull); +extern void ResetCursorOption(Portal portal, bool reset); +extern void exec_assign_value(PLpgSQL_execstate *estate, + PLpgSQL_datum *target, + Datum value, Oid valtype, bool *isNull); +extern void exec_eval_datum(PLpgSQL_execstate *estate, + PLpgSQL_datum *datum, + Oid *typeId, + int32 *typetypmod, + Datum *value, + bool *isnull, + bool isretry); +extern void exec_eval_cleanup(PLpgSQL_execstate *estate); +/* ---------- + * Functions for namespace handling in pl_funcs.c + * ---------- + */ +extern void plpgsql_ns_init(void); +extern void plpgsql_ns_push(const char* label); +extern void plpgsql_ns_pop(void); +extern PLpgSQL_nsitem* plpgsql_ns_top(void); +extern void plpgsql_ns_additem(int itemtype, int itemno, const char* name); +extern PLpgSQL_nsitem* plpgsql_ns_lookup( + PLpgSQL_nsitem* ns_cur, bool localmode, const char* name1, const char* name2, const char* name3, int* names_used); +extern PLpgSQL_nsitem* plpgsql_ns_lookup_label(PLpgSQL_nsitem* ns_cur, const char* name); + +/* ---------- + * Other functions in pl_funcs.c + * ---------- + */ +extern const char* plpgsql_stmt_typename(PLpgSQL_stmt* stmt); +extern const char* plpgsql_getdiag_kindname(int kind); +extern void plpgsql_free_function_memory(PLpgSQL_function* func); +extern void plpgsql_dumptree(PLpgSQL_function* func); +extern bool plpgsql_is_trigger_shippable(PLpgSQL_function* func); + +/* ---------- + * Scanner functions in pl_scanner.c + * ---------- + */ +extern int plpgsql_base_yylex(void); +extern int plpgsql_yylex(void); +extern void plpgsql_push_back_token(int token); +extern void plpgsql_append_source_text(StringInfo buf, int startlocation, int endlocation); +extern void plpgsql_peek2(int* tok1_p, int* tok2_p, int* tok1_loc, int* tok2_loc); +extern int plpgsql_scanner_errposition(int location); +extern void plpgsql_yyerror(const char* message); +extern int plpgsql_location_to_lineno(int location); +extern int plpgsql_latest_lineno(void); +extern void plpgsql_scanner_init(const char* str); +extern void plpgsql_scanner_finish(void); + +/* ---------- + * Externs in gram.y + * ---------- + */ +extern int plpgsql_yyparse(void); +extern bool plpgsql_is_token_match2(int token, int token_next); +extern bool plpgsql_is_token_match(int token); + +#endif /* PLPGSQL_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/portal.h postgresql-hll-2.14/include/include/utils/portal.h --- postgresql-hll-2.14_old/include/include/utils/portal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/portal.h 2020-12-12 17:06:43.292348619 +0800 @@ -0,0 +1,236 @@ +/* ------------------------------------------------------------------------- + * + * portal.h + * POSTGRES portal definitions. + * + * A portal is an abstraction which represents the execution state of + * a running or runnable query. Portals support both SQL-level CURSORs + * and protocol-level portals. + * + * Scrolling (nonsequential access) and suspension of execution are allowed + * only for portals that contain a single SELECT-type query. We do not want + * to let the client suspend an update-type query partway through! Because + * the query rewriter does not allow arbitrary ON SELECT rewrite rules, + * only queries that were originally update-type could produce multiple + * plan trees; so the restriction to a single query is not a problem + * in practice. + * + * For SQL cursors, we support three kinds of scroll behavior: + * + * (1) Neither NO SCROLL nor SCROLL was specified: to remain backward + * compatible, we allow backward fetches here, unless it would + * impose additional runtime overhead to do so. + * + * (2) NO SCROLL was specified: don't allow any backward fetches. + * + * (3) SCROLL was specified: allow all kinds of backward fetches, even + * if we need to take a performance hit to do so. (The planner sticks + * a Materialize node atop the query plan if needed.) + * + * Case #1 is converted to #2 or #3 by looking at the query itself and + * determining if scrollability can be supported without additional + * overhead. + * + * Protocol-level portals have no nonsequential-fetch API and so the + * distinction doesn't matter for them. They are always initialized + * to look like NO SCROLL cursors. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/portal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PORTAL_H +#define PORTAL_H + +#include "datatype/timestamp.h" +#include "executor/execdesc.h" +#include "utils/resowner.h" + +/* + * We have several execution strategies for Portals, depending on what + * query or queries are to be executed. (Note: in all cases, a Portal + * executes just a single source-SQL query, and thus produces just a + * single result from the user's viewpoint. However, the rule rewriter + * may expand the single source query to zero or many actual queries.) + * + * PORTAL_ONE_SELECT: the portal contains one single SELECT query. We run + * the Executor incrementally as results are demanded. This strategy also + * supports holdable cursors (the Executor results can be dumped into a + * tuplestore for access after transaction completion). + * + * PORTAL_ONE_RETURNING: the portal contains a single INSERT/UPDATE/DELETE + * query with a RETURNING clause (plus possibly auxiliary queries added by + * rule rewriting). On first execution, we run the portal to completion + * and dump the primary query's results into the portal tuplestore; the + * results are then returned to the client as demanded. (We can't support + * suspension of the query partway through, because the AFTER TRIGGER code + * can't cope, and also because we don't want to risk failing to execute + * all the auxiliary queries.) + * + * PORTAL_ONE_MOD_WITH: the portal contains one single SELECT query, but + * it has data-modifying CTEs. This is currently treated the same as the + * PORTAL_ONE_RETURNING case because of the possibility of needing to fire + * triggers. It may act more like PORTAL_ONE_SELECT in future. + * + * PORTAL_UTIL_SELECT: the portal contains a utility statement that returns + * a SELECT-like result (for example, EXPLAIN or SHOW). On first execution, + * we run the statement and dump its results into the portal tuplestore; + * the results are then returned to the client as demanded. + * + * PORTAL_MULTI_QUERY: all other cases. Here, we do not support partial + * execution: the portal's queries will be run to completion on first call. + */ + +/* the four attributes are defined in params.h: CURSOR_ISOPEN, CURSOR_FOUND, CURSOR_NOTFOUND, CURSOR_ROWCOUNT */ +#define CURSOR_ATTRIBUTE_NUMBER 4 + +typedef enum PortalStrategy { + PORTAL_ONE_SELECT, + PORTAL_ONE_RETURNING, + PORTAL_ONE_MOD_WITH, + PORTAL_UTIL_SELECT, + PORTAL_MULTI_QUERY +} PortalStrategy; + +/* + * A portal is always in one of these states. It is possible to transit + * from ACTIVE back to READY if the query is not run to completion; + * otherwise we never back up in status. + */ +typedef enum PortalStatus { + PORTAL_NEW, /* freshly created */ + PORTAL_DEFINED, /* PortalDefineQuery done */ + PORTAL_READY, /* PortalStart complete, can run it */ + PORTAL_ACTIVE, /* portal is running (can't delete it) */ + PORTAL_DONE, /* portal is finished (don't re-run it) */ + PORTAL_FAILED /* portal got error (can't re-run it) */ +} PortalStatus; + +typedef struct PortalData* Portal; + +typedef struct PortalData { + /* Bookkeeping data */ + const char* name; /* portal's name */ + const char* prepStmtName; /* source prepared statement (NULL if none) */ + MemoryContext heap; /* subsidiary memory for portal */ + ResourceOwner resowner; /* resources owned by portal */ + void (*cleanup)(Portal portal); /* cleanup hook */ + + /* + * State data for remembering which subtransaction(s) the portal was + * created or used in. If the portal is held over from a previous + * transaction, both subxids are InvalidSubTransactionId. Otherwise, + * createSubid is the creating subxact and activeSubid is the last subxact + * in which we ran the portal. + */ + SubTransactionId createSubid; /* the creating subxact */ + SubTransactionId activeSubid; /* the last subxact with activity */ + + /* The query or queries the portal will execute */ + const char* sourceText; /* text of query (as of 8.4, never NULL) */ + const char* commandTag; /* command tag for original query */ + List* stmts; /* PlannedStmts and/or utility statements */ + CachedPlan* cplan; /* CachedPlan, if stmts are from one */ + + ParamListInfo portalParams; /* params to pass to query */ + + /* Features/options */ + PortalStrategy strategy; /* see above */ + int cursorOptions; /* DECLARE CURSOR option bits */ + + /* Status data */ + PortalStatus status; /* see above */ + bool portalPinned; /* a pinned portal can't be dropped */ + bool autoHeld; /* was automatically converted from pinned to + * held (see HoldPinnedPortals()) */ + + /* If not NULL, Executor is active; call ExecutorEnd eventually: */ + QueryDesc* queryDesc; /* info needed for executor invocation */ + + TableScanDesc scanDesc; // info needed for reducing memory allocation + // when reusing the portal for too many times + //(e.g., FETCH/MOVE cursor in a loop) + + /* If portal returns tuples, this is their tupdesc: */ + TupleDesc tupDesc; /* descriptor for result tuples */ + /* and these are the format codes to use for the columns: */ + int16* formats; /* a format code for each column */ + + /* + * Where we store tuples for a held cursor or a PORTAL_ONE_RETURNING or + * PORTAL_UTIL_SELECT query. (A cursor held past the end of its + * transaction no longer has any active executor state.) + */ + Tuplestorestate* holdStore; /* store for holdable cursors */ + MemoryContext holdContext; /* memory containing holdStore */ + + /* + * atStart, atEnd and portalPos indicate the current cursor position. + * portalPos is zero before the first row, N after fetching N'th row of + * query. After we run off the end, portalPos = # of rows in query, and + * atEnd is true. If portalPos overflows, set posOverflow (this causes us + * to stop relying on its value for navigation). Note that atStart + * implies portalPos == 0, but not the reverse (portalPos could have + * overflowed). + */ + bool atStart; + bool atEnd; + bool posOverflow; + long portalPos; + + /* Presentation data, primarily used by the pg_cursors system view */ + TimestampTz creation_time; /* time at which this portal was defined */ + bool visible; /* include this portal in pg_cursors? */ + /* Data used by workload manager. */ + int stmtMemCost; /* Estimate of memory usage from the plan */ + void* cursorAttribute[CURSOR_ATTRIBUTE_NUMBER]; + Oid funcOid; /* function oid */ + int funcUseCount; + bool is_from_spi; +} PortalData; + +/* + * PortalIsValid + * True iff portal is valid. + */ +#define PortalIsValid(p) PointerIsValid(p) + +/* + * Access macros for Portal ... use these in preference to field access. + */ +#define PortalGetQueryDesc(portal) ((portal)->queryDesc) +#define PortalGetHeapMemory(portal) ((portal)->heap) +#define PortalGetPrimaryStmt(portal) PortalListGetPrimaryStmt((portal)->stmts) + +/* Prototypes for functions in utils/mmgr/portalmem.c */ +extern void EnablePortalManager(void); +extern bool PreCommit_Portals(bool isPrepare = true, bool STP_commit = false); +extern void AtAbort_Portals(bool STP_rollback = false); +extern void AtCleanup_Portals(void); +extern void PortalErrorCleanup(void); +extern void AtSubCommit_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner parentXactOwner); +extern void AtSubAbort_Portals( + SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner); +extern void AtSubCleanup_Portals(SubTransactionId mySubid); +extern Portal CreatePortal(const char* name, bool allowDup, bool dupSilent, bool is_from_spi = false); +extern Portal CreateNewPortal(bool is_from_spi = false); +extern void PinPortal(Portal portal); +extern void UnpinPortal(Portal portal); +extern void MarkPortalActive(Portal portal); +extern void MarkPortalDone(Portal portal); +extern void MarkPortalFailed(Portal portal); +extern void PortalDrop(Portal portal, bool isTopCommit); +extern Portal GetPortalByName(const char* name); +extern void PortalDefineQuery(Portal portal, const char* prepStmtName, const char* sourceText, const char* commandTag, + List* stmts, CachedPlan* cplan); +extern Node* PortalListGetPrimaryStmt(List* stmts); +extern void PortalCreateHoldStore(Portal portal); +extern void PortalHashTableDeleteAll(void); +extern bool ThereAreNoReadyPortals(void); +extern void ResetPortalCursor(SubTransactionId mySubid, Oid funOid, int funUseCount); +extern void HoldPinnedPortals(void); +#endif /* PORTAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/postinit.h postgresql-hll-2.14/include/include/utils/postinit.h --- postgresql-hll-2.14_old/include/include/utils/postinit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/postinit.h 2020-12-12 17:06:43.292348619 +0800 @@ -0,0 +1,179 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * postinit.h + * init postgres thread. + * + * + * IDENTIFICATION + * src/include/utils/postinit.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef UTILS_POSTINIT_H +#define UTILS_POSTINIT_H + +#define PGAUDIT_MAXLENGTH 1024 + +/* -------------------------------- + * POSTGRES Initialize POSTGRES. + * + * The database can be specified by name, using the in_dbname parameter, or by + * OID, using the dboid parameter. In the latter case, the actual database + * name can be returned to the caller in out_dbname. If out_dbname isn't + * NULL, it must point to a buffer of size NAMEDATALEN. + * + * In bootstrap mode no parameters are used. The autovacuum launcher process + * doesn't use any parameters either, because it only goes far enough to be + * able to read pg_database; it doesn't connect to any particular database. + * In walsender mode only username is used. + * + * We expect InitProcess() was already called, so we already have a PGPROC struct ... + * but it's not completely filled in yet. + * + * Note: + * Be very careful with the order of calls in the InitPostgres function. + * -------------------------------- + */ + +class PostgresInitializer : public BaseObject { +public: + PostgresInitializer(); + + ~PostgresInitializer(); + + void SetDatabaseAndUser(const char* in_dbname, Oid dboid, const char* username); + + void GetDatabaseName(char* out_dbname); + + void InitBootstrap(); + + void InitJobScheduler(); + + void InitJobExecuteWorker(); + + void InitSnapshotWorker(); + + void InitAspWorker(); + + void InitStatementWorker(); + + void InitPercentileWorker(); + + void InitAutoVacLauncher(); + + void InitAutoVacWorker(); + + void InitCsnminSync(); + + void InitCatchupWorker(); + + void InitStreamWorker(); + + void InitBackendWorker(); + + void InitWLM(); + + void InitWAL(); + + void InitSession(); + + void InitStreamingBackend(); + + void InitCompactionWorker(); + + void InitCompactionWorkerSwitchSession(); + + void InitStreamSession(); + +public: + const char* m_indbname; + + Oid m_dboid; + + const char* m_username; + +private: + void InitThread(); + + void InitSysCache(); + + void SetProcessExitCallback(); + + void StartXact(); + + void CheckAuthentication(); + + void SetSuperUserStandalone(); + + void SetSuperUserAndDatabase(); + + void CheckAtLeastOneRoles(); + + void InitUser(); + + void CheckConnPermission(); + + void CheckConnPermissionInShutDown(); + + void CheckConnPermissionInBinaryUpgrade(); + + void CheckConnLimitation(); + + void InitPlainWalSender(); + + void SetDefaultDatabase(); + + void SetDatabase(); + + void SetDatabaseByName(); + + void SetDatabaseByOid(); + + void LockDatabase(); + + void RecheckDatabaseExists(); + + void SetDatabasePath(); + + void LoadSysCache(); + + void ProcessStartupOpt(); + + void InitDatabase(); + + void InitPGXCPort(); + + void InitSettings(); + + void FinishInit(); + + void AuditUserLogin(); + + void InitCompactionThread(); + +private: + bool m_isSuperUser; + + char m_dbname[NAMEDATALEN]; + + char m_details[PGAUDIT_MAXLENGTH]; + + char* m_fullpath; +}; + +void ShutdownPostgres(int code, Datum arg); + +#endif /* UTILS_POSTINIT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/probes.h postgresql-hll-2.14/include/include/utils/probes.h --- postgresql-hll-2.14_old/include/include/utils/probes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/probes.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,118 @@ +#define TRACE_POSTGRESQL_TRANSACTION_START(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_START_ENABLED() (0) +#define TRACE_POSTGRESQL_TRANSACTION_COMMIT(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_COMMIT_ENABLED() (0) +#define TRACE_POSTGRESQL_TRANSACTION_ABORT(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_ABORT_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_ACQUIRE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_RELEASE(INT1) +#define TRACE_POSTGRESQL_LWLOCK_RELEASE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_START(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_FAIL(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_FAIL_ENABLED() (0) +#define TRACE_POSTGRESQL_LOCK_WAIT_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_LOCK_WAIT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_LOCK_WAIT_DONE(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_LOCK_WAIT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PARSE_START(INT1) +#define TRACE_POSTGRESQL_QUERY_PARSE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PARSE_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_PARSE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_REWRITE_START(INT1) +#define TRACE_POSTGRESQL_QUERY_REWRITE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_REWRITE_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_REWRITE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PLAN_START() +#define TRACE_POSTGRESQL_QUERY_PLAN_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PLAN_DONE() +#define TRACE_POSTGRESQL_QUERY_PLAN_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_EXECUTE_START() +#define TRACE_POSTGRESQL_QUERY_EXECUTE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_EXECUTE_DONE() +#define TRACE_POSTGRESQL_QUERY_EXECUTE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_START(INT1) +#define TRACE_POSTGRESQL_QUERY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_STATEMENT_STATUS(INT1) +#define TRACE_POSTGRESQL_STATEMENT_STATUS_ENABLED() (0) +#define TRACE_POSTGRESQL_SORT_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_SORT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SORT_DONE(INT1, INT2) +#define TRACE_POSTGRESQL_SORT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_READ_START(INT1, INT2, INT3, INT4, INT5, INT6, INT7) +#define TRACE_POSTGRESQL_BUFFER_READ_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_READ_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_BUFFER_READ_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_SYNC_START() +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_SYNC_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_DONE() +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_START(INT1, INT2) +#define TRACE_POSTGRESQL_BUFFER_SYNC_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN(INT1) +#define TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_DONE(INT1, INT2, INT3) +#define TRACE_POSTGRESQL_BUFFER_SYNC_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_DEADLOCK_FOUND() +#define TRACE_POSTGRESQL_DEADLOCK_FOUND_ENABLED() (0) +#define TRACE_POSTGRESQL_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CHECKPOINT_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_START() +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_DONE() +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_READ_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_SMGR_MD_READ_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_READ_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_SMGR_MD_READ_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_XLOG_INSERT(INT1, INT2) +#define TRACE_POSTGRESQL_XLOG_INSERT_ENABLED() (0) +#define TRACE_POSTGRESQL_XLOG_SWITCH() +#define TRACE_POSTGRESQL_XLOG_SWITCH_ENABLED() (0) +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_START() +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_DONE() +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_DONE_ENABLED() (0) diff -uprN postgresql-hll-2.14_old/include/include/utils/ps_status.h postgresql-hll-2.14/include/include/utils/ps_status.h --- postgresql-hll-2.14_old/include/include/utils/ps_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/ps_status.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * ps_status.h + * + * Declarations for backend/utils/misc/ps_status.c + * + * src/include/utils/ps_status.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PS_STATUS_H +#define PS_STATUS_H + +extern char** save_ps_display_args(int argc, char** argv); + +extern void init_ps_display(const char* username, const char* dbname, const char* host_info, const char* initial_str); + +extern void set_ps_display(const char* activity, bool force); + +extern const char* get_ps_display(int* displen); + +#endif /* PS_STATUS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/rangetypes.h postgresql-hll-2.14/include/include/utils/rangetypes.h --- postgresql-hll-2.14_old/include/include/utils/rangetypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/rangetypes.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,177 @@ +/* ------------------------------------------------------------------------- + * + * rangetypes.h + * Declarations for Postgres range types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/rangetypes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RANGETYPES_H +#define RANGETYPES_H + +#include "utils/typcache.h" + +/* + * Ranges are varlena objects, so must meet the varlena convention that + * the first int32 of the object contains the total object size in bytes. + * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though! + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + Oid rangetypid; /* range type's own OID */ + /* Following the OID are zero to two bound values, then a flags byte */ +} RangeType; + +/* Use this macro in preference to fetching rangetypid field directly */ +#define RangeTypeGetOid(r) ((r)->rangetypid) + +/* A range's flags byte contains these bits: */ +#define RANGE_EMPTY 0x01 /* range is empty */ +#define RANGE_LB_INC 0x02 /* lower bound is inclusive */ +#define RANGE_UB_INC 0x04 /* upper bound is inclusive */ +#define RANGE_LB_INF 0x08 /* lower bound is -infinity */ +#define RANGE_UB_INF 0x10 /* upper bound is +infinity */ +#define RANGE_LB_NULL 0x20 /* lower bound is null (NOT USED) */ +#define RANGE_UB_NULL 0x40 /* upper bound is null (NOT USED) */ +#define RANGE_CONTAIN_EMPTY \ + 0x80 /* marks a GiST internal-page entry whose \ + * subtree contains some empty ranges */ + +#define RANGE_HAS_LBOUND(flags) (!((flags) & (RANGE_EMPTY | RANGE_LB_NULL | RANGE_LB_INF))) + +#define RANGE_HAS_UBOUND(flags) (!((flags) & (RANGE_EMPTY | RANGE_UB_NULL | RANGE_UB_INF))) + +#define RangeIsEmpty(r) (((unsigned int)range_get_flags(r) & RANGE_EMPTY) != 0) +#define RangeIsOrContainsEmpty(r) (((unsigned int)range_get_flags(r) & (RANGE_EMPTY | RANGE_CONTAIN_EMPTY)) != 0) + +/* Internal representation of either bound of a range (not what's on disk) */ +typedef struct { + Datum val; /* the bound value, if any */ + bool infinite; /* bound is +/- infinity */ + bool inclusive; /* bound is inclusive (vs exclusive) */ + bool lower; /* this is the lower (vs upper) bound */ +} RangeBound; + +/* + * fmgr macros for range type objects + */ +#define DatumGetRangeType(X) ((RangeType*)PG_DETOAST_DATUM(X)) +#define DatumGetRangeTypeCopy(X) ((RangeType*)PG_DETOAST_DATUM_COPY(X)) +#define RangeTypeGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_RANGE(n) DatumGetRangeType(PG_GETARG_DATUM(n)) +#define PG_GETARG_RANGE_COPY(n) DatumGetRangeTypeCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_RANGE(x) return RangeTypeGetDatum(x) + +/* + * prototypes for functions defined in rangetypes.c + */ + +/* I/O */ +extern Datum range_in(PG_FUNCTION_ARGS); +extern Datum range_out(PG_FUNCTION_ARGS); +extern Datum range_recv(PG_FUNCTION_ARGS); +extern Datum range_send(PG_FUNCTION_ARGS); + +/* constructors */ +extern Datum range_constructor2(PG_FUNCTION_ARGS); +extern Datum range_constructor3(PG_FUNCTION_ARGS); + +/* range -> subtype */ +extern Datum range_lower(PG_FUNCTION_ARGS); +extern Datum range_upper(PG_FUNCTION_ARGS); + +/* range -> bool */ +extern Datum range_empty(PG_FUNCTION_ARGS); +extern Datum range_lower_inc(PG_FUNCTION_ARGS); +extern Datum range_upper_inc(PG_FUNCTION_ARGS); +extern Datum range_lower_inf(PG_FUNCTION_ARGS); +extern Datum range_upper_inf(PG_FUNCTION_ARGS); + +/* range, element -> bool */ +extern Datum range_contains_elem(PG_FUNCTION_ARGS); +extern Datum elem_contained_by_range(PG_FUNCTION_ARGS); + +extern bool range_contains_elem_internal(TypeCacheEntry* typcache, RangeType* r, Datum val); + +/* range, range -> bool */ +extern Datum range_eq(PG_FUNCTION_ARGS); +extern Datum range_ne(PG_FUNCTION_ARGS); +extern Datum range_contains(PG_FUNCTION_ARGS); +extern Datum range_contained_by(PG_FUNCTION_ARGS); +extern Datum range_before(PG_FUNCTION_ARGS); +extern Datum range_after(PG_FUNCTION_ARGS); +extern Datum range_adjacent(PG_FUNCTION_ARGS); +extern Datum range_overlaps(PG_FUNCTION_ARGS); +extern Datum range_overleft(PG_FUNCTION_ARGS); +extern Datum range_overright(PG_FUNCTION_ARGS); + +/* internal versions of the above */ +extern bool range_eq_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_ne_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_contains_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_contained_by_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_before_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_after_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_adjacent_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overlaps_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overleft_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overright_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); + +/* range, range -> range */ +extern Datum range_minus(PG_FUNCTION_ARGS); +extern Datum range_union(PG_FUNCTION_ARGS); +extern Datum range_intersect(PG_FUNCTION_ARGS); + +/* BTree support */ +extern Datum range_cmp(PG_FUNCTION_ARGS); +extern Datum range_lt(PG_FUNCTION_ARGS); +extern Datum range_le(PG_FUNCTION_ARGS); +extern Datum range_ge(PG_FUNCTION_ARGS); +extern Datum range_gt(PG_FUNCTION_ARGS); + +/* Hash support */ +extern Datum hash_range(PG_FUNCTION_ARGS); + +/* ANALYZE support */ +extern Datum range_typanalyze(PG_FUNCTION_ARGS); + +/* Canonical functions */ +extern Datum int4range_canonical(PG_FUNCTION_ARGS); +extern Datum int8range_canonical(PG_FUNCTION_ARGS); +extern Datum daterange_canonical(PG_FUNCTION_ARGS); + +/* Subtype Difference functions */ +extern Datum int4range_subdiff(PG_FUNCTION_ARGS); +extern Datum int8range_subdiff(PG_FUNCTION_ARGS); +extern Datum numrange_subdiff(PG_FUNCTION_ARGS); +extern Datum daterange_subdiff(PG_FUNCTION_ARGS); +extern Datum tsrange_subdiff(PG_FUNCTION_ARGS); +extern Datum tstzrange_subdiff(PG_FUNCTION_ARGS); + +/* assorted support functions */ +extern TypeCacheEntry* range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid); +extern RangeType* range_serialize(TypeCacheEntry* typcache, RangeBound* lower, RangeBound* upper, bool empty); +extern void range_deserialize( + TypeCacheEntry* typcache, RangeType* range, RangeBound* lower, RangeBound* upper, bool* empty); +extern char range_get_flags(RangeType* range); +extern void range_set_contain_empty(RangeType* range); +extern RangeType* make_range(TypeCacheEntry* typcache, RangeBound* lower, RangeBound* upper, bool empty); +extern int range_cmp_bounds(TypeCacheEntry* typcache, RangeBound* b1, RangeBound* b2); +extern int range_cmp_bound_values(TypeCacheEntry* typcache, RangeBound* b1, RangeBound* b2); +extern RangeType* make_empty_range(TypeCacheEntry* typcache); + +/* GiST support (in rangetypes_gist.c) */ +extern Datum range_gist_consistent(PG_FUNCTION_ARGS); +extern Datum range_gist_compress(PG_FUNCTION_ARGS); +extern Datum range_gist_decompress(PG_FUNCTION_ARGS); +extern Datum range_gist_union(PG_FUNCTION_ARGS); +extern Datum range_gist_penalty(PG_FUNCTION_ARGS); +extern Datum range_gist_picksplit(PG_FUNCTION_ARGS); +extern Datum range_gist_same(PG_FUNCTION_ARGS); + +#endif /* RANGETYPES_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/rbtree.h postgresql-hll-2.14/include/include/utils/rbtree.h --- postgresql-hll-2.14_old/include/include/utils/rbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/rbtree.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * rbtree.h + * interface for PostgreSQL generic Red-Black binary tree package + * + * Copyright (c) 2009-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/utils/rbtree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RBTREE_H +#define RBTREE_H + +/* + * RBNode is intended to be used as the first field of a larger struct, + * whose additional fields carry whatever payload data the caller needs + * for a tree entry. (The total size of that larger struct is passed to + * rb_create.) RBNode is declared here to support this usage, but + * callers must treat it as an opaque struct. + */ +typedef struct RBNode { + char iteratorState; /* workspace for iterating through tree */ + char color; /* node's current color, red or black */ + struct RBNode* left; /* left child, or RBNIL if none */ + struct RBNode* right; /* right child, or RBNIL if none */ + struct RBNode* parent; /* parent, or NULL (not RBNIL!) if none */ +} RBNode; + +/* Opaque struct representing a whole tree */ +typedef struct RBTree RBTree; + +/* Available tree iteration orderings */ +typedef enum RBOrderControl { + LeftRightWalk, /* inorder: left child, node, right child */ + RightLeftWalk, /* reverse inorder: right, node, left */ + DirectWalk, /* preorder: node, left child, right child */ + InvertedWalk /* postorder: left child, right child, node */ +} RBOrderControl; + +/* Support functions to be provided by caller */ +typedef int (*rb_comparator)(const RBNode* a, const RBNode* b, void* arg); +typedef void (*rb_combiner)(RBNode* existing, const RBNode* newdata, void* arg); +typedef RBNode* (*rb_allocfunc)(void* arg); +typedef void (*rb_freefunc)(RBNode* x, void* arg); + +extern RBTree* rb_create(Size node_size, rb_comparator comparator, rb_combiner combiner, rb_allocfunc allocfunc, + rb_freefunc freefunc, void* arg); + +extern RBNode* rb_find(RBTree* rb, const RBNode* data); +extern RBNode* rb_leftmost(RBTree* rb); + +extern RBNode* rb_insert(RBTree* rb, const RBNode* data, bool* isNew); +extern void rb_delete(RBTree* rb, RBNode* node); + +extern void rb_begin_iterate(RBTree* rb, RBOrderControl ctrl); +extern RBNode* rb_iterate(RBTree* rb); + +#endif /* RBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/relcache.h postgresql-hll-2.14/include/include/utils/relcache.h --- postgresql-hll-2.14_old/include/include/utils/relcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/relcache.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,153 @@ +/* ------------------------------------------------------------------------- + * + * relcache.h + * Relation descriptor cache definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/relcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELCACHE_H +#define RELCACHE_H + +#include "access/tupdesc.h" +#include "nodes/bitmapset.h" +#include "utils/hsearch.h" + +#define IsValidCatalogParam(catalogDesc) (catalogDesc.oid != InvalidOid) + +typedef struct RelationData* Relation; +typedef struct PartitionData* Partition; +struct HeapTupleData; +typedef HeapTupleData* HeapTuple; +typedef int LOCKMODE; + +/* ---------------- + * RelationPtr is used in the executor to support index scans + * where we have to keep track of several index relations in an + * array. -cim 9/10/89 + * ---------------- + */ +typedef Relation* RelationPtr; + +typedef struct CatalogRelationBuildParam { + Oid oid; + const char* relationName; + Oid relationReltype; + bool isshared; + bool hasoids; + int natts; + const FormData_pg_attribute* attrs; + bool isnailed; + bool insertIt; +} CatalogRelationBuildParam; + +/* + * Routines to open (lookup) and close a relcache entry + */ +extern Relation RelationIdGetRelation(Oid relationId); +extern void RelationClose(Relation relation); + +/* + * Routines to compute/retrieve additional cached information + */ +extern List* PartitionGetPartIndexList(Partition part); +extern List* RelationGetIndexList(Relation relation); +extern List* RelationGetSpecificKindIndexList(Relation relation, bool isGlobal); +extern List* RelationGetIndexInfoList(Relation relation); +extern int RelationGetIndexNum(Relation relation); +extern Oid RelationGetOidIndex(Relation relation); +extern Oid RelationGetReplicaIndex(Relation relation); +extern List* RelationGetIndexExpressions(Relation relation); +extern List* RelationGetIndexExpressions(Relation relation); +extern List* RelationGetDummyIndexExpressions(Relation relation); +extern List* RelationGetIndexPredicate(Relation relation); +extern void AtEOXact_FreeTupleDesc(); + +typedef enum IndexAttrBitmapKind { + INDEX_ATTR_BITMAP_ALL, + INDEX_ATTR_BITMAP_KEY, + INDEX_ATTR_BITMAP_IDENTITY_KEY +} IndexAttrBitmapKind; + +typedef enum PartitionMetadataStatus { + PART_METADATA_NOEXIST, /* partition is not exists */ + PART_METADATA_LIVE, /* partition is live, normal use */ + PART_METADATA_CREATING, /* partition is being created */ + PART_METADATA_INVISIBLE /* partition is invisible, being droped */ +} PartStatus; + +extern Bitmapset* RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind keyAttrs); + +extern void RelationGetExclusionInfo(Relation indexRelation, Oid** operators, Oid** procs, uint16** strategies); + +extern void RelationSetIndexList(Relation relation, List* indexIds, Oid oidIndex); + +extern void RelationInitIndexAccessInfo(Relation relation, HeapTuple index_tuple = NULL); + +/* + * Routines for backend startup + */ +extern void RelationCacheInitialize(void); +extern void RelationCacheInitializePhase2(void); +extern void RelationCacheInitializePhase3(void); + +/* + * Routine to create a relcache entry for an about-to-be-created relation + */ +extern Relation RelationBuildLocalRelation(const char* relname, Oid relnamespace, TupleDesc tupDesc, Oid relid, + Oid relfilenode, Oid reltablespace, bool shared_relation, bool mapped_relation, char relpersistence, char relkind, + int8 row_compress, TableAmType tam_type); + +/* + * Routine to manage assignment of new relfilenode to a relation + */ +extern void DescTableSetNewRelfilenode(Oid relid, TransactionId freezeXid, bool partition); +extern void DeltaTableSetNewRelfilenode(Oid relid, TransactionId freezeXid, bool partition); +extern void RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid, bool isDfsTruncate = false); + +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void RelationForgetRelation(Oid rid); + +extern void RelationCacheInvalidateEntry(Oid relationId); + +extern void RelationCacheInvalidate(void); + +extern void RelationCacheInvalidateBuckets(); + +extern void RelationCloseSmgrByOid(Oid relationId); +extern Oid RelationGetBucketOid(Relation relation); + +extern void AtEOXact_RelationCache(bool isCommit); +extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); + +/* + * Routines to help manage rebuilding of relcache init files + */ +extern bool RelationIdIsInInitFile(Oid relationId); +extern void RelationCacheInitFilePreInvalidate(void); +extern void RelationCacheInitFilePostInvalidate(void); +extern void RelationCacheInitFileRemove(void); + +extern TupleDesc BuildHardcodedDescriptor(int natts, const FormData_pg_attribute* attrs, bool hasoids); +extern TupleDesc GetDefaultPgClassDesc(void); +extern TupleDesc GetDefaultPgIndexDesc(void); + +extern bool CheckRelationInRedistribution(Oid rel_oid); + +extern CatalogRelationBuildParam GetCatalogParam(Oid id); + +extern HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic); + +/* + * this function is used for timeseries database, do not call this function directly!!! + */ +extern Relation tuple_get_rel(HeapTuple pg_class_tuple, LOCKMODE lockmode, TupleDesc tuple_desc, HeapTuple pg_indextuple = NULL); +extern THR_LOCAL bool needNewLocalCacheFile; +#endif /* RELCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/relfilenodemap.h postgresql-hll-2.14/include/include/utils/relfilenodemap.h --- postgresql-hll-2.14_old/include/include/utils/relfilenodemap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/relfilenodemap.h 2020-12-12 17:06:43.293348632 +0800 @@ -0,0 +1,20 @@ +/* --------------------------------------------------------------------------------------- + * + * relfilenodemap.h + * relfilenode to oid mapping cache. + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/relfilenodemap.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RELFILENODEMAP_H +#define RELFILENODEMAP_H + +extern Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode); +extern Oid PartitionRelidByRelfilenode(Oid reltablespace, Oid relfilenode, Oid& partationReltoastrelid); + +#endif /* RELFILENODEMAP_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/rel_gs.h postgresql-hll-2.14/include/include/utils/rel_gs.h --- postgresql-hll-2.14_old/include/include/utils/rel_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/rel_gs.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,701 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rel_gs.h + * POSTGRES relation descriptor (a/k/a relcache entry) definitions. + * + * + * IDENTIFICATION + * src/include/utils/rel_gs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REL_GS_H +#define REL_GS_H + +/* + * Relation Compression Type + * REL_CMPRS_NOT_SUPPORT: + * relation doesn't support compression. That means these relations have constant + * commpression attr. 'ALTER TABLE ... SET COMPRESS/UNCOMPRESS' mustn't applies + * to these relations. For examples, system relations, index, etc. + * REL_CMPRS_PAGE_PLAIN: + * relation support compression with 'CREATE/ALTER TABLE ... [SET] COMPRESS/UNCOMPRESS' clause. + * Under this condition, all the data in this relation are stored in plain format. + * REL_CMPRS_PAGE_DICT: + * relation support compression with 'CREATE/ALTER TABLE ... [SET] COMPRESS/UNCOMPRESS' clause. + * Under this condition, many tuples of one page in this relation are stored after compressing. + * REL_CMPRS_MAX_TYPE: + * The other types must be defined above this value. + */ +typedef enum { + REL_CMPRS_NOT_SUPPORT = 0, + REL_CMPRS_PAGE_PLAIN, + REL_CMPRS_FIELDS_EXTRACT, + REL_CMPRS_MAX_TYPE +} RelCompressType; + +#ifndef FRONTEND_PARSER +#include "catalog/pg_partition.h" +#include "catalog/pg_hashbucket.h" +#include "catalog/catalog.h" +#include "catalog/pg_namespace.h" +#include "utils/partitionmap_gs.h" +#include "rel.h" + +#define CHECK_CMPRS_VALID(compress) ((compress) > REL_CMPRS_NOT_SUPPORT && (compress) < REL_CMPRS_MAX_TYPE) +#define CHECK_CMPRS_NOT_SUPPORT(compress) (REL_CMPRS_NOT_SUPPORT == (compress)) + +typedef struct PartitionData { + RelFileNode pd_node; /* relation physical identifier */ + /* use "struct" here to avoid needing to include smgr.h: */ + struct SMgrRelationData* pd_smgr; /* cached file handle, or NULL */ + int pd_refcnt; /* reference count */ + bool pd_isvalid; /* partcache entry is valid */ + char pd_indexvalid; /* state of pd_indexlist: 0 = not valid, 1 = + * valid, 2 = temporarily forced */ + + /* + * rd_createSubid is the ID of the highest subtransaction the rel has + * survived into; or zero if the rel was not created in the current top + * transaction. This should be relied on only for optimization purposes; + * it is possible for new-ness to be "forgotten" (eg, after CLUSTER). + * Likewise, rd_newRelfilenodeSubid is the ID of the highest + * subtransaction the relfilenode change has survived into, or zero if not + * changed in the current transaction (or we have forgotten changing it). + */ + SubTransactionId pd_createSubid; /* rel was created in current xact */ + SubTransactionId pd_newRelfilenodeSubid; /* new relfilenode assigned in + * current xact */ + + Form_pg_partition pd_part; /* PARTITION tuple */ + Oid pd_id; /* partition's object id */ + List* pd_indexlist; /* list of OIDs of indexes on partition */ + Bitmapset* pd_indexattr; /* identifies columns used in indexes */ + Oid pd_oidindex; /* OID of unique index on OID, if any */ + LockInfoData pd_lockInfo; /* lock mgr's info for locking relation */ /*?*/ + /* + * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new + * version of a table, we need to make any toast pointers inserted into it + * have the existing toast table's OID, not the OID of the transient toast + * table. If rd_toastoid isn't InvalidOid, it is the OID to place in + * toast pointers inserted into this rel. (Note it's set on the new + * version of the main heap, not the toast table itself.) This also + * causes toast_save_datum() to try to preserve toast value OIDs. + */ + Oid pd_toastoid; /* Real TOAST table's OID from pg_partition, or InvalidOid */ + /* use "struct" here to avoid needing to include pgstat.h: */ + bytea* rd_options; /* partition's reloptions */ + struct PgStat_TableStatus* pd_pgstat_info; /* statistics collection area */ + Partition parent; +} PartitionData; + +typedef struct AttrMetaData { + NodeTag type; + + char* attname; /* name of attribute */ + Oid atttypid; + int2 attlen; + int2 attnum; + int4 atttypmod; + bool attbyval; + char attstorage; + char attalign; + bool attnotnull; + bool atthasdef; + bool attisdropped; + bool attislocal; + int1 attkvtype; + int1 attcmprmode; + int4 attinhcount; + Oid attcollation; +} AttrMetaData; + +typedef struct RelationMetaData { + NodeTag type; + + Oid rd_id; /* relation's object id */ + + // RelFileNode rd_node; /* relation physical identifier */ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ + int4 bucketNode; /* bucket */ + + // Form_pg_class rd_rel; /* RELATION tuple */ + char* relname; /* class name */ + char relkind; /* see RELKIND_xxx constants below */ + char parttype; /* 'p' for partitioned relation, 'n' for non-partitioned relation */ + + // TupleDesc rd_att; /* tuple descriptor */ + int natts; /* number of attributes in the tuple */ + List* attrs; /* the list of AttrMetaData */ +} RelationMetaData; + +#define ORIENTATION_ROW "row" +#define ORIENTATION_COLUMN "column" +#define ORIENTATION_ORC "orc" +#define ORIENTATION_TIMESERIES "timeseries" + +#define TIME_ONE_HOUR "1 HOUR" +#define TIME_ONE_DAY "1 DAY" +#define TIME_ONE_WEEK "1 WEEK" +#define TIME_ONE_MONTH "1 MONTH" +#define TIME_ONE_YEAR "1 YEAR" +#define TIME_UNDEFINED "UNDEFINED" + +#define COLUMN_UNDEFINED "UNDEFINED" + +#define ORC_VERSION_011 "0.11" +#define ORC_VERSION_012 "0.12" + +#define COMPRESSION_NO "no" +#define COMPRESSION_YES "yes" +#define COMPRESSION_LOW "low" +#define COMPRESSION_MIDDLE "middle" +#define COMPRESSION_HIGH "high" +#define COMPRESSION_ZLIB "zlib" +#define COMPRESSION_SNAPPY "snappy" +#define COMPRESSION_LZ4 "lz4" + +/* + * values for different table access method types. + */ +#define TABLE_ACCESS_METHOD_HEAP "HEAP" +#define TABLE_ACCESS_METHOD_USTORE "USTORE" + +#define FILESYSTEM_GENERAL "general" +#define FILESYSTEM_HDFS "hdfs" + +#define OptIgnoreEnableHadoopEnv "ignore_enable_hadoop_env" +#define TS_PSEUDO_DIST_COLUMN "ts_pseudo_distcol" + +#define OptEnabledWaitCleanGpi "y" +#define OptDisabledWaitCleanGpi "n" + +#define INTERNAL_MASK_DISABLE 0x0 +#define INTERNAL_MASK_ENABLE 0x8000 +#define INTERNAL_MASK_DINSERT 0x01 // disable insert +#define INTERNAL_MASK_DDELETE 0x02 // disable delete +#define INTERNAL_MASK_DALTER 0x04 // disable alter +#define INTERNAL_MASK_DSELECT 0x08 // disable select +#define INTERNAL_MASK_DUPDATE 0x0100 // disable update + +#define StdRdOptionsGetStringData(_basePtr, _memberName, _defaultVal) \ + (((_basePtr) && (((StdRdOptions*)(_basePtr))->_memberName)) \ + ? (((char*)(_basePtr) + *(int*)&(((StdRdOptions*)(_basePtr))->_memberName))) \ + : (_defaultVal)) + +/* + * ReltionGetTableAccessMethoType + * Returns the relations TableAmType + */ +#define RelationGetTableAccessMethodType(_reloptions) \ + StdRdOptionsGetStringData(_reloptions, table_access_method, TABLE_ACCESS_METHOD_HEAP) + +#define RelationIsTableAccessMethodHeapType(_reloptions) \ + pg_strcasecmp(RelationGetTableAccessMethodType(_reloptions), TABLE_ACCESS_METHOD_HEAP) == 0 + +#define RelationIsTableAccessMethodUStoreType(_reloptions) \ + pg_strcasecmp(RelationGetTableAccessMethodType(_reloptions), TABLE_ACCESS_METHOD_USTORE) == 0 + + +/* + * @Description: get TableAmType type from Relation's reloptions data. + * @IN reloptions: Table's reloptions. + * @Return: return TableAmType type for this relation. + */ +static inline TableAmType get_tableam_from_reloptions(bytea* reloptions, char relkind) +{ + if (relkind == RELKIND_RELATION) + { + if (reloptions!= NULL) + { + if (RelationIsTableAccessMethodHeapType(reloptions)) + { + return TAM_HEAP; + } + else if (RelationIsTableAccessMethodUStoreType(reloptions)) + { + return TAM_USTORE; + } + + return TAM_HEAP; + } + else //For System Tables reloptions can be NULL. + { + return TAM_HEAP; + } + } + else if (relkind == RELKIND_INDEX || + relkind == RELKIND_TOASTVALUE || + relkind == RELKIND_SEQUENCE || + relkind == RELKIND_COMPOSITE_TYPE || + relkind == RELKIND_VIEW || + relkind == RELKIND_FOREIGN_TABLE) + { + return TAM_HEAP; + } + + return TAM_HEAP; +} + +/* RelationGetOrientation + * Return the relations' orientation + */ +#define RelationGetOrientation(relation) StdRdOptionsGetStringData((relation)->rd_options, orientation, ORIENTATION_ROW) + +#define RaletionGetStoreVersion(relation) StdRdOptionsGetStringData((relation)->rd_options, version, ORC_VERSION_012) + +#define RelationGetFileSystem(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, filesystem, FILESYSTEM_GENERAL) + +#define RelationIsCUFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_COLUMN) == 0) + +#define RelationIsRowFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_ROW) == 0) + +#define RelationIsColumnFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && (RelationIsCUFormat(relation) || RelationIsPAXFormat(relation))) + +#define RelationGetCUDescRelId(r) ((r)->rd_rel->relcudescrelid) +#define RelationGetDeltaRelId(r) ((r)->rd_rel->reldeltarelid) +#define RelationGetRelFileNode(r) ((r)->rd_rel->relfilenode) + +/* + * @Description: get columnar relation's compress level. + * @IN rel: columnar heap relation + * @Return: return user explictly defined compresslevel, + * or return compresslevel zero. + * @See also: + */ +static inline int relation_get_compresslevel(Relation rel) +{ + Assert(rel != NULL); + if ((RELKIND_RELATION == rel->rd_rel->relkind) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->compresslevel; + } + /* Otherwise just return zero */ + return 0; +} + +static inline int RelationGetInternalMask(Relation rel) +{ + /* Now internal mask is only available for ordinary relation */ + if ((RELKIND_RELATION == rel->rd_rel->relkind) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->internalMask; + } else { + return INTERNAL_MASK_DISABLE; + } +} + +#define RelationIsInternal(relation) (RelationGetInternalMask(relation) != INTERNAL_MASK_DISABLE) + +#define RelationIsRelation(relation) (RELKIND_RELATION == (relation)->rd_rel->relkind) + +#define RelationIsMatview(relation) (RELKIND_MATVIEW == (relation)->rd_rel->relkind) + +/* + * Mgr for Redistribute + */ +static inline RedisHtlAction RelationGetAppendMode(Relation rel) +{ + Assert(rel != NULL); + if (RelationIsRelation(rel) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->append_mode_internal; + } + + /* Otherwise just return zero */ + return REDIS_REL_NORMAL; +} + +/* + * RelationIsPAXFormat + * Return the relations' orientation. Pax format includes ORC format. + */ +#define RelationIsPAXFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_ORC) == 0) + +/* RelationIsColStore + * Return relation whether is column store, which includes CU format and PAX format. + */ +#define RelationIsColStore(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && (RelationIsCUFormat(relation) || RelationIsPAXFormat(relation))) + +#define RelationOptionIsDfsStore(optionValue) (optionValue && 0 == pg_strncasecmp(optionValue, HDFS, strlen(HDFS))) + +#define RelationIsTsStore(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_TIMESERIES) == 0) + +#define TsRelWithImplDistColumn(attribute, pos) \ + (((attribute)[pos]->attkvtype == ATT_KV_HIDE) && \ + namestrcmp(&((attribute)[pos]->attname), TS_PSEUDO_DIST_COLUMN) == 0) + +// Helper Macro Defination +// +#define StdRelOptGetOrientation(__stdRelOpt) StdRdOptionsGetStringData((__stdRelOpt), orientation, ORIENTATION_ROW) + +#define StdRelOptIsColStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_COLUMN, StdRelOptGetOrientation(__stdRelOpt))) + +#define StdRelOptIsRowStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_ROW, StdRelOptGetOrientation(__stdRelOpt))) + +#define StdRelOptIsTsStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_TIMESERIES, \ + StdRelOptGetOrientation(__stdRelOpt))) + + +/* get internal_mask option from reloption */ +#define StdRelOptGetInternalMask(__stdRelOpt) StdRdOptionsGetStringData((__stdRelOpt), internalMask, 0) + +// RelationGetCompression +// Return the relation's compression option +// +#define RelationGetCompression(relation) StdRdOptionsGetStringData((relation)->rd_options, compression, COMPRESSION_LOW) + +// make sure that: +// 1. RelDefaultFullCuSize = N * BatchMaxSize +// 2. RelDefaultPartialClusterRows = M * RelDefaultFullCuSize +// +#define RelMaxFullCuSize (60 * BatchMaxSize) +#define RelDefaultFullCuSize RelMaxFullCuSize +#define RelDefaultPartialClusterRows (70 * RelDefaultFullCuSize) +#define RelDefaultDletaRows 100 + +/* the min/max values about compress-level option */ +#define REL_MIN_COMPRESSLEVEL (0) +#define REL_MAX_COMPRESSLEVEL (3) + +#define RelRoundIntOption(_v1, _v2) (AssertMacro((_v1) >= (_v2)), ((_v2) * ((_v1) / (_v2)))) + +// RelationGetMaxBatchRows +// Return the relation's max_batch_rows option +// +#define RelationGetMaxBatchRows(relation) \ + ((relation)->rd_options ? RelRoundIntOption(((StdRdOptions*)(relation)->rd_options)->max_batch_rows, BatchMaxSize) \ + : RelDefaultFullCuSize) + +// RelationGetDeltaRowsThreshold +// Return the relation's delta_rows_threshold option +// +#define RelationGetDeltaRowsThreshold(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->delta_rows_threshold : RelDefaultDletaRows) + +// RelationGetPartialClusterRows +// Return the relation's partial_cluster_rows option(return max value for -1) +// +#define RelationGetPartialClusterRows(relation) \ + ((relation)->rd_options \ + ? ((((StdRdOptions*)(relation)->rd_options)->partial_cluster_rows < 0) \ + ? RelRoundIntOption(0x7fffffff, RelationGetMaxBatchRows(relation)) \ + : RelRoundIntOption(((StdRdOptions*)(relation)->rd_options)->partial_cluster_rows, \ + RelationGetMaxBatchRows(relation))) \ + : RelDefaultPartialClusterRows) + +/* Relation whether create in current xact */ +static inline bool RelationCreateInCurrXact(Relation rel) +{ + return rel->rd_createSubid != InvalidTransactionId; +} + +/* RelationGetPgClassOid + * return the pg_class OID of this relation. + * if this is a PARTITION, return its parent oid; + * otherwise the same to macro RelationGetRelid(). + */ +#define RelationGetPgClassOid(relation, isPartition) \ + ((isPartition) ? ((relation)->parentId) : RelationGetRelid(relation)) + +/* + * PartitionOpenSmgr + * Open the partition at the smgr level, if not already done. + */ +#define PartitionOpenSmgr(partition) \ + do { \ + if ((partition)->pd_smgr == NULL) \ + smgrsetowner(&((partition)->pd_smgr), smgropen((partition)->pd_node, InvalidBackendId)); \ + } while (0) + + +/* + * PartionCloseSmgr + * Close the partition at the smgr level, if not already done. + * + * Note: smgrclose should unhook from owner pointer, hence the Assert. + */ +#define PartitionCloseSmgr(partition) \ + do { \ + if ((partition)->pd_smgr != NULL) { \ + smgrclose((partition)->pd_smgr); \ + Assert(PartitionIsBucket(partition) || (partition)->pd_smgr == NULL); \ + } \ + } while (0) + +/* + * PartitionGetTargetBlock + * Fetch partition's current insertion target block. + * + * Returns InvalidBlockNumber if there is no current target block. Note + * that the target block status is discarded on any smgr-level invalidation. + */ +#define PartitionGetTargetBlock(partition) \ + ((partition)->pd_smgr != NULL ? (partition)->pd_smgr->smgr_targblock : InvalidBlockNumber) +/* + * PartitionSetTargetBlock + * Set relation's current insertion target block. + */ +/* + * PartitionGetPartitionName + * Returns the part's name. + * + * Note that the name is only unique within the containing namespace. + */ +#define PartitionGetPartitionName(partition) (NameStr((partition)->pd_part->relname)) +/* + * PartitionGetPartid + * Returns the OID of the partition + */ +#define PartitionGetPartid(partition) ((partition)->pd_id) + +#define PartitionGetRelid(partition) ((partition)->pd_part->parentid) + +/* + * PartitionIsValid + * True iff partition descriptor is valid. + */ +#define PartitionIsValid(partition) PointerIsValid(partition) + +/* + * true if the relation is construct from a partition + */ +#define RelationIsPartition(relation) \ + (OidIsValid((relation)->parentId) && (PARTTYPE_NON_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + ((RELKIND_RELATION == (relation)->rd_rel->relkind) || (RELKIND_INDEX == (relation)->rd_rel->relkind))) + +#define InvalidPartition ((Partition)NULL) + +#define InvalidBktId (-1) +#define RelationIsBucket(relation) \ + ((relation)->rd_node.bucketNode > InvalidBktId) + +/* + * PartitionHasReferenceCountZero + * True iff partition reference count is zero. + * + * Note: + * Assumes partition descriptor is valid. + */ +#define PartitionHasReferenceCountZero(partition) ((bool)((partition)->pd_refcnt == 0)) +/* routines in utils/cache/partcache.c */ +extern void PartitionIncrementReferenceCount(Partition part); +extern void PartitionDecrementReferenceCount(Partition part); + +#define PartitionIsMapped(part) ((part)->pd_part->relfilenode == InvalidOid) + +#define CStoreRelationOpenSmgr(relation, col) \ + do { \ + if ((relation)->rd_smgr == NULL) \ + smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node, (relation)->rd_backend, (col))); \ + else { \ + SMgrRelation tmp; \ + tmp = smgropen((relation)->rd_node, (relation)->rd_backend, (col)); \ + Assert((relation)->rd_smgr == tmp); \ + } \ + } while (0) + +#define RelationIsLocalTemp(relation) \ + ((relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempNamespace || \ + (relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempToastNamespace) + +#define RelationIsUnlogged(relation) ((relation)->rd_rel->relnamespace == RELPERSISTENCE_UNLOGGED) + +#define RelationIsGlobalIndex(relation) (RELKIND_GLOBAL_INDEX == (relation)->rd_rel->relkind) + +#define RelationIsIndex(relation) (RELKIND_INDEX == (relation)->rd_rel->relkind || RelationIsGlobalIndex(relation)) + +#define RelationIsSequnce(relation) (RELKIND_SEQUENCE == (relation)->rd_rel->relkind) + +#define RelationIsToast(relation) (RELKIND_TOASTVALUE == (relation)->rd_rel->relkind) + +#define RelationIsView(relation) (RELKIND_VIEW == (relation)->rd_rel->relkind) + +#define RelationIsContquery(relation) (RELKIND_CONTQUERY == (relation)->rd_rel->relkind) + +#define RelationIsForeignTable(relation) (RELKIND_FOREIGN_TABLE == (relation)->rd_rel->relkind) + +#define RelationIsStream(relation) (RELKIND_STREAM == (relation)->rd_rel->relkind) + +#define RelationIsUnCataloged(relation) (RELKIND_UNCATALOGED == (relation)->rd_rel->relkind) + +#define RelationIsPartitioned(relation) (PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) +#define RelationIsRangePartitioned(relation) (PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +#define RelationIsValuePartitioned(relation) (PARTTYPE_VALUE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +#define RelationGetValuePartitionList(relation) \ + (RelationIsValuePartitioned(relation) ? ((ValuePartitionMap*)relation->partMap)->partList : NIL) + +#define RelationIsNonpartitioned(relation) (PARTTYPE_NON_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +/* + * RELATION_IS_OTHER_TEMP + * Test for a temporary relation that belongs to some other session. + * + * Beware of multiple eval of argument + */ +#define RELATION_IS_OTHER_TEMP(relation) \ + (STMT_RETRY_ENABLED ? ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \ + u_sess->catalog_cxt.myTempNamespace != (relation)->rd_rel->relnamespace && \ + u_sess->catalog_cxt.myTempToastNamespace != (relation)->rd_rel->relnamespace && \ + CSTORE_NAMESPACE != (relation)->rd_rel->relnamespace && \ + PG_TOAST_NAMESPACE != (relation)->rd_rel->relnamespace) \ + : ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \ + u_sess->catalog_cxt.myTempNamespace != (relation)->rd_rel->relnamespace && \ + u_sess->catalog_cxt.myTempToastNamespace != (relation)->rd_rel->relnamespace)) + +#define RELATION_IS_PARTITIONED(relation) \ + ((PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + (RELKIND_RELATION == (relation)->rd_rel->relkind)) + +#define RELATION_IS_VALUE_PARTITIONED(relation) \ + ((PARTTYPE_VALUE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + (RELKIND_RELATION == (relation)->rd_rel->relkind)) + +/* + * type bucketOid bucketKey meaning + * N INV INV relation has no bucket + * B 1 KEY relation has bucket but without bucket storage + * S OID INV relation has bucket storage without bucket key + * K OID KEY relation has bucket key + */ +#define REALTION_BUCKETKEY_INITED(relation) \ + ((relation)->rd_bucketkey != (RelationBucketKey*)&((relation)->rd_bucketkey)) + +#define REALTION_BUCKETKEY_VALID(relation) \ + (REALTION_BUCKETKEY_INITED(relation) && \ + PointerIsValid((relation)->rd_bucketkey)) + +/* type: SKB*/ +#define RELATION_HAS_BUCKET(relation) \ + (OidIsValid((relation)->rd_bucketoid)) + +/* type: SK */ +#define RELATION_OWN_BUCKET(relation) \ + (RELATION_HAS_BUCKET(relation) && \ + (VirtualBktOid != (relation)->rd_bucketoid)) + +/* type: K*/ +#define RELATION_OWN_BUCKETKEY(relation) \ + (RELATION_OWN_BUCKET(relation) && \ + RelationIsPartitioned(relation)) + +/* type: SK && Non-part*/ +#define RELATION_CREATE_BUCKET(relation) \ + (RelationIsNonpartitioned(relation) && \ + RELATION_OWN_BUCKET(relation)) + + +#define RELATION_IS_DELTA(relation) \ + (IsCStoreNamespace(RelationGetNamespace(relation)) && \ + pg_strncasecmp(RelationGetRelationName(relation), "pg_delta", strlen("pg_delta")) == 0) + +#define RELATION_GET_CMPRS_ATTR(relation) ((relation)->rd_rel->relcmprs) +#define RELATION_SET_CMPRS_ATTR(relation, cmprs) ((relation)->rd_rel->relcmprs = cmprs) + +static inline bool IsCompressedByCmprsInPgclass(const RelCompressType cmprInPgclass) +{ + return (cmprInPgclass > REL_CMPRS_PAGE_PLAIN && cmprInPgclass < REL_CMPRS_MAX_TYPE); +} + +/* at default row relation is not compressed in options */ +/* maybe exsiting compressed row-table don't modify compression option synchronously */ +#define RowRelationIsCompressed(relation) \ + (pg_strcasecmp(COMPRESSION_NO, StdRdOptionsGetStringData(relation->rd_options, compression, COMPRESSION_NO)) != 0 || \ + IsCompressedByCmprsInPgclass((RelCompressType)relation->rd_rel->relcmprs)) + +#define RelIsSpecifiedFTbl(rte, SepcifiedType) \ + ((rte->relkind == RELKIND_FOREIGN_TABLE || rte->relkind == RELKIND_STREAM) \ + && isSpecifiedSrvTypeFromRelId(rte->relid, SepcifiedType)) + +#define RelationGetStartCtidInternal(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, start_ctid_internal, NULL) + +#define RelationGetEndCtidInternal(relation) StdRdOptionsGetStringData((relation)->rd_options, end_ctid_internal, NULL) + +#define RelationInRedistribute(relation) (REDIS_REL_NORMAL < (RelationGetAppendMode(relation)) ? true : false) + +#define RelationInRedistributeReadOnly(relation) \ + (REDIS_REL_READ_ONLY == (RelationGetAppendMode(relation)) ? true : false) + +#define RelationInRedistributeEndCatchup(relation) \ + (REDIS_REL_END_CATCHUP == (RelationGetAppendMode(relation)) ? true : false) + +#define RelationIsRedistributeDest(relation) \ + (REDIS_REL_DESTINATION == (RelationGetAppendMode(relation)) ? true : false) + +/* Get info */ +#define RelationGetRelCnOid(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->rel_cn_oid : InvalidOid) + +#define RelationGetRelMergeList(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, merge_list, NULL) + +#define ParitionGetWaitCleanGpi(partition) StdRdOptionsGetStringData((partition)->rd_options, wait_clean_gpi, OptDisabledWaitCleanGpi) +#define RelationGetWaitCleanGpi(relation) StdRdOptionsGetStringData((relation)->rd_options, wait_clean_gpi, OptDisabledWaitCleanGpi) + +/* Partition get reloptions whether have wait_clean_gpi for parition */ +static inline bool PartitionEnableWaitCleanGpi(Partition partition) +{ + if (PointerIsValid(partition) && partition->rd_options != NULL && + pg_strcasecmp(OptEnabledWaitCleanGpi, ParitionGetWaitCleanGpi(partition)) == 0) { + return true; + } + + return false; +} + +/* Relation get reloptions whether have wait_clean_gpi for relation */ +static inline bool RelationEnableWaitCleanGpi(Relation relation) +{ + if (PointerIsValid(relation) && relation->rd_options != NULL && + pg_strcasecmp(OptEnabledWaitCleanGpi, RelationGetWaitCleanGpi(relation)) == 0) { + return true; + } + + return false; +} + +/* routines in utils/cache/relcache.c */ +extern bool RelationIsDfsStore(Relation relatioin); +extern bool RelationIsPaxFormatByOid(Oid relid); +#ifdef ENABLE_MOT +extern bool RelationIsMOTTableByOid(Oid relid); +#endif +extern bool RelationIsCUFormatByOid(Oid relid); + +#define IS_FOREIGNTABLE(rel) ((rel)->rd_rel->relkind == RELKIND_FOREIGN_TABLE) +#define IS_STREAM_TABLE(rel) ((rel)->rd_rel->relkind == RELKIND_STREAM) +extern bool have_useft_privilege(void); + +extern RelationMetaData* make_relmeta(Relation rel); +extern Relation get_rel_from_meta(RelationMetaData* frel); +extern bool CheckRelOrientationByPgClassTuple(HeapTuple tuple, TupleDesc tupdesc, const char* orientation); + +#endif // !FRONTEND_PARSER +#endif /* REL_GS_H */ + diff -uprN postgresql-hll-2.14_old/include/include/utils/rel.h postgresql-hll-2.14/include/include/utils/rel.h --- postgresql-hll-2.14_old/include/include/utils/rel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/rel.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,614 @@ +/* ------------------------------------------------------------------------- + * + * rel.h + * POSTGRES relation descriptor (a/k/a relcache entry) definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/rel.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REL_H +#define REL_H + +#include "access/tupdesc.h" +#include "catalog/pg_am.h" +#include "catalog/pg_class.h" +#include "catalog/pg_index.h" + + +#include "fmgr.h" +#include "nodes/bitmapset.h" +#include "nodes/nodes.h" +#ifdef PGXC +#include "pgxc/locator.h" +#endif +#include "rewrite/prs2lock.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "tcop/stmt_retry.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/reltrigger.h" +#include "utils/partitionmap.h" +#include "catalog/pg_hashbucket_fn.h" + + +#ifndef HDFS +#define HDFS "hdfs" +#endif +#ifndef OBS +#define OBS "obs" +#endif + +/* + * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient + * to declare them here so we can have a LockInfoData field in a Relation. + */ + +typedef struct LockRelId { + Oid relId; /* a relation identifier */ + Oid dbId; /* a database identifier */ + Oid bktId; /* a bucket identifier = bucketid + 1 */ +} LockRelId; + +typedef struct LockInfoData { + LockRelId lockRelId; +} LockInfoData; + +typedef LockInfoData* LockInfo; +#define InvalidLockRelId { InvalidOid, InvalidOid, InvalidOid} +#define LockRelIdIsInvalid(__lockrelid) (((__lockrelid).relId == InvalidOid) && ((__lockrelid).dbId == InvalidOid)) + +/* + * Cached lookup information for the index access method functions defined + * by the pg_am row associated with an index relation. + */ +typedef struct RelationAmInfo { + FmgrInfo aminsert; + FmgrInfo ambeginscan; + FmgrInfo amgettuple; + FmgrInfo amgetbitmap; + FmgrInfo amrescan; + FmgrInfo amendscan; + FmgrInfo ammarkpos; + FmgrInfo amrestrpos; + FmgrInfo ammerge; + FmgrInfo ambuild; + FmgrInfo ambuildempty; + FmgrInfo ambulkdelete; + FmgrInfo amvacuumcleanup; + FmgrInfo amcanreturn; + FmgrInfo amcostestimate; + FmgrInfo amoptions; +} RelationAmInfo; + +//describe bucket info of hash Bucketed-Table +typedef struct RelationBucketKey +{ + int2vector *bucketKey; /*bucket key*/ + Oid *bucketKeyType; /*the data type of partition key*/ +}RelationBucketKey; + +/* + * Here are the contents of a relation cache entry. + */ + +typedef struct RelationData { + + RelFileNode rd_node; /* relation physical identifier */ + /* use "struct" here to avoid needing to include smgr.h: */ + struct SMgrRelationData* rd_smgr; /* cached file handle, or NULL */ + int rd_refcnt; /* reference count */ + BackendId rd_backend; /* owning backend id, if temporary relation */ + bool rd_isscannable; /* rel can be scanned */ + bool rd_isnailed; /* rel is nailed in cache */ + bool rd_isvalid; /* relcache entry is valid */ + char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1 = + * valid, 2 = temporarily forced */ + bool rd_islocaltemp; /* rel is a temp rel of this session */ + + /* + * rd_createSubid is the ID of the highest subtransaction the rel has + * survived into; or zero if the rel was not created in the current top + * transaction. This should be relied on only for optimization purposes; + * it is possible for new-ness to be "forgotten" (eg, after CLUSTER). + * Likewise, rd_newRelfilenodeSubid is the ID of the highest + * subtransaction the relfilenode change has survived into, or zero if not + * changed in the current transaction (or we have forgotten changing it). + */ + SubTransactionId rd_createSubid; /* rel was created in current xact */ + SubTransactionId rd_newRelfilenodeSubid; /* new relfilenode assigned in + * current xact */ + + Form_pg_class rd_rel; /* RELATION tuple */ + TupleDesc rd_att; /* tuple descriptor */ + Oid rd_id; /* relation's object id */ + + LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */ + RuleLock* rd_rules; /* rewrite rules */ + MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */ + TriggerDesc* trigdesc; /* Trigger info, or NULL if rel has none */ + /* use "struct" here to avoid needing to include rewriteRlsPolicy.h */ + struct RlsPoliciesDesc* rd_rlsdesc; /* Row level security policies, or NULL */ + /* data managed by RelationGetIndexList: */ + List* rd_indexlist; /* list of OIDs of indexes on relation */ + Oid rd_oidindex; /* OID of unique index on OID, if any */ + Oid rd_refSynOid; /* OID of referenced synonym Oid, if mapping indeed. */ + + /* data managed by RelationGetIndexAttrBitmap: */ + Bitmapset* rd_indexattr; /* identifies columns used in indexes */ + Bitmapset* rd_idattr; /* included in replica identity index */ + + /* + * The index chosen as the relation's replication identity or + * InvalidOid. Only set correctly if RelationGetIndexList has been + * called/rd_indexvalid > 0. + */ + Oid rd_replidindex; + + /* + * rd_options is set whenever rd_rel is loaded into the relcache entry. + * Note that you can NOT look into rd_rel for this data. NULL means "use + * defaults". + */ + bytea* rd_options; /* parsed pg_class.reloptions */ + + /* These are non-NULL only for an index relation: */ + Oid rd_partHeapOid; /* partition index's partition oid */ + Form_pg_index rd_index; /* pg_index tuple describing this index */ + /* use "struct" here to avoid needing to include htup.h: */ + struct HeapTupleData* rd_indextuple; /* all of pg_index tuple */ + Form_pg_am rd_am; /* pg_am tuple for index's AM */ + int rd_indnkeyatts; /* index relation's indexkey nums */ + TableAmType rd_tam_type; /*Table accessor method type*/ + + /* + * index access support info (used only for an index relation) + * + * Note: only default support procs for each opclass are cached, namely + * those with lefttype and righttype equal to the opclass's opcintype. The + * arrays are indexed by support function number, which is a sufficient + * identifier given that restriction. + * + * Note: rd_amcache is available for index AMs to cache private data about + * an index. This must be just a cache since it may get reset at any time + * (in particular, it will get reset by a relcache inval message for the + * index). If used, it must point to a single memory chunk palloc'd in + * rd_indexcxt. A relcache reset will include freeing that chunk and + * setting rd_amcache = NULL. + */ + MemoryContext rd_indexcxt; /* private memory cxt for this stuff */ + RelationAmInfo* rd_aminfo; /* lookup info for funcs found in pg_am */ + Oid* rd_opfamily; /* OIDs of op families for each index col */ + Oid* rd_opcintype; /* OIDs of opclass declared input data types */ + RegProcedure* rd_support; /* OIDs of support procedures */ + FmgrInfo* rd_supportinfo; /* lookup info for support procedures */ + int16* rd_indoption; /* per-column AM-specific flags */ + List* rd_indexprs; /* index expression trees, if any */ + List* rd_indpred; /* index predicate tree, if any */ + Oid* rd_exclops; /* OIDs of exclusion operators, if any */ + Oid* rd_exclprocs; /* OIDs of exclusion ops' procs, if any */ + uint16* rd_exclstrats; /* exclusion ops' strategy numbers, if any */ + void* rd_amcache; /* available for use by index AM */ + Oid* rd_indcollation; /* OIDs of index collations */ + + /* + * foreign-table support + * + * rd_fdwroutine must point to a single memory chunk palloc'd in + * t_thrd.mem_cxt.cache_mem_cxt. It will be freed and reset to NULL on a relcache + * reset. + */ + + /* use "struct" here to avoid needing to include fdwapi.h: */ + struct FdwRoutine* rd_fdwroutine; /* cached function pointers, or NULL */ + + /* + * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new + * version of a table, we need to make any toast pointers inserted into it + * have the existing toast table's OID, not the OID of the transient toast + * table. If rd_toastoid isn't InvalidOid, it is the OID to place in + * toast pointers inserted into this rel. (Note it's set on the new + * version of the main heap, not the toast table itself.) This also + * causes toast_save_datum() to try to preserve toast value OIDs. + */ + Oid rd_toastoid; /* Real TOAST table's OID, or InvalidOid */ + Oid rd_bucketoid;/* bucket OID in pg_hashbucket*/ + + /*bucket key info, indicating which keys are used to comoute hash value */ + RelationBucketKey *rd_bucketkey; + + /* For 1-level hash table, it points into a HashBucketMap instances; + * For 2-level hash table, e.g. range-hash, it points into a RangePartitionMap + * instances. */ + + PartitionMap* partMap; + Oid parentId; /*if this is construct by partitionGetRelation,this is Partition Oid,else this is InvalidOid*/ + /* use "struct" here to avoid needing to include pgstat.h: */ + struct PgStat_TableStatus* pgstat_info; /* statistics collection area */ +#ifdef PGXC + RelationLocInfo* rd_locator_info; + PartitionMap* sliceMap; +#endif + Relation parent; + + /* double linked list node, partition and bucket relation would be stored in fakerels list of resource owner */ + dlist_node node; + + Oid rd_mlogoid; +} RelationData; + +/* + * StdRdOptions + * Standard contents of rd_options for heaps and generic indexes. + * + * RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only + * be applied to relations that use this format or a superset for + * private options data. + */ +/* autovacuum-related reloptions. */ +typedef struct AutoVacOpts { + bool enabled; + int vacuum_threshold; + int analyze_threshold; + int vacuum_cost_delay; + int vacuum_cost_limit; + int64 freeze_min_age; + int64 freeze_max_age; + int64 freeze_table_age; + float8 vacuum_scale_factor; + float8 analyze_scale_factor; +} AutoVacOpts; + +typedef enum RedisCtidType { REDIS_START_CTID = 0, REDIS_END_CTID } RedisCtidType; + +typedef enum RedisRelAction { + REDIS_REL_INVALID = -1, + REDIS_REL_NORMAL, + REDIS_REL_APPEND, + REDIS_REL_READ_ONLY, + REDIS_REL_END_CATCHUP, + REDIS_REL_REFRESH, + REDIS_REL_DESTINATION, + REDIS_REL_RESET_CTID +} RedisHtlAction; + +typedef struct StdRdOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int fillfactor; /* page fill factor in percent (0..100) */ + AutoVacOpts autovacuum; /* autovacuum-related options */ + bool security_barrier; /* for views */ + bool enable_rowsecurity; /* enable row level security or not */ + bool force_rowsecurity; /* force row level security or not */ + bool enable_tsdb_delta; /* enable delta table for timeseries relations */ + + int tsdb_deltamerge_interval; /* interval for tsdb delta merge job */ + int tsdb_deltamerge_threshold; /* data threshold for tsdb delta merge job */ + int tsdb_deltainsert_threshold; /* data threshold for tsdb delta insert */ + int max_batch_rows; /* the upmost rows at each batch inserting */ + int delta_rows_threshold; /* the upmost rows delta table holds */ + int partial_cluster_rows; /* row numbers of partial cluster feature */ + int compresslevel; /* compress level, see relation storage options 'compresslevel' */ + int internalMask; /*internal mask*/ + bool ignore_enable_hadoop_env; /* ignore enable_hadoop_env */ + bool user_catalog_table; /* use as an additional catalog relation */ + bool hashbucket; /* enable hash bucket for this relation */ + + /* info for redistribution */ + Oid rel_cn_oid; + RedisHtlAction append_mode_internal; + + // Important: + // for string type, data is appended at the tail of its parent struct. + // CHAR* member of this STRUCT stores the offset of its string data. + // offset=0 means that it's a NULL string. + // + // Take Care !!! + // CHAR* member CANNOT be accessed directly. + // StdRdOptionsGetStringData macro must be used for accessing CHAR* type member. + // + char* compression; /* compress or not compress */ + char* table_access_method; /*table access method kind */ + char* orientation; /* row-store or column-store */ + char* ttl; /* time to live for tsdb data management */ + char* period; /* partition range for tsdb data management */ + char* partition_interval; /* partition interval for streaming contquery table */ + char* time_column; /* time column for streaming contquery table */ + char* ttl_interval; /* ttl interval for streaming contquery table */ + char* gather_interval; /* gather interval for streaming contquery table */ + char* string_optimize; /* string optimize for streaming contquery table */ + char* version; + char* wait_clean_gpi; /* pg_partition system catalog wait gpi-clean or not */ + /* item for online expand */ + char* append_mode; + char* start_ctid_internal; + char* end_ctid_internal; + char *merge_list; + bool on_commit_delete_rows; /* global temp table */ +} StdRdOptions; + +#define HEAP_MIN_FILLFACTOR 10 +#define HEAP_DEFAULT_FILLFACTOR 100 + +/* + * RelationIsUsedAsCatalogTable + * Returns whether the relation should be treated as a catalog table + * from the pov of logical decoding. + */ +#define RelationIsUsedAsCatalogTable(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->user_catalog_table : false) + +#define RelationIsInternal(relation) (RelationGetInternalMask(relation) != INTERNAL_MASK_DISABLE) + +/* + * RelationGetFillFactor + * Returns the relation's fillfactor. Note multiple eval of argument! + */ +#define RelationGetFillFactor(relation, defaultff) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->fillfactor : (defaultff)) + +/* + * RelationGetTargetPageUsage + * Returns the relation's desired space usage per page in bytes. + */ +#define RelationGetTargetPageUsage(relation, defaultff) (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100) + +/* + * RelationGetTargetPageFreeSpace + * Returns the relation's desired freespace per page in bytes. + */ +#define RelationGetTargetPageFreeSpace(relation, defaultff) \ + (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100) + +/* + * RelationIsSecurityView + * Returns whether the relation is security view, or not + */ +#define RelationIsSecurityView(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->security_barrier : false) + +/* + * RelationIsValid + * True iff relation descriptor is valid. + */ +#define RelationIsValid(relation) PointerIsValid(relation) + +#define InvalidRelation ((Relation)NULL) + +/* + * RelationHasReferenceCountZero + * True iff relation reference count is zero. + * + * Note: + * Assumes relation descriptor is valid. + */ +#define RelationHasReferenceCountZero(relation) ((bool)((relation)->rd_refcnt == 0)) + +/* + * RelationGetForm + * Returns pg_class tuple for a relation. + * + * Note: + * Assumes relation descriptor is valid. + */ +#define RelationGetForm(relation) ((relation)->rd_rel) + +/* + * RelationGetRelid + * Returns the OID of the relation + */ +#define RelationGetRelid(relation) ((relation)->rd_id) + +#define RelationGetBktid(relation) ((relation)->rd_node.bucketNode) + +/* + * RelationGetNumberOfAttributes + * Returns the total number of attributes in a relation. + */ +#define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts) + +/* + * IndexRelationGetNumberOfAttributes + * Returns the number of attributes in an index. + */ +#define IndexRelationGetNumberOfAttributes(relation) ((relation)->rd_index->indnatts) + +/* + * IndexRelationGetNumberOfKeyAttributes + * Returns the number of key attributes in an index. + */ +#define IndexRelationGetNumberOfKeyAttributes(relation) \ + (AssertMacro((relation)->rd_indnkeyatts != 0), ((relation)->rd_indnkeyatts)) + + +/* + * RelationGetDescr + * Returns tuple descriptor for a relation. + */ +#define RelationGetDescr(relation) ((relation)->rd_att) + +/* + * RelationGetRelationName + * Returns the rel's name. + * + * Note that the name is only unique within the containing namespace. + */ +#define RelationGetRelationName(relation) (NameStr((relation)->rd_rel->relname)) + +#define PartitionGetPartitionName(partition) (NameStr((partition)->pd_part->relname)) + +#define RelationGetPartType(relation) ((relation)->rd_rel->parttype) + +/* + * RelationGetNamespace + * Returns the rel's namespace OID. + */ +#define RelationGetNamespace(relation) ((relation)->rd_rel->relnamespace) + +/* + * RelationIsMapped + * True if the relation uses the relfilenode map. + * + * NB: this is only meaningful for relkinds that have storage, else it + * will misleadingly say "true". + */ +#define RelationIsMapped(relation) ((relation)->rd_rel->relfilenode == InvalidOid) + +/* + * RelationOpenSmgr + * Open the relation at the smgr level, if not already done. + */ +#define RelationOpenSmgr(relation) \ + do { \ + if ((relation)->rd_smgr == NULL) { \ + oidvector* bucketlist = NULL; \ + if (RELATION_CREATE_BUCKET(relation)) { \ + bucketlist = searchHashBucketByOid(relation->rd_bucketoid); \ + } \ + smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node, (relation)->rd_backend, 0, bucketlist)); \ + } \ + } while (0) + +/* + * RelationCloseSmgr + * Close the relation at the smgr level, if not already done. + * + * Note: smgrclose should unhook from owner pointer, hence the Assert. + */ +#define RelationCloseSmgr(relation) \ + do { \ + if ((relation)->rd_smgr != NULL) { \ + smgrclose((relation)->rd_smgr); \ + Assert(RelationIsBucket(relation) || (relation)->rd_smgr == NULL); \ + } \ + } while (0) + +/* + * RelationGetTargetBlock + * Fetch relation's current insertion target block. + * + * Returns InvalidBlockNumber if there is no current target block. Note + * that the target block status is discarded on any smgr-level invalidation. + */ +#define RelationGetTargetBlock(relation) \ + ((relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber) + +/* + * RelationSetTargetBlock + * Set relation's current insertion target block. + */ +#define RelationSetTargetBlock(relation, targblock) \ + do { \ + RelationOpenSmgr(relation); \ + (relation)->rd_smgr->smgr_targblock = (targblock); \ + } while (0) + +/* + * RelationNeedsWAL + * True if relation needs WAL. + */ +#define RelationNeedsWAL(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT || \ + (((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP) && STMT_RETRY_ENABLED)) + +/* + * RelationUsesLocalBuffers + * True if relation's pages are stored in local buffers. + */ +#define RelationUsesLocalBuffers(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) +#define RelationIsLocalTemp(relation) \ + ((relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempNamespace || \ + (relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempToastNamespace) + +#define RelationIsRelation(relation) (RELKIND_RELATION == (relation)->rd_rel->relkind) + +#define isPartitionedRelation(classForm) (PARTTYPE_PARTITIONED_RELATION == (classForm)->parttype) + +#ifdef PGXC +/* + * RelationGetLocInfo + * Return the location info of relation + */ +#define RelationGetLocInfo(relation) ((relation)->rd_locator_info) +#endif + +/* + * RelationGetBucketKey + * Fetch relation's current bucket key. + * + * Returns NULL if there is no hash bucket in current Relation + */ +#define RelationGetBucketKey(relation) \ + ((relation)->rd_bucketkey != NULL) ? (relation)->rd_bucketkey->bucketKey : NULL + +/* + * RELATION_IS_LOCAL + * If a rel is either local temp or global temp relation + * or newly created in the current transaction, + * it can be assumed to be accessible only to the current backend. + * This is typically used to decide that we can skip acquiring locks. + * + * Beware of multiple eval of argument + */ +#define RELATION_IS_LOCAL(relation) \ + ((relation)->rd_islocaltemp || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP || \ + (relation)->rd_createSubid != InvalidSubTransactionId) + +/* + * RELATION_IS_TEMP + * Test a rel is either local temp relation of this session + * or global temp relation. + */ +#define RELATION_IS_TEMP(relation) \ + ((relation)->rd_islocaltemp || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) + +/* global temp table implementations */ +#define RELATION_IS_GLOBAL_TEMP(relation) \ + ((relation) != NULL && (relation)->rd_rel != NULL && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) + +#define RELATION_GTT_ON_COMMIT_DELETE(relation) \ + ((relation)->rd_options && (relation)->rd_rel->relkind == RELKIND_RELATION && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP ? \ + (reinterpret_cast((relation)->rd_options))->on_commit_delete_rows : false) + +#define RelationGetRelPersistence(relation) ((relation)->rd_rel->relpersistence) + +/* routines in utils/cache/relcache.c */ +extern void RelationIncrementReferenceCount(Relation rel); +extern void RelationDecrementReferenceCount(Relation rel); + +/* + * RelationIsAccessibleInLogicalDecoding + * True if we need to log enough information to have access via + * decoding snapshot. + */ +#define RelationIsAccessibleInLogicalDecoding(relation) \ + (XLogLogicalInfoActive() && RelationNeedsWAL(relation) && \ + (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) + +/* + * RelationIsLogicallyLogged + * True if we need to log enough information to extract the data from the + * WAL stream. + * + * We don't log information for unlogged tables (since they don't WAL log + * anyway) and for system tables (their content is hard to make sense of, and + * it would complicate decoding slightly for little gain). Note that we *do* + * log information for user defined catalog tables since they presumably are + * interesting to the user... + */ +#define RelationIsLogicallyLogged(relation) \ + (XLogLogicalInfoActive() && RelationNeedsWAL(relation) && !IsCatalogRelation(relation)) + +#endif /* REL_H */ + diff -uprN postgresql-hll-2.14_old/include/include/utils/relmapper.h postgresql-hll-2.14/include/include/utils/relmapper.h --- postgresql-hll-2.14_old/include/include/utils/relmapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/relmapper.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,94 @@ +/* ------------------------------------------------------------------------- + * + * relmapper.h + * Catalog-to-filenode mapping + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/relmapper.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELMAPPER_H +#define RELMAPPER_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* + * The map file is critical data: we have no automatic method for recovering + * from loss or corruption of it. We use a CRC so that we can detect + * corruption. To minimize the risk of failed updates, the map file should + * be kept to no more than one standard-size disk sector (ie 512 bytes), + * and we use overwrite-in-place rather than playing renaming games. + * The struct layout below is designed to occupy exactly 512 bytes, which + * might make filesystem updates a bit more efficient. + * + * Entries in the mappings[] array are in no particular order. We could + * speed searching by insisting on OID order, but it really shouldn't be + * worth the trouble given the intended size of the mapping sets. + */ +#define RELMAPPER_FILENAME "pg_filenode.map" +#define RELMAPPER_FILENAME_BAK "pg_filenode.map.backup" + +#define RELMAPPER_FILEMAGIC 0x592717 /* version ID value */ + +#define MAX_MAPPINGS 62 /* 62 * 8 + 16 = 512 */ + +typedef struct RelMapping { + Oid mapoid; /* OID of a catalog */ + Oid mapfilenode; /* its filenode number */ +} RelMapping; + +typedef struct RelMapFile { + int32 magic; /* always RELMAPPER_FILEMAGIC */ + int32 num_mappings; /* number of valid RelMapping entries */ + RelMapping mappings[MAX_MAPPINGS]; + int32 crc; /* CRC of all above */ + int32 pad; /* to make the struct size be 512 exactly */ +} RelMapFile; + +/* ---------------- + * relmap-related XLOG entries + * ---------------- + */ + +#define XLOG_RELMAP_UPDATE 0x00 + +typedef struct xl_relmap_update { + Oid dbid; /* database ID, or 0 for shared map */ + Oid tsid; /* database's tablespace, or pg_global */ + int32 nbytes; /* size of relmap data */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_relmap_update; + +#define MinSizeOfRelmapUpdate offsetof(xl_relmap_update, data) + +extern Oid RelationMapOidToFilenode(Oid relationId, bool shared); +extern Oid RelationMapFilenodeToOid(Oid relationId, bool shared); + +extern void RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, bool immediate); + +extern void RelationMapRemoveMapping(Oid relationId); + +extern void RelationMapInvalidate(bool shared); +extern void RelationMapInvalidateAll(void); + +extern void AtCCI_RelationMap(void); +extern void AtEOXact_RelationMap(bool isCommit); +extern void AtPrepare_RelationMap(void); + +extern void CheckPointRelationMap(void); + +extern void RelationMapFinishBootstrap(void); + +extern void RelationMapInitialize(void); +extern void RelationMapInitializePhase2(void); +extern void RelationMapInitializePhase3(void); + +extern void relmap_redo(XLogReaderState* record); +extern void relmap_desc(StringInfo buf, XLogReaderState* record); + +#endif /* RELMAPPER_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/reltrigger.h postgresql-hll-2.14/include/include/utils/reltrigger.h --- postgresql-hll-2.14_old/include/include/utils/reltrigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/reltrigger.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * reltrigger.h + * POSTGRES relation trigger definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/reltrigger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELTRIGGER_H +#define RELTRIGGER_H + +/* + * These struct really belongs to trigger.h, but we put it separately so that + * it can be cleanly included in rel.h and other places. + */ + +typedef struct Trigger { + Oid tgoid; /* OID of trigger (pg_trigger row) */ + /* Remaining fields are copied from pg_trigger, see pg_trigger.h */ + char* tgname; + Oid tgfoid; + uint16 tgtype; + char tgenabled; + bool tgisinternal; + Oid tgconstrrelid; + Oid tgconstrindid; + Oid tgconstraint; + bool tgdeferrable; + bool tginitdeferred; + int16 tgnargs; + int16 tgnattr; + int16* tgattr; + char** tgargs; + char* tgqual; + Oid tgowner; +} Trigger; + +typedef struct TriggerDesc { + Trigger* triggers; /* array of Trigger structs */ + int numtriggers; /* number of array entries */ + + /* + * These flags indicate whether the array contains at least one of each + * type of trigger. We use these to skip searching the array if not. + */ + bool trig_insert_before_row; + bool trig_insert_after_row; + bool trig_insert_instead_row; + bool trig_insert_before_statement; + bool trig_insert_after_statement; + bool trig_update_before_row; + bool trig_update_after_row; + bool trig_update_instead_row; + bool trig_update_before_statement; + bool trig_update_after_statement; + bool trig_delete_before_row; + bool trig_delete_after_row; + bool trig_delete_instead_row; + bool trig_delete_before_statement; + bool trig_delete_after_statement; + /* there are no row-level truncate triggers */ + bool trig_truncate_before_statement; + bool trig_truncate_after_statement; +} TriggerDesc; + +#endif /* RELTRIGGER_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/resowner.h postgresql-hll-2.14/include/include/utils/resowner.h --- postgresql-hll-2.14_old/include/include/utils/resowner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/resowner.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * resowner.h + * POSTGRES resource owner definitions. + * + * Query-lifespan resources are tracked by associating them with + * ResourceOwner objects. This provides a simple mechanism for ensuring + * that such resources are freed at the right time. + * See utils/resowner/README for more info. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/resowner.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RESOWNER_H +#define RESOWNER_H + +#include "storage/fd.h" +#include "utils/catcache.h" +#include "utils/plancache.h" +#include "utils/snapshot.h" +#include "utils/partcache.h" +#include "storage/cucache_mgr.h" + +/* + * ResourceOwner objects are an opaque data structure known only within + * resowner.c. + */ +typedef struct ResourceOwnerData* ResourceOwner; + +extern THR_LOCAL PGDLLIMPORT ResourceOwner IsolatedResourceOwner; + +/* + * Resource releasing is done in three phases: pre-locks, locks, and + * post-locks. The pre-lock phase must release any resources that are + * visible to other backends (such as pinned buffers); this ensures that + * when we release a lock that another backend may be waiting on, it will + * see us as being fully out of our transaction. The post-lock phase + * should be used for backend-internal cleanup. + */ +typedef enum { + RESOURCE_RELEASE_BEFORE_LOCKS, + RESOURCE_RELEASE_LOCKS, + RESOURCE_RELEASE_AFTER_LOCKS +} ResourceReleasePhase; + +/* + * Dynamically loaded modules can get control during ResourceOwnerRelease + * by providing a callback of this form. + */ +typedef void (*ResourceReleaseCallback)(ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void* arg); + +/* + * Functions in resowner.c + */ + +/* generic routines */ +extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char* name, MemoryGroupType memGroup); +extern void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel); +extern void ResourceOwnerDelete(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetNextChild(ResourceOwner owner); +extern const char * ResourceOwnerGetName(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetFirstChild(ResourceOwner owner); +extern void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent); +extern void RegisterResourceReleaseCallback(ResourceReleaseCallback callback, void* arg); +extern void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback, const void* arg); + +/* support for buffer refcount management */ +extern void ResourceOwnerEnlargeBuffers(ResourceOwner owner); +extern void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer); +extern void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer); + +/* support for catcache refcount management */ +extern void ResourceOwnerEnlargeCatCacheRefs(ResourceOwner owner); +extern void ResourceOwnerRememberCatCacheRef(ResourceOwner owner, HeapTuple tuple); +extern void ResourceOwnerForgetCatCacheRef(ResourceOwner owner, HeapTuple tuple); +extern void ResourceOwnerEnlargeCatCacheListRefs(ResourceOwner owner); +extern void ResourceOwnerRememberCatCacheListRef(ResourceOwner owner, CatCList* list); +extern void ResourceOwnerForgetCatCacheListRef(ResourceOwner owner, CatCList* list); + +/* support for relcache refcount management */ +extern void ResourceOwnerEnlargeRelationRefs(ResourceOwner owner); +extern void ResourceOwnerRememberRelationRef(ResourceOwner owner, Relation rel); +extern void ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel); +/* support for partcache refcount management */ +extern void ResourceOwnerEnlargePartitionRefs(ResourceOwner owner); + +extern void ResourceOwnerRememberPartitionRef(ResourceOwner owner, + Partition part); +extern void ResourceOwnerForgetPartitionRef(ResourceOwner owner, + Partition part); + +extern void ResourceOwnerRememberFakerelRef(ResourceOwner owner, Relation fakerel); +extern void ResourceOwnerForgetFakerelRef(ResourceOwner owner, Relation fakerel); + +/* support for fakepart refcount management */ +extern void ResourceOwnerEnlargeFakepartRefs(ResourceOwner owner); +extern void ResourceOwnerRememberFakepartRef(ResourceOwner owner, + Partition fakepart); +extern void ResourceOwnerForgetFakepartRef(ResourceOwner owner, + Partition fakerel); + +/* support for plancache refcount management */ +extern void ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner); +extern void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan* plan); +extern void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan* plan); + +/* support for tupledesc refcount management */ +extern void ResourceOwnerEnlargeTupleDescs(ResourceOwner owner); +extern void ResourceOwnerRememberTupleDesc(ResourceOwner owner, TupleDesc tupdesc); +extern void ResourceOwnerForgetTupleDesc(ResourceOwner owner, TupleDesc tupdesc); + +/* support for snapshot refcount management */ +extern void ResourceOwnerEnlargeSnapshots(ResourceOwner owner); +extern void ResourceOwnerRememberSnapshot(ResourceOwner owner, Snapshot snapshot); +extern void ResourceOwnerForgetSnapshot(ResourceOwner owner, Snapshot snapshot); +extern void ResourceOwnerDecrementNsnapshots(ResourceOwner owner, void* queryDesc); +extern void ResourceOwnerDecrementNPlanRefs(ResourceOwner owner, bool useResOwner); + +/* support for temporary file management */ +extern void ResourceOwnerEnlargeFiles(ResourceOwner owner); +extern void ResourceOwnerRememberFile(ResourceOwner owner, File file); +extern void ResourceOwnerForgetFile(ResourceOwner owner, File file); + +/* support for data cache refcount management */ +extern void ResourceOwnerEnlargeDataCacheSlot(ResourceOwner owner); +extern void ResourceOwnerRememberDataCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); +extern void ResourceOwnerForgetDataCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); + +/* support for meta cache refcount management */ +extern void ResourceOwnerEnlargeMetaCacheSlot(ResourceOwner owner); +extern void ResourceOwnerRememberMetaCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); +extern void ResourceOwnerForgetMetaCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); + +// support for pthread mutex +// +extern void ResourceOwnerForgetPthreadMutex(ResourceOwner owner, pthread_mutex_t* pMutex); + +extern void ResourceOwnerRememberPthreadMutex(ResourceOwner owner, pthread_mutex_t* pMutex); + +extern void ResourceOwnerEnlargePthreadMutex(ResourceOwner owner); + +extern void PrintPthreadMutexLeakWarning(pthread_mutex_t* pMutex); +extern void PrintResourceOwnerLeakWarning(); +extern void ResourceOwnerReleasePthreadMutex(); + +extern void ResourceOwnerEnlargePartitionMapRefs(ResourceOwner owner); +extern void ResourceOwnerRememberPartitionMapRef(ResourceOwner owner, PartitionMap* partmap); +extern void ResourceOwnerForgetPartitionMapRef(ResourceOwner owner, PartitionMap* partmap); + +#endif /* RESOWNER_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/rowstore.h postgresql-hll-2.14/include/include/utils/rowstore.h --- postgresql-hll-2.14_old/include/include/utils/rowstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/rowstore.h 2020-12-12 17:06:43.294348645 +0800 @@ -0,0 +1,168 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rowstore.h + * Generalized routines for buffer row storage rotine + * + * Description: Generalized data row store routines. + * + * What is row store? + * ------------------- + * Quite like tuple store, row store is for storing the row data(serialized + * tuple recieved from dn) and providing the disk swap ability. If the tuple + * size stored in RowStore exceeds the max memory allowed (work_mem), the + * following coming data will be written into disk. + * + * You might ask why don't we use tuple/batch store instead? + * (1) for performance. The tuple/batch store will de-serialize data when store + * the row data. That cause un-needed CPU overhead. That's why we have row store + * which have the ability to put the row data in its original format. + * (2) the tuple/batch store cannot store the nodeid of a row. + * + * + * The design of row store + * ------------------------ + * row store coming with the features such as + * (1) FIFO: which perserved data order. + * (2) DiskOnDemand: the comming data will be written to disk only when the + * memory is full. and unlike tuple/batch store all data(including the data + * in the memory) is written to disk, the rowstore only write those data + * who cannot fit into memory. + * (3) O(1) for read and write. The data row is directly read/write from/to the + * node's bank. Because we allocate a bank for each node. + * + * + * The internal of row store + * ------------------------ + * The data structure for the row store is as follows: + * + * [row store] + * bank[1]---->[m][m][m].....[m][d][d][d]......[d] + * bank[2]---->[m][m][m].....[m][d][d][d]......[d] + * bank[3]---->[m][m][m].....[m][d][d][d]......[d] + * bank[N]---->[m][m][m].....[m][d][d][d]......[d] + * *----in mem----*------in disk-----* + * + * The row store has many banks(NumDataNodes), each datanode has its own bank. + * Each bank contains many cells. The input data row is directed to its own + * bank based on the msgid, and append to the bank's cell list. If the bank + * has enough memory to hold the cell, the cell will be appeded to the in mem + * list, otherwise will be append to the in disk list. The cell will be compressed + * to save both memory and diskspace. + * + * Relation of structs + * ------------------------- + * RowStoreManager: holds all meta-data for a row store and have one bank for each datanode + * Bank: holds all cells of a given datanode + * RowStoreCell: each datarow convert to a cell and stored in bank + * + * introduce to the APIs + * ------------------------- + * First of all, have to invoke RowStoreAlloc() to initialize a RowStoreManager + * And then you can use RowStoreInsert() to insert DataRow into the RowStore. + * If the row store contains any data, you can use RowStoreFetch() to get the data + * in the row store. + * Finally, you have to invoke RowStoreDestory() to do the clean up work. + * + * IDENTIFICATION + * src/include/utils/rowstore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ROWSTORE_H +#define ROWSTORE_H + +#include "storage/buffile.h" +#include "utils/memprot.h" +#include "utils/memutils.h" +#include "pgxc/pgxcnode.h" + +#ifdef USE_ASSERT_CHECKING +#define CHECK_MEM(rs) MemoryContextCheck(rs->context, rs->context->session_id > 0) +#else +#define CHECK_MEM(rs) +#endif + +#define ROW_STORE_MAX_MEM \ + (u_sess->attr.attr_memory.work_mem * 1024L) /* use u_sess->attr.attr_memory.work_mem, default 64MB */ + +/* + * bank holds all cell of a given datanode + */ +typedef struct Bank { + List* mem; /* in memory list */ + BufFile* file; /* in disk list */ + size_t max_size; /* max memory allowed by this bank */ + size_t current_size; /* current memory allocated for this bank */ + int write_fileno; /* disk file no for write */ + off_t write_offset; /* file no offset for write */ + int read_fileno; /* disk file no for read */ + off_t read_offset; /* file no offset for read */ + int length; /* how many tuples stored in this bank */ +} Bank; + +/* + * each row convert to a cell and stored in the bank + */ +typedef struct RowStoreCellData { + char* msg; /* data row msg, might be compressed */ + int msglen; /* length of the data row message */ + int msgnode; /* node number of the data row message */ + int clen; /* compressed length of the msg */ +} RowStoreCellData; + +typedef RowStoreCellData* RowStoreCell; + +/* + * row store manager holds all meta-data for a row store. + */ +typedef struct RowStoreManagerData { + + MemoryContext context; /* memory context for the RowStore */ + + Bank** cn_banks; /* each coordinator has its own bank */ + int cn_bank_num; /* total number of cn_banks, should equal to NumCoordinates */ + + Bank** dn_banks; /* each datanode has its own bank */ + int dn_bank_num; /* total number of dn_banks, should equal to NumDataNodes */ +} RowStoreManagerData; + + +typedef RowStoreManagerData* RowStoreManager; + +/*===============API================*/ + +/* initialize a row store */ +extern RowStoreManager RowStoreAlloc(MemoryContext context, size_t max_size); + +/* insert a value into row store */ +extern void RowStoreInsert(RowStoreManager rs, RemoteDataRow data); + +/* fetch data row based on node id */ +extern bool RowStoreFetch(RowStoreManager rs, Oid nodeid, RemoteDataRow datarow); + +/* fetch data row */ +extern bool RowStoreFetch(RowStoreManager rs, RemoteDataRow datarow); + +/* get the length of row store */ +extern int RowStoreLen(RowStoreManager rs); + +/* reset a row store */ +extern void RowStoreReset(RowStoreManager rs); + +/* distory a row store */ +extern void RowStoreDestory(RowStoreManager rs); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/sec_rls_utils.h postgresql-hll-2.14/include/include/utils/sec_rls_utils.h --- postgresql-hll-2.14_old/include/include/utils/sec_rls_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/sec_rls_utils.h 2020-12-12 17:06:43.295348658 +0800 @@ -0,0 +1,119 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * sec_rls_utils.h + * Security Module. + * Utility commands used in Row Level Security Policy. + * + * + * IDENTIFICATION + * src/include/utils/sec_rls_utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef UTILS_SEC_RLS_UTILS_H +#define UTILS_SEC_RLS_UTILS_H + +#include "pgxc/pgxc.h" +/* + * If enable_rowsecurity for one relation is false then return RLS_DISABLED. + * If enable_rowsecurity for one relation is true, but current user can + * bypass the RLS policies for this relation, then return RLS_DEPEND to + * indicate that if the environment changes, we need to invalidate and + * replan. Finally, if enable_rowsecurity for one relation is true and + * current user can not bypss the RLS policies, then return RLS_ENABLED, + * which means we also need to invalidate if the environment changes. + */ +enum EnableRlsFeature { RLS_DISABLED, RLS_DEPEND, RLS_ENABLED }; + +/* + * SupportRlsOnCurrentNode + * Check whether support ddl(create, change, drop) operation or apply + * rls policy on current node(cn, dn, single_node). + * + * @return: support row level security on current node or not. + */ +inline bool SupportRlsOnCurrentNode() +{ + return (IS_PGXC_COORDINATOR || IS_SINGLE_NODE); +} + +/* + * RelationEnableRowSecurity + * Returns whether the relation enable row level security, or not + * + * @param (in) relation: Relation information. + * @return: enable row level security or not. + */ +inline bool RelationEnableRowSecurity(const Relation relation) +{ + /* Check whether support RLS on current node */ + if (SupportRlsOnCurrentNode() == false) { + return false; + } + /* Only check this option for normal relation */ + if (relation->rd_rel->relkind != RELKIND_RELATION) { + return false; + } + if (relation->rd_options != NULL) { + /* + * Only when relation is normal relation, rd_options + * can be casted to StdRdOptions type. Index has its + * own rd_options type, so it is dangerous to cast + * rd_options to StdRdOptions for index relation. + */ + StdRdOptions* rd_options = (StdRdOptions*)relation->rd_options; + return rd_options->enable_rowsecurity; + } + return false; +} + +/* + * RelationForceRowSecurity + * Returns whether the relation force row level security, or not + * + * @param (in) relation: Relation information. + * @return: force row level security or not. + */ +inline bool RelationForceRowSecurity(const Relation relation) +{ + /* Check whether support RLS on current node */ + if (SupportRlsOnCurrentNode() == false) { + return false; + } + /* Only check this option for normal relation */ + if (relation->rd_rel->relkind != RELKIND_RELATION) { + return false; + } + if (relation->rd_options != NULL) { + /* + * Only when relation is normal relation, rd_options + * can be casted to StdRdOptions type. Index has its + * own rd_options type, so it is dangerous to cast + * rd_options to StdRdOptions for index relation. + */ + StdRdOptions* rd_options = (StdRdOptions*)relation->rd_options; + return rd_options->force_rowsecurity; + } + return false; +} + +extern EnableRlsFeature CheckEnableRlsPolicies(const Relation relation, Oid roleid); +extern SelectStmt* MakeRlsSelectStmtForCopyTo(const Relation relation, const CopyStmt* stmt); +extern void LicenseSupportRls(); +extern void SupportRlsForRel(const Relation relation); + +#endif /* UTILS_SEC_RLS_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/selfuncs.h postgresql-hll-2.14/include/include/utils/selfuncs.h --- postgresql-hll-2.14_old/include/include/utils/selfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/selfuncs.h 2020-12-12 17:06:43.295348658 +0800 @@ -0,0 +1,262 @@ +/* ------------------------------------------------------------------------- + * + * selfuncs.h + * Selectivity functions and index cost estimation functions for + * standard operators and index access methods. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/selfuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SELFUNCS_H +#define SELFUNCS_H + +#include "fmgr.h" +#include "access/htup.h" +#include "nodes/relation.h" +#include "optimizer/nodegroups.h" + +/* + * Note: the default selectivity estimates are not chosen entirely at random. + * We want them to be small enough to ensure that indexscans will be used if + * available, for typical table densities of ~100 tuples/page. Thus, for + * example, 0.01 is not quite small enough, since that makes it appear that + * nearly all pages will be hit anyway. Also, since we sometimes estimate + * eqsel as 1/num_distinct, we probably want DEFAULT_NUM_DISTINCT to equal + * 1/DEFAULT_EQ_SEL. + */ + +/* default selectivity estimate for equalities such as "A = b" */ +#define DEFAULT_EQ_SEL 0.005 + +/* default selectivity estimate for inequalities such as "A < b" */ +#define DEFAULT_INEQ_SEL 0.3333333333333333 + +/* default selectivity estimate for range inequalities "A > b AND A < c" */ +#define DEFAULT_RANGE_INEQ_SEL 0.005 + +/* default selectivity estimate for pattern-match operators such as LIKE */ +#define DEFAULT_MATCH_SEL 0.005 + +/* default number of distinct values in a table */ +#define DEFAULT_NUM_DISTINCT 200 + +/* default number of rows */ +#define DEFAULT_NUM_ROWS 10 + +/* default number of distinct values and biase for the special expression */ +#define DEFAULT_SPECIAL_EXPR_DISTINCT 10 +#define DEFAULT_SPECIAL_EXPR_BIASE (pow(u_sess->pgxc_cxt.NumDataNodes, (double)1 / 2) / u_sess->pgxc_cxt.NumDataNodes) + +/* default selectivity estimate for boolean and null test nodes */ +#define DEFAULT_UNK_SEL 0.005 +#define DEFAULT_NOT_UNK_SEL (1.0 - DEFAULT_UNK_SEL) + +/* default selectivity estimate for neq anti join */ +#define MIN_NEQ_ANTI_SEL 0.05 +#define MAX_NEQ_SEMI_SEL (1.0 - MIN_NEQ_ANTI_SEL) + +/* If the selectivity is too high, we do not use POISSON to estimate the numbwe of distinct values */ +#define SELECTIVITY_THRESHOLD_TO_USE_POISSON 0.95 + +/* Estimate local distinct of join or agg after filter or join for scattered distribution. */ +#define NUM_DISTINCT_SELECTIVITY_FOR_POISSON(distinct, input_rows, selectivity) \ + (double)((distinct) * (1 - exp(-((input_rows) * (selectivity) / (distinct))))) + +/* Estimate distinct from global to local for scattered distribution. */ +#define NUM_DISTINCT_GTL_FOR_POISSON(gdistinct, input_rows, num_datanodes, dop) \ + (double)(NUM_DISTINCT_SELECTIVITY_FOR_POISSON(gdistinct, input_rows, 1.0 / num_datanodes / (dop))) + +/* Estimate thread distinct from dn distinct num. */ +#define NUM_PARALLEL_DISTINCT_GTL_FOR_POISSON(dn_distinct, dn_rows, dop) \ + (double)(NUM_DISTINCT_SELECTIVITY_FOR_POISSON(dn_distinct, dn_rows, 1.0 / (dop))) + +/* + * Clamp a computed probability estimate (which may suffer from roundoff or + * estimation errors) to valid range. Argument must be a float variable. + */ +#define CLAMP_PROBABILITY(p) \ + do { \ + if (p < 0.0) \ + p = 0.0; \ + else if (p > 1.0) \ + p = 1.0; \ + } while (0) + +/* Return data from examine_variable and friends */ +typedef struct VariableStatData { + Node* var; /* the Var or expression tree */ + RelOptInfo* rel; /* Relation, or NULL if not identifiable */ + HeapTuple statsTuple; /* pg_statistic tuple, or NULL if none */ + /* NB: if statsTuple!=NULL, it must be freed when caller is done */ + void (*freefunc)(HeapTuple tuple); /* how to free statsTuple */ + Oid vartype; /* exposed type of expression */ + Oid atttype; /* type to pass to get_attstatsslot */ + int32 atttypmod; /* typmod to pass to get_attstatsslot */ + bool isunique; /* matches unique index or DISTINCT clause */ + bool enablePossion; /* indentify we can use possion or not */ +} VariableStatData; + +#define ReleaseVariableStats(vardata) \ + do { \ + if (HeapTupleIsValid((vardata).statsTuple)) \ + (*(vardata).freefunc)((vardata).statsTuple); \ + } while (0) + +typedef enum { Pattern_Type_Like, Pattern_Type_Like_IC, Pattern_Type_Regex, Pattern_Type_Regex_IC } Pattern_Type; + +typedef enum { Pattern_Prefix_None, Pattern_Prefix_Partial, Pattern_Prefix_Exact } Pattern_Prefix_Status; + +typedef enum { STATS_TYPE_GLOBAL, STATS_TYPE_LOCAL } STATS_EST_TYPE; + +/* + * Helper routine for estimate_num_groups: add an item to a list of + * GroupVarInfos, but only if it's not known equal to any of the existing + * entries. + */ +typedef struct { + Node* var; /* might be an expression, not just a Var */ + RelOptInfo* rel; /* relation it belongs to */ + double ndistinct; /* # distinct values */ + bool isdefault; /* if estimated distinct value is default value */ + bool es_is_used; /* true if extended statistic is used*/ + Bitmapset* es_attnums; /* number of correlated attributes */ +} GroupVarInfo; + +extern void set_local_rel_size(PlannerInfo* root, RelOptInfo* rel); +extern double get_multiple_by_distkey(PlannerInfo* root, List* distkey, double rows); +extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Plan* plan, const double* numGroups); +extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Path* path, const double* numGroups); +extern void output_noanalyze_rellist_to_log(int lev); +extern void set_noanalyze_rellist(Oid relid, AttrNumber attid); +extern double estimate_local_numdistinct(PlannerInfo* root, Node* hashkey, Path* path, SpecialJoinInfo* sjinfo, + double* global_distinct, bool* isdefault, VariableStatData* vardata); +extern void get_num_distinct(PlannerInfo* root, List* groupExprs, double local_rows, double global_rows, + unsigned int num_datanodes, double* numdistinct, List** pgset = NULL); + +extern double get_local_rows(double global_rows, double multiple, bool replicate, unsigned int num_data_nodes); +extern double get_global_rows(double local_rows, double multiple, unsigned int num_data_nodes); + +#define PATH_LOCAL_ROWS(path) \ + get_local_rows( \ + (path)->rows, (path)->multiple, IsLocatorReplicated((path)->locator_type), ng_get_dest_num_data_nodes(path)) +#define PLAN_LOCAL_ROWS(plan) \ + get_local_rows( \ + (plan)->plan_rows, (plan)->multiple, (plan)->exec_type != EXEC_ON_DATANODES, ng_get_dest_num_data_nodes(plan)) +#define RELOPTINFO_LOCAL_FIELD(root, rel, fldname) \ + get_local_rows((rel)->fldname, \ + (rel)->multiple, \ + IsLocatorReplicated((rel)->locator_type), \ + ng_get_dest_num_data_nodes((root), (rel))) +#define IDXOPTINFO_LOCAL_FIELD(root, idx, fldname) \ + get_local_rows((idx)->fldname, \ + (idx)->rel->multiple, \ + IsLocatorReplicated((idx)->rel->locator_type), \ + ng_get_dest_num_data_nodes((root), (idx)->rel)) + +/* Functions in selfuncs.c */ + +extern void examine_variable(PlannerInfo* root, Node* node, int varRelid, VariableStatData* vardata); +extern bool get_restriction_variable( + PlannerInfo* root, List* args, int varRelid, VariableStatData* vardata, Node** other, bool* varonleft); +extern void get_join_variables(PlannerInfo* root, List* args, SpecialJoinInfo* sjinfo, VariableStatData* vardata1, + VariableStatData* vardata2, bool* join_is_reversed); +extern double get_variable_numdistinct(VariableStatData* vardata, bool* isdefault, bool adjust_rows = true, + double join_ratio = 1.0, SpecialJoinInfo* sjinfo = NULL, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL); +extern double mcv_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft, + double* sumcommonp, Oid equaloperator, bool* inmcv, double* lastcommonp = NULL); +extern double histogram_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft, + int min_hist_size, int n_skip, int* hist_size); + +extern Pattern_Prefix_Status pattern_fixed_prefix( + Const* patt, Pattern_Type ptype, Oid collation, Const** prefix, Selectivity* rest_selec); +extern Const* make_greater_string(const Const* str_const, FmgrInfo* ltproc, Oid collation); + +extern Datum eqsel(PG_FUNCTION_ARGS); +extern Datum neqsel(PG_FUNCTION_ARGS); +extern Datum scalarltsel(PG_FUNCTION_ARGS); +extern Datum scalargtsel(PG_FUNCTION_ARGS); +extern Datum regexeqsel(PG_FUNCTION_ARGS); +extern Datum icregexeqsel(PG_FUNCTION_ARGS); +extern Datum likesel(PG_FUNCTION_ARGS); +extern Datum iclikesel(PG_FUNCTION_ARGS); +extern Datum regexnesel(PG_FUNCTION_ARGS); +extern Datum icregexnesel(PG_FUNCTION_ARGS); +extern Datum nlikesel(PG_FUNCTION_ARGS); +extern Datum icnlikesel(PG_FUNCTION_ARGS); + +extern Datum eqjoinsel(PG_FUNCTION_ARGS); +extern Datum neqjoinsel(PG_FUNCTION_ARGS); +extern Datum scalarltjoinsel(PG_FUNCTION_ARGS); +extern Datum scalargtjoinsel(PG_FUNCTION_ARGS); +extern Datum regexeqjoinsel(PG_FUNCTION_ARGS); +extern Datum icregexeqjoinsel(PG_FUNCTION_ARGS); +extern Datum likejoinsel(PG_FUNCTION_ARGS); +extern Datum iclikejoinsel(PG_FUNCTION_ARGS); +extern Datum regexnejoinsel(PG_FUNCTION_ARGS); +extern Datum icregexnejoinsel(PG_FUNCTION_ARGS); +extern Datum nlikejoinsel(PG_FUNCTION_ARGS); +extern Datum icnlikejoinsel(PG_FUNCTION_ARGS); + +extern Selectivity booltestsel( + PlannerInfo* root, BoolTestType booltesttype, Node* arg, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern Selectivity nulltestsel( + PlannerInfo* root, NullTestType nulltesttype, Node* arg, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern Selectivity scalararraysel(PlannerInfo* root, ScalarArrayOpExpr* clause, bool is_join_clause, int varRelid, + JoinType jointype, SpecialJoinInfo* sjinfo); +extern int estimate_array_length(Node* arrayexpr); +extern Selectivity rowcomparesel( + PlannerInfo* root, RowCompareExpr* clause, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); + +extern void mergejoinscansel(PlannerInfo* root, Node* clause, Oid opfamily, int strategy, bool nulls_first, + Selectivity* leftstart, Selectivity* leftend, Selectivity* rightstart, Selectivity* rightend); + +extern double estimate_num_groups(PlannerInfo* root, List* groupExprs, double input_rows, unsigned int num_datanodes, + STATS_EST_TYPE eType = STATS_TYPE_GLOBAL, List** pgset = NULL); + +extern Selectivity estimate_hash_bucketsize( + PlannerInfo* root, Node* hashkey, double nbuckets, Path* inner_path, SpecialJoinInfo* sjinfo, double* distinctnum); + +extern Datum btcostestimate(PG_FUNCTION_ARGS); +extern Datum hashcostestimate(PG_FUNCTION_ARGS); +extern Datum gistcostestimate(PG_FUNCTION_ARGS); +extern Datum spgcostestimate(PG_FUNCTION_ARGS); +extern Datum gincostestimate(PG_FUNCTION_ARGS); +extern Datum psortcostestimate(PG_FUNCTION_ARGS); + +/* Functions in array_selfuncs.c */ + +extern Selectivity scalararraysel_containment( + PlannerInfo* root, Node* leftop, Node* rightop, Oid elemtype, bool isEquality, bool useOr, int varRelid); +extern Datum arraycontsel(PG_FUNCTION_ARGS); +extern Datum arraycontjoinsel(PG_FUNCTION_ARGS); + +/* the type for var data ratio we cached. */ +typedef enum { RatioType_Filter, RatioType_Join } RatioType; + +/* var ratio structure for one relation after join with other relation or filter by self. */ +typedef struct VarRatio { + RatioType ratiotype; /* filter ratio or join ratio. */ + Node* var; /* the var of local rel in restriction clause. */ + double ratio; /* identify joinratio or filterratio if after compute join selectivity, + others it means selectivity of filter. */ + Relids joinrelids; /* the joinrel relids. */ +} VarRatio; + +typedef struct VarEqRatio { + Var* var; /* the var of local rel in restriction clause. */ + double ratio; /* identify joinratio or filterratio if after compute join selectivity, + others it means selectivity of filter. */ + Relids joinrelids; /* the joinrel relids. */ +} VarEqRatio; + +extern void set_varratio_after_calc_selectivity( + VariableStatData* vardata, RatioType type, double ratio, SpecialJoinInfo* sjinfo); +extern double get_windowagg_selectivity(PlannerInfo* root, WindowClause* wc, WindowFunc* wfunc, List* partitionExprs, + int32 constval, double tuples, unsigned int num_datanodes); +extern bool contain_single_col_stat(List* stat_list); +#endif /* SELFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/snapmgr.h postgresql-hll-2.14/include/include/utils/snapmgr.h --- postgresql-hll-2.14_old/include/include/utils/snapmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/snapmgr.h 2020-12-12 17:06:43.295348658 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * snapmgr.h + * POSTGRES snapshot manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/snapmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNAPMGR_H +#define SNAPMGR_H + +#include "utils/resowner.h" +#include "utils/snapshot.h" +#include "access/transam.h" + +/* Static variables representing various special snapshot semantics */ +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotNowData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotSelfData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotAnyData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotToastData; + +#define SnapshotNow (&SnapshotNowData) +#define SnapshotSelf (&SnapshotSelfData) +#define SnapshotAny (&SnapshotAnyData) +#define SnapshotToast (&SnapshotToastData) + +#ifdef USE_ASSERT_CHECKING +#define LatestTransactionStatusError(xid, snapshot, action) PrintCurrentSnapshotInfo(PANIC, xid, snapshot, action) +#else +#define LatestTransactionStatusError(xid, snapshot, action) PrintCurrentSnapshotInfo(ERROR, xid, snapshot, action) +#endif + +extern bool XidVisibleInSnapshot(TransactionId xid, Snapshot snapshot, TransactionIdStatus *hintstatus, + Buffer buffer, bool *sync); +extern bool XidVisibleInLocalSnapshot(TransactionId xid, Snapshot snapshot); +extern bool CommittedXidVisibleInSnapshot(TransactionId xid, Snapshot snapshot, Buffer buffer); +extern bool IsXidVisibleInGtmLiteLocalSnapshot(TransactionId xid, Snapshot snapshot, TransactionIdStatus hint_status, + bool xmin_equal_xmax, Buffer buffer, bool *sync); +/* + * We don't provide a static SnapshotDirty variable because it would be + * non-reentrant. Instead, users of that snapshot type should declare a + * local variable of type SnapshotData, and initialize it with this macro. + */ +#define InitDirtySnapshot(snapshotdata) ((snapshotdata).satisfies = SNAPSHOT_DIRTY) + +/* This macro encodes the knowledge of which snapshots are MVCC-safe */ +#define IsMVCCSnapshot(snapshot) \ + ((((snapshot)->satisfies) == SNAPSHOT_MVCC) || (((snapshot)->satisfies) == SNAPSHOT_HISTORIC_MVCC)) + +extern Snapshot GetTransactionSnapshot(bool force_local_snapshot = false); +extern Snapshot GetLatestSnapshot(void); +extern Snapshot GetCatalogSnapshot(Oid relid); +extern void SnapshotSetCommandId(CommandId curcid); +extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid); + +extern void PushActiveSnapshot(Snapshot snapshot); +extern void PushCopiedSnapshot(Snapshot snapshot); +extern void UpdateActiveSnapshotCommandId(void); +extern void PopActiveSnapshot(void); +extern Snapshot GetActiveSnapshot(void); +extern bool ActiveSnapshotSet(void); + +extern Snapshot RegisterSnapshot(Snapshot snapshot); +extern void UnregisterSnapshot(Snapshot snapshot); +extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner); +extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner); +extern void RegisterStreamSnapshots(); +extern void ForgetRegisterStreamSnapshots(); + +extern void UnRegisterStreamSnapshots(); + +extern void AtSubCommit_Snapshot(int level); +extern void AtSubAbort_Snapshot(int level); +extern void AtEOXact_Snapshot(bool isCommit); + +extern Datum pg_export_snapshot(PG_FUNCTION_ARGS); +extern void ImportSnapshot(const char* idstr); +extern bool XactHasExportedSnapshots(void); +extern void DeleteAllExportedSnapshotFiles(void); + +extern void StreamTxnContextSaveSnapmgr(void* stc); +extern void StreamTxnContextRestoreSnapmgr(const void* stc); +extern void StreamTxnContextSetSnapShot(void* snapshotPtr); +extern bool ThereAreNoPriorRegisteredSnapshots(void); +extern Snapshot PgFdwCopySnapshot(Snapshot snapshot); +extern char* ExportSnapshot(Snapshot snapshot, CommitSeqNo *snapshotcsn); + +/* Support for catalog timetravel for logical decoding */ +struct HTAB; +extern struct HTAB* HistoricSnapshotGetTupleCids(void); +extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB* tuplecids); +extern void TeardownHistoricSnapshot(bool is_error); +extern bool HistoricSnapshotActive(void); +#endif /* SNAPMGR_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/snapshot.h postgresql-hll-2.14/include/include/utils/snapshot.h --- postgresql-hll-2.14_old/include/include/utils/snapshot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/snapshot.h 2020-12-12 17:06:43.295348658 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * snapshot.h + * POSTGRES snapshot definition + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/snapshot.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNAPSHOT_H +#define SNAPSHOT_H + +#include "access/htup.h" +#include "storage/buf.h" +#include "gtm/gtm_c.h" + +/* + * The different snapshot types. We use SnapshotData structures to represent + * both "regular" (MVCC) snapshots and "special" snapshots that have non-MVCC + * semantics. The specific semantics of a snapshot are encoded by its type. + * + * The behaviour of each type of snapshot should be documented alongside its + * enum value, best in terms that are not specific to an individual table AM. + * + * The reason the snapshot type rather than a callback as it used to be is + * that that allows to use the same snapshot for different table AMs without + * having one callback per AM. + */ +typedef enum SnapshotSatisfiesMethod +{ + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid for the given MVCC snapshot. + * + * Here, we consider the effects of: + * - all transactions committed as of the time of the given snapshot + * - previous commands of this transaction + * + * Does _not_ include: + * - transactions shown as in-progress by the snapshot + * - transactions started after the snapshot was taken + * - changes made by the current command + * ------------------------------------------------------------------------- + */ + SNAPSHOT_MVCC = 0, + + /* ------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid for the given local MVCC snapshot. + * + * Here, we consider the effects of: + * - all transactions local committed as of the time of the given snapshot + * - previous commands of this transaction + * + * Does _not_ include: + * - transactions committed in gtm but not committed locally + * - transactions shown as in-progress by the snapshot + * - transactions started after the snapshot was taken + * - changes made by the current command + * ------------------------------------------------------------------------- + */ + SNAPSHOT_LOCAL_MVCC, + + /* ------------------------------------------------------------------------- + * A tuple is visible iff heap tuple is valid "now". + * + * Here, we consider the effects of: + * - all committed transactions (as of the current instant) + * - previous commands of this transaction + * + * Does _not_ include: + * - changes made by the current command. + * ------------------------------------------------------------------------- + */ + SNAPSHOT_NOW, + + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid "for itself". + * + * Here, we consider the effects of: + * - all committed transactions (as of the current instant) + * - previous commands of this transaction + * - changes made by the current command + * + * Does _not_ include: + * - in-progress transactions (as of the current instant) + * ------------------------------------------------------------------------- + */ + SNAPSHOT_SELF, + + /* + * Any tuple is visible. + */ + SNAPSHOT_ANY, + + /* + * A tuple is visible iff the tuple is valid as a TOAST row. + */ + SNAPSHOT_TOAST, + + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid including effects of open + * transactions. + * + * Here, we consider the effects of: + * - all committed and in-progress transactions (as of the current instant) + * - previous commands of this transaction + * - changes made by the current command + * + * This is essentially like SNAPSHOT_SELF as far as effects of the current + * transaction and committed/aborted xacts are concerned. However, it + * also includes the effects of other xacts still in progress. + * + * A special hack is that when a snapshot of this type is used to + * determine tuple visibility, the passed-in snapshot struct is used as an + * output argument to return the xids of concurrent xacts that affected + * the tuple. snapshot->xmin is set to the tuple's xmin if that is + * another transaction that's still in progress; or to + * InvalidTransactionId if the tuple's xmin is committed good, committed + * dead, or my own xact. Similarly for snapshot->xmax and the tuple's + * xmax. If the tuple was inserted speculatively, meaning that the + * inserter might still back down on the insertion without aborting the + * whole transaction, the associated token is also returned in + * snapshot->speculativeToken. See also InitDirtySnapshot(). + * ------------------------------------------------------------------------- + */ + SNAPSHOT_DIRTY, + + /* + * A tuple is visible iff it follows the rules of SNAPSHOT_MVCC, but + * supports being called in timetravel context (for decoding catalog + * contents in the context of logical decoding). + */ + SNAPSHOT_HISTORIC_MVCC, +} SnapshotSatisfiesMethod; + +typedef struct SnapshotData* Snapshot; + +#define InvalidSnapshot ((Snapshot)NULL) + +/* + * Struct representing all kind of possible snapshots. + * + * There are several different kinds of snapshots: + * * Normal MVCC snapshots + * * MVCC snapshots taken during recovery (in Hot-Standby mode) + * * Historic MVCC snapshots used during logical decoding + * * snapshots passed to HeapTupleSatisfiesDirty() + * * snapshots used for SatisfiesAny, Toast, Self where no members are + * accessed. + * + * It's probably a good idea to split this struct using a NodeTag + * similar to how parser and executor nodes are handled, with one type for + * each different kind of snapshot to avoid overloading the meaning of + * individual fields. + */ + +typedef struct SnapshotData { + SnapshotSatisfiesMethod satisfies; /* satisfies type. */ + + /* + * The remaining fields are used only for MVCC snapshots, and are normally + * just zeroes in special snapshots. (But xmin and xmax are used + * specially by HeapTupleSatisfiesDirty.) + * + * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see + * the effects of all older XIDs except those listed in the snapshot. xmin + * is stored as an optimization to avoid needing to search the XID arrays + * for most tuples. + */ + TransactionId xmin; /* all XID < xmin are visible to me */ + TransactionId xmax; /* all XID >= xmax are invisible to me */ + /* + * For normal MVCC snapshot this contains the all xact IDs that are in + * progress, unless the snapshot was taken during recovery in which case + * it's empty. For historic MVCC snapshots, the meaning is inverted, + * i.e. it contains *committed* transactions between xmin and xmax. + */ + TransactionId* xip; + /* + * For non-historic MVCC snapshots, this contains subxact IDs that are in + * progress (and other transactions that are in progress if taken during + * recovery). For historic snapshot it contains *all* xids assigned to the + * replayed transaction, including the toplevel xid. + */ + TransactionId* subxip; + + uint32 xcnt; /* # of xact ids in xip[] */ + GTM_Timeline timeline; /* GTM timeline */ +#ifdef PGXC /* PGXC_COORD */ + uint32 max_xcnt; /* Max # of xact in xip[] */ +#endif + /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */ + int32 subxcnt; /* # of xact ids in subxip[] */ + int32 maxsubxcnt; /* # max xids could store in subxip[] */ + bool suboverflowed; /* has the subxip array overflowed? */ + + /* + * This snapshot can see the effects of all transactions with CSN <= + * snapshotcsn. + */ + CommitSeqNo snapshotcsn; + + /* For GTMLite local snapshot, we keep an array of prepared transaction xids for MVCC */ + int prepared_array_capacity; + int prepared_count; + TransactionId* prepared_array; + + bool takenDuringRecovery; /* recovery-shaped snapshot? */ + bool copied; /* false if it's a static snapshot */ + + /* + * note: all ids in subxip[] are >= xmin, but we don't bother filtering + * out any that are >= xmax + */ + CommandId curcid; /* in my xact, CID < curcid are visible */ + uint32 active_count; /* refcount on ActiveSnapshot stack */ + uint32 regd_count; /* refcount on RegisteredSnapshotList */ + void* user_data; /* for local multiversion snapshot */ + GTM_SnapshotType gtm_snapshot_type; +} SnapshotData; + +/* + * Result codes for AM API tuple_{update,delete,lock}, and for visibility. + */ +typedef enum TM_Result +{ + /* + * Signals that the action succeeded (i.e. update/delete performed, lock + * was acquired) + */ + TM_Ok, + + /* The affected tuple wasn't visible to the relevant snapshot */ + TM_Invisible, + + /* The affected tuple was already modified by the calling backend */ + TM_SelfModified, + + /* + * The affected tuple was updated by another transaction. + */ + TM_Updated, + + /* The affected tuple was deleted by another transaction */ + TM_Deleted, + + /* + * The affected tuple is currently being modified by another session. This + * will only be returned if (update/delete/lock)_tuple are instructed not + * to wait. + */ + TM_BeingModified, + TM_SelfCreated, + TM_SelfUpdated +} TM_Result; + +#endif /* SNAPSHOT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/sortsupport_gs.h postgresql-hll-2.14/include/include/utils/sortsupport_gs.h --- postgresql-hll-2.14_old/include/include/utils/sortsupport_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/sortsupport_gs.h 2020-12-12 17:06:43.295348658 +0800 @@ -0,0 +1,91 @@ +/* --------------------------------------------------------------------------------------- + * + * sortsupport_gs.h + * Framework for accelerated sorting. + * + * Traditionally, PostgreSQL has implemented sorting by repeatedly invoking + * an SQL-callable comparison function "cmp(x, y) returns int" on pairs of + * values to be compared, where the comparison function is the BTORDER_PROC + * pg_amproc support function of the appropriate btree index opclass. + * + * This file defines alternative APIs that allow sorting to be performed with + * reduced overhead. To support lower-overhead sorting, a btree opclass may + * provide a BTSORTSUPPORT_PROC pg_amproc entry, which must take a single + * argument of type internal and return void. The argument is actually a + * pointer to a SortSupportData struct, which is defined below. + * + * If provided, the BTSORTSUPPORT function will be called during sort setup, + * and it must initialize the provided struct with pointers to function(s) + * that can be called to perform sorting. This API is defined to allow + * multiple acceleration mechanisms to be supported, but no opclass is + * required to provide all of them. The BTSORTSUPPORT function should + * simply not set any function pointers for mechanisms it doesn't support. + * (However, all opclasses that provide BTSORTSUPPORT are required to provide + * the comparator function.) + * + * All sort support functions will be passed the address of the + * SortSupportData struct when called, so they can use it to store + * additional private data as needed. In particular, for collation-aware + * datatypes, the ssup_collation field is set before calling BTSORTSUPPORT + * and is available to all support functions. Additional opclass-dependent + * data can be stored using the ssup_extra field. Any such data + * should be allocated in the ssup_cxt memory context. + * + * Note: since pg_amproc functions are indexed by (lefttype, righttype) + * it is possible to associate a BTSORTSUPPORT function with a cross-type + * comparison. This could sensibly be used to provide a fast comparator + * function for such cases, but probably not any other acceleration method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/sortsupport_gs.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SORTSUPPORT_GS_H +#define SORTSUPPORT_GS_H + +#include "access/attnum.h" + +/* ApplySortComparator should be inlined if possible */ +#ifdef USE_INLINE + +/* + * Apply a sort comparator function and return a 3-way comparison using full, + * authoritative comparator. This takes care of handling reverse-sort and + * NULLs-ordering properly. + */ +static inline int ApplySortAbbrevFullComparator( + Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup) +{ + int compare; + + if (isNull1) { + if (isNull2) + compare = 0; /* NULL "=" NULL */ + else if (ssup->ssup_nulls_first) + compare = -1; /* NULL "<" NOT_NULL */ + else + compare = 1; /* NULL ">" NOT_NULL */ + } else if (isNull2) { + if (ssup->ssup_nulls_first) + compare = 1; /* NOT_NULL ">" NULL */ + else + compare = -1; /* NOT_NULL "<" NULL */ + } else { + compare = (*ssup->abbrev_full_comparator)(datum1, datum2, ssup); + if (ssup->ssup_reverse) + compare = -compare; + } + + return compare; +} +#else +extern int ApplySortAbbrevFullComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup); +#endif /* USE_INLINE */ + +#endif /* SORTSUPPORT_GS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/utils/sortsupport.h postgresql-hll-2.14/include/include/utils/sortsupport.h --- postgresql-hll-2.14_old/include/include/utils/sortsupport.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/sortsupport.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,228 @@ +/* ------------------------------------------------------------------------- + * + * sortsupport.h + * Framework for accelerated sorting. + * + * Traditionally, PostgreSQL has implemented sorting by repeatedly invoking + * an SQL-callable comparison function "cmp(x, y) returns int" on pairs of + * values to be compared, where the comparison function is the BTORDER_PROC + * pg_amproc support function of the appropriate btree index opclass. + * + * This file defines alternative APIs that allow sorting to be performed with + * reduced overhead. To support lower-overhead sorting, a btree opclass may + * provide a BTSORTSUPPORT_PROC pg_amproc entry, which must take a single + * argument of type internal and return void. The argument is actually a + * pointer to a SortSupportData struct, which is defined below. + * + * If provided, the BTSORTSUPPORT function will be called during sort setup, + * and it must initialize the provided struct with pointers to function(s) + * that can be called to perform sorting. This API is defined to allow + * multiple acceleration mechanisms to be supported, but no opclass is + * required to provide all of them. The BTSORTSUPPORT function should + * simply not set any function pointers for mechanisms it doesn't support. + * (However, all opclasses that provide BTSORTSUPPORT are required to provide + * the comparator function.) + * + * All sort support functions will be passed the address of the + * SortSupportData struct when called, so they can use it to store + * additional private data as needed. In particular, for collation-aware + * datatypes, the ssup_collation field is set before calling BTSORTSUPPORT + * and is available to all support functions. Additional opclass-dependent + * data can be stored using the ssup_extra field. Any such data + * should be allocated in the ssup_cxt memory context. + * + * Note: since pg_amproc functions are indexed by (lefttype, righttype) + * it is possible to associate a BTSORTSUPPORT function with a cross-type + * comparison. This could sensibly be used to provide a fast comparator + * function for such cases, but probably not any other acceleration method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/sortsupport.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SORTSUPPORT_H +#define SORTSUPPORT_H + +#include "access/attnum.h" + +typedef struct SortSupportData* SortSupport; + +typedef struct SortSupportData { + /* + * These fields are initialized before calling the BTSORTSUPPORT function + * and should not be changed later. + */ + MemoryContext ssup_cxt; /* Context containing sort info */ + Oid ssup_collation; /* Collation to use, or InvalidOid */ + + /* + * Additional sorting parameters; but unlike ssup_collation, these can be + * changed after BTSORTSUPPORT is called, so don't use them in selecting + * sort support functions. + */ + bool ssup_reverse; /* descending-order sort? */ + bool ssup_nulls_first; /* sort nulls first? */ + + /* + * These fields are workspace for callers, and should not be touched by + * opclass-specific functions. + */ + AttrNumber ssup_attno; /* column number to sort */ + + /* + * ssup_extra is zeroed before calling the BTSORTSUPPORT function, and is + * not touched subsequently by callers. + */ + void* ssup_extra; /* Workspace for opclass functions */ + + /* + * Function pointers are zeroed before calling the BTSORTSUPPORT function, + * and must be set by it for any acceleration methods it wants to supply. + * The comparator pointer must be set, others are optional. + */ + + /* + * Comparator function has the same API as the traditional btree + * comparison function, ie, return <0, 0, or >0 according as x is less + * than, equal to, or greater than y. Note that x and y are guaranteed + * not null, and there is no way to return null either. Do not return + * INT_MIN, as callers are allowed to negate the result before using it. + * + * This may be either the authoritative comparator, or the abbreviated + * comparator. Core code may switch this over the initial preference of an + * opclass support function despite originally indicating abbreviation was + * applicable, by assigning the authoritative comparator back. + */ + int (*comparator)(Datum x, Datum y, SortSupport ssup); + + /* + * "Abbreviated key" infrastructure follows. + * + * All callbacks must be set by sortsupport opclasses that make use of this + * optional additional infrastructure (unless for whatever reasons the + * opclass doesn't proceed with abbreviation, in which case + * abbrev_converter must not be set). + * + * This allows opclass authors to supply a conversion routine, used to + * create an alternative representation of the underlying type (an + * "abbreviated key"). Typically, this representation is an ad-hoc, + * pass-by-value Datum format that only the opclass has knowledge of. An + * alternative comparator, used only with this alternative representation + * must also be provided (which is assigned to "comparator"). This + * representation is a simple approximation of the original Datum. It must + * be possible to compare datums of this representation with each other + * using the supplied alternative comparator, and have any non-zero return + * value be a reliable proxy for what a proper comparison would indicate. + * Returning zero from the alternative comparator does not indicate + * equality, as with a conventional support routine 1, though -- it + * indicates that it wasn't possible to determine how the two abbreviated + * values compared. A proper comparison, using "abbrev_full_comparator"/ + * ApplySortAbbrevFullComparator() is therefore required. In many cases + * this results in most or all comparisons only using the cheap alternative + * comparison func, which is typically implemented as code that compiles to + * just a few CPU instructions. CPU cache miss penalties are expensive; to + * get good overall performance, sort infrastructure must heavily weigh + * cache performance. + * + * Opclass authors must consider the final cardinality of abbreviated keys + * when devising an encoding scheme. It's possible for a strategy to work + * better than an alternative strategy with one usage pattern, while the + * reverse might be true for another usage pattern. All of these factors + * must be considered. + */ + + /* + * "abbreviate" concerns whether or not the abbreviated key optimization is + * applicable in principle (that is, the sortsupport routine needs to know + * if its dealing with a key where an abbreviated representation can + * usefully be packed together. Conventionally, this is the leading + * attribute key). Note, however, that in order to determine that + * abbreviation is not in play, the core code always checks whether or not + * the opclass has set abbrev_converter. This is a one way, one time + * message to the opclass. + */ + bool abbreviate; + + /* + * Converter to abbreviated format, from original representation. Core + * code uses this callback to convert from a pass-by-reference "original" + * Datum to a pass-by-value abbreviated key Datum. Note that original is + * guaranteed NOT NULL, because it doesn't make sense to factor NULLness + * into ad-hoc cost model. + * + * abbrev_converter is tested to see if abbreviation is in play. Core code + * may set it to NULL to indicate abbreviation should not be used (which is + * something sortsupport routines need not concern themselves with). + * However, sortsupport routines must not set it when it is immediately + * established that abbreviation should not proceed (for abbreviation + * calls, or platform-specific impediments to using abbreviation). + */ + Datum (*abbrev_converter)(Datum original, SortSupport ssup); + + /* + * abbrev_abort callback allows clients to verify that the current strategy + * is working out, using a sortsupport routine defined ad-hoc cost model. + * If there is a lot of duplicate abbreviated keys in practice, it's useful + * to be able to abandon the strategy before paying too high a cost in + * conversion (perhaps certain opclass-specific adaptations are useful + * too). + */ + bool (*abbrev_abort)(int memtupcount, SortSupport ssup); + + /* + * Full, authoritative comparator for key that an abbreviated + * representation was generated for, used when an abbreviated comparison + * was inconclusive (by calling ApplySortComparatorFull()), or used to + * replace "comparator" when core system ultimately decides against + * abbreviation. + */ + int (*abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup); +} SortSupportData; + +/* ApplySortComparator should be inlined if possible */ +#ifdef USE_INLINE + +/* + * Apply a sort comparator function and return a 3-way comparison result. + * This takes care of handling reverse-sort and NULLs-ordering properly. + */ +static inline int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup) +{ + int compare; + + if (isNull1) { + if (isNull2) + compare = 0; /* NULL "=" NULL */ + else if (ssup->ssup_nulls_first) + compare = -1; /* NULL "<" NOT_NULL */ + else + compare = 1; /* NULL ">" NOT_NULL */ + } else if (isNull2) { + if (ssup->ssup_nulls_first) + compare = 1; /* NOT_NULL ">" NULL */ + else + compare = -1; /* NOT_NULL "<" NULL */ + } else { + compare = (*ssup->comparator)(datum1, datum2, ssup); + if (ssup->ssup_reverse) + compare = -compare; + } + + return compare; +} + +#else + +extern int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup); + +#endif /* USE_INLINE */ + +/* Other functions in utils/sort/sortsupport.c */ +extern void PrepareSortSupportComparisonShim(Oid cmpFunc, SortSupport ssup); +extern void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup); + +#endif /* SORTSUPPORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/spccache.h postgresql-hll-2.14/include/include/utils/spccache.h --- postgresql-hll-2.14_old/include/include/utils/spccache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/spccache.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,18 @@ +/* ------------------------------------------------------------------------- + * + * spccache.h + * Tablespace cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/spccache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPCCACHE_H +#define SPCCACHE_H + +void get_tablespace_page_costs(Oid spcid, float8* spc_random_page_cost, float8* spc_seq_page_cost); + +#endif /* SPCCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/syscache.h postgresql-hll-2.14/include/include/utils/syscache.h --- postgresql-hll-2.14_old/include/include/utils/syscache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/syscache.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------- + * + * syscache.h + * System catalog cache definitions. + * + * See also lsyscache.h, which provides convenience routines for + * common cache-lookup operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/syscache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SYSCACHE_H +#define SYSCACHE_H + +#include "utils/catcache.h" + +/* + * SysCache identifiers. + * + * The order of these identifiers must match the order + * of the entries in the array cacheinfo[] in syscache.c. + * Keep them in alphabetical order (renumbering only costs a + * backend rebuild). + */ +#define STATRELATTINH STATRELKINDATTINH + +enum SysCacheIdentifier { + AGGFNOID = 0, + AMNAME, + AMOID, + AMOPOPID, + AMOPSTRATEGY, + AMPROCNUM, + ATTNAME, + ATTNUM, + AUTHMEMMEMROLE, + AUTHMEMROLEMEM, + AUTHNAME, + AUTHOID, + BUCKETRELID, + CASTSOURCETARGET, + CEOID, + CERELIDCOUMNNAME, + CLAAMNAMENSP, + CLAOID, + COLLNAMEENCNSP, + COLLOID, + COLUMNSETTINGDISTID, + COLUMNSETTINGNAME, + COLUMNSETTINGOID, + CONDEFAULT, + CONNAMENSP, + CONSTROID, + CONVOID, + DATABASEOID, + DATASOURCENAME, + DATASOURCEOID, + DEFACLROLENSPOBJ, + DIRECTORYNAME, + DIRECTORYOID, + ENUMOID, + ENUMTYPOIDNAME, + FOREIGNDATAWRAPPERNAME, + FOREIGNDATAWRAPPEROID, + FOREIGNSERVERNAME, + FOREIGNSERVEROID, + FOREIGNTABLEREL, + GLOBALSETTINGNAME, + GLOBALSETTINGOID, + INDEXRELID, + LANGNAME, + LANGOID, + OPTMODEL, + NAMESPACENAME, + NAMESPACEOID, + OPERNAMENSP, + OPEROID, + OPFAMILYAMNAMENSP, + OPFAMILYOID, + PARTRELID, + PARTPARTOID, + PGJOBID, + PGJOBPROCID, + PGOBJECTID, +#ifdef PGXC + PGXCCLASSRELID, + PGXCGROUPNAME, + PGXCGROUPOID, + PGXCNODENAME, + PGXCNODEOID, + PGXCNODEIDENTIFIER, + PGXCRESOURCEPOOLNAME, + PGXCRESOURCEPOOLOID, + PGXCWORKLOADGROUPNAME, + PGXCWORKLOADGROUPOID, + PGXCAPPWGMAPPINGNAME, + PGXCAPPWGMAPPINGOID, + PGXCSLICERELID, +#endif + POLICYLABELNAME, + POLICYLABELOID, + PROCNAMEARGSNSP, + PROCOID, + RANGETYPE, + RELNAMENSP, + RELOID, + RULERELNAME, + STATRELKINDATTINH, /* single column statistics */ + STATRELKINDKEYINH, /* multi column statistics */ + STREAMCQDEFRELID, + STREAMCQID, + STREAMCQLOOKUPID, + STREAMCQMATRELID, + STREAMCQOID, + STREAMCQRELID, + STREAMCQSCHEMACHANGE, + STREAMOID, + STREAMRELID, + REAPERCQOID, + REAPERSTATUSOID, + SYNOID, + SYNONYMNAMENSP, + TABLESPACEOID, + TSCONFIGMAP, + TSCONFIGNAMENSP, + TSCONFIGOID, + TSDICTNAMENSP, + TSDICTOID, + TSPARSERNAMENSP, + TSPARSEROID, + TSTEMPLATENAMENSP, + TSTEMPLATEOID, + TYPENAMENSP, + TYPEOID, + USERMAPPINGOID, + USERMAPPINGUSERSERVER, + USERSTATUSOID, + USERSTATUSROLEID, + STREAMINGGATHERAGGOID +}; + +extern int SysCacheSize; + +extern void InitCatalogCache(void); +extern void InitCatalogCachePhase2(void); + +extern HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4, int level = DEBUG2); +/* + * The use of argument specific numbers is encouraged. They're faster, andTENAMENSP,TENAMENSP, + * insulates the caller from changes in the maximum number of keys. + */ +extern HeapTuple SearchSysCache1(int cacheId, Datum key1); +extern HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2); +extern HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3); +extern HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +extern void ReleaseSysCache(HeapTuple tuple); + +/* convenience routines */ +extern HeapTuple SearchSysCacheCopy(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4, int level = DEBUG2); +extern bool SearchSysCacheExists(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); +extern Oid GetSysCacheOid(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +extern HeapTuple SearchSysCacheAttName(Oid relid, const char* attname); +extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char* attname); +extern bool SearchSysCacheExistsAttName(Oid relid, const char* attname); + +extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool* isNull); + +extern uint32 GetSysCacheHashValue(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +/* list-search interface. Users of this must import catcache.h too */ +extern struct catclist* SearchSysCacheList(int cacheId, int nkeys, Datum key1, Datum key2, Datum key3, Datum key4); + +/* + * The use of the macros below rather than direct calls to the corresponding + * functions is encouraged, as it insulates the caller from changes in the + * maximum number of keys. + */ +#define SearchSysCache1WithLogLevel(cacheId, key1, level) SearchSysCache(cacheId, key1, 0, 0, 0, level) + +#define SearchSysCacheCopy1(cacheId, key1) SearchSysCacheCopy(cacheId, key1, 0, 0, 0) +#define SearchSysCacheCopy2(cacheId, key1, key2) SearchSysCacheCopy(cacheId, key1, key2, 0, 0) +#define SearchSysCacheCopy3(cacheId, key1, key2, key3) SearchSysCacheCopy(cacheId, key1, key2, key3, 0) +#define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) SearchSysCacheCopy(cacheId, key1, key2, key3, key4) +#define SearchSysCacheCopyWithLogLevel(cacheId, key1, level) SearchSysCacheCopy(cacheId, key1, 0, 0, 0, level) + +#define SearchSysCacheExists1(cacheId, key1) SearchSysCacheExists(cacheId, key1, 0, 0, 0) +#define SearchSysCacheExists2(cacheId, key1, key2) SearchSysCacheExists(cacheId, key1, key2, 0, 0) +#define SearchSysCacheExists3(cacheId, key1, key2, key3) SearchSysCacheExists(cacheId, key1, key2, key3, 0) +#define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) SearchSysCacheExists(cacheId, key1, key2, key3, key4) + +#define GetSysCacheOid1(cacheId, key1) GetSysCacheOid(cacheId, key1, 0, 0, 0) +#define GetSysCacheOid2(cacheId, key1, key2) GetSysCacheOid(cacheId, key1, key2, 0, 0) +#define GetSysCacheOid3(cacheId, key1, key2, key3) GetSysCacheOid(cacheId, key1, key2, key3, 0) +#define GetSysCacheOid4(cacheId, key1, key2, key3, key4) GetSysCacheOid(cacheId, key1, key2, key3, key4) + +#define GetSysCacheHashValue1(cacheId, key1) GetSysCacheHashValue(cacheId, key1, 0, 0, 0) +#define GetSysCacheHashValue2(cacheId, key1, key2) GetSysCacheHashValue(cacheId, key1, key2, 0, 0) +#define GetSysCacheHashValue3(cacheId, key1, key2, key3) GetSysCacheHashValue(cacheId, key1, key2, key3, 0) +#define GetSysCacheHashValue4(cacheId, key1, key2, key3, key4) GetSysCacheHashValue(cacheId, key1, key2, key3, key4) + +#define SearchSysCacheList1(cacheId, key1) SearchSysCacheList(cacheId, 1, key1, 0, 0, 0) +#define SearchSysCacheList2(cacheId, key1, key2) SearchSysCacheList(cacheId, 2, key1, key2, 0, 0) +#define SearchSysCacheList3(cacheId, key1, key2, key3) SearchSysCacheList(cacheId, 3, key1, key2, key3, 0) +#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) SearchSysCacheList(cacheId, 4, key1, key2, key3, key4) + +#define ReleaseSysCacheList(x) ReleaseCatCacheList(x) + +#endif /* SYSCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/syscall_lock.h postgresql-hll-2.14/include/include/utils/syscall_lock.h --- postgresql-hll-2.14_old/include/include/utils/syscall_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/syscall_lock.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,56 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * syscall_lock.h + * + * + * + * IDENTIFICATION + * src/include/utils/syscall_lock.h + * + * NOTE + * some function in lib has not thread safe version , use lock to protect them + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SYSCALL_LOCK_H_ +#define SYSCALL_LOCK_H_ + +#ifndef WIN32 +#include "pthread.h" +#else +#define _WINSOCKAPI_ +#include +#include "pthread-win32.h" +#endif + +typedef pthread_mutex_t syscalllock; + +#define syscalllockInit(lock) pthread_mutex_init(lock, NULL) +#define syscalllockAcquire(lock) pthread_mutex_lock(lock) +#define syscalllockRelease(lock) pthread_mutex_unlock(lock) +#define syscalllockFree(lock) pthread_mutex_destroy(lock) + +/* + * the locks declared here should be initialized in syscall_lock_init function + */ +extern syscalllock getpwuid_lock; +extern syscalllock env_lock; +extern syscalllock dlerror_lock; +extern syscalllock kerberos_conn_lock; +extern syscalllock read_cipher_lock; + +#endif /* SYSCALL_LOCK_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/utils/timestamp.h postgresql-hll-2.14/include/include/utils/timestamp.h --- postgresql-hll-2.14_old/include/include/utils/timestamp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/timestamp.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,274 @@ +/* ------------------------------------------------------------------------- + * + * timestamp.h + * Definitions for the SQL92 "timestamp" and "interval" types. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/timestamp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TIMESTAMP_H +#define TIMESTAMP_H + +#define TIMESTAMP_MASK(b) (1 << (b)) +#define INTERVAL_MASK(b) (1 << (b)) + +/* Macros to handle packing and unpacking the typmod field for intervals */ +#define INTERVAL_FULL_RANGE (0x7FFF) +#define INTERVAL_RANGE_MASK (0x7FFF) +#define INTERVAL_FULL_PRECISION (0xFFFF) +#define INTERVAL_PRECISION_MASK (0xFFFF) +#define INTERVAL_TYPMOD(p, r) ((((r)&INTERVAL_RANGE_MASK) << 16) | ((p)&INTERVAL_PRECISION_MASK)) +#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK) +#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK) + + +#ifndef FRONTEND_PARSER +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "pgtime.h" + +/* + * Macros for fmgr-callable functions. + * + * For Timestamp, we make use of the same support routines as for int64 + * or float8. Therefore Timestamp is pass-by-reference if and only if + * int64 or float8 is! + */ +#ifdef HAVE_INT64_TIMESTAMP + +#define DatumGetTimestamp(X) ((Timestamp)DatumGetInt64(X)) +#define DatumGetTimestampTz(X) ((TimestampTz)DatumGetInt64(X)) +#define DatumGetIntervalP(X) ((Interval*)DatumGetPointer(X)) + +#define TimestampGetDatum(X) Int64GetDatum(X) +#define TimestampTzGetDatum(X) Int64GetDatum(X) +#define IntervalPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n)) +#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x) +#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x) +#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x) +#else /* !HAVE_INT64_TIMESTAMP */ + +#define DatumGetTimestamp(X) ((Timestamp)DatumGetFloat8(X)) +#define DatumGetTimestampTz(X) ((TimestampTz)DatumGetFloat8(X)) +#define DatumGetIntervalP(X) ((Interval*)DatumGetPointer(X)) + +#define TimestampGetDatum(X) Float8GetDatum(X) +#define TimestampTzGetDatum(X) Float8GetDatum(X) +#define IntervalPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n)) +#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x) +#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x) +#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x) +#endif /* HAVE_INT64_TIMESTAMP */ + +#ifdef HAVE_INT64_TIMESTAMP +#define TimestampTzPlusMilliseconds(tz, ms) ((tz) + ((ms) * (int64)1000)) +#else +#define TimestampTzPlusMilliseconds(tz, ms) ((tz) + ((ms) / 1000.0)) +#endif + +#ifdef PGXC +#define InvalidGlobalTimestamp ((TimestampTz)0) +#define GlobalTimestampIsValid(timestamp) ((TimestampTz)(timestamp)) != InvalidGlobalTimestamp +#endif + +#ifndef MAX_INT32 +#define MAX_INT32 2147483600 +#endif + +/* + * timestamp.c prototypes + */ +extern Datum smalldatetime_eq(PG_FUNCTION_ARGS); +extern Datum smalldatetime_ne(PG_FUNCTION_ARGS); +extern Datum smalldatetime_lt(PG_FUNCTION_ARGS); +extern Datum smalldatetime_gt(PG_FUNCTION_ARGS); +extern Datum smalldatetime_le(PG_FUNCTION_ARGS); +extern Datum smalldatetime_ge(PG_FUNCTION_ARGS); +extern Datum smalldatetime_cmp(PG_FUNCTION_ARGS); +extern Datum smalldatetime_hash(PG_FUNCTION_ARGS); +extern Datum smalldatetime_in(PG_FUNCTION_ARGS); +extern Datum smalldatetime_out(PG_FUNCTION_ARGS); +extern Datum smalldatetime_recv(PG_FUNCTION_ARGS); +extern Datum smalldatetime_send(PG_FUNCTION_ARGS); +extern Datum smalldatetime_smaller(PG_FUNCTION_ARGS); +extern Datum smalldatetime_larger(PG_FUNCTION_ARGS); +extern Datum timestamp_in(PG_FUNCTION_ARGS); +extern Datum timestamp_out(PG_FUNCTION_ARGS); +extern Datum timestamp_recv(PG_FUNCTION_ARGS); +extern Datum timestamp_send(PG_FUNCTION_ARGS); +extern Datum timestamptypmodin(PG_FUNCTION_ARGS); +extern Datum timestamptypmodout(PG_FUNCTION_ARGS); +extern Datum timestamp_transform(PG_FUNCTION_ARGS); +extern Datum timestamp_scale(PG_FUNCTION_ARGS); +extern Datum timestamp_eq(PG_FUNCTION_ARGS); +extern Datum timestamp_ne(PG_FUNCTION_ARGS); +extern Datum timestamp_lt(PG_FUNCTION_ARGS); +extern Datum timestamp_le(PG_FUNCTION_ARGS); +extern Datum timestamp_ge(PG_FUNCTION_ARGS); +extern Datum timestamp_gt(PG_FUNCTION_ARGS); +extern Datum timestamp_finite(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp(PG_FUNCTION_ARGS); +extern Datum timestamp_sortsupport(PG_FUNCTION_ARGS); +extern Datum timestamp_hash(PG_FUNCTION_ARGS); +extern Datum timestamp_smaller(PG_FUNCTION_ARGS); +extern Datum timestamp_larger(PG_FUNCTION_ARGS); +extern Datum to_date_default_format(PG_FUNCTION_ARGS); + +extern Datum timestamp_eq_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_ne_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_lt_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_le_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_gt_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_ge_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp_timestamptz(PG_FUNCTION_ARGS); + +extern Datum timestamptz_eq_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_ne_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_lt_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_le_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_gt_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_ge_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_cmp_timestamp(PG_FUNCTION_ARGS); +extern Datum add_months(PG_FUNCTION_ARGS); +extern Datum next_day_str(PG_FUNCTION_ARGS); +extern Datum next_day_int(PG_FUNCTION_ARGS); +extern Datum last_day(PG_FUNCTION_ARGS); + +extern Datum interval_in(PG_FUNCTION_ARGS); +extern Datum interval_out(PG_FUNCTION_ARGS); +extern Datum interval_recv(PG_FUNCTION_ARGS); +extern Datum interval_send(PG_FUNCTION_ARGS); +extern Datum intervaltypmodin(PG_FUNCTION_ARGS); +extern Datum intervaltypmodout(PG_FUNCTION_ARGS); +extern Datum interval_transform(PG_FUNCTION_ARGS); +extern Datum interval_scale(PG_FUNCTION_ARGS); +extern Datum interval_eq_withhead(PG_FUNCTION_ARGS); +extern Datum interval_eq(PG_FUNCTION_ARGS); +extern Datum interval_ne(PG_FUNCTION_ARGS); +extern Datum interval_lt(PG_FUNCTION_ARGS); +extern Datum interval_le(PG_FUNCTION_ARGS); +extern Datum interval_ge(PG_FUNCTION_ARGS); +extern Datum interval_gt(PG_FUNCTION_ARGS); +extern Datum interval_finite(PG_FUNCTION_ARGS); +extern Datum interval_cmp(PG_FUNCTION_ARGS); +extern Datum interval_hash(PG_FUNCTION_ARGS); +extern Datum interval_smaller(PG_FUNCTION_ARGS); +extern Datum interval_larger(PG_FUNCTION_ARGS); +extern Datum interval_justify_interval(PG_FUNCTION_ARGS); +extern Datum interval_justify_hours(PG_FUNCTION_ARGS); +extern Datum interval_justify_days(PG_FUNCTION_ARGS); + +extern Datum timestamp_trunc(PG_FUNCTION_ARGS); +extern Datum interval_trunc(PG_FUNCTION_ARGS); +extern Datum timestamp_part(PG_FUNCTION_ARGS); +extern Datum interval_part(PG_FUNCTION_ARGS); +extern Datum timestamp_zone(PG_FUNCTION_ARGS); +extern Datum timestamp_izone(PG_FUNCTION_ARGS); +extern Datum timestamp_timestamptz(PG_FUNCTION_ARGS); + +extern Datum timestamptz_in(PG_FUNCTION_ARGS); +extern Datum timestamptz_out(PG_FUNCTION_ARGS); +extern Datum timestamptz_recv(PG_FUNCTION_ARGS); +extern Datum timestamptz_send(PG_FUNCTION_ARGS); +extern Datum timestamptztypmodin(PG_FUNCTION_ARGS); +extern Datum timestamptztypmodout(PG_FUNCTION_ARGS); +extern Datum timestamptz_scale(PG_FUNCTION_ARGS); +extern Datum timestamptz_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_zone(PG_FUNCTION_ARGS); +extern Datum timestamptz_izone(PG_FUNCTION_ARGS); +extern Datum timestamptz_timestamptz(PG_FUNCTION_ARGS); + +extern Datum interval_um(PG_FUNCTION_ARGS); +extern Datum interval_pl(PG_FUNCTION_ARGS); +extern Datum interval_mi(PG_FUNCTION_ARGS); +extern Datum interval_mul(const Interval* span, float8 factor); +extern Datum interval_mul(PG_FUNCTION_ARGS); +extern Datum mul_d_interval(PG_FUNCTION_ARGS); +extern Datum interval_div(PG_FUNCTION_ARGS); +extern Datum interval_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum interval_collect(PG_FUNCTION_ARGS); +#endif +extern Datum interval_avg(PG_FUNCTION_ARGS); + +extern Datum timestamp_mi(Timestamp dt1, Timestamp dt2); +extern Datum timestamp_mi(PG_FUNCTION_ARGS); +extern Datum timestamp_pl_interval(Timestamp timestamp, const Interval* span); +extern Datum timestamp_pl_interval(PG_FUNCTION_ARGS); +extern Datum timestamp_mi_interval(Timestamp timestamp, const Interval* span); +extern Datum timestamp_mi_interval(PG_FUNCTION_ARGS); +extern Datum timestamp_age(PG_FUNCTION_ARGS); +extern Datum timestamp_diff(PG_FUNCTION_ARGS); +extern Datum overlaps_timestamp(PG_FUNCTION_ARGS); + +extern Datum timestamptz_pl_interval(PG_FUNCTION_ARGS); +extern Datum timestamptz_mi_interval(PG_FUNCTION_ARGS); +extern Datum timestamptz_age(PG_FUNCTION_ARGS); +extern Datum timestamptz_trunc(PG_FUNCTION_ARGS); +extern Datum timestamptz_part(PG_FUNCTION_ARGS); + +extern Datum now(PG_FUNCTION_ARGS); +extern Datum statement_timestamp(PG_FUNCTION_ARGS); +extern Datum clock_timestamp(PG_FUNCTION_ARGS); + +extern Datum pg_postmaster_start_time(PG_FUNCTION_ARGS); +extern Datum get_node_stat_reset_time(PG_FUNCTION_ARGS); + +extern Datum pg_conf_load_time(PG_FUNCTION_ARGS); + +extern Datum generate_series_timestamp(PG_FUNCTION_ARGS); +extern Datum generate_series_timestamptz(PG_FUNCTION_ARGS); + +/* Internal routines (not fmgr-callable) */ + +extern TimestampTz GetCurrentTimestamp(void); +extern TimestampTz timestamp2timestamptz(Timestamp timestamp); + +extern void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long* secs, int* microsecs); +extern int ComputeTimeStamp(TimestampTz start); +extern bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec); + +extern TimestampTz time_t_to_timestamptz(pg_time_t tm); +extern pg_time_t timestamptz_to_time_t(TimestampTz t); + +extern const char* timestamptz_to_str(TimestampTz t); + +extern int tm2timestamp(struct pg_tm* tm, const fsec_t fsec, const int* tzp, Timestamp* dt); +extern int timestamp2tm(Timestamp dt, int* tzp, struct pg_tm* tm, fsec_t* fsec, const char** tzn, pg_tz* attimezone); +extern void dt2time(Timestamp dt, int* hour, int* min, int* sec, fsec_t* fsec); + +extern int interval2tm(Interval span, struct pg_tm* tm, fsec_t* fsec); +extern int tm2interval(struct pg_tm* tm, fsec_t fsec, Interval* span); +extern int interval_cmp_internal(Interval* interval1, Interval* interval2); + +extern Timestamp SetEpochTimestamp(void); +extern void GetEpochTime(struct pg_tm* tm); + +extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2); + +/* timestamp comparison works for timestamptz also */ +#define timestamptz_cmp_internal(dt1, dt2) timestamp_cmp_internal(dt1, dt2) + +extern int isoweek2j(int year, int week); +extern void isoweek2date(int woy, int* year, int* mon, int* mday); +extern void isoweekdate2date(int isoweek, int isowday, int* year, int* mon, int* mday); +extern int date2isoweek(int year, int mon, int mday); +extern int date2isoyear(int year, int mon, int mday); +extern int date2isoyearday(int year, int mon, int mday); + +#endif // !FRONTEND_PARSER +#endif /* TIMESTAMP_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/tuplesort.h postgresql-hll-2.14/include/include/utils/tuplesort.h --- postgresql-hll-2.14_old/include/include/utils/tuplesort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/tuplesort.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,123 @@ +/* ------------------------------------------------------------------------- + * + * tuplesort.h + * Generalized tuple sorting routines. + * + * This module handles sorting of heap tuples, index tuples, or single + * Datums (and could easily support other kinds of sortable objects, + * if necessary). It works efficiently for both small and large amounts + * of data. Small amounts are sorted in-memory using qsort(). Large + * amounts are sorted using temporary files and a standard external sort + * algorithm. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tuplesort.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPLESORT_H +#define TUPLESORT_H + +#include "access/itup.h" +#include "executor/tuptable.h" +#include "fmgr.h" +#include "utils/relcache.h" +#include "utils/tuplestore.h" + +/* Tuplesortstate is an opaque type whose details are not known outside + * tuplesort.c. + */ +typedef struct Tuplesortstate Tuplesortstate; + +/* + * We provide multiple interfaces to what is essentially the same code, + * since different callers have different data to be sorted and want to + * specify the sort key information differently. There are two APIs for + * sorting HeapTuples and two more for sorting IndexTuples. Yet another + * API supports sorting bare Datums. + * + * The "heap" API actually stores/sorts MinimalTuples, which means it doesn't + * preserve the system columns (tuple identity and transaction visibility + * info). The sort keys are specified by column numbers within the tuples + * and sort operator OIDs. We save some cycles by passing and returning the + * tuples in TupleTableSlots, rather than forming actual HeapTuples (which'd + * have to be converted to MinimalTuples). This API works well for sorts + * executed as parts of plan trees. + * + * The "cluster" API stores/sorts full HeapTuples including all visibility + * info. The sort keys are specified by reference to a btree index that is + * defined on the relation to be sorted. Note that putheaptuple/getheaptuple + * go with this API, not the "begin_heap" one! + * + * The "index_btree" API stores/sorts IndexTuples (preserving all their + * header fields). The sort keys are specified by a btree index definition. + * + * The "index_hash" API is similar to index_btree, but the tuples are + * actually sorted by their hash codes not the raw data. + */ + +extern Tuplesortstate* tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, int64 workMem, bool randomAccess, int64 maxMem = 0, + int planId = 0, int dop = 1); +extern Tuplesortstate* tuplesort_begin_cluster( + TupleDesc tupDesc, Relation indexRel, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_index_btree( + Relation indexRel, bool enforceUnique, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_index_hash( + Relation indexRel, uint32 hash_mask, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_datum( + Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, bool randomAccess); +#ifdef PGXC +extern void tuplesort_puttupleslotontape(Tuplesortstate* state, TupleTableSlot* slot); +extern void tuplesort_remoteread_end(Tuplesortstate* state); +#endif + +extern void tuplesort_set_bound(Tuplesortstate* state, int64 bound); + +extern void tuplesort_puttupleslot(Tuplesortstate* state, TupleTableSlot* slot); +extern void tuplesort_putheaptuple(Tuplesortstate* state, HeapTuple tup); +extern void tuplesort_putindextuplevalues( + Tuplesortstate* state, Relation rel, ItemPointer self, Datum* values, const bool* isnull); +extern void tuplesort_putdatum(Tuplesortstate* state, Datum val, bool isNull); + +extern void tuplesort_performsort(Tuplesortstate* state); + +extern bool tuplesort_gettupleslot(Tuplesortstate* state, bool forward, TupleTableSlot* slot, Datum* abbrev); +extern bool tuplesort_gettupleslot_into_tuplestore( + Tuplesortstate* state, bool forward, TupleTableSlot* slot, Datum* abbrev, Tuplestorestate* tstate); +extern HeapTuple tuplesort_getheaptuple(Tuplesortstate* state, bool forward, bool* should_free); +extern IndexTuple tuplesort_getindextuple(Tuplesortstate* state, bool forward, bool* should_free); +extern bool tuplesort_getdatum(Tuplesortstate* state, bool forward, Datum* val, bool* isNull); + +extern void tuplesort_end(Tuplesortstate* state); + +extern void tuplesort_get_stats(Tuplesortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +extern int tuplesort_merge_order(double allowedMem); + +/* + * These routines may only be called if randomAccess was specified 'true'. + * Likewise, backwards scan in gettuple/getdatum is only allowed if + * randomAccess was specified. + */ + +extern void tuplesort_rescan(Tuplesortstate* state); +extern void tuplesort_markpos(Tuplesortstate* state); +extern void tuplesort_restorepos(Tuplesortstate* state); + +extern void sort_count(Tuplesortstate* state); + +extern int64 tuplesort_get_avgwidth(Tuplesortstate* state); +extern bool tuplesort_get_busy_status(Tuplesortstate* state); +extern int tuplesort_get_spread_num(Tuplesortstate* state); +extern bool tuplesort_skiptuples(Tuplesortstate* state, int64 ntuples, bool forward); +extern void UpdateUniqueSQLSortStats(Tuplesortstate* state, TimestampTz* start_time); + +/* + * Return the int64 value of tuplesortstate->peakMemorySize + */ +extern int64 tuplesort_get_peak_memory(Tuplesortstate* state); + +#endif /* TUPLESORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/tuplestore.h postgresql-hll-2.14/include/include/utils/tuplestore.h --- postgresql-hll-2.14_old/include/include/utils/tuplestore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/tuplestore.h 2020-12-12 17:06:43.296348671 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * tuplestore.h + * Generalized routines for temporary tuple storage. + * + * This module handles temporary storage of tuples for purposes such + * as Materialize nodes, hashjoin batch files, etc. It is essentially + * a dumbed-down version of tuplesort.c; it does no sorting of tuples + * but can only store and regurgitate a sequence of tuples. However, + * because no sort is required, it is allowed to start reading the sequence + * before it has all been written. This is particularly useful for cursors, + * because it allows random access within the already-scanned portion of + * a query without having to process the underlying scan to completion. + * Also, it is possible to support multiple independent read pointers. + * + * A temporary file is used to handle the data if it exceeds the + * space limit specified by the caller. + * + * Beginning in Postgres 8.2, what is stored is just MinimalTuples; + * callers cannot expect valid system columns in regurgitated tuples. + * Also, we have changed the API to return tuples in TupleTableSlots, + * so that there is a check to prevent attempted access to system columns. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tuplestore.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPLESTORE_H +#define TUPLESTORE_H + +#include "executor/tuptable.h" + +/* Tuplestorestate is an opaque type whose details are not known outside + * tuplestore.c. + */ +typedef struct Tuplestorestate Tuplestorestate; + +/* + * Currently we only need to store MinimalTuples, but it would be easy + * to support the same behavior for IndexTuples and/or bare Datums. + */ + +extern Tuplestorestate* tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes, int maxMem = 0, + int planId = 0, int dop = 1, bool isAddMemCtl = false); + +extern void tuplestore_set_eflags(Tuplestorestate* state, int eflags); + +extern void tuplestore_puttupleslot(Tuplestorestate* state, TupleTableSlot* slot, bool need_transform_anyarray = false); +extern void tuplestore_puttuple(Tuplestorestate* state, HeapTuple tuple); +extern void tuplestore_putvalues(Tuplestorestate* state, TupleDesc tdesc, Datum* values, const bool* isnull); + +/* tuplestore_donestoring() used to be required, but is no longer used */ +#define tuplestore_donestoring(state) ((void)0) + +extern int tuplestore_alloc_read_pointer(Tuplestorestate* state, int eflags); + +extern void tuplestore_select_read_pointer(Tuplestorestate* state, int ptr); + +extern void tuplestore_copy_read_pointer(Tuplestorestate* state, int srcptr, int destptr); + +extern void tuplestore_trim(Tuplestorestate* state); + +extern bool tuplestore_in_memory(Tuplestorestate* state); + +extern bool tuplestore_gettupleslot(Tuplestorestate* state, bool forward, bool copy, TupleTableSlot* slot); +extern bool tuplestore_advance(Tuplestorestate* state, bool forward); + +extern bool tuplestore_ateof(Tuplestorestate* state); + +extern void tuplestore_rescan(Tuplestorestate* state); + +extern void tuplestore_clear(Tuplestorestate* state); + +extern void tuplestore_end(Tuplestorestate* state); + +extern int64 tuplestore_get_avgwidth(Tuplestorestate* state); +extern bool tuplestore_get_busy_status(Tuplestorestate* state); +extern int tuplestore_get_spread_num(Tuplestorestate* state); + +#endif /* TUPLESTORE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/typcache.h postgresql-hll-2.14/include/include/utils/typcache.h --- postgresql-hll-2.14_old/include/include/utils/typcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/typcache.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,121 @@ +/* ------------------------------------------------------------------------- + * + * typcache.h + * Type cache definitions. + * + * The type cache exists to speed lookup of certain information about data + * types that is not directly available from a type's pg_type row. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/typcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TYPCACHE_H +#define TYPCACHE_H + +#include "access/tupdesc.h" +#include "fmgr.h" + +/* TypeCacheEnumData is an opaque struct known only within typcache.c */ +struct TypeCacheEnumData; + +typedef struct TypeCacheEntry { + /* typeId is the hash lookup key and MUST BE FIRST */ + Oid type_id; /* OID of the data type */ + + /* some subsidiary information copied from the pg_type row */ + int16 typlen; + bool typbyval; + char typalign; + char typstorage; + char typtype; + Oid typrelid; + + /* + * Information obtained from opfamily entries + * + * These will be InvalidOid if no match could be found, or if the + * information hasn't yet been requested. Also note that for array and + * composite types, typcache.c checks that the contained types are + * comparable or hashable before allowing eq_opr etc to become set. + */ + Oid btree_opf; /* the default btree opclass' family */ + Oid btree_opintype; /* the default btree opclass' opcintype */ + Oid hash_opf; /* the default hash opclass' family */ + Oid hash_opintype; /* the default hash opclass' opcintype */ + Oid eq_opr; /* the equality operator */ + Oid lt_opr; /* the less-than operator */ + Oid gt_opr; /* the greater-than operator */ + Oid cmp_proc; /* the btree comparison function */ + Oid hash_proc; /* the hash calculation function */ + + /* + * Pre-set-up fmgr call info for the equality operator, the btree + * comparison function, and the hash calculation function. These are kept + * in the type cache to avoid problems with memory leaks in repeated calls + * to functions such as array_eq, array_cmp, hash_array. There is not + * currently a need to maintain call info for the lt_opr or gt_opr. + */ + FmgrInfo eq_opr_finfo; + FmgrInfo cmp_proc_finfo; + FmgrInfo hash_proc_finfo; + + /* + * Tuple descriptor if it's a composite type (row type). NULL if not + * composite or information hasn't yet been requested. (NOTE: this is a + * reference-counted tupledesc.) + */ + TupleDesc tupDesc; + + /* + * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not + * a range type or information hasn't yet been requested. Note that + * rng_cmp_proc_finfo could be different from the element type's default + * btree comparison function. + */ + struct TypeCacheEntry* rngelemtype; /* range's element type */ + Oid rng_collation; /* collation for comparisons, if any */ + FmgrInfo rng_cmp_proc_finfo; /* comparison function */ + FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */ + FmgrInfo rng_subdiff_finfo; /* difference function, if any */ + + /* Private data, for internal use of typcache.c only */ + int flags; /* flags about what we've computed */ + + /* + * Private information about an enum type. NULL if not enum or + * information hasn't been requested. + */ + struct TypeCacheEnumData* enumData; +} TypeCacheEntry; + +/* Bit flags to indicate which fields a given caller needs to have set */ +#define TYPECACHE_EQ_OPR 0x0001 +#define TYPECACHE_LT_OPR 0x0002 +#define TYPECACHE_GT_OPR 0x0004 +#define TYPECACHE_CMP_PROC 0x0008 +#define TYPECACHE_HASH_PROC 0x0010 +#define TYPECACHE_EQ_OPR_FINFO 0x0020 +#define TYPECACHE_CMP_PROC_FINFO 0x0040 +#define TYPECACHE_HASH_PROC_FINFO 0x0080 +#define TYPECACHE_TUPDESC 0x0100 +#define TYPECACHE_BTREE_OPFAMILY 0x0200 +#define TYPECACHE_HASH_OPFAMILY 0x0400 +#define TYPECACHE_RANGE_INFO 0x0800 + +extern TypeCacheEntry* lookup_type_cache(Oid type_id, int flags); + +extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod); + +extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError); + +extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod); + +extern void assign_record_type_typmod(TupleDesc tupDesc); + +extern int compare_values_of_enum(TypeCacheEntry* tcache, Oid arg1, Oid arg2); + +#endif /* TYPCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/tzparser.h postgresql-hll-2.14/include/include/utils/tzparser.h --- postgresql-hll-2.14_old/include/include/utils/tzparser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/tzparser.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,35 @@ +/* ------------------------------------------------------------------------- + * + * tzparser.h + * Timezone offset file parsing definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tzparser.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TZPARSER_H +#define TZPARSER_H + +#include "utils/datetime.h" + +/* + * The result of parsing a timezone configuration file is an array of + * these structs, in order by abbrev. We export this because datetime.c + * needs it. + */ +typedef struct tzEntry { + /* the actual data: TZ abbrev (downcased), offset, DST flag */ + char* abbrev; + int offset; /* in seconds from UTC */ + bool is_dst; + /* source information (for error messages) */ + int lineno; + const char* filename; +} tzEntry; + +extern TimeZoneAbbrevTable* load_tzoffsets(const char* filename); + +#endif /* TZPARSER_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/uuid.h postgresql-hll-2.14/include/include/utils/uuid.h --- postgresql-hll-2.14_old/include/include/utils/uuid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/uuid.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * uuid.h + * Header file for the "uuid" ADT. In C, we use the name pg_uuid_t, + * to avoid conflicts with any uuid_t type that might be defined by + * the system headers. + * + * Copyright (c) 2007-2012, PostgreSQL Global Development Group + * + * src/include/utils/uuid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef UUID_H +#define UUID_H + +/* guid size in bytes */ +#define UUID_LEN 16 + +struct pg_uuid_t { + unsigned char data[UUID_LEN]; +}; + +/* opaque struct; defined in uuid.c */ +typedef struct pg_uuid_t pg_uuid_t; + +/* fmgr interface macros */ +#define UUIDPGetDatum(X) PointerGetDatum(X) +#define PG_RETURN_UUID_P(X) return UUIDPGetDatum(X) +#define DatumGetUUIDP(X) ((pg_uuid_t*)DatumGetPointer(X)) +#define PG_GETARG_UUID_P(X) DatumGetUUIDP(PG_GETARG_DATUM(X)) + +Datum uuid_hash(PG_FUNCTION_ARGS); +#endif /* UUID_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/varbit.h postgresql-hll-2.14/include/include/utils/varbit.h --- postgresql-hll-2.14_old/include/include/utils/varbit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/varbit.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,110 @@ +/* ------------------------------------------------------------------------- + * + * varbit.h + * Functions for the SQL datatypes BIT() and BIT VARYING(). + * + * Code originally contributed by Adriaan Joubert. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/varbit.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VARBIT_H +#define VARBIT_H + +#include +#include "fmgr.h" + +/* + * Modeled on struct varlena from postgres.h, but data type is bits8. + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 bit_len; /* number of valid bits */ + bits8 bit_dat[FLEXIBLE_ARRAY_MEMBER]; /* bit string, most sig. byte first */ +} VarBit; + +/* + * fmgr interface macros + * + * BIT and BIT VARYING are toastable varlena types. They are the same + * as far as representation goes, so we just have one set of macros. + */ +#define DatumGetVarBitP(X) ((VarBit*)PG_DETOAST_DATUM(X)) +#define DatumGetVarBitPCopy(X) ((VarBit*)PG_DETOAST_DATUM_COPY(X)) +#define VarBitPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_VARBIT_P(n) DatumGetVarBitP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_VARBIT_P(x) return VarBitPGetDatum(x) + +/* Header overhead *in addition to* VARHDRSZ */ +#define VARBITHDRSZ sizeof(int32) +/* Number of bits in this bit string */ +#define VARBITLEN(PTR) (((VarBit*)(PTR))->bit_len) +/* Pointer to the first byte containing bit string data */ +#define VARBITS(PTR) (((VarBit*)(PTR))->bit_dat) +/* Number of bytes in the data section of a bit string */ +#define VARBITBYTES(PTR) (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ) +/* Padding of the bit string at the end (in bits) */ +#define VARBITPAD(PTR) (VARBITBYTES(PTR) * BITS_PER_BYTE - VARBITLEN(PTR)) +/* Number of bytes needed to store a bit string of a given length */ +#define VARBITTOTALLEN(BITLEN) (((BITLEN) + BITS_PER_BYTE - 1) / BITS_PER_BYTE + VARHDRSZ + VARBITHDRSZ) +/* + * Maximum number of bits. Several code sites assume no overflow from + * computing bitlen + X; VARBITTOTALLEN() has the largest such X. + */ +#define VARBITMAXLEN (INT_MAX - BITS_PER_BYTE + 1) +/* pointer beyond the end of the bit string (like end() in STL containers) */ +#define VARBITEND(PTR) (((bits8*)(PTR)) + VARSIZE(PTR)) +/* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */ +#define BITMASK 0xFF + +extern Datum bit_in(PG_FUNCTION_ARGS); +extern Datum bit_out(PG_FUNCTION_ARGS); +extern Datum bit_recv(PG_FUNCTION_ARGS); +extern Datum bit_send(PG_FUNCTION_ARGS); +extern Datum bittypmodin(PG_FUNCTION_ARGS); +extern Datum bittypmodout(PG_FUNCTION_ARGS); +extern Datum varbit_in(PG_FUNCTION_ARGS); +extern Datum varbit_out(PG_FUNCTION_ARGS); +extern Datum varbit_recv(PG_FUNCTION_ARGS); +extern Datum varbit_send(PG_FUNCTION_ARGS); +extern Datum varbittypmodin(PG_FUNCTION_ARGS); +extern Datum varbittypmodout(PG_FUNCTION_ARGS); +extern Datum bit(PG_FUNCTION_ARGS); +extern Datum varbit_transform(PG_FUNCTION_ARGS); +extern Datum varbit(PG_FUNCTION_ARGS); +extern Datum biteq(PG_FUNCTION_ARGS); +extern Datum bitne(PG_FUNCTION_ARGS); +extern Datum bitlt(PG_FUNCTION_ARGS); +extern Datum bitle(PG_FUNCTION_ARGS); +extern Datum bitgt(PG_FUNCTION_ARGS); +extern Datum bitge(PG_FUNCTION_ARGS); +extern Datum bitcmp(PG_FUNCTION_ARGS); + +/* avoid the names bitand and bitor, since they are C++ keywords */ +extern Datum bit_and(PG_FUNCTION_ARGS); +extern Datum bit_or(PG_FUNCTION_ARGS); +extern Datum bitxor(PG_FUNCTION_ARGS); +extern Datum bitnot(PG_FUNCTION_ARGS); +extern Datum bitshiftleft(PG_FUNCTION_ARGS); +extern Datum bitshiftright(PG_FUNCTION_ARGS); +extern Datum bitcat(PG_FUNCTION_ARGS); +extern Datum bitsubstr(PG_FUNCTION_ARGS); +extern Datum bitsubstr_no_len(PG_FUNCTION_ARGS); +extern Datum bitoverlay(PG_FUNCTION_ARGS); +extern Datum bitoverlay_no_len(PG_FUNCTION_ARGS); +extern Datum bitlength(PG_FUNCTION_ARGS); +extern Datum bitoctetlength(PG_FUNCTION_ARGS); +extern Datum bitfromint4(PG_FUNCTION_ARGS); +extern Datum bittoint4(PG_FUNCTION_ARGS); +extern Datum bitfromint8(PG_FUNCTION_ARGS); +extern Datum bittoint8(PG_FUNCTION_ARGS); +extern Datum bitposition(PG_FUNCTION_ARGS); +extern Datum bitsetbit(PG_FUNCTION_ARGS); +extern Datum bitgetbit(PG_FUNCTION_ARGS); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/utils/xml.h postgresql-hll-2.14/include/include/utils/xml.h --- postgresql-hll-2.14_old/include/include/utils/xml.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/xml.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * xml.h + * Declarations for XML data type support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/xml.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef XML_H +#define XML_H + +#include "fmgr.h" +#include "nodes/execnodes.h" +#include "nodes/primnodes.h" +#include "utils/xmltypes.h" + +#define DatumGetXmlP(X) ((xmltype*)PG_DETOAST_DATUM(X)) +#define XmlPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_XML_P(n) DatumGetXmlP(PG_GETARG_DATUM(n)) +#define PG_RETURN_XML_P(x) PG_RETURN_POINTER(x) + +extern Datum xml_in(PG_FUNCTION_ARGS); +extern Datum xml_out(PG_FUNCTION_ARGS); +extern Datum xml_recv(PG_FUNCTION_ARGS); +extern Datum xml_send(PG_FUNCTION_ARGS); +extern Datum xmlcomment(PG_FUNCTION_ARGS); +extern Datum xmlconcat2(PG_FUNCTION_ARGS); +extern Datum texttoxml(PG_FUNCTION_ARGS); +extern Datum xmltotext(PG_FUNCTION_ARGS); +extern Datum xmlvalidate(PG_FUNCTION_ARGS); +extern Datum xpath(PG_FUNCTION_ARGS); +extern Datum xpath_exists(PG_FUNCTION_ARGS); +extern Datum xmlexists(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed_document(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed_content(PG_FUNCTION_ARGS); + +extern Datum table_to_xml(PG_FUNCTION_ARGS); +extern Datum query_to_xml(PG_FUNCTION_ARGS); +extern Datum cursor_to_xml(PG_FUNCTION_ARGS); +extern Datum table_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum query_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum cursor_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum table_to_xml_and_xmlschema(PG_FUNCTION_ARGS); +extern Datum query_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern Datum schema_to_xml(PG_FUNCTION_ARGS); +extern Datum schema_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum schema_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern Datum database_to_xml(PG_FUNCTION_ARGS); +extern Datum database_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum database_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern void pg_xml_init_library(void); +extern PgXmlErrorContext* pg_xml_init(PgXmlStrictness strictness); +extern void pg_xml_done(PgXmlErrorContext* errcxt, bool isError); +extern bool pg_xml_error_occurred(PgXmlErrorContext* errcxt); +extern void xml_ereport(PgXmlErrorContext* errcxt, int level, int sqlcode, const char* msg); + +extern xmltype* xmlconcat(List* args); +extern xmltype* xmlelement(XmlExprState* xmlExpr, ExprContext* econtext); +extern xmltype* xmlparse(text* data, XmlOptionType xmloption, bool preserve_whitespace); +extern xmltype* xmlpi(char* target, text* arg, bool arg_is_null, bool* result_is_null); +extern xmltype* xmlroot(xmltype* data, text* version, int standalone); +extern bool xml_is_document(xmltype* arg); +extern text* xmltotext_with_xmloption(xmltype* data, XmlOptionType xmloption_arg); +extern char* escape_xml(const char* str); + +extern char* map_sql_identifier_to_xml_name(char* ident, bool fully_escaped, bool escape_period); +extern char* map_xml_name_to_sql_identifier(char* name); +extern char* map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings); + +extern THR_LOCAL int xmloption; /* XmlOptionType, but int for guc enum */ + +#endif /* XML_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/xmltypes.h postgresql-hll-2.14/include/include/utils/xmltypes.h --- postgresql-hll-2.14_old/include/include/utils/xmltypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/xmltypes.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * xmltypes.h + * + * IDENTIFICATION + * src\include\utils\xmltypes.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef XMLTYPES_H +#define XMLTYPES_H + +typedef struct varlena xmltype; + +typedef enum { + XML_STANDALONE_YES, + XML_STANDALONE_NO, + XML_STANDALONE_NO_VALUE, + XML_STANDALONE_OMITTED +} XmlStandaloneType; + +typedef enum { + XMLBINARY_BASE64, + XMLBINARY_HEX +} XmlBinaryType; + +typedef enum { + PG_XML_STRICTNESS_LEGACY, /* ignore errors unless function result indicates error condition */ + PG_XML_STRICTNESS_WELLFORMED, /* ignore non-parser messages */ + PG_XML_STRICTNESS_ALL /* report all notices/warnings/errors */ +} PgXmlStrictness; + +/* struct PgXmlErrorContext is private to xml.c */ +typedef struct PgXmlErrorContext PgXmlErrorContext; + +#endif /* XMLTYPES_H */ diff -uprN postgresql-hll-2.14_old/include/include/utils/zfiles.h postgresql-hll-2.14/include/include/utils/zfiles.h --- postgresql-hll-2.14_old/include/include/utils/zfiles.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/utils/zfiles.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * zfiles.h + * + * + * + * IDENTIFICATION + * src/include/utils/zfiles.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _LOG_FDW_ZFILES_H_ +#define _LOG_FDW_ZFILES_H_ + +#include "ioapi.h" +#include "unzip.h" + +typedef struct opaque_vfd { + int m_tmp_vfd; /* virtual fd */ + int m_errno; /* io error no */ + off_t m_cur_off; /* file offset */ + long m_max_off; /* file max offset */ +} opaque_vfd; + +typedef struct zip_reader { + unzFile m_unz; + unz_global_info64 m_unz_gi; + ZPOS64_T m_unz_curfile; + opaque_vfd m_vfd; +} zip_reader; + +typedef struct gz_reader { + gzFile m_gzf; + opaque_vfd* m_vfd; +} gz_reader; + +extern void pm_set_unzip_memfuncs(void); + +/* unzip postgresql-2018-03-31_000000.zip log file and read its contents */ +extern void set_unzip_filefuncs(zlib_filefunc64_def* funcs, voidpf opaque); +extern void* unzip_open(const char* zipfile); +extern int unzip_read(void* zr, char* buf, int bufsize); +extern void unzip_close(void* zr); + +extern void* vfd_file_open(const char* logfile); +extern int vfd_file_read(void* fobj, char* buf, int bufsize); +extern void vfd_file_close(void* fobj); +extern void vfd_file_close_with_thief(void* fobj); + +extern void* gz_open(const char* gzfile); +extern int gz_read(void* gzfd, char* buf, int bufsize); +extern void gz_close(void* gzfd); + +#endif /* _LOG_FDW_ZFILES_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecagg.h postgresql-hll-2.14/include/include/vecexecutor/vecagg.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecagg.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,248 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecagg.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECAGG_H_ +#define VECAGG_H_ + +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecnodes.h" +#include "utils/batchsort.h" + +extern VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags); +extern VectorBatch* ExecVecAggregation(VecAggState* node); +extern void ExecEndVecAggregation(VecAggState* node); +extern void ExecReScanVecAggregation(VecAggState* node); +extern void ExecEarlyFreeVecAggregation(VecAggState* node); + +#define AGG_PREPARE 0 +#define AGG_BUILD 1 +#define AGG_FETCH 2 +#define AGG_RETURN 3 +#define AGG_RETURN_LAST 4 +#define AGG_RETURN_NULL 5 + +struct finalAggInfo { + int idx; + VecAggInfo* info; +}; + +typedef struct SortDistinct { + Batchsortstate** batchsortstate; + VectorBatch** aggDistinctBatch; + ScalarValue* lastVal; + hashCell* m_distinctLoc; + int* lastValLen; +} SortDistinct; + +class BaseAggRunner : public hashBasedOperator { +public: + BaseAggRunner(VecAggState* runtime, bool isHashAgg); + BaseAggRunner(); + + void init_aggInfo(int agg_num, VecAggInfo* aggInfo); + + virtual bool ResetNecessary(VecAggState* node) = 0; + + virtual VectorBatch* Run() = 0; + + void (BaseAggRunner::*m_buildScanBatch)(hashCell* cell); + + void init_index(); + + template + void initCellValue(VectorBatch* batch, hashCell* cell, int idx); + + void BatchAggregation(VectorBatch* batch); + + template + bool match_key(VectorBatch* batch, int batchIdx, hashCell* cell); + + void AggregationOnScalar(VecAggInfo* aggInfo, ScalarVector* pVector, int idx, hashCell** location); + + // build scan batch + void BuildScanBatchSimple(hashCell* cell); + + void BuildScanBatchFinal(hashCell* cell); + + // build result batch + VectorBatch* ProducerBatch(); + + /* Filter repeat value which be used when agg need distinct.*/ + bool FilterRepeatValue(FmgrInfo* equalfns, int currentSet, int aggno, bool first); + + /*Add for sort agg*/ + void BatchSortAggregation(int i, int workMem, int maxMem, int planId, int dop); + + void initialize_sortstate(int workMem, int maxMem, int planId, int dop); + + void build_batch(); + + /*keep last values, when need distinct operation. This value need compare with the values of next batch*/ + void copyLastValues(Oid typOid, ScalarValue m_vals, int aggno, int currentSet); + + void BatchNoSortAgg(VectorBatch* batch); + + void AppendBatchForSortAgg(VectorBatch* batch, int start, int end, int currentSet); + +public: + VecAggState* m_runtime; + + int m_cellVarLen; + // how many aggregation function (column) + int m_aggNum; + + bool* m_aggCount; + + // the agg index in the tuple,as some agg function may split into two function + // e.g avg + int* m_aggIdx; + + int* m_cellBatchMap; + + int* m_keyIdxInCell; + + bool m_finish; + + bool m_hasDistinct; + + int m_keySimple; // whether the key is simple. 1:is simple 2: not simple + // simple means there is no variable length data type or complex expression evaluation. + + // the index which need do some final calc. + finalAggInfo* m_finalAggInfo; + + int m_finalAggNum; + + // Batch for scan the hash table. + VectorBatch* m_scanBatch; + + // projection batch. The projection code binds column offset with outer batch, so we + // shall keep the outer batch to leverage it. Notice that we have actually copied + // accessible columns to the hash table already (due to aggregation semantics), so + // we simply use outer batch offset only. + // + VectorBatch* m_proBatch; + + // same structure as outer node return batch + VectorBatch* m_outerBatch; + + // runtime state. + int m_runState; + + // the location for entry to be insert + hashCell* m_Loc[BatchMaxSize]; + + SortDistinct* m_sortDistinct; + + VarBuf* m_sortCurrentBuf; + + int m_projected_set; + + /* expression-evaluation context */ + ExprContext* m_econtext; + +private: + void init_Baseindex(); + void prepare_projection_batch(); + + virtual void BindingFp() = 0; +}; + +#define DO_AGGEGATION(tbl) (((BaseAggRunner*)tbl)->Run)() + +template +void BaseAggRunner::initCellValue(VectorBatch* batch, hashCell* cell, int idx) +{ + int k; + ScalarVector* pVector = NULL; + + for (k = 0; k < m_cellVarLen; k++) { + pVector = &batch->m_arr[m_cellBatchMap[k]]; + + if (simple || pVector->m_desc.encoded == false) { + cell->m_val[k].val = pVector->m_vals[idx]; + cell->m_val[k].flag = pVector->m_flag[idx]; + } else { + if (likely(pVector->IsNull(idx) == false)) { + /* For hashagg, CurrentMemoryContext is hashcell context */ + cell->m_val[k].val = sortAgg ? addToVarBuffer(m_sortCurrentBuf, pVector->m_vals[idx]) + : addVariable(CurrentMemoryContext, pVector->m_vals[idx]); + if (!sortAgg && m_tupleCount >= 0) + m_colWidth += VARSIZE_ANY(pVector->m_vals[idx]); + } + + cell->m_val[k].flag = pVector->m_flag[idx]; + } + } + + // set the init value. + for (k = 0; k < m_aggNum; k++) { + if (m_aggCount[k]) { + cell->m_val[m_aggIdx[k]].val = 0; + SET_NOTNULL(cell->m_val[m_aggIdx[k]].flag); + } else + SET_NULL(cell->m_val[m_aggIdx[k]].flag); + } +} + +template +bool BaseAggRunner::match_key(VectorBatch* batch, int batchIdx, hashCell* cell) +{ + bool match = true; + int i; + ScalarVector* pVector = NULL; + hashVal* hashval = NULL; + FunctionCallInfoData fcinfo; + Datum args[2]; + + fcinfo.arg = &args[0]; + + for (i = 0; i < m_key; i++) { + pVector = &batch->m_arr[m_keyIdx[i]]; + hashval = &cell->m_val[m_keyIdxInCell[i]]; + + if (BOTH_NOT_NULL(pVector->m_flag[batchIdx], hashval->flag)) { + if (simpleKey || pVector->m_desc.encoded == false) { + if (pVector->m_vals[batchIdx] == hashval->val) + continue; + else + return false; + } else { + fcinfo.arg[0] = ScalarVector::Decode(pVector->m_vals[batchIdx]); + fcinfo.arg[1] = ScalarVector::Decode(hashval->val); + fcinfo.flinfo = (m_eqfunctions + i); + match = m_eqfunctions[i].fn_addr(&fcinfo); + if (match == false) + return false; + } + } else if (IS_NULL(pVector->m_flag[batchIdx]) && IS_NULL(hashval->flag)) // both null is equal + continue; + else if (IS_NULL(pVector->m_flag[batchIdx]) || IS_NULL(hashval->flag)) + return false; + } + + return true; +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecappend.h postgresql-hll-2.14/include/include/vecexecutor/vecappend.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecappend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecappend.h 2020-12-12 17:06:43.297348683 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecappend.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecappend.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECAPPEND_H +#define NODEVECAPPEND_H + +#include "vecexecutor/vecnodes.h" + +extern VecAppendState* ExecInitVecAppend(VecAppend* node, EState* estate, int eflags); +extern VectorBatch* ExecVecAppend(VecAppendState* node); +extern void ExecEndVecAppend(VecAppendState* node); +extern void ExecReScanVecAppend(VecAppendState* node); + +#endif /* NODEVECAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecexecutor.h postgresql-hll-2.14/include/include/vecexecutor/vecexecutor.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecexecutor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecexecutor.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexecutor.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecexecutor.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef VECEXECUTOR_H_ +#define VECEXECUTOR_H_ + +#include "nodes/execnodes.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/bytea.h" +#include "utils/geo_decls.h" +#include "utils/nabstime.h" +#include "utils/timestamp.h" + +#define initEcontextBatch(m_scanbatch, m_outerbatch, m_innerbatch, m_aggbatch) \ + { \ + econtext->ecxt_scanbatch = m_scanbatch; \ + econtext->ecxt_outerbatch = m_outerbatch; \ + econtext->ecxt_innerbatch = m_innerbatch; \ + econtext->ecxt_aggbatch = m_aggbatch; \ + } + +extern VectorBatch* VectorEngine(PlanState* node); +extern VectorBatch* ExecVecProject(ProjectionInfo* projInfo, bool selReSet = true, ExprDoneCond* isDone = NULL); +extern ExprState* ExecInitVecExpr(Expr* node, PlanState* parent); + +extern ScalarVector* ExecVecQual(List* qual, ExprContext* econtext, bool resultForNull, bool isReset = true); + +typedef VectorBatch* (*ExecVecScanAccessMtd)(ScanState* node); +typedef bool (*ExecVecScanRecheckMtd)(ScanState* node, VectorBatch* batch); +extern VectorBatch* ExecVecScan(ScanState* node, ExecVecScanAccessMtd accessMtd, ExecVecScanRecheckMtd recheckMtd); +extern void ExecAssignVecScanProjectionInfo(ScanState* node); +extern void ExecVecMarkPos(PlanState* node); +extern void ExecVecRestrPos(PlanState* node); +extern void VecExecReScan(PlanState* node); + +#endif /* VECEXECUTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecexpression.h postgresql-hll-2.14/include/include/vecexecutor/vecexpression.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecexpression.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecexpression.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexpression.h + * Vectorized Expression Engine + * + * IDENTIFICATION + * src/include/vecexecutor/vecexpression.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECEXPRESSION_H_ +#define VECEXPRESSION_H_ + +#include "fmgr.h" +#include "vecexecutor/vectorbatch.h" + +#define VectorExprEngine(expr, econtext, selVector, inputVector, isDone) \ + ((expr)->vecExprFun ? (*(expr)->vecExprFun)(expr, econtext, selVector, inputVector, isDone) \ + : (elog(ERROR, "Unsupported expressions for vector engine"), ((ScalarVector*)NULL))) + +GenericArgExtract ChooseExtractFun(Oid Dtype, Oid fn_oid = 0); + +#endif /* VECEXPRESSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecfunc.h postgresql-hll-2.14/include/include/vecexecutor/vecfunc.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecfunc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecfunc.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecfunc.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecfunc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECFUNC_H +#define VECFUNC_H + +#include "utils/hsearch.h" + +#include "utils/builtins.h" +#include "utils/fmgrtab.h" +#include "mb/pg_wchar.h" + +#define FUNCACHE_NUM 8 + +typedef struct { + /* fn_oid is the hash key and so must be first! */ + Oid fn_oid; /* OID of an external C function */ + VectorFunction vec_fn_cache[FUNCACHE_NUM]; /* address of its info record */ + VectorFunction vec_agg_cache[FUNCACHE_NUM]; + + /* + * function cache pointer to the sonic hash agg function if supported + */ + VectorFunction vec_sonic_agg_cache[FUNCACHE_NUM]; + + /* vec_transform_function has three applications + * 1. this function is used for the last stage of avg(vec_aggfinal_function); + * 2. we can replace some native PGFunctions to our transformed function for some reasons; + * (such as: int_numeric TO int_numeric_bi) + * 3. this interface is reserved for later use. + */ + PGFunction vec_transform_function[FUNCACHE_NUM]; + + /* + * sonic transform functions, which have the same meanings as vec_transform_function, but + * used only for sonic cases. + */ + PGFunction vec_sonic_transform_function[FUNCACHE_NUM]; + +} VecFuncCacheEntry; + +typedef Datum (*sub_Array)(Datum str, int32 start, int32 length, bool* isnull, mblen_converter fun_mblen); + +extern sub_Array substr_Array[32]; + +#endif /* VECFUNC_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecgroup.h postgresql-hll-2.14/include/include/vecexecutor/vecgroup.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecgroup.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecgroup.h + * Prototypes for vectorized group + * + * IDENTIFICATION + * src/include/vecexecutor/vecgroup.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECGROUP_H +#define VECGROUP_H + +#include "vecexecutor/vecnodes.h" + +extern VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags); +extern VectorBatch* ExecVecGroup(VecGroupState* node); +extern void ExecEndVecGroup(VecGroupState* node); +extern void ExecReScanVecGroup(VecGroupState* node); + +#endif /* VECGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecgrpuniq.h postgresql-hll-2.14/include/include/vecexecutor/vecgrpuniq.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecgrpuniq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecgrpuniq.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,263 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecgrpuniq.h + * Prototypes for vectorized unique and group + * + * IDENTIFICATION + * src/include/vecexecutor/vecgrpuniq.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECGRPUNIQ_H +#define VECGRPUNIQ_H +#include "vecexecutor/vectorbatch.h" +#include "vecexecutor/vecexecutor.h" + +// The value of cell which is contained in GUCell +// +struct GUCellVal { + ScalarValue val; + uint8 flag; +}; + +// The container to store cells which are used to produce outer batch +// +struct GUCell { + int dummy; /* a dummy field to avoid compile error for sigle var-len array in an empty struct*/ + GUCellVal val[FLEXIBLE_ARRAY_MEMBER]; +}; + +// The encapsulation of VectorBatch, cols and colIdx. Use this to reduce the parameter number, +// create and fill it in vecgroup and vecunique seperately to avoid using if in template because +// of the different name of colIdx(grpColIdx, uniqColIdx). +// +struct Encap { + VectorBatch* batch; + int cols; + int outerCols; + AttrNumber* colIdx; + FmgrInfo* eqfunctions; +}; + +inline ScalarValue AddVar(VarBuf* buf, ScalarValue value) +{ + return PointerGetDatum(buf->Append(DatumGetPointer(value), VARSIZE_ANY(value))); +} + +template +static void InitCellValue(Encap* cap, GUCell* cell, int idx, VarBuf* currentBuf) +{ + int k = 0; + ScalarVector* pVector = NULL; + VectorBatch* batch = cap->batch; + ScalarVector* arr = batch->m_arr; + GUCellVal* val = cell->val; + int outerCols = cap->outerCols; + + for (k = 0; k < outerCols; k++) { + pVector = &arr[k]; + if (simple || pVector->m_desc.encoded == false) { + val[k].val = pVector->m_vals[idx]; + val[k].flag = pVector->m_flag[idx]; + } else { + if (likely(pVector->IsNull(idx) == false)) + val[k].val = AddVar(currentBuf, pVector->m_vals[idx]); + + val[k].flag = pVector->m_flag[idx]; + } + } +} + +template +static bool Match(Encap* cap, int batchIdx, GUCell* cell) +{ + bool match = true; + int i = 0; + ScalarVector* pVector = NULL; + ScalarDesc desc; + GUCellVal* cellVal = NULL; + Datum key1; + Datum key2; + ScalarVector* arr = cap->batch->m_arr; + GUCellVal* val = cell->val; + int cols = cap->cols; + AttrNumber* colIdx = cap->colIdx; + FmgrInfo* eqfuncs = cap->eqfunctions; + + for (i = 0; i < cols; i++) { + pVector = &arr[colIdx[i] - 1]; + cellVal = &val[colIdx[i] - 1]; + desc = pVector->m_desc; + + if (BOTH_NOT_NULL(pVector->m_flag[batchIdx], cellVal->flag)) { + if (simpleKey || desc.encoded == false) { + if (pVector->m_vals[batchIdx] == cellVal->val) + continue; + else + return false; + } else { + key1 = ScalarVector::Decode(pVector->m_vals[batchIdx]); + key2 = ScalarVector::Decode(cellVal->val); + + match = DatumGetBool(FunctionCall2((eqfuncs + i), key1, key2)); + if (match == false) + return false; + } + } + // both null is equal + else if (IS_NULL(pVector->m_flag[batchIdx]) && IS_NULL(cellVal->flag)) + continue; + else if (IS_NULL(pVector->m_flag[batchIdx]) || IS_NULL(cellVal->flag)) + return false; + } + + return true; +} + +// Build the container filled with cells which not match others. +// +template +Datum BuildFunc(PG_FUNCTION_ARGS) +{ + T* node = (T*)PG_GETARG_DATUM(0); + Encap* cap = (Encap*)PG_GETARG_DATUM(1); + VectorBatch* batch = cap->batch; + int i = 0; + int rows = batch->m_rows; + int cellSize = node->cellSize; + GUCell* cell = NULL; + void** container = node->container; + VarBuf* currentBuf = node->currentBuf; + uint16* idx = &(node->idx); + + for (i = 0; i < rows; i++) { + cell = (GUCell*)container[*idx]; + if (cell == NULL || !Match(cap, i, cell)) { + // means we got match fail + if (cell != NULL) { + (*idx)++; + if (*idx == BatchMaxSize) { + // switch buffer + VarBuf* tmp; + tmp = node->currentBuf; + node->currentBuf = node->bckBuf; + node->bckBuf = tmp; + currentBuf = node->currentBuf; + } + } + cell = (GUCell*)currentBuf->Allocate(cellSize); + container[*idx] = cell; + + InitCellValue(cap, cell, i, currentBuf); + } + } + + PG_FREE_IF_COPY(node, 0); + PG_FREE_IF_COPY(cap, 1); + + PG_RETURN_DATUM(0); +} + +Datum BuildScanBatch(PG_FUNCTION_ARGS); + +template +static void BindingFp(T* node) +{ + node->buildScanFunc->fn_addr = BuildScanBatch; + if (node->keySimple) { + node->buildFunc->fn_addr = BuildFunc; + } else { + node->buildFunc->fn_addr = BuildFunc; + } +} + +template +static void ReplaceGrpUniqEqfunc(Encap* cap, Form_pg_attribute* attrs) +{ + AttrNumber* colIdx = cap->colIdx; + FmgrInfo* eqfunctions = cap->eqfunctions; + + for (int i = 0; i < cap->cols; i++) { + switch (attrs[colIdx[i] - 1]->atttypid) { + case TIMETZOID: + eqfunctions[i].fn_addr = timetz_eq_withhead; + break; + case TINTERVALOID: + eqfunctions[i].fn_addr = tintervaleq_withhead; + break; + case INTERVALOID: + eqfunctions[i].fn_addr = interval_eq_withhead; + break; + case NAMEOID: + eqfunctions[i].fn_addr = nameeq_withhead; + break; + default: + break; + } + } +} + +template +void InitGrpUniq(T* state, int cols, AttrNumber* colIdx) +{ + int i = 0; + Encap* cap = (Encap*)state->cap; + + // Initialize the variables used in Vector execution process and bind the function in FmgrInfo. + state->idx = 0; + state->keySimple = true; + state->container = (void**)palloc0(2 * BatchMaxSize * sizeof(GUCell*)); + + TupleDesc outDesc = outerPlanState(state)->ps_ResultTupleSlot->tts_tupleDescriptor; + state->cellSize = offsetof(GUCell, val) + outDesc->natts * sizeof(GUCellVal); + cap->cols = cols; + cap->outerCols = outDesc->natts; + cap->colIdx = colIdx; + cap->eqfunctions = state->eqfunctions; + Form_pg_attribute* attrs = outDesc->attrs; + + for (i = 0; i < cap->outerCols; i++) { + if (COL_IS_ENCODE(attrs[i]->atttypid)) { + state->keySimple = false; + break; + } + } + + ReplaceGrpUniqEqfunc(cap, attrs); + + state->scanBatch = New(CurrentMemoryContext) VectorBatch(CurrentMemoryContext, outDesc); + state->currentBuf = New(CurrentMemoryContext) VarBuf(CurrentMemoryContext); + state->currentBuf->Init(); + state->bckBuf = New(CurrentMemoryContext) VarBuf(CurrentMemoryContext); + state->bckBuf->Init(); + state->buildFunc = (FmgrInfo*)palloc0(sizeof(FmgrInfo)); + state->buildScanFunc = (FmgrInfo*)palloc0(sizeof(FmgrInfo)); + BindingFp(state); +} + +template +void ReScanGrpUniq(T* node) +{ + errno_t rc; + // clear the container and buffers which will be used in the next scan with a clean status. + rc = memset_s(node->container, 2 * BatchMaxSize * sizeof(GUCell*), 0, 2 * BatchMaxSize * sizeof(GUCell*)); + securec_check(rc, "\0", "\0"); + node->idx = 0; + node->currentBuf->Reset(); +} + +#endif /* VECGRPUNIQ_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vechashagg.h postgresql-hll-2.14/include/include/vecexecutor/vechashagg.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vechashagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vechashagg.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashagg.h + * hash agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vechashagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHAGG_H_ +#define VECHASHAGG_H_ + +#include "vecexecutor/vecagg.h" + +struct AggStateLog { + bool restore; + hashCell* lastCell; + int lastIdx; + int lastSeg; +}; + +class HashAggRunner : public BaseAggRunner { +public: + HashAggRunner(VecAggState* runtime); + ~HashAggRunner(){}; + + bool ResetNecessary(VecAggState* node); + + /* Wrap allocate new hash cell and initialization */ + template + void AllocHashSlot(VectorBatch* batch, int i); + void HashTableGrowUp(); + +private: + /* Different build function, if we exceed the threshold in memory row number,we need to flush to the disk.*/ + template + void buildAggTbl(VectorBatch* batch); + + void Build(); + + VectorBatch* Probe(); + + /* Hash based aggregation.*/ + VectorBatch* Run(); + + /* Get the hash source.*/ + hashSource* GetHashSource(); + + void BindingFp(); + + template + int64 computeHashTableSize(int64 newsize); + ScalarValue getHashValue(hashCell* hashentry); + + FORCE_INLINE uint32 get_bucket(uint32 hashvalue) + { + return hashvalue & (m_hashSize - 1); + } + + template + void dyHashSlotTmp(VectorBatch* batch, int i, int hash_idx, int start_idx); + + void GetPosbyLoc(uint64 idx, int* nseg, int64* pos); + + template + void BuildHashTable(int64 oldsize); + + void Profile(char* stats, bool* can_wlm_warning_statistics); + +private: + /* Some status log.*/ + AggStateLog m_statusLog; + + /* Hash source.*/ + hashSource* m_hashSource; + + /* Hash value to store.*/ + ScalarValue m_hashVal[BatchMaxSize]; + int m_fileIdx; + bool m_can_grow; /* mark weather can grow up */ + int64 m_max_hashsize; /* memory allowed max hashtable size */ + int64 m_grow_threshold; /* the threshold to grow up */ + double m_hashbuild_time; + double m_hashagg_time; + MemoryContext m_hashcell_context; /* stack context for hashcell */ + HashSegTbl* m_hashData; /*hashagg table */ + int m_segnum; /* segment number */ + int m_hashseg_max; /* max hashsize for one segment */ + int64 m_hashSize; /* total hash size */ + void (HashAggRunner::*m_buildFun)(VectorBatch* batch); + int m_spill_times; /* spill time */ +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vechashjoin.h postgresql-hll-2.14/include/include/vecexecutor/vechashjoin.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vechashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vechashjoin.h 2020-12-12 17:06:43.298348696 +0800 @@ -0,0 +1,341 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashjoin.h + * Prototypes for vectorized hash join + * + * IDENTIFICATION + * src/include/vecexecutor/vechashjoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHJOIN_H_ +#define VECHASHJOIN_H_ + +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecnodes.h" +#include "workload/workload.h" +// hash join runtime state +#define HASH_BUILD 0 +#define HASH_PROBE 1 +#define HASH_END 2 + +typedef enum { + HASH_JOIN_INNER = 0, + HASH_JOIN_LEFT, + HASH_JOIN_RIGHT, + HASH_JOIN_SEMI, + HASH_JOIN_ANTI, + HASH_JOIN_RIGHT_SEMI, + HASH_JOIN_RIGHT_ANTI, + HASH_JOIN_LEFT_ANTI_FULL, + HASH_JOIN_RIGHT_ANTI_FULL, + HASH_JOIN_TYPE_NUM +} hashJoinType; + +// hash strategy +#define MEMORY_HASH 0 +#define GRACE_HASH 1 + +// probe status +#define PROBE_FETCH 0 +#define PROBE_PARTITION_FILE 1 +#define PROBE_DATA 2 +#define PROBE_FINAL 3 +#define PROBE_PREPARE_PAIR 4 + +extern VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int eflags); +extern VectorBatch* ExecVecHashJoin(VecHashJoinState* node); +extern void ExecEndVecHashJoin(VecHashJoinState* node); +extern void ExecReScanVecHashJoin(VecHashJoinState* node); +extern long ExecGetMemCostVecHash(VecHashJoin*); +extern void ExecEarlyFreeVecHashJoin(VecHashJoinState* node); + +// Save current probing place for next join iteration +// +struct JoinStateLog { + int lastBuildIdx; + hashCell* lastCell; + bool restore; +}; + +// Record hash key matching passed cells +// +struct ReCheckCellLoc { + hashCell* cell; + int resultIdx; + int oriIdx; +}; + +// Vectorized hash join implementation class +// +class HashJoinTbl : public hashBasedOperator { +public: + HashJoinTbl(VecHashJoinState* runtimeContext); + + void Build(); + + VectorBatch* Probe(); + + void ResetNecessary(); + +public: + // number of columns in outer child + // + int m_outCols; + + // list of join keys in outer child + // + int* m_outKeyIdx; + + // list of original value of varattno on join keys in outer child + int* m_outOKeyIdx; + + // list of OID of collation on join keys in outer child + Oid* m_outKeyCollation; + + // a list for cache the data. + List* m_cache; + + // the status flag to indicate the probe. + int m_probeStatus; + + bool m_complicateJoinKey; + + // the cjVector is only alloced and used when m_complicateJoinKey is true + // + ScalarVector* m_cjVector; + + // out batch is simple + bool m_outSimple; + + // inner batch is simple + bool m_innerSimple; + + // whether check the key match + bool m_doProbeData; + + // inner batch + VectorBatch* m_innerBatch; + + // outer batch + VectorBatch* m_outerBatch; + + // complicate inner batch + VectorBatch* m_complicate_innerBatch; + + // complicate outer batch + VectorBatch* m_complicate_outerBatch; + + // inner qual batch + VectorBatch* m_inQualBatch; + + // outer qual batch + VectorBatch* m_outQualBatch; + + // out raw batch + VectorBatch* m_outRawBatch; + + VectorBatch* m_result; + + // runtime state + VecHashJoinState* m_runtime; + + // hash Join type. + hashJoinType m_joinType; + + // memory hash or grace hash + int m_strategy; + + JoinStateLog m_joinStateLog; + // prob source + hashOpSource* m_probOpSource; // prob source + + ReCheckCellLoc m_reCheckCell[BatchMaxSize]; + + // flag the row match + bool m_match[BatchMaxSize]; + + int m_probeIdx; + + // for null-eq special case + bool m_nulleqmatch[BatchMaxSize]; + + // build file source + hashFileSource* m_buildFileSource; + + // probe file source + hashFileSource* m_probeFileSource; + + bool* m_simpletype; + + Oid* m_outerkeyType; + + /* partition level of each file source: for repartition process */ + uint8* m_pLevel; + + /* maximum partition level need to be paid attention */ + uint8 m_maxPLevel; + + /* partition is from a valid repartition process or not: for repartition process */ + bool* m_isValid; + + /* Point to cell in semiJoin, in order to return value of righttree.*/ + hashCell** cellPoint; + + /* Print warning message after partitioned three times */ + bool m_isWarning; + + double m_build_time; + double m_probe_time; + +private: + void SetJoinType(); + void PrepareProbe(); + + template + void buildHashTable(hashSource* source, int64 rownum); + + template + void bindingFp(); + + // prepare for disk hash. + void initFile(bool buildSide, VectorBatch* templateBatch, int fileNum); + + // probe the in memory hash table. + VectorBatch* probeMemory(); + + // probe the hash table in a grace way. + VectorBatch* probeGrace(); + + // probe in memory hash table + VectorBatch* probeHashTable(hashSource* probSource); + + // probe the partition. + template + void probePartition(); + + /* repartition file source of a specific file */ + template + void RePartitionFileSource(hashFileSource* hashSource, int fileIdx); + + /* record partition info into log file */ + void recordPartitionInfo(bool buildside, int fileIdx, int istart, int iend); + + // prepare the partition join. + void preparePartition(); + + // init memory control parameter + void initMemoryControl(); + + // calc the spilling file. + int calcSpillFile(); + + // end hash join + VectorBatch* endJoin(); + + // build result batch. + VectorBatch* buildResult(VectorBatch* inBatch, VectorBatch* outBatch, bool checkqual); + + bool* checkQual(VectorBatch* inBatch, VectorBatch* outBatch); + + // match key + + template + void matchKey(ScalarVector* key, int nrows, int hashValKeyIdx, int key_num); + + bool simpletype(Oid type); + + void matchComplicateKey(VectorBatch* batch); + + void DispatchKeyInnerFunction(int KeyIdx); + + template + void DispatchKeyOuterFunction(int KeyIdx); + + // different join function + // full join + template + VectorBatch* innerJoinT(VectorBatch* batch); + + template + VectorBatch* leftJoinT(VectorBatch* batch); + + template + VectorBatch* leftJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightJoinT(VectorBatch* batch); + + template + VectorBatch* rightJoinWithQualT(VectorBatch* batch); + + // semi join + template + VectorBatch* semiJoinT(VectorBatch* batch); + + template + VectorBatch* semiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* antiJoinT(VectorBatch* batch); + + template + VectorBatch* antiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightSemiJoinT(VectorBatch* batch); + + template + VectorBatch* rightSemiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightAntiJoinT(VectorBatch* batch); + + template + VectorBatch* rightAntiJoinWithQualT(VectorBatch* batch); + + void PushDownFilterIfNeed(); + +private: + // build function array. + void (HashJoinTbl::*m_funBuild[2])(VectorBatch* batch); // the build function; + + void CalcComplicateHashVal(VectorBatch* batch, List* hashKeys, bool inner); + + bool HasEnoughMem(int nrows); + + template + void SaveToMemory(VectorBatch* batch); + + template + void flushToDisk(); + + template + void SaveToDisk(VectorBatch* batch); + + VectorBatch* (HashJoinTbl::*m_probeFun[2])(); // the probe function; + + VectorBatch* (HashJoinTbl::*m_joinFun)(VectorBatch* batch); // join function + + VectorBatch* (HashJoinTbl::*m_joinFunArray[36])(VectorBatch* batch); + + typedef void (HashJoinTbl::*pMatchKeyFunc)(ScalarVector* key, int nrows, int hashValKeyIdx, int key_num); + + pMatchKeyFunc* m_matchKeyFunction; +}; + +#endif /* VECHASHJOIN_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vechashtable.h postgresql-hll-2.14/include/include/vecexecutor/vechashtable.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vechashtable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vechashtable.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,697 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashtable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vechashtable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHTABLE_H_ +#define VECHASHTABLE_H_ + +#include "vecexecutor/vectorbatch.h" +#include "nodes/execnodes.h" +#include "access/hash.h" +#include "storage/buffile.h" +#include "utils/memutils.h" +#include "utils/batchsort.h" +#include "utils/memprot.h" + +#ifdef USE_ASSERT_CHECKING +#define HASH_BASED_DEBUG(A) A /* for debug only */ +#else +#define HASH_BASED_DEBUG(A) +#endif + +/* hash key type */ +typedef uint32 HashKey; +class vechashtable; + +// row base hash value +struct hashVal { + ScalarValue val; + uint8 flag; +}; + +// we do not store the column number and row number here +// as it is duplicate information, we can remember it outside the struct. +struct hashCell { + union { + hashCell* m_next; + int m_rows; + } flag; + + hashVal m_val[FLEXIBLE_ARRAY_MEMBER]; // data begins here +}; + +typedef struct HashSegTbl { + int tbl_size; // hash table size + hashCell** tbl_data; // hash table data. +} HashSegTbl; + +#define GET_NTH_CELL(cellHead, i) (hashCell*)((char*)cellHead + i * m_cellSize) +#define CELL_NTH_VAL(cell, i) (cell)->m_val[i].val +#define CELL_NTH_FLAG(cell, i) (cell)->m_val[i].flag +#define FILL_FACTOR 1.2 +#define MHASH_FUN 0 // for in memory hash function +#define DHASH_FUN 1 // decide which partition the value will store in temp file +#define INNER_SIDE 0 // for use inner hash function +#define OUTER_SIDE 1 // for use outer hash function +#define MIN_HASH_TABLE_SIZE 4096 +#define MAX_BUCKET_NUM (MaxAllocSize / sizeof(hashCell*) - 1) +#define MAX_LOG_LEN 1024 + +#define HASH_PREFETCH_DISTANCE 10 + +#define HASH_VARBUFSIZE 2 * 1024 * 1024 // 2M for buf +#define SCALAR_FUN 0 +#define VAR_FUN 1 + +#define HASH_IN_MEMORY 0 +#define HASH_IN_DISK 1 +#define HASH_RESPILL 2 + +#define HASH_EXPAND_THRESHOLD 2 /* threshold for hashtable expanding */ +#define HASH_EXPAND_SIZE 2 + +class hashSource : public BaseObject { +public: + virtual VectorBatch* getBatch() + { + Assert(false); + return NULL; + } + + virtual hashCell* getCell() + { + Assert(false); + return NULL; + } + + virtual void close(int idx) + { + Assert(false); + } + + virtual TupleTableSlot* getTup() + { + Assert(false); + return NULL; + } + + virtual ~hashSource() + {} +}; + +class hashOpSource : public hashSource { +public: + hashOpSource(PlanState* op); + ~hashOpSource(){}; + + VectorBatch* getBatch(); + + int64 getFileSize(); + + TupleTableSlot* getTup(); + + void close(int idx) + { + return; + } + +private: + // data source operator; + PlanState* m_op; +}; + +typedef ScalarValue (*stripValFun)(ScalarValue* val); + +class hashMemSource : public hashSource { +public: + hashMemSource(List* data); + ~hashMemSource(){}; + + hashCell* getCell(); + +private: + List* m_list; + + ListCell* m_cell; +}; + +class hashFileSource : public hashSource { +public: + hashFileSource(VectorBatch* batch, MemoryContext context, int cellSize, hashCell* cellArray, bool complicateJoin, + int m_write_cols, int fileNum, TupleDesc tupleDescritor); + + hashFileSource(TupleTableSlot* hashslot, int fileNum); + ~hashFileSource(){}; + + TupleTableSlot* getTup(); + + void writeTup(MinimalTupleData* Tup, int idx); + + void rewind(int idx); + + void close(int idx); + + void closeAll(); + + void freeFileSource(); + + void setCurrentIdx(int idx); + + int getCurrentIdx(); + + int64 getCurrentIdxRownum(int64 rows_in_mem); + + bool next(); + + void enlargeFileSource(int fileNum); + + void writeCell(hashCell* cell, HashKey key); + void writeBatch(VectorBatch* batch, int idx, HashKey key); + void writeBatchToFile(VectorBatch* batch, int idx, int fileIdx); + + void writeBatchWithHashval(VectorBatch* batch, int idx, HashKey key); + void writeBatchWithHashval(VectorBatch* batch, int idx, HashKey key, int fileIdx); + + void resetFileSource(); + + void initFileSource(int fileNum); + + VectorBatch* getBatch(); + + int64 getFileSize(); + + hashCell* getCell(); + + void resetVariableMemberIfNecessary(int fileNum); + + /* release the buffer in file handler if necessary */ + void ReleaseFileHandlerBuffer(int fileIdx); + void ReleaseAllFileHandlerBuffer(); + + /* prepare the buffer in file handler if necessary */ + void PrepareFileHandlerBuffer(int fileIdx); + +public: + int m_cellSize; + + int64* m_rownum; + + int64 m_total_filesize; + + int64* m_spill_size; + + int64* m_fileSize; + + int m_cols; + + int m_write_cols; // just for right join + + int* m_funType; + + VectorBatch* m_batch; + + hashCell* m_cellArray; // a bunch of cell + + MemoryContext m_context; + + void** m_file; + + TupleTableSlot* m_hashTupleSlot; + + MinimalTuple m_tuple; + + uint32 m_tupleSize; + + int m_currentFileIdx; + + int m_fileNum; + + Datum* m_values; + + bool* m_isnull; + + uint32 m_varSpaceLen; + + stripValFun* m_stripFunArray; + + size_t (hashFileSource::*m_write[2])(ScalarValue val, uint8 flag, int idx); + + size_t (hashFileSource::*m_read[2])(ScalarValue* val, uint8* flag); + + size_t (hashFileSource::*m_writeTuple)(MinimalTupleData* Tup, int idx); + + TupleTableSlot* (hashFileSource::*m_getTuple)(); + + hashCell* (hashFileSource::*m_getCell)(); + + void (hashFileSource::*m_rewind)(int idx); + void (hashFileSource::*m_close)(int idx); + + size_t (hashFileSource::*m_writeCell)(hashCell* cell, int idx); + + size_t (hashFileSource::*m_writeBatch)(VectorBatch* batch, int idx, int fileIdx); + + VectorBatch* (hashFileSource::*m_getBatch)(); + + size_t (hashFileSource::*m_writeBatchWithHashval)(VectorBatch* batch, int idx, HashKey key, int fileIdx); + +private: + // write the value from the file. + template + size_t writeScalar(ScalarValue val, uint8 flag, int fileIdx); + template + size_t writeVar(ScalarValue val, uint8 flag, int fileIdx); + + // read the value from the file. + template + size_t readScalar(ScalarValue* val, uint8* flag); + template + size_t readVar(ScalarValue* val, uint8* flag); + + size_t writeBatchNoCompress(VectorBatch* batch, int idx, int fileIdx); + + size_t writeBatchCompress(VectorBatch* batch, int idx, int fileIdx); + + void assembleBatch(TupleTableSlot* slot, int idx); + + template + VectorBatch* getBatchCompress(); + + template + VectorBatch* getBatchNoCompress(); + + void rewindCompress(int idx); + void rewindNoCompress(int idx); + void closeCompress(int idx); + void closeNoCompress(int idx); + + template + size_t writeCellNoCompress(hashCell* cell, int fileIdx); + + template + size_t writeCellCompress(hashCell* cell, int fileIdx); + + template + hashCell* getCellNoCompress(); + + template + hashCell* getCellCompress(); + + template + size_t writeTupCompress(MinimalTupleData* Tup, int idx); + + template + TupleTableSlot* getTupCompress(); + + template + size_t writeBatchWithHashvalCompress(VectorBatch* batch, int idx, HashKey key, int fileIdx); +}; + +class hashSortSource : public hashSource { +public: + hashSortSource(Batchsortstate* batchSortState, VectorBatch* sortBatch); + ~hashSortSource(){}; + + VectorBatch* getBatch(); + + VectorBatch* m_SortBatch; + +private: + Batchsortstate* m_batchSortStateIn; +}; + +inline int getPower2LessNum(int num) +{ + int i = 1; + int count = 0; + + for (;;) { + num = num / 2; + if (num == 0) + break; + count++; + } + i <<= count; + + return i; +} + +inline int getPower2NextNum(int num) +{ + int i = 1; + int count = 0; + + // guard too long number + if (num > INT_MAX / 2) + num = INT_MAX / 2; + + num = num - 1; + for (;;) { + num = num / 2; + if (num == 0) + break; + count++; + } + + i <<= (count + 1); + return i; +} + +/* we need split the hash table implementation and some hash-based + * operator common structure. */ +class hashBasedOperator : public BaseObject { +public: + hashBasedOperator() : m_spillToDisk(false), m_rows(0), m_totalMem(0), m_availmems(0) + { + m_filesource = NULL; + m_innerHashFuncs = NULL; + m_key = 0; + m_cols = 0; + m_sysBusy = false; + m_outerHashFuncs = NULL; + m_overflowsource = NULL; + m_hashContext = NULL; + m_keyDesc = NULL; + m_tupleCount = 0; + m_hashTbl = NULL; + m_colWidth = 0; + m_cellSize = 0; + m_tmpContext = NULL; + m_colDesc = NULL; + m_spreadNum = 0; + m_okeyIdx = NULL; + m_fill_table_rows = 0; + m_keyIdx = NULL; + m_keySimple = false; + m_eqfunctions = NULL; + m_strategy = 0; + m_maxMem = 0; + } + + virtual ~hashBasedOperator() + {} + + // build a hash table + virtual void Build() = 0; + + // probe the hash table. + virtual VectorBatch* Probe() = 0; + + // create temprorary file. + hashFileSource* CreateTempFile(VectorBatch* batch, int fileNum, PlanState* planstate); + + // close temprorary file. + void closeFile(); + + FORCE_INLINE + int64 getRows() + { + return m_rows; + } + + int getFileNum() + { + if (m_filesource != NULL) + return m_filesource->m_fileNum; + else + return 0; + } + + int calcFileNum(long numGroups); + + // replace some equal function. + void ReplaceEqfunc(); + + // judge memory over flow. + void JudgeMemoryOverflow(char* opname, int planid, int dop, Instrumentation* instrument = NULL); + + /* judge memory allow table expnd */ + bool JudgeMemoryAllowExpand(); + + // free memory context. + void freeMemoryContext(); + + // simple hash function without string type in the key + template + void hashCellT(hashCell* cell, int keyIdx, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes); + + template + void hashColT(ScalarVector* val, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes); + + inline void hashBatch( + VectorBatch* batch, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill = false); + + inline void hashCellArray( + hashCell* cell, int nrows, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill = false); + +public: + vechashtable* m_hashTbl; + + // memory context for hash. + MemoryContext m_hashContext; + + // memory context for temprorary calculation. + MemoryContext m_tmpContext; + + /* memory context for hashtable and hashcell. + * need not free and apply memory again, only do reset when rescan. + */ + + // cache location + ScalarValue m_cacheLoc[BatchMaxSize]; + + hashCell* m_cellCache[BatchMaxSize]; + + // flag the key match + bool m_keyMatch[BatchMaxSize]; + + FmgrInfo* m_eqfunctions; /* equal function */ + + FmgrInfo* m_outerHashFuncs; /* lookup data for hash functions */ + + FmgrInfo* m_innerHashFuncs; /* lookup data for hash functions */ + + // spilling file. + hashFileSource* m_filesource; + + hashFileSource* m_overflowsource; + + // whether spill to disk. + bool m_spillToDisk; + + // memory or disk. + int m_strategy; + + // how many rows in hash table + int64 m_rows; + + /*total memory, in bytes*/ + int64 m_totalMem; + + /*avail memory */ + int64 m_availmems; + + // how many cols in the hash table. + int m_cols; + + // how many key in the hash table. + int m_key; + + int* m_keyIdx; /* list of varattno on hash keys. */ + int* m_okeyIdx; /* list of original value of varattno on hash keys. */ + + ScalarDesc* m_keyDesc; // indicate key desc + + ScalarDesc* m_colDesc; // indicate col desc; + + // whether the key is simple. 1:is simple 2: not simple + // simple means there is no variable length data type or complex expression evaluation. + bool m_keySimple; + + int m_cellSize; + + /* row numbers in memory of first spill */ + int m_fill_table_rows; + + /* records avg width of encoded columns in memory */ + int64 m_tupleCount; + int64 m_colWidth; + + /* record memory auto spread info */ + int64 m_maxMem; + int m_spreadNum; + + /* If disk spill caused by system resource danger */ + bool m_sysBusy; +}; + +// chain +class vechashtable : public BaseObject { +public: + vechashtable(int hashSize) : m_size(hashSize), m_data(0) + { + m_data = (hashCell**)palloc0(m_size * sizeof(hashCell*)); + } + // depend the sub class to init the member variable. + ~vechashtable() + { + if (m_data) + pfree(m_data); + + m_data = NULL; + m_size = 0; + } + + void Reset() + { + Assert(m_size != 0); + m_data = (hashCell**)palloc0(m_size * sizeof(hashCell*)); + } + + void Profile(char* stats, bool* can_wlm_warning_statistics); + +public: + int m_size; // hash table size + + hashCell** m_data; // hash table data. +}; + +#define GET_HASH_TABLE(node) (((vechashtable*)(node->hashTbl))) + +// simple hash function without string type in the key +template +inline void hashBasedOperator::hashCellT(hashCell* cell, int keyIdx, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes) +{ + hashVal val; + ScalarValue hashV; + FunctionCallInfoData fcinfo; + Datum args[2]; + fcinfo.arg = &args[0]; + fcinfo.flinfo = hashFmgr; + PGFunction func = hashFmgr->fn_addr; + + for (int j = 0; j < nval; j++) { + val = cell->m_val[keyIdx]; + if (likely(NOT_NULL(val.flag))) { + fcinfo.arg[0] = val.val; + if (reHash) { + /* rotate hashkey left 1 bit at each rehash step */ + hashV = hashRes[j]; + hashV = (hashV << 1) | ((hashV & 0x80000000) ? 1 : 0); + hashV ^= func(&fcinfo); + hashRes[j] = hashV; + } else + hashRes[j] = func(&fcinfo); + } else { + if (!reHash) + hashRes[j] = 0; // give the init value; + } + + cell = (hashCell*)((char*)cell + m_cellSize); + } +} + +// simple hash function without string type in the key +template +inline void hashBasedOperator::hashColT(ScalarVector* val, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes) +{ + ScalarValue* value = val->m_vals; + uint8* flag = val->m_flag; + FunctionCallInfoData fcinfo; + Datum args[2]; + fcinfo.arg = &args[0]; + fcinfo.flinfo = hashFmgr; + PGFunction func = hashFmgr->fn_addr; + ScalarValue hashV; + + for (int j = 0; j < nval; j++) { + if (likely(NOT_NULL(flag[j]))) { + fcinfo.arg[0] = value[j]; + if (reHash) { + /* rotate hashkey left 1 bit at each rehash step */ + hashV = hashRes[j]; + hashV = (hashV << 1) | ((hashV & 0x80000000) ? 1 : 0); + hashV ^= func(&fcinfo); + hashRes[j] = hashV; + } else + hashRes[j] = func(&fcinfo); + } else { + if (!reHash) + hashRes[j] = 0; // give the init value; + } + } +} + +inline void hashBasedOperator::hashBatch( + VectorBatch* batch, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill) +{ + int i; + int nrows = batch->m_rows; + ScalarVector* pVector = batch->m_arr; + AutoContextSwitch memGuard(m_tmpContext); + + hashColT(&pVector[keyIdx[0]], hashFmgr, nrows, hashRes); + + for (i = 1; i < m_key; i++) + hashColT(&pVector[keyIdx[i]], (hashFmgr + i), nrows, hashRes); + + /* Rehash the hash value for avoiding the key and distribute key using the same hash function. */ + for (i = 0; i < nrows; i++) { + if (needSpill) + hashRes[i] = hash_new_uint32(DatumGetUInt32(hashRes[i])); + else + hashRes[i] = hash_uint32(DatumGetUInt32(hashRes[i])); + } + + MemoryContextReset(m_tmpContext); +} + +inline void hashBasedOperator::hashCellArray( + hashCell* cell, int nrows, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill) +{ + int i; + AutoContextSwitch memGuard(m_tmpContext); + + hashCellT(cell, keyIdx[0], hashFmgr, nrows, hashRes); + + for (i = 1; i < m_key; i++) + hashCellT(cell, keyIdx[i], (hashFmgr + i), nrows, hashRes); + + /* Rehash the hash value for avoiding the key and distribute key using the same hash function. */ + for (i = 0; i < nrows; i++) { + if (needSpill) + hashRes[i] = hash_new_uint32(DatumGetUInt32(hashRes[i])); + else + hashRes[i] = hash_uint32(DatumGetUInt32(hashRes[i])); + } + + MemoryContextReset(m_tmpContext); +} + +extern ScalarValue addVariable(MemoryContext context, ScalarValue val); +extern ScalarValue replaceVariable(MemoryContext context, ScalarValue oldVal, ScalarValue val); +extern ScalarValue addToVarBuffer(VarBuf* buf, ScalarValue value); +extern void* TempFileCreate(); +extern ScalarValue DatumToScalarInContext(MemoryContext context, Datum datumVal, Oid datumType); + +#endif /* VECHASHTABLE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/veclimit.h postgresql-hll-2.14/include/include/vecexecutor/veclimit.h --- postgresql-hll-2.14_old/include/include/vecexecutor/veclimit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/veclimit.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * veclimit.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/veclimit.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODELIMIT_H +#define VECNODELIMIT_H + +#include "vecexecutor/vecnodes.h" + +extern VectorBatch* ExecVecLimit(VecLimitState* node); +extern VecLimitState* ExecInitVecLimit(VecLimit* node, EState* estate, int eflags); +extern void ExecEndVecLimit(VecLimitState* node); +extern void ExecReScanVecLimit(VecLimitState* node); + +#endif /*VECNODELIMIT_H*/ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecmaterial.h postgresql-hll-2.14/include/include/vecexecutor/vecmaterial.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecmaterial.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecmaterial.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmaterial.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmaterial.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMATERIAL_H +#define VECMATERIAL_H + +#include "vecexecutor/vecnodes.h" + +extern VecMaterialState* ExecInitVecMaterial(VecMaterial* node, EState* estate, int eflags); +extern VectorBatch* ExecVecMaterial(VecMaterialState* node); +extern void ExecEndVecMaterial(VecMaterialState* node); +extern void ExecVecMaterialMarkPos(VecMaterialState* node); +extern void ExecVecMaterialRestrPos(VecMaterialState* node); +extern void ExecVecReScanMaterial(VecMaterialState* node); +extern void ExecEarlyFreeVecMaterial(VecMaterialState* node); + +#endif /* VECMATERIAL_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecmergeinto.h postgresql-hll-2.14/include/include/vecexecutor/vecmergeinto.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecmergeinto.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecmergeinto.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmergeinto.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmergeinto.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMERGEINTO_H +#define VECMERGEINTO_H + +#include "nodes/execnodes.h" + +struct VecModifyTableState; + +extern void ExecVecMerge(VecModifyTableState* mtstate); + +extern void ExecInitVecMerge(ModifyTableState* mtstate, EState* estate, ResultRelInfo* resultRelInfo); + +#endif /* VECMERGEINTO_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecmergejoin.h postgresql-hll-2.14/include/include/vecexecutor/vecmergejoin.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecmergejoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecmergejoin.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmergejoin.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmergejoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMERGEJOIN_H +#define VECMERGEJOIN_H + +#include "nodes/execnodes.h" +#include "executor/nodeMergejoin.h" +extern VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int eflags); +extern VectorBatch* ExecVecMergeJoin(VecMergeJoinState* node); +extern void ExecEndVecMergeJoin(VecMergeJoinState* node); +extern void ExecReScanVecMergeJoin(VecMergeJoinState* node); + +#endif /* EVECMERGEJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecmodifytable.h postgresql-hll-2.14/include/include/vecexecutor/vecmodifytable.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecmodifytable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecmodifytable.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,54 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmodifytable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmodifytable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMODIFYTABLE_H +#define VECMODIFYTABLE_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +extern VecModifyTableState* ExecInitVecModifyTable(VecModifyTable* node, EState* estate, int eflags); + +extern VectorBatch* ExecVecModifyTable(VecModifyTableState* node); + +extern void ExecEndVecModifyTable(VecModifyTableState* node); + +extern void ExecReScanVecModifyTable(VecModifyTableState* node); + +template +extern VectorBatch* ExecVecUpdate( + VecModifyTableState* state, T* update_op, VectorBatch* batch, EState* estate, bool canSetTag, int options); + +template +extern VectorBatch* ExecVecInsert(VecModifyTableState* state, T* insert_op, VectorBatch* batch, VectorBatch* planBatch, + EState* estate, bool canSetTag, int options); + +extern bool checkInsertScanPartitionSame(VecModifyTableState* mtstate); + +struct InsertArg; +extern void* CreateOperatorObject(CmdType operation, bool isPartitioned, Relation resultRelationDesc, + ResultRelInfo* resultRelInfo, EState* estate, TupleDesc sortTupDesc, InsertArg* args, Relation* dataDestRel, + VecModifyTableState* node); + +#endif /* VECMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnestloop.h postgresql-hll-2.14/include/include/vecexecutor/vecnestloop.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnestloop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnestloop.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnestloop.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnestloop.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNESTLOOP_H +#define VECNESTLOOP_H + +#include "vecexecutor/vecnodes.h" + +extern VectorBatch* ExecVecNestloop(VecNestLoopState* node); +extern VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int eflags); +extern void ExecEndVecNestLoop(VecNestLoopState* node); +extern void ExecReScanVecNestLoop(VecNestLoopState* node); + +#define NL_NEEDNEWOUTER 1 +#define NL_NEEDNEXTOUTROW 2 +#define NL_EXECQUAL 3 +#define NL_END 4 + +class VecNestLoopRuntime : public BaseObject { + +public: + VecNestLoopRuntime(VecNestLoopState* runtime); + + template + VectorBatch* JoinT(); + + void Rescan(); + + /* To avoid Coverity Warning: missing_user_dtor */ + virtual ~VecNestLoopRuntime(); + +private: + template + void FetchOuterT(); + + void NextOuterRow(); + + void OutJoinBatchAlignInnerJoinBatch(int rows); + + template + VectorBatch* JoinQualT(); + + template + void InitT(List* joinqual, List* otherqual, ProjectionInfo* projInfo); + + void BindingFp(); + + VectorBatch* (VecNestLoopRuntime::*WrapperBatch)(VectorBatch* batch); + + VectorBatch* (VecNestLoopRuntime::*JoinOnQual)(); + + void (VecNestLoopRuntime::*FetchOuter)(); + +private: + VecNestLoopState* m_runtime; + + // runtime status + // + int m_status; + + // a batch with 1 null row, for left/anti join + // + VectorBatch* m_innerNullBatch; + + // outer batch + // + VectorBatch* m_outerBatch; + + // 1 row from outer batch, but we set for a batch max size + // + VectorBatch* m_outJoinBatch; + + int m_outReadIdx; + + JoinType m_joinType; + + bool m_matched; + + VectorBatch* m_currentBatch; + + VectorBatch* m_bckBatch; + + int m_bufferRows; + + bool m_SimpletargetCol; + + bool m_outerTargetIsNull; + + int m_outJoinBatchRows; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexand.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexand.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexand.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexand.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexand.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexand.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXAND_H +#define VECNODECSTOREINDEXAND_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexAndState* ExecInitCstoreIndexAnd(CStoreIndexAnd* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexAnd(CStoreIndexAndState* node); +extern void ExecEndCstoreIndexAnd(CStoreIndexAndState* node); +extern void ExecReScanCstoreIndexAnd(CStoreIndexAndState* node); + +#endif /* VECNODECSTOREINDEXAND_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexctidscan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexctidscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexctidscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexctidscan.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexctidscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexctidscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXCTIDSCAN_H +#define VECNODECSTOREINDEXCTIDSCAN_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexCtidScanState* ExecInitCstoreIndexCtidScan(CStoreIndexCtidScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecEndCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecReScanCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecInitPartitionForBitmapIndexScan(BitmapIndexScanState* indexstate, EState* estate, Relation rel); + +#endif /* CSTOREINDEXCTIDSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexheapscan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexheapscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexheapscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexheapscan.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexheapscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexheapscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXHEAPSCAN_H +#define VECNODECSTOREINDEXHEAPSCAN_H + +extern CStoreIndexHeapScanState* ExecInitCstoreIndexHeapScan(CStoreIndexHeapScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexHeapScan(CStoreIndexHeapScanState* state); +extern void ExecEndCstoreIndexHeapScan(CStoreIndexHeapScanState* state); +extern void ExecReScanCstoreIndexHeapScan(CStoreIndexHeapScanState* state); + +#endif /* CSTOREINDEXHEAPSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexor.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexor.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexor.h 2020-12-12 17:06:43.299348709 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexor.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexor.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECCSTOREINDEXOR_H +#define VECCSTOREINDEXOR_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexOrState* ExecInitCstoreIndexOr(CStoreIndexOr* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexOr(CStoreIndexOrState* node); +extern void ExecEndCstoreIndexOr(CStoreIndexOrState* node); +extern void ExecReScanCstoreIndexOr(CStoreIndexOrState* node); + +#endif /* VECCSTOREINDEXOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexscan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstoreindexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstoreindexscan.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexscan.h + * + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEINDEXSCAN_H +#define VECNODEINDEXSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" + +// Column index scan interfaces +// +extern CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexScan(CStoreIndexScanState* node); +extern void ExecEndCstoreIndexScan(CStoreIndexScanState* node); +extern void ExecCstoreIndexMarkPos(CStoreIndexScanState* node); +extern void ExecCstoreIndexRestrPos(CStoreIndexScanState* node); +extern void ExecReScanCStoreIndexScan(CStoreIndexScanState* node); + +#endif /* VECNODEINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstorescan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodecstorescan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodecstorescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodecstorescan.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstorescan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstorescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTORESCAN_H +#define VECNODECSTORESCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" +#include "access/cstoreskey.h" +#include "vecexecutor/vecexecutor.h" +#include "executor/executor.h" +#include "utils/memutils.h" + +typedef enum { BTREE_INDEX, BTREE_INDEX_ONLY, PSORT_INDEX, PSORT_INDEX_ONLY } IndexType; + +extern CStoreScanState* ExecInitCStoreScan(CStoreScan* node, Relation parentHeapRel, EState* estate, int eflags, + bool indexFlag = false, bool codegenInUplevel = false); +extern DfsScanState* ExecInitDfsScan( + DfsScan* node, Relation parentHeapRel, EState* estate, int eflags, bool indexFlag = false); +extern VectorBatch* ExecCStoreScan(CStoreScanState* node); +extern VectorBatch* ExecDfsScan(DfsScanState* node); +extern void ExecReScanDfsScan(DfsScanState* node); +extern void ExecEndCStoreScan(CStoreScanState* node, bool indexFlag); +extern void ExecEndDfsScan(DfsScanState* node); +extern void ExecReSetRuntimeKeys(CStoreScanState* node); +extern void ExecReScanCStoreScan(CStoreScanState* node); +extern void ExecCStoreBuildScanKeys(CStoreScanState* state, List* quals, CStoreScanKey* scankeys, int* numScanKeys); +extern void ExecReScanCStoreIndexScan(CStoreIndexScanState* node); + +extern void OptimizeProjectionAndFilter(CStoreScanState* node); + +extern VectorBatch* ApplyProjectionAndFilter( + CStoreScanState* node, VectorBatch* pScanBatch, ExprDoneCond* isDone = NULL); + +extern TupleDesc BuildTupleDescByTargetList(List* tlist); +extern void BuildCBtreeIndexScan(CBTreeScanState* btreeIndexScan, ScanState* scanstate, Scan* node, EState* estate, + Relation indexRel, List* indexqual, List* indexorderby); +extern void BuildCBtreeIndexOnlyScan(CBTreeOnlyScanState* btreeIndexOnlyScan, ScanState* scanstate, Scan* node, + EState* estate, Relation indexRel, List* indexqual, List* indexorderby); +extern Batchsortstate* InitTidSortState(TupleDesc sortTupDesc, int tidAttNo, int sortMem = 0, int maxMem = 0); +extern void PutBatchToSorter(IndexSortState* sort, VectorBatch* batch); +extern bool IsSorterEmpty(IndexSortState* sort); +extern void ResetSorter(IndexSortState* sort); +extern void RunSorter(IndexSortState* sort); +extern void FetchBatchFromSorter(IndexSortState* sort, VectorBatch* tids); +extern void FetchTids(IndexScanDesc scandesc, List* indexScanTargetList, PlanState* ps, IndexSortState* sort, + VectorBatch* tids, bool indexOnly); + +#endif /* NODECSTORESCAN_H */ + diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodedfsindexscan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodedfsindexscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodedfsindexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodedfsindexscan.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodedfsindexscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodedfsindexscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEDFSINDEXSCAN_H +#define VECNODEDFSINDEXSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" + +// Column index scan interfaces +// +extern DfsIndexScanState* ExecInitDfsIndexScan(DfsIndexScan* node, EState* estate, int eflags); +extern VectorBatch* ExecDfsIndexScan(DfsIndexScanState* node); +extern void ExecEndDfsIndexScan(DfsIndexScanState* node); +extern void ExecReScanDfsIndexScan(DfsIndexScanState* node); + +#endif /* VECNODEDFSINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodeforeignscan.h postgresql-hll-2.14/include/include/vecexecutor/vecnodeforeignscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodeforeignscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodeforeignscan.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodeforeignscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodeforeignscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEFOREIGIGNSCAN_H +#define VECNODEFOREIGIGNSCAN_H + +#include "nodes/plannodes.h" +#include "vecexecutor/vecnodes.h" + +extern VecForeignScanState* ExecInitVecForeignScan(VecForeignScan* node, EState* estate, int eflags); + +extern VectorBatch* ExecVecForeignScan(VecForeignScanState* node); + +extern void ExecEndVecForeignScan(VecForeignScanState* node); +extern void ExecReScanVecForeignScan(VecForeignScanState* node); + +#endif /* VECNODEFOREIGIGNSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodemodifytable.h postgresql-hll-2.14/include/include/vecexecutor/vecnodemodifytable.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodemodifytable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodemodifytable.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,28 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodemodifytable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodemodifytable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEMODIFYTABLE_H +#define VECNODEMODIFYTABLE_H + +#endif /* VECNODEMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnoderesult.h postgresql-hll-2.14/include/include/vecexecutor/vecnoderesult.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnoderesult.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnoderesult.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnoderesult.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnoderesult.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODERESULT_H +#define VECNODERESULT_H + +#include "vecexecutor/vecnodes.h" + +extern VecResultState* ExecInitVecResult(VecResult* node, EState* estate, int eflags); +extern VectorBatch* ExecVecResult(VecResultState* node); +extern void ExecEndVecResult(VecResultState* node); +extern void ExecReScanVecResult(VecResultState* node); + +#endif /* NODERESULT_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnoderowtovector.h postgresql-hll-2.14/include/include/vecexecutor/vecnoderowtovector.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnoderowtovector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnoderowtovector.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnoderowtovector.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnoderowtovector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEROWTOVECTOR_H +#define VECNODEROWTOVECTOR_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +extern RowToVecState* ExecInitRowToVec(RowToVec* node, EState* estate, int eflags); +extern VectorBatch* ExecRowToVec(RowToVecState* node); +extern void ExecEndRowToVec(RowToVecState* node); +extern void ExecReScanRowToVec(RowToVecState* node); +extern bool VectorizeOneTuple(VectorBatch* pBatch, TupleTableSlot* slot, MemoryContext transformContext); +#endif /* NODEROWTOVEC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodes.h postgresql-hll-2.14/include/include/vecexecutor/vecnodes.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodes.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,397 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodes.h + * Definition for vector executor state nodes. + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodes.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODES_H_ +#define VECNODES_H_ + +#include "access/dfs/dfs_am.h" +#include "executor/execStream.h" +#include "nodes/execnodes.h" +#include "access/cstore_am.h" +#include "pgxc/execRemote.h" +#include "access/cstoreskey.h" +#ifdef ENABLE_MULTIPLE_NODES +#include "tsdb/common/data_row.h" +#endif + +typedef ScalarVector* (*vecqual_func)(ExprContext* econtext); + +/* runtime bloomfilter */ +typedef struct BloomFilterRuntime { + List* bf_var_list; /* bloomfilter var list. */ + List* bf_filter_index; /* bloomfilter array index. */ + filter::BloomFilter** bf_array; /* bloomfilter array. */ +} BloomFilterRuntime; + +typedef struct VecHashJoinState : public HashJoinState { + int joinState; + + void* hashTbl; + + FmgrInfo* eqfunctions; + + /* + * function pointer to LLVM machine code if hash join qual + * can be LLVM optimiezed. + */ + vecqual_func jitted_joinqual; /* LLVM IR function pointer to point to + * codegened hash->joinqual expr */ + vecqual_func jitted_hashclause; /* LLVM IR function pointer to point to + * codegened hash clause expr */ + + char* jitted_innerjoin; /* jitted inner hash join */ + char* jitted_matchkey; /* jitted matchKey for hash join*/ + char* jitted_buildHashTable; /* jitted buildHashTable*/ + char* jitted_probeHashTable; /* jitted probeHashTable*/ + int enable_fast_keyMatch; /* fast path for key match + * 0 : normal keyMatch + * 1 : one hash clause + * 2 : fast path keyMatch + */ + BloomFilterRuntime bf_runtime; /* runtime bloomfilter */ + char* jitted_hashjoin_bfaddLong; + char* jitted_hashjoin_bfincLong; + + char* jitted_buildHashTable_NeedCopy; +} VecHashJoinState; + +typedef enum VecAggType { + AGG_COUNT = 0, + AGG_SUM, + AGG_AVG, + AGG_MIN, + AGG_MAX, +} VecAggType; + +typedef struct VecAggInfo { + FunctionCallInfoData vec_agg_function; + FunctionCallInfoData vec_final_function; + VectorFunction* vec_agg_cache; + VectorFunction* vec_sonic_agg_cache; + PGFunction* vec_agg_final; +} VecAggInfo; + +typedef struct VecAggState : public AggState { + void* aggRun; + + VecAggInfo* aggInfo; + char* jitted_hashing; /* LLVM function pointer to point to + * the codegened hashing function */ + char* jitted_sglhashing; /* LLVM function pointer to point to + * the codegened hashing function for + * only single hash table case */ + char* jitted_batchagg; /* LLVM function pointer to point to + * the codegened BatchAggregation + * function */ + char* jitted_sonicbatchagg; /* LLVM function pointer to point to + * the codegened BatchAggregation + * with sonic format */ + char* jitted_SortAggMatchKey; /* LLVM jitted function pointer */ + +} VecAggState; + +typedef struct VecWindowAggState : public WindowAggState { + void* VecWinAggRuntime; + VecAggInfo* windowAggInfo; +} VecWindowAggState; + +struct VecGroupState : public GroupState { + void** container; + void* cap; + uint16 idx; + int cellSize; + bool keySimple; + FmgrInfo* buildFunc; + FmgrInfo* buildScanFunc; + VectorBatch* scanBatch; + VarBuf* currentBuf; + VarBuf* bckBuf; + vecqual_func jitted_vecqual; /* LLVM IR function pointer to point to + * codegened grpstate->ss.ps.qual expr */ +}; + +struct VecUniqueState : public UniqueState { + bool uniqueDone; + void** container; + void* cap; + uint16 idx; + int cellSize; + bool keySimple; + FmgrInfo* buildFunc; + FmgrInfo* buildScanFunc; + VectorBatch* scanBatch; + VarBuf* currentBuf; + VarBuf* bckBuf; +}; + +typedef struct VecSetOpState : public SetOpState { + void* vecSetOpInfo; +} VecSetOpState; + +typedef struct VecSortState : public SortState { + VectorBatch* m_pCurrentBatch; + char* jitted_CompareMultiColumn; /* jitted function for CompareMultiColumn */ + char* jitted_CompareMultiColumn_TOPN; /* jitted function for CompareMultiColumn used by Top N sort */ +} VecSortState; + +typedef struct VecRemoteQueryState : public RemoteQueryState { + VectorBatch* resultBatch; + +} VecRemoteQueryState; + +typedef struct VecToRowState VecToRowState; +typedef void (*DevectorizeFun)(VecToRowState* state, ScalarVector* pColumn, int rows, int cols, int i); +typedef struct VecToRowState { + PlanState ps; + + VectorBatch* m_pCurrentBatch; // current active batch in outputing + int m_currentRow; // position to current row in outpting + int nattrs; // number of attributes + TupleTableSlot* tts; // template of the current returning tts + Datum* m_ttsvalues; // column values of the active batch + bool* m_ttsisnull; // indicator if one column value is null + + DevectorizeFun* devectorizeFunRuntime; + +} VecToRowState; + +typedef struct RowToVecState { + PlanState ps; + + bool m_fNoMoreRows; // does it has more rows to output + VectorBatch* m_pCurrentBatch; // current active batch in outputing +} RowToVecState; + +typedef struct VecResultState : public ResultState { +} VecResultState; + +struct VecAppendState : public AppendState { + // Nothing special for vectorized append +}; + +struct VecStreamState; + +typedef void (*assembleBatchFun)(VecStreamState* vsstate, VectorBatch* batch); + +typedef struct VecStreamState : public StreamState { + VectorBatch* m_CurrentBatch; + assembleBatchFun batchForm; + bool redistribute; + int bitNumericLen; + int bitNullLen; + uint32* m_colsType; + +} VecStreamState; + +typedef struct CStoreScanRunTimeKeyInfo { + CStoreScanKey scan_key; + ExprState* key_expr; +} CStoreScanRunTimeKeyInfo; + +typedef struct CStoreScanState : ScanState { + Relation ss_currentDeltaRelation; + Relation ss_partition_parent; + TableScanDesc ss_currentDeltaScanDesc; + bool ss_deltaScan; + bool ss_deltaScanEnd; + + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + CStoreScanRunTimeKeyInfo* m_pScanRunTimeKeys; + int m_ScanRunTimeKeysNum; + bool m_ScanRunTimeKeysReady; + + CStore* m_CStore; + /*Optimizer Information*/ + CStoreScanKey csss_ScanKeys; // support pushing predicate down to cstore scan. + int csss_NumScanKeys; + + // Optimization for access pattern + // + bool m_fSimpleMap; // if it is simple without need to invoke projection code + bool m_fUseColumnRef; // Use column reference without copy to return data + + vecqual_func jitted_vecqual; + + bool m_isReplicaTable; /* If it is a replication table? */ +} CStoreScanState; + +typedef struct DfsScanState : ScanState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + MemoryContext m_scanCxt; + bool m_done; + dfs::reader::ReaderState* m_readerState; + dfs::reader::Reader* m_fileReader; + List* m_splitList; +} DfsScanState; + +class TimeRange; +class TagFilters; +class TsStoreSearch; + +typedef struct TsStoreScanState : ScanState { + /* Determined by upper layer */ + int top_key_func_arg; + bool is_simple_scan; + bool has_sort; + int limit; // If is limit n + AttrNumber sort_by_time_colidx; // If is sort by tstime limit n +#ifdef ENABLE_MULTIPLE_NODES + TagRows* tag_rows; +#endif + bool only_scan_tag; // series function + /* regular member */ + VectorBatch* scanBatch; // batch to work on + VectorBatch* currentBatch; // output batch + Relation ss_partition_parent; + vecqual_func jitted_vecqual; + /* ts special */ + TsStoreSearch* ts_store_search; + int tag_id_num; + bool only_const_col; + bool early_stop; + bool tags_scan_done; // cu data has not been finished + TimeRange* time_range; // time range + int scaned_tuples; + bool first_scan; + +} TsStoreScanState; + +class Batchsortstate; + +typedef struct IndexSortState { + VectorBatch* m_tids; + int64 m_sortCount; + Batchsortstate* m_sortState; + TupleDesc m_sortTupleDesc; + bool m_tidEnd; +} IndexSortState; + +typedef struct CBTreeScanState : IndexScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CBTreeScanState; + +typedef struct CBTreeOnlyScanState : IndexOnlyScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CBTreeOnlyScanState; + +struct CStoreIndexScanState; +struct DfsIndexScanState; +typedef VectorBatch* (*cstoreIndexScanFunc)(CStoreIndexScanState* state); +typedef void (*dfsIndexScanFunc)(DfsIndexScanState* state); + +typedef struct CstoreBitmapIndexScanState : BitmapIndexScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CstoreBitmapIndexScanState; + +typedef struct DfsIndexScanState : DfsScanState { + CStoreScanState* m_indexScan; /* index scan state */ + CBTreeScanState* m_btreeIndexScan; /* cbtree index scan state */ + CBTreeOnlyScanState* m_btreeIndexOnlyScan; /* cbtree index only scan state */ + IndexSortState* m_sort; + List* m_dfsPreparedCols; /* the list of prepared columns(index) */ + bool m_indexonly; /* index only scan flag */ + dfsIndexScanFunc m_dfsIndexScanFunc; +} DfsIndexScanState; + +/* ---------------- + * CstoreIndexScanState information + * A column index scan employees two scan: one for index scan to retrieve + * ctids and the other is the base table scan based on ctids. + */ +typedef struct CStoreIndexScanState : CStoreScanState { + CStoreScanState* m_indexScan; + CBTreeScanState* m_btreeIndexScan; + CBTreeOnlyScanState* m_btreeIndexOnlyScan; + List* m_deltaQual; + bool index_only_scan; + + // scan index and then output tid, these columns in base table + // + int* m_indexOutBaseTabAttr; + int* m_idxInTargetList; + int m_indexOutAttrNo; + cstoreIndexScanFunc m_cstoreIndexScanFunc; +} CStoreIndexScanState; + +typedef struct CStoreIndexCtidScanState : CStoreIndexScanState { + CstoreBitmapIndexScanState* m_cstoreBitmapIndexScan; +} CStoreIndexCtidScanState; + +typedef struct CStoreIndexHeapScanState : CStoreIndexScanState { +} CStoreIndexHeapScanState; + +typedef struct CStoreIndexAndState : public BitmapAndState { + StringInfo resultTids; + uint64 fetchCount; + VectorBatch* m_resultBatch; +} CStoreIndexAndState; + +typedef struct CStoreIndexOrState : public BitmapOrState { + StringInfo resultTids; + uint64 fetchCount; + VectorBatch* m_resultBatch; +} CStoreIndexOrState; + +typedef void (*AddVarFunc)(ScalarVector* vec, Datum v, int row); + +typedef struct VecForeignScanState : public ForeignScanState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + MemoryContext m_scanCxt; + bool m_done; + Datum* m_values; + bool* m_nulls; +} VecForeignScanState; + +typedef struct VecModifyTableState : public ModifyTableState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch +} VecModifyTableState; + +typedef struct VecSubqueryScanState : public SubqueryScanState { +} VecSubqueryScanState; + +struct VecNestLoopState : public NestLoopState { + void* vecNestLoopRuntime; + vecqual_func jitted_vecqual; + vecqual_func jitted_joinqual; +}; + +typedef struct VecPartIteratorState : public PartIteratorState { +} VecPartIteratorState; + +class BatchStore; + +typedef struct VecMaterialState : public MaterialState { + VectorBatch* m_pCurrentBatch; + BatchStore* batchstorestate; + bool from_memory; +} VecMaterialState; + +#endif /* VECNODES_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodesort.h postgresql-hll-2.14/include/include/vecexecutor/vecnodesort.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodesort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodesort.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodesort.h + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodesort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECSORT_H +#define NODEVECSORT_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "workload/workload.h" + +extern VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags); +extern VectorBatch* ExecVecSort(VecSortState* node); +extern void ExecEndVecSort(VecSortState* node); +extern void ExecVecSortMarkPos(VecSortState* node); +extern void ExecVecSortRestrPos(VecSortState* node); +extern void ExecReScanVecSort(VecSortState* node); +extern long ExecGetMemCostVecSort(VecSort*); +extern void ExecEarlyFreeVecSort(VecSortState* node); + +#endif /* NODEVECSORT_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecnodevectorow.h postgresql-hll-2.14/include/include/vecexecutor/vecnodevectorow.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecnodevectorow.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecnodevectorow.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodevectorow.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodevectorow.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECTOROW_H +#define NODEVECTOROW_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +extern VecToRowState* ExecInitVecToRow(VecToRow* node, EState* estate, int eflags); +extern TupleTableSlot* ExecVecToRow(VecToRowState* node); +extern void ExecEndVecToRow(VecToRowState* node); +extern void ExecReScanVecToRow(VecToRowState* node); + +#endif /* NODEVECTOROW_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecpartiterator.h postgresql-hll-2.14/include/include/vecexecutor/vecpartiterator.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecpartiterator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecpartiterator.h 2020-12-12 17:06:43.300348722 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecpartiterator.h + * Partition Iterator is a new execution operator for partition wise join. + * + * IDENTIFICATION + * src/include/vecexecutor/vecpartiterator.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECPARTITERATOR_H +#define VECPARTITERATOR_H + +#include "vecexecutor/vecnodes.h" + +extern VecPartIteratorState* ExecInitVecPartIterator(VecPartIterator* node, EState* estate, int eflags); +extern VectorBatch* ExecVecPartIterator(VecPartIteratorState* node); +extern void ExecEndVecPartIterator(VecPartIteratorState* node); +extern void ExecReScanVecPartIterator(VecPartIteratorState* node); + +#endif /* VECPARTITERATOR_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecplainagg.h postgresql-hll-2.14/include/include/vecexecutor/vecplainagg.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecplainagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecplainagg.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecplainagg.h + * plain agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vecplainagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECPLAINAGG_H +#define VECPLAINAGG_H + +#include "vecexecutor/vecagg.h" + +class PlainAggRunner : public BaseAggRunner { +public: + VectorBatch* Run(); + + PlainAggRunner(VecAggState* runtime); + ~PlainAggRunner(){}; + + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node); + + void endPlainAgg(); + +private: + /* Plain aggregation without group by.*/ + template + VectorBatch* RunPlain(); + + void BindingFp(); + + VectorBatch* (PlainAggRunner::*plainAggregation)(); + + template + void buildPlaintAgg(VectorBatch* outerBatch, bool first_batch); +}; + +#endif /* VECPLAINAGG_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecremotequery.h postgresql-hll-2.14/include/include/vecexecutor/vecremotequery.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecremotequery.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecremotequery.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecremotequery.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecremotequery.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECREMOTEQUERY_H_ +#define VECREMOTEQUERY_H_ + +extern VectorBatch* ExecVecRemoteQuery(VecRemoteQueryState* node); +extern VecRemoteQueryState* ExecInitVecRemoteQuery(VecRemoteQuery* node, EState* estate, int eflags); +extern void ExecEndVecRemoteQuery(VecRemoteQueryState* node); +extern void ExecVecRemoteQueryReScan(VecRemoteQueryState* node, ExprContext* exprCtxt); + +#endif /* VECREMOTEQUERY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecsetop.h postgresql-hll-2.14/include/include/vecexecutor/vecsetop.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecsetop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecsetop.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,170 @@ +/* + * 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; /* number of left-input dups in group */ + long numRight; /* number of right-input dups in group */ +} VecSetOpStatePerGroupData; + +struct SetOpHashCell { + SetOpHashCell* m_next; + VecSetOpStatePerGroupData perGroup; + hashVal m_val[FLEXIBLE_ARRAY_MEMBER]; +}; + +struct SetOpStateLog { + bool restore; /* indicate that the output scanbatch is full, and need to restore one */ + int lastIdx; /* store the last idx in m_setOpHashData */ + int numOutput; /* store the remaining number of ouput for the current cell */ + SetOpHashCell* lastCell; /* store the last SetOpHashCell for the next time to go on processing */ +}; + +class setOpTbl : public hashBasedOperator { +public: + setOpTbl(VecSetOpState* runtime); + ~setOpTbl(){}; + + // reset the environment if necessary when rescan + // + void ResetNecessary(VecSetOpState* node); + + /* the entrance to start build the hashtable */ + void Build(); + + /* probe the established hash table to get the result batch */ + VectorBatch* Probe(); + + /* the function point pointing to execute the mainly task */ + VectorBatch* (setOpTbl::*Operation)(); + +private: + /* bind the function point to the coresponding function */ + void BindingFp(); + + /* hash based Set Operation */ + VectorBatch* RunHash(); + + /* sort based Set Operation */ + template + 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); + + /* get the hash source */ + hashSource* GetHashSource(); + + /* function point to build the hash table */ + void (setOpTbl::*m_BuildFun)(VectorBatch* batch); + + /* function point to build the scan batch for the output result */ + void (setOpTbl::*m_BuildScanBatch)(SetOpHashCell* cell); + + /* the implemental function to build hash table */ + template + void BuildSetOpTbl(VectorBatch* batch); + + /* the function to initialize the hashCell, which is also used to initialize the firstCell in sort strategy */ + template + void InitCell(SetOpHashCell* cell, VectorBatch* batch, int row, int flag); + + /* the function to compare row in batch and cell */ + template + bool MatchKey(VectorBatch* batch, int batchIdx, SetOpHashCell* cell); + + /* the implemental function to build scan batch */ + void BuildScanBatch(SetOpHashCell* cell); + template + int computeHashTableSize(int oldsize); + void HashTableGrowUp(); + + FORCE_INLINE uint32 get_bucket(uint32 hashvalue) + { + return hashvalue & (m_size - 1); + } + template + void AllocHashSlot(VectorBatch* batch, int i, int flag, bool foundMatch, SetOpHashCell* cell); + ScalarValue getHashValue(SetOpHashCell* hashentry); + +private: + VecSetOpState* m_runtime; + + /* the number of output columns, include additional column*/ + int m_outerColNum; + + int m_runState; + + /* flag to identify which side of the input */ + int m_firstFlag; + + /* indicate the flag column added by system */ + AttrNumber m_junkCol; + + hashSource* m_hashSource; + + /* include four types which use different strategy to compute the numOutput */ + int m_cmd; + + /* some status log */ + SetOpStateLog m_statusLog; + + /* the batch for scan the result */ + VectorBatch* m_scanBatch; + + /* this is used to store all heads of SetOpHashCell linked lists like m_data */ + SetOpHashCell** m_setOpHashData; + + /* set op hash table size*/ + int m_size; + + VectorBatch* m_lastBatch; + + int m_max_hashsize; /* memory allowed max hashtable size */ + bool m_can_grow; /* mark weather can grow up */ + int64 m_grow_threshold; /* the threshold to grow up */ +}; + +#define DO_SETOPERATION(tbl) (((setOpTbl*)tbl)->*(((setOpTbl*)tbl)->Operation))() + +#endif /* VECSETOP_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecsortagg.h postgresql-hll-2.14/include/include/vecexecutor/vecsortagg.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecsortagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecsortagg.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,133 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsortagg.h + * sort agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vecsortagg.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef VECSORTAGG_H_ +#define VECSORTAGG_H_ + +#include "vecexecutor/vecagg.h" + +#define GET_MATCH_KEY 0 +#define SORT_MATCH 1 + +#define GET_SOURCE 0 +#define RUN_SORT 1 +#define SWITCH_PARSE 2 + +typedef struct GroupintAtomContainer { + hashCell* sortGrp[2 * BatchMaxSize]; + + /* we need double space for extreme case.*/ + VarBuf* sortBckBuf; + + VarBuf* sortCurrentBuf; + + /* the structure to support the sort group aggregation.*/ + int sortGrpIdx; + +} GroupintAtomContainer; + +class SortAggRunner : public BaseAggRunner { +public: + SortAggRunner(VecAggState* runtime); + ~SortAggRunner(){}; + + void endSortAgg(); + + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node); + +private: + hashSource* GetSortSource(); + + template + void buildSortAgg(VectorBatch* batch); + + void init_phase(); + + void BindingFp(); + + void switch_phase(); + + void init_indexForApFun(); + + template + void FreeSortGrpMem(int num); + + VectorBatch* ReturnData(); + + VectorBatch* ReturnLastData(); + + void BuildNullScanBatch(); + + bool set_group_num(int current_grp); + + VectorBatch* ReturnNullData(); + + void set_key(); + + template + void BatchMatchAndAgg(int current_grp, VectorBatch* batch); + + VectorBatch* RunSort(); + + /* sort aggregation*/ + VectorBatch* Run(); + +private: + bool m_FreeMem; + + bool m_ApFun; + + bool m_noData; + + int m_prepareState; + + /* group state*/ + int m_groupState; + + GroupintAtomContainer* m_sortGrps; + + /* add for AP function*/ + Batchsortstate* m_batchSortIn; + + /* add for AP function*/ + Batchsortstate* m_batchSortOut; + + /* storage result of sort for cube or grouping set*/ + VectorBatch* m_SortBatch; + + hashSource* m_sortSource; + + void (SortAggRunner::*m_buildSortFun)(VectorBatch* batch); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecstore.h postgresql-hll-2.14/include/include/vecexecutor/vecstore.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecstore.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,345 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecstore.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecstore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECSTORE_H +#define VECSTORE_H + +#include "executor/executor.h" +#include "nodes/execnodes.h" +#include "pgstat.h" +#include "storage/buffile.h" +#include "utils/memutils.h" +#include "utils/memprot.h" +#include "utils/datum.h" +#include "vecexecutor/vectorbatch.h" +#include "workload/workload.h" + +/* BatchStore is an opaque type whose details are not known outside + * batchstore.cpp. + * If the first sort column is text or numeric type, allocate one + * more Datum to store the prefixal data for fast compare. + */ + +typedef struct MultiColumns { + Datum* m_values; + uint8* m_nulls; + + int idx; + int size; + + int GetLen(int colNum); + +} MultiColumns; + +/* + * The data of those column to be sorted or unsorted + */ +typedef struct MultiColumnsData { + + MultiColumns* m_memValues; + + /* + * The number of columns + */ + int m_colNum; + + /* + * The capacity of storing row in memory + */ + int m_capacity; + + /* + * The current row number in memory + */ + int m_memRowNum; + + /* + * Initialize variables + */ + void Init(int capacity); + + bool HasFreeSlot(); + + void PutValue(MultiColumns val); + + inline MultiColumns* GetValue(int row); + +} MultiColumnsData; + +class VecStore : public BaseObject { +public: + char* GetData(int colNum, MultiColumns* multiColumn); + void SetData(char* dataPtr, int size, MultiColumns* multiColumn); + void InitColInfo(VectorBatch* batch); + + bool HasFreeSlot(); + + void PutValue(MultiColumns multiColumn); + + void UseMem(int64 size); + + void FreeMem(int64 size); + + bool LackMem(); + + bool GrowMemValueSlots(char* opname, int planid, MemoryContext context); + + void AppendBatch(VectorBatch* batch, MultiColumns& multiColumn, int curRow, bool isfree = true); + + /* + * abbreSortOptimize used to mark whether allocate one more Datum for + * fast compare of two data(text or numeric type) + */ + template + MultiColumns CopyMultiColumn(VectorBatch* batch, int row) + { + MultiColumns multiColValue; + m_colNum = batch->m_cols; + if (abbreSortOptimize) + multiColValue.m_values = (ScalarValue*)palloc((batch->m_cols + 1) * sizeof(Datum)); + else + multiColValue.m_values = (ScalarValue*)palloc(batch->m_cols * sizeof(Datum)); + UseMem(GetMemoryChunkSpace(multiColValue.m_values)); + + multiColValue.m_nulls = (uint8*)palloc(batch->m_cols * sizeof(uint8)); + UseMem(GetMemoryChunkSpace(multiColValue.m_nulls)); + if (m_addWidth) + m_colWidth += batch->m_cols * sizeof(Datum) + batch->m_cols * sizeof(uint8); + multiColValue.size = 0; + uint8 flag; + + /* + * When faced with NULL, we just skip, in the following produce, we do the same thing. + */ + for (int col = 0; col < batch->m_cols; ++col) { + Form_pg_attribute attr = tupDesc->attrs[col]; + + flag = batch->m_arr[col].m_flag[row]; + multiColValue.m_nulls[col] = flag; + multiColValue.size += sizeof(uint8); + + if (!IS_NULL(flag)) { + if (NeedDecode(col)) { + ScalarValue val = batch->m_arr[col].m_vals[row]; + Datum v = ScalarVector::Decode(val); + multiColValue.m_values[col] = datumCopy(v, attr->attbyval, VARSIZE_ANY(v)); + if (m_addWidth) + m_colWidth += VARSIZE_ANY(v); + char* p = DatumGetPointer(multiColValue.m_values[col]); + UseMem(GetMemoryChunkSpace(p)); + multiColValue.size += datumGetSize(v, attr->attbyval, VARSIZE_ANY(v)); + } else { + multiColValue.m_values[col] = PointerGetDatum(batch->m_arr[col].m_vals[row]); + multiColValue.size += sizeof(Datum); + } + } + } + return multiColValue; + } + + FORCE_INLINE bool NeedDecode(int col) + { + if (m_colInfo[col].m_desc.encoded) + return true; + return false; + } + void FreeMultiColumn(MultiColumns* pMultiColumn); + +public: + MultiColumnsData m_storeColumns; + + /* + * remaining memory allowed, in bytes + */ + int64 m_availMem; + /* + * total memory allowed, in bytes + */ + int64 m_allowedMem; + ScalarVector* m_colInfo; + int m_colNum; + TupleDesc tupDesc; + int64 m_lastFetchCursor; + int64 m_curFetchCursor; + + int64 m_colWidth; + bool m_addWidth; + bool m_sysBusy; + int64 m_maxMem; + int m_spreadNum; + int m_planId; + int m_dop; +}; + +inline bool MultiColumnsData::HasFreeSlot() +{ + return m_memRowNum < m_capacity - 1; +} + +inline void MultiColumnsData::PutValue(MultiColumns val) +{ + m_memValues[m_memRowNum] = val; + ++m_memRowNum; +} + +inline int MultiColumns::GetLen(int colNum) +{ + return size; +} + +inline MultiColumns* MultiColumnsData::GetValue(int row) +{ + return m_memValues + row; +} + +inline void VecStore::UseMem(int64 size) +{ + m_availMem -= size; +} + +inline void VecStore::FreeMem(int64 size) +{ + m_availMem += size; +} + +inline bool VecStore::LackMem() +{ + int64 usedMem = m_allowedMem - m_availMem; + + if (m_availMem < 0 || gs_sysmemory_busy(usedMem * m_dop, true)) + return true; + + return false; +} + +inline bool VecStore::HasFreeSlot() +{ + return m_storeColumns.HasFreeSlot(); +} + +inline bool VecStore::GrowMemValueSlots(char* opname, int planid, MemoryContext context) +{ + double grow_ratio = + Min(DEFAULT_GROW_RATIO, ((double)(MaxAllocSize / sizeof(MultiColumns))) / m_storeColumns.m_capacity); + double unspread_ratio = grow_ratio; + bool need_spread = false; + int64 mem_used = m_allowedMem - m_availMem; + + if (m_availMem < mem_used) + unspread_ratio = Min(unspread_ratio, (double)m_allowedMem / mem_used); + + /* No grow of rows, so return */ + if (m_storeColumns.m_capacity * unspread_ratio <= m_storeColumns.m_capacity) { + if (m_maxMem < m_allowedMem) + return false; + else + need_spread = true; + } else + grow_ratio = unspread_ratio; + + if (gs_sysmemory_busy((m_allowedMem - m_availMem) * m_dop, true)) { + m_sysBusy = true; + AllocSet sortContext = (AllocSet)context; + sortContext->maxSpaceSize = m_allowedMem - m_availMem; + m_allowedMem = m_allowedMem - m_availMem; + MEMCTL_LOG(LOG, + "%s(%d) early spilled, workmem: %ldKB, freemem: %ldKB.", + opname, + planid, + m_allowedMem / 1024L, + m_availMem / 1024L); + pgstat_add_warning_early_spill(); + return false; + } + + /* For concurrent case, we don't allow sort/materialize to spread a lot */ + if (need_spread && (m_spreadNum < 2 || g_instance.wlm_cxt->stat_manager.comp_count == 1)) { + if (m_availMem < 0) + m_allowedMem -= m_availMem; + int64 spreadMem = Min(Min(dywlm_client_get_memory() * 1024L, m_allowedMem), m_maxMem - m_allowedMem); + if (spreadMem <= m_allowedMem * MEM_AUTO_SPREAD_MIN_RATIO) { + MEMCTL_LOG(LOG, + "%s(%d) auto mem spread %ldKB failed, and work mem is %ldKB.", + opname, + planid, + spreadMem / 1024L, + m_allowedMem / 1024L); + if (m_spreadNum > 0) { + pgstat_add_warning_spill_on_memory_spread(); + } + return false; + } + grow_ratio = Min(grow_ratio, 1 + (double)spreadMem / m_allowedMem); + m_allowedMem += spreadMem; + m_availMem = spreadMem; + AllocSet sortContext = (AllocSet)context; + sortContext->maxSpaceSize += spreadMem; + m_spreadNum++; + MEMCTL_LOG(DEBUG2, + "%s(%d) auto mem spread %ldKB succeed, and work mem is %ldKB.", + opname, + planid, + spreadMem / 1024L, + m_allowedMem / 1024L); + } + + /* if there's no more space after grow, then fail */ + if (m_storeColumns.m_capacity * grow_ratio <= m_storeColumns.m_capacity) { + MEMCTL_LOG(LOG, "%s(%d) mem limit reached.", opname, planid); + return false; + } + + if (!gs_sysmemory_avail(mem_used * (grow_ratio - 1))) { + MEMCTL_LOG(LOG, + "%s(%d) mem lack, workmem: %ldKB, freemem: %ldKB," + "usedmem: %ldKB, grow ratio: %.2f.", + opname, + planid, + m_allowedMem / 1024L, + m_availMem / 1024L, + mem_used / 1024L, + grow_ratio); + return false; + } + + FreeMem(GetMemoryChunkSpace(m_storeColumns.m_memValues)); + + m_storeColumns.m_capacity *= grow_ratio; + m_storeColumns.m_memValues = + (MultiColumns*)repalloc(m_storeColumns.m_memValues, m_storeColumns.m_capacity * sizeof(MultiColumns)); + + UseMem(GetMemoryChunkSpace(m_storeColumns.m_memValues)); + + if (m_availMem < 0) + return false; + + return true; +} + +inline void VecStore::PutValue(MultiColumns multiColValue) +{ + m_storeColumns.PutValue(multiColValue); +} + +#endif /* VECSTORE_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecstream.h postgresql-hll-2.14/include/include/vecexecutor/vecstream.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecstream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecstream.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecstream.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecstream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VECNODE_H +#define VECNODE_H + +#include "vecexecutor/vecnodes.h" + +// Extern functions +// +extern void HandleStreamBatch(VecStreamState* node, char* msg, int msg_len); +extern VecStreamState* ExecInitVecStream(Stream* node, EState* estate, int eflags); +extern VectorBatch* ExecVecStream(VecStreamState* node); +extern void ExecEndVecStream(VecStreamState* node); +extern void redistributeStreamInitType(TupleDesc desc, uint32* colsType); + +#endif /* VECNODE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecsubplan.h postgresql-hll-2.14/include/include/vecexecutor/vecsubplan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecsubplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecsubplan.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsubplan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecsubplan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ +#define SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ + +#include "nodes/execnodes.h" + +extern SubPlanState* ExecInitVecSubPlan(SubPlan* subplan, PlanState* parent); + +#endif /* SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecsubqueryscan.h postgresql-hll-2.14/include/include/vecexecutor/vecsubqueryscan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecsubqueryscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecsubqueryscan.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,40 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsubqueryscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecsubqueryscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODESUBQUERYSCAN_H +#define VECNODESUBQUERYSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" + +// Vectorized implementation +// +extern VecSubqueryScanState* ExecInitVecSubqueryScan(VecSubqueryScan* node, EState* estate, int eflags); +extern VectorBatch* ExecVecSubqueryScan(VecSubqueryScanState* node); +extern void ExecEndVecSubqueryScan(VecSubqueryScanState* node); +extern void ExecReScanVecSubqueryScan(VecSubqueryScanState* node); + +#endif /* NODESUBQUERYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vectorbatch.h postgresql-hll-2.14/include/include/vecexecutor/vectorbatch.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vectorbatch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vectorbatch.h 2020-12-12 17:06:43.301348735 +0800 @@ -0,0 +1,593 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectorbatch.h + * Core data structure definition for vector engine. + * + * + * IDENTIFICATION + * src/include/vecexecutor/vectorbatch.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECTORBATCH_H_ +#define VECTORBATCH_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/tupdesc.h" +#include "lib/stringinfo.h" +#include "catalog/pg_type.h" +// Scalar data type +// +typedef uint64 ScalarValue; + +#define V_NULL_MASK 0b00000001 +#define V_NOTNULL_MASK 0b00000000 +// steal bit to identify variable value +#define MASK_VAR 0xC000000000000000ULL +#define MASK_VAR_POINTER 0x0000000000000000ULL +#define MASK_VAR_STORAGE 0x8000000000000000ULL +#define MASK_POINTER 0x0FFFFFFFFFFFFFFFULL + +#define VAR_POINTER(val) ((val & MASK_VAR) == MASK_VAR_POINTER) +#define VAR_STORAGE(val) ((val & MASK_VAR) == MASK_VAR_STORAGE) + +typedef enum BatchCompressType { BCT_NOCOMP, BCT_LZ4 } BatchCompressType; + +inline bool COL_IS_ENCODE(int typeId) +{ + // we search the sys table to find [0,8] attlen data type + // select typname,typlen from pg_type where typlen >= 0 and typlen <=8; + switch (typeId) { + case CHAROID: + case BOOLOID: + case INT2OID: + case INT8OID: + case INT1OID: + case INT4OID: + case FLOAT4OID: + case FLOAT8OID: + case CASHOID: + case DATEOID: + case TIMEOID: + case TIMESTAMPOID: + case TIMESTAMPTZOID: + case SMALLDATETIMEOID: + case OIDOID: + case TIDOID: + case CIDOID: + case ABSTIMEOID: + case RELTIMEOID: + case ANYOID: + case VOIDOID: + case TRIGGEROID: + case INTERNALOID: + case OPAQUEOID: + case ANYELEMENTOID: + case ANYNONARRAYOID: + case LANGUAGE_HANDLEROID: + case REGPROCOID: + case XIDOID: + case REGPROCEDUREOID: + case REGOPEROID: + case REGOPERATOROID: + case REGCLASSOID: + case REGTYPEOID: + case REGCONFIGOID: + case REGDICTIONARYOID: + case ANYENUMOID: + case FDW_HANDLEROID: + case HLL_HASHVAL_OID: + case SMGROID: + return false; + default: + return true; + } +} + +template +bool COL_IS_ENCODE_T() +{ + return COL_IS_ENCODE(typeId); +} + +#define BOTH_NOT_NULL(flag1, flag2) (likely(NOT_NULL((flag1) | (flag2)))) +#define IS_NULL(flag) (unlikely(((flag)&V_NULL_MASK) == V_NULL_MASK)) +#define NOT_NULL(flag) ((((unsigned int)flag) & V_NULL_MASK) == V_NOTNULL_MASK) +#define SET_NULL(flag) ((flag) = (flag) | V_NULL_MASK) +#define BOTH_NULL(flag1, flag2) (IS_NULL((flag1) & (flag2))) + +#define SET_NOTNULL(flag) ((flag) = (flag) & (~V_NULL_MASK)) +#define BatchIsNull(pBatch) ((pBatch) == NULL || (pBatch)->m_rows == 0) +#define VAR_BUF_SIZE 16384 + +// Retrieve selection vector guarded by selection usage flag +// +#define SelectionVector(pBatch) ((pBatch)->m_checkSel ? (pBatch)->m_sel : NULL) + +#define ShallowCopyVector(targetVector, sourceVector) \ + ((targetVector).m_rows = (sourceVector).m_rows, \ + (targetVector).m_vals = (sourceVector).m_vals, \ + (targetVector).m_flag = (sourceVector).m_flag, \ + (targetVector).m_buf = (sourceVector).m_buf) + +struct ScalarDesc : public BaseObject { + + // Scalar Value type Oid. + Oid typeId; + + // atttypmod records type-specific data supplied at table creation time + // The value will generally be -1 for types that do not need typmod. + int4 typeMod; + + // this value means that the value in the scalarvector may be encoded, on storage/pointer to some + // where else, may be inlined(in which case it is not encode) + // it can be deduct from typeId, + bool encoded : 1; + + ScalarDesc() + { + typeId = InvalidOid; + typeMod = -1; + encoded = false; + }; +}; + +struct varBuf : public BaseObject { + char* buf; + int len; + int size; + varBuf* next; +}; + +class VarBuf : public BaseObject { +public: + // constructor .deconstructor + VarBuf(MemoryContext context); + + ~VarBuf(); + + // init + void Init(); + + void Init(int bufLen); + + void DeInit(bool needFree = true); + + // reset the buf. + void Reset(); + + // append a binary object + char* Append(const char* data, int datalen); + + // allocate a space. + char* Allocate(int datalen); + // add a var + + FORCE_INLINE + ScalarValue AddVar(ScalarValue value) + { + return PointerGetDatum(Append(DatumGetPointer(value), VARSIZE_ANY(value))); + } + +private: + // create a buffer; + varBuf* CreateBuf(int datalen); + + varBuf* m_head; + + varBuf* m_current; + + MemoryContext m_context; + + int m_bufNum; + + int m_bufInitLen; +}; + +// the core data structure for a column +class ScalarVector : public BaseObject { + friend class VectorBatch; + +public: + // number of values. + int m_rows; + + // type desciption information for this scalar value. + ScalarDesc m_desc; + + // this value means that the value in the scalarvector is always the same + bool m_const; + + // flags in the scalar value array. + uint8* m_flag; + + // a company buffer for store the data if the data type is not plain. + VarBuf* m_buf; + + // the value array. + ScalarValue* m_vals; + +public: + // decode a variable length data. + // null value judgement should be outside of this function. + FORCE_INLINE + static Datum Decode(ScalarValue val) + { + return val; + } + + // convert a datum to scalar value + static ScalarValue DatumToScalar(Datum datumVal, Oid datumType, bool isNull); + + template + static ScalarValue DatumToScalarT(Datum datumVal, bool isNull); + +public: + // constructor/deconstructor. + ScalarVector(); + ~ScalarVector(); + + // init the ScalarVector. + // + void init(MemoryContext cxt, ScalarDesc desc); + + // used in tsdb. init with another ScalarVector object. + // + void init(MemoryContext cxt, ScalarVector* vec, const int batchSize); + + // serialize the Scalar vector + // + void Serialize(StringInfo buf); + + // serialize the Scalar vector of the particular index + // + void Serialize(StringInfo buf, int idx); + + // Deserialize the vector + // + char* Deserialize(char* msg, size_t len); + + // Add a variable length data + // this var may be from + // cstring, fixed length(> 8) data type, or pg traditional header-contain variable length + Datum AddVar(Datum data, int index); + + // Add a header-contain variable + Datum AddVarWithHeader(Datum data); + + // Add a variable without header on a special position. The original variable will be + // transfered in together with the length of the content. And inside the funtion, the header + // of the ScalarValue will be added before the actual content according to the data type. + Datum AddBPCharWithoutHeader(const char* data, int maxLen, int len, int aindex); + Datum AddVarCharWithoutHeader(const char* data, int len, int aindex); + + // Add a short decimal without header on a special position. The value of decimal + // will be transfered in by int64 format together with the scale of it. And inside the function, + // the header will be added and the value will be converted into PG format. Here we only support + // short decimal which can be stored using int64. + Datum AddShortNumericWithoutHeader(int64 value, uint8 scale, int aindex); + Datum AddBigNumericWithoutHeader(int128 value, uint8 scale, int aindex); + + char* AddVars(const char* src, int length); + + // add a normal header-contain val + Datum AddHeaderVar(Datum data, int index); + + // add a cstring type val + Datum AddCStringVar(Datum data, int index); + + // add a fixed length val + template + Datum AddFixLenVar(Datum data, int index); + + // copy a vector + void copy(ScalarVector* vector, int start_idx, int endIdx); + void copy(ScalarVector* vector); + + void copyDeep(ScalarVector* vector, int start_idx, int endIdx); + void copyNth(ScalarVector* vector, int Nth); + + void copy(ScalarVector* vector, const bool* pSel); + + // convert a cstring to Scalar value. + static Datum DatumCstringToScalar(Datum data, Size len); + + // convert a fixed len datatype to Scalar Value + static Datum DatumFixLenToScalar(Datum data, Size len); + + FORCE_INLINE + bool IsNull(int i) + { + Assert(i >= 0 && i < m_rows); + return ((m_flag[i] & V_NULL_MASK) == V_NULL_MASK); + } + + FORCE_INLINE + void SetNull(int i) + { + Assert(i >= 0 && i < BatchMaxSize); + m_flag[i] |= V_NULL_MASK; + } + + FORCE_INLINE + void SetAllNull() + { + for (int i = 0; i < m_rows; i++) { + SetNull(i); + } + } + +private: + // init some function pointer. + void BindingFp(); + + Datum (ScalarVector::*m_addVar)(Datum data, int index); +}; + +struct SysColContainer : public BaseObject { + int sysColumns; + ScalarVector* m_ppColumns; + uint8 sysColumpMap[9]; +}; + +#define SelectionVector(pBatch) ((pBatch)->m_checkSel ? (pBatch)->m_sel : NULL) + +// A batch of vectorize rows +// +class VectorBatch : public BaseObject { +public: + // number of rows in the batch. + // + int m_rows; + + // number of columns in the batch. + // + int m_cols; + + // Shall we check the selection vector. + // + bool m_checkSel; + + // Selection vector; + // + bool* m_sel; + + // ScalarVector + // + ScalarVector* m_arr; + + // SysColumns + // + SysColContainer* m_sysColumns; + + // Compress buffer + // + StringInfo m_pCompressBuf; + +public: + // Many Constructors + // + VectorBatch(MemoryContext cxt, TupleDesc desc); + + VectorBatch(MemoryContext cxt, VectorBatch* batch); + + VectorBatch(MemoryContext cxt, ScalarDesc* desc, int ncols); + + // Deconstructor. + // + ~VectorBatch(); + + // Serialize the particular data index of the batch into the buffer. + // + void Serialize(StringInfo buf, int idx); + + // Deserialze the per-row msg into the batch + // + void Deserialize(char* msg); + + // Serialize the batch into the buffer without compress. + // + void SerializeWithoutCompress(StringInfo buf); + + // Deserialze the msg into the batch without compress. + // + void DeserializeWithoutDecompress(char* msg, size_t msglen); + + // Serialize the batch into the buffer with lz4 compress. + // + void SerializeWithLZ4Compress(StringInfo buf); + + // Deserialze the compressed msg into the batch with lz4 compress. + // + void DeserializeWithLZ4Decompress(char* msg, size_t msglen); + + // Reset + // + void Reset(bool resetflag = false); + + void ResetSelection(bool value); + + // Test the batch is valid or not + // + bool IsValid(); + + void FixRowCount(); + + void FixRowCount(int rows); + + // Pack the batch + // + void Pack(const bool* sel); + + /* Optimzed Pack function */ + void OptimizePack(const bool* sel, List* CopyVars); + + /* Optimzed Pack function for later read. later read cols and ctid col*/ + void OptimizePackForLateRead(const bool* sel, List* lateVars, int ctidColIdx); + + // SysColumns + // + void CreateSysColContainer(MemoryContext cxt, List* sysVarList); + ScalarVector* GetSysVector(int sysColIdx); + int GetSysColumnNum(); + + template + void Copy(VectorBatch* batch, int start_idx = 0, int endIdx = -1); + + void CopyNth(VectorBatch* batchSrc, int Nth); + +public: + /* Pack template function. */ + template + void PackT(_in_ const bool* sel); + + /* Optimize template function. */ + template + void OptimizePackT(_in_ const bool* sel, _in_ List* CopyVars); + + /* Optimize template function for later read. */ + template + void OptimizePackTForLateRead(_in_ const bool* sel, _in_ List* lateVars, int ctidColIdx); + +private: + // init the vectorbatch. + void init(MemoryContext cxt, TupleDesc desc); + + void init(MemoryContext cxt, VectorBatch* batch); + + void init(MemoryContext cxt, ScalarDesc* desc, int ncols); +}; + +/* + * @Description: copy batch with specific rows + * @in batch - current batch to be copyed. + * @in startIdx - start index at current batch + * @in endIdx - end index at current batch + * @template deep - weather a deep copy + * @template add - add rows or not + */ +template +void VectorBatch::Copy(VectorBatch* batch, int start_idx, int endIdx) +{ + int copy_end_idx; + copy_end_idx = (endIdx == -1) ? batch->m_rows : endIdx; + for (int i = 0; i < m_cols; i++) { + if (false == add) + m_arr[i].m_rows = 0; + if (deep) { + m_arr[i].copyDeep(&batch->m_arr[i], start_idx, copy_end_idx); + } else { + m_arr[i].copy(&batch->m_arr[i], start_idx, copy_end_idx); + } + } + + if (false == add) + m_rows = 0; + m_rows += copy_end_idx - start_idx; +} + +template +inline ScalarValue ScalarVector::DatumToScalarT(Datum datumVal, bool isNull) +{ + ScalarValue val = 0; + Size datumLen; /* length of the datum */ + + DBG_ASSERT(datumType != InvalidOid); + + if (!isNull) { + if (COL_IS_ENCODE_T()) { + switch (datumType) { + case MACADDROID: + val = DatumFixLenToScalar(datumVal, 6); + break; + case TIMETZOID: + case TINTERVALOID: + val = DatumFixLenToScalar(datumVal, 12); + break; + case INTERVALOID: + case UUIDOID: + val = DatumFixLenToScalar(datumVal, 16); + break; + case NAMEOID: + val = DatumFixLenToScalar(datumVal, 64); + break; + case UNKNOWNOID: + case CSTRINGOID: + datumLen = strlen((char*)datumVal); + val = DatumCstringToScalar(datumVal, datumLen); + break; + default: + val = datumVal; + break; + } + } else + val = datumVal; + } + + return val; +} + +extern Datum ExtractAddrType(Datum* val); +extern Datum ExtractFixedType(Datum* val); +extern Datum ExtractVarType(Datum* val); +extern Datum ExtractCstringType(Datum* val); + +/* + * Convert the scalar value of vector batch to the datum of row tuple. + * @_in_param val: The scalar value to be converted. + * @return the converted datum to be returned. + */ +typedef Datum (*ScalarToDatum)(ScalarValue); +template +Datum convertScalarToDatumT(ScalarValue val) +{ + Datum datum = 0; + switch (typid) { + case VARCHAROID: { + datum = ScalarVector::Decode(val); + break; + } + case TIMETZOID: { + char* result = (char*)(ScalarVector::Decode(val)) + VARHDRSZ_SHORT; + datum = PointerGetDatum(result); + break; + } + case TIDOID: { + datum = PointerGetDatum(val); + break; + } + case UNKNOWNOID: { + Datum tmp = ScalarVector::Decode(val); + char* result = NULL; + if (VARATT_IS_1B(tmp)) { + result = (char*)tmp + VARHDRSZ_SHORT; + } else { + result = (char*)tmp + VARHDRSZ; + } + datum = PointerGetDatum(result); + break; + } + default: { + datum = (Datum)val; + break; + } + } + return datum; +} + +#endif /* VECTORBATCH_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vectorbatch.inl postgresql-hll-2.14/include/include/vecexecutor/vectorbatch.inl --- postgresql-hll-2.14_old/include/include/vecexecutor/vectorbatch.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vectorbatch.inl 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,264 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectorbatch.inl + * Core data structure template implementation for vEngine + * + * IDENTIFICATION + * src/include/vecexecutor/vectorbatch.inl + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VECTORBATCH_INL +#define VECTORBATCH_INL + + +/* + * @Description: If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + * @in sel - flag which row we should move. + * @in Copyvars - flag which column we should move. + * @template copyMatch - copy match pattern which always true. + * @template hasSysCol - whether has System column data need to move. + */ +template +void VectorBatch::OptimizePackT(_in_ const bool * sel, _in_ List * CopyVars) +{ + int i, j, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + // Copy all values what we need indeed instead of copy whole table. + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + /* + * If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + */ + ListCell *var = NULL; + foreach (var, CopyVars) + { + int k = lfirst_int(var) - 1; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + + writeIdx ++; + } + } + + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + + +/* + * @Description: If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePackTForLateRead func to move specific column data + * that we want in later read situation. + * @in sel - flag which row we should move. + * @in lateVars - flag which column we should move in late read. + * @in ctidColIdx - flag which ctid column data. + * @template copyMatch - copy match pattern which always true. + * @template hasSysCol - whether has System column data need to move. + */ +template +void VectorBatch::OptimizePackTForLateRead(_in_ const bool * sel, _in_ List * lateVars, int ctidColIdx) +{ + int i, j, k, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + // Copy all values what we need indeed instead of copy whole table. + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + /* + * If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + */ + + ListCell *var = NULL; + foreach (var, lateVars) + { + k = lfirst_int(var) - 1; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + k = ctidColIdx; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + writeIdx ++; + } + } + + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + + + +template +void VectorBatch::PackT (_in_ const bool *sel) +{ + int i, j, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + + // Copy all values + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + for (j = 0; j < cColumns; j++) + { + pValues = pColumns[j].m_vals; + pFlag = pColumns[j].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + + writeIdx ++; + } + } + + // Restore constant columns + // + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vectsstorescan.h postgresql-hll-2.14/include/include/vecexecutor/vectsstorescan.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vectsstorescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vectsstorescan.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectsstorescan.h + * tsstore scan + * + * IDENTIFICATION + * src/include/vecexecutor/vectsstorescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODETSSTORESCAN_H +#define VECNODETSSTORESCAN_H + +#include "utils/relcache.h" + +struct TsStoreScan; +struct EState; +struct TsStoreScanState; +struct VectorBatch; + +extern TsStoreScanState* ExecInitTsStoreScan(TsStoreScan* node, Relation parentHeapRel, EState* estate, int eflags, + bool indexFlag = false, bool codegenInUplevel = false); +extern VectorBatch* ExecTsStoreScan(TsStoreScanState* node); +extern void ExecEndTsStoreScan(TsStoreScanState* node, bool indexFlag); +extern void ExecReScanTsStoreScan(TsStoreScanState* node); +extern VectorBatch* ts_apply_projection_and_filter(TsStoreScanState* node, + VectorBatch* pScanBatch, + ExprDoneCond* isDone); +void reset_sys_vector(const List* sys_attr_list, VectorBatch* vector); + +#endif /* VECNODETSSTORESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecunique.h postgresql-hll-2.14/include/include/vecexecutor/vecunique.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecunique.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecunique.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecunique.h + * Prototypes for vectorized unique + * + * IDENTIFICATION + * src/include/vecexecutor/vecunique.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECUNIQUE_H +#define VECUNIQUE_H + +#include "vecexecutor/vecnodes.h" + +extern VecUniqueState* ExecInitVecUnique(VecUnique* node, EState* estate, int eflags); +extern VectorBatch* ExecVecUnique(VecUniqueState* node); +extern void ExecEndVecUnique(VecUniqueState* node); +extern void ExecReScanVecUnique(VecUniqueState* node); + +#endif /* VECUNIQUE_H */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecvar.h postgresql-hll-2.14/include/include/vecexecutor/vecvar.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecvar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecvar.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecvar.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecvar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECVAR_H_ +#define VECVAR_H_ + +#include "vecexecutor/vectorbatch.h" +#include "utils/relcache.h" + +#define GETSLOTID(val) (((val)&0x3FFFFFFFFFFFFFFFULL) >> 48) +#define GETCODE(val) ((val)&0x0000FFFFFFFFFFFFULL) +#define STORAGEVAR_SIZE_STEP 10 + +class StorageVar : public BaseObject { +public: + // constructor deconstructor + // + StorageVar(); + + ~StorageVar(); + + // set the Attr + // + void SetAttr(Relation rel, int colId); + + // decode the data. + // + Datum Decode(Size code); + +private: + // related colid and relation. + int m_colId; + + Relation m_rel; +}; + +class StorageVarManager { +public: + StorageVarManager(); + + ~StorageVarManager(); + + // add a variable storage var container. + StorageVar* AddStorageVar(); + + // get the storage variable length. + StorageVar* GetStorageVar(int16 vindex); + + // Decode a value. + Datum Decode(ScalarValue val); + +private: + StorageVar** m_varData; + + // storage var manager size. + int m_size; + + // current storage var index. + int m_index; + + // manager related context. + // + MemoryContext m_context; +}; + +#endif /* VECVAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vecexecutor/vecwindowagg.h postgresql-hll-2.14/include/include/vecexecutor/vecwindowagg.h --- postgresql-hll-2.14_old/include/include/vecexecutor/vecwindowagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vecexecutor/vecwindowagg.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,376 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecwindowagg.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecwindowagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECWINDOWAGG_H +#define NODEVECWINDOWAGG_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vecagg.h" +#include "windowapi.h" + +extern VecWindowAggState* ExecInitVecWindowAgg(VecWindowAgg* node, EState* estate, int eflags); +extern const VectorBatch* ExecVecWindowAgg(VecWindowAggState* node); +extern void ExecEndVecWindowAgg(VecWindowAggState* node); +extern void ExecReScanVecWindowAgg(VecWindowAggState* node); +#define VA_FETCHBATCH 0 +#define VA_EVALFUNCTION 1 +#define VA_END 2 + +#define WINDOW_RANK 0 +#define WINDOW_ROWNUMBER 1 + +/* Save current probing place for next probe */ +typedef struct WindowStoreLog { + int lastFetchIdx; /* frame idx */ + int lastFrameRows; /* rows idx in a frame */ + bool restore; + void set(bool flag, int new_idx, int new_rows); +} WindowStoreLog; + +/* window aggregation info */ +typedef struct WindowAggIdxInfo { + int aggIdx; /* the idx of agg */ + bool is_final; /* if has final function */ +} WindowAggIdxInfo; + +class VecWinAggRuntime : public BaseAggRunner { +public: + // constructor/ + VecWinAggRuntime(VecWindowAggState* runtime); + ~VecWinAggRuntime(){}; + + // return the result batch. + const VectorBatch* getBatch(); + + /* virtual function in BaseAggRunner */ + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node) + { + return true; + } + + VectorBatch* Run() + { + return NULL; + } + + void BindingFp() + {} + + /* return agg number */ + int get_aggNum() + { + return m_aggNum; + } + + bool MatchPeerByOrder(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2); + + bool MatchPeerByPartition(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2); + + void MatchSequenceByOrder(VectorBatch* batch, int start, int end); + + void MatchSequenceByPartition(VectorBatch* batch, int start, int end); + void ReplaceEqfunc(); + void ResetNecessary(); + +private: + void FetchBatch(); + + template + const VectorBatch* EvalWindow(); + VectorBatch* EvalAllBatch(); + const VectorBatch* EvalPerBatch(); + void DispatchAssembleFunc(); + + void InitAggIdxInfo(VecAggInfo* aggInfo); + + void EvalWindowFunction(WindowStatePerFunc perfuncstate, int idx); + + void DispatchWindowFunction(WindowStatePerFunc perfuncstate, int i); + void DispatchAggFunction(WindowStatePerAgg peraggState, WindowStatePerFunc perfuncstate, VecAggInfo* aggInfo); + void EvalWindowAggNopartition(VectorBatch* batch); + bool CheckAggEncoded(Oid type_id); + +public: + // executor state + VecWindowAggState* m_winruntime; + + VectorBatch* m_currentBatch; + + VectorBatch* m_outBatch; + + /* to store last batch value */ + VectorBatch* m_lastBatch; + + /* store batch value */ + BatchStore* m_batchstorestate; + + // runtime status + int m_status; + + // down side has pop all data? + bool m_noInput; + + FunctionCallInfoData* m_windowFunc; + + int m_winFuns; + + // is the key column simple + bool m_simplePartKey; + + int m_partitionkey; // partition by + + int* m_partitionkeyIdx; + + ScalarDesc* m_pkeyDesc; + + bool m_simpleSortKey; + + int m_sortKey; // sort by + + int* m_sortKeyIdx; + + ScalarDesc* m_skeyDesc; + + uint8 m_winSequence[BatchMaxSize]; + /* array for order equal result */ + uint8 m_winSequence_dup[BatchMaxSize]; + FmgrInfo* m_parteqfunctions; + FmgrInfo* m_ordeqfunctions; + + /* the number of frames */ + int m_windowIdx; + + /* array for window func index */ + int* m_funcIdx; + + /* we need one more BatchMaxSize space for last batch */ + hashCell* m_windowGrp[BatchMaxSize + 1]; + + /* the numbers in each frame */ + int m_framrows[BatchMaxSize + 1]; + + int m_result_rows; /* the rows for agg */ + + /* the store state for each function to probe data */ + WindowStoreLog* m_window_store; + + ScalarVector* m_vector; /* the vector for expression */ + + /* the same window with last batch for no agg case */ + bool m_same_frame; + + bool* m_cellvar_encoded; /* trans-value is encoded */ + VarBuf* m_windowCurrentBuf; /* window agg buffer */ + WindowAggIdxInfo* m_windowagg_idxinfo; /* window agg info */ + +private: + template + bool AssembleAggWindow(VectorBatch* batch); + + template + bool MatchPeer(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + template + void MatchSequence(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + template + void buildWindowAgg(VectorBatch* batch); + + template + void buildWindowNoAgg(VectorBatch* batch); + + bool (VecWinAggRuntime::*m_assembeFun)(VectorBatch* batch); + + const VectorBatch* (VecWinAggRuntime::*m_EvalFunc)(); + + void (VecWinAggRuntime::*m_buildScanBatch)(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + + bool (VecWinAggRuntime::*m_MatchPeerOrd)( + VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + bool (VecWinAggRuntime::*m_MatchPeerPart)( + VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + void (VecWinAggRuntime::*m_MatchSeqOrd)(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + + void (VecWinAggRuntime::*m_MatchSeqPart)(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + template + bool AssemblePerBatch(VectorBatch* batch); + void RefreshLastbatch(VectorBatch* batch); + + template + void initCellValue(hashCell* cell, hashCell* last_cell, int m_frame_rows); + + void BatchAggregation(VectorBatch* batch); + void BuildScanBatchSimple(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + void BuildScanBatchFinal(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + + template + void EvalWindowAgg(); + + bool CheckStoreValid(); + + template + void buildWindowAggWithSort(VectorBatch* batch); + + void EvalWindowFuncRank(int whichFn, int idx); + + bool IsFinal(int idx); +}; + +/* + *@Description: set WindowStoreLog + */ +inline void WindowStoreLog::set(bool flag, int new_idx, int new_rows) +{ + lastFetchIdx = new_idx; + lastFrameRows = new_rows; + restore = flag; +} + +extern ScalarVector* vwindow_row_number(PG_FUNCTION_ARGS); +extern ScalarVector* vwindow_rank(PG_FUNCTION_ARGS); +extern ScalarVector* vwindow_denserank(PG_FUNCTION_ARGS); + +template +extern ScalarVector* vwindowfunc_withsort(PG_FUNCTION_ARGS); + +/* + * @Description: Evaluate window_rank and winow_rownumber with sort + * @template which_func - which func, window_rank is 0 and window_number is 1 + */ +template +ScalarVector* vwindowfunc_withsort(PG_FUNCTION_ARGS) +{ + WindowObject winobj = PG_WINDOW_OBJECT(); + int whichFn = PG_GETARG_INT32(0); + VecWindowAggState* state; + VecWinAggRuntime* winRuntime; + ScalarVector* pResCol; + VectorBatch* curWinBatch; + VectorBatch* preWinBatch; + + int j; + int batch_rows = 0; + int start_idx = 0; + int start_rows = 0; /* the position for frame start */ + int idx = 0; /* vector index */ + int frame_number = 0; + int fun_idx; + + state = (VecWindowAggState*)winobj->winstate; + winRuntime = (VecWinAggRuntime*)state->VecWinAggRuntime; + + /* the number of window frame */ + frame_number = winRuntime->m_windowIdx; + preWinBatch = winRuntime->m_lastBatch; + curWinBatch = winRuntime->m_currentBatch; + + /* which func, rank or row_number */ + fun_idx = winRuntime->m_funcIdx[whichFn]; + + /* result vector */ + pResCol = state->perfunc[whichFn].wfuncstate->m_resultVector; + pResCol->m_rows = 0; + batch_rows = winRuntime->m_currentBatch->m_rows; + + /* means that there are remain data in last frame */ + if (winRuntime->m_window_store[whichFn].restore == true) { + start_idx = winRuntime->m_window_store[whichFn].lastFetchIdx; + start_rows = winRuntime->m_window_store[whichFn].lastFrameRows; + winRuntime->m_window_store[whichFn].set(false, 0, 0); + } + + /* the last frame and there is no data in outer plan */ + if (winRuntime->m_noInput == true) { + /* rows of current frame */ + int rows = winRuntime->m_framrows[frame_number]; + bool first = true; + + for (int m = start_rows; m < rows; m++) { + if (first || which_func == WINDOW_RANK) { + pResCol->m_vals[idx] = winRuntime->m_windowGrp[frame_number]->m_val[fun_idx].val; + first = false; + } else + pResCol->m_vals[idx] = pResCol->m_vals[idx - 1] + 1; + + pResCol->m_rows++; + idx++; + + if (idx == curWinBatch->m_rows && m < rows - 1) { + winRuntime->m_window_store[whichFn].set(true, frame_number, m + 1); + break; + } + } + } else { + for (j = start_idx; j < frame_number; j++) { + /* rows of current frame */ + int n_rows = winRuntime->m_framrows[j]; + int m = 0; + /* the number of rows to be fetched from current frame */ + int frame_calcu_rows = rtl::min(batch_rows - idx, n_rows - start_rows); + for (m = start_rows; m < frame_calcu_rows + start_rows; m++) { + pResCol->m_vals[idx] = ((m == start_rows) || (which_func == WINDOW_RANK)) ? + winRuntime->m_windowGrp[j]->m_val[fun_idx].val : (pResCol->m_vals[idx - 1] + 1); + + pResCol->m_rows++; + idx++; + } + + /* current batch is full */ + if (idx == batch_rows) { + if (which_func == WINDOW_RANK) + state->currentpos = n_rows; + if (m < n_rows) /* current frame is not end */ + { + winRuntime->m_window_store[whichFn].set(true, j, m); + } else { + if (j < frame_number - 1) /* still has frame to be fetch */ + { + winRuntime->m_window_store[whichFn].set(true, j + 1, 0); + } else { + winRuntime->m_window_store[whichFn].set(false, 0, 0); + } + } + break; + } + /* for a new frame, set start_rows to be 0 */ + start_rows = 0; + } + } + + Assert(pResCol->m_rows <= BatchMaxSize); + Assert(pResCol->m_rows == batch_rows); + + return NULL; +} + +#endif /* NODEVECAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicarray.h postgresql-hll-2.14/include/include/vectorsonic/vsonicarray.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicarray.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicarray.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,257 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicarray.h + * Routines to handle Sonic datum array. + * SonicDatumArray is the base class to store data and flag. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicarray.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +struct atom { + char* data; + char* nullFlag; +}; + +struct DatumDesc { + Oid typeId; + int typeMod; + int typeSize; + int dataType; + + DatumDesc() + { + typeId = InvalidOid; + typeMod = -1; + typeSize = 0; + dataType = 0; + }; +}; + +#pragma pack(1) +struct n1pack { + uint8 scale; + uint8 val; +}; + +struct n2pack { + uint8 scale; + uint16 val; +}; + +struct n4pack { + uint8 scale; + uint32 val; +}; + +struct n8pack { + uint8 scale; + uint64 val; +}; + +#pragma pack() + +struct ArrayIdx { + int arrIdx; + int16 atomIdx; +}; + +#define INIT_ARR_CONTAINER_SIZE 16 +#define MAX_DIC_ENCODE_ITEMS 256 +#define INIT_DATUM_ARRAY_SIZE (16 * 1024) + +#define SONIC_INT_TYPE 0 +#define SONIC_FIXLEN_TYPE 1 +#define SONIC_CHAR_DIC_TYPE 2 +#define SONIC_VAR_TYPE 3 +#define SONIC_NUMERIC_COMPRESS_TYPE 4 +#define SONIC_TOTAL_TYPES 5 + +#define getArrayIndx(nth, nbit) (nth >> (nbit)) +#define getArrayLoc(nth, mask) (nth & (unsigned int)(mask)) + +class SonicDatumArray : public BaseObject { +public: + SonicDatumArray(MemoryContext cxt, int capacity); + + virtual ~SonicDatumArray() + {} + + /* descr area, static information */ + MemoryContext m_cxt; /* context */ + DatumDesc m_desc; /* datum descrption */ + bool m_nullFlag; /* Whether atom has null flag array */ + int m_arrSize; /* The number of allocated atoms. Init value is INIT_ARR_CONTAINER_SIZE 16 */ + const uint32 m_atomSize; /* The size of one atom. Def value is INIT_DATUM_ARRAY_SIZE 16k */ + int m_atomTypeSize; /* Element type size in atom. */ + const uint32 m_nbit; /* log2(m_atomSize) */ + + /*data area*/ + atom** m_arr; /* Record atoms address.. Each element points to one atom. */ + atom* m_curAtom; /* Current atom */ + + /*index area*/ + int m_arrIdx; /* m_arrIdx + 1 == the number of used atoms. Init value -1 */ + int m_atomIdx; /* Current position in atom */ + + char* m_curData; /* record the current data in atom */ + uint8* m_curFlag; /* record the current flag in atom */ + +public: + virtual void genNewArray(bool genBitMap); + + /* put function. */ + void putArray(ScalarValue* vals, uint8* flag, int rows); + + void loadArrayByRow(void* file); + + void loadArray(void* file, int64 rows); + + /* get function */ + int64 getRows(); + + FORCE_INLINE + uint8 getNthNullFlag(int arrIdx, int atomIdx) + { + return m_arr[arrIdx]->nullFlag[atomIdx]; + } + + void getNthDatumFlag(uint32 nth, ScalarValue* val, uint8* toflag); + + Datum getNthDatum(uint32 nth); + + void getArrayAtomIdx(int nrows, uint32* locs, ArrayIdx* arrayIdx); + + /* set function. */ + ScalarValue replaceVariable(ScalarValue oldVal, ScalarValue val); + + FORCE_INLINE + void setNthNullFlag(uint32 nth, bool isNull) + { + int arrIdx; + int atomIdx; + arrIdx = getArrayIndx(nth, m_nbit); + atomIdx = getArrayLoc(nth, m_atomSize - 1); + m_arr[arrIdx]->nullFlag[atomIdx] = isNull; + } + + FORCE_INLINE + void setNthNullFlag(int arrIdx, int atomIdx, bool isNull) + { + m_arr[arrIdx]->nullFlag[atomIdx] = isNull; + } + + virtual void setNthDatum(uint32 nth, ScalarValue* val) + { + Assert(false); + } + + virtual void setValue(ScalarValue val, bool isNull, int arrIndx, int atomIndx) + { + Assert(false); + } + + virtual void getDatumArray(int nrows, int* arrayIdx, int* atomIdx, Datum* data) + { + Assert(false); + } + + virtual void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag) + { + Assert(false); + } + + virtual void getDatumFlagArrayWithMatch( + int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx) + { + Assert(false); + } + + virtual size_t flushDatumFlagArrayByRow( + int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows) + { + return 0; + } + + virtual size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows) + { + return 0; + } + + virtual void loadIntValArray(void* file, int nrows) + { + Assert(false); + } + + virtual void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows) + { + Assert(false); + } + + virtual void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* toflag) + { + Assert(false); + } + +private: + void putNullFlagArray(uint8* flag, int rows); + + virtual void loadDatumFlagArray(void* file, int rows) + { + Assert(false); + } + + virtual void loadDatumFlagArrayByRow(void* file, int leftrows) + { + Assert(false); + } + + virtual Datum getDatum(int arrIdx, int atomIdx) + { + Assert(false); + return 0; + } +}; + +extern int getDataMinLen(Oid typeOid, int typeMod); +extern void getDataDesc(DatumDesc* desc, int typeSize, Form_pg_attribute attr, bool isHashKey); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicchar.h postgresql-hll-2.14/include/include/vectorsonic/vsonicchar.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicchar.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,106 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicchar.h + * Routines to handle Character data type like char, bpchar. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicchar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICCHAR_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICCHAR_H_ + +#include "vectorsonic/vsonicarray.h" + +class SonicCharDatumArray : public SonicDatumArray { +public: + SonicCharDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicCharDatumArray(){}; + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + void loadDatumFlagArray(void* file, int rows); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + Datum getDatum(int arrIdx, int atomIdx); + + void initCharDatumArray(); + +private: + void initDict(); + + void initResultBuf(); + + void initFunc(); + + void putDicDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void putCharDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getCharDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getDicDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getCharDatum(int arrIdx, int atomIdx); + + Datum getDicDatum(int arrIdx, int atomIdx); + + void rebuildFromDict(); + + typedef void (SonicCharDatumArray::*putFunc)(ScalarValue* vals, uint8* flag, int rows); + + typedef void (SonicCharDatumArray::*putDatumFunc)(ScalarValue* vals, uint8* flag); + + typedef void (SonicCharDatumArray::*getDatumFlagFunc)(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + typedef Datum (SonicCharDatumArray::*getDatumFunc)(int arrIdx, int atomIdx); + + /* put and get functions */ + putFunc m_putFunc; + getDatumFunc m_getDatumFunc[2]; + getDatumFlagFunc m_getDatumFlagFunc[2]; + + /* store dict */ + void* m_dict; + + /* tag dict and char data, + * for atom whose arrIdx < m_dictArrLen + * stores dict data, otherwise stores char + */ + int m_dictArrLen; + + /* buffer to store results */ + char* m_resultBuf; + + /* temp varible to get buffer data */ + int m_resultBufIndx; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicencodingchar.h postgresql-hll-2.14/include/include/vectorsonic/vsonicencodingchar.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicencodingchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicencodingchar.h 2020-12-12 17:06:43.302348748 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicencodingchar.h + * Routines to handle variable length data type. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicencodingchar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ + +#include "vectorsonic/vsonicarray.h" + +class SonicEncodingDatumArray : public SonicDatumArray { +public: + SonicEncodingDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicEncodingDatumArray(){}; + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void setValue(ScalarValue val, bool isNull, int arrIndx, int atomIndx); + + Datum getDatum(int arrIdx, int atomIdx); + +private: + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void loadDatumFlagArray(void* file, int rows); +}; + +class SonicStackEncodingDatumArray : public SonicEncodingDatumArray { +public: + SonicStackEncodingDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicStackEncodingDatumArray(){}; + +private: + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void putDatumFlag(ScalarValue* vals, uint8* flag); + + void loadDatumFlagArray(void* fileSource, int rows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + VarBuf* m_buf; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicfilesource.h postgresql-hll-2.14/include/include/vectorsonic/vsonicfilesource.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicfilesource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicfilesource.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,385 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicfilesource.h + * sonic file source class and class member declare + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicfilesource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "vectorsonic/vsonicarray.h" + +#define CheckReadIsValid(nread, toread) \ + if ((nread) != (toread)) { \ + ereport(ERROR, (errcode_for_file_access(), errmsg("could not read from sonic hash-join temporary file: %m"))); \ + } + +/* file info for every file type */ +typedef struct FileInfo { + /* record the original position in targetlist. */ + uint32 partColIdx; + + /* typeSize of current column in file */ + int typeSize; + + /* record the varheadlen of difference column in same file */ + uint8 varheadlen; +} FileInfo; + +class SonicHashFileSource : public BaseObject { +public: + SonicHashFileSource(MemoryContext context); + + SonicHashFileSource(MemoryContext context, DatumDesc* desc); + + virtual ~SonicHashFileSource() + {} + + /* memory context */ + MemoryContext m_context; + + /* data description */ + DatumDesc m_desc; + + /* pointer of temp file */ + void* m_file; + + /* columns include */ + uint32 m_cols; + + /* total column width */ + size_t m_colWidth; + + /* colIdx in current file */ + uint32 m_nextColIdx; + + /* fileinfo include colIdx in targetlist and typeSize of current colIdx */ + FileInfo* m_fileInfo; + + /* + * record the size of varible data which will not contained within the Atom's allocated space + * when loading into memory, such as SONIC_NUMERIC_COMPRESS_TYPE and SONIC_VAR_TYPE, + * whose data may stored in buffers (eg. VarBuf) other than Atom. + * The Atom only holds the pointers of the data. + */ + size_t* m_varSize; + + /* write and read functions to and from temp file*/ + size_t (SonicHashFileSource::*m_writeScalarValue)(ScalarValue* val, uint8 flag); + + size_t (SonicHashFileSource::*m_readScalarValue)(ScalarValue* val, uint8* flag); + + size_t (SonicHashFileSource::*m_readTempFile)(void* file, void* data, size_t size); + + size_t (SonicHashFileSource::*m_writeTempFile)(void* file, void* data, size_t size); + + /* rewind function */ + void (SonicHashFileSource::*m_rewind)(); + + /* close function */ + void (SonicHashFileSource::*m_close)(); + + void prepareFileHandlerBuffer(); + + void releaseFileHandlerBuffer(); + + size_t write(void* data, size_t size); + + size_t read(void* data, size_t size); + +public: + virtual void setBuffer() + { + return; + } + + /* get typeSize in current column */ + size_t getTypeSize(int colIdx) + { + return (size_t)m_fileInfo[colIdx].typeSize; + } + + /* m_cols means max column number in filesource */ + uint32 getMaxCols() + { + return m_cols; + } + + size_t getColWidth() + { + return m_colWidth; + } + size_t writeVal(char* val, uint8 flag = V_NOTNULL_MASK); + + size_t writeVal(ScalarValue* val, uint8 flag); + + size_t readVal(char* val, uint8* flag = NULL); + + size_t readVal(ScalarValue* val, uint8* flag); + + void rewind(); + + void close(); + +private: + virtual size_t writeScalar(ScalarValue* val, uint8 flag) + { + return 0; + } + + virtual size_t readScalar(ScalarValue* val, uint8* flag) + { + return 0; + } + + virtual size_t writeScalarOpt(ScalarValue* val, uint8 flag) + { + return 0; + } + + virtual size_t readScalarOpt(ScalarValue* val, uint8* flag) + { + return 0; + } + + virtual void init(DatumDesc* desc, uint16 fileIdx) + { + Assert(false); + } + + size_t writeCompress(void* file, void* data, size_t size); + + size_t writeNoCompress(void* file, void* data, size_t size); + + size_t readCompress(void* file, void* data, size_t size); + + size_t readNoCompress(void* file, void* data, size_t size); + + void rewindCompress(); + + void rewindNoCompress(); + + void closeCompress(); + + void closeNoCompress(); +}; + +class SonicHashIntFileSource : public SonicHashFileSource { + +private: + /* write function according to the integer bytes */ + size_t (SonicHashIntFileSource::*m_writeIntScalarValue)(ScalarValue* val, uint8 flag); + + /* read function according to the integer bytes */ + size_t (SonicHashIntFileSource::*m_readIntScalarValue)(ScalarValue* val, uint8* flag); + + /* write function according to the integer bytes */ + typedef size_t (SonicHashIntFileSource::*pWriteIntScalarValue)(ScalarValue* val, uint8 flag); + + /* read function according to the integer bytes */ + typedef size_t (SonicHashIntFileSource::*pReadIntScalarValue)(ScalarValue* val, uint8* flag); + + pWriteIntScalarValue* m_writeIntScalarValueFuncs; + + pReadIntScalarValue* m_readIntScalarValueFuncs; + +public: + SonicHashIntFileSource(MemoryContext context, DatumDesc* desc, bool hasFlag = true); + + ~SonicHashIntFileSource(){}; + + SonicHashIntFileSource(MemoryContext context, uint32 maxCols, bool hasFlag = true); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t write1ByteScalar(ScalarValue* val, uint8 flag); + + size_t write1ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write2ByteScalar(ScalarValue* val, uint8 flag); + + size_t write2ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write4ByteScalar(ScalarValue* val, uint8 flag); + + size_t write4ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write8ByteScalar(ScalarValue* val, uint8 flag); + + size_t write8ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + + size_t read1ByteScalar(ScalarValue* val, uint8* flag); + + size_t read1ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read2ByteScalar(ScalarValue* val, uint8* flag); + + size_t read2ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read4ByteScalar(ScalarValue* val, uint8* flag); + + size_t read4ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read8ByteScalar(ScalarValue* val, uint8* flag); + + size_t read8ByteScalarOpt(ScalarValue* val, uint8* flag); + + /* init typeSize and m_cols in SONIC_INT_TYPE file */ + void init(DatumDesc* desc, uint16 fileIdx); + +private: + size_t readValue(char* val, uint8* flag); +}; + +class SonicHashNumericFileSource : public SonicHashFileSource { +public: + SonicHashNumericFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashNumericFileSource(MemoryContext context, uint32 maxCols); + + ~SonicHashNumericFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + /* temp buffer to store one numeric */ + char* m_packBuf; + + /* buffer to store 128 numeric data */ + VarBuf* m_buf; +}; + +class SonicHashEncodingFileSource : public SonicHashFileSource { +public: + SonicHashEncodingFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashEncodingFileSource(MemoryContext context, uint32 maxCols); + + ~SonicHashEncodingFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + /* buffer to store real data */ + VarBuf* m_buf; +}; + +class SonicHashCharFileSource : public SonicHashFileSource { + +private: + /* temp pointer to buffer */ + char* m_buf; + + /* buffer to store a batch */ + char* m_batchBuf; + + /* actual header size */ + uint8 m_varheadlen; + +public: + SonicHashCharFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashCharFileSource(MemoryContext context, int typeSize, uint32 maxCols); + + ~SonicHashCharFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + void initBatchBuf(); +}; + +class SonicHashFixLenFileSource : public SonicHashFileSource { + +private: + /* actual header size */ + uint8 m_varheadlen; + + /* buffer to store a batch */ + char* m_batchBuf; + + /* temp pointer to buffer */ + char* m_buf; + + char* m_tmpvalue; + +public: + SonicHashFixLenFileSource(MemoryContext context, DatumDesc* desc); + + ~SonicHashFixLenFileSource(){}; + + SonicHashFixLenFileSource(MemoryContext context, uint32 maxCols); + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + void initBatchBuf(); +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicfixlen.h postgresql-hll-2.14/include/include/vectorsonic/vsonicfixlen.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicfixlen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicfixlen.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicfixlen.h + * Routines to handle data type that attribute has fixed length. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicfixlen.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ + +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicchar.h" + +class SonicFixLenDatumArray : public SonicDatumArray { +public: + SonicFixLenDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicFixLenDatumArray(){}; + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArray(void* fileSource, int rows); + + void loadDatumFlagArrayByRow(void* fileSource, int leftrows); + +private: + void initResultBuf(); + + /* buffer to assemble results */ + char* m_resultBuf; + + /* index in the buffer */ + int m_resultBufIndx; + + /* header size*/ + int m_varheadlen; +}; +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonichashagg.h postgresql-hll-2.14/include/include/vectorsonic/vsonichashagg.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonichashagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonichashagg.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,284 @@ +/* + * 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(){}; + + /* Main sonic HashAgg function */ + VectorBatch* Run(); + + /* Main process to build hash table */ + void Build(); + + /* Main process to produce result */ + VectorBatch* Probe(); + + /* Get the hash source */ + SonicHashSource* GetHashSource(); + + /* Reset current status */ + bool ResetNecessary(VecAggState* node); + + /* Show number of partition files */ + 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. + */ + /* match function. */ + template + bool matchValue(ScalarVector* pVector, uint16 keyIdx, int16 pVectorIdx, uint32 cmpIdx); + + template + void matchArray(ScalarVector* pVector, uint16 keyIdx, uint16 cmpRows); + + /* build sonic hash table function */ + template + void buildAggTblBatch(VectorBatch* batch); + + int64 insertHashTbl(VectorBatch* batch, int idx, uint32 hashval, uint32 hashLoc); + + void calcHashContextSize(MemoryContext ctx, int64* memorySize, int64* freeSize); + + /* judge current used memory context */ + void judgeMemoryOverflow(char* opname, int planId, int dop, Instrumentation* instrument, int64 size_needed); + + bool judgeMemoryAllowExpand(); + + /* calculate hash table size */ + template + int64 calcHashTableSize(int64 oldSize); + + /* Following function are used for alloc new hash table or expand it. */ + void AllocHashTbl(VectorBatch* batch, int idx, uint32 hashval, int hashLoc); + + void tryExpandHashTable(); + + void expandHashTable(); + + /* following functions are about partiton function */ + 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: + /* runtime state */ + VecAggState* m_runtime; + + /* runtime stage (source, build, probe) */ + int m_runState; + + /* memory or disk. */ + int m_strategy; + + /* record avg width of encoded columns in memory */ + int64 m_tupleCount; + int64 m_colWidth; + int m_arrayElementSize; + + /* record memory need for each expand */ + int64 m_arrayExpandSize; + + /* row numbers in memory of first spill */ + int m_fill_table_rows; + + /* expression-evaluation context */ + ExprContext* m_econtext; + + /* Sonic hash source */ + SonicHashSource* m_sonicHashSource; + + /* partitions for hash source(file source) */ + SonicHashPartition** m_partFileSource; + + /* partitions for respill hash source */ + SonicHashPartition** m_overflowFileSource; + + /* number of partitions */ + uint16 m_partNum; + + /* number of overflow partitions */ + uint16 m_overflowNum; + + /* current partition index */ + 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. + */ + + /* the actual structure for the table is bucket, hash, next, hash_needed cols, agg cols + * number of columns needed in hash table + */ + uint16 m_hashNeed; + uint16* m_hashInBatchIdx; + uint16* m_keyIdxInSonic; + + /* the information to describe the aggregation */ + /* number of aggregation function */ + uint16 m_aggNum; + + /* number of aggregation function need to transform */ + uint16 m_finalAggNum; + + /* check if current agg function is count(*)/count(any) or not. */ + bool* m_aggCount; + + /* agg index in the tupe, as some agg function may split into two function */ + uint16* m_aggIdx; + + /* whether the key is simple or not */ + bool m_keySimple; + + /* the index which need to do some final calculation */ + finalAggInfo* m_finalAggInfo; + + /* equal function used to match values. */ + FmgrInfo* m_equalFuncs; + + /* batch infomation used during aggregation */ + /* batch for scaning the hash table */ + VectorBatch* m_scanBatch; + + /* projection batch. */ + VectorBatch* m_proBatch; + + /* same structure as outer node return batch */ + VectorBatch* m_outBatch; + + /* batch used to store data from file */ + VectorBatch* m_sourceBatch; + + /* flag used to mark */ + bool m_useSegHashTbl; + + /* number of segment hash table */ + int m_segNum; + + /* segment index hash table */ + SonicDatumArray* m_segBucket; + + /* where we put the next data */ + SonicDatumArray* m_next; + + /* mark weather hash table can grow up */ + bool m_enableExpansion; + + /* build function pointer */ + void (SonicHashAgg::*m_buildFun)(VectorBatch* batch); + + /* hash build time */ + double m_hashbuild_time; + + /* hash agg-calc time */ + double m_calcagg_time; + + /* match function array. */ + pKeyMatchArrayFunc* m_arrayKeyMatch; + pKeyMatchValueFunc* m_valueKeyMatch; + + /* record the miss match idx. */ + uint16 m_missIdx[BatchMaxSize]; + uint16 m_missNum; + + /* record the suspect idx which need to be match. */ + uint16 m_suspectIdx[BatchMaxSize]; + uint16 m_suspectNum; + + /* record the bucket location. */ + uint32 m_bucketLoc[BatchMaxSize]; + + /* handle duplicate, record the orginial the location. */ + uint32 m_orgLoc[BatchMaxSize]; +}; +#endif diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonichash.h postgresql-hll-2.14/include/include/vectorsonic/vsonichash.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonichash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonichash.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,317 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonichash.h + * Routines to handle vector sonic hash nodes. + * SonicHash is base class of SonicHashJoin and SonicHashAgg. + * This file also contains many hash functions. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonichash.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ + +#include "vecexecutor/vectorbatch.h" +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicnumeric.h" +#include "vectorsonic/vsonicint.h" +#include "vectorsonic/vsonicchar.h" +#include "vectorsonic/vsonicencodingchar.h" +#include "vectorsonic/vsonicfixlen.h" + +#define PROBE_FETCH 0 +#define PROBE_PARTITION_FILE 1 +#define PROBE_DATA 2 +#define PROBE_FINAL 3 +#define PROBE_PREPARE_PAIR 4 +#define PROBE_PARTITION_MEM 5 + +#define USE_PRIME + +#ifdef USE_PRIME +/* + * The prime calculated via hashfindrprime() with rows + * larger than SONIC_MAX_ROWS will be larger than UINT_MAX. + */ +#define SONIC_MAX_ROWS 4080218831 +#else +#define SONIC_MAX_ROWS 4294950910 +#endif + +typedef enum { CALC_BASE = 0, CALC_SPILL, CALC_HASHTABLE } CalcBatchHashType; + +struct hashStateLog { + int lastProcessIdx; + bool restore; +}; + +struct SonicHashMemoryControl { + + bool sysBusy; + /* record spill info */ + bool spillToDisk; /* true when next batch should put into disk */ + int spillNum; + /* record memory auto spread info */ + uint64 maxMem; + int spreadNum; + /* record context memory info */ + uint64 totalMem; + uint64 availMem; + uint64 allocatedMem; + MemoryContext hashContext; + MemoryContext tmpContext; + + SonicHashMemoryControl() + { + sysBusy = false; + spillToDisk = false; + spillNum = 0; + maxMem = 0; + spreadNum = 0; + totalMem = 0; + availMem = 0; + allocatedMem = 0; + hashContext = NULL; + tmpContext = NULL; + }; +}; + +class SonicHashSource : public BaseObject { +public: + virtual VectorBatch* getBatch() + { + Assert(false); + return NULL; + } + + virtual ~SonicHashSource() + {} +}; + +class SonicHashOpSource : public SonicHashSource { +public: + SonicHashOpSource(PlanState* op) : m_op(op) + {} + ~SonicHashOpSource(){}; + + VectorBatch* getBatch() + { + return VectorEngine(m_op); + } + +private: + /* data source operator */ + PlanState* m_op; +}; + +class SonicHash : public BaseObject { +public: + SonicHash(int size); + + virtual ~SonicHash() + {} + + void initHashFunc(TupleDesc desc, void* hashFun, uint16* m_keyIndx, bool isAtom = false); + + /* Hash Functions */ + /* Specialized for int8, int16, int32 */ + template + void hashInteger(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + /* Specialized for int64 */ + template + void hashInteger8(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashbpchar(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashtext(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashtext_compatible(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashnumeric(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + /* General hash functions */ + template + void hashGeneralFunc(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr); + + void freeMemoryContext(); + + int64 getRows(); + + bool integerType(Oid typeId); + + bool isHashKey(Oid typeOid, int attidx, uint16* keyIdx, int keyNum); + + void replaceEqFunc(); + + inline void hashBatchArray(VectorBatch* batch, void* hashFun, FmgrInfo* hashFmgr, uint16* keyIndx, uint32* hashRes) + { + int i; + AutoContextSwitch memGuard(m_memControl.tmpContext); + hashValFun* hashfun = (hashValFun*)hashFun; + + for (i = 0; i < m_buildOp.keyNum; i++) + RuntimeBinding(hashfun, i)((char*)batch->m_arr[keyIndx[i]].m_vals, + (uint8*)batch->m_arr[keyIndx[i]].m_flag, + batch->m_rows, + hashRes, + (hashFmgr + i)); + + MemoryContextReset(m_memControl.tmpContext); + } + + inline void hashAtomArray(SonicDatumArray** array, int nrows, int arrIdx, void* hashFun, FmgrInfo* hashFmgr, + uint16* keyIndx, uint32* hashRes) + { + int i; + AutoContextSwitch memGuard(m_memControl.tmpContext); + atom* datum_arr; + hashValFun* hashfun = (hashValFun*)hashFun; + + for (i = 0; i < m_buildOp.keyNum; i++) { + datum_arr = array[keyIndx[i]]->m_arr[arrIdx]; + RuntimeBinding(hashfun, i)( + (char*)datum_arr->data, (uint8*)datum_arr->nullFlag, nrows, hashRes, (hashFmgr + i)); + } + + MemoryContextReset(m_memControl.tmpContext); + } + + template + void matchCheckColT(ScalarVector* val, SonicDatumArray* array, int nrows, int keyNum) + { + bool* boolloc = m_match; + uint16* loc1 = m_selectIndx; + Datum* data = m_matchKeys; + uint8* flag = m_nullFlag; + + bool notnullcheck = false; + bool nullcheck = false; + + array->getArrayAtomIdx(nrows, m_loc, m_arrayIdx); + array->getDatumFlagArrayWithMatch(nrows, m_arrayIdx, m_matchKeys, m_nullFlag, m_match); + + for (int i = 0; i < nrows; i++) { + notnullcheck = BOTH_NOT_NULL(val->m_flag[*loc1], m_nullFlag[i]); + nullcheck = nulleqnull & (uint8)BOTH_NULL((unsigned char)val->m_flag[*loc1], (unsigned char)m_nullFlag[i]); + if (simpleType) + *boolloc = + *boolloc && (nullcheck || (notnullcheck && ((outerType)val->m_vals[*loc1] == (innerType)(*data)))); + else { + FunctionCallInfoData fcinfo; + PGFunction cmpfun = m_eqfunctions[keyNum].fn_addr; + Datum args[2]; + fcinfo.arg = &args[0]; + + fcinfo.arg[0] = val->m_vals[*loc1]; + fcinfo.arg[1] = *data; + fcinfo.flinfo = (m_eqfunctions + keyNum); + *boolloc = *boolloc && (nullcheck || (notnullcheck && (bool)cmpfun(&fcinfo))); + } + + boolloc++; + loc1++; + data++; + flag++; + } + } + +public: + typedef void (SonicHash::*hashValFun)(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr); + + typedef void (SonicHash::*matchFun)(ScalarVector* val, SonicDatumArray* array, int nrows, int keyNum); + + typedef void (SonicHash::*profileFun)(); + + typedef struct SonicHashInputOpAttr { + bool simple; /* without encoding */ + + uint16* keyIndx; + + uint16* oKeyIndx; + + uint16 keyNum; + + hashValFun* hashFunc; + + hashValFun* hashAtomFunc; + + FmgrInfo* hashFmgr; + + VectorBatch* batch; + + uint16 cols; + + TupleDesc tupleDesc; + + SonicHashInputOpAttr() + { + simple = false; + keyIndx = NULL; + oKeyIndx = NULL; + keyNum = 0; + hashFunc = NULL; + hashAtomFunc = NULL; + hashFmgr = NULL; + batch = NULL; + cols = 0; + tupleDesc = NULL; + } + } SonicHashInputOpAttr; + + /* the hash data and the desc */ + SonicDatumArray** m_data; + SonicDatumArray* m_hash; + char* m_bucket; + uint8 m_bucketTypeSize; + + int m_atomSize; /* array size for atom structure */ + int64 m_hashSize; + int64 m_rows; + + /* runtime status and binding function. */ + matchFun* m_matchKey; /* matching functions */ + hashStateLog m_stateLog; + uint8 m_probeStatus; + uint8 m_status; + SonicHashInputOpAttr m_buildOp; + FmgrInfo* m_eqfunctions; /* equal functions */ + + /* memory control.*/ + SonicHashMemoryControl m_memControl; + + /* temporary space for vector processing */ + uint32 m_hashVal[INIT_DATUM_ARRAY_SIZE]; /* temp hash values */ + uint32 m_loc[BatchMaxSize]; /* record position from inner atom */ + uint32 m_partLoc[BatchMaxSize]; /* record partition number */ + uint16 m_selectIndx[BatchMaxSize]; /* record position from outer batch */ + uint16 m_selectRows; /* matched tuple number */ + bool m_match[BatchMaxSize]; + Datum m_matchKeys[BatchMaxSize]; + uint8 m_nullFlag[BatchMaxSize]; + ArrayIdx m_arrayIdx[BatchMaxSize]; /* record matched idx */ +}; + +extern uint64 hashfindprime(uint64 n); +extern uint32 hashquickany(uint32 seed, register const unsigned char* data, register int len); +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonichashjoin.h postgresql-hll-2.14/include/include/vectorsonic/vsonichashjoin.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonichashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonichashjoin.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,305 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonichashjoin.h + * Routines to handle vector sonic hashjoin nodes. + * Sonic Hash Join nodes are based on the column-based hash table. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonichashjoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ + +#include "vectorsonic/vsonichash.h" +#include "vectorsonic/vsonicpartition.h" + +/* + * Max partition number when doing partition or repartition. + * Total partition number can be larger than this value. + */ +#define SONIC_PART_MAX_NUM 1024 + +typedef enum { reportTypeBuild = 1, reportTypeProbe, reportTypeRepartition } ReportType; + +struct BatchPos { + uint32 partIdx; + int rowIdx; +}; + +class SonicHashJoin : public SonicHash { +public: + SonicHashJoin(int size, VecHashJoinState* node); + + ~SonicHashJoin(){}; + + void Build(); + + VectorBatch* Probe(); + + void closeAllFiles(); + + void ResetNecessary(); + + void freeMemoryContext(); + +private: + /* init functions */ + void setHashIndex(uint16* keyIndx, uint16* oKeyIndx, List* hashKeys); + + void initMemoryControl(); + + void initHashTable(uint8 byteSize, uint32 curPartIdx); + + void initHashFmgr(); + + /* binding function pointer. */ + template + void bindingFp(); + + /* build side functions to put data */ + template + void saveToMemory(VectorBatch* batch); + + template + void saveToDisk(VectorBatch* batch); + + template + void flushToDisk(); + + template + void buildHashTable(uint32 curPartIdx); + + uint64 calcHashSize(int64 nrows); + + void prepareProbe(); + + /* output functions */ + VectorBatch* buildRes(VectorBatch* inBatch, VectorBatch* outBatch); + + /* Memory functions */ + bool hasEnoughMem(); + + void judgeMemoryOverflow(uint64 hash_head_size); + + void calcHashContextSize(MemoryContext ctx, uint64* allocateSize, uint64* freeSize); + + void calcDatumArrayExpandSize(); + + /* probe functions */ + VectorBatch* probeMemory(); + + VectorBatch* probeGrace(); + + template + VectorBatch* probeMemoryTable(SonicHashSource* probeP); + + template + VectorBatch* probePartition(SonicHashSource* probeP = NULL); + + /* join functions */ + template + VectorBatch* innerJoin(VectorBatch* batch); + + /* profiling functions */ + void profile(bool writeLog, uint32 partIdx, uint8 bucketTypeSize); + + template + void profileFunc(char* stats, uint32 partIdx); + + /* Match Functions */ + void initMatchFunc(TupleDesc desc, uint16 keyNum); + + void DispatchKeyInnerFunction(int KeyIndx); + + template + void DispatchKeyOuterFunction(int KeyIndx); + + /* complicate join key */ + void CalcComplicateHashVal(VectorBatch* batch, List* hashKeys, bool inner); + + /* Match Functions for complicate join key */ + template + void matchComplicateKey(VectorBatch* batch, SonicHashMemPartition* inPartition = NULL); + + /* partitions functions */ + uint32 calcPartitionNum(); + + void calcPartIdx(uint32* hashVal, uint32 partNum, int nrows); + + void calcRePartIdx(uint32* hashVal, uint32 partNum, uint32 rbit, int nrows); + + bool preparePartition(); + + void initProbePartitions(); + + template + void rePartition(uint32 rePartIdx); + + void recordPartitionInfo(bool buildside, int32 partIdx, uint32 istart, uint32 iend); + + void analyzePartition(bool buildside, uint32 startPartIdx, uint32 endPartIdx, int64* totalFileNum, + long* totalFileSize, long* partSizeMin, long* partSizeMax, int* spillPartNum); + + void reportSorthashinfo(ReportType reportType, uint32 totalPartNum, int32 rePartIdx = -1); + + template + void initPartition(SonicHashPartition* partition); + + void loadInnerPartitions(uint64 memorySize); + + void loadInnerPartition(uint32 partIdx); + + void loadMultiInnerPartition(uint32 partIdx, SonicHashMemPartition* memPartition); + + void quickSort(uint32* elements, const int start, const int end); + + void sortPartitionSize(uint64 memorySize); + + template + void saveProbePartition(); + + /* bloom filter functions */ + void pushDownFilterIfNeed(); + + /* clean functions */ + void finishJoinPartition(uint32 partIdx); + + void closePartFiles(uint32 partIdx); + + void releaseAllFileHandlerBuffer(bool isInner); + + void resetMemoryControl(); + uint64 get_hash_head_size(int64 rows); + +public: + double m_build_time; + double m_probe_time; + +private: + VectorBatch* (SonicHashJoin::*m_probeFun[2])(); + + typedef VectorBatch* (SonicHashJoin::*probeTypeFun)(SonicHashSource* probeP); + + /* save probe partition function */ + void (SonicHashJoin::*m_saveProbePartition)(); + + /* the build function */ + void (SonicHashJoin::*m_funBuild[2])(VectorBatch* batch); + + /* static information */ + probeTypeFun m_probeTypeFun; + + bool m_complicatekey; + + /* describe outer operator */ + SonicHashInputOpAttr m_probeOp; + + /* describe whether hash key is integer. */ + bool* m_integertype; + + /* runtime state */ + VecHashJoinState* m_runtime; + + /* where we put data */ + char* m_next; + + /* join strategy */ + uint8 m_strategy; + + /* runtime attribute */ + VectorBatch* m_outRawBatch; + + /* record matched position. */ + uint32 m_innerMatchLoc[2 * BatchMaxSize]; + uint32 m_innerPartMatchLoc[2 * BatchMaxSize]; + uint16 m_outerMatchLoc[2 * BatchMaxSize]; + uint16 m_matchLocIndx; + + /* rocord partition indexes of data in atom or batch */ + uint32 m_partIdx[INIT_DATUM_ARRAY_SIZE]; + uint32 m_probeIdx; + + /* memory need for each expand */ + size_t m_arrayExpandSize; + + /* partitions for inner source */ + SonicHashPartition** m_innerPartitions; + + /* partitions for outer source */ + SonicHashPartition** m_outerPartitions; + + /* + * Get build side data from lower operator. + * Used for join without spilling. + */ + SonicHashOpSource* m_hashOpPartition; + + /* status for probePartition() */ + uint8 m_probePartStatus; + + /* + * number of partitions. + * inner and outer should have the same number of partitions. + */ + uint32 m_partNum; + + /* partition index ordered by size */ + uint32* m_partSizeOrderedIdx; + + /* the offset in m_partSizeOrderedIdx that have been loaded */ + int32 m_partLoadedOffset; + + /* hash level for repartition */ + uint8* m_pLevel; + + /* maximum partition level need to be paid attention */ + uint8 m_maxPLevel; + + /* partition is from a valid repartition process or not: for repartition process */ + bool* m_isValid; + + /* + * the cjVector is only allocated and + * used when m_complicateJoinKey is true + */ + ScalarVector* m_cjVector; + /* complicate inner batch */ + VectorBatch* m_complicate_innerBatch; + /* complicate outer batch */ + VectorBatch* m_complicate_outerBatch; + + bool m_nulleqmatch[BatchMaxSize]; + + /* + * flag to show whether the build side partition is in memory. + * SONIC_PART_MAX_NUM is enough, because this array is not + * used after probePartition. + */ + bool m_memPartFlag[SONIC_PART_MAX_NUM]; + + /* record file partition info. */ + BatchPos m_diskPartIdx[BatchMaxSize]; + + /* number of data in m_diskPartIdx[] */ + uint32 m_diskPartNum; +}; + +extern bool isSonicHashJoinEnable(HashJoin* hj); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicint.h postgresql-hll-2.14/include/include/vectorsonic/vsonicint.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicint.h 2020-12-12 17:06:43.303348761 +0800 @@ -0,0 +1,318 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicint.h + * Routines to handle data type whose attribute length is + * 1, 2, 4, 8. + * The length of type can be retrieved from query below: + * select oid, typname from pg_type where typlen = len; + * There is one exception: + * TIDOID's length is 6, and use atomTypeSize 8. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicint.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +#include "vectorsonic/vsonicarray.h" + +template +class SonicIntTemplateDatumArray : public SonicDatumArray { +public: + SonicIntTemplateDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicIntTemplateDatumArray(){}; + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getDatumArray(int nrows, int* arrIdx, int* atomIdx, Datum* data); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + void loadDatumFlagArray(void* file, int rows); + + void loadIntValArray(void* file, int nrows); + + void loadIntVal(void* file, int rows); + + void setNthDatum(uint32 nth, ScalarValue* val); + + void putIntValArray(T* val, int nrows); + + void putIntVal(T* val, int nrows); +}; + +/* + * @Description: constructor. + * @in cxt - memory context. + * @in capacity - atom size. + * @in genBitMap - Whether use null flag. + * @in desc - data description. + */ +template +SonicIntTemplateDatumArray::SonicIntTemplateDatumArray( + MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc) + : SonicDatumArray(cxt, capacity) +{ + Assert(desc); + AutoContextSwitch memGuard(m_cxt); + + m_nullFlag = genBitMap; + m_desc = *desc; + m_atomTypeSize = m_desc.typeSize; + genNewArray(genBitMap); + /* + * The first position in the first atom doesn't have data. + * And set the first flag to NULL. + */ + if (m_nullFlag) + setNthNullFlag(0, true); + + m_atomIdx = 1; +} + +/* + * @Description: put function. + * keep parameter flag to keep the same interfaces as + * as other data types. Do not check flag for better efficiency. + * @in vals - data to put. + * @in flag - flag, not used here. + * @in rows - the number of data to put. + */ +template +void SonicIntTemplateDatumArray::putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows) +{ + T* dst = (T*)(m_curAtom->data + sizeof(T) * m_atomIdx); + for (int i = 0; i < rows; i++) { + *dst = (T)(*vals); + dst++; + vals++; + } +} + +/* + * @Description: Get function. Get val. + * @in arrIdx - array index. + * @in atomIdx - index in atom. + * @in val - output value. + * @return - Datum values. + */ +template +Datum SonicIntTemplateDatumArray::getDatum(int arrIdx, int atomIdx) +{ + Assert(0 <= arrIdx && arrIdx < m_arrSize); + Assert(0 <= atomIdx && (uint32)atomIdx < m_atomSize); + + return (Datum)((T*)m_arr[arrIdx]->data)[atomIdx]; +} + +/* + * @Description: Get function. Get both val and flag. + * @in arrIdx - array index. + * @in atomIdx - index in atom. + * @in val - output value. + * @in flag - output flag. + */ +template +void SonicIntTemplateDatumArray::getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag) +{ + Assert(0 <= arrIdx && arrIdx < m_arrSize); + Assert(0 <= atomIdx && (uint32)atomIdx < m_atomSize); + + *val = ((T*)m_arr[arrIdx]->data)[atomIdx]; + *flag = getNthNullFlag(arrIdx, atomIdx); +} + +/* + * @Description: Get function. Get vals. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumArray(int nrows, int* arrIdx, int* atomIdx, Datum* data) +{ + Assert(nrows <= BatchMaxSize); + int i; + + for (i = 0; i < nrows; i++) { + *data = (Datum)((T*)m_arr[*arrIdx]->data)[*atomIdx]; + arrIdx++; + atomIdx++; + data++; + } +} + +/* + * @Description: Get function. Get both vals and flags. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * @in flag - output flags. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag) +{ + Assert(nrows <= BatchMaxSize); + int i; + + for (i = 0; i < nrows; i++) { + *flag = getNthNullFlag(arrayIdx->arrIdx, arrayIdx->atomIdx); + *data = (Datum)((T*)m_arr[arrayIdx->arrIdx]->data)[arrayIdx->atomIdx]; + arrayIdx++; + data++; + flag++; + } +} + +/* + * @Description: Get function when does hash key matching. Get data and flag from atoms. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * @in flag - output flags. + * @in matchIdx - matched array. If false, means current tuple pair doesn't match, + * so no need to get datum and flag any more, skip it. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumFlagArrayWithMatch( + int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx) +{ + Assert(nrows <= BatchMaxSize); + for (int i = 0; i < nrows; i++) { + if (*matchIdx) { + int arrIdx = arrayIdx->arrIdx; + int atomIdx = arrayIdx->atomIdx; + + *flag = m_arr[arrIdx]->nullFlag[atomIdx]; + *data = (Datum)((T*)m_arr[arrIdx]->data)[atomIdx]; + } + matchIdx++; + arrayIdx++; + data++; + flag++; + } +} + +/* + * @Description: set value into nth position in atom. + * The space in atom must be valid. + * @in nth - value position. + * @in val - value to put. + */ +template +void SonicIntTemplateDatumArray::setNthDatum(uint32 nth, ScalarValue* val) +{ + int arrIndx; + int atomIndx; + + arrIndx = (int)getArrayIndx(nth, m_nbit); + atomIndx = (int)getArrayLoc(nth, m_atomSize - 1); + + // Make sure the space is already allocated. + Assert(&(((T*)m_arr[arrIndx]->data)[atomIndx])); + ((T*)m_arr[arrIndx]->data)[atomIndx] = (T)*val; +} + +/* + * @Description: put data into atom. + * Do not consider flag in this function. + * If more space is needed, allocate it. + * @in val - data to put. + * @in nrows - the number of data. + */ +template +void SonicIntTemplateDatumArray::putIntValArray(T* val, int nrows) +{ + int loopRows; + + bool needExpand = (uint32)nrows > (m_atomSize - m_atomIdx); + loopRows = needExpand ? (m_atomSize - m_atomIdx) : nrows; + + if (loopRows > 0) { + putIntVal(val, loopRows); + m_atomIdx += loopRows; + } + + if (needExpand) { + genNewArray(m_nullFlag); + putIntValArray(val + loopRows, nrows - loopRows); + } +} + +/* + * @Description: put data into single atom. + * Do not consider flag in this function. + * The atom used must be valid. + * @in val - data to put. + * @in nrows - the number of data. + */ +template +void SonicIntTemplateDatumArray::putIntVal(T* val, int nrows) +{ + T* dst = (uint32*)(m_curAtom->data + sizeof(T) * m_atomIdx); + for (int i = 0; i < nrows; i++) { + *dst = *val; + dst++; + val++; + } +} + +extern SonicDatumArray* AllocateIntArray( + MemoryContext createContext, MemoryContext internalContext, int capacity, bool genNullFlag, DatumDesc* desc); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicnumeric.h postgresql-hll-2.14/include/include/vectorsonic/vsonicnumeric.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicnumeric.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicnumeric.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,97 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicnumeric.h + * Routines to handle Numeric data type. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicnumeric.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +#include "vectorsonic/vsonicarray.h" + +class SonicNumericDatumArray : public SonicDatumArray { +public: + SonicNumericDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicNumericDatumArray(){}; + + void genAdditonArr(); + + void genNewArray(bool genBitMap); + + void setResultBuf(char* resultBuf, int* bufIndx); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* fileSource, int leftrows); + + void loadDatumFlagArray(void* fileSource, int rows); + +public: + /* Used for non-numeric64. */ + VarBuf* m_buf; + /* Manage multiple m_curOffset. */ + uint32** m_offsetArr; + /* Record current offset. */ + uint32* m_curOffset; + int m_offArrSize; + uint32 m_internalLen; + uint32 m_curLen; + /* Used for numeric64 when get from atom. */ + char* m_tmpBuf; + int m_tmpBufIdx; + char* m_atomBuf; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/vectorsonic/vsonicpartition.h postgresql-hll-2.14/include/include/vectorsonic/vsonicpartition.h --- postgresql-hll-2.14_old/include/include/vectorsonic/vsonicpartition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/vectorsonic/vsonicpartition.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,233 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicpartition.h + * sonic partition class and class member declare + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicpartition.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "vectorsonic/vsonichash.h" +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicfilesource.h" + +/* int typeSize has 4 values:1,2,4,8. */ +#define int_typeSize_1Byte 1 +#define int_typeSize_2Byte 2 +#define int_typeSize_4Byte 4 +#define int_typeSize_8Byte 8 + +typedef enum { + partitionStatusInitial = 1, + partitionStatusMemory, + partitionStatusFile, + partitionStatusFinish +} PartitionStatus; + +class SonicHashPartition : public SonicHashSource { + +public: + /* memory context partition holds */ + MemoryContext m_context; + + /* partition status */ + PartitionStatus m_status; + + /* number of columns */ + uint16 m_cols; + + /* number of rows partition holds */ + int64 m_rows; + + /* number of records in each files */ + uint64* m_fileRecords; + + /* total byte size of data */ + size_t m_size; + +public: + SonicHashPartition(const char* cxtname, uint16 cols, int64 workMem); + ~SonicHashPartition(){}; + + virtual void freeResources() + { + Assert(false); + } + + virtual void init(uint16 colIdx, DatumDesc* desc) + { + Assert(false); + } + + virtual void putHash(uint32* hashValues, uint64 nrows = 1) + { + Assert(false); + } + + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + Assert(false); + } + + virtual bool isValid() + { + Assert(false); + return false; + } +}; + +class SonicHashMemPartition : public SonicHashPartition { + +public: + /* where to put data */ + SonicDatumArray** m_data; + + /* For complicate join key */ + SonicDatumArray* m_hash; + + uint8 m_bucketTypeSize; + + uint32 m_hashSize; + + uint32 m_mask; + + bool m_segHashTable; + + /* non-segment hashtable */ + char* m_bucket; + + char* m_next; + + /* Segment hashtable */ + SonicDatumArray* m_segBucket; + + SonicDatumArray* m_segNext; + +public: + SonicHashMemPartition(const char* cxtname, bool hasHash, TupleDesc tupleDesc, int64 workMem); + ~SonicHashMemPartition(){}; + + void init(uint16 colIdx, DatumDesc* desc); + + void freeResources(); + + void putBatch(VectorBatch* batch); + + void flushPartition(int arrIdx, uint32* partIdx, SonicHashPartition** filePartitions, int nrows); + + void loadPartition(void* filePartition); + + void loadHash(void* partition); + + void putHash(uint32* hashValues, uint64 nrows); + + inline bool isValid(); + +private: + /* + * @Description: put ScalarValue column into SonicDatumArray per column + * actually, in memory, putVal has not been used. + * @in val - data to put + * @in flag - flag to put + * @in colIdx - column index this data belongs to + */ + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + m_data[colIdx]->putArray(val, flag, 1); + } +}; + +class SonicHashFilePartition : public SonicHashPartition { + +public: + /* number of files */ + uint16 m_fileNum; + + /* pointers of files */ + SonicHashFileSource** m_files; + + /* + * record the size of varible data which will not contained within the Atom's allocated space + * when loading into memory, such as SONIC_NUMERIC_COMPRESS_TYPE and SONIC_VAR_TYPE, + * whose data may stored in buffers (eg. VarBuf) other than Atom. + * The Atom only holds the pointers of the data. + */ + size_t m_varSize; + + /* assembled batch */ + VectorBatch* m_batch; + + int* m_filetype; + +public: + SonicHashFilePartition(const char* cxtname, bool hasHash, TupleDesc tupleDesc, int64 workMem); + + SonicHashFilePartition(const char* cxtname, VectorBatch* out_batch, int64 workMem); + + ~SonicHashFilePartition(){}; + + void init(uint16 fileIdx, DatumDesc* desc); + + void prepareFileHandlerBuffer(); + + void releaseFileHandlerBuffer(); + + void freeResources(); + + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + if (optspill) { + int fileidx = m_filetype[colIdx]; + size_t written = m_files[fileidx]->writeVal(val, *flag); + /* fix row number */ + m_fileRecords[fileidx]++; + /* record written size */ + m_size += written; + pgstat_increase_session_spill_size(written); + } else { + size_t written = m_files[colIdx]->writeVal(val, *flag); + /* fix row number */ + m_fileRecords[colIdx]++; + /* record written size */ + m_size += written; + pgstat_increase_session_spill_size(written); + } + } + + void putHash(uint32* hashValues, uint64 nrows = 1); + + void getHash(uint32* hashValues, uint64 nrows); + + VectorBatch* getBatch(); + + void closeFiles(); + + void rewindFiles(); + + inline bool isValid(); +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/windowapi.h postgresql-hll-2.14/include/include/windowapi.h --- postgresql-hll-2.14_old/include/include/windowapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/windowapi.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,162 @@ +/* ------------------------------------------------------------------------- + * + * windowapi.h + * API for window functions to extract data from their window + * + * A window function does not receive its arguments in the normal way + * (and therefore the concept of strictness is irrelevant). Instead it + * receives a "WindowObject", which it can fetch with PG_WINDOW_OBJECT() + * (note V1 calling convention must be used). Correct call context can + * be tested with WindowObjectIsValid(). Although argument values are + * not passed, the call is correctly set up so that PG_NARGS() can be + * used and argument type information can be obtained with + * get_fn_expr_argtype(), get_fn_expr_arg_stable(), etc. + * + * Operations on the WindowObject allow the window function to find out + * the current row number, total number of rows in the partition, etc + * and to evaluate its argument expression(s) at various rows in the + * window partition. See the header comments for each WindowObject API + * function in nodeWindowAgg.c for details. + * + * + * Portions Copyright (c) 2000-2012, PostgreSQL Global Development Group + * + * src/include/windowapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef WINDOWAPI_H +#define WINDOWAPI_H + +/* values of "seektype" */ +#define WINDOW_SEEK_CURRENT 0 +#define WINDOW_SEEK_HEAD 1 +#define WINDOW_SEEK_TAIL 2 +#include "nodes/execnodes.h" + +typedef struct rownumber_context { + int64 rownumber; +} rownumber_context; + +/* + * ranking process information + */ +typedef struct rank_context { + int64 rank; /* current rank */ +} rank_context; +/* + * All the window function APIs are called with this object, which is passed + * to window functions as fcinfo->context. + */ +typedef struct WindowObjectData { + NodeTag type; + WindowAggState* winstate; /* parent WindowAggState */ + List* argstates; /* ExprState trees for fn's arguments */ + void* localmem; /* WinGetPartitionLocalMemory's chunk */ + int markptr; /* tuplestore mark pointer for this fn */ + int readptr; /* tuplestore read pointer for this fn */ + int64 markpos; /* row that markptr is positioned on */ + int64 seekpos; /* row that readptr is positioned on */ +} WindowObjectData; + +/* this struct is private in nodeWindowAgg.c */ +typedef struct WindowObjectData* WindowObject; +/* + * We have one WindowStatePerFunc struct for each window function and + * window aggregate handled by this node. + */ +typedef struct WindowStatePerFuncData { + /* Links to WindowFunc expr and state nodes this working state is for */ + WindowFuncExprState* wfuncstate; + WindowFunc* wfunc; + + int numArguments; /* number of arguments */ + + FmgrInfo flinfo; /* fmgr lookup data for window function */ + + Oid winCollation; /* collation derived for window function */ + + /* + * We need the len and byval info for the result of each function in order + * to know how to copy/delete values. + */ + int16 resulttypeLen; + bool resulttypeByVal; + + bool plain_agg; /* is it just a plain aggregate function? */ + int aggno; /* if so, index of its PerAggData */ + + WindowObject winobj; /* object used in window function API */ + + // Vectorization specific + // + AttrNumber m_resultCol; // position in the output batch + +} WindowStatePerFuncData; + +/* + * For plain aggregate window functions, we also have one of these. + */ +typedef struct WindowStatePerAggData { + /* Oids of transfer functions */ + Oid transfn_oid; + Oid finalfn_oid; /* may be InvalidOid */ + + /* + * fmgr lookup data for transfer functions --- only valid when + * corresponding oid is not InvalidOid. Note in particular that fn_strict + * flags are kept here. + */ + FmgrInfo transfn; + FmgrInfo finalfn; + + /* + * initial value from pg_aggregate entry + */ + Datum initValue; + bool initValueIsNull; + + /* + * cached value for current frame boundaries + */ + Datum resultValue; + bool resultValueIsNull; + + /* + * We need the len and byval info for the agg's input, result, and + * transition data types in order to know how to copy/delete values. + */ + int16 inputtypeLen, resulttypeLen, transtypeLen; + bool inputtypeByVal, resulttypeByVal, transtypeByVal; + + int wfuncno; /* index of associated PerFuncData */ + + /* Current transition value */ + Datum transValue; /* current transition value */ + bool transValueIsNull; + + bool noTransValue; /* true if transValue not set yet */ +} WindowStatePerAggData; + +#define PG_WINDOW_OBJECT() ((WindowObject)fcinfo->context) + +#define WindowObjectIsValid(winobj) ((winobj) != NULL && IsA(winobj, WindowObjectData)) + +extern void* WinGetPartitionLocalMemory(WindowObject winobj, Size sz); + +extern int64 WinGetCurrentPosition(WindowObject winobj); +extern int64 WinGetPartitionRowCount(WindowObject winobj); + +extern void WinSetMarkPosition(WindowObject winobj, int64 markpos); + +extern bool WinRowsArePeers(WindowObject winobj, int64 pos1, int64 pos2); + +extern Datum WinGetFuncArgInPartition( + WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool* isnull, bool* isout); + +extern Datum WinGetFuncArgInFrame( + WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool* isnull, bool* isout); + +extern Datum WinGetFuncArgCurrent(WindowObject winobj, int argno, bool* isnull); + +#endif /* WINDOWAPI_H */ diff -uprN postgresql-hll-2.14_old/include/include/workload/commgr.h postgresql-hll-2.14/include/include/workload/commgr.h --- postgresql-hll-2.14_old/include/include/workload/commgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/commgr.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * commgr.h + * definitions for statistics control functions + * + * IDENTIFICATION + * src/include/workload/commgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef WORKLOAD_COMMGR_H +#define WORKLOAD_COMMGR_H + +#include "pgxc/pgxcnode.h" + +typedef void (*WLMParseDetail)(const char*, void*); +typedef void (*WLMParseMessage)(StringInfo, void*, int); + +typedef enum WLMCollectTag { + WLM_COLLECT_NONE = 0, + WLM_COLLECT_UTIL, + WLM_COLLECT_USERINFO, + WLM_COLLECT_SESSINFO, + WLM_COLLECT_IO_RUNTIME, + WLM_COLLECT_PROCINFO, + WLM_COLLECT_ANY, + WLM_COLLECT_OPERATOR_RUNTIME, + WLM_COLLECT_OPERATOR_SESSION, + WLM_COLLECT_ADJUST, + WLM_COLLECT_JOBINFO +} WLMCollectTag; + +extern LWLock* LockSessRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockSessHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockSessRealTHashPartition(uint32 hashCode); +extern void UnLockSessHistHashPartition(uint32 hashCode); +extern LWLock* LockInstanceRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockInstanceHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockInstanceRealTHashPartition(uint32 hashCode); +extern void UnLockInstanceHistHashPartition(uint32 hashCode); +extern void WLMLocalInfoCollector(StringInfo msg); +extern List* WLMRemoteJobInfoCollector(const char* keystr, void* suminfo, WLMCollectTag tag); +extern void WLMRemoteInfoCollector( + const char* keystr, void* suminfo, WLMCollectTag tag, int size, WLMParseMessage parse_func); +extern PGXCNodeAllHandles* WLMRemoteInfoCollectorStart(void); +extern int WLMRemoteInfoSenderByNG(const char* group_name, const char* keystr, WLMCollectTag tag); +extern int WLMRemoteInfoSender(PGXCNodeAllHandles* pgxc_handles, const char* keystr, WLMCollectTag tag); +extern void WLMRemoteInfoReceiverByNG(const char* group_name, void* suminfo, int size, WLMParseMessage parse_func); +extern void WLMRemoteInfoReceiver( + PGXCNodeAllHandles* pgxc_handles, void* suminfo, int size, WLMParseMessage parse_func); +extern void WLMRemoteInfoCollectorFinish(PGXCNodeAllHandles* pgxc_handles); +extern void WLMRemoteNodeExecuteSql(const char* sql, int nodeid = 0); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/cpwlm.h postgresql-hll-2.14/include/include/workload/cpwlm.h --- postgresql-hll-2.14_old/include/include/workload/cpwlm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/cpwlm.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,77 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cpwlm.h + * + * + * IDENTIFICATION + * src/include/workload/cpwlm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CPWLM_H +#define CPWLM_H + +#include "lib/stringinfo.h" +#include "pgxc/pgxcnode.h" + +/* core data in CCN of the compute pool */ +typedef struct DNState { + bool is_normal; + int num_rp; +} DNState; + +/* core data in CCN of the compute pool */ +typedef struct { + DNState* dn_state; + int dn_num; +} ComputePoolState; + +/* from the CN of the compute pool */ +typedef struct { + int dnnum; + int freerp; + char* version; +} CPRuntimeInfo; + +/* from the conf file in CN data directory of DWS. */ +typedef struct { + char* cpip; + char* cpport; + char* username; + char* password; + char* version; + int dnnum; + int pl; + int rpthreshold; +} ComputePoolConfig; + +extern List* get_dnlist(int neededDNnum); +extern ComputePoolState* get_cluster_state(); +extern void process_request(StringInfo input_message); +extern void get_cp_runtime_info(PGXCNodeHandle* handle); +extern char* get_version(); +extern ComputePoolConfig** get_cp_conninfo(int* cnum = NULL); + +extern char* trim(char* src); + +extern bool check_version_compatibility(const char* remote_version); + +/* just run on DN */ +extern void decrease_rp_number(); +extern void increase_rp_number(); + +#endif // CPWLM_H diff -uprN postgresql-hll-2.14_old/include/include/workload/ctxctl.h postgresql-hll-2.14/include/include/workload/ctxctl.h --- postgresql-hll-2.14_old/include/include/workload/ctxctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/ctxctl.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,521 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ctxctl.h + * definitions for context control functions + * + * IDENTIFICATION + * src/include/workload/ctxctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CTXCTL_H +#define CTXCTL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "gstrace/gstrace_infra.h" + +#define THREADID (gettid()) +#define PROCESSID (getpid()) + +#define DUP_ARRAY_POINTER(p, n) pobjdup(p, n) +#define DUP_POINTER(p) DUP_ARRAY_POINTER(p, 1) + +/* use a mutext lock */ +#define USE_CONTEXT_LOCK(mutex) \ + WLMContextLock sp_mutex_lock(mutex); \ + sp_mutex_lock.Lock() +/* use a lwlock */ +#define USE_AUTO_LWLOCK(lockid, lockmode) \ + WLMAutoLWLock sp_lwlock(lockid, lockmode); \ + sp_lwlock.AutoLWLockAcquire() +/* use a memory context */ +#define USE_MEMORY_CONTEXT(context) \ + WLMContextGuard spcxt((CleanHandler)MemoryContextSwitchTo, MemoryContextSwitchTo(context)) +/* use a smart context guard */ +#define USE_CONTEXT_GUARD(handler, object) WLMContextGuard sp_guard((CleanHandler)handler, object) +/* make ptr a smart pointer */ +#define MAKE_SMART_POINTER(ptr) USE_CONTEXT_GUARD(pfree, ptr) + +#define RELEASE_CONTEXT_LOCK() sp_mutex_lock.UnLock() +#define RELEASE_AUTO_LWLOCK() sp_lwlock.AutoLWLockRelease() +#define REVERT_MEMORY_CONTEXT() spcxt.handle() + +#define USE_LOCK_TO_ADD(mutex, src, inc) \ + do { \ + USE_CONTEXT_LOCK(&mutex); \ + src += inc; \ + if (src < 0) \ + src = 0; \ + } while (0); + +#define HANDLE_CONTEXT_GUARD() sp_guard.handle() + +#define IS_MUTEX_HELD(mutex, pid) ((mutex)->__data.__owner == pid) + +#define securec_check_errval(errno, express, elevel) \ + do { \ + errno_t resno = errno; \ + if (EOK != resno) { \ + express; \ + switch (resno) { \ + case EINVAL: \ + elog(elevel, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(elevel, "%s : %d : The Source Buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(elevel, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(elevel, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(elevel, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(elevel, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } while (0) + +#define securec_check_ssval(errno, express, elevel) \ + do { \ + errno_t resno = errno; \ + if (resno == -1) { \ + express; \ + elog(elevel, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } while (0) + +typedef void (*CleanHandler)(void*); + +extern void* palloc0_noexcept(Size size); + +template +struct smart_ptr { + smart_ptr() : m_handler(NULL), m_ptr(NULL) + {} + + explicit smart_ptr(T* ptr) : m_handler(pfree), m_ptr(ptr) + {} + + smart_ptr(CleanHandler myHandler, T* ptr) : m_handler(myHandler), m_ptr(ptr) + {} + + ~smart_ptr() + { + handle(); + } + + T* set(Size size) + { + m_handler = pfree; + m_ptr = palloc0(size); + + return m_ptr; + } + + void set(T* ptr) + { + m_handler = pfree; + m_ptr = ptr; + } + + void set(CleanHandler handler, T* ptr) + { + m_handler = handler; + m_ptr = ptr; + } + + void reset() + { + m_handler = NULL; + m_ptr = NULL; + } + + T* ptr() + { + return m_ptr; + } + + T* operator->() const + { + return m_ptr; + } + + void handle() + { + if (m_handler) + m_handler(m_ptr); + + reset(); + } + +protected: + smart_ptr(const smart_ptr&); + smart_ptr& operator=(const smart_ptr&); + +private: + CleanHandler m_handler; + T* m_ptr; +}; + +struct WLMContextLock { + WLMContextLock(pthread_mutex_t* mutex) + : m_mutex(mutex), m_isLocked(false), m_exitUnlock(true), m_clean(NULL), m_ptr(NULL), m_tid(THREADID) + {} + + WLMContextLock(pthread_mutex_t* mutex, bool thread_exit_unlock) + : m_mutex(mutex), + m_isLocked(false), + m_exitUnlock(thread_exit_unlock), + m_clean(NULL), + m_ptr(NULL), + m_tid(THREADID) + {} + + ~WLMContextLock() + { + if (t_thrd.proc_cxt.proc_exit_inprogress && !m_exitUnlock) { + m_isLocked = false; + } + UnLock(); + } + + void Lock(bool isForce = false) + { + if (isForce || !m_isLocked) { + if (!IsOwner()) + (void)pthread_mutex_lock(m_mutex); + m_isLocked = true; + } + } + + bool TryLock() + { + if (!m_isLocked) { + int ret = pthread_mutex_trylock(m_mutex); + if (ret == 0) + m_isLocked = true; + } + + return m_isLocked; + } + + void UnLock(bool isSafe = false) + { + if (m_isLocked) { + clean(); + + if (!isSafe || IsOwner()) + (void)pthread_mutex_unlock(m_mutex); + + m_isLocked = false; + } + } + + bool IsOwner() + { + return IS_MUTEX_HELD(m_mutex, m_tid); + } + + void ReleaseLock(pthread_mutex_t* mutex) + { + pthread_mutex_t* old_mutex = m_mutex; + + m_mutex = mutex; + + if (IsOwner()) + (void)pthread_mutex_unlock(m_mutex); + + m_mutex = old_mutex; + } + + bool replace(pthread_mutex_t* mutex) + { + if (!m_isLocked) { + m_mutex = mutex; + return true; + } + + return false; + } + + void set(CleanHandler func, void* ptr) + { + m_clean = func; + m_ptr = ptr; + } + /* + * function name: reset + * description : reset params to handle for context lock. + * return value : void + */ + void reset() + { + m_clean = NULL; + m_ptr = NULL; + } + /* + * function name: clean + * description : execute the clean handler for context lock. + * return value : void + */ + void clean() + { + if (m_clean) { + m_clean(m_ptr); + reset(); + } + } + /* + * function name: ConditionWait + * description : execute the condition wait + * return value : void + */ + void ConditionWait(pthread_cond_t* condition) + { + (void)pthread_cond_wait(condition, m_mutex); + } + + void ConditionTimedWait(pthread_cond_t* condition, int seconds) + { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += seconds; + (void)pthread_cond_timedwait(condition, m_mutex, &ts); + } + + void ConditionWakeUp(pthread_cond_t* condition) + { + (void)pthread_cond_signal(condition); + } + +private: + pthread_mutex_t* m_mutex; + bool m_isLocked; + bool m_exitUnlock; + + CleanHandler m_clean; + void* m_ptr; + + pid_t m_tid; +}; + +#define WORKLOAD_LOCK_NUM ((int)WorkloadNodeGroupLock + 10) + +class WLMAutoLWLock { +public: + WLMAutoLWLock(LWLock *lock, LWLockMode lockMode) : m_lockId(lock), m_lockMode(lockMode), m_isLocked(false) + {} + + ~WLMAutoLWLock() + { + AutoLWLockRelease(); + } + + inline void AutoLWLockAcquire() + { + // Guard against recursive lock + if (!m_isLocked) { + LWLockAcquire(m_lockId, m_lockMode); + m_isLocked = true; + } + } + + inline void AutoLWLockRelease() + { + if (m_isLocked && !t_thrd.port_cxt.thread_is_exiting) { + /* maybe there is try-catch operation, + * it resets the t_thrd.int_cxt.InterruptHoldoffCount as 0. + * So reset it again to avoid core issue */ + if (t_thrd.int_cxt.InterruptHoldoffCount == 0) + HOLD_INTERRUPTS(); + LWLockRelease(m_lockId); + m_isLocked = false; + } + } + +private: + LWLock *m_lockId; + LWLockMode m_lockMode; + bool m_isLocked; +}; + +typedef smart_ptr WLMContextGuard; + +template +T* pobjdup(T* ptr, size_t n) +{ + if (ptr == NULL) + return ptr; + + T* duptr = (T*)palloc0_noexcept(sizeof(T) * n); + + if (duptr == NULL) + return duptr; + + errno_t errval = memcpy_s(duptr, n * sizeof(T), ptr, n * sizeof(T)); + securec_check_errval(errval, , LOG); + + return duptr; +} + +template +NodeType* search_node(const List* list, const KeyType* keydata) +{ + foreach_cell(cell, list) + { + NodeType* node = (NodeType*)lfirst(cell); + + if (node->equals(keydata)) + return node; + } + + return NULL; +} + +template +ListCell* search_list(const List* list, const KeyType* keydata, bool* found) +{ + ListCell* curr = NULL; + ListCell* prev = NULL; + NodeType* node = NULL; + + if (found != NULL) + *found = false; + + foreach (curr, list) { + node = (NodeType*)lfirst(curr); + + int comp = node->compare(keydata); + + if (comp == 0) { + if (found != NULL) + *found = true; + + return curr; + } else if (comp > 0) + return prev; + + prev = curr; + } + + return prev; +} + +template +ListCell* append_to_list(List** list, const KeyType* keydata, NodeType* node = NULL) +{ + bool found = false; + + ListCell* lcnode = search_list(*list, keydata, &found); + + if (found) + return lcnode; + + /* cannot find the node with this priority, we must create a new one. */ + if (ToAlloc) + node = (NodeType*)palloc0_noexcept(sizeof(NodeType)); + + if (node == NULL) + return NULL; + + PG_TRY(); + { + if (lcnode == NULL) { + *list = lcons(node, *list); + + lcnode = list_head(*list); + } else { + lcnode = lappend_cell(*list, lcnode, node); + } + } + PG_CATCH(); + { + lcnode = NULL; + + if (ToAlloc) + pfree(node); + + FlushErrorState(); + } + PG_END_TRY(); + + return lcnode; +} + +/* + * @Description: scan hash table, assign all the info "is_dirty" true + * @IN htab: hash table + * @Return: void + * @See also: + */ +template +void AssignHTabInfoDirtyWithLock(HTAB* htab, LWLock *lwlock) +{ + DataType* hdata = NULL; + + HASH_SEQ_STATUS hash_seq; + + USE_AUTO_LWLOCK(lwlock, LW_EXCLUSIVE); + + hash_seq_init(&hash_seq, htab); + + while ((hdata = (DataType*)hash_seq_search(&hash_seq)) != NULL) + hdata->is_dirty = true; +} + +template +void ProcessHTabRecordWithLock(HTAB* htab, LWLock *lwlock, CleanHandler handle) +{ + DataType* hdata = NULL; + + HASH_SEQ_STATUS hash_seq; + + USE_AUTO_LWLOCK(lwlock, LW_EXCLUSIVE); + + hash_seq_init(&hash_seq, htab); + + while ((hdata = (DataType*)hash_seq_search(&hash_seq)) != NULL) + handle(hdata); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/dywlm_client.h postgresql-hll-2.14/include/include/workload/dywlm_client.h --- postgresql-hll-2.14_old/include/include/workload/dywlm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/dywlm_client.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,191 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dywlm_client.h + * definitions for parallel control functions + * + * + * IDENTIFICATION + * src/include/workload/dywlm_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DYWLM_CLIENT1_H +#define DYWLM_CLIENT1_H + +#include "utils/hsearch.h" +#include "nodes/pg_list.h" +#include "workload/gscgroup.h" +#include "workload/statctl.h" +#include "workload/parctl.h" +#include "executor/execdesc.h" + +#define DYWLM_SEND_OK -5000 +#define DYWLM_SEND_FAILED -5001 +#define DYWLM_NO_NODE -5002 +#define DYWLM_NO_RECORD -5003 +#define DYWLM_NO_NGROUP -5004 + +#define DYWLM_TOP_QUOTA 90 +#define DYWLM_HIGH_QUOTA 80 +#define DYWLM_MEDIUM_QUOTA 60 +#define DYWLM_LOW_QUOTA 10 + +typedef struct ClientDynamicManager { + int active_statements; /* the number of active statements */ + int max_info_count; /* max info count in the hash table */ + int max_active_statements; /* global max active statements */ + int max_support_statements; /* max supported statement count */ + int max_statements; /* max statements in active */ + int current_support_statements; /* current statements who occupy memory */ + int central_waiting_count; /* count number in central queue waiting list */ + + int usedsize; /* used memory for client */ + int cluster; /* whether is cluster */ + int freesize; /* free memory size */ + + int running_count; /* count of complicated query */ + + bool recover; /* recovering mode */ + + char* group_name; /* group name */ + void* srvmgr; /* server manager */ + + HTAB* dynamic_info_hashtbl; /* resource pool is stored in this hash table*/ + List* statements_waiting_list; /* list for statements are waiting to do due to active statements over + max_active_statements */ + pthread_mutex_t statement_list_mutex; /* a mutex to lock statements waiting list */ +} ClientDynamicManager; + +struct DynamicInfoNode { + Qid qid; /* a id of a query */ + ThreadId threadid; /* thread id for a query */ + + int memsize; /* memory size to reserve */ + int max_memsize; /* max memory size to reserve */ + int min_memsize; /* min memory size to reserve */ + int priority; /* priority */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a query in the resource pool */ + + pthread_cond_t condition; /* The condition of the node to wake up */ + pthread_mutex_t mutex; /* mutex to wake up thread */ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char ngroup[NAMEDATALEN]; /* node group name */ + + bool wakeup; /* whether is woken up */ + bool is_dirty; /* whether is dirty */ + bool use_planb; /* whether use plan b */ +}; + +struct DynamicMessageInfo { + Qid qid; /* a id of a query */ + int memsize; /* memory size to reserve */ + int max_memsize; /* max memory size to reserve */ + int min_memsize; /* min memory size to reserve */ + int priority; /* priority */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a query in the resource pool */ + + ParctlType qtype; /* parallel control type */ + EnqueueType etype; /* enqueue type */ + + bool isserver; /* check the message whether is from server */ + bool use_max_mem; /* check whether use maximum memsize to execute */ + bool subquery; /* check whether is subquery */ + bool insubquery; /* check whether is the first subquery in one query*/ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char nodename[NAMEDATALEN]; /* node name */ + char groupname[NAMEDATALEN]; /* node group name */ +}; + +struct DynamicWorkloadRecord { + Qid qid; /* a id of a query */ + + int memsize; /* memory size reserved for a query */ + int max_memsize; /* max memory size reserved for a query */ + int min_memsize; /* min memory size reserved for a query */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a resource pool */ + int priority; /* priority of the record */ + + ParctlType qtype; /* parallel control type */ + WLMListNode* pnode; /* head of the queue, point to priority queue node */ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char nodename[NAMEDATALEN]; /* node name */ + char groupname[NAMEDATALEN]; /* node group name */ + + bool try_wakeup; /* trying to wake up the query */ + bool removed; /* query already be removed */ + bool is_dirty; /* record is dirty */ + bool maybe_deleted; /* the record is already deleted probably */ + bool use_planb; /* check whether use planb to execute */ + + bool equals(const Qid* qid) + { + return IsQidEqual(&this->qid, qid); /* check qid is matched */ + } +}; + +extern ClientDynamicManager g_client_dywlm; +extern THR_LOCAL bool WLMProcessExiting; + +extern void dywlm_client_receive(StringInfo msg); +extern void dywlm_client_release(ParctlState* state); +extern void dywlm_client_reserve(void); +extern void dywlm_parallel_ready(const char* sqltext); +extern int dywlm_client_post(ClientDynamicManager*, const DynamicMessageInfo* msginfo); +extern int dywlm_get_central_node_idx(void); +extern void dywlm_client_write_catalog(StringInfo input_message); +extern void dywlm_client_recover(ClientDynamicManager*); +extern void dywlm_client_max_reserve(void); +extern void dywlm_client_max_release(ParctlState* state); +extern void dywlm_update_max_statements(int active_stetements); + +extern char* dywlm_get_node_name(Oid nodeidx, char* nodename); +extern int dywlm_get_node_idx(const char* nodename); +extern int dywlm_client_physical_info(int* total_mem, int* free_mem); +extern DynamicWorkloadRecord* dywlm_get_records(int* num); + +extern void dywlm_client_move_node_to_list(void* ng, ThreadId tid, const char* cgroup); +extern int dywlm_client_jump_queue(ClientDynamicManager*, ThreadId tid); +extern bool dywlm_client_is_cluster(); +extern int64 dywlm_client_get_memory(void); +extern int64 dywlm_client_get_max_memory(bool* use_tenant); +extern int64 dywlm_client_get_free_memory(void); +extern void dywlm_client_get_memory_info(int* total_mem, int* free_mem, bool* use_tenant); +extern void dywlm_client_set_respool_memory(int size, WLMStatusTag); +extern void dywlm_client_clean(void* ptr); +extern void dywlm_client_manager(QueryDesc* queryDesc, bool isQueryDesc = true); +extern void dywlm_client_verify_register(void); +extern int dywlm_get_cpu_count(void); +extern int dywlm_get_cpu_util(void); +extern int dywlm_get_active_statement_count(void); + +extern void dywlm_client_proc_release(void); + +extern void dywlm_client_display_climgr_info(StringInfo strinfo); +bool dywlm_is_local_node(); +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/dywlm_server.h postgresql-hll-2.14/include/include/workload/dywlm_server.h --- postgresql-hll-2.14_old/include/include/workload/dywlm_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/dywlm_server.h 2020-12-12 17:06:43.304348774 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dywlm_server.h + * definitions for parallel control functions + * + * + * IDENTIFICATION + * src/include/workload/dywlm_server.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DYWLM_SERVER1_H +#define DYWLM_SERVER1_H + +#define UPDATE_FREQUENCY 3 /*updating resource utilization in COMPUTATION ACCELERATION cluster*/ + +#define COMP_ACC_CLUSTER \ + g_instance.attr.attr_sql.enable_acceleration_cluster_wlm /*COMPUTATION ACCELERATION cluster flag*/ + +typedef struct ServerDynamicManager { + int totalsize; /* total memory size for server */ + int freesize; /* free size for server */ + int freesize_inc; /* free memory increment between booking and DNs */ + int freesize_update; /* freesize is updated */ + int freesize_limit; + int rp_memsize; /* memory size occupied on resource pool */ + int active_count; /* COMPUTATION ACCELERATION cluster: active statement count */ + int statement_quota; /* COMPUTATION ACCELERATION cluster*/ + bool recover; /* recovering mode */ + bool try_wakeup; /* are waking up some requests*/ + + char* group_name; /* group name */ + + List* global_waiting_list; /* the queue complicate statements is waiting for waking up */ + HTAB* global_info_hashtbl; /* resource pool is stored in this hash table*/ + + ClientDynamicManager* climgr; /* client manager of the current server */ + + pthread_mutex_t global_list_mutex; /* a mutex to lock statements waiting list */ +} ServerDynamicManager; + +struct DynamicNodeData { + char host[NAMEDATALEN]; /* node host */ + Oid* group_members; /* group members of one node group */ + int group_count; /* group count of one node group */ + int used_memory; /* node used memory */ + int total_memory; /* node total memory */ + int estimate_memory; /* node estimate memory */ + + int phy_totalmem; /* physical total memory */ + int phy_freemem; /* physical free memory */ + int phy_usemem_rate; /* physical memory use rate */ + + int fp_memsize; /* setting memory for foreign users */ + int fp_usedsize; /* memory used for foreign users */ + int fp_estmsize; /* memory used for foreign users */ + int fp_mempct; /* memory used for foreign users */ + + int cpu_util; /* max physical cpu util of all nodes */ + int cpu_count; /* max physical cpu count of all nodes */ + int io_util; /* max io count of all nodes */ + + int min_freesize; /* minimum free size of nodes */ + + int min_memutil; /* minimum memory usage rate */ + int max_memutil; /* maximum memory usage rate */ + int min_cpuutil; /* minimum cpu usage rate */ + int max_cpuutil; /* maximum cpu usage rate */ + int min_ioutil; /* minimum io usage rate */ + int max_ioutil; /* maximum io usage rate */ + + HTAB* nodedata_htab; /* node data hash table */ +}; + +extern Oid dywlm_get_node_id(Oid procid); +extern void dywlm_server_receive(StringInfo msg); + +extern EnqueueType dywlm_server_reserve(ServerDynamicManager*, DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_release(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_cancel(ServerDynamicManager*, DynamicMessageInfo* msginfo); +extern void dywlm_server_clean(const char* nodename); +extern EnqueueType dywlm_server_clean_internal(ServerDynamicManager*, const char* nodename); +extern EnqueueType dywlm_server_move_node_to_list(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_jump_queue(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern void dywlm_node_recover(bool isForce); +extern DynamicWorkloadRecord* dywlm_server_get_records(ServerDynamicManager*, const char* nodename, int* num); +extern void dywlm_server_collector(void); +extern void dywlm_server_sync_records(void); +extern DynamicNodeData* dywlm_get_resource_info(ServerDynamicManager* srvmgr); +extern void dywlm_server_check_resource_pool(void); +extern void dywlm_server_get_respool_params(const char* rpname, int* running_count, int* waiting_count); + +extern void dywlm_server_display_srvmgr_info(StringInfo strinfo); +extern void dywlm_server_display_respool_info(StringInfo strinfo); +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/gscgroup.h postgresql-hll-2.14/include/include/workload/gscgroup.h --- postgresql-hll-2.14_old/include/include/workload/gscgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/gscgroup.h 2020-12-12 17:06:43.305348787 +0800 @@ -0,0 +1,482 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gscgroup.h + * header file to export the functions to use cgroup + * + * IDENTIFICATION + * src/include/workload/gscgroup.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_CGROUPS__ +#define __GS_CGROUPS__ + +#ifndef gettid + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include + +#include "c.h" +#include "gs_threadlocal.h" + +#include "datatype/timestamp.h" + +#define gettid() (pid_t) syscall(__NR_gettid) + +#endif + +#include "securec.h" +#include "securec_check.h" + +#define securec_check_berrno(errno, express, retval) \ + { \ + if (errno != EOK) { \ + express; \ + return retval; \ + } \ + } + +#define check_errno(errno, express, retval, file, line) \ + { \ + if (EOK != errno) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_errno(errno, express, retval) check_errno(errno, express, retval, __FILE__, __LINE__) + +#define check_intval(errno, express, retval, file, line) \ + { \ + if (errno == -1) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_intval(val, express, retval) check_intval(val, express, retval, __FILE__, __LINE__) + +/* + * Cgroups is divided into 4 purposes: + * Backend Cgroup: used to control the backend threads + * Class Cgroup: used to specify the resource percentage for classes + * DefaultWD Cgroup: used to control the default workload threads + * Timeshare Cgroup: used to control the timeshare threads + * + * Usually, Gaussdb cgroup has 80% dynamic resource of the whole system, + * but it can't beyond the 95% hard limitation. + * + * The resource Ratio for Class and Backend will be 1:2 as default. + * + * Each class can be assigned the specified resource percentage from + * Class cgroup based on requirement. + * + * Under each class cgroup, the default workload cgroup can be assigned the + * specified resource percentage; and its maximum level will be 5 as default. + * + * Each Class cgroup has the timeshare cgroups; + * The resource for timeshare is the remained resource of the class; + * So it must make sure that all resource for default workload is not the total of user. + * + * The logic graph of cgroup is deployed. + * a. /dev/cgroups is the mount point of cgroups + * b. Gaussdb is the top cgroup of Gauss Database + * c. Backend is the cgroup of backend threads + * e. Class is the top cgroup of users' query threads + * f. The name rule for default workload cgroups should be made up with "name:level" + * h. The default Class and default workload cgroup are provided + * i. At most, there are 6 levels for each user (4 levels for defaultwd and 2 level for timeshare) + * j. There are only 2 cgroups for default workload in each level + * f. Rush/High/Medium/Low is the timeshare cgroup in the bottom line of each tree path + + + /dev/cgroups/ ------- mount point + | + tasks (non-gaussdb threads) Gaussdb/ ------- database topdir + | + Backend/ tasks(no threads) Class/ ------- top class dir + | | + Vacuum/ ... tasks(backend threads) DefaultClass/ Class1/ ... --- class dir + | | + tasks(vacuum thread) DefaultWD:1/ RemainWD:1/ tasks(no threads) --- defaultwd dir (Level 1) + | | + tasks (query) DefaultWD:2/ RemainWD:2/ tasks(no threads) --- defaultwd dir (Level 2) + | + Timeshare:3/ tasks(no threads) --- top timeshare dir (Level 3) + | + Rush:4/ High:4/ Medium:4/ Low:4/ tasks(no threads) --- timeshare dir (Level 4) + | + tasks(query threads) + + + * Default values: + * 0. The top level cgroup number is 4: mountpoint, Gaussdb, Backend and Class; + * 1. The maximum number for backend cgroup is 16; + * 2. The maximum number for class cgroup is 64; + * 3. The maximum number for defaultwd and timeshare cgroup is 256 (64 * 4 = all timeshare cgroups); + * If user want to create one defaultwd cgroup, but there is no slot, it will fail. + * 4. + */ + +#define MOUNT_SUBSYS_KINDS 5 +#define MOUNT_CPU_ID 0 +#define MOUNT_CPUACCT_ID 1 /* cpu and cpuacct could not be separated */ +#define MOUNT_BLKIO_ID 2 +#define MOUNT_CPUSET_ID 3 +#define MOUNT_MEMORY_ID 4 + +#define MOUNT_CPU_NAME "cpu" +#define MOUNT_BLKIO_NAME "blkio" +#define MOUNT_CPUSET_NAME "cpuset" +#define MOUNT_CPUACCT_NAME "cpuacct" +#define MOUNT_MEMORY_NAME "memory" + +#define GSCGROUP_CONF_DIR "etc" +#define GSCFG_BACKUP ".bak" + +#define GSCGROUP_MOUNT_POINT "/sys/fs/cgroup" +#define GSCGROUP_MOUNT_POINT_OLD "/dev/cgroups" + +#define GSCGROUP_ROOT "Root" +#define GSCGROUP_TOP_DATABASE "Gaussdb" +#define GSCGROUP_CM "CM" +#define GSCGROUP_TOP_BACKEND "Backend" +#define GSCGROUP_TOP_CLASS "Class" +#define GSCGROUP_DEFAULT_CLASS "DefaultClass" +#define GSCGROUP_REMAIN_WORKLOAD "RemainWD" +#define GSCGROUP_TOP_TIMESHARE "Timeshare" +#define GSCGROUP_RUSH_TIMESHARE "Rush" +#define GSCGROUP_HIGH_TIMESHARE "High" +#define GSCGROUP_MEDIUM_TIMESHARE "Medium" +#define GSCGROUP_LOW_TIMESHARE "Low" +#define GSCGROUP_DEFAULT_BACKEND "DefaultBackend" +#define GSCGROUP_VACUUM "Vacuum" +#define GSCGROUP_TOP_WORKLOAD "TopWD" +#define GSCGROUP_INVALID_GROUP "InvalidGroup" + +#define GSCGROUP_DEFAULT_CGNAME GSCGROUP_MEDIUM_TIMESHARE + +#define GSCGROUP_TOPNUM 4 /* 4 groups for top cgroups */ +#define GSCGROUP_BAKNUM 16 /* 16 groups for backend threads */ +#define GSCGROUP_CLASSNUM 64 /* 64 groups for classes */ +#define GSCGROUP_WDNUM_OLD 256 /* 256 groups for default workload threads */ +#define GSCGROUP_WDNUM 640 /* 640 groups for default workload threads */ +#define GSCGROUP_TSNUM 4 /* 4 groups for timeshare workload threads */ +#define GSCGROUP_ALLNUM_OLD \ + (GSCGROUP_TOPNUM + GSCGROUP_BAKNUM + GSCGROUP_CLASSNUM + GSCGROUP_WDNUM_OLD + GSCGROUP_TSNUM) +#define GSCGROUP_ALLNUM (GSCGROUP_TOPNUM + GSCGROUP_BAKNUM + GSCGROUP_CLASSNUM + GSCGROUP_WDNUM + GSCGROUP_TSNUM) + +/* Timeshare Rate Value */ +#define TS_RUSH_RATE 8 /* the rate of rush timeshare group */ +#define TS_HIGH_RATE 4 /* the rate of high timeshare group */ +#define TS_MEDIUM_RATE 2 /* the rate of medium timeshare group */ +#define TS_LOW_RATE 1 /* the rate of low timeshare group */ +#define TS_ALL_RATE (TS_RUSH_RATE + TS_HIGH_RATE + TS_MEDIUM_RATE + TS_LOW_RATE) + +#define TOPCG_START_ID 0 +#define TOPCG_ROOT 0 +#define TOPCG_GAUSSDB 1 +#define TOPCG_BACKEND 2 +#define TOPCG_CLASS 3 +#define TOPCG_END_ID (GSCGROUP_TOPNUM - 1) /*3*/ + +#define BACKENDCG_START_ID (TOPCG_END_ID + 1) /*4*/ +#define BACKENDCG_END_ID (BACKENDCG_START_ID + GSCGROUP_BAKNUM - 1) /*19*/ + +#define CLASSCG_START_ID (BACKENDCG_END_ID + 1) /*20*/ +#define CLASSCG_END_ID (CLASSCG_START_ID + GSCGROUP_CLASSNUM - 1) /*83*/ + +#define WDCG_START_ID (CLASSCG_END_ID + 1) /*84*/ +#define WDCG_END_ID_OLD (WDCG_START_ID + GSCGROUP_WDNUM_OLD - 1) /*84+255*/ +#define WDCG_END_ID (WDCG_START_ID + GSCGROUP_WDNUM - 1) /*84+640-1*/ + +#define TSCG_START_ID_OLD (WDCG_END_ID_OLD + 1) +#define TSCG_START_ID (WDCG_END_ID + 1) +#define TSCG_END_ID (TSCG_START_ID + GSCGROUP_TSNUM - 1) + +#define DEFAULT_CPU_SHARES 1024 +#define DEFAULT_GAUSS_CPUSHARES 5120 /* about 5x non-database resource */ +#define DEFAULT_CM_CPUSHARES 8192 /* about 8x non-database resource */ +#define MAX_CLASS_CPUSHARES 10000 /* for easy calculation */ + +#define TOP_BACKEND_PERCENT 40 /* 40% percentage of gaussdb resource */ +#define TOP_CLASS_PERCENT (100 - TOP_BACKEND_PERCENT) /* 60% percentage of gaussdb resource */ + +#define DEFAULT_BACKEND_PERCENT 80 /* 80% percentage of top backend resource */ +#define VACUUM_PERCENT 20 /* 20% percentage of top backend resource */ +#define DEFAULT_CLASS_PERCENT 20 /* 20% percentage of top class resource */ +#define OTHER_CLASS_PERCENT (100 - DEFAULT_CLASS_PERCENT) /* 60% percentage of other class resource */ +#define DEFAULT_WORKLOAD_PERCENT 20 /* 20% percentage of default class resource */ +#define TOPWD_PERCENT 90 /* 90% percentage of Class used for top wd */ + +#define DEFAULT_CPU_PERIOD 100000 +#define DEFAULT_IO_WEIGHT 500 +#define MIN_IO_WEIGHT 100 +#define MAX_IO_WEIGHT 1000 + +#define GROUP_ALL_PERCENT 100 +#define TOPWD_PERCENT 90 +#define NORMALWD_PERCENT 10 + +#define DEFAULT_CPUSKEWPCT 30 +#define DEFAULT_QUALITIME 1800 + +/* gscgroup.cfg saves the cgroups information and is placed under etc directory */ +#define GSCFG_PREFIX "gscgroup" +#define GSCFG_SUFFIX ".cfg" + +#define WD_TOP_LEVEL 1 +#define MAX_WD_LEVEL 10 +#define GPNAME_LEN 64 /* name:level */ +#define IODATA_LEN 96 /* support about 6 ~ 8 disk devices */ +#define EXCEPT_LEN 256 +#define USERNAME_LEN 56 /* 64 - sizeof("Gaussdb:") */ +#define GPNAME_PATH_LEN (GPNAME_LEN * (MAX_WD_LEVEL + 1)) +#define PROCLINE_LEN 4096 +#define CPUSET_OLD_LEN 8 +#define CPUSET_LEN 64 +#define SUBSYS_LEN 8 + +#define NANOSECS_PER_SEC ((int64)(1000000000)) + +#define IO_WEIGHT_CALC(weight, percent) \ + ((weight * (percent) / 100) > MIN_IO_WEIGHT ? (weight * (percent) / 100) : MIN_IO_WEIGHT) + +#define CPU_SHARES "cpu.shares" +#define CPU_QUOTA "cpu.cfs_quota_us" +#define CPU_PERIOD "cpu.cfs_period_us" +#define BLKIO_WEIGHT "blkio.weight" +#define BLKIO_BPSREAD "blkio.throttle.read_bps_device" +#define BLKIO_IOPSREAD "blkio.throttle.read_iops_device" +#define BLKIO_BPSWRITE "blkio.throttle.write_bps_device" +#define BLKIO_IOPSWRITE "blkio.throttle.write_iops_device" +#define CPUSET_CPUS "cpuset.cpus" +#define CPUSET_MEMS "cpuset.mems" +#define CPUACCT_USAGE "cpuacct.usage" + +#define EXCEPT_ALL_KINDS 2 + +#define EXCEPT_ERROR -2 +#define EXCEPT_NONE -1 +#define EXCEPT_ABORT 0 +#define EXCEPT_PENALTY 1 + +#define EXCEPT_FLAG(eflag) ((eflag) + 1) +#define IS_EXCEPT_FLAG(eflag, except) ((eflag) == EXCEPT_FLAG((except))) + +#define CGroupIsValid(group) (NULL != (void*)group && *group && strcmp(group, GSCGROUP_INVALID_GROUP) != 0) +#define CGroupIsDefault(group) (NULL != (void*)group && *group && strcmp(group, "DefaultClass:Medium") == 0) + +#define V1R5_VERSION 1 /* used for upgrade from v1r5 */ +#define V1R6_VERSION 2 /* used for upgrade from v1r6 */ + +/* + * get the cpuset start value + * astart: the upper level cpu core start value + * aend: the upper level cpu core end value + * bsum: the sum of cpu cores except the current updating group + * bmax: the max cpu core of the same level other groups + * blen: the length of the cpu cores of the current updating group + */ +#define GET_CPUSET_START_VALUE(astart, aend, bsum, bmax, blen) \ + (((bsum) + (blen) <= (aend) - (astart) + 1) \ + ? (((aend) - (bmax) >= (blen)) ? (((bsum) > 0) ? ((bmax) + 1) : (astart)) : ((astart) + (bsum))) \ + : ((aend) - (blen) + 1)) + +/* type of all cgroups */ +typedef enum { + GROUP_NONE, + GROUP_TOP, /* the top cgroup */ + GROUP_CLASS, /* the class cgroup with the given resource, + not to control any threads */ + GROUP_BAKWD, /* the cgroup to control the backend threads */ + GROUP_DEFWD, /* the default workload cgroup for each class, + to control the query threads in the given level */ + GROUP_TSWD /* the timeshare group for each user, + to control the query threads in the bottom level */ +} group_type; + +/* type of resource allocation */ +typedef enum { + ALLOC_DYNAMIC, /* the dynamic allocation method */ + ALLOC_FIXED /* the fixed allocation method */ +} alloc_type; + +typedef struct { + int shares; /* the value of cpu.shares */ + int weight; /* the value of blkio.weight */ + int quota; /* the percentage of cpuset. */ + char iopsread[IODATA_LEN]; /* the value of blkio.throttle.read_iops_device */ + char iopswrite[IODATA_LEN]; /* the value of blkio.throttle.write_iops_device */ + char bpsread[IODATA_LEN]; /* the value of blkio.throttle.read_bps_device */ + char bpswrite[IODATA_LEN]; /* the value of blkio.throttle.write_bps_device */ +} alloc_old_info_t; + +typedef struct { + int shares; /* the value of cpu.shares */ + int weight; /* the value of blkio.weight */ + int quota; /* the percentage of cpuset. */ + int spare; /* not used */ + char iopsread[IODATA_LEN]; /* the value of blkio.throttle.read_iops_device */ + char iopswrite[IODATA_LEN]; /* the value of blkio.throttle.write_iops_device */ + char bpsread[IODATA_LEN]; /* the value of blkio.throttle.read_bps_device */ + char bpswrite[IODATA_LEN]; /* the value of blkio.throttle.write_bps_device */ +} alloc_info_t; + +typedef struct { + int percent; /* the percent value in gaussdb */ +} gscgroup_top_t; + +typedef struct { + int tgid; /* top gid */ + int maxlevel; /* the maxlevel of defaultwd cgroup */ + int percent; /* the percentage value in top class */ + int rempct; /* the remain percentage for workload */ +} gscgroup_class_t; + +typedef struct { + int cgid; /* class gid */ + int wdlevel; /* the level of the defaultwd cgroup */ + int percent; /* the percentage value in parent class */ +} gscgroup_wd_t; + +typedef struct { + int cgid; /* class gid */ + int rate; /* the rate based on the default value */ +} gscgroup_ts_t; + +typedef union { + gscgroup_top_t top; /* top group special information */ + gscgroup_class_t cls; /* class group special information */ + gscgroup_wd_t wd; /* defaultwd group special information */ + gscgroup_ts_t ts; /* timeshare group special information */ +} group_info_t; + +/* the throttle value for exception verification */ +typedef struct { + unsigned int blocktime; /* the start time - the submit time of query */ + unsigned int elapsedtime; /* the end time - the start time */ + unsigned int allcputime; /* the CPU time of all the node */ + unsigned int qualitime; /* the qualification time of all the node */ + unsigned int skewpercent; /* the CPU skew percent is the cuptime/allcputime */ + unsigned int spare[5]; /* not used */ +} except_old_data_t; + +/* the throttle value for exception verification */ +typedef struct { + unsigned int blocktime; /* the start time - the submit time of query */ + unsigned int elapsedtime; /* the end time - the start time */ + unsigned int allcputime; /* the CPU time of all the node */ + unsigned int qualitime; /* the qualification time of all the node */ + unsigned int skewpercent; /* the CPU skew percent is the cuptime/allcputime */ + unsigned int reserved; /* reserved flag */ + int64 spoolsize; /* spill size, unit is MB*/ + int64 broadcastsize; /* broadcast size, unit is MB*/ + unsigned int spare[14]; /* not used */ +} except_data_t; + +/* old version group information */ +typedef struct { + unsigned short used; /* flag if this group has been used */ + unsigned short gid; /* the group id */ + group_type gtype; /* top, backend, class, defaultwd or timeshare */ + group_info_t ginfo; /* group special information */ + unsigned short percent; /* the percentage value calculated by dynamic or fixed value */ + char grpname[GPNAME_LEN]; /* the cgroup name */ + alloc_old_info_t ainfo; /* resource alloc information */ + except_old_data_t except[EXCEPT_ALL_KINDS]; /* the exception data for aborting */ + char cpuset[CPUSET_OLD_LEN]; /* cpuset info */ + int spare[3]; /* not used */ +} gscgroup_old_grp_t; + +/* group information */ +typedef struct { + unsigned short used; /* flag if this group has been used */ + unsigned short gid; /* the group id */ + group_type gtype; /* top, backend, class, defaultwd or timeshare */ + group_info_t ginfo; /* group special information */ + char grpname[GPNAME_LEN]; /* the cgroup name */ + alloc_info_t ainfo; /* resource alloc information */ + except_data_t except[EXCEPT_ALL_KINDS]; /* the exception data for aborting */ + char cpuset[CPUSET_LEN]; /* cpuset info */ + unsigned int percent; /* the percentage value calculated by dynamic or fixed value */ + int spare[63]; /* not used , total size is 1024 bytes */ +} gscgroup_grp_t; + +typedef struct { + char name[GPNAME_LEN]; /* classname:workloadname */ + int percent; /* percent of the group */ + int cpuUtil; /* percent of the cpu usage */ + int cpuCount; /* the count of the cpu cores */ + int usedCpuCount; /* used cpu cores */ + int64 cpuUsedAcct; /* cpu usage value */ + int64 cpuLastAcct; /* last cpu value */ + TimestampTz lastTime; /* last collect time */ + struct cgroup* cg; /* cgroup structure */ + struct cgroup* oldcg; /* old cgroup structure */ +} gscgroup_entry_t; + +typedef struct { + gscgroup_entry_t entry; /* cgroup entry */ + char relpath[GPNAME_PATH_LEN]; /* relative path */ + char cpuset[CPUSET_LEN]; /* cpu set */ + char nodegroup[GPNAME_LEN]; /* node group name */ + int shares; /* cpu shares */ + bool valid; /* cgroup is valid or not */ +} gscgroup_info_t; + +typedef enum { GSCGROUP_NONE_STMT = 0, GSCGROUP_NORMAL_STMT, GSCGROUP_TOP_STMT, GSCGROUP_VACUUM_STMT } gscgroup_stmt_t; + +/* get the file size */ +extern long gsutil_filesize(const char* fname); + +/* return mapping address */ +extern void* gsutil_filemap(const char* fname, size_t nbytes, int prot, int flags, struct passwd* passwd_user); + +/* get the parent path of workload group */ +extern char* gscgroup_get_parent_wdcg_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); + +/* get the top timeshare path of class group */ +extern char* gscgroup_get_topts_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); +/* get the relative path of any specified group */ +extern char* gscgroup_get_relative_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); +/* print exception flag */ +extern char* gsutil_print_exception_flag(int eflag); + +/* check the exception whether is valid */ +extern int gsutil_exception_is_valid(gscgroup_grp_t* grp, int kinds); + +/* check the exception kiind whether is valid */ +extern int gsutil_exception_kind_is_valid(gscgroup_grp_t* grp, int kind); + +/* get the cpu count */ +extern int gsutil_get_cpu_count(); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/ioschdl.h postgresql-hll-2.14/include/include/workload/ioschdl.h --- postgresql-hll-2.14_old/include/include/workload/ioschdl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/ioschdl.h 2020-12-12 17:06:43.305348787 +0800 @@ -0,0 +1,182 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ioschdl.h + * definitions for IO control parameters + * + * IDENTIFICATION + * src/include/workload/ioschdl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef IOSCHDL_H +#define IOSCHDL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +/* IO types */ +#define IO_TYPE_WRITE 0 // IO type write +#define IO_TYPE_READ 1 // IO type read +#define IO_TYPE_COLUMN 0 // IO type for column +#define IO_TYPE_ROW 1 // IO type for row + +/* iostat */ +#define MAX_DEVICE_DIR 256 +#define UTIL_COUNT_LEN 3 + +/* util threshold */ +#define UTIL_HIGH_THRESHOLD 50 +#define UTIL_LOW_THRESHOLD 30 + +/* util state */ +#define UTIL_LOW 0 +#define UTIL_MEDIUM 1 +#define UTIL_HIGH 2 + +#define FETCH_IOSTAT 0 +#define RESET_IOSTAT 1 + +#define IO_MIN_COST 50000 + +#define IOCONTROL_UNIT 6000 + +// write take 30% +#define W_RATIO_THRESHOLD 30 +// iops cannot be lower than 5 +#define IOPS_LOW_LIMIT 5 + +#define FULL_PERCENT 100 + +#define IOPRIORITY_NONE 0 +#define IOPRIORITY_LOW 10 +#define IOPRIORITY_MEDIUM 20 +#define IOPRIORITY_HIGH 50 + +#define WLM_AUTOWAKE_INTERVAL 1 + +#define IOLIMIT_WAKE_TIME 1 +#define CPUSTAT_WAKE_TIME 8 + +#define IOPRIORITY_LOW_WAKE_TIME 3 +#define IOPRIORITY_MEDIUM_WAKE_TIME 2 +#define IOPRIORITY_HIGH_WAKE_TIME 1 + +#define FILE_DISKSTAT "/proc/diskstats" +#define FILE_CPUSTAT "/proc/stat" +#define FILE_MOUNTS "/proc/mounts" + +#define AVERAGE_DISK_VALUE(m, n, p, u) (((double)((n) - (m))) / (p)*u) + +typedef struct IORequestEntry { + int amount; // IO amount + int rqst_type; // IO type + int count; // iocount + + int count_down; // count of time wlmmonitor thread is wakened + pthread_cond_t io_proceed_cond; +} IORequestEntry; + +struct blkio_info { + int used; + uint64 rd_ios; /* Read I/O operations */ + uint64 wr_ios; /* Write I/O operations */ + uint64 rd_sectors; /* Sectors read */ + uint64 wr_sectors; /* Sectors written */ + uint64 tot_ticks; /* Time of requests in queue */ +}; + +typedef struct WLMmonitor_iostat { + // updated on DN + char device[MAX_DEVICE_DIR]; /* device name */ + + // iostat + double rs; /* r/s */ + double ws; /* w/s */ + double util; /* %util */ + double w_ratio; /* write proportion */ + + // cpu util + double cpu_util; + int cpu_util_count; + int cpu_count; + + // for io scheduler + unsigned char device_util_tbl[UTIL_COUNT_LEN]; /* whether it is below the threshold*/ + int total_tbl_util; + int tick_count; + + // updated on CN + int maxIOUtil; + int minIOUtil; + int maxCpuUtil; + int minCpuUtil; + + int node_count; /* count of DN */ +} WLMmonitor_iostat; + +typedef struct WLMIOContext { + /* waiting list and mutex */ + List* waiting_list; + pthread_mutex_t waiting_list_mutex; + + /* cpu cores */ + int cpu_nr; + + /* + * cpu total time calculated from /proc/stat, + * the first element stores the last one, + * and the second stores the current + */ + uint64 uptime[2]; + /* cpu0 total calculated from /proc/stat */ + uint64 uptime0[2]; + /* cpu user time */ + uint64 cputime_user[2]; + + /* timestamp of the previous and the current */ + TimestampTz prev_timestamp; + TimestampTz cur_timestamp; + + /* hz per second */ + uint32 hz; + + /* blockio info, got from /proc/diskstats */ + struct blkio_info new_blkio; + struct blkio_info old_blkio; + + /* device iostat */ + WLMmonitor_iostat WLMmonitorDeviceStat; + + /* device init */ + bool device_init; +} WLMIOContext; + +extern void IOStatistics(int type, int count, int size); +extern void IOSchedulerAndUpdate(int type, int count, int store_type); +extern void WLMmonitor_check_and_update_IOCost(PlannerInfo* root, NodeTag node, Cost IOcost); + +/* monitoring thread use */ +extern ThreadId StartWLMmonitor(void); + +/* arbiter thread use */ +extern ThreadId StartWLMarbiter(void); + +#ifdef EXEC_BACKEND +extern void WLMmonitorMain(); +extern void WLMarbiterMain(); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/memctl.h postgresql-hll-2.14/include/include/workload/memctl.h --- postgresql-hll-2.14_old/include/include/workload/memctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/memctl.h 2020-12-12 17:06:43.305348787 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memctl.h + * Routines related to memory quota for queries. + * + * IDENTIFICATION + * src/include/workload/memctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MEMCTL_H_ +#define MEMCTL_H_ + +/* + * during mem decrease procedure, we want to assign decreased mem to large mem, + * so just through the mem gap, and after decrease, large item should be at least 20% + * large than the small one + */ +#define DECREASED_MIN_CMP_GAP 0.1 + +/* Memory usage larger than 4GB is incredible */ +#define MAX_OP_MEM 4 * 1024L * 1024L + +/* min memory allocate for memory intensive operator for sake of huge initial mem allocation */ +#define MIN_OP_MEM 16 * 1024L + +extern void CalculateQueryMemMain(PlannedStmt* stmt, bool use_tenant, bool called_by_wlm); + +extern bool QueryNeedPlanB(PlannedStmt* stmt); +extern void ReSetNgQueryMem(PlannedStmt* result); +extern THR_LOCAL Oid lc_replan_nodegroup; + +#endif /* MEMQUOTA_H_ */ diff -uprN postgresql-hll-2.14_old/include/include/workload/parctl.h postgresql-hll-2.14/include/include/workload/parctl.h --- postgresql-hll-2.14_old/include/include/workload/parctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/parctl.h 2020-12-12 17:06:43.305348787 +0800 @@ -0,0 +1,164 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * parctl.h + * definitions for parallel control functions + * + * IDENTIFICATION + * src/include/workload/parctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARCTLS_H +#define PARCTLS_H +#define MAX_PARCTL_MEMORY ((unsigned int)maxChunksPerProcess << (chunkSizeInBits - BITS_IN_MB)) +/*the process memory while query running */ +#define PARCTL_PROCESS_MEMORY 32 /* MB */ + +/*the memory size of a query to start to do parallel control*/ +#define PARCTL_MEMORY_UNIT 3 /* MB */ + +#define PARCTL_ACTIVE_PERCENT 80 +#define PARCTL_ALL_PERCENT 100 + +typedef enum ParctlType { + PARCTL_NONE = 0, /* no parallel control */ + PARCTL_RESERVE, /* reserve resource request */ + PARCTL_GLOBAL, /* global parallel control */ + PARCTL_RESPOOL, /* resource pool parallel control */ + PARCTL_ACTIVE, /* query is running */ + PARCTL_RELEASE, /* release resource request */ + PARCTL_CANCEL, /* cancel query request */ + PARCTL_CLEAN, /* client recover request */ + PARCTL_SYNC, /* server recover request */ + PARCTL_TRANSACT, /* query is in the transaction block */ + PARCTL_MVNODE, /* move statement to new priority */ + PARCTL_JPQUEUE, /* move statement to highest priority */ + PARCTL_TYPES, /* count of types for parallel control, it's always the last one */ +} ParctlType; + +typedef enum EnqueueType { + ENQUEUE_NONE = 0, /* default state */ + ENQUEUE_BLOCK, /* query should be blocked */ + ENQUEUE_ERROR, /* query is in error state */ + ENQUEUE_NORESPOOL, /* target resource pool is not exist */ + ENQUEUE_MEMERR, /* query is in error state due to out of memory */ + ENQUEUE_RECOVERY, /* server is in recover state */ + ENQUEUE_CONNERR, /* connect to target node failed */ + ENQUEUE_PRIVILEGE, /* has privilege to run */ + ENQUEUE_GROUPERR, /* node group error */ + ENQUEUE_UNKNOWN /* parctl type is not valid, unknown to handle it */ +} EnqueueType; + +typedef struct RespoolData { + Oid rpoid; /* resource pool oid*/ + int max_pts; /* active statements for the resource pool */ + int max_stmt_simple; /* max statements for the resource pool for simple queries */ + int max_dop; /* max dop */ + int mem_size; /* memory pool size, kb */ + int act_pts; /* active statement points */ + int max_act_pts; /* active statement points */ + int min_act_pts; /* active statement points */ + int iops_limits; /* iops limits */ + int io_priority; /* io priority */ + bool superuser; /* Am I super user? */ + bool cgchange; /* check cgroup whether is changed */ + char rpname[NAMEDATALEN]; + char* cgroup; /* control group in resource pool */ +} RespoolData; + +/* used for BuildResourcePoolHash function, avoid dead lock */ +typedef struct TmpResourcePool +{ + Oid rpoid; /* resource pool id */ + Oid parentoid; /* resource pool id */ + int32 iops_limits; /* iops limit for each resource pool */ + int io_priority; /* io_percent for each resource pool */ + int mempct; /* setting percent */ + bool is_foreign; /* indicate that the resource pool is used for foreign users */ + + char cgroup[NAMEDATALEN]; /* cgroup information */ + char ngroup[NAMEDATALEN]; /* nodegroup information */ +} TmpResourcePool; + +typedef struct ParctlManager { + int max_active_statements; /* global max active statements */ + int statements_waiting_count; /* count of statements in waiting */ + int statements_runtime_count; /* count of statements in running */ + int statements_runtime_plus; /* increased of statements in running */ + int max_statements; /* max statements in active */ + int max_support_statements; /* max supported statements */ + int current_support_statements; /* current supported statements */ + int respool_waiting_count; /* count of statements waiting in resource pool */ + + List* statements_waiting_list; /* the queue complicate statements is waiting for waking up */ + + HTAB* resource_pool_hashtbl; /* resource pool is stored in this hash table*/ + + pthread_mutex_t statements_list_mutex; /* a mutex to lock statements waiting list */ +} ParctlManager; + +typedef struct WLMListNode { + int data; /* The priority of the node */ + List* request_list; /* list for statements with this priority in waiting */ + + bool equals(const int* data) + { + return this->data == *data; + } + + int compare(const int* data) + { + if (this->data == *data) + return 0; + + return ((this->data < *data) ? 1 : -1); + } +} WLMListNode; + +extern bool IsQueuedSubquery(void); +extern void WLMParctlReady(const char*); +/*Reserve workload resource*/ +extern void WLMParctlReserve(ParctlType); +/*Release workload resource*/ +extern void WLMParctlRelease(ParctlState*); +/*Handle simple stmt except for dywlm*/ +extern void WLMHandleDywlmSimpleExcept(bool proc_exit); +/*Initialize workload group hash table*/ +extern void InitializeUserResourcePoolHashTable(); +/* Switch node in the waiting list from old priority to new priority */ +extern void WLMSwitchQNodeList(ParctlManager*, int priority_old, int priority_new); +extern void WLMCreateResourcePoolInHash(Oid); +extern bool WLMCheckResourcePoolIsIdle(Oid); + +extern int WLMJumpQueue(ParctlManager*, ThreadId); +extern void WLMSetMaxStatements(int); +extern int WLMGetActiveStatments(); +/* get resource pool data info from hash table */ +extern void* WLMGetResourcePoolDataInfo(int* num); +extern ListCell* WLMSearchAndCheckMaxNode(const List* list); + +extern int WLMGetMaxDop(); +extern void WLMVerifyGlobalParallelControl(ParctlManager*); +extern int WLMGetMaxStatements(int active_statements); +extern void WLMCheckResourcePool(); + +extern void WLMProcReleaseActiveStatement(void); + +extern int WLMReleaseGroupActiveStatement(void); +void WLMCheckDefaultXactReadOnly(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/qnode.h postgresql-hll-2.14/include/include/workload/qnode.h --- postgresql-hll-2.14_old/include/include/workload/qnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/qnode.h 2020-12-12 17:06:43.305348787 +0800 @@ -0,0 +1,76 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * qnode.h + * definitions for query node information in workload manager + * + * IDENTIFICATION + * src/include/workload/qnode.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef QNODE_H +#define QNODE_H + +typedef struct ResourcePool { + Oid rpoid; /* resource pool id */ + Oid parentoid; /* resource pool id */ + int ref_count; /* ref count of the resource pool */ + int active_points; /* the count of active statements in the resource pool */ + int server_actpts; /* server active points */ + int running_count; /* the count of running statements */ + int waiting_count; /* the count of waiting statements */ + int running_count_simple; /* the count of running statements for simple queries */ + int32 iops_limits; /* iops limit for each resource pool */ + int io_priority; /* io_percent for each resource pool */ + int memsize; /* setting memory size */ + int memused; /* used memory size */ + int mempct; /* setting percent */ + int actpct; /* real percent */ + int peakmem; /* peak used memory size */ + int estmsize; /* estimated memory size */ + bool is_dirty; /* resource pool is dirty, it will be removed while it's dirty */ + bool reset; /* reset */ + bool is_foreign; /* indicate that the resource pool is used for foreign users */ + List* waiters; /* list for statements are waiting in resource pool */ + List* waiters_simple; /* list for statements are waiting in resource pool for simple queries */ + void* node_group; /* node group pointer */ + List* entry_list; /* Used to save the foreign query list on datanode */ + struct ResourcePool* foreignrp; /* foreign resource pool of one parent */ + struct ResourcePool* parentrp; /* foreign resource pool of one parent */ + + char cgroup[NAMEDATALEN]; /* cgroup information */ + char ngroup[NAMEDATALEN]; /* nodegroup information */ + + pthread_mutex_t mutex; /* mutex to lock workload group */ +} ResourcePool; + +typedef struct WLMQNodeInfo { +#ifndef WIN32 + pthread_cond_t condition; /* pthread condtion */ +#endif + Oid userid; /* The user id of the thread */ + bool removed; /* whether is removed from the waiting list */ + bool privilege; /* the query has privilege? */ + uint64 sessid; /* session id of current session */ + int priority; /* priority of the query */ + int max_pts; /* max pts for complicate or max stmt for simple */ + int act_pts; /* stmt active points */ + ListCell* lcnode; /* head of the queue */ + ResourcePool* rp; /* resource pool of the node */ +} WLMQNodeInfo; + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/statctl.h postgresql-hll-2.14/include/include/workload/statctl.h --- postgresql-hll-2.14_old/include/include/workload/statctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/statctl.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,796 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * statctl.h + * definitions for statistics control functions + * + * IDENTIFICATION + * src/include/workload/statctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STATCTL_H +#define STATCTL_H + +#include "workload/parctl.h" +#include "instruments/list.h" +#define StringIsValid(pstr) (pstr && *pstr) +#define SqlIsValid(sql) (StringIsValid(sql) && strcmp(sql, ";") != 0) + +#define KBYTES 1024 +#define MBYTES (KBYTES * KBYTES) + +#define MAX_SLEEP_TIME 5 /*seconds*/ + +#define STAT_PATH_LEN KBYTES +#define INFO_STR_LEN 94 +/* + * warning includes + * - 256 byte reserved for warnings from query-executor + * - 2kb reserved for warnings from query-optimizer + */ +#define WARNING_INFO_LEN 2304 + +#define WARNING_SPILL_SIZE 256 /* 256MB */ +#define WARNING_BROADCAST_SIZE 100 /* 100MB */ +#define WARNING_SPILL_TIME 3 +#define WARNING_HASH_CONFLICT_LEN 256 + +#define GSUSER_ALLNUM 102400 +#define PAST_TIME_COUNT 3 +#define SIG_RECVDATA_COUNT 16 +#define GSWLM_CONF_DIR "etc" +#define GSWLMCFG_PREFIX "gswlm" +#define GSCONF_NAME "userinfo" +#define MAX_DEVICE_LEN 64 +#define ALL_USER "0000" //"0000" is an invalid user name, means update all user used space + +#define AVERAGE_VALUE(m, n, p) (((n) > (m)) ? (((int)((n) - (m))) / (p)) : (0)) +#define GET_LARGER_VALUE(x, y) (((x) > (y)) ? (x) : (y)) +#define PEAK_VALUE(start, end, intval, cmp) (GET_LARGER_VALUE(AVERAGE_VALUE((start), (end), (intval)), (cmp))) + +/*get max and min data in the session info, min value maybe 0, so set -1 as init value*/ +#define GetMaxAndMinCollectInfo(info, elem, data) \ + do { \ + if (data > info->max##elem) \ + info->max##elem = data; \ + if (info->min##elem == -1) \ + info->min##elem = data; \ + else if (data < info->min##elem) \ + info->min##elem = data; \ + } while (0) + +#define WLM_USER_RESOURCE_HISTORY "gs_wlm_user_resource_history" +#define WLM_INSTANCE_HISTORY "gs_wlm_instance_history" +#define WLM_EC_OPERATOR_INFO "gs_wlm_ec_operator_info" +#define WLM_OPERATOR_INFO "gs_wlm_operator_info" +#define WLM_SESSION_INFO "gs_wlm_session_query_info_all" + +enum WLMActionTag { + WLM_ACTION_REMAIN = 0, /* keep thread running */ + WLM_ACTION_ADJUST, /* change control group of statement */ + WLM_ACTION_ABORT, /* abort the statement */ + WLM_ACTION_FINISHED, /* finish the statement */ + WLM_ACTION_FETCHSESS, /* fetch session info */ + WLM_ACTION_REMOVED /* info removed */ +}; + +enum WLMStatusTag { + WLM_STATUS_RESERVE = 0, /* a status before waiting in wlm queue */ + WLM_STATUS_PENDING, /* waiting in the wlm queue */ + WLM_STATUS_RUNNING, /* statement is running */ + WLM_STATUS_FINISHED, /* statement is finished */ + WLM_STATUS_ABORT, /* statement is abort */ + WLM_STATUS_RELEASE /* wlm collect infomation is into db list or release statistics ctrl*/ +}; + +enum WLMAttrTag { + WLM_ATTR_NORMAL = 0, /* Normal is not into db */ + WLM_ATTR_INDB, /* push collect infomation into db list */ + WLM_ATTR_INVALID /* collect info is invalid */ +}; + +enum WLMWarnTag { + WLM_WARN_NONE = 0, /* no warn */ + WLM_WARN_SPILL, + WLM_WARN_EARLY_SPILL, + WLM_WARN_SPILL_TIMES_LARGE, + WLM_WARN_SPILL_FILE_LARGE, + WLM_WARN_BROADCAST_LARGE, + WLM_WARN_SPILL_ON_MEMORY_SPREAD, + WLM_WARN_HASH_CONFLICT +}; + +enum WLMExceptTag { + WLM_EXCEPT_NONE = 0, + WLM_EXCEPT_CPU, + WLM_EXCEPT_SPOOL, + WLM_EXCEPT_QUEUE_TIMEOUT, + WLM_EXCEPT_RUN_TIMEOUT +}; + +struct Qid { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ +}; + +/* user info in the user config file */ +struct WLMUserInfo { + Oid userid; /* user id */ + Oid rpoid; /* resource pool id */ + Oid parentid; /* parent user id */ + int childcount; /* count of the child user */ + int64 space; /* user space */ + int64 spacelimit; /* user space limit */ + int used; /* user info is used */ + bool admin; /* user is admin user? */ + char* children; /* child list string */ +}; + +/* general params */ +struct WLMGeneralParam { + Qid qid; /* a tag of a query */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char ngroup[NAMEDATALEN]; /* node group name */ + unsigned char cpuctrl; /* under cpu control? */ + unsigned char memtrack; /* track memory ? */ + unsigned char iotrack; /* track IO? */ + unsigned char iocontrol; /* need control IO ?*/ + unsigned char infoinit; /* hash tab init */ + unsigned char iostate; /* workload io state*/ + unsigned char complicate; /* query is complicated */ + unsigned char complicate_stream; /* query is complicated & thread is stream */ + unsigned char privilege; /* flags reserved */ + RespoolData rpdata; /* resource pool in use */ + int memsize; /* statement memory size, mb */ + int max_memsize; /*max statement memory size */ + int min_memsize; /* min statement memory size */ + int dopvalue; /* current dop value */ + int iops_limits; /* iops_limits */ + int io_priority; /* io percentage transfered from io_priority */ + int iocount; /* io count */ + void* infoptr; /* a pointer to user info in configure file */ + void* ptr; /* a pointer in general param */ + void* ioptr; /* io info pointer */ + void* rp; /* resource pool */ + void* userdata; /* user data */ + bool use_planA; /* force use plan A*/ +}; + +template +struct WLMDataIndicator { + DataType min_value; + DataType max_value; + DataType total_value; + DataType avg_value; + int skew_percent; +}; + +/* collect user information from DN */ +struct WLMUserCollInfoDetail { + char nodeName[NAMEDATALEN]; /* node name */ + WLMDataIndicator usedMemoryData; /* used memory data */ + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ + int cpuUsedCnt; /* cpu core counts used */ + int cpuTotalCnt; /* cpu core counts used */ + int nodeCount; /* node count */ + int64 totalSpace; /* total used space */ + /* IO flow data */ + uint64 readBytes; /* current readKb for all DN */ + uint64 writeBytes; /* current writeKb for all DN */ + uint64 readCounts; /* current read counts for all DN */ + uint64 writeCounts; /* current write counts for all DN */ + + int64 tmpSpace; /* total used temp space*/ + int64 spillSpace; /* total used spill space*/ +}; + +/* collect realtime info detail */ +struct WLMCollectInfoDetail { + char nodeName[NAMEDATALEN]; /* node name */ + Oid* group_members; /* group members of one node group */ + int group_count; /* group count of one node group */ + + int usedMemory; /* memory used */ + int peakMemory; /* peak memory */ + int spillCount; /* count for spill */ + int warning; /* warning info */ + int nodeCount; /* node count */ + int maxUsedMemory; /* max used memory */ + int avgUsedMemory; /* average used memory */ + int cpuCnt; /* cpu core counts used */ + int64 dnTime; /* query used time on dn */ + uint64 space; /* table space used */ + int64 cpuTime; /* cpu time used */ + + int maxIOUtil; /* max IO util */ + int minIOUtil; /* min IO util */ + int maxCpuUtil; /* max CPU util */ + int minCpuUtil; /* min CPU util */ + + int peak_iops; /* peak iops */ + int curr_iops; /* current iops */ + + int64 spillSize; /* spill size*/ + int64 broadcastSize; /* broadcast size */ + + char misc[NAMEDATALEN]; +}; + +struct WLMGeneralInfo { + int64 totalCpuTime; /* total query cpu time on dn */ + int64 maxCpuTime; /* max query cpu time on dn */ + int64 minCpuTime; /* min query cpu time on dn */ + int64 dnTime; /* query used time on dn */ + + int maxUsedMemory; /* max used memory */ + int maxPeakChunksQuery; /* max peak chunks for query */ + int minPeakChunksQuery; /* min peak chunks for query */ + + int spillCount; /* total spill count */ + int spillNodeCount; /* the count of the data node with spilled */ + int64 spillSize; /* spill size*/ + int64 broadcastSize; /* broadcast size, unit is bytes */ + int64 broadcastThreshold; /* Threshold of broadcast size, unit is bytes */ + + int scanCount; /* scan counter */ + int nodeCount; /* data node counter */ + + uint64 totalSpace; /* total table space */ + WLMActionTag action; /* data node num */ + + char* nodeInfo; /* node info string */ +}; + +struct WLMGeneralData { + WLMDataIndicator peakMemoryData; /* peak memory data */ + WLMDataIndicator usedMemoryData; /* used memory data */ + WLMDataIndicator spillData; /* spill data */ + WLMDataIndicator broadcastData; /* broadcast data */ + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ + WLMDataIndicator dnTimeData; /* query used time on dn */ + WLMDataIndicator cpuData; /* query cpu time on dn */ + + int nodeCount; /* node count */ + int spillNodeCount; /* spill node count */ + int warning; /* warning info */ + + uint64 totalSpace; /* total table space */ + WLMTopDnList* WLMCPUTopDnInfo; /* top5 cpu dn list */ + WLMTopDnList* WLMMEMTopDnInfo; /* top5 mem dn list */ + SlowQueryInfo slowQueryInfo; + List* query_plan; + int tag; +}; + +struct WLMIoGeninfo { + // calculated variable from io_priority + int curr_iops_limit; /* current iops_limits calculated from io_priority*/ + int prio_count_down; /* count down for io_priority 3, 2, 1 */ + int io_count; /* update when write/read is running reset every io_priority gap (0.5, 1, 1.5) */ + int hist_iops_tbl[PAST_TIME_COUNT]; /* history io_count table */ + + // iops collectinfo + int io_count_persec; /* IO count for io_priority*** ----reset every second*/ + int tick_count_down; /* count down for collect info */ + + // iops statistics --update each second + int curr_iops; /* current mean iops */ + int peak_iops; /* peak mean iops */ + + int nodeCount; /* count of node */ + /* IO flow */ + uint64 read_bytes[2]; /* logical read_bytes */ + uint64 write_bytes[2]; /* logical write_bytes */ + uint64 read_counts[2]; /* read operation counts */ + uint64 write_counts[2]; /* write operation counts */ + uint64 group_value[4]; /* used for group user */ + uint64 read_speed; /* read speed */ + uint64 write_speed; /* write speed */ + + TimestampTz timestampTz; /* last timestamp */ + + // the belowing is only updated on CN + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ +}; + +/* reply statement info */ +struct WLMStmtReplyDetail { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ + int estimate_memory; /* estimate total memory */ + WLMStatusTag status; /* wlm status of statement */ +}; + +/* statement info */ +struct WLMStmtDetail { + Qid qid; /* qid for query */ + + Oid databaseid; /* database id */ + Oid userid; /* user id */ + uint64 debug_query_id; /* debug query id */ + uint64 plan_size; /* plan size */ + Oid rpoid; /* resource pool oid */ + char respool[NAMEDATALEN]; /* resource pool */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char appname[NAMEDATALEN]; /* application name */ + char* username; /* user name */ + char* schname; /* schema name */ + char* msg; /* statement's message to show */ + char* query_plan_issue; /* query plan issue */ + char* query_plan; /* query plan */ + char* query_band; /* query band */ + char* statement; /* sql statement text */ + char* clienthostname; /* MUST be null-terminated */ + void* clientaddr; /* client address */ + + WLMGeneralInfo geninfo; /* general session info */ + WLMIoGeninfo ioinfo; /* session IO info */ + SlowQueryInfo slowQueryInfo; /* slow query info */ + + ThreadId threadid; /* thread id */ + bool valid; /* detail info is valid? */ + + TimestampTz start_time; /* query start time stamp */ + TimestampTz fintime; /* query finish time stamp */ + TimestampTz exptime; /* record expire time */ + + WLMStatusTag status; /* wlm status of statement */ + int64 block_time; /* query block time */ + int64 estimate_time; /* estimate total time */ + int estimate_memory; /* estimate total memory */ + int warning; /* warning info */ +}; + +/* data node resource info update */ +struct WLMNodeUpdateInfo { + Qid qid; /* id for statement on dn */ + char nodegroup[NAMEDATALEN]; /* node group name */ + unsigned char cpuctrl; /* reference counter */ + WLMGeneralInfo geninfo; /* general info for the dnode collect info */ +}; + +/* data node resource info, it's used on CN and DN */ +struct WLMDNodeInfo { + Qid qid; /* id for statement on dn */ + Oid userid; /* user id */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char schname[NAMEDATALEN]; /* schema name */ + char* statement; /* sql statement text */ + char* qband; /* query band string */ + ThreadId tid; /* cn pid */ + int threadCount; /* a counter of thread */ + unsigned char cpuctrl; /* reference counter */ + unsigned char restrack; /* resource track flag */ + unsigned char flags[2]; /* reserve flags */ + WLMActionTag tag; /* action tag */ + void* mementry; /* session memory entry */ + void* respool; /* resource pool in htab */ + void* userdata; /* user info pointer */ + WLMGeneralInfo geninfo; /* general info for the dnode collect info */ + int64 block_time; /* query block time */ + TimestampTz start_time; /* query start time stamp */ +}; + +struct WLMDNodeIOInfo { + Qid qid; /* id for statement on dn */ + ThreadId tid; /* cn pid */ + WLMActionTag tag; /* action tag */ + char nodegroup[NAMEDATALEN]; /* node group name */ + + // user set GUC variables + int io_priority; /* user set io percent for query */ + int iops_limits; /* user set iops_limits for each query */ + + void* userptr; /* UserData pointer in the htab */ + + int io_state; /* IOSTATE_WRITE? IOSTATE_READ? */ + volatile int threadCount; /* thread attached for the query */ + + WLMIoGeninfo io_geninfo; /* io general info for query */ +}; + +/* data node real time resource info */ +struct WLMDNRealTimeInfoDetail { + Qid qid; /* id for statement on dn */ + + int64 cpuStartTime; /* start cpu time */ + int64 cpuEndTime; /* end cpu time */ + + pid_t tid; /* a key of this detail info, it's a thread id */ + unsigned char cpuctrl; /* cpu control is valid ? */ + unsigned char flags[3]; /* save it in the collect info list? */ + WLMStatusTag status; /* status of the detail info */ +}; + +/* cgroup info */ +struct WLMCGroupInfo { + gscgroup_grp_t* grpinfo; /* cgroup exception infomation */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + bool attaching; /* check the thread whether is attaching a new cgroup */ + bool invalid; /* check the cgroup whether is invalid */ +}; + +/* collect info on cn */ +struct WLMCollectInfo { + WLMStmtDetail sdetail; /* statement info detail */ + + WLMCGroupInfo cginfo; /* control group info */ + + TimestampTz blockStartTime; /* query block start time */ + TimestampTz blockEndTime; /* query block end time for a period of time*/ + TimestampTz execStartTime; /* query exec start time */ + TimestampTz execEndTime; /* query exec end time for a period of time*/ + + int trait; /* trait for exception handler */ + int update; /* reserved */ + + int64 max_mem; /* max memory for thread */ + int64 avail_mem; /* available memory for thread */ + + WLMStatusTag status; /* wlm status of statement */ + WLMActionTag action; /* wlm action for statement process */ + WLMAttrTag attribute; /* wlm attribute of statement */ +}; + +/* exception manager */ +struct ExceptionManager { + TimestampTz blockEndTime; /* statement block end time */ + TimestampTz execEndTime; /* statement execute end time */ + TimestampTz adjustEndTime; /* statement penalty end time for a period of time */ + TimestampTz intvalEndTime; /* interval end time */ + TimestampTz qualiEndTime; /* qualification end time */ + + int max_waiting_time; /* statement max block time */ + int max_running_time; /* statement max execute time */ + int max_adjust_time; /* statement max penalty time */ + int max_interval_time; /* statement max interval time */ + + except_data_t except[EXCEPT_ALL_KINDS]; /* cgroup exception infomation */ +}; + +struct WLMIoStatisticsGenenral { + ThreadId tid; + + int maxcurr_iops; /* max current iops for all DN */ + int mincurr_iops; /* max current iops for all DN */ + + int maxpeak_iops; /* max current iops for all DN */ + int minpeak_iops; /* max current iops for all DN */ + + int iops_limits; + int io_priority; + int curr_iops_limit; /* iops_limit calculated from io_priority*/ +}; + +struct WLMIoStatisticsList { + WLMIoStatisticsGenenral* node; + WLMIoStatisticsList* next; +}; + +/* query runtime info for pg_session_wlmstat */ +struct WLMStatistics { + char stmt[KBYTES]; /* statement */ + int64 blocktime; /* query block time while waiting in the queue */ + int64 elapsedtime; /* elapsed time of the query */ + int64 maxcputime; /* max cpu time of the query */ + int64 totalcputime; /* total cpu time of the query */ + int64 qualitime; /* the qualification time of the query */ + int skewpercent; /* the skew percent of the query */ + int priority; /* priority in the queue */ + int stmt_mem; /* statement memory */ + int act_pts; /* active points */ + int dop_value; /* dop value */ + char cgroup[NAMEDATALEN]; /* control group */ + char srespool[NAMEDATALEN]; /* session_respool */ + char* status; /* status */ + char* action; /* action */ + char* enqueue; /* enqueue state: respool, global or none. */ + char* qtype; /* statement's type, simple or complicated. */ + bool is_planA; /* statement's type, simple or complicated. */ + char groupname[NAMEDATALEN]; /* node group name */ +}; + +/* session history resource info for gs_wlm_session_query_info_all */ +struct WLMSessionStatistics { + char respool[NAMEDATALEN]; /* resource pool */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char spillInfo[16]; /* spill info */ + + WLMGeneralData gendata; /* wlm general data on dn */ + + Qid qid; /* qid for the query */ + Oid databaseid; /* database id */ + Oid userid; /* user id */ + uint64 debug_query_id; /* debug query id */ + TimestampTz start_time; /* query start time stamp */ + TimestampTz fintime; /* query finish time stamp */ + ThreadId tid; /* thread id */ + WLMStatusTag status; /* wlm status of statement */ + int64 block_time; /* query block time */ + int64 estimate_time; /* estimate total time */ + int64 duration; /* query excute time */ + char* query_band; /* query band */ + char* query_plan; /* query plan */ + char* query_plan_issue; /* query plan issue */ + char* err_msg; /* error message */ + char* statement; /* sql statement text */ + char* schname; /* schema name */ + char* appname; /* application name */ + char* clienthostname; /* client host name */ + char* username; /* user name */ + + void* clientaddr; /* client address */ + bool remove; /* remove info from hash table */ + int estimate_memory; /* estimate total memory */ + uint64 n_returned_rows; +}; + +struct WLMSigReceiveData { + char cgroup[NAMEDATALEN]; /* cgroup name */ + pthread_t tid; /* thread id */ + int priority; /* priority of cgroup */ + int used; /* slot is used */ +}; + +typedef struct IOHashCtrl { + int lockId; /* lock id */ + HTAB* hashTable; /* hash tables */ +} IOHashCtrl; + +/* statistics control */ +struct WLMStatManager { + int max_collectinfo_num; /* max collect info num in list */ + int max_statistics_num; /* max collect info num in list */ + int max_iostatinfo_num; /* max iostat info num in list */ + int max_detail_num; /* max session info num in the hash table */ + int index; /* index of the statistics memory */ + int comp_count; /* complicated statement count */ + + unsigned char stop; /* a flag to stop running. */ + unsigned char overwrite; /* check the statistics memory whether is overwritten */ + unsigned char datainit; /* a flag to check collect_info_hashtbl whether has record. */ + unsigned char remain; + + char user[NAMEDATALEN]; /* user name to use in the backend thread */ + char mon_user[NAMEDATALEN]; /* user name to use in wlm monitor thread */ + + char database[NAMEDATALEN]; /* database name to use in the backend thread */ + + char execdir[STAT_PATH_LEN]; /* the path for binaries */ + char datadir[STAT_PATH_LEN]; /* the path for log */ + + unsigned int infoinit; /* htab init ok */ + unsigned int sendsig; /* send signal */ + + TimestampTz scanEndTime; /* a timer for collect data persistence */ + + ThreadId thread_id; /* backend thread id */ + + HTAB* collect_info_hashtbl; /* collect information hash table */ + HTAB* session_info_hashtbl; /* session fino hash table for the query finished */ + HTAB* user_info_hashtbl; /* user info hash tbale */ + IOHashCtrl* iostat_info_hashtbl; /* iostat info control */ + HTAB* node_group_hashtbl; /* node group hash table */ + HASH_SEQ_STATUS collect_info_seq; /* collect info hash table seq */ + HASH_SEQ_STATUS iostat_info_seq; /* collect info hash table seq */ + + WLMStatistics* statistics; /* the pointer to statistics memory */ + WLMSigReceiveData* recvdata; /* received data */ + + WLMUserInfo** userinfo; /* user info list */ + + pthread_mutex_t statistics_mutex; /* mutex to lock the statistics list */ + pthread_mutex_t collectinfo_list_mutex; /* mutex to lock the list */ +}; + +/* Structures for I/O stats. */ +struct DiskIOStats { + unsigned long long total_io; /* total io operation */ + unsigned long read_sectors; /* read sectors */ + unsigned long write_sectors; /* write sectors */ + unsigned long read_io; /* read io operation */ + unsigned long read_merges; /* read requests merged */ + unsigned long write_io; /* write io operation */ + unsigned long write_merges; /* write requests merged */ + unsigned int read_ticks; /* Time of read requests in queue */ + unsigned int write_ticks; /* Time of write requests in queue */ + unsigned int discard_ticks; /* Time of discard requests in queue */ + unsigned int total_ticks; /* total ticks */ + unsigned int queue_ticks; /* Time of ticks requests spent in queue */ +}; + +/* I/O stats calculcate result. */ +struct DiskIOStatsMetric { + double rsectors; /* rsec/s */ + double wsectors; /* wsec/s */ + double util; /* disk util */ + double await; /* disk await */ +}; + +/* dn instance info */ +typedef struct WLMInstanceInfo { + TimestampTz timestamp; /* timestamp */ + double usr_cpu; /* userspace cpu usage */ + double sys_cpu; /* system cpu usage */ + int free_mem; /* instance free mem, max_process_mem - process_used_memory */ + int used_mem; /* instance used mem */ + double io_await; /* disk io_await */ + double io_util; /* disk io_util */ + double disk_read; /* disk read speed */ + double disk_write; /* disk write speed */ + uint64 process_read_speed; /* gaussdb process read speed */ + uint64 process_write_speed; /* gaussdb process write speed */ + uint64 read_counts; /* logical read counts */ + uint64 write_counts; /* logical write counts */ + uint64 logical_read_speed; /* logical read speed */ + uint64 logical_write_speed; /* logical write speed */ +} WLMInstanceInfo; + +/* dn instance statistics control */ +typedef struct WLMInstanceStatManager { + int max_stat_num; /* max stat info num in list */ + int collect_interval; /* the collect info interval */ + int persistence_interval; /* the persistence interval */ + int cleanup_interval; /* the cleanup history info interval */ + + char instancename[NAMEDATALEN]; /* dn instance name */ + char diskname[MAX_DEVICE_LEN]; /* the dn diskname */ + + uint64 totalCPUTime[2]; /* total time of the cpu,0 is old value,1 is new value */ + uint64 userCPUTime[2]; /*cpu time of the process user mode,0 is old value,1 is new value*/ + uint64 sysCPUTime[2]; /*cpu time of the process systerm mode,0 is old value,1 is new value*/ + + unsigned long long uptime[2]; /* uptime array */ + DiskIOStats device[2]; /* dev statistics */ + + uint64 process_read_bytes[2]; /* gaussdb process read bytes */ + uint64 process_write_bytes[2]; /* gaussdb process write bytes */ + + uint64 logical_read_bytes[2]; /* logical write bytes */ + uint64 logical_write_bytes[2]; /* logical write bytes */ + + uint64 read_counts[2]; /* logical read counts */ + uint64 write_counts[2]; /* logical write counts */ + + TimestampTz last_timestamp; /* a timer for collect data*/ + TimestampTz recent_timestamp; /* a timer for collect data*/ + + HTAB* instance_info_hashtbl; /* instance info hash table */ +} WLMInstanceStatManager; + +/* process wlm workload manager */ +extern int WLMProcessWorkloadManager(); +/* get hashCode of io statistics from qid */ +extern uint32 GetIoStatBucket(const Qid* qid); +/* get lockId of io statistics from hashCode */ +extern int GetIoStatLockId(const uint32 bucket); +/* initialize stat info */ +extern void WLMInitializeStatInfo(); +/* set stat info */ +extern void WLMSetStatInfo(const char*); +/* reset stat info for exception */ +extern void WLMResetStatInfo4Exception(); +/* generate a hash code by a key */ +extern uint32 WLMHashCode(const void* key, Size keysize); +/* set collect info status to finished */ +extern void WLMSetCollectInfoStatusFinish(); +/* set collect info status */ +extern void WLMSetCollectInfoStatus(WLMStatusTag); +/* create collect info on datanodes */ +extern void WLMCreateDNodeInfoOnDN(const QueryDesc*); +/* get wlm backend state */ +extern void WLMGetStatistics(TimestampTz*, TimestampTz*, WLMStatistics*); +/* get wlm statistics for handling exception */ +extern WLMStatistics* WLMGetStatistics(int*); +/* initialize worker thread */ +extern void WLMWorkerInitialize(struct Port*); +/* worker thread main function */ +extern int WLMProcessThreadMain(); +/* shut down the worker thread*/ +extern void WLMProcessThreadShutDown(); +/* get session info */ +extern void* WLMGetSessionInfo(const Qid* qid, int removed, int* num); +/* get instance info */ +extern void* WLMGetInstanceInfo(int* num, bool isCleanup); +/* plan list format string */ +extern char* PlanListToString(const List* query_plan); +/* get session info from each data nodes */ +extern char* WLMGetSessionLevelInfoInternal(Qid* qid, WLMGeneralInfo* geninfo); +/* get wlm session statistics */ +extern void* WLMGetSessionStatistics(int* num); +/* get wlm session io statistics */ +extern void* WLMGetIoStatistics(int* num); +/* switch cgroup with cn thread id */ +extern bool WLMAjustCGroupByCNSessid(uint64 sess_id, const char* cgroup); +extern void WLMAdjustCGroup4EachThreadOnDN(WLMDNodeInfo* info); +/* get spill info string */ +extern char* WLMGetSpillInfo(char* spillInfo, int size, int spillNodeCount); +/* get warn info string */ +extern void WLMGetWarnInfo(char* warnInfo, int size, unsigned int warn_bit, int spill_size, int broadcast_size, + WLMSessionStatistics* session_stat = NULL); +/* get skew ratio of datanodes */ +extern int GetSkewRatioOfDN(const WLMGeneralInfo* pGenInfo); +/* get each datanode session info for a thread */ +extern WLMCollectInfoDetail* WLMGetSessionInfo4Thread(ThreadId threadid, int* num); +/* parse node info string */ +extern void WLMParseInfoString(const char* infostr, WLMCollectInfoDetail* detail); +/* parse collect info string */ +extern void WLMParseFunc4CollectInfo(StringInfo msg, void* suminfo, int size); +/* alloc function for hash table */ +extern void* WLMAlloc0NoExcept4Hash(Size size); +/* check user info htab init is ok */ +extern bool WLMIsInfoInit(void); +/* get user info from the user config */ +extern WLMUserInfo* WLMGetUserInfoFromConfig(Oid uid, bool* found); +/* get user cgroup cpu util */ +extern int WLMGetGroupCpuUtil(char* nodegroup, void* handles, const char* cgroup); + +extern uint32 WLMHashCode(const void* key, Size keysize); +extern int WLMHashMatch(const void* key1, const void* key2, Size keysize); +extern bool IsQidInvalid(const Qid* qid); +extern bool IsQidEqual(const Qid* qid1, const Qid* qid2); +extern void WLMLocalInfoCollector(StringInfo msg); +extern void WLMAdjustCGroup4EachThreadOnDN(WLMDNodeInfo* info); +extern void WLMCreateIOInfoOnDN(void); +extern WLMIoStatisticsList* WLMGetIOStatisticsGeneral(); +extern void WLMCleanUpIoInfo(void); +extern void WLMUpdateCgroupCPUInfo(void); +extern void WLMInitTransaction(bool* backinit); +extern void WLMInitPostgres(); +extern void WLMCleanIOHashTable(); +extern void WLMSetBuildHashStat(int status); +extern bool WLMIsQueryFinished(void); +extern void WLMReadjustAllUserSpace(Oid uid); +extern void WLMReadjustUserSpaceThroughAllDbs(const char* username); +extern void WLMReadjustUserSpaceByNameWithResetFlag(const char* username, bool resetFlag); +extern WLMCollectInfoDetail* WLMGetUserSessionInfo4Thread(const char* uname, int* num); +extern void WLMSetExecutorStartTime(void); +extern bool WLMIsDumpActive(const char* sql); +extern void WLMCheckSigRecvData(void); +extern char* GetStatusName(WLMStatusTag tag); + +extern char* WLMGetExceptWarningMsg(WLMExceptTag tag); +extern int64 WLMGetTimestampDuration(TimestampTz start, TimestampTz end); +extern void WLMInitQueryPlan(QueryDesc* queryDesc, bool isQueryDesc = true); +extern double WLMGetTotalCost(const QueryDesc* desc, bool isQueryDesc); +extern int WLMGetQueryMem(const QueryDesc* desc, bool isQueryDesc, bool max = true); +extern bool WLMGetInComputePool(const QueryDesc* desc, bool isQueryDesc); +extern int WLMGetMinMem(const QueryDesc* desc, bool isQueryDesc, bool max = true); +extern int WLMGetAvailbaleMemory(const char* ngname); +extern bool WLMChoosePlanA(PlannedStmt* stmt); +extern void WLMGetWorkloadStruct(StringInfo strinfo); +extern void WLMDefaultXactReadOnlyCheckAndHandle(void); +extern void WLMTopSQLReady(QueryDesc* queryDesc); +extern void WLMReleaseIoInfoFromHash(void); + +#define WORKLOAD_STAT_HASH_SIZE 64 +// default database name +#define DEFDBNAME "postgres" + +#ifdef ENABLE_UT +void ut_to_update(void*); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/include/workload/workload.h postgresql-hll-2.14/include/include/workload/workload.h --- postgresql-hll-2.14_old/include/include/workload/workload.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/include/workload/workload.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,603 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * workload.h + * definitions for workload manager + * + * IDENTIFICATION + * src/include/workload/workload.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef WORKLOAD_H +#define WORKLOAD_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "gs_threadlocal.h" +#include "nodes/parsenodes.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "utils/datetime.h" +#include "utils/portal.h" +#include "utils/palloc.h" +#include "postmaster/postmaster.h" + +#include "workload/gscgroup.h" +#include "workload/ctxctl.h" +#include "workload/parctl.h" +#include "workload/statctl.h" +#include "workload/memctl.h" +#include "workload/dywlm_client.h" +#include "workload/dywlm_server.h" +#include "workload/ioschdl.h" +#include "workload/cpwlm.h" + +#define FULL_PERCENT 100 +#define OTHER_USED_PERCENT 60 /* 60 aviable memory for other uses */ + +#define STATEMENT_MIN_MEM 256 /*MB*/ +#define STATEMETN_MIN_MODIFY_MEM 2 * 1024 /*MB, 2gb*/ +#define MEM_THRESHOLD 32 /*MB*/ +#define SIMPLE_THRESHOLD (32 * 1024) /* 32MB */ +#define HOLD_NODE_GROUP(group) gs_lock_test_and_set((int*)&group->used, 1) +#define RESUME_NODE_GROUP(group) gs_lock_test_and_set((int*)&group->used, 0) + +#define NodeGroupIsDefault(group) (NULL == (void*)group || *group == '\0' || strcmp(group, "installation") == 0) + +#define ENABLE_WORKLOAD_CONTROL \ + (u_sess->attr.attr_resource.use_workload_manager || u_sess->attr.attr_resource.bypass_workload_manager) + +#define DY_MEM_ADJ(stmt) \ + g_instance.wlm_cxt->dynamic_workload_inited&& t_thrd.wlm_cxt.parctl_state.enqueue && \ + (stmt)->query_mem[0] >= MEM_THRESHOLD * 1024L +#define ASSIGNED_QUERY_MEM(mem, max_mem) ((max_mem) > 0 ? Min((mem), (max_mem)) : (mem)) +#define VALID_QUERY_MEM() \ + (ASSIGNED_QUERY_MEM(u_sess->attr.attr_sql.statement_mem, u_sess->attr.attr_sql.statement_max_mem) > 0) + +extern THR_LOCAL bool log_workload_manager; + +typedef enum CGSwitchState { CG_ORIGINAL = 0, CG_USERSET, CG_USING, CG_RESPOOL } CGSwitchState; + +typedef enum DataSpaceType { SP_PERM = 0, SP_TEMP, SP_SPILL } DataSpaceType; + +typedef struct UserData { + Oid userid; /* user id */ + bool is_super; /* user is admin user */ + bool is_dirty; /* userinfo is dirty, temorarily used in BuildUserInfoHash*/ + unsigned char adjust; /* adjust space flag */ + unsigned char keepdata; /* keep memory size */ + int64 totalspace; /* user used total space */ + int64 global_totalspace; /* user used total space on all cns and dns in bytes*/ + int64 reAdjustPermSpace; /* for wlm_readjust_user_space */ + int64 spacelimit; /* user space limit in bytes*/ + bool spaceUpdate; /* user used total space or temp space updated ? */ + int64 tmpSpace; /* user used temp space in bytes */ + int64 globalTmpSpace; /* user used temp space on all cns and dns in bytes */ + int64 reAdjustTmpSpace; /* for wlm_readjust_user_space */ + int64 tmpSpaceLimit; /* user temp space limit in bytes */ + int64 spillSpace; /* user used spill space in bytes */ + int64 globalSpillSpace; /* user used spill space on all cns and dns in bytes */ + int64 spillSpaceLimit; /* user spill space limit in bytes */ + Oid rpoid; /* resource pool in htab */ + int memsize; /* user used memory */ + int usedCpuCnt; /* average used CPU counts */ + int totalCpuCnt; /* average total CPU counts */ + volatile int referenceCnt; /* reference count, avoid wrong remove */ + ResourcePool* respool; /* resource pool in htab */ + UserData* parent; /* parent user data in htab */ + List* childlist; /* child list */ + WLMUserInfo* infoptr; /* user info */ + int query_count; /* how many IO complicated queries are active now */ + WLMIoGeninfo ioinfo; /* io info*/ + pthread_mutex_t mutex; /* entry list mutex */ + List* entry_list; /* session entry list */ + + int compare(const Oid* userid) + { + if (this->userid == *userid) + return 0; + + return ((this->userid < *userid) ? 1 : -1); + } +} UserData; + +/* used for BuildUserInfoHash function, avoid dead lock */ +typedef struct TmpUserData { + Oid userid; /* user id */ + Oid puid; /* parent id */ + bool is_super; /* user is admin user */ + bool is_dirty; /* userinfo is dirty, temorarily used in BuildUserInfoHash*/ + int64 spacelimit; /* user space limit in bytes*/ + int64 tmpSpaceLimit; /* user temp space limit in bytes */ + int64 spillSpaceLimit; /* user spill space limit in bytes */ + Oid rpoid; /* resource pool in htab */ + ResourcePool *respool; /* resource pool in htab */ +} TmpUserData; + +typedef struct UserResourceData { + Oid userid; /* user oid */ + int total_memory; /* user total memroy */ + int used_memory; /* user used memory */ + int total_cpuset; /* user total cpuset */ + int used_cpuset; /* user used cpuset */ + int64 total_space; /* user total space limit */ + int64 used_space; /* user used space */ + int64 total_temp_space; /* user total temp space limit */ + int64 used_temp_space; /* user used temp space */ + int64 total_spill_space; /* user total spill space limit */ + int64 used_spill_space; /* user used spill space */ + + /* io collect information for user */ + int mincurr_iops; /* user min current iops */ + int maxcurr_iops; /* user max current iops */ + int minpeak_iops; /* user min peak iops */ + int maxpeak_iops; /* user max peak iops */ + + int iops_limits; /* iops_limits for user */ + int io_priority; /* io_priority for user */ + int curr_iops_limit; /* iops_limit calculated from io_priority */ + /* IO flow data */ + uint64 read_bytes; /* read bytes during the monitor interval */ + uint64 write_bytes; /* write bytes during the monitor interval */ + uint64 read_counts; /* read counts during the monitor interval */ + uint64 write_counts; /* write counts during the monitor interval */ + uint64 read_speed; /* read speed */ + uint64 write_speed; /* write speed */ +} UserResourceData; + +typedef struct WLMNodeGroupInfo { + char group_name[NAMEDATALEN]; /* node group name */ + + int used_memory; /* node used memory */ + int total_memory; /* node total memory */ + int estimate_memory; /* node estimate memory */ + + int min_freesize; /* minimum free size of nodes */ + + unsigned int used; /* if it is in use */ + + ClientDynamicManager climgr; /* client manager */ + ServerDynamicManager srvmgr; /* server manager */ + ParctlManager parctl; /* static parallel manager */ + + gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM]; /* control group info */ + HTAB* cgroups_htab; /* cgroup hash table of the node group */ + pthread_mutex_t cgroups_mutex; /* not used */ + + List* node_list; /* node list of the node group */ + + ResourcePool* foreignrp; /* foreign resource pool */ + + bool is_dirty; /* the node group is dirty */ + +} WLMNodeGroupInfo; + +/* debug info */ +typedef struct WLMDebugInfo { + WLMGeneralParam* wparams; /* debug info for general params */ + ExceptionManager* statctl; /* debug info for statctl manager */ + WLMCollectInfo* colinfo; /* debug info for collect info */ + + ParctlState* pstate; /* debug info for parctl state */ + ParctlManager* parctl; /* debug info for parctl manager */ + ClientDynamicManager* climgr; /* debug info for client manager */ + ServerDynamicManager* srvmgr; /* debug info for server manager */ + + int active_statement; + bool* reserved_in_transaction; + +} WLMDebugInfo; + +typedef struct knl_g_wlm_context { + /* The default node group when there is no logical cluster */ + WLMNodeGroupInfo MyDefaultNodeGroup; + + /* the node group information for foreign users */ + WLMNodeGroupInfo* local_dn_nodegroup; + + /* the global variable of workload manager memory context */ + MemoryContext workload_manager_mcxt; + + /* the global variable of query resource track memory context */ + MemoryContext query_resource_track_mcxt; + + /* the global variable of operator resource track memory context */ + MemoryContext oper_resource_track_mcxt; + + /* stat manager */ + WLMStatManager stat_manager; + + /* dn instance statistics manager */ + WLMInstanceStatManager instance_manager; + + /* resource pool is stored in this hash table*/ + HTAB* resource_pool_hashtbl; + + /* flag to enable dynamic workload */ + bool dynamic_workload_inited; + + /* Dynamic DNs memory collected flag */ + bool dynamic_memory_collected = false; + + /* the memory unused in parallel control */ + int parctl_process_memory; + + /* cgroup initialized completed */ + int gscgroup_init_done; + + /* config parsed completed */ + int gscgroup_config_parsed; + + /* CPU count */ + int gscgroup_cpucnt; + + /* the node group for local datanode */ + char local_dn_ngname[NAMEDATALEN]; + + /* configure file */ + gscgroup_grp_t* gscgroup_vaddr[GSCGROUP_ALLNUM]; + + /* vacuum cgroup structure */ + struct cgroup* gscgroup_vaccg; + + /* default backend cgroup structure */ + struct cgroup* gscgroup_bkdcg; + + /* root cgroup structure */ + struct cgroup* gscgroup_rootcg; + + /* default workload cgroup structure */ + struct cgroup* gscgroup_defwdcg; + + /* default topwd cgroup structure */ + struct cgroup* gscgroup_deftopwdcg; + + /* used for io scheduler */ + WLMIOContext io_context; + + // cluster state + struct DNState* cluster_state; + + // dn count in cluster state + int dnnum_in_cluster_state; + + // indicate if the node is cnn + bool is_ccn; + + // the index count of cnn + int ccn_idx; + + /* record the resource package number in datanode */ + int rp_number_in_dn; +} knl_g_wlm_context; + +typedef struct knl_u_wlm_context { + /* save the Cgroup name */ + char control_group[NAMEDATALEN]; + + /* indicate if the name of control_group has changed */ + CGSwitchState cgroup_state; + + /* save control group switch status */ + gscgroup_stmt_t cgroup_stmt; + gscgroup_stmt_t cgroup_last_stmt; + + /* if the session resource pool is changed */ + bool session_respool_switch; + + /* session_respool is initialized or not */ + bool session_respool_initialize; + + /* get is_foreign for updating hash table */ + bool respool_is_foreign; + + /* flag to update user hash table */ + bool wlmcatalog_update_user; + + /*cancel job due to workload manager exception*/ + bool cancel_from_wlm; + + /*cancel job due to space limitation*/ + bool cancel_from_space_limit; + + /*cancel job due to transcation readonly */ + bool cancel_from_defaultXact_readOnly; + + /* save the session_respool name */ + char session_respool[NAMEDATALEN]; + + /* get oid of the created resource pool for updating hash table */ + Oid respool_create_oid; + + /* get oid of the altered resource pool for updating hash table */ + Oid respool_alter_oid; + + /*record last stmt session respool*/ + Oid respool_old_oid; + + /* get oid list of the resource pool dropping list for updating hash table */ + List* respool_delete_list; + + /* mempct for updating hash table */ + int respool_foreign_mempct; + + /* actual percent for updating hash table */ + int respool_foreign_actpct; + + /* parentid for updating hash table */ + Oid respool_parentid; + + /* get io_limits for updating hash table */ + int32 respool_io_limit_update; + + /* get io_priority for updating hash table */ + char respool_io_pri_update[NAMEDATALEN]; + + /* get io_priority for updating hash table */ + char respool_nodegroup[NAMEDATALEN]; + + /* get io_priority for updating hash table */ + char respool_controlgroup[NAMEDATALEN]; + + /* which node group resource pool belong to */ + WLMNodeGroupInfo* respool_node_group; + + /* local foreign respool */ + ResourcePool* local_foreign_respool; + + /* workload debug info */ + WLMDebugInfo wlm_debug_info; + + /* workload session info */ + WLMGeneralParam wlm_params; + + /* the num of streams' thread */ + int wlm_num_streams; + + /* the keyname of the control group */ + char group_keyname[GPNAME_LEN]; + + /* indicate if it is in transcation */ + bool is_reserved_in_transaction; + + /* indicate if the parallel queue is reset */ + bool is_active_statements_reset; + + /* indicate if the query is forced to run */ + bool forced_running; + + /* indicate if the query has running one time */ + bool query_count_record; + + /* record if the computing pool task is running */ + bool cp_task_running; + + /* reserved count in global active statements */ + int reserved_in_active_statements; + + /* reserved count in resource pool active statements */ + int reserved_in_group_statements; + + /* reserved count for simple query in resource pool active statements */ + int reserved_in_group_statements_simple; + + /* the count which is waiting in resouce pool */ + int reserved_in_respool_waiting; + + int reserved_in_central_waiting; + + /* used to record the user when inserting data */ + UserData* spmgr_userdata; + + HTAB* TmptableCacheHash; + + /* computing pool runtime information */ + CPRuntimeInfo* cp_runtime_info; + + /* Track storage usage in bytes at individual thread level when space increasing */ + uint64 spmgr_space_bytes; + + /* Mark query reach the spill limit */ + bool spill_limit_error; + + /* user pl */ + int64 wlm_userpl; + + /* the reserved query string */ + char reserved_debug_query[1024]; + + unsigned char stroedproc_rp_reserve; + + unsigned char stroedproc_rp_release; + + unsigned char stroedproc_release; + + /* mark the session already do paralle control */ + unsigned char parctl_state_control; + + /* mark the session already exit */ + unsigned char parctl_state_exit; +} knl_u_wlm_context; + +extern void dywlm_client_init(WLMNodeGroupInfo*); +extern void dywlm_server_init(WLMNodeGroupInfo*); +extern void WLMParctlInit(WLMNodeGroupInfo*); +extern void InitializeWorkloadManager(void); + +extern void SetCpuAffinity(int64 setting); + +extern void WLMSetControlGroup(const char* cgname); +extern gscgroup_stmt_t WLMIsSpecialCommand(const Node* parsetree, const Portal); +extern bool WLMIsSimpleQuery(const QueryDesc* queryDesc, bool force_control, bool isQueryDesc); +extern bool WLMNeedTrackResource(const QueryDesc* queryDesc); +extern bool WLMIsSpecialQuery(const char* query); +extern unsigned char WLMCheckToAttachCgroup(const QueryDesc* queryDesc); +extern void WLMSetUserInfo(); +extern void GetCurrentCgroup(char* cgroup, const char* curr_group, int len); +extern void WLMSwitchCGroup(void); +extern char* GetMemorySizeWithUnit(char* memory, int size, int memsize); +extern bool CheckWLMSessionInfoTableValid(const char* tablename); +extern WLMUserInfo* WLMGetUserInfo(Oid userid, WLMUserInfo* info); +extern int ParseUserInfoConfigFile(void); +extern UserData* GetUserDataFromHTab(Oid roleid, bool is_noexcept); +extern bool BuildUserRPHash(void); +extern void* WLMGetAllUserData(int* num); /* get all user data from htab */ +extern void WLMReAdjustUserSpace(UserData* userdata, bool isForce = false); +extern char* GenerateResourcePoolStmt(CreateResourcePoolStmt* stmt, const char* origin_query); + +extern void CreateResourcePool(CreateResourcePoolStmt* stmt); +extern void AlterResourcePool(AlterResourcePoolStmt* stmt); +extern void RemoveResourcePool(Oid pool_oid); +extern void DropResourcePool(DropResourcePoolStmt* stmt); + +extern void CreateWorkloadGroup(CreateWorkloadGroupStmt* stmt); +extern void AlterWorkloadGroup(AlterWorkloadGroupStmt* stmt); +extern void RemoveWorkloadGroup(Oid group_oid); +extern void DropWorkloadGroup(DropWorkloadGroupStmt* stmt); + +extern void CreateAppWorkloadGroupMapping(CreateAppWorkloadGroupMappingStmt* stmt); +extern void AlterAppWorkloadGroupMapping(AlterAppWorkloadGroupMappingStmt* stmt); +extern void RemoveAppWorkloadGroupMapping(Oid app_oid); +extern void DropAppWorkloadGroupMapping(DropAppWorkloadGroupMappingStmt* stmt); + +extern bool UsersInOneGroup(UserData* user1, UserData* user2); +extern void CheckUserRelation(Oid roleid, Oid parentid, Oid rpoid, bool isDefault, int issuper); +extern int UserGetChildRoles(Oid roleid, DropRoleStmt* stmt); +extern void GetUserDataFromCatalog(Oid userid, Oid* rpoid, Oid* parentid, bool* issuper, int64* spacelimit, + int64* tmpspacelimit, int64* spillspacelimit, char* groupname = NULL, int lenNgroup = 0); +extern bool GetUserChildlistFromCatalog(Oid userid, List** childlist, bool findall); +extern UserResourceData* GetUserResourceData(const char* username); +extern void CheckUserSpaceLimit(Oid roleid, Oid parentid, int64 spacelimit, int64 tmpspacelimit, + int64 spillspacelimit, bool is_default, bool changed, bool tmpchanged, bool spillchanged); +extern ResourcePool* GetRespoolFromHTab(Oid rpoid, bool is_noexcept = true); +extern void perm_space_increase(Oid ownerID, uint64 size, DataSpaceType type); +extern void perm_space_decrease(Oid ownerID, uint64 size, DataSpaceType type); +extern void perm_space_value_reset(void); +extern bool SearchUsedSpace(Oid userID, int64* permSpace, int64* tempSpace); +extern void UpdateUsedSpace(Oid userID, int64 permSpace, int64 tempSpace); + +extern void CheckUserInfoHash(); +extern void UpdateWlmCatalogInfoHash(void); +extern void ResetWlmCatalogFlag(void); +extern unsigned int GetRPMemorySize(int pct, Oid parentid); + +extern void WLMCheckSessionRespool(const char* respool); +extern void WLMSetSessionRespool(const char* respool); + +extern int WLMGetUserMemory(UserData* userdata); +extern void WLMCheckSpaceLimit(void); +extern WLMNodeGroupInfo* WLMGetNodeGroupFromHTAB(const char* group_name); +extern WLMNodeGroupInfo* WLMMustGetNodeGroupFromHTAB(const char* group_name); +extern WLMNodeGroupInfo* WLMGetNodeGroupByUserId(Oid userid); +extern WLMNodeGroupInfo* CreateNodeGroupInfoInHTAB(const char* group_name); +extern void RemoveNodeGroupInfoInHTAB(const char* group_name); +extern void WLMInitNodeGroupInfo(WLMNodeGroupInfo* info); + +/* get debug info string */ +extern void WLMGetDebugInfo(StringInfo strinfo, WLMDebugInfo* debug_info); +/* init cgroup */ +extern void gscgroup_init(void); + +/* free cgroup */ +extern void gscgroup_free(void); + +/* get the percent of specified group */ +extern int gscgroup_get_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* attach task into cgroup */ +extern void gscgroup_attach_task(WLMNodeGroupInfo* ng, const char* gname); + +/* attach batch task into cgroup with tid */ +extern int gscgroup_attach_task_batch(WLMNodeGroupInfo* ng, const char* gname, pid_t tid, int* is_first); + +/* attach backend task into cgroup */ +extern int gscgroup_attach_backend_task(const char* gname, bool is_noexcept); + +/* check if the group has been set */ +extern int gscgroup_check_group_name(WLMNodeGroupInfo* ng, const char* gname); + +/* check if the node in the waiting list need switch */ +extern int gscgroup_check_group_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* switch cgroup */ +extern bool WLMAjustCGroupByCNSessid(WLMNodeGroupInfo* ng, uint64 sess_id, const char* cgroup); + +/* get cgroup name from cgroup */ +char* gsutil_get_cgroup_name(struct cgroup* cg); + +/* get the group configuration information */ +extern gscgroup_grp_t* gscgroup_get_grpconf(WLMNodeGroupInfo* ng, const char* gname); + +/* check if the cgroup is class cgroup */ +extern int gscgroup_is_class(WLMNodeGroupInfo* ng, const char* gname); + +/* switch to TopWD cgroup */ +extern void gscgroup_switch_topwd(WLMNodeGroupInfo* ng); + +/* Back to Current cgroup */ +extern void gscgroup_switch_vacuum(void); + +/* update the hash table */ +extern void gscgroup_update_hashtbl(WLMNodeGroupInfo* ng, const char* keyname); + +/* get group entry from hash table */ +extern gscgroup_entry_t* gscgroup_lookup_hashtbl(WLMNodeGroupInfo* ng, const char* name); + +/* get the next group */ +extern int gscgroup_get_next_group(WLMNodeGroupInfo* ng, char* gname); + +/* get the top group name */ +extern char* gscgroup_get_top_group_name(WLMNodeGroupInfo* ng, char* gname, int len); + +/* look up cgroup from htab */ +extern struct cgroup* gscgroup_lookup_cgroup(WLMNodeGroupInfo* ng, const char* gname, bool* found = NULL); + +/* update cgroup cpu info */ +extern void gscgroup_update_hashtbl_cpuinfo(WLMNodeGroupInfo* ng); + +/* get cgroup info */ +extern gscgroup_info_t* gscgroup_get_cgroup_info(int* num); + +/* get cgroup cpu info */ +extern void gscgroup_get_cpuinfo(gscgroup_entry_t* entry); + +/* get cpu usage percent */ +extern int gscgroup_get_cpu_usage_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* check the cgroups whether are in the same class */ +extern bool gscgroup_is_brother_group(const char* cgroup1, const char* cgroup2); + +/* check whether parentcg is parent cgroup of childcg */ +extern bool gscgroup_is_child_group(const char* parentcg, const char* childcg); + +/* check whether gname is timeshare or not */ +extern int gscgroup_is_timeshare(const char* gname); + +/* convert cgroup name to tthe name without level info */ +extern char* gscgroup_convert_cgroup(char* gname); + +/* check Cgroup percent */ +extern int WLMCheckCgroupPercent(WLMNodeGroupInfo* ng, const char*); + +/* move node to list */ +extern void WLMMoveNodeToList(WLMNodeGroupInfo* ng, ThreadId tid, const char* cgroup); + +/* release active statements while proc exiting */ +extern void WLMReleaseAtThreadExit(); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/ash.h postgresql-hll-2.14/include/instruments/ash.h --- postgresql-hll-2.14_old/include/instruments/ash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/ash.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,60 @@ +#ifndef ASH_H +#define ASH_H +#include "gs_thread.h" +#include "pgstat.h" + +#define ENABLE_ASP u_sess->attr.attr_common.enable_asp +typedef struct SessionHistEntry { + uint64 changCount; + uint64 sample_id; + /* time stamp of every case */ + TimestampTz sample_time; + /* Whether the sample has been flushed to wdr */ + bool need_flush_sample; + + uint64 session_id; + TimestampTz start_time; + bool is_flushed_sample; + uint64 psessionid; + /* Database OID, owning user's OID, connection client address */ + Oid databaseid; + Oid userid; + SockAddr clientaddr; + char* clienthostname; /* MUST be null-terminated */ + + /* application name; MUST be null-terminated */ + char* st_appname; + + uint64 queryid; /* debug query id of current query */ + UniqueSQLKey unique_sql_key; /* get unique sql key */ + ThreadId procpid; /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */ + pid_t tid; + int thread_level; /* thread level, mark with plan node id of Stream node */ + uint32 smpid; /* smp worker id, used for parallel execution */ + WaitState waitstatus; /* backend waiting states */ + uint32 waitevent; /* backend's wait event */ + uint64 xid; /* for transaction id, fit for 64-bit */ + int waitnode_count; /* count of waiting nodes */ + int nodeid; /* maybe for nodeoid/nodeidx */ + int plannodeid; /* indentify which consumer is receiving data for SCTP */ + char* relname; /* relation name, for analyze, vacuum, .etc.*/ + Oid libpq_wait_nodeid; /* for libpq, point to libpq_wait_node*/ + int libpq_wait_nodecount; /* for libpq, point to libpq_wait_nodecount*/ + WaitStatePhase waitstatus_phase; /* detailed phase for wait status, now only for 'wait node' status */ + int numnodes; /* nodes number when reporting waitstatus in case it changed */ + LOCALLOCKTAG locallocktag; /* locked object */ + uint64 st_block_sessionid; /* block session */ +} SessionHistEntry; + +typedef struct ActiveSessHistArrary { + uint32 curr_index; /* the current index of active session history arrary */ + uint32 max_size; /* the max size of the active_sess_hist_arrary */ + SessionHistEntry *active_sess_hist_info; +} ActiveSessHistArrary; + +void InitAsp(); +extern ThreadId ash_start(void); +extern void ActiveSessionCollectMain(); +extern bool IsJobAspProcess(void); +#endif + diff -uprN postgresql-hll-2.14_old/include/instruments/capture_view.h postgresql-hll-2.14/include/instruments/capture_view.h --- postgresql-hll-2.14_old/include/instruments/capture_view.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/capture_view.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * capture_view.cpp + * support utility to capture view to json file + * + * IDENTIFICATION + * src/gausskernel/cbb/instruments/capture_view/capture_view.cpp + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_CAPTURE_VIEW_H +#define INSTR_CAPTURE_VIEW_H + +void init_capture_view(); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/dblink_query.h postgresql-hll-2.14/include/instruments/dblink_query.h --- postgresql-hll-2.14_old/include/instruments/dblink_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/dblink_query.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dblink_query.h + * Functions returning results from a remote database + * + * + * IDENTIFICATION + * src/include/instruments/dblink_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DBLINK_QUERY_H +#define DBLINK_QUERY_H + +#include "fmgr.h" + +extern Datum wdr_xdb_query(PG_FUNCTION_ARGS); + +extern void dblinkCloseConn(void); + +extern void dblinkRequestCancel(void); + +#endif /* DBLINK_QUERY_H */ diff -uprN postgresql-hll-2.14_old/include/instruments/generate_report.h postgresql-hll-2.14/include/instruments/generate_report.h --- postgresql-hll-2.14_old/include/instruments/generate_report.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/generate_report.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * generate_report.h + * definitions for WDR report. + * + * Before generating a report, you need to generate at least two WDR snapshot. + * A WDR report is used to show the performance of the database between snapshots. + * + * + * IDENTIFICATION + * src/include/instruments/generate_report.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef GENER_REPORT +#define GENER_REPORT + +#include + +extern Datum generate_wdr_report(PG_FUNCTION_ARGS); +extern char* Datum_to_string(Datum value, Oid type, bool isnull); +extern void DeepListFree(List* deepList, bool deep); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/gs_stat.h postgresql-hll-2.14/include/instruments/gs_stat.h --- postgresql-hll-2.14_old/include/instruments/gs_stat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/gs_stat.h 2020-12-12 17:06:43.306348799 +0800 @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------- + * + * gs_stat.h + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/instruments/gs_stat.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GS_STAT_H +#define GS_STAT_H +#include "c.h" +#include "funcapi.h" +#include "gs_thread.h" + +static inline void gsGetStatCurrentStatus(PG_FUNCTION_ARGS, FuncCallContext* funcctx, bool has_first_arg = true) +{ + funcctx->user_fctx = gs_stat_read_current_status(&funcctx->max_calls); + if (has_first_arg && !PG_ARGISNULL(0)) { + ThreadId pid = PG_GETARG_INT64(0); + PgBackendStatusNode* beNode = (PgBackendStatusNode*)funcctx->user_fctx; + bool isFind = false; + while (beNode != NULL) { + PgBackendStatus* be = beNode->data; + if (be != NULL && be->st_procpid == pid) { + isFind = true; + funcctx->user_fctx = beNode; + break; + } + beNode = beNode->next; + } + if (isFind) + funcctx->max_calls = 1; + else + funcctx->max_calls = 0; + } +} +extern PgBackendStatusNode* gs_stat_get_timeout_beentry(int timeout_threshold); +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_event.h postgresql-hll-2.14/include/instruments/instr_event.h --- postgresql-hll-2.14_old/include/instruments/instr_event.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_event.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_event.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/instr_event.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_EVENT_H +#define INSTR_EVENT_H +#include "storage/lwlock.h" +void LWLockReportWaitFailed(LWLock *lock); +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_handle_mgr.h postgresql-hll-2.14/include/instruments/instr_handle_mgr.h --- postgresql-hll-2.14_old/include/instruments/instr_handle_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_handle_mgr.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_handle_mgr.h + * definitions for handle manager used in full/slow sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_handle_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_HANDLE_MGR_H +#define INSTR_HANDLE_MGR_H +#include "pgstat.h" + +#define CURRENT_STMT_METRIC_HANDLE ((StatementStatContext*)(u_sess->statement_cxt.curStatementMetrics)) +#define CHECK_STMT_HANDLE() \ +{ \ + if (CURRENT_STMT_METRIC_HANDLE == NULL || u_sess->statement_cxt.stmt_stat_cxt == NULL) { \ + return; \ + } \ +} + +void statement_init_metric_context(); +void statement_commit_metirc_context(); +void release_statement_context(PgBackendStatus* beentry, const char* func, int line); +void concat_suspend_to_free_list(List* free_list, List* suspend_list); +void* bind_statement_context(); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_slow_query.h postgresql-hll-2.14/include/instruments/instr_slow_query.h --- postgresql-hll-2.14_old/include/instruments/instr_slow_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_slow_query.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * instr_slow_query.h + * + * IDENTIFICATION + * src/include/instruments/instr_slow_query.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef INSTR_SLOW_QUERY_H +#define INSTR_SLOW_QUERY_H +#include "nodes/parsenodes.h" +#include "pgstat.h" +#include "c.h" + +void ReportQueryStatus(void); +void WLMSetSessionSlowInfo(WLMStmtDetail* pDetail); +void exec_auto_explain(QueryDesc *queryDesc); +void exec_explain_plan(QueryDesc *queryDesc); +void print_duration(const QueryDesc *queryDesc); +void explain_querydesc(ExplainState *es, QueryDesc *queryDesc); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_slow_query_log.h postgresql-hll-2.14/include/instruments/instr_slow_query_log.h --- postgresql-hll-2.14_old/include/instruments/instr_slow_query_log.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_slow_query_log.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * instr_slow_query_log.h + * + * IDENTIFICATION + * src/include/instruments/instr_slow_query_log.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_SLOW_QUERY_LOG_H +#define INSTR_SLOW_QUERY_LOG_H + +void write_local_slow_log(char *data, int len, bool end); + +#endif + + diff -uprN postgresql-hll-2.14_old/include/instruments/instr_statement.h postgresql-hll-2.14/include/instruments/instr_statement.h --- postgresql-hll-2.14_old/include/instruments/instr_statement.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_statement.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,205 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_statement.h + * definitions for full/slow sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_statement.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_STATEMENT_H +#define INSTR_STATEMENT_H + +#include "c.h" +#include "pgstat.h" +#include "instruments/unique_sql_basic.h" + +#define ENABLE_STATEMENT_TRACK u_sess->attr.attr_common.enable_stmt_track +typedef enum { + STMT_TRACK_OFF = 0, + STMT_TRACK_L0, + STMT_TRACK_L1, + STMT_TRACK_L2, + LEVEL_INVALID +} StatLevel; + +#define MAX_STATEMENT_STAT_LEVEL (STMT_TRACK_L2) + +struct LockSummaryStat { + /* lock */ + int64 lock_start_time; + int64 lock_cnt; + int64 lock_time; + int64 lock_wait_start_time; + int64 lock_wait_cnt; + int64 lock_wait_time; + + /* lwlock */ + int64 lwlock_start_time; + int64 lwlock_cnt; + int64 lwlock_time; + int64 lwlock_wait_start_time; + int64 lwlock_wait_cnt; + int64 lwlock_wait_time; + + /* the maximum lock count at a time. */ + int64 lock_max_cnt; + int64 lock_hold_cnt; +}; + +#pragma pack (1) +typedef struct { + char eventType; + int64 timestamp; + LOCKTAG tag; + LOCKMODE mode; +} LockEventStartInfo; + +typedef struct { + char eventType; + int64 timestamp; + uint16 id; + LWLockMode mode; +} LWLockEventStartInfo; + +typedef struct { + char eventType; + int64 timestamp; +} LockEventEndInfo; +#pragma pack() + +typedef enum { + LOCK_START = 1, + LOCK_END, + LOCK_WAIT_START, + LOCK_WAIT_END, + LOCK_RELEASE_START, + LOCK_RELEASE_END, + LWLOCK_START, + LWLOCK_END, + LWLOCK_WAIT_START, + LWLOCK_WAIT_END, + LWLOCK_RELEASE_START, + LWLOCK_RELEASE_END, + TYPE_INVALID +} StatementDetailType; + +// type(1 byte), timestamp(8 bytes), locktag(20 bytes), lockmode(4 bytes) +#define LOCK_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_END_DETAIL_BUFSIZE 9 +// type, timestamp, locktag, lockmode +#define LOCK_WAIT_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_WAIT_END_DETAIL_BUFSIZE 9 +// type, timestamp, locktag, lockmode +#define LOCK_RELEASE_START_DETAIL_BUFSIZE 33 +// type, timestamp +#define LOCK_RELEASE_END_DETAIL_BUFSIZE 9 +// type(1 byte), timestamp(8 bytes), lwlockId(2 bytes), lockmode(4 bytes) +#define LWLOCK_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_END_DETAIL_BUFSIZE 9 +// type, timestamp, lwlockId, lockmode +#define LWLOCK_WAIT_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_WAIT_END_DETAIL_BUFSIZE 9 +// type, timestamp, lwlockId, lockmode +#define LWLOCK_RELEASE_START_DETAIL_BUFSIZE 15 +// type, timestamp +#define LWLOCK_RELEASE_END_DETAIL_BUFSIZE 9 +#define INVALID_DETAIL_BUFSIZE 0 + +#define STATEMENT_DETAIL_BUF_MULTI 10 +#define STATEMENT_DETAIL_BUF 256 + +#define STATEMENT_DETAIL_BUFSIZE 4096 +struct StatementDetailItem { + void *next; /* next item */ + char buf[STATEMENT_DETAIL_BUFSIZE]; /* [version, [LOCK_START, timestamp, locktag, lockmode], [...]] */ +}; + +struct StatementDetail { + int n_items; /* how many of detail items */ + uint32 cur_pos; /* the write position of the last item */ + StatementDetailItem *head; /* the first detail item. */ + StatementDetailItem *tail; /* the last detail item. */ +}; + +#define STATEMENT_DETAIL_VERSION 1 +#define STATEMENT_DETAIL_NOT_TRUNCATED 0 +#define STATEMENT_DETAIL_TRUNCATED 1 +#define STATEMENT_DETAIL_FORMAT_STRING "plaintext" +#define STATEMENT_DETAIL_FORMAT_JSON "json" +#define STATEMENT_DETAIL_TYPE_PRETTY "pretty" + +/* entry for full/slow sql stat */ +typedef struct StatementStatContext { + // GUC variant + char* schema_name; /* search path */ + char* application_name; /* workload identifier */ + StatLevel level; /* which level metrics to be collected base on GUC */ + + // variant, collect at commit handler + uint64 unique_query_id; /* from knl_u_unique_sql_context's unique_sql_id */ + uint64 debug_query_id; /* from knl_session_context's debug_query_id */ + uint32 unique_sql_cn_id; /* from knl_session_context's unique_sql_cn_id */ + char* query; /* from PgBackendStatus's st_activity + or knl_u_unique_sql_context's curr_single_unique_sql */ + TimestampTz start_time; /* from PgBackendStatus's st_activity_start_timestamp */ + TimestampTz finish_time; /* commit's GetCurrentTimestamp */ + int slow_query_threshold; /* from knl_session_attr_storage's log_min_duration_statement */ + + int64 timeModel[TOTAL_TIME_INFO_TYPES]; /* from knl_u_stat_context's localTimeInfoArray */ + int64 networkInfo[TOTAL_NET_INFO_TYPES]; /* from knl_u_stat_context's localNetInfo */ + UniqueSQLRowActivity row_activity; /* row activity */ + UniqueSQLCacheIO cache_io; /* cache/IO */ + + // variant, collect them during its progress + ThreadId tid; + TransactionId txn_id; + UniqueSQLParse parse; + char* query_plan; /* query plan */ + uint64 plan_size; + LockSummaryStat lock_summary; + StatementDetail details; +} StatementStatContext; +extern void StatementFlushMain(); +extern bool IsStatementFlushProcess(void); + +extern bool check_statement_stat_level(char** newval, void** extra, GucSource source); +extern void assign_statement_stat_level(const char* newval, void* extra); + +extern void statement_full_info_record( + StatementDetailType type, int lockmode = -1, const LOCKTAG *locktag = NULL, uint16 lwlockId = 0); +extern void instr_stmt_report_basic_info(); +extern void instr_stmt_report_stat_at_handle_commit(); +extern void instr_stmt_report_unique_sql_info(const PgStat_TableCounts *agg_table_stat, + const int64 timeInfo[], const uint64 *netInfo, const UniqueSQLParse *parse); +extern void instr_stmt_report_txid(uint64 txid); +extern void instr_stmt_report_query(uint64 unique_query_id); +extern void instr_stmt_report_query_plan(QueryDesc *queryDesc); +extern void instr_stmt_report_debug_query_id(uint64 debug_query_id); +extern void instr_stmt_report_start_time(); +extern void instr_stmt_report_finish_time(); +extern text *get_statement_detail(StatementDetail *text); +extern char *decode_statement_detail_text(text *details, const char *format, bool pretty); + +#endif + diff -uprN postgresql-hll-2.14_old/include/instruments/instr_unique_sql.h postgresql-hll-2.14/include/instruments/instr_unique_sql.h --- postgresql-hll-2.14_old/include/instruments/instr_unique_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_unique_sql.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,192 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_unique_sql.h + * definitions for unique sql + * + * + * IDENTIFICATION + * src/include/instruments/instr_unique_sql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_UNIQUE_SQL_H +#define INSTR_UNIQUE_SQL_H + +#include "nodes/parsenodes.h" +#include "pgstat.h" +#include "instruments/unique_sql_basic.h" + +typedef struct { + int64 total_time; /* total time for the unique sql entry */ + int64 min_time; /* min time for unique sql entry's history events */ + int64 max_time; /* max time for unique sql entry's history events */ +} UniqueSQLElapseTime; + +typedef struct UniqueSQLTime { + int64 TimeInfoArray[TOTAL_TIME_INFO_TYPES]; +} UniqueSQLTime; + +typedef struct UniqueSQLNetInfo { + uint64 netInfoArray[TOTAL_NET_INFO_TYPES]; +} UniqueSQLNetInfo; + +typedef struct { + UniqueSQLKey key; /* CN oid + user oid + unique sql id */ + + /* alloc extra UNIQUE_SQL_MAX_LEN space to store unique sql string */ + char* unique_sql; /* unique sql text */ + + pg_atomic_uint64 calls; /* calling times */ + UniqueSQLElapseTime elapse_time; /* elapst time stat in ms */ + TimestampTz updated_time; /* latest update time for the unique sql entry */ + UniqueSQLTime timeInfo; + UniqueSQLNetInfo netInfo; + + UniqueSQLRowActivity row_activity; /* row activity */ + UniqueSQLCacheIO cache_io; /* cache/IO */ + UniqueSQLParse parse; /* hard/soft parse counter */ + bool is_local; /* local sql(run from current node) */ +} UniqueSQL; + +/* Unique SQL track type */ +typedef enum { + UNIQUE_SQL_NONE = 0, + UNIQUE_SQL_TRACK_TOP, /* only top SQL will be tracked */ + UNIQUE_SQL_TRACK_ALL /* later maybe support parent and child SQLs */ +} UniqueSQLTrackType; + +typedef struct { + int64* timeInfo; + uint64* netInfo; +} UniqueSQLStat; + +extern int GetUniqueSQLTrackType(); + +#define UniqueSQLStatCountReturnedRows(n) \ + if ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_returned_rows_counter += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %lu returned rows", \ + u_sess->unique_sql_cxt.unique_sql_id, \ + (uint64)n))); \ + } + +#define UniqueSQLStatCountResetReturnedRows() \ + if ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_returned_rows_counter = 0); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: reset returned rows", u_sess->unique_sql_cxt.unique_sql_id))); \ + } + +#define UniqueSQLStatCountSoftParse(n) \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_soft_parse += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %d soft parse", u_sess->unique_sql_cxt.unique_sql_id, n))); \ + } + +#define UniqueSQLStatCountHardParse(n) \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_hard_parse += n); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: %d hard parse", u_sess->unique_sql_cxt.unique_sql_id, n))); \ + } + +#define UniqueSQLStatCountResetParseCounter() \ + if (is_unique_sql_enabled()) { \ + (u_sess->unique_sql_cxt.unique_sql_soft_parse = 0); \ + (u_sess->unique_sql_cxt.unique_sql_hard_parse = 0); \ + ereport(DEBUG1, \ + (errmodule(MOD_INSTR), \ + errmsg("[UniqueSQL] unique id: %lu: reset parse counter", u_sess->unique_sql_cxt.unique_sql_id))); \ + } + +#define UniqueSQLSumTableStatCounter(A, B) \ + if (IS_PGXC_DATANODE && is_unique_sql_enabled()) { \ + A.t_tuples_returned += B.t_tuples_returned; \ + A.t_tuples_fetched += B.t_tuples_fetched; \ + A.t_tuples_inserted += B.t_tuples_inserted; \ + A.t_tuples_updated += B.t_tuples_updated; \ + A.t_tuples_deleted += B.t_tuples_deleted; \ + A.t_blocks_fetched += B.t_blocks_fetched; \ + A.t_blocks_hit += B.t_blocks_hit; \ + } + +#define UniqueSQLDiffTableStatCounter(A, B, C) \ + if (IS_PGXC_DATANODE && is_unique_sql_enabled()) { \ + A.t_tuples_returned = B.t_tuples_returned - C.t_tuples_returned; \ + A.t_tuples_fetched = B.t_tuples_fetched - C.t_tuples_fetched; \ + A.t_tuples_inserted = B.t_tuples_inserted - C.t_tuples_inserted; \ + A.t_tuples_updated = B.t_tuples_updated - C.t_tuples_updated; \ + A.t_tuples_deleted = B.t_tuples_deleted - C.t_tuples_deleted; \ + A.t_blocks_fetched = B.t_blocks_fetched - C.t_blocks_fetched; \ + A.t_blocks_hit = B.t_blocks_hit - C.t_blocks_hit; \ + } + +#define IS_UNIQUE_SQL_TRACK_TOP ((IS_PGXC_COORDINATOR || IS_SINGLE_NODE) && GetUniqueSQLTrackType() == UNIQUE_SQL_TRACK_TOP) + +#define INIT_UNIQUE_SQL_CXT() \ + bool old_is_top_unique_sql = false; \ + uint64 old_unique_sql_id = 0; + +#define BACKUP_UNIQUE_SQL_CXT() \ + old_is_top_unique_sql = IsTopUniqueSQL(); \ + if (old_is_top_unique_sql) { \ + SetIsTopUniqueSQL(false); \ + old_unique_sql_id = u_sess->unique_sql_cxt.unique_sql_id; \ + } + +#define RESTORE_UNIQUE_SQL_CXT() \ + if (old_is_top_unique_sql) { \ + SetIsTopUniqueSQL(true); \ + u_sess->unique_sql_cxt.unique_sql_id = old_unique_sql_id; \ + } + +void InitUniqueSQL(); +void UpdateUniqueSQLStat(Query* query, const char* sql, int64 elapse_start_time, + PgStat_TableCounts* agg_table_count = NULL, UniqueSQLStat* sql_stat = NULL); +void ResetUniqueSQLString(); + +void instr_unique_sql_register_hook(); +void SetUniqueSQLIdFromPortal(Portal portal, CachedPlanSource* unnamedPsrc); +void SetUniqueSQLIdFromCachedPlanSource(CachedPlanSource* cplan); + +void ReplyUniqueSQLsStat(StringInfo msg, uint32 count); + +void PrintPgStatTableCounter(char type, PgStat_TableCounts* stat); +void UpdateUniqueSQLStatOnRemote(); + +bool is_unique_sql_enabled(); + +bool IsNeedUpdateUniqueSQLStat(Portal portal); + +void SetIsTopUniqueSQL(bool value); +bool IsTopUniqueSQL(); + +bool is_local_unique_sql(); +bool need_normalize_unique_string(); +bool need_update_unique_sql_row_stat(); +void ResetCurrentUniqueSQL(bool need_reset_cn_id = false); +bool isUniqueSQLContextInvalid(); +void UpdateSingleNodeByPassUniqueSQLStat(bool isTopLevel); +void FindUniqueSQL(UniqueSQLKey key, char* unique_sql); +char* FindUniqueSQL(const UniqueSQLKey key); +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_user.h postgresql-hll-2.14/include/instruments/instr_user.h --- postgresql-hll-2.14_old/include/instruments/instr_user.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_user.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_user.h + * definitions for user stat info + * + * + * IDENTIFICATION + * src/include/instruments/instr_user.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_USER_H +#define INSTR_USER_H + +void InstrUpdateUserLogCounter(bool is_login); +void InitInstrUser(); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_waitevent.h postgresql-hll-2.14/include/instruments/instr_waitevent.h --- postgresql-hll-2.14_old/include/instruments/instr_waitevent.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_waitevent.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,29 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_waitevent.h + * definitions for wait event stat + * + * + * IDENTIFICATION + * src/include/instruments/instr_waitevent.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_WAITEVENT_H +#define INSTR_WAITEVENT_H + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/instr_workload.h postgresql-hll-2.14/include/instruments/instr_workload.h --- postgresql-hll-2.14_old/include/instruments/instr_workload.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/instr_workload.h 2020-12-12 17:06:43.307348813 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * instr_workload.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/instr_workload.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_WORKLOAD_H +#define INSTR_WORKLOAD_H +#include "c.h" +#include "utils/timestamp.h" +#include "utils/syscache.h" + +typedef struct StatData { + TimestampTz max; + TimestampTz min; + TimestampTz average; + TimestampTz total; +} StatData; + +typedef struct WLMTransactonInfo { + uint64 commit_counter; + uint64 rollback_counter; + StatData responstime; +} WLMTransactionInfo; + +typedef struct WLMWorkLoadKey { + Oid user_id; +} WLMWorkLoadKey; + +typedef struct WorkloadXactInfo { + // WLMWorkLoadKey wlkey; + Oid user_id; + WLMTransactionInfo transaction_info; + WLMTransactionInfo bg_xact_info; +} WorkloadXactInfo; + +extern void InitInstrWorkloadTransaction(void); +extern void InitInstrOneUserTransaction(Oid userId); +extern void instr_report_workload_xact_info(bool isCommit); +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/list.h postgresql-hll-2.14/include/instruments/list.h --- postgresql-hll-2.14_old/include/instruments/list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/list.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,46 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * list.h + * definitions for instruments workload + * + * + * IDENTIFICATION + * src/include/instruments/list.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIST_H +#define LIST_H +#include "c.h" +#include "lib/stringinfo.h" +/* top dn info*/ +typedef struct WLMTopDnInfo { + char nodeName[NAMEDATALEN]; + int64 data; +} WLMTopDnInfo; + +/* list of top dn*/ +typedef struct WLMTopDnList { + WLMTopDnInfo topDn; + WLMTopDnList* nextTopDn; +} WLMTopDnList; + +void InsertElemSortTopN(WLMTopDnList** head, WLMTopDnList** elem, int topN); +void DeleteList(WLMTopDnList** head); +void GetTopNInfo(WLMTopDnList* head, char name[][NAMEDATALEN], int* values, int topN); +void GetTopNInfoJsonFormat(StringInfoData topNstr, char nodeName[][NAMEDATALEN], int* value, int topN); +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/percentile.h postgresql-hll-2.14/include/instruments/percentile.h --- postgresql-hll-2.14_old/include/instruments/percentile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/percentile.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * percentile.h + * Definitions for the PostgreSQL statistics collector daemon. + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/instruments/percentile.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PERCENTILE_H +#define PERCENTILE_H +#include "gs_thread.h" + +extern void PercentileMain(); +extern void JobPercentileIAm(void); +extern bool IsJobPercentileProcess(void); +extern void InitPercentile(void); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/instruments/snapshot.h postgresql-hll-2.14/include/instruments/snapshot.h --- postgresql-hll-2.14_old/include/instruments/snapshot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/snapshot.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * snapshot.h + * definitions for WDR snapshot. + * + * + * By default, the snapshot thread collects database statistics + * from the views in dbe_perf schema in one hour, + * and insert these data into the corresponding tables in the snapshot schema. + * The WDR report generates a performance diagnosis report + * based on the data collected by the snapshot thread. + * + * IDENTIFICATION + * src/include/instruments/snapshot.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef INSTR_SNAPSHOT_H +#define INSTR_SNAPSHOT_H +#include "gs_thread.h" + +extern ThreadId snapshot_start(void); +extern void SnapshotMain(); +extern Datum create_wdr_snapshot(PG_FUNCTION_ARGS); + +extern void JobSnapshotIAm(void); +extern bool IsJobSnapshotProcess(void); +extern THR_LOCAL bool am_job_snapshot; +extern THR_LOCAL bool operate_snapshot_tables; + +extern Datum GetDatumValue(const char* query, uint32 row, uint32 col, bool* isnull = NULL); + +extern void instrSnapshotClean(void); + +extern void instrSnapshotCancel(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/unique_query.h postgresql-hll-2.14/include/instruments/unique_query.h --- postgresql-hll-2.14_old/include/instruments/unique_query.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/unique_query.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * unique_query.h + * definitions for unique query + * + * + * IDENTIFICATION + * src/include/instruments/unique_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _QUERYID_ +#define _QUERYID_ + +#include "nodes/parsenodes.h" +#include "c.h" + +extern uint32 generate_unique_queryid(Query* query, const char* query_string); +extern bool normalized_unique_querystring(Query* query, const char* query_string, char* unique_string, int len); + +#endif diff -uprN postgresql-hll-2.14_old/include/instruments/unique_sql_basic.h postgresql-hll-2.14/include/instruments/unique_sql_basic.h --- postgresql-hll-2.14_old/include/instruments/unique_sql_basic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/instruments/unique_sql_basic.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,33 @@ +#ifndef UNIQUE_SQL_BASIC_H +#define UNIQUE_SQL_BASIC_H + +typedef struct { + uint32 cn_id; /* SQL is run on which CN node, + * same with node_id in PGXC_NODE */ + Oid user_id; /* user id */ + uint64 unique_sql_id; /* unique sql id */ +} UniqueSQLKey; + +typedef struct { + pg_atomic_uint64 soft_parse; /* reuse plan counter */ + pg_atomic_uint64 hard_parse; /* new generated plan counter */ +} UniqueSQLParse; + +typedef struct { + pg_atomic_uint64 returned_rows; /* select SQL returned rows */ + + pg_atomic_uint64 tuples_fetched; /* randowm IO */ + pg_atomic_uint64 tuples_returned; /* sequence IO */ + + pg_atomic_uint64 tuples_inserted; /* inserted tuples counter */ + pg_atomic_uint64 tuples_updated; /* updated tuples counter */ + pg_atomic_uint64 tuples_deleted; /* deleted tuples counter */ +} UniqueSQLRowActivity; + +typedef struct { + pg_atomic_uint64 blocks_fetched; /* the blocks fetched times */ + pg_atomic_uint64 blocks_hit; /* the blocks hit times in buffer */ +} UniqueSQLCacheIO; + +#endif + diff -uprN postgresql-hll-2.14_old/include/iprange/iprange.h postgresql-hll-2.14/include/iprange/iprange.h --- postgresql-hll-2.14_old/include/iprange/iprange.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/iprange/iprange.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,194 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * iprange.h + * define operation functions for ip type data + * + * IDENTIFICATION + * src/include/iprange/iprange.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef IPRANGE_AUDIT_H_ +#define IPRANGE_AUDIT_H_ + +#include +#include +#include +#include + +typedef unsigned char ipv6arr[16]; + +typedef struct IPV6_64_s +{ + uint64_t lower; + uint64_t upper; +} IPV6_64; + +typedef struct IPV6_32_s +{ + uint32_t a; + uint32_t b; + uint32_t c; + uint32_t d; +} IPV6_32; + +typedef union IPV6_s +{ + IPV6_64 ip_64; + IPV6_32 ip_32; +} IPV6; + +inline bool operator< (const IPV6 lhs, const IPV6 rhs){ return lhs.ip_64.upper < rhs.ip_64.upper || lhs.ip_64.lower < rhs.ip_64.lower; } +inline bool operator> (const IPV6 lhs, const IPV6 rhs){ return rhs < lhs; } +inline bool operator<=(const IPV6 lhs, const IPV6 rhs){ return !(lhs > rhs); } +inline bool operator>=(const IPV6 lhs, const IPV6 rhs){ return !(lhs < rhs); } + +inline const IPV6 operator~(const IPV6 ip) +{ + IPV6 new_ip; + new_ip.ip_64.lower = ~ip.ip_64.lower; + new_ip.ip_64.upper = ~ip.ip_64.upper; + return new_ip; +} + +inline bool operator==(const IPV6 lhs, const IPV6 rhs) +{ + return lhs.ip_64.lower == rhs.ip_64.lower && lhs.ip_64.upper == rhs.ip_64.upper; +} + +inline const IPV6 operator+(const IPV6 lhs, const IPV6 rhs) +{ + uint64_t tmp; + IPV6 new_ip {0,0}; + + if (lhs.ip_32.b == 0x0000FFFF) { + new_ip.ip_32.a = lhs.ip_32.a + rhs.ip_32.a; + new_ip.ip_32.b = 0x0000FFFF; + return new_ip; + } + + new_ip.ip_32.a = tmp = ((int64_t)lhs.ip_32.a) + rhs.ip_32.a; + new_ip.ip_32.b = tmp = ((int64_t)lhs.ip_32.b) + rhs.ip_32.b + (tmp >> 32); + new_ip.ip_32.c = tmp = ((int64_t)lhs.ip_32.c) + rhs.ip_32.c + (tmp >> 32); + new_ip.ip_32.d = ((int64_t)lhs.ip_32.d) + rhs.ip_32.d + (tmp >> 32); + return new_ip; +} + +inline const IPV6 operator+(const IPV6 lhs, const int i) +{ + IPV6 new_ip {0,0}; + new_ip.ip_64.lower = i; + return lhs + new_ip; +} + +inline const IPV6 operator-(const IPV6 lhs, const IPV6 rhs) +{ + if (lhs.ip_32.b == 0x0000FFFF) { + IPV6 new_ip {0,0}; + new_ip.ip_32.a = lhs.ip_32.a - rhs.ip_32.a; + new_ip.ip_32.b = 0x0000FFFF; + return new_ip; + } + + uint64_t tmp; + IPV6 new_ip {0,0}; + new_ip.ip_32.a = tmp = ((int64_t)lhs.ip_32.a) - rhs.ip_32.a; + new_ip.ip_32.b = tmp = ((int64_t)lhs.ip_32.b) - rhs.ip_32.b - (tmp>>63); + new_ip.ip_32.c = tmp = ((int64_t)lhs.ip_32.c) - rhs.ip_32.c - (tmp>>63); + new_ip.ip_32.d = ((int64_t)lhs.ip_32.d) - rhs.ip_32.d - (tmp>>63); + return new_ip; +} + +inline const IPV6 operator-(const IPV6 lhs, const int i) +{ + IPV6 new_ip {0,0}; + new_ip.ip_64.lower = i; + return lhs - new_ip; +} + +inline const IPV6 operator&(const IPV6 lhs, const IPV6 rhs) +{ + IPV6 new_ip; + new_ip.ip_64.lower = lhs.ip_64.lower & rhs.ip_64.lower; + new_ip.ip_64.upper = lhs.ip_64.upper & rhs.ip_64.upper; + return new_ip; +} + +inline const IPV6 operator|(const IPV6 lhs, const IPV6 rhs) +{ + IPV6 new_ip; + new_ip.ip_64.lower = lhs.ip_64.lower | rhs.ip_64.lower; + new_ip.ip_64.upper = lhs.ip_64.upper | rhs.ip_64.upper; + return new_ip; +} + +typedef struct Range_s +{ + Range_s(const IPV6 _from = IPV6(), const IPV6 _to = IPV6()):from(_from), to(_to){} + IPV6 from; + IPV6 to; +} Range; + +class IPRange +{ +public: + + IPRange(); + ~IPRange(); + + static bool is_range_valid(const std::string range); + bool add_ranges(const std::unordered_set ranges); + bool add_range(Range *new_range); + bool add_range(const char *range, size_t range_len); + bool remove_ranges(const std::unordered_set ranges); + bool remove_range(const char *range, size_t range_len); + std::unordered_set get_ranges_set(); + + bool is_in_range(const char *ip_str); + bool is_in_range(const IPV6 *ip); + bool is_in_range(const uint32_t ipv4); + bool is_intersect(const IPRange *arg); + bool empty() const; + + const std::string& get_err_str() { return m_err_str; } + void print_ranges(); + std::string ip_to_str(const IPV6 *ip) const; + bool str_to_ip(const char* ip_str, IPV6 *ip); +private: + + typedef std::vector Ranges_t; + Ranges_t m_ranges; + std::string m_err_str; + + bool parse_range(const char* range, size_t range_len, Range *new_range); + bool parse_slash(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_hyphen(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_mask(const char* range, size_t range_len, const char *ptr, Range *new_range); + bool parse_single(const char* range, size_t range_len, Range *new_range); + bool binary_search(const IPV6 ip) const; + + bool mask_range(Range *range, unsigned short cidr); + void handle_remove_intersection(Ranges_t *new_ranges, const Range *remove_range, Range *exist_range); + bool handle_add_intersection(Range *new_range, const Range *exist_range); + void print_range(const Range *range); + void copy_without_spaces(char buf[], size_t buf_len, const char *original, size_t original_len) const; + void net_ipv6_to_host_order(IPV6 *ip, const struct sockaddr_in6 *sa) const; + void net_ipv4_to_host_order(IPV6 *ip, const struct in_addr *addr) const; + +}; + +#endif // IPRANGE_AUDIT_H_ diff -uprN postgresql-hll-2.14_old/include/job/job_scheduler.h postgresql-hll-2.14/include/job/job_scheduler.h --- postgresql-hll-2.14_old/include/job/job_scheduler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/job/job_scheduler.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,73 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_scheduler.h + * declare functions and guc variables for external + * + * + * IDENTIFICATION + * src/include/job/job_scheduler.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_SCHEDULER_H +#define JOB_SCHEDULER_H + +/* GUC variables */ +extern THR_LOCAL int job_queue_processes; +#define DEFAULT_JOB_QUEUE_PROCESSES 10 +#define MIN_JOB_QUEUE_PROCESSES 0 +#define MAX_JOB_QUEUE_PROCESSES 1000 + +/* Job info define */ +typedef struct JobInfoData { + int4 job_id; + Oid job_oid; + Oid job_dboid; + NameData log_user; + NameData node_name; + TimestampTz last_start_date; /* arrange jobs in last_start_date order */ +} JobInfoData; + +typedef struct JobInfoData* JobInfo; + +/***************************************************************************** + Description : shared memory size. +*****************************************************************************/ +extern Size JobInfoShmemSize(void); + +/***************************************************************************** + Description : init shared memory +*****************************************************************************/ +extern void JobInfoShmemInit(void); + +/***************************************************************************** + Description : start job scheduler process. +*****************************************************************************/ +extern ThreadId StartJobScheduler(void); + +/***************************************************************************** + Description : +*****************************************************************************/ +extern void JobScheduleMain(); + +/* Status inquiry functions */ +extern bool IsJobSchedulerProcess(void); + +/* called from postmaster when a worker could not be forked */ +extern void RecordForkJobWorkerFailed(void); + +#endif /* JOB_SCHEDULER_H */ diff -uprN postgresql-hll-2.14_old/include/job/job_shmem.h postgresql-hll-2.14/include/job/job_shmem.h --- postgresql-hll-2.14_old/include/job/job_shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/job/job_shmem.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_shmem.h + * define the shared memory for jobs. + * + * + * IDENTIFICATION + * src/include/job/job_shmem.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_SHMEM_H +#define JOB_SHMEM_H +#include "postgres.h" +#include "knl/knl_variable.h" +#include "catalog/genbki.h" +#include "storage/shmem.h" +#include "utils/timestamp.h" + +/* Job worker info define */ +typedef struct JobWorkerInfoData { + SHM_QUEUE job_links; + ThreadId job_worker_pid; + int4 job_id; + Oid job_oid; + Oid job_dboid; + NameData username; + TimestampTz job_launchtime; +} JobWorkerInfoData; + +typedef struct JobWorkerInfoData* JobWorkerInfo; + +/* shared memeory define */ +typedef enum JobShmemE { + ForkJobWorkerFailed, + JobScheduleSignalNum /* must be last */ +} JobShmemE; + +typedef struct JobScheduleShmemStruct { + sig_atomic_t jsch_signal[JobScheduleSignalNum]; + ThreadId jsch_pid; + JobWorkerInfo jsch_freeWorkers; + SHM_QUEUE jsch_runningWorkers; + JobWorkerInfo jsch_startingWorker; +} JobScheduleShmemStruct; + +#endif /* JOB_SHMEM_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/job/job_worker.h postgresql-hll-2.14/include/job/job_worker.h --- postgresql-hll-2.14_old/include/job/job_worker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/job/job_worker.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * job_worker.h + * declare functions for external + * + * + * IDENTIFICATION + * src/include/job/job_worker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef JOB_WORKER_H +#define JOB_WORKER_H + +/***************************************************************************** + Description : start job worker process. +*****************************************************************************/ +extern ThreadId StartJobExecuteWorker(void); +extern void JobExecuteWorkerMain(); + +/* Status inquiry functions */ +extern bool IsJobWorkerProcess(void); + +#endif /* JOB_WORKER_H */ diff -uprN postgresql-hll-2.14_old/include/keymanagement/FIKMSmessage.h postgresql-hll-2.14/include/keymanagement/FIKMSmessage.h --- postgresql-hll-2.14_old/include/keymanagement/FIKMSmessage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/keymanagement/FIKMSmessage.h 2020-12-12 17:06:43.308348825 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * FIKMSmessage.h + * Processing of messages defined by FI KMS + * + * + * IDENTIFICATION + * src/include/keymanagement/FIKMSmessage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_FIKMSMESSAGE_H +#define SEC_KEY_FIKMSMESSAGE_H + +#include "cjson/cJSON.h" +#include + +/* The following values are defined by the RESTful interface of FI KMS */ +const char* const FIKMS_MESSAGE_name = "name"; +const char* const FIKMS_MESSAGE_cipher = "cipher"; +const char* const FIKMS_MESSAGE_length = "length"; +const char* const FIKMS_MESSAGE_material = "material"; +const char* const FIKMS_MESSAGE_number_of_keys_to_generate = "number_of_keys_to_generate"; +const char* const FIKMS_MESSAGE_key_name = "key-name"; +const char* const FIKMS_MESSAGE_versionname = "versionName"; +const char* const FIKMS_MESSAGE_iv = "iv"; +const char* const FIKMS_MESSAGE_encryptedKeyVersion = "encryptedKeyVersion"; +const char* const FIKMS_MESSAGE_exception = "RemoteException"; + +/* This class is used for FI KMS protocol parsing. */ +class FIKMSmessage { +public: + FIKMSmessage(); + ~FIKMSmessage(); + + /* Parsing JSON structure from string. */ + bool parser(std::string serizial_str); + + /* Use name, cipher, length to assemble the message needed by FI KMS.Returns the result of serialization of JSON + * information.*/ + std::string create(std::string name, std::string cipher, int length); + /* Use name, iv, material to assemble the message needed by FI KMS.Returns the result of serialization of JSON + * information.*/ + std::string create(std::string name, std::string iv, std::string material); + + /* Parsing Create CEK Messages. */ + bool parser_create_CEK(std::string& CEK_name); + /* Parsing Create DEK Messages. */ + bool parser_create_DEK(std::string& DEK_IV, std::string& DEK_cipher, std::string& CEK_versionname); + + /* Parsing gte DEK Messages. */ + bool parser_get_DEK(std::string& DEK); + /* Parsing get CEK Messages. */ + bool parser_get_CEK(const std::string& CEK_name); + +private: + cJSON* response_data; + bool is_exception(); +}; + +#endif // SEC_KEY_FIKMSMESSAGE_H diff -uprN postgresql-hll-2.14_old/include/keymanagement/HttpRestfulClient.h postgresql-hll-2.14/include/keymanagement/HttpRestfulClient.h --- postgresql-hll-2.14_old/include/keymanagement/HttpRestfulClient.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/keymanagement/HttpRestfulClient.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,58 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * HttpRestfulClient.h + * Implementation of Exchanging Data with FI KMS Restful API + * + * + * IDENTIFICATION + * src/include/keymanagement/HttpRestfulClient.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_HTTPRESTFULCLIENT_H +#define SEC_KEY_HTTPRESTFULCLIENT_H + +#include +#include +#include + +/* + * This class is used to complete the network connection and realize the transmission and reception of network data. + * Support GSS-Negotiate authentication. + */ +class HttpRestfulClient { +public: + HttpRestfulClient(); + ~HttpRestfulClient(); + std::string post(const char* res, const char* data, const long length); + std::string get(const char* res); + +private: + std::string host; + std::string port; + std::string http_protocol; + std::vector hosts; + bool is_ReportAlarmAbnormalKMSConnt; + CURL* curl; + CURLcode response_code; + struct curl_slist* headers; + + bool send(); + void update_kms_url(); +}; + +#endif // SEC_KEY_HTTPRESTFULCLIENT_H diff -uprN postgresql-hll-2.14_old/include/keymanagement/KeyManager.h postgresql-hll-2.14/include/keymanagement/KeyManager.h --- postgresql-hll-2.14_old/include/keymanagement/KeyManager.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/keymanagement/KeyManager.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,73 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * KeyManager.h + * TDE key management is the external interface of key management + * + * + * IDENTIFICATION + * src/include/keymanagement/KeyManager.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_KEYMANAGER_H +#define SEC_KEY_KEYMANAGER_H + +#include "TDEKeysFile.h" +enum TDE_KEY_STATUS { + CEK_NONE, + CEK_ERROR, + CEK_CREATED, + DEK_NONE, + DEK_ERROR, + DEK_CREATED, + DEK_IV_NONE, + DEK_IV_ERROR, + DEK_IV_CREATED, + KEY_NOT_INIT, + KEY_INITED +}; + +/* This class is used for key management */ +class KeyManager : public TDEKeysFile { +public: + KeyManager(const char* db_uid_in, const char* tb_uid_in); + virtual ~KeyManager(); + /* + * Initialization of key environment based on key algorithm and CEK key name. + * the algo and cekname come form user. + */ + bool init_Key(const char* algo, const char* cekname); + /* use default value init key environment.*/ + bool init_Key(); + + /* Checking whether DEK is correct will be judged by the saved encrypted_sample_string. */ + bool check_key(unsigned char* dek); + + std::string getDEK(); + TDE_KEY_STATUS getKey_status() const; + +private: + TDE_KEY_STATUS Key_status; + + bool createCEK(); + bool createDEK(); + + bool fill_Disk(); + bool read_Disk(); +}; + +#endif // SEC_KEY_KEYMANAGER_H diff -uprN postgresql-hll-2.14_old/include/keymanagement/KeyRecord.h postgresql-hll-2.14/include/keymanagement/KeyRecord.h --- postgresql-hll-2.14_old/include/keymanagement/KeyRecord.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/keymanagement/KeyRecord.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * KeyRecord.h + * encrypt and decrypt functions for MPPDB + * + * + * IDENTIFICATION + * src/include/keymanagement/KeyRecord.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_KEYRECORD_H +#define SEC_KEY_KEYRECORD_H + +#include + +const int TDE_IV_LEN = 16; + +enum TDE_ALGO { TDE_ALGO_SM4_CTR_128, TDE_ALGO_AES_CTR_128, TDE_ALGO_NULL }; + +class KeyRecord { + +public: + KeyRecord(); + virtual ~KeyRecord() = default; + + bool create_encrypted_sample_string(std::string dek_b64); + bool check_encrypted_sample_string(unsigned char* dek); + std::string getEncryptedSampleStr(); + + bool create_dek_iv(); + bool getIV(unsigned char* out_iv); + + TDE_ALGO get_tde_algo() const; + +protected: + std::string cek_name; + std::string cek_version; + std::string cek_IV; + std::string dek_cipher; + std::string db_uid; + std::string tb_uid; + std::string encrypted_sample_string; + unsigned char dek_iv[TDE_IV_LEN] = {}; + TDE_ALGO tde_algo; +}; + +#endif // SEC_KEY_KEYRECORD_H diff -uprN postgresql-hll-2.14_old/include/keymanagement/TDEKeysFile.h postgresql-hll-2.14/include/keymanagement/TDEKeysFile.h --- postgresql-hll-2.14_old/include/keymanagement/TDEKeysFile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/keymanagement/TDEKeysFile.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * TDEKeysFile.h + * encrypt and decrypt functions for MPPDB + * + * + * IDENTIFICATION + * src/include/keymanagement/TDEKeysFile.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SEC_KEY_TDEKEYSFILE_H +#define SEC_KEY_TDEKEYSFILE_H + +#include "KeyRecord.h" +#include + +#define TDE_KEYS_STORE_NAME "gs_tde_keys.cipher" + +class TDEKeysFile : public KeyRecord { +public: + TDEKeysFile(); + virtual ~TDEKeysFile(); + void setfile(const char* gausshome); + bool existed() const; + bool save(); + bool parser(); + void clear(); + +private: + std::string tde_keys_store_path; +}; + +#endif // SEC_KEY_TDEKEYSFILE_H diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_guc_common.h postgresql-hll-2.14/include/knl/knl_guc/knl_guc_common.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_guc_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_guc_common.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,75 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_guc_common.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_guc_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ + +#include "c.h" + +/* Configuration variables */ +#define MAX_GTM_HOST_NUM (8) +#ifdef ENABLE_MULTIPLE_NODES +#define GUC_MAX_REPLNODE_NUM (8) +#else +#define GUC_MAX_REPLNODE_NUM (9) +#endif + +#ifdef WIN32 +typedef unsigned __int64 GS_UINT64; +#else +typedef unsigned long long GS_UINT64; +#endif + +#if defined(__LP64__) || defined(__64BIT__) +typedef unsigned int GS_UINT32; + +typedef signed int GS_INT32; +#else +typedef unsigned long GS_UINT32; + +typedef signed long GS_INT32; +#endif + +typedef unsigned char GS_UCHAR; + +const int GTMOPTION_GTM = 0; +const int GTMOPTION_GTMLITE = 1; +const int GTMOPTION_GTMFREE = 2; +const int GTM_OLD_VERSION_NUM = 92061; +const int SLOW_QUERY_VERSION = 92089; +const int STATEMENT_TRACK_VERSION = 92277; +#endif /* SRC_INCLUDE_KNL_KNL_GUC_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_common.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_common.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_common.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,96 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_common.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_common { + bool support_extended_features; + bool lastval_supported; +#ifdef USE_BONJOUR + bool enable_bonjour; +#endif + bool Logging_collector; + bool allowSystemTableMods; + bool enable_thread_pool; + bool enable_global_plancache; + int max_files_per_process; + int pgstat_track_activity_query_size; + int GtmHostPortArray[MAX_GTM_HOST_NUM]; + int MaxDataNodes; + int max_changes_in_memory; + int max_cached_tuplebufs; +#ifdef USE_BONJOUR + char* bonjour_name; +#endif + char* shared_preload_libraries_string; + char* event_source; + char* data_directory; + char* ConfigFileName; + char* HbaFileName; + char* IdentFileName; + char* external_pid_file; + char* PGXCNodeName; + char* transparent_encrypt_kms_url; + char* thread_pool_attr; + char* numa_distribute_mode; + + bool data_sync_retry; + + bool enable_alarm; + char* Alarm_component; + bool enable_tsdb; + char* Perf_directory; + char* asp_log_directory; + char* query_log_directory; + int asp_sample_num; + + /* + * guc - bbox_blacklist_items + * char* : original value + * uint64 : parsed bits mask + */ + char* bbox_blacklist_items; + uint64 bbox_blacklist_mask; +#ifdef ENABLE_MOT + char* MOTConfigFileName; +#endif +} knl_instance_attr_common; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_memory.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_memory.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_memory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_memory.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_memory.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_memory.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_memory { + bool memorypool_enable; + bool enable_memory_limit; + int memorypool_size; + int max_process_memory; + int local_syscache_threshold; +} knl_instance_attr_memory; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_MEMORY_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_network.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_network.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_network.h 2020-12-12 17:06:43.309348838 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_network.h + * Data struct to store all knl_instance_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_network.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_network { + bool PoolerStatelessReuse; + bool comm_tcp_mode; + int MaxConnections; + int maxInnerToolConnections; + int ReservedBackends; + int PostPortNumber; + int Unix_socket_permissions; + int MaxPoolSize; + int PoolerPort; + int MaxCoords; + int comm_sctp_port; + int comm_control_port; + int comm_quota_size; + int comm_usable_memory; + int comm_memory_pool; + int comm_memory_pool_percent; + int comm_max_stream; + int comm_max_receiver; + int cn_send_buffer_size; + char* Unix_socket_group; + char* UnixSocketDir; + char* ListenAddresses; + char* tcp_link_addr; +} knl_instance_attr_network; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_NETWORK_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_resource.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_resource.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_resource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_resource.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_resource.h + * Data struct to store all knl_instance_attr_resource GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_resource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_resource { + bool enable_dynamic_workload; + bool enable_backend_control; + bool enable_vacuum_control; + bool enable_perm_space; +} knl_instance_attr_resource; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_RESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_security.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_security.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_security.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_security.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_security.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_security.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_security { + bool EnableSSL; + bool enablePrivilegesSeparate; + bool enable_nonsysadmin_execute_direct; + char* ssl_cert_file; + char* ssl_key_file; + char* ssl_ca_file; + char* ssl_crl_file; + char* SSLCipherSuites; + char* Audit_directory; + char* Audit_data_format; + char* transparent_encrypted_string; + char* transparent_encrypt_kms_region; + bool use_elastic_search; + char* elastic_search_ip_addr; +} knl_instance_attr_security; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SECURITY_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_sql.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_sql.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_sql.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,56 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_sql.h + * Data struct to store all knl_instance_attr_sql GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_sql.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_sql { + bool string_hash_compatible; + bool enable_acceleration_cluster_wlm; + bool enable_orc_cache; + bool enable_default_cfunc_libpath; + int udf_memory_limit; + int UDFWorkerMemHardLimit; + int job_queue_processes; + int max_compile_functions; + int max_resource_package; +} knl_instance_attr_sql; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_SQL */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_storage.h postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_storage.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_instance_attr_storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_instance_attr_storage.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,98 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance_attr_storage.h + * Data struct to store all knl_instance_attr_storage GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_instance_attr_storage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_instance_attr_storage { + bool wal_log_hints; + bool EnableHotStandby; + bool enable_mix_replication; + bool IsRoachStandbyCluster; + bool enable_gtm_free; + bool comm_cn_dn_logic_conn; + bool enable_adio_function; + bool enable_access_server_directory; + bool enableIncrementalCheckpoint; + bool enable_double_write; + bool enable_delta_store; + bool enableWalLsnCheck; + int WalReceiverBufSize; + int DataQueueBufSize; + int NBuffers; + int cstore_buffers; + int MaxSendSize; + int max_prepared_xacts; + int max_locks_per_xact; + int max_predicate_locks_per_xact; + int64 xlog_idle_flushes_before_sleep; + int num_xloginsert_locks; + int wal_writer_cpu; + int xlog_flush_uplimit; + int wal_file_init_num; + int XLOGbuffers; + int max_wal_senders; + int max_replication_slots; + int replication_type; + int autovacuum_max_workers; + int64 autovacuum_freeze_max_age; + int wal_level; + /* User specified maximum number of recovery threads. */ + int max_recovery_parallelism; + int recovery_parse_workers; + int recovery_redo_workers_per_paser_worker; + int pagewriter_thread_num; + int bgwriter_thread_num; + int real_recovery_parallelism; + int batch_redo_num; + int remote_read_mode; + int advance_xlog_file_num; + int gtm_option; + int enable_update_max_page_flush_lsn; + int max_keep_log_seg; + int catchup2normal_wait_time; +#ifdef EXTREME_RTO_DEBUG_AB + int extreme_rto_ab_pos; + int extreme_rto_ab_type; + int extreme_rto_ab_count; +#endif + char* available_zone; +} knl_instance_attr_storage; + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_common.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_common.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_common.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,208 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_common.h + * Data struct to store all knl_session_attr_common GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_common.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_common { + bool enable_beta_features; + bool session_auth_is_superuser; + bool ignore_checksum_failure; + bool log_checkpoints; + bool Log_disconnections; + bool ExitOnAnyError; + bool omit_encoding_error; + bool log_parser_stats; + bool log_planner_stats; + bool log_executor_stats; + bool log_statement_stats; + bool pgstat_track_activities; + bool pgstat_track_counts; + bool pgstat_track_sql_count; + bool track_io_timing; + bool update_process_title; + bool pooler_cache_connection; + bool Trace_notify; + bool log_hostname; + bool XactReadOnly; + bool Log_truncate_on_rotation; + bool trace_sort; + bool integer_datetimes; + bool XLogArchiveMode; + bool IsInplaceUpgrade; + bool allow_concurrent_tuple_update; + bool IgnoreSystemIndexes; + bool PersistentConnections; + bool xc_maintenance_mode; + bool enable_redistribute; + bool check_implicit_conversions_for_indexcol; + bool support_batch_bind; + int XLogArchiveTimeout; + int Log_file_mode; + int bbox_dump_count; + int session_sequence_cache; + int max_stack_depth; + int max_query_retry_times; + int StatementTimeout; + int SessionTimeout; + int pgstat_collect_thread_status_interval; + int extra_float_digits; + int effective_io_concurrency; + int backend_flush_after; + int Log_RotationAge; + int Log_RotationSize; + int max_function_args; + int max_user_defined_exception; + int tcp_keepalives_idle; + int tcp_keepalives_interval; + int tcp_keepalives_count; + int GinFuzzySearchLimit; + int server_version_num; + int log_temp_files; + int transaction_sync_naptime; + int ngram_gram_size; + int gtm_connect_timeout; + int gtm_rw_timeout; + int transaction_sync_timeout; + int fault_mon_timeout; + double ConnectionAlarmRate; + char* client_encoding_string; + char* Log_line_prefix; + char* log_timezone_string; + char* datestyle_string; + char* Dynamic_library_path; + char* locale_collate; + char* locale_ctype; + char* locale_messages; + char* locale_monetary; + char* locale_numeric; + char* locale_time; + char* local_preload_libraries_string; + char* current_logic_cluster_name; + char* node_group_mode; + char* namespace_search_path; + char* nls_timestamp_format_string; + char* namespace_current_schema; + char* server_encoding_string; + char* server_version_string; + char* role_string; + char* session_authorization_string; + char* log_destination_string; + char* Log_directory; + char* asp_flush_mode; + char* asp_log_filename; + char* Perf_log; + char* Log_filename; + char* query_log_file; + char* syslog_ident_str; + char* timezone_string; + struct pg_tz* session_timezone; + struct pg_tz* log_timezone; + char* timezone_abbreviations_string; + char* pgstat_temp_directory; + char* TSCurrentConfig; + char* GtmHostInfoStringArray[MAX_GTM_HOST_NUM]; + struct tagGtmHostIP* GtmHostArray[MAX_GTM_HOST_NUM]; + int GtmHostIPNumArray[MAX_GTM_HOST_NUM]; + char* test_param_str; + char* application_name; + char* analysis_options; + int bytea_output; + int DefaultXactIsoLevel; + int IntervalStyle; + int Log_error_verbosity; + int backtrace_min_messages; + int client_min_messages; + int log_min_messages; + int log_min_error_statement; + int log_statement; + int syslog_facility; + int SessionReplicationRole; + int trace_recovery_messages; + int pgstat_track_functions; + int xmlbinary; + int remoteConnType; + + bool enable_bbox_dump; + char* bbox_dump_path; + + bool assert_enabled; + int AlarmReportInterval; + int xmloption; + bool enable_ts_compaction; + bool ts_adaptive_threads; + char* ts_compaction_strategy; + int ts_consumer_workers; + + /* instrumentation guc parameters */ + int instr_unique_sql_count; + bool enable_instr_cpu_timer; + int unique_sql_track_type; + bool enable_instr_track_wait; + bool enable_slow_query_log; + + int instr_rt_percentile_interval; + bool enable_instr_rt_percentile; + char* percentile_values; + + /* instr - full sql/slow sql */ + bool enable_stmt_track; + int track_stmt_session_slot; + char *track_stmt_stat_level; + int64 track_stmt_details_size; + char* track_stmt_retention_time; + + bool enable_wdr_snapshot; + bool enable_asp; + int wdr_snapshot_interval; + int wdr_snapshot_retention_days; + int asp_sample_interval; + int asp_flush_rate; + int asp_retention_days; + int max_datanode_for_plan; + int upgrade_mode; + int wdr_snapshot_query_timeout; + int dn_heartbeat_interval; + bool enable_full_encryption; + + char* router_att; + bool enable_router; +} knl_session_attr_common; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_COMMON_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_memory.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_memory.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_memory.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_memory.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_memory.h + * knl_session_attr_memory.h + * Data struct to store all knl_session_attr_memory GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_memory.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_memory { + bool enable_memory_context_control; + bool disable_memory_protect; + int work_mem; + int maintenance_work_mem; + char* memory_detail_tracking; + char* uncontrolled_memory_context; + int memory_tracking_mode; +} knl_session_attr_memory; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_MEMORY_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_network.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_network.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_network.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_network.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_network.h + * Data struct to store all knl_session_attr_network GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_network.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_network { + bool PoolerForceReuse; + bool comm_debug_mode; + bool comm_stat_mode; + bool comm_timer_mode; + bool comm_no_delay; + int PoolerTimeout; + int MinPoolSize; + int PoolerMaxIdleTime; + int PoolerConnectMaxLoops; + int PoolerConnectIntervalTime; + int PoolerConnectTimeout; + int PoolerCancelTimeout; + int comm_max_datanode; +#ifdef LIBCOMM_SPEED_TEST_ENABLE + int comm_test_thread_num; + int comm_test_msg_len; + int comm_test_send_sleep; + int comm_test_send_once; + int comm_test_recv_sleep; + int comm_test_recv_once; +#endif +#ifdef LIBCOMM_FAULT_INJECTION_ENABLE + int comm_fault_injection; +#endif + bool comm_client_bind; + int comm_ackchk_time; +} knl_session_attr_network; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_NETWORK_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_resource.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_resource.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_resource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_resource.h 2020-12-12 17:06:43.310348851 +0800 @@ -0,0 +1,95 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_resource.h + * Data struct to store all knl_session_attr_resource GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_resource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_resource { +#ifdef BTREE_BUILD_STATS + bool log_btree_build_stats; +#endif +#ifdef TRACE_SYNCSCAN + bool trace_syncscan; +#endif + bool enable_cgroup_switch; + bool enable_resource_track; + bool enable_hotkeys_collection; + bool enable_verify_statements; + bool enable_force_memory_control; + bool enable_dywlm_adjust; + bool enable_resource_record; + bool enable_user_metric_persistent; + bool enable_instance_metric_persistent; + bool enable_logical_io_statistics; + bool enable_reaper_backend; + bool enable_transaction_parctl; + int max_active_statements; + int dynamic_memory_quota; + int memory_fault_percent; + int parctl_min_cost; + int resource_track_cost; + int resource_track_duration; + int user_metric_retention_time; + int topsql_retention_time; + int unique_sql_retention_time; + int instance_metric_retention_time; + int cpu_collect_timer; + int iops_limits; + int autovac_iops_limits; + int io_control_unit; + int transaction_pending_time; + char* cgroup_name; + char* query_band; + char* session_resource_pool; + int resource_track_level; + int io_priority; + bool use_workload_manager; + bool enable_control_group; + + /* GUC variable for session statistics memory */ + int session_statistics_memory; + /* GUC variable for session history memory */ + int session_history_memory; + bool bypass_workload_manager; + /* sql_use_spacelimit */ + int sqlUseSpaceLimit; + bool enable_auto_explain; + int auto_explain_level; +} knl_session_attr_resource; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_RESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_security.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_security.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_security.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_security.h 2020-12-12 17:06:43.311348864 +0800 @@ -0,0 +1,91 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_security.h + * Data struct to store all knl_session_attr_security GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_security.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_security { + bool RequireSSL; + bool zero_damaged_pages; + bool pg_krb_caseins_users; + bool Audit_enabled; + bool Audit_CleanupPolicy; + bool Modify_initial_password; + bool operation_mode; + int PostAuthDelay; + int AuthenticationTimeout; + int PreAuthDelay; + int ssl_renegotiation_limit; + int ssl_cert_notify_time; + int Password_policy; + int Password_encryption_type; + int Password_reuse_max; + int Failed_login_attempts; + int Password_min_upper; + int Password_min_lower; + int Password_min_digital; + int Password_min_special; + int Password_min_length; + int Password_max_length; + int Password_notify_time; + int Audit_RotationAge; + int Audit_RotationSize; + int Audit_SpaceLimit; + int Audit_RemainAge; + int Audit_RemainThreshold; + int Audit_Session; + int Audit_ServerAction; + int Audit_LockUser; + int Audit_UserViolation; + int Audit_PrivilegeAdmin; + int Audit_DDL; + int Audit_DML; + int Audit_DML_SELECT; + int Audit_Exec; + int Audit_Copy; + int Audit_Set; + int auth_iteration_count; + double Password_reuse_time; + double Password_effect_time; + double Password_lock_time; + char* pg_krb_server_keyfile; + char* pg_krb_srvnam; + bool Enable_Security_Policy; +} knl_session_attr_security; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SECURITY_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_sql.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_sql.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_sql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_sql.h 2020-12-12 17:06:43.311348864 +0800 @@ -0,0 +1,216 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_sql.h + * Data struct to store knl_session_attr_sql variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_sql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_sql { + bool enable_fast_numeric; + bool enable_global_stats; + bool enable_hdfs_predicate_pushdown; + bool enable_absolute_tablespace; + bool enable_hadoop_env; + bool enable_valuepartition_pruning; + bool enable_constraint_optimization; + bool enable_bloom_filter; + bool enable_codegen; + bool enable_codegen_print; + bool enable_sonic_optspill; + bool enable_sonic_hashjoin; + bool enable_sonic_hashagg; + bool enable_upsert_to_merge; + bool enable_csqual_pushdown; + bool enable_change_hjcost; + bool enable_seqscan; + bool enable_indexscan; + bool enable_indexonlyscan; + bool enable_bitmapscan; + bool force_bitmapand; + bool enable_parallel_ddl; + bool enable_tidscan; + bool enable_sort; + bool enable_compress_spill; + bool enable_hashagg; + bool enable_material; + bool enable_nestloop; + bool enable_mergejoin; + bool enable_hashjoin; + bool enable_index_nestloop; + bool under_explain; + bool enable_nodegroup_debug; + bool enable_partitionwise; + bool enable_remotejoin; + bool enable_fast_query_shipping; + bool enable_compress_hll; + bool enable_remotegroup; + bool enable_remotesort; + bool enable_remotelimit; + bool gtm_backup_barrier; + bool explain_allow_multinode; + bool enable_stream_operator; + bool enable_stream_concurrent_update; + bool enable_vector_engine; + bool enable_force_vector_engine; + bool enable_random_datanode; + bool enable_fstream; + bool enable_geqo; + bool restart_after_crash; + bool enable_early_free; + bool enable_kill_query; + bool log_duration; + bool Debug_print_parse; + bool Debug_print_rewritten; + bool Debug_print_plan; + bool Debug_pretty_print; + bool enable_analyze_check; + bool enable_autoanalyze; + bool SQL_inheritance; + bool Transform_null_equals; + bool check_function_bodies; + bool Array_nulls; + bool default_with_oids; +#ifdef DEBUG_BOUNDED_SORT + bool optimize_bounded_sort; +#endif + bool escape_string_warning; + bool standard_conforming_strings; + bool enable_light_proxy; + bool enable_pbe_optimization; + bool enable_cluster_resize; + bool lo_compat_privileges; + bool quote_all_identifiers; + bool enforce_oracle_behavior; + bool enable_slot_log; + bool convert_string_to_digit; + bool agg_redistribute_enhancement; + bool enable_broadcast; + bool ngram_punctuation_ignore; + bool ngram_grapsymbol_ignore; + bool enable_fast_allocate; + bool td_compatible_truncation; + bool enable_upgrade_merge_lock_mode; + bool acceleration_with_compute_pool; + bool enable_extrapolation_stats; + bool enable_trigger_shipping; + bool enable_agg_pushdown_for_cooperation_analysis; + bool enable_online_ddl_waitlock; + bool show_acce_estimate_detail; + bool enable_prevent_job_task_startup; + bool enable_dngather; + int from_collapse_limit; + int join_collapse_limit; + int geqo_threshold; + int Geqo_effort; + int Geqo_pool_size; + int Geqo_generations; + int g_default_log2m; + int g_default_regwidth; + int g_default_sparseon; + int g_max_sparse; + int g_planCacheMode; + int cost_param; + int schedule_splits_threshold; + int hashagg_table_size; + int statement_mem; + int statement_max_mem; + int temp_file_limit; + int effective_cache_size; + int best_agg_plan; + int query_dop_tmp; + int plan_mode_seed; + int codegen_cost_threshold; + int acce_min_datasize_per_thread; + int max_cn_temp_file_size; + int default_statistics_target; + /* Memory Limit user could set in session */ + int FencedUDFMemoryLimit; + int64 g_default_expthresh; + double seq_page_cost; + double random_page_cost; + double cpu_tuple_cost; + double allocate_mem_cost; + double cpu_index_tuple_cost; + double cpu_operator_cost; + double stream_multiple; + double dngather_min_rows; + double cursor_tuple_fraction; + double Geqo_selection_bias; + double Geqo_seed; + double phony_random_seed; + char* expected_computing_nodegroup; + char* default_storage_nodegroup; + char* inlist2join_optmode; + char* behavior_compat_string; + char* connection_info; + char* retry_errcode_list; + /* the vmoptions to start JVM */ + char* pljava_vmoptions; + int backslash_quote; + int constraint_exclusion; + int rewrite_rule; + int sql_compatibility; + int guc_explain_perf_mode; + int skew_strategy_store; + int codegen_strategy; + + int application_type; + + bool enable_unshipping_log; + /* + * enable to support "with-recursive" stream plan + */ + bool enable_stream_recursive; + bool enable_save_datachanged_timestamp; + int max_recursive_times; + /* Table skewness warning rows, range from 0 to INT_MAX*/ + int table_skewness_warning_rows; + /* Table skewness warning threshold, range from 0 to 1, 0 indicates feature disabled*/ + double table_skewness_warning_threshold; + bool enable_opfusion; + bool enable_beta_opfusion; + bool enable_partition_opfusion; + int opfusion_debug_mode; + double cost_weight_index; + double default_limit_rows; + int sql_beta_feature; + /* hypo index */ + bool enable_hypo_index; + bool hypopg_is_explain; +} knl_session_attr_sql; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_SQL */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_storage.h postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_storage.h --- postgresql-hll-2.14_old/include/knl/knl_guc/knl_session_attr_storage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc/knl_session_attr_storage.h 2020-12-12 17:06:43.311348864 +0800 @@ -0,0 +1,193 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session_attr_storage.h + * Data struct to store all knl_session_attr_storage GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc/knl_session_attr_storage.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE +#define SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE + +#include "knl/knl_guc/knl_guc_common.h" + +typedef struct knl_session_attr_storage { + bool raise_errors_if_no_files; + bool enableFsync; + bool fullPageWrites; + bool Log_connections; + bool autovacuum_start_daemon; +#ifdef LOCK_DEBUG + bool Trace_locks; + bool Trace_userlocks; + bool Trace_lwlocks; +#endif + /* belong to #ifdef LOCK_DEBUG, but if #ifdef, compile error */ + bool Debug_deadlocks; + bool log_lock_waits; + bool phony_autocommit; + bool DefaultXactReadOnly; + bool DefaultXactDeferrable; + bool XactDeferrable; +#ifdef WAL_DEBUG + bool XLOG_DEBUG; +#endif + bool synchronize_seqscans; + bool enable_data_replicate; + bool HaModuleDebug; + bool hot_standby_feedback; + bool enable_stream_replication; + bool EnforceTwoPhaseCommit; + bool guc_most_available_sync; + bool enable_show_any_tuples; + bool enable_debug_vacuum; + bool enable_adio_debug; + bool gds_debug_mod; + bool log_pagewriter; + bool enable_incremental_catchup; + bool auto_explain_log_verbose; + int wait_dummy_time; + int DeadlockTimeout; + int LockWaitTimeout; + int LockWaitUpdateTimeout; + int max_standby_archive_delay; + int max_standby_streaming_delay; + int wal_receiver_status_interval; + int wal_receiver_timeout; + int wal_receiver_connect_timeout; + int wal_receiver_connect_retries; + int max_loaded_cudesc; + int num_temp_buffers; + int psort_work_mem; + int bulk_write_ring_size; + int bulk_read_ring_size; + int partition_mem_batch; + int partition_max_cache_size; + int VacuumCostPageHit; + int VacuumCostPageMiss; + int VacuumCostPageDirty; + int VacuumCostLimit; + int VacuumCostDelay; + int autovacuum_vac_cost_delay; + int autovacuum_vac_cost_limit; + int gs_clean_timeout; + int twophase_clean_workers; +#ifdef LOCK_DEBUG + int Trace_lock_oidmin; + int Trace_lock_table; +#endif + int replorigin_sesssion_origin; + int wal_keep_segments; + int CheckPointSegments; + int CheckPointTimeout; + int fullCheckPointTimeout; + int incrCheckPointTimeout; + int CheckPointWarning; + int checkpoint_flush_after; + int CheckPointWaitTimeOut; + int WalWriterDelay; + int wal_sender_timeout; + int CommitDelay; + int partition_lock_upgrade_timeout; + int CommitSiblings; + int log_min_duration_statement; + int Log_autovacuum_min_duration; + int BgWriterDelay; + int bgwriter_lru_maxpages; + int bgwriter_flush_after; + int max_index_keys; + int max_identifier_length; + int block_size; + int segment_size; + int wal_block_size; + int wal_segment_size; + int autovacuum_naptime; + int autoanalyze_timeout; + int autovacuum_vac_thresh; + int autovacuum_anl_thresh; + int prefetch_quantity; + int backwrite_quantity; + int cstore_prefetch_quantity; + int cstore_backwrite_max_threshold; + int cstore_backwrite_quantity; + int fast_extend_file_size; + int gin_pending_list_limit; + int gtm_connect_retries; + int gtm_conn_check_interval; + int dfs_max_parsig_length; + int plog_merge_age; + int max_redo_log_size; + int max_io_capacity; + int64 vacuum_freeze_min_age; + int64 vacuum_freeze_table_age; + int64 vacuum_defer_cleanup_age; + double bgwriter_lru_multiplier; + double shared_buffers_fraction; + double autovacuum_vac_scale; + double autovacuum_anl_scale; + double CheckPointCompletionTarget; + double candidate_buf_percent_target; + double dirty_page_percent_max; + char* XLogArchiveCommand; + char* XLogArchiveDest; + char* default_tablespace; + char* temp_tablespaces; + char* XactIsoLevel_string; + char* SyncRepStandbyNames; + char* ReplConnInfoArr[GUC_MAX_REPLNODE_NUM]; + char* PrimarySlotName; + char* logging_module; + char* Inplace_upgrade_next_system_object_oids; + int resource_track_log; + int guc_synchronous_commit; + int sync_method; + int autovacuum_mode; + int cstore_insert_mode; + int pageWriterSleep; + bool enable_cbm_tracking; + bool enable_copy_server_files; + int target_rto; + bool enable_twophase_commit; + /* + * xlog keep for all standbys even through they are not connect and donnot created replslot. + */ + bool enable_xlog_prune; + int max_size_for_xlog_prune; + int defer_csn_cleanup_time; + + bool enable_hashbucket; + + /* for GTT */ + int max_active_gtt; + int vacuum_gtt_defer_check_age; +} knl_session_attr_storage; + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_ATTR_STORAGE */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_guc.h postgresql-hll-2.14/include/knl/knl_guc.h --- postgresql-hll-2.14_old/include/knl/knl_guc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_guc.h 2020-12-12 17:06:43.311348864 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_guc.h + * Data struct to store all GUC variables. + * + * When anyone try to added variable in this file, which means add a guc + * variable, there are several rules needed to obey: + * + * add variable to struct 'knl_@level@_attr_@group@' + * + * @level@: + * 1. instance: the level of guc variable is PGC_POSTMASTER. + * 2. session: the other level of guc variable. + * + * @group@: sql, storage, security, network, memory, resource, common + * select the group according to the type of guc variable. + * + * IDENTIFICATION + * src/include/knl/knl_guc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_GUC_H_ +#define SRC_INCLUDE_KNL_KNL_GUC_H_ + +#include "knl_guc/knl_session_attr_sql.h" +#include "knl_guc/knl_instance_attr_sql.h" +#include "knl_guc/knl_session_attr_storage.h" +#include "knl_guc/knl_instance_attr_storage.h" +#include "knl_guc/knl_session_attr_security.h" +#include "knl_guc/knl_instance_attr_security.h" +#include "knl_guc/knl_session_attr_network.h" +#include "knl_guc/knl_instance_attr_network.h" +#include "knl_guc/knl_session_attr_memory.h" +#include "knl_guc/knl_instance_attr_memory.h" +#include "knl_guc/knl_session_attr_resource.h" +#include "knl_guc/knl_instance_attr_resource.h" +#include "knl_guc/knl_session_attr_common.h" +#include "knl_guc/knl_instance_attr_common.h" + +#endif /* SRC_INCLUDE_KNL_KNL_GUC_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_instance.h postgresql-hll-2.14/include/knl/knl_instance.h --- postgresql-hll-2.14_old/include/knl/knl_instance.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_instance.h 2020-12-12 17:06:43.311348864 +0800 @@ -0,0 +1,798 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_instance.h + * Data stucture for instance level global variables. + * + * Instance level variables can be accessed by all threads in gaussdb. + * Thread competition must be considered at the first place. If it can + * be changed by every thread in this process, then we must use lock or + * atomic operation to prevent competition. + * + * IDENTIFICATION + * src/include/knl/knl_instance.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_INSTANCE_H_ +#define SRC_INCLUDE_KNL_KNL_INSTANCE_H_ + +#include +#include "c.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "knl/knl_guc.h" +#include "lib/circularqueue.h" +#include "nodes/pg_list.h" +#include "storage/s_lock.h" +#include "access/double_write_basic.h" +#include "utils/palloc.h" +#include "replication/replicainternal.h" +#include "storage/latch.h" +#include "libcomm/libcomm.h" +#include "knl/knl_session.h" +#include "hotpatch/hotpatch.h" +#include "hotpatch/hotpatch_backend.h" +#include "utils/atomic.h" +#include "postmaster/bgwriter.h" +#include "postmaster/pagewriter.h" +#include "replication/heartbeat.h" +#include "access/multi_redo_settings.h" +#include "access/redo_statistic_msg.h" +#include "portability/instr_time.h" +#include "streaming/init.h" +#include "replication/rto_statistic.h" +#include "tsdb/utils/constant_def.h" +#include "streaming/init.h" +#include "storage/lwlock.h" +#include "utils/memgroup.h" + +const int NUM_PERCENTILE_COUNT = 2; +const int INIT_NUMA_ALLOC_COUNT = 32; +const int HOTKEY_ABANDON_LENGTH = 100; + +enum knl_virtual_role { + VUNKNOWN = 0, + VCOORDINATOR = 1, + VDATANODE = 2, + VSINGLENODE = 3, +}; + +/* + * start process: set to REDO_INIT + * parallel redo begin:set to REDO_STARTING_BEGIN, wait for redo worker thread to start + * all redo workers are started or waiting timeout: set to REDO_STARTING_END, + * if redo worker starts at this stage, the redo worker has to exit + */ +enum knl_parallel_redo_state { + REDO_INIT = 0, + REDO_STARTING_BEGIN, + REDO_STARTING_END, + REDO_IN_PROGRESS, + REDO_DONE, +}; + +/* all process level attribute which expose to user */ +typedef struct knl_instance_attr { + + knl_instance_attr_sql attr_sql; + knl_instance_attr_storage attr_storage; + knl_instance_attr_security attr_security; + knl_instance_attr_network attr_network; + knl_instance_attr_memory attr_memory; + knl_instance_attr_resource attr_resource; + knl_instance_attr_common attr_common; + +} knl_instance_attr_t; + +typedef struct knl_g_cache_context +{ + MemoryContext global_cache_mem; +} knl_g_cache_context; + +typedef struct knl_g_cost_context { + double cpu_hash_cost; + + double send_kdata_cost; + + double receive_kdata_cost; + + Cost disable_cost; + + Cost disable_cost_enlarge_factor; + +} knl_g_cost_context; + +typedef struct knl_g_pid_context { + ThreadId StartupPID; + ThreadId TwoPhaseCleanerPID; + ThreadId FaultMonitorPID; + ThreadId BgWriterPID; + ThreadId* CkptBgWriterPID; + ThreadId* PageWriterPID; + ThreadId CheckpointerPID; + ThreadId WalWriterPID; + ThreadId WalWriterAuxiliaryPID; + ThreadId WalReceiverPID; + ThreadId WalRcvWriterPID; + ThreadId DataReceiverPID; + ThreadId DataRcvWriterPID; + ThreadId AutoVacPID; + ThreadId PgJobSchdPID; + ThreadId PgArchPID; + ThreadId PgStatPID; + ThreadId PercentilePID; + ThreadId PgAuditPID; + ThreadId SysLoggerPID; + ThreadId CatchupPID; + ThreadId WLMCollectPID; + ThreadId WLMCalSpaceInfoPID; + ThreadId WLMMonitorPID; + ThreadId WLMArbiterPID; + ThreadId CPMonitorPID; + ThreadId AlarmCheckerPID; + ThreadId CBMWriterPID; + ThreadId RemoteServicePID; + ThreadId AioCompleterStarted; + ThreadId HeartbeatPID; + ThreadId CsnminSyncPID; + volatile ThreadId ReaperBackendPID; + volatile ThreadId SnapshotPID; + ThreadId AshPID; + ThreadId StatementPID; + ThreadId CommSenderFlowPID; + ThreadId CommReceiverFlowPID; + ThreadId CommAuxiliaryPID; + ThreadId CommPoolerCleanPID; + ThreadId* CommReceiverPIDS; + ThreadId TsCompactionPID; + ThreadId TsCompactionAuxiliaryPID; +} knl_g_pid_context; + +typedef struct knl_g_stat_context { + /* Every cell is a array size of 128 and the list stores all users` sql count results */ + struct List* WaitCountStatusList; + + /* Shared hashtable used to mapping user and g_instance.stat.WaitCountStatusList index for QPS */ + struct HTAB* WaitCountHashTbl; + + pgsocket pgStatSock; + + Latch pgStatLatch; + + time_t last_pgstat_start_time; + + /* Last time the collector successfully wrote the stats file */ + TimestampTz last_statwrite; + + /* Latest statistics request time from backends */ + TimestampTz last_statrequest; + + volatile bool need_exit; + + volatile bool got_SIGHUP; + + /* unique sql */ + MemoryContext UniqueSqlContext; + HTAB* volatile UniqueSQLHashtbl; + + /* hypothetical index */ + MemoryContext HypopgContext; + + /* user logon/logout stat */ + MemoryContext InstrUserContext; + HTAB* InstrUserHTAB; + + /* workload trx stat */ + HTAB* workload_info_hashtbl; + + /* percentile stat */ + volatile bool calculate_on_other_cn; + volatile bool force_process; + int64 RTPERCENTILE[NUM_PERCENTILE_COUNT]; + struct SqlRTInfoArray* sql_rt_info_array; + MemoryContext InstrPercentileContext; + + /* Set at the following cases: + 1. the cluster occures ha action + 2. user perform reset action + 3. the node startup + 4. ... + */ + volatile TimestampTz NodeStatResetTime; + int64* gInstanceTimeInfo; + + /* snapshot thread status counter, will +1 when "each" startup */ + volatile uint32 snapshot_thread_counter; + /* Record the sum of file io stat */ + struct FileIOStat* fileIOStat; + + /* Active session history */ + MemoryContext AshContext; + struct ActiveSessHistArrary *active_sess_hist_arrary; + char *ash_appname; + char *ash_clienthostname; + char *ashRelname; + HTAB* ASHUniqueSQLHashtbl; + /* used for capture view to json file */ + HTAB* capture_view_file_hashtbl; + + /* used for track memory alloc info */ + MemoryContext track_context; + HTAB* track_context_hash; + HTAB* track_memory_info_hash; + bool track_memory_inited; + pthread_rwlock_t track_memory_lock; + + /* A g_instance lock-free queue to collect keys */ + CircularQueue* hotkeysCollectList; + + /* memorycontext for managing hotkeys */ + MemoryContext hotkeysCxt; + + struct LRUCache* lru; + List* fifo; + +} knl_g_stat_context; + +/* + *quota related + */ +typedef struct knl_g_quota_context { + /* quota for each stream */ + unsigned long g_quota; + /* quota ratio for dynamic quota changing, but no use now */ + unsigned long g_quotanofify_ratio; + /* using quota or not */ + bool g_having_quota; + /* for notifying bufCAP of stream is changed */ + struct binary_semaphore* g_quota_changing; +} knl_g_quota_context; + +typedef enum { + POLLING_CONNECTION = 0, + + SPECIFY_CONNECTION = 1, + + PROHIBIT_CONNECTION = 2 +} CONN_MODE; + +typedef struct knl_g_disconn_node_context_data { + CONN_MODE conn_mode; + char disable_conn_node_host[NAMEDATALEN]; + int disable_conn_node_port; +} knl_g_disconn_node_context_data; + +typedef struct knl_g_disconn_node_context { + knl_g_disconn_node_context_data disable_conn_node_data; + slock_t info_lck; /* locks shared variables shown above */ +} knl_g_disconn_node_context; + +/* + *local basic connection info + */ +typedef struct knl_g_localinfo_context { + char* g_local_host; + char* g_self_nodename; + int g_local_ctrl_tcp_sock; + int sock_to_server_loop; + /* The start time of receiving the ready message */ + uint64 g_r_first_recv_time; + /* record CPU utilization, gs_receivers_flow_controller ,gs_sender_flow_controller, gs_reveiver_loop, postmaster */ + int *g_libcomm_used_rate; + /* GSS kerberos authentication */ + char* gs_krb_keyfile; + volatile uint32 term_from_file = 1; + volatile uint32 term_from_xlog = 1; + bool set_term = true; + knl_g_disconn_node_context disable_conn_node; + volatile uint32 is_finish_redo = 0; + volatile bool need_disable_connection_node = false; +} knl_g_localinfo_context; + +typedef struct knl_g_counters_context { + /* connection number, equal to real node number (dn + cn) */ + int g_cur_node_num; + /* + * expected node number, if g_expect_node_num != g_cur_node_num, + * we will use online capacity change. + */ + int g_expect_node_num; + /* stream number of each logic connection */ + int g_max_stream_num; + /* the number of receiver thread */ + int g_recv_num; + int g_comm_send_timeout; +} knl_g_counters_context; + +typedef struct knl_g_tests_context { + int libcomm_test_current_thread; + int* libcomm_test_thread_arg; + bool libcomm_stop_flag; + int libcomm_test_thread_num; + int libcomm_test_msg_len; + int libcomm_test_send_sleep; + int libcomm_test_send_once; + int libcomm_test_recv_sleep; + int libcomm_test_recv_once; +} knl_g_tests_context; + +/* the epoll cabinets for receiving control messages and data */ +typedef struct knl_g_pollers_context { + /* data receiver epoll cabinet */ + class mc_poller_hndl_list* g_libcomm_receiver_poller_list; + pthread_mutex_t* g_r_libcomm_poller_list_lock; + /* the epoll cabinet for receiving control messages at receiver */ + class mc_poller_hndl_list* g_r_poller_list; + pthread_mutex_t* g_r_poller_list_lock; + /* the epoll cabinet for receiving control messages at sender */ + class mc_poller_hndl_list* g_s_poller_list; + pthread_mutex_t* g_s_poller_list_lock; +} knl_g_pollers_context; + +/* request checking variable */ +typedef struct knl_g_reqcheck_context { + volatile bool g_shutdown_requested; + volatile ThreadId g_cancel_requested; + volatile bool g_close_poll_requested; +} knl_g_reqcheck_context; + +typedef struct knl_g_mctcp_context { + int mc_tcp_keepalive_idle; + int mc_tcp_keepalive_interval; + int mc_tcp_keepalive_count; + int mc_tcp_connect_timeout; + int mc_tcp_send_timeout; +} knl_g_mctcp_context; + +typedef struct knl_g_commutil_context { + volatile bool g_debug_mode; + volatile bool g_timer_mode; + volatile bool g_stat_mode; + volatile bool g_no_delay; + + int g_comm_sender_buffer_size; + long g_total_usable_memory; + long g_memory_pool_size; + bool ut_libcomm_test; +} knl_g_commutil_context; + +const int TWO_UINT64_SLOT = 2; +/*checkpoint*/ +typedef struct knl_g_ckpt_context { + uint64 dirty_page_queue_reclsn; + uint64 dirty_page_queue_tail; + + CkptSortItem* CkptBufferIds; + + /* dirty_page_queue store dirty buffer, buf_id + 1, 0 is invalid */ + DirtyPageQueueSlot* dirty_page_queue; + uint64 dirty_page_queue_size; + pg_atomic_uint64 dirty_page_queue_head; + pg_atomic_uint32 actual_dirty_page_num; + slock_t queue_lock; + + /* pagewriter thread */ + PageWriterProcs page_writer_procs; + uint64 page_writer_actual_flush; + volatile uint32 page_writer_last_flush; + + /* full checkpoint infomation */ + volatile bool flush_all_dirty_page; + volatile uint64 full_ckpt_expected_flush_loc; + volatile uint64 full_ckpt_redo_ptr; + volatile uint32 current_page_writer_count; + volatile XLogRecPtr page_writer_xlog_flush_loc; + volatile LWLock *backend_wait_lock; + + /* Pagewriter thread need wait shutdown checkpoint finish */ + volatile bool page_writer_can_exit; + volatile bool ckpt_need_fast_flush; + + /* checkpoint flush page num except buffers */ + int64 ckpt_clog_flush_num; + int64 ckpt_csnlog_flush_num; + int64 ckpt_multixact_flush_num; + int64 ckpt_predicate_flush_num; + int64 ckpt_twophase_flush_num; + volatile XLogRecPtr ckpt_current_redo_point; + +#ifdef ENABLE_MOT + struct CheckpointCallbackItem* ckptCallback; +#endif + + uint64 pad[TWO_UINT64_SLOT]; +} knl_g_ckpt_context; + +typedef struct knl_g_dw_context { + int fd; + volatile uint32 closed; + + struct LWLock* flush_lock; + volatile uint16 write_pos; /* the copied pages in buffer, updated when mark page */ + uint16 flush_page; /* total number of flushed pages before truncate or reset */ + MemoryContext mem_cxt; + char* unaligned_buf; + char* buf; + dw_file_head_t* file_head; + bool contain_hashbucket; + + /* single flush dw extras information */ + single_slot_pos *single_flush_pos; /* dw single flush slot */ + single_slot_state *single_flush_state; /* dw single flush slot state */ + + /* dw view information */ + dw_stat_info_batch batch_stat_info; + dw_stat_info_single single_stat_info; +} knl_g_dw_context; + +typedef struct knl_g_bgwriter_context { + BgWriterProc *bgwriter_procs; + int bgwriter_num; /* bgwriter thread num*/ + pg_atomic_uint32 curr_bgwriter_num; + Buffer *candidate_buffers; + bool *candidate_free_map; + + /* bgwriter view information*/ + volatile uint64 bgwriter_actual_total_flush; + volatile uint64 get_buf_num_candidate_list; + volatile uint64 get_buf_num_clock_sweep; +}knl_g_bgwriter_context; + +typedef struct { + ThreadId threadId; + uint32 threadState; +} PageRedoWorkerStatus; + +typedef struct { + uint64 preEndPtr; + instr_time preTime; + XLogRecPtr redo_start_ptr; + int64 redo_start_time; + int64 redo_done_time; + int64 current_time; + XLogRecPtr min_recovery_point; + XLogRecPtr read_ptr; + XLogRecPtr last_replayed_end_ptr; + XLogRecPtr recovery_done_ptr; + XLogRecPtr primary_flush_ptr; + RedoWaitInfo wait_info[WAIT_REDO_NUM]; + uint32 speed_according_seg; + XLogRecPtr local_max_lsn; + uint64 oldest_segment; +} RedoPerf; + + +typedef enum{ + DEFAULT_REDO, + PARALLEL_REDO, + EXTREME_REDO, +}RedoType; + + +typedef struct knl_g_parallel_redo_context { + RedoType redoType; + volatile knl_parallel_redo_state state; + slock_t rwlock; /* redo worker starting lock */ + MemoryContext parallelRedoCtx; + uint32 totalNum; + volatile PageRedoWorkerStatus pageRedoThreadStatusList[MAX_RECOVERY_THREAD_NUM]; + RedoPerf redoPf; /* redo Performance statistics */ + pg_atomic_uint32 isRedoFinish; + int pre_enable_switch; + slock_t destroy_lock; /* redo worker destroy lock */ + pg_atomic_uint64 max_page_flush_lsn[NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS]; + pg_atomic_uint32 permitFinishRedo; + pg_atomic_uint32 hotStdby; + char* unali_buf; /* unaligned_buf */ + char* ali_buf; +} knl_g_parallel_redo_context; + +typedef struct knl_g_heartbeat_context { + volatile bool heartbeat_running; +} knl_g_heartbeat_context; + +typedef struct knl_g_csnminsync_context { + bool stop; + bool is_fcn_ccn; /* whether this instance is center cn or the first cn while without ccn */ +} knl_g_csnminsync_context; + +typedef struct knl_g_comm_context { + /* function point, for wake up consumer in executor */ + wakeup_hook_type gs_wakeup_consumer; + /* connection handles at receivers, for listening and receiving data through logic connection */ + struct local_receivers* g_receivers; + /* connection handles at senders, for sending data through logic connection */ + struct local_senders* g_senders; + bool g_delay_survey_switch; + /* the unix path to send startuppacket to postmaster */ + char* g_unix_path; + HaShmemData* g_ha_shm_data; + /* + * filo queue, for keeping the usable stream indexes of each node + * we pop up a stream index for communication and push back after + * the stream is closed + */ + struct mc_queue* g_usable_streamid; + + /* + * sockets (control tcp & sctp sockets) of receiver and sender, for socket management and avaliable checking + * the indexes of the items in the array is the node indexes for each datanode, + * e.g. g_r_node_sock[1] is using to keep socket information of Datanode 1 at receiver in this datanode, maybe + * Datanode 2 or others + */ + struct node_sock* g_r_node_sock; + struct node_sock* g_s_node_sock; + struct libcomm_delay_info* g_delay_info; + /* + * two-dimension array to maintain the information of streams associated to Consumer and Producer, each element + * represent a stream. the first dimension represent node and the second is stream. we call it mailbox, and the node + * index and stream index is the address, e.g. we can get information of a stream at receiver by g_c_mailbox[node + * id][stream id]. + */ + /* Consumer mailboxes at receiver */ + struct c_mailbox** g_c_mailbox; + /* Producer mailboxes at sender */ + struct p_mailbox** g_p_mailbox; + struct pg_tz* libcomm_log_timezone; + + bool g_use_workload_manager; + + knl_g_quota_context quota_cxt; + knl_g_localinfo_context localinfo_cxt; + knl_g_counters_context counters_cxt; + knl_g_tests_context tests_cxt; + knl_g_pollers_context pollers_cxt; + knl_g_reqcheck_context reqcheck_cxt; + knl_g_mctcp_context mctcp_cxt; + knl_g_commutil_context commutil_cxt; + knl_g_parallel_redo_context predo_cxt; /* parallel redo context */ + MemoryContext comm_global_mem_cxt; + bool force_cal_space_info; + bool cal_all_space_info_in_progress; + + HTAB* usedDnSpace; + uint32 current_gsrewind_count; +} knl_g_comm_context; + +typedef struct knl_g_libpq_context { + /* Workaround for Solaris 2.6 brokenness */ + char* pam_passwd; + /* Workaround for passing "Port *port" into pam_passwd_conv_proc */ + struct Port* pam_port_cludge; +#ifdef KRB5 + /* + * Various krb5 state which is not connection specific, and a flag to + * indicate whether we have initialised it yet. + */ + int pg_krb5_initialised; + krb5_context pg_krb5_context; + krb5_keytab pg_krb5_keytab; + krb5_principal pg_krb5_server; +#endif + /* check internal IP, to avoid port injection*/ + List* comm_parsed_hba_lines; +} knl_g_libpq_context; + +#define MIN_CONNECTIONS 1024 + +typedef struct knl_g_shmem_context { + int MaxConnections; + int MaxBackends; + int MaxReserveBackendId; + int ThreadPoolGroupNum; + int numaNodeNum; +} knl_g_shmem_context; + +typedef struct knl_g_executor_context { + HTAB* function_id_hashtbl; +} knl_g_executor_context; + +typedef struct knl_g_xlog_context { + int num_locks_in_group; +#ifdef ENABLE_MOT + struct WALCallbackItem* walCallback; + struct RedoCommitCallbackItem* redoCommitCallback; +#endif +} knl_g_xlog_context; + +struct NumaMemAllocInfo { + void* numaAddr; /* Start address returned from numa_alloc_xxx */ + size_t length; +}; + +typedef struct knl_g_numa_context { + bool inheritThreadPool; // Inherit NUMA node No. from thread pool module + NumaMemAllocInfo* numaAllocInfos; + size_t maxLength; + size_t allocIndex; +} knl_g_numa_context; +typedef struct knl_g_ts_compaction_context { + volatile Compaction::knl_compaction_state state; + int totalNum; + int* origin_id; + volatile uint32 drop_db_count; + volatile bool compaction_rest; + Oid dropdb_id; + volatile TsCompactionWorkerStatus compaction_worker_status_list[Compaction::MAX_TSCOMPATION_NUM]; + MemoryContext compaction_instance_cxt; +} knl_g_ts_compaction_context; + +typedef struct knl_g_security_policy_context { + MemoryContext policy_instance_cxt; + HTAB* account_table; + LWLock* account_table_lock; +} knl_g_security_policy_context; + +typedef struct knl_g_oid_nodename_mapping_cache +{ + HTAB *s_mapping_hash; + volatile bool s_valid; + pthread_mutex_t s_mutex; +} knl_g_oid_nodename_mapping_cache; + +typedef uint64 XLogSegNo; /* XLogSegNo - physical log file sequence number */ +typedef struct WalInsertStatusEntry WALInsertStatusEntry; +typedef struct WALFlushWaitLockPadded WALFlushWaitLockPadded; +typedef struct WALBufferInitWaitLockPadded WALBufferInitWaitLockPadded; +typedef struct WALInitSegLockPadded WALInitSegLockPadded; +typedef struct knl_g_conn_context { + volatile int CurConnCount; + volatile int CurCMAConnCount; + slock_t ConnCountLock; +} knl_g_conn_context; + +typedef struct knl_g_wal_context { + /* Start address of WAL insert status table that contains WAL_INSERT_STATUS_ENTRIES entries */ + WALInsertStatusEntry* walInsertStatusTable; + WALFlushWaitLockPadded* walFlushWaitLock; + WALBufferInitWaitLockPadded* walBufferInitWaitLock; + WALInitSegLockPadded* walInitSegLock; + volatile bool isWalWriterUp; + XLogRecPtr flushResult; + XLogRecPtr sentResult; + pthread_mutex_t flushResultMutex; + pthread_cond_t flushResultCV; + int XLogFlusherCPU; + volatile bool isWalWriterSleeping; + pthread_mutex_t criticalEntryMutex; + pthread_cond_t criticalEntryCV; + volatile uint32 walWaitFlushCount; /* only for xlog statistics use */ + volatile XLogSegNo globalEndPosSegNo; /* Global variable for init xlog segment files. */ + int lastWalStatusEntryFlushed; + volatile int lastLRCScanned; + int num_locks_in_group; +} knl_g_wal_context; + +typedef struct GlobalSeqInfoHashBucket { + DList* shb_list; + int lock_id; +} GlobalSeqInfoHashBucket; + +typedef struct knl_instance_context { + knl_virtual_role role; + volatile int status; + DemoteMode demotion; + bool fatal_error; + + bool WalSegmentArchSucceed; + + /* + * request to flush buffer log data + * 1. syslogger thread will read this var. if it's true, + * flush all buffered log data and reset this flag. + * 2. the other worker threads will set this flag be true if needed. + * needn't use THR_LOCAL modifier. + */ + volatile sig_atomic_t flush_buf_requested; + + /* True if WAL recovery failed */ + bool recover_error; + pthread_mutex_t gpc_reset_lock; + struct Dllist* backend_list; + struct Backend* backend_array; + + void* t_thrd; + char* prog_name; + int64 start_time; + + bool binaryupgrade; + + bool dummy_standby; + + struct GlobalSeqInfoHashBucket global_seq[NUM_GS_PARTITIONS]; + + struct GlobalPlanCache* plan_cache; + struct GlobalPrepareStmt* prepare_cache; + + struct PROC_HDR* proc_base; + slock_t proc_base_lock; + struct PGPROC** proc_base_all_procs; + struct PGXACT* proc_base_all_xacts; + struct PGPROC** proc_aux_base; + struct PGPROC** proc_preparexact_base; + struct ProcArrayStruct* proc_array_idx; + struct GsSignalBase* signal_base; + struct DistributeTestParam* distribute_test_param_instance; + + /* Set by the -o option */ + char ExtraOptions[MAXPGPATH]; + + /* load ir file count for each session */ + long codegen_IRload_process_count; + + struct HTAB* vec_func_hash; + + MemoryContext instance_context; + MemoryContext error_context; + MemoryContext signal_context; + MemoryContext increCheckPoint_context; + MemoryContext wal_context; + MemoryContext account_context; + MemoryContextGroup* mcxt_group; + + knl_instance_attr_t attr; + knl_g_stat_context stat_cxt; + knl_g_pid_context pid_cxt; + knl_g_cache_context cache_cxt; + knl_g_cost_context cost_cxt; + knl_g_comm_context comm_cxt; + knl_g_conn_context conn_cxt; + knl_g_libpq_context libpq_cxt; + struct knl_g_wlm_context* wlm_cxt; + knl_g_ckpt_context ckpt_cxt; + knl_g_ckpt_context* ckpt_cxt_ctl; + knl_g_bgwriter_context bgwriter_cxt; + struct knl_g_dw_context dw_batch_cxt; + struct knl_g_dw_context dw_single_cxt; + knl_g_shmem_context shmem_cxt; + knl_g_wal_context wal_cxt; + knl_g_executor_context exec_cxt; + knl_g_heartbeat_context heartbeat_cxt; + knl_g_rto_context rto_cxt; + knl_g_xlog_context xlog_cxt; + knl_g_numa_context numa_cxt; + knl_g_ts_compaction_context ts_compaction_cxt; + knl_g_security_policy_context policy_cxt; + knl_g_streaming_context streaming_cxt; + knl_g_csnminsync_context csnminsync_cxt; + knl_g_oid_nodename_mapping_cache oid_nodename_cache; + struct HTAB* ngroup_hash_table; +} knl_instance_context; + +extern void knl_instance_init(); +extern void knl_g_set_redo_finish_status(uint32 status); +extern bool knl_g_get_local_redo_finish_status(); +extern bool knl_g_get_redo_finish_status(); +extern knl_instance_context g_instance; + +extern void add_numa_alloc_info(void* numaAddr, size_t length); + +#define GTM_FREE_MODE (g_instance.attr.attr_storage.enable_gtm_free || \ + g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTMFREE) +#define GTM_MODE (!g_instance.attr.attr_storage.enable_gtm_free && \ + (g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTM)) +#define GTM_LITE_MODE (!g_instance.attr.attr_storage.enable_gtm_free && \ + g_instance.attr.attr_storage.gtm_option == GTMOPTION_GTMLITE) + +#define REDO_FINISH_STATUS_LOCAL 0x00000001 +#define REDO_FINISH_STATUS_CM 0x00000002 + +#define ATOMIC_TRUE 1 +#define ATOMIC_FALSE 0 + +#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_H_ */ + diff -uprN postgresql-hll-2.14_old/include/knl/knl_session.h postgresql-hll-2.14/include/knl/knl_session.h --- postgresql-hll-2.14_old/include/knl/knl_session.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_session.h 2020-12-12 17:06:43.312348877 +0800 @@ -0,0 +1,2333 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_session.h + * Data stucture for session level global variables. + * + * several guidelines for put variables in knl_session.h + * + * variables which related to session only and can be decoupled with thread status + * should put int knl_session.h + * + * pay attention to memory allocation + * allocate runtime session variable in session context, which is highly recommended + * to do that. + * + * variables related to dedicated utility thread(wal, bgwrited, log...) usually put + * in knl_thread.h + * + * all context define below should follow naming rules: + * knl_u_sess->on_xxxx + * + * IDENTIFICATION + * src/include/knl/knl_session.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_SESSION_H_ +#define SRC_INCLUDE_KNL_KNL_SESSION_H_ + +#include + +#include "c.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "knl/knl_guc.h" +#include "lib/dllist.h" +#include "lib/ilist.h" +#include "lib/stringinfo.h" +#include "libpq/pqcomm.h" +#include "nodes/pg_list.h" +#include "cipher.h" +#include "openssl/ossl_typ.h" +#include "portability/instr_time.h" +#include "storage/backendid.h" +#include "storage/s_lock.h" +#include "storage/shmem.h" +#include "utils/palloc.h" +#include "utils/memgroup.h" + +typedef void (*pg_on_exit_callback)(int code, Datum arg); + +/* all session level attribute which expose to user. */ +typedef struct knl_session_attr { + + knl_session_attr_sql attr_sql; + knl_session_attr_storage attr_storage; + knl_session_attr_security attr_security; + knl_session_attr_network attr_network; + knl_session_attr_memory attr_memory; + knl_session_attr_resource attr_resource; + knl_session_attr_common attr_common; +} knl_session_attr; + +typedef struct knl_u_stream_context { + uint32 producer_dop; + + uint32 smp_id; + + bool in_waiting_quit; + + bool dummy_thread; + + bool enter_sync_point; + + bool inStreamEnv; + + bool stop_mythread; + + ThreadId stop_pid; + + uint64 stop_query_id; + + class StreamNodeGroup* global_obj; + + class StreamProducer* producer_obj; +} knl_u_stream_context; + +typedef struct knl_u_executor_context { + List* remotequery_list; + + bool exec_result_checkqual_fail; + + bool executor_stop_flag; + + bool under_stream_runtime; + bool under_auto_explain; + + /* This variable indicates wheather the prescribed extension is supported */ + bool extension_is_valid; + + uint2* global_bucket_map; + + struct HTAB* vec_func_hash; + + struct PartitionIdentifier* route; + + struct TupleHashTableData* cur_tuple_hash_table; + + class lightProxy* cur_light_proxy_obj; + + /* + * ActivePortal is the currently executing Portal (the most closely nested, + * if there are several). + */ + struct PortalData* ActivePortal; + bool need_track_resource; + int nesting_level; + + HTAB* PortalHashTable; + unsigned int unnamed_portal_count; + /* the single instance for statement retry controll per thread*/ + struct StatementRetryController* RetryController; + + bool hasTempObject; + bool DfsDDLIsTopLevelXact; + /* global variable used to determine if we could cancel redistribution transaction */ + bool could_cancel_redistribution; + + bool g_pgaudit_agent_attached; + /* whether to track sql stats */ + bool pgaudit_track_sqlddl; + + struct HashScanListData* HashScans; + + /* the flag indicate the executor can stop, do not send anything to outer */ + bool executorStopFlag; + + struct OpFusion* CurrentOpFusionObj; + + int global_iteration; + + bool is_exec_trigger_func; + + bool single_shard_stmt; + struct SendRouter* CurrentRouter; + bool is_dn_enable_router; +} knl_u_executor_context; + +typedef struct knl_u_sig_context { + /* + * Flag to mark SIGHUP. Whenever the main loop comes around it + * will reread the configuration file. (Better than doing the + * reading in the signal handler, ey?) + */ + volatile sig_atomic_t got_SIGHUP; + + /* + * like got_PoolReload, but just for the compute pool. + * see CPmonitor_MainLoop for more details. + */ + volatile sig_atomic_t got_PoolReload; + volatile sig_atomic_t cp_PoolReload; +} knl_u_sig_context; + +typedef struct knl_u_SPI_context { +#define BUFLEN 64 +#define XACTMSGLEN 128 + + Oid lastoid; + + char buf[BUFLEN]; + + int _stack_depth; /* allocated size of _SPI_stack */ + + int _connected; + + int _curid; + + struct _SPI_connection* _stack; + + struct _SPI_connection* _current; + + HTAB* SPICacheTable; + + bool is_allow_commit_rollback; + char forbidden_commit_rollback_err_msg[XACTMSGLEN]; + + /* Is Procedure or Function. */ + bool is_stp; + + /* Whether procedure contains option setting guc. */ + bool is_proconfig_set; + + /* Recording the nested exception counts for commit/rollback statement after. */ + int portal_stp_exception_counter; + +} knl_u_SPI_context; + +typedef struct knl_u_index_context { + typedef uint64 XLogRecPtr; + XLogRecPtr counter; +} knl_u_index_context; + +typedef struct knl_u_instrument_context { + bool perf_monitor_enable; + + bool can_record_to_table; + + int operator_plan_number; + + bool OBS_instr_valid; + + bool* p_OBS_instr_valid; + + class StreamInstrumentation* global_instr; + + class ThreadInstrumentation* thread_instr; + + class OBSInstrumentation* obs_instr; + + struct Qpid* gs_query_id; + + struct BufferUsage* pg_buffer_usage; + + int plan_size; +} knl_u_instrument_context; + +typedef struct knl_u_analyze_context { + bool is_under_analyze; + + bool need_autoanalyze; + + MemoryContext analyze_context; + + struct AutoAnaProcess* autoanalyze_process; + + struct StringInfoData* autoanalyze_timeinfo; + + struct BufferAccessStrategyData* vac_strategy; +} knl_u_analyze_context; + +#define PATH_SEED_FACTOR_LEN 3 + +typedef struct knl_u_optimizer_context { + bool disable_dop_change; + + bool enable_nodegroup_explain; + + bool has_obsrel; + + bool is_stream; + + bool is_stream_support; + + bool is_multiple_nodegroup_scenario; + + /* Record the different nodegroup count for multi nodegroup scenario. */ + int different_nodegroup_count; + + bool is_randomfunc_shippable; + + bool is_dngather_support; + + int srvtype; + + int qrw_inlist2join_optmode; + + uint32 plan_current_seed; + + uint32 plan_prev_seed; + + uint16 path_current_seed_factor[PATH_SEED_FACTOR_LEN]; + + double cursor_tuple_fraction; + + /* Global variables used for parallel execution. */ + int query_dop_store; /* Store the dop. */ + + int query_dop; /* Degree of parallel, 1 means not parallel. */ + + double smp_thread_cost; + + /* u_sess->opt_cxt.max_query_dop: + * When used in dynamic smp, this variable set the max limit of dop + * <0 means turned off dynsmp. + * 0 means optimized dop based on query and resources + * 1 is the same as set u_sess->opt_cxt.query_dop=1 + * 2..n means max limit of dop + */ + int max_query_dop; + + int parallel_debug_mode; /* Control the parallel debug mode. */ + + int skew_strategy_opt; + + int op_work_mem; + + MemoryContext ft_context; + + struct Distribution* in_redistribution_group_distribution; + + struct Distribution* compute_permission_group_distribution; + + struct Distribution* query_union_set_group_distribution; + + struct Distribution* single_node_distribution; + + struct DynamicSmpInfo* dynamic_smp_info; + + struct PartitionIdentifier* bottom_seq; + + struct PartitionIdentifier* top_seq; + + struct HTAB* opr_proof_cache_hash; + + struct ShippingInfo* not_shipping_info; + + bool is_under_append_plan; +} knl_u_optimizer_context; + +typedef struct knl_u_parser_context { + bool eaten_begin; + + bool eaten_declare; + + bool has_dollar; + + bool has_placeholder; + + bool stmt_contains_operator_plus; + + List* hint_list; + + List* hint_warning; + + struct HTAB* opr_cache_hash; + + void* param_info; + + StringInfo param_message; + + MemoryContext ddl_pbe_context; +} knl_u_parser_context; + +typedef struct knl_u_trigger_context { + struct HTAB* ri_query_cache; + + struct HTAB* ri_compare_cache; + + bool exec_row_trigger_on_datanode; + + /* How many levels deep into trigger execution are we? */ + int MyTriggerDepth; + List* info_list; + struct AfterTriggersData* afterTriggers; +} knl_u_trigger_context; + +enum guc_choose_strategy { SINGLE_GUC = 0, DISTRIBUTE_GUC, MAX_GUC_STRATEGY}; + +typedef struct knl_u_utils_context { + char suffix_char; + + Oid suffix_collation; + + int test_err_type; + + /* + * While compute_array_stats is running, we keep a pointer to the extra data + * here for use by assorted subroutines. compute_array_stats doesn't + * currently need to be re-entrant, so avoiding this is not worth the extra + * notational cruft that would be needed. + */ + struct ArrayAnalyzeExtraData* array_extra_data; + + struct ItemPointerData* cur_last_tid; + + struct DistributeTestParam* distribute_test_param; + + struct PGLZ_HistEntry** hist_start; + + struct PGLZ_HistEntry* hist_entries; + + char* analysis_options_configure; + + int* guc_new_value; + + int GUC_check_errcode_value; + + TimestampTz lastFailedLoginTime; + + struct StringInfoData* input_set_message; /*Add for set command in transaction*/ + + char* GUC_check_errmsg_string; + + char* GUC_check_errdetail_string; + + char* GUC_check_errhint_string; + + HTAB* set_params_htab; + + struct config_generic** sync_guc_variables; + + struct config_bool* ConfigureNamesBool[MAX_GUC_STRATEGY]; + + struct config_int* ConfigureNamesInt[MAX_GUC_STRATEGY]; + + struct config_real* ConfigureNamesReal[MAX_GUC_STRATEGY]; + + struct config_int64* ConfigureNamesInt64; + + struct config_string* ConfigureNamesString[MAX_GUC_STRATEGY]; + + struct config_enum* ConfigureNamesEnum; + + int size_guc_variables; + + bool guc_dirty; /* TRUE if need to do commit/abort work */ + + bool reporting_enabled; /* TRUE to enable GUC_REPORT */ + + int GUCNestLevel; /* 1 when in main transaction */ + + unsigned int behavior_compat_flags; + + int save_argc; + + char** save_argv; + + /* Hash table to lookup combo cids by cmin and cmax */ + HTAB* comboHash; + + /* + * An array of cmin,cmax pairs, indexed by combo command id. + * To convert a combo cid to cmin and cmax, you do a simple array lookup. + */ + struct ComboCidKeyData* comboCids; + + /* use for stream producer thread */ + struct ComboCidKeyData* StreamParentComboCids; + + int usedComboCids; /* number of elements in comboCids */ + + int sizeComboCids; /* allocated size of array */ + + int StreamParentsizeComboCids; /* allocated size of array for StreamParentComboCids */ + + /* + * CurrentSnapshot points to the only snapshot taken in transaction-snapshot + * mode, and to the latest one taken in a read-committed transaction. + * SecondarySnapshot is a snapshot that's always up-to-date as of the current + * instant, even in transaction-snapshot mode. It should only be used for + * special-purpose code (say, RI checking.) + * + * These SnapshotData structs are static to simplify memory allocation + * (see the hack in GetSnapshotData to avoid repeated malloc/free). + */ + struct SnapshotData* CurrentSnapshotData; + + struct SnapshotData* SecondarySnapshotData; + + struct SnapshotData* CurrentSnapshot; + + struct SnapshotData* SecondarySnapshot; + + struct SnapshotData* CatalogSnapshot; + + struct SnapshotData* HistoricSnapshot; + + /* Staleness detection for CatalogSnapshot. */ + bool CatalogSnapshotStale; + + /* + * These are updated by GetSnapshotData. We initialize them this way + * for the convenience of TransactionIdIsInProgress: even in bootstrap + * mode, we don't want it to say that BootstrapTransactionId is in progress. + * + * RecentGlobalXmin and RecentGlobalDataXmin are initialized to + * InvalidTransactionId, to ensure that no one tries to use a stale + * value. Readers should ensure that it has been set to something else + * before using it. + */ + TransactionId TransactionXmin; + + TransactionId RecentXmin; + + TransactionId RecentGlobalXmin; + + TransactionId RecentGlobalDataXmin; + + /* Global snapshot data */ + bool cn_xc_maintain_mode; + int snapshot_source; + TransactionId gxmin; + TransactionId gxmax; + uint32 GtmTimeline; + struct GTM_SnapshotData* g_GTM_Snapshot; + uint64 g_snapshotcsn; + bool snapshot_need_sync_wait_all; + bool is_autovacuum_snapshot; + + /* (table, ctid) => (cmin, cmax) mapping during timetravel */ + HTAB* tuplecid_data; + + /* Top of the stack of active snapshots */ + struct ActiveSnapshotElt* ActiveSnapshot; + + /* + * How many snapshots is resowner.c tracking for us? + * + * Note: for now, a simple counter is enough. However, if we ever want to be + * smarter about advancing our MyPgXact->xmin we will need to be more + * sophisticated about this, perhaps keeping our own list of snapshots. + */ + int RegisteredSnapshots; + + /* first GetTransactionSnapshot call in a transaction? */ + bool FirstSnapshotSet; + + /* + * Remember the serializable transaction snapshot, if any. We cannot trust + * FirstSnapshotSet in combination with IsolationUsesXactSnapshot(), because + * GUC may be reset before us, changing the value of IsolationUsesXactSnapshot. + */ + struct SnapshotData* FirstXactSnapshot; + + /* Current xact's exported snapshots (a list of Snapshot structs) */ + List* exportedSnapshots; + + uint8_t g_output_version; /* Set the default output schema. */ + + int XactIsoLevel; + + /* a string list parsed from GUC variable (uuncontrolled_memory_context),see more @guc.cpp */ + struct memory_context_list* memory_context_limited_white_list; + +#ifdef ENABLE_QUNIT + int qunit_case_number; +#endif + + bool enable_memory_context_control; + + syscalllock deleMemContextMutex; +} knl_u_utils_context; + +typedef struct knl_u_security_context { + /* + * In common cases the same roleid (ie, the session or current ID) will + * be queried repeatedly. So we maintain a simple one-entry cache for + * the status of the last requested roleid. The cache can be flushed + * at need by watching for cache update events on pg_authid. + */ + Oid last_roleid; /* InvalidOid == cache not valid */ + + bool last_roleid_is_super; + + bool last_roleid_is_sysdba; + + bool last_roleid_is_securityadmin; /* Indicates whether a security admin */ + + bool last_roleid_is_auditadmin; /* Indicates whether an audit admin */ + + bool last_roleid_is_monitoradmin; /* Indicates whether a monitor admin */ + + bool last_roleid_is_operatoradmin; /* Indicates whether a operator admin */ + + bool last_roleid_is_policyadmin; /* Indicates whether a policy admin */ + + bool roleid_callback_registered; +} knl_u_security_context; + +typedef struct knl_u_commands_context { + /* Tablespace usage information management struct */ + struct TableSpaceUsageStruct* TableSpaceUsageArray; + bool isUnderCreateForeignTable; + + Oid CurrentExtensionObject; + + List* PendingLibraryDeletes; + TransactionId OldestXmin; + TransactionId FreezeLimit; + struct SeqTableData* seqtab; /* Head of list of SeqTable items */ + /* + * last_used_seq is updated by nextval() to point to the last used + * sequence. + */ + struct SeqTableData* last_used_seq; + + /* Form of the type created during inplace upgrade */ + char TypeCreateType; + + List* label_provider_list; + /* bulkload_compatible_illegal_chars and bulkload_copy_state are to be deleted */ + bool bulkload_compatible_illegal_chars; + + /* + * This variable ought to be a temperary fix for copy to file encoding bug caused by + * our modification to PGXC copy procejure. + */ + struct CopyStateData* bulkload_copy_state; + int dest_encoding_for_copytofile; + bool need_transcoding_for_copytofile; + MemoryContext OBSParserContext; + List* on_commits; + + /* + * Indicate that the top relation is temporary in my session. + * If it is, also we treat its all subordinate relations as temporary and in my session. + * For an example, if a column relation is temporary in my session, + * also its cudesc, cudesc index, delta are temporary and in my session. + */ + bool topRelatationIsInMyTempSession; + Node bogus_marker; /* marks conflicting defaults */ +} knl_u_commands_context; + +const int ELF_MAGIC_CACHE_LEN = 10; +typedef struct FileSlot { + FILE* file; + /* store header of file to detect a elf file */ + char elf_magic[ELF_MAGIC_CACHE_LEN]; + size_t max_linesize; + int encoding; + int32 id; +} FileSlot; + +typedef struct knl_u_contrib_context { + /* for assigning cursor numbers and prepared statement numbers */ + unsigned int cursor_number; + + int current_context_id; + int file_format; // enum DFSFileType + int file_number; + + struct FileSlot* slots; /* initilaized with zeros */ + int32 slotid; /* next slot id */ + int max_linesize; + char* cur_directory; + +} knl_u_contrib_context; + +#define LC_ENV_BUFSIZE (NAMEDATALEN + 20) + +typedef struct knl_u_locale_context { + /* lc_time localization cache */ + char* localized_abbrev_days[7]; + + char* localized_full_days[7]; + + char* localized_abbrev_months[12]; + + char* localized_full_months[12]; + + bool cur_lc_conv_valid; + + bool cur_lc_time_valid; + + struct lconv* cur_lc_conv; + + int lc_ctype_result; + + int lc_collate_result; + + struct HTAB* collation_cache; + + struct lconv current_lc_conv; +} knl_u_locale_context; + +typedef struct knl_u_log_context { + char* syslog_ident; + + char* module_logging_configure; + /* + * msgbuf is declared as static to save the data to put + * which can be flushed in next put_line() + */ + struct StringInfoData* msgbuf; +} knl_u_log_context; + +typedef struct knl_u_mb_context { + bool insertValuesBind_compatible_illegal_chars; + + List* ConvProcList; /* List of ConvProcInfo */ + + /* + * These variables point to the currently active conversion functions, + * or are NULL when no conversion is needed. + */ + struct FmgrInfo* ToServerConvProc; + + struct FmgrInfo* ToClientConvProc; + + NameData datcollate; /* LC_COLLATE setting */ + NameData datctype; /* LC_CTYPE setting */ + + /* + * These variables track the currently selected FE and BE encodings. + */ + struct pg_enc2name* ClientEncoding; + + struct pg_enc2name* DatabaseEncoding; + + struct pg_enc2name* PlatformEncoding; + + /* + * During backend startup we can't set client encoding because we (a) + * can't look up the conversion functions, and (b) may not know the database + * encoding yet either. So SetClientEncoding() just accepts anything and + * remembers it for InitializeClientEncoding() to apply later. + */ + bool backend_startup_complete; + + int pending_client_encoding; +} knl_u_mb_context; + +typedef struct knl_u_plancache_context { + /* + * This is the head of the backend's list of "saved" CachedPlanSources (i.e., + * those that are in long-lived storage and are examined for sinval events). + * We thread the structs manually instead of using List cells so that we can + * guarantee to save a CachedPlanSource without error. + */ + struct CachedPlanSource* first_saved_plan; + /* the head of plancache list not in gpc on cn. */ + struct CachedPlanSource* ungpc_saved_plan; + + /* + * If an unnamed prepared statement exists, it's stored here. + * We keep it separate from the hashtable kept by commands/prepare.c + * in order to reduce overhead for short-lived queries. + */ + struct CachedPlanSource* unnamed_stmt_psrc; + + /* recode if the query contains params, used in pgxc_shippability_walker */ + bool query_has_params; + + /* + * The hash table in which prepared queries are stored. This is + * per-backend: query plans are not shared between backends. + * The keys for this hash table are the arguments to PREPARE and EXECUTE + * (statement names); the entries are PreparedStatement structs. + */ + HTAB* prepared_queries; + + HTAB* stmt_lightproxy_htab; + + HTAB* lightproxy_objs; + + /* + * The hash table used to find OpFusions. + * The keys are portal names; + * the entries are OpFusion pointers. + */ + HTAB* pn_fusion_htab; + +#ifdef PGXC + /* + * The hash table where Datanode prepared statements are stored. + * The keys are statement names referenced from cached RemoteQuery nodes; the + * entries are DatanodeStatement structs + */ + HTAB* datanode_queries; +#endif + char* cur_stmt_name; /* cngpc non lp need set stmt_name in portal run */ + bool gpc_in_ddl; + bool gpc_remote_msg; + bool gpc_first_send; +} knl_u_plancache_context; + +typedef struct knl_u_typecache_context { + /* The main type cache hashtable searched by lookup_type_cache */ + struct HTAB* TypeCacheHash; + + struct HTAB* RecordCacheHash; + + struct tupleDesc** RecordCacheArray; + + int32 RecordCacheArrayLen; /* allocated length of array */ + + int32 NextRecordTypmod; /* number of entries used */ +} knl_u_typecache_context; + +typedef struct knl_u_tscache_context { + struct HTAB* TSParserCacheHash; + + struct TSParserCacheEntry* lastUsedParser; + + struct HTAB* TSDictionaryCacheHash; + + struct TSDictionaryCacheEntry* lastUsedDictionary; + + struct HTAB* TSConfigCacheHash; + + struct TSConfigCacheEntry* lastUsedConfig; + + Oid TSCurrentConfigCache; +} knl_u_tscache_context; + +/* + * Description: + * There are three processing modes in POSTGRES. They are + * BootstrapProcessing or "bootstrap," InitProcessing or + * "initialization," and NormalProcessing or "normal." + * + * The first two processing modes are used during special times. When the + * system state indicates bootstrap processing, transactions are all given + * transaction id "one" and are consequently guaranteed to commit. This mode + * is used during the initial generation of template databases. + * + * Initialization mode: used while starting a backend, until all normal + * initialization is complete. Some code behaves differently when executed + * in this mode to enable system bootstrapping. + * + * If a POSTGRES backend process is in normal mode, then all code may be + * executed normally. + */ + +typedef enum ProcessingMode { + BootstrapProcessing, /* bootstrap creation of template database */ + InitProcessing, /* initializing system */ + NormalProcessing, /* normal processing */ + PostUpgradeProcessing /* Post upgrade to run script */ +} ProcessingMode; + +/* + * node group mode + * now we support two mode: common node group and logic cluster group + */ +typedef enum NodeGroupMode { + NG_UNKNOWN = 0, /* unknown mode */ + NG_COMMON, /* common node group */ + NG_LOGIC, /* logic cluster node group */ +} NodeGroupMode; + +typedef struct knl_u_misc_context { + enum ProcessingMode Mode; + + /* Note: we rely on this to initialize as zeroes */ + char socketLockFile[MAXPGPATH]; + char hasocketLockFile[MAXPGPATH]; + + /* ---------------------------------------------------------------- + * User ID state + * + * We have to track several different values associated with the concept + * of "user ID". + * + * AuthenticatedUserId is determined at connection start and never changes. + * + * SessionUserId is initially the same as AuthenticatedUserId, but can be + * changed by SET SESSION AUTHORIZATION (if AuthenticatedUserIsSuperuser). + * This is the ID reported by the SESSION_USER SQL function. + * + * OuterUserId is the current user ID in effect at the "outer level" (outside + * any transaction or function). This is initially the same as SessionUserId, + * but can be changed by SET ROLE to any role that SessionUserId is a + * member of. (XXX rename to something like CurrentRoleId?) + * + * CurrentUserId is the current effective user ID; this is the one to use + * for all normal permissions-checking purposes. At outer level this will + * be the same as OuterUserId, but it changes during calls to SECURITY + * DEFINER functions, as well as locally in some specialized commands. + * + * SecurityRestrictionContext holds flags indicating reason(s) for changing + * CurrentUserId. In some cases we need to lock down operations that are + * not directly controlled by privilege settings, and this provides a + * convenient way to do it. + * ---------------------------------------------------------------- + */ + Oid AuthenticatedUserId; + + Oid SessionUserId; + + Oid OuterUserId; + + Oid CurrentUserId; + + int SecurityRestrictionContext; + + const char* CurrentUserName; + + /* + * logic cluster information every backend. + */ + Oid current_logic_cluster; + + enum NodeGroupMode current_nodegroup_mode; + + bool nodegroup_callback_registered; + + /* + * Pseudo_CurrentUserId always refers to CurrentUserId, except in executing stored procedure, + * in that case, Pseudo_CurrentUserId refers to the user id that created the stored procedure. + */ + Oid* Pseudo_CurrentUserId; + + /* We also have to remember the superuser state of some of these levels */ + bool AuthenticatedUserIsSuperuser; + + bool SessionUserIsSuperuser; + + /* We also remember if a SET ROLE is currently active */ + bool SetRoleIsActive; + + /* Flag telling that we are loading shared_preload_libraries */ + bool process_shared_preload_libraries_in_progress; + + /* Flag telling that authentication already finish */ + bool authentication_finished; +} knl_misc_context; + +typedef struct knl_u_proc_context { + struct Port* MyProcPort; + + char firstChar = ' '; + + Oid MyRoleId; + + Oid MyDatabaseId; + + Oid MyDatabaseTableSpace; + + /* + * DatabasePath is the path (relative to t_thrd.proc_cxt.DataDir) of my database's + * primary directory, ie, its directory in the default tablespace. + */ + char* DatabasePath; + + bool Isredisworker; + bool IsInnerMaintenanceTools; /* inner tool check flag */ + bool clientIsGsrewind; /* gs_rewind tool check flag */ + bool clientIsGsredis; /* gs_redis tool check flag */ + bool clientIsGsdump; /* gs_dump tool check flag */ + bool clientIsGsCtl; /* gs_ctl tool check flag */ + bool clientIsGsBasebackup; /* gs_basebackup tool check flag */ + bool clientIsGsroach; /* gs_roach tool check flag */ + bool clientIsGsRestore; /* gs_restore tool check flag */ + bool IsBinaryUpgrade; + bool IsWLMWhiteList; /* this proc will not be controled by WLM */ + bool gsRewindAddCount; + bool PassConnLimit; +} knl_u_proc_context; + +/* maximum possible number of fields in a date string */ +#define MAXDATEFIELDS 25 + +typedef struct knl_u_time_context { + /* + * DateOrder defines the field order to be assumed when reading an + * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit + * year field first, is taken to be ambiguous): + * DATEORDER_YMD specifies field order yy-mm-dd + * DATEORDER_DMY specifies field order dd-mm-yy ("European" convention) + * DATEORDER_MDY specifies field order mm-dd-yy ("US" convention) + * + * In the Postgres and SQL DateStyles, DateOrder also selects output field + * order: day comes before month in DMY style, else month comes before day. + * + * The user-visible "DateStyle" run-time parameter subsumes both of these. + */ + int DateStyle; + + int DateOrder; + + /* + * u_sess->time_cxt.HasCTZSet is true if user has set timezone as a numeric offset from UTC. + * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish + * sign convention, ie, positive offset is west of UTC, rather than the + * SQL-ish convention that positive is east of UTC). + */ + bool HasCTZSet; + + int CTimeZone; + + int sz_timezone_tktbl; + + /* + * datetktbl holds date/time keywords. + * + * Note that this table must be strictly alphabetically ordered to allow an + * O(ln(N)) search algorithm to be used. + * + * The text field is NOT guaranteed to be NULL-terminated. + * + * To keep this table reasonably small, we divide the lexval for TZ and DTZ + * entries by 15 (so they are on 15 minute boundaries) and truncate the text + * field at TOKMAXLEN characters. + * Formerly, we divided by 10 rather than 15 but there are a few time zones + * which are 30 or 45 minutes away from an even hour, most are on an hour + * boundary, and none on other boundaries. + * + * The static table contains no TZ or DTZ entries, rather those are loaded + * from configuration files and stored in t_thrd.time_cxt.timezone_tktbl, which has the same + * format as the static datetktbl. + */ + struct datetkn* timezone_tktbl; + + const struct datetkn* datecache[MAXDATEFIELDS]; + + const struct datetkn* deltacache[MAXDATEFIELDS]; + + struct HTAB* timezone_cache; +} knl_u_time_context; + +typedef struct knl_u_upgrade_context { + bool InplaceUpgradeSwitch; + PGDLLIMPORT Oid binary_upgrade_next_etbl_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_array_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_type_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_heap_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_index_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_class_oid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_heap_pg_class_rfoid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_index_pg_class_rfoid; + PGDLLIMPORT Oid binary_upgrade_next_etbl_toast_pg_class_rfoid; + + /* Potentially set by contrib/pg_upgrade_support functions */ + Oid binary_upgrade_next_array_pg_type_oid; + Oid Inplace_upgrade_next_array_pg_type_oid; + + /* Potentially set by contrib/pg_upgrade_support functions */ + Oid binary_upgrade_next_pg_authid_oid; + + Oid binary_upgrade_next_toast_pg_type_oid; + int32 binary_upgrade_max_part_toast_pg_type_oid; + int32 binary_upgrade_cur_part_toast_pg_type_oid; + Oid* binary_upgrade_next_part_toast_pg_type_oid; + Oid binary_upgrade_next_heap_pg_class_oid; + Oid binary_upgrade_next_toast_pg_class_oid; + Oid binary_upgrade_next_heap_pg_class_rfoid; + Oid binary_upgrade_next_toast_pg_class_rfoid; + int32 binary_upgrade_max_part_pg_partition_oid; + int32 binary_upgrade_cur_part_pg_partition_oid; + Oid* binary_upgrade_next_part_pg_partition_oid; + int32 binary_upgrade_max_part_pg_partition_rfoid; + int32 binary_upgrade_cur_part_pg_partition_rfoid; + Oid* binary_upgrade_next_part_pg_partition_rfoid; + int32 binary_upgrade_max_part_toast_pg_class_oid; + int32 binary_upgrade_cur_part_toast_pg_class_oid; + Oid* binary_upgrade_next_part_toast_pg_class_oid; + int32 binary_upgrade_max_part_toast_pg_class_rfoid; + int32 binary_upgrade_cur_part_toast_pg_class_rfoid; + Oid* binary_upgrade_next_part_toast_pg_class_rfoid; + Oid binary_upgrade_next_partrel_pg_partition_oid; + Oid binary_upgrade_next_partrel_pg_partition_rfoid; + Oid Inplace_upgrade_next_heap_pg_class_oid; + Oid Inplace_upgrade_next_toast_pg_class_oid; + Oid binary_upgrade_next_index_pg_class_oid; + Oid binary_upgrade_next_index_pg_class_rfoid; + int32 binary_upgrade_max_part_index_pg_class_oid; + int32 binary_upgrade_cur_part_index_pg_class_oid; + Oid* binary_upgrade_next_part_index_pg_class_oid; + int32 binary_upgrade_max_part_index_pg_class_rfoid; + int32 binary_upgrade_cur_part_index_pg_class_rfoid; + Oid* binary_upgrade_next_part_index_pg_class_rfoid; + int32 bupgrade_max_psort_pg_class_oid; + int32 bupgrade_cur_psort_pg_class_oid; + Oid* bupgrade_next_psort_pg_class_oid; + int32 bupgrade_max_psort_pg_type_oid; + int32 bupgrade_cur_psort_pg_type_oid; + Oid* bupgrade_next_psort_pg_type_oid; + int32 bupgrade_max_psort_array_pg_type_oid; + int32 bupgrade_cur_psort_array_pg_type_oid; + Oid* bupgrade_next_psort_array_pg_type_oid; + int32 bupgrade_max_psort_pg_class_rfoid; + int32 bupgrade_cur_psort_pg_class_rfoid; + Oid* bupgrade_next_psort_pg_class_rfoid; + Oid Inplace_upgrade_next_index_pg_class_oid; + Oid binary_upgrade_next_pg_enum_oid; + Oid Inplace_upgrade_next_general_oid; + int32 bupgrade_max_cudesc_pg_class_oid; + int32 bupgrade_cur_cudesc_pg_class_oid; + Oid* bupgrade_next_cudesc_pg_class_oid; + int32 bupgrade_max_cudesc_pg_type_oid; + int32 bupgrade_cur_cudesc_pg_type_oid; + Oid* bupgrade_next_cudesc_pg_type_oid; + int32 bupgrade_max_cudesc_array_pg_type_oid; + int32 bupgrade_cur_cudesc_array_pg_type_oid; + Oid* bupgrade_next_cudesc_array_pg_type_oid; + int32 bupgrade_max_cudesc_pg_class_rfoid; + int32 bupgrade_cur_cudesc_pg_class_rfoid; + Oid* bupgrade_next_cudesc_pg_class_rfoid; + int32 bupgrade_max_cudesc_index_oid; + int32 bupgrade_cur_cudesc_index_oid; + Oid* bupgrade_next_cudesc_index_oid; + int32 bupgrade_max_cudesc_toast_pg_class_oid; + int32 bupgrade_cur_cudesc_toast_pg_class_oid; + Oid* bupgrade_next_cudesc_toast_pg_class_oid; + int32 bupgrade_max_cudesc_toast_pg_type_oid; + int32 bupgrade_cur_cudesc_toast_pg_type_oid; + Oid* bupgrade_next_cudesc_toast_pg_type_oid; + int32 bupgrade_max_cudesc_toast_index_oid; + int32 bupgrade_cur_cudesc_toast_index_oid; + Oid* bupgrade_next_cudesc_toast_index_oid; + int32 bupgrade_max_cudesc_index_rfoid; + int32 bupgrade_cur_cudesc_index_rfoid; + Oid* bupgrade_next_cudesc_index_rfoid; + int32 bupgrade_max_cudesc_toast_pg_class_rfoid; + int32 bupgrade_cur_cudesc_toast_pg_class_rfoid; + Oid* bupgrade_next_cudesc_toast_pg_class_rfoid; + int32 bupgrade_max_cudesc_toast_index_rfoid; + int32 bupgrade_cur_cudesc_toast_index_rfoid; + Oid* bupgrade_next_cudesc_toast_index_rfoid; + int32 bupgrade_max_delta_toast_pg_class_oid; + int32 bupgrade_cur_delta_toast_pg_class_oid; + Oid* bupgrade_next_delta_toast_pg_class_oid; + int32 bupgrade_max_delta_toast_pg_type_oid; + int32 bupgrade_cur_delta_toast_pg_type_oid; + Oid* bupgrade_next_delta_toast_pg_type_oid; + int32 bupgrade_max_delta_toast_index_oid; + int32 bupgrade_cur_delta_toast_index_oid; + Oid* bupgrade_next_delta_toast_index_oid; + int32 bupgrade_max_delta_toast_pg_class_rfoid; + int32 bupgrade_cur_delta_toast_pg_class_rfoid; + Oid* bupgrade_next_delta_toast_pg_class_rfoid; + int32 bupgrade_max_delta_toast_index_rfoid; + int32 bupgrade_cur_delta_toast_index_rfoid; + Oid* bupgrade_next_delta_toast_index_rfoid; + int32 bupgrade_max_delta_pg_class_oid; + int32 bupgrade_cur_delta_pg_class_oid; + Oid* bupgrade_next_delta_pg_class_oid; + int32 bupgrade_max_delta_pg_type_oid; + int32 bupgrade_cur_delta_pg_type_oid; + Oid* bupgrade_next_delta_pg_type_oid; + int32 bupgrade_max_delta_array_pg_type_oid; + int32 bupgrade_cur_delta_array_pg_type_oid; + Oid* bupgrade_next_delta_array_pg_type_oid; + int32 bupgrade_max_delta_pg_class_rfoid; + int32 bupgrade_cur_delta_pg_class_rfoid; + Oid* bupgrade_next_delta_pg_class_rfoid; + Oid Inplace_upgrade_next_pg_proc_oid; + Oid Inplace_upgrade_next_pg_namespace_oid; + Oid binary_upgrade_next_pg_type_oid; + Oid Inplace_upgrade_next_pg_type_oid; + bool new_catalog_isshared; + bool new_catalog_need_storage; + List* new_shared_catalog_list; +} knl_u_upgrade_context; + +typedef struct knl_u_bootstrap_context { +#define MAXATTR 40 +#define NAMEDATALEN 64 + int num_columns_read; + int yyline; /* line number for error reporting */ + + struct RelationData* boot_reldesc; /* current relation descriptor */ + struct FormData_pg_attribute* attrtypes[MAXATTR]; /* points to attribute info */ + int numattr; /* number of attributes for cur. rel */ + + struct typmap** Typ; + struct typmap* Ap; + + MemoryContext nogc; /* special no-gc mem context */ + struct _IndexList* ILHead; + char newStr[NAMEDATALEN + 1]; /* array type names < NAMEDATALEN long */ +} knl_u_bootstrap_context; + +typedef enum { + IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */ + IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */ + IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */ +} IdentifierLookup; + +typedef struct knl_u_xact_context { + struct XactCallbackItem* Xact_callbacks; + struct SubXactCallbackItem* SubXact_callbacks; +#ifdef PGXC + struct abort_callback_type* dbcleanup_info; +#endif + + /* + * GID to be used for preparing the current transaction. This is also + * global to a whole transaction, so we don't keep it in the state stack. + */ + char* prepareGID; + char* savePrepareGID; + + bool pbe_execute_complete; +} knl_u_xact_context; + +typedef struct knl_u_plpgsql_context { + bool inited; + /* pl_comp.cpp */ + /* A context for func to store in one session. */ + MemoryContext plpgsql_func_cxt; + /* ---------- + * Hash table for compiled functions + * ---------- + */ + HTAB* plpgsql_HashTable; + /* list of functions' cell. */ + DList* plpgsql_dlist_functions; + + int datums_alloc; + int plpgsql_nDatums; + int datums_last; + int plpgsql_IndexErrorVariable; + char* plpgsql_error_funcname; + bool plpgsql_DumpExecTree; + bool plpgsql_check_syntax; + /* A context appropriate for short-term allocs during compilation */ + MemoryContext compile_tmp_cxt; + struct PLpgSQL_stmt_block* plpgsql_parse_result; + struct PLpgSQL_datum** plpgsql_Datums; + struct PLpgSQL_function* plpgsql_curr_compile; + + /* pl_exec.cpp */ + struct EState* simple_eval_estate; + struct SimpleEcontextStackEntry* simple_econtext_stack; + + /* + * "context_array" is allocated from top_transaction_mem_cxt, but the variables inside + * of SQLContext is created under "SQLContext Entry" memory context. + */ + List* context_array; + + /* pl_handler.cpp */ + int plpgsql_variable_conflict; + /* Hook for plugins */ + struct PLpgSQL_plugin** plugin_ptr; + + /* pl_funcs.cpp */ + int dump_indent; + + /* pl_funcs.cpp */ + /* ---------- + * Local variables for namespace handling + * + * The namespace structure actually forms a tree, of which only one linear + * list or "chain" (from the youngest item to the root) is accessible from + * any one plpgsql statement. During initial parsing of a function, ns_top + * points to the youngest item accessible from the block currently being + * parsed. We store the entire tree, however, since at runtime we will need + * to access the chain that's relevant to any one statement. + * + * Block boundaries in the namespace chain are marked by PLPGSQL_NSTYPE_LABEL + * items. + * ---------- + */ + struct PLpgSQL_nsitem* ns_top; + + /* pl_scanner.cpp */ + /* Klugy flag to tell scanner how to look up identifiers */ + IdentifierLookup plpgsql_IdentifierLookup; + /* + * Scanner working state. At some point we might wish to fold all this + * into a YY_EXTRA struct. For the moment, there is no need for plpgsql's + * lexer to be re-entrant, and the notational burden of passing a yyscanner + * pointer around is great enough to not want to do it without need. + */ + + /* The stuff the core lexer needs(core_yyscan_t) */ + void* yyscanner; + struct core_yy_extra_type* core_yy; + + /* The original input string */ + const char* scanorig; + + /* Current token's length (corresponds to plpgsql_yylval and plpgsql_yylloc) */ + int plpgsql_yyleng; + + /* Token pushback stack */ +#define MAX_PUSHBACKS 4 + + int num_pushbacks; + int pushback_token[MAX_PUSHBACKS]; + + /* State for plpgsql_location_to_lineno() */ + const char* cur_line_start; + const char* cur_line_end; + int cur_line_num; + List* goto_labels; + + struct HTAB* rendezvousHash; + + /* dbe.output buffer limit */ + uint32 dbe_output_buffer_limit; + + bool is_delete_function; +} knl_u_plpgsql_context; + +typedef struct knl_u_postgres_context { + /* + * Flags to implement skip-till-Sync-after-error behavior for messages of + * the extended query protocol. + */ + bool doing_extended_query_message; + bool ignore_till_sync; +} knl_u_postgres_context; + +typedef struct knl_u_stat_context { + char* pgstat_stat_filename; + char* pgstat_stat_tmpname; + + struct HTAB* pgStatDBHash; + struct TabStatusArray* pgStatTabList; + + /* + * BgWriter global statistics counters (unused in other processes). + * Stored directly in a stats message structure so it can be sent + * without needing to copy things around. We assume this inits to zeroes. + */ + struct PgStat_MsgBgWriter* BgWriterStats; + + /* + * Hash table for O(1) t_id -> tsa_entry lookup + */ + HTAB* pgStatTabHash; + /* MemoryContext for pgStatTabHash */ + MemoryContext pgStatTabHashContext; + + /* + * Backends store per-function info that's waiting to be sent to the collector + * in this hash table (indexed by function OID). + */ + struct HTAB* pgStatFunctions; + + /* + * Indicates if backend has some function stats that it hasn't yet + * sent to the collector. + */ + bool have_function_stats; + + bool pgStatRunningInCollector; + + struct PgStat_SubXactStatus* pgStatXactStack; + + int pgStatXactCommit; + + int pgStatXactRollback; + + int64 pgStatBlockReadTime; + + int64 pgStatBlockWriteTime; + + struct PgBackendStatus* localBackendStatusTable; + + int localNumBackends; + + /* + * Cluster wide statistics, kept in the stats collector. + * Contains statistics that are not collected per database + * or per table. + */ + struct PgStat_GlobalStats* globalStats; + + /* + * Total time charged to functions so far in the current backend. + * We use this to help separate "self" and "other" time charges. + * (We assume this initializes to zero.) + */ + instr_time total_func_time; + + struct HTAB* analyzeCheckHash; + + union NumericValue* osStatDataArray; + struct OSRunInfoDesc* osStatDescArray; + TimestampTz last_report; + bool isTopLevelPlSql; + int64* localTimeInfoArray; + uint64* localNetInfo; + + MemoryContext pgStatLocalContext; + MemoryContext pgStatCollectThdStatusContext; + + /* Track memory usage in chunks at individual session level */ + int32 trackedMemChunks; + + /* Track memory usage in bytes at individual session level */ + int64 trackedBytes; + + List* hotkeyCandidates; + MemoryContext hotkeySessContext; +} knl_u_stat_context; + +#define MAX_LOCKMETHOD 2 + +typedef uint16 CycleCtr; +typedef void* Block; +typedef struct knl_u_storage_context { + /* + * How many buffers PrefetchBuffer callers should try to stay ahead of their + * ReadBuffer calls by. This is maintained by the assign hook for + * effective_io_concurrency. Zero means "never prefetch". + */ + int target_prefetch_pages; + + volatile bool session_timeout_active; + /* session_fin_time is valid only if session_timeout_active is true */ + TimestampTz session_fin_time; + + /* Number of file descriptors known to be in use by VFD entries. */ + int nfile; + + /* + * Flag to tell whether it's worth scanning VfdCache looking for temp files + * to close + */ + bool have_xact_temporary_files; + /* + * Tracks the total size of all temporary files. Note: when temp_file_limit + * is being enforced, this cannot overflow since the limit cannot be more + * than INT_MAX kilobytes. When not enforcing, it could theoretically + * overflow, but we don't care. + */ + uint64 temporary_files_size; + int numAllocatedDescs; + int maxAllocatedDescs; + struct AllocateDesc* allocatedDescs; + /* + * Number of temporary files opened during the current session; + * this is used in generation of tempfile names. + */ + long tempFileCounter; + /* + * Array of OIDs of temp tablespaces. When numTempTableSpaces is -1, + * this has not been set in the current transaction. + */ + Oid* tempTableSpaces; + int numTempTableSpaces; + int nextTempTableSpace; + /* record how many IO request submit in async mode, because if error happen, + * we should distinguish which IOs has been submit, if not, the resource clean will + * meet error like ref_count, flags + * remember set AsyncSubmitIOCount to 0 after resource clean up sucessfully + */ + int AsyncSubmitIOCount; + + /* + * Virtual File Descriptor array pointer and size. This grows as + * needed. 'File' values are indexes into this array. + * Note that VfdCache[0] is not a usable VFD, just a list header. + */ + struct vfd* VfdCache; + Size SizeVfdCache; + + /* + * Each backend has a hashtable that stores all extant SMgrRelation objects. + * In addition, "unowned" SMgrRelation objects are chained together in a list. + */ + struct HTAB* SMgrRelationHash; + dlist_head unowned_reln; + + MemoryContext MdCxt; /* context for all md.c allocations */ + struct HTAB* pendingOpsTable; + List* pendingUnlinks; + CycleCtr mdsync_cycle_ctr; + CycleCtr mdckpt_cycle_ctr; + bool mdsync_in_progress; + + LocalTransactionId nextLocalTransactionId; + + /* + * Whether current session is holding a session lock after transaction commit. + * This may appear ugly, but since at present all lock information is stored in + * per-thread pgproc, we should not decouple session from thread if session lock + * is held. + * We now set this flag at LockReleaseAll phase during transaction commit or abort. + * As a result, all callbackups for releasing session locks should come before it. + */ + bool holdSessionLock[MAX_LOCKMETHOD]; + + /* true if datanode is within the process of two phase commit */ + bool twoPhaseCommitInProgress; + int32 dumpHashbucketIdNum; + int2 *dumpHashbucketIds; + + /* Pointers to shared state */ + // struct BufferStrategyControl* StrategyControl; + int NLocBuffer; /* until buffers are initialized */ + struct BufferDesc* LocalBufferDescriptors; + Block* LocalBufferBlockPointers; + int32* LocalRefCount; + int nextFreeLocalBuf; + struct HTAB* LocalBufHash; + char* cur_block; + int next_buf_in_block; + int num_bufs_in_block; + int total_bufs_allocated; + MemoryContext LocalBufferContext; +} knl_u_storage_context; + + +typedef struct knl_u_libpq_context { + /* + * LO "FD"s are indexes into the cookies array. + * + * A non-null entry is a pointer to a LargeObjectDesc allocated in the + * LO private memory context "fscxt". The cookies array itself is also + * dynamically allocated in that context. Its current allocated size is + * cookies_len entries, of which any unused entries will be NULL. + */ + struct LargeObjectDesc** cookies; + int cookies_size; + MemoryContext fscxt; + GS_UCHAR* server_key; + + /* + * These variables hold the pre-parsed contents of the ident usermap + * configuration file. ident_lines is a triple-nested list of lines, fields + * and tokens, as returned by tokenize_file. There will be one line in + * ident_lines for each (non-empty, non-comment) line of the file. Note there + * will always be at least one field, since blank lines are not entered in the + * data structure. ident_line_nums is an integer list containing the actual + * line number for each line represented in ident_lines. ident_context is + * the memory context holding all this. + */ + List* ident_lines; + List* ident_line_nums; + MemoryContext ident_context; + bool IsConnFromCmAgent; +#ifdef USE_SSL + bool ssl_loaded_verify_locations; + bool ssl_initialized; + SSL_CTX* SSL_server_context; +#endif +} knl_u_libpq_context; + +typedef struct knl_u_relcache_context { + struct HTAB* RelationIdCache; + + /* + * This flag is false until we have prepared the critical relcache entries + * that are needed to do indexscans on the tables read by relcache building. + * Should be used only by relcache.c and catcache.c + */ + bool criticalRelcachesBuilt; + + /* + * This flag is false until we have prepared the critical relcache entries + * for shared catalogs (which are the tables needed for login). + * Should be used only by relcache.c and postinit.c + */ + bool criticalSharedRelcachesBuilt; + + /* + * This counter counts relcache inval events received since backend startup + * (but only for rels that are actually in cache). Presently, we use it only + * to detect whether data about to be written by write_relcache_init_file() + * might already be obsolete. + */ + long relcacheInvalsReceived; + + /* + * This list remembers the OIDs of the non-shared relations cached in the + * database's local relcache init file. Note that there is no corresponding + * list for the shared relcache init file, for reasons explained in the + * comments for RelationCacheInitFileRemove. + */ + List* initFileRelationIds; + + /* + * This flag lets us optimize away work in AtEO(Sub)Xact_RelationCache(). + */ + bool need_eoxact_work; + + HTAB* OpClassCache; + + struct tupleDesc* pgclassdesc; + + struct tupleDesc* pgindexdesc; + + /* + * BucketMap Cache, consists of a list of BucketMapCache element. + * Location information of every rel cache is actually pointed to these list + * members. + * Attention: we need to invalidate bucket map caches when accepting + * SI messages of tuples in PGXC_GROUP or SI reset messages! + */ + List* g_bucketmap_cache; + uint32 max_bucket_map_size; +} knl_u_relcache_context; + +#if defined(HAVE_SETPROCTITLE) +#define PS_USE_SETPROCTITLE +#elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD) +#define PS_USE_PSTAT +#elif defined(HAVE_PS_STRINGS) +#define PS_USE_PS_STRINGS +#elif (defined(BSD) || defined(__hurd__)) && !defined(__darwin__) +#define PS_USE_CHANGE_ARGV +#elif defined(__linux__) || defined(_AIX) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(ultrix) || \ + defined(__ksr__) || defined(__osf__) || defined(__svr5__) || defined(__darwin__) +#define PS_USE_CLOBBER_ARGV +#elif defined(WIN32) +#define PS_USE_WIN32 +#else +#define PS_USE_NONE +#endif + +typedef struct knl_u_ps_context { +#ifndef PS_USE_CLOBBER_ARGV +/* all but one option need a buffer to write their ps line in */ +#define PS_BUFFER_SIZE 256 + char ps_buffer[PS_BUFFER_SIZE]; + size_t ps_buffer_size; +#else /* PS_USE_CLOBBER_ARGV */ + char* ps_buffer; /* will point to argv area */ + size_t ps_buffer_size; /* space determined at run time */ + size_t last_status_len; /* use to minimize length of clobber */ +#endif /* PS_USE_CLOBBER_ARGV */ + size_t ps_buffer_cur_len; /* nominal strlen(ps_buffer) */ + size_t ps_buffer_fixed_size; /* size of the constant prefix */ + + /* save the original argv[] location here */ + int save_argc; + char** save_argv; +} knl_u_ps_context; + +typedef struct ParctlState { + unsigned char global_reserve; /* global reserve active statement flag */ + unsigned char rp_reserve; /* resource pool reserve active statement flag */ + unsigned char reserve; /* reserve active statement flag */ + unsigned char release; /* release active statement flag */ + unsigned char global_release; /* global release active statement */ + unsigned char rp_release; /* resource pool release active statement */ + unsigned char except; /* a flag to handle exception while the query executing */ + unsigned char special; /* check the query whether is a special query */ + unsigned char transact; /* check the query whether is in a transaction block*/ + unsigned char transact_begin; /* check the query if "begin transaction" */ + unsigned char simple; /* check the query whether is a simple query */ + unsigned char iocomplex; /* check the query whether is a IO simple query */ + unsigned char enqueue; /* check the query whether do global parallel control */ + unsigned char errjmp; /* this is error jump point */ + unsigned char global_waiting; /* waiting in the global list */ + unsigned char respool_waiting; /* waiting in the respool list */ + unsigned char preglobal_waiting; /* waiting in simple global list */ + unsigned char central_waiting; /* waiting in central_waiting */ + unsigned char attach; /* attach cgroup */ + unsigned char subquery; /* check the query whether is in a stored procedure */ + +} ParctlState; + +typedef struct knl_u_relmap_context { + /* + * The currently known contents of the shared map file and our database's + * local map file are stored here. These can be reloaded from disk + * immediately whenever we receive an update sinval message. + */ + struct RelMapFile* shared_map; + struct RelMapFile* local_map; + + /* + * We use the same RelMapFile data structure to track uncommitted local + * changes in the mappings (but note the magic and crc fields are not made + * valid in these variables). Currently, map updates are not allowed within + * subtransactions, so one set of transaction-level changes is sufficient. + * + * The active_xxx variables contain updates that are valid in our transaction + * and should be honored by RelationMapOidToFilenode. The pending_xxx + * variables contain updates we have been told about that aren't active yet; + * they will become active at the next CommandCounterIncrement. This setup + * lets map updates act similarly to updates of pg_class rows, ie, they + * become visible only at the next CommandCounterIncrement boundary. + */ + struct RelMapFile* active_shared_updates; + struct RelMapFile* active_local_updates; + struct RelMapFile* pending_shared_updates; + struct RelMapFile* pending_local_updates; + + /* Hash table for informations about each relfilenode <-> oid pair */ + struct HTAB* RelfilenodeMapHash; +} knl_u_relmap_context; + +typedef struct knl_u_unique_sql_context { + /* each sql should have one unique query id + * limitation: Query* is needed by calculating unique query id, + * and Query * is generated after parsing and + * rewriting SQL, so unique query id only can be used + * after SQL rewrite + */ + uint64 unique_sql_id; + Oid unique_sql_user_id; + uint32 unique_sql_cn_id; + + /* + * storing unique sql start time, + * in PortalRun method, we will update unique sql elapse time, + * use it to store the start time. + * + * Note: as in exec_simple_query, we can get multi parsetree, + * and will generate multi the unique sql id, so we set + * unique_sql_start_time at each LOOP(parsetree) started + * + * exec_simple_query + * + * pg_parse_query(parsetree List) + * + * LOOP start + * ****-> set unique_sql_start_time + * pg_analyze_and_rewrite + * analyze + * rewrite + * pg_plan_queries + * PortalStart + * PortalRun + * ****-> UpdateUniqueSQLStat/UpdateUniqueSQLElapseTime + * PortalDrop + * + * LOOP end + */ + int64 unique_sql_start_time; + + /* unique sql's returned rows counter, only updated on CN */ + uint64 unique_sql_returned_rows_counter; + + /* parse counter, both CN and DN can update the counter */ + uint64 unique_sql_soft_parse; + uint64 unique_sql_hard_parse; + + /* + * last_stat_counter - store pgStatTabList's total counter values when + * exit from pgstat_report_stat last time + * current_table_counter - store current unique sql id's row activity stat + */ + struct PgStat_TableCounts* last_stat_counter; + struct PgStat_TableCounts* current_table_counter; + + /* + * handle multi SQLs case in exec_simple_query function, + * for below case: + * - we send sqls "select * from xx; update xx;" using libpq + * PQexec method(refer to gs_ctl tool) + * - then exec_simple_query will get two SQLs + * - pg_parse_query will generate parsetree list with two nodes + * - then run twice: + * # call unique_sql_post_parse_analyze(generate unique sql id/ + * normalized sql string) + * -- here we get the sql using debug_query_string or ParseState.p_sourcetext + * -- but the two way to get sql string will be two SQLs, not single one + * -- so we need add below two variables to handle this case + * # call PortalDefineQuery + * # call PortalRun -> update unique sql stat + */ + bool is_multi_unique_sql; + char* curr_single_unique_sql; + + /* + * for case unique sql track type is 'UNIQUE_SQL_TRACK_TOP' + * main logic(only happened on CN): + * - postgresmain + * >> is_top_unique_sql = false + * + * - sql parse -> generate unique sql id(top SQL) + * >> is_top_unique_sql = true + * + * - exec_simple_query + * or exec_bind_message + * >> PortalRun -> using TOP SQL's unique sql id(will sned to DN) + * + * - is_top_unique_sql to false + */ + bool is_top_unique_sql; + bool need_update_calls; +} knl_u_unique_sql_context; + +typedef struct knl_u_percentile_context { + struct SqlRTInfo* LocalsqlRT; + int LocalCounter; +} knl_u_percentile_context; + +#define STATEMENT_SQL_KIND 2 +typedef struct knl_u_statement_context { + int statement_level[STATEMENT_SQL_KIND]; /* diff levels for full or slow SQL */ + + /* basic information, should not be changed during one session */ + char* db_name; /* which database */ + char* user_name; /* client's user name */ + char* client_addr; /* client's IP address */ + int client_port; /* client's port */ + uint64 session_id; /* session's identifier */ + + + void *curStatementMetrics; /* current Statement handler to record metrics */ + int allocatedCxtCnt; /* how many of handers allocated */ + List toFreeStatementList; /* handers to be freed. */ + List suspendStatementList; /* handers to be flushed into system table */ + syscalllock list_protect; /* concurrency control for above two lists */ + MemoryContext stmt_stat_cxt; /* statement stat context */ +} knl_u_statement_context; + +struct Qid_key { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ +}; + +struct SlowQueryInfo { + uint64 unique_sql_id; + uint64 debug_query_sql_id; + int64* localTimeInfoArray; + struct PgStat_TableCounts* current_table_counter; + uint64 n_returned_rows; +}; + + +typedef struct knl_u_slow_query_context { + SlowQueryInfo slow_query; +} knl_u_slow_query_context; + +typedef struct knl_u_user_login_context { + /* + * when user is login, will update the variable in PerformAuthentication, + * and update the user's login counter. + * + * when proc exit, we register the callback function, in the callback + * function, will update the logout counter, and reset CurrentInstrLoginUserOid. + */ + Oid CurrentInstrLoginUserOid; +} knl_u_user_login_context; + +#define MAXINVALMSGS 32 +typedef struct knl_u_inval_context { + int32 deepthInAcceptInvalidationMessage; + + struct TransInvalidationInfo* transInvalInfo; + + union SharedInvalidationMessage* SharedInvalidMessagesArray; + + int numSharedInvalidMessagesArray; + + int maxSharedInvalidMessagesArray; + + struct SYSCACHECALLBACK* syscache_callback_list; + + int syscache_callback_count; + + struct RELCACHECALLBACK* relcache_callback_list; + + int relcache_callback_count; + + struct PARTCACHECALLBACK* partcache_callback_list; + + int partcache_callback_count; + + uint64 SharedInvalidMessageCounter; + + volatile sig_atomic_t catchupInterruptPending; + + union SharedInvalidationMessage* messages; + + volatile int nextmsg; + + volatile int nummsgs; +} knl_u_inval_context; + +typedef struct knl_u_cache_context { + /* num of cached re's(regular expression) */ + int num_res; + + /* cached re's (regular expression) */ + struct cached_re_str* re_array; + + /* + * We frequently need to test whether a given role is a member of some other + * role. In most of these tests the "given role" is the same, namely the + * active current user. So we can optimize it by keeping a cached list of + * all the roles the "given role" is a member of, directly or indirectly. + * The cache is flushed whenever we detect a change in pg_auth_members. + * + * There are actually two caches, one computed under "has_privs" rules + * (do not recurse where rolinherit isn't true) and one computed under + * "is_member" rules (recurse regardless of rolinherit). + * + * Possibly this mechanism should be generalized to allow caching membership + * info for multiple roles? + * + * The has_privs cache is: + * cached_privs_role is the role OID the cache is for. + * cached_privs_roles is an OID list of roles that cached_privs_role + * has the privileges of (always including itself). + * The cache is valid if cached_privs_role is not InvalidOid. + * + * The is_member cache is similarly: + * cached_member_role is the role OID the cache is for. + * cached_membership_roles is an OID list of roles that cached_member_role + * is a member of (always including itself). + * The cache is valid if cached_member_role is not InvalidOid. + */ + Oid cached_privs_role; + + List* cached_privs_roles; + + Oid cached_member_role; + + List* cached_membership_roles; + + struct _SPI_plan* plan_getrulebyoid; + + struct _SPI_plan* plan_getviewrule; + + /* Hash table for informations about each attribute's options */ + struct HTAB* att_opt_cache_hash; + + /* Cache management header --- pointer is NULL until created */ + struct CatCacheHeader* cache_header; + + /* Hash table for information about each tablespace */ + struct HTAB* TableSpaceCacheHash; + + struct HTAB* PartitionIdCache; + + struct HTAB* BucketIdCache; + + struct HTAB* dn_hash_table; + + bool part_cache_need_eoxact_work; + + bool bucket_cache_need_eoxact_work; + +} knl_u_cache_context; + + +typedef struct knl_u_syscache_context { + MemoryContext SysCacheMemCxt; + + struct CatCache** SysCache; + + bool CacheInitialized; + + Oid* SysCacheRelationOid; + +} knl_u_syscache_context; + +namespace dfs { +class DFSConnector; +} +typedef struct knl_u_catalog_context { + bool nulls[4]; + struct PartitionIdentifier* route; + + /* + * If "Create function ... LANGUAGE SQL" include agg function, agg->aggtype + * is the final aggtype. While for "Select agg()", agg->aggtype should be agg->aggtrantype. + * Here we use Parse_sql_language to distinguish these two cases. + */ + bool Parse_sql_language; + struct PendingRelDelete* pendingDeletes; /* head of linked list */ + /* Handle deleting BCM files. + * + * For column relation, one bcm file for each column file. + * For row relation, only one bcm file for the whole relation. + * We have to handle BCM files of some column file during rollback. + * Take an example, ADD COLUMN or SET TABLESPACE, may be canceled by user in some cases. + * Shared buffer must be invalided before BCM files are deleted. + * See also CStoreCopyColumnDataEnd(), RelationDropStorage(), ect. + */ + struct RelFileNodeBackend* ColMainFileNodes; + int ColMainFileNodesMaxNum; + int ColMainFileNodesCurNum; + List* pendingDfsDeletes; + dfs::DFSConnector* delete_conn; + struct StringInfoData* vf_store_root; + Oid currentlyReindexedHeap; + Oid currentlyReindexedIndex; + List* pendingReindexedIndexes; + /* These variables define the actually active state: */ + List* activeSearchPath; + /* default place to create stuff; if InvalidOid, no default */ + Oid activeCreationNamespace; + /* if TRUE, activeCreationNamespace is wrong, it should be temp namespace */ + bool activeTempCreationPending; + /* These variables are the values last derived from namespace_search_path: */ + List* baseSearchPath; + Oid baseCreationNamespace; + bool baseTempCreationPending; + Oid namespaceUser; + /* The above four values are valid only if baseSearchPathValid */ + bool baseSearchPathValid; + List* overrideStack; + bool overrideStackValid; + Oid myTempNamespaceOld; + /* + * myTempNamespace is InvalidOid until and unless a TEMP namespace is set up + * in a particular backend session (this happens when a CREATE TEMP TABLE + * command is first executed). Thereafter it's the OID of the temp namespace. + * + * myTempToastNamespace is the OID of the namespace for my temp tables' toast + * tables. It is set when myTempNamespace is, and is InvalidOid before that. + * + * myTempNamespaceSubID shows whether we've created the TEMP namespace in the + * current subtransaction. The flag propagates up the subtransaction tree, + * so the main transaction will correctly recognize the flag if all + * intermediate subtransactions commit. When it is InvalidSubTransactionId, + * we either haven't made the TEMP namespace yet, or have successfully + * committed its creation, depending on whether myTempNamespace is valid. + */ + Oid myTempNamespace; + Oid myTempToastNamespace; + bool deleteTempOnQuiting; + SubTransactionId myTempNamespaceSubID; + /* stuff for online expansion redis-cancel */ + bool redistribution_cancelable; +} knl_u_catalog_context; + +typedef struct knl_u_pgxc_context { + /* Current size of dn_handles and co_handles */ + int NumDataNodes; + int NumCoords; + int NumStandbyDataNodes; + + /* Number of connections held */ + int datanode_count; + int coord_count; + + /* dn oid matrics for multiple standby deployment */ + Oid** dn_matrics; + int dn_num; + int standby_num; + + /* + * Datanode handles saved in session memory context + * when PostgresMain is launched. + * Those handles are used inside a transaction by Coordinator to Datanodes. + */ + struct pgxc_node_handle* dn_handles; + /* + * Coordinator handles saved in session memory context + * when PostgresMain is launched. + * Those handles are used inside a transaction by Coordinator to Coordinators + */ + struct pgxc_node_handle* co_handles; + + struct RemoteXactState* remoteXactState; + + int PGXCNodeId; + /* + * When a particular node starts up, store the node identifier in this variable + * so that we dont have to calculate it OR do a search in cache any where else + * This will have minimal impact on performance + */ + uint32 PGXCNodeIdentifier; + + /* + * List of PGXCNodeHandle to track readers and writers involved in the + * current transaction + */ + List* XactWriteNodes; + List* XactReadNodes; + char* preparedNodes; + + /* Pool */ + char sock_path[MAXPGPATH]; + int last_reported_send_errno; + bool PoolerResendParams; + struct PGXCNodeConnectionInfo* PoolerConnectionInfo; + struct PoolAgent* poolHandle; + + List* connection_cache; + List* connection_cache_handle; + + bool is_gc_fdw; + bool is_gc_fdw_analyze; + int gc_fdw_current_idx; + int gc_fdw_max_idx; + int gc_fdw_run_version; + struct SnapshotData* gc_fdw_snapshot; +} knl_u_pgxc_context; + +typedef struct knl_u_fmgr_context { + struct df_files_init* file_list_init; + + struct df_files_init* file_init_tail; + +} knl_u_fmgr_context; + +typedef struct knl_u_erand_context { + unsigned short rand48_seed[3]; +} knl_u_erand_context; + +typedef struct knl_u_regex_context { + int pg_regex_strategy; /* enum PG_Locale_Strategy */ + Oid pg_regex_collation; + struct pg_ctype_cache* pg_ctype_cache_list; +} knl_u_regex_context; + +#ifdef ENABLE_MOT +namespace MOT { + class SessionContext; + class TxnManager; +} + +namespace JitExec { + struct JitContext; + struct JitContextPool; +} + +namespace tvm { + class JitIf; + class JitWhile; + class JitDoWhile; +} + +namespace llvm { + class JitIf; + class JitWhile; + class JitDoWhile; +} + +typedef struct knl_u_mot_context { + bool callbacks_set; + + // session attributes + uint32_t session_id; + uint32_t connection_id; + MOT::SessionContext* session_context; + MOT::TxnManager* txn_manager; + + // JIT + JitExec::JitContextPool* jit_session_context_pool; + uint32_t jit_context_count; + llvm::JitIf* jit_llvm_if_stack; + llvm::JitWhile* jit_llvm_while_stack; + llvm::JitDoWhile* jit_llvm_do_while_stack; + tvm::JitIf* jit_tvm_if_stack; + tvm::JitWhile* jit_tvm_while_stack; + tvm::JitDoWhile* jit_tvm_do_while_stack; + JitExec::JitContext* jit_context; + MOT::TxnManager* jit_txn; +} knl_u_mot_context; +#endif + +typedef struct knl_u_gtt_context { + bool gtt_cleaner_exit_registered; + HTAB* gtt_storage_local_hash; + MemoryContext gtt_relstats_context; + + /* relfrozenxid of all gtts in the current session */ + List* gtt_session_relfrozenxid_list; + TransactionId gtt_session_frozenxid; + pg_on_exit_callback gtt_sess_exit; +} knl_u_gtt_context; + +enum knl_ext_fdw_type { + MYSQL_TYPE_FDW, + ORACLE_TYPE_FDW, + POSTGRES_TYPE_FDW, + /* Add new external FDW type before MAX_TYPE_FDW */ + MAX_TYPE_FDW +}; + +typedef struct knl_u_ext_fdw_context { + void* connList; /* Connection info to other DB */ + pg_on_exit_callback fdwExitFunc; /* Exit callback, will be called when session exit */ +} knl_u_ext_fdw_context; + +enum knl_session_status { + KNL_SESS_FAKE, + KNL_SESS_UNINIT, + KNL_SESS_ATTACH, + KNL_SESS_DETACH, + KNL_SESS_CLOSE, + KNL_SESS_END_PHASE1, + KNL_SESS_CLOSERAW, // not initialize and +}; + +typedef struct sess_orient{ + uint64 cn_sessid; + uint32 cn_timeline; + uint32 cn_nodeid; +}sess_orient; + +typedef struct knl_session_context { + volatile knl_session_status status; + Dlelem elem; + + ThreadId attachPid; + + MemoryContext top_mem_cxt; + MemoryContext cache_mem_cxt; + MemoryContext top_transaction_mem_cxt; + MemoryContext self_mem_cxt; + MemoryContext top_portal_cxt; + MemoryContextGroup* mcxt_group; + /* temp_mem_cxt is a context which will be reset when the session attach to a thread */ + MemoryContext temp_mem_cxt; + int session_ctr_index; + uint64 session_id; + uint64 debug_query_id; + List* ts_cached_queryid; + + //use this to identify which cn connection to. + sess_orient sess_ident; + uint32 cn_session_abort_count; + long cancel_key; + char* prog_name; + + bool ClientAuthInProgress; + + bool need_report_top_xid; + + struct config_generic** guc_variables; + + int num_guc_variables; + + int on_sess_exit_index; + + knl_session_attr attr; + struct knl_u_wlm_context* wlm_cxt; + knl_u_analyze_context analyze_cxt; + knl_u_cache_context cache_cxt; + knl_u_catalog_context catalog_cxt; + knl_u_commands_context cmd_cxt; + knl_u_contrib_context contrib_cxt; + knl_u_erand_context rand_cxt; + knl_u_executor_context exec_cxt; + knl_u_fmgr_context fmgr_cxt; + knl_u_index_context index_cxt; + knl_u_instrument_context instr_cxt; + knl_u_inval_context inval_cxt; + knl_u_locale_context lc_cxt; + knl_u_log_context log_cxt; + knl_u_libpq_context libpq_cxt; + knl_u_mb_context mb_cxt; + knl_u_misc_context misc_cxt; + knl_u_optimizer_context opt_cxt; + knl_u_parser_context parser_cxt; + knl_u_pgxc_context pgxc_cxt; + knl_u_plancache_context pcache_cxt; + knl_u_plpgsql_context plsql_cxt; + knl_u_postgres_context postgres_cxt; + knl_u_proc_context proc_cxt; + knl_u_ps_context ps_cxt; + knl_u_regex_context regex_cxt; + knl_u_xact_context xact_cxt; + knl_u_sig_context sig_cxt; + knl_u_SPI_context SPI_cxt; + knl_u_relcache_context relcache_cxt; + knl_u_relmap_context relmap_cxt; + knl_u_stat_context stat_cxt; + knl_u_storage_context storage_cxt; + knl_u_stream_context stream_cxt; + knl_u_syscache_context syscache_cxt; + knl_u_time_context time_cxt; + knl_u_trigger_context tri_cxt; + knl_u_tscache_context tscache_cxt; + knl_u_typecache_context tycache_cxt; + knl_u_upgrade_context upg_cxt; + knl_u_utils_context utils_cxt; + knl_u_security_context sec_cxt; + +#ifdef ENABLE_MOT + knl_u_mot_context mot_cxt; +#endif + + /* instrumentation */ + knl_u_unique_sql_context unique_sql_cxt; + knl_u_user_login_context user_login_cxt; + knl_u_percentile_context percentile_cxt; + knl_u_statement_context statement_cxt; + + knl_u_slow_query_context slow_query_cxt; + /* external FDW */ + knl_u_ext_fdw_context ext_fdw_ctx[MAX_TYPE_FDW]; + /* GTT */ + knl_u_gtt_context gtt_ctx; +} knl_session_context; + +enum stp_xact_err_type { + STP_XACT_OPEN_FOR, + STP_XACT_USED_AS_EXPR, + STP_XACT_GUC_IN_OPT_CLAUSE, + STP_XACT_OF_SECURE_DEFINER, + STP_XACT_AFTER_TRIGGER_BEGIN, +}; + + +extern void knl_session_init(knl_session_context* sess_cxt); +extern void knl_u_executor_init(knl_u_executor_context* exec_cxt); +extern knl_session_context* create_session_context(MemoryContext parent, uint64 id); +extern void free_session_context(knl_session_context* session); +extern void use_fake_session(); +extern bool stp_set_commit_rollback_err_msg(stp_xact_err_type type); + +extern THR_LOCAL knl_session_context* u_sess; + +inline bool stp_disable_xact_and_set_err_msg(bool *save_commit_rollback_state, stp_xact_err_type type) +{ + *save_commit_rollback_state = u_sess->SPI_cxt.is_allow_commit_rollback; + u_sess->SPI_cxt.is_allow_commit_rollback = false; + return stp_set_commit_rollback_err_msg(type); +} + +inline bool stp_enable_and_get_old_xact_stmt_state() +{ + bool save_commit_rollback_state = u_sess->SPI_cxt.is_allow_commit_rollback; + u_sess->SPI_cxt.is_allow_commit_rollback = true; + return save_commit_rollback_state; +} + +inline void stp_retore_old_xact_stmt_state(bool OldState) +{ + u_sess->SPI_cxt.is_allow_commit_rollback = OldState; +} + +inline void stp_reset_commit_rolback_err_msg() +{ + memset_s(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg, + sizeof(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg), + 0, sizeof(u_sess->SPI_cxt.forbidden_commit_rollback_err_msg)); +} + +inline void stp_reset_opt_values() +{ + u_sess->SPI_cxt.is_allow_commit_rollback = false; + stp_reset_commit_rolback_err_msg(); + u_sess->SPI_cxt.is_stp = true; + u_sess->SPI_cxt.is_proconfig_set = false; + u_sess->SPI_cxt.portal_stp_exception_counter = 0; +} + +inline void stp_reset_xact_state_and_err_msg(bool savedisAllowCommitRollback, bool needResetErrMsg) +{ + stp_retore_old_xact_stmt_state(savedisAllowCommitRollback); + if (needResetErrMsg) { + stp_reset_commit_rolback_err_msg(); + } +} + +#endif /* SRC_INCLUDE_KNL_KNL_SESSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_thread.h postgresql-hll-2.14/include/knl/knl_thread.h --- postgresql-hll-2.14_old/include/knl/knl_thread.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_thread.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,2926 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_thread.h + * Data stucture for thread level global variables. + * + * When anyone try to added variable in this file, which means add a thread level + * variable, there are several rules needed to obey: + * + * 1. Only used in one thread. + * If we try to share the variable with all threads, then this variable should be + * added to instance level context rather than thread level context. + * + * 2. Session independent. + * When we use thread pool to server for all sessions, then the thread in + * thread pool should be stateless. So, session related info can not be stored + * in thread level context, for instance, client user, password, cached plans, + * compiled plpgsql, etc. + * + * 3. Transaction level lifecycle. + * The thread will only change to another session when one transaction has + * already finished in current session. So, we can put the variable in thread + * level context if it will be reset at thread transaction finish or start + * time. + * + * 4. Name pattern + * All context define below should follow naming rules: + * knl_t_xxxx + * + * + * IDENTIFICATION + * src/include/knl/knl_thread.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_KNL_THRD_H_ +#define SRC_INCLUDE_KNL_KNL_THRD_H_ + +#include + +#include "c.h" +#include "access/sdir.h" +#include "datatype/timestamp.h" +#include "gs_thread.h" +#include "gssignal/gs_signal.h" +#include "knl/knl_guc.h" +#include "knl/knl_session.h" +#include "nodes/pg_list.h" +#include "storage/s_lock.h" +#include "utils/palloc.h" +#include "storage/latch.h" +#include "portability/instr_time.h" +#include "cipher.h" +#include "openssl/ossl_typ.h" +#include "workload/qnode.h" +#include "streaming/init.h" +#include "tcop/dest.h" +#include "streaming/init.h" +#include "utils/memgroup.h" +#include "lib/circularqueue.h" + +#define MAX_PATH_LEN 1024 + +#define RESERVE_SIZE 33 + +typedef struct ResourceOwnerData* ResourceOwner; + +typedef struct knl_t_codegen_context { + void* thr_codegen_obj; + + bool g_runningInFmgr; + + long codegen_IRload_thr_count; + +} knl_t_codegen_context; + +typedef struct knl_t_relopt_context { + struct relopt_gen** relOpts; + + bits32 last_assigned_kind; + + int num_custom_options; + + struct relopt_gen** custom_options; + + bool need_initialization; + + int max_custom_options; + +} knl_t_relopt_context; + +typedef struct knl_t_mem_context { + MemoryContext postmaster_mem_cxt; + + MemoryContext msg_mem_cxt; + + MemoryContext cur_transaction_mem_cxt; + + MemoryContext gs_signal_mem_cxt; + + MemoryContext mask_password_mem_cxt; + + MemoryContext row_desc_mem_cxt; + + MemoryContext stream_runtime_mem_cxt; + + /* Shared memory context for in-memory data exchange. */ + MemoryContext data_exchange_mem_cxt; + + /* This is a transient link to the active portal's memory context: */ + MemoryContext portal_mem_cxt; + + /* used to track the memory usage */ + MemoryContext mem_track_mem_cxt; + + /* private memory context for profile logging, it's under t_thrd.top_mem_cxt */ + MemoryContext profile_log_mem_cxt; + + /* gBatchEncodeNumericMemCnxt -- special memory context for encoding batch numeric. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during encoding of each batch of numeric values, and reset after done. + + * Bacause varlena with 1B maybe exist, we have to free them at the + * end. the number of LOOP is always 60000 and releasing space is so + * ineffective. So that use gBatchEncodeNumericMemCnxt. + * Alloc some times, and reset one time. + */ + MemoryContext batch_encode_numeric_mem_cxt; + + /* system auditor memory context. */ + MemoryContext pgAuditLocalContext; +} knl_t_mem_context; + +#ifdef HAVE_INT64_TIMESTAMP +typedef int64 TimestampTz; +#else + +typedef double TimestampTz; +#endif +/* + * During prepare, the state file is assembled in memory before writing it + * to WAL and the actual state file. We use a chain of StateFileChunk blocks + * for that. + */ +typedef struct StateFileChunk { + char* data; + uint32 len; + struct StateFileChunk* next; +} StateFileChunk; + +typedef struct xllist { + StateFileChunk* head; /* first data block in the chain */ + StateFileChunk* tail; /* last block in chain */ + uint32 num_chunks; + uint32 bytes_free; /* free bytes left in tail block */ + uint32 total_len; /* total data bytes in chain */ +} xllist; + +typedef struct knl_t_xact_context { + /* var in transam.cpp */ + typedef uint64 CommitSeqNo; + typedef int CLogXidStatus; + typedef uint64 XLogRecPtr; + /* + * Single-item cache for results of TransactionIdGetCommitSeqNo. It's worth + * having + * such a cache because we frequently find ourselves repeatedly checking the + * same XID, for example when scanning a table just after a bulk insert, + * update, or delete. + */ + TransactionId cachedFetchCSNXid; + CommitSeqNo cachedFetchCSN; + TransactionId latestFetchCSNXid; + CommitSeqNo latestFetchCSN; + + /* Just use for check set hitbit right */ + /* Just use for check set hitbit right */ + TransactionId latestFetchXid; + CLogXidStatus latestFetchXidStatus; + + /* + * Single-item cache for results of TransactionLogFetch. It's worth having + * such a cache because we frequently find ourselves repeatedly checking the + * same XID, for example when scanning a table just after a bulk insert, + * update, or delete. + */ + TransactionId cachedFetchXid; + CLogXidStatus cachedFetchXidStatus; + XLogRecPtr cachedCommitLSN; + + /* var in multixact.cpp*/ + struct mXactCacheEnt* MXactCache; + MemoryContext MXactContext; + + /* var in twophase.cpp*/ + /* + * Global transaction entry currently locked by us, if any. Note that any + * access to the entry pointed to by this variable must be protected by + * TwoPhaseStateLock, though obviously the pointer itself doesn't need to be + * (since it's just local memory). + */ + struct GlobalTransactionData* MyLockedGxact; + bool twophaseExitRegistered; + TransactionId cached_xid; + struct GlobalTransactionData* cached_gxact; + struct TwoPhaseStateData* TwoPhaseState; + xllist records; + + /* var in varsup.cpp*/ + TransactionId cn_xid; + TransactionId next_xid; + bool force_get_xid_from_gtm; + Oid InplaceUpgradeNextOid; + /* pointer to "variable cache" in shared memory (set up by shmem.c) */ + struct VariableCacheData* ShmemVariableCache; + + /* var in xact.cpp */ + bool CancelStmtForReadOnly; + /* + * MyXactAccessedTempRel is set when a temporary relation is accessed. + * We don't allow PREPARE TRANSACTION in that case. (This is global + * so that it can be set from heapam.c.) + */ + /* Kluge for 2PC support */ + bool MyXactAccessedTempRel; + bool MyXactAccessedRepRel; + bool needRemoveTwophaseState; + /* Whether in abort transaction procedure */ + bool bInAbortTransaction; + bool handlesDestroyedInCancelQuery; + /* if true, we do not unlink dropped col files at xact commit or abort */ + bool xactDelayDDL; + /* + * unreportedXids holds XIDs of all subtransactions that have not yet been + * reported in a XLOG_XACT_ASSIGNMENT record. + */ +#define PGPROC_MAX_CACHED_SUBXIDS 64 + int nUnreportedXids; + TransactionId unreportedXids[PGPROC_MAX_CACHED_SUBXIDS]; + /* + * The subtransaction ID and command ID assignment counters are global + * to a whole transaction, so we do not keep them in the state stack. + */ + TransactionId currentSubTransactionId; + CommandId currentCommandId; + bool currentCommandIdUsed; + /* + * Parameters for communication control of Command ID between Postgres-XC nodes. + * isCommandIdReceived is used to determine of a command ID has been received by a remote + * node from a Coordinator. + * sendCommandId is used to determine if a Postgres-XC node needs to communicate its command ID. + * This is possible for both remote nodes and Coordinators connected to applications. + * receivedCommandId is the command ID received on Coordinator from remote node or on remote node + * from Coordinator. + */ + bool isCommandIdReceived; + bool sendCommandId; + CommandId receivedCommandId; + + /* + * xactStartTimestamp is the value of transaction_timestamp(). + * stmtStartTimestamp is the value of statement_timestamp(). + * xactStopTimestamp is the time at which we log a commit or abort WAL record. + * These do not change as we enter and exit subtransactions, so we don't + * keep them inside the TransactionState stack. + */ + TimestampTz xactStartTimestamp; + TimestampTz stmtStartTimestamp; + TimestampTz xactStopTimestamp; + + /* + * PGXC receives from GTM a timestamp value at the same time as a GXID + * This one is set as GTMxactStartTimestamp and is a return value of now(), current_transaction(). + * GTMxactStartTimestamp is also sent to each node with gxid and snapshot and delta is calculated locally. + * GTMdeltaTimestamp is used to calculate current_statement as its value can change + * during a transaction. Delta can have a different value through the nodes of the cluster + * but its uniqueness in the cluster is maintained thanks to the global value GTMxactStartTimestamp. + */ + TimestampTz GTMxactStartTimestamp; + TimestampTz GTMdeltaTimestamp; + bool timestamp_from_cn; + + bool XactLocalNodePrepared; + bool XactReadLocalNode; + bool XactWriteLocalNode; + bool XactLocalNodeCanAbort; + bool XactPrepareSent; + bool AlterCoordinatorStmt; + + /* white-box check TransactionID, when there is no 2pc + * the thread local variable save the executor cn commit(abort) xid + * compare with the remote-commit xid in other CNs and DNs + */ + TransactionId XactXidStoreForCheck; + TransactionId reserved_nextxid_check; + /* + * Some commands want to force synchronous commit. + */ + bool forceSyncCommit; + /* + * Private context for transaction-abort work --- we reserve space for this + * at startup to ensure that AbortTransaction and AbortSubTransaction can work + * when we've run out of memory. + */ + MemoryContext TransactionAbortContext; + struct GTMCallbackItem* GTM_callbacks; + struct GTMCallbackItem* Seq_callbacks; + + LocalTransactionId lxid; + TransactionId stablexid; + + /* var in gtm.cpp */ + TransactionId currentGxid; + struct gtm_conn* conn; + + /* var in slru.cpp */ + typedef int SlruErrorCause; + SlruErrorCause slru_errcause; + int slru_errno; + + /* var in predicate.cpp */ + uint32 ScratchTargetTagHash; + struct LWLock *ScratchPartitionLock; + /* + * The local hash table used to determine when to combine multiple fine- + * grained locks into a single courser-grained lock. + */ + struct HTAB* LocalPredicateLockHash; + /* + * Keep a pointer to the currently-running serializable transaction (if any) + * for quick reference. Also, remember if we have written anything that could + * cause a rw-conflict. + */ + struct SERIALIZABLEXACT* MySerializableXact; + bool MyXactDidWrite; + +#ifdef PGXC + bool useLocalSnapshot; + /* + * Hash bucket map of the group. + * Used only in the DN for DDL operations. + * Allocated from t_thrd.mem_cxt.top_transaction_mem_cxt. + */ + uint2 *PGXCBucketMap; + int PGXCNodeId; + bool inheritFileNode; +#endif +} knl_t_xact_context; + +typedef void (*RedoInterruptCallBackFunc)(void); + +typedef struct knl_t_xlog_context { +#define MAXFNAMELEN 64 + typedef uint32 TimeLineID; + typedef int HotStandbyState; + typedef uint32 pg_crc32; + typedef int RecoveryTargetType; + typedef int ServerMode; + typedef uint64 XLogRecPtr; + typedef uint64 XLogSegNo; + /* + * ThisTimeLineID will be same in all backends --- it identifies current + * WAL timeline for the database system. + */ + TimeLineID ThisTimeLineID; + + /* + * Are we doing recovery from XLOG? + * + * This is only ever true in the startup process; it should be read as meaning + * "this process is replaying WAL records", rather than "the system is in + * recovery mode". It should be examined primarily by functions that need + * to act differently when called from a WAL redo function (e.g., to skip WAL + * logging). To check whether the system is in recovery regardless of which + * process you're running in, use RecoveryInProgress() but only after shared + * memory startup and lock initialization. + */ + bool InRecovery; + /* Are we in Hot Standby mode? Only valid in startup process, see xlog.h */ + + HotStandbyState standbyState; + XLogRecPtr LastRec; + pg_crc32 latestRecordCrc; + /* + * During recovery, lastFullPageWrites keeps track of full_page_writes that + * the replayed WAL records indicate. It's initialized with full_page_writes + * that the recovery starting checkpoint record indicates, and then updated + * each time XLOG_FPW_CHANGE record is replayed. + */ + bool lastFullPageWrites; + /* + * Local copy of SharedRecoveryInProgress variable. True actually means "not + * known, need to check the shared state". + */ + bool LocalRecoveryInProgress; + /* + * Local copy of SharedHotStandbyActive variable. False actually means "not + * known, need to check the shared state". + */ + bool LocalHotStandbyActive; + + /* + * Local state for XLogInsertAllowed(): + * 1: unconditionally allowed to insert XLOG + * 0: unconditionally not allowed to insert XLOG + * -1: must check RecoveryInProgress(); disallow until it is false + * Most processes start with -1 and transition to 1 after seeing that recovery + * is not in progress. But we can also force the value for special cases. + * The coding in XLogInsertAllowed() depends on the first two of these states + * being numerically the same as bool true and false. + */ + int LocalXLogInsertAllowed; + + /* + * When ArchiveRecoveryRequested is set, archive recovery was requested, + * ie. recovery.conf file was present. When InArchiveRecovery is set, we are + * currently recovering using offline XLOG archives. These variables are only + * valid in the startup process. + * + * When ArchiveRecoveryRequested is true, but InArchiveRecovery is false, we're + * currently performing crash recovery using only XLOG files in pg_xlog, but + * will switch to using offline XLOG archives as soon as we reach the end of + * WAL in pg_xlog. + * + * When recovery.conf is configed, it means that we will recover from offline XLOG + * archives, set ArchiveRstoreRequested to true to distinguish archive recovery with + * other recovery scenarios. + */ + bool ArchiveRecoveryRequested; + bool InArchiveRecovery; + bool ArchiveRestoreRequested; + + /* Was the last xlog file restored from archive, or local? */ + bool restoredFromArchive; + + /* options taken from recovery.conf for archive recovery */ + char* recoveryRestoreCommand; + char* recoveryEndCommand; + char* archiveCleanupCommand; + RecoveryTargetType recoveryTarget; + bool recoveryTargetInclusive; + bool recoveryPauseAtTarget; + TransactionId recoveryTargetXid; + TimestampTz recoveryTargetTime; + char* recoveryTargetBarrierId; + char* recoveryTargetName; + XLogRecPtr recoveryTargetLSN; + + /* options taken from recovery.conf for XLOG streaming */ + bool StandbyModeRequested; + char* PrimaryConnInfo; + char* TriggerFile; + + /* are we currently in standby mode? */ + bool StandbyMode; + + /* if trigger has been set in reader for any reason, check it in read record */ + bool recoveryTriggered; + + /* if recoveryStopsHere returns true, it saves actual stop xid/time/name here */ + TransactionId recoveryStopXid; + TimestampTz recoveryStopTime; + XLogRecPtr recoveryStopLSN; + char recoveryStopName[MAXFNAMELEN]; + bool recoveryStopAfter; + + /* + * During normal operation, the only timeline we care about is ThisTimeLineID. + * During recovery, however, things are more complicated. To simplify life + * for rmgr code, we keep ThisTimeLineID set to the "current" timeline as we + * scan through the WAL history (that is, it is the line that was active when + * the currently-scanned WAL record was generated). We also need these + * timeline values: + * + * recoveryTargetTLI: the desired timeline that we want to end in. + * + * recoveryTargetIsLatest: was the requested target timeline 'latest'? + * + * expectedTLIs: an integer list of recoveryTargetTLI and the TLIs of + * its known parents, newest first (so recoveryTargetTLI is always the + * first list member). Only these TLIs are expected to be seen in the WAL + * segments we read, and indeed only these TLIs will be considered as + * candidate WAL files to open at all. + * + * curFileTLI: the TLI appearing in the name of the current input WAL file. + * (This is not necessarily the same as ThisTimeLineID, because we could + * be scanning data that was copied from an ancestor timeline when the current + * file was created.) During a sequential scan we do not allow this value + * to decrease. + */ + TimeLineID recoveryTargetTLI; + bool recoveryTargetIsLatest; + List* expectedTLIs; + TimeLineID curFileTLI; + + /* + * ProcLastRecPtr points to the start of the last XLOG record inserted by the + * current backend. It is updated for all inserts. XactLastRecEnd points to + * end+1 of the last record, and is reset when we end a top-level transaction, + * or start a new one; so it can be used to tell if the current transaction has + * created any XLOG records. + */ + XLogRecPtr ProcLastRecPtr; + + XLogRecPtr XactLastRecEnd; + + /* + * RedoRecPtr is this backend's local copy of the REDO record pointer + * (which is almost but not quite the same as a pointer to the most recent + * CHECKPOINT record). We update this from the shared-memory copy, + * XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we + * hold the Insert lock). See XLogInsertRecord for details. We are also + * allowed to update from XLogCtl->Insert.RedoRecPtr if we hold the info_lck; + * see GetRedoRecPtr. A freshly spawned backend obtains the value during + * InitXLOGAccess. + */ + XLogRecPtr RedoRecPtr; + + /* + * doPageWrites is this backend's local copy of (forcePageWrites || + * fullPageWrites). It is used together with RedoRecPtr to decide whether + * a full-page image of a page need to be taken. + */ + bool doPageWrites; + + /* + * RedoStartLSN points to the checkpoint's REDO location which is specified + * in a backup label file, backup history file or control file. In standby + * mode, XLOG streaming usually starts from the position where an invalid + * record was found. But if we fail to read even the initial checkpoint + * record, we use the REDO location instead of the checkpoint location as + * the start position of XLOG streaming. Otherwise we would have to jump + * backwards to the REDO location after reading the checkpoint record, + * because the REDO record can precede the checkpoint record. + */ + XLogRecPtr RedoStartLSN; + ServerMode server_mode; + bool is_cascade_standby; + + /* Flags to tell if we are in an startup process */ + bool startup_processing; + + /* + * openLogFile is -1 or a kernel FD for an open log file segment. + * When it's open, openLogOff is the current seek offset in the file. + * openLogSegNo identifies the segment. These variables are only + * used to write the XLOG, and so will normally refer to the active segment. + */ + int openLogFile; + XLogSegNo openLogSegNo; + uint32 openLogOff; + + /* + * These variables are used similarly to the ones above, but for reading + * the XLOG. Note, however, that readOff generally represents the offset + * of the page just read, not the seek position of the FD itself, which + * will be just past that page. readLen indicates how much of the current + * page has been read into readBuf, and readSource indicates where we got + * the currently open file from. + */ + int readFile; + XLogSegNo readSegNo; + uint32 readOff; + uint32 readLen; + unsigned int readSource; /* XLOG_FROM_* code */ + + /* + * Keeps track of which sources we've tried to read the current WAL + * record from and failed. + */ + unsigned int failedSources; /* OR of XLOG_FROM_* codes */ + + bool readfrombuffer; + + /* + * These variables track when we last obtained some WAL data to process, + * and where we got it from. (XLogReceiptSource is initially the same as + * readSource, but readSource gets reset to zero when we don't have data + * to process right now.) + */ + TimestampTz XLogReceiptTime; + int XLogReceiptSource; /* XLOG_FROM_* code */ + + /* State information for XLOG reading */ + XLogRecPtr ReadRecPtr; /* start of last record read */ + XLogRecPtr EndRecPtr; /* end+1 of last record read */ + + XLogRecPtr minRecoveryPoint; /* local copy of + * ControlFile->minRecoveryPoint */ + bool updateMinRecoveryPoint; + + /* + * Have we reached a consistent database state? In crash recovery, we have + * to replay all the WAL, so reachedConsistency is never set. During archive + * recovery, the database is consistent once minRecoveryPoint is reached. + */ + bool reachedConsistency; + + bool InRedo; + bool RedoDone; + + /* Have we launched bgwriter during recovery? */ + bool bgwriterLaunched; + bool pagewriter_launched; + + /* Added for XLOG scaling*/ + /* For WALInsertLockAcquire/Release functions */ + int MyLockNo; + bool holdingAllLocks; + + int lockToTry; + uint64 cachedPage; + char* cachedPos; +#ifdef WIN32 + unsigned int deletedcounter; +#endif + +#define STR_TIME_BUF_LEN 128 + char buf[STR_TIME_BUF_LEN]; + XLogRecPtr receivedUpto; + XLogRecPtr lastComplaint; + bool failover_triggered; + bool switchover_triggered; + + struct registered_buffer* registered_buffers; + int max_registered_buffers; /* allocated size */ + int max_registered_block_id; /* highest block_id + 1 + * currently registered */ + + /* + * A chain of XLogRecDatas to hold the "main data" of a WAL record, registered + * with XLogRegisterData(...). + */ + struct XLogRecData* mainrdata_head; + struct XLogRecData* mainrdata_last; + uint32 mainrdata_len; /* total # of bytes in chain */ + + /* + * These are used to hold the record header while constructing a record. + * 'hdr_scratch' is not a plain variable, but is palloc'd at initialization, + * because we want it to be MAXALIGNed and padding bytes zeroed. + * + * For simplicity, it's allocated large enough to hold the headers for any + * WAL record. + */ + struct XLogRecData* ptr_hdr_rdt; + char* hdr_scratch; + + /* + * An array of XLogRecData structs, to hold registered data. + */ + struct XLogRecData* rdatas; + int num_rdatas; /* entries currently used */ + int max_rdatas; /* allocated size */ + + bool begininsert_called; + + /* Should te in-progress insertion log the origin */ + bool include_origin; + + /* Memory context to hold the registered buffer and data references. */ + MemoryContext xloginsert_cxt; + + struct HTAB* invalid_page_tab; + + /* state maintained across calls */ + uint32 sendId; + int sendFile; + XLogSegNo sendSegNo; + uint32 sendOff; + TimeLineID sendTLI; + + List* incomplete_actions; + + MemoryContext spg_opCtx; + MemoryContext gist_opCtx; + MemoryContext gin_opCtx; + + bool redo_oldversion_xlog; + /* + * Statistics for current checkpoint are collected in this global struct. + * Because only the checkpointer or a stand-alone backend can perform + * checkpoints, this will be unused in normal backends. + */ + struct CheckpointStatsData* CheckpointStats; + struct XLogwrtResult* LogwrtResult; + bool needImmediateCkp; + int redoItemIdx; + /* ignore cleanup when startup end. when isIgoreCleanup is true, a standby DN always keep isIgoreCleanup true */ + bool forceFinishHappened; + uint32 invaildPageCnt; + uint32 imcompleteActionCnt; + XLogRecPtr max_page_flush_lsn; + bool permit_finish_redo; + +#ifndef ENABLE_MULTIPLE_NODES + /* redo RM_STANDBY_ID record committing csn's transaction id */ + List* committing_csn_list; +#endif + RedoInterruptCallBackFunc redoInterruptCallBackFunc; +} knl_t_xlog_context; + +typedef struct knl_t_dfs_context { + /* + * Provide a pending-delete like mechanism to allow external routines to release the + * memory stuffs that were NOT allocated in mem-context e.g. those allocated in + * 3rd-party libraries, we have to do so as a none-dfs error-out may miss dropping + * this kind of resources which defintely causing memory leak. + */ + List* pending_free_reader_list; + + List* pending_free_writer_list; + +} knl_t_dfs_context; + +typedef struct knl_t_obs_context { + MemoryContext ObsMemoryContext; + + char* pCAInfo; + + int retrySleepInterval; + + int statusG; + +#define ERROR_DETAIL_LEN 4096 + char errorDetailsG[ERROR_DETAIL_LEN]; + + int uriStyleG; +} knl_t_obs_context; + +typedef struct knl_t_cbm_context { + /* The xlog parsing and bitmap output struct instance */ + struct XlogBitmapStruct* XlogCbmSys; + + /* cbmwriter.cpp */ + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + MemoryContext cbmwriter_context; + MemoryContext cbmwriter_page_context; +} knl_t_cbm_context; + +/* thread local pointer to the shared memory */ +typedef struct knl_t_shemem_ptr_context { + struct ss_scan_locations_t* scan_locations; + struct SlruCtlData* MultiXactOffsetCtl; + struct SlruCtlData* MultiXactMemberCtl; + struct MultiXactStateData* MultiXactState; + MultiXactId* OldestMemberMXactId; + MultiXactId* OldestVisibleMXactId; + + struct SlruCtlData* ClogCtl; + + struct SlruCtlData* CsnlogCtlPtr; + + struct XLogCtlData* XLogCtl; + + union WALInsertLockPadded **GlobalWALInsertLocks; + union WALInsertLockPadded *LocalGroupWALInsertLocks; + + /* + * We maintain an image of pg_control in shared memory. + */ + struct ControlFileData* ControlFile; + + struct LsnXlogFlushData* g_LsnXlogFlushChkFile; + + struct SlruCtlData* OldSerXidSlruCtl; + + struct OldSerXidControlData* oldSerXidControl; + + /* + * When the oldest committed transaction on the "finished" list is moved to + * SLRU, its predicate locks will be moved to this "dummy" transaction, + * collapsing duplicate targets. When a duplicate is found, the later + * commitSeqNo is used. + */ + struct SERIALIZABLEXACT* OldCommittedSxact; + + /* + * This provides a list of objects in order to track transactions + * participating in predicate locking. Entries in the list are fixed size, + * and reside in shared memory. The memory address of an entry must remain + * fixed during its lifetime. The list will be protected from concurrent + * update externally; no provision is made in this code to manage that. The + * number of entries in the list, and the size allowed for each entry is + * fixed upon creation. + */ + struct PredXactListData* PredXact; + + /* + * This provides a pool of RWConflict data elements to use in conflict lists + * between transactions. + */ + struct RWConflictPoolHeaderData* RWConflictPool; + /* + * The predicate locking hash tables are in shared memory. + * Each backend keeps pointers to them. + */ + struct HTAB* SerializableXidHash; + struct HTAB* PredicateLockTargetHash; + struct HTAB* PredicateLockHash; + struct SHM_QUEUE* FinishedSerializableTransactions; + + /* ------------------------------------------------------------ + * Functions for management of the shared-memory PgBackendStatus array + * ------------------------------------------------------------ + */ + PgBackendStatus* BackendStatusArray; + char* BackendClientHostnameBuffer; + char* BackendAppnameBuffer; + char* BackendConninfoBuffer; + char* BackendActivityBuffer; + struct PgStat_WaitCountStatus* WaitCountBuffer; + Size BackendActivityBufferSize; + + PgBackendStatus* MyBEEntry; + + volatile struct SessionLevelStatistic* mySessionStatEntry; + struct SessionLevelStatistic* sessionStatArray; + struct SessionLevelMemory* mySessionMemoryEntry; + struct SessionLevelMemory* sessionMemoryArray; + volatile struct SessionTimeEntry* mySessionTimeEntry; + struct SessionTimeEntry* sessionTimeArray; + + struct ProcSignalSlot* ProcSignalSlots; + + volatile struct ProcSignalSlot* MyProcSignalSlot; // volatile + + struct PGShmemHeader* ShmemSegHdr; /* shared mem segment header */ + + void* ShmemBase; /* start address of shared memory */ + + void* ShmemEnd; /* end+1 address of shared memory */ + + slock_t* ShmemLock; /* spinlock for shared memory and LWLock allocation */ + + struct HTAB* ShmemIndex; /* primary index hashtable for shmem */ + + struct SISeg* shmInvalBuffer; /* pointer to the shared inval buffer */ + + struct PMSignalData* PMSignalState; // volatile + + /* + * This points to the array of LWLocks in shared memory. Backends inherit + * the pointer by fork from the postmaster (except in the EXEC_BACKEND case, + * where we have special measures to pass it down). + */ + union LWLockPadded *mainLWLockArray; + + // for GTT table to track sessions and their usage of GTTs + struct gtt_ctl_data* gtt_shared_ctl; + struct HTAB* active_gtt_shared_hash; +} knl_t_shemem_ptr_context; + +typedef struct knl_t_cstore_context { + /* + * remember all the relation ALTER TABLE SET DATATYPE is applied to. + * note that this object is live in t_thrd.top_mem_cxt. + */ + class CStoreAlterRegister* gCStoreAlterReg; + + /* bulkload_memsize_used + * Remember how many memory has been allocated and used. + * It will be <= partition_max_cache_size. + */ + Size bulkload_memsize_used; + + int cstore_prefetch_count; + + /* local state for aio clean up resource */ + struct AioDispatchCUDesc** InProgressAioCUDispatch; + int InProgressAioCUDispatchCount; +} knl_t_cstore_context; + +typedef struct knl_t_index_context { + typedef uint64 XLogRecPtr; + struct ginxlogInsertDataInternal* ptr_data; + struct ginxlogInsertEntry* ptr_entry; + /* + * ginInsertCtx -- static thread local memory context for gininsert(). + * ginInsertCtx is to avoid create and destory context frequently. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during insert one tuple into gin index, and reset after done. + */ + MemoryContext ginInsertCtx; + struct BTVacInfo* btvacinfo; +} knl_t_index_context; + +typedef struct knl_t_wlmthrd_context { + /* thread level node group */ + struct WLMNodeGroupInfo* thread_node_group; + + /* dynamic workload client structure */ + struct ClientDynamicManager* thread_climgr; + + /* dynamic workload server structure */ + struct ServerDynamicManager* thread_srvmgr; + + /* collect info */ + struct WLMCollectInfo* collect_info; + + /* exception control manager */ + struct ExceptionManager* except_ctl; + + /* dn cpu info detail */ + struct WLMDNRealTimeInfoDetail* dn_cpu_detail; + + /* query node for workload manager */ + WLMQNodeInfo qnode; + + /* the states of query while doing parallel control */ + ParctlState parctl_state; + + /* indicate if it is alrm pending */ + bool wlmalarm_pending; + + /* indicate if alarm timeout is active */ + bool wlmalarm_timeout_active; + + /* indicate if alarm dump is active */ + bool wlmalarm_dump_active; + + /* indicate if transcation is started */ + bool wlm_xact_start; + + /* thread initialization has been finished */ + bool wlm_init_done; + + /*check if current stmt has recorded cursor*/ + bool has_cursor_record; + + /* alarm finish time */ + TimestampTz wlmalarm_fin_time; + + /* latch for wlm */ + Latch wlm_mainloop_latch; + + /* got sigterm signal */ + int wlm_got_sigterm; + + /* wlm thread is got sighup signal */ + int wlm_got_sighup; + + MemoryContext MaskPasswordMemoryContext; + MemoryContext query_resource_track_mcxt; +} knl_t_wlmthrd_context; + +#define RANDOM_LEN 16 +#define NUMBER_OF_SAVED_DERIVEKEYS 48 + +typedef struct knl_t_aes_context { + /* Save several used derive_keys, random_salt and user_key in one thread. */ + bool encryption_function_call; + GS_UCHAR derive_vector_saved[RANDOM_LEN]; + GS_UCHAR mac_vector_saved[RANDOM_LEN]; + GS_UCHAR input_saved[RANDOM_LEN]; + + /* + * Thread-local variables including random_salt, derive_key and key + * will be saved during the thread. + */ + GS_UCHAR random_salt_saved[RANDOM_LEN]; + + /* Save several used derive_keys, random_salt and user_key in one thread. */ + bool decryption_function_call; + GS_UCHAR derive_vector_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR mac_vector_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR random_salt_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UCHAR user_input_used[NUMBER_OF_SAVED_DERIVEKEYS][RANDOM_LEN]; + GS_UINT64 decryption_count; + + /* + * The usage_frequency is used to decided which random_salt to start comparing with + * The usage_frequency is based on the recent using times of derive_key + */ + GS_UINT32 usage_frequency[NUMBER_OF_SAVED_DERIVEKEYS]; + /* + * The insert_position is used to seperate two different region for usage_frequency + * From 0 to NUMBER_OF_SAVED_DERIVEKEYS/2 -1 , there are derive_keys used many times. + * From NUMBER_OF_SAVED_DERIVEKEYS/2 to NUMBER_OF_SAVED_DERIVEKEYS -1, + * these derive_keys were used only one time. + * Therefore, the newborn derive_key will be saved in insert_position. + */ + GS_UINT32 insert_position; + + /* use saved random salt unless unavailable*/ + GS_UCHAR gs_random_salt_saved[RANDOM_LEN]; + bool random_salt_tag; + GS_UINT64 random_salt_count; +} knl_t_aes_context; + +typedef struct knl_t_time_context { + /* Set at postmaster start */ + TimestampTz pg_start_time; + + /* Set at configuration reload */ + TimestampTz pg_reload_time; + + TimestampTz stmt_system_timestamp; + + bool is_abstimeout_in; + +} knl_t_time_context; + +/* We provide a small stack of ErrorData records for re-entrant cases */ +#define ERRORDATA_STACK_SIZE 5 + +/* buffers for formatted timestamps that might be used by both + * log_line_prefix and csv logs. + */ +#define FORMATTED_TS_LEN 128 + +typedef struct knl_t_log_context { + /* switch a new plog message every 1s */ + struct timeval plog_msg_switch_tm; + + /* for magnetic disk */ + char* plog_md_read_entry; + + char* plog_md_write_entry; + + /* for OBS */ + char* plog_obs_list_entry; + + char* plog_obs_read_entry; + + char* plog_obs_write_entry; + + /* for Hadoop */ + char* plog_hdp_read_entry; + + char* plog_hdp_write_entry; + + char* plog_hdp_open_entry; + + /* for remote datanode */ + char* plog_remote_read_entry; + + char*** g_plog_msgmem_array; + + /* for elog.cpp */ + struct ErrorContextCallback* error_context_stack; + + sigjmp_buf* PG_exception_stack; + + char** thd_bt_symbol; + + bool flush_message_immediately; + + int Log_destination; + + bool disable_log_output; + + bool on_mask_password; + + bool openlog_done; + + bool error_with_nodename; + + struct ErrorData* errordata; + + struct LogControlData* pLogCtl; + + int errordata_stack_depth; /* index of topmost active frame */ + + int recursion_depth; /* to detect actual recursion */ + + char formatted_start_time[FORMATTED_TS_LEN]; + + char formatted_log_time[FORMATTED_TS_LEN]; + + int save_format_errnumber; + + const char* save_format_domain; + + unsigned long syslog_seq; + + /* static counter for line numbers */ + long log_line_number; + + /* has counter been reset in current process? */ + ThreadId log_my_pid; + + /* static counter for line numbers */ + long csv_log_line_number; + + /* has counter been reset in current process? */ + ThreadId csv_log_my_pid; + + /* + * msgbuf is declared as static to save the data to put + * which can be flushed in next put_line() + */ + struct StringInfoData* msgbuf; + + unsigned char* module_logging_configure; + +} knl_t_log_context; + +typedef struct knl_t_format_context { + bool all_digits; + + struct DCHCacheEntry* DCH_cache; + + /* number of entries */ + int n_DCH_cache; + + int DCH_counter; + + struct NUMCacheEntry* NUM_cache; + + /* number of entries */ + int n_NUM_cache; + + int NUM_counter; + + /* see `EarlyBindingTLSVariables` */ + struct NUMCacheEntry* last_NUM_cache_entry; +} knl_t_format_context; + +typedef struct knl_t_audit_context { + bool Audit_delete; + /* + + * Flags set by interrupt handlers for later service in the main loop. + + */ + /* for only sessionid needed by SDBSS */ + TimestampTz user_login_time; + volatile sig_atomic_t need_exit; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t rotation_requested; + uint64 space_beyond_size; /* The static variable for print log when exceeding the space limit */ + uint64 pgaudit_totalspace; + int64 next_rotation_time; + bool pipe_eof_seen; + bool rotation_disabled; + FILE *sysauditFile; + FILE *policyauditFile; + Latch sysAuditorLatch; + time_t last_pgaudit_start_time; + struct AuditIndexTable* audit_indextbl; + char pgaudit_filepath[MAXPGPATH]; +#define NBUFFER_LISTS 256 + List* buffer_lists[NBUFFER_LISTS]; +} knl_stat_context; + +typedef struct knl_t_async_context { + struct AsyncQueueControl* asyncQueueControl; + + /* + * listenChannels identifies the channels we are actually listening to + * (ie, have committed a LISTEN on). It is a simple list of channel names, + * allocated in t_thrd.top_mem_cxt. + */ + List* listenChannels; /* list of C strings */ + List* pendingActions; /* list of ListenAction */ + List* upperPendingActions; /* list of upper-xact lists */ + List* pendingNotifies; /* list of Notifications */ + List* upperPendingNotifies; /* list of upper-xact lists */ + + /* True if we've registered an on_shmem_exit cleanup */ + bool unlistenExitRegistered; + /* True if we're currently registered as a listener in t_thrd.asy_cxt.asyncQueueControl */ + bool amRegisteredListener; + /* has this backend sent notifications in the current transaction? */ + bool backendHasSentNotifications; +} knl_t_async_context; + +typedef struct knl_t_explain_context { + int explain_perf_mode; + bool explain_light_proxy; +} knl_t_explain_context; + +typedef struct knl_t_arch_context { + time_t last_pgarch_start_time; + time_t last_sigterm_time; + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + volatile sig_atomic_t wakened; + volatile sig_atomic_t ready_to_stop; + /* + * Latch used by signal handlers to wake up the sleep in the main loop. + */ + Latch mainloop_latch; + +} knl_t_arch_context; + +/* Maximum length of a timezone name (not including trailing null) */ +#define TZ_STRLEN_MAX 255 +#define LOG_MAX_NODENAME_LEN 64 + +typedef struct knl_t_logger_context { + int64 next_rotation_time; + bool pipe_eof_seen; + bool rotation_disabled; + FILE* syslogFile; + FILE* csvlogFile; + FILE* querylogFile; + char* last_query_log_file_name; + FILE* asplogFile; + int64 first_syslogger_file_time; + char* last_file_name; + char* last_csv_file_name; + char* last_asp_file_name; + Latch sysLoggerLatch; + +#define NBUFFER_LISTS 256 + List* buffer_lists[NBUFFER_LISTS]; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t rotation_requested; +} knl_t_logger_context; + +/***************************************************************************** + * System interrupt and critical section handling + * + * There are two types of interrupts that a running backend needs to accept + * without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM). + * In both cases, we need to be able to clean up the current transaction + * gracefully, so we can't respond to the interrupt instantaneously --- + * there's no guarantee that internal data structures would be self-consistent + * if the code is interrupted at an arbitrary instant. Instead, the signal + * handlers set flags that are checked periodically during execution. + * + * The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots + * where it is normally safe to accept a cancel or die interrupt. In some + * cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that + * might sometimes be called in contexts that do *not* want to allow a cancel + * or die interrupt. The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros + * allow code to ensure that no cancel or die interrupt will be accepted, + * even if CHECK_FOR_INTERRUPTS() gets called in a subroutine. The interrupt + * will be held off until CHECK_FOR_INTERRUPTS() is done outside any + * HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section. + * + * Special mechanisms are used to let an interrupt be accepted when we are + * waiting for a lock or when we are waiting for command input (but, of + * course, only if the interrupt holdoff counter is zero). See the + * related code for details. + * + * A lost connection is handled similarly, although the loss of connection + * does not raise a signal, but is detected when we fail to write to the + * socket. If there was a signal for a broken connection, we could make use of + * it by setting t_thrd.int_cxt.ClientConnectionLost in the signal handler. + * + * A related, but conceptually distinct, mechanism is the "critical section" + * mechanism. A critical section not only holds off cancel/die interrupts, + * but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC) + * --- that is, a system-wide reset is forced. Needless to say, only really + * *critical* code should be marked as a critical section! Currently, this + * mechanism is only used for XLOG-related code. + * + *****************************************************************************/ +typedef struct knl_t_interrupt_context { + /* these are marked volatile because they are set by signal handlers: */ + volatile bool QueryCancelPending; + + volatile bool PoolValidateCancelPending; + + volatile bool ProcDiePending; + + volatile bool ClientConnectionLost; + + volatile bool StreamConnectionLost; + + volatile bool ImmediateInterruptOK; + + /* these are marked volatile because they are examined by signal handlers: */ + volatile uint32 InterruptHoldoffCount; + + volatile uint32 CritSectionCount; + + volatile bool InterruptByCN; + +} knl_t_interrupt_context; + +typedef int64 pg_time_t; +#define INVALID_CANCEL_KEY (0) + +typedef struct knl_t_proc_context { + ThreadId MyProcPid; + + pg_time_t MyStartTime; + + int MyPMChildSlot; + + long MyCancelKey; + + char* MyProgName; + + BackendId MyBackendId; + + /* + * t_thrd.proc_cxt.DataDir is the absolute path to the top level of the PGDATA directory tree. + * Except during early startup, this is also the server's working directory; + * most code therefore can simply use relative paths and not reference t_thrd.proc_cxt.DataDir + * explicitly. + */ + char* DataDir; + + char OutputFileName[MAXPGPATH]; /* debugging output file */ + + char pkglib_path[MAXPGPATH]; /* full path to lib directory */ + + char postgres_exec_path[MAXPGPATH]; /* full path to backend */ + + /* Flag: PostgresMain enter queries loop */ + bool postgres_initialized; + + class PostgresInitializer* PostInit; + + /* + * This flag is set during proc_exit() to change ereport()'s behavior, + * so that an ereport() from an on_proc_exit routine cannot get us out + * of the exit procedure. We do NOT want to go back to the idle loop... + */ + bool proc_exit_inprogress; + bool sess_exit_inprogress; + bool pooler_connection_inprogress; +} knl_t_proc_context; + +typedef struct knl_t_vacuum_context { + int VacuumPageHit; + + int VacuumPageMiss; + + int VacuumPageDirty; + + int VacuumCostBalance; /* working state for vacuum */ + + bool VacuumCostActive; + + /* just for dfs table on "vacuum full" */ + bool vacuum_full_compact; + + /* A few variables that don't seem worth passing around as parameters */ + MemoryContext vac_context; + + bool in_vacuum; + +} knl_t_vacuum_context; + +typedef struct knl_t_autovacuum_context { + /* Flags set by signal handlers */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGUSR2; + volatile sig_atomic_t got_SIGTERM; + + /* Comparison point for determining whether freeze_max_age is exceeded */ + TransactionId recentXid; + + /* Default freeze ages to use for autovacuum (varies by database) */ + int64 default_freeze_min_age; + int64 default_freeze_table_age; + + /* Memory context for long-lived data */ + MemoryContext AutovacMemCxt; + + /* hash table to keep all tuples stat info that fetchs from DataNode */ + HTAB* pgStatAutoVacInfo; + + char* autovacuum_coordinators_string; + int autovac_iops_limits; + struct AutoVacuumShmemStruct* AutoVacuumShmem; + + /* the database list in the launcher, and the context that contains it */ + struct Dllist* DatabaseList; + MemoryContext DatabaseListCxt; + + /* Pointer to my own WorkerInfo, valid on each worker */ + struct WorkerInfoData* MyWorkerInfo; + + /* PID of launcher, valid only in worker while shutting down */ + ThreadId AutovacuumLauncherPid; + + TimestampTz last_read; +} knl_t_autovacuum_context; + +typedef struct knl_t_aiocompleter_context { + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t config_requested; +} knl_t_aiocompleter_context; + +typedef struct knl_t_twophasecleaner_context { + char pgxc_clean_log_path[MAX_PATH_LEN]; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_twophasecleaner_context; + +typedef struct knl_t_bgwriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + int thread_id; + pg_time_t next_flush_time; +} knl_t_bgwriter_context; + +typedef struct knl_t_pagewriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + int page_writer_after; + int pagewriter_id; + pg_time_t next_flush_time; +} knl_t_pagewriter_context; + +#define MAX_SEQ_SCANS 100 + +typedef struct knl_t_dynahash_context { + MemoryContext CurrentDynaHashCxt; + + /* + * We track active hash_seq_search scans here. The need for this mechanism + * comes from the fact that a scan will get confused if a bucket split occurs + * while it's in progress: it might visit entries twice, or even miss some + * entirely (if it's partway through the same bucket that splits). Hence + * we want to inhibit bucket splits if there are any active scans on the + * table being inserted into. This is a fairly rare case in current usage, + * so just postponing the split until the next insertion seems sufficient. + * + * Given present usages of the function, only a few scans are likely to be + * open concurrently; so a finite-size stack of open scans seems sufficient, + * and we don't worry that linear search is too slow. Note that we do + * allow multiple scans of the same hashtable to be open concurrently. + * + * This mechanism can support concurrent scan and insertion in a shared + * hashtable if it's the same backend doing both. It would fail otherwise, + * but locking reasons seem to preclude any such scenario anyway, so we don't + * worry. + * + * This arrangement is reasonably robust if a transient hashtable is deleted + * without notifying us. The absolute worst case is we might inhibit splits + * in another table created later at exactly the same address. We will give + * a warning at transaction end for reference leaks, so any bugs leading to + * lack of notification should be easy to catch. + */ + HTAB* seq_scan_tables[MAX_SEQ_SCANS]; /* tables being scanned */ + + int seq_scan_level[MAX_SEQ_SCANS]; /* subtransaction nest level */ + + int num_seq_scans; +} knl_t_dynahash_context; + +typedef struct knl_t_bulkload_context { + char distExportDataDir[MAX_PATH_LEN]; +#define TIME_STAMP_STR_LEN 15 + char distExportTimestampStr[15]; + TransactionId distExportCurrXid; + uint32 distExportNextSegNo; + int illegal_character_err_cnt; + bool illegal_character_err_threshold_reported; +} knl_t_bulkload_context; + +typedef struct knl_t_job_context { + /* Share memory for job scheudler. */ + struct JobScheduleShmemStruct* JobScheduleShmem; + /* Flags set by signal handlers */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGUSR2; + volatile sig_atomic_t got_SIGTERM; + /* Memory context for long-lived data */ + MemoryContext JobScheduleMemCxt; + /* expired job list at present, and the context that contains it */ + struct Dllist* ExpiredJobList; + MemoryContext ExpiredJobListCtx; + + /* job info */ + struct JobWorkerInfoData* MyWorkerInfo; +} knl_t_job_context; + +typedef uintptr_t Datum; + +typedef struct knl_t_postgres_context { + /* clear key message that may appear in core file for security */ + bool clear_key_memory; + + /* true if create table in create table as select' has been done */ + bool table_created_in_CTAS; + const char* debug_query_string; /* client-supplied query string */ + bool isInResetUserName; + + /* Note: whereToSendOutput is initialized for the bootstrap/standalone case */ + int whereToSendOutput; // enum CommandDest + struct ResourcePool* local_foreign_respool; + + /* max_stack_depth converted to bytes for speed of checking */ + long max_stack_depth_bytes; + + /* mark if the initial password has been changed or not */ + bool password_changed; + + /* + * Stack base pointer -- initialized by PostmasterMain and inherited by + * subprocesses. This is not static because old versions of PL/Java modify + * it directly. Newer versions use set_stack_base(), but we want to stay + * binary-compatible for the time being. + */ + char* stack_base_ptr; + + /* + * Flag to keep track of whether we have started a transaction. + * For extended query protocol this has to be remembered across messages. + */ + bool xact_started; + + /* + * Flag to indicate that we are doing the outer loop's read-from-client, + * as opposed to any random read from client that might happen within + * commands like COPY FROM STDIN. + */ + bool DoingCommandRead; + + /* assorted command-line switches */ + const char* userDoption; /* -D switch */ + bool EchoQuery; + + /* + * people who want to use EOF should #define DONTUSENEWLINE in + * tcop/tcopdebug.h + */ +#ifndef TCOP_DONTUSENEWLINE + int UseNewLine; /* Use newlines query delimiters (the default) */ +#else + int UseNewLine; /* Use EOF as query delimiters */ +#endif /* TCOP_DONTUSENEWLINE */ + + /* whether or not, and why, we were canceled by conflict with recovery */ + bool RecoveryConflictPending; + bool RecoveryConflictRetryable; + int RecoveryConflictReason; // enum ProcSignalReason + + /* reused buffer to pass to SendRowDescriptionMessage() */ + struct StringInfoData* row_description_buf; + const char* clobber_qstr; + + /* + * for delta merge + */ + Datum query_result; + + /* + * It is a list of some relations or columns which have no statistic info. + * we should output them to warning or log if it is not null. + */ + List* g_NoAnalyzeRelNameList; + + /* show real run datanodes of pbe query for explain analyze/performance */ + bool mark_explain_analyze; + + /* + * false if the query is non-explain or explain analyze(performance), true if + * it is simple explain. + */ + bool mark_explain_only; + + /* GUC variable to enable plan cache if stmt_name is not given. */ + bool enable_explicit_stmt_name; + long val; + // struct rusage Save_r; // not define + struct timeval Save_t; + + bool gpc_fisrt_send_clean; // cn send clean to dn for global plan cache +} knl_t_postgres_context; + +typedef struct knl_t_utils_context { + /* to record the sequent count when creating memory context */ + int mctx_sequent_count; + + /* to track the memory context when query is executing */ + struct MemoryTrackData* ExecutorMemoryTrack; + +#ifdef MEMORY_CONTEXT_CHECKING + /* to record the sequent count of GUC setting */ + int memory_track_sequent_count; + + /* to record the plan node id of GUC setting */ + int memory_track_plan_nodeid; + + /* to save the detail allocation information */ + struct StringInfoData* detailTrackingBuf; +#endif + + /* used to track the element count in the output file */ + int track_cnt; + + /* gValueCompareContext -- special memory context for partition value routing. + * It's created under TOP memory context, and destroyed until this thread exits. + * It's used during each value's partition routing, and reset after done. + */ + MemoryContext gValueCompareContext; + /*ContextUsedCount-- is used to count the number of gValueCompareContext to + * avoid the allocated memory is released early. + */ + int ContextUsedCount; + struct PartitionIdentifier* partId; +#define RANGE_PARTKEYMAXNUM 4 + struct Const* valueItemArr[RANGE_PARTKEYMAXNUM]; + struct ResourceOwnerData* TopResourceOwner; + struct ResourceOwnerData* CurrentResourceOwner; + struct ResourceOwnerData* STPSavedResourceOwner; + struct ResourceOwnerData* CurTransactionResourceOwner; + struct ResourceOwnerData* TopTransactionResourceOwner; + struct ResourceReleaseCallbackItem* ResourceRelease_callbacks; + bool SortColumnOptimize; + struct RelationData* pRelatedRel; + + timer_t sigTimerId; + + unsigned int ConfigFileLineno; + const char* GUC_flex_fatal_errmsg; + sigjmp_buf* GUC_flex_fatal_jmp; + + /* Static state for pg_strtok */ + char* pg_strtok_ptr; + /* + * Support for newNode() macro + * + * In a GCC build there is no need for the global variable newNodeMacroHolder. + * However, we create it anyway, to support the case of a non-GCC-built + * loadable module being loaded into a GCC-built backend. + */ + Node* newNodeMacroHolder; + + /* Memory Protecting feature initialization flag */ + bool gs_mp_inited; + + /* Memory Protecting need flag */ + bool memNeedProtect; + + /* Track memory usage in chunks at individual thread level */ + int32 trackedMemChunks; + + /* Track memory usage in bytes at individual thread level */ + int64 trackedBytes; + + /* Per thread/query quota in chunks */ + int32 maxChunksPerThread; /* Will be updated by CostSize */ + + /* Memory Protecting feature initialization flag */ + int32 beyondChunk; + + bool backend_reserved; +} knl_t_utils_context; + +/* Maximum number of preferred Datanodes that can be defined in cluster */ +#define MAX_PREFERRED_NODES 64 + +typedef struct knl_t_pgxc_context { + Oid primary_data_node; + int num_preferred_data_nodes; + Oid preferred_data_node[MAX_PREFERRED_NODES]; + + /* + * Local cache for current installation/redistribution node group, allocated in + * t_thrd.top_mem_cxt at session start-up time + */ + char* current_installation_nodegroup; + char* current_redistribution_nodegroup; + int globalBucketLen; + + /* Global number of nodes. Point to a shared memory block */ + int* shmemNumCoords; + int* shmemNumCoordsInCluster; + int* shmemNumDataNodes; + int* shmemNumDataStandbyNodes; + + /* Shared memory tables of node definitions */ + struct NodeDefinition* coDefs; + struct NodeDefinition* coDefsInCluster; + struct NodeDefinition* dnDefs; + struct NodeDefinition* dnStandbyDefs; + + /* pgxcnode.cpp */ + struct PGXCNodeNetCtlLayer* pgxc_net_ctl; + + struct Instrumentation* GlobalNetInstr; + + /* save the connection to the compute pool */ + struct pgxc_node_handle* compute_pool_handle; + struct pg_conn* compute_pool_conn; + + /* execRemote.cpp */ + + /* + * Flag to track if a temporary object is accessed by the current transaction + */ + bool temp_object_included; + +#ifdef PGXC + struct abort_callback_type* dbcleanup_info; +#endif +#define SOCKET_BUFFER_LEN 256 + char socket_buffer[SOCKET_BUFFER_LEN]; + bool is_gc_fdw; + bool is_gc_fdw_analyze; + int gc_fdw_current_idx; + int gc_fdw_max_idx; + int gc_fdw_run_version; + struct SnapshotData* gc_fdw_snapshot; +#define BEGIN_CMD_BUFF_SIZE 1024 + char begin_cmd[BEGIN_CMD_BUFF_SIZE]; +} knl_t_pgxc_context; + +typedef struct knl_t_conn_context { + /* connector.cpp */ + char* value_drivertype; + char* value_dsn; + char* value_username; + char* value_password; + char* value_sql; + char* value_encoding; + /* + * Extension Connector Controler + */ + class ECControlBasic* ecCtrl; + + /* odbc_connector.cpp */ + + void* dl_handle; + void* _conn; + void* _result; + struct pg_enc2name* _DatabaseEncoding; + const char* _float_inf; +} knl_t_conn_context; + +typedef struct { + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t sleep_long; +} knl_t_page_redo_context; + +typedef struct knl_t_startup_context { + /* + * Flags set by interrupt handlers for later service in the redo loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t failover_triggered; + volatile sig_atomic_t switchover_triggered; + volatile sig_atomic_t primary_triggered; + volatile sig_atomic_t standby_triggered; + + /* + * Flag set when executing a restore command, to tell SIGTERM signal handler + * that it's safe to just proc_exit. + */ + volatile sig_atomic_t in_restore_command; + + struct notifysignaldata* NotifySigState; +} knl_t_startup_context; + +typedef struct knl_t_alarmchecker_context { + /* private variables for alarm checker thread */ + Latch AlarmCheckerLatch; /* the tls latch for alarm checker thread */ + + /* signal handle flags */ + volatile sig_atomic_t gotSighup; /* the signal flag of SIGHUP */ + volatile sig_atomic_t gotSigdie; /* the signal flag of SIGTERM and SIGINT */ +} knl_t_alarmchecker_context; + +typedef struct knl_t_lwlockmoniter_context { + /* Flags set by interrupt handlers for later service in the main loop. */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_lwlockmoniter_context; + +typedef struct knl_t_remoteservice_context { + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + struct RPCServerContext* server_context; +} knl_t_remoteservice_context; + +typedef struct knl_t_walwriter_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_walwriter_context; + +typedef struct knl_t_walwriterauxiliary_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_walwriterauxiliary_context; + +typedef struct knl_t_poolcleaner_context { + volatile sig_atomic_t shutdown_requested; +} knl_t_poolcleaner_context; + +typedef struct knl_t_catchup_context { + volatile sig_atomic_t catchup_shutdown_requested; +} knl_t_catchup_context; + +/* + * Pointer to a location in the XLOG. These pointers are 64 bits wide, + * because we don't want them ever to overflow. + */ +typedef uint64 XLogRecPtr; + +typedef struct knl_t_checkpoint_context { + struct CheckpointerShmemStruct* CheckpointerShmem; + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t checkpoint_requested; + volatile sig_atomic_t shutdown_requested; + + /* Private state */ + bool ckpt_active; + + /* these values are valid when ckpt_active is true: */ + pg_time_t ckpt_start_time; + XLogRecPtr ckpt_start_recptr; + double ckpt_cached_elapsed; + + pg_time_t last_checkpoint_time; + pg_time_t last_xlog_switch_time; + pg_time_t last_truncate_log_time; + int absorb_counter; + int ckpt_done; +} knl_t_checkpoint_context; + +typedef struct knl_t_snapshot_context { + struct SnapshotData* SnapshotNowData; + struct SnapshotData* SnapshotSelfData; + struct SnapshotData* SnapshotAnyData; + struct SnapshotData* SnapshotToastData; +} knl_t_snapshot_context; + +typedef struct knl_t_comm_context { + /* + *last epoll wait up time of receiver loop thread + */ + uint64 g_receiver_loop_poll_up; + int LibcommThreadType; + /* + * libcomm thread use libcomm_semaphore wake up work thread + * libcomm_semaphore save as mailbox->semaphore + * libcomm_semaphore create by gs_poll_create when work thread call gs_connect/gs_send/gs_wait_poll first time + * libcomm_semaphore destory by gs_poll_close when thread exit + */ + struct binary_semaphore* libcomm_semaphore; + struct mc_poller* g_libcomm_poller_list; + struct mc_poller_hndl_list* g_libcomm_recv_poller_hndl_list; + /* + *last time when consumer thread exit gs_wait_poll + */ + uint64 g_consumer_process_duration; + /* + *last time when producer thread exit gs_send + */ + uint64 g_producer_process_duration; + pid_t MyPid; + uint64 debug_query_id; +} knl_t_comm_context; + +typedef struct knl_t_libpq_context { + /* + * listen socket for unix domain connection + * between receiver flow control thread and postmaster + */ + int listen_fd_for_recv_flow_ctrl; + /* Where the Unix socket file is */ + char sock_path[MAXPGPATH]; + /* Where the Unix socket file for ha port is */ + char ha_sock_path[MAXPGPATH]; + char* PqSendBuffer; + /* Size send buffer */ + int PqSendBufferSize; + /* Next index to store a byte in PqSendBuffer */ + int PqSendPointer; + /* Next index to send a byte in PqSendBuffer */ + int PqSendStart; + char* PqRecvBuffer; + /* Size recv buffer */ + int PqRecvBufferSize; + /* Next index to read a byte from PqRecvBuffer */ + int PqRecvPointer; + /* End of data available in PqRecvBuffer */ + int PqRecvLength; + /* Message status */ + bool PqCommBusy; + bool DoingCopyOut; +#ifdef HAVE_SIGPROCMASK + sigset_t UnBlockSig, BlockSig, StartupBlockSig; +#else + int UnBlockSig, BlockSig, StartupBlockSig; +#endif + + /* variables for save query results to temp file*/ + bool save_query_result_to_disk; + struct TempFileContextInfo* PqTempFileContextInfo; + + /* + * pre-parsed content of HBA config file: list of HbaLine structs. + * parsed_hba_context is the memory context where it lives. + */ + List* parsed_hba_lines; + MemoryContext parsed_hba_context; +} knl_t_libpq_context; + +typedef struct knl_t_contrib_context { + int g_searchletId; + struct S_VectorInfo* vec_info; + bool assert_enabled; + Datum g_log_hostname; + Datum g_log_nodename; + + /* Hash table for caching the results of shippability lookups */ + HTAB* ShippableCacheHash; + + /* + * Valid options for gc_fdw. + * Allocated and filled in InitGcFdwOptions. + */ + struct PgFdwOption* gc_fdw_options; +} knl_t_contrib_context; + +typedef struct knl_t_basebackup_context { + char g_xlog_location[MAXPGPATH]; + + char* buf_block; +} knl_t_basebackup_context; + +typedef struct knl_t_datarcvwriter_context { + HTAB* data_writer_rel_tab; + + /* Data receiver writer flush page error times */ + uint32 dataRcvWriterFlushPageErrorCount; + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t gotSIGHUP; + volatile sig_atomic_t shutdownRequested; + + bool AmDataReceiverForDummyStandby; + + /* max dummy data write file (default: 1GB) */ + uint32 dummy_data_writer_file_num; +} knl_t_datarcvwriter_context; + +typedef struct knl_t_libwalreceiver_context { + /* Current connection to the primary, if any */ + struct pg_conn* streamConn; + + /* Buffer for currently read records */ + char* recvBuf; +} knl_t_libwalreceiver_context; + +typedef struct knl_t_sig_context { + unsigned long signal_handle_cnt; + GsSignalCheckType gs_sigale_check_type; + uint64 session_id; +} knl_t_sig_context; + +typedef struct knl_t_slot_context { + /* Control array for replication slot management */ + struct ReplicationSlotCtlData* ReplicationSlotCtl; + + /* My backend's replication slot in the shared memory array */ + struct ReplicationSlot* MyReplicationSlot; +} knl_t_slot_context; + +typedef struct knl_t_datareceiver_context { + int DataReplFlag; + + /* + * Flags set by interrupt handlers of datareceiver for later service in the + * main loop. + */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + + struct StandbyDataReplyMessage* reply_message; + + /* Current connection to the primary, if any */ + struct pg_conn* dataStreamingConn; + + /* DummyStandby */ + bool AmDataReceiverForDummyStandby; + + /* Buffer for currently read data */ + char* recvBuf; + + struct DataRcvData* DataRcv; + + /* + * About SIGTERM handling: + * + * We can't just exit(1) within SIGTERM signal handler, because the signal + * might arrive in the middle of some critical operation, like while we're + * holding a spinlock. We also can't just set a flag in signal handler and + * check it in the main loop, because we perform some blocking operations + * like libpqrcv_PQexec(), which can take a long time to finish. + * + * We use a combined approach: When DataRcvImmediateInterruptOK is true, it's + * safe for the signal handler to elog(FATAL) immediately. Otherwise it just + * sets got_SIGTERM flag, which is checked in the main loop when convenient. + * + * This is very much like what regular backends do with t_thrd.int_cxt.ImmediateInterruptOK, + * ProcessInterrupts() etc. + */ + volatile bool DataRcvImmediateInterruptOK; +} knl_t_datareceiver_context; + +typedef struct knl_t_datasender_context { + /* Array of DataSnds in shared memory */ + struct DataSndCtlData* DataSndCtl; + + /* My slot in the shared memory array */ + struct DataSnd* MyDataSnd; + + /* Global state */ + bool am_datasender; /* Am I a datasender process ? */ + + /* + * Buffer for processing reply messages. + */ + struct StringInfoData* reply_message; + + /* + * Buffer for constructing outgoing messages + * (1 + sizeof(DataPageMessageHeader) + MAX_SEND_SIZE bytes) + */ + char* output_message; + + /* + * dummy standby read data file num and offset. + */ + uint32 dummy_data_read_file_num; + FILE* dummy_data_read_file_fd; + + /* + * Timestamp of the last receipt of the reply from the standby. + */ + TimestampTz last_reply_timestamp; + + /* Have we sent a heartbeat message asking for reply, since last reply? */ + bool ping_sent; + + /* Flags set by signal handlers for later service in main loop */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t datasender_shutdown_requested; + volatile sig_atomic_t datasender_ready_to_stop; +} knl_t_datasender_context; + +typedef struct knl_t_walreceiver_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t got_SIGTERM; + volatile sig_atomic_t start_switchover; + char gucconf_file[MAXPGPATH]; + char temp_guc_conf_file[MAXPGPATH]; + char gucconf_lock_file[MAXPGPATH]; + /* + * Define guc parameters which would not be synchronized to standby. + * NB: RESERVE_SIZE must be changed at the same time. + */ + char** reserve_item; +#define RESERVE_SIZE 33 + time_t standby_config_modify_time; + time_t Primary_config_modify_time; + TimestampTz last_sendfilereply_timestamp; + int check_file_timeout; + struct WalRcvCtlBlock* walRcvCtlBlock; + struct StandbyReplyMessage* reply_message; + struct StandbyHSFeedbackMessage* feedback_message; + struct StandbySwitchRequestMessage* request_message; + struct ConfigModifyTimeMessage* reply_modify_message; + volatile bool WalRcvImmediateInterruptOK; + bool AmWalReceiverForFailover; + bool AmWalReceiverForStandby; + int control_file_writed; +} knl_t_walreceiver_context; + +typedef struct knl_t_walsender_context { + char* load_cu_buffer; + int load_cu_buffer_size; + /* Array of WalSnds in shared memory */ + struct WalSndCtlData* WalSndCtl; + /* My slot in the shared memory array */ + struct WalSnd* MyWalSnd; + int logical_xlog_advanced_timeout; /* maximum time to write xlog * of logical slot advance */ + typedef int ServerMode; + typedef int DemoteMode; + DemoteMode Demotion; + /* State for WalSndWakeupRequest */ + bool wake_wal_senders; + bool wal_send_completed; + /* + * These variables are used similarly to openLogFile/Id/Seg/Off, + * but for walsender to read the XLOG. + */ + int sendFile; + typedef uint64 XLogSegNo; + XLogSegNo sendSegNo; + uint32 sendOff; + struct WSXLogJustSendRegion* wsXLogJustSendRegion; + /* + * How far have we sent WAL already? This is also advertised in + * MyWalSnd->sentPtr. (Actually, this is the next WAL location to send.) + */ + typedef uint64 XLogRecPtr; + XLogRecPtr sentPtr; + XLogRecPtr catchup_threshold; + /* + * Buffer for processing reply messages. + */ + struct StringInfoData* reply_message; + /* + * Buffer for processing timestamp. + */ + struct StringInfoData* tmpbuf; + /* + * Buffer for constructing outgoing messages + * (1 + sizeof(WalDataMessageHeader) + MAX_SEND_SIZE bytes) + * if with enable_mix_replication being true the new message as the following: + * (1 + sizeof(WalDataMessageHeader) + 1 + sizeof(XLogRecPtr) + MAX_SEND_SIZE bytes) + * 1 --> 'w' + * sizeof(WalDataMessageHeader) --> WalDataMessageHeader + * 1 --> 'w' + * sizeof(XLogRecPtr) -->XLogRecPtr dataStart + * MAX_SEND_SIZE bytes --> wal data bytes + */ + char* output_xlog_message; + Size output_xlog_msg_prefix_len; + /* + * Buffer for constructing outgoing messages + * (sizeof(DataElementHeaderData) + MAX_SEND_SIZE bytes) + * if with enable_mix_replication being true the new message as the following: + * (1 + sizeof(WalDataMessageHeader) + 1 + MAX_SEND_SIZE bytes) + * 1 --> 'd' + * sizeof(WalDataMessageHeader) --> WalDataMessageHeader + * 1 --> 'd' + * MAX_SEND_SIZE bytes --> wal data bytes + */ + char* output_data_message; + /* used to flag the latest length in output_data_message*/ + uint32 output_data_msg_cur_len; + XLogRecPtr output_data_msg_start_xlog; + XLogRecPtr output_data_msg_end_xlog; + /* + * The xlog reader and private info employed for the xlog parsing in wal sender. + */ + struct XLogReaderState* ws_xlog_reader; + /* + * Timestamp of the last receipt of the reply from the standby. + */ + TimestampTz last_reply_timestamp; + /* + * Timestamp of the last logical xlog advanced is written. + */ + TimestampTz last_logical_xlog_advanced_timestamp; + /* Have we sent a heartbeat message asking for reply, since last reply? */ + bool waiting_for_ping_response; + /* Flags set by signal handlers for later service in main loop */ + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t walsender_shutdown_requested; + volatile sig_atomic_t walsender_ready_to_stop; + volatile sig_atomic_t response_switchover_requested; + ServerMode server_run_mode; + /* for config_file */ + char gucconf_file[MAXPGPATH]; + char gucconf_lock_file[MAXPGPATH]; + /* the dummy data reader fd for the wal streaming */ + FILE* ws_dummy_data_read_file_fd; + uint32 ws_dummy_data_read_file_num; + /* Missing CU checking stuff */ + struct cbmarray* CheckCUArray; + struct LogicalDecodingContext* logical_decoding_ctx; + XLogRecPtr logical_startptr; + int remotePort; +} knl_t_walsender_context; + +typedef struct knl_t_walreceiverfuncs_context { + struct WalRcvData* WalRcv; + int WalReplIndex; +} knl_t_walreceiverfuncs_context; + +typedef struct knl_t_replgram_context { + /* Result of the parsing is returned here */ + struct Node* replication_parse_result; +} knl_t_replgram_context; + +typedef struct knl_t_replscanner_context { + struct yy_buffer_state* scanbufhandle; + struct StringInfoData* litbuf; +} knl_t_replscanner_context; + +typedef struct knl_t_syncrepgram_context { + /* Result of parsing is returned in one of these two variables */ + struct SyncRepConfigData* syncrep_parse_result; +} knl_t_syncrepgram_context; + +typedef struct knl_t_syncrepscanner_context { + struct yy_buffer_state* scanbufhandle; + struct StringInfoData* xdbuf; + int result; +} knl_t_syncrepscanner_context; + +typedef struct knl_t_syncrep_context { + struct SyncRepConfigData* SyncRepConfig; + bool announce_next_takeover; +} knl_t_syncrep_context; + +typedef struct knl_t_logical_context { + int sendFd; + uint64 sendSegNo; + uint32 sendOff; + bool ExportInProgress; + ResourceOwner SavedResourceOwnerDuringExport; +} knl_t_logical_context; + +typedef struct knl_t_dataqueue_context { + struct DataQueueData* DataSenderQueue; + struct DataQueueData* DataWriterQueue; + struct BCMElementData* BCMElementArray; + uint32 BCMElementArrayIndex1; + uint32 BCMElementArrayIndex2; + struct DataQueuePtr* BCMElementArrayOffset1; + struct DataQueuePtr* BCMElementArrayOffset2; + uint32 save_send_dummy_count; + struct HTAB* heap_sync_rel_tab; +} knl_t_dataqueue_context; + +typedef struct knl_t_walrcvwriter_context { + uint64 walStreamWrite; /* last byte + 1 written out in the standby */ + + /* + * Flags set by interrupt handlers for later service in the main loop. + */ + volatile sig_atomic_t gotSIGHUP; + volatile sig_atomic_t shutdownRequested; + + int WAL_WRITE_UNIT_BYTES; + uint32 ws_dummy_data_writer_file_num; +} knl_t_walrcvwriter_context; + +typedef int CacheSlotId_t; +typedef void (*pg_on_exit_callback)(int code, Datum arg); +typedef void (*shmem_startup_hook_type)(void); +typedef struct ONEXIT { + pg_on_exit_callback function; + Datum arg; +} ONEXIT; +#define MAX_ON_EXITS 20 +typedef struct knl_t_storage_context { + /* + * Bookkeeping for tracking emulated transactions in recovery + */ + TransactionId latestObservedXid; + struct RunningTransactionsData* CurrentRunningXacts; + struct VirtualTransactionId* proc_vxids; + + union BufferDescPadded* BufferDescriptors; + char* BufferBlocks; + struct WritebackContext* BackendWritebackContext; + struct HTAB* SharedBufHash; + struct HTAB* BufFreeListHash; + struct BufferDesc* InProgressBuf; + /* local state for StartBufferIO and related functions */ + volatile bool IsForInput; + /* local state for LockBufferForCleanup */ + struct BufferDesc* PinCountWaitBuf; + /* local state for aio clean up resource */ + struct AioDispatchDesc** InProgressAioDispatch; + int InProgressAioDispatchCount; + struct BufferDesc* InProgressAioBuf; + int InProgressAioType; + /* + * When btree split, it will record two xlog: + * 1. page split + * 2. insert new split page to parent + * Since it is an atomic action, don't interrupt above two steps. + * Now use a special flag to remark and dont't ereport error when read buffers. + */ + bool is_btree_split; + /* + * Backend-Private refcount management: + * + * Each buffer also has a private refcount that keeps track of the number of + * times the buffer is pinned in the current process. This is so that the + * shared refcount needs to be modified only once if a buffer is pinned more + * than once by a individual backend. It's also used to check that no buffers + * are still pinned at the end of transactions and when exiting. + * + * + * To avoid - as we used to - requiring an array with g_instance.attr.attr_storage.NBuffers entries to keep + * track of local buffers we use a small sequentially searched array + * (PrivateRefCountArray) and a overflow hash table (PrivateRefCountHash) to + * keep track of backend local pins. + * + * Until no more than REFCOUNT_ARRAY_ENTRIES buffers are pinned at once, all + * refcounts are kept track of in the array; after that, new array entries + * displace old ones into the hash table. That way a frequently used entry + * can't get "stuck" in the hashtable while infrequent ones clog the array. + * + * Note that in most scenarios the number of pinned buffers will not exceed + * REFCOUNT_ARRAY_ENTRIES. + */ + struct PrivateRefCountEntry* PrivateRefCountArray; + struct HTAB* PrivateRefCountHash; + int32 PrivateRefCountOverflowed; + uint32 PrivateRefCountClock; + /* + * Information saved between calls so we can determine the strategy + * point's advance rate and avoid scanning already-cleaned buffers. + */ + bool saved_info_valid; + int prev_strategy_buf_id; + uint32 prev_strategy_passes; + int next_to_clean; + uint32 next_passes; + /* Moving averages of allocation rate and clean-buffer density */ + float smoothed_alloc; + float smoothed_density; + + /* Pointers to shared state */ + struct BufferStrategyControl* StrategyControl; + /* remember global block slot in progress */ + CacheSlotId_t CacheBlockInProgressIO; + CacheSlotId_t CacheBlockInProgressUncompress; + CacheSlotId_t MetaBlockInProgressIO; + + List* RecoveryLockList; + int standbyWait_us; + /* + * All accesses to pg_largeobject and its index make use of a single Relation + * reference, so that we only need to open pg_relation once per transaction. + * To avoid problems when the first such reference occurs inside a + * subtransaction, we execute a slightly klugy maneuver to assign ownership of + * the Relation reference to TopTransactionResourceOwner. + */ + struct RelationData* lo_heap_r; + struct RelationData* lo_index_r; + slock_t dummy_spinlock; + int spins_per_delay; + + /* Workspace for FindLockCycle */ + struct PGPROC** visitedProcs; /* Array of visited procs */ + int nVisitedProcs; + /* Workspace for TopoSort */ + struct PGPROC** topoProcs; /* Array of not-yet-output procs */ + int* beforeConstraints; /* Counts of remaining before-constraints */ + int* afterConstraints; /* List head for after-constraints */ + /* Output area for ExpandConstraints */ + struct WAIT_ORDER* waitOrders; /* Array of proposed queue rearrangements */ + int nWaitOrders; + struct PGPROC** waitOrderProcs; /* Space for waitOrders queue contents */ + /* Current list of constraints being considered */ + struct EDGE* curConstraints; + int nCurConstraints; + int maxCurConstraints; + /* Storage space for results from FindLockCycle */ + struct EDGE* possibleConstraints; + int nPossibleConstraints; + int maxPossibleConstraints; + struct DEADLOCK_INFO* deadlockDetails; + int nDeadlockDetails; + /* PGPROC pointer of all blocking autovacuum worker found and its max size. + * blocking_autovacuum_proc_num is in [0, autovacuum_max_workers]. + * + * Partitioned table has been supported, which maybe have hundreds of partitions. + * When a few autovacuum workers are active and running, partitions of the same partitioned + * table, whose shared lock is hold by these workers, may be handled at the same time. + * So that remember all the blocked autovacuum workers and notify to cancle them. + */ + struct PGPROC** blocking_autovacuum_proc; + int blocking_autovacuum_proc_num; + TimestampTz deadlock_checker_start_time; + const char* conflicting_lock_mode_name; + ThreadId conflicting_lock_thread_id; + bool conflicting_lock_by_holdlock; + /* + * Count of the number of fast path lock slots we believe to be used. This + * might be higher than the real number if another backend has transferred + * our locks to the primary lock table, but it can never be lower than the + * real value, since only we can acquire locks on our own behalf. + */ + int FastPathLocalUseCount; + volatile struct FastPathStrongRelationLockData* FastPathStrongRelationLocks; + /* + * Pointers to hash tables containing lock state + * + * The LockMethodLockHash and LockMethodProcLockHash hash tables are in + * shared memory; LockMethodLocalHash is local to each backend. + */ + struct HTAB* LockMethodLockHash; + struct HTAB* LockMethodProcLockHash; + struct HTAB* LockMethodLocalHash; + /* private state for error cleanup */ + struct LOCALLOCK* StrongLockInProgress; + struct LOCALLOCK* awaitedLock; + struct ResourceOwnerData* awaitedOwner; + /* PGPROC pointer of blocking data redistribution proc. */ + struct PGPROC* blocking_redistribution_proc; + struct VirtualTransactionId* lock_vxids; + + /* if false, this transaction has the same timeout to check deadlock + * with the others. if true, the larger timeout, the lower possibility + * of aborting. the default timeout is defined by *DeadlockTimeout*. + * one case is that, when VACUUM FULL PARTITION is running while another + * transaction is also running, and deadlock maybe happens, so that one + * of them shall abort and rollback. because VACUUM FULL is a heavy work + * and we always want it to work done. so that we can enlarge the timeout + * to check deadlock, then another transaction has the bigger possibility + * to check and rollback. + */ + bool EnlargeDeadlockTimeout; + /* If we are waiting for a lock, this points to the associated LOCALLOCK */ + struct LOCALLOCK* lockAwaited; + /* Mark these volatile because they can be changed by signal handler */ + volatile bool standby_timeout_active; + volatile bool statement_timeout_active; + volatile bool deadlock_timeout_active; + volatile bool lockwait_timeout_active; + volatile int deadlock_state; + volatile bool cancel_from_timeout; + /* timeout_start_time is set when log_lock_waits is true */ + TimestampTz timeout_start_time; + /* statement_fin_time is valid only if statement_timeout_active is true */ + TimestampTz statement_fin_time; + TimestampTz statement_fin_time2; /* valid only in recovery */ + /* global variable */ + char* pageCopy; + + int num_held_lwlocks; + struct LWLockHandle* held_lwlocks; + int lock_addin_request; + bool lock_addin_request_allowed; + int counts_for_pid; + int* block_counts; + /* description, memory context opt */ + MemoryContext remote_function_context; + bool work_env_init; + + shmem_startup_hook_type shmem_startup_hook; + Size total_addin_request; + bool addin_request_allowed; + + /* + * This flag tracks whether we've called atexit() in the current process + * (or in the parent postmaster). + */ + bool atexit_callback_setup; + ONEXIT on_proc_exit_list[MAX_ON_EXITS]; + ONEXIT on_shmem_exit_list[MAX_ON_EXITS]; + ONEXIT before_shmem_exit_list[MAX_ON_EXITS]; + int on_proc_exit_index; + int on_shmem_exit_index; + int before_shmem_exit_index; + + union CmprMetaUnion* cmprMetaInfo; + + /* Thread share file id cache */ + struct HTAB* DataFileIdCache; + + /* + * Maximum number of file descriptors to open for either VFD entries or + * AllocateFile/AllocateDir/OpenTransientFile operations. This is initialized + * to a conservative value, and remains that way indefinitely in bootstrap or + * standalone-backend cases. In normal postmaster operation, the postmaster + * calls set_max_safe_fds() late in initialization to update the value, and + * that value is then inherited by forked subprocesses. * + * Note: the value of max_files_per_process is taken into account while + * setting this variable, and so need not be tested separately. + */ + int max_safe_fds; /* default if not changed */ + /* reserve `1000' for thread-private file id */ + int max_userdatafiles; + +} knl_t_storage_context; + +typedef struct knl_t_port_context { + char cryptresult[21]; /* encrypted result (1 + 4 + 4 + 11 + 1)*/ + char buf[24]; + + bool thread_is_exiting; + struct ThreadArg* m_pThreadArg; + + locale_t save_locale_r; + NameData cur_datcollate; /* LC_COLLATE setting */ + NameData cur_datctype; /* LC_CTYPE setting */ + NameData cur_monetary; /* LC_MONETARY setting */ + NameData cur_numeric; /* LC_NUMERIC setting */ +} knl_t_port_context; + +typedef struct knl_t_tsearch_context { + int nres; + int ntres; +} knl_t_tsearch_context; + +typedef struct knl_t_postmaster_context { +/* Notice: the value is same sa GUC_MAX_REPLNODE_NUM */ +#ifdef ENABLE_MULTIPLE_NODES +#define MAX_REPLNODE_NUM 8 +#else +#define MAX_REPLNODE_NUM 9 +#endif +#define MAXLISTEN 64 +#define IP_LEN 64 + + /* flag when process startup packet for logic conn */ + bool ProcessStartupPacketForLogicConn; + + /* socket and port for recv gs_sock from receiver flow control*/ + int sock_for_libcomm; + struct Port* port_for_libcomm; + bool KeepSocketOpenForStream; + + /* + * Stream replication connection info between primary, standby and secondary. + * + * ReplConn*1 is used to connect primary on standby, or standby on primary, or + * connect primary or standby on secondary. + * ReplConn*2 is used to connect secondary on primary or standby, or connect primary + * or standby on secondary. + */ + struct replconninfo* ReplConnArray[MAX_REPLNODE_NUM]; + bool ReplConnChanged[MAX_REPLNODE_NUM]; + struct hashmemdata* HaShmData; + + /* The socket(s) we're listening to. */ + pgsocket ListenSocket[MAXLISTEN]; + char LocalAddrList[MAXLISTEN][IP_LEN]; + int LocalIpNum; + int listen_sock_type[MAXLISTEN]; /* ori type: enum ListenSocketType */ + gs_thread_t CurExitThread; + + bool IsRPCWorkerThread; + + /* private variables for reaper backend thread */ + Latch ReaperBackendLatch; + + /* Database Security: Support database audit */ + bool audit_primary_start; + bool audit_primary_failover; + bool audit_standby_switchover; + bool senderToDummyStandby; + bool senderToBuildStandby; + bool ReachedNormalRunning; /* T if we've reached PM_RUN */ + bool redirection_done; /* stderr redirected for syslogger? */ + + /* received START_AUTOVAC_LAUNCHER signal */ + volatile sig_atomic_t start_autovac_launcher; + /* the launcher needs to be signalled to communicate some condition */ + volatile bool avlauncher_needs_signal; + /* received PMSIGNAL_START_JOB_SCHEDULER signal */ + volatile sig_atomic_t start_job_scheduler; + /* the jobscheduler needs to be signalled to communicate some condition */ + volatile bool jobscheduler_needs_signal; + + /* + * State for assigning random salts and cancel keys. + * Also, the global t_thrd.proc_cxt.MyCancelKey passes the cancel key assigned to a given + * backend from the postmaster to that backend (via fork). + */ + unsigned int random_seed; + struct timeval random_start_time; + + /* key pair to be used as object id while using advisory lock for backup */ + Datum xc_lockForBackupKey1; + Datum xc_lockForBackupKey2; + + bool forceNoSeparate; + +#ifndef WIN32 + /* + * File descriptors for pipe used to monitor if postmaster is alive. + * First is POSTMASTER_FD_WATCH, second is POSTMASTER_FD_OWN. + */ + int postmaster_alive_fds[2]; +#endif + +#ifndef WIN32 + int syslogPipe[2]; +#endif +} knl_t_postmaster_context; + +#define CACHE_BUFF_LEN 128 + +typedef struct knl_t_buf_context { + char cash_buf[CACHE_BUFF_LEN]; + char config_opt_buf[256]; + char config_opt_reset_buf[256]; + /* this buffer is only used if errno has a bogus value */ + char errorstr_buf[48]; + char pg_rusage_show_buf[100]; + char unpack_sql_state_buf[12]; + char show_enable_dynamic_workload_buf[8]; + char show_enable_memory_limit_buf[8]; + char show_log_file_mode_buf[8]; + char show_memory_detail_tracking_buf[256]; + char show_tcp_keepalives_idle_buf[16]; + char show_tcp_keepalives_interval_buf[16]; + char show_tcp_keepalives_count_buf[16]; + char show_unix_socket_permissions_buf[8]; +} knl_t_buf_context; + +typedef struct knl_t_bootstrap_context { +#define MAXATTR 40 +#define NAMEDATALEN 64 + int num_columns_read; + int yyline; /* line number for error reporting */ + + int MyAuxProcType; /* declared in miscadmin.h */ + struct RelationData* boot_reldesc; /* current relation descriptor */ + struct FormData_pg_attribute* attrtypes[MAXATTR]; /* points to attribute info */ + int numattr; /* number of attributes for cur. rel */ + + struct typmap** Typ; + struct typmap* Ap; + + MemoryContext nogc; /* special no-gc mem context */ + struct _IndexList* ILHead; + char newStr[NAMEDATALEN + 1]; /* array type names < NAMEDATALEN long */ +} knl_t_bootstrap_context; + +typedef struct knl_t_locale_context { + /* Environment variable storage area */ + char lc_collate_envbuf[LC_ENV_BUFSIZE]; + + char lc_ctype_envbuf[LC_ENV_BUFSIZE]; + + char lc_monetary_envbuf[LC_ENV_BUFSIZE]; + + char lc_numeric_envbuf[LC_ENV_BUFSIZE]; + + char lc_time_envbuf[LC_ENV_BUFSIZE]; + +} knl_t_locale_context; + + + +typedef struct knl_t_stat_context { + /* + * thread statistics of bad block + * used for cache current thread statistics of bad block + * update global_bad_block_stat by pgstat_send_badblock_stat() + */ + MemoryContext local_bad_block_mcxt; + HTAB* local_bad_block_stat; + +} knl_t_stat_context; + +typedef struct knl_t_thread_pool_context { + class ThreadPoolGroup* group; + class ThreadPoolListener* listener; + class ThreadPoolWorker* worker; + class ThreadPoolScheduler* scheduler; +#ifdef ENABLE_MULTIPLE_NODES + class ThreadPoolStream* stream; +#endif + bool reaper_dead_session; +} knl_t_thread_pool_context; + +/* percentile sql responese time */ +typedef struct knl_t_percentile_context { + bool need_exit; + volatile bool need_reset_timer; + struct PGXCNodeAllHandles* pgxc_all_handles; + volatile sig_atomic_t got_SIGHUP; +} knl_t_percentile_context; + +typedef struct knl_t_perf_snap_context { + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + time_t last_snapshot_start_time; + + struct pg_conn* connect; /* Cross database query */ + struct pg_result* res; + int cancel_request; /* connection cancel request */ + uint64 curr_table_size; // Current table size + uint64 curr_snapid; // snapid is Increasing + MemoryContext PerfSnapMemCxt; + volatile bool request_snapshot; + volatile bool is_mem_protect; +} knl_t_perf_snap_context; + +typedef struct knl_t_ash_context { + time_t last_ash_start_time; + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + uint32 slot; // the slot of ActiveSessionHistArray + struct wait_event_info* waitEventStr; +} knl_t_ash_context; + +typedef struct knl_t_statement_context { + volatile sig_atomic_t need_exit; + volatile bool got_SIGHUP; + TimestampTz min_slow_query_timestamp; + TimestampTz min_full_sql_timestamp; +} knl_t_statement_context; + + +/* Default send interval is 1s */ +const int DEFAULT_SEND_INTERVAL = 1000; +typedef struct knl_t_heartbeat_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + struct heartbeat_state* state; +} knl_t_heartbeat_context; + +/* compaction and compaction worker use */ +typedef struct knl_t_ts_compaction_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; + volatile sig_atomic_t sleep_long; + MemoryContext compaction_mem_cxt; + MemoryContext compaction_data_cxt; +} knl_t_ts_compaction_context; + +typedef struct knl_t_security_policy_context { + MemoryContext policy_audit_context; + MemoryContext policy_mask_context; + MemoryContext policy_rls_context; +} knl_t_security_policy_context; + +typedef struct knl_t_csnmin_sync_context { + volatile sig_atomic_t got_SIGHUP; + volatile sig_atomic_t shutdown_requested; +} knl_t_csnmin_sync_context; + +#ifdef ENABLE_MOT +/* MOT thread attributes */ +#define MOT_MAX_ERROR_MESSAGE 256 +#define MOT_MAX_ERROR_FRAMES 32 + +#define MOT_LOG_BUF_SIZE_KB 1 +#define MOT_MAX_LOG_LINE_LENGTH (MOT_LOG_BUF_SIZE_KB * 1024 - 1) + +namespace MOT { + struct StringBuffer; +} + +struct mot_error_frame { + int m_errorCode; + int m_severity; + const char* m_file; + int m_line; + const char* m_function; + const char* m_entity; + const char* m_context; + char m_errorMessage[MOT_MAX_ERROR_MESSAGE]; +}; + +typedef struct knl_t_mot_context { + // last error + int last_error_code; + int last_error_severity; + mot_error_frame error_stack[MOT_MAX_ERROR_FRAMES]; + int error_frame_count; + + // log line + char log_line[MOT_MAX_LOG_LINE_LENGTH + 1]; + int log_line_pos; + bool log_line_overflow; + MOT::StringBuffer* log_line_buf; + + // misc + uint8_t log_level; + bool init_codegen_once; + + uint16_t currentThreadId; + int currentNumaNodeId; + + int bindPolicy; + unsigned int mbindFlags; +} knl_t_mot_context; +#endif + +/* thread context. */ +typedef struct knl_thrd_context { + knl_thread_role role; + knl_thread_role subrole; /* we need some sub role status. */ + + struct GsSignalSlot* signal_slot; + /* Pointer to this process's PGPROC and PGXACT structs, if any */ + struct PGPROC* proc; + struct PGXACT* pgxact; + struct Backend* bn; + // we need to have a fake session to do some initialize + knl_session_context* fake_session; + + int myLogicTid; + + MemoryContext top_mem_cxt; + MemoryContextGroup* mcxt_group; + + knl_t_aes_context aes_cxt; + knl_t_aiocompleter_context aio_cxt; + knl_t_alarmchecker_context alarm_cxt; + knl_t_arch_context arch; + knl_t_async_context asy_cxt; + knl_t_audit_context audit; + knl_t_autovacuum_context autovacuum_cxt; + knl_t_basebackup_context basebackup_cxt; + knl_t_bgwriter_context bgwriter_cxt; + knl_t_bootstrap_context bootstrap_cxt; + knl_t_pagewriter_context pagewriter_cxt; + knl_t_buf_context buf_cxt; + knl_t_bulkload_context bulk_cxt; + knl_t_cbm_context cbm_cxt; + knl_t_checkpoint_context checkpoint_cxt; + knl_t_codegen_context codegen_cxt; + knl_t_comm_context comm_cxt; + knl_t_conn_context conn_cxt; + knl_t_contrib_context contrib_cxt; + knl_t_cstore_context cstore_cxt; + knl_t_dataqueue_context dataqueue_cxt; + knl_t_datarcvwriter_context datarcvwriter_cxt; + knl_t_datareceiver_context datareceiver_cxt; + knl_t_datasender_context datasender_cxt; + knl_t_dfs_context dfs_cxt; + knl_t_dynahash_context dyhash_cxt; + knl_t_explain_context explain_cxt; + knl_t_format_context format_cxt; + knl_t_index_context index_cxt; + knl_t_interrupt_context int_cxt; + knl_t_job_context job_cxt; + knl_t_libwalreceiver_context libwalreceiver_cxt; + knl_t_locale_context lc_cxt; + knl_t_log_context log_cxt; + knl_t_logger_context logger; + knl_t_logical_context logical_cxt; + knl_t_libpq_context libpq_cxt; + knl_t_lwlockmoniter_context lwm_cxt; + knl_t_mem_context mem_cxt; + knl_t_obs_context obs_cxt; + knl_t_pgxc_context pgxc_cxt; + knl_t_port_context port_cxt; + knl_t_postgres_context postgres_cxt; + knl_t_postmaster_context postmaster_cxt; + knl_t_proc_context proc_cxt; + knl_t_relopt_context relopt_cxt; + knl_t_remoteservice_context rs_cxt; + knl_t_replgram_context replgram_cxt; + knl_t_replscanner_context replscanner_cxt; + knl_t_shemem_ptr_context shemem_ptr_cxt; + knl_t_sig_context sig_cxt; + knl_t_slot_context slot_cxt; + knl_t_snapshot_context snapshot_cxt; + knl_t_startup_context startup_cxt; + knl_t_stat_context stat_cxt; + knl_t_storage_context storage_cxt; + knl_t_syncrep_context syncrep_cxt; + knl_t_syncrepgram_context syncrepgram_cxt; + knl_t_syncrepscanner_context syncrepscanner_cxt; + knl_t_thread_pool_context threadpool_cxt; + knl_t_time_context time_cxt; + knl_t_tsearch_context tsearch_cxt; + knl_t_twophasecleaner_context tpcleaner_cxt; + knl_t_utils_context utils_cxt; + knl_t_vacuum_context vacuum_cxt; + knl_t_walsender_context walsender_cxt; + knl_t_walrcvwriter_context walrcvwriter_cxt; + knl_t_walreceiver_context walreceiver_cxt; + knl_t_walreceiverfuncs_context walreceiverfuncs_cxt; + knl_t_walwriter_context walwriter_cxt; + knl_t_walwriterauxiliary_context walwriterauxiliary_cxt; + knl_t_catchup_context catchup_cxt; + knl_t_wlmthrd_context wlm_cxt; + knl_t_xact_context xact_cxt; + knl_t_xlog_context xlog_cxt; + knl_t_percentile_context percentile_cxt; + knl_t_perf_snap_context perf_snap_cxt; + knl_t_page_redo_context page_redo_cxt; + knl_t_heartbeat_context heartbeat_cxt; + knl_t_security_policy_context security_policy_cxt; + knl_t_poolcleaner_context poolcleaner_cxt; + knl_t_ts_compaction_context ts_compaction_cxt; + knl_t_ash_context ash_cxt; + knl_t_statement_context statement_cxt; + knl_t_streaming_context streaming_cxt; + knl_t_csnmin_sync_context csnminsync_cxt; +#ifdef ENABLE_MOT + knl_t_mot_context mot_cxt; +#endif +} knl_thrd_context; + +#ifdef ENABLE_MOT +extern void knl_thread_mot_init(); +#endif + +extern void knl_thread_init(knl_thread_role role); +extern THR_LOCAL knl_thrd_context t_thrd; + +inline bool StreamThreadAmI() +{ + return (t_thrd.role == STREAM_WORKER || t_thrd.role == THREADPOOL_STREAM); +} + +inline void StreamTopConsumerIam() +{ + t_thrd.subrole = TOP_CONSUMER; +} + +inline bool StreamTopConsumerAmI() +{ + return (t_thrd.subrole == TOP_CONSUMER); +} + +#ifdef ENABLE_MULTIPLE_NODES +#define BUCKETDATALEN (t_thrd.pgxc_cxt.globalBucketLen) +#define BUCKETSTRLEN (6*BUCKETDATALEN) +#endif + +RedoInterruptCallBackFunc RegisterRedoInterruptCallBack(RedoInterruptCallBackFunc func); +void RedoInterruptCallBack(); + +#endif /* SRC_INCLUDE_KNL_KNL_THRD_H_ */ diff -uprN postgresql-hll-2.14_old/include/knl/knl_variable.h postgresql-hll-2.14/include/knl/knl_variable.h --- postgresql-hll-2.14_old/include/knl/knl_variable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/knl/knl_variable.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * knl_variable.h + * Include file for knl variables. + * + * IDENTIFICATION + * src/include/knl/knl_variable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_KNL_BARIABLE_H_ +#define SRC_INCLUDE_KNL_VARIABLE_H_ + +#include "knl/knl_instance.h" +#include "knl/knl_session.h" +#include "knl/knl_thread.h" + +#endif /* SRC_INCLUDE_KNL_VARIABLE_H_ */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/lib/binaryheap.h postgresql-hll-2.14/include/lib/binaryheap.h --- postgresql-hll-2.14_old/include/lib/binaryheap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/binaryheap.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * binaryheap.h + * A simple binary heap implementation + * + * + * IDENTIFICATION + * src/include/lib/binaryheap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BINARYHEAP_H +#define BINARYHEAP_H + +/* + * For a max-heap, the comparator must return <0 iff a < b, 0 iff a == b, + * and >0 iff a > b. For a min-heap, the conditions are reversed. + */ +typedef int (*binaryheap_comparator)(Datum a, Datum b, void* arg); + +/* + * binaryheap + * + * bh_size how many nodes are currently in "nodes" + * bh_space how many nodes can be stored in "nodes" + * bh_has_heap_property no unordered operations since last heap build + * bh_compare comparison function to define the heap property + * bh_arg user data for comparison function + * bh_nodes variable-length array of "space" nodes + */ +typedef struct binaryheap { + int bh_size; + int bh_space; + bool bh_has_heap_property; /* debugging cross-check */ + binaryheap_comparator bh_compare; + void* bh_arg; + Datum bh_nodes[FLEXIBLE_ARRAY_MEMBER]; +} binaryheap; + +extern binaryheap* binaryheap_allocate(int capacity, binaryheap_comparator compare, void* arg); +extern void binaryheap_reset(binaryheap* heap); +extern void binaryheap_free(binaryheap* heap); +extern void binaryheap_add_unordered(binaryheap* heap, Datum d); +extern void binaryheap_build(binaryheap* heap); +extern void binaryheap_add(binaryheap* heap, Datum d); +extern Datum binaryheap_first(binaryheap* heap); +extern Datum binaryheap_remove_first(binaryheap* heap); +extern void binaryheap_replace_first(binaryheap* heap, Datum d); + +#define binaryheap_empty(h) ((h)->bh_size == 0) + +#endif /* BINARYHEAP_H */ diff -uprN postgresql-hll-2.14_old/include/lib/bipartite_match.h postgresql-hll-2.14/include/lib/bipartite_match.h --- postgresql-hll-2.14_old/include/lib/bipartite_match.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/bipartite_match.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bipartite_match.h + * + * + * + * IDENTIFICATION + * src/include/lib/bipartite_match.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BIPARTITE_MATCH_H +#define BIPARTITE_MATCH_H + +/* + * Given a bipartite graph consisting of nodes U numbered 1..nU, nodes V + * numbered 1..nV, and an adjacency map of undirected edges in the form + * adjacency[u] = [k, v1, v2, v3, ... vk], we wish to find a "maximum + * cardinality matching", which is defined as follows: a matching is a subset + * of the original edges such that no node has more than one edge, and a + * matching has maximum cardinality if there exists no other matching with a + * greater number of edges. + * + * This matching has various applications in graph theory, but the motivating + * example here is Dilworth's theorem: a partially-ordered set can be divided + * into the minimum number of chains (i.e. subsets X where x1 < x2 < x3 ...) by + * a bipartite graph construction. This gives us a polynomial-time solution to + * the problem of planning a collection of grouping sets with the provably + * minimal number of sort operations. + */ +typedef struct BipartiteMatchState { + /* inputs: */ + int u_size; /* size of U */ + int v_size; /* size of V */ + short** adjacency; /* adjacency[u] = [k, v1,v2,v3,...,vk] */ + /* outputs: */ + int matching; /* number of edges in matching */ + short* pair_uv; /* pair_uv[u] -> v */ + short* pair_vu; /* pair_vu[v] -> u */ + /* private state for matching algorithm: */ + short* distance; /* distance[u] */ + short* queue; /* queue storage for breadth search */ +} BipartiteMatchState; + +extern BipartiteMatchState* BipartiteMatch(int u_size, int v_size, short** adjacency); + +extern void BipartiteMatchFree(BipartiteMatchState* state); + +#endif /* BIPARTITE_MATCH_H */ diff -uprN postgresql-hll-2.14_old/include/lib/circularqueue.h postgresql-hll-2.14/include/lib/circularqueue.h --- postgresql-hll-2.14_old/include/lib/circularqueue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/circularqueue.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,55 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * circularQueue.h + * + * + * + * IDENTIFICATION + * src/include/lib/Circularqueue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef Circular_QUEUE_H +#define Circular_QUEUE_H + +#include "postgres.h" + +class CircularQueue : public BaseObject { +public: + CircularQueue(int size, MemoryContext context); + ~CircularQueue(); + + void Init(); + void Destroy(); + bool LockFreeEnQueue(void* elem); /* append elem to the queue */ + + const uint32 GetStart() const; /* get the start */ + void SetStart(uint32 index); /* set the start */ + const uint32 GetEnd() const; /* get the end */ + const bool IsFull(); /* if the queue is full */ + uint32 GetLength(uint32 start, uint32 end); /* get the length of queue */ + void QueueTraverse(); /* traverse the queue */ + void* GetElem(int n); /* get nth element in the queue */ + MemoryContext GetContext(); /* get the memory context of this queue */ +public: + uint32 head; + volatile uint32 tail; + uint32 capacity; + void** queue; + MemoryContext cxt; +}; + +#endif /* Circular_QUEUE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/lib/dllist.h postgresql-hll-2.14/include/lib/dllist.h --- postgresql-hll-2.14_old/include/lib/dllist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/dllist.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,106 @@ +/* ------------------------------------------------------------------------- + * + * dllist.h + * simple doubly linked list primitives + * the elements of the list are void* so the lists can contain anything + * Dlelem can only be in one list at a time + * + * + * Here's a small example of how to use Dllists: + * + * Dllist *lst; + * Dlelem *elt; + * void *in_stuff; -- stuff to stick in the list + * void *out_stuff + * + * lst = DLNewList(); -- make a new dllist + * DLAddHead(lst, DLNewElem(in_stuff)); -- add a new element to the list + * with in_stuff as the value + * ... + * elt = DLGetHead(lst); -- retrieve the head element + * out_stuff = (void*)DLE_VAL(elt); -- get the stuff out + * DLRemove(elt); -- removes the element from its list + * DLFreeElem(elt); -- free the element since we don't + * use it anymore + * + * + * It is also possible to use Dllist objects that are embedded in larger + * structures instead of being separately malloc'd. To do this, use + * DLInitElem() to initialize a Dllist field within a larger object. + * Don't forget to DLRemove() each field from its list (if any) before + * freeing the larger object! + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/lib/dllist.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef DLLIST_H +#define DLLIST_H + +struct Dllist; +struct Dlelem; + +typedef struct Dlelem { + struct Dlelem* dle_next; /* next element */ + struct Dlelem* dle_prev; /* previous element */ + void* dle_val; /* value of the element */ + struct Dllist* dle_list; /* what list this element is in */ +} Dlelem; + +typedef struct Dllist { + Dlelem *dll_head; + Dlelem *dll_tail; + uint64 dll_len; +} Dllist; + +class DllistWithLock : public BaseObject { +public: + DllistWithLock(); + ~DllistWithLock(); + void Remove(Dlelem* e); + void AddHead(Dlelem* e); + void AddTail(Dlelem* e); + Dlelem* RemoveHead(); + bool IsEmpty(); + + inline uint64 GetLength() + { + return m_list.dll_len; + } + +private: + slock_t m_lock; + Dllist m_list; +}; + +extern Dllist* DLNewList(void); /* allocate and initialize a list header */ +extern void DLInitList(Dllist* list); /* init a header alloced by caller */ +extern void DLFreeList(Dllist* list); /* free up a list and all the nodes in + * it */ +extern Dlelem* DLNewElem(void* val); +extern void DLInitElem(Dlelem* e, void* val); +extern void DLFreeElem(Dlelem* e); +extern void DLRemove(Dlelem* e); /* removes node from list */ +extern void DLAddHead(Dllist* list, Dlelem* node); +extern void DLAddTail(Dllist* list, Dlelem* node); +extern Dlelem* DLRemHead(Dllist* list); /* remove and return the head */ +extern Dlelem* DLRemTail(Dllist* list); +extern void DLMoveToFront(Dlelem* e); /* move node to front of its list */ +extern uint64 DLListLength(Dllist* list); + +/* These are macros for speed */ +#define DLGetHead(list) ((list)->dll_head) +#define DLGetTail(list) ((list)->dll_tail) +#define DLIsNIL(list) ((list)->dll_head == NULL) +#define DLGetSucc(elem) ((elem)->dle_next) +#define DLGetPred(elem) ((elem)->dle_prev) +#define DLGetListHdr(elem) ((elem)->dle_list) + +#define DLE_VAL(elem) ((elem)->dle_val) + +#endif /* DLLIST_H */ diff -uprN postgresql-hll-2.14_old/include/lib/hyperloglog.h postgresql-hll-2.14/include/lib/hyperloglog.h --- postgresql-hll-2.14_old/include/lib/hyperloglog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/hyperloglog.h 2020-12-12 17:06:43.313348890 +0800 @@ -0,0 +1,71 @@ +/* --------------------------------------------------------------------------------------- + * + * hyperloglog.h + * A simple HyperLogLog cardinality estimator implementation + * + * Portions Copyright (c) 2014-2016, PostgreSQL Global Development Group + * + * Based on Hideaki Ohno's C++ implementation. The copyright terms of Ohno's + * original version (the MIT license) follow. + * + * IDENTIFICATION + * src/include/lib/hyperloglog.h + * + * --------------------------------------------------------------------------------------- + */ + +/* + * Copyright (c) 2013 Hideaki Ohno + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the 'Software'), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef HYPERLOGLOG_H +#define HYPERLOGLOG_H + +/* + * HyperLogLog is an approximate technique for computing the number of distinct + * entries in a set. Importantly, it does this by using a fixed amount of + * memory. See the 2007 paper "HyperLogLog: the analysis of a near-optimal + * cardinality estimation algorithm" for more. + * + * hyperLogLogState + * + * registerWidth register width, in bits ("k") + * nRegisters number of registers + * alphaMM alpha * m ^ 2 (see initHyperLogLog()) + * hashesArr array of hashes + * arrSize size of hashesArr + */ +typedef struct hyperLogLogState { + uint8 registerWidth; + Size nRegisters; + double alphaMM; + uint8* hashesArr; + Size arrSize; +} hyperLogLogState; + +extern void initHyperLogLog(hyperLogLogState* cState, uint8 bwidth); +extern void initHyperLogLogError(hyperLogLogState* cState, double error); +extern void addHyperLogLog(hyperLogLogState* cState, uint32 hash); +extern double estimateHyperLogLog(hyperLogLogState* cState); +extern void mergeHyperLogLog(hyperLogLogState* cState, const hyperLogLogState* oState); +extern void freeHyperLogLog(hyperLogLogState* cState); + +#endif /* HYPERLOGLOG_H */ diff -uprN postgresql-hll-2.14_old/include/lib/ilist.h postgresql-hll-2.14/include/lib/ilist.h --- postgresql-hll-2.14_old/include/lib/ilist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/ilist.h 2020-12-12 17:06:43.314348903 +0800 @@ -0,0 +1,703 @@ +/* --------------------------------------------------------------------------------------- + * + * ilist.h + * integrated/inline doubly- and singly-linked lists + * + * + * IDENTIFICATION + * src/include/lib/ilist.h + * + * NOTE + * These list types are useful when there are only a predetermined set of + * lists that an object could be in. List links are embedded directly into + * the objects, and thus no extra memory management overhead is required. + * (Of course, if only a small proportion of existing objects are in a list, + * the link fields in the remainder would be wasted space. But usually, + * it saves space to not have separately-allocated list nodes.) + * + * None of the functions here allocate any memory; they just manipulate + * externally managed memory. The APIs for singly and doubly linked lists + * are identical as far as capabilities of both allow. + * + * Each list has a list header, which exists even when the list is empty. + * An empty singly-linked list has a NULL pointer in its header. + * There are two kinds of empty doubly linked lists: those that have been + * initialized to NULL, and those that have been initialized to circularity. + * (If a dlist is modified and then all its elements are deleted, it will be + * in the circular state.) We prefer circular dlists because there are some + * operations that can be done without branches (and thus faster) on lists + * that use circular representation. However, it is often convenient to + * initialize list headers to zeroes rather than setting them up with an + * explicit initialization function, so we also allow the other case. + * + * EXAMPLES + * + * Here's a simple example demonstrating how this can be used. Let's assume + * we want to store information about the tables contained in a database. + * + * #include "lib/ilist.h" + * + * // Define struct for the databases including a list header that will be + * // used to access the nodes in the table list later on. + * typedef struct my_database + * { + * char *datname; + * dlist_head tables; + * // ... + * } my_database; + * + * // Define struct for the tables. Note the list_node element which stores + * // prev/next list links. The list_node element need not be first. + * typedef struct my_table + * { + * char *tablename; + * dlist_node list_node; + * perm_t permissions; + * // ... + * } my_table; + * + * // create a database + * my_database *db = create_database(); + * + * // and add a few tables to its table list + * dlist_push_head(&db->tables, &create_table(db, "a")->list_node); + * ... + * dlist_push_head(&db->tables, &create_table(db, "b")->list_node); + * + * + * To iterate over the table list, we allocate an iterator variable and use + * a specialized looping construct. Inside a dlist_foreach, the iterator's + * 'cur' field can be used to access the current element. iter.cur points to + * a 'dlist_node', but most of the time what we want is the actual table + * information; dlist_container() gives us that, like so: + * + * dlist_iter iter; + * dlist_foreach(iter, &db->tables) + * { + * my_table *tbl = dlist_container(my_table, list_node, iter.cur); + * printf("we have a table: %s in database %s\n", + * tbl->tablename, db->datname); + * } + * + * + * While a simple iteration is useful, we sometimes also want to manipulate + * the list while iterating. There is a different iterator element and looping + * construct for that. Suppose we want to delete tables that meet a certain + * criterion: + * + * dlist_mutable_iter miter; + * dlist_foreach_modify(miter, &db->tables) + * { + * my_table *tbl = dlist_container(my_table, list_node, miter.cur); + * + * if (!tbl->to_be_deleted) + * continue; // don't touch this one + * + * // unlink the current table from the linked list + * dlist_delete(miter.cur); + * // as these lists never manage memory, we can still access the table + * // after it's been unlinked + * drop_table(db, tbl); + * } + * + * + * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ILIST_H +#define ILIST_H + +/* + * Enable for extra debugging. This is rather expensive, so it's not enabled by + * default even when USE_ASSERT_CHECKING. + */ + +/* + * Node of a doubly linked list. + * + * Embed this in structs that need to be part of a doubly linked list. + */ +struct dlist_node { + dlist_node* prev; + dlist_node* next; +}; +typedef struct dlist_node dlist_node; +/* + * Head of a doubly linked list. + * + * Non-empty lists are internally circularly linked. Circular lists have the + * advantage of not needing any branches in the most common list manipulations. + * An empty list can also be represented as a pair of NULL pointers, making + * initialization easier. + */ +typedef struct dlist_head { + /* + * head.next either points to the first element of the list; to &head if + * it's a circular empty list; or to NULL if empty and not circular. + * + * head.prev either points to the last element of the list; to &head if + * it's a circular empty list; or to NULL if empty and not circular. + */ + dlist_node head; +} dlist_head; + +/* + * Doubly linked list iterator. + * + * Used as state in dlist_foreach() and dlist_reverse_foreach(). To get the + * current element of the iteration use the 'cur' member. + * + * Iterations using this are *not* allowed to change the list while iterating! + * + * NB: We use an extra "end" field here to avoid multiple evaluations of + * arguments in the dlist_foreach() macro. + */ +typedef struct dlist_iter { + dlist_node* cur; /* current element */ + dlist_node* end; /* last node we'll iterate to */ +} dlist_iter; + +/* + * Doubly linked list iterator allowing some modifications while iterating. + * + * Used as state in dlist_foreach_modify(). To get the current element of the + * iteration use the 'cur' member. + * + * Iterations using this are only allowed to change the list at the current + * point of iteration. It is fine to delete the current node, but it is *not* + * fine to insert or delete adjacent nodes. + * + * NB: We need a separate type for mutable iterations so that we can store + * the 'next' node of the current node in case it gets deleted or modified. + */ +typedef struct dlist_mutable_iter { + dlist_node* cur; /* current element */ + dlist_node* next; /* next node we'll iterate to */ + dlist_node* end; /* last node we'll iterate to */ +} dlist_mutable_iter; + +/* + * Node of a singly linked list. + * + * Embed this in structs that need to be part of a singly linked list. + */ +typedef struct slist_node slist_node; +struct slist_node { + slist_node* next; +}; + +/* + * Head of a singly linked list. + * + * Singly linked lists are not circularly linked, in contrast to doubly linked + * lists; we just set head.next to NULL if empty. This doesn't incur any + * additional branches in the usual manipulations. + */ +typedef struct slist_head { + slist_node head; +} slist_head; + +/* + * Singly linked list iterator. + * + * Used as state in slist_foreach(). To get the current element of the + * iteration use the 'cur' member. + * + * It's allowed to modify the list while iterating, with the exception of + * deleting the iterator's current node; deletion of that node requires + * care if the iteration is to be continued afterward. (Doing so and also + * deleting or inserting adjacent list elements might misbehave; also, if + * the user frees the current node's storage, continuing the iteration is + * not safe.) + * + * NB: this wouldn't really need to be an extra struct, we could use an + * slist_node * directly. We prefer a separate type for consistency. + */ +typedef struct slist_iter { + slist_node* cur; +} slist_iter; + +/* + * Singly linked list iterator allowing some modifications while iterating. + * + * Used as state in slist_foreach_modify(). To get the current element of the + * iteration use the 'cur' member. + * + * The only list modification allowed while iterating is to remove the current + * node via slist_delete_current() (*not* slist_delete()). Insertion or + * deletion of nodes adjacent to the current node would misbehave. + */ +typedef struct slist_mutable_iter { + slist_node* cur; /* current element */ + slist_node* next; /* next node we'll iterate to */ + slist_node* prev; /* prev node, for deletions */ +} slist_mutable_iter; + +/* Static initializers */ +#define DLIST_STATIC_INIT(name) \ + { \ + { \ + &(name).head, &(name).head \ + } \ + } +#define SLIST_STATIC_INIT(name) \ + { \ + { \ + NULL \ + } \ + } + +/* Prototypes for functions too big to be inline */ + +/* Caution: this is O(n); consider using slist_delete_current() instead */ +extern void slist_delete(slist_head* head, slist_node* node); + +#ifdef ILIST_DEBUG +extern void dlist_check(dlist_head* head); +extern void slist_check(slist_head* head); +#else +/* + * These seemingly useless casts to void are here to keep the compiler quiet + * about the argument being unused in many functions in a non-debug compile, + * in which functions the only point of passing the list head pointer is to be + * able to run these checks. + */ +#define dlist_check(head) ((void)(head)) +#define slist_check(head) ((void)(head)) +#endif /* ILIST_DEBUG */ + +/* doubly linked list implementation */ + +/* init a doubly linked list node */ +static inline void DListNodeInit(dlist_node* node) +{ + node->next = node->prev = NULL; +} + +/* + * Initialize a doubly linked list. + * Previous state will be thrown away without any cleanup. + */ +static inline void dlist_init(dlist_head* head) +{ + head->head.next = head->head.prev = &head->head; +} + +/* + * Is the list empty? + * + * An empty list has either its first 'next' pointer set to NULL, or to itself. + */ +static inline bool dlist_is_empty(dlist_head* head) +{ + dlist_check(head); + + return head->head.next == NULL || head->head.next == &(head->head); +} + +/* + * Insert a node at the beginning of the list. + */ +static inline void dlist_push_head(dlist_head* head, dlist_node* node) +{ + if (head->head.next == NULL) /* convert NULL header to circular */ + dlist_init(head); + + node->next = head->head.next; + node->prev = &head->head; + node->next->prev = node; + head->head.next = node; + + dlist_check(head); +} + +/* + * Insert a node at the end of the list. + */ +static inline void dlist_push_tail(dlist_head* head, dlist_node* node) +{ + if (head->head.next == NULL) /* convert NULL header to circular */ + dlist_init(head); + + node->next = &head->head; + node->prev = head->head.prev; + node->prev->next = node; + head->head.prev = node; + + dlist_check(head); +} + +/* + * Insert a node after another *in the same list* + */ +static inline void dlist_insert_after(dlist_node* after, dlist_node* node) +{ + node->prev = after; + node->next = after->next; + after->next = node; + node->next->prev = node; +} + +/* + * Insert a node before another *in the same list* + */ +static inline void dlist_insert_before(dlist_node* before, dlist_node* node) +{ + node->prev = before->prev; + node->next = before; + before->prev = node; + node->prev->next = node; +} + +/* + * Delete 'node' from its list (it must be in one). + */ +static inline void dlist_delete(dlist_node* node) +{ + node->prev->next = node->next; + node->next->prev = node->prev; +} + +/* + * Remove and return the first node from a list (there must be one). + */ +static inline dlist_node* dlist_pop_head_node(dlist_head* head) +{ + dlist_node* node = NULL; + + Assert(!dlist_is_empty(head)); + node = head->head.next; + dlist_delete(node); + return node; +} + +/* + * Move element from its current position in the list to the head position in + * the same list. + * + * Undefined behaviour if 'node' is not already part of the list. + */ +static inline void dlist_move_head(dlist_head* head, dlist_node* node) +{ + /* fast path if it's already at the head */ + if (head->head.next == node) + return; + + dlist_delete(node); + dlist_push_head(head, node); + + dlist_check(head); +} + +/* + * Check whether 'node' has a following node. + * Caution: unreliable if 'node' is not in the list. + */ +static inline bool dlist_has_next(dlist_head* head, dlist_node* node) +{ + return node->next != &head->head; +} + +/* + * Check whether 'node' has a preceding node. + * Caution: unreliable if 'node' is not in the list. + */ +static inline bool dlist_has_prev(dlist_head* head, dlist_node* node) +{ + return node->prev != &head->head; +} + +/* + * Return the next node in the list (there must be one). + */ +static inline dlist_node* dlist_next_node(dlist_head* head, dlist_node* node) +{ + Assert(dlist_has_next(head, node)); + return node->next; +} + +/* + * Return previous node in the list (there must be one). + */ +static inline dlist_node* dlist_prev_node(dlist_head* head, dlist_node* node) +{ + Assert(dlist_has_prev(head, node)); + return node->prev; +} + +/* internal support function to get address of head element's struct */ +static inline void* dlist_head_element_off(dlist_head* head, size_t off) +{ + Assert(!dlist_is_empty(head)); + return (char*)head->head.next - off; +} + +/* + * Return the first node in the list (there must be one). + */ +static inline dlist_node* dlist_head_node(dlist_head* head) +{ + return (dlist_node*)dlist_head_element_off(head, 0); +} + +/* internal support function to get address of tail element's struct */ +static inline void* dlist_tail_element_off(dlist_head* head, size_t off) +{ + Assert(!dlist_is_empty(head)); + return (char*)head->head.prev - off; +} + +/* + * Return the last node in the list (there must be one). + */ +static inline dlist_node* dlist_tail_node(dlist_head* head) +{ + return (dlist_node*)dlist_tail_element_off(head, 0); +} + +/* + * Return the containing struct of 'type' where 'membername' is the dlist_node + * pointed at by 'ptr'. + * + * This is used to convert a dlist_node * back to its containing struct. + */ +#define dlist_container(type, membername, ptr) \ + (AssertVariableIsOfTypeMacro(ptr, dlist_node*), \ + AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + ((type*)((char*)(ptr)-offsetof(type, membername)))) + +/* + * Return the address of the first element in the list. + * + * The list must not be empty. + */ +#define dlist_head_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + (type*)dlist_head_element_off(lhead, offsetof(type, membername))) + +/* + * Return the address of the last element in the list. + * + * The list must not be empty. + */ +#define dlist_tail_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, dlist_node), \ + ((type*)dlist_tail_element_off(lhead, offsetof(type, membername)))) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * It is *not* allowed to manipulate the list during iteration. + */ +#define dlist_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->next ? (iter).end->next : (iter).end; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).cur->next) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * Iterations using this are only allowed to change the list at the current + * point of iteration. It is fine to delete the current node, but it is *not* + * fine to insert or delete adjacent nodes. + */ +#define dlist_foreach_modify(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_mutable_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->next ? (iter).end->next : (iter).end, \ + (iter).next = (iter).cur->next; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).next, (iter).next = (iter).cur->next) + +/* + * Iterate through the list in reverse order. + * + * It is *not* allowed to manipulate the list during iteration. + */ +#define dlist_reverse_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, dlist_iter), \ + AssertVariableIsOfTypeMacro(lhead, dlist_head*), \ + (iter).end = &(lhead)->head, \ + (iter).cur = (iter).end->prev ? (iter).end->prev : (iter).end; \ + (iter).cur != (iter).end; \ + (iter).cur = (iter).cur->prev) + +/* singly linked list implementation */ + +/* + * Initialize a singly linked list. + * Previous state will be thrown away without any cleanup. + */ +static inline void slist_init(slist_head* head) +{ + head->head.next = NULL; +} + +/* + * Is the list empty? + */ +static inline bool slist_is_empty(slist_head* head) +{ + slist_check(head); + + return head->head.next == NULL; +} + +/* + * Insert a node at the beginning of the list. + */ +static inline void slist_push_head(slist_head* head, slist_node* node) +{ + node->next = head->head.next; + head->head.next = node; + + slist_check(head); +} + +/* + * Insert a node after another *in the same list* + */ +static inline void slist_insert_after(slist_node* after, slist_node* node) +{ + node->next = after->next; + after->next = node; +} + +/* + * Remove and return the first node from a list (there must be one). + */ +static inline slist_node* slist_pop_head_node(slist_head* head) +{ + slist_node* node = NULL; + + Assert(!slist_is_empty(head)); + node = head->head.next; + head->head.next = node->next; + slist_check(head); + return node; +} + +/* + * Check whether 'node' has a following node. + */ +static inline bool slist_has_next(slist_head* head, slist_node* node) +{ + slist_check(head); + + return node->next != NULL; +} + +/* + * Return the next node in the list (there must be one). + */ +static inline slist_node* slist_next_node(slist_head* head, slist_node* node) +{ + Assert(slist_has_next(head, node)); + return node->next; +} + +/* internal support function to get address of head element's struct */ +static inline void* slist_head_element_off(slist_head* head, size_t off) +{ + Assert(!slist_is_empty(head)); + return (char*)head->head.next - off; +} + +/* + * Return the first node in the list (there must be one). + */ +static inline slist_node* slist_head_node(slist_head* head) +{ + return (slist_node*)slist_head_element_off(head, 0); +} + +/* + * Delete the list element the iterator currently points to. + * + * Caution: this modifies iter->cur, so don't use that again in the current + * loop iteration. + */ +static inline void slist_delete_current(slist_mutable_iter* iter) +{ + /* + * Update previous element's forward link. If the iteration is at the + * first list element, iter->prev will point to the list header's "head" + * field, so we don't need a special case for that. + */ + iter->prev->next = iter->next; + + /* + * Reset cur to prev, so that prev will continue to point to the prior + * valid list element after slist_foreach_modify() advances to the next. + */ + iter->cur = iter->prev; +} + +/* + * Return the containing struct of 'type' where 'membername' is the slist_node + * pointed at by 'ptr'. + * + * This is used to convert a slist_node * back to its containing struct. + */ +#define slist_container(type, membername, ptr) \ + (AssertVariableIsOfTypeMacro(ptr, slist_node*), \ + AssertVariableIsOfTypeMacro(((type*)NULL)->membername, slist_node), \ + ((type*)((char*)(ptr)-offsetof(type, membername)))) + +/* + * Return the address of the first element in the list. + * + * The list must not be empty. + */ +#define slist_head_element(type, membername, lhead) \ + (AssertVariableIsOfTypeMacro(((type*)NULL)->membername, slist_node), \ + (type*)slist_head_element_off(lhead, offsetof(type, membername))) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * It's allowed to modify the list while iterating, with the exception of + * deleting the iterator's current node; deletion of that node requires + * care if the iteration is to be continued afterward. (Doing so and also + * deleting or inserting adjacent list elements might misbehave; also, if + * the user frees the current node's storage, continuing the iteration is + * not safe.) + */ +#define slist_foreach(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, slist_iter), \ + AssertVariableIsOfTypeMacro(lhead, slist_head*), \ + (iter).cur = (lhead)->head.next; \ + (iter).cur != NULL; \ + (iter).cur = (iter).cur->next) + +/* + * Iterate through the list pointed at by 'lhead' storing the state in 'iter'. + * + * Access the current element with iter.cur. + * + * The only list modification allowed while iterating is to remove the current + * node via slist_delete_current() (*not* slist_delete()). Insertion or + * deletion of nodes adjacent to the current node would misbehave. + */ +#define slist_foreach_modify(iter, lhead) \ + for (AssertVariableIsOfTypeMacro(iter, slist_mutable_iter), \ + AssertVariableIsOfTypeMacro(lhead, slist_head*), \ + (iter).prev = &(lhead)->head, \ + (iter).cur = (iter).prev->next, \ + (iter).next = (iter).cur ? (iter).cur->next : NULL; \ + (iter).cur != NULL; \ + (iter).prev = (iter).cur, (iter).cur = (iter).next, (iter).next = (iter).next ? (iter).next->next : NULL) + +#endif /* ILIST_H */ diff -uprN postgresql-hll-2.14_old/include/lib/lrucache.h postgresql-hll-2.14/include/lib/lrucache.h --- postgresql-hll-2.14_old/include/lib/lrucache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/lrucache.h 2020-12-12 17:06:43.314348903 +0800 @@ -0,0 +1,147 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * lrucache.h + * + * + * + * IDENTIFICATION + * src/include/lib/lrucache.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LRUCACHE_INCLUDE +#define LRUCACHE_INCLUDE + +#include "postgres.h" + +typedef bool (*CmpFuncType)(void*, void*); +void CleanHotkeyInfo(struct HotkeyInfo* key); + +/* struct with ref count to help release key info */ +struct RefNode : public BaseObject { + void* key; + volatile uint64 refcount; + RefNode() + { + key = NULL; + refcount = 1; + } + ~RefNode() + {} + void Destroy() + { + if (key != NULL) { + CleanHotkeyInfo((HotkeyInfo*)key); + key = NULL; + } + refcount = 0; + } +}; + +/* basic node for lru cache operation */ +struct DllNode : public BaseObject { + RefNode* node; + volatile uint64 value; + double weight; + DllNode* next; + DllNode* prev; + volatile uint32 state; // thread that occupies 0 can operate this Node + MemoryContext cxt; + DllNode(MemoryContext context) + { + value = 0; + weight = 0; + next = NULL; + prev = NULL; + state = 0; + cxt = context; + } + ~DllNode() + {} + void Init() + { + node = New(cxt) RefNode(); + } + void Destroy() + { + if (node != NULL) { + node->Destroy(); + node = NULL; + } + value = 0; + weight = 0; + next = NULL; + prev = NULL; + state = 0; + } +}; + +class LRUCache : public BaseObject { +public: + LRUCache(int size, MemoryContext context); + ~LRUCache(); + + void Init(); + void Destroy(); + void Put(void* node); + bool Contain(void* node, CmpFuncType type); + void AddToTail(RefNode* x); + void Remove(DllNode* n); + void MoveToTail(DllNode* n); + void ReLocate(DllNode* x); + void Clean(); + void DeleteHotkeysInTAB(Oid t_oid); + void DeleteHotkeysInDB(Oid db_oid); + void DestroyNode(DllNode* node); + int GetLength() + { + return len; + } + DllNode* GetFirstElem() + { + return head->next; + } + DllNode* GetLastElem() + { + return tail->prev; + } + DllNode** GetArray() + { + return array; + } + bool IsFull() + { + return len == capacity; + } + bool IsEmpty() + { + return len == 0; + } + pthread_rwlock_t* GetLock() + { + return lock; + } + +private: + int len; + int capacity; + MemoryContext cxt; + DllNode* head; + DllNode* tail; + DllNode** array; + pthread_rwlock_t* lock; +}; +#endif /* LRUCACHE_INCLUDE */ diff -uprN postgresql-hll-2.14_old/include/lib/stringinfo.h postgresql-hll-2.14/include/lib/stringinfo.h --- postgresql-hll-2.14_old/include/lib/stringinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/lib/stringinfo.h 2020-12-12 17:06:43.314348903 +0800 @@ -0,0 +1,159 @@ +/* ------------------------------------------------------------------------- + * + * stringinfo.h + * Declarations/definitions for "StringInfo" functions. + * + * StringInfo provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with palloc(). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/lib/stringinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STRINGINFO_H +#define STRINGINFO_H + +/* ------------------------- + * StringInfoData holds information about an extensible string. + * data is the current buffer for the string (allocated with palloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * cursor is initialized to zero by makeStringInfo or initStringInfo, + * but is not otherwise touched by the stringinfo.c routines. + * Some routines use it to scan through a StringInfo. + * ------------------------- + */ +typedef struct StringInfoData { + char* data; + int len; + int maxlen; + int cursor; +} StringInfoData; + +typedef StringInfoData* StringInfo; + +/* ------------------------ + * There are two ways to create a StringInfo object initially: + * + * StringInfo stringptr = makeStringInfo(); + * Both the StringInfoData and the data buffer are palloc'd. + * + * StringInfoData string; + * initStringInfo(&string); + * The data buffer is palloc'd but the StringInfoData is just local. + * This is the easiest approach for a StringInfo object that will + * only live as long as the current routine. + * + * To destroy a StringInfo, pfree() the data buffer, and then pfree() the + * StringInfoData if it was palloc'd. There's no special support for this. + * + * NOTE: some routines build up a string using StringInfo, and then + * release the StringInfoData but return the data string itself to their + * caller. At that point the data string looks like a plain palloc'd + * string. + * ------------------------- + */ + +/* ------------------------ + * makeStringInfo + * Create an empty 'StringInfoData' & return a pointer to it. + */ +extern StringInfo makeStringInfo(void); + +/* ------------------------ + * initStringInfo + * Initialize a StringInfoData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initStringInfo(StringInfo str); + +/* ------------------------ + * resetStringInfo + * Clears the current content of the StringInfo, if any. The + * StringInfo remains valid. + */ +extern void resetStringInfo(StringInfo str); + +/* ------------------------ + * appendStringInfo + * Format text data under the control of fmt (an sprintf-style format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendStringInfo(StringInfo str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/* ------------------------ + * appendStringInfoVA + * Attempt to format text data under the control of fmt (an sprintf-style + * format string) and append it to whatever is already in str. If successful + * return true; if not (because there's not enough space), return false + * without modifying str. Typically the caller would enlarge str and retry + * on false return --- see appendStringInfo for standard usage pattern. + */ +extern bool appendStringInfoVA(StringInfo str, const char* fmt, va_list args) + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0))); + +/* ------------------------ + * appendStringInfoString + * Append a null-terminated string to str. + * Like appendStringInfo(str, "%s", s) but faster. + */ +extern void appendStringInfoString(StringInfo str, const char* s); + +/* ------------------------ + * appendStringInfoChar + * Append a single byte to str. + * Like appendStringInfo(str, "%c", ch) but much faster. + */ +extern void appendStringInfoChar(StringInfo str, char ch); + +/* ------------------------ + * appendStringInfoCharMacro + * As above, but a macro for even more speed where it matters. + * Caution: str argument will be evaluated multiple times. + */ +#define appendStringInfoCharMacro(str, ch) \ + (((str)->len + 1 >= (str)->maxlen) ? appendStringInfoChar(str, ch) \ + : (void)((str)->data[(str)->len] = (ch), (str)->data[++(str)->len] = '\0')) + +/* ------------------------ + * appendStringInfoSpaces + * Append a given number of spaces to str. + */ +extern void appendStringInfoSpaces(StringInfo str, int count); + +/* ------------------------ + * appendBinaryStringInfo + * Append arbitrary binary data to a StringInfo, allocating more space + * if necessary. + */ +extern void appendBinaryStringInfo(StringInfo str, const char* data, int datalen); + +extern void copyStringInfo(StringInfo to, StringInfo from); + +/* ------------------------ + * enlargeBuffer + * Make sure a buffer can hold at least 'needed' more bytes. + */ +template +void enlargeBuffer(_in_ int needed, _in_ int len, __inout T* maxlen, __inout char** data); + +/* ------------------------ + * enlargeStringInfo + * Make sure a StringInfo's buffer can hold at least 'needed' more bytes. + */ +extern void enlargeStringInfo(StringInfo str, int needed); + +#endif /* STRINGINFO_H */ diff -uprN postgresql-hll-2.14_old/include/libcomm/libcomm.h postgresql-hll-2.14/include/libcomm/libcomm.h --- postgresql-hll-2.14_old/include/libcomm/libcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libcomm/libcomm.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,559 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libcomm.h + * + * + * IDENTIFICATION + * src/include/libcomm/libcomm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _GS_LIBCOMM_H_ +#define _GS_LIBCOMM_H_ + +#include +#include +#ifndef WIN32 +#include +#else +#include "pthread-win32.h" +#endif +#include +#include "c.h" + +#define ECOMMTCPARGSINVAL 1001 +#define ECOMMTCPMEMALLOC 1002 +#define ECOMMTCPCVINIT 1003 +#define ECOMMTCPCVDESTROY 1004 +#define ECOMMTCPLOCKINIT 1005 +#define ECOMMTCPLOCKDESTROY 1006 +#define ECOMMTCPNODEIDFD 1007 +#define ECOMMTCPNODEIDXTCPFD 1008 +#define ECOMMTCPSETSTREAMIDX 1009 +#define ECOMMTCPBUFFQSIZE 1010 +#define ECOMMTCPQUTOASZIE 1011 +#define ECOMMTCPSEMINIT 1012 +#define ECOMMTCPSEMPOST 1013 +#define ECOMMTCPSEMWAIT 1014 +#define ECOMMTCPEPOLLINIT 1015 +#define ECOMMTCPEPOLLHNDL 1016 +#define ECOMMTCPSCTPADRINIT 1017 +#define ECOMMTCPSCTPLISTEN 1018 +#define ECOMMTCPCMAILBOXINIT 1019 +#define ECOMMTCPNODEIDXSCTPPORT 1020 +#define ECOMMTCPSTREAMIDX 1021 +#define ECOMMTCPTCPFD 1022 +#define ECOMMTCPEPOLLEVNT 1023 +#define ECOMMTCPCTRLMSG 1024 +#define ECOMMTCPCTRLMSGWR 1025 +#define ECOMMTCPCTRLMSGRD 1026 +#define ECOMMTCPSTREAMIDXINVAL 1027 +#define ECOMMTCPINVALNODEID 1028 +#define ECOMMTCPCTRLMSGSIZE 1029 +#define ECOMMTCPCVSIGNAL 1030 +#define ECOMMTCPEPOLLLST 1031 +#define ECOMMTCPCTRLCONN 1032 +#define ECOMMTCPSND 1033 +#define ECOMMTCPEPOLLCLOSE 1034 +#define ECOMMTCPEPOLLTIMEOUT 1035 +#define ECOMMTCPHASHENTRYDEL 1036 +#define ECOMMTCPTHREADSTOP 1037 +#define ECOMMTCPMAILBOXCLOSE 1038 +#define ECOMMTCPSTREAMSTATE 1039 +#define ECOMMTCPSCTPFDINVAL 1040 +#define ECOMMTCPNODATA 1041 +#define ECOMMTCPTHREADSTART 1042 +#define ECOMMTCPHASHENTRYADD 1043 +#define ECOMMTCPBUILDSCTPASSOC 1044 +#define ECOMMTCPWRONGSTREAMKEY 1045 +#define ECOMMTCPRELEASEMEM 1046 +#define ECOMMTCPTCPDISCONNECT 1047 +#define ECOMMTCPDISCONNECT 1048 +#define ECOMMTCPREMOETECLOSE 1049 +#define ECOMMTCPAPPCLOSE 1050 +#define ECOMMTCPLOCALCLOSEPOLL 1051 +#define ECOMMTCPPEERCLOSEPOLL 1052 +#define ECOMMTCPCONNFAIL 1054 +#define ECOMMTCPSTREAMCONNFAIL 1055 +#define ECOMMTCPREJECTSTREAM 1056 +#define ECOMMTCPCONNTIMEOUT 1057 +#define ECOMMTCPWAITQUOTAFAIL 1058 +#define ECOMMTCPWAITPOLLERROR 1059 +#define ECOMMTCPPEERCHANGED 1060 +#define ECOMMTCPGSSAUTHFAIL 1061 +#define ECOMMTCPSENDTIMEOUT 1062 +#define ECOMMTCPNOTINTERNALIP 1063 + +// Structure definitions. +// Stream key is using to associate producers and consumers +// +#define HOST_ADDRSTRLEN INET6_ADDRSTRLEN +#define HOST_LEN_OF_HTAB 64 +#define NAMEDATALEN 64 +#define MSG_TIME_LEN 30 +#define MAX_DN_NODE_NUM 8192 +#define MAX_CN_NODE_NUM 1024 +#define MAX_CN_DN_NODE_NUM (MAX_DN_NODE_NUM + MAX_CN_NODE_NUM) //(MaxCoords+MaxDataNodes) +#define MIN_CN_DN_NODE_NUM (1 + 1) //(1 CN + 1 DN) + +#define SEC_TO_MICRO_SEC 1000 + +typedef enum { + LIBCOMM_NONE, + LIBCOMM_SEND_CTRL, + LIBCOMM_RECV_CTRL, + LIBCOMM_RECV_LOOP, + LIBCOMM_AUX +} LibcommThreadTypeDef; + +/* send and recv message type */ +typedef enum +{ + SEND_SOME = 0, + SECURE_READ, + SECURE_WRITE, + READ_DATA, + READ_DATA_FROM_LOGIC +} CommMsgOper; + +typedef enum +{ + POSTMASTER = 0, + GS_SEND_flow, + GS_RECV_FLOW, + GS_RECV_LOOP, +} CommThreadUsed; + +typedef struct CommStreamKey { + uint64 queryId; /* Plan id of current query. */ + uint32 planNodeId; /* Plan node id of stream node. */ + uint32 producerSmpId; /* Smp id for producer. */ + uint32 consumerSmpId; /* Smp id for consumer. */ +} TcpStreamKey; + +// struct of libcomm logic addr +// idx gives the node idx of backend +// sid gives the logic conn idx with specific node +// ver gives the version of this logic addr, once it is closed ver++ +// type is GSOCK_TYPE +typedef struct { + uint16 idx; + uint16 sid; + uint16 ver; + uint16 type; +} gsocket; + +struct StreamConnInfo; + +// statistic structure +// +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_id; + const char* stream_state; + int tcp_sock; + uint64 query_id; + TcpStreamKey stream_key; + long quota_size; + unsigned long buff_usize; + long bytes; + long time; + long speed; + unsigned long local_thread_id; + unsigned long peer_thread_id; +} CommRecvStreamStatus; + +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_id; + const char* stream_state; + int tcp_sock; + int packet_count; + int quota_count; + uint64 query_id; + TcpStreamKey stream_key; + long bytes; + long time; + long speed; + long quota_size; + long wait_quota; + long send_overhead; + unsigned long local_thread_id; + unsigned long peer_thread_id; +} CommSendStreamStatus; + +typedef struct { + long recv_speed; + long send_speed; + int recv_count_speed; + int send_count_speed; + long buffer; + long mem_libcomm; + long mem_libpq; + int postmaster; + int gs_sender_flow; + int gs_receiver_flow; + int gs_receiver_loop; + int stream_conn_num; +} CommStat; + + +typedef struct { + char remote_node[NAMEDATALEN]; + char remote_host[HOST_ADDRSTRLEN]; + int idx; + int stream_num; + uint32 min_delay; + uint32 dev_delay; + uint32 max_delay; +} CommDelayInfo; + +// sctp address infomation +// +typedef struct libcommaddrinfo { + char* host; // host ip + char nodename[NAMEDATALEN]; // datanode name + int ctrl_port; // control tcp listening port + int listen_port; // listening port + int status; // status of the address info, + // -1:closed, 0:need send, 1:send finish + int nodeIdx; // datanode index, like PGXCNodeId + CommStreamKey streamKey; // stream key, use plan id,plan node id, producer smp id and consumer smp id + unsigned int qid; // query index + bool parallel_send_mode; // this connection use parallel mode to send + int addr_list_size; // how many node in addr info list, only the head node set it + libcommaddrinfo* addr_list_next; // point to next addr info node, libcomm use it to build addr info list + gsocket gs_sock; // libcomm logic addr +} libcomm_addrinfo; + +/* cn and dn send and recv message log */ +typedef struct MessageIpcLog +{ + char type; /* the incomplete message type parsed last time */ + int msg_cursor; + int msg_len; /* When the message parsed last time is incomplete, record the true length of the message */ + + int len_cursor; /* When msglen is parsed to be less than 4 bytes, the received bytes count are recorded */ + uint32 len_cache; + + /* For consecutive parses to the same message, record the msgtype, length, and last parsed time and same message count. */ + char last_msg_type; /* the type of the previous message */ + int last_msg_len; /* the message of the previous message */ + int last_msg_count; /* same message count */ + char last_msg_time[MSG_TIME_LEN]; // the time of the previous message +}MessageIpcLog; + +typedef struct MessageCommLog +{ + MessageIpcLog recv_ipc_log; + MessageIpcLog send_ipc_log; +}MessageCommLog; + +typedef enum { + GSOCK_INVALID, + GSOCK_PRODUCER, + GSOCK_CONSUMER, + GSOCK_DAUL_CHANNEL, +} GSOCK_TYPE; + +extern gsocket gs_invalid_gsock; +#define GS_INVALID_GSOCK gs_invalid_gsock + +void mc_elog(int elevel, const char* fmt, ...) __attribute__((format(printf, 2, 3))); + +#define LIBCOMM_DEBUG_LOG(format, ...) \ + do { \ + ; \ + } while (0) + +// the role of current node +// +typedef enum { ROLE_PRODUCER, ROLE_CONSUMER, ROLE_MAX_TYPE } SctpNodeRole; + +// the connection state of IP+PORT +// +typedef enum { CONNSTATEFAIL, CONNSTATECONNECTING, CONNSTATESUCCEED } ConnectionState; + +// the channel type +// +typedef enum { DATA_CHANNEL, CTRL_CHANNEL } ChannelType; + +typedef bool (*wakeup_hook_type)(TcpStreamKey key, StreamConnInfo connInfo); + +// Set basic initialization information for communication, +// calling by each datanode for initializing the communication layer +// +extern int gs_set_basic_info(const char* local_host, // local ip of the datanode, it can be used "localhost" for simple + const char* local_node_name, // local node name of the datanode, like PGXCNodeName + int node_num, // total number of datanodes, maximum value is 1024, it could be set in postgresql.conf with + // parameter name comm_max_datanode + char* sock_path); // unix domain path + +// Connect to destination datanode, and get the sctp stream index for sending +// called by Sender +// +// return: stream index +// +extern int gs_connect(libcommaddrinfo** sctp_addrinfo, // destination address + int addr_num, // connection number + int timeout // timeout threshold, default is 10 min +); + +// Regist call back function of receiver for waking up Consumer in executor, +// if a sender connect successfully to receiver, wake up the consumer once +// +extern void gs_connect_regist_callback(wakeup_hook_type wakeup_callback); + +// Send message through sctp channel using a sctp stream +// called by Sender +// +// return: transmitted data size +// +extern int gs_send(gsocket* gs_sock, // destination address + char* message, // message to send + int m_len, // message length + int time_out, // timeout threshold, default is -1 + bool block_mode // is wait quota +); + +extern int gs_broadcast_send(struct libcommaddrinfo* sctp_addrinfo, char* message, int m_len, int time_out); + +// Receive message from an array of sctp channels, +// however, we will get message data from just one channel, +// and copy the data into buffer. +// +// return: received data size +// +extern int gs_recv( + gsocket* gs_sock, // array of node index, which labeled the datanodes will send data to this datanode + void* buff, // buffer to copy data message, allocated by caller + int buff_size // size of buffer +); + +// Simulate linux poll interface, +// to notify the Consumer thread data have been received into the inner buffer, you can come to take it +// +// return: the number of mailbox which has data +// +extern int gs_wait_poll(gsocket* gs_sock_array, // array of producers node index + int nproducer, // number of producers + int* producer, // producers number triggers poll + int timeout, // time out in seconds, 0 for block mode + bool close_expected // is logic connection closed by remote is an expected result +); + +/* Handle the same message and print message receiving and sending log */ +extern void gs_comm_ipc_print(MessageIpcLog *ipc_log, char *remotenode, gsocket *gs_sock, CommMsgOper msg_oper); + +/* Send and receive data between nodes, for performance problem location */ +extern MessageCommLog* gs_comm_ipc_performance(MessageCommLog *msgLog, + void *ptr, + int n, + char *remotenode, + gsocket *gs_sock, + CommMsgOper logType); + +// Receiver close sctp stream +// +extern int gs_r_close_stream(int sctp_idx, // node index + int sctp_sid, // stream index + int version // stream key(the plan id and plan node id), associated the pair of Consumer and Producer +); + +// Sender close sctp stream +// +extern int gs_s_close_stream(int sctp_idx, // node index + int sctp_sid, // node index + int version // stream key(the plan id and plan node id), associated the pair of Consumer and Producer +); + +extern void gs_close_gsocket(gsocket* gsock); + +extern void gs_poll_close(); + +extern int gs_close_all_stream_by_debug_id(uint64 query_id); + +extern bool gs_stop_query(gsocket* gsock, uint32 remote_pid); + +// Shudown the communication layer +// +extern void gs_shutdown_comm(); + +// Do internal cancel when cancelling is requested +// +extern void gs_r_cancel(); + +// export communication layer status +// +extern void gs_log_comm_status(); + +// check if the kernel version is reliable +// +extern int gs_check_SLESSP2_version(); + +// get the assigned stream number +// +extern int gs_get_stream_num(); + +// get the error information +// +const char* gs_comm_strerror(); + +// get communication layer stream status at receiver as a tuple for pg_comm_recv_stream +// +extern bool get_next_recv_stream_status(CommRecvStreamStatus* stream_status); + +// get communication layer stream status at sender as a tuple for pg_comm_send_stream +// +extern bool get_next_send_stream_status(CommSendStreamStatus* stream_status); + +// get communication layer stream status as a tuple for pg_comm_status +// +extern bool gs_get_comm_stat(CommStat* comm_stat); + +// get communication layer sctp delay infomation as a tuple for pg_comm_delay +// +extern bool get_next_comm_delay_info(CommDelayInfo* delay_info); + +extern void gs_set_debug_mode(bool mod); + +extern void gs_set_stat_mode(bool mod); + +extern void gs_set_timer_mode(bool mod); + +extern void gs_set_no_delay(bool mod); + +extern void gs_set_ackchk_time(int mod); + +extern void gs_set_libcomm_used_rate(int rate); + +extern void init_libcomm_cpu_rate(); + +// get availabe memory of communication layer +// +extern long gs_get_comm_used_memory(void); + +extern long gs_get_comm_peak_memory(void); + +extern Size gs_get_comm_context_memory(void); + +extern int gs_release_comm_memory(); + +// interface function for postmaster read msg by unix domain +extern int gs_recv_msg_by_unix_domain(int fd, gsocket* gs_sock); + +// check mailbox version for connection reused by poolmgr +extern bool gs_test_libcomm_conn(gsocket* gs_sock); + +// reset cmailbox for pooler reuse +extern void gs_clean_cmailbox(gsocket gs_sock); + +// for capacity expansion +extern void gs_change_capacity(int newval); + +extern int gs_get_cur_node(); + +extern void commSenderFlowMain(); +extern void commReceiverFlowMain(); +extern void commAuxiliaryMain(); +extern void commPoolCleanerMain(); +extern void commReceiverMain(void* tid_callback); + +extern void gs_init_hash_table(); +extern int mc_tcp_connect_nonblock(const char* host, int port); + +/* + * LIBCOMM_CHECK is defined when make commcheck + */ +#ifdef LIBCOMM_CHECK +#define LIBCOMM_FAULT_INJECTION_ENABLE +#define LIBCOMM_SPEED_TEST_ENABLE +#else +#undef LIBCOMM_FAULT_INJECTION_ENABLE +#undef LIBCOMM_SPEED_TEST_ENABLE +#endif + +/* + * Libcomm Speed Test Framework + * Before start: 1, Must run a stream query to get DN connections. + * 2, add new guc params to $GAUSSHOME/bin/cluster_guc.conf + * Start: Use gs_guc reload to set test thread num. + * For example: gs_guc reload -Z datanode -N all -I all -c "comm_test_thread_num=1" + * Stop: Use gs_guc reload to set test thread num=0. + */ +#ifdef LIBCOMM_SPEED_TEST_ENABLE +extern void gs_set_test_thread_num(int newval); +extern void gs_set_test_msg_len(int newval); +extern void gs_set_test_send_sleep(int newval); +extern void gs_set_test_send_once(int newval); +extern void gs_set_test_recv_sleep(int newval); +extern void gs_set_test_recv_once(int newval); +#endif + +/*Libcomm fault injection Framework + * Before start: 1, enable LIBCOMM_FAULT_INJECTION_ENABLE. + * 2, add new guc params to $GAUSSHOME/bin/cluster_guc.conf + * Start: Use gs_guc reload to set FI num. + * For instance: gs_guc reload -Z datanode -N all -I all -c "comm_fault_injection=6" + * Stop: Use gs_guc reload to set comm_fault_injection=0. + */ +#ifdef LIBCOMM_FAULT_INJECTION_ENABLE +typedef enum { + LIBCOMM_FI_NONE, + LIBCOMM_FI_R_TCP_DISCONNECT, + LIBCOMM_FI_R_SCTP_DISCONNECT, + LIBCOMM_FI_S_TCP_DISCONNECT, + LIBCOMM_FI_S_SCTP_DISCONNECT, + LIBCOMM_FI_RELEASE_MEMORY, + LIBCOMM_FI_FAILOVER, // + LIBCOMM_FI_NO_STREAMID, + LIBCOMM_FI_CONSUMER_REJECT, + LIBCOMM_FI_R_APP_CLOSE, // + LIBCOMM_FI_S_APP_CLOSE, // + LIBCOMM_FI_CANCEL_SIGNAL, // + LIBCOMM_FI_CLOSE_BY_VIEW, // + LIBCOMM_FI_GSS_TCP_FAILED, + LIBCOMM_FI_GSS_SCTP_FAILED, + LIBCOMM_FI_R_PACKAGE_SPLIT, + LIBCOMM_FI_MALLOC_FAILED, + LIBCOMM_FI_MC_TCP_READ_FAILED, + LIBCOMM_FI_MC_TCP_READ_BLOCK_FAILED, + LIBCOMM_FI_MC_TCP_READ_NONBLOCK_FAILED, + LIBCOMM_FI_MC_TCP_WRITE_FAILED, + LIBCOMM_FI_MC_TCP_WRITE_NONBLOCK_FAILED, + LIBCOMM_FI_MC_TCP_ACCEPT_FAILED, + LIBCOMM_FI_MC_TCP_LISTEN_FAILED, + LIBCOMM_FI_MC_TCP_CONNECT_FAILED, + LIBCOMM_FI_FD_SOCKETVERSION_FAILED, + LIBCOMM_FI_SOCKID_NODEIDX_FAILED, + LIBCOMM_FI_POLLER_ADD_FD_FAILED, + LIBCOMM_FI_NO_NODEIDX, + LIBCOMM_FI_CREATE_POLL_FAILED, + LIBCOMM_FI_DYNAMIC_CAPACITY_FAILED, + LIBCOMM_FI_MAX +} LibcommFaultInjection; + +extern void gs_set_fault_injection(int newval); +extern void set_comm_fault_injection(int type); +extern bool is_comm_fault_injection(LibcommFaultInjection type); +#endif + +#endif //_GS_LIBCOMM_H_ diff -uprN postgresql-hll-2.14_old/include/libpq/auth.h postgresql-hll-2.14/include/libpq/auth.h --- postgresql-hll-2.14_old/include/libpq/auth.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/auth.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * auth.h + * Definitions for network authentication routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/auth.h + * + * ------------------------------------------------------------------------- + */ +#ifndef AUTH_H +#define AUTH_H + +#include "libpq/libpq-be.h" +#include "gssapi/gssapi.h" +#include "gssapi/gssapi_krb5.h" + +#define INITIAL_USER_ID 10 +#define PREFIX_LENGTH 8 + +/* The struct for gss kerberos authentication. */ +typedef struct GssConn { + int sock; + + gss_ctx_id_t gctx; /* GSS context */ + gss_name_t gtarg_nam; /* GSS target name */ + gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc goutbuf; /* GSS output token */ +} GssConn; + +extern char* pg_krb_server_hostname; +extern char* pg_krb_realm; + +extern void ClientAuthentication(Port* port); + +/* Main function for gss kerberos client/server authentication. */ +extern int GssServerAuth(int socket, const char* krb_keyfile); +extern int GssClientAuth(int socket, char* server_host); + +/* Hook for plugins to get control in ClientAuthentication() */ +typedef void (*ClientAuthentication_hook_type)(Port*, int); +extern THR_LOCAL PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook; +extern bool IsDSorHaWalSender(); + +#endif /* AUTH_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/be-fsstubs.h postgresql-hll-2.14/include/libpq/be-fsstubs.h --- postgresql-hll-2.14_old/include/libpq/be-fsstubs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/be-fsstubs.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,54 @@ +/* ------------------------------------------------------------------------- + * + * be-fsstubs.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/be-fsstubs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BE_FSSTUBS_H +#define BE_FSSTUBS_H + +#include "fmgr.h" + +/* + * LO functions available via pg_proc entries + */ +extern Datum lo_import(PG_FUNCTION_ARGS); +extern Datum lo_import_with_oid(PG_FUNCTION_ARGS); +extern Datum lo_export(PG_FUNCTION_ARGS); + +extern Datum lo_creat(PG_FUNCTION_ARGS); +extern Datum lo_create(PG_FUNCTION_ARGS); + +extern Datum lo_open(PG_FUNCTION_ARGS); +extern Datum lo_close(PG_FUNCTION_ARGS); + +extern Datum loread(PG_FUNCTION_ARGS); +extern Datum lowrite(PG_FUNCTION_ARGS); + +extern Datum lo_lseek(PG_FUNCTION_ARGS); +extern Datum lo_tell(PG_FUNCTION_ARGS); +extern Datum lo_unlink(PG_FUNCTION_ARGS); +extern Datum lo_truncate(PG_FUNCTION_ARGS); + +/* + * These are not fmgr-callable, but are available to C code. + * Probably these should have had the underscore-free names, + * but too late now... + */ +extern int lo_read(int fd, char* buf, int len); +extern int lo_write(int fd, const char* buf, int len); + +/* + * Cleanup LOs at xact commit/abort + */ +extern void AtEOXact_LargeObject(bool isCommit); +extern void AtEOSubXact_LargeObject(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); + +#endif /* BE_FSSTUBS_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/cl_state.h postgresql-hll-2.14/include/libpq/cl_state.h --- postgresql-hll-2.14_old/include/libpq/cl_state.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/cl_state.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,84 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cl_state.h + * + * IDENTIFICATION + * src\include\libpq\cl_state.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +// CLIENT LOGIC STATE +#include "guc_vars.h" +#include +#include +#include "client_logic_cache/cache_refresh_type.h" +#include "libpq-fe.h" +#include "postgres_fe.h" +#include "client_logic_processor/raw_values_list.h" + +typedef struct pg_conn PGconn; + +struct ICachedColumns; +typedef struct CopyStateData CopyStateData; +class CStringsMap; +typedef CStringsMap StringArgs; +class StatementData; + +class HookResource; +typedef struct objectFqdn { + char data[NAMEDATALEN * 4]; +} ObjectFqdn; + +class PreparedStatementsList; + +/* + the PGClientLogic class maintains the per session state machine related to the Client Logic feature +*/ +class PGClientLogic { +public: + PGClientLogic(PGconn *conn); + ~PGClientLogic(); + PGconn* m_conn; + bool enable_client_encryption; + bool disable_once; + PreparedStatementsList *preparedStatements; + PreparedStatementsList *pendingStatements; + + char lastStmtName[NAMEDATALEN]; + ObjectFqdn *droppedSchemas; + size_t droppedSchemas_size; + size_t droppedSchemas_allocated; + ObjectFqdn *droppedGlobalSettings; + size_t droppedGlobalSettings_size; + size_t droppedGlobalSettings_allocated; + ObjectFqdn *droppedColumnSettings; + size_t droppedColumnSettings_size; + size_t droppedColumnSettings_allocated; + ExecStatusType m_lastResultStatus; + bool isInvalidOperationOnColumn; + bool isDuringRefreshCacheOnError; + CacheRefreshType cacheRefreshType; + std::unordered_map m_hookResources; + + // GUC params + GucParams gucParams; + GucParams tmpGucParams; + updateGucValues val_to_update; + RawValuesList *rawValuesForReplace; +}; diff -uprN postgresql-hll-2.14_old/include/libpq/crypt.h postgresql-hll-2.14/include/libpq/crypt.h --- postgresql-hll-2.14_old/include/libpq/crypt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/crypt.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,36 @@ +/* ------------------------------------------------------------------------- + * + * crypt.h + * Interface to libpq/crypt.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/crypt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CRYPT_H +#define PG_CRYPT_H + +#include "libpq/libpq-be.h" + +#include "libpq/sha2.h" + +/* the struct for iam token */ +typedef struct iam_token { + char* expires_at; + char* username; + bool role_priv; + char* cluster_id; + char* tenant_id; +} iam_token; + +extern int32 get_password_stored_method(const char* role, char* encrypted_string, int len); +extern int CheckUserValid(Port* port, const char* role); +extern int crypt_verify(const Port* port, const char* user, char* client_pass); +extern int get_stored_iteration(const char* role); +extern char* verify_cms_token(char* token_string); +extern bool parse_token(const char* token_string, iam_token* token); +extern bool check_token(iam_token token, char* rolname); +#endif diff -uprN postgresql-hll-2.14_old/include/libpq/guc_vars.h postgresql-hll-2.14/include/libpq/guc_vars.h --- postgresql-hll-2.14_old/include/libpq/guc_vars.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/guc_vars.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * guc_vars.h + * + * IDENTIFICATION + * src\include\libpq\guc_vars.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include +#include "parser/backslash_quotes.h" + +/* + GUC variables (Grand Unified Configuration variables) + These variables are typically only maintained the server side but some variables the client driver must also keep + track of. Typically used by the parser's lexer component +*/ + +typedef enum updateGucValues { + GUC_NONE = 0x0, + BACKSLASH_QUOTE = 0x1, + CONFORMING = 0x2, + ESCAPE_STRING = 0x4, + SEARCH_PATH = 0x8, + GUC_ROLE = 0x10 +} updateGucValues; + + +inline updateGucValues operator | (updateGucValues lhs, updateGucValues rhs) +{ + using T = std::underlying_type::type; + return static_cast(static_cast(lhs) | static_cast(rhs)); +} + +inline updateGucValues operator&(updateGucValues lhs, updateGucValues rhs) +{ + using T = std::underlying_type::type; + return static_cast(static_cast(lhs) & static_cast(rhs)); +} + +inline updateGucValues &operator |= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = lhs | rhs; + return lhs; +} + +inline updateGucValues &operator &= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = lhs & rhs; + return lhs; +} + +inline updateGucValues &operator ^= (updateGucValues &lhs, updateGucValues rhs) +{ + lhs = updateGucValues((int)lhs ^ (int)rhs); + return lhs; +} + + +typedef struct GucParams { + GucParams() + : backslash_quote(BACKSLASH_QUOTE_SAFE_ENCODING), + standard_conforming_strings(true), + escape_string_warning(true), + searchpathStr("\"$user\",public") {}; + int backslash_quote; + bool standard_conforming_strings; + bool escape_string_warning; + std::string searchpathStr; + std::string role; +} GucParams; diff -uprN postgresql-hll-2.14_old/include/libpq/hba.h postgresql-hll-2.14/include/libpq/hba.h --- postgresql-hll-2.14_old/include/libpq/hba.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/hba.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,82 @@ +/* ------------------------------------------------------------------------- + * + * hba.h + * Interface to hba.c + * + * + * src/include/libpq/hba.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HBA_H +#define HBA_H + +#include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */ +#include "nodes/pg_list.h" + +typedef enum UserAuth { + uaReject, + uaImplicitReject, + uaKrb5, + uaTrust, + uaIdent, + uaMD5, + uaSHA256, + uaGSS, + uaSSPI, + uaPAM, + uaLDAP, + uaCert, + uaPeer, + uaIAM +} UserAuth; + +typedef enum IPCompareMethod { ipCmpMask, ipCmpSameHost, ipCmpSameNet, ipCmpAll } IPCompareMethod; + +typedef enum ConnType { ctLocal, ctHost, ctHostSSL, ctHostNoSSL } ConnType; + +typedef struct HbaLine { + int linenumber; + ConnType conntype; + List* databases; + List* roles; + struct sockaddr_storage addr; + struct sockaddr_storage mask; + IPCompareMethod ip_cmp_method; + char* hostname; + UserAuth auth_method; + + char* usermap; + char* pamservice; + bool ldaptls; + char* ldapserver; + int ldapport; + char* ldapbinddn; + char* ldapbindpasswd; + char* ldapsearchattribute; + char* ldapbasedn; + char* ldapprefix; + char* ldapsuffix; + bool clientcert; + char* krb_server_hostname; + char* krb_realm; + bool include_realm; + bool remoteTrust; +} HbaLine; + +/* kluge to avoid including libpq/libpq-be.h here */ +typedef struct Port hbaPort; + +extern bool load_hba(void); +extern void load_ident(void); +extern void hba_getauthmethod(hbaPort* port); +extern bool IsLoopBackAddr(Port* port); +extern int check_usermap(const char* usermap_name, const char* pg_role, const char* auth_user, bool case_sensitive); + +extern bool pg_isblank(const char c); +extern bool is_cluster_internal_connection(hbaPort* port); +extern bool is_node_internal_connection(hbaPort* port); +extern bool is_cluster_internal_IP(sockaddr peer_addr); +extern bool check_ip_whitelist(hbaPort* port, char* ip, unsigned int ip_len); + +#endif /* HBA_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/ip.h postgresql-hll-2.14/include/libpq/ip.h --- postgresql-hll-2.14_old/include/libpq/ip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/ip.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * ip.h + * Definitions for IPv6-aware network access. + * + * These definitions are used by both frontend and backend code. Be careful + * what you include here! + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/libpq/ip.h + * + * ------------------------------------------------------------------------- + */ +#ifndef IP_H +#define IP_H + +#include "getaddrinfo.h" /* pgrminclude ignore */ +#include "libpq/pqcomm.h" /* pgrminclude ignore */ + +#ifdef HAVE_UNIX_SOCKETS +#define IS_AF_UNIX(fam) ((fam) == AF_UNIX) +#else +#define IS_AF_UNIX(fam) (0) +#endif + +typedef void (*PgIfAddrCallback)(struct sockaddr* addr, struct sockaddr* netmask, void* cb_data); + +extern int pg_getaddrinfo_all( + const char* hostname, const char* servname, const struct addrinfo* hintp, struct addrinfo** result); +extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo* ai); + +extern int pg_getnameinfo_all( + const struct sockaddr_storage* addr, int salen, char* node, int nodelen, char* service, int servicelen, int flags); + +extern int pg_range_sockaddr(const struct sockaddr_storage* addr, const struct sockaddr_storage* netaddr, + const struct sockaddr_storage* netmask); + +extern int pg_sockaddr_cidr_mask(struct sockaddr_storage* mask, const char* numbits, int family); + +#ifdef HAVE_IPV6 +extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage* addr); +extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage* addr); +#endif + +extern int pg_foreach_ifaddr(PgIfAddrCallback callback, void* cb_data); + +#endif /* IP_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq-be.h postgresql-hll-2.14/include/libpq/libpq-be.h --- postgresql-hll-2.14_old/include/libpq/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq-be.h 2020-12-12 17:06:43.315348916 +0800 @@ -0,0 +1,232 @@ +/* ------------------------------------------------------------------------- + * + * libpq_be.h + * This file contains definitions for structures and externs used + * by the postmaster during client authentication. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq-be.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_BE_H +#define LIBPQ_BE_H + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifdef USE_SSL +#include "openssl/ossl_typ.h" +#endif + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + +#ifdef ENABLE_GSS +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif /* HAVE_GSSAPI_H */ +/* + * GSSAPI brings in headers that set a lot of things in the global namespace on win32, + * that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore, + * but also defines a symbol that simply does not exist. Undefine it again. + */ +#ifdef WIN32_ONLY_COMPILER +#undef HAVE_GETADDRINFO +#endif +#endif /* ENABLE_GSS */ + +#ifdef ENABLE_SSPI +#define SECURITY_WIN32 +#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER) +#include +#endif +#include +#undef SECURITY_WIN32 +#ifndef ENABLE_GSS +/* + * Define a fake structure compatible with GSSAPI on Unix. + */ +typedef struct { + void* value; + int length; +} gss_buffer_desc; +#endif +#endif /* ENABLE_SSPI */ + +#include "datatype/timestamp.h" +#include "libpq/hba.h" +#include "libpq/pqcomm.h" +#include "libpq/sha2.h" +#include "libcomm/libcomm.h" + +typedef enum CAC_state { CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY, CAC_WAITBACKUP } CAC_state; + +/* + * GSSAPI specific state information + */ +#if defined(ENABLE_GSS) | defined(ENABLE_SSPI) +typedef struct { + gss_buffer_desc outbuf; /* GSSAPI output token buffer */ +#ifdef ENABLE_GSS + gss_cred_id_t cred; /* GSSAPI connection cred's */ + gss_ctx_id_t ctx; /* GSSAPI connection context */ + gss_name_t name; /* GSSAPI client name */ +#endif +} pg_gssinfo; +#endif + +/* + * This is used by the postmaster in its communication with frontends. It + * contains all state information needed during this communication before the + * backend is run. The Port structure is kept in malloc'd memory and is + * still available when a backend is running (see u_sess->proc_cxt.MyProcPort). The data + * it points to must also be malloc'd, or else palloc'd in TopMemoryContext, + * so that it survives into PostgresMain execution! + */ + +typedef struct Port { + volatile pgsocket sock; /* File descriptor */ + bool noblock; /* is the socket in non-blocking mode? */ + ProtocolVersion proto; /* FE/BE protocol version */ + SockAddr laddr; /* local addr (postmaster) */ + SockAddr raddr; /* remote addr (client) */ + char* remote_host; /* name (or ip addr) of remote host */ + char* remote_hostname; /* name (not ip addr) of remote host, if + * available */ + int remote_hostname_resolv; /* +1 = remote_hostname is known to + * resolve to client's IP address; -1 + * = remote_hostname is known NOT to + * resolve to client's IP address; 0 = + * we have not done the forward DNS + * lookup yet */ + char* remote_port; /* text rep of remote port */ + + // Stream Commucation. Use only between DN. + // + libcommaddrinfo* libcomm_addrinfo; + + gsocket gs_sock; + + CAC_state canAcceptConnections; /* postmaster connection status */ + + /* + * Information that needs to be saved from the startup packet and passed + * into backend execution. "char *" fields are NULL if not set. + * guc_options points to a List of alternating option names and values. + */ + char* database_name; + char* user_name; + char* cmdline_options; + List* guc_options; + + /* + * Information that needs to be held during the authentication cycle. + */ + HbaLine* hba; + char md5Salt[4]; /* Password salt */ + + /* + * Information that really has no business at all being in struct Port, + * but since it gets used by elog.c in the same way as database_name and + * other members of this struct, we may as well keep it here. + */ + TimestampTz SessionStartTime; /* backend start time */ + + /* + * Backend version number of the remote end, if available. + * + * For local backends, they should be launched with the same version + * number as the remote end for compatibility. + */ + uint32 SessionVersionNum; + + /* + * TCP keepalive settings. + * + * default values are 0 if AF_UNIX or not yet known; current values are 0 + * if AF_UNIX or using the default. Also, -1 in a default value means we + * were unable to find out the default (getsockopt failed). + */ + int default_keepalives_idle; + int default_keepalives_interval; + int default_keepalives_count; + int keepalives_idle; + int keepalives_interval; + int keepalives_count; + +#if defined(ENABLE_GSS) || defined(ENABLE_SSPI) + + /* + * If GSSAPI is supported, store GSSAPI information. Otherwise, store a + * NULL pointer to make sure offsets in the struct remain the same. + */ + pg_gssinfo* gss; +#else + void* gss; +#endif + + /* + * SSL structures (keep these last so that USE_SSL doesn't affect + * locations of other fields) + */ +#ifdef USE_SSL + SSL* ssl; + X509* peer; + char* peer_cn; + unsigned long count; + +#endif + /* begin RFC 5802 */ + char token[TOKEN_LENGTH * 2 + 1]; + /* end RFC 5802 */ + bool is_logic_conn; + MessageCommLog *msgLog; + + /* Support kerberos authentication for gtm server */ +#ifdef ENABLE_GSS + char* krbsrvname; /* Kerberos service name */ + gss_ctx_id_t gss_ctx; /* GSS context */ + gss_cred_id_t gss_cred; /* GSS credential */ + gss_name_t gss_name; /* GSS target name */ + gss_buffer_desc gss_outbuf; /* GSS output token buffer */ +#endif +} Port; + +#define STREAM_BUFFER_SIZE 8192 +#define STREAM_BUFFER_SIZE_KB 8 + +typedef struct StreamBuffer { + char PqSendBuffer[STREAM_BUFFER_SIZE]; + int PqSendBufferSize; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + int PqSendStart; + bool PqCommBusy; +} StreamBuffer; + +extern char* tcp_link_addr; +extern THR_LOCAL ProtocolVersion FrontendProtocol; + +/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ + +extern int pq_getkeepalivesidle(Port* port); +extern int pq_getkeepalivesinterval(Port* port); +extern int pq_getkeepalivescount(Port* port); + +extern int pq_setkeepalivesidle(int idle, Port* port); +extern int pq_setkeepalivesinterval(int interval, Port* port); +extern int pq_setkeepalivescount(int count, Port* port); + +extern CAC_state canAcceptConnections(bool isSession); + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq-events.h postgresql-hll-2.14/include/libpq/libpq-events.h --- postgresql-hll-2.14_old/include/libpq/libpq-events.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq-events.h 2020-12-12 17:06:43.316348929 +0800 @@ -0,0 +1,87 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-events.h + * This file contains definitions that are useful to applications + * that invoke the libpq "events" API, but are not interesting to + * ordinary users of libpq. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/libpq/libpq-events.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_EVENTS_H +#define LIBPQ_EVENTS_H + +#include "libpq-fe.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Callback Event Ids */ +typedef enum { + PGEVT_REGISTER, + PGEVT_CONNRESET, + PGEVT_CONNDESTROY, + PGEVT_RESULTCREATE, + PGEVT_RESULTCOPY, + PGEVT_RESULTDESTROY +} PGEventId; + +typedef struct { + PGconn* conn; +} PGEventRegister; + +typedef struct { + PGconn* conn; +} PGEventConnReset; + +typedef struct { + PGconn* conn; +} PGEventConnDestroy; + +typedef struct { + PGconn* conn; + PGresult* result; +} PGEventResultCreate; + +typedef struct { + const PGresult* src; + PGresult* dest; +} PGEventResultCopy; + +typedef struct { + PGresult* result; +} PGEventResultDestroy; + +typedef int (*PGEventProc)(PGEventId evtId, void* evtInfo, void* passThrough); + +/* Registers an event proc with the given PGconn. */ +extern int PQregisterEventProc(PGconn* conn, PGEventProc proc, const char* name, void* passThrough); + +/* Sets the PGconn instance data for the provided proc to data. */ +extern int PQsetInstanceData(PGconn* conn, PGEventProc proc, void* data); + +/* Gets the PGconn instance data for the provided proc. */ +extern void* PQinstanceData(const PGconn* conn, PGEventProc proc); + +/* Sets the PGresult instance data for the provided proc to data. */ +extern int PQresultSetInstanceData(PGresult* result, PGEventProc proc, void* data); + +/* Gets the PGresult instance data for the provided proc. */ +extern void* PQresultInstanceData(const PGresult* result, PGEventProc proc); + +/* Fires RESULTCREATE events for an application-created PGresult. */ +extern int PQfireResultCreateEvents(PGconn* conn, PGresult* res); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_EVENTS_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq-fe.h postgresql-hll-2.14/include/libpq/libpq-fe.h --- postgresql-hll-2.14_old/include/libpq/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq-fe.h 2020-12-12 17:06:43.316348929 +0800 @@ -0,0 +1,578 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * + * IDENTIFICATION + * src/include/libpq/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_FE_H +#define LIBPQ_FE_H + +#ifdef __cplusplus +extern "C" { +#endif +#include +#include +#include + +/* + * postgres_ext.h defines the backend's externally visible types, + * such as Oid. + */ +#include "postgres_ext.h" +#include "gs_thread.h" + +/* + * Option flags for PQcopyResult + */ +#define PG_COPYRES_ATTRS 0x01 +#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */ +#define PG_COPYRES_EVENTS 0x04 +#define PG_COPYRES_NOTICEHOOKS 0x08 + +#define libpq_free(__p) \ + do { \ + if ((__p) != NULL) { \ + free((__p)); \ + (__p) = NULL; \ + } \ + } while (0) + +#ifndef Assert +#ifndef USE_ASSERT_CHECKING +#define Assert(p) +#else +#define Assert(p) assert(p) +#endif /* USE_ASSERT_CHECKING */ +#endif /* Assert */ + +extern long libpq_used_memory; +extern long libpq_peak_memory; +extern long libcomm_used_memory; +extern long comm_peak_used_memory; + +/* Application-visible enum types */ +/* + * Although it is okay to add to these lists, values which become unused + * should never be removed, nor should constants be redefined - that would + * break compatibility with existing code. + */ + +typedef enum { + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should only + * be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} ConnStatusType; + +typedef enum { + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} PostgresPollingStatusType; + +typedef enum { + PGRES_EMPTY_QUERY = 0, /* empty query string was executed */ + PGRES_COMMAND_OK, /* a query command that doesn't return + * anything was executed properly by the + * backend */ + PGRES_TUPLES_OK, /* a query command that returns tuples was + * executed properly by the backend, PGresult + * contains the result tuples */ + PGRES_COPY_OUT, /* Copy Out data transfer in progress */ + PGRES_COPY_IN, /* Copy In data transfer in progress */ + PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the + * backend */ + PGRES_NONFATAL_ERROR, /* notice or warning message */ + PGRES_FATAL_ERROR, /* query failed */ + PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */ + PGRES_SINGLE_TUPLE /* single tuple from larger resultset */ +} ExecStatusType; + +typedef enum { + PQTRANS_IDLE, /* connection idle */ + PQTRANS_ACTIVE, /* command in progress */ + PQTRANS_INTRANS, /* idle, within transaction block */ + PQTRANS_INERROR, /* idle, within failed transaction */ + PQTRANS_UNKNOWN /* cannot determine status */ +} PGTransactionStatusType; + +typedef enum { + PQERRORS_TERSE, /* single-line error messages */ + PQERRORS_DEFAULT, /* recommended style */ + PQERRORS_VERBOSE /* all the facts, ma'am */ +} PGVerbosity; + +typedef enum { + PQPING_OK, /* server is accepting connections */ + PQPING_REJECT, /* server is alive but rejecting connections */ + PQPING_NO_RESPONSE, /* could not establish connection */ + PQPING_NO_ATTEMPT /* connection not attempted (bad params) */ +} PGPing; + +/* PGconn encapsulates a connection to the backend. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_conn PGconn; + +/* PGresult encapsulates the result of a query (or more precisely, of a single + * SQL command --- a query string given to PQsendQuery can contain multiple + * commands and thus return multiple PGresult objects). + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_result PGresult; + +/* PGcancel encapsulates the information needed to cancel a running + * query on an existing connection. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_cancel PGcancel; + +// ConnPack encapsulates the information needed to connect remote stream threads +// +typedef struct ConnPack ConnPack; + +/* PGnotify represents the occurrence of a NOTIFY message. + * Ideally this would be an opaque typedef, but it's so simple that it's + * unlikely to change. + * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's, + * whereas in earlier versions it was always your own backend's PID. + */ +typedef struct pgNotify { + char* relname; /* notification condition name */ + ThreadId be_pid; /* process ID of notifying server process */ + char* extra; /* notification parameter */ + /* Fields below here are private to libpq; apps should not use 'em */ + struct pgNotify* next; /* list link */ +} PGnotify; + +/* Function types for notice-handling callbacks */ +typedef void (*PQnoticeReceiver)(void* arg, const PGresult* res); +typedef void (*PQnoticeProcessor)(void* arg, const char* message); + +/* Print options for PQprint() */ +typedef char pqbool; + +typedef struct _PQprintOpt { + pqbool header; /* print output field headings and row count */ + pqbool align; /* fill align the fields */ + pqbool standard; /* old brain dead format */ + pqbool html3; /* output html tables */ + pqbool expanded; /* expand tables */ + pqbool pager; /* use pager for output if needed */ + char* fieldSep; /* field separator */ + char* tableOpt; /* insert to HTML */ + char* caption; /* HTML
*/ + char** fieldName; /* null terminated array of replacement field + * names */ +} PQprintOpt; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * or PQconninfoParse. + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. PQconninfoFree() + * will release both the val strings and the PQconninfoOption array itself. + * ---------------- + */ +typedef struct _PQconninfoOption { + char* keyword; /* The keyword of the option */ + char* envvar; /* Fallback environment variable name */ + char* compiled; /* Fallback compiled in default value */ + char* val; /* Option's current value, or NULL */ + char* label; /* Label for field in connect dialog */ + char* dispchar; /* Indicates how to display this field in a + * connect dialog. Values are: "" Display + * entered value as is "*" Password field - + * hide value "D" Debug option - don't show + * by default */ + int dispsize; /* Field size in characters for dialog */ + size_t valsize; /* Value actual length for double check */ +} PQconninfoOption; + +/* ---------------- + * PQArgBlock -- structure for PQfn() arguments + * ---------------- + */ +typedef struct { + int len; + int isint; + union { + int* ptr; /* can't use void (dec compiler barfs) */ + int integer; + } u; +} PQArgBlock; + +/* ---------------- + * PGresAttDesc -- Data about a single attribute (column) of a query result + * ---------------- + */ +typedef struct pgresAttDesc { + char* name; /* column name */ + Oid tableid; /* source table, if known */ + int columnid; /* source column, if known */ + int format; /* format code for value (text/binary) */ + Oid typid; /* type id */ + int typlen; /* type size */ + int atttypmod; /* type-specific modifier info */ +} PGresAttDesc; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +extern char* PQbuildPGconn(const char* conninfo, PGconn** connPtr, int* packetlen); + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern PGconn* PQconnectStart(const char* conninfo); +extern PGconn* PQconnectStartParams(const char* const* keywords, const char* const* values, int expand_dbname); +extern PostgresPollingStatusType PQconnectPoll(PGconn* conn); + +/* Synchronous (blocking) */ +extern PGconn* PQconnectdb(const char* conninfo); +/* connect parallel (no blocking) */ +extern int PQconnectdbParallel(char const* const* conninfo, int count, PGconn* conn[], Oid* nodeid); + +extern PGconn* PQconnectdbParams(const char* const* keywords, const char* const* values, int expand_dbname); +extern PGconn* PQsetdbLogin(const char* pghost, const char* pgport, const char* pgoptions, const char* pgtty, + const char* dbName, const char* login, const char* pwd); + +#define PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME) \ + PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL) + +/* close the current connection and free the PGconn data structure */ +extern void PQfinish(PGconn* conn); + +extern void closePGconn(PGconn* conn); +extern void freePGconn(PGconn* conn); + +/* get info about connection options known to PQconnectdb */ +extern PQconninfoOption* PQconndefaults(void); + +/* parse connection options in same way as PQconnectdb */ +extern PQconninfoOption* PQconninfoParse(const char* conninfo, char** errmsg); + +/* free the data structure returned by PQconndefaults() or PQconninfoParse() */ +extern void PQconninfoFree(PQconninfoOption* connOptions); + +/* + * close the current connection and restablish a new one with the same + * parameters + */ +/* Asynchronous (non-blocking) */ +extern int PQresetStart(PGconn* conn); +extern PostgresPollingStatusType PQresetPoll(PGconn* conn); + +/* Synchronous (blocking) */ +extern void PQreset(PGconn* conn); + +/* request a cancel structure */ +extern PGcancel* PQgetCancel(PGconn* conn); + +/* free a cancel structure */ +extern void PQfreeCancel(PGcancel* cancel); + +/* issue a cancel request */ +extern int PQcancel(PGcancel* cancel, char* errbuf, int errbufsize); +extern int PQcancel_timeout(PGcancel* cancel, char* errbuf, int errbufsize, int timeout); + +/* issue a stop request */ +extern int PQStop(PGcancel* cancel, char* errbuf, int errbufsize, unsigned long query_id); +extern int PQstop_timeout(PGcancel* cancel, char* errbuf, int errbufsize, int timeout, unsigned long query_id); + +/* issue a stream connect request */ +extern int StreamConnect(void* raddr, ConnPack* csp, int packetlen, char* errbuf, int errbufsize); + +/* backwards compatible version of PQcancel; not thread-safe */ +extern int PQrequestCancel(PGconn* conn); + +/* Accessor functions for PGconn objects */ +extern char* PQdb(const PGconn* conn); +extern char* PQuser(const PGconn* conn); +extern char* PQpass(const PGconn* conn); +extern char* PQhost(const PGconn* conn); +extern char* PQport(const PGconn* conn); +extern char* PQtty(const PGconn* conn); +extern char* PQoptions(const PGconn* conn); +extern ConnStatusType PQstatus(const PGconn* conn); +extern PGTransactionStatusType PQtransactionStatus(const PGconn* conn); +extern const char* PQparameterStatus(const PGconn* conn, const char* paramName); +extern int PQprotocolVersion(const PGconn* conn); +extern int PQserverVersion(const PGconn* conn); +extern char* PQerrorMessage(const PGconn* conn); +extern int PQsocket(const PGconn* conn); + +extern struct sockaddr* PQLocalSockaddr(const PGconn* conn); +extern struct sockaddr* PQRemoteSockaddr(const PGconn* conn); + +extern int PQbackendPID(const PGconn* conn); +extern int PQconnectionNeedsPassword(const PGconn* conn); +extern int PQconnectionUsedPassword(const PGconn* conn); +extern int PQclientEncoding(const PGconn* conn); +extern int PQsetClientEncoding(PGconn* conn, const char* encoding); +extern int PQsetRwTimeout(PGconn* conn, int build_receive_timeout); + +/* Get the OpenSSL structure associated with a connection. Returns NULL for + * unencrypted connections or if any other TLS library is in use. */ +extern void* PQgetssl(PGconn* conn); + +/* Tell libpq whether it needs to initialize OpenSSL */ +extern void PQinitSSL(int do_init); + +/* More detailed way to tell libpq whether it needs to initialize OpenSSL */ +extern void PQinitOpenSSL(int do_ssl, int do_crypto); + +/* Set verbosity for PQerrorMessage and PQresultErrorMessage */ +extern PGVerbosity PQsetErrorVerbosity(PGconn* conn, PGVerbosity verbosity); + +/* Enable/disable tracing */ +extern void PQtrace(PGconn* conn, FILE* debug_port); +extern void PQuntrace(PGconn* conn); + +/* Override default notice handling routines */ +extern PQnoticeReceiver PQsetNoticeReceiver(PGconn* conn, PQnoticeReceiver proc, void* arg); +extern PQnoticeProcessor PQsetNoticeProcessor(PGconn* conn, PQnoticeProcessor proc, void* arg); + +/* + * Used to set callback that prevents concurrent access to + * non-thread safe functions that libpq needs. + * The default implementation uses a libpq internal mutex. + * Only required for multithreaded apps that use kerberos + * both within their app and for postgresql connections. + */ +typedef void (*pgthreadlock_t)(int acquire); + +extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler); + +/* === in fe-exec.c === */ + +/* Simple synchronous query */ +extern PGresult* PQexec(PGconn* conn, const char* query); +extern PGresult* PQexecParams(PGconn* conn, const char* command, int nParams, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); +extern PGresult* PQexecParamsBatch(PGconn* conn, const char* command, int nParams, int nBatch, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern PGresult* PQprepare(PGconn* conn, const char* stmtName, const char* query, int nParams, const Oid* paramTypes); +extern PGresult* PQexecPrepared(PGconn* conn, const char* stmtName, int nParams, const char* const* paramValues, + const int* paramLengths, const int* paramFormats, int resultFormat); +extern PGresult* PQexecPreparedBatch(PGconn* conn, const char* stmtName, int nParams, int nBatchCount, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +/* Interface for multiple-result or asynchronous queries */ +extern int PQsendQuery(PGconn* conn, const char* query); +extern int PqSendQueryCheckConnValid(Oid nod_oid, PGconn* conn, const char* query); +extern int PQsendQueryPoolerStatelessReuse(PGconn* conn, const char* query); +extern int PQsendQueryParams(PGconn* conn, const char* command, int nParams, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); +extern int PQsendQueryParamsBatch(PGconn* conn, const char* command, int nParams, int nBatch, const Oid* paramTypes, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern int PQsendPrepare(PGconn* conn, const char* stmtName, const char* query, int nParams, const Oid* paramTypes); +extern int PQsendQueryPrepared(PGconn* conn, const char* stmtName, int nParams, const char* const* paramValues, + const int* paramLengths, const int* paramFormats, int resultFormat); +extern int PQsendQueryPreparedBatch(PGconn* conn, const char* stmtName, int nParams, int nBatchCount, + const char* const* paramValues, const int* paramLengths, const int* paramFormats, int resultFormat); + +extern int PQsetSingleRowMode(PGconn* conn); +extern PGresult* PQgetResult(PGconn* conn); + +/* Routines for managing an asynchronous query */ +extern int PQisBusy(PGconn* conn); +extern int PQconsumeInput(PGconn* conn); + +/* LISTEN/NOTIFY support */ +extern PGnotify* PQnotifies(PGconn* conn); + +/* Routines for copy in/out */ +extern int PQputCopyData(PGconn* conn, const char* buffer, int nbytes); +extern int PQputCopyEnd(PGconn* conn, const char* errormsg); +extern int PQgetCopyData(PGconn* conn, char** buffer, int async); + +/* Deprecated routines for copy in/out */ +extern int PQgetline(PGconn* conn, char* string, int length); +extern int PQputline(PGconn* conn, const char* string); +extern int PQgetlineAsync(PGconn* conn, char* buffer, int bufsize); +extern int PQputnbytes(PGconn* conn, const char* buffer, int nbytes); +extern int PQendcopy(PGconn* conn); + +/* Set blocking/nonblocking connection to the backend */ +extern int PQsetnonblocking(PGconn* conn, int arg); +extern int PQisnonblocking(const PGconn* conn); +extern int PQisthreadsafe(void); +extern PGPing PQping(const char* conninfo); +extern PGPing PQpingParams(const char* const* keywords, const char* const* values, int expand_dbname); + +/* Force the write buffer to be written (or at least try) */ +extern int PQflush(PGconn* conn); + +/* + * "Fast path" interface --- not really recommended for application + * use + */ +extern PGresult* PQfn( + PGconn* conn, int fnid, int* result_buf, int* result_len, int result_is_int, const PQArgBlock* args, int nargs); + +/* Accessor functions for PGresult objects */ +extern ExecStatusType PQresultStatus(const PGresult* res); +extern char* PQresStatus(ExecStatusType status); +extern char* PQresultErrorMessage(const PGresult* res); +extern char* PQresultErrorField(const PGresult* res, int fieldcode); +extern int PQntuples(const PGresult* res); +extern int PQnfields(const PGresult* res); +extern int PQbinaryTuples(const PGresult* res); +extern char* PQfname(const PGresult* res, int field_num); +extern int PQfnumber(const PGresult* res, const char* field_name); +extern Oid PQftable(const PGresult* res, int field_num); +extern int PQftablecol(const PGresult* res, int field_num); +extern int PQfformat(const PGresult* res, int field_num); +extern Oid PQftype(const PGresult* res, int field_num); +extern int PQfsize(const PGresult* res, int field_num); +extern int PQfmod(const PGresult* res, int field_num); +extern char* PQcmdStatus(PGresult* res); +extern char* PQoidStatus(const PGresult* res); /* old and ugly */ +extern Oid PQoidValue(const PGresult* res); /* new and improved */ +extern char* PQcmdTuples(PGresult* res); +extern char* PQgetvalue(const PGresult* res, int tup_num, int field_num); +extern int PQgetlength(const PGresult* res, int tup_num, int field_num); +extern int PQgetisnull(const PGresult* res, int tup_num, int field_num); +extern int PQnparams(const PGresult* res); +extern Oid PQparamtype(const PGresult* res, int param_num); + +/* Describe prepared statements and portals */ +extern PGresult* PQdescribePrepared(PGconn* conn, const char* stmt); +extern PGresult* PQdescribePortal(PGconn* conn, const char* portal); +extern int PQsendDescribePrepared(PGconn* conn, const char* stmt); +extern int PQsendDescribePortal(PGconn* conn, const char* portal); + +/* Delete a PGresult */ +extern void PQclear(PGresult* res); + +/* For freeing other alloc'd results, such as PGnotify structs */ +extern void PQfreemem(void* ptr); + +/* Exists for backward compatibility. bjm 2003-03-24 */ +#define PQfreeNotify(ptr) PQfreemem(ptr) + +/* Create and manipulate PGresults */ +extern PGresult* PQmakeEmptyPGresult(PGconn* conn, ExecStatusType status); +extern PGresult* PQcopyResult(const PGresult* src, unsigned int flags); +extern int PQsetResultAttrs(PGresult* res, int numAttributes, PGresAttDesc* attDescs); +extern void* PQresultAlloc(PGresult* res, size_t nBytes); +extern int PQsetvalue(PGresult* res, int tup_num, int field_num, const char* value, int len); + +/* Quoting strings before inclusion in queries. */ +extern size_t PQescapeStringConn(PGconn* conn, char* to, const char* from, size_t length, int* error); +extern char* PQescapeLiteral(PGconn* conn, const char* str, size_t len); +extern char* PQescapeIdentifier(PGconn* conn, const char* str, size_t len); +extern unsigned char *PQescapeByteaConn(PGconn *conn, const unsigned char *from, + size_t from_length, size_t *to_length); +extern unsigned char* PQunescapeBytea(const unsigned char* strtext, size_t* retbuflen); + +/* These forms are deprecated! */ +extern size_t PQescapeString(char* to, const char* from, size_t length); +extern unsigned char* PQescapeBytea(const unsigned char* from, size_t from_length, size_t* to_length); +#ifdef HAVE_CE +extern void checkRefreshCacheOnError(PGconn* conn); +#endif + +/* === in fe-print.c === */ + +extern void PQprint(FILE* fout, /* output stream */ + const PGresult* res, const PQprintOpt* ps); /* option structure */ + +/* + * really old printing routines + */ +extern void PQdisplayTuples(const PGresult* res, FILE* fp, /* where to send the output */ + int fillAlign, /* pad the fields with spaces */ + const char* fieldSep, /* field separator */ + int printHeader, /* display headers? */ + int quiet); + +extern void PQprintTuples(const PGresult* res, FILE* fout, /* output stream */ + int printAttName, /* print attribute names */ + int terseOutput, /* delimiter bars */ + int width); /* width of column, if 0, use variable width */ + +/* === in fe-lobj.c === */ + +/* Large-object access routines */ +extern int lo_open(PGconn* conn, Oid lobjId, int mode); +extern int lo_close(PGconn* conn, int fd); +extern int lo_read(PGconn* conn, int fd, char* buf, size_t len); +extern int lo_write(PGconn* conn, int fd, const char* buf, size_t len); +extern int lo_lseek(PGconn* conn, int fd, int offset, int whence); +extern Oid lo_creat(PGconn* conn, int mode); +extern Oid lo_create(PGconn* conn, Oid lobjId); +extern int lo_tell(PGconn* conn, int fd); +extern int lo_truncate(PGconn* conn, int fd, size_t len); +extern int lo_unlink(PGconn* conn, Oid lobjId); +extern Oid lo_import(PGconn* conn, const char* filename); +extern Oid lo_import_with_oid(PGconn* conn, const char* filename, Oid lobjId); +extern int lo_export(PGconn* conn, Oid lobjId, const char* filename); + +/* === in fe-misc.c === */ + +/* Get the version of the libpq library in use */ +extern int PQlibVersion(void); + +/* Determine length of multibyte encoded char at *s */ +extern int PQmblen(const char* s, int encoding); + +/* Determine display length of multibyte encoded char at *s */ +extern int PQdsplen(const char* s, int encoding); + +/* Get encoding id from environment variable PGCLIENTENCODING */ +extern int PQenv2encoding(void); + +/* === in fe-auth.c === */ + +extern char* PQencryptPassword(const char* passwd, const char* user); + +/* === in encnames.c === */ + +extern int pg_char_to_encoding(const char* name); +extern const char* pg_encoding_to_char(int encoding); +extern int pg_valid_server_encoding_id(int encoding); + +extern void parseInput(PGconn* conn); + +extern PGresult* getCopyResult(PGconn* conn, ExecStatusType copytype); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq-fs.h postgresql-hll-2.14/include/libpq/libpq-fs.h --- postgresql-hll-2.14_old/include/libpq/libpq-fs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq-fs.h 2020-12-12 17:06:43.316348929 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * libpq-fs.h + * definitions for using Inversion file system routines (ie, large objects) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq-fs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_FS_H +#define LIBPQ_FS_H + +/* + * Read/write mode flags for inversion (large object) calls + */ + +#define INV_WRITE 0x00020000 +#define INV_READ 0x00040000 + +#endif /* LIBPQ_FS_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq.h postgresql-hll-2.14/include/libpq/libpq.h --- postgresql-hll-2.14_old/include/libpq/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq.h 2020-12-12 17:06:43.316348929 +0800 @@ -0,0 +1,111 @@ +/* ------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/libpq.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LIBPQ_H +#define LIBPQ_H + +#include +#include + +#include "lib/stringinfo.h" +#include "libpq/libpq-be.h" + +/* ---------------- + * PQArgBlock + * Information (pointer to array of this structure) required + * for the PQfn() call. (This probably ought to go somewhere else...) + * ---------------- + */ +typedef struct { + int len; + int isint; + union { + int* ptr; /* can't use void (dec compiler barfs) */ + int integer; + } u; +} PQArgBlock; + +/* + * External functions. + */ + +/* + * prototypes for functions in pqcomm.c + */ +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, const char* unixSocketName, + pgsocket ListenSocket[], int MaxListen, bool add_localaddr_flag, + bool is_create_psql_sock, bool is_create_libcomm_sock); +extern int StreamConnection(pgsocket server_fd, Port* port); +extern void StreamClose(pgsocket sock); +extern void TouchSocketFile(void); +extern void pq_init(void); +extern void pq_comm_reset(void); +extern int pq_getbytes(char* s, size_t len); +extern int pq_getstring(StringInfo s); +extern int pq_getmessage(StringInfo s, int maxlen); +extern int pq_getbyte(void); +extern int pq_peekbyte(void); +extern int pq_getbyte_if_available(unsigned char* c); +extern int pq_putbytes(const char* s, size_t len); +extern int pq_flush(void); +extern int pq_flush_if_writable(void); +extern void pq_flush_timedwait(int timeout); +extern bool pq_is_send_pending(void); +extern int pq_putmessage(char msgtype, const char* s, size_t len); +extern int pq_putmessage_noblock(char msgtype, const char* s, size_t len); +extern void pq_startcopyout(void); +extern void pq_endcopyout(bool errorAbort); +extern bool pq_select(int timeout_ms); +extern void pq_abandon_sendbuffer(void); +extern void pq_abandon_recvbuffer(void); +extern void pq_resize_recvbuffer(int size); +extern void pq_revert_recvbuffer(const char* data, int len); +/* + * prototypes for functions in be-secure.c + */ +extern const char* ssl_cipher_file; +extern const char* ssl_rand_file; + +extern bool secure_loaded_verify_locations(void); +extern void secure_destroy(void); +extern int secure_open_server(Port* port); +extern void secure_close(Port* port); +extern ssize_t secure_read(Port* port, void* ptr, size_t len); +extern ssize_t secure_write(Port* port, void* ptr, size_t len); + +/* + * interface for flushing sendbuffer to disk + */ + +typedef enum TempFileState { + TEMPFILE_DEFAULT, + TEMPFILE_CREATED, + TEMPFILE_FLUSHED, + TEMPFILE_ON_SENDING, + TEMPFILE_SENDED, + TEMPFILE_CLOSED, + TEMPFILE_ERROR_CLOSE, + TEMPFILE_ERROR_SEND, +} TempFileState; + +extern void pq_disk_reset_tempfile_contextinfo(void); +extern void pq_disk_discard_temp_file(void); +extern bool pq_disk_is_flushed(void); +extern int pq_disk_send_to_frontend(void); +extern void pq_disk_extract_sendbuffer(void); +extern void pq_disk_enable_temp_file(void); +extern void pq_disk_disable_temp_file(void); +extern bool pq_disk_is_temp_file_enabled(void); +extern bool pq_disk_is_temp_file_created(void); + +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/libpq-int.h postgresql-hll-2.14/include/libpq/libpq-int.h --- postgresql-hll-2.14_old/include/libpq/libpq-int.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/libpq-int.h 2020-12-12 17:06:43.316348929 +0800 @@ -0,0 +1,675 @@ +/* --------------------------------------------------------------------------------------- + * + * libpq-int.h + * This file contains internal definitions meant to be used only by + * the frontend libpq library, not by applications that call it. + * + * An application can include this file if it wants to bypass the + * official API defined by libpq-fe.h, but code that does so is much + * more likely to break across PostgreSQL releases than code that uses + * only the official API. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * + * IDENTIFICATION + * src/include/libpq/libpq-int.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_INT_H +#define LIBPQ_INT_H + +/* We assume libpq-fe.h has already been included. */ +#include "postgres_fe.h" +#include "libpq-events.h" + +#include +#include +#ifndef WIN32 +#include +#endif + +#include +#include +#include + +#ifdef ENABLE_THREAD_SAFETY +#ifdef WIN32 +#include "pthread-win32.h" +#else +#include +#endif +#include +#endif + +/* include stuff common to fe and be */ +#include "getaddrinfo.h" +#include "libpq/pqcomm.h" +#include "libpq/sha2.h" +/* include stuff found in fe only */ +#include "pqexpbuffer.h" +#include "cipher.h" +#include "../../include/securec.h" +#include "../../include/securec_check.h" +#include "libcomm/libcomm.h" + +#ifdef ENABLE_GSS +#if defined(HAVE_GSSAPI_H) +#include +#else +#include +#endif +#endif + +#ifdef ENABLE_SSPI +#define SECURITY_WIN32 +#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER) +#include +#endif +#include +#undef SECURITY_WIN32 + +#ifndef ENABLE_GSS +/* + * Define a fake structure compatible with GSSAPI on Unix. + */ +typedef struct { + void* value; + int length; +} gss_buffer_desc; +#endif +#endif /* ENABLE_SSPI */ + +#ifdef USE_SSL +#include "openssl/ossl_typ.h" +#endif /* USE_SSL */ + +#ifdef HAVE_CE +#include "cl_state.h" +#endif + +/* + * POSTGRES backend dependent Constants. + */ +#define CMDSTATUS_LEN 64 /* should match COMPLETION_TAG_BUFSIZE */ +#define MAX_ERRMSG_LENGTH 1024 + +/* + * PGresult and the subsidiary types PGresAttDesc, PGresAttValue + * represent the result of a query (or more precisely, of a single SQL + * command --- a query string given to PQexec can contain multiple commands). + * Note we assume that a single command can return at most one tuple group, + * hence there is no need for multiple descriptor sets. + */ + +/* Subsidiary-storage management structure for PGresult. + * See space management routines in fe-exec.c for details. + * Note that space[k] refers to the k'th byte starting from the physical + * head of the block --- it's a union, not a struct! + */ +typedef union pgresult_data PGresult_data; + +union pgresult_data { + PGresult_data* next; /* link to next block, or NULL */ + char space[1]; /* dummy for accessing block as bytes */ +}; + +/* Data about a single parameter of a prepared statement */ +typedef struct pgresParamDesc { + Oid typid; /* type id */ +} PGresParamDesc; + +/* + * Data for a single attribute of a single tuple + * + * We use char* for Attribute values. + * + * The value pointer always points to a null-terminated area; we add a + * null (zero) byte after whatever the backend sends us. This is only + * particularly useful for text values ... with a binary value, the + * value might have embedded nulls, so the application can't use C string + * operators on it. But we add a null anyway for consistency. + * Note that the value itself does not contain a length word. + * + * A NULL attribute is a special case in two ways: its len field is NULL_LEN + * and its value field points to null_field in the owning PGresult. All the + * NULL attributes in a query result point to the same place (there's no need + * to store a null string separately for each one). + */ +#define NULL_LEN (-1) /* pg_result len for NULL value */ + +typedef struct pgresAttValue { + int len; /* length in bytes of the value */ + char* value; /* actual value, plus terminating zero byte */ +} PGresAttValue; + +/* Typedef for message-field list entries */ +typedef struct pgMessageField { + struct pgMessageField* next; /* list link */ + char code; /* field code */ + char contents[1]; /* field value (VARIABLE LENGTH) */ +} PGMessageField; + +/* Fields needed for notice handling */ +typedef struct { + PQnoticeReceiver noticeRec; /* notice message receiver */ + void* noticeRecArg; + PQnoticeProcessor noticeProc; /* notice message processor */ + void* noticeProcArg; +} PGNoticeHooks; + +typedef struct PGEvent { + PGEventProc proc; /* the function to call on events */ + char* name; /* used only for error messages */ + void* passThrough; /* pointer supplied at registration time */ + void* data; /* optional state (instance) data */ + bool resultInitialized; /* T if RESULTCREATE/COPY succeeded */ +} PGEvent; + +struct pg_result { + int ntups; + int numAttributes; + PGresAttDesc* attDescs; + PGresAttValue** tuples; /* each PGresTuple is an array of + * PGresAttValue's */ + int tupArrSize; /* allocated size of tuples array */ + int numParameters; + PGresParamDesc* paramDescs; + ExecStatusType resultStatus; + char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the query */ + int binary; /* binary tuple values if binary == 1, + * otherwise text */ + + /* + * These fields are copied from the originating PGconn, so that operations + * on the PGresult don't have to reference the PGconn. + */ + PGNoticeHooks noticeHooks; + PGEvent* events; + int nEvents; + int client_encoding; /* encoding id */ + + /* + * Error information (all NULL if not an error result). errMsg is the + * "overall" error message returned by PQresultErrorMessage. If we have + * per-field info then it is stored in a linked list. + */ + char* errMsg; /* error message, or NULL if no error */ + PGMessageField* errFields; /* message broken into fields */ + + /* All NULL attributes in the query result point to this null string */ + char null_field[1]; + + /* + * Space management information. Note that attDescs and error stuff, if + * not null, point into allocated blocks. But tuples points to a + * separately malloc'd block, so that we can realloc it. + */ + PGresult_data* curBlock; /* most recently allocated block */ + int curOffset; /* start offset of free space in block */ + int spaceLeft; /* number of free bytes remaining in block */ +}; + +/* PGAsyncStatusType defines the state of the query-execution state machine */ +typedef enum { + PGASYNC_IDLE, /* nothing's happening, dude */ + PGASYNC_BUSY, /* query in progress */ + PGASYNC_READY, /* result ready for PQgetResult */ + PGASYNC_COPY_IN, /* Copy In data transfer in progress */ + PGASYNC_COPY_OUT, /* Copy Out data transfer in progress */ + PGASYNC_COPY_BOTH /* Copy In/Out data transfer in progress */ +} PGAsyncStatusType; + +/* PGQueryClass tracks which query protocol we are now executing */ +typedef enum { + PGQUERY_SIMPLE, /* simple Query protocol (PQexec) */ + PGQUERY_EXTENDED, /* full Extended protocol (PQexecParams) */ + PGQUERY_PREPARE, /* Parse only (PQprepare) */ + PGQUERY_DESCRIBE /* Describe Statement or Portal */ +} PGQueryClass; + +/* PGSetenvStatusType defines the state of the PQSetenv state machine */ +/* (this is used only for 2.0-protocol connections) */ +typedef enum { + SETENV_STATE_CLIENT_ENCODING_SEND, /* About to send an Environment Option */ + SETENV_STATE_CLIENT_ENCODING_WAIT, /* Waiting for above send to complete */ + SETENV_STATE_OPTION_SEND, /* About to send an Environment Option */ + SETENV_STATE_OPTION_WAIT, /* Waiting for above send to complete */ + SETENV_STATE_QUERY1_SEND, /* About to send a status query */ + SETENV_STATE_QUERY1_WAIT, /* Waiting for query to complete */ + SETENV_STATE_QUERY2_SEND, /* About to send a status query */ + SETENV_STATE_QUERY2_WAIT, /* Waiting for query to complete */ + SETENV_STATE_IDLE +} PGSetenvStatusType; + +/* Typedef for the EnvironmentOptions[] array */ +typedef struct PQEnvironmentOption { + const char *envName, /* name of an environment variable */ + *pgName; /* name of corresponding SET variable */ +} PQEnvironmentOption; + +/* Typedef for parameter-status list entries */ +typedef struct pgParameterStatus { + struct pgParameterStatus* next; /* list link */ + char* name; /* parameter name */ + char* value; /* parameter value */ + /* Note: name and value are stored in same malloc block as struct is */ +} pgParameterStatus; + +/* large-object-access data ... allocated only if large-object code is used. */ +typedef struct pgLobjfuncs { + Oid fn_lo_open; /* OID of backend function lo_open */ + Oid fn_lo_close; /* OID of backend function lo_close */ + Oid fn_lo_creat; /* OID of backend function lo_creat */ + Oid fn_lo_create; /* OID of backend function lo_create */ + Oid fn_lo_unlink; /* OID of backend function lo_unlink */ + Oid fn_lo_lseek; /* OID of backend function lo_lseek */ + Oid fn_lo_tell; /* OID of backend function lo_tell */ + Oid fn_lo_truncate; /* OID of backend function lo_truncate */ + Oid fn_lo_read; /* OID of backend function LOread */ + Oid fn_lo_write; /* OID of backend function LOwrite */ +} PGlobjfuncs; + +/* PGdataValue represents a data field value being passed to a row processor. + * It could be either text or binary data; text data is not zero-terminated. + * A SQL NULL is represented by len < 0; then value is still valid but there + * are no data bytes there. + */ +typedef struct pgDataValue { + int len; /* data length in bytes, or <0 if NULL */ + const char* value; /* data value, without zero-termination */ +} PGdataValue; + +/* + * PGconn stores all the state data associated with a single connection + * to a backend. + */ +struct pg_conn { + /* Saved values of connection options */ + char* pghost; /* the machine on which the server is running */ + char* pghostaddr; /* the numeric IP address of the machine on + * which the server is running. Takes + * precedence over above. */ + char* pgport; /* the server's communication port */ + char* pglocalhost; /* The localhost specified in one conenct channel */ + char* pglocalport; /* The localport specified in one conenct channel */ + char* pgunixsocket; /* the Unix-domain socket that the server is + * listening on; if NULL, uses a default + * constructed from pgport */ + char* pgtty; /* tty on which the backend messages is + * displayed (OBSOLETE, NOT USED) */ + char* connect_timeout; /* connection timeout (numeric string) */ + char* client_encoding_initial; /* encoding to use */ + char* pgoptions; /* options to start the backend with */ + char* appname; /* application name */ + char* fbappname; /* fallback application name */ + char* dbName; /* database name */ + char* replication; /* connect as the replication standby? */ + char* backend_version; /* backend version to be passed to the remote end */ + char* pguser; /* Postgres username and password, if any */ + char* pgpass; + char* keepalives; /* use TCP keepalives? */ + char* keepalives_idle; /* time between TCP keepalives */ + char* keepalives_interval; /* time between TCP keepalive + * retransmits */ + char* keepalives_count; /* maximum number of TCP keepalive + * retransmits */ + char* rw_timeout; /* read-write timeout during idle connection.*/ + char* sslmode; /* SSL mode (require,prefer,allow,disable) */ + char* sslcompression; /* SSL compression (0 or 1) */ + char* sslkey; /* client key filename */ + char* sslcert; /* client certificate filename */ + char* sslrootcert; /* root certificate filename */ + char* sslcrl; /* certificate revocation list filename */ + char* requirepeer; /* required peer credentials for local sockets */ + unsigned char cipher_passwd[CIPHER_LEN + 1]; + +#if defined(KRB5) || defined(ENABLE_GSS) || defined(ENABLE_SSPI) + char* krbsrvname; /* Kerberos service name */ +#endif + + /* Optional file to write trace info to */ + FILE* Pfdebug; + + /* Callback procedures for notice message processing */ + PGNoticeHooks noticeHooks; + + /* Event procs registered via PQregisterEventProc */ + PGEvent* events; /* expandable array of event data */ + int nEvents; /* number of active events */ + int eventArraySize; /* allocated array size */ + + /* Status indicators */ + ConnStatusType status; + PGAsyncStatusType asyncStatus; + PGTransactionStatusType xactStatus; /* never changes to ACTIVE */ + PGQueryClass queryclass; + char* last_query; /* last SQL command, or NULL if unknown */ + char last_sqlstate[6]; /* last reported SQLSTATE */ + bool options_valid; /* true if OK to attempt connection */ + bool nonblocking; /* whether this connection is using nonblock + * sending semantics */ + bool singleRowMode; /* return current query result row-by-row? */ + char copy_is_binary; /* 1 = copy binary, 0 = copy text */ + int copy_already_done; /* # bytes already returned in COPY + * OUT */ + PGnotify* notifyHead; /* oldest unreported Notify msg */ + PGnotify* notifyTail; /* newest unreported Notify msg */ + + /* Connection data */ + int sock; /* Unix FD for socket, -1 if not connected */ + SockAddr laddr; /* Local address */ + SockAddr raddr; /* Remote address */ + char *remote_nodename; /* remote datanode name */ + ProtocolVersion pversion; /* FE/BE protocol version in use */ + int sversion; /* server version, e.g. 70401 for 7.4.1 */ + bool auth_req_received; /* true if any type of auth req + * received */ + bool password_needed; /* true if server demanded a password */ + bool dot_pgpass_used; /* true if used .pgpass */ + bool sigpipe_so; /* have we masked SIGPIPE via SO_NOSIGPIPE? */ + bool sigpipe_flag; /* can we mask SIGPIPE via MSG_NOSIGNAL? */ + + /* Transient state needed while establishing connection */ + struct addrinfo* addrlist; /* list of possible backend addresses */ + struct addrinfo* addr_cur; /* the one currently being tried */ + int addrlist_family; /* needed to know how to free addrlist */ + PGSetenvStatusType setenv_state; /* for 2.0 protocol only */ + const PQEnvironmentOption* next_eo; + bool send_appname; /* okay to send application_name? */ + + /* Miscellaneous stuff */ + ThreadId be_pid; /* PID of backend --- needed for cancels */ + ThreadId remote_pid; /* remote pid */ + int be_key; /* key of backend --- needed for cancels */ + char md5Salt[4]; /* password salt received from backend */ + /*password stored method on server : md5, sha256 or plain*/ + int32 password_stored_method; + pgParameterStatus* pstatus; /* ParameterStatus data */ + int client_encoding; /* encoding id */ + bool std_strings; /* standard_conforming_strings */ + PGVerbosity verbosity; /* error/notice message verbosity */ + PGlobjfuncs* lobjfuncs; /* private state for large-object access fns */ + + /* Buffer for data received from backend and not yet processed */ + char* inBuffer; /* currently allocated buffer */ + int inBufSize; /* allocated size of buffer */ + int inStart; /* offset to first unconsumed data in buffer */ + int inCursor; /* next byte to tentatively consume */ + int inEnd; /* offset to first position after avail data */ + + /* Buffer for data not yet sent to backend */ + char* outBuffer; /* currently allocated buffer */ + int outBufSize; /* allocated size of buffer */ + int outCount; /* number of chars waiting in buffer */ + + /* State for constructing messages in outBuffer */ + int outMsgStart; /* offset to msg start (length word); if -1, + * msg has no length word */ + int outMsgEnd; /* offset to msg end (so far) */ + + /* Row processor interface workspace */ + PGdataValue* rowBuf; /* array for passing values to rowProcessor */ + int rowBufLen; /* number of entries allocated in rowBuf */ + + /* Status for asynchronous result construction */ + PGresult* result; /* result being constructed */ + PGresult* next_result; /* next result (used in single-row mode) */ + + /* Assorted state for SSL, GSS, etc */ +#ifdef USE_SSL + bool allow_ssl_try; /* Allowed to try SSL negotiation */ + bool wait_ssl_try; /* Delay SSL negotiation until after + * attempting normal connection */ + + SSL* ssl; /* SSL status, if have SSL connection */ + X509* peer; /* X509 cert of server */ +#endif /* USE_SSL */ + +#ifdef ENABLE_GSS + gss_ctx_id_t gctx; /* GSS context */ + gss_name_t gtarg_nam; /* GSS target name */ + gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc goutbuf; /* GSS output token */ +#endif + +#ifdef ENABLE_SSPI +#ifndef ENABLE_GSS + gss_buffer_desc ginbuf; /* GSS input token */ +#else + char* gsslib; /* What GSS librart to use ("gssapi" or + * "sspi") */ +#endif + CredHandle* sspicred; /* SSPI credentials handle */ + CtxtHandle* sspictx; /* SSPI context */ + char* sspitarget; /* SSPI target name */ + int usesspi; /* Indicate if SSPI is in use on the + * connection */ +#endif + + /* Buffer for current error message */ + PQExpBufferData errorMessage; /* expansible string */ + + /* Buffer for receiving various parts of messages */ + PQExpBufferData workBuffer; /* expansible string */ + /* begin RFC 5802 */ + char sever_signature[STORED_KEY_LENGTH * 2 + 1]; + char salt[SALT_LENGTH * 2 + 1]; + char token[TOKEN_LENGTH * 2 + 1]; + /* end RFC 5802 */ + + /* Stored the encrypted password and clientkey for gsql parallel execute. */ + char encrypted_passwd[SHA256_PASSWD_LEN + CLIENT_KEY_STRING_LENGTH + 1]; + + /* fenced udf RPC use unix domain socket and special socket file name */ + bool fencedUdfRPCMode; + /* Support adjust iteration to adapt the hardware development for safe reason. */ + int iteration_count; + /* flag to identify the logic connection between cn and dn */ + bool is_logic_conn; + /* logic connection address between cn and dn */ + libcommaddrinfo libcomm_addrinfo; + /* Connection_info is a json string containing driver_name, driver_version, driver_path and os_user. + * If connection_info is not NULL, use connection_info and ignore the value of connection_extra_info. + * If connection_info is NULL: + * generate connection_info strings related to libpq. + * connection_info has only driver_name and driver_version while connection_extra_info is false. + */ + char* connection_info; + bool connection_extra_info; + +#ifdef HAVE_CE + PGClientLogic* client_logic; +#endif +}; + +/* PGcancel stores all data necessary to cancel a connection. A copy of this + * data is required to safely cancel a connection running on a different + * thread. + */ +struct pg_cancel { + SockAddr raddr; /* Remote address */ + ThreadId be_pid; /* PID of backend --- needed for cancels */ + int be_key; /* key of backend --- needed for cancels */ +}; + +/* String descriptions of the ExecStatusTypes. + * direct use of this array is deprecated; call PQresStatus() instead. + */ +extern char* const pgresStatus[]; + +/* ---------------- + * Internal functions of libpq + * Functions declared here need to be visible across files of libpq, + * but are not intended to be called by applications. We use the + * convention "pqXXX" for internal functions, vs. the "PQxxx" names + * used for application-visible routines. + * ---------------- + */ + +/* === in fe-connect.c === */ +extern THR_LOCAL bool g_pq_interrupt_happened; +extern int pqPacketSend(PGconn* conn, char pack_type, const void* buf, size_t buf_len); +extern bool pqGetHomeDirectory(char* buf, int bufsize); + +#define PGTHREAD_ERROR(msg) \ + do { \ + fprintf(stderr, "%s\n", msg); \ + abort(); \ + } while (0) + +#ifdef ENABLE_THREAD_SAFETY +extern pgthreadlock_t pg_g_threadlock; + +#define pglock_thread() pg_g_threadlock(true) +#define pgunlock_thread() pg_g_threadlock(false) +#else +#define pglock_thread() ((void)0) +#define pgunlock_thread() ((void)0) +#endif + +/* === in fe-exec.c === */ + +extern void pqSetResultError(PGresult* res, const char* msg); +extern void pqCatenateResultError(PGresult* res, const char* msg); +extern void* pqResultAlloc(PGresult* res, size_t nBytes, bool isBinary); +extern char* pqResultStrdup(PGresult* res, const char* str); +extern void pqClearAsyncResult(PGconn* conn); +extern void pqSaveErrorResult(PGconn* conn); +extern PGresult* pqPrepareAsyncResult(PGconn* conn); +extern void pqInternalNotice(const PGNoticeHooks* hooks, const char* fmt, ...) + /* This lets gcc check the format string for consistency. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); +extern void pqSaveMessageField(PGresult* res, char code, const char* value, PGconn* conn = NULL); +extern void pqSaveParameterStatus(PGconn* conn, const char* name, const char* value); +extern int pqRowProcessor(PGconn* conn, const char** errmsgp); +extern void pqHandleSendFailure(PGconn* conn); + +/* === in fe-protocol2.c === */ + +extern PostgresPollingStatusType pqSetenvPoll(PGconn* conn); + +extern char* pqBuildStartupPacket2(PGconn* conn, int* packetlen, const PQEnvironmentOption* options); +extern void pqParseInput2(PGconn* conn); +extern int pqGetCopyData2(PGconn* conn, char** buffer, int async); +extern int pqGetline2(PGconn* conn, char* s, int maxlen); +extern int pqGetlineAsync2(PGconn* conn, char* buffer, int bufsize); +extern int pqEndcopy2(PGconn* conn); +extern PGresult* pqFunctionCall2(PGconn* conn, Oid fnid, int* result_buf, int* actual_result_len, int result_is_int, + const PQArgBlock* args, int nargs); + +/* === in fe-protocol3.c === */ + +extern char* pqBuildStartupPacket3(PGconn* conn, int* packetlen, const PQEnvironmentOption* options); +extern void pqParseInput3(PGconn* conn); +extern int pqGetErrorNotice3(PGconn* conn, bool isError); +extern int pqGetCopyData3(PGconn* conn, char** buffer, int async); +extern int pqGetline3(PGconn* conn, char* s, int maxlen); +extern int pqGetlineAsync3(PGconn* conn, char* buffer, int bufsize); +extern int pqEndcopy3(PGconn* conn); +extern PGresult* pqFunctionCall3(PGconn* conn, Oid fnid, int* result_buf, int* actual_result_len, int result_is_int, + const PQArgBlock* args, int nargs); + +/* === in fe-misc.c === */ + +/* + * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for + * Get, EOF merely means the buffer is exhausted, not that there is + * necessarily any error. + */ +extern int pqCheckOutBufferSpace(size_t bytes_needed, PGconn* conn); +extern int pqCheckInBufferSpace(size_t bytes_needed, PGconn* conn); +extern int pqGetc(char* result, PGconn* conn); +extern int pqPutc(char c, PGconn* conn); +extern int pqGets(PQExpBuffer buf, PGconn* conn); +extern int pqGets_append(PQExpBuffer buf, PGconn* conn); +extern int pqPuts(const char* s, PGconn* conn); +extern int pqGetnchar(char* s, size_t len, PGconn* conn); +extern int pqSkipnchar(size_t len, PGconn* conn); +extern int pqPutnchar(const char* s, size_t len, PGconn* conn); +extern int pqGetInt(int* result, size_t bytes, PGconn* conn); +extern int64 pqGetInt64(int64 *result, PGconn *conn); +extern int pqPutInt(int value, size_t bytes, PGconn* conn); +extern int pqPutMsgStart(char msg_type, bool force_len, PGconn* conn); +extern int pqPutMsgEnd(PGconn* conn); +extern int pqReadData(PGconn* conn); +extern int pqFlush(PGconn* conn); +extern int pqWait(int forRead, int forWrite, PGconn* conn); +extern int pqWaitTimed(int forRead, int forWrite, PGconn* conn, time_t finish_time); +extern int pqReadReady(PGconn* conn); +extern int pqWriteReady(PGconn* conn); + +/* === in fe-secure.c === */ + +extern int pqsecure_initialize(PGconn*); +extern void pqsecure_destroy(void); +extern PostgresPollingStatusType pqsecure_open_client(PGconn*); +extern void pqsecure_close(PGconn*); +extern ssize_t pqsecure_read(PGconn*, void* ptr, size_t len); +extern ssize_t pqsecure_write(PGconn*, const void* ptr, size_t len); +extern ssize_t pgfdw_pqsecure_read(PGconn*, void* ptr, size_t len); +extern ssize_t pgfdw_pqsecure_write(PGconn*, const void* ptr, size_t len); + +#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) +extern int pq_block_sigpipe(sigset_t* osigset, bool* sigpipe_pending); +extern void pq_reset_sigpipe(sigset_t* osigset, bool sigpipe_pending, bool got_epipe); +#endif + +/* + * this is so that we can check if a connection is non-blocking internally + * without the overhead of a function call + */ +#define pqIsnonblocking(conn) ((conn)->nonblocking) + +#ifdef ENABLE_NLS +extern char* libpq_gettext(const char* msgid) __attribute__((format_arg(1))); +#else +#define libpq_gettext(x) (x) +#endif + +/* + * These macros are needed to let error-handling code be portable between + * Unix and Windows. (ugh) + */ +#ifdef WIN32 +#define SOCK_ERRNO (WSAGetLastError()) +#define SOCK_STRERROR winsock_strerror +#define SOCK_ERRNO_SET(e) WSASetLastError(e) +#else +#define SOCK_ERRNO errno +#define SOCK_STRERROR pqStrerror +#define SOCK_ERRNO_SET(e) (errno = (e)) +#endif + +/* erase the memory pointed by p, with sz bytes */ +#define erase_mem(p, sz) memset((p), 0, (sz)) + +/* Erase the memory of array spcecified by arr */ +#define erase_arr(arr) erase_mem((arr), sizeof(arr)) + +/* Erase the memory of a string specified by s */ +#define erase_string(s) \ + do { \ + int l_to_erase = strlen(s); \ + erase_mem((s), l_to_erase); \ + } while (0) + +#define check_memcpy_s(r) securec_check_c((r), "", "") +#define check_memmove_s(r) securec_check_c((r), "", "") +#define check_memset_s(r) securec_check_c((r), "", "") +#define check_strcpy_s(r) securec_check_c((r), "", "") +#define check_strncpy_s(r) securec_check_c((r), "", "") +#define check_strcat_s(r) securec_check_c((r), "", "") +#define check_strncat_s(r) securec_check_c((r), "", "") +#define check_gets_s(r) securec_check_ss_c((r), "", "") +#define check_sprintf_s(r) securec_check_ss_c((r), "", "") +#define check_snprintf_s(r) securec_check_ss_c((r), "", "") +#define check_scanf_s(r) securec_check_ss_c((r), "", "") + +extern void* libpq_realloc(void* src, size_t old_len, size_t new_len); + +#endif /* LIBPQ_INT_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/md5.h postgresql-hll-2.14/include/libpq/md5.h --- postgresql-hll-2.14_old/include/libpq/md5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/md5.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * md5.h + * Interface to libpq/md5.c + * + * These definitions are needed by both frontend and backend code to work + * with MD5-encrypted passwords. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/md5.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_MD5_H +#define PG_MD5_H + +#define MD5_PASSWD_CHARSET "0123456789abcdef" +#define MD5_PASSWD_LEN 35 + +#define isMD5(passwd) \ + ((strncmp(passwd, "md5", 3) == 0) && (strlen(passwd) == MD5_PASSWD_LEN) && \ + (strspn(passwd + 3, MD5_PASSWD_CHARSET) == MD5_PASSWD_LEN - 3)) + +extern bool pg_md5_hash(const void* buff, size_t len, char* hexsum); +extern bool pg_md5_binary(const void* buff, size_t len, void* outbuf); +extern bool pg_md5_encrypt(const char* passwd, const char* salt, size_t salt_len, char* buf); + +#endif diff -uprN postgresql-hll-2.14_old/include/libpq/pqcomm.h postgresql-hll-2.14/include/libpq/pqcomm.h --- postgresql-hll-2.14_old/include/libpq/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/pqcomm.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqcomm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQCOMM_H +#define PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE + +#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY +#define ss_family __ss_family +#else +#error struct sockaddr_storage does not provide an ss_family member +#endif +#endif + +#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN +#define ss_len __ss_len +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1 +#endif +#else /* !HAVE_STRUCT_SOCKADDR_STORAGE */ + +/* Define a struct sockaddr_storage if we don't have one. */ +struct sockaddr_storage { + union { + struct sockaddr sa; /* get the system-dependent fields */ + int64 ss_align; /* ensures struct is properly aligned */ + char ss_pad[128]; /* ensures struct has desired size */ + } ss_stuff; +}; + +#define ss_family ss_stuff.sa.sa_family +/* It should have an ss_len field if sockaddr has sa_len. */ +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN +#define ss_len ss_stuff.sa.sa_len +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1 +#endif +#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */ + +typedef struct { + struct sockaddr_storage addr; + ACCEPT_TYPE_ARG3 salen; +} SockAddr; + +extern const char* check_client_env(const char* input_env_value); +/* Configure the UNIX socket location for the well known port. */ +#define UNIXSOCK_PATH(path, port, sockdir) \ + do { \ + int rc = 0; \ + const char* unixSocketDir = NULL; \ + const char* pghost = gs_getenv_r("PGHOST"); \ + if (check_client_env(pghost) == NULL) { \ + pghost = NULL; \ + } \ + if (sockdir != NULL && (*sockdir) != '\0') { \ + unixSocketDir = sockdir; \ + } else { \ + if (pghost != NULL && (*pghost) != '\0') { \ + unixSocketDir = pghost; \ + } else { \ + unixSocketDir = DEFAULT_PGSOCKET_DIR; \ + } \ + } \ + rc = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/.s.PGSQL.%d", unixSocketDir, (port)); \ + securec_check_ss_c(rc, "\0", "\0"); \ + } while (0) + +#define UNIXSOCK_FENCED_MASTER_PATH(path, sockdir) \ + do { \ + int rc = 0; \ + const char* unixSocketDir = NULL; \ + const char* pghost = gs_getenv_r("PGHOST"); \ + if (check_client_env(pghost) == NULL) { \ + pghost = NULL; \ + } \ + if (sockdir != NULL && (*sockdir) != '\0') { \ + unixSocketDir = sockdir; \ + } else { \ + if (pghost != NULL && (*pghost) != '\0') { \ + unixSocketDir = pghost; \ + } else { \ + unixSocketDir = DEFAULT_PGSOCKET_DIR; \ + } \ + } \ + rc = snprintf_s(path, sizeof(path), sizeof(path) - 1, "%s/.s.fencedMaster_unixdomain", unixSocketDir); \ + securec_check_ss_c(rc, "\0", "\0"); \ + } while (0) + +/* + * The maximum workable length of a socket path is what will fit into + * struct sockaddr_un. This is usually only 100 or so bytes :-(. + * + * For consistency, always pass a MAXPGPATH-sized buffer to UNIXSOCK_PATH(), + * then complain if the resulting string is >= UNIXSOCK_PATH_BUFLEN bytes. + * (Because the standard API for getaddrinfo doesn't allow it to complain in + * a useful way when the socket pathname is too long, we have to test for + * this explicitly, instead of just letting the subroutine return an error.) + */ +#define UNIXSOCK_PATH_BUFLEN sizeof(((struct sockaddr_un*)NULL)->sun_path) + +/* + * These manipulate the frontend/backend protocol version number. + * + * The major number should be incremented for incompatible changes. The minor + * number should be incremented for compatible changes (eg. additional + * functionality). + * + * If a backend supports version m.n of the protocol it must actually support + * versions m.[0..n]. Backend support for version m-1 can be dropped after a + * `reasonable' length of time. + * + * A frontend isn't required to support anything other than the current + * version. + */ + +#define PG_PROTOCOL_MAJOR(v) ((v) >> 16) +#define PG_PROTOCOL_MINOR(v) ((v)&0x0000ffff) +#define PG_PROTOCOL(m, n) (((m) << 16) | (n)) + +/* The protocol versions server supported */ +extern const unsigned short protoVersionList[][2]; + +/* The earliest and latest frontend/backend protocol version supported. */ +#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1, 0) +#define PG_PROTOCOL_LATEST PG_PROTOCOL(3, 51) +#define PG_PROTOCOL_GAUSS_BASE 50 + +typedef uint32 ProtocolVersion; /* FE/BE protocol version number */ + +typedef ProtocolVersion MsgType; + +/* + * Packet lengths are 4 bytes in network byte order. + * + * The initial length is omitted from the packet layouts appearing below. + */ + +typedef uint32 PacketLen; + +/* + * Old-style startup packet layout with fixed-width fields. This is used in + * protocol 1.0 and 2.0, but not in later versions. Note that the fields + * in this layout are '\0' terminated only if there is room. + */ + +#define SM_DATABASE 64 +#define SM_USER 32 +#define SM_OPTIONS 64 +#define SM_UNUSED 64 +#define SM_TTY 64 + +typedef struct StartupPacket { + ProtocolVersion protoVersion; /* Protocol version */ + char database[SM_DATABASE]; /* Database name */ + char user[SM_USER]; /* User name */ + char options[SM_OPTIONS]; /* Optional additional args */ + char unused[SM_UNUSED]; /* Unused */ + char tty[SM_TTY]; /* Tty for debug output */ +} StartupPacket; + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +/* These are the authentication request codes sent by the backend. */ +#define AUTH_REQ_OK 0 /* User is authenticated */ +#define AUTH_REQ_KRB4 1 /* Kerberos V4. Not supported any more. */ +#define AUTH_REQ_KRB5 2 /* Kerberos V5 */ +#define AUTH_REQ_PASSWORD 3 /* Password */ +#define AUTH_REQ_CRYPT 4 /* crypt password. Not supported any more. */ +#define AUTH_REQ_MD5 5 /* md5 password */ +#define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */ +#define AUTH_REQ_GSS 7 /* GSSAPI without wrap() */ +#define AUTH_REQ_GSS_CONT 8 /* Continue GSS exchanges */ +#define AUTH_REQ_SSPI 9 /* SSPI negotiate without wrap() */ + +#define AUTH_REQ_SHA256 10 /* sha256 password */ +#define AUTH_REQ_MD5_SHA256 11 /* md5_auth_sha256_stored password */ +#define AUTH_REQ_IAM 12 /* iam token authenication */ + +typedef uint32 AuthRequest; + +/* + * A client can also send a cancel-current-operation request to the postmaster. + * This is uglier than sending it directly to the client's backend, but it + * avoids depending on out-of-band communication facilities. + * + * The cancel request code must not match any protocol version number + * we're ever likely to use. This random choice should do. + */ +#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234, 5678) + +typedef struct CancelRequestPacket { + /* Note that each field is stored in network byte order! */ + MsgType cancelRequestCode; /* code to identify a cancel request */ + uint32 backendPID; /* PID of client's backend */ + uint32 cancelAuthCode; /* secret key to authorize cancel */ +} CancelRequestPacket; + +/* + * A client can also start by sending a SSL negotiation request, to get a + * secure channel. + */ +#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234, 5679) + +/* + * A client can also start by sending stop query request + */ +#define STOP_REQUEST_CODE PG_PROTOCOL(1234, 5681) +typedef struct StopRequestPacket { + /* Note that each field is stored in network byte order! */ + MsgType stopRequestCode; /* code to identify a stop request */ + uint32 backendPID; /* PID of client's backend */ + uint32 query_id_first; /* query id of front 4 bytes */ + uint32 query_id_end; /* query id of back 4 bytes */ +} StopRequestPacket; + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/pqexpbuffer.h postgresql-hll-2.14/include/libpq/pqexpbuffer.h --- postgresql-hll-2.14_old/include/libpq/pqexpbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/pqexpbuffer.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,199 @@ +/* --------------------------------------------------------------------------------------- + * + * pqexpbuffer.h + * Declarations/definitions for "PQExpBuffer" functions. + * + * PQExpBuffer provides an indefinitely-extensible string data type. + * It can be used to buffer either ordinary C strings (null-terminated text) + * or arbitrary binary data. All storage is allocated with malloc(). + * + * This module is essentially the same as the backend's StringInfo data type, + * but it is intended for use in frontend libpq and client applications. + * Thus, it does not rely on palloc() nor elog(). + * + * It does rely on vsnprintf(); if configure finds that libc doesn't provide + * a usable vsnprintf(), then a copy of our own implementation of it will + * be linked into libpq. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/libpq/pqexpbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PQEXPBUFFER_H +#define PQEXPBUFFER_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PG_PRINTF_ATTRIBUTE +#ifdef WIN32 +#define PG_PRINTF_ATTRIBUTE gnu_printf +#else +#define PG_PRINTF_ATTRIBUTE printf +#endif +#endif + +/*------------------------- + * PQExpBufferData holds information about an extensible string. + * data is the current buffer for the string (allocated with malloc). + * len is the current string length. There is guaranteed to be + * a terminating '\0' at data[len], although this is not very + * useful when the string holds binary data rather than text. + * maxlen is the allocated size in bytes of 'data', i.e. the maximum + * string size (including the terminating '\0' char) that we can + * currently store in 'data' without having to reallocate + * more space. We must always have maxlen > len. + * + * An exception occurs if we failed to allocate enough memory for the string + * buffer. In that case data points to a statically allocated empty string, + * and len = maxlen = 0. + * ------------------------- + */ +typedef struct PQExpBufferData { + char* data; + size_t len; + size_t maxlen; +} PQExpBufferData; + +typedef PQExpBufferData* PQExpBuffer; + +/*------------------------ + * Test for a broken (out of memory) PQExpBuffer. + * When a buffer is "broken", all operations except resetting or deleting it + * are no-ops. + * ------------------------ + */ +#define PQExpBufferBroken(str) ((str) == NULL || (str)->maxlen == 0) + +/*------------------------ + * Same, but for use when using a static or local PQExpBufferData struct. + * For that, a null-pointer test is useless and may draw compiler warnings. + * ------------------------ + */ +#define PQExpBufferDataBroken(buf) ((buf).maxlen == 0) + +/*------------------------ + * Initial size of the data buffer in a PQExpBuffer. + * NB: this must be large enough to hold error messages that might + * be returned by PQrequestCancel(). + * ------------------------ + */ +#define INITIAL_EXPBUFFER_SIZE 256 + +/*------------------------ + * There are two ways to create a PQExpBuffer object initially: + * + * PQExpBuffer stringptr = createPQExpBuffer(); + * Both the PQExpBufferData and the data buffer are malloc'd. + * + * PQExpBufferData string; + * initPQExpBuffer(&string); + * The data buffer is malloc'd but the PQExpBufferData is presupplied. + * This is appropriate if the PQExpBufferData is a field of another + * struct. + * ------------------------- + */ + +/*------------------------ + * createPQExpBuffer + * Create an empty 'PQExpBufferData' & return a pointer to it. + */ +extern PQExpBuffer createPQExpBuffer(void); + +/*------------------------ + * initPQExpBuffer + * Initialize a PQExpBufferData struct (with previously undefined contents) + * to describe an empty string. + */ +extern void initPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * To destroy a PQExpBuffer, use either: + * + * destroyPQExpBuffer(str); + * free()s both the data buffer and the PQExpBufferData. + * This is the inverse of createPQExpBuffer(). + * + * termPQExpBuffer(str) + * free()s the data buffer but not the PQExpBufferData itself. + * This is the inverse of initPQExpBuffer(). + * + * NOTE: some routines build up a string using PQExpBuffer, and then + * release the PQExpBufferData but return the data string itself to their + * caller. At that point the data string looks like a plain malloc'd + * string. + */ +extern void destroyPQExpBuffer(PQExpBuffer str); +extern void termPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * resetPQExpBuffer + * Reset a PQExpBuffer to empty + * + * Note: if possible, a "broken" PQExpBuffer is returned to normal. + */ +extern void resetPQExpBuffer(PQExpBuffer str); + +/*------------------------ + * enlargePQExpBuffer + * Make sure there is enough space for 'needed' more bytes in the buffer + * ('needed' does not include the terminating null). + * + * Returns 1 if OK, 0 if failed to enlarge buffer. (In the latter case + * the buffer is left in "broken" state.) + */ +extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed); + +/*------------------------ + * printfPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and insert it into str. More space is allocated to str if necessary. + * This is a convenience routine that does the same thing as + * resetPQExpBuffer() followed by appendPQExpBuffer(). + */ +extern void printfPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/*------------------------ + * appendPQExpBuffer + * Format text data under the control of fmt (an sprintf-like format string) + * and append it to whatever is already in str. More space is allocated + * to str if necessary. This is sort of like a combination of sprintf and + * strcat. + */ +extern void appendPQExpBuffer(PQExpBuffer str, const char* fmt, ...) + /* This extension allows gcc to check the format string */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/*------------------------ + * appendPQExpBufferStr + * Append the given string to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendPQExpBufferStr(PQExpBuffer str, const char* data); + +/*------------------------ + * appendPQExpBufferChar + * Append a single byte to str. + * Like appendPQExpBuffer(str, "%c", ch) but much faster. + */ +extern void appendPQExpBufferChar(PQExpBuffer str, char ch); + +/*------------------------ + * appendBinaryPQExpBuffer + * Append arbitrary binary data to a PQExpBuffer, allocating more space + * if necessary. + */ +extern void appendBinaryPQExpBuffer(PQExpBuffer str, const char* data, size_t datalen); + +#ifdef __cplusplus +} +#endif + +#endif /* PQEXPBUFFER_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/pqformat.h postgresql-hll-2.14/include/libpq/pqformat.h --- postgresql-hll-2.14_old/include/libpq/pqformat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/pqformat.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,210 @@ +/* ------------------------------------------------------------------------- + * + * pqformat.h + * Definitions for formatting and parsing frontend/backend messages + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqformat.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQFORMAT_H +#define PQFORMAT_H + +#include "lib/stringinfo.h" +#include "mb/pg_wchar.h" + +extern void pq_beginmessage(StringInfo buf, char msgtype); +extern void pq_beginmessage_reuse(StringInfo buf, char msgtype); +extern void pq_sendbytes(StringInfo buf, const char* data, int datalen); +extern void pq_sendcountedtext(StringInfo buf, const char* str, int slen, bool countincludesself); +extern void pq_sendtext(StringInfo buf, const char* str, int slen); +extern void pq_sendstring(StringInfo buf, const char* str); +extern void pq_send_ascii_string(StringInfo buf, const char* str); +extern void pq_sendfloat4(StringInfo buf, float4 f); +extern void pq_sendfloat8(StringInfo buf, float8 f); +extern void pq_endmessage(StringInfo buf); +extern void pq_endmessage_reuse(StringInfo buf); +extern void pq_endmessage_noblock(StringInfo buf); + +extern void pq_begintypsend(StringInfo buf); +extern bytea* pq_endtypsend(StringInfo buf); + +extern void pq_puttextmessage(char msgtype, const char* str); +extern void pq_puttextmessage_noblock(char msgtype, const char* str); +extern void pq_putemptymessage(char msgtype); +extern void pq_putemptymessage_noblock(char msgtype); + +extern int pq_getmsgbyte(StringInfo msg); +extern unsigned int pq_getmsgint(StringInfo msg, int b); +extern int64 pq_getmsgint64(StringInfo msg); +extern float4 pq_getmsgfloat4(StringInfo msg); +extern float8 pq_getmsgfloat8(StringInfo msg); +extern const char* pq_getmsgbytes(StringInfo msg, int datalen); +extern void pq_copymsgbytes(StringInfo msg, char* buf, int datalen); +extern char* pq_getmsgtext(StringInfo msg, int rawbytes, int* nbytes); +extern const char* pq_getmsgstring(StringInfo msg); +extern void pq_getmsgend(StringInfo msg); + +/* + * Append a [u]int8 to a StringInfo buffer, which already has enough space + * preallocated. + * + * The use of restrict allows the compiler to optimize the code based on the + * assumption that buf, buf->len, buf->data and *buf->data don't + * overlap. Without the annotation buf->len etc cannot be kept in a register + * over subsequent pq_writeintN calls. + * + * The use of StringInfoData * rather than StringInfo is due to MSVC being + * overly picky and demanding a * before a restrict. + */ +static inline void pq_writeint8(StringInfoData* pg_restrict buf, uint8 i) +{ + uint8 ni = i; + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint8), &ni, sizeof(uint8)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint8); +} + +/* + * Append a [u]int16 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint16(StringInfoData* pg_restrict buf, uint16 i) +{ + uint16 ni = htons(i); + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint16), &ni, sizeof(uint16)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint16); +} + +/* + * Append a [u]int32 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint32(StringInfoData* pg_restrict buf, uint32 i) +{ + uint32 ni = htonl(i); + errno_t rc = EOK; + + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &ni, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); +} + +/* + * Append a [u]int64 to a StringInfo buffer, which already has enough space + * preallocated. + */ +static inline void pq_writeint64(StringInfoData* pg_restrict buf, uint64 i) +{ + uint32 n32; + errno_t rc = EOK; + + /* High order half first, since we're doing MSB-first */ + n32 = (uint32)(i >> 32); + n32 = htonl(n32); + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &n32, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); + + /* Now the low order half */ + n32 = (uint32)i; + n32 = htonl(n32); + rc = memcpy_s((char* pg_restrict)(buf->data + buf->len), sizeof(uint32), &n32, sizeof(uint32)); + securec_check(rc, "\0", "\0"); + buf->len += sizeof(uint32); +} + +/* + * Append a null-terminated text string (with conversion) to a buffer with + * preallocated space. + * + * NB: The pre-allocated space needs to be sufficient for the string after + * converting to client encoding. + * + * NB: passed text string must be null-terminated, and so is the data + * sent to the frontend. + */ +static inline void pq_writestring(StringInfoData* pg_restrict buf, const char* pg_restrict str) +{ + int slen = strlen(str); + char* p = NULL; + errno_t rc = EOK; + + p = pg_server_to_client(str, slen); + if (p != str) /* actual conversion has been done? */ + slen = strlen(p); + + rc = memcpy_s(((char* pg_restrict)buf->data + buf->len), slen + 1, p, slen + 1); + securec_check(rc, "\0", "\0"); + buf->len += slen + 1; + + if (p != str) + pfree(p); +} + +/* append a binary [u]int8 to a StringInfo buffer */ +static inline void pq_sendint8(StringInfo buf, uint8 i) +{ + enlargeStringInfo(buf, sizeof(uint8)); + pq_writeint8(buf, i); +} + +/* append a binary [u]int16 to a StringInfo buffer */ +static inline void pq_sendint16(StringInfo buf, uint16 i) +{ + enlargeStringInfo(buf, sizeof(uint16)); + pq_writeint16(buf, i); +} + +/* append a binary [u]int32 to a StringInfo buffer */ +static inline void pq_sendint32(StringInfo buf, uint32 i) +{ + enlargeStringInfo(buf, sizeof(uint32)); + pq_writeint32(buf, i); +} + +/* append a binary [u]int64 to a StringInfo buffer */ +static inline void pq_sendint64(StringInfo buf, uint64 i) +{ + enlargeStringInfo(buf, sizeof(uint64)); + pq_writeint64(buf, i); +} + +/* append a binary byte to a StringInfo buffer */ +static inline void pq_sendbyte(StringInfo buf, uint8 byt) +{ + pq_sendint8(buf, byt); +} + +/* + * Append a binary integer to a StringInfo buffer + * + * This function is deprecated; prefer use of the functions above. + */ +static inline void pq_sendint(StringInfo buf, uint32 i, int b) +{ + switch (b) { + case 1: + pq_sendint8(buf, (uint8)i); + break; + case 2: + pq_sendint16(buf, (uint16)i); + break; + case 4: + pq_sendint32(buf, (uint32)i); + break; + default: + elog(ERROR, "unsupported integer size %d", b); + break; + } +} + +#endif /* PQFORMAT_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/pqsignal.h postgresql-hll-2.14/include/libpq/pqsignal.h --- postgresql-hll-2.14_old/include/libpq/pqsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/pqsignal.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * pqsignal.h + * prototypes for the reliable BSD-style signal(2) routine. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/libpq/pqsignal.h + * + * NOTES + * This shouldn't be in libpq, but the monitor and some other + * things need it... + * + * ------------------------------------------------------------------------- + */ +#ifndef PQSIGNAL_H +#define PQSIGNAL_H + +#include + +#ifdef HAVE_SIGPROCMASK +#define PG_SETMASK(mask) pthread_sigmask(SIG_SETMASK, mask, NULL) +#else /* not HAVE_SIGPROCMASK */ + +#ifndef WIN32 +#define PG_SETMASK(mask) sigsetmask(*((int*)(mask))) +#else +#define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask))) +int pqsigsetmask(int mask); +#endif + +#define sigaddset(set, signum) (*(set) |= (sigmask(signum))) +#define sigdelset(set, signum) (*(set) &= ~(sigmask(signum))) +#endif /* not HAVE_SIGPROCMASK */ + +typedef void (*pqsigfunc)(int); + +extern void pqinitmask(void); + +extern pqsigfunc pqsignal(int signo, pqsigfunc func); + +#endif /* PQSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/libpq/sha2.h postgresql-hll-2.14/include/libpq/sha2.h --- postgresql-hll-2.14_old/include/libpq/sha2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/libpq/sha2.h 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,115 @@ +/* contrib/pgcrypto/sha2.h */ +/* $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $ */ + +/* + * FILE: sha2.h + * AUTHOR: Aaron D. Gifford + * + * Copyright (c) 2000-2001, Aaron D. Gifford + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ + */ + +#ifndef _SHA2_H +#define _SHA2_H + +/* avoid conflict with OpenSSL */ +#define SHA256_Init2 gs_SHA256_Init +#define SHA256_Update2 gs_SHA256_Update +#define SHA256_Final2 gs_SHA256_Final + +/*** SHA-256 Various Length Definitions ***********************/ +#define SHA256_BLOCK_LENGTH 64 +#define SHA256_DIGEST_LENGTH 32 +#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) + +/*** SHA-256 Context Structures *******************************/ +#define K_LENGTH 32 +#define ITERATION_COUNT 10000 +#define CLIENT_STRING_LENGTH 11 +#define SEVER_STRING_LENGTH 10 +#define HMAC_LENGTH 32 +#define HMAC_BYTES_LENGTH 32 +#define HMAC_STRING_LENGTH (HMAC_LENGTH * 2) +#define STORED_KEY_LENGTH 32 +#define STORED_KEY_BYTES_LENGTH STORED_KEY_LENGTH +#define STORED_KEY_STRING_LENGTH (STORED_KEY_LENGTH * 2) +#define CLIENT_KEY_BYTES_LENGTH 32 +#define CLIENT_KEY_STRING_LENGTH (CLIENT_KEY_BYTES_LENGTH * 2) +#define SALT_LENGTH 32 +#define SALT_BYTE_LENGTH 32 +#define SALT_STRING_LENGTH (SALT_LENGTH * 2) +#define H_LENGTH 64 +#define ENCRYPTED_STRING_LENGTH (HMAC_STRING_LENGTH + STORED_KEY_STRING_LENGTH + SALT_STRING_LENGTH) +#define TOKEN_LENGTH 4 +#define SHA256_LENGTH 6 +#define SHA256_PASSWD_LEN (ENCRYPTED_STRING_LENGTH + SHA256_LENGTH) +#define SHA256_MD5_ENCRY_PASSWD_LEN 70 +#define ITERATION_STRING_LEN 11 /* The length of INT_MAX(2147483647) */ +#define SHA256_MD5_COMBINED_LEN (SHA256_PASSWD_LEN + MD5_PASSWD_LEN + ITERATION_STRING_LEN) + +#define isSHA256(passwd) \ + (strncmp(passwd, "sha256", SHA256_LENGTH) == 0 && strlen(passwd) == SHA256_PASSWD_LEN + ITERATION_STRING_LEN) + +/* Check combined password for compatible with PG. */ +#define isCOMBINED(passwd) \ + (strncmp(passwd, "sha256", SHA256_LENGTH) == 0 && strncmp(passwd + SHA256_PASSWD_LEN, "md5", 3) == 0) + +/* Check whether it is encrypted password. */ +#define isPWDENCRYPTED(passwd) (isMD5(passwd) || isSHA256(passwd) || isCOMBINED(passwd)) + +/* The current password stored method are sha256, md5 and combined. */ +#define PLAIN_PASSWORD 0 +#define MD5_PASSWORD 1 +#define SHA256_PASSWORD 2 +#define ERROR_PASSWORD 3 +#define BAD_MEM_ADDR 4 +#define COMBINED_PASSWORD 5 + +typedef struct _SHA256_CTX2 { + uint32 state[8]; + uint64 bitcount; + uint8 buffer[SHA256_BLOCK_LENGTH]; +} SHA256_CTX2; + +void SHA256_Init2(SHA256_CTX2*); +void SHA256_Update2(SHA256_CTX2*, const uint8*, size_t); +void SHA256_Final2(uint8[SHA256_DIGEST_LENGTH], SHA256_CTX2*); + +/* Use the old iteration ITERATION_COUNT as the default iteraion count. */ +extern bool pg_sha256_encrypt(const char* passwd, const char* salt_s, size_t salt_len, char* buf, char* client_key_buf, + int iteration_count = ITERATION_COUNT); +extern int XOR_between_password(const char* password1, const char* password2, char* r, int length); +extern void sha_hex_to_bytes32(char* s, const char b[64]); +extern void sha_hex_to_bytes4(char* s, const char b[8]); +extern void sha_bytes_to_hex8(uint8 b[4], char* s); +extern void sha_bytes_to_hex64(uint8 b[32], char* s); +extern bool pg_sha256_encrypt_for_md5(const char* passwd, const char* salt, size_t salt_len, char* buf); + +#endif /* _SHA2_H */ + diff -uprN postgresql-hll-2.14_old/include/Makefile postgresql-hll-2.14/include/Makefile --- postgresql-hll-2.14_old/include/Makefile 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/Makefile 2020-12-12 17:06:43.317348941 +0800 @@ -0,0 +1,111 @@ +#------------------------------------------------------------------------- +# +# Makefile for src/include +# +# 'make install' installs whole contents of src/include. +# +# src/include/Makefile +# +#------------------------------------------------------------------------- + +subdir = src/include +top_builddir = ../.. +include $(top_builddir)/src/Makefile.global + + +all: pg_config.h pg_config_os.h + + +# Subdirectories containing headers for server-side dev +SUBDIRS = bootstrap catalog commands client_logic datatype executor foreign gs_policy iprange lib libpq mb \ + nodes optimizer parser pgxc postmaster regex replication rewrite \ + tcop snowball snowball/libstemmer tsearch tsearch/dicts utils\ + port port/win32 port/win32_msvc port/win32_msvc/sys \ + port/win32/arpa port/win32/netinet port/win32/sys \ + portability \ + gtm \ + storage vecexecutor access tsdb streaming tsdb/utils access/obs \ + hotpatch\ + gstrace\ + knl knl/knl_guc threadpool workload\ +# Install all headers +install: all installdirs +# These headers are needed by the public headers of the interfaces. + $(INSTALL_DATA) $(srcdir)/postgres_ext.h '$(DESTDIR)$(includedir)' + $(INSTALL_DATA) $(srcdir)/libpq/libpq-fs.h '$(DESTDIR)$(includedir)/libpq' + $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir)' + $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir)' + $(INSTALL_DATA) $(srcdir)/pg_config_manual.h '$(DESTDIR)$(includedir)' +# These headers are needed by libpq. + $(INSTALL_DATA) gs_thread.h '$(DESTDIR)$(includedir)' + $(INSTALL_DATA) gs_threadlocal.h '$(DESTDIR)$(includedir)' +# These headers are needed by the not-so-public headers of the interfaces. + $(INSTALL_DATA) $(srcdir)/c.h '$(DESTDIR)$(includedir_internal)' + $(INSTALL_DATA) $(srcdir)/port.h '$(DESTDIR)$(includedir_internal)' + $(INSTALL_DATA) $(srcdir)/postgres_fe.h '$(DESTDIR)$(includedir_internal)' + $(INSTALL_DATA) $(srcdir)/libpq/pqcomm.h '$(DESTDIR)$(includedir_internal)/libpq' +# These headers are needed for server-side development + $(INSTALL_DATA) pg_config.h '$(DESTDIR)$(includedir_server)' + $(INSTALL_DATA) pg_config_os.h '$(DESTDIR)$(includedir_server)' + $(INSTALL_DATA) utils/errcodes.h '$(DESTDIR)$(includedir_server)/utils' + $(INSTALL_DATA) utils/fmgroids.h '$(DESTDIR)$(includedir_server)/utils' +# These headers are needed by madlib + $(INSTALL_DATA) $(with_3rd)/$(BINARYPATH)/cjson/comm/include/cjson/cJSON.h '$(DESTDIR)$(includedir_server)'/cjson/cJSON.h + $(INSTALL_DATA) $(with_3rd)/$(BINARYPATH)/libobs/comm/include/eSDKOBS.h '$(DESTDIR)$(includedir_server)'/access/obs/eSDKOBS.h + $(INSTALL_DATA) $(srcdir)/access/hash.inl '$(DESTDIR)$(includedir_server)'/access/hash.inl +# These headers are needed by fdw + $(INSTALL_DATA) gssignal/gs_signal.h '$(DESTDIR)$(includedir_server)/gssignal/gs_signal.h' + $(INSTALL_DATA) libcomm/libcomm.h '$(DESTDIR)$(includedir_server)/libcomm/libcomm.h' + $(INSTALL_DATA) cm/etcdapi.h '$(DESTDIR)$(includedir_server)/cm/etcdapi.h' + $(INSTALL_DATA) access/parallel_recovery/redo_item.h '$(DESTDIR)$(includedir_server)/access/parallel_recovery/redo_item.h' + $(INSTALL_DATA) access/parallel_recovery/posix_semaphore.h '$(DESTDIR)$(includedir_server)/access/parallel_recovery/posix_semaphore.h' + $(INSTALL_DATA) access/dfs/dfs_am.h '$(DESTDIR)$(includedir_server)/access/dfs/dfs_am.h' + $(INSTALL_DATA) alarm/alarm.h '$(DESTDIR)$(includedir_server)/alarm/alarm.h' + $(INSTALL_DATA) bulkload/dist_fdw.h '$(DESTDIR)$(includedir_server)/bulkload/dist_fdw.h' + $(INSTALL_DATA) bulkload/importerror.h '$(DESTDIR)$(includedir_server)/bulkload/importerror.h' + $(INSTALL_DATA) bulkload/utils.h '$(DESTDIR)$(includedir_server)/bulkload/utils.h' + $(INSTALL_DATA) ssl/gs_openssl_client.h '$(DESTDIR)$(includedir_server)/ssl/gs_openssl_client.h' + $(INSTALL_DATA) instruments/list.h '$(DESTDIR)$(includedir_server)/instruments/list.h' + $(INSTALL_DATA) instruments/instr_event.h '$(DESTDIR)$(includedir_server)/instruments/instr_event.h' + $(INSTALL_DATA) storage/dfs/dfs_connector.h '$(DESTDIR)$(includedir_server)/storage/dfs/dfs_connector.h' + $(INSTALL_DATA) distributelayer/streamConsumer.h '$(DESTDIR)$(includedir_server)/distributelayer/streamConsumer.h' + $(INSTALL_DATA) distributelayer/streamCore.h '$(DESTDIR)$(includedir_server)/distributelayer/streamCore.h' + $(INSTALL_DATA) distributelayer/streamProducer.h '$(DESTDIR)$(includedir_server)/distributelayer/streamProducer.h' + $(INSTALL_DATA) distributelayer/streamTransportCore.h '$(DESTDIR)$(includedir_server)/distributelayer/streamTransportCore.h' +# We don't use INSTALL_DATA for performance reasons --- there are a lot of files + cp $(srcdir)/*.h '$(DESTDIR)$(includedir_server)'/ || exit; \ + chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/*.h || exit; \ + cp $(srcdir)/vecexecutor/*.inl '$(DESTDIR)$(includedir_server)'/ || exit; \ + chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/*.inl || exit; \ + for dir in $(SUBDIRS); do \ + cp $(srcdir)/$$dir/*.h '$(DESTDIR)$(includedir_server)'/$$dir/ || exit; \ + chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/$$dir/*.h || exit; \ + done + +ifeq ($(vpath_build),yes) + for file in dynloader.h catalog/schemapg.h parser/gram.h utils/probes.h; do \ + cp $$file '$(DESTDIR)$(includedir_server)'/$$file || exit; \ + chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/$$file || exit; \ + done +endif + +installdirs: + $(MKDIR_P) '$(DESTDIR)$(includedir)/libpq' '$(DESTDIR)$(includedir_internal)/libpq' + $(MKDIR_P) $(addprefix '$(DESTDIR)$(includedir_server)'/, $(SUBDIRS)) + + +uninstall: + rm -f $(addprefix '$(DESTDIR)$(includedir)'/, pg_config.h pg_config_os.h pg_config_manual.h postgres_ext.h libpq/libpq-fs.h) + rm -f $(addprefix '$(DESTDIR)$(includedir_internal)'/, c.h port.h postgres_fe.h libpq/pqcomm.h) +# heuristic... + rm -rf $(addprefix '$(DESTDIR)$(includedir_server)'/, $(SUBDIRS) *.h) + + +clean: + rm -f utils/fmgroids.h utils/errcodes.h parser/gram.hpp utils/probes.h catalog/schemapg.h replication/syncrep_gram.hpp replication/repl_gram.hpp + +distclean maintainer-clean: clean + rm -f pg_config.h dynloader.h pg_config_os.h stamp-h + +maintainer-check: + cd catalog && ./duplicate_oids diff -uprN postgresql-hll-2.14_old/include/mb/pg_wchar.h postgresql-hll-2.14/include/mb/pg_wchar.h --- postgresql-hll-2.14_old/include/mb/pg_wchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/mb/pg_wchar.h 2020-12-12 17:06:43.318348954 +0800 @@ -0,0 +1,484 @@ +/* ------------------------------------------------------------------------- + * + * pg_wchar.h + * multibyte-character support + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/mb/pg_wchar.h + * + * NOTES + * This is used both by the backend and by libpq, but should not be + * included by libpq client programs. In particular, a libpq client + * should not assume that the encoding IDs used by the version of libpq + * it's linked to match up with the IDs declared here. + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_WCHAR_H +#define PG_WCHAR_H + +#ifndef WIN32 +#include +#endif + +/* + * The pg_wchar type + */ +typedef unsigned int pg_wchar; + +/* + * various definitions for EUC + */ +#define SS2 0x8e /* single shift 2 (JIS0201) */ +#define SS3 0x8f /* single shift 3 (JIS0212) */ + +/* + * SJIS validation macros + */ +#define ISSJISHEAD(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xfc)) +#define ISSJISTAIL(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc)) + +/* + * Leading byte types or leading prefix byte for MULE internal code. + * See http://www.xemacs.org for more details. (there is a doc titled + * "XEmacs Internals Manual", "MULE Character Sets and Encodings" + * section.) + */ +/* + * Is a leading byte for "official" single byte encodings? + */ +#define IS_LC1(c) ((unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x8d) +/* + * Is a prefix byte for "private" single byte encodings? + */ +#define LCPRV1_A 0x9a +#define LCPRV1_B 0x9b +#define IS_LCPRV1(c) ((unsigned char)(c) == LCPRV1_A || (unsigned char)(c) == LCPRV1_B) +#define IS_LCPRV1_A_RANGE(c) ((unsigned char)(c) >= 0xa0 && (unsigned char)(c) <= 0xdf) +#define IS_LCPRV1_B_RANGE(c) ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) <= 0xef) +/* + * Is a leading byte for "official" multibyte encodings? + */ +#define IS_LC2(c) ((unsigned char)(c) >= 0x90 && (unsigned char)(c) <= 0x99) +/* + * Is a prefix byte for "private" multibyte encodings? + */ +#define LCPRV2_A 0x9c +#define LCPRV2_B 0x9d +#define IS_LCPRV2(c) ((unsigned char)(c) == LCPRV2_A || (unsigned char)(c) == LCPRV2_B) +#define IS_LCPRV2_A_RANGE(c) ((unsigned char)(c) >= 0xf0 && (unsigned char)(c) <= 0xf4) +#define IS_LCPRV2_B_RANGE(c) ((unsigned char)(c) >= 0xf5 && (unsigned char)(c) <= 0xfe) + +/* ---------------------------------------------------- + * leading characters + * ---------------------------------------------------- + */ + +/* + * Official single byte encodings (0x81-0x8e) + */ +#define LC_ISO8859_1 0x81 /* ISO8859 Latin 1 */ +#define LC_ISO8859_2 0x82 /* ISO8859 Latin 2 */ +#define LC_ISO8859_3 0x83 /* ISO8859 Latin 3 */ +#define LC_ISO8859_4 0x84 /* ISO8859 Latin 4 */ +#define LC_TIS620 0x85 /* Thai (not supported yet) */ +#define LC_ISO8859_7 0x86 /* Greek (not supported yet) */ +#define LC_ISO8859_6 0x87 /* Arabic (not supported yet) */ +#define LC_ISO8859_8 0x88 /* Hebrew (not supported yet) */ +#define LC_JISX0201K 0x89 /* Japanese 1 byte kana */ +#define LC_JISX0201R 0x8a /* Japanese 1 byte Roman */ +/* Note that 0x8b seems to be unused as of Emacs 20.7. + * However, there might be a chance that 0x8b could be used + * in later version of Emacs. + */ +#define LC_KOI8_R 0x8b /* Cyrillic KOI8-R */ +#define LC_KOI8_U 0x8b /* Cyrillic KOI8-U */ +#define LC_ISO8859_5 0x8c /* ISO8859 Cyrillic */ +#define LC_ISO8859_9 0x8d /* ISO8859 Latin 5 (not supported yet) */ +/* FREE 0x8e free (unused) */ + +/* + * Unused + */ +#define CONTROL_1 0x8f /* control characters (unused) */ + +/* + * Official multibyte byte encodings (0x90-0x99) + * 0x9a-0x9d are free. 0x9e and 0x9f are reserved. + */ +#define LC_JISX0208_1978 0x90 /* Japanese Kanji, old JIS (not supported) */ +#define LC_GB2312_80 0x91 /* Chinese */ +#define LC_JISX0208 0x92 /* Japanese Kanji (JIS X 0208) */ +#define LC_KS5601 0x93 /* Korean */ +#define LC_JISX0212 0x94 /* Japanese Kanji (JIS X 0212) */ +#define LC_CNS11643_1 0x95 /* CNS 11643-1992 Plane 1 */ +#define LC_CNS11643_2 0x96 /* CNS 11643-1992 Plane 2 */ +/* FREE 0x97 free (unused) */ +#define LC_BIG5_1 0x98 /* Plane 1 Chinese traditional (not supported) */ +#define LC_BIG5_2 0x99 /* Plane 1 Chinese traditional (not supported) */ + +/* + * Private single byte encodings (0xa0-0xef) + */ +#define LC_SISHENG \ + 0xa0 /* Chinese SiSheng characters for \ + * PinYin/ZhuYin (not supported) */ +#define LC_IPA \ + 0xa1 /* IPA (International Phonetic Association) \ + * (not supported) */ +#define LC_VISCII_LOWER \ + 0xa2 /* Vietnamese VISCII1.1 lower-case (not \ + * supported) */ +#define LC_VISCII_UPPER \ + 0xa3 /* Vietnamese VISCII1.1 upper-case (not \ + * supported) */ +#define LC_ARABIC_DIGIT 0xa4 /* Arabic digit (not supported) */ +#define LC_ARABIC_1_COLUMN 0xa5 /* Arabic 1-column (not supported) */ +#define LC_ASCII_RIGHT_TO_LEFT \ + 0xa6 /* ASCII (left half of ISO8859-1) with \ + * right-to-left direction (not \ + * supported) */ +#define LC_LAO \ + 0xa7 /* Lao characters (ISO10646 0E80..0EDF) (not \ + * supported) */ +#define LC_ARABIC_2_COLUMN 0xa8 /* Arabic 1-column (not supported) */ + +/* + * Private multibyte encodings (0xf0-0xff) + */ +#define LC_INDIAN_1_COLUMN \ + 0xf0 /* Indian charset for 1-column width glypps \ + * (not supported) */ +#define LC_TIBETAN_1_COLUMN 0xf1 /* Tibetan 1 column glyph (not supported) */ +#define LC_ETHIOPIC 0xf5 /* Ethiopic characters (not supported) */ +#define LC_CNS11643_3 0xf6 /* CNS 11643-1992 Plane 3 */ +#define LC_CNS11643_4 0xf7 /* CNS 11643-1992 Plane 4 */ +#define LC_CNS11643_5 0xf8 /* CNS 11643-1992 Plane 5 */ +#define LC_CNS11643_6 0xf9 /* CNS 11643-1992 Plane 6 */ +#define LC_CNS11643_7 0xfa /* CNS 11643-1992 Plane 7 */ +#define LC_INDIAN_2_COLUMN \ + 0xfb /* Indian charset for 2-column width glypps \ + * (not supported) */ +#define LC_TIBETAN 0xfc /* Tibetan (not supported) */ +/* FREE 0xfd free (unused) */ +/* FREE 0xfe free (unused) */ +/* FREE 0xff free (unused) */ + +/* + * PostgreSQL encoding identifiers + * + * WARNING: the order of this enum must be same as order of entries + * in the pg_enc2name_tbl[] array (in mb/encnames.c), and + * in the pg_wchar_table[] array (in mb/wchar.c)! + * + * If you add some encoding don't forget to check + * PG_ENCODING_BE_LAST macro. + * + * PG_SQL_ASCII is default encoding and must be = 0. + * + * XXX We must avoid renumbering any backend encoding until libpq's major + * version number is increased beyond 5; it turns out that the backend + * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and + * psql are concerned. + */ +typedef enum pg_enc { + PG_SQL_ASCII = 0, /* SQL/ASCII */ + PG_EUC_JP, /* EUC for Japanese */ + PG_EUC_CN, /* EUC for Chinese */ + PG_EUC_KR, /* EUC for Korean */ + PG_EUC_TW, /* EUC for Taiwan */ + PG_EUC_JIS_2004, /* EUC-JIS-2004 */ + // supports GBK for server encoding + PG_GBK, /* GBK (Windows-936) */ + PG_UTF8, /* Unicode UTF8 */ + PG_MULE_INTERNAL, /* Mule internal code */ + PG_LATIN1, /* ISO-8859-1 Latin 1 */ + PG_LATIN2, /* ISO-8859-2 Latin 2 */ + PG_LATIN3, /* ISO-8859-3 Latin 3 */ + PG_LATIN4, /* ISO-8859-4 Latin 4 */ + PG_LATIN5, /* ISO-8859-9 Latin 5 */ + PG_LATIN6, /* ISO-8859-10 Latin6 */ + PG_LATIN7, /* ISO-8859-13 Latin7 */ + PG_LATIN8, /* ISO-8859-14 Latin8 */ + PG_LATIN9, /* ISO-8859-15 Latin9 */ + PG_LATIN10, /* ISO-8859-16 Latin10 */ + PG_WIN1256, /* windows-1256 */ + PG_WIN1258, /* Windows-1258 */ + PG_WIN866, /* (MS-DOS CP866) */ + PG_WIN874, /* windows-874 */ + PG_KOI8R, /* KOI8-R */ + PG_WIN1251, /* windows-1251 */ + PG_WIN1252, /* windows-1252 */ + PG_ISO_8859_5, /* ISO-8859-5 */ + PG_ISO_8859_6, /* ISO-8859-6 */ + PG_ISO_8859_7, /* ISO-8859-7 */ + PG_ISO_8859_8, /* ISO-8859-8 */ + PG_WIN1250, /* windows-1250 */ + PG_WIN1253, /* windows-1253 */ + PG_WIN1254, /* windows-1254 */ + PG_WIN1255, /* windows-1255 */ + PG_WIN1257, /* windows-1257 */ + PG_KOI8U, /* KOI8-U */ + /* PG_ENCODING_BE_LAST points to the above entry */ + + /* followings are for client encoding only */ + PG_SJIS, /* Shift JIS (Winindows-932) */ + PG_BIG5, /* Big5 (Windows-950) */ + PG_UHC, /* UHC (Windows-949) */ + PG_GB18030, /* GB18030 */ + PG_JOHAB, /* EUC for Korean JOHAB */ + PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */ + _PG_LAST_ENCODING_ /* mark only */ + +} pg_enc; + +#define PG_ENCODING_BE_LAST PG_KOI8U + +/* + * Please use these tests before access to pg_encconv_tbl[] + * or to other places... + */ +#define PG_VALID_BE_ENCODING(_enc) ((_enc) >= 0 && (_enc) <= PG_ENCODING_BE_LAST) + +#define PG_ENCODING_IS_CLIENT_ONLY(_enc) ((_enc) > PG_ENCODING_BE_LAST && (_enc) < _PG_LAST_ENCODING_) + +#define PG_VALID_ENCODING(_enc) ((_enc) >= 0 && (_enc) < _PG_LAST_ENCODING_) + +/* On FE are possible all encodings */ +#define PG_VALID_FE_ENCODING(_enc) PG_VALID_ENCODING(_enc) + +/* + * When converting strings between different encodings, we assume that space + * for converted result is 4-to-1 growth in the worst case. The rate for + * currently supported encoding pairs are within 3 (SJIS JIS X0201 half width + * kanna -> UTF8 is the worst case). So "4" should be enough for the moment. + * + * Note that this is not the same as the maximum character width in any + * particular encoding. + */ +#define MAX_CONVERSION_GROWTH 4 + +/* + * Encoding names with all aliases + */ +typedef struct pg_encname { + char* name; + pg_enc encoding; +} pg_encname; + +extern pg_encname pg_encname_tbl[]; +extern unsigned int pg_encname_tbl_sz; + +/* + * Careful: + * + * if (PG_VALID_ENCODING(encoding)) + * pg_enc2name_tbl[ encoding ]; + */ +typedef struct pg_enc2name { + char* name; + pg_enc encoding; +#ifdef WIN32 + unsigned codepage; /* codepage for WIN32 */ +#endif +} pg_enc2name; + +extern pg_enc2name pg_enc2name_tbl[]; + +/* + * Encoding names for gettext + */ +typedef struct pg_enc2gettext { + pg_enc encoding; + const char* name; +} pg_enc2gettext; + +extern pg_enc2gettext pg_enc2gettext_tbl[]; + +/* + * pg_wchar stuff + */ +typedef int (*mb2wchar_with_len_converter)(const unsigned char* from, pg_wchar* to, int len); + +typedef int (*wchar2mb_with_len_converter)(const pg_wchar* from, unsigned char* to, int len); + +typedef int (*mblen_converter)(const unsigned char* mbstr); + +typedef int (*mbdisplaylen_converter)(const unsigned char* mbstr); + +typedef bool (*mbcharacter_incrementer)(unsigned char* mbstr, int len); + +typedef int (*mbverifier)(const unsigned char* mbstr, int len); + +typedef struct { + mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multibyte + * string to a wchar */ + wchar2mb_with_len_converter wchar2mb_with_len; /* convert a wchar + * string to a multibyte */ + mblen_converter mblen; /* get byte length of a char */ + mbdisplaylen_converter dsplen; /* get display width of a char */ + mbverifier mbverify; /* verify multibyte sequence */ + int maxmblen; /* max bytes for a char in this encoding */ +} pg_wchar_tbl; + +extern pg_wchar_tbl pg_wchar_table[]; + +/* + * UTF-8 to local code conversion map + * Note that we limit the max length of UTF-8 to 4 bytes, + * which is UCS-4 00010000-001FFFFF range. + */ +typedef struct { + uint32 utf; /* UTF-8 */ + uint32 code; /* local code */ +} pg_utf_to_local; + +/* + * local code to UTF-8 conversion map + */ +typedef struct { + uint32 code; /* local code */ + uint32 utf; /* UTF-8 */ +} pg_local_to_utf; + +/* + * UTF-8 to local code conversion map(combined characters) + */ +typedef struct { + uint32 utf1; /* UTF-8 code 1 */ + uint32 utf2; /* UTF-8 code 2 */ + uint32 code; /* local code */ +} pg_utf_to_local_combined; + +/* + * local code to UTF-8 conversion map(combined characters) + */ +typedef struct { + uint32 code; /* local code */ + uint32 utf1; /* UTF-8 code 1 */ + uint32 utf2; /* UTF-8 code 2 */ +} pg_local_to_utf_combined; + +/* + * Support macro for encoding conversion functions to validate their + * arguments. (This could be made more compact if we included fmgr.h + * here, but we don't want to do that because this header file is also + * used by frontends.) + */ +#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding, destencoding) \ + check_encoding_conversion_args( \ + PG_GETARG_INT32(0), PG_GETARG_INT32(1), PG_GETARG_INT32(4), (srcencoding), (destencoding)) + +/* + * These functions are considered part of libpq's exported API and + * are also declared in libpq-fe.h. + */ +extern "C" int pg_char_to_encoding(const char* name); +extern "C" const char* pg_encoding_to_char(int encoding); +extern "C" int pg_valid_server_encoding_id(int encoding); + +/* + * Remaining functions are not considered part of libpq's API, though many + * of them do exist inside libpq. + */ +extern pg_encname* pg_char_to_encname_struct(const char* name); + +extern int pg_mb2wchar(const char* from, pg_wchar* to); +extern int pg_mb2wchar_with_len(const char* from, pg_wchar* to, int len); +extern int pg_encoding_mb2wchar_with_len(int encoding, const char* from, pg_wchar* to, int len); +extern int pg_wchar2mb(const pg_wchar* from, char* to); +extern int pg_wchar2mb_with_len(const pg_wchar* from, char* to, int len); +extern int pg_encoding_wchar2mb_with_len(int encoding, const pg_wchar* from, char* to, int len); +extern int pg_char_and_wchar_strcmp(const char* s1, const pg_wchar* s2); +extern int pg_wchar_strncmp(const pg_wchar* s1, const pg_wchar* s2, size_t n); +extern int pg_char_and_wchar_strncmp(const char* s1, const pg_wchar* s2, size_t n); +extern size_t pg_wchar_strlen(const pg_wchar* wstr); +extern int pg_mblen(const char* mbstr); +extern int pg_dsplen(const char* mbstr); +extern int pg_encoding_mblen(int encoding, const char* mbstr); +extern int pg_encoding_dsplen(int encoding, const char* mbstr); +extern int pg_encoding_verifymb(int encoding, const char* mbstr, int len); +extern int pg_mule_mblen(const unsigned char* mbstr); +extern int pg_mic_mblen(const unsigned char* mbstr); +extern int pg_mbstrlen(const char* mbstr); +extern int pg_mbstrlen_with_len(const char* mbstr, int len); +extern int pg_mbstrlen_with_len_eml(const char* mbstr, int len, int eml); +extern int pg_mbcliplen(const char* mbstr, int len, int limit); +extern int pg_encoding_mbcliplen(int encoding, const char* mbstr, int len, int limit); +extern int pg_mbcharcliplen(const char* mbstr, int len, int imit); +extern int pg_mbcharcliplen_orig(const char* mbstr, int len, int limit); +extern int pg_encoding_max_length(int encoding); +extern int pg_database_encoding_max_length(void); +extern mbcharacter_incrementer pg_database_encoding_character_incrementer(void); + +extern int PrepareClientEncoding(int encoding); +extern int SetClientEncoding(int encoding); +extern void InitializeClientEncoding(void); +extern int pg_get_client_encoding(void); +extern const char* pg_get_client_encoding_name(void); + +extern void SetDatabaseEncoding(int encoding); +extern int GetDatabaseEncoding(void); +extern const char* GetDatabaseEncodingName(void); +extern int GetPlatformEncoding(void); +extern void pg_bind_textdomain_codeset(const char* domainname); + +extern int pg_valid_client_encoding(const char* name); +extern int pg_valid_server_encoding(const char* name); + +extern unsigned char* unicode_to_utf8(pg_wchar c, unsigned char* utf8string); +extern pg_wchar utf8_to_unicode(const unsigned char* c); +extern int pg_utf_mblen(const unsigned char*); +extern unsigned char* pg_do_encoding_conversion(unsigned char* src, int len, int src_encoding, int dest_encoding); + +extern char* pg_client_to_server(const char* s, int len); +extern char* pg_server_to_client(const char* s, int len); +extern char* pg_any_to_server(const char* s, int len, int encoding); +extern char* pg_server_to_any(const char* s, int len, int encoding); +extern bool WillTranscodingBePerformed(int encoding); + +extern unsigned short BIG5toCNS(unsigned short big5, unsigned char* lc); +extern unsigned short CNStoBIG5(unsigned short cns, unsigned char lc); + +extern void LocalToUtf(const unsigned char* iso, unsigned char* utf, const pg_local_to_utf* map, + const pg_local_to_utf_combined* cmap, int size1, int size2, int encoding, int len); + +extern void UtfToLocal(const unsigned char* utf, unsigned char* iso, const pg_utf_to_local* map, + const pg_utf_to_local_combined* cmap, int size1, int size2, int encoding, int len); + +extern bool pg_verifymbstr(const char* mbstr, int len, bool noError); +extern bool pg_verify_mbstr(int encoding, const char* mbstr, int len, bool noError); +extern int pg_verify_mbstr_len(int encoding, const char* mbstr, int len, bool noError); + +extern void check_encoding_conversion_args( + int src_encoding, int dest_encoding, int len, int expected_src_encoding, int expected_dest_encoding); + +extern void report_invalid_encoding(int encoding, const char* mbstr, int len); +extern void report_untranslatable_char(int src_encoding, int dest_encoding, const char* mbstr, int len); + +extern void pg_ascii2mic(const unsigned char* l, unsigned char* p, int len); +extern void pg_mic2ascii(const unsigned char* mic, unsigned char* p, int len); +extern void latin2mic(const unsigned char* l, unsigned char* p, int len, int lc, int encoding); +extern void mic2latin(const unsigned char* mic, unsigned char* p, int len, int lc, int encoding); +extern void latin2mic_with_table( + const unsigned char* l, unsigned char* p, int len, int lc, int encoding, const unsigned char* tab); +extern void mic2latin_with_table( + const unsigned char* mic, unsigned char* p, int len, int lc, int encoding, const unsigned char* tab); + +extern bool pg_utf8_islegal(const unsigned char* source, int length); +extern bool pg_gbk_islegal(const unsigned char* source, int length); + +extern char* gs_setlocale_r(int category, const char* locale); +#ifndef WIN32 +extern char* gs_nl_langinfo_r(nl_item item); +#else +extern char* gs_nl_langinfo_r(const char* ctype); +#endif + +#ifdef WIN32 +extern WCHAR* pgwin32_toUTF16(const char* str, int len, int* utf16len); +#endif + +#endif /* PG_WCHAR_H */ diff -uprN postgresql-hll-2.14_old/include/miscadmin.h postgresql-hll-2.14/include/miscadmin.h --- postgresql-hll-2.14_old/include/miscadmin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/miscadmin.h 2020-12-12 17:06:43.318348954 +0800 @@ -0,0 +1,457 @@ +/* ------------------------------------------------------------------------- + * + * miscadmin.h + * This file contains general postgres administration and initialization + * stuff that used to be spread out between the following files: + * globals.h global variables + * pdir.h directory path crud + * pinit.h postgres initialization + * pmod.h processing modes + * Over time, this has also become the preferred place for widely known + * resource-limitation stuff, such as u_sess->attr.attr_memory.work_mem and check_stack_depth(). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/miscadmin.h + * + * NOTES + * some of the information in this file should be moved to other files. + * + * ------------------------------------------------------------------------- + */ +#ifndef MISCADMIN_H +#define MISCADMIN_H + +#ifndef FRONTEND +#include "postgres.h" +#include "knl/knl_variable.h" +#endif +#include "gs_thread.h" +#include "pgtime.h" /* for pg_time_t */ +#include "libpq/libpq-be.h" + +#define PG_BACKEND_VERSIONSTR "gaussdb " DEF_GS_VERSION "\n" + +/***************************************************************************** + * Backend version and inplace upgrade staffs + *****************************************************************************/ + +extern const uint32 GRAND_VERSION_NUM; + +extern const uint32 MATVIEW_VERSION_NUM; +extern const uint32 PARTIALPUSH_VERSION_NUM; +extern const uint32 SUBLINKPULLUP_VERSION_NUM; +extern const uint32 PREDPUSH_VERSION_NUM; +extern const uint32 GTMLITE_VERSION_NUM; +extern const uint32 EXECUTE_DIRECT_ON_MULTI_VERSION_NUM; +extern const uint32 FIX_PBE_CUSTOME_PLAN_BUG_VERSION_NUM; +extern const uint32 FUNCNAME_PUSHDOWN_VERSION_NUM; +extern const uint32 STP_SUPPORT_COMMIT_ROLLBACK; +extern const uint32 SUPPORT_GPI_VERSION_NUM; +extern const uint32 PRIVS_VERSION_NUM; + +#define INPLACE_UPGRADE_PRECOMMIT_VERSION 1 + +#define OPT_DISPLAY_LEADING_ZERO 1 +#define OPT_END_MONTH_CALCULATE 2 +#define OPT_COMPAT_ANALYZE_SAMPLE 4 +#define OPT_BIND_SCHEMA_TABLESPACE 8 +#define OPT_RETURN_NS_OR_NULL 16 +#define OPT_BIND_SEARCHPATH 32 +#define OPT_UNBIND_DIVIDE_BOUND 64 +#define OPT_CORRECT_TO_NUMBER 128 +#define OPT_CONCAT_VARIADIC 256 +#define OPT_MEGRE_UPDATE_MULTI 512 +#define OPT_CONVERT_TO_NUMERIC 1024 +#define OPT_MAX 11 + +#define DISPLAY_LEADING_ZERO (u_sess->utils_cxt.behavior_compat_flags & OPT_DISPLAY_LEADING_ZERO) +#define END_MONTH_CALCULATE (u_sess->utils_cxt.behavior_compat_flags & OPT_END_MONTH_CALCULATE) +#define SUPPORT_PRETTY_ANALYZE (!(u_sess->utils_cxt.behavior_compat_flags & OPT_COMPAT_ANALYZE_SAMPLE)) +#define SUPPORT_BIND_TABLESPACE (u_sess->utils_cxt.behavior_compat_flags & OPT_BIND_SCHEMA_TABLESPACE) +#define SUPPORT_BIND_DIVIDE (!(u_sess->utils_cxt.behavior_compat_flags & OPT_UNBIND_DIVIDE_BOUND)) +#define RETURN_NS (u_sess->utils_cxt.behavior_compat_flags & OPT_RETURN_NS_OR_NULL) +#define CORRECT_TO_NUMBER (u_sess->utils_cxt.behavior_compat_flags & OPT_CORRECT_TO_NUMBER) +#define SUPPORT_BIND_SEARCHPATH (u_sess->utils_cxt.behavior_compat_flags & OPT_BIND_SEARCHPATH) +/*CONCAT_VARIADIC controls 1.the variadic type process, and 2. td mode null return process in concat. By default, the + * option is blank and the behavior is new and compatible with current A and C mode, if the option is set, the + * behavior is old and the same as previous GAUSSDB kernel. */ +#define CONCAT_VARIADIC (!(u_sess->utils_cxt.behavior_compat_flags & OPT_CONCAT_VARIADIC)) +#define MEGRE_UPDATE_MULTI (u_sess->utils_cxt.behavior_compat_flags & OPT_MEGRE_UPDATE_MULTI) +#define CONVERT_STRING_DIGIT_TO_NUMERIC (u_sess->utils_cxt.behavior_compat_flags & OPT_CONVERT_TO_NUMERIC) + +/* define database compatibility Attribute */ +typedef struct { + int flag; + char name[256]; +} DB_CompatibilityAttr; +#define DB_CMPT_A 0 +#define DB_CMPT_B 1 +#define DB_CMPT_C 2 +extern DB_CompatibilityAttr g_dbCompatArray[]; + +/* in tcop/postgres.c */ +extern void ProcessInterrupts(void); + +#ifndef WIN32 + +#define CHECK_FOR_INTERRUPTS() \ + do { \ + if (InterruptPending) \ + ProcessInterrupts(); \ + } while (0) +#else /* WIN32 */ + +#define CHECK_FOR_INTERRUPTS() \ + do { \ + if (UNBLOCKED_SIGNAL_QUEUE()) \ + pgwin32_dispatch_queued_signals(); \ + if (InterruptPending) \ + ProcessInterrupts(); \ + } while (0) +#endif /* WIN32 */ + +#define HOLD_INTERRUPTS() (t_thrd.int_cxt.InterruptHoldoffCount++) + +#define RESUME_INTERRUPTS() \ + do { \ + Assert(t_thrd.int_cxt.InterruptHoldoffCount > 0); \ + t_thrd.int_cxt.InterruptHoldoffCount--; \ + } while (0) + +#define START_CRIT_SECTION() (t_thrd.int_cxt.CritSectionCount++) + +#define END_CRIT_SECTION() \ + do { \ + Assert(t_thrd.int_cxt.CritSectionCount > 0); \ + t_thrd.int_cxt.CritSectionCount--; \ + } while (0) + +/***************************************************************************** + * globals.h -- * + *****************************************************************************/ +extern bool open_join_children; +extern bool will_shutdown; +extern bool dummyStandbyMode; + +/* + * from utils/init/globals.c + */ +extern THR_LOCAL PGDLLIMPORT volatile bool InterruptPending; + +extern volatile ThreadId PostmasterPid; +extern bool IsPostmasterEnvironment; +extern volatile uint32 WorkingGrandVersionNum; +extern bool InplaceUpgradePrecommit; + +extern THR_LOCAL PGDLLIMPORT bool IsUnderPostmaster; +extern THR_LOCAL PGDLLIMPORT char my_exec_path[]; + +extern int8 ce_cache_refresh_type; + +#define MAX_QUERY_DOP (64) +#define MIN_QUERY_DOP -(MAX_QUERY_DOP) + +/* Debug mode. + * 0 - Do not change any thing. + * 1 - For test: Parallel when inExplain. And change the scan limit to MIN_ROWS_L. + * 2 - For llt: Do not parallel when inExplain. And change the scan limit to MIN_ROWS_L. + */ +#define DEFAULT_MODE 0 +#define DEBUG_MODE 1 +#define LLT_MODE 2 + +/* + * Date/Time Configuration + * + * u_sess->time_cxt.DateStyle defines the output formatting choice for date/time types: + * USE_POSTGRES_DATES specifies traditional Postgres format + * USE_ISO_DATES specifies ISO-compliant format + * USE_SQL_DATES specifies Oracle/Ingres-compliant format + * USE_GERMAN_DATES specifies German-style dd.mm/yyyy + * + */ + +/* valid u_sess->time_cxt.DateStyle values */ +#define USE_POSTGRES_DATES 0 +#define USE_ISO_DATES 1 +#define USE_SQL_DATES 2 +#define USE_GERMAN_DATES 3 +#define USE_XSD_DATES 4 + +/* valid u_sess->time_cxt.DateOrder values */ +#define DATEORDER_YMD 0 +#define DATEORDER_DMY 1 +#define DATEORDER_MDY 2 + +/* + * u_sess->attr.attr_common.IntervalStyles + * INTSTYLE_POSTGRES Like Postgres < 8.4 when u_sess->time_cxt.DateStyle = 'iso' + * INTSTYLE_POSTGRES_VERBOSE Like Postgres < 8.4 when u_sess->time_cxt.DateStyle != 'iso' + * INTSTYLE_SQL_STANDARD SQL standard interval literals + * INTSTYLE_ISO_8601 ISO-8601-basic formatted intervals + */ +#define INTSTYLE_POSTGRES 0 +#define INTSTYLE_POSTGRES_VERBOSE 1 +#define INTSTYLE_SQL_STANDARD 2 +#define INTSTYLE_ISO_8601 3 +#define INTSTYLE_ORACLE 4 + +#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */ +#define OPT_MAX_OP_MEM (4 * 1024L * 1024L) /* 4GB, used to restrict operator mem in optimizer */ + +#ifdef PGXC +extern bool useLocalXid; +#endif + +#define DEFUALT_STACK_SIZE 16384 + +/* in tcop/postgres.c */ + +#if defined(__ia64__) || defined(__ia64) +typedef struct { + char* stack_base_ptr; + char* register_stack_base_ptr; +} pg_stack_base_t; +#else +typedef char* pg_stack_base_t; +#endif + +extern pg_stack_base_t set_stack_base(void); +extern void restore_stack_base(pg_stack_base_t base); +extern void check_stack_depth(void); +extern bool stack_is_too_deep(void); + +/* in tcop/utility.c */ +extern void PreventCommandIfReadOnly(const char* cmdname); +extern void PreventCommandDuringRecovery(const char* cmdname); + +extern int trace_recovery(int trace_level); + +/***************************************************************************** + * pdir.h -- * + * POSTGRES directory path definitions. * + *****************************************************************************/ + +/* flags to be OR'd to form sec_context */ +#define SECURITY_LOCAL_USERID_CHANGE 0x0001 +#define SECURITY_RESTRICTED_OPERATION 0x0002 + +/* now in utils/init/miscinit.c */ +extern char* GetUserNameFromId(Oid roleid); +extern char* GetUserNameById(Oid roleid); +extern Oid GetAuthenticatedUserId(void); +extern Oid GetUserId(void); +extern Oid getCurrentNamespace(); +extern Oid GetCurrentUserId(void); +extern Oid GetOuterUserId(void); +extern Oid GetSessionUserId(void); +extern void GetUserIdAndSecContext(Oid* userid, int* sec_context); +extern void SetUserIdAndSecContext(Oid userid, int sec_context); +extern bool InLocalUserIdChange(void); +extern bool InSecurityRestrictedOperation(void); +extern void GetUserIdAndContext(Oid* userid, bool* sec_def_context); +extern void SetUserIdAndContext(Oid userid, bool sec_def_context); +extern void InitializeSessionUserId(const char* rolename); +extern void InitializeSessionUserIdStandalone(void); +extern void SetSessionAuthorization(Oid userid, bool is_superuser); +extern Oid GetCurrentRoleId(void); +extern void SetCurrentRoleId(Oid roleid, bool is_superuser); + +extern Oid get_current_lcgroup_oid(); +extern const char* get_current_lcgroup_name(); +extern bool is_lcgroup_admin(); +extern bool is_logic_cluster(Oid group_id); +extern bool in_logic_cluster(); +extern bool exist_logic_cluster(); +#ifdef ENABLE_MULTIPLE_NODES +extern const char* show_nodegroup_mode(void); +#endif +extern const char* show_lcgroup_name(); +extern Oid get_pgxc_logic_groupoid(Oid roleid); +extern Oid get_pgxc_logic_groupoid(const char* groupname); +extern void Reset_Pseudo_CurrentUserId(void); + +extern void SetDataDir(const char* dir); +extern void ChangeToDataDir(void); +extern char* make_absolute_path(const char* path); + +/* in utils/misc/superuser.c */ +extern bool superuser( + void); /* when privileges separate is used,current user is or superuser or sysdba,if not,current user is superuser*/ +extern bool isRelSuperuser( + void); /*current user is real superuser.if you don't want sysdba to entitle to operate,use it*/ +extern bool initialuser(void); /* current user is initial user. */ +extern bool superuser_arg(Oid roleid); /* given user is superuser */ +extern bool superuser_arg_no_seperation(Oid roleid); /* given user is superuser (no seperation)*/ +extern bool systemDBA_arg(Oid roleid); /* given user is systemdba */ +extern bool isSecurityadmin(Oid roleid); /* given user is security admin */ +extern bool isAuditadmin(Oid roleid); /* given user is audit admin */ +extern bool isMonitoradmin(Oid roleid); /* given user is monitor admin */ +extern bool isOperatoradmin(Oid roleid); /* given user is operator admin */ +extern bool isPolicyadmin(Oid roleid); /* given user is policy admin */ +extern bool CheckExecDirectPrivilege(const char* query); /* check user have privilege to use execute direct */ + +/***************************************************************************** + * pmod.h -- * + * POSTGRES processing mode definitions. * + *****************************************************************************/ + +#define IsBootstrapProcessingMode() (u_sess->misc_cxt.Mode == BootstrapProcessing) +#define IsInitProcessingMode() (u_sess->misc_cxt.Mode == InitProcessing) +#define IsNormalProcessingMode() (u_sess->misc_cxt.Mode == NormalProcessing) +#define IsPostUpgradeProcessingMode() (u_sess->misc_cxt.Mode == PostUpgradeProcessing) + +#define GetProcessingMode() u_sess->misc_cxt.Mode + +#define SetProcessingMode(mode) \ + do { \ + AssertArg((mode) == BootstrapProcessing || (mode) == InitProcessing || (mode) == NormalProcessing || \ + (mode) == PostUpgradeProcessing); \ + u_sess->misc_cxt.Mode = (mode); \ + } while (0) + + +/* + * Auxiliary-process type identifiers. + */ +typedef enum { + NotAnAuxProcess = -1, + CheckerProcess = 0, + BootstrapProcess, + StartupProcess, + BgWriterProcess, + CheckpointerProcess, + WalWriterProcess, + WalWriterAuxiliaryProcess, + WalReceiverProcess, + WalRcvWriterProcess, + DataReceiverProcess, + DataRcvWriterProcess, + HeartbeatProcess, +#ifdef PGXC + TwoPhaseCleanerProcess, + WLMWorkerProcess, + WLMMonitorWorkerProcess, + WLMArbiterWorkerProcess, + CPMonitorProcess, + FaultMonitorProcess, + CBMWriterProcess, + RemoteServiceProcess, +#endif + AsyncIOCompleterProcess, + TpoolSchdulerProcess, + TsCompactionProcess, + TsCompactionAuxiliaryProcess, + NUM_SINGLE_AUX_PROC, /* Sentry for auxiliary type with single thread. */ + + /* + * If anyone want add a new auxiliary thread type, and will create several + * threads for this type, then you must add it below NUM_SINGLE_AUX_PROC. + * Meanwhile, you must update NUM_MULTI_AUX_PROC and GetAuxProcEntryIndex(). + */ + PageWriterProcess, + MultiBgWriterProcess, + PageRedoProcess, + TpoolListenerProcess, + TsCompactionConsumerProcess, + CsnMinSyncProcess, + + NUM_AUXPROCTYPES /* Must be last! */ +} AuxProcType; + +#define AmBootstrapProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == BootstrapProcess) +#define AmStartupProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == StartupProcess) +#define AmPageRedoProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == PageRedoProcess) +#define AmBackgroundWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == BgWriterProcess) +#define AmMulitBackgroundWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == MultiBgWriterProcess) +#define AmCheckpointerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CheckpointerProcess) +#define AmWalWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalWriterProcess) +#define AmWalWriterAuxiliaryProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalWriterAuxiliaryProcess) +#define AmWalReceiverProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalReceiverProcess) +#define AmWalReceiverWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WalRcvWriterProcess) +#define AmDataReceiverProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == DataReceiverProcess) +#define AmDataReceiverWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == DataRcvWriterProcess) +#define AmWLMWorkerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMWorkerProcess) +#define AmWLMMonitorProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMMonitorWorkerProcess) +#define AmWLMArbiterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == WLMArbiterWorkerProcess) +#define AmCPMonitorProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CPMonitorProcess) +#define AmCBMWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == CBMWriterProcess) +#define AmRemoteServiceProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == RemoteServiceProcess) +#define AmPageWriterProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == PageWriterProcess) +#define AmHeartbeatProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == HeartbeatProcess) +#define AmTsCompactionProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionProcess) +#define AmTsCompactionConsumerProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionConsumerProcess) +#define AmTsCompactionAuxiliaryProcess() (t_thrd.bootstrap_cxt.MyAuxProcType == TsCompactionAuxiliaryProcess) +#define AmPageRedoWorker() (t_thrd.bootstrap_cxt.MyAuxProcType == PageRedoProcess) + + + + +/***************************************************************************** + * pinit.h -- * + * POSTGRES initialization and cleanup definitions. * + *****************************************************************************/ + +/* in utils/init/postinit.c */ +extern void pg_split_opts(char** argv, int* argcp, char* optstr); +extern void PostgresResetUsernamePgoption(const char* username); +extern void BaseInit(void); + +/* + * As of 9.1, the contents of the data-directory lock file are: + * + * line # + * 1 postmaster PID (or negative of a standalone backend's PID) + * 2 data directory path + * 3 postmaster start timestamp (time_t representation) + * 4 port number + * 5 socket directory path (empty on Windows) + * 6 first listen_address (IP address or "*"; empty if no TCP port) + * 7 shared memory key (not present on Windows) + * + * Lines 6 and up are added via AddToDataDirLockFile() after initial file + * creation; they have to be ordered according to time of addition. + * + * The socket lock file, if used, has the same contents as lines 1-5. + */ +#define LOCK_FILE_LINE_PID 1 +#define LOCK_FILE_LINE_DATA_DIR 2 +#define LOCK_FILE_LINE_START_TIME 3 +#define LOCK_FILE_LINE_PORT 4 +#define LOCK_FILE_LINE_SOCKET_DIR 5 +#define LOCK_FILE_LINE_LISTEN_ADDR 6 +#define LOCK_FILE_LINE_SHMEM_KEY 7 + +extern void CreateDataDirLockFile(bool amPostmaster); +extern void CreateSocketLockFile(const char* socketfile, bool amPostmaster, bool is_create_psql_sock = true); +extern void TouchSocketLockFile(void); +extern void AddToDataDirLockFile(int target_line, const char* str); +extern void ValidatePgVersion(const char* path); +extern void process_shared_preload_libraries(void); +extern void process_local_preload_libraries(void); +extern void pg_bindtextdomain(const char* domain); +extern bool has_rolreplication(Oid roleid); +extern bool has_rolvcadmin(Oid roleid); + +/* in access/transam/xlog.c */ +extern bool BackupInProgress(void); +extern void CancelBackup(void); + +extern void EarlyBindingTLSVariables(void); + +/* + * converts the 64 bits unsigned integer between host byte order and network byte order. + * Note that the network byte order is BIG ENDIAN. + */ +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define htonl64(x) htobe64(x) +#define ntohl64(x) be64toh(x) +#else +#define htonl64(x) (x) +#define ntohl64(x) (x) +#endif + +#define UPSERT_ROW_STORE_VERSION_NUM 92073 /* Version control for UPSERT */ +#endif /* MISCADMIN_H */ diff -uprN postgresql-hll-2.14_old/include/MurmurHash3.h postgresql-hll-2.14/include/MurmurHash3.h --- postgresql-hll-2.14_old/include/MurmurHash3.h 2019-11-15 18:39:18.000000000 +0800 +++ postgresql-hll-2.14/include/MurmurHash3.h 1970-01-01 08:00:00.000000000 +0800 @@ -1,50 +0,0 @@ -// **************************************************************************** -// This file originally from: -// http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.h -// **************************************************************************** - -//----------------------------------------------------------------------------- -// MurmurHash3 was written by Austin Appleby, and is placed in the public -// domain. The author hereby disclaims copyright to this source code. - -#ifndef _MURMURHASH3_H_ -#define _MURMURHASH3_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -//----------------------------------------------------------------------------- -// Platform-specific functions and macros - -// Microsoft Visual Studio - -#if defined(_MSC_VER) - -typedef unsigned char uint8_t; -typedef unsigned long uint32_t; -typedef unsigned __int64 uint64_t; - -// Other compilers - -#else // defined(_MSC_VER) - -#include - -#endif // !defined(_MSC_VER) - -//----------------------------------------------------------------------------- - -void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ); - -void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ); - -void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ); - -//----------------------------------------------------------------------------- - -#ifdef __cplusplus -} -#endif - -#endif // _MURMURHASH3_H_ diff -uprN postgresql-hll-2.14_old/include/nodes/bitmapset.h postgresql-hll-2.14/include/nodes/bitmapset.h --- postgresql-hll-2.14_old/include/nodes/bitmapset.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/bitmapset.h 2020-12-12 17:06:43.318348954 +0800 @@ -0,0 +1,99 @@ +/* ------------------------------------------------------------------------- + * + * bitmapset.h + * PostgreSQL generic bitmap set package + * + * A bitmap set can represent any set of nonnegative integers, although + * it is mainly intended for sets where the maximum value is not large, + * say at most a few hundred. By convention, a NULL pointer is always + * accepted by all operations to represent the empty set. (But beware + * that this is not the only representation of the empty set. Use + * bms_is_empty() in preference to testing for NULL.) + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/bitmapset.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BITMAPSET_H +#define BITMAPSET_H + +/* + * Data representation + */ + +/* The unit size can be adjusted by changing these three declarations: */ +#define BITS_PER_BITMAPWORD 32 +typedef uint32 bitmapword; /* must be an unsigned type */ +typedef int32 signedbitmapword; /* must be the matching signed type */ + +typedef struct Bitmapset { + int nwords; /* number of words in array */ + bitmapword words[FLEXIBLE_ARRAY_MEMBER]; /* really [nwords] */ +} Bitmapset; + +/* result of bms_subset_compare */ +typedef enum { + BMS_EQUAL, /* sets are equal */ + BMS_SUBSET1, /* first set is a subset of the second */ + BMS_SUBSET2, /* second set is a subset of the first */ + BMS_DIFFERENT /* neither set is a subset of the other */ +} BMS_Comparison; + +/* result of bms_membership */ +typedef enum { + BMS_EMPTY_SET, /* 0 members */ + BMS_SINGLETON, /* 1 member */ + BMS_MULTIPLE /* >1 member */ +} BMS_Membership; + +/* + * function prototypes in nodes/bitmapset.c + */ +extern Bitmapset* bms_copy(const Bitmapset* a); +extern bool bms_equal(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_make_singleton(int x); +extern void bms_free(Bitmapset* a); + +#define bms_free_ext(bms) \ + do { \ + if ((bms) != NULL) { \ + bms_free(bms); \ + bms = NULL; \ + } \ + } while (0) + +extern Bitmapset* bms_union(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_intersect(const Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_difference(const Bitmapset* a, const Bitmapset* b); +extern bool bms_is_subset(const Bitmapset* a, const Bitmapset* b); +extern BMS_Comparison bms_subset_compare(const Bitmapset* a, const Bitmapset* b); +extern bool bms_is_member(int x, const Bitmapset* a); +extern bool bms_overlap(const Bitmapset* a, const Bitmapset* b); +extern bool bms_nonempty_difference(const Bitmapset* a, const Bitmapset* b); +extern int bms_singleton_member(const Bitmapset* a); +extern int bms_num_members(const Bitmapset* a); + +/* optimized tests when we don't need to know exact membership count: */ +extern BMS_Membership bms_membership(const Bitmapset* a); +extern bool bms_is_empty(const Bitmapset* a); + +/* these routines recycle (modify or free) their non-const inputs: */ +extern Bitmapset* bms_add_member(Bitmapset* a, int x); +extern Bitmapset* bms_del_member(Bitmapset* a, int x); +extern Bitmapset* bms_add_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_int_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_del_members(Bitmapset* a, const Bitmapset* b); +extern Bitmapset* bms_join(Bitmapset* a, Bitmapset* b); + +/* support for iterating through the integer elements of a set: */ +extern int bms_first_member(Bitmapset* a); +extern int bms_next_member(const Bitmapset* a, int prevbit); + +/* support for hashtables using Bitmapsets as keys: */ +extern uint32 bms_hash_value(const Bitmapset* a); + +#endif /* BITMAPSET_H */ + diff -uprN postgresql-hll-2.14_old/include/nodes/execnodes.h postgresql-hll-2.14/include/nodes/execnodes.h --- postgresql-hll-2.14_old/include/nodes/execnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/execnodes.h 2020-12-12 17:06:43.319348967 +0800 @@ -0,0 +1,2474 @@ +/* ------------------------------------------------------------------------- + * + * execnodes.h + * definitions for executor state nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/execnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef EXECNODES_H +#define EXECNODES_H + +// EB: put genam.h first +#include "access/genam.h" +#include "access/relscan.h" +#include "bulkload/dist_fdw.h" +#include "executor/instrument.h" +#include "nodes/params.h" +#include "nodes/plannodes.h" +#include "storage/pagecompress.h" +#include "utils/bloom_filter.h" +#include "utils/reltrigger.h" +#include "utils/sortsupport.h" +#include "utils/tuplesort.h" +#include "utils/tuplestore.h" +#include "vecexecutor/vectorbatch.h" + +#ifdef ENABLE_MOT +// forward declaration for MOT JitContext +namespace JitExec +{ + struct JitContext; +} +#endif + +/* struct for utility statement mem usage */ +typedef struct UtilityDesc { + double cost; /* cost of utility statement */ + int query_mem[2]; /* max and min mem of utility statement */ + int min_mem; /* operator min mem from cost estimation */ + int assigned_mem; /* statement mem assigned by workload manager */ +} UtilityDesc; + +/* ---------------- + * IndexInfo information + * + * this struct holds the information needed to construct new index + * entries for a particular index. Used for both index_build and + * retail creation of index entries. + * + * NumIndexAttrs total number of columns in this index + * NumIndexKeyAttrs number of key columns in index + * KeyAttrNumbers underlying-rel attribute numbers used as keys + * (zeroes indicate expressions). It also contains + * info about included columns. + * Expressions expr trees for expression entries, or NIL if none + * ExpressionsState exec state for expressions, or NIL if none + * Predicate partial-index predicate, or NIL if none + * PredicateState exec state for predicate, or NIL if none + * ExclusionOps Per-column exclusion operators, or NULL if none + * ExclusionProcs Underlying function OIDs for ExclusionOps + * ExclusionStrats Opclass strategy numbers for ExclusionOps + * UniqueOps Theses are like Exclusion*, but for unique indexes + * UniqueProcs + * UniqueStrats + * Unique is it a unique index? + * ReadyForInserts is it valid for inserts? + * Concurrent are we doing a concurrent index build? + * BrokenHotChain did we detect any broken HOT chains? + * + * ii_Concurrent and ii_BrokenHotChain are used only during index build; + * they're conventionally set to false otherwise. + * ---------------- + */ +typedef struct IndexInfo { + NodeTag type; + int ii_NumIndexAttrs; /* total number of columns in index */ + int ii_NumIndexKeyAttrs; /* number of key columns in index */ + AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS]; + List* ii_Expressions; /* list of Expr */ + List* ii_ExpressionsState; /* list of ExprState */ + List* ii_Predicate; /* list of Expr */ + List* ii_PredicateState; /* list of ExprState */ + Oid* ii_ExclusionOps; /* array with one entry per column */ + Oid* ii_ExclusionProcs; /* array with one entry per column */ + uint16* ii_ExclusionStrats; /* array with one entry per column */ + Oid *ii_UniqueOps; /* array with one entry per column */ + Oid *ii_UniqueProcs; /* array with one entry per column */ + uint16 *ii_UniqueStrats; /* array with one entry per column */ + bool ii_Unique; + bool ii_ReadyForInserts; + bool ii_Concurrent; + bool ii_BrokenHotChain; + short ii_PgClassAttrId; + UtilityDesc ii_desc; /* meminfo for index create */ +} IndexInfo; + +/* ---------------- + * ExprContext_CB + * + * List of callbacks to be called at ExprContext shutdown. + * ---------------- + */ +typedef void (*ExprContextCallbackFunction)(Datum arg); + +typedef struct ExprContext_CB { + struct ExprContext_CB* next; + ExprContextCallbackFunction function; + Datum arg; +} ExprContext_CB; + +/* ---------------- + * ExprContext + * + * This class holds the "current context" information + * needed to evaluate expressions for doing tuple qualifications + * and tuple projections. For example, if an expression refers + * to an attribute in the current inner tuple then we need to know + * what the current inner tuple is and so we look at the expression + * context. + * + * There are two memory contexts associated with an ExprContext: + * * ecxt_per_query_memory is a query-lifespan context, typically the same + * context the ExprContext node itself is allocated in. This context + * can be used for purposes such as storing function call cache info. + * * ecxt_per_tuple_memory is a short-term context for expression results. + * As the name suggests, it will typically be reset once per tuple, + * before we begin to evaluate expressions for that tuple. Each + * ExprContext normally has its very own per-tuple memory context. + * + * CurrentMemoryContext should be set to ecxt_per_tuple_memory before + * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext(). + * ---------------- + */ +struct PLpgSQL_execstate; + +typedef struct ExprContext { + NodeTag type; + + /* Tuples that Var nodes in expression may refer to */ + TupleTableSlot* ecxt_scantuple; + TupleTableSlot* ecxt_innertuple; + TupleTableSlot* ecxt_outertuple; + + /* Memory contexts for expression evaluation --- see notes above */ + MemoryContext ecxt_per_query_memory; + MemoryContext ecxt_per_tuple_memory; + + /* Values to substitute for Param nodes in expression */ + ParamExecData* ecxt_param_exec_vals; /* for PARAM_EXEC params */ + ParamListInfo ecxt_param_list_info; /* for other param types */ + + /* + * Values to substitute for Aggref nodes in the expressions of an Agg + * node, or for WindowFunc nodes within a WindowAgg node. + */ + Datum* ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */ + bool* ecxt_aggnulls; /* null flags for aggs/windowfuncs */ + + /* Value to substitute for CaseTestExpr nodes in expression */ + Datum caseValue_datum; + bool caseValue_isNull; + + ScalarVector* caseValue_vector; + + /* Value to substitute for CoerceToDomainValue nodes in expression */ + Datum domainValue_datum; + bool domainValue_isNull; + + /* Link to containing EState (NULL if a standalone ExprContext) */ + struct EState* ecxt_estate; + + /* Functions to call back when ExprContext is shut down */ + ExprContext_CB* ecxt_callbacks; + + // vector specific fields + // consider share space with row fields + // + VectorBatch* ecxt_scanbatch; + VectorBatch* ecxt_innerbatch; + VectorBatch* ecxt_outerbatch; + + // Batch to substitute for Aggref nodes in the expression of an VecAgg node + // + VectorBatch* ecxt_aggbatch; + + /* + * mark the real rows for expression cluster, all the results' m_rows generated by + * vec-expression are aligned by econtext->align_rows + */ + int align_rows; + + bool m_fUseSelection; // Shall we use selection vector? + ScalarVector* qual_results; + ScalarVector* boolVector; + bool is_cursor; + Cursor_Data cursor_data; + int dno; + PLpgSQL_execstate* plpgsql_estate; + /* + * For vector set-result function. + */ + bool have_vec_set_fun; + bool* vec_fun_sel; // selection for vector set-result function. + int current_row; +} ExprContext; + +/* + * Set-result status returned by ExecEvalExpr() + */ +typedef enum { + ExprSingleResult, /* expression does not return a set */ + ExprMultipleResult, /* this result is an element of a set */ + ExprEndResult /* there are no more elements in the set */ +} ExprDoneCond; + +/* + * Return modes for functions returning sets. Note values must be chosen + * as separate bits so that a bitmask can be formed to indicate supported + * modes. SFRM_Materialize_Random and SFRM_Materialize_Preferred are + * auxiliary flags about SFRM_Materialize mode, rather than separate modes. + */ +typedef enum { + SFRM_ValuePerCall = 0x01, /* one value returned per call */ + SFRM_Materialize = 0x02, /* result set instantiated in Tuplestore */ + SFRM_Materialize_Random = 0x04, /* Tuplestore needs randomAccess */ + SFRM_Materialize_Preferred = 0x08 /* caller prefers Tuplestore */ +} SetFunctionReturnMode; + +/* + * When calling a function that might return a set (multiple rows), + * a node of this type is passed as fcinfo->resultinfo to allow + * return status to be passed back. A function returning set should + * raise an error if no such resultinfo is provided. + */ +typedef struct ReturnSetInfo { + NodeTag type; + /* values set by caller: */ + ExprContext* econtext; /* context function is being called in */ + TupleDesc expectedDesc; /* tuple descriptor expected by caller */ + int allowedModes; /* bitmask: return modes caller can handle */ + /* result status from function (but pre-initialized by caller): */ + SetFunctionReturnMode returnMode; /* actual return mode */ + ExprDoneCond isDone; /* status for ValuePerCall mode */ + /* fields filled by function in Materialize return mode: */ + Tuplestorestate* setResult; /* holds the complete returned tuple set */ + TupleDesc setDesc; /* actual descriptor for returned tuples */ +} ReturnSetInfo; + +/* ---------------- + * ProjectionInfo node information + * + * This is all the information needed to perform projections --- + * that is, form new tuples by evaluation of targetlist expressions. + * Nodes which need to do projections create one of these. + * + * ExecProject() evaluates the tlist, forms a tuple, and stores it + * in the given slot. Note that the result will be a "virtual" tuple + * unless ExecMaterializeSlot() is then called to force it to be + * converted to a physical tuple. The slot must have a tupledesc + * that matches the output of the tlist! + * + * The planner very often produces tlists that consist entirely of + * simple Var references (lower levels of a plan tree almost always + * look like that). And top-level tlists are often mostly Vars too. + * We therefore optimize execution of simple-Var tlist entries. + * The pi_targetlist list actually contains only the tlist entries that + * aren't simple Vars, while those that are Vars are processed using the + * varSlotOffsets/varNumbers/varOutputCols arrays. + * + * The lastXXXVar fields are used to optimize fetching of fields from + * input tuples: they let us do a slot_getsomeattrs() call to ensure + * that all needed attributes are extracted in one pass. + * + * targetlist target list for projection (non-Var expressions only) + * exprContext expression context in which to evaluate targetlist + * slot slot to place projection result in + * itemIsDone workspace array for ExecProject + * directMap true if varOutputCols[] is an identity map + * numSimpleVars number of simple Vars found in original tlist + * varSlotOffsets array indicating which slot each simple Var is from + * varNumbers array containing input attr numbers of simple Vars + * varOutputCols array containing output attr numbers of simple Vars + * lastInnerVar highest attnum from inner tuple slot (0 if none) + * lastOuterVar highest attnum from outer tuple slot (0 if none) + * lastScanVar highest attnum from scan tuple slot (0 if none) + * pi_maxOrmin column table optimize, indicate if get this column's max or min. + * ---------------- + */ +typedef bool (*vectarget_func)(ExprContext* econtext, VectorBatch* pBatch); +typedef struct ProjectionInfo { + NodeTag type; + List* pi_targetlist; + ExprContext* pi_exprContext; + TupleTableSlot* pi_slot; + ExprDoneCond* pi_itemIsDone; + bool pi_directMap; + int pi_numSimpleVars; + int* pi_varSlotOffsets; + int* pi_varNumbers; + int* pi_varOutputCols; + int pi_lastInnerVar; + int pi_lastOuterVar; + int pi_lastScanVar; + List* pi_acessedVarNumbers; + List* pi_sysAttrList; + List* pi_lateAceessVarNumbers; + List* pi_maxOrmin; + List* pi_PackTCopyVars; /* VarList to record those columns what we need to move */ + List* pi_PackLateAccessVarNumbers; /*VarList to record those columns what we need to move in late read cstore + scan.*/ + bool pi_const; + VectorBatch* pi_batch; + vectarget_func jitted_vectarget; /* LLVM function pointer to point to the codegened targetlist expr function */ + VectorBatch* pi_setFuncBatch; +} ProjectionInfo; + +/* + * Function pointer which will be used by LLVM assemble. The created IR functions + * will be added to the actual machine code. + */ +typedef ScalarVector* (*vecqual_func)(ExprContext* econtext); + +/* ---------------- + * JunkFilter + * + * This class is used to store information regarding junk attributes. + * A junk attribute is an attribute in a tuple that is needed only for + * storing intermediate information in the executor, and does not belong + * in emitted tuples. For example, when we do an UPDATE query, + * the planner adds a "junk" entry to the targetlist so that the tuples + * returned to ExecutePlan() contain an extra attribute: the ctid of + * the tuple to be updated. This is needed to do the update, but we + * don't want the ctid to be part of the stored new tuple! So, we + * apply a "junk filter" to remove the junk attributes and form the + * real output tuple. The junkfilter code also provides routines to + * extract the values of the junk attribute(s) from the input tuple. + * + * targetList: the original target list (including junk attributes). + * cleanTupType: the tuple descriptor for the "clean" tuple (with + * junk attributes removed). + * cleanMap: A map with the correspondence between the non-junk + * attribute numbers of the "original" tuple and the + * attribute numbers of the "clean" tuple. + * resultSlot: tuple slot used to hold cleaned tuple. + * junkAttNo: not used by junkfilter code. Can be used by caller + * to remember the attno of a specific junk attribute + * (nodeModifyTable.c keeps the "ctid" or "wholerow" + * attno here). + * ---------------- + */ +typedef struct JunkFilter { + NodeTag type; + List* jf_targetList; + TupleDesc jf_cleanTupType; + AttrNumber* jf_cleanMap; + TupleTableSlot* jf_resultSlot; + AttrNumber jf_junkAttNo; +#ifdef PGXC + /* + * Similar to jf_junkAttNo that is used for ctid, we also need xc_node_id + * and wholerow junk attribute numbers to be saved here. In XC, we need + * multiple junk attributes at the same time, so just jf_junkAttNo is not + * enough. In PG, jf_junkAttNo is used either for ctid or for wholerow, + * it does not need both of them at the same time; ctid is used for physical + * relations while wholerow is used for views. + */ + AttrNumber jf_xc_node_id; + AttrNumber jf_xc_wholerow; + AttrNumber jf_xc_part_id; + AttrNumber jf_xc_bucket_id; + List* jf_primary_keys; +#endif +} JunkFilter; + +typedef struct MergeState { + /* List of MERGE MATCHED action states */ + List* matchedActionStates; + /* List of MERGE NOT MATCHED action states */ + List* notMatchedActionStates; +} MergeState; + +/* ---------------- + * ResultRelInfo information + * + * Whenever we update an existing relation, we have to + * update indices on the relation, and perhaps also fire triggers. + * The ResultRelInfo class is used to hold all the information needed + * about a result relation, including indices.. -cim 10/15/89 + * + * RangeTableIndex result relation's range table index + * RelationDesc relation descriptor for result relation + * NumIndices # of indices existing on result relation + * ri_ContainGPI indices whether contain global parition index + * IndexRelationDescs array of relation descriptors for indices + * IndexRelationInfo array of key/attr info for indices + * TrigDesc triggers to be fired, if any + * TrigFunctions cached lookup info for trigger functions + * TrigWhenExprs array of trigger WHEN expr states + * TrigInstrument optional runtime measurements for triggers + * FdwRoutine FDW callback functions, if foreign table + * FdwState available to save private state of FDW + * ConstraintExprs array of constraint-checking expr states + * junkFilter for removing junk attributes from tuples + * projectReturning for computing a RETURNING list + * updateProj for computing a UPSERT update list + * ---------------- + */ +typedef struct ResultRelInfo { + NodeTag type; + Index ri_RangeTableIndex; + Relation ri_RelationDesc; + int ri_NumIndices; + bool ri_ContainGPI; + RelationPtr ri_IndexRelationDescs; + IndexInfo** ri_IndexRelationInfo; + TriggerDesc* ri_TrigDesc; + FmgrInfo* ri_TrigFunctions; + List** ri_TrigWhenExprs; + Instrumentation* ri_TrigInstrument; + struct FdwRoutine* ri_FdwRoutine; + void* ri_FdwState; + List** ri_ConstraintExprs; + JunkFilter* ri_junkFilter; + AttrNumber ri_partOidAttNum; + AttrNumber ri_bucketIdAttNum; + ProjectionInfo* ri_projectReturning; + + /* for running MERGE on this result relation */ + MergeState* ri_mergeState; + + /* + * While executing MERGE, the target relation is processed twice; once + * as a target relation and once to run a join between the target and the + * source. We generate two different RTEs for these two purposes, one with + * rte->inh set to false and other with rte->inh set to true. + * + * Since the plan re-evaluated by EvalPlanQual uses the join RTE, we must + * install the updated tuple in the scan corresponding to that RTE. The + * following member tracks the index of the second RTE for EvalPlanQual + * purposes. ri_mergeTargetRTI is non-zero only when MERGE is in-progress. + * We use ri_mergeTargetRTI to run EvalPlanQual for MERGE and + * ri_RangeTableIndex elsewhere. + */ + Index ri_mergeTargetRTI; + ProjectionInfo* ri_updateProj; +} ResultRelInfo; + +/* bloom filter controller */ +typedef struct BloomFilterControl { + filter::BloomFilter** bfarray; /* bloom filter array. */ + int array_size; /* bloom filter array size. */ +} BloomFilterControl; + +#define InvalidBktId (-1) /* invalid hash-bucket id */ + +/* ---------------- + * EState information + * + * Master working state for an Executor invocation + * ---------------- + */ +typedef struct EState { + NodeTag type; + + /* Basic state for all query types: */ + ScanDirection es_direction; /* current scan direction */ + Snapshot es_snapshot; /* time qual to use */ + Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ + List* es_range_table; /* List of RangeTblEntry */ + PlannedStmt* es_plannedstmt; /* link to top of plan tree */ + + JunkFilter* es_junkFilter; /* top-level junk filter, if any */ + + /* If query can insert/delete tuples, the command ID to mark them with */ + CommandId es_output_cid; + + /* Info about target table(s) for insert/update/delete queries: */ + ResultRelInfo* es_result_relations; /* array of ResultRelInfos */ + int es_num_result_relations; /* length of array */ + ResultRelInfo* es_result_relation_info; /* currently active array elt */ + + Relation esCurrentPartition; + HTAB* esfRelations; /* do the update,delete , cache the Relation which get from partitionGetRelation */ +#ifdef PGXC + struct PlanState* es_result_remoterel; /* currently active remote rel */ + struct PlanState* es_result_insert_remoterel; /* currently active remote rel */ + struct PlanState* es_result_update_remoterel; /* currently active remote rel */ + struct PlanState* es_result_delete_remoterel; /* currently active remote rel */ +#endif + + /* Stuff used for firing triggers: */ + List* es_trig_target_relations; /* trigger-only ResultRelInfos */ + TupleTableSlot* es_trig_tuple_slot; /* for trigger output tuples */ + TupleTableSlot* es_trig_oldtup_slot; /* for TriggerEnabled */ + TupleTableSlot* es_trig_newtup_slot; /* for TriggerEnabled */ + + /* Parameter info: */ + ParamListInfo es_param_list_info; /* values of external params */ + ParamExecData* es_param_exec_vals; /* values of internal params */ + + /* Other working state: */ + MemoryContext es_query_cxt; /* per-query context in which EState lives */ + MemoryContext es_const_query_cxt; /* const per-query context used to create node context */ + + List* es_tupleTable; /* List of TupleTableSlots */ + + List* es_rowMarks; /* List of ExecRowMarks */ + + uint64 es_processed; /* # of tuples processed */ + + uint64 es_last_processed; /* last value of es_processed for ModifyTable plan*/ + + Oid es_lastoid; /* last oid processed (by INSERT) */ + + int es_top_eflags; /* eflags passed to ExecutorStart */ + int es_instrument; /* OR of InstrumentOption flags */ + bool es_finished; /* true when ExecutorFinish is done */ + + List* es_exprcontexts; /* List of ExprContexts within EState */ + + List* es_subplanstates; /* List of PlanState for SubPlans */ + + List* es_auxmodifytables; /* List of secondary ModifyTableStates */ + + List* es_remotequerystates; /* List of RemoteQueryStates */ + + /* + * this ExprContext is for per-output-tuple operations, such as constraint + * checks and index-value computations. It will be reset for each output + * tuple. Note that it will be created only if needed. + */ + ExprContext* es_per_tuple_exprcontext; + + /* + * These fields are for re-evaluating plan quals when an updated tuple is + * substituted in READ COMMITTED mode. es_epqTuple[] contains tuples that + * scan plan nodes should return instead of whatever they'd normally + * return, or NULL if nothing to return; es_epqTupleSet[] is true if a + * particular array entry is valid; and es_epqScanDone[] is state to + * remember if the tuple has been returned already. Arrays are of size + * list_length(es_range_table) and are indexed by scan node scanrelid - 1. + */ + HeapTuple* es_epqTuple; /* array of EPQ substitute tuples */ + bool* es_epqTupleSet; /* true if EPQ tuple is provided */ + bool* es_epqScanDone; /* true if EPQ tuple has been fetched */ + + List* es_subplan_ids; + bool es_skip_early_free; /* true if we don't apply early free mechanisim, especially for subplan */ + /* true if we don't apply early-free-consumer mechanisim, especially for subplan */ + bool es_skip_early_deinit_consumer; + bool es_under_subplan; /* true if operator is under a subplan */ + List* es_material_of_subplan; /* List of Materialize operator of subplan */ + bool es_recursive_next_iteration; /* true if under recursive-stream and need to rescan. */ + + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + */ + Index dataDestRelIndex; + + BloomFilterControl es_bloom_filter; /* bloom filter controller */ + + bool es_can_realtime_statistics; /* true if can realime statistics */ + bool es_can_history_statistics; /* true if can history statistics */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ +#ifdef ENABLE_MOT + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif +} EState; + +/* + * ExecRowMark - + * runtime representation of FOR UPDATE/SHARE clauses + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we should have an + * ExecRowMark for each non-target relation in the query (except inheritance + * parent RTEs, which can be ignored at runtime). See PlanRowMark for details + * about most of the fields. In addition to fields directly derived from + * PlanRowMark, we store curCtid, which is used by the WHERE CURRENT OF code. + * + * EState->es_rowMarks is a list of these structs. + */ +typedef struct ExecRowMark { + Relation relation; /* opened and suitably locked relation */ + Index rti; /* its range table index */ + Index prti; /* parent range table index, if child */ + Index rowmarkId; /* unique identifier for resjunk columns */ + RowMarkType markType; /* see enum in nodes/plannodes.h */ + bool noWait; /* NOWAIT option */ + ItemPointerData curCtid; /* ctid of currently locked tuple, if any */ + int numAttrs; /* number of attributes in subplan */ +} ExecRowMark; + +/* + * ExecAuxRowMark - + * additional runtime representation of FOR UPDATE/SHARE clauses + * + * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to + * deal with. In addition to a pointer to the related entry in es_rowMarks, + * this struct carries the column number(s) of the resjunk columns associated + * with the rowmark (see comments for PlanRowMark for more detail). In the + * case of ModifyTable, there has to be a separate ExecAuxRowMark list for + * each child plan, because the resjunk columns could be at different physical + * column positions in different subplans. + */ +typedef struct ExecAuxRowMark { + ExecRowMark* rowmark; /* related entry in es_rowMarks */ + AttrNumber ctidAttNo; /* resno of ctid junk attribute, if any */ + AttrNumber toidAttNo; /* resno of tableoid junk attribute, if any */ + AttrNumber tbidAttNo; /* resno of bucketid junk attribute, if any */ + AttrNumber wholeAttNo; /* resno of whole-row junk attribute, if any */ +} ExecAuxRowMark; + +/* ---------------------------------------------------------------- + * Tuple Hash Tables + * + * All-in-memory tuple hash tables are used for a number of purposes. + * + * Note: tab_hash_funcs are for the key datatype(s) stored in the table, + * and tab_eq_funcs are non-cross-type equality operators for those types. + * Normally these are the only functions used, but FindTupleHashEntry() + * supports searching a hashtable using cross-data-type hashing. For that, + * the caller must supply hash functions for the LHS datatype as well as + * the cross-type equality operators to use. in_hash_funcs and cur_eq_funcs + * are set to point to the caller's function arrays while doing such a search. + * During LookupTupleHashEntry(), they point to tab_hash_funcs and + * tab_eq_funcs respectively. + * ---------------------------------------------------------------- + */ +typedef struct TupleHashEntryData* TupleHashEntry; +typedef struct TupleHashTableData* TupleHashTable; + +typedef struct TupleHashEntryData { + /* firstTuple must be the first field in this struct! */ + MinimalTuple firstTuple; /* copy of first tuple in this group */ + /* there may be additional data beyond the end of this struct */ +} TupleHashEntryData; /* VARIABLE LENGTH STRUCT */ + +typedef struct TupleHashTableData { + HTAB* hashtab; /* underlying dynahash table */ + int numCols; /* number of columns in lookup key */ + AttrNumber* keyColIdx; /* attr numbers of key columns */ + FmgrInfo* tab_hash_funcs; /* hash functions for table datatype(s) */ + FmgrInfo* tab_eq_funcs; /* equality functions for table datatype(s) */ + MemoryContext tablecxt; /* memory context containing table */ + MemoryContext tempcxt; /* context for function evaluations */ + Size entrysize; /* actual size to make each hash entry */ + TupleTableSlot* tableslot; /* slot for referencing table entries */ + /* The following fields are set transiently for each table search: */ + TupleTableSlot* inputslot; /* current input tuple's slot */ + FmgrInfo* in_hash_funcs; /* hash functions for input datatype(s) */ + FmgrInfo* cur_eq_funcs; /* equality functions for input vs. table */ + int64 width; /* records total width in memory */ + bool add_width; /* if width should be added */ + bool causedBySysRes; /* the batch increase caused by system resources limit? */ +} TupleHashTableData; + +typedef HASH_SEQ_STATUS TupleHashIterator; + +/* + * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan. + * Use ResetTupleHashIterator if the table can be frozen (in this case no + * explicit scan termination is needed). + */ +#define InitTupleHashIterator(htable, iter) hash_seq_init(iter, (htable)->hashtab) +#define TermTupleHashIterator(iter) hash_seq_term(iter) +#define ResetTupleHashIterator(htable, iter) \ + do { \ + hash_freeze((htable)->hashtab); \ + hash_seq_init(iter, (htable)->hashtab); \ + } while (0) +#define ScanTupleHashTable(iter) ((TupleHashEntry)hash_seq_search(iter)) + +/* ---------------------------------------------------------------- + * Expression State Trees + * + * Each executable expression tree has a parallel ExprState tree. + * + * Unlike PlanState, there is not an exact one-for-one correspondence between + * ExprState node types and Expr node types. Many Expr node types have no + * need for node-type-specific run-time state, and so they can use plain + * ExprState or GenericExprState as their associated ExprState node type. + * ---------------------------------------------------------------- + */ + +/* ---------------- + * ExprState node + * + * ExprState is the common superclass for all ExprState-type nodes. + * + * It can also be instantiated directly for leaf Expr nodes that need no + * local run-time state (such as Var, Const, or Param). + * + * To save on dispatch overhead, each ExprState node contains a function + * pointer to the routine to execute to evaluate the node. + * ---------------- + */ +typedef struct ExprState ExprState; + +typedef Datum (*ExprStateEvalFunc)(ExprState* expression, ExprContext* econtext, bool* isNull, ExprDoneCond* isDone); +typedef ScalarVector* (*VectorExprFun)( + ExprState* expression, ExprContext* econtext, bool* selVector, ScalarVector* inputVector, ExprDoneCond* isDone); + +typedef void* (*exprFakeCodeGenSig)(void*); +struct ExprState { + NodeTag type; + Expr* expr; /* associated Expr node */ + ExprStateEvalFunc evalfunc; /* routine to run to execute node */ + + // vectorized evaluator + // + VectorExprFun vecExprFun; + + exprFakeCodeGenSig exprCodeGen; /* routine to run llvm assembler function */ + + ScalarVector tmpVector; + + Oid resultType; +}; + +/* ---------------- + * GenericExprState node + * + * This is used for Expr node types that need no local run-time state, + * but have one child Expr node. + * ---------------- + */ +typedef struct GenericExprState { + ExprState xprstate; + ExprState* arg; /* state of my child node */ +} GenericExprState; + +/* ---------------- + * WholeRowVarExprState node + * ---------------- + */ +typedef struct WholeRowVarExprState { + ExprState xprstate; + struct PlanState* parent; /* parent PlanState, or NULL if none */ + JunkFilter* wrv_junkFilter; /* JunkFilter to remove resjunk cols */ +} WholeRowVarExprState; + +/* ---------------- + * AggrefExprState node + * ---------------- + */ +typedef struct AggrefExprState { + ExprState xprstate; + List* aggdirectargs; /* states of direct-argument expressions */ + List* args; /* states of argument expressions */ + ExprState* aggfilter; /* state of FILTER expression, if any */ + int aggno; /* ID number for agg within its plan node */ + + // Vectorized aggregation fields + // + int m_htbOffset; // offset in the hash table +} AggrefExprState; + +/* ---------------- + * WindowFuncExprState node + * ---------------- + */ +typedef struct WindowFuncExprState { + ExprState xprstate; + List* args; /* states of argument expressions */ + int wfuncno; /* ID number for wfunc within its plan node */ + + // Vectorized aggregation fields + // + ScalarVector* m_resultVector; +} WindowFuncExprState; + +/* ---------------- + * ArrayRefExprState node + * + * Note: array types can be fixed-length (typlen > 0), but only when the + * element type is itself fixed-length. Otherwise they are varlena structures + * and have typlen = -1. In any case, an array type is never pass-by-value. + * ---------------- + */ +typedef struct ArrayRefExprState { + ExprState xprstate; + List* refupperindexpr; /* states for child nodes */ + List* reflowerindexpr; + ExprState* refexpr; + ExprState* refassgnexpr; + int16 refattrlength; /* typlen of array type */ + int16 refelemlength; /* typlen of the array element type */ + bool refelembyval; /* is the element type pass-by-value? */ + char refelemalign; /* typalign of the element type */ +} ArrayRefExprState; + +/* ---------------- + * FuncExprState node + * + * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr, + * and NullIf nodes; be careful to check what xprstate.expr is actually + * pointing at! + * ---------------- + */ +typedef struct FuncExprState { + ExprState xprstate; + List* args; /* states of argument expressions */ + + /* + * Function manager's lookup info for the target function. If func.fn_oid + * is InvalidOid, we haven't initialized it yet (nor any of the following + * fields). + */ + FmgrInfo func; + + /* + * For a set-returning function (SRF) that returns a tuplestore, we keep + * the tuplestore here and dole out the result rows one at a time. The + * slot holds the row currently being returned. + */ + Tuplestorestate* funcResultStore; + TupleTableSlot* funcResultSlot; + + /* + * In some cases we need to compute a tuple descriptor for the function's + * output. If so, it's stored here. + */ + TupleDesc funcResultDesc; + bool funcReturnsTuple; /* valid when funcResultDesc isn't + * NULL */ + + /* + * setArgsValid is true when we are evaluating a set-returning function + * that uses value-per-call mode and we are in the middle of a call + * series; we want to pass the same argument values to the function again + * (and again, until it returns ExprEndResult). This indicates that + * fcinfo_data already contains valid argument data. + */ + bool setArgsValid; + + /* + * Flag to remember whether we found a set-valued argument to the + * function. This causes the function result to be a set as well. Valid + * only when setArgsValid is true or funcResultStore isn't NULL. + */ + bool setHasSetArg; /* some argument returns a set */ + + /* + * Flag to remember whether we have registered a shutdown callback for + * this FuncExprState. We do so only if funcResultStore or setArgsValid + * has been set at least once (since all the callback is for is to release + * the tuplestore or clear setArgsValid). + */ + bool shutdown_reg; /* a shutdown callback is registered */ + + /* + * Call parameter structure for the function. This has been initialized + * (by InitFunctionCallInfoData) if func.fn_oid is valid. It also saves + * argument values between calls, when setArgsValid is true. + */ + FunctionCallInfoData fcinfo_data; + + ScalarVector* tmpVec; +} FuncExprState; + +/* ---------------- + * ScalarArrayOpExprState node + * + * This is a FuncExprState plus some additional data. + * ---------------- + */ +typedef struct ScalarArrayOpExprState { + FuncExprState fxprstate; + /* Cached info about array element type */ + Oid element_type; + int16 typlen; + bool typbyval; + char typalign; + bool* pSel; /* selection used to fast path of ALL/ANY */ + ScalarVector *tmpVecLeft; + ScalarVector *tmpVecRight; + ScalarVector* tmpVec; +} ScalarArrayOpExprState; + +/* ---------------- + * BoolExprState node + * ---------------- + */ +typedef struct BoolExprState { + ExprState xprstate; + List* args; /* states of argument expression(s) */ + + bool tmpSelection[BatchMaxSize]; // temp selection +} BoolExprState; + +/* ---------------- + * SubPlanState node + * ---------------- + */ +typedef struct SubPlanState { + ExprState xprstate; + struct PlanState* planstate; /* subselect plan's state tree */ + ExprState* testexpr; /* state of combining expression */ + List* args; /* states of argument expression(s) */ + ExprState* row_testexpr; /* for vector hash subplan */ + HeapTuple curTuple; /* copy of most recent tuple from subplan */ + Datum curArray; /* most recent array from ARRAY() subplan */ + /* these are used when hashing the subselect's output: */ + ProjectionInfo* projLeft; /* for projecting lefthand exprs */ + ProjectionInfo* projRight; /* for projecting subselect output */ + TupleHashTable hashtable; /* hash table for no-nulls subselect rows */ + TupleHashTable hashnulls; /* hash table for rows with null(s) */ + bool havehashrows; /* TRUE if hashtable is not empty */ + bool havenullrows; /* TRUE if hashnulls is not empty */ + MemoryContext hashtablecxt; /* memory context containing hash tables */ + MemoryContext hashtempcxt; /* temp memory context for hash tables */ + ExprContext* innerecontext; /* econtext for computing inner tuples */ + AttrNumber* keyColIdx; /* control data for hash tables */ + FmgrInfo* tab_hash_funcs; /* hash functions for table datatype(s) */ + FmgrInfo* tab_eq_funcs; /* equality functions for table datatype(s) */ + FmgrInfo* lhs_hash_funcs; /* hash functions for lefthand datatype(s) */ + FmgrInfo* cur_eq_funcs; /* equality functions for LHS vs. table */ + + /* for vector engine */ + int idx; /* a index to indicate which parameter to be pushed */ + ScalarVector** pParamVectorArray; /* a array to store the param data */ + ScalarVector** pParamVectorTmp; /* a temporary place to store the para data pointer */ + bool* pSel; /* selection used to fast path */ + VectorBatch* outExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* innerExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* scanExprBatch; /* a batch for only one row to store the para data for vector expr */ + VectorBatch* aggExprBatch; /* a batch for only one row to store the para data for vector expr */ + ScalarVector* tempvector; /* a temp vector for vector expression */ + MemoryContext ecxt_per_batch_memory; /* memory contexts for one batch */ +} SubPlanState; + +/* ---------------- + * AlternativeSubPlanState node + * ---------------- + */ +typedef struct AlternativeSubPlanState { + ExprState xprstate; + List* subplans; /* states of alternative subplans */ + int active; /* list index of the one we're using */ +} AlternativeSubPlanState; + +/* ---------------- + * FieldSelectState node + * ---------------- + */ +typedef struct FieldSelectState { + ExprState xprstate; + ExprState* arg; /* input expression */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} FieldSelectState; + +/* ---------------- + * FieldStoreState node + * ---------------- + */ +typedef struct FieldStoreState { + ExprState xprstate; + ExprState* arg; /* input tuple value */ + List* newvals; /* new value(s) for field(s) */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} FieldStoreState; + +/* ---------------- + * CoerceViaIOState node + * ---------------- + */ +typedef struct CoerceViaIOState { + ExprState xprstate; + ExprState* arg; /* input expression */ + FmgrInfo outfunc; /* lookup info for source output function */ + FmgrInfo infunc; /* lookup info for result input function */ + Oid intypioparam; /* argument needed for input function */ +} CoerceViaIOState; + +/* ---------------- + * ArrayCoerceExprState node + * ---------------- + */ +typedef struct ArrayCoerceExprState { + ExprState xprstate; + ExprState* arg; /* input array value */ + Oid resultelemtype; /* element type of result array */ + FmgrInfo elemfunc; /* lookup info for element coercion function */ + /* use struct pointer to avoid including array.h here */ + struct ArrayMapState* amstate; /* workspace for array_map */ +} ArrayCoerceExprState; + +/* ---------------- + * ConvertRowtypeExprState node + * ---------------- + */ +typedef struct ConvertRowtypeExprState { + ExprState xprstate; + ExprState* arg; /* input tuple value */ + TupleDesc indesc; /* tupdesc for source rowtype */ + TupleDesc outdesc; /* tupdesc for result rowtype */ + /* use "struct" so we needn't include tupconvert.h here */ + struct TupleConversionMap* map; + bool initialized; +} ConvertRowtypeExprState; + +/* ---------------- + * CaseExprState node + * ---------------- + */ +typedef struct CaseExprState { + ExprState xprstate; + ExprState* arg; /* implicit equality comparison argument */ + List* args; /* the arguments (list of WHEN clauses) */ + ExprState* defresult; /* the default result (ELSE clause) */ + bool* matchedResult; + bool* localSel; + ScalarVector* save_vector; +} CaseExprState; + +/* ---------------- + * CaseWhenState node + * ---------------- + */ +typedef struct CaseWhenState { + ExprState xprstate; + ExprState* expr; /* condition expression */ + ExprState* result; /* substitution result */ +} CaseWhenState; + +/* ---------------- + * ArrayExprState node + * + * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length + * arrays. + * ---------------- + */ +typedef struct ArrayExprState { + ExprState xprstate; + List* elements; /* states for child nodes */ + int16 elemlength; /* typlen of the array element type */ + bool elembyval; /* is the element type pass-by-value? */ + char elemalign; /* typalign of the element type */ +} ArrayExprState; + +/* ---------------- + * RowExprState node + * ---------------- + */ +typedef struct RowExprState { + ExprState xprstate; + List* args; /* the arguments */ + TupleDesc tupdesc; /* descriptor for result tuples */ + VectorBatch* rowBatch; /* Save need columns */ +} RowExprState; + +/* ---------------- + * RowCompareExprState node + * ---------------- + */ +typedef struct RowCompareExprState { + ExprState xprstate; + List* largs; /* the left-hand input arguments */ + List* rargs; /* the right-hand input arguments */ + FmgrInfo* funcs; /* array of comparison function info */ + Oid* collations; /* array of collations to use */ + + FunctionCallInfoData* cinfo; + + ScalarVector* left_argvec; /* the left-hand input vector arguments */ + ScalarVector* right_argvec; /* the right-hand input vector arguments */ + ScalarVector* cmpresult; /* vector for compare result */ + bool* pSel; /* vector for marking arguments to calculation */ +} RowCompareExprState; + +/* ---------------- + * CoalesceExprState node + * ---------------- + */ +typedef struct CoalesceExprState { + ExprState xprstate; + List* args; /* the arguments */ + bool* pSel; /* selection used to fast path */ +} CoalesceExprState; + +/* ---------------- + * MinMaxExprState node + * ---------------- + */ +typedef struct MinMaxExprState { + ExprState xprstate; + List* args; /* the arguments */ + FmgrInfo cfunc; /* lookup info for comparison func */ + FunctionCallInfoData cinfo; + + ScalarVector* argvec; /* eval arg results */ + ScalarVector* cmpresult; + bool* pSel; +} MinMaxExprState; + +/* ---------------- + * XmlExprState node + * ---------------- + */ +typedef struct XmlExprState { + ExprState xprstate; + List* named_args; /* ExprStates for named arguments */ + List* args; /* ExprStates for other arguments */ +} XmlExprState; + +/* ---------------- + * NullTestState node + * ---------------- + */ +typedef struct NullTestState { + ExprState xprstate; + ExprState* arg; /* input expression */ + /* used only if input is of composite type: */ + TupleDesc argdesc; /* tupdesc for most recent input */ +} NullTestState; + +/* ---------------- + * HashFilterState node + * ---------------- + */ +typedef struct HashFilterState { + ExprState xprstate; + List* arg; /* input expression */ + uint2* nodelist; /* Node indices where data is located */ + uint2* bucketMap; +} HashFilterState; + +/* ---------------- + * CoerceToDomainState node + * ---------------- + */ +typedef struct CoerceToDomainState { + ExprState xprstate; + ExprState* arg; /* input expression */ + /* Cached list of constraints that need to be checked */ + List* constraints; /* list of DomainConstraintState nodes */ +} CoerceToDomainState; + +/* + * DomainConstraintState - one item to check during CoerceToDomain + * + * Note: this is just a Node, and not an ExprState, because it has no + * corresponding Expr to link to. Nonetheless it is part of an ExprState + * tree, so we give it a name following the xxxState convention. + */ +typedef enum DomainConstraintType { DOM_CONSTRAINT_NOTNULL, DOM_CONSTRAINT_CHECK } DomainConstraintType; + +typedef struct DomainConstraintState { + NodeTag type; + DomainConstraintType constrainttype; /* constraint type */ + char* name; /* name of constraint (for error msgs) */ + ExprState* check_expr; /* for CHECK, a boolean expression */ +} DomainConstraintState; + +typedef struct HbktScanSlot { + int currSlot; +} HbktScanSlot; + +/* ---------------------------------------------------------------- + * Executor State Trees + * + * An executing query has a PlanState tree paralleling the Plan tree + * that describes the plan. + * ---------------------------------------------------------------- + */ +typedef enum { + PST_None = 0, + PST_Norm = 1, + PST_Scan = 2 +} PlanStubType; + +/* ---------------- + * PlanState node + * + * We never actually instantiate any PlanState nodes; this is just the common + * abstract superclass for all PlanState-type nodes. + * ---------------- + */ +typedef struct PlanState { + NodeTag type; + + Plan* plan; /* associated Plan node */ + + EState* state; /* at execution time, states of individual + * nodes point to one EState for the whole + * top-level plan */ + + Instrumentation* instrument; /* Optional runtime stats for this node */ + + /* + * Common structural data for all Plan types. These links to subsidiary + * state trees parallel links in the associated plan tree (except for the + * subPlan list, which does not exist in the plan tree). + */ + List* targetlist; /* target list to be computed at this node */ + List* qual; /* implicitly-ANDed qual conditions */ + struct PlanState* lefttree; /* input plan tree(s) */ + struct PlanState* righttree; + List* initPlan; /* Init SubPlanState nodes (un-correlated expr subselects) */ + List* subPlan; /* SubPlanState nodes in my expressions */ + + /* + * State for management of parameter-change-driven rescanning + */ + Bitmapset* chgParam; /* set of IDs of changed Params */ + HbktScanSlot hbktScanSlot; + + /* + * Other run-time state needed by most if not all node types. + */ + TupleTableSlot* ps_ResultTupleSlot; /* slot for my result tuples */ + ExprContext* ps_ExprContext; /* node's expression-evaluation context */ + ProjectionInfo* ps_ProjInfo; /* info for doing tuple projection */ + bool ps_TupFromTlist; /* state flag for processing set-valued functions in targetlist */ + + bool vectorized; // is vectorized? + + MemoryContext nodeContext; /* Memory Context for this Node */ + + bool earlyFreed; /* node memory already freed? */ + uint8 stubType; /* node stub execution type, see @PlanStubType */ + vectarget_func jitted_vectarget; /* LLVM IR function pointer to point to the codegened targetlist expr. */ + + /* + * Describe issues found in curernt plan node, mainly used for issue de-duplication + * of data skew and inaccurate e-rows + */ + List* plan_issues; + bool recursive_reset; /* node already reset? */ + bool qual_is_inited; + + int64 ps_rownum; /* store current rownum */ +} PlanState; + +static inline bool planstate_need_stub(PlanState* ps) +{ + return ps->stubType != PST_None; +} + +/* ---------------- + * these are defined to avoid confusion problems with "left" + * and "right" and "inner" and "outer". The convention is that + * the "left" plan is the "outer" plan and the "right" plan is + * the inner plan, but these make the code more readable. + * ---------------- + */ +#define innerPlanState(node) (((PlanState*)(node))->righttree) +#define outerPlanState(node) (((PlanState*)(node))->lefttree) + +/* Macros for inline access to certain instrumentation counters */ +#define InstrCountFiltered1(node, delta) \ + do { \ + if (((PlanState*)(node))->instrument) \ + ((PlanState*)(node))->instrument->nfiltered1 += (delta); \ + } while (0) +#define InstrCountFiltered2(node, delta) \ + do { \ + if (((PlanState*)(node))->instrument) \ + ((PlanState*)(node))->instrument->nfiltered2 += (delta); \ + } while (0) + +/* + * EPQState is state for executing an EvalPlanQual recheck on a candidate + * tuple in ModifyTable or LockRows. The estate and planstate fields are + * NULL if inactive. + */ +typedef struct EPQState { + EState* estate; /* subsidiary EState */ + PlanState* planstate; /* plan state tree ready to be executed */ + TupleTableSlot* origslot; /* original output tuple to be rechecked */ + Plan* plan; /* plan tree to be executed */ + List* arowMarks; /* ExecAuxRowMarks (non-locking only) */ + int epqParam; /* ID of Param to force scan node re-eval */ +} EPQState; + +/* ---------------- + * ResultState information + * ---------------- + */ +typedef struct ResultState { + PlanState ps; /* its first field is NodeTag */ + ExprState* resconstantqual; + bool rs_done; /* are we done? */ + bool rs_checkqual; /* do we need to check the qual? */ +} ResultState; + +/* ---------------- + * MergeActionState information + * ---------------- + */ +typedef struct MergeActionState { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + ExprState* whenqual; /* WHEN AND conditions */ + CmdType commandType; /* INSERT/UPDATE/DELETE/DO NOTHING */ + ProjectionInfo* proj; /* tuple projection info */ + TupleDesc tupDesc; /* tuple descriptor for projection */ + JunkFilter* junkfilter; /* junkfilter for UPDATE */ + VectorBatch* scanBatch; /* scan batch for UPDATE */ +} MergeActionState; + +/* ---------------- + * UpsertState information + * ---------------- + */ +typedef struct UpsertState +{ + NodeTag type; + UpsertAction us_action; /* Flags showing DUPLICATE UPDATE NOTHING or SOMETHING */ + TupleTableSlot *us_existing; /* slot to store existing target tuple in */ + List *us_excludedtlist; /* the excluded pseudo relation's tlist */ + TupleTableSlot *us_updateproj; /* slot to update */ +} UpsertState; + +/* ---------------- + * ModifyTableState information + * ---------------- + */ +typedef struct ModifyTableState { + PlanState ps; /* its first field is NodeTag */ + CmdType operation; /* INSERT, UPDATE, or DELETE */ + bool canSetTag; /* do we set the command tag/es_processed? */ + bool mt_done; /* are we done? */ + PlanState** mt_plans; /* subplans (one per target rel) */ +#ifdef PGXC + PlanState** mt_remoterels; /* per-target remote query node */ + PlanState** mt_insert_remoterels; /* per-target remote query node */ + PlanState** mt_update_remoterels; /* per-target remote query node */ + PlanState** mt_delete_remoterels; /* per-target remote query node */ +#endif + int mt_nplans; /* number of plans in the array */ + int mt_whichplan; /* which one is being executed (0..n-1) */ + ResultRelInfo* resultRelInfo; /* per-subplan target relations */ + List** mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ + EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ + bool fireBSTriggers; /* do we need to fire stmt triggers? */ + Relation delete_delta_rel; /* for online expansion's delete data catchup */ + + // For error table + // + Relation errorRel; + ErrorCacheEntry* cacheEnt; + + TupleTableSlot* mt_scan_slot; + TupleTableSlot* mt_update_constr_slot; /* slot to store target tuple in for checking constraints */ + TupleTableSlot* mt_insert_constr_slot; /* slot to store target tuple in for checking constraints */ + TupleTableSlot* mt_mergeproj; /* MERGE action projection target */ + uint32 mt_merge_subcommands; /* Flags showing which subcommands are present INS/UPD/DEL/DO NOTHING */ + UpsertState* mt_upsert; /* DUPLICATE KEY UPDATE evaluation state */ + instr_time first_tuple_modified; /* record the end time for the first tuple inserted, deleted, or updated */ +} ModifyTableState; + +typedef struct CopyFromManagerData* CopyFromManager; + +typedef struct DistInsertSelectState { + ModifyTableState mt; + int rows; + MemoryContext insert_mcxt; + CopyFromManager mgr; + BulkInsertState bistate; + PageCompress* pcState; +} DistInsertSelectState; + +/* ---------------- + * AppendState information + * + * nplans how many plans are in the array + * whichplan which plan is being executed (0 .. n-1) + * ---------------- + */ +typedef struct AppendState { + PlanState ps; /* its first field is NodeTag */ + PlanState** appendplans; /* array of PlanStates for my inputs */ + int as_nplans; + int as_whichplan; +} AppendState; + +/* ---------------- + * MergeAppendState information + * + * nplans how many plans are in the array + * nkeys number of sort key columns + * sortkeys sort keys in SortSupport representation + * slots current output tuple of each subplan + * heap heap of active tuples (represented as array indexes) + * heap_size number of active heap entries + * initialized true if we have fetched first tuple from each subplan + * last_slot last subplan fetched from (which must be re-called) + * ---------------- + */ +typedef struct MergeAppendState { + PlanState ps; /* its first field is NodeTag */ + PlanState** mergeplans; /* array of PlanStates for my inputs */ + int ms_nplans; + int ms_nkeys; + SortSupport ms_sortkeys; /* array of length ms_nkeys */ + TupleTableSlot** ms_slots; /* array of length ms_nplans */ + int* ms_heap; /* array of length ms_nplans */ + int ms_heap_size; /* current active length of ms_heap[] */ + bool ms_initialized; /* are subplans started? */ + int ms_last_slot; /* last subplan slot we returned from */ +} MergeAppendState; + +/* ---------------- + * RecursiveUnionState information + * + * RecursiveUnionState is used for performing a recursive union. + * + * recursing T when we're done scanning the non-recursive term + * intermediate_empty T if intermediate_table is currently empty + * working_table working table (to be scanned by recursive term) + * intermediate_table current recursive output (next generation of WT) + * ---------------- + */ +struct RecursiveUnionController; +typedef struct RecursiveUnionState { + PlanState ps; /* its first field is NodeTag */ + bool recursing; + bool intermediate_empty; + Tuplestorestate* working_table; + Tuplestorestate* intermediate_table; + int iteration; + /* Remaining fields are unused in UNION ALL case */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + MemoryContext tempContext; /* short-term context for comparisons */ + TupleHashTable hashtable; /* hash table for tuples already seen */ + MemoryContext tableContext; /* memory context containing hash table */ + + /* + * MPP with-recursive support + */ + /* Distributed with-recursive execution controller for current RecursiveUnion operator */ + RecursiveUnionController* rucontroller; + + /* record the number of tuples that produced by current iteration step */ + uint64 step_tuple_produced; + + /* + * The share memory context pointer that is used in distributed recursive CTE + * processing where WorkTable is access via different stream threads, we need + * put it on higher level of memory context to persists the whole query runing + * stage. + */ + MemoryContext shareContext; +} RecursiveUnionState; + +/* ---------------- + * BitmapAndState information + * ---------------- + */ +typedef struct BitmapAndState { + PlanState ps; /* its first field is NodeTag */ + PlanState** bitmapplans; /* array of PlanStates for my inputs */ + int nplans; /* number of input plans */ +} BitmapAndState; + +/* ---------------- + * BitmapOrState information + * ---------------- + */ +typedef struct BitmapOrState { + PlanState ps; /* its first field is NodeTag */ + PlanState** bitmapplans; /* array of PlanStates for my inputs */ + int nplans; /* number of input plans */ +} BitmapOrState; + +/* ---------------------------------------------------------------- + * Run time predicate information + * ---------------------------------------------------------------- + */ +typedef struct RunTimeParamPredicateInfo { + ExprState* paraExecExpr; /* internal executor parameter predicate information. */ + Expr* opExpr; /* the operator expression */ + AttrNumber varNoPos; /* an order number in the hdfsScanPredicateArr. */ + int32 typeMod; /* var typmode. */ + Oid datumType; /* the parameter data type. */ + Oid varTypeOid; /* var type oid. */ + int32 paramPosition; /* the parameter predicate position in *hdfsScanPredicateArr. */ +} RunTimeParamPredicateInfo; + +/* ---------------- + * SampleScanInfo information + * ---------------- + */ +typedef struct SampleScanParams { + List* args; /* expr states for TABLESAMPLE params */ + ExprState* repeatable; /* expr state for REPEATABLE expr */ + TableSampleType sampleType; /* sample scan type.*/ + /* use struct pointer to avoid including tsmapi.h here */ + void* tsm_state; /* tablesample method can keep state here */ +} SampleScanParams; + +/* ---------------------------------------------------------------- + * Scan State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * ScanState information + * + * ScanState extends PlanState for node types that represent + * scans of an underlying relation. It can also be used for nodes + * that scan the output of an underlying plan node --- in that case, + * only ScanTupleSlot is actually useful, and it refers to the tuple + * retrieved from the subplan. + * + * currentRelation relation being scanned (NULL if none) + * currentScanDesc current scan descriptor for scan (NULL if none) + * ScanTupleSlot pointer to slot in tuple table holding scan tuple + * ---------------- + */ +struct ScanState; +struct SeqScanAccessor; + +/* + * prototypes from functions in execScan.c + */ +typedef TupleTableSlot *(*ExecScanAccessMtd) (ScanState *node); +typedef bool(*ExecScanRecheckMtd) (ScanState *node, TupleTableSlot *slot); + +typedef struct ScanState { + PlanState ps; /* its first field is NodeTag */ + Relation ss_currentRelation; + TableScanDesc ss_currentScanDesc; + TupleTableSlot* ss_ScanTupleSlot; + bool ss_ReScan; + Relation ss_currentPartition; + bool isPartTbl; + int currentSlot; /* current iteration position */ + ScanDirection partScanDirection; + List* partitions; /* list of Partition */ + LOCKMODE lockMode; + List* runTimeParamPredicates; + bool runTimePredicatesReady; + bool is_scan_end; /* @hdfs Mark whether iterator is over or not, if the scan uses informational constraint. */ + SeqScanAccessor* ss_scanaccessor; /* prefetch related */ + int part_id; + int startPartitionId; /* start partition id for parallel threads. */ + int endPartitionId; /* end partition id for parallel threads. */ + RangeScanInRedis rangeScanInRedis; /* if it is a range scan in redistribution time */ + bool isSampleScan; /* identify is it table sample scan or not. */ + SampleScanParams sampleScanInfo; /* TABLESAMPLE params include type/seed/repeatable. */ + ExecScanAccessMtd ScanNextMtd; +} ScanState; + +/* + * SeqScan uses a bare ScanState as its state node, since it needs + * no additional fields. + */ +typedef ScanState SeqScanState; + +/* + * These structs store information about index quals that don't have simple + * constant right-hand sides. See comments for ExecIndexBuildScanKeys() + * for discussion. + */ +typedef struct { + ScanKey scan_key; /* scankey to put value into */ + ExprState* key_expr; /* expr to evaluate to get value */ + bool key_toastable; /* is expr's result a toastable datatype? */ +} IndexRuntimeKeyInfo; + +typedef struct { + ScanKey scan_key; /* scankey to put value into */ + ExprState* array_expr; /* expr to evaluate to get array value */ + int next_elem; /* next array element to use */ + int num_elems; /* number of elems in current array value */ + Datum* elem_values; /* array of num_elems Datums */ + bool* elem_nulls; /* array of num_elems is-null flags */ +} IndexArrayKeyInfo; + +/* ---------------- + * IndexScanState information + * + * indexqualorig execution state for indexqualorig expressions + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * OrderByKeys Skey structures for index ordering operators + * NumOrderByKeys number of OrderByKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * ---------------- + */ +typedef struct IndexScanState { + ScanState ss; /* its first field is NodeTag */ + List* indexqualorig; + ScanKey iss_ScanKeys; + int iss_NumScanKeys; + ScanKey iss_OrderByKeys; + int iss_NumOrderByKeys; + IndexRuntimeKeyInfo* iss_RuntimeKeys; + int iss_NumRuntimeKeys; + bool iss_RuntimeKeysReady; + ExprContext* iss_RuntimeContext; + Relation iss_RelationDesc; + IndexScanDesc iss_ScanDesc; + List* iss_IndexPartitionList; + LOCKMODE lockMode; + Relation iss_CurrentIndexPartition; + int part_id; +} IndexScanState; + +/* ---------------- + * IndexOnlyScanState information + * + * indexqual execution state for indexqual expressions + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * OrderByKeys Skey structures for index ordering operators + * NumOrderByKeys number of OrderByKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * VMBuffer buffer in use for visibility map testing, if any + * HeapFetches number of tuples we were forced to fetch from heap + * ---------------- + */ +typedef struct IndexOnlyScanState { + ScanState ss; /* its first field is NodeTag */ + List* indexqual; + ScanKey ioss_ScanKeys; + int ioss_NumScanKeys; + ScanKey ioss_OrderByKeys; + int ioss_NumOrderByKeys; + IndexRuntimeKeyInfo* ioss_RuntimeKeys; + int ioss_NumRuntimeKeys; + bool ioss_RuntimeKeysReady; + ExprContext* ioss_RuntimeContext; + Relation ioss_RelationDesc; + IndexScanDesc ioss_ScanDesc; + Buffer ioss_VMBuffer; + long ioss_HeapFetches; + List* ioss_IndexPartitionList; + LOCKMODE lockMode; + Relation ioss_CurrentIndexPartition; + int part_id; +} IndexOnlyScanState; + +/* ---------------- + * BitmapIndexScanState information + * + * result bitmap to return output into, or NULL + * ScanKeys Skey structures for index quals + * NumScanKeys number of ScanKeys + * RuntimeKeys info about Skeys that must be evaluated at runtime + * NumRuntimeKeys number of RuntimeKeys + * ArrayKeys info about Skeys that come from ScalarArrayOpExprs + * NumArrayKeys number of ArrayKeys + * RuntimeKeysReady true if runtime Skeys have been computed + * RuntimeContext expr context for evaling runtime Skeys + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor + * ---------------- + */ +typedef struct BitmapIndexScanState { + ScanState ss; /* its first field is NodeTag */ + TIDBitmap* biss_result; + ScanKey biss_ScanKeys; + int biss_NumScanKeys; + IndexRuntimeKeyInfo* biss_RuntimeKeys; + int biss_NumRuntimeKeys; + IndexArrayKeyInfo* biss_ArrayKeys; + int biss_NumArrayKeys; + bool biss_RuntimeKeysReady; + ExprContext* biss_RuntimeContext; + Relation biss_RelationDesc; + IndexScanDesc biss_ScanDesc; + List* biss_IndexPartitionList; + LOCKMODE lockMode; + Relation biss_CurrentIndexPartition; + int part_id; +} BitmapIndexScanState; + +/* ---------------- + * BitmapHeapScanState information + * + * bitmapqualorig execution state for bitmapqualorig expressions + * tbm bitmap obtained from child index scan(s) + * tbmiterator iterator for scanning current pages + * tbmres current-page data + * prefetch_iterator iterator for prefetching ahead of current page + * prefetch_pages # pages prefetch iterator is ahead of current + * prefetch_target target prefetch distance + * ---------------- + */ +typedef struct BitmapHeapScanState { + ScanState ss; /* its first field is NodeTag */ + List* bitmapqualorig; + TIDBitmap* tbm; + TBMIterator* tbmiterator; + TBMIterateResult* tbmres; + TBMIterator* prefetch_iterator; + int prefetch_pages; + int prefetch_target; + GPIScanDesc gpi_scan; /* global partition index scan use information */ + int part_id; +} BitmapHeapScanState; + +/* ---------------- + * TidScanState information + * + * isCurrentOf scan has a CurrentOfExpr qual + * NumTids number of tids in this scan + * TidPtr index of currently fetched tid + * TidList evaluated item pointers (array of size NumTids) + * ---------------- + */ +typedef struct TidScanState { + ScanState ss; /* its first field is NodeTag */ + List* tss_tidquals; /* list of ExprState nodes */ + bool tss_isCurrentOf; + Relation tss_CurrentOf_CurrentPartition; + int tss_NumTids; + int tss_TidPtr; + int tss_MarkTidPtr; + ItemPointerData* tss_TidList; + HeapTupleData tss_htup; + /* put decompressed tuple data into tss_ctbuf_hdr be careful , when malloc memory should give extra mem for + *xs_ctbuf_hdr. t_bits which is varlength arr */ + HeapTupleHeaderData tss_ctbuf_hdr; +} TidScanState; + +#define SizeofTidScanState (offsetof(TidScanState, tss_ctbuf_hdr) + SizeofHeapTupleHeader) + +/* ---------------- + * SubqueryScanState information + * + * SubqueryScanState is used for scanning a sub-query in the range table. + * ScanTupleSlot references the current output tuple of the sub-query. + * ---------------- + */ +typedef struct SubqueryScanState { + ScanState ss; /* its first field is NodeTag */ + PlanState* subplan; +} SubqueryScanState; + +/* ---------------- + * FunctionScanState information + * + * Function nodes are used to scan the results of a + * function appearing in FROM (typically a function returning set). + * + * eflags node's capability flags + * tupdesc expected return tuple description + * tuplestorestate private state of tuplestore.c + * funcexpr state for function expression being evaluated + * ---------------- + */ +typedef struct FunctionScanState { + ScanState ss; /* Its first field is NodeTag */ + int eflags; + TupleDesc tupdesc; + Tuplestorestate* tuplestorestate; + ExprState* funcexpr; + bool atomic; /* Atomic execution context, does not allow transactions */ +} FunctionScanState; + +/* ---------------- + * ValuesScanState information + * + * ValuesScan nodes are used to scan the results of a VALUES list + * + * rowcontext per-expression-list context + * exprlists array of expression lists being evaluated + * array_len size of array + * curr_idx current array index (0-based) + * marked_idx marked position (for mark/restore) + * + * Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection + * expressions attached to the node. We create a second ExprContext, + * rowcontext, in which to build the executor expression state for each + * Values sublist. Resetting this context lets us get rid of expression + * state for each row, avoiding major memory leakage over a long values list. + * ---------------- + */ +typedef struct ValuesScanState { + ScanState ss; /* its first field is NodeTag */ + ExprContext* rowcontext; + List** exprlists; + int array_len; + int curr_idx; + int marked_idx; +} ValuesScanState; + +/* ---------------- + * CteScanState information + * + * CteScan nodes are used to scan a CommonTableExpr query. + * + * Multiple CteScan nodes can read out from the same CTE query. We use + * a tuplestore to hold rows that have been read from the CTE query but + * not yet consumed by all readers. + * ---------------- + */ +typedef struct CteScanState { + ScanState ss; /* its first field is NodeTag */ + int eflags; /* capability flags to pass to tuplestore */ + int readptr; /* index of my tuplestore read pointer */ + PlanState* cteplanstate; /* PlanState for the CTE query itself */ + /* Link to the "leader" CteScanState (possibly this same node) */ + struct CteScanState* leader; + /* The remaining fields are only valid in the "leader" CteScanState */ + Tuplestorestate* cte_table; /* rows already read from the CTE query */ + bool eof_cte; /* reached end of CTE query? */ +} CteScanState; + +/* ---------------- + * WorkTableScanState information + * + * WorkTableScan nodes are used to scan the work table created by + * a RecursiveUnion node. We locate the RecursiveUnion node + * during executor startup. + * ---------------- + */ +typedef struct WorkTableScanState { + ScanState ss; /* its first field is NodeTag */ + RecursiveUnionState* rustate; +} WorkTableScanState; + +/* ---------------- + * ForeignScanState information + * + * ForeignScan nodes are used to scan foreign-data tables. + * ---------------- + */ +typedef struct ForeignScanState { + ScanState ss; /* its first field is NodeTag */ + /* use struct pointer to avoid including fdwapi.h here */ + struct FdwRoutine* fdwroutine; + void* fdw_state; /* foreign-data wrapper can keep state here */ + + MemoryContext scanMcxt; + + ForeignOptions* options; +} ForeignScanState; + +/* ---------------- + * ExtensiblePlanState information + * + * ExtensiblePlan nodes are used to execute extensible code within executor. + * + * Core code must avoid assuming that the ExtensiblePlanState is only as large as + * the structure declared here; providers are allowed to make it the first + * element in a larger structure, and typically would need to do so. The + * struct is actually allocated by the CreateExtensiblePlanState method associated + * with the plan node. Any additional fields can be initialized there, or in + * the BeginExtensiblePlan method. + * ---------------- + */ +struct ExplainState; /* avoid including explain.h here */ +struct ExtensiblePlanState; + +typedef struct ExtensibleExecMethods { + const char* ExtensibleName; + + /* Executor methods: mark/restore are optional, the rest are required */ + void (*BeginExtensiblePlan)(struct ExtensiblePlanState* node, EState* estate, int eflags); + TupleTableSlot* (*ExecExtensiblePlan)(struct ExtensiblePlanState* node); + void (*EndExtensiblePlan)(struct ExtensiblePlanState* node); + void (*ReScanExtensiblePlan)(struct ExtensiblePlanState* node); + void (*ExplainExtensiblePlan)(struct ExtensiblePlanState* node, List* ancestors, struct ExplainState* es); +} ExtensibleExecMethods; + +typedef struct ExtensiblePlanState { + ScanState ss; + uint32 flags; /* mask of EXTENSIBLEPATH_* flags, see relation.h */ + List* extensible_ps; /* list of child PlanState nodes, if any */ + const ExtensibleExecMethods* methods; +} ExtensiblePlanState; + +/* ---------------------------------------------------------------- + * Join State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * JoinState information + * + * Superclass for state nodes of join plans. + * ---------------- + */ +typedef struct JoinState { + PlanState ps; + JoinType jointype; + List* joinqual; /* JOIN quals (in addition to ps.qual) */ + List* nulleqqual; +} JoinState; + +/* ---------------- + * NestLoopState information + * + * NeedNewOuter true if need new outer tuple on next call + * MatchedOuter true if found a join match for current outer tuple + * NullInnerTupleSlot prepared null tuple for left outer joins + * ---------------- + */ +typedef struct NestLoopState { + JoinState js; /* its first field is NodeTag */ + bool nl_NeedNewOuter; + bool nl_MatchedOuter; + bool nl_MaterialAll; + TupleTableSlot* nl_NullInnerTupleSlot; +} NestLoopState; + +/* ---------------- + * MergeJoinState information + * + * NumClauses number of mergejoinable join clauses + * Clauses info for each mergejoinable clause + * JoinState current state of ExecMergeJoin state machine + * ExtraMarks true to issue extra Mark operations on inner scan + * ConstFalseJoin true if we have a constant-false joinqual + * FillOuter true if should emit unjoined outer tuples anyway + * FillInner true if should emit unjoined inner tuples anyway + * MatchedOuter true if found a join match for current outer tuple + * MatchedInner true if found a join match for current inner tuple + * OuterTupleSlot slot in tuple table for cur outer tuple + * InnerTupleSlot slot in tuple table for cur inner tuple + * MarkedTupleSlot slot in tuple table for marked tuple + * NullOuterTupleSlot prepared null tuple for right outer joins + * NullInnerTupleSlot prepared null tuple for left outer joins + * OuterEContext workspace for computing outer tuple's join values + * InnerEContext workspace for computing inner tuple's join values + * ---------------- + */ +/* private in nodeMergejoin.c: */ +typedef struct MergeJoinClauseData* MergeJoinClause; + +typedef struct MergeJoinState { + JoinState js; /* its first field is NodeTag */ + int mj_NumClauses; + MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */ + int mj_JoinState; + bool mj_ExtraMarks; + bool mj_ConstFalseJoin; + bool mj_FillOuter; + bool mj_FillInner; + bool mj_MatchedOuter; + bool mj_MatchedInner; + TupleTableSlot* mj_OuterTupleSlot; + TupleTableSlot* mj_InnerTupleSlot; + TupleTableSlot* mj_MarkedTupleSlot; + TupleTableSlot* mj_NullOuterTupleSlot; + TupleTableSlot* mj_NullInnerTupleSlot; + ExprContext* mj_OuterEContext; + ExprContext* mj_InnerEContext; +} MergeJoinState; + +struct MergeJoinShared { + JoinState js; /* its first field is NodeTag */ + int mj_NumClauses; + int mj_JoinState; + bool mj_ExtraMarks; + bool mj_ConstFalseJoin; + bool mj_FillOuter; + bool mj_FillInner; + bool mj_MatchedOuter; + bool mj_MatchedInner; +}; + +/* private in vecmergejoin.cpp: */ +typedef struct VecMergeJoinClauseData* VecMergeJoinClause; + +// Mark the offset of a row in a batch +// It is the same with integer and we rely on compiler to generate efficient +// code for structure copy. +struct MJBatchOffset { + // offset in the batch, starting from zero + uint16 m_offset; + + // Flag: is it actually representing an empty row? + bool m_fEmpty; + // Flag: is the offset pointing to the marked batch? + bool m_fMarked; + // batch sequence: ok to wrap around + int m_batchSeq; +}; + +struct BatchAccessor { + // child query to retrieve data + PlanState* m_plan; + // Current offset. It also points to the batch the offset is against. + // The maxOffset is used to detect the end of the batch. + VectorBatch* m_curBatch; + int m_batchSeq; + int m_curOffset; + int m_maxOffset; +}; + +struct VecMergeJoinState : public MergeJoinShared { + // Vectorization run support + VecMergeJoinClause mj_Clauses; + MJBatchOffset mj_OuterOffset; + MJBatchOffset mj_InnerOffset; + ExprContext* mj_OuterEContext; + ExprContext* mj_InnerEContext; + // Marked batch and offset. We need both to represent a marked row. + MJBatchOffset mj_MarkedOffset; + VectorBatch* mj_MarkedBatch; + + // Input batches (inner: 0, outer: 1). We record current progress on the + // input batches here. + BatchAccessor m_inputs[2]; + + // Previous batch join status. This is needed as some join types need + // to look backward to decide if we shall output current tuples. + MJBatchOffset m_prevInnerOffset; + bool m_prevInnerQualified; + MJBatchOffset m_prevOuterOffset; + bool m_prevOuterQualified; + + // Result batch and intermediate results. pInner and pOuter hold the join + // candiates passed the join key checks. + bool m_fDone; + VectorBatch* m_pInnerMatch; + MJBatchOffset* m_pInnerOffset; + VectorBatch* m_pOuterMatch; + MJBatchOffset* m_pOuterOffset; + VectorBatch* m_pCurrentBatch; + VectorBatch* m_pReturnBatch; + vecqual_func jitted_joinqual; /* LLVM IR function pointer to point to codegened mj_joinqualexpr */ +}; + +/* ---------------- + * HashJoinState information + * + * hashclauses original form of the hashjoin condition + * hj_OuterHashKeys the outer hash keys in the hashjoin condition + * hj_InnerHashKeys the inner hash keys in the hashjoin condition + * hj_HashOperators the join operators in the hashjoin condition + * hj_HashTable hash table for the hashjoin + * (NULL if table not built yet) + * hj_CurHashValue hash value for current outer tuple + * hj_CurBucketNo regular bucket# for current outer tuple + * hj_CurSkewBucketNo skew bucket# for current outer tuple + * hj_CurTuple last inner tuple matched to current outer + * tuple, or NULL if starting search + * (hj_CurXXX variables are undefined if + * OuterTupleSlot is empty!) + * hj_OuterTupleSlot tuple slot for outer tuples + * hj_HashTupleSlot tuple slot for inner (hashed) tuples + * hj_NullOuterTupleSlot prepared null tuple for right/full outer joins + * hj_NullInnerTupleSlot prepared null tuple for left/full outer joins + * hj_FirstOuterTupleSlot first tuple retrieved from outer plan + * hj_JoinState current state of ExecHashJoin state machine + * hj_MatchedOuter true if found a join match for current outer + * hj_OuterNotEmpty true if outer relation known not empty + * ---------------- + */ +/* these structs are defined in executor/hashjoin.h: */ +typedef struct HashJoinTupleData* HashJoinTuple; +typedef struct HashJoinTableData* HashJoinTable; + +typedef struct HashJoinState { + JoinState js; /* its first field is NodeTag */ + List* hashclauses; /* list of ExprState nodes */ + List* hj_OuterHashKeys; /* list of ExprState nodes */ + List* hj_InnerHashKeys; /* list of ExprState nodes */ + List* hj_HashOperators; /* list of operator OIDs */ + HashJoinTable hj_HashTable; + uint32 hj_CurHashValue; + int hj_CurBucketNo; + int hj_CurSkewBucketNo; + HashJoinTuple hj_CurTuple; + /* pointer which follows hj_CurTuple help us to delete matched tuples in HashTable.designed for Right Semi/Anti Join */ + HashJoinTuple hj_PreTuple; + TupleTableSlot* hj_OuterTupleSlot; + TupleTableSlot* hj_HashTupleSlot; + TupleTableSlot* hj_NullOuterTupleSlot; + TupleTableSlot* hj_NullInnerTupleSlot; + TupleTableSlot* hj_FirstOuterTupleSlot; + int hj_JoinState; + bool hj_MatchedOuter; + bool hj_OuterNotEmpty; + bool hj_streamBothSides; + bool hj_rebuildHashtable; +} HashJoinState; + +/* ---------------------------------------------------------------- + * Materialization State Information + * ---------------------------------------------------------------- + */ + +/* ---------------- + * MaterialState information + * + * materialize nodes are used to materialize the results + * of a subplan into a temporary file. + * + * ss.ss_ScanTupleSlot refers to output of underlying plan. + * ---------------- + */ +typedef struct MaterialState { + ScanState ss; /* its first field is NodeTag */ + int eflags; /* capability flags to pass to tuplestore */ + bool eof_underlying; /* reached end of underlying plan? */ + bool materalAll; + Tuplestorestate* tuplestorestate; +} MaterialState; + +/* ---------------- + * SortState information + * ---------------- + */ +typedef struct SortState { + ScanState ss; /* its first field is NodeTag */ + bool randomAccess; /* need random access to sort output? */ + bool bounded; /* is the result set bounded? */ + int64 bound; /* if bounded, how many tuples are needed */ + bool sort_Done; /* sort completed yet? */ + bool bounded_Done; /* value of bounded we did the sort with */ + int64 bound_Done; /* value of bound we did the sort with */ + void* tuplesortstate; /* private state of tuplesort.c */ + int32 local_work_mem; /* work_mem local for this sort */ + int sortMethodId; /* sort method for explain */ + int spaceTypeId; /* space type for explain */ + long spaceUsed; /* space used for explain */ + int64* space_size; /* spill size for temp table */ +} SortState; + +/* --------------------- + * GroupState information + * ------------------------- + */ +typedef struct GroupState { + ScanState ss; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-field lookup data for equality fns */ + bool grp_done; /* indicates completion of Group scan */ +} GroupState; + +/* --------------------- + * AggState information + * + * ss.ss_ScanTupleSlot refers to output of underlying plan. + * + * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and + * ecxt_aggnulls arrays, which hold the computed agg values for the current + * input group during evaluation of an Agg node's output tuple(s). We + * create a second ExprContext, tmpcontext, in which to evaluate input + * expressions and run the aggregate transition functions. + * ------------------------- + */ +/* these structs are private in nodeAgg.c: */ +typedef struct AggStatePerAggData* AggStatePerAgg; +typedef struct AggStatePerGroupData* AggStatePerGroup; +typedef struct AggStatePerPhaseData* AggStatePerPhase; + +typedef struct AggState { + ScanState ss; /* its first field is NodeTag */ + List* aggs; /* all Aggref nodes in targetlist & quals */ + int numaggs; /* length of list (could be zero!) */ + AggStatePerPhase phase; /* pointer to current phase data */ + int numphases; /* number of phases */ + int current_phase; /* current phase number */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + AggStatePerAgg peragg; /* per-Aggref information */ + MemoryContext* aggcontexts; /* memory context for long-lived data */ + ExprContext* tmpcontext; /* econtext for input expressions */ + AggStatePerAgg curperagg; /* identifies currently active aggregate */ + bool input_done; /* indicates end of input */ + bool agg_done; /* indicates completion of Agg scan */ + int projected_set; /* The last projected grouping set */ + int current_set; /* The current grouping set being evaluated */ + Bitmapset* grouped_cols; /* grouped cols in current projection */ + List* all_grouped_cols; /* list of all grouped cols in DESC order */ + /* These fields are for grouping set phase data */ + int maxsets; /* The max number of sets in any phase */ + AggStatePerPhase phases; /* array of all phases */ + Tuplesortstate* sort_in; /* sorted input to phases > 0 */ + Tuplesortstate* sort_out; /* input is copied here for next phase */ + TupleTableSlot* sort_slot; /* slot for sort results */ + /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */ + AggStatePerGroup pergroup; /* per-Aggref-per-group working state */ + HeapTuple grp_firstTuple; /* copy of first tuple of current group */ + /* these fields are used in AGG_HASHED mode: */ + TupleHashTable hashtable; /* hash table with one entry per group */ + TupleTableSlot* hashslot; /* slot for loading hash table */ + List* hash_needed; /* list of columns needed in hash table */ + bool table_filled; /* hash table filled yet? */ + TupleHashIterator hashiter; /* for iterating through hash table */ +#ifdef PGXC + bool is_final; /* apply the final step for aggregates */ +#endif /* PGXC */ + void* aggTempFileControl; + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ +} AggState; + +/* ---------------- + * WindowAggState information + * ---------------- + */ +/* these structs are private in nodeWindowAgg.c: */ +typedef struct WindowStatePerFuncData* WindowStatePerFunc; +typedef struct WindowStatePerAggData* WindowStatePerAgg; + +typedef struct WindowAggState { + ScanState ss; /* its first field is NodeTag */ + + /* these fields are filled in by ExecInitExpr: */ + List* funcs; /* all WindowFunc nodes in targetlist */ + int numfuncs; /* total number of window functions */ + int numaggs; /* number that are plain aggregates */ + + WindowStatePerFunc perfunc; /* per-window-function information */ + WindowStatePerAgg peragg; /* per-plain-aggregate information */ + FmgrInfo* partEqfunctions; /* equality funcs for partition columns */ + FmgrInfo* ordEqfunctions; /* equality funcs for ordering columns */ + Tuplestorestate* buffer; /* stores rows of current partition */ + int current_ptr; /* read pointer # for current */ + int64 spooled_rows; /* total # of rows in buffer */ + int64 currentpos; /* position of current row in partition */ + int64 frameheadpos; /* current frame head position */ + int64 frametailpos; /* current frame tail position */ + /* use struct pointer to avoid including windowapi.h here */ + struct WindowObjectData* agg_winobj; /* winobj for aggregate fetches */ + int64 aggregatedbase; /* start row for current aggregates */ + int64 aggregatedupto; /* rows before this one are aggregated */ + + int frameOptions; /* frame_clause options, see WindowDef */ + ExprState* startOffset; /* expression for starting bound offset */ + ExprState* endOffset; /* expression for ending bound offset */ + Datum startOffsetValue; /* result of startOffset evaluation */ + Datum endOffsetValue; /* result of endOffset evaluation */ + + MemoryContext partcontext; /* context for partition-lifespan data */ + MemoryContext aggcontext; /* context for each aggregate data */ + ExprContext* tmpcontext; /* short-term evaluation context */ + + bool all_first; /* true if the scan is starting */ + bool all_done; /* true if the scan is finished */ + bool partition_spooled; /* true if all tuples in current partition have been spooled into tuplestore */ + bool more_partitions; /* true if there's more partitions after this one */ + bool framehead_valid; /* true if frameheadpos is known up to date for current row */ + bool frametail_valid; /* true if frametailpos is known up to date for current row */ + + TupleTableSlot* first_part_slot; /* first tuple of current or next partition */ + + /* temporary slots for tuples fetched back from tuplestore */ + TupleTableSlot* agg_row_slot; + TupleTableSlot* temp_slot_1; + TupleTableSlot* temp_slot_2; +} WindowAggState; + +/* ---------------- + * OrderedSetAggState information + * ---------------- + */ +typedef struct OrderedSetAggState { + AggState* aggstate; + Aggref* aggref; /* Keep the agg info for start up used */ + Tuplesortstate* sortstate; /* Used for accumulate sort datum */ + int64 number_of_rows; /* Number of normal datum inside sortstate */ + TupleDesc tupdesc; /* Tuple descriptor for datum inside sortstate */ + + Oid datumtype; /* Datatype of datums being sorted */ + int16 typLen; + bool typByVal; + char typAlign; + Oid eq_operator; /* Equality operator associated with sort operator */ + char sign; /* Sign for orderedSetAggState */ +} OrderedSetAggState; + +/* ---------------- + * UniqueState information + * + * Unique nodes are used "on top of" sort nodes to discard + * duplicate tuples returned from the sort phase. Basically + * all it does is compare the current tuple from the subplan + * with the previously fetched tuple (stored in its result slot). + * If the two are identical in all interesting fields, then + * we just fetch another tuple from the sort and try again. + * ---------------- + */ +typedef struct UniqueState { + PlanState ps; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-field lookup data for equality fns */ + MemoryContext tempContext; /* short-term context for comparisons */ +} UniqueState; + +/* ---------------- + * HashState information + * ---------------- + */ +typedef struct HashState { + PlanState ps; /* its first field is NodeTag */ + HashJoinTable hashtable; /* hash table for the hashjoin */ + List* hashkeys; /* list of ExprState nodes */ + int32 local_work_mem; /* work_mem local for this hash join */ + int64 spill_size; + + /* hashkeys is same as parent's hj_InnerHashKeys */ +} HashState; + +/* ---------------- + * SetOpState information + * + * Even in "sorted" mode, SetOp nodes are more complex than a simple + * Unique, since we have to count how many duplicates to return. But + * we also support hashing, so this is really more like a cut-down + * form of Agg. + * ---------------- + */ +/* this struct is private in nodeSetOp.c: */ +typedef struct SetOpStatePerGroupData* SetOpStatePerGroup; + +typedef struct SetOpState { + PlanState ps; /* its first field is NodeTag */ + FmgrInfo* eqfunctions; /* per-grouping-field equality fns */ + FmgrInfo* hashfunctions; /* per-grouping-field hash fns */ + bool setop_done; /* indicates completion of output scan */ + long numOutput; /* number of dups left to output */ + MemoryContext tempContext; /* short-term context for comparisons */ + /* these fields are used in SETOP_SORTED mode: */ + SetOpStatePerGroup pergroup; /* per-group working state */ + HeapTuple grp_firstTuple; /* copy of first tuple of current group */ + /* these fields are used in SETOP_HASHED mode: */ + TupleHashTable hashtable; /* hash table with one entry per group */ + MemoryContext tableContext; /* memory context containing hash table */ + bool table_filled; /* hash table filled yet? */ + TupleHashIterator hashiter; /* for iterating through hash table */ + void* TempFileControl; + int64 spill_size; +} SetOpState; + +/* ---------------- + * LockRowsState information + * + * LockRows nodes are used to enforce FOR UPDATE/FOR SHARE locking. + * ---------------- + */ +typedef struct LockRowsState { + PlanState ps; /* its first field is NodeTag */ + List* lr_arowMarks; /* List of ExecAuxRowMarks */ + EPQState lr_epqstate; /* for evaluating EvalPlanQual rechecks */ +} LockRowsState; + +/* ---------------- + * LimitState information + * + * Limit nodes are used to enforce LIMIT/OFFSET clauses. + * They just select the desired subrange of their subplan's output. + * + * offset is the number of initial tuples to skip (0 does nothing). + * count is the number of tuples to return after skipping the offset tuples. + * If no limit count was specified, count is undefined and noCount is true. + * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet. + * ---------------- + */ +typedef enum { + LIMIT_INITIAL, /* initial state for LIMIT node */ + LIMIT_RESCAN, /* rescan after recomputing parameters */ + LIMIT_EMPTY, /* there are no returnable rows */ + LIMIT_INWINDOW, /* have returned a row in the window */ + LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */ + LIMIT_WINDOWEND, /* stepped off end of window */ + LIMIT_WINDOWSTART /* stepped off beginning of window */ +} LimitStateCond; + +typedef struct LimitState { + PlanState ps; /* its first field is NodeTag */ + ExprState* limitOffset; /* OFFSET parameter, or NULL if none */ + ExprState* limitCount; /* COUNT parameter, or NULL if none */ + int64 offset; /* current OFFSET value */ + int64 count; /* current COUNT, if any */ + bool noCount; /* if true, ignore count */ + LimitStateCond lstate; /* state machine status, as above */ + int64 position; /* 1-based index of last tuple returned */ + TupleTableSlot* subSlot; /* tuple last obtained from subplan */ +} LimitState; + +/* + * Target : data partition + * Brief : structure definition about partition iteration + */ +typedef struct PartIteratorState { + PlanState ps; /* its first field is NodeTag */ + int currentItr; /* the sequence number for processing partition */ +} PartIteratorState; + +struct VecLimitState : public LimitState { + VectorBatch* subBatch; +}; + +/* + * RownumState node: used for computing the pseudo-column ROWNUM + */ +typedef struct RownumState { + ExprState xprstate; + PlanState* ps; /* the value of ROWNUM depends on its parent PlanState */ +} RownumState; + +/* ---------------- + * GroupingFuncExprState node + * + * The list of column numbers refers to the input tuples of the Agg node to + * which the GroupingFunc belongs, and may contain 0 for references to columns + * that are only present in grouping sets processed by different Agg nodes (and + * which are therefore always considered "grouping" here). + * ---------------- + */ +typedef struct GroupingFuncExprState { + ExprState xprstate; + AggState* aggstate; + List* clauses; /* integer list of column numbers */ +} GroupingFuncExprState; + +typedef struct GroupingIdExprState { + ExprState xprstate; + AggState* aggstate; +} GroupingIdExprState; + +/* + * used by CstoreInsert and DfsInsert in nodeModifyTable.h and vecmodifytable.cpp + */ +#define FLUSH_DATA(obj, type) \ + do { \ + ((type*)obj)->SetEndFlag(); \ + ((type*)obj)->BatchInsert((VectorBatch*)NULL, 0); \ + ((type*)obj)->EndBatchInsert(); \ + ((type*)obj)->Destroy(); \ + delete (type*)obj; \ + } while (0) + +/* + * used by TsStoreInsert in nodeModifyTable.h and vecmodifytable.cpp + */ +#define FLUSH_DATA_TSDB(obj, type) \ + do{ \ + ((type*)obj)->BatchInsert((VectorBatch*)NULL, 0); \ + ((type*)obj)->end_batch_insert(); \ + ((type*)obj)->Destroy(); \ + }while(0) +/* + * record the first tuple time used by INSERT, UPDATE and DELETE in ExecModifyTable and ExecVecModifyTable + */ +#define record_first_time() \ + do { \ + if (unlikely(is_first_modified)) { \ + INSTR_TIME_SET_CURRENT(node->first_tuple_modified); \ + is_first_modified = false; \ + } \ + } while (0) + +extern TupleTableSlot* ExecMakeTupleSlot(Tuple tuple, TableScanDesc tableScan, TupleTableSlot* slot, TableAmType tableAm); + +/* + * When the global partition index is used for bitmap scanning, + * checks whether the partition table needs to be + * switched each time an tbmres is obtained. + */ +inline bool BitmapNodeNeedSwitchPartRel(BitmapHeapScanState* node) +{ + return tbm_is_global(node->tbm) && GPIScanCheckPartOid(node->gpi_scan, node->tbmres->partitionOid); +} + +extern RangeScanInRedis reset_scan_qual(Relation currHeapRel, ScanState *node); + +#endif /* EXECNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/nodes/feparser_memutils.h postgresql-hll-2.14/include/nodes/feparser_memutils.h --- postgresql-hll-2.14_old/include/nodes/feparser_memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/feparser_memutils.h 2020-12-12 17:06:43.319348967 +0800 @@ -0,0 +1,23 @@ +/* + * fe_memutils.h + * memory management support for frontend code + * + * Copyright (c) 2003-2015, PostgreSQL Global Development Group + * + * src/include/common/fe_memutils.h + */ +#ifndef FEPARSER_MEMUTILS_H +#define FEPARSER_MEMUTILS_H +#ifdef FRONTEND_PARSER +/* + * "Safe" memory allocation functions --- these exit(1) on failure + */ +char *feparser_strdup(const char *in); +void *feparser_malloc(size_t size); +void *feparser_malloc0(size_t size); +void *feparser_malloc_extended(size_t size, int flags); +void *feparser_realloc(void *pointer, size_t size); +void feparser_free(void *pointer); +void free_memory(); +#endif +#endif /* FEPARSER_MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/makefuncs.h postgresql-hll-2.14/include/nodes/makefuncs.h --- postgresql-hll-2.14_old/include/nodes/makefuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/makefuncs.h 2020-12-12 17:06:43.319348967 +0800 @@ -0,0 +1,87 @@ +/* ------------------------------------------------------------------------- + * + * makefuncs.h + * prototypes for the creator functions (for primitive nodes) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/makefuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MAKEFUNC_H +#define MAKEFUNC_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#include "nodes/execnodes.h" +#else +#include "datatypes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "nodes/parsenodes_common.h" +#endif /* FRONTEND_PARSER */ + +extern Const *makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, + bool constisnull, bool constbyval, Cursor_Data *cur = NULL); + +#ifndef FRONTEND_PARSER + +extern Var* makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup); + +extern Var* makeVarFromTargetEntry(Index varno, TargetEntry* tle); + +extern Var* makeWholeRowVar(RangeTblEntry* rte, Index varno, Index varlevelsup, bool allowScalar); + +extern TargetEntry* makeTargetEntry(Expr* expr, AttrNumber resno, char* resname, bool resjunk); + +extern TargetEntry* flatCopyTargetEntry(TargetEntry* src_tle); + +extern FromExpr* makeFromExpr(List* fromlist, Node* quals); + +extern ColumnRef* makeColumnRef(char* relname, char* colname, int location); + +extern Const* makeMaxConst(Oid consttype, int32 consttypmod, Oid constcollid); + +extern Node* makeNullAConst(int location); + +extern Const* makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid); + +extern Node* makeBoolConst(bool value, bool isnull); + +extern Expr* makeBoolExpr(BoolExprType boolop, List* args, int location); + +extern Alias* makeAlias(const char* aliasname, List* colnames); + +extern RelabelType* makeRelabelType(Expr* arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat); + +extern TypeName* makeTypeNameFromOid(Oid typeOid, int32 typmod); + +extern FuncExpr* makeFuncExpr( + Oid funcid, Oid rettype, List* args, Oid funccollid, Oid inputcollid, CoercionForm fformat); + +extern NullTest* makeNullTest(NullTestType type, Expr* expr); +extern Expr* makeBoolExprTreeNode(BoolExprType boolop, List* args); +extern HashFilter* makeHashFilter(List* arg, List* typeOidlist, List* nodelist); +extern Node* makeTidConst(ItemPointer item); +extern FuncCall* makeFuncCall(List* funcname, List* args, int location); +extern Param* makeParam( + ParamKind paramkind, int paramid, Oid paramtype, int32 paramtypmod, Oid paramcollid, int location); +extern IndexInfo* makeIndexInfo(int numattrs, List *expressions, List *predicates, + bool unique, bool isready, bool concurrent); + +#endif /* !FRONTEND_PARSER */ +extern A_Expr *makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location); +extern A_Expr *makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location); +extern RangeVar *makeRangeVar(char *schemaname, char *relname, int location); +extern TypeName *makeTypeName(char *typnam); +extern TypeName *makeTypeNameFromNameList(List *names); +extern DefElem *makeDefElem(char *name, Node *arg); +extern DefElem *makeDefElemExtended(char *nameSpace, char *name, Node *arg, DefElemAction defaction); +extern GroupingSet *makeGroupingSet(GroupingSetKind kind, List *content, int location); + +#endif /* MAKEFUNC_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/memnodes.h postgresql-hll-2.14/include/nodes/memnodes.h --- postgresql-hll-2.14_old/include/nodes/memnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/memnodes.h 2020-12-12 17:06:43.319348967 +0800 @@ -0,0 +1,268 @@ +/* ------------------------------------------------------------------------- + * + * memnodes.h + * POSTGRES memory context node definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/memnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMNODES_H +#define MEMNODES_H + +#include "nodes/nodes.h" +#include "nodes/pg_list.h" + +/* + * MemoryContext + * A logical context in which memory allocations occur. + * + * MemoryContext itself is an abstract type that can have multiple + * implementations, though for now we have only AllocSetContext. + * The function pointers in MemoryContextMethods define one specific + * implementation of MemoryContext --- they are a virtual function table + * in C++ terms. + * + * Node types that are actual implementations of memory contexts must + * begin with the same fields as MemoryContext. + * + * Note: for largely historical reasons, typedef MemoryContext is a pointer + * to the context struct rather than the struct type itself. + */ +typedef struct MemoryContextMethods { + void* (*alloc)(MemoryContext context, Size align, Size size, const char* file, int line); + /* call this free_p in case someone #define's free() */ + void (*free_p)(MemoryContext context, void* pointer); + void* (*realloc)(MemoryContext context, void* pointer, Size align, Size size, const char* file, int line); + void (*init)(MemoryContext context); + void (*reset)(MemoryContext context); + void (*delete_context)(MemoryContext context); + Size (*get_chunk_space)(MemoryContext context, void* pointer); + bool (*is_empty)(MemoryContext context); + void (*stats)(MemoryContext context, int level); +#ifdef MEMORY_CONTEXT_CHECKING + void (*check)(MemoryContext context); +#endif +} MemoryContextMethods; + +typedef struct MemoryTrackData* MemoryTrack; /* forward reference */ + +typedef struct MemoryTrackData { + NodeTag type; /* identifies exact kind of context */ + MemoryTrack parent; /* NULL if no parent (toplevel context) */ + MemoryTrack firstchild; /* head of linked list of children */ + MemoryTrack nextchild; /* next child of same parent */ + char* name; /* context name */ + Size peakSpace; /* the peak bytes allocated by this context */ + Size allBytesPeak; /* the peak bytes allocated by this and its children's context */ + Size allBytesAlloc; /* all bytes allocated by this and its children's context */ + Size allBytesFreed; /* all bytes freed by this and its children's context */ + int sequentCount; /* the sequent count when creating in the thread */ +#ifdef MEMORY_CONTEXT_CHECKING + bool isTracking; /* flag to indicate which is tracked by memory_detail_tracking setting */ +#endif +} MemoryTrackData; + +typedef struct MemoryContextData { + NodeTag type; /* identifies exact kind of context */ + MemoryContextMethods* methods; /* virtual function table */ + MemoryContext parent; /* NULL if no parent (toplevel context) */ + MemoryContext firstchild; /* head of linked list of children */ + MemoryContext prevchild; /* previous child of same parent */ + MemoryContext nextchild; /* next child of same parent */ + char* name; /* context name (just for debugging) */ + pthread_rwlock_t lock; /* lock to protect members if the context is shared */ + bool is_sealed; /* sealed context prevent any memory change */ + bool is_shared; /* context is shared by threads */ + bool isReset; /* T = no space alloced since last reset */ + int level; /* context level */ + uint64 session_id; /* session id of context owner */ + ThreadId thread_id; /* thread id of context owner */ + ListCell cell; /* cell to pointer to this context*/ +} MemoryContextData; + +#define MemoryContextIsShared(context) (((MemoryContextData*)(context))->is_shared) + +#define MemoryContextLock(context) \ + do { \ + START_CRIT_SECTION(); \ + int err = pthread_rwlock_wrlock(&((MemoryContextData*)(context))->lock); \ + if (err != 0) { \ + END_CRIT_SECTION(); \ + ereport(ERROR, \ + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), \ + errmsg("system call failed when lock, errno:%d.", err))); \ + } \ + } while (0) + +#define MemoryContextUnlock(context) \ + do { \ + int unlock_err = pthread_rwlock_unlock(&((MemoryContextData*)(context))->lock); \ + if (unlock_err != 0) { \ + END_CRIT_SECTION(); \ + ereport(PANIC, \ + (errcode(ERRCODE_LOCK_NOT_AVAILABLE), \ + errmsg("system call failed when unlock, errno:%d.", unlock_err))); \ + } \ + END_CRIT_SECTION(); \ + } while (0) + +typedef struct AllocBlockData* AllocBlock; /* forward reference */ +typedef struct AllocChunkData* AllocChunk; +typedef struct AsanBlockData* AsanBlock; +/* + * AllocPointer + * Aligned pointer which may be a member of an allocation set. + */ +typedef void* AllocPointer; + +#define ALLOCSET_NUM_FREELISTS 11 + +/* + * AllocSetContext is our standard implementation of MemoryContext. + * + * Note: header.isReset means there is nothing for AllocSetReset to do. + * This is different from the aset being physically empty (empty blocks list) + * because we may still have a keeper block. It's also different from the set + * being logically empty, because we don't attempt to detect pfree'ing the + * last active chunk. + */ +typedef struct AllocSetContext { + MemoryContextData header; /* Standard memory-context fields */ + /* Info about storage allocated in this context: */ + AllocBlock blocks; /* head of list of blocks in this set */ + AllocChunk freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ + /* Allocation parameters for this context: */ + Size initBlockSize; /* initial block size */ + Size maxBlockSize; /* maximum block size */ + Size nextBlockSize; /* next block size to allocate */ + Size allocChunkLimit; /* effective chunk size limit */ + AllocBlock keeper; /* if not NULL, keep this block over resets */ + Size totalSpace; /* all bytes allocated by this context */ + Size freeSpace; /* all bytes freed by this context */ + + /* maximum memory allocation of MemoryContext.For more information,we could see @StackSetContext too. */ + Size maxSpaceSize; + + MemoryTrack track; /* used to track the memory allocation information */ +} AllocSetContext; + +typedef AllocSetContext* AllocSet; + +/* + * AllocBlock + * An AllocBlock is the unit of memory that is obtained by aset.c + * from malloc(). It contains one or more AllocChunks, which are + * the units requested by palloc() and freed by pfree(). AllocChunks + * cannot be returned to malloc() individually, instead they are put + * on freelists by pfree() and re-used by the next palloc() that has + * a matching request size. + * + * AllocBlockData is the header data for a block --- the usable space + * within the block begins at the next alignment boundary. + */ +typedef struct AllocBlockData { + AllocSet aset; /* aset that owns this block */ + AllocBlock prev; /* prev block in aset's blocks list, if any */ + AllocBlock next; /* next block in aset's blocks list */ + char* freeptr; /* start of free space in this block */ + char* endptr; /* end of space in this block */ + Size allocSize; /* allocated size */ +#ifdef MEMORY_CONTEXT_CHECKING + uint64 magicNum; /* DADA */ +#endif +} AllocBlockData; + +#define ALLOC_BLOCKHDRSZ MAXALIGN(sizeof(AllocBlockData)) +/* AsanSetContext is our asan implementation of MemoryContext. + * Note: + * AsanSetContext's structure must be consistent with AllocSetContext. + * header.isReset means there is nothing for AsanSetContext to do. + * This is different from the aset being physically empty (empty blocks list) + * because we may still have a keeper block. It's also different from the set + * being logically empty, because we don't attempt to detect pfree'ing the * last active chunk. */ +typedef struct AsanSetContext { + MemoryContextData header; /* Standard memory-context fields */ + /* Info about storage allocated in this context: */ + AsanBlock blocks; /* head of list of blocks in this set */ + char* reserve[ALLOCSET_NUM_FREELISTS]; /* Allocation parameters for this context: */ + Size initBlockSize; /* initial block size */ + Size maxBlockSize; /* maximum block size */ + Size nextBlockSize; /* next block size to allocate */ + Size allocChunkLimit; /* effective chunk size limit */ + AsanBlock keeper; /* if not NULL, keep this block over resets */ + Size totalSpace; /* all bytes allocated by this context */ + Size freeSpace; /* all bytes freed by this context */ + /* maximum memory allocation of MemoryContext.For more information,we could see @StackSetContext too. */ + Size maxSpaceSize; + MemoryTrack track; /* used to track the memory allocation information */ +} AsanSetContext; + +typedef AsanSetContext* AsanSet; + +typedef struct AsanBlockData { + AsanSet aset; /* aset that owns this block */ + AsanBlock prev; /* prev block in aset's blocks list, if any */ + AsanBlock next; /* next block in aset's blocks list */ + uint32 requestSize; /* request size */ + int line; /* __LINE__ of palloc/palloc0 call */ + const char* file; /* __FILE__ of palloc/palloc0 call */ +} AsanBlockData; + +#define ASAN_BLOCKHDRSZ MAXALIGN(sizeof(AsanBlockData)) +/* utils/palloc.h contains typedef struct MemoryContextData *MemoryContext */ +typedef struct StackBlockData* StackBlock; + +typedef struct StackSetContext { + MemoryContextData header; /* Standard memory-context fields */ + StackBlock blocks; + StackBlock freelist[ALLOCSET_NUM_FREELISTS]; /* free chunk lists */ + + // Allocation parameters for this context: + // + Size initBlockSize; // initial block size + Size maxBlockSize; // maximum block size + Size nextBlockSize; // next block size + Size allocChunkLimit; // limit chunk + StackBlock keeper; + Size totalSpace; + Size freeSpace; + + /* The parameter named maxSpaceSize is an allocation parameter,but this parameter must be here. + * Otherwise the pointer of MemoryContextMethods will be out-of-order. + * So AllocSetContext is.You can see @AllocSetContext + */ + Size maxSpaceSize; + MemoryTrack track; /* used to track the memory allocation information */ +} StackSetContext; + +typedef struct MemoryProtectFuncDef { + void* (*malloc)(Size sz, bool needProtect); + void (*free)(void* ptr, Size sz); + void* (*realloc)(void* ptr, Size oldsz, Size newsz, bool needProtect); + int (*memalign)(void** memptr, Size alignment, Size sz, bool needProtect); +} MemoryProtectFuncDef; + +extern MemoryProtectFuncDef GenericFunctions; +extern MemoryProtectFuncDef SessionFunctions; +extern MemoryProtectFuncDef SharedFunctions; + +/* + * MemoryContextIsValid + * True iff memory context is valid. + * + * Add new context types to the set accepted by this macro. + */ +#define MemoryContextIsValid(context) \ + ((context) != NULL && \ + (IsA((context), AllocSetContext) || IsA((context), AsanSetContext) || IsA((context), StackAllocSetContext) || \ + IsA((context), SharedAllocSetContext) || IsA((context), MemalignAllocSetContext) || \ + IsA((context), MemalignSharedAllocSetContext))) + +#define AllocSetContextUsedSpace(aset) ((aset)->totalSpace - (aset)->freeSpace) +#endif /* MEMNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/nodes/nodeFuncs.h postgresql-hll-2.14/include/nodes/nodeFuncs.h --- postgresql-hll-2.14_old/include/nodes/nodeFuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/nodeFuncs.h 2020-12-12 17:06:43.320348980 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * nodeFuncs.h + * Various general-purpose manipulations of Node trees + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/nodeFuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEFUNCS_H +#define NODEFUNCS_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#else +#include "datatypes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "nodes/parsenodes_common.h" +#endif + +/* flags bits for query_tree_walker and query_tree_mutator */ +#define QTW_IGNORE_RT_SUBQUERIES 0x01 /* subqueries in rtable */ +#define QTW_IGNORE_CTE_SUBQUERIES 0x02 /* subqueries in cteList */ +#define QTW_IGNORE_RC_SUBQUERIES 0x03 /* both of above */ +#define QTW_IGNORE_JOINALIASES 0x04 /* JOIN alias var lists */ +#define QTW_IGNORE_RANGE_TABLE 0x08 /* skip rangetable entirely */ +#define QTW_EXAMINE_RTES 0x10 /* examine RTEs */ +#define QTW_DONT_COPY_QUERY 0x20 /* do not copy top Query */ +#define QTW_IGNORE_DUMMY 0x40 /* remote dummy */ + +extern Oid exprType(const Node* expr); +extern int32 exprTypmod(const Node* expr); +extern bool exprIsLengthCoercion(const Node* expr, int32* coercedTypmod); +extern Node* relabel_to_typmod(Node* expr, int32 typmod); +extern bool expression_returns_set(Node* clause); + +extern Oid exprCollation(const Node* expr); +extern Oid exprInputCollation(const Node* expr); +extern void exprSetCollation(Node* expr, Oid collation); +extern void exprSetInputCollation(Node* expr, Oid inputcollation); + +extern int exprLocation(const Node* expr); + +extern bool expression_tree_walker(Node* node, bool (*walker)(), void* context); +extern Node* expression_tree_mutator(Node* node, Node* (*mutator)(Node*, void*), void* context, bool isCopy = true); + +#ifndef FRONTEND_PARSER +extern bool query_tree_walker(Query* query, bool (*walker)(), void* context, int flags); +extern Query* query_tree_mutator(Query* query, Node* (*mutator)(Node*, void*), void* context, int flags); +#endif + +extern bool range_table_walker(List* rtable, bool (*walker)(), void* context, int flags); +extern List* range_table_mutator(List* rtable, Node* (*mutator)(Node*, void*), void* context, int flags); + +extern bool query_or_expression_tree_walker(Node* node, bool (*walker)(), void* context, int flags); +extern Node* query_or_expression_tree_mutator(Node* node, Node* (*mutator)(Node*, void*), void* context, int flags); + +extern bool raw_expression_tree_walker(Node* node, bool (*walker)(), void* context); +extern bool is_func_distinct_unshippable(Oid funcid); + +extern bool lockNextvalWalker(Node* node, void* context); + +#endif /* NODEFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/nodes.h postgresql-hll-2.14/include/nodes/nodes.h --- postgresql-hll-2.14_old/include/nodes/nodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/nodes.h 2020-12-12 17:06:43.320348980 +0800 @@ -0,0 +1,960 @@ +/* ------------------------------------------------------------------------- + * + * nodes.h + * Definitions for tagged nodes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/nodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODES_H +#define NODES_H +#ifdef FRONTEND_PARSER +#include "feparser_memutils.h" +#endif +/* + * The first field of every node is NodeTag. Each node created (with makeNode) + * will have one of the following tags as the value of its first field. + * + * Note that the numbers of the node tags are not contiguous. We left holes + * here so that we can add more tags without changing the existing enum's. + * (Since node tag numbers never exist outside backend memory, there's no + * real harm in renumbering, it just costs a full rebuild ...) + */ +typedef enum NodeTag { + T_Invalid = 0, + + /* + * TAGS FOR EXECUTOR NODES (execnodes.h) + */ + T_IndexInfo = 10, + T_ExprContext, + T_ProjectionInfo, + T_JunkFilter, + T_ResultRelInfo, + T_EState, + T_TupleTableSlot, + + /* + * TAGS FOR PLAN NODES (plannodes.h) + */ + T_Plan = 100, + T_BaseResult, + T_ModifyTable, + T_Append, + T_PartIterator, + T_MergeAppend, + T_RecursiveUnion, + T_BitmapAnd, + T_BitmapOr, + T_Scan, + T_SeqScan, + T_IndexScan, + T_IndexOnlyScan, + T_BitmapIndexScan, + T_BitmapHeapScan, + T_TidScan, + T_SubqueryScan, + T_FunctionScan, + T_ValuesScan, + T_CteScan, + T_WorkTableScan, + T_ForeignScan, + T_ExtensiblePlan, + T_Join, + T_NestLoop, + T_MergeJoin, + T_HashJoin, + T_Material, + T_Sort, + T_Group, + T_Agg, + T_WindowAgg, + T_Unique, + T_Hash, + T_SetOp, + T_LockRows, + T_Limit, + T_Stream, +#ifdef PGXC + /* + * TAGS FOR PGXC NODES + * (planner.h, locator.h, nodemgr.h, groupmgr.h) + */ + T_ExecNodes, + T_SliceBoundary, + T_ExecBoundary, + T_SimpleSort, + T_RemoteQuery, + T_PGXCNodeHandle, + T_AlterNodeStmt, + T_CreateNodeStmt, + T_DropNodeStmt, + T_AlterCoordinatorStmt, + T_CreateGroupStmt, + T_AlterGroupStmt, + T_DropGroupStmt, + T_CreateResourcePoolStmt, + T_AlterResourcePoolStmt, + T_DropResourcePoolStmt, + T_CreateWorkloadGroupStmt, + T_AlterWorkloadGroupStmt, + T_DropWorkloadGroupStmt, + T_CreateAppWorkloadGroupMappingStmt, + T_AlterAppWorkloadGroupMappingStmt, + T_DropAppWorkloadGroupMappingStmt, +#endif + /* these aren't subclasses of Plan: */ + T_NestLoopParam, + T_PartIteratorParam, + T_PlanRowMark, + T_PlanInvalItem, + /* TAGS FOR POLICY LABEL */ + T_PolicyFilterNode, + T_CreatePolicyLabelStmt, + T_AlterPolicyLabelStmt, + T_DropPolicyLabelStmt, + T_CreateAuditPolicyStmt, + T_AlterAuditPolicyStmt, + T_DropAuditPolicyStmt, + T_MaskingPolicyCondition, + T_CreateMaskingPolicyStmt, + T_AlterMaskingPolicyStmt, + T_DropMaskingPolicyStmt, + T_CreateSecurityPolicyStmt, + T_AlterSecurityPolicyStmt, + T_DropSecurityPolicyStmt, + + /* + * TAGS FOR PLAN STATE NODES (execnodes.h) + * + * These should correspond one-to-one with Plan node types. + */ + T_PlanState = 200, + T_ResultState, + T_MergeActionState, + T_ModifyTableState, + T_DistInsertSelectState, + T_AppendState, + T_PartIteratorState, + T_MergeAppendState, + T_RecursiveUnionState, + T_BitmapAndState, + T_BitmapOrState, + T_ScanState, + T_SeqScanState, + T_IndexScanState, + T_IndexOnlyScanState, + T_BitmapIndexScanState, + T_BitmapHeapScanState, + T_TidScanState, + T_SubqueryScanState, + T_FunctionScanState, + T_ValuesScanState, + T_CteScanState, + T_WorkTableScanState, + T_ForeignScanState, + T_ExtensiblePlanState, + T_JoinState, + T_NestLoopState, + T_MergeJoinState, + T_HashJoinState, + T_MaterialState, + T_SortState, + T_GroupState, + T_AggState, + T_WindowAggState, + T_UniqueState, + T_HashState, + T_SetOpState, + T_LockRowsState, + T_LimitState, +#ifdef PGXC + T_RemoteQueryState, +#endif + T_StreamState, + + /* + * TAGS FOR PRIMITIVE NODES (primnodes.h) + */ + T_Alias = 300, + T_RangeVar, + T_Expr, + T_Var, + T_Const, + T_Param, + T_Aggref, + T_GroupingFunc, + T_WindowFunc, + T_InitList, + T_ArrayRef, + T_FuncExpr, + T_NamedArgExpr, + T_OpExpr, + T_DistinctExpr, + T_NullIfExpr, + T_ScalarArrayOpExpr, + T_BoolExpr, + T_SubLink, + T_SubPlan, + T_AlternativeSubPlan, + T_FieldSelect, + T_FieldStore, + T_RelabelType, + T_CoerceViaIO, + T_ArrayCoerceExpr, + T_ConvertRowtypeExpr, + T_CollateExpr, + T_CaseExpr, + T_CaseWhen, + T_CaseTestExpr, + T_ArrayExpr, + T_RowExpr, + T_RowCompareExpr, + T_CoalesceExpr, + T_MinMaxExpr, + T_XmlExpr, + T_NullTest, + T_BooleanTest, + T_CoerceToDomain, + T_CoerceToDomainValue, + T_SetToDefault, + T_CurrentOfExpr, + T_TargetEntry, + T_RangeTblRef, + T_JoinExpr, + T_FromExpr, + T_UpsertExpr, + T_IntoClause, + T_IndexVar, +#ifdef PGXC + T_DistributeBy, + T_PGXCSubCluster, + T_DistState, + T_ListSliceDefState, +#endif + T_HashFilter, + T_EstSPNode, + T_Rownum, + + /* + * TAGS FOR EXPRESSION STATE NODES (execnodes.h) + * + * These correspond (not always one-for-one) to primitive nodes derived + * from Expr. + */ + T_ExprState = 400, + T_GenericExprState, + T_AggrefExprState, + T_GroupingFuncExprState, + T_WindowFuncExprState, + T_ArrayRefExprState, + T_FuncExprState, + T_ScalarArrayOpExprState, + T_BoolExprState, + T_SubPlanState, + T_AlternativeSubPlanState, + T_FieldSelectState, + T_FieldStoreState, + T_CoerceViaIOState, + T_ArrayCoerceExprState, + T_ConvertRowtypeExprState, + T_CaseExprState, + T_CaseWhenState, + T_ArrayExprState, + T_RowExprState, + T_RowCompareExprState, + T_CoalesceExprState, + T_MinMaxExprState, + T_XmlExprState, + T_NullTestState, + T_HashFilterState, + T_CoerceToDomainState, + T_DomainConstraintState, + T_WholeRowVarExprState, /* will be in a more natural position in 9.3 */ + T_RangePartitionDefState, + T_IntervalPartitionDefState, + T_PartitionState, + T_RangePartitionindexDefState, + T_SplitPartitionState, + T_AddPartitionState, + T_RangePartitionStartEndDefState, + T_RownumState, + T_ListPartitionDefState, + T_HashPartitionDefState, + + /* + * TAGS FOR PLANNER NODES (relation.h) + */ + T_PlannerInfo = 500, + T_PlannerGlobal, + T_RelOptInfo, + T_IndexOptInfo, + T_ParamPathInfo, + T_Path, + T_IndexPath, + T_BitmapHeapPath, + T_BitmapAndPath, + T_BitmapOrPath, + T_NestPath, + T_MergePath, + T_HashPath, + T_TidPath, + T_ForeignPath, + T_ExtensiblePath, + T_AppendPath, + T_MergeAppendPath, + T_ResultPath, + T_MaterialPath, + T_UniquePath, + T_PartIteratorPath, + T_EquivalenceClass, + T_EquivalenceMember, + T_PathKey, + T_RestrictInfo, + T_PlaceHolderVar, + T_SpecialJoinInfo, + T_LateralJoinInfo, + T_AppendRelInfo, + T_PlaceHolderInfo, + T_MinMaxAggInfo, + T_PlannerParamItem, +#ifdef PGXC + T_RemoteQueryPath, +#endif /* PGXC */ + T_StreamPath, + T_MergeAction, + T_UpsertState, + T_SubqueryScanPath, + + /* + * TAGS FOR MEMORY NODES (memnodes.h) + */ + T_MemoryContext = 600, + T_AllocSetContext, + T_AsanSetContext, + T_StackAllocSetContext, + T_SharedAllocSetContext, + T_MemalignAllocSetContext, + T_MemalignSharedAllocSetContext, + + T_MemoryTracking, + + /* + * TAGS FOR VALUE NODES (value.h) + */ + T_Value = 650, + T_Integer, + T_Float, + T_String, + T_BitString, + T_Null, + + /* + * TAGS FOR LIST NODES (pg_list.h) + */ + T_List, + T_IntList, + T_OidList, + + /* + * TAGS FOR DOUBLE LIST NODES (pg_list.h) + */ + T_DList, + T_IntDList, + T_OidDList, + + /* + * TAGS FOR STATEMENT NODES (mostly in parsenodes.h) + */ + T_Query = 700, + T_PlannedStmt, + T_InsertStmt, + T_DeleteStmt, + T_UpdateStmt, + T_MergeStmt, + T_SelectStmt, + T_AlterTableStmt, + T_AlterTableCmd, + T_AlterDomainStmt, + T_SetOperationStmt, + T_GrantStmt, + T_GrantRoleStmt, + T_AlterDefaultPrivilegesStmt, + T_ClosePortalStmt, + T_ClusterStmt, + T_CopyStmt, + T_CreateStmt, + T_DefineStmt, + T_DropStmt, +#ifdef ENABLE_MOT + T_DropForeignStmt, +#endif + T_TruncateStmt, + T_CommentStmt, + T_FetchStmt, + T_IndexStmt, + T_CreateFunctionStmt, + T_AlterFunctionStmt, + T_DoStmt, + T_RenameStmt, + T_RuleStmt, + T_NotifyStmt, + T_ListenStmt, + T_UnlistenStmt, + T_TransactionStmt, + T_ViewStmt, + T_LoadStmt, + T_CreateDomainStmt, + T_CreatedbStmt, + T_DropdbStmt, + T_VacuumStmt, + T_ExplainStmt, + T_CreateTableAsStmt, + T_CreateSeqStmt, + T_AlterSeqStmt, + T_VariableSetStmt, + T_VariableShowStmt, + T_ShutdownStmt, + T_DiscardStmt, + T_CreateTrigStmt, + T_CreatePLangStmt, + T_CreateRoleStmt, + T_AlterRoleStmt, + T_DropRoleStmt, + T_LockStmt, + T_ConstraintsSetStmt, + T_ReindexStmt, + T_CheckPointStmt, +#ifdef PGXC + T_BarrierStmt, +#endif + T_CreateSchemaStmt, + T_AlterDatabaseStmt, + T_AlterDatabaseSetStmt, + T_AlterRoleSetStmt, + T_CreateConversionStmt, + T_CreateCastStmt, + T_CreateOpClassStmt, + T_CreateOpFamilyStmt, + T_AlterOpFamilyStmt, + T_PrepareStmt, + T_ExecuteStmt, + T_DeallocateStmt, + T_DeclareCursorStmt, + T_CreateTableSpaceStmt, + T_DropTableSpaceStmt, + T_AlterObjectSchemaStmt, + T_AlterOwnerStmt, + T_DropOwnedStmt, + T_ReassignOwnedStmt, + T_CompositeTypeStmt, + T_CreateEnumStmt, + T_CreateRangeStmt, + T_AlterEnumStmt, + T_AlterTSDictionaryStmt, + T_AlterTSConfigurationStmt, + T_CreateFdwStmt, + T_AlterFdwStmt, + T_CreateForeignServerStmt, + T_AlterForeignServerStmt, + T_CreateUserMappingStmt, + T_AlterUserMappingStmt, + T_DropUserMappingStmt, + T_ExecDirectStmt, + T_CleanConnStmt, + T_AlterTableSpaceOptionsStmt, + T_SecLabelStmt, + T_CreateForeignTableStmt, + T_CreateExtensionStmt, + T_AlterExtensionStmt, + T_AlterExtensionContentsStmt, + T_CreateDataSourceStmt, + T_AlterDataSourceStmt, + T_ReplicaIdentityStmt, + T_CreateDirectoryStmt, + T_DropDirectoryStmt, + T_CreateRlsPolicyStmt, + T_AlterRlsPolicyStmt, + T_RefreshMatViewStmt, +#ifndef ENABLE_MULTIPLE_NODES + T_AlterSystemStmt, +#endif + T_CreateWeakPasswordDictionaryStmt, + T_DropWeakPasswordDictionaryStmt, + + /* + * TAGS FOR PARSE TREE NODES (parsenodes.h) + */ + T_A_Expr = 900, + T_ColumnRef, + T_ParamRef, + T_A_Const, + T_FuncCall, + T_A_Star, + T_A_Indices, + T_A_Indirection, + T_A_ArrayExpr, + T_ResTarget, + T_TypeCast, + T_CollateClause, + T_SortBy, + T_WindowDef, + T_RangeSubselect, + T_RangeFunction, + T_RangeTableSample, + T_TypeName, + T_ColumnDef, + T_IndexElem, + T_Constraint, + T_DefElem, + T_RangeTblEntry, + T_TableSampleClause, + T_SortGroupClause, + T_GroupingSet, + T_WindowClause, + T_PrivGrantee, + T_FuncWithArgs, + T_AccessPriv, + T_CreateOpClassItem, + T_TableLikeClause, + T_FunctionParameter, + T_LockingClause, + T_RowMarkClause, + T_XmlSerialize, + T_WithClause, + T_CommonTableExpr, + T_PruningResult, + T_Position, + T_MergeWhenClause, + T_UpsertClause, + /* + * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h) + */ + T_IdentifySystemCmd, + T_IdentifyVersionCmd, + T_IdentifyModeCmd, + T_IdentifyMaxLsnCmd, + T_IdentifyConsistenceCmd, + T_IdentifyChannelCmd, + T_IdentifyAZCmd, + T_BaseBackupCmd, + T_CreateReplicationSlotCmd, + T_DropReplicationSlotCmd, + T_StartReplicationCmd, + T_StartDataReplicationCmd, + T_FetchMotCheckpointCmd, + + /* + * TAGS FOR RANDOM OTHER STUFF + * + * These are objects that aren't part of parse/plan/execute node tree + * structures, but we give them NodeTags anyway for identification + * purposes (usually because they are involved in APIs where we want to + * pass multiple object types through the same pointer). + */ + T_TriggerData = 960, /* in commands/trigger.h */ + T_ReturnSetInfo, /* in nodes/execnodes.h */ + T_WindowObjectData, /* private in nodeWindowAgg.c */ + T_TIDBitmap, /* in nodes/tidbitmap.h */ + T_InlineCodeBlock, /* in nodes/parsenodes.h */ + T_FdwRoutine, /* in foreign/fdwapi.h */ + + T_DistFdwDataNodeTask, /* in bulkload/dist_fdw.h */ + T_DistFdwFileSegment, /* in bulkload/dist_fdw.h */ + T_SplitInfo, + T_SplitMap, + T_DfsPrivateItem, + T_ErrorCacheEntry, + T_ForeignPartState, + T_RoachRoutine, /* in bulkload/roach_api.h */ + + /* + * Vectorized Plan Nodes + */ + T_VecPlan = 1000, + T_VecResult, + T_VecModifyTable, + T_VecAppend, + T_VecPartIterator, + T_VecMergeAppend, + T_VecRecursiveUnion, + T_VecScan, + T_CStoreScan, + T_DfsScan, +#ifdef ENABLE_MULTIPLE_NODES + T_TsStoreScan, +#endif /* ENABLE_MULTIPLE_NODES */ + T_VecIndexScan, + T_VecIndexOnlyScan, + T_VecBitmapIndexScan, + T_VecBitmapHeapScan, + T_VecSubqueryScan, + T_VecForeignScan, + T_VecNestLoop, + T_VecMergeJoin, + T_VecHashJoin, + T_VecMaterial, + T_VecSort, + T_VecGroup, + T_VecAgg, + T_VecWindowAgg, + T_VecUnique, + T_VecHash, + T_VecSetOp, + T_VecLockRows, + T_VecLimit, + T_VecStream, + T_RowToVec, + T_VecToRow, + T_DfsIndexScan, + T_CStoreIndexScan, + T_CStoreIndexCtidScan, + T_CStoreIndexHeapScan, + T_CStoreIndexAnd, + T_CStoreIndexOr, + T_VecRemoteQuery, + T_CBTreeScanState, + T_CBTreeOnlyScanState, + T_CstoreBitmapIndexScanState, + + /* + * Vectorized Execution Nodes + */ + T_VecToRowState = 2000, + + // this must put first for vector engine runtime state + T_VecStartState, + + T_RowToVecState, + T_VecAggState, + T_VecHashJoinState, + T_VecStreamState, + T_VecSortState, + T_VecForeignScanState, + T_CStoreScanState, + T_DfsScanState, +#ifdef ENABLE_MULTIPLE_NODES + T_TsStoreScanState, +#endif /* ENABLE_MULTIPLE_NODES */ + T_DfsIndexScanState, + T_CStoreIndexScanState, + T_CStoreIndexCtidScanState, + T_CStoreIndexHeapScanState, + T_CStoreIndexAndState, + T_CStoreIndexOrState, + T_VecRemoteQueryState, + T_VecResultState, + T_VecSubqueryScanState, + T_VecModifyTableState, + T_VecPartIteratorState, + T_VecAppendState, + T_VecLimitState, + T_VecGroupState, + T_VecUniqueState, + T_VecSetOpState, + T_VecNestLoopState, + T_VecMaterialState, + T_VecMergeJoinState, + T_VecWindowAggState, + + // this must put last for vector engine runtime state + T_VecEndState, + + /* @hdfs. support HDFS operation */ + T_HDFSTableAnalyze, + T_ForeignTableDesc, + T_AttrMetaData, + T_RelationMetaData, + T_ForeignOptions, + + /* + * @hdfs + * support infotmational constraint. + */ + T_InformationalConstraint, + T_GroupingId, + T_GroupingIdExprState, + T_BloomFilterSet, + /* Hint type. */ + T_HintState, + T_OuterInnerRels, + T_JoinMethodHint, + T_LeadingHint, + T_RowsHint, + T_StreamHint, + T_BlockNameHint, + T_ScanMethodHint, + T_MultiNodeHint, + T_PredpushHint, + T_RewriteHint, + + /* + * pgfdw + */ + T_PgFdwRemoteInfo, + + /* Create table like. */ + T_TableLikeCtx, + T_SkewHint, + + /* Skew Hint Transform Info */ + T_SkewHintTransf, + T_SkewRelInfo, + T_SkewColumnInfo, + T_SkewValueInfo, + + /* Skew Info */ + T_QualSkewInfo, + + /* Synonym */ + T_CreateSynonymStmt, + T_DropSynonymStmt, + + T_BucketInfo, + + /* Encrypted Column */ + T_ClientLogicGlobalParam, + T_CreateClientLogicGlobal, + T_ClientLogicColumnParam, + T_CreateClientLogicColumn, + T_ClientLogicColumnRef, + T_ExprWithComma +} NodeTag; + +/* if you add to NodeTag also need to add nodeTagToString */ +extern char* nodeTagToString(NodeTag tag); + +/* + * The first field of a node of any type is guaranteed to be the NodeTag. + * Hence the type of any node can be gotten by casting it to Node. Declaring + * a variable to be of Node * (instead of void *) can also facilitate + * debugging. + */ +typedef struct Node { + NodeTag type; +} Node; + +#define nodeTag(nodeptr) (((const Node*)(nodeptr))->type) + +/* + * newNode - + * create a new node of the specified size and tag the node with the + * specified tag. + * + * !WARNING!: Avoid using newNode directly. You should be using the + * macro makeNode. eg. to create a Query node, use makeNode(Query) + * + * Note: the size argument should always be a compile-time constant, so the + * apparent risk of multiple evaluation doesn't matter in practice. + */ +#ifdef __GNUC__ + +/* With GCC, we can use a compound statement within an expression */ +#ifndef FRONTEND_PARSER +#define newNode(size, tag) \ + ({ \ + Node* _result; \ + AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \ + _result = (Node*)palloc0fast(size); \ + _result->type = (tag); \ + _result; \ + }) +#else // !FRONTEND_PARSER +#define newNode(size, tag) \ + ({ \ + Node *_result; \ + AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \ + _result = (Node *)feparser_malloc0(size); \ + _result->type = (tag); \ + _result; \ + }) +#endif // !FRONTEND_PARSER +#else + +#define newNode(size, tag) \ + (AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \ + t_thrd.utils_cxt.newNodeMacroHolder = (Node*)palloc0fast(size), \ + t_thrd.utils_cxt.newNodeMacroHolder->type = (tag), \ + t_thrd.utils_cxt.newNodeMacroHolder) +#endif /* __GNUC__ */ + +#define makeNode(_type_) ((_type_*)newNode(sizeof(_type_), T_##_type_)) +#define makeNodeWithSize(_type_, _size) ((_type_*)newNode(_size, T_##_type_)) + +#define NodeSetTag(nodeptr, t) (((Node*)(nodeptr))->type = (t)) + +#define IsA(nodeptr, _type_) (nodeTag(nodeptr) == T_##_type_) + +/* + * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled, + * verifies that the node has the appropriate type (using its nodeTag()). + * + * Use an inline function when assertions are enabled, to avoid multiple + * evaluations of the ptr argument (which could e.g. be a function call). + * iIf inline functions are not available - only a small number of platforms - + * don't Assert, but use the non-checking version. + */ +#if defined(USE_ASSERT_CHECKING) && defined(PG_USE_INLINE) +static inline Node* castNodeImpl(NodeTag type, void* ptr) +{ + Assert(ptr == NULL || nodeTag(ptr) == type); + return (Node*)ptr; +} +#define castNode(_type_, nodeptr) ((_type_*)castNodeImpl(T_##_type_, nodeptr)) +#else +#define castNode(_type_, nodeptr) ((_type_*)(nodeptr)) +#endif /* USE_ASSERT_CHECKING && PG_USE_INLINE */ + +/* ---------------------------------------------------------------- + * extern declarations follow + * ---------------------------------------------------------------- + */ + +/* + * nodes/{outfuncs.c,print.c} + */ +extern char* nodeToString(const void* obj); +extern void appendBitmapsetToString(void* str, void* bms); + +/* + * nodes/{readfuncs.c,read.c} + */ +extern void* stringToNode(char* str); + +extern void* stringToNode_skip_extern_fields(char* str); + +/* + * nodes/copyfuncs.c + */ +extern void* copyObject(const void* obj); + +/* + * nodes/equalfuncs.c + */ +extern bool _equalSimpleVar(void* va, void* vb); +extern bool equal(const void* a, const void* b); + +/* + * Typedefs for identifying qualifier selectivities and plan costs as such. + * These are just plain "double"s, but declaring a variable as Selectivity + * or Cost makes the intent more obvious. + * + * These could have gone into plannodes.h or some such, but many files + * depend on them... + */ +typedef double Selectivity; /* fraction of tuples a qualifier will pass */ +typedef double Cost; /* execution cost (in page-access units) */ + +/* + * CmdType - + * enums for type of operation represented by a Query or PlannedStmt + * + * This is needed in both parsenodes.h and plannodes.h, so put it here... + */ +typedef enum CmdType { + CMD_UNKNOWN, + CMD_SELECT, /* select stmt */ + CMD_UPDATE, /* update stmt */ + CMD_INSERT, /* insert stmt */ + CMD_DELETE, /* delete stmt */ + CMD_MERGE, /* merge stmt */ + CMD_UTILITY, /* cmds like create, destroy, copy, vacuum, + * etc. */ + CMD_PREPARE, /* prepare stmt */ + CMD_DEALLOCATE, /* deallocate stmt*/ + CMD_EXECUTE, /* execure stmt*/ + CMD_TRUNCATE, /* truncate table*/ + CMD_REINDEX, /* reindex table/index*/ + CMD_NOTHING, /* dummy command for instead nothing rules + * with qual */ + CMD_DDL, + CMD_DCL, + CMD_DML, + CMD_TCL +} CmdType; + +/* + * JoinType - + * enums for types of relation joins + * + * JoinType determines the exact semantics of joining two relations using + * a matching qualification. For example, it tells what to do with a tuple + * that has no match in the other relation. + * + * This is needed in both parsenodes.h and plannodes.h, so put it here... + */ +typedef enum JoinType { + /* + * The canonical kinds of joins according to the SQL JOIN syntax. Only + * these codes can appear in parser output (e.g., JoinExpr nodes). + */ + JOIN_INNER, /* matching tuple pairs only */ + JOIN_LEFT, /* pairs + unmatched LHS tuples */ + JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */ + JOIN_RIGHT, /* pairs + unmatched RHS tuples */ + + /* + * Semijoins and anti-semijoins (as defined in relational theory) do not + * appear in the SQL JOIN syntax, but there are standard idioms for + * representing them (e.g., using EXISTS). The planner recognizes these + * cases and converts them to joins. So the planner and executor must + * support these codes. NOTE: in JOIN_SEMI output, it is unspecified + * which matching RHS row is joined to. In JOIN_ANTI output, the row is + * guaranteed to be null-extended. + */ + JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */ + JOIN_ANTI, /* 1 copy of each LHS row that has no match */ + + /* + * These codes are used internally in the planner, but are not supported + * by the executor (nor, indeed, by most of the planner). + */ + JOIN_UNIQUE_OUTER, /* LHS path must be made unique */ + JOIN_UNIQUE_INNER, /* RHS path must be made unique */ + + JOIN_RIGHT_SEMI, /* Right Semi Join */ + JOIN_RIGHT_ANTI, /* Right Anti join */ + + JOIN_LEFT_ANTI_FULL, /* unmatched LHS tuples */ + JOIN_RIGHT_ANTI_FULL /* unmatched RHS tuples */ + + /* + * We might need additional join types someday. + */ +} JoinType; + +/* + * OUTER joins are those for which pushed-down quals must behave differently + * from the join's own quals. This is in fact everything except INNER and + * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols + * since those are temporary proxies for what will eventually be an INNER + * join. + * + * Note: semijoins are a hybrid case, but we choose to treat them as not + * being outer joins. This is okay principally because the SQL syntax makes + * it impossible to have a pushed-down qual that refers to the inner relation + * of a semijoin; so there is no strong need to distinguish join quals from + * pushed-down quals. This is convenient because for almost all purposes, + * quals attached to a semijoin can be treated the same as innerjoin quals. + * + * We treat right semijoins/antijoins as semijoins/antijoins being treated. + */ +#define IS_OUTER_JOIN(jointype) \ + (((1 << (jointype)) & ((1 << JOIN_LEFT) | (1 << JOIN_FULL) | (1 << JOIN_RIGHT) | (1 << JOIN_ANTI) | \ + (1 << JOIN_RIGHT_ANTI) | (1 << JOIN_LEFT_ANTI_FULL) | (1 << JOIN_RIGHT_ANTI_FULL))) != \ + 0) + +typedef enum UpsertAction +{ + UPSERT_NONE, /* No "DUPLICATE KEY UPDATE" clause */ + UPSERT_NOTHING, /* DUPLICATE KEY UPDATE NOTHING */ + UPSERT_UPDATE /* DUPLICATE KEY UPDATE ... */ +}UpsertAction; + +#endif /* NODES_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/params.h postgresql-hll-2.14/include/nodes/params.h --- postgresql-hll-2.14_old/include/nodes/params.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/params.h 2020-12-12 17:06:43.320348980 +0800 @@ -0,0 +1,116 @@ +/* ------------------------------------------------------------------------- + * + * params.h + * Support for finding the values associated with Param nodes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/params.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARAMS_H +#define PARAMS_H + +/* To avoid including a pile of parser headers, reference ParseState thus: */ +struct ParseState; + +/* ---------------- + * ParamListInfo + * + * ParamListInfo arrays are used to pass parameters into the executor + * for parameterized plans. Each entry in the array defines the value + * to be substituted for a PARAM_EXTERN parameter. The "paramid" + * of a PARAM_EXTERN Param can range from 1 to numParams. + * + * Although parameter numbers are normally consecutive, we allow + * ptype == InvalidOid to signal an unused array entry. + * + * pflags is a flags field. Currently the only used bit is: + * PARAM_FLAG_CONST signals the planner that it may treat this parameter + * as a constant (i.e., generate a plan that works only for this value + * of the parameter). + * + * There are two hook functions that can be associated with a ParamListInfo + * array to support dynamic parameter handling. First, if paramFetch + * isn't null and the executor requires a value for an invalid parameter + * (one with ptype == InvalidOid), the paramFetch hook is called to give + * it a chance to fill in the parameter value. Second, a parserSetup + * hook can be supplied to re-instantiate the original parsing hooks if + * a query needs to be re-parsed/planned (as a substitute for supposing + * that the current ptype values represent a fixed set of parameter types). + + * Although the data structure is really an array, not a list, we keep + * the old typedef name to avoid unnecessary code changes. + * ---------------- + */ +#define PARAM_FLAG_CONST 0x0001 /* parameter is constant */ + +typedef struct Cursor_Data { + int row_count; + int cur_dno; + bool is_open; + bool found; + bool not_found; + bool null_open; + bool null_fetch; +} Cursor_Data; + +typedef struct ParamExternData { + Datum value; /* parameter value */ + bool isnull; /* is it NULL? */ + uint16 pflags; /* flag bits, see above */ + Oid ptype; /* parameter's datatype, or 0 */ + Cursor_Data cursor_data; +} ParamExternData; + +typedef struct ParamListInfoData* ParamListInfo; + +typedef void (*ParamFetchHook)(ParamListInfo params, int paramid); + +typedef void (*ParserSetupHook)(struct ParseState* pstate, void* arg); + +typedef struct ParamListInfoData { + ParamFetchHook paramFetch; /* parameter fetch hook */ + void* paramFetchArg; + ParserSetupHook parserSetup; /* parser setup hook */ + void* parserSetupArg; + int numParams; /* number of ParamExternDatas following */ + bool params_need_process; + ParamExternData params[FLEXIBLE_ARRAY_MEMBER]; +} ParamListInfoData; + +/* ---------------- + * ParamExecData + * + * ParamExecData entries are used for executor internal parameters + * (that is, values being passed into or out of a sub-query). The + * paramid of a PARAM_EXEC Param is a (zero-based) index into an + * array of ParamExecData records, which is referenced through + * es_param_exec_vals or ecxt_param_exec_vals. + * + * If execPlan is not NULL, it points to a SubPlanState node that needs + * to be executed to produce the value. (This is done so that we can have + * lazy evaluation of InitPlans: they aren't executed until/unless a + * result value is needed.) Otherwise the value is assumed to be valid + * when needed. + * ---------------- + */ +typedef struct ParamExecData { + void* execPlan; /* should be "SubPlanState *" */ + Oid valueType; + Datum value; + bool isnull; + void* paramVector; + bool isChanged; + bool isConst; /* for init plan , no need to build scalarvector everytime */ +} ParamExecData; + +enum { CURSOR_ISOPEN = 1, CURSOR_FOUND, CURSOR_NOTFOUND, CURSOR_ROWCOUNT }; + +/* Functions found in src/backend/nodes/params.c */ +extern ParamListInfo copyParamList(ParamListInfo from); + +#endif /* PARAMS_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/parsenodes_common.h postgresql-hll-2.14/include/nodes/parsenodes_common.h --- postgresql-hll-2.14_old/include/nodes/parsenodes_common.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/parsenodes_common.h 2020-12-12 17:06:43.321348993 +0800 @@ -0,0 +1,1721 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * parsenodes_common.h + * + * IDENTIFICATION + * src\include\nodes\parsenodes_common.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#ifdef FRONTEND_PARSER +#include "postgres_fe.h" +#endif + +#include "datatypes.h" +#include "nodes/params.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "catalog/pg_attribute.h" +#include "access/tupdesc.h" +#include "client_logic/client_logic_enums.h" +/* + * When a command can act on several kinds of objects with only one + * parse structure required, use these constants to designate the + * object type. Note that commands typically don't support all the types. + */ +typedef enum ObjectType { + OBJECT_AGGREGATE, + OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */ + OBJECT_CAST, + OBJECT_COLUMN, + OBJECT_CONSTRAINT, + OBJECT_CONTQUERY, + OBJECT_COLLATION, + OBJECT_CONVERSION, + OBJECT_DATABASE, + OBJECT_DATA_SOURCE, + OBJECT_DOMAIN, + OBJECT_EXTENSION, + OBJECT_FDW, + OBJECT_FOREIGN_SERVER, + OBJECT_FOREIGN_TABLE, + OBJECT_FUNCTION, + OBJECT_INDEX, + OBJECT_INDEX_PARTITION, + OBJECT_INTERNAL, + OBJECT_INTERNAL_PARTITION, + OBJECT_LANGUAGE, + OBJECT_LARGEOBJECT, + OBJECT_MATVIEW, + OBJECT_OPCLASS, + OBJECT_OPERATOR, + OBJECT_OPFAMILY, + OBJECT_PARTITION, + OBJECT_RLSPOLICY, + OBJECT_PARTITION_INDEX, + OBJECT_ROLE, + OBJECT_RULE, + OBJECT_SCHEMA, + OBJECT_SEQUENCE, + OBJECT_STREAM, + OBJECT_SYNONYM, + OBJECT_TABLE, + OBJECT_TABLE_PARTITION, + OBJECT_TABLESPACE, + OBJECT_TRIGGER, + OBJECT_TSCONFIGURATION, + OBJECT_TSDICTIONARY, + OBJECT_TSPARSER, + OBJECT_TSTEMPLATE, + OBJECT_TYPE, + OBJECT_USER, + OBJECT_VIEW, + OBJECT_DIRECTORY, + OBJECT_GLOBAL_SETTING, + OBJECT_COLUMN_SETTING +} ObjectType; + +typedef enum DropBehavior { + DROP_RESTRICT, /* drop fails if any dependent objects */ + DROP_CASCADE /* remove dependent objects too */ +} DropBehavior; +/* ---------------------- + * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement + * ---------------------- + */ + +typedef struct DropStmt { + NodeTag type; + List *objects; /* list of sublists of names (as Values) */ + List *arguments; /* list of sublists of arguments (as Values) */ + ObjectType removeType; /* object type */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing_ok; /* skip error if object is missing? */ + bool concurrent; /* drop index concurrently? */ + bool isProcedure; /* true if it is DROP PROCEDURE */ +} DropStmt; + +/* + * TypeName - specifies a type in definitions + * + * For TypeName structures generated internally, it is often easier to + * specify the type by OID than by name. If "names" is NIL then the + * actual type OID is given by typeOid, otherwise typeOid is unused. + * Similarly, if "typmods" is NIL then the actual typmod is expected to + * be prespecified in typemod, otherwise typemod is unused. + * + * If pct_type is TRUE, then names is actually a field name and we look up + * the type of that field. Otherwise (the normal case), names is a type + * name possibly qualified with schema and database name. + */ +typedef struct TypeName { + NodeTag type; + List *names; /* qualified name (list of Value strings) */ + Oid typeOid; /* type identified by OID */ + bool setof; /* is a set? */ + bool pct_type; /* %TYPE specified? */ + List *typmods; /* type modifier expression(s) */ + int32 typemod; /* prespecified type modifier */ + List *arrayBounds; /* array bounds */ + int location; /* token location, or -1 if unknown */ +} TypeName; + +typedef enum FunctionParameterMode { + /* the assigned enum values appear in pg_proc, don't change 'em! */ + FUNC_PARAM_IN = 'i', /* input only */ + FUNC_PARAM_OUT = 'o', /* output only */ + FUNC_PARAM_INOUT = 'b', /* both */ + FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */ + FUNC_PARAM_TABLE = 't' /* table function output column */ +} FunctionParameterMode; + +typedef struct FunctionParameter { + NodeTag type; + char *name; /* parameter name, or NULL if not given */ + TypeName *argType; /* TypeName for parameter type */ + FunctionParameterMode mode; /* IN/OUT/etc */ + Node *defexpr; /* raw default expr, or NULL if not given */ +} FunctionParameter; + +/* + * Note: FuncWithArgs carries only the types of the input parameters of the + * function. So it is sufficient to identify an existing function, but it + * is not enough info to define a function nor to call it. + */ +typedef struct FuncWithArgs { + NodeTag type; + List *funcname; /* qualified name of function */ + List *funcargs; /* list of Typename nodes */ +} FuncWithArgs; + +/* + * DefElem - a generic "name = value" option definition + * + * In some contexts the name can be qualified. Also, certain SQL commands + * allow a SET/ADD/DROP action to be attached to option settings, so it's + * convenient to carry a field for that too. (Note: currently, it is our + * practice that the grammar allows namespace and action only in statements + * where they are relevant; C code can just ignore those fields in other + * statements.) + */ +typedef enum DefElemAction { + DEFELEM_UNSPEC, /* no action given */ + DEFELEM_SET, + DEFELEM_ADD, + DEFELEM_DROP +} DefElemAction; + +typedef struct DefElem { + NodeTag type; + char *defnamespace; /* NULL if unqualified name */ + char *defname; + Node *arg; /* a (Value *) or a (TypeName *) */ + DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ +} DefElem; + +typedef enum SortByDir { + SORTBY_DEFAULT, + SORTBY_ASC, + SORTBY_DESC, + SORTBY_USING /* not allowed in CREATE INDEX ... */ +} SortByDir; + +typedef enum SortByNulls { + SORTBY_NULLS_DEFAULT, + SORTBY_NULLS_FIRST, + SORTBY_NULLS_LAST +} SortByNulls; + +/* + * SortBy - for ORDER BY clause + */ +typedef struct SortBy { + NodeTag type; + Node *node; /* expression to sort on */ + SortByDir sortby_dir; /* ASC/DESC/USING/default */ + SortByNulls sortby_nulls; /* NULLS FIRST/LAST */ + List *useOp; /* name of op to use, if SORTBY_USING */ + int location; /* operator location, or -1 if none/unknown */ +} SortBy; + +/* + * WindowDef - raw representation of WINDOW and OVER clauses + * + * For entries in a WINDOW list, "name" is the window name being defined. + * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname" + * for the "OVER (window)" syntax, which is subtly different --- the latter + * implies overriding the window frame clause. + */ +typedef struct WindowDef { + NodeTag type; + char *name; /* window's own name */ + char *refname; /* referenced window name, if any */ + List *partitionClause; /* PARTITION BY expression list */ + List *orderClause; /* ORDER BY (list of SortBy) */ + int frameOptions; /* frame_clause options, see below */ + Node *startOffset; /* expression for starting bound, if any */ + Node *endOffset; /* expression for ending bound, if any */ + int location; /* parse location, or -1 if none/unknown */ +} WindowDef; + +/* + * IndexElem - index parameters (used in CREATE INDEX) + * + * For a plain index attribute, 'name' is the name of the table column to + * index, and 'expr' is NULL. For an index expression, 'name' is NULL and + * 'expr' is the expression tree. + */ +typedef struct IndexElem { + NodeTag type; + char *name; /* name of attribute to index, or NULL */ + Node *expr; /* expression to index, or NULL */ + char *indexcolname; /* name for index column; NULL = default */ + List *collation; /* name of collation; NIL = default */ + List *opclass; /* name of desired opclass; NIL = default */ + SortByDir ordering; /* ASC/DESC/default */ + SortByNulls nulls_ordering; /* FIRST/LAST/default */ +} IndexElem; + +/* + * WithClause - + * representation of WITH clause + * + * Note: WithClause does not propagate into the Query representation; + * but CommonTableExpr does. + */ +typedef struct WithClause { + NodeTag type; + List *ctes; /* list of CommonTableExprs */ + bool recursive; /* true = WITH RECURSIVE */ + int location; /* token location, or -1 if unknown */ +} WithClause; + +/* + * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx]) + */ +typedef struct A_Indices { + NodeTag type; + Node *lidx; /* NULL if it's a single subscript */ + Node *uidx; +} A_Indices; + +/* + * ResTarget - + * result target (used in target list of pre-transformed parse trees) + * + * In a SELECT target list, 'name' is the column label from an + * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the + * value expression itself. The 'indirection' field is not used. + * + * INSERT uses ResTarget in its target-column-names list. Here, 'name' is + * the name of the destination column, 'indirection' stores any subscripts + * attached to the destination, and 'val' is not used. + * + * In an UPDATE target list, 'name' is the name of the destination column, + * 'indirection' stores any subscripts attached to the destination, and + * 'val' is the expression to assign. + * + * See A_Indirection for more info about what can appear in 'indirection'. + */ +typedef struct ResTarget { + NodeTag type; + char *name; /* column name or NULL */ + List *indirection; /* subscripts, field names, and '*', or NIL */ + Node *val; /* the value expression to compute or assign */ + int location; /* token location, or -1 if unknown */ +} ResTarget; + +/* + * Describes a context of hint processing. + */ +typedef struct HintState { + NodeTag type; + + int nall_hints; /* Hint num */ + List* join_hint; /* Join hint list */ + List* leading_hint; /* Leading hint list */ + List* row_hint; /* Rows hint list */ + List* stream_hint; /* stream hint list */ + List* block_name_hint; /* block name hint list */ + List* scan_hint; /* scan hint list */ + List* skew_hint; /* skew hint list */ + List* hint_warning; /* hint warning list */ + bool multi_node_hint; /* multinode hint */ + List* predpush_hint; + List* rewrite_hint; /* rewrite hint list */ +} HintState; + +/* ---------------------- + * Insert Statement + * + * The source expression is represented by SelectStmt for both the + * SELECT and VALUES cases. If selectStmt is NULL, then the query + * is INSERT ... DEFAULT VALUES. + * ---------------------- + */ + +typedef struct UpsertClause { + NodeTag type; + List *targetList; + int location; +} UpsertClause; + +typedef struct InsertStmt { + NodeTag type; + RangeVar *relation; /* relation to insert into */ + List *cols; /* optional: names of the target columns */ + Node *selectStmt; /* the source SELECT/VALUES, or NULL */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + UpsertClause *upsertClause; /* DUPLICATE KEY UPDATE clause */ + HintState *hintState; + bool isRewritten; /* is this Stmt created by rewritter or end user? */ +} InsertStmt; + +/* ---------------------- + * Delete Statement + * ---------------------- + */ +typedef struct DeleteStmt { + NodeTag type; + RangeVar *relation; /* relation to delete from */ + List *usingClause; /* optional using clause for more tables */ + Node *whereClause; /* qualifications */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + HintState *hintState; + Node *limitClause; /* limit row count */ +} DeleteStmt; + +/* ---------------------- + * Update Statement + * ---------------------- + */ +typedef struct UpdateStmt { + NodeTag type; + RangeVar *relation; /* relation to update */ + List *targetList; /* the target list (of ResTarget) */ + Node *whereClause; /* qualifications */ + List *fromClause; /* optional from clause for more tables */ + List *returningList; /* list of expressions to return */ + WithClause *withClause; /* WITH clause */ + HintState *hintState; +} UpdateStmt; + +/* ---------------------- + * PREPARE Statement + * ---------------------- + */ +typedef struct PrepareStmt { + NodeTag type; + char *name; /* Name of plan, arbitrary */ + List *argtypes; /* Types of parameters (List of TypeName) */ + Node *query; /* The query itself (as a raw parsetree) */ +} PrepareStmt; + + +/* ---------------------- + * EXECUTE Statement + * ---------------------- + */ + +typedef struct ExecuteStmt { + NodeTag type; + char *name; /* The name of the plan to execute */ + List *params; /* Values to assign to parameters */ +} ExecuteStmt; + +/* ---------------------- + * SET Statement (includes RESET) + * + * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we + * preserve the distinction in VariableSetKind for CreateCommandTag(). + * ---------------------- + */ +typedef enum { + VAR_SET_VALUE, /* SET var = value */ + VAR_SET_DEFAULT, /* SET var TO DEFAULT */ + VAR_SET_CURRENT, /* SET var FROM CURRENT */ + VAR_SET_MULTI, /* special case for SET TRANSACTION ... */ + VAR_SET_ROLEPWD, /* special case for SET ROLE PASSWORD... */ + VAR_RESET, /* RESET var */ + VAR_RESET_ALL /* RESET ALL */ +} VariableSetKind; + +typedef struct VariableSetStmt { + NodeTag type; + VariableSetKind kind; + char *name; /* variable to be set */ + List *args; /* List of A_Const nodes */ + bool is_local; /* SET LOCAL? */ +} VariableSetStmt; + +typedef struct AlterRoleSetStmt { + NodeTag type; + char *role; /* role name */ + char *database; /* database name, or NULL */ + VariableSetStmt *setstmt; /* SET or RESET subcommand */ +} AlterRoleSetStmt; + + +typedef struct AlterDatabaseSetStmt { + NodeTag type; + char *dbname; /* database name */ + VariableSetStmt *setstmt; /* SET or RESET subcommand */ +} AlterDatabaseSetStmt; + +/* + * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar + * output. After parse analysis it's set to null, and the Query points to the + * DeclareCursorStmt, not vice versa. + * ---------------------- + */ +#define CURSOR_OPT_BINARY 0x0001 /* BINARY */ +#define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */ +#define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */ +#define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */ +#define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */ +/* these planner-control flags do not correspond to any SQL grammar: */ +#define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */ +#define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */ +#define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */ + +typedef struct DeclareCursorStmt { + NodeTag type; + char *portalname; /* name of the portal (cursor) */ + int options; /* bitmask of options (see above) */ + Node *query; /* the raw SELECT query */ +} DeclareCursorStmt; + +/* ---------------------- + * Select Statement + * + * A "simple" SELECT is represented in the output of gram.y by a single + * SelectStmt node; so is a VALUES construct. A query containing set + * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt + * nodes, in which the leaf nodes are component SELECTs and the internal nodes + * represent UNION, INTERSECT, or EXCEPT operators. Using the same node + * type for both leaf and internal nodes allows gram.y to stick ORDER BY, + * LIMIT, etc, clause values into a SELECT statement without worrying + * whether it is a simple or compound SELECT. + * ---------------------- + */ +typedef enum SetOperation { + SETOP_NONE = 0, + SETOP_UNION, + SETOP_INTERSECT, + SETOP_EXCEPT +} SetOperation; + +typedef struct SelectStmt { + NodeTag type; + + /* + * These fields are used only in "leaf" SelectStmts. + */ + List *distinctClause; /* NULL, list of DISTINCT ON exprs, or + * lcons(NIL,NIL) for all (SELECT DISTINCT) */ + IntoClause *intoClause; /* target for SELECT INTO */ + List *targetList; /* the target list (of ResTarget) */ + List *fromClause; /* the FROM clause */ + Node *whereClause; /* WHERE qualification */ + List *groupClause; /* GROUP BY clauses */ + Node *havingClause; /* HAVING conditional-expression */ + List *windowClause; /* WINDOW window_name AS (...), ... */ + WithClause *withClause; /* WITH clause */ + + /* + * In a "leaf" node representing a VALUES list, the above fields are all + * null, and instead this field is set. Note that the elements of the + * sublists are just expressions, without ResTarget decoration. Also note + * that a list element can be DEFAULT (represented as a SetToDefault + * node), regardless of the context of the VALUES list. It's up to parse + * analysis to reject that where not valid. + */ + List *valuesLists; /* untransformed list of expression lists */ + + /* + * These fields are used in both "leaf" SelectStmts and upper-level + * SelectStmts. + */ + List *sortClause; /* sort clause (a list of SortBy's) */ + Node *limitOffset; /* # of result tuples to skip */ + Node *limitCount; /* # of result tuples to return */ + List *lockingClause; /* FOR UPDATE (list of LockingClause's) */ + HintState *hintState; + + /* + * These fields are used only in upper-level SelectStmts. + */ + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + struct SelectStmt *larg; /* left child */ + struct SelectStmt *rarg; /* right child */ + + /* + * These fields are used by operator "(+)" + */ + bool hasPlus; + /* Eventually add fields for CORRESPONDING spec here */ +} SelectStmt; + +/* + * CollateClause - a COLLATE expression + */ +typedef struct CollateClause { + NodeTag type; + Node *arg; /* input expression */ + List *collname; /* possibly-qualified collation name */ + int location; /* token location, or -1 if unknown */ +} CollateClause; + +/* ---------------------- + * Create Schema Statement + * + * NOTE: the schemaElts list contains raw parsetrees for component statements + * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and + * executed after the schema itself is created. + * ---------------------- + */ +typedef enum TempType { + Temp_None, + Temp_Rel, + Temp_Toast +} TempType; + +typedef struct CreateSchemaStmt { + NodeTag type; + char *schemaname; /* the name of the schema to create */ + char *authid; /* the owner of the created schema */ + List *schemaElts; /* schema components (list of parsenodes) */ + TempType temptype; /* if the schema is temp table's schema */ + List *uuids; /* the list of uuid(only create sequence or table with serial type need) */ +} CreateSchemaStmt; + +/* ---------------------- + * Alter Table + * ---------------------- + */ +typedef struct AlterTableStmt { + NodeTag type; + RangeVar *relation; /* table to work on */ + List *cmds; /* list of subcommands */ + ObjectType relkind; /* type of object */ + bool missing_ok; /* skip error if table missing */ + bool fromCreate; /* from create stmt */ + bool need_rewrite_sql; /* after rewrite rule, need to rewrite query string */ +} AlterTableStmt; + +typedef enum AlterTableType { + AT_AddColumn, /* add column */ + AT_AddColumnRecurse, /* internal to commands/tablecmds.c */ + AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */ + AT_AddPartition, + AT_ColumnDefault, /* alter column default */ + AT_DropNotNull, /* alter column drop not null */ + AT_SetNotNull, /* alter column set not null */ + AT_SetStatistics, /* alter column set statistics */ + AT_AddStatistics, /* alter column add statistics */ + AT_DeleteStatistics, /* alter column delete statistics */ + AT_SetOptions, /* alter column set ( options ) */ + AT_ResetOptions, /* alter column reset ( options ) */ + AT_SetStorage, /* alter column set storage */ + AT_DropColumn, /* drop column */ + AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ + AT_DropPartition, + AT_AddIndex, /* add index */ + AT_ReAddIndex, /* internal to commands/tablecmds.c */ + AT_AddConstraint, /* add constraint */ + AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_ValidateConstraint, /* validate constraint */ + AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_ProcessedConstraint, /* pre-processed add constraint (local in + * parser/parse_utilcmd.c) */ + AT_AddIndexConstraint, /* add constraint using existing index */ + AT_DropConstraint, /* drop constraint */ + AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */ + AT_AlterColumnType, /* alter column type */ + AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */ + AT_ChangeOwner, /* change owner */ + AT_ClusterOn, /* CLUSTER ON */ + AT_DropCluster, /* SET WITHOUT CLUSTER */ + AT_AddOids, /* SET WITH OIDS */ + AT_AddOidsRecurse, /* internal to commands/tablecmds.c */ + AT_DropOids, /* SET WITHOUT OIDS */ + AT_SetTableSpace, /* SET TABLESPACE */ + AT_SetPartitionTableSpace, /* SET TABLESPACE FOR PARTITION */ + AT_SetRelOptions, /* SET (...) -- AM specific parameters */ + AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */ + AT_ReplaceRelOptions, /* replace reloption list in its entirety */ + AT_UnusableIndex, + AT_UnusableIndexPartition, + AT_UnusableAllIndexOnPartition, + AT_RebuildIndex, + AT_RebuildIndexPartition, + AT_RebuildAllIndexOnPartition, + AT_EnableTrig, /* ENABLE TRIGGER name */ + AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */ + AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */ + AT_DisableTrig, /* DISABLE TRIGGER name */ + AT_EnableTrigAll, /* ENABLE TRIGGER ALL */ + AT_DisableTrigAll, /* DISABLE TRIGGER ALL */ + AT_EnableTrigUser, /* ENABLE TRIGGER USER */ + AT_DisableTrigUser, /* DISABLE TRIGGER USER */ + AT_EnableRule, /* ENABLE RULE name */ + AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */ + AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */ + AT_DisableRule, /* DISABLE RULE name */ + AT_EnableRls, /* ENABLE ROW LEVEL SECURITY */ + AT_DisableRls, /* DISABLE ROW LEVEL SECURITY */ + AT_ForceRls, /* FORCE ROW LEVEL SECURITY */ + AT_NoForceRls, /* NO FORCE ROW LEVEL SECURITY */ + AT_AddInherit, /* INHERIT parent */ + AT_DropInherit, /* NO INHERIT parent */ + AT_AddOf, /* OF */ + AT_DropOf, /* NOT OF */ + AT_ReplicaIdentity, /* REPLICA IDENTITY */ + AT_SET_COMPRESS, /* SET COMPRESS/NOCOMPRESS */ +#ifdef PGXC + AT_DistributeBy, /* DISTRIBUTE BY ... */ + AT_SubCluster, /* TO [ NODE nodelist | GROUP groupname ] */ + AT_AddNodeList, /* ADD NODE nodelist */ + AT_DeleteNodeList, /* DELETE NODE nodelist */ +#endif + AT_GenericOptions, /* OPTIONS (...) */ + AT_EnableRowMoveMent, + AT_DisableRowMoveMent, + AT_TruncatePartition, + AT_ExchangePartition, /* ALTER TABLE EXCHANGE PARTITION WITH TABLE */ + AT_MergePartition, /* MERGE PARTITION */ + AT_SplitPartition, /* SPLIT PARTITION */ + /* this will be in a more natural position in 9.3: */ + AT_ReAddConstraint /* internal to commands/tablecmds.c */ +} AlterTableType; + +typedef enum AlterTableStatProperty { /* Additional Property for AlterTableCmd */ + AT_CMD_WithPercent, /* ALTER TABLE ALTER COLUMN SET STATISTICS PERCENT */ + AT_CMD_WithoutPercent /* ALTER TABLE ALTER COLUMN SET STATISTICS */ +} AlterTableStatProperty; + +typedef struct AlterTableCmd { /* one subcommand of an ALTER TABLE */ + NodeTag type; + AlterTableType subtype; /* Type of table alteration to apply */ + char *name; /* column, constraint, or trigger to act on, + * or new owner or tablespace */ + Node *def; /* definition of new column, index, + * constraint, or parent table */ + DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ + bool missing_ok; /* skip error if missing? */ + RangeVar *exchange_with_rel; /* the ordinary table of exchange with */ + bool check_validation; /* Checking the tuple of ordinary table + whether can insert into the partition */ + bool exchange_verbose; /* When check_validation is true, if tuple + of ordinary table can not insert into + the partition, insert the tuple the right partition */ + char *target_partition_tablespace; /* using in merge partition */ + AlterTableStatProperty additional_property; /* additional property for AlterTableCmd */ + List *bucket_list; /* bucket list to drop */ + bool alterGPI; /* check whether is global partition index alter statement */ +} AlterTableCmd; + +/* ---------------------- + * REINDEX Statement + * ---------------------- + */ + +/* struct for adaptive memory allocation for specific utility */ +typedef struct AdaptMem { + int work_mem; /* estimate mem for the utility */ + int max_mem; /* max spread mem for the utility */ +} AdaptMem; + +typedef struct ReindexStmt { + NodeTag type; + ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_INTERNAL, OBJECT_DATABASE */ + RangeVar *relation; /* Table or index to reindex */ + const char *name; /* name of database to reindex */ + bool do_system; /* include system tables in database case */ + bool do_user; /* include user tables in database case */ + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ +} ReindexStmt; + +typedef struct Position { + NodeTag type; + char *colname; /* name of column */ + int fixedlen; + int position; +} Position; + +/* ------------------------------------------- + * Create Row Level Security Policy Statement + * ------------------------------------------- + */ +typedef struct CreateRlsPolicyStmt { + NodeTag type; + bool isPermissive; /* restrictive or permissive policy */ + bool fromExternal; /* this command from external(user) or internal(system) */ + char *policyName; /* Policy's name */ + RangeVar *relation; /* the table name the policy applies to */ + char *cmdName; /* the command name the policy applies to */ + List *roleList; /* the roles associated with the policy */ + Node *usingQual; /* the policy's condition */ +} CreateRlsPolicyStmt; + +/* ------------------------------------------ + * Alter Row Level Security Policy Statement + * ------------------------------------------ + */ +typedef struct AlterRlsPolicyStmt { + NodeTag type; + char *policyName; /* Policy's name */ + RangeVar *relation; /* the table name the policy applies to */ + List *roleList; /* the roles associated with the policy */ + Node *usingQual; /* the policy's condition */ +} AlterPolicyStmt; + +// CLIENT_LOGIC GLOBAL_SETTINGS +typedef enum class ClientLogicGlobalProperty { + GLOBAL_FUNCTION, + GLOBAL_ARGS, + CMK_KEY_STORE, + CMK_KEY_PATH, + CMK_ALGORITHM +} ClientLogicGlobalProperty; + + +typedef struct ClientLogicGlobalParam { + NodeTag type; + ClientLogicGlobalProperty key; + char *value; + unsigned int len; + int location; /* token location, or -1 if unknown */ +} ClientLogicGlobalParam; + + +typedef struct CreateClientLogicGlobal { + NodeTag type; + List *global_key_name; + List *global_setting_params; +} CreateClientLogicGlobal; + +// CLIENT_LOGIC COLUMN_SETTINGS +typedef enum class ClientLogicColumnProperty { + GLOBAL_SETTING, + CEK_ALGORITHM, + CEK_EXPECTED_VALUE, + ENCRYPTION_TYPE, + COLUMN_FUNCTION, + COLUMN_ARGS +} ClientLogicColumnProperty; + +typedef struct ClientLogicColumnParam { + NodeTag type; + ClientLogicColumnProperty key; + char *value; + unsigned int len; + List *qualname; + int location; /* token location, or -1 if unknown */ +} ClientLogicColumnParam; + +typedef struct CreateClientLogicColumn { + NodeTag type; + List *column_key_name; + List *column_setting_params; +} CreateClientLogicColumn; + +typedef struct ClientLogicColumnRef { + NodeTag type; + EncryptionType columnEncryptionAlgorithmType; + List *column_key_name; + TypeName *orig_typname; /* original type of column */ + TypeName *dest_typname; /* real type of column */ + int location; /* token location, or -1 if unknown */ + Oid encryptionoid; +} ClientLogicColumnRef; +/* + * ColumnDef - column definition (used in various creates) + * + * If the column has a default value, we may have the value expression + * in either "raw" form (an untransformed parse tree) or "cooked" form + * (a post-parse-analysis, executable expression tree), depending on + * how this ColumnDef node was created (by parsing, or by inheritance + * from an existing relation). We should never have both in the same node! + * + * Similarly, we may have a COLLATE specification in either raw form + * (represented as a CollateClause with arg==NULL) or cooked form + * (the collation's OID). + * + * The constraints list may contain a CONSTR_DEFAULT item in a raw + * parsetree produced by gram.y, but transformCreateStmt will remove + * the item and set raw_default instead. CONSTR_DEFAULT items + * should not appear in any subsequent processing. + */ +typedef struct ColumnDef { + NodeTag type; + char *colname; /* name of column */ + TypeName *typname; /* type of column */ + int kvtype; /* kv attribute type if use kv storage */ + int inhcount; /* number of times column is inherited */ + bool is_local; /* column has local (non-inherited) def'n */ + bool is_not_null; /* NOT NULL constraint specified? */ + bool is_from_type; /* column definition came from table type */ + bool is_serial; /* column is serial type or not */ + char storage; /* attstorage setting, or 0 for default */ + int8 cmprs_mode; /* compression method applied to this column */ + Node *raw_default; /* default value (untransformed parse tree) */ + Node *cooked_default; /* default value (transformed expr tree) */ + CollateClause *collClause; /* untransformed COLLATE spec, if any */ + Oid collOid; /* collation OID (InvalidOid if not set) */ + List *constraints; /* other constraints on column */ + List *fdwoptions; /* per-column FDW options */ + ClientLogicColumnRef *clientLogicColumnRef; + Position *position; + Form_pg_attribute dropped_attr; /* strcuture for dropped attribute during create table like OE */ +} ColumnDef; + +/* + * definition of a range partition. + * range partition pattern: PARTITION [partitionName] LESS THAN [boundary] + * + */ +typedef struct RangePartitionDefState { + NodeTag type; + char *partitionName; /* name of range partition */ + List *boundary; /* the boundary of a range partition */ + char *tablespacename; /* table space to use, or NULL */ + Const *curStartVal; + char *partitionInitName; +} RangePartitionDefState; + +typedef struct RangePartitionStartEndDefState { + NodeTag type; + char *partitionName; /* name of range partition */ + List *startValue; /* the start value of a start/end clause */ + List *endValue; /* the end value of a start/end clause */ + List *everyValue; /* the interval value of a start/end clause */ + char *tableSpaceName; /* table space to use, or NULL */ +} RangePartitionStartEndDefState; + +/* * + * definition of a range partition. + * interval pattern: INTERVAL ([interval]) [tablespaceLists] + */ +typedef struct IntervalPartitionDefState { + NodeTag type; + Node *partInterval; /* the interval of table which is a constant expression */ + List *intervalTablespaces; /* list of tablespace */ +} IntervalPartitionDefState; +/* * + * definition of a partitioned table. + */ +typedef enum RowMovementValue { + ROWMOVEMENT_DISABLE, + ROWMOVEMENT_ENABLE, + ROWMOVEMENT_DEFAULT +} RowMovementValue; + +typedef struct PartitionState { + NodeTag type; + char partitionStrategy; + /* + * 'i': interval partition + * 'r': range partition + * 'v': value partition (HDFS table only) + * 'i': interval partition. (unsupported yet) + * 'l': list partition (unsupported yet) + * 'h': hash partition (unsupported yet) + */ + + IntervalPartitionDefState *intervalPartDef; /* interval definition */ + List *partitionKey; /* partition key of partitioned table , which is list of ColumnRef */ + List *partitionList; /* list of partition definition */ + RowMovementValue rowMovement; /* default: for colum-stored table means true, for row-stored means false */ +} PartitionState; + +typedef struct AddPartitionState { /* ALTER TABLE ADD PARTITION */ + NodeTag type; + List *partitionList; + bool isStartEnd; +} AddPartitionState; + +typedef struct SplitPartitionState { /* ALTER TABLE SPLIT PARTITION INTO */ + NodeTag type; + char *src_partition_name; + List *partition_for_values; + List *split_point; + List *dest_partition_define_list; +} SplitPartitionState; + +typedef struct ReplicaIdentityStmt { + NodeTag type; + char identity_type; + char *name; +} ReplicaIdentityStmt; + +/* ---------------------- + * Create Table Statement + * + * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are + * intermixed in tableElts, and constraints is NIL. After parse analysis, + * tableElts contains just ColumnDefs, and constraints contains just + * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present + * implementation). + * ---------------------- + */ + +typedef struct CreateStmt { + NodeTag type; + RangeVar *relation; /* relation to create */ + List *tableElts; /* column definitions (list of ColumnDef) */ + List *inhRelations; /* relations to inherit from (list of + * inhRelation) */ + TypeName *ofTypename; /* OF typename */ + List *constraints; /* constraints (list of Constraint nodes) */ + List *options; /* options from WITH clause */ + List *clusterKeys; /* partial cluster key for table */ + OnCommitAction oncommit; /* what do we do at COMMIT? */ + char *tablespacename; /* table space to use, or NULL */ + bool if_not_exists; /* just do nothing if it already exists? */ + bool ivm; /* incremental view maintenance is used by materialized view */ + int8 row_compress; /* row compression flag */ + PartitionState *partTableState; /* the PartitionState */ +#ifdef PGXC + DistributeBy *distributeby; /* distribution to use, or NULL */ + PGXCSubCluster *subcluster; /* subcluster of table */ +#endif + + List *tableEltsDup; /* Used for cstore constraint check */ + char *internalData; /* Used for create table like */ + + List *uuids; /* list of uuid, used for create sequence(like 'create table t(a serial))' */ + Oid oldBucket; /* bucketoid of resizing table */ + List *oldNode; /* relfilenode of resizing table */ + List *oldToastNode; /* toastnode of resizing table */ + char relkind; /* type of object */ +} CreateStmt; + +/* ---------------------- + * Copy Statement + * + * We support "COPY relation FROM file", "COPY relation TO file", and + * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation" + * and "query" must be non-NULL. + * ---------------------- + */ +typedef struct CopyStmt { + NodeTag type; + RangeVar *relation; /* the relation to copy */ + Node *query; /* the SELECT query to copy */ + List *attlist; /* List of column names (as Strings), or NIL + * for all columns */ + bool is_from; /* TO or FROM */ + char *filename; /* filename, or NULL for STDIN/STDOUT */ + List *options; /* List of DefElem nodes */ + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; + bool encrypted; +} CopyStmt; + +#define ATT_KV_UNDEFINED (0) +#define ATT_KV_TAG (1) +#define ATT_KV_FIELD (2) +#define ATT_KV_TIMETAG (3) +#define ATT_KV_HIDE (4) +// valid value for ColumnDef.cmprs_mode +// +#define ATT_CMPR_UNDEFINED (0x7F) +// +// default value for system tables' attrs. +// modify %PGATTR_DEFAULTS in src/backend/catalog/genbki.pl if you modify this mocro +// +#define ATT_CMPR_NOCOMPRESS (0) +#define ATT_CMPR_DELTA (1) +#define ATT_CMPR_DICTIONARY (2) +#define ATT_CMPR_PREFIX (3) +#define ATT_CMPR_NUMSTR (4) + +/* ---------- + * Definitions for constraints in CreateStmt + * + * Note that column defaults are treated as a type of constraint, + * even though that's a bit odd semantically. + * + * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + * + * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype + * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are + * stored into pg_constraint.confmatchtype. Changing the code values may + * require an initdb! + * + * If skip_validation is true then we skip checking that the existing rows + * in the table satisfy the constraint, and just install the catalog entries + * for the constraint. A new FK constraint is marked as valid iff + * initially_valid is true. (Usually skip_validation and initially_valid + * are inverses, but we can set both true if the table is known empty.) + * + * Constraint attributes (DEFERRABLE etc) are initially represented as + * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes + * a pass through the constraints list to insert the info into the appropriate + * Constraint node. + * ---------- + */ + +typedef enum ConstrType { /* types of constraints */ + CONSTR_NULL, /* not SQL92, but a lot of people expect it */ + CONSTR_NOTNULL, + CONSTR_DEFAULT, + CONSTR_CHECK, + CONSTR_PRIMARY, + CONSTR_UNIQUE, + CONSTR_EXCLUSION, + CONSTR_FOREIGN, + CONSTR_CLUSTER, + CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ + CONSTR_ATTR_NOT_DEFERRABLE, + CONSTR_ATTR_DEFERRED, + CONSTR_ATTR_IMMEDIATE +} ConstrType; + +typedef struct Constraint { + NodeTag type; + ConstrType contype; /* see above */ + + /* Fields used for most/all constraint types: */ + char *conname; /* Constraint name, or NULL if unnamed */ + bool deferrable; /* DEFERRABLE? */ + bool initdeferred; /* INITIALLY DEFERRED? */ + int location; /* token location, or -1 if unknown */ + + /* Fields used for constraints with expressions (CHECK and DEFAULT): */ + bool is_no_inherit; /* is constraint non-inheritable? */ + Node *raw_expr; /* expr, as untransformed parse tree */ + char *cooked_expr; /* expr, as nodeToString representation */ + + /* Fields used for unique constraints (UNIQUE and PRIMARY KEY) or cluster partial key for colstore: */ + List *keys; /* String nodes naming referenced column(s) */ + List *including; /* String nodes naming referenced nonkey column(s) */ + + /* Fields used for EXCLUSION constraints: */ + List *exclusions; /* list of (IndexElem, operator name) pairs */ + + /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */ + List *options; /* options from WITH clause */ + char *indexname; /* existing index to use; otherwise NULL */ + char *indexspace; /* index tablespace; NULL for default */ + /* These could be, but currently are not, used for UNIQUE/PKEY: */ + char *access_method; /* index access method; NULL for default */ + Node *where_clause; /* partial index predicate */ + + /* Fields used for FOREIGN KEY constraints: */ + RangeVar *pktable; /* Primary key table */ + List *fk_attrs; /* Attributes of foreign key */ + List *pk_attrs; /* Corresponding attrs in PK table */ + char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */ + char fk_upd_action; /* ON UPDATE action */ + char fk_del_action; /* ON DELETE action */ + List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */ + Oid old_pktable_oid; /* pg_constraint.confrelid of my former self */ + + /* Fields used for constraints that allow a NOT VALID specification */ + bool skip_validation; /* skip validation of existing rows? */ + bool initially_valid; /* mark the new constraint as valid? */ + + /* + * @hdfs + * Field used for soft constraint, which works on HDFS foreign table. + */ + InformationalConstraint *inforConstraint; +} Constraint; + +/* + * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause + */ +typedef struct TableLikeClause { + NodeTag type; + RangeVar *relation; + bits32 options; /* OR of TableLikeOption flags */ +} TableLikeClause; + +#define MAX_TABLE_LIKE_OPTIONS (9) +typedef enum TableLikeOption { + CREATE_TABLE_LIKE_DEFAULTS = 1 << 0, + CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1, + CREATE_TABLE_LIKE_INDEXES = 1 << 2, + CREATE_TABLE_LIKE_STORAGE = 1 << 3, + CREATE_TABLE_LIKE_COMMENTS = 1 << 4, + CREATE_TABLE_LIKE_PARTITION = 1 << 5, + CREATE_TABLE_LIKE_RELOPTIONS = 1 << 6, + CREATE_TABLE_LIKE_DISTRIBUTION = 1 << 7, + CREATE_TABLE_LIKE_OIDS = 1 << 8, + CREATE_TABLE_LIKE_ALL = 0x7FFFFFFF +} TableLikeOption; + +/* Foreign key matchtype codes */ +#define FKCONSTR_MATCH_FULL 'f' +#define FKCONSTR_MATCH_PARTIAL 'p' +#define FKCONSTR_MATCH_UNSPECIFIED 'u' + +/* Foreign key action codes */ +#define FKCONSTR_ACTION_NOACTION 'a' +#define FKCONSTR_ACTION_RESTRICT 'r' +#define FKCONSTR_ACTION_CASCADE 'c' +#define FKCONSTR_ACTION_SETNULL 'n' +#define FKCONSTR_ACTION_SETDEFAULT 'd' + +/* *************************************************************************** + * Supporting data structures for Parse Trees + * + * Most of these node types appear in raw parsetrees output by the grammar, + * and get transformed to something else by the analyzer. A few of them + * are used as-is in transformed querytrees. + * ************************************************************************** */ +/* + * ColumnRef - specifies a reference to a column, or possibly a whole tuple + * + * The "fields" list must be nonempty. It can contain string Value nodes + * (representing names) and A_Star nodes (representing occurrence of a '*'). + * Currently, A_Star must appear only as the last list element --- the grammar + * is responsible for enforcing this! + * + * Note: any array subscripting or selection of fields from composite columns + * is represented by an A_Indirection node above the ColumnRef. However, + * for simplicity in the normal case, initial field selection from a table + * name is represented within ColumnRef and not by adding A_Indirection. + */ +typedef struct ColumnRef { + NodeTag type; + List *fields; /* field names (Value strings) or A_Star */ + int location; /* token location, or -1 if unknown */ +} ColumnRef; + +/* + * A_Star - '*' representing all columns of a table or compound field + * + * This can appear within ColumnRef.fields, A_Indirection.indirection, and + * ResTarget.indirection lists. + */ +typedef struct A_Star { + NodeTag type; +} A_Star; + +/* + * CommonTableExpr - + * representation of WITH list element + * + * We don't currently support the SEARCH or CYCLE clause. + */ +typedef struct CommonTableExpr { + NodeTag type; + char *ctename; /* query name (never qualified) */ + List *aliascolnames; /* optional list of column names */ + /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */ + Node *ctequery; /* the CTE's subquery */ + int location; /* token location, or -1 if unknown */ + /* These fields are set during parse analysis: */ + bool cterecursive; /* is this CTE actually recursive? */ + int cterefcount; /* number of RTEs referencing this CTE + * (excluding internal self-references) */ + List *ctecolnames; /* list of output column names */ + List *ctecoltypes; /* OID list of output column type OIDs */ + List *ctecoltypmods; /* integer list of output column typmods */ + List *ctecolcollations; /* OID list of column collation OIDs */ + char locator_type; /* the location type of cte */ +} CommonTableExpr; + +/* + * FuncCall - a function or aggregate invocation + * + * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)'. + * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct + * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the + * construct *must* be an aggregate call. Otherwise, it might be either an + * aggregate or some other kind of function. However, if OVER is present + * it had better be an aggregate or window function. + */ +typedef struct FuncCall { + NodeTag type; + List *funcname; /* qualified name of function */ + char *colname; /* column name for the function */ + List *args; /* the arguments (list of exprs) */ + List *agg_order; /* ORDER BY (list of SortBy) */ + bool agg_within_group; + bool agg_star; /* argument was really '*' */ + bool agg_distinct; /* arguments were labeled DISTINCT */ + bool func_variadic; /* last argument was labeled VARIADIC */ + struct WindowDef *over; /* OVER clause, if any */ + int location; /* token location, or -1 if unknown */ + bool call_func; /* call function, false is select function */ +} FuncCall; + +/* + * GroupingSet - + * representation of CUBE, ROLLUP and GROUPING SETS clauses + * + * In a Query with grouping sets, the groupClause contains a flat list of + * SortGroupClause nodes for each distinct expression used. The actual + * structure of the GROUP BY clause is given by the groupingSets tree + * + * In the raw parser output, GroupingSet nodes (of all types except SIMPLE + * which is not used) are potentially mixed in with the expressions in the + * groupClause of the SelectStmt. (An expression can't contain a GroupingSet, + * but a list may mix GroupingSet and expression nodes.) At this stage, the + * content of each node is a list of expressions, some of which may be RowExprs + * which represent sublists rather than actual row constructors, and nested + * GroupingSet nodes where legal in the grammar. The structure directly + * reflects the query syntax. + * + * In parse analysis, the transformed expressions are used to build the tlist + * and groupClause list (of SortGroupClause nodes), and the groupingSets tree + * is eventually reduced to a fixed format: + * + * EMPTY nodes represent (), and obviously have no content + * + * SIMPLE nodes represent a list of one or more expressions to be treated as an + * atom by the enclosing structure; the content is an integer list of + * ressortgroupref values (see SortGroupClause) + * + * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes. + * + * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after + * parse analysis they cannot contain more SETS nodes; enough of the syntactic + * transforms of the spec have been applied that we no longer have arbitrarily + * deep nesting (though we still preserve the use of cube/rollup). + * + * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY + * nodes at the leaves), then the groupClause will be empty, but this is still + * an aggregation query (similar to using aggs or HAVING without GROUP BY). + * + * As an example, the following clause: + * + * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e))) + * + * looks like this after raw parsing: + * + * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) ) + * + * and parse analysis converts it to: + * + * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) ) + */ +typedef enum { + GROUPING_SET_EMPTY, + GROUPING_SET_SIMPLE, + GROUPING_SET_ROLLUP, + GROUPING_SET_CUBE, + GROUPING_SET_SETS +} GroupingSetKind; + +typedef struct GroupingSet { + NodeTag type; + GroupingSetKind kind; + List *content; + int location; +} GroupingSet; + +/* + * LockingClause - raw representation of FOR UPDATE/SHARE options + * + * Note: lockedRels == NIL means "all relations in query". Otherwise it + * is a list of RangeVar nodes. (We use RangeVar mainly because it carries + * a location field --- currently, parse analysis insists on unqualified + * names in LockingClause.) + */ +typedef struct LockingClause { + NodeTag type; + List *lockedRels; /* FOR UPDATE or FOR SHARE relations */ + bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ + bool noWait; /* NOWAIT option */ +} LockingClause; + +/* + * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause + * + * This node, appearing only in raw parse trees, represents + * TABLESAMPLE () REPEATABLE () + * Currently, the can only be a RangeVar, but we might in future + * allow RangeSubselect and other options. Note that the RangeTableSample + * is wrapped around the node representing the , rather than being + * a subfield of it. + */ +typedef struct RangeTableSample { + NodeTag type; + Node *relation; /* relation to be sampled */ + List *method; /* sampling method name (possibly qualified) */ + List *args; /* argument(s) for sampling method */ + Node *repeatable; /* REPEATABLE expression, or NULL if none */ + int location; /* method name location, or -1 if unknown */ +} RangeTableSample; + +/* + * RangeFunction - function call appearing in a FROM clause + */ +typedef struct RangeFunction { + NodeTag type; + bool lateral; /* does it have LATERAL prefix? */ + Node *funccallnode; /* untransformed function call tree */ + Alias *alias; /* table alias & optional column aliases */ + List *coldeflist; /* list of ColumnDef nodes to describe result + * of function returning RECORD */ +} RangeFunction; + +/* + * RangeSubselect - subquery appearing in a FROM clause + */ +typedef struct RangeSubselect { + NodeTag type; + bool lateral; /* does it have LATERAL prefix? */ + Node *subquery; /* the untransformed sub-select clause */ + Alias *alias; /* table alias & optional column aliases */ +} RangeSubselect; + +/* + * A_Expr - infix, prefix, and postfix expressions + */ +typedef enum A_Expr_Kind { + AEXPR_OP, /* normal operator */ + AEXPR_AND, /* booleans - name field is unused */ + AEXPR_OR, + AEXPR_NOT, + AEXPR_OP_ANY, /* scalar op ANY (array) */ + AEXPR_OP_ALL, /* scalar op ALL (array) */ + AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ + AEXPR_NULLIF, /* NULLIF - name must be "=" */ + AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */ + AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */ +} A_Expr_Kind; + +typedef struct A_Expr { + NodeTag type; + A_Expr_Kind kind; /* see above */ + List *name; /* possibly-qualified name of operator */ + Node *lexpr; /* left argument, or NULL if none */ + Node *rexpr; /* right argument, or NULL if none */ + int location; /* token location, or -1 if unknown */ +} A_Expr; + +/* + * ParamRef - specifies a $n parameter reference + */ +typedef struct ParamRef { + NodeTag type; + int number; /* the number of the parameter */ + int location; /* token location, or -1 if unknown */ +} ParamRef; + +/* + * A_Indirection - select a field and/or array element from an expression + * + * The indirection list can contain A_Indices nodes (representing + * subscripting), string Value nodes (representing field selection --- the + * string value is the name of the field to select), and A_Star nodes + * (representing selection of all fields of a composite type). + * For example, a complex selection operation like + * (foo).field1[42][7].field2 + * would be represented with a single A_Indirection node having a 4-element + * indirection list. + * + * Currently, A_Star must appear only as the last list element --- the grammar + * is responsible for enforcing this! + */ +typedef struct A_Indirection { + NodeTag type; + Node *arg; /* the thing being selected from */ + List *indirection; /* subscripts and/or field names and/or * */ +} A_Indirection; + +/* + * A_ArrayExpr - an ARRAY[] construct + */ +typedef struct A_ArrayExpr { + NodeTag type; + List *elements; /* array element expressions */ + int location; /* token location, or -1 if unknown */ +} A_ArrayExpr; + +/* + * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are + * used so that ruleutils.c can tell which properties were specified and + * which were defaulted; the correct behavioral bits must be set either way. + * The START_foo and END_foo options must come in pairs of adjacent bits for + * the convenience of gram.y, even though some of them are useless/invalid. + * We will need more bits (and fields) to cover the full SQL:2008 option set. + */ +#define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */ +#define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */ +#define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */ +#define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */ +#define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */ +#define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */ +#define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */ +#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */ +#define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */ +#define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */ +#define FRAMEOPTION_START_VALUE_PRECEDING 0x00400 /* start is V. P. */ +#define FRAMEOPTION_END_VALUE_PRECEDING 0x00800 /* end is V. P. */ +#define FRAMEOPTION_START_VALUE_FOLLOWING 0x01000 /* start is V. F. */ +#define FRAMEOPTION_END_VALUE_FOLLOWING 0x02000 /* end is V. F. */ + +#define FRAMEOPTION_START_VALUE (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING) +#define FRAMEOPTION_END_VALUE (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING) + +#define FRAMEOPTION_DEFAULTS (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | FRAMEOPTION_END_CURRENT_ROW) + +/* + * XMLSERIALIZE (in raw parse tree only) + */ +typedef struct XmlSerialize { + NodeTag type; + XmlOptionType xmloption; /* DOCUMENT or CONTENT */ + Node *expr; + TypeName *typname; + int location; /* token location, or -1 if unknown */ +} XmlSerialize; + +/* + * TypeCast - a CAST expression + */ +typedef struct TypeCast { + NodeTag type; + Node *arg; /* the expression being casted */ + TypeName *typname; /* the target type */ + int location; /* token location, or -1 if unknown */ +} TypeCast; + +/* + * A_Const - a literal constant + */ +typedef struct A_Const { + NodeTag type; + Value val; /* value (includes type info, see value.h) */ + int location; /* token location, or -1 if unknown */ +} A_Const; + + +/* Possible sources of a Query */ +typedef enum QuerySource { + QSRC_ORIGINAL, /* original parsetree (explicit query) */ + QSRC_PARSER, /* added by parse analysis in MERGE */ + QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */ + QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */ + QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */ +} QuerySource; + +typedef enum TdTruncCastStatus { + UNINVOLVED_QUERY = 0, + NOT_CAST_BECAUSEOF_GUC, + TRUNC_CAST_QUERY +} TdTruncCastStatus; +#define TRUNCAST_VERSION_NUM 92023 + +/* **************************************************************************** + * Query Tree + * *************************************************************************** */ + +/* + * Query - + * Parse analysis turns all statements into a Query tree + * for further processing by the rewriter and planner. + * + * Utility statements (i.e. non-optimizable statements) have the + * utilityStmt field set, and the Query itself is mostly dummy. + * DECLARE CURSOR is a special case: it is represented like a SELECT, + * but the original DeclareCursorStmt is stored in utilityStmt. + * + * Planning converts a Query tree into a Plan tree headed by a PlannedStmt + * node --- the Query structure is not used by the executor. + */ +typedef struct Query { + NodeTag type; + + CmdType commandType; /* select|insert|update|delete|merge|utility */ + + QuerySource querySource; /* where did I come from? */ + + uint64 queryId; /* query identifier (can be set by plugins) */ + + bool canSetTag; /* do I set the command result tag? */ + + Node* utilityStmt; /* non-null if this is DECLARE CURSOR or a + * non-optimizable statement */ + + int resultRelation; /* rtable index of target relation for + * INSERT/UPDATE/DELETE/MERGE; 0 for SELECT */ + + bool hasAggs; /* has aggregates in tlist or havingQual */ + bool hasWindowFuncs; /* has window functions in tlist */ + bool hasSubLinks; /* has subquery SubLink */ + bool hasDistinctOn; /* distinctClause is from DISTINCT ON */ + bool hasRecursive; /* WITH RECURSIVE was specified */ + bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */ + bool hasForUpdate; /* FOR UPDATE or FOR SHARE was specified */ + bool hasRowSecurity; /* rewriter has applied some RLS policy */ + bool hasSynonyms; /* has synonym mapping in rtable */ + + List* cteList; /* WITH list (of CommonTableExpr's) */ + + List* rtable; /* list of range table entries */ + FromExpr* jointree; /* table join tree (FROM and WHERE clauses) */ + + List* targetList; /* target list (of TargetEntry) */ + + List* starStart; /* Corresponding p_star_start in ParseState */ + + List* starEnd; /* Corresponding p_star_end in ParseState */ + + List* starOnly; /* Corresponding p_star_only in ParseState */ + + List* returningList; /* return-values list (of TargetEntry) */ + + List* groupClause; /* a list of SortGroupClause's */ + + List* groupingSets; /* a list of GroupingSet's if present */ + + Node* havingQual; /* qualifications applied to groups */ + + List* windowClause; /* a list of WindowClause's */ + + List* distinctClause; /* a list of SortGroupClause's */ + + List* sortClause; /* a list of SortGroupClause's */ + + Node* limitOffset; /* # of result tuples to skip (int8 expr) */ + Node* limitCount; /* # of result tuples to return (int8 expr) */ + + List* rowMarks; /* a list of RowMarkClause's */ + + Node* setOperations; /* set-operation tree if this is top level of + * a UNION/INTERSECT/EXCEPT query */ + + List *constraintDeps; /* a list of pg_constraint OIDs that the query + * depends on to be semantically valid */ + HintState* hintState; +#ifdef PGXC + /* need this info for PGXC Planner, may be temporary */ + char* sql_statement; /* original query */ + bool is_local; /* enforce query execution on local node + * this is used by EXECUTE DIRECT especially. */ + bool has_to_save_cmd_id; /* true if the query is such an INSERT SELECT + * that inserts into a child by selecting + * from its parent OR a WITH query that + * updates a table in main query and inserts + * a row to the same table in WITH query */ + bool vec_output; /* true if it's vec output. this flag is used in FQS planning */ + TdTruncCastStatus tdTruncCastStatus; /* Auto truncation Cast added, only used for stmt in stored procedure or + prepare stmt. */ + List* equalVars; /* vars appears in UPDATE/DELETE clause */ +#endif + ParamListInfo boundParamsQ; + + int mergeTarget_relation; + List* mergeSourceTargetList; + List* mergeActionList; /* list of actions for MERGE (only) */ + Query* upsertQuery; /* insert query for INSERT ON DUPLICATE KEY UPDATE (only) */ + UpsertExpr* upsertClause; /* DUPLICATE KEY UPDATE [NOTHING | ...] */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ + bool use_star_targets; /* true if use * for targetlist. */ + + bool is_from_full_join_rewrite; /* true if the query is created when doing + * full join rewrite. If true, we should not + * do some expression processing. + * Please refer to subquery_planner. + */ + uint64 uniqueSQLId; /* used by unique sql id */ + bool can_push; + bool unique_check; /* true if the subquery is generated by general + * sublink pullup, and scalar output is needed */ + Oid* fixed_paramTypes; /* For plpy CTAS query. CTAS is a recursive call.CREATE query is the first rewrited. + * thd 2nd rewrited query is INSERT SELECT.whithout this attribute, DB will have + * an error that has no idea about $x when INSERT SELECT query is analyzed. */ + int fixed_numParams; +} Query; + +/* ---------------------- + * {Begin|Commit|Rollback} Transaction Statement + * ---------------------- + */ + +typedef enum TransactionStmtKind { + TRANS_STMT_BEGIN, + TRANS_STMT_START, /* semantically identical to BEGIN */ + TRANS_STMT_COMMIT, + TRANS_STMT_ROLLBACK, + TRANS_STMT_SAVEPOINT, + TRANS_STMT_RELEASE, + TRANS_STMT_ROLLBACK_TO, + TRANS_STMT_PREPARE, + TRANS_STMT_COMMIT_PREPARED, + TRANS_STMT_ROLLBACK_PREPARED +} TransactionStmtKind; + +typedef struct TransactionStmt { + NodeTag type; + TransactionStmtKind kind; /* see above */ + List *options; /* for BEGIN/START and savepoint commands */ + char *gid; /* for two-phase-commit related commands */ + CommitSeqNo csn; /* for gs_clean two-phase-commit related commands */ +} TransactionStmt; +/* ---------------------- + * Create View Statement + * ---------------------- + */ +typedef struct ViewStmt { + NodeTag type; + RangeVar *view; /* the view to be created */ + List *aliases; /* target column names */ + Node *query; /* the SELECT query */ + bool replace; /* replace an existing view? */ + bool ivm; /* incremental materialized view? */ + List *options; /* options from WITH clause */ + char *sql_statement; /* used for resize rule, replace the original statement */ + ObjectType relkind; /* type of object */ + Node* mv_stmt; + char *mv_sql; +#ifdef ENABLE_MULTIPLE_NODES + struct PGXCSubCluster* subcluster; /* subcluster of table */ +#endif +} ViewStmt; + +/* ---------------------- + * Merge Statement + * ---------------------- + */ +typedef struct MergeStmt { + NodeTag type; + RangeVar *relation; /* target relation to merge into */ + Node *source_relation; /* source relation */ + Node *join_condition; /* join condition between source and target */ + List *mergeWhenClauses; /* list of MergeWhenClause(es) */ + bool is_insert_update; /* TRUE if the stmt is from INSERT UPDATE */ + Node *insert_stmt; /* insert stmt from INSERT UPDATE */ + HintState *hintState; +} MergeStmt; + +typedef struct MergeWhenClause { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + CmdType commandType; /* INSERT/UPDATE/DELETE */ + Node *condition; /* WHERE conditions (raw parser) */ + List *targetList; /* INSERT/UPDATE targetlist */ + /* the following members are only useful for INSERT action */ + List *cols; /* optional: names of the target columns */ + List *values; /* VALUES to INSERT, or NULL */ +} MergeWhenClause; + +/* + * WHEN [NOT] MATCHED THEN action info + */ +typedef struct MergeAction { + NodeTag type; + bool matched; /* true=MATCHED, false=NOT MATCHED */ + Node *qual; /* transformed WHERE conditions */ + CmdType commandType; /* INSERT/UPDATE/DELETE */ + List *targetList; /* the target list (of ResTarget) */ + /* + * the replaced targetlist after simple subquery pullup. In stream plan, + * we don't do the replacement to targetlist and quals, but this pulluped + * targetlist, and then choose distribute key from this pulluped targetlist + */ + List *pulluped_targetList; +} MergeAction; + +/* PGXC_BEGIN */ +typedef enum { + EXEC_DIRECT_ON_LIST, + EXEC_DIRECT_ON_ALL_CN, + EXEC_DIRECT_ON_ALL_DN, + EXEC_DIRECT_ON_ALL_NODES, + EXEC_DIRECT_ON_NONE +} ExecDirectOption; +/* + * EXECUTE DIRECT statement + */ +typedef struct ExecDirectStmt { + NodeTag type; + List *node_names; + ExecDirectOption exec_option; + char *query; + int location; +} ExecDirectStmt; diff -uprN postgresql-hll-2.14_old/include/nodes/parsenodes.h postgresql-hll-2.14/include/nodes/parsenodes.h --- postgresql-hll-2.14_old/include/nodes/parsenodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/parsenodes.h 2020-12-12 17:06:43.322349006 +0800 @@ -0,0 +1,2264 @@ +/* ------------------------------------------------------------------------- + * + * parsenodes.h + * definitions for parse tree nodes + * + * Many of the node types used in parsetrees include a "location" field. + * This is a byte (not character) offset in the original source text, to be + * used for positioning an error cursor when there is an error related to + * the node. Access to the original source text is needed to make use of + * the location. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/parsenodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSENODES_H +#define PARSENODES_H + +#include "nodes/bitmapset.h" +#include "nodes/params.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#ifdef PGXC +#include "access/tupdesc.h" +#include "pgxc/locator.h" +#endif +#include "tcop/dest.h" +#include "nodes/parsenodes_common.h" + +/* + * Relids + * Set of relation identifiers (indexes into the rangetable). + */ +typedef Bitmapset* Relids; + +/* Sort ordering options for ORDER BY and CREATE INDEX */ +typedef enum RoleLockType { DO_NOTHING, LOCK_ROLE, UNLOCK_ROLE } RoleLockType; + +typedef enum RelOrientation { + REL_ORIENT_UNKNOWN, + REL_COL_ORIENTED, /* It represents CU sotre foramt also. */ + REL_ROW_ORIENTED, + REL_PAX_ORIENTED, + REL_TIMESERIES_ORIENTED +} RelOrientation; + +/* + * It keeps file system which the relatoin store. + * LOCAL_STORE represents local file system. + * HDFS_STORE represents Hadoop file system. + */ +typedef enum RelstoreType { LOCAL_STORE, HDFS_STORE } RelstoreType; + +#define SAMPLEARGSNUM 2 +/* Method of tablesample */ +typedef enum TableSampleType { SYSTEM_SAMPLE = 0, BERNOULLI_SAMPLE, HYBRID_SAMPLE } TableSampleType; + +/* + * Grantable rights are encoded so that we can OR them together in a bitmask. + * The present representation of AclItem limits us to 16 distinct rights, + * even though AclMode is defined as uint32. See utils/acl.h. + * + * Caution: changing these codes breaks stored ACLs, hence forces initdb. + */ +typedef uint32 AclMode; /* a bitmask of privilege bits */ + +#define ACL_INSERT (1 << 0) /* for relations */ +#define ACL_SELECT (1 << 1) +#define ACL_UPDATE (1 << 2) +#define ACL_DELETE (1 << 3) +#define ACL_TRUNCATE (1 << 4) +#define ACL_REFERENCES (1 << 5) +#define ACL_TRIGGER (1 << 6) +#define ACL_EXECUTE (1 << 7) /* for functions */ +#define ACL_USAGE \ + (1 << 8) /* for languages, namespaces, FDWs, and \ + * servers */ +#define ACL_CREATE (1 << 9) /* for namespaces and databases */ +#define ACL_CREATE_TEMP (1 << 10) /* for databases */ +#define ACL_CONNECT (1 << 11) /* for databases */ +#define ACL_COMPUTE (1 << 12) /* for node group */ +#define ACL_READ (1 << 13) /* for pg_directory */ +#define ACL_WRITE (1 << 14) /* for pg_directory */ +#define N_ACL_RIGHTS 15 /* 1 plus the last 1<aliasname is required to be present, and should generally be used + * to identify the RTE for error messages etc. + * + * In RELATION RTEs, the colnames in both alias and eref are indexed by + * physical attribute number; this means there must be colname entries for + * dropped columns. When building an RTE we insert empty strings ("") for + * dropped columns. Note however that a stored rule may have nonempty + * colnames for columns dropped since the rule was created (and for that + * matter the colnames might be out of date due to column renamings). + * The same comments apply to FUNCTION RTEs when the function's return type + * is a named composite type. + * + * In JOIN RTEs, the colnames in both alias and eref are one-to-one with + * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when + * those columns are known to be dropped at parse time. Again, however, + * a stored rule might contain entries for columns dropped since the rule + * was created. (This is only possible for columns not actually referenced + * in the rule.) When loading a stored rule, we replace the joinaliasvars + * items for any such columns with NULL Consts. (We can't simply delete + * them from the joinaliasvars list, because that would affect the attnums + * of Vars referencing the rest of the list.) + * + * inh is TRUE for relation references that should be expanded to include + * inheritance children, if the rel has any. This *must* be FALSE for + * RTEs other than RTE_RELATION entries. + * + * inFromCl marks those range variables that are listed in the FROM clause. + * It's false for RTEs that are added to a query behind the scenes, such + * as the NEW and OLD variables for a rule, or the subqueries of a UNION. + * This flag is not used anymore during parsing, since the parser now uses + * a separate "namespace" data structure to control visibility, but it is + * needed by ruleutils.c to determine whether RTEs should be shown in + * decompiled queries. + * + * requiredPerms and checkAsUser specify run-time access permissions + * checks to be performed at query startup. The user must have *all* + * of the permissions that are OR'd together in requiredPerms (zero + * indicates no permissions checking). If checkAsUser is not zero, + * then do the permissions checks using the access rights of that user, + * not the current effective user ID. (This allows rules to act as + * setuid gateways.) Permissions checks only apply to RELATION RTEs. + * + * For SELECT/INSERT/UPDATE permissions, if the user doesn't have + * table-wide permissions then it is sufficient to have the permissions + * on all columns identified in selectedCols (for SELECT) and/or + * modifiedCols (for INSERT/UPDATE; we can tell which from the query type). + * selectedCols and modifiedCols are bitmapsets, which cannot have negative + * integer members, so we subtract FirstLowInvalidHeapAttributeNumber from + * column numbers before storing them in these fields. A whole-row Var + * reference is represented by setting the bit for InvalidAttrNumber. + * -------------------- + */ +typedef enum RTEKind { + RTE_RELATION, /* ordinary relation reference */ + RTE_SUBQUERY, /* subquery in FROM */ + RTE_JOIN, /* join */ + RTE_FUNCTION, /* function in FROM */ + RTE_VALUES, /* VALUES (), (), ... */ + RTE_CTE /* common table expr (WITH list element) */ +#ifdef PGXC + , + RTE_REMOTE_DUMMY /* RTEs created by remote plan reduction */ +#endif /* PGXC */ +} RTEKind; + +typedef struct RangeTblEntry { + NodeTag type; + + RTEKind rtekind; /* see above */ + + /* + * XXX the fields applicable to only some rte kinds should be merged into + * a union. I didn't do this yet because the diffs would impact a lot of + * code that is being actively worked on. + */ + +#ifdef PGXC + char* relname; + List* partAttrNum; +#endif + + /* + * Fields valid for a plain relation RTE (else zero): + */ + Oid relid; /* OID of the relation */ + Oid partitionOid; /* + * OID of a partition if relation is partitioned table. + * Select * from table_name partition (partition_name); + * or select * from table_name partition for (partition_key_value_list) + */ + bool isContainPartition; /* select from caluse whether contains partition + * if contains partition isContainPartition=true, + * otherwise isContainPartition=false + */ + Oid refSynOid; /* OID of synonym object if relation is referenced by some synonym object. */ + List* partid_list; + + char relkind; /* relation kind (see pg_class.relkind) */ + bool isResultRel; /* used in target of SELECT INTO or similar */ + TableSampleClause* tablesample; /* sampling method and parameters */ + + bool ispartrel; /* is it a partitioned table */ + + /* works just for _readRangeTblEntry(). set true if plan is running in the compute pool. */ + bool ignoreResetRelid; + + /* + * Fields valid for a subquery RTE (else NULL): + */ + Query* subquery; /* the sub-query */ + bool security_barrier; /* subquery from security_barrier view */ + + /* + * Fields valid for a join RTE (else NULL/zero): + * + * joinaliasvars is a list of Vars or COALESCE expressions corresponding + * to the columns of the join result. An alias Var referencing column K + * of the join result can be replaced by the K'th element of joinaliasvars + * --- but to simplify the task of reverse-listing aliases correctly, we + * do not do that until planning time. In a Query loaded from a stored + * rule, it is also possible for joinaliasvars items to be NULL Consts, + * denoting columns dropped since the rule was made. + */ + JoinType jointype; /* type of join */ + List* joinaliasvars; /* list of alias-var expansions */ + + /* + * Fields valid for a function RTE (else NULL): + * + * If the function returns RECORD, funccoltypes lists the column types + * declared in the RTE's column type specification, funccoltypmods lists + * their declared typmods, funccolcollations their collations. Otherwise, + * those fields are NIL. + */ + Node* funcexpr; /* expression tree for func call */ + List* funccoltypes; /* OID list of column type OIDs */ + List* funccoltypmods; /* integer list of column typmods */ + List* funccolcollations; /* OID list of column collation OIDs */ + + /* + * Fields valid for a values RTE (else NIL): + */ + List* values_lists; /* list of expression lists */ + List* values_collations; /* OID list of column collation OIDs */ + + /* + * Fields valid for a CTE RTE (else NULL/zero): + */ + char* ctename; /* name of the WITH list item */ + Index ctelevelsup; /* number of query levels up */ + bool self_reference; /* is this a recursive self-reference? */ + List* ctecoltypes; /* OID list of column type OIDs */ + List* ctecoltypmods; /* integer list of column typmods */ + List* ctecolcollations; /* OID list of column collation OIDs */ + char locator_type; /* keep subplan/cte's locator type */ + + /* + * Fields valid in all RTEs: + */ + Alias* alias; /* user-written alias clause, if any */ + Alias* eref; /* expanded reference names */ + Alias* pname; /* partition name, if any */ + List* plist; + bool lateral; /* subquery or function is marked LATERAL? */ + bool inh; /* inheritance requested? */ + bool inFromCl; /* present in FROM clause? */ + AclMode requiredPerms; /* bitmask of required access permissions */ + Oid checkAsUser; /* if valid, check access as this role */ + Bitmapset* selectedCols; /* columns needing SELECT permission */ + Bitmapset* modifiedCols; /* columns needing INSERT/UPDATE permission, not used in current version + * we split it to insertedCols and updatedCols for MERGEINTO + */ + Bitmapset* insertedCols; /* columns needing INSERT permission */ + Bitmapset* updatedCols; /* columns needing UPDATE permission */ + RelOrientation orientation; /* column oriented or row oriented */ + + char* mainRelName; + char* mainRelNameSpace; + List* securityQuals; /* security barrier quals to apply */ + + /* For skew hint */ + bool subquery_pull_up; /* mark that the subquery whether been pull up */ + + /* + * Indicate current RTE is correlated with a Recursive CTE, the flag is set in + * check_plan_correlation() + */ + bool correlated_with_recursive_cte; + /* For hash buckets */ + bool relhasbucket; /* the rel has underlying buckets, get from pg_class */ + bool isbucket; /* the sql only want some buckets from the rel */ + List* buckets; /* the bucket id wanted */ + + bool isexcluded; /* the rel is the EXCLUDED relation for UPSERT */ + /* For sublink in targetlist pull up */ + bool sublink_pull_up; /* mark the subquery is sublink pulled up */ +} RangeTblEntry; + +/* + * SortGroupClause - + * representation of ORDER BY, GROUP BY, PARTITION BY, + * DISTINCT, DISTINCT ON items + * + * You might think that ORDER BY is only interested in defining ordering, + * and GROUP/DISTINCT are only interested in defining equality. However, + * one way to implement grouping is to sort and then apply a "uniq"-like + * filter. So it's also interesting to keep track of possible sort operators + * for GROUP/DISTINCT, and in particular to try to sort for the grouping + * in a way that will also yield a requested ORDER BY ordering. So we need + * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates + * the decision to give them the same representation. + * + * tleSortGroupRef must match ressortgroupref of exactly one entry of the + * query's targetlist; that is the expression to be sorted or grouped by. + * eqop is the OID of the equality operator. + * sortop is the OID of the ordering operator (a "<" or ">" operator), + * or InvalidOid if not available. + * nulls_first means about what you'd expect. If sortop is InvalidOid + * then nulls_first is meaningless and should be set to false. + * hashable is TRUE if eqop is hashable (note this condition also depends + * on the datatype of the input expression). + * + * In an ORDER BY item, all fields must be valid. (The eqop isn't essential + * here, but it's cheap to get it along with the sortop, and requiring it + * to be valid eases comparisons to grouping items.) Note that this isn't + * actually enough information to determine an ordering: if the sortop is + * collation-sensitive, a collation OID is needed too. We don't store the + * collation in SortGroupClause because it's not available at the time the + * parser builds the SortGroupClause; instead, consult the exposed collation + * of the referenced targetlist expression to find out what it is. + * + * In a grouping item, eqop must be valid. If the eqop is a btree equality + * operator, then sortop should be set to a compatible ordering operator. + * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that + * the query presents for the same tlist item. If there is none, we just + * use the default ordering op for the datatype. + * + * If the tlist item's type has a hash opclass but no btree opclass, then + * we will set eqop to the hash equality operator, sortop to InvalidOid, + * and nulls_first to false. A grouping item of this kind can only be + * implemented by hashing, and of course it'll never match an ORDER BY item. + * + * The hashable flag is provided since we generally have the requisite + * information readily available when the SortGroupClause is constructed, + * and it's relatively expensive to get it again later. Note there is no + * need for a "sortable" flag since OidIsValid(sortop) serves the purpose. + * + * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses. + * In SELECT DISTINCT, the distinctClause list is as long or longer than the + * sortClause list, while in SELECT DISTINCT ON it's typically shorter. + * The two lists must match up to the end of the shorter one --- the parser + * rearranges the distinctClause if necessary to make this true. (This + * restriction ensures that only one sort step is needed to both satisfy the + * ORDER BY and set up for the Unique step. This is semantically necessary + * for DISTINCT ON, and presents no real drawback for DISTINCT.) + */ +typedef struct SortGroupClause { + NodeTag type; + Index tleSortGroupRef; /* reference into targetlist */ + Oid eqop; /* the equality operator ('=' op) */ + Oid sortop; /* the ordering operator ('<' op), or 0 */ + bool nulls_first; /* do NULLs come before normal values? */ + bool hashable; /* can eqop be implemented by hashing? */ + bool groupSet; /* It will be set to true If this expr in group clause and not include + in all group clause when groupingSet is not null. It mean it's value can be altered. */ +} SortGroupClause; + +/* + * WindowClause - + * transformed representation of WINDOW and OVER clauses + * + * A parsed Query's windowClause list contains these structs. "name" is set + * if the clause originally came from WINDOW, and is NULL if it originally + * was an OVER clause (but note that we collapse out duplicate OVERs). + * partitionClause and orderClause are lists of SortGroupClause structs. + * winref is an ID number referenced by WindowFunc nodes; it must be unique + * among the members of a Query's windowClause list. + * When refname isn't null, the partitionClause is always copied from there; + * the orderClause might or might not be copied (see copiedOrder); the framing + * options are never copied, per spec. + */ +typedef struct WindowClause { + NodeTag type; + char* name; /* window name (NULL in an OVER clause) */ + char* refname; /* referenced window name, if any */ + List* partitionClause; /* PARTITION BY list */ + List* orderClause; /* ORDER BY list */ + int frameOptions; /* frame_clause options, see WindowDef */ + Node* startOffset; /* expression for starting bound, if any */ + Node* endOffset; /* expression for ending bound, if any */ + Index winref; /* ID referenced by window functions */ + bool copiedOrder; /* did we copy orderClause from refname? */ +} WindowClause; + +/* + * RowMarkClause - + * parser output representation of FOR UPDATE/SHARE clauses + * + * Query.rowMarks contains a separate RowMarkClause node for each relation + * identified as a FOR UPDATE/SHARE target. If FOR UPDATE/SHARE is applied + * to a subquery, we generate RowMarkClauses for all normal and subquery rels + * in the subquery, but they are marked pushedDown = true to distinguish them + * from clauses that were explicitly written at this query level. Also, + * Query.hasForUpdate tells whether there were explicit FOR UPDATE/SHARE + * clauses in the current query level. + */ +typedef struct RowMarkClause { + NodeTag type; + Index rti; /* range table index of target relation */ + bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */ + bool noWait; /* NOWAIT option */ + bool pushedDown; /* pushed down from higher query level? */ +} RowMarkClause; + +/* Convenience macro to get the output tlist of a CTE's query */ +#define GetCTETargetList(cte) \ + (AssertMacro(IsA((cte)->ctequery, Query)), \ + ((Query*)(cte)->ctequery)->commandType == CMD_SELECT ? ((Query*)(cte)->ctequery)->targetList \ + : ((Query*)(cte)->ctequery)->returningList) + +/***************************************************************************** + * Optimizable Statements + *****************************************************************************/ + + +/* ---------------------- + * Set Operation node for post-analysis query trees + * + * After parse analysis, a SELECT with set operations is represented by a + * top-level Query node containing the leaf SELECTs as subqueries in its + * range table. Its setOperations field shows the tree of set operations, + * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal + * nodes replaced by SetOperationStmt nodes. Information about the output + * column types is added, too. (Note that the child nodes do not necessarily + * produce these types directly, but we've checked that their output types + * can be coerced to the output column type.) Also, if it's not UNION ALL, + * information about the types' sort/group semantics is provided in the form + * of a SortGroupClause list (same representation as, eg, DISTINCT). + * The resolved common column collations are provided too; but note that if + * it's not UNION ALL, it's okay for a column to not have a common collation, + * so a member of the colCollations list could be InvalidOid even though the + * column has a collatable type. + * ---------------------- + */ +typedef struct SetOperationStmt { + NodeTag type; + SetOperation op; /* type of set op */ + bool all; /* ALL specified? */ + Node* larg; /* left child */ + Node* rarg; /* right child */ + /* Eventually add fields for CORRESPONDING spec here */ + + /* Fields derived during parse analysis: */ + List* colTypes; /* OID list of output column type OIDs */ + List* colTypmods; /* integer list of output column typmods */ + List* colCollations; /* OID list of output column collation OIDs */ + List* groupClauses; /* a list of SortGroupClause's */ + /* groupClauses is NIL if UNION ALL, but must be set otherwise */ +} SetOperationStmt; + +/***************************************************************************** + * Other Statements (no optimizations required) + * + * These are not touched by parser/analyze.c except to put them into + * the utilityStmt field of a Query. This is eventually passed to + * ProcessUtility (by-passing rewriting and planning). Some of the + * statements do need attention from parse analysis, and this is + * done by routines in parser/parse_utilcmd.c after ProcessUtility + * receives the command for execution. + *****************************************************************************/ + +/* ---------------------- + * Alter Domain + * + * The fields are used in different ways by the different variants of + * this command. + * ---------------------- + */ +typedef struct AlterDomainStmt { + NodeTag type; + char subtype; /*------------ + * T = alter column default + * N = alter column drop not null + * O = alter column set not null + * C = add constraint + * X = drop constraint + * ------------ + */ + List* typname; /* domain to work on */ + char* name; /* column or constraint name to act on */ + Node* def; /* definition of default or constraint */ + DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ + bool missing_ok; /* skip error if missing? */ +} AlterDomainStmt; + +/* ---------------------- + * Grant|Revoke Statement + * ---------------------- + */ +typedef enum GrantTargetType { + ACL_TARGET_OBJECT, /* grant on specific named object(s) */ + ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */ + ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */ +} GrantTargetType; + +typedef enum GrantObjectType { + ACL_OBJECT_COLUMN, /* column */ + ACL_OBJECT_RELATION, /* table, view */ + ACL_OBJECT_SEQUENCE, /* sequence */ + ACL_OBJECT_DATABASE, /* database */ + ACL_OBJECT_DOMAIN, /* domain */ + ACL_OBJECT_FDW, /* foreign-data wrapper */ + ACL_OBJECT_FOREIGN_SERVER, /* foreign server */ + ACL_OBJECT_FUNCTION, /* function */ + ACL_OBJECT_LANGUAGE, /* procedural language */ + ACL_OBJECT_LARGEOBJECT, /* largeobject */ + ACL_OBJECT_NAMESPACE, /* namespace */ + ACL_OBJECT_NODEGROUP, /* nodegroup */ + ACL_OBJECT_TABLESPACE, /* tablespace */ + ACL_OBJECT_TYPE, /* type */ + ACL_OBJECT_DATA_SOURCE, /* data source */ + ACL_OBJECT_GLOBAL_SETTING, /* Global Setting */ + ACL_OBJECT_COLUMN_SETTING, /* Column Setting */ + ACL_OBJECT_DIRECTORY /* directory */ +} GrantObjectType; + +typedef struct GrantStmt { + NodeTag type; + bool is_grant; /* true = GRANT, false = REVOKE */ + GrantTargetType targtype; /* type of the grant target */ + GrantObjectType objtype; /* kind of object being operated on */ + List* objects; /* list of RangeVar nodes, FuncWithArgs nodes, + * or plain names (as Value strings) */ + List* privileges; /* list of AccessPriv nodes */ + /* privileges == NIL denotes ALL PRIVILEGES */ + List* grantees; /* list of PrivGrantee nodes */ + bool grant_option; /* grant or revoke grant option */ + DropBehavior behavior; /* drop behavior (for REVOKE) */ +} GrantStmt; + +typedef struct PrivGrantee { + NodeTag type; + char* rolname; /* if NULL then PUBLIC */ +} PrivGrantee; + +/* + * An access privilege, with optional list of column names + * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list) + * cols == NIL denotes "all columns" + * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not + * an AccessPriv with both fields null. + */ +typedef struct AccessPriv { + NodeTag type; + char* priv_name; /* string name of privilege */ + List* cols; /* list of Value strings */ +} AccessPriv; + +/* ---------------------- + * Grant/Revoke Role Statement + * + * Note: because of the parsing ambiguity with the GRANT + * statement, granted_roles is a list of AccessPriv; the execution code + * should complain if any column lists appear. grantee_roles is a list + * of role names, as Value strings. + * ---------------------- + */ +typedef struct GrantRoleStmt { + NodeTag type; + List* granted_roles; /* list of roles to be granted/revoked */ + List* grantee_roles; /* list of member roles to add/delete */ + bool is_grant; /* true = GRANT, false = REVOKE */ + bool admin_opt; /* with admin option */ + char* grantor; /* set grantor to other than current role */ + DropBehavior behavior; /* drop behavior (for REVOKE) */ +} GrantRoleStmt; + +/* ---------------------- + * Alter Default Privileges Statement + * ---------------------- + */ +typedef struct AlterDefaultPrivilegesStmt { + NodeTag type; + List* options; /* list of DefElem */ + GrantStmt* action; /* GRANT/REVOKE action (with objects=NIL) */ +} AlterDefaultPrivilegesStmt; + +/* ---------------------- + * Show Statement + * ---------------------- + */ +typedef struct VariableShowStmt { + NodeTag type; + char* name; +} VariableShowStmt; + +/* ---------------------- + * Shutdown Statement + * ---------------------- + */ +typedef struct ShutdownStmt { + NodeTag type; + char* mode; +} ShutdownStmt; + +typedef struct ListPartitionDefState { + NodeTag type; + char* partitionName; /* name of list partition */ + List* boundary; /* the boundary of a list partition */ + char* tablespacename; /* table space to use, or NULL */ +} ListPartitionDefState; + +typedef struct HashPartitionDefState { + NodeTag type; + char* partitionName; /* name of hash partition */ + List* boundary; /* the boundary of a hash partition */ + char* tablespacename; /* table space to use, or NULL */ +} HashPartitionDefState; + +typedef struct RangePartitionindexDefState { + NodeTag type; + char* name; + char* tablespace; +} RangePartitionindexDefState; + + +/* ---------- + * Definitions for constraints in CreateStmt + * + * Note that column defaults are treated as a type of constraint, + * even though that's a bit odd semantically. + * + * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) + * we may have the expression in either "raw" form (an untransformed + * parse tree) or "cooked" form (the nodeToString representation of + * an executable expression tree), depending on how this Constraint + * node was created (by parsing, or by inheritance from an existing + * relation). We should never have both in the same node! + * + * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype + * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are + * stored into pg_constraint.confmatchtype. Changing the code values may + * require an initdb! + * + * If skip_validation is true then we skip checking that the existing rows + * in the table satisfy the constraint, and just install the catalog entries + * for the constraint. A new FK constraint is marked as valid iff + * initially_valid is true. (Usually skip_validation and initially_valid + * are inverses, but we can set both true if the table is known empty.) + * + * Constraint attributes (DEFERRABLE etc) are initially represented as + * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes + * a pass through the constraints list to insert the info into the appropriate + * Constraint node. + * ---------- + */ + +#define CSTORE_SUPPORT_CONSTRAINT(type) \ + ((type) == CONSTR_NULL || (type) == CONSTR_NOTNULL || (type) == CONSTR_DEFAULT || (type) == CONSTR_CLUSTER) + +#define GetConstraintType(type) \ + ({ \ + const char* tname = NULL; \ + switch (type) { \ + case CONSTR_NULL: \ + tname = "NULL"; \ + break; \ + case CONSTR_NOTNULL: \ + tname = "NOT NULL"; \ + break; \ + case CONSTR_DEFAULT: \ + tname = "DEFAULT"; \ + break; \ + case CONSTR_CHECK: \ + tname = "CHECK"; \ + break; \ + case CONSTR_PRIMARY: \ + tname = "PRIMARY KEY"; \ + break; \ + case CONSTR_UNIQUE: \ + tname = "UNIQUE"; \ + break; \ + case CONSTR_EXCLUSION: \ + tname = "EXCLUSION"; \ + break; \ + case CONSTR_FOREIGN: \ + tname = "FOREIGN KEY"; \ + break; \ + case CONSTR_CLUSTER: \ + tname = "CLUSTER"; \ + break; \ + case CONSTR_ATTR_DEFERRABLE: \ + tname = "ATTR DEFERRABLE"; \ + break; \ + case CONSTR_ATTR_NOT_DEFERRABLE: \ + tname = "ATTR NOT DEFERRABLE"; \ + break; \ + case CONSTR_ATTR_DEFERRED: \ + tname = "ATTR DEFERRED"; \ + break; \ + case CONSTR_ATTR_IMMEDIATE: \ + tname = "ATTR IMMEDIATE"; \ + break; \ + } \ + tname; \ + }) + +/* ---------------------- + * Create/Drop Table Space Statements + * ---------------------- + */ +typedef struct CreateTableSpaceStmt { + NodeTag type; + char* tablespacename; + char* owner; + char* location; + char* maxsize; + List* options; + bool relative; /* location is relative to data directory */ +} CreateTableSpaceStmt; + +typedef struct DropTableSpaceStmt { + NodeTag type; + char* tablespacename; + bool missing_ok; /* skip error if missing? */ +} DropTableSpaceStmt; + +typedef struct AlterTableSpaceOptionsStmt { + NodeTag type; + char* tablespacename; + char* maxsize; + List* options; + bool isReset; +} AlterTableSpaceOptionsStmt; + +/* ---------------------- + * Create/Alter Extension Statements + * ---------------------- + */ +typedef struct CreateExtensionStmt { + NodeTag type; + char* extname; + bool if_not_exists; /* just do nothing if it already exists? */ + List* options; /* List of DefElem nodes */ +} CreateExtensionStmt; + +/* Only used for ALTER EXTENSION UPDATE; later might need an action field */ +typedef struct AlterExtensionStmt { + NodeTag type; + char* extname; + List* options; /* List of DefElem nodes */ +} AlterExtensionStmt; + +typedef struct AlterExtensionContentsStmt { + NodeTag type; + char* extname; /* Extension's name */ + int action; /* +1 = add object, -1 = drop object */ + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ +} AlterExtensionContentsStmt; + +/* ---------------------- + * Create/Alter FOREIGN DATA WRAPPER Statements + * ---------------------- + */ +typedef struct CreateFdwStmt { + NodeTag type; + char* fdwname; /* foreign-data wrapper name */ + List* func_options; /* HANDLER/VALIDATOR options */ + List* options; /* generic options to FDW */ +} CreateFdwStmt; + +typedef struct AlterFdwStmt { + NodeTag type; + char* fdwname; /* foreign-data wrapper name */ + List* func_options; /* HANDLER/VALIDATOR options */ + List* options; /* generic options to FDW */ +} AlterFdwStmt; + +/* ---------------------- + * Create Weak Password Statements + * ---------------------- + */ +typedef struct CreateWeakPasswordDictionaryStmt { + NodeTag type; + List* weak_password_string_list; +} CreateWeakPasswordDictionaryStmt; + +/* ---------------------- + * Drop Weak Password Statements + * ---------------------- + */ +typedef struct DropWeakPasswordDictionaryStmt { + NodeTag type; +} DropWeakPasswordDictionaryStmt; + +/* ---------------------- + * Create/Alter FOREIGN SERVER Statements + * ---------------------- + */ +typedef struct CreateForeignServerStmt { + NodeTag type; + char* servername; /* server name */ + char* servertype; /* optional server type */ + char* version; /* optional server version */ + char* fdwname; /* FDW name */ + List* options; /* generic options to server */ +} CreateForeignServerStmt; + +typedef struct AlterForeignServerStmt { + NodeTag type; + char* servername; /* server name */ + char* version; /* optional server version */ + List* options; /* generic options to server */ + bool has_version; /* version specified */ +} AlterForeignServerStmt; + +/* ---------------------- + * Create FOREIGN TABLE Statements + * ---------------------- + */ +typedef struct ForeignPartState { + NodeTag type; + + /* partition key of partitioned table , which is list of ColumnRef */ + List* partitionKey; +} ForeignPartState; + +struct DistributeBy; + +typedef struct CreateForeignTableStmt { + CreateStmt base; + char* servername; + Node* error_relation; + List* options; + List* extOptions; +#ifdef PGXC + DistributeBy* distributeby; +#endif + bool write_only; + ForeignPartState* part_state; +} CreateForeignTableStmt; + +/* ---------------------- + * Create/Drop USER MAPPING Statements + * ---------------------- + */ +typedef struct CreateUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + List* options; /* generic options to server */ +} CreateUserMappingStmt; + +typedef struct AlterUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + List* options; /* generic options to server */ +} AlterUserMappingStmt; + +typedef struct DropUserMappingStmt { + NodeTag type; + char* username; /* username or PUBLIC/CURRENT_USER */ + char* servername; /* server name */ + bool missing_ok; /* ignore missing mappings */ +} DropUserMappingStmt; + +/* ---------------------- + * Create Synonym Statement + * ---------------------- + */ +typedef struct CreateSynonymStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + List* synName; /* qualified name of synonym */ + List* objName; /* referenced object name, eg. relation, view, function, procedure. */ +} CreateSynonymStmt; + +/* ---------------------- + * Drop Synonym Statement + * ---------------------- + */ +typedef struct DropSynonymStmt { + NodeTag type; + List* synName; /* qualified name of synonym */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing; /* skip error if a synonym is missing? */ +} DropSynonymStmt; + +/* ---------------------- + * Create/Alter DATA SOURCE Statements + * ---------------------- + */ +typedef struct CreateDataSourceStmt { + NodeTag type; + char* srcname; /* source name */ + char* srctype; /* optional source type */ + char* version; /* optional source version */ + List* options; /* generic options to server */ +} CreateDataSourceStmt; + +typedef struct AlterDataSourceStmt { + NodeTag type; + char* srcname; /* source name */ + char* srctype; /* optional source type */ + char* version; /* optional source version */ + List* options; /* generic options to source */ + bool has_version; /* version specified */ +} AlterDataSourceStmt; + +/* ---------------------- + * Create TRIGGER Statement + * ---------------------- + */ +typedef struct CreateTrigStmt { + NodeTag type; + char* trigname; /* TRIGGER's name */ + RangeVar* relation; /* relation trigger is on */ + List* funcname; /* qual. name of function to call */ + List* args; /* list of (T_String) Values or NIL */ + bool row; /* ROW/STATEMENT */ + /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ + int16 timing; /* BEFORE, AFTER, or INSTEAD */ + /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ + int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */ + List* columns; /* column names, or NIL for all columns */ + Node* whenClause; /* qual expression, or NULL if none */ + bool isconstraint; /* This is a constraint trigger */ + /* The remaining fields are only used for constraint triggers */ + bool deferrable; /* [NOT] DEFERRABLE */ + bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ + RangeVar* constrrel; /* opposite relation, if RI trigger */ +} CreateTrigStmt; + +/* ---------------------- + * Create PROCEDURAL LANGUAGE Statements + * ---------------------- + */ +typedef struct CreatePLangStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + char* plname; /* PL name */ + List* plhandler; /* PL call handler function (qual. name) */ + List* plinline; /* optional inline function (qual. name) */ + List* plvalidator; /* optional validator function (qual. name) */ + bool pltrusted; /* PL is trusted */ +} CreatePLangStmt; + +/* ---------------------- + * Create/Alter/Drop Role Statements + * + * Note: these node types are also used for the backwards-compatible + * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases + * there's really no need to distinguish what the original spelling was, + * but for CREATE we mark the type because the defaults vary. + * ---------------------- + */ +typedef enum RoleStmtType { ROLESTMT_ROLE, ROLESTMT_USER, ROLESTMT_GROUP } RoleStmtType; + +typedef struct CreateRoleStmt { + NodeTag type; + RoleStmtType stmt_type; /* ROLE/USER/GROUP */ + char* role; /* role name */ + List* options; /* List of DefElem nodes */ +} CreateRoleStmt; + +typedef struct AlterRoleStmt { + NodeTag type; + char* role; /* role name */ + List* options; /* List of DefElem nodes */ + int action; /* +1 = add members, -1 = drop members */ + RoleLockType lockstatus; +} AlterRoleStmt; + +typedef struct DropRoleStmt { + NodeTag type; + List* roles; /* List of roles to remove */ + bool missing_ok; /* skip error if a role is missing? */ + bool is_user; /* drop user or role */ + bool inherit_from_parent; /* whether user is inherited from parent user */ + DropBehavior behavior; /* CASCADE or RESTRICT */ +} DropRoleStmt; + +/* ---------------------- + * {Create|Alter} SEQUENCE Statement + * ---------------------- + */ + +typedef struct CreateSeqStmt { + NodeTag type; + RangeVar* sequence; /* the sequence to create */ + List* options; + Oid ownerId; /* ID of owner, or InvalidOid for default */ +#ifdef PGXC + bool is_serial; /* Indicates if this sequence is part of SERIAL process */ +#endif + int64 uuid; /* UUID of the sequence, mark unique sequence globally */ + bool canCreateTempSeq; /* create sequence when "create table (like )" */ +} CreateSeqStmt; + +typedef struct AlterSeqStmt { + NodeTag type; + RangeVar* sequence; /* the sequence to alter */ + List* options; + bool missing_ok; /* skip error if a role is missing? */ +#ifdef PGXC + bool is_serial; /* Indicates if this sequence is part of SERIAL process */ +#endif +} AlterSeqStmt; + +/* ---------------------- + * Create {Aggregate|Operator|Type} Statement + * ---------------------- + */ +typedef struct DefineStmt { + NodeTag type; + ObjectType kind; /* aggregate, operator, type */ + bool oldstyle; /* hack to signal old CREATE AGG syntax */ + List* defnames; /* qualified name (list of Value strings) */ + List* args; /* a list of TypeName (if needed) */ + List* definition; /* a list of DefElem */ +} DefineStmt; + +/* ---------------------- + * Create Domain Statement + * ---------------------- + */ +typedef struct CreateDomainStmt { + NodeTag type; + List* domainname; /* qualified name (list of Value strings) */ + TypeName* typname; /* the base type */ + CollateClause* collClause; /* untransformed COLLATE spec, if any */ + List* constraints; /* constraints (list of Constraint nodes) */ +} CreateDomainStmt; + +/* ---------------------- + * Create Operator Class Statement + * ---------------------- + */ +typedef struct CreateOpClassStmt { + NodeTag type; + List* opclassname; /* qualified name (list of Value strings) */ + List* opfamilyname; /* qualified name (ditto); NIL if omitted */ + char* amname; /* name of index AM opclass is for */ + TypeName* datatype; /* datatype of indexed column */ + List* items; /* List of CreateOpClassItem nodes */ + bool isDefault; /* Should be marked as default for type? */ +} CreateOpClassStmt; + +#define OPCLASS_ITEM_OPERATOR 1 +#define OPCLASS_ITEM_FUNCTION 2 +#define OPCLASS_ITEM_STORAGETYPE 3 + +typedef struct CreateOpClassItem { + NodeTag type; + int itemtype; /* see codes above */ + /* fields used for an operator or function item: */ + List* name; /* operator or function name */ + List* args; /* argument types */ + int number; /* strategy num or support proc num */ + List* order_family; /* only used for ordering operators */ + List* class_args; /* only used for functions */ + /* fields used for a storagetype item: */ + TypeName* storedtype; /* datatype stored in index */ +} CreateOpClassItem; + +/* ---------------------- + * Create Operator Family Statement + * ---------------------- + */ +typedef struct CreateOpFamilyStmt { + NodeTag type; + List* opfamilyname; /* qualified name (list of Value strings) */ + char* amname; /* name of index AM opfamily is for */ +} CreateOpFamilyStmt; + +/* ---------------------- + * Alter Operator Family Statement + * ---------------------- + */ +typedef struct AlterOpFamilyStmt { + NodeTag type; + List* opfamilyname; /* qualified name (list of Value strings) */ + char* amname; /* name of index AM opfamily is for */ + bool isDrop; /* ADD or DROP the items? */ + List* items; /* List of CreateOpClassItem nodes */ +} AlterOpFamilyStmt; + + +#ifdef ENABLE_MOT +typedef struct DropForeignStmt { + NodeTag type; + char relkind; + Oid reloid; + Oid indexoid; + char* name; +} DropForeignStmt; +#endif + +/* ---------------------- + * Truncate Table Statement + * ---------------------- + */ +typedef struct TruncateStmt { + NodeTag type; + List* relations; /* relations (RangeVars) to be truncated */ + bool restart_seqs; /* restart owned sequences? */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ +} TruncateStmt; + +/* ---------------------- + * Comment On Statement + * ---------------------- + */ +typedef struct CommentStmt { + NodeTag type; + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ + char* comment; /* Comment to insert, or NULL to remove */ +} CommentStmt; + +/* ---------------------- + * SECURITY LABEL Statement + * ---------------------- + */ +typedef struct SecLabelStmt { + NodeTag type; + ObjectType objtype; /* Object's type */ + List* objname; /* Qualified name of the object */ + List* objargs; /* Arguments if needed (eg, for functions) */ + char* provider; /* Label provider (or NULL) */ + char* label; /* New security label to be assigned */ +} SecLabelStmt; + +/* ---------------------- + * Close Portal Statement + * ---------------------- + */ +typedef struct ClosePortalStmt { + NodeTag type; + char* portalname; /* name of the portal (cursor) */ + /* NULL means CLOSE ALL */ +} ClosePortalStmt; + +/* ---------------------- + * Fetch Statement (also Move) + * ---------------------- + */ +typedef enum FetchDirection { + /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */ + FETCH_FORWARD, + FETCH_BACKWARD, + /* for these, howMany indicates a position; only one row is fetched */ + FETCH_ABSOLUTE, + FETCH_RELATIVE +} FetchDirection; + +#define FETCH_ALL LONG_MAX + +typedef struct FetchStmt { + NodeTag type; + FetchDirection direction; /* see above */ + long howMany; /* number of rows, or position argument */ + char* portalname; /* name of portal (cursor) */ + bool ismove; /* TRUE if MOVE */ +} FetchStmt; + +/* ---------------------- + * Create Index Statement + * + * This represents creation of an index and/or an associated constraint. + * If isconstraint is true, we should create a pg_constraint entry along + * with the index. But if indexOid isn't InvalidOid, we are not creating an + * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint + * must always be true in this case, and the fields describing the index + * properties are empty. + * ---------------------- + */ +typedef struct IndexStmt { + NodeTag type; + char* schemaname; /* namespace of new index, or NULL for default */ + char* idxname; /* name of new index, or NULL for default */ + RangeVar* relation; /* relation to build index on */ + char* accessMethod; /* name of access method (eg. btree) */ + char* tableSpace; /* tablespace, or NULL for default */ + List* indexParams; /* columns to index: a list of IndexElem */ + List* indexIncludingParams; /* additional columns to index: a list of IndexElem */ + List* options; /* WITH clause options: a list of DefElem */ + Node* whereClause; /* qualification (partial-index predicate) */ + List* excludeOpNames; /* exclusion operator names, or NIL if none */ + char* idxcomment; /* comment to apply to index, or NULL */ + Oid indexOid; /* OID of an existing index, if any */ + Oid oldNode; /* relfilenode of existing storage, if any */ + Oid oldPSortOid; /* oid of existing psort storage for col-storage, if any */ + List* partIndexOldNodes; /* partition relfilenode of existing storage, if any */ + List* partIndexOldPSortOid; /* partition psort oid, if any */ + Node* partClause; /* partition index define */ + + /* @hdfs + * is a partitioned index? The foreign table dose not index. The isPartitioned + * value is false when relation is a foreign table. + */ + bool isPartitioned; + bool isGlobal; /* is GLOBAL partition index */ + bool unique; /* is index unique? */ + bool primary; /* is index a primary key? */ + bool isconstraint; /* is it for a pkey/unique constraint? */ + bool deferrable; /* is the constraint DEFERRABLE? */ + bool initdeferred; /* is the constraint INITIALLY DEFERRED? */ + bool concurrent; /* should this be a concurrent index build? */ + InformationalConstraint* inforConstraint; /* Soft constraint info, Currently only the HDFS foreign table support it + */ + + /* + * Internal_flag is set to true when we use informational constraint feature, + * at the same time not_enforeced is also set to true. + */ + bool internal_flag; + /* + * For memory adapation, we will check the size of table before index create, + * but if it's constraint index during table creation, we don't need to do the size + * check, so set this flag to skip this + */ + bool skip_mem_check; + + /* adaptive memory assigned for the stmt */ + AdaptMem memUsage; +} IndexStmt; + +/* ---------------------- + * Create Function Statement + * ---------------------- + */ +typedef struct CreateFunctionStmt { + NodeTag type; + bool isOraStyle; /* T => a db compatible function or procedure */ + bool replace; /* T => replace if already exists */ + List* funcname; /* qualified name of function to create */ + List* parameters; /* a list of FunctionParameter */ + TypeName* returnType; /* the return type */ + List* options; /* a list of DefElem */ + List* withClause; /* a list of DefElem */ + bool isProcedure; /* true if it is a procedure */ +} CreateFunctionStmt; + +typedef struct AlterFunctionStmt { + NodeTag type; + FuncWithArgs* func; /* name and args of function */ + List* actions; /* list of DefElem */ +} AlterFunctionStmt; + +/* ---------------------- + * DO Statement + * + * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API + * ---------------------- + */ +typedef struct DoStmt { + NodeTag type; + List* args; /* List of DefElem nodes */ +} DoStmt; + +typedef struct InlineCodeBlock { + NodeTag type; + char* source_text; /* source text of anonymous code block */ + Oid langOid; /* OID of selected language */ + bool langIsTrusted; /* trusted property of the language */ + bool atomic; /* Atomic execution context, does not allow transactions */ +} InlineCodeBlock; + +typedef struct CallContext +{ + NodeTag type; + bool atomic; /* Atomic execution context, does not allow transactions */ +} CallContext; + +/* ---------------------- + * Alter Object Rename Statement + * ---------------------- + */ +typedef struct RenameStmt { + NodeTag type; + ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */ + ObjectType relationType; /* if column name, associated relation type */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* subname; /* name of contained object (column, rule, + * trigger, etc) */ + char* newname; /* the new name */ + DropBehavior behavior; /* RESTRICT or CASCADE behavior */ + bool missing_ok; /* skip error if missing? */ +} RenameStmt; + +/* ---------------------- + * ALTER object SET SCHEMA Statement + * ---------------------- + */ +typedef struct AlterObjectSchemaStmt { + NodeTag type; + ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* addname; /* additional name if needed */ + char* newschema; /* the new schema */ + bool missing_ok; /* skip error if missing? */ +} AlterObjectSchemaStmt; + +/* ---------------------- + * Alter Object Owner Statement + * ---------------------- + */ +typedef struct AlterOwnerStmt { + NodeTag type; + ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ + RangeVar* relation; /* in case it's a table */ + List* object; /* in case it's some other object */ + List* objarg; /* argument types, if applicable */ + char* addname; /* additional name if needed */ + char* newowner; /* the new owner */ +} AlterOwnerStmt; + +/* ---------------------- + * Create Rule Statement + * ---------------------- + */ +typedef struct RuleStmt { + NodeTag type; + RangeVar* relation; /* relation the rule is for */ + char* rulename; /* name of the rule */ + Node* whereClause; /* qualifications */ + CmdType event; /* SELECT, INSERT, etc */ + bool instead; /* is a 'do instead'? */ + List* actions; /* the action statements */ + bool replace; /* OR REPLACE */ + char* sql_statement; /* used for resize rule */ +} RuleStmt; + +/* ---------------------- + * Notify Statement + * ---------------------- + */ +typedef struct NotifyStmt { + NodeTag type; + char* conditionname; /* condition name to notify */ + char* payload; /* the payload string, or NULL if none */ +} NotifyStmt; + +/* ---------------------- + * Listen Statement + * ---------------------- + */ +typedef struct ListenStmt { + NodeTag type; + char* conditionname; /* condition name to listen on */ +} ListenStmt; + +/* ---------------------- + * Unlisten Statement + * ---------------------- + */ +typedef struct UnlistenStmt { + NodeTag type; + char* conditionname; /* name to unlisten on, or NULL for all */ +} UnlistenStmt; + +/* ---------------------- + * Create Type Statement, composite types + * ---------------------- + */ +typedef struct CompositeTypeStmt { + NodeTag type; + RangeVar* typevar; /* the composite type to be created */ + List* coldeflist; /* list of ColumnDef nodes */ +} CompositeTypeStmt; + +/* ---------------------- + * Create Type Statement, enum types + * ---------------------- + */ +typedef struct CreateEnumStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + List* vals; /* enum values (list of Value strings) */ +} CreateEnumStmt; + +/* ---------------------- + * Create Type Statement, range types + * ---------------------- + */ +typedef struct CreateRangeStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + List* params; /* range parameters (list of DefElem) */ +} CreateRangeStmt; + +/* ---------------------- + * Alter Type Statement, enum types + * ---------------------- + */ +typedef struct AlterEnumStmt { + NodeTag type; + List* typname; /* qualified name (list of Value strings) */ + char* oldVal; /* old enum value's name, if renaming */ + char* newVal; /* new enum value's name */ + char* newValNeighbor; /* neighboring enum value, if specified */ + bool newValIsAfter; /* place new enum value after neighbor? */ + bool skipIfNewValExists; /* no error if new already exists? */ +} AlterEnumStmt; + +/* ---------------------- + * Load Statement + * ---------------------- + */ +typedef struct LoadStmt { + NodeTag type; + char* filename; /* file to load */ +} LoadStmt; + +/* ---------------------- + * Createdb Statement + * ---------------------- + */ +typedef struct CreatedbStmt { + NodeTag type; + char* dbname; /* name of database to create */ + List* options; /* List of DefElem nodes */ +} CreatedbStmt; + +/* ---------------------- + * Alter Database + * ---------------------- + */ +typedef struct AlterDatabaseStmt { + NodeTag type; + char* dbname; /* name of database to alter */ + List* options; /* List of DefElem nodes */ +} AlterDatabaseStmt; + +/* ---------------------- + * Dropdb Statement + * ---------------------- + */ +typedef struct DropdbStmt { + NodeTag type; + char* dbname; /* database to drop */ + bool missing_ok; /* skip error if db is missing? */ +} DropdbStmt; + +#ifndef ENABLE_MULTIPLE_NODES +/* ---------------------- + * Alter System Statement + * ---------------------- + */ +typedef struct AlterSystemStmt { + NodeTag type; + VariableSetStmt *setstmt; /* SET subcommand */ +} AlterSystemStmt; +#endif +/* ---------------------- + * Cluster Statement (support pbrown's cluster index implementation) + * ---------------------- + */ +typedef struct ClusterStmt { + NodeTag type; + RangeVar* relation; /* relation being indexed, or NULL if all */ + char* indexname; /* original index defined */ + bool verbose; /* print progress info */ + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ +} ClusterStmt; + +/* ---------------------- + * Vacuum and Analyze Statements + * + * Even though these are nominally two statements, it's convenient to use + * just one node type for both. Note that at least one of VACOPT_VACUUM + * and VACOPT_ANALYZE must be set in options. VACOPT_FREEZE is an internal + * convenience for the grammar and is not examined at runtime --- the + * freeze_min_age and freeze_table_age fields are what matter. + * ---------------------- + */ +typedef enum VacuumOption { + VACOPT_VACUUM = 1 << 0, /* do VACUUM */ + VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */ + VACOPT_VERBOSE = 1 << 2, /* print progress info */ + VACOPT_FREEZE = 1 << 3, /* FREEZE option */ + VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */ + VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */ + VACOPT_MERGE = 1 << 6, /* move data from delta table to main table */ + VACOPT_MULTICOLUMN = 1 << 7, + VACOPT_VERIFY = 1 << 8, /* VERITY to check the data file */ + VACOPT_FAST = 1 << 9, /* verify fast option */ + VACOPT_COMPLETE = 1 << 10, /* verify complete option */ +#ifdef ENABLE_MOT + VACOPT_AUTOVAC = 1 << 11, /* mark automatic vacuum initiation */ +#endif + VACOPT_COMPACT = 1 << 30, /* compact hdfs file with invalid data just for DFS table */ + VACOPT_HDFSDIRECTORY = 1 << 31 /* just clean empty hdfs directory */ +} VacuumOption; + +#define DEFAULT_SAMPLE_ROWCNT 30000 +#define ANALYZE_MODE_MAX_NUM 4 +#define GET_ESTTOTALROWCNTS_FLAG ((double)(-1.0)) +#define INVALID_ESTTOTALROWS ((double)(-1.0)) + +/* + * Currently, the HDFS table need collect three statistics information + * in pg_statistic. we define AnalyzeMode enum strunct to realize global + * analyze. + * ANALYZENORMAL: Execute normal analyze command. + * ANALYZEMAIN: Collect only HDFS table information when execute global analyze. + * ANALYZEDELTA: Collect only Delta table information when execute global analyze. + * ANALYZECOMPLEX: Collect HDFS table and Delta table information when execute global analyze. + */ +typedef enum AnalyzeMode { ANALYZENORMAL = 0, ANALYZEMAIN = 1, ANALYZEDELTA = 2, ANALYZECOMPLEX = 3 } AnalyzeMode; + +typedef struct GlobalStatInfoEx { + AnalyzeMode eAnalyzeMode; /* The mode of table whitch will collect stat info, normal table or HDFS table. + It need collect three statistics information for HDFS table. */ + double sampleRate; /* CN compute it and send to DN. */ + double secsamplerows; /* real sample rows num for second sampling. */ + bool isReplication; /* the current relation is replication or not. */ + bool exec_query; /* do query for dfs table and delta table to get sample or not according to the ratio with rows of + complex. */ + double totalRowCnts; /* How many tuples receive from DN. */ + int64 topRowCnts; /* Top tuple numbers receive from DN. */ + int64 topMemSize; /* memory_size(KB)=com_size*oneTupleSize for DN, top memory size of all DNs for CN. */ + int attnum; /* column num for current table. */ + double dn1totalRowCnts; /* reltuples from DN1. */ + double* dndistinct; /* stadndistinct for DN1 */ + double* correlations; /* correlation of stats for DN1 */ + int num_samples; /* how many sample rows receive from DN. */ + HeapTuple* sampleRows; /* sample rows receive from DN. */ + TupleDesc tupleDesc; /* sample row's tuple descriptor. */ +} GlobalStatInfoEx; + +typedef enum HdfsSampleRowsFlag { + SAMPLEFLAG_DFS = 1 << 0, /* sample rows for dfs table. */ + SAMPLEFLAG_DELTA = 1 << 1, /* sample rows for delta table */ +} HdfsSampleRowsFlag; + +/* One sample row of HDFS table. */ +typedef struct { + double totalrows; /* estimate total rows */ + double samplerows; /* real sample rows num for first sampling. */ + double secsamplerows; /* real sample rows num for second sampling. */ + int8* flag; /* Identify which category(main/delta/complex) the sample row belong. */ + HeapTuple* rows; /* sample row data. */ +} HDFS_SAMPLE_ROWS; + +/* All sample rows of HDFS table for global stats. */ +typedef struct { + MemoryContext hdfs_sample_context; /* using to save sample rows. */ + double totalSampleRowCnt; /* total sample row count include dfs table and delta table */ + HDFS_SAMPLE_ROWS stHdfsSampleRows[ANALYZECOMPLEX]; /* sample rows include dfs table and delta table. */ +} GBLSTAT_HDFS_SAMPLE_ROWS; + +struct SplitMap; + +typedef struct VacuumStmt { + NodeTag type; + int options; /* OR of VacuumOption flags */ + int flags; /* flags to distinguish partition or btree */ + /* the values for this flags are in vacuum.h */ + Oid rely_oid; /* for btree, it is the heap btree or it is InvalidOid */ + int freeze_min_age; /* min freeze age, or -1 to use default */ + int freeze_table_age; /* age at which to scan whole table */ + RangeVar* relation; /* single table to process, or NULL */ + List* va_cols; /* list of column names, or NIL for all */ + + Relation onepartrel; /* for tracing the opened relation */ + Partition onepart; /* for tracing the opened partition */ + List* partList; +#ifdef PGXC + void* HDFSDnWorkFlow; /* @hdfs HDFSDnWorkFlow stores analyze operation related information */ +#endif + bool isForeignTables; /* @hdfs This parameter is true when we run "analyze [verbose] foreign table;" command */ + bool isPgFdwForeignTables; /* This parameter is true when the fdw of foreign table is gc_fdw */ +#ifdef ENABLE_MOT + bool isMOTForeignTable; +#endif + + /* + * @hdfs + * parameter totalFileCnt and nodeNo is set by CNSchedulingForAnalyze + * CNSchedulingForAnalyze( int *totalFilesCnt, + * int *nodeNo, + * Oid foreignTableId) + */ + unsigned int totalFileCnt; /* @hdfs The count of file to be sampled in analyze foreign table operation */ + int nodeNo; /* @hdfs Which data node will do analyze operation, + @global stats: Other coordinators will get statistics from which coordinator node. */ + + /* + * @hdfs total number of Data nodes, we use this number to adjust reltuples cnt stored in pg_class + * eg: We do the operation "analyze tablename", we have x data nodes and tablename is a hdfs foreign + * table. Data node finish analyze command, CN get tuples number information from DN. This number + * is 1/x of the total tuples number. We adjust this number to the real one in CN. + */ + unsigned int DnCnt; + + /* + * Add param for global stats. + */ + DestReceiver* dest; /* used to DN send sample rows to CN. */ + int num_samples; /* how many sample rows receive from DN. */ + HeapTuple* sampleRows; /* sample rows receive from DN. */ + TupleDesc tupleDesc; /* sample row's tuple descriptor for normal table. */ + int tableidx; /* set current index which table need to set sample rate or total row counts */ + GlobalStatInfoEx pstGlobalStatEx[ANALYZE_MODE_MAX_NUM - 1]; /* the auxiliary info for global stats, it extend to + identify hdfs table. */ + unsigned int orgCnNodeNo; /* the nodeId identify which CN receive analyze command from client, other CN need to get + stats from it. */ + List* hdfsforeignMapDnList; /* identify some datanodes belone to split map used for CN get total reltuples from + them. */ + bool sampleTableRequired; /* require sample table for get statistic. */ + List* tmpSampleTblNameList; /* identify sample table name if under debugging. */ + bool isAnalyzeTmpTable; /* true if analyze's table is temp table. */ +#ifdef PGXC + DistributionType disttype; /* Distribution type for analyze's table. */ +#endif + AdaptMem memUsage; /* adaptive memory assigned for the stmt */ + Oid curVerifyRel; /* the current relation is for database mode to send remote query */ + bool isCascade; /* used to verify table */ +} VacuumStmt; +/* Only support analyze, can not support vacuum analyze in transaction block. */ +#define IS_ONLY_ANALYZE_TMPTABLE (((stmt)->isAnalyzeTmpTable) && !((stmt)->options & VACOPT_VACUUM)) + +#ifdef PGXC +/* + * ---------------------- + * Barrier Statement + */ +typedef struct BarrierStmt { + NodeTag type; + const char* id; /* User supplied barrier id, if any */ +} BarrierStmt; + +/* + * ---------------------- + * Create Node statement + */ +typedef struct CreateNodeStmt { + NodeTag type; + char* node_name; + List* options; +} CreateNodeStmt; + +/* + * ---------------------- + * Alter Node statement + */ +typedef struct AlterNodeStmt { + NodeTag type; + char* node_name; + List* options; +} AlterNodeStmt; + +typedef struct AlterCoordinatorStmt { + NodeTag type; + char* node_name; + char* set_value; + List* coor_nodes; +} AlterCoordinatorStmt; + +/* + * ---------------------- + * Drop Node statement + */ +typedef struct DropNodeStmt { + NodeTag type; + char* node_name; + bool missing_ok; /* skip error if db is missing? */ + List* remote_nodes; /* specify where to drop node remotely */ +} DropNodeStmt; + +/* + * ---------------------- + * Create Group statement + */ +typedef struct CreateGroupStmt { + NodeTag type; + char* group_name; + char* src_group_name; + List* nodes; + List* buckets; + bool vcgroup; +} CreateGroupStmt; + +/* + * ---------------------- + * Alter Group statement + */ +typedef enum { + AG_SET_DEFAULT, + AG_SET_VCGROUP, + AG_SET_NOT_VCGROUP, + AG_SET_RENAME, + AG_SET_TABLE_GROUP, + AG_SET_BUCKETS, + AG_ADD_NODES, + AG_DELETE_NODES, + AG_RESIZE_GROUP, + AG_CONVERT_VCGROUP, + AG_SET_SEQ_ALLNODES, + AG_SET_SEQ_SELFNODES +} AlterGroupType; + +typedef struct AlterGroupStmt { + NodeTag type; + char* group_name; + char* install_name; + List* nodes; + AlterGroupType alter_type; +} AlterGroupStmt; + +/* + * ---------------------- + * Drop Group statement + */ +typedef struct DropGroupStmt { + NodeTag type; + char* group_name; + char* src_group_name; + bool to_elastic_group; +} DropGroupStmt; + +/* + * ---------------------- + * Create Policy Label statement + */ +typedef struct CreatePolicyLabelStmt { + NodeTag type; + bool if_not_exists; + char* label_type; + char* label_name; + List* label_items; +} CreatePolicyLabelStmt; + +/* + * ---------------------- + * Alter Policy Label statement + */ +typedef struct AlterPolicyLabelStmt { + NodeTag type; + char* stmt_type; + char* label_name; + List* label_items; +} AlterPolicyLabelStmt; + +/* + * ---------------------- + * Drop Policy Label statement + */ +typedef struct DropPolicyLabelStmt { + NodeTag type; + bool if_exists; + List* label_names; +} DropPolicyLabelStmt; + +/* + * ---------------------- + * + */ +typedef struct PolicyFilterNode +{ + NodeTag type; + char *node_type; /* operator or filter node */ + char *op_value; /* for operator type node usage */ + char *filter_type; /* for filter type node usage */ + List *values; /* for filter type node usage */ + bool has_not_operator; /* for filter type node usage */ + Node *left; /* for operator type node usage */ + Node *right; /* for operator type node usage */ +} PolicyFilterNode; + +/* + * ---------------------- + * Create Audit Policy statement + */ +typedef struct CreateAuditPolicyStmt +{ + NodeTag type; + bool if_not_exists; + char *policy_type; + char *policy_name; + List *policy_targets; + List *policy_filters; + bool policy_enabled; +} CreateAuditPolicyStmt; + +/* + * ---------------------- + * Alter Audit Policy statement + */ +typedef struct AlterAuditPolicyStmt +{ + NodeTag type; + bool missing_ok; + char *policy_name; + char *policy_action; + char *policy_type; + List *policy_items; + List *policy_filters; + char *policy_comments; + Node *policy_enabled; +} AlterAuditPolicyStmt; + +/* + * ---------------------- + * Drop Audit Policy statement + */ +typedef struct DropAuditPolicyStmt +{ + NodeTag type; + bool missing_ok; + List *policy_names; +} DropAuditPolicyStmt; + +/* + * ---------------------- + * Masking Policy Condition + */ +typedef struct MaskingPolicyCondition +{ + NodeTag type; + RangeVar *fqdn; + char *_operator; + Node *arg; +} MaskingPolicyCondition; + +/* + * ---------------------- + * Create Masking Policy statement + */ +typedef struct CreateMaskingPolicyStmt +{ + NodeTag type; + bool if_not_exists; + char *policy_name; + List *policy_data; + Node *policy_condition; + List *policy_filters; + bool policy_enabled; +} CreateMaskingPolicyStmt; + +/* + * ---------------------- + * Alter Masking Policy statement + */ +typedef struct AlterMaskingPolicyStmt +{ + NodeTag type; + char *policy_name; + char *policy_action; + List *policy_items; + Node *policy_condition; + List *policy_filters; + char *policy_comments; + Node *policy_enabled; +} AlterMaskingPolicyStmt; + +/* + * ---------------------- + * Drop Masking Policy statement + */ +typedef struct DropMaskingPolicyStmt +{ + NodeTag type; + bool if_exists; + List *policy_names; +} DropMaskingPolicyStmt; + +/* + * ---------------------- + * Create Resource Pool statement + */ +typedef struct CreateResourcePoolStmt { + NodeTag type; + char* pool_name; + List* options; +} CreateResourcePoolStmt; + +/* + * ---------------------- + * Alter Resource Pool statement + */ +typedef struct AlterResourcePoolStmt { + NodeTag type; + char* pool_name; + List* options; +} AlterResourcePoolStmt; + +/* + * ---------------------- + * Drop Resource Pool statement + */ +typedef struct DropResourcePoolStmt { + NodeTag type; + bool missing_ok; + char* pool_name; +} DropResourcePoolStmt; + +/* + * ---------------------- + * Create Workload Group statement + */ +typedef struct CreateWorkloadGroupStmt { + NodeTag type; + char* group_name; + char* pool_name; + List* options; +} CreateWorkloadGroupStmt; + +/* + * ---------------------- + * Alter Workload Group statement + */ +typedef struct AlterWorkloadGroupStmt { + NodeTag type; + char* group_name; + char* pool_name; + List* options; +} AlterWorkloadGroupStmt; + +/* + * ---------------------- + * Drop Workload Group statement + */ +typedef struct DropWorkloadGroupStmt { + NodeTag type; + bool missing_ok; + char* group_name; +} DropWorkloadGroupStmt; + +/* + * ---------------------- + * Create App Workload Group Mapping statement + */ +typedef struct CreateAppWorkloadGroupMappingStmt { + NodeTag type; + char* app_name; + List* options; +} CreateAppWorkloadGroupMappingStmt; + +/* + * ---------------------- + * Alter App Workload Group Mapping statement + */ +typedef struct AlterAppWorkloadGroupMappingStmt { + NodeTag type; + char* app_name; + List* options; +} AlterAppWorkloadGroupMappingStmt; + +/* + * ---------------------- + * Drop App Workload Group Mapping statement + */ +typedef struct DropAppWorkloadGroupMappingStmt { + NodeTag type; + bool missing_ok; + char* app_name; +} DropAppWorkloadGroupMappingStmt; + +#endif + +struct PlanInformation; +/* ---------------------- + * Explain Statement + * + * The "query" field is either a raw parse tree (SelectStmt, InsertStmt, etc) + * or a Query node if parse analysis has been done. Note that rewriting and + * planning of the query are always postponed until execution of EXPLAIN. + * ---------------------- + */ +typedef struct ExplainStmt { + NodeTag type; + Node* statement; /* statement_id for EXPLAIN PLAN */ + Node* query; /* the query (see comments above) */ + List* options; /* list of DefElem nodes */ + PlanInformation* planinfo; +} ExplainStmt; + +/* ---------------------- + * CREATE TABLE AS Statement (a/k/a SELECT INTO) + * + * A query written as CREATE TABLE AS will produce this node type natively. + * A query written as SELECT ... INTO will be transformed to this form during + * parse analysis. + * A query written as CREATE MATERIALIZED view will produce this node type, + * during parse analysis, since it needs all the same data. + * + * The "query" field is handled similarly to EXPLAIN, though note that it + * can be a SELECT or an EXECUTE, but not other DML statements. + * ---------------------- + */ +typedef struct CreateTableAsStmt { + NodeTag type; + Node* query; /* the query (see comments above) */ + IntoClause* into; /* destination table */ + ObjectType relkind; /* type of object */ + bool is_select_into; /* it was written as SELECT INTO */ +#ifdef PGXC + Oid groupid; + void* parserSetup; + void* parserSetupArg; +#endif +} CreateTableAsStmt; + +/* ---------------------- + * REFRESH MATERIALIZED VIEW Statement + * ---------------------- + */ +typedef struct RefreshMatViewStmt +{ + NodeTag type; + bool skipData; /* true for WITH NO DATA */ + bool incremental; /* true for INCREMENTALLY */ + RangeVar *relation; /* relation to insert into */ +} RefreshMatViewStmt; + +/* ---------------------- + * Checkpoint Statement + * ---------------------- + */ +typedef struct CheckPointStmt { + NodeTag type; +} CheckPointStmt; + +/* ---------------------- + * Discard Statement + * ---------------------- + */ +typedef enum DiscardMode { DISCARD_ALL, DISCARD_PLANS, DISCARD_TEMP } DiscardMode; + +typedef struct DiscardStmt { + NodeTag type; + DiscardMode target; +} DiscardStmt; + +/* ---------------------- + * LOCK Statement + * ---------------------- + */ +typedef struct LockStmt { + NodeTag type; + List* relations; /* relations to lock */ + int mode; /* lock mode */ + bool nowait; /* no wait mode */ +} LockStmt; + +/* ---------------------- + * SET CONSTRAINTS Statement + * ---------------------- + */ +typedef struct ConstraintsSetStmt { + NodeTag type; + List* constraints; /* List of names as RangeVars */ + bool deferred; +} ConstraintsSetStmt; + +#ifdef ENABLE_MOT +typedef struct ReindexForeignStmt { + NodeTag type; + char relkind; + Oid reloid; + Oid indexoid; + char* name; +} ReindexForeignStmt; +#endif + +/* ---------------------- + * CREATE CONVERSION Statement + * ---------------------- + */ +typedef struct CreateConversionStmt { + NodeTag type; + List* conversion_name; /* Name of the conversion */ + char* for_encoding_name; /* source encoding name */ + char* to_encoding_name; /* destination encoding name */ + List* func_name; /* qualified conversion function name */ + bool def; /* is this a default conversion? */ +} CreateConversionStmt; + +/* ---------------------- + * CREATE CAST Statement + * ---------------------- + */ +typedef struct CreateCastStmt { + NodeTag type; + TypeName* sourcetype; + TypeName* targettype; + FuncWithArgs* func; + CoercionContext context; + bool inout; +} CreateCastStmt; + +/* ---------------------- + * DEALLOCATE Statement + * ---------------------- + */ +typedef struct DeallocateStmt { + NodeTag type; + char* name; /* The name of the plan to remove */ + /* NULL means DEALLOCATE ALL */ +} DeallocateStmt; + +/* + * DROP OWNED statement + */ +typedef struct DropOwnedStmt { + NodeTag type; + List* roles; + DropBehavior behavior; +} DropOwnedStmt; + +/* + * REASSIGN OWNED statement + */ +typedef struct ReassignOwnedStmt { + NodeTag type; + List* roles; + char* newrole; +} ReassignOwnedStmt; + +/* + * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default + */ +typedef struct AlterTSDictionaryStmt { + NodeTag type; + List* dictname; /* qualified name (list of Value strings) */ + List* options; /* List of DefElem nodes */ +} AlterTSDictionaryStmt; + +/* + * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default + */ +typedef struct AlterTSConfigurationStmt { + NodeTag type; + List* cfgname; /* qualified name (list of Value strings) */ + + /* + * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is + * NIL, but tokentype isn't, DROP MAPPING was specified. + */ + List* tokentype; /* list of Value strings */ + List* dicts; /* list of list of Value strings */ + List* cfoptions; /* list of configuration options */ + bool override; /* if true - remove old variant */ + bool replace; /* if true - replace dictionary by another */ + bool missing_ok; /* for DROP - skip error if missing? */ + bool is_reset; /* if true - reset options */ +} AlterTSConfigurationStmt; + +/* + * CLEAN CONNECTION statement + */ +typedef struct CleanConnStmt { + NodeTag type; + List* nodes; /* list of nodes dropped */ + char* dbname; /* name of database to drop connections */ + char* username; /* name of user whose connections are dropped */ + bool is_coord; /* type of connections dropped */ + bool is_force; /* option force */ + bool is_check; /* option check */ +} CleanConnStmt; + +/* + * CreateTableLike Context + */ +typedef struct TableLikeCtx { + NodeTag type; + bits32 options; /* OR of TableLikeOption flags */ + bool temp_table; /* temporary table or not */ + bool hasoids; /* has oids or not */ + List* columns; /* the list of ColumnDef */ + List* ckconstraints; + List* comments; + List* cluster_keys; + PartitionState* partition; + List* inh_indexes; + List* reloptions; +} TableLikeCtx; + +typedef struct CreateDirectoryStmt { + NodeTag type; + bool replace; /* T => replace if already exists */ + char* directoryname; /* the name of directory to create */ + char* owner; /* directory's owner */ + char* location; /* the real path of directory */ +} CreateDirectoryStmt; + +typedef struct AlterDirectoryStmt { + NodeTag type; + char* directoryname; /* the name of directory to create */ + char* owner; /* directory's owner */ + char* location; /* the real path of directory */ + List* options; /* list of options */ +} AlterDirectoryStmt; + +typedef struct DropDirectoryStmt { + NodeTag type; + char* directoryname; /* the name of directory to drop */ + bool missing_ok; /* skip error if db is missing? */ + +} DropDirectoryStmt; +#endif /* PARSENODES_H */ + diff -uprN postgresql-hll-2.14_old/include/nodes/pg_list.h postgresql-hll-2.14/include/nodes/pg_list.h --- postgresql-hll-2.14_old/include/nodes/pg_list.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/pg_list.h 2020-12-12 17:06:43.322349006 +0800 @@ -0,0 +1,398 @@ +/* ------------------------------------------------------------------------- + * + * pg_list.h + * interface for PostgreSQL generic linked list package + * + * This package implements singly-linked homogeneous lists. + * + * It is important to have constant-time length, append, and prepend + * operations. To achieve this, we deal with two distinct data + * structures: + * + * 1. A set of "list cells": each cell contains a data field and + * a link to the next cell in the list or NULL. + * 2. A single structure containing metadata about the list: the + * type of the list, pointers to the head and tail cells, and + * the length of the list. + * + * We support three types of lists: + * + * T_List: lists of pointers + * (in practice usually pointers to Nodes, but not always; + * declared as "void *" to minimize casting annoyances) + * T_IntList: lists of integers + * T_OidList: lists of Oids + * + * (At the moment, ints and Oids are the same size, but they may not + * always be so; try to be careful to maintain the distinction.) + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/pg_list.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_LIST_H +#define PG_LIST_H + +#include "nodes/nodes.h" + +typedef struct ListCell ListCell; + +typedef struct DListCell DListCell; + +typedef struct List { + NodeTag type; /* T_List, T_IntList, or T_OidList */ + int length; + ListCell* head; + ListCell* tail; +} List; + +struct ListCell { + union { + void* ptr_value; + int int_value; + Oid oid_value; + } data; + ListCell* next; +}; + +typedef struct DList { + NodeTag type; + int length; + DListCell* head; + DListCell* tail; +} DList; + +struct DListCell { + union { + void* ptr_value; + int int_value; + Oid oid_value; + } data; + DListCell* next; + DListCell* prev; +}; + +/* + * The *only* valid representation of an empty list is NIL; in other + * words, a non-NIL list is guaranteed to have length >= 1 and + * head/tail != NULL + */ +#define NIL ((List*)NULL) + +/* + * These routines are used frequently. However, we can't implement + * them as macros, since we want to avoid double-evaluation of macro + * arguments. Therefore, we implement them using static inline functions + * if supported by the compiler, or as regular functions otherwise. + */ +#ifdef USE_INLINE + +static inline ListCell* list_head(const List* l) +{ + return l ? l->head : NULL; +} + +static inline ListCell* list_tail(List* l) +{ + return l ? l->tail : NULL; +} + +static inline int list_length(const List* l) +{ + return l ? l->length : 0; +} + +static inline DListCell* dlist_head_cell(const DList* l) +{ + return l ? l->head : NULL; +} + +static inline DListCell* dlist_tail_cell(DList* l) +{ + return l ? l->tail : NULL; +} + +#else + +extern ListCell* list_head(const List* l); +extern ListCell* list_tail(List* l); +extern int list_length(const List* l); + +extern ListCell *dlist_head_cell(const DList *l); +extern ListCell *dlist_tail_cell(DList *l); + +#endif /* USE_INLINE */ + +/* + * NB: There is an unfortunate legacy from a previous incarnation of + * the List API: the macro lfirst() was used to mean "the data in this + * cons cell". To avoid changing every usage of lfirst(), that meaning + * has been kept. As a result, lfirst() takes a ListCell and returns + * the data it contains; to get the data in the first cell of a + * List, use linitial(). Worse, lsecond() is more closely related to + * linitial() than lfirst(): given a List, lsecond() returns the data + * in the second cons cell. + */ +#define lnext(lc) ((lc)->next) +#define lprev(lc) ((lc)->prev) +#define lfirst(lc) ((lc)->data.ptr_value) +#define lfirst_int(lc) ((lc)->data.int_value) +#define lfirst_oid(lc) ((lc)->data.oid_value) +#define lfirst_node(type, lc) castNode(type, lfirst(lc)) + +#define linitial(l) lfirst(list_head(l)) +#define linitial_int(l) lfirst_int(list_head(l)) +#define linitial_oid(l) lfirst_oid(list_head(l)) +#define linitial_node(type, l) castNode(type, linitial(l)) + +#define lsecond(l) lfirst(lnext(list_head(l))) +#define lsecond_int(l) lfirst_int(lnext(list_head(l))) +#define lsecond_oid(l) lfirst_oid(lnext(list_head(l))) +#define lsecond_node(type, l) castNode(type, lsecond(l)) + +#define lthird(l) lfirst(lnext(lnext(list_head(l)))) +#define lthird_int(l) lfirst_int(lnext(lnext(list_head(l)))) +#define lthird_oid(l) lfirst_oid(lnext(lnext(list_head(l)))) +#define lthird_node(type, l) castNode(type, lthird(l)) + +#define lfourth(l) lfirst(lnext(lnext(lnext(list_head(l))))) +#define lfourth_int(l) lfirst_int(lnext(lnext(lnext(list_head(l))))) +#define lfourth_oid(l) lfirst_oid(lnext(lnext(lnext(list_head(l))))) +#define lfourth_node(type, l) castNode(type, lfourth(l)) + +#define llast(l) lfirst(list_tail(l)) +#define llast_int(l) lfirst_int(list_tail(l)) +#define llast_oid(l) lfirst_oid(list_tail(l)) +#define llast_node(type, l) castNode(type, llast(l)) + +/* + * Convenience macros for building fixed-length lists + */ +#define list_make1(x1) lcons(x1, NIL) +#define list_make2(x1, x2) lcons(x1, list_make1(x2)) +#define list_make3(x1, x2, x3) lcons(x1, list_make2(x2, x3)) +#define list_make4(x1, x2, x3, x4) lcons(x1, list_make3(x2, x3, x4)) + +#define list_make1_int(x1) lcons_int(x1, NIL) +#define list_make2_int(x1, x2) lcons_int(x1, list_make1_int(x2)) +#define list_make3_int(x1, x2, x3) lcons_int(x1, list_make2_int(x2, x3)) +#define list_make4_int(x1, x2, x3, x4) lcons_int(x1, list_make3_int(x2, x3, x4)) + +#define list_make1_oid(x1) lcons_oid(x1, NIL) +#define list_make2_oid(x1, x2) lcons_oid(x1, list_make1_oid(x2)) +#define list_make3_oid(x1, x2, x3) lcons_oid(x1, list_make2_oid(x2, x3)) +#define list_make4_oid(x1, x2, x3, x4) lcons_oid(x1, list_make3_oid(x2, x3, x4)) + +/* + * foreach - + * a convenience macro which loops through the list + */ +#define foreach(cell, l) for ((cell) = list_head(l); (cell) != NULL; (cell) = lnext(cell)) + +#define foreach_cell(cell, l) for (ListCell* cell = list_head(l); cell != NULL; cell = lnext(cell)) + +#define dlist_foreach_cell(cell, l) \ + for ((cell) = dlist_head_cell(l); (cell) != NULL; (cell) = lnext(cell)) + +/* + * for_each_cell - + * a convenience macro which loops through a list starting from a + * specified cell + */ +#define for_each_cell(cell, initcell) for ((cell) = (initcell); (cell) != NULL; (cell) = lnext(cell)) + +/* + * forboth - + * a convenience macro for advancing through two linked lists + * simultaneously. This macro loops through both lists at the same + * time, stopping when either list runs out of elements. Depending + * on the requirements of the call site, it may also be wise to + * assert that the lengths of the two lists are equal. + */ +#define forboth(cell1, list1, cell2, list2) \ + for ((cell1) = list_head(list1), (cell2) = list_head(list2); (cell1) != NULL && (cell2) != NULL; \ + (cell1) = lnext(cell1), (cell2) = lnext(cell2)) + +/* + * forthree - + * the same for three lists + */ +#define forthree(cell1, list1, cell2, list2, cell3, list3) \ + for ((cell1) = list_head(list1), (cell2) = list_head(list2), (cell3) = list_head(list3); \ + (cell1) != NULL && (cell2) != NULL && (cell3) != NULL; \ + (cell1) = lnext(cell1), (cell2) = lnext(cell2), (cell3) = lnext(cell3)) + +extern DList* dlappend(DList* dlist, void* datum); + +extern List* lappend(List* list, void* datum); +extern List* lappend2(List* list, ListCell* cell); +extern List* lappend3(List*, List*); +extern List* lappend_int(List* list, int datum); +extern List* lappend_oid(List* list, Oid datum); + +extern ListCell* lappend_cell(List* list, ListCell* prev, void* datum); +extern ListCell* lappend_cell_int(List* list, ListCell* prev, int datum); +extern ListCell* lappend_cell_oid(List* list, ListCell* prev, Oid datum); + +extern List* lcons(void* datum, List* list); +extern List* lcons_int(int datum, List* list); +extern List* lcons_oid(Oid datum, List* list); + +extern List* list_concat(List* list1, List* list2); +extern List* list_truncate(List* list, int new_size); + +extern void* list_nth(const List* list, int n); +extern ListCell* list_nth_cell(const List* list, int n); +extern int list_nth_int(const List* list, int n); +extern Oid list_nth_oid(const List* list, int n); +#define list_nth_node(type, list, n) castNode(type, list_nth(list, n)) + +extern bool list_member(const List* list, const void* datum); +extern bool list_member_ptr(const List* list, const void* datum); +extern bool list_member_int(const List* list, int datum); +extern bool list_member_oid(const List* list, Oid datum); + +extern List* list_delete(List* list, const void* datum); +extern List* list_delete_ptr(List* list, const void* datum); +extern List* list_delete_int(List* list, int datum); +extern List* list_delete_oid(List* list, Oid datum); +extern List* list_delete_first(List* list); +extern List* list_delete_first_nofree(List* list); +extern List* list_delete_cell(List* list, ListCell* cell, ListCell* prev); +extern List* list_delete_cell2(List* list, ListCell* cell); +extern List *list_delete_name(List *list, const char* name); + +extern DList* dlist_delete_cell(DList* dlist, DListCell* cell, bool deep); + +extern List* RemoveListCell(List* list, int pos); + +typedef bool (*NodeMatchFunc)(void* val1, void* val2); +typedef void (*NodeHandler)(void*); +extern List* list_cell_clear(List* list, void* val, NodeMatchFunc is_match); +extern List* list_cell_handle(List* list, NodeHandler handle, bool removed); + +extern List* list_union(const List* list1, const List* list2); +extern List* list_union_ptr(const List* list1, const List* list2); +extern List* list_union_int(const List* list1, const List* list2); +extern List* list_union_oid(const List* list1, const List* list2); +extern List* list_intersection_int(const List* list1, const List* list2); +extern bool list_is_subset(List* list1, List* list2); + +#ifdef PGXC +/* Well... this is used by Postgres-XC */ +extern List* list_intersection_int(const List* list1, const List* list2); +#endif +extern List* list_intersection(const List* list1, const List* list2); + +/* currently, there's no need for list_intersection_int etc */ +extern List* list_difference(const List* list1, const List* list2); +extern List* list_difference_ptr(const List* list1, const List* list2); +extern List* list_difference_int(const List* list1, const List* list2); +extern List* list_difference_oid(const List* list1, const List* list2); + +extern List* list_append_unique(List* list, void* datum); +extern List* list_append_unique_ptr(List* list, void* datum); +extern List* list_append_unique_int(List* list, int datum); +extern List* list_append_unique_oid(List* list, Oid datum); + +extern List* list_concat_unique(List* list1, List* list2); +extern List* list_concat_unique_ptr(List* list1, List* list2); +extern List* list_concat_unique_int(List* list1, List* list2); +extern List* list_concat_unique_oid(List* list1, List* list2); + +extern void dlist_free(DList* list, bool deep); + +extern void list_free(List* list); +extern void list_free_deep(List* list); + +#define list_free_ext(list) \ + do { \ + if ((list) != NIL) { \ + list_free(list); \ + list = NIL; \ + } \ + } while (0) + +extern List* list_copy(const List* list); +extern List* list_copy_tail(const List* list, int nskip); + +extern void dlist_add_tail_cell(DList* dlist, DListCell* cell); +extern List* list_merge_int(List* list1, List* list2); +extern List* list_insert_nth_oid(List *list, int pos, Oid datum); + +/* + * To ease migration to the new list API, a set of compatibility + * macros are provided that reduce the impact of the list API changes + * as far as possible. Until client code has been rewritten to use the + * new list API, the ENABLE_LIST_COMPAT symbol can be defined before + * including pg_list.h + */ +#ifdef ENABLE_LIST_COMPAT + +#define lfirsti(lc) lfirst_int(lc) +#define lfirsto(lc) lfirst_oid(lc) + +#define makeList1(x1) list_make1(x1) +#define makeList2(x1, x2) list_make2(x1, x2) +#define makeList3(x1, x2, x3) list_make3(x1, x2, x3) +#define makeList4(x1, x2, x3, x4) list_make4(x1, x2, x3, x4) + +#define makeListi1(x1) list_make1_int(x1) +#define makeListi2(x1, x2) list_make2_int(x1, x2) + +#define makeListo1(x1) list_make1_oid(x1) +#define makeListo2(x1, x2) list_make2_oid(x1, x2) + +#define lconsi(datum, list) lcons_int(datum, list) +#define lconso(datum, list) lcons_oid(datum, list) + +#define lappendi(list, datum) lappend_int(list, datum) +#define lappendo(list, datum) lappend_oid(list, datum) + +#define nconc(l1, l2) list_concat(l1, l2) + +#define nth(n, list) list_nth(list, n) + +#define member(datum, list) list_member(list, datum) +#define ptrMember(datum, list) list_member_ptr(list, datum) +#define intMember(datum, list) list_member_int(list, datum) +#define oidMember(datum, list) list_member_oid(list, datum) + +/* + * Note that the old lremove() determined equality via pointer + * comparison, whereas the new list_delete() uses equal(); in order to + * keep the same behavior, we therefore need to map lremove() calls to + * list_delete_ptr() rather than list_delete() + */ +#define lremove(elem, list) list_delete_ptr(list, elem) +#define LispRemove(elem, list) list_delete(list, elem) +#define lremovei(elem, list) list_delete_int(list, elem) +#define lremoveo(elem, list) list_delete_oid(list, elem) + +#define ltruncate(n, list) list_truncate(list, n) + +#define set_union(l1, l2) list_union(l1, l2) +#define set_uniono(l1, l2) list_union_oid(l1, l2) +#define set_ptrUnion(l1, l2) list_union_ptr(l1, l2) + +#define set_difference(l1, l2) list_difference(l1, l2) +#define set_differenceo(l1, l2) list_difference_oid(l1, l2) +#define set_ptrDifference(l1, l2) list_difference_ptr(l1, l2) + +#define equali(l1, l2) equal(l1, l2) +#define equalo(l1, l2) equal(l1, l2) + +#define freeList(list) list_free(list) + +#define listCopy(list) list_copy(list) + +extern int length(List* list); +#endif /* ENABLE_LIST_COMPAT */ + +extern int dlength(DList* list); + +#endif /* PG_LIST_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/plannodes.h postgresql-hll-2.14/include/nodes/plannodes.h --- postgresql-hll-2.14_old/include/nodes/plannodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/plannodes.h 2020-12-12 17:06:43.322349006 +0800 @@ -0,0 +1,1385 @@ +/* ------------------------------------------------------------------------- + * + * plannodes.h + * definitions for query plan nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/plannodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANNODES_H +#define PLANNODES_H + +#include "access/sdir.h" +#include "foreign/foreign.h" +#include "nodes/bitmapset.h" +#include "nodes/primnodes.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "optimizer/pruning.h" +#include "pgxc/locator.h" +#include "pgxc/nodemgr.h" +#include "bulkload/dist_fdw.h" +#include "utils/bloom_filter.h" + +#define MAX_SPECIAL_BUCKETMAP_NUM 2 +#define BUCKETMAP_DEFAULT_INDEX -1 + +/* + * Determines if query has to be launched + * on Coordinators only (SEQUENCE DDL), + * on Datanodes (normal Remote Queries), + * or on all Postgres-XC nodes (Utilities and DDL). + */ +typedef enum +{ + EXEC_ON_DATANODES, + EXEC_ON_COORDS, + EXEC_ON_ALL_NODES, + EXEC_ON_NONE +} RemoteQueryExecType; + +#define EXEC_CONTAIN_COORDINATOR(exec_type) \ + ((exec_type) == EXEC_ON_ALL_NODES || (exec_type) == EXEC_ON_COORDS) + +#define EXEC_CONTAIN_DATANODE(exec_type) \ + ((exec_type) == EXEC_ON_ALL_NODES || (exec_type) == EXEC_ON_DATANODES) + +/* + * Determines the position where the RemoteQuery node will run. + */ +typedef enum { GATHER, PLAN_ROUTER, SCAN_GATHER } RemoteQueryType; + +/* + * @hdfs + * Determines the optimization mode base on informational constraint. + * Currently, join Scan and foreign scan about on HDFS foreign table + * would be optimized. + */ +typedef enum { INVALID_MODE, SCAN_OPTIMIZE_MODE, JOIN_OPTIMIZE_MODE } OptimizedMode; +/* ---------------------------------------------------------------- + * node definitions + * ---------------------------------------------------------------- + */ + +typedef struct NodeGroupQueryMem { + Oid ng_oid; + char nodegroup[NAMEDATALEN]; + + int query_mem[2]; /* memory in kb */ +} NodeGroupQueryMem; + +/* ---------------- + * PlannedStmt node + * + * The output of the planner is a Plan tree headed by a PlannedStmt node. + * PlannedStmt holds the "one time" information needed by the executor. + * ---------------- + */ +typedef struct PlannedStmt { + NodeTag type; + + CmdType commandType; /* select|insert|update|delete */ + + uint64 queryId; /* query identifier, uniquely indicate this plan in Runtime (copied from Query) */ + + bool hasReturning; /* is it insert|update|delete RETURNING? */ + + bool hasModifyingCTE; /* has insert|update|delete in WITH? */ + + bool canSetTag; /* do I set the command result tag? */ + + bool transientPlan; /* redo plan when TransactionXmin changes? */ + + bool dependsOnRole; /* is plan specific to current role? */ + + Plan* planTree; /* tree of Plan nodes */ + + List* rtable; /* list of RangeTblEntry nodes */ + + /* rtable indexes of target relations for INSERT/UPDATE/DELETE */ + List* resultRelations; /* integer list of RT indexes, or NIL */ + + Node* utilityStmt; /* non-null if this is DECLARE CURSOR */ + + List* subplans; /* Plan trees for SubPlan expressions */ + + Bitmapset* rewindPlanIDs; /* indices of subplans that require REWIND */ + + List* rowMarks; /* a list of PlanRowMark's */ + + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the plan depends on */ + + List* invalItems; /* other dependencies, as PlanInvalItems */ + + int nParamExec; /* number of PARAM_EXEC Params used */ + + int num_streams; /* number of stream exist in plan tree */ + + int max_push_sql_num; /* number of split sql want push DN execute */ + + int gather_count; /* gather_count in query */ + + int num_nodes; /* number of data nodes */ + + NodeDefinition* nodesDefinition; /* all data nodes' defination */ + + int instrument_option; /* used for collect instrument data */ + + int num_plannodes; /* how many plan node in this planstmt */ + + int query_mem[2]; /* how many memory the query can use , memory in kb */ + + int assigned_query_mem[2]; /* how many memory the query is assigned */ + + bool is_dynmaic_smp; + + int dynsmp_max_cpu; /* max avaliable cpu for this dn */ + + int dynsmp_avail_cpu; /* max avaliable cpu for this dn */ + + int dynsmp_cpu_util; + + int dynsmp_active_statement; + + double dynsmp_query_estimate_cpu_usge; + + int dynsmp_plan_optimal_dop; /* the final optimized dop for the plan */ + + int dynsmp_plan_original_dop; + + int dynsmp_dop_mem_limit; /* memory will put a limit on dop */ + + int dynsmp_min_non_spill_dop; /* optimal dop cannot greater than this */ + + int num_bucketmaps; /* Num of special-bucketmap stored in plannedstmt */ + + uint2* bucketMap[MAX_SPECIAL_BUCKETMAP_NUM]; /* the map information need to be get */ + + char* query_string; /* convey the query string to backend/stream thread of DataNode for debug purpose */ + + List* subplan_ids; /* in which plan id subplan should be inited */ + + List* initPlan; /* initplan in top plan node */ + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + */ + Index dataDestRelIndex; + + int MaxBloomFilterNum; + + int query_dop; /* Dop of current query. */ + + double plannertime; /* planner execute time */ + + /* set true in do_query_for_planrouter() for PlannedStmt sent to + * the compute pool + */ + bool in_compute_pool; + + /* true if there is/are ForeignScan node(s) of OBS foreign table + * in plantree. + */ + bool has_obsrel; + + List* plan_hint_warning; /* hint warning during plan generation, only used in CN */ + + List* noanalyze_rellist; /* relations and attributes that have no statistics, only used in CN */ + + int ng_num; /* nodegroup number */ + NodeGroupQueryMem* ng_queryMem; /* each nodegroup's query mem */ + bool ng_use_planA; /* true means I am a planA, default false */ + + bool isRowTriggerShippable; /* true if all row triggers are shippable. */ + bool is_stream_plan; + bool multi_node_hint; + + uint64 uniqueSQLId; +} PlannedStmt; + +typedef struct NodeGroupInfoContext { + Oid groupOids[MAX_SPECIAL_BUCKETMAP_NUM]; + uint2* bucketMap[MAX_SPECIAL_BUCKETMAP_NUM]; + int num_bucketmaps; +} NodeGroupInfoContext; + +/* + * Determine if this plan step needs excution on current dn + * RestoreMode is always considered as 'have to' execute + */ +#define NeedExecute(plan) \ + (isRestoreMode ? true \ + : (plan->exec_nodes == NULL || plan->exec_nodes->nodeList == NULL || \ + list_member_int((plan)->exec_nodes->nodeList, u_sess->pgxc_cxt.PGXCNodeId))) + +/* macro for fetching the Plan associated with a SubPlan node */ +#define exec_subplan_get_plan(plannedstmt, subplan) ((Plan*)list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1)) + +/* ---------------- + * Plan node + * + * All plan nodes "derive" from the Plan structure by having the + * Plan structure as the first field. This ensures that everything works + * when nodes are cast to Plan's. (node pointers are frequently cast to Plan* + * when passed around generically in the executor) + * + * We never actually instantiate any Plan nodes; this is just the common + * abstract superclass for all Plan-type nodes. + * ---------------- + */ +typedef struct Plan { + NodeTag type; + + int plan_node_id; /* node id */ + int parent_node_id; /* parent node id */ + RemoteQueryExecType exec_type; + + /* + * estimated execution costs for plan (see costsize.c for more info) + */ + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + + /* + * planner's estimate of result size of this plan step + */ + double plan_rows; /* number of global rows plan is expected to emit */ + double multiple; + int plan_width; /* average row width in bytes */ + int dop; /* degree of parallelism of current plan */ + + /* + * MPPDB Recursive-Union Support + * + * - @recursive_union_plan_nodeid + * Pointing to its belonging RecursiveUnion's plan node id to indate if we are + * under RecursiveUnion + * + * - @recursive_union_controller + * Indicate if current Plan node is controller node in recursive-union steps + * + * - @control_plan_nodeid + * Normally, set on the top-plan node of a producer thread, to indicate which + * control-plan we need syn-up with + * + * - @is_sync_planode + * Indicate the current producer thread is the sync-up thread in recursive union, + * normally set on produer's top plan node + * + * Please note the above four variables is meaningless if a plan node is not under + * recursive-union's recursive part + */ + /* + * plan node id of RecursiveUnion node where current plan node belongs to, 0 for + * not under recursive-union + */ + int recursive_union_plan_nodeid; + + /* flag to indicate if it is controller plan node */ + bool recursive_union_controller; + + /* plan node id of Controller plan node, 0 for not in control */ + int control_plan_nodeid; + + /* flag indicate if the current plan node is the sync node (for multi-stream case) */ + bool is_sync_plannode; + + /* + * Common structural data for all Plan types. + */ + List* targetlist; /* target list to be computed at this node */ + List* qual; /* implicitly-ANDed qual conditions */ + struct Plan* lefttree; /* input plan tree(s) */ + struct Plan* righttree; + + bool ispwj; /* is it special for partitionwisejoin? */ + int paramno; /* the partition'sn that it is scaning */ + + List* initPlan; /* Init Plan nodes (un-correlated expr + * subselects) */ + + List* distributed_keys; /* distributed on which key */ + ExecNodes* exec_nodes; /* List of Datanodes where to execute this plan */ + + /* + * Information for management of parameter-change-driven rescanning + * + * extParam includes the paramIDs of all external PARAM_EXEC params + * affecting this plan node or its children. setParam params from the + * node's initPlans are not included, but their extParams are. + * + * allParam includes all the extParam paramIDs, plus the IDs of local + * params that affect the node (i.e., the setParams of its initplans). + * These are _all_ the PARAM_EXEC params that affect this node. + */ + Bitmapset* extParam; + Bitmapset* allParam; + + // For vectorized engine, plan produce vector output + // + bool vec_output; + /* + * @hdfs + * Mark the foreign scan whether has unique results on one of its + * output columns. + */ + bool hasUniqueResults; + /* + * Mark the plan whether includes delta table or not. + */ + bool isDeltaTable; + + /* used to replace work_mem, maxmem in [0], and minmem in [1] */ + int operatorMemKB[2]; + /* allowed max mem after spread */ + int operatorMaxMem; + + bool parallel_enabled; /* Is it run in parallel? */ + bool hasHashFilter; /* true for this plan has a hashfilter */ + + List* var_list; /* Need bloom filter var list. */ + List* filterIndexList; /* Need used bloomfilter array index. */ + + /* used to replace work_mem */ + int** ng_operatorMemKBArray; /* for multiple logic cluster */ + int ng_num; + double innerdistinct; /* join inner rel distinct estimation value */ + double outerdistinct; /* join outer rel distinct estimation value */ +} Plan; + +/* ---------------- + * these are defined to avoid confusion problems with "left" + * and "right" and "inner" and "outer". The convention is that + * the "left" plan is the "outer" plan and the "right" plan is + * the inner plan, but these make the code more readable. + * ---------------- + */ +#define innerPlan(node) (((Plan*)(node))->righttree) +#define outerPlan(node) (((Plan*)(node))->lefttree) + +/* ---------------- + * Result node - + * If no outer plan, evaluate a variable-free targetlist. + * If outer plan, return tuples from outer plan (after a level of + * projection as shown by targetlist). + * + * If resconstantqual isn't NULL, it represents a one-time qualification + * test (i.e., one that doesn't depend on any variables from the outer plan, + * so needs to be evaluated only once). + * ---------------- + */ +typedef struct BaseResult { + Plan plan; + Node* resconstantqual; +} BaseResult; + +typedef struct VecResult : public BaseResult { +} VecResult; + +/* ---------------- + * ModifyTable node - + * Apply rows produced by subplan(s) to result table(s), + * by inserting, updating, or deleting. + * + * Note that rowMarks and epqParam are presumed to be valid for all the + * subplan(s); they can't contain any info that varies across subplans. + * ---------------- + */ +typedef struct ModifyTable { + Plan plan; + CmdType operation; /* INSERT, UPDATE, or DELETE */ + bool canSetTag; /* do we set the command tag/es_processed? */ + List* resultRelations; /* integer list of RT indexes */ + int resultRelIndex; /* index of first resultRel in plan's list */ + List* plans; /* plan(s) producing source data */ + List* returningLists; /* per-target-table RETURNING tlists */ + List* fdwPrivLists; /* per-target-table FDW private data lists */ + List* rowMarks; /* PlanRowMarks (non-locking only) */ + int epqParam; /* ID of Param for EvalPlanQual re-eval */ + bool partKeyUpdated; /* when update on a partitioned table,true: part key column + is to be updated,false: no part key column is to updated */ +#ifdef PGXC + List* remote_plans; /* per-target-table remote node */ + List* remote_insert_plans; + List* remote_update_plans; + List* remote_delete_plans; +#endif + bool is_dist_insertselect; + + ErrorCacheEntry* cacheEnt; /* Error record cache */ + + Index mergeTargetRelation; /* RT index of the merge target */ + List* mergeSourceTargetList; + List* mergeActionList; /* actions for MERGE */ + + UpsertAction upsertAction; /* DUPLICATE KEY UPDATE action */ + List* updateTlist; /* List of UPDATE target */ + List* exclRelTlist; /* target list of the EXECLUDED pseudo relation */ + Index exclRelRTIndex; /* RTI of the EXCLUDED pseudo relation */ + + OpMemInfo mem_info; /* Memory info for modify node */ +} ModifyTable; + +/* ---------------- + * Append node - + * Generate the concatenation of the results of sub-plans. + * ---------------- + */ +typedef struct Append { + Plan plan; + List* appendplans; +} Append; + +typedef struct VecAppend : public Append { +} VecAppend; +/* ---------------- + * MergeAppend node - + * Merge the results of pre-sorted sub-plans to preserve the ordering. + * ---------------- + */ +typedef struct MergeAppend { + Plan plan; + List* mergeplans; + /* remaining fields are just like the sort-key info in struct Sort */ + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* collations; /* OIDs of collations */ + bool* nullsFirst; /* NULLS FIRST/LAST directions */ +} MergeAppend; + +/* ---------------- + * RecursiveUnion node - + * Generate a recursive union of two subplans. + * + * The "outer" subplan is always the non-recursive term, and the "inner" + * subplan is the recursive term. + * ---------------- + */ +typedef struct RecursiveUnion { + Plan plan; + int wtParam; /* ID of Param representing work table */ + /* Remaining fields are zero/null in UNION ALL case */ + int numCols; /* number of columns to check for + * duplicate-ness */ + AttrNumber* dupColIdx; /* their indexes in the target list */ + Oid* dupOperators; /* equality operators to compare with */ + long numGroups; /* estimated number of groups in input */ + bool has_inner_stream; /* indicate the underlaying plan node has stream operator (on recursive-term) */ + bool has_outer_stream; /* indicate the underlaying plan node has stream operator (on none-recursive side) */ + bool is_used; + bool is_correlated; /* indicate if the recursive union contains correlated term, + * in case of correlated term involved, we need broadcast data + * to one datanode to execute the recursive CTE in one-DN mode */ +} RecursiveUnion; + +/* ---------------- + * BitmapAnd node - + * Generate the intersection of the results of sub-plans. + * + * The subplans must be of types that yield tuple bitmaps. The targetlist + * and qual fields of the plan are unused and are always NIL. + * ---------------- + */ +typedef struct BitmapAnd { + Plan plan; + List* bitmapplans; +} BitmapAnd; + +/* ---------------- + * BitmapOr node - + * Generate the union of the results of sub-plans. + * + * The subplans must be of types that yield tuple bitmaps. The targetlist + * and qual fields of the plan are unused and are always NIL. + * ---------------- + */ +typedef struct BitmapOr { + Plan plan; + List* bitmapplans; +} BitmapOr; + +/* + * ========== + * Scan nodes + * ========== + */ +typedef struct Scan { + Plan plan; + Index scanrelid; /* relid is index into the range table */ + bool isPartTbl; /* Does it scan a partitioned table */ + int itrs; /* table partition's number for scan */ + PruningResult* pruningInfo; /* pruning result for where-clause */ + BucketInfo* bucketInfo; /* pruning result for buckets */ + ScanDirection partScanDirection; /* specifies the scan ordering */ + /* + * @hdfs + * If we use the informational constarint, the following variables will be seted as true. + * If scan_qual_optimized is true, it means that foreign scan will be optimized by using + * scan qual in executor phase. + * If predicate_pushdown_optimized is true, it means that predicate is pushed down and + * foreign scan will be optimized in the executor phase by using the predicate. + */ + bool scan_qual_optimized; + bool predicate_pushdown_optimized; + + /* use struct pointer to avoid including parsenodes.h here */ + TableSampleClause* tablesample; + + /* Memory info for scan node, now it just used on indexscan, indexonlyscan, bitmapscan, dfsindexscan */ + OpMemInfo mem_info; +} Scan; + +/* ---------------- + * sequential scan node + * ---------------- + */ +typedef Scan SeqScan; + +/* + * ========== + * Column Store Scan nodes + * ========== + */ +typedef struct CStoreScan : public Scan { + /* Some optimization information */ + double selectionRatio; /* row output / rows scanned */ + List* cstorequal; /* push predicate down to cstorescan */ + List* minMaxInfo; /* min/max information, mark get this column min or max value. */ + RelstoreType relStoreLocation; /* The store position information. */ + bool is_replica_table; /* Is a replication table? */ +} CStoreScan; + +/* + * ========== + * Dfs Store Scan nodes. When the relation is CU format, we use CstoreScan + * to scan data. + * ========== + */ +typedef struct DfsScan : public Scan { + RelstoreType relStoreLocation; + char* storeFormat; /* The store format, the ORC format only is supported for dfsScan. */ + List* privateData; /* Private data. */ +} DfsScan; + +/* + * ========== + * Time Series Store Scan nodes + * ========== + */ +typedef struct TsStoreScan: public Scan { + /* Some optimization information */ + double selectionRatio; /* row output / rows scanned */ + List *tsstorequal; /* push predicate down to tsstorescan */ + List *minMaxInfo; /* min/max information, mark get this column min or max value.*/ + RelstoreType relStoreLocation; /* The store position information. */ + bool is_replica_table; /* Is a replication table? */ + AttrNumber sort_by_time_colidx; /* If is sort by tstime limit n */ + int limit; /* If is limit n */ + bool is_simple_scan; /* If is sort by tstime limit n */ + bool has_sort; /* If is have sort node */ + int series_func_calls; /* series function calls time */ + int top_key_func_arg; /* second arg of top_key function */ +} TsStoreScan; + +/* ---------------- + * index scan node + * + * indexqualorig is an implicitly-ANDed list of index qual expressions, each + * in the same form it appeared in the query WHERE condition. Each should + * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey). + * The indexkey is a Var or expression referencing column(s) of the index's + * base table. The comparisonval might be any expression, but it won't use + * any columns of the base table. The expressions are ordered by index + * column position (but items referencing the same index column can appear + * in any order). indexqualorig is used at runtime only if we have to recheck + * a lossy indexqual. + * + * indexqual has the same form, but the expressions have been commuted if + * necessary to put the indexkeys on the left, and the indexkeys are replaced + * by Var nodes identifying the index columns (their varno is INDEX_VAR and + * their varattno is the index column number). + * + * indexorderbyorig is similarly the original form of any ORDER BY expressions + * that are being implemented by the index, while indexorderby is modified to + * have index column Vars on the left-hand side. Here, multiple expressions + * must appear in exactly the ORDER BY order, and this is not necessarily the + * index column order. Only the expressions are provided, not the auxiliary + * sort-order information from the ORDER BY SortGroupClauses; it's assumed + * that the sort ordering is fully determinable from the top-level operators. + * indexorderbyorig is unused at run time, but is needed for EXPLAIN. + * (Note these fields are used for amcanorderbyop cases, not amcanorder cases.) + * + * indexorderdir specifies the scan ordering, for indexscans on amcanorder + * indexes (for other indexes it should be "don't care"). + * ---------------- + */ +typedef struct IndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + char* indexname; /* Index name of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + bool usecstoreindex; /* mark the column store index */ + Index indexscan_relid; /* Hack for column store index, treat the index as normal relation */ + List* idx_cstorequal; /* For column store, this contains only quals pushdownable to + storage engine */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* targetlist; /* Hack for column store index, target list to be computed at this node */ + bool index_only_scan; +} IndexScan; + +/* ---------------- + * index-only scan node + * + * IndexOnlyScan is very similar to IndexScan, but it specifies an + * index-only scan, in which the data comes from the index not the heap. + * Because of this, *all* Vars in the plan node's targetlist, qual, and + * index expressions reference index columns and have varno = INDEX_VAR. + * Hence we do not need separate indexqualorig and indexorderbyorig lists, + * since their contents would be equivalent to indexqual and indexorderby. + * + * To help EXPLAIN interpret the index Vars for display, we provide + * indextlist, which represents the contents of the index as a targetlist + * with one TLE per index column. Vars appearing in this list reference + * the base table, and this is the only field in the plan node that may + * contain such Vars. + * ---------------- + */ +typedef struct IndexOnlyScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indextlist; /* TargetEntry list describing index's cols */ + ScanDirection indexorderdir; /* forward or backward or don't care */ +} IndexOnlyScan; + +/* ---------------- + * bitmap index scan node + * + * BitmapIndexScan delivers a bitmap of potential tuple locations; + * it does not access the heap itself. The bitmap is used by an + * ancestor BitmapHeapScan node, possibly after passing through + * intermediate BitmapAnd and/or BitmapOr nodes to combine it with + * the results of other BitmapIndexScans. + * + * The fields have the same meanings as for IndexScan, except we don't + * store a direction flag because direction is uninteresting. + * + * In a BitmapIndexScan plan node, the targetlist and qual fields are + * not used and are always NIL. The indexqualorig field is unused at + * run time too, but is saved for the benefit of EXPLAIN. + * ---------------- + */ +typedef struct BitmapIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + char* indexname; /* name of index to scan */ + List* indexqual; /* list of index quals (OpExprs) */ + List* indexqualorig; /* the same in original form */ +} BitmapIndexScan; + +/* ---------------- + * bitmap sequential scan node + * + * This needs a copy of the qual conditions being used by the input index + * scans because there are various cases where we need to recheck the quals; + * for example, when the bitmap is lossy about the specific rows on a page + * that meet the index condition. + * ---------------- + */ +typedef struct BitmapHeapScan { + Scan scan; + List* bitmapqualorig; /* index quals, in standard expr form */ +} BitmapHeapScan; + +/* ---------------- + * Column Store index scan node + * + * ---------------- + */ +typedef struct CStoreIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + + List* baserelcstorequal; /* for base relation of index */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* indextlist; + RelstoreType relStoreLocation; /* The store position information. */ + bool indexonly; /* flag indicates index only scan */ +} CStoreIndexScan; + +typedef struct CStoreIndexCtidScan : public BitmapIndexScan { + List* indextlist; + List* cstorequal; +} CStoreIndexCtidScan; + +typedef struct CStoreIndexHeapScan : public BitmapHeapScan { +} CStoreIndexHeapScan; + +typedef struct CStoreIndexAnd : public BitmapAnd { +} CStoreIndexAnd; + +typedef struct CStoreIndexOr : public BitmapOr { +} CStoreIndexOr; + +/* ---------------- + * DFS Store index scan node + */ +typedef struct DfsIndexScan { + Scan scan; + Oid indexid; /* OID of index to scan */ + List* indextlist; /* list of index target entry which represents the column of base-relation */ + List* indexqual; /* list of index quals (usually OpExprs) */ + List* indexqualorig; /* the same in original form */ + List* indexorderby; /* list of index ORDER BY exprs */ + List* indexorderbyorig; /* the same in original form */ + ScanDirection indexorderdir; /* forward or backward or don't care */ + RelstoreType relStoreLocation; /* The store position information. */ + List* cstorequal; /* quals that can be pushdown to cstore base table */ + List* indexScantlist; /* list of target column for scanning on index table */ + DfsScan* dfsScan; /* the inner object for scanning the base-relation */ + bool indexonly; /* flag indicates index only scan */ +} DfsIndexScan; + +/* ---------------- + * tid scan node + * + * tidquals is an implicitly OR'ed list of qual expressions of the form + * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)". + * ---------------- + */ +typedef struct TidScan { + Scan scan; + List* tidquals; /* qual(s) involving CTID = something */ +} TidScan; + +/* ---------------- + * subquery scan node + * + * SubqueryScan is for scanning the output of a sub-query in the range table. + * We often need an extra plan node above the sub-query's plan to perform + * expression evaluations (which we can't push into the sub-query without + * risking changing its semantics). Although we are not scanning a physical + * relation, we make this a descendant of Scan anyway for code-sharing + * purposes. + * + * Note: we store the sub-plan in the type-specific subplan field, not in + * the generic lefttree field as you might expect. This is because we do + * not want plan-tree-traversal routines to recurse into the subplan without + * knowing that they are changing Query contexts. + * ---------------- + */ +typedef struct SubqueryScan { + Scan scan; + Plan* subplan; +} SubqueryScan; + +typedef struct VecSubqueryScan : public SubqueryScan { +} VecSubqueryScan; + +/* ---------------- + * FunctionScan node + * ---------------- + */ +typedef struct FunctionScan { + Scan scan; + Node* funcexpr; /* expression tree for func call */ + List* funccolnames; /* output column names (string Value nodes) */ + List* funccoltypes; /* OID list of column type OIDs */ + List* funccoltypmods; /* integer list of column typmods */ + List* funccolcollations; /* OID list of column collation OIDs */ +} FunctionScan; + +/* ---------------- + * ValuesScan node + * ---------------- + */ +typedef struct ValuesScan { + Scan scan; + List* values_lists; /* list of expression lists */ +} ValuesScan; + +/* ---------------- + * CteScan node + * ---------------- + */ +typedef struct CteScan { + Scan scan; + int ctePlanId; /* ID of init SubPlan for CTE */ + int cteParam; /* ID of Param representing CTE output */ + RecursiveUnion* subplan; /* subplan of CteScan, must be RecursiveUnion */ +} CteScan; + +/* ---------------- + * WorkTableScan node + * ---------------- + */ +typedef struct WorkTableScan { + Scan scan; + int wtParam; /* ID of Param representing work table */ +} WorkTableScan; + +/* ---------------- + * ForeignScan node + * + * fdw_exprs and fdw_private are both under the control of the foreign-data + * wrapper, but fdw_exprs is presumed to contain expression trees and will + * be post-processed accordingly by the planner; fdw_private won't be. + * Note that everything in both lists must be copiable by copyObject(). + * One way to store an arbitrary blob of bytes is to represent it as a bytea + * Const. Usually, though, you'll be better off choosing a representation + * that can be dumped usefully by nodeToString(). + * ---------------- + */ +typedef struct ForeignScan { + Scan scan; + + Oid scan_relid; /* Oid of the scan relation */ + List* fdw_exprs; /* expressions that FDW may evaluate */ + List* fdw_private; /* private data for FDW */ + bool fsSystemCol; /* true if any "system column" is needed */ + + bool needSaveError; + ErrorCacheEntry* errCache; /* Error record cache */ + + /* This is used in hdfs foreign scan to store prunning information. */ + List* prunningResult; + + RelationMetaData* rel; /* the meta data of the foreign table */ + ForeignOptions* options; /* the configuration options */ + + /* number of files(objects) to be scanned. just valid for planner */ + int64 objectNum; + BloomFilterSet** bloomFilterSet; + int bfNum; /* the number of bloomfilter object. */ + + /* set true in do_query_for_planrouter() for ForeignScan sent to + * the compute pool + */ + bool in_compute_pool; + bool not_use_bloomfilter; /* set true in ExecInitXXXX() of planrouter node */ +} ForeignScan; + +/* ---------------- + * ExtensiblePlan node + * + * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist, + * and fs_relids fields apply equally to ExtensiblePlan's extensible_exprs, + * extensible_data, extensible_plan_tlist, and extensible_relids fields. The + * convention of setting scan.scanrelid to zero for joins applies as well. + * + * Note that since Plan trees can be copied, extensible scan providers *must* + * fit all plan data they need into those fields; embedding ExtensiblePlan in + * a larger struct will not work. + * ---------------- + */ +struct ExtensiblePlan; + +typedef struct ExtensiblePlanMethods { + char* ExtensibleName; + + /* Create execution state (ExtensiblePlanState) from a ExtensiblePlan plan node */ + Node* (*CreateExtensiblePlanState)(struct ExtensiblePlan* cscan); +} ExtensiblePlanMethods; + +typedef struct ExtensiblePlan { + Scan scan; + + uint32 flags; /* mask of EXTENSIBLEPATH_* flags, see relation.h */ + + List* extensible_plans; /* list of Plan nodes, if any */ + + List* extensible_exprs; /* expressions that extensible code may evaluate */ + + List* extensible_private; /* private data for extensible code */ + + List* extensible_plan_tlist; /* optional tlist describing scan + * tuple */ + Bitmapset* extensible_relids; /* RTIs generated by this scan */ + + ExtensiblePlanMethods* methods; +} ExtensiblePlan; +/* + * ========== + * Join nodes + * ========== + */ + +/* ---------------- + * Join node + * + * jointype: rule for joining tuples from left and right subtrees + * joinqual: qual conditions that came from JOIN/ON or JOIN/USING + * (plan.qual contains conditions that came from WHERE) + * + * When jointype is INNER, joinqual and plan.qual are semantically + * interchangeable. For OUTER jointypes, the two are *not* interchangeable; + * only joinqual is used to determine whether a match has been found for + * the purpose of deciding whether to generate null-extended tuples. + * (But plan.qual is still applied before actually returning a tuple.) + * For an outer join, only joinquals are allowed to be used as the merge + * or hash condition of a merge or hash join. + * ---------------- + */ +typedef struct Join { + Plan plan; + JoinType jointype; + List* joinqual; /* JOIN quals (in addition to plan.qual) */ + /* + * @hdfs + * This flag will be set as true if we use informational constraint + * in order to optimize join plan. + */ + bool optimizable; + List* nulleqqual; + + uint32 skewoptimize; +} Join; + +/* ---------------- + * nest loop join node + * + * The nestParams list identifies any executor Params that must be passed + * into execution of the inner subplan carrying values from the current row + * of the outer subplan. Currently we restrict these values to be simple + * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan + * creation, the paramval can actually be a PlaceHolderVar expression; but it + * must be a Var with varno OUTER_VAR by the time it gets to the executor.) + * ---------------- + */ +typedef struct NestLoop { + Join join; + List* nestParams; /* list of NestLoopParam nodes */ + bool materialAll; +} NestLoop; + +typedef struct VecNestLoop : public NestLoop { +} VecNestLoop; + +typedef struct NestLoopParam { + NodeTag type; + int paramno; /* number of the PARAM_EXEC Param to set */ + Var* paramval; /* outer-relation Var to assign to Param */ +} NestLoopParam; + +/* ---------------- + * merge join node + * + * The expected ordering of each mergeable column is described by a btree + * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or + * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides + * of each mergeclause may be of different datatypes, but they are ordered the + * same way according to the common opfamily and collation. The operator in + * each mergeclause must be an equality operator of the indicated opfamily. + * ---------------- + */ +typedef struct MergeJoin { + Join join; + List* mergeclauses; /* mergeclauses as expression trees */ + /* these are arrays, but have the same length as the mergeclauses list: */ + Oid* mergeFamilies; /* per-clause OIDs of btree opfamilies */ + Oid* mergeCollations; /* per-clause OIDs of collations */ + int* mergeStrategies; /* per-clause ordering (ASC or DESC) */ + bool* mergeNullsFirst; /* per-clause nulls ordering */ +} MergeJoin; + +typedef struct VecMergeJoin : public MergeJoin { +} VecMergeJoin; +/* ---------------- + * hash join node + * ---------------- + */ +typedef struct HashJoin { + Join join; + List* hashclauses; + bool streamBothSides; + bool transferFilterFlag; + bool rebuildHashTable; + bool isSonicHash; + OpMemInfo mem_info; /* Memory info for inner hash table */ +} HashJoin; + +/* ---------------- + * materialization node + * ---------------- + */ +typedef struct Material { + Plan plan; + bool materialize_all; /* if all data should be materialized at the first time */ + OpMemInfo mem_info; /* Memory info for material */ +} Material; + +typedef struct VecMaterial : public Material { +} VecMaterial; + +/* ---------------- + * sort node + * ---------------- + */ +typedef struct Sort { + Plan plan; + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* collations; /* OIDs of collations */ + bool* nullsFirst; /* NULLS FIRST/LAST directions */ +#ifdef PGXC + bool srt_start_merge; /* No need to create the sorted runs. The + * underlying plan provides those runs. Merge + * them. + */ +#endif /* PGXC */ + OpMemInfo mem_info; /* Memory info for sort */ +} Sort; + +typedef struct VecSort : public Sort { +} VecSort; + +/* --------------- + * group node - + * Used for queries with GROUP BY (but no aggregates) specified. + * The input must be presorted according to the grouping columns. + * --------------- + */ +typedef struct Group { + Plan plan; + int numCols; /* number of grouping columns */ + AttrNumber* grpColIdx; /* their indexes in the target list */ + Oid* grpOperators; /* equality operators to compare with */ +} Group; + +typedef struct VecGroup : public Group { +} VecGroup; +/* --------------- + * aggregate node + * + * An Agg node implements plain or grouped aggregation. For grouped + * aggregation, we can work with presorted input or unsorted input; + * the latter strategy uses an internal hashtable. + * + * Notice the lack of any direct info about the aggregate functions to be + * computed. They are found by scanning the node's tlist and quals during + * executor startup. (It is possible that there are no aggregate functions; + * this could happen if they get optimized away by constant-folding, or if + * we are using the Agg node to implement hash-based grouping.) + * --------------- + */ +typedef enum AggStrategy { + AGG_PLAIN, /* simple agg across all input rows */ + AGG_SORTED, /* grouped agg, input must be sorted */ + AGG_HASHED /* grouped agg, use internal hashtable */ +} AggStrategy; + +#ifdef STREAMPLAN +typedef enum SAggMethod { + OPTIMAL_AGG, /* 0. chose the optimal hash agg plan according to costs. */ + DN_AGG_CN_AGG, /* 1. */ + DN_REDISTRIBUTE_AGG, /* 2. */ + DN_AGG_REDISTRIBUTE_AGG, /* 3. */ + DN_REDISTRIBUTE_AGG_CN_AGG, /* 1+. according to DN_AGG_CN_AGG */ + DN_REDISTRIBUTE_AGG_REDISTRIBUTE_AGG /* 3+. according to DN_AGG_REDISTRIBUTE_AGG */ +} SAggMethod; + +/* flags bits for SAggMethod choose */ +#define ALLOW_ALL_AGG 0X00 /* Any AggMethod may be selected */ +#define DISALLOW_CN_AGG 0x01 /* disallow DN_AGG_CN_AGG, DN_REDISTRIBUTE_AGG_CN_AGG */ +#define FOREC_SLVL_AGG 0x02 /* force single level agg, actually disallow CN_AGG meanwhile */ + +#endif + +typedef struct Agg { + Plan plan; + AggStrategy aggstrategy; + int numCols; /* number of grouping columns */ + AttrNumber* grpColIdx; /* their indexes in the target list */ + Oid* grpOperators; /* equality operators to compare with */ + long numGroups; /* estimated number of groups in input */ + List* groupingSets; /* grouping sets to use */ + List* chain; /* chained Agg/Sort nodes */ +#ifdef PGXC + bool is_final; /* apply final agg directly on the data received from remote Datanodes */ + bool single_node; /* We can finalise the aggregates on the datanode/s */ +#endif /* PGXC */ + Bitmapset* aggParams; /* IDs of Params used in Aggref inputs */ + OpMemInfo mem_info; /* Memory info for hashagg */ + bool is_sonichash; /* allowed to use sonic hash routine or not */ + bool is_dummy; /* just for coop analysis, if true, agg node does nothing */ + uint32 skew_optimize; /* skew optimize method for agg */ + bool unique_check; /* we will report an error when meet duplicate in unique check mode */ +} Agg; + +/* ---------------- + * window aggregate node + * ---------------- + */ +typedef struct WindowAgg { + Plan plan; + Index winref; /* ID referenced by window functions */ + int partNumCols; /* number of columns in partition clause */ + AttrNumber* partColIdx; /* their indexes in the target list */ + Oid* partOperators; /* equality operators for partition columns */ + int ordNumCols; /* number of columns in ordering clause */ + AttrNumber* ordColIdx; /* their indexes in the target list */ + Oid* ordOperators; /* equality operators for ordering columns */ + int frameOptions; /* frame_clause options, see WindowDef */ + Node* startOffset; /* expression for starting bound, if any */ + Node* endOffset; /* expression for ending bound, if any */ + OpMemInfo mem_info; /* Memory info for window agg with agg func */ +} WindowAgg; + +typedef struct VecWindowAgg : public WindowAgg { +} VecWindowAgg; +/* ---------------- + * unique node + * ---------------- + */ +typedef struct Unique { + Plan plan; + int numCols; /* number of columns to check for uniqueness */ + AttrNumber* uniqColIdx; /* their indexes in the target list */ + Oid* uniqOperators; /* equality operators to compare with */ +} Unique; + +/* ---------------- + * hash build node + * + * If the executor is supposed to try to apply skew join optimization, then + * skewTable/skewColumn/skewInherit identify the outer relation's join key + * column, from which the relevant MCV statistics can be fetched. Also, its + * type information is provided to save a lookup. + * ---------------- + */ +typedef struct Hash { + Plan plan; + Oid skewTable; /* outer join key's table OID, or InvalidOid */ + AttrNumber skewColumn; /* outer join key's column #, or zero */ + bool skewInherit; /* is outer join rel an inheritance tree? */ + Oid skewColType; /* datatype of the outer key column */ + int32 skewColTypmod; /* typmod of the outer key column */ + /* all other info is in the parent HashJoin node */ +} Hash; + +/* ---------------- + * setop node + * ---------------- + */ +typedef enum SetOpCmd { SETOPCMD_INTERSECT, SETOPCMD_INTERSECT_ALL, SETOPCMD_EXCEPT, SETOPCMD_EXCEPT_ALL } SetOpCmd; + +typedef enum SetOpStrategy { + SETOP_SORTED, /* input must be sorted */ + SETOP_HASHED /* use internal hashtable */ +} SetOpStrategy; + +typedef struct SetOp { + Plan plan; + SetOpCmd cmd; /* what to do */ + SetOpStrategy strategy; /* how to do it */ + int numCols; /* number of columns to check for + * duplicate-ness */ + AttrNumber* dupColIdx; /* their indexes in the target list */ + Oid* dupOperators; /* equality operators to compare with */ + AttrNumber flagColIdx; /* where is the flag column, if any */ + int firstFlag; /* flag value for first input relation */ + long numGroups; /* estimated number of groups in input */ + OpMemInfo mem_info; /* Memory info for hashagg set op */ +} SetOp; + +/* ---------------- + * lock-rows node + * + * rowMarks identifies the rels to be locked by this node; it should be + * a subset of the rowMarks listed in the top-level PlannedStmt. + * epqParam is a Param that all scan nodes below this one must depend on. + * It is used to force re-evaluation of the plan during EvalPlanQual. + * ---------------- + */ +typedef struct LockRows { + Plan plan; + List* rowMarks; /* a list of PlanRowMark's */ + int epqParam; /* ID of Param for EvalPlanQual re-eval */ +} LockRows; + +/* ---------------- + * limit node + * + * Note: as of Postgres 8.2, the offset and count expressions are expected + * to yield int8, rather than int4 as before. + * ---------------- + */ +typedef struct Limit { + Plan plan; + Node* limitOffset; /* OFFSET parameter, or NULL if none */ + Node* limitCount; /* COUNT parameter, or NULL if none */ +} Limit; + +typedef struct VecLimit : public Limit { +} VecLimit; + +/* + * RowMarkType - + * enums for types of row-marking operations + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely + * identify all the source rows, not only those from the target relations, so + * that we can perform EvalPlanQual rechecking at need. For plain tables we + * can just fetch the TID, the same as for a target relation. Otherwise (for + * example for VALUES or FUNCTION scans) we have to copy the whole row value. + * The latter is pretty inefficient but fortunately the case is not + * performance-critical in practice. + */ +typedef enum RowMarkType { + ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */ + ROW_MARK_SHARE, /* obtain shared tuple lock */ + ROW_MARK_REFERENCE, /* just fetch the TID */ + ROW_MARK_COPY, /* physically copy the row value */ + ROW_MARK_COPY_DATUM /* physically copy the datum of every row column */ +} RowMarkType; + +#define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_SHARE) + +/* + * PlanRowMark - + * plan-time representation of FOR UPDATE/SHARE clauses + * + * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate + * PlanRowMark node for each non-target relation in the query. Relations that + * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if + * real tables) or ROW_MARK_COPY (if not). + * + * Initially all PlanRowMarks have rti == prti and isParent == false. + * When the planner discovers that a relation is the root of an inheritance + * tree, it sets isParent true, and adds an additional PlanRowMark to the + * list for each child relation (including the target rel itself in its role + * as a child). The child entries have rti == child rel's RT index and + * prti == parent's RT index, and can therefore be recognized as children by + * the fact that prti != rti. + * + * The planner also adds resjunk output columns to the plan that carry + * information sufficient to identify the locked or fetched rows. For + * tables (markType != ROW_MARK_COPY), these columns are named + * tableoid%u OID of table + * ctid%u TID of row + * The tableoid column is only present for an inheritance hierarchy. + * When markType == ROW_MARK_COPY, there is instead a single column named + * wholerow%u whole-row value of relation + * In all three cases, %u represents the rowmark ID number (rowmarkId). + * This number is unique within a plan tree, except that child relation + * entries copy their parent's rowmarkId. (Assigning unique numbers + * means we needn't renumber rowmarkIds when flattening subqueries, which + * would require finding and renaming the resjunk columns as well.) + * Note this means that all tables in an inheritance hierarchy share the + * same resjunk column names. However, in an inherited UPDATE/DELETE the + * columns could have different physical column numbers in each subplan. + */ +typedef struct PlanRowMark { + NodeTag type; + Index rti; /* range table index of markable relation */ + Index prti; /* range table index of parent relation */ + Index rowmarkId; /* unique identifier for resjunk columns */ + RowMarkType markType; /* see enum above */ + bool noWait; /* NOWAIT option */ + bool isParent; /* true if this is a "dummy" parent entry */ + int numAttrs; /* number of attributes in subplan */ + Bitmapset* bms_nodeids; +} PlanRowMark; + +/* + * Plan invalidation info + * + * We track the objects on which a PlannedStmt depends in two ways: + * relations are recorded as a simple list of OIDs, and everything else + * is represented as a list of PlanInvalItems. A PlanInvalItem is designed + * to be used with the syscache invalidation mechanism, so it identifies a + * system catalog entry by cache ID and hash value. + */ +typedef struct PlanInvalItem { + NodeTag type; + int cacheId; /* a syscache ID, see utils/syscache.h */ + uint32 hashValue; /* hash value of object's cache lookup key */ +} PlanInvalItem; +/* + * Target : data partition + * Brief : structure definition about partition iteration + */ +typedef struct PartIteratorParam { + NodeTag type; + int paramno; +} PartIteratorParam; + +typedef struct PartIterator { + Plan plan; + PartitionType partType; /* partition type, range or interval? */ + int itrs; /* the number of the partitions */ + ScanDirection direction; + PartIteratorParam* param; + /* + * Below three variables are used to record starting partition id, ending partition id and number of + * partitions. + */ + int startPartitionId; /* Used in parallel execution to record smp worker starting partition id. */ + int endPartitionId; /* Used in parallel execution to record smp worker ending partition id. */ +} PartIterator; +typedef struct GlobalPartIterator { + int curItrs; + PruningResult* pruningResult; +} GlobalPartIterator; + +typedef struct VecPartIterator : public PartIterator { +} VecPartIterator; +/* + * Vector Plan Nodes. + * + */ + +/* ---------------- + * vector hash join node + * ---------------- + */ + +// comment to avoid g++ warning +// vector aggregation. + +typedef struct HashJoin VecHashJoin; +typedef struct Agg VecAgg; +typedef struct SetOp VecSetOp; +typedef struct Unique VecUnique; + +typedef struct RowToVec { + Plan plan; +} RowToVec; + +typedef struct VecToRow { + Plan plan; +} VecToRow; + +inline bool IsVecOutput(Plan* p) +{ + return p && p->vec_output; +} + +typedef struct VecForeignScan : public ForeignScan { +} VecForeignScan; + +typedef struct VecModifyTable : public ModifyTable { +} VecModifyTable; +#endif /* PLANNODES_H */ + diff -uprN postgresql-hll-2.14_old/include/nodes/primnodes.h postgresql-hll-2.14/include/nodes/primnodes.h --- postgresql-hll-2.14_old/include/nodes/primnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/primnodes.h 2020-12-12 17:06:43.323349019 +0800 @@ -0,0 +1,1403 @@ +/* ------------------------------------------------------------------------- + * + * primnodes.h + * Definitions for "primitive" node types, those that are used in more + * than one of the parse/plan/execute stages of the query pipeline. + * Currently, these are mostly nodes for executable expressions + * and join trees. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/nodes/primnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRIMNODES_H +#define PRIMNODES_H + +#include "access/attnum.h" +#include "nodes/pg_list.h" +#include "nodes/params.h" + +/* ---------------------------------------------------------------- + * node definitions + * ---------------------------------------------------------------- + */ + +/* + * Alias - + * specifies an alias for a range variable; the alias might also + * specify renaming of columns within the table. + * + * Note: colnames is a list of Value nodes (always strings). In Alias structs + * associated with RTEs, there may be entries corresponding to dropped + * columns; these are normally empty strings (""). See parsenodes.h for info. + */ +typedef struct Alias { + NodeTag type; + char* aliasname; /* aliased rel name (never qualified) */ + List* colnames; /* optional list of column aliases */ +} Alias; + +typedef enum InhOption { + INH_NO, /* Do NOT scan child tables */ + INH_YES, /* DO scan child tables */ + INH_DEFAULT /* Use current SQL_inheritance option */ +} InhOption; + +/* What to do at commit time for temporary relations */ +typedef enum OnCommitAction { + ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */ + ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */ + ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */ + ONCOMMIT_DROP /* ON COMMIT DROP */ +} OnCommitAction; + +// If enable_compress is off, the table will not be compressed no matter +// which option is specified. +// +typedef enum OptCompress { + COMPRESS_NO = 0, + COMPRESS_LOW, + COMPRESS_MIDDLE, + COMPRESS_HIGH, +} OptCompress; + +/* + * RangeVar - range variable, used in FROM clauses + * + * Also used to represent table names in utility statements; there, the alias + * field is not used, and inhOpt shows whether to apply the operation + * recursively to child tables. In some contexts it is also useful to carry + * a TEMP table indication here. + */ +typedef struct RangeVar { + NodeTag type; + char* catalogname; /* the catalog (database) name, or NULL */ + char* schemaname; /* the schema name, or NULL */ + char* relname; /* the relation/sequence name */ + char* partitionname; /* partition name, if is a partition */ + InhOption inhOpt; /* expand rel by inheritance? recursively act + * on children? */ + char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */ + Alias* alias; /* table alias & optional column aliases */ + int location; /* token location, or -1 if unknown */ + bool ispartition; /* for partition action */ + List* partitionKeyValuesList; + bool isbucket; /* is the RangeVar means a hash bucket id ? */ + List* buckets; /* the corresponding bucketid list */ + int length; +#ifdef ENABLE_MOT + Oid foreignOid; +#endif +} RangeVar; + +/* + * IntoClause - target information for SELECT INTO, CREATE TABLE AS, and + * CREATE MATERIALIZED VIEW + */ +typedef struct IntoClause { + NodeTag type; + + RangeVar* rel; /* target relation name */ + List* colNames; /* column names to assign, or NIL */ + List* options; /* options from WITH clause */ + OnCommitAction onCommit; /* what do we do at COMMIT? */ + int8 row_compress; /* row compression flag */ + char* tableSpaceName; /* table space to use, or NULL */ + bool skipData; /* true for WITH NO DATA */ + bool ivm; /* true for WITH IVM */ + char relkind; /* RELKIND_RELATION or RELKIND_MATVIEW */ +#ifdef PGXC + struct DistributeBy* distributeby; /* distribution to use, or NULL */ + struct PGXCSubCluster* subcluster; /* subcluster node members */ +#endif +} IntoClause; + +/* ---------------------------------------------------------------- + * node types for executable expressions + * ---------------------------------------------------------------- + */ + +/* + * Expr - generic superclass for executable-expression nodes + * + * All node types that are used in executable expression trees should derive + * from Expr (that is, have Expr as their first field). Since Expr only + * contains NodeTag, this is a formality, but it is an easy form of + * documentation. See also the ExprState node types in execnodes.h. + */ +typedef struct Expr { + NodeTag type; +} Expr; + +/* + * Var - expression node representing a variable (ie, a table column) + * + * Note: during parsing/planning, varnoold/varoattno are always just copies + * of varno/varattno. At the tail end of planning, Var nodes appearing in + * upper-level plan nodes are reassigned to point to the outputs of their + * subplans; for example, in a join node varno becomes INNER_VAR or OUTER_VAR + * and varattno becomes the index of the proper element of that subplan's + * target list. But varnoold/varoattno continue to hold the original values. + * The code doesn't really need varnoold/varoattno, but they are very useful + * for debugging and interpreting completed plans, so we keep them around. + */ +#define INNER_VAR 65000 /* reference to inner subplan */ +#define OUTER_VAR 65001 /* reference to outer subplan */ +#define INDEX_VAR 65002 /* reference to index column */ +#define MERGEJOIN_VAR 65003 /* reference to merge join results */ + +#define IS_SPECIAL_VARNO(varno) ((varno) >= INNER_VAR) + +/* Symbols for the indexes of the special RTE entries in rules */ +#define PRS2_OLD_VARNO 1 +#define PRS2_NEW_VARNO 2 + +typedef struct Var { + Expr xpr; + Index varno; /* index of this var's relation in the range + * table, or INNER_VAR/OUTER_VAR/INDEX_VAR */ + AttrNumber varattno; /* attribute number of this var, or zero for + * all */ + Oid vartype; /* pg_type OID for the type of this var */ + int32 vartypmod; /* pg_attribute typmod value */ + Oid varcollid; /* OID of collation, or InvalidOid if none */ + Index varlevelsup; /* for subquery variables referencing outer + * relations; 0 in a normal var, >0 means N + * levels up */ + Index varnoold; /* original value of varno, for debugging */ + AttrNumber varoattno; /* original value of varattno */ + int location; /* token location, or -1 if unknown */ +} Var; + +/* + * Const + */ +typedef struct Const { + Expr xpr; + Oid consttype; /* pg_type OID of the constant's datatype */ + int32 consttypmod; /* typmod value, if any */ + Oid constcollid; /* OID of collation, or InvalidOid if none */ + int constlen; /* typlen of the constant's datatype */ + Datum constvalue; /* the constant's value */ + bool constisnull; /* whether the constant is null (if true, + * constvalue is undefined) */ + bool constbyval; /* whether this datatype is passed by value. + * If true, then all the information is stored + * in the Datum. If false, then the Datum + * contains a pointer to the information. */ + int location; /* token location, or -1 if unknown */ + bool ismaxvalue; /*is the Const represent maxValue, maxValue is used for partition */ + + Cursor_Data cursor_data; +} Const; + +/* ---------------- + * Param + * paramkind - specifies the kind of parameter. The possible values + * for this field are: + * + * PARAM_EXTERN: The parameter value is supplied from outside the plan. + * Such parameters are numbered from 1 to n. + * + * PARAM_EXEC: The parameter is an internal executor parameter, used + * for passing values into and out of sub-queries or from + * nestloop joins to their inner scans. + * For historical reasons, such parameters are numbered from 0. + * These numbers are independent of PARAM_EXTERN numbers. + * + * PARAM_SUBLINK: The parameter represents an output column of a SubLink + * node's sub-select. The column number is contained in the + * `paramid' field. (This type of Param is converted to + * PARAM_EXEC during planning.) + * + * Note: currently, paramtypmod is valid for PARAM_SUBLINK Params, and for + * PARAM_EXEC Params generated from them; it is always -1 for PARAM_EXTERN + * params, since the APIs that supply values for such parameters don't carry + * any typmod info. + * ---------------- + */ +typedef enum ParamKind { PARAM_EXTERN, PARAM_EXEC, PARAM_SUBLINK } ParamKind; + +typedef struct Param { + Expr xpr; + ParamKind paramkind; /* kind of parameter. See above */ + int paramid; /* numeric ID for parameter */ + Oid paramtype; /* pg_type OID of parameter's datatype */ + int32 paramtypmod; /* typmod value, if known */ + Oid paramcollid; /* OID of collation, or InvalidOid if none */ + int location; /* token location, or -1 if unknown */ +} Param; + +/* + * Aggref + * + * The aggregate's args list is a targetlist, ie, a list of TargetEntry nodes + * (before Postgres 9.0 it was just bare expressions). The non-resjunk TLEs + * represent the aggregate's regular arguments (if any) and resjunk TLEs can + * be added at the end to represent ORDER BY expressions that are not also + * arguments. As in a top-level Query, the TLEs can be marked with + * ressortgroupref indexes to let them be referenced by SortGroupClause + * entries in the aggorder and/or aggdistinct lists. This represents ORDER BY + * and DISTINCT operations to be applied to the aggregate input rows before + * they are passed to the transition function. The grammar only allows a + * simple "DISTINCT" specifier for the arguments, but we use the full + * query-level representation to allow more code sharing. + */ +typedef struct Aggref { + Expr xpr; + Oid aggfnoid; /* pg_proc Oid of the aggregate */ + Oid aggtype; /* type Oid of result of the aggregate */ + Oid aggcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ +#ifdef PGXC + Oid aggtrantype; /* type Oid of transition results */ + bool agghas_collectfn; /* is collection function available */ + int8 aggstage; /* in which stage this aggref is in */ +#endif /* PGXC */ + List* aggdirectargs; /* direct arguments, if an ordered-set agg */ + List* args; /* arguments and sort expressions */ + List* aggorder; /* ORDER BY (list of SortGroupClause) */ + List* aggdistinct; /* DISTINCT (list of SortGroupClause) */ + bool aggstar; /* TRUE if argument list was really '*' */ + bool aggvariadic; /* true if variadic arguments have been + * combined into an array last argument */ + char aggkind; /* aggregate kind (see pg_aggregate.h) */ + Index agglevelsup; /* > 0 if agg belongs to outer query */ + int location; /* token location, or -1 if unknown */ +} Aggref; + +/* + * GroupingFunc + * + * A GroupingFunc is a GROUPING(...) expression, which behaves in many ways + * like an aggregate function (e.g. it "belongs" to a specific query level, + * which might not be the one immediately containing it), but also differs in + * an important respect: it never evaluates its arguments, they merely + * designate expressions from the GROUP BY clause of the query level to which + * it belongs. + * + * The spec defines the evaluation of GROUPING() purely by syntactic + * replacement, but we make it a real expression for optimization purposes so + * that one Agg node can handle multiple grouping sets at once. Evaluating the + * result only needs the column positions to check against the grouping set + * being projected. However, for EXPLAIN to produce meaningful output, we have + * to keep the original expressions around, since expression deparse does not + * give us any feasible way to get at the GROUP BY clause. + * + * Also, we treat two GroupingFunc nodes as equal if they have equal arguments + * lists and agglevelsup, without comparing the refs and cols annotations. + * + * In raw parse output we have only the args list; parse analysis fills in the + * refs list, and the planner fills in the cols list. + */ +typedef struct GroupingFunc { + Expr xpr; + List* args; /* arguments, not evaluated but kept for + * benefit of EXPLAIN etc. */ + List* refs; /* ressortgrouprefs of arguments */ + List* cols; /* actual column positions set by planner */ + Index agglevelsup; /* same as Aggref.agglevelsup */ + int location; /* token location */ +} GroupingFunc; + +typedef struct GroupingId { + Expr xpr; +} GroupingId; + +/* + * WindowFunc + */ +typedef struct WindowFunc { + Expr xpr; + Oid winfnoid; /* pg_proc Oid of the function */ + Oid wintype; /* type Oid of result of the window function */ + Oid wincollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + List* args; /* arguments to the window function */ + Index winref; /* index of associated WindowClause */ + bool winstar; /* TRUE if argument list was really '*' */ + bool winagg; /* is function a simple aggregate? */ + int location; /* token location, or -1 if unknown */ +} WindowFunc; + +/* + * pseudo-column "ROWNUM" + */ +typedef struct Rownum { + Expr xpr; + Oid rownumcollid; /* OID of collation of result */ + int location; /* token location, or -1 if unknown */ +} Rownum; +/* ---------------- + * ArrayRef: describes an array subscripting operation + * + * An ArrayRef can describe fetching a single element from an array, + * fetching a subarray (array slice), storing a single element into + * an array, or storing a slice. The "store" cases work with an + * initial array value and a source value that is inserted into the + * appropriate part of the array; the result of the operation is an + * entire new modified array value. + * + * If reflowerindexpr = NIL, then we are fetching or storing a single array + * element at the subscripts given by refupperindexpr. Otherwise we are + * fetching or storing an array slice, that is a rectangular subarray + * with lower and upper bounds given by the index expressions. + * reflowerindexpr must be the same length as refupperindexpr when it + * is not NIL. + * + * Note: the result datatype is the element type when fetching a single + * element; but it is the array type when doing subarray fetch or either + * type of store. + * ---------------- + */ +typedef struct ArrayRef { + Expr xpr; + Oid refarraytype; /* type of the array proper */ + Oid refelemtype; /* type of the array elements */ + int32 reftypmod; /* typmod of the array (and elements too) */ + Oid refcollid; /* OID of collation, or InvalidOid if none */ + List* refupperindexpr; /* expressions that evaluate to upper array + * indexes */ + List* reflowerindexpr; /* expressions that evaluate to lower array + * indexes */ + Expr* refexpr; /* the expression that evaluates to an array + * value */ + Expr* refassgnexpr; /* expression for the source value, or NULL if + * fetch */ +} ArrayRef; + +/* + * CoercionContext - distinguishes the allowed set of type casts + * + * NB: ordering of the alternatives is significant; later (larger) values + * allow more casts than earlier ones. + */ +typedef enum CoercionContext { + COERCION_IMPLICIT, /* coercion in context of expression */ + COERCION_ASSIGNMENT, /* coercion in context of assignment */ + COERCION_EXPLICIT /* explicit cast operation */ +} CoercionContext; + +/* + * CoercionForm - information showing how to display a function-call node + * + * NB: equal() ignores CoercionForm fields, therefore this *must* not carry + * any semantically significant information. We need that behavior so that + * the planner will consider equivalent implicit and explicit casts to be + * equivalent. In cases where those actually behave differently, the coercion + * function's arguments will be different. + */ +typedef enum CoercionForm { + COERCE_EXPLICIT_CALL, /* display as a function call */ + COERCE_EXPLICIT_CAST, /* display as an explicit cast */ + COERCE_IMPLICIT_CAST, /* implicit cast, so hide it */ + COERCE_DONTCARE /* special case for planner */ +} CoercionForm; + +/* + * FuncExpr - expression node for a function call + */ +typedef struct FuncExpr { + Expr xpr; + Oid funcid; /* PG_PROC OID of the function */ + Oid funcresulttype; /* PG_TYPE OID of result value */ + bool funcretset; /* true if function returns set */ + /* true if variadic arguments have been combined into an array last argument */ + bool funcvariadic; + CoercionForm funcformat; /* how to display this function call */ + Oid funccollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + List* args; /* arguments to the function */ + int location; /* token location, or -1 if unknown */ + Oid refSynOid; /* PG_SYNONYM OID of the referenced synonym */ +} FuncExpr; + +/* + * NamedArgExpr - a named argument of a function + * + * This node type can only appear in the args list of a FuncCall or FuncExpr + * node. We support pure positional call notation (no named arguments), + * named notation (all arguments are named), and mixed notation (unnamed + * arguments followed by named ones). + * + * Parse analysis sets argnumber to the positional index of the argument, + * but doesn't rearrange the argument list. + * + * The planner will convert argument lists to pure positional notation + * during expression preprocessing, so execution never sees a NamedArgExpr. + */ +typedef struct NamedArgExpr { + Expr xpr; + Expr* arg; /* the argument expression */ + char* name; /* the name */ + int argnumber; /* argument's number in positional notation */ + int location; /* argument name location, or -1 if unknown */ +} NamedArgExpr; + +/* + * OpExpr - expression node for an operator invocation + * + * Semantically, this is essentially the same as a function call. + * + * Note that opfuncid is not necessarily filled in immediately on creation + * of the node. The planner makes sure it is valid before passing the node + * tree to the executor, but during parsing/planning opfuncid can be 0. + */ +typedef struct OpExpr { + Expr xpr; + Oid opno; /* PG_OPERATOR OID of the operator */ + Oid opfuncid; /* PG_PROC OID of underlying function */ + Oid opresulttype; /* PG_TYPE OID of result value */ + bool opretset; /* true if operator returns set */ + Oid opcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that operator should use */ + List* args; /* arguments to the operator (1 or 2) */ + int location; /* token location, or -1 if unknown */ +} OpExpr; + +/* + * DistinctExpr - expression node for "x IS DISTINCT FROM y" + * + * Except for the nodetag, this is represented identically to an OpExpr + * referencing the "=" operator for x and y. + * We use "=", not the more obvious "<>", because more datatypes have "=" + * than "<>". This means the executor must invert the operator result. + * Note that the operator function won't be called at all if either input + * is NULL, since then the result can be determined directly. + */ +typedef OpExpr DistinctExpr; + +/* + * NullIfExpr - a NULLIF expression + * + * Like DistinctExpr, this is represented the same as an OpExpr referencing + * the "=" operator for x and y. + */ +typedef OpExpr NullIfExpr; + +/* + * ScalarArrayOpExpr - expression node for "scalar op ANY/ALL (array)" + * + * The operator must yield boolean. It is applied to the left operand + * and each element of the righthand array, and the results are combined + * with OR or AND (for ANY or ALL respectively). The node representation + * is almost the same as for the underlying operator, but we need a useOr + * flag to remember whether it's ANY or ALL, and we don't have to store + * the result type (or the collation) because it must be boolean. + */ +typedef struct ScalarArrayOpExpr { + Expr xpr; + Oid opno; /* PG_OPERATOR OID of the operator */ + Oid opfuncid; /* PG_PROC OID of underlying function */ + bool useOr; /* true for ANY, false for ALL */ + Oid inputcollid; /* OID of collation that operator should use */ + List* args; /* the scalar and array operands */ + int location; /* token location, or -1 if unknown */ +} ScalarArrayOpExpr; + +/* + * BoolExpr - expression node for the basic Boolean operators AND, OR, NOT + * + * Notice the arguments are given as a List. For NOT, of course the list + * must always have exactly one element. For AND and OR, the executor can + * handle any number of arguments. The parser generally treats AND and OR + * as binary and so it typically only produces two-element lists, but the + * optimizer will flatten trees of AND and OR nodes to produce longer lists + * when possible. There are also a few special cases where more arguments + * can appear before optimization. + */ +typedef enum BoolExprType { AND_EXPR, OR_EXPR, NOT_EXPR } BoolExprType; + +typedef struct BoolExpr { + Expr xpr; + BoolExprType boolop; + List* args; /* arguments to this expression */ + int location; /* token location, or -1 if unknown */ +} BoolExpr; + +/* + * SubLink + * + * A SubLink represents a subselect appearing in an expression, and in some + * cases also the combining operator(s) just above it. The subLinkType + * indicates the form of the expression represented: + * EXISTS_SUBLINK EXISTS(SELECT ...) + * ALL_SUBLINK (lefthand) op ALL (SELECT ...) + * ANY_SUBLINK (lefthand) op ANY (SELECT ...) + * ROWCOMPARE_SUBLINK (lefthand) op (SELECT ...) + * EXPR_SUBLINK (SELECT with single targetlist item ...) + * ARRAY_SUBLINK ARRAY(SELECT with single targetlist item ...) + * CTE_SUBLINK WITH query (never actually part of an expression) + * For ALL, ANY, and ROWCOMPARE, the lefthand is a list of expressions of the + * same length as the subselect's targetlist. ROWCOMPARE will *always* have + * a list with more than one entry; if the subselect has just one target + * then the parser will create an EXPR_SUBLINK instead (and any operator + * above the subselect will be represented separately). Note that both + * ROWCOMPARE and EXPR require the subselect to deliver only one row. + * ALL, ANY, and ROWCOMPARE require the combining operators to deliver boolean + * results. ALL and ANY combine the per-row results using AND and OR + * semantics respectively. + * ARRAY requires just one target column, and creates an array of the target + * column's type using any number of rows resulting from the subselect. + * + * SubLink is classed as an Expr node, but it is not actually executable; + * it must be replaced in the expression tree by a SubPlan node during + * planning. + * + * NOTE: in the raw output of gram.y, testexpr contains just the raw form + * of the lefthand expression (if any), and operName is the String name of + * the combining operator. Also, subselect is a raw parsetree. During parse + * analysis, the parser transforms testexpr into a complete boolean expression + * that compares the lefthand value(s) to PARAM_SUBLINK nodes representing the + * output columns of the subselect. And subselect is transformed to a Query. + * This is the representation seen in saved rules and in the rewriter. + * + * In EXISTS, EXPR, and ARRAY SubLinks, testexpr and operName are unused and + * are always null. + * + * The CTE_SUBLINK case never occurs in actual SubLink nodes, but it is used + * in SubPlans generated for WITH subqueries. + */ +typedef enum SubLinkType { + EXISTS_SUBLINK, + ALL_SUBLINK, + ANY_SUBLINK, + ROWCOMPARE_SUBLINK, + EXPR_SUBLINK, + ARRAY_SUBLINK, + CTE_SUBLINK /* for SubPlans only */ +} SubLinkType; + +typedef struct SubLink { + Expr xpr; + SubLinkType subLinkType; /* see above */ + Node* testexpr; /* outer-query test for ALL/ANY/ROWCOMPARE */ + List* operName; /* originally specified operator name */ + Node* subselect; /* subselect as Query* or parsetree */ + int location; /* token location, or -1 if unknown */ +} SubLink; + +/* + * SubPlan - executable expression node for a subplan (sub-SELECT) + * + * The planner replaces SubLink nodes in expression trees with SubPlan + * nodes after it has finished planning the subquery. SubPlan references + * a sub-plantree stored in the subplans list of the toplevel PlannedStmt. + * (We avoid a direct link to make it easier to copy expression trees + * without causing multiple processing of the subplan.) + * + * In an ordinary subplan, testexpr points to an executable expression + * (OpExpr, an AND/OR tree of OpExprs, or RowCompareExpr) for the combining + * operator(s); the left-hand arguments are the original lefthand expressions, + * and the right-hand arguments are PARAM_EXEC Param nodes representing the + * outputs of the sub-select. (NOTE: runtime coercion functions may be + * inserted as well.) This is just the same expression tree as testexpr in + * the original SubLink node, but the PARAM_SUBLINK nodes are replaced by + * suitably numbered PARAM_EXEC nodes. + * + * If the sub-select becomes an initplan rather than a subplan, the executable + * expression is part of the outer plan's expression tree (and the SubPlan + * node itself is not, but rather is found in the outer plan's initPlan + * list). In this case testexpr is NULL to avoid duplication. + * + * The planner also derives lists of the values that need to be passed into + * and out of the subplan. Input values are represented as a list "args" of + * expressions to be evaluated in the outer-query context (currently these + * args are always just Vars, but in principle they could be any expression). + * The values are assigned to the global PARAM_EXEC params indexed by parParam + * (the parParam and args lists must have the same ordering). setParam is a + * list of the PARAM_EXEC params that are computed by the sub-select, if it + * is an initplan; they are listed in order by sub-select output column + * position. (parParam and setParam are integer Lists, not Bitmapsets, + * because their ordering is significant.) + * + * Also, the planner computes startup and per-call costs for use of the + * SubPlan. Note that these include the cost of the subquery proper, + * evaluation of the testexpr if any, and any hashtable management overhead. + */ +typedef struct SubPlan { + Expr xpr; + /* Fields copied from original SubLink: */ + SubLinkType subLinkType; /* see above */ + /* The combining operators, transformed to an executable expression: */ + Node* testexpr; /* OpExpr or RowCompareExpr expression tree */ + List* paramIds; /* IDs of Params embedded in the above */ + /* Identification of the Plan tree to use: */ + int plan_id; /* Index (from 1) in PlannedStmt.subplans */ + /* Identification of the SubPlan for EXPLAIN and debugging purposes: */ + char* plan_name; /* A name assigned during planning */ + /* Extra data useful for determining subplan's output type: */ + Oid firstColType; /* Type of first column of subplan result */ + int32 firstColTypmod; /* Typmod of first column of subplan result */ + Oid firstColCollation; /* Collation of first column of subplan result */ + /* Information about execution strategy: */ + /* TRUE to store subselect output in a hash table (implies we are doing "IN") */ + bool useHashTable; + /* TRUE if it's okay to return FALSE when the spec result is UNKNOWN; this allows much simpler handling of null values */ + bool unknownEqFalse; + /* Information for passing params into and out of the subselect: */ + /* setParam and parParam are lists of integers (param IDs) */ + List* setParam; /* initplan subqueries have to set these Params for parent plan */ + List* parParam; /* indices of input Params from parent plan */ + List* args; /* exprs to pass as parParam values */ + /* Estimated execution costs: */ + Cost startup_cost; /* one-time setup cost */ + Cost per_call_cost; /* cost for each subplan evaluation */ +} SubPlan; + +/* + * AlternativeSubPlan - expression node for a choice among SubPlans + * + * The subplans are given as a List so that the node definition need not + * change if there's ever more than two alternatives. For the moment, + * though, there are always exactly two; and the first one is the fast-start + * plan. + */ +typedef struct AlternativeSubPlan { + Expr xpr; + List* subplans; /* SubPlan(s) with equivalent results */ +} AlternativeSubPlan; + +/* ---------------- + * FieldSelect + * + * FieldSelect represents the operation of extracting one field from a tuple + * value. At runtime, the input expression is expected to yield a rowtype + * Datum. The specified field number is extracted and returned as a Datum. + * ---------------- + */ +typedef struct FieldSelect { + Expr xpr; + Expr* arg; /* input expression */ + AttrNumber fieldnum; /* attribute number of field to extract */ + Oid resulttype; /* type of the field (result type of this + * node) */ + int32 resulttypmod; /* output typmod (usually -1) */ + Oid resultcollid; /* OID of collation of the field */ +} FieldSelect; + +/* ---------------- + * FieldStore + * + * FieldStore represents the operation of modifying one field in a tuple + * value, yielding a new tuple value (the input is not touched!). Like + * the assign case of ArrayRef, this is used to implement UPDATE of a + * portion of a column. + * + * A single FieldStore can actually represent updates of several different + * fields. The parser only generates FieldStores with single-element lists, + * but the planner will collapse multiple updates of the same base column + * into one FieldStore. + * ---------------- + */ +typedef struct FieldStore { + Expr xpr; + Expr* arg; /* input tuple value */ + List* newvals; /* new value(s) for field(s) */ + List* fieldnums; /* integer list of field attnums */ + Oid resulttype; /* type of result (same as type of arg) */ + /* Like RowExpr, we deliberately omit a typmod and collation here */ +} FieldStore; + +/* ---------------- + * RelabelType + * + * RelabelType represents a "dummy" type coercion between two binary- + * compatible datatypes, such as reinterpreting the result of an OID + * expression as an int4. It is a no-op at runtime; we only need it + * to provide a place to store the correct type to be attributed to + * the expression result during type resolution. (We can't get away + * with just overwriting the type field of the input expression node, + * so we need a separate node to show the coercion's result type.) + * ---------------- + */ +typedef struct RelabelType { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type of coercion expression */ + int32 resulttypmod; /* output typmod (usually -1) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm relabelformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} RelabelType; + +/* ---------------- + * CoerceViaIO + * + * CoerceViaIO represents a type coercion between two types whose textual + * representations are compatible, implemented by invoking the source type's + * typoutput function then the destination type's typinput function. + * ---------------- + */ +typedef struct CoerceViaIO { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type of coercion */ + /* output typmod is not stored, but is presumed -1 */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm coerceformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} CoerceViaIO; + +/* ---------------- + * ArrayCoerceExpr + * + * ArrayCoerceExpr represents a type coercion from one array type to another, + * which is implemented by applying the indicated element-type coercion + * function to each element of the source array. If elemfuncid is InvalidOid + * then the element types are binary-compatible, but the coercion still + * requires some effort (we have to fix the element type ID stored in the + * array header). + * ---------------- + */ +typedef struct ArrayCoerceExpr { + Expr xpr; + Expr* arg; /* input expression (yields an array) */ + Oid elemfuncid; /* OID of element coercion function, or 0 */ + Oid resulttype; /* output type of coercion (an array type) */ + int32 resulttypmod; /* output typmod (also element typmod) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + bool isExplicit; /* conversion semantics flag to pass to func */ + CoercionForm coerceformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} ArrayCoerceExpr; + +/* ---------------- + * ConvertRowtypeExpr + * + * ConvertRowtypeExpr represents a type coercion from one composite type + * to another, where the source type is guaranteed to contain all the columns + * needed for the destination type plus possibly others; the columns need not + * be in the same positions, but are matched up by name. This is primarily + * used to convert a whole-row value of an inheritance child table into a + * valid whole-row value of its parent table's rowtype. + * ---------------- + */ +typedef struct ConvertRowtypeExpr { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* output type (always a composite type) */ + /* Like RowExpr, we deliberately omit a typmod and collation here */ + CoercionForm convertformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} ConvertRowtypeExpr; + +/* ---------- + * CollateExpr - COLLATE + * + * The planner replaces CollateExpr with RelabelType during expression + * preprocessing, so execution never sees a CollateExpr. + * ---------- + */ +typedef struct CollateExpr { + Expr xpr; + Expr* arg; /* input expression */ + Oid collOid; /* collation's OID */ + int location; /* token location, or -1 if unknown */ +} CollateExpr; + +/* ---------- + * CaseExpr - a CASE expression + * + * We support two distinct forms of CASE expression: + * CASE WHEN boolexpr THEN expr [ WHEN boolexpr THEN expr ... ] + * CASE testexpr WHEN compexpr THEN expr [ WHEN compexpr THEN expr ... ] + * These are distinguishable by the "arg" field being NULL in the first case + * and the testexpr in the second case. + * + * In the raw grammar output for the second form, the condition expressions + * of the WHEN clauses are just the comparison values. Parse analysis + * converts these to valid boolean expressions of the form + * CaseTestExpr '=' compexpr + * where the CaseTestExpr node is a placeholder that emits the correct + * value at runtime. This structure is used so that the testexpr need be + * evaluated only once. Note that after parse analysis, the condition + * expressions always yield boolean. + * + * Note: we can test whether a CaseExpr has been through parse analysis + * yet by checking whether casetype is InvalidOid or not. + * ---------- + */ +typedef struct CaseExpr { + Expr xpr; + Oid casetype; /* type of expression result */ + Oid casecollid; /* OID of collation, or InvalidOid if none */ + Expr* arg; /* implicit equality comparison argument */ + List* args; /* the arguments (list of WHEN clauses) */ + Expr* defresult; /* the default result (ELSE clause) */ + int location; /* token location, or -1 if unknown */ +} CaseExpr; + +/* + * CaseWhen - one arm of a CASE expression + */ +typedef struct CaseWhen { + Expr xpr; + Expr* expr; /* condition expression */ + Expr* result; /* substitution result */ + int location; /* token location, or -1 if unknown */ +} CaseWhen; + +/* + * Placeholder node for the test value to be processed by a CASE expression. + * This is effectively like a Param, but can be implemented more simply + * since we need only one replacement value at a time. + * + * We also use this in nested UPDATE expressions. + * See transformAssignmentIndirection(). + */ +typedef struct CaseTestExpr { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ +} CaseTestExpr; + +/* + * ArrayExpr - an ARRAY[] expression + * + * Note: if multidims is false, the constituent expressions all yield the + * scalar type identified by element_typeid. If multidims is true, the + * constituent expressions all yield arrays of element_typeid (ie, the same + * type as array_typeid); at runtime we must check for compatible subscripts. + */ +typedef struct ArrayExpr { + Expr xpr; + Oid array_typeid; /* type of expression result */ + Oid array_collid; /* OID of collation, or InvalidOid if none */ + Oid element_typeid; /* common type of array elements */ + List* elements; /* the array elements or sub-arrays */ + bool multidims; /* true if elements are sub-arrays */ + int location; /* token location, or -1 if unknown */ +} ArrayExpr; + +/* + * RowExpr - a ROW() expression + * + * Note: the list of fields must have a one-for-one correspondence with + * physical fields of the associated rowtype, although it is okay for it + * to be shorter than the rowtype. That is, the N'th list element must + * match up with the N'th physical field. When the N'th physical field + * is a dropped column (attisdropped) then the N'th list element can just + * be a NULL constant. (This case can only occur for named composite types, + * not RECORD types, since those are built from the RowExpr itself rather + * than vice versa.) It is important not to assume that length(args) is + * the same as the number of columns logically present in the rowtype. + * + * colnames provides field names in cases where the names can't easily be + * obtained otherwise. Names *must* be provided if row_typeid is RECORDOID. + * If row_typeid identifies a known composite type, colnames can be NIL to + * indicate the type's cataloged field names apply. Note that colnames can + * be non-NIL even for a composite type, and typically is when the RowExpr + * was created by expanding a whole-row Var. This is so that we can retain + * the column alias names of the RTE that the Var referenced (which would + * otherwise be very difficult to extract from the parsetree). Like the + * args list, colnames is one-for-one with physical fields of the rowtype. + */ +typedef struct RowExpr { + Expr xpr; + List* args; /* the fields */ + Oid row_typeid; /* RECORDOID or a composite type's ID */ + + /* + * Note: we deliberately do NOT store a typmod. Although a typmod will be + * associated with specific RECORD types at runtime, it will differ for + * different backends, and so cannot safely be stored in stored + * parsetrees. We must assume typmod -1 for a RowExpr node. + * + * We don't need to store a collation either. The result type is + * necessarily composite, and composite types never have a collation. + */ + CoercionForm row_format; /* how to display this node */ + List* colnames; /* list of String, or NIL */ + int location; /* token location, or -1 if unknown */ +} RowExpr; + +/* + * RowCompareExpr - row-wise comparison, such as (a, b) <= (1, 2) + * + * We support row comparison for any operator that can be determined to + * act like =, <>, <, <=, >, or >= (we determine this by looking for the + * operator in btree opfamilies). Note that the same operator name might + * map to a different operator for each pair of row elements, since the + * element datatypes can vary. + * + * A RowCompareExpr node is only generated for the < <= > >= cases; + * the = and <> cases are translated to simple AND or OR combinations + * of the pairwise comparisons. However, we include = and <> in the + * RowCompareType enum for the convenience of parser logic. + */ +typedef enum RowCompareType { + /* Values of this enum are chosen to match btree strategy numbers */ + ROWCOMPARE_LT = 1, /* BTLessStrategyNumber */ + ROWCOMPARE_LE = 2, /* BTLessEqualStrategyNumber */ + ROWCOMPARE_EQ = 3, /* BTEqualStrategyNumber */ + ROWCOMPARE_GE = 4, /* BTGreaterEqualStrategyNumber */ + ROWCOMPARE_GT = 5, /* BTGreaterStrategyNumber */ + ROWCOMPARE_NE = 6 /* no such btree strategy */ +} RowCompareType; + +typedef struct RowCompareExpr { + Expr xpr; + RowCompareType rctype; /* LT LE GE or GT, never EQ or NE */ + List* opnos; /* OID list of pairwise comparison ops */ + List* opfamilies; /* OID list of containing operator families */ + List* inputcollids; /* OID list of collations for comparisons */ + List* largs; /* the left-hand input arguments */ + List* rargs; /* the right-hand input arguments */ +} RowCompareExpr; + +/* + * CoalesceExpr - a COALESCE expression + */ +typedef struct CoalesceExpr { + Expr xpr; + Oid coalescetype; /* type of expression result */ + Oid coalescecollid; /* OID of collation, or InvalidOid if none */ + List* args; /* the arguments */ + int location; /* token location, or -1 if unknown */ + bool isnvl; /* is CoalesceExpr NVL ? */ +} CoalesceExpr; + +/* + * MinMaxExpr - a GREATEST or LEAST function + */ +typedef enum MinMaxOp { IS_GREATEST, IS_LEAST } MinMaxOp; + +typedef struct MinMaxExpr { + Expr xpr; + Oid minmaxtype; /* common type of arguments and result */ + Oid minmaxcollid; /* OID of collation of result */ + Oid inputcollid; /* OID of collation that function should use */ + MinMaxOp op; /* function to execute */ + List* args; /* the arguments */ + int location; /* token location, or -1 if unknown */ +} MinMaxExpr; + +/* + * XmlExpr - various SQL/XML functions requiring special grammar productions + * + * 'name' carries the "NAME foo" argument (already XML-escaped). + * 'named_args' and 'arg_names' represent an xml_attribute list. + * 'args' carries all other arguments. + * + * Note: result type/typmod/collation are not stored, but can be deduced + * from the XmlExprOp. The type/typmod fields are just used for display + * purposes, and are NOT necessarily the true result type of the node. + * (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.) + */ +typedef enum XmlExprOp { + IS_XMLCONCAT, /* XMLCONCAT(args) */ + IS_XMLELEMENT, /* XMLELEMENT(name, xml_attributes, args) */ + IS_XMLFOREST, /* XMLFOREST(xml_attributes) */ + IS_XMLPARSE, /* XMLPARSE(text, is_doc, preserve_ws) */ + IS_XMLPI, /* XMLPI(name [, args]) */ + IS_XMLROOT, /* XMLROOT(xml, version, standalone) */ + IS_XMLSERIALIZE, /* XMLSERIALIZE(is_document, xmlval) */ + IS_DOCUMENT /* xmlval IS DOCUMENT */ +} XmlExprOp; + +typedef enum { XMLOPTION_DOCUMENT, XMLOPTION_CONTENT } XmlOptionType; + +typedef struct XmlExpr { + Expr xpr; + XmlExprOp op; /* xml function ID */ + char* name; /* name in xml(NAME foo ...) syntaxes */ + List* named_args; /* non-XML expressions for xml_attributes */ + List* arg_names; /* parallel list of Value strings */ + List* args; /* list of expressions */ + XmlOptionType xmloption; /* DOCUMENT or CONTENT */ + Oid type; /* target type/typmod for XMLSERIALIZE */ + int32 typmod; + int location; /* token location, or -1 if unknown */ +} XmlExpr; + +/* ---------------- + * NullTest + * + * NullTest represents the operation of testing a value for NULLness. + * The appropriate test is performed and returned as a boolean Datum. + * + * NOTE: the semantics of this for rowtype inputs are noticeably different + * from the scalar case. We provide an "argisrow" flag to reflect that. + * ---------------- + */ +typedef enum NullTestType { IS_NULL, IS_NOT_NULL } NullTestType; + +typedef struct NullTest { + Expr xpr; + Expr* arg; /* input expression */ + NullTestType nulltesttype; /* IS NULL, IS NOT NULL */ + bool argisrow; /* T if input is of a composite type */ +} NullTest; + +/* + * BooleanTest + * + * BooleanTest represents the operation of determining whether a boolean + * is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations + * are supported. Note that a NULL input does *not* cause a NULL result. + * The appropriate test is performed and returned as a boolean Datum. + */ +typedef enum BoolTestType { IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN } BoolTestType; + +typedef struct BooleanTest { + Expr xpr; + Expr* arg; /* input expression */ + BoolTestType booltesttype; /* test type */ +} BooleanTest; + +/* HashFilter indicate that filter tuple using hash */ +typedef struct HashFilter { + Expr xpr; + List* arg; /* input expression */ + List* typeOids; /* type oid list of var for filter */ + List* nodeList; /* Node indices where data is located */ + // uint2 *bucketMap; +} HashFilter; + +/* + * EstSPNode + * + * For some expression, we can't estimate them though vars under them. Therefore, + * we should keep them and get the vars under them to get an overall estimation. + */ +typedef struct EstSPNode { + Expr xpr; + Node* expr; + List* varlist; +} EstSPNode; + +/* + * CoerceToDomain + * + * CoerceToDomain represents the operation of coercing a value to a domain + * type. At runtime (and not before) the precise set of constraints to be + * checked will be determined. If the value passes, it is returned as the + * result; if not, an error is raised. Note that this is equivalent to + * RelabelType in the scenario where no constraints are applied. + */ +typedef struct CoerceToDomain { + Expr xpr; + Expr* arg; /* input expression */ + Oid resulttype; /* domain type ID (result type) */ + int32 resulttypmod; /* output typmod (currently always -1) */ + Oid resultcollid; /* OID of collation, or InvalidOid if none */ + CoercionForm coercionformat; /* how to display this node */ + int location; /* token location, or -1 if unknown */ +} CoerceToDomain; + +/* + * Placeholder node for the value to be processed by a domain's check + * constraint. This is effectively like a Param, but can be implemented more + * simply since we need only one replacement value at a time. + * + * Note: the typeId/typeMod/collation will be set from the domain's base type, + * not the domain itself. This is because we shouldn't consider the value + * to be a member of the domain if we haven't yet checked its constraints. + */ +typedef struct CoerceToDomainValue { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ + int location; /* token location, or -1 if unknown */ +} CoerceToDomainValue; + +/* + * Placeholder node for a DEFAULT marker in an INSERT or UPDATE command. + * + * This is not an executable expression: it must be replaced by the actual + * column default expression during rewriting. But it is convenient to + * treat it as an expression node during parsing and rewriting. + */ +typedef struct SetToDefault { + Expr xpr; + Oid typeId; /* type for substituted value */ + int32 typeMod; /* typemod for substituted value */ + Oid collation; /* collation for the substituted value */ + int location; /* token location, or -1 if unknown */ +} SetToDefault; + +/* value expressions (changed for client_logic feature) */ +typedef struct ExprWithComma { + NodeTag type; + Expr *xpr; + int comma_before_loc; +} ExprWithComma; + +/* + * Node representing [WHERE] CURRENT OF cursor_name + * + * CURRENT OF is a bit like a Var, in that it carries the rangetable index + * of the target relation being constrained; this aids placing the expression + * correctly during planning. We can assume however that its "levelsup" is + * always zero, due to the syntactic constraints on where it can appear. + * + * The referenced cursor can be represented either as a hardwired string + * or as a reference to a run-time parameter of type REFCURSOR. The latter + * case is for the convenience of plpgsql. + */ +typedef struct CurrentOfExpr { + Expr xpr; + Index cvarno; /* RT index of target relation */ + char* cursor_name; /* name of referenced cursor, or NULL */ + int cursor_param; /* refcursor parameter number, or 0 */ +} CurrentOfExpr; + +/* -------------------- + * TargetEntry - + * a target entry (used in query target lists) + * + * Strictly speaking, a TargetEntry isn't an expression node (since it can't + * be evaluated by ExecEvalExpr). But we treat it as one anyway, since in + * very many places it's convenient to process a whole query targetlist as a + * single expression tree. + * + * In a SELECT's targetlist, resno should always be equal to the item's + * ordinal position (counting from 1). However, in an INSERT or UPDATE + * targetlist, resno represents the attribute number of the destination + * column for the item; so there may be missing or out-of-order resnos. + * It is even legal to have duplicated resnos; consider + * UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ... + * The two meanings come together in the executor, because the planner + * transforms INSERT/UPDATE tlists into a normalized form with exactly + * one entry for each column of the destination table. Before that's + * happened, however, it is risky to assume that resno == position. + * Generally get_tle_by_resno() should be used rather than list_nth() + * to fetch tlist entries by resno, and only in SELECT should you assume + * that resno is a unique identifier. + * + * resname is required to represent the correct column name in non-resjunk + * entries of top-level SELECT targetlists, since it will be used as the + * column title sent to the frontend. In most other contexts it is only + * a debugging aid, and may be wrong or even NULL. (In particular, it may + * be wrong in a tlist from a stored rule, if the referenced column has been + * renamed by ALTER TABLE since the rule was made. Also, the planner tends + * to store NULL rather than look up a valid name for tlist entries in + * non-toplevel plan nodes.) In resjunk entries, resname should be either + * a specific system-generated name (such as "ctid") or NULL; anything else + * risks confusing ExecGetJunkAttribute! + * + * ressortgroupref is used in the representation of ORDER BY, GROUP BY, and + * DISTINCT items. Targetlist entries with ressortgroupref=0 are not + * sort/group items. If ressortgroupref>0, then this item is an ORDER BY, + * GROUP BY, and/or DISTINCT target value. No two entries in a targetlist + * may have the same nonzero ressortgroupref --- but there is no particular + * meaning to the nonzero values, except as tags. (For example, one must + * not assume that lower ressortgroupref means a more significant sort key.) + * The order of the associated SortGroupClause lists determine the semantics. + * + * resorigtbl/resorigcol identify the source of the column, if it is a + * simple reference to a column of a base table (or view). If it is not + * a simple reference, these fields are zeroes. + * + * If resjunk is true then the column is a working column (such as a sort key) + * that should be removed from the final output of the query. Resjunk columns + * must have resnos that cannot duplicate any regular column's resno. Also + * note that there are places that assume resjunk columns come after non-junk + * columns. + * -------------------- + */ +typedef struct TargetEntry { + Expr xpr; + Expr* expr; /* expression to evaluate */ + AttrNumber resno; /* attribute number (see notes above) */ + char* resname; /* name of the column (could be NULL) */ + Index ressortgroupref; /* nonzero if referenced by a sort/group + * clause */ + Oid resorigtbl; /* OID of column's source table */ + AttrNumber resorigcol; /* column's number in source table */ + bool resjunk; /* set to true to eliminate the attribute from + * final target list */ +} TargetEntry; + +/* ---------------------------------------------------------------- + * node types for join trees + * + * The leaves of a join tree structure are RangeTblRef nodes. Above + * these, JoinExpr nodes can appear to denote a specific kind of join + * or qualified join. Also, FromExpr nodes can appear to denote an + * ordinary cross-product join ("FROM foo, bar, baz WHERE ..."). + * FromExpr is like a JoinExpr of jointype JOIN_INNER, except that it + * may have any number of child nodes, not just two. + * + * NOTE: the top level of a Query's jointree is always a FromExpr. + * Even if the jointree contains no rels, there will be a FromExpr. + * + * NOTE: the qualification expressions present in JoinExpr nodes are + * *in addition to* the query's main WHERE clause, which appears as the + * qual of the top-level FromExpr. The reason for associating quals with + * specific nodes in the jointree is that the position of a qual is critical + * when outer joins are present. (If we enforce a qual too soon or too late, + * that may cause the outer join to produce the wrong set of NULL-extended + * rows.) If all joins are inner joins then all the qual positions are + * semantically interchangeable. + * + * NOTE: in the raw output of gram.y, a join tree contains RangeVar, + * RangeSubselect, and RangeFunction nodes, which are all replaced by + * RangeTblRef nodes during the parse analysis phase. Also, the top-level + * FromExpr is added during parse analysis; the grammar regards FROM and + * WHERE as separate. + * ---------------------------------------------------------------- + */ + +/* + * RangeTblRef - reference to an entry in the query's rangetable + * + * We could use direct pointers to the RT entries and skip having these + * nodes, but multiple pointers to the same node in a querytree cause + * lots of headaches, so it seems better to store an index into the RT. + */ +typedef struct RangeTblRef { + NodeTag type; + int rtindex; +} RangeTblRef; + +/* ---------- + * JoinExpr - for SQL JOIN expressions + * + * isNatural, usingClause, and quals are interdependent. The user can write + * only one of NATURAL, USING(), or ON() (this is enforced by the grammar). + * If he writes NATURAL then parse analysis generates the equivalent USING() + * list, and from that fills in "quals" with the right equality comparisons. + * If he writes USING() then "quals" is filled with equality comparisons. + * If he writes ON() then only "quals" is set. Note that NATURAL/USING + * are not equivalent to ON() since they also affect the output column list. + * + * alias is an Alias node representing the AS alias-clause attached to the + * join expression, or NULL if no clause. NB: presence or absence of the + * alias has a critical impact on semantics, because a join with an alias + * restricts visibility of the tables/columns inside it. + * + * During parse analysis, an RTE is created for the Join, and its index + * is filled into rtindex. This RTE is present mainly so that Vars can + * be created that refer to the outputs of the join. The planner sometimes + * generates JoinExprs internally; these can have rtindex = 0 if there are + * no join alias variables referencing such joins. + * ---------- + */ +typedef struct JoinExpr { + NodeTag type; + JoinType jointype; /* type of join */ + bool isNatural; /* Natural join? Will need to shape table */ + Node* larg; /* left subtree */ + Node* rarg; /* right subtree */ + List* usingClause; /* USING clause, if any (list of String) */ + Node* quals; /* qualifiers on join, if any */ + Alias* alias; /* user-written alias clause, if any */ + int rtindex; /* RT index assigned for join, or 0 */ +} JoinExpr; + +/* ---------- + * FromExpr - represents a FROM ... WHERE ... construct + * + * This is both more flexible than a JoinExpr (it can have any number of + * children, including zero) and less so --- we don't need to deal with + * aliases and so on. The output column set is implicitly just the union + * of the outputs of the children. + * ---------- + */ +typedef struct FromExpr { + NodeTag type; + List* fromlist; /* List of join subtrees */ + Node* quals; /* qualifiers on join, if any */ +} FromExpr; + +#ifdef PGXC +/* ---------- + * DistributionType - how to distribute the data + * + * ---------- + */ +typedef enum DistributionType { + DISTTYPE_REPLICATION, /* Replicated */ + DISTTYPE_HASH, /* Hash partitioned */ + DISTTYPE_ROUNDROBIN, /* Round Robin */ + DISTTYPE_MODULO, /* Modulo partitioned */ + DISTTYPE_HIDETAG, /* Use a hidden column as distribute column */ + DISTTYPE_LIST, /* List */ + DISTTYPE_RANGE /* Range */ +} DistributionType; + +typedef struct ListSliceDefState { + NodeTag type; + char* name; + List* boundaries; /* list of boundary(multi-values) */ + char* datanode_name; +} ListSliceDefState; + +typedef struct DistState { + NodeTag type; + /* + * 'r' range slice + * 'l' list slice + */ + char strategy; + /* list of slice definition, like: + * ListSliceDefState or RangePartitionDefState or RangePartitionStartEndDefState + */ + List* sliceList; + char* refTableName; +} DistState; + +/* ---------- + * DistributeBy - represents a DISTRIBUTE BY clause in a CREATE TABLE statement + * + * ---------- + */ +typedef struct DistributeBy { + NodeTag type; + DistributionType disttype; /* Distribution type */ + List* colname; /* Distribution column name */ + DistState* distState; /* Slice Definitions */ + Oid referenceoid; /* table oid that slice references, InvalidOid if none */ +} DistributeBy; + +/* ---------- + * SubClusterType - type of subcluster used + * + * ---------- + */ +typedef enum PGXCSubClusterType { SUBCLUSTER_NONE, SUBCLUSTER_NODE, SUBCLUSTER_GROUP } PGXCSubClusterType; + +/* ---------- + * PGXCSubCluster - Subcluster on which a table can be created + * + * ---------- + */ +typedef struct PGXCSubCluster { + NodeTag type; + PGXCSubClusterType clustertype; /* Subcluster type */ + List* members; /* List of nodes or groups */ +} PGXCSubCluster; +#endif + +typedef struct { + NodeTag type; + Oid relid; + AttrNumber attno; + char* relname; + char* attname; + + bool indexcol; + List* indexoids; + bool indexpath; +} IndexVar; + +typedef struct UpsertExpr { + NodeTag type; + UpsertAction upsertAction; /* DO NOTHING or UPDATE? */ + + /* DUPLICATE KEY UPDATE */ + List* updateTlist; /* List of UPDATE TargetEntrys */ + List* exclRelTlist; /* tlist of the 'EXCLUDED' pseudo relation */ + int exclRelIndex; /* RT index of 'EXCLUDED' relation */ +} UpsertExpr; + +#endif /* PRIMNODES_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/print.h postgresql-hll-2.14/include/nodes/print.h --- postgresql-hll-2.14_old/include/nodes/print.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/print.h 2020-12-12 17:06:43.323349019 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * print.h + * definitions for nodes/print.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/print.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRINT_H +#define PRINT_H + +#include "executor/tuptable.h" + +#define nodeDisplay(x) pprint(x) + +extern void print(const void* obj); +extern void pprint(const void* obj); +extern void elog_node_display(int lev, const char* title, const void* obj, bool pretty); +extern char* format_node_dump(const char* dump); +extern char* pretty_format_node_dump(const char* dump); +extern void print_rt(const List* rtable); +extern void print_expr(const Node* expr, const List* rtable); +extern void print_pathkeys(const List* pathkeys, const List* rtable); +extern void print_tl(const List* tlist, const List* rtable); +extern void print_slot(TupleTableSlot* slot); +extern char* ExprToString(const Node* expr, const List* rtable); + +#endif /* PRINT_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/readfuncs.h postgresql-hll-2.14/include/nodes/readfuncs.h --- postgresql-hll-2.14_old/include/nodes/readfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/readfuncs.h 2020-12-12 17:06:43.323349019 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * readfuncs.h + * header file for read.c and readfuncs.c. These functions are internal + * to the stringToNode interface and should not be used by anyone else. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/readfuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef READFUNCS_H +#define READFUNCS_H + +#include "nodes/nodes.h" + +/* + * prototypes for functions in read.c (the lisp token parser) + */ +extern char* pg_strtok(int* length, bool chg_org_strok = true); +extern char* debackslash(const char* token, int length); +extern void* nodeRead(char* token, int tok_len); + +/* + * prototypes for functions in readfuncs.c + */ +extern Node* parseNodeString(void); + +extern void* stringToNode_skip_extern_fields(char* str); + +#endif /* READFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/relation.h postgresql-hll-2.14/include/nodes/relation.h --- postgresql-hll-2.14_old/include/nodes/relation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/relation.h 2020-12-12 17:06:43.324349032 +0800 @@ -0,0 +1,1970 @@ +/* ------------------------------------------------------------------------- + * + * relation.h + * Definitions for planner's internal data structures. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/relation.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELATION_H +#define RELATION_H + +#include "access/sdir.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "storage/block.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" + +#include "optimizer/bucketinfo.h" + +/* + * When looking for a "cheapest path", this enum specifies whether we want + * cheapest startup cost or cheapest total cost. + */ +typedef enum CostSelector { STARTUP_COST, TOTAL_COST } CostSelector; + +/* + * The cost estimate produced by cost_qual_eval() includes both a one-time + * (startup) cost, and a per-tuple cost. + */ +typedef struct QualCost { + Cost startup; /* one-time cost */ + Cost per_tuple; /* per-evaluation cost */ +} QualCost; + +/* + * Costing aggregate function execution requires these statistics about + * the aggregates to be executed by a given Agg node. Note that transCost + * includes the execution costs of the aggregates' input expressions. + */ +typedef struct AggClauseCosts { + int numAggs; /* total number of aggregate functions */ + int numOrderedAggs; /* number that use ORDER BY */ + List* exprAggs; /* expression that use DISTINCT */ + QualCost transCost; /* total per-input-row execution costs */ + Cost finalCost; /* total costs of agg final functions */ + Size transitionSpace; /* space for pass-by-ref transition data */ + bool hasdctDnAggs; /* has agg-once functions in distinct expr */ + bool hasDnAggs; /* has agg-once functions not in distinct expr */ + bool unhashable; /* if distinct node is not hashable */ + bool hasPolymorphicType; /* if aggregate expressions have polymorphic pseudotype */ + int aggWidth; /* total width of agg function */ +} AggClauseCosts; + +/* + * For global path optimization, we should keep all paths with interesting distribute + * keys. There are two kinds of such keys: super set (taking effect for intermediate + * relation and before agg) and exact match (taking effect for intermediate resultset + * with all referenced tables (no group by or subset of group by), or final result set + * after agg). Super set key is used for aggregation redistribution optimization, and + * matching key is used for insert/ delete/ update redistribution optimization. + * Also, we should keep corresponding positions for each interesting key, in order to + * redistribute in positions in sub level, to avoid redistribute in current level + */ +typedef struct ItstDisKey { + List* superset_keys; /* list of superset keys list, several members possible */ + List* matching_keys; /* list of exact matching keys, */ +} ItstDisKey; + +typedef struct { + int bloomfilter_index; /* Current bloomfilter Num */ + bool add_index; /* If bloomfilter_index add 1. To eqClass equal member, it's filter index is alike. */ +} bloomfilter_context; + +typedef struct PlannerContext { + MemoryContext plannerMemContext; + MemoryContext dataSkewMemContext; +} PlannerContext; + +/* + * For query mem-based optimization, we should record current memory usage, + * memory usage with no disk, with maximum disk possible (no severe influence + * to operator. We allow hashjoin and hashagg to use at most 32 disk files, and + * sort 256 files. For materialize, we don't want it to spill to disk unless it exceeds + * memory allowed), and the performance degression ratio between them. + * (Assume it's linear) + */ +typedef struct OpMemInfo { + double opMem; /* u_sess->opt_cxt.op_work_mem in path phase */ + double minMem; /* ideal memory usage with maximum disk */ + double maxMem; /* ideal memory usage without disk */ + double regressCost; /* performance degression ratio between min and max Mem */ +} OpMemInfo; + +#define HASH_MAX_DISK_SIZE 32 +#define SORT_MAX_DISK_SIZE 256 +#define DFS_MIN_MEM_SIZE 128 * 1024 /* 128MB, the unit is kb */ +#define PARTITION_MAX_SIZE (2 * 1024 * 1024L) /* 2GB, the unit is kb */ +#define MAX_BATCH_ROWS 60000 /* default max number of max batch rows, the value can be changed. */ +#define PARTIAL_CLUSTER_ROWS 4200000 /* default vaule for max partialClusterRows, the value can be changed. */ + +/* the min memory for sort is 16MB, the unit is kb. Don't sort in memory when we don't have engough memory. */ +#define SORT_MIM_MEM 16 * 1024 +#define DFSSCAN_MIN_MEM 12 * 1024 /* the min memory for dfsscan is 12MB, the unit is kb. */ +#define MEM_KB 1024L /* 1024kb for caculating mem info */ + +/* PSORT_SPREAD_MAXMEM_RATIO can increase 20% for partition table's one part on extended limit. */ +#define PSORT_SPREAD_MAXMEM_RATIO 1.2 + +/* ---------- + * PlannerGlobal + * Global information for planning/optimization + * + * PlannerGlobal holds state for an entire planner invocation; this state + * is shared across all levels of sub-Queries that exist in the command being + * planned. + * ---------- + */ +typedef struct PlannerGlobal { + NodeTag type; + + ParamListInfo boundParams; /* Param values provided to planner() */ + + List* paramlist; /* unused, will be removed in 9.3 */ + + List* subplans; /* Plans for SubPlan nodes */ + + List* subroots; /* PlannerInfos for SubPlan nodes */ + + Bitmapset* rewindPlanIDs; /* indices of subplans that require REWIND */ + + List* finalrtable; /* "flat" rangetable for executor */ + + List* finalrowmarks; /* "flat" list of PlanRowMarks */ + + List* resultRelations; /* "flat" list of integer RT indexes */ + + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the plan depends on */ + + List* invalItems; /* other dependencies, as PlanInvalItems */ + + Index lastPHId; /* highest PlaceHolderVar ID assigned */ + + Index lastRowMarkId; /* highest PlanRowMark ID assigned */ + + bool transientPlan; /* redo plan when TransactionXmin changes? */ + + bool dependsOnRole; /* is plan specific to current role? */ + + /* Added post-release, will be in a saner place in 9.3: */ + int nParamExec; /* number of PARAM_EXEC Params used */ + bool insideRecursion; /* For sql on hdfs, internal flag. */ + + bloomfilter_context bloomfilter; /* Bloom filter context. */ + bool vectorized; /* whether vector plan be generated, used in join planning phase */ + int minopmem; /* min work mem if query mem is used for planning */ + + int estiopmem; /* estimation of operator mem, used to revise u_sess->opt_cxt.op_work_mem */ + + Cost IOTotalCost; /* total cost */ + + List* hint_warning; /* hint warning list */ + + PlannerContext* plannerContext; + + /* There is a counter attempt to get name for sublinks */ + int sublink_counter; +} PlannerGlobal; + +/* macro for fetching the Plan associated with a SubPlan node */ +#define planner_subplan_get_plan(root, subplan) ((Plan*)list_nth((root)->glob->subplans, (subplan)->plan_id - 1)) + +/* we have to distinguish the different type of subquery */ +#define SUBQUERY_NORMAL 0x1 +#define SUBQUERY_PARAM 0x2 +#define SUBQUERY_RESULT 0x3 +#define SUBQUERY_TYPE_BITMAP 0x3 +#define SUBQUERY_SUBLINK 0x4 + +#define SUBQUERY_IS_NORMAL(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_NORMAL)) +#define SUBQUERY_IS_PARAM(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_PARAM)) +#define SUBQUERY_IS_RESULT(pr) (((pr->subquery_type & SUBQUERY_TYPE_BITMAP) == SUBQUERY_RESULT)) + +#define SUBQUERY_IS_SUBLINK(pr) (((pr->subquery_type & SUBQUERY_SUBLINK) == SUBQUERY_SUBLINK)) + +#define SUBQUERY_PREDPUSH(pr) ((SUBQUERY_IS_RESULT(pr)) || (SUBQUERY_IS_PARAM(pr))) + +/* ---------- + * PlannerInfo + * Per-query information for planning/optimization + * + * This struct is conventionally called "root" in all the planner routines. + * It holds links to all of the planner's working state, in addition to the + * original Query. Note that at present the planner extensively modifies + * the passed-in Query data structure; someday that should stop. + * ---------- + */ +typedef struct PlannerInfo { + NodeTag type; + + Query* parse; /* the Query being planned */ + + PlannerGlobal* glob; /* global info for current planner run */ + + Index query_level; /* 1 at the outermost Query */ + + struct PlannerInfo* parent_root; /* NULL at outermost Query */ + + /* + * simple_rel_array holds pointers to "base rels" and "other rels" (see + * comments for RelOptInfo for more info). It is indexed by rangetable + * index (so entry 0 is always wasted). Entries can be NULL when an RTE + * does not correspond to a base relation, such as a join RTE or an + * unreferenced view RTE; or if the RelOptInfo hasn't been made yet. + */ + struct RelOptInfo** simple_rel_array; /* All 1-rel RelOptInfos */ + int simple_rel_array_size; /* allocated size of array */ + + /* + * List of changed var that mutated during cost-based rewrite optimization, the + * element in the list is "struct RewriteVarMapping", for example: + * - inlist2join + * - pushjoin2union (will implemented) + * _ ... + * + */ + List* var_mappings; + Relids var_mapping_rels; /* all the relations that related to inlist2join */ + + /* + * simple_rte_array is the same length as simple_rel_array and holds + * pointers to the associated rangetable entries. This lets us avoid + * rt_fetch(), which can be a bit slow once large inheritance sets have + * been expanded. + */ + RangeTblEntry** simple_rte_array; /* rangetable as an array */ + + /* + * all_baserels is a Relids set of all base relids (but not "other" + * relids) in the query; that is, the Relids identifier of the final join + * we need to form. + */ + Relids all_baserels; + + /* + * join_rel_list is a list of all join-relation RelOptInfos we have + * considered in this planning run. For small problems we just scan the + * list to do lookups, but when there are many join relations we build a + * hash table for faster lookups. The hash table is present and valid + * when join_rel_hash is not NULL. Note that we still maintain the list + * even when using the hash table for lookups; this simplifies life for + * GEQO. + */ + List* join_rel_list; /* list of join-relation RelOptInfos */ + struct HTAB* join_rel_hash; /* optional hashtable for join relations */ + + /* + * When doing a dynamic-programming-style join search, join_rel_level[k] + * is a list of all join-relation RelOptInfos of level k, and + * join_cur_level is the current level. New join-relation RelOptInfos are + * automatically added to the join_rel_level[join_cur_level] list. + * join_rel_level is NULL if not in use. + */ + List** join_rel_level; /* lists of join-relation RelOptInfos */ + int join_cur_level; /* index of list being extended */ + + List* init_plans; /* init SubPlans for query */ + + List* cte_plan_ids; /* per-CTE-item list of subplan IDs */ + + List* eq_classes; /* list of active EquivalenceClasses */ + + List* canon_pathkeys; /* list of "canonical" PathKeys */ + + List* left_join_clauses; /* list of RestrictInfos for + * mergejoinable outer join clauses + * w/nonnullable var on left */ + + List* right_join_clauses; /* list of RestrictInfos for + * mergejoinable outer join clauses + * w/nonnullable var on right */ + + List* full_join_clauses; /* list of RestrictInfos for + * mergejoinable full join clauses */ + + List* join_info_list; /* list of SpecialJoinInfos */ + + List* lateral_info_list; /* list of LateralJoinInfos */ + + List* append_rel_list; /* list of AppendRelInfos */ + + List* rowMarks; /* list of PlanRowMarks */ + + List* placeholder_list; /* list of PlaceHolderInfos */ + + List* query_pathkeys; /* desired pathkeys for query_planner(), and + * actual pathkeys afterwards */ + + List* group_pathkeys; /* groupClause pathkeys, if any */ + List* window_pathkeys; /* pathkeys of bottom window, if any */ + List* distinct_pathkeys; /* distinctClause pathkeys, if any */ + List* sort_pathkeys; /* sortClause pathkeys, if any */ + + List* minmax_aggs; /* List of MinMaxAggInfos */ + + List* initial_rels; /* RelOptInfos we are now trying to join */ + + MemoryContext planner_cxt; /* context holding PlannerInfo */ + + double total_table_pages; /* # of pages in all tables of query */ + + double tuple_fraction; /* tuple_fraction passed to query_planner */ + double limit_tuples; /* limit_tuples passed to query_planner */ + + bool hasInheritedTarget; /* true if parse->resultRelation is an + * inheritance child rel */ + bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */ + bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */ + bool hasHavingQual; /* true if havingQual was non-null */ + bool hasPseudoConstantQuals; /* true if any RestrictInfo has + * pseudoconstant = true */ + bool hasRecursion; /* true if planning a recursive WITH item */ + + /* Note: qualSecurityLevel is zero if there are no securityQuals */ + Index qualSecurityLevel; /* minimum security_level for quals */ + +#ifdef PGXC + /* This field is used only when RemoteScan nodes are involved */ + int rs_alias_index; /* used to build the alias reference */ + + /* + * In Postgres-XC Coordinators are supposed to skip the handling of + * row marks of type ROW_MARK_EXCLUSIVE & ROW_MARK_SHARE. + * In order to do that we simply remove such type + * of row marks from the list rowMarks. Instead they are saved + * in xc_rowMarks list that is then handeled to add + * FOR UPDATE/SHARE in the remote query + */ + List* xc_rowMarks; /* list of PlanRowMarks of type ROW_MARK_EXCLUSIVE & ROW_MARK_SHARE */ +#endif + + /* These fields are used only when hasRecursion is true: */ + int wt_param_id; /* PARAM_EXEC ID for the work table */ + struct Plan* non_recursive_plan; /* plan for non-recursive term */ + + /* These fields are workspace for createplan.c */ + Relids curOuterRels; /* outer rels above current node */ + List* curOuterParams; /* not-yet-assigned NestLoopParams */ + + Index curIteratorParamIndex; + bool isPartIteratorPlanning; + int curItrs; + List* subqueryRestrictInfo; /* Subquery RestrictInfo, which only be used in wondows agg. */ + + /* optional private data for join_search_hook, e.g., GEQO */ + void* join_search_private; + + /* Added post-release, will be in a saner place in 9.3: */ + List* plan_params; /* list of PlannerParamItems, see below */ + + /* For count_distinct, save null info for group by clause */ + List* join_null_info; + /* for GroupingFunc fixup in setrefs */ + AttrNumber* grouping_map; + + /* If current query level is correlated with upper level */ + bool is_correlated; + + /* data redistribution for DFS table. + * dataDestRelIndex is index into the range table. This variable + * will take effect on data redistribution state. + * The effective value must be greater than 0. + */ + Index dataDestRelIndex; + + /* interesting keys of current query level */ + ItstDisKey dis_keys; + + /* + * indicate if the subquery planning root (PlannerInfo) is under or rooted from + * recursive-cte planning. + */ + bool is_under_recursive_cte; + + /* + * indicate if the subquery planning root (PlannerInfo) is under recursive-cte's + * recursive branch + */ + bool is_under_recursive_tree; + bool has_recursive_correlated_rte; /* true if any RTE correlated with recursive cte */ + + int subquery_type; + Bitmapset *param_upper; + + bool hasRownumQual; +} PlannerInfo; + +/* + * In places where it's known that simple_rte_array[] must have been prepared + * already, we just index into it to fetch RTEs. In code that might be + * executed before or after entering query_planner(), use this macro. + */ +#define planner_rt_fetch(rti, root) \ + ((root)->simple_rte_array ? (root)->simple_rte_array[rti] : rt_fetch(rti, (root)->parse->rtable)) + +/* ---------- + * RelOptInfo + * Per-relation information for planning/optimization + * + * For planning purposes, a "base rel" is either a plain relation (a table) + * or the output of a sub-SELECT or function that appears in the range table. + * In either case it is uniquely identified by an RT index. A "joinrel" + * is the joining of two or more base rels. A joinrel is identified by + * the set of RT indexes for its component baserels. We create RelOptInfo + * nodes for each baserel and joinrel, and store them in the PlannerInfo's + * simple_rel_array and join_rel_list respectively. + * + * Note that there is only one joinrel for any given set of component + * baserels, no matter what order we assemble them in; so an unordered + * set is the right datatype to identify it with. + * + * We also have "other rels", which are like base rels in that they refer to + * single RT indexes; but they are not part of the join tree, and are given + * a different RelOptKind to identify them. Lastly, there is a RelOptKind + * for "dead" relations, which are base rels that we have proven we don't + * need to join after all. + * + * Currently the only kind of otherrels are those made for member relations + * of an "append relation", that is an inheritance set or UNION ALL subquery. + * An append relation has a parent RTE that is a base rel, which represents + * the entire append relation. The member RTEs are otherrels. The parent + * is present in the query join tree but the members are not. The member + * RTEs and otherrels are used to plan the scans of the individual tables or + * subqueries of the append set; then the parent baserel is given Append + * and/or MergeAppend paths comprising the best paths for the individual + * member rels. (See comments for AppendRelInfo for more information.) + * + * At one time we also made otherrels to represent join RTEs, for use in + * handling join alias Vars. Currently this is not needed because all join + * alias Vars are expanded to non-aliased form during preprocess_expression. + * + * Parts of this data structure are specific to various scan and join + * mechanisms. It didn't seem worth creating new node types for them. + * + * relids - Set of base-relation identifiers; it is a base relation + * if there is just one, a join relation if more than one + * rows - estimated number of tuples in the relation after restriction + * clauses have been applied (ie, output rows of a plan for it) + * width - avg. number of bytes per tuple in the relation after the + * appropriate projections have been done (ie, output width) + * reltargetlist - List of Var and PlaceHolderVar nodes for the values + * we need to output from this relation. + * List is in no particular order, but all rels of an + * appendrel set must use corresponding orders. + * NOTE: in a child relation, may contain RowExpr or + * ConvertRowtypeExpr representing a whole-row Var. + * pathlist - List of Path nodes, one for each potentially useful + * method of generating the relation + * ppilist - ParamPathInfo nodes for parameterized Paths, if any + * cheapest_startup_path - the pathlist member with lowest startup cost + * (regardless of its ordering; but must be + * unparameterized) + * cheapest_total_path - the pathlist member with lowest total cost + * (regardless of its ordering; but must be + * unparameterized) + * cheapest_unique_path - for caching cheapest path to produce unique + * (no duplicates) output from relation + * cheapest_parameterized_paths - paths with cheapest total costs for + * their parameterizations; always includes + * cheapest_total_path + * + * If the relation is a base relation it will have these fields set: + * + * relid - RTE index (this is redundant with the relids field, but + * is provided for convenience of access) + * rtekind - distinguishes plain relation, subquery, or function RTE + * min_attr, max_attr - range of valid AttrNumbers for rel + * attr_needed - array of bitmapsets indicating the highest joinrel + * in which each attribute is needed; if bit 0 is set then + * the attribute is needed as part of final targetlist + * attr_widths - cache space for per-attribute width estimates; + * zero means not computed yet + * indexlist - list of IndexOptInfo nodes for relation's indexes + * (always NIL if it's not a table) + * pages - number of disk pages in relation (zero if not a table) + * tuples - number of tuples in relation (not considering restrictions) + * allvisfrac - fraction of disk pages that are marked all-visible + * subplan - plan for subquery (NULL if it's not a subquery) + * subroot - PlannerInfo for subquery (NULL if it's not a subquery) + * fdwroutine - function hooks for FDW, if foreign table (else NULL) + * fdw_private - private state for FDW, if foreign table (else NULL) + * + * Note: for a subquery, tuples, subplan, subroot are not set immediately + * upon creation of the RelOptInfo object; they are filled in when + * set_subquery_pathlist processes the object. Likewise, fdwroutine + * and fdw_private are filled during initial path creation. + * + * For otherrels that are appendrel members, these fields are filled + * in just as for a baserel. + * + * The presence of the remaining fields depends on the restrictions + * and joins that the relation participates in: + * + * baserestrictinfo - List of RestrictInfo nodes, containing info about + * each non-join qualification clause in which this relation + * participates (only used for base rels) + * baserestrictcost - Estimated cost of evaluating the baserestrictinfo + * clauses at a single tuple (only used for base rels) + * baserestrict_min_security - Smallest security_level found among + * clauses in baserestrictinfo + * joininfo - List of RestrictInfo nodes, containing info about each + * join clause in which this relation participates (but + * note this excludes clauses that might be derivable from + * EquivalenceClasses) + * has_eclass_joins - flag that EquivalenceClass joins are possible + * + * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for + * base rels, because for a join rel the set of clauses that are treated as + * restrict clauses varies depending on which sub-relations we choose to join. + * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be + * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but + * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2} + * and should not be processed again at the level of {1 2 3}.) Therefore, + * the restrictinfo list in the join case appears in individual JoinPaths + * (field joinrestrictinfo), not in the parent relation. But it's OK for + * the RelOptInfo to store the joininfo list, because that is the same + * for a given rel no matter how we form it. + * + * We store baserestrictcost in the RelOptInfo (for base relations) because + * we know we will need it at least once (to price the sequential scan) + * and may need it multiple times to price index scans. + * ---------- + */ +typedef enum RelOptKind { RELOPT_BASEREL, RELOPT_JOINREL, RELOPT_OTHER_MEMBER_REL, RELOPT_DEADREL } RelOptKind; + +typedef enum PartitionFlag { PARTITION_NONE, PARTITION_REQURIED, PARTITION_ANCESOR } PartitionFlag; + +/* + * Is the given relation a simple relation i.e a base or "other" member + * relation? + */ +#define IS_SIMPLE_REL(rel) ((rel)->reloptkind == RELOPT_BASEREL || (rel)->reloptkind == RELOPT_OTHER_MEMBER_REL) + +/* Is the given relation a join relation? */ +#define IS_JOIN_REL(rel) ((rel)->reloptkind == RELOPT_JOINREL) + +typedef struct RelOptInfo { + NodeTag type; + + RelOptKind reloptkind; + + /* all relations included in this RelOptInfo */ + Relids relids; /* set of base relids (rangetable indexes) */ + + bool isPartitionedTable; /* is it a partitioned table? it is meaningless unless + it is a 'baserel' (reloptkind = RELOPT_BASEREL) */ + PartitionFlag partflag; + + /* size estimates generated by planner */ + double rows; /* estimated number of global result tuples */ + int width; /* estimated avg width of result tuples */ + int encodedwidth; /* estimated avg width of encoded columns in result tuples */ + AttrNumber encodednum; /* number of encoded column */ + + /* materialization information */ + List* reltargetlist; /* Vars to be output by scan of relation */ + List* distribute_keys; /* distribute key */ + List* pathlist; /* Path structures */ + List* ppilist; /* ParamPathInfos used in pathlist */ + struct Path* cheapest_startup_path; + List* cheapest_total_path; /* contain all cheapest total paths from different distribute key */ + struct Path* cheapest_unique_path; + List* cheapest_parameterized_paths; + + /* information about a base rel (not set for join rels!) */ + Index relid; + Oid reltablespace; /* containing tablespace */ + RTEKind rtekind; /* RELATION, SUBQUERY, or FUNCTION */ + AttrNumber min_attr; /* smallest attrno of rel (often <0) */ + AttrNumber max_attr; /* largest attrno of rel */ + Relids* attr_needed; /* array indexed [min_attr .. max_attr] */ + int32* attr_widths; /* array indexed [min_attr .. max_attr] */ + List* lateral_vars; /* LATERAL Vars and PHVs referenced by rel */ + Relids lateral_relids; /* minimum parameterization of rel */ + List* indexlist; /* list of IndexOptInfo */ + RelPageType pages; /* local size estimates derived from pg_class */ + double tuples; /* global size estimates derived from pg_class */ + double multiple; /* how many dn skewed and biased be influenced by distinct. */ + double allvisfrac; + + struct PruningResult* pruning_result; /* pruning result for partitioned table with + baserestrictinfo,it is meaningless unless it + is a 'baserel' (reloptkind = RELOPT_BASEREL) */ + int partItrs; /* the number of the partitions in pruning_result */ + struct PruningResult* pruning_result_for_index_usable; + int partItrs_for_index_usable; /* the number of the partitions in pruning_result_for_seqscan */ + struct PruningResult* pruning_result_for_index_unusable; + int partItrs_for_index_unusable; /* the number of the partitions in pruning_result_for_seqscan */ + /* information about a partitioned table */ + BucketInfo *bucketInfo; + + /* use "struct Plan" to avoid including plannodes.h here */ + struct Plan* subplan; /* if subquery */ + PlannerInfo* subroot; /* if subquery */ + List *subplan_params; /* if subquery */ + /* use "struct FdwRoutine" to avoid including fdwapi.h here */ + struct FdwRoutine* fdwroutine; /* if foreign table */ + void* fdw_private; /* if foreign table */ + + /* used by various scans and joins: */ + List* baserestrictinfo; /* RestrictInfo structures (if base + * rel) */ + QualCost baserestrictcost; /* cost of evaluating the above */ + Index baserestrict_min_security; /* min security_level found in + * baserestrictinfo */ + List* joininfo; /* RestrictInfo structures for join clauses + * involving this rel */ + bool has_eclass_joins; /* T means joininfo is incomplete */ + RelOrientation orientation; /* the store type of base rel */ + RelstoreType relStoreLocation; /* the relation store location. */ + char locator_type; /* the location type of base rel */ + Oid rangelistOid; /* oid of list/range distributed table, InvalidOid if not list/range table */ + List* subplanrestrictinfo; /* table filter with correlated column involved */ + ItstDisKey rel_dis_keys; /* interesting key info for current relation */ + List* varratio; /* rel tuples ratio after join to different relation */ + List* varEqRatio; + + /* + * The alternative rel for cost-based query rewrite + * + * Note: Only base rel have valid pointer of this fields, set to NULL for alternative rel + */ + List* alternatives; + + /* + * Rel opinter to base rel that in plannerinfo->simple_rel_array[x]. + * + * Note: Only alternative rels has valid pointer of this field, set to NULL for the + * origin rel. + */ + RelOptInfo* base_rel; + + unsigned int num_data_nodes = 0; //number of distributing data nodes +} RelOptInfo; + +/* + * IndexOptInfo + * Per-index information for planning/optimization + * + * indexkeys[], indexcollations[], opfamily[], and opcintype[] + * each have ncolumns entries. + * + * sortopfamily[], reverse_sort[], and nulls_first[] likewise have + * ncolumns entries, if the index is ordered; but if it is unordered, + * those pointers are NULL. + * + * Zeroes in the indexkeys[] array indicate index columns that are + * expressions; there is one element in indexprs for each such column. + * + * For an ordered index, reverse_sort[] and nulls_first[] describe the + * sort ordering of a forward indexscan; we can also consider a backward + * indexscan, which will generate the reverse ordering. + * + * The indexprs and indpred expressions have been run through + * prepqual.c and eval_const_expressions() for ease of matching to + * WHERE clauses. indpred is in implicit-AND form. + * + * indextlist is a TargetEntry list representing the index columns. + * It provides an equivalent base-relation Var for each simple column, + * and links to the matching indexprs element for each expression column. + */ +typedef struct IndexOptInfo { + NodeTag type; + + Oid indexoid; /* OID of the index relation */ + bool ispartitionedindex; /* it is an partitioned index */ + Oid partitionindex; /* the partition index oid for current partition */ + Oid reltablespace; /* tablespace of index (not table) */ + RelOptInfo* rel; /* back-link to index's table */ + + /* statistics from pg_class */ + RelPageType pages; /* number of disk pages in index */ + double tuples; /* number of global index tuples in index */ + + /* index descriptor information */ + int ncolumns; /* number of columns in index */ + int nkeycolumns; /* number of key columns in index */ + int* indexkeys; /* column numbers of index's keys, or 0 */ + Oid* indexcollations; /* OIDs of collations of index columns */ + Oid* opfamily; /* OIDs of operator families for columns */ + Oid* opcintype; /* OIDs of opclass declared input data types */ + Oid* sortopfamily; /* OIDs of btree opfamilies, if orderable */ + bool* reverse_sort; /* is sort order descending? */ + bool* nulls_first; /* do NULLs come first in the sort order? */ + Oid relam; /* OID of the access method (in pg_am) */ + + RegProcedure amcostestimate; /* OID of the access method's cost fcn */ + + List* indexprs; /* expressions for non-simple index columns */ + List* indpred; /* predicate if a partial index, else NIL */ + + List* indextlist; /* targetlist representing index columns */ + + bool isGlobal; /* true if index is global partition index */ + bool predOK; /* true if predicate matches query */ + bool unique; /* true if a unique index */ + bool immediate; /* is uniqueness enforced immediately? */ + bool hypothetical; /* true if index doesn't really exist */ + bool canreturn; /* can index return IndexTuples? */ + bool amcanorderbyop; /* does AM support order by operator result? */ + bool amoptionalkey; /* can query omit key for the first column? */ + bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */ + bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */ + bool amhasgettuple; /* does AM have amgettuple interface? */ + bool amhasgetbitmap; /* does AM have amgetbitmap interface? */ +} IndexOptInfo; + +/* + * EquivalenceClasses + * + * Whenever we can determine that a mergejoinable equality clause A = B is + * not delayed by any outer join, we create an EquivalenceClass containing + * the expressions A and B to record this knowledge. If we later find another + * equivalence B = C, we add C to the existing EquivalenceClass; this may + * require merging two existing EquivalenceClasses. At the end of the qual + * distribution process, we have sets of values that are known all transitively + * equal to each other, where "equal" is according to the rules of the btree + * operator family(s) shown in ec_opfamilies, as well as the collation shown + * by ec_collation. (We restrict an EC to contain only equalities whose + * operators belong to the same set of opfamilies. This could probably be + * relaxed, but for now it's not worth the trouble, since nearly all equality + * operators belong to only one btree opclass anyway. Similarly, we suppose + * that all or none of the input datatypes are collatable, so that a single + * collation value is sufficient.) + * + * We also use EquivalenceClasses as the base structure for PathKeys, letting + * us represent knowledge about different sort orderings being equivalent. + * Since every PathKey must reference an EquivalenceClass, we will end up + * with single-member EquivalenceClasses whenever a sort key expression has + * not been equivalenced to anything else. It is also possible that such an + * EquivalenceClass will contain a volatile expression ("ORDER BY random()"), + * which is a case that can't arise otherwise since clauses containing + * volatile functions are never considered mergejoinable. We mark such + * EquivalenceClasses specially to prevent them from being merged with + * ordinary EquivalenceClasses. Also, for volatile expressions we have + * to be careful to match the EquivalenceClass to the correct targetlist + * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a. + * So we record the SortGroupRef of the originating sort clause. + * + * We allow equality clauses appearing below the nullable side of an outer join + * to form EquivalenceClasses, but these have a slightly different meaning: + * the included values might be all NULL rather than all the same non-null + * values. See src/backend/optimizer/README for more on that point. + * + * NB: if ec_merged isn't NULL, this class has been merged into another, and + * should be ignored in favor of using the pointed-to class. + */ +typedef struct EquivalenceClass { + NodeTag type; + + List* ec_opfamilies; /* btree operator family OIDs */ + Oid ec_collation; /* collation, if datatypes are collatable */ + List* ec_members; /* list of EquivalenceMembers */ + List* ec_sources; /* list of generating RestrictInfos */ + List* ec_derives; /* list of derived RestrictInfos */ + Relids ec_relids; /* all relids appearing in ec_members */ + bool ec_has_const; /* any pseudoconstants in ec_members? */ + bool ec_has_volatile; /* the (sole) member is a volatile expr */ + bool ec_below_outer_join; /* equivalence applies below an OJ */ + bool ec_group_set; /* if take part in group */ + bool ec_broken; /* failed to generate needed clauses? */ + Index ec_sortref; /* originating sortclause label, or 0 */ + Index ec_min_security; /* minimum security_level in ec_sources */ + Index ec_max_security; /* maximum security_level in ec_sources */ + struct EquivalenceClass* ec_merged; /* set if merged into another EC */ +} EquivalenceClass; + +/* + * If an EC contains a const and isn't below-outer-join, any PathKey depending + * on it must be redundant, since there's only one possible value of the key. + */ +#define EC_MUST_BE_REDUNDANT(eclass) ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join) + +#define IS_EC_FUNC(rte) \ + (rte->rtekind == RTE_FUNCTION && (((FuncExpr*)rte->funcexpr)->funcid == ECEXTENSIONFUNCOID || \ + ((FuncExpr*)rte->funcexpr)->funcid == ECHADOOPFUNCOID)) + +/* + * EquivalenceMember - one member expression of an EquivalenceClass + * + * em_is_child signifies that this element was built by transposing a member + * for an appendrel parent relation to represent the corresponding expression + * for an appendrel child. These members are used for determining the + * pathkeys of scans on the child relation and for explicitly sorting the + * child when necessary to build a MergeAppend path for the whole appendrel + * tree. An em_is_child member has no impact on the properties of the EC as a + * whole; in particular the EC's ec_relids field does NOT include the child + * relation. An em_is_child member should never be marked em_is_const nor + * cause ec_has_const or ec_has_volatile to be set, either. Thus, em_is_child + * members are not really full-fledged members of the EC, but just reflections + * or doppelgangers of real members. Most operations on EquivalenceClasses + * should ignore em_is_child members, and those that don't should test + * em_relids to make sure they only consider relevant members. + * + * em_datatype is usually the same as exprType(em_expr), but can be + * different when dealing with a binary-compatible opfamily; in particular + * anyarray_ops would never work without this. Use em_datatype when + * looking up a specific btree operator to work with this expression. + */ +typedef struct EquivalenceMember { + NodeTag type; + + Expr* em_expr; /* the expression represented */ + Relids em_relids; /* all relids appearing in em_expr */ + Relids em_nullable_relids; /* nullable by lower outer joins */ + bool em_is_const; /* expression is pseudoconstant? */ + bool em_is_child; /* derived version for a child relation? */ + Oid em_datatype; /* the "nominal type" used by the opfamily */ +} EquivalenceMember; + +/* + * PathKeys + * + * The sort ordering of a path is represented by a list of PathKey nodes. + * An empty list implies no known ordering. Otherwise the first item + * represents the primary sort key, the second the first secondary sort key, + * etc. The value being sorted is represented by linking to an + * EquivalenceClass containing that value and including pk_opfamily among its + * ec_opfamilies. The EquivalenceClass tells which collation to use, too. + * This is a convenient method because it makes it trivial to detect + * equivalent and closely-related orderings. (See optimizer/README for more + * information.) + * + * Note: pk_strategy is either BTLessStrategyNumber (for ASC) or + * BTGreaterStrategyNumber (for DESC). We assume that all ordering-capable + * index types will use btree-compatible strategy numbers. + */ +typedef struct PathKey { + NodeTag type; + + EquivalenceClass* pk_eclass; /* the value that is ordered */ + Oid pk_opfamily; /* btree opfamily defining the ordering */ + int pk_strategy; /* sort direction (ASC or DESC) */ + bool pk_nulls_first; /* do NULLs come before normal values? */ +} PathKey; + +/* + * ParamPathInfo + * + * All parameterized paths for a given relation with given required outer rels + * link to a single ParamPathInfo, which stores common information such as + * the estimated rowcount for this parameterization. We do this partly to + * avoid recalculations, but mostly to ensure that the estimated rowcount + * is in fact the same for every such path. + * + * Note: ppi_clauses is only used in ParamPathInfos for base relation paths; + * in join cases it's NIL because the set of relevant clauses varies depending + * on how the join is formed. The relevant clauses will appear in each + * parameterized join path's joinrestrictinfo list, instead. + */ +typedef struct ParamPathInfo { + NodeTag type; + + Relids ppi_req_outer; /* rels supplying parameters used by path */ + double ppi_rows; /* estimated global number of result tuples */ + List* ppi_clauses; /* join clauses available from outer rels */ + Bitmapset* ppi_req_upper; /* param IDs*/ +} ParamPathInfo; + +/* + * Type "Path" is used as-is for sequential-scan paths, as well as some other + * simple plan types that we don't need any extra information in the path for. + * For other path types it is the first component of a larger struct. + * + * "pathtype" is the NodeTag of the Plan node we could build from this Path. + * It is partially redundant with the Path's NodeTag, but allows us to use + * the same Path type for multiple Plan types when there is no need to + * distinguish the Plan type during path processing. + * + * "param_info", if not NULL, links to a ParamPathInfo that identifies outer + * relation(s) that provide parameter values to each scan of this path. + * That means this path can only be joined to those rels by means of nestloop + * joins with this path on the inside. Also note that a parameterized path + * is responsible for testing all "movable" joinclauses involving this rel + * and the specified outer rel(s). + * + * "rows" is the same as parent->rows in simple paths, but in parameterized + * paths and UniquePaths it can be less than parent->rows, reflecting the + * fact that we've filtered by extra join conditions or removed duplicates. + * + * "pathkeys" is a List of PathKey nodes (see above), describing the sort + * ordering of the path's output rows. + */ +typedef struct Path { + NodeTag type; + + NodeTag pathtype; /* tag identifying scan/join method */ + + RelOptInfo* parent; /* the relation this path can build */ + ParamPathInfo* param_info; /* parameterization info, or NULL if none */ + + /* estimated size/costs for path (see costsize.c for more info) */ + double rows; /* estimated number of global result tuples */ + double multiple; + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + Cost stream_cost; /* cost of actions invoked by stream but can't be parallelled in this path */ + + List* pathkeys; /* sort ordering of path's output */ + List* distribute_keys; /* distribute key, Var list */ + char locator_type; + Oid rangelistOid; + int dop; /* degree of parallelism */ + /* pathkeys is a List of PathKey nodes; see above */ + Distribution distribution; + int hint_value; /* Mark this path if be hinted, and hint kind. */ + double innerdistinct; /* join inner rel distinct estimation value */ + double outerdistinct; /* join outer rel distinct estimation value */ +} Path; + +/* Macro for extracting a path's parameterization relids; beware double eval */ +#define PATH_REQ_OUTER(path) ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids)NULL) +#define PATH_REQ_UPPER(path) ((path)->param_info ? (path)->param_info->ppi_req_upper : (Relids)NULL) + +/* ---------- + * IndexPath represents an index scan over a single index. + * + * This struct is used for both regular indexscans and index-only scans; + * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant. + * + * 'indexinfo' is the index to be scanned. + * + * 'indexclauses' is a list of index qualification clauses, with implicit + * AND semantics across the list. Each clause is a RestrictInfo node from + * the query's WHERE or JOIN conditions. An empty list implies a full + * index scan. + * + * 'indexquals' has the same structure as 'indexclauses', but it contains + * the actual index qual conditions that can be used with the index. + * In simple cases this is identical to 'indexclauses', but when special + * indexable operators appear in 'indexclauses', they are replaced by the + * derived indexscannable conditions in 'indexquals'. + * + * 'indexqualcols' is an integer list of index column numbers (zero-based) + * of the same length as 'indexquals', showing which index column each qual + * is meant to be used with. 'indexquals' is required to be ordered by + * index column, so 'indexqualcols' must form a nondecreasing sequence. + * (The order of multiple quals for the same index column is unspecified.) + * + * 'indexorderbys', if not NIL, is a list of ORDER BY expressions that have + * been found to be usable as ordering operators for an amcanorderbyop index. + * The list must match the path's pathkeys, ie, one expression per pathkey + * in the same order. These are not RestrictInfos, just bare expressions, + * since they generally won't yield booleans. Also, unlike the case for + * quals, it's guaranteed that each expression has the index key on the left + * side of the operator. + * + * 'indexorderbycols' is an integer list of index column numbers (zero-based) + * of the same length as 'indexorderbys', showing which index column each + * ORDER BY expression is meant to be used with. (There is no restriction + * on which index column each ORDER BY can be used with.) + * + * 'indexscandir' is one of: + * ForwardScanDirection: forward scan of an ordered index + * BackwardScanDirection: backward scan of an ordered index + * NoMovementScanDirection: scan of an unordered index, or don't care + * (The executor doesn't care whether it gets ForwardScanDirection or + * NoMovementScanDirection for an indexscan, but the planner wants to + * distinguish ordered from unordered indexes for building pathkeys.) + * + * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that + * we need not recompute them when considering using the same index in a + * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath + * itself represent the costs of an IndexScan or IndexOnlyScan plan type. + * ---------- + */ +typedef struct IndexPath { + Path path; + IndexOptInfo* indexinfo; + List* indexclauses; + List* indexquals; + List* indexqualcols; + List* indexorderbys; + List* indexorderbycols; + ScanDirection indexscandir; + Cost indextotalcost; + Selectivity indexselectivity; +} IndexPath; + +typedef struct PartIteratorPath { + Path path; + PartitionType partType; + Path* subPath; + int itrs; + ScanDirection direction; + bool ispwj; + /* the upper boundary list for the partitions in pruning_result, it is meanless unless it is a partitionwise join */ + List* upperboundary; + /* the lower boundary list for the partitions in pruning_result, it is meanless unless it is a partitionwise join */ + List* lowerboundary; +} PartIteratorPath; + +/* + * BitmapHeapPath represents one or more indexscans that generate TID bitmaps + * instead of directly accessing the heap, followed by AND/OR combinations + * to produce a single bitmap, followed by a heap scan that uses the bitmap. + * Note that the output is always considered unordered, since it will come + * out in physical heap order no matter what the underlying indexes did. + * + * The individual indexscans are represented by IndexPath nodes, and any + * logic on top of them is represented by a tree of BitmapAndPath and + * BitmapOrPath nodes. Notice that we can use the same IndexPath node both + * to represent a regular (or index-only) index scan plan, and as the child + * of a BitmapHeapPath that represents scanning the same index using a + * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath + * always represent the costs to use it as a regular (or index-only) + * IndexScan. The costs of a BitmapIndexScan can be computed using the + * IndexPath's indextotalcost and indexselectivity. + */ +typedef struct BitmapHeapPath { + Path path; + Path* bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */ +} BitmapHeapPath; + +/* + * BitmapAndPath represents a BitmapAnd plan node; it can only appear as + * part of the substructure of a BitmapHeapPath. The Path structure is + * a bit more heavyweight than we really need for this, but for simplicity + * we make it a derivative of Path anyway. + */ +typedef struct BitmapAndPath { + Path path; + List* bitmapquals; /* IndexPaths and BitmapOrPaths */ + Selectivity bitmapselectivity; +} BitmapAndPath; + +/* + * BitmapOrPath represents a BitmapOr plan node; it can only appear as + * part of the substructure of a BitmapHeapPath. The Path structure is + * a bit more heavyweight than we really need for this, but for simplicity + * we make it a derivative of Path anyway. + */ +typedef struct BitmapOrPath { + Path path; + List* bitmapquals; /* IndexPaths and BitmapAndPaths */ + Selectivity bitmapselectivity; +} BitmapOrPath; + +/* + * TidPath represents a scan by TID + * + * tidquals is an implicitly OR'ed list of qual expressions of the form + * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)". + * Note they are bare expressions, not RestrictInfos. + */ +typedef struct TidPath { + Path path; + List* tidquals; /* qual(s) involving CTID = something */ +} TidPath; + +/* + * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM + * + * Note that the subpath comes from a different planning domain; for example + * RTE indexes within it mean something different from those known to the + * SubqueryScanPath. path.parent->subroot is the planning context needed to + * interpret the subpath. + * NOTE: GaussDB keep an subplan other than the sub-path + */ +typedef struct SubqueryScanPath +{ + Path path; + List *subplan_params; + PlannerInfo *subroot; + struct Plan *subplan; /* path representing subquery execution */ +} SubqueryScanPath; + +/* + * ForeignPath represents a potential scan of a foreign table + * + * fdw_private stores FDW private data about the scan. While fdw_private is + * not actually touched by the core code during normal operations, it's + * generally a good idea to use a representation that can be dumped by + * nodeToString(), so that you can examine the structure during debugging + * with tools like pprint(). + */ +typedef struct ForeignPath { + Path path; + Path* fdw_outerpath; + List* fdw_private; +} ForeignPath; + +/* + * ExtensiblePath represents a table scan done by some out-of-core extension. + * + * We provide a set of hooks here - which the provider must take care to set + * up correctly - to allow extensions to supply their own methods of scanning + * a relation. For example, a provider might provide GPU acceleration, a + * cache-based scan, or some other kind of logic we haven't dreamed up yet. + * + * ExtensiblePaths can be injected into the planning process for a relation by + * set_rel_pathlist_hook functions. + * + * Core code must avoid assuming that the ExtensiblePath is only as large as + * the structure declared here; providers are allowed to make it the first + * element in a larger structure. (Since the planner never copies Paths, + * this doesn't add any complication.) However, for consistency with the + * FDW case, we provide a "extensible_private" field in ExtensiblePath; providers + * may prefer to use that rather than define another struct type. + */ +struct ExtensiblePath; + +typedef struct ExtensiblePathMethods { + const char* ExtensibleName; + + /* Convert Path to a Plan */ + struct Plan* (*PlanExtensiblePath)(PlannerInfo* root, RelOptInfo* rel, struct ExtensiblePath* best_path, + List* tlist, List* clauses, List* extensible_plans); +} ExtensiblePathMethods; + +typedef struct ExtensiblePath { + Path path; + uint32 flags; /* mask of EXTENSIBLEPATH_* flags */ + List* extensible_paths; /* list of child Path nodes, if any */ + List* extensible_private; + const struct ExtensiblePathMethods* methods; +} ExtensiblePath; +/* + * AppendPath represents an Append plan, ie, successive execution of + * several member plans. + * + * Note: it is possible for "subpaths" to contain only one, or even no, + * elements. These cases are optimized during create_append_plan. + * In particular, an AppendPath with no subpaths is a "dummy" path that + * is created to represent the case that a relation is provably empty. + */ +typedef struct AppendPath { + Path path; + List* subpaths; /* list of component Paths */ +} AppendPath; + +#define IS_DUMMY_PATH(p) (IsA((p), AppendPath) && ((AppendPath*)(p))->subpaths == NIL) + +/* A relation that's been proven empty will have one path that is dummy */ +#define IS_DUMMY_REL(r) ((r)->cheapest_total_path != NIL && IS_DUMMY_PATH(linitial((r)->cheapest_total_path))) + +/* + * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted + * results from several member plans to produce similarly-sorted output. + */ +typedef struct MergeAppendPath { + Path path; + List* subpaths; /* list of component Paths */ + double limit_tuples; /* hard limit on output tuples, or -1 */ + OpMemInfo* mem_info; +} MergeAppendPath; + +/* + * ResultPath represents use of a Result plan node to compute a variable-free + * targetlist with no underlying tables (a "SELECT expressions" query). + * The query could have a WHERE clause, too, represented by "quals". + * + * Note that quals is a list of bare clauses, not RestrictInfos. + */ +typedef struct ResultPath { + Path path; + List* quals; + Path* subpath; + List* pathqual; + bool ispulledupqual; // qual is pulled up from lower path +} ResultPath; + +/* + * MaterialPath represents use of a Material plan node, i.e., caching of + * the output of its subpath. This is used when the subpath is expensive + * and needs to be scanned repeatedly, or when we need mark/restore ability + * and the subpath doesn't have it. + */ +typedef struct MaterialPath { + Path path; + Path* subpath; + bool materialize_all; /* true for materialize above streamed subplan */ + OpMemInfo mem_info; /* Memory info for materialize */ +} MaterialPath; + +/* + * UniquePath represents elimination of distinct rows from the output of + * its subpath. + * + * This is unlike the other Path nodes in that it can actually generate + * different plans: either hash-based or sort-based implementation, or a + * no-op if the input path can be proven distinct already. The decision + * is sufficiently localized that it's not worth having separate Path node + * types. (Note: in the no-op case, we could eliminate the UniquePath node + * entirely and just return the subpath; but it's convenient to have a + * UniquePath in the path tree to signal upper-level routines that the input + * is known distinct.) + */ +typedef enum { + UNIQUE_PATH_NOOP, /* input is known unique already */ + UNIQUE_PATH_HASH, /* use hashing */ + UNIQUE_PATH_SORT /* use sorting */ +} UniquePathMethod; + +typedef struct UniquePath { + Path path; + Path* subpath; + UniquePathMethod umethod; + List* in_operators; /* equality operators of the IN clause */ + List* uniq_exprs; /* expressions to be made unique */ + bool both_method; + bool hold_tlist; + OpMemInfo mem_info; /* Memory info for hashagg or sort */ +} UniquePath; + +/* + * All join-type paths share these fields. + */ +typedef struct JoinPath { + Path path; + + JoinType jointype; + + Path* outerjoinpath; /* path for the outer side of the join */ + Path* innerjoinpath; /* path for the inner side of the join */ + + List* joinrestrictinfo; /* RestrictInfos to apply to join */ + + /* + * See the notes for RelOptInfo and ParamPathInfo to understand why + * joinrestrictinfo is needed in JoinPath, and can't be merged into the + * parent RelOptInfo. + */ + int skewoptimize; +} JoinPath; + +/* + * A nested-loop path needs no special fields. + */ +typedef JoinPath NestPath; + +/* + * A mergejoin path has these fields. + * + * Unlike other path types, a MergePath node doesn't represent just a single + * run-time plan node: it can represent up to four. Aside from the MergeJoin + * node itself, there can be a Sort node for the outer input, a Sort node + * for the inner input, and/or a Material node for the inner input. We could + * represent these nodes by separate path nodes, but considering how many + * different merge paths are investigated during a complex join problem, + * it seems better to avoid unnecessary palloc overhead. + * + * path_mergeclauses lists the clauses (in the form of RestrictInfos) + * that will be used in the merge. + * + * Note that the mergeclauses are a subset of the parent relation's + * restriction-clause list. Any join clauses that are not mergejoinable + * appear only in the parent's restrict list, and must be checked by a + * qpqual at execution time. + * + * outersortkeys (resp. innersortkeys) is NIL if the outer path + * (resp. inner path) is already ordered appropriately for the + * mergejoin. If it is not NIL then it is a PathKeys list describing + * the ordering that must be created by an explicit Sort node. + * + * materialize_inner is TRUE if a Material node should be placed atop the + * inner input. This may appear with or without an inner Sort step. + */ +typedef struct MergePath { + JoinPath jpath; + List* path_mergeclauses; /* join clauses to be used for merge */ + List* outersortkeys; /* keys for explicit sort, if any */ + List* innersortkeys; /* keys for explicit sort, if any */ + bool materialize_inner; /* add Materialize to inner? */ + OpMemInfo outer_mem_info; /* Mem info for outer explicit sort */ + OpMemInfo inner_mem_info; /* Mem info for inner explicit sort */ + OpMemInfo mat_mem_info; /* Mem info for materialization of inner */ +} MergePath; + +/* + * A hashjoin path has these fields. + * + * The remarks above for mergeclauses apply for hashclauses as well. + * + * Hashjoin does not care what order its inputs appear in, so we have + * no need for sortkeys. + */ +typedef struct HashPath { + JoinPath jpath; + List* path_hashclauses; /* join clauses used for hashing */ + int num_batches; /* number of batches expected */ + OpMemInfo mem_info; /* Mem info for hash table */ +} HashPath; + +#ifdef PGXC +/* + * A remotequery path represents the queries to be sent to the datanode/s + * + * When RemoteQuery plan is created from RemoteQueryPath, we build the query to + * be executed at the datanode. For building such a query, it's important to get + * the RHS relation and LHS relation of the JOIN clause. So, instead of storing + * the outer and inner paths, we find out the RHS and LHS paths and store those + * here. + */ +typedef struct RemoteQueryPath { + Path path; + ExecNodes* rqpath_en; /* List of datanodes to execute the query on */ + /* + * If the path represents a JOIN rel, leftpath and rightpath represent the + * RemoteQuery paths for left (outer) and right (inner) side of the JOIN + * resp. jointype and join_restrictlist pertains to such JOINs. + */ + struct RemoteQueryPath* leftpath; + struct RemoteQueryPath* rightpath; + JoinType jointype; + List* join_restrictlist; /* restrict list corresponding to JOINs, + * only considered if rest of + * the JOIN information is + * available + */ + bool rqhas_unshippable_qual; /* TRUE if there is at least + * one qual which can not be + * shipped to the datanodes + */ + bool rqhas_temp_rel; /* TRUE if one of the base relations + * involved in this path is a temporary + * table. + */ + bool rqhas_unshippable_tlist; /* TRUE if there is at least one + * targetlist entry which is + * not completely shippable. + */ +} RemoteQueryPath; +#endif /* PGXC */ + +/* + * Cached bucket selectivity for hashjoin. + * + * Since bucket selectivity is limited by hashjoin bucket size, so we should only use the cache + * when bucket size is the same. + */ +typedef struct BucketSelectivity { + double nbuckets; + Selectivity bucket_size; + double ndistinct; +} BucketSelectivity; + +/* + * Cached bucket selectivity for one side of restrictinfo. + * + * Since bucket selectivity differs among different data georgraphy, so we should cache three + * stream cases for one side of restrictinfo: non-stream, broadcast, redistribute. + */ +typedef struct BucketSize { + BucketSelectivity normal; + BucketSelectivity broadcast; + BucketSelectivity redistribute; +} BucketSize; + +/* + * Restriction clause info. + * + * We create one of these for each AND sub-clause of a restriction condition + * (WHERE or JOIN/ON clause). Since the restriction clauses are logically + * ANDed, we can use any one of them or any subset of them to filter out + * tuples, without having to evaluate the rest. The RestrictInfo node itself + * stores data used by the optimizer while choosing the best query plan. + * + * If a restriction clause references a single base relation, it will appear + * in the baserestrictinfo list of the RelOptInfo for that base rel. + * + * If a restriction clause references more than one base rel, it will + * appear in the joininfo list of every RelOptInfo that describes a strict + * subset of the base rels mentioned in the clause. The joininfo lists are + * used to drive join tree building by selecting plausible join candidates. + * The clause cannot actually be applied until we have built a join rel + * containing all the base rels it references, however. + * + * When we construct a join rel that includes all the base rels referenced + * in a multi-relation restriction clause, we place that clause into the + * joinrestrictinfo lists of paths for the join rel, if neither left nor + * right sub-path includes all base rels referenced in the clause. The clause + * will be applied at that join level, and will not propagate any further up + * the join tree. (Note: the "predicate migration" code was once intended to + * push restriction clauses up and down the plan tree based on evaluation + * costs, but it's dead code and is unlikely to be resurrected in the + * foreseeable future.) + * + * Note that in the presence of more than two rels, a multi-rel restriction + * might reach different heights in the join tree depending on the join + * sequence we use. So, these clauses cannot be associated directly with + * the join RelOptInfo, but must be kept track of on a per-join-path basis. + * + * RestrictInfos that represent equivalence conditions (i.e., mergejoinable + * equalities that are not outerjoin-delayed) are handled a bit differently. + * Initially we attach them to the EquivalenceClasses that are derived from + * them. When we construct a scan or join path, we look through all the + * EquivalenceClasses and generate derived RestrictInfos representing the + * minimal set of conditions that need to be checked for this particular scan + * or join to enforce that all members of each EquivalenceClass are in fact + * equal in all rows emitted by the scan or join. + * + * When dealing with outer joins we have to be very careful about pushing qual + * clauses up and down the tree. An outer join's own JOIN/ON conditions must + * be evaluated exactly at that join node, unless they are "degenerate" + * conditions that reference only Vars from the nullable side of the join. + * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed + * down below the outer join, if they reference any nullable Vars. + * RestrictInfo nodes contain a flag to indicate whether a qual has been + * pushed down to a lower level than its original syntactic placement in the + * join tree would suggest. If an outer join prevents us from pushing a qual + * down to its "natural" semantic level (the level associated with just the + * base rels used in the qual) then we mark the qual with a "required_relids" + * value including more than just the base rels it actually uses. By + * pretending that the qual references all the rels required to form the outer + * join, we prevent it from being evaluated below the outer join's joinrel. + * When we do form the outer join's joinrel, we still need to distinguish + * those quals that are actually in that join's JOIN/ON condition from those + * that appeared elsewhere in the tree and were pushed down to the join rel + * because they used no other rels. That's what the is_pushed_down flag is + * for; it tells us that a qual is not an OUTER JOIN qual for the set of base + * rels listed in required_relids. A clause that originally came from WHERE + * or an INNER JOIN condition will *always* have its is_pushed_down flag set. + * It's possible for an OUTER JOIN clause to be marked is_pushed_down too, + * if we decide that it can be pushed down into the nullable side of the join. + * In that case it acts as a plain filter qual for wherever it gets evaluated. + * (In short, is_pushed_down is only false for non-degenerate outer join + * conditions. Possibly we should rename it to reflect that meaning?) + * + * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true + * if the clause's applicability must be delayed due to any outer joins + * appearing below it (ie, it has to be postponed to some join level higher + * than the set of relations it actually references). + * + * There is also an outer_relids field, which is NULL except for outer join + * clauses; for those, it is the set of relids on the outer side of the + * clause's outer join. (These are rels that the clause cannot be applied to + * in parameterized scans, since pushing it into the join's outer side would + * lead to wrong answers.) + * + * There is also a nullable_relids field, which is the set of rels the clause + * references that can be forced null by some outer join below the clause. + * + * outerjoin_delayed = true is subtly different from nullable_relids != NULL: + * a clause might reference some nullable rels and yet not be + * outerjoin_delayed because it also references all the other rels of the + * outer join(s). A clause that is not outerjoin_delayed can be enforced + * anywhere it is computable. + * + * To handle security-barrier conditions efficiently, we mark RestrictInfo + * nodes with a security_level field, in which higher values identify clauses + * coming from less-trusted sources. The exact semantics are that a clause + * cannot be evaluated before another clause with a lower security_level value + * unless the first clause is leakproof. As with outer-join clauses, this + * creates a reason for clauses to sometimes need to be evaluated higher in + * the join tree than their contents would suggest; and even at a single plan + * node, this rule constrains the order of application of clauses. + * + * In general, the referenced clause might be arbitrarily complex. The + * kinds of clauses we can handle as indexscan quals, mergejoin clauses, + * or hashjoin clauses are limited (e.g., no volatile functions). The code + * for each kind of path is responsible for identifying the restrict clauses + * it can use and ignoring the rest. Clauses not implemented by an indexscan, + * mergejoin, or hashjoin will be placed in the plan qual or joinqual field + * of the finished Plan node, where they will be enforced by general-purpose + * qual-expression-evaluation code. (But we are still entitled to count + * their selectivity when estimating the result tuple count, if we + * can guess what it is...) + * + * When the referenced clause is an OR clause, we generate a modified copy + * in which additional RestrictInfo nodes are inserted below the top-level + * OR/AND structure. This is a convenience for OR indexscan processing: + * indexquals taken from either the top level or an OR subclause will have + * associated RestrictInfo nodes. + * + * The can_join flag is set true if the clause looks potentially useful as + * a merge or hash join clause, that is if it is a binary opclause with + * nonoverlapping sets of relids referenced in the left and right sides. + * (Whether the operator is actually merge or hash joinable isn't checked, + * however.) + * + * The pseudoconstant flag is set true if the clause contains no Vars of + * the current query level and no volatile functions. Such a clause can be + * pulled out and used as a one-time qual in a gating Result node. We keep + * pseudoconstant clauses in the same lists as other RestrictInfos so that + * the regular clause-pushing machinery can assign them to the correct join + * level, but they need to be treated specially for cost and selectivity + * estimates. Note that a pseudoconstant clause can never be an indexqual + * or merge or hash join clause, so it's of no interest to large parts of + * the planner. + * + * When join clauses are generated from EquivalenceClasses, there may be + * several equally valid ways to enforce join equivalence, of which we need + * apply only one. We mark clauses of this kind by setting parent_ec to + * point to the generating EquivalenceClass. Multiple clauses with the same + * parent_ec in the same join are redundant. + */ +typedef struct RestrictInfo { + NodeTag type; + + Expr* clause; /* the represented clause of WHERE or JOIN */ + + bool is_pushed_down; /* TRUE if clause was pushed down in level */ + + bool outerjoin_delayed; /* TRUE if delayed by lower outer join */ + + bool can_join; /* see comment above */ + + bool pseudoconstant; /* see comment above */ + + bool leakproof; /* TRUE if known to contain no leaked Vars */ + + Index security_level; /* Mark RestrictInfo nodes with a security_level */ + + /* The set of relids (varnos) actually referenced in the clause: */ + Relids clause_relids; + + /* The set of relids required to evaluate the clause: */ + Relids required_relids; + + /* If an outer-join clause, the outer-side relations, else NULL: */ + Relids outer_relids; + + /* The relids used in the clause that are nullable by lower outer joins: */ + Relids nullable_relids; + + /* These fields are set for any binary opclause: */ + Relids left_relids; /* relids in left side of clause */ + Relids right_relids; /* relids in right side of clause */ + + /* This field is NULL unless clause is an OR clause: */ + Expr* orclause; /* modified clause with RestrictInfos */ + + /* This field is NULL unless clause is potentially redundant: */ + EquivalenceClass* parent_ec; /* generating EquivalenceClass */ + + /* cache space for cost and selectivity */ + QualCost eval_cost; /* eval cost of clause; -1 if not yet set */ + Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER) + * semantics; -1 if not yet set; >1 means a + * redundant clause */ + Selectivity outer_selec; /* selectivity for outer join semantics; -1 if + * not yet set */ + + /* valid if clause is mergejoinable, else NIL */ + List* mergeopfamilies; /* opfamilies containing clause operator */ + + /* cache space for mergeclause processing; NULL if not yet set */ + EquivalenceClass* left_ec; /* EquivalenceClass containing lefthand */ + EquivalenceClass* right_ec; /* EquivalenceClass containing righthand */ + EquivalenceMember* left_em; /* EquivalenceMember for lefthand */ + EquivalenceMember* right_em; /* EquivalenceMember for righthand */ + List* scansel_cache; /* list of MergeScanSelCache structs */ + + /* transient workspace for use while considering a specific join path */ + bool outer_is_left; /* T = outer var on left, F = on right */ + + /* valid if clause is hashjoinable, else InvalidOid: */ + Oid hashjoinoperator; /* copy of clause operator */ + + /* cache space for hashclause processing; -1 if not yet set */ + BucketSize left_bucketsize; /* avg bucketsize of left side */ + BucketSize right_bucketsize; /* avg bucketsize of right side */ +} RestrictInfo; + +/* + * Since mergejoinscansel() is a relatively expensive function, and would + * otherwise be invoked many times while planning a large join tree, + * we go out of our way to cache its results. Each mergejoinable + * RestrictInfo carries a list of the specific sort orderings that have + * been considered for use with it, and the resulting selectivities. + */ +typedef struct MergeScanSelCache { + /* Ordering details (cache lookup key) */ + Oid opfamily; /* btree opfamily defining the ordering */ + Oid collation; /* collation for the ordering */ + int strategy; /* sort direction (ASC or DESC) */ + bool nulls_first; /* do NULLs come before normal values? */ + /* Results */ + Selectivity leftstartsel; /* first-join fraction for clause left side */ + Selectivity leftendsel; /* last-join fraction for clause left side */ + Selectivity rightstartsel; /* first-join fraction for clause right side */ + Selectivity rightendsel; /* last-join fraction for clause right side */ +} MergeScanSelCache; + +/* + * Placeholder node for an expression to be evaluated below the top level + * of a plan tree. This is used during planning to represent the contained + * expression. At the end of the planning process it is replaced by either + * the contained expression or a Var referring to a lower-level evaluation of + * the contained expression. Typically the evaluation occurs below an outer + * join, and Var references above the outer join might thereby yield NULL + * instead of the expression value. + * + * Although the planner treats this as an expression node type, it is not + * recognized by the parser or executor, so we declare it here rather than + * in primnodes.h. + */ +typedef struct PlaceHolderVar { + Expr xpr; + Expr* phexpr; /* the represented expression */ + Relids phrels; /* base relids syntactically within expr src */ + Index phid; /* ID for PHV (unique within planner run) */ + Index phlevelsup; /* > 0 if PHV belongs to outer query */ +} PlaceHolderVar; + +/* + * "Special join" info. + * + * One-sided outer joins constrain the order of joining partially but not + * completely. We flatten such joins into the planner's top-level list of + * relations to join, but record information about each outer join in a + * SpecialJoinInfo struct. These structs are kept in the PlannerInfo node's + * join_info_list. + * + * Similarly, semijoins and antijoins created by flattening IN (subselect) + * and EXISTS(subselect) clauses create partial constraints on join order. + * These are likewise recorded in SpecialJoinInfo structs. + * + * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility + * of planning for them, because this simplifies make_join_rel()'s API. + * + * min_lefthand and min_righthand are the sets of base relids that must be + * available on each side when performing the special join. lhs_strict is + * true if the special join's condition cannot succeed when the LHS variables + * are all NULL (this means that an outer join can commute with upper-level + * outer joins even if it appears in their RHS). We don't bother to set + * lhs_strict for FULL JOINs, however. + * + * It is not valid for either min_lefthand or min_righthand to be empty sets; + * if they were, this would break the logic that enforces join order. + * + * syn_lefthand and syn_righthand are the sets of base relids that are + * syntactically below this special join. (These are needed to help compute + * min_lefthand and min_righthand for higher joins.) + * + * delay_upper_joins is set TRUE if we detect a pushed-down clause that has + * to be evaluated after this join is formed (because it references the RHS). + * Any outer joins that have such a clause and this join in their RHS cannot + * commute with this join, because that would leave noplace to check the + * pushed-down clause. (We don't track this for FULL JOINs, either.) + * + * join_quals is an implicit-AND list of the quals syntactically associated + * with the join (they may or may not end up being applied at the join level). + * This is just a side list and does not drive actual application of quals. + * For JOIN_SEMI joins, this is cleared to NIL in create_unique_path() if + * the join is found not to be suitable for a uniqueify-the-RHS plan. + * + * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching + * the inputs to make it a LEFT JOIN. So the allowed values of jointype + * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI. + * + * For purposes of join selectivity estimation, we create transient + * SpecialJoinInfo structures for regular inner joins; so it is possible + * to have jointype == JOIN_INNER in such a structure, even though this is + * not allowed within join_info_list. We also create transient + * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for + * cost estimation purposes it is sometimes useful to know the join size under + * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and + * join_quals are not set meaningfully within such structs. + */ +typedef struct SpecialJoinInfo { + NodeTag type; + Relids min_lefthand; /* base relids in minimum LHS for join */ + Relids min_righthand; /* base relids in minimum RHS for join */ + Relids syn_lefthand; /* base relids syntactically within LHS */ + Relids syn_righthand; /* base relids syntactically within RHS */ + JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */ + bool lhs_strict; /* joinclause is strict for some LHS rel */ + bool delay_upper_joins; /* can't commute with upper RHS */ + List* join_quals; /* join quals, in implicit-AND list format */ + bool varratio_cached; /* decide chach selec or not. */ +} SpecialJoinInfo; + +/* + * "Lateral join" info. + * + * Lateral references in subqueries constrain the join order in a way that's + * somewhat like outer joins, though different in detail. We construct one or + * more LateralJoinInfos for each RTE with lateral references, and add them to + * the PlannerInfo node's lateral_info_list. + * + * lateral_rhs is the relid of a baserel with lateral references, and + * lateral_lhs is a set of relids of baserels it references, all of which + * must be present on the LHS to compute a parameter needed by the RHS. + * Typically, lateral_lhs is a singleton, but it can include multiple rels + * if the RHS references a PlaceHolderVar with a multi-rel ph_eval_at level. + * We disallow joining to only part of the LHS in such cases, since that would + * result in a join tree with no convenient place to compute the PHV. + * + * When an appendrel contains lateral references (eg "LATERAL (SELECT x.col1 + * UNION ALL SELECT y.col2)"), the LateralJoinInfos reference the parent + * baserel not the member otherrels, since it is the parent relid that is + * considered for joining purposes. + */ +typedef struct LateralJoinInfo +{ + NodeTag type; + Index lateral_rhs; /* a baserel containing lateral refs */ + Relids lateral_lhs; /* some base relids it references */ +} LateralJoinInfo; + + +/* + * Append-relation info. + * + * When we expand an inheritable table or a UNION-ALL subselect into an + * "append relation" (essentially, a list of child RTEs), we build an + * AppendRelInfo for each child RTE. The list of AppendRelInfos indicates + * which child RTEs must be included when expanding the parent, and each + * node carries information needed to translate Vars referencing the parent + * into Vars referencing that child. + * + * These structs are kept in the PlannerInfo node's append_rel_list. + * Note that we just throw all the structs into one list, and scan the + * whole list when desiring to expand any one parent. We could have used + * a more complex data structure (eg, one list per parent), but this would + * be harder to update during operations such as pulling up subqueries, + * and not really any easier to scan. Considering that typical queries + * will not have many different append parents, it doesn't seem worthwhile + * to complicate things. + * + * Note: after completion of the planner prep phase, any given RTE is an + * append parent having entries in append_rel_list if and only if its + * "inh" flag is set. We clear "inh" for plain tables that turn out not + * to have inheritance children, and (in an abuse of the original meaning + * of the flag) we set "inh" for subquery RTEs that turn out to be + * flattenable UNION ALL queries. This lets us avoid useless searches + * of append_rel_list. + * + * Note: the data structure assumes that append-rel members are single + * baserels. This is OK for inheritance, but it prevents us from pulling + * up a UNION ALL member subquery if it contains a join. While that could + * be fixed with a more complex data structure, at present there's not much + * point because no improvement in the plan could result. + */ +typedef struct AppendRelInfo { + NodeTag type; + + /* + * These fields uniquely identify this append relationship. There can be + * (in fact, always should be) multiple AppendRelInfos for the same + * parent_relid, but never more than one per child_relid, since a given + * RTE cannot be a child of more than one append parent. + */ + Index parent_relid; /* RT index of append parent rel */ + Index child_relid; /* RT index of append child rel */ + + /* + * For an inheritance appendrel, the parent and child are both regular + * relations, and we store their rowtype OIDs here for use in translating + * whole-row Vars. For a UNION-ALL appendrel, the parent and child are + * both subqueries with no named rowtype, and we store InvalidOid here. + */ + Oid parent_reltype; /* OID of parent's composite type */ + Oid child_reltype; /* OID of child's composite type */ + + /* + * The N'th element of this list is a Var or expression representing the + * child column corresponding to the N'th column of the parent. This is + * used to translate Vars referencing the parent rel into references to + * the child. A list element is NULL if it corresponds to a dropped + * column of the parent (this is only possible for inheritance cases, not + * UNION ALL). The list elements are always simple Vars for inheritance + * cases, but can be arbitrary expressions in UNION ALL cases. + * + * Notice we only store entries for user columns (attno > 0). Whole-row + * Vars are special-cased, and system columns (attno < 0) need no special + * translation since their attnos are the same for all tables. + * + * Caution: the Vars have varlevelsup = 0. Be careful to adjust as needed + * when copying into a subquery. + */ + List* translated_vars; /* Expressions in the child's Vars */ + + /* + * We store the parent table's OID here for inheritance, or InvalidOid for + * UNION ALL. This is only needed to help in generating error messages if + * an attempt is made to reference a dropped parent column. + */ + Oid parent_reloid; /* OID of parent relation */ +} AppendRelInfo; + +/* + * For each distinct placeholder expression generated during planning, we + * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list. + * This stores info that is needed centrally rather than in each copy of the + * PlaceHolderVar. The phid fields identify which PlaceHolderInfo goes with + * each PlaceHolderVar. Note that phid is unique throughout a planner run, + * not just within a query level --- this is so that we need not reassign ID's + * when pulling a subquery into its parent. + * + * The idea is to evaluate the expression at (only) the ph_eval_at join level, + * then allow it to bubble up like a Var until the ph_needed join level. + * ph_needed has the same definition as attr_needed for a regular Var. + * + * ph_may_need is an initial estimate of ph_needed, formed using the + * syntactic locations of references to the PHV. We need this in order to + * determine whether the PHV reference forces a join ordering constraint: + * if the PHV has to be evaluated below the nullable side of an outer join, + * and then used above that outer join, we must constrain join order to ensure + * there's a valid place to evaluate the PHV below the join. The final + * actual ph_needed level might be lower than ph_may_need, but we can't + * determine that until later on. Fortunately this doesn't matter for what + * we need ph_may_need for: if there's a PHV reference syntactically + * above the outer join, it's not going to be allowed to drop below the outer + * join, so we would come to the same conclusions about join order even if + * we had the final ph_needed value to compare to. + * + * We create a PlaceHolderInfo only after determining that the PlaceHolderVar + * is actually referenced in the plan tree, so that unreferenced placeholders + * don't result in unnecessary constraints on join order. + */ +typedef struct PlaceHolderInfo { + NodeTag type; + + Index phid; /* ID for PH (unique within planner run) */ + PlaceHolderVar* ph_var; /* copy of PlaceHolderVar tree */ + Relids ph_eval_at; /* lowest level we can evaluate value at */ + Relids ph_needed; /* highest level the value is needed at */ + int32 ph_width; /* estimated attribute width */ +} PlaceHolderInfo; + +/* + * For each potentially index-optimizable MIN/MAX aggregate function, + * root->minmax_aggs stores a MinMaxAggInfo describing it. + */ +typedef struct MinMaxAggInfo { + NodeTag type; + + Oid aggfnoid; /* pg_proc Oid of the aggregate */ + Oid aggsortop; /* Oid of its sort operator */ + Expr* target; /* expression we are aggregating on */ + PlannerInfo* subroot; /* modified "root" for planning the subquery */ + Path* path; /* access path for subquery */ + Cost pathcost; /* estimated cost to fetch first row */ + Param* param; /* param for subplan's output */ + Aggref* aggref; /* used for construct the final agg in distributed env */ +} MinMaxAggInfo; + +/* + * At runtime, PARAM_EXEC slots are used to pass values around from one plan + * node to another. They can be used to pass values down into subqueries (for + * outer references in subqueries), or up out of subqueries (for the results + * of a subplan), or from a NestLoop plan node into its inner relation (when + * the inner scan is parameterized with values from the outer relation). + * The planner is responsible for assigning nonconflicting PARAM_EXEC IDs to + * the PARAM_EXEC Params it generates. + * + * Outer references are managed via root->plan_params, which is a list of + * PlannerParamItems. While planning a subquery, each parent query level's + * plan_params contains the values required from it by the current subquery. + * During create_plan(), we use plan_params to track values that must be + * passed from outer to inner sides of NestLoop plan nodes. + * + * The item a PlannerParamItem represents can be one of three kinds: + * + * A Var: the slot represents a variable of this level that must be passed + * down because subqueries have outer references to it, or must be passed + * from a NestLoop node to its inner scan. The varlevelsup value in the Var + * will always be zero. + * + * A PlaceHolderVar: this works much like the Var case, except that the + * entry is a PlaceHolderVar node with a contained expression. The PHV + * will have phlevelsup = 0, and the contained expression is adjusted + * to match in level. + * + * An Aggref (with an expression tree representing its argument): the slot + * represents an aggregate expression that is an outer reference for some + * subquery. The Aggref itself has agglevelsup = 0, and its argument tree + * is adjusted to match in level. + * + * Note: we detect duplicate Var and PlaceHolderVar parameters and coalesce + * them into one slot, but we do not bother to do that for Aggrefs. + * The scope of duplicate-elimination only extends across the set of + * parameters passed from one query level into a single subquery, or for + * nestloop parameters across the set of nestloop parameters used in a single + * query level. So there is no possibility of a PARAM_EXEC slot being used + * for conflicting purposes. + * + * In addition, PARAM_EXEC slots are assigned for Params representing outputs + * from subplans (values that are setParam items for those subplans). These + * IDs need not be tracked via PlannerParamItems, since we do not need any + * duplicate-elimination nor later processing of the represented expressions. + * Instead, we just record the assignment of the slot number by incrementing + * root->glob->nParamExec. + */ +typedef struct PlannerParamItem { + NodeTag type; + + Node* item; /* the Var, PlaceHolderVar, or Aggref */ + int paramId; /* its assigned PARAM_EXEC slot number */ +} PlannerParamItem; + +/* + * When making cost estimates for a SEMI or ANTI join, there are some + * correction factors that are needed in both nestloop and hash joins + * to account for the fact that the executor can stop scanning inner rows + * as soon as it finds a match to the current outer row. These numbers + * depend only on the selected outer and inner join relations, not on the + * particular paths used for them, so it's worthwhile to calculate them + * just once per relation pair not once per considered path. This struct + * is filled by compute_semi_anti_join_factors and must be passed along + * to the join cost estimation functions. + * + * outer_match_frac is the fraction of the outer tuples that are + * expected to have at least one match. + * match_count is the average number of matches expected for + * outer tuples that have at least one match. + * + * Note: For right-semi/anti join, match_count is the fraction of the inner tuples + * that are expected to have at least one match in outer tuples. + */ +typedef struct SemiAntiJoinFactors { + Selectivity outer_match_frac; + Selectivity match_count; +} SemiAntiJoinFactors; + +/* + * For speed reasons, cost estimation for join paths is performed in two + * phases: the first phase tries to quickly derive a lower bound for the + * join cost, and then we check if that's sufficient to reject the path. + * If not, we come back for a more refined cost estimate. The first phase + * fills a JoinCostWorkspace struct with its preliminary cost estimates + * and possibly additional intermediate values. The second phase takes + * these values as inputs to avoid repeating work. + * + * (Ideally we'd declare this in cost.h, but it's also needed in pathnode.h, + * so seems best to put it here.) + */ +typedef struct JoinCostWorkspace { + /* Preliminary cost estimates --- must not be larger than final ones! */ + Cost startup_cost; /* cost expended before fetching any tuples */ + Cost total_cost; /* total cost (assuming all tuples fetched) */ + + /* Fields below here should be treated as private to costsize.c */ + Cost run_cost; /* non-startup cost components */ + + /* private for cost_nestloop code */ + Cost inner_rescan_run_cost; + double outer_matched_rows; + Selectivity inner_scan_frac; + + /* private for cost_mergejoin code */ + Cost inner_run_cost; + double outer_rows; + double inner_rows; + double outer_skip_rows; + double inner_skip_rows; + + /* private for cost_hashjoin code */ + int numbuckets; + int numbatches; + + /* Meminfo for joins */ + OpMemInfo outer_mem_info; + OpMemInfo inner_mem_info; +} JoinCostWorkspace; + +#endif /* RELATION_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/replnodes.h postgresql-hll-2.14/include/nodes/replnodes.h --- postgresql-hll-2.14_old/include/nodes/replnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/replnodes.h 2020-12-12 17:06:43.324349032 +0800 @@ -0,0 +1,114 @@ +/* ------------------------------------------------------------------------- + * + * replnodes.h + * definitions for replication grammar parse nodes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/nodes/replnodes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REPLNODES_H +#define REPLNODES_H + +#include "access/xlogdefs.h" +#include "nodes/pg_list.h" + +typedef enum ReplicationKind { REPLICATION_KIND_PHYSICAL, REPLICATION_KIND_LOGICAL } ReplicationKind; + +/* ---------------------- + * IDENTIFY_SYSTEM command + * ---------------------- + */ +typedef struct IdentifySystemCmd { + NodeTag type; +} IdentifySystemCmd; + +typedef struct IdentifyVersionCmd { + NodeTag type; +} IdentifyVersionCmd; + +typedef struct IdentifyModeCmd { + NodeTag type; +} IdentifyModeCmd; + +typedef struct IdentifyMaxLsnCmd { + NodeTag type; +} IdentifyMaxLsnCmd; + +typedef struct IdentifyConsistenceCmd { + NodeTag type; + XLogRecPtr recordptr; +} IdentifyConsistenceCmd; + +typedef struct IdentifyChannelCmd { + NodeTag type; + int channel_identifier; +} IdentifyChannelCmd; + +typedef struct IdentifyAZCmd { + NodeTag type; +} IdentifyAZCmd; + +/* ---------------------- + * BASE_BACKUP command + * ---------------------- + */ +typedef struct BaseBackupCmd { + NodeTag type; + List* options; +} BaseBackupCmd; + +/* ---------------------- + * CREATE_REPLICATION_SLOT command + * ---------------------- + */ +typedef struct CreateReplicationSlotCmd { + NodeTag type; + char* slotname; + ReplicationKind kind; + XLogRecPtr init_slot_lsn; + char* plugin; +} CreateReplicationSlotCmd; + +/* ---------------------- + * DROP_REPLICATION_SLOT command + * ---------------------- + */ +typedef struct DropReplicationSlotCmd { + NodeTag type; + char* slotname; +} DropReplicationSlotCmd; + +/* ---------------------- + * START_REPLICATION command + * ---------------------- + */ +typedef struct StartReplicationCmd { + NodeTag type; + ReplicationKind kind; + char* slotname; + XLogRecPtr startpoint; + List* options; +} StartReplicationCmd; + +/* ---------------------- + * START_REPLICATION(DATA) command + * ---------------------- + */ +typedef struct StartDataReplicationCmd { + NodeTag type; +} StartDataReplicationCmd; + +/* ---------------------- + * FETCH_MOT_CHECKPOINT command + * ---------------------- + */ +typedef struct FetchMotCheckpointCmd { + NodeTag type; +} FetchMotCheckpointCmd; + +#endif /* REPLNODES_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/tidbitmap.h postgresql-hll-2.14/include/nodes/tidbitmap.h --- postgresql-hll-2.14_old/include/nodes/tidbitmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/tidbitmap.h 2020-12-12 17:06:43.324349032 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * tidbitmap.h + * PostgreSQL tuple-id (TID) bitmap package + * + * This module provides bitmap data structures that are spiritually + * similar to Bitmapsets, but are specially adapted to store sets of + * tuple identifiers (TIDs), or ItemPointers. In particular, the division + * of an ItemPointer into BlockNumber and OffsetNumber is catered for. + * Also, since we wish to be able to store very large tuple sets in + * memory with this data structure, we support "lossy" storage, in which + * we no longer remember individual tuple offsets on a page but only the + * fact that a particular page needs to be visited. + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/tidbitmap.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TIDBITMAP_H +#define TIDBITMAP_H + +#include "storage/itemptr.h" + +/* + * Actual bitmap representation is private to tidbitmap.c. Callers can + * do IsA(x, TIDBitmap) on it, but nothing else. + */ +typedef struct TIDBitmap TIDBitmap; + +/* Likewise, TBMIterator is private */ +typedef struct TBMIterator TBMIterator; + +/* Result structure for tbm_iterate */ +typedef struct { + BlockNumber blockno; /* page number containing tuples */ + Oid partitionOid; + int ntuples; /* -1 indicates lossy result */ + bool recheck; /* should the tuples be rechecked? */ + /* Note: recheck is always true if ntuples < 0 */ + OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; +} TBMIterateResult; + +/* function prototypes in nodes/tidbitmap.c */ +extern TIDBitmap* tbm_create(long maxbytes); +extern void tbm_free(TIDBitmap* tbm); + +extern void tbm_add_tuples( + TIDBitmap* tbm, const ItemPointer tids, int ntids, bool recheck, Oid partitionOid = InvalidOid); +extern void tbm_add_page(TIDBitmap* tbm, BlockNumber pageno, Oid partitionOid = InvalidOid); + +extern void tbm_union(TIDBitmap* a, const TIDBitmap* b); +extern void tbm_intersect(TIDBitmap* a, const TIDBitmap* b); + +extern bool tbm_is_empty(const TIDBitmap* tbm); + +extern TBMIterator* tbm_begin_iterate(TIDBitmap* tbm); +extern TBMIterateResult* tbm_iterate(TBMIterator* iterator); +extern void tbm_end_iterate(TBMIterator* iterator); +extern bool tbm_is_global(const TIDBitmap* tbm); +extern void tbm_set_global(TIDBitmap* tbm, bool isGlobal); +#endif /* TIDBITMAP_H */ diff -uprN postgresql-hll-2.14_old/include/nodes/value.h postgresql-hll-2.14/include/nodes/value.h --- postgresql-hll-2.14_old/include/nodes/value.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/nodes/value.h 2020-12-12 17:06:43.324349032 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * value.h + * interface for Value nodes + * + * + * Copyright (c) 2003-2012, PostgreSQL Global Development Group + * + * src/include/nodes/value.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef VALUE_H +#define VALUE_H +#include "nodes/primnodes.h" +#include "nodes/nodes.h" + +/* ---------------------- + * Value node + * + * The same Value struct is used for five node types: T_Integer, + * T_Float, T_String, T_BitString, T_Null. + * + * Integral values are actually represented by a machine integer, + * but both floats and strings are represented as strings. + * Using T_Float as the node type simply indicates that + * the contents of the string look like a valid numeric literal. + * + * (Before Postgres 7.0, we used a double to represent T_Float, + * but that creates loss-of-precision problems when the value is + * ultimately destined to be converted to NUMERIC. Since Value nodes + * are only used in the parsing process, not for runtime data, it's + * better to use the more general representation.) + * + * Note that an integer-looking string will get lexed as T_Float if + * the value is too large to fit in a 'long'. + * + * Nulls, of course, don't need the value part at all. + * ---------------------- + */ +typedef struct Value { + NodeTag type; /* tag appropriately (eg. T_String) */ + union ValUnion { + long ival; /* machine integer */ + char* str; /* string */ + } val; +} Value; + +#define intVal(v) (((Value*)(v))->val.ival) +#define floatVal(v) atof(((Value*)(v))->val.str) +#define strVal(v) (((Value*)(v))->val.str) + +extern Value* makeInteger(long i); +extern Value* makeFloat(char* numericStr); +extern Value* makeString(char* str); +extern Value* makeBitString(char* str); + +#endif /* VALUE_H */ diff -uprN postgresql-hll-2.14_old/include/openssl/aes.h postgresql-hll-2.14/include/openssl/aes.h --- postgresql-hll-2.14_old/include/openssl/aes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/aes.h 2020-12-12 17:06:43.325349045 +0800 @@ -0,0 +1,92 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_AES_H +# define HEADER_AES_H + +# include + +# include +# ifdef __cplusplus +extern "C" { +# endif + +# define AES_ENCRYPT 1 +# define AES_DECRYPT 0 + +/* + * Because array size can't be a const in C, the following two are macros. + * Both sizes are in bytes. + */ +# define AES_MAXNR 14 +# define AES_BLOCK_SIZE 16 + +/* This should be a hidden type, but EVP requires that the size be known */ +struct aes_key_st { +# ifdef AES_LONG + unsigned long rd_key[4 * (AES_MAXNR + 1)]; +# else + unsigned int rd_key[4 * (AES_MAXNR + 1)]; +# endif + int rounds; +}; +typedef struct aes_key_st AES_KEY; + +const char *AES_options(void); + +int AES_set_encrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); +int AES_set_decrypt_key(const unsigned char *userKey, const int bits, + AES_KEY *key); + +void AES_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); +void AES_decrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key); + +void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, + const AES_KEY *key, const int enc); +void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, const int enc); +void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num, const int enc); +void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, int *num); +/* NB: the IV is _two_ blocks long */ +void AES_ige_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + unsigned char *ivec, const int enc); +/* NB: the IV is _four_ blocks long */ +void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const AES_KEY *key, + const AES_KEY *key2, const unsigned char *ivec, + const int enc); + +int AES_wrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); +int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, unsigned int inlen); + + +# ifdef __cplusplus +} +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/asn1err.h postgresql-hll-2.14/include/openssl/asn1err.h --- postgresql-hll-2.14_old/include/openssl/asn1err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/asn1err.h 2020-12-12 17:06:43.325349045 +0800 @@ -0,0 +1,256 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASN1ERR_H +# define HEADER_ASN1ERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_ASN1_strings(void); + +/* + * ASN1 function codes. + */ +# define ASN1_F_A2D_ASN1_OBJECT 100 +# define ASN1_F_A2I_ASN1_INTEGER 102 +# define ASN1_F_A2I_ASN1_STRING 103 +# define ASN1_F_APPEND_EXP 176 +# define ASN1_F_ASN1_BIO_INIT 113 +# define ASN1_F_ASN1_BIT_STRING_SET_BIT 183 +# define ASN1_F_ASN1_CB 177 +# define ASN1_F_ASN1_CHECK_TLEN 104 +# define ASN1_F_ASN1_COLLECT 106 +# define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 +# define ASN1_F_ASN1_D2I_FP 109 +# define ASN1_F_ASN1_D2I_READ_BIO 107 +# define ASN1_F_ASN1_DIGEST 184 +# define ASN1_F_ASN1_DO_ADB 110 +# define ASN1_F_ASN1_DO_LOCK 233 +# define ASN1_F_ASN1_DUP 111 +# define ASN1_F_ASN1_ENC_SAVE 115 +# define ASN1_F_ASN1_EX_C2I 204 +# define ASN1_F_ASN1_FIND_END 190 +# define ASN1_F_ASN1_GENERALIZEDTIME_ADJ 216 +# define ASN1_F_ASN1_GENERATE_V3 178 +# define ASN1_F_ASN1_GET_INT64 224 +# define ASN1_F_ASN1_GET_OBJECT 114 +# define ASN1_F_ASN1_GET_UINT64 225 +# define ASN1_F_ASN1_I2D_BIO 116 +# define ASN1_F_ASN1_I2D_FP 117 +# define ASN1_F_ASN1_ITEM_D2I_FP 206 +# define ASN1_F_ASN1_ITEM_DUP 191 +# define ASN1_F_ASN1_ITEM_EMBED_D2I 120 +# define ASN1_F_ASN1_ITEM_EMBED_NEW 121 +# define ASN1_F_ASN1_ITEM_FLAGS_I2D 118 +# define ASN1_F_ASN1_ITEM_I2D_BIO 192 +# define ASN1_F_ASN1_ITEM_I2D_FP 193 +# define ASN1_F_ASN1_ITEM_PACK 198 +# define ASN1_F_ASN1_ITEM_SIGN 195 +# define ASN1_F_ASN1_ITEM_SIGN_CTX 220 +# define ASN1_F_ASN1_ITEM_UNPACK 199 +# define ASN1_F_ASN1_ITEM_VERIFY 197 +# define ASN1_F_ASN1_MBSTRING_NCOPY 122 +# define ASN1_F_ASN1_OBJECT_NEW 123 +# define ASN1_F_ASN1_OUTPUT_DATA 214 +# define ASN1_F_ASN1_PCTX_NEW 205 +# define ASN1_F_ASN1_PRIMITIVE_NEW 119 +# define ASN1_F_ASN1_SCTX_NEW 221 +# define ASN1_F_ASN1_SIGN 128 +# define ASN1_F_ASN1_STR2TYPE 179 +# define ASN1_F_ASN1_STRING_GET_INT64 227 +# define ASN1_F_ASN1_STRING_GET_UINT64 230 +# define ASN1_F_ASN1_STRING_SET 186 +# define ASN1_F_ASN1_STRING_TABLE_ADD 129 +# define ASN1_F_ASN1_STRING_TO_BN 228 +# define ASN1_F_ASN1_STRING_TYPE_NEW 130 +# define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 +# define ASN1_F_ASN1_TEMPLATE_NEW 133 +# define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I 131 +# define ASN1_F_ASN1_TIME_ADJ 217 +# define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 +# define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 +# define ASN1_F_ASN1_UTCTIME_ADJ 218 +# define ASN1_F_ASN1_VERIFY 137 +# define ASN1_F_B64_READ_ASN1 209 +# define ASN1_F_B64_WRITE_ASN1 210 +# define ASN1_F_BIO_NEW_NDEF 208 +# define ASN1_F_BITSTR_CB 180 +# define ASN1_F_BN_TO_ASN1_STRING 229 +# define ASN1_F_C2I_ASN1_BIT_STRING 189 +# define ASN1_F_C2I_ASN1_INTEGER 194 +# define ASN1_F_C2I_ASN1_OBJECT 196 +# define ASN1_F_C2I_IBUF 226 +# define ASN1_F_C2I_UINT64_INT 101 +# define ASN1_F_COLLECT_DATA 140 +# define ASN1_F_D2I_ASN1_OBJECT 147 +# define ASN1_F_D2I_ASN1_UINTEGER 150 +# define ASN1_F_D2I_AUTOPRIVATEKEY 207 +# define ASN1_F_D2I_PRIVATEKEY 154 +# define ASN1_F_D2I_PUBLICKEY 155 +# define ASN1_F_DO_BUF 142 +# define ASN1_F_DO_CREATE 124 +# define ASN1_F_DO_DUMP 125 +# define ASN1_F_DO_TCREATE 222 +# define ASN1_F_I2A_ASN1_OBJECT 126 +# define ASN1_F_I2D_ASN1_BIO_STREAM 211 +# define ASN1_F_I2D_ASN1_OBJECT 143 +# define ASN1_F_I2D_DSA_PUBKEY 161 +# define ASN1_F_I2D_EC_PUBKEY 181 +# define ASN1_F_I2D_PRIVATEKEY 163 +# define ASN1_F_I2D_PUBLICKEY 164 +# define ASN1_F_I2D_RSA_PUBKEY 165 +# define ASN1_F_LONG_C2I 166 +# define ASN1_F_NDEF_PREFIX 127 +# define ASN1_F_NDEF_SUFFIX 136 +# define ASN1_F_OID_MODULE_INIT 174 +# define ASN1_F_PARSE_TAGGING 182 +# define ASN1_F_PKCS5_PBE2_SET_IV 167 +# define ASN1_F_PKCS5_PBE2_SET_SCRYPT 231 +# define ASN1_F_PKCS5_PBE_SET 202 +# define ASN1_F_PKCS5_PBE_SET0_ALGOR 215 +# define ASN1_F_PKCS5_PBKDF2_SET 219 +# define ASN1_F_PKCS5_SCRYPT_SET 232 +# define ASN1_F_SMIME_READ_ASN1 212 +# define ASN1_F_SMIME_TEXT 213 +# define ASN1_F_STABLE_GET 138 +# define ASN1_F_STBL_MODULE_INIT 223 +# define ASN1_F_UINT32_C2I 105 +# define ASN1_F_UINT32_NEW 139 +# define ASN1_F_UINT64_C2I 112 +# define ASN1_F_UINT64_NEW 141 +# define ASN1_F_X509_CRL_ADD0_REVOKED 169 +# define ASN1_F_X509_INFO_NEW 170 +# define ASN1_F_X509_NAME_ENCODE 203 +# define ASN1_F_X509_NAME_EX_D2I 158 +# define ASN1_F_X509_NAME_EX_NEW 171 +# define ASN1_F_X509_PKEY_NEW 173 + +/* + * ASN1 reason codes. + */ +# define ASN1_R_ADDING_OBJECT 171 +# define ASN1_R_ASN1_PARSE_ERROR 203 +# define ASN1_R_ASN1_SIG_PARSE_ERROR 204 +# define ASN1_R_AUX_ERROR 100 +# define ASN1_R_BAD_OBJECT_HEADER 102 +# define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 214 +# define ASN1_R_BN_LIB 105 +# define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 +# define ASN1_R_BUFFER_TOO_SMALL 107 +# define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108 +# define ASN1_R_CONTEXT_NOT_INITIALISED 217 +# define ASN1_R_DATA_IS_WRONG 109 +# define ASN1_R_DECODE_ERROR 110 +# define ASN1_R_DEPTH_EXCEEDED 174 +# define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED 198 +# define ASN1_R_ENCODE_ERROR 112 +# define ASN1_R_ERROR_GETTING_TIME 173 +# define ASN1_R_ERROR_LOADING_SECTION 172 +# define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 +# define ASN1_R_EXPECTING_AN_INTEGER 115 +# define ASN1_R_EXPECTING_AN_OBJECT 116 +# define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 +# define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 +# define ASN1_R_FIELD_MISSING 121 +# define ASN1_R_FIRST_NUM_TOO_LARGE 122 +# define ASN1_R_HEADER_TOO_LONG 123 +# define ASN1_R_ILLEGAL_BITSTRING_FORMAT 175 +# define ASN1_R_ILLEGAL_BOOLEAN 176 +# define ASN1_R_ILLEGAL_CHARACTERS 124 +# define ASN1_R_ILLEGAL_FORMAT 177 +# define ASN1_R_ILLEGAL_HEX 178 +# define ASN1_R_ILLEGAL_IMPLICIT_TAG 179 +# define ASN1_R_ILLEGAL_INTEGER 180 +# define ASN1_R_ILLEGAL_NEGATIVE_VALUE 226 +# define ASN1_R_ILLEGAL_NESTED_TAGGING 181 +# define ASN1_R_ILLEGAL_NULL 125 +# define ASN1_R_ILLEGAL_NULL_VALUE 182 +# define ASN1_R_ILLEGAL_OBJECT 183 +# define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 +# define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 +# define ASN1_R_ILLEGAL_PADDING 221 +# define ASN1_R_ILLEGAL_TAGGED_ANY 127 +# define ASN1_R_ILLEGAL_TIME_VALUE 184 +# define ASN1_R_ILLEGAL_ZERO_CONTENT 222 +# define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185 +# define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 +# define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 220 +# define ASN1_R_INVALID_BMPSTRING_LENGTH 129 +# define ASN1_R_INVALID_DIGIT 130 +# define ASN1_R_INVALID_MIME_TYPE 205 +# define ASN1_R_INVALID_MODIFIER 186 +# define ASN1_R_INVALID_NUMBER 187 +# define ASN1_R_INVALID_OBJECT_ENCODING 216 +# define ASN1_R_INVALID_SCRYPT_PARAMETERS 227 +# define ASN1_R_INVALID_SEPARATOR 131 +# define ASN1_R_INVALID_STRING_TABLE_VALUE 218 +# define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 +# define ASN1_R_INVALID_UTF8STRING 134 +# define ASN1_R_INVALID_VALUE 219 +# define ASN1_R_LIST_ERROR 188 +# define ASN1_R_MIME_NO_CONTENT_TYPE 206 +# define ASN1_R_MIME_PARSE_ERROR 207 +# define ASN1_R_MIME_SIG_PARSE_ERROR 208 +# define ASN1_R_MISSING_EOC 137 +# define ASN1_R_MISSING_SECOND_NUMBER 138 +# define ASN1_R_MISSING_VALUE 189 +# define ASN1_R_MSTRING_NOT_UNIVERSAL 139 +# define ASN1_R_MSTRING_WRONG_TAG 140 +# define ASN1_R_NESTED_ASN1_STRING 197 +# define ASN1_R_NESTED_TOO_DEEP 201 +# define ASN1_R_NON_HEX_CHARACTERS 141 +# define ASN1_R_NOT_ASCII_FORMAT 190 +# define ASN1_R_NOT_ENOUGH_DATA 142 +# define ASN1_R_NO_CONTENT_TYPE 209 +# define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 +# define ASN1_R_NO_MULTIPART_BODY_FAILURE 210 +# define ASN1_R_NO_MULTIPART_BOUNDARY 211 +# define ASN1_R_NO_SIG_CONTENT_TYPE 212 +# define ASN1_R_NULL_IS_WRONG_LENGTH 144 +# define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191 +# define ASN1_R_ODD_NUMBER_OF_CHARS 145 +# define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 +# define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 +# define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 +# define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192 +# define ASN1_R_SHORT_LINE 150 +# define ASN1_R_SIG_INVALID_MIME_TYPE 213 +# define ASN1_R_STREAMING_NOT_SUPPORTED 202 +# define ASN1_R_STRING_TOO_LONG 151 +# define ASN1_R_STRING_TOO_SHORT 152 +# define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 +# define ASN1_R_TIME_NOT_ASCII_FORMAT 193 +# define ASN1_R_TOO_LARGE 223 +# define ASN1_R_TOO_LONG 155 +# define ASN1_R_TOO_SMALL 224 +# define ASN1_R_TYPE_NOT_CONSTRUCTED 156 +# define ASN1_R_TYPE_NOT_PRIMITIVE 195 +# define ASN1_R_UNEXPECTED_EOC 159 +# define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH 215 +# define ASN1_R_UNKNOWN_FORMAT 160 +# define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 +# define ASN1_R_UNKNOWN_OBJECT_TYPE 162 +# define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 +# define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM 199 +# define ASN1_R_UNKNOWN_TAG 194 +# define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 +# define ASN1_R_UNSUPPORTED_CIPHER 228 +# define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 +# define ASN1_R_UNSUPPORTED_TYPE 196 +# define ASN1_R_WRONG_INTEGER_TYPE 225 +# define ASN1_R_WRONG_PUBLIC_KEY_TYPE 200 +# define ASN1_R_WRONG_TAG 168 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/asn1.h postgresql-hll-2.14/include/openssl/asn1.h --- postgresql-hll-2.14_old/include/openssl/asn1.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/asn1.h 2020-12-12 17:06:43.325349045 +0800 @@ -0,0 +1,886 @@ +/* + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASN1_H +# define HEADER_ASN1_H + +# include +# include +# include +# include +# include +# include +# include + +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +# define V_ASN1_UNIVERSAL 0x00 +# define V_ASN1_APPLICATION 0x40 +# define V_ASN1_CONTEXT_SPECIFIC 0x80 +# define V_ASN1_PRIVATE 0xc0 + +# define V_ASN1_CONSTRUCTED 0x20 +# define V_ASN1_PRIMITIVE_TAG 0x1f +# define V_ASN1_PRIMATIVE_TAG /*compat*/ V_ASN1_PRIMITIVE_TAG + +# define V_ASN1_APP_CHOOSE -2/* let the recipient choose */ +# define V_ASN1_OTHER -3/* used in ASN1_TYPE */ +# define V_ASN1_ANY -4/* used in ASN1 template code */ + +# define V_ASN1_UNDEF -1 +/* ASN.1 tag values */ +# define V_ASN1_EOC 0 +# define V_ASN1_BOOLEAN 1 /**/ +# define V_ASN1_INTEGER 2 +# define V_ASN1_BIT_STRING 3 +# define V_ASN1_OCTET_STRING 4 +# define V_ASN1_NULL 5 +# define V_ASN1_OBJECT 6 +# define V_ASN1_OBJECT_DESCRIPTOR 7 +# define V_ASN1_EXTERNAL 8 +# define V_ASN1_REAL 9 +# define V_ASN1_ENUMERATED 10 +# define V_ASN1_UTF8STRING 12 +# define V_ASN1_SEQUENCE 16 +# define V_ASN1_SET 17 +# define V_ASN1_NUMERICSTRING 18 /**/ +# define V_ASN1_PRINTABLESTRING 19 +# define V_ASN1_T61STRING 20 +# define V_ASN1_TELETEXSTRING 20/* alias */ +# define V_ASN1_VIDEOTEXSTRING 21 /**/ +# define V_ASN1_IA5STRING 22 +# define V_ASN1_UTCTIME 23 +# define V_ASN1_GENERALIZEDTIME 24 /**/ +# define V_ASN1_GRAPHICSTRING 25 /**/ +# define V_ASN1_ISO64STRING 26 /**/ +# define V_ASN1_VISIBLESTRING 26/* alias */ +# define V_ASN1_GENERALSTRING 27 /**/ +# define V_ASN1_UNIVERSALSTRING 28 /**/ +# define V_ASN1_BMPSTRING 30 + +/* + * NB the constants below are used internally by ASN1_INTEGER + * and ASN1_ENUMERATED to indicate the sign. They are *not* on + * the wire tag values. + */ + +# define V_ASN1_NEG 0x100 +# define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) +# define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) + +/* For use with d2i_ASN1_type_bytes() */ +# define B_ASN1_NUMERICSTRING 0x0001 +# define B_ASN1_PRINTABLESTRING 0x0002 +# define B_ASN1_T61STRING 0x0004 +# define B_ASN1_TELETEXSTRING 0x0004 +# define B_ASN1_VIDEOTEXSTRING 0x0008 +# define B_ASN1_IA5STRING 0x0010 +# define B_ASN1_GRAPHICSTRING 0x0020 +# define B_ASN1_ISO64STRING 0x0040 +# define B_ASN1_VISIBLESTRING 0x0040 +# define B_ASN1_GENERALSTRING 0x0080 +# define B_ASN1_UNIVERSALSTRING 0x0100 +# define B_ASN1_OCTET_STRING 0x0200 +# define B_ASN1_BIT_STRING 0x0400 +# define B_ASN1_BMPSTRING 0x0800 +# define B_ASN1_UNKNOWN 0x1000 +# define B_ASN1_UTF8STRING 0x2000 +# define B_ASN1_UTCTIME 0x4000 +# define B_ASN1_GENERALIZEDTIME 0x8000 +# define B_ASN1_SEQUENCE 0x10000 +/* For use with ASN1_mbstring_copy() */ +# define MBSTRING_FLAG 0x1000 +# define MBSTRING_UTF8 (MBSTRING_FLAG) +# define MBSTRING_ASC (MBSTRING_FLAG|1) +# define MBSTRING_BMP (MBSTRING_FLAG|2) +# define MBSTRING_UNIV (MBSTRING_FLAG|4) +# define SMIME_OLDMIME 0x400 +# define SMIME_CRLFEOL 0x800 +# define SMIME_STREAM 0x1000 + struct X509_algor_st; +DEFINE_STACK_OF(X509_ALGOR) + +# define ASN1_STRING_FLAG_BITS_LEFT 0x08/* Set if 0x07 has bits left value */ +/* + * This indicates that the ASN1_STRING is not a real value but just a place + * holder for the location where indefinite length constructed data should be + * inserted in the memory buffer + */ +# define ASN1_STRING_FLAG_NDEF 0x010 + +/* + * This flag is used by the CMS code to indicate that a string is not + * complete and is a place holder for content when it had all been accessed. + * The flag will be reset when content has been written to it. + */ + +# define ASN1_STRING_FLAG_CONT 0x020 +/* + * This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING + * type. + */ +# define ASN1_STRING_FLAG_MSTRING 0x040 +/* String is embedded and only content should be freed */ +# define ASN1_STRING_FLAG_EMBED 0x080 +/* String should be parsed in RFC 5280's time format */ +# define ASN1_STRING_FLAG_X509_TIME 0x100 +/* This is the base type that holds just about everything :-) */ +struct asn1_string_st { + int length; + int type; + unsigned char *data; + /* + * The value of the following field depends on the type being held. It + * is mostly being used for BIT_STRING so if the input data has a + * non-zero 'unused bits' value, it will be handled correctly + */ + long flags; +}; + +/* + * ASN1_ENCODING structure: this is used to save the received encoding of an + * ASN1 type. This is useful to get round problems with invalid encodings + * which can break signatures. + */ + +typedef struct ASN1_ENCODING_st { + unsigned char *enc; /* DER encoding */ + long len; /* Length of encoding */ + int modified; /* set to 1 if 'enc' is invalid */ +} ASN1_ENCODING; + +/* Used with ASN1 LONG type: if a long is set to this it is omitted */ +# define ASN1_LONG_UNDEF 0x7fffffffL + +# define STABLE_FLAGS_MALLOC 0x01 +/* + * A zero passed to ASN1_STRING_TABLE_new_add for the flags is interpreted + * as "don't change" and STABLE_FLAGS_MALLOC is always set. By setting + * STABLE_FLAGS_MALLOC only we can clear the existing value. Use the alias + * STABLE_FLAGS_CLEAR to reflect this. + */ +# define STABLE_FLAGS_CLEAR STABLE_FLAGS_MALLOC +# define STABLE_NO_MASK 0x02 +# define DIRSTRING_TYPE \ + (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) +# define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) + +typedef struct asn1_string_table_st { + int nid; + long minsize; + long maxsize; + unsigned long mask; + unsigned long flags; +} ASN1_STRING_TABLE; + +DEFINE_STACK_OF(ASN1_STRING_TABLE) + +/* size limits: this stuff is taken straight from RFC2459 */ + +# define ub_name 32768 +# define ub_common_name 64 +# define ub_locality_name 128 +# define ub_state_name 128 +# define ub_organization_name 64 +# define ub_organization_unit_name 64 +# define ub_title 64 +# define ub_email_address 128 + +/* + * Declarations for template structures: for full definitions see asn1t.h + */ +typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; +typedef struct ASN1_TLC_st ASN1_TLC; +/* This is just an opaque pointer */ +typedef struct ASN1_VALUE_st ASN1_VALUE; + +/* Declare ASN1 functions: the implement macro in in asn1t.h */ + +# define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) + +# define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type) + +# define DECLARE_ASN1_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) + +# define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) + +# define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(itname) + +# define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ + type *d2i_##name(type **a, const unsigned char **in, long len); \ + int i2d_##name(const type *a, unsigned char **out); \ + DECLARE_ASN1_ITEM(name) + +# define DECLARE_ASN1_NDEF_FUNCTION(name) \ + int i2d_##name##_NDEF(name *a, unsigned char **out); + +# define DECLARE_ASN1_FUNCTIONS_const(name) \ + DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ + DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) + +# define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ + type *name##_new(void); \ + void name##_free(type *a); + +# define DECLARE_ASN1_PRINT_FUNCTION(stname) \ + DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname) + +# define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ + int fname##_print_ctx(BIO *out, stname *x, int indent, \ + const ASN1_PCTX *pctx); + +# define D2I_OF(type) type *(*)(type **,const unsigned char **,long) +# define I2D_OF(type) int (*)(type *,unsigned char **) +# define I2D_OF_const(type) int (*)(const type *,unsigned char **) + +# define CHECKED_D2I_OF(type, d2i) \ + ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0))) +# define CHECKED_I2D_OF(type, i2d) \ + ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0))) +# define CHECKED_NEW_OF(type, xnew) \ + ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0))) +# define CHECKED_PTR_OF(type, p) \ + ((void*) (1 ? p : (type*)0)) +# define CHECKED_PPTR_OF(type, p) \ + ((void**) (1 ? p : (type**)0)) + +# define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long) +# define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **) +# define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type) + +TYPEDEF_D2I2D_OF(void); + +/*- + * The following macros and typedefs allow an ASN1_ITEM + * to be embedded in a structure and referenced. Since + * the ASN1_ITEM pointers need to be globally accessible + * (possibly from shared libraries) they may exist in + * different forms. On platforms that support it the + * ASN1_ITEM structure itself will be globally exported. + * Other platforms will export a function that returns + * an ASN1_ITEM pointer. + * + * To handle both cases transparently the macros below + * should be used instead of hard coding an ASN1_ITEM + * pointer in a structure. + * + * The structure will look like this: + * + * typedef struct SOMETHING_st { + * ... + * ASN1_ITEM_EXP *iptr; + * ... + * } SOMETHING; + * + * It would be initialised as e.g.: + * + * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; + * + * and the actual pointer extracted with: + * + * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); + * + * Finally an ASN1_ITEM pointer can be extracted from an + * appropriate reference with: ASN1_ITEM_rptr(X509). This + * would be used when a function takes an ASN1_ITEM * argument. + * + */ + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM ASN1_ITEM_EXP; + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +# define ASN1_ITEM_ptr(iptr) (iptr) + +/* Macro to include ASN1_ITEM pointer from base type */ +# define ASN1_ITEM_ref(iptr) (&(iptr##_it)) + +# define ASN1_ITEM_rptr(ref) (&(ref##_it)) + +# define DECLARE_ASN1_ITEM(name) \ + OPENSSL_EXTERN const ASN1_ITEM name##_it; + +# else + +/* + * Platforms that can't easily handle shared global variables are declared as + * functions returning ASN1_ITEM pointers. + */ + +/* ASN1_ITEM pointer exported type */ +typedef const ASN1_ITEM *ASN1_ITEM_EXP (void); + +/* Macro to obtain ASN1_ITEM pointer from exported type */ +# define ASN1_ITEM_ptr(iptr) (iptr()) + +/* Macro to include ASN1_ITEM pointer from base type */ +# define ASN1_ITEM_ref(iptr) (iptr##_it) + +# define ASN1_ITEM_rptr(ref) (ref##_it()) + +# define DECLARE_ASN1_ITEM(name) \ + const ASN1_ITEM * name##_it(void); + +# endif + +/* Parameters used by ASN1_STRING_print_ex() */ + +/* + * These determine which characters to escape: RFC2253 special characters, + * control characters and MSB set characters + */ + +# define ASN1_STRFLGS_ESC_2253 1 +# define ASN1_STRFLGS_ESC_CTRL 2 +# define ASN1_STRFLGS_ESC_MSB 4 + +/* + * This flag determines how we do escaping: normally RC2253 backslash only, + * set this to use backslash and quote. + */ + +# define ASN1_STRFLGS_ESC_QUOTE 8 + +/* These three flags are internal use only. */ + +/* Character is a valid PrintableString character */ +# define CHARTYPE_PRINTABLESTRING 0x10 +/* Character needs escaping if it is the first character */ +# define CHARTYPE_FIRST_ESC_2253 0x20 +/* Character needs escaping if it is the last character */ +# define CHARTYPE_LAST_ESC_2253 0x40 + +/* + * NB the internal flags are safely reused below by flags handled at the top + * level. + */ + +/* + * If this is set we convert all character strings to UTF8 first + */ + +# define ASN1_STRFLGS_UTF8_CONVERT 0x10 + +/* + * If this is set we don't attempt to interpret content: just assume all + * strings are 1 byte per character. This will produce some pretty odd + * looking output! + */ + +# define ASN1_STRFLGS_IGNORE_TYPE 0x20 + +/* If this is set we include the string type in the output */ +# define ASN1_STRFLGS_SHOW_TYPE 0x40 + +/* + * This determines which strings to display and which to 'dump' (hex dump of + * content octets or DER encoding). We can only dump non character strings or + * everything. If we don't dump 'unknown' they are interpreted as character + * strings with 1 octet per character and are subject to the usual escaping + * options. + */ + +# define ASN1_STRFLGS_DUMP_ALL 0x80 +# define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 + +/* + * These determine what 'dumping' does, we can dump the content octets or the + * DER encoding: both use the RFC2253 #XXXXX notation. + */ + +# define ASN1_STRFLGS_DUMP_DER 0x200 + +/* + * This flag specifies that RC2254 escaping shall be performed. + */ +#define ASN1_STRFLGS_ESC_2254 0x400 + +/* + * All the string flags consistent with RFC2253, escaping control characters + * isn't essential in RFC2253 but it is advisable anyway. + */ + +# define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ + ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + ASN1_STRFLGS_UTF8_CONVERT | \ + ASN1_STRFLGS_DUMP_UNKNOWN | \ + ASN1_STRFLGS_DUMP_DER) + +DEFINE_STACK_OF(ASN1_INTEGER) + +DEFINE_STACK_OF(ASN1_GENERALSTRING) + +DEFINE_STACK_OF(ASN1_UTF8STRING) + +typedef struct asn1_type_st { + int type; + union { + char *ptr; + ASN1_BOOLEAN boolean; + ASN1_STRING *asn1_string; + ASN1_OBJECT *object; + ASN1_INTEGER *integer; + ASN1_ENUMERATED *enumerated; + ASN1_BIT_STRING *bit_string; + ASN1_OCTET_STRING *octet_string; + ASN1_PRINTABLESTRING *printablestring; + ASN1_T61STRING *t61string; + ASN1_IA5STRING *ia5string; + ASN1_GENERALSTRING *generalstring; + ASN1_BMPSTRING *bmpstring; + ASN1_UNIVERSALSTRING *universalstring; + ASN1_UTCTIME *utctime; + ASN1_GENERALIZEDTIME *generalizedtime; + ASN1_VISIBLESTRING *visiblestring; + ASN1_UTF8STRING *utf8string; + /* + * set and sequence are left complete and still contain the set or + * sequence bytes + */ + ASN1_STRING *set; + ASN1_STRING *sequence; + ASN1_VALUE *asn1_value; + } value; +} ASN1_TYPE; + +DEFINE_STACK_OF(ASN1_TYPE) + +typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; + +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY) + +/* This is used to contain a list of bit names */ +typedef struct BIT_STRING_BITNAME_st { + int bitnum; + const char *lname; + const char *sname; +} BIT_STRING_BITNAME; + +# define B_ASN1_TIME \ + B_ASN1_UTCTIME | \ + B_ASN1_GENERALIZEDTIME + +# define B_ASN1_PRINTABLE \ + B_ASN1_NUMERICSTRING| \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_T61STRING| \ + B_ASN1_IA5STRING| \ + B_ASN1_BIT_STRING| \ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING|\ + B_ASN1_SEQUENCE|\ + B_ASN1_UNKNOWN + +# define B_ASN1_DIRECTORYSTRING \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_TELETEXSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_UTF8STRING + +# define B_ASN1_DISPLAYTEXT \ + B_ASN1_IA5STRING| \ + B_ASN1_VISIBLESTRING| \ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING + +DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) + +int ASN1_TYPE_get(const ASN1_TYPE *a); +void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); +int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); +int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); + +ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t); +void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t); + +ASN1_OBJECT *ASN1_OBJECT_new(void); +void ASN1_OBJECT_free(ASN1_OBJECT *a); +int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp); +ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, + long length); + +DECLARE_ASN1_ITEM(ASN1_OBJECT) + +DEFINE_STACK_OF(ASN1_OBJECT) + +ASN1_STRING *ASN1_STRING_new(void); +void ASN1_STRING_free(ASN1_STRING *a); +void ASN1_STRING_clear_free(ASN1_STRING *a); +int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str); +ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *a); +ASN1_STRING *ASN1_STRING_type_new(int type); +int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); + /* + * Since this is used to store all sorts of things, via macros, for now, + * make its data void * + */ +int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); +void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); +int ASN1_STRING_length(const ASN1_STRING *x); +void ASN1_STRING_length_set(ASN1_STRING *x, int n); +int ASN1_STRING_type(const ASN1_STRING *x); +DEPRECATEDIN_1_1_0(unsigned char *ASN1_STRING_data(ASN1_STRING *x)) +const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x); + +DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) +int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length); +int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); +int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n); +int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, + const unsigned char *flags, int flags_len); + +int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, + BIT_STRING_BITNAME *tbl, int indent); +int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl); +int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value, + BIT_STRING_BITNAME *tbl); + +DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) +ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, + long length); +ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x); +int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y); + +DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) + +int ASN1_UTCTIME_check(const ASN1_UTCTIME *a); +ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t); +ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, + int offset_day, long offset_sec); +int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); +int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); + +int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, + time_t t); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, + time_t t, int offset_day, + long offset_sec); +int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); + +int ASN1_TIME_diff(int *pday, int *psec, + const ASN1_TIME *from, const ASN1_TIME *to); + +DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) +ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a); +int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, + const ASN1_OCTET_STRING *b); +int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, + int len); + +DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_NULL) +DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) + +int UTF8_getc(const unsigned char *str, int len, unsigned long *val); +int UTF8_putc(unsigned char *str, int len, unsigned long value); + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) + +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) +DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) +DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) +DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) +DECLARE_ASN1_FUNCTIONS(ASN1_TIME) + +DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF) + +ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); +ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, + int offset_day, long offset_sec); +int ASN1_TIME_check(const ASN1_TIME *t); +ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, + ASN1_GENERALIZEDTIME **out); +int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); +int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str); +int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm); +int ASN1_TIME_normalize(ASN1_TIME *s); +int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t); +int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b); + +int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); +int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size); +int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a); +int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size); +int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a); +int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size); +int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type); +int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a); + +int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num); +ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, + const char *sn, const char *ln); + +int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a); +int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r); +int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a); +int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r); + +int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); +long ASN1_INTEGER_get(const ASN1_INTEGER *a); +ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai); +BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); + +int ASN1_ENUMERATED_get_int64(int64_t *pr, const ASN1_ENUMERATED *a); +int ASN1_ENUMERATED_set_int64(ASN1_ENUMERATED *a, int64_t r); + + +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); +long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai); +BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn); + +/* General */ +/* given a string, return the correct type, max is the maximum length */ +int ASN1_PRINTABLE_type(const unsigned char *s, int max); + +unsigned long ASN1_tag2bit(int tag); + +/* SPECIALS */ +int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, + int *pclass, long omax); +int ASN1_check_infinite_end(unsigned char **p, long len); +int ASN1_const_check_infinite_end(const unsigned char **p, long len); +void ASN1_put_object(unsigned char **pp, int constructed, int length, + int tag, int xclass); +int ASN1_put_eoc(unsigned char **pp); +int ASN1_object_size(int constructed, int length, int tag); + +/* Used to implement other functions */ +void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x); + +# define ASN1_dup_of(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_dup_of_const(type,i2d,d2i,x) \ + ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \ + CHECKED_D2I_OF(type, d2i), \ + CHECKED_PTR_OF(const type, x))) + +void *ASN1_item_dup(const ASN1_ITEM *it, void *x); + +/* ASN1 alloc/free macros for when a type is only used internally */ + +# define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type)) +# define M_ASN1_free_of(x, type) \ + ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type)) + +# ifndef OPENSSL_NO_STDIO +void *ASN1_d2i_fp(void *(*xnew) (void), d2i_of_void *d2i, FILE *in, void **x); + +# define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); +int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x); + +# define ASN1_i2d_fp_of(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_i2d_fp_of_const(type,i2d,out,x) \ + (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); +int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags); +# endif + +int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in); + +void *ASN1_d2i_bio(void *(*xnew) (void), d2i_of_void *d2i, BIO *in, void **x); + +# define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \ + ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \ + CHECKED_D2I_OF(type, d2i), \ + in, \ + CHECKED_PPTR_OF(type, x))) + +void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); +int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x); + +# define ASN1_i2d_bio_of(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \ + out, \ + CHECKED_PTR_OF(type, x))) + +# define ASN1_i2d_bio_of_const(type,i2d,out,x) \ + (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \ + out, \ + CHECKED_PTR_OF(const type, x))) + +int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); +int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a); +int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a); +int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a); +int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v); +int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags); +int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int off); +int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, + unsigned char *buf, int off); +int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); +int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, + int dump); +const char *ASN1_tag2str(int tag); + +/* Used to load and write Netscape format cert */ + +int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); + +int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len); +int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data, int max_len); +int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, + unsigned char *data, int len); +int ASN1_TYPE_get_int_octetstring(const ASN1_TYPE *a, long *num, + unsigned char *data, int max_len); + +void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it); + +ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, + ASN1_OCTET_STRING **oct); + +void ASN1_STRING_set_default_mask(unsigned long mask); +int ASN1_STRING_set_default_mask_asc(const char *p); +unsigned long ASN1_STRING_get_default_mask(void); +int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask); +int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, + int inform, unsigned long mask, + long minsize, long maxsize); + +ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, + const unsigned char *in, int inlen, + int inform, int nid); +ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); +int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); +void ASN1_STRING_TABLE_cleanup(void); + +/* ASN1 template functions */ + +/* Old API compatible functions */ +ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); +void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); +ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, + long len, const ASN1_ITEM *it); +int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); +int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, + const ASN1_ITEM *it); + +void ASN1_add_oid_module(void); +void ASN1_add_stable_module(void); + +ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf); +ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf); +int ASN1_str2mask(const char *str, unsigned long *pmask); + +/* ASN1 Print flags */ + +/* Indicate missing OPTIONAL fields */ +# define ASN1_PCTX_FLAGS_SHOW_ABSENT 0x001 +/* Mark start and end of SEQUENCE */ +# define ASN1_PCTX_FLAGS_SHOW_SEQUENCE 0x002 +/* Mark start and end of SEQUENCE/SET OF */ +# define ASN1_PCTX_FLAGS_SHOW_SSOF 0x004 +/* Show the ASN1 type of primitives */ +# define ASN1_PCTX_FLAGS_SHOW_TYPE 0x008 +/* Don't show ASN1 type of ANY */ +# define ASN1_PCTX_FLAGS_NO_ANY_TYPE 0x010 +/* Don't show ASN1 type of MSTRINGs */ +# define ASN1_PCTX_FLAGS_NO_MSTRING_TYPE 0x020 +/* Don't show field names in SEQUENCE */ +# define ASN1_PCTX_FLAGS_NO_FIELD_NAME 0x040 +/* Show structure names of each SEQUENCE field */ +# define ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME 0x080 +/* Don't show structure name even at top level */ +# define ASN1_PCTX_FLAGS_NO_STRUCT_NAME 0x100 + +int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent, + const ASN1_ITEM *it, const ASN1_PCTX *pctx); +ASN1_PCTX *ASN1_PCTX_new(void); +void ASN1_PCTX_free(ASN1_PCTX *p); +unsigned long ASN1_PCTX_get_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_nm_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_nm_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_cert_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_cert_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_oid_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags); +unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); +void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); + +ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx)); +void ASN1_SCTX_free(ASN1_SCTX *p); +const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p); +const ASN1_TEMPLATE *ASN1_SCTX_get_template(ASN1_SCTX *p); +unsigned long ASN1_SCTX_get_flags(ASN1_SCTX *p); +void ASN1_SCTX_set_app_data(ASN1_SCTX *p, void *data); +void *ASN1_SCTX_get_app_data(ASN1_SCTX *p); + +const BIO_METHOD *BIO_f_asn1(void); + +BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); + +int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, + const ASN1_ITEM *it); +int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, + const char *hdr, const ASN1_ITEM *it); +int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, + int ctype_nid, int econt_nid, + STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it); +ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it); +int SMIME_crlf_copy(BIO *in, BIO *out, int flags); +int SMIME_text(BIO *in, BIO *out); + +const ASN1_ITEM *ASN1_ITEM_lookup(const char *name); +const ASN1_ITEM *ASN1_ITEM_get(size_t i); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/asn1_mac.h postgresql-hll-2.14/include/openssl/asn1_mac.h --- postgresql-hll-2.14_old/include/openssl/asn1_mac.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/asn1_mac.h 2020-12-12 17:06:43.325349045 +0800 @@ -0,0 +1,10 @@ +/* + * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#error "This file is obsolete; please update your software." diff -uprN postgresql-hll-2.14_old/include/openssl/asn1t.h postgresql-hll-2.14/include/openssl/asn1t.h --- postgresql-hll-2.14_old/include/openssl/asn1t.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/asn1t.h 2020-12-12 17:06:43.325349045 +0800 @@ -0,0 +1,945 @@ +/* + * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASN1T_H +# define HEADER_ASN1T_H + +# include +# include +# include + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +/* ASN1 template defines, structures and functions */ + +#ifdef __cplusplus +extern "C" { +#endif + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) + +/* Macros for start and end of ASN1_ITEM definition */ + +# define ASN1_ITEM_start(itname) \ + const ASN1_ITEM itname##_it = { + +# define static_ASN1_ITEM_start(itname) \ + static const ASN1_ITEM itname##_it = { + +# define ASN1_ITEM_end(itname) \ + }; + +# else + +/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ +# define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)())) + +/* Macros for start and end of ASN1_ITEM definition */ + +# define ASN1_ITEM_start(itname) \ + const ASN1_ITEM * itname##_it(void) \ + { \ + static const ASN1_ITEM local_it = { + +# define static_ASN1_ITEM_start(itname) \ + static ASN1_ITEM_start(itname) + +# define ASN1_ITEM_end(itname) \ + }; \ + return &local_it; \ + } + +# endif + +/* Macros to aid ASN1 template writing */ + +# define ASN1_ITEM_TEMPLATE(tname) \ + static const ASN1_TEMPLATE tname##_item_tt + +# define ASN1_ITEM_TEMPLATE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE,\ + -1,\ + &tname##_item_tt,\ + 0,\ + NULL,\ + 0,\ + #tname \ + ASN1_ITEM_end(tname) +# define static_ASN1_ITEM_TEMPLATE_END(tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_PRIMITIVE,\ + -1,\ + &tname##_item_tt,\ + 0,\ + NULL,\ + 0,\ + #tname \ + ASN1_ITEM_end(tname) + +/* This is a ASN1 type which just embeds a template */ + +/*- + * This pair helps declare a SEQUENCE. We can do: + * + * ASN1_SEQUENCE(stname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END(stname) + * + * This will produce an ASN1_ITEM called stname_it + * for a structure called stname. + * + * If you want the same structure but a different + * name then use: + * + * ASN1_SEQUENCE(itname) = { + * ... SEQUENCE components ... + * } ASN1_SEQUENCE_END_name(stname, itname) + * + * This will create an item called itname_it using + * a structure called stname. + */ + +# define ASN1_SEQUENCE(tname) \ + static const ASN1_TEMPLATE tname##_seq_tt[] + +# define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) + +# define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) + +# define ASN1_SEQUENCE_END_name(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #tname \ + ASN1_ITEM_end(tname) + +# define static_ASN1_SEQUENCE_END_name(stname, tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_NDEF_SEQUENCE(tname) \ + ASN1_SEQUENCE(tname) + +# define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ + ASN1_SEQUENCE_cb(tname, cb) + +# define ASN1_SEQUENCE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_BROKEN_SEQUENCE(tname) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_SEQUENCE_ref(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_SEQUENCE_enc(tname, enc, cb) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ + ASN1_SEQUENCE(tname) + +# define ASN1_NDEF_SEQUENCE_END(tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(tname),\ + #tname \ + ASN1_ITEM_end(tname) +# define static_ASN1_NDEF_SEQUENCE_END(tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(tname),\ + #tname \ + ASN1_ITEM_end(tname) + +# define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) +# define static_ASN1_BROKEN_SEQUENCE_END(stname) \ + static_ASN1_SEQUENCE_END_ref(stname, stname) + +# define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) + +# define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) +# define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) + +# define ASN1_SEQUENCE_END_ref(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #tname \ + ASN1_ITEM_end(tname) +# define static_ASN1_SEQUENCE_END_ref(stname, tname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_NDEF_SEQUENCE,\ + V_ASN1_SEQUENCE,\ + tname##_seq_tt,\ + sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +/*- + * This pair helps declare a CHOICE type. We can do: + * + * ASN1_CHOICE(chname) = { + * ... CHOICE options ... + * ASN1_CHOICE_END(chname) + * + * This will produce an ASN1_ITEM called chname_it + * for a structure called chname. The structure + * definition must look like this: + * typedef struct { + * int type; + * union { + * ASN1_SOMETHING *opt1; + * ASN1_SOMEOTHER *opt2; + * } value; + * } chname; + * + * the name of the selector must be 'type'. + * to use an alternative selector name use the + * ASN1_CHOICE_END_selector() version. + */ + +# define ASN1_CHOICE(tname) \ + static const ASN1_TEMPLATE tname##_ch_tt[] + +# define ASN1_CHOICE_cb(tname, cb) \ + static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ + ASN1_CHOICE(tname) + +# define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) + +# define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) + +# define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) + +# define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) + +# define ASN1_CHOICE_END_selector(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ + ;\ + static_ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + NULL,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +# define ASN1_CHOICE_END_cb(stname, tname, selname) \ + ;\ + ASN1_ITEM_start(tname) \ + ASN1_ITYPE_CHOICE,\ + offsetof(stname,selname) ,\ + tname##_ch_tt,\ + sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ + &tname##_aux,\ + sizeof(stname),\ + #stname \ + ASN1_ITEM_end(tname) + +/* This helps with the template wrapper form of ASN1_ITEM */ + +# define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ + (flags), (tag), 0,\ + #name, ASN1_ITEM_ref(type) } + +/* These help with SEQUENCE or CHOICE components */ + +/* used to declare other types */ + +# define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ + (flags), (tag), offsetof(stname, field),\ + #field, ASN1_ITEM_ref(type) } + +/* implicit and explicit helper macros */ + +# define ASN1_IMP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type) + +# define ASN1_EXP_EX(stname, field, type, tag, ex) \ + ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type) + +/* Any defined by macros: the field used is in the table itself */ + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } +# else +# define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } +# define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } +# endif +/* Plain simple type */ +# define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) +/* Embedded simple type */ +# define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED,0, stname, field, type) + +/* OPTIONAL simple type */ +# define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) +# define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED, 0, stname, field, type) + +/* IMPLICIT tagged simple type */ +# define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) +# define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) + +/* IMPLICIT tagged OPTIONAL simple type */ +# define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) +# define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) + +/* Same as above but EXPLICIT */ + +# define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) +# define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) +# define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) +# define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) + +/* SEQUENCE OF type */ +# define ASN1_SEQUENCE_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) + +/* OPTIONAL SEQUENCE OF */ +# define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Same as above but for SET OF */ + +# define ASN1_SET_OF(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) + +# define ASN1_SET_OF_OPT(stname, field, type) \ + ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) + +/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ + +# define ASN1_IMP_SET_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +# define ASN1_EXP_SET_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) + +# define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +# define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +# define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) + +# define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) + +/* EXPLICIT using indefinite length constructed form */ +# define ASN1_NDEF_EXP(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) + +/* EXPLICIT OPTIONAL using indefinite length constructed form */ +# define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ + ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) + +/* Macros for the ASN1_ADB structure */ + +# define ASN1_ADB(name) \ + static const ASN1_ADB_TABLE name##_adbtbl[] + +# ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION + +# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ + ;\ + static const ASN1_ADB name##_adb = {\ + flags,\ + offsetof(name, field),\ + adb_cb,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + } + +# else + +# define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ + ;\ + static const ASN1_ITEM *name##_adb(void) \ + { \ + static const ASN1_ADB internal_adb = \ + {\ + flags,\ + offsetof(name, field),\ + adb_cb,\ + name##_adbtbl,\ + sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ + def,\ + none\ + }; \ + return (const ASN1_ITEM *) &internal_adb; \ + } \ + void dummy_function(void) + +# endif + +# define ADB_ENTRY(val, template) {val, template} + +# define ASN1_ADB_TEMPLATE(name) \ + static const ASN1_TEMPLATE name##_tt + +/* + * This is the ASN1 template structure that defines a wrapper round the + * actual type. It determines the actual position of the field in the value + * structure, various flags such as OPTIONAL and the field name. + */ + +struct ASN1_TEMPLATE_st { + unsigned long flags; /* Various flags */ + long tag; /* tag, not used if no tagging */ + unsigned long offset; /* Offset of this field in structure */ + const char *field_name; /* Field name */ + ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ +}; + +/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ + +# define ASN1_TEMPLATE_item(t) (t->item_ptr) +# define ASN1_TEMPLATE_adb(t) (t->item_ptr) + +typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; +typedef struct ASN1_ADB_st ASN1_ADB; + +struct ASN1_ADB_st { + unsigned long flags; /* Various flags */ + unsigned long offset; /* Offset of selector field */ + int (*adb_cb)(long *psel); /* Application callback */ + const ASN1_ADB_TABLE *tbl; /* Table of possible types */ + long tblcount; /* Number of entries in tbl */ + const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ + const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ +}; + +struct ASN1_ADB_TABLE_st { + long value; /* NID for an object or value for an int */ + const ASN1_TEMPLATE tt; /* item for this value */ +}; + +/* template flags */ + +/* Field is optional */ +# define ASN1_TFLG_OPTIONAL (0x1) + +/* Field is a SET OF */ +# define ASN1_TFLG_SET_OF (0x1 << 1) + +/* Field is a SEQUENCE OF */ +# define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) + +/* + * Special case: this refers to a SET OF that will be sorted into DER order + * when encoded *and* the corresponding STACK will be modified to match the + * new order. + */ +# define ASN1_TFLG_SET_ORDER (0x3 << 1) + +/* Mask for SET OF or SEQUENCE OF */ +# define ASN1_TFLG_SK_MASK (0x3 << 1) + +/* + * These flags mean the tag should be taken from the tag field. If EXPLICIT + * then the underlying type is used for the inner tag. + */ + +/* IMPLICIT tagging */ +# define ASN1_TFLG_IMPTAG (0x1 << 3) + +/* EXPLICIT tagging, inner tag from underlying type */ +# define ASN1_TFLG_EXPTAG (0x2 << 3) + +# define ASN1_TFLG_TAG_MASK (0x3 << 3) + +/* context specific IMPLICIT */ +# define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT) + +/* context specific EXPLICIT */ +# define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT) + +/* + * If tagging is in force these determine the type of tag to use. Otherwise + * the tag is determined by the underlying type. These values reflect the + * actual octet format. + */ + +/* Universal tag */ +# define ASN1_TFLG_UNIVERSAL (0x0<<6) +/* Application tag */ +# define ASN1_TFLG_APPLICATION (0x1<<6) +/* Context specific tag */ +# define ASN1_TFLG_CONTEXT (0x2<<6) +/* Private tag */ +# define ASN1_TFLG_PRIVATE (0x3<<6) + +# define ASN1_TFLG_TAG_CLASS (0x3<<6) + +/* + * These are for ANY DEFINED BY type. In this case the 'item' field points to + * an ASN1_ADB structure which contains a table of values to decode the + * relevant type + */ + +# define ASN1_TFLG_ADB_MASK (0x3<<8) + +# define ASN1_TFLG_ADB_OID (0x1<<8) + +# define ASN1_TFLG_ADB_INT (0x1<<9) + +/* + * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes + * indefinite length constructed encoding to be used if required. + */ + +# define ASN1_TFLG_NDEF (0x1<<11) + +/* Field is embedded and not a pointer */ +# define ASN1_TFLG_EMBED (0x1 << 12) + +/* This is the actual ASN1 item itself */ + +struct ASN1_ITEM_st { + char itype; /* The item type, primitive, SEQUENCE, CHOICE + * or extern */ + long utype; /* underlying type */ + const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains + * the contents */ + long tcount; /* Number of templates if SEQUENCE or CHOICE */ + const void *funcs; /* functions that handle this type */ + long size; /* Structure size (usually) */ + const char *sname; /* Structure name */ +}; + +/*- + * These are values for the itype field and + * determine how the type is interpreted. + * + * For PRIMITIVE types the underlying type + * determines the behaviour if items is NULL. + * + * Otherwise templates must contain a single + * template and the type is treated in the + * same way as the type specified in the template. + * + * For SEQUENCE types the templates field points + * to the members, the size field is the + * structure size. + * + * For CHOICE types the templates field points + * to each possible member (typically a union) + * and the 'size' field is the offset of the + * selector. + * + * The 'funcs' field is used for application + * specific functions. + * + * The EXTERN type uses a new style d2i/i2d. + * The new style should be used where possible + * because it avoids things like the d2i IMPLICIT + * hack. + * + * MSTRING is a multiple string type, it is used + * for a CHOICE of character strings where the + * actual strings all occupy an ASN1_STRING + * structure. In this case the 'utype' field + * has a special meaning, it is used as a mask + * of acceptable types using the B_ASN1 constants. + * + * NDEF_SEQUENCE is the same as SEQUENCE except + * that it will use indefinite length constructed + * encoding if requested. + * + */ + +# define ASN1_ITYPE_PRIMITIVE 0x0 + +# define ASN1_ITYPE_SEQUENCE 0x1 + +# define ASN1_ITYPE_CHOICE 0x2 + +# define ASN1_ITYPE_EXTERN 0x4 + +# define ASN1_ITYPE_MSTRING 0x5 + +# define ASN1_ITYPE_NDEF_SEQUENCE 0x6 + +/* + * Cache for ASN1 tag and length, so we don't keep re-reading it for things + * like CHOICE + */ + +struct ASN1_TLC_st { + char valid; /* Values below are valid */ + int ret; /* return value */ + long plen; /* length */ + int ptag; /* class value */ + int pclass; /* class value */ + int hdrlen; /* header length */ +}; + +/* Typedefs for ASN1 function pointers */ +typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); + +typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass); +typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); +typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); + +typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, + int indent, const char *fname, + const ASN1_PCTX *pctx); + +typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, + int *putype, const ASN1_ITEM *it); +typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, + int len, int utype, char *free_cont, + const ASN1_ITEM *it); +typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, + const ASN1_ITEM *it, int indent, + const ASN1_PCTX *pctx); + +typedef struct ASN1_EXTERN_FUNCS_st { + void *app_data; + ASN1_ex_new_func *asn1_ex_new; + ASN1_ex_free_func *asn1_ex_free; + ASN1_ex_free_func *asn1_ex_clear; + ASN1_ex_d2i *asn1_ex_d2i; + ASN1_ex_i2d *asn1_ex_i2d; + ASN1_ex_print_func *asn1_ex_print; +} ASN1_EXTERN_FUNCS; + +typedef struct ASN1_PRIMITIVE_FUNCS_st { + void *app_data; + unsigned long flags; + ASN1_ex_new_func *prim_new; + ASN1_ex_free_func *prim_free; + ASN1_ex_free_func *prim_clear; + ASN1_primitive_c2i *prim_c2i; + ASN1_primitive_i2c *prim_i2c; + ASN1_primitive_print *prim_print; +} ASN1_PRIMITIVE_FUNCS; + +/* + * This is the ASN1_AUX structure: it handles various miscellaneous + * requirements. For example the use of reference counts and an informational + * callback. The "informational callback" is called at various points during + * the ASN1 encoding and decoding. It can be used to provide minor + * customisation of the structures used. This is most useful where the + * supplied routines *almost* do the right thing but need some extra help at + * a few points. If the callback returns zero then it is assumed a fatal + * error has occurred and the main operation should be abandoned. If major + * changes in the default behaviour are required then an external type is + * more appropriate. + */ + +typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, + void *exarg); + +typedef struct ASN1_AUX_st { + void *app_data; + int flags; + int ref_offset; /* Offset of reference value */ + int ref_lock; /* Lock type to use */ + ASN1_aux_cb *asn1_cb; + int enc_offset; /* Offset of ASN1_ENCODING structure */ +} ASN1_AUX; + +/* For print related callbacks exarg points to this structure */ +typedef struct ASN1_PRINT_ARG_st { + BIO *out; + int indent; + const ASN1_PCTX *pctx; +} ASN1_PRINT_ARG; + +/* For streaming related callbacks exarg points to this structure */ +typedef struct ASN1_STREAM_ARG_st { + /* BIO to stream through */ + BIO *out; + /* BIO with filters appended */ + BIO *ndef_bio; + /* Streaming I/O boundary */ + unsigned char **boundary; +} ASN1_STREAM_ARG; + +/* Flags in ASN1_AUX */ + +/* Use a reference count */ +# define ASN1_AFLG_REFCOUNT 1 +/* Save the encoding of structure (useful for signatures) */ +# define ASN1_AFLG_ENCODING 2 +/* The Sequence length is invalid */ +# define ASN1_AFLG_BROKEN 4 + +/* operation values for asn1_cb */ + +# define ASN1_OP_NEW_PRE 0 +# define ASN1_OP_NEW_POST 1 +# define ASN1_OP_FREE_PRE 2 +# define ASN1_OP_FREE_POST 3 +# define ASN1_OP_D2I_PRE 4 +# define ASN1_OP_D2I_POST 5 +# define ASN1_OP_I2D_PRE 6 +# define ASN1_OP_I2D_POST 7 +# define ASN1_OP_PRINT_PRE 8 +# define ASN1_OP_PRINT_POST 9 +# define ASN1_OP_STREAM_PRE 10 +# define ASN1_OP_STREAM_POST 11 +# define ASN1_OP_DETACHED_PRE 12 +# define ASN1_OP_DETACHED_POST 13 + +/* Macro to implement a primitive type */ +# define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) +# define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ + ASN1_ITEM_end(itname) + +/* Macro to implement a multi string type */ +# define IMPLEMENT_ASN1_MSTRING(itname, mask) \ + ASN1_ITEM_start(itname) \ + ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ + ASN1_ITEM_end(itname) + +# define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ + ASN1_ITEM_start(sname) \ + ASN1_ITYPE_EXTERN, \ + tag, \ + NULL, \ + 0, \ + &fptrs, \ + 0, \ + #sname \ + ASN1_ITEM_end(sname) + +/* Macro to implement standard functions in terms of ASN1_ITEM structures */ + +# define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) + +# define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ + IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) + +# define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ + pre stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + pre void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } + +# define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ + stname *fname##_new(void) \ + { \ + return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ + } \ + void fname##_free(stname *a) \ + { \ + ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ + } + +# define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +# define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ + int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ + { \ + return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ + } + +# define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \ + static stname *d2i_##stname(stname **a, \ + const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \ + ASN1_ITEM_rptr(stname)); \ + } \ + static int i2d_##stname(stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, \ + ASN1_ITEM_rptr(stname)); \ + } + +/* + * This includes evil casts to remove const: they will go away when full ASN1 + * constification is done. + */ +# define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ + { \ + return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ + } \ + int i2d_##fname(const stname *a, unsigned char **out) \ + { \ + return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ + } + +# define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ + stname * stname##_dup(stname *x) \ + { \ + return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ + } + +# define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ + IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) + +# define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ + int fname##_print_ctx(BIO *out, stname *x, int indent, \ + const ASN1_PCTX *pctx) \ + { \ + return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \ + ASN1_ITEM_rptr(itname), pctx); \ + } + +# define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ + IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) + +# define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ + IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) + +/* external definitions for primitive types */ + +DECLARE_ASN1_ITEM(ASN1_BOOLEAN) +DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_SEQUENCE) +DECLARE_ASN1_ITEM(CBIGNUM) +DECLARE_ASN1_ITEM(BIGNUM) +DECLARE_ASN1_ITEM(INT32) +DECLARE_ASN1_ITEM(ZINT32) +DECLARE_ASN1_ITEM(UINT32) +DECLARE_ASN1_ITEM(ZUINT32) +DECLARE_ASN1_ITEM(INT64) +DECLARE_ASN1_ITEM(ZINT64) +DECLARE_ASN1_ITEM(UINT64) +DECLARE_ASN1_ITEM(ZUINT64) + +# if OPENSSL_API_COMPAT < 0x10200000L +/* + * LONG and ZLONG are strongly discouraged for use as stored data, as the + * underlying C type (long) differs in size depending on the architecture. + * They are designed with 32-bit longs in mind. + */ +DECLARE_ASN1_ITEM(LONG) +DECLARE_ASN1_ITEM(ZLONG) +# endif + +DEFINE_STACK_OF(ASN1_VALUE) + +/* Functions used internally by the ASN1 code */ + +int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); +void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); + +int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, + const ASN1_ITEM *it, int tag, int aclass, char opt, + ASN1_TLC *ctx); + +int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass); + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/asyncerr.h postgresql-hll-2.14/include/openssl/asyncerr.h --- postgresql-hll-2.14_old/include/openssl/asyncerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/asyncerr.h 2020-12-12 17:06:43.326349058 +0800 @@ -0,0 +1,42 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ASYNCERR_H +# define HEADER_ASYNCERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_ASYNC_strings(void); + +/* + * ASYNC function codes. + */ +# define ASYNC_F_ASYNC_CTX_NEW 100 +# define ASYNC_F_ASYNC_INIT_THREAD 101 +# define ASYNC_F_ASYNC_JOB_NEW 102 +# define ASYNC_F_ASYNC_PAUSE_JOB 103 +# define ASYNC_F_ASYNC_START_FUNC 104 +# define ASYNC_F_ASYNC_START_JOB 105 +# define ASYNC_F_ASYNC_WAIT_CTX_SET_WAIT_FD 106 + +/* + * ASYNC reason codes. + */ +# define ASYNC_R_FAILED_TO_SET_POOL 101 +# define ASYNC_R_FAILED_TO_SWAP_CONTEXT 102 +# define ASYNC_R_INIT_FAILED 105 +# define ASYNC_R_INVALID_POOL_SIZE 103 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/async.h postgresql-hll-2.14/include/openssl/async.h --- postgresql-hll-2.14_old/include/openssl/async.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/async.h 2020-12-12 17:06:43.326349058 +0800 @@ -0,0 +1,76 @@ +/* + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifndef HEADER_ASYNC_H +# define HEADER_ASYNC_H + +#if defined(_WIN32) +# if defined(BASETYPES) || defined(_WINDEF_H) +/* application has to include to use this */ +#define OSSL_ASYNC_FD HANDLE +#define OSSL_BAD_ASYNC_FD INVALID_HANDLE_VALUE +# endif +#else +#define OSSL_ASYNC_FD int +#define OSSL_BAD_ASYNC_FD -1 +#endif +# include + + +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct async_job_st ASYNC_JOB; +typedef struct async_wait_ctx_st ASYNC_WAIT_CTX; + +#define ASYNC_ERR 0 +#define ASYNC_NO_JOBS 1 +#define ASYNC_PAUSE 2 +#define ASYNC_FINISH 3 + +int ASYNC_init_thread(size_t max_size, size_t init_size); +void ASYNC_cleanup_thread(void); + +#ifdef OSSL_ASYNC_FD +ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void); +void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx); +int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key, + OSSL_ASYNC_FD fd, + void *custom_data, + void (*cleanup)(ASYNC_WAIT_CTX *, const void *, + OSSL_ASYNC_FD, void *)); +int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key, + OSSL_ASYNC_FD *fd, void **custom_data); +int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd, + size_t *numfds); +int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd, + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds); +int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key); +#endif + +int ASYNC_is_capable(void); + +int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret, + int (*func)(void *), void *args, size_t size); +int ASYNC_pause_job(void); + +ASYNC_JOB *ASYNC_get_current_job(void); +ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job); +void ASYNC_block_pause(void); +void ASYNC_unblock_pause(void); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/bioerr.h postgresql-hll-2.14/include/openssl/bioerr.h --- postgresql-hll-2.14_old/include/openssl/bioerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/bioerr.h 2020-12-12 17:06:43.326349058 +0800 @@ -0,0 +1,124 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BIOERR_H +# define HEADER_BIOERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_BIO_strings(void); + +/* + * BIO function codes. + */ +# define BIO_F_ACPT_STATE 100 +# define BIO_F_ADDRINFO_WRAP 148 +# define BIO_F_ADDR_STRINGS 134 +# define BIO_F_BIO_ACCEPT 101 +# define BIO_F_BIO_ACCEPT_EX 137 +# define BIO_F_BIO_ACCEPT_NEW 152 +# define BIO_F_BIO_ADDR_NEW 144 +# define BIO_F_BIO_BIND 147 +# define BIO_F_BIO_CALLBACK_CTRL 131 +# define BIO_F_BIO_CONNECT 138 +# define BIO_F_BIO_CONNECT_NEW 153 +# define BIO_F_BIO_CTRL 103 +# define BIO_F_BIO_GETS 104 +# define BIO_F_BIO_GET_HOST_IP 106 +# define BIO_F_BIO_GET_NEW_INDEX 102 +# define BIO_F_BIO_GET_PORT 107 +# define BIO_F_BIO_LISTEN 139 +# define BIO_F_BIO_LOOKUP 135 +# define BIO_F_BIO_LOOKUP_EX 143 +# define BIO_F_BIO_MAKE_PAIR 121 +# define BIO_F_BIO_METH_NEW 146 +# define BIO_F_BIO_NEW 108 +# define BIO_F_BIO_NEW_DGRAM_SCTP 145 +# define BIO_F_BIO_NEW_FILE 109 +# define BIO_F_BIO_NEW_MEM_BUF 126 +# define BIO_F_BIO_NREAD 123 +# define BIO_F_BIO_NREAD0 124 +# define BIO_F_BIO_NWRITE 125 +# define BIO_F_BIO_NWRITE0 122 +# define BIO_F_BIO_PARSE_HOSTSERV 136 +# define BIO_F_BIO_PUTS 110 +# define BIO_F_BIO_READ 111 +# define BIO_F_BIO_READ_EX 105 +# define BIO_F_BIO_READ_INTERN 120 +# define BIO_F_BIO_SOCKET 140 +# define BIO_F_BIO_SOCKET_NBIO 142 +# define BIO_F_BIO_SOCK_INFO 141 +# define BIO_F_BIO_SOCK_INIT 112 +# define BIO_F_BIO_WRITE 113 +# define BIO_F_BIO_WRITE_EX 119 +# define BIO_F_BIO_WRITE_INTERN 128 +# define BIO_F_BUFFER_CTRL 114 +# define BIO_F_CONN_CTRL 127 +# define BIO_F_CONN_STATE 115 +# define BIO_F_DGRAM_SCTP_NEW 149 +# define BIO_F_DGRAM_SCTP_READ 132 +# define BIO_F_DGRAM_SCTP_WRITE 133 +# define BIO_F_DOAPR_OUTCH 150 +# define BIO_F_FILE_CTRL 116 +# define BIO_F_FILE_READ 130 +# define BIO_F_LINEBUFFER_CTRL 129 +# define BIO_F_LINEBUFFER_NEW 151 +# define BIO_F_MEM_WRITE 117 +# define BIO_F_NBIOF_NEW 154 +# define BIO_F_SLG_WRITE 155 +# define BIO_F_SSL_NEW 118 + +/* + * BIO reason codes. + */ +# define BIO_R_ACCEPT_ERROR 100 +# define BIO_R_ADDRINFO_ADDR_IS_NOT_AF_INET 141 +# define BIO_R_AMBIGUOUS_HOST_OR_SERVICE 129 +# define BIO_R_BAD_FOPEN_MODE 101 +# define BIO_R_BROKEN_PIPE 124 +# define BIO_R_CONNECT_ERROR 103 +# define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 +# define BIO_R_GETSOCKNAME_ERROR 132 +# define BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS 133 +# define BIO_R_GETTING_SOCKTYPE 134 +# define BIO_R_INVALID_ARGUMENT 125 +# define BIO_R_INVALID_SOCKET 135 +# define BIO_R_IN_USE 123 +# define BIO_R_LENGTH_TOO_LONG 102 +# define BIO_R_LISTEN_V6_ONLY 136 +# define BIO_R_LOOKUP_RETURNED_NOTHING 142 +# define BIO_R_MALFORMED_HOST_OR_SERVICE 130 +# define BIO_R_NBIO_CONNECT_ERROR 110 +# define BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED 143 +# define BIO_R_NO_HOSTNAME_OR_SERVICE_SPECIFIED 144 +# define BIO_R_NO_PORT_DEFINED 113 +# define BIO_R_NO_SUCH_FILE 128 +# define BIO_R_NULL_PARAMETER 115 +# define BIO_R_UNABLE_TO_BIND_SOCKET 117 +# define BIO_R_UNABLE_TO_CREATE_SOCKET 118 +# define BIO_R_UNABLE_TO_KEEPALIVE 137 +# define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 +# define BIO_R_UNABLE_TO_NODELAY 138 +# define BIO_R_UNABLE_TO_REUSEADDR 139 +# define BIO_R_UNAVAILABLE_IP_FAMILY 145 +# define BIO_R_UNINITIALIZED 120 +# define BIO_R_UNKNOWN_INFO_TYPE 140 +# define BIO_R_UNSUPPORTED_IP_FAMILY 146 +# define BIO_R_UNSUPPORTED_METHOD 121 +# define BIO_R_UNSUPPORTED_PROTOCOL_FAMILY 131 +# define BIO_R_WRITE_TO_READ_ONLY_BIO 126 +# define BIO_R_WSASTARTUP 122 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/bio.h postgresql-hll-2.14/include/openssl/bio.h --- postgresql-hll-2.14_old/include/openssl/bio.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/bio.h 2020-12-12 17:06:43.326349058 +0800 @@ -0,0 +1,801 @@ +/* + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BIO_H +# define HEADER_BIO_H + +# include + +# ifndef OPENSSL_NO_STDIO +# include +# endif +# include + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* There are the classes of BIOs */ +# define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ +# define BIO_TYPE_FILTER 0x0200 +# define BIO_TYPE_SOURCE_SINK 0x0400 + +/* These are the 'types' of BIOs */ +# define BIO_TYPE_NONE 0 +# define BIO_TYPE_MEM ( 1|BIO_TYPE_SOURCE_SINK) +# define BIO_TYPE_FILE ( 2|BIO_TYPE_SOURCE_SINK) + +# define BIO_TYPE_FD ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_SOCKET ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_NULL ( 6|BIO_TYPE_SOURCE_SINK) +# define BIO_TYPE_SSL ( 7|BIO_TYPE_FILTER) +# define BIO_TYPE_MD ( 8|BIO_TYPE_FILTER) +# define BIO_TYPE_BUFFER ( 9|BIO_TYPE_FILTER) +# define BIO_TYPE_CIPHER (10|BIO_TYPE_FILTER) +# define BIO_TYPE_BASE64 (11|BIO_TYPE_FILTER) +# define BIO_TYPE_CONNECT (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_ACCEPT (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) + +# define BIO_TYPE_NBIO_TEST (16|BIO_TYPE_FILTER)/* server proxy BIO */ +# define BIO_TYPE_NULL_FILTER (17|BIO_TYPE_FILTER) +# define BIO_TYPE_BIO (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */ +# define BIO_TYPE_LINEBUFFER (20|BIO_TYPE_FILTER) +# define BIO_TYPE_DGRAM (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# define BIO_TYPE_ASN1 (22|BIO_TYPE_FILTER) +# define BIO_TYPE_COMP (23|BIO_TYPE_FILTER) +# ifndef OPENSSL_NO_SCTP +# define BIO_TYPE_DGRAM_SCTP (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR) +# endif + +#define BIO_TYPE_START 128 + +/* + * BIO_FILENAME_READ|BIO_CLOSE to open or close on free. + * BIO_set_fp(in,stdin,BIO_NOCLOSE); + */ +# define BIO_NOCLOSE 0x00 +# define BIO_CLOSE 0x01 + +/* + * These are used in the following macros and are passed to BIO_ctrl() + */ +# define BIO_CTRL_RESET 1/* opt - rewind/zero etc */ +# define BIO_CTRL_EOF 2/* opt - are we at the eof */ +# define BIO_CTRL_INFO 3/* opt - extra tit-bits */ +# define BIO_CTRL_SET 4/* man - set the 'IO' type */ +# define BIO_CTRL_GET 5/* man - get the 'IO' type */ +# define BIO_CTRL_PUSH 6/* opt - internal, used to signify change */ +# define BIO_CTRL_POP 7/* opt - internal, used to signify change */ +# define BIO_CTRL_GET_CLOSE 8/* man - set the 'close' on free */ +# define BIO_CTRL_SET_CLOSE 9/* man - set the 'close' on free */ +# define BIO_CTRL_PENDING 10/* opt - is their more data buffered */ +# define BIO_CTRL_FLUSH 11/* opt - 'flush' buffered output */ +# define BIO_CTRL_DUP 12/* man - extra stuff for 'duped' BIO */ +# define BIO_CTRL_WPENDING 13/* opt - number of bytes still to write */ +# define BIO_CTRL_SET_CALLBACK 14/* opt - set callback function */ +# define BIO_CTRL_GET_CALLBACK 15/* opt - set callback function */ + +# define BIO_CTRL_PEEK 29/* BIO_f_buffer special */ +# define BIO_CTRL_SET_FILENAME 30/* BIO_s_file special */ + +/* dgram BIO stuff */ +# define BIO_CTRL_DGRAM_CONNECT 31/* BIO dgram special */ +# define BIO_CTRL_DGRAM_SET_CONNECTED 32/* allow for an externally connected + * socket to be passed in */ +# define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33/* setsockopt, essentially */ +# define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34/* getsockopt, essentially */ +# define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35/* setsockopt, essentially */ +# define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36/* getsockopt, essentially */ + +# define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37/* flag whether the last */ +# define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38/* I/O operation tiemd out */ + +/* #ifdef IP_MTU_DISCOVER */ +# define BIO_CTRL_DGRAM_MTU_DISCOVER 39/* set DF bit on egress packets */ +/* #endif */ + +# define BIO_CTRL_DGRAM_QUERY_MTU 40/* as kernel for current MTU */ +# define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 +# define BIO_CTRL_DGRAM_GET_MTU 41/* get cached value for MTU */ +# define BIO_CTRL_DGRAM_SET_MTU 42/* set cached value for MTU. + * want to use this if asking + * the kernel fails */ + +# define BIO_CTRL_DGRAM_MTU_EXCEEDED 43/* check whether the MTU was + * exceed in the previous write + * operation */ + +# define BIO_CTRL_DGRAM_GET_PEER 46 +# define BIO_CTRL_DGRAM_SET_PEER 44/* Destination for the data */ + +# define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45/* Next DTLS handshake timeout + * to adjust socket timeouts */ +# define BIO_CTRL_DGRAM_SET_DONT_FRAG 48 + +# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49 + +/* Deliberately outside of OPENSSL_NO_SCTP - used in bss_dgram.c */ +# define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 +# ifndef OPENSSL_NO_SCTP +/* SCTP stuff */ +# define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51 +# define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52 +# define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53 +# define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60 +# define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61 +# define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62 +# define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63 +# define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64 +# define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65 +# define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70 +# endif + +# define BIO_CTRL_DGRAM_SET_PEEK_MODE 71 + +/* modifiers */ +# define BIO_FP_READ 0x02 +# define BIO_FP_WRITE 0x04 +# define BIO_FP_APPEND 0x08 +# define BIO_FP_TEXT 0x10 + +# define BIO_FLAGS_READ 0x01 +# define BIO_FLAGS_WRITE 0x02 +# define BIO_FLAGS_IO_SPECIAL 0x04 +# define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) +# define BIO_FLAGS_SHOULD_RETRY 0x08 +# ifndef BIO_FLAGS_UPLINK +/* + * "UPLINK" flag denotes file descriptors provided by application. It + * defaults to 0, as most platforms don't require UPLINK interface. + */ +# define BIO_FLAGS_UPLINK 0 +# endif + +# define BIO_FLAGS_BASE64_NO_NL 0x100 + +/* + * This is used with memory BIOs: + * BIO_FLAGS_MEM_RDONLY means we shouldn't free up or change the data in any way; + * BIO_FLAGS_NONCLEAR_RST means we shouldn't clear data on reset. + */ +# define BIO_FLAGS_MEM_RDONLY 0x200 +# define BIO_FLAGS_NONCLEAR_RST 0x400 +# define BIO_FLAGS_IN_EOF 0x800 + +typedef union bio_addr_st BIO_ADDR; +typedef struct bio_addrinfo_st BIO_ADDRINFO; + +int BIO_get_new_index(void); +void BIO_set_flags(BIO *b, int flags); +int BIO_test_flags(const BIO *b, int flags); +void BIO_clear_flags(BIO *b, int flags); + +# define BIO_get_flags(b) BIO_test_flags(b, ~(0x0)) +# define BIO_set_retry_special(b) \ + BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_set_retry_read(b) \ + BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_set_retry_write(b) \ + BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) + +/* These are normally used internally in BIOs */ +# define BIO_clear_retry_flags(b) \ + BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) +# define BIO_get_retry_flags(b) \ + BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) + +/* These should be used by the application to tell why we should retry */ +# define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) +# define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) +# define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) +# define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) +# define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) + +/* + * The next three are used in conjunction with the BIO_should_io_special() + * condition. After this returns true, BIO *BIO_get_retry_BIO(BIO *bio, int + * *reason); will walk the BIO stack and return the 'reason' for the special + * and the offending BIO. Given a BIO, BIO_get_retry_reason(bio) will return + * the code. + */ +/* + * Returned from the SSL bio when the certificate retrieval code had an error + */ +# define BIO_RR_SSL_X509_LOOKUP 0x01 +/* Returned from the connect BIO when a connect would have blocked */ +# define BIO_RR_CONNECT 0x02 +/* Returned from the accept BIO when an accept would have blocked */ +# define BIO_RR_ACCEPT 0x03 + +/* These are passed by the BIO callback */ +# define BIO_CB_FREE 0x01 +# define BIO_CB_READ 0x02 +# define BIO_CB_WRITE 0x03 +# define BIO_CB_PUTS 0x04 +# define BIO_CB_GETS 0x05 +# define BIO_CB_CTRL 0x06 + +/* + * The callback is called before and after the underling operation, The + * BIO_CB_RETURN flag indicates if it is after the call + */ +# define BIO_CB_RETURN 0x80 +# define BIO_CB_return(a) ((a)|BIO_CB_RETURN) +# define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) +# define BIO_cb_post(a) ((a)&BIO_CB_RETURN) + +typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi, + long argl, long ret); +typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp, + size_t len, int argi, + long argl, int ret, size_t *processed); +BIO_callback_fn BIO_get_callback(const BIO *b); +void BIO_set_callback(BIO *b, BIO_callback_fn callback); + +BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b); +void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback); + +char *BIO_get_callback_arg(const BIO *b); +void BIO_set_callback_arg(BIO *b, char *arg); + +typedef struct bio_method_st BIO_METHOD; + +const char *BIO_method_name(const BIO *b); +int BIO_method_type(const BIO *b); + +typedef int BIO_info_cb(BIO *, int, int); +typedef BIO_info_cb bio_info_cb; /* backward compatibility */ + +DEFINE_STACK_OF(BIO) + +/* Prefix and suffix callback in ASN1 BIO */ +typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen, + void *parg); + +# ifndef OPENSSL_NO_SCTP +/* SCTP parameter structs */ +struct bio_dgram_sctp_sndinfo { + uint16_t snd_sid; + uint16_t snd_flags; + uint32_t snd_ppid; + uint32_t snd_context; +}; + +struct bio_dgram_sctp_rcvinfo { + uint16_t rcv_sid; + uint16_t rcv_ssn; + uint16_t rcv_flags; + uint32_t rcv_ppid; + uint32_t rcv_tsn; + uint32_t rcv_cumtsn; + uint32_t rcv_context; +}; + +struct bio_dgram_sctp_prinfo { + uint16_t pr_policy; + uint32_t pr_value; +}; +# endif + +/* + * #define BIO_CONN_get_param_hostname BIO_ctrl + */ + +# define BIO_C_SET_CONNECT 100 +# define BIO_C_DO_STATE_MACHINE 101 +# define BIO_C_SET_NBIO 102 +/* # define BIO_C_SET_PROXY_PARAM 103 */ +# define BIO_C_SET_FD 104 +# define BIO_C_GET_FD 105 +# define BIO_C_SET_FILE_PTR 106 +# define BIO_C_GET_FILE_PTR 107 +# define BIO_C_SET_FILENAME 108 +# define BIO_C_SET_SSL 109 +# define BIO_C_GET_SSL 110 +# define BIO_C_SET_MD 111 +# define BIO_C_GET_MD 112 +# define BIO_C_GET_CIPHER_STATUS 113 +# define BIO_C_SET_BUF_MEM 114 +# define BIO_C_GET_BUF_MEM_PTR 115 +# define BIO_C_GET_BUFF_NUM_LINES 116 +# define BIO_C_SET_BUFF_SIZE 117 +# define BIO_C_SET_ACCEPT 118 +# define BIO_C_SSL_MODE 119 +# define BIO_C_GET_MD_CTX 120 +/* # define BIO_C_GET_PROXY_PARAM 121 */ +# define BIO_C_SET_BUFF_READ_DATA 122/* data to read first */ +# define BIO_C_GET_CONNECT 123 +# define BIO_C_GET_ACCEPT 124 +# define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 +# define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 +# define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +# define BIO_C_FILE_SEEK 128 +# define BIO_C_GET_CIPHER_CTX 129 +# define BIO_C_SET_BUF_MEM_EOF_RETURN 130/* return end of input + * value */ +# define BIO_C_SET_BIND_MODE 131 +# define BIO_C_GET_BIND_MODE 132 +# define BIO_C_FILE_TELL 133 +# define BIO_C_GET_SOCKS 134 +# define BIO_C_SET_SOCKS 135 + +# define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ +# define BIO_C_GET_WRITE_BUF_SIZE 137 +# define BIO_C_MAKE_BIO_PAIR 138 +# define BIO_C_DESTROY_BIO_PAIR 139 +# define BIO_C_GET_WRITE_GUARANTEE 140 +# define BIO_C_GET_READ_REQUEST 141 +# define BIO_C_SHUTDOWN_WR 142 +# define BIO_C_NREAD0 143 +# define BIO_C_NREAD 144 +# define BIO_C_NWRITE0 145 +# define BIO_C_NWRITE 146 +# define BIO_C_RESET_READ_REQUEST 147 +# define BIO_C_SET_MD_CTX 148 + +# define BIO_C_SET_PREFIX 149 +# define BIO_C_GET_PREFIX 150 +# define BIO_C_SET_SUFFIX 151 +# define BIO_C_GET_SUFFIX 152 + +# define BIO_C_SET_EX_ARG 153 +# define BIO_C_GET_EX_ARG 154 + +# define BIO_C_SET_CONNECT_MODE 155 + +# define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) +# define BIO_get_app_data(s) BIO_get_ex_data(s,0) + +# define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) + +# ifndef OPENSSL_NO_SOCK +/* IP families we support, for BIO_s_connect() and BIO_s_accept() */ +/* Note: the underlying operating system may not support some of them */ +# define BIO_FAMILY_IPV4 4 +# define BIO_FAMILY_IPV6 6 +# define BIO_FAMILY_IPANY 256 + +/* BIO_s_connect() */ +# define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0, \ + (char *)(name)) +# define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1, \ + (char *)(port)) +# define BIO_set_conn_address(b,addr) BIO_ctrl(b,BIO_C_SET_CONNECT,2, \ + (char *)(addr)) +# define BIO_set_conn_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f) +# define BIO_get_conn_hostname(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)) +# define BIO_get_conn_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)) +# define BIO_get_conn_address(b) ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)) +# define BIO_get_conn_ip_family(b) BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL) +# define BIO_set_conn_mode(b,n) BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL) + +/* BIO_s_accept() */ +# define BIO_set_accept_name(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0, \ + (char *)(name)) +# define BIO_set_accept_port(b,port) BIO_ctrl(b,BIO_C_SET_ACCEPT,1, \ + (char *)(port)) +# define BIO_get_accept_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)) +# define BIO_get_accept_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1)) +# define BIO_get_peer_name(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2)) +# define BIO_get_peer_port(b) ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3)) +/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ +# define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL) +# define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,3, \ + (char *)(bio)) +# define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f) +# define BIO_get_accept_ip_family(b) BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL) + +/* Aliases kept for backward compatibility */ +# define BIO_BIND_NORMAL 0 +# define BIO_BIND_REUSEADDR BIO_SOCK_REUSEADDR +# define BIO_BIND_REUSEADDR_IF_UNUSED BIO_SOCK_REUSEADDR +# define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +# define BIO_get_bind_mode(b) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + +/* BIO_s_accept() and BIO_s_connect() */ +# define BIO_do_connect(b) BIO_do_handshake(b) +# define BIO_do_accept(b) BIO_do_handshake(b) +# endif /* OPENSSL_NO_SOCK */ + +# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) + +/* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */ +# define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) +# define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)(c)) + +/* BIO_s_file() */ +# define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)(fp)) +# define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)(fpp)) + +/* BIO_s_fd() and BIO_s_file() */ +# define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +# define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + +/* + * name is cast to lose const, but might be better to route through a + * function so we can do it safely + */ +# ifdef CONST_STRICT +/* + * If you are wondering why this isn't defined, its because CONST_STRICT is + * purely a compile-time kludge to allow const to be checked. + */ +int BIO_read_filename(BIO *b, const char *name); +# else +# define BIO_read_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ,(char *)(name)) +# endif +# define BIO_write_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_WRITE,name) +# define BIO_append_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_APPEND,name) +# define BIO_rw_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) + +/* + * WARNING WARNING, this ups the reference count on the read bio of the SSL + * structure. This is because the ssl read BIO is now pointed to by the + * next_bio field in the bio. So when you free the BIO, make sure you are + * doing a BIO_free_all() to catch the underlying BIO. + */ +# define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)(ssl)) +# define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)(sslp)) +# define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) +# define BIO_set_ssl_renegotiate_bytes(b,num) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL) +# define BIO_get_num_renegotiates(b) \ + BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL) +# define BIO_set_ssl_renegotiate_timeout(b,seconds) \ + BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL) + +/* defined in evp.h */ +/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)(md)) */ + +# define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)(pp)) +# define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)(bm)) +# define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0, \ + (char *)(pp)) +# define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) + +/* For the BIO_f_buffer() type */ +# define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) +# define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) +# define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) +# define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) +# define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) + +/* Don't use the next one unless you know what you are doing :-) */ +# define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) + +# define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) +# define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) +# define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) +# define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) +# define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) +# define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +/* ...pending macros have inappropriate return type */ +size_t BIO_ctrl_pending(BIO *b); +size_t BIO_ctrl_wpending(BIO *b); +# define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) +# define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \ + cbp) +# define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb) + +/* For the BIO_f_buffer() type */ +# define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) +# define BIO_buffer_peek(b,s,l) BIO_ctrl(b,BIO_CTRL_PEEK,(l),(s)) + +/* For BIO_s_bio() */ +# define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) +# define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) +# define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) +# define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) +# define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) +/* macros with inappropriate type -- but ...pending macros use int too: */ +# define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) +# define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +size_t BIO_ctrl_get_write_guarantee(BIO *b); +size_t BIO_ctrl_get_read_request(BIO *b); +int BIO_ctrl_reset_read_request(BIO *b); + +/* ctrl macros for dgram */ +# define BIO_ctrl_dgram_connect(b,peer) \ + (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)(peer)) +# define BIO_ctrl_set_connected(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)(peer)) +# define BIO_dgram_recv_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL) +# define BIO_dgram_send_timedout(b) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL) +# define BIO_dgram_get_peer(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)(peer)) +# define BIO_dgram_set_peer(b,peer) \ + (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)(peer)) +# define BIO_dgram_get_mtu_overhead(b) \ + (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL) + +#define BIO_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, l, p, newf, dupf, freef) +int BIO_set_ex_data(BIO *bio, int idx, void *data); +void *BIO_get_ex_data(BIO *bio, int idx); +uint64_t BIO_number_read(BIO *bio); +uint64_t BIO_number_written(BIO *bio); + +/* For BIO_f_asn1() */ +int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, + asn1_ps_func *prefix_free); +int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, + asn1_ps_func **pprefix_free); +int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, + asn1_ps_func *suffix_free); +int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, + asn1_ps_func **psuffix_free); + +const BIO_METHOD *BIO_s_file(void); +BIO *BIO_new_file(const char *filename, const char *mode); +# ifndef OPENSSL_NO_STDIO +BIO *BIO_new_fp(FILE *stream, int close_flag); +# endif +BIO *BIO_new(const BIO_METHOD *type); +int BIO_free(BIO *a); +void BIO_set_data(BIO *a, void *ptr); +void *BIO_get_data(BIO *a); +void BIO_set_init(BIO *a, int init); +int BIO_get_init(BIO *a); +void BIO_set_shutdown(BIO *a, int shut); +int BIO_get_shutdown(BIO *a); +void BIO_vfree(BIO *a); +int BIO_up_ref(BIO *a); +int BIO_read(BIO *b, void *data, int dlen); +int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes); +int BIO_gets(BIO *bp, char *buf, int size); +int BIO_write(BIO *b, const void *data, int dlen); +int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); +int BIO_puts(BIO *bp, const char *buf); +int BIO_indent(BIO *b, int indent, int max); +long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); +long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp); +void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg); +long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); +BIO *BIO_push(BIO *b, BIO *append); +BIO *BIO_pop(BIO *b); +void BIO_free_all(BIO *a); +BIO *BIO_find_type(BIO *b, int bio_type); +BIO *BIO_next(BIO *b); +void BIO_set_next(BIO *b, BIO *next); +BIO *BIO_get_retry_BIO(BIO *bio, int *reason); +int BIO_get_retry_reason(BIO *bio); +void BIO_set_retry_reason(BIO *bio, int reason); +BIO *BIO_dup_chain(BIO *in); + +int BIO_nread0(BIO *bio, char **buf); +int BIO_nread(BIO *bio, char **buf, int num); +int BIO_nwrite0(BIO *bio, char **buf); +int BIO_nwrite(BIO *bio, char **buf, int num); + +long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, + long argl, long ret); + +const BIO_METHOD *BIO_s_mem(void); +const BIO_METHOD *BIO_s_secmem(void); +BIO *BIO_new_mem_buf(const void *buf, int len); +# ifndef OPENSSL_NO_SOCK +const BIO_METHOD *BIO_s_socket(void); +const BIO_METHOD *BIO_s_connect(void); +const BIO_METHOD *BIO_s_accept(void); +# endif +const BIO_METHOD *BIO_s_fd(void); +const BIO_METHOD *BIO_s_log(void); +const BIO_METHOD *BIO_s_bio(void); +const BIO_METHOD *BIO_s_null(void); +const BIO_METHOD *BIO_f_null(void); +const BIO_METHOD *BIO_f_buffer(void); +const BIO_METHOD *BIO_f_linebuffer(void); +const BIO_METHOD *BIO_f_nbio_test(void); +# ifndef OPENSSL_NO_DGRAM +const BIO_METHOD *BIO_s_datagram(void); +int BIO_dgram_non_fatal_error(int error); +BIO *BIO_new_dgram(int fd, int close_flag); +# ifndef OPENSSL_NO_SCTP +const BIO_METHOD *BIO_s_datagram_sctp(void); +BIO *BIO_new_dgram_sctp(int fd, int close_flag); +int BIO_dgram_is_sctp(BIO *bio); +int BIO_dgram_sctp_notification_cb(BIO *b, + void (*handle_notifications) (BIO *bio, + void *context, + void *buf), + void *context); +int BIO_dgram_sctp_wait_for_dry(BIO *b); +int BIO_dgram_sctp_msg_waiting(BIO *b); +# endif +# endif + +# ifndef OPENSSL_NO_SOCK +int BIO_sock_should_retry(int i); +int BIO_sock_non_fatal_error(int error); +# endif + +int BIO_fd_should_retry(int i); +int BIO_fd_non_fatal_error(int error); +int BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u), + void *u, const char *s, int len); +int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), + void *u, const char *s, int len, int indent); +int BIO_dump(BIO *b, const char *bytes, int len); +int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent); +# ifndef OPENSSL_NO_STDIO +int BIO_dump_fp(FILE *fp, const char *s, int len); +int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent); +# endif +int BIO_hex_string(BIO *out, int indent, int width, unsigned char *data, + int datalen); + +# ifndef OPENSSL_NO_SOCK +BIO_ADDR *BIO_ADDR_new(void); +int BIO_ADDR_rawmake(BIO_ADDR *ap, int family, + const void *where, size_t wherelen, unsigned short port); +void BIO_ADDR_free(BIO_ADDR *); +void BIO_ADDR_clear(BIO_ADDR *ap); +int BIO_ADDR_family(const BIO_ADDR *ap); +int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l); +unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap); +char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric); +char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric); +char *BIO_ADDR_path_string(const BIO_ADDR *ap); + +const BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_family(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai); +int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai); +const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai); +void BIO_ADDRINFO_free(BIO_ADDRINFO *bai); + +enum BIO_hostserv_priorities { + BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV +}; +int BIO_parse_hostserv(const char *hostserv, char **host, char **service, + enum BIO_hostserv_priorities hostserv_prio); +enum BIO_lookup_type { + BIO_LOOKUP_CLIENT, BIO_LOOKUP_SERVER +}; +int BIO_lookup(const char *host, const char *service, + enum BIO_lookup_type lookup_type, + int family, int socktype, BIO_ADDRINFO **res); +int BIO_lookup_ex(const char *host, const char *service, + int lookup_type, int family, int socktype, int protocol, + BIO_ADDRINFO **res); +int BIO_sock_error(int sock); +int BIO_socket_ioctl(int fd, long type, void *arg); +int BIO_socket_nbio(int fd, int mode); +int BIO_sock_init(void); +# if OPENSSL_API_COMPAT < 0x10100000L +# define BIO_sock_cleanup() while(0) continue +# endif +int BIO_set_tcp_ndelay(int sock, int turn_on); + +DEPRECATEDIN_1_1_0(struct hostent *BIO_gethostbyname(const char *name)) +DEPRECATEDIN_1_1_0(int BIO_get_port(const char *str, unsigned short *port_ptr)) +DEPRECATEDIN_1_1_0(int BIO_get_host_ip(const char *str, unsigned char *ip)) +DEPRECATEDIN_1_1_0(int BIO_get_accept_socket(char *host_port, int mode)) +DEPRECATEDIN_1_1_0(int BIO_accept(int sock, char **ip_port)) + +union BIO_sock_info_u { + BIO_ADDR *addr; +}; +enum BIO_sock_info_type { + BIO_SOCK_INFO_ADDRESS +}; +int BIO_sock_info(int sock, + enum BIO_sock_info_type type, union BIO_sock_info_u *info); + +# define BIO_SOCK_REUSEADDR 0x01 +# define BIO_SOCK_V6_ONLY 0x02 +# define BIO_SOCK_KEEPALIVE 0x04 +# define BIO_SOCK_NONBLOCK 0x08 +# define BIO_SOCK_NODELAY 0x10 + +int BIO_socket(int domain, int socktype, int protocol, int options); +int BIO_connect(int sock, const BIO_ADDR *addr, int options); +int BIO_bind(int sock, const BIO_ADDR *addr, int options); +int BIO_listen(int sock, const BIO_ADDR *addr, int options); +int BIO_accept_ex(int accept_sock, BIO_ADDR *addr, int options); +int BIO_closesocket(int sock); + +BIO *BIO_new_socket(int sock, int close_flag); +BIO *BIO_new_connect(const char *host_port); +BIO *BIO_new_accept(const char *host_port); +# endif /* OPENSSL_NO_SOCK*/ + +BIO *BIO_new_fd(int fd, int close_flag); + +int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, + BIO **bio2, size_t writebuf2); +/* + * If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. + * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. Size 0 uses default + * value. + */ + +void BIO_copy_next_retry(BIO *b); + +/* + * long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); + */ + +# define ossl_bio__attr__(x) +# if defined(__GNUC__) && defined(__STDC_VERSION__) \ + && !defined(__APPLE__) + /* + * Because we support the 'z' modifier, which made its appearance in C99, + * we can't use __attribute__ with pre C99 dialects. + */ +# if __STDC_VERSION__ >= 199901L +# undef ossl_bio__attr__ +# define ossl_bio__attr__ __attribute__ +# if __GNUC__*10 + __GNUC_MINOR__ >= 44 +# define ossl_bio__printf__ __gnu_printf__ +# else +# define ossl_bio__printf__ __printf__ +# endif +# endif +# endif +int BIO_printf(BIO *bio, const char *format, ...) +ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 3))); +int BIO_vprintf(BIO *bio, const char *format, va_list args) +ossl_bio__attr__((__format__(ossl_bio__printf__, 2, 0))); +int BIO_snprintf(char *buf, size_t n, const char *format, ...) +ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 4))); +int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) +ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 0))); +# undef ossl_bio__attr__ +# undef ossl_bio__printf__ + + +BIO_METHOD *BIO_meth_new(int type, const char *name); +void BIO_meth_free(BIO_METHOD *biom); +int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, int); +int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, size_t, + size_t *); +int BIO_meth_set_write(BIO_METHOD *biom, + int (*write) (BIO *, const char *, int)); +int BIO_meth_set_write_ex(BIO_METHOD *biom, + int (*bwrite) (BIO *, const char *, size_t, size_t *)); +int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int); +int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *); +int BIO_meth_set_read(BIO_METHOD *biom, + int (*read) (BIO *, char *, int)); +int BIO_meth_set_read_ex(BIO_METHOD *biom, + int (*bread) (BIO *, char *, size_t, size_t *)); +int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *); +int BIO_meth_set_puts(BIO_METHOD *biom, + int (*puts) (BIO *, const char *)); +int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int); +int BIO_meth_set_gets(BIO_METHOD *biom, + int (*gets) (BIO *, char *, int)); +long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, long, void *); +int BIO_meth_set_ctrl(BIO_METHOD *biom, + long (*ctrl) (BIO *, int, long, void *)); +int (*BIO_meth_get_create(const BIO_METHOD *bion)) (BIO *); +int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *)); +int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *); +int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)); +long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom)) + (BIO *, int, BIO_info_cb *); +int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, + long (*callback_ctrl) (BIO *, int, + BIO_info_cb *)); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/blowfish.h postgresql-hll-2.14/include/openssl/blowfish.h --- postgresql-hll-2.14_old/include/openssl/blowfish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/blowfish.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,61 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BLOWFISH_H +# define HEADER_BLOWFISH_H + +# include + +# ifndef OPENSSL_NO_BF +# include +# ifdef __cplusplus +extern "C" { +# endif + +# define BF_ENCRYPT 1 +# define BF_DECRYPT 0 + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! BF_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define BF_LONG unsigned int + +# define BF_ROUNDS 16 +# define BF_BLOCK 8 + +typedef struct bf_key_st { + BF_LONG P[BF_ROUNDS + 2]; + BF_LONG S[4 * 256]; +} BF_KEY; + +void BF_set_key(BF_KEY *key, int len, const unsigned char *data); + +void BF_encrypt(BF_LONG *data, const BF_KEY *key); +void BF_decrypt(BF_LONG *data, const BF_KEY *key); + +void BF_ecb_encrypt(const unsigned char *in, unsigned char *out, + const BF_KEY *key, int enc); +void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + const BF_KEY *schedule, unsigned char *ivec, int enc); +void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const BF_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const BF_KEY *schedule, + unsigned char *ivec, int *num); +const char *BF_options(void); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/bnerr.h postgresql-hll-2.14/include/openssl/bnerr.h --- postgresql-hll-2.14_old/include/openssl/bnerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/bnerr.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,100 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BNERR_H +# define HEADER_BNERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_BN_strings(void); + +/* + * BN function codes. + */ +# define BN_F_BNRAND 127 +# define BN_F_BNRAND_RANGE 138 +# define BN_F_BN_BLINDING_CONVERT_EX 100 +# define BN_F_BN_BLINDING_CREATE_PARAM 128 +# define BN_F_BN_BLINDING_INVERT_EX 101 +# define BN_F_BN_BLINDING_NEW 102 +# define BN_F_BN_BLINDING_UPDATE 103 +# define BN_F_BN_BN2DEC 104 +# define BN_F_BN_BN2HEX 105 +# define BN_F_BN_COMPUTE_WNAF 142 +# define BN_F_BN_CTX_GET 116 +# define BN_F_BN_CTX_NEW 106 +# define BN_F_BN_CTX_START 129 +# define BN_F_BN_DIV 107 +# define BN_F_BN_DIV_RECP 130 +# define BN_F_BN_EXP 123 +# define BN_F_BN_EXPAND_INTERNAL 120 +# define BN_F_BN_GENCB_NEW 143 +# define BN_F_BN_GENERATE_DSA_NONCE 140 +# define BN_F_BN_GENERATE_PRIME_EX 141 +# define BN_F_BN_GF2M_MOD 131 +# define BN_F_BN_GF2M_MOD_EXP 132 +# define BN_F_BN_GF2M_MOD_MUL 133 +# define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134 +# define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135 +# define BN_F_BN_GF2M_MOD_SQR 136 +# define BN_F_BN_GF2M_MOD_SQRT 137 +# define BN_F_BN_LSHIFT 145 +# define BN_F_BN_MOD_EXP2_MONT 118 +# define BN_F_BN_MOD_EXP_MONT 109 +# define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124 +# define BN_F_BN_MOD_EXP_MONT_WORD 117 +# define BN_F_BN_MOD_EXP_RECP 125 +# define BN_F_BN_MOD_EXP_SIMPLE 126 +# define BN_F_BN_MOD_INVERSE 110 +# define BN_F_BN_MOD_INVERSE_NO_BRANCH 139 +# define BN_F_BN_MOD_LSHIFT_QUICK 119 +# define BN_F_BN_MOD_SQRT 121 +# define BN_F_BN_MONT_CTX_NEW 149 +# define BN_F_BN_MPI2BN 112 +# define BN_F_BN_NEW 113 +# define BN_F_BN_POOL_GET 147 +# define BN_F_BN_RAND 114 +# define BN_F_BN_RAND_RANGE 122 +# define BN_F_BN_RECP_CTX_NEW 150 +# define BN_F_BN_RSHIFT 146 +# define BN_F_BN_SET_WORDS 144 +# define BN_F_BN_STACK_PUSH 148 +# define BN_F_BN_USUB 115 + +/* + * BN reason codes. + */ +# define BN_R_ARG2_LT_ARG3 100 +# define BN_R_BAD_RECIPROCAL 101 +# define BN_R_BIGNUM_TOO_LONG 114 +# define BN_R_BITS_TOO_SMALL 118 +# define BN_R_CALLED_WITH_EVEN_MODULUS 102 +# define BN_R_DIV_BY_ZERO 103 +# define BN_R_ENCODING_ERROR 104 +# define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 +# define BN_R_INPUT_NOT_REDUCED 110 +# define BN_R_INVALID_LENGTH 106 +# define BN_R_INVALID_RANGE 115 +# define BN_R_INVALID_SHIFT 119 +# define BN_R_NOT_A_SQUARE 111 +# define BN_R_NOT_INITIALIZED 107 +# define BN_R_NO_INVERSE 108 +# define BN_R_NO_SOLUTION 116 +# define BN_R_PRIVATE_KEY_TOO_LARGE 117 +# define BN_R_P_IS_NOT_PRIME 112 +# define BN_R_TOO_MANY_ITERATIONS 113 +# define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/bn.h postgresql-hll-2.14/include/openssl/bn.h --- postgresql-hll-2.14_old/include/openssl/bn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/bn.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,539 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BN_H +# define HEADER_BN_H + +# include +# ifndef OPENSSL_NO_STDIO +# include +# endif +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * 64-bit processor with LP64 ABI + */ +# ifdef SIXTY_FOUR_BIT_LONG +# define BN_ULONG unsigned long +# define BN_BYTES 8 +# endif + +/* + * 64-bit processor other than LP64 ABI + */ +# ifdef SIXTY_FOUR_BIT +# define BN_ULONG unsigned long long +# define BN_BYTES 8 +# endif + +# ifdef THIRTY_TWO_BIT +# define BN_ULONG unsigned int +# define BN_BYTES 4 +# endif + +# define BN_BITS2 (BN_BYTES * 8) +# define BN_BITS (BN_BITS2 * 2) +# define BN_TBIT ((BN_ULONG)1 << (BN_BITS2 - 1)) + +# define BN_FLG_MALLOCED 0x01 +# define BN_FLG_STATIC_DATA 0x02 + +/* + * avoid leaking exponent information through timing, + * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime, + * BN_div() will call BN_div_no_branch, + * BN_mod_inverse() will call BN_mod_inverse_no_branch. + */ +# define BN_FLG_CONSTTIME 0x04 +# define BN_FLG_SECURE 0x08 + +# if OPENSSL_API_COMPAT < 0x00908000L +/* deprecated name for the flag */ +# define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME +# define BN_FLG_FREE 0x8000 /* used for debugging */ +# endif + +void BN_set_flags(BIGNUM *b, int n); +int BN_get_flags(const BIGNUM *b, int n); + +/* Values for |top| in BN_rand() */ +#define BN_RAND_TOP_ANY -1 +#define BN_RAND_TOP_ONE 0 +#define BN_RAND_TOP_TWO 1 + +/* Values for |bottom| in BN_rand() */ +#define BN_RAND_BOTTOM_ANY 0 +#define BN_RAND_BOTTOM_ODD 1 + +/* + * get a clone of a BIGNUM with changed flags, for *temporary* use only (the + * two BIGNUMs cannot be used in parallel!). Also only for *read only* use. The + * value |dest| should be a newly allocated BIGNUM obtained via BN_new() that + * has not been otherwise initialised or used. + */ +void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags); + +/* Wrapper function to make using BN_GENCB easier */ +int BN_GENCB_call(BN_GENCB *cb, int a, int b); + +BN_GENCB *BN_GENCB_new(void); +void BN_GENCB_free(BN_GENCB *cb); + +/* Populate a BN_GENCB structure with an "old"-style callback */ +void BN_GENCB_set_old(BN_GENCB *gencb, void (*callback) (int, int, void *), + void *cb_arg); + +/* Populate a BN_GENCB structure with a "new"-style callback */ +void BN_GENCB_set(BN_GENCB *gencb, int (*callback) (int, int, BN_GENCB *), + void *cb_arg); + +void *BN_GENCB_get_arg(BN_GENCB *cb); + +# define BN_prime_checks 0 /* default: select number of iterations based + * on the size of the number */ + +/* + * BN_prime_checks_for_size() returns the number of Miller-Rabin iterations + * that will be done for checking that a random number is probably prime. The + * error rate for accepting a composite number as prime depends on the size of + * the prime |b|. The error rates used are for calculating an RSA key with 2 primes, + * and so the level is what you would expect for a key of double the size of the + * prime. + * + * This table is generated using the algorithm of FIPS PUB 186-4 + * Digital Signature Standard (DSS), section F.1, page 117. + * (https://dx.doi.org/10.6028/NIST.FIPS.186-4) + * + * The following magma script was used to generate the output: + * securitybits:=125; + * k:=1024; + * for t:=1 to 65 do + * for M:=3 to Floor(2*Sqrt(k-1)-1) do + * S:=0; + * // Sum over m + * for m:=3 to M do + * s:=0; + * // Sum over j + * for j:=2 to m do + * s+:=(RealField(32)!2)^-(j+(k-1)/j); + * end for; + * S+:=2^(m-(m-1)*t)*s; + * end for; + * A:=2^(k-2-M*t); + * B:=8*(Pi(RealField(32))^2-6)/3*2^(k-2)*S; + * pkt:=2.00743*Log(2)*k*2^-k*(A+B); + * seclevel:=Floor(-Log(2,pkt)); + * if seclevel ge securitybits then + * printf "k: %5o, security: %o bits (t: %o, M: %o)\n",k,seclevel,t,M; + * break; + * end if; + * end for; + * if seclevel ge securitybits then break; end if; + * end for; + * + * It can be run online at: + * http://magma.maths.usyd.edu.au/calc + * + * And will output: + * k: 1024, security: 129 bits (t: 6, M: 23) + * + * k is the number of bits of the prime, securitybits is the level we want to + * reach. + * + * prime length | RSA key size | # MR tests | security level + * -------------+--------------|------------+--------------- + * (b) >= 6394 | >= 12788 | 3 | 256 bit + * (b) >= 3747 | >= 7494 | 3 | 192 bit + * (b) >= 1345 | >= 2690 | 4 | 128 bit + * (b) >= 1080 | >= 2160 | 5 | 128 bit + * (b) >= 852 | >= 1704 | 5 | 112 bit + * (b) >= 476 | >= 952 | 5 | 80 bit + * (b) >= 400 | >= 800 | 6 | 80 bit + * (b) >= 347 | >= 694 | 7 | 80 bit + * (b) >= 308 | >= 616 | 8 | 80 bit + * (b) >= 55 | >= 110 | 27 | 64 bit + * (b) >= 6 | >= 12 | 34 | 64 bit + */ + +# define BN_prime_checks_for_size(b) ((b) >= 3747 ? 3 : \ + (b) >= 1345 ? 4 : \ + (b) >= 476 ? 5 : \ + (b) >= 400 ? 6 : \ + (b) >= 347 ? 7 : \ + (b) >= 308 ? 8 : \ + (b) >= 55 ? 27 : \ + /* b >= 6 */ 34) + +# define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) + +int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); +int BN_is_zero(const BIGNUM *a); +int BN_is_one(const BIGNUM *a); +int BN_is_word(const BIGNUM *a, const BN_ULONG w); +int BN_is_odd(const BIGNUM *a); + +# define BN_one(a) (BN_set_word((a),1)) + +void BN_zero_ex(BIGNUM *a); + +# if OPENSSL_API_COMPAT >= 0x00908000L +# define BN_zero(a) BN_zero_ex(a) +# else +# define BN_zero(a) (BN_set_word((a),0)) +# endif + +const BIGNUM *BN_value_one(void); +char *BN_options(void); +BN_CTX *BN_CTX_new(void); +BN_CTX *BN_CTX_secure_new(void); +void BN_CTX_free(BN_CTX *c); +void BN_CTX_start(BN_CTX *ctx); +BIGNUM *BN_CTX_get(BN_CTX *ctx); +void BN_CTX_end(BN_CTX *ctx); +int BN_rand(BIGNUM *rnd, int bits, int top, int bottom); +int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom); +int BN_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_priv_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom); +int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range); +int BN_num_bits(const BIGNUM *a); +int BN_num_bits_word(BN_ULONG l); +int BN_security_bits(int L, int N); +BIGNUM *BN_new(void); +BIGNUM *BN_secure_new(void); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); +void BN_swap(BIGNUM *a, BIGNUM *b); +BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2bin(const BIGNUM *a, unsigned char *to); +int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); +BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen); +BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret); +int BN_bn2mpi(const BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); +int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); +/** BN_set_negative sets sign of a BIGNUM + * \param b pointer to the BIGNUM object + * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise + */ +void BN_set_negative(BIGNUM *b, int n); +/** BN_is_negative returns 1 if the BIGNUM is negative + * \param b pointer to the BIGNUM object + * \return 1 if a < 0 and 0 otherwise + */ +int BN_is_negative(const BIGNUM *b); + +int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, + BN_CTX *ctx); +# define BN_mod(rem,m,d,ctx) BN_div(NULL,(rem),(m),(d),(ctx)) +int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); +int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *m); +int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *m); +int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); +int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m); +int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, + BN_CTX *ctx); +int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m); + +BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(const BIGNUM *a); + +int BN_cmp(const BIGNUM *a, const BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(const BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, const BIGNUM *a); +int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); + +int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *in_mont); +int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1, + const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m, + BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); + +int BN_mask_bits(BIGNUM *a, int n); +# ifndef OPENSSL_NO_STDIO +int BN_print_fp(FILE *fp, const BIGNUM *a); +# endif +int BN_print(BIO *bio, const BIGNUM *a); +int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, const BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *BN_dup(const BIGNUM *a); +int BN_ucmp(const BIGNUM *a, const BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char *BN_bn2hex(const BIGNUM *a); +char *BN_bn2dec(const BIGNUM *a); +int BN_hex2bn(BIGNUM **a, const char *str); +int BN_dec2bn(BIGNUM **a, const char *str); +int BN_asc2bn(BIGNUM **a, const char *str); +int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); +int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); /* returns + * -2 for + * error */ +BIGNUM *BN_mod_inverse(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); +BIGNUM *BN_mod_sqrt(BIGNUM *ret, + const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx); + +void BN_consttime_swap(BN_ULONG swap, BIGNUM *a, BIGNUM *b, int nwords); + +/* Deprecated versions */ +DEPRECATEDIN_0_9_8(BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, + const BIGNUM *add, + const BIGNUM *rem, + void (*callback) (int, int, + void *), + void *cb_arg)) +DEPRECATEDIN_0_9_8(int + BN_is_prime(const BIGNUM *p, int nchecks, + void (*callback) (int, int, void *), + BN_CTX *ctx, void *cb_arg)) +DEPRECATEDIN_0_9_8(int + BN_is_prime_fasttest(const BIGNUM *p, int nchecks, + void (*callback) (int, int, void *), + BN_CTX *ctx, void *cb_arg, + int do_trial_division)) + +/* Newer versions */ +int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add, + const BIGNUM *rem, BN_GENCB *cb); +int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb); +int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, + int do_trial_division, BN_GENCB *cb); + +int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx); + +int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, + const BIGNUM *Xp, const BIGNUM *Xp1, + const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx, + BN_GENCB *cb); +int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, BIGNUM *Xp1, + BIGNUM *Xp2, const BIGNUM *Xp, const BIGNUM *e, + BN_CTX *ctx, BN_GENCB *cb); + +BN_MONT_CTX *BN_MONT_CTX_new(void); +int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + BN_MONT_CTX *mont, BN_CTX *ctx); +int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, + BN_CTX *ctx); +int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont, + BN_CTX *ctx); +void BN_MONT_CTX_free(BN_MONT_CTX *mont); +int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx); +BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from); +BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock, + const BIGNUM *mod, BN_CTX *ctx); + +/* BN_BLINDING flags */ +# define BN_BLINDING_NO_UPDATE 0x00000001 +# define BN_BLINDING_NO_RECREATE 0x00000002 + +BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod); +void BN_BLINDING_free(BN_BLINDING *b); +int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); +int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); +int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, + BN_CTX *); + +int BN_BLINDING_is_current_thread(BN_BLINDING *b); +void BN_BLINDING_set_current_thread(BN_BLINDING *b); +int BN_BLINDING_lock(BN_BLINDING *b); +int BN_BLINDING_unlock(BN_BLINDING *b); + +unsigned long BN_BLINDING_get_flags(const BN_BLINDING *); +void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long); +BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b, + const BIGNUM *e, BIGNUM *m, BN_CTX *ctx, + int (*bn_mod_exp) (BIGNUM *r, + const BIGNUM *a, + const BIGNUM *p, + const BIGNUM *m, + BN_CTX *ctx, + BN_MONT_CTX *m_ctx), + BN_MONT_CTX *m_ctx); + +DEPRECATEDIN_0_9_8(void BN_set_params(int mul, int high, int low, int mont)) +DEPRECATEDIN_0_9_8(int BN_get_params(int which)) /* 0, mul, 1 high, 2 low, 3 + * mont */ + +BN_RECP_CTX *BN_RECP_CTX_new(void); +void BN_RECP_CTX_free(BN_RECP_CTX *recp); +int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *rdiv, BN_CTX *ctx); +int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, + BN_RECP_CTX *recp, BN_CTX *ctx); +int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, + BN_RECP_CTX *recp, BN_CTX *ctx); + +# ifndef OPENSSL_NO_EC2M + +/* + * Functions for arithmetic over binary polynomials represented by BIGNUMs. + * The BIGNUM::neg property of BIGNUMs representing binary polynomials is + * ignored. Note that input arguments are not const so that their bit arrays + * can be expanded to the appropriate size if needed. + */ + +/* + * r = a + b + */ +int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +# define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b) +/* + * r=a mod p + */ +int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); +/* r = (a * b) mod p */ +int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = (a * a) mod p */ +int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +/* r = (1 / b) mod p */ +int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx); +/* r = (a / b) mod p */ +int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = (a ^ b) mod p */ +int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const BIGNUM *p, BN_CTX *ctx); +/* r = sqrt(a) mod p */ +int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); +/* r^2 + r = a mod p */ +int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + BN_CTX *ctx); +# define BN_GF2m_cmp(a, b) BN_ucmp((a), (b)) +/*- + * Some functions allow for representation of the irreducible polynomials + * as an unsigned int[], say p. The irreducible f(t) is then of the form: + * t^p[0] + t^p[1] + ... + t^p[k] + * where m = p[0] > p[1] > ... > p[k] = 0. + */ +/* r = a mod p */ +int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]); +/* r = (a * b) mod p */ +int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = (a * a) mod p */ +int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], + BN_CTX *ctx); +/* r = (1 / b) mod p */ +int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[], + BN_CTX *ctx); +/* r = (a / b) mod p */ +int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = (a ^ b) mod p */ +int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, + const int p[], BN_CTX *ctx); +/* r = sqrt(a) mod p */ +int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, + const int p[], BN_CTX *ctx); +/* r^2 + r = a mod p */ +int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a, + const int p[], BN_CTX *ctx); +int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max); +int BN_GF2m_arr2poly(const int p[], BIGNUM *a); + +# endif + +/* + * faster mod functions for the 'NIST primes' 0 <= a < p^2 + */ +int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); +int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); + +const BIGNUM *BN_get0_nist_prime_192(void); +const BIGNUM *BN_get0_nist_prime_224(void); +const BIGNUM *BN_get0_nist_prime_256(void); +const BIGNUM *BN_get0_nist_prime_384(void); +const BIGNUM *BN_get0_nist_prime_521(void); + +int (*BN_nist_mod_func(const BIGNUM *p)) (BIGNUM *r, const BIGNUM *a, + const BIGNUM *field, BN_CTX *ctx); + +int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range, + const BIGNUM *priv, const unsigned char *message, + size_t message_len, BN_CTX *ctx); + +/* Primes from RFC 2409 */ +BIGNUM *BN_get_rfc2409_prime_768(BIGNUM *bn); +BIGNUM *BN_get_rfc2409_prime_1024(BIGNUM *bn); + +/* Primes from RFC 3526 */ +BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *bn); +BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *bn); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define get_rfc2409_prime_768 BN_get_rfc2409_prime_768 +# define get_rfc2409_prime_1024 BN_get_rfc2409_prime_1024 +# define get_rfc3526_prime_1536 BN_get_rfc3526_prime_1536 +# define get_rfc3526_prime_2048 BN_get_rfc3526_prime_2048 +# define get_rfc3526_prime_3072 BN_get_rfc3526_prime_3072 +# define get_rfc3526_prime_4096 BN_get_rfc3526_prime_4096 +# define get_rfc3526_prime_6144 BN_get_rfc3526_prime_6144 +# define get_rfc3526_prime_8192 BN_get_rfc3526_prime_8192 +# endif + +int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/buffererr.h postgresql-hll-2.14/include/openssl/buffererr.h --- postgresql-hll-2.14_old/include/openssl/buffererr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/buffererr.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,34 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BUFERR_H +# define HEADER_BUFERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_BUF_strings(void); + +/* + * BUF function codes. + */ +# define BUF_F_BUF_MEM_GROW 100 +# define BUF_F_BUF_MEM_GROW_CLEAN 105 +# define BUF_F_BUF_MEM_NEW 101 + +/* + * BUF reason codes. + */ + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/buffer.h postgresql-hll-2.14/include/openssl/buffer.h --- postgresql-hll-2.14_old/include/openssl/buffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/buffer.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,58 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_BUFFER_H +# define HEADER_BUFFER_H + +# include +# ifndef HEADER_CRYPTO_H +# include +# endif +# include + + +#ifdef __cplusplus +extern "C" { +#endif + +# include +# include + +/* + * These names are outdated as of OpenSSL 1.1; a future release + * will move them to be deprecated. + */ +# define BUF_strdup(s) OPENSSL_strdup(s) +# define BUF_strndup(s, size) OPENSSL_strndup(s, size) +# define BUF_memdup(data, size) OPENSSL_memdup(data, size) +# define BUF_strlcpy(dst, src, size) OPENSSL_strlcpy(dst, src, size) +# define BUF_strlcat(dst, src, size) OPENSSL_strlcat(dst, src, size) +# define BUF_strnlen(str, maxlen) OPENSSL_strnlen(str, maxlen) + +struct buf_mem_st { + size_t length; /* current number of bytes */ + char *data; + size_t max; /* size of buffer */ + unsigned long flags; +}; + +# define BUF_MEM_FLAG_SECURE 0x01 + +BUF_MEM *BUF_MEM_new(void); +BUF_MEM *BUF_MEM_new_ex(unsigned long flags); +void BUF_MEM_free(BUF_MEM *a); +size_t BUF_MEM_grow(BUF_MEM *str, size_t len); +size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len); +void BUF_reverse(unsigned char *out, const unsigned char *in, size_t siz); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/camellia.h postgresql-hll-2.14/include/openssl/camellia.h --- postgresql-hll-2.14_old/include/openssl/camellia.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/camellia.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,83 @@ +/* + * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CAMELLIA_H +# define HEADER_CAMELLIA_H + +# include + +# ifndef OPENSSL_NO_CAMELLIA +# include +#ifdef __cplusplus +extern "C" { +#endif + +# define CAMELLIA_ENCRYPT 1 +# define CAMELLIA_DECRYPT 0 + +/* + * Because array size can't be a const in C, the following two are macros. + * Both sizes are in bytes. + */ + +/* This should be a hidden type, but EVP requires that the size be known */ + +# define CAMELLIA_BLOCK_SIZE 16 +# define CAMELLIA_TABLE_BYTE_LEN 272 +# define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4) + +typedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; /* to match + * with WORD */ + +struct camellia_key_st { + union { + double d; /* ensures 64-bit align */ + KEY_TABLE_TYPE rd_key; + } u; + int grand_rounds; +}; +typedef struct camellia_key_st CAMELLIA_KEY; + +int Camellia_set_key(const unsigned char *userKey, const int bits, + CAMELLIA_KEY *key); + +void Camellia_encrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key); +void Camellia_decrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key); + +void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, + const CAMELLIA_KEY *key, const int enc); +void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, const int enc); +void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num, const int enc); +void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char *ivec, int *num); +void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const CAMELLIA_KEY *key, + unsigned char ivec[CAMELLIA_BLOCK_SIZE], + unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE], + unsigned int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cast.h postgresql-hll-2.14/include/openssl/cast.h --- postgresql-hll-2.14_old/include/openssl/cast.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cast.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,53 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CAST_H +# define HEADER_CAST_H + +# include + +# ifndef OPENSSL_NO_CAST +# ifdef __cplusplus +extern "C" { +# endif + +# define CAST_ENCRYPT 1 +# define CAST_DECRYPT 0 + +# define CAST_LONG unsigned int + +# define CAST_BLOCK 8 +# define CAST_KEY_LENGTH 16 + +typedef struct cast_key_st { + CAST_LONG data[32]; + int short_key; /* Use reduced rounds for short key */ +} CAST_KEY; + +void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); +void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, + const CAST_KEY *key, int enc); +void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key); +void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key); +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *ks, unsigned char *iv, + int enc); +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, const CAST_KEY *schedule, + unsigned char *ivec, int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cmac.h postgresql-hll-2.14/include/openssl/cmac.h --- postgresql-hll-2.14_old/include/openssl/cmac.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cmac.h 2020-12-12 17:06:43.327349071 +0800 @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CMAC_H +# define HEADER_CMAC_H + +# ifndef OPENSSL_NO_CMAC + +#ifdef __cplusplus +extern "C" { +#endif + +# include + +/* Opaque */ +typedef struct CMAC_CTX_st CMAC_CTX; + +CMAC_CTX *CMAC_CTX_new(void); +void CMAC_CTX_cleanup(CMAC_CTX *ctx); +void CMAC_CTX_free(CMAC_CTX *ctx); +EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx); +int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in); + +int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, + const EVP_CIPHER *cipher, ENGINE *impl); +int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen); +int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen); +int CMAC_resume(CMAC_CTX *ctx); + +#ifdef __cplusplus +} +#endif + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cmserr.h postgresql-hll-2.14/include/openssl/cmserr.h --- postgresql-hll-2.14_old/include/openssl/cmserr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cmserr.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,202 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CMSERR_H +# define HEADER_CMSERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_CMS + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_CMS_strings(void); + +/* + * CMS function codes. + */ +# define CMS_F_CHECK_CONTENT 99 +# define CMS_F_CMS_ADD0_CERT 164 +# define CMS_F_CMS_ADD0_RECIPIENT_KEY 100 +# define CMS_F_CMS_ADD0_RECIPIENT_PASSWORD 165 +# define CMS_F_CMS_ADD1_RECEIPTREQUEST 158 +# define CMS_F_CMS_ADD1_RECIPIENT_CERT 101 +# define CMS_F_CMS_ADD1_SIGNER 102 +# define CMS_F_CMS_ADD1_SIGNINGTIME 103 +# define CMS_F_CMS_COMPRESS 104 +# define CMS_F_CMS_COMPRESSEDDATA_CREATE 105 +# define CMS_F_CMS_COMPRESSEDDATA_INIT_BIO 106 +# define CMS_F_CMS_COPY_CONTENT 107 +# define CMS_F_CMS_COPY_MESSAGEDIGEST 108 +# define CMS_F_CMS_DATA 109 +# define CMS_F_CMS_DATAFINAL 110 +# define CMS_F_CMS_DATAINIT 111 +# define CMS_F_CMS_DECRYPT 112 +# define CMS_F_CMS_DECRYPT_SET1_KEY 113 +# define CMS_F_CMS_DECRYPT_SET1_PASSWORD 166 +# define CMS_F_CMS_DECRYPT_SET1_PKEY 114 +# define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 115 +# define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 116 +# define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 117 +# define CMS_F_CMS_DIGEST_VERIFY 118 +# define CMS_F_CMS_ENCODE_RECEIPT 161 +# define CMS_F_CMS_ENCRYPT 119 +# define CMS_F_CMS_ENCRYPTEDCONTENT_INIT 179 +# define CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO 120 +# define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 121 +# define CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT 122 +# define CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY 123 +# define CMS_F_CMS_ENVELOPEDDATA_CREATE 124 +# define CMS_F_CMS_ENVELOPEDDATA_INIT_BIO 125 +# define CMS_F_CMS_ENVELOPED_DATA_INIT 126 +# define CMS_F_CMS_ENV_ASN1_CTRL 171 +# define CMS_F_CMS_FINAL 127 +# define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 128 +# define CMS_F_CMS_GET0_CONTENT 129 +# define CMS_F_CMS_GET0_ECONTENT_TYPE 130 +# define CMS_F_CMS_GET0_ENVELOPED 131 +# define CMS_F_CMS_GET0_REVOCATION_CHOICES 132 +# define CMS_F_CMS_GET0_SIGNED 133 +# define CMS_F_CMS_MSGSIGDIGEST_ADD1 162 +# define CMS_F_CMS_RECEIPTREQUEST_CREATE0 159 +# define CMS_F_CMS_RECEIPT_VERIFY 160 +# define CMS_F_CMS_RECIPIENTINFO_DECRYPT 134 +# define CMS_F_CMS_RECIPIENTINFO_ENCRYPT 169 +# define CMS_F_CMS_RECIPIENTINFO_KARI_ENCRYPT 178 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ALG 175 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_ORIG_ID 173 +# define CMS_F_CMS_RECIPIENTINFO_KARI_GET0_REKS 172 +# define CMS_F_CMS_RECIPIENTINFO_KARI_ORIG_ID_CMP 174 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 135 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 136 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 137 +# define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 138 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 139 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 140 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 141 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS 142 +# define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID 143 +# define CMS_F_CMS_RECIPIENTINFO_PWRI_CRYPT 167 +# define CMS_F_CMS_RECIPIENTINFO_SET0_KEY 144 +# define CMS_F_CMS_RECIPIENTINFO_SET0_PASSWORD 168 +# define CMS_F_CMS_RECIPIENTINFO_SET0_PKEY 145 +# define CMS_F_CMS_SD_ASN1_CTRL 170 +# define CMS_F_CMS_SET1_IAS 176 +# define CMS_F_CMS_SET1_KEYID 177 +# define CMS_F_CMS_SET1_SIGNERIDENTIFIER 146 +# define CMS_F_CMS_SET_DETACHED 147 +# define CMS_F_CMS_SIGN 148 +# define CMS_F_CMS_SIGNED_DATA_INIT 149 +# define CMS_F_CMS_SIGNERINFO_CONTENT_SIGN 150 +# define CMS_F_CMS_SIGNERINFO_SIGN 151 +# define CMS_F_CMS_SIGNERINFO_VERIFY 152 +# define CMS_F_CMS_SIGNERINFO_VERIFY_CERT 153 +# define CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT 154 +# define CMS_F_CMS_SIGN_RECEIPT 163 +# define CMS_F_CMS_SI_CHECK_ATTRIBUTES 183 +# define CMS_F_CMS_STREAM 155 +# define CMS_F_CMS_UNCOMPRESS 156 +# define CMS_F_CMS_VERIFY 157 +# define CMS_F_KEK_UNWRAP_KEY 180 + +/* + * CMS reason codes. + */ +# define CMS_R_ADD_SIGNER_ERROR 99 +# define CMS_R_ATTRIBUTE_ERROR 161 +# define CMS_R_CERTIFICATE_ALREADY_PRESENT 175 +# define CMS_R_CERTIFICATE_HAS_NO_KEYID 160 +# define CMS_R_CERTIFICATE_VERIFY_ERROR 100 +# define CMS_R_CIPHER_INITIALISATION_ERROR 101 +# define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102 +# define CMS_R_CMS_DATAFINAL_ERROR 103 +# define CMS_R_CMS_LIB 104 +# define CMS_R_CONTENTIDENTIFIER_MISMATCH 170 +# define CMS_R_CONTENT_NOT_FOUND 105 +# define CMS_R_CONTENT_TYPE_MISMATCH 171 +# define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106 +# define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107 +# define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108 +# define CMS_R_CONTENT_VERIFY_ERROR 109 +# define CMS_R_CTRL_ERROR 110 +# define CMS_R_CTRL_FAILURE 111 +# define CMS_R_DECRYPT_ERROR 112 +# define CMS_R_ERROR_GETTING_PUBLIC_KEY 113 +# define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114 +# define CMS_R_ERROR_SETTING_KEY 115 +# define CMS_R_ERROR_SETTING_RECIPIENTINFO 116 +# define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117 +# define CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER 176 +# define CMS_R_INVALID_KEY_LENGTH 118 +# define CMS_R_MD_BIO_INIT_ERROR 119 +# define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120 +# define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121 +# define CMS_R_MSGSIGDIGEST_ERROR 172 +# define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162 +# define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163 +# define CMS_R_NEED_ONE_SIGNER 164 +# define CMS_R_NOT_A_SIGNED_RECEIPT 165 +# define CMS_R_NOT_ENCRYPTED_DATA 122 +# define CMS_R_NOT_KEK 123 +# define CMS_R_NOT_KEY_AGREEMENT 181 +# define CMS_R_NOT_KEY_TRANSPORT 124 +# define CMS_R_NOT_PWRI 177 +# define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125 +# define CMS_R_NO_CIPHER 126 +# define CMS_R_NO_CONTENT 127 +# define CMS_R_NO_CONTENT_TYPE 173 +# define CMS_R_NO_DEFAULT_DIGEST 128 +# define CMS_R_NO_DIGEST_SET 129 +# define CMS_R_NO_KEY 130 +# define CMS_R_NO_KEY_OR_CERT 174 +# define CMS_R_NO_MATCHING_DIGEST 131 +# define CMS_R_NO_MATCHING_RECIPIENT 132 +# define CMS_R_NO_MATCHING_SIGNATURE 166 +# define CMS_R_NO_MSGSIGDIGEST 167 +# define CMS_R_NO_PASSWORD 178 +# define CMS_R_NO_PRIVATE_KEY 133 +# define CMS_R_NO_PUBLIC_KEY 134 +# define CMS_R_NO_RECEIPT_REQUEST 168 +# define CMS_R_NO_SIGNERS 135 +# define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136 +# define CMS_R_RECEIPT_DECODE_ERROR 169 +# define CMS_R_RECIPIENT_ERROR 137 +# define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138 +# define CMS_R_SIGNFINAL_ERROR 139 +# define CMS_R_SMIME_TEXT_ERROR 140 +# define CMS_R_STORE_INIT_ERROR 141 +# define CMS_R_TYPE_NOT_COMPRESSED_DATA 142 +# define CMS_R_TYPE_NOT_DATA 143 +# define CMS_R_TYPE_NOT_DIGESTED_DATA 144 +# define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145 +# define CMS_R_TYPE_NOT_ENVELOPED_DATA 146 +# define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147 +# define CMS_R_UNKNOWN_CIPHER 148 +# define CMS_R_UNKNOWN_DIGEST_ALGORITHM 149 +# define CMS_R_UNKNOWN_ID 150 +# define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151 +# define CMS_R_UNSUPPORTED_CONTENT_TYPE 152 +# define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153 +# define CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM 179 +# define CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE 155 +# define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154 +# define CMS_R_UNSUPPORTED_TYPE 156 +# define CMS_R_UNWRAP_ERROR 157 +# define CMS_R_UNWRAP_FAILURE 180 +# define CMS_R_VERIFICATION_FAILURE 158 +# define CMS_R_WRAP_ERROR 159 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cms.h postgresql-hll-2.14/include/openssl/cms.h --- postgresql-hll-2.14_old/include/openssl/cms.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cms.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,339 @@ +/* + * Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CMS_H +# define HEADER_CMS_H + +# include + +# ifndef OPENSSL_NO_CMS +# include +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct CMS_ContentInfo_st CMS_ContentInfo; +typedef struct CMS_SignerInfo_st CMS_SignerInfo; +typedef struct CMS_CertificateChoices CMS_CertificateChoices; +typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice; +typedef struct CMS_RecipientInfo_st CMS_RecipientInfo; +typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest; +typedef struct CMS_Receipt_st CMS_Receipt; +typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey; +typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute; + +DEFINE_STACK_OF(CMS_SignerInfo) +DEFINE_STACK_OF(CMS_RecipientEncryptedKey) +DEFINE_STACK_OF(CMS_RecipientInfo) +DEFINE_STACK_OF(CMS_RevocationInfoChoice) +DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo) +DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest) +DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo) + +# define CMS_SIGNERINFO_ISSUER_SERIAL 0 +# define CMS_SIGNERINFO_KEYIDENTIFIER 1 + +# define CMS_RECIPINFO_NONE -1 +# define CMS_RECIPINFO_TRANS 0 +# define CMS_RECIPINFO_AGREE 1 +# define CMS_RECIPINFO_KEK 2 +# define CMS_RECIPINFO_PASS 3 +# define CMS_RECIPINFO_OTHER 4 + +/* S/MIME related flags */ + +# define CMS_TEXT 0x1 +# define CMS_NOCERTS 0x2 +# define CMS_NO_CONTENT_VERIFY 0x4 +# define CMS_NO_ATTR_VERIFY 0x8 +# define CMS_NOSIGS \ + (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY) +# define CMS_NOINTERN 0x10 +# define CMS_NO_SIGNER_CERT_VERIFY 0x20 +# define CMS_NOVERIFY 0x20 +# define CMS_DETACHED 0x40 +# define CMS_BINARY 0x80 +# define CMS_NOATTR 0x100 +# define CMS_NOSMIMECAP 0x200 +# define CMS_NOOLDMIMETYPE 0x400 +# define CMS_CRLFEOL 0x800 +# define CMS_STREAM 0x1000 +# define CMS_NOCRL 0x2000 +# define CMS_PARTIAL 0x4000 +# define CMS_REUSE_DIGEST 0x8000 +# define CMS_USE_KEYID 0x10000 +# define CMS_DEBUG_DECRYPT 0x20000 +# define CMS_KEY_PARAM 0x40000 +# define CMS_ASCIICRLF 0x80000 + +const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms); + +BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont); +int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio); + +ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms); +int CMS_is_detached(CMS_ContentInfo *cms); +int CMS_set_detached(CMS_ContentInfo *cms, int detached); + +# ifdef HEADER_PEM_H +DECLARE_PEM_rw_const(CMS, CMS_ContentInfo) +# endif +int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms); +CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms); +int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms); + +BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms); +int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags); +int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, + int flags); +CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont); +int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags); + +int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, + unsigned int flags); + +CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, + STACK_OF(X509) *certs, BIO *data, + unsigned int flags); + +CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si, + X509 *signcert, EVP_PKEY *pkey, + STACK_OF(X509) *certs, unsigned int flags); + +int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags); +CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags); + +int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out, + unsigned int flags); +CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, + unsigned int flags); + +int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms, + const unsigned char *key, size_t keylen, + BIO *dcont, BIO *out, unsigned int flags); + +CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, + const unsigned char *key, + size_t keylen, unsigned int flags); + +int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph, + const unsigned char *key, size_t keylen); + +int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, + X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags); + +int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms, + STACK_OF(X509) *certs, + X509_STORE *store, unsigned int flags); + +STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms); + +CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in, + const EVP_CIPHER *cipher, unsigned int flags); + +int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert, + BIO *dcont, BIO *out, unsigned int flags); + +int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert); +int CMS_decrypt_set1_key(CMS_ContentInfo *cms, + unsigned char *key, size_t keylen, + const unsigned char *id, size_t idlen); +int CMS_decrypt_set1_password(CMS_ContentInfo *cms, + unsigned char *pass, ossl_ssize_t passlen); + +STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms); +int CMS_RecipientInfo_type(CMS_RecipientInfo *ri); +EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri); +CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher); +CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms, + X509 *recip, unsigned int flags); +int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey); +int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert); +int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri, + EVP_PKEY **pk, X509 **recip, + X509_ALGOR **palg); +int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); + +CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid, + unsigned char *key, size_t keylen, + unsigned char *id, size_t idlen, + ASN1_GENERALIZEDTIME *date, + ASN1_OBJECT *otherTypeId, + ASN1_TYPE *otherType); + +int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, + X509_ALGOR **palg, + ASN1_OCTET_STRING **pid, + ASN1_GENERALIZEDTIME **pdate, + ASN1_OBJECT **potherid, + ASN1_TYPE **pothertype); + +int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, + unsigned char *key, size_t keylen); + +int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, + const unsigned char *id, size_t idlen); + +int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri, + unsigned char *pass, + ossl_ssize_t passlen); + +CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms, + int iter, int wrap_nid, + int pbe_nid, + unsigned char *pass, + ossl_ssize_t passlen, + const EVP_CIPHER *kekciph); + +int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); +int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); + +int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out, + unsigned int flags); +CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags); + +int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid); +const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms); + +CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms); +int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert); +int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert); +STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms); + +CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms); +int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl); +int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl); +STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms); + +int CMS_SignedData_init(CMS_ContentInfo *cms); +CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, + X509 *signer, EVP_PKEY *pk, const EVP_MD *md, + unsigned int flags); +EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si); +EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si); +STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms); + +void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer); +int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, ASN1_INTEGER **sno); +int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert); +int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs, + unsigned int flags); +void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, + X509 **signer, X509_ALGOR **pdig, + X509_ALGOR **psig); +ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si); +int CMS_SignerInfo_sign(CMS_SignerInfo *si); +int CMS_SignerInfo_verify(CMS_SignerInfo *si); +int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain); + +int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs); +int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs, + int algnid, int keysize); +int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap); + +int CMS_signed_get_attr_count(const CMS_SignerInfo *si); +int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, + int lastpos); +int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc); +X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc); +int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); +int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); +int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, + int nid, int type, + const void *bytes, int len); +int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, + const char *attrname, int type, + const void *bytes, int len); +void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid, + int lastpos, int type); + +int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si); +int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, + int lastpos); +int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int lastpos); +X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc); +X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc); +int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); +int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, + const ASN1_OBJECT *obj, int type, + const void *bytes, int len); +int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, + int nid, int type, + const void *bytes, int len); +int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, + const char *attrname, int type, + const void *bytes, int len); +void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, + int lastpos, int type); + +int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr); +CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, + int allorfirst, + STACK_OF(GENERAL_NAMES) + *receiptList, STACK_OF(GENERAL_NAMES) + *receiptsTo); +int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr); +void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, + ASN1_STRING **pcid, + int *pallorfirst, + STACK_OF(GENERAL_NAMES) **plist, + STACK_OF(GENERAL_NAMES) **prto); +int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, + X509_ALGOR **palg, + ASN1_OCTET_STRING **pukm); +STACK_OF(CMS_RecipientEncryptedKey) +*CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri); + +int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri, + X509_ALGOR **pubalg, + ASN1_BIT_STRING **pubkey, + ASN1_OCTET_STRING **keyid, + X509_NAME **issuer, + ASN1_INTEGER **sno); + +int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert); + +int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek, + ASN1_OCTET_STRING **keyid, + ASN1_GENERALIZEDTIME **tm, + CMS_OtherKeyAttribute **other, + X509_NAME **issuer, ASN1_INTEGER **sno); +int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek, + X509 *cert); +int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk); +EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri); +int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms, + CMS_RecipientInfo *ri, + CMS_RecipientEncryptedKey *rek); + +int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg, + ASN1_OCTET_STRING *ukm, int keylen); + +/* Backward compatibility for spelling errors. */ +# define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM +# define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \ + CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/comperr.h postgresql-hll-2.14/include/openssl/comperr.h --- postgresql-hll-2.14_old/include/openssl/comperr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/comperr.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,44 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_COMPERR_H +# define HEADER_COMPERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_COMP + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_COMP_strings(void); + +/* + * COMP function codes. + */ +# define COMP_F_BIO_ZLIB_FLUSH 99 +# define COMP_F_BIO_ZLIB_NEW 100 +# define COMP_F_BIO_ZLIB_READ 101 +# define COMP_F_BIO_ZLIB_WRITE 102 +# define COMP_F_COMP_CTX_NEW 103 + +/* + * COMP reason codes. + */ +# define COMP_R_ZLIB_DEFLATE_ERROR 99 +# define COMP_R_ZLIB_INFLATE_ERROR 100 +# define COMP_R_ZLIB_NOT_SUPPORTED 101 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/comp.h postgresql-hll-2.14/include/openssl/comp.h --- postgresql-hll-2.14_old/include/openssl/comp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/comp.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,53 @@ +/* + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_COMP_H +# define HEADER_COMP_H + +# include + +# ifndef OPENSSL_NO_COMP +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + + + +COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); +const COMP_METHOD *COMP_CTX_get_method(const COMP_CTX *ctx); +int COMP_CTX_get_type(const COMP_CTX* comp); +int COMP_get_type(const COMP_METHOD *meth); +const char *COMP_get_name(const COMP_METHOD *meth); +void COMP_CTX_free(COMP_CTX *ctx); + +int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); +int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen, + unsigned char *in, int ilen); + +COMP_METHOD *COMP_zlib(void); + +#if OPENSSL_API_COMPAT < 0x10100000L +#define COMP_zlib_cleanup() while(0) continue +#endif + +# ifdef HEADER_BIO_H +# ifdef ZLIB +const BIO_METHOD *BIO_f_zlib(void); +# endif +# endif + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/conf_api.h postgresql-hll-2.14/include/openssl/conf_api.h --- postgresql-hll-2.14_old/include/openssl/conf_api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/conf_api.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,40 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CONF_API_H +# define HEADER_CONF_API_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Up until OpenSSL 0.9.5a, this was new_section */ +CONF_VALUE *_CONF_new_section(CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was get_section */ +CONF_VALUE *_CONF_get_section(const CONF *conf, const char *section); +/* Up until OpenSSL 0.9.5a, this was CONF_get_section */ +STACK_OF(CONF_VALUE) *_CONF_get_section_values(const CONF *conf, + const char *section); + +int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value); +char *_CONF_get_string(const CONF *conf, const char *section, + const char *name); +long _CONF_get_number(const CONF *conf, const char *section, + const char *name); + +int _CONF_new_data(CONF *conf); +void _CONF_free_data(CONF *conf); + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/conferr.h postgresql-hll-2.14/include/openssl/conferr.h --- postgresql-hll-2.14_old/include/openssl/conferr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/conferr.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,76 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CONFERR_H +# define HEADER_CONFERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_CONF_strings(void); + +/* + * CONF function codes. + */ +# define CONF_F_CONF_DUMP_FP 104 +# define CONF_F_CONF_LOAD 100 +# define CONF_F_CONF_LOAD_FP 103 +# define CONF_F_CONF_PARSE_LIST 119 +# define CONF_F_DEF_LOAD 120 +# define CONF_F_DEF_LOAD_BIO 121 +# define CONF_F_GET_NEXT_FILE 107 +# define CONF_F_MODULE_ADD 122 +# define CONF_F_MODULE_INIT 115 +# define CONF_F_MODULE_LOAD_DSO 117 +# define CONF_F_MODULE_RUN 118 +# define CONF_F_NCONF_DUMP_BIO 105 +# define CONF_F_NCONF_DUMP_FP 106 +# define CONF_F_NCONF_GET_NUMBER_E 112 +# define CONF_F_NCONF_GET_SECTION 108 +# define CONF_F_NCONF_GET_STRING 109 +# define CONF_F_NCONF_LOAD 113 +# define CONF_F_NCONF_LOAD_BIO 110 +# define CONF_F_NCONF_LOAD_FP 114 +# define CONF_F_NCONF_NEW 111 +# define CONF_F_PROCESS_INCLUDE 116 +# define CONF_F_SSL_MODULE_INIT 123 +# define CONF_F_STR_COPY 101 + +/* + * CONF reason codes. + */ +# define CONF_R_ERROR_LOADING_DSO 110 +# define CONF_R_LIST_CANNOT_BE_NULL 115 +# define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 +# define CONF_R_MISSING_EQUAL_SIGN 101 +# define CONF_R_MISSING_INIT_FUNCTION 112 +# define CONF_R_MODULE_INITIALIZATION_ERROR 109 +# define CONF_R_NO_CLOSE_BRACE 102 +# define CONF_R_NO_CONF 105 +# define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106 +# define CONF_R_NO_SECTION 107 +# define CONF_R_NO_SUCH_FILE 114 +# define CONF_R_NO_VALUE 108 +# define CONF_R_NUMBER_TOO_LARGE 121 +# define CONF_R_RECURSIVE_DIRECTORY_INCLUDE 111 +# define CONF_R_SSL_COMMAND_SECTION_EMPTY 117 +# define CONF_R_SSL_COMMAND_SECTION_NOT_FOUND 118 +# define CONF_R_SSL_SECTION_EMPTY 119 +# define CONF_R_SSL_SECTION_NOT_FOUND 120 +# define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 +# define CONF_R_UNKNOWN_MODULE_NAME 113 +# define CONF_R_VARIABLE_EXPANSION_TOO_LONG 116 +# define CONF_R_VARIABLE_HAS_NO_VALUE 104 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/conf.h postgresql-hll-2.14/include/openssl/conf.h --- postgresql-hll-2.14_old/include/openssl/conf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/conf.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,168 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CONF_H +# define HEADER_CONF_H + +# include +# include +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char *section; + char *name; + char *value; +} CONF_VALUE; + +DEFINE_STACK_OF(CONF_VALUE) +DEFINE_LHASH_OF(CONF_VALUE); + +struct conf_st; +struct conf_method_st; +typedef struct conf_method_st CONF_METHOD; + +struct conf_method_st { + const char *name; + CONF *(*create) (CONF_METHOD *meth); + int (*init) (CONF *conf); + int (*destroy) (CONF *conf); + int (*destroy_data) (CONF *conf); + int (*load_bio) (CONF *conf, BIO *bp, long *eline); + int (*dump) (const CONF *conf, BIO *bp); + int (*is_number) (const CONF *conf, char c); + int (*to_int) (const CONF *conf, char c); + int (*load) (CONF *conf, const char *name, long *eline); +}; + +/* Module definitions */ + +typedef struct conf_imodule_st CONF_IMODULE; +typedef struct conf_module_st CONF_MODULE; + +DEFINE_STACK_OF(CONF_MODULE) +DEFINE_STACK_OF(CONF_IMODULE) + +/* DSO module function typedefs */ +typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf); +typedef void conf_finish_func (CONF_IMODULE *md); + +# define CONF_MFLAGS_IGNORE_ERRORS 0x1 +# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2 +# define CONF_MFLAGS_SILENT 0x4 +# define CONF_MFLAGS_NO_DSO 0x8 +# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 +# define CONF_MFLAGS_DEFAULT_SECTION 0x20 + +int CONF_set_default_method(CONF_METHOD *meth); +void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash); +LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, + long *eline); +# ifndef OPENSSL_NO_STDIO +LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, + long *eline); +# endif +LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, + long *eline); +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, + const char *section); +char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group, + const char *name); +long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group, + const char *name); +void CONF_free(LHASH_OF(CONF_VALUE) *conf); +#ifndef OPENSSL_NO_STDIO +int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out); +#endif +int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out); + +DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name)) + +#if OPENSSL_API_COMPAT < 0x10100000L +# define OPENSSL_no_config() \ + OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL) +#endif + +/* + * New conf code. The semantics are different from the functions above. If + * that wasn't the case, the above functions would have been replaced + */ + +struct conf_st { + CONF_METHOD *meth; + void *meth_data; + LHASH_OF(CONF_VALUE) *data; +}; + +CONF *NCONF_new(CONF_METHOD *meth); +CONF_METHOD *NCONF_default(void); +CONF_METHOD *NCONF_WIN32(void); +void NCONF_free(CONF *conf); +void NCONF_free_data(CONF *conf); + +int NCONF_load(CONF *conf, const char *file, long *eline); +# ifndef OPENSSL_NO_STDIO +int NCONF_load_fp(CONF *conf, FILE *fp, long *eline); +# endif +int NCONF_load_bio(CONF *conf, BIO *bp, long *eline); +STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, + const char *section); +char *NCONF_get_string(const CONF *conf, const char *group, const char *name); +int NCONF_get_number_e(const CONF *conf, const char *group, const char *name, + long *result); +#ifndef OPENSSL_NO_STDIO +int NCONF_dump_fp(const CONF *conf, FILE *out); +#endif +int NCONF_dump_bio(const CONF *conf, BIO *out); + +#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r) + +/* Module functions */ + +int CONF_modules_load(const CONF *cnf, const char *appname, + unsigned long flags); +int CONF_modules_load_file(const char *filename, const char *appname, + unsigned long flags); +void CONF_modules_unload(int all); +void CONF_modules_finish(void); +#if OPENSSL_API_COMPAT < 0x10100000L +# define CONF_modules_free() while(0) continue +#endif +int CONF_module_add(const char *name, conf_init_func *ifunc, + conf_finish_func *ffunc); + +const char *CONF_imodule_get_name(const CONF_IMODULE *md); +const char *CONF_imodule_get_value(const CONF_IMODULE *md); +void *CONF_imodule_get_usr_data(const CONF_IMODULE *md); +void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data); +CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md); +unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md); +void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags); +void *CONF_module_get_usr_data(CONF_MODULE *pmod); +void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data); + +char *CONF_get1_default_config_file(void); + +int CONF_parse_list(const char *list, int sep, int nospc, + int (*list_cb) (const char *elem, int len, void *usr), + void *arg); + +void OPENSSL_load_builtin_modules(void); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cryptoerr.h postgresql-hll-2.14/include/openssl/cryptoerr.h --- postgresql-hll-2.14_old/include/openssl/cryptoerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cryptoerr.h 2020-12-12 17:06:43.328349083 +0800 @@ -0,0 +1,57 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CRYPTOERR_H +# define HEADER_CRYPTOERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_CRYPTO_strings(void); + +/* + * CRYPTO function codes. + */ +# define CRYPTO_F_CMAC_CTX_NEW 120 +# define CRYPTO_F_CRYPTO_DUP_EX_DATA 110 +# define CRYPTO_F_CRYPTO_FREE_EX_DATA 111 +# define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 +# define CRYPTO_F_CRYPTO_MEMDUP 115 +# define CRYPTO_F_CRYPTO_NEW_EX_DATA 112 +# define CRYPTO_F_CRYPTO_OCB128_COPY_CTX 121 +# define CRYPTO_F_CRYPTO_OCB128_INIT 122 +# define CRYPTO_F_CRYPTO_SET_EX_DATA 102 +# define CRYPTO_F_FIPS_MODE_SET 109 +# define CRYPTO_F_GET_AND_LOCK 113 +# define CRYPTO_F_OPENSSL_ATEXIT 114 +# define CRYPTO_F_OPENSSL_BUF2HEXSTR 117 +# define CRYPTO_F_OPENSSL_FOPEN 119 +# define CRYPTO_F_OPENSSL_HEXSTR2BUF 118 +# define CRYPTO_F_OPENSSL_INIT_CRYPTO 116 +# define CRYPTO_F_OPENSSL_LH_NEW 126 +# define CRYPTO_F_OPENSSL_SK_DEEP_COPY 127 +# define CRYPTO_F_OPENSSL_SK_DUP 128 +# define CRYPTO_F_PKEY_HMAC_INIT 123 +# define CRYPTO_F_PKEY_POLY1305_INIT 124 +# define CRYPTO_F_PKEY_SIPHASH_INIT 125 +# define CRYPTO_F_SK_RESERVE 129 + +/* + * CRYPTO reason codes. + */ +# define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED 101 +# define CRYPTO_R_ILLEGAL_HEX_DIGIT 102 +# define CRYPTO_R_ODD_NUMBER_OF_DIGITS 103 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/crypto.h postgresql-hll-2.14/include/openssl/crypto.h --- postgresql-hll-2.14_old/include/openssl/crypto.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/crypto.h 2020-12-12 17:06:43.329349096 +0800 @@ -0,0 +1,445 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CRYPTO_H +# define HEADER_CRYPTO_H + +# include +# include + +# include + +# ifndef OPENSSL_NO_STDIO +# include +# endif + +# include +# include +# include +# include +# include + +# ifdef CHARSET_EBCDIC +# include +# endif + +/* + * Resolve problems on some operating systems with symbol names that clash + * one way or another + */ +# include + +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSLeay OpenSSL_version_num +# define SSLeay_version OpenSSL_version +# define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER +# define SSLEAY_VERSION OPENSSL_VERSION +# define SSLEAY_CFLAGS OPENSSL_CFLAGS +# define SSLEAY_BUILT_ON OPENSSL_BUILT_ON +# define SSLEAY_PLATFORM OPENSSL_PLATFORM +# define SSLEAY_DIR OPENSSL_DIR + +/* + * Old type for allocating dynamic locks. No longer used. Use the new thread + * API instead. + */ +typedef struct { + int dummy; +} CRYPTO_dynlock; + +# endif /* OPENSSL_API_COMPAT */ + +typedef void CRYPTO_RWLOCK; + +CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void); +int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock); +int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock); +int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock); +void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock); + +int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock); + +/* + * The following can be used to detect memory leaks in the library. If + * used, it turns on malloc checking + */ +# define CRYPTO_MEM_CHECK_OFF 0x0 /* Control only */ +# define CRYPTO_MEM_CHECK_ON 0x1 /* Control and mode bit */ +# define CRYPTO_MEM_CHECK_ENABLE 0x2 /* Control and mode bit */ +# define CRYPTO_MEM_CHECK_DISABLE 0x3 /* Control only */ + +struct crypto_ex_data_st { + STACK_OF(void) *sk; +}; +DEFINE_STACK_OF(void) + +/* + * Per class, we have a STACK of function pointers. + */ +# define CRYPTO_EX_INDEX_SSL 0 +# define CRYPTO_EX_INDEX_SSL_CTX 1 +# define CRYPTO_EX_INDEX_SSL_SESSION 2 +# define CRYPTO_EX_INDEX_X509 3 +# define CRYPTO_EX_INDEX_X509_STORE 4 +# define CRYPTO_EX_INDEX_X509_STORE_CTX 5 +# define CRYPTO_EX_INDEX_DH 6 +# define CRYPTO_EX_INDEX_DSA 7 +# define CRYPTO_EX_INDEX_EC_KEY 8 +# define CRYPTO_EX_INDEX_RSA 9 +# define CRYPTO_EX_INDEX_ENGINE 10 +# define CRYPTO_EX_INDEX_UI 11 +# define CRYPTO_EX_INDEX_BIO 12 +# define CRYPTO_EX_INDEX_APP 13 +# define CRYPTO_EX_INDEX_UI_METHOD 14 +# define CRYPTO_EX_INDEX_DRBG 15 +# define CRYPTO_EX_INDEX__COUNT 16 + +/* No longer needed, so this is a no-op */ +#define OPENSSL_malloc_init() while(0) continue + +int CRYPTO_mem_ctrl(int mode); + +# define OPENSSL_malloc(num) \ + CRYPTO_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_zalloc(num) \ + CRYPTO_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_realloc(addr, num) \ + CRYPTO_realloc(addr, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_clear_realloc(addr, old_num, num) \ + CRYPTO_clear_realloc(addr, old_num, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_clear_free(addr, num) \ + CRYPTO_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_free(addr) \ + CRYPTO_free(addr, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_memdup(str, s) \ + CRYPTO_memdup((str), s, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_strdup(str) \ + CRYPTO_strdup(str, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_strndup(str, n) \ + CRYPTO_strndup(str, n, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_malloc(num) \ + CRYPTO_secure_malloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_zalloc(num) \ + CRYPTO_secure_zalloc(num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_free(addr) \ + CRYPTO_secure_free(addr, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_clear_free(addr, num) \ + CRYPTO_secure_clear_free(addr, num, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_secure_actual_size(ptr) \ + CRYPTO_secure_actual_size(ptr) + +size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); +size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz); +size_t OPENSSL_strnlen(const char *str, size_t maxlen); +char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len); +unsigned char *OPENSSL_hexstr2buf(const char *str, long *len); +int OPENSSL_hexchar2int(unsigned char c); + +# define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U<<(sizeof(int)*8-1))-1)/sizeof(type)) + +unsigned long OpenSSL_version_num(void); +const char *OpenSSL_version(int type); +# define OPENSSL_VERSION 0 +# define OPENSSL_CFLAGS 1 +# define OPENSSL_BUILT_ON 2 +# define OPENSSL_PLATFORM 3 +# define OPENSSL_DIR 4 +# define OPENSSL_ENGINES_DIR 5 + +int OPENSSL_issetugid(void); + +typedef void CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad, + int idx, long argl, void *argp); +typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, + void *from_d, int idx, long argl, void *argp); +__owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, + CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, + CRYPTO_EX_free *free_func); +/* No longer use an index. */ +int CRYPTO_free_ex_index(int class_index, int idx); + +/* + * Initialise/duplicate/free CRYPTO_EX_DATA variables corresponding to a + * given class (invokes whatever per-class callbacks are applicable) + */ +int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); +int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, + const CRYPTO_EX_DATA *from); + +void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad); + +/* + * Get/set data in a CRYPTO_EX_DATA variable corresponding to a particular + * index (relative to the class type involved) + */ +int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val); +void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); + +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * This function cleans up all "ex_data" state. It mustn't be called under + * potential race-conditions. + */ +# define CRYPTO_cleanup_all_ex_data() while(0) continue + +/* + * The old locking functions have been removed completely without compatibility + * macros. This is because the old functions either could not properly report + * errors, or the returned error values were not clearly documented. + * Replacing the locking functions with no-ops would cause race condition + * issues in the affected applications. It is far better for them to fail at + * compile time. + * On the other hand, the locking callbacks are no longer used. Consequently, + * the callback management functions can be safely replaced with no-op macros. + */ +# define CRYPTO_num_locks() (1) +# define CRYPTO_set_locking_callback(func) +# define CRYPTO_get_locking_callback() (NULL) +# define CRYPTO_set_add_lock_callback(func) +# define CRYPTO_get_add_lock_callback() (NULL) + +/* + * These defines where used in combination with the old locking callbacks, + * they are not called anymore, but old code that's not called might still + * use them. + */ +# define CRYPTO_LOCK 1 +# define CRYPTO_UNLOCK 2 +# define CRYPTO_READ 4 +# define CRYPTO_WRITE 8 + +/* This structure is no longer used */ +typedef struct crypto_threadid_st { + int dummy; +} CRYPTO_THREADID; +/* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ +# define CRYPTO_THREADID_set_numeric(id, val) +# define CRYPTO_THREADID_set_pointer(id, ptr) +# define CRYPTO_THREADID_set_callback(threadid_func) (0) +# define CRYPTO_THREADID_get_callback() (NULL) +# define CRYPTO_THREADID_current(id) +# define CRYPTO_THREADID_cmp(a, b) (-1) +# define CRYPTO_THREADID_cpy(dest, src) +# define CRYPTO_THREADID_hash(id) (0UL) + +# if OPENSSL_API_COMPAT < 0x10000000L +# define CRYPTO_set_id_callback(func) +# define CRYPTO_get_id_callback() (NULL) +# define CRYPTO_thread_id() (0UL) +# endif /* OPENSSL_API_COMPAT < 0x10000000L */ + +# define CRYPTO_set_dynlock_create_callback(dyn_create_function) +# define CRYPTO_set_dynlock_lock_callback(dyn_lock_function) +# define CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function) +# define CRYPTO_get_dynlock_create_callback() (NULL) +# define CRYPTO_get_dynlock_lock_callback() (NULL) +# define CRYPTO_get_dynlock_destroy_callback() (NULL) +# endif /* OPENSSL_API_COMPAT < 0x10100000L */ + +int CRYPTO_set_mem_functions( + void *(*m) (size_t, const char *, int), + void *(*r) (void *, size_t, const char *, int), + void (*f) (void *, const char *, int)); +int CRYPTO_set_mem_debug(int flag); +void CRYPTO_get_mem_functions( + void *(**m) (size_t, const char *, int), + void *(**r) (void *, size_t, const char *, int), + void (**f) (void *, const char *, int)); + +void *CRYPTO_malloc(size_t num, const char *file, int line); +void *CRYPTO_zalloc(size_t num, const char *file, int line); +void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); +char *CRYPTO_strdup(const char *str, const char *file, int line); +char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); +void CRYPTO_free(void *ptr, const char *file, int line); +void CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line); +void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line); +void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num, + const char *file, int line); + +int CRYPTO_secure_malloc_init(size_t sz, int minsize); +int CRYPTO_secure_malloc_done(void); +void *CRYPTO_secure_malloc(size_t num, const char *file, int line); +void *CRYPTO_secure_zalloc(size_t num, const char *file, int line); +void CRYPTO_secure_free(void *ptr, const char *file, int line); +void CRYPTO_secure_clear_free(void *ptr, size_t num, + const char *file, int line); +int CRYPTO_secure_allocated(const void *ptr); +int CRYPTO_secure_malloc_initialized(void); +size_t CRYPTO_secure_actual_size(void *ptr); +size_t CRYPTO_secure_used(void); + +void OPENSSL_cleanse(void *ptr, size_t len); + +# ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_mem_debug_push(info) \ + CRYPTO_mem_debug_push(info, OPENSSL_FILE, OPENSSL_LINE) +# define OPENSSL_mem_debug_pop() \ + CRYPTO_mem_debug_pop() +int CRYPTO_mem_debug_push(const char *info, const char *file, int line); +int CRYPTO_mem_debug_pop(void); +void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount); + +/*- + * Debugging functions (enabled by CRYPTO_set_mem_debug(1)) + * The flag argument has the following significance: + * 0: called before the actual memory allocation has taken place + * 1: called after the actual memory allocation has taken place + */ +void CRYPTO_mem_debug_malloc(void *addr, size_t num, int flag, + const char *file, int line); +void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num, int flag, + const char *file, int line); +void CRYPTO_mem_debug_free(void *addr, int flag, + const char *file, int line); + +int CRYPTO_mem_leaks_cb(int (*cb) (const char *str, size_t len, void *u), + void *u); +# ifndef OPENSSL_NO_STDIO +int CRYPTO_mem_leaks_fp(FILE *); +# endif +int CRYPTO_mem_leaks(BIO *bio); +# endif + +/* die if we have to */ +ossl_noreturn void OPENSSL_die(const char *assertion, const char *file, int line); +# if OPENSSL_API_COMPAT < 0x10100000L +# define OpenSSLDie(f,l,a) OPENSSL_die((a),(f),(l)) +# endif +# define OPENSSL_assert(e) \ + (void)((e) ? 0 : (OPENSSL_die("assertion failed: " #e, OPENSSL_FILE, OPENSSL_LINE), 1)) + +int OPENSSL_isservice(void); + +int FIPS_mode(void); +int FIPS_mode_set(int r); + +void OPENSSL_init(void); +# ifdef OPENSSL_SYS_UNIX +void OPENSSL_fork_prepare(void); +void OPENSSL_fork_parent(void); +void OPENSSL_fork_child(void); +# endif + +struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result); +int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); +int OPENSSL_gmtime_diff(int *pday, int *psec, + const struct tm *from, const struct tm *to); + +/* + * CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. + * It takes an amount of time dependent on |len|, but independent of the + * contents of |a| and |b|. Unlike memcmp, it cannot be used to put elements + * into a defined order as the return value when a != b is undefined, other + * than to be non-zero. + */ +int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len); + +/* Standard initialisation options */ +# define OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS 0x00000001L +# define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L +# define OPENSSL_INIT_ADD_ALL_CIPHERS 0x00000004L +# define OPENSSL_INIT_ADD_ALL_DIGESTS 0x00000008L +# define OPENSSL_INIT_NO_ADD_ALL_CIPHERS 0x00000010L +# define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0x00000020L +# define OPENSSL_INIT_LOAD_CONFIG 0x00000040L +# define OPENSSL_INIT_NO_LOAD_CONFIG 0x00000080L +# define OPENSSL_INIT_ASYNC 0x00000100L +# define OPENSSL_INIT_ENGINE_RDRAND 0x00000200L +# define OPENSSL_INIT_ENGINE_DYNAMIC 0x00000400L +# define OPENSSL_INIT_ENGINE_OPENSSL 0x00000800L +# define OPENSSL_INIT_ENGINE_CRYPTODEV 0x00001000L +# define OPENSSL_INIT_ENGINE_CAPI 0x00002000L +# define OPENSSL_INIT_ENGINE_PADLOCK 0x00004000L +# define OPENSSL_INIT_ENGINE_AFALG 0x00008000L +/* OPENSSL_INIT_ZLIB 0x00010000L */ +# define OPENSSL_INIT_ATFORK 0x00020000L +/* OPENSSL_INIT_BASE_ONLY 0x00040000L */ +# define OPENSSL_INIT_NO_ATEXIT 0x00080000L +/* OPENSSL_INIT flag range 0xfff00000 reserved for OPENSSL_init_ssl() */ +/* Max OPENSSL_INIT flag value is 0x80000000 */ + +/* openssl and dasync not counted as builtin */ +# define OPENSSL_INIT_ENGINE_ALL_BUILTIN \ + (OPENSSL_INIT_ENGINE_RDRAND | OPENSSL_INIT_ENGINE_DYNAMIC \ + | OPENSSL_INIT_ENGINE_CRYPTODEV | OPENSSL_INIT_ENGINE_CAPI | \ + OPENSSL_INIT_ENGINE_PADLOCK) + + +/* Library initialisation functions */ +void OPENSSL_cleanup(void); +int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); +int OPENSSL_atexit(void (*handler)(void)); +void OPENSSL_thread_stop(void); + +/* Low-level control of initialization */ +OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void); +# ifndef OPENSSL_NO_STDIO +int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings, + const char *config_filename); +void OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *settings, + unsigned long flags); +int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings, + const char *config_appname); +# endif +void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings); + +# if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) +# if defined(_WIN32) +# if defined(BASETYPES) || defined(_WINDEF_H) +/* application has to include in order to use this */ +typedef DWORD CRYPTO_THREAD_LOCAL; +typedef DWORD CRYPTO_THREAD_ID; + +typedef LONG CRYPTO_ONCE; +# define CRYPTO_ONCE_STATIC_INIT 0 +# endif +# else +# include +typedef pthread_once_t CRYPTO_ONCE; +typedef pthread_key_t CRYPTO_THREAD_LOCAL; +typedef pthread_t CRYPTO_THREAD_ID; + +# define CRYPTO_ONCE_STATIC_INIT PTHREAD_ONCE_INIT +# endif +# endif + +# if !defined(CRYPTO_ONCE_STATIC_INIT) +typedef unsigned int CRYPTO_ONCE; +typedef unsigned int CRYPTO_THREAD_LOCAL; +typedef unsigned int CRYPTO_THREAD_ID; +# define CRYPTO_ONCE_STATIC_INIT 0 +# endif + +int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void)); + +int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *)); +void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key); +int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val); +int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key); + +CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void); +int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/cterr.h postgresql-hll-2.14/include/openssl/cterr.h --- postgresql-hll-2.14_old/include/openssl/cterr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/cterr.h 2020-12-12 17:06:43.329349096 +0800 @@ -0,0 +1,80 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CTERR_H +# define HEADER_CTERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_CT + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_CT_strings(void); + +/* + * CT function codes. + */ +# define CT_F_CTLOG_NEW 117 +# define CT_F_CTLOG_NEW_FROM_BASE64 118 +# define CT_F_CTLOG_NEW_FROM_CONF 119 +# define CT_F_CTLOG_STORE_LOAD_CTX_NEW 122 +# define CT_F_CTLOG_STORE_LOAD_FILE 123 +# define CT_F_CTLOG_STORE_LOAD_LOG 130 +# define CT_F_CTLOG_STORE_NEW 131 +# define CT_F_CT_BASE64_DECODE 124 +# define CT_F_CT_POLICY_EVAL_CTX_NEW 133 +# define CT_F_CT_V1_LOG_ID_FROM_PKEY 125 +# define CT_F_I2O_SCT 107 +# define CT_F_I2O_SCT_LIST 108 +# define CT_F_I2O_SCT_SIGNATURE 109 +# define CT_F_O2I_SCT 110 +# define CT_F_O2I_SCT_LIST 111 +# define CT_F_O2I_SCT_SIGNATURE 112 +# define CT_F_SCT_CTX_NEW 126 +# define CT_F_SCT_CTX_VERIFY 128 +# define CT_F_SCT_NEW 100 +# define CT_F_SCT_NEW_FROM_BASE64 127 +# define CT_F_SCT_SET0_LOG_ID 101 +# define CT_F_SCT_SET1_EXTENSIONS 114 +# define CT_F_SCT_SET1_LOG_ID 115 +# define CT_F_SCT_SET1_SIGNATURE 116 +# define CT_F_SCT_SET_LOG_ENTRY_TYPE 102 +# define CT_F_SCT_SET_SIGNATURE_NID 103 +# define CT_F_SCT_SET_VERSION 104 + +/* + * CT reason codes. + */ +# define CT_R_BASE64_DECODE_ERROR 108 +# define CT_R_INVALID_LOG_ID_LENGTH 100 +# define CT_R_LOG_CONF_INVALID 109 +# define CT_R_LOG_CONF_INVALID_KEY 110 +# define CT_R_LOG_CONF_MISSING_DESCRIPTION 111 +# define CT_R_LOG_CONF_MISSING_KEY 112 +# define CT_R_LOG_KEY_INVALID 113 +# define CT_R_SCT_FUTURE_TIMESTAMP 116 +# define CT_R_SCT_INVALID 104 +# define CT_R_SCT_INVALID_SIGNATURE 107 +# define CT_R_SCT_LIST_INVALID 105 +# define CT_R_SCT_LOG_ID_MISMATCH 114 +# define CT_R_SCT_NOT_SET 106 +# define CT_R_SCT_UNSUPPORTED_VERSION 115 +# define CT_R_UNRECOGNIZED_SIGNATURE_NID 101 +# define CT_R_UNSUPPORTED_ENTRY_TYPE 102 +# define CT_R_UNSUPPORTED_VERSION 103 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ct.h postgresql-hll-2.14/include/openssl/ct.h --- postgresql-hll-2.14_old/include/openssl/ct.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ct.h 2020-12-12 17:06:43.329349096 +0800 @@ -0,0 +1,474 @@ +/* + * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CT_H +# define HEADER_CT_H + +# include + +# ifndef OPENSSL_NO_CT +# include +# include +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + + +/* Minimum RSA key size, from RFC6962 */ +# define SCT_MIN_RSA_BITS 2048 + +/* All hashes are SHA256 in v1 of Certificate Transparency */ +# define CT_V1_HASHLEN SHA256_DIGEST_LENGTH + +typedef enum { + CT_LOG_ENTRY_TYPE_NOT_SET = -1, + CT_LOG_ENTRY_TYPE_X509 = 0, + CT_LOG_ENTRY_TYPE_PRECERT = 1 +} ct_log_entry_type_t; + +typedef enum { + SCT_VERSION_NOT_SET = -1, + SCT_VERSION_V1 = 0 +} sct_version_t; + +typedef enum { + SCT_SOURCE_UNKNOWN, + SCT_SOURCE_TLS_EXTENSION, + SCT_SOURCE_X509V3_EXTENSION, + SCT_SOURCE_OCSP_STAPLED_RESPONSE +} sct_source_t; + +typedef enum { + SCT_VALIDATION_STATUS_NOT_SET, + SCT_VALIDATION_STATUS_UNKNOWN_LOG, + SCT_VALIDATION_STATUS_VALID, + SCT_VALIDATION_STATUS_INVALID, + SCT_VALIDATION_STATUS_UNVERIFIED, + SCT_VALIDATION_STATUS_UNKNOWN_VERSION +} sct_validation_status_t; + +DEFINE_STACK_OF(SCT) +DEFINE_STACK_OF(CTLOG) + +/****************************************** + * CT policy evaluation context functions * + ******************************************/ + +/* + * Creates a new, empty policy evaluation context. + * The caller is responsible for calling CT_POLICY_EVAL_CTX_free when finished + * with the CT_POLICY_EVAL_CTX. + */ +CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new(void); + +/* Deletes a policy evaluation context and anything it owns. */ +void CT_POLICY_EVAL_CTX_free(CT_POLICY_EVAL_CTX *ctx); + +/* Gets the peer certificate that the SCTs are for */ +X509* CT_POLICY_EVAL_CTX_get0_cert(const CT_POLICY_EVAL_CTX *ctx); + +/* + * Sets the certificate associated with the received SCTs. + * Increments the reference count of cert. + * Returns 1 on success, 0 otherwise. + */ +int CT_POLICY_EVAL_CTX_set1_cert(CT_POLICY_EVAL_CTX *ctx, X509 *cert); + +/* Gets the issuer of the aforementioned certificate */ +X509* CT_POLICY_EVAL_CTX_get0_issuer(const CT_POLICY_EVAL_CTX *ctx); + +/* + * Sets the issuer of the certificate associated with the received SCTs. + * Increments the reference count of issuer. + * Returns 1 on success, 0 otherwise. + */ +int CT_POLICY_EVAL_CTX_set1_issuer(CT_POLICY_EVAL_CTX *ctx, X509 *issuer); + +/* Gets the CT logs that are trusted sources of SCTs */ +const CTLOG_STORE *CT_POLICY_EVAL_CTX_get0_log_store(const CT_POLICY_EVAL_CTX *ctx); + +/* Sets the log store that is in use. It must outlive the CT_POLICY_EVAL_CTX. */ +void CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE(CT_POLICY_EVAL_CTX *ctx, + CTLOG_STORE *log_store); + +/* + * Gets the time, in milliseconds since the Unix epoch, that will be used as the + * current time when checking whether an SCT was issued in the future. + * Such SCTs will fail validation, as required by RFC6962. + */ +uint64_t CT_POLICY_EVAL_CTX_get_time(const CT_POLICY_EVAL_CTX *ctx); + +/* + * Sets the time to evaluate SCTs against, in milliseconds since the Unix epoch. + * If an SCT's timestamp is after this time, it will be interpreted as having + * been issued in the future. RFC6962 states that "TLS clients MUST reject SCTs + * whose timestamp is in the future", so an SCT will not validate in this case. + */ +void CT_POLICY_EVAL_CTX_set_time(CT_POLICY_EVAL_CTX *ctx, uint64_t time_in_ms); + +/***************** + * SCT functions * + *****************/ + +/* + * Creates a new, blank SCT. + * The caller is responsible for calling SCT_free when finished with the SCT. + */ +SCT *SCT_new(void); + +/* + * Creates a new SCT from some base64-encoded strings. + * The caller is responsible for calling SCT_free when finished with the SCT. + */ +SCT *SCT_new_from_base64(unsigned char version, + const char *logid_base64, + ct_log_entry_type_t entry_type, + uint64_t timestamp, + const char *extensions_base64, + const char *signature_base64); + +/* + * Frees the SCT and the underlying data structures. + */ +void SCT_free(SCT *sct); + +/* + * Free a stack of SCTs, and the underlying SCTs themselves. + * Intended to be compatible with X509V3_EXT_FREE. + */ +void SCT_LIST_free(STACK_OF(SCT) *a); + +/* + * Returns the version of the SCT. + */ +sct_version_t SCT_get_version(const SCT *sct); + +/* + * Set the version of an SCT. + * Returns 1 on success, 0 if the version is unrecognized. + */ +__owur int SCT_set_version(SCT *sct, sct_version_t version); + +/* + * Returns the log entry type of the SCT. + */ +ct_log_entry_type_t SCT_get_log_entry_type(const SCT *sct); + +/* + * Set the log entry type of an SCT. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_log_entry_type(SCT *sct, ct_log_entry_type_t entry_type); + +/* + * Gets the ID of the log that an SCT came from. + * Ownership of the log ID remains with the SCT. + * Returns the length of the log ID. + */ +size_t SCT_get0_log_id(const SCT *sct, unsigned char **log_id); + +/* + * Set the log ID of an SCT to point directly to the *log_id specified. + * The SCT takes ownership of the specified pointer. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set0_log_id(SCT *sct, unsigned char *log_id, size_t log_id_len); + +/* + * Set the log ID of an SCT. + * This makes a copy of the log_id. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, + size_t log_id_len); + +/* + * Returns the timestamp for the SCT (epoch time in milliseconds). + */ +uint64_t SCT_get_timestamp(const SCT *sct); + +/* + * Set the timestamp of an SCT (epoch time in milliseconds). + */ +void SCT_set_timestamp(SCT *sct, uint64_t timestamp); + +/* + * Return the NID for the signature used by the SCT. + * For CT v1, this will be either NID_sha256WithRSAEncryption or + * NID_ecdsa_with_SHA256 (or NID_undef if incorrect/unset). + */ +int SCT_get_signature_nid(const SCT *sct); + +/* + * Set the signature type of an SCT + * For CT v1, this should be either NID_sha256WithRSAEncryption or + * NID_ecdsa_with_SHA256. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_signature_nid(SCT *sct, int nid); + +/* + * Set *ext to point to the extension data for the SCT. ext must not be NULL. + * The SCT retains ownership of this pointer. + * Returns length of the data pointed to. + */ +size_t SCT_get0_extensions(const SCT *sct, unsigned char **ext); + +/* + * Set the extensions of an SCT to point directly to the *ext specified. + * The SCT takes ownership of the specified pointer. + */ +void SCT_set0_extensions(SCT *sct, unsigned char *ext, size_t ext_len); + +/* + * Set the extensions of an SCT. + * This takes a copy of the ext. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_extensions(SCT *sct, const unsigned char *ext, + size_t ext_len); + +/* + * Set *sig to point to the signature for the SCT. sig must not be NULL. + * The SCT retains ownership of this pointer. + * Returns length of the data pointed to. + */ +size_t SCT_get0_signature(const SCT *sct, unsigned char **sig); + +/* + * Set the signature of an SCT to point directly to the *sig specified. + * The SCT takes ownership of the specified pointer. + */ +void SCT_set0_signature(SCT *sct, unsigned char *sig, size_t sig_len); + +/* + * Set the signature of an SCT to be a copy of the *sig specified. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set1_signature(SCT *sct, const unsigned char *sig, + size_t sig_len); + +/* + * The origin of this SCT, e.g. TLS extension, OCSP response, etc. + */ +sct_source_t SCT_get_source(const SCT *sct); + +/* + * Set the origin of this SCT, e.g. TLS extension, OCSP response, etc. + * Returns 1 on success, 0 otherwise. + */ +__owur int SCT_set_source(SCT *sct, sct_source_t source); + +/* + * Returns a text string describing the validation status of |sct|. + */ +const char *SCT_validation_status_string(const SCT *sct); + +/* + * Pretty-prints an |sct| to |out|. + * It will be indented by the number of spaces specified by |indent|. + * If |logs| is not NULL, it will be used to lookup the CT log that the SCT came + * from, so that the log name can be printed. + */ +void SCT_print(const SCT *sct, BIO *out, int indent, const CTLOG_STORE *logs); + +/* + * Pretty-prints an |sct_list| to |out|. + * It will be indented by the number of spaces specified by |indent|. + * SCTs will be delimited by |separator|. + * If |logs| is not NULL, it will be used to lookup the CT log that each SCT + * came from, so that the log names can be printed. + */ +void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent, + const char *separator, const CTLOG_STORE *logs); + +/* + * Gets the last result of validating this SCT. + * If it has not been validated yet, returns SCT_VALIDATION_STATUS_NOT_SET. + */ +sct_validation_status_t SCT_get_validation_status(const SCT *sct); + +/* + * Validates the given SCT with the provided context. + * Sets the "validation_status" field of the SCT. + * Returns 1 if the SCT is valid and the signature verifies. + * Returns 0 if the SCT is invalid or could not be verified. + * Returns -1 if an error occurs. + */ +__owur int SCT_validate(SCT *sct, const CT_POLICY_EVAL_CTX *ctx); + +/* + * Validates the given list of SCTs with the provided context. + * Sets the "validation_status" field of each SCT. + * Returns 1 if there are no invalid SCTs and all signatures verify. + * Returns 0 if at least one SCT is invalid or could not be verified. + * Returns a negative integer if an error occurs. + */ +__owur int SCT_LIST_validate(const STACK_OF(SCT) *scts, + CT_POLICY_EVAL_CTX *ctx); + + +/********************************* + * SCT parsing and serialisation * + *********************************/ + +/* + * Serialize (to TLS format) a stack of SCTs and return the length. + * "a" must not be NULL. + * If "pp" is NULL, just return the length of what would have been serialized. + * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer + * for data that caller is responsible for freeing (only if function returns + * successfully). + * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring + * that "*pp" is large enough to accept all of the serialized data. + * Returns < 0 on error, >= 0 indicating bytes written (or would have been) + * on success. + */ +__owur int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); + +/* + * Convert TLS format SCT list to a stack of SCTs. + * If "a" or "*a" is NULL, a new stack will be created that the caller is + * responsible for freeing (by calling SCT_LIST_free). + * "**pp" and "*pp" must not be NULL. + * Upon success, "*pp" will point to after the last bytes read, and a stack + * will be returned. + * Upon failure, a NULL pointer will be returned, and the position of "*pp" is + * not defined. + */ +STACK_OF(SCT) *o2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, + size_t len); + +/* + * Serialize (to DER format) a stack of SCTs and return the length. + * "a" must not be NULL. + * If "pp" is NULL, just returns the length of what would have been serialized. + * If "pp" is not NULL and "*pp" is null, function will allocate a new pointer + * for data that caller is responsible for freeing (only if function returns + * successfully). + * If "pp" is NULL and "*pp" is not NULL, caller is responsible for ensuring + * that "*pp" is large enough to accept all of the serialized data. + * Returns < 0 on error, >= 0 indicating bytes written (or would have been) + * on success. + */ +__owur int i2d_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp); + +/* + * Parses an SCT list in DER format and returns it. + * If "a" or "*a" is NULL, a new stack will be created that the caller is + * responsible for freeing (by calling SCT_LIST_free). + * "**pp" and "*pp" must not be NULL. + * Upon success, "*pp" will point to after the last bytes read, and a stack + * will be returned. + * Upon failure, a NULL pointer will be returned, and the position of "*pp" is + * not defined. + */ +STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, const unsigned char **pp, + long len); + +/* + * Serialize (to TLS format) an |sct| and write it to |out|. + * If |out| is null, no SCT will be output but the length will still be returned. + * If |out| points to a null pointer, a string will be allocated to hold the + * TLS-format SCT. It is the responsibility of the caller to free it. + * If |out| points to an allocated string, the TLS-format SCT will be written + * to it. + * The length of the SCT in TLS format will be returned. + */ +__owur int i2o_SCT(const SCT *sct, unsigned char **out); + +/* + * Parses an SCT in TLS format and returns it. + * If |psct| is not null, it will end up pointing to the parsed SCT. If it + * already points to a non-null pointer, the pointer will be free'd. + * |in| should be a pointer to a string containing the TLS-format SCT. + * |in| will be advanced to the end of the SCT if parsing succeeds. + * |len| should be the length of the SCT in |in|. + * Returns NULL if an error occurs. + * If the SCT is an unsupported version, only the SCT's 'sct' and 'sct_len' + * fields will be populated (with |in| and |len| respectively). + */ +SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len); + +/******************** + * CT log functions * + ********************/ + +/* + * Creates a new CT log instance with the given |public_key| and |name|. + * Takes ownership of |public_key| but copies |name|. + * Returns NULL if malloc fails or if |public_key| cannot be converted to DER. + * Should be deleted by the caller using CTLOG_free when no longer needed. + */ +CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name); + +/* + * Creates a new CTLOG instance with the base64-encoded SubjectPublicKeyInfo DER + * in |pkey_base64|. The |name| is a string to help users identify this log. + * Returns 1 on success, 0 on failure. + * Should be deleted by the caller using CTLOG_free when no longer needed. + */ +int CTLOG_new_from_base64(CTLOG ** ct_log, + const char *pkey_base64, const char *name); + +/* + * Deletes a CT log instance and its fields. + */ +void CTLOG_free(CTLOG *log); + +/* Gets the name of the CT log */ +const char *CTLOG_get0_name(const CTLOG *log); +/* Gets the ID of the CT log */ +void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id, + size_t *log_id_len); +/* Gets the public key of the CT log */ +EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log); + +/************************** + * CT log store functions * + **************************/ + +/* + * Creates a new CT log store. + * Should be deleted by the caller using CTLOG_STORE_free when no longer needed. + */ +CTLOG_STORE *CTLOG_STORE_new(void); + +/* + * Deletes a CT log store and all of the CT log instances held within. + */ +void CTLOG_STORE_free(CTLOG_STORE *store); + +/* + * Finds a CT log in the store based on its log ID. + * Returns the CT log, or NULL if no match is found. + */ +const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store, + const uint8_t *log_id, + size_t log_id_len); + +/* + * Loads a CT log list into a |store| from a |file|. + * Returns 1 if loading is successful, or 0 otherwise. + */ +__owur int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file); + +/* + * Loads the default CT log list into a |store|. + * Returns 1 if loading is successful, or 0 otherwise. + */ +__owur int CTLOG_STORE_load_default_file(CTLOG_STORE *store); + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/des.h postgresql-hll-2.14/include/openssl/des.h --- postgresql-hll-2.14_old/include/openssl/des.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/des.h 2020-12-12 17:06:43.329349096 +0800 @@ -0,0 +1,174 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DES_H +# define HEADER_DES_H + +# include + +# ifndef OPENSSL_NO_DES +# ifdef __cplusplus +extern "C" { +# endif +# include + +typedef unsigned int DES_LONG; + +# ifdef OPENSSL_BUILD_SHLIBCRYPTO +# undef OPENSSL_EXTERN +# define OPENSSL_EXTERN OPENSSL_EXPORT +# endif + +typedef unsigned char DES_cblock[8]; +typedef /* const */ unsigned char const_DES_cblock[8]; +/* + * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and + * const_DES_cblock * are incompatible pointer types. + */ + +typedef struct DES_ks { + union { + DES_cblock cblock; + /* + * make sure things are correct size on machines with 8 byte longs + */ + DES_LONG deslong[2]; + } ks[16]; +} DES_key_schedule; + +# define DES_KEY_SZ (sizeof(DES_cblock)) +# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) + +# define DES_ENCRYPT 1 +# define DES_DECRYPT 0 + +# define DES_CBC_MODE 0 +# define DES_PCBC_MODE 1 + +# define DES_ecb2_encrypt(i,o,k1,k2,e) \ + DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */ +# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) + +const char *DES_options(void); +void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, + DES_key_schedule *ks1, DES_key_schedule *ks2, + DES_key_schedule *ks3, int enc); +DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output, + long length, DES_key_schedule *schedule, + const_DES_cblock *ivec); +/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ +void DES_cbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, const_DES_cblock *inw, + const_DES_cblock *outw, int enc); +void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, + DES_key_schedule *ks, int enc); + +/* + * This is the DES encryption function that gets called by just about every + * other DES routine in the library. You should not use this function except + * to implement 'modes' of DES. I say this because the functions that call + * this routine do the conversion from 'char *' to long, and this needs to be + * done to make sure 'non-aligned' memory access do not occur. The + * characters are loaded 'little endian'. Data is a pointer to 2 unsigned + * long's and ks is the DES_key_schedule to use. enc, is non zero specifies + * encryption, zero if decryption. + */ +void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc); + +/* + * This functions is the same as DES_encrypt1() except that the DES initial + * permutation (IP) and final permutation (FP) have been left out. As for + * DES_encrypt1(), you should not use this function. It is used by the + * routines in the library that implement triple DES. IP() DES_encrypt2() + * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1() + * DES_encrypt1() DES_encrypt1() except faster :-). + */ +void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc); + +void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3); +void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, + long length, + DES_key_schedule *ks1, DES_key_schedule *ks2, + DES_key_schedule *ks3, DES_cblock *ivec, int enc); +void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int *num, int enc); +void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out, + int numbits, long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int enc); +void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *ks1, + DES_key_schedule *ks2, DES_key_schedule *ks3, + DES_cblock *ivec, int *num); +char *DES_fcrypt(const char *buf, const char *salt, char *ret); +char *DES_crypt(const char *buf, const char *salt); +void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, DES_key_schedule *schedule, + DES_cblock *ivec); +void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int enc); +DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], + long length, int out_count, DES_cblock *seed); +int DES_random_key(DES_cblock *ret); +void DES_set_odd_parity(DES_cblock *key); +int DES_check_key_parity(const_DES_cblock *key); +int DES_is_weak_key(const_DES_cblock *key); +/* + * DES_set_key (= set_key = DES_key_sched = key_sched) calls + * DES_set_key_checked if global variable DES_check_key is set, + * DES_set_key_unchecked otherwise. + */ +int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule); +int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule); +int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule); +void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule); +void DES_string_to_key(const char *str, DES_cblock *key); +void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2); +void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int *num, int enc); +void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, DES_key_schedule *schedule, + DES_cblock *ivec, int *num); + +# define DES_fixup_key_parity DES_set_odd_parity + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/dherr.h postgresql-hll-2.14/include/openssl/dherr.h --- postgresql-hll-2.14_old/include/openssl/dherr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/dherr.h 2020-12-12 17:06:43.329349096 +0800 @@ -0,0 +1,88 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DHERR_H +# define HEADER_DHERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_DH + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_DH_strings(void); + +/* + * DH function codes. + */ +# define DH_F_COMPUTE_KEY 102 +# define DH_F_DHPARAMS_PRINT_FP 101 +# define DH_F_DH_BUILTIN_GENPARAMS 106 +# define DH_F_DH_CHECK_EX 121 +# define DH_F_DH_CHECK_PARAMS_EX 122 +# define DH_F_DH_CHECK_PUB_KEY_EX 123 +# define DH_F_DH_CMS_DECRYPT 114 +# define DH_F_DH_CMS_SET_PEERKEY 115 +# define DH_F_DH_CMS_SET_SHARED_INFO 116 +# define DH_F_DH_METH_DUP 117 +# define DH_F_DH_METH_NEW 118 +# define DH_F_DH_METH_SET1_NAME 119 +# define DH_F_DH_NEW_BY_NID 104 +# define DH_F_DH_NEW_METHOD 105 +# define DH_F_DH_PARAM_DECODE 107 +# define DH_F_DH_PKEY_PUBLIC_CHECK 124 +# define DH_F_DH_PRIV_DECODE 110 +# define DH_F_DH_PRIV_ENCODE 111 +# define DH_F_DH_PUB_DECODE 108 +# define DH_F_DH_PUB_ENCODE 109 +# define DH_F_DO_DH_PRINT 100 +# define DH_F_GENERATE_KEY 103 +# define DH_F_PKEY_DH_CTRL_STR 120 +# define DH_F_PKEY_DH_DERIVE 112 +# define DH_F_PKEY_DH_INIT 125 +# define DH_F_PKEY_DH_KEYGEN 113 + +/* + * DH reason codes. + */ +# define DH_R_BAD_GENERATOR 101 +# define DH_R_BN_DECODE_ERROR 109 +# define DH_R_BN_ERROR 106 +# define DH_R_CHECK_INVALID_J_VALUE 115 +# define DH_R_CHECK_INVALID_Q_VALUE 116 +# define DH_R_CHECK_PUBKEY_INVALID 122 +# define DH_R_CHECK_PUBKEY_TOO_LARGE 123 +# define DH_R_CHECK_PUBKEY_TOO_SMALL 124 +# define DH_R_CHECK_P_NOT_PRIME 117 +# define DH_R_CHECK_P_NOT_SAFE_PRIME 118 +# define DH_R_CHECK_Q_NOT_PRIME 119 +# define DH_R_DECODE_ERROR 104 +# define DH_R_INVALID_PARAMETER_NAME 110 +# define DH_R_INVALID_PARAMETER_NID 114 +# define DH_R_INVALID_PUBKEY 102 +# define DH_R_KDF_PARAMETER_ERROR 112 +# define DH_R_KEYS_NOT_SET 108 +# define DH_R_MISSING_PUBKEY 125 +# define DH_R_MODULUS_TOO_LARGE 103 +# define DH_R_NOT_SUITABLE_GENERATOR 120 +# define DH_R_NO_PARAMETERS_SET 107 +# define DH_R_NO_PRIVATE_VALUE 100 +# define DH_R_PARAMETER_ENCODING_ERROR 105 +# define DH_R_PEER_KEY_ERROR 111 +# define DH_R_SHARED_INFO_ERROR 113 +# define DH_R_UNABLE_TO_CHECK_GENERATOR 121 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/dh.h postgresql-hll-2.14/include/openssl/dh.h --- postgresql-hll-2.14_old/include/openssl/dh.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/dh.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,340 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DH_H +# define HEADER_DH_H + +# include + +# ifndef OPENSSL_NO_DH +# include +# include +# include +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# ifndef OPENSSL_DH_MAX_MODULUS_BITS +# define OPENSSL_DH_MAX_MODULUS_BITS 10000 +# endif + +# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024 + +# define DH_FLAG_CACHE_MONT_P 0x01 + +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define DH_FLAG_NO_EXP_CONSTTIME 0x00 +# endif + +/* + * If this flag is set the DH method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define DH_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define DH_FLAG_NON_FIPS_ALLOW 0x0400 + +/* Already defined in ossl_typ.h */ +/* typedef struct dh_st DH; */ +/* typedef struct dh_method DH_METHOD; */ + +DECLARE_ASN1_ITEM(DHparams) + +# define DH_GENERATOR_2 2 +/* #define DH_GENERATOR_3 3 */ +# define DH_GENERATOR_5 5 + +/* DH_check error codes */ +# define DH_CHECK_P_NOT_PRIME 0x01 +# define DH_CHECK_P_NOT_SAFE_PRIME 0x02 +# define DH_UNABLE_TO_CHECK_GENERATOR 0x04 +# define DH_NOT_SUITABLE_GENERATOR 0x08 +# define DH_CHECK_Q_NOT_PRIME 0x10 +# define DH_CHECK_INVALID_Q_VALUE 0x20 +# define DH_CHECK_INVALID_J_VALUE 0x40 + +/* DH_check_pub_key error codes */ +# define DH_CHECK_PUBKEY_TOO_SMALL 0x01 +# define DH_CHECK_PUBKEY_TOO_LARGE 0x02 +# define DH_CHECK_PUBKEY_INVALID 0x04 + +/* + * primes p where (p-1)/2 is prime too are called "safe"; we define this for + * backward compatibility: + */ +# define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME + +# define d2i_DHparams_fp(fp,x) \ + (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ + (char *(*)())d2i_DHparams, \ + (fp), \ + (unsigned char **)(x)) +# define i2d_DHparams_fp(fp,x) \ + ASN1_i2d_fp(i2d_DHparams,(fp), (unsigned char *)(x)) +# define d2i_DHparams_bio(bp,x) \ + ASN1_d2i_bio_of(DH, DH_new, d2i_DHparams, bp, x) +# define i2d_DHparams_bio(bp,x) \ + ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x) + +# define d2i_DHxparams_fp(fp,x) \ + (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ + (char *(*)())d2i_DHxparams, \ + (fp), \ + (unsigned char **)(x)) +# define i2d_DHxparams_fp(fp,x) \ + ASN1_i2d_fp(i2d_DHxparams,(fp), (unsigned char *)(x)) +# define d2i_DHxparams_bio(bp,x) \ + ASN1_d2i_bio_of(DH, DH_new, d2i_DHxparams, bp, x) +# define i2d_DHxparams_bio(bp,x) \ + ASN1_i2d_bio_of_const(DH, i2d_DHxparams, bp, x) + +DH *DHparams_dup(DH *); + +const DH_METHOD *DH_OpenSSL(void); + +void DH_set_default_method(const DH_METHOD *meth); +const DH_METHOD *DH_get_default_method(void); +int DH_set_method(DH *dh, const DH_METHOD *meth); +DH *DH_new_method(ENGINE *engine); + +DH *DH_new(void); +void DH_free(DH *dh); +int DH_up_ref(DH *dh); +int DH_bits(const DH *dh); +int DH_size(const DH *dh); +int DH_security_bits(const DH *dh); +#define DH_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, l, p, newf, dupf, freef) +int DH_set_ex_data(DH *d, int idx, void *arg); +void *DH_get_ex_data(DH *d, int idx); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(DH *DH_generate_parameters(int prime_len, int generator, + void (*callback) (int, int, + void *), + void *cb_arg)) + +/* New version */ +int DH_generate_parameters_ex(DH *dh, int prime_len, int generator, + BN_GENCB *cb); + +int DH_check_params_ex(const DH *dh); +int DH_check_ex(const DH *dh); +int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key); +int DH_check_params(const DH *dh, int *ret); +int DH_check(const DH *dh, int *codes); +int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *codes); +int DH_generate_key(DH *dh); +int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); +int DH_compute_key_padded(unsigned char *key, const BIGNUM *pub_key, DH *dh); +DH *d2i_DHparams(DH **a, const unsigned char **pp, long length); +int i2d_DHparams(const DH *a, unsigned char **pp); +DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length); +int i2d_DHxparams(const DH *a, unsigned char **pp); +# ifndef OPENSSL_NO_STDIO +int DHparams_print_fp(FILE *fp, const DH *x); +# endif +int DHparams_print(BIO *bp, const DH *x); + +/* RFC 5114 parameters */ +DH *DH_get_1024_160(void); +DH *DH_get_2048_224(void); +DH *DH_get_2048_256(void); + +/* Named parameters, currently RFC7919 */ +DH *DH_new_by_nid(int nid); +int DH_get_nid(const DH *dh); + +# ifndef OPENSSL_NO_CMS +/* RFC2631 KDF */ +int DH_KDF_X9_42(unsigned char *out, size_t outlen, + const unsigned char *Z, size_t Zlen, + ASN1_OBJECT *key_oid, + const unsigned char *ukm, size_t ukmlen, const EVP_MD *md); +# endif + +void DH_get0_pqg(const DH *dh, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g); +void DH_get0_key(const DH *dh, + const BIGNUM **pub_key, const BIGNUM **priv_key); +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key); +const BIGNUM *DH_get0_p(const DH *dh); +const BIGNUM *DH_get0_q(const DH *dh); +const BIGNUM *DH_get0_g(const DH *dh); +const BIGNUM *DH_get0_priv_key(const DH *dh); +const BIGNUM *DH_get0_pub_key(const DH *dh); +void DH_clear_flags(DH *dh, int flags); +int DH_test_flags(const DH *dh, int flags); +void DH_set_flags(DH *dh, int flags); +ENGINE *DH_get0_engine(DH *d); +long DH_get_length(const DH *dh); +int DH_set_length(DH *dh, long length); + +DH_METHOD *DH_meth_new(const char *name, int flags); +void DH_meth_free(DH_METHOD *dhm); +DH_METHOD *DH_meth_dup(const DH_METHOD *dhm); +const char *DH_meth_get0_name(const DH_METHOD *dhm); +int DH_meth_set1_name(DH_METHOD *dhm, const char *name); +int DH_meth_get_flags(const DH_METHOD *dhm); +int DH_meth_set_flags(DH_METHOD *dhm, int flags); +void *DH_meth_get0_app_data(const DH_METHOD *dhm); +int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data); +int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *); +int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *)); +int (*DH_meth_get_compute_key(const DH_METHOD *dhm)) + (unsigned char *key, const BIGNUM *pub_key, DH *dh); +int DH_meth_set_compute_key(DH_METHOD *dhm, + int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh)); +int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm)) + (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + BN_CTX *, BN_MONT_CTX *); +int DH_meth_set_bn_mod_exp(DH_METHOD *dhm, + int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, BN_CTX *, BN_MONT_CTX *)); +int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *); +int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *)); +int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *); +int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *)); +int (*DH_meth_get_generate_params(const DH_METHOD *dhm)) + (DH *, int, int, BN_GENCB *); +int DH_meth_set_generate_params(DH_METHOD *dhm, + int (*generate_params) (DH *, int, int, BN_GENCB *)); + + +# define EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, len, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_subprime_len(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN, len, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_type(ctx, typ) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, typ, NULL) + +# define EVP_PKEY_CTX_set_dh_paramgen_generator(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, gen, NULL) + +# define EVP_PKEY_CTX_set_dh_rfc5114(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_RFC5114, gen, NULL) + +# define EVP_PKEY_CTX_set_dhx_rfc5114(ctx, gen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DH_RFC5114, gen, NULL) + +# define EVP_PKEY_CTX_set_dh_nid(ctx, nid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, \ + EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_DH_NID, nid, NULL) + +# define EVP_PKEY_CTX_set_dh_pad(ctx, pad) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_PAD, pad, NULL) + +# define EVP_PKEY_CTX_set_dh_kdf_type(ctx, kdf) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_TYPE, kdf, NULL) + +# define EVP_PKEY_CTX_get_dh_kdf_type(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_TYPE, -2, NULL) + +# define EVP_PKEY_CTX_set0_dh_kdf_oid(ctx, oid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_OID, 0, (void *)(oid)) + +# define EVP_PKEY_CTX_get0_dh_kdf_oid(ctx, poid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_OID, 0, (void *)(poid)) + +# define EVP_PKEY_CTX_set_dh_kdf_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_get_dh_kdf_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_MD, 0, (void *)(pmd)) + +# define EVP_PKEY_CTX_set_dh_kdf_outlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_OUTLEN, len, NULL) + +# define EVP_PKEY_CTX_get_dh_kdf_outlen(ctx, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN, 0, (void *)(plen)) + +# define EVP_PKEY_CTX_set0_dh_kdf_ukm(ctx, p, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_DH_KDF_UKM, plen, (void *)(p)) + +# define EVP_PKEY_CTX_get0_dh_kdf_ukm(ctx, p) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_DH_KDF_UKM, 0, (void *)(p)) + +# define EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_DH_RFC5114 (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_DH_PARAMGEN_TYPE (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_DH_KDF_TYPE (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_DH_KDF_MD (EVP_PKEY_ALG_CTRL + 8) +# define EVP_PKEY_CTRL_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 10) +# define EVP_PKEY_CTRL_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_GET_DH_KDF_UKM (EVP_PKEY_ALG_CTRL + 12) +# define EVP_PKEY_CTRL_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 13) +# define EVP_PKEY_CTRL_GET_DH_KDF_OID (EVP_PKEY_ALG_CTRL + 14) +# define EVP_PKEY_CTRL_DH_NID (EVP_PKEY_ALG_CTRL + 15) +# define EVP_PKEY_CTRL_DH_PAD (EVP_PKEY_ALG_CTRL + 16) + +/* KDF types */ +# define EVP_PKEY_DH_KDF_NONE 1 +# ifndef OPENSSL_NO_CMS +# define EVP_PKEY_DH_KDF_X9_42 2 +# endif + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/dsaerr.h postgresql-hll-2.14/include/openssl/dsaerr.h --- postgresql-hll-2.14_old/include/openssl/dsaerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/dsaerr.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,72 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DSAERR_H +# define HEADER_DSAERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_DSA + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_DSA_strings(void); + +/* + * DSA function codes. + */ +# define DSA_F_DSAPARAMS_PRINT 100 +# define DSA_F_DSAPARAMS_PRINT_FP 101 +# define DSA_F_DSA_BUILTIN_PARAMGEN 125 +# define DSA_F_DSA_BUILTIN_PARAMGEN2 126 +# define DSA_F_DSA_DO_SIGN 112 +# define DSA_F_DSA_DO_VERIFY 113 +# define DSA_F_DSA_METH_DUP 127 +# define DSA_F_DSA_METH_NEW 128 +# define DSA_F_DSA_METH_SET1_NAME 129 +# define DSA_F_DSA_NEW_METHOD 103 +# define DSA_F_DSA_PARAM_DECODE 119 +# define DSA_F_DSA_PRINT_FP 105 +# define DSA_F_DSA_PRIV_DECODE 115 +# define DSA_F_DSA_PRIV_ENCODE 116 +# define DSA_F_DSA_PUB_DECODE 117 +# define DSA_F_DSA_PUB_ENCODE 118 +# define DSA_F_DSA_SIGN 106 +# define DSA_F_DSA_SIGN_SETUP 107 +# define DSA_F_DSA_SIG_NEW 102 +# define DSA_F_OLD_DSA_PRIV_DECODE 122 +# define DSA_F_PKEY_DSA_CTRL 120 +# define DSA_F_PKEY_DSA_CTRL_STR 104 +# define DSA_F_PKEY_DSA_KEYGEN 121 + +/* + * DSA reason codes. + */ +# define DSA_R_BAD_Q_VALUE 102 +# define DSA_R_BN_DECODE_ERROR 108 +# define DSA_R_BN_ERROR 109 +# define DSA_R_DECODE_ERROR 104 +# define DSA_R_INVALID_DIGEST_TYPE 106 +# define DSA_R_INVALID_PARAMETERS 112 +# define DSA_R_MISSING_PARAMETERS 101 +# define DSA_R_MISSING_PRIVATE_KEY 111 +# define DSA_R_MODULUS_TOO_LARGE 103 +# define DSA_R_NO_PARAMETERS_SET 107 +# define DSA_R_PARAMETER_ENCODING_ERROR 105 +# define DSA_R_Q_NOT_PRIME 113 +# define DSA_R_SEED_LEN_SMALL 110 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/dsa.h postgresql-hll-2.14/include/openssl/dsa.h --- postgresql-hll-2.14_old/include/openssl/dsa.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/dsa.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,244 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DSA_H +# define HEADER_DSA_H + +# include + +# ifndef OPENSSL_NO_DSA +# ifdef __cplusplus +extern "C" { +# endif +# include +# include +# include +# include +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif +# include + +# ifndef OPENSSL_DSA_MAX_MODULUS_BITS +# define OPENSSL_DSA_MAX_MODULUS_BITS 10000 +# endif + +# define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024 + +# define DSA_FLAG_CACHE_MONT_P 0x01 +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define DSA_FLAG_NO_EXP_CONSTTIME 0x00 +# endif + +/* + * If this flag is set the DSA method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define DSA_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define DSA_FLAG_NON_FIPS_ALLOW 0x0400 +# define DSA_FLAG_FIPS_CHECKED 0x0800 + +/* Already defined in ossl_typ.h */ +/* typedef struct dsa_st DSA; */ +/* typedef struct dsa_method DSA_METHOD; */ + +typedef struct DSA_SIG_st DSA_SIG; + +# define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ + (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) +# define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ + (unsigned char *)(x)) +# define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) +# define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) + +DSA *DSAparams_dup(DSA *x); +DSA_SIG *DSA_SIG_new(void); +void DSA_SIG_free(DSA_SIG *a); +int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); +DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length); +void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); +int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s); + +DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); +int DSA_do_verify(const unsigned char *dgst, int dgst_len, + DSA_SIG *sig, DSA *dsa); + +const DSA_METHOD *DSA_OpenSSL(void); + +void DSA_set_default_method(const DSA_METHOD *); +const DSA_METHOD *DSA_get_default_method(void); +int DSA_set_method(DSA *dsa, const DSA_METHOD *); +const DSA_METHOD *DSA_get_method(DSA *d); + +DSA *DSA_new(void); +DSA *DSA_new_method(ENGINE *engine); +void DSA_free(DSA *r); +/* "up" the DSA object's reference count */ +int DSA_up_ref(DSA *r); +int DSA_size(const DSA *); +int DSA_bits(const DSA *d); +int DSA_security_bits(const DSA *d); + /* next 4 return -1 on error */ +DEPRECATEDIN_1_2_0(int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)) +int DSA_sign(int type, const unsigned char *dgst, int dlen, + unsigned char *sig, unsigned int *siglen, DSA *dsa); +int DSA_verify(int type, const unsigned char *dgst, int dgst_len, + const unsigned char *sigbuf, int siglen, DSA *dsa); +#define DSA_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, l, p, newf, dupf, freef) +int DSA_set_ex_data(DSA *d, int idx, void *arg); +void *DSA_get_ex_data(DSA *d, int idx); + +DSA *d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); +DSA *d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); +DSA *d2i_DSAparams(DSA **a, const unsigned char **pp, long length); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(DSA *DSA_generate_parameters(int bits, + unsigned char *seed, + int seed_len, + int *counter_ret, + unsigned long *h_ret, void + (*callback) (int, int, + void *), + void *cb_arg)) + +/* New version */ +int DSA_generate_parameters_ex(DSA *dsa, int bits, + const unsigned char *seed, int seed_len, + int *counter_ret, unsigned long *h_ret, + BN_GENCB *cb); + +int DSA_generate_key(DSA *a); +int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); +int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); +int i2d_DSAparams(const DSA *a, unsigned char **pp); + +int DSAparams_print(BIO *bp, const DSA *x); +int DSA_print(BIO *bp, const DSA *x, int off); +# ifndef OPENSSL_NO_STDIO +int DSAparams_print_fp(FILE *fp, const DSA *x); +int DSA_print_fp(FILE *bp, const DSA *x, int off); +# endif + +# define DSS_prime_checks 64 +/* + * Primality test according to FIPS PUB 186-4, Appendix C.3. Since we only + * have one value here we set the number of checks to 64 which is the 128 bit + * security level that is the highest level and valid for creating a 3072 bit + * DSA key. + */ +# define DSA_is_prime(n, callback, cb_arg) \ + BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) + +# ifndef OPENSSL_NO_DH +/* + * Convert DSA structure (key or just parameters) into DH structure (be + * careful to avoid small subgroup attacks when using this!) + */ +DH *DSA_dup_DH(const DSA *r); +# endif + +# define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) +# define EVP_PKEY_CTX_set_dsa_paramgen_q_bits(ctx, qbits) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, NULL) +# define EVP_PKEY_CTX_set_dsa_paramgen_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3) + +void DSA_get0_pqg(const DSA *d, + const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); +int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g); +void DSA_get0_key(const DSA *d, + const BIGNUM **pub_key, const BIGNUM **priv_key); +int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key); +const BIGNUM *DSA_get0_p(const DSA *d); +const BIGNUM *DSA_get0_q(const DSA *d); +const BIGNUM *DSA_get0_g(const DSA *d); +const BIGNUM *DSA_get0_pub_key(const DSA *d); +const BIGNUM *DSA_get0_priv_key(const DSA *d); +void DSA_clear_flags(DSA *d, int flags); +int DSA_test_flags(const DSA *d, int flags); +void DSA_set_flags(DSA *d, int flags); +ENGINE *DSA_get0_engine(DSA *d); + +DSA_METHOD *DSA_meth_new(const char *name, int flags); +void DSA_meth_free(DSA_METHOD *dsam); +DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam); +const char *DSA_meth_get0_name(const DSA_METHOD *dsam); +int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name); +int DSA_meth_get_flags(const DSA_METHOD *dsam); +int DSA_meth_set_flags(DSA_METHOD *dsam, int flags); +void *DSA_meth_get0_app_data(const DSA_METHOD *dsam); +int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data); +DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam)) + (const unsigned char *, int, DSA *); +int DSA_meth_set_sign(DSA_METHOD *dsam, + DSA_SIG *(*sign) (const unsigned char *, int, DSA *)); +int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam)) + (DSA *, BN_CTX *, BIGNUM **, BIGNUM **); +int DSA_meth_set_sign_setup(DSA_METHOD *dsam, + int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)); +int (*DSA_meth_get_verify(const DSA_METHOD *dsam)) + (const unsigned char *, int, DSA_SIG *, DSA *); +int DSA_meth_set_verify(DSA_METHOD *dsam, + int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *)); +int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam)) + (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *); +int DSA_meth_set_mod_exp(DSA_METHOD *dsam, + int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *, + BN_MONT_CTX *)); +int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam)) + (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, + BN_CTX *, BN_MONT_CTX *); +int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam, + int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, + const BIGNUM *, BN_CTX *, BN_MONT_CTX *)); +int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *); +int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *)); +int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *); +int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *)); +int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam)) + (DSA *, int, const unsigned char *, int, int *, unsigned long *, + BN_GENCB *); +int DSA_meth_set_paramgen(DSA_METHOD *dsam, + int (*paramgen) (DSA *, int, const unsigned char *, int, int *, + unsigned long *, BN_GENCB *)); +int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *); +int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *)); + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/dtls1.h postgresql-hll-2.14/include/openssl/dtls1.h --- postgresql-hll-2.14_old/include/openssl/dtls1.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/dtls1.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,55 @@ +/* + * Copyright 2005-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DTLS1_H +# define HEADER_DTLS1_H + +#ifdef __cplusplus +extern "C" { +#endif + +# define DTLS1_VERSION 0xFEFF +# define DTLS1_2_VERSION 0xFEFD +# define DTLS_MIN_VERSION DTLS1_VERSION +# define DTLS_MAX_VERSION DTLS1_2_VERSION +# define DTLS1_VERSION_MAJOR 0xFE + +# define DTLS1_BAD_VER 0x0100 + +/* Special value for method supporting multiple versions */ +# define DTLS_ANY_VERSION 0x1FFFF + +/* lengths of messages */ +/* + * Actually the max cookie length in DTLS is 255. But we can't change this now + * due to compatibility concerns. + */ +# define DTLS1_COOKIE_LENGTH 256 + +# define DTLS1_RT_HEADER_LENGTH 13 + +# define DTLS1_HM_HEADER_LENGTH 12 + +# define DTLS1_HM_BAD_FRAGMENT -2 +# define DTLS1_HM_FRAGMENT_RETRY -3 + +# define DTLS1_CCS_HEADER_LENGTH 1 + +# define DTLS1_AL_HEADER_LENGTH 2 + +/* Timeout multipliers */ +# define DTLS1_TMO_READ_COUNT 2 +# define DTLS1_TMO_WRITE_COUNT 2 + +# define DTLS1_TMO_ALERT_COUNT 12 + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ebcdic.h postgresql-hll-2.14/include/openssl/ebcdic.h --- postgresql-hll-2.14_old/include/openssl/ebcdic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ebcdic.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_EBCDIC_H +# define HEADER_EBCDIC_H + +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Avoid name clashes with other applications */ +# define os_toascii _openssl_os_toascii +# define os_toebcdic _openssl_os_toebcdic +# define ebcdic2ascii _openssl_ebcdic2ascii +# define ascii2ebcdic _openssl_ascii2ebcdic + +extern const unsigned char os_toascii[256]; +extern const unsigned char os_toebcdic[256]; +void *ebcdic2ascii(void *dest, const void *srce, size_t count); +void *ascii2ebcdic(void *dest, const void *srce, size_t count); + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ecdh.h postgresql-hll-2.14/include/openssl/ecdh.h --- postgresql-hll-2.14_old/include/openssl/ecdh.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ecdh.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,10 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include diff -uprN postgresql-hll-2.14_old/include/openssl/ecdsa.h postgresql-hll-2.14/include/openssl/ecdsa.h --- postgresql-hll-2.14_old/include/openssl/ecdsa.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ecdsa.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,10 @@ +/* + * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include diff -uprN postgresql-hll-2.14_old/include/openssl/ecerr.h postgresql-hll-2.14/include/openssl/ecerr.h --- postgresql-hll-2.14_old/include/openssl/ecerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ecerr.h 2020-12-12 17:06:43.330349109 +0800 @@ -0,0 +1,275 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ECERR_H +# define HEADER_ECERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_EC + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_EC_strings(void); + +/* + * EC function codes. + */ +# define EC_F_BN_TO_FELEM 224 +# define EC_F_D2I_ECPARAMETERS 144 +# define EC_F_D2I_ECPKPARAMETERS 145 +# define EC_F_D2I_ECPRIVATEKEY 146 +# define EC_F_DO_EC_KEY_PRINT 221 +# define EC_F_ECDH_CMS_DECRYPT 238 +# define EC_F_ECDH_CMS_SET_SHARED_INFO 239 +# define EC_F_ECDH_COMPUTE_KEY 246 +# define EC_F_ECDH_SIMPLE_COMPUTE_KEY 257 +# define EC_F_ECDSA_DO_SIGN_EX 251 +# define EC_F_ECDSA_DO_VERIFY 252 +# define EC_F_ECDSA_SIGN_EX 254 +# define EC_F_ECDSA_SIGN_SETUP 248 +# define EC_F_ECDSA_SIG_NEW 265 +# define EC_F_ECDSA_VERIFY 253 +# define EC_F_ECD_ITEM_VERIFY 270 +# define EC_F_ECKEY_PARAM2TYPE 223 +# define EC_F_ECKEY_PARAM_DECODE 212 +# define EC_F_ECKEY_PRIV_DECODE 213 +# define EC_F_ECKEY_PRIV_ENCODE 214 +# define EC_F_ECKEY_PUB_DECODE 215 +# define EC_F_ECKEY_PUB_ENCODE 216 +# define EC_F_ECKEY_TYPE2PARAM 220 +# define EC_F_ECPARAMETERS_PRINT 147 +# define EC_F_ECPARAMETERS_PRINT_FP 148 +# define EC_F_ECPKPARAMETERS_PRINT 149 +# define EC_F_ECPKPARAMETERS_PRINT_FP 150 +# define EC_F_ECP_NISTZ256_GET_AFFINE 240 +# define EC_F_ECP_NISTZ256_INV_MOD_ORD 275 +# define EC_F_ECP_NISTZ256_MULT_PRECOMPUTE 243 +# define EC_F_ECP_NISTZ256_POINTS_MUL 241 +# define EC_F_ECP_NISTZ256_PRE_COMP_NEW 244 +# define EC_F_ECP_NISTZ256_WINDOWED_MUL 242 +# define EC_F_ECX_KEY_OP 266 +# define EC_F_ECX_PRIV_ENCODE 267 +# define EC_F_ECX_PUB_ENCODE 268 +# define EC_F_EC_ASN1_GROUP2CURVE 153 +# define EC_F_EC_ASN1_GROUP2FIELDID 154 +# define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208 +# define EC_F_EC_GF2M_SIMPLE_FIELD_INV 296 +# define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159 +# define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195 +# define EC_F_EC_GF2M_SIMPLE_LADDER_POST 285 +# define EC_F_EC_GF2M_SIMPLE_LADDER_PRE 288 +# define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160 +# define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161 +# define EC_F_EC_GF2M_SIMPLE_POINTS_MUL 289 +# define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162 +# define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163 +# define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164 +# define EC_F_EC_GFP_MONT_FIELD_DECODE 133 +# define EC_F_EC_GFP_MONT_FIELD_ENCODE 134 +# define EC_F_EC_GFP_MONT_FIELD_INV 297 +# define EC_F_EC_GFP_MONT_FIELD_MUL 131 +# define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209 +# define EC_F_EC_GFP_MONT_FIELD_SQR 132 +# define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189 +# define EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE 225 +# define EC_F_EC_GFP_NISTP224_POINTS_MUL 228 +# define EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES 226 +# define EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE 230 +# define EC_F_EC_GFP_NISTP256_POINTS_MUL 231 +# define EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES 232 +# define EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE 233 +# define EC_F_EC_GFP_NISTP521_POINTS_MUL 234 +# define EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES 235 +# define EC_F_EC_GFP_NIST_FIELD_MUL 200 +# define EC_F_EC_GFP_NIST_FIELD_SQR 201 +# define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202 +# define EC_F_EC_GFP_SIMPLE_BLIND_COORDINATES 287 +# define EC_F_EC_GFP_SIMPLE_FIELD_INV 298 +# define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165 +# define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166 +# define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102 +# define EC_F_EC_GFP_SIMPLE_OCT2POINT 103 +# define EC_F_EC_GFP_SIMPLE_POINT2OCT 104 +# define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137 +# define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167 +# define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168 +# define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169 +# define EC_F_EC_GROUP_CHECK 170 +# define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171 +# define EC_F_EC_GROUP_COPY 106 +# define EC_F_EC_GROUP_GET_CURVE 291 +# define EC_F_EC_GROUP_GET_CURVE_GF2M 172 +# define EC_F_EC_GROUP_GET_CURVE_GFP 130 +# define EC_F_EC_GROUP_GET_DEGREE 173 +# define EC_F_EC_GROUP_GET_ECPARAMETERS 261 +# define EC_F_EC_GROUP_GET_ECPKPARAMETERS 262 +# define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193 +# define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194 +# define EC_F_EC_GROUP_NEW 108 +# define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174 +# define EC_F_EC_GROUP_NEW_FROM_DATA 175 +# define EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS 263 +# define EC_F_EC_GROUP_NEW_FROM_ECPKPARAMETERS 264 +# define EC_F_EC_GROUP_SET_CURVE 292 +# define EC_F_EC_GROUP_SET_CURVE_GF2M 176 +# define EC_F_EC_GROUP_SET_CURVE_GFP 109 +# define EC_F_EC_GROUP_SET_GENERATOR 111 +# define EC_F_EC_GROUP_SET_SEED 286 +# define EC_F_EC_KEY_CHECK_KEY 177 +# define EC_F_EC_KEY_COPY 178 +# define EC_F_EC_KEY_GENERATE_KEY 179 +# define EC_F_EC_KEY_NEW 182 +# define EC_F_EC_KEY_NEW_METHOD 245 +# define EC_F_EC_KEY_OCT2PRIV 255 +# define EC_F_EC_KEY_PRINT 180 +# define EC_F_EC_KEY_PRINT_FP 181 +# define EC_F_EC_KEY_PRIV2BUF 279 +# define EC_F_EC_KEY_PRIV2OCT 256 +# define EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES 229 +# define EC_F_EC_KEY_SIMPLE_CHECK_KEY 258 +# define EC_F_EC_KEY_SIMPLE_OCT2PRIV 259 +# define EC_F_EC_KEY_SIMPLE_PRIV2OCT 260 +# define EC_F_EC_PKEY_CHECK 273 +# define EC_F_EC_PKEY_PARAM_CHECK 274 +# define EC_F_EC_POINTS_MAKE_AFFINE 136 +# define EC_F_EC_POINTS_MUL 290 +# define EC_F_EC_POINT_ADD 112 +# define EC_F_EC_POINT_BN2POINT 280 +# define EC_F_EC_POINT_CMP 113 +# define EC_F_EC_POINT_COPY 114 +# define EC_F_EC_POINT_DBL 115 +# define EC_F_EC_POINT_GET_AFFINE_COORDINATES 293 +# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183 +# define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116 +# define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117 +# define EC_F_EC_POINT_INVERT 210 +# define EC_F_EC_POINT_IS_AT_INFINITY 118 +# define EC_F_EC_POINT_IS_ON_CURVE 119 +# define EC_F_EC_POINT_MAKE_AFFINE 120 +# define EC_F_EC_POINT_NEW 121 +# define EC_F_EC_POINT_OCT2POINT 122 +# define EC_F_EC_POINT_POINT2BUF 281 +# define EC_F_EC_POINT_POINT2OCT 123 +# define EC_F_EC_POINT_SET_AFFINE_COORDINATES 294 +# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185 +# define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124 +# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES 295 +# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186 +# define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125 +# define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126 +# define EC_F_EC_POINT_SET_TO_INFINITY 127 +# define EC_F_EC_PRE_COMP_NEW 196 +# define EC_F_EC_SCALAR_MUL_LADDER 284 +# define EC_F_EC_WNAF_MUL 187 +# define EC_F_EC_WNAF_PRECOMPUTE_MULT 188 +# define EC_F_I2D_ECPARAMETERS 190 +# define EC_F_I2D_ECPKPARAMETERS 191 +# define EC_F_I2D_ECPRIVATEKEY 192 +# define EC_F_I2O_ECPUBLICKEY 151 +# define EC_F_NISTP224_PRE_COMP_NEW 227 +# define EC_F_NISTP256_PRE_COMP_NEW 236 +# define EC_F_NISTP521_PRE_COMP_NEW 237 +# define EC_F_O2I_ECPUBLICKEY 152 +# define EC_F_OLD_EC_PRIV_DECODE 222 +# define EC_F_OSSL_ECDH_COMPUTE_KEY 247 +# define EC_F_OSSL_ECDSA_SIGN_SIG 249 +# define EC_F_OSSL_ECDSA_VERIFY_SIG 250 +# define EC_F_PKEY_ECD_CTRL 271 +# define EC_F_PKEY_ECD_DIGESTSIGN 272 +# define EC_F_PKEY_ECD_DIGESTSIGN25519 276 +# define EC_F_PKEY_ECD_DIGESTSIGN448 277 +# define EC_F_PKEY_ECX_DERIVE 269 +# define EC_F_PKEY_EC_CTRL 197 +# define EC_F_PKEY_EC_CTRL_STR 198 +# define EC_F_PKEY_EC_DERIVE 217 +# define EC_F_PKEY_EC_INIT 282 +# define EC_F_PKEY_EC_KDF_DERIVE 283 +# define EC_F_PKEY_EC_KEYGEN 199 +# define EC_F_PKEY_EC_PARAMGEN 219 +# define EC_F_PKEY_EC_SIGN 218 +# define EC_F_VALIDATE_ECX_DERIVE 278 + +/* + * EC reason codes. + */ +# define EC_R_ASN1_ERROR 115 +# define EC_R_BAD_SIGNATURE 156 +# define EC_R_BIGNUM_OUT_OF_RANGE 144 +# define EC_R_BUFFER_TOO_SMALL 100 +# define EC_R_CANNOT_INVERT 165 +# define EC_R_COORDINATES_OUT_OF_RANGE 146 +# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH 160 +# define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING 159 +# define EC_R_D2I_ECPKPARAMETERS_FAILURE 117 +# define EC_R_DECODE_ERROR 142 +# define EC_R_DISCRIMINANT_IS_ZERO 118 +# define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119 +# define EC_R_FIELD_TOO_LARGE 143 +# define EC_R_GF2M_NOT_SUPPORTED 147 +# define EC_R_GROUP2PKPARAMETERS_FAILURE 120 +# define EC_R_I2D_ECPKPARAMETERS_FAILURE 121 +# define EC_R_INCOMPATIBLE_OBJECTS 101 +# define EC_R_INVALID_ARGUMENT 112 +# define EC_R_INVALID_COMPRESSED_POINT 110 +# define EC_R_INVALID_COMPRESSION_BIT 109 +# define EC_R_INVALID_CURVE 141 +# define EC_R_INVALID_DIGEST 151 +# define EC_R_INVALID_DIGEST_TYPE 138 +# define EC_R_INVALID_ENCODING 102 +# define EC_R_INVALID_FIELD 103 +# define EC_R_INVALID_FORM 104 +# define EC_R_INVALID_GROUP_ORDER 122 +# define EC_R_INVALID_KEY 116 +# define EC_R_INVALID_OUTPUT_LENGTH 161 +# define EC_R_INVALID_PEER_KEY 133 +# define EC_R_INVALID_PENTANOMIAL_BASIS 132 +# define EC_R_INVALID_PRIVATE_KEY 123 +# define EC_R_INVALID_TRINOMIAL_BASIS 137 +# define EC_R_KDF_PARAMETER_ERROR 148 +# define EC_R_KEYS_NOT_SET 140 +# define EC_R_LADDER_POST_FAILURE 136 +# define EC_R_LADDER_PRE_FAILURE 153 +# define EC_R_LADDER_STEP_FAILURE 162 +# define EC_R_MISSING_PARAMETERS 124 +# define EC_R_MISSING_PRIVATE_KEY 125 +# define EC_R_NEED_NEW_SETUP_VALUES 157 +# define EC_R_NOT_A_NIST_PRIME 135 +# define EC_R_NOT_IMPLEMENTED 126 +# define EC_R_NOT_INITIALIZED 111 +# define EC_R_NO_PARAMETERS_SET 139 +# define EC_R_NO_PRIVATE_VALUE 154 +# define EC_R_OPERATION_NOT_SUPPORTED 152 +# define EC_R_PASSED_NULL_PARAMETER 134 +# define EC_R_PEER_KEY_ERROR 149 +# define EC_R_PKPARAMETERS2GROUP_FAILURE 127 +# define EC_R_POINT_ARITHMETIC_FAILURE 155 +# define EC_R_POINT_AT_INFINITY 106 +# define EC_R_POINT_COORDINATES_BLIND_FAILURE 163 +# define EC_R_POINT_IS_NOT_ON_CURVE 107 +# define EC_R_RANDOM_NUMBER_GENERATION_FAILED 158 +# define EC_R_SHARED_INFO_ERROR 150 +# define EC_R_SLOT_FULL 108 +# define EC_R_UNDEFINED_GENERATOR 113 +# define EC_R_UNDEFINED_ORDER 128 +# define EC_R_UNKNOWN_COFACTOR 164 +# define EC_R_UNKNOWN_GROUP 129 +# define EC_R_UNKNOWN_ORDER 114 +# define EC_R_UNSUPPORTED_FIELD 131 +# define EC_R_WRONG_CURVE_PARAMETERS 145 +# define EC_R_WRONG_ORDER 130 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ec.h postgresql-hll-2.14/include/openssl/ec.h --- postgresql-hll-2.14_old/include/openssl/ec.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ec.h 2020-12-12 17:06:43.331349122 +0800 @@ -0,0 +1,1479 @@ +/* + * Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_EC_H +# define HEADER_EC_H + +# include + +# ifndef OPENSSL_NO_EC +# include +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif +# include +# ifdef __cplusplus +extern "C" { +# endif + +# ifndef OPENSSL_ECC_MAX_FIELD_BITS +# define OPENSSL_ECC_MAX_FIELD_BITS 661 +# endif + +/** Enum for the point conversion form as defined in X9.62 (ECDSA) + * for the encoding of a elliptic curve point (x,y) */ +typedef enum { + /** the point is encoded as z||x, where the octet z specifies + * which solution of the quadratic equation y is */ + POINT_CONVERSION_COMPRESSED = 2, + /** the point is encoded as z||x||y, where z is the octet 0x04 */ + POINT_CONVERSION_UNCOMPRESSED = 4, + /** the point is encoded as z||x||y, where the octet z specifies + * which solution of the quadratic equation y is */ + POINT_CONVERSION_HYBRID = 6 +} point_conversion_form_t; + +typedef struct ec_method_st EC_METHOD; +typedef struct ec_group_st EC_GROUP; +typedef struct ec_point_st EC_POINT; +typedef struct ecpk_parameters_st ECPKPARAMETERS; +typedef struct ec_parameters_st ECPARAMETERS; + +/********************************************************************/ +/* EC_METHODs for curves over GF(p) */ +/********************************************************************/ + +/** Returns the basic GFp ec methods which provides the basis for the + * optimized methods. + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_simple_method(void); + +/** Returns GFp methods using montgomery multiplication. + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_mont_method(void); + +/** Returns GFp methods using optimized methods for NIST recommended curves + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nist_method(void); + +# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +/** Returns 64-bit optimized methods for nistp224 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp224_method(void); + +/** Returns 64-bit optimized methods for nistp256 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp256_method(void); + +/** Returns 64-bit optimized methods for nistp521 + * \return EC_METHOD object + */ +const EC_METHOD *EC_GFp_nistp521_method(void); +# endif + +# ifndef OPENSSL_NO_EC2M +/********************************************************************/ +/* EC_METHOD for curves over GF(2^m) */ +/********************************************************************/ + +/** Returns the basic GF2m ec method + * \return EC_METHOD object + */ +const EC_METHOD *EC_GF2m_simple_method(void); + +# endif + +/********************************************************************/ +/* EC_GROUP functions */ +/********************************************************************/ + +/** Creates a new EC_GROUP object + * \param meth EC_METHOD to use + * \return newly created EC_GROUP object or NULL in case of an error. + */ +EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); + +/** Frees a EC_GROUP object + * \param group EC_GROUP object to be freed. + */ +void EC_GROUP_free(EC_GROUP *group); + +/** Clears and frees a EC_GROUP object + * \param group EC_GROUP object to be cleared and freed. + */ +void EC_GROUP_clear_free(EC_GROUP *group); + +/** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD. + * \param dst destination EC_GROUP object + * \param src source EC_GROUP object + * \return 1 on success and 0 if an error occurred. + */ +int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); + +/** Creates a new EC_GROUP object and copies the copies the content + * form src to the newly created EC_KEY object + * \param src source EC_GROUP object + * \return newly created EC_GROUP object or NULL in case of an error. + */ +EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); + +/** Returns the EC_METHOD of the EC_GROUP object. + * \param group EC_GROUP object + * \return EC_METHOD used in this EC_GROUP object. + */ +const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); + +/** Returns the field type of the EC_METHOD. + * \param meth EC_METHOD object + * \return NID of the underlying field type OID. + */ +int EC_METHOD_get_field_type(const EC_METHOD *meth); + +/** Sets the generator and its order/cofactor of a EC_GROUP object. + * \param group EC_GROUP object + * \param generator EC_POINT object with the generator. + * \param order the order of the group generated by the generator. + * \param cofactor the index of the sub-group generated by the generator + * in the group of all points on the elliptic curve. + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, + const BIGNUM *order, const BIGNUM *cofactor); + +/** Returns the generator of a EC_GROUP object. + * \param group EC_GROUP object + * \return the currently used generator (possibly NULL). + */ +const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); + +/** Returns the montgomery data for order(Generator) + * \param group EC_GROUP object + * \return the currently used montgomery data (possibly NULL). +*/ +BN_MONT_CTX *EC_GROUP_get_mont_data(const EC_GROUP *group); + +/** Gets the order of a EC_GROUP + * \param group EC_GROUP object + * \param order BIGNUM to which the order is copied + * \param ctx unused + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); + +/** Gets the order of an EC_GROUP + * \param group EC_GROUP object + * \return the group order + */ +const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); + +/** Gets the number of bits of the order of an EC_GROUP + * \param group EC_GROUP object + * \return number of bits of group order. + */ +int EC_GROUP_order_bits(const EC_GROUP *group); + +/** Gets the cofactor of a EC_GROUP + * \param group EC_GROUP object + * \param cofactor BIGNUM to which the cofactor is copied + * \param ctx unused + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, + BN_CTX *ctx); + +/** Gets the cofactor of an EC_GROUP + * \param group EC_GROUP object + * \return the group cofactor + */ +const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); + +/** Sets the name of a EC_GROUP object + * \param group EC_GROUP object + * \param nid NID of the curve name OID + */ +void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); + +/** Returns the curve name of a EC_GROUP object + * \param group EC_GROUP object + * \return NID of the curve name OID or 0 if not set. + */ +int EC_GROUP_get_curve_name(const EC_GROUP *group); + +void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); +int EC_GROUP_get_asn1_flag(const EC_GROUP *group); + +void EC_GROUP_set_point_conversion_form(EC_GROUP *group, + point_conversion_form_t form); +point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *); + +unsigned char *EC_GROUP_get0_seed(const EC_GROUP *x); +size_t EC_GROUP_get_seed_len(const EC_GROUP *); +size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len); + +/** Sets the parameters of a ec curve defined by y^2 = x^3 + a*x + b (for GFp) + * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM with parameter a of the equation + * \param b BIGNUM with parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); + +/** Gets the parameters of the ec curve defined by y^2 = x^3 + a*x + b (for GFp) + * or y^2 + x*y = x^3 + a*x^2 + b (for GF2m) + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM for parameter a of the equation + * \param b BIGNUM for parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, + BN_CTX *ctx); + +/** Sets the parameters of an ec curve. Synonym for EC_GROUP_set_curve + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM with parameter a of the equation + * \param b BIGNUM with parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, + const BIGNUM *a, const BIGNUM *b, + BN_CTX *ctx)) + +/** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM for parameter a of the equation + * \param b BIGNUM for parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, + BIGNUM *a, BIGNUM *b, + BN_CTX *ctx)) + +# ifndef OPENSSL_NO_EC2M +/** Sets the parameter of an ec curve. Synonym for EC_GROUP_set_curve + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM with parameter a of the equation + * \param b BIGNUM with parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, + const BIGNUM *a, const BIGNUM *b, + BN_CTX *ctx)) + +/** Gets the parameters of an ec curve. Synonym for EC_GROUP_get_curve + * \param group EC_GROUP object + * \param p BIGNUM with the prime number (GFp) or the polynomial + * defining the underlying field (GF2m) + * \param a BIGNUM for parameter a of the equation + * \param b BIGNUM for parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, + BIGNUM *a, BIGNUM *b, + BN_CTX *ctx)) +# endif +/** Returns the number of bits needed to represent a field element + * \param group EC_GROUP object + * \return number of bits needed to represent a field element + */ +int EC_GROUP_get_degree(const EC_GROUP *group); + +/** Checks whether the parameter in the EC_GROUP define a valid ec group + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 if group is a valid ec group and 0 otherwise + */ +int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); + +/** Checks whether the discriminant of the elliptic curve is zero or not + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 if the discriminant is not zero and 0 otherwise + */ +int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); + +/** Compares two EC_GROUP objects + * \param a first EC_GROUP object + * \param b second EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 0 if the groups are equal, 1 if not, or -1 on error + */ +int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); + +/* + * EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() after + * choosing an appropriate EC_METHOD + */ + +/** Creates a new EC_GROUP object with the specified parameters defined + * over GFp (defined by the equation y^2 = x^3 + a*x + b) + * \param p BIGNUM with the prime number + * \param a BIGNUM with the parameter a of the equation + * \param b BIGNUM with the parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return newly created EC_GROUP object with the specified parameters + */ +EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); +# ifndef OPENSSL_NO_EC2M +/** Creates a new EC_GROUP object with the specified parameters defined + * over GF2m (defined by the equation y^2 + x*y = x^3 + a*x^2 + b) + * \param p BIGNUM with the polynomial defining the underlying field + * \param a BIGNUM with the parameter a of the equation + * \param b BIGNUM with the parameter b of the equation + * \param ctx BN_CTX object (optional) + * \return newly created EC_GROUP object with the specified parameters + */ +EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, + const BIGNUM *b, BN_CTX *ctx); +# endif + +/** Creates a EC_GROUP object with a curve specified by a NID + * \param nid NID of the OID of the curve name + * \return newly created EC_GROUP object with specified curve or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_by_curve_name(int nid); + +/** Creates a new EC_GROUP object from an ECPARAMETERS object + * \param params pointer to the ECPARAMETERS object + * \return newly created EC_GROUP object with specified curve or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params); + +/** Creates an ECPARAMETERS object for the given EC_GROUP object. + * \param group pointer to the EC_GROUP object + * \param params pointer to an existing ECPARAMETERS object or NULL + * \return pointer to the new ECPARAMETERS object or NULL + * if an error occurred. + */ +ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group, + ECPARAMETERS *params); + +/** Creates a new EC_GROUP object from an ECPKPARAMETERS object + * \param params pointer to an existing ECPKPARAMETERS object, or NULL + * \return newly created EC_GROUP object with specified curve, or NULL + * if an error occurred + */ +EC_GROUP *EC_GROUP_new_from_ecpkparameters(const ECPKPARAMETERS *params); + +/** Creates an ECPKPARAMETERS object for the given EC_GROUP object. + * \param group pointer to the EC_GROUP object + * \param params pointer to an existing ECPKPARAMETERS object or NULL + * \return pointer to the new ECPKPARAMETERS object or NULL + * if an error occurred. + */ +ECPKPARAMETERS *EC_GROUP_get_ecpkparameters(const EC_GROUP *group, + ECPKPARAMETERS *params); + +/********************************************************************/ +/* handling of internal curves */ +/********************************************************************/ + +typedef struct { + int nid; + const char *comment; +} EC_builtin_curve; + +/* + * EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number of all + * available curves or zero if a error occurred. In case r is not zero, + * nitems EC_builtin_curve structures are filled with the data of the first + * nitems internal groups + */ +size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); + +const char *EC_curve_nid2nist(int nid); +int EC_curve_nist2nid(const char *name); + +/********************************************************************/ +/* EC_POINT functions */ +/********************************************************************/ + +/** Creates a new EC_POINT object for the specified EC_GROUP + * \param group EC_GROUP the underlying EC_GROUP object + * \return newly created EC_POINT object or NULL if an error occurred + */ +EC_POINT *EC_POINT_new(const EC_GROUP *group); + +/** Frees a EC_POINT object + * \param point EC_POINT object to be freed + */ +void EC_POINT_free(EC_POINT *point); + +/** Clears and frees a EC_POINT object + * \param point EC_POINT object to be cleared and freed + */ +void EC_POINT_clear_free(EC_POINT *point); + +/** Copies EC_POINT object + * \param dst destination EC_POINT object + * \param src source EC_POINT object + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); + +/** Creates a new EC_POINT object and copies the content of the supplied + * EC_POINT + * \param src source EC_POINT object + * \param group underlying the EC_GROUP object + * \return newly created EC_POINT object or NULL if an error occurred + */ +EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); + +/** Returns the EC_METHOD used in EC_POINT object + * \param point EC_POINT object + * \return the EC_METHOD used + */ +const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); + +/** Sets a point to infinity (neutral element) + * \param group underlying EC_GROUP object + * \param point EC_POINT to set to infinity + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); + +/** Sets the jacobian projective coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param z BIGNUM with the z-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, + EC_POINT *p, const BIGNUM *x, + const BIGNUM *y, const BIGNUM *z, + BN_CTX *ctx); + +/** Gets the jacobian projective coordinates of a EC_POINT over GFp + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param z BIGNUM for the z-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, + const EC_POINT *p, BIGNUM *x, + BIGNUM *y, BIGNUM *z, + BN_CTX *ctx); + +/** Sets the affine coordinates of an EC_POINT + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, + const BIGNUM *x, const BIGNUM *y, + BN_CTX *ctx); + +/** Gets the affine coordinates of an EC_POINT. + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, + BIGNUM *x, BIGNUM *y, BN_CTX *ctx); + +/** Sets the affine coordinates of an EC_POINT. A synonym of + * EC_POINT_set_affine_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, + EC_POINT *p, + const BIGNUM *x, + const BIGNUM *y, + BN_CTX *ctx)) + +/** Gets the affine coordinates of an EC_POINT. A synonym of + * EC_POINT_get_affine_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, + const EC_POINT *p, + BIGNUM *x, + BIGNUM *y, + BN_CTX *ctx)) + +/** Sets the x9.62 compressed coordinates of a EC_POINT + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with x-coordinate + * \param y_bit integer with the y-Bit (either 0 or 1) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, + const BIGNUM *x, int y_bit, + BN_CTX *ctx); + +/** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of + * EC_POINT_set_compressed_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with x-coordinate + * \param y_bit integer with the y-Bit (either 0 or 1) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, + EC_POINT *p, + const BIGNUM *x, + int y_bit, + BN_CTX *ctx)) +# ifndef OPENSSL_NO_EC2M +/** Sets the affine coordinates of an EC_POINT. A synonym of + * EC_POINT_set_affine_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with the x-coordinate + * \param y BIGNUM with the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, + EC_POINT *p, + const BIGNUM *x, + const BIGNUM *y, + BN_CTX *ctx)) + +/** Gets the affine coordinates of an EC_POINT. A synonym of + * EC_POINT_get_affine_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM for the x-coordinate + * \param y BIGNUM for the y-coordinate + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, + const EC_POINT *p, + BIGNUM *x, + BIGNUM *y, + BN_CTX *ctx)) + +/** Sets the x9.62 compressed coordinates of a EC_POINT. A synonym of + * EC_POINT_set_compressed_coordinates + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param x BIGNUM with x-coordinate + * \param y_bit integer with the y-Bit (either 0 or 1) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +DEPRECATEDIN_1_2_0(int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, + EC_POINT *p, + const BIGNUM *x, + int y_bit, + BN_CTX *ctx)) +# endif +/** Encodes a EC_POINT object to a octet string + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param form point conversion form + * \param buf memory buffer for the result. If NULL the function returns + * required buffer size. + * \param len length of the memory buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ +size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, + point_conversion_form_t form, + unsigned char *buf, size_t len, BN_CTX *ctx); + +/** Decodes a EC_POINT from a octet string + * \param group underlying EC_GROUP object + * \param p EC_POINT object + * \param buf memory buffer with the encoded ec point + * \param len length of the encoded ec point + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, + const unsigned char *buf, size_t len, BN_CTX *ctx); + +/** Encodes an EC_POINT object to an allocated octet string + * \param group underlying EC_GROUP object + * \param point EC_POINT object + * \param form point conversion form + * \param pbuf returns pointer to allocated buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ +size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, + point_conversion_form_t form, + unsigned char **pbuf, BN_CTX *ctx); + +/* other interfaces to point2oct/oct2point: */ +BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BIGNUM *, BN_CTX *); +EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *, + EC_POINT *, BN_CTX *); +char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *, + point_conversion_form_t form, BN_CTX *); +EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *, + EC_POINT *, BN_CTX *); + +/********************************************************************/ +/* functions for doing EC_POINT arithmetic */ +/********************************************************************/ + +/** Computes the sum of two EC_POINT + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result (r = a + b) + * \param a EC_POINT object with the first summand + * \param b EC_POINT object with the second summand + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, + const EC_POINT *b, BN_CTX *ctx); + +/** Computes the double of a EC_POINT + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result (r = 2 * a) + * \param a EC_POINT object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, + BN_CTX *ctx); + +/** Computes the inverse of a EC_POINT + * \param group underlying EC_GROUP object + * \param a EC_POINT object to be inverted (it's used for the result as well) + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx); + +/** Checks whether the point is the neutral element of the group + * \param group the underlying EC_GROUP object + * \param p EC_POINT object + * \return 1 if the point is the neutral element and 0 otherwise + */ +int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); + +/** Checks whether the point is on the curve + * \param group underlying EC_GROUP object + * \param point EC_POINT object to check + * \param ctx BN_CTX object (optional) + * \return 1 if the point is on the curve, 0 if not, or -1 on error + */ +int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, + BN_CTX *ctx); + +/** Compares two EC_POINTs + * \param group underlying EC_GROUP object + * \param a first EC_POINT object + * \param b second EC_POINT object + * \param ctx BN_CTX object (optional) + * \return 1 if the points are not equal, 0 if they are, or -1 on error + */ +int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, + BN_CTX *ctx); + +int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx); +int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, + EC_POINT *points[], BN_CTX *ctx); + +/** Computes r = generator * n + sum_{i=0}^{num-1} p[i] * m[i] + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result + * \param n BIGNUM with the multiplier for the group generator (optional) + * \param num number further summands + * \param p array of size num of EC_POINT objects + * \param m array of size num of BIGNUM objects + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, + size_t num, const EC_POINT *p[], const BIGNUM *m[], + BN_CTX *ctx); + +/** Computes r = generator * n + q * m + * \param group underlying EC_GROUP object + * \param r EC_POINT object for the result + * \param n BIGNUM with the multiplier for the group generator (optional) + * \param q EC_POINT object with the first factor of the second summand + * \param m BIGNUM with the second factor of the second summand + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, + const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx); + +/** Stores multiples of generator for faster point multiplication + * \param group EC_GROUP object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ +int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx); + +/** Reports whether a precomputation has been done + * \param group EC_GROUP object + * \return 1 if a pre-computation has been done and 0 otherwise + */ +int EC_GROUP_have_precompute_mult(const EC_GROUP *group); + +/********************************************************************/ +/* ASN1 stuff */ +/********************************************************************/ + +DECLARE_ASN1_ITEM(ECPKPARAMETERS) +DECLARE_ASN1_ALLOC_FUNCTIONS(ECPKPARAMETERS) +DECLARE_ASN1_ITEM(ECPARAMETERS) +DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) + +/* + * EC_GROUP_get_basis_type() returns the NID of the basis type used to + * represent the field elements + */ +int EC_GROUP_get_basis_type(const EC_GROUP *); +# ifndef OPENSSL_NO_EC2M +int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k); +int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1, + unsigned int *k2, unsigned int *k3); +# endif + +# define OPENSSL_EC_EXPLICIT_CURVE 0x000 +# define OPENSSL_EC_NAMED_CURVE 0x001 + +EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len); +int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out); + +# define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x) +# define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x) +# define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \ + (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x)) +# define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \ + (unsigned char *)(x)) + +int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off); +# ifndef OPENSSL_NO_STDIO +int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off); +# endif + +/********************************************************************/ +/* EC_KEY functions */ +/********************************************************************/ + +/* some values for the encoding_flag */ +# define EC_PKEY_NO_PARAMETERS 0x001 +# define EC_PKEY_NO_PUBKEY 0x002 + +/* some values for the flags field */ +# define EC_FLAG_NON_FIPS_ALLOW 0x1 +# define EC_FLAG_FIPS_CHECKED 0x2 +# define EC_FLAG_COFACTOR_ECDH 0x1000 + +/** Creates a new EC_KEY object. + * \return EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_new(void); + +int EC_KEY_get_flags(const EC_KEY *key); + +void EC_KEY_set_flags(EC_KEY *key, int flags); + +void EC_KEY_clear_flags(EC_KEY *key, int flags); + +/** Creates a new EC_KEY object using a named curve as underlying + * EC_GROUP object. + * \param nid NID of the named curve. + * \return EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_new_by_curve_name(int nid); + +/** Frees a EC_KEY object. + * \param key EC_KEY object to be freed. + */ +void EC_KEY_free(EC_KEY *key); + +/** Copies a EC_KEY object. + * \param dst destination EC_KEY object + * \param src src EC_KEY object + * \return dst or NULL if an error occurred. + */ +EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); + +/** Creates a new EC_KEY object and copies the content from src to it. + * \param src the source EC_KEY object + * \return newly created EC_KEY object or NULL if an error occurred. + */ +EC_KEY *EC_KEY_dup(const EC_KEY *src); + +/** Increases the internal reference count of a EC_KEY object. + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_up_ref(EC_KEY *key); + +/** Returns the ENGINE object of a EC_KEY object + * \param eckey EC_KEY object + * \return the ENGINE object (possibly NULL). + */ +ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey); + +/** Returns the EC_GROUP object of a EC_KEY object + * \param key EC_KEY object + * \return the EC_GROUP object (possibly NULL). + */ +const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); + +/** Sets the EC_GROUP of a EC_KEY object. + * \param key EC_KEY object + * \param group EC_GROUP to use in the EC_KEY object (note: the EC_KEY + * object will use an own copy of the EC_GROUP). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); + +/** Returns the private key of a EC_KEY object. + * \param key EC_KEY object + * \return a BIGNUM with the private key (possibly NULL). + */ +const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); + +/** Sets the private key of a EC_KEY object. + * \param key EC_KEY object + * \param prv BIGNUM with the private key (note: the EC_KEY object + * will use an own copy of the BIGNUM). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv); + +/** Returns the public key of a EC_KEY object. + * \param key the EC_KEY object + * \return a EC_POINT object with the public key (possibly NULL) + */ +const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); + +/** Sets the public key of a EC_KEY object. + * \param key EC_KEY object + * \param pub EC_POINT object with the public key (note: the EC_KEY object + * will use an own copy of the EC_POINT object). + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); + +unsigned EC_KEY_get_enc_flags(const EC_KEY *key); +void EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags); +point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); +void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); + +#define EC_KEY_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_EC_KEY, l, p, newf, dupf, freef) +int EC_KEY_set_ex_data(EC_KEY *key, int idx, void *arg); +void *EC_KEY_get_ex_data(const EC_KEY *key, int idx); + +/* wrapper functions for the underlying EC_GROUP object */ +void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); + +/** Creates a table of pre-computed multiples of the generator to + * accelerate further EC_KEY operations. + * \param key EC_KEY object + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); + +/** Creates a new ec private (and optional a new public) key. + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred. + */ +int EC_KEY_generate_key(EC_KEY *key); + +/** Verifies that a private and/or public key is valid. + * \param key the EC_KEY object + * \return 1 on success and 0 otherwise. + */ +int EC_KEY_check_key(const EC_KEY *key); + +/** Indicates if an EC_KEY can be used for signing. + * \param eckey the EC_KEY object + * \return 1 if can can sign and 0 otherwise. + */ +int EC_KEY_can_sign(const EC_KEY *eckey); + +/** Sets a public key from affine coordinates performing + * necessary NIST PKV tests. + * \param key the EC_KEY object + * \param x public key x coordinate + * \param y public key y coordinate + * \return 1 on success and 0 otherwise. + */ +int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, + BIGNUM *y); + +/** Encodes an EC_KEY public key to an allocated octet string + * \param key key to encode + * \param form point conversion form + * \param pbuf returns pointer to allocated buffer + * \param ctx BN_CTX object (optional) + * \return the length of the encoded octet string or 0 if an error occurred + */ +size_t EC_KEY_key2buf(const EC_KEY *key, point_conversion_form_t form, + unsigned char **pbuf, BN_CTX *ctx); + +/** Decodes a EC_KEY public key from a octet string + * \param key key to decode + * \param buf memory buffer with the encoded ec point + * \param len length of the encoded ec point + * \param ctx BN_CTX object (optional) + * \return 1 on success and 0 if an error occurred + */ + +int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len, + BN_CTX *ctx); + +/** Decodes an EC_KEY private key from an octet string + * \param key key to decode + * \param buf memory buffer with the encoded private key + * \param len length of the encoded key + * \return 1 on success and 0 if an error occurred + */ + +int EC_KEY_oct2priv(EC_KEY *key, const unsigned char *buf, size_t len); + +/** Encodes a EC_KEY private key to an octet string + * \param key key to encode + * \param buf memory buffer for the result. If NULL the function returns + * required buffer size. + * \param len length of the memory buffer + * \return the length of the encoded octet string or 0 if an error occurred + */ + +size_t EC_KEY_priv2oct(const EC_KEY *key, unsigned char *buf, size_t len); + +/** Encodes an EC_KEY private key to an allocated octet string + * \param eckey key to encode + * \param pbuf returns pointer to allocated buffer + * \return the length of the encoded octet string or 0 if an error occurred + */ +size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf); + +/********************************************************************/ +/* de- and encoding functions for SEC1 ECPrivateKey */ +/********************************************************************/ + +/** Decodes a private key from a memory buffer. + * \param key a pointer to a EC_KEY object which should be used (or NULL) + * \param in pointer to memory with the DER encoded private key + * \param len length of the DER encoded private key + * \return the decoded private key or NULL if an error occurred. + */ +EC_KEY *d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes a private key object and stores the result in a buffer. + * \param key the EC_KEY object to encode + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred. + */ +int i2d_ECPrivateKey(EC_KEY *key, unsigned char **out); + +/********************************************************************/ +/* de- and encoding functions for EC parameters */ +/********************************************************************/ + +/** Decodes ec parameter from a memory buffer. + * \param key a pointer to a EC_KEY object which should be used (or NULL) + * \param in pointer to memory with the DER encoded ec parameters + * \param len length of the DER encoded ec parameters + * \return a EC_KEY object with the decoded parameters or NULL if an error + * occurred. + */ +EC_KEY *d2i_ECParameters(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes ec parameter and stores the result in a buffer. + * \param key the EC_KEY object with ec parameters to encode + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred. + */ +int i2d_ECParameters(EC_KEY *key, unsigned char **out); + +/********************************************************************/ +/* de- and encoding functions for EC public key */ +/* (octet string, not DER -- hence 'o2i' and 'i2o') */ +/********************************************************************/ + +/** Decodes a ec public key from a octet string. + * \param key a pointer to a EC_KEY object which should be used + * \param in memory buffer with the encoded public key + * \param len length of the encoded public key + * \return EC_KEY object with decoded public key or NULL if an error + * occurred. + */ +EC_KEY *o2i_ECPublicKey(EC_KEY **key, const unsigned char **in, long len); + +/** Encodes a ec public key in an octet string. + * \param key the EC_KEY object with the public key + * \param out the buffer for the result (if NULL the function returns number + * of bytes needed). + * \return 1 on success and 0 if an error occurred + */ +int i2o_ECPublicKey(const EC_KEY *key, unsigned char **out); + +/** Prints out the ec parameters on human readable form. + * \param bp BIO object to which the information is printed + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred + */ +int ECParameters_print(BIO *bp, const EC_KEY *key); + +/** Prints out the contents of a EC_KEY object + * \param bp BIO object to which the information is printed + * \param key EC_KEY object + * \param off line offset + * \return 1 on success and 0 if an error occurred + */ +int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); + +# ifndef OPENSSL_NO_STDIO +/** Prints out the ec parameters on human readable form. + * \param fp file descriptor to which the information is printed + * \param key EC_KEY object + * \return 1 on success and 0 if an error occurred + */ +int ECParameters_print_fp(FILE *fp, const EC_KEY *key); + +/** Prints out the contents of a EC_KEY object + * \param fp file descriptor to which the information is printed + * \param key EC_KEY object + * \param off line offset + * \return 1 on success and 0 if an error occurred + */ +int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); + +# endif + +const EC_KEY_METHOD *EC_KEY_OpenSSL(void); +const EC_KEY_METHOD *EC_KEY_get_default_method(void); +void EC_KEY_set_default_method(const EC_KEY_METHOD *meth); +const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); +int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); +EC_KEY *EC_KEY_new_method(ENGINE *engine); + +/** The old name for ecdh_KDF_X9_63 + * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, + * it is actually specified in ANSI X9.63. + * This identifier is retained for backwards compatibility + */ +int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, + const unsigned char *Z, size_t Zlen, + const unsigned char *sinfo, size_t sinfolen, + const EVP_MD *md); + +int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, + const EC_KEY *ecdh, + void *(*KDF) (const void *in, size_t inlen, + void *out, size_t *outlen)); + +typedef struct ECDSA_SIG_st ECDSA_SIG; + +/** Allocates and initialize a ECDSA_SIG structure + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_SIG_new(void); + +/** frees a ECDSA_SIG structure + * \param sig pointer to the ECDSA_SIG structure + */ +void ECDSA_SIG_free(ECDSA_SIG *sig); + +/** DER encode content of ECDSA_SIG object (note: this function modifies *pp + * (*pp += length of the DER encoded signature)). + * \param sig pointer to the ECDSA_SIG object + * \param pp pointer to a unsigned char pointer for the output or NULL + * \return the length of the DER encoded ECDSA_SIG object or a negative value + * on error + */ +int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp); + +/** Decodes a DER encoded ECDSA signature (note: this function changes *pp + * (*pp += len)). + * \param sig pointer to ECDSA_SIG pointer (may be NULL) + * \param pp memory buffer with the DER encoded signature + * \param len length of the buffer + * \return pointer to the decoded ECDSA_SIG structure (or NULL) + */ +ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len); + +/** Accessor for r and s fields of ECDSA_SIG + * \param sig pointer to ECDSA_SIG structure + * \param pr pointer to BIGNUM pointer for r (may be NULL) + * \param ps pointer to BIGNUM pointer for s (may be NULL) + */ +void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); + +/** Accessor for r field of ECDSA_SIG + * \param sig pointer to ECDSA_SIG structure + */ +const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig); + +/** Accessor for s field of ECDSA_SIG + * \param sig pointer to ECDSA_SIG structure + */ +const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig); + +/** Setter for r and s fields of ECDSA_SIG + * \param sig pointer to ECDSA_SIG structure + * \param r pointer to BIGNUM for r (may be NULL) + * \param s pointer to BIGNUM for s (may be NULL) + */ +int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s); + +/** Computes the ECDSA signature of the given hash value using + * the supplied private key and returns the created signature. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param eckey EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, + EC_KEY *eckey); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param kinv BIGNUM with a pre-computed inverse k (optional) + * \param rp BIGNUM with a pre-computed rp value (optional), + * see ECDSA_sign_setup + * \param eckey EC_KEY object containing a private EC key + * \return pointer to a ECDSA_SIG structure or NULL if an error occurred + */ +ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, + const BIGNUM *kinv, const BIGNUM *rp, + EC_KEY *eckey); + +/** Verifies that the supplied signature is a valid ECDSA + * signature of the supplied hash value using the supplied public key. + * \param dgst pointer to the hash value + * \param dgst_len length of the hash value + * \param sig ECDSA_SIG structure + * \param eckey EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid + * and -1 on error + */ +int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, + const ECDSA_SIG *sig, EC_KEY *eckey); + +/** Precompute parts of the signing operation + * \param eckey EC_KEY object containing a private EC key + * \param ctx BN_CTX object (optional) + * \param kinv BIGNUM pointer for the inverse of k + * \param rp BIGNUM pointer for x coordinate of k * generator + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig memory for the DER encoded created signature + * \param siglen pointer to the length of the returned signature + * \param eckey EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); + +/** Computes ECDSA signature of a given hash value using the supplied + * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). + * \param type this parameter is ignored + * \param dgst pointer to the hash value to sign + * \param dgstlen length of the hash value + * \param sig buffer to hold the DER encoded signature + * \param siglen pointer to the length of the returned signature + * \param kinv BIGNUM with a pre-computed inverse k (optional) + * \param rp BIGNUM with a pre-computed rp value (optional), + * see ECDSA_sign_setup + * \param eckey EC_KEY object containing a private EC key + * \return 1 on success and 0 otherwise + */ +int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, + unsigned char *sig, unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); + +/** Verifies that the given signature is valid ECDSA signature + * of the supplied hash value using the specified public key. + * \param type this parameter is ignored + * \param dgst pointer to the hash value + * \param dgstlen length of the hash value + * \param sig pointer to the DER encoded signature + * \param siglen length of the DER encoded signature + * \param eckey EC_KEY object containing a public EC key + * \return 1 if the signature is valid, 0 if the signature is invalid + * and -1 on error + */ +int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, + const unsigned char *sig, int siglen, EC_KEY *eckey); + +/** Returns the maximum length of the DER encoded signature + * \param eckey EC_KEY object + * \return numbers of bytes required for the DER encoded signature + */ +int ECDSA_size(const EC_KEY *eckey); + +/********************************************************************/ +/* EC_KEY_METHOD constructors, destructors, writers and accessors */ +/********************************************************************/ + +EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth); +void EC_KEY_METHOD_free(EC_KEY_METHOD *meth); +void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, + int (*init)(EC_KEY *key), + void (*finish)(EC_KEY *key), + int (*copy)(EC_KEY *dest, const EC_KEY *src), + int (*set_group)(EC_KEY *key, const EC_GROUP *grp), + int (*set_private)(EC_KEY *key, + const BIGNUM *priv_key), + int (*set_public)(EC_KEY *key, + const EC_POINT *pub_key)); + +void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, + int (*keygen)(EC_KEY *key)); + +void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, + int (*ckey)(unsigned char **psec, + size_t *pseclen, + const EC_POINT *pub_key, + const EC_KEY *ecdh)); + +void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, + int (*sign)(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey), + int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, + BIGNUM **kinvp, BIGNUM **rp), + ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, + int dgst_len, + const BIGNUM *in_kinv, + const BIGNUM *in_r, + EC_KEY *eckey)); + +void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, + int (*verify)(int type, const unsigned + char *dgst, int dgst_len, + const unsigned char *sigbuf, + int sig_len, EC_KEY *eckey), + int (*verify_sig)(const unsigned char *dgst, + int dgst_len, + const ECDSA_SIG *sig, + EC_KEY *eckey)); + +void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, + int (**pinit)(EC_KEY *key), + void (**pfinish)(EC_KEY *key), + int (**pcopy)(EC_KEY *dest, const EC_KEY *src), + int (**pset_group)(EC_KEY *key, + const EC_GROUP *grp), + int (**pset_private)(EC_KEY *key, + const BIGNUM *priv_key), + int (**pset_public)(EC_KEY *key, + const EC_POINT *pub_key)); + +void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, + int (**pkeygen)(EC_KEY *key)); + +void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, + int (**pck)(unsigned char **psec, + size_t *pseclen, + const EC_POINT *pub_key, + const EC_KEY *ecdh)); + +void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, + int (**psign)(int type, const unsigned char *dgst, + int dlen, unsigned char *sig, + unsigned int *siglen, + const BIGNUM *kinv, const BIGNUM *r, + EC_KEY *eckey), + int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, + BIGNUM **kinvp, BIGNUM **rp), + ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, + int dgst_len, + const BIGNUM *in_kinv, + const BIGNUM *in_r, + EC_KEY *eckey)); + +void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, + int (**pverify)(int type, const unsigned + char *dgst, int dgst_len, + const unsigned char *sigbuf, + int sig_len, EC_KEY *eckey), + int (**pverify_sig)(const unsigned char *dgst, + int dgst_len, + const ECDSA_SIG *sig, + EC_KEY *eckey)); + +# define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) + +# ifndef __cplusplus +# if defined(__SUNPRO_C) +# if __SUNPRO_C >= 0x520 +# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) +# endif +# endif +# endif + +# define EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID, nid, NULL) + +# define EVP_PKEY_CTX_set_ec_param_enc(ctx, flag) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_PARAMGEN|EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_EC_PARAM_ENC, flag, NULL) + +# define EVP_PKEY_CTX_set_ecdh_cofactor_mode(ctx, flag) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_ECDH_COFACTOR, flag, NULL) + +# define EVP_PKEY_CTX_get_ecdh_cofactor_mode(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_ECDH_COFACTOR, -2, NULL) + +# define EVP_PKEY_CTX_set_ecdh_kdf_type(ctx, kdf) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_TYPE, kdf, NULL) + +# define EVP_PKEY_CTX_get_ecdh_kdf_type(ctx) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_TYPE, -2, NULL) + +# define EVP_PKEY_CTX_set_ecdh_kdf_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_get_ecdh_kdf_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_MD, 0, (void *)(pmd)) + +# define EVP_PKEY_CTX_set_ecdh_kdf_outlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_OUTLEN, len, NULL) + +# define EVP_PKEY_CTX_get_ecdh_kdf_outlen(ctx, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN, 0, \ + (void *)(plen)) + +# define EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p, plen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_EC_KDF_UKM, plen, (void *)(p)) + +# define EVP_PKEY_CTX_get0_ecdh_kdf_ukm(ctx, p) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_EC, \ + EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_GET_EC_KDF_UKM, 0, (void *)(p)) + +/* SM2 will skip the operation check so no need to pass operation here */ +# define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \ + EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ + EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id)) + +# define EVP_PKEY_CTX_get1_id(ctx, id) \ + EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ + EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id)) + +# define EVP_PKEY_CTX_get1_id_len(ctx, id_len) \ + EVP_PKEY_CTX_ctrl(ctx, -1, -1, \ + EVP_PKEY_CTRL_GET1_ID_LEN, 0, (void*)(id_len)) + +# define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_EC_PARAM_ENC (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_EC_ECDH_COFACTOR (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_EC_KDF_TYPE (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_GET_EC_KDF_MD (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN (EVP_PKEY_ALG_CTRL + 8) +# define EVP_PKEY_CTRL_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_GET_EC_KDF_UKM (EVP_PKEY_ALG_CTRL + 10) +# define EVP_PKEY_CTRL_SET1_ID (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_GET1_ID (EVP_PKEY_ALG_CTRL + 12) +# define EVP_PKEY_CTRL_GET1_ID_LEN (EVP_PKEY_ALG_CTRL + 13) +/* KDF types */ +# define EVP_PKEY_ECDH_KDF_NONE 1 +# define EVP_PKEY_ECDH_KDF_X9_63 2 +/** The old name for EVP_PKEY_ECDH_KDF_X9_63 + * The ECDH KDF specification has been mistakingly attributed to ANSI X9.62, + * it is actually specified in ANSI X9.63. + * This identifier is retained for backwards compatibility + */ +# define EVP_PKEY_ECDH_KDF_X9_62 EVP_PKEY_ECDH_KDF_X9_63 + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/engineerr.h postgresql-hll-2.14/include/openssl/engineerr.h --- postgresql-hll-2.14_old/include/openssl/engineerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/engineerr.h 2020-12-12 17:06:43.331349122 +0800 @@ -0,0 +1,111 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ENGINEERR_H +# define HEADER_ENGINEERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_ENGINE + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_ENGINE_strings(void); + +/* + * ENGINE function codes. + */ +# define ENGINE_F_DIGEST_UPDATE 198 +# define ENGINE_F_DYNAMIC_CTRL 180 +# define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 +# define ENGINE_F_DYNAMIC_LOAD 182 +# define ENGINE_F_DYNAMIC_SET_DATA_CTX 183 +# define ENGINE_F_ENGINE_ADD 105 +# define ENGINE_F_ENGINE_BY_ID 106 +# define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 +# define ENGINE_F_ENGINE_CTRL 142 +# define ENGINE_F_ENGINE_CTRL_CMD 178 +# define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 +# define ENGINE_F_ENGINE_FINISH 107 +# define ENGINE_F_ENGINE_GET_CIPHER 185 +# define ENGINE_F_ENGINE_GET_DIGEST 186 +# define ENGINE_F_ENGINE_GET_FIRST 195 +# define ENGINE_F_ENGINE_GET_LAST 196 +# define ENGINE_F_ENGINE_GET_NEXT 115 +# define ENGINE_F_ENGINE_GET_PKEY_ASN1_METH 193 +# define ENGINE_F_ENGINE_GET_PKEY_METH 192 +# define ENGINE_F_ENGINE_GET_PREV 116 +# define ENGINE_F_ENGINE_INIT 119 +# define ENGINE_F_ENGINE_LIST_ADD 120 +# define ENGINE_F_ENGINE_LIST_REMOVE 121 +# define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 +# define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 +# define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 194 +# define ENGINE_F_ENGINE_NEW 122 +# define ENGINE_F_ENGINE_PKEY_ASN1_FIND_STR 197 +# define ENGINE_F_ENGINE_REMOVE 123 +# define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 +# define ENGINE_F_ENGINE_SET_ID 129 +# define ENGINE_F_ENGINE_SET_NAME 130 +# define ENGINE_F_ENGINE_TABLE_REGISTER 184 +# define ENGINE_F_ENGINE_UNLOCKED_FINISH 191 +# define ENGINE_F_ENGINE_UP_REF 190 +# define ENGINE_F_INT_CLEANUP_ITEM 199 +# define ENGINE_F_INT_CTRL_HELPER 172 +# define ENGINE_F_INT_ENGINE_CONFIGURE 188 +# define ENGINE_F_INT_ENGINE_MODULE_INIT 187 +# define ENGINE_F_OSSL_HMAC_INIT 200 + +/* + * ENGINE reason codes. + */ +# define ENGINE_R_ALREADY_LOADED 100 +# define ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER 133 +# define ENGINE_R_CMD_NOT_EXECUTABLE 134 +# define ENGINE_R_COMMAND_TAKES_INPUT 135 +# define ENGINE_R_COMMAND_TAKES_NO_INPUT 136 +# define ENGINE_R_CONFLICTING_ENGINE_ID 103 +# define ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED 119 +# define ENGINE_R_DSO_FAILURE 104 +# define ENGINE_R_DSO_NOT_FOUND 132 +# define ENGINE_R_ENGINES_SECTION_ERROR 148 +# define ENGINE_R_ENGINE_CONFIGURATION_ERROR 102 +# define ENGINE_R_ENGINE_IS_NOT_IN_LIST 105 +# define ENGINE_R_ENGINE_SECTION_ERROR 149 +# define ENGINE_R_FAILED_LOADING_PRIVATE_KEY 128 +# define ENGINE_R_FAILED_LOADING_PUBLIC_KEY 129 +# define ENGINE_R_FINISH_FAILED 106 +# define ENGINE_R_ID_OR_NAME_MISSING 108 +# define ENGINE_R_INIT_FAILED 109 +# define ENGINE_R_INTERNAL_LIST_ERROR 110 +# define ENGINE_R_INVALID_ARGUMENT 143 +# define ENGINE_R_INVALID_CMD_NAME 137 +# define ENGINE_R_INVALID_CMD_NUMBER 138 +# define ENGINE_R_INVALID_INIT_VALUE 151 +# define ENGINE_R_INVALID_STRING 150 +# define ENGINE_R_NOT_INITIALISED 117 +# define ENGINE_R_NOT_LOADED 112 +# define ENGINE_R_NO_CONTROL_FUNCTION 120 +# define ENGINE_R_NO_INDEX 144 +# define ENGINE_R_NO_LOAD_FUNCTION 125 +# define ENGINE_R_NO_REFERENCE 130 +# define ENGINE_R_NO_SUCH_ENGINE 116 +# define ENGINE_R_UNIMPLEMENTED_CIPHER 146 +# define ENGINE_R_UNIMPLEMENTED_DIGEST 147 +# define ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD 101 +# define ENGINE_R_VERSION_INCOMPATIBILITY 145 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/engine.h postgresql-hll-2.14/include/openssl/engine.h --- postgresql-hll-2.14_old/include/openssl/engine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/engine.h 2020-12-12 17:06:43.331349122 +0800 @@ -0,0 +1,751 @@ +/* + * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ENGINE_H +# define HEADER_ENGINE_H + +# include + +# ifndef OPENSSL_NO_ENGINE +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# include +# include +# include +# include +# include +# include +# include +# endif +# include +# include +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +/* + * These flags are used to control combinations of algorithm (methods) by + * bitwise "OR"ing. + */ +# define ENGINE_METHOD_RSA (unsigned int)0x0001 +# define ENGINE_METHOD_DSA (unsigned int)0x0002 +# define ENGINE_METHOD_DH (unsigned int)0x0004 +# define ENGINE_METHOD_RAND (unsigned int)0x0008 +# define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 +# define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 +# define ENGINE_METHOD_PKEY_METHS (unsigned int)0x0200 +# define ENGINE_METHOD_PKEY_ASN1_METHS (unsigned int)0x0400 +# define ENGINE_METHOD_EC (unsigned int)0x0800 +/* Obvious all-or-nothing cases. */ +# define ENGINE_METHOD_ALL (unsigned int)0xFFFF +# define ENGINE_METHOD_NONE (unsigned int)0x0000 + +/* + * This(ese) flag(s) controls behaviour of the ENGINE_TABLE mechanism used + * internally to control registration of ENGINE implementations, and can be + * set by ENGINE_set_table_flags(). The "NOINIT" flag prevents attempts to + * initialise registered ENGINEs if they are not already initialised. + */ +# define ENGINE_TABLE_FLAG_NOINIT (unsigned int)0x0001 + +/* ENGINE flags that can be set by ENGINE_set_flags(). */ +/* Not used */ +/* #define ENGINE_FLAGS_MALLOCED 0x0001 */ + +/* + * This flag is for ENGINEs that wish to handle the various 'CMD'-related + * control commands on their own. Without this flag, ENGINE_ctrl() handles + * these control commands on behalf of the ENGINE using their "cmd_defns" + * data. + */ +# define ENGINE_FLAGS_MANUAL_CMD_CTRL (int)0x0002 + +/* + * This flag is for ENGINEs who return new duplicate structures when found + * via "ENGINE_by_id()". When an ENGINE must store state (eg. if + * ENGINE_ctrl() commands are called in sequence as part of some stateful + * process like key-generation setup and execution), it can set this flag - + * then each attempt to obtain the ENGINE will result in it being copied into + * a new structure. Normally, ENGINEs don't declare this flag so + * ENGINE_by_id() just increments the existing ENGINE's structural reference + * count. + */ +# define ENGINE_FLAGS_BY_ID_COPY (int)0x0004 + +/* + * This flag if for an ENGINE that does not want its methods registered as + * part of ENGINE_register_all_complete() for example if the methods are not + * usable as default methods. + */ + +# define ENGINE_FLAGS_NO_REGISTER_ALL (int)0x0008 + +/* + * ENGINEs can support their own command types, and these flags are used in + * ENGINE_CTRL_GET_CMD_FLAGS to indicate to the caller what kind of input + * each command expects. Currently only numeric and string input is + * supported. If a control command supports none of the _NUMERIC, _STRING, or + * _NO_INPUT options, then it is regarded as an "internal" control command - + * and not for use in config setting situations. As such, they're not + * available to the ENGINE_ctrl_cmd_string() function, only raw ENGINE_ctrl() + * access. Changes to this list of 'command types' should be reflected + * carefully in ENGINE_cmd_is_executable() and ENGINE_ctrl_cmd_string(). + */ + +/* accepts a 'long' input value (3rd parameter to ENGINE_ctrl) */ +# define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001 +/* + * accepts string input (cast from 'void*' to 'const char *', 4th parameter + * to ENGINE_ctrl) + */ +# define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002 +/* + * Indicates that the control command takes *no* input. Ie. the control + * command is unparameterised. + */ +# define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004 +/* + * Indicates that the control command is internal. This control command won't + * be shown in any output, and is only usable through the ENGINE_ctrl_cmd() + * function. + */ +# define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008 + +/* + * NB: These 3 control commands are deprecated and should not be used. + * ENGINEs relying on these commands should compile conditional support for + * compatibility (eg. if these symbols are defined) but should also migrate + * the same functionality to their own ENGINE-specific control functions that + * can be "discovered" by calling applications. The fact these control + * commands wouldn't be "executable" (ie. usable by text-based config) + * doesn't change the fact that application code can find and use them + * without requiring per-ENGINE hacking. + */ + +/* + * These flags are used to tell the ctrl function what should be done. All + * command numbers are shared between all engines, even if some don't make + * sense to some engines. In such a case, they do nothing but return the + * error ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED. + */ +# define ENGINE_CTRL_SET_LOGSTREAM 1 +# define ENGINE_CTRL_SET_PASSWORD_CALLBACK 2 +# define ENGINE_CTRL_HUP 3/* Close and reinitialise + * any handles/connections + * etc. */ +# define ENGINE_CTRL_SET_USER_INTERFACE 4/* Alternative to callback */ +# define ENGINE_CTRL_SET_CALLBACK_DATA 5/* User-specific data, used + * when calling the password + * callback and the user + * interface */ +# define ENGINE_CTRL_LOAD_CONFIGURATION 6/* Load a configuration, + * given a string that + * represents a file name + * or so */ +# define ENGINE_CTRL_LOAD_SECTION 7/* Load data from a given + * section in the already + * loaded configuration */ + +/* + * These control commands allow an application to deal with an arbitrary + * engine in a dynamic way. Warn: Negative return values indicate errors FOR + * THESE COMMANDS because zero is used to indicate 'end-of-list'. Other + * commands, including ENGINE-specific command types, return zero for an + * error. An ENGINE can choose to implement these ctrl functions, and can + * internally manage things however it chooses - it does so by setting the + * ENGINE_FLAGS_MANUAL_CMD_CTRL flag (using ENGINE_set_flags()). Otherwise + * the ENGINE_ctrl() code handles this on the ENGINE's behalf using the + * cmd_defns data (set using ENGINE_set_cmd_defns()). This means an ENGINE's + * ctrl() handler need only implement its own commands - the above "meta" + * commands will be taken care of. + */ + +/* + * Returns non-zero if the supplied ENGINE has a ctrl() handler. If "not", + * then all the remaining control commands will return failure, so it is + * worth checking this first if the caller is trying to "discover" the + * engine's capabilities and doesn't want errors generated unnecessarily. + */ +# define ENGINE_CTRL_HAS_CTRL_FUNCTION 10 +/* + * Returns a positive command number for the first command supported by the + * engine. Returns zero if no ctrl commands are supported. + */ +# define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11 +/* + * The 'long' argument specifies a command implemented by the engine, and the + * return value is the next command supported, or zero if there are no more. + */ +# define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12 +/* + * The 'void*' argument is a command name (cast from 'const char *'), and the + * return value is the command that corresponds to it. + */ +# define ENGINE_CTRL_GET_CMD_FROM_NAME 13 +/* + * The next two allow a command to be converted into its corresponding string + * form. In each case, the 'long' argument supplies the command. In the + * NAME_LEN case, the return value is the length of the command name (not + * counting a trailing EOL). In the NAME case, the 'void*' argument must be a + * string buffer large enough, and it will be populated with the name of the + * command (WITH a trailing EOL). + */ +# define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14 +# define ENGINE_CTRL_GET_NAME_FROM_CMD 15 +/* The next two are similar but give a "short description" of a command. */ +# define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16 +# define ENGINE_CTRL_GET_DESC_FROM_CMD 17 +/* + * With this command, the return value is the OR'd combination of + * ENGINE_CMD_FLAG_*** values that indicate what kind of input a given + * engine-specific ctrl command expects. + */ +# define ENGINE_CTRL_GET_CMD_FLAGS 18 + +/* + * ENGINE implementations should start the numbering of their own control + * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). + */ +# define ENGINE_CMD_BASE 200 + +/* + * NB: These 2 nCipher "chil" control commands are deprecated, and their + * functionality is now available through ENGINE-specific control commands + * (exposed through the above-mentioned 'CMD'-handling). Code using these 2 + * commands should be migrated to the more general command handling before + * these are removed. + */ + +/* Flags specific to the nCipher "chil" engine */ +# define ENGINE_CTRL_CHIL_SET_FORKCHECK 100 + /* + * Depending on the value of the (long)i argument, this sets or + * unsets the SimpleForkCheck flag in the CHIL API to enable or + * disable checking and workarounds for applications that fork(). + */ +# define ENGINE_CTRL_CHIL_NO_LOCKING 101 + /* + * This prevents the initialisation function from providing mutex + * callbacks to the nCipher library. + */ + +/* + * If an ENGINE supports its own specific control commands and wishes the + * framework to handle the above 'ENGINE_CMD_***'-manipulation commands on + * its behalf, it should supply a null-terminated array of ENGINE_CMD_DEFN + * entries to ENGINE_set_cmd_defns(). It should also implement a ctrl() + * handler that supports the stated commands (ie. the "cmd_num" entries as + * described by the array). NB: The array must be ordered in increasing order + * of cmd_num. "null-terminated" means that the last ENGINE_CMD_DEFN element + * has cmd_num set to zero and/or cmd_name set to NULL. + */ +typedef struct ENGINE_CMD_DEFN_st { + unsigned int cmd_num; /* The command number */ + const char *cmd_name; /* The command name itself */ + const char *cmd_desc; /* A short description of the command */ + unsigned int cmd_flags; /* The input the command expects */ +} ENGINE_CMD_DEFN; + +/* Generic function pointer */ +typedef int (*ENGINE_GEN_FUNC_PTR) (void); +/* Generic function pointer taking no arguments */ +typedef int (*ENGINE_GEN_INT_FUNC_PTR) (ENGINE *); +/* Specific control function pointer */ +typedef int (*ENGINE_CTRL_FUNC_PTR) (ENGINE *, int, long, void *, + void (*f) (void)); +/* Generic load_key function pointer */ +typedef EVP_PKEY *(*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, + UI_METHOD *ui_method, + void *callback_data); +typedef int (*ENGINE_SSL_CLIENT_CERT_PTR) (ENGINE *, SSL *ssl, + STACK_OF(X509_NAME) *ca_dn, + X509 **pcert, EVP_PKEY **pkey, + STACK_OF(X509) **pother, + UI_METHOD *ui_method, + void *callback_data); +/*- + * These callback types are for an ENGINE's handler for cipher and digest logic. + * These handlers have these prototypes; + * int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid); + * int foo(ENGINE *e, const EVP_MD **digest, const int **nids, int nid); + * Looking at how to implement these handlers in the case of cipher support, if + * the framework wants the EVP_CIPHER for 'nid', it will call; + * foo(e, &p_evp_cipher, NULL, nid); (return zero for failure) + * If the framework wants a list of supported 'nid's, it will call; + * foo(e, NULL, &p_nids, 0); (returns number of 'nids' or -1 for error) + */ +/* + * Returns to a pointer to the array of supported cipher 'nid's. If the + * second parameter is non-NULL it is set to the size of the returned array. + */ +typedef int (*ENGINE_CIPHERS_PTR) (ENGINE *, const EVP_CIPHER **, + const int **, int); +typedef int (*ENGINE_DIGESTS_PTR) (ENGINE *, const EVP_MD **, const int **, + int); +typedef int (*ENGINE_PKEY_METHS_PTR) (ENGINE *, EVP_PKEY_METHOD **, + const int **, int); +typedef int (*ENGINE_PKEY_ASN1_METHS_PTR) (ENGINE *, EVP_PKEY_ASN1_METHOD **, + const int **, int); +/* + * STRUCTURE functions ... all of these functions deal with pointers to + * ENGINE structures where the pointers have a "structural reference". This + * means that their reference is to allowed access to the structure but it + * does not imply that the structure is functional. To simply increment or + * decrement the structural reference count, use ENGINE_by_id and + * ENGINE_free. NB: This is not required when iterating using ENGINE_get_next + * as it will automatically decrement the structural reference count of the + * "current" ENGINE and increment the structural reference count of the + * ENGINE it returns (unless it is NULL). + */ + +/* Get the first/last "ENGINE" type available. */ +ENGINE *ENGINE_get_first(void); +ENGINE *ENGINE_get_last(void); +/* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ +ENGINE *ENGINE_get_next(ENGINE *e); +ENGINE *ENGINE_get_prev(ENGINE *e); +/* Add another "ENGINE" type into the array. */ +int ENGINE_add(ENGINE *e); +/* Remove an existing "ENGINE" type from the array. */ +int ENGINE_remove(ENGINE *e); +/* Retrieve an engine from the list by its unique "id" value. */ +ENGINE *ENGINE_by_id(const char *id); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define ENGINE_load_openssl() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_OPENSSL, NULL) +# define ENGINE_load_dynamic() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL) +# ifndef OPENSSL_NO_STATIC_ENGINE +# define ENGINE_load_padlock() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_PADLOCK, NULL) +# define ENGINE_load_capi() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CAPI, NULL) +# define ENGINE_load_afalg() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL) +# endif +# define ENGINE_load_cryptodev() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_CRYPTODEV, NULL) +# define ENGINE_load_rdrand() \ + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_RDRAND, NULL) +#endif +void ENGINE_load_builtin_engines(void); + +/* + * Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation + * "registry" handling. + */ +unsigned int ENGINE_get_table_flags(void); +void ENGINE_set_table_flags(unsigned int flags); + +/*- Manage registration of ENGINEs per "table". For each type, there are 3 + * functions; + * ENGINE_register_***(e) - registers the implementation from 'e' (if it has one) + * ENGINE_unregister_***(e) - unregister the implementation from 'e' + * ENGINE_register_all_***() - call ENGINE_register_***() for each 'e' in the list + * Cleanup is automatically registered from each table when required. + */ + +int ENGINE_register_RSA(ENGINE *e); +void ENGINE_unregister_RSA(ENGINE *e); +void ENGINE_register_all_RSA(void); + +int ENGINE_register_DSA(ENGINE *e); +void ENGINE_unregister_DSA(ENGINE *e); +void ENGINE_register_all_DSA(void); + +int ENGINE_register_EC(ENGINE *e); +void ENGINE_unregister_EC(ENGINE *e); +void ENGINE_register_all_EC(void); + +int ENGINE_register_DH(ENGINE *e); +void ENGINE_unregister_DH(ENGINE *e); +void ENGINE_register_all_DH(void); + +int ENGINE_register_RAND(ENGINE *e); +void ENGINE_unregister_RAND(ENGINE *e); +void ENGINE_register_all_RAND(void); + +int ENGINE_register_ciphers(ENGINE *e); +void ENGINE_unregister_ciphers(ENGINE *e); +void ENGINE_register_all_ciphers(void); + +int ENGINE_register_digests(ENGINE *e); +void ENGINE_unregister_digests(ENGINE *e); +void ENGINE_register_all_digests(void); + +int ENGINE_register_pkey_meths(ENGINE *e); +void ENGINE_unregister_pkey_meths(ENGINE *e); +void ENGINE_register_all_pkey_meths(void); + +int ENGINE_register_pkey_asn1_meths(ENGINE *e); +void ENGINE_unregister_pkey_asn1_meths(ENGINE *e); +void ENGINE_register_all_pkey_asn1_meths(void); + +/* + * These functions register all support from the above categories. Note, use + * of these functions can result in static linkage of code your application + * may not need. If you only need a subset of functionality, consider using + * more selective initialisation. + */ +int ENGINE_register_complete(ENGINE *e); +int ENGINE_register_all_complete(void); + +/* + * Send parameterised control commands to the engine. The possibilities to + * send down an integer, a pointer to data or a function pointer are + * provided. Any of the parameters may or may not be NULL, depending on the + * command number. In actuality, this function only requires a structural + * (rather than functional) reference to an engine, but many control commands + * may require the engine be functional. The caller should be aware of trying + * commands that require an operational ENGINE, and only use functional + * references in such situations. + */ +int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)); + +/* + * This function tests if an ENGINE-specific command is usable as a + * "setting". Eg. in an application's config file that gets processed through + * ENGINE_ctrl_cmd_string(). If this returns zero, it is not available to + * ENGINE_ctrl_cmd_string(), only ENGINE_ctrl(). + */ +int ENGINE_cmd_is_executable(ENGINE *e, int cmd); + +/* + * This function works like ENGINE_ctrl() with the exception of taking a + * command name instead of a command number, and can handle optional + * commands. See the comment on ENGINE_ctrl_cmd_string() for an explanation + * on how to use the cmd_name and cmd_optional. + */ +int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, + long i, void *p, void (*f) (void), int cmd_optional); + +/* + * This function passes a command-name and argument to an ENGINE. The + * cmd_name is converted to a command number and the control command is + * called using 'arg' as an argument (unless the ENGINE doesn't support such + * a command, in which case no control command is called). The command is + * checked for input flags, and if necessary the argument will be converted + * to a numeric value. If cmd_optional is non-zero, then if the ENGINE + * doesn't support the given cmd_name the return value will be success + * anyway. This function is intended for applications to use so that users + * (or config files) can supply engine-specific config data to the ENGINE at + * run-time to control behaviour of specific engines. As such, it shouldn't + * be used for calling ENGINE_ctrl() functions that return data, deal with + * binary data, or that are otherwise supposed to be used directly through + * ENGINE_ctrl() in application code. Any "return" data from an ENGINE_ctrl() + * operation in this function will be lost - the return value is interpreted + * as failure if the return value is zero, success otherwise, and this + * function returns a boolean value as a result. In other words, vendors of + * 'ENGINE'-enabled devices should write ENGINE implementations with + * parameterisations that work in this scheme, so that compliant ENGINE-based + * applications can work consistently with the same configuration for the + * same ENGINE-enabled devices, across applications. + */ +int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, + int cmd_optional); + +/* + * These functions are useful for manufacturing new ENGINE structures. They + * don't address reference counting at all - one uses them to populate an + * ENGINE structure with personalised implementations of things prior to + * using it directly or adding it to the builtin ENGINE list in OpenSSL. + * These are also here so that the ENGINE structure doesn't have to be + * exposed and break binary compatibility! + */ +ENGINE *ENGINE_new(void); +int ENGINE_free(ENGINE *e); +int ENGINE_up_ref(ENGINE *e); +int ENGINE_set_id(ENGINE *e, const char *id); +int ENGINE_set_name(ENGINE *e, const char *name); +int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); +int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); +int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ecdsa_meth); +int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); +int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); +int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); +int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); +int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); +int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); +int ENGINE_set_load_privkey_function(ENGINE *e, + ENGINE_LOAD_KEY_PTR loadpriv_f); +int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); +int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, + ENGINE_SSL_CLIENT_CERT_PTR + loadssl_f); +int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); +int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); +int ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f); +int ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f); +int ENGINE_set_flags(ENGINE *e, int flags); +int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); +/* These functions allow control over any per-structure ENGINE data. */ +#define ENGINE_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, l, p, newf, dupf, freef) +int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); +void *ENGINE_get_ex_data(const ENGINE *e, int idx); + +#if OPENSSL_API_COMPAT < 0x10100000L +/* + * This function previously cleaned up anything that needs it. Auto-deinit will + * now take care of it so it is no longer required to call this function. + */ +# define ENGINE_cleanup() while(0) continue +#endif + +/* + * These return values from within the ENGINE structure. These can be useful + * with functional references as well as structural references - it depends + * which you obtained. Using the result for functional purposes if you only + * obtained a structural reference may be problematic! + */ +const char *ENGINE_get_id(const ENGINE *e); +const char *ENGINE_get_name(const ENGINE *e); +const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); +const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); +const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e); +const DH_METHOD *ENGINE_get_DH(const ENGINE *e); +const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); +ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); +ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); +ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); +ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE + *e); +ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); +ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); +ENGINE_PKEY_METHS_PTR ENGINE_get_pkey_meths(const ENGINE *e); +ENGINE_PKEY_ASN1_METHS_PTR ENGINE_get_pkey_asn1_meths(const ENGINE *e); +const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); +const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); +const EVP_PKEY_METHOD *ENGINE_get_pkey_meth(ENGINE *e, int nid); +const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid); +const EVP_PKEY_ASN1_METHOD *ENGINE_get_pkey_asn1_meth_str(ENGINE *e, + const char *str, + int len); +const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe, + const char *str, + int len); +const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); +int ENGINE_get_flags(const ENGINE *e); + +/* + * FUNCTIONAL functions. These functions deal with ENGINE structures that + * have (or will) be initialised for use. Broadly speaking, the structural + * functions are useful for iterating the list of available engine types, + * creating new engine types, and other "list" operations. These functions + * actually deal with ENGINEs that are to be used. As such these functions + * can fail (if applicable) when particular engines are unavailable - eg. if + * a hardware accelerator is not attached or not functioning correctly. Each + * ENGINE has 2 reference counts; structural and functional. Every time a + * functional reference is obtained or released, a corresponding structural + * reference is automatically obtained or released too. + */ + +/* + * Initialise a engine type for use (or up its reference count if it's + * already in use). This will fail if the engine is not currently operational + * and cannot initialise. + */ +int ENGINE_init(ENGINE *e); +/* + * Free a functional reference to a engine type. This does not require a + * corresponding call to ENGINE_free as it also releases a structural + * reference. + */ +int ENGINE_finish(ENGINE *e); + +/* + * The following functions handle keys that are stored in some secondary + * location, handled by the engine. The storage may be on a card or + * whatever. + */ +EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, + UI_METHOD *ui_method, void *callback_data); +int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, + EVP_PKEY **ppkey, STACK_OF(X509) **pother, + UI_METHOD *ui_method, void *callback_data); + +/* + * This returns a pointer for the current ENGINE structure that is (by + * default) performing any RSA operations. The value returned is an + * incremented reference, so it should be free'd (ENGINE_finish) before it is + * discarded. + */ +ENGINE *ENGINE_get_default_RSA(void); +/* Same for the other "methods" */ +ENGINE *ENGINE_get_default_DSA(void); +ENGINE *ENGINE_get_default_EC(void); +ENGINE *ENGINE_get_default_DH(void); +ENGINE *ENGINE_get_default_RAND(void); +/* + * These functions can be used to get a functional reference to perform + * ciphering or digesting corresponding to "nid". + */ +ENGINE *ENGINE_get_cipher_engine(int nid); +ENGINE *ENGINE_get_digest_engine(int nid); +ENGINE *ENGINE_get_pkey_meth_engine(int nid); +ENGINE *ENGINE_get_pkey_asn1_meth_engine(int nid); + +/* + * This sets a new default ENGINE structure for performing RSA operations. If + * the result is non-zero (success) then the ENGINE structure will have had + * its reference count up'd so the caller should still free their own + * reference 'e'. + */ +int ENGINE_set_default_RSA(ENGINE *e); +int ENGINE_set_default_string(ENGINE *e, const char *def_list); +/* Same for the other "methods" */ +int ENGINE_set_default_DSA(ENGINE *e); +int ENGINE_set_default_EC(ENGINE *e); +int ENGINE_set_default_DH(ENGINE *e); +int ENGINE_set_default_RAND(ENGINE *e); +int ENGINE_set_default_ciphers(ENGINE *e); +int ENGINE_set_default_digests(ENGINE *e); +int ENGINE_set_default_pkey_meths(ENGINE *e); +int ENGINE_set_default_pkey_asn1_meths(ENGINE *e); + +/* + * The combination "set" - the flags are bitwise "OR"d from the + * ENGINE_METHOD_*** defines above. As with the "ENGINE_register_complete()" + * function, this function can result in unnecessary static linkage. If your + * application requires only specific functionality, consider using more + * selective functions. + */ +int ENGINE_set_default(ENGINE *e, unsigned int flags); + +void ENGINE_add_conf_module(void); + +/* Deprecated functions ... */ +/* int ENGINE_clear_defaults(void); */ + +/**************************/ +/* DYNAMIC ENGINE SUPPORT */ +/**************************/ + +/* Binary/behaviour compatibility levels */ +# define OSSL_DYNAMIC_VERSION (unsigned long)0x00030000 +/* + * Binary versions older than this are too old for us (whether we're a loader + * or a loadee) + */ +# define OSSL_DYNAMIC_OLDEST (unsigned long)0x00030000 + +/* + * When compiling an ENGINE entirely as an external shared library, loadable + * by the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' + * structure type provides the calling application's (or library's) error + * functionality and memory management function pointers to the loaded + * library. These should be used/set in the loaded library code so that the + * loading application's 'state' will be used/changed in all operations. The + * 'static_state' pointer allows the loaded library to know if it shares the + * same static data as the calling application (or library), and thus whether + * these callbacks need to be set or not. + */ +typedef void *(*dyn_MEM_malloc_fn) (size_t, const char *, int); +typedef void *(*dyn_MEM_realloc_fn) (void *, size_t, const char *, int); +typedef void (*dyn_MEM_free_fn) (void *, const char *, int); +typedef struct st_dynamic_MEM_fns { + dyn_MEM_malloc_fn malloc_fn; + dyn_MEM_realloc_fn realloc_fn; + dyn_MEM_free_fn free_fn; +} dynamic_MEM_fns; +/* + * FIXME: Perhaps the memory and locking code (crypto.h) should declare and + * use these types so we (and any other dependent code) can simplify a bit?? + */ +/* The top-level structure */ +typedef struct st_dynamic_fns { + void *static_state; + dynamic_MEM_fns mem_fns; +} dynamic_fns; + +/* + * The version checking function should be of this prototype. NB: The + * ossl_version value passed in is the OSSL_DYNAMIC_VERSION of the loading + * code. If this function returns zero, it indicates a (potential) version + * incompatibility and the loaded library doesn't believe it can proceed. + * Otherwise, the returned value is the (latest) version supported by the + * loading library. The loader may still decide that the loaded code's + * version is unsatisfactory and could veto the load. The function is + * expected to be implemented with the symbol name "v_check", and a default + * implementation can be fully instantiated with + * IMPLEMENT_DYNAMIC_CHECK_FN(). + */ +typedef unsigned long (*dynamic_v_check_fn) (unsigned long ossl_version); +# define IMPLEMENT_DYNAMIC_CHECK_FN() \ + OPENSSL_EXPORT unsigned long v_check(unsigned long v); \ + OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \ + if (v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ + return 0; } + +/* + * This function is passed the ENGINE structure to initialise with its own + * function and command settings. It should not adjust the structural or + * functional reference counts. If this function returns zero, (a) the load + * will be aborted, (b) the previous ENGINE state will be memcpy'd back onto + * the structure, and (c) the shared library will be unloaded. So + * implementations should do their own internal cleanup in failure + * circumstances otherwise they could leak. The 'id' parameter, if non-NULL, + * represents the ENGINE id that the loader is looking for. If this is NULL, + * the shared library can choose to return failure or to initialise a + * 'default' ENGINE. If non-NULL, the shared library must initialise only an + * ENGINE matching the passed 'id'. The function is expected to be + * implemented with the symbol name "bind_engine". A standard implementation + * can be instantiated with IMPLEMENT_DYNAMIC_BIND_FN(fn) where the parameter + * 'fn' is a callback function that populates the ENGINE structure and + * returns an int value (zero for failure). 'fn' should have prototype; + * [static] int fn(ENGINE *e, const char *id); + */ +typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id, + const dynamic_fns *fns); +# define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ + OPENSSL_EXPORT \ + int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); \ + OPENSSL_EXPORT \ + int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ + if (ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \ + CRYPTO_set_mem_functions(fns->mem_fns.malloc_fn, \ + fns->mem_fns.realloc_fn, \ + fns->mem_fns.free_fn); \ + skip_cbs: \ + if (!fn(e, id)) return 0; \ + return 1; } + +/* + * If the loading application (or library) and the loaded ENGINE library + * share the same static data (eg. they're both dynamically linked to the + * same libcrypto.so) we need a way to avoid trying to set system callbacks - + * this would fail, and for the same reason that it's unnecessary to try. If + * the loaded ENGINE has (or gets from through the loader) its own copy of + * the libcrypto static data, we will need to set the callbacks. The easiest + * way to detect this is to have a function that returns a pointer to some + * static data and let the loading application and loaded ENGINE compare + * their respective values. + */ +void *ENGINE_get_static_state(void); + +# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) +DEPRECATEDIN_1_1_0(void ENGINE_setup_bsd_cryptodev(void)) +# endif + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/e_os2.h postgresql-hll-2.14/include/openssl/e_os2.h --- postgresql-hll-2.14_old/include/openssl/e_os2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/e_os2.h 2020-12-12 17:06:43.332349135 +0800 @@ -0,0 +1,300 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_E_OS2_H +# define HEADER_E_OS2_H + +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Detect operating systems. This probably needs completing. + * The result is that at least one OPENSSL_SYS_os macro should be defined. + * However, if none is defined, Unix is assumed. + **/ + +# define OPENSSL_SYS_UNIX + +/* --------------------- Microsoft operating systems ---------------------- */ + +/* + * Note that MSDOS actually denotes 32-bit environments running on top of + * MS-DOS, such as DJGPP one. + */ +# if defined(OPENSSL_SYS_MSDOS) +# undef OPENSSL_SYS_UNIX +# endif + +/* + * For 32 bit environment, there seems to be the CygWin environment and then + * all the others that try to do the same thing Microsoft does... + */ +/* + * UEFI lives here because it might be built with a Microsoft toolchain and + * we need to avoid the false positive match on Windows. + */ +# if defined(OPENSSL_SYS_UEFI) +# undef OPENSSL_SYS_UNIX +# elif defined(OPENSSL_SYS_UWIN) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WIN32_UWIN +# else +# if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN) +# define OPENSSL_SYS_WIN32_CYGWIN +# else +# if defined(_WIN32) || defined(OPENSSL_SYS_WIN32) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN32) +# define OPENSSL_SYS_WIN32 +# endif +# endif +# if defined(_WIN64) || defined(OPENSSL_SYS_WIN64) +# undef OPENSSL_SYS_UNIX +# if !defined(OPENSSL_SYS_WIN64) +# define OPENSSL_SYS_WIN64 +# endif +# endif +# if defined(OPENSSL_SYS_WINNT) +# undef OPENSSL_SYS_UNIX +# endif +# if defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# endif +# endif +# endif + +/* Anything that tries to look like Microsoft is "Windows" */ +# if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE) +# undef OPENSSL_SYS_UNIX +# define OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_SYS_MSDOS +# define OPENSSL_SYS_MSDOS +# endif +# endif + +/* + * DLL settings. This part is a bit tough, because it's up to the + * application implementor how he or she will link the application, so it + * requires some macro to be used. + */ +# ifdef OPENSSL_SYS_WINDOWS +# ifndef OPENSSL_OPT_WINDLL +# if defined(_WINDLL) /* This is used when building OpenSSL to + * indicate that DLL linkage should be used */ +# define OPENSSL_OPT_WINDLL +# endif +# endif +# endif + +/* ------------------------------- OpenVMS -------------------------------- */ +# if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS) +# if !defined(OPENSSL_SYS_VMS) +# undef OPENSSL_SYS_UNIX +# endif +# define OPENSSL_SYS_VMS +# if defined(__DECC) +# define OPENSSL_SYS_VMS_DECC +# elif defined(__DECCXX) +# define OPENSSL_SYS_VMS_DECC +# define OPENSSL_SYS_VMS_DECCXX +# else +# define OPENSSL_SYS_VMS_NODECC +# endif +# endif + +/* -------------------------------- Unix ---------------------------------- */ +# ifdef OPENSSL_SYS_UNIX +# if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX) +# define OPENSSL_SYS_LINUX +# endif +# if defined(_AIX) && !defined(OPENSSL_SYS_AIX) +# define OPENSSL_SYS_AIX +# endif +# endif + +/* -------------------------------- VOS ----------------------------------- */ +# if defined(__VOS__) && !defined(OPENSSL_SYS_VOS) +# define OPENSSL_SYS_VOS +# ifdef __HPPA__ +# define OPENSSL_SYS_VOS_HPPA +# endif +# ifdef __IA32__ +# define OPENSSL_SYS_VOS_IA32 +# endif +# endif + +/** + * That's it for OS-specific stuff + *****************************************************************************/ + +/* Specials for I/O an exit */ +# ifdef OPENSSL_SYS_MSDOS +# define OPENSSL_UNISTD_IO +# define OPENSSL_DECLARE_EXIT extern void exit(int); +# else +# define OPENSSL_UNISTD_IO OPENSSL_UNISTD +# define OPENSSL_DECLARE_EXIT /* declared in unistd.h */ +# endif + +/*- + * OPENSSL_EXTERN is normally used to declare a symbol with possible extra + * attributes to handle its presence in a shared library. + * OPENSSL_EXPORT is used to define a symbol with extra possible attributes + * to make it visible in a shared library. + * Care needs to be taken when a header file is used both to declare and + * define symbols. Basically, for any library that exports some global + * variables, the following code must be present in the header file that + * declares them, before OPENSSL_EXTERN is used: + * + * #ifdef SOME_BUILD_FLAG_MACRO + * # undef OPENSSL_EXTERN + * # define OPENSSL_EXTERN OPENSSL_EXPORT + * #endif + * + * The default is to have OPENSSL_EXPORT and OPENSSL_EXTERN + * have some generally sensible values. + */ + +# if defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL) +# define OPENSSL_EXPORT extern __declspec(dllexport) +# define OPENSSL_EXTERN extern __declspec(dllimport) +# else +# define OPENSSL_EXPORT extern +# define OPENSSL_EXTERN extern +# endif + +/*- + * Macros to allow global variables to be reached through function calls when + * required (if a shared library version requires it, for example. + * The way it's done allows definitions like this: + * + * // in foobar.c + * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0) + * // in foobar.h + * OPENSSL_DECLARE_GLOBAL(int,foobar); + * #define foobar OPENSSL_GLOBAL_REF(foobar) + */ +# ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \ + type *_shadow_##name(void) \ + { static type _hide_##name=value; return &_hide_##name; } +# define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void) +# define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name())) +# else +# define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) type _shadow_##name=value; +# define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name +# define OPENSSL_GLOBAL_REF(name) _shadow_##name +# endif + +# ifdef _WIN32 +# ifdef _WIN64 +# define ossl_ssize_t __int64 +# define OSSL_SSIZE_MAX _I64_MAX +# else +# define ossl_ssize_t int +# define OSSL_SSIZE_MAX INT_MAX +# endif +# endif + +# if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t) +# define ossl_ssize_t INTN +# define OSSL_SSIZE_MAX MAX_INTN +# endif + +# ifndef ossl_ssize_t +# define ossl_ssize_t ssize_t +# if defined(SSIZE_MAX) +# define OSSL_SSIZE_MAX SSIZE_MAX +# elif defined(_POSIX_SSIZE_MAX) +# define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX +# else +# define OSSL_SSIZE_MAX ((ssize_t)(SIZE_MAX>>1)) +# endif +# endif + +# ifdef DEBUG_UNUSED +# define __owur __attribute__((__warn_unused_result__)) +# else +# define __owur +# endif + +/* Standard integer types */ +# if defined(OPENSSL_SYS_UEFI) +typedef INT8 int8_t; +typedef UINT8 uint8_t; +typedef INT16 int16_t; +typedef UINT16 uint16_t; +typedef INT32 int32_t; +typedef UINT32 uint32_t; +typedef INT64 int64_t; +typedef UINT64 uint64_t; +# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + defined(__osf__) || defined(__sgi) || defined(__hpux) || \ + defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__) +# include +# elif defined(_MSC_VER) && _MSC_VER<=1500 +/* + * minimally required typdefs for systems not supporting inttypes.h or + * stdint.h: currently just older VC++ + */ +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +# else +# include +# endif + +/* ossl_inline: portable inline definition usable in public headers */ +# if !defined(inline) && !defined(__cplusplus) +# if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L + /* just use inline */ +# define ossl_inline inline +# elif defined(__GNUC__) && __GNUC__>=2 +# define ossl_inline __inline__ +# elif defined(_MSC_VER) + /* + * Visual Studio: inline is available in C++ only, however + * __inline is available for C, see + * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx + */ +# define ossl_inline __inline +# else +# define ossl_inline +# endif +# else +# define ossl_inline inline +# endif + +# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define ossl_noreturn _Noreturn +# elif defined(__GNUC__) && __GNUC__ >= 2 +# define ossl_noreturn __attribute__((noreturn)) +# else +# define ossl_noreturn +# endif + +/* ossl_unused: portable unused attribute for use in public headers */ +# if defined(__GNUC__) +# define ossl_unused __attribute__((unused)) +# else +# define ossl_unused +# endif + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/err.h postgresql-hll-2.14/include/openssl/err.h --- postgresql-hll-2.14_old/include/openssl/err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/err.h 2020-12-12 17:06:43.332349135 +0800 @@ -0,0 +1,274 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ERR_H +# define HEADER_ERR_H + +# include + +# ifndef OPENSSL_NO_STDIO +# include +# include +# endif + +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# ifndef OPENSSL_NO_ERR +# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) +# else +# define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) +# endif + +# include + +# define ERR_TXT_MALLOCED 0x01 +# define ERR_TXT_STRING 0x02 + +# define ERR_FLAG_MARK 0x01 +# define ERR_FLAG_CLEAR 0x02 + +# define ERR_NUM_ERRORS 16 +typedef struct err_state_st { + int err_flags[ERR_NUM_ERRORS]; + unsigned long err_buffer[ERR_NUM_ERRORS]; + char *err_data[ERR_NUM_ERRORS]; + int err_data_flags[ERR_NUM_ERRORS]; + const char *err_file[ERR_NUM_ERRORS]; + int err_line[ERR_NUM_ERRORS]; + int top, bottom; +} ERR_STATE; + +/* library */ +# define ERR_LIB_NONE 1 +# define ERR_LIB_SYS 2 +# define ERR_LIB_BN 3 +# define ERR_LIB_RSA 4 +# define ERR_LIB_DH 5 +# define ERR_LIB_EVP 6 +# define ERR_LIB_BUF 7 +# define ERR_LIB_OBJ 8 +# define ERR_LIB_PEM 9 +# define ERR_LIB_DSA 10 +# define ERR_LIB_X509 11 +/* #define ERR_LIB_METH 12 */ +# define ERR_LIB_ASN1 13 +# define ERR_LIB_CONF 14 +# define ERR_LIB_CRYPTO 15 +# define ERR_LIB_EC 16 +# define ERR_LIB_SSL 20 +/* #define ERR_LIB_SSL23 21 */ +/* #define ERR_LIB_SSL2 22 */ +/* #define ERR_LIB_SSL3 23 */ +/* #define ERR_LIB_RSAREF 30 */ +/* #define ERR_LIB_PROXY 31 */ +# define ERR_LIB_BIO 32 +# define ERR_LIB_PKCS7 33 +# define ERR_LIB_X509V3 34 +# define ERR_LIB_PKCS12 35 +# define ERR_LIB_RAND 36 +# define ERR_LIB_DSO 37 +# define ERR_LIB_ENGINE 38 +# define ERR_LIB_OCSP 39 +# define ERR_LIB_UI 40 +# define ERR_LIB_COMP 41 +# define ERR_LIB_ECDSA 42 +# define ERR_LIB_ECDH 43 +# define ERR_LIB_OSSL_STORE 44 +# define ERR_LIB_FIPS 45 +# define ERR_LIB_CMS 46 +# define ERR_LIB_TS 47 +# define ERR_LIB_HMAC 48 +/* # define ERR_LIB_JPAKE 49 */ +# define ERR_LIB_CT 50 +# define ERR_LIB_ASYNC 51 +# define ERR_LIB_KDF 52 +# define ERR_LIB_SM2 53 + +# define ERR_LIB_USER 128 + +# define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECerr(f,r) ERR_PUT_error(ERR_LIB_EC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define OSSL_STOREerr(f,r) ERR_PUT_error(ERR_LIB_OSSL_STORE,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define KDFerr(f,r) ERR_PUT_error(ERR_LIB_KDF,(f),(r),OPENSSL_FILE,OPENSSL_LINE) +# define SM2err(f,r) ERR_PUT_error(ERR_LIB_SM2,(f),(r),OPENSSL_FILE,OPENSSL_LINE) + +# define ERR_PACK(l,f,r) ( \ + (((unsigned int)(l) & 0x0FF) << 24L) | \ + (((unsigned int)(f) & 0xFFF) << 12L) | \ + (((unsigned int)(r) & 0xFFF) ) ) +# define ERR_GET_LIB(l) (int)(((l) >> 24L) & 0x0FFL) +# define ERR_GET_FUNC(l) (int)(((l) >> 12L) & 0xFFFL) +# define ERR_GET_REASON(l) (int)( (l) & 0xFFFL) +# define ERR_FATAL_ERROR(l) (int)( (l) & ERR_R_FATAL) + +/* OS functions */ +# define SYS_F_FOPEN 1 +# define SYS_F_CONNECT 2 +# define SYS_F_GETSERVBYNAME 3 +# define SYS_F_SOCKET 4 +# define SYS_F_IOCTLSOCKET 5 +# define SYS_F_BIND 6 +# define SYS_F_LISTEN 7 +# define SYS_F_ACCEPT 8 +# define SYS_F_WSASTARTUP 9/* Winsock stuff */ +# define SYS_F_OPENDIR 10 +# define SYS_F_FREAD 11 +# define SYS_F_GETADDRINFO 12 +# define SYS_F_GETNAMEINFO 13 +# define SYS_F_SETSOCKOPT 14 +# define SYS_F_GETSOCKOPT 15 +# define SYS_F_GETSOCKNAME 16 +# define SYS_F_GETHOSTBYNAME 17 +# define SYS_F_FFLUSH 18 +# define SYS_F_OPEN 19 +# define SYS_F_CLOSE 20 +# define SYS_F_IOCTL 21 +# define SYS_F_STAT 22 +# define SYS_F_FCNTL 23 +# define SYS_F_FSTAT 24 + +/* reasons */ +# define ERR_R_SYS_LIB ERR_LIB_SYS/* 2 */ +# define ERR_R_BN_LIB ERR_LIB_BN/* 3 */ +# define ERR_R_RSA_LIB ERR_LIB_RSA/* 4 */ +# define ERR_R_DH_LIB ERR_LIB_DH/* 5 */ +# define ERR_R_EVP_LIB ERR_LIB_EVP/* 6 */ +# define ERR_R_BUF_LIB ERR_LIB_BUF/* 7 */ +# define ERR_R_OBJ_LIB ERR_LIB_OBJ/* 8 */ +# define ERR_R_PEM_LIB ERR_LIB_PEM/* 9 */ +# define ERR_R_DSA_LIB ERR_LIB_DSA/* 10 */ +# define ERR_R_X509_LIB ERR_LIB_X509/* 11 */ +# define ERR_R_ASN1_LIB ERR_LIB_ASN1/* 13 */ +# define ERR_R_EC_LIB ERR_LIB_EC/* 16 */ +# define ERR_R_BIO_LIB ERR_LIB_BIO/* 32 */ +# define ERR_R_PKCS7_LIB ERR_LIB_PKCS7/* 33 */ +# define ERR_R_X509V3_LIB ERR_LIB_X509V3/* 34 */ +# define ERR_R_ENGINE_LIB ERR_LIB_ENGINE/* 38 */ +# define ERR_R_UI_LIB ERR_LIB_UI/* 40 */ +# define ERR_R_ECDSA_LIB ERR_LIB_ECDSA/* 42 */ +# define ERR_R_OSSL_STORE_LIB ERR_LIB_OSSL_STORE/* 44 */ + +# define ERR_R_NESTED_ASN1_ERROR 58 +# define ERR_R_MISSING_ASN1_EOS 63 + +/* fatal error */ +# define ERR_R_FATAL 64 +# define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) +# define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) +# define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) +# define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL) +# define ERR_R_DISABLED (5|ERR_R_FATAL) +# define ERR_R_INIT_FAIL (6|ERR_R_FATAL) +# define ERR_R_PASSED_INVALID_ARGUMENT (7) +# define ERR_R_OPERATION_FAIL (8|ERR_R_FATAL) + +/* + * 99 is the maximum possible ERR_R_... code, higher values are reserved for + * the individual libraries + */ + +typedef struct ERR_string_data_st { + unsigned long error; + const char *string; +} ERR_STRING_DATA; + +DEFINE_LHASH_OF(ERR_STRING_DATA); + +void ERR_put_error(int lib, int func, int reason, const char *file, int line); +void ERR_set_error_data(char *data, int flags); + +unsigned long ERR_get_error(void); +unsigned long ERR_get_error_line(const char **file, int *line); +unsigned long ERR_get_error_line_data(const char **file, int *line, + const char **data, int *flags); +unsigned long ERR_peek_error(void); +unsigned long ERR_peek_error_line(const char **file, int *line); +unsigned long ERR_peek_error_line_data(const char **file, int *line, + const char **data, int *flags); +unsigned long ERR_peek_last_error(void); +unsigned long ERR_peek_last_error_line(const char **file, int *line); +unsigned long ERR_peek_last_error_line_data(const char **file, int *line, + const char **data, int *flags); +void ERR_clear_error(void); +char *ERR_error_string(unsigned long e, char *buf); +void ERR_error_string_n(unsigned long e, char *buf, size_t len); +const char *ERR_lib_error_string(unsigned long e); +const char *ERR_func_error_string(unsigned long e); +const char *ERR_reason_error_string(unsigned long e); +void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), + void *u); +# ifndef OPENSSL_NO_STDIO +void ERR_print_errors_fp(FILE *fp); +# endif +void ERR_print_errors(BIO *bp); +void ERR_add_error_data(int num, ...); +void ERR_add_error_vdata(int num, va_list args); +int ERR_load_strings(int lib, ERR_STRING_DATA *str); +int ERR_load_strings_const(const ERR_STRING_DATA *str); +int ERR_unload_strings(int lib, ERR_STRING_DATA *str); +int ERR_load_ERR_strings(void); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define ERR_load_crypto_strings() \ + OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) +# define ERR_free_strings() while(0) continue +#endif + +DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *)) +DEPRECATEDIN_1_0_0(void ERR_remove_state(unsigned long pid)) +ERR_STATE *ERR_get_state(void); + +int ERR_get_next_error_library(void); + +int ERR_set_mark(void); +int ERR_pop_to_mark(void); +int ERR_clear_last_mark(void); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/evperr.h postgresql-hll-2.14/include/openssl/evperr.h --- postgresql-hll-2.14_old/include/openssl/evperr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/evperr.h 2020-12-12 17:06:43.332349135 +0800 @@ -0,0 +1,205 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_EVPERR_H +# define HEADER_EVPERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_EVP_strings(void); + +/* + * EVP function codes. + */ +# define EVP_F_AESNI_INIT_KEY 165 +# define EVP_F_AESNI_XTS_INIT_KEY 207 +# define EVP_F_AES_GCM_CTRL 196 +# define EVP_F_AES_INIT_KEY 133 +# define EVP_F_AES_OCB_CIPHER 169 +# define EVP_F_AES_T4_INIT_KEY 178 +# define EVP_F_AES_T4_XTS_INIT_KEY 208 +# define EVP_F_AES_WRAP_CIPHER 170 +# define EVP_F_AES_XTS_INIT_KEY 209 +# define EVP_F_ALG_MODULE_INIT 177 +# define EVP_F_ARIA_CCM_INIT_KEY 175 +# define EVP_F_ARIA_GCM_CTRL 197 +# define EVP_F_ARIA_GCM_INIT_KEY 176 +# define EVP_F_ARIA_INIT_KEY 185 +# define EVP_F_B64_NEW 198 +# define EVP_F_CAMELLIA_INIT_KEY 159 +# define EVP_F_CHACHA20_POLY1305_CTRL 182 +# define EVP_F_CMLL_T4_INIT_KEY 179 +# define EVP_F_DES_EDE3_WRAP_CIPHER 171 +# define EVP_F_DO_SIGVER_INIT 161 +# define EVP_F_ENC_NEW 199 +# define EVP_F_EVP_CIPHERINIT_EX 123 +# define EVP_F_EVP_CIPHER_ASN1_TO_PARAM 204 +# define EVP_F_EVP_CIPHER_CTX_COPY 163 +# define EVP_F_EVP_CIPHER_CTX_CTRL 124 +# define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 +# define EVP_F_EVP_CIPHER_PARAM_TO_ASN1 205 +# define EVP_F_EVP_DECRYPTFINAL_EX 101 +# define EVP_F_EVP_DECRYPTUPDATE 166 +# define EVP_F_EVP_DIGESTFINALXOF 174 +# define EVP_F_EVP_DIGESTINIT_EX 128 +# define EVP_F_EVP_ENCRYPTDECRYPTUPDATE 219 +# define EVP_F_EVP_ENCRYPTFINAL_EX 127 +# define EVP_F_EVP_ENCRYPTUPDATE 167 +# define EVP_F_EVP_MD_CTX_COPY_EX 110 +# define EVP_F_EVP_MD_SIZE 162 +# define EVP_F_EVP_OPENINIT 102 +# define EVP_F_EVP_PBE_ALG_ADD 115 +# define EVP_F_EVP_PBE_ALG_ADD_TYPE 160 +# define EVP_F_EVP_PBE_CIPHERINIT 116 +# define EVP_F_EVP_PBE_SCRYPT 181 +# define EVP_F_EVP_PKCS82PKEY 111 +# define EVP_F_EVP_PKEY2PKCS8 113 +# define EVP_F_EVP_PKEY_ASN1_ADD0 188 +# define EVP_F_EVP_PKEY_CHECK 186 +# define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 +# define EVP_F_EVP_PKEY_CTX_CTRL 137 +# define EVP_F_EVP_PKEY_CTX_CTRL_STR 150 +# define EVP_F_EVP_PKEY_CTX_DUP 156 +# define EVP_F_EVP_PKEY_CTX_MD 168 +# define EVP_F_EVP_PKEY_DECRYPT 104 +# define EVP_F_EVP_PKEY_DECRYPT_INIT 138 +# define EVP_F_EVP_PKEY_DECRYPT_OLD 151 +# define EVP_F_EVP_PKEY_DERIVE 153 +# define EVP_F_EVP_PKEY_DERIVE_INIT 154 +# define EVP_F_EVP_PKEY_DERIVE_SET_PEER 155 +# define EVP_F_EVP_PKEY_ENCRYPT 105 +# define EVP_F_EVP_PKEY_ENCRYPT_INIT 139 +# define EVP_F_EVP_PKEY_ENCRYPT_OLD 152 +# define EVP_F_EVP_PKEY_GET0_DH 119 +# define EVP_F_EVP_PKEY_GET0_DSA 120 +# define EVP_F_EVP_PKEY_GET0_EC_KEY 131 +# define EVP_F_EVP_PKEY_GET0_HMAC 183 +# define EVP_F_EVP_PKEY_GET0_POLY1305 184 +# define EVP_F_EVP_PKEY_GET0_RSA 121 +# define EVP_F_EVP_PKEY_GET0_SIPHASH 172 +# define EVP_F_EVP_PKEY_GET_RAW_PRIVATE_KEY 202 +# define EVP_F_EVP_PKEY_GET_RAW_PUBLIC_KEY 203 +# define EVP_F_EVP_PKEY_KEYGEN 146 +# define EVP_F_EVP_PKEY_KEYGEN_INIT 147 +# define EVP_F_EVP_PKEY_METH_ADD0 194 +# define EVP_F_EVP_PKEY_METH_NEW 195 +# define EVP_F_EVP_PKEY_NEW 106 +# define EVP_F_EVP_PKEY_NEW_CMAC_KEY 193 +# define EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY 191 +# define EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY 192 +# define EVP_F_EVP_PKEY_PARAMGEN 148 +# define EVP_F_EVP_PKEY_PARAMGEN_INIT 149 +# define EVP_F_EVP_PKEY_PARAM_CHECK 189 +# define EVP_F_EVP_PKEY_PUBLIC_CHECK 190 +# define EVP_F_EVP_PKEY_SET1_ENGINE 187 +# define EVP_F_EVP_PKEY_SET_ALIAS_TYPE 206 +# define EVP_F_EVP_PKEY_SIGN 140 +# define EVP_F_EVP_PKEY_SIGN_INIT 141 +# define EVP_F_EVP_PKEY_VERIFY 142 +# define EVP_F_EVP_PKEY_VERIFY_INIT 143 +# define EVP_F_EVP_PKEY_VERIFY_RECOVER 144 +# define EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT 145 +# define EVP_F_EVP_SIGNFINAL 107 +# define EVP_F_EVP_VERIFYFINAL 108 +# define EVP_F_INT_CTX_NEW 157 +# define EVP_F_OK_NEW 200 +# define EVP_F_PKCS5_PBE_KEYIVGEN 117 +# define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 +# define EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN 164 +# define EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN 180 +# define EVP_F_PKEY_SET_TYPE 158 +# define EVP_F_RC2_MAGIC_TO_METH 109 +# define EVP_F_RC5_CTRL 125 +# define EVP_F_R_32_12_16_INIT_KEY 242 +# define EVP_F_S390X_AES_GCM_CTRL 201 +# define EVP_F_UPDATE 173 + +/* + * EVP reason codes. + */ +# define EVP_R_AES_KEY_SETUP_FAILED 143 +# define EVP_R_ARIA_KEY_SETUP_FAILED 176 +# define EVP_R_BAD_DECRYPT 100 +# define EVP_R_BAD_KEY_LENGTH 195 +# define EVP_R_BUFFER_TOO_SMALL 155 +# define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157 +# define EVP_R_CIPHER_PARAMETER_ERROR 122 +# define EVP_R_COMMAND_NOT_SUPPORTED 147 +# define EVP_R_COPY_ERROR 173 +# define EVP_R_CTRL_NOT_IMPLEMENTED 132 +# define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 +# define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138 +# define EVP_R_DECODE_ERROR 114 +# define EVP_R_DIFFERENT_KEY_TYPES 101 +# define EVP_R_DIFFERENT_PARAMETERS 153 +# define EVP_R_ERROR_LOADING_SECTION 165 +# define EVP_R_ERROR_SETTING_FIPS_MODE 166 +# define EVP_R_EXPECTING_AN_HMAC_KEY 174 +# define EVP_R_EXPECTING_AN_RSA_KEY 127 +# define EVP_R_EXPECTING_A_DH_KEY 128 +# define EVP_R_EXPECTING_A_DSA_KEY 129 +# define EVP_R_EXPECTING_A_EC_KEY 142 +# define EVP_R_EXPECTING_A_POLY1305_KEY 164 +# define EVP_R_EXPECTING_A_SIPHASH_KEY 175 +# define EVP_R_FIPS_MODE_NOT_SUPPORTED 167 +# define EVP_R_GET_RAW_KEY_FAILED 182 +# define EVP_R_ILLEGAL_SCRYPT_PARAMETERS 171 +# define EVP_R_INITIALIZATION_ERROR 134 +# define EVP_R_INPUT_NOT_INITIALIZED 111 +# define EVP_R_INVALID_DIGEST 152 +# define EVP_R_INVALID_FIPS_MODE 168 +# define EVP_R_INVALID_IV_LENGTH 194 +# define EVP_R_INVALID_KEY 163 +# define EVP_R_INVALID_KEY_LENGTH 130 +# define EVP_R_INVALID_OPERATION 148 +# define EVP_R_KEYGEN_FAILURE 120 +# define EVP_R_KEY_SETUP_FAILED 180 +# define EVP_R_MEMORY_LIMIT_EXCEEDED 172 +# define EVP_R_MESSAGE_DIGEST_IS_NULL 159 +# define EVP_R_METHOD_NOT_SUPPORTED 144 +# define EVP_R_MISSING_PARAMETERS 103 +# define EVP_R_NOT_XOF_OR_INVALID_LENGTH 178 +# define EVP_R_NO_CIPHER_SET 131 +# define EVP_R_NO_DEFAULT_DIGEST 158 +# define EVP_R_NO_DIGEST_SET 139 +# define EVP_R_NO_KEY_SET 154 +# define EVP_R_NO_OPERATION_SET 149 +# define EVP_R_ONLY_ONESHOT_SUPPORTED 177 +# define EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 150 +# define EVP_R_OPERATON_NOT_INITIALIZED 151 +# define EVP_R_PARTIALLY_OVERLAPPING 162 +# define EVP_R_PBKDF2_ERROR 181 +# define EVP_R_PKEY_APPLICATION_ASN1_METHOD_ALREADY_REGISTERED 179 +# define EVP_R_PRIVATE_KEY_DECODE_ERROR 145 +# define EVP_R_PRIVATE_KEY_ENCODE_ERROR 146 +# define EVP_R_PUBLIC_KEY_NOT_RSA 106 +# define EVP_R_UNKNOWN_CIPHER 160 +# define EVP_R_UNKNOWN_DIGEST 161 +# define EVP_R_UNKNOWN_OPTION 169 +# define EVP_R_UNKNOWN_PBE_ALGORITHM 121 +# define EVP_R_UNSUPPORTED_ALGORITHM 156 +# define EVP_R_UNSUPPORTED_CIPHER 107 +# define EVP_R_UNSUPPORTED_KEYLENGTH 123 +# define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 +# define EVP_R_UNSUPPORTED_KEY_SIZE 108 +# define EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS 135 +# define EVP_R_UNSUPPORTED_PRF 125 +# define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 +# define EVP_R_UNSUPPORTED_SALT_TYPE 126 +# define EVP_R_WRAP_MODE_NOT_ALLOWED 170 +# define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 +# define EVP_R_XTS_DUPLICATED_KEYS 183 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/evp.h postgresql-hll-2.14/include/openssl/evp.h --- postgresql-hll-2.14_old/include/openssl/evp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/evp.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,1666 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_ENVELOPE_H +# define HEADER_ENVELOPE_H + +# include +# include +# include +# include +# include + +# define EVP_MAX_MD_SIZE 64/* longest known is SHA512 */ +# define EVP_MAX_KEY_LENGTH 64 +# define EVP_MAX_IV_LENGTH 16 +# define EVP_MAX_BLOCK_LENGTH 32 + +# define PKCS5_SALT_LEN 8 +/* Default PKCS#5 iteration count */ +# define PKCS5_DEFAULT_ITER 2048 + +# include + +# define EVP_PK_RSA 0x0001 +# define EVP_PK_DSA 0x0002 +# define EVP_PK_DH 0x0004 +# define EVP_PK_EC 0x0008 +# define EVP_PKT_SIGN 0x0010 +# define EVP_PKT_ENC 0x0020 +# define EVP_PKT_EXCH 0x0040 +# define EVP_PKS_RSA 0x0100 +# define EVP_PKS_DSA 0x0200 +# define EVP_PKS_EC 0x0400 + +# define EVP_PKEY_NONE NID_undef +# define EVP_PKEY_RSA NID_rsaEncryption +# define EVP_PKEY_RSA2 NID_rsa +# define EVP_PKEY_RSA_PSS NID_rsassaPss +# define EVP_PKEY_DSA NID_dsa +# define EVP_PKEY_DSA1 NID_dsa_2 +# define EVP_PKEY_DSA2 NID_dsaWithSHA +# define EVP_PKEY_DSA3 NID_dsaWithSHA1 +# define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 +# define EVP_PKEY_DH NID_dhKeyAgreement +# define EVP_PKEY_DHX NID_dhpublicnumber +# define EVP_PKEY_EC NID_X9_62_id_ecPublicKey +# define EVP_PKEY_SM2 NID_sm2 +# define EVP_PKEY_HMAC NID_hmac +# define EVP_PKEY_CMAC NID_cmac +# define EVP_PKEY_SCRYPT NID_id_scrypt +# define EVP_PKEY_TLS1_PRF NID_tls1_prf +# define EVP_PKEY_HKDF NID_hkdf +# define EVP_PKEY_POLY1305 NID_poly1305 +# define EVP_PKEY_SIPHASH NID_siphash +# define EVP_PKEY_X25519 NID_X25519 +# define EVP_PKEY_ED25519 NID_ED25519 +# define EVP_PKEY_X448 NID_X448 +# define EVP_PKEY_ED448 NID_ED448 + +#ifdef __cplusplus +extern "C" { +#endif + +# define EVP_PKEY_MO_SIGN 0x0001 +# define EVP_PKEY_MO_VERIFY 0x0002 +# define EVP_PKEY_MO_ENCRYPT 0x0004 +# define EVP_PKEY_MO_DECRYPT 0x0008 + +# ifndef EVP_MD +EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type); +EVP_MD *EVP_MD_meth_dup(const EVP_MD *md); +void EVP_MD_meth_free(EVP_MD *md); + +int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize); +int EVP_MD_meth_set_result_size(EVP_MD *md, int resultsize); +int EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize); +int EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags); +int EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)); +int EVP_MD_meth_set_update(EVP_MD *md, int (*update)(EVP_MD_CTX *ctx, + const void *data, + size_t count)); +int EVP_MD_meth_set_final(EVP_MD *md, int (*final)(EVP_MD_CTX *ctx, + unsigned char *md)); +int EVP_MD_meth_set_copy(EVP_MD *md, int (*copy)(EVP_MD_CTX *to, + const EVP_MD_CTX *from)); +int EVP_MD_meth_set_cleanup(EVP_MD *md, int (*cleanup)(EVP_MD_CTX *ctx)); +int EVP_MD_meth_set_ctrl(EVP_MD *md, int (*ctrl)(EVP_MD_CTX *ctx, int cmd, + int p1, void *p2)); + +int EVP_MD_meth_get_input_blocksize(const EVP_MD *md); +int EVP_MD_meth_get_result_size(const EVP_MD *md); +int EVP_MD_meth_get_app_datasize(const EVP_MD *md); +unsigned long EVP_MD_meth_get_flags(const EVP_MD *md); +int (*EVP_MD_meth_get_init(const EVP_MD *md))(EVP_MD_CTX *ctx); +int (*EVP_MD_meth_get_update(const EVP_MD *md))(EVP_MD_CTX *ctx, + const void *data, + size_t count); +int (*EVP_MD_meth_get_final(const EVP_MD *md))(EVP_MD_CTX *ctx, + unsigned char *md); +int (*EVP_MD_meth_get_copy(const EVP_MD *md))(EVP_MD_CTX *to, + const EVP_MD_CTX *from); +int (*EVP_MD_meth_get_cleanup(const EVP_MD *md))(EVP_MD_CTX *ctx); +int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd, + int p1, void *p2); + +/* digest can only handle a single block */ +# define EVP_MD_FLAG_ONESHOT 0x0001 + +/* digest is extensible-output function, XOF */ +# define EVP_MD_FLAG_XOF 0x0002 + +/* DigestAlgorithmIdentifier flags... */ + +# define EVP_MD_FLAG_DIGALGID_MASK 0x0018 + +/* NULL or absent parameter accepted. Use NULL */ + +# define EVP_MD_FLAG_DIGALGID_NULL 0x0000 + +/* NULL or absent parameter accepted. Use NULL for PKCS#1 otherwise absent */ + +# define EVP_MD_FLAG_DIGALGID_ABSENT 0x0008 + +/* Custom handling via ctrl */ + +# define EVP_MD_FLAG_DIGALGID_CUSTOM 0x0018 + +/* Note if suitable for use in FIPS mode */ +# define EVP_MD_FLAG_FIPS 0x0400 + +/* Digest ctrls */ + +# define EVP_MD_CTRL_DIGALGID 0x1 +# define EVP_MD_CTRL_MICALG 0x2 +# define EVP_MD_CTRL_XOF_LEN 0x3 + +/* Minimum Algorithm specific ctrl value */ + +# define EVP_MD_CTRL_ALG_CTRL 0x1000 + +# endif /* !EVP_MD */ + +/* values for EVP_MD_CTX flags */ + +# define EVP_MD_CTX_FLAG_ONESHOT 0x0001/* digest update will be + * called once only */ +# define EVP_MD_CTX_FLAG_CLEANED 0x0002/* context has already been + * cleaned */ +# define EVP_MD_CTX_FLAG_REUSE 0x0004/* Don't free up ctx->md_data + * in EVP_MD_CTX_reset */ +/* + * FIPS and pad options are ignored in 1.0.0, definitions are here so we + * don't accidentally reuse the values for other purposes. + */ + +# define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008/* Allow use of non FIPS + * digest in FIPS mode */ + +/* + * The following PAD options are also currently ignored in 1.0.0, digest + * parameters are handled through EVP_DigestSign*() and EVP_DigestVerify*() + * instead. + */ +# define EVP_MD_CTX_FLAG_PAD_MASK 0xF0/* RSA mode to use */ +# define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00/* PKCS#1 v1.5 mode */ +# define EVP_MD_CTX_FLAG_PAD_X931 0x10/* X9.31 mode */ +# define EVP_MD_CTX_FLAG_PAD_PSS 0x20/* PSS mode */ + +# define EVP_MD_CTX_FLAG_NO_INIT 0x0100/* Don't initialize md_data */ +/* + * Some functions such as EVP_DigestSign only finalise copies of internal + * contexts so additional data can be included after the finalisation call. + * This is inefficient if this functionality is not required: it is disabled + * if the following flag is set. + */ +# define EVP_MD_CTX_FLAG_FINALISE 0x0200 +/* NOTE: 0x0400 is reserved for internal usage */ + +EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len); +EVP_CIPHER *EVP_CIPHER_meth_dup(const EVP_CIPHER *cipher); +void EVP_CIPHER_meth_free(EVP_CIPHER *cipher); + +int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len); +int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags); +int EVP_CIPHER_meth_set_impl_ctx_size(EVP_CIPHER *cipher, int ctx_size); +int EVP_CIPHER_meth_set_init(EVP_CIPHER *cipher, + int (*init) (EVP_CIPHER_CTX *ctx, + const unsigned char *key, + const unsigned char *iv, + int enc)); +int EVP_CIPHER_meth_set_do_cipher(EVP_CIPHER *cipher, + int (*do_cipher) (EVP_CIPHER_CTX *ctx, + unsigned char *out, + const unsigned char *in, + size_t inl)); +int EVP_CIPHER_meth_set_cleanup(EVP_CIPHER *cipher, + int (*cleanup) (EVP_CIPHER_CTX *)); +int EVP_CIPHER_meth_set_set_asn1_params(EVP_CIPHER *cipher, + int (*set_asn1_parameters) (EVP_CIPHER_CTX *, + ASN1_TYPE *)); +int EVP_CIPHER_meth_set_get_asn1_params(EVP_CIPHER *cipher, + int (*get_asn1_parameters) (EVP_CIPHER_CTX *, + ASN1_TYPE *)); +int EVP_CIPHER_meth_set_ctrl(EVP_CIPHER *cipher, + int (*ctrl) (EVP_CIPHER_CTX *, int type, + int arg, void *ptr)); + +int (*EVP_CIPHER_meth_get_init(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, + const unsigned char *key, + const unsigned char *iv, + int enc); +int (*EVP_CIPHER_meth_get_do_cipher(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *ctx, + unsigned char *out, + const unsigned char *in, + size_t inl); +int (*EVP_CIPHER_meth_get_cleanup(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *); +int (*EVP_CIPHER_meth_get_set_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + ASN1_TYPE *); +int (*EVP_CIPHER_meth_get_get_asn1_params(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + ASN1_TYPE *); +int (*EVP_CIPHER_meth_get_ctrl(const EVP_CIPHER *cipher))(EVP_CIPHER_CTX *, + int type, int arg, + void *ptr); + +/* Values for cipher flags */ + +/* Modes for ciphers */ + +# define EVP_CIPH_STREAM_CIPHER 0x0 +# define EVP_CIPH_ECB_MODE 0x1 +# define EVP_CIPH_CBC_MODE 0x2 +# define EVP_CIPH_CFB_MODE 0x3 +# define EVP_CIPH_OFB_MODE 0x4 +# define EVP_CIPH_CTR_MODE 0x5 +# define EVP_CIPH_GCM_MODE 0x6 +# define EVP_CIPH_CCM_MODE 0x7 +# define EVP_CIPH_XTS_MODE 0x10001 +# define EVP_CIPH_WRAP_MODE 0x10002 +# define EVP_CIPH_OCB_MODE 0x10003 +# define EVP_CIPH_MODE 0xF0007 +/* Set if variable length cipher */ +# define EVP_CIPH_VARIABLE_LENGTH 0x8 +/* Set if the iv handling should be done by the cipher itself */ +# define EVP_CIPH_CUSTOM_IV 0x10 +/* Set if the cipher's init() function should be called if key is NULL */ +# define EVP_CIPH_ALWAYS_CALL_INIT 0x20 +/* Call ctrl() to init cipher parameters */ +# define EVP_CIPH_CTRL_INIT 0x40 +/* Don't use standard key length function */ +# define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 +/* Don't use standard block padding */ +# define EVP_CIPH_NO_PADDING 0x100 +/* cipher handles random key generation */ +# define EVP_CIPH_RAND_KEY 0x200 +/* cipher has its own additional copying logic */ +# define EVP_CIPH_CUSTOM_COPY 0x400 +/* Don't use standard iv length function */ +# define EVP_CIPH_CUSTOM_IV_LENGTH 0x800 +/* Allow use default ASN1 get/set iv */ +# define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000 +/* Buffer length in bits not bytes: CFB1 mode only */ +# define EVP_CIPH_FLAG_LENGTH_BITS 0x2000 +/* Note if suitable for use in FIPS mode */ +# define EVP_CIPH_FLAG_FIPS 0x4000 +/* Allow non FIPS cipher in FIPS mode */ +# define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x8000 +/* + * Cipher handles any and all padding logic as well as finalisation. + */ +# define EVP_CIPH_FLAG_CUSTOM_CIPHER 0x100000 +# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 +# define EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0x400000 +/* Cipher can handle pipeline operations */ +# define EVP_CIPH_FLAG_PIPELINE 0X800000 + +/* + * Cipher context flag to indicate we can handle wrap mode: if allowed in + * older applications it could overflow buffers. + */ + +# define EVP_CIPHER_CTX_FLAG_WRAP_ALLOW 0x1 + +/* ctrl() values */ + +# define EVP_CTRL_INIT 0x0 +# define EVP_CTRL_SET_KEY_LENGTH 0x1 +# define EVP_CTRL_GET_RC2_KEY_BITS 0x2 +# define EVP_CTRL_SET_RC2_KEY_BITS 0x3 +# define EVP_CTRL_GET_RC5_ROUNDS 0x4 +# define EVP_CTRL_SET_RC5_ROUNDS 0x5 +# define EVP_CTRL_RAND_KEY 0x6 +# define EVP_CTRL_PBE_PRF_NID 0x7 +# define EVP_CTRL_COPY 0x8 +# define EVP_CTRL_AEAD_SET_IVLEN 0x9 +# define EVP_CTRL_AEAD_GET_TAG 0x10 +# define EVP_CTRL_AEAD_SET_TAG 0x11 +# define EVP_CTRL_AEAD_SET_IV_FIXED 0x12 +# define EVP_CTRL_GCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN +# define EVP_CTRL_GCM_GET_TAG EVP_CTRL_AEAD_GET_TAG +# define EVP_CTRL_GCM_SET_TAG EVP_CTRL_AEAD_SET_TAG +# define EVP_CTRL_GCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED +# define EVP_CTRL_GCM_IV_GEN 0x13 +# define EVP_CTRL_CCM_SET_IVLEN EVP_CTRL_AEAD_SET_IVLEN +# define EVP_CTRL_CCM_GET_TAG EVP_CTRL_AEAD_GET_TAG +# define EVP_CTRL_CCM_SET_TAG EVP_CTRL_AEAD_SET_TAG +# define EVP_CTRL_CCM_SET_IV_FIXED EVP_CTRL_AEAD_SET_IV_FIXED +# define EVP_CTRL_CCM_SET_L 0x14 +# define EVP_CTRL_CCM_SET_MSGLEN 0x15 +/* + * AEAD cipher deduces payload length and returns number of bytes required to + * store MAC and eventual padding. Subsequent call to EVP_Cipher even + * appends/verifies MAC. + */ +# define EVP_CTRL_AEAD_TLS1_AAD 0x16 +/* Used by composite AEAD ciphers, no-op in GCM, CCM... */ +# define EVP_CTRL_AEAD_SET_MAC_KEY 0x17 +/* Set the GCM invocation field, decrypt only */ +# define EVP_CTRL_GCM_SET_IV_INV 0x18 + +# define EVP_CTRL_TLS1_1_MULTIBLOCK_AAD 0x19 +# define EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT 0x1a +# define EVP_CTRL_TLS1_1_MULTIBLOCK_DECRYPT 0x1b +# define EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE 0x1c + +# define EVP_CTRL_SSL3_MASTER_SECRET 0x1d + +/* EVP_CTRL_SET_SBOX takes the char * specifying S-boxes */ +# define EVP_CTRL_SET_SBOX 0x1e +/* + * EVP_CTRL_SBOX_USED takes a 'size_t' and 'char *', pointing at a + * pre-allocated buffer with specified size + */ +# define EVP_CTRL_SBOX_USED 0x1f +/* EVP_CTRL_KEY_MESH takes 'size_t' number of bytes to mesh the key after, + * 0 switches meshing off + */ +# define EVP_CTRL_KEY_MESH 0x20 +/* EVP_CTRL_BLOCK_PADDING_MODE takes the padding mode */ +# define EVP_CTRL_BLOCK_PADDING_MODE 0x21 + +/* Set the output buffers to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS 0x22 +/* Set the input buffers to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_INPUT_BUFS 0x23 +/* Set the input buffer lengths to use for a pipelined operation */ +# define EVP_CTRL_SET_PIPELINE_INPUT_LENS 0x24 + +# define EVP_CTRL_GET_IVLEN 0x25 + +/* Padding modes */ +#define EVP_PADDING_PKCS7 1 +#define EVP_PADDING_ISO7816_4 2 +#define EVP_PADDING_ANSI923 3 +#define EVP_PADDING_ISO10126 4 +#define EVP_PADDING_ZERO 5 + +/* RFC 5246 defines additional data to be 13 bytes in length */ +# define EVP_AEAD_TLS1_AAD_LEN 13 + +typedef struct { + unsigned char *out; + const unsigned char *inp; + size_t len; + unsigned int interleave; +} EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM; + +/* GCM TLS constants */ +/* Length of fixed part of IV derived from PRF */ +# define EVP_GCM_TLS_FIXED_IV_LEN 4 +/* Length of explicit part of IV part of TLS records */ +# define EVP_GCM_TLS_EXPLICIT_IV_LEN 8 +/* Length of tag for TLS */ +# define EVP_GCM_TLS_TAG_LEN 16 + +/* CCM TLS constants */ +/* Length of fixed part of IV derived from PRF */ +# define EVP_CCM_TLS_FIXED_IV_LEN 4 +/* Length of explicit part of IV part of TLS records */ +# define EVP_CCM_TLS_EXPLICIT_IV_LEN 8 +/* Total length of CCM IV length for TLS */ +# define EVP_CCM_TLS_IV_LEN 12 +/* Length of tag for TLS */ +# define EVP_CCM_TLS_TAG_LEN 16 +/* Length of CCM8 tag for TLS */ +# define EVP_CCM8_TLS_TAG_LEN 8 + +/* Length of tag for TLS */ +# define EVP_CHACHAPOLY_TLS_TAG_LEN 16 + +typedef struct evp_cipher_info_st { + const EVP_CIPHER *cipher; + unsigned char iv[EVP_MAX_IV_LENGTH]; +} EVP_CIPHER_INFO; + + +/* Password based encryption function */ +typedef int (EVP_PBE_KEYGEN) (EVP_CIPHER_CTX *ctx, const char *pass, + int passlen, ASN1_TYPE *param, + const EVP_CIPHER *cipher, const EVP_MD *md, + int en_de); + +# ifndef OPENSSL_NO_RSA +# define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ + (char *)(rsa)) +# endif + +# ifndef OPENSSL_NO_DSA +# define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ + (char *)(dsa)) +# endif + +# ifndef OPENSSL_NO_DH +# define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ + (char *)(dh)) +# endif + +# ifndef OPENSSL_NO_EC +# define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\ + (char *)(eckey)) +# endif +# ifndef OPENSSL_NO_SIPHASH +# define EVP_PKEY_assign_SIPHASH(pkey,shkey) EVP_PKEY_assign((pkey),EVP_PKEY_SIPHASH,\ + (char *)(shkey)) +# endif + +# ifndef OPENSSL_NO_POLY1305 +# define EVP_PKEY_assign_POLY1305(pkey,polykey) EVP_PKEY_assign((pkey),EVP_PKEY_POLY1305,\ + (char *)(polykey)) +# endif + +/* Add some extra combinations */ +# define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) +# define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) +# define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) +# define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) + +int EVP_MD_type(const EVP_MD *md); +# define EVP_MD_nid(e) EVP_MD_type(e) +# define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) +int EVP_MD_pkey_type(const EVP_MD *md); +int EVP_MD_size(const EVP_MD *md); +int EVP_MD_block_size(const EVP_MD *md); +unsigned long EVP_MD_flags(const EVP_MD *md); + +const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); +int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx, + const void *data, size_t count); +void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx, + int (*update) (EVP_MD_CTX *ctx, + const void *data, size_t count)); +# define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) +# define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) +# define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) +EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx); +void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx); +void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx); + +int EVP_CIPHER_nid(const EVP_CIPHER *cipher); +# define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) +int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); +int EVP_CIPHER_impl_ctx_size(const EVP_CIPHER *cipher); +int EVP_CIPHER_key_length(const EVP_CIPHER *cipher); +int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher); +unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher); +# define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE) + +const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); +const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx); +const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx); +unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx); +unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx); +int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX *ctx); +void EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num); +int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in); +void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); +void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); +void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx); +void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data); +# define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) +# if OPENSSL_API_COMPAT < 0x10100000L +# define EVP_CIPHER_CTX_flags(c) EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(c)) +# endif +# define EVP_CIPHER_CTX_mode(c) EVP_CIPHER_mode(EVP_CIPHER_CTX_cipher(c)) + +# define EVP_ENCODE_LENGTH(l) ((((l)+2)/3*4)+((l)/48+1)*2+80) +# define EVP_DECODE_LENGTH(l) (((l)+3)/4*3+80) + +# define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +# define EVP_SignInit(a,b) EVP_DigestInit(a,b) +# define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c) +# define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) +# define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) +# define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) +# define EVP_DigestSignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) +# define EVP_DigestVerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) + +# ifdef CONST_STRICT +void BIO_set_md(BIO *, const EVP_MD *md); +# else +# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)(md)) +# endif +# define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)(mdp)) +# define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0, \ + (char *)(mdcp)) +# define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0, \ + (char *)(mdcp)) +# define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) +# define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0, \ + (char *)(c_pp)) + +/*__owur*/ int EVP_Cipher(EVP_CIPHER_CTX *c, + unsigned char *out, + const unsigned char *in, unsigned int inl); + +# define EVP_add_cipher_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) +# define EVP_add_digest_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) +# define EVP_delete_cipher_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); +# define EVP_delete_digest_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); + +int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); +EVP_MD_CTX *EVP_MD_CTX_new(void); +int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); +void EVP_MD_CTX_free(EVP_MD_CTX *ctx); +# define EVP_MD_CTX_create() EVP_MD_CTX_new() +# define EVP_MD_CTX_init(ctx) EVP_MD_CTX_reset((ctx)) +# define EVP_MD_CTX_destroy(ctx) EVP_MD_CTX_free((ctx)) +__owur int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); +void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); +void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); +int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); +__owur int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, + ENGINE *impl); +__owur int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, + size_t cnt); +__owur int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, + unsigned int *s); +__owur int EVP_Digest(const void *data, size_t count, + unsigned char *md, unsigned int *size, + const EVP_MD *type, ENGINE *impl); + +__owur int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in); +__owur int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); +__owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, + unsigned int *s); +__owur int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, + size_t len); + +int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); +int EVP_read_pw_string_min(char *buf, int minlen, int maxlen, + const char *prompt, int verify); +void EVP_set_pw_prompt(const char *prompt); +char *EVP_get_pw_prompt(void); + +__owur int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, + const unsigned char *salt, + const unsigned char *data, int datal, int count, + unsigned char *key, unsigned char *iv); + +void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags); +void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags); +int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags); + +__owur int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +/*__owur*/ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv); +/*__owur*/ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +/*__owur*/ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl); +/*__owur*/ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl); + +__owur int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv); +/*__owur*/ int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv); +/*__owur*/ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +__owur int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); +/*__owur*/ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); + +__owur int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + const unsigned char *key, const unsigned char *iv, + int enc); +/*__owur*/ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, + const EVP_CIPHER *cipher, ENGINE *impl, + const unsigned char *key, + const unsigned char *iv, int enc); +__owur int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, + int *outl, const unsigned char *in, int inl); +__owur int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); +__owur int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, + int *outl); + +__owur int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s, + EVP_PKEY *pkey); + +__owur int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, + size_t *siglen, const unsigned char *tbs, + size_t tbslen); + +__owur int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, + unsigned int siglen, EVP_PKEY *pkey); + +__owur int EVP_DigestVerify(EVP_MD_CTX *ctx, const unsigned char *sigret, + size_t siglen, const unsigned char *tbs, + size_t tbslen); + +/*__owur*/ int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, + const EVP_MD *type, ENGINE *e, + EVP_PKEY *pkey); +__owur int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, + size_t *siglen); + +__owur int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, + const EVP_MD *type, ENGINE *e, + EVP_PKEY *pkey); +__owur int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, + size_t siglen); + +# ifndef OPENSSL_NO_RSA +__owur int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, + const unsigned char *ek, int ekl, + const unsigned char *iv, EVP_PKEY *priv); +__owur int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); + +__owur int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, + unsigned char **ek, int *ekl, unsigned char *iv, + EVP_PKEY **pubk, int npubk); +__owur int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); +# endif + +EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void); +void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx); +int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, EVP_ENCODE_CTX *sctx); +int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx); +void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); +int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + const unsigned char *in, int inl); +void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl); +int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); + +void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); +int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + const unsigned char *in, int inl); +int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned + char *out, int *outl); +int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define EVP_CIPHER_CTX_init(c) EVP_CIPHER_CTX_reset(c) +# define EVP_CIPHER_CTX_cleanup(c) EVP_CIPHER_CTX_reset(c) +# endif +EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void); +int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c); +void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *c); +int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); +int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); +int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); +int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key); + +const BIO_METHOD *BIO_f_md(void); +const BIO_METHOD *BIO_f_base64(void); +const BIO_METHOD *BIO_f_cipher(void); +const BIO_METHOD *BIO_f_reliable(void); +__owur int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k, + const unsigned char *i, int enc); + +const EVP_MD *EVP_md_null(void); +# ifndef OPENSSL_NO_MD2 +const EVP_MD *EVP_md2(void); +# endif +# ifndef OPENSSL_NO_MD4 +const EVP_MD *EVP_md4(void); +# endif +# ifndef OPENSSL_NO_MD5 +const EVP_MD *EVP_md5(void); +const EVP_MD *EVP_md5_sha1(void); +# endif +# ifndef OPENSSL_NO_BLAKE2 +const EVP_MD *EVP_blake2b512(void); +const EVP_MD *EVP_blake2s256(void); +# endif +const EVP_MD *EVP_sha1(void); +const EVP_MD *EVP_sha224(void); +const EVP_MD *EVP_sha256(void); +const EVP_MD *EVP_sha384(void); +const EVP_MD *EVP_sha512(void); +const EVP_MD *EVP_sha512_224(void); +const EVP_MD *EVP_sha512_256(void); +const EVP_MD *EVP_sha3_224(void); +const EVP_MD *EVP_sha3_256(void); +const EVP_MD *EVP_sha3_384(void); +const EVP_MD *EVP_sha3_512(void); +const EVP_MD *EVP_shake128(void); +const EVP_MD *EVP_shake256(void); +# ifndef OPENSSL_NO_MDC2 +const EVP_MD *EVP_mdc2(void); +# endif +# ifndef OPENSSL_NO_RMD160 +const EVP_MD *EVP_ripemd160(void); +# endif +# ifndef OPENSSL_NO_WHIRLPOOL +const EVP_MD *EVP_whirlpool(void); +# endif +# ifndef OPENSSL_NO_SM3 +const EVP_MD *EVP_sm3(void); +# endif +const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ +# ifndef OPENSSL_NO_DES +const EVP_CIPHER *EVP_des_ecb(void); +const EVP_CIPHER *EVP_des_ede(void); +const EVP_CIPHER *EVP_des_ede3(void); +const EVP_CIPHER *EVP_des_ede_ecb(void); +const EVP_CIPHER *EVP_des_ede3_ecb(void); +const EVP_CIPHER *EVP_des_cfb64(void); +# define EVP_des_cfb EVP_des_cfb64 +const EVP_CIPHER *EVP_des_cfb1(void); +const EVP_CIPHER *EVP_des_cfb8(void); +const EVP_CIPHER *EVP_des_ede_cfb64(void); +# define EVP_des_ede_cfb EVP_des_ede_cfb64 +const EVP_CIPHER *EVP_des_ede3_cfb64(void); +# define EVP_des_ede3_cfb EVP_des_ede3_cfb64 +const EVP_CIPHER *EVP_des_ede3_cfb1(void); +const EVP_CIPHER *EVP_des_ede3_cfb8(void); +const EVP_CIPHER *EVP_des_ofb(void); +const EVP_CIPHER *EVP_des_ede_ofb(void); +const EVP_CIPHER *EVP_des_ede3_ofb(void); +const EVP_CIPHER *EVP_des_cbc(void); +const EVP_CIPHER *EVP_des_ede_cbc(void); +const EVP_CIPHER *EVP_des_ede3_cbc(void); +const EVP_CIPHER *EVP_desx_cbc(void); +const EVP_CIPHER *EVP_des_ede3_wrap(void); +/* + * This should now be supported through the dev_crypto ENGINE. But also, why + * are rc4 and md5 declarations made here inside a "NO_DES" precompiler + * branch? + */ +# endif +# ifndef OPENSSL_NO_RC4 +const EVP_CIPHER *EVP_rc4(void); +const EVP_CIPHER *EVP_rc4_40(void); +# ifndef OPENSSL_NO_MD5 +const EVP_CIPHER *EVP_rc4_hmac_md5(void); +# endif +# endif +# ifndef OPENSSL_NO_IDEA +const EVP_CIPHER *EVP_idea_ecb(void); +const EVP_CIPHER *EVP_idea_cfb64(void); +# define EVP_idea_cfb EVP_idea_cfb64 +const EVP_CIPHER *EVP_idea_ofb(void); +const EVP_CIPHER *EVP_idea_cbc(void); +# endif +# ifndef OPENSSL_NO_RC2 +const EVP_CIPHER *EVP_rc2_ecb(void); +const EVP_CIPHER *EVP_rc2_cbc(void); +const EVP_CIPHER *EVP_rc2_40_cbc(void); +const EVP_CIPHER *EVP_rc2_64_cbc(void); +const EVP_CIPHER *EVP_rc2_cfb64(void); +# define EVP_rc2_cfb EVP_rc2_cfb64 +const EVP_CIPHER *EVP_rc2_ofb(void); +# endif +# ifndef OPENSSL_NO_BF +const EVP_CIPHER *EVP_bf_ecb(void); +const EVP_CIPHER *EVP_bf_cbc(void); +const EVP_CIPHER *EVP_bf_cfb64(void); +# define EVP_bf_cfb EVP_bf_cfb64 +const EVP_CIPHER *EVP_bf_ofb(void); +# endif +# ifndef OPENSSL_NO_CAST +const EVP_CIPHER *EVP_cast5_ecb(void); +const EVP_CIPHER *EVP_cast5_cbc(void); +const EVP_CIPHER *EVP_cast5_cfb64(void); +# define EVP_cast5_cfb EVP_cast5_cfb64 +const EVP_CIPHER *EVP_cast5_ofb(void); +# endif +# ifndef OPENSSL_NO_RC5 +const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); +const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); +const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void); +# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64 +const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); +# endif +const EVP_CIPHER *EVP_aes_128_ecb(void); +const EVP_CIPHER *EVP_aes_128_cbc(void); +const EVP_CIPHER *EVP_aes_128_cfb1(void); +const EVP_CIPHER *EVP_aes_128_cfb8(void); +const EVP_CIPHER *EVP_aes_128_cfb128(void); +# define EVP_aes_128_cfb EVP_aes_128_cfb128 +const EVP_CIPHER *EVP_aes_128_ofb(void); +const EVP_CIPHER *EVP_aes_128_ctr(void); +const EVP_CIPHER *EVP_aes_128_ccm(void); +const EVP_CIPHER *EVP_aes_128_gcm(void); +const EVP_CIPHER *EVP_aes_128_xts(void); +const EVP_CIPHER *EVP_aes_128_wrap(void); +const EVP_CIPHER *EVP_aes_128_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_128_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_192_ecb(void); +const EVP_CIPHER *EVP_aes_192_cbc(void); +const EVP_CIPHER *EVP_aes_192_cfb1(void); +const EVP_CIPHER *EVP_aes_192_cfb8(void); +const EVP_CIPHER *EVP_aes_192_cfb128(void); +# define EVP_aes_192_cfb EVP_aes_192_cfb128 +const EVP_CIPHER *EVP_aes_192_ofb(void); +const EVP_CIPHER *EVP_aes_192_ctr(void); +const EVP_CIPHER *EVP_aes_192_ccm(void); +const EVP_CIPHER *EVP_aes_192_gcm(void); +const EVP_CIPHER *EVP_aes_192_wrap(void); +const EVP_CIPHER *EVP_aes_192_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_192_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_256_ecb(void); +const EVP_CIPHER *EVP_aes_256_cbc(void); +const EVP_CIPHER *EVP_aes_256_cfb1(void); +const EVP_CIPHER *EVP_aes_256_cfb8(void); +const EVP_CIPHER *EVP_aes_256_cfb128(void); +# define EVP_aes_256_cfb EVP_aes_256_cfb128 +const EVP_CIPHER *EVP_aes_256_ofb(void); +const EVP_CIPHER *EVP_aes_256_ctr(void); +const EVP_CIPHER *EVP_aes_256_ccm(void); +const EVP_CIPHER *EVP_aes_256_gcm(void); +const EVP_CIPHER *EVP_aes_256_xts(void); +const EVP_CIPHER *EVP_aes_256_wrap(void); +const EVP_CIPHER *EVP_aes_256_wrap_pad(void); +# ifndef OPENSSL_NO_OCB +const EVP_CIPHER *EVP_aes_256_ocb(void); +# endif +const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); +const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void); +const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha256(void); +const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha256(void); +# ifndef OPENSSL_NO_ARIA +const EVP_CIPHER *EVP_aria_128_ecb(void); +const EVP_CIPHER *EVP_aria_128_cbc(void); +const EVP_CIPHER *EVP_aria_128_cfb1(void); +const EVP_CIPHER *EVP_aria_128_cfb8(void); +const EVP_CIPHER *EVP_aria_128_cfb128(void); +# define EVP_aria_128_cfb EVP_aria_128_cfb128 +const EVP_CIPHER *EVP_aria_128_ctr(void); +const EVP_CIPHER *EVP_aria_128_ofb(void); +const EVP_CIPHER *EVP_aria_128_gcm(void); +const EVP_CIPHER *EVP_aria_128_ccm(void); +const EVP_CIPHER *EVP_aria_192_ecb(void); +const EVP_CIPHER *EVP_aria_192_cbc(void); +const EVP_CIPHER *EVP_aria_192_cfb1(void); +const EVP_CIPHER *EVP_aria_192_cfb8(void); +const EVP_CIPHER *EVP_aria_192_cfb128(void); +# define EVP_aria_192_cfb EVP_aria_192_cfb128 +const EVP_CIPHER *EVP_aria_192_ctr(void); +const EVP_CIPHER *EVP_aria_192_ofb(void); +const EVP_CIPHER *EVP_aria_192_gcm(void); +const EVP_CIPHER *EVP_aria_192_ccm(void); +const EVP_CIPHER *EVP_aria_256_ecb(void); +const EVP_CIPHER *EVP_aria_256_cbc(void); +const EVP_CIPHER *EVP_aria_256_cfb1(void); +const EVP_CIPHER *EVP_aria_256_cfb8(void); +const EVP_CIPHER *EVP_aria_256_cfb128(void); +# define EVP_aria_256_cfb EVP_aria_256_cfb128 +const EVP_CIPHER *EVP_aria_256_ctr(void); +const EVP_CIPHER *EVP_aria_256_ofb(void); +const EVP_CIPHER *EVP_aria_256_gcm(void); +const EVP_CIPHER *EVP_aria_256_ccm(void); +# endif +# ifndef OPENSSL_NO_CAMELLIA +const EVP_CIPHER *EVP_camellia_128_ecb(void); +const EVP_CIPHER *EVP_camellia_128_cbc(void); +const EVP_CIPHER *EVP_camellia_128_cfb1(void); +const EVP_CIPHER *EVP_camellia_128_cfb8(void); +const EVP_CIPHER *EVP_camellia_128_cfb128(void); +# define EVP_camellia_128_cfb EVP_camellia_128_cfb128 +const EVP_CIPHER *EVP_camellia_128_ofb(void); +const EVP_CIPHER *EVP_camellia_128_ctr(void); +const EVP_CIPHER *EVP_camellia_192_ecb(void); +const EVP_CIPHER *EVP_camellia_192_cbc(void); +const EVP_CIPHER *EVP_camellia_192_cfb1(void); +const EVP_CIPHER *EVP_camellia_192_cfb8(void); +const EVP_CIPHER *EVP_camellia_192_cfb128(void); +# define EVP_camellia_192_cfb EVP_camellia_192_cfb128 +const EVP_CIPHER *EVP_camellia_192_ofb(void); +const EVP_CIPHER *EVP_camellia_192_ctr(void); +const EVP_CIPHER *EVP_camellia_256_ecb(void); +const EVP_CIPHER *EVP_camellia_256_cbc(void); +const EVP_CIPHER *EVP_camellia_256_cfb1(void); +const EVP_CIPHER *EVP_camellia_256_cfb8(void); +const EVP_CIPHER *EVP_camellia_256_cfb128(void); +# define EVP_camellia_256_cfb EVP_camellia_256_cfb128 +const EVP_CIPHER *EVP_camellia_256_ofb(void); +const EVP_CIPHER *EVP_camellia_256_ctr(void); +# endif +# ifndef OPENSSL_NO_CHACHA +const EVP_CIPHER *EVP_chacha20(void); +# ifndef OPENSSL_NO_POLY1305 +const EVP_CIPHER *EVP_chacha20_poly1305(void); +# endif +# endif + +# ifndef OPENSSL_NO_SEED +const EVP_CIPHER *EVP_seed_ecb(void); +const EVP_CIPHER *EVP_seed_cbc(void); +const EVP_CIPHER *EVP_seed_cfb128(void); +# define EVP_seed_cfb EVP_seed_cfb128 +const EVP_CIPHER *EVP_seed_ofb(void); +# endif + +# ifndef OPENSSL_NO_SM4 +const EVP_CIPHER *EVP_sm4_ecb(void); +const EVP_CIPHER *EVP_sm4_cbc(void); +const EVP_CIPHER *EVP_sm4_cfb128(void); +# define EVP_sm4_cfb EVP_sm4_cfb128 +const EVP_CIPHER *EVP_sm4_ofb(void); +const EVP_CIPHER *EVP_sm4_ctr(void); +# endif + +# if OPENSSL_API_COMPAT < 0x10100000L +# define OPENSSL_add_all_algorithms_conf() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS \ + | OPENSSL_INIT_LOAD_CONFIG, NULL) +# define OPENSSL_add_all_algorithms_noconf() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ + | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) + +# ifdef OPENSSL_LOAD_CONF +# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_conf() +# else +# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_noconf() +# endif + +# define OpenSSL_add_all_ciphers() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL) +# define OpenSSL_add_all_digests() \ + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) + +# define EVP_cleanup() while(0) continue +# endif + +int EVP_add_cipher(const EVP_CIPHER *cipher); +int EVP_add_digest(const EVP_MD *digest); + +const EVP_CIPHER *EVP_get_cipherbyname(const char *name); +const EVP_MD *EVP_get_digestbyname(const char *name); + +void EVP_CIPHER_do_all(void (*fn) (const EVP_CIPHER *ciph, + const char *from, const char *to, void *x), + void *arg); +void EVP_CIPHER_do_all_sorted(void (*fn) + (const EVP_CIPHER *ciph, const char *from, + const char *to, void *x), void *arg); + +void EVP_MD_do_all(void (*fn) (const EVP_MD *ciph, + const char *from, const char *to, void *x), + void *arg); +void EVP_MD_do_all_sorted(void (*fn) + (const EVP_MD *ciph, const char *from, + const char *to, void *x), void *arg); + +int EVP_PKEY_decrypt_old(unsigned char *dec_key, + const unsigned char *enc_key, int enc_key_len, + EVP_PKEY *private_key); +int EVP_PKEY_encrypt_old(unsigned char *enc_key, + const unsigned char *key, int key_len, + EVP_PKEY *pub_key); +int EVP_PKEY_type(int type); +int EVP_PKEY_id(const EVP_PKEY *pkey); +int EVP_PKEY_base_id(const EVP_PKEY *pkey); +int EVP_PKEY_bits(const EVP_PKEY *pkey); +int EVP_PKEY_security_bits(const EVP_PKEY *pkey); +int EVP_PKEY_size(const EVP_PKEY *pkey); +int EVP_PKEY_set_type(EVP_PKEY *pkey, int type); +int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len); +int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type); +# ifndef OPENSSL_NO_ENGINE +int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e); +ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey); +# endif +int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); +void *EVP_PKEY_get0(const EVP_PKEY *pkey); +const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len); +# ifndef OPENSSL_NO_POLY1305 +const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len); +# endif +# ifndef OPENSSL_NO_SIPHASH +const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len); +# endif + +# ifndef OPENSSL_NO_RSA +struct rsa_st; +int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key); +struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey); +struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_DSA +struct dsa_st; +int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, struct dsa_st *key); +struct dsa_st *EVP_PKEY_get0_DSA(EVP_PKEY *pkey); +struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_DH +struct dh_st; +int EVP_PKEY_set1_DH(EVP_PKEY *pkey, struct dh_st *key); +struct dh_st *EVP_PKEY_get0_DH(EVP_PKEY *pkey); +struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); +# endif +# ifndef OPENSSL_NO_EC +struct ec_key_st; +int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); +struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); +struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); +# endif + +EVP_PKEY *EVP_PKEY_new(void); +int EVP_PKEY_up_ref(EVP_PKEY *pkey); +void EVP_PKEY_free(EVP_PKEY *pkey); + +EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); + +EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, + long length); +EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, + long length); +int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); + +int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); +int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); +int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode); +int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b); + +int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); +int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); +int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx); + +int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid); + +int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey, + const unsigned char *pt, size_t ptlen); +size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt); + +int EVP_CIPHER_type(const EVP_CIPHER *ctx); + +/* calls methods */ +int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +/* These are used by EVP_CIPHER methods */ +int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +/* PKCS5 password based encryption */ +int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md, int en_de); +int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, + const unsigned char *salt, int saltlen, int iter, + int keylen, unsigned char *out); +int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, + const unsigned char *salt, int saltlen, int iter, + const EVP_MD *digest, int keylen, unsigned char *out); +int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md, int en_de); + +#ifndef OPENSSL_NO_SCRYPT +int EVP_PBE_scrypt(const char *pass, size_t passlen, + const unsigned char *salt, size_t saltlen, + uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, + unsigned char *key, size_t keylen); + +int PKCS5_v2_scrypt_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, + int passlen, ASN1_TYPE *param, + const EVP_CIPHER *c, const EVP_MD *md, int en_de); +#endif + +void PKCS5_PBE_add(void); + +int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); + +/* PBE type */ + +/* Can appear as the outermost AlgorithmIdentifier */ +# define EVP_PBE_TYPE_OUTER 0x0 +/* Is an PRF type OID */ +# define EVP_PBE_TYPE_PRF 0x1 +/* Is a PKCS#5 v2.0 KDF */ +# define EVP_PBE_TYPE_KDF 0x2 + +int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, + int md_nid, EVP_PBE_KEYGEN *keygen); +int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md, + EVP_PBE_KEYGEN *keygen); +int EVP_PBE_find(int type, int pbe_nid, int *pcnid, int *pmnid, + EVP_PBE_KEYGEN **pkeygen); +void EVP_PBE_cleanup(void); +int EVP_PBE_get(int *ptype, int *ppbe_nid, size_t num); + +# define ASN1_PKEY_ALIAS 0x1 +# define ASN1_PKEY_DYNAMIC 0x2 +# define ASN1_PKEY_SIGPARAM_NULL 0x4 + +# define ASN1_PKEY_CTRL_PKCS7_SIGN 0x1 +# define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 0x2 +# define ASN1_PKEY_CTRL_DEFAULT_MD_NID 0x3 +# define ASN1_PKEY_CTRL_CMS_SIGN 0x5 +# define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7 +# define ASN1_PKEY_CTRL_CMS_RI_TYPE 0x8 + +# define ASN1_PKEY_CTRL_SET1_TLS_ENCPT 0x9 +# define ASN1_PKEY_CTRL_GET1_TLS_ENCPT 0xa + +int EVP_PKEY_asn1_get_count(void); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type); +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, + const char *str, int len); +int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth); +int EVP_PKEY_asn1_add_alias(int to, int from); +int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, + int *ppkey_flags, const char **pinfo, + const char **ppem_str, + const EVP_PKEY_ASN1_METHOD *ameth); + +const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey); +EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, + const char *pem_str, + const char *info); +void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, + const EVP_PKEY_ASN1_METHOD *src); +void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth); +void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, + int (*pub_decode) (EVP_PKEY *pk, + X509_PUBKEY *pub), + int (*pub_encode) (X509_PUBKEY *pub, + const EVP_PKEY *pk), + int (*pub_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*pub_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, ASN1_PCTX *pctx), + int (*pkey_size) (const EVP_PKEY *pk), + int (*pkey_bits) (const EVP_PKEY *pk)); +void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, + int (*priv_decode) (EVP_PKEY *pk, + const PKCS8_PRIV_KEY_INFO + *p8inf), + int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, + const EVP_PKEY *pk), + int (*priv_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); +void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, + int (*param_decode) (EVP_PKEY *pkey, + const unsigned char **pder, + int derlen), + int (*param_encode) (const EVP_PKEY *pkey, + unsigned char **pder), + int (*param_missing) (const EVP_PKEY *pk), + int (*param_copy) (EVP_PKEY *to, + const EVP_PKEY *from), + int (*param_cmp) (const EVP_PKEY *a, + const EVP_PKEY *b), + int (*param_print) (BIO *out, + const EVP_PKEY *pkey, + int indent, + ASN1_PCTX *pctx)); + +void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, + void (*pkey_free) (EVP_PKEY *pkey)); +void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_ctrl) (EVP_PKEY *pkey, int op, + long arg1, void *arg2)); +void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth, + int (*item_verify) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *a, + ASN1_BIT_STRING *sig, + EVP_PKEY *pkey), + int (*item_sign) (EVP_MD_CTX *ctx, + const ASN1_ITEM *it, + void *asn, + X509_ALGOR *alg1, + X509_ALGOR *alg2, + ASN1_BIT_STRING *sig)); + +void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth, + int (*siginf_set) (X509_SIG_INFO *siginf, + const X509_ALGOR *alg, + const ASN1_STRING *sig)); + +void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_check) (const EVP_PKEY *pk)); + +void EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_pub_check) (const EVP_PKEY *pk)); + +void EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_param_check) (const EVP_PKEY *pk)); + +void EVP_PKEY_asn1_set_set_priv_key(EVP_PKEY_ASN1_METHOD *ameth, + int (*set_priv_key) (EVP_PKEY *pk, + const unsigned char + *priv, + size_t len)); +void EVP_PKEY_asn1_set_set_pub_key(EVP_PKEY_ASN1_METHOD *ameth, + int (*set_pub_key) (EVP_PKEY *pk, + const unsigned char *pub, + size_t len)); +void EVP_PKEY_asn1_set_get_priv_key(EVP_PKEY_ASN1_METHOD *ameth, + int (*get_priv_key) (const EVP_PKEY *pk, + unsigned char *priv, + size_t *len)); +void EVP_PKEY_asn1_set_get_pub_key(EVP_PKEY_ASN1_METHOD *ameth, + int (*get_pub_key) (const EVP_PKEY *pk, + unsigned char *pub, + size_t *len)); + +void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth, + int (*pkey_security_bits) (const EVP_PKEY + *pk)); + +# define EVP_PKEY_OP_UNDEFINED 0 +# define EVP_PKEY_OP_PARAMGEN (1<<1) +# define EVP_PKEY_OP_KEYGEN (1<<2) +# define EVP_PKEY_OP_SIGN (1<<3) +# define EVP_PKEY_OP_VERIFY (1<<4) +# define EVP_PKEY_OP_VERIFYRECOVER (1<<5) +# define EVP_PKEY_OP_SIGNCTX (1<<6) +# define EVP_PKEY_OP_VERIFYCTX (1<<7) +# define EVP_PKEY_OP_ENCRYPT (1<<8) +# define EVP_PKEY_OP_DECRYPT (1<<9) +# define EVP_PKEY_OP_DERIVE (1<<10) + +# define EVP_PKEY_OP_TYPE_SIG \ + (EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER \ + | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX) + +# define EVP_PKEY_OP_TYPE_CRYPT \ + (EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT) + +# define EVP_PKEY_OP_TYPE_NOGEN \ + (EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT | EVP_PKEY_OP_DERIVE) + +# define EVP_PKEY_OP_TYPE_GEN \ + (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN) + +# define EVP_PKEY_CTX_set_signature_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, \ + EVP_PKEY_CTRL_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_get_signature_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, \ + EVP_PKEY_CTRL_GET_MD, 0, (void *)(pmd)) + +# define EVP_PKEY_CTX_set_mac_key(ctx, key, len) \ + EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_SET_MAC_KEY, len, (void *)(key)) + +# define EVP_PKEY_CTRL_MD 1 +# define EVP_PKEY_CTRL_PEER_KEY 2 + +# define EVP_PKEY_CTRL_PKCS7_ENCRYPT 3 +# define EVP_PKEY_CTRL_PKCS7_DECRYPT 4 + +# define EVP_PKEY_CTRL_PKCS7_SIGN 5 + +# define EVP_PKEY_CTRL_SET_MAC_KEY 6 + +# define EVP_PKEY_CTRL_DIGESTINIT 7 + +/* Used by GOST key encryption in TLS */ +# define EVP_PKEY_CTRL_SET_IV 8 + +# define EVP_PKEY_CTRL_CMS_ENCRYPT 9 +# define EVP_PKEY_CTRL_CMS_DECRYPT 10 +# define EVP_PKEY_CTRL_CMS_SIGN 11 + +# define EVP_PKEY_CTRL_CIPHER 12 + +# define EVP_PKEY_CTRL_GET_MD 13 + +# define EVP_PKEY_CTRL_SET_DIGEST_SIZE 14 + +# define EVP_PKEY_ALG_CTRL 0x1000 + +# define EVP_PKEY_FLAG_AUTOARGLEN 2 +/* + * Method handles all operations: don't assume any digest related defaults. + */ +# define EVP_PKEY_FLAG_SIGCTX_CUSTOM 4 + +const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type); +EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags); +void EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, + const EVP_PKEY_METHOD *meth); +void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src); +void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth); +int EVP_PKEY_meth_add0(const EVP_PKEY_METHOD *pmeth); +int EVP_PKEY_meth_remove(const EVP_PKEY_METHOD *pmeth); +size_t EVP_PKEY_meth_get_count(void); +const EVP_PKEY_METHOD *EVP_PKEY_meth_get0(size_t idx); + +EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); +EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e); +EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); +void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, + int cmd, int p1, void *p2); +int EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, + const char *value); +int EVP_PKEY_CTX_ctrl_uint64(EVP_PKEY_CTX *ctx, int keytype, int optype, + int cmd, uint64_t value); + +int EVP_PKEY_CTX_str2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *str); +int EVP_PKEY_CTX_hex2ctrl(EVP_PKEY_CTX *ctx, int cmd, const char *hex); + +int EVP_PKEY_CTX_md(EVP_PKEY_CTX *ctx, int optype, int cmd, const char *md); + +int EVP_PKEY_CTX_get_operation(EVP_PKEY_CTX *ctx); +void EVP_PKEY_CTX_set0_keygen_info(EVP_PKEY_CTX *ctx, int *dat, int datlen); + +EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, + const unsigned char *key, int keylen); +EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e, + const unsigned char *priv, + size_t len); +EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e, + const unsigned char *pub, + size_t len); +int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv, + size_t *len); +int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, + size_t *len); + +EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, + size_t len, const EVP_CIPHER *cipher); + +void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data); +void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx); +EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); + +EVP_PKEY *EVP_PKEY_CTX_get0_peerkey(EVP_PKEY_CTX *ctx); + +void EVP_PKEY_CTX_set_app_data(EVP_PKEY_CTX *ctx, void *data); +void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, size_t tbslen); +int EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_verify(EVP_PKEY_CTX *ctx, + const unsigned char *sig, size_t siglen, + const unsigned char *tbs, size_t tbslen); +int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, + unsigned char *rout, size_t *routlen, + const unsigned char *sig, size_t siglen); +int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, + unsigned char *out, size_t *outlen, + const unsigned char *in, size_t inlen); +int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, + unsigned char *out, size_t *outlen, + const unsigned char *in, size_t inlen); + +int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); +int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); + +typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); +int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); +int EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey); +int EVP_PKEY_check(EVP_PKEY_CTX *ctx); +int EVP_PKEY_public_check(EVP_PKEY_CTX *ctx); +int EVP_PKEY_param_check(EVP_PKEY_CTX *ctx); + +void EVP_PKEY_CTX_set_cb(EVP_PKEY_CTX *ctx, EVP_PKEY_gen_cb *cb); +EVP_PKEY_gen_cb *EVP_PKEY_CTX_get_cb(EVP_PKEY_CTX *ctx); + +int EVP_PKEY_CTX_get_keygen_info(EVP_PKEY_CTX *ctx, int idx); + +void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth, + int (*init) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth, + int (*copy) (EVP_PKEY_CTX *dst, + EVP_PKEY_CTX *src)); + +void EVP_PKEY_meth_set_cleanup(EVP_PKEY_METHOD *pmeth, + void (*cleanup) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_set_paramgen(EVP_PKEY_METHOD *pmeth, + int (*paramgen_init) (EVP_PKEY_CTX *ctx), + int (*paramgen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_keygen(EVP_PKEY_METHOD *pmeth, + int (*keygen_init) (EVP_PKEY_CTX *ctx), + int (*keygen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_sign(EVP_PKEY_METHOD *pmeth, + int (*sign_init) (EVP_PKEY_CTX *ctx), + int (*sign) (EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_verify(EVP_PKEY_METHOD *pmeth, + int (*verify_init) (EVP_PKEY_CTX *ctx), + int (*verify) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_verify_recover(EVP_PKEY_METHOD *pmeth, + int (*verify_recover_init) (EVP_PKEY_CTX + *ctx), + int (*verify_recover) (EVP_PKEY_CTX + *ctx, + unsigned char + *sig, + size_t *siglen, + const unsigned + char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_signctx(EVP_PKEY_METHOD *pmeth, + int (*signctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (*signctx) (EVP_PKEY_CTX *ctx, + unsigned char *sig, + size_t *siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_set_verifyctx(EVP_PKEY_METHOD *pmeth, + int (*verifyctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (*verifyctx) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + int siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_set_encrypt(EVP_PKEY_METHOD *pmeth, + int (*encrypt_init) (EVP_PKEY_CTX *ctx), + int (*encryptfn) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_set_decrypt(EVP_PKEY_METHOD *pmeth, + int (*decrypt_init) (EVP_PKEY_CTX *ctx), + int (*decrypt) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_set_derive(EVP_PKEY_METHOD *pmeth, + int (*derive_init) (EVP_PKEY_CTX *ctx), + int (*derive) (EVP_PKEY_CTX *ctx, + unsigned char *key, + size_t *keylen)); + +void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, + int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, + void *p2), + int (*ctrl_str) (EVP_PKEY_CTX *ctx, + const char *type, + const char *value)); + +void EVP_PKEY_meth_set_digestsign(EVP_PKEY_METHOD *pmeth, + int (*digestsign) (EVP_MD_CTX *ctx, + unsigned char *sig, + size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_digestverify(EVP_PKEY_METHOD *pmeth, + int (*digestverify) (EVP_MD_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_set_check(EVP_PKEY_METHOD *pmeth, + int (*check) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_public_check(EVP_PKEY_METHOD *pmeth, + int (*check) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_param_check(EVP_PKEY_METHOD *pmeth, + int (*check) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_set_digest_custom(EVP_PKEY_METHOD *pmeth, + int (*digest_custom) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth, + int (**pinit) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth, + int (**pcopy) (EVP_PKEY_CTX *dst, + EVP_PKEY_CTX *src)); + +void EVP_PKEY_meth_get_cleanup(const EVP_PKEY_METHOD *pmeth, + void (**pcleanup) (EVP_PKEY_CTX *ctx)); + +void EVP_PKEY_meth_get_paramgen(const EVP_PKEY_METHOD *pmeth, + int (**pparamgen_init) (EVP_PKEY_CTX *ctx), + int (**pparamgen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_keygen(const EVP_PKEY_METHOD *pmeth, + int (**pkeygen_init) (EVP_PKEY_CTX *ctx), + int (**pkeygen) (EVP_PKEY_CTX *ctx, + EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_sign(const EVP_PKEY_METHOD *pmeth, + int (**psign_init) (EVP_PKEY_CTX *ctx), + int (**psign) (EVP_PKEY_CTX *ctx, + unsigned char *sig, size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_verify(const EVP_PKEY_METHOD *pmeth, + int (**pverify_init) (EVP_PKEY_CTX *ctx), + int (**pverify) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_verify_recover(const EVP_PKEY_METHOD *pmeth, + int (**pverify_recover_init) (EVP_PKEY_CTX + *ctx), + int (**pverify_recover) (EVP_PKEY_CTX + *ctx, + unsigned char + *sig, + size_t *siglen, + const unsigned + char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_signctx(const EVP_PKEY_METHOD *pmeth, + int (**psignctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (**psignctx) (EVP_PKEY_CTX *ctx, + unsigned char *sig, + size_t *siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_get_verifyctx(const EVP_PKEY_METHOD *pmeth, + int (**pverifyctx_init) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx), + int (**pverifyctx) (EVP_PKEY_CTX *ctx, + const unsigned char *sig, + int siglen, + EVP_MD_CTX *mctx)); + +void EVP_PKEY_meth_get_encrypt(const EVP_PKEY_METHOD *pmeth, + int (**pencrypt_init) (EVP_PKEY_CTX *ctx), + int (**pencryptfn) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_get_decrypt(const EVP_PKEY_METHOD *pmeth, + int (**pdecrypt_init) (EVP_PKEY_CTX *ctx), + int (**pdecrypt) (EVP_PKEY_CTX *ctx, + unsigned char *out, + size_t *outlen, + const unsigned char *in, + size_t inlen)); + +void EVP_PKEY_meth_get_derive(const EVP_PKEY_METHOD *pmeth, + int (**pderive_init) (EVP_PKEY_CTX *ctx), + int (**pderive) (EVP_PKEY_CTX *ctx, + unsigned char *key, + size_t *keylen)); + +void EVP_PKEY_meth_get_ctrl(const EVP_PKEY_METHOD *pmeth, + int (**pctrl) (EVP_PKEY_CTX *ctx, int type, int p1, + void *p2), + int (**pctrl_str) (EVP_PKEY_CTX *ctx, + const char *type, + const char *value)); + +void EVP_PKEY_meth_get_digestsign(EVP_PKEY_METHOD *pmeth, + int (**digestsign) (EVP_MD_CTX *ctx, + unsigned char *sig, + size_t *siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_digestverify(EVP_PKEY_METHOD *pmeth, + int (**digestverify) (EVP_MD_CTX *ctx, + const unsigned char *sig, + size_t siglen, + const unsigned char *tbs, + size_t tbslen)); + +void EVP_PKEY_meth_get_check(const EVP_PKEY_METHOD *pmeth, + int (**pcheck) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_public_check(const EVP_PKEY_METHOD *pmeth, + int (**pcheck) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_param_check(const EVP_PKEY_METHOD *pmeth, + int (**pcheck) (EVP_PKEY *pkey)); + +void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth, + int (**pdigest_custom) (EVP_PKEY_CTX *ctx, + EVP_MD_CTX *mctx)); +void EVP_add_alg_module(void); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/hmac.h postgresql-hll-2.14/include/openssl/hmac.h --- postgresql-hll-2.14_old/include/openssl/hmac.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/hmac.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,51 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_HMAC_H +# define HEADER_HMAC_H + +# include + +# include + +# if OPENSSL_API_COMPAT < 0x10200000L +# define HMAC_MAX_MD_CBLOCK 128 /* Deprecated */ +# endif + +#ifdef __cplusplus +extern "C" { +#endif + +size_t HMAC_size(const HMAC_CTX *e); +HMAC_CTX *HMAC_CTX_new(void); +int HMAC_CTX_reset(HMAC_CTX *ctx); +void HMAC_CTX_free(HMAC_CTX *ctx); + +DEPRECATEDIN_1_1_0(__owur int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md)) + +/*__owur*/ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md, ENGINE *impl); +/*__owur*/ int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, + size_t len); +/*__owur*/ int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, + unsigned int *len); +unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, + const unsigned char *d, size_t n, unsigned char *md, + unsigned int *md_len); +__owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); + +void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); +const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/idea.h postgresql-hll-2.14/include/openssl/idea.h --- postgresql-hll-2.14_old/include/openssl/idea.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/idea.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,64 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_IDEA_H +# define HEADER_IDEA_H + +# include + +# ifndef OPENSSL_NO_IDEA +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned int IDEA_INT; + +# define IDEA_ENCRYPT 1 +# define IDEA_DECRYPT 0 + +# define IDEA_BLOCK 8 +# define IDEA_KEY_LENGTH 16 + +typedef struct idea_key_st { + IDEA_INT data[9][6]; +} IDEA_KEY_SCHEDULE; + +const char *IDEA_options(void); +void IDEA_ecb_encrypt(const unsigned char *in, unsigned char *out, + IDEA_KEY_SCHEDULE *ks); +void IDEA_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); +void IDEA_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); +void IDEA_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int enc); +void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num, int enc); +void IDEA_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num); +void IDEA_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define idea_options IDEA_options +# define idea_ecb_encrypt IDEA_ecb_encrypt +# define idea_set_encrypt_key IDEA_set_encrypt_key +# define idea_set_decrypt_key IDEA_set_decrypt_key +# define idea_cbc_encrypt IDEA_cbc_encrypt +# define idea_cfb64_encrypt IDEA_cfb64_encrypt +# define idea_ofb64_encrypt IDEA_ofb64_encrypt +# define idea_encrypt IDEA_encrypt +# endif + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/kdferr.h postgresql-hll-2.14/include/openssl/kdferr.h --- postgresql-hll-2.14_old/include/openssl/kdferr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/kdferr.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,55 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_KDFERR_H +# define HEADER_KDFERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_KDF_strings(void); + +/* + * KDF function codes. + */ +# define KDF_F_PKEY_HKDF_CTRL_STR 103 +# define KDF_F_PKEY_HKDF_DERIVE 102 +# define KDF_F_PKEY_HKDF_INIT 108 +# define KDF_F_PKEY_SCRYPT_CTRL_STR 104 +# define KDF_F_PKEY_SCRYPT_CTRL_UINT64 105 +# define KDF_F_PKEY_SCRYPT_DERIVE 109 +# define KDF_F_PKEY_SCRYPT_INIT 106 +# define KDF_F_PKEY_SCRYPT_SET_MEMBUF 107 +# define KDF_F_PKEY_TLS1_PRF_CTRL_STR 100 +# define KDF_F_PKEY_TLS1_PRF_DERIVE 101 +# define KDF_F_PKEY_TLS1_PRF_INIT 110 +# define KDF_F_TLS1_PRF_ALG 111 + +/* + * KDF reason codes. + */ +# define KDF_R_INVALID_DIGEST 100 +# define KDF_R_MISSING_ITERATION_COUNT 109 +# define KDF_R_MISSING_KEY 104 +# define KDF_R_MISSING_MESSAGE_DIGEST 105 +# define KDF_R_MISSING_PARAMETER 101 +# define KDF_R_MISSING_PASS 110 +# define KDF_R_MISSING_SALT 111 +# define KDF_R_MISSING_SECRET 107 +# define KDF_R_MISSING_SEED 106 +# define KDF_R_UNKNOWN_PARAMETER_TYPE 103 +# define KDF_R_VALUE_ERROR 108 +# define KDF_R_VALUE_MISSING 102 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/kdf.h postgresql-hll-2.14/include/openssl/kdf.h --- postgresql-hll-2.14_old/include/openssl/kdf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/kdf.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,97 @@ +/* + * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_KDF_H +# define HEADER_KDF_H + +# include +#ifdef __cplusplus +extern "C" { +#endif + +# define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL) +# define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2) +# define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5) +# define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_HKDF_MODE (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_PASS (EVP_PKEY_ALG_CTRL + 8) +# define EVP_PKEY_CTRL_SCRYPT_SALT (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_SCRYPT_N (EVP_PKEY_ALG_CTRL + 10) +# define EVP_PKEY_CTRL_SCRYPT_R (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_SCRYPT_P (EVP_PKEY_ALG_CTRL + 12) +# define EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES (EVP_PKEY_ALG_CTRL + 13) + +# define EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND 0 +# define EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY 1 +# define EVP_PKEY_HKDEF_MODE_EXPAND_ONLY 2 + +# define EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, seclen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_SECRET, seclen, (void *)(sec)) + +# define EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seedlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_TLS_SEED, seedlen, (void *)(seed)) + +# define EVP_PKEY_CTX_set_hkdf_md(pctx, md) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, saltlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_SALT, saltlen, (void *)(salt)) + +# define EVP_PKEY_CTX_set1_hkdf_key(pctx, key, keylen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_KEY, keylen, (void *)(key)) + +# define EVP_PKEY_CTX_add1_hkdf_info(pctx, info, infolen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_INFO, infolen, (void *)(info)) + +# define EVP_PKEY_CTX_hkdf_mode(pctx, mode) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_HKDF_MODE, mode, NULL) + +# define EVP_PKEY_CTX_set1_pbe_pass(pctx, pass, passlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_PASS, passlen, (void *)(pass)) + +# define EVP_PKEY_CTX_set1_scrypt_salt(pctx, salt, saltlen) \ + EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_SCRYPT_SALT, saltlen, (void *)(salt)) + +# define EVP_PKEY_CTX_set_scrypt_N(pctx, n) \ + EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_SCRYPT_N, n) + +# define EVP_PKEY_CTX_set_scrypt_r(pctx, r) \ + EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_SCRYPT_R, r) + +# define EVP_PKEY_CTX_set_scrypt_p(pctx, p) \ + EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_SCRYPT_P, p) + +# define EVP_PKEY_CTX_set_scrypt_maxmem_bytes(pctx, maxmem_bytes) \ + EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ + EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES, maxmem_bytes) + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/lhash.h postgresql-hll-2.14/include/openssl/lhash.h --- postgresql-hll-2.14_old/include/openssl/lhash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/lhash.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,241 @@ +/* + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Header for dynamic hash table routines Author - Eric Young + */ + +#ifndef HEADER_LHASH_H +# define HEADER_LHASH_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct lhash_node_st OPENSSL_LH_NODE; +typedef int (*OPENSSL_LH_COMPFUNC) (const void *, const void *); +typedef unsigned long (*OPENSSL_LH_HASHFUNC) (const void *); +typedef void (*OPENSSL_LH_DOALL_FUNC) (void *); +typedef void (*OPENSSL_LH_DOALL_FUNCARG) (void *, void *); +typedef struct lhash_st OPENSSL_LHASH; + +/* + * Macros for declaring and implementing type-safe wrappers for LHASH + * callbacks. This way, callbacks can be provided to LHASH structures without + * function pointer casting and the macro-defined callbacks provide + * per-variable casting before deferring to the underlying type-specific + * callbacks. NB: It is possible to place a "static" in front of both the + * DECLARE and IMPLEMENT macros if the functions are strictly internal. + */ + +/* First: "hash" functions */ +# define DECLARE_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *); +# define IMPLEMENT_LHASH_HASH_FN(name, o_type) \ + unsigned long name##_LHASH_HASH(const void *arg) { \ + const o_type *a = arg; \ + return name##_hash(a); } +# define LHASH_HASH_FN(name) name##_LHASH_HASH + +/* Second: "compare" functions */ +# define DECLARE_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *, const void *); +# define IMPLEMENT_LHASH_COMP_FN(name, o_type) \ + int name##_LHASH_COMP(const void *arg1, const void *arg2) { \ + const o_type *a = arg1; \ + const o_type *b = arg2; \ + return name##_cmp(a,b); } +# define LHASH_COMP_FN(name) name##_LHASH_COMP + +/* Fourth: "doall_arg" functions */ +# define DECLARE_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *, void *); +# define IMPLEMENT_LHASH_DOALL_ARG_FN(name, o_type, a_type) \ + void name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ + o_type *a = arg1; \ + a_type *b = arg2; \ + name##_doall_arg(a, b); } +# define LHASH_DOALL_ARG_FN(name) name##_LHASH_DOALL_ARG + + +# define LH_LOAD_MULT 256 + +int OPENSSL_LH_error(OPENSSL_LHASH *lh); +OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); +void OPENSSL_LH_free(OPENSSL_LHASH *lh); +void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); +void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); +void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); +void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); +void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg); +unsigned long OPENSSL_LH_strhash(const char *c); +unsigned long OPENSSL_LH_num_items(const OPENSSL_LHASH *lh); +unsigned long OPENSSL_LH_get_down_load(const OPENSSL_LHASH *lh); +void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long down_load); + +# ifndef OPENSSL_NO_STDIO +void OPENSSL_LH_stats(const OPENSSL_LHASH *lh, FILE *fp); +void OPENSSL_LH_node_stats(const OPENSSL_LHASH *lh, FILE *fp); +void OPENSSL_LH_node_usage_stats(const OPENSSL_LHASH *lh, FILE *fp); +# endif +void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out); +void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out); +void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define _LHASH OPENSSL_LHASH +# define LHASH_NODE OPENSSL_LH_NODE +# define lh_error OPENSSL_LH_error +# define lh_new OPENSSL_LH_new +# define lh_free OPENSSL_LH_free +# define lh_insert OPENSSL_LH_insert +# define lh_delete OPENSSL_LH_delete +# define lh_retrieve OPENSSL_LH_retrieve +# define lh_doall OPENSSL_LH_doall +# define lh_doall_arg OPENSSL_LH_doall_arg +# define lh_strhash OPENSSL_LH_strhash +# define lh_num_items OPENSSL_LH_num_items +# ifndef OPENSSL_NO_STDIO +# define lh_stats OPENSSL_LH_stats +# define lh_node_stats OPENSSL_LH_node_stats +# define lh_node_usage_stats OPENSSL_LH_node_usage_stats +# endif +# define lh_stats_bio OPENSSL_LH_stats_bio +# define lh_node_stats_bio OPENSSL_LH_node_stats_bio +# define lh_node_usage_stats_bio OPENSSL_LH_node_usage_stats_bio +# endif + +/* Type checking... */ + +# define LHASH_OF(type) struct lhash_st_##type + +# define DEFINE_LHASH_OF(type) \ + LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2; int d3; } dummy; }; \ + static ossl_unused ossl_inline LHASH_OF(type) *lh_##type##_new(unsigned long (*hfn)(const type *), \ + int (*cfn)(const type *, const type *)) \ + { \ + return (LHASH_OF(type) *) \ + OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \ + } \ + static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \ + { \ + OPENSSL_LH_free((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \ + { \ + return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \ + { \ + return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \ + } \ + static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \ + { \ + OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \ + } \ + static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \ + { \ + return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \ + } \ + static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \ + { \ + OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \ + } \ + static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \ + void (*doall)(type *)) \ + { \ + OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \ + } \ + LHASH_OF(type) + +#define IMPLEMENT_LHASH_DOALL_ARG_CONST(type, argtype) \ + int_implement_lhash_doall(type, argtype, const type) + +#define IMPLEMENT_LHASH_DOALL_ARG(type, argtype) \ + int_implement_lhash_doall(type, argtype, type) + +#define int_implement_lhash_doall(type, argtype, cbargtype) \ + static ossl_unused ossl_inline void \ + lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \ + void (*fn)(cbargtype *, argtype *), \ + argtype *arg) \ + { \ + OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); \ + } \ + LHASH_OF(type) + +DEFINE_LHASH_OF(OPENSSL_STRING); +# ifdef _MSC_VER +/* + * push and pop this warning: + * warning C4090: 'function': different 'const' qualifiers + */ +# pragma warning (push) +# pragma warning (disable: 4090) +# endif + +DEFINE_LHASH_OF(OPENSSL_CSTRING); + +# ifdef _MSC_VER +# pragma warning (pop) +# endif + +/* + * If called without higher optimization (min. -xO3) the Oracle Developer + * Studio compiler generates code for the defined (static inline) functions + * above. + * This would later lead to the linker complaining about missing symbols when + * this header file is included but the resulting object is not linked against + * the Crypto library (openssl#6912). + */ +# ifdef __SUNPRO_C +# pragma weak OPENSSL_LH_new +# pragma weak OPENSSL_LH_free +# pragma weak OPENSSL_LH_insert +# pragma weak OPENSSL_LH_delete +# pragma weak OPENSSL_LH_retrieve +# pragma weak OPENSSL_LH_error +# pragma weak OPENSSL_LH_num_items +# pragma weak OPENSSL_LH_node_stats_bio +# pragma weak OPENSSL_LH_node_usage_stats_bio +# pragma weak OPENSSL_LH_stats_bio +# pragma weak OPENSSL_LH_get_down_load +# pragma weak OPENSSL_LH_set_down_load +# pragma weak OPENSSL_LH_doall +# pragma weak OPENSSL_LH_doall_arg +# endif /* __SUNPRO_C */ + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/md2.h postgresql-hll-2.14/include/openssl/md2.h --- postgresql-hll-2.14_old/include/openssl/md2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/md2.h 2020-12-12 17:06:43.333349148 +0800 @@ -0,0 +1,44 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD2_H +# define HEADER_MD2_H + +# include + +# ifndef OPENSSL_NO_MD2 +# include +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned char MD2_INT; + +# define MD2_DIGEST_LENGTH 16 +# define MD2_BLOCK 16 + +typedef struct MD2state_st { + unsigned int num; + unsigned char data[MD2_BLOCK]; + MD2_INT cksm[MD2_BLOCK]; + MD2_INT state[MD2_BLOCK]; +} MD2_CTX; + +const char *MD2_options(void); +int MD2_Init(MD2_CTX *c); +int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len); +int MD2_Final(unsigned char *md, MD2_CTX *c); +unsigned char *MD2(const unsigned char *d, size_t n, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/md4.h postgresql-hll-2.14/include/openssl/md4.h --- postgresql-hll-2.14_old/include/openssl/md4.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/md4.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,51 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD4_H +# define HEADER_MD4_H + +# include + +# ifndef OPENSSL_NO_MD4 +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD4_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define MD4_LONG unsigned int + +# define MD4_CBLOCK 64 +# define MD4_LBLOCK (MD4_CBLOCK/4) +# define MD4_DIGEST_LENGTH 16 + +typedef struct MD4state_st { + MD4_LONG A, B, C, D; + MD4_LONG Nl, Nh; + MD4_LONG data[MD4_LBLOCK]; + unsigned int num; +} MD4_CTX; + +int MD4_Init(MD4_CTX *c); +int MD4_Update(MD4_CTX *c, const void *data, size_t len); +int MD4_Final(unsigned char *md, MD4_CTX *c); +unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); +void MD4_Transform(MD4_CTX *c, const unsigned char *b); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/md5.h postgresql-hll-2.14/include/openssl/md5.h --- postgresql-hll-2.14_old/include/openssl/md5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/md5.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,50 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MD5_H +# define HEADER_MD5_H + +# include + +# ifndef OPENSSL_NO_MD5 +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD5_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define MD5_LONG unsigned int + +# define MD5_CBLOCK 64 +# define MD5_LBLOCK (MD5_CBLOCK/4) +# define MD5_DIGEST_LENGTH 16 + +typedef struct MD5state_st { + MD5_LONG A, B, C, D; + MD5_LONG Nl, Nh; + MD5_LONG data[MD5_LBLOCK]; + unsigned int num; +} MD5_CTX; + +int MD5_Init(MD5_CTX *c); +int MD5_Update(MD5_CTX *c, const void *data, size_t len); +int MD5_Final(unsigned char *md, MD5_CTX *c); +unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); +void MD5_Transform(MD5_CTX *c, const unsigned char *b); +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/mdc2.h postgresql-hll-2.14/include/openssl/mdc2.h --- postgresql-hll-2.14_old/include/openssl/mdc2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/mdc2.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,42 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MDC2_H +# define HEADER_MDC2_H + +# include + +#ifndef OPENSSL_NO_MDC2 +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +# define MDC2_BLOCK 8 +# define MDC2_DIGEST_LENGTH 16 + +typedef struct mdc2_ctx_st { + unsigned int num; + unsigned char data[MDC2_BLOCK]; + DES_cblock h, hh; + int pad_type; /* either 1 or 2, default 1 */ +} MDC2_CTX; + +int MDC2_Init(MDC2_CTX *c); +int MDC2_Update(MDC2_CTX *c, const unsigned char *data, size_t len); +int MDC2_Final(unsigned char *md, MDC2_CTX *c); +unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/modes.h postgresql-hll-2.14/include/openssl/modes.h --- postgresql-hll-2.14_old/include/openssl/modes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/modes.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,208 @@ +/* + * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_MODES_H +# define HEADER_MODES_H + +# include + +# ifdef __cplusplus +extern "C" { +# endif +typedef void (*block128_f) (const unsigned char in[16], + unsigned char out[16], const void *key); + +typedef void (*cbc128_f) (const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int enc); + +typedef void (*ctr128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + const unsigned char ivec[16]); + +typedef void (*ccm128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + const unsigned char ivec[16], + unsigned char cmac[16]); + +void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], block128_f block); +void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], block128_f block); + +void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], + unsigned char ecount_buf[16], unsigned int *num, + block128_f block); + +void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], + unsigned char ecount_buf[16], + unsigned int *num, ctr128_f ctr); + +void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int *num, + block128_f block); + +void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); +void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out, + size_t length, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); +void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out, + size_t bits, const void *key, + unsigned char ivec[16], int *num, + int enc, block128_f block); + +size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, unsigned char ivec[16], + block128_f block); +size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); +size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, unsigned char ivec[16], + block128_f block); +size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); + +size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, + unsigned char ivec[16], + block128_f block); +size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); +size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, + unsigned char *out, size_t len, + const void *key, + unsigned char ivec[16], + block128_f block); +size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out, + size_t len, const void *key, + unsigned char ivec[16], cbc128_f cbc); + +typedef struct gcm128_context GCM128_CONTEXT; + +GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block); +void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block); +void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv, + size_t len); +int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad, + size_t len); +int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len); +int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len); +int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream); +int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, + const unsigned char *in, unsigned char *out, + size_t len, ctr128_f stream); +int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const unsigned char *tag, + size_t len); +void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len); +void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx); + +typedef struct ccm128_context CCM128_CONTEXT; + +void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, + unsigned int M, unsigned int L, void *key, + block128_f block); +int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, const unsigned char *nonce, + size_t nlen, size_t mlen); +void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, const unsigned char *aad, + size_t alen); +int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len); +int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len); +int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len, + ccm128_f stream); +int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, const unsigned char *inp, + unsigned char *out, size_t len, + ccm128_f stream); +size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len); + +typedef struct xts128_context XTS128_CONTEXT; + +int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, + const unsigned char iv[16], + const unsigned char *inp, unsigned char *out, + size_t len, int enc); + +size_t CRYPTO_128_wrap(void *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, size_t inlen, + block128_f block); + +size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv, + unsigned char *out, + const unsigned char *in, size_t inlen, + block128_f block); +size_t CRYPTO_128_wrap_pad(void *key, const unsigned char *icv, + unsigned char *out, const unsigned char *in, + size_t inlen, block128_f block); +size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv, + unsigned char *out, const unsigned char *in, + size_t inlen, block128_f block); + +# ifndef OPENSSL_NO_OCB +typedef struct ocb128_context OCB128_CONTEXT; + +typedef void (*ocb128_f) (const unsigned char *in, unsigned char *out, + size_t blocks, const void *key, + size_t start_block_num, + unsigned char offset_i[16], + const unsigned char L_[][16], + unsigned char checksum[16]); + +OCB128_CONTEXT *CRYPTO_ocb128_new(void *keyenc, void *keydec, + block128_f encrypt, block128_f decrypt, + ocb128_f stream); +int CRYPTO_ocb128_init(OCB128_CONTEXT *ctx, void *keyenc, void *keydec, + block128_f encrypt, block128_f decrypt, + ocb128_f stream); +int CRYPTO_ocb128_copy_ctx(OCB128_CONTEXT *dest, OCB128_CONTEXT *src, + void *keyenc, void *keydec); +int CRYPTO_ocb128_setiv(OCB128_CONTEXT *ctx, const unsigned char *iv, + size_t len, size_t taglen); +int CRYPTO_ocb128_aad(OCB128_CONTEXT *ctx, const unsigned char *aad, + size_t len); +int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx, const unsigned char *in, + unsigned char *out, size_t len); +int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx, const unsigned char *in, + unsigned char *out, size_t len); +int CRYPTO_ocb128_finish(OCB128_CONTEXT *ctx, const unsigned char *tag, + size_t len); +int CRYPTO_ocb128_tag(OCB128_CONTEXT *ctx, unsigned char *tag, size_t len); +void CRYPTO_ocb128_cleanup(OCB128_CONTEXT *ctx); +# endif /* OPENSSL_NO_OCB */ + +# ifdef __cplusplus +} +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/objectserr.h postgresql-hll-2.14/include/openssl/objectserr.h --- postgresql-hll-2.14_old/include/openssl/objectserr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/objectserr.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,42 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OBJERR_H +# define HEADER_OBJERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_OBJ_strings(void); + +/* + * OBJ function codes. + */ +# define OBJ_F_OBJ_ADD_OBJECT 105 +# define OBJ_F_OBJ_ADD_SIGID 107 +# define OBJ_F_OBJ_CREATE 100 +# define OBJ_F_OBJ_DUP 101 +# define OBJ_F_OBJ_NAME_NEW_INDEX 106 +# define OBJ_F_OBJ_NID2LN 102 +# define OBJ_F_OBJ_NID2OBJ 103 +# define OBJ_F_OBJ_NID2SN 104 +# define OBJ_F_OBJ_TXT2OBJ 108 + +/* + * OBJ reason codes. + */ +# define OBJ_R_OID_EXISTS 102 +# define OBJ_R_UNKNOWN_NID 101 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/objects.h postgresql-hll-2.14/include/openssl/objects.h --- postgresql-hll-2.14_old/include/openssl/objects.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/objects.h 2020-12-12 17:06:43.334349161 +0800 @@ -0,0 +1,175 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OBJECTS_H +# define HEADER_OBJECTS_H + +# include +# include +# include +# include + +# define OBJ_NAME_TYPE_UNDEF 0x00 +# define OBJ_NAME_TYPE_MD_METH 0x01 +# define OBJ_NAME_TYPE_CIPHER_METH 0x02 +# define OBJ_NAME_TYPE_PKEY_METH 0x03 +# define OBJ_NAME_TYPE_COMP_METH 0x04 +# define OBJ_NAME_TYPE_NUM 0x05 + +# define OBJ_NAME_ALIAS 0x8000 + +# define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 +# define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct obj_name_st { + int type; + int alias; + const char *name; + const char *data; +} OBJ_NAME; + +# define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) + +int OBJ_NAME_init(void); +int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), + int (*cmp_func) (const char *, const char *), + void (*free_func) (const char *, int, const char *)); +const char *OBJ_NAME_get(const char *name, int type); +int OBJ_NAME_add(const char *name, int type, const char *data); +int OBJ_NAME_remove(const char *name, int type); +void OBJ_NAME_cleanup(int type); /* -1 for everything */ +void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), + void *arg); +void OBJ_NAME_do_all_sorted(int type, + void (*fn) (const OBJ_NAME *, void *arg), + void *arg); + +ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o); +ASN1_OBJECT *OBJ_nid2obj(int n); +const char *OBJ_nid2ln(int n); +const char *OBJ_nid2sn(int n); +int OBJ_obj2nid(const ASN1_OBJECT *o); +ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); +int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); +int OBJ_txt2nid(const char *s); +int OBJ_ln2nid(const char *s); +int OBJ_sn2nid(const char *s); +int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); +const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, + int (*cmp) (const void *, const void *)); +const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, + int size, + int (*cmp) (const void *, const void *), + int flags); + +# define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ + static int nm##_cmp(type1 const *, type2 const *); \ + scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) + +# define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \ + _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp) +# define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ + type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) + +/*- + * Unsolved problem: if a type is actually a pointer type, like + * nid_triple is, then its impossible to get a const where you need + * it. Consider: + * + * typedef int nid_triple[3]; + * const void *a_; + * const nid_triple const *a = a_; + * + * The assignment discards a const because what you really want is: + * + * const int const * const *a = a_; + * + * But if you do that, you lose the fact that a is an array of 3 ints, + * which breaks comparison functions. + * + * Thus we end up having to cast, sadly, or unpack the + * declarations. Or, as I finally did in this case, declare nid_triple + * to be a struct, which it should have been in the first place. + * + * Ben, August 2008. + * + * Also, strictly speaking not all types need be const, but handling + * the non-constness means a lot of complication, and in practice + * comparison routines do always not touch their arguments. + */ + +# define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ + { \ + type1 const *a = a_; \ + type2 const *b = b_; \ + return nm##_cmp(a,b); \ + } \ + static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ + { \ + return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ + nm##_cmp_BSEARCH_CMP_FN); \ + } \ + extern void dummy_prototype(void) + +# define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ + static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ + { \ + type1 const *a = a_; \ + type2 const *b = b_; \ + return nm##_cmp(a,b); \ + } \ + type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ + { \ + return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ + nm##_cmp_BSEARCH_CMP_FN); \ + } \ + extern void dummy_prototype(void) + +# define OBJ_bsearch(type1,key,type2,base,num,cmp) \ + ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ + num,sizeof(type2), \ + ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ + (void)CHECKED_PTR_OF(type2,cmp##_type_2), \ + cmp##_BSEARCH_CMP_FN))) + +# define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \ + ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ + num,sizeof(type2), \ + ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ + (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \ + cmp##_BSEARCH_CMP_FN)),flags) + +int OBJ_new_nid(int num); +int OBJ_add_object(const ASN1_OBJECT *obj); +int OBJ_create(const char *oid, const char *sn, const char *ln); +#if OPENSSL_API_COMPAT < 0x10100000L +# define OBJ_cleanup() while(0) continue +#endif +int OBJ_create_objects(BIO *in); + +size_t OBJ_length(const ASN1_OBJECT *obj); +const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); + +int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); +int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); +int OBJ_add_sigid(int signid, int dig_id, int pkey_id); +void OBJ_sigid_free(void); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/obj_mac.h postgresql-hll-2.14/include/openssl/obj_mac.h --- postgresql-hll-2.14_old/include/openssl/obj_mac.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/obj_mac.h 2020-12-12 17:06:43.336349187 +0800 @@ -0,0 +1,5198 @@ +/* + * WARNING: do not edit! + * Generated by crypto/objects/objects.pl + * + * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved. + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#define SN_undef "UNDEF" +#define LN_undef "undefined" +#define NID_undef 0 +#define OBJ_undef 0L + +#define SN_itu_t "ITU-T" +#define LN_itu_t "itu-t" +#define NID_itu_t 645 +#define OBJ_itu_t 0L + +#define NID_ccitt 404 +#define OBJ_ccitt OBJ_itu_t + +#define SN_iso "ISO" +#define LN_iso "iso" +#define NID_iso 181 +#define OBJ_iso 1L + +#define SN_joint_iso_itu_t "JOINT-ISO-ITU-T" +#define LN_joint_iso_itu_t "joint-iso-itu-t" +#define NID_joint_iso_itu_t 646 +#define OBJ_joint_iso_itu_t 2L + +#define NID_joint_iso_ccitt 393 +#define OBJ_joint_iso_ccitt OBJ_joint_iso_itu_t + +#define SN_member_body "member-body" +#define LN_member_body "ISO Member Body" +#define NID_member_body 182 +#define OBJ_member_body OBJ_iso,2L + +#define SN_identified_organization "identified-organization" +#define NID_identified_organization 676 +#define OBJ_identified_organization OBJ_iso,3L + +#define SN_hmac_md5 "HMAC-MD5" +#define LN_hmac_md5 "hmac-md5" +#define NID_hmac_md5 780 +#define OBJ_hmac_md5 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,1L + +#define SN_hmac_sha1 "HMAC-SHA1" +#define LN_hmac_sha1 "hmac-sha1" +#define NID_hmac_sha1 781 +#define OBJ_hmac_sha1 OBJ_identified_organization,6L,1L,5L,5L,8L,1L,2L + +#define SN_x509ExtAdmission "x509ExtAdmission" +#define LN_x509ExtAdmission "Professional Information or basis for Admission" +#define NID_x509ExtAdmission 1093 +#define OBJ_x509ExtAdmission OBJ_identified_organization,36L,8L,3L,3L + +#define SN_certicom_arc "certicom-arc" +#define NID_certicom_arc 677 +#define OBJ_certicom_arc OBJ_identified_organization,132L + +#define SN_ieee "ieee" +#define NID_ieee 1170 +#define OBJ_ieee OBJ_identified_organization,111L + +#define SN_ieee_siswg "ieee-siswg" +#define LN_ieee_siswg "IEEE Security in Storage Working Group" +#define NID_ieee_siswg 1171 +#define OBJ_ieee_siswg OBJ_ieee,2L,1619L + +#define SN_international_organizations "international-organizations" +#define LN_international_organizations "International Organizations" +#define NID_international_organizations 647 +#define OBJ_international_organizations OBJ_joint_iso_itu_t,23L + +#define SN_wap "wap" +#define NID_wap 678 +#define OBJ_wap OBJ_international_organizations,43L + +#define SN_wap_wsg "wap-wsg" +#define NID_wap_wsg 679 +#define OBJ_wap_wsg OBJ_wap,1L + +#define SN_selected_attribute_types "selected-attribute-types" +#define LN_selected_attribute_types "Selected Attribute Types" +#define NID_selected_attribute_types 394 +#define OBJ_selected_attribute_types OBJ_joint_iso_itu_t,5L,1L,5L + +#define SN_clearance "clearance" +#define NID_clearance 395 +#define OBJ_clearance OBJ_selected_attribute_types,55L + +#define SN_ISO_US "ISO-US" +#define LN_ISO_US "ISO US Member Body" +#define NID_ISO_US 183 +#define OBJ_ISO_US OBJ_member_body,840L + +#define SN_X9_57 "X9-57" +#define LN_X9_57 "X9.57" +#define NID_X9_57 184 +#define OBJ_X9_57 OBJ_ISO_US,10040L + +#define SN_X9cm "X9cm" +#define LN_X9cm "X9.57 CM ?" +#define NID_X9cm 185 +#define OBJ_X9cm OBJ_X9_57,4L + +#define SN_ISO_CN "ISO-CN" +#define LN_ISO_CN "ISO CN Member Body" +#define NID_ISO_CN 1140 +#define OBJ_ISO_CN OBJ_member_body,156L + +#define SN_oscca "oscca" +#define NID_oscca 1141 +#define OBJ_oscca OBJ_ISO_CN,10197L + +#define SN_sm_scheme "sm-scheme" +#define NID_sm_scheme 1142 +#define OBJ_sm_scheme OBJ_oscca,1L + +#define SN_dsa "DSA" +#define LN_dsa "dsaEncryption" +#define NID_dsa 116 +#define OBJ_dsa OBJ_X9cm,1L + +#define SN_dsaWithSHA1 "DSA-SHA1" +#define LN_dsaWithSHA1 "dsaWithSHA1" +#define NID_dsaWithSHA1 113 +#define OBJ_dsaWithSHA1 OBJ_X9cm,3L + +#define SN_ansi_X9_62 "ansi-X9-62" +#define LN_ansi_X9_62 "ANSI X9.62" +#define NID_ansi_X9_62 405 +#define OBJ_ansi_X9_62 OBJ_ISO_US,10045L + +#define OBJ_X9_62_id_fieldType OBJ_ansi_X9_62,1L + +#define SN_X9_62_prime_field "prime-field" +#define NID_X9_62_prime_field 406 +#define OBJ_X9_62_prime_field OBJ_X9_62_id_fieldType,1L + +#define SN_X9_62_characteristic_two_field "characteristic-two-field" +#define NID_X9_62_characteristic_two_field 407 +#define OBJ_X9_62_characteristic_two_field OBJ_X9_62_id_fieldType,2L + +#define SN_X9_62_id_characteristic_two_basis "id-characteristic-two-basis" +#define NID_X9_62_id_characteristic_two_basis 680 +#define OBJ_X9_62_id_characteristic_two_basis OBJ_X9_62_characteristic_two_field,3L + +#define SN_X9_62_onBasis "onBasis" +#define NID_X9_62_onBasis 681 +#define OBJ_X9_62_onBasis OBJ_X9_62_id_characteristic_two_basis,1L + +#define SN_X9_62_tpBasis "tpBasis" +#define NID_X9_62_tpBasis 682 +#define OBJ_X9_62_tpBasis OBJ_X9_62_id_characteristic_two_basis,2L + +#define SN_X9_62_ppBasis "ppBasis" +#define NID_X9_62_ppBasis 683 +#define OBJ_X9_62_ppBasis OBJ_X9_62_id_characteristic_two_basis,3L + +#define OBJ_X9_62_id_publicKeyType OBJ_ansi_X9_62,2L + +#define SN_X9_62_id_ecPublicKey "id-ecPublicKey" +#define NID_X9_62_id_ecPublicKey 408 +#define OBJ_X9_62_id_ecPublicKey OBJ_X9_62_id_publicKeyType,1L + +#define OBJ_X9_62_ellipticCurve OBJ_ansi_X9_62,3L + +#define OBJ_X9_62_c_TwoCurve OBJ_X9_62_ellipticCurve,0L + +#define SN_X9_62_c2pnb163v1 "c2pnb163v1" +#define NID_X9_62_c2pnb163v1 684 +#define OBJ_X9_62_c2pnb163v1 OBJ_X9_62_c_TwoCurve,1L + +#define SN_X9_62_c2pnb163v2 "c2pnb163v2" +#define NID_X9_62_c2pnb163v2 685 +#define OBJ_X9_62_c2pnb163v2 OBJ_X9_62_c_TwoCurve,2L + +#define SN_X9_62_c2pnb163v3 "c2pnb163v3" +#define NID_X9_62_c2pnb163v3 686 +#define OBJ_X9_62_c2pnb163v3 OBJ_X9_62_c_TwoCurve,3L + +#define SN_X9_62_c2pnb176v1 "c2pnb176v1" +#define NID_X9_62_c2pnb176v1 687 +#define OBJ_X9_62_c2pnb176v1 OBJ_X9_62_c_TwoCurve,4L + +#define SN_X9_62_c2tnb191v1 "c2tnb191v1" +#define NID_X9_62_c2tnb191v1 688 +#define OBJ_X9_62_c2tnb191v1 OBJ_X9_62_c_TwoCurve,5L + +#define SN_X9_62_c2tnb191v2 "c2tnb191v2" +#define NID_X9_62_c2tnb191v2 689 +#define OBJ_X9_62_c2tnb191v2 OBJ_X9_62_c_TwoCurve,6L + +#define SN_X9_62_c2tnb191v3 "c2tnb191v3" +#define NID_X9_62_c2tnb191v3 690 +#define OBJ_X9_62_c2tnb191v3 OBJ_X9_62_c_TwoCurve,7L + +#define SN_X9_62_c2onb191v4 "c2onb191v4" +#define NID_X9_62_c2onb191v4 691 +#define OBJ_X9_62_c2onb191v4 OBJ_X9_62_c_TwoCurve,8L + +#define SN_X9_62_c2onb191v5 "c2onb191v5" +#define NID_X9_62_c2onb191v5 692 +#define OBJ_X9_62_c2onb191v5 OBJ_X9_62_c_TwoCurve,9L + +#define SN_X9_62_c2pnb208w1 "c2pnb208w1" +#define NID_X9_62_c2pnb208w1 693 +#define OBJ_X9_62_c2pnb208w1 OBJ_X9_62_c_TwoCurve,10L + +#define SN_X9_62_c2tnb239v1 "c2tnb239v1" +#define NID_X9_62_c2tnb239v1 694 +#define OBJ_X9_62_c2tnb239v1 OBJ_X9_62_c_TwoCurve,11L + +#define SN_X9_62_c2tnb239v2 "c2tnb239v2" +#define NID_X9_62_c2tnb239v2 695 +#define OBJ_X9_62_c2tnb239v2 OBJ_X9_62_c_TwoCurve,12L + +#define SN_X9_62_c2tnb239v3 "c2tnb239v3" +#define NID_X9_62_c2tnb239v3 696 +#define OBJ_X9_62_c2tnb239v3 OBJ_X9_62_c_TwoCurve,13L + +#define SN_X9_62_c2onb239v4 "c2onb239v4" +#define NID_X9_62_c2onb239v4 697 +#define OBJ_X9_62_c2onb239v4 OBJ_X9_62_c_TwoCurve,14L + +#define SN_X9_62_c2onb239v5 "c2onb239v5" +#define NID_X9_62_c2onb239v5 698 +#define OBJ_X9_62_c2onb239v5 OBJ_X9_62_c_TwoCurve,15L + +#define SN_X9_62_c2pnb272w1 "c2pnb272w1" +#define NID_X9_62_c2pnb272w1 699 +#define OBJ_X9_62_c2pnb272w1 OBJ_X9_62_c_TwoCurve,16L + +#define SN_X9_62_c2pnb304w1 "c2pnb304w1" +#define NID_X9_62_c2pnb304w1 700 +#define OBJ_X9_62_c2pnb304w1 OBJ_X9_62_c_TwoCurve,17L + +#define SN_X9_62_c2tnb359v1 "c2tnb359v1" +#define NID_X9_62_c2tnb359v1 701 +#define OBJ_X9_62_c2tnb359v1 OBJ_X9_62_c_TwoCurve,18L + +#define SN_X9_62_c2pnb368w1 "c2pnb368w1" +#define NID_X9_62_c2pnb368w1 702 +#define OBJ_X9_62_c2pnb368w1 OBJ_X9_62_c_TwoCurve,19L + +#define SN_X9_62_c2tnb431r1 "c2tnb431r1" +#define NID_X9_62_c2tnb431r1 703 +#define OBJ_X9_62_c2tnb431r1 OBJ_X9_62_c_TwoCurve,20L + +#define OBJ_X9_62_primeCurve OBJ_X9_62_ellipticCurve,1L + +#define SN_X9_62_prime192v1 "prime192v1" +#define NID_X9_62_prime192v1 409 +#define OBJ_X9_62_prime192v1 OBJ_X9_62_primeCurve,1L + +#define SN_X9_62_prime192v2 "prime192v2" +#define NID_X9_62_prime192v2 410 +#define OBJ_X9_62_prime192v2 OBJ_X9_62_primeCurve,2L + +#define SN_X9_62_prime192v3 "prime192v3" +#define NID_X9_62_prime192v3 411 +#define OBJ_X9_62_prime192v3 OBJ_X9_62_primeCurve,3L + +#define SN_X9_62_prime239v1 "prime239v1" +#define NID_X9_62_prime239v1 412 +#define OBJ_X9_62_prime239v1 OBJ_X9_62_primeCurve,4L + +#define SN_X9_62_prime239v2 "prime239v2" +#define NID_X9_62_prime239v2 413 +#define OBJ_X9_62_prime239v2 OBJ_X9_62_primeCurve,5L + +#define SN_X9_62_prime239v3 "prime239v3" +#define NID_X9_62_prime239v3 414 +#define OBJ_X9_62_prime239v3 OBJ_X9_62_primeCurve,6L + +#define SN_X9_62_prime256v1 "prime256v1" +#define NID_X9_62_prime256v1 415 +#define OBJ_X9_62_prime256v1 OBJ_X9_62_primeCurve,7L + +#define OBJ_X9_62_id_ecSigType OBJ_ansi_X9_62,4L + +#define SN_ecdsa_with_SHA1 "ecdsa-with-SHA1" +#define NID_ecdsa_with_SHA1 416 +#define OBJ_ecdsa_with_SHA1 OBJ_X9_62_id_ecSigType,1L + +#define SN_ecdsa_with_Recommended "ecdsa-with-Recommended" +#define NID_ecdsa_with_Recommended 791 +#define OBJ_ecdsa_with_Recommended OBJ_X9_62_id_ecSigType,2L + +#define SN_ecdsa_with_Specified "ecdsa-with-Specified" +#define NID_ecdsa_with_Specified 792 +#define OBJ_ecdsa_with_Specified OBJ_X9_62_id_ecSigType,3L + +#define SN_ecdsa_with_SHA224 "ecdsa-with-SHA224" +#define NID_ecdsa_with_SHA224 793 +#define OBJ_ecdsa_with_SHA224 OBJ_ecdsa_with_Specified,1L + +#define SN_ecdsa_with_SHA256 "ecdsa-with-SHA256" +#define NID_ecdsa_with_SHA256 794 +#define OBJ_ecdsa_with_SHA256 OBJ_ecdsa_with_Specified,2L + +#define SN_ecdsa_with_SHA384 "ecdsa-with-SHA384" +#define NID_ecdsa_with_SHA384 795 +#define OBJ_ecdsa_with_SHA384 OBJ_ecdsa_with_Specified,3L + +#define SN_ecdsa_with_SHA512 "ecdsa-with-SHA512" +#define NID_ecdsa_with_SHA512 796 +#define OBJ_ecdsa_with_SHA512 OBJ_ecdsa_with_Specified,4L + +#define OBJ_secg_ellipticCurve OBJ_certicom_arc,0L + +#define SN_secp112r1 "secp112r1" +#define NID_secp112r1 704 +#define OBJ_secp112r1 OBJ_secg_ellipticCurve,6L + +#define SN_secp112r2 "secp112r2" +#define NID_secp112r2 705 +#define OBJ_secp112r2 OBJ_secg_ellipticCurve,7L + +#define SN_secp128r1 "secp128r1" +#define NID_secp128r1 706 +#define OBJ_secp128r1 OBJ_secg_ellipticCurve,28L + +#define SN_secp128r2 "secp128r2" +#define NID_secp128r2 707 +#define OBJ_secp128r2 OBJ_secg_ellipticCurve,29L + +#define SN_secp160k1 "secp160k1" +#define NID_secp160k1 708 +#define OBJ_secp160k1 OBJ_secg_ellipticCurve,9L + +#define SN_secp160r1 "secp160r1" +#define NID_secp160r1 709 +#define OBJ_secp160r1 OBJ_secg_ellipticCurve,8L + +#define SN_secp160r2 "secp160r2" +#define NID_secp160r2 710 +#define OBJ_secp160r2 OBJ_secg_ellipticCurve,30L + +#define SN_secp192k1 "secp192k1" +#define NID_secp192k1 711 +#define OBJ_secp192k1 OBJ_secg_ellipticCurve,31L + +#define SN_secp224k1 "secp224k1" +#define NID_secp224k1 712 +#define OBJ_secp224k1 OBJ_secg_ellipticCurve,32L + +#define SN_secp224r1 "secp224r1" +#define NID_secp224r1 713 +#define OBJ_secp224r1 OBJ_secg_ellipticCurve,33L + +#define SN_secp256k1 "secp256k1" +#define NID_secp256k1 714 +#define OBJ_secp256k1 OBJ_secg_ellipticCurve,10L + +#define SN_secp384r1 "secp384r1" +#define NID_secp384r1 715 +#define OBJ_secp384r1 OBJ_secg_ellipticCurve,34L + +#define SN_secp521r1 "secp521r1" +#define NID_secp521r1 716 +#define OBJ_secp521r1 OBJ_secg_ellipticCurve,35L + +#define SN_sect113r1 "sect113r1" +#define NID_sect113r1 717 +#define OBJ_sect113r1 OBJ_secg_ellipticCurve,4L + +#define SN_sect113r2 "sect113r2" +#define NID_sect113r2 718 +#define OBJ_sect113r2 OBJ_secg_ellipticCurve,5L + +#define SN_sect131r1 "sect131r1" +#define NID_sect131r1 719 +#define OBJ_sect131r1 OBJ_secg_ellipticCurve,22L + +#define SN_sect131r2 "sect131r2" +#define NID_sect131r2 720 +#define OBJ_sect131r2 OBJ_secg_ellipticCurve,23L + +#define SN_sect163k1 "sect163k1" +#define NID_sect163k1 721 +#define OBJ_sect163k1 OBJ_secg_ellipticCurve,1L + +#define SN_sect163r1 "sect163r1" +#define NID_sect163r1 722 +#define OBJ_sect163r1 OBJ_secg_ellipticCurve,2L + +#define SN_sect163r2 "sect163r2" +#define NID_sect163r2 723 +#define OBJ_sect163r2 OBJ_secg_ellipticCurve,15L + +#define SN_sect193r1 "sect193r1" +#define NID_sect193r1 724 +#define OBJ_sect193r1 OBJ_secg_ellipticCurve,24L + +#define SN_sect193r2 "sect193r2" +#define NID_sect193r2 725 +#define OBJ_sect193r2 OBJ_secg_ellipticCurve,25L + +#define SN_sect233k1 "sect233k1" +#define NID_sect233k1 726 +#define OBJ_sect233k1 OBJ_secg_ellipticCurve,26L + +#define SN_sect233r1 "sect233r1" +#define NID_sect233r1 727 +#define OBJ_sect233r1 OBJ_secg_ellipticCurve,27L + +#define SN_sect239k1 "sect239k1" +#define NID_sect239k1 728 +#define OBJ_sect239k1 OBJ_secg_ellipticCurve,3L + +#define SN_sect283k1 "sect283k1" +#define NID_sect283k1 729 +#define OBJ_sect283k1 OBJ_secg_ellipticCurve,16L + +#define SN_sect283r1 "sect283r1" +#define NID_sect283r1 730 +#define OBJ_sect283r1 OBJ_secg_ellipticCurve,17L + +#define SN_sect409k1 "sect409k1" +#define NID_sect409k1 731 +#define OBJ_sect409k1 OBJ_secg_ellipticCurve,36L + +#define SN_sect409r1 "sect409r1" +#define NID_sect409r1 732 +#define OBJ_sect409r1 OBJ_secg_ellipticCurve,37L + +#define SN_sect571k1 "sect571k1" +#define NID_sect571k1 733 +#define OBJ_sect571k1 OBJ_secg_ellipticCurve,38L + +#define SN_sect571r1 "sect571r1" +#define NID_sect571r1 734 +#define OBJ_sect571r1 OBJ_secg_ellipticCurve,39L + +#define OBJ_wap_wsg_idm_ecid OBJ_wap_wsg,4L + +#define SN_wap_wsg_idm_ecid_wtls1 "wap-wsg-idm-ecid-wtls1" +#define NID_wap_wsg_idm_ecid_wtls1 735 +#define OBJ_wap_wsg_idm_ecid_wtls1 OBJ_wap_wsg_idm_ecid,1L + +#define SN_wap_wsg_idm_ecid_wtls3 "wap-wsg-idm-ecid-wtls3" +#define NID_wap_wsg_idm_ecid_wtls3 736 +#define OBJ_wap_wsg_idm_ecid_wtls3 OBJ_wap_wsg_idm_ecid,3L + +#define SN_wap_wsg_idm_ecid_wtls4 "wap-wsg-idm-ecid-wtls4" +#define NID_wap_wsg_idm_ecid_wtls4 737 +#define OBJ_wap_wsg_idm_ecid_wtls4 OBJ_wap_wsg_idm_ecid,4L + +#define SN_wap_wsg_idm_ecid_wtls5 "wap-wsg-idm-ecid-wtls5" +#define NID_wap_wsg_idm_ecid_wtls5 738 +#define OBJ_wap_wsg_idm_ecid_wtls5 OBJ_wap_wsg_idm_ecid,5L + +#define SN_wap_wsg_idm_ecid_wtls6 "wap-wsg-idm-ecid-wtls6" +#define NID_wap_wsg_idm_ecid_wtls6 739 +#define OBJ_wap_wsg_idm_ecid_wtls6 OBJ_wap_wsg_idm_ecid,6L + +#define SN_wap_wsg_idm_ecid_wtls7 "wap-wsg-idm-ecid-wtls7" +#define NID_wap_wsg_idm_ecid_wtls7 740 +#define OBJ_wap_wsg_idm_ecid_wtls7 OBJ_wap_wsg_idm_ecid,7L + +#define SN_wap_wsg_idm_ecid_wtls8 "wap-wsg-idm-ecid-wtls8" +#define NID_wap_wsg_idm_ecid_wtls8 741 +#define OBJ_wap_wsg_idm_ecid_wtls8 OBJ_wap_wsg_idm_ecid,8L + +#define SN_wap_wsg_idm_ecid_wtls9 "wap-wsg-idm-ecid-wtls9" +#define NID_wap_wsg_idm_ecid_wtls9 742 +#define OBJ_wap_wsg_idm_ecid_wtls9 OBJ_wap_wsg_idm_ecid,9L + +#define SN_wap_wsg_idm_ecid_wtls10 "wap-wsg-idm-ecid-wtls10" +#define NID_wap_wsg_idm_ecid_wtls10 743 +#define OBJ_wap_wsg_idm_ecid_wtls10 OBJ_wap_wsg_idm_ecid,10L + +#define SN_wap_wsg_idm_ecid_wtls11 "wap-wsg-idm-ecid-wtls11" +#define NID_wap_wsg_idm_ecid_wtls11 744 +#define OBJ_wap_wsg_idm_ecid_wtls11 OBJ_wap_wsg_idm_ecid,11L + +#define SN_wap_wsg_idm_ecid_wtls12 "wap-wsg-idm-ecid-wtls12" +#define NID_wap_wsg_idm_ecid_wtls12 745 +#define OBJ_wap_wsg_idm_ecid_wtls12 OBJ_wap_wsg_idm_ecid,12L + +#define SN_cast5_cbc "CAST5-CBC" +#define LN_cast5_cbc "cast5-cbc" +#define NID_cast5_cbc 108 +#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L + +#define SN_cast5_ecb "CAST5-ECB" +#define LN_cast5_ecb "cast5-ecb" +#define NID_cast5_ecb 109 + +#define SN_cast5_cfb64 "CAST5-CFB" +#define LN_cast5_cfb64 "cast5-cfb" +#define NID_cast5_cfb64 110 + +#define SN_cast5_ofb64 "CAST5-OFB" +#define LN_cast5_ofb64 "cast5-ofb" +#define NID_cast5_ofb64 111 + +#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" +#define NID_pbeWithMD5AndCast5_CBC 112 +#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L + +#define SN_id_PasswordBasedMAC "id-PasswordBasedMAC" +#define LN_id_PasswordBasedMAC "password based MAC" +#define NID_id_PasswordBasedMAC 782 +#define OBJ_id_PasswordBasedMAC OBJ_ISO_US,113533L,7L,66L,13L + +#define SN_id_DHBasedMac "id-DHBasedMac" +#define LN_id_DHBasedMac "Diffie-Hellman based MAC" +#define NID_id_DHBasedMac 783 +#define OBJ_id_DHBasedMac OBJ_ISO_US,113533L,7L,66L,30L + +#define SN_rsadsi "rsadsi" +#define LN_rsadsi "RSA Data Security, Inc." +#define NID_rsadsi 1 +#define OBJ_rsadsi OBJ_ISO_US,113549L + +#define SN_pkcs "pkcs" +#define LN_pkcs "RSA Data Security, Inc. PKCS" +#define NID_pkcs 2 +#define OBJ_pkcs OBJ_rsadsi,1L + +#define SN_pkcs1 "pkcs1" +#define NID_pkcs1 186 +#define OBJ_pkcs1 OBJ_pkcs,1L + +#define LN_rsaEncryption "rsaEncryption" +#define NID_rsaEncryption 6 +#define OBJ_rsaEncryption OBJ_pkcs1,1L + +#define SN_md2WithRSAEncryption "RSA-MD2" +#define LN_md2WithRSAEncryption "md2WithRSAEncryption" +#define NID_md2WithRSAEncryption 7 +#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L + +#define SN_md4WithRSAEncryption "RSA-MD4" +#define LN_md4WithRSAEncryption "md4WithRSAEncryption" +#define NID_md4WithRSAEncryption 396 +#define OBJ_md4WithRSAEncryption OBJ_pkcs1,3L + +#define SN_md5WithRSAEncryption "RSA-MD5" +#define LN_md5WithRSAEncryption "md5WithRSAEncryption" +#define NID_md5WithRSAEncryption 8 +#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L + +#define SN_sha1WithRSAEncryption "RSA-SHA1" +#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" +#define NID_sha1WithRSAEncryption 65 +#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L + +#define SN_rsaesOaep "RSAES-OAEP" +#define LN_rsaesOaep "rsaesOaep" +#define NID_rsaesOaep 919 +#define OBJ_rsaesOaep OBJ_pkcs1,7L + +#define SN_mgf1 "MGF1" +#define LN_mgf1 "mgf1" +#define NID_mgf1 911 +#define OBJ_mgf1 OBJ_pkcs1,8L + +#define SN_pSpecified "PSPECIFIED" +#define LN_pSpecified "pSpecified" +#define NID_pSpecified 935 +#define OBJ_pSpecified OBJ_pkcs1,9L + +#define SN_rsassaPss "RSASSA-PSS" +#define LN_rsassaPss "rsassaPss" +#define NID_rsassaPss 912 +#define OBJ_rsassaPss OBJ_pkcs1,10L + +#define SN_sha256WithRSAEncryption "RSA-SHA256" +#define LN_sha256WithRSAEncryption "sha256WithRSAEncryption" +#define NID_sha256WithRSAEncryption 668 +#define OBJ_sha256WithRSAEncryption OBJ_pkcs1,11L + +#define SN_sha384WithRSAEncryption "RSA-SHA384" +#define LN_sha384WithRSAEncryption "sha384WithRSAEncryption" +#define NID_sha384WithRSAEncryption 669 +#define OBJ_sha384WithRSAEncryption OBJ_pkcs1,12L + +#define SN_sha512WithRSAEncryption "RSA-SHA512" +#define LN_sha512WithRSAEncryption "sha512WithRSAEncryption" +#define NID_sha512WithRSAEncryption 670 +#define OBJ_sha512WithRSAEncryption OBJ_pkcs1,13L + +#define SN_sha224WithRSAEncryption "RSA-SHA224" +#define LN_sha224WithRSAEncryption "sha224WithRSAEncryption" +#define NID_sha224WithRSAEncryption 671 +#define OBJ_sha224WithRSAEncryption OBJ_pkcs1,14L + +#define SN_sha512_224WithRSAEncryption "RSA-SHA512/224" +#define LN_sha512_224WithRSAEncryption "sha512-224WithRSAEncryption" +#define NID_sha512_224WithRSAEncryption 1145 +#define OBJ_sha512_224WithRSAEncryption OBJ_pkcs1,15L + +#define SN_sha512_256WithRSAEncryption "RSA-SHA512/256" +#define LN_sha512_256WithRSAEncryption "sha512-256WithRSAEncryption" +#define NID_sha512_256WithRSAEncryption 1146 +#define OBJ_sha512_256WithRSAEncryption OBJ_pkcs1,16L + +#define SN_pkcs3 "pkcs3" +#define NID_pkcs3 27 +#define OBJ_pkcs3 OBJ_pkcs,3L + +#define LN_dhKeyAgreement "dhKeyAgreement" +#define NID_dhKeyAgreement 28 +#define OBJ_dhKeyAgreement OBJ_pkcs3,1L + +#define SN_pkcs5 "pkcs5" +#define NID_pkcs5 187 +#define OBJ_pkcs5 OBJ_pkcs,5L + +#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES" +#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" +#define NID_pbeWithMD2AndDES_CBC 9 +#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L + +#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES" +#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" +#define NID_pbeWithMD5AndDES_CBC 10 +#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L + +#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64" +#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +#define NID_pbeWithMD2AndRC2_CBC 168 +#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L + +#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64" +#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +#define NID_pbeWithMD5AndRC2_CBC 169 +#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L + +#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES" +#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +#define NID_pbeWithSHA1AndDES_CBC 170 +#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L + +#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64" +#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" +#define NID_pbeWithSHA1AndRC2_CBC 68 +#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L + +#define LN_id_pbkdf2 "PBKDF2" +#define NID_id_pbkdf2 69 +#define OBJ_id_pbkdf2 OBJ_pkcs5,12L + +#define LN_pbes2 "PBES2" +#define NID_pbes2 161 +#define OBJ_pbes2 OBJ_pkcs5,13L + +#define LN_pbmac1 "PBMAC1" +#define NID_pbmac1 162 +#define OBJ_pbmac1 OBJ_pkcs5,14L + +#define SN_pkcs7 "pkcs7" +#define NID_pkcs7 20 +#define OBJ_pkcs7 OBJ_pkcs,7L + +#define LN_pkcs7_data "pkcs7-data" +#define NID_pkcs7_data 21 +#define OBJ_pkcs7_data OBJ_pkcs7,1L + +#define LN_pkcs7_signed "pkcs7-signedData" +#define NID_pkcs7_signed 22 +#define OBJ_pkcs7_signed OBJ_pkcs7,2L + +#define LN_pkcs7_enveloped "pkcs7-envelopedData" +#define NID_pkcs7_enveloped 23 +#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L + +#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" +#define NID_pkcs7_signedAndEnveloped 24 +#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L + +#define LN_pkcs7_digest "pkcs7-digestData" +#define NID_pkcs7_digest 25 +#define OBJ_pkcs7_digest OBJ_pkcs7,5L + +#define LN_pkcs7_encrypted "pkcs7-encryptedData" +#define NID_pkcs7_encrypted 26 +#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L + +#define SN_pkcs9 "pkcs9" +#define NID_pkcs9 47 +#define OBJ_pkcs9 OBJ_pkcs,9L + +#define LN_pkcs9_emailAddress "emailAddress" +#define NID_pkcs9_emailAddress 48 +#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L + +#define LN_pkcs9_unstructuredName "unstructuredName" +#define NID_pkcs9_unstructuredName 49 +#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L + +#define LN_pkcs9_contentType "contentType" +#define NID_pkcs9_contentType 50 +#define OBJ_pkcs9_contentType OBJ_pkcs9,3L + +#define LN_pkcs9_messageDigest "messageDigest" +#define NID_pkcs9_messageDigest 51 +#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L + +#define LN_pkcs9_signingTime "signingTime" +#define NID_pkcs9_signingTime 52 +#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L + +#define LN_pkcs9_countersignature "countersignature" +#define NID_pkcs9_countersignature 53 +#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L + +#define LN_pkcs9_challengePassword "challengePassword" +#define NID_pkcs9_challengePassword 54 +#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L + +#define LN_pkcs9_unstructuredAddress "unstructuredAddress" +#define NID_pkcs9_unstructuredAddress 55 +#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L + +#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" +#define NID_pkcs9_extCertAttributes 56 +#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L + +#define SN_ext_req "extReq" +#define LN_ext_req "Extension Request" +#define NID_ext_req 172 +#define OBJ_ext_req OBJ_pkcs9,14L + +#define SN_SMIMECapabilities "SMIME-CAPS" +#define LN_SMIMECapabilities "S/MIME Capabilities" +#define NID_SMIMECapabilities 167 +#define OBJ_SMIMECapabilities OBJ_pkcs9,15L + +#define SN_SMIME "SMIME" +#define LN_SMIME "S/MIME" +#define NID_SMIME 188 +#define OBJ_SMIME OBJ_pkcs9,16L + +#define SN_id_smime_mod "id-smime-mod" +#define NID_id_smime_mod 189 +#define OBJ_id_smime_mod OBJ_SMIME,0L + +#define SN_id_smime_ct "id-smime-ct" +#define NID_id_smime_ct 190 +#define OBJ_id_smime_ct OBJ_SMIME,1L + +#define SN_id_smime_aa "id-smime-aa" +#define NID_id_smime_aa 191 +#define OBJ_id_smime_aa OBJ_SMIME,2L + +#define SN_id_smime_alg "id-smime-alg" +#define NID_id_smime_alg 192 +#define OBJ_id_smime_alg OBJ_SMIME,3L + +#define SN_id_smime_cd "id-smime-cd" +#define NID_id_smime_cd 193 +#define OBJ_id_smime_cd OBJ_SMIME,4L + +#define SN_id_smime_spq "id-smime-spq" +#define NID_id_smime_spq 194 +#define OBJ_id_smime_spq OBJ_SMIME,5L + +#define SN_id_smime_cti "id-smime-cti" +#define NID_id_smime_cti 195 +#define OBJ_id_smime_cti OBJ_SMIME,6L + +#define SN_id_smime_mod_cms "id-smime-mod-cms" +#define NID_id_smime_mod_cms 196 +#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L + +#define SN_id_smime_mod_ess "id-smime-mod-ess" +#define NID_id_smime_mod_ess 197 +#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L + +#define SN_id_smime_mod_oid "id-smime-mod-oid" +#define NID_id_smime_mod_oid 198 +#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L + +#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3" +#define NID_id_smime_mod_msg_v3 199 +#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L + +#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88" +#define NID_id_smime_mod_ets_eSignature_88 200 +#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L + +#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97" +#define NID_id_smime_mod_ets_eSignature_97 201 +#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L + +#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88" +#define NID_id_smime_mod_ets_eSigPolicy_88 202 +#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L + +#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97" +#define NID_id_smime_mod_ets_eSigPolicy_97 203 +#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L + +#define SN_id_smime_ct_receipt "id-smime-ct-receipt" +#define NID_id_smime_ct_receipt 204 +#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L + +#define SN_id_smime_ct_authData "id-smime-ct-authData" +#define NID_id_smime_ct_authData 205 +#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L + +#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert" +#define NID_id_smime_ct_publishCert 206 +#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L + +#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo" +#define NID_id_smime_ct_TSTInfo 207 +#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L + +#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo" +#define NID_id_smime_ct_TDTInfo 208 +#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L + +#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo" +#define NID_id_smime_ct_contentInfo 209 +#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L + +#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData" +#define NID_id_smime_ct_DVCSRequestData 210 +#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L + +#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData" +#define NID_id_smime_ct_DVCSResponseData 211 +#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L + +#define SN_id_smime_ct_compressedData "id-smime-ct-compressedData" +#define NID_id_smime_ct_compressedData 786 +#define OBJ_id_smime_ct_compressedData OBJ_id_smime_ct,9L + +#define SN_id_smime_ct_contentCollection "id-smime-ct-contentCollection" +#define NID_id_smime_ct_contentCollection 1058 +#define OBJ_id_smime_ct_contentCollection OBJ_id_smime_ct,19L + +#define SN_id_smime_ct_authEnvelopedData "id-smime-ct-authEnvelopedData" +#define NID_id_smime_ct_authEnvelopedData 1059 +#define OBJ_id_smime_ct_authEnvelopedData OBJ_id_smime_ct,23L + +#define SN_id_ct_asciiTextWithCRLF "id-ct-asciiTextWithCRLF" +#define NID_id_ct_asciiTextWithCRLF 787 +#define OBJ_id_ct_asciiTextWithCRLF OBJ_id_smime_ct,27L + +#define SN_id_ct_xml "id-ct-xml" +#define NID_id_ct_xml 1060 +#define OBJ_id_ct_xml OBJ_id_smime_ct,28L + +#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest" +#define NID_id_smime_aa_receiptRequest 212 +#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L + +#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel" +#define NID_id_smime_aa_securityLabel 213 +#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L + +#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory" +#define NID_id_smime_aa_mlExpandHistory 214 +#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L + +#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint" +#define NID_id_smime_aa_contentHint 215 +#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L + +#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest" +#define NID_id_smime_aa_msgSigDigest 216 +#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L + +#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType" +#define NID_id_smime_aa_encapContentType 217 +#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L + +#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier" +#define NID_id_smime_aa_contentIdentifier 218 +#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L + +#define SN_id_smime_aa_macValue "id-smime-aa-macValue" +#define NID_id_smime_aa_macValue 219 +#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L + +#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels" +#define NID_id_smime_aa_equivalentLabels 220 +#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L + +#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference" +#define NID_id_smime_aa_contentReference 221 +#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L + +#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref" +#define NID_id_smime_aa_encrypKeyPref 222 +#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L + +#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate" +#define NID_id_smime_aa_signingCertificate 223 +#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L + +#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts" +#define NID_id_smime_aa_smimeEncryptCerts 224 +#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L + +#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken" +#define NID_id_smime_aa_timeStampToken 225 +#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L + +#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId" +#define NID_id_smime_aa_ets_sigPolicyId 226 +#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L + +#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType" +#define NID_id_smime_aa_ets_commitmentType 227 +#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L + +#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation" +#define NID_id_smime_aa_ets_signerLocation 228 +#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L + +#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr" +#define NID_id_smime_aa_ets_signerAttr 229 +#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L + +#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert" +#define NID_id_smime_aa_ets_otherSigCert 230 +#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L + +#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp" +#define NID_id_smime_aa_ets_contentTimestamp 231 +#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L + +#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs" +#define NID_id_smime_aa_ets_CertificateRefs 232 +#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L + +#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs" +#define NID_id_smime_aa_ets_RevocationRefs 233 +#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L + +#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues" +#define NID_id_smime_aa_ets_certValues 234 +#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L + +#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues" +#define NID_id_smime_aa_ets_revocationValues 235 +#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L + +#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp" +#define NID_id_smime_aa_ets_escTimeStamp 236 +#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L + +#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp" +#define NID_id_smime_aa_ets_certCRLTimestamp 237 +#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L + +#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp" +#define NID_id_smime_aa_ets_archiveTimeStamp 238 +#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L + +#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType" +#define NID_id_smime_aa_signatureType 239 +#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L + +#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc" +#define NID_id_smime_aa_dvcs_dvc 240 +#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L + +#define SN_id_smime_aa_signingCertificateV2 "id-smime-aa-signingCertificateV2" +#define NID_id_smime_aa_signingCertificateV2 1086 +#define OBJ_id_smime_aa_signingCertificateV2 OBJ_id_smime_aa,47L + +#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES" +#define NID_id_smime_alg_ESDHwith3DES 241 +#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L + +#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2" +#define NID_id_smime_alg_ESDHwithRC2 242 +#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L + +#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap" +#define NID_id_smime_alg_3DESwrap 243 +#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L + +#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap" +#define NID_id_smime_alg_RC2wrap 244 +#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L + +#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH" +#define NID_id_smime_alg_ESDH 245 +#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L + +#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap" +#define NID_id_smime_alg_CMS3DESwrap 246 +#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L + +#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap" +#define NID_id_smime_alg_CMSRC2wrap 247 +#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L + +#define SN_id_alg_PWRI_KEK "id-alg-PWRI-KEK" +#define NID_id_alg_PWRI_KEK 893 +#define OBJ_id_alg_PWRI_KEK OBJ_id_smime_alg,9L + +#define SN_id_smime_cd_ldap "id-smime-cd-ldap" +#define NID_id_smime_cd_ldap 248 +#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L + +#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri" +#define NID_id_smime_spq_ets_sqt_uri 249 +#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L + +#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice" +#define NID_id_smime_spq_ets_sqt_unotice 250 +#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L + +#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin" +#define NID_id_smime_cti_ets_proofOfOrigin 251 +#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L + +#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt" +#define NID_id_smime_cti_ets_proofOfReceipt 252 +#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L + +#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery" +#define NID_id_smime_cti_ets_proofOfDelivery 253 +#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L + +#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender" +#define NID_id_smime_cti_ets_proofOfSender 254 +#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L + +#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval" +#define NID_id_smime_cti_ets_proofOfApproval 255 +#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L + +#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation" +#define NID_id_smime_cti_ets_proofOfCreation 256 +#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L + +#define LN_friendlyName "friendlyName" +#define NID_friendlyName 156 +#define OBJ_friendlyName OBJ_pkcs9,20L + +#define LN_localKeyID "localKeyID" +#define NID_localKeyID 157 +#define OBJ_localKeyID OBJ_pkcs9,21L + +#define SN_ms_csp_name "CSPName" +#define LN_ms_csp_name "Microsoft CSP Name" +#define NID_ms_csp_name 417 +#define OBJ_ms_csp_name 1L,3L,6L,1L,4L,1L,311L,17L,1L + +#define SN_LocalKeySet "LocalKeySet" +#define LN_LocalKeySet "Microsoft Local Key set" +#define NID_LocalKeySet 856 +#define OBJ_LocalKeySet 1L,3L,6L,1L,4L,1L,311L,17L,2L + +#define OBJ_certTypes OBJ_pkcs9,22L + +#define LN_x509Certificate "x509Certificate" +#define NID_x509Certificate 158 +#define OBJ_x509Certificate OBJ_certTypes,1L + +#define LN_sdsiCertificate "sdsiCertificate" +#define NID_sdsiCertificate 159 +#define OBJ_sdsiCertificate OBJ_certTypes,2L + +#define OBJ_crlTypes OBJ_pkcs9,23L + +#define LN_x509Crl "x509Crl" +#define NID_x509Crl 160 +#define OBJ_x509Crl OBJ_crlTypes,1L + +#define OBJ_pkcs12 OBJ_pkcs,12L + +#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L + +#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128" +#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +#define NID_pbe_WithSHA1And128BitRC4 144 +#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L + +#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40" +#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +#define NID_pbe_WithSHA1And40BitRC4 145 +#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L + +#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES" +#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L + +#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES" +#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L + +#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128" +#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +#define NID_pbe_WithSHA1And128BitRC2_CBC 148 +#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L + +#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40" +#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +#define NID_pbe_WithSHA1And40BitRC2_CBC 149 +#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L + +#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L + +#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L + +#define LN_keyBag "keyBag" +#define NID_keyBag 150 +#define OBJ_keyBag OBJ_pkcs12_BagIds,1L + +#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +#define NID_pkcs8ShroudedKeyBag 151 +#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L + +#define LN_certBag "certBag" +#define NID_certBag 152 +#define OBJ_certBag OBJ_pkcs12_BagIds,3L + +#define LN_crlBag "crlBag" +#define NID_crlBag 153 +#define OBJ_crlBag OBJ_pkcs12_BagIds,4L + +#define LN_secretBag "secretBag" +#define NID_secretBag 154 +#define OBJ_secretBag OBJ_pkcs12_BagIds,5L + +#define LN_safeContentsBag "safeContentsBag" +#define NID_safeContentsBag 155 +#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L + +#define SN_md2 "MD2" +#define LN_md2 "md2" +#define NID_md2 3 +#define OBJ_md2 OBJ_rsadsi,2L,2L + +#define SN_md4 "MD4" +#define LN_md4 "md4" +#define NID_md4 257 +#define OBJ_md4 OBJ_rsadsi,2L,4L + +#define SN_md5 "MD5" +#define LN_md5 "md5" +#define NID_md5 4 +#define OBJ_md5 OBJ_rsadsi,2L,5L + +#define SN_md5_sha1 "MD5-SHA1" +#define LN_md5_sha1 "md5-sha1" +#define NID_md5_sha1 114 + +#define LN_hmacWithMD5 "hmacWithMD5" +#define NID_hmacWithMD5 797 +#define OBJ_hmacWithMD5 OBJ_rsadsi,2L,6L + +#define LN_hmacWithSHA1 "hmacWithSHA1" +#define NID_hmacWithSHA1 163 +#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +#define SN_sm2 "SM2" +#define LN_sm2 "sm2" +#define NID_sm2 1172 +#define OBJ_sm2 OBJ_sm_scheme,301L + +#define SN_sm3 "SM3" +#define LN_sm3 "sm3" +#define NID_sm3 1143 +#define OBJ_sm3 OBJ_sm_scheme,401L + +#define SN_sm3WithRSAEncryption "RSA-SM3" +#define LN_sm3WithRSAEncryption "sm3WithRSAEncryption" +#define NID_sm3WithRSAEncryption 1144 +#define OBJ_sm3WithRSAEncryption OBJ_sm_scheme,504L + +#define LN_hmacWithSHA224 "hmacWithSHA224" +#define NID_hmacWithSHA224 798 +#define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L + +#define LN_hmacWithSHA256 "hmacWithSHA256" +#define NID_hmacWithSHA256 799 +#define OBJ_hmacWithSHA256 OBJ_rsadsi,2L,9L + +#define LN_hmacWithSHA384 "hmacWithSHA384" +#define NID_hmacWithSHA384 800 +#define OBJ_hmacWithSHA384 OBJ_rsadsi,2L,10L + +#define LN_hmacWithSHA512 "hmacWithSHA512" +#define NID_hmacWithSHA512 801 +#define OBJ_hmacWithSHA512 OBJ_rsadsi,2L,11L + +#define LN_hmacWithSHA512_224 "hmacWithSHA512-224" +#define NID_hmacWithSHA512_224 1193 +#define OBJ_hmacWithSHA512_224 OBJ_rsadsi,2L,12L + +#define LN_hmacWithSHA512_256 "hmacWithSHA512-256" +#define NID_hmacWithSHA512_256 1194 +#define OBJ_hmacWithSHA512_256 OBJ_rsadsi,2L,13L + +#define SN_rc2_cbc "RC2-CBC" +#define LN_rc2_cbc "rc2-cbc" +#define NID_rc2_cbc 37 +#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L + +#define SN_rc2_ecb "RC2-ECB" +#define LN_rc2_ecb "rc2-ecb" +#define NID_rc2_ecb 38 + +#define SN_rc2_cfb64 "RC2-CFB" +#define LN_rc2_cfb64 "rc2-cfb" +#define NID_rc2_cfb64 39 + +#define SN_rc2_ofb64 "RC2-OFB" +#define LN_rc2_ofb64 "rc2-ofb" +#define NID_rc2_ofb64 40 + +#define SN_rc2_40_cbc "RC2-40-CBC" +#define LN_rc2_40_cbc "rc2-40-cbc" +#define NID_rc2_40_cbc 98 + +#define SN_rc2_64_cbc "RC2-64-CBC" +#define LN_rc2_64_cbc "rc2-64-cbc" +#define NID_rc2_64_cbc 166 + +#define SN_rc4 "RC4" +#define LN_rc4 "rc4" +#define NID_rc4 5 +#define OBJ_rc4 OBJ_rsadsi,3L,4L + +#define SN_rc4_40 "RC4-40" +#define LN_rc4_40 "rc4-40" +#define NID_rc4_40 97 + +#define SN_des_ede3_cbc "DES-EDE3-CBC" +#define LN_des_ede3_cbc "des-ede3-cbc" +#define NID_des_ede3_cbc 44 +#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L + +#define SN_rc5_cbc "RC5-CBC" +#define LN_rc5_cbc "rc5-cbc" +#define NID_rc5_cbc 120 +#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L + +#define SN_rc5_ecb "RC5-ECB" +#define LN_rc5_ecb "rc5-ecb" +#define NID_rc5_ecb 121 + +#define SN_rc5_cfb64 "RC5-CFB" +#define LN_rc5_cfb64 "rc5-cfb" +#define NID_rc5_cfb64 122 + +#define SN_rc5_ofb64 "RC5-OFB" +#define LN_rc5_ofb64 "rc5-ofb" +#define NID_rc5_ofb64 123 + +#define SN_ms_ext_req "msExtReq" +#define LN_ms_ext_req "Microsoft Extension Request" +#define NID_ms_ext_req 171 +#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L + +#define SN_ms_code_ind "msCodeInd" +#define LN_ms_code_ind "Microsoft Individual Code Signing" +#define NID_ms_code_ind 134 +#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +#define SN_ms_code_com "msCodeCom" +#define LN_ms_code_com "Microsoft Commercial Code Signing" +#define NID_ms_code_com 135 +#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +#define SN_ms_ctl_sign "msCTLSign" +#define LN_ms_ctl_sign "Microsoft Trust List Signing" +#define NID_ms_ctl_sign 136 +#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +#define SN_ms_sgc "msSGC" +#define LN_ms_sgc "Microsoft Server Gated Crypto" +#define NID_ms_sgc 137 +#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +#define SN_ms_efs "msEFS" +#define LN_ms_efs "Microsoft Encrypted File System" +#define NID_ms_efs 138 +#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +#define SN_ms_smartcard_login "msSmartcardLogin" +#define LN_ms_smartcard_login "Microsoft Smartcard Login" +#define NID_ms_smartcard_login 648 +#define OBJ_ms_smartcard_login 1L,3L,6L,1L,4L,1L,311L,20L,2L,2L + +#define SN_ms_upn "msUPN" +#define LN_ms_upn "Microsoft User Principal Name" +#define NID_ms_upn 649 +#define OBJ_ms_upn 1L,3L,6L,1L,4L,1L,311L,20L,2L,3L + +#define SN_idea_cbc "IDEA-CBC" +#define LN_idea_cbc "idea-cbc" +#define NID_idea_cbc 34 +#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L + +#define SN_idea_ecb "IDEA-ECB" +#define LN_idea_ecb "idea-ecb" +#define NID_idea_ecb 36 + +#define SN_idea_cfb64 "IDEA-CFB" +#define LN_idea_cfb64 "idea-cfb" +#define NID_idea_cfb64 35 + +#define SN_idea_ofb64 "IDEA-OFB" +#define LN_idea_ofb64 "idea-ofb" +#define NID_idea_ofb64 46 + +#define SN_bf_cbc "BF-CBC" +#define LN_bf_cbc "bf-cbc" +#define NID_bf_cbc 91 +#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L + +#define SN_bf_ecb "BF-ECB" +#define LN_bf_ecb "bf-ecb" +#define NID_bf_ecb 92 + +#define SN_bf_cfb64 "BF-CFB" +#define LN_bf_cfb64 "bf-cfb" +#define NID_bf_cfb64 93 + +#define SN_bf_ofb64 "BF-OFB" +#define LN_bf_ofb64 "bf-ofb" +#define NID_bf_ofb64 94 + +#define SN_id_pkix "PKIX" +#define NID_id_pkix 127 +#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +#define SN_id_pkix_mod "id-pkix-mod" +#define NID_id_pkix_mod 258 +#define OBJ_id_pkix_mod OBJ_id_pkix,0L + +#define SN_id_pe "id-pe" +#define NID_id_pe 175 +#define OBJ_id_pe OBJ_id_pkix,1L + +#define SN_id_qt "id-qt" +#define NID_id_qt 259 +#define OBJ_id_qt OBJ_id_pkix,2L + +#define SN_id_kp "id-kp" +#define NID_id_kp 128 +#define OBJ_id_kp OBJ_id_pkix,3L + +#define SN_id_it "id-it" +#define NID_id_it 260 +#define OBJ_id_it OBJ_id_pkix,4L + +#define SN_id_pkip "id-pkip" +#define NID_id_pkip 261 +#define OBJ_id_pkip OBJ_id_pkix,5L + +#define SN_id_alg "id-alg" +#define NID_id_alg 262 +#define OBJ_id_alg OBJ_id_pkix,6L + +#define SN_id_cmc "id-cmc" +#define NID_id_cmc 263 +#define OBJ_id_cmc OBJ_id_pkix,7L + +#define SN_id_on "id-on" +#define NID_id_on 264 +#define OBJ_id_on OBJ_id_pkix,8L + +#define SN_id_pda "id-pda" +#define NID_id_pda 265 +#define OBJ_id_pda OBJ_id_pkix,9L + +#define SN_id_aca "id-aca" +#define NID_id_aca 266 +#define OBJ_id_aca OBJ_id_pkix,10L + +#define SN_id_qcs "id-qcs" +#define NID_id_qcs 267 +#define OBJ_id_qcs OBJ_id_pkix,11L + +#define SN_id_cct "id-cct" +#define NID_id_cct 268 +#define OBJ_id_cct OBJ_id_pkix,12L + +#define SN_id_ppl "id-ppl" +#define NID_id_ppl 662 +#define OBJ_id_ppl OBJ_id_pkix,21L + +#define SN_id_ad "id-ad" +#define NID_id_ad 176 +#define OBJ_id_ad OBJ_id_pkix,48L + +#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88" +#define NID_id_pkix1_explicit_88 269 +#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L + +#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88" +#define NID_id_pkix1_implicit_88 270 +#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L + +#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93" +#define NID_id_pkix1_explicit_93 271 +#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L + +#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93" +#define NID_id_pkix1_implicit_93 272 +#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L + +#define SN_id_mod_crmf "id-mod-crmf" +#define NID_id_mod_crmf 273 +#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L + +#define SN_id_mod_cmc "id-mod-cmc" +#define NID_id_mod_cmc 274 +#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L + +#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88" +#define NID_id_mod_kea_profile_88 275 +#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L + +#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93" +#define NID_id_mod_kea_profile_93 276 +#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L + +#define SN_id_mod_cmp "id-mod-cmp" +#define NID_id_mod_cmp 277 +#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L + +#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88" +#define NID_id_mod_qualified_cert_88 278 +#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L + +#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93" +#define NID_id_mod_qualified_cert_93 279 +#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L + +#define SN_id_mod_attribute_cert "id-mod-attribute-cert" +#define NID_id_mod_attribute_cert 280 +#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L + +#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol" +#define NID_id_mod_timestamp_protocol 281 +#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L + +#define SN_id_mod_ocsp "id-mod-ocsp" +#define NID_id_mod_ocsp 282 +#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L + +#define SN_id_mod_dvcs "id-mod-dvcs" +#define NID_id_mod_dvcs 283 +#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L + +#define SN_id_mod_cmp2000 "id-mod-cmp2000" +#define NID_id_mod_cmp2000 284 +#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L + +#define SN_info_access "authorityInfoAccess" +#define LN_info_access "Authority Information Access" +#define NID_info_access 177 +#define OBJ_info_access OBJ_id_pe,1L + +#define SN_biometricInfo "biometricInfo" +#define LN_biometricInfo "Biometric Info" +#define NID_biometricInfo 285 +#define OBJ_biometricInfo OBJ_id_pe,2L + +#define SN_qcStatements "qcStatements" +#define NID_qcStatements 286 +#define OBJ_qcStatements OBJ_id_pe,3L + +#define SN_ac_auditEntity "ac-auditEntity" +#define NID_ac_auditEntity 287 +#define OBJ_ac_auditEntity OBJ_id_pe,4L + +#define SN_ac_targeting "ac-targeting" +#define NID_ac_targeting 288 +#define OBJ_ac_targeting OBJ_id_pe,5L + +#define SN_aaControls "aaControls" +#define NID_aaControls 289 +#define OBJ_aaControls OBJ_id_pe,6L + +#define SN_sbgp_ipAddrBlock "sbgp-ipAddrBlock" +#define NID_sbgp_ipAddrBlock 290 +#define OBJ_sbgp_ipAddrBlock OBJ_id_pe,7L + +#define SN_sbgp_autonomousSysNum "sbgp-autonomousSysNum" +#define NID_sbgp_autonomousSysNum 291 +#define OBJ_sbgp_autonomousSysNum OBJ_id_pe,8L + +#define SN_sbgp_routerIdentifier "sbgp-routerIdentifier" +#define NID_sbgp_routerIdentifier 292 +#define OBJ_sbgp_routerIdentifier OBJ_id_pe,9L + +#define SN_ac_proxying "ac-proxying" +#define NID_ac_proxying 397 +#define OBJ_ac_proxying OBJ_id_pe,10L + +#define SN_sinfo_access "subjectInfoAccess" +#define LN_sinfo_access "Subject Information Access" +#define NID_sinfo_access 398 +#define OBJ_sinfo_access OBJ_id_pe,11L + +#define SN_proxyCertInfo "proxyCertInfo" +#define LN_proxyCertInfo "Proxy Certificate Information" +#define NID_proxyCertInfo 663 +#define OBJ_proxyCertInfo OBJ_id_pe,14L + +#define SN_tlsfeature "tlsfeature" +#define LN_tlsfeature "TLS Feature" +#define NID_tlsfeature 1020 +#define OBJ_tlsfeature OBJ_id_pe,24L + +#define SN_id_qt_cps "id-qt-cps" +#define LN_id_qt_cps "Policy Qualifier CPS" +#define NID_id_qt_cps 164 +#define OBJ_id_qt_cps OBJ_id_qt,1L + +#define SN_id_qt_unotice "id-qt-unotice" +#define LN_id_qt_unotice "Policy Qualifier User Notice" +#define NID_id_qt_unotice 165 +#define OBJ_id_qt_unotice OBJ_id_qt,2L + +#define SN_textNotice "textNotice" +#define NID_textNotice 293 +#define OBJ_textNotice OBJ_id_qt,3L + +#define SN_server_auth "serverAuth" +#define LN_server_auth "TLS Web Server Authentication" +#define NID_server_auth 129 +#define OBJ_server_auth OBJ_id_kp,1L + +#define SN_client_auth "clientAuth" +#define LN_client_auth "TLS Web Client Authentication" +#define NID_client_auth 130 +#define OBJ_client_auth OBJ_id_kp,2L + +#define SN_code_sign "codeSigning" +#define LN_code_sign "Code Signing" +#define NID_code_sign 131 +#define OBJ_code_sign OBJ_id_kp,3L + +#define SN_email_protect "emailProtection" +#define LN_email_protect "E-mail Protection" +#define NID_email_protect 132 +#define OBJ_email_protect OBJ_id_kp,4L + +#define SN_ipsecEndSystem "ipsecEndSystem" +#define LN_ipsecEndSystem "IPSec End System" +#define NID_ipsecEndSystem 294 +#define OBJ_ipsecEndSystem OBJ_id_kp,5L + +#define SN_ipsecTunnel "ipsecTunnel" +#define LN_ipsecTunnel "IPSec Tunnel" +#define NID_ipsecTunnel 295 +#define OBJ_ipsecTunnel OBJ_id_kp,6L + +#define SN_ipsecUser "ipsecUser" +#define LN_ipsecUser "IPSec User" +#define NID_ipsecUser 296 +#define OBJ_ipsecUser OBJ_id_kp,7L + +#define SN_time_stamp "timeStamping" +#define LN_time_stamp "Time Stamping" +#define NID_time_stamp 133 +#define OBJ_time_stamp OBJ_id_kp,8L + +#define SN_OCSP_sign "OCSPSigning" +#define LN_OCSP_sign "OCSP Signing" +#define NID_OCSP_sign 180 +#define OBJ_OCSP_sign OBJ_id_kp,9L + +#define SN_dvcs "DVCS" +#define LN_dvcs "dvcs" +#define NID_dvcs 297 +#define OBJ_dvcs OBJ_id_kp,10L + +#define SN_ipsec_IKE "ipsecIKE" +#define LN_ipsec_IKE "ipsec Internet Key Exchange" +#define NID_ipsec_IKE 1022 +#define OBJ_ipsec_IKE OBJ_id_kp,17L + +#define SN_capwapAC "capwapAC" +#define LN_capwapAC "Ctrl/provision WAP Access" +#define NID_capwapAC 1023 +#define OBJ_capwapAC OBJ_id_kp,18L + +#define SN_capwapWTP "capwapWTP" +#define LN_capwapWTP "Ctrl/Provision WAP Termination" +#define NID_capwapWTP 1024 +#define OBJ_capwapWTP OBJ_id_kp,19L + +#define SN_sshClient "secureShellClient" +#define LN_sshClient "SSH Client" +#define NID_sshClient 1025 +#define OBJ_sshClient OBJ_id_kp,21L + +#define SN_sshServer "secureShellServer" +#define LN_sshServer "SSH Server" +#define NID_sshServer 1026 +#define OBJ_sshServer OBJ_id_kp,22L + +#define SN_sendRouter "sendRouter" +#define LN_sendRouter "Send Router" +#define NID_sendRouter 1027 +#define OBJ_sendRouter OBJ_id_kp,23L + +#define SN_sendProxiedRouter "sendProxiedRouter" +#define LN_sendProxiedRouter "Send Proxied Router" +#define NID_sendProxiedRouter 1028 +#define OBJ_sendProxiedRouter OBJ_id_kp,24L + +#define SN_sendOwner "sendOwner" +#define LN_sendOwner "Send Owner" +#define NID_sendOwner 1029 +#define OBJ_sendOwner OBJ_id_kp,25L + +#define SN_sendProxiedOwner "sendProxiedOwner" +#define LN_sendProxiedOwner "Send Proxied Owner" +#define NID_sendProxiedOwner 1030 +#define OBJ_sendProxiedOwner OBJ_id_kp,26L + +#define SN_cmcCA "cmcCA" +#define LN_cmcCA "CMC Certificate Authority" +#define NID_cmcCA 1131 +#define OBJ_cmcCA OBJ_id_kp,27L + +#define SN_cmcRA "cmcRA" +#define LN_cmcRA "CMC Registration Authority" +#define NID_cmcRA 1132 +#define OBJ_cmcRA OBJ_id_kp,28L + +#define SN_id_it_caProtEncCert "id-it-caProtEncCert" +#define NID_id_it_caProtEncCert 298 +#define OBJ_id_it_caProtEncCert OBJ_id_it,1L + +#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes" +#define NID_id_it_signKeyPairTypes 299 +#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L + +#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes" +#define NID_id_it_encKeyPairTypes 300 +#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L + +#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg" +#define NID_id_it_preferredSymmAlg 301 +#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L + +#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo" +#define NID_id_it_caKeyUpdateInfo 302 +#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L + +#define SN_id_it_currentCRL "id-it-currentCRL" +#define NID_id_it_currentCRL 303 +#define OBJ_id_it_currentCRL OBJ_id_it,6L + +#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs" +#define NID_id_it_unsupportedOIDs 304 +#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L + +#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest" +#define NID_id_it_subscriptionRequest 305 +#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L + +#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse" +#define NID_id_it_subscriptionResponse 306 +#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L + +#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq" +#define NID_id_it_keyPairParamReq 307 +#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L + +#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep" +#define NID_id_it_keyPairParamRep 308 +#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L + +#define SN_id_it_revPassphrase "id-it-revPassphrase" +#define NID_id_it_revPassphrase 309 +#define OBJ_id_it_revPassphrase OBJ_id_it,12L + +#define SN_id_it_implicitConfirm "id-it-implicitConfirm" +#define NID_id_it_implicitConfirm 310 +#define OBJ_id_it_implicitConfirm OBJ_id_it,13L + +#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime" +#define NID_id_it_confirmWaitTime 311 +#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L + +#define SN_id_it_origPKIMessage "id-it-origPKIMessage" +#define NID_id_it_origPKIMessage 312 +#define OBJ_id_it_origPKIMessage OBJ_id_it,15L + +#define SN_id_it_suppLangTags "id-it-suppLangTags" +#define NID_id_it_suppLangTags 784 +#define OBJ_id_it_suppLangTags OBJ_id_it,16L + +#define SN_id_regCtrl "id-regCtrl" +#define NID_id_regCtrl 313 +#define OBJ_id_regCtrl OBJ_id_pkip,1L + +#define SN_id_regInfo "id-regInfo" +#define NID_id_regInfo 314 +#define OBJ_id_regInfo OBJ_id_pkip,2L + +#define SN_id_regCtrl_regToken "id-regCtrl-regToken" +#define NID_id_regCtrl_regToken 315 +#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L + +#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator" +#define NID_id_regCtrl_authenticator 316 +#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L + +#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo" +#define NID_id_regCtrl_pkiPublicationInfo 317 +#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L + +#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions" +#define NID_id_regCtrl_pkiArchiveOptions 318 +#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L + +#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID" +#define NID_id_regCtrl_oldCertID 319 +#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L + +#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey" +#define NID_id_regCtrl_protocolEncrKey 320 +#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L + +#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs" +#define NID_id_regInfo_utf8Pairs 321 +#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L + +#define SN_id_regInfo_certReq "id-regInfo-certReq" +#define NID_id_regInfo_certReq 322 +#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L + +#define SN_id_alg_des40 "id-alg-des40" +#define NID_id_alg_des40 323 +#define OBJ_id_alg_des40 OBJ_id_alg,1L + +#define SN_id_alg_noSignature "id-alg-noSignature" +#define NID_id_alg_noSignature 324 +#define OBJ_id_alg_noSignature OBJ_id_alg,2L + +#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1" +#define NID_id_alg_dh_sig_hmac_sha1 325 +#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L + +#define SN_id_alg_dh_pop "id-alg-dh-pop" +#define NID_id_alg_dh_pop 326 +#define OBJ_id_alg_dh_pop OBJ_id_alg,4L + +#define SN_id_cmc_statusInfo "id-cmc-statusInfo" +#define NID_id_cmc_statusInfo 327 +#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L + +#define SN_id_cmc_identification "id-cmc-identification" +#define NID_id_cmc_identification 328 +#define OBJ_id_cmc_identification OBJ_id_cmc,2L + +#define SN_id_cmc_identityProof "id-cmc-identityProof" +#define NID_id_cmc_identityProof 329 +#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L + +#define SN_id_cmc_dataReturn "id-cmc-dataReturn" +#define NID_id_cmc_dataReturn 330 +#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L + +#define SN_id_cmc_transactionId "id-cmc-transactionId" +#define NID_id_cmc_transactionId 331 +#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L + +#define SN_id_cmc_senderNonce "id-cmc-senderNonce" +#define NID_id_cmc_senderNonce 332 +#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L + +#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce" +#define NID_id_cmc_recipientNonce 333 +#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L + +#define SN_id_cmc_addExtensions "id-cmc-addExtensions" +#define NID_id_cmc_addExtensions 334 +#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L + +#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP" +#define NID_id_cmc_encryptedPOP 335 +#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L + +#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP" +#define NID_id_cmc_decryptedPOP 336 +#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L + +#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness" +#define NID_id_cmc_lraPOPWitness 337 +#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L + +#define SN_id_cmc_getCert "id-cmc-getCert" +#define NID_id_cmc_getCert 338 +#define OBJ_id_cmc_getCert OBJ_id_cmc,15L + +#define SN_id_cmc_getCRL "id-cmc-getCRL" +#define NID_id_cmc_getCRL 339 +#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L + +#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest" +#define NID_id_cmc_revokeRequest 340 +#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L + +#define SN_id_cmc_regInfo "id-cmc-regInfo" +#define NID_id_cmc_regInfo 341 +#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L + +#define SN_id_cmc_responseInfo "id-cmc-responseInfo" +#define NID_id_cmc_responseInfo 342 +#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L + +#define SN_id_cmc_queryPending "id-cmc-queryPending" +#define NID_id_cmc_queryPending 343 +#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L + +#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom" +#define NID_id_cmc_popLinkRandom 344 +#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L + +#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness" +#define NID_id_cmc_popLinkWitness 345 +#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L + +#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance" +#define NID_id_cmc_confirmCertAcceptance 346 +#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L + +#define SN_id_on_personalData "id-on-personalData" +#define NID_id_on_personalData 347 +#define OBJ_id_on_personalData OBJ_id_on,1L + +#define SN_id_on_permanentIdentifier "id-on-permanentIdentifier" +#define LN_id_on_permanentIdentifier "Permanent Identifier" +#define NID_id_on_permanentIdentifier 858 +#define OBJ_id_on_permanentIdentifier OBJ_id_on,3L + +#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth" +#define NID_id_pda_dateOfBirth 348 +#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L + +#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth" +#define NID_id_pda_placeOfBirth 349 +#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L + +#define SN_id_pda_gender "id-pda-gender" +#define NID_id_pda_gender 351 +#define OBJ_id_pda_gender OBJ_id_pda,3L + +#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship" +#define NID_id_pda_countryOfCitizenship 352 +#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,4L + +#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence" +#define NID_id_pda_countryOfResidence 353 +#define OBJ_id_pda_countryOfResidence OBJ_id_pda,5L + +#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo" +#define NID_id_aca_authenticationInfo 354 +#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L + +#define SN_id_aca_accessIdentity "id-aca-accessIdentity" +#define NID_id_aca_accessIdentity 355 +#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L + +#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity" +#define NID_id_aca_chargingIdentity 356 +#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L + +#define SN_id_aca_group "id-aca-group" +#define NID_id_aca_group 357 +#define OBJ_id_aca_group OBJ_id_aca,4L + +#define SN_id_aca_role "id-aca-role" +#define NID_id_aca_role 358 +#define OBJ_id_aca_role OBJ_id_aca,5L + +#define SN_id_aca_encAttrs "id-aca-encAttrs" +#define NID_id_aca_encAttrs 399 +#define OBJ_id_aca_encAttrs OBJ_id_aca,6L + +#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1" +#define NID_id_qcs_pkixQCSyntax_v1 359 +#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L + +#define SN_id_cct_crs "id-cct-crs" +#define NID_id_cct_crs 360 +#define OBJ_id_cct_crs OBJ_id_cct,1L + +#define SN_id_cct_PKIData "id-cct-PKIData" +#define NID_id_cct_PKIData 361 +#define OBJ_id_cct_PKIData OBJ_id_cct,2L + +#define SN_id_cct_PKIResponse "id-cct-PKIResponse" +#define NID_id_cct_PKIResponse 362 +#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L + +#define SN_id_ppl_anyLanguage "id-ppl-anyLanguage" +#define LN_id_ppl_anyLanguage "Any language" +#define NID_id_ppl_anyLanguage 664 +#define OBJ_id_ppl_anyLanguage OBJ_id_ppl,0L + +#define SN_id_ppl_inheritAll "id-ppl-inheritAll" +#define LN_id_ppl_inheritAll "Inherit all" +#define NID_id_ppl_inheritAll 665 +#define OBJ_id_ppl_inheritAll OBJ_id_ppl,1L + +#define SN_Independent "id-ppl-independent" +#define LN_Independent "Independent" +#define NID_Independent 667 +#define OBJ_Independent OBJ_id_ppl,2L + +#define SN_ad_OCSP "OCSP" +#define LN_ad_OCSP "OCSP" +#define NID_ad_OCSP 178 +#define OBJ_ad_OCSP OBJ_id_ad,1L + +#define SN_ad_ca_issuers "caIssuers" +#define LN_ad_ca_issuers "CA Issuers" +#define NID_ad_ca_issuers 179 +#define OBJ_ad_ca_issuers OBJ_id_ad,2L + +#define SN_ad_timeStamping "ad_timestamping" +#define LN_ad_timeStamping "AD Time Stamping" +#define NID_ad_timeStamping 363 +#define OBJ_ad_timeStamping OBJ_id_ad,3L + +#define SN_ad_dvcs "AD_DVCS" +#define LN_ad_dvcs "ad dvcs" +#define NID_ad_dvcs 364 +#define OBJ_ad_dvcs OBJ_id_ad,4L + +#define SN_caRepository "caRepository" +#define LN_caRepository "CA Repository" +#define NID_caRepository 785 +#define OBJ_caRepository OBJ_id_ad,5L + +#define OBJ_id_pkix_OCSP OBJ_ad_OCSP + +#define SN_id_pkix_OCSP_basic "basicOCSPResponse" +#define LN_id_pkix_OCSP_basic "Basic OCSP Response" +#define NID_id_pkix_OCSP_basic 365 +#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L + +#define SN_id_pkix_OCSP_Nonce "Nonce" +#define LN_id_pkix_OCSP_Nonce "OCSP Nonce" +#define NID_id_pkix_OCSP_Nonce 366 +#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L + +#define SN_id_pkix_OCSP_CrlID "CrlID" +#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID" +#define NID_id_pkix_OCSP_CrlID 367 +#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L + +#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses" +#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses" +#define NID_id_pkix_OCSP_acceptableResponses 368 +#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L + +#define SN_id_pkix_OCSP_noCheck "noCheck" +#define LN_id_pkix_OCSP_noCheck "OCSP No Check" +#define NID_id_pkix_OCSP_noCheck 369 +#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L + +#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff" +#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff" +#define NID_id_pkix_OCSP_archiveCutoff 370 +#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L + +#define SN_id_pkix_OCSP_serviceLocator "serviceLocator" +#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator" +#define NID_id_pkix_OCSP_serviceLocator 371 +#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L + +#define SN_id_pkix_OCSP_extendedStatus "extendedStatus" +#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status" +#define NID_id_pkix_OCSP_extendedStatus 372 +#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L + +#define SN_id_pkix_OCSP_valid "valid" +#define NID_id_pkix_OCSP_valid 373 +#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L + +#define SN_id_pkix_OCSP_path "path" +#define NID_id_pkix_OCSP_path 374 +#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L + +#define SN_id_pkix_OCSP_trustRoot "trustRoot" +#define LN_id_pkix_OCSP_trustRoot "Trust Root" +#define NID_id_pkix_OCSP_trustRoot 375 +#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L + +#define SN_algorithm "algorithm" +#define LN_algorithm "algorithm" +#define NID_algorithm 376 +#define OBJ_algorithm 1L,3L,14L,3L,2L + +#define SN_md5WithRSA "RSA-NP-MD5" +#define LN_md5WithRSA "md5WithRSA" +#define NID_md5WithRSA 104 +#define OBJ_md5WithRSA OBJ_algorithm,3L + +#define SN_des_ecb "DES-ECB" +#define LN_des_ecb "des-ecb" +#define NID_des_ecb 29 +#define OBJ_des_ecb OBJ_algorithm,6L + +#define SN_des_cbc "DES-CBC" +#define LN_des_cbc "des-cbc" +#define NID_des_cbc 31 +#define OBJ_des_cbc OBJ_algorithm,7L + +#define SN_des_ofb64 "DES-OFB" +#define LN_des_ofb64 "des-ofb" +#define NID_des_ofb64 45 +#define OBJ_des_ofb64 OBJ_algorithm,8L + +#define SN_des_cfb64 "DES-CFB" +#define LN_des_cfb64 "des-cfb" +#define NID_des_cfb64 30 +#define OBJ_des_cfb64 OBJ_algorithm,9L + +#define SN_rsaSignature "rsaSignature" +#define NID_rsaSignature 377 +#define OBJ_rsaSignature OBJ_algorithm,11L + +#define SN_dsa_2 "DSA-old" +#define LN_dsa_2 "dsaEncryption-old" +#define NID_dsa_2 67 +#define OBJ_dsa_2 OBJ_algorithm,12L + +#define SN_dsaWithSHA "DSA-SHA" +#define LN_dsaWithSHA "dsaWithSHA" +#define NID_dsaWithSHA 66 +#define OBJ_dsaWithSHA OBJ_algorithm,13L + +#define SN_shaWithRSAEncryption "RSA-SHA" +#define LN_shaWithRSAEncryption "shaWithRSAEncryption" +#define NID_shaWithRSAEncryption 42 +#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L + +#define SN_des_ede_ecb "DES-EDE" +#define LN_des_ede_ecb "des-ede" +#define NID_des_ede_ecb 32 +#define OBJ_des_ede_ecb OBJ_algorithm,17L + +#define SN_des_ede3_ecb "DES-EDE3" +#define LN_des_ede3_ecb "des-ede3" +#define NID_des_ede3_ecb 33 + +#define SN_des_ede_cbc "DES-EDE-CBC" +#define LN_des_ede_cbc "des-ede-cbc" +#define NID_des_ede_cbc 43 + +#define SN_des_ede_cfb64 "DES-EDE-CFB" +#define LN_des_ede_cfb64 "des-ede-cfb" +#define NID_des_ede_cfb64 60 + +#define SN_des_ede3_cfb64 "DES-EDE3-CFB" +#define LN_des_ede3_cfb64 "des-ede3-cfb" +#define NID_des_ede3_cfb64 61 + +#define SN_des_ede_ofb64 "DES-EDE-OFB" +#define LN_des_ede_ofb64 "des-ede-ofb" +#define NID_des_ede_ofb64 62 + +#define SN_des_ede3_ofb64 "DES-EDE3-OFB" +#define LN_des_ede3_ofb64 "des-ede3-ofb" +#define NID_des_ede3_ofb64 63 + +#define SN_desx_cbc "DESX-CBC" +#define LN_desx_cbc "desx-cbc" +#define NID_desx_cbc 80 + +#define SN_sha "SHA" +#define LN_sha "sha" +#define NID_sha 41 +#define OBJ_sha OBJ_algorithm,18L + +#define SN_sha1 "SHA1" +#define LN_sha1 "sha1" +#define NID_sha1 64 +#define OBJ_sha1 OBJ_algorithm,26L + +#define SN_dsaWithSHA1_2 "DSA-SHA1-old" +#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" +#define NID_dsaWithSHA1_2 70 +#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L + +#define SN_sha1WithRSA "RSA-SHA1-2" +#define LN_sha1WithRSA "sha1WithRSA" +#define NID_sha1WithRSA 115 +#define OBJ_sha1WithRSA OBJ_algorithm,29L + +#define SN_ripemd160 "RIPEMD160" +#define LN_ripemd160 "ripemd160" +#define NID_ripemd160 117 +#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L + +#define SN_ripemd160WithRSA "RSA-RIPEMD160" +#define LN_ripemd160WithRSA "ripemd160WithRSA" +#define NID_ripemd160WithRSA 119 +#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L + +#define SN_blake2b512 "BLAKE2b512" +#define LN_blake2b512 "blake2b512" +#define NID_blake2b512 1056 +#define OBJ_blake2b512 1L,3L,6L,1L,4L,1L,1722L,12L,2L,1L,16L + +#define SN_blake2s256 "BLAKE2s256" +#define LN_blake2s256 "blake2s256" +#define NID_blake2s256 1057 +#define OBJ_blake2s256 1L,3L,6L,1L,4L,1L,1722L,12L,2L,2L,8L + +#define SN_sxnet "SXNetID" +#define LN_sxnet "Strong Extranet ID" +#define NID_sxnet 143 +#define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +#define SN_X500 "X500" +#define LN_X500 "directory services (X.500)" +#define NID_X500 11 +#define OBJ_X500 2L,5L + +#define SN_X509 "X509" +#define NID_X509 12 +#define OBJ_X509 OBJ_X500,4L + +#define SN_commonName "CN" +#define LN_commonName "commonName" +#define NID_commonName 13 +#define OBJ_commonName OBJ_X509,3L + +#define SN_surname "SN" +#define LN_surname "surname" +#define NID_surname 100 +#define OBJ_surname OBJ_X509,4L + +#define LN_serialNumber "serialNumber" +#define NID_serialNumber 105 +#define OBJ_serialNumber OBJ_X509,5L + +#define SN_countryName "C" +#define LN_countryName "countryName" +#define NID_countryName 14 +#define OBJ_countryName OBJ_X509,6L + +#define SN_localityName "L" +#define LN_localityName "localityName" +#define NID_localityName 15 +#define OBJ_localityName OBJ_X509,7L + +#define SN_stateOrProvinceName "ST" +#define LN_stateOrProvinceName "stateOrProvinceName" +#define NID_stateOrProvinceName 16 +#define OBJ_stateOrProvinceName OBJ_X509,8L + +#define SN_streetAddress "street" +#define LN_streetAddress "streetAddress" +#define NID_streetAddress 660 +#define OBJ_streetAddress OBJ_X509,9L + +#define SN_organizationName "O" +#define LN_organizationName "organizationName" +#define NID_organizationName 17 +#define OBJ_organizationName OBJ_X509,10L + +#define SN_organizationalUnitName "OU" +#define LN_organizationalUnitName "organizationalUnitName" +#define NID_organizationalUnitName 18 +#define OBJ_organizationalUnitName OBJ_X509,11L + +#define SN_title "title" +#define LN_title "title" +#define NID_title 106 +#define OBJ_title OBJ_X509,12L + +#define LN_description "description" +#define NID_description 107 +#define OBJ_description OBJ_X509,13L + +#define LN_searchGuide "searchGuide" +#define NID_searchGuide 859 +#define OBJ_searchGuide OBJ_X509,14L + +#define LN_businessCategory "businessCategory" +#define NID_businessCategory 860 +#define OBJ_businessCategory OBJ_X509,15L + +#define LN_postalAddress "postalAddress" +#define NID_postalAddress 861 +#define OBJ_postalAddress OBJ_X509,16L + +#define LN_postalCode "postalCode" +#define NID_postalCode 661 +#define OBJ_postalCode OBJ_X509,17L + +#define LN_postOfficeBox "postOfficeBox" +#define NID_postOfficeBox 862 +#define OBJ_postOfficeBox OBJ_X509,18L + +#define LN_physicalDeliveryOfficeName "physicalDeliveryOfficeName" +#define NID_physicalDeliveryOfficeName 863 +#define OBJ_physicalDeliveryOfficeName OBJ_X509,19L + +#define LN_telephoneNumber "telephoneNumber" +#define NID_telephoneNumber 864 +#define OBJ_telephoneNumber OBJ_X509,20L + +#define LN_telexNumber "telexNumber" +#define NID_telexNumber 865 +#define OBJ_telexNumber OBJ_X509,21L + +#define LN_teletexTerminalIdentifier "teletexTerminalIdentifier" +#define NID_teletexTerminalIdentifier 866 +#define OBJ_teletexTerminalIdentifier OBJ_X509,22L + +#define LN_facsimileTelephoneNumber "facsimileTelephoneNumber" +#define NID_facsimileTelephoneNumber 867 +#define OBJ_facsimileTelephoneNumber OBJ_X509,23L + +#define LN_x121Address "x121Address" +#define NID_x121Address 868 +#define OBJ_x121Address OBJ_X509,24L + +#define LN_internationaliSDNNumber "internationaliSDNNumber" +#define NID_internationaliSDNNumber 869 +#define OBJ_internationaliSDNNumber OBJ_X509,25L + +#define LN_registeredAddress "registeredAddress" +#define NID_registeredAddress 870 +#define OBJ_registeredAddress OBJ_X509,26L + +#define LN_destinationIndicator "destinationIndicator" +#define NID_destinationIndicator 871 +#define OBJ_destinationIndicator OBJ_X509,27L + +#define LN_preferredDeliveryMethod "preferredDeliveryMethod" +#define NID_preferredDeliveryMethod 872 +#define OBJ_preferredDeliveryMethod OBJ_X509,28L + +#define LN_presentationAddress "presentationAddress" +#define NID_presentationAddress 873 +#define OBJ_presentationAddress OBJ_X509,29L + +#define LN_supportedApplicationContext "supportedApplicationContext" +#define NID_supportedApplicationContext 874 +#define OBJ_supportedApplicationContext OBJ_X509,30L + +#define SN_member "member" +#define NID_member 875 +#define OBJ_member OBJ_X509,31L + +#define SN_owner "owner" +#define NID_owner 876 +#define OBJ_owner OBJ_X509,32L + +#define LN_roleOccupant "roleOccupant" +#define NID_roleOccupant 877 +#define OBJ_roleOccupant OBJ_X509,33L + +#define SN_seeAlso "seeAlso" +#define NID_seeAlso 878 +#define OBJ_seeAlso OBJ_X509,34L + +#define LN_userPassword "userPassword" +#define NID_userPassword 879 +#define OBJ_userPassword OBJ_X509,35L + +#define LN_userCertificate "userCertificate" +#define NID_userCertificate 880 +#define OBJ_userCertificate OBJ_X509,36L + +#define LN_cACertificate "cACertificate" +#define NID_cACertificate 881 +#define OBJ_cACertificate OBJ_X509,37L + +#define LN_authorityRevocationList "authorityRevocationList" +#define NID_authorityRevocationList 882 +#define OBJ_authorityRevocationList OBJ_X509,38L + +#define LN_certificateRevocationList "certificateRevocationList" +#define NID_certificateRevocationList 883 +#define OBJ_certificateRevocationList OBJ_X509,39L + +#define LN_crossCertificatePair "crossCertificatePair" +#define NID_crossCertificatePair 884 +#define OBJ_crossCertificatePair OBJ_X509,40L + +#define SN_name "name" +#define LN_name "name" +#define NID_name 173 +#define OBJ_name OBJ_X509,41L + +#define SN_givenName "GN" +#define LN_givenName "givenName" +#define NID_givenName 99 +#define OBJ_givenName OBJ_X509,42L + +#define SN_initials "initials" +#define LN_initials "initials" +#define NID_initials 101 +#define OBJ_initials OBJ_X509,43L + +#define LN_generationQualifier "generationQualifier" +#define NID_generationQualifier 509 +#define OBJ_generationQualifier OBJ_X509,44L + +#define LN_x500UniqueIdentifier "x500UniqueIdentifier" +#define NID_x500UniqueIdentifier 503 +#define OBJ_x500UniqueIdentifier OBJ_X509,45L + +#define SN_dnQualifier "dnQualifier" +#define LN_dnQualifier "dnQualifier" +#define NID_dnQualifier 174 +#define OBJ_dnQualifier OBJ_X509,46L + +#define LN_enhancedSearchGuide "enhancedSearchGuide" +#define NID_enhancedSearchGuide 885 +#define OBJ_enhancedSearchGuide OBJ_X509,47L + +#define LN_protocolInformation "protocolInformation" +#define NID_protocolInformation 886 +#define OBJ_protocolInformation OBJ_X509,48L + +#define LN_distinguishedName "distinguishedName" +#define NID_distinguishedName 887 +#define OBJ_distinguishedName OBJ_X509,49L + +#define LN_uniqueMember "uniqueMember" +#define NID_uniqueMember 888 +#define OBJ_uniqueMember OBJ_X509,50L + +#define LN_houseIdentifier "houseIdentifier" +#define NID_houseIdentifier 889 +#define OBJ_houseIdentifier OBJ_X509,51L + +#define LN_supportedAlgorithms "supportedAlgorithms" +#define NID_supportedAlgorithms 890 +#define OBJ_supportedAlgorithms OBJ_X509,52L + +#define LN_deltaRevocationList "deltaRevocationList" +#define NID_deltaRevocationList 891 +#define OBJ_deltaRevocationList OBJ_X509,53L + +#define SN_dmdName "dmdName" +#define NID_dmdName 892 +#define OBJ_dmdName OBJ_X509,54L + +#define LN_pseudonym "pseudonym" +#define NID_pseudonym 510 +#define OBJ_pseudonym OBJ_X509,65L + +#define SN_role "role" +#define LN_role "role" +#define NID_role 400 +#define OBJ_role OBJ_X509,72L + +#define LN_organizationIdentifier "organizationIdentifier" +#define NID_organizationIdentifier 1089 +#define OBJ_organizationIdentifier OBJ_X509,97L + +#define SN_countryCode3c "c3" +#define LN_countryCode3c "countryCode3c" +#define NID_countryCode3c 1090 +#define OBJ_countryCode3c OBJ_X509,98L + +#define SN_countryCode3n "n3" +#define LN_countryCode3n "countryCode3n" +#define NID_countryCode3n 1091 +#define OBJ_countryCode3n OBJ_X509,99L + +#define LN_dnsName "dnsName" +#define NID_dnsName 1092 +#define OBJ_dnsName OBJ_X509,100L + +#define SN_X500algorithms "X500algorithms" +#define LN_X500algorithms "directory services - algorithms" +#define NID_X500algorithms 378 +#define OBJ_X500algorithms OBJ_X500,8L + +#define SN_rsa "RSA" +#define LN_rsa "rsa" +#define NID_rsa 19 +#define OBJ_rsa OBJ_X500algorithms,1L,1L + +#define SN_mdc2WithRSA "RSA-MDC2" +#define LN_mdc2WithRSA "mdc2WithRSA" +#define NID_mdc2WithRSA 96 +#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L + +#define SN_mdc2 "MDC2" +#define LN_mdc2 "mdc2" +#define NID_mdc2 95 +#define OBJ_mdc2 OBJ_X500algorithms,3L,101L + +#define SN_id_ce "id-ce" +#define NID_id_ce 81 +#define OBJ_id_ce OBJ_X500,29L + +#define SN_subject_directory_attributes "subjectDirectoryAttributes" +#define LN_subject_directory_attributes "X509v3 Subject Directory Attributes" +#define NID_subject_directory_attributes 769 +#define OBJ_subject_directory_attributes OBJ_id_ce,9L + +#define SN_subject_key_identifier "subjectKeyIdentifier" +#define LN_subject_key_identifier "X509v3 Subject Key Identifier" +#define NID_subject_key_identifier 82 +#define OBJ_subject_key_identifier OBJ_id_ce,14L + +#define SN_key_usage "keyUsage" +#define LN_key_usage "X509v3 Key Usage" +#define NID_key_usage 83 +#define OBJ_key_usage OBJ_id_ce,15L + +#define SN_private_key_usage_period "privateKeyUsagePeriod" +#define LN_private_key_usage_period "X509v3 Private Key Usage Period" +#define NID_private_key_usage_period 84 +#define OBJ_private_key_usage_period OBJ_id_ce,16L + +#define SN_subject_alt_name "subjectAltName" +#define LN_subject_alt_name "X509v3 Subject Alternative Name" +#define NID_subject_alt_name 85 +#define OBJ_subject_alt_name OBJ_id_ce,17L + +#define SN_issuer_alt_name "issuerAltName" +#define LN_issuer_alt_name "X509v3 Issuer Alternative Name" +#define NID_issuer_alt_name 86 +#define OBJ_issuer_alt_name OBJ_id_ce,18L + +#define SN_basic_constraints "basicConstraints" +#define LN_basic_constraints "X509v3 Basic Constraints" +#define NID_basic_constraints 87 +#define OBJ_basic_constraints OBJ_id_ce,19L + +#define SN_crl_number "crlNumber" +#define LN_crl_number "X509v3 CRL Number" +#define NID_crl_number 88 +#define OBJ_crl_number OBJ_id_ce,20L + +#define SN_crl_reason "CRLReason" +#define LN_crl_reason "X509v3 CRL Reason Code" +#define NID_crl_reason 141 +#define OBJ_crl_reason OBJ_id_ce,21L + +#define SN_invalidity_date "invalidityDate" +#define LN_invalidity_date "Invalidity Date" +#define NID_invalidity_date 142 +#define OBJ_invalidity_date OBJ_id_ce,24L + +#define SN_delta_crl "deltaCRL" +#define LN_delta_crl "X509v3 Delta CRL Indicator" +#define NID_delta_crl 140 +#define OBJ_delta_crl OBJ_id_ce,27L + +#define SN_issuing_distribution_point "issuingDistributionPoint" +#define LN_issuing_distribution_point "X509v3 Issuing Distribution Point" +#define NID_issuing_distribution_point 770 +#define OBJ_issuing_distribution_point OBJ_id_ce,28L + +#define SN_certificate_issuer "certificateIssuer" +#define LN_certificate_issuer "X509v3 Certificate Issuer" +#define NID_certificate_issuer 771 +#define OBJ_certificate_issuer OBJ_id_ce,29L + +#define SN_name_constraints "nameConstraints" +#define LN_name_constraints "X509v3 Name Constraints" +#define NID_name_constraints 666 +#define OBJ_name_constraints OBJ_id_ce,30L + +#define SN_crl_distribution_points "crlDistributionPoints" +#define LN_crl_distribution_points "X509v3 CRL Distribution Points" +#define NID_crl_distribution_points 103 +#define OBJ_crl_distribution_points OBJ_id_ce,31L + +#define SN_certificate_policies "certificatePolicies" +#define LN_certificate_policies "X509v3 Certificate Policies" +#define NID_certificate_policies 89 +#define OBJ_certificate_policies OBJ_id_ce,32L + +#define SN_any_policy "anyPolicy" +#define LN_any_policy "X509v3 Any Policy" +#define NID_any_policy 746 +#define OBJ_any_policy OBJ_certificate_policies,0L + +#define SN_policy_mappings "policyMappings" +#define LN_policy_mappings "X509v3 Policy Mappings" +#define NID_policy_mappings 747 +#define OBJ_policy_mappings OBJ_id_ce,33L + +#define SN_authority_key_identifier "authorityKeyIdentifier" +#define LN_authority_key_identifier "X509v3 Authority Key Identifier" +#define NID_authority_key_identifier 90 +#define OBJ_authority_key_identifier OBJ_id_ce,35L + +#define SN_policy_constraints "policyConstraints" +#define LN_policy_constraints "X509v3 Policy Constraints" +#define NID_policy_constraints 401 +#define OBJ_policy_constraints OBJ_id_ce,36L + +#define SN_ext_key_usage "extendedKeyUsage" +#define LN_ext_key_usage "X509v3 Extended Key Usage" +#define NID_ext_key_usage 126 +#define OBJ_ext_key_usage OBJ_id_ce,37L + +#define SN_freshest_crl "freshestCRL" +#define LN_freshest_crl "X509v3 Freshest CRL" +#define NID_freshest_crl 857 +#define OBJ_freshest_crl OBJ_id_ce,46L + +#define SN_inhibit_any_policy "inhibitAnyPolicy" +#define LN_inhibit_any_policy "X509v3 Inhibit Any Policy" +#define NID_inhibit_any_policy 748 +#define OBJ_inhibit_any_policy OBJ_id_ce,54L + +#define SN_target_information "targetInformation" +#define LN_target_information "X509v3 AC Targeting" +#define NID_target_information 402 +#define OBJ_target_information OBJ_id_ce,55L + +#define SN_no_rev_avail "noRevAvail" +#define LN_no_rev_avail "X509v3 No Revocation Available" +#define NID_no_rev_avail 403 +#define OBJ_no_rev_avail OBJ_id_ce,56L + +#define SN_anyExtendedKeyUsage "anyExtendedKeyUsage" +#define LN_anyExtendedKeyUsage "Any Extended Key Usage" +#define NID_anyExtendedKeyUsage 910 +#define OBJ_anyExtendedKeyUsage OBJ_ext_key_usage,0L + +#define SN_netscape "Netscape" +#define LN_netscape "Netscape Communications Corp." +#define NID_netscape 57 +#define OBJ_netscape 2L,16L,840L,1L,113730L + +#define SN_netscape_cert_extension "nsCertExt" +#define LN_netscape_cert_extension "Netscape Certificate Extension" +#define NID_netscape_cert_extension 58 +#define OBJ_netscape_cert_extension OBJ_netscape,1L + +#define SN_netscape_data_type "nsDataType" +#define LN_netscape_data_type "Netscape Data Type" +#define NID_netscape_data_type 59 +#define OBJ_netscape_data_type OBJ_netscape,2L + +#define SN_netscape_cert_type "nsCertType" +#define LN_netscape_cert_type "Netscape Cert Type" +#define NID_netscape_cert_type 71 +#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L + +#define SN_netscape_base_url "nsBaseUrl" +#define LN_netscape_base_url "Netscape Base Url" +#define NID_netscape_base_url 72 +#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L + +#define SN_netscape_revocation_url "nsRevocationUrl" +#define LN_netscape_revocation_url "Netscape Revocation Url" +#define NID_netscape_revocation_url 73 +#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L + +#define SN_netscape_ca_revocation_url "nsCaRevocationUrl" +#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" +#define NID_netscape_ca_revocation_url 74 +#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L + +#define SN_netscape_renewal_url "nsRenewalUrl" +#define LN_netscape_renewal_url "Netscape Renewal Url" +#define NID_netscape_renewal_url 75 +#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L + +#define SN_netscape_ca_policy_url "nsCaPolicyUrl" +#define LN_netscape_ca_policy_url "Netscape CA Policy Url" +#define NID_netscape_ca_policy_url 76 +#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L + +#define SN_netscape_ssl_server_name "nsSslServerName" +#define LN_netscape_ssl_server_name "Netscape SSL Server Name" +#define NID_netscape_ssl_server_name 77 +#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L + +#define SN_netscape_comment "nsComment" +#define LN_netscape_comment "Netscape Comment" +#define NID_netscape_comment 78 +#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L + +#define SN_netscape_cert_sequence "nsCertSequence" +#define LN_netscape_cert_sequence "Netscape Certificate Sequence" +#define NID_netscape_cert_sequence 79 +#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L + +#define SN_ns_sgc "nsSGC" +#define LN_ns_sgc "Netscape Server Gated Crypto" +#define NID_ns_sgc 139 +#define OBJ_ns_sgc OBJ_netscape,4L,1L + +#define SN_org "ORG" +#define LN_org "org" +#define NID_org 379 +#define OBJ_org OBJ_iso,3L + +#define SN_dod "DOD" +#define LN_dod "dod" +#define NID_dod 380 +#define OBJ_dod OBJ_org,6L + +#define SN_iana "IANA" +#define LN_iana "iana" +#define NID_iana 381 +#define OBJ_iana OBJ_dod,1L + +#define OBJ_internet OBJ_iana + +#define SN_Directory "directory" +#define LN_Directory "Directory" +#define NID_Directory 382 +#define OBJ_Directory OBJ_internet,1L + +#define SN_Management "mgmt" +#define LN_Management "Management" +#define NID_Management 383 +#define OBJ_Management OBJ_internet,2L + +#define SN_Experimental "experimental" +#define LN_Experimental "Experimental" +#define NID_Experimental 384 +#define OBJ_Experimental OBJ_internet,3L + +#define SN_Private "private" +#define LN_Private "Private" +#define NID_Private 385 +#define OBJ_Private OBJ_internet,4L + +#define SN_Security "security" +#define LN_Security "Security" +#define NID_Security 386 +#define OBJ_Security OBJ_internet,5L + +#define SN_SNMPv2 "snmpv2" +#define LN_SNMPv2 "SNMPv2" +#define NID_SNMPv2 387 +#define OBJ_SNMPv2 OBJ_internet,6L + +#define LN_Mail "Mail" +#define NID_Mail 388 +#define OBJ_Mail OBJ_internet,7L + +#define SN_Enterprises "enterprises" +#define LN_Enterprises "Enterprises" +#define NID_Enterprises 389 +#define OBJ_Enterprises OBJ_Private,1L + +#define SN_dcObject "dcobject" +#define LN_dcObject "dcObject" +#define NID_dcObject 390 +#define OBJ_dcObject OBJ_Enterprises,1466L,344L + +#define SN_mime_mhs "mime-mhs" +#define LN_mime_mhs "MIME MHS" +#define NID_mime_mhs 504 +#define OBJ_mime_mhs OBJ_Mail,1L + +#define SN_mime_mhs_headings "mime-mhs-headings" +#define LN_mime_mhs_headings "mime-mhs-headings" +#define NID_mime_mhs_headings 505 +#define OBJ_mime_mhs_headings OBJ_mime_mhs,1L + +#define SN_mime_mhs_bodies "mime-mhs-bodies" +#define LN_mime_mhs_bodies "mime-mhs-bodies" +#define NID_mime_mhs_bodies 506 +#define OBJ_mime_mhs_bodies OBJ_mime_mhs,2L + +#define SN_id_hex_partial_message "id-hex-partial-message" +#define LN_id_hex_partial_message "id-hex-partial-message" +#define NID_id_hex_partial_message 507 +#define OBJ_id_hex_partial_message OBJ_mime_mhs_headings,1L + +#define SN_id_hex_multipart_message "id-hex-multipart-message" +#define LN_id_hex_multipart_message "id-hex-multipart-message" +#define NID_id_hex_multipart_message 508 +#define OBJ_id_hex_multipart_message OBJ_mime_mhs_headings,2L + +#define SN_zlib_compression "ZLIB" +#define LN_zlib_compression "zlib compression" +#define NID_zlib_compression 125 +#define OBJ_zlib_compression OBJ_id_smime_alg,8L + +#define OBJ_csor 2L,16L,840L,1L,101L,3L + +#define OBJ_nistAlgorithms OBJ_csor,4L + +#define OBJ_aes OBJ_nistAlgorithms,1L + +#define SN_aes_128_ecb "AES-128-ECB" +#define LN_aes_128_ecb "aes-128-ecb" +#define NID_aes_128_ecb 418 +#define OBJ_aes_128_ecb OBJ_aes,1L + +#define SN_aes_128_cbc "AES-128-CBC" +#define LN_aes_128_cbc "aes-128-cbc" +#define NID_aes_128_cbc 419 +#define OBJ_aes_128_cbc OBJ_aes,2L + +#define SN_aes_128_ofb128 "AES-128-OFB" +#define LN_aes_128_ofb128 "aes-128-ofb" +#define NID_aes_128_ofb128 420 +#define OBJ_aes_128_ofb128 OBJ_aes,3L + +#define SN_aes_128_cfb128 "AES-128-CFB" +#define LN_aes_128_cfb128 "aes-128-cfb" +#define NID_aes_128_cfb128 421 +#define OBJ_aes_128_cfb128 OBJ_aes,4L + +#define SN_id_aes128_wrap "id-aes128-wrap" +#define NID_id_aes128_wrap 788 +#define OBJ_id_aes128_wrap OBJ_aes,5L + +#define SN_aes_128_gcm "id-aes128-GCM" +#define LN_aes_128_gcm "aes-128-gcm" +#define NID_aes_128_gcm 895 +#define OBJ_aes_128_gcm OBJ_aes,6L + +#define SN_aes_128_ccm "id-aes128-CCM" +#define LN_aes_128_ccm "aes-128-ccm" +#define NID_aes_128_ccm 896 +#define OBJ_aes_128_ccm OBJ_aes,7L + +#define SN_id_aes128_wrap_pad "id-aes128-wrap-pad" +#define NID_id_aes128_wrap_pad 897 +#define OBJ_id_aes128_wrap_pad OBJ_aes,8L + +#define SN_aes_192_ecb "AES-192-ECB" +#define LN_aes_192_ecb "aes-192-ecb" +#define NID_aes_192_ecb 422 +#define OBJ_aes_192_ecb OBJ_aes,21L + +#define SN_aes_192_cbc "AES-192-CBC" +#define LN_aes_192_cbc "aes-192-cbc" +#define NID_aes_192_cbc 423 +#define OBJ_aes_192_cbc OBJ_aes,22L + +#define SN_aes_192_ofb128 "AES-192-OFB" +#define LN_aes_192_ofb128 "aes-192-ofb" +#define NID_aes_192_ofb128 424 +#define OBJ_aes_192_ofb128 OBJ_aes,23L + +#define SN_aes_192_cfb128 "AES-192-CFB" +#define LN_aes_192_cfb128 "aes-192-cfb" +#define NID_aes_192_cfb128 425 +#define OBJ_aes_192_cfb128 OBJ_aes,24L + +#define SN_id_aes192_wrap "id-aes192-wrap" +#define NID_id_aes192_wrap 789 +#define OBJ_id_aes192_wrap OBJ_aes,25L + +#define SN_aes_192_gcm "id-aes192-GCM" +#define LN_aes_192_gcm "aes-192-gcm" +#define NID_aes_192_gcm 898 +#define OBJ_aes_192_gcm OBJ_aes,26L + +#define SN_aes_192_ccm "id-aes192-CCM" +#define LN_aes_192_ccm "aes-192-ccm" +#define NID_aes_192_ccm 899 +#define OBJ_aes_192_ccm OBJ_aes,27L + +#define SN_id_aes192_wrap_pad "id-aes192-wrap-pad" +#define NID_id_aes192_wrap_pad 900 +#define OBJ_id_aes192_wrap_pad OBJ_aes,28L + +#define SN_aes_256_ecb "AES-256-ECB" +#define LN_aes_256_ecb "aes-256-ecb" +#define NID_aes_256_ecb 426 +#define OBJ_aes_256_ecb OBJ_aes,41L + +#define SN_aes_256_cbc "AES-256-CBC" +#define LN_aes_256_cbc "aes-256-cbc" +#define NID_aes_256_cbc 427 +#define OBJ_aes_256_cbc OBJ_aes,42L + +#define SN_aes_256_ofb128 "AES-256-OFB" +#define LN_aes_256_ofb128 "aes-256-ofb" +#define NID_aes_256_ofb128 428 +#define OBJ_aes_256_ofb128 OBJ_aes,43L + +#define SN_aes_256_cfb128 "AES-256-CFB" +#define LN_aes_256_cfb128 "aes-256-cfb" +#define NID_aes_256_cfb128 429 +#define OBJ_aes_256_cfb128 OBJ_aes,44L + +#define SN_id_aes256_wrap "id-aes256-wrap" +#define NID_id_aes256_wrap 790 +#define OBJ_id_aes256_wrap OBJ_aes,45L + +#define SN_aes_256_gcm "id-aes256-GCM" +#define LN_aes_256_gcm "aes-256-gcm" +#define NID_aes_256_gcm 901 +#define OBJ_aes_256_gcm OBJ_aes,46L + +#define SN_aes_256_ccm "id-aes256-CCM" +#define LN_aes_256_ccm "aes-256-ccm" +#define NID_aes_256_ccm 902 +#define OBJ_aes_256_ccm OBJ_aes,47L + +#define SN_id_aes256_wrap_pad "id-aes256-wrap-pad" +#define NID_id_aes256_wrap_pad 903 +#define OBJ_id_aes256_wrap_pad OBJ_aes,48L + +#define SN_aes_128_xts "AES-128-XTS" +#define LN_aes_128_xts "aes-128-xts" +#define NID_aes_128_xts 913 +#define OBJ_aes_128_xts OBJ_ieee_siswg,0L,1L,1L + +#define SN_aes_256_xts "AES-256-XTS" +#define LN_aes_256_xts "aes-256-xts" +#define NID_aes_256_xts 914 +#define OBJ_aes_256_xts OBJ_ieee_siswg,0L,1L,2L + +#define SN_aes_128_cfb1 "AES-128-CFB1" +#define LN_aes_128_cfb1 "aes-128-cfb1" +#define NID_aes_128_cfb1 650 + +#define SN_aes_192_cfb1 "AES-192-CFB1" +#define LN_aes_192_cfb1 "aes-192-cfb1" +#define NID_aes_192_cfb1 651 + +#define SN_aes_256_cfb1 "AES-256-CFB1" +#define LN_aes_256_cfb1 "aes-256-cfb1" +#define NID_aes_256_cfb1 652 + +#define SN_aes_128_cfb8 "AES-128-CFB8" +#define LN_aes_128_cfb8 "aes-128-cfb8" +#define NID_aes_128_cfb8 653 + +#define SN_aes_192_cfb8 "AES-192-CFB8" +#define LN_aes_192_cfb8 "aes-192-cfb8" +#define NID_aes_192_cfb8 654 + +#define SN_aes_256_cfb8 "AES-256-CFB8" +#define LN_aes_256_cfb8 "aes-256-cfb8" +#define NID_aes_256_cfb8 655 + +#define SN_aes_128_ctr "AES-128-CTR" +#define LN_aes_128_ctr "aes-128-ctr" +#define NID_aes_128_ctr 904 + +#define SN_aes_192_ctr "AES-192-CTR" +#define LN_aes_192_ctr "aes-192-ctr" +#define NID_aes_192_ctr 905 + +#define SN_aes_256_ctr "AES-256-CTR" +#define LN_aes_256_ctr "aes-256-ctr" +#define NID_aes_256_ctr 906 + +#define SN_aes_128_ocb "AES-128-OCB" +#define LN_aes_128_ocb "aes-128-ocb" +#define NID_aes_128_ocb 958 + +#define SN_aes_192_ocb "AES-192-OCB" +#define LN_aes_192_ocb "aes-192-ocb" +#define NID_aes_192_ocb 959 + +#define SN_aes_256_ocb "AES-256-OCB" +#define LN_aes_256_ocb "aes-256-ocb" +#define NID_aes_256_ocb 960 + +#define SN_des_cfb1 "DES-CFB1" +#define LN_des_cfb1 "des-cfb1" +#define NID_des_cfb1 656 + +#define SN_des_cfb8 "DES-CFB8" +#define LN_des_cfb8 "des-cfb8" +#define NID_des_cfb8 657 + +#define SN_des_ede3_cfb1 "DES-EDE3-CFB1" +#define LN_des_ede3_cfb1 "des-ede3-cfb1" +#define NID_des_ede3_cfb1 658 + +#define SN_des_ede3_cfb8 "DES-EDE3-CFB8" +#define LN_des_ede3_cfb8 "des-ede3-cfb8" +#define NID_des_ede3_cfb8 659 + +#define OBJ_nist_hashalgs OBJ_nistAlgorithms,2L + +#define SN_sha256 "SHA256" +#define LN_sha256 "sha256" +#define NID_sha256 672 +#define OBJ_sha256 OBJ_nist_hashalgs,1L + +#define SN_sha384 "SHA384" +#define LN_sha384 "sha384" +#define NID_sha384 673 +#define OBJ_sha384 OBJ_nist_hashalgs,2L + +#define SN_sha512 "SHA512" +#define LN_sha512 "sha512" +#define NID_sha512 674 +#define OBJ_sha512 OBJ_nist_hashalgs,3L + +#define SN_sha224 "SHA224" +#define LN_sha224 "sha224" +#define NID_sha224 675 +#define OBJ_sha224 OBJ_nist_hashalgs,4L + +#define SN_sha512_224 "SHA512-224" +#define LN_sha512_224 "sha512-224" +#define NID_sha512_224 1094 +#define OBJ_sha512_224 OBJ_nist_hashalgs,5L + +#define SN_sha512_256 "SHA512-256" +#define LN_sha512_256 "sha512-256" +#define NID_sha512_256 1095 +#define OBJ_sha512_256 OBJ_nist_hashalgs,6L + +#define SN_sha3_224 "SHA3-224" +#define LN_sha3_224 "sha3-224" +#define NID_sha3_224 1096 +#define OBJ_sha3_224 OBJ_nist_hashalgs,7L + +#define SN_sha3_256 "SHA3-256" +#define LN_sha3_256 "sha3-256" +#define NID_sha3_256 1097 +#define OBJ_sha3_256 OBJ_nist_hashalgs,8L + +#define SN_sha3_384 "SHA3-384" +#define LN_sha3_384 "sha3-384" +#define NID_sha3_384 1098 +#define OBJ_sha3_384 OBJ_nist_hashalgs,9L + +#define SN_sha3_512 "SHA3-512" +#define LN_sha3_512 "sha3-512" +#define NID_sha3_512 1099 +#define OBJ_sha3_512 OBJ_nist_hashalgs,10L + +#define SN_shake128 "SHAKE128" +#define LN_shake128 "shake128" +#define NID_shake128 1100 +#define OBJ_shake128 OBJ_nist_hashalgs,11L + +#define SN_shake256 "SHAKE256" +#define LN_shake256 "shake256" +#define NID_shake256 1101 +#define OBJ_shake256 OBJ_nist_hashalgs,12L + +#define SN_hmac_sha3_224 "id-hmacWithSHA3-224" +#define LN_hmac_sha3_224 "hmac-sha3-224" +#define NID_hmac_sha3_224 1102 +#define OBJ_hmac_sha3_224 OBJ_nist_hashalgs,13L + +#define SN_hmac_sha3_256 "id-hmacWithSHA3-256" +#define LN_hmac_sha3_256 "hmac-sha3-256" +#define NID_hmac_sha3_256 1103 +#define OBJ_hmac_sha3_256 OBJ_nist_hashalgs,14L + +#define SN_hmac_sha3_384 "id-hmacWithSHA3-384" +#define LN_hmac_sha3_384 "hmac-sha3-384" +#define NID_hmac_sha3_384 1104 +#define OBJ_hmac_sha3_384 OBJ_nist_hashalgs,15L + +#define SN_hmac_sha3_512 "id-hmacWithSHA3-512" +#define LN_hmac_sha3_512 "hmac-sha3-512" +#define NID_hmac_sha3_512 1105 +#define OBJ_hmac_sha3_512 OBJ_nist_hashalgs,16L + +#define OBJ_dsa_with_sha2 OBJ_nistAlgorithms,3L + +#define SN_dsa_with_SHA224 "dsa_with_SHA224" +#define NID_dsa_with_SHA224 802 +#define OBJ_dsa_with_SHA224 OBJ_dsa_with_sha2,1L + +#define SN_dsa_with_SHA256 "dsa_with_SHA256" +#define NID_dsa_with_SHA256 803 +#define OBJ_dsa_with_SHA256 OBJ_dsa_with_sha2,2L + +#define OBJ_sigAlgs OBJ_nistAlgorithms,3L + +#define SN_dsa_with_SHA384 "id-dsa-with-sha384" +#define LN_dsa_with_SHA384 "dsa_with_SHA384" +#define NID_dsa_with_SHA384 1106 +#define OBJ_dsa_with_SHA384 OBJ_sigAlgs,3L + +#define SN_dsa_with_SHA512 "id-dsa-with-sha512" +#define LN_dsa_with_SHA512 "dsa_with_SHA512" +#define NID_dsa_with_SHA512 1107 +#define OBJ_dsa_with_SHA512 OBJ_sigAlgs,4L + +#define SN_dsa_with_SHA3_224 "id-dsa-with-sha3-224" +#define LN_dsa_with_SHA3_224 "dsa_with_SHA3-224" +#define NID_dsa_with_SHA3_224 1108 +#define OBJ_dsa_with_SHA3_224 OBJ_sigAlgs,5L + +#define SN_dsa_with_SHA3_256 "id-dsa-with-sha3-256" +#define LN_dsa_with_SHA3_256 "dsa_with_SHA3-256" +#define NID_dsa_with_SHA3_256 1109 +#define OBJ_dsa_with_SHA3_256 OBJ_sigAlgs,6L + +#define SN_dsa_with_SHA3_384 "id-dsa-with-sha3-384" +#define LN_dsa_with_SHA3_384 "dsa_with_SHA3-384" +#define NID_dsa_with_SHA3_384 1110 +#define OBJ_dsa_with_SHA3_384 OBJ_sigAlgs,7L + +#define SN_dsa_with_SHA3_512 "id-dsa-with-sha3-512" +#define LN_dsa_with_SHA3_512 "dsa_with_SHA3-512" +#define NID_dsa_with_SHA3_512 1111 +#define OBJ_dsa_with_SHA3_512 OBJ_sigAlgs,8L + +#define SN_ecdsa_with_SHA3_224 "id-ecdsa-with-sha3-224" +#define LN_ecdsa_with_SHA3_224 "ecdsa_with_SHA3-224" +#define NID_ecdsa_with_SHA3_224 1112 +#define OBJ_ecdsa_with_SHA3_224 OBJ_sigAlgs,9L + +#define SN_ecdsa_with_SHA3_256 "id-ecdsa-with-sha3-256" +#define LN_ecdsa_with_SHA3_256 "ecdsa_with_SHA3-256" +#define NID_ecdsa_with_SHA3_256 1113 +#define OBJ_ecdsa_with_SHA3_256 OBJ_sigAlgs,10L + +#define SN_ecdsa_with_SHA3_384 "id-ecdsa-with-sha3-384" +#define LN_ecdsa_with_SHA3_384 "ecdsa_with_SHA3-384" +#define NID_ecdsa_with_SHA3_384 1114 +#define OBJ_ecdsa_with_SHA3_384 OBJ_sigAlgs,11L + +#define SN_ecdsa_with_SHA3_512 "id-ecdsa-with-sha3-512" +#define LN_ecdsa_with_SHA3_512 "ecdsa_with_SHA3-512" +#define NID_ecdsa_with_SHA3_512 1115 +#define OBJ_ecdsa_with_SHA3_512 OBJ_sigAlgs,12L + +#define SN_RSA_SHA3_224 "id-rsassa-pkcs1-v1_5-with-sha3-224" +#define LN_RSA_SHA3_224 "RSA-SHA3-224" +#define NID_RSA_SHA3_224 1116 +#define OBJ_RSA_SHA3_224 OBJ_sigAlgs,13L + +#define SN_RSA_SHA3_256 "id-rsassa-pkcs1-v1_5-with-sha3-256" +#define LN_RSA_SHA3_256 "RSA-SHA3-256" +#define NID_RSA_SHA3_256 1117 +#define OBJ_RSA_SHA3_256 OBJ_sigAlgs,14L + +#define SN_RSA_SHA3_384 "id-rsassa-pkcs1-v1_5-with-sha3-384" +#define LN_RSA_SHA3_384 "RSA-SHA3-384" +#define NID_RSA_SHA3_384 1118 +#define OBJ_RSA_SHA3_384 OBJ_sigAlgs,15L + +#define SN_RSA_SHA3_512 "id-rsassa-pkcs1-v1_5-with-sha3-512" +#define LN_RSA_SHA3_512 "RSA-SHA3-512" +#define NID_RSA_SHA3_512 1119 +#define OBJ_RSA_SHA3_512 OBJ_sigAlgs,16L + +#define SN_hold_instruction_code "holdInstructionCode" +#define LN_hold_instruction_code "Hold Instruction Code" +#define NID_hold_instruction_code 430 +#define OBJ_hold_instruction_code OBJ_id_ce,23L + +#define OBJ_holdInstruction OBJ_X9_57,2L + +#define SN_hold_instruction_none "holdInstructionNone" +#define LN_hold_instruction_none "Hold Instruction None" +#define NID_hold_instruction_none 431 +#define OBJ_hold_instruction_none OBJ_holdInstruction,1L + +#define SN_hold_instruction_call_issuer "holdInstructionCallIssuer" +#define LN_hold_instruction_call_issuer "Hold Instruction Call Issuer" +#define NID_hold_instruction_call_issuer 432 +#define OBJ_hold_instruction_call_issuer OBJ_holdInstruction,2L + +#define SN_hold_instruction_reject "holdInstructionReject" +#define LN_hold_instruction_reject "Hold Instruction Reject" +#define NID_hold_instruction_reject 433 +#define OBJ_hold_instruction_reject OBJ_holdInstruction,3L + +#define SN_data "data" +#define NID_data 434 +#define OBJ_data OBJ_itu_t,9L + +#define SN_pss "pss" +#define NID_pss 435 +#define OBJ_pss OBJ_data,2342L + +#define SN_ucl "ucl" +#define NID_ucl 436 +#define OBJ_ucl OBJ_pss,19200300L + +#define SN_pilot "pilot" +#define NID_pilot 437 +#define OBJ_pilot OBJ_ucl,100L + +#define LN_pilotAttributeType "pilotAttributeType" +#define NID_pilotAttributeType 438 +#define OBJ_pilotAttributeType OBJ_pilot,1L + +#define LN_pilotAttributeSyntax "pilotAttributeSyntax" +#define NID_pilotAttributeSyntax 439 +#define OBJ_pilotAttributeSyntax OBJ_pilot,3L + +#define LN_pilotObjectClass "pilotObjectClass" +#define NID_pilotObjectClass 440 +#define OBJ_pilotObjectClass OBJ_pilot,4L + +#define LN_pilotGroups "pilotGroups" +#define NID_pilotGroups 441 +#define OBJ_pilotGroups OBJ_pilot,10L + +#define LN_iA5StringSyntax "iA5StringSyntax" +#define NID_iA5StringSyntax 442 +#define OBJ_iA5StringSyntax OBJ_pilotAttributeSyntax,4L + +#define LN_caseIgnoreIA5StringSyntax "caseIgnoreIA5StringSyntax" +#define NID_caseIgnoreIA5StringSyntax 443 +#define OBJ_caseIgnoreIA5StringSyntax OBJ_pilotAttributeSyntax,5L + +#define LN_pilotObject "pilotObject" +#define NID_pilotObject 444 +#define OBJ_pilotObject OBJ_pilotObjectClass,3L + +#define LN_pilotPerson "pilotPerson" +#define NID_pilotPerson 445 +#define OBJ_pilotPerson OBJ_pilotObjectClass,4L + +#define SN_account "account" +#define NID_account 446 +#define OBJ_account OBJ_pilotObjectClass,5L + +#define SN_document "document" +#define NID_document 447 +#define OBJ_document OBJ_pilotObjectClass,6L + +#define SN_room "room" +#define NID_room 448 +#define OBJ_room OBJ_pilotObjectClass,7L + +#define LN_documentSeries "documentSeries" +#define NID_documentSeries 449 +#define OBJ_documentSeries OBJ_pilotObjectClass,9L + +#define SN_Domain "domain" +#define LN_Domain "Domain" +#define NID_Domain 392 +#define OBJ_Domain OBJ_pilotObjectClass,13L + +#define LN_rFC822localPart "rFC822localPart" +#define NID_rFC822localPart 450 +#define OBJ_rFC822localPart OBJ_pilotObjectClass,14L + +#define LN_dNSDomain "dNSDomain" +#define NID_dNSDomain 451 +#define OBJ_dNSDomain OBJ_pilotObjectClass,15L + +#define LN_domainRelatedObject "domainRelatedObject" +#define NID_domainRelatedObject 452 +#define OBJ_domainRelatedObject OBJ_pilotObjectClass,17L + +#define LN_friendlyCountry "friendlyCountry" +#define NID_friendlyCountry 453 +#define OBJ_friendlyCountry OBJ_pilotObjectClass,18L + +#define LN_simpleSecurityObject "simpleSecurityObject" +#define NID_simpleSecurityObject 454 +#define OBJ_simpleSecurityObject OBJ_pilotObjectClass,19L + +#define LN_pilotOrganization "pilotOrganization" +#define NID_pilotOrganization 455 +#define OBJ_pilotOrganization OBJ_pilotObjectClass,20L + +#define LN_pilotDSA "pilotDSA" +#define NID_pilotDSA 456 +#define OBJ_pilotDSA OBJ_pilotObjectClass,21L + +#define LN_qualityLabelledData "qualityLabelledData" +#define NID_qualityLabelledData 457 +#define OBJ_qualityLabelledData OBJ_pilotObjectClass,22L + +#define SN_userId "UID" +#define LN_userId "userId" +#define NID_userId 458 +#define OBJ_userId OBJ_pilotAttributeType,1L + +#define LN_textEncodedORAddress "textEncodedORAddress" +#define NID_textEncodedORAddress 459 +#define OBJ_textEncodedORAddress OBJ_pilotAttributeType,2L + +#define SN_rfc822Mailbox "mail" +#define LN_rfc822Mailbox "rfc822Mailbox" +#define NID_rfc822Mailbox 460 +#define OBJ_rfc822Mailbox OBJ_pilotAttributeType,3L + +#define SN_info "info" +#define NID_info 461 +#define OBJ_info OBJ_pilotAttributeType,4L + +#define LN_favouriteDrink "favouriteDrink" +#define NID_favouriteDrink 462 +#define OBJ_favouriteDrink OBJ_pilotAttributeType,5L + +#define LN_roomNumber "roomNumber" +#define NID_roomNumber 463 +#define OBJ_roomNumber OBJ_pilotAttributeType,6L + +#define SN_photo "photo" +#define NID_photo 464 +#define OBJ_photo OBJ_pilotAttributeType,7L + +#define LN_userClass "userClass" +#define NID_userClass 465 +#define OBJ_userClass OBJ_pilotAttributeType,8L + +#define SN_host "host" +#define NID_host 466 +#define OBJ_host OBJ_pilotAttributeType,9L + +#define SN_manager "manager" +#define NID_manager 467 +#define OBJ_manager OBJ_pilotAttributeType,10L + +#define LN_documentIdentifier "documentIdentifier" +#define NID_documentIdentifier 468 +#define OBJ_documentIdentifier OBJ_pilotAttributeType,11L + +#define LN_documentTitle "documentTitle" +#define NID_documentTitle 469 +#define OBJ_documentTitle OBJ_pilotAttributeType,12L + +#define LN_documentVersion "documentVersion" +#define NID_documentVersion 470 +#define OBJ_documentVersion OBJ_pilotAttributeType,13L + +#define LN_documentAuthor "documentAuthor" +#define NID_documentAuthor 471 +#define OBJ_documentAuthor OBJ_pilotAttributeType,14L + +#define LN_documentLocation "documentLocation" +#define NID_documentLocation 472 +#define OBJ_documentLocation OBJ_pilotAttributeType,15L + +#define LN_homeTelephoneNumber "homeTelephoneNumber" +#define NID_homeTelephoneNumber 473 +#define OBJ_homeTelephoneNumber OBJ_pilotAttributeType,20L + +#define SN_secretary "secretary" +#define NID_secretary 474 +#define OBJ_secretary OBJ_pilotAttributeType,21L + +#define LN_otherMailbox "otherMailbox" +#define NID_otherMailbox 475 +#define OBJ_otherMailbox OBJ_pilotAttributeType,22L + +#define LN_lastModifiedTime "lastModifiedTime" +#define NID_lastModifiedTime 476 +#define OBJ_lastModifiedTime OBJ_pilotAttributeType,23L + +#define LN_lastModifiedBy "lastModifiedBy" +#define NID_lastModifiedBy 477 +#define OBJ_lastModifiedBy OBJ_pilotAttributeType,24L + +#define SN_domainComponent "DC" +#define LN_domainComponent "domainComponent" +#define NID_domainComponent 391 +#define OBJ_domainComponent OBJ_pilotAttributeType,25L + +#define LN_aRecord "aRecord" +#define NID_aRecord 478 +#define OBJ_aRecord OBJ_pilotAttributeType,26L + +#define LN_pilotAttributeType27 "pilotAttributeType27" +#define NID_pilotAttributeType27 479 +#define OBJ_pilotAttributeType27 OBJ_pilotAttributeType,27L + +#define LN_mXRecord "mXRecord" +#define NID_mXRecord 480 +#define OBJ_mXRecord OBJ_pilotAttributeType,28L + +#define LN_nSRecord "nSRecord" +#define NID_nSRecord 481 +#define OBJ_nSRecord OBJ_pilotAttributeType,29L + +#define LN_sOARecord "sOARecord" +#define NID_sOARecord 482 +#define OBJ_sOARecord OBJ_pilotAttributeType,30L + +#define LN_cNAMERecord "cNAMERecord" +#define NID_cNAMERecord 483 +#define OBJ_cNAMERecord OBJ_pilotAttributeType,31L + +#define LN_associatedDomain "associatedDomain" +#define NID_associatedDomain 484 +#define OBJ_associatedDomain OBJ_pilotAttributeType,37L + +#define LN_associatedName "associatedName" +#define NID_associatedName 485 +#define OBJ_associatedName OBJ_pilotAttributeType,38L + +#define LN_homePostalAddress "homePostalAddress" +#define NID_homePostalAddress 486 +#define OBJ_homePostalAddress OBJ_pilotAttributeType,39L + +#define LN_personalTitle "personalTitle" +#define NID_personalTitle 487 +#define OBJ_personalTitle OBJ_pilotAttributeType,40L + +#define LN_mobileTelephoneNumber "mobileTelephoneNumber" +#define NID_mobileTelephoneNumber 488 +#define OBJ_mobileTelephoneNumber OBJ_pilotAttributeType,41L + +#define LN_pagerTelephoneNumber "pagerTelephoneNumber" +#define NID_pagerTelephoneNumber 489 +#define OBJ_pagerTelephoneNumber OBJ_pilotAttributeType,42L + +#define LN_friendlyCountryName "friendlyCountryName" +#define NID_friendlyCountryName 490 +#define OBJ_friendlyCountryName OBJ_pilotAttributeType,43L + +#define SN_uniqueIdentifier "uid" +#define LN_uniqueIdentifier "uniqueIdentifier" +#define NID_uniqueIdentifier 102 +#define OBJ_uniqueIdentifier OBJ_pilotAttributeType,44L + +#define LN_organizationalStatus "organizationalStatus" +#define NID_organizationalStatus 491 +#define OBJ_organizationalStatus OBJ_pilotAttributeType,45L + +#define LN_janetMailbox "janetMailbox" +#define NID_janetMailbox 492 +#define OBJ_janetMailbox OBJ_pilotAttributeType,46L + +#define LN_mailPreferenceOption "mailPreferenceOption" +#define NID_mailPreferenceOption 493 +#define OBJ_mailPreferenceOption OBJ_pilotAttributeType,47L + +#define LN_buildingName "buildingName" +#define NID_buildingName 494 +#define OBJ_buildingName OBJ_pilotAttributeType,48L + +#define LN_dSAQuality "dSAQuality" +#define NID_dSAQuality 495 +#define OBJ_dSAQuality OBJ_pilotAttributeType,49L + +#define LN_singleLevelQuality "singleLevelQuality" +#define NID_singleLevelQuality 496 +#define OBJ_singleLevelQuality OBJ_pilotAttributeType,50L + +#define LN_subtreeMinimumQuality "subtreeMinimumQuality" +#define NID_subtreeMinimumQuality 497 +#define OBJ_subtreeMinimumQuality OBJ_pilotAttributeType,51L + +#define LN_subtreeMaximumQuality "subtreeMaximumQuality" +#define NID_subtreeMaximumQuality 498 +#define OBJ_subtreeMaximumQuality OBJ_pilotAttributeType,52L + +#define LN_personalSignature "personalSignature" +#define NID_personalSignature 499 +#define OBJ_personalSignature OBJ_pilotAttributeType,53L + +#define LN_dITRedirect "dITRedirect" +#define NID_dITRedirect 500 +#define OBJ_dITRedirect OBJ_pilotAttributeType,54L + +#define SN_audio "audio" +#define NID_audio 501 +#define OBJ_audio OBJ_pilotAttributeType,55L + +#define LN_documentPublisher "documentPublisher" +#define NID_documentPublisher 502 +#define OBJ_documentPublisher OBJ_pilotAttributeType,56L + +#define SN_id_set "id-set" +#define LN_id_set "Secure Electronic Transactions" +#define NID_id_set 512 +#define OBJ_id_set OBJ_international_organizations,42L + +#define SN_set_ctype "set-ctype" +#define LN_set_ctype "content types" +#define NID_set_ctype 513 +#define OBJ_set_ctype OBJ_id_set,0L + +#define SN_set_msgExt "set-msgExt" +#define LN_set_msgExt "message extensions" +#define NID_set_msgExt 514 +#define OBJ_set_msgExt OBJ_id_set,1L + +#define SN_set_attr "set-attr" +#define NID_set_attr 515 +#define OBJ_set_attr OBJ_id_set,3L + +#define SN_set_policy "set-policy" +#define NID_set_policy 516 +#define OBJ_set_policy OBJ_id_set,5L + +#define SN_set_certExt "set-certExt" +#define LN_set_certExt "certificate extensions" +#define NID_set_certExt 517 +#define OBJ_set_certExt OBJ_id_set,7L + +#define SN_set_brand "set-brand" +#define NID_set_brand 518 +#define OBJ_set_brand OBJ_id_set,8L + +#define SN_setct_PANData "setct-PANData" +#define NID_setct_PANData 519 +#define OBJ_setct_PANData OBJ_set_ctype,0L + +#define SN_setct_PANToken "setct-PANToken" +#define NID_setct_PANToken 520 +#define OBJ_setct_PANToken OBJ_set_ctype,1L + +#define SN_setct_PANOnly "setct-PANOnly" +#define NID_setct_PANOnly 521 +#define OBJ_setct_PANOnly OBJ_set_ctype,2L + +#define SN_setct_OIData "setct-OIData" +#define NID_setct_OIData 522 +#define OBJ_setct_OIData OBJ_set_ctype,3L + +#define SN_setct_PI "setct-PI" +#define NID_setct_PI 523 +#define OBJ_setct_PI OBJ_set_ctype,4L + +#define SN_setct_PIData "setct-PIData" +#define NID_setct_PIData 524 +#define OBJ_setct_PIData OBJ_set_ctype,5L + +#define SN_setct_PIDataUnsigned "setct-PIDataUnsigned" +#define NID_setct_PIDataUnsigned 525 +#define OBJ_setct_PIDataUnsigned OBJ_set_ctype,6L + +#define SN_setct_HODInput "setct-HODInput" +#define NID_setct_HODInput 526 +#define OBJ_setct_HODInput OBJ_set_ctype,7L + +#define SN_setct_AuthResBaggage "setct-AuthResBaggage" +#define NID_setct_AuthResBaggage 527 +#define OBJ_setct_AuthResBaggage OBJ_set_ctype,8L + +#define SN_setct_AuthRevReqBaggage "setct-AuthRevReqBaggage" +#define NID_setct_AuthRevReqBaggage 528 +#define OBJ_setct_AuthRevReqBaggage OBJ_set_ctype,9L + +#define SN_setct_AuthRevResBaggage "setct-AuthRevResBaggage" +#define NID_setct_AuthRevResBaggage 529 +#define OBJ_setct_AuthRevResBaggage OBJ_set_ctype,10L + +#define SN_setct_CapTokenSeq "setct-CapTokenSeq" +#define NID_setct_CapTokenSeq 530 +#define OBJ_setct_CapTokenSeq OBJ_set_ctype,11L + +#define SN_setct_PInitResData "setct-PInitResData" +#define NID_setct_PInitResData 531 +#define OBJ_setct_PInitResData OBJ_set_ctype,12L + +#define SN_setct_PI_TBS "setct-PI-TBS" +#define NID_setct_PI_TBS 532 +#define OBJ_setct_PI_TBS OBJ_set_ctype,13L + +#define SN_setct_PResData "setct-PResData" +#define NID_setct_PResData 533 +#define OBJ_setct_PResData OBJ_set_ctype,14L + +#define SN_setct_AuthReqTBS "setct-AuthReqTBS" +#define NID_setct_AuthReqTBS 534 +#define OBJ_setct_AuthReqTBS OBJ_set_ctype,16L + +#define SN_setct_AuthResTBS "setct-AuthResTBS" +#define NID_setct_AuthResTBS 535 +#define OBJ_setct_AuthResTBS OBJ_set_ctype,17L + +#define SN_setct_AuthResTBSX "setct-AuthResTBSX" +#define NID_setct_AuthResTBSX 536 +#define OBJ_setct_AuthResTBSX OBJ_set_ctype,18L + +#define SN_setct_AuthTokenTBS "setct-AuthTokenTBS" +#define NID_setct_AuthTokenTBS 537 +#define OBJ_setct_AuthTokenTBS OBJ_set_ctype,19L + +#define SN_setct_CapTokenData "setct-CapTokenData" +#define NID_setct_CapTokenData 538 +#define OBJ_setct_CapTokenData OBJ_set_ctype,20L + +#define SN_setct_CapTokenTBS "setct-CapTokenTBS" +#define NID_setct_CapTokenTBS 539 +#define OBJ_setct_CapTokenTBS OBJ_set_ctype,21L + +#define SN_setct_AcqCardCodeMsg "setct-AcqCardCodeMsg" +#define NID_setct_AcqCardCodeMsg 540 +#define OBJ_setct_AcqCardCodeMsg OBJ_set_ctype,22L + +#define SN_setct_AuthRevReqTBS "setct-AuthRevReqTBS" +#define NID_setct_AuthRevReqTBS 541 +#define OBJ_setct_AuthRevReqTBS OBJ_set_ctype,23L + +#define SN_setct_AuthRevResData "setct-AuthRevResData" +#define NID_setct_AuthRevResData 542 +#define OBJ_setct_AuthRevResData OBJ_set_ctype,24L + +#define SN_setct_AuthRevResTBS "setct-AuthRevResTBS" +#define NID_setct_AuthRevResTBS 543 +#define OBJ_setct_AuthRevResTBS OBJ_set_ctype,25L + +#define SN_setct_CapReqTBS "setct-CapReqTBS" +#define NID_setct_CapReqTBS 544 +#define OBJ_setct_CapReqTBS OBJ_set_ctype,26L + +#define SN_setct_CapReqTBSX "setct-CapReqTBSX" +#define NID_setct_CapReqTBSX 545 +#define OBJ_setct_CapReqTBSX OBJ_set_ctype,27L + +#define SN_setct_CapResData "setct-CapResData" +#define NID_setct_CapResData 546 +#define OBJ_setct_CapResData OBJ_set_ctype,28L + +#define SN_setct_CapRevReqTBS "setct-CapRevReqTBS" +#define NID_setct_CapRevReqTBS 547 +#define OBJ_setct_CapRevReqTBS OBJ_set_ctype,29L + +#define SN_setct_CapRevReqTBSX "setct-CapRevReqTBSX" +#define NID_setct_CapRevReqTBSX 548 +#define OBJ_setct_CapRevReqTBSX OBJ_set_ctype,30L + +#define SN_setct_CapRevResData "setct-CapRevResData" +#define NID_setct_CapRevResData 549 +#define OBJ_setct_CapRevResData OBJ_set_ctype,31L + +#define SN_setct_CredReqTBS "setct-CredReqTBS" +#define NID_setct_CredReqTBS 550 +#define OBJ_setct_CredReqTBS OBJ_set_ctype,32L + +#define SN_setct_CredReqTBSX "setct-CredReqTBSX" +#define NID_setct_CredReqTBSX 551 +#define OBJ_setct_CredReqTBSX OBJ_set_ctype,33L + +#define SN_setct_CredResData "setct-CredResData" +#define NID_setct_CredResData 552 +#define OBJ_setct_CredResData OBJ_set_ctype,34L + +#define SN_setct_CredRevReqTBS "setct-CredRevReqTBS" +#define NID_setct_CredRevReqTBS 553 +#define OBJ_setct_CredRevReqTBS OBJ_set_ctype,35L + +#define SN_setct_CredRevReqTBSX "setct-CredRevReqTBSX" +#define NID_setct_CredRevReqTBSX 554 +#define OBJ_setct_CredRevReqTBSX OBJ_set_ctype,36L + +#define SN_setct_CredRevResData "setct-CredRevResData" +#define NID_setct_CredRevResData 555 +#define OBJ_setct_CredRevResData OBJ_set_ctype,37L + +#define SN_setct_PCertReqData "setct-PCertReqData" +#define NID_setct_PCertReqData 556 +#define OBJ_setct_PCertReqData OBJ_set_ctype,38L + +#define SN_setct_PCertResTBS "setct-PCertResTBS" +#define NID_setct_PCertResTBS 557 +#define OBJ_setct_PCertResTBS OBJ_set_ctype,39L + +#define SN_setct_BatchAdminReqData "setct-BatchAdminReqData" +#define NID_setct_BatchAdminReqData 558 +#define OBJ_setct_BatchAdminReqData OBJ_set_ctype,40L + +#define SN_setct_BatchAdminResData "setct-BatchAdminResData" +#define NID_setct_BatchAdminResData 559 +#define OBJ_setct_BatchAdminResData OBJ_set_ctype,41L + +#define SN_setct_CardCInitResTBS "setct-CardCInitResTBS" +#define NID_setct_CardCInitResTBS 560 +#define OBJ_setct_CardCInitResTBS OBJ_set_ctype,42L + +#define SN_setct_MeAqCInitResTBS "setct-MeAqCInitResTBS" +#define NID_setct_MeAqCInitResTBS 561 +#define OBJ_setct_MeAqCInitResTBS OBJ_set_ctype,43L + +#define SN_setct_RegFormResTBS "setct-RegFormResTBS" +#define NID_setct_RegFormResTBS 562 +#define OBJ_setct_RegFormResTBS OBJ_set_ctype,44L + +#define SN_setct_CertReqData "setct-CertReqData" +#define NID_setct_CertReqData 563 +#define OBJ_setct_CertReqData OBJ_set_ctype,45L + +#define SN_setct_CertReqTBS "setct-CertReqTBS" +#define NID_setct_CertReqTBS 564 +#define OBJ_setct_CertReqTBS OBJ_set_ctype,46L + +#define SN_setct_CertResData "setct-CertResData" +#define NID_setct_CertResData 565 +#define OBJ_setct_CertResData OBJ_set_ctype,47L + +#define SN_setct_CertInqReqTBS "setct-CertInqReqTBS" +#define NID_setct_CertInqReqTBS 566 +#define OBJ_setct_CertInqReqTBS OBJ_set_ctype,48L + +#define SN_setct_ErrorTBS "setct-ErrorTBS" +#define NID_setct_ErrorTBS 567 +#define OBJ_setct_ErrorTBS OBJ_set_ctype,49L + +#define SN_setct_PIDualSignedTBE "setct-PIDualSignedTBE" +#define NID_setct_PIDualSignedTBE 568 +#define OBJ_setct_PIDualSignedTBE OBJ_set_ctype,50L + +#define SN_setct_PIUnsignedTBE "setct-PIUnsignedTBE" +#define NID_setct_PIUnsignedTBE 569 +#define OBJ_setct_PIUnsignedTBE OBJ_set_ctype,51L + +#define SN_setct_AuthReqTBE "setct-AuthReqTBE" +#define NID_setct_AuthReqTBE 570 +#define OBJ_setct_AuthReqTBE OBJ_set_ctype,52L + +#define SN_setct_AuthResTBE "setct-AuthResTBE" +#define NID_setct_AuthResTBE 571 +#define OBJ_setct_AuthResTBE OBJ_set_ctype,53L + +#define SN_setct_AuthResTBEX "setct-AuthResTBEX" +#define NID_setct_AuthResTBEX 572 +#define OBJ_setct_AuthResTBEX OBJ_set_ctype,54L + +#define SN_setct_AuthTokenTBE "setct-AuthTokenTBE" +#define NID_setct_AuthTokenTBE 573 +#define OBJ_setct_AuthTokenTBE OBJ_set_ctype,55L + +#define SN_setct_CapTokenTBE "setct-CapTokenTBE" +#define NID_setct_CapTokenTBE 574 +#define OBJ_setct_CapTokenTBE OBJ_set_ctype,56L + +#define SN_setct_CapTokenTBEX "setct-CapTokenTBEX" +#define NID_setct_CapTokenTBEX 575 +#define OBJ_setct_CapTokenTBEX OBJ_set_ctype,57L + +#define SN_setct_AcqCardCodeMsgTBE "setct-AcqCardCodeMsgTBE" +#define NID_setct_AcqCardCodeMsgTBE 576 +#define OBJ_setct_AcqCardCodeMsgTBE OBJ_set_ctype,58L + +#define SN_setct_AuthRevReqTBE "setct-AuthRevReqTBE" +#define NID_setct_AuthRevReqTBE 577 +#define OBJ_setct_AuthRevReqTBE OBJ_set_ctype,59L + +#define SN_setct_AuthRevResTBE "setct-AuthRevResTBE" +#define NID_setct_AuthRevResTBE 578 +#define OBJ_setct_AuthRevResTBE OBJ_set_ctype,60L + +#define SN_setct_AuthRevResTBEB "setct-AuthRevResTBEB" +#define NID_setct_AuthRevResTBEB 579 +#define OBJ_setct_AuthRevResTBEB OBJ_set_ctype,61L + +#define SN_setct_CapReqTBE "setct-CapReqTBE" +#define NID_setct_CapReqTBE 580 +#define OBJ_setct_CapReqTBE OBJ_set_ctype,62L + +#define SN_setct_CapReqTBEX "setct-CapReqTBEX" +#define NID_setct_CapReqTBEX 581 +#define OBJ_setct_CapReqTBEX OBJ_set_ctype,63L + +#define SN_setct_CapResTBE "setct-CapResTBE" +#define NID_setct_CapResTBE 582 +#define OBJ_setct_CapResTBE OBJ_set_ctype,64L + +#define SN_setct_CapRevReqTBE "setct-CapRevReqTBE" +#define NID_setct_CapRevReqTBE 583 +#define OBJ_setct_CapRevReqTBE OBJ_set_ctype,65L + +#define SN_setct_CapRevReqTBEX "setct-CapRevReqTBEX" +#define NID_setct_CapRevReqTBEX 584 +#define OBJ_setct_CapRevReqTBEX OBJ_set_ctype,66L + +#define SN_setct_CapRevResTBE "setct-CapRevResTBE" +#define NID_setct_CapRevResTBE 585 +#define OBJ_setct_CapRevResTBE OBJ_set_ctype,67L + +#define SN_setct_CredReqTBE "setct-CredReqTBE" +#define NID_setct_CredReqTBE 586 +#define OBJ_setct_CredReqTBE OBJ_set_ctype,68L + +#define SN_setct_CredReqTBEX "setct-CredReqTBEX" +#define NID_setct_CredReqTBEX 587 +#define OBJ_setct_CredReqTBEX OBJ_set_ctype,69L + +#define SN_setct_CredResTBE "setct-CredResTBE" +#define NID_setct_CredResTBE 588 +#define OBJ_setct_CredResTBE OBJ_set_ctype,70L + +#define SN_setct_CredRevReqTBE "setct-CredRevReqTBE" +#define NID_setct_CredRevReqTBE 589 +#define OBJ_setct_CredRevReqTBE OBJ_set_ctype,71L + +#define SN_setct_CredRevReqTBEX "setct-CredRevReqTBEX" +#define NID_setct_CredRevReqTBEX 590 +#define OBJ_setct_CredRevReqTBEX OBJ_set_ctype,72L + +#define SN_setct_CredRevResTBE "setct-CredRevResTBE" +#define NID_setct_CredRevResTBE 591 +#define OBJ_setct_CredRevResTBE OBJ_set_ctype,73L + +#define SN_setct_BatchAdminReqTBE "setct-BatchAdminReqTBE" +#define NID_setct_BatchAdminReqTBE 592 +#define OBJ_setct_BatchAdminReqTBE OBJ_set_ctype,74L + +#define SN_setct_BatchAdminResTBE "setct-BatchAdminResTBE" +#define NID_setct_BatchAdminResTBE 593 +#define OBJ_setct_BatchAdminResTBE OBJ_set_ctype,75L + +#define SN_setct_RegFormReqTBE "setct-RegFormReqTBE" +#define NID_setct_RegFormReqTBE 594 +#define OBJ_setct_RegFormReqTBE OBJ_set_ctype,76L + +#define SN_setct_CertReqTBE "setct-CertReqTBE" +#define NID_setct_CertReqTBE 595 +#define OBJ_setct_CertReqTBE OBJ_set_ctype,77L + +#define SN_setct_CertReqTBEX "setct-CertReqTBEX" +#define NID_setct_CertReqTBEX 596 +#define OBJ_setct_CertReqTBEX OBJ_set_ctype,78L + +#define SN_setct_CertResTBE "setct-CertResTBE" +#define NID_setct_CertResTBE 597 +#define OBJ_setct_CertResTBE OBJ_set_ctype,79L + +#define SN_setct_CRLNotificationTBS "setct-CRLNotificationTBS" +#define NID_setct_CRLNotificationTBS 598 +#define OBJ_setct_CRLNotificationTBS OBJ_set_ctype,80L + +#define SN_setct_CRLNotificationResTBS "setct-CRLNotificationResTBS" +#define NID_setct_CRLNotificationResTBS 599 +#define OBJ_setct_CRLNotificationResTBS OBJ_set_ctype,81L + +#define SN_setct_BCIDistributionTBS "setct-BCIDistributionTBS" +#define NID_setct_BCIDistributionTBS 600 +#define OBJ_setct_BCIDistributionTBS OBJ_set_ctype,82L + +#define SN_setext_genCrypt "setext-genCrypt" +#define LN_setext_genCrypt "generic cryptogram" +#define NID_setext_genCrypt 601 +#define OBJ_setext_genCrypt OBJ_set_msgExt,1L + +#define SN_setext_miAuth "setext-miAuth" +#define LN_setext_miAuth "merchant initiated auth" +#define NID_setext_miAuth 602 +#define OBJ_setext_miAuth OBJ_set_msgExt,3L + +#define SN_setext_pinSecure "setext-pinSecure" +#define NID_setext_pinSecure 603 +#define OBJ_setext_pinSecure OBJ_set_msgExt,4L + +#define SN_setext_pinAny "setext-pinAny" +#define NID_setext_pinAny 604 +#define OBJ_setext_pinAny OBJ_set_msgExt,5L + +#define SN_setext_track2 "setext-track2" +#define NID_setext_track2 605 +#define OBJ_setext_track2 OBJ_set_msgExt,7L + +#define SN_setext_cv "setext-cv" +#define LN_setext_cv "additional verification" +#define NID_setext_cv 606 +#define OBJ_setext_cv OBJ_set_msgExt,8L + +#define SN_set_policy_root "set-policy-root" +#define NID_set_policy_root 607 +#define OBJ_set_policy_root OBJ_set_policy,0L + +#define SN_setCext_hashedRoot "setCext-hashedRoot" +#define NID_setCext_hashedRoot 608 +#define OBJ_setCext_hashedRoot OBJ_set_certExt,0L + +#define SN_setCext_certType "setCext-certType" +#define NID_setCext_certType 609 +#define OBJ_setCext_certType OBJ_set_certExt,1L + +#define SN_setCext_merchData "setCext-merchData" +#define NID_setCext_merchData 610 +#define OBJ_setCext_merchData OBJ_set_certExt,2L + +#define SN_setCext_cCertRequired "setCext-cCertRequired" +#define NID_setCext_cCertRequired 611 +#define OBJ_setCext_cCertRequired OBJ_set_certExt,3L + +#define SN_setCext_tunneling "setCext-tunneling" +#define NID_setCext_tunneling 612 +#define OBJ_setCext_tunneling OBJ_set_certExt,4L + +#define SN_setCext_setExt "setCext-setExt" +#define NID_setCext_setExt 613 +#define OBJ_setCext_setExt OBJ_set_certExt,5L + +#define SN_setCext_setQualf "setCext-setQualf" +#define NID_setCext_setQualf 614 +#define OBJ_setCext_setQualf OBJ_set_certExt,6L + +#define SN_setCext_PGWYcapabilities "setCext-PGWYcapabilities" +#define NID_setCext_PGWYcapabilities 615 +#define OBJ_setCext_PGWYcapabilities OBJ_set_certExt,7L + +#define SN_setCext_TokenIdentifier "setCext-TokenIdentifier" +#define NID_setCext_TokenIdentifier 616 +#define OBJ_setCext_TokenIdentifier OBJ_set_certExt,8L + +#define SN_setCext_Track2Data "setCext-Track2Data" +#define NID_setCext_Track2Data 617 +#define OBJ_setCext_Track2Data OBJ_set_certExt,9L + +#define SN_setCext_TokenType "setCext-TokenType" +#define NID_setCext_TokenType 618 +#define OBJ_setCext_TokenType OBJ_set_certExt,10L + +#define SN_setCext_IssuerCapabilities "setCext-IssuerCapabilities" +#define NID_setCext_IssuerCapabilities 619 +#define OBJ_setCext_IssuerCapabilities OBJ_set_certExt,11L + +#define SN_setAttr_Cert "setAttr-Cert" +#define NID_setAttr_Cert 620 +#define OBJ_setAttr_Cert OBJ_set_attr,0L + +#define SN_setAttr_PGWYcap "setAttr-PGWYcap" +#define LN_setAttr_PGWYcap "payment gateway capabilities" +#define NID_setAttr_PGWYcap 621 +#define OBJ_setAttr_PGWYcap OBJ_set_attr,1L + +#define SN_setAttr_TokenType "setAttr-TokenType" +#define NID_setAttr_TokenType 622 +#define OBJ_setAttr_TokenType OBJ_set_attr,2L + +#define SN_setAttr_IssCap "setAttr-IssCap" +#define LN_setAttr_IssCap "issuer capabilities" +#define NID_setAttr_IssCap 623 +#define OBJ_setAttr_IssCap OBJ_set_attr,3L + +#define SN_set_rootKeyThumb "set-rootKeyThumb" +#define NID_set_rootKeyThumb 624 +#define OBJ_set_rootKeyThumb OBJ_setAttr_Cert,0L + +#define SN_set_addPolicy "set-addPolicy" +#define NID_set_addPolicy 625 +#define OBJ_set_addPolicy OBJ_setAttr_Cert,1L + +#define SN_setAttr_Token_EMV "setAttr-Token-EMV" +#define NID_setAttr_Token_EMV 626 +#define OBJ_setAttr_Token_EMV OBJ_setAttr_TokenType,1L + +#define SN_setAttr_Token_B0Prime "setAttr-Token-B0Prime" +#define NID_setAttr_Token_B0Prime 627 +#define OBJ_setAttr_Token_B0Prime OBJ_setAttr_TokenType,2L + +#define SN_setAttr_IssCap_CVM "setAttr-IssCap-CVM" +#define NID_setAttr_IssCap_CVM 628 +#define OBJ_setAttr_IssCap_CVM OBJ_setAttr_IssCap,3L + +#define SN_setAttr_IssCap_T2 "setAttr-IssCap-T2" +#define NID_setAttr_IssCap_T2 629 +#define OBJ_setAttr_IssCap_T2 OBJ_setAttr_IssCap,4L + +#define SN_setAttr_IssCap_Sig "setAttr-IssCap-Sig" +#define NID_setAttr_IssCap_Sig 630 +#define OBJ_setAttr_IssCap_Sig OBJ_setAttr_IssCap,5L + +#define SN_setAttr_GenCryptgrm "setAttr-GenCryptgrm" +#define LN_setAttr_GenCryptgrm "generate cryptogram" +#define NID_setAttr_GenCryptgrm 631 +#define OBJ_setAttr_GenCryptgrm OBJ_setAttr_IssCap_CVM,1L + +#define SN_setAttr_T2Enc "setAttr-T2Enc" +#define LN_setAttr_T2Enc "encrypted track 2" +#define NID_setAttr_T2Enc 632 +#define OBJ_setAttr_T2Enc OBJ_setAttr_IssCap_T2,1L + +#define SN_setAttr_T2cleartxt "setAttr-T2cleartxt" +#define LN_setAttr_T2cleartxt "cleartext track 2" +#define NID_setAttr_T2cleartxt 633 +#define OBJ_setAttr_T2cleartxt OBJ_setAttr_IssCap_T2,2L + +#define SN_setAttr_TokICCsig "setAttr-TokICCsig" +#define LN_setAttr_TokICCsig "ICC or token signature" +#define NID_setAttr_TokICCsig 634 +#define OBJ_setAttr_TokICCsig OBJ_setAttr_IssCap_Sig,1L + +#define SN_setAttr_SecDevSig "setAttr-SecDevSig" +#define LN_setAttr_SecDevSig "secure device signature" +#define NID_setAttr_SecDevSig 635 +#define OBJ_setAttr_SecDevSig OBJ_setAttr_IssCap_Sig,2L + +#define SN_set_brand_IATA_ATA "set-brand-IATA-ATA" +#define NID_set_brand_IATA_ATA 636 +#define OBJ_set_brand_IATA_ATA OBJ_set_brand,1L + +#define SN_set_brand_Diners "set-brand-Diners" +#define NID_set_brand_Diners 637 +#define OBJ_set_brand_Diners OBJ_set_brand,30L + +#define SN_set_brand_AmericanExpress "set-brand-AmericanExpress" +#define NID_set_brand_AmericanExpress 638 +#define OBJ_set_brand_AmericanExpress OBJ_set_brand,34L + +#define SN_set_brand_JCB "set-brand-JCB" +#define NID_set_brand_JCB 639 +#define OBJ_set_brand_JCB OBJ_set_brand,35L + +#define SN_set_brand_Visa "set-brand-Visa" +#define NID_set_brand_Visa 640 +#define OBJ_set_brand_Visa OBJ_set_brand,4L + +#define SN_set_brand_MasterCard "set-brand-MasterCard" +#define NID_set_brand_MasterCard 641 +#define OBJ_set_brand_MasterCard OBJ_set_brand,5L + +#define SN_set_brand_Novus "set-brand-Novus" +#define NID_set_brand_Novus 642 +#define OBJ_set_brand_Novus OBJ_set_brand,6011L + +#define SN_des_cdmf "DES-CDMF" +#define LN_des_cdmf "des-cdmf" +#define NID_des_cdmf 643 +#define OBJ_des_cdmf OBJ_rsadsi,3L,10L + +#define SN_rsaOAEPEncryptionSET "rsaOAEPEncryptionSET" +#define NID_rsaOAEPEncryptionSET 644 +#define OBJ_rsaOAEPEncryptionSET OBJ_rsadsi,1L,1L,6L + +#define SN_ipsec3 "Oakley-EC2N-3" +#define LN_ipsec3 "ipsec3" +#define NID_ipsec3 749 + +#define SN_ipsec4 "Oakley-EC2N-4" +#define LN_ipsec4 "ipsec4" +#define NID_ipsec4 750 + +#define SN_whirlpool "whirlpool" +#define NID_whirlpool 804 +#define OBJ_whirlpool OBJ_iso,0L,10118L,3L,0L,55L + +#define SN_cryptopro "cryptopro" +#define NID_cryptopro 805 +#define OBJ_cryptopro OBJ_member_body,643L,2L,2L + +#define SN_cryptocom "cryptocom" +#define NID_cryptocom 806 +#define OBJ_cryptocom OBJ_member_body,643L,2L,9L + +#define SN_id_tc26 "id-tc26" +#define NID_id_tc26 974 +#define OBJ_id_tc26 OBJ_member_body,643L,7L,1L + +#define SN_id_GostR3411_94_with_GostR3410_2001 "id-GostR3411-94-with-GostR3410-2001" +#define LN_id_GostR3411_94_with_GostR3410_2001 "GOST R 34.11-94 with GOST R 34.10-2001" +#define NID_id_GostR3411_94_with_GostR3410_2001 807 +#define OBJ_id_GostR3411_94_with_GostR3410_2001 OBJ_cryptopro,3L + +#define SN_id_GostR3411_94_with_GostR3410_94 "id-GostR3411-94-with-GostR3410-94" +#define LN_id_GostR3411_94_with_GostR3410_94 "GOST R 34.11-94 with GOST R 34.10-94" +#define NID_id_GostR3411_94_with_GostR3410_94 808 +#define OBJ_id_GostR3411_94_with_GostR3410_94 OBJ_cryptopro,4L + +#define SN_id_GostR3411_94 "md_gost94" +#define LN_id_GostR3411_94 "GOST R 34.11-94" +#define NID_id_GostR3411_94 809 +#define OBJ_id_GostR3411_94 OBJ_cryptopro,9L + +#define SN_id_HMACGostR3411_94 "id-HMACGostR3411-94" +#define LN_id_HMACGostR3411_94 "HMAC GOST 34.11-94" +#define NID_id_HMACGostR3411_94 810 +#define OBJ_id_HMACGostR3411_94 OBJ_cryptopro,10L + +#define SN_id_GostR3410_2001 "gost2001" +#define LN_id_GostR3410_2001 "GOST R 34.10-2001" +#define NID_id_GostR3410_2001 811 +#define OBJ_id_GostR3410_2001 OBJ_cryptopro,19L + +#define SN_id_GostR3410_94 "gost94" +#define LN_id_GostR3410_94 "GOST R 34.10-94" +#define NID_id_GostR3410_94 812 +#define OBJ_id_GostR3410_94 OBJ_cryptopro,20L + +#define SN_id_Gost28147_89 "gost89" +#define LN_id_Gost28147_89 "GOST 28147-89" +#define NID_id_Gost28147_89 813 +#define OBJ_id_Gost28147_89 OBJ_cryptopro,21L + +#define SN_gost89_cnt "gost89-cnt" +#define NID_gost89_cnt 814 + +#define SN_gost89_cnt_12 "gost89-cnt-12" +#define NID_gost89_cnt_12 975 + +#define SN_gost89_cbc "gost89-cbc" +#define NID_gost89_cbc 1009 + +#define SN_gost89_ecb "gost89-ecb" +#define NID_gost89_ecb 1010 + +#define SN_gost89_ctr "gost89-ctr" +#define NID_gost89_ctr 1011 + +#define SN_id_Gost28147_89_MAC "gost-mac" +#define LN_id_Gost28147_89_MAC "GOST 28147-89 MAC" +#define NID_id_Gost28147_89_MAC 815 +#define OBJ_id_Gost28147_89_MAC OBJ_cryptopro,22L + +#define SN_gost_mac_12 "gost-mac-12" +#define NID_gost_mac_12 976 + +#define SN_id_GostR3411_94_prf "prf-gostr3411-94" +#define LN_id_GostR3411_94_prf "GOST R 34.11-94 PRF" +#define NID_id_GostR3411_94_prf 816 +#define OBJ_id_GostR3411_94_prf OBJ_cryptopro,23L + +#define SN_id_GostR3410_2001DH "id-GostR3410-2001DH" +#define LN_id_GostR3410_2001DH "GOST R 34.10-2001 DH" +#define NID_id_GostR3410_2001DH 817 +#define OBJ_id_GostR3410_2001DH OBJ_cryptopro,98L + +#define SN_id_GostR3410_94DH "id-GostR3410-94DH" +#define LN_id_GostR3410_94DH "GOST R 34.10-94 DH" +#define NID_id_GostR3410_94DH 818 +#define OBJ_id_GostR3410_94DH OBJ_cryptopro,99L + +#define SN_id_Gost28147_89_CryptoPro_KeyMeshing "id-Gost28147-89-CryptoPro-KeyMeshing" +#define NID_id_Gost28147_89_CryptoPro_KeyMeshing 819 +#define OBJ_id_Gost28147_89_CryptoPro_KeyMeshing OBJ_cryptopro,14L,1L + +#define SN_id_Gost28147_89_None_KeyMeshing "id-Gost28147-89-None-KeyMeshing" +#define NID_id_Gost28147_89_None_KeyMeshing 820 +#define OBJ_id_Gost28147_89_None_KeyMeshing OBJ_cryptopro,14L,0L + +#define SN_id_GostR3411_94_TestParamSet "id-GostR3411-94-TestParamSet" +#define NID_id_GostR3411_94_TestParamSet 821 +#define OBJ_id_GostR3411_94_TestParamSet OBJ_cryptopro,30L,0L + +#define SN_id_GostR3411_94_CryptoProParamSet "id-GostR3411-94-CryptoProParamSet" +#define NID_id_GostR3411_94_CryptoProParamSet 822 +#define OBJ_id_GostR3411_94_CryptoProParamSet OBJ_cryptopro,30L,1L + +#define SN_id_Gost28147_89_TestParamSet "id-Gost28147-89-TestParamSet" +#define NID_id_Gost28147_89_TestParamSet 823 +#define OBJ_id_Gost28147_89_TestParamSet OBJ_cryptopro,31L,0L + +#define SN_id_Gost28147_89_CryptoPro_A_ParamSet "id-Gost28147-89-CryptoPro-A-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_A_ParamSet 824 +#define OBJ_id_Gost28147_89_CryptoPro_A_ParamSet OBJ_cryptopro,31L,1L + +#define SN_id_Gost28147_89_CryptoPro_B_ParamSet "id-Gost28147-89-CryptoPro-B-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_B_ParamSet 825 +#define OBJ_id_Gost28147_89_CryptoPro_B_ParamSet OBJ_cryptopro,31L,2L + +#define SN_id_Gost28147_89_CryptoPro_C_ParamSet "id-Gost28147-89-CryptoPro-C-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_C_ParamSet 826 +#define OBJ_id_Gost28147_89_CryptoPro_C_ParamSet OBJ_cryptopro,31L,3L + +#define SN_id_Gost28147_89_CryptoPro_D_ParamSet "id-Gost28147-89-CryptoPro-D-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_D_ParamSet 827 +#define OBJ_id_Gost28147_89_CryptoPro_D_ParamSet OBJ_cryptopro,31L,4L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet 828 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet OBJ_cryptopro,31L,5L + +#define SN_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet "id-Gost28147-89-CryptoPro-Oscar-1-0-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet 829 +#define OBJ_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet OBJ_cryptopro,31L,6L + +#define SN_id_Gost28147_89_CryptoPro_RIC_1_ParamSet "id-Gost28147-89-CryptoPro-RIC-1-ParamSet" +#define NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet 830 +#define OBJ_id_Gost28147_89_CryptoPro_RIC_1_ParamSet OBJ_cryptopro,31L,7L + +#define SN_id_GostR3410_94_TestParamSet "id-GostR3410-94-TestParamSet" +#define NID_id_GostR3410_94_TestParamSet 831 +#define OBJ_id_GostR3410_94_TestParamSet OBJ_cryptopro,32L,0L + +#define SN_id_GostR3410_94_CryptoPro_A_ParamSet "id-GostR3410-94-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_A_ParamSet 832 +#define OBJ_id_GostR3410_94_CryptoPro_A_ParamSet OBJ_cryptopro,32L,2L + +#define SN_id_GostR3410_94_CryptoPro_B_ParamSet "id-GostR3410-94-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_B_ParamSet 833 +#define OBJ_id_GostR3410_94_CryptoPro_B_ParamSet OBJ_cryptopro,32L,3L + +#define SN_id_GostR3410_94_CryptoPro_C_ParamSet "id-GostR3410-94-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_C_ParamSet 834 +#define OBJ_id_GostR3410_94_CryptoPro_C_ParamSet OBJ_cryptopro,32L,4L + +#define SN_id_GostR3410_94_CryptoPro_D_ParamSet "id-GostR3410-94-CryptoPro-D-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_D_ParamSet 835 +#define OBJ_id_GostR3410_94_CryptoPro_D_ParamSet OBJ_cryptopro,32L,5L + +#define SN_id_GostR3410_94_CryptoPro_XchA_ParamSet "id-GostR3410-94-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchA_ParamSet 836 +#define OBJ_id_GostR3410_94_CryptoPro_XchA_ParamSet OBJ_cryptopro,33L,1L + +#define SN_id_GostR3410_94_CryptoPro_XchB_ParamSet "id-GostR3410-94-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchB_ParamSet 837 +#define OBJ_id_GostR3410_94_CryptoPro_XchB_ParamSet OBJ_cryptopro,33L,2L + +#define SN_id_GostR3410_94_CryptoPro_XchC_ParamSet "id-GostR3410-94-CryptoPro-XchC-ParamSet" +#define NID_id_GostR3410_94_CryptoPro_XchC_ParamSet 838 +#define OBJ_id_GostR3410_94_CryptoPro_XchC_ParamSet OBJ_cryptopro,33L,3L + +#define SN_id_GostR3410_2001_TestParamSet "id-GostR3410-2001-TestParamSet" +#define NID_id_GostR3410_2001_TestParamSet 839 +#define OBJ_id_GostR3410_2001_TestParamSet OBJ_cryptopro,35L,0L + +#define SN_id_GostR3410_2001_CryptoPro_A_ParamSet "id-GostR3410-2001-CryptoPro-A-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_A_ParamSet 840 +#define OBJ_id_GostR3410_2001_CryptoPro_A_ParamSet OBJ_cryptopro,35L,1L + +#define SN_id_GostR3410_2001_CryptoPro_B_ParamSet "id-GostR3410-2001-CryptoPro-B-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_B_ParamSet 841 +#define OBJ_id_GostR3410_2001_CryptoPro_B_ParamSet OBJ_cryptopro,35L,2L + +#define SN_id_GostR3410_2001_CryptoPro_C_ParamSet "id-GostR3410-2001-CryptoPro-C-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_C_ParamSet 842 +#define OBJ_id_GostR3410_2001_CryptoPro_C_ParamSet OBJ_cryptopro,35L,3L + +#define SN_id_GostR3410_2001_CryptoPro_XchA_ParamSet "id-GostR3410-2001-CryptoPro-XchA-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet 843 +#define OBJ_id_GostR3410_2001_CryptoPro_XchA_ParamSet OBJ_cryptopro,36L,0L + +#define SN_id_GostR3410_2001_CryptoPro_XchB_ParamSet "id-GostR3410-2001-CryptoPro-XchB-ParamSet" +#define NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet 844 +#define OBJ_id_GostR3410_2001_CryptoPro_XchB_ParamSet OBJ_cryptopro,36L,1L + +#define SN_id_GostR3410_94_a "id-GostR3410-94-a" +#define NID_id_GostR3410_94_a 845 +#define OBJ_id_GostR3410_94_a OBJ_id_GostR3410_94,1L + +#define SN_id_GostR3410_94_aBis "id-GostR3410-94-aBis" +#define NID_id_GostR3410_94_aBis 846 +#define OBJ_id_GostR3410_94_aBis OBJ_id_GostR3410_94,2L + +#define SN_id_GostR3410_94_b "id-GostR3410-94-b" +#define NID_id_GostR3410_94_b 847 +#define OBJ_id_GostR3410_94_b OBJ_id_GostR3410_94,3L + +#define SN_id_GostR3410_94_bBis "id-GostR3410-94-bBis" +#define NID_id_GostR3410_94_bBis 848 +#define OBJ_id_GostR3410_94_bBis OBJ_id_GostR3410_94,4L + +#define SN_id_Gost28147_89_cc "id-Gost28147-89-cc" +#define LN_id_Gost28147_89_cc "GOST 28147-89 Cryptocom ParamSet" +#define NID_id_Gost28147_89_cc 849 +#define OBJ_id_Gost28147_89_cc OBJ_cryptocom,1L,6L,1L + +#define SN_id_GostR3410_94_cc "gost94cc" +#define LN_id_GostR3410_94_cc "GOST 34.10-94 Cryptocom" +#define NID_id_GostR3410_94_cc 850 +#define OBJ_id_GostR3410_94_cc OBJ_cryptocom,1L,5L,3L + +#define SN_id_GostR3410_2001_cc "gost2001cc" +#define LN_id_GostR3410_2001_cc "GOST 34.10-2001 Cryptocom" +#define NID_id_GostR3410_2001_cc 851 +#define OBJ_id_GostR3410_2001_cc OBJ_cryptocom,1L,5L,4L + +#define SN_id_GostR3411_94_with_GostR3410_94_cc "id-GostR3411-94-with-GostR3410-94-cc" +#define LN_id_GostR3411_94_with_GostR3410_94_cc "GOST R 34.11-94 with GOST R 34.10-94 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_94_cc 852 +#define OBJ_id_GostR3411_94_with_GostR3410_94_cc OBJ_cryptocom,1L,3L,3L + +#define SN_id_GostR3411_94_with_GostR3410_2001_cc "id-GostR3411-94-with-GostR3410-2001-cc" +#define LN_id_GostR3411_94_with_GostR3410_2001_cc "GOST R 34.11-94 with GOST R 34.10-2001 Cryptocom" +#define NID_id_GostR3411_94_with_GostR3410_2001_cc 853 +#define OBJ_id_GostR3411_94_with_GostR3410_2001_cc OBJ_cryptocom,1L,3L,4L + +#define SN_id_GostR3410_2001_ParamSet_cc "id-GostR3410-2001-ParamSet-cc" +#define LN_id_GostR3410_2001_ParamSet_cc "GOST R 3410-2001 Parameter Set Cryptocom" +#define NID_id_GostR3410_2001_ParamSet_cc 854 +#define OBJ_id_GostR3410_2001_ParamSet_cc OBJ_cryptocom,1L,8L,1L + +#define SN_id_tc26_algorithms "id-tc26-algorithms" +#define NID_id_tc26_algorithms 977 +#define OBJ_id_tc26_algorithms OBJ_id_tc26,1L + +#define SN_id_tc26_sign "id-tc26-sign" +#define NID_id_tc26_sign 978 +#define OBJ_id_tc26_sign OBJ_id_tc26_algorithms,1L + +#define SN_id_GostR3410_2012_256 "gost2012_256" +#define LN_id_GostR3410_2012_256 "GOST R 34.10-2012 with 256 bit modulus" +#define NID_id_GostR3410_2012_256 979 +#define OBJ_id_GostR3410_2012_256 OBJ_id_tc26_sign,1L + +#define SN_id_GostR3410_2012_512 "gost2012_512" +#define LN_id_GostR3410_2012_512 "GOST R 34.10-2012 with 512 bit modulus" +#define NID_id_GostR3410_2012_512 980 +#define OBJ_id_GostR3410_2012_512 OBJ_id_tc26_sign,2L + +#define SN_id_tc26_digest "id-tc26-digest" +#define NID_id_tc26_digest 981 +#define OBJ_id_tc26_digest OBJ_id_tc26_algorithms,2L + +#define SN_id_GostR3411_2012_256 "md_gost12_256" +#define LN_id_GostR3411_2012_256 "GOST R 34.11-2012 with 256 bit hash" +#define NID_id_GostR3411_2012_256 982 +#define OBJ_id_GostR3411_2012_256 OBJ_id_tc26_digest,2L + +#define SN_id_GostR3411_2012_512 "md_gost12_512" +#define LN_id_GostR3411_2012_512 "GOST R 34.11-2012 with 512 bit hash" +#define NID_id_GostR3411_2012_512 983 +#define OBJ_id_GostR3411_2012_512 OBJ_id_tc26_digest,3L + +#define SN_id_tc26_signwithdigest "id-tc26-signwithdigest" +#define NID_id_tc26_signwithdigest 984 +#define OBJ_id_tc26_signwithdigest OBJ_id_tc26_algorithms,3L + +#define SN_id_tc26_signwithdigest_gost3410_2012_256 "id-tc26-signwithdigest-gost3410-2012-256" +#define LN_id_tc26_signwithdigest_gost3410_2012_256 "GOST R 34.10-2012 with GOST R 34.11-2012 (256 bit)" +#define NID_id_tc26_signwithdigest_gost3410_2012_256 985 +#define OBJ_id_tc26_signwithdigest_gost3410_2012_256 OBJ_id_tc26_signwithdigest,2L + +#define SN_id_tc26_signwithdigest_gost3410_2012_512 "id-tc26-signwithdigest-gost3410-2012-512" +#define LN_id_tc26_signwithdigest_gost3410_2012_512 "GOST R 34.10-2012 with GOST R 34.11-2012 (512 bit)" +#define NID_id_tc26_signwithdigest_gost3410_2012_512 986 +#define OBJ_id_tc26_signwithdigest_gost3410_2012_512 OBJ_id_tc26_signwithdigest,3L + +#define SN_id_tc26_mac "id-tc26-mac" +#define NID_id_tc26_mac 987 +#define OBJ_id_tc26_mac OBJ_id_tc26_algorithms,4L + +#define SN_id_tc26_hmac_gost_3411_2012_256 "id-tc26-hmac-gost-3411-2012-256" +#define LN_id_tc26_hmac_gost_3411_2012_256 "HMAC GOST 34.11-2012 256 bit" +#define NID_id_tc26_hmac_gost_3411_2012_256 988 +#define OBJ_id_tc26_hmac_gost_3411_2012_256 OBJ_id_tc26_mac,1L + +#define SN_id_tc26_hmac_gost_3411_2012_512 "id-tc26-hmac-gost-3411-2012-512" +#define LN_id_tc26_hmac_gost_3411_2012_512 "HMAC GOST 34.11-2012 512 bit" +#define NID_id_tc26_hmac_gost_3411_2012_512 989 +#define OBJ_id_tc26_hmac_gost_3411_2012_512 OBJ_id_tc26_mac,2L + +#define SN_id_tc26_cipher "id-tc26-cipher" +#define NID_id_tc26_cipher 990 +#define OBJ_id_tc26_cipher OBJ_id_tc26_algorithms,5L + +#define SN_id_tc26_cipher_gostr3412_2015_magma "id-tc26-cipher-gostr3412-2015-magma" +#define NID_id_tc26_cipher_gostr3412_2015_magma 1173 +#define OBJ_id_tc26_cipher_gostr3412_2015_magma OBJ_id_tc26_cipher,1L + +#define SN_id_tc26_cipher_gostr3412_2015_magma_ctracpkm "id-tc26-cipher-gostr3412-2015-magma-ctracpkm" +#define NID_id_tc26_cipher_gostr3412_2015_magma_ctracpkm 1174 +#define OBJ_id_tc26_cipher_gostr3412_2015_magma_ctracpkm OBJ_id_tc26_cipher_gostr3412_2015_magma,1L + +#define SN_id_tc26_cipher_gostr3412_2015_magma_ctracpkm_omac "id-tc26-cipher-gostr3412-2015-magma-ctracpkm-omac" +#define NID_id_tc26_cipher_gostr3412_2015_magma_ctracpkm_omac 1175 +#define OBJ_id_tc26_cipher_gostr3412_2015_magma_ctracpkm_omac OBJ_id_tc26_cipher_gostr3412_2015_magma,2L + +#define SN_id_tc26_cipher_gostr3412_2015_kuznyechik "id-tc26-cipher-gostr3412-2015-kuznyechik" +#define NID_id_tc26_cipher_gostr3412_2015_kuznyechik 1176 +#define OBJ_id_tc26_cipher_gostr3412_2015_kuznyechik OBJ_id_tc26_cipher,2L + +#define SN_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm "id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm" +#define NID_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm 1177 +#define OBJ_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm OBJ_id_tc26_cipher_gostr3412_2015_kuznyechik,1L + +#define SN_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm_omac "id-tc26-cipher-gostr3412-2015-kuznyechik-ctracpkm-omac" +#define NID_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm_omac 1178 +#define OBJ_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm_omac OBJ_id_tc26_cipher_gostr3412_2015_kuznyechik,2L + +#define SN_id_tc26_agreement "id-tc26-agreement" +#define NID_id_tc26_agreement 991 +#define OBJ_id_tc26_agreement OBJ_id_tc26_algorithms,6L + +#define SN_id_tc26_agreement_gost_3410_2012_256 "id-tc26-agreement-gost-3410-2012-256" +#define NID_id_tc26_agreement_gost_3410_2012_256 992 +#define OBJ_id_tc26_agreement_gost_3410_2012_256 OBJ_id_tc26_agreement,1L + +#define SN_id_tc26_agreement_gost_3410_2012_512 "id-tc26-agreement-gost-3410-2012-512" +#define NID_id_tc26_agreement_gost_3410_2012_512 993 +#define OBJ_id_tc26_agreement_gost_3410_2012_512 OBJ_id_tc26_agreement,2L + +#define SN_id_tc26_wrap "id-tc26-wrap" +#define NID_id_tc26_wrap 1179 +#define OBJ_id_tc26_wrap OBJ_id_tc26_algorithms,7L + +#define SN_id_tc26_wrap_gostr3412_2015_magma "id-tc26-wrap-gostr3412-2015-magma" +#define NID_id_tc26_wrap_gostr3412_2015_magma 1180 +#define OBJ_id_tc26_wrap_gostr3412_2015_magma OBJ_id_tc26_wrap,1L + +#define SN_id_tc26_wrap_gostr3412_2015_magma_kexp15 "id-tc26-wrap-gostr3412-2015-magma-kexp15" +#define NID_id_tc26_wrap_gostr3412_2015_magma_kexp15 1181 +#define OBJ_id_tc26_wrap_gostr3412_2015_magma_kexp15 OBJ_id_tc26_wrap_gostr3412_2015_magma,1L + +#define SN_id_tc26_wrap_gostr3412_2015_kuznyechik "id-tc26-wrap-gostr3412-2015-kuznyechik" +#define NID_id_tc26_wrap_gostr3412_2015_kuznyechik 1182 +#define OBJ_id_tc26_wrap_gostr3412_2015_kuznyechik OBJ_id_tc26_wrap,2L + +#define SN_id_tc26_wrap_gostr3412_2015_kuznyechik_kexp15 "id-tc26-wrap-gostr3412-2015-kuznyechik-kexp15" +#define NID_id_tc26_wrap_gostr3412_2015_kuznyechik_kexp15 1183 +#define OBJ_id_tc26_wrap_gostr3412_2015_kuznyechik_kexp15 OBJ_id_tc26_wrap_gostr3412_2015_kuznyechik,1L + +#define SN_id_tc26_constants "id-tc26-constants" +#define NID_id_tc26_constants 994 +#define OBJ_id_tc26_constants OBJ_id_tc26,2L + +#define SN_id_tc26_sign_constants "id-tc26-sign-constants" +#define NID_id_tc26_sign_constants 995 +#define OBJ_id_tc26_sign_constants OBJ_id_tc26_constants,1L + +#define SN_id_tc26_gost_3410_2012_256_constants "id-tc26-gost-3410-2012-256-constants" +#define NID_id_tc26_gost_3410_2012_256_constants 1147 +#define OBJ_id_tc26_gost_3410_2012_256_constants OBJ_id_tc26_sign_constants,1L + +#define SN_id_tc26_gost_3410_2012_256_paramSetA "id-tc26-gost-3410-2012-256-paramSetA" +#define LN_id_tc26_gost_3410_2012_256_paramSetA "GOST R 34.10-2012 (256 bit) ParamSet A" +#define NID_id_tc26_gost_3410_2012_256_paramSetA 1148 +#define OBJ_id_tc26_gost_3410_2012_256_paramSetA OBJ_id_tc26_gost_3410_2012_256_constants,1L + +#define SN_id_tc26_gost_3410_2012_256_paramSetB "id-tc26-gost-3410-2012-256-paramSetB" +#define LN_id_tc26_gost_3410_2012_256_paramSetB "GOST R 34.10-2012 (256 bit) ParamSet B" +#define NID_id_tc26_gost_3410_2012_256_paramSetB 1184 +#define OBJ_id_tc26_gost_3410_2012_256_paramSetB OBJ_id_tc26_gost_3410_2012_256_constants,2L + +#define SN_id_tc26_gost_3410_2012_256_paramSetC "id-tc26-gost-3410-2012-256-paramSetC" +#define LN_id_tc26_gost_3410_2012_256_paramSetC "GOST R 34.10-2012 (256 bit) ParamSet C" +#define NID_id_tc26_gost_3410_2012_256_paramSetC 1185 +#define OBJ_id_tc26_gost_3410_2012_256_paramSetC OBJ_id_tc26_gost_3410_2012_256_constants,3L + +#define SN_id_tc26_gost_3410_2012_256_paramSetD "id-tc26-gost-3410-2012-256-paramSetD" +#define LN_id_tc26_gost_3410_2012_256_paramSetD "GOST R 34.10-2012 (256 bit) ParamSet D" +#define NID_id_tc26_gost_3410_2012_256_paramSetD 1186 +#define OBJ_id_tc26_gost_3410_2012_256_paramSetD OBJ_id_tc26_gost_3410_2012_256_constants,4L + +#define SN_id_tc26_gost_3410_2012_512_constants "id-tc26-gost-3410-2012-512-constants" +#define NID_id_tc26_gost_3410_2012_512_constants 996 +#define OBJ_id_tc26_gost_3410_2012_512_constants OBJ_id_tc26_sign_constants,2L + +#define SN_id_tc26_gost_3410_2012_512_paramSetTest "id-tc26-gost-3410-2012-512-paramSetTest" +#define LN_id_tc26_gost_3410_2012_512_paramSetTest "GOST R 34.10-2012 (512 bit) testing parameter set" +#define NID_id_tc26_gost_3410_2012_512_paramSetTest 997 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetTest OBJ_id_tc26_gost_3410_2012_512_constants,0L + +#define SN_id_tc26_gost_3410_2012_512_paramSetA "id-tc26-gost-3410-2012-512-paramSetA" +#define LN_id_tc26_gost_3410_2012_512_paramSetA "GOST R 34.10-2012 (512 bit) ParamSet A" +#define NID_id_tc26_gost_3410_2012_512_paramSetA 998 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetA OBJ_id_tc26_gost_3410_2012_512_constants,1L + +#define SN_id_tc26_gost_3410_2012_512_paramSetB "id-tc26-gost-3410-2012-512-paramSetB" +#define LN_id_tc26_gost_3410_2012_512_paramSetB "GOST R 34.10-2012 (512 bit) ParamSet B" +#define NID_id_tc26_gost_3410_2012_512_paramSetB 999 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetB OBJ_id_tc26_gost_3410_2012_512_constants,2L + +#define SN_id_tc26_gost_3410_2012_512_paramSetC "id-tc26-gost-3410-2012-512-paramSetC" +#define LN_id_tc26_gost_3410_2012_512_paramSetC "GOST R 34.10-2012 (512 bit) ParamSet C" +#define NID_id_tc26_gost_3410_2012_512_paramSetC 1149 +#define OBJ_id_tc26_gost_3410_2012_512_paramSetC OBJ_id_tc26_gost_3410_2012_512_constants,3L + +#define SN_id_tc26_digest_constants "id-tc26-digest-constants" +#define NID_id_tc26_digest_constants 1000 +#define OBJ_id_tc26_digest_constants OBJ_id_tc26_constants,2L + +#define SN_id_tc26_cipher_constants "id-tc26-cipher-constants" +#define NID_id_tc26_cipher_constants 1001 +#define OBJ_id_tc26_cipher_constants OBJ_id_tc26_constants,5L + +#define SN_id_tc26_gost_28147_constants "id-tc26-gost-28147-constants" +#define NID_id_tc26_gost_28147_constants 1002 +#define OBJ_id_tc26_gost_28147_constants OBJ_id_tc26_cipher_constants,1L + +#define SN_id_tc26_gost_28147_param_Z "id-tc26-gost-28147-param-Z" +#define LN_id_tc26_gost_28147_param_Z "GOST 28147-89 TC26 parameter set" +#define NID_id_tc26_gost_28147_param_Z 1003 +#define OBJ_id_tc26_gost_28147_param_Z OBJ_id_tc26_gost_28147_constants,1L + +#define SN_INN "INN" +#define LN_INN "INN" +#define NID_INN 1004 +#define OBJ_INN OBJ_member_body,643L,3L,131L,1L,1L + +#define SN_OGRN "OGRN" +#define LN_OGRN "OGRN" +#define NID_OGRN 1005 +#define OBJ_OGRN OBJ_member_body,643L,100L,1L + +#define SN_SNILS "SNILS" +#define LN_SNILS "SNILS" +#define NID_SNILS 1006 +#define OBJ_SNILS OBJ_member_body,643L,100L,3L + +#define SN_subjectSignTool "subjectSignTool" +#define LN_subjectSignTool "Signing Tool of Subject" +#define NID_subjectSignTool 1007 +#define OBJ_subjectSignTool OBJ_member_body,643L,100L,111L + +#define SN_issuerSignTool "issuerSignTool" +#define LN_issuerSignTool "Signing Tool of Issuer" +#define NID_issuerSignTool 1008 +#define OBJ_issuerSignTool OBJ_member_body,643L,100L,112L + +#define SN_grasshopper_ecb "grasshopper-ecb" +#define NID_grasshopper_ecb 1012 + +#define SN_grasshopper_ctr "grasshopper-ctr" +#define NID_grasshopper_ctr 1013 + +#define SN_grasshopper_ofb "grasshopper-ofb" +#define NID_grasshopper_ofb 1014 + +#define SN_grasshopper_cbc "grasshopper-cbc" +#define NID_grasshopper_cbc 1015 + +#define SN_grasshopper_cfb "grasshopper-cfb" +#define NID_grasshopper_cfb 1016 + +#define SN_grasshopper_mac "grasshopper-mac" +#define NID_grasshopper_mac 1017 + +#define SN_magma_ecb "magma-ecb" +#define NID_magma_ecb 1187 + +#define SN_magma_ctr "magma-ctr" +#define NID_magma_ctr 1188 + +#define SN_magma_ofb "magma-ofb" +#define NID_magma_ofb 1189 + +#define SN_magma_cbc "magma-cbc" +#define NID_magma_cbc 1190 + +#define SN_magma_cfb "magma-cfb" +#define NID_magma_cfb 1191 + +#define SN_magma_mac "magma-mac" +#define NID_magma_mac 1192 + +#define SN_camellia_128_cbc "CAMELLIA-128-CBC" +#define LN_camellia_128_cbc "camellia-128-cbc" +#define NID_camellia_128_cbc 751 +#define OBJ_camellia_128_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,2L + +#define SN_camellia_192_cbc "CAMELLIA-192-CBC" +#define LN_camellia_192_cbc "camellia-192-cbc" +#define NID_camellia_192_cbc 752 +#define OBJ_camellia_192_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,3L + +#define SN_camellia_256_cbc "CAMELLIA-256-CBC" +#define LN_camellia_256_cbc "camellia-256-cbc" +#define NID_camellia_256_cbc 753 +#define OBJ_camellia_256_cbc 1L,2L,392L,200011L,61L,1L,1L,1L,4L + +#define SN_id_camellia128_wrap "id-camellia128-wrap" +#define NID_id_camellia128_wrap 907 +#define OBJ_id_camellia128_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,2L + +#define SN_id_camellia192_wrap "id-camellia192-wrap" +#define NID_id_camellia192_wrap 908 +#define OBJ_id_camellia192_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,3L + +#define SN_id_camellia256_wrap "id-camellia256-wrap" +#define NID_id_camellia256_wrap 909 +#define OBJ_id_camellia256_wrap 1L,2L,392L,200011L,61L,1L,1L,3L,4L + +#define OBJ_ntt_ds 0L,3L,4401L,5L + +#define OBJ_camellia OBJ_ntt_ds,3L,1L,9L + +#define SN_camellia_128_ecb "CAMELLIA-128-ECB" +#define LN_camellia_128_ecb "camellia-128-ecb" +#define NID_camellia_128_ecb 754 +#define OBJ_camellia_128_ecb OBJ_camellia,1L + +#define SN_camellia_128_ofb128 "CAMELLIA-128-OFB" +#define LN_camellia_128_ofb128 "camellia-128-ofb" +#define NID_camellia_128_ofb128 766 +#define OBJ_camellia_128_ofb128 OBJ_camellia,3L + +#define SN_camellia_128_cfb128 "CAMELLIA-128-CFB" +#define LN_camellia_128_cfb128 "camellia-128-cfb" +#define NID_camellia_128_cfb128 757 +#define OBJ_camellia_128_cfb128 OBJ_camellia,4L + +#define SN_camellia_128_gcm "CAMELLIA-128-GCM" +#define LN_camellia_128_gcm "camellia-128-gcm" +#define NID_camellia_128_gcm 961 +#define OBJ_camellia_128_gcm OBJ_camellia,6L + +#define SN_camellia_128_ccm "CAMELLIA-128-CCM" +#define LN_camellia_128_ccm "camellia-128-ccm" +#define NID_camellia_128_ccm 962 +#define OBJ_camellia_128_ccm OBJ_camellia,7L + +#define SN_camellia_128_ctr "CAMELLIA-128-CTR" +#define LN_camellia_128_ctr "camellia-128-ctr" +#define NID_camellia_128_ctr 963 +#define OBJ_camellia_128_ctr OBJ_camellia,9L + +#define SN_camellia_128_cmac "CAMELLIA-128-CMAC" +#define LN_camellia_128_cmac "camellia-128-cmac" +#define NID_camellia_128_cmac 964 +#define OBJ_camellia_128_cmac OBJ_camellia,10L + +#define SN_camellia_192_ecb "CAMELLIA-192-ECB" +#define LN_camellia_192_ecb "camellia-192-ecb" +#define NID_camellia_192_ecb 755 +#define OBJ_camellia_192_ecb OBJ_camellia,21L + +#define SN_camellia_192_ofb128 "CAMELLIA-192-OFB" +#define LN_camellia_192_ofb128 "camellia-192-ofb" +#define NID_camellia_192_ofb128 767 +#define OBJ_camellia_192_ofb128 OBJ_camellia,23L + +#define SN_camellia_192_cfb128 "CAMELLIA-192-CFB" +#define LN_camellia_192_cfb128 "camellia-192-cfb" +#define NID_camellia_192_cfb128 758 +#define OBJ_camellia_192_cfb128 OBJ_camellia,24L + +#define SN_camellia_192_gcm "CAMELLIA-192-GCM" +#define LN_camellia_192_gcm "camellia-192-gcm" +#define NID_camellia_192_gcm 965 +#define OBJ_camellia_192_gcm OBJ_camellia,26L + +#define SN_camellia_192_ccm "CAMELLIA-192-CCM" +#define LN_camellia_192_ccm "camellia-192-ccm" +#define NID_camellia_192_ccm 966 +#define OBJ_camellia_192_ccm OBJ_camellia,27L + +#define SN_camellia_192_ctr "CAMELLIA-192-CTR" +#define LN_camellia_192_ctr "camellia-192-ctr" +#define NID_camellia_192_ctr 967 +#define OBJ_camellia_192_ctr OBJ_camellia,29L + +#define SN_camellia_192_cmac "CAMELLIA-192-CMAC" +#define LN_camellia_192_cmac "camellia-192-cmac" +#define NID_camellia_192_cmac 968 +#define OBJ_camellia_192_cmac OBJ_camellia,30L + +#define SN_camellia_256_ecb "CAMELLIA-256-ECB" +#define LN_camellia_256_ecb "camellia-256-ecb" +#define NID_camellia_256_ecb 756 +#define OBJ_camellia_256_ecb OBJ_camellia,41L + +#define SN_camellia_256_ofb128 "CAMELLIA-256-OFB" +#define LN_camellia_256_ofb128 "camellia-256-ofb" +#define NID_camellia_256_ofb128 768 +#define OBJ_camellia_256_ofb128 OBJ_camellia,43L + +#define SN_camellia_256_cfb128 "CAMELLIA-256-CFB" +#define LN_camellia_256_cfb128 "camellia-256-cfb" +#define NID_camellia_256_cfb128 759 +#define OBJ_camellia_256_cfb128 OBJ_camellia,44L + +#define SN_camellia_256_gcm "CAMELLIA-256-GCM" +#define LN_camellia_256_gcm "camellia-256-gcm" +#define NID_camellia_256_gcm 969 +#define OBJ_camellia_256_gcm OBJ_camellia,46L + +#define SN_camellia_256_ccm "CAMELLIA-256-CCM" +#define LN_camellia_256_ccm "camellia-256-ccm" +#define NID_camellia_256_ccm 970 +#define OBJ_camellia_256_ccm OBJ_camellia,47L + +#define SN_camellia_256_ctr "CAMELLIA-256-CTR" +#define LN_camellia_256_ctr "camellia-256-ctr" +#define NID_camellia_256_ctr 971 +#define OBJ_camellia_256_ctr OBJ_camellia,49L + +#define SN_camellia_256_cmac "CAMELLIA-256-CMAC" +#define LN_camellia_256_cmac "camellia-256-cmac" +#define NID_camellia_256_cmac 972 +#define OBJ_camellia_256_cmac OBJ_camellia,50L + +#define SN_camellia_128_cfb1 "CAMELLIA-128-CFB1" +#define LN_camellia_128_cfb1 "camellia-128-cfb1" +#define NID_camellia_128_cfb1 760 + +#define SN_camellia_192_cfb1 "CAMELLIA-192-CFB1" +#define LN_camellia_192_cfb1 "camellia-192-cfb1" +#define NID_camellia_192_cfb1 761 + +#define SN_camellia_256_cfb1 "CAMELLIA-256-CFB1" +#define LN_camellia_256_cfb1 "camellia-256-cfb1" +#define NID_camellia_256_cfb1 762 + +#define SN_camellia_128_cfb8 "CAMELLIA-128-CFB8" +#define LN_camellia_128_cfb8 "camellia-128-cfb8" +#define NID_camellia_128_cfb8 763 + +#define SN_camellia_192_cfb8 "CAMELLIA-192-CFB8" +#define LN_camellia_192_cfb8 "camellia-192-cfb8" +#define NID_camellia_192_cfb8 764 + +#define SN_camellia_256_cfb8 "CAMELLIA-256-CFB8" +#define LN_camellia_256_cfb8 "camellia-256-cfb8" +#define NID_camellia_256_cfb8 765 + +#define OBJ_aria 1L,2L,410L,200046L,1L,1L + +#define SN_aria_128_ecb "ARIA-128-ECB" +#define LN_aria_128_ecb "aria-128-ecb" +#define NID_aria_128_ecb 1065 +#define OBJ_aria_128_ecb OBJ_aria,1L + +#define SN_aria_128_cbc "ARIA-128-CBC" +#define LN_aria_128_cbc "aria-128-cbc" +#define NID_aria_128_cbc 1066 +#define OBJ_aria_128_cbc OBJ_aria,2L + +#define SN_aria_128_cfb128 "ARIA-128-CFB" +#define LN_aria_128_cfb128 "aria-128-cfb" +#define NID_aria_128_cfb128 1067 +#define OBJ_aria_128_cfb128 OBJ_aria,3L + +#define SN_aria_128_ofb128 "ARIA-128-OFB" +#define LN_aria_128_ofb128 "aria-128-ofb" +#define NID_aria_128_ofb128 1068 +#define OBJ_aria_128_ofb128 OBJ_aria,4L + +#define SN_aria_128_ctr "ARIA-128-CTR" +#define LN_aria_128_ctr "aria-128-ctr" +#define NID_aria_128_ctr 1069 +#define OBJ_aria_128_ctr OBJ_aria,5L + +#define SN_aria_192_ecb "ARIA-192-ECB" +#define LN_aria_192_ecb "aria-192-ecb" +#define NID_aria_192_ecb 1070 +#define OBJ_aria_192_ecb OBJ_aria,6L + +#define SN_aria_192_cbc "ARIA-192-CBC" +#define LN_aria_192_cbc "aria-192-cbc" +#define NID_aria_192_cbc 1071 +#define OBJ_aria_192_cbc OBJ_aria,7L + +#define SN_aria_192_cfb128 "ARIA-192-CFB" +#define LN_aria_192_cfb128 "aria-192-cfb" +#define NID_aria_192_cfb128 1072 +#define OBJ_aria_192_cfb128 OBJ_aria,8L + +#define SN_aria_192_ofb128 "ARIA-192-OFB" +#define LN_aria_192_ofb128 "aria-192-ofb" +#define NID_aria_192_ofb128 1073 +#define OBJ_aria_192_ofb128 OBJ_aria,9L + +#define SN_aria_192_ctr "ARIA-192-CTR" +#define LN_aria_192_ctr "aria-192-ctr" +#define NID_aria_192_ctr 1074 +#define OBJ_aria_192_ctr OBJ_aria,10L + +#define SN_aria_256_ecb "ARIA-256-ECB" +#define LN_aria_256_ecb "aria-256-ecb" +#define NID_aria_256_ecb 1075 +#define OBJ_aria_256_ecb OBJ_aria,11L + +#define SN_aria_256_cbc "ARIA-256-CBC" +#define LN_aria_256_cbc "aria-256-cbc" +#define NID_aria_256_cbc 1076 +#define OBJ_aria_256_cbc OBJ_aria,12L + +#define SN_aria_256_cfb128 "ARIA-256-CFB" +#define LN_aria_256_cfb128 "aria-256-cfb" +#define NID_aria_256_cfb128 1077 +#define OBJ_aria_256_cfb128 OBJ_aria,13L + +#define SN_aria_256_ofb128 "ARIA-256-OFB" +#define LN_aria_256_ofb128 "aria-256-ofb" +#define NID_aria_256_ofb128 1078 +#define OBJ_aria_256_ofb128 OBJ_aria,14L + +#define SN_aria_256_ctr "ARIA-256-CTR" +#define LN_aria_256_ctr "aria-256-ctr" +#define NID_aria_256_ctr 1079 +#define OBJ_aria_256_ctr OBJ_aria,15L + +#define SN_aria_128_cfb1 "ARIA-128-CFB1" +#define LN_aria_128_cfb1 "aria-128-cfb1" +#define NID_aria_128_cfb1 1080 + +#define SN_aria_192_cfb1 "ARIA-192-CFB1" +#define LN_aria_192_cfb1 "aria-192-cfb1" +#define NID_aria_192_cfb1 1081 + +#define SN_aria_256_cfb1 "ARIA-256-CFB1" +#define LN_aria_256_cfb1 "aria-256-cfb1" +#define NID_aria_256_cfb1 1082 + +#define SN_aria_128_cfb8 "ARIA-128-CFB8" +#define LN_aria_128_cfb8 "aria-128-cfb8" +#define NID_aria_128_cfb8 1083 + +#define SN_aria_192_cfb8 "ARIA-192-CFB8" +#define LN_aria_192_cfb8 "aria-192-cfb8" +#define NID_aria_192_cfb8 1084 + +#define SN_aria_256_cfb8 "ARIA-256-CFB8" +#define LN_aria_256_cfb8 "aria-256-cfb8" +#define NID_aria_256_cfb8 1085 + +#define SN_aria_128_ccm "ARIA-128-CCM" +#define LN_aria_128_ccm "aria-128-ccm" +#define NID_aria_128_ccm 1120 +#define OBJ_aria_128_ccm OBJ_aria,37L + +#define SN_aria_192_ccm "ARIA-192-CCM" +#define LN_aria_192_ccm "aria-192-ccm" +#define NID_aria_192_ccm 1121 +#define OBJ_aria_192_ccm OBJ_aria,38L + +#define SN_aria_256_ccm "ARIA-256-CCM" +#define LN_aria_256_ccm "aria-256-ccm" +#define NID_aria_256_ccm 1122 +#define OBJ_aria_256_ccm OBJ_aria,39L + +#define SN_aria_128_gcm "ARIA-128-GCM" +#define LN_aria_128_gcm "aria-128-gcm" +#define NID_aria_128_gcm 1123 +#define OBJ_aria_128_gcm OBJ_aria,34L + +#define SN_aria_192_gcm "ARIA-192-GCM" +#define LN_aria_192_gcm "aria-192-gcm" +#define NID_aria_192_gcm 1124 +#define OBJ_aria_192_gcm OBJ_aria,35L + +#define SN_aria_256_gcm "ARIA-256-GCM" +#define LN_aria_256_gcm "aria-256-gcm" +#define NID_aria_256_gcm 1125 +#define OBJ_aria_256_gcm OBJ_aria,36L + +#define SN_kisa "KISA" +#define LN_kisa "kisa" +#define NID_kisa 773 +#define OBJ_kisa OBJ_member_body,410L,200004L + +#define SN_seed_ecb "SEED-ECB" +#define LN_seed_ecb "seed-ecb" +#define NID_seed_ecb 776 +#define OBJ_seed_ecb OBJ_kisa,1L,3L + +#define SN_seed_cbc "SEED-CBC" +#define LN_seed_cbc "seed-cbc" +#define NID_seed_cbc 777 +#define OBJ_seed_cbc OBJ_kisa,1L,4L + +#define SN_seed_cfb128 "SEED-CFB" +#define LN_seed_cfb128 "seed-cfb" +#define NID_seed_cfb128 779 +#define OBJ_seed_cfb128 OBJ_kisa,1L,5L + +#define SN_seed_ofb128 "SEED-OFB" +#define LN_seed_ofb128 "seed-ofb" +#define NID_seed_ofb128 778 +#define OBJ_seed_ofb128 OBJ_kisa,1L,6L + +#define SN_sm4_ecb "SM4-ECB" +#define LN_sm4_ecb "sm4-ecb" +#define NID_sm4_ecb 1133 +#define OBJ_sm4_ecb OBJ_sm_scheme,104L,1L + +#define SN_sm4_cbc "SM4-CBC" +#define LN_sm4_cbc "sm4-cbc" +#define NID_sm4_cbc 1134 +#define OBJ_sm4_cbc OBJ_sm_scheme,104L,2L + +#define SN_sm4_ofb128 "SM4-OFB" +#define LN_sm4_ofb128 "sm4-ofb" +#define NID_sm4_ofb128 1135 +#define OBJ_sm4_ofb128 OBJ_sm_scheme,104L,3L + +#define SN_sm4_cfb128 "SM4-CFB" +#define LN_sm4_cfb128 "sm4-cfb" +#define NID_sm4_cfb128 1137 +#define OBJ_sm4_cfb128 OBJ_sm_scheme,104L,4L + +#define SN_sm4_cfb1 "SM4-CFB1" +#define LN_sm4_cfb1 "sm4-cfb1" +#define NID_sm4_cfb1 1136 +#define OBJ_sm4_cfb1 OBJ_sm_scheme,104L,5L + +#define SN_sm4_cfb8 "SM4-CFB8" +#define LN_sm4_cfb8 "sm4-cfb8" +#define NID_sm4_cfb8 1138 +#define OBJ_sm4_cfb8 OBJ_sm_scheme,104L,6L + +#define SN_sm4_ctr "SM4-CTR" +#define LN_sm4_ctr "sm4-ctr" +#define NID_sm4_ctr 1139 +#define OBJ_sm4_ctr OBJ_sm_scheme,104L,7L + +#define SN_hmac "HMAC" +#define LN_hmac "hmac" +#define NID_hmac 855 + +#define SN_cmac "CMAC" +#define LN_cmac "cmac" +#define NID_cmac 894 + +#define SN_rc4_hmac_md5 "RC4-HMAC-MD5" +#define LN_rc4_hmac_md5 "rc4-hmac-md5" +#define NID_rc4_hmac_md5 915 + +#define SN_aes_128_cbc_hmac_sha1 "AES-128-CBC-HMAC-SHA1" +#define LN_aes_128_cbc_hmac_sha1 "aes-128-cbc-hmac-sha1" +#define NID_aes_128_cbc_hmac_sha1 916 + +#define SN_aes_192_cbc_hmac_sha1 "AES-192-CBC-HMAC-SHA1" +#define LN_aes_192_cbc_hmac_sha1 "aes-192-cbc-hmac-sha1" +#define NID_aes_192_cbc_hmac_sha1 917 + +#define SN_aes_256_cbc_hmac_sha1 "AES-256-CBC-HMAC-SHA1" +#define LN_aes_256_cbc_hmac_sha1 "aes-256-cbc-hmac-sha1" +#define NID_aes_256_cbc_hmac_sha1 918 + +#define SN_aes_128_cbc_hmac_sha256 "AES-128-CBC-HMAC-SHA256" +#define LN_aes_128_cbc_hmac_sha256 "aes-128-cbc-hmac-sha256" +#define NID_aes_128_cbc_hmac_sha256 948 + +#define SN_aes_192_cbc_hmac_sha256 "AES-192-CBC-HMAC-SHA256" +#define LN_aes_192_cbc_hmac_sha256 "aes-192-cbc-hmac-sha256" +#define NID_aes_192_cbc_hmac_sha256 949 + +#define SN_aes_256_cbc_hmac_sha256 "AES-256-CBC-HMAC-SHA256" +#define LN_aes_256_cbc_hmac_sha256 "aes-256-cbc-hmac-sha256" +#define NID_aes_256_cbc_hmac_sha256 950 + +#define SN_chacha20_poly1305 "ChaCha20-Poly1305" +#define LN_chacha20_poly1305 "chacha20-poly1305" +#define NID_chacha20_poly1305 1018 + +#define SN_chacha20 "ChaCha20" +#define LN_chacha20 "chacha20" +#define NID_chacha20 1019 + +#define SN_dhpublicnumber "dhpublicnumber" +#define LN_dhpublicnumber "X9.42 DH" +#define NID_dhpublicnumber 920 +#define OBJ_dhpublicnumber OBJ_ISO_US,10046L,2L,1L + +#define SN_brainpoolP160r1 "brainpoolP160r1" +#define NID_brainpoolP160r1 921 +#define OBJ_brainpoolP160r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,1L + +#define SN_brainpoolP160t1 "brainpoolP160t1" +#define NID_brainpoolP160t1 922 +#define OBJ_brainpoolP160t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,2L + +#define SN_brainpoolP192r1 "brainpoolP192r1" +#define NID_brainpoolP192r1 923 +#define OBJ_brainpoolP192r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,3L + +#define SN_brainpoolP192t1 "brainpoolP192t1" +#define NID_brainpoolP192t1 924 +#define OBJ_brainpoolP192t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,4L + +#define SN_brainpoolP224r1 "brainpoolP224r1" +#define NID_brainpoolP224r1 925 +#define OBJ_brainpoolP224r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,5L + +#define SN_brainpoolP224t1 "brainpoolP224t1" +#define NID_brainpoolP224t1 926 +#define OBJ_brainpoolP224t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,6L + +#define SN_brainpoolP256r1 "brainpoolP256r1" +#define NID_brainpoolP256r1 927 +#define OBJ_brainpoolP256r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,7L + +#define SN_brainpoolP256t1 "brainpoolP256t1" +#define NID_brainpoolP256t1 928 +#define OBJ_brainpoolP256t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,8L + +#define SN_brainpoolP320r1 "brainpoolP320r1" +#define NID_brainpoolP320r1 929 +#define OBJ_brainpoolP320r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,9L + +#define SN_brainpoolP320t1 "brainpoolP320t1" +#define NID_brainpoolP320t1 930 +#define OBJ_brainpoolP320t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,10L + +#define SN_brainpoolP384r1 "brainpoolP384r1" +#define NID_brainpoolP384r1 931 +#define OBJ_brainpoolP384r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,11L + +#define SN_brainpoolP384t1 "brainpoolP384t1" +#define NID_brainpoolP384t1 932 +#define OBJ_brainpoolP384t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,12L + +#define SN_brainpoolP512r1 "brainpoolP512r1" +#define NID_brainpoolP512r1 933 +#define OBJ_brainpoolP512r1 1L,3L,36L,3L,3L,2L,8L,1L,1L,13L + +#define SN_brainpoolP512t1 "brainpoolP512t1" +#define NID_brainpoolP512t1 934 +#define OBJ_brainpoolP512t1 1L,3L,36L,3L,3L,2L,8L,1L,1L,14L + +#define OBJ_x9_63_scheme 1L,3L,133L,16L,840L,63L,0L + +#define OBJ_secg_scheme OBJ_certicom_arc,1L + +#define SN_dhSinglePass_stdDH_sha1kdf_scheme "dhSinglePass-stdDH-sha1kdf-scheme" +#define NID_dhSinglePass_stdDH_sha1kdf_scheme 936 +#define OBJ_dhSinglePass_stdDH_sha1kdf_scheme OBJ_x9_63_scheme,2L + +#define SN_dhSinglePass_stdDH_sha224kdf_scheme "dhSinglePass-stdDH-sha224kdf-scheme" +#define NID_dhSinglePass_stdDH_sha224kdf_scheme 937 +#define OBJ_dhSinglePass_stdDH_sha224kdf_scheme OBJ_secg_scheme,11L,0L + +#define SN_dhSinglePass_stdDH_sha256kdf_scheme "dhSinglePass-stdDH-sha256kdf-scheme" +#define NID_dhSinglePass_stdDH_sha256kdf_scheme 938 +#define OBJ_dhSinglePass_stdDH_sha256kdf_scheme OBJ_secg_scheme,11L,1L + +#define SN_dhSinglePass_stdDH_sha384kdf_scheme "dhSinglePass-stdDH-sha384kdf-scheme" +#define NID_dhSinglePass_stdDH_sha384kdf_scheme 939 +#define OBJ_dhSinglePass_stdDH_sha384kdf_scheme OBJ_secg_scheme,11L,2L + +#define SN_dhSinglePass_stdDH_sha512kdf_scheme "dhSinglePass-stdDH-sha512kdf-scheme" +#define NID_dhSinglePass_stdDH_sha512kdf_scheme 940 +#define OBJ_dhSinglePass_stdDH_sha512kdf_scheme OBJ_secg_scheme,11L,3L + +#define SN_dhSinglePass_cofactorDH_sha1kdf_scheme "dhSinglePass-cofactorDH-sha1kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha1kdf_scheme 941 +#define OBJ_dhSinglePass_cofactorDH_sha1kdf_scheme OBJ_x9_63_scheme,3L + +#define SN_dhSinglePass_cofactorDH_sha224kdf_scheme "dhSinglePass-cofactorDH-sha224kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha224kdf_scheme 942 +#define OBJ_dhSinglePass_cofactorDH_sha224kdf_scheme OBJ_secg_scheme,14L,0L + +#define SN_dhSinglePass_cofactorDH_sha256kdf_scheme "dhSinglePass-cofactorDH-sha256kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha256kdf_scheme 943 +#define OBJ_dhSinglePass_cofactorDH_sha256kdf_scheme OBJ_secg_scheme,14L,1L + +#define SN_dhSinglePass_cofactorDH_sha384kdf_scheme "dhSinglePass-cofactorDH-sha384kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha384kdf_scheme 944 +#define OBJ_dhSinglePass_cofactorDH_sha384kdf_scheme OBJ_secg_scheme,14L,2L + +#define SN_dhSinglePass_cofactorDH_sha512kdf_scheme "dhSinglePass-cofactorDH-sha512kdf-scheme" +#define NID_dhSinglePass_cofactorDH_sha512kdf_scheme 945 +#define OBJ_dhSinglePass_cofactorDH_sha512kdf_scheme OBJ_secg_scheme,14L,3L + +#define SN_dh_std_kdf "dh-std-kdf" +#define NID_dh_std_kdf 946 + +#define SN_dh_cofactor_kdf "dh-cofactor-kdf" +#define NID_dh_cofactor_kdf 947 + +#define SN_ct_precert_scts "ct_precert_scts" +#define LN_ct_precert_scts "CT Precertificate SCTs" +#define NID_ct_precert_scts 951 +#define OBJ_ct_precert_scts 1L,3L,6L,1L,4L,1L,11129L,2L,4L,2L + +#define SN_ct_precert_poison "ct_precert_poison" +#define LN_ct_precert_poison "CT Precertificate Poison" +#define NID_ct_precert_poison 952 +#define OBJ_ct_precert_poison 1L,3L,6L,1L,4L,1L,11129L,2L,4L,3L + +#define SN_ct_precert_signer "ct_precert_signer" +#define LN_ct_precert_signer "CT Precertificate Signer" +#define NID_ct_precert_signer 953 +#define OBJ_ct_precert_signer 1L,3L,6L,1L,4L,1L,11129L,2L,4L,4L + +#define SN_ct_cert_scts "ct_cert_scts" +#define LN_ct_cert_scts "CT Certificate SCTs" +#define NID_ct_cert_scts 954 +#define OBJ_ct_cert_scts 1L,3L,6L,1L,4L,1L,11129L,2L,4L,5L + +#define SN_jurisdictionLocalityName "jurisdictionL" +#define LN_jurisdictionLocalityName "jurisdictionLocalityName" +#define NID_jurisdictionLocalityName 955 +#define OBJ_jurisdictionLocalityName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,1L + +#define SN_jurisdictionStateOrProvinceName "jurisdictionST" +#define LN_jurisdictionStateOrProvinceName "jurisdictionStateOrProvinceName" +#define NID_jurisdictionStateOrProvinceName 956 +#define OBJ_jurisdictionStateOrProvinceName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,2L + +#define SN_jurisdictionCountryName "jurisdictionC" +#define LN_jurisdictionCountryName "jurisdictionCountryName" +#define NID_jurisdictionCountryName 957 +#define OBJ_jurisdictionCountryName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,3L + +#define SN_id_scrypt "id-scrypt" +#define LN_id_scrypt "scrypt" +#define NID_id_scrypt 973 +#define OBJ_id_scrypt 1L,3L,6L,1L,4L,1L,11591L,4L,11L + +#define SN_tls1_prf "TLS1-PRF" +#define LN_tls1_prf "tls1-prf" +#define NID_tls1_prf 1021 + +#define SN_hkdf "HKDF" +#define LN_hkdf "hkdf" +#define NID_hkdf 1036 + +#define SN_id_pkinit "id-pkinit" +#define NID_id_pkinit 1031 +#define OBJ_id_pkinit 1L,3L,6L,1L,5L,2L,3L + +#define SN_pkInitClientAuth "pkInitClientAuth" +#define LN_pkInitClientAuth "PKINIT Client Auth" +#define NID_pkInitClientAuth 1032 +#define OBJ_pkInitClientAuth OBJ_id_pkinit,4L + +#define SN_pkInitKDC "pkInitKDC" +#define LN_pkInitKDC "Signing KDC Response" +#define NID_pkInitKDC 1033 +#define OBJ_pkInitKDC OBJ_id_pkinit,5L + +#define SN_X25519 "X25519" +#define NID_X25519 1034 +#define OBJ_X25519 1L,3L,101L,110L + +#define SN_X448 "X448" +#define NID_X448 1035 +#define OBJ_X448 1L,3L,101L,111L + +#define SN_ED25519 "ED25519" +#define NID_ED25519 1087 +#define OBJ_ED25519 1L,3L,101L,112L + +#define SN_ED448 "ED448" +#define NID_ED448 1088 +#define OBJ_ED448 1L,3L,101L,113L + +#define SN_kx_rsa "KxRSA" +#define LN_kx_rsa "kx-rsa" +#define NID_kx_rsa 1037 + +#define SN_kx_ecdhe "KxECDHE" +#define LN_kx_ecdhe "kx-ecdhe" +#define NID_kx_ecdhe 1038 + +#define SN_kx_dhe "KxDHE" +#define LN_kx_dhe "kx-dhe" +#define NID_kx_dhe 1039 + +#define SN_kx_ecdhe_psk "KxECDHE-PSK" +#define LN_kx_ecdhe_psk "kx-ecdhe-psk" +#define NID_kx_ecdhe_psk 1040 + +#define SN_kx_dhe_psk "KxDHE-PSK" +#define LN_kx_dhe_psk "kx-dhe-psk" +#define NID_kx_dhe_psk 1041 + +#define SN_kx_rsa_psk "KxRSA_PSK" +#define LN_kx_rsa_psk "kx-rsa-psk" +#define NID_kx_rsa_psk 1042 + +#define SN_kx_psk "KxPSK" +#define LN_kx_psk "kx-psk" +#define NID_kx_psk 1043 + +#define SN_kx_srp "KxSRP" +#define LN_kx_srp "kx-srp" +#define NID_kx_srp 1044 + +#define SN_kx_gost "KxGOST" +#define LN_kx_gost "kx-gost" +#define NID_kx_gost 1045 + +#define SN_kx_any "KxANY" +#define LN_kx_any "kx-any" +#define NID_kx_any 1063 + +#define SN_auth_rsa "AuthRSA" +#define LN_auth_rsa "auth-rsa" +#define NID_auth_rsa 1046 + +#define SN_auth_ecdsa "AuthECDSA" +#define LN_auth_ecdsa "auth-ecdsa" +#define NID_auth_ecdsa 1047 + +#define SN_auth_psk "AuthPSK" +#define LN_auth_psk "auth-psk" +#define NID_auth_psk 1048 + +#define SN_auth_dss "AuthDSS" +#define LN_auth_dss "auth-dss" +#define NID_auth_dss 1049 + +#define SN_auth_gost01 "AuthGOST01" +#define LN_auth_gost01 "auth-gost01" +#define NID_auth_gost01 1050 + +#define SN_auth_gost12 "AuthGOST12" +#define LN_auth_gost12 "auth-gost12" +#define NID_auth_gost12 1051 + +#define SN_auth_srp "AuthSRP" +#define LN_auth_srp "auth-srp" +#define NID_auth_srp 1052 + +#define SN_auth_null "AuthNULL" +#define LN_auth_null "auth-null" +#define NID_auth_null 1053 + +#define SN_auth_any "AuthANY" +#define LN_auth_any "auth-any" +#define NID_auth_any 1064 + +#define SN_poly1305 "Poly1305" +#define LN_poly1305 "poly1305" +#define NID_poly1305 1061 + +#define SN_siphash "SipHash" +#define LN_siphash "siphash" +#define NID_siphash 1062 + +#define SN_ffdhe2048 "ffdhe2048" +#define NID_ffdhe2048 1126 + +#define SN_ffdhe3072 "ffdhe3072" +#define NID_ffdhe3072 1127 + +#define SN_ffdhe4096 "ffdhe4096" +#define NID_ffdhe4096 1128 + +#define SN_ffdhe6144 "ffdhe6144" +#define NID_ffdhe6144 1129 + +#define SN_ffdhe8192 "ffdhe8192" +#define NID_ffdhe8192 1130 + +#define SN_ISO_UA "ISO-UA" +#define NID_ISO_UA 1150 +#define OBJ_ISO_UA OBJ_member_body,804L + +#define SN_ua_pki "ua-pki" +#define NID_ua_pki 1151 +#define OBJ_ua_pki OBJ_ISO_UA,2L,1L,1L,1L + +#define SN_dstu28147 "dstu28147" +#define LN_dstu28147 "DSTU Gost 28147-2009" +#define NID_dstu28147 1152 +#define OBJ_dstu28147 OBJ_ua_pki,1L,1L,1L + +#define SN_dstu28147_ofb "dstu28147-ofb" +#define LN_dstu28147_ofb "DSTU Gost 28147-2009 OFB mode" +#define NID_dstu28147_ofb 1153 +#define OBJ_dstu28147_ofb OBJ_dstu28147,2L + +#define SN_dstu28147_cfb "dstu28147-cfb" +#define LN_dstu28147_cfb "DSTU Gost 28147-2009 CFB mode" +#define NID_dstu28147_cfb 1154 +#define OBJ_dstu28147_cfb OBJ_dstu28147,3L + +#define SN_dstu28147_wrap "dstu28147-wrap" +#define LN_dstu28147_wrap "DSTU Gost 28147-2009 key wrap" +#define NID_dstu28147_wrap 1155 +#define OBJ_dstu28147_wrap OBJ_dstu28147,5L + +#define SN_hmacWithDstu34311 "hmacWithDstu34311" +#define LN_hmacWithDstu34311 "HMAC DSTU Gost 34311-95" +#define NID_hmacWithDstu34311 1156 +#define OBJ_hmacWithDstu34311 OBJ_ua_pki,1L,1L,2L + +#define SN_dstu34311 "dstu34311" +#define LN_dstu34311 "DSTU Gost 34311-95" +#define NID_dstu34311 1157 +#define OBJ_dstu34311 OBJ_ua_pki,1L,2L,1L + +#define SN_dstu4145le "dstu4145le" +#define LN_dstu4145le "DSTU 4145-2002 little endian" +#define NID_dstu4145le 1158 +#define OBJ_dstu4145le OBJ_ua_pki,1L,3L,1L,1L + +#define SN_dstu4145be "dstu4145be" +#define LN_dstu4145be "DSTU 4145-2002 big endian" +#define NID_dstu4145be 1159 +#define OBJ_dstu4145be OBJ_dstu4145le,1L,1L + +#define SN_uacurve0 "uacurve0" +#define LN_uacurve0 "DSTU curve 0" +#define NID_uacurve0 1160 +#define OBJ_uacurve0 OBJ_dstu4145le,2L,0L + +#define SN_uacurve1 "uacurve1" +#define LN_uacurve1 "DSTU curve 1" +#define NID_uacurve1 1161 +#define OBJ_uacurve1 OBJ_dstu4145le,2L,1L + +#define SN_uacurve2 "uacurve2" +#define LN_uacurve2 "DSTU curve 2" +#define NID_uacurve2 1162 +#define OBJ_uacurve2 OBJ_dstu4145le,2L,2L + +#define SN_uacurve3 "uacurve3" +#define LN_uacurve3 "DSTU curve 3" +#define NID_uacurve3 1163 +#define OBJ_uacurve3 OBJ_dstu4145le,2L,3L + +#define SN_uacurve4 "uacurve4" +#define LN_uacurve4 "DSTU curve 4" +#define NID_uacurve4 1164 +#define OBJ_uacurve4 OBJ_dstu4145le,2L,4L + +#define SN_uacurve5 "uacurve5" +#define LN_uacurve5 "DSTU curve 5" +#define NID_uacurve5 1165 +#define OBJ_uacurve5 OBJ_dstu4145le,2L,5L + +#define SN_uacurve6 "uacurve6" +#define LN_uacurve6 "DSTU curve 6" +#define NID_uacurve6 1166 +#define OBJ_uacurve6 OBJ_dstu4145le,2L,6L + +#define SN_uacurve7 "uacurve7" +#define LN_uacurve7 "DSTU curve 7" +#define NID_uacurve7 1167 +#define OBJ_uacurve7 OBJ_dstu4145le,2L,7L + +#define SN_uacurve8 "uacurve8" +#define LN_uacurve8 "DSTU curve 8" +#define NID_uacurve8 1168 +#define OBJ_uacurve8 OBJ_dstu4145le,2L,8L + +#define SN_uacurve9 "uacurve9" +#define LN_uacurve9 "DSTU curve 9" +#define NID_uacurve9 1169 +#define OBJ_uacurve9 OBJ_dstu4145le,2L,9L diff -uprN postgresql-hll-2.14_old/include/openssl/ocsperr.h postgresql-hll-2.14/include/openssl/ocsperr.h --- postgresql-hll-2.14_old/include/openssl/ocsperr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ocsperr.h 2020-12-12 17:06:43.336349187 +0800 @@ -0,0 +1,78 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OCSPERR_H +# define HEADER_OCSPERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_OCSP + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_OCSP_strings(void); + +/* + * OCSP function codes. + */ +# define OCSP_F_D2I_OCSP_NONCE 102 +# define OCSP_F_OCSP_BASIC_ADD1_STATUS 103 +# define OCSP_F_OCSP_BASIC_SIGN 104 +# define OCSP_F_OCSP_BASIC_SIGN_CTX 119 +# define OCSP_F_OCSP_BASIC_VERIFY 105 +# define OCSP_F_OCSP_CERT_ID_NEW 101 +# define OCSP_F_OCSP_CHECK_DELEGATED 106 +# define OCSP_F_OCSP_CHECK_IDS 107 +# define OCSP_F_OCSP_CHECK_ISSUER 108 +# define OCSP_F_OCSP_CHECK_VALIDITY 115 +# define OCSP_F_OCSP_MATCH_ISSUERID 109 +# define OCSP_F_OCSP_PARSE_URL 114 +# define OCSP_F_OCSP_REQUEST_SIGN 110 +# define OCSP_F_OCSP_REQUEST_VERIFY 116 +# define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111 +# define OCSP_F_PARSE_HTTP_LINE1 118 + +/* + * OCSP reason codes. + */ +# define OCSP_R_CERTIFICATE_VERIFY_ERROR 101 +# define OCSP_R_DIGEST_ERR 102 +# define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122 +# define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123 +# define OCSP_R_ERROR_PARSING_URL 121 +# define OCSP_R_MISSING_OCSPSIGNING_USAGE 103 +# define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124 +# define OCSP_R_NOT_BASIC_RESPONSE 104 +# define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105 +# define OCSP_R_NO_RESPONSE_DATA 108 +# define OCSP_R_NO_REVOKED_TIME 109 +# define OCSP_R_NO_SIGNER_KEY 130 +# define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110 +# define OCSP_R_REQUEST_NOT_SIGNED 128 +# define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111 +# define OCSP_R_ROOT_CA_NOT_TRUSTED 112 +# define OCSP_R_SERVER_RESPONSE_ERROR 114 +# define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115 +# define OCSP_R_SIGNATURE_FAILURE 117 +# define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118 +# define OCSP_R_STATUS_EXPIRED 125 +# define OCSP_R_STATUS_NOT_YET_VALID 126 +# define OCSP_R_STATUS_TOO_OLD 127 +# define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119 +# define OCSP_R_UNKNOWN_NID 120 +# define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ocsp.h postgresql-hll-2.14/include/openssl/ocsp.h --- postgresql-hll-2.14_old/include/openssl/ocsp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ocsp.h 2020-12-12 17:06:43.336349187 +0800 @@ -0,0 +1,352 @@ +/* + * Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OCSP_H +# define HEADER_OCSP_H + +#include + +/* + * These definitions are outside the OPENSSL_NO_OCSP guard because although for + * historical reasons they have OCSP_* names, they can actually be used + * independently of OCSP. E.g. see RFC5280 + */ +/*- + * CRLReason ::= ENUMERATED { + * unspecified (0), + * keyCompromise (1), + * cACompromise (2), + * affiliationChanged (3), + * superseded (4), + * cessationOfOperation (5), + * certificateHold (6), + * removeFromCRL (8) } + */ +# define OCSP_REVOKED_STATUS_NOSTATUS -1 +# define OCSP_REVOKED_STATUS_UNSPECIFIED 0 +# define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 +# define OCSP_REVOKED_STATUS_CACOMPROMISE 2 +# define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 +# define OCSP_REVOKED_STATUS_SUPERSEDED 4 +# define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 +# define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 +# define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 + + +# ifndef OPENSSL_NO_OCSP + +# include +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Various flags and values */ + +# define OCSP_DEFAULT_NONCE_LENGTH 16 + +# define OCSP_NOCERTS 0x1 +# define OCSP_NOINTERN 0x2 +# define OCSP_NOSIGS 0x4 +# define OCSP_NOCHAIN 0x8 +# define OCSP_NOVERIFY 0x10 +# define OCSP_NOEXPLICIT 0x20 +# define OCSP_NOCASIGN 0x40 +# define OCSP_NODELEGATED 0x80 +# define OCSP_NOCHECKS 0x100 +# define OCSP_TRUSTOTHER 0x200 +# define OCSP_RESPID_KEY 0x400 +# define OCSP_NOTIME 0x800 + +typedef struct ocsp_cert_id_st OCSP_CERTID; + +DEFINE_STACK_OF(OCSP_CERTID) + +typedef struct ocsp_one_request_st OCSP_ONEREQ; + +DEFINE_STACK_OF(OCSP_ONEREQ) + +typedef struct ocsp_req_info_st OCSP_REQINFO; +typedef struct ocsp_signature_st OCSP_SIGNATURE; +typedef struct ocsp_request_st OCSP_REQUEST; + +# define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 +# define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 +# define OCSP_RESPONSE_STATUS_INTERNALERROR 2 +# define OCSP_RESPONSE_STATUS_TRYLATER 3 +# define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 +# define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 + +typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES; + +# define V_OCSP_RESPID_NAME 0 +# define V_OCSP_RESPID_KEY 1 + +DEFINE_STACK_OF(OCSP_RESPID) + +typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; + +# define V_OCSP_CERTSTATUS_GOOD 0 +# define V_OCSP_CERTSTATUS_REVOKED 1 +# define V_OCSP_CERTSTATUS_UNKNOWN 2 + +typedef struct ocsp_cert_status_st OCSP_CERTSTATUS; +typedef struct ocsp_single_response_st OCSP_SINGLERESP; + +DEFINE_STACK_OF(OCSP_SINGLERESP) + +typedef struct ocsp_response_data_st OCSP_RESPDATA; + +typedef struct ocsp_basic_response_st OCSP_BASICRESP; + +typedef struct ocsp_crl_id_st OCSP_CRLID; +typedef struct ocsp_service_locator_st OCSP_SERVICELOC; + +# define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" +# define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" + +# define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) + +# define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) + +# define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST, \ + bp,(char **)(x),cb,NULL) + +# define PEM_read_bio_OCSP_RESPONSE(bp,x,cb) (OCSP_RESPONSE *)PEM_ASN1_read_bio(\ + (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE, \ + bp,(char **)(x),cb,NULL) + +# define PEM_write_bio_OCSP_REQUEST(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\ + bp,(char *)(o), NULL,NULL,0,NULL,NULL) + +# define PEM_write_bio_OCSP_RESPONSE(bp,o) \ + PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ + bp,(char *)(o), NULL,NULL,0,NULL,NULL) + +# define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) + +# define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) + +# define ASN1_BIT_STRING_digest(data,type,md,len) \ + ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len) + +# define OCSP_CERTSTATUS_dup(cs)\ + (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\ + (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs)) + +OCSP_CERTID *OCSP_CERTID_dup(OCSP_CERTID *id); + +OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req); +OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req, + int maxline); +int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx); +int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx); +OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline); +void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx); +void OCSP_set_max_response_length(OCSP_REQ_CTX *rctx, unsigned long len); +int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it, + ASN1_VALUE *val); +int OCSP_REQ_CTX_nbio_d2i(OCSP_REQ_CTX *rctx, ASN1_VALUE **pval, + const ASN1_ITEM *it); +BIO *OCSP_REQ_CTX_get0_mem_bio(OCSP_REQ_CTX *rctx); +int OCSP_REQ_CTX_http(OCSP_REQ_CTX *rctx, const char *op, const char *path); +int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req); +int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx, + const char *name, const char *value); + +OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject, + const X509 *issuer); + +OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, + const X509_NAME *issuerName, + const ASN1_BIT_STRING *issuerKey, + const ASN1_INTEGER *serialNumber); + +OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid); + +int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len); +int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len); +int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs); +int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req); + +int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm); +int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert); + +int OCSP_request_sign(OCSP_REQUEST *req, + X509 *signer, + EVP_PKEY *key, + const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); + +int OCSP_response_status(OCSP_RESPONSE *resp); +OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp); + +const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs); +const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs); +const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs); +int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer, + STACK_OF(X509) *extra_certs); + +int OCSP_resp_count(OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx); +const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP* bs); +const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs); +int OCSP_resp_get0_id(const OCSP_BASICRESP *bs, + const ASN1_OCTET_STRING **pid, + const X509_NAME **pname); +int OCSP_resp_get1_id(const OCSP_BASICRESP *bs, + ASN1_OCTET_STRING **pid, + X509_NAME **pname); + +int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last); +int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status, + int *reason, + ASN1_GENERALIZEDTIME **revtime, + ASN1_GENERALIZEDTIME **thisupd, + ASN1_GENERALIZEDTIME **nextupd); +int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, + ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec); + +int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, + X509_STORE *store, unsigned long flags); + +int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, + int *pssl); + +int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); +int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); + +int OCSP_request_onereq_count(OCSP_REQUEST *req); +OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); +OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one); +int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd, + ASN1_OCTET_STRING **pikeyHash, + ASN1_INTEGER **pserial, OCSP_CERTID *cid); +int OCSP_request_is_signed(OCSP_REQUEST *req); +OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs); +OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp, + OCSP_CERTID *cid, + int status, int reason, + ASN1_TIME *revtime, + ASN1_TIME *thisupd, + ASN1_TIME *nextupd); +int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert); +int OCSP_basic_sign(OCSP_BASICRESP *brsp, + X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, + STACK_OF(X509) *certs, unsigned long flags); +int OCSP_basic_sign_ctx(OCSP_BASICRESP *brsp, + X509 *signer, EVP_MD_CTX *ctx, + STACK_OF(X509) *certs, unsigned long flags); +int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert); +int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert); +int OCSP_RESPID_match(OCSP_RESPID *respid, X509 *cert); + +X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim); + +X509_EXTENSION *OCSP_accept_responses_new(char **oids); + +X509_EXTENSION *OCSP_archive_cutoff_new(char *tim); + +X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls); + +int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x); +int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos); +int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos); +X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc); +X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc); +void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit, + int *idx); +int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc); + +int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x); +int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos); +int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, const ASN1_OBJECT *obj, int lastpos); +int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos); +X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc); +X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc); +void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx); +int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit, + unsigned long flags); +int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc); + +int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x); +int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos); +int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit, + int lastpos); +X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc); +X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc); +void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit, + int *idx); +int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value, + int crit, unsigned long flags); +int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc); + +int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x); +int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos); +int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj, + int lastpos); +int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit, + int lastpos); +X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc); +X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc); +void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit, + int *idx); +int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value, + int crit, unsigned long flags); +int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc); +const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *x); + +DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS) +DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPID) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE) +DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES) +DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ) +DECLARE_ASN1_FUNCTIONS(OCSP_CERTID) +DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST) +DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE) +DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO) +DECLARE_ASN1_FUNCTIONS(OCSP_CRLID) +DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC) + +const char *OCSP_response_status_str(long s); +const char *OCSP_cert_status_str(long s); +const char *OCSP_crl_reason_str(long s); + +int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *a, unsigned long flags); +int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags); + +int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, + X509_STORE *st, unsigned long flags); + + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/opensslconf.h postgresql-hll-2.14/include/openssl/opensslconf.h --- postgresql-hll-2.14_old/include/openssl/opensslconf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/opensslconf.h 2020-12-12 17:06:43.336349187 +0800 @@ -0,0 +1,195 @@ +/* + * WARNING: do not edit! + * Generated by Makefile from include/openssl/opensslconf.h.in + * + * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef OPENSSL_ALGORITHM_DEFINES +# error OPENSSL_ALGORITHM_DEFINES no longer supported +#endif + +/* + * OpenSSL was configured with the following options: + */ + +#ifndef OPENSSL_NO_MD2 +# define OPENSSL_NO_MD2 +#endif +#ifndef OPENSSL_NO_RC5 +# define OPENSSL_NO_RC5 +#endif +#ifndef OPENSSL_THREADS +# define OPENSSL_THREADS +#endif +#ifndef OPENSSL_RAND_SEED_OS +# define OPENSSL_RAND_SEED_OS +#endif +#ifndef OPENSSL_NO_AFALGENG +# define OPENSSL_NO_AFALGENG +#endif +#ifndef OPENSSL_NO_ASAN +# define OPENSSL_NO_ASAN +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG +# define OPENSSL_NO_CRYPTO_MDEBUG +#endif +#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE +#endif +#ifndef OPENSSL_NO_DEVCRYPTOENG +# define OPENSSL_NO_DEVCRYPTOENG +#endif +#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 +# define OPENSSL_NO_EC_NISTP_64_GCC_128 +#endif +#ifndef OPENSSL_NO_EGD +# define OPENSSL_NO_EGD +#endif +#ifndef OPENSSL_NO_EXTERNAL_TESTS +# define OPENSSL_NO_EXTERNAL_TESTS +#endif +#ifndef OPENSSL_NO_FUZZ_AFL +# define OPENSSL_NO_FUZZ_AFL +#endif +#ifndef OPENSSL_NO_FUZZ_LIBFUZZER +# define OPENSSL_NO_FUZZ_LIBFUZZER +#endif +#ifndef OPENSSL_NO_HEARTBEATS +# define OPENSSL_NO_HEARTBEATS +#endif +#ifndef OPENSSL_NO_MSAN +# define OPENSSL_NO_MSAN +#endif +#ifndef OPENSSL_NO_SCTP +# define OPENSSL_NO_SCTP +#endif +#ifndef OPENSSL_NO_SSL_TRACE +# define OPENSSL_NO_SSL_TRACE +#endif +#ifndef OPENSSL_NO_SSL3 +# define OPENSSL_NO_SSL3 +#endif +#ifndef OPENSSL_NO_SSL3_METHOD +# define OPENSSL_NO_SSL3_METHOD +#endif +#ifndef OPENSSL_NO_UBSAN +# define OPENSSL_NO_UBSAN +#endif +#ifndef OPENSSL_NO_UNIT_TEST +# define OPENSSL_NO_UNIT_TEST +#endif +#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS +# define OPENSSL_NO_WEAK_SSL_CIPHERS +#endif +#ifndef OPENSSL_NO_STATIC_ENGINE +# define OPENSSL_NO_STATIC_ENGINE +#endif + + +/* + * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers + * don't like that. This will hopefully silence them. + */ +#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy; + +/* + * Applications should use -DOPENSSL_API_COMPAT= to suppress the + * declarations of functions deprecated in or before . Otherwise, they + * still won't see them if the library has been built to disable deprecated + * functions. + */ +#ifndef DECLARE_DEPRECATED +# define DECLARE_DEPRECATED(f) f; +# ifdef __GNUC__ +# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# undef DECLARE_DEPRECATED +# define DECLARE_DEPRECATED(f) f __attribute__ ((deprecated)); +# endif +# endif +#endif + +#ifndef OPENSSL_FILE +# ifdef OPENSSL_NO_FILENAMES +# define OPENSSL_FILE "" +# define OPENSSL_LINE 0 +# else +# define OPENSSL_FILE __FILE__ +# define OPENSSL_LINE __LINE__ +# endif +#endif + +#ifndef OPENSSL_MIN_API +# define OPENSSL_MIN_API 0 +#endif + +#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API +# undef OPENSSL_API_COMPAT +# define OPENSSL_API_COMPAT OPENSSL_MIN_API +#endif + +/* + * Do not deprecate things to be deprecated in version 1.2.0 before the + * OpenSSL version number matches. + */ +#if OPENSSL_VERSION_NUMBER < 0x10200000L +# define DEPRECATEDIN_1_2_0(f) f; +#elif OPENSSL_API_COMPAT < 0x10200000L +# define DEPRECATEDIN_1_2_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_2_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10100000L +# define DEPRECATEDIN_1_1_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_1_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x10000000L +# define DEPRECATEDIN_1_0_0(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_1_0_0(f) +#endif + +#if OPENSSL_API_COMPAT < 0x00908000L +# define DEPRECATEDIN_0_9_8(f) DECLARE_DEPRECATED(f) +#else +# define DEPRECATEDIN_0_9_8(f) +#endif + +/* Generate 80386 code? */ +#undef I386_ONLY + +#undef OPENSSL_UNISTD +#define OPENSSL_UNISTD + +#undef OPENSSL_EXPORT_VAR_AS_FUNCTION + +/* + * The following are cipher-specific, but are part of the public API. + */ +#if !defined(OPENSSL_SYS_UEFI) +# undef BN_LLONG +/* Only one for the following should be defined */ +# define SIXTY_FOUR_BIT_LONG +# undef SIXTY_FOUR_BIT +# undef THIRTY_TWO_BIT +#endif + +#define RC4_INT unsigned int + +#ifdef __cplusplus +} +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/opensslv.h postgresql-hll-2.14/include/openssl/opensslv.h --- postgresql-hll-2.14_old/include/openssl/opensslv.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/opensslv.h 2020-12-12 17:06:43.336349187 +0800 @@ -0,0 +1,101 @@ +/* + * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OPENSSLV_H +# define HEADER_OPENSSLV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * Numeric release version identifier: + * MNNFFPPS: major minor fix patch status + * The status nibble has one of the values 0 for development, 1 to e for betas + * 1 to 14, and f for release. The patch level is exactly that. + * For example: + * 0.9.3-dev 0x00903000 + * 0.9.3-beta1 0x00903001 + * 0.9.3-beta2-dev 0x00903002 + * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) + * 0.9.3 0x0090300f + * 0.9.3a 0x0090301f + * 0.9.4 0x0090400f + * 1.2.3z 0x102031af + * + * For continuity reasons (because 0.9.5 is already out, and is coded + * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level + * part is slightly different, by setting the highest bit. This means + * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start + * with 0x0090600S... + * + * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) + * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for + * major minor fix final patch/beta) + */ +# define OPENSSL_VERSION_NUMBER 0x1010107fL +# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1g 21 Apr 2020" + +/*- + * The macros below are to be used for shared library (.so, .dll, ...) + * versioning. That kind of versioning works a bit differently between + * operating systems. The most usual scheme is to set a major and a minor + * number, and have the runtime loader check that the major number is equal + * to what it was at application link time, while the minor number has to + * be greater or equal to what it was at application link time. With this + * scheme, the version number is usually part of the file name, like this: + * + * libcrypto.so.0.9 + * + * Some unixen also make a softlink with the major version number only: + * + * libcrypto.so.0 + * + * On Tru64 and IRIX 6.x it works a little bit differently. There, the + * shared library version is stored in the file, and is actually a series + * of versions, separated by colons. The rightmost version present in the + * library when linking an application is stored in the application to be + * matched at run time. When the application is run, a check is done to + * see if the library version stored in the application matches any of the + * versions in the version string of the library itself. + * This version string can be constructed in any way, depending on what + * kind of matching is desired. However, to implement the same scheme as + * the one used in the other unixen, all compatible versions, from lowest + * to highest, should be part of the string. Consecutive builds would + * give the following versions strings: + * + * 3.0 + * 3.0:3.1 + * 3.0:3.1:3.2 + * 4.0 + * 4.0:4.1 + * + * Notice how version 4 is completely incompatible with version, and + * therefore give the breach you can see. + * + * There may be other schemes as well that I haven't yet discovered. + * + * So, here's the way it works here: first of all, the library version + * number doesn't need at all to match the overall OpenSSL version. + * However, it's nice and more understandable if it actually does. + * The current library version is stored in the macro SHLIB_VERSION_NUMBER, + * which is just a piece of text in the format "M.m.e" (Major, minor, edit). + * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, + * we need to keep a history of version numbers, which is done in the + * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and + * should only keep the versions that are binary compatible with the current. + */ +# define SHLIB_VERSION_HISTORY "" +# define SHLIB_VERSION_NUMBER "1.1" + + +#ifdef __cplusplus +} +#endif +#endif /* HEADER_OPENSSLV_H */ diff -uprN postgresql-hll-2.14_old/include/openssl/ossl_typ.h postgresql-hll-2.14/include/openssl/ossl_typ.h --- postgresql-hll-2.14_old/include/openssl/ossl_typ.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ossl_typ.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,197 @@ +/* + * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OPENSSL_TYPES_H +# define HEADER_OPENSSL_TYPES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +# include + +# ifdef NO_ASN1_TYPEDEFS +# define ASN1_INTEGER ASN1_STRING +# define ASN1_ENUMERATED ASN1_STRING +# define ASN1_BIT_STRING ASN1_STRING +# define ASN1_OCTET_STRING ASN1_STRING +# define ASN1_PRINTABLESTRING ASN1_STRING +# define ASN1_T61STRING ASN1_STRING +# define ASN1_IA5STRING ASN1_STRING +# define ASN1_UTCTIME ASN1_STRING +# define ASN1_GENERALIZEDTIME ASN1_STRING +# define ASN1_TIME ASN1_STRING +# define ASN1_GENERALSTRING ASN1_STRING +# define ASN1_UNIVERSALSTRING ASN1_STRING +# define ASN1_BMPSTRING ASN1_STRING +# define ASN1_VISIBLESTRING ASN1_STRING +# define ASN1_UTF8STRING ASN1_STRING +# define ASN1_BOOLEAN int +# define ASN1_NULL int +# else +typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_ENUMERATED; +typedef struct asn1_string_st ASN1_BIT_STRING; +typedef struct asn1_string_st ASN1_OCTET_STRING; +typedef struct asn1_string_st ASN1_PRINTABLESTRING; +typedef struct asn1_string_st ASN1_T61STRING; +typedef struct asn1_string_st ASN1_IA5STRING; +typedef struct asn1_string_st ASN1_GENERALSTRING; +typedef struct asn1_string_st ASN1_UNIVERSALSTRING; +typedef struct asn1_string_st ASN1_BMPSTRING; +typedef struct asn1_string_st ASN1_UTCTIME; +typedef struct asn1_string_st ASN1_TIME; +typedef struct asn1_string_st ASN1_GENERALIZEDTIME; +typedef struct asn1_string_st ASN1_VISIBLESTRING; +typedef struct asn1_string_st ASN1_UTF8STRING; +typedef struct asn1_string_st ASN1_STRING; +typedef int ASN1_BOOLEAN; +typedef int ASN1_NULL; +# endif + +typedef struct asn1_object_st ASN1_OBJECT; + +typedef struct ASN1_ITEM_st ASN1_ITEM; +typedef struct asn1_pctx_st ASN1_PCTX; +typedef struct asn1_sctx_st ASN1_SCTX; + +# ifdef _WIN32 +# undef X509_NAME +# undef X509_EXTENSIONS +# undef PKCS7_ISSUER_AND_SERIAL +# undef PKCS7_SIGNER_INFO +# undef OCSP_REQUEST +# undef OCSP_RESPONSE +# endif + +# ifdef BIGNUM +# undef BIGNUM +# endif +struct dane_st; +typedef struct bio_st BIO; +typedef struct bignum_st BIGNUM; +typedef struct bignum_ctx BN_CTX; +typedef struct bn_blinding_st BN_BLINDING; +typedef struct bn_mont_ctx_st BN_MONT_CTX; +typedef struct bn_recp_ctx_st BN_RECP_CTX; +typedef struct bn_gencb_st BN_GENCB; + +typedef struct buf_mem_st BUF_MEM; + +typedef struct evp_cipher_st EVP_CIPHER; +typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; +typedef struct evp_md_st EVP_MD; +typedef struct evp_md_ctx_st EVP_MD_CTX; +typedef struct evp_pkey_st EVP_PKEY; + +typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; + +typedef struct evp_pkey_method_st EVP_PKEY_METHOD; +typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; + +typedef struct evp_Encode_Ctx_st EVP_ENCODE_CTX; + +typedef struct hmac_ctx_st HMAC_CTX; + +typedef struct dh_st DH; +typedef struct dh_method DH_METHOD; + +typedef struct dsa_st DSA; +typedef struct dsa_method DSA_METHOD; + +typedef struct rsa_st RSA; +typedef struct rsa_meth_st RSA_METHOD; +typedef struct rsa_pss_params_st RSA_PSS_PARAMS; + +typedef struct ec_key_st EC_KEY; +typedef struct ec_key_method_st EC_KEY_METHOD; + +typedef struct rand_meth_st RAND_METHOD; +typedef struct rand_drbg_st RAND_DRBG; + +typedef struct ssl_dane_st SSL_DANE; +typedef struct x509_st X509; +typedef struct X509_algor_st X509_ALGOR; +typedef struct X509_crl_st X509_CRL; +typedef struct x509_crl_method_st X509_CRL_METHOD; +typedef struct x509_revoked_st X509_REVOKED; +typedef struct X509_name_st X509_NAME; +typedef struct X509_pubkey_st X509_PUBKEY; +typedef struct x509_store_st X509_STORE; +typedef struct x509_store_ctx_st X509_STORE_CTX; + +typedef struct x509_object_st X509_OBJECT; +typedef struct x509_lookup_st X509_LOOKUP; +typedef struct x509_lookup_method_st X509_LOOKUP_METHOD; +typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; + +typedef struct x509_sig_info_st X509_SIG_INFO; + +typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; + +typedef struct v3_ext_ctx X509V3_CTX; +typedef struct conf_st CONF; +typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS; + +typedef struct ui_st UI; +typedef struct ui_method_st UI_METHOD; + +typedef struct engine_st ENGINE; +typedef struct ssl_st SSL; +typedef struct ssl_ctx_st SSL_CTX; + +typedef struct comp_ctx_st COMP_CTX; +typedef struct comp_method_st COMP_METHOD; + +typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; +typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; +typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; +typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; + +typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; +typedef struct DIST_POINT_st DIST_POINT; +typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; +typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; + +typedef struct crypto_ex_data_st CRYPTO_EX_DATA; + +typedef struct ocsp_req_ctx_st OCSP_REQ_CTX; +typedef struct ocsp_response_st OCSP_RESPONSE; +typedef struct ocsp_responder_id_st OCSP_RESPID; + +typedef struct sct_st SCT; +typedef struct sct_ctx_st SCT_CTX; +typedef struct ctlog_st CTLOG; +typedef struct ctlog_store_st CTLOG_STORE; +typedef struct ct_policy_eval_ctx_st CT_POLICY_EVAL_CTX; + +typedef struct ossl_store_info_st OSSL_STORE_INFO; +typedef struct ossl_store_search_st OSSL_STORE_SEARCH; + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \ + defined(INTMAX_MAX) && defined(UINTMAX_MAX) +typedef intmax_t ossl_intmax_t; +typedef uintmax_t ossl_uintmax_t; +#else +/* + * Not long long, because the C-library can only be expected to provide + * strtoll(), strtoull() at the same time as intmax_t and strtoimax(), + * strtoumax(). Since we use these for parsing arguments, we need the + * conversion functions, not just the sizes. + */ +typedef long ossl_intmax_t; +typedef unsigned long ossl_uintmax_t; +#endif + +#ifdef __cplusplus +} +#endif +#endif /* def HEADER_OPENSSL_TYPES_H */ diff -uprN postgresql-hll-2.14_old/include/openssl/pem2.h postgresql-hll-2.14/include/openssl/pem2.h --- postgresql-hll-2.14_old/include/openssl/pem2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pem2.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,13 @@ +/* + * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PEM2_H +# define HEADER_PEM2_H +# include +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pemerr.h postgresql-hll-2.14/include/openssl/pemerr.h --- postgresql-hll-2.14_old/include/openssl/pemerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pemerr.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,103 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PEMERR_H +# define HEADER_PEMERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_PEM_strings(void); + +/* + * PEM function codes. + */ +# define PEM_F_B2I_DSS 127 +# define PEM_F_B2I_PVK_BIO 128 +# define PEM_F_B2I_RSA 129 +# define PEM_F_CHECK_BITLEN_DSA 130 +# define PEM_F_CHECK_BITLEN_RSA 131 +# define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 +# define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 +# define PEM_F_DO_B2I 132 +# define PEM_F_DO_B2I_BIO 133 +# define PEM_F_DO_BLOB_HEADER 134 +# define PEM_F_DO_I2B 146 +# define PEM_F_DO_PK8PKEY 126 +# define PEM_F_DO_PK8PKEY_FP 125 +# define PEM_F_DO_PVK_BODY 135 +# define PEM_F_DO_PVK_HEADER 136 +# define PEM_F_GET_HEADER_AND_DATA 143 +# define PEM_F_GET_NAME 144 +# define PEM_F_I2B_PVK 137 +# define PEM_F_I2B_PVK_BIO 138 +# define PEM_F_LOAD_IV 101 +# define PEM_F_PEM_ASN1_READ 102 +# define PEM_F_PEM_ASN1_READ_BIO 103 +# define PEM_F_PEM_ASN1_WRITE 104 +# define PEM_F_PEM_ASN1_WRITE_BIO 105 +# define PEM_F_PEM_DEF_CALLBACK 100 +# define PEM_F_PEM_DO_HEADER 106 +# define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 +# define PEM_F_PEM_READ 108 +# define PEM_F_PEM_READ_BIO 109 +# define PEM_F_PEM_READ_BIO_DHPARAMS 141 +# define PEM_F_PEM_READ_BIO_EX 145 +# define PEM_F_PEM_READ_BIO_PARAMETERS 140 +# define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 +# define PEM_F_PEM_READ_DHPARAMS 142 +# define PEM_F_PEM_READ_PRIVATEKEY 124 +# define PEM_F_PEM_SIGNFINAL 112 +# define PEM_F_PEM_WRITE 113 +# define PEM_F_PEM_WRITE_BIO 114 +# define PEM_F_PEM_WRITE_PRIVATEKEY 139 +# define PEM_F_PEM_X509_INFO_READ 115 +# define PEM_F_PEM_X509_INFO_READ_BIO 116 +# define PEM_F_PEM_X509_INFO_WRITE_BIO 117 + +/* + * PEM reason codes. + */ +# define PEM_R_BAD_BASE64_DECODE 100 +# define PEM_R_BAD_DECRYPT 101 +# define PEM_R_BAD_END_LINE 102 +# define PEM_R_BAD_IV_CHARS 103 +# define PEM_R_BAD_MAGIC_NUMBER 116 +# define PEM_R_BAD_PASSWORD_READ 104 +# define PEM_R_BAD_VERSION_NUMBER 117 +# define PEM_R_BIO_WRITE_FAILURE 118 +# define PEM_R_CIPHER_IS_NULL 127 +# define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 +# define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119 +# define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120 +# define PEM_R_HEADER_TOO_LONG 128 +# define PEM_R_INCONSISTENT_HEADER 121 +# define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122 +# define PEM_R_KEYBLOB_TOO_SHORT 123 +# define PEM_R_MISSING_DEK_IV 129 +# define PEM_R_NOT_DEK_INFO 105 +# define PEM_R_NOT_ENCRYPTED 106 +# define PEM_R_NOT_PROC_TYPE 107 +# define PEM_R_NO_START_LINE 108 +# define PEM_R_PROBLEMS_GETTING_PASSWORD 109 +# define PEM_R_PVK_DATA_TOO_SHORT 124 +# define PEM_R_PVK_TOO_SHORT 125 +# define PEM_R_READ_KEY 111 +# define PEM_R_SHORT_HEADER 112 +# define PEM_R_UNEXPECTED_DEK_IV 130 +# define PEM_R_UNSUPPORTED_CIPHER 113 +# define PEM_R_UNSUPPORTED_ENCRYPTION 114 +# define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pem.h postgresql-hll-2.14/include/openssl/pem.h --- postgresql-hll-2.14_old/include/openssl/pem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pem.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,378 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PEM_H +# define HEADER_PEM_H + +# include +# include +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# define PEM_BUFSIZE 1024 + +# define PEM_STRING_X509_OLD "X509 CERTIFICATE" +# define PEM_STRING_X509 "CERTIFICATE" +# define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" +# define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" +# define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" +# define PEM_STRING_X509_CRL "X509 CRL" +# define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" +# define PEM_STRING_PUBLIC "PUBLIC KEY" +# define PEM_STRING_RSA "RSA PRIVATE KEY" +# define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" +# define PEM_STRING_DSA "DSA PRIVATE KEY" +# define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" +# define PEM_STRING_PKCS7 "PKCS7" +# define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" +# define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" +# define PEM_STRING_PKCS8INF "PRIVATE KEY" +# define PEM_STRING_DHPARAMS "DH PARAMETERS" +# define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" +# define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" +# define PEM_STRING_DSAPARAMS "DSA PARAMETERS" +# define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" +# define PEM_STRING_ECPARAMETERS "EC PARAMETERS" +# define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" +# define PEM_STRING_PARAMETERS "PARAMETERS" +# define PEM_STRING_CMS "CMS" + +# define PEM_TYPE_ENCRYPTED 10 +# define PEM_TYPE_MIC_ONLY 20 +# define PEM_TYPE_MIC_CLEAR 30 +# define PEM_TYPE_CLEAR 40 + +/* + * These macros make the PEM_read/PEM_write functions easier to maintain and + * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or + * IMPLEMENT_PEM_rw_cb(...) + */ + +# ifdef OPENSSL_NO_STDIO + +# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ +# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ +# else + +# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ +type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ +} + +# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x) \ +{ \ +return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, const type *x) \ +{ \ +return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ + } + +# endif + +# define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ +type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ +} + +# define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x) \ +{ \ +return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, const type *x) \ +{ \ +return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ +} + +# define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ + } + +# define IMPLEMENT_PEM_write(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_read_fp(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_const(name, type, str, asn1) + +# define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb(name, type, str, asn1) + +/* These are the same except they are for the declarations */ + +# if defined(OPENSSL_NO_STDIO) + +# define DECLARE_PEM_read_fp(name, type) /**/ +# define DECLARE_PEM_write_fp(name, type) /**/ +# define DECLARE_PEM_write_fp_const(name, type) /**/ +# define DECLARE_PEM_write_cb_fp(name, type) /**/ +# else + +# define DECLARE_PEM_read_fp(name, type) \ + type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x); + +# define DECLARE_PEM_write_fp_const(name, type) \ + int PEM_write_##name(FILE *fp, const type *x); + +# define DECLARE_PEM_write_cb_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +# endif + +# define DECLARE_PEM_read_bio(name, type) \ + type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x); + +# define DECLARE_PEM_write_bio_const(name, type) \ + int PEM_write_bio_##name(BIO *bp, const type *x); + +# define DECLARE_PEM_write_cb_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +# define DECLARE_PEM_write(name, type) \ + DECLARE_PEM_write_bio(name, type) \ + DECLARE_PEM_write_fp(name, type) +# define DECLARE_PEM_write_const(name, type) \ + DECLARE_PEM_write_bio_const(name, type) \ + DECLARE_PEM_write_fp_const(name, type) +# define DECLARE_PEM_write_cb(name, type) \ + DECLARE_PEM_write_cb_bio(name, type) \ + DECLARE_PEM_write_cb_fp(name, type) +# define DECLARE_PEM_read(name, type) \ + DECLARE_PEM_read_bio(name, type) \ + DECLARE_PEM_read_fp(name, type) +# define DECLARE_PEM_rw(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write(name, type) +# define DECLARE_PEM_rw_const(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_const(name, type) +# define DECLARE_PEM_rw_cb(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_cb(name, type) +typedef int pem_password_cb (char *buf, int size, int rwflag, void *userdata); + +int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); +int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len, + pem_password_cb *callback, void *u); + +int PEM_read_bio(BIO *bp, char **name, char **header, + unsigned char **data, long *len); +# define PEM_FLAG_SECURE 0x1 +# define PEM_FLAG_EAY_COMPATIBLE 0x2 +# define PEM_FLAG_ONLY_B64 0x4 +int PEM_read_bio_ex(BIO *bp, char **name, char **header, + unsigned char **data, long *len, unsigned int flags); +int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm, + const char *name, BIO *bp, pem_password_cb *cb, + void *u); +int PEM_write_bio(BIO *bp, const char *name, const char *hdr, + const unsigned char *data, long len); +int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, + const char *name, BIO *bp, pem_password_cb *cb, + void *u); +void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, + const EVP_CIPHER *enc, unsigned char *kstr, int klen, + pem_password_cb *cb, void *u); + +STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); +int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, + unsigned char *kstr, int klen, + pem_password_cb *cd, void *u); + +#ifndef OPENSSL_NO_STDIO +int PEM_read(FILE *fp, char **name, char **header, + unsigned char **data, long *len); +int PEM_write(FILE *fp, const char *name, const char *hdr, + const unsigned char *data, long len); +void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, + void *x, const EVP_CIPHER *enc, unsigned char *kstr, + int klen, pem_password_cb *callback, void *u); +STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); +#endif + +int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); +int PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt); +int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, + unsigned int *siglen, EVP_PKEY *pkey); + +/* The default pem_password_cb that's used internally */ +int PEM_def_callback(char *buf, int num, int rwflag, void *userdata); +void PEM_proc_type(char *buf, int type); +void PEM_dek_info(char *buf, const char *type, int len, char *str); + +# include + +DECLARE_PEM_rw(X509, X509) +DECLARE_PEM_rw(X509_AUX, X509) +DECLARE_PEM_rw(X509_REQ, X509_REQ) +DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) +DECLARE_PEM_rw(X509_CRL, X509_CRL) +DECLARE_PEM_rw(PKCS7, PKCS7) +DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) +DECLARE_PEM_rw(PKCS8, X509_SIG) +DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) +# ifndef OPENSSL_NO_RSA +DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) +DECLARE_PEM_rw_const(RSAPublicKey, RSA) +DECLARE_PEM_rw(RSA_PUBKEY, RSA) +# endif +# ifndef OPENSSL_NO_DSA +DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) +DECLARE_PEM_rw(DSA_PUBKEY, DSA) +DECLARE_PEM_rw_const(DSAparams, DSA) +# endif +# ifndef OPENSSL_NO_EC +DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) +DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) +DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) +# endif +# ifndef OPENSSL_NO_DH +DECLARE_PEM_rw_const(DHparams, DH) +DECLARE_PEM_write_const(DHxparams, DH) +# endif +DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) +DECLARE_PEM_rw(PUBKEY, EVP_PKEY) + +int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x, + const EVP_CIPHER *enc, + unsigned char *kstr, int klen, + pem_password_cb *cb, void *u); + +int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, + char *, int, pem_password_cb *, void *); +int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, + void *u); + +# ifndef OPENSSL_NO_STDIO +int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); +int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, + char *kstr, int klen, + pem_password_cb *cb, void *u); + +EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, + void *u); + +int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cd, + void *u); +# endif +EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); +int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); + +# ifndef OPENSSL_NO_DSA +EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); +EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); +EVP_PKEY *b2i_PrivateKey_bio(BIO *in); +EVP_PKEY *b2i_PublicKey_bio(BIO *in); +int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); +int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); +# ifndef OPENSSL_NO_RC4 +EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); +int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, + pem_password_cb *cb, void *u); +# endif +# endif + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pkcs12err.h postgresql-hll-2.14/include/openssl/pkcs12err.h --- postgresql-hll-2.14_old/include/openssl/pkcs12err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pkcs12err.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,81 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS12ERR_H +# define HEADER_PKCS12ERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_PKCS12_strings(void); + +/* + * PKCS12 function codes. + */ +# define PKCS12_F_OPENSSL_ASC2UNI 121 +# define PKCS12_F_OPENSSL_UNI2ASC 124 +# define PKCS12_F_OPENSSL_UNI2UTF8 127 +# define PKCS12_F_OPENSSL_UTF82UNI 129 +# define PKCS12_F_PKCS12_CREATE 105 +# define PKCS12_F_PKCS12_GEN_MAC 107 +# define PKCS12_F_PKCS12_INIT 109 +# define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106 +# define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108 +# define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117 +# define PKCS12_F_PKCS12_KEY_GEN_ASC 110 +# define PKCS12_F_PKCS12_KEY_GEN_UNI 111 +# define PKCS12_F_PKCS12_KEY_GEN_UTF8 116 +# define PKCS12_F_PKCS12_NEWPASS 128 +# define PKCS12_F_PKCS12_PACK_P7DATA 114 +# define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 +# define PKCS12_F_PKCS12_PARSE 118 +# define PKCS12_F_PKCS12_PBE_CRYPT 119 +# define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE0_P8INF 112 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE0_PKCS8 113 +# define PKCS12_F_PKCS12_SAFEBAG_CREATE_PKCS8_ENCRYPT 133 +# define PKCS12_F_PKCS12_SETUP_MAC 122 +# define PKCS12_F_PKCS12_SET_MAC 123 +# define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130 +# define PKCS12_F_PKCS12_UNPACK_P7DATA 131 +# define PKCS12_F_PKCS12_VERIFY_MAC 126 +# define PKCS12_F_PKCS8_ENCRYPT 125 +# define PKCS12_F_PKCS8_SET0_PBE 132 + +/* + * PKCS12 reason codes. + */ +# define PKCS12_R_CANT_PACK_STRUCTURE 100 +# define PKCS12_R_CONTENT_TYPE_NOT_DATA 121 +# define PKCS12_R_DECODE_ERROR 101 +# define PKCS12_R_ENCODE_ERROR 102 +# define PKCS12_R_ENCRYPT_ERROR 103 +# define PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE 120 +# define PKCS12_R_INVALID_NULL_ARGUMENT 104 +# define PKCS12_R_INVALID_NULL_PKCS12_POINTER 105 +# define PKCS12_R_IV_GEN_ERROR 106 +# define PKCS12_R_KEY_GEN_ERROR 107 +# define PKCS12_R_MAC_ABSENT 108 +# define PKCS12_R_MAC_GENERATION_ERROR 109 +# define PKCS12_R_MAC_SETUP_ERROR 110 +# define PKCS12_R_MAC_STRING_SET_ERROR 111 +# define PKCS12_R_MAC_VERIFY_FAILURE 113 +# define PKCS12_R_PARSE_ERROR 114 +# define PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR 115 +# define PKCS12_R_PKCS12_CIPHERFINAL_ERROR 116 +# define PKCS12_R_PKCS12_PBE_CRYPT_ERROR 117 +# define PKCS12_R_UNKNOWN_DIGEST_ALGORITHM 118 +# define PKCS12_R_UNSUPPORTED_PKCS12_MODE 119 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pkcs12.h postgresql-hll-2.14/include/openssl/pkcs12.h --- postgresql-hll-2.14_old/include/openssl/pkcs12.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pkcs12.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,223 @@ +/* + * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS12_H +# define HEADER_PKCS12_H + +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# define PKCS12_KEY_ID 1 +# define PKCS12_IV_ID 2 +# define PKCS12_MAC_ID 3 + +/* Default iteration count */ +# ifndef PKCS12_DEFAULT_ITER +# define PKCS12_DEFAULT_ITER PKCS5_DEFAULT_ITER +# endif + +# define PKCS12_MAC_KEY_LENGTH 20 + +# define PKCS12_SALT_LEN 8 + +/* It's not clear if these are actually needed... */ +# define PKCS12_key_gen PKCS12_key_gen_utf8 +# define PKCS12_add_friendlyname PKCS12_add_friendlyname_utf8 + +/* MS key usage constants */ + +# define KEY_EX 0x10 +# define KEY_SIG 0x80 + +typedef struct PKCS12_MAC_DATA_st PKCS12_MAC_DATA; + +typedef struct PKCS12_st PKCS12; + +typedef struct PKCS12_SAFEBAG_st PKCS12_SAFEBAG; + +DEFINE_STACK_OF(PKCS12_SAFEBAG) + +typedef struct pkcs12_bag_st PKCS12_BAGS; + +# define PKCS12_ERROR 0 +# define PKCS12_OK 1 + +/* Compatibility macros */ + +#if OPENSSL_API_COMPAT < 0x10100000L + +# define M_PKCS12_bag_type PKCS12_bag_type +# define M_PKCS12_cert_bag_type PKCS12_cert_bag_type +# define M_PKCS12_crl_bag_type PKCS12_cert_bag_type + +# define PKCS12_certbag2x509 PKCS12_SAFEBAG_get1_cert +# define PKCS12_certbag2scrl PKCS12_SAFEBAG_get1_crl +# define PKCS12_bag_type PKCS12_SAFEBAG_get_nid +# define PKCS12_cert_bag_type PKCS12_SAFEBAG_get_bag_nid +# define PKCS12_x5092certbag PKCS12_SAFEBAG_create_cert +# define PKCS12_x509crl2certbag PKCS12_SAFEBAG_create_crl +# define PKCS12_MAKE_KEYBAG PKCS12_SAFEBAG_create0_p8inf +# define PKCS12_MAKE_SHKEYBAG PKCS12_SAFEBAG_create_pkcs8_encrypt + +#endif + +DEPRECATEDIN_1_1_0(ASN1_TYPE *PKCS12_get_attr(const PKCS12_SAFEBAG *bag, int attr_nid)) + +ASN1_TYPE *PKCS8_get_attr(PKCS8_PRIV_KEY_INFO *p8, int attr_nid); +int PKCS12_mac_present(const PKCS12 *p12); +void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac, + const X509_ALGOR **pmacalg, + const ASN1_OCTET_STRING **psalt, + const ASN1_INTEGER **piter, + const PKCS12 *p12); + +const ASN1_TYPE *PKCS12_SAFEBAG_get0_attr(const PKCS12_SAFEBAG *bag, + int attr_nid); +const ASN1_OBJECT *PKCS12_SAFEBAG_get0_type(const PKCS12_SAFEBAG *bag); +int PKCS12_SAFEBAG_get_nid(const PKCS12_SAFEBAG *bag); +int PKCS12_SAFEBAG_get_bag_nid(const PKCS12_SAFEBAG *bag); + +X509 *PKCS12_SAFEBAG_get1_cert(const PKCS12_SAFEBAG *bag); +X509_CRL *PKCS12_SAFEBAG_get1_crl(const PKCS12_SAFEBAG *bag); +const STACK_OF(PKCS12_SAFEBAG) * +PKCS12_SAFEBAG_get0_safes(const PKCS12_SAFEBAG *bag); +const PKCS8_PRIV_KEY_INFO *PKCS12_SAFEBAG_get0_p8inf(const PKCS12_SAFEBAG *bag); +const X509_SIG *PKCS12_SAFEBAG_get0_pkcs8(const PKCS12_SAFEBAG *bag); + +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_cert(X509 *x509); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_crl(X509_CRL *crl); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_p8inf(PKCS8_PRIV_KEY_INFO *p8); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create0_pkcs8(X509_SIG *p8); +PKCS12_SAFEBAG *PKCS12_SAFEBAG_create_pkcs8_encrypt(int pbe_nid, + const char *pass, + int passlen, + unsigned char *salt, + int saltlen, int iter, + PKCS8_PRIV_KEY_INFO *p8inf); + +PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, + int nid1, int nid2); +PKCS8_PRIV_KEY_INFO *PKCS8_decrypt(const X509_SIG *p8, const char *pass, + int passlen); +PKCS8_PRIV_KEY_INFO *PKCS12_decrypt_skey(const PKCS12_SAFEBAG *bag, + const char *pass, int passlen); +X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, + const char *pass, int passlen, unsigned char *salt, + int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8); +X509_SIG *PKCS8_set0_pbe(const char *pass, int passlen, + PKCS8_PRIV_KEY_INFO *p8inf, X509_ALGOR *pbe); +PKCS7 *PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7data(PKCS7 *p7); +PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + STACK_OF(PKCS12_SAFEBAG) *bags); +STACK_OF(PKCS12_SAFEBAG) *PKCS12_unpack_p7encdata(PKCS7 *p7, const char *pass, + int passlen); + +int PKCS12_pack_authsafes(PKCS12 *p12, STACK_OF(PKCS7) *safes); +STACK_OF(PKCS7) *PKCS12_unpack_authsafes(const PKCS12 *p12); + +int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, + int namelen); +int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_friendlyname_utf8(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_CSPName_asc(PKCS12_SAFEBAG *bag, const char *name, + int namelen); +int PKCS12_add_friendlyname_uni(PKCS12_SAFEBAG *bag, + const unsigned char *name, int namelen); +int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage); +ASN1_TYPE *PKCS12_get_attr_gen(const STACK_OF(X509_ATTRIBUTE) *attrs, + int attr_nid); +char *PKCS12_get_friendlyname(PKCS12_SAFEBAG *bag); +const STACK_OF(X509_ATTRIBUTE) * +PKCS12_SAFEBAG_get0_attrs(const PKCS12_SAFEBAG *bag); +unsigned char *PKCS12_pbe_crypt(const X509_ALGOR *algor, + const char *pass, int passlen, + const unsigned char *in, int inlen, + unsigned char **data, int *datalen, + int en_de); +void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it, + const char *pass, int passlen, + const ASN1_OCTET_STRING *oct, int zbuf); +ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, + const ASN1_ITEM *it, + const char *pass, int passlen, + void *obj, int zbuf); +PKCS12 *PKCS12_init(int mode); +int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_key_gen_utf8(const char *pass, int passlen, unsigned char *salt, + int saltlen, int id, int iter, int n, + unsigned char *out, const EVP_MD *md_type); +int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, const EVP_CIPHER *cipher, + const EVP_MD *md_type, int en_de); +int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *mac, unsigned int *maclen); +int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen); +int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + const EVP_MD *md_type); +int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, + int saltlen, const EVP_MD *md_type); +unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, + unsigned char **uni, int *unilen); +char *OPENSSL_uni2asc(const unsigned char *uni, int unilen); +unsigned char *OPENSSL_utf82uni(const char *asc, int asclen, + unsigned char **uni, int *unilen); +char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen); + +DECLARE_ASN1_FUNCTIONS(PKCS12) +DECLARE_ASN1_FUNCTIONS(PKCS12_MAC_DATA) +DECLARE_ASN1_FUNCTIONS(PKCS12_SAFEBAG) +DECLARE_ASN1_FUNCTIONS(PKCS12_BAGS) + +DECLARE_ASN1_ITEM(PKCS12_SAFEBAGS) +DECLARE_ASN1_ITEM(PKCS12_AUTHSAFES) + +void PKCS12_PBE_add(void); +int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, + STACK_OF(X509) **ca); +PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, + X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, + int iter, int mac_iter, int keytype); + +PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert); +PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, + EVP_PKEY *key, int key_usage, int iter, + int key_nid, const char *pass); +int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, + int safe_nid, int iter, const char *pass); +PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid); + +int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); +# ifndef OPENSSL_NO_STDIO +int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); +# endif +PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); +# ifndef OPENSSL_NO_STDIO +PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12); +# endif +int PKCS12_newpass(PKCS12 *p12, const char *oldpass, const char *newpass); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pkcs7err.h postgresql-hll-2.14/include/openssl/pkcs7err.h --- postgresql-hll-2.14_old/include/openssl/pkcs7err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pkcs7err.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,103 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS7ERR_H +# define HEADER_PKCS7ERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_PKCS7_strings(void); + +/* + * PKCS7 function codes. + */ +# define PKCS7_F_DO_PKCS7_SIGNED_ATTRIB 136 +# define PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME 135 +# define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118 +# define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 +# define PKCS7_F_PKCS7_ADD_CRL 101 +# define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 +# define PKCS7_F_PKCS7_ADD_SIGNATURE 131 +# define PKCS7_F_PKCS7_ADD_SIGNER 103 +# define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125 +# define PKCS7_F_PKCS7_COPY_EXISTING_DIGEST 138 +# define PKCS7_F_PKCS7_CTRL 104 +# define PKCS7_F_PKCS7_DATADECODE 112 +# define PKCS7_F_PKCS7_DATAFINAL 128 +# define PKCS7_F_PKCS7_DATAINIT 105 +# define PKCS7_F_PKCS7_DATAVERIFY 107 +# define PKCS7_F_PKCS7_DECRYPT 114 +# define PKCS7_F_PKCS7_DECRYPT_RINFO 133 +# define PKCS7_F_PKCS7_ENCODE_RINFO 132 +# define PKCS7_F_PKCS7_ENCRYPT 115 +# define PKCS7_F_PKCS7_FINAL 134 +# define PKCS7_F_PKCS7_FIND_DIGEST 127 +# define PKCS7_F_PKCS7_GET0_SIGNERS 124 +# define PKCS7_F_PKCS7_RECIP_INFO_SET 130 +# define PKCS7_F_PKCS7_SET_CIPHER 108 +# define PKCS7_F_PKCS7_SET_CONTENT 109 +# define PKCS7_F_PKCS7_SET_DIGEST 126 +# define PKCS7_F_PKCS7_SET_TYPE 110 +# define PKCS7_F_PKCS7_SIGN 116 +# define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 +# define PKCS7_F_PKCS7_SIGNER_INFO_SET 129 +# define PKCS7_F_PKCS7_SIGNER_INFO_SIGN 139 +# define PKCS7_F_PKCS7_SIGN_ADD_SIGNER 137 +# define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119 +# define PKCS7_F_PKCS7_VERIFY 117 + +/* + * PKCS7 reason codes. + */ +# define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117 +# define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144 +# define PKCS7_R_CIPHER_NOT_INITIALIZED 116 +# define PKCS7_R_CONTENT_AND_DATA_PRESENT 118 +# define PKCS7_R_CTRL_ERROR 152 +# define PKCS7_R_DECRYPT_ERROR 119 +# define PKCS7_R_DIGEST_FAILURE 101 +# define PKCS7_R_ENCRYPTION_CTRL_FAILURE 149 +# define PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 150 +# define PKCS7_R_ERROR_ADDING_RECIPIENT 120 +# define PKCS7_R_ERROR_SETTING_CIPHER 121 +# define PKCS7_R_INVALID_NULL_POINTER 143 +# define PKCS7_R_INVALID_SIGNED_DATA_TYPE 155 +# define PKCS7_R_NO_CONTENT 122 +# define PKCS7_R_NO_DEFAULT_DIGEST 151 +# define PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND 154 +# define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 +# define PKCS7_R_NO_SIGNATURES_ON_DATA 123 +# define PKCS7_R_NO_SIGNERS 142 +# define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 +# define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124 +# define PKCS7_R_PKCS7_ADD_SIGNER_ERROR 153 +# define PKCS7_R_PKCS7_DATASIGN 145 +# define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127 +# define PKCS7_R_SIGNATURE_FAILURE 105 +# define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128 +# define PKCS7_R_SIGNING_CTRL_FAILURE 147 +# define PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 148 +# define PKCS7_R_SMIME_TEXT_ERROR 129 +# define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 +# define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 +# define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 +# define PKCS7_R_UNKNOWN_DIGEST_TYPE 109 +# define PKCS7_R_UNKNOWN_OPERATION 110 +# define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111 +# define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112 +# define PKCS7_R_WRONG_CONTENT_TYPE 113 +# define PKCS7_R_WRONG_PKCS7_TYPE 114 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/pkcs7.h postgresql-hll-2.14/include/openssl/pkcs7.h --- postgresql-hll-2.14_old/include/openssl/pkcs7.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/pkcs7.h 2020-12-12 17:06:43.337349199 +0800 @@ -0,0 +1,319 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_PKCS7_H +# define HEADER_PKCS7_H + +# include +# include +# include + +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/*- +Encryption_ID DES-CBC +Digest_ID MD5 +Digest_Encryption_ID rsaEncryption +Key_Encryption_ID rsaEncryption +*/ + +typedef struct pkcs7_issuer_and_serial_st { + X509_NAME *issuer; + ASN1_INTEGER *serial; +} PKCS7_ISSUER_AND_SERIAL; + +typedef struct pkcs7_signer_info_st { + ASN1_INTEGER *version; /* version 1 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *digest_alg; + STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ + X509_ALGOR *digest_enc_alg; + ASN1_OCTET_STRING *enc_digest; + STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ + /* The private key to sign with */ + EVP_PKEY *pkey; +} PKCS7_SIGNER_INFO; + +DEFINE_STACK_OF(PKCS7_SIGNER_INFO) + +typedef struct pkcs7_recip_info_st { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; + X509_ALGOR *key_enc_algor; + ASN1_OCTET_STRING *enc_key; + X509 *cert; /* get the pub-key from this */ +} PKCS7_RECIP_INFO; + +DEFINE_STACK_OF(PKCS7_RECIP_INFO) + +typedef struct pkcs7_signed_st { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + struct pkcs7_st *contents; +} PKCS7_SIGNED; +/* + * The above structure is very very similar to PKCS7_SIGN_ENVELOPE. How about + * merging the two + */ + +typedef struct pkcs7_enc_content_st { + ASN1_OBJECT *content_type; + X509_ALGOR *algorithm; + ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ + const EVP_CIPHER *cipher; +} PKCS7_ENC_CONTENT; + +typedef struct pkcs7_enveloped_st { + ASN1_INTEGER *version; /* version 0 */ + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; + PKCS7_ENC_CONTENT *enc_data; +} PKCS7_ENVELOPE; + +typedef struct pkcs7_signedandenveloped_st { + ASN1_INTEGER *version; /* version 1 */ + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; + PKCS7_ENC_CONTENT *enc_data; + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; +} PKCS7_SIGN_ENVELOPE; + +typedef struct pkcs7_digest_st { + ASN1_INTEGER *version; /* version 0 */ + X509_ALGOR *md; /* md used */ + struct pkcs7_st *contents; + ASN1_OCTET_STRING *digest; +} PKCS7_DIGEST; + +typedef struct pkcs7_encrypted_st { + ASN1_INTEGER *version; /* version 0 */ + PKCS7_ENC_CONTENT *enc_data; +} PKCS7_ENCRYPT; + +typedef struct pkcs7_st { + /* + * The following is non NULL if it contains ASN1 encoding of this + * structure + */ + unsigned char *asn1; + long length; +# define PKCS7_S_HEADER 0 +# define PKCS7_S_BODY 1 +# define PKCS7_S_TAIL 2 + int state; /* used during processing */ + int detached; + ASN1_OBJECT *type; + /* content as defined by the type */ + /* + * all encryption/message digests are applied to the 'contents', leaving + * out the 'type' field. + */ + union { + char *ptr; + /* NID_pkcs7_data */ + ASN1_OCTET_STRING *data; + /* NID_pkcs7_signed */ + PKCS7_SIGNED *sign; + /* NID_pkcs7_enveloped */ + PKCS7_ENVELOPE *enveloped; + /* NID_pkcs7_signedAndEnveloped */ + PKCS7_SIGN_ENVELOPE *signed_and_enveloped; + /* NID_pkcs7_digest */ + PKCS7_DIGEST *digest; + /* NID_pkcs7_encrypted */ + PKCS7_ENCRYPT *encrypted; + /* Anything else */ + ASN1_TYPE *other; + } d; +} PKCS7; + +DEFINE_STACK_OF(PKCS7) + +# define PKCS7_OP_SET_DETACHED_SIGNATURE 1 +# define PKCS7_OP_GET_DETACHED_SIGNATURE 2 + +# define PKCS7_get_signed_attributes(si) ((si)->auth_attr) +# define PKCS7_get_attributes(si) ((si)->unauth_attr) + +# define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) +# define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted) +# define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) +# define PKCS7_type_is_signedAndEnveloped(a) \ + (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) +# define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) +# define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest) + +# define PKCS7_set_detached(p,v) \ + PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) +# define PKCS7_get_detached(p) \ + PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) + +# define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7)) + +/* S/MIME related flags */ + +# define PKCS7_TEXT 0x1 +# define PKCS7_NOCERTS 0x2 +# define PKCS7_NOSIGS 0x4 +# define PKCS7_NOCHAIN 0x8 +# define PKCS7_NOINTERN 0x10 +# define PKCS7_NOVERIFY 0x20 +# define PKCS7_DETACHED 0x40 +# define PKCS7_BINARY 0x80 +# define PKCS7_NOATTR 0x100 +# define PKCS7_NOSMIMECAP 0x200 +# define PKCS7_NOOLDMIMETYPE 0x400 +# define PKCS7_CRLFEOL 0x800 +# define PKCS7_STREAM 0x1000 +# define PKCS7_NOCRL 0x2000 +# define PKCS7_PARTIAL 0x4000 +# define PKCS7_REUSE_DIGEST 0x8000 +# define PKCS7_NO_DUAL_CONTENT 0x10000 + +/* Flags: for compatibility with older code */ + +# define SMIME_TEXT PKCS7_TEXT +# define SMIME_NOCERTS PKCS7_NOCERTS +# define SMIME_NOSIGS PKCS7_NOSIGS +# define SMIME_NOCHAIN PKCS7_NOCHAIN +# define SMIME_NOINTERN PKCS7_NOINTERN +# define SMIME_NOVERIFY PKCS7_NOVERIFY +# define SMIME_DETACHED PKCS7_DETACHED +# define SMIME_BINARY PKCS7_BINARY +# define SMIME_NOATTR PKCS7_NOATTR + +/* CRLF ASCII canonicalisation */ +# define SMIME_ASCIICRLF 0x80000 + +DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) + +int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, + const EVP_MD *type, unsigned char *md, + unsigned int *len); +# ifndef OPENSSL_NO_STDIO +PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7); +int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7); +# endif +PKCS7 *PKCS7_dup(PKCS7 *p7); +PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7); +int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7); +int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); +int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags); + +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE) +DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST) +DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT) +DECLARE_ASN1_FUNCTIONS(PKCS7) + +DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN) +DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY) + +DECLARE_ASN1_NDEF_FUNCTION(PKCS7) +DECLARE_ASN1_PRINT_FUNCTION(PKCS7) + +long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); + +int PKCS7_set_type(PKCS7 *p7, int type); +int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other); +int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); +int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, + const EVP_MD *dgst); +int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si); +int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); +int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); +int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); +int PKCS7_content_new(PKCS7 *p7, int nid); +int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, + BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, + X509 *x509); + +BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); +int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); +BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); + +PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, + EVP_PKEY *pkey, const EVP_MD *dgst); +X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md); +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); + +PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); +void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk, + X509_ALGOR **pdig, X509_ALGOR **psig); +void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc); +int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); +int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); +int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7); + +PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); +ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type, + void *data); +int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value); +ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid); +ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid); +int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); + +PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, + BIO *data, int flags); + +PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, + X509 *signcert, EVP_PKEY *pkey, + const EVP_MD *md, int flags); + +int PKCS7_final(PKCS7 *p7, BIO *data, int flags); +int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, + BIO *indata, BIO *out, int flags); +STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, + int flags); +PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, + int flags); +int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, + int flags); + +int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, + STACK_OF(X509_ALGOR) *cap); +STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); +int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); + +int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid); +int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t); +int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, + const unsigned char *md, int mdlen); + +int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); +PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); + +BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rand_drbg.h postgresql-hll-2.14/include/openssl/rand_drbg.h --- postgresql-hll-2.14_old/include/openssl/rand_drbg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rand_drbg.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,130 @@ +/* + * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_DRBG_RAND_H +# define HEADER_DRBG_RAND_H + +# include +# include +# include + +/* + * RAND_DRBG flags + * + * Note: if new flags are added, the constant `rand_drbg_used_flags` + * in drbg_lib.c needs to be updated accordingly. + */ + +/* In CTR mode, disable derivation function ctr_df */ +# define RAND_DRBG_FLAG_CTR_NO_DF 0x1 + + +# if OPENSSL_API_COMPAT < 0x10200000L +/* This #define was replaced by an internal constant and should not be used. */ +# define RAND_DRBG_USED_FLAGS (RAND_DRBG_FLAG_CTR_NO_DF) +# endif + +/* + * Default security strength (in the sense of [NIST SP 800-90Ar1]) + * + * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that + * of the cipher by collecting less entropy. The current DRBG implementation + * does not take RAND_DRBG_STRENGTH into account and sets the strength of the + * DRBG to that of the cipher. + * + * RAND_DRBG_STRENGTH is currently only used for the legacy RAND + * implementation. + * + * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and + * NID_aes_256_ctr + */ +# define RAND_DRBG_STRENGTH 256 +/* Default drbg type */ +# define RAND_DRBG_TYPE NID_aes_256_ctr +/* Default drbg flags */ +# define RAND_DRBG_FLAGS 0 + + +# ifdef __cplusplus +extern "C" { +# endif + +/* + * Object lifetime functions. + */ +RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent); +RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent); +int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags); +int RAND_DRBG_set_defaults(int type, unsigned int flags); +int RAND_DRBG_instantiate(RAND_DRBG *drbg, + const unsigned char *pers, size_t perslen); +int RAND_DRBG_uninstantiate(RAND_DRBG *drbg); +void RAND_DRBG_free(RAND_DRBG *drbg); + +/* + * Object "use" functions. + */ +int RAND_DRBG_reseed(RAND_DRBG *drbg, + const unsigned char *adin, size_t adinlen, + int prediction_resistance); +int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen, + int prediction_resistance, + const unsigned char *adin, size_t adinlen); +int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen); + +int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval); +int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval); + +int RAND_DRBG_set_reseed_defaults( + unsigned int master_reseed_interval, + unsigned int slave_reseed_interval, + time_t master_reseed_time_interval, + time_t slave_reseed_time_interval + ); + +RAND_DRBG *RAND_DRBG_get0_master(void); +RAND_DRBG *RAND_DRBG_get0_public(void); +RAND_DRBG *RAND_DRBG_get0_private(void); + +/* + * EXDATA + */ +# define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef) +int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg); +void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx); + +/* + * Callback function typedefs + */ +typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg, + unsigned char **pout, + int entropy, size_t min_len, + size_t max_len, + int prediction_resistance); +typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx, + unsigned char *out, size_t outlen); +typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout, + int entropy, size_t min_len, + size_t max_len); +typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg, + unsigned char *out, size_t outlen); + +int RAND_DRBG_set_callbacks(RAND_DRBG *drbg, + RAND_DRBG_get_entropy_fn get_entropy, + RAND_DRBG_cleanup_entropy_fn cleanup_entropy, + RAND_DRBG_get_nonce_fn get_nonce, + RAND_DRBG_cleanup_nonce_fn cleanup_nonce); + + +# ifdef __cplusplus +} +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/randerr.h postgresql-hll-2.14/include/openssl/randerr.h --- postgresql-hll-2.14_old/include/openssl/randerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/randerr.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,94 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RANDERR_H +# define HEADER_RANDERR_H + +# include + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_RAND_strings(void); + +/* + * RAND function codes. + */ +# define RAND_F_DATA_COLLECT_METHOD 127 +# define RAND_F_DRBG_BYTES 101 +# define RAND_F_DRBG_GET_ENTROPY 105 +# define RAND_F_DRBG_SETUP 117 +# define RAND_F_GET_ENTROPY 106 +# define RAND_F_RAND_BYTES 100 +# define RAND_F_RAND_DRBG_ENABLE_LOCKING 119 +# define RAND_F_RAND_DRBG_GENERATE 107 +# define RAND_F_RAND_DRBG_GET_ENTROPY 120 +# define RAND_F_RAND_DRBG_GET_NONCE 123 +# define RAND_F_RAND_DRBG_INSTANTIATE 108 +# define RAND_F_RAND_DRBG_NEW 109 +# define RAND_F_RAND_DRBG_RESEED 110 +# define RAND_F_RAND_DRBG_RESTART 102 +# define RAND_F_RAND_DRBG_SET 104 +# define RAND_F_RAND_DRBG_SET_DEFAULTS 121 +# define RAND_F_RAND_DRBG_UNINSTANTIATE 118 +# define RAND_F_RAND_LOAD_FILE 111 +# define RAND_F_RAND_POOL_ACQUIRE_ENTROPY 122 +# define RAND_F_RAND_POOL_ADD 103 +# define RAND_F_RAND_POOL_ADD_BEGIN 113 +# define RAND_F_RAND_POOL_ADD_END 114 +# define RAND_F_RAND_POOL_ATTACH 124 +# define RAND_F_RAND_POOL_BYTES_NEEDED 115 +# define RAND_F_RAND_POOL_GROW 125 +# define RAND_F_RAND_POOL_NEW 116 +# define RAND_F_RAND_PSEUDO_BYTES 126 +# define RAND_F_RAND_WRITE_FILE 112 + +/* + * RAND reason codes. + */ +# define RAND_R_ADDITIONAL_INPUT_TOO_LONG 102 +# define RAND_R_ALREADY_INSTANTIATED 103 +# define RAND_R_ARGUMENT_OUT_OF_RANGE 105 +# define RAND_R_CANNOT_OPEN_FILE 121 +# define RAND_R_DRBG_ALREADY_INITIALIZED 129 +# define RAND_R_DRBG_NOT_INITIALISED 104 +# define RAND_R_ENTROPY_INPUT_TOO_LONG 106 +# define RAND_R_ENTROPY_OUT_OF_RANGE 124 +# define RAND_R_ERROR_ENTROPY_POOL_WAS_IGNORED 127 +# define RAND_R_ERROR_INITIALISING_DRBG 107 +# define RAND_R_ERROR_INSTANTIATING_DRBG 108 +# define RAND_R_ERROR_RETRIEVING_ADDITIONAL_INPUT 109 +# define RAND_R_ERROR_RETRIEVING_ENTROPY 110 +# define RAND_R_ERROR_RETRIEVING_NONCE 111 +# define RAND_R_FAILED_TO_CREATE_LOCK 126 +# define RAND_R_FUNC_NOT_IMPLEMENTED 101 +# define RAND_R_FWRITE_ERROR 123 +# define RAND_R_GENERATE_ERROR 112 +# define RAND_R_INTERNAL_ERROR 113 +# define RAND_R_IN_ERROR_STATE 114 +# define RAND_R_NOT_A_REGULAR_FILE 122 +# define RAND_R_NOT_INSTANTIATED 115 +# define RAND_R_NO_DRBG_IMPLEMENTATION_SELECTED 128 +# define RAND_R_PARENT_LOCKING_NOT_ENABLED 130 +# define RAND_R_PARENT_STRENGTH_TOO_WEAK 131 +# define RAND_R_PERSONALISATION_STRING_TOO_LONG 116 +# define RAND_R_PREDICTION_RESISTANCE_NOT_SUPPORTED 133 +# define RAND_R_PRNG_NOT_SEEDED 100 +# define RAND_R_RANDOM_POOL_OVERFLOW 125 +# define RAND_R_RANDOM_POOL_UNDERFLOW 134 +# define RAND_R_REQUEST_TOO_LARGE_FOR_DRBG 117 +# define RAND_R_RESEED_ERROR 118 +# define RAND_R_SELFTEST_FAILURE 119 +# define RAND_R_TOO_LITTLE_NONCE_REQUESTED 135 +# define RAND_R_TOO_MUCH_NONCE_REQUESTED 136 +# define RAND_R_UNSUPPORTED_DRBG_FLAGS 132 +# define RAND_R_UNSUPPORTED_DRBG_TYPE 120 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rand.h postgresql-hll-2.14/include/openssl/rand.h --- postgresql-hll-2.14_old/include/openssl/rand.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rand.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,77 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RAND_H +# define HEADER_RAND_H + +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +struct rand_meth_st { + int (*seed) (const void *buf, int num); + int (*bytes) (unsigned char *buf, int num); + void (*cleanup) (void); + int (*add) (const void *buf, int num, double randomness); + int (*pseudorand) (unsigned char *buf, int num); + int (*status) (void); +}; + +int RAND_set_rand_method(const RAND_METHOD *meth); +const RAND_METHOD *RAND_get_rand_method(void); +# ifndef OPENSSL_NO_ENGINE +int RAND_set_rand_engine(ENGINE *engine); +# endif + +RAND_METHOD *RAND_OpenSSL(void); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define RAND_cleanup() while(0) continue +# endif +int RAND_bytes(unsigned char *buf, int num); +int RAND_priv_bytes(unsigned char *buf, int num); +DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num)) + +void RAND_seed(const void *buf, int num); +void RAND_keep_random_devices_open(int keep); + +# if defined(__ANDROID__) && defined(__NDK_FPABI__) +__NDK_FPABI__ /* __attribute__((pcs("aapcs"))) on ARM */ +# endif +void RAND_add(const void *buf, int num, double randomness); +int RAND_load_file(const char *file, long max_bytes); +int RAND_write_file(const char *file); +const char *RAND_file_name(char *file, size_t num); +int RAND_status(void); + +# ifndef OPENSSL_NO_EGD +int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); +int RAND_egd(const char *path); +int RAND_egd_bytes(const char *path, int bytes); +# endif + +int RAND_poll(void); + +# if defined(_WIN32) && (defined(BASETYPES) || defined(_WINDEF_H)) +/* application has to include in order to use these */ +DEPRECATEDIN_1_1_0(void RAND_screen(void)) +DEPRECATEDIN_1_1_0(int RAND_event(UINT, WPARAM, LPARAM)) +# endif + + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rc2.h postgresql-hll-2.14/include/openssl/rc2.h --- postgresql-hll-2.14_old/include/openssl/rc2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rc2.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,51 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC2_H +# define HEADER_RC2_H + +# include + +# ifndef OPENSSL_NO_RC2 +# ifdef __cplusplus +extern "C" { +# endif + +typedef unsigned int RC2_INT; + +# define RC2_ENCRYPT 1 +# define RC2_DECRYPT 0 + +# define RC2_BLOCK 8 +# define RC2_KEY_LENGTH 16 + +typedef struct rc2_key_st { + RC2_INT data[64]; +} RC2_KEY; + +void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits); +void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, + RC2_KEY *key, int enc); +void RC2_encrypt(unsigned long *data, RC2_KEY *key); +void RC2_decrypt(unsigned long *data, RC2_KEY *key); +void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + RC2_KEY *ks, unsigned char *iv, int enc); +void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC2_KEY *schedule, unsigned char *ivec, + int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rc4.h postgresql-hll-2.14/include/openssl/rc4.h --- postgresql-hll-2.14_old/include/openssl/rc4.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rc4.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,36 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC4_H +# define HEADER_RC4_H + +# include + +# ifndef OPENSSL_NO_RC4 +# include +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rc4_key_st { + RC4_INT x, y; + RC4_INT data[256]; +} RC4_KEY; + +const char *RC4_options(void); +void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); +void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, + unsigned char *outdata); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rc5.h postgresql-hll-2.14/include/openssl/rc5.h --- postgresql-hll-2.14_old/include/openssl/rc5.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rc5.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,63 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RC5_H +# define HEADER_RC5_H + +# include + +# ifndef OPENSSL_NO_RC5 +# ifdef __cplusplus +extern "C" { +# endif + +# define RC5_ENCRYPT 1 +# define RC5_DECRYPT 0 + +# define RC5_32_INT unsigned int + +# define RC5_32_BLOCK 8 +# define RC5_32_KEY_LENGTH 16/* This is a default, max is 255 */ + +/* + * This are the only values supported. Tweak the code if you want more The + * most supported modes will be RC5-32/12/16 RC5-32/16/8 + */ +# define RC5_8_ROUNDS 8 +# define RC5_12_ROUNDS 12 +# define RC5_16_ROUNDS 16 + +typedef struct rc5_key_st { + /* Number of rounds */ + int rounds; + RC5_32_INT data[2 * (RC5_16_ROUNDS + 1)]; +} RC5_32_KEY; + +void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data, + int rounds); +void RC5_32_ecb_encrypt(const unsigned char *in, unsigned char *out, + RC5_32_KEY *key, int enc); +void RC5_32_encrypt(unsigned long *data, RC5_32_KEY *key); +void RC5_32_decrypt(unsigned long *data, RC5_32_KEY *key); +void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *ks, unsigned char *iv, + int enc); +void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *schedule, + unsigned char *ivec, int *num, int enc); +void RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, RC5_32_KEY *schedule, + unsigned char *ivec, int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ripemd.h postgresql-hll-2.14/include/openssl/ripemd.h --- postgresql-hll-2.14_old/include/openssl/ripemd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ripemd.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,47 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RIPEMD_H +# define HEADER_RIPEMD_H + +# include + +#ifndef OPENSSL_NO_RMD160 +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +# define RIPEMD160_LONG unsigned int + +# define RIPEMD160_CBLOCK 64 +# define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4) +# define RIPEMD160_DIGEST_LENGTH 20 + +typedef struct RIPEMD160state_st { + RIPEMD160_LONG A, B, C, D, E; + RIPEMD160_LONG Nl, Nh; + RIPEMD160_LONG data[RIPEMD160_LBLOCK]; + unsigned int num; +} RIPEMD160_CTX; + +int RIPEMD160_Init(RIPEMD160_CTX *c); +int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); +int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); +unsigned char *RIPEMD160(const unsigned char *d, size_t n, unsigned char *md); +void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); + +# ifdef __cplusplus +} +# endif +# endif + + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rsaerr.h postgresql-hll-2.14/include/openssl/rsaerr.h --- postgresql-hll-2.14_old/include/openssl/rsaerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rsaerr.h 2020-12-12 17:06:43.338349212 +0800 @@ -0,0 +1,167 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RSAERR_H +# define HEADER_RSAERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_RSA_strings(void); + +/* + * RSA function codes. + */ +# define RSA_F_CHECK_PADDING_MD 140 +# define RSA_F_ENCODE_PKCS1 146 +# define RSA_F_INT_RSA_VERIFY 145 +# define RSA_F_OLD_RSA_PRIV_DECODE 147 +# define RSA_F_PKEY_PSS_INIT 165 +# define RSA_F_PKEY_RSA_CTRL 143 +# define RSA_F_PKEY_RSA_CTRL_STR 144 +# define RSA_F_PKEY_RSA_SIGN 142 +# define RSA_F_PKEY_RSA_VERIFY 149 +# define RSA_F_PKEY_RSA_VERIFYRECOVER 141 +# define RSA_F_RSA_ALGOR_TO_MD 156 +# define RSA_F_RSA_BUILTIN_KEYGEN 129 +# define RSA_F_RSA_CHECK_KEY 123 +# define RSA_F_RSA_CHECK_KEY_EX 160 +# define RSA_F_RSA_CMS_DECRYPT 159 +# define RSA_F_RSA_CMS_VERIFY 158 +# define RSA_F_RSA_ITEM_VERIFY 148 +# define RSA_F_RSA_METH_DUP 161 +# define RSA_F_RSA_METH_NEW 162 +# define RSA_F_RSA_METH_SET1_NAME 163 +# define RSA_F_RSA_MGF1_TO_MD 157 +# define RSA_F_RSA_MULTIP_INFO_NEW 166 +# define RSA_F_RSA_NEW_METHOD 106 +# define RSA_F_RSA_NULL 124 +# define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132 +# define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133 +# define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134 +# define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135 +# define RSA_F_RSA_OSSL_PRIVATE_DECRYPT 101 +# define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT 102 +# define RSA_F_RSA_OSSL_PUBLIC_DECRYPT 103 +# define RSA_F_RSA_OSSL_PUBLIC_ENCRYPT 104 +# define RSA_F_RSA_PADDING_ADD_NONE 107 +# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 +# define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1 154 +# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 +# define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1 152 +# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 +# define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 +# define RSA_F_RSA_PADDING_ADD_SSLV23 110 +# define RSA_F_RSA_PADDING_ADD_X931 127 +# define RSA_F_RSA_PADDING_CHECK_NONE 111 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1 153 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 +# define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 +# define RSA_F_RSA_PADDING_CHECK_SSLV23 114 +# define RSA_F_RSA_PADDING_CHECK_X931 128 +# define RSA_F_RSA_PARAM_DECODE 164 +# define RSA_F_RSA_PRINT 115 +# define RSA_F_RSA_PRINT_FP 116 +# define RSA_F_RSA_PRIV_DECODE 150 +# define RSA_F_RSA_PRIV_ENCODE 138 +# define RSA_F_RSA_PSS_GET_PARAM 151 +# define RSA_F_RSA_PSS_TO_CTX 155 +# define RSA_F_RSA_PUB_DECODE 139 +# define RSA_F_RSA_SETUP_BLINDING 136 +# define RSA_F_RSA_SIGN 117 +# define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 +# define RSA_F_RSA_VERIFY 119 +# define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 +# define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1 126 +# define RSA_F_SETUP_TBUF 167 + +/* + * RSA reason codes. + */ +# define RSA_R_ALGORITHM_MISMATCH 100 +# define RSA_R_BAD_E_VALUE 101 +# define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 +# define RSA_R_BAD_PAD_BYTE_COUNT 103 +# define RSA_R_BAD_SIGNATURE 104 +# define RSA_R_BLOCK_TYPE_IS_NOT_01 106 +# define RSA_R_BLOCK_TYPE_IS_NOT_02 107 +# define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 +# define RSA_R_DATA_TOO_LARGE 109 +# define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 +# define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132 +# define RSA_R_DATA_TOO_SMALL 111 +# define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 +# define RSA_R_DIGEST_DOES_NOT_MATCH 158 +# define RSA_R_DIGEST_NOT_ALLOWED 145 +# define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 +# define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 +# define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 +# define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 +# define RSA_R_FIRST_OCTET_INVALID 133 +# define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 144 +# define RSA_R_INVALID_DIGEST 157 +# define RSA_R_INVALID_DIGEST_LENGTH 143 +# define RSA_R_INVALID_HEADER 137 +# define RSA_R_INVALID_LABEL 160 +# define RSA_R_INVALID_MESSAGE_LENGTH 131 +# define RSA_R_INVALID_MGF1_MD 156 +# define RSA_R_INVALID_MULTI_PRIME_KEY 167 +# define RSA_R_INVALID_OAEP_PARAMETERS 161 +# define RSA_R_INVALID_PADDING 138 +# define RSA_R_INVALID_PADDING_MODE 141 +# define RSA_R_INVALID_PSS_PARAMETERS 149 +# define RSA_R_INVALID_PSS_SALTLEN 146 +# define RSA_R_INVALID_SALT_LENGTH 150 +# define RSA_R_INVALID_TRAILER 139 +# define RSA_R_INVALID_X931_DIGEST 142 +# define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 +# define RSA_R_KEY_PRIME_NUM_INVALID 165 +# define RSA_R_KEY_SIZE_TOO_SMALL 120 +# define RSA_R_LAST_OCTET_INVALID 134 +# define RSA_R_MISSING_PRIVATE_KEY 179 +# define RSA_R_MGF1_DIGEST_NOT_ALLOWED 152 +# define RSA_R_MODULUS_TOO_LARGE 105 +# define RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R 168 +# define RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D 169 +# define RSA_R_MP_R_NOT_PRIME 170 +# define RSA_R_NO_PUBLIC_EXPONENT 140 +# define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 +# define RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES 172 +# define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 +# define RSA_R_OAEP_DECODING_ERROR 121 +# define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 148 +# define RSA_R_PADDING_CHECK_FAILED 114 +# define RSA_R_PKCS_DECODING_ERROR 159 +# define RSA_R_PSS_SALTLEN_TOO_SMALL 164 +# define RSA_R_P_NOT_PRIME 128 +# define RSA_R_Q_NOT_PRIME 129 +# define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 +# define RSA_R_SLEN_CHECK_FAILED 136 +# define RSA_R_SLEN_RECOVERY_FAILED 135 +# define RSA_R_SSLV3_ROLLBACK_ATTACK 115 +# define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 +# define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 +# define RSA_R_UNKNOWN_DIGEST 166 +# define RSA_R_UNKNOWN_MASK_DIGEST 151 +# define RSA_R_UNKNOWN_PADDING_TYPE 118 +# define RSA_R_UNSUPPORTED_ENCRYPTION_TYPE 162 +# define RSA_R_UNSUPPORTED_LABEL_SOURCE 163 +# define RSA_R_UNSUPPORTED_MASK_ALGORITHM 153 +# define RSA_R_UNSUPPORTED_MASK_PARAMETER 154 +# define RSA_R_UNSUPPORTED_SIGNATURE_TYPE 155 +# define RSA_R_VALUE_MISSING 147 +# define RSA_R_WRONG_SIGNATURE_LENGTH 119 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/rsa.h postgresql-hll-2.14/include/openssl/rsa.h --- postgresql-hll-2.14_old/include/openssl/rsa.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/rsa.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,513 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_RSA_H +# define HEADER_RSA_H + +# include + +# ifndef OPENSSL_NO_RSA +# include +# include +# include +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif +# include +# ifdef __cplusplus +extern "C" { +# endif + +/* The types RSA and RSA_METHOD are defined in ossl_typ.h */ + +# ifndef OPENSSL_RSA_MAX_MODULUS_BITS +# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 +# endif + +# define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024 + +# ifndef OPENSSL_RSA_SMALL_MODULUS_BITS +# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 +# endif +# ifndef OPENSSL_RSA_MAX_PUBEXP_BITS + +/* exponent limit enforced for "large" modulus only */ +# define OPENSSL_RSA_MAX_PUBEXP_BITS 64 +# endif + +# define RSA_3 0x3L +# define RSA_F4 0x10001L + +/* based on RFC 8017 appendix A.1.2 */ +# define RSA_ASN1_VERSION_DEFAULT 0 +# define RSA_ASN1_VERSION_MULTI 1 + +# define RSA_DEFAULT_PRIME_NUM 2 + +# define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private + * match */ + +# define RSA_FLAG_CACHE_PUBLIC 0x0002 +# define RSA_FLAG_CACHE_PRIVATE 0x0004 +# define RSA_FLAG_BLINDING 0x0008 +# define RSA_FLAG_THREAD_SAFE 0x0010 +/* + * This flag means the private key operations will be handled by rsa_mod_exp + * and that they do not depend on the private key components being present: + * for example a key stored in external hardware. Without this flag + * bn_mod_exp gets called when private key components are absent. + */ +# define RSA_FLAG_EXT_PKEY 0x0020 + +/* + * new with 0.9.6j and 0.9.7b; the built-in + * RSA implementation now uses blinding by + * default (ignoring RSA_FLAG_BLINDING), + * but other engines might not need it + */ +# define RSA_FLAG_NO_BLINDING 0x0080 +# if OPENSSL_API_COMPAT < 0x10100000L +/* + * Does nothing. Previously this switched off constant time behaviour. + */ +# define RSA_FLAG_NO_CONSTTIME 0x0000 +# endif +# if OPENSSL_API_COMPAT < 0x00908000L +/* deprecated name for the flag*/ +/* + * new with 0.9.7h; the built-in RSA + * implementation now uses constant time + * modular exponentiation for secret exponents + * by default. This flag causes the + * faster variable sliding window method to + * be used for all exponents. + */ +# define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME +# endif + +# define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \ + RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_RSA_PADDING, pad, NULL) + +# define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \ + RSA_pkey_ctx_ctrl(ctx, -1, EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad) + +# define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \ + RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ + EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL) +/* Salt length matches digest */ +# define RSA_PSS_SALTLEN_DIGEST -1 +/* Verify only: auto detect salt length */ +# define RSA_PSS_SALTLEN_AUTO -2 +/* Set salt length to maximum possible */ +# define RSA_PSS_SALTLEN_MAX -3 +/* Old compatible max salt length for sign only */ +# define RSA_PSS_SALTLEN_MAX_SIGN -2 + +# define EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(ctx, len) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_PSS_SALTLEN, len, NULL) + +# define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \ + RSA_pkey_ctx_ctrl(ctx, (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \ + EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, 0, plen) + +# define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \ + RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL) + +# define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \ + RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp) + +# define EVP_PKEY_CTX_set_rsa_keygen_primes(ctx, primes) \ + RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES, primes, NULL) + +# define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \ + RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, EVP_PKEY_OP_KEYGEN, \ + EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)(md)) + +# define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \ + RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)(pmd)) + +# define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)(pmd)) + +# define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)(l)) + +# define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \ + EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)(l)) + +# define EVP_PKEY_CTX_set_rsa_pss_keygen_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA_PSS, \ + EVP_PKEY_OP_KEYGEN, EVP_PKEY_CTRL_MD, \ + 0, (void *)(md)) + +# define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1) +# define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2) + +# define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3) +# define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4) +# define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5) + +# define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6) +# define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7) +# define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8) + +# define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9) +# define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10) + +# define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11) +# define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12) + +# define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES (EVP_PKEY_ALG_CTRL + 13) + +# define RSA_PKCS1_PADDING 1 +# define RSA_SSLV23_PADDING 2 +# define RSA_NO_PADDING 3 +# define RSA_PKCS1_OAEP_PADDING 4 +# define RSA_X931_PADDING 5 +/* EVP_PKEY_ only */ +# define RSA_PKCS1_PSS_PADDING 6 + +# define RSA_PKCS1_PADDING_SIZE 11 + +# define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) +# define RSA_get_app_data(s) RSA_get_ex_data(s,0) + +RSA *RSA_new(void); +RSA *RSA_new_method(ENGINE *engine); +int RSA_bits(const RSA *rsa); +int RSA_size(const RSA *rsa); +int RSA_security_bits(const RSA *rsa); + +int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); +int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); +int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp); +int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[], + BIGNUM *coeffs[], int pnum); +void RSA_get0_key(const RSA *r, + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d); +void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q); +int RSA_get_multi_prime_extra_count(const RSA *r); +int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]); +void RSA_get0_crt_params(const RSA *r, + const BIGNUM **dmp1, const BIGNUM **dmq1, + const BIGNUM **iqmp); +int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], + const BIGNUM *coeffs[]); +const BIGNUM *RSA_get0_n(const RSA *d); +const BIGNUM *RSA_get0_e(const RSA *d); +const BIGNUM *RSA_get0_d(const RSA *d); +const BIGNUM *RSA_get0_p(const RSA *d); +const BIGNUM *RSA_get0_q(const RSA *d); +const BIGNUM *RSA_get0_dmp1(const RSA *r); +const BIGNUM *RSA_get0_dmq1(const RSA *r); +const BIGNUM *RSA_get0_iqmp(const RSA *r); +const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r); +void RSA_clear_flags(RSA *r, int flags); +int RSA_test_flags(const RSA *r, int flags); +void RSA_set_flags(RSA *r, int flags); +int RSA_get_version(RSA *r); +ENGINE *RSA_get0_engine(const RSA *r); + +/* Deprecated version */ +DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void + (*callback) (int, int, void *), + void *cb_arg)) + +/* New version */ +int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); +/* Multi-prime version */ +int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, + BIGNUM *e, BN_GENCB *cb); + +int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, + BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2, + const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2, + const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb); +int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, + BN_GENCB *cb); + +int RSA_check_key(const RSA *); +int RSA_check_key_ex(const RSA *, BN_GENCB *cb); + /* next 4 return -1 on error */ +int RSA_public_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_private_encrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_public_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_private_decrypt(int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +void RSA_free(RSA *r); +/* "up" the RSA object's reference count */ +int RSA_up_ref(RSA *r); + +int RSA_flags(const RSA *r); + +void RSA_set_default_method(const RSA_METHOD *meth); +const RSA_METHOD *RSA_get_default_method(void); +const RSA_METHOD *RSA_null_method(void); +const RSA_METHOD *RSA_get_method(const RSA *rsa); +int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); + +/* these are the actual RSA functions */ +const RSA_METHOD *RSA_PKCS1_OpenSSL(void); + +int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2); + +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey) +DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey) + +struct rsa_pss_params_st { + X509_ALGOR *hashAlgorithm; + X509_ALGOR *maskGenAlgorithm; + ASN1_INTEGER *saltLength; + ASN1_INTEGER *trailerField; + /* Decoded hash algorithm from maskGenAlgorithm */ + X509_ALGOR *maskHash; +}; + +DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) + +typedef struct rsa_oaep_params_st { + X509_ALGOR *hashFunc; + X509_ALGOR *maskGenFunc; + X509_ALGOR *pSourceFunc; + /* Decoded hash algorithm from maskGenFunc */ + X509_ALGOR *maskHash; +} RSA_OAEP_PARAMS; + +DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS) + +# ifndef OPENSSL_NO_STDIO +int RSA_print_fp(FILE *fp, const RSA *r, int offset); +# endif + +int RSA_print(BIO *bp, const RSA *r, int offset); + +/* + * The following 2 functions sign and verify a X509_SIG ASN1 object inside + * PKCS#1 padded RSA encryption + */ +int RSA_sign(int type, const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, RSA *rsa); +int RSA_verify(int type, const unsigned char *m, unsigned int m_length, + const unsigned char *sigbuf, unsigned int siglen, RSA *rsa); + +/* + * The following 2 function sign and verify a ASN1_OCTET_STRING object inside + * PKCS#1 padded RSA encryption + */ +int RSA_sign_ASN1_OCTET_STRING(int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + RSA *rsa); +int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m, + unsigned int m_length, unsigned char *sigbuf, + unsigned int siglen, RSA *rsa); + +int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); +void RSA_blinding_off(RSA *rsa); +BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx); + +int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, + const unsigned char *f, int fl, + int rsa_len); +int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, + const unsigned char *f, int fl, + int rsa_len); +int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed, + long seedlen, const EVP_MD *dgst); +int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, + const unsigned char *f, int fl, + const unsigned char *p, int pl); +int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len, + const unsigned char *p, int pl); +int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, + const unsigned char *from, int flen, + const unsigned char *param, int plen, + const EVP_MD *md, const EVP_MD *mgf1md); +int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, + const unsigned char *from, int flen, + int num, const unsigned char *param, + int plen, const EVP_MD *md, + const EVP_MD *mgf1md); +int RSA_padding_add_SSLv23(unsigned char *to, int tlen, + const unsigned char *f, int fl); +int RSA_padding_check_SSLv23(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f, + int fl); +int RSA_padding_check_none(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f, + int fl); +int RSA_padding_check_X931(unsigned char *to, int tlen, + const unsigned char *f, int fl, int rsa_len); +int RSA_X931_hash_id(int nid); + +int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, + const EVP_MD *Hash, const unsigned char *EM, + int sLen); +int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, + const unsigned char *mHash, const EVP_MD *Hash, + int sLen); + +int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, + const EVP_MD *Hash, const EVP_MD *mgf1Hash, + const unsigned char *EM, int sLen); + +int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM, + const unsigned char *mHash, + const EVP_MD *Hash, const EVP_MD *mgf1Hash, + int sLen); + +#define RSA_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef) +int RSA_set_ex_data(RSA *r, int idx, void *arg); +void *RSA_get_ex_data(const RSA *r, int idx); + +RSA *RSAPublicKey_dup(RSA *rsa); +RSA *RSAPrivateKey_dup(RSA *rsa); + +/* + * If this flag is set the RSA method is FIPS compliant and can be used in + * FIPS mode. This is set in the validated module method. If an application + * sets this flag in its own methods it is its responsibility to ensure the + * result is compliant. + */ + +# define RSA_FLAG_FIPS_METHOD 0x0400 + +/* + * If this flag is set the operations normally disabled in FIPS mode are + * permitted it is then the applications responsibility to ensure that the + * usage is compliant. + */ + +# define RSA_FLAG_NON_FIPS_ALLOW 0x0400 +/* + * Application has decided PRNG is good enough to generate a key: don't + * check. + */ +# define RSA_FLAG_CHECKED 0x0800 + +RSA_METHOD *RSA_meth_new(const char *name, int flags); +void RSA_meth_free(RSA_METHOD *meth); +RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth); +const char *RSA_meth_get0_name(const RSA_METHOD *meth); +int RSA_meth_set1_name(RSA_METHOD *meth, const char *name); +int RSA_meth_get_flags(const RSA_METHOD *meth); +int RSA_meth_set_flags(RSA_METHOD *meth, int flags); +void *RSA_meth_get0_app_data(const RSA_METHOD *meth); +int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data); +int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_pub_enc(RSA_METHOD *rsa, + int (*pub_enc) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_pub_dec(RSA_METHOD *rsa, + int (*pub_dec) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_priv_enc(RSA_METHOD *rsa, + int (*priv_enc) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) + (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_meth_set_priv_dec(RSA_METHOD *rsa, + int (*priv_dec) (int flen, const unsigned char *from, + unsigned char *to, RSA *rsa, + int padding)); +int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) + (BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx); +int RSA_meth_set_mod_exp(RSA_METHOD *rsa, + int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa, + BN_CTX *ctx)); +int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) + (BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa, + int (*bn_mod_exp) (BIGNUM *r, + const BIGNUM *a, + const BIGNUM *p, + const BIGNUM *m, + BN_CTX *ctx, + BN_MONT_CTX *m_ctx)); +int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa); +int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa)); +int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa); +int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa)); +int (*RSA_meth_get_sign(const RSA_METHOD *meth)) + (int type, + const unsigned char *m, unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + const RSA *rsa); +int RSA_meth_set_sign(RSA_METHOD *rsa, + int (*sign) (int type, const unsigned char *m, + unsigned int m_length, + unsigned char *sigret, unsigned int *siglen, + const RSA *rsa)); +int (*RSA_meth_get_verify(const RSA_METHOD *meth)) + (int dtype, const unsigned char *m, + unsigned int m_length, const unsigned char *sigbuf, + unsigned int siglen, const RSA *rsa); +int RSA_meth_set_verify(RSA_METHOD *rsa, + int (*verify) (int dtype, const unsigned char *m, + unsigned int m_length, + const unsigned char *sigbuf, + unsigned int siglen, const RSA *rsa)); +int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) + (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); +int RSA_meth_set_keygen(RSA_METHOD *rsa, + int (*keygen) (RSA *rsa, int bits, BIGNUM *e, + BN_GENCB *cb)); +int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) + (RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb); +int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth, + int (*keygen) (RSA *rsa, int bits, + int primes, BIGNUM *e, + BN_GENCB *cb)); + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/safestack.h postgresql-hll-2.14/include/openssl/safestack.h --- postgresql-hll-2.14_old/include/openssl/safestack.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/safestack.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,207 @@ +/* + * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SAFESTACK_H +# define HEADER_SAFESTACK_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# define STACK_OF(type) struct stack_st_##type + +# define SKM_DEFINE_STACK_OF(t1, t2, t3) \ + STACK_OF(t1); \ + typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \ + typedef void (*sk_##t1##_freefunc)(t3 *a); \ + typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \ + static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \ + { \ + return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \ + { \ + return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_free((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_zero((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \ + { \ + return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \ + (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \ + { \ + return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \ + { \ + OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \ + { \ + return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \ + } \ + static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \ + { \ + return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \ + { \ + return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \ + } \ + static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \ + { \ + OPENSSL_sk_sort((OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \ + { \ + return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \ + } \ + static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \ + sk_##t1##_copyfunc copyfunc, \ + sk_##t1##_freefunc freefunc) \ + { \ + return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((const OPENSSL_STACK *)sk, \ + (OPENSSL_sk_copyfunc)copyfunc, \ + (OPENSSL_sk_freefunc)freefunc); \ + } \ + static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \ + { \ + return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \ + } + +# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2) +# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t) +# define DEFINE_SPECIAL_STACK_OF_CONST(t1, t2) \ + SKM_DEFINE_STACK_OF(t1, const t2, t2) +# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t) + +/*- + * Strings are special: normally an lhash entry will point to a single + * (somewhat) mutable object. In the case of strings: + * + * a) Instead of a single char, there is an array of chars, NUL-terminated. + * b) The string may have be immutable. + * + * So, they need their own declarations. Especially important for + * type-checking tools, such as Deputy. + * + * In practice, however, it appears to be hard to have a const + * string. For now, I'm settling for dealing with the fact it is a + * string at all. + */ +typedef char *OPENSSL_STRING; +typedef const char *OPENSSL_CSTRING; + +/*- + * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but + * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned + * above, instead of a single char each entry is a NUL-terminated array of + * chars. So, we have to implement STRING specially for STACK_OF. This is + * dealt with in the autogenerated macros below. + */ +DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char) +DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char) + +/* + * Similarly, we sometimes use a block of characters, NOT nul-terminated. + * These should also be distinguished from "normal" stacks. + */ +typedef void *OPENSSL_BLOCK; +DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void) + +/* + * If called without higher optimization (min. -xO3) the Oracle Developer + * Studio compiler generates code for the defined (static inline) functions + * above. + * This would later lead to the linker complaining about missing symbols when + * this header file is included but the resulting object is not linked against + * the Crypto library (openssl#6912). + */ +# ifdef __SUNPRO_C +# pragma weak OPENSSL_sk_num +# pragma weak OPENSSL_sk_value +# pragma weak OPENSSL_sk_new +# pragma weak OPENSSL_sk_new_null +# pragma weak OPENSSL_sk_new_reserve +# pragma weak OPENSSL_sk_reserve +# pragma weak OPENSSL_sk_free +# pragma weak OPENSSL_sk_zero +# pragma weak OPENSSL_sk_delete +# pragma weak OPENSSL_sk_delete_ptr +# pragma weak OPENSSL_sk_push +# pragma weak OPENSSL_sk_unshift +# pragma weak OPENSSL_sk_pop +# pragma weak OPENSSL_sk_shift +# pragma weak OPENSSL_sk_pop_free +# pragma weak OPENSSL_sk_insert +# pragma weak OPENSSL_sk_set +# pragma weak OPENSSL_sk_find +# pragma weak OPENSSL_sk_find_ex +# pragma weak OPENSSL_sk_sort +# pragma weak OPENSSL_sk_is_sorted +# pragma weak OPENSSL_sk_dup +# pragma weak OPENSSL_sk_deep_copy +# pragma weak OPENSSL_sk_set_cmp_func +# endif /* __SUNPRO_C */ + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/seed.h postgresql-hll-2.14/include/openssl/seed.h --- postgresql-hll-2.14_old/include/openssl/seed.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/seed.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,96 @@ +/* + * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Neither the name of author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef HEADER_SEED_H +# define HEADER_SEED_H + +# include + +# ifndef OPENSSL_NO_SEED +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* look whether we need 'long' to get 32 bits */ +# ifdef AES_LONG +# ifndef SEED_LONG +# define SEED_LONG 1 +# endif +# endif + +# include + +# define SEED_BLOCK_SIZE 16 +# define SEED_KEY_LENGTH 16 + +typedef struct seed_key_st { +# ifdef SEED_LONG + unsigned long data[32]; +# else + unsigned int data[32]; +# endif +} SEED_KEY_SCHEDULE; + +void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], + SEED_KEY_SCHEDULE *ks); + +void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], + unsigned char d[SEED_BLOCK_SIZE], + const SEED_KEY_SCHEDULE *ks); +void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], + unsigned char d[SEED_BLOCK_SIZE], + const SEED_KEY_SCHEDULE *ks); + +void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, + const SEED_KEY_SCHEDULE *ks, int enc); +void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len, + const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int enc); +void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int *num, + int enc); +void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const SEED_KEY_SCHEDULE *ks, + unsigned char ivec[SEED_BLOCK_SIZE], int *num); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/sha.h postgresql-hll-2.14/include/openssl/sha.h --- postgresql-hll-2.14_old/include/openssl/sha.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/sha.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,119 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SHA_H +# define HEADER_SHA_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/*- + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! SHA_LONG has to be at least 32 bits wide. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ +# define SHA_LONG unsigned int + +# define SHA_LBLOCK 16 +# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ +# define SHA_LAST_BLOCK (SHA_CBLOCK-8) +# define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st { + SHA_LONG h0, h1, h2, h3, h4; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num; +} SHA_CTX; + +int SHA1_Init(SHA_CTX *c); +int SHA1_Update(SHA_CTX *c, const void *data, size_t len); +int SHA1_Final(unsigned char *md, SHA_CTX *c); +unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); +void SHA1_Transform(SHA_CTX *c, const unsigned char *data); + +# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a + * contiguous array of 32 bit wide + * big-endian values. */ + +typedef struct SHA256state_st { + SHA_LONG h[8]; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num, md_len; +} SHA256_CTX; + +int SHA224_Init(SHA256_CTX *c); +int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA224_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); +int SHA256_Init(SHA256_CTX *c); +int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); +int SHA256_Final(unsigned char *md, SHA256_CTX *c); +unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); +void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); + +# define SHA224_DIGEST_LENGTH 28 +# define SHA256_DIGEST_LENGTH 32 +# define SHA384_DIGEST_LENGTH 48 +# define SHA512_DIGEST_LENGTH 64 + +/* + * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 + * being exactly 64-bit wide. See Implementation Notes in sha512.c + * for further details. + */ +/* + * SHA-512 treats input data as a + * contiguous array of 64 bit + * wide big-endian values. + */ +# define SHA512_CBLOCK (SHA_LBLOCK*8) +# if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) +# define SHA_LONG64 unsigned __int64 +# define U64(C) C##UI64 +# elif defined(__arch64__) +# define SHA_LONG64 unsigned long +# define U64(C) C##UL +# else +# define SHA_LONG64 unsigned long long +# define U64(C) C##ULL +# endif + +typedef struct SHA512state_st { + SHA_LONG64 h[8]; + SHA_LONG64 Nl, Nh; + union { + SHA_LONG64 d[SHA_LBLOCK]; + unsigned char p[SHA512_CBLOCK]; + } u; + unsigned int num, md_len; +} SHA512_CTX; + +int SHA384_Init(SHA512_CTX *c); +int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA384_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); +int SHA512_Init(SHA512_CTX *c); +int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); +int SHA512_Final(unsigned char *md, SHA512_CTX *c); +unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); +void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/srp.h postgresql-hll-2.14/include/openssl/srp.h --- postgresql-hll-2.14_old/include/openssl/srp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/srp.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,135 @@ +/* + * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2004, EdelKey Project. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + * + * Originally written by Christophe Renou and Peter Sylvester, + * for the EdelKey project. + */ + +#ifndef HEADER_SRP_H +# define HEADER_SRP_H + +#include + +#ifndef OPENSSL_NO_SRP +# include +# include +# include +# include +# include + +# ifdef __cplusplus +extern "C" { +# endif + +typedef struct SRP_gN_cache_st { + char *b64_bn; + BIGNUM *bn; +} SRP_gN_cache; + + +DEFINE_STACK_OF(SRP_gN_cache) + +typedef struct SRP_user_pwd_st { + /* Owned by us. */ + char *id; + BIGNUM *s; + BIGNUM *v; + /* Not owned by us. */ + const BIGNUM *g; + const BIGNUM *N; + /* Owned by us. */ + char *info; +} SRP_user_pwd; + +void SRP_user_pwd_free(SRP_user_pwd *user_pwd); + +DEFINE_STACK_OF(SRP_user_pwd) + +typedef struct SRP_VBASE_st { + STACK_OF(SRP_user_pwd) *users_pwd; + STACK_OF(SRP_gN_cache) *gN_cache; +/* to simulate a user */ + char *seed_key; + const BIGNUM *default_g; + const BIGNUM *default_N; +} SRP_VBASE; + +/* + * Internal structure storing N and g pair + */ +typedef struct SRP_gN_st { + char *id; + const BIGNUM *g; + const BIGNUM *N; +} SRP_gN; + +DEFINE_STACK_OF(SRP_gN) + +SRP_VBASE *SRP_VBASE_new(char *seed_key); +void SRP_VBASE_free(SRP_VBASE *vb); +int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); + +/* This method ignores the configured seed and fails for an unknown user. */ +DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)) +/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/ +SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username); + +char *SRP_create_verifier(const char *user, const char *pass, char **salt, + char **verifier, const char *N, const char *g); +int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, + BIGNUM **verifier, const BIGNUM *N, + const BIGNUM *g); + +# define SRP_NO_ERROR 0 +# define SRP_ERR_VBASE_INCOMPLETE_FILE 1 +# define SRP_ERR_VBASE_BN_LIB 2 +# define SRP_ERR_OPEN_FILE 3 +# define SRP_ERR_MEMORY 4 + +# define DB_srptype 0 +# define DB_srpverifier 1 +# define DB_srpsalt 2 +# define DB_srpid 3 +# define DB_srpgN 4 +# define DB_srpinfo 5 +# undef DB_NUMBER +# define DB_NUMBER 6 + +# define DB_SRP_INDEX 'I' +# define DB_SRP_VALID 'V' +# define DB_SRP_REVOKED 'R' +# define DB_SRP_MODIF 'v' + +/* see srp.c */ +char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N); +SRP_gN *SRP_get_default_gN(const char *id); + +/* server side .... */ +BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u, + const BIGNUM *b, const BIGNUM *N); +BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, + const BIGNUM *v); +int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N); +BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); + +/* client side .... */ +BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass); +BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g); +BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, + const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); +int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N); + +# define SRP_MINIMAL_N 1024 + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/srtp.h postgresql-hll-2.14/include/openssl/srtp.h --- postgresql-hll-2.14_old/include/openssl/srtp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/srtp.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * DTLS code by Eric Rescorla + * + * Copyright (C) 2006, Network Resonance, Inc. Copyright (C) 2011, RTFM, Inc. + */ + +#ifndef HEADER_D1_SRTP_H +# define HEADER_D1_SRTP_H + +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# define SRTP_AES128_CM_SHA1_80 0x0001 +# define SRTP_AES128_CM_SHA1_32 0x0002 +# define SRTP_AES128_F8_SHA1_80 0x0003 +# define SRTP_AES128_F8_SHA1_32 0x0004 +# define SRTP_NULL_SHA1_80 0x0005 +# define SRTP_NULL_SHA1_32 0x0006 + +/* AEAD SRTP protection profiles from RFC 7714 */ +# define SRTP_AEAD_AES_128_GCM 0x0007 +# define SRTP_AEAD_AES_256_GCM 0x0008 + +# ifndef OPENSSL_NO_SRTP + +__owur int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles); +__owur int SSL_set_tlsext_use_srtp(SSL *ssl, const char *profiles); + +__owur STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *ssl); +__owur SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s); + +# endif + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ssl2.h postgresql-hll-2.14/include/openssl/ssl2.h --- postgresql-hll-2.14_old/include/openssl/ssl2.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ssl2.h 2020-12-12 17:06:43.339349225 +0800 @@ -0,0 +1,24 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SSL2_H +# define HEADER_SSL2_H + +#ifdef __cplusplus +extern "C" { +#endif + +# define SSL2_VERSION 0x0002 + +# define SSL2_MT_CLIENT_HELLO 1 + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ssl3.h postgresql-hll-2.14/include/openssl/ssl3.h --- postgresql-hll-2.14_old/include/openssl/ssl3.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ssl3.h 2020-12-12 17:06:43.340349238 +0800 @@ -0,0 +1,339 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SSL3_H +# define HEADER_SSL3_H + +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Signalling cipher suite value from RFC 5746 + * (TLS_EMPTY_RENEGOTIATION_INFO_SCSV) + */ +# define SSL3_CK_SCSV 0x030000FF + +/* + * Signalling cipher suite value from draft-ietf-tls-downgrade-scsv-00 + * (TLS_FALLBACK_SCSV) + */ +# define SSL3_CK_FALLBACK_SCSV 0x03005600 + +# define SSL3_CK_RSA_NULL_MD5 0x03000001 +# define SSL3_CK_RSA_NULL_SHA 0x03000002 +# define SSL3_CK_RSA_RC4_40_MD5 0x03000003 +# define SSL3_CK_RSA_RC4_128_MD5 0x03000004 +# define SSL3_CK_RSA_RC4_128_SHA 0x03000005 +# define SSL3_CK_RSA_RC2_40_MD5 0x03000006 +# define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 +# define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 +# define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 +# define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A + +# define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B +# define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C +# define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D +# define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E +# define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F +# define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 + +# define SSL3_CK_DHE_DSS_DES_40_CBC_SHA 0x03000011 +# define SSL3_CK_EDH_DSS_DES_40_CBC_SHA SSL3_CK_DHE_DSS_DES_40_CBC_SHA +# define SSL3_CK_DHE_DSS_DES_64_CBC_SHA 0x03000012 +# define SSL3_CK_EDH_DSS_DES_64_CBC_SHA SSL3_CK_DHE_DSS_DES_64_CBC_SHA +# define SSL3_CK_DHE_DSS_DES_192_CBC3_SHA 0x03000013 +# define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA SSL3_CK_DHE_DSS_DES_192_CBC3_SHA +# define SSL3_CK_DHE_RSA_DES_40_CBC_SHA 0x03000014 +# define SSL3_CK_EDH_RSA_DES_40_CBC_SHA SSL3_CK_DHE_RSA_DES_40_CBC_SHA +# define SSL3_CK_DHE_RSA_DES_64_CBC_SHA 0x03000015 +# define SSL3_CK_EDH_RSA_DES_64_CBC_SHA SSL3_CK_DHE_RSA_DES_64_CBC_SHA +# define SSL3_CK_DHE_RSA_DES_192_CBC3_SHA 0x03000016 +# define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA SSL3_CK_DHE_RSA_DES_192_CBC3_SHA + +# define SSL3_CK_ADH_RC4_40_MD5 0x03000017 +# define SSL3_CK_ADH_RC4_128_MD5 0x03000018 +# define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 +# define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A +# define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B + +/* a bundle of RFC standard cipher names, generated from ssl3_ciphers[] */ +# define SSL3_RFC_RSA_NULL_MD5 "TLS_RSA_WITH_NULL_MD5" +# define SSL3_RFC_RSA_NULL_SHA "TLS_RSA_WITH_NULL_SHA" +# define SSL3_RFC_RSA_DES_192_CBC3_SHA "TLS_RSA_WITH_3DES_EDE_CBC_SHA" +# define SSL3_RFC_DHE_DSS_DES_192_CBC3_SHA "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" +# define SSL3_RFC_DHE_RSA_DES_192_CBC3_SHA "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" +# define SSL3_RFC_ADH_DES_192_CBC_SHA "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" +# define SSL3_RFC_RSA_IDEA_128_SHA "TLS_RSA_WITH_IDEA_CBC_SHA" +# define SSL3_RFC_RSA_RC4_128_MD5 "TLS_RSA_WITH_RC4_128_MD5" +# define SSL3_RFC_RSA_RC4_128_SHA "TLS_RSA_WITH_RC4_128_SHA" +# define SSL3_RFC_ADH_RC4_128_MD5 "TLS_DH_anon_WITH_RC4_128_MD5" + +# define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" +# define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" +# define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" +# define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" +# define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" +# define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" +# define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" +# define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" +# define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" +# define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" + +# define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" +# define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" +# define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" +# define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" +# define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" +# define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" + +# define SSL3_TXT_DHE_DSS_DES_40_CBC_SHA "EXP-DHE-DSS-DES-CBC-SHA" +# define SSL3_TXT_DHE_DSS_DES_64_CBC_SHA "DHE-DSS-DES-CBC-SHA" +# define SSL3_TXT_DHE_DSS_DES_192_CBC3_SHA "DHE-DSS-DES-CBC3-SHA" +# define SSL3_TXT_DHE_RSA_DES_40_CBC_SHA "EXP-DHE-RSA-DES-CBC-SHA" +# define SSL3_TXT_DHE_RSA_DES_64_CBC_SHA "DHE-RSA-DES-CBC-SHA" +# define SSL3_TXT_DHE_RSA_DES_192_CBC3_SHA "DHE-RSA-DES-CBC3-SHA" + +/* + * This next block of six "EDH" labels is for backward compatibility with + * older versions of OpenSSL. New code should use the six "DHE" labels above + * instead: + */ +# define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" +# define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" +# define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" +# define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" +# define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" +# define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" + +# define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" +# define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" +# define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" +# define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" +# define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" + +# define SSL3_SSL_SESSION_ID_LENGTH 32 +# define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 + +# define SSL3_MASTER_SECRET_SIZE 48 +# define SSL3_RANDOM_SIZE 32 +# define SSL3_SESSION_ID_SIZE 32 +# define SSL3_RT_HEADER_LENGTH 5 + +# define SSL3_HM_HEADER_LENGTH 4 + +# ifndef SSL3_ALIGN_PAYLOAD + /* + * Some will argue that this increases memory footprint, but it's not + * actually true. Point is that malloc has to return at least 64-bit aligned + * pointers, meaning that allocating 5 bytes wastes 3 bytes in either case. + * Suggested pre-gaping simply moves these wasted bytes from the end of + * allocated region to its front, but makes data payload aligned, which + * improves performance:-) + */ +# define SSL3_ALIGN_PAYLOAD 8 +# else +# if (SSL3_ALIGN_PAYLOAD&(SSL3_ALIGN_PAYLOAD-1))!=0 +# error "insane SSL3_ALIGN_PAYLOAD" +# undef SSL3_ALIGN_PAYLOAD +# endif +# endif + +/* + * This is the maximum MAC (digest) size used by the SSL library. Currently + * maximum of 20 is used by SHA1, but we reserve for future extension for + * 512-bit hashes. + */ + +# define SSL3_RT_MAX_MD_SIZE 64 + +/* + * Maximum block size used in all ciphersuites. Currently 16 for AES. + */ + +# define SSL_RT_MAX_CIPHER_BLOCK_SIZE 16 + +# define SSL3_RT_MAX_EXTRA (16384) + +/* Maximum plaintext length: defined by SSL/TLS standards */ +# define SSL3_RT_MAX_PLAIN_LENGTH 16384 +/* Maximum compression overhead: defined by SSL/TLS standards */ +# define SSL3_RT_MAX_COMPRESSED_OVERHEAD 1024 + +/* + * The standards give a maximum encryption overhead of 1024 bytes. In + * practice the value is lower than this. The overhead is the maximum number + * of padding bytes (256) plus the mac size. + */ +# define SSL3_RT_MAX_ENCRYPTED_OVERHEAD (256 + SSL3_RT_MAX_MD_SIZE) +# define SSL3_RT_MAX_TLS13_ENCRYPTED_OVERHEAD 256 + +/* + * OpenSSL currently only uses a padding length of at most one block so the + * send overhead is smaller. + */ + +# define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \ + (SSL_RT_MAX_CIPHER_BLOCK_SIZE + SSL3_RT_MAX_MD_SIZE) + +/* If compression isn't used don't include the compression overhead */ + +# ifdef OPENSSL_NO_COMP +# define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH +# else +# define SSL3_RT_MAX_COMPRESSED_LENGTH \ + (SSL3_RT_MAX_PLAIN_LENGTH+SSL3_RT_MAX_COMPRESSED_OVERHEAD) +# endif +# define SSL3_RT_MAX_ENCRYPTED_LENGTH \ + (SSL3_RT_MAX_ENCRYPTED_OVERHEAD+SSL3_RT_MAX_COMPRESSED_LENGTH) +# define SSL3_RT_MAX_TLS13_ENCRYPTED_LENGTH \ + (SSL3_RT_MAX_PLAIN_LENGTH + SSL3_RT_MAX_TLS13_ENCRYPTED_OVERHEAD) +# define SSL3_RT_MAX_PACKET_SIZE \ + (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) + +# define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54" +# define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52" + +# define SSL3_VERSION 0x0300 +# define SSL3_VERSION_MAJOR 0x03 +# define SSL3_VERSION_MINOR 0x00 + +# define SSL3_RT_CHANGE_CIPHER_SPEC 20 +# define SSL3_RT_ALERT 21 +# define SSL3_RT_HANDSHAKE 22 +# define SSL3_RT_APPLICATION_DATA 23 +# define DTLS1_RT_HEARTBEAT 24 + +/* Pseudo content types to indicate additional parameters */ +# define TLS1_RT_CRYPTO 0x1000 +# define TLS1_RT_CRYPTO_PREMASTER (TLS1_RT_CRYPTO | 0x1) +# define TLS1_RT_CRYPTO_CLIENT_RANDOM (TLS1_RT_CRYPTO | 0x2) +# define TLS1_RT_CRYPTO_SERVER_RANDOM (TLS1_RT_CRYPTO | 0x3) +# define TLS1_RT_CRYPTO_MASTER (TLS1_RT_CRYPTO | 0x4) + +# define TLS1_RT_CRYPTO_READ 0x0000 +# define TLS1_RT_CRYPTO_WRITE 0x0100 +# define TLS1_RT_CRYPTO_MAC (TLS1_RT_CRYPTO | 0x5) +# define TLS1_RT_CRYPTO_KEY (TLS1_RT_CRYPTO | 0x6) +# define TLS1_RT_CRYPTO_IV (TLS1_RT_CRYPTO | 0x7) +# define TLS1_RT_CRYPTO_FIXED_IV (TLS1_RT_CRYPTO | 0x8) + +/* Pseudo content types for SSL/TLS header info */ +# define SSL3_RT_HEADER 0x100 +# define SSL3_RT_INNER_CONTENT_TYPE 0x101 + +# define SSL3_AL_WARNING 1 +# define SSL3_AL_FATAL 2 + +# define SSL3_AD_CLOSE_NOTIFY 0 +# define SSL3_AD_UNEXPECTED_MESSAGE 10/* fatal */ +# define SSL3_AD_BAD_RECORD_MAC 20/* fatal */ +# define SSL3_AD_DECOMPRESSION_FAILURE 30/* fatal */ +# define SSL3_AD_HANDSHAKE_FAILURE 40/* fatal */ +# define SSL3_AD_NO_CERTIFICATE 41 +# define SSL3_AD_BAD_CERTIFICATE 42 +# define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 +# define SSL3_AD_CERTIFICATE_REVOKED 44 +# define SSL3_AD_CERTIFICATE_EXPIRED 45 +# define SSL3_AD_CERTIFICATE_UNKNOWN 46 +# define SSL3_AD_ILLEGAL_PARAMETER 47/* fatal */ + +# define TLS1_HB_REQUEST 1 +# define TLS1_HB_RESPONSE 2 + + +# define SSL3_CT_RSA_SIGN 1 +# define SSL3_CT_DSS_SIGN 2 +# define SSL3_CT_RSA_FIXED_DH 3 +# define SSL3_CT_DSS_FIXED_DH 4 +# define SSL3_CT_RSA_EPHEMERAL_DH 5 +# define SSL3_CT_DSS_EPHEMERAL_DH 6 +# define SSL3_CT_FORTEZZA_DMS 20 +/* + * SSL3_CT_NUMBER is used to size arrays and it must be large enough to + * contain all of the cert types defined for *either* SSLv3 and TLSv1. + */ +# define SSL3_CT_NUMBER 10 + +# if defined(TLS_CT_NUMBER) +# if TLS_CT_NUMBER != SSL3_CT_NUMBER +# error "SSL/TLS CT_NUMBER values do not match" +# endif +# endif + +/* No longer used as of OpenSSL 1.1.1 */ +# define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 + +/* Removed from OpenSSL 1.1.0 */ +# define TLS1_FLAGS_TLS_PADDING_BUG 0x0 + +# define TLS1_FLAGS_SKIP_CERT_VERIFY 0x0010 + +/* Set if we encrypt then mac instead of usual mac then encrypt */ +# define TLS1_FLAGS_ENCRYPT_THEN_MAC_READ 0x0100 +# define TLS1_FLAGS_ENCRYPT_THEN_MAC TLS1_FLAGS_ENCRYPT_THEN_MAC_READ + +/* Set if extended master secret extension received from peer */ +# define TLS1_FLAGS_RECEIVED_EXTMS 0x0200 + +# define TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE 0x0400 + +# define TLS1_FLAGS_STATELESS 0x0800 + +# define SSL3_MT_HELLO_REQUEST 0 +# define SSL3_MT_CLIENT_HELLO 1 +# define SSL3_MT_SERVER_HELLO 2 +# define SSL3_MT_NEWSESSION_TICKET 4 +# define SSL3_MT_END_OF_EARLY_DATA 5 +# define SSL3_MT_ENCRYPTED_EXTENSIONS 8 +# define SSL3_MT_CERTIFICATE 11 +# define SSL3_MT_SERVER_KEY_EXCHANGE 12 +# define SSL3_MT_CERTIFICATE_REQUEST 13 +# define SSL3_MT_SERVER_DONE 14 +# define SSL3_MT_CERTIFICATE_VERIFY 15 +# define SSL3_MT_CLIENT_KEY_EXCHANGE 16 +# define SSL3_MT_FINISHED 20 +# define SSL3_MT_CERTIFICATE_URL 21 +# define SSL3_MT_CERTIFICATE_STATUS 22 +# define SSL3_MT_SUPPLEMENTAL_DATA 23 +# define SSL3_MT_KEY_UPDATE 24 +# ifndef OPENSSL_NO_NEXTPROTONEG +# define SSL3_MT_NEXT_PROTO 67 +# endif +# define SSL3_MT_MESSAGE_HASH 254 +# define DTLS1_MT_HELLO_VERIFY_REQUEST 3 + +/* Dummy message type for handling CCS like a normal handshake message */ +# define SSL3_MT_CHANGE_CIPHER_SPEC 0x0101 + +# define SSL3_MT_CCS 1 + +/* These are used when changing over to a new cipher */ +# define SSL3_CC_READ 0x001 +# define SSL3_CC_WRITE 0x002 +# define SSL3_CC_CLIENT 0x010 +# define SSL3_CC_SERVER 0x020 +# define SSL3_CC_EARLY 0x040 +# define SSL3_CC_HANDSHAKE 0x080 +# define SSL3_CC_APPLICATION 0x100 +# define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) +# define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) +# define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) +# define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/sslerr.h postgresql-hll-2.14/include/openssl/sslerr.h --- postgresql-hll-2.14_old/include/openssl/sslerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/sslerr.h 2020-12-12 17:06:43.340349238 +0800 @@ -0,0 +1,773 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SSLERR_H +# define HEADER_SSLERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_SSL_strings(void); + +/* + * SSL function codes. + */ +# define SSL_F_ADD_CLIENT_KEY_SHARE_EXT 438 +# define SSL_F_ADD_KEY_SHARE 512 +# define SSL_F_BYTES_TO_CIPHER_LIST 519 +# define SSL_F_CHECK_SUITEB_CIPHER_LIST 331 +# define SSL_F_CIPHERSUITE_CB 622 +# define SSL_F_CONSTRUCT_CA_NAMES 552 +# define SSL_F_CONSTRUCT_KEY_EXCHANGE_TBS 553 +# define SSL_F_CONSTRUCT_STATEFUL_TICKET 636 +# define SSL_F_CONSTRUCT_STATELESS_TICKET 637 +# define SSL_F_CREATE_SYNTHETIC_MESSAGE_HASH 539 +# define SSL_F_CREATE_TICKET_PREQUEL 638 +# define SSL_F_CT_MOVE_SCTS 345 +# define SSL_F_CT_STRICT 349 +# define SSL_F_CUSTOM_EXT_ADD 554 +# define SSL_F_CUSTOM_EXT_PARSE 555 +# define SSL_F_D2I_SSL_SESSION 103 +# define SSL_F_DANE_CTX_ENABLE 347 +# define SSL_F_DANE_MTYPE_SET 393 +# define SSL_F_DANE_TLSA_ADD 394 +# define SSL_F_DERIVE_SECRET_KEY_AND_IV 514 +# define SSL_F_DO_DTLS1_WRITE 245 +# define SSL_F_DO_SSL3_WRITE 104 +# define SSL_F_DTLS1_BUFFER_RECORD 247 +# define SSL_F_DTLS1_CHECK_TIMEOUT_NUM 318 +# define SSL_F_DTLS1_HEARTBEAT 305 +# define SSL_F_DTLS1_HM_FRAGMENT_NEW 623 +# define SSL_F_DTLS1_PREPROCESS_FRAGMENT 288 +# define SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS 424 +# define SSL_F_DTLS1_PROCESS_RECORD 257 +# define SSL_F_DTLS1_READ_BYTES 258 +# define SSL_F_DTLS1_READ_FAILED 339 +# define SSL_F_DTLS1_RETRANSMIT_MESSAGE 390 +# define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268 +# define SSL_F_DTLS1_WRITE_BYTES 545 +# define SSL_F_DTLSV1_LISTEN 350 +# define SSL_F_DTLS_CONSTRUCT_CHANGE_CIPHER_SPEC 371 +# define SSL_F_DTLS_CONSTRUCT_HELLO_VERIFY_REQUEST 385 +# define SSL_F_DTLS_GET_REASSEMBLED_MESSAGE 370 +# define SSL_F_DTLS_PROCESS_HELLO_VERIFY 386 +# define SSL_F_DTLS_RECORD_LAYER_NEW 635 +# define SSL_F_DTLS_WAIT_FOR_DRY 592 +# define SSL_F_EARLY_DATA_COUNT_OK 532 +# define SSL_F_FINAL_EARLY_DATA 556 +# define SSL_F_FINAL_EC_PT_FORMATS 485 +# define SSL_F_FINAL_EMS 486 +# define SSL_F_FINAL_KEY_SHARE 503 +# define SSL_F_FINAL_MAXFRAGMENTLEN 557 +# define SSL_F_FINAL_RENEGOTIATE 483 +# define SSL_F_FINAL_SERVER_NAME 558 +# define SSL_F_FINAL_SIG_ALGS 497 +# define SSL_F_GET_CERT_VERIFY_TBS_DATA 588 +# define SSL_F_NSS_KEYLOG_INT 500 +# define SSL_F_OPENSSL_INIT_SSL 342 +# define SSL_F_OSSL_STATEM_CLIENT13_READ_TRANSITION 436 +# define SSL_F_OSSL_STATEM_CLIENT13_WRITE_TRANSITION 598 +# define SSL_F_OSSL_STATEM_CLIENT_CONSTRUCT_MESSAGE 430 +# define SSL_F_OSSL_STATEM_CLIENT_POST_PROCESS_MESSAGE 593 +# define SSL_F_OSSL_STATEM_CLIENT_PROCESS_MESSAGE 594 +# define SSL_F_OSSL_STATEM_CLIENT_READ_TRANSITION 417 +# define SSL_F_OSSL_STATEM_CLIENT_WRITE_TRANSITION 599 +# define SSL_F_OSSL_STATEM_SERVER13_READ_TRANSITION 437 +# define SSL_F_OSSL_STATEM_SERVER13_WRITE_TRANSITION 600 +# define SSL_F_OSSL_STATEM_SERVER_CONSTRUCT_MESSAGE 431 +# define SSL_F_OSSL_STATEM_SERVER_POST_PROCESS_MESSAGE 601 +# define SSL_F_OSSL_STATEM_SERVER_POST_WORK 602 +# define SSL_F_OSSL_STATEM_SERVER_PRE_WORK 640 +# define SSL_F_OSSL_STATEM_SERVER_PROCESS_MESSAGE 603 +# define SSL_F_OSSL_STATEM_SERVER_READ_TRANSITION 418 +# define SSL_F_OSSL_STATEM_SERVER_WRITE_TRANSITION 604 +# define SSL_F_PARSE_CA_NAMES 541 +# define SSL_F_PITEM_NEW 624 +# define SSL_F_PQUEUE_NEW 625 +# define SSL_F_PROCESS_KEY_SHARE_EXT 439 +# define SSL_F_READ_STATE_MACHINE 352 +# define SSL_F_SET_CLIENT_CIPHERSUITE 540 +# define SSL_F_SRP_GENERATE_CLIENT_MASTER_SECRET 595 +# define SSL_F_SRP_GENERATE_SERVER_MASTER_SECRET 589 +# define SSL_F_SRP_VERIFY_SERVER_PARAM 596 +# define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 +# define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 +# define SSL_F_SSL3_CTRL 213 +# define SSL_F_SSL3_CTX_CTRL 133 +# define SSL_F_SSL3_DIGEST_CACHED_RECORDS 293 +# define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC 292 +# define SSL_F_SSL3_ENC 608 +# define SSL_F_SSL3_FINAL_FINISH_MAC 285 +# define SSL_F_SSL3_FINISH_MAC 587 +# define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 +# define SSL_F_SSL3_GENERATE_MASTER_SECRET 388 +# define SSL_F_SSL3_GET_RECORD 143 +# define SSL_F_SSL3_INIT_FINISHED_MAC 397 +# define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 +# define SSL_F_SSL3_READ_BYTES 148 +# define SSL_F_SSL3_READ_N 149 +# define SSL_F_SSL3_SETUP_KEY_BLOCK 157 +# define SSL_F_SSL3_SETUP_READ_BUFFER 156 +# define SSL_F_SSL3_SETUP_WRITE_BUFFER 291 +# define SSL_F_SSL3_WRITE_BYTES 158 +# define SSL_F_SSL3_WRITE_PENDING 159 +# define SSL_F_SSL_ADD_CERT_CHAIN 316 +# define SSL_F_SSL_ADD_CERT_TO_BUF 319 +# define SSL_F_SSL_ADD_CERT_TO_WPACKET 493 +# define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT 298 +# define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 277 +# define SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT 307 +# define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 +# define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 +# define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT 299 +# define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 278 +# define SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT 308 +# define SSL_F_SSL_BAD_METHOD 160 +# define SSL_F_SSL_BUILD_CERT_CHAIN 332 +# define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 +# define SSL_F_SSL_CACHE_CIPHERLIST 520 +# define SSL_F_SSL_CERT_ADD0_CHAIN_CERT 346 +# define SSL_F_SSL_CERT_DUP 221 +# define SSL_F_SSL_CERT_NEW 162 +# define SSL_F_SSL_CERT_SET0_CHAIN 340 +# define SSL_F_SSL_CHECK_PRIVATE_KEY 163 +# define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 280 +# define SSL_F_SSL_CHECK_SRP_EXT_CLIENTHELLO 606 +# define SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG 279 +# define SSL_F_SSL_CHOOSE_CLIENT_VERSION 607 +# define SSL_F_SSL_CIPHER_DESCRIPTION 626 +# define SSL_F_SSL_CIPHER_LIST_TO_BYTES 425 +# define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 +# define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 +# define SSL_F_SSL_CLEAR 164 +# define SSL_F_SSL_CLIENT_HELLO_GET1_EXTENSIONS_PRESENT 627 +# define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165 +# define SSL_F_SSL_CONF_CMD 334 +# define SSL_F_SSL_CREATE_CIPHER_LIST 166 +# define SSL_F_SSL_CTRL 232 +# define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168 +# define SSL_F_SSL_CTX_ENABLE_CT 398 +# define SSL_F_SSL_CTX_MAKE_PROFILES 309 +# define SSL_F_SSL_CTX_NEW 169 +# define SSL_F_SSL_CTX_SET_ALPN_PROTOS 343 +# define SSL_F_SSL_CTX_SET_CIPHER_LIST 269 +# define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE 290 +# define SSL_F_SSL_CTX_SET_CT_VALIDATION_CALLBACK 396 +# define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219 +# define SSL_F_SSL_CTX_SET_SSL_VERSION 170 +# define SSL_F_SSL_CTX_SET_TLSEXT_MAX_FRAGMENT_LENGTH 551 +# define SSL_F_SSL_CTX_USE_CERTIFICATE 171 +# define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172 +# define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY 174 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175 +# define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176 +# define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT 272 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178 +# define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179 +# define SSL_F_SSL_CTX_USE_SERVERINFO 336 +# define SSL_F_SSL_CTX_USE_SERVERINFO_EX 543 +# define SSL_F_SSL_CTX_USE_SERVERINFO_FILE 337 +# define SSL_F_SSL_DANE_DUP 403 +# define SSL_F_SSL_DANE_ENABLE 395 +# define SSL_F_SSL_DERIVE 590 +# define SSL_F_SSL_DO_CONFIG 391 +# define SSL_F_SSL_DO_HANDSHAKE 180 +# define SSL_F_SSL_DUP_CA_LIST 408 +# define SSL_F_SSL_ENABLE_CT 402 +# define SSL_F_SSL_GENERATE_PKEY_GROUP 559 +# define SSL_F_SSL_GENERATE_SESSION_ID 547 +# define SSL_F_SSL_GET_NEW_SESSION 181 +# define SSL_F_SSL_GET_PREV_SESSION 217 +# define SSL_F_SSL_GET_SERVER_CERT_INDEX 322 +# define SSL_F_SSL_GET_SIGN_PKEY 183 +# define SSL_F_SSL_HANDSHAKE_HASH 560 +# define SSL_F_SSL_INIT_WBIO_BUFFER 184 +# define SSL_F_SSL_KEY_UPDATE 515 +# define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 +# define SSL_F_SSL_LOG_MASTER_SECRET 498 +# define SSL_F_SSL_LOG_RSA_CLIENT_KEY_EXCHANGE 499 +# define SSL_F_SSL_MODULE_INIT 392 +# define SSL_F_SSL_NEW 186 +# define SSL_F_SSL_NEXT_PROTO_VALIDATE 565 +# define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT 300 +# define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT 302 +# define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT 310 +# define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT 301 +# define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT 303 +# define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT 311 +# define SSL_F_SSL_PEEK 270 +# define SSL_F_SSL_PEEK_EX 432 +# define SSL_F_SSL_PEEK_INTERNAL 522 +# define SSL_F_SSL_READ 223 +# define SSL_F_SSL_READ_EARLY_DATA 529 +# define SSL_F_SSL_READ_EX 434 +# define SSL_F_SSL_READ_INTERNAL 523 +# define SSL_F_SSL_RENEGOTIATE 516 +# define SSL_F_SSL_RENEGOTIATE_ABBREVIATED 546 +# define SSL_F_SSL_SCAN_CLIENTHELLO_TLSEXT 320 +# define SSL_F_SSL_SCAN_SERVERHELLO_TLSEXT 321 +# define SSL_F_SSL_SESSION_DUP 348 +# define SSL_F_SSL_SESSION_NEW 189 +# define SSL_F_SSL_SESSION_PRINT_FP 190 +# define SSL_F_SSL_SESSION_SET1_ID 423 +# define SSL_F_SSL_SESSION_SET1_ID_CONTEXT 312 +# define SSL_F_SSL_SET_ALPN_PROTOS 344 +# define SSL_F_SSL_SET_CERT 191 +# define SSL_F_SSL_SET_CERT_AND_KEY 621 +# define SSL_F_SSL_SET_CIPHER_LIST 271 +# define SSL_F_SSL_SET_CT_VALIDATION_CALLBACK 399 +# define SSL_F_SSL_SET_FD 192 +# define SSL_F_SSL_SET_PKEY 193 +# define SSL_F_SSL_SET_RFD 194 +# define SSL_F_SSL_SET_SESSION 195 +# define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218 +# define SSL_F_SSL_SET_SESSION_TICKET_EXT 294 +# define SSL_F_SSL_SET_TLSEXT_MAX_FRAGMENT_LENGTH 550 +# define SSL_F_SSL_SET_WFD 196 +# define SSL_F_SSL_SHUTDOWN 224 +# define SSL_F_SSL_SRP_CTX_INIT 313 +# define SSL_F_SSL_START_ASYNC_JOB 389 +# define SSL_F_SSL_UNDEFINED_FUNCTION 197 +# define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244 +# define SSL_F_SSL_USE_CERTIFICATE 198 +# define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 +# define SSL_F_SSL_USE_CERTIFICATE_FILE 200 +# define SSL_F_SSL_USE_PRIVATEKEY 201 +# define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202 +# define SSL_F_SSL_USE_PRIVATEKEY_FILE 203 +# define SSL_F_SSL_USE_PSK_IDENTITY_HINT 273 +# define SSL_F_SSL_USE_RSAPRIVATEKEY 204 +# define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205 +# define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206 +# define SSL_F_SSL_VALIDATE_CT 400 +# define SSL_F_SSL_VERIFY_CERT_CHAIN 207 +# define SSL_F_SSL_VERIFY_CLIENT_POST_HANDSHAKE 616 +# define SSL_F_SSL_WRITE 208 +# define SSL_F_SSL_WRITE_EARLY_DATA 526 +# define SSL_F_SSL_WRITE_EARLY_FINISH 527 +# define SSL_F_SSL_WRITE_EX 433 +# define SSL_F_SSL_WRITE_INTERNAL 524 +# define SSL_F_STATE_MACHINE 353 +# define SSL_F_TLS12_CHECK_PEER_SIGALG 333 +# define SSL_F_TLS12_COPY_SIGALGS 533 +# define SSL_F_TLS13_CHANGE_CIPHER_STATE 440 +# define SSL_F_TLS13_ENC 609 +# define SSL_F_TLS13_FINAL_FINISH_MAC 605 +# define SSL_F_TLS13_GENERATE_SECRET 591 +# define SSL_F_TLS13_HKDF_EXPAND 561 +# define SSL_F_TLS13_RESTORE_HANDSHAKE_DIGEST_FOR_PHA 617 +# define SSL_F_TLS13_SAVE_HANDSHAKE_DIGEST_FOR_PHA 618 +# define SSL_F_TLS13_SETUP_KEY_BLOCK 441 +# define SSL_F_TLS1_CHANGE_CIPHER_STATE 209 +# define SSL_F_TLS1_CHECK_DUPLICATE_EXTENSIONS 341 +# define SSL_F_TLS1_ENC 401 +# define SSL_F_TLS1_EXPORT_KEYING_MATERIAL 314 +# define SSL_F_TLS1_GET_CURVELIST 338 +# define SSL_F_TLS1_PRF 284 +# define SSL_F_TLS1_SAVE_U16 628 +# define SSL_F_TLS1_SETUP_KEY_BLOCK 211 +# define SSL_F_TLS1_SET_GROUPS 629 +# define SSL_F_TLS1_SET_RAW_SIGALGS 630 +# define SSL_F_TLS1_SET_SERVER_SIGALGS 335 +# define SSL_F_TLS1_SET_SHARED_SIGALGS 631 +# define SSL_F_TLS1_SET_SIGALGS 632 +# define SSL_F_TLS_CHOOSE_SIGALG 513 +# define SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK 354 +# define SSL_F_TLS_COLLECT_EXTENSIONS 435 +# define SSL_F_TLS_CONSTRUCT_CERTIFICATE_AUTHORITIES 542 +# define SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST 372 +# define SSL_F_TLS_CONSTRUCT_CERT_STATUS 429 +# define SSL_F_TLS_CONSTRUCT_CERT_STATUS_BODY 494 +# define SSL_F_TLS_CONSTRUCT_CERT_VERIFY 496 +# define SSL_F_TLS_CONSTRUCT_CHANGE_CIPHER_SPEC 427 +# define SSL_F_TLS_CONSTRUCT_CKE_DHE 404 +# define SSL_F_TLS_CONSTRUCT_CKE_ECDHE 405 +# define SSL_F_TLS_CONSTRUCT_CKE_GOST 406 +# define SSL_F_TLS_CONSTRUCT_CKE_PSK_PREAMBLE 407 +# define SSL_F_TLS_CONSTRUCT_CKE_RSA 409 +# define SSL_F_TLS_CONSTRUCT_CKE_SRP 410 +# define SSL_F_TLS_CONSTRUCT_CLIENT_CERTIFICATE 484 +# define SSL_F_TLS_CONSTRUCT_CLIENT_HELLO 487 +# define SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE 488 +# define SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY 489 +# define SSL_F_TLS_CONSTRUCT_CTOS_ALPN 466 +# define SSL_F_TLS_CONSTRUCT_CTOS_CERTIFICATE 355 +# define SSL_F_TLS_CONSTRUCT_CTOS_COOKIE 535 +# define SSL_F_TLS_CONSTRUCT_CTOS_EARLY_DATA 530 +# define SSL_F_TLS_CONSTRUCT_CTOS_EC_PT_FORMATS 467 +# define SSL_F_TLS_CONSTRUCT_CTOS_EMS 468 +# define SSL_F_TLS_CONSTRUCT_CTOS_ETM 469 +# define SSL_F_TLS_CONSTRUCT_CTOS_HELLO 356 +# define SSL_F_TLS_CONSTRUCT_CTOS_KEY_EXCHANGE 357 +# define SSL_F_TLS_CONSTRUCT_CTOS_KEY_SHARE 470 +# define SSL_F_TLS_CONSTRUCT_CTOS_MAXFRAGMENTLEN 549 +# define SSL_F_TLS_CONSTRUCT_CTOS_NPN 471 +# define SSL_F_TLS_CONSTRUCT_CTOS_PADDING 472 +# define SSL_F_TLS_CONSTRUCT_CTOS_POST_HANDSHAKE_AUTH 619 +# define SSL_F_TLS_CONSTRUCT_CTOS_PSK 501 +# define SSL_F_TLS_CONSTRUCT_CTOS_PSK_KEX_MODES 509 +# define SSL_F_TLS_CONSTRUCT_CTOS_RENEGOTIATE 473 +# define SSL_F_TLS_CONSTRUCT_CTOS_SCT 474 +# define SSL_F_TLS_CONSTRUCT_CTOS_SERVER_NAME 475 +# define SSL_F_TLS_CONSTRUCT_CTOS_SESSION_TICKET 476 +# define SSL_F_TLS_CONSTRUCT_CTOS_SIG_ALGS 477 +# define SSL_F_TLS_CONSTRUCT_CTOS_SRP 478 +# define SSL_F_TLS_CONSTRUCT_CTOS_STATUS_REQUEST 479 +# define SSL_F_TLS_CONSTRUCT_CTOS_SUPPORTED_GROUPS 480 +# define SSL_F_TLS_CONSTRUCT_CTOS_SUPPORTED_VERSIONS 481 +# define SSL_F_TLS_CONSTRUCT_CTOS_USE_SRTP 482 +# define SSL_F_TLS_CONSTRUCT_CTOS_VERIFY 358 +# define SSL_F_TLS_CONSTRUCT_ENCRYPTED_EXTENSIONS 443 +# define SSL_F_TLS_CONSTRUCT_END_OF_EARLY_DATA 536 +# define SSL_F_TLS_CONSTRUCT_EXTENSIONS 447 +# define SSL_F_TLS_CONSTRUCT_FINISHED 359 +# define SSL_F_TLS_CONSTRUCT_HELLO_REQUEST 373 +# define SSL_F_TLS_CONSTRUCT_HELLO_RETRY_REQUEST 510 +# define SSL_F_TLS_CONSTRUCT_KEY_UPDATE 517 +# define SSL_F_TLS_CONSTRUCT_NEW_SESSION_TICKET 428 +# define SSL_F_TLS_CONSTRUCT_NEXT_PROTO 426 +# define SSL_F_TLS_CONSTRUCT_SERVER_CERTIFICATE 490 +# define SSL_F_TLS_CONSTRUCT_SERVER_HELLO 491 +# define SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE 492 +# define SSL_F_TLS_CONSTRUCT_STOC_ALPN 451 +# define SSL_F_TLS_CONSTRUCT_STOC_CERTIFICATE 374 +# define SSL_F_TLS_CONSTRUCT_STOC_COOKIE 613 +# define SSL_F_TLS_CONSTRUCT_STOC_CRYPTOPRO_BUG 452 +# define SSL_F_TLS_CONSTRUCT_STOC_DONE 375 +# define SSL_F_TLS_CONSTRUCT_STOC_EARLY_DATA 531 +# define SSL_F_TLS_CONSTRUCT_STOC_EARLY_DATA_INFO 525 +# define SSL_F_TLS_CONSTRUCT_STOC_EC_PT_FORMATS 453 +# define SSL_F_TLS_CONSTRUCT_STOC_EMS 454 +# define SSL_F_TLS_CONSTRUCT_STOC_ETM 455 +# define SSL_F_TLS_CONSTRUCT_STOC_HELLO 376 +# define SSL_F_TLS_CONSTRUCT_STOC_KEY_EXCHANGE 377 +# define SSL_F_TLS_CONSTRUCT_STOC_KEY_SHARE 456 +# define SSL_F_TLS_CONSTRUCT_STOC_MAXFRAGMENTLEN 548 +# define SSL_F_TLS_CONSTRUCT_STOC_NEXT_PROTO_NEG 457 +# define SSL_F_TLS_CONSTRUCT_STOC_PSK 504 +# define SSL_F_TLS_CONSTRUCT_STOC_RENEGOTIATE 458 +# define SSL_F_TLS_CONSTRUCT_STOC_SERVER_NAME 459 +# define SSL_F_TLS_CONSTRUCT_STOC_SESSION_TICKET 460 +# define SSL_F_TLS_CONSTRUCT_STOC_STATUS_REQUEST 461 +# define SSL_F_TLS_CONSTRUCT_STOC_SUPPORTED_GROUPS 544 +# define SSL_F_TLS_CONSTRUCT_STOC_SUPPORTED_VERSIONS 611 +# define SSL_F_TLS_CONSTRUCT_STOC_USE_SRTP 462 +# define SSL_F_TLS_EARLY_POST_PROCESS_CLIENT_HELLO 521 +# define SSL_F_TLS_FINISH_HANDSHAKE 597 +# define SSL_F_TLS_GET_MESSAGE_BODY 351 +# define SSL_F_TLS_GET_MESSAGE_HEADER 387 +# define SSL_F_TLS_HANDLE_ALPN 562 +# define SSL_F_TLS_HANDLE_STATUS_REQUEST 563 +# define SSL_F_TLS_PARSE_CERTIFICATE_AUTHORITIES 566 +# define SSL_F_TLS_PARSE_CLIENTHELLO_TLSEXT 449 +# define SSL_F_TLS_PARSE_CTOS_ALPN 567 +# define SSL_F_TLS_PARSE_CTOS_COOKIE 614 +# define SSL_F_TLS_PARSE_CTOS_EARLY_DATA 568 +# define SSL_F_TLS_PARSE_CTOS_EC_PT_FORMATS 569 +# define SSL_F_TLS_PARSE_CTOS_EMS 570 +# define SSL_F_TLS_PARSE_CTOS_KEY_SHARE 463 +# define SSL_F_TLS_PARSE_CTOS_MAXFRAGMENTLEN 571 +# define SSL_F_TLS_PARSE_CTOS_POST_HANDSHAKE_AUTH 620 +# define SSL_F_TLS_PARSE_CTOS_PSK 505 +# define SSL_F_TLS_PARSE_CTOS_PSK_KEX_MODES 572 +# define SSL_F_TLS_PARSE_CTOS_RENEGOTIATE 464 +# define SSL_F_TLS_PARSE_CTOS_SERVER_NAME 573 +# define SSL_F_TLS_PARSE_CTOS_SESSION_TICKET 574 +# define SSL_F_TLS_PARSE_CTOS_SIG_ALGS 575 +# define SSL_F_TLS_PARSE_CTOS_SIG_ALGS_CERT 615 +# define SSL_F_TLS_PARSE_CTOS_SRP 576 +# define SSL_F_TLS_PARSE_CTOS_STATUS_REQUEST 577 +# define SSL_F_TLS_PARSE_CTOS_SUPPORTED_GROUPS 578 +# define SSL_F_TLS_PARSE_CTOS_USE_SRTP 465 +# define SSL_F_TLS_PARSE_STOC_ALPN 579 +# define SSL_F_TLS_PARSE_STOC_COOKIE 534 +# define SSL_F_TLS_PARSE_STOC_EARLY_DATA 538 +# define SSL_F_TLS_PARSE_STOC_EARLY_DATA_INFO 528 +# define SSL_F_TLS_PARSE_STOC_EC_PT_FORMATS 580 +# define SSL_F_TLS_PARSE_STOC_KEY_SHARE 445 +# define SSL_F_TLS_PARSE_STOC_MAXFRAGMENTLEN 581 +# define SSL_F_TLS_PARSE_STOC_NPN 582 +# define SSL_F_TLS_PARSE_STOC_PSK 502 +# define SSL_F_TLS_PARSE_STOC_RENEGOTIATE 448 +# define SSL_F_TLS_PARSE_STOC_SCT 564 +# define SSL_F_TLS_PARSE_STOC_SERVER_NAME 583 +# define SSL_F_TLS_PARSE_STOC_SESSION_TICKET 584 +# define SSL_F_TLS_PARSE_STOC_STATUS_REQUEST 585 +# define SSL_F_TLS_PARSE_STOC_SUPPORTED_VERSIONS 612 +# define SSL_F_TLS_PARSE_STOC_USE_SRTP 446 +# define SSL_F_TLS_POST_PROCESS_CLIENT_HELLO 378 +# define SSL_F_TLS_POST_PROCESS_CLIENT_KEY_EXCHANGE 384 +# define SSL_F_TLS_PREPARE_CLIENT_CERTIFICATE 360 +# define SSL_F_TLS_PROCESS_AS_HELLO_RETRY_REQUEST 610 +# define SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST 361 +# define SSL_F_TLS_PROCESS_CERT_STATUS 362 +# define SSL_F_TLS_PROCESS_CERT_STATUS_BODY 495 +# define SSL_F_TLS_PROCESS_CERT_VERIFY 379 +# define SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC 363 +# define SSL_F_TLS_PROCESS_CKE_DHE 411 +# define SSL_F_TLS_PROCESS_CKE_ECDHE 412 +# define SSL_F_TLS_PROCESS_CKE_GOST 413 +# define SSL_F_TLS_PROCESS_CKE_PSK_PREAMBLE 414 +# define SSL_F_TLS_PROCESS_CKE_RSA 415 +# define SSL_F_TLS_PROCESS_CKE_SRP 416 +# define SSL_F_TLS_PROCESS_CLIENT_CERTIFICATE 380 +# define SSL_F_TLS_PROCESS_CLIENT_HELLO 381 +# define SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE 382 +# define SSL_F_TLS_PROCESS_ENCRYPTED_EXTENSIONS 444 +# define SSL_F_TLS_PROCESS_END_OF_EARLY_DATA 537 +# define SSL_F_TLS_PROCESS_FINISHED 364 +# define SSL_F_TLS_PROCESS_HELLO_REQ 507 +# define SSL_F_TLS_PROCESS_HELLO_RETRY_REQUEST 511 +# define SSL_F_TLS_PROCESS_INITIAL_SERVER_FLIGHT 442 +# define SSL_F_TLS_PROCESS_KEY_EXCHANGE 365 +# define SSL_F_TLS_PROCESS_KEY_UPDATE 518 +# define SSL_F_TLS_PROCESS_NEW_SESSION_TICKET 366 +# define SSL_F_TLS_PROCESS_NEXT_PROTO 383 +# define SSL_F_TLS_PROCESS_SERVER_CERTIFICATE 367 +# define SSL_F_TLS_PROCESS_SERVER_DONE 368 +# define SSL_F_TLS_PROCESS_SERVER_HELLO 369 +# define SSL_F_TLS_PROCESS_SKE_DHE 419 +# define SSL_F_TLS_PROCESS_SKE_ECDHE 420 +# define SSL_F_TLS_PROCESS_SKE_PSK_PREAMBLE 421 +# define SSL_F_TLS_PROCESS_SKE_SRP 422 +# define SSL_F_TLS_PSK_DO_BINDER 506 +# define SSL_F_TLS_SCAN_CLIENTHELLO_TLSEXT 450 +# define SSL_F_TLS_SETUP_HANDSHAKE 508 +# define SSL_F_USE_CERTIFICATE_CHAIN_FILE 220 +# define SSL_F_WPACKET_INTERN_INIT_LEN 633 +# define SSL_F_WPACKET_START_SUB_PACKET_LEN__ 634 +# define SSL_F_WRITE_STATE_MACHINE 586 + +/* + * SSL reason codes. + */ +# define SSL_R_APPLICATION_DATA_AFTER_CLOSE_NOTIFY 291 +# define SSL_R_APP_DATA_IN_HANDSHAKE 100 +# define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272 +# define SSL_R_AT_LEAST_TLS_1_0_NEEDED_IN_FIPS_MODE 143 +# define SSL_R_AT_LEAST_TLS_1_2_NEEDED_IN_SUITEB_MODE 158 +# define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 +# define SSL_R_BAD_CIPHER 186 +# define SSL_R_BAD_DATA 390 +# define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 +# define SSL_R_BAD_DECOMPRESSION 107 +# define SSL_R_BAD_DH_VALUE 102 +# define SSL_R_BAD_DIGEST_LENGTH 111 +# define SSL_R_BAD_EARLY_DATA 233 +# define SSL_R_BAD_ECC_CERT 304 +# define SSL_R_BAD_ECPOINT 306 +# define SSL_R_BAD_EXTENSION 110 +# define SSL_R_BAD_HANDSHAKE_LENGTH 332 +# define SSL_R_BAD_HANDSHAKE_STATE 236 +# define SSL_R_BAD_HELLO_REQUEST 105 +# define SSL_R_BAD_HRR_VERSION 263 +# define SSL_R_BAD_KEY_SHARE 108 +# define SSL_R_BAD_KEY_UPDATE 122 +# define SSL_R_BAD_LEGACY_VERSION 292 +# define SSL_R_BAD_LENGTH 271 +# define SSL_R_BAD_PACKET 240 +# define SSL_R_BAD_PACKET_LENGTH 115 +# define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 +# define SSL_R_BAD_PSK 219 +# define SSL_R_BAD_PSK_IDENTITY 114 +# define SSL_R_BAD_RECORD_TYPE 443 +# define SSL_R_BAD_RSA_ENCRYPT 119 +# define SSL_R_BAD_SIGNATURE 123 +# define SSL_R_BAD_SRP_A_LENGTH 347 +# define SSL_R_BAD_SRP_PARAMETERS 371 +# define SSL_R_BAD_SRTP_MKI_VALUE 352 +# define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST 353 +# define SSL_R_BAD_SSL_FILETYPE 124 +# define SSL_R_BAD_VALUE 384 +# define SSL_R_BAD_WRITE_RETRY 127 +# define SSL_R_BINDER_DOES_NOT_VERIFY 253 +# define SSL_R_BIO_NOT_SET 128 +# define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 +# define SSL_R_BN_LIB 130 +# define SSL_R_CALLBACK_FAILED 234 +# define SSL_R_CANNOT_CHANGE_CIPHER 109 +# define SSL_R_CA_DN_LENGTH_MISMATCH 131 +# define SSL_R_CA_KEY_TOO_SMALL 397 +# define SSL_R_CA_MD_TOO_WEAK 398 +# define SSL_R_CCS_RECEIVED_EARLY 133 +# define SSL_R_CERTIFICATE_VERIFY_FAILED 134 +# define SSL_R_CERT_CB_ERROR 377 +# define SSL_R_CERT_LENGTH_MISMATCH 135 +# define SSL_R_CIPHERSUITE_DIGEST_HAS_CHANGED 218 +# define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 +# define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 +# define SSL_R_CLIENTHELLO_TLSEXT 226 +# define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 +# define SSL_R_COMPRESSION_DISABLED 343 +# define SSL_R_COMPRESSION_FAILURE 141 +# define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307 +# define SSL_R_COMPRESSION_LIBRARY_ERROR 142 +# define SSL_R_CONNECTION_TYPE_NOT_SET 144 +# define SSL_R_CONTEXT_NOT_DANE_ENABLED 167 +# define SSL_R_COOKIE_GEN_CALLBACK_FAILURE 400 +# define SSL_R_COOKIE_MISMATCH 308 +# define SSL_R_CUSTOM_EXT_HANDLER_ALREADY_INSTALLED 206 +# define SSL_R_DANE_ALREADY_ENABLED 172 +# define SSL_R_DANE_CANNOT_OVERRIDE_MTYPE_FULL 173 +# define SSL_R_DANE_NOT_ENABLED 175 +# define SSL_R_DANE_TLSA_BAD_CERTIFICATE 180 +# define SSL_R_DANE_TLSA_BAD_CERTIFICATE_USAGE 184 +# define SSL_R_DANE_TLSA_BAD_DATA_LENGTH 189 +# define SSL_R_DANE_TLSA_BAD_DIGEST_LENGTH 192 +# define SSL_R_DANE_TLSA_BAD_MATCHING_TYPE 200 +# define SSL_R_DANE_TLSA_BAD_PUBLIC_KEY 201 +# define SSL_R_DANE_TLSA_BAD_SELECTOR 202 +# define SSL_R_DANE_TLSA_NULL_DATA 203 +# define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 +# define SSL_R_DATA_LENGTH_TOO_LONG 146 +# define SSL_R_DECRYPTION_FAILED 147 +# define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 +# define SSL_R_DH_KEY_TOO_SMALL 394 +# define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 +# define SSL_R_DIGEST_CHECK_FAILED 149 +# define SSL_R_DTLS_MESSAGE_TOO_BIG 334 +# define SSL_R_DUPLICATE_COMPRESSION_ID 309 +# define SSL_R_ECC_CERT_NOT_FOR_SIGNING 318 +# define SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE 374 +# define SSL_R_EE_KEY_TOO_SMALL 399 +# define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST 354 +# define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 +# define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 +# define SSL_R_ERROR_SETTING_TLSA_BASE_DOMAIN 204 +# define SSL_R_EXCEEDS_MAX_FRAGMENT_SIZE 194 +# define SSL_R_EXCESSIVE_MESSAGE_SIZE 152 +# define SSL_R_EXTENSION_NOT_RECEIVED 279 +# define SSL_R_EXTRA_DATA_IN_MESSAGE 153 +# define SSL_R_EXT_LENGTH_MISMATCH 163 +# define SSL_R_FAILED_TO_INIT_ASYNC 405 +# define SSL_R_FRAGMENTED_CLIENT_HELLO 401 +# define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154 +# define SSL_R_HTTPS_PROXY_REQUEST 155 +# define SSL_R_HTTP_REQUEST 156 +# define SSL_R_ILLEGAL_POINT_COMPRESSION 162 +# define SSL_R_ILLEGAL_SUITEB_DIGEST 380 +# define SSL_R_INAPPROPRIATE_FALLBACK 373 +# define SSL_R_INCONSISTENT_COMPRESSION 340 +# define SSL_R_INCONSISTENT_EARLY_DATA_ALPN 222 +# define SSL_R_INCONSISTENT_EARLY_DATA_SNI 231 +# define SSL_R_INCONSISTENT_EXTMS 104 +# define SSL_R_INSUFFICIENT_SECURITY 241 +# define SSL_R_INVALID_ALERT 205 +# define SSL_R_INVALID_CCS_MESSAGE 260 +# define SSL_R_INVALID_CERTIFICATE_OR_ALG 238 +# define SSL_R_INVALID_COMMAND 280 +# define SSL_R_INVALID_COMPRESSION_ALGORITHM 341 +# define SSL_R_INVALID_CONFIG 283 +# define SSL_R_INVALID_CONFIGURATION_NAME 113 +# define SSL_R_INVALID_CONTEXT 282 +# define SSL_R_INVALID_CT_VALIDATION_TYPE 212 +# define SSL_R_INVALID_KEY_UPDATE_TYPE 120 +# define SSL_R_INVALID_MAX_EARLY_DATA 174 +# define SSL_R_INVALID_NULL_CMD_NAME 385 +# define SSL_R_INVALID_SEQUENCE_NUMBER 402 +# define SSL_R_INVALID_SERVERINFO_DATA 388 +# define SSL_R_INVALID_SESSION_ID 999 +# define SSL_R_INVALID_SRP_USERNAME 357 +# define SSL_R_INVALID_STATUS_RESPONSE 328 +# define SSL_R_INVALID_TICKET_KEYS_LENGTH 325 +# define SSL_R_LENGTH_MISMATCH 159 +# define SSL_R_LENGTH_TOO_LONG 404 +# define SSL_R_LENGTH_TOO_SHORT 160 +# define SSL_R_LIBRARY_BUG 274 +# define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 +# define SSL_R_MISSING_DSA_SIGNING_CERT 165 +# define SSL_R_MISSING_ECDSA_SIGNING_CERT 381 +# define SSL_R_MISSING_FATAL 256 +# define SSL_R_MISSING_PARAMETERS 290 +# define SSL_R_MISSING_RSA_CERTIFICATE 168 +# define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 +# define SSL_R_MISSING_RSA_SIGNING_CERT 170 +# define SSL_R_MISSING_SIGALGS_EXTENSION 112 +# define SSL_R_MISSING_SIGNING_CERT 221 +# define SSL_R_MISSING_SRP_PARAM 358 +# define SSL_R_MISSING_SUPPORTED_GROUPS_EXTENSION 209 +# define SSL_R_MISSING_TMP_DH_KEY 171 +# define SSL_R_MISSING_TMP_ECDH_KEY 311 +# define SSL_R_MIXED_HANDSHAKE_AND_NON_HANDSHAKE_DATA 293 +# define SSL_R_NOT_ON_RECORD_BOUNDARY 182 +# define SSL_R_NOT_REPLACING_CERTIFICATE 289 +# define SSL_R_NOT_SERVER 284 +# define SSL_R_NO_APPLICATION_PROTOCOL 235 +# define SSL_R_NO_CERTIFICATES_RETURNED 176 +# define SSL_R_NO_CERTIFICATE_ASSIGNED 177 +# define SSL_R_NO_CERTIFICATE_SET 179 +# define SSL_R_NO_CHANGE_FOLLOWING_HRR 214 +# define SSL_R_NO_CIPHERS_AVAILABLE 181 +# define SSL_R_NO_CIPHERS_SPECIFIED 183 +# define SSL_R_NO_CIPHER_MATCH 185 +# define SSL_R_NO_CLIENT_CERT_METHOD 331 +# define SSL_R_NO_COMPRESSION_SPECIFIED 187 +# define SSL_R_NO_COOKIE_CALLBACK_SET 287 +# define SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER 330 +# define SSL_R_NO_METHOD_SPECIFIED 188 +# define SSL_R_NO_PEM_EXTENSIONS 389 +# define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 +# define SSL_R_NO_PROTOCOLS_AVAILABLE 191 +# define SSL_R_NO_RENEGOTIATION 339 +# define SSL_R_NO_REQUIRED_DIGEST 324 +# define SSL_R_NO_SHARED_CIPHER 193 +# define SSL_R_NO_SHARED_GROUPS 410 +# define SSL_R_NO_SHARED_SIGNATURE_ALGORITHMS 376 +# define SSL_R_NO_SRTP_PROFILES 359 +# define SSL_R_NO_SUITABLE_KEY_SHARE 101 +# define SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM 118 +# define SSL_R_NO_VALID_SCTS 216 +# define SSL_R_NO_VERIFY_COOKIE_CALLBACK 403 +# define SSL_R_NULL_SSL_CTX 195 +# define SSL_R_NULL_SSL_METHOD_PASSED 196 +# define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 +# define SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED 344 +# define SSL_R_OVERFLOW_ERROR 237 +# define SSL_R_PACKET_LENGTH_TOO_LONG 198 +# define SSL_R_PARSE_TLSEXT 227 +# define SSL_R_PATH_TOO_LONG 270 +# define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 +# define SSL_R_PEM_NAME_BAD_PREFIX 391 +# define SSL_R_PEM_NAME_TOO_SHORT 392 +# define SSL_R_PIPELINE_FAILURE 406 +# define SSL_R_POST_HANDSHAKE_AUTH_ENCODING_ERR 278 +# define SSL_R_PRIVATE_KEY_MISMATCH 288 +# define SSL_R_PROTOCOL_IS_SHUTDOWN 207 +# define SSL_R_PSK_IDENTITY_NOT_FOUND 223 +# define SSL_R_PSK_NO_CLIENT_CB 224 +# define SSL_R_PSK_NO_SERVER_CB 225 +# define SSL_R_READ_BIO_NOT_SET 211 +# define SSL_R_READ_TIMEOUT_EXPIRED 312 +# define SSL_R_RECORD_LENGTH_MISMATCH 213 +# define SSL_R_RECORD_TOO_SMALL 298 +# define SSL_R_RENEGOTIATE_EXT_TOO_LONG 335 +# define SSL_R_RENEGOTIATION_ENCODING_ERR 336 +# define SSL_R_RENEGOTIATION_MISMATCH 337 +# define SSL_R_REQUEST_PENDING 285 +# define SSL_R_REQUEST_SENT 286 +# define SSL_R_REQUIRED_CIPHER_MISSING 215 +# define SSL_R_REQUIRED_COMPRESSION_ALGORITHM_MISSING 342 +# define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING 345 +# define SSL_R_SCT_VERIFICATION_FAILED 208 +# define SSL_R_SERVERHELLO_TLSEXT 275 +# define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 +# define SSL_R_SHUTDOWN_WHILE_IN_INIT 407 +# define SSL_R_SIGNATURE_ALGORITHMS_ERROR 360 +# define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 +# define SSL_R_SRP_A_CALC 361 +# define SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES 362 +# define SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG 363 +# define SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE 364 +# define SSL_R_SSL3_EXT_INVALID_MAX_FRAGMENT_LENGTH 232 +# define SSL_R_SSL3_EXT_INVALID_SERVERNAME 319 +# define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 320 +# define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 +# define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 +# define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 +# define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 +# define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 +# define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 +# define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 +# define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 +# define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 +# define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 +# define SSL_R_SSL_COMMAND_SECTION_EMPTY 117 +# define SSL_R_SSL_COMMAND_SECTION_NOT_FOUND 125 +# define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228 +# define SSL_R_SSL_HANDSHAKE_FAILURE 229 +# define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230 +# define SSL_R_SSL_NEGATIVE_LENGTH 372 +# define SSL_R_SSL_SECTION_EMPTY 126 +# define SSL_R_SSL_SECTION_NOT_FOUND 136 +# define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301 +# define SSL_R_SSL_SESSION_ID_CONFLICT 302 +# define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273 +# define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303 +# define SSL_R_SSL_SESSION_ID_TOO_LONG 408 +# define SSL_R_SSL_SESSION_VERSION_MISMATCH 210 +# define SSL_R_STILL_IN_INIT 121 +# define SSL_R_TLSV13_ALERT_CERTIFICATE_REQUIRED 1116 +# define SSL_R_TLSV13_ALERT_MISSING_EXTENSION 1109 +# define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 +# define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 +# define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 +# define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 +# define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060 +# define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086 +# define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 +# define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 +# define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 +# define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 +# define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 +# define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 +# define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 +# define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE 1114 +# define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE 1113 +# define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE 1111 +# define SSL_R_TLSV1_UNRECOGNIZED_NAME 1112 +# define SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110 +# define SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT 365 +# define SSL_R_TLS_HEARTBEAT_PENDING 366 +# define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL 367 +# define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 157 +# define SSL_R_TOO_MANY_KEY_UPDATES 132 +# define SSL_R_TOO_MANY_WARN_ALERTS 409 +# define SSL_R_TOO_MUCH_EARLY_DATA 164 +# define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314 +# define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 +# define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242 +# define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243 +# define SSL_R_UNEXPECTED_CCS_MESSAGE 262 +# define SSL_R_UNEXPECTED_END_OF_EARLY_DATA 178 +# define SSL_R_UNEXPECTED_MESSAGE 244 +# define SSL_R_UNEXPECTED_RECORD 245 +# define SSL_R_UNINITIALIZED 276 +# define SSL_R_UNKNOWN_ALERT_TYPE 246 +# define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247 +# define SSL_R_UNKNOWN_CIPHER_RETURNED 248 +# define SSL_R_UNKNOWN_CIPHER_TYPE 249 +# define SSL_R_UNKNOWN_CMD_NAME 386 +# define SSL_R_UNKNOWN_COMMAND 139 +# define SSL_R_UNKNOWN_DIGEST 368 +# define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250 +# define SSL_R_UNKNOWN_PKEY_TYPE 251 +# define SSL_R_UNKNOWN_PROTOCOL 252 +# define SSL_R_UNKNOWN_SSL_VERSION 254 +# define SSL_R_UNKNOWN_STATE 255 +# define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED 338 +# define SSL_R_UNSOLICITED_EXTENSION 217 +# define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 +# define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315 +# define SSL_R_UNSUPPORTED_PROTOCOL 258 +# define SSL_R_UNSUPPORTED_SSL_VERSION 259 +# define SSL_R_UNSUPPORTED_STATUS_TYPE 329 +# define SSL_R_USE_SRTP_NOT_NEGOTIATED 369 +# define SSL_R_VERSION_TOO_HIGH 166 +# define SSL_R_VERSION_TOO_LOW 396 +# define SSL_R_WRONG_CERTIFICATE_TYPE 383 +# define SSL_R_WRONG_CIPHER_RETURNED 261 +# define SSL_R_WRONG_CURVE 378 +# define SSL_R_WRONG_SIGNATURE_LENGTH 264 +# define SSL_R_WRONG_SIGNATURE_SIZE 265 +# define SSL_R_WRONG_SIGNATURE_TYPE 370 +# define SSL_R_WRONG_SSL_VERSION 266 +# define SSL_R_WRONG_VERSION_NUMBER 267 +# define SSL_R_X509_LIB 268 +# define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ssl.h postgresql-hll-2.14/include/openssl/ssl.h --- postgresql-hll-2.14_old/include/openssl/ssl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ssl.h 2020-12-12 17:06:43.341349251 +0800 @@ -0,0 +1,2438 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * Copyright 2005 Nokia. All rights reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SSL_H +# define HEADER_SSL_H + +# include +# include +# include +# include +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# include +# include +# endif +# include +# include +# include +# include + +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* OpenSSL version number for ASN.1 encoding of the session information */ +/*- + * Version 0 - initial version + * Version 1 - added the optional peer certificate + */ +# define SSL_SESSION_ASN1_VERSION 0x0001 + +# define SSL_MAX_SSL_SESSION_ID_LENGTH 32 +# define SSL_MAX_SID_CTX_LENGTH 32 + +# define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) +# define SSL_MAX_KEY_ARG_LENGTH 8 +# define SSL_MAX_MASTER_KEY_LENGTH 48 + +/* The maximum number of encrypt/decrypt pipelines we can support */ +# define SSL_MAX_PIPELINES 32 + +/* text strings for the ciphers */ + +/* These are used to specify which ciphers to use and not to use */ + +# define SSL_TXT_LOW "LOW" +# define SSL_TXT_MEDIUM "MEDIUM" +# define SSL_TXT_HIGH "HIGH" +# define SSL_TXT_FIPS "FIPS" + +# define SSL_TXT_aNULL "aNULL" +# define SSL_TXT_eNULL "eNULL" +# define SSL_TXT_NULL "NULL" + +# define SSL_TXT_kRSA "kRSA" +# define SSL_TXT_kDHr "kDHr"/* this cipher class has been removed */ +# define SSL_TXT_kDHd "kDHd"/* this cipher class has been removed */ +# define SSL_TXT_kDH "kDH"/* this cipher class has been removed */ +# define SSL_TXT_kEDH "kEDH"/* alias for kDHE */ +# define SSL_TXT_kDHE "kDHE" +# define SSL_TXT_kECDHr "kECDHr"/* this cipher class has been removed */ +# define SSL_TXT_kECDHe "kECDHe"/* this cipher class has been removed */ +# define SSL_TXT_kECDH "kECDH"/* this cipher class has been removed */ +# define SSL_TXT_kEECDH "kEECDH"/* alias for kECDHE */ +# define SSL_TXT_kECDHE "kECDHE" +# define SSL_TXT_kPSK "kPSK" +# define SSL_TXT_kRSAPSK "kRSAPSK" +# define SSL_TXT_kECDHEPSK "kECDHEPSK" +# define SSL_TXT_kDHEPSK "kDHEPSK" +# define SSL_TXT_kGOST "kGOST" +# define SSL_TXT_kSRP "kSRP" + +# define SSL_TXT_aRSA "aRSA" +# define SSL_TXT_aDSS "aDSS" +# define SSL_TXT_aDH "aDH"/* this cipher class has been removed */ +# define SSL_TXT_aECDH "aECDH"/* this cipher class has been removed */ +# define SSL_TXT_aECDSA "aECDSA" +# define SSL_TXT_aPSK "aPSK" +# define SSL_TXT_aGOST94 "aGOST94" +# define SSL_TXT_aGOST01 "aGOST01" +# define SSL_TXT_aGOST12 "aGOST12" +# define SSL_TXT_aGOST "aGOST" +# define SSL_TXT_aSRP "aSRP" + +# define SSL_TXT_DSS "DSS" +# define SSL_TXT_DH "DH" +# define SSL_TXT_DHE "DHE"/* same as "kDHE:-ADH" */ +# define SSL_TXT_EDH "EDH"/* alias for DHE */ +# define SSL_TXT_ADH "ADH" +# define SSL_TXT_RSA "RSA" +# define SSL_TXT_ECDH "ECDH" +# define SSL_TXT_EECDH "EECDH"/* alias for ECDHE" */ +# define SSL_TXT_ECDHE "ECDHE"/* same as "kECDHE:-AECDH" */ +# define SSL_TXT_AECDH "AECDH" +# define SSL_TXT_ECDSA "ECDSA" +# define SSL_TXT_PSK "PSK" +# define SSL_TXT_SRP "SRP" + +# define SSL_TXT_DES "DES" +# define SSL_TXT_3DES "3DES" +# define SSL_TXT_RC4 "RC4" +# define SSL_TXT_RC2 "RC2" +# define SSL_TXT_IDEA "IDEA" +# define SSL_TXT_SEED "SEED" +# define SSL_TXT_AES128 "AES128" +# define SSL_TXT_AES256 "AES256" +# define SSL_TXT_AES "AES" +# define SSL_TXT_AES_GCM "AESGCM" +# define SSL_TXT_AES_CCM "AESCCM" +# define SSL_TXT_AES_CCM_8 "AESCCM8" +# define SSL_TXT_CAMELLIA128 "CAMELLIA128" +# define SSL_TXT_CAMELLIA256 "CAMELLIA256" +# define SSL_TXT_CAMELLIA "CAMELLIA" +# define SSL_TXT_CHACHA20 "CHACHA20" +# define SSL_TXT_GOST "GOST89" +# define SSL_TXT_ARIA "ARIA" +# define SSL_TXT_ARIA_GCM "ARIAGCM" +# define SSL_TXT_ARIA128 "ARIA128" +# define SSL_TXT_ARIA256 "ARIA256" + +# define SSL_TXT_MD5 "MD5" +# define SSL_TXT_SHA1 "SHA1" +# define SSL_TXT_SHA "SHA"/* same as "SHA1" */ +# define SSL_TXT_GOST94 "GOST94" +# define SSL_TXT_GOST89MAC "GOST89MAC" +# define SSL_TXT_GOST12 "GOST12" +# define SSL_TXT_GOST89MAC12 "GOST89MAC12" +# define SSL_TXT_SHA256 "SHA256" +# define SSL_TXT_SHA384 "SHA384" + +# define SSL_TXT_SSLV3 "SSLv3" +# define SSL_TXT_TLSV1 "TLSv1" +# define SSL_TXT_TLSV1_1 "TLSv1.1" +# define SSL_TXT_TLSV1_2 "TLSv1.2" + +# define SSL_TXT_ALL "ALL" + +/*- + * COMPLEMENTOF* definitions. These identifiers are used to (de-select) + * ciphers normally not being used. + * Example: "RC4" will activate all ciphers using RC4 including ciphers + * without authentication, which would normally disabled by DEFAULT (due + * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT" + * will make sure that it is also disabled in the specific selection. + * COMPLEMENTOF* identifiers are portable between version, as adjustments + * to the default cipher setup will also be included here. + * + * COMPLEMENTOFDEFAULT does not experience the same special treatment that + * DEFAULT gets, as only selection is being done and no sorting as needed + * for DEFAULT. + */ +# define SSL_TXT_CMPALL "COMPLEMENTOFALL" +# define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" + +/* + * The following cipher list is used by default. It also is substituted when + * an application-defined cipher list string starts with 'DEFAULT'. + * This applies to ciphersuites for TLSv1.2 and below. + */ +# define SSL_DEFAULT_CIPHER_LIST "ALL:!COMPLEMENTOFDEFAULT:!eNULL" +/* This is the default set of TLSv1.3 ciphersuites */ +# if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) +# define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \ + "TLS_CHACHA20_POLY1305_SHA256:" \ + "TLS_AES_128_GCM_SHA256" +# else +# define TLS_DEFAULT_CIPHERSUITES "TLS_AES_256_GCM_SHA384:" \ + "TLS_AES_128_GCM_SHA256" +#endif +/* + * As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always + * starts with a reasonable order, and all we have to do for DEFAULT is + * throwing out anonymous and unencrypted ciphersuites! (The latter are not + * actually enabled by ALL, but "ALL:RSA" would enable some of them.) + */ + +/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ +# define SSL_SENT_SHUTDOWN 1 +# define SSL_RECEIVED_SHUTDOWN 2 + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +# define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 +# define SSL_FILETYPE_PEM X509_FILETYPE_PEM + +/* + * This is needed to stop compilers complaining about the 'struct ssl_st *' + * function parameters used to prototype callbacks in SSL_CTX. + */ +typedef struct ssl_st *ssl_crock_st; +typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT; +typedef struct ssl_method_st SSL_METHOD; +typedef struct ssl_cipher_st SSL_CIPHER; +typedef struct ssl_session_st SSL_SESSION; +typedef struct tls_sigalgs_st TLS_SIGALGS; +typedef struct ssl_conf_ctx_st SSL_CONF_CTX; +typedef struct ssl_comp_st SSL_COMP; + +STACK_OF(SSL_CIPHER); +STACK_OF(SSL_COMP); + +/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/ +typedef struct srtp_protection_profile_st { + const char *name; + unsigned long id; +} SRTP_PROTECTION_PROFILE; + +DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE) + +typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data, + int len, void *arg); +typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len, + STACK_OF(SSL_CIPHER) *peer_ciphers, + const SSL_CIPHER **cipher, void *arg); + +/* Extension context codes */ +/* This extension is only allowed in TLS */ +#define SSL_EXT_TLS_ONLY 0x0001 +/* This extension is only allowed in DTLS */ +#define SSL_EXT_DTLS_ONLY 0x0002 +/* Some extensions may be allowed in DTLS but we don't implement them for it */ +#define SSL_EXT_TLS_IMPLEMENTATION_ONLY 0x0004 +/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */ +#define SSL_EXT_SSL3_ALLOWED 0x0008 +/* Extension is only defined for TLS1.2 and below */ +#define SSL_EXT_TLS1_2_AND_BELOW_ONLY 0x0010 +/* Extension is only defined for TLS1.3 and above */ +#define SSL_EXT_TLS1_3_ONLY 0x0020 +/* Ignore this extension during parsing if we are resuming */ +#define SSL_EXT_IGNORE_ON_RESUMPTION 0x0040 +#define SSL_EXT_CLIENT_HELLO 0x0080 +/* Really means TLS1.2 or below */ +#define SSL_EXT_TLS1_2_SERVER_HELLO 0x0100 +#define SSL_EXT_TLS1_3_SERVER_HELLO 0x0200 +#define SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS 0x0400 +#define SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST 0x0800 +#define SSL_EXT_TLS1_3_CERTIFICATE 0x1000 +#define SSL_EXT_TLS1_3_NEW_SESSION_TICKET 0x2000 +#define SSL_EXT_TLS1_3_CERTIFICATE_REQUEST 0x4000 + +/* Typedefs for handling custom extensions */ + +typedef int (*custom_ext_add_cb)(SSL *s, unsigned int ext_type, + const unsigned char **out, size_t *outlen, + int *al, void *add_arg); + +typedef void (*custom_ext_free_cb)(SSL *s, unsigned int ext_type, + const unsigned char *out, void *add_arg); + +typedef int (*custom_ext_parse_cb)(SSL *s, unsigned int ext_type, + const unsigned char *in, size_t inlen, + int *al, void *parse_arg); + + +typedef int (*SSL_custom_ext_add_cb_ex)(SSL *s, unsigned int ext_type, + unsigned int context, + const unsigned char **out, + size_t *outlen, X509 *x, + size_t chainidx, + int *al, void *add_arg); + +typedef void (*SSL_custom_ext_free_cb_ex)(SSL *s, unsigned int ext_type, + unsigned int context, + const unsigned char *out, + void *add_arg); + +typedef int (*SSL_custom_ext_parse_cb_ex)(SSL *s, unsigned int ext_type, + unsigned int context, + const unsigned char *in, + size_t inlen, X509 *x, + size_t chainidx, + int *al, void *parse_arg); + +/* Typedef for verification callback */ +typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx); + +/* + * Some values are reserved until OpenSSL 1.2.0 because they were previously + * included in SSL_OP_ALL in a 1.1.x release. + * + * Reserved value (until OpenSSL 1.2.0) 0x00000001U + * Reserved value (until OpenSSL 1.2.0) 0x00000002U + */ +/* Allow initial connection to servers that don't support RI */ +# define SSL_OP_LEGACY_SERVER_CONNECT 0x00000004U + +/* Reserved value (until OpenSSL 1.2.0) 0x00000008U */ +# define SSL_OP_TLSEXT_PADDING 0x00000010U +/* Reserved value (until OpenSSL 1.2.0) 0x00000020U */ +# define SSL_OP_SAFARI_ECDHE_ECDSA_BUG 0x00000040U +/* + * Reserved value (until OpenSSL 1.2.0) 0x00000080U + * Reserved value (until OpenSSL 1.2.0) 0x00000100U + * Reserved value (until OpenSSL 1.2.0) 0x00000200U + */ + +/* In TLSv1.3 allow a non-(ec)dhe based kex_mode */ +# define SSL_OP_ALLOW_NO_DHE_KEX 0x00000400U + +/* + * Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added in + * OpenSSL 0.9.6d. Usually (depending on the application protocol) the + * workaround is not needed. Unfortunately some broken SSL/TLS + * implementations cannot handle it at all, which is why we include it in + * SSL_OP_ALL. Added in 0.9.6e + */ +# define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800U + +/* DTLS options */ +# define SSL_OP_NO_QUERY_MTU 0x00001000U +/* Turn on Cookie Exchange (on relevant for servers) */ +# define SSL_OP_COOKIE_EXCHANGE 0x00002000U +/* Don't use RFC4507 ticket extension */ +# define SSL_OP_NO_TICKET 0x00004000U +# ifndef OPENSSL_NO_DTLS1_METHOD +/* Use Cisco's "speshul" version of DTLS_BAD_VER + * (only with deprecated DTLSv1_client_method()) */ +# define SSL_OP_CISCO_ANYCONNECT 0x00008000U +# endif + +/* As server, disallow session resumption on renegotiation */ +# define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000U +/* Don't use compression even if supported */ +# define SSL_OP_NO_COMPRESSION 0x00020000U +/* Permit unsafe legacy renegotiation */ +# define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0x00040000U +/* Disable encrypt-then-mac */ +# define SSL_OP_NO_ENCRYPT_THEN_MAC 0x00080000U + +/* + * Enable TLSv1.3 Compatibility mode. This is on by default. A future version + * of OpenSSL may have this disabled by default. + */ +# define SSL_OP_ENABLE_MIDDLEBOX_COMPAT 0x00100000U + +/* Prioritize Chacha20Poly1305 when client does. + * Modifies SSL_OP_CIPHER_SERVER_PREFERENCE */ +# define SSL_OP_PRIORITIZE_CHACHA 0x00200000U + +/* + * Set on servers to choose the cipher according to the server's preferences + */ +# define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000U +/* + * If set, a server will allow a client to issue a SSLv3.0 version number as + * latest version supported in the premaster secret, even when TLSv1.0 + * (version 3.1) was announced in the client hello. Normally this is + * forbidden to prevent version rollback attacks. + */ +# define SSL_OP_TLS_ROLLBACK_BUG 0x00800000U + +/* + * Switches off automatic TLSv1.3 anti-replay protection for early data. This + * is a server-side option only (no effect on the client). + */ +# define SSL_OP_NO_ANTI_REPLAY 0x01000000U + +# define SSL_OP_NO_SSLv3 0x02000000U +# define SSL_OP_NO_TLSv1 0x04000000U +# define SSL_OP_NO_TLSv1_2 0x08000000U +# define SSL_OP_NO_TLSv1_1 0x10000000U +# define SSL_OP_NO_TLSv1_3 0x20000000U + +# define SSL_OP_NO_DTLSv1 0x04000000U +# define SSL_OP_NO_DTLSv1_2 0x08000000U + +# define SSL_OP_NO_SSL_MASK (SSL_OP_NO_SSLv3|\ + SSL_OP_NO_TLSv1|SSL_OP_NO_TLSv1_1|SSL_OP_NO_TLSv1_2|SSL_OP_NO_TLSv1_3) +# define SSL_OP_NO_DTLS_MASK (SSL_OP_NO_DTLSv1|SSL_OP_NO_DTLSv1_2) + +/* Disallow all renegotiation */ +# define SSL_OP_NO_RENEGOTIATION 0x40000000U + +/* + * Make server add server-hello extension from early version of cryptopro + * draft, when GOST ciphersuite is negotiated. Required for interoperability + * with CryptoPro CSP 3.x + */ +# define SSL_OP_CRYPTOPRO_TLSEXT_BUG 0x80000000U + +/* + * SSL_OP_ALL: various bug workarounds that should be rather harmless. + * This used to be 0x000FFFFFL before 0.9.7. + * This used to be 0x80000BFFU before 1.1.1. + */ +# define SSL_OP_ALL (SSL_OP_CRYPTOPRO_TLSEXT_BUG|\ + SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS|\ + SSL_OP_LEGACY_SERVER_CONNECT|\ + SSL_OP_TLSEXT_PADDING|\ + SSL_OP_SAFARI_ECDHE_ECDSA_BUG) + +/* OBSOLETE OPTIONS: retained for compatibility */ + +/* Removed from OpenSSL 1.1.0. Was 0x00000001L */ +/* Related to removed SSLv2. */ +# define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00000002L */ +/* Related to removed SSLv2. */ +# define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0 +/* Removed from OpenSSL 0.9.8q and 1.0.0c. Was 0x00000008L */ +/* Dead forever, see CVE-2010-4180 */ +# define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0 +/* Removed from OpenSSL 1.0.1h and 1.0.2. Was 0x00000010L */ +/* Refers to ancient SSLREF and SSLv2. */ +# define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00000020 */ +# define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0 +/* Removed from OpenSSL 0.9.7h and 0.9.8b. Was 0x00000040L */ +# define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00000080 */ +/* Ancient SSLeay version. */ +# define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00000100L */ +# define SSL_OP_TLS_D5_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00000200L */ +# define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00080000L */ +# define SSL_OP_SINGLE_ECDH_USE 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x00100000L */ +# define SSL_OP_SINGLE_DH_USE 0x0 +/* Removed from OpenSSL 1.0.1k and 1.0.2. Was 0x00200000L */ +# define SSL_OP_EPHEMERAL_RSA 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x01000000L */ +# define SSL_OP_NO_SSLv2 0x0 +/* Removed from OpenSSL 1.0.1. Was 0x08000000L */ +# define SSL_OP_PKCS1_CHECK_1 0x0 +/* Removed from OpenSSL 1.0.1. Was 0x10000000L */ +# define SSL_OP_PKCS1_CHECK_2 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x20000000L */ +# define SSL_OP_NETSCAPE_CA_DN_BUG 0x0 +/* Removed from OpenSSL 1.1.0. Was 0x40000000L */ +# define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0 + +/* + * Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success + * when just a single record has been written): + */ +# define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001U +/* + * Make it possible to retry SSL_write() with changed buffer location (buffer + * contents must stay the same!); this is not the default to avoid the + * misconception that non-blocking SSL_write() behaves like non-blocking + * write(): + */ +# define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002U +/* + * Never bother the application with retries if the transport is blocking: + */ +# define SSL_MODE_AUTO_RETRY 0x00000004U +/* Don't attempt to automatically build certificate chain */ +# define SSL_MODE_NO_AUTO_CHAIN 0x00000008U +/* + * Save RAM by releasing read and write buffers when they're empty. (SSL3 and + * TLS only.) Released buffers are freed. + */ +# define SSL_MODE_RELEASE_BUFFERS 0x00000010U +/* + * Send the current time in the Random fields of the ClientHello and + * ServerHello records for compatibility with hypothetical implementations + * that require it. + */ +# define SSL_MODE_SEND_CLIENTHELLO_TIME 0x00000020U +# define SSL_MODE_SEND_SERVERHELLO_TIME 0x00000040U +/* + * Send TLS_FALLBACK_SCSV in the ClientHello. To be set only by applications + * that reconnect with a downgraded protocol version; see + * draft-ietf-tls-downgrade-scsv-00 for details. DO NOT ENABLE THIS if your + * application attempts a normal handshake. Only use this in explicit + * fallback retries, following the guidance in + * draft-ietf-tls-downgrade-scsv-00. + */ +# define SSL_MODE_SEND_FALLBACK_SCSV 0x00000080U +/* + * Support Asynchronous operation + */ +# define SSL_MODE_ASYNC 0x00000100U + +/* + * When using DTLS/SCTP, include the terminating zero in the label + * used for computing the endpoint-pair shared secret. Required for + * interoperability with implementations having this bug like these + * older version of OpenSSL: + * - OpenSSL 1.0.0 series + * - OpenSSL 1.0.1 series + * - OpenSSL 1.0.2 series + * - OpenSSL 1.1.0 series + * - OpenSSL 1.1.1 and 1.1.1a + */ +# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U + +/* Cert related flags */ +/* + * Many implementations ignore some aspects of the TLS standards such as + * enforcing certificate chain algorithms. When this is set we enforce them. + */ +# define SSL_CERT_FLAG_TLS_STRICT 0x00000001U + +/* Suite B modes, takes same values as certificate verify flags */ +# define SSL_CERT_FLAG_SUITEB_128_LOS_ONLY 0x10000 +/* Suite B 192 bit only mode */ +# define SSL_CERT_FLAG_SUITEB_192_LOS 0x20000 +/* Suite B 128 bit mode allowing 192 bit algorithms */ +# define SSL_CERT_FLAG_SUITEB_128_LOS 0x30000 + +/* Perform all sorts of protocol violations for testing purposes */ +# define SSL_CERT_FLAG_BROKEN_PROTOCOL 0x10000000 + +/* Flags for building certificate chains */ +/* Treat any existing certificates as untrusted CAs */ +# define SSL_BUILD_CHAIN_FLAG_UNTRUSTED 0x1 +/* Don't include root CA in chain */ +# define SSL_BUILD_CHAIN_FLAG_NO_ROOT 0x2 +/* Just check certificates already there */ +# define SSL_BUILD_CHAIN_FLAG_CHECK 0x4 +/* Ignore verification errors */ +# define SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR 0x8 +/* Clear verification errors from queue */ +# define SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR 0x10 + +/* Flags returned by SSL_check_chain */ +/* Certificate can be used with this session */ +# define CERT_PKEY_VALID 0x1 +/* Certificate can also be used for signing */ +# define CERT_PKEY_SIGN 0x2 +/* EE certificate signing algorithm OK */ +# define CERT_PKEY_EE_SIGNATURE 0x10 +/* CA signature algorithms OK */ +# define CERT_PKEY_CA_SIGNATURE 0x20 +/* EE certificate parameters OK */ +# define CERT_PKEY_EE_PARAM 0x40 +/* CA certificate parameters OK */ +# define CERT_PKEY_CA_PARAM 0x80 +/* Signing explicitly allowed as opposed to SHA1 fallback */ +# define CERT_PKEY_EXPLICIT_SIGN 0x100 +/* Client CA issuer names match (always set for server cert) */ +# define CERT_PKEY_ISSUER_NAME 0x200 +/* Cert type matches client types (always set for server cert) */ +# define CERT_PKEY_CERT_TYPE 0x400 +/* Cert chain suitable to Suite B */ +# define CERT_PKEY_SUITEB 0x800 + +# define SSL_CONF_FLAG_CMDLINE 0x1 +# define SSL_CONF_FLAG_FILE 0x2 +# define SSL_CONF_FLAG_CLIENT 0x4 +# define SSL_CONF_FLAG_SERVER 0x8 +# define SSL_CONF_FLAG_SHOW_ERRORS 0x10 +# define SSL_CONF_FLAG_CERTIFICATE 0x20 +# define SSL_CONF_FLAG_REQUIRE_PRIVATE 0x40 +/* Configuration value types */ +# define SSL_CONF_TYPE_UNKNOWN 0x0 +# define SSL_CONF_TYPE_STRING 0x1 +# define SSL_CONF_TYPE_FILE 0x2 +# define SSL_CONF_TYPE_DIR 0x3 +# define SSL_CONF_TYPE_NONE 0x4 + +/* Maximum length of the application-controlled segment of a a TLSv1.3 cookie */ +# define SSL_COOKIE_LENGTH 4096 + +/* + * Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, they + * cannot be used to clear bits. + */ + +unsigned long SSL_CTX_get_options(const SSL_CTX *ctx); +unsigned long SSL_get_options(const SSL *s); +unsigned long SSL_CTX_clear_options(SSL_CTX *ctx, unsigned long op); +unsigned long SSL_clear_options(SSL *s, unsigned long op); +unsigned long SSL_CTX_set_options(SSL_CTX *ctx, unsigned long op); +unsigned long SSL_set_options(SSL *s, unsigned long op); + +# define SSL_CTX_set_mode(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) +# define SSL_CTX_clear_mode(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL) +# define SSL_CTX_get_mode(ctx) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL) +# define SSL_clear_mode(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL) +# define SSL_set_mode(ssl,op) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) +# define SSL_get_mode(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) +# define SSL_set_mtu(ssl, mtu) \ + SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL) +# define DTLS_set_link_mtu(ssl, mtu) \ + SSL_ctrl((ssl),DTLS_CTRL_SET_LINK_MTU,(mtu),NULL) +# define DTLS_get_link_min_mtu(ssl) \ + SSL_ctrl((ssl),DTLS_CTRL_GET_LINK_MIN_MTU,0,NULL) + +# define SSL_get_secure_renegotiation_support(ssl) \ + SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL) + +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_heartbeat(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT,0,NULL) +# endif + +# define SSL_CTX_set_cert_flags(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL) +# define SSL_set_cert_flags(s,op) \ + SSL_ctrl((s),SSL_CTRL_CERT_FLAGS,(op),NULL) +# define SSL_CTX_clear_cert_flags(ctx,op) \ + SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) +# define SSL_clear_cert_flags(s,op) \ + SSL_ctrl((s),SSL_CTRL_CLEAR_CERT_FLAGS,(op),NULL) + +void SSL_CTX_set_msg_callback(SSL_CTX *ctx, + void (*cb) (int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); +void SSL_set_msg_callback(SSL *ssl, + void (*cb) (int write_p, int version, + int content_type, const void *buf, + size_t len, SSL *ssl, void *arg)); +# define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) +# define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) + +# define SSL_get_extms_support(s) \ + SSL_ctrl((s),SSL_CTRL_GET_EXTMS_SUPPORT,0,NULL) + +# ifndef OPENSSL_NO_SRP + +/* see tls_srp.c */ +__owur int SSL_SRP_CTX_init(SSL *s); +__owur int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx); +int SSL_SRP_CTX_free(SSL *ctx); +int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx); +__owur int SSL_srp_server_param_with_username(SSL *s, int *ad); +__owur int SRP_Calc_A_param(SSL *s); + +# endif + +/* 100k max cert list */ +# define SSL_MAX_CERT_LIST_DEFAULT 1024*100 + +# define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) + +/* + * This callback type is used inside SSL_CTX, SSL, and in the functions that + * set them. It is used to override the generation of SSL/TLS session IDs in + * a server. Return value should be zero on an error, non-zero to proceed. + * Also, callbacks should themselves check if the id they generate is unique + * otherwise the SSL handshake will fail with an error - callbacks can do + * this using the 'ssl' value they're passed by; + * SSL_has_matching_session_id(ssl, id, *id_len) The length value passed in + * is set at the maximum size the session ID can be. In SSLv3/TLSv1 it is 32 + * bytes. The callback can alter this length to be less if desired. It is + * also an error for the callback to set the size to zero. + */ +typedef int (*GEN_SESSION_CB) (SSL *ssl, unsigned char *id, + unsigned int *id_len); + +# define SSL_SESS_CACHE_OFF 0x0000 +# define SSL_SESS_CACHE_CLIENT 0x0001 +# define SSL_SESS_CACHE_SERVER 0x0002 +# define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) +# define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 +/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ +# define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 +# define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 +# define SSL_SESS_CACHE_NO_INTERNAL \ + (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) + +LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx); +# define SSL_CTX_sess_number(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) +# define SSL_CTX_sess_connect(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) +# define SSL_CTX_sess_connect_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) +# define SSL_CTX_sess_connect_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) +# define SSL_CTX_sess_accept(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) +# define SSL_CTX_sess_accept_renegotiate(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) +# define SSL_CTX_sess_accept_good(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) +# define SSL_CTX_sess_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) +# define SSL_CTX_sess_cb_hits(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) +# define SSL_CTX_sess_misses(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) +# define SSL_CTX_sess_timeouts(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) +# define SSL_CTX_sess_cache_full(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) + +void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, + int (*new_session_cb) (struct ssl_st *ssl, + SSL_SESSION *sess)); +int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, + SSL_SESSION *sess); +void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, + void (*remove_session_cb) (struct ssl_ctx_st + *ctx, + SSL_SESSION *sess)); +void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (struct ssl_ctx_st *ctx, + SSL_SESSION *sess); +void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, + SSL_SESSION *(*get_session_cb) (struct ssl_st + *ssl, + const unsigned char + *data, int len, + int *copy)); +SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (struct ssl_st *ssl, + const unsigned char *data, + int len, int *copy); +void SSL_CTX_set_info_callback(SSL_CTX *ctx, + void (*cb) (const SSL *ssl, int type, int val)); +void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, + int val); +void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, + int (*client_cert_cb) (SSL *ssl, X509 **x509, + EVP_PKEY **pkey)); +int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509, + EVP_PKEY **pkey); +# ifndef OPENSSL_NO_ENGINE +__owur int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e); +# endif +void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, + int (*app_gen_cookie_cb) (SSL *ssl, + unsigned char + *cookie, + unsigned int + *cookie_len)); +void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, + int (*app_verify_cookie_cb) (SSL *ssl, + const unsigned + char *cookie, + unsigned int + cookie_len)); + +void SSL_CTX_set_stateless_cookie_generate_cb( + SSL_CTX *ctx, + int (*gen_stateless_cookie_cb) (SSL *ssl, + unsigned char *cookie, + size_t *cookie_len)); +void SSL_CTX_set_stateless_cookie_verify_cb( + SSL_CTX *ctx, + int (*verify_stateless_cookie_cb) (SSL *ssl, + const unsigned char *cookie, + size_t cookie_len)); +# ifndef OPENSSL_NO_NEXTPROTONEG + +typedef int (*SSL_CTX_npn_advertised_cb_func)(SSL *ssl, + const unsigned char **out, + unsigned int *outlen, + void *arg); +void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, + SSL_CTX_npn_advertised_cb_func cb, + void *arg); +# define SSL_CTX_set_npn_advertised_cb SSL_CTX_set_next_protos_advertised_cb + +typedef int (*SSL_CTX_npn_select_cb_func)(SSL *s, + unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg); +void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, + SSL_CTX_npn_select_cb_func cb, + void *arg); +# define SSL_CTX_set_npn_select_cb SSL_CTX_set_next_proto_select_cb + +void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data, + unsigned *len); +# define SSL_get0_npn_negotiated SSL_get0_next_proto_negotiated +# endif + +__owur int SSL_select_next_proto(unsigned char **out, unsigned char *outlen, + const unsigned char *in, unsigned int inlen, + const unsigned char *client, + unsigned int client_len); + +# define OPENSSL_NPN_UNSUPPORTED 0 +# define OPENSSL_NPN_NEGOTIATED 1 +# define OPENSSL_NPN_NO_OVERLAP 2 + +__owur int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos, + unsigned int protos_len); +__owur int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos, + unsigned int protos_len); +typedef int (*SSL_CTX_alpn_select_cb_func)(SSL *ssl, + const unsigned char **out, + unsigned char *outlen, + const unsigned char *in, + unsigned int inlen, + void *arg); +void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, + SSL_CTX_alpn_select_cb_func cb, + void *arg); +void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, + unsigned int *len); + +# ifndef OPENSSL_NO_PSK +/* + * the maximum length of the buffer given to callbacks containing the + * resulting identity/psk + */ +# define PSK_MAX_IDENTITY_LEN 128 +# define PSK_MAX_PSK_LEN 256 +typedef unsigned int (*SSL_psk_client_cb_func)(SSL *ssl, + const char *hint, + char *identity, + unsigned int max_identity_len, + unsigned char *psk, + unsigned int max_psk_len); +void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, SSL_psk_client_cb_func cb); +void SSL_set_psk_client_callback(SSL *ssl, SSL_psk_client_cb_func cb); + +typedef unsigned int (*SSL_psk_server_cb_func)(SSL *ssl, + const char *identity, + unsigned char *psk, + unsigned int max_psk_len); +void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, SSL_psk_server_cb_func cb); +void SSL_set_psk_server_callback(SSL *ssl, SSL_psk_server_cb_func cb); + +__owur int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint); +__owur int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint); +const char *SSL_get_psk_identity_hint(const SSL *s); +const char *SSL_get_psk_identity(const SSL *s); +# endif + +typedef int (*SSL_psk_find_session_cb_func)(SSL *ssl, + const unsigned char *identity, + size_t identity_len, + SSL_SESSION **sess); +typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md, + const unsigned char **id, + size_t *idlen, + SSL_SESSION **sess); + +void SSL_set_psk_find_session_callback(SSL *s, SSL_psk_find_session_cb_func cb); +void SSL_CTX_set_psk_find_session_callback(SSL_CTX *ctx, + SSL_psk_find_session_cb_func cb); +void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb); +void SSL_CTX_set_psk_use_session_callback(SSL_CTX *ctx, + SSL_psk_use_session_cb_func cb); + +/* Register callbacks to handle custom TLS Extensions for client or server. */ + +__owur int SSL_CTX_has_client_custom_ext(const SSL_CTX *ctx, + unsigned int ext_type); + +__owur int SSL_CTX_add_client_custom_ext(SSL_CTX *ctx, + unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); + +__owur int SSL_CTX_add_server_custom_ext(SSL_CTX *ctx, + unsigned int ext_type, + custom_ext_add_cb add_cb, + custom_ext_free_cb free_cb, + void *add_arg, + custom_ext_parse_cb parse_cb, + void *parse_arg); + +__owur int SSL_CTX_add_custom_ext(SSL_CTX *ctx, unsigned int ext_type, + unsigned int context, + SSL_custom_ext_add_cb_ex add_cb, + SSL_custom_ext_free_cb_ex free_cb, + void *add_arg, + SSL_custom_ext_parse_cb_ex parse_cb, + void *parse_arg); + +__owur int SSL_extension_supported(unsigned int ext_type); + +# define SSL_NOTHING 1 +# define SSL_WRITING 2 +# define SSL_READING 3 +# define SSL_X509_LOOKUP 4 +# define SSL_ASYNC_PAUSED 5 +# define SSL_ASYNC_NO_JOBS 6 +# define SSL_CLIENT_HELLO_CB 7 + +/* These will only be used when doing non-blocking IO */ +# define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) +# define SSL_want_read(s) (SSL_want(s) == SSL_READING) +# define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) +# define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) +# define SSL_want_async(s) (SSL_want(s) == SSL_ASYNC_PAUSED) +# define SSL_want_async_job(s) (SSL_want(s) == SSL_ASYNC_NO_JOBS) +# define SSL_want_client_hello_cb(s) (SSL_want(s) == SSL_CLIENT_HELLO_CB) + +# define SSL_MAC_FLAG_READ_MAC_STREAM 1 +# define SSL_MAC_FLAG_WRITE_MAC_STREAM 2 + +/* + * A callback for logging out TLS key material. This callback should log out + * |line| followed by a newline. + */ +typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line); + +/* + * SSL_CTX_set_keylog_callback configures a callback to log key material. This + * is intended for debugging use with tools like Wireshark. The cb function + * should log line followed by a newline. + */ +void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb); + +/* + * SSL_CTX_get_keylog_callback returns the callback configured by + * SSL_CTX_set_keylog_callback. + */ +SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx); + +int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data); +uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx); +int SSL_set_max_early_data(SSL *s, uint32_t max_early_data); +uint32_t SSL_get_max_early_data(const SSL *s); +int SSL_CTX_set_recv_max_early_data(SSL_CTX *ctx, uint32_t recv_max_early_data); +uint32_t SSL_CTX_get_recv_max_early_data(const SSL_CTX *ctx); +int SSL_set_recv_max_early_data(SSL *s, uint32_t recv_max_early_data); +uint32_t SSL_get_recv_max_early_data(const SSL *s); + +#ifdef __cplusplus +} +#endif + +# include +# include +# include /* This is mostly sslv3 with a few tweaks */ +# include /* Datagram TLS */ +# include /* Support for the use_srtp extension */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * These need to be after the above set of includes due to a compiler bug + * in VisualStudio 2015 + */ +DEFINE_STACK_OF_CONST(SSL_CIPHER) +DEFINE_STACK_OF(SSL_COMP) + +/* compatibility */ +# define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)(arg))) +# define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) +# define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0, \ + (char *)(a))) +# define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) +# define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) +# define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0, \ + (char *)(arg))) +DEPRECATEDIN_1_1_0(void SSL_set_debug(SSL *s, int debug)) + +/* TLSv1.3 KeyUpdate message types */ +/* -1 used so that this is an invalid value for the on-the-wire protocol */ +#define SSL_KEY_UPDATE_NONE -1 +/* Values as defined for the on-the-wire protocol */ +#define SSL_KEY_UPDATE_NOT_REQUESTED 0 +#define SSL_KEY_UPDATE_REQUESTED 1 + +/* + * The valid handshake states (one for each type message sent and one for each + * type of message received). There are also two "special" states: + * TLS = TLS or DTLS state + * DTLS = DTLS specific state + * CR/SR = Client Read/Server Read + * CW/SW = Client Write/Server Write + * + * The "special" states are: + * TLS_ST_BEFORE = No handshake has been initiated yet + * TLS_ST_OK = A handshake has been successfully completed + */ +typedef enum { + TLS_ST_BEFORE, + TLS_ST_OK, + DTLS_ST_CR_HELLO_VERIFY_REQUEST, + TLS_ST_CR_SRVR_HELLO, + TLS_ST_CR_CERT, + TLS_ST_CR_CERT_STATUS, + TLS_ST_CR_KEY_EXCH, + TLS_ST_CR_CERT_REQ, + TLS_ST_CR_SRVR_DONE, + TLS_ST_CR_SESSION_TICKET, + TLS_ST_CR_CHANGE, + TLS_ST_CR_FINISHED, + TLS_ST_CW_CLNT_HELLO, + TLS_ST_CW_CERT, + TLS_ST_CW_KEY_EXCH, + TLS_ST_CW_CERT_VRFY, + TLS_ST_CW_CHANGE, + TLS_ST_CW_NEXT_PROTO, + TLS_ST_CW_FINISHED, + TLS_ST_SW_HELLO_REQ, + TLS_ST_SR_CLNT_HELLO, + DTLS_ST_SW_HELLO_VERIFY_REQUEST, + TLS_ST_SW_SRVR_HELLO, + TLS_ST_SW_CERT, + TLS_ST_SW_KEY_EXCH, + TLS_ST_SW_CERT_REQ, + TLS_ST_SW_SRVR_DONE, + TLS_ST_SR_CERT, + TLS_ST_SR_KEY_EXCH, + TLS_ST_SR_CERT_VRFY, + TLS_ST_SR_NEXT_PROTO, + TLS_ST_SR_CHANGE, + TLS_ST_SR_FINISHED, + TLS_ST_SW_SESSION_TICKET, + TLS_ST_SW_CERT_STATUS, + TLS_ST_SW_CHANGE, + TLS_ST_SW_FINISHED, + TLS_ST_SW_ENCRYPTED_EXTENSIONS, + TLS_ST_CR_ENCRYPTED_EXTENSIONS, + TLS_ST_CR_CERT_VRFY, + TLS_ST_SW_CERT_VRFY, + TLS_ST_CR_HELLO_REQ, + TLS_ST_SW_KEY_UPDATE, + TLS_ST_CW_KEY_UPDATE, + TLS_ST_SR_KEY_UPDATE, + TLS_ST_CR_KEY_UPDATE, + TLS_ST_EARLY_DATA, + TLS_ST_PENDING_EARLY_DATA_END, + TLS_ST_CW_END_OF_EARLY_DATA, + TLS_ST_SR_END_OF_EARLY_DATA +} OSSL_HANDSHAKE_STATE; + +/* + * Most of the following state values are no longer used and are defined to be + * the closest equivalent value in the current state machine code. Not all + * defines have an equivalent and are set to a dummy value (-1). SSL_ST_CONNECT + * and SSL_ST_ACCEPT are still in use in the definition of SSL_CB_ACCEPT_LOOP, + * SSL_CB_ACCEPT_EXIT, SSL_CB_CONNECT_LOOP and SSL_CB_CONNECT_EXIT. + */ + +# define SSL_ST_CONNECT 0x1000 +# define SSL_ST_ACCEPT 0x2000 + +# define SSL_ST_MASK 0x0FFF + +# define SSL_CB_LOOP 0x01 +# define SSL_CB_EXIT 0x02 +# define SSL_CB_READ 0x04 +# define SSL_CB_WRITE 0x08 +# define SSL_CB_ALERT 0x4000/* used in callback */ +# define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) +# define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) +# define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) +# define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) +# define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) +# define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) +# define SSL_CB_HANDSHAKE_START 0x10 +# define SSL_CB_HANDSHAKE_DONE 0x20 + +/* Is the SSL_connection established? */ +# define SSL_in_connect_init(a) (SSL_in_init(a) && !SSL_is_server(a)) +# define SSL_in_accept_init(a) (SSL_in_init(a) && SSL_is_server(a)) +int SSL_in_init(const SSL *s); +int SSL_in_before(const SSL *s); +int SSL_is_init_finished(const SSL *s); + +/* + * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you + * should not need these + */ +# define SSL_ST_READ_HEADER 0xF0 +# define SSL_ST_READ_BODY 0xF1 +# define SSL_ST_READ_DONE 0xF2 + +/*- + * Obtain latest Finished message + * -- that we sent (SSL_get_finished) + * -- that we expected from peer (SSL_get_peer_finished). + * Returns length (0 == no Finished so far), copies up to 'count' bytes. + */ +size_t SSL_get_finished(const SSL *s, void *buf, size_t count); +size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); + +/* + * use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 3 options are + * 'ored' with SSL_VERIFY_PEER if they are desired + */ +# define SSL_VERIFY_NONE 0x00 +# define SSL_VERIFY_PEER 0x01 +# define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 +# define SSL_VERIFY_CLIENT_ONCE 0x04 +# define SSL_VERIFY_POST_HANDSHAKE 0x08 + +# if OPENSSL_API_COMPAT < 0x10100000L +# define OpenSSL_add_ssl_algorithms() SSL_library_init() +# define SSLeay_add_ssl_algorithms() SSL_library_init() +# endif + +/* More backward compatibility */ +# define SSL_get_cipher(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +# define SSL_get_cipher_bits(s,np) \ + SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) +# define SSL_get_cipher_version(s) \ + SSL_CIPHER_get_version(SSL_get_current_cipher(s)) +# define SSL_get_cipher_name(s) \ + SSL_CIPHER_get_name(SSL_get_current_cipher(s)) +# define SSL_get_time(a) SSL_SESSION_get_time(a) +# define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) +# define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) +# define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) + +# define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id) +# define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id) + +DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) +# define SSL_AD_REASON_OFFSET 1000/* offset to get SSL_R_... value + * from SSL_AD_... */ +/* These alert types are for SSLv3 and TLSv1 */ +# define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY +/* fatal */ +# define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE +/* fatal */ +# define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC +# define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED +# define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW +/* fatal */ +# define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE +/* fatal */ +# define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE +/* Not for TLS */ +# define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE +# define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE +# define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE +# define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED +# define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED +# define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN +/* fatal */ +# define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER +/* fatal */ +# define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA +/* fatal */ +# define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED +/* fatal */ +# define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR +# define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR +/* fatal */ +# define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION +/* fatal */ +# define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION +/* fatal */ +# define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY +/* fatal */ +# define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR +# define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED +# define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION +# define SSL_AD_MISSING_EXTENSION TLS13_AD_MISSING_EXTENSION +# define SSL_AD_CERTIFICATE_REQUIRED TLS13_AD_CERTIFICATE_REQUIRED +# define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION +# define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE +# define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME +# define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE +# define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE +/* fatal */ +# define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY +/* fatal */ +# define SSL_AD_INAPPROPRIATE_FALLBACK TLS1_AD_INAPPROPRIATE_FALLBACK +# define SSL_AD_NO_APPLICATION_PROTOCOL TLS1_AD_NO_APPLICATION_PROTOCOL +# define SSL_ERROR_NONE 0 +# define SSL_ERROR_SSL 1 +# define SSL_ERROR_WANT_READ 2 +# define SSL_ERROR_WANT_WRITE 3 +# define SSL_ERROR_WANT_X509_LOOKUP 4 +# define SSL_ERROR_SYSCALL 5/* look at error stack/return + * value/errno */ +# define SSL_ERROR_ZERO_RETURN 6 +# define SSL_ERROR_WANT_CONNECT 7 +# define SSL_ERROR_WANT_ACCEPT 8 +# define SSL_ERROR_WANT_ASYNC 9 +# define SSL_ERROR_WANT_ASYNC_JOB 10 +# define SSL_ERROR_WANT_CLIENT_HELLO_CB 11 +# define SSL_CTRL_SET_TMP_DH 3 +# define SSL_CTRL_SET_TMP_ECDH 4 +# define SSL_CTRL_SET_TMP_DH_CB 6 +# define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9 +# define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10 +# define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11 +# define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12 +# define SSL_CTRL_GET_FLAGS 13 +# define SSL_CTRL_EXTRA_CHAIN_CERT 14 +# define SSL_CTRL_SET_MSG_CALLBACK 15 +# define SSL_CTRL_SET_MSG_CALLBACK_ARG 16 +/* only applies to datagram connections */ +# define SSL_CTRL_SET_MTU 17 +/* Stats */ +# define SSL_CTRL_SESS_NUMBER 20 +# define SSL_CTRL_SESS_CONNECT 21 +# define SSL_CTRL_SESS_CONNECT_GOOD 22 +# define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 +# define SSL_CTRL_SESS_ACCEPT 24 +# define SSL_CTRL_SESS_ACCEPT_GOOD 25 +# define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 +# define SSL_CTRL_SESS_HIT 27 +# define SSL_CTRL_SESS_CB_HIT 28 +# define SSL_CTRL_SESS_MISSES 29 +# define SSL_CTRL_SESS_TIMEOUTS 30 +# define SSL_CTRL_SESS_CACHE_FULL 31 +# define SSL_CTRL_MODE 33 +# define SSL_CTRL_GET_READ_AHEAD 40 +# define SSL_CTRL_SET_READ_AHEAD 41 +# define SSL_CTRL_SET_SESS_CACHE_SIZE 42 +# define SSL_CTRL_GET_SESS_CACHE_SIZE 43 +# define SSL_CTRL_SET_SESS_CACHE_MODE 44 +# define SSL_CTRL_GET_SESS_CACHE_MODE 45 +# define SSL_CTRL_GET_MAX_CERT_LIST 50 +# define SSL_CTRL_SET_MAX_CERT_LIST 51 +# define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52 +/* see tls1.h for macros based on these */ +# define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 +# define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 +# define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 +# define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56 +# define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57 +# define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58 +# define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59 +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT 60 */ +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB 61 */ +/*# define SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG 62 */ +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70 +# define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71 +# define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72 +# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75 +# define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76 +# define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77 +# define SSL_CTRL_SET_SRP_ARG 78 +# define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79 +# define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80 +# define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81 +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT 85 +# define SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING 86 +# define SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS 87 +# endif +# define DTLS_CTRL_GET_TIMEOUT 73 +# define DTLS_CTRL_HANDLE_TIMEOUT 74 +# define SSL_CTRL_GET_RI_SUPPORT 76 +# define SSL_CTRL_CLEAR_MODE 78 +# define SSL_CTRL_SET_NOT_RESUMABLE_SESS_CB 79 +# define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82 +# define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83 +# define SSL_CTRL_CHAIN 88 +# define SSL_CTRL_CHAIN_CERT 89 +# define SSL_CTRL_GET_GROUPS 90 +# define SSL_CTRL_SET_GROUPS 91 +# define SSL_CTRL_SET_GROUPS_LIST 92 +# define SSL_CTRL_GET_SHARED_GROUP 93 +# define SSL_CTRL_SET_SIGALGS 97 +# define SSL_CTRL_SET_SIGALGS_LIST 98 +# define SSL_CTRL_CERT_FLAGS 99 +# define SSL_CTRL_CLEAR_CERT_FLAGS 100 +# define SSL_CTRL_SET_CLIENT_SIGALGS 101 +# define SSL_CTRL_SET_CLIENT_SIGALGS_LIST 102 +# define SSL_CTRL_GET_CLIENT_CERT_TYPES 103 +# define SSL_CTRL_SET_CLIENT_CERT_TYPES 104 +# define SSL_CTRL_BUILD_CERT_CHAIN 105 +# define SSL_CTRL_SET_VERIFY_CERT_STORE 106 +# define SSL_CTRL_SET_CHAIN_CERT_STORE 107 +# define SSL_CTRL_GET_PEER_SIGNATURE_NID 108 +# define SSL_CTRL_GET_PEER_TMP_KEY 109 +# define SSL_CTRL_GET_RAW_CIPHERLIST 110 +# define SSL_CTRL_GET_EC_POINT_FORMATS 111 +# define SSL_CTRL_GET_CHAIN_CERTS 115 +# define SSL_CTRL_SELECT_CURRENT_CERT 116 +# define SSL_CTRL_SET_CURRENT_CERT 117 +# define SSL_CTRL_SET_DH_AUTO 118 +# define DTLS_CTRL_SET_LINK_MTU 120 +# define DTLS_CTRL_GET_LINK_MIN_MTU 121 +# define SSL_CTRL_GET_EXTMS_SUPPORT 122 +# define SSL_CTRL_SET_MIN_PROTO_VERSION 123 +# define SSL_CTRL_SET_MAX_PROTO_VERSION 124 +# define SSL_CTRL_SET_SPLIT_SEND_FRAGMENT 125 +# define SSL_CTRL_SET_MAX_PIPELINES 126 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE 127 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB 128 +# define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG 129 +# define SSL_CTRL_GET_MIN_PROTO_VERSION 130 +# define SSL_CTRL_GET_MAX_PROTO_VERSION 131 +# define SSL_CTRL_GET_SIGNATURE_NID 132 +# define SSL_CTRL_GET_TMP_KEY 133 +# define SSL_CERT_SET_FIRST 1 +# define SSL_CERT_SET_NEXT 2 +# define SSL_CERT_SET_SERVER 3 +# define DTLSv1_get_timeout(ssl, arg) \ + SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)(arg)) +# define DTLSv1_handle_timeout(ssl) \ + SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL) +# define SSL_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) +# define SSL_clear_num_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) +# define SSL_total_renegotiations(ssl) \ + SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) +# define SSL_CTX_set_tmp_dh(ctx,dh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh)) +# define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh)) +# define SSL_CTX_set_dh_auto(ctx, onoff) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL) +# define SSL_set_dh_auto(s, onoff) \ + SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL) +# define SSL_set_tmp_dh(ssl,dh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)(dh)) +# define SSL_set_tmp_ecdh(ssl,ecdh) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh)) +# define SSL_CTX_add_extra_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)(x509)) +# define SSL_CTX_get_extra_chain_certs(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509) +# define SSL_CTX_get_extra_chain_certs_only(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,1,px509) +# define SSL_CTX_clear_extra_chain_certs(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL) +# define SSL_CTX_set0_chain(ctx,sk) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk)) +# define SSL_CTX_set1_chain(ctx,sk) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,1,(char *)(sk)) +# define SSL_CTX_add0_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,0,(char *)(x509)) +# define SSL_CTX_add1_chain_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN_CERT,1,(char *)(x509)) +# define SSL_CTX_get0_chain_certs(ctx,px509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_CHAIN_CERTS,0,px509) +# define SSL_CTX_clear_chain_certs(ctx) \ + SSL_CTX_set0_chain(ctx,NULL) +# define SSL_CTX_build_cert_chain(ctx, flags) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +# define SSL_CTX_select_current_cert(ctx,x509) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509)) +# define SSL_CTX_set_current_cert(ctx, op) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CURRENT_CERT, op, NULL) +# define SSL_CTX_set0_verify_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st)) +# define SSL_CTX_set1_verify_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st)) +# define SSL_CTX_set0_chain_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st)) +# define SSL_CTX_set1_chain_cert_store(ctx,st) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st)) +# define SSL_set0_chain(s,sk) \ + SSL_ctrl(s,SSL_CTRL_CHAIN,0,(char *)(sk)) +# define SSL_set1_chain(s,sk) \ + SSL_ctrl(s,SSL_CTRL_CHAIN,1,(char *)(sk)) +# define SSL_add0_chain_cert(s,x509) \ + SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,0,(char *)(x509)) +# define SSL_add1_chain_cert(s,x509) \ + SSL_ctrl(s,SSL_CTRL_CHAIN_CERT,1,(char *)(x509)) +# define SSL_get0_chain_certs(s,px509) \ + SSL_ctrl(s,SSL_CTRL_GET_CHAIN_CERTS,0,px509) +# define SSL_clear_chain_certs(s) \ + SSL_set0_chain(s,NULL) +# define SSL_build_cert_chain(s, flags) \ + SSL_ctrl(s,SSL_CTRL_BUILD_CERT_CHAIN, flags, NULL) +# define SSL_select_current_cert(s,x509) \ + SSL_ctrl(s,SSL_CTRL_SELECT_CURRENT_CERT,0,(char *)(x509)) +# define SSL_set_current_cert(s,op) \ + SSL_ctrl(s,SSL_CTRL_SET_CURRENT_CERT, op, NULL) +# define SSL_set0_verify_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,0,(char *)(st)) +# define SSL_set1_verify_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_VERIFY_CERT_STORE,1,(char *)(st)) +# define SSL_set0_chain_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,0,(char *)(st)) +# define SSL_set1_chain_cert_store(s,st) \ + SSL_ctrl(s,SSL_CTRL_SET_CHAIN_CERT_STORE,1,(char *)(st)) +# define SSL_get1_groups(s, glist) \ + SSL_ctrl(s,SSL_CTRL_GET_GROUPS,0,(int*)(glist)) +# define SSL_CTX_set1_groups(ctx, glist, glistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist)) +# define SSL_CTX_set1_groups_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(s)) +# define SSL_set1_groups(s, glist, glistlen) \ + SSL_ctrl(s,SSL_CTRL_SET_GROUPS,glistlen,(char *)(glist)) +# define SSL_set1_groups_list(s, str) \ + SSL_ctrl(s,SSL_CTRL_SET_GROUPS_LIST,0,(char *)(str)) +# define SSL_get_shared_group(s, n) \ + SSL_ctrl(s,SSL_CTRL_GET_SHARED_GROUP,n,NULL) +# define SSL_CTX_set1_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist)) +# define SSL_CTX_set1_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(s)) +# define SSL_set1_sigalgs(s, slist, slistlen) \ + SSL_ctrl(s,SSL_CTRL_SET_SIGALGS,slistlen,(int *)(slist)) +# define SSL_set1_sigalgs_list(s, str) \ + SSL_ctrl(s,SSL_CTRL_SET_SIGALGS_LIST,0,(char *)(str)) +# define SSL_CTX_set1_client_sigalgs(ctx, slist, slistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist)) +# define SSL_CTX_set1_client_sigalgs_list(ctx, s) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(s)) +# define SSL_set1_client_sigalgs(s, slist, slistlen) \ + SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS,slistlen,(int *)(slist)) +# define SSL_set1_client_sigalgs_list(s, str) \ + SSL_ctrl(s,SSL_CTRL_SET_CLIENT_SIGALGS_LIST,0,(char *)(str)) +# define SSL_get0_certificate_types(s, clist) \ + SSL_ctrl(s, SSL_CTRL_GET_CLIENT_CERT_TYPES, 0, (char *)(clist)) +# define SSL_CTX_set1_client_certificate_types(ctx, clist, clistlen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen, \ + (char *)(clist)) +# define SSL_set1_client_certificate_types(s, clist, clistlen) \ + SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist)) +# define SSL_get_signature_nid(s, pn) \ + SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn) +# define SSL_get_peer_signature_nid(s, pn) \ + SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn) +# define SSL_get_peer_tmp_key(s, pk) \ + SSL_ctrl(s,SSL_CTRL_GET_PEER_TMP_KEY,0,pk) +# define SSL_get_tmp_key(s, pk) \ + SSL_ctrl(s,SSL_CTRL_GET_TMP_KEY,0,pk) +# define SSL_get0_raw_cipherlist(s, plst) \ + SSL_ctrl(s,SSL_CTRL_GET_RAW_CIPHERLIST,0,plst) +# define SSL_get0_ec_point_formats(s, plst) \ + SSL_ctrl(s,SSL_CTRL_GET_EC_POINT_FORMATS,0,plst) +# define SSL_CTX_set_min_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +# define SSL_CTX_set_max_proto_version(ctx, version) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) +# define SSL_CTX_get_min_proto_version(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) +# define SSL_CTX_get_max_proto_version(ctx) \ + SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) +# define SSL_set_min_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL) +# define SSL_set_max_proto_version(s, version) \ + SSL_ctrl(s, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL) +# define SSL_get_min_proto_version(s) \ + SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, NULL) +# define SSL_get_max_proto_version(s) \ + SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, NULL) + +/* Backwards compatibility, original 1.1.0 names */ +# define SSL_CTRL_GET_SERVER_TMP_KEY \ + SSL_CTRL_GET_PEER_TMP_KEY +# define SSL_get_server_tmp_key(s, pk) \ + SSL_get_peer_tmp_key(s, pk) + +/* + * The following symbol names are old and obsolete. They are kept + * for compatibility reasons only and should not be used anymore. + */ +# define SSL_CTRL_GET_CURVES SSL_CTRL_GET_GROUPS +# define SSL_CTRL_SET_CURVES SSL_CTRL_SET_GROUPS +# define SSL_CTRL_SET_CURVES_LIST SSL_CTRL_SET_GROUPS_LIST +# define SSL_CTRL_GET_SHARED_CURVE SSL_CTRL_GET_SHARED_GROUP + +# define SSL_get1_curves SSL_get1_groups +# define SSL_CTX_set1_curves SSL_CTX_set1_groups +# define SSL_CTX_set1_curves_list SSL_CTX_set1_groups_list +# define SSL_set1_curves SSL_set1_groups +# define SSL_set1_curves_list SSL_set1_groups_list +# define SSL_get_shared_curve SSL_get_shared_group + + +# if OPENSSL_API_COMPAT < 0x10100000L +/* Provide some compatibility macros for removed functionality. */ +# define SSL_CTX_need_tmp_RSA(ctx) 0 +# define SSL_CTX_set_tmp_rsa(ctx,rsa) 1 +# define SSL_need_tmp_RSA(ssl) 0 +# define SSL_set_tmp_rsa(ssl,rsa) 1 +# define SSL_CTX_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +# define SSL_set_ecdh_auto(dummy, onoff) ((onoff) != 0) +/* + * We "pretend" to call the callback to avoid warnings about unused static + * functions. + */ +# define SSL_CTX_set_tmp_rsa_callback(ctx, cb) while(0) (cb)(NULL, 0, 0) +# define SSL_set_tmp_rsa_callback(ssl, cb) while(0) (cb)(NULL, 0, 0) +# endif +__owur const BIO_METHOD *BIO_f_ssl(void); +__owur BIO *BIO_new_ssl(SSL_CTX *ctx, int client); +__owur BIO *BIO_new_ssl_connect(SSL_CTX *ctx); +__owur BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); +__owur int BIO_ssl_copy_session_id(BIO *to, BIO *from); +void BIO_ssl_shutdown(BIO *ssl_bio); + +__owur int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str); +__owur SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth); +int SSL_CTX_up_ref(SSL_CTX *ctx); +void SSL_CTX_free(SSL_CTX *); +__owur long SSL_CTX_set_timeout(SSL_CTX *ctx, long t); +__owur long SSL_CTX_get_timeout(const SSL_CTX *ctx); +__owur X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *); +void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *); +void SSL_CTX_set1_cert_store(SSL_CTX *, X509_STORE *); +__owur int SSL_want(const SSL *s); +__owur int SSL_clear(SSL *s); + +void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm); + +__owur const SSL_CIPHER *SSL_get_current_cipher(const SSL *s); +__owur const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s); +__owur int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits); +__owur const char *SSL_CIPHER_get_version(const SSL_CIPHER *c); +__owur const char *SSL_CIPHER_get_name(const SSL_CIPHER *c); +__owur const char *SSL_CIPHER_standard_name(const SSL_CIPHER *c); +__owur const char *OPENSSL_cipher_name(const char *rfc_name); +__owur uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *c); +__owur uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *c); +__owur int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c); +__owur int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c); +__owur const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c); +__owur int SSL_CIPHER_is_aead(const SSL_CIPHER *c); + +__owur int SSL_get_fd(const SSL *s); +__owur int SSL_get_rfd(const SSL *s); +__owur int SSL_get_wfd(const SSL *s); +__owur const char *SSL_get_cipher_list(const SSL *s, int n); +__owur char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size); +__owur int SSL_get_read_ahead(const SSL *s); +__owur int SSL_pending(const SSL *s); +__owur int SSL_has_pending(const SSL *s); +# ifndef OPENSSL_NO_SOCK +__owur int SSL_set_fd(SSL *s, int fd); +__owur int SSL_set_rfd(SSL *s, int fd); +__owur int SSL_set_wfd(SSL *s, int fd); +# endif +void SSL_set0_rbio(SSL *s, BIO *rbio); +void SSL_set0_wbio(SSL *s, BIO *wbio); +void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio); +__owur BIO *SSL_get_rbio(const SSL *s); +__owur BIO *SSL_get_wbio(const SSL *s); +__owur int SSL_set_cipher_list(SSL *s, const char *str); +__owur int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str); +__owur int SSL_set_ciphersuites(SSL *s, const char *str); +void SSL_set_read_ahead(SSL *s, int yes); +__owur int SSL_get_verify_mode(const SSL *s); +__owur int SSL_get_verify_depth(const SSL *s); +__owur SSL_verify_cb SSL_get_verify_callback(const SSL *s); +void SSL_set_verify(SSL *s, int mode, SSL_verify_cb callback); +void SSL_set_verify_depth(SSL *s, int depth); +void SSL_set_cert_cb(SSL *s, int (*cb) (SSL *ssl, void *arg), void *arg); +# ifndef OPENSSL_NO_RSA +__owur int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); +__owur int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, + long len); +# endif +__owur int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); +__owur int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, + long len); +__owur int SSL_use_certificate(SSL *ssl, X509 *x); +__owur int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); +__owur int SSL_use_cert_and_key(SSL *ssl, X509 *x509, EVP_PKEY *privatekey, + STACK_OF(X509) *chain, int override); + + +/* serverinfo file format versions */ +# define SSL_SERVERINFOV1 1 +# define SSL_SERVERINFOV2 2 + +/* Set serverinfo data for the current active cert. */ +__owur int SSL_CTX_use_serverinfo(SSL_CTX *ctx, const unsigned char *serverinfo, + size_t serverinfo_length); +__owur int SSL_CTX_use_serverinfo_ex(SSL_CTX *ctx, unsigned int version, + const unsigned char *serverinfo, + size_t serverinfo_length); +__owur int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file); + +#ifndef OPENSSL_NO_RSA +__owur int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); +#endif + +__owur int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); +__owur int SSL_use_certificate_file(SSL *ssl, const char *file, int type); + +#ifndef OPENSSL_NO_RSA +__owur int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, + int type); +#endif +__owur int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, + int type); +__owur int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, + int type); +/* PEM type */ +__owur int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); +__owur int SSL_use_certificate_chain_file(SSL *ssl, const char *file); +__owur STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); +__owur int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *file); +int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, + const char *dir); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_load_error_strings() \ + OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS \ + | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) +# endif + +__owur const char *SSL_state_string(const SSL *s); +__owur const char *SSL_rstate_string(const SSL *s); +__owur const char *SSL_state_string_long(const SSL *s); +__owur const char *SSL_rstate_string_long(const SSL *s); +__owur long SSL_SESSION_get_time(const SSL_SESSION *s); +__owur long SSL_SESSION_set_time(SSL_SESSION *s, long t); +__owur long SSL_SESSION_get_timeout(const SSL_SESSION *s); +__owur long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); +__owur int SSL_SESSION_get_protocol_version(const SSL_SESSION *s); +__owur int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version); + +__owur const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s); +__owur int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname); +void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s, + const unsigned char **alpn, + size_t *len); +__owur int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s, + const unsigned char *alpn, + size_t len); +__owur const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s); +__owur int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher); +__owur int SSL_SESSION_has_ticket(const SSL_SESSION *s); +__owur unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s); +void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick, + size_t *len); +__owur uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s); +__owur int SSL_SESSION_set_max_early_data(SSL_SESSION *s, + uint32_t max_early_data); +__owur int SSL_copy_session_id(SSL *to, const SSL *from); +__owur X509 *SSL_SESSION_get0_peer(SSL_SESSION *s); +__owur int SSL_SESSION_set1_id_context(SSL_SESSION *s, + const unsigned char *sid_ctx, + unsigned int sid_ctx_len); +__owur int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, + unsigned int sid_len); +__owur int SSL_SESSION_is_resumable(const SSL_SESSION *s); + +__owur SSL_SESSION *SSL_SESSION_new(void); +__owur SSL_SESSION *SSL_SESSION_dup(SSL_SESSION *src); +const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, + unsigned int *len); +const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s, + unsigned int *len); +__owur unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s); +# ifndef OPENSSL_NO_STDIO +int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses); +# endif +int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses); +int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x); +int SSL_SESSION_up_ref(SSL_SESSION *ses); +void SSL_SESSION_free(SSL_SESSION *ses); +__owur int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp); +__owur int SSL_set_session(SSL *to, SSL_SESSION *session); +int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session); +int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session); +__owur int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb); +__owur int SSL_set_generate_session_id(SSL *s, GEN_SESSION_CB cb); +__owur int SSL_has_matching_session_id(const SSL *s, + const unsigned char *id, + unsigned int id_len); +SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, + long length); + +# ifdef HEADER_X509_H +__owur X509 *SSL_get_peer_certificate(const SSL *s); +# endif + +__owur STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s); + +__owur int SSL_CTX_get_verify_mode(const SSL_CTX *ctx); +__owur int SSL_CTX_get_verify_depth(const SSL_CTX *ctx); +__owur SSL_verify_cb SSL_CTX_get_verify_callback(const SSL_CTX *ctx); +void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, SSL_verify_cb callback); +void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth); +void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, + int (*cb) (X509_STORE_CTX *, void *), + void *arg); +void SSL_CTX_set_cert_cb(SSL_CTX *c, int (*cb) (SSL *ssl, void *arg), + void *arg); +# ifndef OPENSSL_NO_RSA +__owur int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); +__owur int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, + long len); +# endif +__owur int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); +__owur int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, + const unsigned char *d, long len); +__owur int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); +__owur int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, + const unsigned char *d); +__owur int SSL_CTX_use_cert_and_key(SSL_CTX *ctx, X509 *x509, EVP_PKEY *privatekey, + STACK_OF(X509) *chain, int override); + +void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); +void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); +pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx); +void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx); +void SSL_set_default_passwd_cb(SSL *s, pem_password_cb *cb); +void SSL_set_default_passwd_cb_userdata(SSL *s, void *u); +pem_password_cb *SSL_get_default_passwd_cb(SSL *s); +void *SSL_get_default_passwd_cb_userdata(SSL *s); + +__owur int SSL_CTX_check_private_key(const SSL_CTX *ctx); +__owur int SSL_check_private_key(const SSL *ctx); + +__owur int SSL_CTX_set_session_id_context(SSL_CTX *ctx, + const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +SSL *SSL_new(SSL_CTX *ctx); +int SSL_up_ref(SSL *s); +int SSL_is_dtls(const SSL *s); +__owur int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx, + unsigned int sid_ctx_len); + +__owur int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose); +__owur int SSL_set_purpose(SSL *ssl, int purpose); +__owur int SSL_CTX_set_trust(SSL_CTX *ctx, int trust); +__owur int SSL_set_trust(SSL *ssl, int trust); + +__owur int SSL_set1_host(SSL *s, const char *hostname); +__owur int SSL_add1_host(SSL *s, const char *hostname); +__owur const char *SSL_get0_peername(SSL *s); +void SSL_set_hostflags(SSL *s, unsigned int flags); + +__owur int SSL_CTX_dane_enable(SSL_CTX *ctx); +__owur int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md, + uint8_t mtype, uint8_t ord); +__owur int SSL_dane_enable(SSL *s, const char *basedomain); +__owur int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector, + uint8_t mtype, unsigned const char *data, size_t dlen); +__owur int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki); +__owur int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector, + uint8_t *mtype, unsigned const char **data, + size_t *dlen); +/* + * Bridge opacity barrier between libcrypt and libssl, also needed to support + * offline testing in test/danetest.c + */ +SSL_DANE *SSL_get0_dane(SSL *ssl); +/* + * DANE flags + */ +unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags); +unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags); +unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags); +unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags); + +__owur int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm); +__owur int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm); + +__owur X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx); +__owur X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl); + +# ifndef OPENSSL_NO_SRP +int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name); +int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password); +int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength); +int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx, + char *(*cb) (SSL *, void *)); +int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx, + int (*cb) (SSL *, void *)); +int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx, + int (*cb) (SSL *, int *, void *)); +int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg); + +int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g, + BIGNUM *sa, BIGNUM *v, char *info); +int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass, + const char *grp); + +__owur BIGNUM *SSL_get_srp_g(SSL *s); +__owur BIGNUM *SSL_get_srp_N(SSL *s); + +__owur char *SSL_get_srp_username(SSL *s); +__owur char *SSL_get_srp_userinfo(SSL *s); +# endif + +/* + * ClientHello callback and helpers. + */ + +# define SSL_CLIENT_HELLO_SUCCESS 1 +# define SSL_CLIENT_HELLO_ERROR 0 +# define SSL_CLIENT_HELLO_RETRY (-1) + +typedef int (*SSL_client_hello_cb_fn) (SSL *s, int *al, void *arg); +void SSL_CTX_set_client_hello_cb(SSL_CTX *c, SSL_client_hello_cb_fn cb, + void *arg); +int SSL_client_hello_isv2(SSL *s); +unsigned int SSL_client_hello_get0_legacy_version(SSL *s); +size_t SSL_client_hello_get0_random(SSL *s, const unsigned char **out); +size_t SSL_client_hello_get0_session_id(SSL *s, const unsigned char **out); +size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out); +size_t SSL_client_hello_get0_compression_methods(SSL *s, + const unsigned char **out); +int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen); +int SSL_client_hello_get0_ext(SSL *s, unsigned int type, + const unsigned char **out, size_t *outlen); + +void SSL_certs_clear(SSL *s); +void SSL_free(SSL *ssl); +# ifdef OSSL_ASYNC_FD +/* + * Windows application developer has to include windows.h to use these. + */ +__owur int SSL_waiting_for_async(SSL *s); +__owur int SSL_get_all_async_fds(SSL *s, OSSL_ASYNC_FD *fds, size_t *numfds); +__owur int SSL_get_changed_async_fds(SSL *s, OSSL_ASYNC_FD *addfd, + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds); +# endif +__owur int SSL_accept(SSL *ssl); +__owur int SSL_stateless(SSL *s); +__owur int SSL_connect(SSL *ssl); +__owur int SSL_read(SSL *ssl, void *buf, int num); +__owur int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes); + +# define SSL_READ_EARLY_DATA_ERROR 0 +# define SSL_READ_EARLY_DATA_SUCCESS 1 +# define SSL_READ_EARLY_DATA_FINISH 2 + +__owur int SSL_read_early_data(SSL *s, void *buf, size_t num, + size_t *readbytes); +__owur int SSL_peek(SSL *ssl, void *buf, int num); +__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes); +__owur int SSL_write(SSL *ssl, const void *buf, int num); +__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written); +__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num, + size_t *written); +long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg); +long SSL_callback_ctrl(SSL *, int, void (*)(void)); +long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg); +long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void)); + +# define SSL_EARLY_DATA_NOT_SENT 0 +# define SSL_EARLY_DATA_REJECTED 1 +# define SSL_EARLY_DATA_ACCEPTED 2 + +__owur int SSL_get_early_data_status(const SSL *s); + +__owur int SSL_get_error(const SSL *s, int ret_code); +__owur const char *SSL_get_version(const SSL *s); + +/* This sets the 'default' SSL version that SSL_new() will create */ +__owur int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth); + +# ifndef OPENSSL_NO_SSL3_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_method(void)) /* SSLv3 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *SSLv3_client_method(void)) +# endif + +#define SSLv23_method TLS_method +#define SSLv23_server_method TLS_server_method +#define SSLv23_client_method TLS_client_method + +/* Negotiate highest available SSL/TLS version */ +__owur const SSL_METHOD *TLS_method(void); +__owur const SSL_METHOD *TLS_server_method(void); +__owur const SSL_METHOD *TLS_client_method(void); + +# ifndef OPENSSL_NO_TLS1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_method(void)) /* TLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_client_method(void)) +# endif + +# ifndef OPENSSL_NO_TLS1_1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_method(void)) /* TLSv1.1 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_client_method(void)) +# endif + +# ifndef OPENSSL_NO_TLS1_2_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_client_method(void)) +# endif + +# ifndef OPENSSL_NO_DTLS1_METHOD +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_method(void)) /* DTLSv1.0 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_client_method(void)) +# endif + +# ifndef OPENSSL_NO_DTLS1_2_METHOD +/* DTLSv1.2 */ +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_server_method(void)) +DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *DTLSv1_2_client_method(void)) +# endif + +__owur const SSL_METHOD *DTLS_method(void); /* DTLS 1.0 and 1.2 */ +__owur const SSL_METHOD *DTLS_server_method(void); /* DTLS 1.0 and 1.2 */ +__owur const SSL_METHOD *DTLS_client_method(void); /* DTLS 1.0 and 1.2 */ + +__owur size_t DTLS_get_data_mtu(const SSL *s); + +__owur STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); +__owur STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx); +__owur STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s); +__owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s); + +__owur int SSL_do_handshake(SSL *s); +int SSL_key_update(SSL *s, int updatetype); +int SSL_get_key_update_type(const SSL *s); +int SSL_renegotiate(SSL *s); +int SSL_renegotiate_abbreviated(SSL *s); +__owur int SSL_renegotiate_pending(const SSL *s); +int SSL_shutdown(SSL *s); +__owur int SSL_verify_client_post_handshake(SSL *s); +void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val); +void SSL_set_post_handshake_auth(SSL *s, int val); + +__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx); +__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s); +__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method); +__owur const char *SSL_alert_type_string_long(int value); +__owur const char *SSL_alert_type_string(int value); +__owur const char *SSL_alert_desc_string_long(int value); +__owur const char *SSL_alert_desc_string(int value); + +void SSL_set0_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list); +void SSL_CTX_set0_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list); +__owur const STACK_OF(X509_NAME) *SSL_get0_CA_list(const SSL *s); +__owur const STACK_OF(X509_NAME) *SSL_CTX_get0_CA_list(const SSL_CTX *ctx); +__owur int SSL_add1_to_CA_list(SSL *ssl, const X509 *x); +__owur int SSL_CTX_add1_to_CA_list(SSL_CTX *ctx, const X509 *x); +__owur const STACK_OF(X509_NAME) *SSL_get0_peer_CA_list(const SSL *s); + +void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list); +void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list); +__owur STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s); +__owur STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s); +__owur int SSL_add_client_CA(SSL *ssl, X509 *x); +__owur int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x); + +void SSL_set_connect_state(SSL *s); +void SSL_set_accept_state(SSL *s); + +__owur long SSL_get_default_timeout(const SSL *s); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_library_init() OPENSSL_init_ssl(0, NULL) +# endif + +__owur char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size); +__owur STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk); + +__owur SSL *SSL_dup(SSL *ssl); + +__owur X509 *SSL_get_certificate(const SSL *ssl); +/* + * EVP_PKEY + */ +struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl); + +__owur X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx); +__owur EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx); + +void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode); +__owur int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx); +void SSL_set_quiet_shutdown(SSL *ssl, int mode); +__owur int SSL_get_quiet_shutdown(const SSL *ssl); +void SSL_set_shutdown(SSL *ssl, int mode); +__owur int SSL_get_shutdown(const SSL *ssl); +__owur int SSL_version(const SSL *ssl); +__owur int SSL_client_version(const SSL *s); +__owur int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); +__owur int SSL_CTX_set_default_verify_dir(SSL_CTX *ctx); +__owur int SSL_CTX_set_default_verify_file(SSL_CTX *ctx); +__owur int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, + const char *CApath); +# define SSL_get0_session SSL_get_session/* just peek at pointer */ +__owur SSL_SESSION *SSL_get_session(const SSL *ssl); +__owur SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ +__owur SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); +SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx); +void SSL_set_info_callback(SSL *ssl, + void (*cb) (const SSL *ssl, int type, int val)); +void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, + int val); +__owur OSSL_HANDSHAKE_STATE SSL_get_state(const SSL *ssl); + +void SSL_set_verify_result(SSL *ssl, long v); +__owur long SSL_get_verify_result(const SSL *ssl); +__owur STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s); + +__owur size_t SSL_get_client_random(const SSL *ssl, unsigned char *out, + size_t outlen); +__owur size_t SSL_get_server_random(const SSL *ssl, unsigned char *out, + size_t outlen); +__owur size_t SSL_SESSION_get_master_key(const SSL_SESSION *sess, + unsigned char *out, size_t outlen); +__owur int SSL_SESSION_set1_master_key(SSL_SESSION *sess, + const unsigned char *in, size_t len); +uint8_t SSL_SESSION_get_max_fragment_length(const SSL_SESSION *sess); + +#define SSL_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef) +__owur int SSL_set_ex_data(SSL *ssl, int idx, void *data); +void *SSL_get_ex_data(const SSL *ssl, int idx); +#define SSL_SESSION_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, l, p, newf, dupf, freef) +__owur int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data); +void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx); +#define SSL_CTX_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef) +__owur int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data); +void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx); + +__owur int SSL_get_ex_data_X509_STORE_CTX_idx(void); + +# define SSL_CTX_sess_set_cache_size(ctx,t) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) +# define SSL_CTX_sess_get_cache_size(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) +# define SSL_CTX_set_session_cache_mode(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) +# define SSL_CTX_get_session_cache_mode(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) + +# define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) +# define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) +# define SSL_CTX_get_read_ahead(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) +# define SSL_CTX_set_read_ahead(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL) +# define SSL_CTX_get_max_cert_list(ctx) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +# define SSL_CTX_set_max_cert_list(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) +# define SSL_get_max_cert_list(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) +# define SSL_set_max_cert_list(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) + +# define SSL_CTX_set_max_send_fragment(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) +# define SSL_set_max_send_fragment(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL) +# define SSL_CTX_set_split_send_fragment(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) +# define SSL_set_split_send_fragment(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_SPLIT_SEND_FRAGMENT,m,NULL) +# define SSL_CTX_set_max_pipelines(ctx,m) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) +# define SSL_set_max_pipelines(ssl,m) \ + SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL) + +void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len); +void SSL_set_default_read_buffer_len(SSL *s, size_t len); + +# ifndef OPENSSL_NO_DH +/* NB: the |keylength| is only applicable when is_export is true */ +void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, + DH *(*dh) (SSL *ssl, int is_export, + int keylength)); +void SSL_set_tmp_dh_callback(SSL *ssl, + DH *(*dh) (SSL *ssl, int is_export, + int keylength)); +# endif + +__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s); +__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s); +__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp); +__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp); +__owur int SSL_COMP_get_id(const SSL_COMP *comp); +STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); +__owur STACK_OF(SSL_COMP) *SSL_COMP_set0_compression_methods(STACK_OF(SSL_COMP) + *meths); +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_COMP_free_compression_methods() while(0) continue +# endif +__owur int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm); + +const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr); +int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c); +int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c); +int SSL_bytes_to_cipher_list(SSL *s, const unsigned char *bytes, size_t len, + int isv2format, STACK_OF(SSL_CIPHER) **sk, + STACK_OF(SSL_CIPHER) **scsvs); + +/* TLS extensions functions */ +__owur int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len); + +__owur int SSL_set_session_ticket_ext_cb(SSL *s, + tls_session_ticket_ext_cb_fn cb, + void *arg); + +/* Pre-shared secret session resumption functions */ +__owur int SSL_set_session_secret_cb(SSL *s, + tls_session_secret_cb_fn session_secret_cb, + void *arg); + +void SSL_CTX_set_not_resumable_session_callback(SSL_CTX *ctx, + int (*cb) (SSL *ssl, + int + is_forward_secure)); + +void SSL_set_not_resumable_session_callback(SSL *ssl, + int (*cb) (SSL *ssl, + int is_forward_secure)); + +void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx, + size_t (*cb) (SSL *ssl, int type, + size_t len, void *arg)); +void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg); +void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx); +int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size); + +void SSL_set_record_padding_callback(SSL *ssl, + size_t (*cb) (SSL *ssl, int type, + size_t len, void *arg)); +void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg); +void *SSL_get_record_padding_callback_arg(const SSL *ssl); +int SSL_set_block_padding(SSL *ssl, size_t block_size); + +int SSL_set_num_tickets(SSL *s, size_t num_tickets); +size_t SSL_get_num_tickets(const SSL *s); +int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); +size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_cache_hit(s) SSL_session_reused(s) +# endif + +__owur int SSL_session_reused(const SSL *s); +__owur int SSL_is_server(const SSL *s); + +__owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void); +int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx); +void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx); +unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags); +__owur unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx, + unsigned int flags); +__owur int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre); + +void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl); +void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx); + +__owur int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value); +__owur int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv); +__owur int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd); + +void SSL_add_ssl_module(void); +int SSL_config(SSL *s, const char *name); +int SSL_CTX_config(SSL_CTX *ctx, const char *name); + +# ifndef OPENSSL_NO_SSL_TRACE +void SSL_trace(int write_p, int version, int content_type, + const void *buf, size_t len, SSL *ssl, void *arg); +# endif + +# ifndef OPENSSL_NO_SOCK +int DTLSv1_listen(SSL *s, BIO_ADDR *client); +# endif + +# ifndef OPENSSL_NO_CT + +/* + * A callback for verifying that the received SCTs are sufficient. + * Expected to return 1 if they are sufficient, otherwise 0. + * May return a negative integer if an error occurs. + * A connection should be aborted if the SCTs are deemed insufficient. + */ +typedef int (*ssl_ct_validation_cb)(const CT_POLICY_EVAL_CTX *ctx, + const STACK_OF(SCT) *scts, void *arg); + +/* + * Sets a |callback| that is invoked upon receipt of ServerHelloDone to validate + * the received SCTs. + * If the callback returns a non-positive result, the connection is terminated. + * Call this function before beginning a handshake. + * If a NULL |callback| is provided, SCT validation is disabled. + * |arg| is arbitrary userdata that will be passed to the callback whenever it + * is invoked. Ownership of |arg| remains with the caller. + * + * NOTE: A side-effect of setting a CT callback is that an OCSP stapled response + * will be requested. + */ +int SSL_set_ct_validation_callback(SSL *s, ssl_ct_validation_cb callback, + void *arg); +int SSL_CTX_set_ct_validation_callback(SSL_CTX *ctx, + ssl_ct_validation_cb callback, + void *arg); +#define SSL_disable_ct(s) \ + ((void) SSL_set_validation_callback((s), NULL, NULL)) +#define SSL_CTX_disable_ct(ctx) \ + ((void) SSL_CTX_set_validation_callback((ctx), NULL, NULL)) + +/* + * The validation type enumerates the available behaviours of the built-in SSL + * CT validation callback selected via SSL_enable_ct() and SSL_CTX_enable_ct(). + * The underlying callback is a static function in libssl. + */ +enum { + SSL_CT_VALIDATION_PERMISSIVE = 0, + SSL_CT_VALIDATION_STRICT +}; + +/* + * Enable CT by setting up a callback that implements one of the built-in + * validation variants. The SSL_CT_VALIDATION_PERMISSIVE variant always + * continues the handshake, the application can make appropriate decisions at + * handshake completion. The SSL_CT_VALIDATION_STRICT variant requires at + * least one valid SCT, or else handshake termination will be requested. The + * handshake may continue anyway if SSL_VERIFY_NONE is in effect. + */ +int SSL_enable_ct(SSL *s, int validation_mode); +int SSL_CTX_enable_ct(SSL_CTX *ctx, int validation_mode); + +/* + * Report whether a non-NULL callback is enabled. + */ +int SSL_ct_is_enabled(const SSL *s); +int SSL_CTX_ct_is_enabled(const SSL_CTX *ctx); + +/* Gets the SCTs received from a connection */ +const STACK_OF(SCT) *SSL_get0_peer_scts(SSL *s); + +/* + * Loads the CT log list from the default location. + * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store, + * the log information loaded from this file will be appended to the + * CTLOG_STORE. + * Returns 1 on success, 0 otherwise. + */ +int SSL_CTX_set_default_ctlog_list_file(SSL_CTX *ctx); + +/* + * Loads the CT log list from the specified file path. + * If a CTLOG_STORE has previously been set using SSL_CTX_set_ctlog_store, + * the log information loaded from this file will be appended to the + * CTLOG_STORE. + * Returns 1 on success, 0 otherwise. + */ +int SSL_CTX_set_ctlog_list_file(SSL_CTX *ctx, const char *path); + +/* + * Sets the CT log list used by all SSL connections created from this SSL_CTX. + * Ownership of the CTLOG_STORE is transferred to the SSL_CTX. + */ +void SSL_CTX_set0_ctlog_store(SSL_CTX *ctx, CTLOG_STORE *logs); + +/* + * Gets the CT log list used by all SSL connections created from this SSL_CTX. + * This will be NULL unless one of the following functions has been called: + * - SSL_CTX_set_default_ctlog_list_file + * - SSL_CTX_set_ctlog_list_file + * - SSL_CTX_set_ctlog_store + */ +const CTLOG_STORE *SSL_CTX_get0_ctlog_store(const SSL_CTX *ctx); + +# endif /* OPENSSL_NO_CT */ + +/* What the "other" parameter contains in security callback */ +/* Mask for type */ +# define SSL_SECOP_OTHER_TYPE 0xffff0000 +# define SSL_SECOP_OTHER_NONE 0 +# define SSL_SECOP_OTHER_CIPHER (1 << 16) +# define SSL_SECOP_OTHER_CURVE (2 << 16) +# define SSL_SECOP_OTHER_DH (3 << 16) +# define SSL_SECOP_OTHER_PKEY (4 << 16) +# define SSL_SECOP_OTHER_SIGALG (5 << 16) +# define SSL_SECOP_OTHER_CERT (6 << 16) + +/* Indicated operation refers to peer key or certificate */ +# define SSL_SECOP_PEER 0x1000 + +/* Values for "op" parameter in security callback */ + +/* Called to filter ciphers */ +/* Ciphers client supports */ +# define SSL_SECOP_CIPHER_SUPPORTED (1 | SSL_SECOP_OTHER_CIPHER) +/* Cipher shared by client/server */ +# define SSL_SECOP_CIPHER_SHARED (2 | SSL_SECOP_OTHER_CIPHER) +/* Sanity check of cipher server selects */ +# define SSL_SECOP_CIPHER_CHECK (3 | SSL_SECOP_OTHER_CIPHER) +/* Curves supported by client */ +# define SSL_SECOP_CURVE_SUPPORTED (4 | SSL_SECOP_OTHER_CURVE) +/* Curves shared by client/server */ +# define SSL_SECOP_CURVE_SHARED (5 | SSL_SECOP_OTHER_CURVE) +/* Sanity check of curve server selects */ +# define SSL_SECOP_CURVE_CHECK (6 | SSL_SECOP_OTHER_CURVE) +/* Temporary DH key */ +# define SSL_SECOP_TMP_DH (7 | SSL_SECOP_OTHER_PKEY) +/* SSL/TLS version */ +# define SSL_SECOP_VERSION (9 | SSL_SECOP_OTHER_NONE) +/* Session tickets */ +# define SSL_SECOP_TICKET (10 | SSL_SECOP_OTHER_NONE) +/* Supported signature algorithms sent to peer */ +# define SSL_SECOP_SIGALG_SUPPORTED (11 | SSL_SECOP_OTHER_SIGALG) +/* Shared signature algorithm */ +# define SSL_SECOP_SIGALG_SHARED (12 | SSL_SECOP_OTHER_SIGALG) +/* Sanity check signature algorithm allowed */ +# define SSL_SECOP_SIGALG_CHECK (13 | SSL_SECOP_OTHER_SIGALG) +/* Used to get mask of supported public key signature algorithms */ +# define SSL_SECOP_SIGALG_MASK (14 | SSL_SECOP_OTHER_SIGALG) +/* Use to see if compression is allowed */ +# define SSL_SECOP_COMPRESSION (15 | SSL_SECOP_OTHER_NONE) +/* EE key in certificate */ +# define SSL_SECOP_EE_KEY (16 | SSL_SECOP_OTHER_CERT) +/* CA key in certificate */ +# define SSL_SECOP_CA_KEY (17 | SSL_SECOP_OTHER_CERT) +/* CA digest algorithm in certificate */ +# define SSL_SECOP_CA_MD (18 | SSL_SECOP_OTHER_CERT) +/* Peer EE key in certificate */ +# define SSL_SECOP_PEER_EE_KEY (SSL_SECOP_EE_KEY | SSL_SECOP_PEER) +/* Peer CA key in certificate */ +# define SSL_SECOP_PEER_CA_KEY (SSL_SECOP_CA_KEY | SSL_SECOP_PEER) +/* Peer CA digest algorithm in certificate */ +# define SSL_SECOP_PEER_CA_MD (SSL_SECOP_CA_MD | SSL_SECOP_PEER) + +void SSL_set_security_level(SSL *s, int level); +__owur int SSL_get_security_level(const SSL *s); +void SSL_set_security_callback(SSL *s, + int (*cb) (const SSL *s, const SSL_CTX *ctx, + int op, int bits, int nid, + void *other, void *ex)); +int (*SSL_get_security_callback(const SSL *s)) (const SSL *s, + const SSL_CTX *ctx, int op, + int bits, int nid, void *other, + void *ex); +void SSL_set0_security_ex_data(SSL *s, void *ex); +__owur void *SSL_get0_security_ex_data(const SSL *s); + +void SSL_CTX_set_security_level(SSL_CTX *ctx, int level); +__owur int SSL_CTX_get_security_level(const SSL_CTX *ctx); +void SSL_CTX_set_security_callback(SSL_CTX *ctx, + int (*cb) (const SSL *s, const SSL_CTX *ctx, + int op, int bits, int nid, + void *other, void *ex)); +int (*SSL_CTX_get_security_callback(const SSL_CTX *ctx)) (const SSL *s, + const SSL_CTX *ctx, + int op, int bits, + int nid, + void *other, + void *ex); +void SSL_CTX_set0_security_ex_data(SSL_CTX *ctx, void *ex); +__owur void *SSL_CTX_get0_security_ex_data(const SSL_CTX *ctx); + +/* OPENSSL_INIT flag 0x010000 reserved for internal use */ +# define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L +# define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L + +# define OPENSSL_INIT_SSL_DEFAULT \ + (OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS) + +int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); + +# ifndef OPENSSL_NO_UNIT_TEST +__owur const struct openssl_ssl_test_functions *SSL_test_functions(void); +# endif + +__owur int SSL_free_buffers(SSL *ssl); +__owur int SSL_alloc_buffers(SSL *ssl); + +/* Status codes passed to the decrypt session ticket callback. Some of these + * are for internal use only and are never passed to the callback. */ +typedef int SSL_TICKET_STATUS; + +/* Support for ticket appdata */ +/* fatal error, malloc failure */ +# define SSL_TICKET_FATAL_ERR_MALLOC 0 +/* fatal error, either from parsing or decrypting the ticket */ +# define SSL_TICKET_FATAL_ERR_OTHER 1 +/* No ticket present */ +# define SSL_TICKET_NONE 2 +/* Empty ticket present */ +# define SSL_TICKET_EMPTY 3 +/* the ticket couldn't be decrypted */ +# define SSL_TICKET_NO_DECRYPT 4 +/* a ticket was successfully decrypted */ +# define SSL_TICKET_SUCCESS 5 +/* same as above but the ticket needs to be renewed */ +# define SSL_TICKET_SUCCESS_RENEW 6 + +/* Return codes for the decrypt session ticket callback */ +typedef int SSL_TICKET_RETURN; + +/* An error occurred */ +#define SSL_TICKET_RETURN_ABORT 0 +/* Do not use the ticket, do not send a renewed ticket to the client */ +#define SSL_TICKET_RETURN_IGNORE 1 +/* Do not use the ticket, send a renewed ticket to the client */ +#define SSL_TICKET_RETURN_IGNORE_RENEW 2 +/* Use the ticket, do not send a renewed ticket to the client */ +#define SSL_TICKET_RETURN_USE 3 +/* Use the ticket, send a renewed ticket to the client */ +#define SSL_TICKET_RETURN_USE_RENEW 4 + +typedef int (*SSL_CTX_generate_session_ticket_fn)(SSL *s, void *arg); +typedef SSL_TICKET_RETURN (*SSL_CTX_decrypt_session_ticket_fn)(SSL *s, SSL_SESSION *ss, + const unsigned char *keyname, + size_t keyname_length, + SSL_TICKET_STATUS status, + void *arg); +int SSL_CTX_set_session_ticket_cb(SSL_CTX *ctx, + SSL_CTX_generate_session_ticket_fn gen_cb, + SSL_CTX_decrypt_session_ticket_fn dec_cb, + void *arg); +int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len); +int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len); + +extern const char SSL_version_str[]; + +typedef unsigned int (*DTLS_timer_cb)(SSL *s, unsigned int timer_us); + +void DTLS_set_timer_cb(SSL *s, DTLS_timer_cb cb); + + +typedef int (*SSL_allow_early_data_cb_fn)(SSL *s, void *arg); +void SSL_CTX_set_allow_early_data_cb(SSL_CTX *ctx, + SSL_allow_early_data_cb_fn cb, + void *arg); +void SSL_set_allow_early_data_cb(SSL *s, + SSL_allow_early_data_cb_fn cb, + void *arg); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/stack.h postgresql-hll-2.14/include/openssl/stack.h --- postgresql-hll-2.14_old/include/openssl/stack.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/stack.h 2020-12-12 17:06:43.341349251 +0800 @@ -0,0 +1,83 @@ +/* + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_STACK_H +# define HEADER_STACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct stack_st OPENSSL_STACK; /* Use STACK_OF(...) instead */ + +typedef int (*OPENSSL_sk_compfunc)(const void *, const void *); +typedef void (*OPENSSL_sk_freefunc)(void *); +typedef void *(*OPENSSL_sk_copyfunc)(const void *); + +int OPENSSL_sk_num(const OPENSSL_STACK *); +void *OPENSSL_sk_value(const OPENSSL_STACK *, int); + +void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data); + +OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc cmp); +OPENSSL_STACK *OPENSSL_sk_new_null(void); +OPENSSL_STACK *OPENSSL_sk_new_reserve(OPENSSL_sk_compfunc c, int n); +int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n); +void OPENSSL_sk_free(OPENSSL_STACK *); +void OPENSSL_sk_pop_free(OPENSSL_STACK *st, void (*func) (void *)); +OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *, + OPENSSL_sk_copyfunc c, + OPENSSL_sk_freefunc f); +int OPENSSL_sk_insert(OPENSSL_STACK *sk, const void *data, int where); +void *OPENSSL_sk_delete(OPENSSL_STACK *st, int loc); +void *OPENSSL_sk_delete_ptr(OPENSSL_STACK *st, const void *p); +int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data); +int OPENSSL_sk_unshift(OPENSSL_STACK *st, const void *data); +void *OPENSSL_sk_shift(OPENSSL_STACK *st); +void *OPENSSL_sk_pop(OPENSSL_STACK *st); +void OPENSSL_sk_zero(OPENSSL_STACK *st); +OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, + OPENSSL_sk_compfunc cmp); +OPENSSL_STACK *OPENSSL_sk_dup(const OPENSSL_STACK *st); +void OPENSSL_sk_sort(OPENSSL_STACK *st); +int OPENSSL_sk_is_sorted(const OPENSSL_STACK *st); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define _STACK OPENSSL_STACK +# define sk_num OPENSSL_sk_num +# define sk_value OPENSSL_sk_value +# define sk_set OPENSSL_sk_set +# define sk_new OPENSSL_sk_new +# define sk_new_null OPENSSL_sk_new_null +# define sk_free OPENSSL_sk_free +# define sk_pop_free OPENSSL_sk_pop_free +# define sk_deep_copy OPENSSL_sk_deep_copy +# define sk_insert OPENSSL_sk_insert +# define sk_delete OPENSSL_sk_delete +# define sk_delete_ptr OPENSSL_sk_delete_ptr +# define sk_find OPENSSL_sk_find +# define sk_find_ex OPENSSL_sk_find_ex +# define sk_push OPENSSL_sk_push +# define sk_unshift OPENSSL_sk_unshift +# define sk_shift OPENSSL_sk_shift +# define sk_pop OPENSSL_sk_pop +# define sk_zero OPENSSL_sk_zero +# define sk_set_cmp_func OPENSSL_sk_set_cmp_func +# define sk_dup OPENSSL_sk_dup +# define sk_sort OPENSSL_sk_sort +# define sk_is_sorted OPENSSL_sk_is_sorted +# endif + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/storeerr.h postgresql-hll-2.14/include/openssl/storeerr.h --- postgresql-hll-2.14_old/include/openssl/storeerr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/storeerr.h 2020-12-12 17:06:43.341349251 +0800 @@ -0,0 +1,91 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OSSL_STOREERR_H +# define HEADER_OSSL_STOREERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_OSSL_STORE_strings(void); + +/* + * OSSL_STORE function codes. + */ +# define OSSL_STORE_F_FILE_CTRL 129 +# define OSSL_STORE_F_FILE_FIND 138 +# define OSSL_STORE_F_FILE_GET_PASS 118 +# define OSSL_STORE_F_FILE_LOAD 119 +# define OSSL_STORE_F_FILE_LOAD_TRY_DECODE 124 +# define OSSL_STORE_F_FILE_NAME_TO_URI 126 +# define OSSL_STORE_F_FILE_OPEN 120 +# define OSSL_STORE_F_OSSL_STORE_ATTACH_PEM_BIO 127 +# define OSSL_STORE_F_OSSL_STORE_EXPECT 130 +# define OSSL_STORE_F_OSSL_STORE_FILE_ATTACH_PEM_BIO_INT 128 +# define OSSL_STORE_F_OSSL_STORE_FIND 131 +# define OSSL_STORE_F_OSSL_STORE_GET0_LOADER_INT 100 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_CERT 101 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_CRL 102 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_NAME 103 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_NAME_DESCRIPTION 135 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_PARAMS 104 +# define OSSL_STORE_F_OSSL_STORE_INFO_GET1_PKEY 105 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_CERT 106 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_CRL 107 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_EMBEDDED 123 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_NAME 109 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_PARAMS 110 +# define OSSL_STORE_F_OSSL_STORE_INFO_NEW_PKEY 111 +# define OSSL_STORE_F_OSSL_STORE_INFO_SET0_NAME_DESCRIPTION 134 +# define OSSL_STORE_F_OSSL_STORE_INIT_ONCE 112 +# define OSSL_STORE_F_OSSL_STORE_LOADER_NEW 113 +# define OSSL_STORE_F_OSSL_STORE_OPEN 114 +# define OSSL_STORE_F_OSSL_STORE_OPEN_INT 115 +# define OSSL_STORE_F_OSSL_STORE_REGISTER_LOADER_INT 117 +# define OSSL_STORE_F_OSSL_STORE_SEARCH_BY_ALIAS 132 +# define OSSL_STORE_F_OSSL_STORE_SEARCH_BY_ISSUER_SERIAL 133 +# define OSSL_STORE_F_OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT 136 +# define OSSL_STORE_F_OSSL_STORE_SEARCH_BY_NAME 137 +# define OSSL_STORE_F_OSSL_STORE_UNREGISTER_LOADER_INT 116 +# define OSSL_STORE_F_TRY_DECODE_PARAMS 121 +# define OSSL_STORE_F_TRY_DECODE_PKCS12 122 +# define OSSL_STORE_F_TRY_DECODE_PKCS8ENCRYPTED 125 + +/* + * OSSL_STORE reason codes. + */ +# define OSSL_STORE_R_AMBIGUOUS_CONTENT_TYPE 107 +# define OSSL_STORE_R_BAD_PASSWORD_READ 115 +# define OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC 113 +# define OSSL_STORE_R_FINGERPRINT_SIZE_DOES_NOT_MATCH_DIGEST 121 +# define OSSL_STORE_R_INVALID_SCHEME 106 +# define OSSL_STORE_R_IS_NOT_A 112 +# define OSSL_STORE_R_LOADER_INCOMPLETE 116 +# define OSSL_STORE_R_LOADING_STARTED 117 +# define OSSL_STORE_R_NOT_A_CERTIFICATE 100 +# define OSSL_STORE_R_NOT_A_CRL 101 +# define OSSL_STORE_R_NOT_A_KEY 102 +# define OSSL_STORE_R_NOT_A_NAME 103 +# define OSSL_STORE_R_NOT_PARAMETERS 104 +# define OSSL_STORE_R_PASSPHRASE_CALLBACK_ERROR 114 +# define OSSL_STORE_R_PATH_MUST_BE_ABSOLUTE 108 +# define OSSL_STORE_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES 119 +# define OSSL_STORE_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED 109 +# define OSSL_STORE_R_UNREGISTERED_SCHEME 105 +# define OSSL_STORE_R_UNSUPPORTED_CONTENT_TYPE 110 +# define OSSL_STORE_R_UNSUPPORTED_OPERATION 118 +# define OSSL_STORE_R_UNSUPPORTED_SEARCH_TYPE 120 +# define OSSL_STORE_R_URI_AUTHORITY_UNSUPPORTED 111 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/store.h postgresql-hll-2.14/include/openssl/store.h --- postgresql-hll-2.14_old/include/openssl/store.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/store.h 2020-12-12 17:06:43.341349251 +0800 @@ -0,0 +1,266 @@ +/* + * Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_OSSL_STORE_H +# define HEADER_OSSL_STORE_H + +# include +# include +# include +# include + +# ifdef __cplusplus +extern "C" { +# endif + +/*- + * The main OSSL_STORE functions. + * ------------------------------ + * + * These allow applications to open a channel to a resource with supported + * data (keys, certs, crls, ...), read the data a piece at a time and decide + * what to do with it, and finally close. + */ + +typedef struct ossl_store_ctx_st OSSL_STORE_CTX; + +/* + * Typedef for the OSSL_STORE_INFO post processing callback. This can be used + * to massage the given OSSL_STORE_INFO, or to drop it entirely (by returning + * NULL). + */ +typedef OSSL_STORE_INFO *(*OSSL_STORE_post_process_info_fn)(OSSL_STORE_INFO *, + void *); + +/* + * Open a channel given a URI. The given UI method will be used any time the + * loader needs extra input, for example when a password or pin is needed, and + * will be passed the same user data every time it's needed in this context. + * + * Returns a context reference which represents the channel to communicate + * through. + */ +OSSL_STORE_CTX *OSSL_STORE_open(const char *uri, const UI_METHOD *ui_method, + void *ui_data, + OSSL_STORE_post_process_info_fn post_process, + void *post_process_data); + +/* + * Control / fine tune the OSSL_STORE channel. |cmd| determines what is to be + * done, and depends on the underlying loader (use OSSL_STORE_get0_scheme to + * determine which loader is used), except for common commands (see below). + * Each command takes different arguments. + */ +int OSSL_STORE_ctrl(OSSL_STORE_CTX *ctx, int cmd, ... /* args */); +int OSSL_STORE_vctrl(OSSL_STORE_CTX *ctx, int cmd, va_list args); + +/* + * Common ctrl commands that different loaders may choose to support. + */ +/* int on = 0 or 1; STORE_ctrl(ctx, STORE_C_USE_SECMEM, &on); */ +# define OSSL_STORE_C_USE_SECMEM 1 +/* Where custom commands start */ +# define OSSL_STORE_C_CUSTOM_START 100 + +/* + * Read one data item (a key, a cert, a CRL) that is supported by the OSSL_STORE + * functionality, given a context. + * Returns a OSSL_STORE_INFO pointer, from which OpenSSL typed data can be + * extracted with OSSL_STORE_INFO_get0_PKEY(), OSSL_STORE_INFO_get0_CERT(), ... + * NULL is returned on error, which may include that the data found at the URI + * can't be figured out for certain or is ambiguous. + */ +OSSL_STORE_INFO *OSSL_STORE_load(OSSL_STORE_CTX *ctx); + +/* + * Check if end of data (end of file) is reached + * Returns 1 on end, 0 otherwise. + */ +int OSSL_STORE_eof(OSSL_STORE_CTX *ctx); + +/* + * Check if an error occurred + * Returns 1 if it did, 0 otherwise. + */ +int OSSL_STORE_error(OSSL_STORE_CTX *ctx); + +/* + * Close the channel + * Returns 1 on success, 0 on error. + */ +int OSSL_STORE_close(OSSL_STORE_CTX *ctx); + + +/*- + * Extracting OpenSSL types from and creating new OSSL_STORE_INFOs + * --------------------------------------------------------------- + */ + +/* + * Types of data that can be ossl_stored in a OSSL_STORE_INFO. + * OSSL_STORE_INFO_NAME is typically found when getting a listing of + * available "files" / "tokens" / what have you. + */ +# define OSSL_STORE_INFO_NAME 1 /* char * */ +# define OSSL_STORE_INFO_PARAMS 2 /* EVP_PKEY * */ +# define OSSL_STORE_INFO_PKEY 3 /* EVP_PKEY * */ +# define OSSL_STORE_INFO_CERT 4 /* X509 * */ +# define OSSL_STORE_INFO_CRL 5 /* X509_CRL * */ + +/* + * Functions to generate OSSL_STORE_INFOs, one function for each type we + * support having in them, as well as a generic constructor. + * + * In all cases, ownership of the object is transferred to the OSSL_STORE_INFO + * and will therefore be freed when the OSSL_STORE_INFO is freed. + */ +OSSL_STORE_INFO *OSSL_STORE_INFO_new_NAME(char *name); +int OSSL_STORE_INFO_set0_NAME_description(OSSL_STORE_INFO *info, char *desc); +OSSL_STORE_INFO *OSSL_STORE_INFO_new_PARAMS(EVP_PKEY *params); +OSSL_STORE_INFO *OSSL_STORE_INFO_new_PKEY(EVP_PKEY *pkey); +OSSL_STORE_INFO *OSSL_STORE_INFO_new_CERT(X509 *x509); +OSSL_STORE_INFO *OSSL_STORE_INFO_new_CRL(X509_CRL *crl); + +/* + * Functions to try to extract data from a OSSL_STORE_INFO. + */ +int OSSL_STORE_INFO_get_type(const OSSL_STORE_INFO *info); +const char *OSSL_STORE_INFO_get0_NAME(const OSSL_STORE_INFO *info); +char *OSSL_STORE_INFO_get1_NAME(const OSSL_STORE_INFO *info); +const char *OSSL_STORE_INFO_get0_NAME_description(const OSSL_STORE_INFO *info); +char *OSSL_STORE_INFO_get1_NAME_description(const OSSL_STORE_INFO *info); +EVP_PKEY *OSSL_STORE_INFO_get0_PARAMS(const OSSL_STORE_INFO *info); +EVP_PKEY *OSSL_STORE_INFO_get1_PARAMS(const OSSL_STORE_INFO *info); +EVP_PKEY *OSSL_STORE_INFO_get0_PKEY(const OSSL_STORE_INFO *info); +EVP_PKEY *OSSL_STORE_INFO_get1_PKEY(const OSSL_STORE_INFO *info); +X509 *OSSL_STORE_INFO_get0_CERT(const OSSL_STORE_INFO *info); +X509 *OSSL_STORE_INFO_get1_CERT(const OSSL_STORE_INFO *info); +X509_CRL *OSSL_STORE_INFO_get0_CRL(const OSSL_STORE_INFO *info); +X509_CRL *OSSL_STORE_INFO_get1_CRL(const OSSL_STORE_INFO *info); + +const char *OSSL_STORE_INFO_type_string(int type); + +/* + * Free the OSSL_STORE_INFO + */ +void OSSL_STORE_INFO_free(OSSL_STORE_INFO *info); + + +/*- + * Functions to construct a search URI from a base URI and search criteria + * ----------------------------------------------------------------------- + */ + +/* OSSL_STORE search types */ +# define OSSL_STORE_SEARCH_BY_NAME 1 /* subject in certs, issuer in CRLs */ +# define OSSL_STORE_SEARCH_BY_ISSUER_SERIAL 2 +# define OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT 3 +# define OSSL_STORE_SEARCH_BY_ALIAS 4 + +/* To check what search types the scheme handler supports */ +int OSSL_STORE_supports_search(OSSL_STORE_CTX *ctx, int search_type); + +/* Search term constructors */ +/* + * The input is considered to be owned by the caller, and must therefore + * remain present throughout the lifetime of the returned OSSL_STORE_SEARCH + */ +OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_name(X509_NAME *name); +OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_issuer_serial(X509_NAME *name, + const ASN1_INTEGER + *serial); +OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_key_fingerprint(const EVP_MD *digest, + const unsigned char + *bytes, size_t len); +OSSL_STORE_SEARCH *OSSL_STORE_SEARCH_by_alias(const char *alias); + +/* Search term destructor */ +void OSSL_STORE_SEARCH_free(OSSL_STORE_SEARCH *search); + +/* Search term accessors */ +int OSSL_STORE_SEARCH_get_type(const OSSL_STORE_SEARCH *criterion); +X509_NAME *OSSL_STORE_SEARCH_get0_name(OSSL_STORE_SEARCH *criterion); +const ASN1_INTEGER *OSSL_STORE_SEARCH_get0_serial(const OSSL_STORE_SEARCH + *criterion); +const unsigned char *OSSL_STORE_SEARCH_get0_bytes(const OSSL_STORE_SEARCH + *criterion, size_t *length); +const char *OSSL_STORE_SEARCH_get0_string(const OSSL_STORE_SEARCH *criterion); +const EVP_MD *OSSL_STORE_SEARCH_get0_digest(const OSSL_STORE_SEARCH *criterion); + +/* + * Add search criterion and expected return type (which can be unspecified) + * to the loading channel. This MUST happen before the first OSSL_STORE_load(). + */ +int OSSL_STORE_expect(OSSL_STORE_CTX *ctx, int expected_type); +int OSSL_STORE_find(OSSL_STORE_CTX *ctx, OSSL_STORE_SEARCH *search); + + +/*- + * Function to register a loader for the given URI scheme. + * ------------------------------------------------------- + * + * The loader receives all the main components of an URI except for the + * scheme. + */ + +typedef struct ossl_store_loader_st OSSL_STORE_LOADER; +OSSL_STORE_LOADER *OSSL_STORE_LOADER_new(ENGINE *e, const char *scheme); +const ENGINE *OSSL_STORE_LOADER_get0_engine(const OSSL_STORE_LOADER *loader); +const char *OSSL_STORE_LOADER_get0_scheme(const OSSL_STORE_LOADER *loader); +/* struct ossl_store_loader_ctx_st is defined differently by each loader */ +typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX; +typedef OSSL_STORE_LOADER_CTX *(*OSSL_STORE_open_fn)(const OSSL_STORE_LOADER + *loader, + const char *uri, + const UI_METHOD *ui_method, + void *ui_data); +int OSSL_STORE_LOADER_set_open(OSSL_STORE_LOADER *loader, + OSSL_STORE_open_fn open_function); +typedef int (*OSSL_STORE_ctrl_fn)(OSSL_STORE_LOADER_CTX *ctx, int cmd, + va_list args); +int OSSL_STORE_LOADER_set_ctrl(OSSL_STORE_LOADER *loader, + OSSL_STORE_ctrl_fn ctrl_function); +typedef int (*OSSL_STORE_expect_fn)(OSSL_STORE_LOADER_CTX *ctx, int expected); +int OSSL_STORE_LOADER_set_expect(OSSL_STORE_LOADER *loader, + OSSL_STORE_expect_fn expect_function); +typedef int (*OSSL_STORE_find_fn)(OSSL_STORE_LOADER_CTX *ctx, + OSSL_STORE_SEARCH *criteria); +int OSSL_STORE_LOADER_set_find(OSSL_STORE_LOADER *loader, + OSSL_STORE_find_fn find_function); +typedef OSSL_STORE_INFO *(*OSSL_STORE_load_fn)(OSSL_STORE_LOADER_CTX *ctx, + const UI_METHOD *ui_method, + void *ui_data); +int OSSL_STORE_LOADER_set_load(OSSL_STORE_LOADER *loader, + OSSL_STORE_load_fn load_function); +typedef int (*OSSL_STORE_eof_fn)(OSSL_STORE_LOADER_CTX *ctx); +int OSSL_STORE_LOADER_set_eof(OSSL_STORE_LOADER *loader, + OSSL_STORE_eof_fn eof_function); +typedef int (*OSSL_STORE_error_fn)(OSSL_STORE_LOADER_CTX *ctx); +int OSSL_STORE_LOADER_set_error(OSSL_STORE_LOADER *loader, + OSSL_STORE_error_fn error_function); +typedef int (*OSSL_STORE_close_fn)(OSSL_STORE_LOADER_CTX *ctx); +int OSSL_STORE_LOADER_set_close(OSSL_STORE_LOADER *loader, + OSSL_STORE_close_fn close_function); +void OSSL_STORE_LOADER_free(OSSL_STORE_LOADER *loader); + +int OSSL_STORE_register_loader(OSSL_STORE_LOADER *loader); +OSSL_STORE_LOADER *OSSL_STORE_unregister_loader(const char *scheme); + +/*- + * Functions to list STORE loaders + * ------------------------------- + */ +int OSSL_STORE_do_all_loaders(void (*do_function) (const OSSL_STORE_LOADER + *loader, void *do_arg), + void *do_arg); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/symhacks.h postgresql-hll-2.14/include/openssl/symhacks.h --- postgresql-hll-2.14_old/include/openssl/symhacks.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/symhacks.h 2020-12-12 17:06:43.341349251 +0800 @@ -0,0 +1,37 @@ +/* + * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_SYMHACKS_H +# define HEADER_SYMHACKS_H + +# include + +/* Case insensitive linking causes problems.... */ +# if defined(OPENSSL_SYS_VMS) +# undef ERR_load_CRYPTO_strings +# define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings +# undef OCSP_crlID_new +# define OCSP_crlID_new OCSP_crlID2_new + +# undef d2i_ECPARAMETERS +# define d2i_ECPARAMETERS d2i_UC_ECPARAMETERS +# undef i2d_ECPARAMETERS +# define i2d_ECPARAMETERS i2d_UC_ECPARAMETERS +# undef d2i_ECPKPARAMETERS +# define d2i_ECPKPARAMETERS d2i_UC_ECPKPARAMETERS +# undef i2d_ECPKPARAMETERS +# define i2d_ECPKPARAMETERS i2d_UC_ECPKPARAMETERS + +/* This one clashes with CMS_data_create */ +# undef cms_Data_create +# define cms_Data_create priv_cms_Data_create + +# endif + +#endif /* ! defined HEADER_VMS_IDHACKS_H */ diff -uprN postgresql-hll-2.14_old/include/openssl/tls1.h postgresql-hll-2.14/include/openssl/tls1.h --- postgresql-hll-2.14_old/include/openssl/tls1.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/tls1.h 2020-12-12 17:06:43.342349264 +0800 @@ -0,0 +1,1237 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * Copyright 2005 Nokia. All rights reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TLS1_H +# define HEADER_TLS1_H + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Default security level if not overridden at config time */ +# ifndef OPENSSL_TLS_SECURITY_LEVEL +# define OPENSSL_TLS_SECURITY_LEVEL 1 +# endif + +# define TLS1_VERSION 0x0301 +# define TLS1_1_VERSION 0x0302 +# define TLS1_2_VERSION 0x0303 +# define TLS1_3_VERSION 0x0304 +# define TLS_MAX_VERSION TLS1_3_VERSION + +/* Special value for method supporting multiple versions */ +# define TLS_ANY_VERSION 0x10000 + +# define TLS1_VERSION_MAJOR 0x03 +# define TLS1_VERSION_MINOR 0x01 + +# define TLS1_1_VERSION_MAJOR 0x03 +# define TLS1_1_VERSION_MINOR 0x02 + +# define TLS1_2_VERSION_MAJOR 0x03 +# define TLS1_2_VERSION_MINOR 0x03 + +# define TLS1_get_version(s) \ + ((SSL_version(s) >> 8) == TLS1_VERSION_MAJOR ? SSL_version(s) : 0) + +# define TLS1_get_client_version(s) \ + ((SSL_client_version(s) >> 8) == TLS1_VERSION_MAJOR ? SSL_client_version(s) : 0) + +# define TLS1_AD_DECRYPTION_FAILED 21 +# define TLS1_AD_RECORD_OVERFLOW 22 +# define TLS1_AD_UNKNOWN_CA 48/* fatal */ +# define TLS1_AD_ACCESS_DENIED 49/* fatal */ +# define TLS1_AD_DECODE_ERROR 50/* fatal */ +# define TLS1_AD_DECRYPT_ERROR 51 +# define TLS1_AD_EXPORT_RESTRICTION 60/* fatal */ +# define TLS1_AD_PROTOCOL_VERSION 70/* fatal */ +# define TLS1_AD_INSUFFICIENT_SECURITY 71/* fatal */ +# define TLS1_AD_INTERNAL_ERROR 80/* fatal */ +# define TLS1_AD_INAPPROPRIATE_FALLBACK 86/* fatal */ +# define TLS1_AD_USER_CANCELLED 90 +# define TLS1_AD_NO_RENEGOTIATION 100 +/* TLSv1.3 alerts */ +# define TLS13_AD_MISSING_EXTENSION 109 /* fatal */ +# define TLS13_AD_CERTIFICATE_REQUIRED 116 /* fatal */ +/* codes 110-114 are from RFC3546 */ +# define TLS1_AD_UNSUPPORTED_EXTENSION 110 +# define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111 +# define TLS1_AD_UNRECOGNIZED_NAME 112 +# define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113 +# define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114 +# define TLS1_AD_UNKNOWN_PSK_IDENTITY 115/* fatal */ +# define TLS1_AD_NO_APPLICATION_PROTOCOL 120 /* fatal */ + +/* ExtensionType values from RFC3546 / RFC4366 / RFC6066 */ +# define TLSEXT_TYPE_server_name 0 +# define TLSEXT_TYPE_max_fragment_length 1 +# define TLSEXT_TYPE_client_certificate_url 2 +# define TLSEXT_TYPE_trusted_ca_keys 3 +# define TLSEXT_TYPE_truncated_hmac 4 +# define TLSEXT_TYPE_status_request 5 +/* ExtensionType values from RFC4681 */ +# define TLSEXT_TYPE_user_mapping 6 +/* ExtensionType values from RFC5878 */ +# define TLSEXT_TYPE_client_authz 7 +# define TLSEXT_TYPE_server_authz 8 +/* ExtensionType values from RFC6091 */ +# define TLSEXT_TYPE_cert_type 9 + +/* ExtensionType values from RFC4492 */ +/* + * Prior to TLSv1.3 the supported_groups extension was known as + * elliptic_curves + */ +# define TLSEXT_TYPE_supported_groups 10 +# define TLSEXT_TYPE_elliptic_curves TLSEXT_TYPE_supported_groups +# define TLSEXT_TYPE_ec_point_formats 11 + + +/* ExtensionType value from RFC5054 */ +# define TLSEXT_TYPE_srp 12 + +/* ExtensionType values from RFC5246 */ +# define TLSEXT_TYPE_signature_algorithms 13 + +/* ExtensionType value from RFC5764 */ +# define TLSEXT_TYPE_use_srtp 14 + +/* ExtensionType value from RFC5620 */ +# define TLSEXT_TYPE_heartbeat 15 + +/* ExtensionType value from RFC7301 */ +# define TLSEXT_TYPE_application_layer_protocol_negotiation 16 + +/* + * Extension type for Certificate Transparency + * https://tools.ietf.org/html/rfc6962#section-3.3.1 + */ +# define TLSEXT_TYPE_signed_certificate_timestamp 18 + +/* + * ExtensionType value for TLS padding extension. + * http://tools.ietf.org/html/draft-agl-tls-padding + */ +# define TLSEXT_TYPE_padding 21 + +/* ExtensionType value from RFC7366 */ +# define TLSEXT_TYPE_encrypt_then_mac 22 + +/* ExtensionType value from RFC7627 */ +# define TLSEXT_TYPE_extended_master_secret 23 + +/* ExtensionType value from RFC4507 */ +# define TLSEXT_TYPE_session_ticket 35 + +/* As defined for TLS1.3 */ +# define TLSEXT_TYPE_psk 41 +# define TLSEXT_TYPE_early_data 42 +# define TLSEXT_TYPE_supported_versions 43 +# define TLSEXT_TYPE_cookie 44 +# define TLSEXT_TYPE_psk_kex_modes 45 +# define TLSEXT_TYPE_certificate_authorities 47 +# define TLSEXT_TYPE_post_handshake_auth 49 +# define TLSEXT_TYPE_signature_algorithms_cert 50 +# define TLSEXT_TYPE_key_share 51 + +/* Temporary extension type */ +# define TLSEXT_TYPE_renegotiate 0xff01 + +# ifndef OPENSSL_NO_NEXTPROTONEG +/* This is not an IANA defined extension number */ +# define TLSEXT_TYPE_next_proto_neg 13172 +# endif + +/* NameType value from RFC3546 */ +# define TLSEXT_NAMETYPE_host_name 0 +/* status request value from RFC3546 */ +# define TLSEXT_STATUSTYPE_ocsp 1 + +/* ECPointFormat values from RFC4492 */ +# define TLSEXT_ECPOINTFORMAT_first 0 +# define TLSEXT_ECPOINTFORMAT_uncompressed 0 +# define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime 1 +# define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 2 +# define TLSEXT_ECPOINTFORMAT_last 2 + +/* Signature and hash algorithms from RFC5246 */ +# define TLSEXT_signature_anonymous 0 +# define TLSEXT_signature_rsa 1 +# define TLSEXT_signature_dsa 2 +# define TLSEXT_signature_ecdsa 3 +# define TLSEXT_signature_gostr34102001 237 +# define TLSEXT_signature_gostr34102012_256 238 +# define TLSEXT_signature_gostr34102012_512 239 + +/* Total number of different signature algorithms */ +# define TLSEXT_signature_num 7 + +# define TLSEXT_hash_none 0 +# define TLSEXT_hash_md5 1 +# define TLSEXT_hash_sha1 2 +# define TLSEXT_hash_sha224 3 +# define TLSEXT_hash_sha256 4 +# define TLSEXT_hash_sha384 5 +# define TLSEXT_hash_sha512 6 +# define TLSEXT_hash_gostr3411 237 +# define TLSEXT_hash_gostr34112012_256 238 +# define TLSEXT_hash_gostr34112012_512 239 + +/* Total number of different digest algorithms */ + +# define TLSEXT_hash_num 10 + +/* Flag set for unrecognised algorithms */ +# define TLSEXT_nid_unknown 0x1000000 + +/* ECC curves */ + +# define TLSEXT_curve_P_256 23 +# define TLSEXT_curve_P_384 24 + +/* OpenSSL value to disable maximum fragment length extension */ +# define TLSEXT_max_fragment_length_DISABLED 0 +/* Allowed values for max fragment length extension */ +# define TLSEXT_max_fragment_length_512 1 +# define TLSEXT_max_fragment_length_1024 2 +# define TLSEXT_max_fragment_length_2048 3 +# define TLSEXT_max_fragment_length_4096 4 + +int SSL_CTX_set_tlsext_max_fragment_length(SSL_CTX *ctx, uint8_t mode); +int SSL_set_tlsext_max_fragment_length(SSL *ssl, uint8_t mode); + +# define TLSEXT_MAXLEN_host_name 255 + +__owur const char *SSL_get_servername(const SSL *s, const int type); +__owur int SSL_get_servername_type(const SSL *s); +/* + * SSL_export_keying_material exports a value derived from the master secret, + * as specified in RFC 5705. It writes |olen| bytes to |out| given a label and + * optional context. (Since a zero length context is allowed, the |use_context| + * flag controls whether a context is included.) It returns 1 on success and + * 0 or -1 otherwise. + */ +__owur int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen, + const char *label, size_t llen, + const unsigned char *context, + size_t contextlen, int use_context); + +/* + * SSL_export_keying_material_early exports a value derived from the + * early exporter master secret, as specified in + * https://tools.ietf.org/html/draft-ietf-tls-tls13-23. It writes + * |olen| bytes to |out| given a label and optional context. It + * returns 1 on success and 0 otherwise. + */ +__owur int SSL_export_keying_material_early(SSL *s, unsigned char *out, + size_t olen, const char *label, + size_t llen, + const unsigned char *context, + size_t contextlen); + +int SSL_get_peer_signature_type_nid(const SSL *s, int *pnid); +int SSL_get_signature_type_nid(const SSL *s, int *pnid); + +int SSL_get_sigalgs(SSL *s, int idx, + int *psign, int *phash, int *psignandhash, + unsigned char *rsig, unsigned char *rhash); + +int SSL_get_shared_sigalgs(SSL *s, int idx, + int *psign, int *phash, int *psignandhash, + unsigned char *rsig, unsigned char *rhash); + +__owur int SSL_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain); + +# define SSL_set_tlsext_host_name(s,name) \ + SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,\ + (void *)name) + +# define SSL_set_tlsext_debug_callback(ssl, cb) \ + SSL_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_CB,\ + (void (*)(void))cb) + +# define SSL_set_tlsext_debug_arg(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_ARG,0,arg) + +# define SSL_get_tlsext_status_type(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE,0,NULL) + +# define SSL_set_tlsext_status_type(ssl, type) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type,NULL) + +# define SSL_get_tlsext_status_exts(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS,0,arg) + +# define SSL_set_tlsext_status_exts(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS,0,arg) + +# define SSL_get_tlsext_status_ids(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS,0,arg) + +# define SSL_set_tlsext_status_ids(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS,0,arg) + +# define SSL_get_tlsext_status_ocsp_resp(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,0,arg) + +# define SSL_set_tlsext_status_ocsp_resp(ssl, arg, arglen) \ + SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,arglen,arg) + +# define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ + SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,\ + (void (*)(void))cb) + +# define SSL_TLSEXT_ERR_OK 0 +# define SSL_TLSEXT_ERR_ALERT_WARNING 1 +# define SSL_TLSEXT_ERR_ALERT_FATAL 2 +# define SSL_TLSEXT_ERR_NOACK 3 + +# define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG,0,arg) + +# define SSL_CTX_get_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_GET_TLSEXT_TICKET_KEYS,keylen,keys) +# define SSL_CTX_set_tlsext_ticket_keys(ctx, keys, keylen) \ + SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_TICKET_KEYS,keylen,keys) + +# define SSL_CTX_get_tlsext_status_cb(ssl, cb) \ + SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB,0,(void *)cb) +# define SSL_CTX_set_tlsext_status_cb(ssl, cb) \ + SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,\ + (void (*)(void))cb) + +# define SSL_CTX_get_tlsext_status_arg(ssl, arg) \ + SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG,0,arg) +# define SSL_CTX_set_tlsext_status_arg(ssl, arg) \ + SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0,arg) + +# define SSL_CTX_set_tlsext_status_type(ssl, type) \ + SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type,NULL) + +# define SSL_CTX_get_tlsext_status_type(ssl) \ + SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE,0,NULL) + +# define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \ + SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,\ + (void (*)(void))cb) + +# ifndef OPENSSL_NO_HEARTBEATS +# define SSL_DTLSEXT_HB_ENABLED 0x01 +# define SSL_DTLSEXT_HB_DONT_SEND_REQUESTS 0x02 +# define SSL_DTLSEXT_HB_DONT_RECV_REQUESTS 0x04 +# define SSL_get_dtlsext_heartbeat_pending(ssl) \ + SSL_ctrl(ssl,SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING,0,NULL) +# define SSL_set_dtlsext_heartbeat_no_requests(ssl, arg) \ + SSL_ctrl(ssl,SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS,arg,NULL) + +# if OPENSSL_API_COMPAT < 0x10100000L +# define SSL_CTRL_TLS_EXT_SEND_HEARTBEAT \ + SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT +# define SSL_CTRL_GET_TLS_EXT_HEARTBEAT_PENDING \ + SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING +# define SSL_CTRL_SET_TLS_EXT_HEARTBEAT_NO_REQUESTS \ + SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS +# define SSL_TLSEXT_HB_ENABLED \ + SSL_DTLSEXT_HB_ENABLED +# define SSL_TLSEXT_HB_DONT_SEND_REQUESTS \ + SSL_DTLSEXT_HB_DONT_SEND_REQUESTS +# define SSL_TLSEXT_HB_DONT_RECV_REQUESTS \ + SSL_DTLSEXT_HB_DONT_RECV_REQUESTS +# define SSL_get_tlsext_heartbeat_pending(ssl) \ + SSL_get_dtlsext_heartbeat_pending(ssl) +# define SSL_set_tlsext_heartbeat_no_requests(ssl, arg) \ + SSL_set_dtlsext_heartbeat_no_requests(ssl,arg) +# endif +# endif + +/* PSK ciphersuites from 4279 */ +# define TLS1_CK_PSK_WITH_RC4_128_SHA 0x0300008A +# define TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008B +# define TLS1_CK_PSK_WITH_AES_128_CBC_SHA 0x0300008C +# define TLS1_CK_PSK_WITH_AES_256_CBC_SHA 0x0300008D +# define TLS1_CK_DHE_PSK_WITH_RC4_128_SHA 0x0300008E +# define TLS1_CK_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008F +# define TLS1_CK_DHE_PSK_WITH_AES_128_CBC_SHA 0x03000090 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CBC_SHA 0x03000091 +# define TLS1_CK_RSA_PSK_WITH_RC4_128_SHA 0x03000092 +# define TLS1_CK_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x03000093 +# define TLS1_CK_RSA_PSK_WITH_AES_128_CBC_SHA 0x03000094 +# define TLS1_CK_RSA_PSK_WITH_AES_256_CBC_SHA 0x03000095 + +/* PSK ciphersuites from 5487 */ +# define TLS1_CK_PSK_WITH_AES_128_GCM_SHA256 0x030000A8 +# define TLS1_CK_PSK_WITH_AES_256_GCM_SHA384 0x030000A9 +# define TLS1_CK_DHE_PSK_WITH_AES_128_GCM_SHA256 0x030000AA +# define TLS1_CK_DHE_PSK_WITH_AES_256_GCM_SHA384 0x030000AB +# define TLS1_CK_RSA_PSK_WITH_AES_128_GCM_SHA256 0x030000AC +# define TLS1_CK_RSA_PSK_WITH_AES_256_GCM_SHA384 0x030000AD +# define TLS1_CK_PSK_WITH_AES_128_CBC_SHA256 0x030000AE +# define TLS1_CK_PSK_WITH_AES_256_CBC_SHA384 0x030000AF +# define TLS1_CK_PSK_WITH_NULL_SHA256 0x030000B0 +# define TLS1_CK_PSK_WITH_NULL_SHA384 0x030000B1 +# define TLS1_CK_DHE_PSK_WITH_AES_128_CBC_SHA256 0x030000B2 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CBC_SHA384 0x030000B3 +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA256 0x030000B4 +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA384 0x030000B5 +# define TLS1_CK_RSA_PSK_WITH_AES_128_CBC_SHA256 0x030000B6 +# define TLS1_CK_RSA_PSK_WITH_AES_256_CBC_SHA384 0x030000B7 +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA256 0x030000B8 +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA384 0x030000B9 + +/* NULL PSK ciphersuites from RFC4785 */ +# define TLS1_CK_PSK_WITH_NULL_SHA 0x0300002C +# define TLS1_CK_DHE_PSK_WITH_NULL_SHA 0x0300002D +# define TLS1_CK_RSA_PSK_WITH_NULL_SHA 0x0300002E + +/* AES ciphersuites from RFC3268 */ +# define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F +# define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030 +# define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031 +# define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032 +# define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033 +# define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034 +# define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035 +# define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036 +# define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037 +# define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038 +# define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 +# define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A + +/* TLS v1.2 ciphersuites */ +# define TLS1_CK_RSA_WITH_NULL_SHA256 0x0300003B +# define TLS1_CK_RSA_WITH_AES_128_SHA256 0x0300003C +# define TLS1_CK_RSA_WITH_AES_256_SHA256 0x0300003D +# define TLS1_CK_DH_DSS_WITH_AES_128_SHA256 0x0300003E +# define TLS1_CK_DH_RSA_WITH_AES_128_SHA256 0x0300003F +# define TLS1_CK_DHE_DSS_WITH_AES_128_SHA256 0x03000040 + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000041 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000042 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000043 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000044 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000045 +# define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA 0x03000046 + +/* TLS v1.2 ciphersuites */ +# define TLS1_CK_DHE_RSA_WITH_AES_128_SHA256 0x03000067 +# define TLS1_CK_DH_DSS_WITH_AES_256_SHA256 0x03000068 +# define TLS1_CK_DH_RSA_WITH_AES_256_SHA256 0x03000069 +# define TLS1_CK_DHE_DSS_WITH_AES_256_SHA256 0x0300006A +# define TLS1_CK_DHE_RSA_WITH_AES_256_SHA256 0x0300006B +# define TLS1_CK_ADH_WITH_AES_128_SHA256 0x0300006C +# define TLS1_CK_ADH_WITH_AES_256_SHA256 0x0300006D + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000084 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000085 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000086 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000087 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000088 +# define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA 0x03000089 + +/* SEED ciphersuites from RFC4162 */ +# define TLS1_CK_RSA_WITH_SEED_SHA 0x03000096 +# define TLS1_CK_DH_DSS_WITH_SEED_SHA 0x03000097 +# define TLS1_CK_DH_RSA_WITH_SEED_SHA 0x03000098 +# define TLS1_CK_DHE_DSS_WITH_SEED_SHA 0x03000099 +# define TLS1_CK_DHE_RSA_WITH_SEED_SHA 0x0300009A +# define TLS1_CK_ADH_WITH_SEED_SHA 0x0300009B + +/* TLS v1.2 GCM ciphersuites from RFC5288 */ +# define TLS1_CK_RSA_WITH_AES_128_GCM_SHA256 0x0300009C +# define TLS1_CK_RSA_WITH_AES_256_GCM_SHA384 0x0300009D +# define TLS1_CK_DHE_RSA_WITH_AES_128_GCM_SHA256 0x0300009E +# define TLS1_CK_DHE_RSA_WITH_AES_256_GCM_SHA384 0x0300009F +# define TLS1_CK_DH_RSA_WITH_AES_128_GCM_SHA256 0x030000A0 +# define TLS1_CK_DH_RSA_WITH_AES_256_GCM_SHA384 0x030000A1 +# define TLS1_CK_DHE_DSS_WITH_AES_128_GCM_SHA256 0x030000A2 +# define TLS1_CK_DHE_DSS_WITH_AES_256_GCM_SHA384 0x030000A3 +# define TLS1_CK_DH_DSS_WITH_AES_128_GCM_SHA256 0x030000A4 +# define TLS1_CK_DH_DSS_WITH_AES_256_GCM_SHA384 0x030000A5 +# define TLS1_CK_ADH_WITH_AES_128_GCM_SHA256 0x030000A6 +# define TLS1_CK_ADH_WITH_AES_256_GCM_SHA384 0x030000A7 + +/* CCM ciphersuites from RFC6655 */ +# define TLS1_CK_RSA_WITH_AES_128_CCM 0x0300C09C +# define TLS1_CK_RSA_WITH_AES_256_CCM 0x0300C09D +# define TLS1_CK_DHE_RSA_WITH_AES_128_CCM 0x0300C09E +# define TLS1_CK_DHE_RSA_WITH_AES_256_CCM 0x0300C09F +# define TLS1_CK_RSA_WITH_AES_128_CCM_8 0x0300C0A0 +# define TLS1_CK_RSA_WITH_AES_256_CCM_8 0x0300C0A1 +# define TLS1_CK_DHE_RSA_WITH_AES_128_CCM_8 0x0300C0A2 +# define TLS1_CK_DHE_RSA_WITH_AES_256_CCM_8 0x0300C0A3 +# define TLS1_CK_PSK_WITH_AES_128_CCM 0x0300C0A4 +# define TLS1_CK_PSK_WITH_AES_256_CCM 0x0300C0A5 +# define TLS1_CK_DHE_PSK_WITH_AES_128_CCM 0x0300C0A6 +# define TLS1_CK_DHE_PSK_WITH_AES_256_CCM 0x0300C0A7 +# define TLS1_CK_PSK_WITH_AES_128_CCM_8 0x0300C0A8 +# define TLS1_CK_PSK_WITH_AES_256_CCM_8 0x0300C0A9 +# define TLS1_CK_DHE_PSK_WITH_AES_128_CCM_8 0x0300C0AA +# define TLS1_CK_DHE_PSK_WITH_AES_256_CCM_8 0x0300C0AB + +/* CCM ciphersuites from RFC7251 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CCM 0x0300C0AC +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CCM 0x0300C0AD +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CCM_8 0x0300C0AE +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CCM_8 0x0300C0AF + +/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */ +# define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BA +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BB +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BC +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BD +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BE +# define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA256 0x030000BF + +# define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C0 +# define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C1 +# define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C2 +# define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C3 +# define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C4 +# define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA256 0x030000C5 + +/* ECC ciphersuites from RFC4492 */ +# define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA 0x0300C001 +# define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA 0x0300C002 +# define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C003 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0x0300C004 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0x0300C005 + +# define TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA 0x0300C006 +# define TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA 0x0300C007 +# define TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C008 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0x0300C009 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0x0300C00A + +# define TLS1_CK_ECDH_RSA_WITH_NULL_SHA 0x0300C00B +# define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA 0x0300C00C +# define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA 0x0300C00D +# define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA 0x0300C00E +# define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA 0x0300C00F + +# define TLS1_CK_ECDHE_RSA_WITH_NULL_SHA 0x0300C010 +# define TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA 0x0300C011 +# define TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA 0x0300C012 +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA 0x0300C013 +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA 0x0300C014 + +# define TLS1_CK_ECDH_anon_WITH_NULL_SHA 0x0300C015 +# define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA 0x0300C016 +# define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA 0x0300C017 +# define TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA 0x0300C018 +# define TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA 0x0300C019 + +/* SRP ciphersuites from RFC 5054 */ +# define TLS1_CK_SRP_SHA_WITH_3DES_EDE_CBC_SHA 0x0300C01A +# define TLS1_CK_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA 0x0300C01B +# define TLS1_CK_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA 0x0300C01C +# define TLS1_CK_SRP_SHA_WITH_AES_128_CBC_SHA 0x0300C01D +# define TLS1_CK_SRP_SHA_RSA_WITH_AES_128_CBC_SHA 0x0300C01E +# define TLS1_CK_SRP_SHA_DSS_WITH_AES_128_CBC_SHA 0x0300C01F +# define TLS1_CK_SRP_SHA_WITH_AES_256_CBC_SHA 0x0300C020 +# define TLS1_CK_SRP_SHA_RSA_WITH_AES_256_CBC_SHA 0x0300C021 +# define TLS1_CK_SRP_SHA_DSS_WITH_AES_256_CBC_SHA 0x0300C022 + +/* ECDH HMAC based ciphersuites from RFC5289 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_SHA256 0x0300C023 +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_SHA384 0x0300C024 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_SHA256 0x0300C025 +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_SHA384 0x0300C026 +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256 0x0300C027 +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384 0x0300C028 +# define TLS1_CK_ECDH_RSA_WITH_AES_128_SHA256 0x0300C029 +# define TLS1_CK_ECDH_RSA_WITH_AES_256_SHA384 0x0300C02A + +/* ECDH GCM based ciphersuites from RFC5289 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02B +# define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02C +# define TLS1_CK_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02D +# define TLS1_CK_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02E +# define TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0x0300C02F +# define TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0x0300C030 +# define TLS1_CK_ECDH_RSA_WITH_AES_128_GCM_SHA256 0x0300C031 +# define TLS1_CK_ECDH_RSA_WITH_AES_256_GCM_SHA384 0x0300C032 + +/* ECDHE PSK ciphersuites from RFC5489 */ +# define TLS1_CK_ECDHE_PSK_WITH_RC4_128_SHA 0x0300C033 +# define TLS1_CK_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0x0300C034 +# define TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA 0x0300C035 +# define TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA 0x0300C036 + +# define TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0x0300C037 +# define TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0x0300C038 + +/* NULL PSK ciphersuites from RFC4785 */ +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA 0x0300C039 +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA256 0x0300C03A +# define TLS1_CK_ECDHE_PSK_WITH_NULL_SHA384 0x0300C03B + +/* Camellia-CBC ciphersuites from RFC6367 */ +# define TLS1_CK_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C072 +# define TLS1_CK_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C073 +# define TLS1_CK_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C074 +# define TLS1_CK_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C075 +# define TLS1_CK_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C076 +# define TLS1_CK_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C077 +# define TLS1_CK_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x0300C078 +# define TLS1_CK_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0x0300C079 + +# define TLS1_CK_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C094 +# define TLS1_CK_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C095 +# define TLS1_CK_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C096 +# define TLS1_CK_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C097 +# define TLS1_CK_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C098 +# define TLS1_CK_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C099 +# define TLS1_CK_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0x0300C09A +# define TLS1_CK_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0x0300C09B + +/* draft-ietf-tls-chacha20-poly1305-03 */ +# define TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305 0x0300CCA8 +# define TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 0x0300CCA9 +# define TLS1_CK_DHE_RSA_WITH_CHACHA20_POLY1305 0x0300CCAA +# define TLS1_CK_PSK_WITH_CHACHA20_POLY1305 0x0300CCAB +# define TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305 0x0300CCAC +# define TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305 0x0300CCAD +# define TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305 0x0300CCAE + +/* TLS v1.3 ciphersuites */ +# define TLS1_3_CK_AES_128_GCM_SHA256 0x03001301 +# define TLS1_3_CK_AES_256_GCM_SHA384 0x03001302 +# define TLS1_3_CK_CHACHA20_POLY1305_SHA256 0x03001303 +# define TLS1_3_CK_AES_128_CCM_SHA256 0x03001304 +# define TLS1_3_CK_AES_128_CCM_8_SHA256 0x03001305 + +/* Aria ciphersuites from RFC6209 */ +# define TLS1_CK_RSA_WITH_ARIA_128_GCM_SHA256 0x0300C050 +# define TLS1_CK_RSA_WITH_ARIA_256_GCM_SHA384 0x0300C051 +# define TLS1_CK_DHE_RSA_WITH_ARIA_128_GCM_SHA256 0x0300C052 +# define TLS1_CK_DHE_RSA_WITH_ARIA_256_GCM_SHA384 0x0300C053 +# define TLS1_CK_DH_RSA_WITH_ARIA_128_GCM_SHA256 0x0300C054 +# define TLS1_CK_DH_RSA_WITH_ARIA_256_GCM_SHA384 0x0300C055 +# define TLS1_CK_DHE_DSS_WITH_ARIA_128_GCM_SHA256 0x0300C056 +# define TLS1_CK_DHE_DSS_WITH_ARIA_256_GCM_SHA384 0x0300C057 +# define TLS1_CK_DH_DSS_WITH_ARIA_128_GCM_SHA256 0x0300C058 +# define TLS1_CK_DH_DSS_WITH_ARIA_256_GCM_SHA384 0x0300C059 +# define TLS1_CK_DH_anon_WITH_ARIA_128_GCM_SHA256 0x0300C05A +# define TLS1_CK_DH_anon_WITH_ARIA_256_GCM_SHA384 0x0300C05B +# define TLS1_CK_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 0x0300C05C +# define TLS1_CK_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 0x0300C05D +# define TLS1_CK_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 0x0300C05E +# define TLS1_CK_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 0x0300C05F +# define TLS1_CK_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 0x0300C060 +# define TLS1_CK_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 0x0300C061 +# define TLS1_CK_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 0x0300C062 +# define TLS1_CK_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 0x0300C063 +# define TLS1_CK_PSK_WITH_ARIA_128_GCM_SHA256 0x0300C06A +# define TLS1_CK_PSK_WITH_ARIA_256_GCM_SHA384 0x0300C06B +# define TLS1_CK_DHE_PSK_WITH_ARIA_128_GCM_SHA256 0x0300C06C +# define TLS1_CK_DHE_PSK_WITH_ARIA_256_GCM_SHA384 0x0300C06D +# define TLS1_CK_RSA_PSK_WITH_ARIA_128_GCM_SHA256 0x0300C06E +# define TLS1_CK_RSA_PSK_WITH_ARIA_256_GCM_SHA384 0x0300C06F + +/* a bundle of RFC standard cipher names, generated from ssl3_ciphers[] */ +# define TLS1_RFC_RSA_WITH_AES_128_SHA "TLS_RSA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_DHE_DSS_WITH_AES_128_SHA "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_AES_128_SHA "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_ADH_WITH_AES_128_SHA "TLS_DH_anon_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_RSA_WITH_AES_256_SHA "TLS_RSA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_DHE_DSS_WITH_AES_256_SHA "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_AES_256_SHA "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_ADH_WITH_AES_256_SHA "TLS_DH_anon_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_RSA_WITH_NULL_SHA256 "TLS_RSA_WITH_NULL_SHA256" +# define TLS1_RFC_RSA_WITH_AES_128_SHA256 "TLS_RSA_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_RSA_WITH_AES_256_SHA256 "TLS_RSA_WITH_AES_256_CBC_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_AES_128_SHA256 "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_AES_128_SHA256 "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_AES_256_SHA256 "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_AES_256_SHA256 "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" +# define TLS1_RFC_ADH_WITH_AES_128_SHA256 "TLS_DH_anon_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_ADH_WITH_AES_256_SHA256 "TLS_DH_anon_WITH_AES_256_CBC_SHA256" +# define TLS1_RFC_RSA_WITH_AES_128_GCM_SHA256 "TLS_RSA_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_RSA_WITH_AES_256_GCM_SHA384 "TLS_RSA_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_DHE_RSA_WITH_AES_128_GCM_SHA256 "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_AES_256_GCM_SHA384 "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_DHE_DSS_WITH_AES_128_GCM_SHA256 "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_AES_256_GCM_SHA384 "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_ADH_WITH_AES_128_GCM_SHA256 "TLS_DH_anon_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_ADH_WITH_AES_256_GCM_SHA384 "TLS_DH_anon_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_RSA_WITH_AES_128_CCM "TLS_RSA_WITH_AES_128_CCM" +# define TLS1_RFC_RSA_WITH_AES_256_CCM "TLS_RSA_WITH_AES_256_CCM" +# define TLS1_RFC_DHE_RSA_WITH_AES_128_CCM "TLS_DHE_RSA_WITH_AES_128_CCM" +# define TLS1_RFC_DHE_RSA_WITH_AES_256_CCM "TLS_DHE_RSA_WITH_AES_256_CCM" +# define TLS1_RFC_RSA_WITH_AES_128_CCM_8 "TLS_RSA_WITH_AES_128_CCM_8" +# define TLS1_RFC_RSA_WITH_AES_256_CCM_8 "TLS_RSA_WITH_AES_256_CCM_8" +# define TLS1_RFC_DHE_RSA_WITH_AES_128_CCM_8 "TLS_DHE_RSA_WITH_AES_128_CCM_8" +# define TLS1_RFC_DHE_RSA_WITH_AES_256_CCM_8 "TLS_DHE_RSA_WITH_AES_256_CCM_8" +# define TLS1_RFC_PSK_WITH_AES_128_CCM "TLS_PSK_WITH_AES_128_CCM" +# define TLS1_RFC_PSK_WITH_AES_256_CCM "TLS_PSK_WITH_AES_256_CCM" +# define TLS1_RFC_DHE_PSK_WITH_AES_128_CCM "TLS_DHE_PSK_WITH_AES_128_CCM" +# define TLS1_RFC_DHE_PSK_WITH_AES_256_CCM "TLS_DHE_PSK_WITH_AES_256_CCM" +# define TLS1_RFC_PSK_WITH_AES_128_CCM_8 "TLS_PSK_WITH_AES_128_CCM_8" +# define TLS1_RFC_PSK_WITH_AES_256_CCM_8 "TLS_PSK_WITH_AES_256_CCM_8" +# define TLS1_RFC_DHE_PSK_WITH_AES_128_CCM_8 "TLS_PSK_DHE_WITH_AES_128_CCM_8" +# define TLS1_RFC_DHE_PSK_WITH_AES_256_CCM_8 "TLS_PSK_DHE_WITH_AES_256_CCM_8" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_128_CCM "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_256_CCM "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_128_CCM_8 "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_256_CCM_8 "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" +# define TLS1_3_RFC_AES_128_GCM_SHA256 "TLS_AES_128_GCM_SHA256" +# define TLS1_3_RFC_AES_256_GCM_SHA384 "TLS_AES_256_GCM_SHA384" +# define TLS1_3_RFC_CHACHA20_POLY1305_SHA256 "TLS_CHACHA20_POLY1305_SHA256" +# define TLS1_3_RFC_AES_128_CCM_SHA256 "TLS_AES_128_CCM_SHA256" +# define TLS1_3_RFC_AES_128_CCM_8_SHA256 "TLS_AES_128_CCM_8_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_NULL_SHA "TLS_ECDHE_ECDSA_WITH_NULL_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_ECDHE_RSA_WITH_NULL_SHA "TLS_ECDHE_RSA_WITH_NULL_SHA" +# define TLS1_RFC_ECDHE_RSA_WITH_DES_192_CBC3_SHA "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_128_CBC_SHA "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_256_CBC_SHA "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_ECDH_anon_WITH_NULL_SHA "TLS_ECDH_anon_WITH_NULL_SHA" +# define TLS1_RFC_ECDH_anon_WITH_DES_192_CBC3_SHA "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_ECDH_anon_WITH_AES_128_CBC_SHA "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_ECDH_anon_WITH_AES_256_CBC_SHA "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_128_SHA256 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_256_SHA384 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_128_SHA256 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_256_SHA384 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_128_GCM_SHA256 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_ECDHE_RSA_WITH_AES_256_GCM_SHA384 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_PSK_WITH_NULL_SHA "TLS_PSK_WITH_NULL_SHA" +# define TLS1_RFC_DHE_PSK_WITH_NULL_SHA "TLS_DHE_PSK_WITH_NULL_SHA" +# define TLS1_RFC_RSA_PSK_WITH_NULL_SHA "TLS_RSA_PSK_WITH_NULL_SHA" +# define TLS1_RFC_PSK_WITH_3DES_EDE_CBC_SHA "TLS_PSK_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_PSK_WITH_AES_128_CBC_SHA "TLS_PSK_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_PSK_WITH_AES_256_CBC_SHA "TLS_PSK_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_DHE_PSK_WITH_3DES_EDE_CBC_SHA "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_DHE_PSK_WITH_AES_128_CBC_SHA "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_DHE_PSK_WITH_AES_256_CBC_SHA "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_RSA_PSK_WITH_3DES_EDE_CBC_SHA "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_RSA_PSK_WITH_AES_128_CBC_SHA "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_RSA_PSK_WITH_AES_256_CBC_SHA "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_PSK_WITH_AES_128_GCM_SHA256 "TLS_PSK_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_PSK_WITH_AES_256_GCM_SHA384 "TLS_PSK_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_DHE_PSK_WITH_AES_128_GCM_SHA256 "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_AES_256_GCM_SHA384 "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_RSA_PSK_WITH_AES_128_GCM_SHA256 "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_AES_256_GCM_SHA384 "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" +# define TLS1_RFC_PSK_WITH_AES_128_CBC_SHA256 "TLS_PSK_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_PSK_WITH_AES_256_CBC_SHA384 "TLS_PSK_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_PSK_WITH_NULL_SHA256 "TLS_PSK_WITH_NULL_SHA256" +# define TLS1_RFC_PSK_WITH_NULL_SHA384 "TLS_PSK_WITH_NULL_SHA384" +# define TLS1_RFC_DHE_PSK_WITH_AES_128_CBC_SHA256 "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_AES_256_CBC_SHA384 "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_DHE_PSK_WITH_NULL_SHA256 "TLS_DHE_PSK_WITH_NULL_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_NULL_SHA384 "TLS_DHE_PSK_WITH_NULL_SHA384" +# define TLS1_RFC_RSA_PSK_WITH_AES_128_CBC_SHA256 "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_AES_256_CBC_SHA384 "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_RSA_PSK_WITH_NULL_SHA256 "TLS_RSA_PSK_WITH_NULL_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_NULL_SHA384 "TLS_RSA_PSK_WITH_NULL_SHA384" +# define TLS1_RFC_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_ECDHE_PSK_WITH_AES_128_CBC_SHA "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_ECDHE_PSK_WITH_AES_256_CBC_SHA "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_ECDHE_PSK_WITH_AES_128_CBC_SHA256 "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_PSK_WITH_AES_256_CBC_SHA384 "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" +# define TLS1_RFC_ECDHE_PSK_WITH_NULL_SHA "TLS_ECDHE_PSK_WITH_NULL_SHA" +# define TLS1_RFC_ECDHE_PSK_WITH_NULL_SHA256 "TLS_ECDHE_PSK_WITH_NULL_SHA256" +# define TLS1_RFC_ECDHE_PSK_WITH_NULL_SHA384 "TLS_ECDHE_PSK_WITH_NULL_SHA384" +# define TLS1_RFC_SRP_SHA_WITH_3DES_EDE_CBC_SHA "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" +# define TLS1_RFC_SRP_SHA_WITH_AES_128_CBC_SHA "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_SRP_SHA_RSA_WITH_AES_128_CBC_SHA "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_SRP_SHA_DSS_WITH_AES_128_CBC_SHA "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" +# define TLS1_RFC_SRP_SHA_WITH_AES_256_CBC_SHA "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_SRP_SHA_RSA_WITH_AES_256_CBC_SHA "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_SRP_SHA_DSS_WITH_AES_256_CBC_SHA "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_CHACHA20_POLY1305 "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_ECDHE_RSA_WITH_CHACHA20_POLY1305 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_PSK_WITH_CHACHA20_POLY1305 "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_ECDHE_PSK_WITH_CHACHA20_POLY1305 "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_CHACHA20_POLY1305 "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_CHACHA20_POLY1305 "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" +# define TLS1_RFC_RSA_WITH_CAMELLIA_128_CBC_SHA256 "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_ADH_WITH_CAMELLIA_128_CBC_SHA256 "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_RSA_WITH_CAMELLIA_256_CBC_SHA256 "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" +# define TLS1_RFC_ADH_WITH_CAMELLIA_256_CBC_SHA256 "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" +# define TLS1_RFC_RSA_WITH_CAMELLIA_256_CBC_SHA "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" +# define TLS1_RFC_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" +# define TLS1_RFC_ADH_WITH_CAMELLIA_256_CBC_SHA "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" +# define TLS1_RFC_RSA_WITH_CAMELLIA_128_CBC_SHA "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" +# define TLS1_RFC_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" +# define TLS1_RFC_ADH_WITH_CAMELLIA_128_CBC_SHA "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_PSK_WITH_CAMELLIA_128_CBC_SHA256 "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_PSK_WITH_CAMELLIA_256_CBC_SHA384 "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" +# define TLS1_RFC_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" +# define TLS1_RFC_RSA_WITH_SEED_SHA "TLS_RSA_WITH_SEED_CBC_SHA" +# define TLS1_RFC_DHE_DSS_WITH_SEED_SHA "TLS_DHE_DSS_WITH_SEED_CBC_SHA" +# define TLS1_RFC_DHE_RSA_WITH_SEED_SHA "TLS_DHE_RSA_WITH_SEED_CBC_SHA" +# define TLS1_RFC_ADH_WITH_SEED_SHA "TLS_DH_anon_WITH_SEED_CBC_SHA" +# define TLS1_RFC_ECDHE_PSK_WITH_RC4_128_SHA "TLS_ECDHE_PSK_WITH_RC4_128_SHA" +# define TLS1_RFC_ECDH_anon_WITH_RC4_128_SHA "TLS_ECDH_anon_WITH_RC4_128_SHA" +# define TLS1_RFC_ECDHE_ECDSA_WITH_RC4_128_SHA "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" +# define TLS1_RFC_ECDHE_RSA_WITH_RC4_128_SHA "TLS_ECDHE_RSA_WITH_RC4_128_SHA" +# define TLS1_RFC_PSK_WITH_RC4_128_SHA "TLS_PSK_WITH_RC4_128_SHA" +# define TLS1_RFC_RSA_PSK_WITH_RC4_128_SHA "TLS_RSA_PSK_WITH_RC4_128_SHA" +# define TLS1_RFC_DHE_PSK_WITH_RC4_128_SHA "TLS_DHE_PSK_WITH_RC4_128_SHA" +# define TLS1_RFC_RSA_WITH_ARIA_128_GCM_SHA256 "TLS_RSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_RSA_WITH_ARIA_256_GCM_SHA384 "TLS_RSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DHE_RSA_WITH_ARIA_128_GCM_SHA256 "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DHE_RSA_WITH_ARIA_256_GCM_SHA384 "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DH_RSA_WITH_ARIA_128_GCM_SHA256 "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DH_RSA_WITH_ARIA_256_GCM_SHA384 "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DHE_DSS_WITH_ARIA_128_GCM_SHA256 "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DHE_DSS_WITH_ARIA_256_GCM_SHA384 "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DH_DSS_WITH_ARIA_128_GCM_SHA256 "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DH_DSS_WITH_ARIA_256_GCM_SHA384 "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DH_anon_WITH_ARIA_128_GCM_SHA256 "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DH_anon_WITH_ARIA_256_GCM_SHA384 "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_PSK_WITH_ARIA_128_GCM_SHA256 "TLS_PSK_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_PSK_WITH_ARIA_256_GCM_SHA384 "TLS_PSK_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_DHE_PSK_WITH_ARIA_128_GCM_SHA256 "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_DHE_PSK_WITH_ARIA_256_GCM_SHA384 "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" +# define TLS1_RFC_RSA_PSK_WITH_ARIA_128_GCM_SHA256 "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" +# define TLS1_RFC_RSA_PSK_WITH_ARIA_256_GCM_SHA384 "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" + + +/* + * XXX Backward compatibility alert: Older versions of OpenSSL gave some DHE + * ciphers names with "EDH" instead of "DHE". Going forward, we should be + * using DHE everywhere, though we may indefinitely maintain aliases for + * users or configurations that used "EDH" + */ +# define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA" + +# define TLS1_TXT_PSK_WITH_NULL_SHA "PSK-NULL-SHA" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA "DHE-PSK-NULL-SHA" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA "RSA-PSK-NULL-SHA" + +/* AES ciphersuites from RFC3268 */ +# define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA" +# define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA" +# define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA" +# define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA" + +# define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA" +# define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA" +# define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" +# define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" + +/* ECC ciphersuites from RFC4492 */ +# define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA "ECDH-ECDSA-NULL-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA "ECDH-ECDSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA" + +# define TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA "ECDHE-ECDSA-NULL-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "ECDHE-ECDSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA" + +# define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA "ECDH-RSA-NULL-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA "ECDH-RSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA" + +# define TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA "ECDHE-RSA-NULL-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA "ECDHE-RSA-DES-CBC3-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA" + +# define TLS1_TXT_ECDH_anon_WITH_NULL_SHA "AECDH-NULL-SHA" +# define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA "AECDH-RC4-SHA" +# define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA "AECDH-DES-CBC3-SHA" +# define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA "AECDH-AES128-SHA" +# define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA "AECDH-AES256-SHA" + +/* PSK ciphersuites from RFC 4279 */ +# define TLS1_TXT_PSK_WITH_RC4_128_SHA "PSK-RC4-SHA" +# define TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA "PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA "PSK-AES128-CBC-SHA" +# define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA "PSK-AES256-CBC-SHA" + +# define TLS1_TXT_DHE_PSK_WITH_RC4_128_SHA "DHE-PSK-RC4-SHA" +# define TLS1_TXT_DHE_PSK_WITH_3DES_EDE_CBC_SHA "DHE-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CBC_SHA "DHE-PSK-AES128-CBC-SHA" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CBC_SHA "DHE-PSK-AES256-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_RC4_128_SHA "RSA-PSK-RC4-SHA" +# define TLS1_TXT_RSA_PSK_WITH_3DES_EDE_CBC_SHA "RSA-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_AES_128_CBC_SHA "RSA-PSK-AES128-CBC-SHA" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_CBC_SHA "RSA-PSK-AES256-CBC-SHA" + +/* PSK ciphersuites from RFC 5487 */ +# define TLS1_TXT_PSK_WITH_AES_128_GCM_SHA256 "PSK-AES128-GCM-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_GCM_SHA384 "PSK-AES256-GCM-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_GCM_SHA256 "DHE-PSK-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_GCM_SHA384 "DHE-PSK-AES256-GCM-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_AES_128_GCM_SHA256 "RSA-PSK-AES128-GCM-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_GCM_SHA384 "RSA-PSK-AES256-GCM-SHA384" + +# define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA256 "PSK-AES128-CBC-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA384 "PSK-AES256-CBC-SHA384" +# define TLS1_TXT_PSK_WITH_NULL_SHA256 "PSK-NULL-SHA256" +# define TLS1_TXT_PSK_WITH_NULL_SHA384 "PSK-NULL-SHA384" + +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CBC_SHA256 "DHE-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CBC_SHA384 "DHE-PSK-AES256-CBC-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA256 "DHE-PSK-NULL-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_NULL_SHA384 "DHE-PSK-NULL-SHA384" + +# define TLS1_TXT_RSA_PSK_WITH_AES_128_CBC_SHA256 "RSA-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_AES_256_CBC_SHA384 "RSA-PSK-AES256-CBC-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA256 "RSA-PSK-NULL-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_NULL_SHA384 "RSA-PSK-NULL-SHA384" + +/* SRP ciphersuite from RFC 5054 */ +# define TLS1_TXT_SRP_SHA_WITH_3DES_EDE_CBC_SHA "SRP-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA "SRP-RSA-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA "SRP-DSS-3DES-EDE-CBC-SHA" +# define TLS1_TXT_SRP_SHA_WITH_AES_128_CBC_SHA "SRP-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_AES_128_CBC_SHA "SRP-RSA-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_AES_128_CBC_SHA "SRP-DSS-AES-128-CBC-SHA" +# define TLS1_TXT_SRP_SHA_WITH_AES_256_CBC_SHA "SRP-AES-256-CBC-SHA" +# define TLS1_TXT_SRP_SHA_RSA_WITH_AES_256_CBC_SHA "SRP-RSA-AES-256-CBC-SHA" +# define TLS1_TXT_SRP_SHA_DSS_WITH_AES_256_CBC_SHA "SRP-DSS-AES-256-CBC-SHA" + +/* Camellia ciphersuites from RFC4132 */ +# define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA "DH-DSS-CAMELLIA128-SHA" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA "DH-RSA-CAMELLIA128-SHA" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "DHE-DSS-CAMELLIA128-SHA" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA" +# define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA "ADH-CAMELLIA128-SHA" + +# define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA "DH-DSS-CAMELLIA256-SHA" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA "DH-RSA-CAMELLIA256-SHA" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "DHE-DSS-CAMELLIA256-SHA" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA" +# define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA "ADH-CAMELLIA256-SHA" + +/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */ +# define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA256 "CAMELLIA128-SHA256" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DH-DSS-CAMELLIA128-SHA256" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DH-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DHE-DSS-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DHE-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA256 "ADH-CAMELLIA128-SHA256" + +# define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA256 "CAMELLIA256-SHA256" +# define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DH-DSS-CAMELLIA256-SHA256" +# define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DH-RSA-CAMELLIA256-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DHE-DSS-CAMELLIA256-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DHE-RSA-CAMELLIA256-SHA256" +# define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA256 "ADH-CAMELLIA256-SHA256" + +# define TLS1_TXT_PSK_WITH_CAMELLIA_128_CBC_SHA256 "PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_PSK_WITH_CAMELLIA_256_CBC_SHA384 "PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "DHE-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "DHE-PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 "RSA-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 "RSA-PSK-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-PSK-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-PSK-CAMELLIA256-SHA384" + +/* SEED ciphersuites from RFC4162 */ +# define TLS1_TXT_RSA_WITH_SEED_SHA "SEED-SHA" +# define TLS1_TXT_DH_DSS_WITH_SEED_SHA "DH-DSS-SEED-SHA" +# define TLS1_TXT_DH_RSA_WITH_SEED_SHA "DH-RSA-SEED-SHA" +# define TLS1_TXT_DHE_DSS_WITH_SEED_SHA "DHE-DSS-SEED-SHA" +# define TLS1_TXT_DHE_RSA_WITH_SEED_SHA "DHE-RSA-SEED-SHA" +# define TLS1_TXT_ADH_WITH_SEED_SHA "ADH-SEED-SHA" + +/* TLS v1.2 ciphersuites */ +# define TLS1_TXT_RSA_WITH_NULL_SHA256 "NULL-SHA256" +# define TLS1_TXT_RSA_WITH_AES_128_SHA256 "AES128-SHA256" +# define TLS1_TXT_RSA_WITH_AES_256_SHA256 "AES256-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_128_SHA256 "DH-DSS-AES128-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_128_SHA256 "DH-RSA-AES128-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA256 "DHE-DSS-AES128-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA256 "DHE-RSA-AES128-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_256_SHA256 "DH-DSS-AES256-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_256_SHA256 "DH-RSA-AES256-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA256 "DHE-DSS-AES256-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA256 "DHE-RSA-AES256-SHA256" +# define TLS1_TXT_ADH_WITH_AES_128_SHA256 "ADH-AES128-SHA256" +# define TLS1_TXT_ADH_WITH_AES_256_SHA256 "ADH-AES256-SHA256" + +/* TLS v1.2 GCM ciphersuites from RFC5288 */ +# define TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256 "AES128-GCM-SHA256" +# define TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384 "AES256-GCM-SHA384" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_GCM_SHA256 "DHE-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_GCM_SHA384 "DHE-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_DH_RSA_WITH_AES_128_GCM_SHA256 "DH-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_DH_RSA_WITH_AES_256_GCM_SHA384 "DH-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_DHE_DSS_WITH_AES_128_GCM_SHA256 "DHE-DSS-AES128-GCM-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_AES_256_GCM_SHA384 "DHE-DSS-AES256-GCM-SHA384" +# define TLS1_TXT_DH_DSS_WITH_AES_128_GCM_SHA256 "DH-DSS-AES128-GCM-SHA256" +# define TLS1_TXT_DH_DSS_WITH_AES_256_GCM_SHA384 "DH-DSS-AES256-GCM-SHA384" +# define TLS1_TXT_ADH_WITH_AES_128_GCM_SHA256 "ADH-AES128-GCM-SHA256" +# define TLS1_TXT_ADH_WITH_AES_256_GCM_SHA384 "ADH-AES256-GCM-SHA384" + +/* CCM ciphersuites from RFC6655 */ +# define TLS1_TXT_RSA_WITH_AES_128_CCM "AES128-CCM" +# define TLS1_TXT_RSA_WITH_AES_256_CCM "AES256-CCM" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_CCM "DHE-RSA-AES128-CCM" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_CCM "DHE-RSA-AES256-CCM" + +# define TLS1_TXT_RSA_WITH_AES_128_CCM_8 "AES128-CCM8" +# define TLS1_TXT_RSA_WITH_AES_256_CCM_8 "AES256-CCM8" +# define TLS1_TXT_DHE_RSA_WITH_AES_128_CCM_8 "DHE-RSA-AES128-CCM8" +# define TLS1_TXT_DHE_RSA_WITH_AES_256_CCM_8 "DHE-RSA-AES256-CCM8" + +# define TLS1_TXT_PSK_WITH_AES_128_CCM "PSK-AES128-CCM" +# define TLS1_TXT_PSK_WITH_AES_256_CCM "PSK-AES256-CCM" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CCM "DHE-PSK-AES128-CCM" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CCM "DHE-PSK-AES256-CCM" + +# define TLS1_TXT_PSK_WITH_AES_128_CCM_8 "PSK-AES128-CCM8" +# define TLS1_TXT_PSK_WITH_AES_256_CCM_8 "PSK-AES256-CCM8" +# define TLS1_TXT_DHE_PSK_WITH_AES_128_CCM_8 "DHE-PSK-AES128-CCM8" +# define TLS1_TXT_DHE_PSK_WITH_AES_256_CCM_8 "DHE-PSK-AES256-CCM8" + +/* CCM ciphersuites from RFC7251 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CCM "ECDHE-ECDSA-AES128-CCM" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CCM "ECDHE-ECDSA-AES256-CCM" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CCM_8 "ECDHE-ECDSA-AES128-CCM8" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CCM_8 "ECDHE-ECDSA-AES256-CCM8" + +/* ECDH HMAC based ciphersuites from RFC5289 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_SHA256 "ECDHE-ECDSA-AES128-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_SHA384 "ECDHE-ECDSA-AES256-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_SHA256 "ECDH-ECDSA-AES128-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_SHA384 "ECDH-ECDSA-AES256-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_SHA256 "ECDHE-RSA-AES128-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_SHA384 "ECDHE-RSA-AES256-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_SHA256 "ECDH-RSA-AES128-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_SHA384 "ECDH-RSA-AES256-SHA384" + +/* ECDH GCM based ciphersuites from RFC5289 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 "ECDHE-ECDSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 "ECDHE-ECDSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 "ECDH-ECDSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 "ECDH-ECDSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256 "ECDHE-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384 "ECDHE-RSA-AES256-GCM-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_AES_128_GCM_SHA256 "ECDH-RSA-AES128-GCM-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_AES_256_GCM_SHA384 "ECDH-RSA-AES256-GCM-SHA384" + +/* TLS v1.2 PSK GCM ciphersuites from RFC5487 */ +# define TLS1_TXT_PSK_WITH_AES_128_GCM_SHA256 "PSK-AES128-GCM-SHA256" +# define TLS1_TXT_PSK_WITH_AES_256_GCM_SHA384 "PSK-AES256-GCM-SHA384" + +/* ECDHE PSK ciphersuites from RFC 5489 */ +# define TLS1_TXT_ECDHE_PSK_WITH_RC4_128_SHA "ECDHE-PSK-RC4-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA "ECDHE-PSK-3DES-EDE-CBC-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA "ECDHE-PSK-AES128-CBC-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA "ECDHE-PSK-AES256-CBC-SHA" + +# define TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA256 "ECDHE-PSK-AES128-CBC-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA384 "ECDHE-PSK-AES256-CBC-SHA384" + +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA "ECDHE-PSK-NULL-SHA" +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA256 "ECDHE-PSK-NULL-SHA256" +# define TLS1_TXT_ECDHE_PSK_WITH_NULL_SHA384 "ECDHE-PSK-NULL-SHA384" + +/* Camellia-CBC ciphersuites from RFC6367 */ +# define TLS1_TXT_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-ECDSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-ECDSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDH-ECDSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDH-ECDSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDHE-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDHE-RSA-CAMELLIA256-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 "ECDH-RSA-CAMELLIA128-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 "ECDH-RSA-CAMELLIA256-SHA384" + +/* draft-ietf-tls-chacha20-poly1305-03 */ +# define TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305 "ECDHE-RSA-CHACHA20-POLY1305" +# define TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 "ECDHE-ECDSA-CHACHA20-POLY1305" +# define TLS1_TXT_DHE_RSA_WITH_CHACHA20_POLY1305 "DHE-RSA-CHACHA20-POLY1305" +# define TLS1_TXT_PSK_WITH_CHACHA20_POLY1305 "PSK-CHACHA20-POLY1305" +# define TLS1_TXT_ECDHE_PSK_WITH_CHACHA20_POLY1305 "ECDHE-PSK-CHACHA20-POLY1305" +# define TLS1_TXT_DHE_PSK_WITH_CHACHA20_POLY1305 "DHE-PSK-CHACHA20-POLY1305" +# define TLS1_TXT_RSA_PSK_WITH_CHACHA20_POLY1305 "RSA-PSK-CHACHA20-POLY1305" + +/* Aria ciphersuites from RFC6209 */ +# define TLS1_TXT_RSA_WITH_ARIA_128_GCM_SHA256 "ARIA128-GCM-SHA256" +# define TLS1_TXT_RSA_WITH_ARIA_256_GCM_SHA384 "ARIA256-GCM-SHA384" +# define TLS1_TXT_DHE_RSA_WITH_ARIA_128_GCM_SHA256 "DHE-RSA-ARIA128-GCM-SHA256" +# define TLS1_TXT_DHE_RSA_WITH_ARIA_256_GCM_SHA384 "DHE-RSA-ARIA256-GCM-SHA384" +# define TLS1_TXT_DH_RSA_WITH_ARIA_128_GCM_SHA256 "DH-RSA-ARIA128-GCM-SHA256" +# define TLS1_TXT_DH_RSA_WITH_ARIA_256_GCM_SHA384 "DH-RSA-ARIA256-GCM-SHA384" +# define TLS1_TXT_DHE_DSS_WITH_ARIA_128_GCM_SHA256 "DHE-DSS-ARIA128-GCM-SHA256" +# define TLS1_TXT_DHE_DSS_WITH_ARIA_256_GCM_SHA384 "DHE-DSS-ARIA256-GCM-SHA384" +# define TLS1_TXT_DH_DSS_WITH_ARIA_128_GCM_SHA256 "DH-DSS-ARIA128-GCM-SHA256" +# define TLS1_TXT_DH_DSS_WITH_ARIA_256_GCM_SHA384 "DH-DSS-ARIA256-GCM-SHA384" +# define TLS1_TXT_DH_anon_WITH_ARIA_128_GCM_SHA256 "ADH-ARIA128-GCM-SHA256" +# define TLS1_TXT_DH_anon_WITH_ARIA_256_GCM_SHA384 "ADH-ARIA256-GCM-SHA384" +# define TLS1_TXT_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 "ECDHE-ECDSA-ARIA128-GCM-SHA256" +# define TLS1_TXT_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 "ECDHE-ECDSA-ARIA256-GCM-SHA384" +# define TLS1_TXT_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 "ECDH-ECDSA-ARIA128-GCM-SHA256" +# define TLS1_TXT_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 "ECDH-ECDSA-ARIA256-GCM-SHA384" +# define TLS1_TXT_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 "ECDHE-ARIA128-GCM-SHA256" +# define TLS1_TXT_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 "ECDHE-ARIA256-GCM-SHA384" +# define TLS1_TXT_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 "ECDH-ARIA128-GCM-SHA256" +# define TLS1_TXT_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 "ECDH-ARIA256-GCM-SHA384" +# define TLS1_TXT_PSK_WITH_ARIA_128_GCM_SHA256 "PSK-ARIA128-GCM-SHA256" +# define TLS1_TXT_PSK_WITH_ARIA_256_GCM_SHA384 "PSK-ARIA256-GCM-SHA384" +# define TLS1_TXT_DHE_PSK_WITH_ARIA_128_GCM_SHA256 "DHE-PSK-ARIA128-GCM-SHA256" +# define TLS1_TXT_DHE_PSK_WITH_ARIA_256_GCM_SHA384 "DHE-PSK-ARIA256-GCM-SHA384" +# define TLS1_TXT_RSA_PSK_WITH_ARIA_128_GCM_SHA256 "RSA-PSK-ARIA128-GCM-SHA256" +# define TLS1_TXT_RSA_PSK_WITH_ARIA_256_GCM_SHA384 "RSA-PSK-ARIA256-GCM-SHA384" + +# define TLS_CT_RSA_SIGN 1 +# define TLS_CT_DSS_SIGN 2 +# define TLS_CT_RSA_FIXED_DH 3 +# define TLS_CT_DSS_FIXED_DH 4 +# define TLS_CT_ECDSA_SIGN 64 +# define TLS_CT_RSA_FIXED_ECDH 65 +# define TLS_CT_ECDSA_FIXED_ECDH 66 +# define TLS_CT_GOST01_SIGN 22 +# define TLS_CT_GOST12_SIGN 238 +# define TLS_CT_GOST12_512_SIGN 239 + +/* + * when correcting this number, correct also SSL3_CT_NUMBER in ssl3.h (see + * comment there) + */ +# define TLS_CT_NUMBER 10 + +# if defined(SSL3_CT_NUMBER) +# if TLS_CT_NUMBER != SSL3_CT_NUMBER +# error "SSL/TLS CT_NUMBER values do not match" +# endif +# endif + +# define TLS1_FINISH_MAC_LENGTH 12 + +# define TLS_MD_MAX_CONST_SIZE 22 +# define TLS_MD_CLIENT_FINISH_CONST "client finished" +# define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 +# define TLS_MD_SERVER_FINISH_CONST "server finished" +# define TLS_MD_SERVER_FINISH_CONST_SIZE 15 +# define TLS_MD_KEY_EXPANSION_CONST "key expansion" +# define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 +# define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" +# define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 +# define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" +# define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 +# define TLS_MD_IV_BLOCK_CONST "IV block" +# define TLS_MD_IV_BLOCK_CONST_SIZE 8 +# define TLS_MD_MASTER_SECRET_CONST "master secret" +# define TLS_MD_MASTER_SECRET_CONST_SIZE 13 +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST "extended master secret" +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE 22 + +# ifdef CHARSET_EBCDIC +# undef TLS_MD_CLIENT_FINISH_CONST +/* + * client finished + */ +# define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" + +# undef TLS_MD_SERVER_FINISH_CONST +/* + * server finished + */ +# define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" + +# undef TLS_MD_SERVER_WRITE_KEY_CONST +/* + * server write key + */ +# define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_KEY_EXPANSION_CONST +/* + * key expansion + */ +# define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" + +# undef TLS_MD_CLIENT_WRITE_KEY_CONST +/* + * client write key + */ +# define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_SERVER_WRITE_KEY_CONST +/* + * server write key + */ +# define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" + +# undef TLS_MD_IV_BLOCK_CONST +/* + * IV block + */ +# define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" + +# undef TLS_MD_MASTER_SECRET_CONST +/* + * master secret + */ +# define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" +# undef TLS_MD_EXTENDED_MASTER_SECRET_CONST +/* + * extended master secret + */ +# define TLS_MD_EXTENDED_MASTER_SECRET_CONST "\x65\x78\x74\x65\x6e\x64\x65\x64\x20\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" +# endif + +/* TLS Session Ticket extension struct */ +struct tls_session_ticket_ext_st { + unsigned short length; + void *data; +}; + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/tserr.h postgresql-hll-2.14/include/openssl/tserr.h --- postgresql-hll-2.14_old/include/openssl/tserr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/tserr.h 2020-12-12 17:06:43.342349264 +0800 @@ -0,0 +1,132 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TSERR_H +# define HEADER_TSERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# include + +# ifndef OPENSSL_NO_TS + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_TS_strings(void); + +/* + * TS function codes. + */ +# define TS_F_DEF_SERIAL_CB 110 +# define TS_F_DEF_TIME_CB 111 +# define TS_F_ESS_ADD_SIGNING_CERT 112 +# define TS_F_ESS_ADD_SIGNING_CERT_V2 147 +# define TS_F_ESS_CERT_ID_NEW_INIT 113 +# define TS_F_ESS_CERT_ID_V2_NEW_INIT 156 +# define TS_F_ESS_SIGNING_CERT_NEW_INIT 114 +# define TS_F_ESS_SIGNING_CERT_V2_NEW_INIT 157 +# define TS_F_INT_TS_RESP_VERIFY_TOKEN 149 +# define TS_F_PKCS7_TO_TS_TST_INFO 148 +# define TS_F_TS_ACCURACY_SET_MICROS 115 +# define TS_F_TS_ACCURACY_SET_MILLIS 116 +# define TS_F_TS_ACCURACY_SET_SECONDS 117 +# define TS_F_TS_CHECK_IMPRINTS 100 +# define TS_F_TS_CHECK_NONCES 101 +# define TS_F_TS_CHECK_POLICY 102 +# define TS_F_TS_CHECK_SIGNING_CERTS 103 +# define TS_F_TS_CHECK_STATUS_INFO 104 +# define TS_F_TS_COMPUTE_IMPRINT 145 +# define TS_F_TS_CONF_INVALID 151 +# define TS_F_TS_CONF_LOAD_CERT 153 +# define TS_F_TS_CONF_LOAD_CERTS 154 +# define TS_F_TS_CONF_LOAD_KEY 155 +# define TS_F_TS_CONF_LOOKUP_FAIL 152 +# define TS_F_TS_CONF_SET_DEFAULT_ENGINE 146 +# define TS_F_TS_GET_STATUS_TEXT 105 +# define TS_F_TS_MSG_IMPRINT_SET_ALGO 118 +# define TS_F_TS_REQ_SET_MSG_IMPRINT 119 +# define TS_F_TS_REQ_SET_NONCE 120 +# define TS_F_TS_REQ_SET_POLICY_ID 121 +# define TS_F_TS_RESP_CREATE_RESPONSE 122 +# define TS_F_TS_RESP_CREATE_TST_INFO 123 +# define TS_F_TS_RESP_CTX_ADD_FAILURE_INFO 124 +# define TS_F_TS_RESP_CTX_ADD_MD 125 +# define TS_F_TS_RESP_CTX_ADD_POLICY 126 +# define TS_F_TS_RESP_CTX_NEW 127 +# define TS_F_TS_RESP_CTX_SET_ACCURACY 128 +# define TS_F_TS_RESP_CTX_SET_CERTS 129 +# define TS_F_TS_RESP_CTX_SET_DEF_POLICY 130 +# define TS_F_TS_RESP_CTX_SET_SIGNER_CERT 131 +# define TS_F_TS_RESP_CTX_SET_STATUS_INFO 132 +# define TS_F_TS_RESP_GET_POLICY 133 +# define TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION 134 +# define TS_F_TS_RESP_SET_STATUS_INFO 135 +# define TS_F_TS_RESP_SET_TST_INFO 150 +# define TS_F_TS_RESP_SIGN 136 +# define TS_F_TS_RESP_VERIFY_SIGNATURE 106 +# define TS_F_TS_TST_INFO_SET_ACCURACY 137 +# define TS_F_TS_TST_INFO_SET_MSG_IMPRINT 138 +# define TS_F_TS_TST_INFO_SET_NONCE 139 +# define TS_F_TS_TST_INFO_SET_POLICY_ID 140 +# define TS_F_TS_TST_INFO_SET_SERIAL 141 +# define TS_F_TS_TST_INFO_SET_TIME 142 +# define TS_F_TS_TST_INFO_SET_TSA 143 +# define TS_F_TS_VERIFY 108 +# define TS_F_TS_VERIFY_CERT 109 +# define TS_F_TS_VERIFY_CTX_NEW 144 + +/* + * TS reason codes. + */ +# define TS_R_BAD_PKCS7_TYPE 132 +# define TS_R_BAD_TYPE 133 +# define TS_R_CANNOT_LOAD_CERT 137 +# define TS_R_CANNOT_LOAD_KEY 138 +# define TS_R_CERTIFICATE_VERIFY_ERROR 100 +# define TS_R_COULD_NOT_SET_ENGINE 127 +# define TS_R_COULD_NOT_SET_TIME 115 +# define TS_R_DETACHED_CONTENT 134 +# define TS_R_ESS_ADD_SIGNING_CERT_ERROR 116 +# define TS_R_ESS_ADD_SIGNING_CERT_V2_ERROR 139 +# define TS_R_ESS_SIGNING_CERTIFICATE_ERROR 101 +# define TS_R_INVALID_NULL_POINTER 102 +# define TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE 117 +# define TS_R_MESSAGE_IMPRINT_MISMATCH 103 +# define TS_R_NONCE_MISMATCH 104 +# define TS_R_NONCE_NOT_RETURNED 105 +# define TS_R_NO_CONTENT 106 +# define TS_R_NO_TIME_STAMP_TOKEN 107 +# define TS_R_PKCS7_ADD_SIGNATURE_ERROR 118 +# define TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR 119 +# define TS_R_PKCS7_TO_TS_TST_INFO_FAILED 129 +# define TS_R_POLICY_MISMATCH 108 +# define TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 120 +# define TS_R_RESPONSE_SETUP_ERROR 121 +# define TS_R_SIGNATURE_FAILURE 109 +# define TS_R_THERE_MUST_BE_ONE_SIGNER 110 +# define TS_R_TIME_SYSCALL_ERROR 122 +# define TS_R_TOKEN_NOT_PRESENT 130 +# define TS_R_TOKEN_PRESENT 131 +# define TS_R_TSA_NAME_MISMATCH 111 +# define TS_R_TSA_UNTRUSTED 112 +# define TS_R_TST_INFO_SETUP_ERROR 123 +# define TS_R_TS_DATASIGN 124 +# define TS_R_UNACCEPTABLE_POLICY 125 +# define TS_R_UNSUPPORTED_MD_ALGORITHM 126 +# define TS_R_UNSUPPORTED_VERSION 113 +# define TS_R_VAR_BAD_VALUE 135 +# define TS_R_VAR_LOOKUP_FAILURE 136 +# define TS_R_WRONG_CONTENT_TYPE 114 + +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ts.h postgresql-hll-2.14/include/openssl/ts.h --- postgresql-hll-2.14_old/include/openssl/ts.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ts.h 2020-12-12 17:06:43.342349264 +0800 @@ -0,0 +1,559 @@ +/* + * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TS_H +# define HEADER_TS_H + +# include + +# ifndef OPENSSL_NO_TS +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +# include +# include + +typedef struct TS_msg_imprint_st TS_MSG_IMPRINT; +typedef struct TS_req_st TS_REQ; +typedef struct TS_accuracy_st TS_ACCURACY; +typedef struct TS_tst_info_st TS_TST_INFO; + +/* Possible values for status. */ +# define TS_STATUS_GRANTED 0 +# define TS_STATUS_GRANTED_WITH_MODS 1 +# define TS_STATUS_REJECTION 2 +# define TS_STATUS_WAITING 3 +# define TS_STATUS_REVOCATION_WARNING 4 +# define TS_STATUS_REVOCATION_NOTIFICATION 5 + +/* Possible values for failure_info. */ +# define TS_INFO_BAD_ALG 0 +# define TS_INFO_BAD_REQUEST 2 +# define TS_INFO_BAD_DATA_FORMAT 5 +# define TS_INFO_TIME_NOT_AVAILABLE 14 +# define TS_INFO_UNACCEPTED_POLICY 15 +# define TS_INFO_UNACCEPTED_EXTENSION 16 +# define TS_INFO_ADD_INFO_NOT_AVAILABLE 17 +# define TS_INFO_SYSTEM_FAILURE 25 + + +typedef struct TS_status_info_st TS_STATUS_INFO; +typedef struct ESS_issuer_serial ESS_ISSUER_SERIAL; +typedef struct ESS_cert_id ESS_CERT_ID; +typedef struct ESS_signing_cert ESS_SIGNING_CERT; + +DEFINE_STACK_OF(ESS_CERT_ID) + +typedef struct ESS_cert_id_v2_st ESS_CERT_ID_V2; +typedef struct ESS_signing_cert_v2_st ESS_SIGNING_CERT_V2; + +DEFINE_STACK_OF(ESS_CERT_ID_V2) + +typedef struct TS_resp_st TS_RESP; + +TS_REQ *TS_REQ_new(void); +void TS_REQ_free(TS_REQ *a); +int i2d_TS_REQ(const TS_REQ *a, unsigned char **pp); +TS_REQ *d2i_TS_REQ(TS_REQ **a, const unsigned char **pp, long length); + +TS_REQ *TS_REQ_dup(TS_REQ *a); + +#ifndef OPENSSL_NO_STDIO +TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a); +int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a); +#endif +TS_REQ *d2i_TS_REQ_bio(BIO *fp, TS_REQ **a); +int i2d_TS_REQ_bio(BIO *fp, TS_REQ *a); + +TS_MSG_IMPRINT *TS_MSG_IMPRINT_new(void); +void TS_MSG_IMPRINT_free(TS_MSG_IMPRINT *a); +int i2d_TS_MSG_IMPRINT(const TS_MSG_IMPRINT *a, unsigned char **pp); +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT(TS_MSG_IMPRINT **a, + const unsigned char **pp, long length); + +TS_MSG_IMPRINT *TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *a); + +#ifndef OPENSSL_NO_STDIO +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a); +int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a); +#endif +TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT **a); +int i2d_TS_MSG_IMPRINT_bio(BIO *bio, TS_MSG_IMPRINT *a); + +TS_RESP *TS_RESP_new(void); +void TS_RESP_free(TS_RESP *a); +int i2d_TS_RESP(const TS_RESP *a, unsigned char **pp); +TS_RESP *d2i_TS_RESP(TS_RESP **a, const unsigned char **pp, long length); +TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token); +TS_RESP *TS_RESP_dup(TS_RESP *a); + +#ifndef OPENSSL_NO_STDIO +TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a); +int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a); +#endif +TS_RESP *d2i_TS_RESP_bio(BIO *bio, TS_RESP **a); +int i2d_TS_RESP_bio(BIO *bio, TS_RESP *a); + +TS_STATUS_INFO *TS_STATUS_INFO_new(void); +void TS_STATUS_INFO_free(TS_STATUS_INFO *a); +int i2d_TS_STATUS_INFO(const TS_STATUS_INFO *a, unsigned char **pp); +TS_STATUS_INFO *d2i_TS_STATUS_INFO(TS_STATUS_INFO **a, + const unsigned char **pp, long length); +TS_STATUS_INFO *TS_STATUS_INFO_dup(TS_STATUS_INFO *a); + +TS_TST_INFO *TS_TST_INFO_new(void); +void TS_TST_INFO_free(TS_TST_INFO *a); +int i2d_TS_TST_INFO(const TS_TST_INFO *a, unsigned char **pp); +TS_TST_INFO *d2i_TS_TST_INFO(TS_TST_INFO **a, const unsigned char **pp, + long length); +TS_TST_INFO *TS_TST_INFO_dup(TS_TST_INFO *a); + +#ifndef OPENSSL_NO_STDIO +TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a); +int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a); +#endif +TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO **a); +int i2d_TS_TST_INFO_bio(BIO *bio, TS_TST_INFO *a); + +TS_ACCURACY *TS_ACCURACY_new(void); +void TS_ACCURACY_free(TS_ACCURACY *a); +int i2d_TS_ACCURACY(const TS_ACCURACY *a, unsigned char **pp); +TS_ACCURACY *d2i_TS_ACCURACY(TS_ACCURACY **a, const unsigned char **pp, + long length); +TS_ACCURACY *TS_ACCURACY_dup(TS_ACCURACY *a); + +ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_new(void); +void ESS_ISSUER_SERIAL_free(ESS_ISSUER_SERIAL *a); +int i2d_ESS_ISSUER_SERIAL(const ESS_ISSUER_SERIAL *a, unsigned char **pp); +ESS_ISSUER_SERIAL *d2i_ESS_ISSUER_SERIAL(ESS_ISSUER_SERIAL **a, + const unsigned char **pp, + long length); +ESS_ISSUER_SERIAL *ESS_ISSUER_SERIAL_dup(ESS_ISSUER_SERIAL *a); + +ESS_CERT_ID *ESS_CERT_ID_new(void); +void ESS_CERT_ID_free(ESS_CERT_ID *a); +int i2d_ESS_CERT_ID(const ESS_CERT_ID *a, unsigned char **pp); +ESS_CERT_ID *d2i_ESS_CERT_ID(ESS_CERT_ID **a, const unsigned char **pp, + long length); +ESS_CERT_ID *ESS_CERT_ID_dup(ESS_CERT_ID *a); + +ESS_SIGNING_CERT *ESS_SIGNING_CERT_new(void); +void ESS_SIGNING_CERT_free(ESS_SIGNING_CERT *a); +int i2d_ESS_SIGNING_CERT(const ESS_SIGNING_CERT *a, unsigned char **pp); +ESS_SIGNING_CERT *d2i_ESS_SIGNING_CERT(ESS_SIGNING_CERT **a, + const unsigned char **pp, long length); +ESS_SIGNING_CERT *ESS_SIGNING_CERT_dup(ESS_SIGNING_CERT *a); + +ESS_CERT_ID_V2 *ESS_CERT_ID_V2_new(void); +void ESS_CERT_ID_V2_free(ESS_CERT_ID_V2 *a); +int i2d_ESS_CERT_ID_V2(const ESS_CERT_ID_V2 *a, unsigned char **pp); +ESS_CERT_ID_V2 *d2i_ESS_CERT_ID_V2(ESS_CERT_ID_V2 **a, + const unsigned char **pp, long length); +ESS_CERT_ID_V2 *ESS_CERT_ID_V2_dup(ESS_CERT_ID_V2 *a); + +ESS_SIGNING_CERT_V2 *ESS_SIGNING_CERT_V2_new(void); +void ESS_SIGNING_CERT_V2_free(ESS_SIGNING_CERT_V2 *a); +int i2d_ESS_SIGNING_CERT_V2(const ESS_SIGNING_CERT_V2 *a, unsigned char **pp); +ESS_SIGNING_CERT_V2 *d2i_ESS_SIGNING_CERT_V2(ESS_SIGNING_CERT_V2 **a, + const unsigned char **pp, + long length); +ESS_SIGNING_CERT_V2 *ESS_SIGNING_CERT_V2_dup(ESS_SIGNING_CERT_V2 *a); + +int TS_REQ_set_version(TS_REQ *a, long version); +long TS_REQ_get_version(const TS_REQ *a); + +int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i); +const ASN1_INTEGER *TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a); + +const STACK_OF(ASN1_UTF8STRING) * +TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a); + +const ASN1_BIT_STRING * +TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a); + +int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint); +TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a); + +int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg); +X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a); + +int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len); +ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a); + +int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy); +ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a); + +int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce); +const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a); + +int TS_REQ_set_cert_req(TS_REQ *a, int cert_req); +int TS_REQ_get_cert_req(const TS_REQ *a); + +STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a); +void TS_REQ_ext_free(TS_REQ *a); +int TS_REQ_get_ext_count(TS_REQ *a); +int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos); +int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos); +int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos); +X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc); +X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc); +int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc); +void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx); + +/* Function declarations for TS_REQ defined in ts/ts_req_print.c */ + +int TS_REQ_print_bio(BIO *bio, TS_REQ *a); + +/* Function declarations for TS_RESP defined in ts/ts_resp_utils.c */ + +int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *info); +TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a); + +/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */ +void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info); +PKCS7 *TS_RESP_get_token(TS_RESP *a); +TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a); + +int TS_TST_INFO_set_version(TS_TST_INFO *a, long version); +long TS_TST_INFO_get_version(const TS_TST_INFO *a); + +int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy_id); +ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a); + +int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint); +TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a); + +int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial); +const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a); + +int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime); +const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a); + +int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy); +TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a); + +int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds); +const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a); + +int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis); +const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a); + +int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros); +const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a); + +int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering); +int TS_TST_INFO_get_ordering(const TS_TST_INFO *a); + +int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce); +const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a); + +int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa); +GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a); + +STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a); +void TS_TST_INFO_ext_free(TS_TST_INFO *a); +int TS_TST_INFO_get_ext_count(TS_TST_INFO *a); +int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos); +int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, + int lastpos); +int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos); +X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc); +X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc); +int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc); +void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx); + +/* + * Declarations related to response generation, defined in ts/ts_resp_sign.c. + */ + +/* Optional flags for response generation. */ + +/* Don't include the TSA name in response. */ +# define TS_TSA_NAME 0x01 + +/* Set ordering to true in response. */ +# define TS_ORDERING 0x02 + +/* + * Include the signer certificate and the other specified certificates in + * the ESS signing certificate attribute beside the PKCS7 signed data. + * Only the signer certificates is included by default. + */ +# define TS_ESS_CERT_ID_CHAIN 0x04 + +/* Forward declaration. */ +struct TS_resp_ctx; + +/* This must return a unique number less than 160 bits long. */ +typedef ASN1_INTEGER *(*TS_serial_cb) (struct TS_resp_ctx *, void *); + +/* + * This must return the seconds and microseconds since Jan 1, 1970 in the sec + * and usec variables allocated by the caller. Return non-zero for success + * and zero for failure. + */ +typedef int (*TS_time_cb) (struct TS_resp_ctx *, void *, long *sec, + long *usec); + +/* + * This must process the given extension. It can modify the TS_TST_INFO + * object of the context. Return values: !0 (processed), 0 (error, it must + * set the status info/failure info of the response). + */ +typedef int (*TS_extension_cb) (struct TS_resp_ctx *, X509_EXTENSION *, + void *); + +typedef struct TS_resp_ctx TS_RESP_CTX; + +DEFINE_STACK_OF_CONST(EVP_MD) + +/* Creates a response context that can be used for generating responses. */ +TS_RESP_CTX *TS_RESP_CTX_new(void); +void TS_RESP_CTX_free(TS_RESP_CTX *ctx); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_signer_key(TS_RESP_CTX *ctx, EVP_PKEY *key); + +int TS_RESP_CTX_set_signer_digest(TS_RESP_CTX *ctx, + const EVP_MD *signer_digest); +int TS_RESP_CTX_set_ess_cert_id_digest(TS_RESP_CTX *ctx, const EVP_MD *md); + +/* This parameter must be set. */ +int TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, const ASN1_OBJECT *def_policy); + +/* No additional certs are included in the response by default. */ +int TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs); + +/* + * Adds a new acceptable policy, only the default policy is accepted by + * default. + */ +int TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, const ASN1_OBJECT *policy); + +/* + * Adds a new acceptable message digest. Note that no message digests are + * accepted by default. The md argument is shared with the caller. + */ +int TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md); + +/* Accuracy is not included by default. */ +int TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx, + int secs, int millis, int micros); + +/* + * Clock precision digits, i.e. the number of decimal digits: '0' means sec, + * '3' msec, '6' usec, and so on. Default is 0. + */ +int TS_RESP_CTX_set_clock_precision_digits(TS_RESP_CTX *ctx, + unsigned clock_precision_digits); +/* At most we accept usec precision. */ +# define TS_MAX_CLOCK_PRECISION_DIGITS 6 + +/* Maximum status message length */ +# define TS_MAX_STATUS_LENGTH (1024 * 1024) + +/* No flags are set by default. */ +void TS_RESP_CTX_add_flags(TS_RESP_CTX *ctx, int flags); + +/* Default callback always returns a constant. */ +void TS_RESP_CTX_set_serial_cb(TS_RESP_CTX *ctx, TS_serial_cb cb, void *data); + +/* Default callback uses the gettimeofday() and gmtime() system calls. */ +void TS_RESP_CTX_set_time_cb(TS_RESP_CTX *ctx, TS_time_cb cb, void *data); + +/* + * Default callback rejects all extensions. The extension callback is called + * when the TS_TST_INFO object is already set up and not signed yet. + */ +/* FIXME: extension handling is not tested yet. */ +void TS_RESP_CTX_set_extension_cb(TS_RESP_CTX *ctx, + TS_extension_cb cb, void *data); + +/* The following methods can be used in the callbacks. */ +int TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, + int status, const char *text); + +/* Sets the status info only if it is still TS_STATUS_GRANTED. */ +int TS_RESP_CTX_set_status_info_cond(TS_RESP_CTX *ctx, + int status, const char *text); + +int TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure); + +/* The get methods below can be used in the extension callback. */ +TS_REQ *TS_RESP_CTX_get_request(TS_RESP_CTX *ctx); + +TS_TST_INFO *TS_RESP_CTX_get_tst_info(TS_RESP_CTX *ctx); + +/* + * Creates the signed TS_TST_INFO and puts it in TS_RESP. + * In case of errors it sets the status info properly. + * Returns NULL only in case of memory allocation/fatal error. + */ +TS_RESP *TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio); + +/* + * Declarations related to response verification, + * they are defined in ts/ts_resp_verify.c. + */ + +int TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs, + X509_STORE *store, X509 **signer_out); + +/* Context structure for the generic verify method. */ + +/* Verify the signer's certificate and the signature of the response. */ +# define TS_VFY_SIGNATURE (1u << 0) +/* Verify the version number of the response. */ +# define TS_VFY_VERSION (1u << 1) +/* Verify if the policy supplied by the user matches the policy of the TSA. */ +# define TS_VFY_POLICY (1u << 2) +/* + * Verify the message imprint provided by the user. This flag should not be + * specified with TS_VFY_DATA. + */ +# define TS_VFY_IMPRINT (1u << 3) +/* + * Verify the message imprint computed by the verify method from the user + * provided data and the MD algorithm of the response. This flag should not + * be specified with TS_VFY_IMPRINT. + */ +# define TS_VFY_DATA (1u << 4) +/* Verify the nonce value. */ +# define TS_VFY_NONCE (1u << 5) +/* Verify if the TSA name field matches the signer certificate. */ +# define TS_VFY_SIGNER (1u << 6) +/* Verify if the TSA name field equals to the user provided name. */ +# define TS_VFY_TSA_NAME (1u << 7) + +/* You can use the following convenience constants. */ +# define TS_VFY_ALL_IMPRINT (TS_VFY_SIGNATURE \ + | TS_VFY_VERSION \ + | TS_VFY_POLICY \ + | TS_VFY_IMPRINT \ + | TS_VFY_NONCE \ + | TS_VFY_SIGNER \ + | TS_VFY_TSA_NAME) +# define TS_VFY_ALL_DATA (TS_VFY_SIGNATURE \ + | TS_VFY_VERSION \ + | TS_VFY_POLICY \ + | TS_VFY_DATA \ + | TS_VFY_NONCE \ + | TS_VFY_SIGNER \ + | TS_VFY_TSA_NAME) + +typedef struct TS_verify_ctx TS_VERIFY_CTX; + +int TS_RESP_verify_response(TS_VERIFY_CTX *ctx, TS_RESP *response); +int TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token); + +/* + * Declarations related to response verification context, + */ +TS_VERIFY_CTX *TS_VERIFY_CTX_new(void); +void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx); +void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx); +void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx); +int TS_VERIFY_CTX_set_flags(TS_VERIFY_CTX *ctx, int f); +int TS_VERIFY_CTX_add_flags(TS_VERIFY_CTX *ctx, int f); +BIO *TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b); +unsigned char *TS_VERIFY_CTX_set_imprint(TS_VERIFY_CTX *ctx, + unsigned char *hexstr, long len); +X509_STORE *TS_VERIFY_CTX_set_store(TS_VERIFY_CTX *ctx, X509_STORE *s); +STACK_OF(X509) *TS_VERIFY_CTS_set_certs(TS_VERIFY_CTX *ctx, STACK_OF(X509) *certs); + +/*- + * If ctx is NULL, it allocates and returns a new object, otherwise + * it returns ctx. It initialises all the members as follows: + * flags = TS_VFY_ALL_IMPRINT & ~(TS_VFY_TSA_NAME | TS_VFY_SIGNATURE) + * certs = NULL + * store = NULL + * policy = policy from the request or NULL if absent (in this case + * TS_VFY_POLICY is cleared from flags as well) + * md_alg = MD algorithm from request + * imprint, imprint_len = imprint from request + * data = NULL + * nonce, nonce_len = nonce from the request or NULL if absent (in this case + * TS_VFY_NONCE is cleared from flags as well) + * tsa_name = NULL + * Important: after calling this method TS_VFY_SIGNATURE should be added! + */ +TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx); + +/* Function declarations for TS_RESP defined in ts/ts_resp_print.c */ + +int TS_RESP_print_bio(BIO *bio, TS_RESP *a); +int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a); +int TS_TST_INFO_print_bio(BIO *bio, TS_TST_INFO *a); + +/* Common utility functions defined in ts/ts_lib.c */ + +int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num); +int TS_OBJ_print_bio(BIO *bio, const ASN1_OBJECT *obj); +int TS_ext_print_bio(BIO *bio, const STACK_OF(X509_EXTENSION) *extensions); +int TS_X509_ALGOR_print_bio(BIO *bio, const X509_ALGOR *alg); +int TS_MSG_IMPRINT_print_bio(BIO *bio, TS_MSG_IMPRINT *msg); + +/* + * Function declarations for handling configuration options, defined in + * ts/ts_conf.c + */ + +X509 *TS_CONF_load_cert(const char *file); +STACK_OF(X509) *TS_CONF_load_certs(const char *file); +EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass); +const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); +int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb, + TS_RESP_CTX *ctx); +#ifndef OPENSSL_NO_ENGINE +int TS_CONF_set_crypto_device(CONF *conf, const char *section, + const char *device); +int TS_CONF_set_default_engine(const char *name); +#endif +int TS_CONF_set_signer_cert(CONF *conf, const char *section, + const char *cert, TS_RESP_CTX *ctx); +int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, + TS_RESP_CTX *ctx); +int TS_CONF_set_signer_key(CONF *conf, const char *section, + const char *key, const char *pass, + TS_RESP_CTX *ctx); +int TS_CONF_set_signer_digest(CONF *conf, const char *section, + const char *md, TS_RESP_CTX *ctx); +int TS_CONF_set_def_policy(CONF *conf, const char *section, + const char *policy, TS_RESP_CTX *ctx); +int TS_CONF_set_policies(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_digests(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_accuracy(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_clock_precision_digits(CONF *conf, const char *section, + TS_RESP_CTX *ctx); +int TS_CONF_set_ordering(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_tsa_name(CONF *conf, const char *section, TS_RESP_CTX *ctx); +int TS_CONF_set_ess_cert_id_chain(CONF *conf, const char *section, + TS_RESP_CTX *ctx); +int TS_CONF_set_ess_cert_id_digest(CONF *conf, const char *section, + TS_RESP_CTX *ctx); + +# ifdef __cplusplus +} +# endif +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/txt_db.h postgresql-hll-2.14/include/openssl/txt_db.h --- postgresql-hll-2.14_old/include/openssl/txt_db.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/txt_db.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,57 @@ +/* + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_TXT_DB_H +# define HEADER_TXT_DB_H + +# include +# include +# include +# include + +# define DB_ERROR_OK 0 +# define DB_ERROR_MALLOC 1 +# define DB_ERROR_INDEX_CLASH 2 +# define DB_ERROR_INDEX_OUT_OF_RANGE 3 +# define DB_ERROR_NO_INDEX 4 +# define DB_ERROR_INSERT_INDEX_CLASH 5 +# define DB_ERROR_WRONG_NUM_FIELDS 6 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef OPENSSL_STRING *OPENSSL_PSTRING; +DEFINE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING) + +typedef struct txt_db_st { + int num_fields; + STACK_OF(OPENSSL_PSTRING) *data; + LHASH_OF(OPENSSL_STRING) **index; + int (**qual) (OPENSSL_STRING *); + long error; + long arg1; + long arg2; + OPENSSL_STRING *arg_row; +} TXT_DB; + +TXT_DB *TXT_DB_read(BIO *in, int num); +long TXT_DB_write(BIO *out, TXT_DB *db); +int TXT_DB_create_index(TXT_DB *db, int field, int (*qual) (OPENSSL_STRING *), + OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC cmp); +void TXT_DB_free(TXT_DB *db); +OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, + OPENSSL_STRING *value); +int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *value); + +#ifdef __cplusplus +} +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/uierr.h postgresql-hll-2.14/include/openssl/uierr.h --- postgresql-hll-2.14_old/include/openssl/uierr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/uierr.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,65 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_UIERR_H +# define HEADER_UIERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_UI_strings(void); + +/* + * UI function codes. + */ +# define UI_F_CLOSE_CONSOLE 115 +# define UI_F_ECHO_CONSOLE 116 +# define UI_F_GENERAL_ALLOCATE_BOOLEAN 108 +# define UI_F_GENERAL_ALLOCATE_PROMPT 109 +# define UI_F_NOECHO_CONSOLE 117 +# define UI_F_OPEN_CONSOLE 114 +# define UI_F_UI_CONSTRUCT_PROMPT 121 +# define UI_F_UI_CREATE_METHOD 112 +# define UI_F_UI_CTRL 111 +# define UI_F_UI_DUP_ERROR_STRING 101 +# define UI_F_UI_DUP_INFO_STRING 102 +# define UI_F_UI_DUP_INPUT_BOOLEAN 110 +# define UI_F_UI_DUP_INPUT_STRING 103 +# define UI_F_UI_DUP_USER_DATA 118 +# define UI_F_UI_DUP_VERIFY_STRING 106 +# define UI_F_UI_GET0_RESULT 107 +# define UI_F_UI_GET_RESULT_LENGTH 119 +# define UI_F_UI_NEW_METHOD 104 +# define UI_F_UI_PROCESS 113 +# define UI_F_UI_SET_RESULT 105 +# define UI_F_UI_SET_RESULT_EX 120 + +/* + * UI reason codes. + */ +# define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104 +# define UI_R_INDEX_TOO_LARGE 102 +# define UI_R_INDEX_TOO_SMALL 103 +# define UI_R_NO_RESULT_BUFFER 105 +# define UI_R_PROCESSING_ERROR 107 +# define UI_R_RESULT_TOO_LARGE 100 +# define UI_R_RESULT_TOO_SMALL 101 +# define UI_R_SYSASSIGN_ERROR 109 +# define UI_R_SYSDASSGN_ERROR 110 +# define UI_R_SYSQIOW_ERROR 111 +# define UI_R_UNKNOWN_CONTROL_COMMAND 106 +# define UI_R_UNKNOWN_TTYGET_ERRNO_VALUE 108 +# define UI_R_USER_DATA_DUPLICATION_UNSUPPORTED 112 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/ui.h postgresql-hll-2.14/include/openssl/ui.h --- postgresql-hll-2.14_old/include/openssl/ui.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/ui.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,368 @@ +/* + * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_UI_H +# define HEADER_UI_H + +# include + +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# endif +# include +# include +# include +# include + +/* For compatibility reasons, the macro OPENSSL_NO_UI is currently retained */ +# if OPENSSL_API_COMPAT < 0x10200000L +# ifdef OPENSSL_NO_UI_CONSOLE +# define OPENSSL_NO_UI +# endif +# endif + +# ifdef __cplusplus +extern "C" { +# endif + +/* + * All the following functions return -1 or NULL on error and in some cases + * (UI_process()) -2 if interrupted or in some other way cancelled. When + * everything is fine, they return 0, a positive value or a non-NULL pointer, + * all depending on their purpose. + */ + +/* Creators and destructor. */ +UI *UI_new(void); +UI *UI_new_method(const UI_METHOD *method); +void UI_free(UI *ui); + +/*- + The following functions are used to add strings to be printed and prompt + strings to prompt for data. The names are UI_{add,dup}__string + and UI_{add,dup}_input_boolean. + + UI_{add,dup}__string have the following meanings: + add add a text or prompt string. The pointers given to these + functions are used verbatim, no copying is done. + dup make a copy of the text or prompt string, then add the copy + to the collection of strings in the user interface. + + The function is a name for the functionality that the given + string shall be used for. It can be one of: + input use the string as data prompt. + verify use the string as verification prompt. This + is used to verify a previous input. + info use the string for informational output. + error use the string for error output. + Honestly, there's currently no difference between info and error for the + moment. + + UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", + and are typically used when one wants to prompt for a yes/no response. + + All of the functions in this group take a UI and a prompt string. + The string input and verify addition functions also take a flag argument, + a buffer for the result to end up with, a minimum input size and a maximum + input size (the result buffer MUST be large enough to be able to contain + the maximum number of characters). Additionally, the verify addition + functions takes another buffer to compare the result against. + The boolean input functions take an action description string (which should + be safe to ignore if the expected user action is obvious, for example with + a dialog box with an OK button and a Cancel button), a string of acceptable + characters to mean OK and to mean Cancel. The two last strings are checked + to make sure they don't have common characters. Additionally, the same + flag argument as for the string input is taken, as well as a result buffer. + The result buffer is required to be at least one byte long. Depending on + the answer, the first character from the OK or the Cancel character strings + will be stored in the first byte of the result buffer. No NUL will be + added, so the result is *not* a string. + + On success, the all return an index of the added information. That index + is useful when retrieving results with UI_get0_result(). */ +int UI_add_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_dup_input_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize); +int UI_add_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, + const char *test_buf); +int UI_dup_verify_string(UI *ui, const char *prompt, int flags, + char *result_buf, int minsize, int maxsize, + const char *test_buf); +int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, + const char *ok_chars, const char *cancel_chars, + int flags, char *result_buf); +int UI_add_info_string(UI *ui, const char *text); +int UI_dup_info_string(UI *ui, const char *text); +int UI_add_error_string(UI *ui, const char *text); +int UI_dup_error_string(UI *ui, const char *text); + +/* These are the possible flags. They can be or'ed together. */ +/* Use to have echoing of input */ +# define UI_INPUT_FLAG_ECHO 0x01 +/* + * Use a default password. Where that password is found is completely up to + * the application, it might for example be in the user data set with + * UI_add_user_data(). It is not recommended to have more than one input in + * each UI being marked with this flag, or the application might get + * confused. + */ +# define UI_INPUT_FLAG_DEFAULT_PWD 0x02 + +/*- + * The user of these routines may want to define flags of their own. The core + * UI won't look at those, but will pass them on to the method routines. They + * must use higher bits so they don't get confused with the UI bits above. + * UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good + * example of use is this: + * + * #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) + * +*/ +# define UI_INPUT_FLAG_USER_BASE 16 + +/*- + * The following function helps construct a prompt. object_desc is a + * textual short description of the object, for example "pass phrase", + * and object_name is the name of the object (might be a card name or + * a file name. + * The returned string shall always be allocated on the heap with + * OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). + * + * If the ui_method doesn't contain a pointer to a user-defined prompt + * constructor, a default string is built, looking like this: + * + * "Enter {object_desc} for {object_name}:" + * + * So, if object_desc has the value "pass phrase" and object_name has + * the value "foo.key", the resulting string is: + * + * "Enter pass phrase for foo.key:" +*/ +char *UI_construct_prompt(UI *ui_method, + const char *object_desc, const char *object_name); + +/* + * The following function is used to store a pointer to user-specific data. + * Any previous such pointer will be returned and replaced. + * + * For callback purposes, this function makes a lot more sense than using + * ex_data, since the latter requires that different parts of OpenSSL or + * applications share the same ex_data index. + * + * Note that the UI_OpenSSL() method completely ignores the user data. Other + * methods may not, however. + */ +void *UI_add_user_data(UI *ui, void *user_data); +/* + * Alternatively, this function is used to duplicate the user data. + * This uses the duplicator method function. The destroy function will + * be used to free the user data in this case. + */ +int UI_dup_user_data(UI *ui, void *user_data); +/* We need a user data retrieving function as well. */ +void *UI_get0_user_data(UI *ui); + +/* Return the result associated with a prompt given with the index i. */ +const char *UI_get0_result(UI *ui, int i); +int UI_get_result_length(UI *ui, int i); + +/* When all strings have been added, process the whole thing. */ +int UI_process(UI *ui); + +/* + * Give a user interface parameterised control commands. This can be used to + * send down an integer, a data pointer or a function pointer, as well as be + * used to get information from a UI. + */ +int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)); + +/* The commands */ +/* + * Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the + * OpenSSL error stack before printing any info or added error messages and + * before any prompting. + */ +# define UI_CTRL_PRINT_ERRORS 1 +/* + * Check if a UI_process() is possible to do again with the same instance of + * a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 + * if not. + */ +# define UI_CTRL_IS_REDOABLE 2 + +/* Some methods may use extra data */ +# define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) +# define UI_get_app_data(s) UI_get_ex_data(s,0) + +# define UI_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_UI, l, p, newf, dupf, freef) +int UI_set_ex_data(UI *r, int idx, void *arg); +void *UI_get_ex_data(UI *r, int idx); + +/* Use specific methods instead of the built-in one */ +void UI_set_default_method(const UI_METHOD *meth); +const UI_METHOD *UI_get_default_method(void); +const UI_METHOD *UI_get_method(UI *ui); +const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); + +# ifndef OPENSSL_NO_UI_CONSOLE + +/* The method with all the built-in thingies */ +UI_METHOD *UI_OpenSSL(void); + +# endif + +/* + * NULL method. Literally does nothing, but may serve as a placeholder + * to avoid internal default. + */ +const UI_METHOD *UI_null(void); + +/* ---------- For method writers ---------- */ +/*- + A method contains a number of functions that implement the low level + of the User Interface. The functions are: + + an opener This function starts a session, maybe by opening + a channel to a tty, or by opening a window. + a writer This function is called to write a given string, + maybe to the tty, maybe as a field label in a + window. + a flusher This function is called to flush everything that + has been output so far. It can be used to actually + display a dialog box after it has been built. + a reader This function is called to read a given prompt, + maybe from the tty, maybe from a field in a + window. Note that it's called with all string + structures, not only the prompt ones, so it must + check such things itself. + a closer This function closes the session, maybe by closing + the channel to the tty, or closing the window. + + All these functions are expected to return: + + 0 on error. + 1 on success. + -1 on out-of-band events, for example if some prompting has + been canceled (by pressing Ctrl-C, for example). This is + only checked when returned by the flusher or the reader. + + The way this is used, the opener is first called, then the writer for all + strings, then the flusher, then the reader for all strings and finally the + closer. Note that if you want to prompt from a terminal or other command + line interface, the best is to have the reader also write the prompts + instead of having the writer do it. If you want to prompt from a dialog + box, the writer can be used to build up the contents of the box, and the + flusher to actually display the box and run the event loop until all data + has been given, after which the reader only grabs the given data and puts + them back into the UI strings. + + All method functions take a UI as argument. Additionally, the writer and + the reader take a UI_STRING. +*/ + +/* + * The UI_STRING type is the data structure that contains all the needed info + * about a string or a prompt, including test data for a verification prompt. + */ +typedef struct ui_string_st UI_STRING; +DEFINE_STACK_OF(UI_STRING) + +/* + * The different types of strings that are currently supported. This is only + * needed by method authors. + */ +enum UI_string_types { + UIT_NONE = 0, + UIT_PROMPT, /* Prompt for a string */ + UIT_VERIFY, /* Prompt for a string and verify */ + UIT_BOOLEAN, /* Prompt for a yes/no response */ + UIT_INFO, /* Send info to the user */ + UIT_ERROR /* Send an error message to the user */ +}; + +/* Create and manipulate methods */ +UI_METHOD *UI_create_method(const char *name); +void UI_destroy_method(UI_METHOD *ui_method); +int UI_method_set_opener(UI_METHOD *method, int (*opener) (UI *ui)); +int UI_method_set_writer(UI_METHOD *method, + int (*writer) (UI *ui, UI_STRING *uis)); +int UI_method_set_flusher(UI_METHOD *method, int (*flusher) (UI *ui)); +int UI_method_set_reader(UI_METHOD *method, + int (*reader) (UI *ui, UI_STRING *uis)); +int UI_method_set_closer(UI_METHOD *method, int (*closer) (UI *ui)); +int UI_method_set_data_duplicator(UI_METHOD *method, + void *(*duplicator) (UI *ui, void *ui_data), + void (*destructor)(UI *ui, void *ui_data)); +int UI_method_set_prompt_constructor(UI_METHOD *method, + char *(*prompt_constructor) (UI *ui, + const char + *object_desc, + const char + *object_name)); +int UI_method_set_ex_data(UI_METHOD *method, int idx, void *data); +int (*UI_method_get_opener(const UI_METHOD *method)) (UI *); +int (*UI_method_get_writer(const UI_METHOD *method)) (UI *, UI_STRING *); +int (*UI_method_get_flusher(const UI_METHOD *method)) (UI *); +int (*UI_method_get_reader(const UI_METHOD *method)) (UI *, UI_STRING *); +int (*UI_method_get_closer(const UI_METHOD *method)) (UI *); +char *(*UI_method_get_prompt_constructor(const UI_METHOD *method)) + (UI *, const char *, const char *); +void *(*UI_method_get_data_duplicator(const UI_METHOD *method)) (UI *, void *); +void (*UI_method_get_data_destructor(const UI_METHOD *method)) (UI *, void *); +const void *UI_method_get_ex_data(const UI_METHOD *method, int idx); + +/* + * The following functions are helpers for method writers to access relevant + * data from a UI_STRING. + */ + +/* Return type of the UI_STRING */ +enum UI_string_types UI_get_string_type(UI_STRING *uis); +/* Return input flags of the UI_STRING */ +int UI_get_input_flags(UI_STRING *uis); +/* Return the actual string to output (the prompt, info or error) */ +const char *UI_get0_output_string(UI_STRING *uis); +/* + * Return the optional action string to output (the boolean prompt + * instruction) + */ +const char *UI_get0_action_string(UI_STRING *uis); +/* Return the result of a prompt */ +const char *UI_get0_result_string(UI_STRING *uis); +int UI_get_result_string_length(UI_STRING *uis); +/* + * Return the string to test the result against. Only useful with verifies. + */ +const char *UI_get0_test_string(UI_STRING *uis); +/* Return the required minimum size of the result */ +int UI_get_result_minsize(UI_STRING *uis); +/* Return the required maximum size of the result */ +int UI_get_result_maxsize(UI_STRING *uis); +/* Set the result of a UI_STRING. */ +int UI_set_result(UI *ui, UI_STRING *uis, const char *result); +int UI_set_result_ex(UI *ui, UI_STRING *uis, const char *result, int len); + +/* A couple of popular utility functions */ +int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, + int verify); +int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt, + int verify); +UI_METHOD *UI_UTIL_wrap_read_pem_callback(pem_password_cb *cb, int rwflag); + + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/whrlpool.h postgresql-hll-2.14/include/openssl/whrlpool.h --- postgresql-hll-2.14_old/include/openssl/whrlpool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/whrlpool.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,48 @@ +/* + * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_WHRLPOOL_H +# define HEADER_WHRLPOOL_H + +#include + +# ifndef OPENSSL_NO_WHIRLPOOL +# include +# include +# ifdef __cplusplus +extern "C" { +# endif + +# define WHIRLPOOL_DIGEST_LENGTH (512/8) +# define WHIRLPOOL_BBLOCK 512 +# define WHIRLPOOL_COUNTER (256/8) + +typedef struct { + union { + unsigned char c[WHIRLPOOL_DIGEST_LENGTH]; + /* double q is here to ensure 64-bit alignment */ + double q[WHIRLPOOL_DIGEST_LENGTH / sizeof(double)]; + } H; + unsigned char data[WHIRLPOOL_BBLOCK / 8]; + unsigned int bitoff; + size_t bitlen[WHIRLPOOL_COUNTER / sizeof(size_t)]; +} WHIRLPOOL_CTX; + +int WHIRLPOOL_Init(WHIRLPOOL_CTX *c); +int WHIRLPOOL_Update(WHIRLPOOL_CTX *c, const void *inp, size_t bytes); +void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c, const void *inp, size_t bits); +int WHIRLPOOL_Final(unsigned char *md, WHIRLPOOL_CTX *c); +unsigned char *WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md); + +# ifdef __cplusplus +} +# endif +# endif + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/x509err.h postgresql-hll-2.14/include/openssl/x509err.h --- postgresql-hll-2.14_old/include/openssl/x509err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/x509err.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,130 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509ERR_H +# define HEADER_X509ERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_X509_strings(void); + +/* + * X509 function codes. + */ +# define X509_F_ADD_CERT_DIR 100 +# define X509_F_BUILD_CHAIN 106 +# define X509_F_BY_FILE_CTRL 101 +# define X509_F_CHECK_NAME_CONSTRAINTS 149 +# define X509_F_CHECK_POLICY 145 +# define X509_F_DANE_I2D 107 +# define X509_F_DIR_CTRL 102 +# define X509_F_GET_CERT_BY_SUBJECT 103 +# define X509_F_I2D_X509_AUX 151 +# define X509_F_LOOKUP_CERTS_SK 152 +# define X509_F_NETSCAPE_SPKI_B64_DECODE 129 +# define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 +# define X509_F_NEW_DIR 153 +# define X509_F_X509AT_ADD1_ATTR 135 +# define X509_F_X509V3_ADD_EXT 104 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 +# define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 +# define X509_F_X509_ATTRIBUTE_GET0_DATA 139 +# define X509_F_X509_ATTRIBUTE_SET1_DATA 138 +# define X509_F_X509_CHECK_PRIVATE_KEY 128 +# define X509_F_X509_CRL_DIFF 105 +# define X509_F_X509_CRL_METHOD_NEW 154 +# define X509_F_X509_CRL_PRINT_FP 147 +# define X509_F_X509_EXTENSION_CREATE_BY_NID 108 +# define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 +# define X509_F_X509_GET_PUBKEY_PARAMETERS 110 +# define X509_F_X509_LOAD_CERT_CRL_FILE 132 +# define X509_F_X509_LOAD_CERT_FILE 111 +# define X509_F_X509_LOAD_CRL_FILE 112 +# define X509_F_X509_LOOKUP_METH_NEW 160 +# define X509_F_X509_LOOKUP_NEW 155 +# define X509_F_X509_NAME_ADD_ENTRY 113 +# define X509_F_X509_NAME_CANON 156 +# define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 +# define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131 +# define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 +# define X509_F_X509_NAME_ONELINE 116 +# define X509_F_X509_NAME_PRINT 117 +# define X509_F_X509_OBJECT_NEW 150 +# define X509_F_X509_PRINT_EX_FP 118 +# define X509_F_X509_PUBKEY_DECODE 148 +# define X509_F_X509_PUBKEY_GET0 119 +# define X509_F_X509_PUBKEY_SET 120 +# define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 +# define X509_F_X509_REQ_PRINT_EX 121 +# define X509_F_X509_REQ_PRINT_FP 122 +# define X509_F_X509_REQ_TO_X509 123 +# define X509_F_X509_STORE_ADD_CERT 124 +# define X509_F_X509_STORE_ADD_CRL 125 +# define X509_F_X509_STORE_ADD_LOOKUP 157 +# define X509_F_X509_STORE_CTX_GET1_ISSUER 146 +# define X509_F_X509_STORE_CTX_INIT 143 +# define X509_F_X509_STORE_CTX_NEW 142 +# define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 +# define X509_F_X509_STORE_NEW 158 +# define X509_F_X509_TO_X509_REQ 126 +# define X509_F_X509_TRUST_ADD 133 +# define X509_F_X509_TRUST_SET 141 +# define X509_F_X509_VERIFY_CERT 127 +# define X509_F_X509_VERIFY_PARAM_NEW 159 + +/* + * X509 reason codes. + */ +# define X509_R_AKID_MISMATCH 110 +# define X509_R_BAD_SELECTOR 133 +# define X509_R_BAD_X509_FILETYPE 100 +# define X509_R_BASE64_DECODE_ERROR 118 +# define X509_R_CANT_CHECK_DH_KEY 114 +# define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 +# define X509_R_CRL_ALREADY_DELTA 127 +# define X509_R_CRL_VERIFY_FAILURE 131 +# define X509_R_IDP_MISMATCH 128 +# define X509_R_INVALID_ATTRIBUTES 138 +# define X509_R_INVALID_DIRECTORY 113 +# define X509_R_INVALID_FIELD_NAME 119 +# define X509_R_INVALID_TRUST 123 +# define X509_R_ISSUER_MISMATCH 129 +# define X509_R_KEY_TYPE_MISMATCH 115 +# define X509_R_KEY_VALUES_MISMATCH 116 +# define X509_R_LOADING_CERT_DIR 103 +# define X509_R_LOADING_DEFAULTS 104 +# define X509_R_METHOD_NOT_SUPPORTED 124 +# define X509_R_NAME_TOO_LONG 134 +# define X509_R_NEWER_CRL_NOT_NEWER 132 +# define X509_R_NO_CERTIFICATE_FOUND 135 +# define X509_R_NO_CERTIFICATE_OR_CRL_FOUND 136 +# define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 +# define X509_R_NO_CRL_FOUND 137 +# define X509_R_NO_CRL_NUMBER 130 +# define X509_R_PUBLIC_KEY_DECODE_ERROR 125 +# define X509_R_PUBLIC_KEY_ENCODE_ERROR 126 +# define X509_R_SHOULD_RETRY 106 +# define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 +# define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 +# define X509_R_UNKNOWN_KEY_TYPE 117 +# define X509_R_UNKNOWN_NID 109 +# define X509_R_UNKNOWN_PURPOSE_ID 121 +# define X509_R_UNKNOWN_TRUST_ID 120 +# define X509_R_UNSUPPORTED_ALGORITHM 111 +# define X509_R_WRONG_LOOKUP_TYPE 112 +# define X509_R_WRONG_TYPE 122 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/x509.h postgresql-hll-2.14/include/openssl/x509.h --- postgresql-hll-2.14_old/include/openssl/x509.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/x509.h 2020-12-12 17:06:43.343349277 +0800 @@ -0,0 +1,1047 @@ +/* + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509_H +# define HEADER_X509_H + +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# if OPENSSL_API_COMPAT < 0x10100000L +# include +# include +# include +# endif + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Flags for X509_get_signature_info() */ +/* Signature info is valid */ +# define X509_SIG_INFO_VALID 0x1 +/* Signature is suitable for TLS use */ +# define X509_SIG_INFO_TLS 0x2 + +# define X509_FILETYPE_PEM 1 +# define X509_FILETYPE_ASN1 2 +# define X509_FILETYPE_DEFAULT 3 + +# define X509v3_KU_DIGITAL_SIGNATURE 0x0080 +# define X509v3_KU_NON_REPUDIATION 0x0040 +# define X509v3_KU_KEY_ENCIPHERMENT 0x0020 +# define X509v3_KU_DATA_ENCIPHERMENT 0x0010 +# define X509v3_KU_KEY_AGREEMENT 0x0008 +# define X509v3_KU_KEY_CERT_SIGN 0x0004 +# define X509v3_KU_CRL_SIGN 0x0002 +# define X509v3_KU_ENCIPHER_ONLY 0x0001 +# define X509v3_KU_DECIPHER_ONLY 0x8000 +# define X509v3_KU_UNDEF 0xffff + +struct X509_algor_st { + ASN1_OBJECT *algorithm; + ASN1_TYPE *parameter; +} /* X509_ALGOR */ ; + +typedef STACK_OF(X509_ALGOR) X509_ALGORS; + +typedef struct X509_val_st { + ASN1_TIME *notBefore; + ASN1_TIME *notAfter; +} X509_VAL; + +typedef struct X509_sig_st X509_SIG; + +typedef struct X509_name_entry_st X509_NAME_ENTRY; + +DEFINE_STACK_OF(X509_NAME_ENTRY) + +DEFINE_STACK_OF(X509_NAME) + +# define X509_EX_V_NETSCAPE_HACK 0x8000 +# define X509_EX_V_INIT 0x0001 +typedef struct X509_extension_st X509_EXTENSION; + +typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; + +DEFINE_STACK_OF(X509_EXTENSION) + +typedef struct x509_attributes_st X509_ATTRIBUTE; + +DEFINE_STACK_OF(X509_ATTRIBUTE) + +typedef struct X509_req_info_st X509_REQ_INFO; + +typedef struct X509_req_st X509_REQ; + +typedef struct x509_cert_aux_st X509_CERT_AUX; + +typedef struct x509_cinf_st X509_CINF; + +DEFINE_STACK_OF(X509) + +/* This is used for a table of trust checking functions */ + +typedef struct x509_trust_st { + int trust; + int flags; + int (*check_trust) (struct x509_trust_st *, X509 *, int); + char *name; + int arg1; + void *arg2; +} X509_TRUST; + +DEFINE_STACK_OF(X509_TRUST) + +/* standard trust ids */ + +# define X509_TRUST_DEFAULT 0 /* Only valid in purpose settings */ + +# define X509_TRUST_COMPAT 1 +# define X509_TRUST_SSL_CLIENT 2 +# define X509_TRUST_SSL_SERVER 3 +# define X509_TRUST_EMAIL 4 +# define X509_TRUST_OBJECT_SIGN 5 +# define X509_TRUST_OCSP_SIGN 6 +# define X509_TRUST_OCSP_REQUEST 7 +# define X509_TRUST_TSA 8 + +/* Keep these up to date! */ +# define X509_TRUST_MIN 1 +# define X509_TRUST_MAX 8 + +/* trust_flags values */ +# define X509_TRUST_DYNAMIC (1U << 0) +# define X509_TRUST_DYNAMIC_NAME (1U << 1) +/* No compat trust if self-signed, preempts "DO_SS" */ +# define X509_TRUST_NO_SS_COMPAT (1U << 2) +/* Compat trust if no explicit accepted trust EKUs */ +# define X509_TRUST_DO_SS_COMPAT (1U << 3) +/* Accept "anyEKU" as a wildcard trust OID */ +# define X509_TRUST_OK_ANY_EKU (1U << 4) + +/* check_trust return codes */ + +# define X509_TRUST_TRUSTED 1 +# define X509_TRUST_REJECTED 2 +# define X509_TRUST_UNTRUSTED 3 + +/* Flags for X509_print_ex() */ + +# define X509_FLAG_COMPAT 0 +# define X509_FLAG_NO_HEADER 1L +# define X509_FLAG_NO_VERSION (1L << 1) +# define X509_FLAG_NO_SERIAL (1L << 2) +# define X509_FLAG_NO_SIGNAME (1L << 3) +# define X509_FLAG_NO_ISSUER (1L << 4) +# define X509_FLAG_NO_VALIDITY (1L << 5) +# define X509_FLAG_NO_SUBJECT (1L << 6) +# define X509_FLAG_NO_PUBKEY (1L << 7) +# define X509_FLAG_NO_EXTENSIONS (1L << 8) +# define X509_FLAG_NO_SIGDUMP (1L << 9) +# define X509_FLAG_NO_AUX (1L << 10) +# define X509_FLAG_NO_ATTRIBUTES (1L << 11) +# define X509_FLAG_NO_IDS (1L << 12) + +/* Flags specific to X509_NAME_print_ex() */ + +/* The field separator information */ + +# define XN_FLAG_SEP_MASK (0xf << 16) + +# define XN_FLAG_COMPAT 0/* Traditional; use old X509_NAME_print */ +# define XN_FLAG_SEP_COMMA_PLUS (1 << 16)/* RFC2253 ,+ */ +# define XN_FLAG_SEP_CPLUS_SPC (2 << 16)/* ,+ spaced: more readable */ +# define XN_FLAG_SEP_SPLUS_SPC (3 << 16)/* ;+ spaced */ +# define XN_FLAG_SEP_MULTILINE (4 << 16)/* One line per field */ + +# define XN_FLAG_DN_REV (1 << 20)/* Reverse DN order */ + +/* How the field name is shown */ + +# define XN_FLAG_FN_MASK (0x3 << 21) + +# define XN_FLAG_FN_SN 0/* Object short name */ +# define XN_FLAG_FN_LN (1 << 21)/* Object long name */ +# define XN_FLAG_FN_OID (2 << 21)/* Always use OIDs */ +# define XN_FLAG_FN_NONE (3 << 21)/* No field names */ + +# define XN_FLAG_SPC_EQ (1 << 23)/* Put spaces round '=' */ + +/* + * This determines if we dump fields we don't recognise: RFC2253 requires + * this. + */ + +# define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) + +# define XN_FLAG_FN_ALIGN (1 << 25)/* Align field names to 20 + * characters */ + +/* Complete set of RFC2253 flags */ + +# define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ + XN_FLAG_SEP_COMMA_PLUS | \ + XN_FLAG_DN_REV | \ + XN_FLAG_FN_SN | \ + XN_FLAG_DUMP_UNKNOWN_FIELDS) + +/* readable oneline form */ + +# define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ + ASN1_STRFLGS_ESC_QUOTE | \ + XN_FLAG_SEP_CPLUS_SPC | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_SN) + +/* readable multiline form */ + +# define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ + ASN1_STRFLGS_ESC_MSB | \ + XN_FLAG_SEP_MULTILINE | \ + XN_FLAG_SPC_EQ | \ + XN_FLAG_FN_LN | \ + XN_FLAG_FN_ALIGN) + +DEFINE_STACK_OF(X509_REVOKED) + +typedef struct X509_crl_info_st X509_CRL_INFO; + +DEFINE_STACK_OF(X509_CRL) + +typedef struct private_key_st { + int version; + /* The PKCS#8 data types */ + X509_ALGOR *enc_algor; + ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ + /* When decrypted, the following will not be NULL */ + EVP_PKEY *dec_pkey; + /* used to encrypt and decrypt */ + int key_length; + char *key_data; + int key_free; /* true if we should auto free key_data */ + /* expanded version of 'enc_algor' */ + EVP_CIPHER_INFO cipher; +} X509_PKEY; + +typedef struct X509_info_st { + X509 *x509; + X509_CRL *crl; + X509_PKEY *x_pkey; + EVP_CIPHER_INFO enc_cipher; + int enc_len; + char *enc_data; +} X509_INFO; + +DEFINE_STACK_OF(X509_INFO) + +/* + * The next 2 structures and their 8 routines are used to manipulate Netscape's + * spki structures - useful if you are writing a CA web page + */ +typedef struct Netscape_spkac_st { + X509_PUBKEY *pubkey; + ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ +} NETSCAPE_SPKAC; + +typedef struct Netscape_spki_st { + NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ + X509_ALGOR sig_algor; + ASN1_BIT_STRING *signature; +} NETSCAPE_SPKI; + +/* Netscape certificate sequence structure */ +typedef struct Netscape_certificate_sequence { + ASN1_OBJECT *type; + STACK_OF(X509) *certs; +} NETSCAPE_CERT_SEQUENCE; + +/*- Unused (and iv length is wrong) +typedef struct CBCParameter_st + { + unsigned char iv[8]; + } CBC_PARAM; +*/ + +/* Password based encryption structure */ + +typedef struct PBEPARAM_st { + ASN1_OCTET_STRING *salt; + ASN1_INTEGER *iter; +} PBEPARAM; + +/* Password based encryption V2 structures */ + +typedef struct PBE2PARAM_st { + X509_ALGOR *keyfunc; + X509_ALGOR *encryption; +} PBE2PARAM; + +typedef struct PBKDF2PARAM_st { +/* Usually OCTET STRING but could be anything */ + ASN1_TYPE *salt; + ASN1_INTEGER *iter; + ASN1_INTEGER *keylength; + X509_ALGOR *prf; +} PBKDF2PARAM; + +#ifndef OPENSSL_NO_SCRYPT +typedef struct SCRYPT_PARAMS_st { + ASN1_OCTET_STRING *salt; + ASN1_INTEGER *costParameter; + ASN1_INTEGER *blockSize; + ASN1_INTEGER *parallelizationParameter; + ASN1_INTEGER *keyLength; +} SCRYPT_PARAMS; +#endif + +#ifdef __cplusplus +} +#endif + +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +# define X509_EXT_PACK_UNKNOWN 1 +# define X509_EXT_PACK_STRING 2 + +# define X509_extract_key(x) X509_get_pubkey(x)/*****/ +# define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) +# define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) + +void X509_CRL_set_default_method(const X509_CRL_METHOD *meth); +X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), + int (*crl_free) (X509_CRL *crl), + int (*crl_lookup) (X509_CRL *crl, + X509_REVOKED **ret, + ASN1_INTEGER *ser, + X509_NAME *issuer), + int (*crl_verify) (X509_CRL *crl, + EVP_PKEY *pk)); +void X509_CRL_METHOD_free(X509_CRL_METHOD *m); + +void X509_CRL_set_meth_data(X509_CRL *crl, void *dat); +void *X509_CRL_get_meth_data(X509_CRL *crl); + +const char *X509_verify_cert_error_string(long n); + +int X509_verify(X509 *a, EVP_PKEY *r); + +int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); +int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); +int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); + +NETSCAPE_SPKI *NETSCAPE_SPKI_b64_decode(const char *str, int len); +char *NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); +EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); +int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); + +int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); + +int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent); +int X509_signature_print(BIO *bp, const X509_ALGOR *alg, + const ASN1_STRING *sig); + +int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx); +# ifndef OPENSSL_NO_OCSP +int X509_http_nbio(OCSP_REQ_CTX *rctx, X509 **pcert); +# endif +int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx); +int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx); +# ifndef OPENSSL_NO_OCSP +int X509_CRL_http_nbio(OCSP_REQ_CTX *rctx, X509_CRL **pcrl); +# endif +int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); + +int X509_pubkey_digest(const X509 *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_digest(const X509 *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); +int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, + unsigned char *md, unsigned int *len); + +# ifndef OPENSSL_NO_STDIO +X509 *d2i_X509_fp(FILE *fp, X509 **x509); +int i2d_X509_fp(FILE *fp, X509 *x509); +X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); +int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl); +X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); +int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req); +# ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); +int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa); +RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); +int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa); +RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); +int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa); +# endif +# ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); +int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); +DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); +int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +# endif +# ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); +int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); +int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); +# endif +X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); +int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); +int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); +# endif + +X509 *d2i_X509_bio(BIO *bp, X509 **x509); +int i2d_X509_bio(BIO *bp, X509 *x509); +X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); +int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl); +X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); +int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); +# ifndef OPENSSL_NO_RSA +RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); +int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa); +RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); +int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa); +RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); +int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa); +# endif +# ifndef OPENSSL_NO_DSA +DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); +int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); +DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); +int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); +# endif +# ifndef OPENSSL_NO_EC +EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); +int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); +EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); +int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); +# endif +X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); +int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf); +int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); +int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); + +X509 *X509_dup(X509 *x509); +X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); +X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); +X509_CRL *X509_CRL_dup(X509_CRL *crl); +X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *rev); +X509_REQ *X509_REQ_dup(X509_REQ *req); +X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); +int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, + void *pval); +void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, + const void **ppval, const X509_ALGOR *algor); +void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); +int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); + +X509_NAME *X509_NAME_dup(X509_NAME *xn); +X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); + +int X509_cmp_time(const ASN1_TIME *s, time_t *t); +int X509_cmp_current_time(const ASN1_TIME *s); +ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *t); +ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, + int offset_day, long offset_sec, time_t *t); +ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj); + +const char *X509_get_default_cert_area(void); +const char *X509_get_default_cert_dir(void); +const char *X509_get_default_cert_file(void); +const char *X509_get_default_cert_dir_env(void); +const char *X509_get_default_cert_file_env(void); +const char *X509_get_default_private_dir(void); + +X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey); + +DECLARE_ASN1_FUNCTIONS(X509_ALGOR) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) +DECLARE_ASN1_FUNCTIONS(X509_VAL) + +DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) + +int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); +EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key); +EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key); +int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain); +long X509_get_pathlen(X509 *x); +int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp); +EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length); +# ifndef OPENSSL_NO_RSA +int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp); +RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length); +# endif +# ifndef OPENSSL_NO_DSA +int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp); +DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length); +# endif +# ifndef OPENSSL_NO_EC +int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp); +EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length); +# endif + +DECLARE_ASN1_FUNCTIONS(X509_SIG) +void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg, + const ASN1_OCTET_STRING **pdigest); +void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg, + ASN1_OCTET_STRING **pdigest); + +DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) +DECLARE_ASN1_FUNCTIONS(X509_REQ) + +DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) +X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); + +DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) +DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) + +DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) + +DECLARE_ASN1_FUNCTIONS(X509_NAME) + +int X509_NAME_set(X509_NAME **xn, X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(X509_CINF) + +DECLARE_ASN1_FUNCTIONS(X509) +DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) + +#define X509_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, l, p, newf, dupf, freef) +int X509_set_ex_data(X509 *r, int idx, void *arg); +void *X509_get_ex_data(X509 *r, int idx); +int i2d_X509_AUX(X509 *a, unsigned char **pp); +X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length); + +int i2d_re_X509_tbs(X509 *x, unsigned char **pp); + +int X509_SIG_INFO_get(const X509_SIG_INFO *siginf, int *mdnid, int *pknid, + int *secbits, uint32_t *flags); +void X509_SIG_INFO_set(X509_SIG_INFO *siginf, int mdnid, int pknid, + int secbits, uint32_t flags); + +int X509_get_signature_info(X509 *x, int *mdnid, int *pknid, int *secbits, + uint32_t *flags); + +void X509_get0_signature(const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg, const X509 *x); +int X509_get_signature_nid(const X509 *x); + +int X509_trusted(const X509 *x); +int X509_alias_set1(X509 *x, const unsigned char *name, int len); +int X509_keyid_set1(X509 *x, const unsigned char *id, int len); +unsigned char *X509_alias_get0(X509 *x, int *len); +unsigned char *X509_keyid_get0(X509 *x, int *len); +int (*X509_TRUST_set_default(int (*trust) (int, X509 *, int))) (int, X509 *, + int); +int X509_TRUST_set(int *t, int trust); +int X509_add1_trust_object(X509 *x, const ASN1_OBJECT *obj); +int X509_add1_reject_object(X509 *x, const ASN1_OBJECT *obj); +void X509_trust_clear(X509 *x); +void X509_reject_clear(X509 *x); + +STACK_OF(ASN1_OBJECT) *X509_get0_trust_objects(X509 *x); +STACK_OF(ASN1_OBJECT) *X509_get0_reject_objects(X509 *x); + +DECLARE_ASN1_FUNCTIONS(X509_REVOKED) +DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) +DECLARE_ASN1_FUNCTIONS(X509_CRL) + +int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); +int X509_CRL_get0_by_serial(X509_CRL *crl, + X509_REVOKED **ret, ASN1_INTEGER *serial); +int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x); + +X509_PKEY *X509_PKEY_new(void); +void X509_PKEY_free(X509_PKEY *a); + +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) +DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) + +X509_INFO *X509_INFO_new(void); +void X509_INFO_free(X509_INFO *a); +char *X509_NAME_oneline(const X509_NAME *a, char *buf, int size); + +int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey); + +int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, + unsigned char *md, unsigned int *len); + +int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + char *data, EVP_PKEY *pkey, const EVP_MD *type); + +int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *data, + unsigned char *md, unsigned int *len); + +int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1, + ASN1_BIT_STRING *signature, void *data, EVP_PKEY *pkey); + +int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *data, + EVP_PKEY *pkey, const EVP_MD *type); +int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, + X509_ALGOR *algor2, ASN1_BIT_STRING *signature, + void *asn, EVP_MD_CTX *ctx); + +long X509_get_version(const X509 *x); +int X509_set_version(X509 *x, long version); +int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); +ASN1_INTEGER *X509_get_serialNumber(X509 *x); +const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x); +int X509_set_issuer_name(X509 *x, X509_NAME *name); +X509_NAME *X509_get_issuer_name(const X509 *a); +int X509_set_subject_name(X509 *x, X509_NAME *name); +X509_NAME *X509_get_subject_name(const X509 *a); +const ASN1_TIME * X509_get0_notBefore(const X509 *x); +ASN1_TIME *X509_getm_notBefore(const X509 *x); +int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm); +const ASN1_TIME *X509_get0_notAfter(const X509 *x); +ASN1_TIME *X509_getm_notAfter(const X509 *x); +int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm); +int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); +int X509_up_ref(X509 *x); +int X509_get_signature_type(const X509 *x); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_get_notBefore X509_getm_notBefore +# define X509_get_notAfter X509_getm_notAfter +# define X509_set_notBefore X509_set1_notBefore +# define X509_set_notAfter X509_set1_notAfter +#endif + + +/* + * This one is only used so that a binary form can output, as in + * i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &buf) + */ +X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x); +const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x); +void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid, + const ASN1_BIT_STRING **psuid); +const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x); + +EVP_PKEY *X509_get0_pubkey(const X509 *x); +EVP_PKEY *X509_get_pubkey(X509 *x); +ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x); +int X509_certificate_type(const X509 *x, const EVP_PKEY *pubkey); + +long X509_REQ_get_version(const X509_REQ *req); +int X509_REQ_set_version(X509_REQ *x, long version); +X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); +int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); +void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg); +int X509_REQ_get_signature_nid(const X509_REQ *req); +int i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp); +int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); +EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req); +EVP_PKEY *X509_REQ_get0_pubkey(X509_REQ *req); +X509_PUBKEY *X509_REQ_get_X509_PUBKEY(X509_REQ *req); +int X509_REQ_extension_nid(int nid); +int *X509_REQ_get_extension_nids(void); +void X509_REQ_set_extension_nids(int *nids); +STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req); +int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, + int nid); +int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); +int X509_REQ_get_attr_count(const X509_REQ *req); +int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, int lastpos); +int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); +X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); +int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); +int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_NID(X509_REQ *req, + int nid, int type, + const unsigned char *bytes, int len); +int X509_REQ_add1_attr_by_txt(X509_REQ *req, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_CRL_set_version(X509_CRL *x, long version); +int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name); +int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm); +int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); +int X509_CRL_sort(X509_CRL *crl); +int X509_CRL_up_ref(X509_CRL *crl); + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate +# define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate +#endif + +long X509_CRL_get_version(const X509_CRL *crl); +const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); +const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); +DEPRECATEDIN_1_1_0(ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)) +DEPRECATEDIN_1_1_0(ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)) +X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); +const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl); +STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); +void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, + const X509_ALGOR **palg); +int X509_CRL_get_signature_nid(const X509_CRL *crl); +int i2d_re_X509_CRL_tbs(X509_CRL *req, unsigned char **pp); + +const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x); +int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); +const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x); +int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); +const STACK_OF(X509_EXTENSION) * +X509_REVOKED_get0_extensions(const X509_REVOKED *r); + +X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, + EVP_PKEY *skey, const EVP_MD *md, unsigned int flags); + +int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey); + +int X509_check_private_key(const X509 *x509, const EVP_PKEY *pkey); +int X509_chain_check_suiteb(int *perror_depth, + X509 *x, STACK_OF(X509) *chain, + unsigned long flags); +int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, unsigned long flags); +STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); + +int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_and_serial_hash(X509 *a); + +int X509_issuer_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_issuer_name_hash(X509 *a); + +int X509_subject_name_cmp(const X509 *a, const X509 *b); +unsigned long X509_subject_name_hash(X509 *x); + +# ifndef OPENSSL_NO_MD5 +unsigned long X509_issuer_name_hash_old(X509 *a); +unsigned long X509_subject_name_hash_old(X509 *x); +# endif + +int X509_cmp(const X509 *a, const X509 *b); +int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); +unsigned long X509_NAME_hash(X509_NAME *x); +unsigned long X509_NAME_hash_old(X509_NAME *x); + +int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); +int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); +int X509_aux_print(BIO *out, X509 *x, int indent); +# ifndef OPENSSL_NO_STDIO +int X509_print_ex_fp(FILE *bp, X509 *x, unsigned long nmflag, + unsigned long cflag); +int X509_print_fp(FILE *bp, X509 *x); +int X509_CRL_print_fp(FILE *bp, X509_CRL *x); +int X509_REQ_print_fp(FILE *bp, X509_REQ *req); +int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent, + unsigned long flags); +# endif + +int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase); +int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, + unsigned long flags); +int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag, + unsigned long cflag); +int X509_print(BIO *bp, X509 *x); +int X509_ocspid_print(BIO *bp, X509 *x); +int X509_CRL_print_ex(BIO *out, X509_CRL *x, unsigned long nmflag); +int X509_CRL_print(BIO *bp, X509_CRL *x); +int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, + unsigned long cflag); +int X509_REQ_print(BIO *bp, X509_REQ *req); + +int X509_NAME_entry_count(const X509_NAME *name); +int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len); +int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, + char *buf, int len); + +/* + * NOTE: you should be passing -1, not 0 as lastpos. The functions that use + * lastpos, search after that position on. + */ +int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos); +int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, + int lastpos); +X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc); +X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); +int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, + int loc, int set); +int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len, int loc, + int set); +int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, + const unsigned char *bytes, int len, int loc, + int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, + const char *field, int type, + const unsigned char *bytes, + int len); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, + int type, + const unsigned char *bytes, + int len); +int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, + const unsigned char *bytes, int len, int loc, + int set); +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, + int len); +int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, const ASN1_OBJECT *obj); +int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, + const unsigned char *bytes, int len); +ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne); +ASN1_STRING * X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); +int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne); + +int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, + size_t *pderlen); + +int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); +int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, + int nid, int lastpos); +int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, + const ASN1_OBJECT *obj, int lastpos); +int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, + int crit, int lastpos); +X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); +X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); +STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, + X509_EXTENSION *ex, int loc); + +int X509_get_ext_count(const X509 *x); +int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); +int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, int lastpos); +int X509_get_ext_by_critical(const X509 *x, int crit, int lastpos); +X509_EXTENSION *X509_get_ext(const X509 *x, int loc); +X509_EXTENSION *X509_delete_ext(X509 *x, int loc); +int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); +void *X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx); +int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_CRL_get_ext_count(const X509_CRL *x); +int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, int lastpos); +int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, const ASN1_OBJECT *obj, + int lastpos); +int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, int lastpos); +X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); +X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); +int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); +void *X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, int *idx); +int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, + unsigned long flags); + +int X509_REVOKED_get_ext_count(const X509_REVOKED *x); +int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, int lastpos); +int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, const ASN1_OBJECT *obj, + int lastpos); +int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit, + int lastpos); +X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc); +X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); +int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); +void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid, int *crit, + int *idx); +int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, + unsigned long flags); + +X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, + int nid, int crit, + ASN1_OCTET_STRING *data); +X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, + const ASN1_OBJECT *obj, int crit, + ASN1_OCTET_STRING *data); +int X509_EXTENSION_set_object(X509_EXTENSION *ex, const ASN1_OBJECT *obj); +int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); +int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data); +ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex); +ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); +int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); + +int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); +int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, + int lastpos); +int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, + const ASN1_OBJECT *obj, int lastpos); +X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); +X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, + X509_ATTRIBUTE *attr); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) + **x, const ASN1_OBJECT *obj, + int type, + const unsigned char *bytes, + int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) + **x, int nid, int type, + const unsigned char *bytes, + int len); +STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) + **x, const char *attrname, + int type, + const unsigned char *bytes, + int len); +void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, + const ASN1_OBJECT *obj, int lastpos, int type); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, + int atrtype, const void *data, + int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, + const ASN1_OBJECT *obj, + int atrtype, const void *data, + int len); +X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, + const char *atrname, int type, + const unsigned char *bytes, + int len); +int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); +int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, + const void *data, int len); +void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype, + void *data); +int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr); +ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); +ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); + +int EVP_PKEY_get_attr_count(const EVP_PKEY *key); +int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, int lastpos); +int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj, + int lastpos); +X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); +X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); +int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); +int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, + const ASN1_OBJECT *obj, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, + int nid, int type, + const unsigned char *bytes, int len); +int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, + const char *attrname, int type, + const unsigned char *bytes, int len); + +int X509_verify_cert(X509_STORE_CTX *ctx); + +/* lookup a cert from a X509 STACK */ +X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name, + ASN1_INTEGER *serial); +X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name); + +DECLARE_ASN1_FUNCTIONS(PBEPARAM) +DECLARE_ASN1_FUNCTIONS(PBE2PARAM) +DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM) +#ifndef OPENSSL_NO_SCRYPT +DECLARE_ASN1_FUNCTIONS(SCRYPT_PARAMS) +#endif + +int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, + const unsigned char *salt, int saltlen); + +X509_ALGOR *PKCS5_pbe_set(int alg, int iter, + const unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen, + unsigned char *aiv, int prf_nid); + +#ifndef OPENSSL_NO_SCRYPT +X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher, + const unsigned char *salt, int saltlen, + unsigned char *aiv, uint64_t N, uint64_t r, + uint64_t p); +#endif + +X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, + int prf_nid, int keylen); + +/* PKCS#8 utilities */ + +DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) + +EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); + +int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, + int version, int ptype, void *pval, + unsigned char *penc, int penclen); +int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, + const unsigned char **pk, int *ppklen, + const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); + +const STACK_OF(X509_ATTRIBUTE) * +PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8); +int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, + const unsigned char *bytes, int len); + +int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, + int ptype, void *pval, + unsigned char *penc, int penclen); +int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, + const unsigned char **pk, int *ppklen, + X509_ALGOR **pa, X509_PUBKEY *pub); + +int X509_check_trust(X509 *x, int id, int flags); +int X509_TRUST_get_count(void); +X509_TRUST *X509_TRUST_get0(int idx); +int X509_TRUST_get_by_id(int id); +int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), + const char *name, int arg1, void *arg2); +void X509_TRUST_cleanup(void); +int X509_TRUST_get_flags(const X509_TRUST *xp); +char *X509_TRUST_get0_name(const X509_TRUST *xp); +int X509_TRUST_get_trust(const X509_TRUST *xp); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/x509v3err.h postgresql-hll-2.14/include/openssl/x509v3err.h --- postgresql-hll-2.14_old/include/openssl/x509v3err.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/x509v3err.h 2020-12-12 17:06:43.344349290 +0800 @@ -0,0 +1,162 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509V3ERR_H +# define HEADER_X509V3ERR_H + +# ifndef HEADER_SYMHACKS_H +# include +# endif + +# ifdef __cplusplus +extern "C" +# endif +int ERR_load_X509V3_strings(void); + +/* + * X509V3 function codes. + */ +# define X509V3_F_A2I_GENERAL_NAME 164 +# define X509V3_F_ADDR_VALIDATE_PATH_INTERNAL 166 +# define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE 161 +# define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL 162 +# define X509V3_F_BIGNUM_TO_STRING 167 +# define X509V3_F_COPY_EMAIL 122 +# define X509V3_F_COPY_ISSUER 123 +# define X509V3_F_DO_DIRNAME 144 +# define X509V3_F_DO_EXT_I2D 135 +# define X509V3_F_DO_EXT_NCONF 151 +# define X509V3_F_GNAMES_FROM_SECTNAME 156 +# define X509V3_F_I2S_ASN1_ENUMERATED 121 +# define X509V3_F_I2S_ASN1_IA5STRING 149 +# define X509V3_F_I2S_ASN1_INTEGER 120 +# define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138 +# define X509V3_F_LEVEL_ADD_NODE 168 +# define X509V3_F_NOTICE_SECTION 132 +# define X509V3_F_NREF_NOS 133 +# define X509V3_F_POLICY_CACHE_CREATE 169 +# define X509V3_F_POLICY_CACHE_NEW 170 +# define X509V3_F_POLICY_DATA_NEW 171 +# define X509V3_F_POLICY_SECTION 131 +# define X509V3_F_PROCESS_PCI_VALUE 150 +# define X509V3_F_R2I_CERTPOL 130 +# define X509V3_F_R2I_PCI 155 +# define X509V3_F_S2I_ASN1_IA5STRING 100 +# define X509V3_F_S2I_ASN1_INTEGER 108 +# define X509V3_F_S2I_ASN1_OCTET_STRING 112 +# define X509V3_F_S2I_SKEY_ID 115 +# define X509V3_F_SET_DIST_POINT_NAME 158 +# define X509V3_F_SXNET_ADD_ID_ASC 125 +# define X509V3_F_SXNET_ADD_ID_INTEGER 126 +# define X509V3_F_SXNET_ADD_ID_ULONG 127 +# define X509V3_F_SXNET_GET_ID_ASC 128 +# define X509V3_F_SXNET_GET_ID_ULONG 129 +# define X509V3_F_TREE_INIT 172 +# define X509V3_F_V2I_ASIDENTIFIERS 163 +# define X509V3_F_V2I_ASN1_BIT_STRING 101 +# define X509V3_F_V2I_AUTHORITY_INFO_ACCESS 139 +# define X509V3_F_V2I_AUTHORITY_KEYID 119 +# define X509V3_F_V2I_BASIC_CONSTRAINTS 102 +# define X509V3_F_V2I_CRLD 134 +# define X509V3_F_V2I_EXTENDED_KEY_USAGE 103 +# define X509V3_F_V2I_GENERAL_NAMES 118 +# define X509V3_F_V2I_GENERAL_NAME_EX 117 +# define X509V3_F_V2I_IDP 157 +# define X509V3_F_V2I_IPADDRBLOCKS 159 +# define X509V3_F_V2I_ISSUER_ALT 153 +# define X509V3_F_V2I_NAME_CONSTRAINTS 147 +# define X509V3_F_V2I_POLICY_CONSTRAINTS 146 +# define X509V3_F_V2I_POLICY_MAPPINGS 145 +# define X509V3_F_V2I_SUBJECT_ALT 154 +# define X509V3_F_V2I_TLS_FEATURE 165 +# define X509V3_F_V3_GENERIC_EXTENSION 116 +# define X509V3_F_X509V3_ADD1_I2D 140 +# define X509V3_F_X509V3_ADD_VALUE 105 +# define X509V3_F_X509V3_EXT_ADD 104 +# define X509V3_F_X509V3_EXT_ADD_ALIAS 106 +# define X509V3_F_X509V3_EXT_I2D 136 +# define X509V3_F_X509V3_EXT_NCONF 152 +# define X509V3_F_X509V3_GET_SECTION 142 +# define X509V3_F_X509V3_GET_STRING 143 +# define X509V3_F_X509V3_GET_VALUE_BOOL 110 +# define X509V3_F_X509V3_PARSE_LIST 109 +# define X509V3_F_X509_PURPOSE_ADD 137 +# define X509V3_F_X509_PURPOSE_SET 141 + +/* + * X509V3 reason codes. + */ +# define X509V3_R_BAD_IP_ADDRESS 118 +# define X509V3_R_BAD_OBJECT 119 +# define X509V3_R_BN_DEC2BN_ERROR 100 +# define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101 +# define X509V3_R_DIRNAME_ERROR 149 +# define X509V3_R_DISTPOINT_ALREADY_SET 160 +# define X509V3_R_DUPLICATE_ZONE_ID 133 +# define X509V3_R_ERROR_CONVERTING_ZONE 131 +# define X509V3_R_ERROR_CREATING_EXTENSION 144 +# define X509V3_R_ERROR_IN_EXTENSION 128 +# define X509V3_R_EXPECTED_A_SECTION_NAME 137 +# define X509V3_R_EXTENSION_EXISTS 145 +# define X509V3_R_EXTENSION_NAME_ERROR 115 +# define X509V3_R_EXTENSION_NOT_FOUND 102 +# define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103 +# define X509V3_R_EXTENSION_VALUE_ERROR 116 +# define X509V3_R_ILLEGAL_EMPTY_EXTENSION 151 +# define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 152 +# define X509V3_R_INVALID_ASNUMBER 162 +# define X509V3_R_INVALID_ASRANGE 163 +# define X509V3_R_INVALID_BOOLEAN_STRING 104 +# define X509V3_R_INVALID_EXTENSION_STRING 105 +# define X509V3_R_INVALID_INHERITANCE 165 +# define X509V3_R_INVALID_IPADDRESS 166 +# define X509V3_R_INVALID_MULTIPLE_RDNS 161 +# define X509V3_R_INVALID_NAME 106 +# define X509V3_R_INVALID_NULL_ARGUMENT 107 +# define X509V3_R_INVALID_NULL_NAME 108 +# define X509V3_R_INVALID_NULL_VALUE 109 +# define X509V3_R_INVALID_NUMBER 140 +# define X509V3_R_INVALID_NUMBERS 141 +# define X509V3_R_INVALID_OBJECT_IDENTIFIER 110 +# define X509V3_R_INVALID_OPTION 138 +# define X509V3_R_INVALID_POLICY_IDENTIFIER 134 +# define X509V3_R_INVALID_PROXY_POLICY_SETTING 153 +# define X509V3_R_INVALID_PURPOSE 146 +# define X509V3_R_INVALID_SAFI 164 +# define X509V3_R_INVALID_SECTION 135 +# define X509V3_R_INVALID_SYNTAX 143 +# define X509V3_R_ISSUER_DECODE_ERROR 126 +# define X509V3_R_MISSING_VALUE 124 +# define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142 +# define X509V3_R_NO_CONFIG_DATABASE 136 +# define X509V3_R_NO_ISSUER_CERTIFICATE 121 +# define X509V3_R_NO_ISSUER_DETAILS 127 +# define X509V3_R_NO_POLICY_IDENTIFIER 139 +# define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 154 +# define X509V3_R_NO_PUBLIC_KEY 114 +# define X509V3_R_NO_SUBJECT_DETAILS 125 +# define X509V3_R_OPERATION_NOT_DEFINED 148 +# define X509V3_R_OTHERNAME_ERROR 147 +# define X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED 155 +# define X509V3_R_POLICY_PATH_LENGTH 156 +# define X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED 157 +# define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159 +# define X509V3_R_SECTION_NOT_FOUND 150 +# define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122 +# define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123 +# define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111 +# define X509V3_R_UNKNOWN_EXTENSION 129 +# define X509V3_R_UNKNOWN_EXTENSION_NAME 130 +# define X509V3_R_UNKNOWN_OPTION 120 +# define X509V3_R_UNSUPPORTED_OPTION 117 +# define X509V3_R_UNSUPPORTED_TYPE 167 +# define X509V3_R_USER_TOO_LONG 132 + +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/x509v3.h postgresql-hll-2.14/include/openssl/x509v3.h --- postgresql-hll-2.14_old/include/openssl/x509v3.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/x509v3.h 2020-12-12 17:06:43.344349290 +0800 @@ -0,0 +1,937 @@ +/* + * Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509V3_H +# define HEADER_X509V3_H + +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward reference */ +struct v3_ext_method; +struct v3_ext_ctx; + +/* Useful typedefs */ + +typedef void *(*X509V3_EXT_NEW)(void); +typedef void (*X509V3_EXT_FREE) (void *); +typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); +typedef int (*X509V3_EXT_I2D) (void *, unsigned char **); +typedef STACK_OF(CONF_VALUE) * + (*X509V3_EXT_I2V) (const struct v3_ext_method *method, void *ext, + STACK_OF(CONF_VALUE) *extlist); +typedef void *(*X509V3_EXT_V2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, + STACK_OF(CONF_VALUE) *values); +typedef char *(*X509V3_EXT_I2S)(const struct v3_ext_method *method, + void *ext); +typedef void *(*X509V3_EXT_S2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, const char *str); +typedef int (*X509V3_EXT_I2R) (const struct v3_ext_method *method, void *ext, + BIO *out, int indent); +typedef void *(*X509V3_EXT_R2I)(const struct v3_ext_method *method, + struct v3_ext_ctx *ctx, const char *str); + +/* V3 extension structure */ + +struct v3_ext_method { + int ext_nid; + int ext_flags; +/* If this is set the following four fields are ignored */ + ASN1_ITEM_EXP *it; +/* Old style ASN1 calls */ + X509V3_EXT_NEW ext_new; + X509V3_EXT_FREE ext_free; + X509V3_EXT_D2I d2i; + X509V3_EXT_I2D i2d; +/* The following pair is used for string extensions */ + X509V3_EXT_I2S i2s; + X509V3_EXT_S2I s2i; +/* The following pair is used for multi-valued extensions */ + X509V3_EXT_I2V i2v; + X509V3_EXT_V2I v2i; +/* The following are used for raw extensions */ + X509V3_EXT_I2R i2r; + X509V3_EXT_R2I r2i; + void *usr_data; /* Any extension specific data */ +}; + +typedef struct X509V3_CONF_METHOD_st { + char *(*get_string) (void *db, const char *section, const char *value); + STACK_OF(CONF_VALUE) *(*get_section) (void *db, const char *section); + void (*free_string) (void *db, char *string); + void (*free_section) (void *db, STACK_OF(CONF_VALUE) *section); +} X509V3_CONF_METHOD; + +/* Context specific info */ +struct v3_ext_ctx { +# define CTX_TEST 0x1 +# define X509V3_CTX_REPLACE 0x2 + int flags; + X509 *issuer_cert; + X509 *subject_cert; + X509_REQ *subject_req; + X509_CRL *crl; + X509V3_CONF_METHOD *db_meth; + void *db; +/* Maybe more here */ +}; + +typedef struct v3_ext_method X509V3_EXT_METHOD; + +DEFINE_STACK_OF(X509V3_EXT_METHOD) + +/* ext_flags values */ +# define X509V3_EXT_DYNAMIC 0x1 +# define X509V3_EXT_CTX_DEP 0x2 +# define X509V3_EXT_MULTILINE 0x4 + +typedef BIT_STRING_BITNAME ENUMERATED_NAMES; + +typedef struct BASIC_CONSTRAINTS_st { + int ca; + ASN1_INTEGER *pathlen; +} BASIC_CONSTRAINTS; + +typedef struct PKEY_USAGE_PERIOD_st { + ASN1_GENERALIZEDTIME *notBefore; + ASN1_GENERALIZEDTIME *notAfter; +} PKEY_USAGE_PERIOD; + +typedef struct otherName_st { + ASN1_OBJECT *type_id; + ASN1_TYPE *value; +} OTHERNAME; + +typedef struct EDIPartyName_st { + ASN1_STRING *nameAssigner; + ASN1_STRING *partyName; +} EDIPARTYNAME; + +typedef struct GENERAL_NAME_st { +# define GEN_OTHERNAME 0 +# define GEN_EMAIL 1 +# define GEN_DNS 2 +# define GEN_X400 3 +# define GEN_DIRNAME 4 +# define GEN_EDIPARTY 5 +# define GEN_URI 6 +# define GEN_IPADD 7 +# define GEN_RID 8 + int type; + union { + char *ptr; + OTHERNAME *otherName; /* otherName */ + ASN1_IA5STRING *rfc822Name; + ASN1_IA5STRING *dNSName; + ASN1_TYPE *x400Address; + X509_NAME *directoryName; + EDIPARTYNAME *ediPartyName; + ASN1_IA5STRING *uniformResourceIdentifier; + ASN1_OCTET_STRING *iPAddress; + ASN1_OBJECT *registeredID; + /* Old names */ + ASN1_OCTET_STRING *ip; /* iPAddress */ + X509_NAME *dirn; /* dirn */ + ASN1_IA5STRING *ia5; /* rfc822Name, dNSName, + * uniformResourceIdentifier */ + ASN1_OBJECT *rid; /* registeredID */ + ASN1_TYPE *other; /* x400Address */ + } d; +} GENERAL_NAME; + +typedef struct ACCESS_DESCRIPTION_st { + ASN1_OBJECT *method; + GENERAL_NAME *location; +} ACCESS_DESCRIPTION; + +typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; + +typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; + +typedef STACK_OF(ASN1_INTEGER) TLS_FEATURE; + +DEFINE_STACK_OF(GENERAL_NAME) +typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; +DEFINE_STACK_OF(GENERAL_NAMES) + +DEFINE_STACK_OF(ACCESS_DESCRIPTION) + +typedef struct DIST_POINT_NAME_st { + int type; + union { + GENERAL_NAMES *fullname; + STACK_OF(X509_NAME_ENTRY) *relativename; + } name; +/* If relativename then this contains the full distribution point name */ + X509_NAME *dpname; +} DIST_POINT_NAME; +/* All existing reasons */ +# define CRLDP_ALL_REASONS 0x807f + +# define CRL_REASON_NONE -1 +# define CRL_REASON_UNSPECIFIED 0 +# define CRL_REASON_KEY_COMPROMISE 1 +# define CRL_REASON_CA_COMPROMISE 2 +# define CRL_REASON_AFFILIATION_CHANGED 3 +# define CRL_REASON_SUPERSEDED 4 +# define CRL_REASON_CESSATION_OF_OPERATION 5 +# define CRL_REASON_CERTIFICATE_HOLD 6 +# define CRL_REASON_REMOVE_FROM_CRL 8 +# define CRL_REASON_PRIVILEGE_WITHDRAWN 9 +# define CRL_REASON_AA_COMPROMISE 10 + +struct DIST_POINT_st { + DIST_POINT_NAME *distpoint; + ASN1_BIT_STRING *reasons; + GENERAL_NAMES *CRLissuer; + int dp_reasons; +}; + +typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; + +DEFINE_STACK_OF(DIST_POINT) + +struct AUTHORITY_KEYID_st { + ASN1_OCTET_STRING *keyid; + GENERAL_NAMES *issuer; + ASN1_INTEGER *serial; +}; + +/* Strong extranet structures */ + +typedef struct SXNET_ID_st { + ASN1_INTEGER *zone; + ASN1_OCTET_STRING *user; +} SXNETID; + +DEFINE_STACK_OF(SXNETID) + +typedef struct SXNET_st { + ASN1_INTEGER *version; + STACK_OF(SXNETID) *ids; +} SXNET; + +typedef struct NOTICEREF_st { + ASN1_STRING *organization; + STACK_OF(ASN1_INTEGER) *noticenos; +} NOTICEREF; + +typedef struct USERNOTICE_st { + NOTICEREF *noticeref; + ASN1_STRING *exptext; +} USERNOTICE; + +typedef struct POLICYQUALINFO_st { + ASN1_OBJECT *pqualid; + union { + ASN1_IA5STRING *cpsuri; + USERNOTICE *usernotice; + ASN1_TYPE *other; + } d; +} POLICYQUALINFO; + +DEFINE_STACK_OF(POLICYQUALINFO) + +typedef struct POLICYINFO_st { + ASN1_OBJECT *policyid; + STACK_OF(POLICYQUALINFO) *qualifiers; +} POLICYINFO; + +typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; + +DEFINE_STACK_OF(POLICYINFO) + +typedef struct POLICY_MAPPING_st { + ASN1_OBJECT *issuerDomainPolicy; + ASN1_OBJECT *subjectDomainPolicy; +} POLICY_MAPPING; + +DEFINE_STACK_OF(POLICY_MAPPING) + +typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; + +typedef struct GENERAL_SUBTREE_st { + GENERAL_NAME *base; + ASN1_INTEGER *minimum; + ASN1_INTEGER *maximum; +} GENERAL_SUBTREE; + +DEFINE_STACK_OF(GENERAL_SUBTREE) + +struct NAME_CONSTRAINTS_st { + STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; + STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; +}; + +typedef struct POLICY_CONSTRAINTS_st { + ASN1_INTEGER *requireExplicitPolicy; + ASN1_INTEGER *inhibitPolicyMapping; +} POLICY_CONSTRAINTS; + +/* Proxy certificate structures, see RFC 3820 */ +typedef struct PROXY_POLICY_st { + ASN1_OBJECT *policyLanguage; + ASN1_OCTET_STRING *policy; +} PROXY_POLICY; + +typedef struct PROXY_CERT_INFO_EXTENSION_st { + ASN1_INTEGER *pcPathLengthConstraint; + PROXY_POLICY *proxyPolicy; +} PROXY_CERT_INFO_EXTENSION; + +DECLARE_ASN1_FUNCTIONS(PROXY_POLICY) +DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) + +struct ISSUING_DIST_POINT_st { + DIST_POINT_NAME *distpoint; + int onlyuser; + int onlyCA; + ASN1_BIT_STRING *onlysomereasons; + int indirectCRL; + int onlyattr; +}; + +/* Values in idp_flags field */ +/* IDP present */ +# define IDP_PRESENT 0x1 +/* IDP values inconsistent */ +# define IDP_INVALID 0x2 +/* onlyuser true */ +# define IDP_ONLYUSER 0x4 +/* onlyCA true */ +# define IDP_ONLYCA 0x8 +/* onlyattr true */ +# define IDP_ONLYATTR 0x10 +/* indirectCRL true */ +# define IDP_INDIRECT 0x20 +/* onlysomereasons present */ +# define IDP_REASONS 0x40 + +# define X509V3_conf_err(val) ERR_add_error_data(6, \ + "section:", (val)->section, \ + ",name:", (val)->name, ",value:", (val)->value) + +# define X509V3_set_ctx_test(ctx) \ + X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST) +# define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; + +# define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ + 0,0,0,0, \ + 0,0, \ + (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ + (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ + NULL, NULL, \ + table} + +# define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ + 0,0,0,0, \ + (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ + 0,0,0,0, \ + NULL} + +# define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + +/* X509_PURPOSE stuff */ + +# define EXFLAG_BCONS 0x1 +# define EXFLAG_KUSAGE 0x2 +# define EXFLAG_XKUSAGE 0x4 +# define EXFLAG_NSCERT 0x8 + +# define EXFLAG_CA 0x10 +/* Really self issued not necessarily self signed */ +# define EXFLAG_SI 0x20 +# define EXFLAG_V1 0x40 +# define EXFLAG_INVALID 0x80 +/* EXFLAG_SET is set to indicate that some values have been precomputed */ +# define EXFLAG_SET 0x100 +# define EXFLAG_CRITICAL 0x200 +# define EXFLAG_PROXY 0x400 + +# define EXFLAG_INVALID_POLICY 0x800 +# define EXFLAG_FRESHEST 0x1000 +/* Self signed */ +# define EXFLAG_SS 0x2000 + +# define KU_DIGITAL_SIGNATURE 0x0080 +# define KU_NON_REPUDIATION 0x0040 +# define KU_KEY_ENCIPHERMENT 0x0020 +# define KU_DATA_ENCIPHERMENT 0x0010 +# define KU_KEY_AGREEMENT 0x0008 +# define KU_KEY_CERT_SIGN 0x0004 +# define KU_CRL_SIGN 0x0002 +# define KU_ENCIPHER_ONLY 0x0001 +# define KU_DECIPHER_ONLY 0x8000 + +# define NS_SSL_CLIENT 0x80 +# define NS_SSL_SERVER 0x40 +# define NS_SMIME 0x20 +# define NS_OBJSIGN 0x10 +# define NS_SSL_CA 0x04 +# define NS_SMIME_CA 0x02 +# define NS_OBJSIGN_CA 0x01 +# define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA) + +# define XKU_SSL_SERVER 0x1 +# define XKU_SSL_CLIENT 0x2 +# define XKU_SMIME 0x4 +# define XKU_CODE_SIGN 0x8 +# define XKU_SGC 0x10 +# define XKU_OCSP_SIGN 0x20 +# define XKU_TIMESTAMP 0x40 +# define XKU_DVCS 0x80 +# define XKU_ANYEKU 0x100 + +# define X509_PURPOSE_DYNAMIC 0x1 +# define X509_PURPOSE_DYNAMIC_NAME 0x2 + +typedef struct x509_purpose_st { + int purpose; + int trust; /* Default trust ID */ + int flags; + int (*check_purpose) (const struct x509_purpose_st *, const X509 *, int); + char *name; + char *sname; + void *usr_data; +} X509_PURPOSE; + +# define X509_PURPOSE_SSL_CLIENT 1 +# define X509_PURPOSE_SSL_SERVER 2 +# define X509_PURPOSE_NS_SSL_SERVER 3 +# define X509_PURPOSE_SMIME_SIGN 4 +# define X509_PURPOSE_SMIME_ENCRYPT 5 +# define X509_PURPOSE_CRL_SIGN 6 +# define X509_PURPOSE_ANY 7 +# define X509_PURPOSE_OCSP_HELPER 8 +# define X509_PURPOSE_TIMESTAMP_SIGN 9 + +# define X509_PURPOSE_MIN 1 +# define X509_PURPOSE_MAX 9 + +/* Flags for X509V3_EXT_print() */ + +# define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) +/* Return error for unknown extensions */ +# define X509V3_EXT_DEFAULT 0 +/* Print error for unknown extensions */ +# define X509V3_EXT_ERROR_UNKNOWN (1L << 16) +/* ASN1 parse unknown extensions */ +# define X509V3_EXT_PARSE_UNKNOWN (2L << 16) +/* BIO_dump unknown extensions */ +# define X509V3_EXT_DUMP_UNKNOWN (3L << 16) + +/* Flags for X509V3_add1_i2d */ + +# define X509V3_ADD_OP_MASK 0xfL +# define X509V3_ADD_DEFAULT 0L +# define X509V3_ADD_APPEND 1L +# define X509V3_ADD_REPLACE 2L +# define X509V3_ADD_REPLACE_EXISTING 3L +# define X509V3_ADD_KEEP_EXISTING 4L +# define X509V3_ADD_DELETE 5L +# define X509V3_ADD_SILENT 0x10 + +DEFINE_STACK_OF(X509_PURPOSE) + +DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) + +DECLARE_ASN1_FUNCTIONS(SXNET) +DECLARE_ASN1_FUNCTIONS(SXNETID) + +int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen); +int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user, + int userlen); +int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, const char *user, + int userlen); + +ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone); +ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); +ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone); + +DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID) + +DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD) + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) +GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a); +int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b); + +ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *nval); +STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + ASN1_BIT_STRING *bits, + STACK_OF(CONF_VALUE) *extlist); +char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); +ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, const char *str); + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, + GENERAL_NAME *gen, + STACK_OF(CONF_VALUE) *ret); +int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); + +DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, + GENERAL_NAMES *gen, + STACK_OF(CONF_VALUE) *extlist); +GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + +DECLARE_ASN1_FUNCTIONS(OTHERNAME) +DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) +int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b); +void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value); +void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype); +int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, + ASN1_OBJECT *oid, ASN1_TYPE *value); +int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen, + ASN1_OBJECT **poid, ASN1_TYPE **pvalue); + +char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + const ASN1_OCTET_STRING *ia5); +ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, const char *str); + +DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) +int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a); + +DECLARE_ASN1_ALLOC_FUNCTIONS(TLS_FEATURE) + +DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) +DECLARE_ASN1_FUNCTIONS(POLICYINFO) +DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO) +DECLARE_ASN1_FUNCTIONS(USERNOTICE) +DECLARE_ASN1_FUNCTIONS(NOTICEREF) + +DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS) +DECLARE_ASN1_FUNCTIONS(DIST_POINT) +DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME) +DECLARE_ASN1_FUNCTIONS(ISSUING_DIST_POINT) + +int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); + +int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc); +int NAME_CONSTRAINTS_check_CN(X509 *x, NAME_CONSTRAINTS *nc); + +DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) +DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) + +DECLARE_ASN1_ITEM(POLICY_MAPPING) +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) +DECLARE_ASN1_ITEM(POLICY_MAPPINGS) + +DECLARE_ASN1_ITEM(GENERAL_SUBTREE) +DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) + +DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) +DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) + +DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) +DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) + +GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, int gen_type, + const char *value, int is_nc); + +# ifdef HEADER_CONF_H +GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf); +GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, + const X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, CONF_VALUE *cnf, + int is_nc); +void X509V3_conf_free(CONF_VALUE *val); + +X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, + const char *value); +X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, const char *name, + const char *value); +int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section, + STACK_OF(X509_EXTENSION) **sk); +int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509 *cert); +int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509_REQ *req); +int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, + X509_CRL *crl); + +X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, + X509V3_CTX *ctx, int ext_nid, + const char *value); +X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *name, const char *value); +int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509 *cert); +int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509_REQ *req); +int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, + const char *section, X509_CRL *crl); + +int X509V3_add_value_bool_nf(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool); +int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint); +void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf); +void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash); +# endif + +char *X509V3_get_string(X509V3_CTX *ctx, const char *name, const char *section); +STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, const char *section); +void X509V3_string_free(X509V3_CTX *ctx, char *str); +void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); +void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, + X509_REQ *req, X509_CRL *crl, int flags); + +int X509V3_add_value(const char *name, const char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_uchar(const char *name, const unsigned char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_bool(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint, + STACK_OF(CONF_VALUE) **extlist); +char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const ASN1_INTEGER *aint); +ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const char *value); +char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, const ASN1_ENUMERATED *aint); +char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, + const ASN1_ENUMERATED *aint); +int X509V3_EXT_add(X509V3_EXT_METHOD *ext); +int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); +int X509V3_EXT_add_alias(int nid_to, int nid_from); +void X509V3_EXT_cleanup(void); + +const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext); +const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); +int X509V3_add_standard_extensions(void); +STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); +void *X509V3_EXT_d2i(X509_EXTENSION *ext); +void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, + int *idx); + +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); +int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, + int crit, unsigned long flags); + +#if OPENSSL_API_COMPAT < 0x10100000L +/* The new declarations are in crypto.h, but the old ones were here. */ +# define hex_to_string OPENSSL_buf2hexstr +# define string_to_hex OPENSSL_hexstr2buf +#endif + +void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, + int ml); +int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, + int indent); +#ifndef OPENSSL_NO_STDIO +int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); +#endif +int X509V3_extensions_print(BIO *out, const char *title, + const STACK_OF(X509_EXTENSION) *exts, + unsigned long flag, int indent); + +int X509_check_ca(X509 *x); +int X509_check_purpose(X509 *x, int id, int ca); +int X509_supported_extension(X509_EXTENSION *ex); +int X509_PURPOSE_set(int *p, int purpose); +int X509_check_issued(X509 *issuer, X509 *subject); +int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid); +void X509_set_proxy_flag(X509 *x); +void X509_set_proxy_pathlen(X509 *x, long l); +long X509_get_proxy_pathlen(X509 *x); + +uint32_t X509_get_extension_flags(X509 *x); +uint32_t X509_get_key_usage(X509 *x); +uint32_t X509_get_extended_key_usage(X509 *x); +const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x); +const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x); +const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x); +const ASN1_INTEGER *X509_get0_authority_serial(X509 *x); + +int X509_PURPOSE_get_count(void); +X509_PURPOSE *X509_PURPOSE_get0(int idx); +int X509_PURPOSE_get_by_sname(const char *sname); +int X509_PURPOSE_get_by_id(int id); +int X509_PURPOSE_add(int id, int trust, int flags, + int (*ck) (const X509_PURPOSE *, const X509 *, int), + const char *name, const char *sname, void *arg); +char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp); +char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp); +int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); +void X509_PURPOSE_cleanup(void); +int X509_PURPOSE_get_id(const X509_PURPOSE *); + +STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x); +STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x); +void X509_email_free(STACK_OF(OPENSSL_STRING) *sk); +STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x); +/* Flags for X509_check_* functions */ + +/* + * Always check subject name for host match even if subject alt names present + */ +# define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0x1 +/* Disable wildcard matching for dnsName fields and common name. */ +# define X509_CHECK_FLAG_NO_WILDCARDS 0x2 +/* Wildcards must not match a partial label. */ +# define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0x4 +/* Allow (non-partial) wildcards to match multiple labels. */ +# define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0x8 +/* Constraint verifier subdomain patterns to match a single labels. */ +# define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0x10 +/* Never check the subject CN */ +# define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 +/* + * Match reference identifiers starting with "." to any sub-domain. + * This is a non-public flag, turned on implicitly when the subject + * reference identity is a DNS name. + */ +# define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 + +int X509_check_host(X509 *x, const char *chk, size_t chklen, + unsigned int flags, char **peername); +int X509_check_email(X509 *x, const char *chk, size_t chklen, + unsigned int flags); +int X509_check_ip(X509 *x, const unsigned char *chk, size_t chklen, + unsigned int flags); +int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags); + +ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); +ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); +int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, + unsigned long chtype); + +void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); +DEFINE_STACK_OF(X509_POLICY_NODE) + +#ifndef OPENSSL_NO_RFC3779 +typedef struct ASRange_st { + ASN1_INTEGER *min, *max; +} ASRange; + +# define ASIdOrRange_id 0 +# define ASIdOrRange_range 1 + +typedef struct ASIdOrRange_st { + int type; + union { + ASN1_INTEGER *id; + ASRange *range; + } u; +} ASIdOrRange; + +typedef STACK_OF(ASIdOrRange) ASIdOrRanges; +DEFINE_STACK_OF(ASIdOrRange) + +# define ASIdentifierChoice_inherit 0 +# define ASIdentifierChoice_asIdsOrRanges 1 + +typedef struct ASIdentifierChoice_st { + int type; + union { + ASN1_NULL *inherit; + ASIdOrRanges *asIdsOrRanges; + } u; +} ASIdentifierChoice; + +typedef struct ASIdentifiers_st { + ASIdentifierChoice *asnum, *rdi; +} ASIdentifiers; + +DECLARE_ASN1_FUNCTIONS(ASRange) +DECLARE_ASN1_FUNCTIONS(ASIdOrRange) +DECLARE_ASN1_FUNCTIONS(ASIdentifierChoice) +DECLARE_ASN1_FUNCTIONS(ASIdentifiers) + +typedef struct IPAddressRange_st { + ASN1_BIT_STRING *min, *max; +} IPAddressRange; + +# define IPAddressOrRange_addressPrefix 0 +# define IPAddressOrRange_addressRange 1 + +typedef struct IPAddressOrRange_st { + int type; + union { + ASN1_BIT_STRING *addressPrefix; + IPAddressRange *addressRange; + } u; +} IPAddressOrRange; + +typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; +DEFINE_STACK_OF(IPAddressOrRange) + +# define IPAddressChoice_inherit 0 +# define IPAddressChoice_addressesOrRanges 1 + +typedef struct IPAddressChoice_st { + int type; + union { + ASN1_NULL *inherit; + IPAddressOrRanges *addressesOrRanges; + } u; +} IPAddressChoice; + +typedef struct IPAddressFamily_st { + ASN1_OCTET_STRING *addressFamily; + IPAddressChoice *ipAddressChoice; +} IPAddressFamily; + +typedef STACK_OF(IPAddressFamily) IPAddrBlocks; +DEFINE_STACK_OF(IPAddressFamily) + +DECLARE_ASN1_FUNCTIONS(IPAddressRange) +DECLARE_ASN1_FUNCTIONS(IPAddressOrRange) +DECLARE_ASN1_FUNCTIONS(IPAddressChoice) +DECLARE_ASN1_FUNCTIONS(IPAddressFamily) + +/* + * API tag for elements of the ASIdentifer SEQUENCE. + */ +# define V3_ASID_ASNUM 0 +# define V3_ASID_RDI 1 + +/* + * AFI values, assigned by IANA. It'd be nice to make the AFI + * handling code totally generic, but there are too many little things + * that would need to be defined for other address families for it to + * be worth the trouble. + */ +# define IANA_AFI_IPV4 1 +# define IANA_AFI_IPV6 2 + +/* + * Utilities to construct and extract values from RFC3779 extensions, + * since some of the encodings (particularly for IP address prefixes + * and ranges) are a bit tedious to work with directly. + */ +int X509v3_asid_add_inherit(ASIdentifiers *asid, int which); +int X509v3_asid_add_id_or_range(ASIdentifiers *asid, int which, + ASN1_INTEGER *min, ASN1_INTEGER *max); +int X509v3_addr_add_inherit(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi); +int X509v3_addr_add_prefix(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *a, const int prefixlen); +int X509v3_addr_add_range(IPAddrBlocks *addr, + const unsigned afi, const unsigned *safi, + unsigned char *min, unsigned char *max); +unsigned X509v3_addr_get_afi(const IPAddressFamily *f); +int X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, + unsigned char *min, unsigned char *max, + const int length); + +/* + * Canonical forms. + */ +int X509v3_asid_is_canonical(ASIdentifiers *asid); +int X509v3_addr_is_canonical(IPAddrBlocks *addr); +int X509v3_asid_canonize(ASIdentifiers *asid); +int X509v3_addr_canonize(IPAddrBlocks *addr); + +/* + * Tests for inheritance and containment. + */ +int X509v3_asid_inherits(ASIdentifiers *asid); +int X509v3_addr_inherits(IPAddrBlocks *addr); +int X509v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b); +int X509v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b); + +/* + * Check whether RFC 3779 extensions nest properly in chains. + */ +int X509v3_asid_validate_path(X509_STORE_CTX *); +int X509v3_addr_validate_path(X509_STORE_CTX *); +int X509v3_asid_validate_resource_set(STACK_OF(X509) *chain, + ASIdentifiers *ext, + int allow_inheritance); +int X509v3_addr_validate_resource_set(STACK_OF(X509) *chain, + IPAddrBlocks *ext, int allow_inheritance); + +#endif /* OPENSSL_NO_RFC3779 */ + +DEFINE_STACK_OF(ASN1_STRING) + +/* + * Admission Syntax + */ +typedef struct NamingAuthority_st NAMING_AUTHORITY; +typedef struct ProfessionInfo_st PROFESSION_INFO; +typedef struct Admissions_st ADMISSIONS; +typedef struct AdmissionSyntax_st ADMISSION_SYNTAX; +DECLARE_ASN1_FUNCTIONS(NAMING_AUTHORITY) +DECLARE_ASN1_FUNCTIONS(PROFESSION_INFO) +DECLARE_ASN1_FUNCTIONS(ADMISSIONS) +DECLARE_ASN1_FUNCTIONS(ADMISSION_SYNTAX) +DEFINE_STACK_OF(ADMISSIONS) +DEFINE_STACK_OF(PROFESSION_INFO) +typedef STACK_OF(PROFESSION_INFO) PROFESSION_INFOS; + +const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId( + const NAMING_AUTHORITY *n); +const ASN1_IA5STRING *NAMING_AUTHORITY_get0_authorityURL( + const NAMING_AUTHORITY *n); +const ASN1_STRING *NAMING_AUTHORITY_get0_authorityText( + const NAMING_AUTHORITY *n); +void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY *n, + ASN1_OBJECT* namingAuthorityId); +void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY *n, + ASN1_IA5STRING* namingAuthorityUrl); +void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY *n, + ASN1_STRING* namingAuthorityText); + +const GENERAL_NAME *ADMISSION_SYNTAX_get0_admissionAuthority( + const ADMISSION_SYNTAX *as); +void ADMISSION_SYNTAX_set0_admissionAuthority( + ADMISSION_SYNTAX *as, GENERAL_NAME *aa); +const STACK_OF(ADMISSIONS) *ADMISSION_SYNTAX_get0_contentsOfAdmissions( + const ADMISSION_SYNTAX *as); +void ADMISSION_SYNTAX_set0_contentsOfAdmissions( + ADMISSION_SYNTAX *as, STACK_OF(ADMISSIONS) *a); +const GENERAL_NAME *ADMISSIONS_get0_admissionAuthority(const ADMISSIONS *a); +void ADMISSIONS_set0_admissionAuthority(ADMISSIONS *a, GENERAL_NAME *aa); +const NAMING_AUTHORITY *ADMISSIONS_get0_namingAuthority(const ADMISSIONS *a); +void ADMISSIONS_set0_namingAuthority(ADMISSIONS *a, NAMING_AUTHORITY *na); +const PROFESSION_INFOS *ADMISSIONS_get0_professionInfos(const ADMISSIONS *a); +void ADMISSIONS_set0_professionInfos(ADMISSIONS *a, PROFESSION_INFOS *pi); +const ASN1_OCTET_STRING *PROFESSION_INFO_get0_addProfessionInfo( + const PROFESSION_INFO *pi); +void PROFESSION_INFO_set0_addProfessionInfo( + PROFESSION_INFO *pi, ASN1_OCTET_STRING *aos); +const NAMING_AUTHORITY *PROFESSION_INFO_get0_namingAuthority( + const PROFESSION_INFO *pi); +void PROFESSION_INFO_set0_namingAuthority( + PROFESSION_INFO *pi, NAMING_AUTHORITY *na); +const STACK_OF(ASN1_STRING) *PROFESSION_INFO_get0_professionItems( + const PROFESSION_INFO *pi); +void PROFESSION_INFO_set0_professionItems( + PROFESSION_INFO *pi, STACK_OF(ASN1_STRING) *as); +const STACK_OF(ASN1_OBJECT) *PROFESSION_INFO_get0_professionOIDs( + const PROFESSION_INFO *pi); +void PROFESSION_INFO_set0_professionOIDs( + PROFESSION_INFO *pi, STACK_OF(ASN1_OBJECT) *po); +const ASN1_PRINTABLESTRING *PROFESSION_INFO_get0_registrationNumber( + const PROFESSION_INFO *pi); +void PROFESSION_INFO_set0_registrationNumber( + PROFESSION_INFO *pi, ASN1_PRINTABLESTRING *rn); + +# ifdef __cplusplus +} +# endif +#endif diff -uprN postgresql-hll-2.14_old/include/openssl/x509_vfy.h postgresql-hll-2.14/include/openssl/x509_vfy.h --- postgresql-hll-2.14_old/include/openssl/x509_vfy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/openssl/x509_vfy.h 2020-12-12 17:06:43.344349290 +0800 @@ -0,0 +1,628 @@ +/* + * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_X509_VFY_H +# define HEADER_X509_VFY_H + +/* + * Protect against recursion, x509.h and x509_vfy.h each include the other. + */ +# ifndef HEADER_X509_H +# include +# endif + +# include +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +/*- +SSL_CTX -> X509_STORE + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + +SSL -> X509_STORE_CTX + ->X509_STORE + +The X509_STORE holds the tables etc for verification stuff. +A X509_STORE_CTX is used while validating a single certificate. +The X509_STORE has X509_LOOKUPs for looking up certs. +The X509_STORE then calls a function to actually verify the +certificate chain. +*/ + +typedef enum { + X509_LU_NONE = 0, + X509_LU_X509, X509_LU_CRL +} X509_LOOKUP_TYPE; + +#if OPENSSL_API_COMPAT < 0x10100000L +#define X509_LU_RETRY -1 +#define X509_LU_FAIL 0 +#endif + +DEFINE_STACK_OF(X509_LOOKUP) +DEFINE_STACK_OF(X509_OBJECT) +DEFINE_STACK_OF(X509_VERIFY_PARAM) + +int X509_STORE_set_depth(X509_STORE *store, int depth); + +typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, + X509_STORE_CTX *ctx, X509 *x); +typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, + X509 *x, X509 *issuer); +typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx); +typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, + X509_CRL **crl, X509 *x); +typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); +typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, + X509_CRL *crl, X509 *x); +typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx); +typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx, + X509_NAME *nm); +typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)(X509_STORE_CTX *ctx, + X509_NAME *nm); +typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx); + + +void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); + +# define X509_STORE_CTX_set_app_data(ctx,data) \ + X509_STORE_CTX_set_ex_data(ctx,0,data) +# define X509_STORE_CTX_get_app_data(ctx) \ + X509_STORE_CTX_get_ex_data(ctx,0) + +# define X509_L_FILE_LOAD 1 +# define X509_L_ADD_DIR 2 + +# define X509_LOOKUP_load_file(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) + +# define X509_LOOKUP_add_dir(x,name,type) \ + X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) + +# define X509_V_OK 0 +# define X509_V_ERR_UNSPECIFIED 1 +# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +# define X509_V_ERR_UNABLE_TO_GET_CRL 3 +# define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +# define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +# define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +# define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +# define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +# define X509_V_ERR_CERT_NOT_YET_VALID 9 +# define X509_V_ERR_CERT_HAS_EXPIRED 10 +# define X509_V_ERR_CRL_NOT_YET_VALID 11 +# define X509_V_ERR_CRL_HAS_EXPIRED 12 +# define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +# define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +# define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +# define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +# define X509_V_ERR_OUT_OF_MEM 17 +# define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +# define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +# define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +# define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +# define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +# define X509_V_ERR_CERT_REVOKED 23 +# define X509_V_ERR_INVALID_CA 24 +# define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +# define X509_V_ERR_INVALID_PURPOSE 26 +# define X509_V_ERR_CERT_UNTRUSTED 27 +# define X509_V_ERR_CERT_REJECTED 28 +/* These are 'informational' when looking for issuer cert */ +# define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +# define X509_V_ERR_AKID_SKID_MISMATCH 30 +# define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +# define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 +# define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +# define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +# define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +# define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +# define X509_V_ERR_INVALID_NON_CA 37 +# define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +# define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +# define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 +# define X509_V_ERR_INVALID_EXTENSION 41 +# define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +# define X509_V_ERR_NO_EXPLICIT_POLICY 43 +# define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 +# define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 +# define X509_V_ERR_UNNESTED_RESOURCE 46 +# define X509_V_ERR_PERMITTED_VIOLATION 47 +# define X509_V_ERR_EXCLUDED_VIOLATION 48 +# define X509_V_ERR_SUBTREE_MINMAX 49 +/* The application is not happy */ +# define X509_V_ERR_APPLICATION_VERIFICATION 50 +# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 +# define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 +# define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 +# define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 +/* Another issuer check debug option */ +# define X509_V_ERR_PATH_LOOP 55 +/* Suite B mode algorithm violation */ +# define X509_V_ERR_SUITE_B_INVALID_VERSION 56 +# define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 +# define X509_V_ERR_SUITE_B_INVALID_CURVE 58 +# define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 +# define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 +# define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 +/* Host, email and IP check errors */ +# define X509_V_ERR_HOSTNAME_MISMATCH 62 +# define X509_V_ERR_EMAIL_MISMATCH 63 +# define X509_V_ERR_IP_ADDRESS_MISMATCH 64 +/* DANE TLSA errors */ +# define X509_V_ERR_DANE_NO_MATCH 65 +/* security level errors */ +# define X509_V_ERR_EE_KEY_TOO_SMALL 66 +# define X509_V_ERR_CA_KEY_TOO_SMALL 67 +# define X509_V_ERR_CA_MD_TOO_WEAK 68 +/* Caller error */ +# define X509_V_ERR_INVALID_CALL 69 +/* Issuer lookup error */ +# define X509_V_ERR_STORE_LOOKUP 70 +/* Certificate transparency */ +# define X509_V_ERR_NO_VALID_SCTS 71 + +# define X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION 72 +/* OCSP status errors */ +# define X509_V_ERR_OCSP_VERIFY_NEEDED 73 /* Need OCSP verification */ +# define X509_V_ERR_OCSP_VERIFY_FAILED 74 /* Couldn't verify cert through OCSP */ +# define X509_V_ERR_OCSP_CERT_UNKNOWN 75 /* Certificate wasn't recognized by the OCSP responder */ + +/* Certificate verify flags */ + +# if OPENSSL_API_COMPAT < 0x10100000L +# define X509_V_FLAG_CB_ISSUER_CHECK 0x0 /* Deprecated */ +# endif +/* Use check time instead of current time */ +# define X509_V_FLAG_USE_CHECK_TIME 0x2 +/* Lookup CRLs */ +# define X509_V_FLAG_CRL_CHECK 0x4 +/* Lookup CRLs for whole chain */ +# define X509_V_FLAG_CRL_CHECK_ALL 0x8 +/* Ignore unhandled critical extensions */ +# define X509_V_FLAG_IGNORE_CRITICAL 0x10 +/* Disable workarounds for broken certificates */ +# define X509_V_FLAG_X509_STRICT 0x20 +/* Enable proxy certificate validation */ +# define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +/* Enable policy checking */ +# define X509_V_FLAG_POLICY_CHECK 0x80 +/* Policy variable require-explicit-policy */ +# define X509_V_FLAG_EXPLICIT_POLICY 0x100 +/* Policy variable inhibit-any-policy */ +# define X509_V_FLAG_INHIBIT_ANY 0x200 +/* Policy variable inhibit-policy-mapping */ +# define X509_V_FLAG_INHIBIT_MAP 0x400 +/* Notify callback that policy is OK */ +# define X509_V_FLAG_NOTIFY_POLICY 0x800 +/* Extended CRL features such as indirect CRLs, alternate CRL signing keys */ +# define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 +/* Delta CRL support */ +# define X509_V_FLAG_USE_DELTAS 0x2000 +/* Check self-signed CA signature */ +# define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +/* Use trusted store first */ +# define X509_V_FLAG_TRUSTED_FIRST 0x8000 +/* Suite B 128 bit only mode: not normally used */ +# define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 +/* Suite B 192 bit only mode */ +# define X509_V_FLAG_SUITEB_192_LOS 0x20000 +/* Suite B 128 bit mode allowing 192 bit algorithms */ +# define X509_V_FLAG_SUITEB_128_LOS 0x30000 +/* Allow partial chains if at least one certificate is in trusted store */ +# define X509_V_FLAG_PARTIAL_CHAIN 0x80000 +/* + * If the initial chain is not trusted, do not attempt to build an alternative + * chain. Alternate chain checking was introduced in 1.1.0. Setting this flag + * will force the behaviour to match that of previous versions. + */ +# define X509_V_FLAG_NO_ALT_CHAINS 0x100000 +/* Do not check certificate/CRL validity against current time */ +# define X509_V_FLAG_NO_CHECK_TIME 0x200000 + +# define X509_VP_FLAG_DEFAULT 0x1 +# define X509_VP_FLAG_OVERWRITE 0x2 +# define X509_VP_FLAG_RESET_FLAGS 0x4 +# define X509_VP_FLAG_LOCKED 0x8 +# define X509_VP_FLAG_ONCE 0x10 + +/* Internal use: mask of policy related options */ +# define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ + | X509_V_FLAG_EXPLICIT_POLICY \ + | X509_V_FLAG_INHIBIT_ANY \ + | X509_V_FLAG_INHIBIT_MAP) + +int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, X509_LOOKUP_TYPE type, + X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, + X509_LOOKUP_TYPE type, + X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, + X509_OBJECT *x); +int X509_OBJECT_up_ref_count(X509_OBJECT *a); +X509_OBJECT *X509_OBJECT_new(void); +void X509_OBJECT_free(X509_OBJECT *a); +X509_LOOKUP_TYPE X509_OBJECT_get_type(const X509_OBJECT *a); +X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a); +int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj); +X509_CRL *X509_OBJECT_get0_X509_CRL(X509_OBJECT *a); +int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj); +X509_STORE *X509_STORE_new(void); +void X509_STORE_free(X509_STORE *v); +int X509_STORE_lock(X509_STORE *ctx); +int X509_STORE_unlock(X509_STORE *ctx); +int X509_STORE_up_ref(X509_STORE *v); +STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *v); + +STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *st, X509_NAME *nm); +STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *st, X509_NAME *nm); +int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); +int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); +int X509_STORE_set_trust(X509_STORE *ctx, int trust); +int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm); +X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx); + +void X509_STORE_set_verify(X509_STORE *ctx, X509_STORE_CTX_verify_fn verify); +#define X509_STORE_set_verify_func(ctx, func) \ + X509_STORE_set_verify((ctx),(func)) +void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, + X509_STORE_CTX_verify_fn verify); +X509_STORE_CTX_verify_fn X509_STORE_get_verify(X509_STORE *ctx); +void X509_STORE_set_verify_cb(X509_STORE *ctx, + X509_STORE_CTX_verify_cb verify_cb); +# define X509_STORE_set_verify_cb_func(ctx,func) \ + X509_STORE_set_verify_cb((ctx),(func)) +X509_STORE_CTX_verify_cb X509_STORE_get_verify_cb(X509_STORE *ctx); +void X509_STORE_set_get_issuer(X509_STORE *ctx, + X509_STORE_CTX_get_issuer_fn get_issuer); +X509_STORE_CTX_get_issuer_fn X509_STORE_get_get_issuer(X509_STORE *ctx); +void X509_STORE_set_check_issued(X509_STORE *ctx, + X509_STORE_CTX_check_issued_fn check_issued); +X509_STORE_CTX_check_issued_fn X509_STORE_get_check_issued(X509_STORE *ctx); +void X509_STORE_set_check_revocation(X509_STORE *ctx, + X509_STORE_CTX_check_revocation_fn check_revocation); +X509_STORE_CTX_check_revocation_fn X509_STORE_get_check_revocation(X509_STORE *ctx); +void X509_STORE_set_get_crl(X509_STORE *ctx, + X509_STORE_CTX_get_crl_fn get_crl); +X509_STORE_CTX_get_crl_fn X509_STORE_get_get_crl(X509_STORE *ctx); +void X509_STORE_set_check_crl(X509_STORE *ctx, + X509_STORE_CTX_check_crl_fn check_crl); +X509_STORE_CTX_check_crl_fn X509_STORE_get_check_crl(X509_STORE *ctx); +void X509_STORE_set_cert_crl(X509_STORE *ctx, + X509_STORE_CTX_cert_crl_fn cert_crl); +X509_STORE_CTX_cert_crl_fn X509_STORE_get_cert_crl(X509_STORE *ctx); +void X509_STORE_set_check_policy(X509_STORE *ctx, + X509_STORE_CTX_check_policy_fn check_policy); +X509_STORE_CTX_check_policy_fn X509_STORE_get_check_policy(X509_STORE *ctx); +void X509_STORE_set_lookup_certs(X509_STORE *ctx, + X509_STORE_CTX_lookup_certs_fn lookup_certs); +X509_STORE_CTX_lookup_certs_fn X509_STORE_get_lookup_certs(X509_STORE *ctx); +void X509_STORE_set_lookup_crls(X509_STORE *ctx, + X509_STORE_CTX_lookup_crls_fn lookup_crls); +#define X509_STORE_set_lookup_crls_cb(ctx, func) \ + X509_STORE_set_lookup_crls((ctx), (func)) +X509_STORE_CTX_lookup_crls_fn X509_STORE_get_lookup_crls(X509_STORE *ctx); +void X509_STORE_set_cleanup(X509_STORE *ctx, + X509_STORE_CTX_cleanup_fn cleanup); +X509_STORE_CTX_cleanup_fn X509_STORE_get_cleanup(X509_STORE *ctx); + +#define X509_STORE_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE, l, p, newf, dupf, freef) +int X509_STORE_set_ex_data(X509_STORE *ctx, int idx, void *data); +void *X509_STORE_get_ex_data(X509_STORE *ctx, int idx); + +X509_STORE_CTX *X509_STORE_CTX_new(void); + +int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); + +void X509_STORE_CTX_free(X509_STORE_CTX *ctx); +int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, + X509 *x509, STACK_OF(X509) *chain); +void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); +void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); + +X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); +X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx); +STACK_OF(X509)* X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set0_untrusted(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); +void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, + X509_STORE_CTX_verify_cb verify); +X509_STORE_CTX_verify_cb X509_STORE_CTX_get_verify_cb(X509_STORE_CTX *ctx); +X509_STORE_CTX_verify_fn X509_STORE_CTX_get_verify(X509_STORE_CTX *ctx); +X509_STORE_CTX_get_issuer_fn X509_STORE_CTX_get_get_issuer(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_issued_fn X509_STORE_CTX_get_check_issued(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_revocation_fn X509_STORE_CTX_get_check_revocation(X509_STORE_CTX *ctx); +X509_STORE_CTX_get_crl_fn X509_STORE_CTX_get_get_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_crl_fn X509_STORE_CTX_get_check_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_cert_crl_fn X509_STORE_CTX_get_cert_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX_check_policy_fn X509_STORE_CTX_get_check_policy(X509_STORE_CTX *ctx); +X509_STORE_CTX_lookup_certs_fn X509_STORE_CTX_get_lookup_certs(X509_STORE_CTX *ctx); +X509_STORE_CTX_lookup_crls_fn X509_STORE_CTX_get_lookup_crls(X509_STORE_CTX *ctx); +X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(X509_STORE_CTX *ctx); + +#if OPENSSL_API_COMPAT < 0x10100000L +# define X509_STORE_CTX_get_chain X509_STORE_CTX_get0_chain +# define X509_STORE_CTX_set_chain X509_STORE_CTX_set0_untrusted +# define X509_STORE_CTX_trusted_stack X509_STORE_CTX_set0_trusted_stack +# define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject +# define X509_STORE_get1_certs X509_STORE_CTX_get1_certs +# define X509_STORE_get1_crls X509_STORE_CTX_get1_crls +/* the following macro is misspelled; use X509_STORE_get1_certs instead */ +# define X509_STORE_get1_cert X509_STORE_CTX_get1_certs +/* the following macro is misspelled; use X509_STORE_get1_crls instead */ +# define X509_STORE_get1_crl X509_STORE_CTX_get1_crls +#endif + +X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); +X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); +X509_LOOKUP_METHOD *X509_LOOKUP_file(void); + +typedef int (*X509_LOOKUP_ctrl_fn)(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); +typedef int (*X509_LOOKUP_get_by_subject_fn)(X509_LOOKUP *ctx, + X509_LOOKUP_TYPE type, + X509_NAME *name, + X509_OBJECT *ret); +typedef int (*X509_LOOKUP_get_by_issuer_serial_fn)(X509_LOOKUP *ctx, + X509_LOOKUP_TYPE type, + X509_NAME *name, + ASN1_INTEGER *serial, + X509_OBJECT *ret); +typedef int (*X509_LOOKUP_get_by_fingerprint_fn)(X509_LOOKUP *ctx, + X509_LOOKUP_TYPE type, + const unsigned char* bytes, + int len, + X509_OBJECT *ret); +typedef int (*X509_LOOKUP_get_by_alias_fn)(X509_LOOKUP *ctx, + X509_LOOKUP_TYPE type, + const char *str, + int len, + X509_OBJECT *ret); + +X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name); +void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method); + +int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method, + int (*new_item) (X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method)) + (X509_LOOKUP *ctx); + +int X509_LOOKUP_meth_set_free(X509_LOOKUP_METHOD *method, + void (*free_fn) (X509_LOOKUP *ctx)); +void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method)) + (X509_LOOKUP *ctx); + +int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method, + int (*init) (X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method)) + (X509_LOOKUP *ctx); + +int X509_LOOKUP_meth_set_shutdown(X509_LOOKUP_METHOD *method, + int (*shutdown) (X509_LOOKUP *ctx)); +int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method)) + (X509_LOOKUP *ctx); + +int X509_LOOKUP_meth_set_ctrl(X509_LOOKUP_METHOD *method, + X509_LOOKUP_ctrl_fn ctrl_fn); +X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method); + +int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method, + X509_LOOKUP_get_by_subject_fn fn); +X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject( + const X509_LOOKUP_METHOD *method); + +int X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method, + X509_LOOKUP_get_by_issuer_serial_fn fn); +X509_LOOKUP_get_by_issuer_serial_fn X509_LOOKUP_meth_get_get_by_issuer_serial( + const X509_LOOKUP_METHOD *method); + +int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method, + X509_LOOKUP_get_by_fingerprint_fn fn); +X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint( + const X509_LOOKUP_METHOD *method); + +int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method, + X509_LOOKUP_get_by_alias_fn fn); +X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias( + const X509_LOOKUP_METHOD *method); + + +int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); +int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); + +int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, + X509_NAME *name, X509_OBJECT *ret); +X509_OBJECT *X509_STORE_CTX_get_obj_by_subject(X509_STORE_CTX *vs, + X509_LOOKUP_TYPE type, + X509_NAME *name); + +int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); + +int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type); + +X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); +void X509_LOOKUP_free(X509_LOOKUP *ctx); +int X509_LOOKUP_init(X509_LOOKUP *ctx); +int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + X509_NAME *name, X509_OBJECT *ret); +int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + X509_NAME *name, ASN1_INTEGER *serial, + X509_OBJECT *ret); +int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + const unsigned char *bytes, int len, + X509_OBJECT *ret); +int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, X509_LOOKUP_TYPE type, + const char *str, int len, X509_OBJECT *ret); +int X509_LOOKUP_set_method_data(X509_LOOKUP *ctx, void *data); +void *X509_LOOKUP_get_method_data(const X509_LOOKUP *ctx); +X509_STORE *X509_LOOKUP_get_store(const X509_LOOKUP *ctx); +int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); + +int X509_STORE_load_locations(X509_STORE *ctx, + const char *file, const char *dir); +int X509_STORE_set_default_paths(X509_STORE *ctx); + +#define X509_STORE_CTX_get_ex_new_index(l, p, newf, dupf, freef) \ + CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, l, p, newf, dupf, freef) +int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data); +void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx); +int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s); +int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_error_depth(X509_STORE_CTX *ctx, int depth); +X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_current_cert(X509_STORE_CTX *ctx, X509 *x); +X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx); +X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); +X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x); +void X509_STORE_CTX_set0_verified_chain(X509_STORE_CTX *c, STACK_OF(X509) *sk); +void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c, STACK_OF(X509_CRL) *sk); +int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); +int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); +int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, + int purpose, int trust); +void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); +void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, + time_t t); + +X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx); +int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); +int X509_STORE_CTX_get_num_untrusted(X509_STORE_CTX *ctx); + +X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx); +void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param); +int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name); + +/* + * Bridge opacity barrier between libcrypt and libssl, also needed to support + * offline testing in test/danetest.c + */ +void X509_STORE_CTX_set0_dane(X509_STORE_CTX *ctx, SSL_DANE *dane); +#define DANE_FLAG_NO_DANE_EE_NAMECHECKS (1L << 0) + +/* X509_VERIFY_PARAM functions */ + +X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); +void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name); +int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose); +int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust); +void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth); +void X509_VERIFY_PARAM_set_auth_level(X509_VERIFY_PARAM *param, int auth_level); +time_t X509_VERIFY_PARAM_get_time(const X509_VERIFY_PARAM *param); +void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t); +int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, + ASN1_OBJECT *policy); +int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, + STACK_OF(ASN1_OBJECT) *policies); + +int X509_VERIFY_PARAM_set_inh_flags(X509_VERIFY_PARAM *param, + uint32_t flags); +uint32_t X509_VERIFY_PARAM_get_inh_flags(const X509_VERIFY_PARAM *param); + +int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, + const char *name, size_t namelen); +int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, + const char *name, size_t namelen); +void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, + unsigned int flags); +unsigned int X509_VERIFY_PARAM_get_hostflags(const X509_VERIFY_PARAM *param); +char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *); +void X509_VERIFY_PARAM_move_peername(X509_VERIFY_PARAM *, X509_VERIFY_PARAM *); +int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, + const char *email, size_t emaillen); +int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, + const unsigned char *ip, size_t iplen); +int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, + const char *ipasc); + +int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_get_auth_level(const X509_VERIFY_PARAM *param); +const char *X509_VERIFY_PARAM_get0_name(const X509_VERIFY_PARAM *param); + +int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); +int X509_VERIFY_PARAM_get_count(void); +const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id); +const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); +void X509_VERIFY_PARAM_table_cleanup(void); + +/* Non positive return values are errors */ +#define X509_PCY_TREE_FAILURE -2 /* Failure to satisfy explicit policy */ +#define X509_PCY_TREE_INVALID -1 /* Inconsistent or invalid extensions */ +#define X509_PCY_TREE_INTERNAL 0 /* Internal error, most likely malloc */ + +/* + * Positive return values form a bit mask, all but the first are internal to + * the library and don't appear in results from X509_policy_check(). + */ +#define X509_PCY_TREE_VALID 1 /* The policy tree is valid */ +#define X509_PCY_TREE_EMPTY 2 /* The policy tree is empty */ +#define X509_PCY_TREE_EXPLICIT 4 /* Explicit policy required */ + +int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, + STACK_OF(X509) *certs, + STACK_OF(ASN1_OBJECT) *policy_oids, unsigned int flags); + +void X509_policy_tree_free(X509_POLICY_TREE *tree); + +int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); +X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, + int i); + +STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const + X509_POLICY_TREE + *tree); + +STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const + X509_POLICY_TREE + *tree); + +int X509_policy_level_node_count(X509_POLICY_LEVEL *level); + +X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, + int i); + +const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node); + +STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const + X509_POLICY_NODE + *node); +const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE + *node); + +#ifdef __cplusplus +} +#endif +#endif diff -uprN postgresql-hll-2.14_old/include/opfusion/opfusion.h postgresql-hll-2.14/include/opfusion/opfusion.h --- postgresql-hll-2.14_old/include/opfusion/opfusion.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/opfusion/opfusion.h 2020-12-12 17:06:43.344349290 +0800 @@ -0,0 +1,396 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion.h + * Operator Fusion's definition for bypass. + * + * IDENTIFICATION + * src/include/opfusion/opfusion.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_H_ +#include "auditfuncs.h" +#include "commands/prepare.h" +#include "opfusion/opfusion_util.h" +#include "opfusion/opfusion_scan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +extern void report_qps_type(CmdType commandType); +extern const char* getBypassReason(FusionType result); +extern void BypassUnsupportedReason(FusionType result); +extern void ExecCheckXactReadOnly(PlannedStmt* plannedstmt); +void InitParamInFusionConstruct(const TupleDesc tupDesc, Datum** values, bool** isNull); +extern FusionType getSelectFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getInsertFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getUpdateFusionType(List* stmt_list, ParamListInfo params); +extern FusionType getDeleteFusionType(List* stmt_list, ParamListInfo params); +extern void tpslot_free_heaptuple(TupleTableSlot* reslot); + +typedef struct pnFusionObj { + char portalname[NAMEDATALEN]; + OpFusion *opfusion; +} pnFusionObj; + +#define HASH_TBL_LEN 64 + +class OpFusion : public BaseObject { +public: + OpFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list); + + virtual ~OpFusion(){}; + + static void* FusionFactory( + FusionType type, MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + static FusionType getFusionType(CachedPlan* cplan, ParamListInfo params, List* plantree_list); + + static void setCurrentOpFusionObj(OpFusion* obj); + + static bool process(int op, StringInfo msg, char* completionTag, bool isTopLevel); + + void CopyFormats(int16* formats, int numRFormats); + + void updatePreAllocParamter(StringInfo msg); + + void useOuterParameter(ParamListInfo params); + + void decribe(StringInfo msg); + + virtual bool execute(long max_rows, char* completionTag) + { + Assert(false); + return false; + } + + virtual void close() + { + Assert(false); + return; + } + + void setPreparedDestReceiver(DestReceiver* preparedDest); + + Datum CalFuncNodeVal(Oid functionId, List* args, bool* is_null, Datum* values, bool* isNulls); + + Datum EvalSimpleArg(Node* arg, bool* is_null, Datum* values, bool* isNulls); + + static void tearDown(OpFusion* opfusion); + + static void clearForCplan(OpFusion* opfusion, CachedPlanSource* psrc); + + void checkPermission(); + + void setReceiver(); + + void initParams(ParamListInfo params); + + void executeInit(); + + void executeEnd(const char* portal_name); + + void auditRecord(); + + static bool isQueryCompleted(); + + void bindClearPosition(); + + static void initFusionHtab(); + + void storeFusion(const char *portalname); + + static OpFusion *locateFusion(const char *portalname); + + static void removeFusionFromHtab(const char *portalname); + + static void refreshCurFusion(StringInfo msg); + +public: + struct ParamLoc { + int paramId; + int scanKeyIndx; + }; + + CachedPlanSource* m_psrc; /* to get m_cacheplan in PBE */ + + CachedPlan* m_cacheplan; + + PlannedStmt* m_planstmt; /* m_cacheplan->stmt_list in PBE, plantree in non-PBE */ + + bool m_isFirst; /* be true if is the fisrt execute in PBE */ + + MemoryContext m_context; + + MemoryContext m_tmpContext; /* use for tmp memory allocation. */ + + ParamListInfo m_params; + + ParamListInfo m_outParams; /* use outer side parameter. */ + + int m_paramNum; + + ParamLoc* m_paramLoc; /* location of m_params, include paramId and the location in indexqual */ + + Oid m_reloid; /* relation oid of range table */ + + TupleDesc m_tupDesc; /* tuple descriptor */ + + TupleTableSlot* m_reslot; /* result slot */ + + int16* m_attrno; /* target attribute number, length is m_tupDesc->natts */ + + Datum* m_values; + + bool* m_isnull; + + Datum* m_tmpvals; /* for mapping m_values */ + + bool* m_tmpisnull; /* for mapping m_isnull */ + + DestReceiver* m_receiver; + + bool m_isInsideRec; + + bool m_is_pbe_query; + + int16* m_rformats; + + bool m_isCompleted; + + long m_position; + + const char *m_portalName; +}; + +class SelectFusion : public OpFusion { +public: + SelectFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SelectFusion(){}; + + bool execute(long max_rows, char* completionTag); + + void close(); + +private: + class ScanFusion* m_scan; + + int64 m_limitCount; + + int64 m_limitOffset; +}; + +class InsertFusion : public OpFusion { +public: + InsertFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~InsertFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + void refreshParameterIfNecessary(); + + EState* m_estate; + + /* for func/op expr calculation */ + FuncExprInfo* m_targetFuncNodes; + + int m_targetFuncNum; + + int m_targetParamNum; + + Datum* m_curVarValue; + + bool* m_curVarIsnull; + + bool m_is_bucket_rel; +}; + +class UpdateFusion : public OpFusion { +public: + UpdateFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~UpdateFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + class ScanFusion* m_scan; + + HeapTuple heapModifyTuple(HeapTuple tuple); + + void refreshTargetParameterIfNecessary(); + + EState* m_estate; + + /* targetlist */ + int m_targetNum; + + int m_targetParamNum; + + Datum* m_targetValues; + + bool* m_targetIsnull; + + Datum* m_curVarValue; + struct VarLoc { + int varNo; + int scanKeyIndx; + }; + + VarLoc* m_targetVarLoc; + + int m_varNum; + + bool* m_curVarIsnull; + + int* m_targetConstLoc; + + ParamLoc* m_targetParamLoc; + + /* for func/op expr calculation */ + FuncExprInfo* m_targetFuncNodes; + + int m_targetFuncNum; + + bool m_is_bucket_rel; +}; + +class DeleteFusion : public OpFusion { +public: + DeleteFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~DeleteFusion(){}; + + bool execute(long max_rows, char* completionTag); + +private: + class ScanFusion* m_scan; + + EState* m_estate; + + bool m_is_bucket_rel; +}; + +#ifdef ENABLE_MOT +class MotJitSelectFusion : public OpFusion { +public: + MotJitSelectFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params); + + ~MotJitSelectFusion() {}; + + bool execute(long max_rows, char *completionTag); +}; + +class MotJitModifyFusion : public OpFusion { +public: + MotJitModifyFusion(MemoryContext context, CachedPlanSource *psrc, List *plantree_list, ParamListInfo params); + + ~MotJitModifyFusion() {}; + + bool execute(long max_rows, char *completionTag); + +private: + EState* m_estate; + CmdType m_cmdType; +}; +#endif + +class SelectForUpdateFusion : public OpFusion { +public: + SelectForUpdateFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SelectForUpdateFusion(){}; + + bool execute(long max_rows, char* completionTag); + + void close(); + +private: + class ScanFusion* m_scan; + + int64 m_limitCount; + + EState* m_estate; + + int64 m_limitOffset; + + bool m_is_bucket_rel; +}; + +class AggFusion : public OpFusion { + +public: + AggFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~AggFusion(){}; + + bool execute(long max_rows, char* completionTag); + +protected: + + typedef void (AggFusion::*aggSumFun)(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + /* agg sum function */ + void agg_int2_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_int4_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_int8_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + void agg_numeric_sum(Datum *transVal, bool transIsNull, Datum *inVal, bool inIsNull); + + inline void init_var_from_num(Numeric num, NumericVar *dest) + { + Assert(!NUMERIC_IS_BI(num)); + dest->ndigits = NUMERIC_NDIGITS(num); + dest->weight = NUMERIC_WEIGHT(num); + dest->sign = NUMERIC_SIGN(num); + dest->dscale = NUMERIC_DSCALE(num); + dest->digits = NUMERIC_DIGITS(num); + dest->buf = NULL; /* digits array is not palloc'd */ + } + + class ScanFusion* m_scan; + + aggSumFun m_aggSumFunc; +}; + +class SortFusion: public OpFusion { + +public: + + SortFusion(MemoryContext context, CachedPlanSource* psrc, List* plantree_list, ParamListInfo params); + + ~SortFusion(){}; + + bool execute(long max_rows, char *completionTag); + +protected: + + class ScanFusion* m_scan; + + TupleDesc m_scanDesc; +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/opfusion/opfusion_scan.h postgresql-hll-2.14/include/opfusion/opfusion_scan.h --- postgresql-hll-2.14_old/include/opfusion/opfusion_scan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/opfusion/opfusion_scan.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,185 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion_scan.h + * scan operator's definition for bypass executor. + * + * IDENTIFICATION + * src/include/opfusion/opfusion_scan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ +#include "commands/prepare.h" +#include "executor/nodeIndexonlyscan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "storage/buf.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +struct ParamLoc { + int paramId; + int scanKeyIndx; +}; + +class ScanFusion : public BaseObject { +public: + ScanFusion(); + + ScanFusion(ParamListInfo params, PlannedStmt* planstmt); + + static ScanFusion* getScanFusion(Node* node, PlannedStmt* planstmt, ParamListInfo params); + + void refreshParameter(ParamListInfo params); + + virtual void Init(long max_rows) = 0; + + virtual HeapTuple getTuple() = 0; + + virtual void End(bool isCompleted) = 0; + + virtual bool EpqCheck(Datum* values, const bool* isnull) = 0; + + virtual void UpdateCurrentRel(Relation* rel) = 0; + + virtual void setAttrNo() = 0; + + virtual TupleTableSlot* getTupleSlot() = 0; + + ParamListInfo m_params; + + PlannedStmt* m_planstmt; + + Relation m_rel; + + Relation m_parentRel; + + Partition m_partRel; + + TupleTableSlot* m_reslot; + + TupleDesc m_tupDesc; + + ScanDirection* m_direction; +}; + +class IndexFusion : public ScanFusion { +public: + IndexFusion(ParamListInfo params, PlannedStmt* planstmt); + + IndexFusion() + {} + + void refreshParameterIfNecessary(); + + void BuildNullTestScanKey(Expr* clause, Expr* leftop, ScanKey this_scan_key); + + void IndexBuildScanKey(List* indexqual); + + virtual void Init(long max_rows) = 0; + + virtual HeapTuple getTuple() = 0; + + virtual void End(bool isCompleted) = 0; + + void setAttrNo(); + + virtual TupleTableSlot* getTupleSlot() = 0; + + bool EpqCheck(Datum* values, const bool* isnull); + + void UpdateCurrentRel(Relation* rel); + + Relation m_index; /* index relation */ + + Oid m_reloid; /* relation oid of range table */ + + IndexScanDesc m_scandesc; + + List* m_epq_indexqual; /* indexqual list */ + + bool m_keyInit; /* true if m_scanKeys has been initialized */ + + int m_keyNum; /* num of scan key */ + + ScanKey m_scanKeys; + + ParamLoc* m_paramLoc; /* location of m_params, include paramId and the location in indexqual */ + + int m_paramNum; + + Datum* m_values; + + bool* m_isnull; + + Datum* m_tmpvals; /* for mapping m_values */ + + bool* m_tmpisnull; /* for mapping m_isnull */ + + List* m_targetList; + + int16* m_attrno; /* target attribute number, length is m_tupDesc->natts */ + +}; + +class IndexScanFusion : public IndexFusion { +public: + IndexScanFusion() + {} + + ~IndexScanFusion(){}; + + IndexScanFusion(IndexScan* node, PlannedStmt* planstmt, ParamListInfo params); + + void Init(long max_rows); + + HeapTuple getTuple(); + + void End(bool isCompleted); + + TupleTableSlot* getTupleSlot(); + +private: + struct IndexScan* m_node; +}; + +class IndexOnlyScanFusion : public IndexFusion { +public: + IndexOnlyScanFusion() + {} + + ~IndexOnlyScanFusion(){}; + + IndexOnlyScanFusion(IndexOnlyScan* node, PlannedStmt* planstmt, ParamListInfo params); + + void Init(long max_rows); + + HeapTuple getTuple(); + + void End(bool isCompleted); + + TupleTableSlot* getTupleSlot(); + +private: + struct IndexOnlyScan* m_node; + + Buffer m_VMBuffer; +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_SCAN_H_ */ + diff -uprN postgresql-hll-2.14_old/include/opfusion/opfusion_util.h postgresql-hll-2.14/include/opfusion/opfusion_util.h --- postgresql-hll-2.14_old/include/opfusion/opfusion_util.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/opfusion/opfusion_util.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,240 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * opfusion_util.h + * Operator Fusion's definition for bypass. + * + * IDENTIFICATION + * src/include/opfusion/opfusion_util.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ +#define SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ +#include "commands/prepare.h" +#include "opfusion/opfusion_scan.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "pgxc/pgxcnode.h" +#include "utils/plancache.h" +#include "utils/syscache.h" + +const int FUSION_EXECUTE = 0; +const int FUSION_DESCRIB = 1; + +extern int namestrcmp(Name name, const char* str); +extern void report_qps_type(CmdType commandType); +void InitOpfusionFunctionId(); + +enum FusionType { + NONE_FUSION, + + SELECT_FUSION, + SELECT_FOR_UPDATE_FUSION, + INSERT_FUSION, + UPDATE_FUSION, + DELETE_FUSION, + AGG_INDEX_FUSION, + SORT_INDEX_FUSION, + + MOT_JIT_SELECT_FUSION, + MOT_JIT_MODIFY_FUSION, + + BYPASS_OK, + + NOBYPASS_NO_CPLAN, + NOBYPASS_NO_SIMPLE_PLAN, + NOBYPASS_NO_QUERY_TYPE, + NOBYPASS_LIMITOFFSET_CONST_LESS_THAN_ZERO, + NOBYPASS_LIMITCOUNT_CONST_LESS_THAN_ZERO, + NOBYPASS_LIMIT_NOT_CONST, + NOBYPASS_INVALID_SELECT_FOR_UPDATE, + NOBYPASS_INVALID_MODIFYTABLE, + NOBYPASS_NO_SIMPLE_INSERT, + NOBYPASS_UPSERT_NOT_SUPPORT, + + NOBYPASS_NO_INDEXSCAN, + NOBYPASS_INDEXSCAN_WITH_ORDERBY, + NOBYPASS_INDEXSCAN_WITH_QUAL, + NOBYPASS_INDEXSCAN_CONDITION_INVALID, + + NOBYPASS_INDEXONLYSCAN_WITH_ORDERBY, + NOBYPASS_INDEXONLYSCAN_WITH_QUAL, + NOBYPASS_INDEXONLYSCAN_CONDITION_INVALID, + + NOBYPASS_TARGET_WITH_SYS_COL, + NOBYPASS_TARGET_WITH_NO_TABLE_COL, + NOBYPASS_NO_TARGETENTRY, + NOBYPASS_PARAM_TYPE_INVALID, + + NOBYPASS_DML_RELATION_NUM_INVALID, + NOBYPASS_DML_RELATION_NOT_SUPPORT, + NOBYPASS_DML_TARGET_TYPE_INVALID, + + NOBYPASS_EXP_NOT_SUPPORT, + NOBYPASS_STREAM_NOT_SUPPORT, + NOBYPASS_NULLTEST_TYPE_INVALID, + + NOBYPASS_INVALID_PLAN, + + NOBYPASS_NOT_PLAIN_AGG, + NOBYPASS_ONE_TARGET_ALLOWED, + NOBYPASS_AGGREF_TARGET_ALLOWED, + NOBYPASS_JUST_SUM_ALLOWED, + NOBYPASS_JUST_VAR_FOR_AGGARGS, + + NOBYPASS_JUST_MERGE_UNSUPPORTED, + NOBYPASS_JUST_VAR_ALLOWED_IN_SORT, + + NOBYPASS_ZERO_PARTITION, + NOBYPASS_MULTI_PARTITION, + NOBYPASS_EXP_NOT_SUPPORT_IN_PARTITION, + NO_BYPASS_PARTITIONKEY_IS_NULL, + NOBYPASS_NO_UPDATE_PARTITIONKEY, + NOBYPASS_NO_INCLUDING_PARTITIONKEY, + NOBYPASS_PARTITION_BYPASS_NOT_OPEN +}; + +enum FusionDebug { + BYPASS_OFF, + BYPASS_LOG, +}; + +const int MAX_OP_FUNCTION_NUM = 2; + +typedef struct FuncExprInfo { + AttrNumber resno; + Oid funcid; + List* args; +} FuncExprInfo; + +const int OPFUSION_FUNCTION_ID_MAX_HASH_SIZE = 200; + +/* length of function_id should not more than OPFUSION_FUNCTION_ID_MAX_HASH_SIZE */ +const Oid function_id[] = { + 311, /* convert float4 to float8 */ + 312, /* convert float8 to float4 */ + 313, /* convert int2 to int4 */ + 314, /* convert int4 to int2 */ + 315, /* int2vectoreq */ + 316, /* convert int4 to float8 */ + 317, /* convert float8 to int4 */ + 318, /* convert int4 to float4 */ + 319, /* convert float4 to int4 */ + 401, /* convert char(n) to text */ + 406, /* convert name to text */ + 407, /* convert text to name */ + 408, /* convert name to char(n) */ + 409, /* convert char(n) to name */ + 668, /* adjust char() to typmod length */ + 669, /* adjust varchar() to typmod length */ + 944, /* convert text to char */ + 946, /* convert char to text */ + 1200, /* adjust interval precision */ + 1400, /* convert varchar to name */ + 1401, /* convert name to varchar */ + 1683, /* convert int4 to bitstring */ + 1684, /* convert bitstring to int4 */ + 1685, /* adjust bit() to typmod length */ + 1687, /* adjust varbit() to typmod length */ + 1703, /* adjust numeric to typmod precision/scale */ + 1705, /* abs */ + 1706, /* sign */ + 1707, /* round */ + 1711, /* ceil */ + 1712, /* floor */ + 1728, /* mod */ + 1740, /* convert int4 to numeric */ + 1742, /* convert float4 to numeric */ + 1743, /* convert float8 to numeric */ + 1744, /* convert numeric to int4 */ + 1745, /* convert numeric to float4 */ + 1746, /* convert numeric to float8 */ + 1768, /* format interval to text */ + 1777, /* convert text to numeric */ + 1778, /* convert text to timestamp with time zone */ + 1780, /* convert text to date */ + 1961, /* adjust timestamp precision */ + 1967, /* adjust timestamptz precision */ + 1968, /* adjust time precision */ + 1969, /* adjust time with time zone precision */ + 2089, /* convert int4 number to hex */ + 2090, /* convert int8 number to hex */ + 2617, /* ceiling */ + 3192, /* convert int4 to bpchar */ + 3207, /* convert text to timestamp without time zone */ + 3811, /* convert int4 to money */ + 3812, /* convert int8 to money */ + 3823, /* convert money to numeric */ + 3824, /* convert numeric to money */ + 3961, /* adjust nvarchar2() to typmod length */ + 3961, /* adjust nvarchar2() to typmod length */ + 4065, /* convert int1 to varchar */ + 4066, /* convert int1 to nvarchar2 */ + 4067, /* convert int1 to bpchar */ + 4068, /* convert int2 to bpchar */ + 4069, /* convert int8 to bpchar */ + 4070, /* convert float4 to bpchar */ + 4071, /* convert float8 to bpchar */ + 4072, /* convert numeric to bpchar */ + 4073, /* convert text to timestamp */ + 4167, /* convert int4 to text */ + 4168, /* convert int8 to text */ + 4169, /* convert float4 to text */ + 4170, /* convert float8 to text */ + 4171, /* convert numeric to text */ + 4172, /* convert bpchar to numeric */ + 4173, /* convert varchar to numeric */ + 4174, /* convert varchar to int4 */ + 4175, /* convert bpchar to int4 */ + 4176, /* convert varchar to int8 */ + 4177, /* convert timestampzone to text */ + 4178, /* convert timestamp to text */ + 4179, /* convert timestamp to text */ + 4180, /* convert int2 to varchar */ + 4181, /* convert int4 to varchar */ + 4182, /* convert int8 to varchar */ + 4183, /* convert numeric to varchar */ + 4184, /* convert float4 to varchar */ + 4185, /* convert float8 to varchar */ + 4186, /* convert varchar to timestamp */ + 4187, /* convert bpchar to timestamp */ + 4188, /* convert text to int1 */ + 4189, /* convert text to int2 */ + 4190, /* convert text to int4 */ + 4191, /* convert text to int8 */ + 4192, /* convert text to float4 */ + 4193, /* convert text to float8 */ + 4194, /* convert text to numeric */ + 4195, /* convert bpchar to int8 */ + 4196, /* convert bpchar to float4 */ + 4197, /* convert bpchar to float8 */ + 4198, /* convert varchar to float4 */ + 4199, /* convert varchar to float8 */ + 5523, /* convert int1 to int2 */ + 5524, /* convert int2 to int1 */ + 5525, /* convert int1 to int4 */ + 5526, /* convert int4 to int1 */ + 5527, /* convert int1 to int8 */ + 5528, /* convert int8 to int1 */ + 5529, /* convert int1 to float4 */ + 5530, /* convert float4 to int1 */ + 5531, /* convert int1 to float8 */ + 5532, /* convert float8 to int1 */ + 5533, /* convert int1 to bool */ + 5534 /* convert bool to int1 */ +}; +#endif /* SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ */ diff -uprN postgresql-hll-2.14_old/include/optimizer/autoanalyzer.h postgresql-hll-2.14/include/optimizer/autoanalyzer.h --- postgresql-hll-2.14_old/include/optimizer/autoanalyzer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/autoanalyzer.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * autoanalyzer.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/autoanalyzer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef AUTOANALYZER_H +#define AUTOANALYZER_H + +#include "libpq/libpq-fe.h" +#include "lib/stringinfo.h" +#include "utils/relcache.h" + +/* Auto-Analyze */ +class AutoAnaProcess : public BaseObject { +public: + // constructor + AutoAnaProcess(Relation rel); + + ~AutoAnaProcess(); + + static bool runAutoAnalyze(Relation rel); + + static void cancelAutoAnalyze(); + +protected: + PGconn* m_pgconn; + + PGresult* m_res; + + List* m_query; + +private: + static bool check_conditions(Relation rel); + + bool run(); + + bool executeSQLCommand(char* cmd); + + static void tear_down(); +}; + +#endif /* AUTOANALYZER_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/bucketinfo.h postgresql-hll-2.14/include/optimizer/bucketinfo.h --- postgresql-hll-2.14_old/include/optimizer/bucketinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/bucketinfo.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * bucketinfo.h + * the basic node defination for hashbucket + * we keep BucketInfo in a seperate file + * + * + * IDENTIFICATION + * src/include/optimizer/bucketinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUCKETINFO_H +#define BUCKETINFO_H + +#include "nodes/nodes.h" +#include "nodes/primnodes.h" +#include "nodes/value.h" +#include "lib/stringinfo.h" + +typedef struct BucketInfo { + NodeTag type; + List* buckets; /* bukect ids to be scanned, NULL means all buckets */ +} BucketInfo; + +extern char* bucketInfoToString(BucketInfo* bucket_info); +extern bool hasValidBuckets(RangeVar* r); +extern List* RangeVarGetBucketList(RangeVar* rangeVar); +#endif diff -uprN postgresql-hll-2.14_old/include/optimizer/bucketpruning.h postgresql-hll-2.14/include/optimizer/bucketpruning.h --- postgresql-hll-2.14_old/include/optimizer/bucketpruning.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/bucketpruning.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,40 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * bucketpruning.h + * functions related to bucketpruning + * + * IDENTIFICATION + * src/include/optimizer/bucketpruning.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUCKETPRUNING_H +#define BUCKETPRUNING_H + +#include "nodes/relation.h" +#include "nodes/parsenodes.h" +#include "nodes/execnodes.h" +#include "utils/plancache.h" +#include "utils/globalplancache.h" + + +extern void set_rel_bucketinfo(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); +extern double getBucketPruningRatio(BucketInfo* bucket_info); +extern void setPlanBucketId(Plan* plan, ParamListInfo params, MemoryContext cxt); +extern void setCachedPlanBucketId(CachedPlan *cplan, ParamListInfo boundParams); +extern BucketInfo* CalBucketInfo(ScanState* state); + +#endif diff -uprN postgresql-hll-2.14_old/include/optimizer/clauses.h postgresql-hll-2.14/include/optimizer/clauses.h --- postgresql-hll-2.14_old/include/optimizer/clauses.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/clauses.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,130 @@ +/* ------------------------------------------------------------------------- + * + * clauses.h + * prototypes for clauses.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/clauses.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CLAUSES_H +#define CLAUSES_H + +#include "nodes/relation.h" +#include "parser/parse_node.h" +#include "nodes/nodeFuncs.h" + +#define is_opclause(clause) ((clause) != NULL && IsA(clause, OpExpr)) +#define is_funcclause(clause) ((clause) != NULL && IsA(clause, FuncExpr)) + +typedef struct { + int numWindowFuncs; /* total number of WindowFuncs found */ + Index maxWinRef; /* windowFuncs[] is indexed 0 .. maxWinRef */ + List** windowFuncs; /* lists of WindowFuncs for each winref */ + List* activeWindows; +} WindowLists; + +typedef enum { UNIQUE_CONSTRAINT, NOT_NULL_CONSTRAINT } constraintType; + +extern Expr* make_opclause( + Oid opno, Oid opresulttype, bool opretset, Expr* leftop, Expr* rightop, Oid opcollid, Oid inputcollid); +extern Node* get_leftop(const Expr* clause); +extern Node* get_rightop(const Expr* clause); + +extern bool not_clause(Node* clause); +extern Expr* make_notclause(Expr* notclause); +extern Expr* get_notclausearg(Expr* notclause); + +extern bool or_clause(Node* clause); +extern Expr* make_orclause(List* orclauses); + +extern bool and_clause(Node* clause); +extern Expr* make_andclause(List* andclauses); +extern Node* make_and_qual(Node* qual1, Node* qual2); +extern Expr* make_ands_explicit(List* andclauses); +extern List* make_ands_implicit(Expr* clause); + +extern bool contain_agg_clause(Node* clause); +extern bool contain_specified_agg_clause(Node* clause); +extern void count_agg_clauses(PlannerInfo* root, Node* clause, AggClauseCosts* costs); + +extern bool contain_window_function(Node* clause); +extern void free_windowFunc_lists(WindowLists* lists); +extern WindowLists* make_windows_lists(Index maxWinRef); +extern void find_window_functions(Node* clause, WindowLists* lists); + +extern double expression_returns_set_rows(Node* clause); +extern double tlist_returns_set_rows(List* tlist); + +extern bool contain_subplans(Node* clause); + +extern bool contain_mutable_functions(Node* clause); +extern bool contain_volatile_functions(Node* clause); +extern bool contain_specified_function(Node* clause, Oid funcid); +extern bool contain_nonstrict_functions(Node* clause, bool check_agg = false); +extern bool contain_leaky_functions(Node* clause); +extern bool exec_simple_check_mutable_function(Node* clause); + +extern Relids find_nonnullable_rels(Node* clause); +extern List* find_nonnullable_vars(Node* clause); +extern List* find_forced_null_vars(Node* clause); +extern Var* find_forced_null_var(Node* clause); + +extern bool is_pseudo_constant_clause(Node* clause); +extern bool is_pseudo_constant_clause_relids(Node* clause, Relids relids); + +extern int NumRelids(Node* clause); + +extern void CommuteOpExpr(OpExpr* clause); +extern void CommuteRowCompareExpr(RowCompareExpr* clause); + +extern Node* strip_implicit_coercions(Node* node); + +extern Node* eval_const_expressions(PlannerInfo* root, Node* node); + +extern Node* eval_const_expressions_params(PlannerInfo* root, Node* node, ParamListInfo boundParams); + +extern Node* estimate_expression_value(PlannerInfo* root, Node* node, EState* estate = NULL); + +extern Query* inline_set_returning_function(PlannerInfo* root, RangeTblEntry* rte); +extern Query* search_cte_by_parse_tree(Query* parse, RangeTblEntry* rte, bool under_recursive_tree); +extern bool filter_cstore_clause(PlannerInfo* root, Expr* clause); +/* evaluate_expr used to be a static function */ +extern Expr* evaluate_expr(Expr* expr, Oid result_type, int32 result_typmod, Oid result_collation); +extern bool contain_var_unsubstitutable_functions(Node* clause); +extern void distribute_qual_to_rels(PlannerInfo* root, Node* clause, bool is_deduced, bool below_outer_join, + JoinType jointype, Index security_level, Relids qualscope, Relids ojscope, Relids outerjoin_nonnullable, + Relids deduced_nullable_relids, List **postponed_qual_list); +extern void check_plan_correlation(PlannerInfo* root, Node* expr); +extern bool findConstraintByVar(Var* var, Oid relid, constraintType conType); +extern bool is_var_node(Node* node); +extern Node* substitute_var(Node* expr, List* planTargetList); +extern bool treat_as_join_clause(Node* clause, RestrictInfo* rinfo, int varRelid, SpecialJoinInfo* sjinfo); +extern List* extract_function_outarguments(Oid funcid, List* parameters, List* funcname); +extern bool need_adjust_agg_inner_func_type(Aggref* aggref); + +#ifndef ENABLE_MULTIPLE_NODES +extern bool contain_rownum_walker(Node *node, void *context); + +static inline bool contain_rownum_expr(Node *node) +{ + return contain_rownum_walker(node, NULL); +} + +/* Check if it includes Rownum */ +static inline void ExcludeRownumExpr(ParseState* pstate, Node* expr) +{ + if (contain_rownum_expr(expr)) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("specified ROWNUM is not allowed here."), + parser_errposition(pstate, exprLocation(expr)))); +} + +extern List* get_quals_lists(Node *jtnode); +#endif +#endif /* CLAUSES_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/cost.h postgresql-hll-2.14/include/optimizer/cost.h --- postgresql-hll-2.14_old/include/optimizer/cost.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/cost.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,320 @@ +/* ------------------------------------------------------------------------- + * + * cost.h + * prototypes for costsize.c and clausesel.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/cost.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COST_H +#define COST_H + +#include "executor/nodeHash.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/planmain.h" +#include "utils/aset.h" +#include "utils/extended_statistics.h" + +#define STREAM_COST_THRESHOLD 100000.0 + +/* + * For columnar scan, the cpu cost is less than seq scan, so + * we are definition that the cost of scanning one tuple is 1/10 times. + */ +#define COL_TUPLE_COST_MULTIPLIER 10 + +/* + * Estimate the overhead per hashtable entry at 64 bytes (same as in + * planner.c). + */ +#define HASH_ENTRY_OVERHEAD 64 + +/* defaults for costsize.c's Cost parameters */ +/* NB: cost-estimation code should use the variables, not these constants! */ +/* If you change these, update backend/utils/misc/postgresql.sample.conf */ +#define DEFAULT_SEQ_PAGE_COST 1.0 +#define DEFAULT_RANDOM_PAGE_COST 4.0 +#define DEFAULT_CPU_TUPLE_COST 0.01 +#define DEFAULT_CPU_INDEX_TUPLE_COST 0.005 +#define DEFAULT_CPU_OPERATOR_COST 0.0025 +#define DEFAULT_CPU_HASH_COST 0.02 +#define DEFAULT_SEND_KDATA_COST 2.0 +#define DEFAULT_RECEIVE_KDATA_COST 2.0 +#define DEFAULT_ALLOCATE_MEM_COST 0.0 +#define LOCAL_SEND_KDATA_COST 1.3 /* The send cost for local stream */ +#define LOCAL_RECEIVE_KDATA_COST 1.3 /* The receive cost for local stream */ +#define DEFAULT_SMP_THREAD_COST 1000 /* The cost for add a new thread */ +#define DEFAULT_STREAM_MULTIPLE 1.0 + +#define DEFAULT_EFFECTIVE_CACHE_SIZE 16384 /* measured in pages */ + +#define COST_ALTERNATIVE_NEQ 0x00000001 +#define COST_ALTERNATIVE_CONJUNCT 0x00000002 +#define COST_ALTERNATIVE_MERGESORT 0x00000004 /* disable mergesort option */ +#define COST_ALTERNATIVE_EQUALRANGE_NOTINMCV 0x00000008 /* filter has equal range but the const not in mcv */ + +#define SIZE_COL_VALUE 16 + +#define TUPLE_OVERHEAD(colorsort) ((colorsort) ? 24 : 8) + +typedef enum { + CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */ + CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */ + CONSTRAINT_EXCLUSION_PARTITION /* apply c_e to otherrels only */ +} ConstraintExclusionType; + +extern void init_plan_cost(Plan* plan); +extern void cost_insert(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); +extern void cost_delete(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); +extern void cost_update(Path* path, bool vectorized, Cost input_cost, double tuples, int width, Cost comparison_cost, + int modify_mem, int dop, Oid resultRelOid, bool isDfsStore, OpMemInfo* mem_info); + +extern double clamp_row_est(double nrows); +extern double index_pages_fetched( + double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo* root, bool ispartitionedindex); +extern void cost_seqscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_samplescan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_cstorescan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_dfsscan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +#ifdef ENABLE_MULTIPLE_NODES +extern void cost_tsstorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel); +#endif /* ENABLE_MULTIPLE_NODES */ +extern void cost_index(IndexPath* path, PlannerInfo* root, double loop_count); +extern void cost_bitmap_heap_scan( + Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info, Path* bitmapqual, double loop_count); +extern void cost_bitmap_and_node(BitmapAndPath* path, PlannerInfo* root); +extern void cost_bitmap_or_node(BitmapOrPath* path, PlannerInfo* root); +extern void cost_bitmap_tree_node(Path* path, Cost* cost, Selectivity* selec); +extern void cost_tidscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, List* tidquals); +extern void cost_subqueryscan(Path* path, PlannerInfo* root, RelOptInfo* baserel, ParamPathInfo* param_info); +extern void cost_functionscan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_valuesscan(Path* path, PlannerInfo* root, RelOptInfo* baserels); +#ifdef PGXC +extern void cost_remotequery(RemoteQueryPath* rqpath, PlannerInfo* root, RelOptInfo* rel); +#endif +extern void cost_ctescan(Path* path, PlannerInfo* root, RelOptInfo* baserel); +extern void cost_recursive_union(Plan* runion, Plan* nrterm, Plan* rterm); +extern void cost_sort(Path* path, List* pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, + int sort_mem, double limit_tuples, bool col_store, int dop = 1, OpMemInfo* mem_info = NULL, + bool index_sort = false); +extern void cost_merge_append(Path* path, PlannerInfo* root, List* pathkeys, int n_streams, Cost input_startup_cost, + Cost input_total_cost, double tuples); +extern void cost_material(Path* path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width); +extern void cost_agg(Path* path, PlannerInfo* root, AggStrategy aggstrategy, const AggClauseCosts* aggcosts, + int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples, + int input_width = 0, int hash_entry_size = 0, int dop = 1, OpMemInfo* mem_info = NULL); +extern void cost_windowagg(Path* path, PlannerInfo* root, List* windowFuncs, int numPartCols, int numOrderCols, + Cost input_startup_cost, Cost input_total_cost, double input_tuples); +extern void cost_group(Path* path, PlannerInfo* root, int numGroupCols, double numGroups, Cost input_startup_cost, + Cost input_total_cost, double input_tuples); +extern void cost_limit(Plan* plan, Plan* lefttree, int64 offset_est, int64 count_est); +extern void initial_cost_nestloop(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, Path* outer_path, + Path* inner_path, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, int dop); +extern void final_cost_nestloop(PlannerInfo* root, NestPath* path, JoinCostWorkspace* workspace, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, bool hasalternative, int dop); +extern void initial_cost_mergejoin(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, + List* mergeclauses, Path* outer_path, Path* inner_path, List* outersortkeys, List* innersortkeys, + SpecialJoinInfo* sjinfo); +extern void final_cost_mergejoin( + PlannerInfo* root, MergePath* path, JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, bool hasalternative); +extern void initial_cost_hashjoin(PlannerInfo* root, JoinCostWorkspace* workspace, JoinType jointype, List* hashclauses, + Path* outer_path, Path* inner_path, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, int dop); +extern void final_cost_hashjoin(PlannerInfo* root, HashPath* path, JoinCostWorkspace* workspace, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, bool hasalternative, int dop); +extern void cost_rescan(PlannerInfo* root, Path* path, Cost* rescan_startup_cost, /* output parameters */ + Cost* rescan_total_cost, OpMemInfo* mem_info); +extern Cost cost_rescan_material(double rows, int width, OpMemInfo* mem_info, bool vectorized, int dop); +extern void cost_subplan(PlannerInfo* root, SubPlan* subplan, Plan* plan); +extern void cost_qual_eval(QualCost* cost, List* quals, PlannerInfo* root); +extern void cost_qual_eval_node(QualCost* cost, Node* qual, PlannerInfo* root); +extern void compute_semi_anti_join_factors(PlannerInfo* root, RelOptInfo* outerrel, RelOptInfo* innerrel, + JoinType jointype, SpecialJoinInfo* sjinfo, List* restrictlist, SemiAntiJoinFactors* semifactors); +extern void set_baserel_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern double get_parameterized_baserel_size(PlannerInfo* root, RelOptInfo* rel, List* param_clauses); +extern double get_parameterized_joinrel_size(PlannerInfo* root, RelOptInfo* rel, double outer_rows, double inner_rows, + SpecialJoinInfo* sjinfo, List* restrict_clauses); +extern void set_joinrel_size_estimates(PlannerInfo* root, RelOptInfo* rel, RelOptInfo* outer_rel, RelOptInfo* inner_rel, + SpecialJoinInfo* sjinfo, List* restrictlist); +extern void set_joinpath_multiple_for_EC(PlannerInfo* root, Path* path, Path* outer_path, Path* inner_path); +extern void set_subquery_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_function_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_values_size_estimates(PlannerInfo* root, RelOptInfo* rel); +extern void set_cte_size_estimates(PlannerInfo* root, RelOptInfo* rel, Plan* cteplan); +extern void set_foreign_size_estimates(PlannerInfo* root, RelOptInfo* rel); + +/* + * prototypes for clausesel.c + * routines to compute clause selectivities + */ +extern Selectivity clauselist_selectivity(PlannerInfo* root, List* clauses, int varRelid, JoinType jointype, + SpecialJoinInfo* sjinfo, bool varratio_cached = true); +extern Selectivity clause_selectivity(PlannerInfo* root, Node* clause, int varRelid, JoinType jointype, + SpecialJoinInfo* sjinfo, bool varratio_cached = true, bool check_scalarop = false); + +extern void set_rel_width(PlannerInfo* root, RelOptInfo* rel); +extern void restore_hashjoin_cost(Path* path); +extern void finalize_dml_cost(ModifyTable* plan); +extern void copy_mem_info(OpMemInfo* dest, OpMemInfo* src); +extern int columnar_get_col_width(int typid, int width, bool aligned = false); +extern int get_path_actual_total_width(Path* path, bool vectorized, OpType type, int newcol = 0); + +extern void bernoulli_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern void system_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern void hybrid_samplescangetsamplesize(PlannerInfo* root, RelOptInfo* baserel, List* paramexprs); +extern double cost_page_size(double tuples, int width); +extern bool can_use_possion(VariableStatData* vardata, SpecialJoinInfo* sjinfo, double* ratio); +extern void set_equal_varratio(VariableStatData* vardata, Relids other_relids, double ratio, SpecialJoinInfo* sjinfo); +extern double estimate_hash_num_distinct(PlannerInfo* root, List* hashkey, Path* inner_path, VariableStatData* vardata, + double local_ndistinct, double global_ndistinct, bool* usesinglestats); +extern RelOptInfo* find_join_input_rel(PlannerInfo* root, Relids relids); +extern double compute_sort_disk_cost(double input_bytes, double sort_mem_bytes); + +extern double approx_tuple_count(PlannerInfo* root, JoinPath* path, List* quals); +extern void set_rel_path_rows(Path* path, RelOptInfo* rel, ParamPathInfo* param_info); +extern Selectivity compute_bucket_size(PlannerInfo* root, RestrictInfo* restrictinfo, double virtualbuckets, + Path* inner_path, bool left, SpecialJoinInfo* sjinfo, double* ndistinct); +extern double page_size(double tuples, int width); +extern bool has_complicate_hashkey(List* hashclauses, Relids inner_relids); +extern bool has_indexed_join_quals(NestPath* joinpath); +extern double relation_byte_size( + double tuples, int width, bool vectorized, bool aligned = true, bool issort = true, bool indexsort = false); +extern MergeScanSelCache* cached_scansel(PlannerInfo* root, RestrictInfo* rinfo, PathKey* pathkey); + +extern double apply_random_page_cost_mod(double rand_page_cost, double seq_page_cost, int num_of_page); + +#define ES_DEBUG_LEVEL DEBUG2 /* debug level for extended statistic in optimizor */ + +#define RANDOM_PAGE_COST(use_mod, rand_cost, seq_cost, pages) (use_mod ? \ + apply_random_page_cost_mod(rand_cost, seq_cost, pages) : rand_cost) + +/* Logistic function */ +#define LOGISTIC_FUNC(variable, threshold, max_func_value, min_func_value, slope_factor) \ + ((variable > threshold && variable > 0) ? max_func_value : \ + 2 * (max_func_value - min_func_value) / (1 + exp(-1 * slope_factor * variable)) \ + - (max_func_value - 2 * min_func_value)) + +enum es_type { ES_EMPTY = 0, ES_EQSEL = 1, ES_EQJOINSEL, ES_GROUPBY, ES_COMPUTEBUCKETSIZE }; + +struct es_bucketsize { + Bitmapset* left_relids; + Bitmapset* right_relids; + RelOptInfo* left_rel; + RelOptInfo* right_rel; + float4 left_distinct; + float4 right_distinct; + float4 left_dndistinct; + float4 right_dndistinct; + double left_mcvfreq; + double right_mcvfreq; + List* left_hashkeys; + List* right_hashkeys; +}; + +/* + * calculate selectivity using extended statistics + */ +class ES_SELECTIVITY : public BaseObject { +public: + List* es_candidate_list; + List* unmatched_clause_group; + PlannerInfo* root; /* root from input */ + SpecialJoinInfo* sjinfo; /* sjinfo from input */ + List* origin_clauses; /* clauselist from input */ + JoinPath* path; /* path from input */ + List* bucketsize_list; /* list of bucket size */ + + /* a simplified structure from clause */ + struct es_clause_map { + int left_attnum; + int right_attnum; + Var* left_var; + Var* right_var; + }; + + struct es_candidate { + es_type tag; + Bitmapset* relids; + Bitmapset* left_relids; /* for eqsel and groupby clause, only use left_XXX */ + Bitmapset* right_relids; + Bitmapset* left_attnums; + Bitmapset* right_attnums; + float4 left_stadistinct; /* will be transfer to absolute value */ + float4 right_stadistinct; + double left_first_mcvfreq; /* frequency of fist mcv, to calculate skew or bucket size */ + double right_first_mcvfreq; + RelOptInfo* left_rel; + RelOptInfo* right_rel; + RangeTblEntry* left_rte; + RangeTblEntry* right_rte; + List* clause_group; + List* clause_map; + ExtendedStats* left_extended_stats; + ExtendedStats* right_extended_stats; /* read from pg_statistic, where distinct value + * could be negative. (-1 means unique.) + */ + List* pseudo_clause_list; /* save the clause build by equivalence class and + * the original clause. + */ + bool has_null_clause; /* if "is null" used in the clauses */ + }; + + ES_SELECTIVITY(); + virtual ~ES_SELECTIVITY(); + Selectivity calculate_selectivity(PlannerInfo* root_input, List* clauses_input, SpecialJoinInfo* sjinfo_input, + JoinType jointype, JoinPath* path_input, es_type action, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL); + void clear(); + void print_clauses(List* clauselist) const; + Selectivity estimate_hash_bucketsize( + es_bucketsize* es_bucket, double* distinctnum, bool left, Path* inner_path, double nbuckets); + +private: + bool add_attnum(RestrictInfo* clause, es_candidate* temp) const; + void add_clause_map(es_candidate* es, int left_attnum, int right_attnum, Node* left_arg, Node* right_arg) const; + bool build_es_candidate(RestrictInfo* clause, es_type type); + void build_pseudo_varinfo(es_candidate* es, STATS_EST_TYPE eType); + void cal_bucket_size(es_candidate* es, es_bucketsize* bucket) const; + Selectivity cal_eqsel(es_candidate* es); + Selectivity cal_eqjoinsel_inner(es_candidate* es); + Selectivity cal_eqjoinsel_semi(es_candidate* es, RelOptInfo* inner_rel, bool inner_on_left); + void clear_extended_stats(ExtendedStats* extended_stats) const; + void clear_extended_stats_list(List* stats_list) const; + ExtendedStats* copy_stats_ptr(ListCell* l) const; + void debug_print(); + double estimate_local_numdistinct(es_bucketsize* bucket, bool left, Path* path); + void group_clauselist(List* clauses); + void group_clauselist_groupby(List* varinfos); + void init_candidate(es_candidate* es) const; + void load_eqsel_clause(RestrictInfo* clause); + void load_eqjoinsel_clause(RestrictInfo* clause); + Bitmapset* make_attnums_by_clause_map(es_candidate* es, Bitmapset* attnums, bool left) const; + void match_extended_stats(es_candidate* es, List* stats_list, bool left); + bool match_pseudo_clauselist(List* clauses, es_candidate* es, List* origin_clause); + void modify_distinct_by_possion_model(es_candidate* es, bool left, SpecialJoinInfo* sjinfo) const; + char* print_expr(const Node* expr, const List* rtable) const; + void print_rel(RangeTblEntry* rel) const; + void print_relids(Bitmapset* relids, const char* str) const; + int read_attnum(Node* node) const; + void read_rel_rte(Node* node, RelOptInfo** rel, RangeTblEntry** rte); + void read_statistic(); + void read_statistic_eqjoinsel(es_candidate* es); + void read_statistic_eqsel(es_candidate* es); + void recheck_candidate_list(); + void remove_candidate(es_candidate* es); + void remove_attnum(es_candidate* es, int dump_attnum); + void replace_clause(Datum* old_clause, Datum* new_clause) const; + void report_no_stats(Oid relid_oid, Bitmapset* attnums) const; + void save_selectivity( + es_candidate* es, double left_join_ratio, double right_join_ratio, bool save_semi_join = false); + void set_up_attnum_order(es_candidate* es, int* attnum_order, bool left) const; + bool try_equivalence_class(es_candidate* es); +}; + +#endif /* COST_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/dataskew.h postgresql-hll-2.14/include/optimizer/dataskew.h --- postgresql-hll-2.14_old/include/optimizer/dataskew.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/dataskew.h 2020-12-12 17:06:43.345349303 +0800 @@ -0,0 +1,456 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataskew.h + * functions for dataskew solution in GaussDB + * + * + * IDENTIFICATION + * src/include/optimizer/dataskew.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATASKEW_H +#define DATASKEW_H +#include "nodes/execnodes.h" +#include "nodes/relation.h" +#include "optimizer/streamplan.h" +#include "parser/parse_hint.h" + +#define SKEW_RES_NONE 0x00 /* No skew optimization path if create. */ +#define SKEW_RES_STAT 0x01 /* Create skew optimization by statistic. */ +#define SKEW_RES_RULE 0x02 /* Create skew optimization by rule. */ +#define SKEW_RES_HINT 0x04 /* Create skew optimization by hint. */ + +typedef enum { + SKEW_NONE, /* Initial value. */ + SKEW_AGG, /* Skew info for agg. */ + SKEW_JOIN /* Skew info for join. */ +} SkewType; + +typedef enum { + PART_NONE = 0, /* Noe hybrid stream. */ + PART_REDISTRIBUTE_PART_BROADCAST, /* Do broadcast for some special data, and redistribute the rest. */ + PART_REDISTRIBUTE_PART_ROUNDROBIN, /* Do roundrobin for some special data, and redistribute the rest. */ + PART_REDISTRIBUTE_PART_LOCAL, /* Do local send for some special data, and redistribute the rest. */ + PART_LOCAL_PART_BROADCAST /* Do broadcast for some special data, and send the rest to local DN. */ +} SkewStreamType; + +typedef struct ColSkewInfo { + Node* var; /* Skew var of distribute keys. */ + Const* value; /* Skew value of this column. */ + double mcv_ratio; /* The proportion of data equal to the skew value. */ + double mcv_op_ratio; /* The proportion of data equal to skew value at the none skew side. */ + bool is_null; /* If this is null skew value. */ +} ColSkewInfo; + +typedef struct MultiColSkewInfo { + List* vars; /* Var list for distribute keys. */ + List* values; /* Skew value lists. */ + double mcv_ratio; /* The proportion of data equal to the skew value. */ + double mcv_op_ratio; /* The proportion of data equal to skew value at the none skew side. */ + bool is_null; /* If this is null skew value. */ +} MultiColSkewInfo; + +typedef struct QualSkewInfo { + NodeTag type; /* Node tag of qual skew info. */ + SkewStreamType skew_stream_type; /* Stream type for this skew qual. */ + List* skew_quals; /* Qual list for skew value. */ + QualCost qual_cost; /* Qual Cost for skew value. */ + double broadcast_ratio; /* Record ratio for broadcast data. */ +} QualSkewInfo; + +typedef struct QualSkewState { + SkewStreamType skew_stream_type; /* Stream type for this skew qual. */ + List* skew_quals_state; /* Qual State for skew value. */ +} QualSkewState; + +class SkewInfo : public BaseObject { +public: + SkewInfo(PlannerInfo* root); + + ~SkewInfo(); + + /* Get skew info. */ + uint32 getSkewInfo() const; + +protected: + /* Find skew value for single column distribute key. */ + List* findSingleColSkewValues(); + + /* Find skew value for single column distribute key from statistic info. */ + List* findSingleColSkewValuesFromStatistic(); + + /* Find skew value for single column distribute key from hint info. */ + List* findSingleColSkewValuesFromHint(); + + /* Find skew value for multi columns distribute key. */ + List* findMultiColSkewValues(); + + /* Find skew value for multi columns distribute key from statistic info. */ + List* findMultiColSkewValuesFromStatistic(); + + /* Find skew value for multi columns distribute key from single column statistic info. */ + List* findMultiColSkewValuesFromSingleStatistic(); + + /* Find skew value for multi columns distribute key from multi column statistic info. */ + List* findMultiColSkewValuesFromMultiStatistic(); + + /* Find skew value for multi columns distribute key from hint. */ + List* findMultiColSkewValuesFromHint(); + + /* Try to get single column statistic info. */ + List* getSingleColumnStatistics(Node* node); + + /* Try to get multi column statistic info. */ + List* getMultiColumnStatistics(); + + /* Find skew value from MCV. */ + List* findMcvValue(Node* var, int mcv_num, Datum* mcv_values, float4* mcv_ratios) const; + + /* Make const for skew value. */ + Const* makeConstForSkew(Var* var, Datum value) const; + + /* Create equal expression to identify skew values. */ + OpExpr* createEqualExprForSkew(Node* expr, Const* con) const; + + /* Get join clause from join path. */ + List* getJoinClause(Path* jpath) const; + + /* Find the column at may add null value in outer join. */ + List* findNullCols(List* target_list, List* subtarget_list, List* join_clauses) const; + + /* Check if the skew value can pass the restriction. */ + List* checkRestrict(List* baseSkewList); + + /* Check if the skew value of single column can pass the restriction. */ + List* checkRestrictForSingleCol(List* baseSkewList); + + /* Check if the skew value of multi column can pass the restriction. */ + List* checkRestrictForMultiCol(List* baseSkewList); + + /* Check if the current relation equal relation in skew hint. */ + bool checkSkewRelEqualHintRel(List* skewRelHint); + + /* Check if the distribute key is compitable to hint key. */ + bool checkEqualKey(Node* node, SkewColumnInfo* colHint) const; + + /* Check if the current column equal column in skew hint. */ + bool checkSkewColEqualHintCol(Node* node, SkewColumnInfo* colHint); + + /* Get skew value for hint. */ + bool getSkewKeys(List* skewHints, int* colLoc, int colLen); + + /* Get skew value for statistic. */ + bool getSkewKeys(); + + /* Get real skew value after type tranfer. */ + Const* getRealSkewValue(Node* diskey, Node* skewkey, Const* value); + + /* Process skew value for type tranfer. */ + void processSkewValue(List* skewlist); + + /* Check if the current distribute keys are simple var. */ + bool checkDistributekeys(List* distributekeys); + + /* Check if the restriction include this distribute keys. */ + bool isColInRestrict(List* distributekeys, Node* clause) const; + + /* Execute the equal expression actually. */ + bool ExecSkewvalExpr(Expr* expr, TupleTableSlot* slot); + + /* Check if the skew value can pass restriction. */ + bool canValuePassQual(List* varList, List* valueList, Expr* expr); + + /* Check if skew values can equal for single col. */ + bool isSingleColSkewValueEqual(ColSkewInfo* cs_inner, ColSkewInfo* cs_outer); + + /* Check if skew values can equal for multi col. */ + bool isMultiColSkewValueEqual(MultiColSkewInfo* mcs_inner, MultiColSkewInfo* mcs_outer); + + /* Updata the skewness for multi column distirbute keys. */ + void updateMultiColSkewness(StreamInfo* sinfo, List* skew_list) const; + + /* Generate a bitmap for rel in skew hint. */ + Relids generateRelidsFromRelList(List* skewRelHint); + + /* Compare two rels are the same one. */ + bool compareRelByRTE(RangeTblEntry* rte1, RangeTblEntry* rte2) const; + + /* Check if we need broadcast the non skew side. */ + bool needPartBroadcast(ColSkewInfo* csinfo) const; + + /* Check if we need broadcast the non skew side. */ + bool needPartBroadcast(MultiColSkewInfo* mcsinfo) const; + + /* Print detail info of skew oprimization info. */ + void printSkewOptimizeDetail(const char* msg); + +protected: + /* Planner info of current query level. */ + PlannerInfo* m_root; + + /* Reloptinfo of current path. */ + RelOptInfo* m_rel; + + /* Reloptinfo of subpath. */ + RelOptInfo* m_subrel; + + /* Distribute keys for this stream. */ + List* m_distributeKeys; + + /* Base skew keys. */ + List* m_skewKeys; + + /* Consumer parallel degree. */ + int m_dop; + + /* Skew type */ + SkewType m_skewType; + + /* Flag to identify if the distribute key include multi-columns. */ + bool m_isMultiCol; + + /* Original memory context. */ + MemoryContext m_oldContext; + + /* Memory context for skew optimization process. */ + MemoryContext m_context; + + /* Find skew info from statistic. */ + bool m_hasStatSkew; + + /* Find skew info from hint. */ + bool m_hasHintSkew; + + /* Find skew info from rule. */ + bool m_hasRuleSkew; +}; + +class JoinSkewInfo : public SkewInfo { +public: + JoinSkewInfo(PlannerInfo* root, RelOptInfo* rel, List* join_clause, JoinType join_type, JoinType save_join_type); + + ~JoinSkewInfo(); + + /* Find skew info for join. */ + uint32 findStreamSkewInfo(); + + /* Set stream info to find skew info for join. */ + void setStreamInfo(StreamInfo* inner_stream_info, StreamInfo* outer_stream_info, Distribution* distribution); + + /* Reset skew info for next use. */ + void resetSkewInfo(); + +private: + /* Find skew info from base relation. */ + void findBaseSkewInfo(); + + /* Find skew info caused by outer join. */ + void findNullSkewInfo(); + + /* Add qual cost. */ + void addQualSkewInfo(); + + /* Add the skew info to stream info. */ + void addToStreamInfo(); + + /* Find skew values for base rel. */ + void findBaseSkewValues(bool stream_outer); + + /* Find null skew from sub outer join. */ + void findSubNullSkew(bool is_outer); + + /* Add skew info to both stream side when we detect skew values. */ + void addSkewInfoBothSides(); + + /* Create quals for skew values. */ + List* createSkewQuals(bool is_stream_outer); + + /* Create quals of single distribute key. */ + List* createSingleColSkewQuals(bool is_stream_outer); + + /* Create quals of multi distribute keys. */ + List* createMultiColSkewQuals(bool is_stream_outer); + + /* Add skew info to the opposite side of skew side. */ + List* addSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Add skew info for single column to the opposite side of skew side. */ + List* addSingleColSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Add skew info for multi column to the opposite side of skew side. */ + List* addMultiColSkewInfoToOtherSide(bool is_outer_skew, List* other_keys); + + /* Choose suitable skew stream type for none skew side of join. */ + SkewStreamType chooseStreamForNoSkewSide(StreamInfo* sinfo) const; + + /* Delete duplicate skew values at both sides of join. */ + void deleteDuplicateSkewValue(); + + /* Delete duplicate skew values for single column at both sides of join. */ + void deleteDuplicateSingleColSkewValue(); + + /* Delete duplicate skew values for multi column at both sides of join. */ + void deleteDuplicateMultiColSkewValue(); + + /* Find out which side has more skew data or which is set by hint. */ + bool findMoreSkewSideForSingleCol(ColSkewInfo* cs1, ColSkewInfo* cs2) const; + + /* Find out which side has more skew data or which is set by hint. */ + bool findMoreSkewSideForMultiCol(MultiColSkewInfo* mcs1, MultiColSkewInfo* mcs2) const; + + /* Delete if we can not handle this skew situation. */ + void deleteUnoptimzeSkew(bool is_outer); + + /* Traverse the sub path to find null skew. */ + void traverseSubPath(Path* path); + + /* Check if current distribute keys are included in outer join's null column. */ + bool checkOuterJoinNulls(Path* jpath); + + /* Get all target list of join's input. */ + List* getSubTargetList(JoinPath* jpath) const; + + /* Add skew qual cost. */ + void addQualCost(bool is_outer); + + /* Check if this join may have skew problem. */ + bool checkSkewPossibility(bool is_outer); + + /* Check if we can optimize this skew problem. */ + bool checkSkewOptimization(bool is_outer); + + /* Check if we have create redundant skew optimization stream. */ + bool checkRedundant(bool is_outer); + + /* Travers sub path to find redundant skew stream. */ + bool checkPathRedundant(List* streamKeys, Path* path); + + /* Find key for the none skew side. */ + List* findOtherSidekeys(bool is_outer_skew); + + /* Find equal var list. */ + List* findEqualVarList(List* skewList, RelOptInfo* rel); + + /* Find equal vae. */ + Node* findEqualVar(Node* var, RelOptInfo* rel); + +private: + /* Join Type. */ + JoinType m_joinType; + + /* Save Join Type. */ + JoinType m_saveJoinType; + + /* Join clause. */ + List* m_joinClause; + + /* Target distribution. */ + Distribution* m_distribution; + + /* Stream info of join's inner side. */ + StreamInfo* m_innerStreamInfo; + + /* Stream info of join's outer side. */ + StreamInfo* m_outerStreamInfo; + + /* Skew info for join inner side. */ + List* m_innerSkewInfo; + + /* Skew Info for join outer side. */ + List* m_outerSkewInfo; + + /* Skew info. */ + List** m_skewInfo; + + /* If this is a outer stream. */ + bool m_isOuterStream; +}; + +class AggSkewInfo : public SkewInfo { +public: + AggSkewInfo(PlannerInfo* root, Plan* subplan, RelOptInfo* rel_info); + + ~AggSkewInfo(); + + /* Find stream skew info for agg. */ + void findStreamSkewInfo(); + + /* Set the distribute keys for agg. */ + void setDistributeKeys(List* distribute_keys); + +private: + /* Reset skew info for later use. */ + void resetSkewInfo(); + + /* Find skew info from hint. */ + void findHintSkewInfo(); + + /* Find skew info from statistic. */ + void findStatSkewInfo(); + + /* Find skew info from outer join' null side. */ + void findNullSkewInfo(); + + /* traverse subplan to find outer join's null skew. */ + void traverseSubPlan(Plan* subplan); + + /* Get the target list that may contain null column. */ + List* getSubTargetListByPlan(Plan* plan) const; + + /* Check if the distribute keys of agg are included in the null columns. */ + bool checkOuterJoinNullsForAgg(Plan* jplan) const; + +private: + /* Subplan of agg. */ + Plan* m_subplan; +}; + +class StreamSkew : public BaseObject { +public: + StreamSkew(List* ssinfo, bool isVec); + + ~StreamSkew(); + + /* Do initial work for skew stream. */ + void init(bool isVec); + + /* Choose suitable stream type for the skew stream. */ + int chooseStreamType(TupleTableSlot* tuple); + + /* Choose suitable stream type for the skew vecstream. */ + void chooseVecStreamType(VectorBatch* batch, int* skewStream); + +public: + /* The node id of local DN */ + int m_localNodeId; + +private: + /* Skew info list. */ + List* m_ssinfo; + + /* Skew qual state list. */ + List* m_skewQual; + + /* EState for skew quals. */ + EState* m_estate; + + /* Expr context for skew quals. */ + ExprContext* m_econtext; +}; + +extern List* find_skew_join_distribute_keys(Plan* plan); +#endif diff -uprN postgresql-hll-2.14_old/include/optimizer/dynsmp.h postgresql-hll-2.14/include/optimizer/dynsmp.h --- postgresql-hll-2.14_old/include/optimizer/dynsmp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/dynsmp.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,103 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dynsmp.h + * functions related to dynamic smp. + * + * + * IDENTIFICATION + * src/include/optimizer/dynsmp.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DYNSMP_H +#define DYNSMP_H + +#include "nodes/plannodes.h" + +extern void OptimizePlanDop(PlannedStmt* plannedStmt); +extern void InitDynamicSmp(); +extern bool IsDynamicSmpEnabled(); +extern void ChooseStartQueryDop(int hashTableCount); +extern void CheckQueryDopValue(); + +typedef struct GMNSDConext { + int max_non_spill_dop; /* the max dop we can use without spill to disk */ + bool already_spilled; /* if the plan is already spilled to disk ? */ + bool spill_if_use_higher_dop; /* if we +1 dop and the plan will spill to disk? */ + List* mem_info_list; /* the mem info we have to adjust later */ +} GMNSDConext; + +/* + * This struct holds the resource info needed by Dynamic Smp. + * For constant value, we only init once. + * For volatile value, we have to refreash from query to query. + */ +typedef struct DynamicSmpInfo { + /*-------CONSTANT----------------------------------- + * + * those variable does not change during one session + * + * -------------------------------------------------- + */ + /* how many dn installed in one physical machine */ + int num_of_dn_in_one_machine; + + /* how many cpu installed in one physical machine */ + int num_of_cpu_in_one_machine; + + /* how many cpu can be used for one dn */ + int num_of_cpu_for_one_dn; + + /*-------VOLATILE----------------------------------- + * + * those variable changes from query to query + * + * -------------------------------------------------- + */ + /* how many sql is running concurrently */ + int active_statement; + + /* the cpu util when planning this query */ + int cpu_util; + + int64 free_mem; + + int num_of_machine; +} DynamicSmpInfo; + +#define DYNMSP_ALREADY_SPILLED -1 +#define DYNMSP_SPILL_IF_USE_HIGHER_DOP -2 + +#define DS_LOG_PREFIX "[dynamic smp]" +#define UNKNOWN_NUM_OF_DN_IN_ONE_MACHINE -1 +#define DEFAULT_NUM_OF_DN_IN_ONE_MACHINE 2 +#define UNKNOWN_NUM_OF_CPU_IN_ONE_MACHINE -1 +#define DEFAULT_NUM_OF_CPU_IN_ONE_MACHINE 4 +#define UNKNOWN_NUM_OF_CPU_FOR_ONE_DN -1 +#define DEFAULT_NUM_OF_CPU_FOR_ONE_DN 2 +#define UNKNOWN_ACTIVE_STATEMENT -1 +#define DEFAULT_ACTIVE_STATEMENT 0 +#define UNKNOWN_CPU_UTIL -1 +#define DEFAULT_CPU_UTIL 40 +#define UNKNOWN_FREE_MEM -1 +#define DEFAULT_FREE_MEM 256 * 1024 /* in kb: 256MB * 1024 */ +#define UNKNOWN_NUM_OF_MACHINE -1 +#define DEFAULT_NUM_OF_MACHINE 1 +#define MAX_STREAM_MEM_RATIO 0.25 +#define MIN_STREAM_MEM_RATIO 0.05 +#define MIN_OPTIMAL_DOP 2 + +#endif diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_copy.h postgresql-hll-2.14/include/optimizer/geqo_copy.h --- postgresql-hll-2.14_old/include/optimizer/geqo_copy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_copy.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_copy.h + * prototypes for copy functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_copy.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_COPY_H +#define GEQO_COPY_H + +#include "optimizer/geqo.h" + +extern void geqo_copy(PlannerInfo* root, Chromosome* chromo1, Chromosome* chromo2, int string_length); + +#endif /* GEQO_COPY_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_gene.h postgresql-hll-2.14/include/optimizer/geqo_gene.h --- postgresql-hll-2.14_old/include/optimizer/geqo_gene.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_gene.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,42 @@ +/* ------------------------------------------------------------------------- + * + * geqo_gene.h + * genome representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_gene.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_GENE_H +#define GEQO_GENE_H + +#include "nodes/nodes.h" + +/* we presume that int instead of Relid + is o.k. for Gene; so don't change it! */ +typedef int Gene; + +typedef struct Chromosome { + Gene* string; + Cost worth; +} Chromosome; + +typedef struct Pool { + Chromosome* data; + int size; + int string_length; +} Pool; + +#endif /* GEQO_GENE_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo.h postgresql-hll-2.14/include/optimizer/geqo.h --- postgresql-hll-2.14_old/include/optimizer/geqo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * geqo.h + * prototypes for various files in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_H +#define GEQO_H + +#include "nodes/relation.h" +#include "optimizer/geqo_gene.h" + +/* GEQO debug flag */ +/* recombination mechanism */ +#define ERX + +/* + * Configuration options + * + * If you change these, update backend/utils/misc/postgresql.conf.sample + */ +#define DEFAULT_GEQO_EFFORT 5 +#define MIN_GEQO_EFFORT 1 +#define MAX_GEQO_EFFORT 10 + +#define DEFAULT_GEQO_SELECTION_BIAS 2.0 +#define MIN_GEQO_SELECTION_BIAS 1.5 +#define MAX_GEQO_SELECTION_BIAS 2.0 + +/* + * Private state for a GEQO run --- accessible via root->join_search_private + */ +typedef struct { + List* initial_rels; /* the base relations we are joining */ + unsigned short random_state[3]; /* state for pg_erand48() */ +} GeqoPrivateData; + +/* routines in geqo_main.c */ +extern RelOptInfo* geqo(PlannerInfo* root, int number_of_rels, List* initial_rels); + +/* routines in geqo_eval.c */ +extern Cost geqo_eval(PlannerInfo* root, Gene* tour, int num_gene); +extern RelOptInfo* gimme_tree(PlannerInfo* root, Gene* tour, int num_gene); + +#endif /* GEQO_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_misc.h postgresql-hll-2.14/include/optimizer/geqo_misc.h --- postgresql-hll-2.14_old/include/optimizer/geqo_misc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_misc.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * geqo_misc.h + * prototypes for printout routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_misc.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MISC_H +#define GEQO_MISC_H + +#include "optimizer/geqo_recombination.h" + +#ifdef GEQO_DEBUG + +extern void print_pool(FILE* fp, Pool* pool, int start, int stop); +extern void print_gen(FILE* fp, Pool* pool, int generation); +extern void print_edge_table(FILE* fp, Edge* edge_table, int num_gene); +#endif /* GEQO_DEBUG */ + +#endif /* GEQO_MISC_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_mutation.h postgresql-hll-2.14/include/optimizer/geqo_mutation.h --- postgresql-hll-2.14_old/include/optimizer/geqo_mutation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_mutation.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_mutation.h + * prototypes for mutation functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_mutation.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MUTATION_H +#define GEQO_MUTATION_H + +#include "optimizer/geqo.h" + +extern void geqo_mutation(PlannerInfo* root, Gene* tour, int num_gene); + +#endif /* GEQO_MUTATION_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_pool.h postgresql-hll-2.14/include/optimizer/geqo_pool.h --- postgresql-hll-2.14_old/include/optimizer/geqo_pool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_pool.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * geqo_pool.h + * pool representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_pool.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_POOL_H +#define GEQO_POOL_H + +#include "optimizer/geqo.h" + +extern Pool* alloc_pool(PlannerInfo* root, int pool_size, int string_length); +extern void free_pool(PlannerInfo* root, Pool* pool); + +extern void random_init_pool(PlannerInfo* root, Pool* pool); +extern Chromosome* alloc_chromo(PlannerInfo* root, int string_length); +extern void free_chromo(PlannerInfo* root, Chromosome* chromo); + +extern void spread_chromo(PlannerInfo* root, Chromosome* chromo, Pool* pool); + +extern void sort_pool(PlannerInfo* root, Pool* pool); + +#endif /* GEQO_POOL_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_random.h postgresql-hll-2.14/include/optimizer/geqo_random.h --- postgresql-hll-2.14_old/include/optimizer/geqo_random.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_random.h 2020-12-12 17:06:43.346349316 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * geqo_random.h + * random number generator + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_random.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RANDOM_H +#define GEQO_RANDOM_H + +#include + +#include "optimizer/geqo.h" + +extern void geqo_set_seed(PlannerInfo* root, double seed); + +/* geqo_rand returns a random float value between 0 and 1 inclusive */ +extern double geqo_rand(PlannerInfo* root); + +/* geqo_randint returns integer value between lower and upper inclusive */ +#define geqo_randint(root, upper, lower) ((int)floor(geqo_rand(root) * (((upper) - (lower)) + 0.999999)) + (lower)) + +#endif /* GEQO_RANDOM_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_recombination.h postgresql-hll-2.14/include/optimizer/geqo_recombination.h --- postgresql-hll-2.14_old/include/optimizer/geqo_recombination.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_recombination.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,73 @@ +/* ------------------------------------------------------------------------- + * + * geqo_recombination.h + * prototypes for recombination in the genetic query optimizer + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_recombination.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RECOMBINATION_H +#define GEQO_RECOMBINATION_H + +#include "optimizer/geqo.h" + +extern void init_tour(PlannerInfo* root, Gene* tour, int num_gene); + +/* edge recombination crossover [ERX] */ +typedef struct Edge { + Gene edge_list[4]; /* list of edges */ + int total_edges; + int unused_edges; +} Edge; + +extern Edge* alloc_edge_table(PlannerInfo* root, int num_gene); +extern void free_edge_table(PlannerInfo* root, Edge* edge_table); + +extern float gimme_edge_table(PlannerInfo* root, Gene* tour1, Gene* tour2, int num_gene, Edge* edge_table); + +extern int gimme_tour(PlannerInfo* root, Edge* edge_table, Gene* new_gene, int num_gene); + +/* partially matched crossover [PMX] */ +#define DAD 1 /* indicator for gene from dad */ +#define MOM 0 /* indicator for gene from mom */ + +extern void pmx(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene); + +typedef struct City { + int tour2_position; + int tour1_position; + int used; + int select_list; +} City; + +extern City* alloc_city_table(PlannerInfo* root, int num_gene); +extern void free_city_table(PlannerInfo* root, City* city_table); + +/* cycle crossover [CX] */ +extern int cx(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene, City* city_table); + +/* position crossover [PX] */ +extern void px(PlannerInfo* root, Gene* tour1, Gene* tour2, Gene* offspring, int num_gene, City* city_table); + +/* order crossover [OX1] according to Davis */ +extern void ox1(PlannerInfo* root, Gene* mom, Gene* dad, Gene* offspring, int num_gene, City* city_table); + +/* order crossover [OX2] according to Syswerda */ +extern void ox2(PlannerInfo* root, Gene* mom, Gene* dad, Gene* offspring, int num_gene, City* city_table); + +#endif /* GEQO_RECOMBINATION_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/geqo_selection.h postgresql-hll-2.14/include/optimizer/geqo_selection.h --- postgresql-hll-2.14_old/include/optimizer/geqo_selection.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/geqo_selection.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- + * + * geqo_selection.h + * prototypes for selection routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_selection.h + * + * ------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_SELECTION_H +#define GEQO_SELECTION_H + +#include "optimizer/geqo.h" + +extern void geqo_selection(PlannerInfo* root, Chromosome* momma, Chromosome* daddy, Pool* pool, double bias); + +#endif /* GEQO_SELECTION_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/gtmfree.h postgresql-hll-2.14/include/optimizer/gtmfree.h --- postgresql-hll-2.14_old/include/optimizer/gtmfree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/gtmfree.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,10 @@ +#ifndef GTMFREE_H +#define GTMFREE_H + +typedef enum { + PERFECT_SHARDING_TYPE, + NOT_PERFECT_SHARDING_TYPE +} application_type_param; + +#endif + diff -uprN postgresql-hll-2.14_old/include/optimizer/joininfo.h postgresql-hll-2.14/include/optimizer/joininfo.h --- postgresql-hll-2.14_old/include/optimizer/joininfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/joininfo.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * joininfo.h + * prototypes for joininfo.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/joininfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef JOININFO_H +#define JOININFO_H + +#include "nodes/relation.h" + +extern bool have_relevant_joinclause(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); + +extern void add_join_clause_to_rels(PlannerInfo* root, RestrictInfo* restrictinfo, Relids join_relids); +extern void remove_join_clause_from_rels(PlannerInfo* root, RestrictInfo* restrictinfo, Relids join_relids); + +#endif /* JOININFO_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/nodegroups.h postgresql-hll-2.14/include/optimizer/nodegroups.h --- postgresql-hll-2.14_old/include/optimizer/nodegroups.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/nodegroups.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,295 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * nodegroups.h + * Variables and functions used in multiple node group optimizer + * + * + * IDENTIFICATION + * src/include/optimizer/nodegroups.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEGROUPS_H +#define NODEGROUPS_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "nodes/bitmapset.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "nodes/pg_list.h" +#include "nodes/relation.h" +#include "pgxc/locator.h" +#include "optimizer/streamplan.h" +/* + * Computing node group options + */ +#define CNG_OPTION_OPTIMAL "optimal" +#define CNG_OPTION_QUERY "query" +#define CNG_OPTION_INSTALLATION "installation" + +/* + * virtual cluster node group options + */ +#define VNG_OPTION_ELASTIC_GROUP "elastic_group" + +/* + * Forbidden cost for agg and join unique + */ +#define NG_FORBIDDEN_COST -100.0 + +typedef struct NGroupInfo +{ + Oid oid; + Bitmapset* bms_nodeids; +}NGroupInfo; + +/* + * Modes for computing node group + * (1) optimal : the optimal mode in compute permission scale + * (2) query : the cost based mode in query scale + * (3) expect : the cost based mode with a expect node group + * (4) force : forced mode which compute in a specific node group + */ +typedef enum ComputingNodeGroupMode { + CNG_MODE_COSTBASED_OPTIMAL, + CNG_MODE_COSTBASED_QUERY, + CNG_MODE_COSTBASED_EXPECT, + CNG_MODE_FORCE +} ComputingNodeGroupMode; + +/*-------------------------------------------------------------------------*/ +/* Variables */ +/*-------------------------------------------------------------------------*/ + +/*-------------------------------------------------------------------------*/ +/* Public functions */ +/* including: */ +/* (1) General functions */ +/* (2) Get general node groups */ +/* (3) Get distribution information of a node group */ +/* (4) Get distribution information of a base relation */ +/* (5) Get distribution information of a path or a plan */ +/* (6) Distribution data structure management */ +/* (7) Convert functions */ +/* (8) Heuristic methods */ +/* (9) Cost based algorithms */ +/* (10) Distribution management for specific operators */ +/* (11) Do shuffle between node groups if needed */ +/* (12) Compare functions, judge functions */ +/* (13) Other functions */ +/*-------------------------------------------------------------------------*/ + +/* ---------- + * General functions + * ---------- + */ +extern void ng_init_nodegroup_optimizer(Query* query); +extern void ng_backup_nodegroup_options(bool* p_is_multiple_nodegroup_scenario, + int* p_different_nodegroup_count, Distribution** p_in_redistribution_group_distribution, + Distribution** p_compute_permission_group_distribution, Distribution** p_query_union_set_group_distribution, + Distribution** p_single_node_distribution); +extern void ng_restore_nodegroup_options(bool p_is_multiple_nodegroup_scenario, + int p_different_nodegroup_count, Distribution* p_in_redistribution_group_distribution, + Distribution* p_compute_permission_group_distribution, Distribution* p_query_union_set_group_distribution, + Distribution* p_single_node_distribution); +extern ComputingNodeGroupMode ng_get_computing_nodegroup_mode(); + +/* ---------- + * Get general node groups + * ---------- + */ +/* installation group */ +extern char* ng_get_installation_group_name(); +extern Oid ng_get_installation_group_oid(); +extern Bitmapset* ng_get_installation_group_nodeids(); +extern Distribution* ng_get_installation_group_distribution(); +extern ExecNodes* ng_get_installation_group_exec_node(); +/* compute permission group */ +extern Distribution* ng_get_compute_permission_group_distribution(); +/* query union set group */ +extern Distribution* ng_get_query_union_set_group_distribution(List* baserel_rte_list, bool* baserels_in_same_group); +extern Distribution* ng_get_query_union_set_group_distribution(); +/* expected computing group */ +extern Distribution* ng_get_expected_computing_group_distribution(); +/* in_redistribution group */ +extern Oid ng_get_in_redistribution_group_oid(); +extern Distribution* ng_get_in_redistribution_group_distribution(); +extern Oid ng_get_redist_dest_group_oid(); +/* functional node group */ +extern Distribution* ng_get_default_computing_group_distribution(); +extern ExecNodes* ng_get_default_computing_group_exec_node(); +extern Distribution* ng_get_correlated_subplan_group_distribution(); +extern Distribution* ng_get_max_computable_group_distribution(); +extern Distribution* ng_get_single_node_distribution(); +/* ---------- + * Get distribution information of a node group + * ---------- + */ +extern Oid ng_get_group_groupoid(const char* group_name); +extern char* ng_get_group_group_name(Oid group_oid); +extern char* ng_get_dist_group_name(Distribution *distribution); +extern Bitmapset* ng_get_group_nodeids(const Oid groupoid); +extern Distribution* ng_get_group_distribution(const Oid groupoid); +extern Distribution* ng_get_group_distribution(const char* group_name); + +/* ---------- + * Get distribution information of a base relation + * ---------- + */ +extern Oid ng_get_baserel_groupoid(Oid tableoid, char relkind); +extern Bitmapset* ng_get_baserel_data_nodeids(Oid tableoid, char relkind); +extern Distribution* ng_get_baserel_data_distribution(Oid tableoid, char relkind); +extern unsigned int ng_get_baserel_num_data_nodes(Oid tableoid, char relkind); + +/* ---------- + * Get distribution information of a path or a plan + * ---------- + */ +/* distribution of Path */ +extern Bitmapset* ng_get_dest_nodeids(Path* path); +extern Distribution* ng_get_dest_distribution(Path* path); +/* distribution of Plan */ +extern Bitmapset* ng_get_dest_nodeids(Plan* plan); +extern Distribution* ng_get_dest_distribution(Plan* plan); +extern ExecNodes* ng_get_dest_execnodes(Plan* plan); +/* number of data nodes of Path, Plan and RelOptInfo */ +extern unsigned int ng_get_dest_num_data_nodes(Path* path); +extern unsigned int ng_get_dest_num_data_nodes(Plan* plan); +extern unsigned int ng_get_dest_num_data_nodes(RelOptInfo* rel); +extern unsigned int ng_get_dest_num_data_nodes(PlannerInfo* root, RelOptInfo* rel); +/* other information of Plan */ +extern char ng_get_dest_locator_type(Plan* plan); +extern List* ng_get_dest_distribute_keys(Plan* plan); + +/* ---------- + * Distribution data structure management + * ---------- + */ +extern Distribution* ng_copy_distribution(Distribution* src_distribution); +extern void ng_copy_distribution(Distribution* dest_distribution, const Distribution* src_distribution); +extern void ng_set_distribution(Distribution* dest_distribution, Distribution* src_distribution); +extern Distribution* ng_get_overlap_distribution(Distribution* distribution_1, Distribution* distribution_2); +extern Distribution* ng_get_union_distribution(Distribution* distribution_1, Distribution* distribution_2); +extern Distribution* ng_get_union_distribution_recycle(Distribution* distribution_1, + Distribution* distribution_2); +extern Distribution* ng_get_random_single_dn_distribution(Distribution* distribution); + +/* ---------- + * Convert functions + * ---------- + */ +/* node id (index) and node oid */ +extern int ng_convert_to_nodeid(Oid nodeoid); +extern Oid ng_convert_to_nodeoid(int nodeid); +/* node list */ +extern List* ng_convert_to_nodeid_list(Bitmapset* bms_nodeids); +/* nodeids */ +extern Bitmapset* ng_convert_to_nodeids(ExecNodes* exec_nodes); +extern Bitmapset* ng_convert_to_nodeids(List* nodeid_list); +/* Distribution */ +extern Distribution* ng_convert_to_distribution(List* nodeid_list); +extern Distribution* ng_convert_to_distribution(ExecNodes* exec_nodes); +/* ExecNodes */ +extern ExecNodes* ng_convert_to_exec_nodes( + Distribution* distribution, char locator_type, RelationAccessType access_type); + + +/* For geting suited candidate distributions to reduce search spaces. example: + * Single node distribution is not good for big data computing. + * Multi node distribution is not good for small data computing. + */ +enum DistrbutionPreferenceType { + DPT_ALL, + DPT_SHUFFLE, + DPT_SINGLE +}; + +/* + * Heuristic methods + */ +/* Join */ +extern List* ng_get_join_candidate_distribution_list(Path* outer_path, Path* inner_path, DistrbutionPreferenceType type); +extern List* ng_get_join_candidate_distribution_list(Path* outer_path, Path* inner_path, bool is_correlated, DistrbutionPreferenceType type); +/* Agg */ +extern List* ng_get_agg_candidate_distribution_list(Plan* plan, bool is_correlated, DistrbutionPreferenceType type); +/* SetOp */ +extern List* ng_get_setop_candidate_distribution_list(List* subPlans, bool is_correlated); + +/* + * Cost based algorithms + */ +extern double ng_get_nodegroup_stream_weight(unsigned int producer_num_dn, unsigned int consumer_num_dn); +extern Cost ng_calculate_setop_branch_stream_cost( + Plan* subPlan, unsigned int producer_num_datanodes, unsigned int consumer_num_datanodes); + +/* + * Distribution management for specific operators + */ +/* Join */ +extern Distribution* ng_get_join_distribution(Path* outer_path, Path* inner_path); +extern Distribution* ng_get_join_data_distribution(Plan* lefttree, Plan* righttree, List* nodeid_list); +/* SetOp */ +extern Distribution* ng_get_union_distribution_for_union_all(List* subPlans); +extern Distribution* ng_get_best_setop_distribution(List* subPlans, bool isUnionAll, bool is_correlated); + +/* + * Do shuffle between node groups if needed + */ +extern void ng_stream_side_paths_for_replicate(PlannerInfo* root, Path** outer_path, Path** inner_path, + JoinType jointype, bool is_mergejoin, Distribution* target_distribution); +extern Path* ng_stream_non_broadcast_side_for_join(PlannerInfo* root, Path* non_stream_path, JoinType save_jointype, + List* non_stream_pathkeys, bool is_replicate, bool stream_outer, Distribution* target_distribution); +extern Plan* ng_agg_force_shuffle(PlannerInfo* root, List* groupcls, Plan* subplan, List* tlist, Path* subpath); + +/* + * Compare functions, judge functions + */ +extern bool ng_is_multiple_nodegroup_scenario(); +extern bool ng_is_all_in_installation_nodegroup_scenario(); +extern bool ng_enable_nodegroup_explain(); +extern bool ng_is_valid_group_name(const char* group_name); +extern bool ng_is_special_group(Distribution* distribution); +extern bool ng_is_same_group(Bitmapset* bms_nodeids_1, Bitmapset* bms_nodeids_2); +extern bool ng_is_same_group(List* nodeid_list_1, List* nodeid_list_2); +extern bool ng_is_same_group(ExecNodes* exec_nodes, Bitmapset* bms_nodeids); +extern bool ng_is_same_group(Distribution* distribution_1, Distribution* distribution_2); +extern bool ng_is_exec_on_subset_nodes(ExecNodes* en1, ExecNodes* en2); +extern bool ng_is_shuffle_needed(Distribution* current_distribution, Distribution* target_distribution); +extern bool ng_is_shuffle_needed(PlannerInfo* root, Path* path, Distribution* target_distribution); +extern bool ng_is_distribute_key_valid(PlannerInfo* root, List* distribute_key, List* target_list); + +/* + * node group cache hash table interface + */ +extern void ngroup_info_hash_create(); +extern Bitmapset* ngroup_info_hash_search(Oid ngroup_oid); +extern void ngroup_info_hash_insert(Oid ngroup_oid, Bitmapset * bms_node_ids); +extern void ngroup_info_hash_delete(Oid ngroup_oid); + +/* + * Other functions + */ +extern Bitmapset* ng_get_single_node_group_nodeids(); +extern Distribution* ng_get_single_node_group_distribution(); +extern ExecNodes* ng_get_single_node_group_exec_node(); +extern char* dist_to_str(Distribution *distribution); +extern void _outBitmapset(StringInfo str, Bitmapset* bms); +extern bool ng_is_single_node_group_distribution(Distribution* distribution); +extern int ng_get_different_nodegroup_count(); +#endif /* NODEGROUPS_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/optimizerdebug.h postgresql-hll-2.14/include/optimizer/optimizerdebug.h --- postgresql-hll-2.14_old/include/optimizer/optimizerdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/optimizerdebug.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * optimizerdebug.h + * prototypes for optimizerdebug.h + * + * + * IDENTIFICATION + * src/include/optimizer/optimizerdebug.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OPTIMIZERDEBUG_H +#define OPTIMIZERDEBUG_H + +#include "nodes/relation.h" +#include "nodes/print.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" + +extern char* debug1_print_relids(Relids relids, List* rtable); + +extern void debug1_print_rel(PlannerInfo* root, RelOptInfo* rel); +extern char* debug1_print_path(PlannerInfo* root, Path* path, int indent); +extern void debug_print_hashjoin_detail(PlannerInfo* root, HashPath* path, double virtualbuckets, + Selectivity innerbucketsize, double outer_scan_ratio, Cost startup_cost, Cost total_cost); +extern void debug_print_agg_detail(PlannerInfo* root, AggStrategy aggstrategy, SAggMethod aggmethod, Path* path1, + Path* path2 = NULL, Path* path3 = NULL, Path* path4 = NULL, Path* path5 = NULL); + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); +#define OPT_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_OPT)) { \ + ereport(level, (errmodule(MOD_OPT), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +#endif /* OPTIMIZERDEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/pathnode.h postgresql-hll-2.14/include/optimizer/pathnode.h --- postgresql-hll-2.14_old/include/optimizer/pathnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pathnode.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,211 @@ +/* ------------------------------------------------------------------------- + * + * pathnode.h + * prototypes for pathnode.c, relnode.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/pathnode.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PATHNODE_H +#define PATHNODE_H + +#include "nodes/relation.h" +#include "optimizer/streamplan.h" + +/* global path */ +#define MAX_PATH_NUM 10 /* the maximum path number of super set distribute key */ + +/* To keep the plan stability, we should compare path costs with fuzzy factor */ +#define FUZZY_FACTOR 1.01 +#define SMALL_FUZZY_FACTOR 1.0000000001 + +typedef enum { + COSTS_EQUAL, /* path costs are fuzzily equal */ + COSTS_BETTER1, /* first path is cheaper than second */ + COSTS_BETTER2, /* second path is cheaper than first */ + COSTS_DIFFERENT /* neither path dominates the other on cost */ +} PathCostComparison; + +typedef enum SJoinUniqueMethod { + REDISTRIBUTE_UNIQUE, + UNIQUE_REDISTRIBUTE, + UNIQUE_REDISTRIBUTE_UNIQUE, + REDISTRIBUTE_UNIQUE_REDISTRIBUTE_UNIQUE +} SJoinUniqueMethod; + +/* + * prototypes for pathnode.c + */ +extern int compare_path_costs(Path* path1, Path* path2, CostSelector criterion); +extern int compare_fractional_path_costs(Path* path1, Path* path2, double fraction); +extern void set_cheapest(RelOptInfo* parent_rel, PlannerInfo* root = NULL); +extern Path* get_cheapest_path(PlannerInfo* root, RelOptInfo* rel, const double* agg_groups, bool has_groupby); +extern Path* find_hinted_path(Path* current_path); +extern void add_path(PlannerInfo* root, RelOptInfo* parent_rel, Path* new_path); +extern bool add_path_precheck( + RelOptInfo* parent_rel, Cost startup_cost, Cost total_cost, List* pathkeys, Relids required_outer); + +extern Path* create_seqscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer, int dop = 1); +extern Path* create_cstorescan_path(PlannerInfo* root, RelOptInfo* rel, int dop = 1); +#ifdef ENABLE_MULTIPLE_NODES +extern Path *create_tsstorescan_path(PlannerInfo * root,RelOptInfo * rel, int dop = 1); +#endif /* ENABLE_MULTIPLE_NODES */ +extern IndexPath* create_index_path(PlannerInfo* root, IndexOptInfo* index, List* indexclauses, List* indexclausecols, + List* indexorderbys, List* indexorderbycols, List* pathkeys, ScanDirection indexscandir, bool indexonly, + Relids required_outer, Bitmapset *upper_params, double loop_count); +extern Path* build_seqScanPath_by_indexScanPath(PlannerInfo* root, Path* index_path); +extern bool CheckBitmapQualIsGlobalIndex(Path* bitmapqual); +extern bool CheckBitmapHeapPathContainGlobalOrLocal(Path* bitmapqual); +extern bool check_bitmap_heap_path_index_unusable(Path* bitmapqual, RelOptInfo* baserel); +extern bool is_partitionIndex_Subpath(Path* subpath); +extern bool is_pwj_path(Path* pwjpath); +extern BitmapHeapPath* create_bitmap_heap_path(PlannerInfo* root, RelOptInfo* rel, Path* bitmapqual, + Relids required_outer, Bitmapset* required_upper, double loop_count); +extern BitmapAndPath* create_bitmap_and_path(PlannerInfo* root, RelOptInfo* rel, List* bitmapquals); +extern BitmapOrPath* create_bitmap_or_path(PlannerInfo* root, RelOptInfo* rel, List* bitmapquals); +extern TidPath* create_tidscan_path(PlannerInfo* root, RelOptInfo* rel, List* tidquals); +extern AppendPath* create_append_path(PlannerInfo* root, RelOptInfo* rel, List* subpaths, Relids required_outer); +extern MergeAppendPath* create_merge_append_path( + PlannerInfo* root, RelOptInfo* rel, List* subpaths, List* pathkeys, Relids required_outer); +extern ResultPath* create_result_path(PlannerInfo *root, RelOptInfo *rel, List* quals, Path* subpath = NULL, Bitmapset *upper_params = NULL); +extern MaterialPath* create_material_path(Path* subpath, bool materialize_all = false); +extern UniquePath* create_unique_path(PlannerInfo* root, RelOptInfo* rel, Path* subpath, SpecialJoinInfo* sjinfo); +extern Path* create_subqueryscan_path(PlannerInfo* root, RelOptInfo* rel, List* pathkeys, Relids required_outer, List *subplan_params); +extern Path* create_subqueryscan_path_reparam(PlannerInfo* root, RelOptInfo* rel, List* pathkeys, Relids required_outer, List *subplan_params); +extern Path* create_functionscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer); +extern Path* create_valuesscan_path(PlannerInfo* root, RelOptInfo* rel, Relids required_outer); +extern Path* create_ctescan_path(PlannerInfo* root, RelOptInfo* rel); +extern Path* create_worktablescan_path(PlannerInfo* root, RelOptInfo* rel); +extern ForeignPath* create_foreignscan_path(PlannerInfo* root, RelOptInfo* rel, Cost startup_cost, Cost total_cost, + List* pathkeys, Relids required_outer, List* fdw_private, int dop = 1); +extern Relids calc_nestloop_required_outer(Path* outer_path, Path* inner_path); +extern Relids calc_non_nestloop_required_outer(Path* outer_path, Path* inner_path); + +extern NestPath* create_nestloop_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, List* pathkeys, Relids required_outer, int dop = 1); + +extern MergePath* create_mergejoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, Path* outer_path, Path* inner_path, List* restrict_clauses, + List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, List* innersortkeys); + +extern HashPath* create_hashjoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, Relids required_outer, List* hashclauses, int dop = 1); + +extern Path* reparameterize_path(PlannerInfo* root, Path* path, Relids required_outer, double loop_count); + +/* + * prototypes for relnode.c + */ +extern void setup_simple_rel_arrays(PlannerInfo* root); +extern RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind); +extern RelOptInfo* find_base_rel(PlannerInfo* root, int relid); +extern RelOptInfo* find_join_rel(PlannerInfo* root, Relids relids); +extern void remove_join_rel(PlannerInfo *root, RelOptInfo *rel); +extern RelOptInfo* build_join_rel(PlannerInfo* root, Relids joinrelids, RelOptInfo* outer_rel, RelOptInfo* inner_rel, + SpecialJoinInfo* sjinfo, List** restrictlist_ptr); +extern AppendRelInfo* find_childrel_appendrelinfo(PlannerInfo* root, RelOptInfo* rel); +extern ParamPathInfo* get_baserel_parampathinfo(PlannerInfo* root, RelOptInfo* baserel, Relids required_outer, Bitmapset *upper_params = NULL); +extern ParamPathInfo* get_subquery_parampathinfo(PlannerInfo* root, RelOptInfo* baserel, Relids required_outer, Bitmapset *upper_params = NULL); +extern ParamPathInfo* get_joinrel_parampathinfo(PlannerInfo* root, RelOptInfo* joinrel, Path* outer_path, + Path* inner_path, SpecialJoinInfo* sjinfo, Relids required_outer, List** restrict_clauses); +extern ParamPathInfo* get_appendrel_parampathinfo(RelOptInfo* appendrel, Relids required_outer, Bitmapset* upper_params); +extern void get_distribute_keys(PlannerInfo* root, List* joinclauses, Path* outer_path, Path* inner_path, + double* skew_outer, double* skew_inner, List** distribute_keys_outer, List** distribute_keys_inner, + List* desired_keys, bool exact_match); +extern bool is_distribute_need_on_joinclauses(PlannerInfo* root, List* side_distkeys, List* joinclauses, + const RelOptInfo* side_rel, const RelOptInfo* other_rel, List** rrinfo); + +extern void add_hashjoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrictlist, Relids required_outer, List* hashclauses, Distribution* target_distribution); + +extern void add_nestloop_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, + Path* inner_path, List* restrict_clauses, List* pathkeys, Relids required_outer, Distribution* target_distribution); + +extern void add_mergejoin_path(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + JoinCostWorkspace* workspace, SpecialJoinInfo* sjinfo, Path* outer_path, Path* inner_path, List* restrict_clauses, + List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, List* innersortkeys, + Distribution* target_distribution); +extern bool equal_distributekey(PlannerInfo* root, List* distribute_key1, List* distribute_key2); +extern bool judge_node_compatible(PlannerInfo* root, Node* n1, Node* n2); +extern List* build_superset_keys_for_rel( + PlannerInfo* root, RelOptInfo* rel, RelOptInfo* outerrel, RelOptInfo* innerrel, JoinType jointype); +extern List* remove_duplicate_superset_keys(List* join_dis_key_list); +extern List* generate_join_implied_equalities_normal( + PlannerInfo* root, EquivalenceClass* ec, Relids join_relids, Relids outer_relids, Relids inner_relids); + +#ifdef STREAMPLAN +/* + * Determine which distributekey can be treated as the joinpath's distributekey + * 1. outer path's distributekey can be treated as the joinpath's distributekey if LHS_join returns true + * 2. inner path's distributekey can be treated as the joinpath's distributekey if RHS_join returns true + */ +#define LHS_join(jointype) \ + (JOIN_INNER == jointype || JOIN_LEFT == jointype || JOIN_SEMI == jointype || JOIN_ANTI == jointype || \ + JOIN_LEFT_ANTI_FULL == jointype) +#define RHS_join(jointype) \ + (JOIN_INNER == jointype || JOIN_RIGHT_ANTI == jointype || JOIN_RIGHT == jointype || JOIN_RIGHT_SEMI == jointype || \ + JOIN_RIGHT_ANTI_FULL == jointype) + +/* + * Check if we can broadcast side path + * 1. inner path can be broadcast if can_broadcast_inner returns true + * 2. outer path can be broadcast if can_broadcast_outer returns true + */ +#define can_broadcast_inner(jointype, save_jointype, replicate_outer, diskeys_outer, path_outer) \ + (LHS_join(jointype) && (save_jointype != JOIN_UNIQUE_OUTER || replicate_outer)) +#define can_broadcast_outer(jointype, save_jointype, replicate_inner, diskeys_inner, path_inner) \ + (RHS_join(jointype) && (save_jointype != JOIN_UNIQUE_INNER || replicate_inner)) + +extern bool find_ec_memeber_for_var(EquivalenceClass* ec, Node* key); +extern double get_skew_ratio(double distinct_value); +extern Path* stream_side_path(PlannerInfo* root, Path* path, JoinType jointype, bool is_replicate, + StreamType stream_type, List* distribute_key, List* pathkeys, bool is_inner, double skew, + Distribution* target_distribution, ParallelDesc* smpDesc = NULL); +extern double get_node_mcf(PlannerInfo* root, Node* v, double rows); +extern bool needs_agg_stream(PlannerInfo* root, List* tlist, List* distribute_targetlist, Distribution* distribution = NULL); +extern bool is_replicated_path(Path* path); +extern void adjust_rows_according_to_hint(HintState* hstate, RelOptInfo* rel, Relids subrelids = NULL); + +extern bool is_subplan_exec_on_coordinator(Path* path); +extern void set_hint_value(RelOptInfo* join_rel, Path* new_path, HintState* hstate); +extern void debug1_print_new_path(PlannerInfo* root, Path* path, bool small_fuzzy_factor_is_used); +extern void debug1_print_compare_result(PathCostComparison costcmp, PathKeysComparison keyscmp, BMS_Comparison outercmp, + double rowscmp, PlannerInfo* root, Path* path, bool small_fuzzy_factor_is_used); +extern PathCostComparison compare_path_costs_fuzzily(Path* path1, Path* path2, double fuzz_factor); +extern Node* get_distribute_node(PlannerInfo* root, RestrictInfo* rinfo, RelOptInfo* parent_rel, bool local_left, + double* skew_multiple, List* desired_keys, Node** exact_match_keys); +extern bool is_exact_match_keys_full(Node** match_keys, int length); +extern List* locate_distribute_key(JoinType jointype, List* outer_distributekey, List* inner_distributekey, + List* desired_key = NIL, bool exact_match = false); +extern SJoinUniqueMethod get_optimal_join_unique_path(PlannerInfo* root, Path* path, StreamType stream_type, + List* distribute_key, List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc); +extern Node* join_clause_get_join_key(Node* join_clause, bool is_var_on_left); + +extern Path* get_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, bool cost_only = false); + +extern Path* get_unique_redist(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc); + +extern Path* get_unique_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, List* distribute_key, + List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, bool cost_only = false); + +extern Path* get_redist_unique_redist_unique(PlannerInfo* root, Path* path, StreamType stream_type, + List* distribute_key, List* pathkeys, double skew, Distribution* target_distribution, ParallelDesc* smpDesc, + bool cost_only = false); + +extern bool equivalence_class_overlap(PlannerInfo* root, Relids outer_relids, Relids inner_relids); + +extern void debug3_print_two_relids(Relids first_relids, Relids second_relids, PlannerInfo* root, StringInfoData* buf); + +#endif +#endif /* PATHNODE_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/paths.h postgresql-hll-2.14/include/optimizer/paths.h --- postgresql-hll-2.14_old/include/optimizer/paths.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/paths.h 2020-12-12 17:06:43.347349329 +0800 @@ -0,0 +1,170 @@ +/* ------------------------------------------------------------------------- + * + * paths.h + * prototypes for various files in optimizer/path + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/paths.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PATHS_H +#define PATHS_H + +#include "nodes/relation.h" + +typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *rel, + Index rti, + RangeTblEntry *rte); +extern THR_LOCAL PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook; + +typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + SpecialJoinInfo *sjinfo, + Relids param_source_rels, + SemiAntiJoinFactors *semifactors, + List *restrictlist); +extern THR_LOCAL PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook; + +extern RelOptInfo* make_one_rel(PlannerInfo* root, List* joinlist); +extern RelOptInfo* standard_join_search(PlannerInfo* root, int levels_needed, List* initial_rels); + +extern void set_rel_size(PlannerInfo* root, RelOptInfo* rel, Index rti, RangeTblEntry* rte); + +#ifdef OPTIMIZER_DEBUG +extern void debug_print_rel(PlannerInfo* root, RelOptInfo* rel); +#endif + +/* + * indxpath.c + * routines to generate index paths + */ +extern void create_index_paths(PlannerInfo* root, RelOptInfo* rel); +extern List* generate_bitmap_or_paths( + PlannerInfo* root, RelOptInfo* rel, List* clauses, List* other_clauses, bool restriction_only); +extern List* GenerateBitmapOrPathsUseGPI( + PlannerInfo* root, RelOptInfo* rel, const List* clauses, List* other_clauses, bool restriction_only); +extern bool relation_has_unique_index_for( + PlannerInfo* root, RelOptInfo* rel, List* restrictlist, List* exprlist, List* oprlist); +extern bool eclass_member_matches_indexcol( + EquivalenceClass* ec, EquivalenceMember* em, IndexOptInfo* index, int indexcol); +extern bool match_index_to_operand(Node* operand, int indexcol, IndexOptInfo* index); +extern void expand_indexqual_conditions( + IndexOptInfo* index, List* indexclauses, List* indexclausecols, List** indexquals_p, List** indexqualcols_p); +extern void check_partial_indexes(PlannerInfo* root, RelOptInfo* rel); +extern Expr* adjust_rowcompare_for_index( + RowCompareExpr* clause, IndexOptInfo* index, int indexcol, List** indexcolnos, bool* var_on_left_p); +/* + * Check index path whether use global partition index to scan + */ +inline bool CheckIndexPathUseGPI(IndexPath* ipath) +{ + return ipath->indexinfo->isGlobal; +} + + +/* + * orindxpath.c + * additional routines for indexable OR clauses + */ +extern bool create_or_index_quals(PlannerInfo* root, RelOptInfo* rel); + +/* + * tidpath.h + * routines to generate tid paths + */ +extern void create_tidscan_paths(PlannerInfo* root, RelOptInfo* rel); + +/* + * joinpath.c + * routines to create join paths + */ +extern void add_paths_to_joinrel(PlannerInfo* root, RelOptInfo* joinrel, RelOptInfo* outerrel, RelOptInfo* innerrel, + JoinType jointype, SpecialJoinInfo* sjinfo, List* restrictlist); +extern bool clause_sides_match_join(RestrictInfo* rinfo, RelOptInfo* outerrel, RelOptInfo* innerrel); + +#ifdef PGXC +/* + * rquerypath.c + * routines to create RemoteQuery paths + */ +extern bool create_plainrel_rqpath(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); +extern void create_joinrel_rqpath(PlannerInfo* root, RelOptInfo* joinrel, RelOptInfo* outerrel, RelOptInfo* innerrel, + List* restrictlist, JoinType jointype, SpecialJoinInfo* sjinfo); +#endif /* PGXC */ + +/* + * joinrels.c + * routines to determine which relations to join + */ +extern void join_search_one_level(PlannerInfo* root, int level); +extern RelOptInfo* make_join_rel(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); +extern bool have_join_order_restriction(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); + +/* + * equivclass.c + * routines for managing EquivalenceClasses + */ +extern bool process_equivalence(PlannerInfo* root, RestrictInfo* restrictinfo, bool below_outer_join); +extern Expr* canonicalize_ec_expression(Expr* expr, Oid req_type, Oid req_collation); +extern void reconsider_outer_join_clauses(PlannerInfo* root); +extern EquivalenceClass* get_eclass_for_sort_expr(PlannerInfo* root, Expr* expr, List* opfamilies, Oid opcintype, + Oid collation, Index sortref, bool groupSet, Relids rel, bool create_it); +extern void generate_base_implied_equalities(PlannerInfo* root); +extern void generate_base_implied_qualities(PlannerInfo* root); +extern List* generate_join_implied_equalities( + PlannerInfo* root, Relids join_relids, Relids outer_relids, RelOptInfo* inner_rel); +extern List* generate_join_implied_equalities_for_ecs( + PlannerInfo* root, List* eclasses, Relids join_relids, Relids outer_relids, RelOptInfo* inner_rel); +extern bool exprs_known_equal(PlannerInfo* root, Node* item1, Node* item2); +extern void add_child_rel_equivalences( + PlannerInfo* root, AppendRelInfo* appinfo, RelOptInfo* parent_rel, RelOptInfo* child_rel); +extern void mutate_eclass_expressions(PlannerInfo* root, Node* (*mutator)(), void* context, bool include_child_exprs); +extern List* generate_implied_equalities_for_indexcol(PlannerInfo* root, IndexOptInfo* index, int indexcol, Relids prohibited_rels); +extern bool have_relevant_eclass_joinclause(PlannerInfo* root, RelOptInfo* rel1, RelOptInfo* rel2); +extern bool has_relevant_eclass_joinclause(PlannerInfo* root, RelOptInfo* rel1); +extern bool eclass_useful_for_merging(EquivalenceClass* eclass, RelOptInfo* rel); +extern bool is_redundant_derived_clause(RestrictInfo* rinfo, List* clauselist); + +/* + * pathkeys.c + * utilities for matching and building path keys + */ +typedef enum { + PATHKEYS_EQUAL, /* pathkeys are identical */ + PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */ + PATHKEYS_BETTER2, /* vice versa */ + PATHKEYS_DIFFERENT /* neither pathkey includes the other */ +} PathKeysComparison; + +extern List* canonicalize_pathkeys(PlannerInfo* root, List* pathkeys); +extern PathKeysComparison compare_pathkeys(List* keys1, List* keys2); +extern bool pathkeys_contained_in(List* keys1, List* keys2); +extern Path* get_cheapest_path_for_pathkeys( + List* paths, List* pathkeys, Relids required_outer, CostSelector cost_criterion); +extern Path* get_cheapest_fractional_path_for_pathkeys( + List* paths, List* pathkeys, Relids required_outer, double fraction); +extern List* build_index_pathkeys(PlannerInfo* root, IndexOptInfo* index, ScanDirection scandir); +extern List* convert_subquery_pathkeys(PlannerInfo* root, RelOptInfo* rel, List* subquery_pathkeys); +extern List* build_join_pathkeys(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, List* outer_pathkeys); +extern List* make_pathkeys_for_sortclauses(PlannerInfo* root, List* sortclauses, List* tlist, bool canonicalize); +extern void initialize_mergeclause_eclasses(PlannerInfo* root, RestrictInfo* restrictinfo); +extern void update_mergeclause_eclasses(PlannerInfo* root, RestrictInfo* restrictinfo); +extern List* find_mergeclauses_for_outer_pathkeys(PlannerInfo* root, List* pathkeys, List* restrictinfos); +extern List* select_outer_pathkeys_for_merge(PlannerInfo* root, List* mergeclauses, RelOptInfo* joinrel); +extern List* make_inner_pathkeys_for_merge(PlannerInfo* root, List* mergeclauses, List* outer_pathkeys); +extern List* trim_mergeclauses_for_inner_pathkeys(PlannerInfo* root, List* mergeclauses, List* pathkeys); + +extern List* truncate_useless_pathkeys(PlannerInfo* root, RelOptInfo* rel, List* pathkeys); +extern bool has_useful_pathkeys(PlannerInfo* root, RelOptInfo* rel); +extern void set_path_rows(Path* path, double rows, double multiple = 1); +extern EquivalenceClass* get_expr_eqClass(PlannerInfo* root, Expr* expr); +extern void delete_eq_member(PlannerInfo* root, List* tlist, List* collectiveGroupExpr); +#endif /* PATHS_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/pgxcplan.h postgresql-hll-2.14/include/optimizer/pgxcplan.h --- postgresql-hll-2.14_old/include/optimizer/pgxcplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pgxcplan.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------- + * + * pgxcplan.h + * Postgres-XC specific planner interfaces and structures. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxcplan.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXCPLANNER_H +#define PGXCPLANNER_H + +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "nodes/primnodes.h" +#include "pgxc/locator.h" +#include "tcop/dest.h" +#include "nodes/relation.h" +#include "optimizer/pgxc_plan_remote.h" + +typedef struct VecRemoteQuery : public RemoteQuery { +} VecRemoteQuery; + +extern PlannedStmt* pgxc_planner(Query* query, int cursorOptions, ParamListInfo boundParams); +extern List* AddRemoteQueryNode(List* stmts, const char* queryString, RemoteQueryExecType remoteExecType, bool is_temp); +extern bool pgxc_query_contains_temp_tables(List* queries); +extern bool pgxc_query_contains_utility(List* queries); +extern void pgxc_rqplan_adjust_tlist(PlannerInfo* root, RemoteQuery* rqplan, bool gensql = true); + +extern Plan* pgxc_make_modifytable(PlannerInfo* root, Plan* topplan); +extern RangeTblEntry* make_dummy_remote_rte(char* relname, Alias* alias); +extern List* pgxc_get_dist_var(Index varno, RangeTblEntry* rte, List* tlist); +extern CombineType get_plan_combine_type(CmdType commandType, char baselocatortype); +extern ExecNodes* pgxc_is_join_shippable(ExecNodes* inner_en, ExecNodes* outer_en, bool inner_unshippable_tlist, + bool outer_shippable_tlist, JoinType jointype, Node* join_quals); +extern bool contains_temp_tables(List* rtable); +extern List* process_agg_targetlist(PlannerInfo* root, List** local_tlist); +extern bool containing_ordinary_table(Node* node); +extern Param* pgxc_make_param(int param_num, Oid param_type); +extern Query* pgxc_build_shippable_query_recurse( + PlannerInfo* root, RemoteQueryPath* rqpath, List** unshippable_quals, List** rep_tlist); + +extern void preprocess_const_params(PlannerInfo* root, Node* jtnode); + +#endif /* PGXCPLANNER_H */ + diff -uprN postgresql-hll-2.14_old/include/optimizer/pgxc_plan_remote.h postgresql-hll-2.14/include/optimizer/pgxc_plan_remote.h --- postgresql-hll-2.14_old/include/optimizer/pgxc_plan_remote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pgxc_plan_remote.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------------- + * + * pgxc_plan_remote.h + * Postgres-XC specific planner interfaces and structures for remote query. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxc_plan_remote.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_PLANN_REMOTE_H +#define PGXC_PLANN_REMOTE_H + +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/params.h" +#include "nodes/parsenodes.h" +#include "nodes/plannodes.h" +#include "nodes/primnodes.h" +#include "pgxc/locator.h" +#include "tcop/dest.h" +#include "nodes/relation.h" + +/* For sorting within RemoteQuery handling */ +/* + * It is pretty much like Sort, but without Plan. We may use Sort later. + */ +typedef struct { + NodeTag type; + int numCols; /* number of sort-key columns */ + AttrNumber* sortColIdx; /* their indexes in the target list */ + Oid* sortOperators; /* OIDs of operators to sort them by */ + Oid* sortCollations; + bool* nullsFirst; /* NULLS FIRST/LAST directions */ + bool sortToStore; /* If should store tuples in sortstore into tuplestore. */ + /* For with hold cursor, we should do so. */ +} SimpleSort; + +typedef enum { + COMBINE_TYPE_NONE, /* it is known that no row count, do not parse */ + COMBINE_TYPE_SUM, /* sum row counts (partitioned, round robin) */ + COMBINE_TYPE_SAME /* expect all row counts to be the same (replicated write) */ +} CombineType; + +typedef enum { + EXEC_DIRECT_NONE, + EXEC_DIRECT_LOCAL, + EXEC_DIRECT_LOCAL_UTILITY, + EXEC_DIRECT_UTILITY, + EXEC_DIRECT_SELECT, + EXEC_DIRECT_INSERT, + EXEC_DIRECT_UPDATE, + EXEC_DIRECT_DELETE +} ExecDirectType; + +/* + * Contains instructions on processing a step of a query. + * In the prototype this will be simple, but it will eventually + * evolve into a GridSQL-style QueryStep. + */ +typedef struct { + Scan scan; + ExecDirectType exec_direct_type; /* track if remote query is execute direct and what type it is */ + char* sql_statement; + char* execute_statement; /* execute statement */ + ExecNodes* exec_nodes; /* List of Datanodes where to launch query */ + CombineType combine_type; + bool read_only; /* do not use 2PC when committing read only steps */ + bool force_autocommit; /* some commands like VACUUM require autocommit mode */ + char* statement; /* if specified use it as a PreparedStatement name on Datanodes */ + int stmt_idx; /* for cngpc, save idx of stmt_name in CachedPlan */ + char* cursor; /* if specified use it as a Portal name on Datanodes */ + int rq_num_params; /* number of parameters present in remote statement */ + Oid* rq_param_types; /* parameter types for the remote statement */ + bool rq_params_internal; /* Do the query params refer to the source data + * plan as against user-supplied params ? + */ + + RemoteQueryExecType exec_type; + bool is_temp; /* determine if this remote node is based + * on a temporary objects (no 2PC) */ + + bool rq_finalise_aggs; /* Aggregates should be finalised at the + * Datanode + */ + bool rq_sortgroup_colno; /* Use resno for sort group references + * instead of expressions + */ + Query* remote_query; /* Query structure representing the query to be + * sent to the datanodes + */ + List* base_tlist; /* the targetlist representing the result of + * the query to be sent to the datanode + */ + /* + * Reference targetlist of Vars to match the Vars in the plan nodes on + * coordinator to the corresponding Vars in the remote_query. These + * targetlists are used to while replacing/adding targetlist and quals in + * the remote_query. + */ + List* coord_var_tlist; + List* query_var_tlist; + bool has_row_marks; /* Did SELECT had FOR UPDATE/SHARE? */ + bool rq_save_command_id; /* Save the command ID to be used in + * some special cases */ + + bool is_simple; /* true if generate by gauss distributed framework, act as gather node in coordinator, + false if generate by pgxc distributed framework */ + bool rq_need_proj; /* @hdfs + * if is_simple is false, this value is always true; if is_simple is true, rq_need_proj + * is true for hdfs foreign table and false on other conditions. + */ + bool mergesort_required; /* true if the underlying node is sorted, default false; */ + bool spool_no_data; /* true if it do not need buffer all the data from data node */ + + bool poll_multi_channel; /* poll receive data from multi channel randomly */ + + int num_stream; /* num of stream below remote query */ + + int num_gather; /* num of gather(scan_gather plan_router) below remote query */ + + SimpleSort* sort; + + /* @hdfs + * The variable rte_ref will be used when the remotequery is executed by converting to stream. + * this variable store RangeTblRef struct, every of which corresponds the rte order number in + * rtable of root(PlannerInfo). + */ + List* rte_ref; + + RemoteQueryType position; /* the position where the RemoteQuery node will run. */ + bool is_send_bucket_map; /* send bucket map to dn or not */ + /* If execute direct on multi nodes, ExecRemoteQuery will call function query next according to this flag */ + bool is_remote_function_query; + bool isCustomPlan = false; + bool isFQS = false; +} RemoteQuery; + +extern Plan* create_remote_mergeinto_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp, MergeAction* action); +extern void pgxc_rqplan_adjust_tlist(PlannerInfo* root, RemoteQuery* rqplan, bool gensql); +extern void pgxc_rqplan_build_statement(RemoteQuery* rqplan); + +extern Plan* create_remotegrouping_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotedml_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp); +extern Plan* create_remotelimit_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotequery_plan(PlannerInfo* root, RemoteQueryPath* best_path); +extern Plan* create_remotesort_plan(PlannerInfo* root, Plan* local_plan, List* pathkeys); + +#endif /* PGXC_PLANN_REMOTE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/optimizer/pgxcship.h postgresql-hll-2.14/include/optimizer/pgxcship.h --- postgresql-hll-2.14_old/include/optimizer/pgxcship.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pgxcship.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,100 @@ +/* ------------------------------------------------------------------------- + * + * pgxcship.h + * Functionalities for the evaluation of expression shippability + * to remote nodes + * + * + * Portions Copyright (c) 1996-2012 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/optimizer/pgxcship.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PGXCSHIP_H +#define PGXCSHIP_H + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "nodes/nodeFuncs.h" +#include "pgxc/locator.h" +#include "utils/plpgsql.h" + +/* Insert select shippability flags */ +#define INSEL_SHIPPABLE_NCOL 0 +#define INSEL_SHIPPABLE_DCOL 1 +#define INSEL_UNSHIPPABLE_COL 2 + +typedef struct { + bool is_randomfunc_shippable; + bool is_nextval_shippable; + bool allow_func_in_targetlist; + bool is_ecfunc_shippable; + bool disallow_volatile_func_shippable; + bool disable_dn_gather; + List* query_list; + uint8 query_count; + bool query_shippable; /* backward compatible */ + bool current_shippable; /* current query can push */ + bool global_shippable; /* the whole query can push */ +} shipping_context; + +typedef struct { + List* funcids; /* List of func Oid */ + List* func_exprs; /* List of FuncExpr we have found */ + + /* true means find all func specified by funcids, false means once find any func then return */ + bool find_all; +} contain_func_context; + +typedef struct { + List* subquery_exprs; +} contain_subquery_context; + +/* Determine if query is shippable */ +extern ExecNodes* pgxc_is_query_shippable( + Query* query, int query_level, bool light_proxy, bool* contain_column_store = NULL, bool* use_star_up = NULL); +/* Determine if an expression is shippable */ +extern bool pgxc_is_expr_shippable(Expr* node, bool* has_aggs); +extern bool pgxc_is_funcRTE_shippable(Expr* node); +/* Determine if given function is shippable */ +extern bool pgxc_is_func_shippable(Oid funcid, shipping_context* context = NULL); +/* Determine if given function is shippable and the args conctains ANY type */ +extern bool pgxc_is_shippable_func_contain_any(Oid funcid); +extern bool pgxc_is_internal_agg_final_func(Oid funcid); +extern bool is_avg_func(Oid funcid); +/* Check equijoin conditions on given relations */ +extern List* pgxc_find_dist_equijoin_qual(List* dist_vars1, List* dist_vars2, Node* quals); +/* Merge given execution nodes based on join shippability conditions */ +extern ExecNodes* pgxc_merge_exec_nodes(ExecNodes* en1, ExecNodes* en2, int join_type = -1); +/* Check if given Query includes distribution column */ +extern bool pgxc_query_has_distcolgrouping(Query* query, ExecNodes* exec_nodes); +/* Check the shippability of an index */ +extern bool pgxc_check_index_shippability(RelationLocInfo* relLocInfo, bool is_primary, bool is_unique, + bool is_exclusion, List* indexAttrs, List* indexExprs); +/* Check the shippability of a parent-child constraint */ +extern bool pgxc_check_fk_shippability( + RelationLocInfo* parentLocInfo, RelationLocInfo* childLocInfo, List* parentRefs, List* childRefs); +extern bool pgxc_check_triggers_shippability(Oid relid, int commandType, bool* hasTrigger); +extern bool pgxc_find_nonshippable_row_trig( + Relation rel, int16 tgtype_event, int16 tgtype_timing, bool ignore_timing, bool* hasTrigger = NULL); +extern bool pgxc_query_contains_foreign_table(List* rtable); +extern bool pgxc_check_dynamic_param(List* dynamicExpr, ParamListInfo params); + +/* For online expansion, we need some user defined function to be shippable to DN */ +extern bool redis_func_shippable(Oid funcid); +extern bool vector_search_func_shippable(Oid funcid); + +/* For trigger shippable check */ +extern bool pgxc_is_query_shippable_in_trigger(PLpgSQL_expr* expr); +extern bool pgxc_find_statement_trigger(Oid relid, int commandType); + +/* For params, subquery walker */ +extern List* contains_subquery(Node* node, contain_subquery_context* context); +extern contain_subquery_context init_contain_subquery_context(); + +/* Get var from nodes */ +extern Var* get_var_from_node(Node* node); +#endif diff -uprN postgresql-hll-2.14_old/include/optimizer/placeholder.h postgresql-hll-2.14/include/optimizer/placeholder.h --- postgresql-hll-2.14_old/include/optimizer/placeholder.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/placeholder.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * placeholder.h + * prototypes for optimizer/util/placeholder.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/placeholder.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLACEHOLDER_H +#define PLACEHOLDER_H + +#include "nodes/relation.h" + +extern PlaceHolderVar* make_placeholder_expr(PlannerInfo* root, Expr* expr, Relids phrels); +extern PlaceHolderInfo* find_placeholder_info(PlannerInfo* root, PlaceHolderVar* phv, bool create_new_ph); +extern void find_placeholders_in_jointree(PlannerInfo* root); +extern void update_placeholder_eval_levels(PlannerInfo* root, SpecialJoinInfo* new_sjinfo); +extern void fix_placeholder_input_needed_levels(PlannerInfo* root); +extern void add_placeholders_to_base_rels(PlannerInfo* root); +extern void add_placeholders_to_joinrel(PlannerInfo* root, RelOptInfo* joinrel); + +#endif /* PLACEHOLDER_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/plancat.h postgresql-hll-2.14/include/optimizer/plancat.h --- postgresql-hll-2.14_old/include/optimizer/plancat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/plancat.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * plancat.h + * prototypes for plancat.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/plancat.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANCAT_H +#define PLANCAT_H + +#include "nodes/relation.h" +#include "utils/relcache.h" + +/* Hook for plugins to get control in get_relation_info() */ +typedef void (*get_relation_info_hook_type) (PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel); +extern THR_LOCAL PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook; + +extern List* build_index_tlist(PlannerInfo* root, IndexOptInfo* index, Relation heapRelation); + +extern void get_relation_info(PlannerInfo* root, Oid relationObjectId, bool inhparent, RelOptInfo* rel); + +extern void estimate_rel_size(Relation rel, int32* attr_widths, RelPageType* pages, double* tuples, double* allvisfrac, + List** sampledPartitionIds); + +extern int32 get_relation_data_width(Oid relid, Oid partitionid, int32* attr_widths, bool vectorized = false); + +extern int32 getPartitionDataWidth(Relation partRel, int32* attr_widths); + +extern int32 getIdxDataWidth(Relation rel, IndexInfo* info, bool vectorized); + +extern bool relation_excluded_by_constraints(PlannerInfo* root, RelOptInfo* rel, RangeTblEntry* rte); + +extern List* build_physical_tlist(PlannerInfo* root, RelOptInfo* rel); + +extern bool has_unique_index(RelOptInfo* rel, AttrNumber attno); + +extern Selectivity restriction_selectivity( + PlannerInfo* root, Oid operatorid, List* args, Oid inputcollid, int varRelid); + +extern Selectivity join_selectivity( + PlannerInfo* root, Oid operatorid, List* args, Oid inputcollid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern void estimatePartitionSize( + Relation relation, Oid partitionid, int32* attr_widths, RelPageType* pages, double* tuples, double* allvisfrac); + +#endif /* PLANCAT_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/planmain.h postgresql-hll-2.14/include/optimizer/planmain.h --- postgresql-hll-2.14_old/include/optimizer/planmain.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/planmain.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,191 @@ +/* ------------------------------------------------------------------------- + * + * planmain.h + * prototypes for various files in optimizer/plan + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planmain.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANMAIN_H +#define PLANMAIN_H + +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/clauses.h" +#include "optimizer/streamplan.h" +#include "utils/selfuncs.h" + +/* GUC parameters */ +#define DEFAULT_CURSOR_TUPLE_FRACTION 0.1 + +typedef enum { OP_HASHJOIN, OP_HASHAGG, OP_SORT, OP_MATERIAL } OpType; + +typedef enum AggOrientation { + AGG_LEVEL_1_INTENT, /* single level in normal case for hashagg */ + AGG_LEVEL_2_1_INTENT, /* first level in two-level hashagg */ + AGG_LEVEL_2_2_INTENT, /* second level in two-level hashagg */ + DISTINCT_INTENT, /* distinct case, no nested agg needed */ + UNIQUE_INTENT /* this is special for SMP to record unique agg type */ +} AggOrientation; + +/* row threshold to apply having filter */ +#define HAVING_THRESHOLD 1e6 + +/* + * prototypes for plan/planmain.c + */ +extern void query_planner(PlannerInfo* root, List* tlist, double tuple_fraction, double limit_tuples, + Path** cheapest_path, Path** sorted_path, double* num_groups, List* rollup_groupclauses = NULL, + List* rollup_lists = NULL); + +/* + * prototypes for plan/planagg.c + */ +extern void preprocess_minmax_aggregates(PlannerInfo* root, List* tlist); +extern Plan* optimize_minmax_aggregates( + PlannerInfo* root, List* tlist, const AggClauseCosts* aggcosts, Path* best_path); + +/* + * prototypes for plan/createplan.c + */ +extern void set_plan_rows(Plan* plan, double globalRows, double multiple = 1.0); +extern Plan* create_plan(PlannerInfo* root, Path* best_path); +extern void disuse_physical_tlist(Plan* plan, Path* path); +extern void copy_plan_costsize(Plan* dest, Plan* src); +extern SubqueryScan* make_subqueryscan(List* qptlist, List* qpqual, Index scanrelid, Plan* subplan); +extern ForeignScan* make_foreignscan(List* qptlist, List* qpqual, Index scanrelid, List* fdw_exprs, List* fdw_private, + RemoteQueryExecType type = EXEC_ON_ALL_NODES); +extern Append* make_append(List* appendplans, List* tlist); +extern RecursiveUnion* make_recursive_union( + List* tlist, Plan* lefttree, Plan* righttree, int wtParam, List* distinctList, long numGroups); +extern Sort* make_sort_from_pathkeys( + PlannerInfo* root, Plan* lefttree, List* pathkeys, double limit_tuples, bool can_parallel = false); +extern Sort* make_sort_from_sortclauses(PlannerInfo* root, List* sortcls, Plan* lefttree); +extern Sort* make_sort_from_groupcols(PlannerInfo* root, List* groupcls, AttrNumber* grpColIdx, Plan* lefttree); +extern Sort* make_sort_from_targetlist(PlannerInfo* root, Plan* lefttree, double limit_tuples); +extern Sort* make_sort(PlannerInfo* root, Plan* lefttree, int numCols, AttrNumber* sortColIdx, Oid* sortOperators, + Oid* collations, bool* nullsFirst, double limit_tuples); +extern Agg* make_agg(PlannerInfo* root, List* tlist, List* qual, AggStrategy aggstrategy, + const AggClauseCosts* aggcosts, int numGroupCols, AttrNumber* grpColIdx, Oid* grpOperators, long numGroups, + Plan* lefttree, WindowLists* wflists, bool need_stream, bool trans_agg, List* groupingSets = NIL, + Size hash_entry_size = 0, bool add_width = false, AggOrientation agg_orientation = AGG_LEVEL_1_INTENT, + bool unique_check = true); +extern WindowAgg* make_windowagg(PlannerInfo* root, List* tlist, List* windowFuncs, Index winref, int partNumCols, + AttrNumber* partColIdx, Oid* partOperators, int ordNumCols, AttrNumber* ordColIdx, Oid* ordOperators, + int frameOptions, Node* startOffset, Node* endOffset, Plan* lefttree); +extern Group* make_group(PlannerInfo* root, List* tlist, List* qual, int numGroupCols, AttrNumber* grpColIdx, + Oid* grpOperators, double numGroups, Plan* lefttree); +extern Plan* materialize_finished_plan(Plan* subplan, bool materialize_above_stream = false, bool vectorized = false); +extern Unique* make_unique(Plan* lefttree, List* distinctList); +extern LockRows* make_lockrows(PlannerInfo* root, Plan* lefttree); +extern Limit* make_limit(PlannerInfo* root, Plan* lefttree, Node* limitOffset, Node* limitCount, int64 offset_est, + int64 count_est, bool enable_parallel = true); +extern void pick_single_node_plan_for_replication(Plan* plan); +extern Plan* make_stream_limit(PlannerInfo* root, Plan* lefttree, Node* limitOffset, Node* limitCount, int64 offset_est, + int64 count_est, double limit_tuples, bool needs_sort); +extern Plan* make_stream_sort(PlannerInfo* root, Plan* lefttree); +extern SetOp* make_setop(SetOpCmd cmd, SetOpStrategy strategy, Plan* lefttree, List* distinctList, + AttrNumber flagColIdx, int firstFlag, long numGroups, double outputRows, OpMemInfo* memInfo); +extern Plan* create_direct_scan( + PlannerInfo* root, List* tlist, RangeTblEntry* realResultRTE, Index src_idx, Index scanrelid); +extern Plan* create_direct_righttree( + PlannerInfo* root, Plan* subplan, List* distinctList, List* uniq_exprs, ExecNodes* target_exec_nodes); +extern HashJoin* create_direct_hashjoin( + PlannerInfo* root, Plan* outerPlan, Plan* innerPlan, List* tlist, List* joinClauses, JoinType joinType); +extern BaseResult* make_result(PlannerInfo* root, List* tlist, Node* resconstantqual, Plan* subplan, List* qual = NIL); +extern Material* make_material(Plan* lefttree, bool materialize_all = false); +extern int find_node_in_targetlist(Node* node, List* targetlist); +extern Node* find_qualify_equal_class(PlannerInfo* root, Node* expr, List* targetlist); +extern List* confirm_distribute_key(PlannerInfo* root, Plan* plan, List* distribute_keys); +extern bool check_dsitribute_key_in_targetlist(PlannerInfo* root, List* distribute_keys, List* targetlist); +extern int get_plan_actual_total_width(Plan* plan, bool vectorized, OpType type, int newcol = 0); +#ifdef STREAMPLAN +extern Plan* make_modifytable(PlannerInfo* root, CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, Index mergeTargetRelation, + List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause, bool isDfsStore = false); +extern Plan* make_modifytables(PlannerInfo* root, CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, bool isDfsStore, + Index mergeTargetRelation, List* mergeSourceTargetList, List *mergeActionList, UpsertExpr *upsertClause); +extern Plan* make_redistribute_for_agg(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple, + Distribution* distribution = NULL, bool is_local_redistribute = false); +extern Plan* make_stream_plan(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple, + Distribution* target_distribution = NULL); +#else +extern ModifyTable* make_modifytable(CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, Index mergeTargetRelation, + List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause, bool isDfsStore = false); +extern ModifyTable* make_modifytables(CmdType operation, bool canSetTag, List* resultRelations, + List* subplans, List* returningLists, List* rowMarks, int epqParam, bool partKeyUpdated, bool isDfsStore, + Index mergeTargetRelation, List* mergeSourceTargetList, List* mergeActionList, UpsertExpr* upsertClause); +#endif + +extern bool is_projection_capable_plan(Plan* plan); +extern RowToVec* make_rowtovec(Plan* lefttree); +extern VecToRow* make_vectorow(Plan* lefttree); +extern bool isEqualExpr(Node* node); +extern bool check_subplan_in_qual(List* tlist, List* qual); +extern bool check_subplan_exec_datanode(PlannerInfo* root, Node* node); + +extern void add_base_rels_to_query(PlannerInfo* root, Node* jtnode); +extern void build_base_rel_tlists(PlannerInfo* root, List* final_tlist); +extern void add_vars_to_targetlist(PlannerInfo* root, List* vars, Relids where_needed, bool create_new_ph); +extern void find_lateral_references(PlannerInfo *root); +extern void create_lateral_join_info(PlannerInfo *root); +extern void add_lateral_info(PlannerInfo *root, Index rhs, Relids lhs); +extern List* deconstruct_jointree(PlannerInfo* root); +extern void distribute_restrictinfo_to_rels(PlannerInfo* root, RestrictInfo* restrictinfo); +extern void process_security_clause_appendrel(PlannerInfo *root); +extern void process_implied_equality(PlannerInfo* root, Oid opno, Oid collation, Expr* item1, Expr* item2, + Relids qualscope, Relids nullable_relids, Index security_level, bool below_outer_join, bool both_const); +extern void process_implied_quality(PlannerInfo* root, Node* node, Relids relids, bool below_outer_join); +extern RestrictInfo* build_implied_join_equality( + Oid opno, Oid collation, Expr* item1, Expr* item2, Relids qualscope, Relids nullable_relids, Index security_level); + +extern bool useInformationalConstraint(PlannerInfo* root, List* qualClause, Relids relids); + +/* + * prototypes for plan/analyzejoins.c + */ +extern List* remove_useless_joins(PlannerInfo* root, List* joinlist); +extern bool query_supports_distinctness(Query* query); +extern bool query_is_distinct_for(Query* query, List* colnos, List* opids); + +/* + * prototypes for plan/setrefs.c + */ +extern Plan* set_plan_references(PlannerInfo* root, Plan* plan); +extern void fix_opfuncids(Node* node); +extern void set_opfuncid(OpExpr* opexpr); +extern void set_sa_opfuncid(ScalarArrayOpExpr* opexpr); +extern void record_plan_function_dependency(PlannerInfo* root, Oid funcid); +extern void extract_query_dependencies( + Node* query, List** relationOids, List** invalItems, bool* hasRowSecurity, bool* hasHdfs); +extern double calc_num_groups(PlannerInfo* root, List* groupClause, double input_rows); + +#ifdef PGXC +/* + * prototypes for plan/pgxcplan.c + */ +extern Plan* create_remotedml_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp); +extern Plan* create_remote_mergeinto_plan(PlannerInfo* root, Plan* topplan, CmdType cmdtyp, MergeAction* action); +extern Plan* create_remotegrouping_plan(PlannerInfo* root, Plan* local_plan); +extern Plan* create_remotequery_plan(PlannerInfo* root, RemoteQueryPath* best_path); +extern Plan* create_remotesort_plan(PlannerInfo* root, Plan* local_plan, List* pathkeys = NIL); +extern Plan* create_remotelimit_plan(PlannerInfo* root, Plan* local_plan); +extern List* pgxc_order_qual_clauses(PlannerInfo* root, List* clauses); +extern List* pgxc_build_relation_tlist(RelOptInfo* rel); +extern void pgxc_copy_path_costsize(Plan* dest, Path* src); +extern Plan* pgxc_create_gating_plan(PlannerInfo* root, Plan* plan, List* quals); +#endif +extern void expand_dfs_tables(PlannerInfo* root); +extern void expand_internal_rtentry(PlannerInfo* root, RangeTblEntry* rte, Index rti); +extern List* find_all_internal_tableOids(Oid parentOid); +extern bool check_agg_optimizable(Aggref* aggref, int16* strategy); +extern void check_hashjoinable(RestrictInfo* restrictinfo); + +#endif /* PLANMAIN_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/planmem_walker.h postgresql-hll-2.14/include/optimizer/planmem_walker.h --- postgresql-hll-2.14_old/include/optimizer/planmem_walker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/planmem_walker.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * planmem_walker.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/planmem_walker.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PLANWALKER_H +#define PLANWALKER_H + +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" + +typedef bool (*MethodWalker)(); +typedef bool (*MethodP2Walker)(Node*, void*); + +/* Traverse flag during plan tree walker */ +#define UNDER_STREAM 0x01 /* this flag indicates that current plan node is under stream */ +#define UNDER_MULTI_GROUP_OP \ + 0x02 /* this flag indicates that current plan node is \ + under node with multiple group, like join, or append */ + +/* + * The plan associated with a SubPlan is found in a list. During planning this is in + * the global structure found through the root PlannerInfo. After planning this is in + * the PlannedStmt. + * + * Structure plan_tree_base_prefix carries the appropriate pointer for general plan + * tree walker/mutator framework. All users of the framework must prefix their context + * structure with a plan_tree_base_prefix and initialize it appropriately. + */ +typedef struct plan_tree_base_prefix { + Node* node; /* PlannerInfo* or PlannedStmt* */ + List* init_plans; /* with all traversed init plan saved, and below nodes can find reference from it */ + bool* traverse_flag; /* flag that indicates whether the subplan is traversed, to prevent duplicate traverse */ +} plan_tree_base_prefix; + +/* Memory calculation and control phase */ +typedef enum { + ASSIGN_MEM = 0, /* memory assignment phase, give memory to each plan node */ + DECREASE_MEM, /* memory decrease phase, only happens when query mem exceeds threshold */ + ADJUST_MEM, /* memory adjust phase, to prevent huge initial memory allocation or early disk spill */ + SPREAD_ADJUST_MEM /* memory spread calculation and adjust phase, to calculate maximum memory to spread */ +} TraversePhase; + +#define ADJ_PHASE(context) ((context)->phase == ADJUST_MEM || (context)->phase == SPREAD_ADJUST_MEM) + +/* each nodegroup's OperatorGroup mem */ +typedef struct OperatorGroupNodeMem { + /* + * The following memory usage are all arrays, and we use the first one for normal memory + * usage, and second one for min memory usage if not equal to normal one, else 0 + */ + /* The memory limit for this group and its child groups */ + int groupMemKB[2]; + /* The memory limit for the operators visible to this group */ + int groupBlockedOpMemKB[2]; + /* The memory limit during the group execution */ + int groupConcMemKB[2]; + /* The memory limit for child groups below stream */ + int belowStreamConcMemKB[2]; + /* The memory limit of operators in this group */ + int groupOpMemKB[2]; + + /* memory that need to decreased */ + int decreaseMemKB; + /* memory that group operator need to decrease */ + int groupOpDMemKB; + /* memory that group top node need to decrease */ + int topNodeDMemKB; +} OperatorGroupNodeMem; + +/* + * OperatorGroupNode + * Store the information regarding an operator group. + * See details in memctl.cpp + */ +typedef struct OperatorGroupNode { + /* The id and top node for this group */ + int groupId; + Plan* topNode; + + /* The list of child groups */ + List* childGroups; + + /* The parent group */ + struct OperatorGroupNode* parentGroup; + + List* belowStreamGroups; /* list of virtual groups below + stream, which are the real co-exist groups */ + + bool virtualGroup; /* groups with memory non-intensive operator as top node */ + bool underStreamGroup; /* virtual group that under stream node */ + + int childLevel; /* number of children group levels below */ + int outerLevel; /* number of children group levels for hash join outer side */ + + /* The memory info for each nodegroup in this operator group node */ + OperatorGroupNodeMem* ng_groupMemKBArray; + int ng_num; +} OperatorGroupNode; + +typedef struct QueryMemKB { + int queryMemKB; /* the query memory limit */ + int minQueryMemKB; /* the minimum query memory limit */ + int currQueryMemKB; /* the query memory limit of current plan */ + int minCurrQueryMemKB; /* the minimum query memory limit of current plan */ + + int availMemKB; /* total expected memory for the query */ + int streamTotalMemKB; /* total memory consumption of stream, which can't be decrease */ + + int assigned_query_mem_1; /* assigned_query_mem[1] for each nodegroup */ +} QueryMemKB; + +/* + * MethodEarlyFreeContext + * Store the intermediate states during the tree walking for the optimize + * memory distribution policy. + */ +typedef struct MethodPlanWalkerContext { + plan_tree_base_prefix base; + + TraversePhase phase; /* Traverse phase */ + bool dnExec; /* current node is executed on datanode */ + OperatorGroupNode* groupTree; /* the root of the group tree */ + OperatorGroupNode* groupNode; /* the current group node in the group tree */ + + int nextGroupId; /* the group id for a new group node */ + + PlannedStmt* plannedStmt; /* pointer to the planned statement */ + + unsigned int status; /* current op is under stream */ + List* groupTreeList; /* list of group trees of a query */ + int groupTreeIdx; /* current group tree index when re-traverse a plan tree */ + bool use_tenant; /* multi-tenant scenario, and we don't allow auto spread in this case */ + + List* ng_distributionList; /* related nodegroup list for logic cluster scenario */ + int ng_num; /* 1 plus number of logic clusters */ + QueryMemKB* ng_queryMemKBArray; /* query memory for each nodegroup */ +} MethodPlanWalkerContext; + +typedef struct PredpushPlanWalkerContext { + MethodPlanWalkerContext mpwc; + + bool predpush_stream; /* is predpush meet a stream */ +} PredpushPlanWalkerContext; + +extern void exec_init_plan_tree_base(plan_tree_base_prefix* base, PlannedStmt* stmt); + +extern Plan* plan_tree_base_subplan_get_plan(plan_tree_base_prefix* base, SubPlan* subplan); + +extern bool walk_plan_node_fields(Plan* plan, MethodWalker walker, void* context); + +extern bool plan_tree_walker(Node* node, MethodWalker walker, void* context); + +extern bool IsBlockedJoinNode(Plan* node); + +#endif /* PLANWALKER_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/planner.h postgresql-hll-2.14/include/optimizer/planner.h --- postgresql-hll-2.14_old/include/optimizer/planner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/planner.h 2020-12-12 17:06:43.348349341 +0800 @@ -0,0 +1,185 @@ +/* ------------------------------------------------------------------------- + * + * planner.h + * prototypes for planner.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planner.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANNER_H +#define PLANNER_H + +#include "executor/execdesc.h" +#include "nodes/plannodes.h" +#include "nodes/relation.h" +#include "optimizer/clauses.h" +#include "nodes/parsenodes.h" +#include "utils/selfuncs.h" + +#define INSTALLATION_MODE "installation" + +/* Expression kind codes for preprocess_expression */ +#define EXPRKIND_QUAL 0 +#define EXPRKIND_TARGET 1 +#define EXPRKIND_RTFUNC 2 +#define EXPRKIND_RTFUNC_LATERAL 3 +#define EXPRKIND_VALUES 4 +#define EXPRKIND_VALUES_LATERAL 5 +#define EXPRKIND_LIMIT 6 +#define EXPRKIND_APPINFO 7 +#define EXPRKIND_PHV 8 +#define EXPRKIND_TABLESAMPLE 9 + +/* + * @hdfs + * Optimize clause type by using informational constraint. + */ +typedef enum { GROUPBY_CLAUSE_TYPE, DISTINCT_CLAUSE_TYPE, SCAN_QUAL_CLAUSE_TYPE, JOIN_QUAL_CLAUSE_TYPE } ClauseType; + +/* Context for mark agg func and denserank in WindowAgg */ +typedef struct { + bool has_agg; + bool has_denserank; +} DenseRank_context; + +extern ExecNodes* getExecNodesByGroupName(const char* gname); +extern PlannedStmt* planner(Query* parse, int cursorOptions, ParamListInfo boundParams); +extern PlannedStmt* standard_planner(Query* parse, int cursorOptions, ParamListInfo boundParams); + +typedef PlannedStmt *(*planner_hook_type) (Query* parse, int cursorOptions, ParamListInfo boundParams); + +extern Plan* subquery_planner(PlannerGlobal* glob, Query* parse, PlannerInfo* parent_root, bool hasRecursion, + double tuple_fraction, PlannerInfo** subroot, int options = SUBQUERY_NORMAL, ItstDisKey* diskeys = NULL, + List* subqueryRestrictInfo = NIL); + +extern void add_tlist_costs_to_plan(PlannerInfo* root, Plan* plan, List* tlist); + +extern bool is_dummy_plan(Plan* plan); + +extern bool is_single_baseresult_plan(Plan* plan); + +extern Expr* expression_planner(Expr* expr); + +extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr); + +extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid); + +extern bool ContainRecursiveUnionSubplan(PlannedStmt* pstmt); + +extern void preprocess_qual_conditions(PlannerInfo* root, Node* jtnode); + +typedef enum { + /* + * Disable "inlist2join" rewrite optimization + */ + QRW_INLIST2JOIN_DISABLE = -1, + + /* + * Enable "inlist2join" rewrite optimization in cost-base mode, and this is default + * behavior in optimizer. + */ + QRW_INLIST2JOIN_CBO = 0, + + /* + * Enable "inlist2join" rewrite optimization in rule-base mode and without consider + * the num of elements specified in "In-List" or "= ANY[]" clause. + * + * We are considering it as a force mode, more likely it is to help DFX improvement + * to evaluate Inlist2Join is correct for query result (developer basis) + */ + QRW_INLIST2JOIN_FORCE = 1, + + /* + * Other values that greater than 2, inlist2join rewrite optimization runs in extended + * rule-base mode, where the GUC value plays as the element num of inlist threshold + * for inlist2join conversion + */ +} QrwInlist2JoinOptMode; + +typedef struct RewriteVarMapping { + Var* old_var; + Var* new_var; + bool need_fix; /* the var is needed to fix when create plan */ +} RewriteVarMapping; + +extern void fix_vars_plannode(PlannerInfo* root, Plan* plan); +extern void inlist2join_qrw_optimization(PlannerInfo* root, int rti); +extern void find_inlist2join_path(PlannerInfo* root, Path* best_path); + +extern bool planClusterPartitionUseSort(Relation partRel, Oid indexOid, PlannerInfo* root, RelOptInfo* relOptInfo); +extern void select_active_windows(PlannerInfo* root, WindowLists* wflists); +extern List* make_pathkeys_for_window(PlannerInfo* root, WindowClause* wc, List* tlist, bool canonicalize); + +extern List* get_distributekey_from_tlist( + PlannerInfo* root, List* tlist, List* groupcls, double rows, double* result_multiple, void* skew_info = NULL); +extern Plan* try_vectorize_plan(Plan* top_plan, Query* parse, bool from_subplan, PlannerInfo* subroot = NULL); +extern bool is_vector_scan(Plan* plan); + +extern bool vector_engine_unsupport_expression_walker(Node* node); + +extern void adjust_all_pathkeys_by_agg_tlist(PlannerInfo* root, List* tlist, WindowLists* wflists); +extern void get_multiple_from_exprlist(PlannerInfo* root, List* exprList, double rows, bool* useskewmultiple, + bool usebiasmultiple, double* skew_multiple, double* bias_multiple); +extern double get_bias_from_varlist(PlannerInfo* root, List* varlist, double rows, bool isCoalesceExpr = false); +extern ExecNodes* getDefaultPlannerExecNodes(PlannerInfo* root); +extern ExecNodes* getRelationExecNodes(Oid tableoid); +extern Bitmapset* get_base_rel_indexes(Node* jtnode); +extern Size get_hash_entry_size(int width, int numAggs = 0); + +typedef enum QueryIssueType { + /* Query not plan shipping */ + QueryShipping = 0, + + /* Large relation Broadcast */ + LargeTableBroadCast, + + /* Large relation is the inner relation when deal with Hashjoin */ + LargeTableAsHashJoinInner, + + /* Large relation in nestloop with equal join condition */ + LargeTableWithEqualCondInNestLoop, + + /* Data Skew */ + DataSkew, + + /* Not Collect Statistics */ + StatsNotCollect, + + /* Estimation rows is inaccurate */ + InaccurateEstimationRowNum, + + /* Unsuitable Scan Method */ + UnsuitableScanMethod +} QueryIssueType; + +/* + * Data structure to represent query issues + */ +typedef struct QueryPlanIssueDesc { + QueryIssueType issue_type; + const PlanState* issue_plannode; + StringInfo issue_suggestion; +} QueryPlanIssueDesc; + +extern List* PlanAnalyzerQuery(QueryDesc* querydesc); +extern List* PlanAnalyzerOperator(QueryDesc* querydesc, PlanState* planstate); +extern void GetPlanNodePlainText( + Plan* plan, char** pname, char** sname, char** strategy, char** operation, char** pt_operation, char** pt_options); +extern void RecordQueryPlanIssues(const List* results); +extern bool enable_check_implicit_cast(); +extern void check_gtm_free_plan(PlannedStmt *stmt, int elevel); +extern THR_LOCAL List* g_index_vars; +extern bool PreprocessOperator(Node* node, void* context); +extern void check_plan_mergeinto_replicate(PlannedStmt* stmt, int elevel); +extern void check_entry_mergeinto_replicate(Query* parse); +extern List* get_plan_list(Plan* plan); +extern RelOptInfo* build_alternative_rel(const RelOptInfo* origin, RTEKind rtekind); +extern Plan* get_foreign_scan(Plan* plan); +extern uint64 adjust_plsize(Oid relid, uint64 plan_width, uint64 pl_size, uint64* width); + +#endif /* PLANNER_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/predtest.h postgresql-hll-2.14/include/optimizer/predtest.h --- postgresql-hll-2.14_old/include/optimizer/predtest.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/predtest.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * predtest.h + * prototypes for predtest.c + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/predtest.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDTEST_H +#define PREDTEST_H + +#include "nodes/primnodes.h" + +extern bool predicate_implied_by(List* predicate_list, List* restrictinfo_list); +extern bool predicate_refuted_by(List* predicate_list, List* restrictinfo_list, bool weakRefute); + +#endif /* PREDTEST_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/prep.h postgresql-hll-2.14/include/optimizer/prep.h --- postgresql-hll-2.14_old/include/optimizer/prep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/prep.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------------- + * + * prep.h + * prototypes for files in optimizer/prep/ + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/prep.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREP_H +#define PREP_H + +#include "nodes/plannodes.h" +#include "nodes/parsenodes.h" +#include "nodes/relation.h" + +#include "utils/guc.h" +#include "catalog/pg_operator.h" +#include "optimizer/clauses.h" + +typedef enum UNIONALL_SHIPPING_TYPE +{ + SHIPPING_NONE, + SHIPPING_PARTIAL, + SHIPPING_ALL +}UNIONALL_SHIPPING_TYPE; + +/* + * prototypes for prepjointree.c + */ +extern void pull_up_sublinks(PlannerInfo* root); +extern void substitute_ctes_with_subqueries(PlannerInfo* root, Query* parse, bool under_recursive_tree); +extern void inline_set_returning_functions(PlannerInfo* root); +extern Node* pull_up_subqueries(PlannerInfo* root, Node* jtnode); +extern void flatten_simple_union_all(PlannerInfo* root); +extern void removeNotNullTest(PlannerInfo* root); +extern void reduce_outer_joins(PlannerInfo* root); +extern void reduce_inequality_fulljoins(PlannerInfo* root); +extern Relids get_relids_in_jointree(Node* jtnode, bool include_joins); +extern Relids get_relids_for_join(PlannerInfo* root, int joinrelid); +extern void pull_up_subquery_hint(PlannerInfo* root, Query* parse, HintState* hint_state); +#ifndef ENABLE_MULTIPLE_NODES +extern void preprocess_rownum(PlannerInfo *root, Query *parse); +#endif + +/* + * prototypes for prepnonjointree.cpp + */ +extern bool get_real_rte_varno_attno( + Query* parse, Index* varno, AttrNumber* varattno, const Index targetVarno = InvalidOid); +extern bool is_join_inner_side( + const Node* fromNode, const Index targetRTEIndex, const bool isParentInnerSide, bool* isFound); +extern Query* lazyagg_main(Query* parse); +extern void reduce_orderby(Query* query, bool reduce); + +extern Node* get_real_rte_varno_attno_or_node(Query* parse, Index* varno, AttrNumber* varattno); + +/* + * prototypes for prepqual.c + */ +extern Node* negate_clause(Node* node); +extern Expr* canonicalize_qual(Expr* qual); + +/* + * prototypes for preptlist.c + */ +extern List* preprocess_targetlist(PlannerInfo* root, List* tlist); +extern List* preprocess_upsert_targetlist(List* tlist, int result_relation, List* range_table); +extern PlanRowMark* get_plan_rowmark(List* rowmarks, Index rtindex); + +/* + * prototypes for prepunion.c + */ +extern Plan* plan_set_operations(PlannerInfo* root, double tuple_fraction, List** sortClauses); + +extern void expand_inherited_tables(PlannerInfo* root); +extern void make_inh_translation_list( + Relation oldrelation, Relation newrelation, Index newvarno, List** translated_vars); +extern Bitmapset* translate_col_privs(const Bitmapset* parent_privs, List* translated_vars); + +extern Node* adjust_appendrel_attrs(PlannerInfo* root, Node* node, AppendRelInfo* appinfo); + +extern void mark_parent_child_pushdown_flag(Query *parent, Query *child); +extern bool check_base_rel_in_fromlist(Query *parse, Node *jtnode); +extern UNIONALL_SHIPPING_TYPE precheck_shipping_union_all(Query *subquery, Node *setOp); +#ifndef ENABLE_MULTIPLE_NODES +/* judge if it is possible to optimize ROWNUM */ +static inline bool contain_rownum_qual(Query *parse) +{ + if (!IsA(parse->jointree, FromExpr)) { + return false; + } + + return contain_rownum_walker(((FromExpr *)parse->jointree)->quals, NULL); +} +#endif +#endif /* PREP_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/pruningboundary.h postgresql-hll-2.14/include/optimizer/pruningboundary.h --- postgresql-hll-2.14_old/include/optimizer/pruningboundary.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pruningboundary.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruningboundary.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/pruningboundary.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PRUNINGBOUNDARY_H_ +#define PRUNINGBOUNDARY_H_ + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "utils/relcache.h" + +extern void destroyPruningBoundary(PruningBoundary* boundary); +extern PruningBoundary* makePruningBoundary(int partKeyNum); +extern PruningBoundary* copyBoundary(PruningBoundary* boundary); + +#endif /* PRUNINGBOUNDARY_H_ */ diff -uprN postgresql-hll-2.14_old/include/optimizer/pruning.h postgresql-hll-2.14/include/optimizer/pruning.h --- postgresql-hll-2.14_old/include/optimizer/pruning.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/pruning.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,101 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruning.h + * + * + * + * IDENTIFICATION + * src/include/optimizer/pruning.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PRUNING_H_ +#define PRUNING_H_ + +#include "nodes/parsenodes.h" +#include "nodes/relation.h" +#include "utils/partitionmap.h" +#include "utils/partitionmap_gs.h" +#include "utils/relcache.h" + +typedef PartitionMap* (*GetPartitionMapFunc)(Relation relation); + +typedef enum PruningType { + PruningPartition = 0, + PruningSlice, +} PruningType; + +typedef struct PruningContext { + PruningType pruningType; + GetPartitionMapFunc GetPartitionMap; + + PlannerInfo* root; + RangeTblEntry* rte; + EState* estate; + Relation relation; + + /* used for slice pruning */ + Index varno; + ParamListInfo boundParams; +} PruningContext; + +typedef enum PartKeyColumnRangeMode { + PARTKEY_RANGE_MODE_POINT = 0, + PARTKEY_RANGE_MODE_INCREASE, + PARTKEY_RANGE_MODE_RANGE, + PARTKEY_RANGE_MODE_UNION +} PartKeyColumnRangeMode; + +typedef enum IndexesUsableType { + INDEXES_FULL_USABLE = 0, + INDEXES_PARTIAL_USABLE, + INDEXES_NONE_USABLE +} IndexesUsableType; + +typedef struct PartKeyColumnRange { + PartKeyColumnRangeMode mode; + Const* prev; + Const* next; +} PartKeyColumnRange; + +typedef struct PartKeyRange { + int num; + PartKeyColumnRange columnRanges[4]; +} PartKeyRange; +extern IndexesUsableType eliminate_partition_index_unusable(Oid IndexOid, PruningResult* inputPruningResult, + PruningResult** indexUsablePruningResult, PruningResult** indexUnusablePruningResult); +PruningResult* getFullPruningResult(Relation relation); +void destroyPruningResult(PruningResult* pruningResult); +void partitionPruningFromBoundary(PruningContext *context, PruningResult* pruningResult); +void generateListFromPruningBM(PruningResult* result); +PruningResult* partitionPruningWalker(Expr* expr, PruningContext* pruningCtx); +PruningResult* partitionPruningForExpr(PlannerInfo* root, RangeTblEntry* rte, Relation rel, Expr* expr); +PruningResult* partitionPruningForRestrictInfo( + PlannerInfo* root, RangeTblEntry* rte, Relation rel, List* restrictInfoList); +PruningResult* singlePartitionPruningForRestrictInfo(Oid partitionOid, Relation rel); +extern PruningResult* copyPruningResult(PruningResult* srcPruningResult); +extern Oid getPartitionOidFromSequence(Relation relation, int partSeq); +extern int varIsInPartitionKey(int attrNo, int2vector* partKeyAttrs, int partKeyNum); +extern bool checkPartitionIndexUnusable(Oid indexOid, int partItrs, PruningResult* pruning_result); + +extern PruningResult* GetPartitionInfo(PruningResult* result, EState* estate, Relation current_relation); +static inline PartitionMap* GetPartitionMap(PruningContext *context) +{ + return context->GetPartitionMap(context->relation); +} + +#endif /* PRUNING_H_ */ diff -uprN postgresql-hll-2.14_old/include/optimizer/randomplan.h postgresql-hll-2.14/include/optimizer/randomplan.h --- postgresql-hll-2.14_old/include/optimizer/randomplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/randomplan.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * randomplan.h + * prototypes for randomplan.c + * + * + * IDENTIFICATION + * src/include/optimizer/randomplan.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RANDOMPLAN_H +#define RANDOMPLAN_H + +#include "nodes/relation.h" + +#define OPTIMIZE_PLAN 0 +#define RANDOM_PLAN_DEFAULT -1 + +extern int choose_random_option(int optionnum); +extern void set_inital_plan_seed(); +extern uint32 get_inital_plan_seed(); +extern List* get_random_path(RelOptInfo* parent_rel, Path** cheapest_startup_path, Path** cheapest_total_path); +extern char* get_random_plan_string(); + +#endif /* RANDOMPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/restrictinfo.h postgresql-hll-2.14/include/optimizer/restrictinfo.h --- postgresql-hll-2.14_old/include/optimizer/restrictinfo.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/restrictinfo.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,35 @@ +/* ------------------------------------------------------------------------- + * + * restrictinfo.h + * prototypes for restrictinfo.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/restrictinfo.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RESTRICTINFO_H +#define RESTRICTINFO_H + +#include "nodes/relation.h" + +/* Convenience macro for the common case of a valid-everywhere qual */ +#define make_simple_restrictinfo(clause) make_restrictinfo(clause, true, false, false, 0, NULL, NULL, NULL) + +extern RestrictInfo* make_restrictinfo(Expr* clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, + Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids); +extern List* make_restrictinfo_from_bitmapqual(Path* bitmapqual, bool is_pushed_down, bool include_predicates); +extern List* make_restrictinfos_from_actual_clauses(PlannerInfo* root, List* clause_list); +extern bool restriction_is_or_clause(RestrictInfo* restrictinfo); +extern bool restriction_is_securely_promotable(RestrictInfo* restrictinfo, RelOptInfo* rel); +extern List* get_actual_clauses(List* restrictinfo_list); +extern List* get_all_actual_clauses(List* restrictinfo_list); +extern List* extract_actual_clauses(List* restrictinfo_list, bool pseudoconstant); +extern void extract_actual_join_clauses(List* restrictinfo_list, List** joinquals, List** otherquals); +extern bool join_clause_is_movable_to(RestrictInfo* rinfo, Index baserelid); +extern bool join_clause_is_movable_into(RestrictInfo* rinfo, Relids currentrelids, Relids current_and_outer); +extern void initialize_bucket_size(RestrictInfo* info); +#endif /* RESTRICTINFO_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/stream_check.h postgresql-hll-2.14/include/optimizer/stream_check.h --- postgresql-hll-2.14_old/include/optimizer/stream_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/stream_check.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,47 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_check.h + * prototypes for stream plan for checking. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_check.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_CHECK_H +#define STREAM_CHECK_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "optimizer/stream_cost.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +typedef struct underStreamContext { + Index reslutIndex; + bool underStream; +} underStreamContext; + +extern Plan* mark_distribute_dml( + PlannerInfo* root, Plan** sourceplan, ModifyTable* mt_plan, List** resultRelations, List* mergeActionList); +extern List* check_op_list_template(Plan* result_plan, List* (*check_eval)(Node*)); +extern bool judge_lockrows_need_redistribute( + PlannerInfo* root, Plan* subplan, Form_pgxc_class target_classForm, Index result_rte_idx); +extern bool judge_redistribute_setop_support(PlannerInfo* root, List* subplanlist, Bitmapset* redistributePlanSet); +extern void mark_query_canpush_flag(Node *query); +extern void mark_stream_unsupport(); +extern List* check_random_expr(Plan* result_plan); +extern List* check_func_list(Plan* result_plan); +extern bool check_stream_support(); +extern List* check_subplan_list(Plan* result_plan); +extern List* check_vartype_list(Plan* result_plan); +extern ExecNodes* get_plan_max_ExecNodes(Plan* lefttree, List* subplans); +extern List* get_max_nodeList(List** nodeList, Plan* result_plan); + +#endif /* STREAM_CHECK_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/optimizer/stream_cost.h postgresql-hll-2.14/include/optimizer/stream_cost.h --- postgresql-hll-2.14_old/include/optimizer/stream_cost.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/stream_cost.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,97 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_cost.h + * prototypes used to calculate stream plan costs. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_cost.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_COST_H +#define STREAM_COST_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +typedef enum { + STREAM_GATHER = 0, + STREAM_BROADCAST, + STREAM_REDISTRIBUTE, + STREAM_ROUNDROBIN, + STREAM_HYBRID, + STREAM_LOCAL, + STREAM_NONE +} StreamType; + +typedef enum { + PARALLEL_NONE = 0, /* Default value, means no parallelization. */ + REMOTE_DISTRIBUTE, /* Distribute data to all nodes. */ + REMOTE_DIRECT_DISTRIBUTE,/* Distribute data to one specific nodes. */ + REMOTE_SPLIT_DISTRIBUTE, /* Distribute data to all parallel threads at all nodes. */ + REMOTE_BROADCAST, /* Broadcast data to all nodes. */ + REMOTE_SPLIT_BROADCAST, /* Broadcast data to all parallel threads all nodes. */ + REMOTE_HYBRID, /* Hybrid send data. */ + LOCAL_DISTRIBUTE, /* Distribute data to all threads at local node. */ + LOCAL_BROADCAST, /* Broadcast data to all threads at local node. */ + LOCAL_ROUNDROBIN /* Roundrobin data to all threads at local node. */ +} SmpStreamType; + +typedef struct ParallelDesc { + int consumerDop; /* DOP of consumer side. */ + int producerDop; /* DOP of producer side. */ + SmpStreamType distriType; /* Tag the data distribution type. */ +} ParallelDesc; + +/* + * All stream-type paths share these fields. + */ +typedef struct StreamPath { + Path path; + StreamType type; + Path* subpath; + ParallelDesc* smpDesc; /* the parallel description of the stream. */ + Distribution consumer_distribution; + List* skew_list; +} StreamPath; + +typedef struct Stream { + Scan scan; + StreamType type; /* indicate it's Redistribute/Broadcast. */ + char* plan_statement; + ExecNodes* consumer_nodes; /* indicate nodes group that send to. */ + List* distribute_keys; + bool is_sorted; /* true if the underlying node is sorted, default false. */ + SimpleSort* sort; /* do the merge sort if producer is sorted */ + bool is_dummy; /* is dummy means the stream thread init by this stream node + * will end asap and init a child stream thread. */ + + ParallelDesc smpDesc; /* the parallel description of the stream. */ + char* jitted_serialize; /* jitted serialize function for vecstream */ + List* skew_list; + int stream_level; /* number of stream level (starts from 1), normally + * used for recursive sql execution that under recursive-union operator. */ + ExecNodes* origin_consumer_nodes; + bool is_recursive_local; /* LOCAL GATHER for recursive */ +} Stream; + +extern void compute_stream_cost(StreamType type, char locator_type, double subrows, double subgblrows, + double skew_ratio, int width, bool isJoin, List* distribute_keys, Cost* total_cost, double* gblrows, + unsigned int producer_num_dn, unsigned int consumer_num_dn, ParallelDesc* smpDesc = NULL, List* ssinfo = NIL); +extern void cost_stream(StreamPath* stream, int width, bool isJoin = false); +extern List* get_max_cost_distkey_for_hasdistkey(PlannerInfo* root, List* subPlans, int subPlanNum, + List** subPlanKeyArray, Cost* subPlanCostArray, Bitmapset** redistributePlanSetCopy); +extern List* get_max_cost_distkey_for_nulldistkey( + PlannerInfo* root, List* subPlans, int subPlanNum, Cost* subPlanCostArray); +extern void parallel_stream_info_print(ParallelDesc* smpDesc, StreamType type); +extern List* make_distkey_for_append(PlannerInfo* root, Plan* subPlan); + +#endif /* STREAM_COST_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/optimizer/streampath.h postgresql-hll-2.14/include/optimizer/streampath.h --- postgresql-hll-2.14_old/include/optimizer/streampath.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/streampath.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,356 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * streampath.h + * functions for distribute join path generation in GaussDB + * + * + * IDENTIFICATION + * src/include/optimizer/streampath.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAMPATH_H +#define STREAMPATH_H + +#include "nodes/relation.h" +#include "optimizer/dataskew.h" +#include "optimizer/streamplan.h" + +class PathGen : public BaseObject { +public: + PathGen(PlannerInfo* root, RelOptInfo* rel); + + virtual ~PathGen(); + + /* Add a path to path list. */ + void addPath(Path* new_path); + +protected: + /* PlannerInfo for this path. */ + PlannerInfo* m_root; + + /* Rel info for this path. */ + RelOptInfo* m_rel; +}; + +class JoinPathGen : public PathGen { +public: + JoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, List* joinclauses, List* restrictinfo, + Path* outer_path, Path* inner_path, Relids required_outer); + + virtual ~JoinPathGen(); + +protected: + /* Init member variable. */ + void init(); + + /* Init if we need stream. */ + void initDistribution(); + + /* special process for list/range distributed table */ + void initRangeListDistribution(); + + /* Reset member variable for later use. */ + void reset(); + + /* Check if we can create parallel join path. */ + const bool isParallelEnable(); + + /* check if is a nestloop parameter path */ + const bool is_param_path(); + + /* Add join path to path list. */ + void addJoinPath(Path* path, List* desired_key, bool exact_match); + + /* Create stream path for join. */ + void addJoinStreamPath(); + + /* Add stream info for join. */ + void addJoinStreamInfo(); + + /* Add stream info for MPP structure. */ + void addStreamMppInfo(); + + /* Add stream info for multi node group execution. */ + void addStreamNodeGroupInfo(); + + /* Add stream info for parallel execution. */ + void addStreamParallelInfo(); + + /* Add stream info for skew optimization. */ + void addStreamSkewInfo(); + + /* Add parallel info for join. */ + bool addJoinParallelInfo(); + + /* Set base stream info. */ + void setStreamBaseInfo(StreamType inner_type, StreamType outer_type, List* inner_keys, List* outer_keys); + + /* Set stream info for multi nodegroup. */ + bool setStreamNodeGroupInfo(bool stream_outer); + + /* Set stream skew optimization info. */ + uint32 setStreamSkewInfo(); + + /* Set stream parallel execution info. */ + void setStreamParallelInfo(bool stream_outer, SmpStreamType sstype = PARALLEL_NONE); + + /* Check if we need local redistribute, */ + void parallelLocalRedistribute(bool* inner_can_local_distribute, bool* outer_can_local_distribute, + bool* inner_need_local_distribute, bool* outer_need_local_distribute); + + /* Find distribute keys for one join side. */ + List* getOthersideKey(bool stream_outer); + + /* Get distribute keys for join. */ + void getDistributeKeys( + List** distribute_keys_outer, List** distribute_keys_inner, List* desired_keys, bool exact_match); + + /* Check if we can alteer join method. */ + bool checkJoinMethodAlternative(bool* try_eq_related_indirectly); + + /* Check if the replicate path can do redistribute. */ + bool isReplicateJoinCanRedistribute(); + + /* Create stream path for join. */ + Path* streamSidePath(bool stream_outer); + + /* Create unique join path. */ + Path* makeJoinUniquePath(bool stream_outer, List* pathkeys); + + /* create a unique path for unique join with skewness at the no-unique side */ + Path* makeJoinSkewUniquePath(bool stream_outer, List* pathkeys); + + /* set distribute keys for join path. */ + const bool setJoinDistributeKeys(JoinPath* joinpath, List* desired_key = NIL, bool exact_match = false); + + /* create a new stream info pair from the old one. */ + void newStreamInfoPair(StreamInfoPair* streamInfoPair); + + /* Confirm the distribute keys in the target list of subpath. */ + void confirmDistributeKeys(StreamInfo* sinfo); + +protected: + /* Join method. */ + NodeTag m_joinmethod; + + /* Join type. */ + JoinType m_jointype; + + /* Save join type. */ + JoinType m_saveJointype; + + /* Cost work space for join. */ + JoinCostWorkspace* m_workspace; + + /* Special join info. */ + SpecialJoinInfo* m_sjinfo; + + /* Join facctors for semi and anti join. */ + SemiAntiJoinFactors* m_semifactors; + + /* Join clauses list. */ + List* m_joinClauses; + + /* Join restrict list. */ + List* m_joinRestrictinfo; + + /* path keys of the join. */ + List* m_pathkeys; + + /* Outer path of join. */ + Path* m_outerPath; + + /* Inner path of join. */ + Path* m_innerPath; + + /* Outer stream path created for join. */ + Path* m_outerStreamPath; + + /* Inner Stream path created for join. */ + Path* m_innerStreamPath; + + /* Outer rel info. */ + RelOptInfo* m_outerRel; + + /* Inner rel info. */ + RelOptInfo* m_innerRel; + + /* The set of required outer rels. */ + Relids m_requiredOuter; + + /* Resource owner for join generation. */ + ResourceOwner m_resourceOwner; + + /* The target distibution of node group. */ + Distribution* m_targetDistribution; + + /* The restrictinfo on which we can join directly. */ + List* m_rrinfoInner; + + /* The restrictinfo on which we can join directly. */ + List* m_rrinfoOuter; + + /* Distribute keys of inner stream. */ + List* m_distributeKeysInner; + + /* Distribute keys of outer stream. */ + List* m_distributeKeysOuter; + + /* Stream info pair. */ + StreamInfoPair* m_streamInfoPair; + + /* Stream info list for the join. */ + List* m_streamInfoList; + + /* Skew optimization info for join. */ + JoinSkewInfo* m_skewInfo; + + /* Skew mutiple for inner redistribute. */ + double m_multipleInner; + + /* Skew multiple for outer redistribute */ + double m_multipleOuter; + + /* Parallel degree for this join. */ + int m_dop; + + /* If the inner path is replicate. */ + bool m_replicateInner; + + /* If the outer path is replicate. */ + bool m_replicateOuter; + + /* If the inner path is rangelist. */ + bool m_rangelistInner; + + /* If the outer path is rangelist. */ + bool m_rangelistOuter; + + /* true if outer and inner path's rangelist boundary same. */ + bool m_sameBoundary; + + /* If we should redistribute the inner side. */ + bool m_redistributeInner; + + /* If we should redistribute the outer side. */ + bool m_redistributeOuter; + + /* If we can broadcast the inner side. */ + bool m_canBroadcastInner; + + /* If we can broadcast the outer side. */ + bool m_canBroadcastOuter; + + /* If we need shuffle the inner side. */ + bool m_needShuffleInner; + + /* If we need shuffle the outer side. */ + bool m_needShuffleOuter; +}; + +class HashJoinPathGen : public JoinPathGen { +public: + HashJoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrictlist, Relids required_outer, List* hashclauses); + + virtual ~HashJoinPathGen(); + + /* Create Hash join path and add it to path list. */ + void addHashJoinPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add hash join path to path list. */ + void addHashjoinPathToList(); + + /* Initial the cost of hash join. */ + void initialCostHashjoin(); + + /* Finalize the cost of hash join. */ + void finalCostHashjoin(HashPath* path, bool hasalternative); + + /* Create hash join path. */ + Path* createHashJoinPath(); + +private: + /* Hash clauses for hash join. */ + List* m_hashClauses; +}; + +class NestLoopPathGen : public JoinPathGen { +public: + NestLoopPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrictlist, List* pathkeys, Relids required_outer); + + virtual ~NestLoopPathGen(); + + /* Create nest loop path and add it to path list. */ + void addNestLoopPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add nest loop path to path list. */ + void addNestloopPathToList(); + + /* Initial the cost of nest loop join. */ + void initialCostNestloop(); + + /* Finalize the cost of nest loop join. */ + void finalCostNestloop(NestPath* path, bool hasalternative); + + /* Create nest loop path. */ + Path* createNestloopPath(); +}; + +class MergeJoinPathGen : public JoinPathGen { +public: + MergeJoinPathGen(PlannerInfo* root, RelOptInfo* joinrel, JoinType jointype, JoinType save_jointype, + SpecialJoinInfo* sjinfo, SemiAntiJoinFactors* semifactors, Path* outer_path, Path* inner_path, + List* restrict_clauses, List* pathkeys, Relids required_outer, List* mergeclauses, List* outersortkeys, + List* innersortkeys); + + virtual ~MergeJoinPathGen(); + + /* Create merge join path and add to path list. */ + void addMergeJoinPath(JoinCostWorkspace* workspace, Distribution* targetDistribution, int dop); + +private: + /* Add merge join path to path list. */ + void addMergejoinPathToList(); + + /* Initial the cost of merge join. */ + void initialCostMergejoin(); + + /* Finalize the cost of merge join. */ + void finalCostMergejoin(MergePath* path, bool hasalternative); + + /* Create mergejoin path. */ + Path* createMergejoinPath(); + +private: + /* Merge clauses for merge join. */ + List* m_mergeClauses; + + /* Sort key of inner path. */ + List* m_innerSortKeys; + + /* Sort key of outer path. */ + List* m_outerSortKeys; +}; + +#endif /* STREAMPATH_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/streamplan.h postgresql-hll-2.14/include/optimizer/streamplan.h --- postgresql-hll-2.14_old/include/optimizer/streamplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/streamplan.h 2020-12-12 17:06:43.349349354 +0800 @@ -0,0 +1,187 @@ +/* --------------------------------------------------------------------------------------- + * + * streamplan.h + * prototypes for stream plan. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/streamplan.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAMPLAN_H +#define STREAMPLAN_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "optimizer/stream_check.h" +#include "optimizer/stream_cost.h" +#include "optimizer/stream_util.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +#define NOTPLANSHIPPING_LENGTH 256 + +typedef struct ShippingInfo { + bool need_log; + char not_shipping_reason[NOTPLANSHIPPING_LENGTH]; +} ShippingInfo; + +#ifndef STREAMPLAN +#define STREAMPLAN +#endif + +#define IS_STREAM (u_sess->opt_cxt.is_stream && !IsConnFromCoord()) +/* Is stream come from datanode for the scene of gpu acceleration. */ +#define IS_STREAM_DATANODE (u_sess->opt_cxt.is_stream && IsConnFromDatanode()) +#define INITIAL_PLAN_NODE_ID 1 +#define INITIAL_PARENT_NODE_ID 0 +#define FLAG_SERIALIZED_PLAN 'Z' +#define IS_STREAM_PLAN (IS_PGXC_COORDINATOR && IS_STREAM && check_stream_support()) +#define STREAM_IS_LOCAL_NODE(type) (type == LOCAL_DISTRIBUTE || type == LOCAL_ROUNDROBIN || type == LOCAL_BROADCAST) +#define SET_DOP(dop) (dop > 1 ? dop : 1) + +#define RANDOM_SHIPPABLE (u_sess->opt_cxt.is_randomfunc_shippable && IS_STREAM_PLAN) + +extern THR_LOCAL ShippingInfo notshippinginfo; + +#define STREAM_RECURSIVECTE_SUPPORTED (IS_STREAM_PLAN && u_sess->attr.attr_sql.enable_stream_recursive) + +#define NO_FORM_CLAUSE(query) ((!query->jointree || !query->jointree->fromlist) && (!query->setOperations)) + +extern char* StreamTypeToString(StreamType type); + +extern char* SmpStreamTypeToString(SmpStreamType type); + +typedef struct StreamInfo { + StreamType type; /* Stream type. */ + Path* subpath; /* Subpath for this stream path. */ + List* stream_keys; /* Distribute keys for this stream. */ + List* ssinfo; /* Skew info list. */ + ParallelDesc smpDesc; /* Parallel execution info. */ + double multiple; /* Skew multiple for redistribution. */ +} StreamInfo; + +typedef struct StreamInfoPair { + StreamInfo inner_info; /* Stream info for inner side of join. */ + StreamInfo outer_info; /* Stream info for outer side of join. */ + uint32 skew_optimize; +} StreamInfoPair; + +typedef enum StreamReason { + STREAMREASON_NONE = 0x00, + STREAMREASON_DISTRIBUTEKEY = 0x01, + STREAMREASON_NODEGROUP = 0x02 +} StreamReason; + +typedef Stream VecStream; + +typedef struct { + short nodeid; + volatile uint32 seed; + volatile bool initialized; +} IdGen; + +typedef struct { + short nodeid; + volatile uint64 seed; + volatile bool initialized; +} Id64Gen; + +extern Id64Gen gt_queryId; + +extern Plan* create_stream_plan(PlannerInfo* root, StreamPath* best_path); +extern uint32 generate_unique_id(IdGen* gen); +extern uint64 generate_unique_id64(Id64Gen* gen); +extern void set_default_stream(); +extern void set_stream_off(); +extern bool stream_walker(Node* node, void* context); +extern contain_func_context init_contain_func_context(List* funcids, bool find_all = false); +extern int2vector* get_baserel_distributekey_no(Oid relid); +extern List* build_baserel_distributekey(RangeTblEntry* rte, int relindex); +extern char locator_type_join(char inner_locator_type, char outer_locator_type); +extern void ProcessRangeListJoinType(Path* joinPath, Path* outerPath, Path* innerPath); +extern Plan* make_simple_RemoteQuery( + Plan* lefttree, PlannerInfo* root, bool is_subplan, ExecNodes* target_exec_nodes = NULL); +extern void add_remote_subplan(PlannerInfo* root, RemoteQuery* result_node); +extern void build_remote_subplanOrSQL(PlannerInfo* root, RemoteQuery* result_node); +extern ExecNodes* get_random_data_nodes(char locatortype, Plan* plan); +extern void inherit_plan_locator_info(Plan* plan, Plan* subplan); +extern void inherit_path_locator_info(Path* path, Path* subpath); +extern Path* create_stream_path(PlannerInfo* root, RelOptInfo* rel, StreamType type, List* distribute_keys, + List* pathkeys, Path* subpath, double skew, Distribution* target_distribution = NULL, ParallelDesc* smp_desc = NULL, + List* ssinfo = NIL); +extern bool is_execute_on_coordinator(Plan* plan); +extern bool is_execute_on_datanodes(Plan* plan); +extern bool is_execute_on_allnodes(Plan* plan); +extern bool is_replicated_plan(Plan* plan); +extern bool is_hashed_plan(Plan* plan); +extern bool is_rangelist_plan(Plan* plan); +extern ExecNodes* stream_merge_exec_nodes(Plan* lefttree, Plan* righttree); +extern ExecNodes* get_all_data_nodes(char locatortype); +extern void pushdown_execnodes(Plan* plan, ExecNodes* exec_nodes, bool add_node = false, bool only_nodelist = false); +extern void stream_join_plan(PlannerInfo* root, Plan* join_plan, JoinPath* join_path); +extern NodeDefinition* get_all_datanodes_def(); +extern List* distributeKeyIndex(PlannerInfo* root, List* distributed_keys, List* targetlist); +extern List* make_groupcl_for_append(PlannerInfo* root, List* targetlist); +extern bool is_broadcast_stream(Stream* stream); +extern bool is_redistribute_stream(Stream* stream); +extern bool is_gather_stream(Stream* stream); +extern bool is_hybid_stream(Stream* stream); +extern void mark_distribute_setop(PlannerInfo* root, Node* node, bool isunionall, bool canDiskeyChange); + +extern void foreign_qual_context_init(foreign_qual_context* context); +extern void foreign_qual_context_free(foreign_qual_context* context); +extern bool is_foreign_expr(Node* node, foreign_qual_context* context); +extern char get_locator_type(Plan* plan); +extern bool is_compatible_type(Oid type1, Oid type2); +extern bool is_args_type_compatible(OpExpr* op_expr); +extern void materialize_remote_query(Plan* result_plan, bool* materialized, bool sort_to_store); +extern Var* locate_distribute_var(Expr* node); +extern bool add_hashfilter_for_replication(PlannerInfo* root, Plan* plan, List* distribute_keys); +extern bool IsModifyTableForDfsTable(Plan* AppendNode); +extern void confirm_parallel_info(Plan* plan, int dop); +extern bool trivial_subqueryscan(SubqueryScan* plan); +extern Plan* add_broacast_under_local_sort(PlannerInfo* root, PlannerInfo* subroot, Plan* plan); +extern void disable_unshipped_log(Query* query, shipping_context* context); +extern void output_unshipped_log(); +extern void stream_walker_context_init(shipping_context *context); + +/* Function for smp. */ +extern ParallelDesc* create_smpDesc(int consumer_dop, int producer_dop, SmpStreamType smp_type); +extern Plan* create_local_gather(Plan* plan); +extern Plan* create_local_redistribute(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple); +extern uint2* get_bucketmap_by_execnode(ExecNodes* exec_node, PlannedStmt* plannedstmt); +extern Oid get_oridinary_or_foreign_relid(List* rtable); +extern uint2* GetGlobalStreamBucketMap(PlannedStmt* planned_stmt); +extern int pickup_random_datanode_from_plan(Plan* plan); +extern bool canSeparateComputeAndStorageGroupForDelete(PlannerInfo* root); +extern bool isAllParallelized(List* subplans); +extern List* getSubPlan(Plan* node, List* subplans, List* initplans); +extern char* GetStreamTypeStrOf(StreamPath* path); +extern void GetHashTableCount(Query* parse, List* cteList, int* ccontext); +extern bool IsBucketmapNeeded(PlannedStmt* pstmt); + +/* Macros for LZ4 error handle */ +#define validate_LZ4_compress_result(res, module, hint) \ + do { \ + if (unlikely(res < 0)) { \ + /* should never happen, otherwise bugs inside LZ4 */ \ + ereport(ERROR, \ + (errcode(ERRCODE_DATA_CORRUPTED), \ + errmodule(module), \ + errmsg("%s : LZ4_compress_default failed trying to compress the data", hint))); \ + } else if (unlikely(res == 0)) { \ + /* should never happen, otherwise bugs inside LZ4_COMPRESSBOUND */ \ + ereport(ERROR, \ + (errcode(ERRCODE_DATA_CORRUPTED), \ + errmodule(module), \ + errmsg("%s : LZ4_compress_default destination buffer couldn't hold all the information", hint))); \ + } \ + } while (0) +#endif /* STREAMPLAN_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/stream_remove.h postgresql-hll-2.14/include/optimizer/stream_remove.h --- postgresql-hll-2.14_old/include/optimizer/stream_remove.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/stream_remove.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,12 @@ +/** + * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved. + * + */ +#ifndef STREAM_REMOVE_H +#define STREAM_REMOVE_H +#include "nodes/plannodes.h" +#include "optimizer/pgxcplan.h" +void delete_redundant_streams_of_append_plan(const Append *append); +void delete_redundant_streams_of_remotequery(RemoteQuery *top_plan); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/optimizer/stream_util.h postgresql-hll-2.14/include/optimizer/stream_util.h --- postgresql-hll-2.14_old/include/optimizer/stream_util.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/stream_util.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,85 @@ +/* --------------------------------------------------------------------------------------- + * + * stream_util.h + * prototypes for stream plan utilities. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/optimizer/stream_util.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STREAM_UTIL_H +#define STREAM_UTIL_H + +#include "catalog/pgxc_class.h" +#include "nodes/parsenodes.h" +#include "optimizer/pgxcplan.h" +#include "optimizer/pgxcship.h" +#include "optimizer/paths.h" +#include "pgxc/nodemgr.h" +#include "pgxc/pgxc.h" + +#define update_scan_list(root, lst, fromRTI, toRTI, rtiSize) \ + ((List*)update_scan_expr(root, (Node*)(lst), fromRTI, toRTI, rtiSize)) + +typedef struct { + Relids outer_relids; /* relids to judge if supplying parameters in subpath */ + Bitmapset *upper_params; + bool only_check_stream; /* if we should only check stream or also check paramterized path */ + bool under_materialize_all; /* if traversing under rescan-avoid materialize */ + bool has_stream; /* if there's stream node in the path */ + bool has_parameterized_path; /* If parameter is passed in the path */ + bool has_cstore_index_delta; /* if there is cstore index scan with delta data */ +} ContainStreamContext; + +typedef enum { + CPLN_DEFAULT = 0x00, + CPLN_ONE_WAY = 0x01, /* Search in one way without go into operators with many branchs */ + CPLN_NO_IGNORE_MATERIAL = 0x10 /* search all plannode, including material */ +} ContainPlanNodeMode; + +typedef struct { + bool collect_vars; + List* aggs; + List* vars; +} foreign_qual_context; + +/* the context for all subplans referenced by current node. */ +typedef struct { + List* org_subplans; /* subplans for planned stmt */ + List* org_initPlan; /* initPlan for planned stmt */ + List* subplan_plan_ids; /* subplans referenced by current node */ +} set_node_ref_subplan_context; + +typedef struct { + PlannerInfo* root; + Index* fromRTIs; + Index* toRTIs; + int rtiSize; +} update_scan_expr_context; + +extern void finalize_node_id(Plan* result_plan, int* plan_node_id, int* parent_node_id, int* num_streams, + int* num_plannodes, int* total_num_streams, int* max_push_sql_num, int* gather_count, List* subplans, + List* subroots, List** initplans, int* subplan_ids, bool is_under_stream, bool is_under_ctescan, + bool is_data_node_exec, bool is_read_only, NodeGroupInfoContext* node_group_info_context); +extern bool has_subplan( + Plan* result_plan, Plan* parent, ListCell* cell, bool is_left, List** initplans, bool is_search); +extern void stream_path_walker(Path* path, ContainStreamContext* context); +extern bool contain_special_plan_node(Plan* plan, NodeTag planTag, ContainPlanNodeMode mode = CPLN_DEFAULT); +extern void SerializePlan(Plan* node, PlannedStmt* planned_stmt, StringInfoData* str, int num_stream, int num_gather, + bool push_subplan = true); +extern char* DecompressSerializedPlan(const char* comp_plan_string, int cLen, int oLen); +extern char* CompressSerializedPlan(const char* plan_string, int* cLen); +extern List* contains_specified_func(Node* node, contain_func_context* context); +extern bool is_local_redistribute_needed(Plan* subplan); +extern bool foreign_qual_walker(Node* node, foreign_qual_context* context); +extern Oid get_hash_type(Oid type_in); +extern bool is_type_cast_hash_compatible(FuncExpr* func); +extern Plan* update_plan_refs(PlannerInfo* root, Plan* plan, Index* fromRTI, Index* toRTI, int rtiSize); +extern void set_node_ref_subplan_walker(Plan* result_plan, set_node_ref_subplan_context* context); +extern void StreamPlanWalker(PlannedStmt *pstmt, Plan *plan, bool *need); + +#endif /* STREAM_UTIL_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/optimizer/subselect.h postgresql-hll-2.14/include/optimizer/subselect.h --- postgresql-hll-2.14_old/include/optimizer/subselect.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/subselect.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * subselect.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/subselect.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SUBSELECT_H +#define SUBSELECT_H + +#include "nodes/plannodes.h" +#include "nodes/relation.h" + +#define SUBLINK_COUNTER 100 + +typedef struct +{ + List *aggFuncsList; +} fetch_agg_funcs_context; + +extern void SS_process_ctes(PlannerInfo* root); +extern JoinExpr* convert_ANY_sublink_to_join( + PlannerInfo* root, SubLink* sublink, bool under_not, Relids available_rels); +extern JoinExpr* convert_EXISTS_sublink_to_join( + PlannerInfo* root, SubLink* sublink, bool under_not, Relids available_rels); +extern Node* convert_EXPR_sublink_to_join(PlannerInfo* root, Node** jtlink1, Node* inout_quals, SubLink* sublink, + Relids *available_rels, Node* all_quals, const char *refname = NULL); + +extern void convert_OREXISTS_to_join( + PlannerInfo* root, BoolExpr* or_clause, SubLink* exists_sublink, Node** jtlink1, Relids available_rels1, bool isnull); +extern void convert_ORANY_to_join( + PlannerInfo* root, BoolExpr* or_clause, SubLink* any_sublink, Node** jtlink1, Relids available_rels); + +extern Node* convert_OREXPR_to_join(PlannerInfo* root, BoolExpr* or_clause, OpExpr* op_expr, SubLink* expr_sublink, + Node** jtlink1, Relids *available_rels); + +extern void convert_ORCLAUSE_to_join(PlannerInfo* root, BoolExpr* or_clause, Node** jtlink1, Relids *available_rels1); +extern Node* SS_replace_correlation_vars(PlannerInfo* root, Node* expr); +extern Node* SS_process_sublinks(PlannerInfo* root, Node* expr, bool isQual); +extern void SS_finalize_plan(PlannerInfo* root, Plan* plan, bool attach_initplans); +extern Param* SS_make_initplan_from_plan( + PlannerInfo* root, Plan* plan, Oid resulttype, int32 resulttypmod, Oid resultcollation); +extern Param* assign_nestloop_param_var(PlannerInfo* root, Var* var); +extern Param* assign_nestloop_param_placeholdervar(PlannerInfo* root, PlaceHolderVar* phv); +extern int assignPartIteratorParam(PlannerInfo* root); + +extern int SS_assign_special_param(PlannerInfo* root); +extern bool check_var_nonnullable(Query* query, Node* node); + +#ifdef STREAMPLAN +extern void convert_multi_count_distinct(PlannerInfo* root); +#endif +extern List* pull_sublink(Node* node, int flag, bool is_name, bool recurse = false); +extern List* pull_opExpr(Node* node); +#endif /* SUBSELECT_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/tlist.h postgresql-hll-2.14/include/optimizer/tlist.h --- postgresql-hll-2.14_old/include/optimizer/tlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/tlist.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * tlist.h + * prototypes for tlist.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/tlist.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TLIST_H +#define TLIST_H + +#include "optimizer/var.h" + +extern TargetEntry* tlist_member(Node* node, List* targetlist); +extern TargetEntry* tlist_member_ignore_relabel(Node* node, List* targetlist); +#ifdef STREAMPLAN +extern TargetEntry* tlist_member_except_aggref( + Node* node, List* targetlist, bool* nested_agg, bool* nested_relabeltype); +#endif + +extern List* flatten_tlist(List* tlist, PVCAggregateBehavior aggbehavior, PVCPlaceHolderBehavior phbehavior); +extern List* add_to_flat_tlist(List* tlist, List* exprs); + +extern List* get_tlist_exprs(List* tlist, bool includeJunk); +extern bool tlist_same_datatypes(List* tlist, List* colTypes, bool junkOK); +extern bool tlist_same_collations(List* tlist, List* colCollations, bool junkOK); + +extern TargetEntry* get_sortgroupref_tle(Index sortref, List* targetList, bool report_error = true); +extern TargetEntry* get_sortgroupclause_tle(SortGroupClause* sgClause, List* targetList, bool report_error = true); +extern Node* get_sortgroupclause_expr(SortGroupClause* sgClause, List* targetList); +extern List* get_sortgrouplist_exprs(List* sgClauses, List* targetList); + +extern SortGroupClause* get_sortgroupref_clause(Index sortref, List* clauses); +extern Oid* extract_grouping_ops(List* groupClause); +extern AttrNumber* extract_grouping_cols(List* groupClause, List* tlist); +extern bool grouping_is_sortable(List* groupClause); +extern bool grouping_is_hashable(List* groupClause); +extern bool grouping_is_distributable(List* groupClause, List* targetlist); +extern int get_grouping_column_index(Query* parse, TargetEntry* tle, List* groupClause); +extern List* make_agg_var_list(PlannerInfo* root, List* tlist, List** duplicate_tlist); +extern void get_tlist_group_vars_split(Query* parse, List* tlist, List** group_cols, List** non_group_cols); +extern List* get_dependency_var_list(Query* parse, List* group_cols, List* non_group_vars); +extern bool var_from_dependency_rel(Query* parse, Var* var, List* dep_oids); +extern bool var_from_sublink_pulluped(Query *parse, Var *var); +#endif /* TLIST_H */ diff -uprN postgresql-hll-2.14_old/include/optimizer/var.h postgresql-hll-2.14/include/optimizer/var.h --- postgresql-hll-2.14_old/include/optimizer/var.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/optimizer/var.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,80 @@ +/* ------------------------------------------------------------------------- + * + * var.h + * prototypes for optimizer/util/var.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/var.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VAR_H +#define VAR_H + +#include "nodes/relation.h" + +typedef enum { + PVC_REJECT_AGGREGATES, /* throw error if Aggref found */ + PVC_INCLUDE_AGGREGATES, /* include Aggrefs in output list */ + PVC_INCLUDE_AGGREGATES_OR_WINAGGS, + PVC_RECURSE_AGGREGATES /* recurse into Aggref arguments */ +} PVCAggregateBehavior; + +typedef enum { + PVC_REJECT_PLACEHOLDERS, /* throw error if PlaceHolderVar found */ + PVC_INCLUDE_PLACEHOLDERS, /* include PlaceHolderVars in output list */ + PVC_RECURSE_PLACEHOLDERS /* recurse into PlaceHolderVar arguments */ +} PVCPlaceHolderBehavior; + +/* + * When we evaluate distinct number and biase of exprs, we meet some special + * exprs that hard to give an accurate estimation + */ +typedef enum { + PVC_REJECT_SPECIAL_EXPR, /* skip if special exprs found */ + PVC_INCLUDE_SPECIAL_EXPR, /* include special nodes in output list */ + PVC_RECURSE_SPECIAL_EXPR /* recurse into special expr nodes */ +} PVCSPExprBehavior; + +/* + * Used by replace_node_clause as behavior flag. + * To mark wheather (1) go into Aggref, (2) copy non-leaf nodes, + * (3) only replace first target we meet. + */ +typedef enum { + RNC_NONE = 0x00u, + RNC_RECURSE_AGGREF = 0x01u, + RNC_COPY_NON_LEAF_NODES = 0x02u, + RNC_REPLACE_FIRST_ONLY = 0x04u +} ReplaceNodeClauseBehavior; + +extern Relids pull_varnos(Node* node, int level = 0, bool isSkip = false); +extern Relids pull_varnos_of_level(Node *node, int levelsup); +extern void pull_varattnos(Node* node, Index varno, Bitmapset** varattnos); +extern List *pull_vars_of_level(Node *node, int levelsup); +extern bool contain_var_clause(Node* node); +extern bool contain_vars_of_level(Node* node, int levelsup); +extern int locate_var_of_level(Node* node, int levelsup); +extern int locate_var_of_relation(Node* node, int relid, int levelsup); +extern int find_minimum_var_level(Node* node); +extern List* pull_var_clause(Node* node, PVCAggregateBehavior aggbehavior, PVCPlaceHolderBehavior phbehavior, + PVCSPExprBehavior spbehavior = PVC_RECURSE_SPECIAL_EXPR, bool includeUpperVars = false, + bool includeUpperAggrefs = false); +extern Node* flatten_join_alias_vars(PlannerInfo* root, Node* node); +extern Node* replace_node_clause_for_equality(Node* clause, List* src_list, Node* dest); +extern Node* replace_node_clause(Node* node, Node* src_list, Node* dest_list, uint32 rncbehavior); +extern bool check_node_clause(Node* clause, Node* node); +extern bool contain_vars_of_level_or_above(Node* node, int levelsup); + +extern bool check_param_clause(Node* clause); +extern Bitmapset* collect_param_clause(Node* clause); +extern bool check_param_expr(Node* node); +extern List* check_random_expr(Node* node); + +extern List* check_subplan_expr(Node* node, bool recurseSubPlan = false); +extern bool check_varno(Node* qual, int varno, int varlevelsup); +extern List* check_vartype(Node* node); +#endif /* VAR_H */ diff -uprN postgresql-hll-2.14_old/include/parser/analyze.h postgresql-hll-2.14/include/parser/analyze.h --- postgresql-hll-2.14_old/include/parser/analyze.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/analyze.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,94 @@ +/* ------------------------------------------------------------------------- + * + * analyze.h + * parse analysis for optimizable statements + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/analyze.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ANALYZE_H +#define ANALYZE_H + +#ifndef FRONTEND_PARSER +#include "parser/parse_node.h" +#include "utils/plancache.h" + +extern const char* const ANALYZE_TEMP_TABLE_PREFIX; + +/* Hook for plugins to get control at end of parse analysis */ +typedef void (*post_parse_analyze_hook_type)(ParseState* pstate, Query* query); + +extern THR_LOCAL PGDLLIMPORT post_parse_analyze_hook_type post_parse_analyze_hook; + +extern Query* parse_analyze(Node* parseTree, const char* sourceText, Oid* paramTypes, int numParams, + bool isFirstNode = true, bool isCreateView = false); +extern Query* parse_analyze_varparams(Node* parseTree, const char* sourceText, Oid** paramTypes, int* numParams); + +extern Query* parse_sub_analyze(Node* parseTree, ParseState* parentParseState, CommonTableExpr* parentCTE, + bool locked_from_parent, bool resolve_unknowns); + +extern List* transformInsertRow(ParseState* pstate, List* exprlist, List* stmtcols, List* icolumns, List* attrnos); +extern Query* transformTopLevelStmt( + ParseState* pstate, Node* parseTree, bool isFirstNode = true, bool isCreateView = false); +extern Query* transformStmt(ParseState* pstate, Node* parseTree, bool isFirstNode = true, bool isCreateView = false); + +extern bool analyze_requires_snapshot(Node* parseTree); + +extern void CheckSelectLocking(Query* qry); +extern void applyLockingClause(Query* qry, Index rtindex, bool forUpdate, bool noWait, bool pushedDown); +#ifdef ENABLE_MOT +extern void CheckTablesStorageEngine(Query* qry, StorageEngineType* type); +extern bool CheckMotIndexedColumnUpdate(Query* qry); + +typedef struct RTEDetectorContext { + bool isMotTable; + bool isPageTable; + List* queryNodes; + int sublevelsUp; +} RTEDetectorContext; + +typedef struct UpdateDetectorContext { + bool isIndexedColumnUpdate; + List* queryNodes; + int sublevelsUp; +} UpdateDetectorContext; +#endif + +/* Record the rel name and corresponding columan name info */ +typedef struct RelColumnInfo { + char* relname; + List* colnames; +} RelColumnInfo; + +typedef struct PlusJoinRTEItem { + RangeTblEntry* rte; /* The RTE that the column referennce */ + bool hasplus; /* Does the Expr contains ''(+)" ? */ +} PlusJoinRTEItem; + +typedef struct OperatorPlusProcessContext { + List* jointerms; /* List of Jointerm */ + bool contain_plus_outerjoin; + ParseState* ps; /* ParseState of Current level */ + Node** whereClause; + bool in_orclause; + bool contain_joinExpr; +} OperatorPlusProcessContext; + +extern void transformOperatorPlus(ParseState* pstate, Node** whereClause); +extern bool IsColumnRefPlusOuterJoin(const ColumnRef* cf); +extern PlusJoinRTEItem* makePlusJoinRTEItem(RangeTblEntry* rte, bool hasplus); +extern void setIgnorePlusFlag(ParseState* pstate, bool ignore); +extern void resetOperatorPlusFlag(); + +extern void fixResTargetNameWithTableNameRef(Relation rd, RangeVar* rel, ResTarget* res); +extern void fixResTargetListWithTableNameRef(Relation rd, RangeVar* rel, List* clause_list); +#endif /* !FRONTEND_PARSER */ + +extern bool getOperatorPlusFlag(); + +#endif /* ANALYZE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/backslash_quotes.h postgresql-hll-2.14/include/parser/backslash_quotes.h --- postgresql-hll-2.14_old/include/parser/backslash_quotes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/backslash_quotes.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * backslash_quotes.h + * + * IDENTIFICATION + * src\include\parser\backslash_quotes.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +typedef enum { + BACKSLASH_QUOTE_OFF, + BACKSLASH_QUOTE_ON, + BACKSLASH_QUOTE_SAFE_ENCODING +} BackslashQuoteType; diff -uprN postgresql-hll-2.14_old/include/parser/gram.hpp postgresql-hll-2.14/include/parser/gram.hpp --- postgresql-hll-2.14_old/include/parser/gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/gram.hpp 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,753 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_BASE_YY_GRAM_HPP_INCLUDED +# define YY_BASE_YY_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int base_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + IDENT = 258, + FCONST = 259, + SCONST = 260, + BCONST = 261, + XCONST = 262, + Op = 263, + CmpOp = 264, + COMMENTSTRING = 265, + ICONST = 266, + PARAM = 267, + TYPECAST = 268, + ORA_JOINOP = 269, + DOT_DOT = 270, + COLON_EQUALS = 271, + PARA_EQUALS = 272, + ABORT_P = 273, + ABSOLUTE_P = 274, + ACCESS = 275, + ACCOUNT = 276, + ACTION = 277, + ADD_P = 278, + ADMIN = 279, + AFTER = 280, + AGGREGATE = 281, + ALGORITHM = 282, + ALL = 283, + ALSO = 284, + ALTER = 285, + ALWAYS = 286, + ANALYSE = 287, + ANALYZE = 288, + AND = 289, + ANY = 290, + APP = 291, + ARRAY = 292, + AS = 293, + ASC = 294, + ASSERTION = 295, + ASSIGNMENT = 296, + ASYMMETRIC = 297, + AT = 298, + ATTRIBUTE = 299, + AUDIT = 300, + AUTHID = 301, + AUTHORIZATION = 302, + AUTOEXTEND = 303, + AUTOMAPPED = 304, + BACKWARD = 305, + BARRIER = 306, + BEFORE = 307, + BEGIN_NON_ANOYBLOCK = 308, + BEGIN_P = 309, + BETWEEN = 310, + BIGINT = 311, + BINARY = 312, + BINARY_DOUBLE = 313, + BINARY_INTEGER = 314, + BIT = 315, + BLOB_P = 316, + BOGUS = 317, + BOOLEAN_P = 318, + BOTH = 319, + BUCKETS = 320, + BY = 321, + BYTEAWITHOUTORDER = 322, + BYTEAWITHOUTORDERWITHEQUAL = 323, + CACHE = 324, + CALL = 325, + CALLED = 326, + CASCADE = 327, + CASCADED = 328, + CASE = 329, + CAST = 330, + CATALOG_P = 331, + CHAIN = 332, + CHAR_P = 333, + CHARACTER = 334, + CHARACTERISTICS = 335, + CHECK = 336, + CHECKPOINT = 337, + CLASS = 338, + CLEAN = 339, + CLIENT = 340, + CLIENT_MASTER_KEY = 341, + CLIENT_MASTER_KEYS = 342, + CLOB = 343, + CLOSE = 344, + CLUSTER = 345, + COALESCE = 346, + COLLATE = 347, + COLLATION = 348, + COLUMN = 349, + COLUMN_ARGS = 350, + COLUMN_ENCRYPTION_KEY = 351, + COLUMN_ENCRYPTION_KEYS = 352, + COLUMN_FUNCTION = 353, + COMMENT = 354, + COMMENTS = 355, + COMMIT = 356, + COMMITTED = 357, + COMPACT = 358, + COMPATIBLE_ILLEGAL_CHARS = 359, + COMPLETE = 360, + COMPRESS = 361, + CONCURRENTLY = 362, + CONDITION = 363, + CONFIGURATION = 364, + CONNECTION = 365, + CONSTRAINT = 366, + CONSTRAINTS = 367, + CONTENT_P = 368, + CONTINUE_P = 369, + CONTQUERY = 370, + CONVERSION_P = 371, + COORDINATOR = 372, + COORDINATORS = 373, + COPY = 374, + COST = 375, + CREATE = 376, + CROSS = 377, + CSV = 378, + CUBE = 379, + CURRENT_P = 380, + CURRENT_CATALOG = 381, + CURRENT_DATE = 382, + CURRENT_ROLE = 383, + CURRENT_SCHEMA = 384, + CURRENT_TIME = 385, + CURRENT_TIMESTAMP = 386, + CURRENT_USER = 387, + CURSOR = 388, + CYCLE = 389, + DATA_P = 390, + DATABASE = 391, + DATAFILE = 392, + DATANODE = 393, + DATANODES = 394, + DATATYPE_CL = 395, + DATE_P = 396, + DATE_FORMAT_P = 397, + DAY_P = 398, + DBCOMPATIBILITY_P = 399, + DEALLOCATE = 400, + DEC = 401, + DECIMAL_P = 402, + DECLARE = 403, + DECODE = 404, + DEFAULT = 405, + DEFAULTS = 406, + DEFERRABLE = 407, + DEFERRED = 408, + DEFINER = 409, + DELETE_P = 410, + DELIMITER = 411, + DELIMITERS = 412, + DELTA = 413, + DELTAMERGE = 414, + DESC = 415, + DETERMINISTIC = 416, + DICTIONARY = 417, + DIRECT = 418, + DIRECTORY = 419, + DISABLE_P = 420, + DISCARD = 421, + DISTINCT = 422, + DISTRIBUTE = 423, + DISTRIBUTION = 424, + DO = 425, + DOCUMENT_P = 426, + DOMAIN_P = 427, + DOUBLE_P = 428, + DROP = 429, + DUPLICATE = 430, + DISCONNECT = 431, + EACH = 432, + ELASTIC = 433, + ELSE = 434, + ENABLE_P = 435, + ENCODING = 436, + ENCRYPTED = 437, + ENCRYPTED_VALUE = 438, + ENCRYPTION = 439, + ENCRYPTION_TYPE = 440, + END_P = 441, + ENFORCED = 442, + ENUM_P = 443, + ERRORS = 444, + ESCAPE = 445, + EOL = 446, + ESCAPING = 447, + EVERY = 448, + EXCEPT = 449, + EXCHANGE = 450, + EXCLUDE = 451, + EXCLUDED = 452, + EXCLUDING = 453, + EXCLUSIVE = 454, + EXECUTE = 455, + EXISTS = 456, + EXPIRED_P = 457, + EXPLAIN = 458, + EXTENSION = 459, + EXTERNAL = 460, + EXTRACT = 461, + FALSE_P = 462, + FAMILY = 463, + FAST = 464, + FENCED = 465, + FETCH = 466, + FILEHEADER_P = 467, + FILL_MISSING_FIELDS = 468, + FILTER = 469, + FIRST_P = 470, + FIXED_P = 471, + FLOAT_P = 472, + FOLLOWING = 473, + FOR = 474, + FORCE = 475, + FOREIGN = 476, + FORMATTER = 477, + FORWARD = 478, + FREEZE = 479, + FROM = 480, + FULL = 481, + FUNCTION = 482, + FUNCTIONS = 483, + GLOBAL = 484, + GLOBAL_FUNCTION = 485, + GRANT = 486, + GRANTED = 487, + GREATEST = 488, + GROUP_P = 489, + GROUPING_P = 490, + HANDLER = 491, + HAVING = 492, + HDFSDIRECTORY = 493, + HEADER_P = 494, + HOLD = 495, + HOUR_P = 496, + IDENTIFIED = 497, + IDENTITY_P = 498, + IF_P = 499, + IGNORE_EXTRA_DATA = 500, + ILIKE = 501, + IMMEDIATE = 502, + IMMUTABLE = 503, + IMPLICIT_P = 504, + IN_P = 505, + INCLUDE = 506, + INCLUDING = 507, + INCREMENT = 508, + INCREMENTAL = 509, + INDEX = 510, + INDEXES = 511, + INHERIT = 512, + INHERITS = 513, + INITIAL_P = 514, + INITIALLY = 515, + INITRANS = 516, + INLINE_P = 517, + INNER_P = 518, + INOUT = 519, + INPUT_P = 520, + INSENSITIVE = 521, + INSERT = 522, + INSTEAD = 523, + INT_P = 524, + INTEGER = 525, + INTERNAL = 526, + INTERSECT = 527, + INTERVAL = 528, + INTO = 529, + INVOKER = 530, + IP = 531, + IS = 532, + ISNULL = 533, + ISOLATION = 534, + JOIN = 535, + KEY = 536, + KILL = 537, + KEY_PATH = 538, + KEY_STORE = 539, + LABEL = 540, + LANGUAGE = 541, + LARGE_P = 542, + LAST_P = 543, + LC_COLLATE_P = 544, + LC_CTYPE_P = 545, + LEADING = 546, + LEAKPROOF = 547, + LEAST = 548, + LESS = 549, + LEFT = 550, + LEVEL = 551, + LIKE = 552, + LIMIT = 553, + LIST = 554, + LISTEN = 555, + LOAD = 556, + LOCAL = 557, + LOCALTIME = 558, + LOCALTIMESTAMP = 559, + LOCATION = 560, + LOCK_P = 561, + LOG_P = 562, + LOGGING = 563, + LOGIN_ANY = 564, + LOGIN_FAILURE = 565, + LOGIN_SUCCESS = 566, + LOGOUT = 567, + LOOP = 568, + MAPPING = 569, + MASKING = 570, + MASTER = 571, + MATCH = 572, + MATERIALIZED = 573, + MATCHED = 574, + MAXEXTENTS = 575, + MAXSIZE = 576, + MAXTRANS = 577, + MAXVALUE = 578, + MERGE = 579, + MINUS_P = 580, + MINUTE_P = 581, + MINVALUE = 582, + MINEXTENTS = 583, + MODE = 584, + MODIFY_P = 585, + MONTH_P = 586, + MOVE = 587, + MOVEMENT = 588, + NAME_P = 589, + NAMES = 590, + NATIONAL = 591, + NATURAL = 592, + NCHAR = 593, + NEXT = 594, + NLSSORT = 595, + NO = 596, + NOCOMPRESS = 597, + NOCYCLE = 598, + NODE = 599, + NOLOGGING = 600, + NOMAXVALUE = 601, + NOMINVALUE = 602, + NONE = 603, + NOT = 604, + NOTHING = 605, + NOTIFY = 606, + NOTNULL = 607, + NOWAIT = 608, + NULL_P = 609, + NULLIF = 610, + NULLS_P = 611, + NUMBER_P = 612, + NUMERIC = 613, + NUMSTR = 614, + NVARCHAR2 = 615, + NVL = 616, + OBJECT_P = 617, + OF = 618, + OFF = 619, + OFFSET = 620, + OIDS = 621, + ON = 622, + ONLY = 623, + OPERATOR = 624, + OPTIMIZATION = 625, + OPTION = 626, + OPTIONS = 627, + OR = 628, + ORDER = 629, + OUT_P = 630, + OUTER_P = 631, + OVER = 632, + OVERLAPS = 633, + OVERLAY = 634, + OWNED = 635, + OWNER = 636, + PACKAGE = 637, + PARSER = 638, + PARTIAL = 639, + PARTITION = 640, + PARTITIONS = 641, + PASSING = 642, + PASSWORD = 643, + PCTFREE = 644, + PER_P = 645, + PERCENT = 646, + PERFORMANCE = 647, + PERM = 648, + PLACING = 649, + PLAN = 650, + PLANS = 651, + POLICY = 652, + POSITION = 653, + POOL = 654, + PRECEDING = 655, + PRECISION = 656, + PREFERRED = 657, + PREFIX = 658, + PRESERVE = 659, + PREPARE = 660, + PREPARED = 661, + PRIMARY = 662, + PRIVATE = 663, + PRIOR = 664, + PRIVILEGES = 665, + PRIVILEGE = 666, + PROCEDURAL = 667, + PROCEDURE = 668, + PROFILE = 669, + QUERY = 670, + QUOTE = 671, + RANDOMIZED = 672, + RANGE = 673, + RAW = 674, + READ = 675, + REAL = 676, + REASSIGN = 677, + REBUILD = 678, + RECHECK = 679, + RECURSIVE = 680, + REDISANYVALUE = 681, + REF = 682, + REFERENCES = 683, + REFRESH = 684, + REINDEX = 685, + REJECT_P = 686, + RELATIVE_P = 687, + RELEASE = 688, + RELOPTIONS = 689, + REMOTE_P = 690, + REMOVE = 691, + RENAME = 692, + REPEATABLE = 693, + REPLACE = 694, + REPLICA = 695, + RESET = 696, + RESIZE = 697, + RESOURCE = 698, + RESTART = 699, + RESTRICT = 700, + RETURN = 701, + RETURNING = 702, + RETURNS = 703, + REUSE = 704, + REVOKE = 705, + RIGHT = 706, + ROLE = 707, + ROLES = 708, + ROLLBACK = 709, + ROLLUP = 710, + ROW = 711, + ROWNUM = 712, + ROWS = 713, + RULE = 714, + SAVEPOINT = 715, + SCHEMA = 716, + SCROLL = 717, + SEARCH = 718, + SECOND_P = 719, + SECURITY = 720, + SELECT = 721, + SEQUENCE = 722, + SEQUENCES = 723, + SERIALIZABLE = 724, + SERVER = 725, + SESSION = 726, + SESSION_USER = 727, + SET = 728, + SETS = 729, + SETOF = 730, + SHARE = 731, + SHIPPABLE = 732, + SHOW = 733, + SHUTDOWN = 734, + SIMILAR = 735, + SIMPLE = 736, + SIZE = 737, + SLICE = 738, + SMALLDATETIME = 739, + SMALLDATETIME_FORMAT_P = 740, + SMALLINT = 741, + SNAPSHOT = 742, + SOME = 743, + SOURCE_P = 744, + SPACE = 745, + SPILL = 746, + SPLIT = 747, + STABLE = 748, + STANDALONE_P = 749, + START = 750, + STATEMENT = 751, + STATEMENT_ID = 752, + STATISTICS = 753, + STDIN = 754, + STDOUT = 755, + STORAGE = 756, + STORE_P = 757, + STREAM = 758, + STRICT_P = 759, + STRIP_P = 760, + SUBSTRING = 761, + SYMMETRIC = 762, + SYNONYM = 763, + SYSDATE = 764, + SYSID = 765, + SYSTEM_P = 766, + SYS_REFCURSOR = 767, + TABLE = 768, + TABLES = 769, + TABLESAMPLE = 770, + TABLESPACE = 771, + TEMP = 772, + TEMPLATE = 773, + TEMPORARY = 774, + TEXT_P = 775, + THAN = 776, + THEN = 777, + TIME = 778, + TIME_FORMAT_P = 779, + TIMESTAMP = 780, + TIMESTAMP_FORMAT_P = 781, + TIMESTAMPDIFF = 782, + TINYINT = 783, + TO = 784, + TRAILING = 785, + TRANSACTION = 786, + TREAT = 787, + TRIGGER = 788, + TRIM = 789, + TRUE_P = 790, + TRUNCATE = 791, + TRUSTED = 792, + TSFIELD = 793, + TSTAG = 794, + TSTIME = 795, + TYPE_P = 796, + TYPES_P = 797, + UNBOUNDED = 798, + UNCOMMITTED = 799, + UNENCRYPTED = 800, + UNION = 801, + UNIQUE = 802, + UNKNOWN = 803, + UNLIMITED = 804, + UNLISTEN = 805, + UNLOCK = 806, + UNLOGGED = 807, + UNTIL = 808, + UNUSABLE = 809, + UPDATE = 810, + USER = 811, + USING = 812, + VACUUM = 813, + VALID = 814, + VALIDATE = 815, + VALIDATION = 816, + VALIDATOR = 817, + VALUE_P = 818, + VALUES = 819, + VARCHAR = 820, + VARCHAR2 = 821, + VARIADIC = 822, + VARRAY = 823, + VARYING = 824, + VCGROUP = 825, + VERBOSE = 826, + VERIFY = 827, + VERSION_P = 828, + VIEW = 829, + VOLATILE = 830, + WEAK = 831, + WHEN = 832, + WHERE = 833, + WHITESPACE_P = 834, + WINDOW = 835, + WITH = 836, + WITHIN = 837, + WITHOUT = 838, + WORK = 839, + WORKLOAD = 840, + WRAPPER = 841, + WRITE = 842, + XML_P = 843, + XMLATTRIBUTES = 844, + XMLCONCAT = 845, + XMLELEMENT = 846, + XMLEXISTS = 847, + XMLFOREST = 848, + XMLPARSE = 849, + XMLPI = 850, + XMLROOT = 851, + XMLSERIALIZE = 852, + YEAR_P = 853, + YES_P = 854, + ZONE = 855, + NULLS_FIRST = 856, + NULLS_LAST = 857, + WITH_TIME = 858, + INCLUDING_ALL = 859, + RENAME_PARTITION = 860, + PARTITION_FOR = 861, + ADD_PARTITION = 862, + DROP_PARTITION = 863, + REBUILD_PARTITION = 864, + MODIFY_PARTITION = 865, + NOT_ENFORCED = 866, + VALID_BEGIN = 867, + DECLARE_CURSOR = 868, + PARTIAL_EMPTY_PREC = 869, + POSTFIXOP = 870, + UMINUS = 871 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 225 "gram.y" + + core_YYSTYPE core_yystype; + /* these fields must match core_YYSTYPE: */ + int ival; + char *str; + const char *keyword; + + char chr; + bool boolean; + JoinType jtype; + DropBehavior dbehavior; + OnCommitAction oncommit; + List *list; + Node *node; + Value *value; + ObjectType objtype; + TypeName *typnam; + FunctionParameter *fun_param; + FunctionParameterMode fun_param_mode; + FuncWithArgs *funwithargs; + DefElem *defelt; + SortBy *sortby; + WindowDef *windef; + JoinExpr *jexpr; + IndexElem *ielem; + Alias *alias; + RangeVar *range; + IntoClause *into; + WithClause *with; + A_Indices *aind; + ResTarget *target; + struct PrivTarget *privtarget; + AccessPriv *accesspriv; + InsertStmt *istmt; + VariableSetStmt *vsetstmt; +/* PGXC_BEGIN */ + DistributeBy *distby; + PGXCSubCluster *subclus; +/* PGXC_END */ + ForeignPartState *foreignpartby; + MergeWhenClause *mergewhen; + UpsertClause *upsert; + EncryptionType algtype; + + +/* Line 2058 of yacc.c */ +#line 719 "gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int base_yyparse (void *YYPARSE_PARAM); +#else +int base_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int base_yyparse (core_yyscan_t yyscanner); +#else +int base_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_BASE_YY_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/parser/gramparse.h postgresql-hll-2.14/include/parser/gramparse.h --- postgresql-hll-2.14_old/include/parser/gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/gramparse.h 2020-12-12 17:06:43.350349367 +0800 @@ -0,0 +1,165 @@ +/* ------------------------------------------------------------------------- + * + * gramparse.h + * Shared definitions for the "raw" parser (flex and bison phases only) + * + * NOTE: this file is only meant to be included in the core parsing files, + * ie, parser.c, gram.y, scan.l, and keywords.c. Definitions that are needed + * outside the core parser should be in parser.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/gramparse.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GRAMPARSE_H +#define GRAMPARSE_H + +#include "parser/scanner.h" + +/* + * NB: include gram.h only AFTER including scanner.h, because scanner.h + * is what #defines YYLTYPE. + */ + +#ifndef FRONTEND_PARSER +#ifdef PARSE_HINT_h +#include "parser/hint_gram.hpp" +#else +#include "parser/gram.hpp" +#endif +#else +#include "nodes/value.h" +#include "frontend_parser/gram.hpp" +#endif /* FRONTEND_PARSER */ + +/* When dealing with DECLARE foo CURSOR case, we must look ahead 2 token after DECLARE to meet CURSOR */ +#define MAX_LOOKAHEAD_NUM 2 + +/* + * The YY_EXTRA data that a flex scanner allows us to pass around. Private + * state needed for raw parsing/lexing goes here. + */ +typedef struct base_yy_extra_type { + /* + * Fields used by the core scanner. + */ + core_yy_extra_type core_yy_extra; + + /* + * State variables for base_yylex(). + */ + int lookahead_num; /* lookahead num. Currently can be:0,1,2 */ + int lookahead_token[MAX_LOOKAHEAD_NUM]; /* token lookahead type */ + core_YYSTYPE lookahead_yylval[MAX_LOOKAHEAD_NUM]; /* yylval for lookahead token */ + YYLTYPE lookahead_yylloc[MAX_LOOKAHEAD_NUM]; /* yylloc for lookahead token */ + + /* + * State variables that belong to the grammar. + */ + List* parsetree; /* final parse result is delivered here */ +} base_yy_extra_type; + +#ifdef FRONTEND_PARSER +typedef struct fe_base_yy_extra_type { + /* + * Fields used by the core scanner. + */ + fe_core_yy_extra_type core_yy_extra; + + /* + * State variables for base_yylex(). + */ + int lookahead_num; /* lookahead num. Currently can be:0,1,2 */ + int lookahead_token[MAX_LOOKAHEAD_NUM]; /* token lookahead type */ + core_YYSTYPE lookahead_yylval[MAX_LOOKAHEAD_NUM]; /* yylval for lookahead token */ + YYLTYPE lookahead_yylloc[MAX_LOOKAHEAD_NUM]; /* yylloc for lookahead token */ + + /* + * State variables that belong to the grammar. + */ + List *parsetree; /* final parse result is delivered here */ +} fe_base_yy_extra_type; + +#endif /* FRONTEND_PARSER */ + +typedef struct hint_yy_extra_type { + /* + * The string the scanner is physically scanning. We keep this mainly so + * that we can cheaply compute the offset of the current token (yytext). + */ + char* scanbuf; + Size scanbuflen; + + /* + * The keyword list to use. + */ + const ScanKeyword* keywords; + int num_keywords; + + /* + * literalbuf is used to accumulate literal values when multiple rules are + * needed to parse a single literal. Call startlit() to reset buffer to + * empty, addlit() to add text. NOTE: the string in literalbuf is NOT + * necessarily null-terminated, but there always IS room to add a trailing + * null at offset literallen. We store a null only when we need it. + */ + char* literalbuf; /* palloc'd expandable buffer */ + int literallen; /* actual current string length */ + int literalalloc; /* current allocated buffer size */ + + int xcdepth; /* depth of nesting in slash-star comments */ + char* dolqstart; /* current $foo$ quote start string */ + + /* first part of UTF16 surrogate pair for Unicode escapes */ + int32 utf16_first_part; + + /* state variables for literal-lexing warnings */ + bool warn_on_first_escape; + bool saw_non_ascii; + bool ident_quoted; + bool warnOnTruncateIdent; + + /* record the message need by multi-query. */ + List* query_string_locationlist; /* record the end location of each single query */ + bool in_slash_proc_body; /* check whether it's in a slash proc body */ + int paren_depth; /* record the current depth in the '(' and ')' */ + bool is_createstmt; /* check whether it's a create statement. */ + bool is_hint_str; /* current identifier is in hint comment string */ + List* parameter_list; /* placeholder parameter list */ +} hint_yy_extra_type; + +#ifdef PARSE_HINT_h +extern int yylex(YYSTYPE* lvalp, yyscan_t yyscanner); +extern int yyparse(yyscan_t yyscanner); +#else + +/* + * In principle we should use yyget_extra() to fetch the yyextra field + * from a yyscanner struct. However, flex always puts that field first, + * and this is sufficiently performance-critical to make it seem worth + * cheating a bit to use an inline macro. + */ +#define pg_yyget_extra(yyscanner) (*((base_yy_extra_type**)(yyscanner))) + +#ifdef FRONTEND_PARSER +#define fe_pg_yyget_extra(yyscanner) (*((fe_base_yy_extra_type **) (yyscanner))) +#endif /* FRONTEND_PARSER */ + +/* from parser.c */ +extern int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner); + +/* from gram.y */ +extern void parser_init(base_yy_extra_type* yyext); +extern int base_yyparse(core_yyscan_t yyscanner); + +#ifdef FRONTEND_PARSER +extern void fe_parser_init(fe_base_yy_extra_type *yyext); +#endif /* FRONTEND_PARSER */ + +#endif + +#endif /* GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/hint_gram.hpp postgresql-hll-2.14/include/parser/hint_gram.hpp --- postgresql-hll-2.14_old/include/parser/hint_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/hint_gram.hpp 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,113 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_YY_HINT_GRAM_HPP_INCLUDED +# define YY_YY_HINT_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + IDENT = 258, + FCONST = 259, + SCONST = 260, + BCONST = 261, + XCONST = 262, + ICONST = 263, + NestLoop_P = 264, + MergeJoin_P = 265, + HashJoin_P = 266, + No_P = 267, + Leading_P = 268, + Rows_P = 269, + Broadcast_P = 270, + Redistribute_P = 271, + BlockName_P = 272, + TableScan_P = 273, + IndexScan_P = 274, + IndexOnlyScan_P = 275, + Skew_P = 276, + HINT_MULTI_NODE_P = 277, + NULL_P = 278, + TRUE_P = 279, + FALSE_P = 280, + Predpush_P = 281, + Rewrite_P = 282 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 41 "hint_gram.y" + + int ival; + char *str; + List *list; + Node *node; + + +/* Line 2058 of yacc.c */ +#line 92 "hint_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int yyparse (void *YYPARSE_PARAM); +#else +int yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int yyparse (yyscan_t yyscanner); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_YY_HINT_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/parser/keywords.h postgresql-hll-2.14/include/parser/keywords.h --- postgresql-hll-2.14_old/include/parser/keywords.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/keywords.h 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- + * + * keywords.h + * lexical token lookup for key words in PostgreSQL + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/keywords.h + * + * ------------------------------------------------------------------------- + */ +#ifndef KEYWORDS_H +#define KEYWORDS_H + +/* Keyword categories --- should match lists in gram.y */ +#define UNRESERVED_KEYWORD 0 +#define COL_NAME_KEYWORD 1 +#define TYPE_FUNC_NAME_KEYWORD 2 +#define RESERVED_KEYWORD 3 + +typedef struct ScanKeyword { + const char* name; /* in lower case */ + int16 value; /* grammar's token code */ + int16 category; /* see codes above */ +} ScanKeyword; + +extern PGDLLIMPORT const ScanKeyword ScanKeywords[]; +extern PGDLLIMPORT const int NumScanKeywords; + +/* Globals from keywords.c */ +extern const ScanKeyword SQLScanKeywords[]; +extern const int NumSQLScanKeywords; + +extern const ScanKeyword* ScanKeywordLookup(const char* text, const ScanKeyword* keywords, int num_keywords); + +#endif /* KEYWORDS_H */ diff -uprN postgresql-hll-2.14_old/include/parser/kwlist.h postgresql-hll-2.14/include/parser/kwlist.h --- postgresql-hll-2.14_old/include/parser/kwlist.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/kwlist.h 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,625 @@ +/* ------------------------------------------------------------------------- + * + * kwlist.h + * + * The keyword list is kept in its own source file for possible use by + * automatic tools. The exact representation of a keyword is determined + * by the PG_KEYWORD macro, which is not defined in this file; it can + * be defined by the caller for special purposes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * IDENTIFICATION + * src/include/parser/kwlist.h + * + * ------------------------------------------------------------------------- + */ + +/* there is deliberately not an #ifndef KWLIST_H here */ + +/* + * List of keyword (name, token-value, category) entries. + * + * !!WARNING!!: This list must be sorted by ASCII name, because binary + * search is used to locate entries. + */ + +/* name, value, category */ +PG_KEYWORD("abort", ABORT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("absolute", ABSOLUTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("access", ACCESS, UNRESERVED_KEYWORD) +PG_KEYWORD("account", ACCOUNT, UNRESERVED_KEYWORD) +PG_KEYWORD("action", ACTION, UNRESERVED_KEYWORD) +PG_KEYWORD("add", ADD_P, UNRESERVED_KEYWORD) +PG_KEYWORD("admin", ADMIN, UNRESERVED_KEYWORD) +PG_KEYWORD("after", AFTER, UNRESERVED_KEYWORD) +PG_KEYWORD("aggregate", AGGREGATE, UNRESERVED_KEYWORD) +PG_KEYWORD("algorithm", ALGORITHM, UNRESERVED_KEYWORD) +PG_KEYWORD("all", ALL, RESERVED_KEYWORD) +PG_KEYWORD("also", ALSO, UNRESERVED_KEYWORD) +PG_KEYWORD("alter", ALTER, UNRESERVED_KEYWORD) +PG_KEYWORD("always", ALWAYS, UNRESERVED_KEYWORD) +PG_KEYWORD("analyse", ANALYSE, RESERVED_KEYWORD) /* British spelling */ +PG_KEYWORD("analyze", ANALYZE, RESERVED_KEYWORD) +PG_KEYWORD("and", AND, RESERVED_KEYWORD) +PG_KEYWORD("any", ANY, RESERVED_KEYWORD) +PG_KEYWORD("app", APP, UNRESERVED_KEYWORD) +PG_KEYWORD("array", ARRAY, RESERVED_KEYWORD) +PG_KEYWORD("as", AS, RESERVED_KEYWORD) +PG_KEYWORD("asc", ASC, RESERVED_KEYWORD) +PG_KEYWORD("assertion", ASSERTION, UNRESERVED_KEYWORD) +PG_KEYWORD("assignment", ASSIGNMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("asymmetric", ASYMMETRIC, RESERVED_KEYWORD) +PG_KEYWORD("at", AT, UNRESERVED_KEYWORD) +PG_KEYWORD("attribute", ATTRIBUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("audit", AUDIT, UNRESERVED_KEYWORD) +PG_KEYWORD("authid", AUTHID, RESERVED_KEYWORD) +PG_KEYWORD("authorization", AUTHORIZATION, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("autoextend", AUTOEXTEND, UNRESERVED_KEYWORD) +PG_KEYWORD("automapped", AUTOMAPPED, UNRESERVED_KEYWORD) +PG_KEYWORD("backward", BACKWARD, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("barrier", BARRIER, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("before", BEFORE, UNRESERVED_KEYWORD) +PG_KEYWORD("begin", BEGIN_P, UNRESERVED_KEYWORD) +PG_KEYWORD("begin_non_anoyblock", BEGIN_NON_ANOYBLOCK, UNRESERVED_KEYWORD) +PG_KEYWORD("between", BETWEEN, COL_NAME_KEYWORD) +PG_KEYWORD("bigint", BIGINT, COL_NAME_KEYWORD) +PG_KEYWORD("binary", BINARY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("binary_double", BINARY_DOUBLE, COL_NAME_KEYWORD) +PG_KEYWORD("binary_integer", BINARY_INTEGER, COL_NAME_KEYWORD) +PG_KEYWORD("bit", BIT, COL_NAME_KEYWORD) +PG_KEYWORD("blob", BLOB_P, UNRESERVED_KEYWORD) +PG_KEYWORD("boolean", BOOLEAN_P, COL_NAME_KEYWORD) +PG_KEYWORD("both", BOTH, RESERVED_KEYWORD) +PG_KEYWORD("buckets", BUCKETS, RESERVED_KEYWORD) +PG_KEYWORD("by", BY, UNRESERVED_KEYWORD) +PG_KEYWORD("byteawithoutorder", BYTEAWITHOUTORDER, COL_NAME_KEYWORD) +PG_KEYWORD("byteawithoutorderwithequal", BYTEAWITHOUTORDERWITHEQUAL, COL_NAME_KEYWORD) +PG_KEYWORD("cache", CACHE, UNRESERVED_KEYWORD) +PG_KEYWORD("call", CALL, UNRESERVED_KEYWORD) +PG_KEYWORD("called", CALLED, UNRESERVED_KEYWORD) +PG_KEYWORD("cascade", CASCADE, UNRESERVED_KEYWORD) +PG_KEYWORD("cascaded", CASCADED, UNRESERVED_KEYWORD) +PG_KEYWORD("case", CASE, RESERVED_KEYWORD) +PG_KEYWORD("cast", CAST, RESERVED_KEYWORD) +PG_KEYWORD("catalog", CATALOG_P, UNRESERVED_KEYWORD) +PG_KEYWORD("chain", CHAIN, UNRESERVED_KEYWORD) +PG_KEYWORD("char", CHAR_P, COL_NAME_KEYWORD) +PG_KEYWORD("character", CHARACTER, COL_NAME_KEYWORD) +PG_KEYWORD("characteristics", CHARACTERISTICS, UNRESERVED_KEYWORD) +PG_KEYWORD("check", CHECK, RESERVED_KEYWORD) +PG_KEYWORD("checkpoint", CHECKPOINT, UNRESERVED_KEYWORD) +PG_KEYWORD("class", CLASS, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("clean", CLEAN, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("client", CLIENT, UNRESERVED_KEYWORD) +PG_KEYWORD("client_master_key", CLIENT_MASTER_KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("client_master_keys", CLIENT_MASTER_KEYS, UNRESERVED_KEYWORD) +PG_KEYWORD("clob", CLOB, UNRESERVED_KEYWORD) +PG_KEYWORD("close", CLOSE, UNRESERVED_KEYWORD) +PG_KEYWORD("cluster", CLUSTER, UNRESERVED_KEYWORD) +PG_KEYWORD("coalesce", COALESCE, COL_NAME_KEYWORD) +PG_KEYWORD("collate", COLLATE, RESERVED_KEYWORD) +PG_KEYWORD("collation", COLLATION, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("column", COLUMN, RESERVED_KEYWORD) +PG_KEYWORD("column_args", COLUMN_ARGS, UNRESERVED_KEYWORD) +PG_KEYWORD("column_encryption_key", COLUMN_ENCRYPTION_KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("column_encryption_keys", COLUMN_ENCRYPTION_KEYS, UNRESERVED_KEYWORD) +PG_KEYWORD("column_function", COLUMN_FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("comment", COMMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("comments", COMMENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("commit", COMMIT, UNRESERVED_KEYWORD) +PG_KEYWORD("committed", COMMITTED, UNRESERVED_KEYWORD) +PG_KEYWORD("compact", COMPACT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("compatible_illegal_chars", COMPATIBLE_ILLEGAL_CHARS, UNRESERVED_KEYWORD) +PG_KEYWORD("complete", COMPLETE, UNRESERVED_KEYWORD) +PG_KEYWORD("compress", COMPRESS, UNRESERVED_KEYWORD) +PG_KEYWORD("concurrently", CONCURRENTLY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("condition", CONDITION, UNRESERVED_KEYWORD) +PG_KEYWORD("configuration", CONFIGURATION, UNRESERVED_KEYWORD) +PG_KEYWORD("connection", CONNECTION, UNRESERVED_KEYWORD) +PG_KEYWORD("constraint", CONSTRAINT, RESERVED_KEYWORD) +PG_KEYWORD("constraints", CONSTRAINTS, UNRESERVED_KEYWORD) +PG_KEYWORD("content", CONTENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("continue", CONTINUE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("contquery", CONTQUERY, RESERVED_KEYWORD) +PG_KEYWORD("conversion", CONVERSION_P, UNRESERVED_KEYWORD) +PG_KEYWORD("coordinator", COORDINATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("coordinators", COORDINATORS, UNRESERVED_KEYWORD) +PG_KEYWORD("copy", COPY, UNRESERVED_KEYWORD) +PG_KEYWORD("cost", COST, UNRESERVED_KEYWORD) +PG_KEYWORD("create", CREATE, RESERVED_KEYWORD) +PG_KEYWORD("cross", CROSS, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("csv", CSV, UNRESERVED_KEYWORD) +PG_KEYWORD("cube", CUBE, UNRESERVED_KEYWORD) +PG_KEYWORD("current", CURRENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("current_catalog", CURRENT_CATALOG, RESERVED_KEYWORD) +PG_KEYWORD("current_date", CURRENT_DATE, RESERVED_KEYWORD) +PG_KEYWORD("current_role", CURRENT_ROLE, RESERVED_KEYWORD) +PG_KEYWORD("current_schema", CURRENT_SCHEMA, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("current_time", CURRENT_TIME, RESERVED_KEYWORD) +PG_KEYWORD("current_timestamp", CURRENT_TIMESTAMP, RESERVED_KEYWORD) +PG_KEYWORD("current_user", CURRENT_USER, RESERVED_KEYWORD) +PG_KEYWORD("cursor", CURSOR, UNRESERVED_KEYWORD) +PG_KEYWORD("cycle", CYCLE, UNRESERVED_KEYWORD) +PG_KEYWORD("data", DATA_P, UNRESERVED_KEYWORD) +PG_KEYWORD("database", DATABASE, UNRESERVED_KEYWORD) +PG_KEYWORD("datafile", DATAFILE, UNRESERVED_KEYWORD) +PG_KEYWORD("datanode", DATANODE, UNRESERVED_KEYWORD) +PG_KEYWORD("datanodes", DATANODES, UNRESERVED_KEYWORD) +PG_KEYWORD("datatype_cl", DATATYPE_CL, UNRESERVED_KEYWORD) +PG_KEYWORD("date", DATE_P, COL_NAME_KEYWORD) +PG_KEYWORD("date_format", DATE_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("day", DAY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("dbcompatibility", DBCOMPATIBILITY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("deallocate", DEALLOCATE, UNRESERVED_KEYWORD) +PG_KEYWORD("dec", DEC, COL_NAME_KEYWORD) +PG_KEYWORD("decimal", DECIMAL_P, COL_NAME_KEYWORD) +PG_KEYWORD("declare", DECLARE, UNRESERVED_KEYWORD) +PG_KEYWORD("decode", DECODE, COL_NAME_KEYWORD) +PG_KEYWORD("default", DEFAULT, RESERVED_KEYWORD) +PG_KEYWORD("defaults", DEFAULTS, UNRESERVED_KEYWORD) +PG_KEYWORD("deferrable", DEFERRABLE, RESERVED_KEYWORD) +PG_KEYWORD("deferred", DEFERRED, UNRESERVED_KEYWORD) +PG_KEYWORD("definer", DEFINER, UNRESERVED_KEYWORD) +PG_KEYWORD("delete", DELETE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("delimiter", DELIMITER, UNRESERVED_KEYWORD) +PG_KEYWORD("delimiters", DELIMITERS, UNRESERVED_KEYWORD) +PG_KEYWORD("delta", DELTA, UNRESERVED_KEYWORD) +PG_KEYWORD("deltamerge", DELTAMERGE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("desc", DESC, RESERVED_KEYWORD) +PG_KEYWORD("deterministic", DETERMINISTIC, UNRESERVED_KEYWORD) +PG_KEYWORD("dictionary", DICTIONARY, UNRESERVED_KEYWORD) +PG_KEYWORD("direct", DIRECT, UNRESERVED_KEYWORD) +PG_KEYWORD("directory", DIRECTORY, UNRESERVED_KEYWORD) +PG_KEYWORD("disable", DISABLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("discard", DISCARD, UNRESERVED_KEYWORD) +PG_KEYWORD("disconnect", DISCONNECT, UNRESERVED_KEYWORD) +PG_KEYWORD("distinct", DISTINCT, RESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("distribute", DISTRIBUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("distribution", DISTRIBUTION, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("do", DO, RESERVED_KEYWORD) +PG_KEYWORD("document", DOCUMENT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("domain", DOMAIN_P, UNRESERVED_KEYWORD) +PG_KEYWORD("double", DOUBLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("drop", DROP, UNRESERVED_KEYWORD) +PG_KEYWORD("duplicate", DUPLICATE, UNRESERVED_KEYWORD) +PG_KEYWORD("each", EACH, UNRESERVED_KEYWORD) +PG_KEYWORD("elastic", ELASTIC, UNRESERVED_KEYWORD) +PG_KEYWORD("else", ELSE, RESERVED_KEYWORD) +PG_KEYWORD("enable", ENABLE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("encoding", ENCODING, UNRESERVED_KEYWORD) +PG_KEYWORD("encrypted", ENCRYPTED, UNRESERVED_KEYWORD) +PG_KEYWORD("encrypted_value", ENCRYPTED_VALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("encryption", ENCRYPTION, UNRESERVED_KEYWORD) +PG_KEYWORD("encryption_type", ENCRYPTION_TYPE, UNRESERVED_KEYWORD) +PG_KEYWORD("end", END_P, RESERVED_KEYWORD) +PG_KEYWORD("enforced", ENFORCED, UNRESERVED_KEYWORD) +PG_KEYWORD("enum", ENUM_P, UNRESERVED_KEYWORD) +PG_KEYWORD("eol", EOL, UNRESERVED_KEYWORD) +PG_KEYWORD("errors", ERRORS, UNRESERVED_KEYWORD) +PG_KEYWORD("escape", ESCAPE, UNRESERVED_KEYWORD) +PG_KEYWORD("escaping", ESCAPING, UNRESERVED_KEYWORD) +PG_KEYWORD("every", EVERY, UNRESERVED_KEYWORD) +PG_KEYWORD("except", EXCEPT, RESERVED_KEYWORD) +PG_KEYWORD("exchange", EXCHANGE, UNRESERVED_KEYWORD) +PG_KEYWORD("exclude", EXCLUDE, UNRESERVED_KEYWORD) +#ifndef ENABLE_MULTIPLE_NODES +PG_KEYWORD("excluded", EXCLUDED, RESERVED_KEYWORD) +#endif +PG_KEYWORD("excluding", EXCLUDING, UNRESERVED_KEYWORD) +PG_KEYWORD("exclusive", EXCLUSIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("execute", EXECUTE, UNRESERVED_KEYWORD) +PG_KEYWORD("exists", EXISTS, COL_NAME_KEYWORD) +PG_KEYWORD("expired", EXPIRED_P, UNRESERVED_KEYWORD) +PG_KEYWORD("explain", EXPLAIN, UNRESERVED_KEYWORD) +PG_KEYWORD("extension", EXTENSION, UNRESERVED_KEYWORD) +PG_KEYWORD("external", EXTERNAL, UNRESERVED_KEYWORD) +PG_KEYWORD("extract", EXTRACT, COL_NAME_KEYWORD) +PG_KEYWORD("false", FALSE_P, RESERVED_KEYWORD) +PG_KEYWORD("family", FAMILY, UNRESERVED_KEYWORD) +PG_KEYWORD("fast", FAST, UNRESERVED_KEYWORD) +PG_KEYWORD("fenced", FENCED, RESERVED_KEYWORD) +PG_KEYWORD("fetch", FETCH, RESERVED_KEYWORD) +PG_KEYWORD("fileheader", FILEHEADER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("fill_missing_fields", FILL_MISSING_FIELDS, UNRESERVED_KEYWORD) +PG_KEYWORD("filter", FILTER, UNRESERVED_KEYWORD) +PG_KEYWORD("first", FIRST_P, UNRESERVED_KEYWORD) +PG_KEYWORD("fixed", FIXED_P, UNRESERVED_KEYWORD) +PG_KEYWORD("float", FLOAT_P, COL_NAME_KEYWORD) +PG_KEYWORD("following", FOLLOWING, UNRESERVED_KEYWORD) +PG_KEYWORD("for", FOR, RESERVED_KEYWORD) +PG_KEYWORD("force", FORCE, UNRESERVED_KEYWORD) +PG_KEYWORD("foreign", FOREIGN, RESERVED_KEYWORD) +PG_KEYWORD("formatter", FORMATTER, UNRESERVED_KEYWORD) +PG_KEYWORD("forward", FORWARD, UNRESERVED_KEYWORD) +PG_KEYWORD("freeze", FREEZE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("from", FROM, RESERVED_KEYWORD) +PG_KEYWORD("full", FULL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("function", FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("functions", FUNCTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("global", GLOBAL, UNRESERVED_KEYWORD) +PG_KEYWORD("global_function", GLOBAL_FUNCTION, UNRESERVED_KEYWORD) +PG_KEYWORD("grant", GRANT, RESERVED_KEYWORD) +PG_KEYWORD("granted", GRANTED, UNRESERVED_KEYWORD) +PG_KEYWORD("greatest", GREATEST, COL_NAME_KEYWORD) +PG_KEYWORD("group", GROUP_P, RESERVED_KEYWORD) +PG_KEYWORD("grouping", GROUPING_P, COL_NAME_KEYWORD) +PG_KEYWORD("handler", HANDLER, UNRESERVED_KEYWORD) +PG_KEYWORD("having", HAVING, RESERVED_KEYWORD) +PG_KEYWORD("hdfsdirectory", HDFSDIRECTORY, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("header", HEADER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("hold", HOLD, UNRESERVED_KEYWORD) +PG_KEYWORD("hour", HOUR_P, UNRESERVED_KEYWORD) +/* new key-word for ALTER ROLE */ +PG_KEYWORD("identified", IDENTIFIED, UNRESERVED_KEYWORD) +PG_KEYWORD("identity", IDENTITY_P, UNRESERVED_KEYWORD) +PG_KEYWORD("if", IF_P, UNRESERVED_KEYWORD) +PG_KEYWORD("ignore_extra_data", IGNORE_EXTRA_DATA, UNRESERVED_KEYWORD) +PG_KEYWORD("ilike", ILIKE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("immediate", IMMEDIATE, UNRESERVED_KEYWORD) +PG_KEYWORD("immutable", IMMUTABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("implicit", IMPLICIT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("in", IN_P, RESERVED_KEYWORD) +PG_KEYWORD("include", INCLUDE, UNRESERVED_KEYWORD) +PG_KEYWORD("including", INCLUDING, UNRESERVED_KEYWORD) +PG_KEYWORD("increment", INCREMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("incremental", INCREMENTAL, UNRESERVED_KEYWORD) +PG_KEYWORD("index", INDEX, UNRESERVED_KEYWORD) +PG_KEYWORD("indexes", INDEXES, UNRESERVED_KEYWORD) +PG_KEYWORD("inherit", INHERIT, UNRESERVED_KEYWORD) +PG_KEYWORD("inherits", INHERITS, UNRESERVED_KEYWORD) +PG_KEYWORD("initial", INITIAL_P, UNRESERVED_KEYWORD) +PG_KEYWORD("initially", INITIALLY, RESERVED_KEYWORD) +PG_KEYWORD("initrans", INITRANS, UNRESERVED_KEYWORD) +PG_KEYWORD("inline", INLINE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("inner", INNER_P, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("inout", INOUT, COL_NAME_KEYWORD) +PG_KEYWORD("input", INPUT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("insensitive", INSENSITIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("insert", INSERT, UNRESERVED_KEYWORD) +PG_KEYWORD("instead", INSTEAD, UNRESERVED_KEYWORD) +PG_KEYWORD("int", INT_P, COL_NAME_KEYWORD) +PG_KEYWORD("integer", INTEGER, COL_NAME_KEYWORD) +PG_KEYWORD("internal", INTERNAL, UNRESERVED_KEYWORD) +PG_KEYWORD("intersect", INTERSECT, RESERVED_KEYWORD) +PG_KEYWORD("interval", INTERVAL, COL_NAME_KEYWORD) +PG_KEYWORD("into", INTO, RESERVED_KEYWORD) +PG_KEYWORD("invoker", INVOKER, UNRESERVED_KEYWORD) +PG_KEYWORD("ip", IP, UNRESERVED_KEYWORD) +PG_KEYWORD("is", IS, RESERVED_KEYWORD) +PG_KEYWORD("isnull", ISNULL, UNRESERVED_KEYWORD) +PG_KEYWORD("isolation", ISOLATION, UNRESERVED_KEYWORD) +PG_KEYWORD("join", JOIN, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("key", KEY, UNRESERVED_KEYWORD) +PG_KEYWORD("key_path", KEY_PATH, UNRESERVED_KEYWORD) +PG_KEYWORD("key_store", KEY_STORE, UNRESERVED_KEYWORD) +PG_KEYWORD("kill", KILL, UNRESERVED_KEYWORD) +PG_KEYWORD("label", LABEL, UNRESERVED_KEYWORD) +PG_KEYWORD("language", LANGUAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("large", LARGE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("last", LAST_P, UNRESERVED_KEYWORD) +PG_KEYWORD("lc_collate", LC_COLLATE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("lc_ctype", LC_CTYPE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("leading", LEADING, RESERVED_KEYWORD) +PG_KEYWORD("leakproof", LEAKPROOF, UNRESERVED_KEYWORD) +PG_KEYWORD("least", LEAST, COL_NAME_KEYWORD) +PG_KEYWORD("left", LEFT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("less", LESS, RESERVED_KEYWORD) +PG_KEYWORD("level", LEVEL, UNRESERVED_KEYWORD) +PG_KEYWORD("like", LIKE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("limit", LIMIT, RESERVED_KEYWORD) +PG_KEYWORD("list", LIST, UNRESERVED_KEYWORD) +PG_KEYWORD("listen", LISTEN, UNRESERVED_KEYWORD) +PG_KEYWORD("load", LOAD, UNRESERVED_KEYWORD) +PG_KEYWORD("local", LOCAL, UNRESERVED_KEYWORD) +PG_KEYWORD("localtime", LOCALTIME, RESERVED_KEYWORD) +PG_KEYWORD("localtimestamp", LOCALTIMESTAMP, RESERVED_KEYWORD) +PG_KEYWORD("location", LOCATION, UNRESERVED_KEYWORD) +PG_KEYWORD("lock", LOCK_P, UNRESERVED_KEYWORD) +PG_KEYWORD("log", LOG_P, UNRESERVED_KEYWORD) +PG_KEYWORD("logging", LOGGING, UNRESERVED_KEYWORD) +PG_KEYWORD("login_any", LOGIN_ANY, UNRESERVED_KEYWORD) +PG_KEYWORD("login_failure", LOGIN_FAILURE, UNRESERVED_KEYWORD) +PG_KEYWORD("login_success", LOGIN_SUCCESS, UNRESERVED_KEYWORD) +PG_KEYWORD("logout", LOGOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("loop", LOOP, UNRESERVED_KEYWORD) +PG_KEYWORD("mapping", MAPPING, UNRESERVED_KEYWORD) +PG_KEYWORD("masking", MASKING, UNRESERVED_KEYWORD) +PG_KEYWORD("master", MASTER, UNRESERVED_KEYWORD) +PG_KEYWORD("match", MATCH, UNRESERVED_KEYWORD) +PG_KEYWORD("matched", MATCHED, UNRESERVED_KEYWORD) +PG_KEYWORD("materialized", MATERIALIZED, UNRESERVED_KEYWORD) +PG_KEYWORD("maxextents", MAXEXTENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("maxsize", MAXSIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("maxtrans", MAXTRANS, UNRESERVED_KEYWORD) +PG_KEYWORD("maxvalue", MAXVALUE, RESERVED_KEYWORD) +PG_KEYWORD("merge", MERGE, UNRESERVED_KEYWORD) +PG_KEYWORD("minextents", MINEXTENTS, UNRESERVED_KEYWORD) +PG_KEYWORD("minus", MINUS_P, RESERVED_KEYWORD) +PG_KEYWORD("minute", MINUTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("minvalue", MINVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("mode", MODE, UNRESERVED_KEYWORD) +PG_KEYWORD("modify", MODIFY_P, RESERVED_KEYWORD) +PG_KEYWORD("month", MONTH_P, UNRESERVED_KEYWORD) +PG_KEYWORD("move", MOVE, UNRESERVED_KEYWORD) +PG_KEYWORD("movement", MOVEMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("name", NAME_P, UNRESERVED_KEYWORD) +PG_KEYWORD("names", NAMES, UNRESERVED_KEYWORD) +PG_KEYWORD("national", NATIONAL, COL_NAME_KEYWORD) +PG_KEYWORD("natural", NATURAL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("nchar", NCHAR, COL_NAME_KEYWORD) +PG_KEYWORD("next", NEXT, UNRESERVED_KEYWORD) +PG_KEYWORD("nlssort", NLSSORT, RESERVED_KEYWORD) +PG_KEYWORD("no", NO, UNRESERVED_KEYWORD) +PG_KEYWORD("nocompress", NOCOMPRESS, UNRESERVED_KEYWORD) +PG_KEYWORD("nocycle", NOCYCLE, UNRESERVED_KEYWORD) +#ifdef PGXC +PG_KEYWORD("node", NODE, UNRESERVED_KEYWORD) +#endif +PG_KEYWORD("nologging", NOLOGGING, UNRESERVED_KEYWORD) +PG_KEYWORD("nomaxvalue", NOMAXVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("nominvalue", NOMINVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("none", NONE, COL_NAME_KEYWORD) +PG_KEYWORD("not", NOT, RESERVED_KEYWORD) +PG_KEYWORD("nothing", NOTHING, UNRESERVED_KEYWORD) +PG_KEYWORD("notify", NOTIFY, UNRESERVED_KEYWORD) +PG_KEYWORD("notnull", NOTNULL, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("nowait", NOWAIT, UNRESERVED_KEYWORD) +PG_KEYWORD("null", NULL_P, RESERVED_KEYWORD) +PG_KEYWORD("nullif", NULLIF, COL_NAME_KEYWORD) +PG_KEYWORD("nulls", NULLS_P, UNRESERVED_KEYWORD) +PG_KEYWORD("number", NUMBER_P, COL_NAME_KEYWORD) +PG_KEYWORD("numeric", NUMERIC, COL_NAME_KEYWORD) +PG_KEYWORD("numstr", NUMSTR, UNRESERVED_KEYWORD) +PG_KEYWORD("nvarchar2", NVARCHAR2, COL_NAME_KEYWORD) +PG_KEYWORD("nvl", NVL, COL_NAME_KEYWORD) +PG_KEYWORD("object", OBJECT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("of", OF, UNRESERVED_KEYWORD) +PG_KEYWORD("off", OFF, UNRESERVED_KEYWORD) +PG_KEYWORD("offset", OFFSET, RESERVED_KEYWORD) +PG_KEYWORD("oids", OIDS, UNRESERVED_KEYWORD) +PG_KEYWORD("on", ON, RESERVED_KEYWORD) +PG_KEYWORD("only", ONLY, RESERVED_KEYWORD) +PG_KEYWORD("operator", OPERATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("optimization", OPTIMIZATION, UNRESERVED_KEYWORD) +PG_KEYWORD("option", OPTION, UNRESERVED_KEYWORD) +PG_KEYWORD("options", OPTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("or", OR, RESERVED_KEYWORD) +PG_KEYWORD("order", ORDER, RESERVED_KEYWORD) +PG_KEYWORD("out", OUT_P, COL_NAME_KEYWORD) +PG_KEYWORD("outer", OUTER_P, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("over", OVER, UNRESERVED_KEYWORD) +PG_KEYWORD("overlaps", OVERLAPS, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("overlay", OVERLAY, COL_NAME_KEYWORD) +PG_KEYWORD("owned", OWNED, UNRESERVED_KEYWORD) +PG_KEYWORD("owner", OWNER, UNRESERVED_KEYWORD) +PG_KEYWORD("package", PACKAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("parser", PARSER, UNRESERVED_KEYWORD) +PG_KEYWORD("partial", PARTIAL, UNRESERVED_KEYWORD) +PG_KEYWORD("partition", PARTITION, UNRESERVED_KEYWORD) +PG_KEYWORD("partitions", PARTITIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("passing", PASSING, UNRESERVED_KEYWORD) +PG_KEYWORD("password", PASSWORD, UNRESERVED_KEYWORD) +PG_KEYWORD("pctfree", PCTFREE, UNRESERVED_KEYWORD) +PG_KEYWORD("per", PER_P, UNRESERVED_KEYWORD) +PG_KEYWORD("percent", PERCENT, UNRESERVED_KEYWORD) +PG_KEYWORD("performance", PERFORMANCE, RESERVED_KEYWORD) +PG_KEYWORD("perm", PERM, UNRESERVED_KEYWORD) +PG_KEYWORD("placing", PLACING, RESERVED_KEYWORD) +PG_KEYWORD("plan", PLAN, UNRESERVED_KEYWORD) +PG_KEYWORD("plans", PLANS, UNRESERVED_KEYWORD) +PG_KEYWORD("policy", POLICY, UNRESERVED_KEYWORD) +PG_KEYWORD("pool", POOL, UNRESERVED_KEYWORD) +PG_KEYWORD("position", POSITION, COL_NAME_KEYWORD) +PG_KEYWORD("preceding", PRECEDING, UNRESERVED_KEYWORD) +PG_KEYWORD("precision", PRECISION, COL_NAME_KEYWORD) +/* PGXC_BEGIN */ +PG_KEYWORD("preferred", PREFERRED, UNRESERVED_KEYWORD) +/* PGXC_END */ +PG_KEYWORD("prefix", PREFIX, UNRESERVED_KEYWORD) +PG_KEYWORD("prepare", PREPARE, UNRESERVED_KEYWORD) +PG_KEYWORD("prepared", PREPARED, UNRESERVED_KEYWORD) +PG_KEYWORD("preserve", PRESERVE, UNRESERVED_KEYWORD) +PG_KEYWORD("primary", PRIMARY, RESERVED_KEYWORD) +PG_KEYWORD("prior", PRIOR, UNRESERVED_KEYWORD) +PG_KEYWORD("private", PRIVATE, UNRESERVED_KEYWORD) +PG_KEYWORD("privilege", PRIVILEGE, UNRESERVED_KEYWORD) +PG_KEYWORD("privileges", PRIVILEGES, UNRESERVED_KEYWORD) +PG_KEYWORD("procedural", PROCEDURAL, UNRESERVED_KEYWORD) +PG_KEYWORD("procedure", PROCEDURE, RESERVED_KEYWORD) +PG_KEYWORD("profile", PROFILE, UNRESERVED_KEYWORD) +PG_KEYWORD("query", QUERY, UNRESERVED_KEYWORD) +PG_KEYWORD("quote", QUOTE, UNRESERVED_KEYWORD) +PG_KEYWORD("randomized", RANDOMIZED, UNRESERVED_KEYWORD) +PG_KEYWORD("range", RANGE, UNRESERVED_KEYWORD) +PG_KEYWORD("raw", RAW, UNRESERVED_KEYWORD) +PG_KEYWORD("read", READ, UNRESERVED_KEYWORD) +PG_KEYWORD("real", REAL, COL_NAME_KEYWORD) +PG_KEYWORD("reassign", REASSIGN, UNRESERVED_KEYWORD) +PG_KEYWORD("rebuild", REBUILD, UNRESERVED_KEYWORD) +PG_KEYWORD("recheck", RECHECK, UNRESERVED_KEYWORD) +PG_KEYWORD("recursive", RECURSIVE, UNRESERVED_KEYWORD) +PG_KEYWORD("redisanyvalue", REDISANYVALUE, UNRESERVED_KEYWORD) +PG_KEYWORD("ref", REF, UNRESERVED_KEYWORD) +PG_KEYWORD("references", REFERENCES, RESERVED_KEYWORD) +PG_KEYWORD("refresh", REFRESH, UNRESERVED_KEYWORD) +PG_KEYWORD("reindex", REINDEX, UNRESERVED_KEYWORD) +PG_KEYWORD("reject", REJECT_P, RESERVED_KEYWORD) +PG_KEYWORD("relative", RELATIVE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("release", RELEASE, UNRESERVED_KEYWORD) +PG_KEYWORD("reloptions", RELOPTIONS, UNRESERVED_KEYWORD) +PG_KEYWORD("remote", REMOTE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("remove", REMOVE, UNRESERVED_KEYWORD) +PG_KEYWORD("rename", RENAME, UNRESERVED_KEYWORD) +PG_KEYWORD("repeatable", REPEATABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("replace", REPLACE, UNRESERVED_KEYWORD) +PG_KEYWORD("replica", REPLICA, UNRESERVED_KEYWORD) +PG_KEYWORD("reset", RESET, UNRESERVED_KEYWORD) +PG_KEYWORD("resize", RESIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("resource", RESOURCE, UNRESERVED_KEYWORD) +PG_KEYWORD("restart", RESTART, UNRESERVED_KEYWORD) +PG_KEYWORD("restrict", RESTRICT, UNRESERVED_KEYWORD) +PG_KEYWORD("return", RETURN, UNRESERVED_KEYWORD) +PG_KEYWORD("returning", RETURNING, RESERVED_KEYWORD) +PG_KEYWORD("returns", RETURNS, UNRESERVED_KEYWORD) +PG_KEYWORD("reuse", REUSE, UNRESERVED_KEYWORD) +PG_KEYWORD("revoke", REVOKE, UNRESERVED_KEYWORD) +PG_KEYWORD("right", RIGHT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("role", ROLE, UNRESERVED_KEYWORD) +PG_KEYWORD("roles", ROLES, UNRESERVED_KEYWORD) +PG_KEYWORD("rollback", ROLLBACK, UNRESERVED_KEYWORD) +PG_KEYWORD("rollup", ROLLUP, UNRESERVED_KEYWORD) +PG_KEYWORD("row", ROW, COL_NAME_KEYWORD) +#ifndef ENABLE_MULTIPLE_NODES +PG_KEYWORD("rownum", ROWNUM, RESERVED_KEYWORD) +#endif +PG_KEYWORD("rows", ROWS, UNRESERVED_KEYWORD) +PG_KEYWORD("rule", RULE, UNRESERVED_KEYWORD) +PG_KEYWORD("savepoint", SAVEPOINT, UNRESERVED_KEYWORD) +PG_KEYWORD("schema", SCHEMA, UNRESERVED_KEYWORD) +PG_KEYWORD("scroll", SCROLL, UNRESERVED_KEYWORD) +PG_KEYWORD("search", SEARCH, UNRESERVED_KEYWORD) +PG_KEYWORD("second", SECOND_P, UNRESERVED_KEYWORD) +PG_KEYWORD("security", SECURITY, UNRESERVED_KEYWORD) +PG_KEYWORD("select", SELECT, RESERVED_KEYWORD) +PG_KEYWORD("sequence", SEQUENCE, UNRESERVED_KEYWORD) +PG_KEYWORD("sequences", SEQUENCES, UNRESERVED_KEYWORD) +PG_KEYWORD("serializable", SERIALIZABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("server", SERVER, UNRESERVED_KEYWORD) +PG_KEYWORD("session", SESSION, UNRESERVED_KEYWORD) +PG_KEYWORD("session_user", SESSION_USER, RESERVED_KEYWORD) +PG_KEYWORD("set", SET, UNRESERVED_KEYWORD) +PG_KEYWORD("setof", SETOF, COL_NAME_KEYWORD) +PG_KEYWORD("sets", SETS, UNRESERVED_KEYWORD) +PG_KEYWORD("share", SHARE, UNRESERVED_KEYWORD) +PG_KEYWORD("shippable", SHIPPABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("show", SHOW, UNRESERVED_KEYWORD) +PG_KEYWORD("shutdown", SHUTDOWN, UNRESERVED_KEYWORD) +PG_KEYWORD("similar", SIMILAR, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("simple", SIMPLE, UNRESERVED_KEYWORD) +PG_KEYWORD("size", SIZE, UNRESERVED_KEYWORD) +PG_KEYWORD("slice", SLICE, UNRESERVED_KEYWORD) +PG_KEYWORD("smalldatetime", SMALLDATETIME, COL_NAME_KEYWORD) +PG_KEYWORD("smalldatetime_format", SMALLDATETIME_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("smallint", SMALLINT, COL_NAME_KEYWORD) +PG_KEYWORD("snapshot", SNAPSHOT, UNRESERVED_KEYWORD) +PG_KEYWORD("some", SOME, RESERVED_KEYWORD) +PG_KEYWORD("source", SOURCE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("space", SPACE, UNRESERVED_KEYWORD) +PG_KEYWORD("spill", SPILL, UNRESERVED_KEYWORD) +PG_KEYWORD("split", SPLIT, UNRESERVED_KEYWORD) +PG_KEYWORD("stable", STABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("standalone", STANDALONE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("start", START, UNRESERVED_KEYWORD) +PG_KEYWORD("statement", STATEMENT, UNRESERVED_KEYWORD) +PG_KEYWORD("statement_id", STATEMENT_ID, UNRESERVED_KEYWORD) +PG_KEYWORD("statistics", STATISTICS, UNRESERVED_KEYWORD) +PG_KEYWORD("stdin", STDIN, UNRESERVED_KEYWORD) +PG_KEYWORD("stdout", STDOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("storage", STORAGE, UNRESERVED_KEYWORD) +PG_KEYWORD("store", STORE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("stream", STREAM, RESERVED_KEYWORD) +PG_KEYWORD("strict", STRICT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("strip", STRIP_P, UNRESERVED_KEYWORD) +PG_KEYWORD("substring", SUBSTRING, COL_NAME_KEYWORD) +PG_KEYWORD("symmetric", SYMMETRIC, RESERVED_KEYWORD) +PG_KEYWORD("synonym", SYNONYM, UNRESERVED_KEYWORD) +PG_KEYWORD("sys_refcursor", SYS_REFCURSOR, UNRESERVED_KEYWORD) +PG_KEYWORD("sysdate", SYSDATE, RESERVED_KEYWORD) +PG_KEYWORD("sysid", SYSID, UNRESERVED_KEYWORD) +PG_KEYWORD("system", SYSTEM_P, UNRESERVED_KEYWORD) +PG_KEYWORD("table", TABLE, RESERVED_KEYWORD) +PG_KEYWORD("tables", TABLES, UNRESERVED_KEYWORD) +PG_KEYWORD("tablesample", TABLESAMPLE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("tablespace", TABLESPACE, UNRESERVED_KEYWORD) +PG_KEYWORD("temp", TEMP, UNRESERVED_KEYWORD) +PG_KEYWORD("template", TEMPLATE, UNRESERVED_KEYWORD) +PG_KEYWORD("temporary", TEMPORARY, UNRESERVED_KEYWORD) +PG_KEYWORD("text", TEXT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("than", THAN, UNRESERVED_KEYWORD) +PG_KEYWORD("then", THEN, RESERVED_KEYWORD) +PG_KEYWORD("time", TIME, COL_NAME_KEYWORD) +PG_KEYWORD("time_format", TIME_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("timestamp", TIMESTAMP, COL_NAME_KEYWORD) +PG_KEYWORD("timestamp_format", TIMESTAMP_FORMAT_P, UNRESERVED_KEYWORD) +PG_KEYWORD("timestampdiff", TIMESTAMPDIFF, COL_NAME_KEYWORD) +PG_KEYWORD("tinyint", TINYINT, COL_NAME_KEYWORD) +PG_KEYWORD("to", TO, RESERVED_KEYWORD) +PG_KEYWORD("trailing", TRAILING, RESERVED_KEYWORD) +PG_KEYWORD("transaction", TRANSACTION, UNRESERVED_KEYWORD) +PG_KEYWORD("treat", TREAT, COL_NAME_KEYWORD) +PG_KEYWORD("trigger", TRIGGER, UNRESERVED_KEYWORD) +PG_KEYWORD("trim", TRIM, COL_NAME_KEYWORD) +PG_KEYWORD("true", TRUE_P, RESERVED_KEYWORD) +PG_KEYWORD("truncate", TRUNCATE, UNRESERVED_KEYWORD) +PG_KEYWORD("trusted", TRUSTED, UNRESERVED_KEYWORD) +PG_KEYWORD("tsfield", TSFIELD, UNRESERVED_KEYWORD) +PG_KEYWORD("tstag", TSTAG, UNRESERVED_KEYWORD) +PG_KEYWORD("tstime", TSTIME, UNRESERVED_KEYWORD) +PG_KEYWORD("type", TYPE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("types", TYPES_P, UNRESERVED_KEYWORD) +PG_KEYWORD("unbounded", UNBOUNDED, UNRESERVED_KEYWORD) +PG_KEYWORD("uncommitted", UNCOMMITTED, UNRESERVED_KEYWORD) +PG_KEYWORD("unencrypted", UNENCRYPTED, UNRESERVED_KEYWORD) +PG_KEYWORD("union", UNION, RESERVED_KEYWORD) +PG_KEYWORD("unique", UNIQUE, RESERVED_KEYWORD) +PG_KEYWORD("unknown", UNKNOWN, UNRESERVED_KEYWORD) +PG_KEYWORD("unlimited", UNLIMITED, UNRESERVED_KEYWORD) +PG_KEYWORD("unlisten", UNLISTEN, UNRESERVED_KEYWORD) +PG_KEYWORD("unlock", UNLOCK, UNRESERVED_KEYWORD) +PG_KEYWORD("unlogged", UNLOGGED, UNRESERVED_KEYWORD) +PG_KEYWORD("until", UNTIL, UNRESERVED_KEYWORD) +PG_KEYWORD("unusable", UNUSABLE, UNRESERVED_KEYWORD) +PG_KEYWORD("update", UPDATE, UNRESERVED_KEYWORD) +PG_KEYWORD("user", USER, RESERVED_KEYWORD) +PG_KEYWORD("using", USING, RESERVED_KEYWORD) +PG_KEYWORD("vacuum", VACUUM, UNRESERVED_KEYWORD) +PG_KEYWORD("valid", VALID, UNRESERVED_KEYWORD) +PG_KEYWORD("validate", VALIDATE, UNRESERVED_KEYWORD) +PG_KEYWORD("validation", VALIDATION, UNRESERVED_KEYWORD) +PG_KEYWORD("validator", VALIDATOR, UNRESERVED_KEYWORD) +PG_KEYWORD("value", VALUE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("values", VALUES, COL_NAME_KEYWORD) +PG_KEYWORD("varchar", VARCHAR, COL_NAME_KEYWORD) +PG_KEYWORD("varchar2", VARCHAR2, COL_NAME_KEYWORD) +PG_KEYWORD("variadic", VARIADIC, RESERVED_KEYWORD) +PG_KEYWORD("varying", VARYING, UNRESERVED_KEYWORD) +PG_KEYWORD("vcgroup", VCGROUP, UNRESERVED_KEYWORD) +PG_KEYWORD("verbose", VERBOSE, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("verify", VERIFY, RESERVED_KEYWORD) +PG_KEYWORD("version", VERSION_P, UNRESERVED_KEYWORD) +PG_KEYWORD("view", VIEW, UNRESERVED_KEYWORD) +PG_KEYWORD("volatile", VOLATILE, UNRESERVED_KEYWORD) +PG_KEYWORD("weak", WEAK, UNRESERVED_KEYWORD) +PG_KEYWORD("when", WHEN, RESERVED_KEYWORD) +PG_KEYWORD("where", WHERE, RESERVED_KEYWORD) +PG_KEYWORD("whitespace", WHITESPACE_P, UNRESERVED_KEYWORD) +PG_KEYWORD("window", WINDOW, RESERVED_KEYWORD) +PG_KEYWORD("with", WITH, RESERVED_KEYWORD) +PG_KEYWORD("within", WITHIN, UNRESERVED_KEYWORD) +PG_KEYWORD("without", WITHOUT, UNRESERVED_KEYWORD) +PG_KEYWORD("work", WORK, UNRESERVED_KEYWORD) +PG_KEYWORD("workload", WORKLOAD, UNRESERVED_KEYWORD) +PG_KEYWORD("wrapper", WRAPPER, UNRESERVED_KEYWORD) +PG_KEYWORD("write", WRITE, UNRESERVED_KEYWORD) +PG_KEYWORD("xml", XML_P, UNRESERVED_KEYWORD) +PG_KEYWORD("xmlattributes", XMLATTRIBUTES, COL_NAME_KEYWORD) +PG_KEYWORD("xmlconcat", XMLCONCAT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlelement", XMLELEMENT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlexists", XMLEXISTS, COL_NAME_KEYWORD) +PG_KEYWORD("xmlforest", XMLFOREST, COL_NAME_KEYWORD) +PG_KEYWORD("xmlparse", XMLPARSE, COL_NAME_KEYWORD) +PG_KEYWORD("xmlpi", XMLPI, COL_NAME_KEYWORD) +PG_KEYWORD("xmlroot", XMLROOT, COL_NAME_KEYWORD) +PG_KEYWORD("xmlserialize", XMLSERIALIZE, COL_NAME_KEYWORD) +PG_KEYWORD("year", YEAR_P, UNRESERVED_KEYWORD) +PG_KEYWORD("yes", YES_P, UNRESERVED_KEYWORD) +PG_KEYWORD("zone", ZONE, UNRESERVED_KEYWORD) diff -uprN postgresql-hll-2.14_old/include/parser/parse_agg.h postgresql-hll-2.14/include/parser/parse_agg.h --- postgresql-hll-2.14_old/include/parser/parse_agg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_agg.h 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * parse_agg.h + * handle aggregates and window functions in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_agg.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_AGG_H +#define PARSE_AGG_H + +#include "parser/parse_node.h" + +extern void transformAggregateCall(ParseState* pstate, Aggref* agg, List* args, List* aggorder, bool agg_distinct); +extern void transformWindowFuncCall(ParseState* pstate, WindowFunc* wfunc, WindowDef* windef); + +extern void parseCheckAggregates(ParseState* pstate, Query* qry); +extern void parseCheckWindowFuncs(ParseState* pstate, Query* qry); +extern Node* transformGroupingFunc(ParseState* pstate, GroupingFunc* g); + +extern List* expand_grouping_sets(List* groupingSets, int limit); + +extern List* extract_rollup_sets(List* groupingSets); + +extern List* reorder_grouping_sets(List* groupingSets, List* sortclause); + +extern List* preprocess_groupclause(PlannerInfo* root, List* force); + +extern void build_aggregate_fnexprs(Oid* agg_input_types, int agg_num_inputs, Oid agg_state_type, Oid agg_result_type, + Oid agg_input_collation, Oid transfn_oid, Oid finalfn_oid, Expr** transfnexpr, Expr** finalfnexpr); + +extern bool check_windowagg_can_shuffle(List* partitionClause, List* targetList); + +extern void build_trans_aggregate_fnexprs(int agg_num_inputs, int agg_num_direct_inputs, bool agg_ordered_set, + bool agg_variadic, Oid agg_state_type, Oid* agg_input_types, Oid agg_result_type, Oid agg_input_collation, + Oid transfn_oid, Oid finalfn_oid, Expr** transfnexpr, Expr** finalfnexpr); + +extern int get_aggregate_argtypes(Aggref* aggref, Oid* inputTypes, int func_max_args); + +extern Oid resolve_aggregate_transtype(Oid aggfuncid, Oid aggtranstype, Oid* inputTypes, int numArguments); + +#endif /* PARSE_AGG_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_clause.h postgresql-hll-2.14/include/parser/parse_clause.h --- postgresql-hll-2.14_old/include/parser/parse_clause.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_clause.h 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,50 @@ +/* ------------------------------------------------------------------------- + * + * parse_clause.h + * handle clauses in parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_clause.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_CLAUSE_H +#define PARSE_CLAUSE_H + +#include "nodes/relation.h" +#include "parser/parse_node.h" + +extern void transformFromClause(ParseState* pstate, List* frmList, bool isFirstNode = true, bool isCreateView = false); +extern int setTargetTable(ParseState* pstate, RangeVar* relation, bool inh, bool alsoSource, AclMode requiredPerms); +extern bool interpretInhOption(InhOption inhOpt); +extern bool interpretOidsOption(List* defList); + +extern Node* transformFromClauseItem(ParseState* pstate, Node* n, RangeTblEntry** top_rte, int* top_rti, + RangeTblEntry** right_rte, int* right_rti, List** relnamespace, bool isFirstNode = true, + bool isCreateView = false, bool isMergeInto = false); + +extern Node* transformJoinOnClause(ParseState* pstate, JoinExpr* j, RangeTblEntry* l_rte, RangeTblEntry* r_rte, + List* relnamespace); +extern Node* transformWhereClause(ParseState* pstate, Node* clause, const char* constructName); +extern Node* transformLimitClause(ParseState* pstate, Node* clause, const char* constructName); +extern List* transformGroupClause( + ParseState* pstate, List* grouplist, List** groupingSets, List** targetlist, List* sortClause, bool useSQL99); +extern List* transformSortClause( + ParseState* pstate, List* orderlist, List** targetlist, bool resolveUnknown, bool useSQL99); + +extern List* transformWindowDefinitions(ParseState* pstate, List* windowdefs, List** targetlist); + +extern List* transformDistinctClause(ParseState* pstate, List** targetlist, List* sortClause, bool is_agg); +extern List* transformDistinctOnClause(ParseState* pstate, List* distinctlist, List** targetlist, List* sortClause); + +extern Index assignSortGroupRef(TargetEntry* tle, List* tlist); +extern bool targetIsInSortList(TargetEntry* tle, Oid sortop, List* sortList); + +extern List* addTargetToSortList( + ParseState* pstate, TargetEntry* tle, List* sortlist, List* targetlist, SortBy* sortby, bool resolveUnknown); +extern ParseNamespaceItem *makeNamespaceItem(RangeTblEntry *rte, bool lateral_only, bool lateral_ok); + +#endif /* PARSE_CLAUSE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_coerce.h postgresql-hll-2.14/include/parser/parse_coerce.h --- postgresql-hll-2.14_old/include/parser/parse_coerce.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_coerce.h 2020-12-12 17:06:43.351349380 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * parse_coerce.h + * Routines for type coercion. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_coerce.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_COERCE_H +#define PARSE_COERCE_H + +#include "parser/parse_node.h" + +/* Setup error traceback support for ereport() */ +#define ELOG_FIELD_NAME_START(fieldname) \ + ErrorContextCallback errcontext; \ + errcontext.callback = expression_error_callback; \ + errcontext.arg = (void*)(fieldname); \ + errcontext.previous = t_thrd.log_cxt.error_context_stack; \ + t_thrd.log_cxt.error_context_stack = &errcontext; + +#define ELOG_FIELD_NAME_END t_thrd.log_cxt.error_context_stack = errcontext.previous; + +/* Type categories (see TYPCATEGORY_xxx symbols in catalog/pg_type.h) */ +typedef char TYPCATEGORY; + +/* Result codes for find_coercion_pathway */ +typedef enum CoercionPathType { + COERCION_PATH_NONE, /* failed to find any coercion pathway */ + COERCION_PATH_FUNC, /* apply the specified coercion function */ + COERCION_PATH_RELABELTYPE, /* binary-compatible cast, no function */ + COERCION_PATH_ARRAYCOERCE, /* need an ArrayCoerceExpr node */ + COERCION_PATH_COERCEVIAIO /* need a CoerceViaIO node */ +} CoercionPathType; + +extern bool IsBinaryCoercible(Oid srctype, Oid targettype); +extern bool IsPreferredType(TYPCATEGORY category, Oid type); +extern TYPCATEGORY TypeCategory(Oid type); + +extern Node* coerce_to_target_type(ParseState* pstate, Node* expr, Oid exprtype, Oid targettype, int32 targettypmod, + CoercionContext ccontext, CoercionForm cformat, int location); +extern bool can_coerce_type(int nargs, Oid* input_typeids, Oid* target_typeids, CoercionContext ccontext); +extern Node* coerce_type(ParseState* pstate, Node* node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, + CoercionContext ccontext, CoercionForm cformat, int location); +extern Node* coerce_to_domain(Node* arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionForm cformat, + int location, bool hideInputCoercion, bool lengthCoercionDone); + +extern Node* coerce_to_boolean(ParseState* pstate, Node* node, const char* constructName); +extern Node* coerce_to_specific_type(ParseState* pstate, Node* node, Oid targetTypeId, const char* constructName); + +extern int parser_coercion_errposition(ParseState* pstate, int coerce_location, Node* input_expr); + +extern Oid select_common_type(ParseState* pstate, List* exprs, const char* context, Node** which_expr); +extern Node* coerce_to_common_type(ParseState* pstate, Node* node, Oid targetTypeId, const char* context); + +extern bool check_generic_type_consistency(Oid* actual_arg_types, Oid* declared_arg_types, int nargs); +extern Oid enforce_generic_type_consistency( + Oid* actual_arg_types, Oid* declared_arg_types, int nargs, Oid rettype, bool allow_poly); +extern Oid resolve_generic_type(Oid declared_type, Oid context_actual_type, Oid context_declared_type); + +extern CoercionPathType find_coercion_pathway( + Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid* funcid); +extern CoercionPathType find_typmod_coercion_function(Oid typeId, Oid* funcid); + +extern void expression_error_callback(void* arg); + +#endif /* PARSE_COERCE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_collate.h postgresql-hll-2.14/include/parser/parse_collate.h --- postgresql-hll-2.14_old/include/parser/parse_collate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_collate.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * parse_collate.h + * Routines for assigning collation information. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_collate.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_COLLATE_H +#define PARSE_COLLATE_H + +#include "parser/parse_node.h" + +extern void assign_query_collations(ParseState* pstate, Query* query); + +extern void assign_list_collations(ParseState* pstate, List* exprs); + +extern void assign_expr_collations(ParseState* pstate, Node* expr); + +extern Oid select_common_collation(ParseState* pstate, List* exprs, bool none_ok); + +#endif /* PARSE_COLLATE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_cte.h postgresql-hll-2.14/include/parser/parse_cte.h --- postgresql-hll-2.14_old/include/parser/parse_cte.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_cte.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * parse_cte.h + * handle CTEs (common table expressions) in parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_cte.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_CTE_H +#define PARSE_CTE_H + +#include "parser/parse_node.h" + +extern List* transformWithClause(ParseState* pstate, WithClause* withClause); + +extern void analyzeCTETargetList(ParseState* pstate, CommonTableExpr* cte, List* tlist); + +#endif /* PARSE_CTE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_expr.h postgresql-hll-2.14/include/parser/parse_expr.h --- postgresql-hll-2.14_old/include/parser/parse_expr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_expr.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * parse_expr.h + * handle expressions in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_expr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_EXPR_H +#define PARSE_EXPR_H + +#include "parser/parse_node.h" +#include "utils/plpgsql.h" + +extern Node* transformExpr(ParseState* pstate, Node* expr); +extern Expr* make_distinct_op(ParseState* pstate, List* opname, Node* ltree, Node* rtree, int location); +extern Oid getMultiFuncInfo(char* fun_expr, PLpgSQL_expr* expr); +extern void lockSeqForNextvalFunc(Node* node); +#endif /* PARSE_EXPR_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_func.h postgresql-hll-2.14/include/parser/parse_func.h --- postgresql-hll-2.14_old/include/parser/parse_func.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_func.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- + * + * parse_func.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_func.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSER_FUNC_H +#define PARSER_FUNC_H + +#include "catalog/namespace.h" +#include "parser/parse_node.h" + +/* + * This structure is used to explore the inheritance hierarchy above + * nodes in the type tree in order to disambiguate among polymorphic + * functions. + */ +typedef struct _InhPaths { + int nsupers; /* number of superclasses */ + Oid self; /* this class */ + Oid* supervec; /* vector of superclasses */ +} InhPaths; + +/* Result codes for func_get_detail */ +typedef enum { + FUNCDETAIL_NOTFOUND, /* no matching function */ + FUNCDETAIL_MULTIPLE, /* too many matching functions */ + FUNCDETAIL_NORMAL, /* found a matching regular function */ + FUNCDETAIL_AGGREGATE, /* found a matching aggregate function */ + FUNCDETAIL_WINDOWFUNC, /* found a matching window function */ + FUNCDETAIL_COERCION /* it's a type coercion request */ +} FuncDetailCode; + +extern Node* ParseFuncOrColumn( + ParseState* pstate, List* funcname, List* fargs, FuncCall* fn, int location, bool call_func = false); + +extern FuncDetailCode func_get_detail(List* funcname, List* fargs, List* fargnames, int nargs, Oid* argtypes, + bool expand_variadic, bool expand_defaults, Oid* funcid, Oid* rettype, bool* retset, int* nvargs, Oid* vatype, + Oid** true_typeids, List** argdefaults, bool call_func = false, Oid* refSynOid = NULL); + +extern int func_match_argtypes( + int nargs, Oid* input_typeids, FuncCandidateList raw_candidates, FuncCandidateList* candidates); + +extern FuncCandidateList func_select_candidate(int nargs, Oid* input_typeids, FuncCandidateList candidates); + +extern void make_fn_arguments(ParseState* pstate, List* fargs, Oid* actual_arg_types, Oid* declared_arg_types); + +extern const char* funcname_signature_string(const char* funcname, int nargs, List* argnames, const Oid* argtypes); +extern const char* func_signature_string(List* funcname, int nargs, List* argnames, const Oid* argtypes); + +extern Oid LookupFuncName(List* funcname, int nargs, const Oid* argtypes, bool noError); +extern Oid LookupFuncNameTypeNames(List* funcname, List* argtypes, bool noError); +extern Oid LookupFuncNameOptTypeNames(List* funcname, List* argtypes, bool noError); +extern Oid LookupAggNameTypeNames(List* aggname, List* argtypes, bool noError); + +extern void check_pg_get_expr_args(ParseState* pstate, Oid fnoid, List* args); +extern int GetPriority(Oid typeoid); +#endif /* PARSE_FUNC_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_hint.h postgresql-hll-2.14/include/parser/parse_hint.h --- postgresql-hll-2.14_old/include/parser/parse_hint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_hint.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,257 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * parse_hint.h + * Table parse hint header file, include struct member declaration. + * + * + * IDENTIFICATION + * src/include/parser/parse_hint.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARSE_HINT_h +#define PARSE_HINT_h + +#include "optimizer/streamplan.h" +#include "parser/parse_node.h" +#include "tcop/dest.h" +#include "utils/guc.h" + +/* hint keywords */ +#define HINT_NESTLOOP "NestLoop" +#define HINT_MERGEJOIN "MergeJoin" +#define HINT_HASHJOIN "HashJoin" +#define HINT_NO "No" +#define HINT_LEADING "Leading" +#define HINT_ROWS "Rows" +#define HINT_BROADCAST "Broadcast" +#define HINT_REDISTRIBUTE "Redistribute" +#define HINT_BLOCKNAME "BlockName" +#define HINT_TABLESCAN "TableScan" +#define HINT_INDEXSCAN "IndexScan" +#define HINT_INDEXONLYSCAN "IndexOnlyScan" +#define HINT_SKEW "Skew" +#define HINT_MULTI_NODE "MultiNode" +#define HINT_NULL "Null" +#define HINT_TRUE "True" +#define HINT_FALSE "False" +#define HINT_PRED_PUSH "Predpush" +#define HINT_REWRITE "Rewrite_rule" + +#define BLOCK_COMMENT_START "/*" +#define BLOCK_COMMENT_END "*/" +#define HINT_COMMENT_KEYWORD "+" +#define HINT_START BLOCK_COMMENT_START HINT_COMMENT_KEYWORD +#define HINT_END BLOCK_COMMENT_END + +typedef struct pull_hint_warning_context { + List* warning; +} pull_qual_vars_context; + +#define append_warning_to_list(root, hint, format, ...) \ + do { \ + StringInfoData buf; \ + char* hint_string = descHint(hint); \ + initStringInfo(&buf); \ + appendStringInfo(&buf, format, ##__VA_ARGS__); \ + root->glob->hint_warning = lappend(root->glob->hint_warning, makeString(buf.data)); \ + pfree(hint_string); \ + } while (0) + +extern THR_LOCAL List* hint_list; +extern THR_LOCAL List* hint_warning; + +/* hint keyword of enum type*/ +typedef enum HintKeyword { + HINT_KEYWORD_NESTLOOP = 0, + HINT_KEYWORD_MERGEJOIN, + HINT_KEYWORD_HASHJOIN, + HINT_KEYWORD_LEADING, + HINT_KEYWORD_ROWS, + HINT_KEYWORD_BROADCAST, + HINT_KEYWORD_REDISTRIBUTE, + HINT_KEYWORD_BLOCKNAME, + HINT_KEYWORD_TABLESCAN, + HINT_KEYWORD_INDEXSCAN, + HINT_KEYWORD_INDEXONLYSCAN, + HINT_KEYWORD_SKEW, + HINT_KEYWORD_PREDPUSH, + HINT_KEYWORD_REWRITE, +} HintKeyword; + +/* hint status */ +typedef enum HintStatus { + HINT_STATE_NOTUSED = 0, /* specified relation not used in query */ + HINT_STATE_USED, /* hint is used */ + HINT_STATE_DUPLICATION /* specified hint duplication */ +} HintStatus; + +/* common data for all hints. */ +struct Hint { + NodeTag type; /* Hint type */ + List* relnames; /* relation name list */ + HintKeyword hint_keyword; /* Hint Keyword */ + HintStatus state; /* hint used state */ +}; + +typedef struct LeadingHint { + Hint base; /* Base hint */ + bool join_order_hint; /* If join order is hinted */ +} LeadingHint; + +/* join method hints */ +typedef struct JoinMethodHint { + Hint base; /* Base hint */ + bool negative; /* Positive or negative? */ + Relids joinrelids; /* Join relids */ + Relids inner_joinrelids; /* Inner relids */ +} JoinMethodHint; + +/* rows hints kind */ +typedef enum RowsValueType { + RVT_ABSOLUTE, /* Rows(... #1000) absolute rows */ + RVT_ADD, /* Rows(... +1000) add rows */ + RVT_SUB, /* Rows(... -1000) subtract rows */ + RVT_MULTI /* Rows(... *1.2) multiply rows */ +} RowsValueType; + +/* rows hint */ +typedef struct RowsHint { + Hint base; /* base hint */ + Relids joinrelids; /* Join relids */ + char* rows_str; /* Row string */ + RowsValueType value_type; /* hints kind */ + double rows; /* Rows */ +} RowsHint; + +typedef struct StreamHint { + Hint base; /* base hint */ + bool negative; /* Positive or negative? */ + Relids joinrelids; /* Join relids */ + StreamType stream_type; /* Stream type, redistribute or broadcast */ +} StreamHint; + +typedef struct BlockNameHint { + Hint base; /* base hint */ + /* Block name will be stored in base.relname. */ +} BlockNameHint; + +/* scan method hints */ +typedef struct ScanMethodHint { + Hint base; + bool negative; + Relids relid; + List* indexlist; +} ScanMethodHint; + +/* skew hints */ +typedef struct SkewHint { + Hint base; /* base hint */ + Relids relid; /* skew relation relids */ + List* column_list; /* skew column list */ + List* value_list; /* skew value list */ +} SkewHint; + +/* multinode hints */ +typedef struct MultiNodeHint { + Hint base; /* base hint */ + bool multi_node_hint; +} MultiNodeHint; + +/* relation information from RangeTblEntry and pg_class */ +typedef struct SkewRelInfo { + NodeTag type; + char* relation_name; /* relation name */ + Oid relation_oid; /* relation`s oid */ + RangeTblEntry* rte; /* relation`s rte */ + RangeTblEntry* parent_rte; /* if relation comes from subquery, then it`s subquery`s rte */ +} SkewRelInfo; + +/* column information from PG_ATTRIBUTE or targetEntry */ +typedef struct SkewColumnInfo { + NodeTag type; + Oid relation_Oid; /* table`s oid */ + char* column_name; /* column`s name */ + AttrNumber attnum; /* column's location in relation */ + Oid column_typid; /* column`s type oid */ + Expr* expr; /* expr that column comes from */ +} SkewColumnInfo; + +/* make skew value to Const */ +typedef struct SkewValueInfo { + NodeTag type; + bool support_redis; /* column type whether support redistribution, if not the const_value will be null */ + Const* const_value; /* skew value */ +} SkewValueInfo; + +/* SkewHint structure after transform */ +typedef struct SkewHintTransf { + NodeTag type; + SkewHint* before; /* skew hint struct before transform */ + List* rel_info_list; /* relation info list after transform */ + List* column_info_list; /* column info list after transform */ + List* value_info_list; /* value info list after transform */ +} SkewHintTransf; + +/* prompts which predicates can be pushdown */ +typedef struct PredpushHint { + Hint base; /* base hint */ + bool negative; + char *dest_name; + int dest_id; + Relids candidates; /* which one will be push down */ +} PredpushHint; + +/* Enable/disable rewrites with hint */ +typedef struct RewriteHint { + Hint base; /* base hint */ + List* param_names; /* rewrite parameters */ + unsigned int param_bits; +} RewriteHint; + +typedef struct hintKeyword { + const char* name; + int value; +} hintKeyword; + +extern HintState* HintStateCreate(); +extern HintState* create_hintstate(const char* hints); +extern List* find_specific_join_hint( + HintState* hstate, Relids joinrelids, Relids innerrelids, HintKeyword keyWord, bool leading = true); +extern List* find_specific_scan_hint(HintState* hstate, Relids relids, HintKeyword keyWord); +extern ScanMethodHint* find_scan_hint(HintState* hstate, Relids relid, HintKeyword keyWord); +extern char* descHint(Hint* hint); +extern void hintDelete(Hint* hint); +extern void desc_hint_in_state(PlannerInfo* root, HintState* hstate); + +extern void transform_hints(PlannerInfo* root, Query* parse, HintState* hstate); + +extern void check_scan_hint_validity(PlannerInfo* root); +extern void adjust_scanhint_relid(HintState* hstate, Index oldIdx, Index newIdx); +extern bool pull_hint_warning_walker(Node* node, pull_qual_vars_context* context); +extern List* retrieve_query_hint_warning(Node* parse); +extern void output_utility_hint_warning(Node* query, int lev); +extern void output_hint_warning(List* warning, int lev); +extern void HintStateDelete(HintState* hintState); +extern bool permit_predpush(PlannerInfo *root); +extern bool permit_from_rewrite_hint(PlannerInfo *root, unsigned int params); +extern Relids predpush_candidates_same_level(PlannerInfo *root); + +#define skip_space(str) \ + while (isspace(*str)) \ + str++; +#endif diff -uprN postgresql-hll-2.14_old/include/parser/parse_merge.h postgresql-hll-2.14/include/parser/parse_merge.h --- postgresql-hll-2.14_old/include/parser/parse_merge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_merge.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * parse_merge.h + * handle merge-stmt in parser + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/parser/parse_merge.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PARSE_MERGE_H +#define PARSE_MERGE_H + +#include "parser/parse_node.h" +extern Query* transformMergeStmt(ParseState* pstate, MergeStmt* stmt); +extern List* expandTargetTL(List* te_list, Query* parsetree); +extern List* expandActionTL(List* te_list, Query* parsetree); +extern List* expandQualTL(List* te_list, Query* parsetree); +extern bool check_unique_constraint(List*& index_list); +#endif diff -uprN postgresql-hll-2.14_old/include/parser/parse_node.h postgresql-hll-2.14/include/parser/parse_node.h --- postgresql-hll-2.14_old/include/parser/parse_node.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_node.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,204 @@ +/* ------------------------------------------------------------------------- + * + * parse_node.h + * Internal definitions for parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_node.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_NODE_H +#define PARSE_NODE_H + +#include "nodes/parsenodes.h" +#include "parser/analyze.h" +#include "utils/relcache.h" + +typedef struct PlusJoinRTEInfo { + bool needrecord; /* need record the RTE info for plus join? only in WhereClause is true for now */ + List* info; /* List of PlusJoinRTEItem we record */ +} PlusJoinRTEInfo; + +/* + * Function signatures for parser hooks + */ +typedef struct ParseState ParseState; + +typedef Node* (*PreParseColumnRefHook)(ParseState* pstate, ColumnRef* cref); +typedef Node* (*PostParseColumnRefHook)(ParseState* pstate, ColumnRef* cref, Node* var); +typedef Node* (*ParseParamRefHook)(ParseState* pstate, ParamRef* pref); +typedef Node* (*CoerceParamHook)(ParseState* pstate, Param* param, Oid targetTypeId, int32 targetTypeMod, int location); + +/* + * State information used during parse analysis + * + * parentParseState: NULL in a top-level ParseState. When parsing a subquery, + * links to current parse state of outer query. + * + * p_sourcetext: source string that generated the raw parsetree being + * analyzed, or NULL if not available. (The string is used only to + * generate cursor positions in error messages: we need it to convert + * byte-wise locations in parse structures to character-wise cursor + * positions.) + * + * p_rtable: list of RTEs that will become the rangetable of the query. + * Note that neither relname nor refname of these entries are necessarily + * unique; searching the rtable by name is a bad idea. + * + * p_joinexprs: list of JoinExpr nodes associated with p_rtable entries. + * This is one-for-one with p_rtable, but contains NULLs for non-join + * RTEs, and may be shorter than p_rtable if the last RTE(s) aren't joins. + * + * p_joinlist: list of join items (RangeTblRef and JoinExpr nodes) that + * will become the fromlist of the query's top-level FromExpr node. + * + * p_relnamespace: list of RTEs that represents the current namespace for + * table lookup, ie, those RTEs that are accessible by qualified names. + * This may be just a subset of the rtable + joinlist, and/or may contain + * entries that are not yet added to the main joinlist. + * + * p_varnamespace: list of RTEs that represents the current namespace for + * column lookup, ie, those RTEs that are accessible by unqualified names. + * This is different from p_relnamespace because a JOIN without an alias does + * not hide the contained tables (so they must still be in p_relnamespace) + * but it does hide their columns (unqualified references to the columns must + * refer to the JOIN, not the member tables). Other special RTEs such as + * NEW/OLD for rules may also appear in just one of these lists. + * + * p_ctenamespace: list of CommonTableExprs (WITH items) that are visible + * at the moment. This is different from p_relnamespace because you have + * to make an RTE before you can access a CTE. + * + * p_future_ctes: list of CommonTableExprs (WITH items) that are not yet + * visible due to scope rules. This is used to help improve error messages. + * + * p_parent_cte: CommonTableExpr that immediately contains the current query, + * if any. + * + * p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses. + * We collect these while transforming expressions and then transform them + * afterwards (so that any resjunk tlist items needed for the sort/group + * clauses end up at the end of the query tlist). A WindowDef's location in + * this list, counting from 1, is the winref number to use to reference it. + */ +struct ParseState { + struct ParseState* parentParseState; /* stack link */ + const char* p_sourcetext; /* source text, or NULL if not available */ + List* p_rtable; /* range table so far */ + List* p_joinexprs; /* JoinExprs for RTE_JOIN p_rtable entries */ + List* p_joinlist; /* join items so far (will become FromExpr + node's fromlist) */ + List* p_relnamespace; /* current namespace for relations */ + List* p_varnamespace; /* current namespace for columns */ + bool p_lateral_active; /* p_lateral_only items visible? */ + List* p_ctenamespace; /* current namespace for common table exprs */ + List* p_future_ctes; /* common table exprs not yet in namespace */ + CommonTableExpr* p_parent_cte; /* this query's containing CTE */ + List* p_windowdefs; /* raw representations of window clauses */ + int p_next_resno; /* next targetlist resno to assign */ + List* p_locking_clause; /* raw FOR UPDATE/FOR SHARE info */ + Node* p_value_substitute; /* what to replace VALUE with, if any */ + bool p_hasAggs; + bool p_hasWindowFuncs; + bool p_hasSubLinks; + bool p_hasModifyingCTE; + bool p_is_insert; + bool p_locked_from_parent; + bool p_resolve_unknowns; /* resolve unknown-type SELECT outputs as type text */ + bool p_hasSynonyms; + Relation p_target_relation; + RangeTblEntry* p_target_rangetblentry; + + /* + * Optional hook functions for parser callbacks. These are null unless + * set up by the caller of make_parsestate. + */ + PreParseColumnRefHook p_pre_columnref_hook; + PostParseColumnRefHook p_post_columnref_hook; + ParseParamRefHook p_paramref_hook; + CoerceParamHook p_coerce_param_hook; + void* p_ref_hook_state; /* common passthrough link for above */ + List* p_target_list; + + /* + * star flag info + * + * create table t1(a int, b int); + * create table t2(a int, b int); + * + * For query: select * from t1 + * star_start = 1; + * star_end = 2; + * star_only = 1; + * + * For query: select t1.*, t2.* from t1, t2 + * star_start = 1, 3; + * star_end = 2, 4; + * star_only = -1, -1; + */ + List* p_star_start; + List* p_star_end; + List* p_star_only; + + /* + * The p_is_in_insert will indicate the sub link is under one top insert statement. + * When p_is_in_insert is true, then we will check if sub link include foreign table, + * If foreign is found, we will set top level insert ParseState's p_is_foreignTbl_exist to true. + * Finially, we will set p_is_td_compatible_truncation to true if the td_compatible_truncation guc + * parameter is on, no foreign table involved in this insert statement. + */ + bool p_is_foreignTbl_exist; /* make there is foreign table founded. */ + bool p_is_in_insert; /* mark the subquery is under one insert statement. */ + bool p_is_td_compatible_truncation; /* mark the auto truncation for insert statement is enabled. */ + TdTruncCastStatus tdTruncCastStatus; /* Auto truncation Cast added, only used for stmt in stored procedure or + prepare stmt. */ + bool isAliasReplace; /* Mark if permit replace. */ + + /* + * Fields for transform "(+)" to outerjoin + */ + bool ignoreplus; /* + * Whether ignore "(+)" during transform stmt? False is default, + * report error when found "(+)". Only true when transform WhereClause + * in SelectStmt. + */ + + PlusJoinRTEInfo* p_plusjoin_rte_info; /* The RTE info while processing "(+)" */ +}; + +/* An element of p_relnamespace or p_varnamespace */ +typedef struct ParseNamespaceItem +{ + RangeTblEntry *p_rte; /* The relation's rangetable entry */ + bool p_lateral_only; /* Is only visible to LATERAL expressions? */ + bool p_lateral_ok; /* If so, does join type allow use? */ +} ParseNamespaceItem; + +/* Support for parser_errposition_callback function */ +typedef struct ParseCallbackState { + ParseState* pstate; + int location; +#ifndef FRONTEND + ErrorContextCallback errcontext; +#endif +} ParseCallbackState; + +extern ParseState* make_parsestate(ParseState* parentParseState); +extern void free_parsestate(ParseState* pstate); +extern int parser_errposition(ParseState* pstate, int location); + +extern void setup_parser_errposition_callback(ParseCallbackState* pcbstate, ParseState* pstate, int location); +extern void cancel_parser_errposition_callback(ParseCallbackState* pcbstate); + +extern Var* make_var(ParseState* pstate, RangeTblEntry* rte, int attrno, int location); +extern Var* ts_make_var(ParseState* pstate, RangeTblEntry* rte, int attrno, int location); +extern Oid transformArrayType(Oid* arrayType, int32* arrayTypmod); +extern ArrayRef* transformArraySubscripts(ParseState* pstate, Node* arrayBase, Oid arrayType, Oid elementType, + int32 arrayTypMod, List* indirection, Node* assignFrom); +extern Const* make_const(ParseState* pstate, Value* value, int location); + +#endif /* PARSE_NODE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_oper.h postgresql-hll-2.14/include/parser/parse_oper.h --- postgresql-hll-2.14_old/include/parser/parse_oper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_oper.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------- + * + * parse_oper.h + * handle operator things for parser + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_oper.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_OPER_H +#define PARSE_OPER_H + +#include "access/htup.h" +#include "parser/parse_node.h" + +typedef HeapTuple Operator; + +/* Routines to look up an operator given name and exact input type(s) */ +extern Oid LookupOperName(ParseState* pstate, List* opername, Oid oprleft, Oid oprright, bool noError, int location); +extern Oid LookupOperNameTypeNames( + ParseState* pstate, List* opername, TypeName* oprleft, TypeName* oprright, bool noError, int location); + +/* Routines to find operators matching a name and given input types */ +/* NB: the selected operator may require coercion of the input types! */ +extern Operator oper( + ParseState* pstate, List* op, Oid arg1, Oid arg2, bool noError, int location, bool inNumeric = false); +extern Operator right_oper(ParseState* pstate, List* op, Oid arg, bool noError, int location); +extern Operator left_oper(ParseState* pstate, List* op, Oid arg, bool noError, int location); + +/* Routines to find operators that DO NOT require coercion --- ie, their */ +/* input types are either exactly as given, or binary-compatible */ +extern Operator compatible_oper(ParseState* pstate, List* op, Oid arg1, Oid arg2, bool noError, int location); + +/* currently no need for compatible_left_oper/compatible_right_oper */ +/* Routines for identifying "<", "=", ">" operators for a type */ +extern void get_sort_group_operators( + Oid argtype, bool needLT, bool needEQ, bool needGT, Oid* ltOpr, Oid* eqOpr, Oid* gtOpr, bool* isHashable); + +/* Convenience routines for common calls on the above */ +extern Oid compatible_oper_opid(List* op, Oid arg1, Oid arg2, bool noError); + +/* Extract operator OID or underlying-function OID from an Operator tuple */ +extern Oid oprid(Operator op); +extern Oid oprfuncid(Operator op); + +extern bool IsIntType(Oid typeoid); +extern bool IsCharType(Oid typeoid); + +/* Build expression tree for an operator invocation */ +extern Expr* make_op(ParseState* pstate, List* opname, Node* ltree, Node* rtree, int location, bool inNumeric = false); +extern Expr* make_scalar_array_op(ParseState* pstate, List* opname, bool useOr, Node* ltree, Node* rtree, int location); +extern Oid OperatorLookup(List* operatorName, Oid leftObjectId, Oid rightObjectId, bool* defined); +extern void InvalidateOprCacheCallBack(Datum arg, int cacheid, uint32 hashvalue); +#endif /* PARSE_OPER_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_param.h postgresql-hll-2.14/include/parser/parse_param.h --- postgresql-hll-2.14_old/include/parser/parse_param.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_param.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * parse_param.h + * handle parameters in parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_param.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_PARAM_H +#define PARSE_PARAM_H + +#include "parser/parse_node.h" + +extern void parse_fixed_parameters(ParseState* pstate, Oid* paramTypes, int numParams); +extern void parse_variable_parameters(ParseState* pstate, Oid** paramTypes, int* numParams); +extern void check_variable_parameters(ParseState* pstate, Query* query); + +#endif /* PARSE_PARAM_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_relation.h postgresql-hll-2.14/include/parser/parse_relation.h --- postgresql-hll-2.14_old/include/parser/parse_relation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_relation.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * parse_relation.h + * prototypes for parse_relation.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_relation.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_RELATION_H +#define PARSE_RELATION_H + +#include "parser/parse_node.h" + +extern RangeTblEntry* refnameRangeTblEntry( + ParseState* pstate, const char* schemaname, const char* refname, int location, int* sublevels_up); +extern CommonTableExpr* scanNameSpaceForCTE(ParseState* pstate, const char* refname, Index* ctelevelsup); +extern void checkNameSpaceConflicts(ParseState* pstate, List* namespace1, List* namespace2); +extern int RTERangeTablePosn(ParseState* pstate, RangeTblEntry* rte, int* sublevels_up); +extern RangeTblEntry* GetRTEByRangeTablePosn(ParseState* pstate, int varno, int sublevels_up); +extern CommonTableExpr* GetCTEForRTE(ParseState* pstate, RangeTblEntry* rte, int rtelevelsup); +extern Node* scanRTEForColumn(ParseState* pstate, RangeTblEntry* rte, char* colname, int location, bool omit = false); +extern Node* colNameToVar( + ParseState* pstate, char* colname, bool localonly, int location, RangeTblEntry** final_rte = NULL); +extern void markVarForSelectPriv(ParseState* pstate, Var* var, RangeTblEntry* rte); +extern Relation parserOpenTable(ParseState* pstate, const RangeVar* relation, int lockmode, bool isFirstNode = true, + bool isCreateView = false, bool isSupportSynonym = false); +extern RangeTblEntry* addRangeTableEntry(ParseState* pstate, RangeVar* relation, Alias* alias, bool inh, bool inFromCl, + bool isFirstNode = true, bool isCreateView = false, bool isSupportSynonym = false); +extern RangeTblEntry* addRangeTableEntryForRelation( + ParseState* pstate, Relation rel, Alias* alias, bool inh, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForSubquery( + ParseState* pstate, Query* subquery, Alias* alias, bool lateral, bool inFromCl, bool sublinkPullUp = false); +extern RangeTblEntry* addRangeTableEntryForFunction( + ParseState* pstate, char* funcname, Node* funcexpr, RangeFunction* rangefunc, bool lateral, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForValues( + ParseState* pstate, List* exprs, List* collations, Alias* alias, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForJoin( + ParseState* pstate, List* colnames, JoinType jointype, List* aliasvars, Alias* alias, bool inFromCl); +extern RangeTblEntry* addRangeTableEntryForCTE( + ParseState* pstate, CommonTableExpr* cte, Index levelsup, RangeVar* rv, bool inFromCl); +extern RangeTblEntry* getRangeTableEntryByRelation(Relation rel); +extern bool isLockedRefname(ParseState* pstate, const char* refname); +extern void addRTEtoQuery( + ParseState* pstate, RangeTblEntry* rte, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace); +extern void errorMissingRTE(ParseState* pstate, RangeVar* relation, bool hasplus = false); +extern void errorMissingColumn(ParseState *pstate, char *relname, char *colname, int location); +extern void expandRTE(RangeTblEntry* rte, int rtindex, int sublevels_up, int location, bool include_dropped, + List** colnames, List** colvars); +extern List* expandRelAttrs(ParseState* pstate, RangeTblEntry* rte, int rtindex, int sublevels_up, int location); +extern int attnameAttNum(Relation rd, const char* attname, bool sysColOK); +extern Name attnumAttName(Relation rd, int attid); +extern Oid attnumTypeId(Relation rd, int attid); +extern Oid attnumCollationId(Relation rd, int attid); + +#ifdef PGXC +extern int specialAttNum(const char* attname); +#endif + +#endif /* PARSE_RELATION_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parser.h postgresql-hll-2.14/include/parser/parser.h --- postgresql-hll-2.14_old/include/parser/parser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parser.h 2020-12-12 17:06:43.352349393 +0800 @@ -0,0 +1,47 @@ +/* ------------------------------------------------------------------------- + * + * parser.h + * Definitions for the "raw" parser (flex and bison phases only) + * + * This is the external API for the raw lexing/parsing functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parser.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSER_H +#define PARSER_H + +#ifndef FRONTEND_PARSER +#include "nodes/parsenodes.h" +#else +#include "nodes/parsenodes_common.h" +#endif /* FRONTEND_PARSER */ + +#include "parser/backslash_quotes.h" + +#define UPSERT_TO_MERGE_VERSION_NUM 92022 + +/* Primary entry point for the raw parsing functions */ +extern List* raw_parser(const char* str, List** query_string_locationlist = NULL); + +#ifdef FRONTEND_PARSER + +class PGClientLogic; + +extern List *fe_raw_parser(PGClientLogic*, const char *str, List **query_string_locationlist = NULL); +#endif /* FRONTEND_PARSER */ + +/* Utility functions exported by gram.y (perhaps these should be elsewhere) */ +extern List* SystemFuncName(char* name); +extern TypeName* SystemTypeName(char* name); +extern Node* makeBoolAConst(bool state, int location); +extern char** get_next_snippet( + char** query_string_single, const char* query_string, List* query_string_locationlist, int* stmt_num); + +extern void fixResTargetNameWithAlias(List* clause_list, const char* aliasname); + +#endif /* PARSER_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_target.h postgresql-hll-2.14/include/parser/parse_target.h --- postgresql-hll-2.14_old/include/parser/parse_target.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_target.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,33 @@ +/* ------------------------------------------------------------------------- + * + * parse_target.h + * handle target lists + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_target.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_TARGET_H +#define PARSE_TARGET_H + +#include "parser/parse_node.h" + +extern List* transformTargetList(ParseState* pstate, List* targetlist); +extern List* transformExpressionList(ParseState* pstate, List* exprlist); +extern void markTargetListOrigins(ParseState* pstate, List* targetlist); +extern void resolveTargetListUnknowns(ParseState* pstate, List* targetlist); +extern TargetEntry* transformTargetEntry(ParseState* pstate, Node* node, Node* expr, char* colname, bool resjunk); +extern Expr* transformAssignedExpr( + ParseState* pstate, Expr* expr, char* colname, int attrno, List* indirection, int location); +extern void updateTargetListEntry( + ParseState* pstate, TargetEntry* tle, char* colname, int attrno, List* indirection, int location); +extern List* checkInsertTargets(ParseState* pstate, List* cols, List** attrnos); +extern TupleDesc expandRecordVariable(ParseState* pstate, Var* var, int levelsup); +extern char* FigureColname(Node* node); +extern char* FigureIndexColname(Node* node); + +#endif /* PARSE_TARGET_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parsetree.h postgresql-hll-2.14/include/parser/parsetree.h --- postgresql-hll-2.14_old/include/parser/parsetree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parsetree.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * parsetree.h + * Routines to access various components and subcomponents of + * parse trees. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parsetree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSETREE_H +#define PARSETREE_H + +#include "nodes/parsenodes.h" + +/* ---------------- + * range table operations + * ---------------- + */ +/* + * rt_fetch + * + * NB: this will crash and burn if handed an out-of-range RT index + */ +#define rt_fetch(rangetable_index, rangetable) ((RangeTblEntry*)list_nth(rangetable, (rangetable_index)-1)) + +/* + * getrelid + * + * Given the range index of a relation, return the corresponding + * relation OID. Note that InvalidOid will be returned if the + * RTE is for a non-relation-type RTE. + */ +#define getrelid(rangeindex, rangetable) (rt_fetch(rangeindex, rangetable)->relid) + +/* + * Given an RTE and an attribute number, return the appropriate + * variable name or alias for that attribute of that RTE. + */ +extern char* get_rte_attribute_name(RangeTblEntry* rte, AttrNumber attnum); + +/* + * Given an RTE and an attribute number, return the appropriate + * type and typemod info for that attribute of that RTE. + */ +extern void get_rte_attribute_type( + RangeTblEntry* rte, AttrNumber attnum, Oid* vartype, int32* vartypmod, Oid* varcollid, int* kvtype = NULL); + +/* + * Check whether an attribute of an RTE has been dropped (note that + * get_rte_attribute_type will fail on such an attr) + */ +extern bool get_rte_attribute_is_dropped(RangeTblEntry* rte, AttrNumber attnum); + +/* ---------------- + * target list operations + * ---------------- + */ +extern TargetEntry* get_tle_by_resno(List* tlist, AttrNumber resno); + +/* ---------------- + * FOR UPDATE/SHARE info + * ---------------- + */ +extern RowMarkClause* get_parse_rowmark(Query* qry, Index rtindex); + +#endif /* PARSETREE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_type.h postgresql-hll-2.14/include/parser/parse_type.h --- postgresql-hll-2.14_old/include/parser/parse_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_type.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- + * + * parse_type.h + * handle type operations for parser + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/parse_type.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_TYPE_H +#define PARSE_TYPE_H + +#include "access/htup.h" +#include "parser/parse_node.h" + +typedef HeapTuple Type; + +extern Type LookupTypeName(ParseState* pstate, const TypeName* typname, int32* typmod_p, bool print_notice = true); +extern Type typenameType(ParseState* pstate, const TypeName* typname, int32* typmod_p); +extern Oid typenameTypeId(ParseState* pstate, const TypeName* typname); +extern void typenameTypeIdAndMod(ParseState* pstate, const TypeName* typname, Oid* typeid_p, int32* typmod_p); + +extern char* TypeNameToString(const TypeName* typname); +extern char* TypeNameListToString(List* typenames); + +extern Oid LookupCollation(ParseState* pstate, List* collnames, int location); +extern Oid GetColumnDefCollation(ParseState* pstate, ColumnDef* coldef, Oid typeOid); + +extern Type typeidType(Oid id); + +extern Oid typeTypeId(Type tp); +extern int16 typeLen(Type t); +extern bool typeByVal(Type t); +extern char* typeTypeName(Type t); +extern Oid typeTypeRelid(Type typ); +extern Oid typeTypeCollation(Type typ); +extern Datum stringTypeDatum(Type tp, char* string, int32 atttypmod); + +extern Oid typeidTypeRelid(Oid type_id); +extern bool IsTypeSupportedByCStore(_in_ Oid typeOid, _in_ int32 typeMod); +extern bool IsTypeSupportedByORCRelation(_in_ Oid typeOid); +extern bool IsTypeSupportedByTsStore(_in_ int kvtype, _in_ Oid typeOid); + +extern void parseTypeString(const char* str, Oid* typeid_p, int32* typmod_p); +extern bool IsTypeTableInInstallationGroup(const Type type_tup); +#define ISCOMPLEX(typeid) (typeidTypeRelid(typeid) != InvalidOid) + +#endif /* PARSE_TYPE_H */ diff -uprN postgresql-hll-2.14_old/include/parser/parse_utilcmd.h postgresql-hll-2.14/include/parser/parse_utilcmd.h --- postgresql-hll-2.14_old/include/parser/parse_utilcmd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/parse_utilcmd.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------- + * + * parse_utilcmd.h + * parse analysis for utility commands + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/parser/parse_utilcmd.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PARSE_UTILCMD_H +#define PARSE_UTILCMD_H + +#include "parser/parse_node.h" + +extern void checkPartitionSynax(CreateStmt *stmt); +extern List* transformCreateStmt(CreateStmt* stmt, const char* queryString, const List* uuids, + bool preCheck, bool isFirstNode = true); +extern List* transformAlterTableStmt(Oid relid, AlterTableStmt* stmt, const char* queryString); +extern IndexStmt* transformIndexStmt(Oid relid, IndexStmt* stmt, const char* queryString); +extern void transformRuleStmt(RuleStmt* stmt, const char* queryString, List** actions, Node** whereClause); +extern List* transformCreateSchemaStmt(CreateSchemaStmt* stmt); +extern void transformRangePartitionValue(ParseState* pstate, Node* rangePartDef, bool needCheck); +extern List* transformListPartitionValue(ParseState* pstate, List* boundary, bool needCheck, bool needFree); +extern List* transformRangePartitionValueInternal(ParseState* pstate, List* boundary, + bool needCheck, bool needFree, bool isPartition = true); +extern Node* transformIntoConst(ParseState* pstate, Node* maxElem, bool isPartition = true); + +#ifdef PGXC +extern bool CheckLocalIndexColumn(char loctype, char* partcolname, char* indexcolname); +#endif +extern Oid generateClonedIndex(Relation source_idx, Relation source_relation, char* tempIndexName, Oid targetTblspcOid, + bool skip_build, bool partitionedIndex); +extern void checkPartitionName(List* partitionList, bool isPartition = true); + +extern Oid searchSeqidFromExpr(Node* cooked_default); +extern bool is_start_end_def_list(List* def_list); +extern void get_range_partition_name_prefix(char* namePrefix, char* srcName, bool printNotice, bool isPartition); +extern List* transformRangePartStartEndStmt(ParseState* pstate, List* partitionList, List* pos, + Form_pg_attribute* attrs, int32 existPartNum, Const* lowBound, Const* upBound, bool needFree, + bool isPartition = true); +extern bool check_contains_tbllike_in_multi_nodegroup(CreateStmt* stmt); +extern bool is_multi_nodegroup_createtbllike(PGXCSubCluster* subcluster, Oid oid); + +#endif /* PARSE_UTILCMD_H */ diff -uprN postgresql-hll-2.14_old/include/parser/scanner.h postgresql-hll-2.14/include/parser/scanner.h --- postgresql-hll-2.14_old/include/parser/scanner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/scanner.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,149 @@ +/* ------------------------------------------------------------------------- + * + * scanner.h + * API for the core scanner (flex machine) + * + * The core scanner is also used by PL/pgsql, so we provide a public API + * for it. However, the rest of the backend is only expected to use the + * higher-level API provided by parser.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/scanner.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCANNER_H +#define SCANNER_H + +#include "nodes/parsenodes_common.h" +#include "parser/keywords.h" + +#ifdef FRONTEND_PARSER +#include +#define ereport(a, b) fe_rethrow(yyscanner) +#endif + +/* + * The scanner returns extra data about scanned tokens in this union type. + * Note that this is a subset of the fields used in YYSTYPE of the bison + * parsers built atop the scanner. + */ +typedef union core_YYSTYPE { + int ival; /* for integer literals */ + char* str; /* for identifiers and non-integer literals */ + const char* keyword; /* canonical spelling of keywords */ +} core_YYSTYPE; + +/* + * We track token locations in terms of byte offsets from the start of the + * source string, not the column number/line number representation that + * bison uses by default. Also, to minimize overhead we track only one + * location (usually the first token location) for each construct, not + * the beginning and ending locations as bison does by default. It's + * therefore sufficient to make YYLTYPE an int. + */ +#define YYLTYPE int + +/* + * Another important component of the scanner's API is the token code numbers. + * However, those are not defined in this file, because bison insists on + * defining them for itself. The token codes used by the core scanner are + * the ASCII characters plus these: + * %token IDENT FCONST SCONST BCONST XCONST Op + * %token ICONST PARAM + * %token TYPECAST DOT_DOT COLON_EQUALS PARA_EQUALS + * The above token definitions *must* be the first ones declared in any + * bison parser built atop this scanner, so that they will have consistent + * numbers assigned to them (specifically, IDENT = 258 and so on). + */ + +/* + * The YY_EXTRA data that a flex scanner allows us to pass around. + * Private state needed by the core scanner goes here. Note that the actual + * yy_extra struct may be larger and have this as its first component, thus + * allowing the calling parser to keep some fields of its own in YY_EXTRA. + */ +typedef struct core_yy_extra_type { + /* + * The string the scanner is physically scanning. We keep this mainly so + * that we can cheaply compute the offset of the current token (yytext). + */ + char* scanbuf; + Size scanbuflen; + + /* + * The keyword list to use. + */ + const ScanKeyword* keywords; + int num_keywords; + + /* + * literalbuf is used to accumulate literal values when multiple rules are + * needed to parse a single literal. Call startlit() to reset buffer to + * empty, addlit() to add text. NOTE: the string in literalbuf is NOT + * necessarily null-terminated, but there always IS room to add a trailing + * null at offset literallen. We store a null only when we need it. + */ + char* literalbuf; /* palloc'd expandable buffer */ + int literallen; /* actual current string length */ + int literalalloc; /* current allocated buffer size */ + + int xcdepth; /* depth of nesting in slash-star comments */ + char* dolqstart; /* current $foo$ quote start string */ + + /* first part of UTF16 surrogate pair for Unicode escapes */ + int32 utf16_first_part; + + /* state variables for literal-lexing warnings */ + bool warn_on_first_escape; + bool saw_non_ascii; + bool ident_quoted; + bool warnOnTruncateIdent; + + /* record the message need by multi-query. */ + List* query_string_locationlist; /* record the end location of each single query */ + bool in_slash_proc_body; /* check whether it's in a slash proc body */ + int paren_depth; /* record the current depth in the '(' and ')' */ + bool is_createstmt; /* check whether it's a create statement. */ + bool is_hint_str; /* current identifier is in hint comment string */ + List* parameter_list; /* placeholder parameter list */ +} core_yy_extra_type; + +#ifdef FRONTEND_PARSER + +class PGClientLogic; + +void fe_rethrow(void *yyscanner); +struct fe_core_yy_extra_type : public core_yy_extra_type { +public: + jmp_buf jump_buffer; + PGClientLogic *m_clientLogic; +}; +#endif /* FRONTEND_PARSER */ + +/* + * The type of yyscanner is opaque outside scan.l. + */ +typedef void* core_yyscan_t; +typedef void* yyscan_t; + +/* Entry points in parser/scan.l */ +extern core_yyscan_t scanner_init( + const char* str, core_yy_extra_type* yyext, const ScanKeyword* keywords, int num_keywords); + +#ifdef FRONTEND_PARSER +extern core_yyscan_t fe_scanner_init(const char *str, fe_core_yy_extra_type *yyext, + const ScanKeyword *keywords, int num_keywords); +#endif /* FRONTEND_PARSER */ + +extern void scanner_finish(core_yyscan_t yyscanner); +extern int core_yylex(core_YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner); +extern int scanner_errposition(int location, core_yyscan_t yyscanner); +extern void scanner_yyerror(const char* message, core_yyscan_t yyscanner); + +#endif /* SCANNER_H */ + diff -uprN postgresql-hll-2.14_old/include/parser/scansup.h postgresql-hll-2.14/include/parser/scansup.h --- postgresql-hll-2.14_old/include/parser/scansup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/parser/scansup.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * scansup.h + * scanner support routines. used by both the bootstrap lexer + * as well as the normal lexer + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/parser/scansup.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef SCANSUP_H +#define SCANSUP_H + +extern char* scanstr(const char* s); + +extern char* downcase_truncate_identifier(const char* ident, int len, bool warn); + +extern void truncate_identifier(char* ident, int len, bool warn); + +extern bool scanner_isspace(char ch); + +#endif /* SCANSUP_H */ diff -uprN postgresql-hll-2.14_old/include/pgaudit.h postgresql-hll-2.14/include/pgaudit.h --- postgresql-hll-2.14_old/include/pgaudit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgaudit.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,154 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pgaudit.h + * + * + * + * IDENTIFICATION + * src/include/pgaudit.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PGAUDIT_H +#define _PGAUDIT_H + +#include "fmgr.h" + +extern THR_LOCAL bool Audit_delete; + +#define AUDIT_EXEC_ENABLED (u_sess->attr.attr_security.Audit_enabled && u_sess->attr.attr_security.Audit_Exec) +#define AUDIT_COPY_ENABLED (u_sess->attr.attr_security.Audit_enabled && u_sess->attr.attr_security.Audit_Copy) +#define CHECK_AUDIT_DDL(type) ((unsigned int)u_sess->attr.attr_security.Audit_DDL & (1 << (type))) +#define CHECK_AUDIT_LOGIN(type) (unsigned int)u_sess->attr.attr_security.Audit_Session & (1 << (type)); +#define PG_QUERY_AUDIT_ARGS_MAX 3 + +extern THR_LOCAL bool am_sysauditor; + +#ifndef WIN32 +extern int sysauditPipe[2]; +#else +extern HANDLE sysauditPipe[2]; +#endif + +extern ThreadId pgaudit_start(void); +extern void allow_immediate_pgaudit_restart(void); + +#ifdef EXEC_BACKEND +extern void PgAuditorMain(); +#endif + +/* ---------- + * Functions called from backends, the sequence is relevent to struct AuditTypeDescs which should be changed in the same time + * ---------- + */ + +typedef enum { + AUDIT_UNKNOWN_TYPE = 0, + AUDIT_LOGIN_SUCCESS, + AUDIT_LOGIN_FAILED, + AUDIT_USER_LOGOUT, + AUDIT_SYSTEM_START, + AUDIT_SYSTEM_STOP, + AUDIT_SYSTEM_RECOVER, + AUDIT_SYSTEM_SWITCH, + AUDIT_LOCK_USER, + AUDIT_UNLOCK_USER, + AUDIT_GRANT_ROLE, + AUDIT_REVOKE_ROLE, + AUDIT_USER_VIOLATION, + AUDIT_DDL_DATABASE, + AUDIT_DDL_DIRECTORY, + AUDIT_DDL_TABLESPACE, + AUDIT_DDL_SCHEMA, + AUDIT_DDL_USER, + AUDIT_DDL_TABLE, + AUDIT_DDL_INDEX, + AUDIT_DDL_VIEW, + AUDIT_DDL_TRIGGER, + AUDIT_DDL_FUNCTION, + AUDIT_DDL_RESOURCEPOOL, + AUDIT_DDL_WORKLOAD, + AUDIT_DDL_SERVERFORHADOOP, + AUDIT_DDL_DATASOURCE, + AUDIT_DDL_NODEGROUP, + AUDIT_DDL_ROWLEVELSECURITY, + AUDIT_DDL_SYNONYM, + AUDIT_DDL_TYPE, + AUDIT_DDL_TEXTSEARCH, + AUDIT_DML_ACTION, + AUDIT_DML_ACTION_SELECT, + AUDIT_INTERNAL_EVENT, + AUDIT_FUNCTION_EXEC, + AUDIT_COPY_TO, + AUDIT_COPY_FROM, + AUDIT_SET_PARAMETER, + AUDIT_POLICY_EVENT, + MASKING_POLICY_EVENT, + SECURITY_EVENT, + AUDIT_DDL_SEQUENCE // ddl_sequence in struct AuditTypeDescs +} AuditType; + +typedef enum { + DDL_DATABASE = 0, + DDL_SCHEMA, + DDL_USER, + DDL_TABLE, + DDL_INDEX, + DDL_VIEW, + DDL_TRIGGER, + DDL_FUNCTION, + DDL_TABLESPACE, + DDL_RESOURCEPOOL, + DDL_WORKLOAD, + DDL_SERVERFORHADOOP, + DDL_DATASOURCE, + DDL_NODEGROUP, + DDL_ROWLEVELSECURITY, + DDL_TYPE, + DDL_TEXTSEARCH, + DDL_DIRECTORY, + DDL_SYNONYM, + DDL_SEQUENCE +} DDLType; + +typedef enum { AUDIT_UNKNOWN = 0, AUDIT_OK, AUDIT_FAILED } AuditResult; + +typedef enum { AUDIT_FUNC_QUERY = 0, AUDIT_FUNC_DELETE } AuditFuncType; + +typedef enum { STD_AUDIT_TYPE = 0, UNIFIED_AUDIT_TYPE } AuditClassType; +extern void audit_report(AuditType type, AuditResult result, const char* object_name, const char* detail_info, AuditClassType ctype = STD_AUDIT_TYPE); + +extern Datum pg_query_audit(PG_FUNCTION_ARGS); + +extern Datum pg_delete_audit(PG_FUNCTION_ARGS); + +/* define a macro about the return value of security function */ +#define check_intval(errno, express, retval, file, line) \ + { \ + if (errno == -1) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_intval(val, express, retval) check_intval(val, express, retval, __FILE__, __LINE__) + +#endif /* _PGAUDIT_H */ diff -uprN postgresql-hll-2.14_old/include/pg_config.h postgresql-hll-2.14/include/pg_config.h --- postgresql-hll-2.14_old/include/pg_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_config.h 2020-12-12 17:06:43.353349406 +0800 @@ -0,0 +1,910 @@ +/* src/include/pg_config.h. Generated from pg_config.h.in by configure. */ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to the type of arg 1 of 'accept' */ +#define ACCEPT_TYPE_ARG1 int + +/* Define to the type of arg 2 of 'accept' */ +#define ACCEPT_TYPE_ARG2 struct sockaddr * + +/* Define to the type of arg 3 of 'accept' */ +#define ACCEPT_TYPE_ARG3 socklen_t + +/* Define to the return type of 'accept' */ +#define ACCEPT_TYPE_RETURN int + +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* The normal alignment of `double', in bytes. */ +#define ALIGNOF_DOUBLE 8 + +/* The normal alignment of `int', in bytes. */ +#define ALIGNOF_INT 4 + +/* The normal alignment of `long', in bytes. */ +#define ALIGNOF_LONG 8 + +/* The normal alignment of `long long int', in bytes. */ +/* #undef ALIGNOF_LONG_LONG_INT */ + +/* The normal alignment of `short', in bytes. */ +#define ALIGNOF_SHORT 2 + +/* Size of a disk block --- this also limits the size of a tuple. You can set + it bigger if you need bigger tuples (although TOAST should reduce the need + to have large tuples, since fields can be spread across multiple tuples). + BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is + currently 2^15 (32768). This is determined by the 15-bit widths of the + lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h). + Changing BLCKSZ requires an initdb. */ +#define BLCKSZ 8192 + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#define DEF_PGPORT 5432 + +/* Define to the default TCP port number as a string constant. */ +#define DEF_PGPORT_STR "5432" + +/* Define to build with GSSAPI support. (--with-gssapi) */ +#define ENABLE_GSS 1 + +/* Define to build with PYTHON support. (--with-python) */ +/* #undef ENABLE_PYTHON2 */ +/* #undef ENABLE_PYTHON3 */ + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +/* #undef ENABLE_NLS */ + +/* Define to 1 if you want to generate gauss product as multiple nodes. (--enable-multiple-nodes) */ +#define ENABLE_MULTIPLE_NODES 1 + +/* Define to 1 if you want MOT support. (--enable-mot). + Supported only in single_node mode, not supported with (--enable-multiple-nodes) */ +/* #undef ENABLE_MOT */ + +/* Define to 1 if you want to check memory. (--enable-memory-check) */ +/* #undef ENABLE_MEMORY_CHECK */ + +/* Define to 1 if you want to check thread. (--enable-thread-check) */ +/* #undef ENABLE_THREAD_CHECK */ + +/* Define to 1 if you want to use default gcc. (--enable-default-gcc) */ +/* #undef ENABLE_DEFAULT_GCC */ + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#define ENABLE_THREAD_SAFETY 1 + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#define FLEXIBLE_ARRAY_MEMBER /**/ + +/* float4 values are passed by value if 'true', by reference if 'false' */ +#define FLOAT4PASSBYVAL true + +/* float8, int8, and related values are passed by value if 'true', by + reference if 'false' */ +#define FLOAT8PASSBYVAL true + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +#define GETPWUID_R_5ARG /**/ + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +/* #undef GETTIMEOFDAY_1ARG */ + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `append_history' function. */ +/* #undef HAVE_APPEND_HISTORY */ + +/* Define to 1 if you have the `cbrt' function. */ +#define HAVE_CBRT 1 + +/* Define to 1 if you have the `class' function. */ +/* #undef HAVE_CLASS */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRTDEFS_H */ + +/* Define to 1 if you have the `crypt' function. */ +#define HAVE_CRYPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_CRYPT_H 1 + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#define HAVE_DECL_FDATASYNC 1 + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#define HAVE_DECL_F_FULLFSYNC 0 + +/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you + don't. */ +#define HAVE_DECL_POSIX_FADVISE 1 + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#define HAVE_DECL_SNPRINTF 1 + +/* Define to 1 if you have the declaration of `strlcat', and to 0 if you + don't. */ +#define HAVE_DECL_STRLCAT 0 + +/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you + don't. */ +#define HAVE_DECL_STRLCPY 0 + +/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you + don't. */ +#define HAVE_DECL_SYS_SIGLIST 1 + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#define HAVE_DECL_VSNPRINTF 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLD_H */ + +/* Define to 1 if you have the `dlopen' function. */ +#define HAVE_DLOPEN 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_READLINE_H */ + +/* Define to 1 if you have the `fdatasync' function. */ +#define HAVE_FDATASYNC 1 + +/* Define to 1 if you have the `fls' function. */ +/* #undef HAVE_FLS */ + +/* Define to 1 if you have the `fpclass' function. */ +/* #undef HAVE_FPCLASS */ + +/* Define to 1 if you have the `fp_class' function. */ +/* #undef HAVE_FP_CLASS */ + +/* Define to 1 if you have the `fp_class_d' function. */ +/* #undef HAVE_FP_CLASS_D */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FP_CLASS_H */ + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#define HAVE_FSEEKO 1 + +/* Define to 1 if your compiler understands __func__. */ +#define HAVE_FUNCNAME__FUNC 1 + +/* Define to 1 if your compiler understands __FUNCTION__. */ +/* #undef HAVE_FUNCNAME__FUNCTION */ + +/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */ +#define HAVE_GCC_INT_ATOMICS 1 + +/* Define to 1 if you have the `getaddrinfo' function. */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if you have the `gethostbyname_r' function. */ +#define HAVE_GETHOSTBYNAME_R 1 + +/* Define to 1 if you have the `getifaddrs' function. */ +#define HAVE_GETIFADDRS 1 + +/* Define to 1 if you have the `getopt' function. */ +#define HAVE_GETOPT 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpeereid' function. */ +/* #undef HAVE_GETPEEREID */ + +/* Define to 1 if you have the `getpeerucred' function. */ +/* #undef HAVE_GETPEERUCRED */ + +/* Define to 1 if you have the `getpwuid_r' function. */ +#define HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getrlimit' function. */ +#define HAVE_GETRLIMIT 1 + +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +/* #undef HAVE_GETTIMEOFDAY */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GSSAPI_GSSAPI_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GSSAPI_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_HISTORY_H */ + +/* Define to 1 if you have the `history_truncate_file' function. */ +/* #undef HAVE_HISTORY_TRUNCATE_FILE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEEFP_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_IFADDRS_H 1 + +/* Define to 1 if you have the `inet_aton' function. */ +#define HAVE_INET_ATON 1 + +/* Define to 1 if the system has the type `int64'. */ +/* #undef HAVE_INT64 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* Define to 1 if the system has the type `intptr_t'. */ +#define HAVE_INTPTR_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the global variable 'int opterr'. */ +#define HAVE_INT_OPTERR 1 + +/* Define to 1 if you have the global variable 'int optreset'. */ +/* #undef HAVE_INT_OPTRESET */ + +/* Define to 1 if you have the global variable 'int timezone'. */ +#define HAVE_INT_TIMEZONE /**/ + +/* Define to 1 if you have support for IPv6. */ +#define HAVE_IPV6 1 + +/* Define to 1 if you have isinf(). */ +#define HAVE_ISINF 1 + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_E_DATA */ + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_TEXT_DATA */ + +/* Define to 1 if you have krb5_free_unparsed_name. */ +/* #undef HAVE_KRB5_FREE_UNPARSED_NAME */ + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_CLIENT */ + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_ENC_PART2 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LANGINFO_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LDAP_H */ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +/* #undef HAVE_LIBCRYPTO */ + +/* Define to 1 if you have the `ldap' library (-lldap). */ +/* #undef HAVE_LIBLDAP */ + +/* Define to 1 if you have the `ldap_r' library (-lldap_r). */ +/* #undef HAVE_LIBLDAP_R */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `pam' library (-lpam). */ +/* #undef HAVE_LIBPAM */ + +/* Define if you have a function readline library */ +/* #undef HAVE_LIBREADLINE */ + +/* Define to 1 if you have the `selinux' library (-lselinux). */ +/* #undef HAVE_LIBSELINUX */ + +/* Define to 1 if you have the `ssl' library (-lssl). */ +/* #undef HAVE_LIBSSL */ + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +/* #undef HAVE_LIBWLDAP32 */ + +/* Define to 1 if you have the `xml2' library (-lxml2). */ +/* #undef HAVE_LIBXML2 */ + +/* Define to 1 if you have the `xslt' library (-lxslt). */ +/* #undef HAVE_LIBXSLT */ + +/* Define to 1 if you have the `z' library (-lz). */ +#define HAVE_LIBZ 1 + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +/* #undef HAVE_LL_CONSTANTS */ + +/* Define to 1 if the system has the type `locale_t'. */ +#define HAVE_LOCALE_T 1 + +/* Define to 1 if `long int' works and is 64 bits. */ +#define HAVE_LONG_INT_64 1 + +/* Define to 1 if the system has the type `long long int'. */ +#define HAVE_LONG_LONG_INT 1 + +/* Define to 1 if `long long int' works and is 64 bits. */ +/* #undef HAVE_LONG_LONG_INT_64 */ + +/* Define to 1 if you have the `mbstowcs_l' function. */ +/* #undef HAVE_MBSTOWCS_L */ + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +/* #undef HAVE_MINIDUMP_TYPE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NET_IF_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_OSSP_UUID_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PAM_PAM_APPL_H */ + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `posix_fadvise' function. */ +#define HAVE_POSIX_FADVISE 1 + +/* Define to 1 if you have the POSIX signal interface. */ +#define HAVE_POSIX_SIGNALS /**/ + +/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */ +/* #undef HAVE_PPC_LWARX_MUTEX_HINT */ + +/* Define to 1 if you have the `pstat' function. */ +/* #undef HAVE_PSTAT */ + +/* Define to 1 if the PS_STRINGS thing exists. */ +/* #undef HAVE_PS_STRINGS */ + +/* Define if you have POSIX threads libraries and header files. */ +/* #undef HAVE_PTHREAD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* Define to 1 if you have the `random' function. */ +#define HAVE_RANDOM 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_READLINE_H */ + +/* Define to 1 if you have the `readlink' function. */ +#define HAVE_READLINK 1 + +/* Define to 1 if you have the `rint' function. */ +#define HAVE_RINT 1 + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +/* #undef HAVE_RL_COMPLETION_APPEND_CHARACTER */ + +/* Define to 1 if you have the `rl_completion_matches' function. */ +/* #undef HAVE_RL_COMPLETION_MATCHES */ + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +/* #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SECURITY_PAM_APPL_H */ + +/* Define to 1 if you have the `setproctitle' function. */ +/* #undef HAVE_SETPROCTITLE */ + +/* Define to 1 if you have the `setsid' function. */ +#define HAVE_SETSID 1 + +/* Define to 1 if you have the `sigprocmask' function. */ +#define HAVE_SIGPROCMASK 1 + +/* Define to 1 if you have sigsetjmp(). */ +#define HAVE_SIGSETJMP 1 + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have spinlocks. */ +#define HAVE_SPINLOCKS 1 + +/* Define to 1 if you have the `srandom' function. */ +#define HAVE_SRANDOM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the `strerror_r' function. */ +#define HAVE_STRERROR_R 1 + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#define HAVE_STRINGIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strlcat' function. */ +/* #undef HAVE_STRLCAT */ + +/* Define to 1 if you have the `strlcpy' function. */ +/* #undef HAVE_STRLCPY */ + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `strtoq' function. */ +/* #undef HAVE_STRTOQ */ + +/* Define to 1 if you have the `strtoull' function. */ +#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the `strtouq' function. */ +/* #undef HAVE_STRTOUQ */ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +/* #undef HAVE_STRUCT_CMSGCRED */ + +/* Define to 1 if the system has the type `struct option'. */ +#define HAVE_STRUCT_OPTION 1 + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +#define HAVE_STRUCT_TM_TM_ZONE 1 + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* Define to 1 if you have the `sync_file_range' function. */ +#define HAVE_SYNC_FILE_RANGE 1 + +/* Define to 1 if you have the syslog interface. */ +#define HAVE_SYSLOG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IPC_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_POLL_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PSTAT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SEM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SHM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOCKIO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_TAS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UCRED_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +#define HAVE_TM_ZONE 1 + +/* Define to 1 if you have the `towlower' function. */ +#define HAVE_TOWLOWER 1 + +/* Define to 1 if you have the external array `tzname'. */ +/* #undef HAVE_TZNAME */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UCRED_H */ + +/* Define to 1 if the system has the type `uint64'. */ +/* #undef HAVE_UINT64 */ + +/* Define to 1 if the system has the type `uint8'. */ +/* #undef HAVE_UINT8 */ + +/* Define to 1 if the system has the type `uintptr_t'. */ +#define HAVE_UINTPTR_T 1 + +/* Define to 1 if the system has the type `union semun'. */ +/* #undef HAVE_UNION_SEMUN */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have unix sockets. */ +#define HAVE_UNIX_SOCKETS 1 + +/* Define to 1 if you have the `unsetenv' function. */ +#define HAVE_UNSETENV 1 + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +#define HAVE_UTIMES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UUID_H */ + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `waitpid' function. */ +#define HAVE_WAITPID 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the `wcstombs' function. */ +#define HAVE_WCSTOMBS 1 + +/* Define to 1 if you have the `wcstombs_l' function. */ +/* #undef HAVE_WCSTOMBS_L */ + +/* Define to 1 if you have the header file. */ +#define HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINLDAP_H */ + +/* Define to the appropriate snprintf format for 64-bit ints. */ +#define INT64_FORMAT "%ld" + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +/* #undef KRB5 */ + +/* Define to 1 if you have __cpuid. */ +/* #undef HAVE__CPUID */ + +/* Define to 1 if you have __get_cpuid. */ +#define HAVE__GET_CPUID 1 + +/* Define to 1 if `locale_t' requires . */ +/* #undef LOCALE_T_IN_XLOCALE */ + +/* Define as the maximum alignment requirement of any C data type. */ +#define MAXIMUM_ALIGNOF 8 + +/* Define bytes to use libc memset(). */ +#define MEMSET_LOOP_LIMIT 1024 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "community@opengauss.org" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Postgres-XC" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Postgres-XC 1.1" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "postgres-xc" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "1.1" + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#define PG_KRB_SRVNAM "postgres" + +/* PostgreSQL major version as a string */ +#define PG_MAJORVERSION "9.2" + +/* PostgreSQL version as a string */ +#define PG_VERSION "9.2.4" + +/* Gaussdb version as a string*/ +#define DEF_GS_VERSION "(GaussDB Kernel V500R001C20 build ba094660) compiled at 2020-11-30 10:19:04 commit 1094 last mr 2058 debug" + +/* PostgreSQL version as a number */ +#define PG_VERSION_NUM 90204 + +/* Postgres-XC major version as a string */ +#define PGXC_MAJORVERSION "1.1" + +/* Postgres-XC version as a string */ +#define PGXC_VERSION "1.1" + +/* Postgres-XC version as a number */ +#define PGXC_VERSION_NUM + +/* A string containing the version number, platform, and C compiler */ +#define PG_VERSION_STR "PostgreSQL 9.2.4 (GaussDB Kernel V500R001C20 build ba094660) compiled at 2020-11-30 10:19:04 commit 1094 last mr 2058 debug on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit" + +/* A string containing the version number of Postgres-XC, platform, and C compiler */ +#define PGXC_VERSION_STR "Postgres-XC 1.1 on x86_64-unknown-linux-gnu, based on PostgreSQL 9.2.4, compiled by g++ (GCC) 7.3.0, 64-bit" + +/* Define to 1 to allow profiling output to be saved separately for each + process. */ +/* #undef PROFILE_PID_DIR */ + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus, + the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger + than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be + less than your OS' limit on file size. This is often 2 GB or 4GB in a + 32-bit operating system, unless you have large file support enabled. By + default, we make the limit 1 GB to avoid any possible integer-overflow + problems within the OS. A limit smaller than necessary only means we divide + a large relation into more chunks than necessary, so it seems best to err + in the direction of a small limit. A power-of-2 value is recommended to + save a few cycles in md.c, but is not absolutely required. Changing + RELSEG_SIZE requires an initdb. */ +#define RELSEG_SIZE 131072 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `off_t', as computed by sizeof. */ +#define SIZEOF_OFF_T 8 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if strerror_r() returns a int. */ +/* #undef STRERROR_R_INT */ + +/* Define to 1 if your declares `struct tm'. */ +/* #undef TM_IN_SYS_TIME */ + +/* Define to the appropriate snprintf format for unsigned 64-bit ints. */ +#define UINT64_FORMAT "%lu" + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +#define USE_ASSERT_CHECKING 1 + +/* Define to 1 to enable llt test. (--enable-llt) */ +/* #undef ENABLE_LLT */ + +/* Define to 1 to enable llvm test. (--enable-llvm) */ +#define ENABLE_LLVM_COMPILE 1 + +/* Define to 1 to enable ut test. (--enable-ut) */ +/* #undef ENABLE_UT */ + +/* Define to 1 to enable qunit test. (--enable-qunit) */ +/* #undef ENABLE_QUNIT */ + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +/* #undef USE_BONJOUR */ + +/* Define to 1 if you want float4 values to be passed by value. + (--enable-float4-byval) */ +#define USE_FLOAT4_BYVAL 1 + +/* Define to 1 if you want float8, int8, etc values to be passed by value. + (--enable-float8-byval) */ +#define USE_FLOAT8_BYVAL 1 + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#define USE_INLINE 1 + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +#define USE_INTEGER_DATETIMES 1 + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +/* #undef USE_LDAP */ + +/* Define to 1 to build with XML support. (--with-libxml) */ +/* #undef USE_LIBXML */ + +/* Define to 1 to use XSLT support when building contrib/xml2. + (--with-libxslt) */ +/* #undef USE_LIBXSLT */ + +/* Define to select named POSIX semaphores. */ +/* #undef USE_NAMED_POSIX_SEMAPHORES */ + +/* Define to 1 to build with PAM support. (--with-pam) */ +/* #undef USE_PAM */ + +/* Use replacement snprintf() functions. */ +/* #undef USE_REPL_SNPRINTF */ + +/* Define to 1 to use slicing-by-8 algorithm. */ +/* #undef USE_SLICING_BY_8_CRC32C */ + +/* Define to 1 use Intel SSE 4.2 CRC instructions. */ +/* #undef USE_SSE42_CRC32C */ + +/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */ +#define USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1 + +/* Define to build with (Open)SSL support. (--with-openssl) */ +#define USE_SSL 1 + +/* Define to select SysV-style semaphores. */ +#define USE_SYSV_SEMAPHORES 1 + +/* Define to select SysV-style shared memory. */ +#define USE_SYSV_SHARED_MEMORY 1 + +/* Define to select unnamed POSIX semaphores. */ +/* #undef USE_UNNAMED_POSIX_SEMAPHORES */ + +/* Define to select Win32-style semaphores. */ +/* #undef USE_WIN32_SEMAPHORES */ + +/* Define to select Win32-style shared memory. */ +/* #undef USE_WIN32_SHARED_MEMORY */ + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +/* # undef WORDS_BIGENDIAN */ +# endif +#endif + +/* Size of a WAL file block. This need have no particular relation to BLCKSZ. + XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O, + XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O + buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb. + */ +#define XLOG_BLCKSZ 8192 + +/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 + and larger than XLOG_BLCKSZ (preferably, a great deal larger than + XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */ +#define XLOG_SEG_SIZE (16 * 1024 * 1024) + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +/* #undef _LARGEFILE_SOURCE */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to the type of a signed integer type wide enough to hold a pointer, + if such a type exists, and if the system does not define it. */ +/* #undef intptr_t */ + +/* Define to empty if the C compiler does not understand signed types. */ +/* #undef signed */ + +/* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ +/* #undef uintptr_t */ + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +/* #undef volatile */ + diff -uprN postgresql-hll-2.14_old/include/pg_config.h.in postgresql-hll-2.14/include/pg_config.h.in --- postgresql-hll-2.14_old/include/pg_config.h.in 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_config.h.in 2020-12-12 17:06:43.354349419 +0800 @@ -0,0 +1,909 @@ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to the type of arg 1 of 'accept' */ +#undef ACCEPT_TYPE_ARG1 + +/* Define to the type of arg 2 of 'accept' */ +#undef ACCEPT_TYPE_ARG2 + +/* Define to the type of arg 3 of 'accept' */ +#undef ACCEPT_TYPE_ARG3 + +/* Define to the return type of 'accept' */ +#undef ACCEPT_TYPE_RETURN + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* The normal alignment of `double', in bytes. */ +#undef ALIGNOF_DOUBLE + +/* The normal alignment of `int', in bytes. */ +#undef ALIGNOF_INT + +/* The normal alignment of `long', in bytes. */ +#undef ALIGNOF_LONG + +/* The normal alignment of `long long int', in bytes. */ +#undef ALIGNOF_LONG_LONG_INT + +/* The normal alignment of `short', in bytes. */ +#undef ALIGNOF_SHORT + +/* Size of a disk block --- this also limits the size of a tuple. You can set + it bigger if you need bigger tuples (although TOAST should reduce the need + to have large tuples, since fields can be spread across multiple tuples). + BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is + currently 2^15 (32768). This is determined by the 15-bit widths of the + lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h). + Changing BLCKSZ requires an initdb. */ +#undef BLCKSZ + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#undef DEF_PGPORT + +/* Define to the default TCP port number as a string constant. */ +#undef DEF_PGPORT_STR + +/* Define to build with GSSAPI support. (--with-gssapi) */ +#undef ENABLE_GSS + +/* Define to build with PYTHON support. (--with-python) */ +#undef ENABLE_PYTHON2 +#undef ENABLE_PYTHON3 + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +#undef ENABLE_NLS + +/* Define to 1 if you want to generate gauss product as multiple nodes. (--enable-multiple-nodes) */ +#undef ENABLE_MULTIPLE_NODES + +/* Define to 1 if you want MOT support. (--enable-mot). + Supported only in single_node mode, not supported with (--enable-multiple-nodes) */ +#undef ENABLE_MOT + +/* Define to 1 if you want to check memory. (--enable-memory-check) */ +#undef ENABLE_MEMORY_CHECK + +/* Define to 1 if you want to check thread. (--enable-thread-check) */ +#undef ENABLE_THREAD_CHECK + +/* Define to 1 if you want to use default gcc. (--enable-default-gcc) */ +#undef ENABLE_DEFAULT_GCC + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#undef ENABLE_THREAD_SAFETY + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#undef FLEXIBLE_ARRAY_MEMBER + +/* float4 values are passed by value if 'true', by reference if 'false' */ +#undef FLOAT4PASSBYVAL + +/* float8, int8, and related values are passed by value if 'true', by + reference if 'false' */ +#undef FLOAT8PASSBYVAL + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +#undef GETPWUID_R_5ARG + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +#undef GETTIMEOFDAY_1ARG + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `append_history' function. */ +#undef HAVE_APPEND_HISTORY + +/* Define to 1 if you have the `cbrt' function. */ +#undef HAVE_CBRT + +/* Define to 1 if you have the `class' function. */ +#undef HAVE_CLASS + +/* Define to 1 if you have the header file. */ +#undef HAVE_CRTDEFS_H + +/* Define to 1 if you have the `crypt' function. */ +#undef HAVE_CRYPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_CRYPT_H + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#undef HAVE_DECL_FDATASYNC + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#undef HAVE_DECL_F_FULLFSYNC + +/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you + don't. */ +#undef HAVE_DECL_POSIX_FADVISE + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#undef HAVE_DECL_SNPRINTF + +/* Define to 1 if you have the declaration of `strlcat', and to 0 if you + don't. */ +#undef HAVE_DECL_STRLCAT + +/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you + don't. */ +#undef HAVE_DECL_STRLCPY + +/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you + don't. */ +#undef HAVE_DECL_SYS_SIGLIST + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#undef HAVE_DECL_VSNPRINTF + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLD_H + +/* Define to 1 if you have the `dlopen' function. */ +#undef HAVE_DLOPEN + +/* Define to 1 if you have the header file. */ +#undef HAVE_EDITLINE_HISTORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_EDITLINE_READLINE_H + +/* Define to 1 if you have the `fdatasync' function. */ +#undef HAVE_FDATASYNC + +/* Define to 1 if you have the `fls' function. */ +#undef HAVE_FLS + +/* Define to 1 if you have the `fpclass' function. */ +#undef HAVE_FPCLASS + +/* Define to 1 if you have the `fp_class' function. */ +#undef HAVE_FP_CLASS + +/* Define to 1 if you have the `fp_class_d' function. */ +#undef HAVE_FP_CLASS_D + +/* Define to 1 if you have the header file. */ +#undef HAVE_FP_CLASS_H + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#undef HAVE_FSEEKO + +/* Define to 1 if your compiler understands __func__. */ +#undef HAVE_FUNCNAME__FUNC + +/* Define to 1 if your compiler understands __FUNCTION__. */ +#undef HAVE_FUNCNAME__FUNCTION + +/* Define to 1 if you have __sync_lock_test_and_set(int *) and friends. */ +#undef HAVE_GCC_INT_ATOMICS + +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + +/* Define to 1 if you have the `gethostbyname_r' function. */ +#undef HAVE_GETHOSTBYNAME_R + +/* Define to 1 if you have the `getifaddrs' function. */ +#undef HAVE_GETIFADDRS + +/* Define to 1 if you have the `getopt' function. */ +#undef HAVE_GETOPT + +/* Define to 1 if you have the header file. */ +#undef HAVE_GETOPT_H + +/* Define to 1 if you have the `getopt_long' function. */ +#undef HAVE_GETOPT_LONG + +/* Define to 1 if you have the `getpeereid' function. */ +#undef HAVE_GETPEEREID + +/* Define to 1 if you have the `getpeerucred' function. */ +#undef HAVE_GETPEERUCRED + +/* Define to 1 if you have the `getpwuid_r' function. */ +#undef HAVE_GETPWUID_R + +/* Define to 1 if you have the `getrlimit' function. */ +#undef HAVE_GETRLIMIT + +/* Define to 1 if you have the `getrusage' function. */ +#undef HAVE_GETRUSAGE + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the header file. */ +#undef HAVE_GSSAPI_GSSAPI_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_GSSAPI_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_HISTORY_H + +/* Define to 1 if you have the `history_truncate_file' function. */ +#undef HAVE_HISTORY_TRUNCATE_FILE + +/* Define to 1 if you have the header file. */ +#undef HAVE_IEEEFP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_IFADDRS_H + +/* Define to 1 if you have the `inet_aton' function. */ +#undef HAVE_INET_ATON + +/* Define to 1 if the system has the type `int64'. */ +#undef HAVE_INT64 + +/* Define to 1 if the system has the type `int8'. */ +#undef HAVE_INT8 + +/* Define to 1 if the system has the type `intptr_t'. */ +#undef HAVE_INTPTR_T + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the global variable 'int opterr'. */ +#undef HAVE_INT_OPTERR + +/* Define to 1 if you have the global variable 'int optreset'. */ +#undef HAVE_INT_OPTRESET + +/* Define to 1 if you have the global variable 'int timezone'. */ +#undef HAVE_INT_TIMEZONE + +/* Define to 1 if you have support for IPv6. */ +#undef HAVE_IPV6 + +/* Define to 1 if you have isinf(). */ +#undef HAVE_ISINF + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +#undef HAVE_KRB5_ERROR_E_DATA + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +#undef HAVE_KRB5_ERROR_TEXT_DATA + +/* Define to 1 if you have krb5_free_unparsed_name. */ +#undef HAVE_KRB5_FREE_UNPARSED_NAME + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +#undef HAVE_KRB5_TICKET_CLIENT + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +#undef HAVE_KRB5_TICKET_ENC_PART2 + +/* Define to 1 if you have the header file. */ +#undef HAVE_LANGINFO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LDAP_H + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#undef HAVE_LIBCRYPTO + +/* Define to 1 if you have the `ldap' library (-lldap). */ +#undef HAVE_LIBLDAP + +/* Define to 1 if you have the `ldap_r' library (-lldap_r). */ +#undef HAVE_LIBLDAP_R + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the `pam' library (-lpam). */ +#undef HAVE_LIBPAM + +/* Define if you have a function readline library */ +#undef HAVE_LIBREADLINE + +/* Define to 1 if you have the `selinux' library (-lselinux). */ +#undef HAVE_LIBSELINUX + +/* Define to 1 if you have the `ssl' library (-lssl). */ +#undef HAVE_LIBSSL + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +#undef HAVE_LIBWLDAP32 + +/* Define to 1 if you have the `xml2' library (-lxml2). */ +#undef HAVE_LIBXML2 + +/* Define to 1 if you have the `xslt' library (-lxslt). */ +#undef HAVE_LIBXSLT + +/* Define to 1 if you have the `z' library (-lz). */ +#undef HAVE_LIBZ + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +#undef HAVE_LL_CONSTANTS + +/* Define to 1 if the system has the type `locale_t'. */ +#undef HAVE_LOCALE_T + +/* Define to 1 if `long int' works and is 64 bits. */ +#undef HAVE_LONG_INT_64 + +/* Define to 1 if the system has the type `long long int'. */ +#undef HAVE_LONG_LONG_INT + +/* Define to 1 if `long long int' works and is 64 bits. */ +#undef HAVE_LONG_LONG_INT_64 + +/* Define to 1 if you have the `mbstowcs_l' function. */ +#undef HAVE_MBSTOWCS_L + +/* Define to 1 if you have the `memmove' function. */ +#undef HAVE_MEMMOVE + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +#undef HAVE_MINIDUMP_TYPE + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_TCP_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NET_IF_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_OSSP_UUID_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_PAM_PAM_APPL_H + +/* Define to 1 if you have the `poll' function. */ +#undef HAVE_POLL + +/* Define to 1 if you have the header file. */ +#undef HAVE_POLL_H + +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + +/* Define to 1 if you have the POSIX signal interface. */ +#undef HAVE_POSIX_SIGNALS + +/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */ +#undef HAVE_PPC_LWARX_MUTEX_HINT + +/* Define to 1 if you have the `pstat' function. */ +#undef HAVE_PSTAT + +/* Define to 1 if the PS_STRINGS thing exists. */ +#undef HAVE_PS_STRINGS + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Define to 1 if you have the header file. */ +#undef HAVE_PWD_H + +/* Define to 1 if you have the `random' function. */ +#undef HAVE_RANDOM + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_HISTORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_READLINE_READLINE_H + +/* Define to 1 if you have the `readlink' function. */ +#undef HAVE_READLINK + +/* Define to 1 if you have the `rint' function. */ +#undef HAVE_RINT + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +#undef HAVE_RL_COMPLETION_APPEND_CHARACTER + +/* Define to 1 if you have the `rl_completion_matches' function. */ +#undef HAVE_RL_COMPLETION_MATCHES + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +#undef HAVE_RL_FILENAME_COMPLETION_FUNCTION + +/* Define to 1 if you have the header file. */ +#undef HAVE_SECURITY_PAM_APPL_H + +/* Define to 1 if you have the `setproctitle' function. */ +#undef HAVE_SETPROCTITLE + +/* Define to 1 if you have the `setsid' function. */ +#undef HAVE_SETSID + +/* Define to 1 if you have the `sigprocmask' function. */ +#undef HAVE_SIGPROCMASK + +/* Define to 1 if you have sigsetjmp(). */ +#undef HAVE_SIGSETJMP + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#undef HAVE_SIG_ATOMIC_T + +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + +/* Define to 1 if you have spinlocks. */ +#undef HAVE_SPINLOCKS + +/* Define to 1 if you have the `srandom' function. */ +#undef HAVE_SRANDOM + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the `strerror' function. */ +#undef HAVE_STRERROR + +/* Define to 1 if you have the `strerror_r' function. */ +#undef HAVE_STRERROR_R + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#undef HAVE_STRINGIZE + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the `strlcat' function. */ +#undef HAVE_STRLCAT + +/* Define to 1 if you have the `strlcpy' function. */ +#undef HAVE_STRLCPY + +/* Define to 1 if you have the `strtoll' function. */ +#undef HAVE_STRTOLL + +/* Define to 1 if you have the `strtoq' function. */ +#undef HAVE_STRTOQ + +/* Define to 1 if you have the `strtoull' function. */ +#undef HAVE_STRTOULL + +/* Define to 1 if you have the `strtouq' function. */ +#undef HAVE_STRTOUQ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#undef HAVE_STRUCT_ADDRINFO + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +#undef HAVE_STRUCT_CMSGCRED + +/* Define to 1 if the system has the type `struct option'. */ +#undef HAVE_STRUCT_OPTION + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +#undef HAVE_STRUCT_SOCKADDR_SA_LEN + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +#undef HAVE_STRUCT_TM_TM_ZONE + +/* Define to 1 if you have the `symlink' function. */ +#undef HAVE_SYMLINK + +/* Define to 1 if you have the `sync_file_range' function. */ +#undef HAVE_SYNC_FILE_RANGE + +/* Define to 1 if you have the syslog interface. */ +#undef HAVE_SYSLOG + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IPC_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_POLL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PSTAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_RESOURCE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SEM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SHM_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKIO_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TAS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UCRED_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +#undef HAVE_TM_ZONE + +/* Define to 1 if you have the `towlower' function. */ +#undef HAVE_TOWLOWER + +/* Define to 1 if you have the external array `tzname'. */ +#undef HAVE_TZNAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_UCRED_H + +/* Define to 1 if the system has the type `uint64'. */ +#undef HAVE_UINT64 + +/* Define to 1 if the system has the type `uint8'. */ +#undef HAVE_UINT8 + +/* Define to 1 if the system has the type `uintptr_t'. */ +#undef HAVE_UINTPTR_T + +/* Define to 1 if the system has the type `union semun'. */ +#undef HAVE_UNION_SEMUN + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have unix sockets. */ +#undef HAVE_UNIX_SOCKETS + +/* Define to 1 if you have the `unsetenv' function. */ +#undef HAVE_UNSETENV + +/* Define to 1 if you have the `utime' function. */ +#undef HAVE_UTIME + +/* Define to 1 if you have the `utimes' function. */ +#undef HAVE_UTIMES + +/* Define to 1 if you have the header file. */ +#undef HAVE_UTIME_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UUID_H + +/* Define to 1 if you have the `vsnprintf' function. */ +#undef HAVE_VSNPRINTF + +/* Define to 1 if you have the `waitpid' function. */ +#undef HAVE_WAITPID + +/* Define to 1 if you have the header file. */ +#undef HAVE_WCHAR_H + +/* Define to 1 if you have the `wcstombs' function. */ +#undef HAVE_WCSTOMBS + +/* Define to 1 if you have the `wcstombs_l' function. */ +#undef HAVE_WCSTOMBS_L + +/* Define to 1 if you have the header file. */ +#undef HAVE_WCTYPE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINLDAP_H + +/* Define to the appropriate snprintf format for 64-bit ints. */ +#undef INT64_FORMAT + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +#undef KRB5 + +/* Define to 1 if you have __cpuid. */ +#undef HAVE__CPUID + +/* Define to 1 if you have __get_cpuid. */ +#undef HAVE__GET_CPUID + +/* Define to 1 if `locale_t' requires . */ +#undef LOCALE_T_IN_XLOCALE + +/* Define as the maximum alignment requirement of any C data type. */ +#undef MAXIMUM_ALIGNOF + +/* Define bytes to use libc memset(). */ +#undef MEMSET_LOOP_LIMIT + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#undef PG_KRB_SRVNAM + +/* PostgreSQL major version as a string */ +#undef PG_MAJORVERSION + +/* PostgreSQL version as a string */ +#undef PG_VERSION + +/* Gaussdb version as a string*/ +#undef DEF_GS_VERSION + +/* PostgreSQL version as a number */ +#undef PG_VERSION_NUM + +/* Postgres-XC major version as a string */ +#undef PGXC_MAJORVERSION + +/* Postgres-XC version as a string */ +#undef PGXC_VERSION + +/* Postgres-XC version as a number */ +#undef PGXC_VERSION_NUM + +/* A string containing the version number, platform, and C compiler */ +#undef PG_VERSION_STR + +/* A string containing the version number of Postgres-XC, platform, and C compiler */ +#undef PGXC_VERSION_STR + +/* Define to 1 to allow profiling output to be saved separately for each + process. */ +#undef PROFILE_PID_DIR + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* RELSEG_SIZE is the maximum number of blocks allowed in one disk file. Thus, + the maximum size of a single file is RELSEG_SIZE * BLCKSZ; relations bigger + than that are divided into multiple files. RELSEG_SIZE * BLCKSZ must be + less than your OS' limit on file size. This is often 2 GB or 4GB in a + 32-bit operating system, unless you have large file support enabled. By + default, we make the limit 1 GB to avoid any possible integer-overflow + problems within the OS. A limit smaller than necessary only means we divide + a large relation into more chunks than necessary, so it seems best to err + in the direction of a small limit. A power-of-2 value is recommended to + save a few cycles in md.c, but is not absolutely required. Changing + RELSEG_SIZE requires an initdb. */ +#undef RELSEG_SIZE + +/* The size of `long', as computed by sizeof. */ +#undef SIZEOF_LONG + +/* The size of `off_t', as computed by sizeof. */ +#undef SIZEOF_OFF_T + +/* The size of `size_t', as computed by sizeof. */ +#undef SIZEOF_SIZE_T + +/* The size of `void *', as computed by sizeof. */ +#undef SIZEOF_VOID_P + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to 1 if strerror_r() returns a int. */ +#undef STRERROR_R_INT + +/* Define to 1 if your declares `struct tm'. */ +#undef TM_IN_SYS_TIME + +/* Define to the appropriate snprintf format for unsigned 64-bit ints. */ +#undef UINT64_FORMAT + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +#undef USE_ASSERT_CHECKING + +/* Define to 1 to enable llt test. (--enable-llt) */ +#undef ENABLE_LLT + +/* Define to 1 to enable llvm test. (--enable-llvm) */ +#undef ENABLE_LLVM_COMPILE + +/* Define to 1 to enable ut test. (--enable-ut) */ +#undef ENABLE_UT + +/* Define to 1 to enable qunit test. (--enable-qunit) */ +#undef ENABLE_QUNIT + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +#undef USE_BONJOUR + +/* Define to 1 if you want float4 values to be passed by value. + (--enable-float4-byval) */ +#undef USE_FLOAT4_BYVAL + +/* Define to 1 if you want float8, int8, etc values to be passed by value. + (--enable-float8-byval) */ +#undef USE_FLOAT8_BYVAL + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#undef USE_INLINE + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +#undef USE_INTEGER_DATETIMES + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +#undef USE_LDAP + +/* Define to 1 to build with XML support. (--with-libxml) */ +#undef USE_LIBXML + +/* Define to 1 to use XSLT support when building contrib/xml2. + (--with-libxslt) */ +#undef USE_LIBXSLT + +/* Define to select named POSIX semaphores. */ +#undef USE_NAMED_POSIX_SEMAPHORES + +/* Define to 1 to build with PAM support. (--with-pam) */ +#undef USE_PAM + +/* Use replacement snprintf() functions. */ +#undef USE_REPL_SNPRINTF + +/* Define to 1 to use slicing-by-8 algorithm. */ +#undef USE_SLICING_BY_8_CRC32C + +/* Define to 1 use Intel SSE 4.2 CRC instructions. */ +#undef USE_SSE42_CRC32C + +/* Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check. */ +#undef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK + +/* Define to build with (Open)SSL support. (--with-openssl) */ +#undef USE_SSL + +/* Define to select SysV-style semaphores. */ +#undef USE_SYSV_SEMAPHORES + +/* Define to select SysV-style shared memory. */ +#undef USE_SYSV_SHARED_MEMORY + +/* Define to select unnamed POSIX semaphores. */ +#undef USE_UNNAMED_POSIX_SEMAPHORES + +/* Define to select Win32-style semaphores. */ +#undef USE_WIN32_SEMAPHORES + +/* Define to select Win32-style shared memory. */ +#undef USE_WIN32_SHARED_MEMORY + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Size of a WAL file block. This need have no particular relation to BLCKSZ. + XLOG_BLCKSZ must be a power of 2, and if your system supports O_DIRECT I/O, + XLOG_BLCKSZ must be a multiple of the alignment requirement for direct-I/O + buffers, else direct I/O may fail. Changing XLOG_BLCKSZ requires an initdb. + */ +#undef XLOG_BLCKSZ + +/* XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 + and larger than XLOG_BLCKSZ (preferably, a great deal larger than + XLOG_BLCKSZ). Changing XLOG_SEG_SIZE requires an initdb. */ +#undef XLOG_SEG_SIZE + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#undef _LARGEFILE_SOURCE + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + +/* Define to the type of a signed integer type wide enough to hold a pointer, + if such a type exists, and if the system does not define it. */ +#undef intptr_t + +/* Define to empty if the C compiler does not understand signed types. */ +#undef signed + +/* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ +#undef uintptr_t + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +#undef volatile + diff -uprN postgresql-hll-2.14_old/include/pg_config.h.win32 postgresql-hll-2.14/include/pg_config.h.win32 --- postgresql-hll-2.14_old/include/pg_config.h.win32 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_config.h.win32 2020-12-12 17:06:43.354349419 +0800 @@ -0,0 +1,682 @@ +/* src/include/pg_config.h. Generated by configure. */ +/* src/include/pg_config.h.in. Generated from configure.in by autoheader. */ + +/* This file is generated from MingW ./configure, and with the following + * changes to be valid for Visual C++ (and compatible): + * + * HAVE_CBRT, HAVE_FUNCNAME_FUNC, HAVE_GETOPT, HAVE_GETOPT_H, HAVE_INTTYPES_H, + * HAVE_GETOPT_LONG, HAVE_LOCALE_T, HAVE_RINT, HAVE_STRINGS_H, HAVE_STRTOLL, + * HAVE_STRTOULL, HAVE_STRUCT_OPTION, ENABLE_THREAD_SAFETY, + * USE_INLINE, inline + */ + +/* Define to the type of arg 1 of 'accept' */ +#define ACCEPT_TYPE_ARG1 unsigned int + +/* Define to the type of arg 2 of 'accept' */ +#define ACCEPT_TYPE_ARG2 struct sockaddr * + +/* Define to the type of arg 3 of 'accept' */ +#define ACCEPT_TYPE_ARG3 int + +/* Define to the return type of 'accept' */ +#define ACCEPT_TYPE_RETURN unsigned int PASCAL + +/* The alignment requirement of a `double'. */ +#define ALIGNOF_DOUBLE 8 + +/* The alignment requirement of a `int'. */ +#define ALIGNOF_INT 4 + +/* The alignment requirement of a `long'. */ +#define ALIGNOF_LONG 4 + +/* The alignment requirement of a `long long int'. */ +#define ALIGNOF_LONG_LONG_INT 8 + +/* The alignment requirement of a `short'. */ +#define ALIGNOF_SHORT 2 + +/* Define to the default TCP port number on which the server listens and to + which clients will try to connect. This can be overridden at run-time, but + it's convenient if your clients have the right default compiled in. + (--with-pgport=PORTNUM) */ +#define DEF_PGPORT 5432 + +/* Define to the default TCP port number as a string constant. */ +#define DEF_PGPORT_STR "5432" + +/* Define to nothing if C supports flexible array members, and to 1 if it does + not. That way, with a declaration like `struct s { int n; double + d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 + compilers. When computing the size of such an object, don't use 'sizeof + (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' + instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with + MSVC and with C++ compilers. */ +#define FLEXIBLE_ARRAY_MEMBER + +/* Define to 1 if you want National Language Support. (--enable-nls) */ +/* #undef ENABLE_NLS */ + +/* Define to 1 to build client libraries as thread-safe code. + (--enable-thread-safety) */ +#define ENABLE_THREAD_SAFETY 1 + +/* Define to 1 if getpwuid_r() takes a 5th argument. */ +/* #undef GETPWUID_R_5ARG */ + +/* Define to 1 if gettimeofday() takes only 1 argument. */ +/* #undef GETTIMEOFDAY_1ARG */ + +#ifdef GETTIMEOFDAY_1ARG +# define gettimeofday(a,b) gettimeofday(a) +#endif + +/* Define to 1 if you have the `cbrt' function. */ +//#define HAVE_CBRT 1 + +/* Define to 1 if you have the `class' function. */ +/* #undef HAVE_CLASS */ + +/* Define to 1 if you have the `crypt' function. */ +/* #undef HAVE_CRYPT */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_CRYPT_H */ + +/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you + don't. */ +#define HAVE_DECL_FDATASYNC 0 + +/* Define to 1 if you have the declaration of `F_FULLFSYNC', and to 0 if you + don't. */ +#define HAVE_DECL_F_FULLFSYNC 0 + +/* Define to 1 if you have the declaration of `snprintf', and to 0 if you + don't. */ +#define HAVE_DECL_SNPRINTF 1 + +/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you + don't. */ +#define HAVE_DECL_VSNPRINTF 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLD_H */ + +/* Define to 1 if you have the `dlopen' function. */ +/* #undef HAVE_DLOPEN */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EDITLINE_READLINE_H */ + +/* Define to 1 if you have the `fcvt' function. */ +#define HAVE_FCVT 1 + +/* Define to 1 if you have the `fdatasync' function. */ +/* #undef HAVE_FDATASYNC */ + +/* Define to 1 if you have finite(). */ +#define HAVE_FINITE 1 + +/* Define to 1 if you have the `fpclass' function. */ +/* #undef HAVE_FPCLASS */ + +/* Define to 1 if you have the `fp_class' function. */ +/* #undef HAVE_FP_CLASS */ + +/* Define to 1 if you have the `fp_class_d' function. */ +/* #undef HAVE_FP_CLASS_D */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_FP_CLASS_H */ + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#define HAVE_FSEEKO 1 + +/* Define to 1 if your compiler understands __func__. */ +//#define HAVE_FUNCNAME__FUNC 1 + +/* Define to 1 if your compiler understands __FUNCTION__. */ +#define HAVE_FUNCNAME__FUNCTION 1 + +/* Define to 1 if you have getaddrinfo(). */ +/* #undef HAVE_GETADDRINFO */ + +/* Define to 1 if you have the `gethostbyname_r' function. */ +/* #undef HAVE_GETHOSTBYNAME_R */ + +/* Define to 1 if you have the `getopt' function. */ +//#define HAVE_GETOPT 1 + +/* Define to 1 if you have the header file. */ +//#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +//#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `getpeereid' function. */ +/* #undef HAVE_GETPEEREID */ + +/* Define to 1 if you have the `getpwuid_r' function. */ +/* #undef HAVE_GETPWUID_R */ + +/* Define to 1 if you have the `getrusage' function. */ +/* #undef HAVE_GETRUSAGE */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_IEEEFP_H */ + +/* Define to 1 if you have the `inet_aton' function. */ +/* #undef HAVE_INET_ATON */ + +/* Define to 1 if the system has the type `int64'. */ +/* #undef HAVE_INT64 */ + +/* Define to 1 if the system has the type `int8'. */ +/* #undef HAVE_INT8 */ + +/* Define to 1 if you have the header file. */ +//#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the global variable 'int timezone'. */ +#define HAVE_INT_TIMEZONE + +/* Define to 1 if you have support for IPv6. */ +#define HAVE_IPV6 1 + +/* Define to 1 if you have isinf(). */ +#define HAVE_ISINF 1 + +/* Define to 1 if `e_data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_E_DATA */ + +/* Define to 1 if `text.data' is member of `krb5_error'. */ +/* #undef HAVE_KRB5_ERROR_TEXT_DATA */ + +/* Define to 1 if `client' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_CLIENT */ + +/* Define to 1 if `enc_part2' is member of `krb5_ticket'. */ +/* #undef HAVE_KRB5_TICKET_ENC_PART2 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LANGINFO_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LDAP_H */ + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +/* #undef HAVE_LIBCRYPTO */ + +/* Define to 1 if you have the `ldap' library (-lldap). */ +/* #undef HAVE_LIBLDAP */ + +/* Define to 1 if you have the `pam' library (-lpam). */ +/* #undef HAVE_LIBPAM */ + +/* Define if you have a function readline library */ +/* #undef HAVE_LIBREADLINE */ + +/* Define to 1 if you have the `ssl' library (-lssl). */ +/* #undef HAVE_LIBSSL */ + +/* Define to 1 if you have the `wldap32' library (-lwldap32). */ +/* #undef HAVE_LIBWLDAP32 */ + +/* Define to 1 if you have the `z' library (-lz). */ +/* #undef HAVE_LIBZ */ + +/* Define to 1 if constants of type 'long long int' should have the suffix LL. + */ +#if (_MSC_VER > 1200) +#define HAVE_LL_CONSTANTS 1 +#endif + +/* Define to 1 if the system has the type `locale_t'. */ +#define HAVE_LOCALE_T 1 + +/* Define to 1 if `long int' works and is 64 bits. */ +/* #undef HAVE_LONG_INT_64 */ + +/* Define to 1 if `long long int' works and is 64 bits. */ +#if (_MSC_VER > 1200) +#define HAVE_LONG_LONG_INT_64 +#endif + +/* Define to 1 if you have the `mbstowcs_l' function. */ +#define HAVE_MBSTOWCS_L 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */ +#define HAVE_MINIDUMP_TYPE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NETINET_TCP_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PAM_PAM_APPL_H */ + +/* Define to 1 if you have the `poll' function. */ +/* #undef HAVE_POLL */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_POLL_H */ + +/* Define to 1 if you have the POSIX signal interface. */ +/* #undef HAVE_POSIX_SIGNALS */ + +/* Define to 1 if you have the `pstat' function. */ +/* #undef HAVE_PSTAT */ + +/* Define to 1 if the PS_STRINGS thing exists. */ +/* #undef HAVE_PS_STRINGS */ + +/* Define if you have POSIX threads libraries and header files. */ +/* #undef HAVE_PTHREAD */ + +/* Define to 1 if you have the header file. */ +#define HAVE_PWD_H 1 + +/* Define to 1 if you have the `random' function. */ +/* #undef HAVE_RANDOM */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_HISTORY_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_READLINE_READLINE_H */ + +/* Define to 1 if you have the `readlink' function. */ +/* #undef HAVE_READLINK */ + +/* Define to 1 if you have the `rint' function. */ +/*#define HAVE_RINT 1*/ + +/* Define to 1 if you have the global variable + 'rl_completion_append_character'. */ +/* #undef HAVE_RL_COMPLETION_APPEND_CHARACTER */ + +/* Define to 1 if you have the `rl_completion_matches' function. */ +/* #undef HAVE_RL_COMPLETION_MATCHES */ + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +/* #undef HAVE_RL_FILENAME_COMPLETION_FUNCTION */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SECURITY_PAM_APPL_H */ + +/* Define to 1 if you have the `setproctitle' function. */ +/* #undef HAVE_SETPROCTITLE */ + +/* Define to 1 if you have the `setsid' function. */ +/* #undef HAVE_SETSID */ + +/* Define to 1 if you have the `sigprocmask' function. */ +/* #undef HAVE_SIGPROCMASK */ + +/* Define to 1 if you have sigsetjmp(). */ +/* #undef HAVE_SIGSETJMP */ + +/* Define to 1 if the system has the type `sig_atomic_t'. */ +#define HAVE_SIG_ATOMIC_T 1 + +/* Define to 1 if you have the `snprintf' function. */ +/* #undef HAVE_SNPRINTF */ + +/* Define to 1 if you have spinlocks. */ +#define HAVE_SPINLOCKS 1 + +/* Define to 1 if you have the `srandom' function. */ +/* #undef HAVE_SRANDOM */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STDINT_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#ifndef HAVE_STRERROR +#define HAVE_STRERROR 1 +#endif + +/* Define to 1 if you have the `strerror_r' function. */ +/* #undef HAVE_STRERROR_R */ + +/* Define to 1 if cpp supports the ANSI # stringizing operator. */ +#define HAVE_STRINGIZE 1 + +/* Define to 1 if you have the header file. */ +/*#define HAVE_STRINGS_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strtoll' function. */ +//#define HAVE_STRTOLL 1 + +/* Define to 1 if you have the `strtoq' function. */ +/* #undef HAVE_STRTOQ */ + +/* Define to 1 if you have the `strtoull' function. */ +//#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the `strtouq' function. */ +/* #undef HAVE_STRTOUQ */ + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_ADDRINFO 1 +#endif + +/* Define to 1 if the system has the type `struct cmsgcred'. */ +/* #undef HAVE_STRUCT_CMSGCRED */ + +/* Define to 1 if the system has the type `struct option'. */ +//#define HAVE_STRUCT_OPTION 1 + +/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ +/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 +#endif + +/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */ +#if (_MSC_VER > 1200) +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 +#endif + +/* Define to 1 if `ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ + +/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +/* #undef HAVE_STRUCT_SOCKADDR_UN */ + +/* Define to 1 if `tm_zone' is member of `struct tm'. */ +/* #undef HAVE_STRUCT_TM_TM_ZONE */ + +/* Define to 1 if you have the `symlink' function. */ +#define HAVE_SYMLINK 1 + +/* Define to 1 if you have the `sysconf' function. */ +/* #undef HAVE_SYSCONF */ + +/* Define to 1 if you have the syslog interface. */ +/* #undef HAVE_SYSLOG */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_IPC_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_POLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PSTAT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SELECT_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SEM_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SHM_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UCRED_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UN_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_TERMIOS_H */ + +/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use + `HAVE_STRUCT_TM_TM_ZONE' instead. */ +/* #undef HAVE_TM_ZONE */ + +/* Define to 1 if you have the `towlower' function. */ +#define HAVE_TOWLOWER 1 + +/* Define to 1 if you have the external array `tzname'. */ +/* #undef HAVE_TZNAME */ + +/* Define to 1 if the system has the type `uint64'. */ +/* #undef HAVE_UINT64 */ + +/* Define to 1 if the system has the type `uint8'. */ +/* #undef HAVE_UINT8 */ + +/* Define to 1 if the system has the type `union semun'. */ +/* #undef HAVE_UNION_SEMUN */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have unix sockets. */ +/* #undef HAVE_UNIX_SOCKETS */ + +/* Define to 1 if you have the `unsetenv' function. */ +/* #undef HAVE_UNSETENV */ + +/* Define to 1 if you have the `utime' function. */ +#define HAVE_UTIME 1 + +/* Define to 1 if you have the `utimes' function. */ +/* #undef HAVE_UTIMES */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if you have the `vsnprintf' function. */ +#define HAVE_VSNPRINTF 1 + +/* Define to 1 if you have the `waitpid' function. */ +/* #undef HAVE_WAITPID */ + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the `wcstombs' function. */ +#define HAVE_WCSTOMBS 1 + +/* Define to 1 if you have the `wcstombs_l' function. */ +#define HAVE_WCSTOMBS_L 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCTYPE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINLDAP_H */ + +/* Define to the appropriate snprintf format for 64-bit ints, if any. */ +#define INT64_FORMAT "%lld" + +/* Define to build with Kerberos 5 support. (--with-krb5) */ +/* #undef KRB5 */ + +/* Define to 1 if `locale_t' requires . */ +/* #undef LOCALE_T_IN_XLOCALE */ + +/* Define to the location of locale files. */ +/* #undef LOCALEDIR */ + +/* Define as the maximum alignment requirement of any C data type. */ +#define MAXIMUM_ALIGNOF 8 + +/* Define bytes to use libc memset(). */ +#define MEMSET_LOOP_LIMIT 1024 + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "postgres-xc-bugs@lists.sourceforge.net" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "Postgres-XC" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "Postgres-XC 1.1beta" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "9.2.4" + +/* PostgreSQL version as a string */ +#define PG_VERSION "9.2.4" + +/* PostgreSQL version as a number */ +#define PG_VERSION_NUM 90204 + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "postgres-xc" + +/* Postgres-XC version as a string */ +#define PGXC_VERSION "1.1devel" + +/* Postgres-XC version as a number */ +#define PGXC_VERSION_NUM 10100 + +/* Define to the name of the default PostgreSQL service principal in Kerberos. + (--with-krb-srvnam=NAME) */ +#define PG_KRB_SRVNAM "postgres" + +/* A string containing the version number, platform, and C compiler */ +#define PG_VERSION_STR "Uninitialized version string (win32)" + +/* A string containing the version number, platform, and C compiler */ +#define PGXC_VERSION_STR "Uninitialized version string (win32)" + +/* Define to the necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `size_t', as computed by sizeof. */ +#ifndef _WIN64 +#define SIZEOF_SIZE_T 4 +#else +#define SIZEOF_SIZE_T 8 +#endif + +/* The size of `void *', as computed by sizeof. */ +#ifndef _WIN64 +#define SIZEOF_VOID_P 4 +#else +#define SIZEOF_VOID_P 8 +#endif + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if strerror_r() returns a int. */ +/* #undef STRERROR_R_INT */ + +/* Define to 1 if your declares `struct tm'. */ +/* #undef TM_IN_SYS_TIME */ + +/* Define to the appropriate snprintf format for unsigned 64-bit ints, if any. + */ +#define UINT64_FORMAT "%llu" + +/* Define to 1 to build with assertion checks. (--enable-cassert) */ +/* #undef USE_ASSERT_CHECKING */ + +/* Define to 1 to build with Bonjour support. (--with-bonjour) */ +/* #undef USE_BONJOUR */ + +/* Define to 1 if "static inline" works without unwanted warnings from + compilations where static inline functions are defined but not called. */ +#define USE_INLINE 1 + +/* Define to 1 if you want 64-bit integer timestamp and interval support. + (--enable-integer-datetimes) */ +/* #undef USE_INTEGER_DATETIMES */ + +/* Define to 1 to build with LDAP support. (--with-ldap) */ +/* #undef USE_LDAP */ + +/* Define to select named POSIX semaphores. */ +/* #undef USE_NAMED_POSIX_SEMAPHORES */ + +/* Define to 1 to build with PAM support. (--with-pam) */ +/* #undef USE_PAM */ + +/* Use replacement snprintf() functions. */ +#define USE_REPL_SNPRINTF 1 + +/* Define to build with (Open)SSL support. (--with-openssl) */ +/* #undef USE_SSL */ + +/* Define to select SysV-style semaphores. */ +/* #undef USE_SYSV_SEMAPHORES */ + +/* Define to select SysV-style shared memory. */ +#define USE_SYSV_SHARED_MEMORY 1 + +/* Define to select unnamed POSIX semaphores. */ +/* #undef USE_UNNAMED_POSIX_SEMAPHORES */ + +/* Define to select Win32-style semaphores. */ +#define USE_WIN32_SEMAPHORES + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +/* #undef _LARGEFILE_SOURCE */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#define inline __inline +#endif + +/* Define to empty if the C compiler does not understand signed types. */ +/* #undef signed */ + +/* Define to empty if the keyword `volatile' does not work. Warning: valid + code using `volatile' can become incorrect without. Disable with care. */ +/* #undef volatile */ diff -uprN postgresql-hll-2.14_old/include/pg_config_manual.h postgresql-hll-2.14/include/pg_config_manual.h --- postgresql-hll-2.14_old/include/pg_config_manual.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_config_manual.h 2020-12-12 17:06:43.354349419 +0800 @@ -0,0 +1,313 @@ +/* ------------------------------------------------------------------------ + * PostgreSQL manual configuration settings + * + * This file contains various configuration symbols and limits. In + * all cases, changing them is only useful in very rare situations or + * for developers. If you edit any of these, be sure to do a *full* + * rebuild (and an initdb if noted). + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/pg_config_manual.h + * ------------------------------------------------------------------------ + */ + +/* + * Maximum length for identifiers (e.g. table names, column names, + * function names). Names actually are limited to one less byte than this, + * because the length must include a trailing zero byte. + * + * Changing this requires an initdb. + */ +#define NAMEDATALEN 64 +#ifndef ENABLE_MULTIPLE_NODES +#define BUCKETDATALEN 16384 +#define BUCKETSTRLEN 6 * BUCKETDATALEN +#endif +#define NODEIDLEN 4 +#define MAX_NODE_DIG 5 // datanode number <= 4096 +#define MAX_DATANODE_NUM 4096 // this value should be same as MaxDataNodes +/* + * Maximum number of arguments to a function. + * + * The minimum value is 8 (GIN indexes use 8-argument support functions). + * The maximum possible value is around 600 (limited by index tuple size in + * pg_proc's index; BLCKSZ larger than 8K would allow more). Values larger + * than needed will waste memory and processing time, but do not directly + * cost disk space. + * + * Changing this does not require an initdb, but it does require a full + * backend recompile (including any user-defined C functions). + */ +#define FUNC_MAX_ARGS 666 + +/* + * Maximum number of columns in an index. There is little point in making + * this anything but a multiple of 32, because the main cost is associated + * with index tuple header size (see access/itup.h). + * + * Changing this requires an initdb. + */ +#define INDEX_MAX_KEYS 32 + +/* + * Set the upper and lower bounds of sequence values. + */ +#define SEQ_MAXVALUE INT64CONST(0x7FFFFFFFFFFFFFFF) +#define SEQ_MINVALUE (-SEQ_MAXVALUE) + +/* + * Number of spare LWLocks to allocate for user-defined add-on code. + */ +#define NUM_USER_DEFINED_LWLOCKS 4 + +/* + * Define this if you want to allow the lo_import and lo_export SQL + * functions to be executed by ordinary users. By default these + * functions are only available to the Postgres superuser. CAUTION: + * These functions are SECURITY HOLES since they can read and write + * any file that the PostgreSQL server has permission to access. If + * you turn this on, don't say we didn't warn you. + * define ALLOW_DANGEROUS_LO_FUNCTIONS + */ + +/* + * MAXPGPATH: standard size of a pathname buffer in PostgreSQL (hence, + * maximum usable pathname length is one less). + * + * We'd use a standard system header symbol for this, if there weren't + * so many to choose from: MAXPATHLEN, MAX_PATH, PATH_MAX are all + * defined by different "standards", and often have different values + * on the same platform! So we just punt and use a reasonably + * generous setting here. + */ +#define MAXPGPATH 1024 + +/* + * PG_SOMAXCONN: maximum accept-queue length limit passed to + * listen(2). You'd think we should use SOMAXCONN from + * , but on many systems that symbol is much smaller + * than the kernel's actual limit. In any case, this symbol need be + * twiddled only if you have a kernel that refuses large limit values, + * rather than silently reducing the value to what it can handle + * (which is what most if not all Unixen do). + */ +#define PG_SOMAXCONN 65535 + +#define PG_SOMINCONN 1024 + + +/* + * You can try changing this if you have a machine with bytes of + * another size, but no guarantee... + */ +#define BITS_PER_BYTE 8 + +/* + * Preferred alignment for disk I/O buffers. On some CPUs, copies between + * user space and kernel space are significantly faster if the user buffer + * is aligned on a larger-than-MAXALIGN boundary. Ideally this should be + * a platform-dependent value, but for now we just hard-wire it. + * + * Direct I/O requires 512 byte alignment of buffers (32 byte is typical otherwise) + */ +#define ALIGNOF_BUFFER 512 + +/* + * Disable UNIX sockets for certain operating systems. + */ +#if defined(WIN32) +#undef HAVE_UNIX_SOCKETS +#endif + +/* + * Define this if your operating system supports link() + */ +#if !defined(WIN32) && !defined(__CYGWIN__) +#define HAVE_WORKING_LINK 1 +#endif + +/* + * USE_POSIX_FADVISE controls whether Postgres will attempt to use the + * posix_fadvise() kernel call. Usually the automatic configure tests are + * sufficient, but some older Linux distributions had broken versions of + * posix_fadvise(). If necessary you can remove the #define here. + */ +#if HAVE_DECL_POSIX_FADVISE && defined(HAVE_POSIX_FADVISE) +#define USE_POSIX_FADVISE +#endif + +/* + * USE_PREFETCH code should be compiled only if we have a way to implement + * prefetching. (This is decoupled from USE_POSIX_FADVISE because there + * might in future be support for alternative low-level prefetch APIs.) + */ +#ifdef USE_POSIX_FADVISE +#define USE_PREFETCH +#endif + +/* + * Default and maximum values for backend_flush_after, bgwriter_flush_after + * and checkpoint_flush_after; measured in blocks. Currently, these are + * enabled by default if sync_file_range() exists, ie, only on Linux. Perhaps + * we could also enable by default if we have mmap and msync(MS_ASYNC)? + */ +#ifdef HAVE_SYNC_FILE_RANGE +#define DEFAULT_BACKEND_FLUSH_AFTER 0 /* never enabled by default */ +#define DEFAULT_BGWRITER_FLUSH_AFTER 64 +#define DEFAULT_CHECKPOINT_FLUSH_AFTER 32 +#else +#define DEFAULT_BACKEND_FLUSH_AFTER 0 +#define DEFAULT_BGWRITER_FLUSH_AFTER 0 +#define DEFAULT_CHECKPOINT_FLUSH_AFTER 0 +#endif +/* upper limit for all three variables */ +#define WRITEBACK_MAX_PENDING_FLUSHES 256 + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * The random() function is expected to yield values between 0 and + * MAX_RANDOM_VALUE. Currently, all known implementations yield + * 0..2^31-1, so we just hardwire this constant. We could do a + * configure test if it proves to be necessary. CAUTION: Think not to + * replace this with RAND_MAX. RAND_MAX defines the maximum value of + * the older rand() function, which is often different from --- and + * considerably inferior to --- random(). + */ +#define MAX_RANDOM_VALUE (0x7FFFFFFF) + +/* + * Set the format style used by gcc to check printf type functions. We really + * want the "gnu_printf" style set, which includes what glibc uses, such + * as %m for error strings and %lld for 64 bit long longs. But not all gcc + * compilers are known to support it, so we just use "printf" which all + * gcc versions alive are known to support, except on Windows where + * using "gnu_printf" style makes a dramatic difference. Maybe someday + * we'll have a configure test for this, if we ever discover use of more + * variants to be necessary. + */ +#ifdef WIN32 +#define PG_PRINTF_ATTRIBUTE gnu_printf +#else +#define PG_PRINTF_ATTRIBUTE printf +#endif + +/* + * On PPC machines, decide whether to use the mutex hint bit in LWARX + * instructions. Setting the hint bit will slightly improve spinlock + * performance on POWER6 and later machines, but does nothing before that, + * and will result in illegal-instruction failures on some pre-POWER4 + * machines. By default we use the hint bit when building for 64-bit PPC, + * which should be safe in nearly all cases. You might want to override + * this if you are building 32-bit code for a known-recent PPC machine. + */ +#ifdef HAVE_PPC_LWARX_MUTEX_HINT /* must have assembler support in any case */ +#if defined(__ppc64__) || defined(__powerpc64__) +#define USE_PPC_LWARX_MUTEX_HINT +#endif +#endif + +/* + * On PPC machines, decide whether to use LWSYNC instructions in place of + * ISYNC and SYNC. This provides slightly better performance, but will + * result in illegal-instruction failures on some pre-POWER4 machines. + * By default we use LWSYNC when building for 64-bit PPC, which should be + * safe in nearly all cases. + */ +#if defined(__ppc64__) || defined(__powerpc64__) +#define USE_PPC_LWSYNC +#endif + +/* + * Assumed cache line size. This doesn't affect correctness, but can be used + * for low-level optimizations. Currently, this is used to pad some data + * structures in xlog.c, to ensure that highly-contended fields are on + * different cache lines. Too small a value can hurt performance due to false + * sharing, while the only downside of too large a value is a few bytes of + * wasted memory. The default is 128, which should be large enough for all + * supported platforms. + */ +#define PG_CACHE_LINE_SIZE 128 + +/* + * ------------------------------------------------------------------------ + * The following symbols are for enabling debugging code, not for + * controlling user-visible features or resource limits. + * ------------------------------------------------------------------------ + */ + +/* + * Define this to cause pfree()'d memory to be cleared immediately, to + * facilitate catching bugs that refer to already-freed values. + * Right now, this gets defined automatically if --enable-cassert. + */ +#ifdef USE_ASSERT_CHECKING +#define CLOBBER_FREED_MEMORY +#endif + +/* + * Define this to check memory allocation errors (scribbling on more + * bytes than were allocated). Right now, this gets defined + * automatically if --enable-cassert. + */ +#ifdef USE_ASSERT_CHECKING +#define MEMORY_CONTEXT_CHECKING +#endif + +/* + * Define this to cause palloc()'d memory to be filled with random data, to + * facilitate catching code that depends on the contents of uninitialized + * memory. Caution: this is horrendously expensive. + * define RANDOMIZE_ALLOCATED_MEMORY + */ + +/* + * Define this to force all parse and plan trees to be passed through + * copyObject(), to facilitate catching errors and omissions in + * copyObject(). + * define COPY_PARSE_PLAN_TREES + */ + +/* + * Enable debugging print statements for lock-related operations. + * define LOCK_DEBUG + */ + +/* + * Enable debugging print statements for WAL-related operations; see + * also the wal_debug GUC var. + * define WAL_DEBUG + */ + +/* + * Enable debugging print for data replication operations. + * define DATA_DEBUG + */ + +/* + * Enable tracing of resource consumption during sort operations; + * see also the trace_sort GUC var. For 8.1 this is enabled by default. + */ +#define TRACE_SORT 1 + +/* + * Enable tracing of syncscan operations (see also the trace_syncscan GUC var). + * define TRACE_SYNCSCAN + */ + +/* + * Other debug #defines (documentation, anyone?) + * define HEAPDEBUGALL + * define ACLDEBUG + * define RTDEBUG + */ diff -uprN postgresql-hll-2.14_old/include/pg_config_os.h postgresql-hll-2.14/include/pg_config_os.h --- postgresql-hll-2.14_old/include/pg_config_os.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_config_os.h 2020-12-12 17:06:43.354349419 +0800 @@ -0,0 +1,26 @@ +/* src/include/port/linux.h */ + +/* + * As of July 2007, all known versions of the Linux kernel will sometimes + * return EIDRM for a shmctl() operation when EINVAL is correct (it happens + * when the low-order 15 bits of the supplied shm ID match the slot number + * assigned to a newer shmem segment). We deal with this by assuming that + * EIDRM means EINVAL in PGSharedMemoryIsInUse(). This is reasonably safe + * since in fact Linux has no excuse for ever returning EIDRM; it doesn't + * track removed segments in a way that would allow distinguishing them from + * private ones. But someday that code might get upgraded, and we'd have + * to have a kernel version test here. + */ +#ifndef LINUX_H +#define LINUX_H + +#define HAVE_LINUX_EIDRM_BUG + +/* + * Set the default wal_sync_method to fdatasync. With recent Linux versions, + * xlogdefs.h's normal rules will prefer open_datasync, which (a) doesn't + * perform better and (b) causes outright failures on ext4 data=journal + * filesystems, because those don't support O_DIRECT. + */ +#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#endif diff -uprN postgresql-hll-2.14_old/include/pgstat.h postgresql-hll-2.14/include/pgstat.h --- postgresql-hll-2.14_old/include/pgstat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgstat.h 2020-12-12 17:06:43.355349432 +0800 @@ -0,0 +1,2512 @@ +/* ---------- + * pgstat.h + * + * Definitions for the PostgreSQL statistics collector daemon. + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/pgstat.h + * ---------- + */ +#ifndef PGSTAT_H +#define PGSTAT_H + +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "gtm/gtm_c.h" +#include "libpq/pqcomm.h" +#include "mb/pg_wchar.h" +#include "portability/instr_time.h" +#include "storage/barrier.h" +#include "utils/hsearch.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/memutils.h" +#include "pgtime.h" +#include "pgxc/execRemote.h" +#include "storage/lwlock.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "workload/workload.h" +#include "access/multi_redo_settings.h" +#include "instruments/instr_event.h" +#include "instruments/unique_sql_basic.h" +#include "knl/knl_instance.h" + +/* Values for track_functions GUC variable --- order is significant! */ +typedef enum TrackFunctionsLevel { TRACK_FUNC_OFF, TRACK_FUNC_PL, TRACK_FUNC_ALL } TrackFunctionsLevel; + +/* ---------- + * The types of backend -> collector messages + * ---------- + */ +typedef enum StatMsgType { + PGSTAT_MTYPE_DUMMY, + PGSTAT_MTYPE_INQUIRY, + PGSTAT_MTYPE_TABSTAT, + PGSTAT_MTYPE_TABPURGE, + PGSTAT_MTYPE_DROPDB, + PGSTAT_MTYPE_RESETCOUNTER, + PGSTAT_MTYPE_RESETSHAREDCOUNTER, + PGSTAT_MTYPE_RESETSINGLECOUNTER, + PGSTAT_MTYPE_AUTOVAC_START, + PGSTAT_MTYPE_VACUUM, + PGSTAT_MTYPE_TRUNCATE, + PGSTAT_MTYPE_ANALYZE, + PGSTAT_MTYPE_BGWRITER, + PGSTAT_MTYPE_FUNCSTAT, + PGSTAT_MTYPE_FUNCPURGE, + PGSTAT_MTYPE_RECOVERYCONFLICT, + PGSTAT_MTYPE_TEMPFILE, + PGSTAT_MTYPE_DEADLOCK, + PGSTAT_MTYPE_AUTOVAC_STAT, + PGSTAT_MTYPE_FILE, + PGSTAT_MTYPE_DATA_CHANGED, + PGSTAT_MTYPE_MEMRESERVED, + PGSTAT_MTYPE_BADBLOCK, + PGSTAT_MTYPE_COLLECTWAITINFO, + PGSTAT_MTYPE_RESPONSETIME, + PGSTAT_MTYPE_PROCESSPERCENTILE, + PGSTAT_MTYPE_CLEANUPHOTKEYS +} StatMsgType; + +/* ---------- + * The data type used for counters. + * ---------- + */ +typedef int64 PgStat_Counter; + +/* ---------- + * PgStat_TableCounts The actual per-table counts kept by a backend + * + * This struct should contain only actual event counters, because we memcmp + * it against zeroes to detect whether there are any counts to transmit. + * It is a component of PgStat_TableStatus (within-backend state) and + * PgStat_TableEntry (the transmitted message format). + * + * Note: for a table, tuples_returned is the number of tuples successfully + * fetched by heap_getnext, while tuples_fetched is the number of tuples + * successfully fetched by heap_fetch under the control of bitmap indexscans. + * For an index, tuples_returned is the number of index entries returned by + * the index AM, while tuples_fetched is the number of tuples successfully + * fetched by heap_fetch under the control of simple indexscans for this index. + * + * tuples_inserted/updated/deleted/hot_updated count attempted actions, + * regardless of whether the transaction committed. delta_live_tuples, + * delta_dead_tuples, and changed_tuples are set depending on commit or abort. + * Note that delta_live_tuples and delta_dead_tuples can be negative! + * ---------- + */ +typedef struct PgStat_TableCounts { + PgStat_Counter t_numscans; + + PgStat_Counter t_tuples_returned; + PgStat_Counter t_tuples_fetched; + + PgStat_Counter t_tuples_inserted; + PgStat_Counter t_tuples_updated; + PgStat_Counter t_tuples_deleted; + PgStat_Counter t_tuples_hot_updated; + bool t_truncated; + + PgStat_Counter t_tuples_inserted_post_truncate; + PgStat_Counter t_tuples_updated_post_truncate; + PgStat_Counter t_tuples_deleted_post_truncate; + + PgStat_Counter t_delta_live_tuples; + PgStat_Counter t_delta_dead_tuples; + PgStat_Counter t_changed_tuples; + + PgStat_Counter t_blocks_fetched; + PgStat_Counter t_blocks_hit; + + PgStat_Counter t_cu_mem_hit; + PgStat_Counter t_cu_hdd_sync; + PgStat_Counter t_cu_hdd_asyn; +} PgStat_TableCounts; + +/* Possible targets for resetting cluster-wide shared values */ +typedef enum PgStat_Shared_Reset_Target { RESET_BGWRITER } PgStat_Shared_Reset_Target; + +/* Possible object types for resetting single counters */ +typedef enum PgStat_Single_Reset_Type { RESET_TABLE, RESET_FUNCTION } PgStat_Single_Reset_Type; + +/* ------------------------------------------------------------ + * Structures kept in backend local memory while accumulating counts + * ------------------------------------------------------------ + */ + +/* ---------- + * PgStat_TableStatus Per-table status within a backend + * + * Many of the event counters are nontransactional, ie, we count events + * in committed and aborted transactions alike. For these, we just count + * directly in the PgStat_TableStatus. However, delta_live_tuples, + * delta_dead_tuples, and changed_tuples must be derived from event counts + * with awareness of whether the transaction or subtransaction committed or + * aborted. Hence, we also keep a stack of per-(sub)transaction status + * records for every table modified in the current transaction. At commit + * or abort, we propagate tuples_inserted/updated/deleted up to the + * parent subtransaction level, or out to the parent PgStat_TableStatus, + * as appropriate. + * ---------- + */ +typedef struct PgStat_TableStatus { + Oid t_id; /* table's OID */ + bool t_shared; /* is it a shared catalog? */ + /* + * if t_id is a parition oid , then t_statFlag is the corresponding partitioned table oid; + * fi t_id is a non-parition oid, then t_statFlag is InvlaidOId + */ + uint32 t_statFlag; + struct PgStat_TableXactStatus* trans; /* lowest subxact's counts */ + PgStat_TableCounts t_counts; /* event counts to be sent */ +} PgStat_TableStatus; + +/* ---------- + * PgStat_TableXactStatus Per-table, per-subtransaction status + * ---------- + */ +typedef struct PgStat_TableXactStatus { + PgStat_Counter tuples_inserted; /* tuples inserted in (sub)xact */ + PgStat_Counter tuples_updated; /* tuples updated in (sub)xact */ + PgStat_Counter tuples_deleted; /* tuples deleted in (sub)xact */ + bool truncated; /* relation truncated in this (sub)xact */ + PgStat_Counter inserted_pre_trunc; /* tuples inserted prior to truncate */ + PgStat_Counter updated_pre_trunc; /* tuples updated prior to truncate */ + PgStat_Counter deleted_pre_trunc; /* tuples deleted prior to truncate */ + int nest_level; /* subtransaction nest level */ + /* links to other structs for same relation: */ + struct PgStat_TableXactStatus* upper; /* next higher subxact if any */ + PgStat_TableStatus* parent; /* per-table status */ + /* structs of same subxact level are linked here: */ + struct PgStat_TableXactStatus* next; /* next of same subxact */ +} PgStat_TableXactStatus; + +/* ------------------------------------------------------------ + * Message formats follow + * ------------------------------------------------------------ + */ + +/* ---------- + * PgStat_MsgHdr The common message header + * ---------- + */ +typedef struct PgStat_MsgHdr { + StatMsgType m_type; + int m_size; +} PgStat_MsgHdr; + +/* ---------- + * Space available in a message. This will keep the UDP packets below 1K, + * which should fit unfragmented into the MTU of the lo interface on most + * platforms. Does anybody care for platforms where it doesn't? + * ---------- + */ +#define PGSTAT_MSG_PAYLOAD (1000 - sizeof(PgStat_MsgHdr)) + +/* ---------- + * PgStat_MsgDummy A dummy message, ignored by the collector + * ---------- + */ +typedef struct PgStat_MsgDummy { + PgStat_MsgHdr m_hdr; +} PgStat_MsgDummy; + +/* ---------- + * PgStat_MsgInquiry Sent by a backend to ask the collector + * to write the stats file. + * ---------- + */ + +typedef struct PgStat_MsgInquiry { + PgStat_MsgHdr m_hdr; + TimestampTz inquiry_time; /* minimum acceptable file timestamp */ +} PgStat_MsgInquiry; + +/* ---------- + * PgStat_TableEntry Per-table info in a MsgTabstat + * ---------- + */ +typedef struct PgStat_TableEntry { + Oid t_id; + uint32 t_statFlag; + PgStat_TableCounts t_counts; +} PgStat_TableEntry; + +/* ---------- + * PgStat_MsgTabstat Sent by the backend to report table + * and buffer access statistics. + * ---------- + */ +#define PGSTAT_NUM_TABENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int)) / sizeof(PgStat_TableEntry)) + +typedef struct PgStat_MsgTabstat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + int m_xact_commit; + int m_xact_rollback; + PgStat_Counter m_block_read_time; /* times in microseconds */ + PgStat_Counter m_block_write_time; + PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES]; +} PgStat_MsgTabstat; + +/* ---------- + * PgStat_MsgTabpurge Sent by the backend to tell the collector + * about dead tables. + * ---------- + */ +typedef struct PgStat_MsgTabEntry { + Oid m_tableid; + uint32 m_statFlag; +} PgStat_MsgTabEntry; +#define PGSTAT_NUM_TABPURGE ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(PgStat_MsgTabEntry)) + +typedef struct PgStat_MsgTabpurge { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + PgStat_MsgTabEntry m_entry[PGSTAT_NUM_TABPURGE]; +} PgStat_MsgTabpurge; + +/* ---------- + * PgStat_MsgDropdb Sent by the backend to tell the collector + * about a dropped database + * ---------- + */ +typedef struct PgStat_MsgDropdb { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgDropdb; + +/* ---------- + * PgStat_MsgResetcounter Sent by the backend to tell the collector + * to reset counters + * ---------- + */ +typedef struct PgStat_MsgResetcounter { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgResetcounter; + +typedef struct PgStat_MsgCleanupHotkeys { + PgStat_MsgHdr m_hdr; + Oid m_databaseOid; + Oid m_tableOid; +} PgStat_MsgCleanupHotkeys; + +/* ---------- + * PgStat_MsgResetsharedcounter Sent by the backend to tell the collector + * to reset a shared counter + * ---------- + */ +typedef struct PgStat_MsgResetsharedcounter { + PgStat_MsgHdr m_hdr; + PgStat_Shared_Reset_Target m_resettarget; +} PgStat_MsgResetsharedcounter; + +/* ---------- + * PgStat_MsgResetsinglecounter Sent by the backend to tell the collector + * to reset a single counter + * ---------- + */ +typedef struct PgStat_MsgResetsinglecounter { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + PgStat_Single_Reset_Type m_resettype; + Oid m_objectid; + Oid p_objectid; /* parentted objectid if m_objectid is a partition objectid */ +} PgStat_MsgResetsinglecounter; + +/* ---------- + * PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal + * that a database is going to be processed + * ---------- + */ +typedef struct PgStat_MsgAutovacStart { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + TimestampTz m_start_time; +} PgStat_MsgAutovacStart; + +/* ---------- + * PgStat_MsgVacuum Sent by the backend or autovacuum daemon + * after VACUUM + * ---------- + */ +typedef struct PgStat_MsgVacuum { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + bool m_autovacuum; + TimestampTz m_vacuumtime; + PgStat_Counter m_tuples; +} PgStat_MsgVacuum; + +/* ---------- + * PgStat_MsgIUD Sent by the insert/delete/update + * ---------- + */ +typedef struct PgStat_MsgDataChanged { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + TimestampTz m_changed_time; +} PgStat_MsgDataChanged; + +/* ---------- + * PgStat_MsgAvStat Sent autovac stat to collector + * Reset by + * ---------- + */ +#define AV_TIMEOUT (1 << 0) /* autovac have been canceled due to timeout */ +#define AV_ANALYZE (1 << 1) /* is doing auto-analyze */ +#define AV_VACUUM (1 << 2) /* is doing auto-vacuum */ + +typedef struct PgStat_MsgAutovacStat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + int64 m_autovacStat; +} PgStat_MsgAutovacStat; + +/* ---------- + * PgStat_MsgTruncate Sent by the truncate + * ---------- + */ + +typedef struct PgStat_MsgTruncate { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + /* + * if m_tableoid is partition oid, then m_statFlag is the corresponding + * partitioned table oid, else it is InvalidOId + */ + uint32 m_statFlag; +} PgStat_MsgTruncate; + +/* ---------- + * PgStat_MsgAnalyze Sent by the backend or autovacuum daemon + * after ANALYZE + * ---------- + */ +typedef struct PgStat_MsgAnalyze { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + Oid m_tableoid; + uint32 m_statFlag; + bool m_autovacuum; + TimestampTz m_analyzetime; + PgStat_Counter m_live_tuples; + PgStat_Counter m_dead_tuples; +} PgStat_MsgAnalyze; + +/* ---------- + * PgStat_MsgBgWriter Sent by the bgwriter to update statistics. + * ---------- + */ +typedef struct PgStat_MsgBgWriter { + PgStat_MsgHdr m_hdr; + + PgStat_Counter m_timed_checkpoints; + PgStat_Counter m_requested_checkpoints; + PgStat_Counter m_buf_written_checkpoints; + PgStat_Counter m_buf_written_clean; + PgStat_Counter m_maxwritten_clean; + PgStat_Counter m_buf_written_backend; + PgStat_Counter m_buf_fsync_backend; + PgStat_Counter m_buf_alloc; + PgStat_Counter m_checkpoint_write_time; /* times in milliseconds */ + PgStat_Counter m_checkpoint_sync_time; +} PgStat_MsgBgWriter; + +/* ---------- + * PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict + * ---------- + */ +typedef struct PgStat_MsgRecoveryConflict { + PgStat_MsgHdr m_hdr; + + Oid m_databaseid; + int m_reason; +} PgStat_MsgRecoveryConflict; + +/* ---------- + * PgStat_MsgTempFile Sent by the backend upon creating a temp file + * ---------- + */ +typedef struct PgStat_MsgTempFile { + PgStat_MsgHdr m_hdr; + + Oid m_databaseid; + size_t m_filesize; +} PgStat_MsgTempFile; + +/* ---------- + * PgStat_MsgMemReserved Sent by the backend upon succeeding in reserving memory + * ---------- + */ +typedef struct PgStat_MsgMemReserved { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int64 m_memMbytes; + int m_reserve_or_release; +} PgStat_MsgMemReserved; + +/* ---------- + * PgStat_FunctionCounts The actual per-function counts kept by a backend + * + * This struct should contain only actual event counters, because we memcmp + * it against zeroes to detect whether there are any counts to transmit. + * + * Note that the time counters are in instr_time format here. We convert to + * microseconds in PgStat_Counter format when transmitting to the collector. + * ---------- + */ +typedef struct PgStat_FunctionCounts { + PgStat_Counter f_numcalls; + instr_time f_total_time; + instr_time f_self_time; +} PgStat_FunctionCounts; + +/* ---------- + * PgStat_BackendFunctionEntry Entry in backend's per-function hash table + * ---------- + */ +typedef struct PgStat_BackendFunctionEntry { + Oid f_id; + PgStat_FunctionCounts f_counts; +} PgStat_BackendFunctionEntry; + +/* ---------- + * PgStat_FunctionEntry Per-function info in a MsgFuncstat + * ---------- + */ +typedef struct PgStat_FunctionEntry { + Oid f_id; + PgStat_Counter f_numcalls; + PgStat_Counter f_total_time; /* times in microseconds */ + PgStat_Counter f_self_time; +} PgStat_FunctionEntry; + +/* ---------- + * PgStat_MsgFuncstat Sent by the backend to report function + * usage statistics. + * ---------- + */ +#define PGSTAT_NUM_FUNCENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(PgStat_FunctionEntry)) + +typedef struct PgStat_MsgFuncstat { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]; +} PgStat_MsgFuncstat; + +/* ---------- + * PgStat_MsgFuncpurge Sent by the backend to tell the collector + * about dead functions. + * ---------- + */ +#define PGSTAT_NUM_FUNCPURGE ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) / sizeof(Oid)) + +typedef struct PgStat_MsgFuncpurge { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + Oid m_functionid[PGSTAT_NUM_FUNCPURGE]; +} PgStat_MsgFuncpurge; + +/* ---------- + * PgStat_MsgDeadlock Sent by the backend to tell the collector + * about a deadlock that occurred. + * ---------- + */ +typedef struct PgStat_MsgDeadlock { + PgStat_MsgHdr m_hdr; + Oid m_databaseid; +} PgStat_MsgDeadlock; + +/* ---------- + * PgStat_MsgFile Sent by the backend upon reading/writing a data file + * ---------- + */ +typedef struct PgStat_MsgFile { + PgStat_MsgHdr m_hdr; + + Oid dbid; + Oid spcid; + Oid fn; + char rw; + PgStat_Counter cnt; + PgStat_Counter blks; + PgStat_Counter tim; + PgStat_Counter lsttim; + PgStat_Counter mintim; + PgStat_Counter maxtim; +} PgStat_MsgFile; + +/* + * PgStat_MsgBadBlock Sent by the backend where read bad page / cu + */ + +typedef struct BadBlockHashKey { + RelFileNode relfilenode; + ForkNumber forknum; +} BadBlockHashKey; + +typedef struct BadBlockHashEnt { + BadBlockHashKey key; + int error_count; + TimestampTz first_time; + TimestampTz last_time; +} BadBlockHashEnt; + +#define PGSTAT_NUM_BADBLOCK_ENTRIES ((PGSTAT_MSG_PAYLOAD - sizeof(int)) / sizeof(BadBlockHashEnt)) + +typedef struct PgStat_MsgBadBlock { + PgStat_MsgHdr m_hdr; + int m_nentries; + BadBlockHashEnt m_entry[PGSTAT_NUM_BADBLOCK_ENTRIES]; +} PgStat_MsgBadBlock; + +const int MAX_SQL_RT_INFO_COUNT = 100000; + +typedef struct SqlRTInfo { + uint64 UniqueSQLId; + int64 start_time; + int64 rt; +} SqlRTInfo; + +typedef struct SqlRTInfoArray { + volatile int32 sqlRTIndex; + bool isFull; + SqlRTInfo sqlRT[MAX_SQL_RT_INFO_COUNT]; +} SqlRTInfoArray; + +typedef struct PgStat_SqlRT { + PgStat_MsgHdr m_hdr; + SqlRTInfo sqlRT; +} PgStat_SqlRT; +const int MAX_SQL_RT_INFO_COUNT_REMOTE = MaxAllocSize / sizeof(SqlRTInfo); + +typedef struct PgStat_PrsPtl { + PgStat_MsgHdr m_hdr; + int64 now; +} PgStat_PrsPtl; + +/* ---------- + * PgStat_Msg Union over all possible messages. + * ---------- + */ +typedef union PgStat_Msg { + PgStat_MsgHdr msg_hdr; + PgStat_MsgDummy msg_dummy; + PgStat_MsgInquiry msg_inquiry; + PgStat_MsgTabstat msg_tabstat; + PgStat_MsgTabpurge msg_tabpurge; + PgStat_MsgDropdb msg_dropdb; + PgStat_MsgResetcounter msg_resetcounter; + PgStat_MsgResetsharedcounter msg_resetsharedcounter; + PgStat_MsgResetsinglecounter msg_resetsinglecounter; + PgStat_MsgAutovacStart msg_autovacuum; + PgStat_MsgVacuum msg_vacuum; + PgStat_MsgTruncate msg_truncate; + PgStat_MsgAnalyze msg_analyze; + PgStat_MsgBgWriter msg_bgwriter; + PgStat_MsgFuncstat msg_funcstat; + PgStat_MsgFuncpurge msg_funcpurge; + PgStat_MsgRecoveryConflict msg_recoveryconflict; + PgStat_MsgDeadlock msg_deadlock; + PgStat_MsgFile msg_file; + PgStat_SqlRT msg_sqlrt; + PgStat_PrsPtl msg_prosqlrt; +} PgStat_Msg; + +/* ------------------------------------------------------------ + * Statistic collector data structures follow + * + * PGSTAT_FILE_FORMAT_ID should be changed whenever any of these + * data structures change. + * ------------------------------------------------------------ + */ + +#define PGSTAT_FILE_FORMAT_ID 0x01A5BC9B + +/* ---------- + * PgStat_StatDBEntry The collector's data per database + * ---------- + */ +typedef struct PgStat_StatDBEntry { + Oid databaseid; + PgStat_Counter n_xact_commit; + PgStat_Counter n_xact_rollback; + PgStat_Counter n_blocks_fetched; + PgStat_Counter n_blocks_hit; + + PgStat_Counter n_cu_mem_hit; + PgStat_Counter n_cu_hdd_sync; + PgStat_Counter n_cu_hdd_asyn; + + PgStat_Counter n_tuples_returned; + PgStat_Counter n_tuples_fetched; + PgStat_Counter n_tuples_inserted; + PgStat_Counter n_tuples_updated; + PgStat_Counter n_tuples_deleted; + TimestampTz last_autovac_time; + PgStat_Counter n_conflict_tablespace; + PgStat_Counter n_conflict_lock; + PgStat_Counter n_conflict_snapshot; + PgStat_Counter n_conflict_bufferpin; + PgStat_Counter n_conflict_startup_deadlock; + PgStat_Counter n_temp_files; + PgStat_Counter n_temp_bytes; + PgStat_Counter n_deadlocks; + PgStat_Counter n_block_read_time; /* times in microseconds */ + PgStat_Counter n_block_write_time; + PgStat_Counter n_mem_mbytes_reserved; + + TimestampTz stat_reset_timestamp; + + /* + * tables and functions must be last in the struct, because we don't write + * the pointers out to the stats file. + */ + HTAB* tables; + HTAB* functions; +} PgStat_StatDBEntry; + +typedef enum PgStat_StatTabType { + STATFLG_RELATION = 0, /* stat info for relation */ + STATFLG_PARTITION = 1, /* stat info for partition */ +} PgStat_StatTabType; + +/* + * stat table key + * if tableid is a relation oid, statFlag is invalidoid + * if tableid is a partition oid, statFlag is the corresponding + * partitioned table's oid + */ +typedef struct PgStat_StatTabKey { + Oid tableid; + uint32 statFlag; +} PgStat_StatTabKey; + +/* ---------- + * PgStat_StatTabEntry The collector's data per table (or index) + * ---------- + */ +#define CONTINUED_TIMEOUT_BITMAP 0X00000000000000FF +#define MAX_CONTINUED_TIMEOUT_COUNT CONTINUED_TIMEOUT_BITMAP +#define CONTINUED_TIMEOUT_COUNT(status) (0X00000000000000FF & (status)) +#define reset_continued_timeout(status) \ + do { \ + (status) = ((~CONTINUED_TIMEOUT_BITMAP) & (status)); \ + } while (0); + +#define increase_continued_timeout(status) \ + do { \ + if (CONTINUED_TIMEOUT_COUNT(status) < MAX_CONTINUED_TIMEOUT_COUNT) \ + (status)++; \ + } while (0); + +#define TOTAL_TIMEOUT_BITMAP 0X0000000000FFFF00 +#define MAX_TOTAL_TIMEOUT_COUNT TOTAL_TIMEOUT_BITMAP >> 16 +#define TOTAL_TIMEOUT_COUNT(status) (((status)&TOTAL_TIMEOUT_BITMAP) >> 16) +#define increase_toatl_timeout(status) \ + do { \ + if (TOTAL_TIMEOUT_COUNT(status) < MAX_TOTAL_TIMEOUT_COUNT) \ + status = status + 0X0000000000000100; \ + } while (0); + +typedef struct PgStat_StatTabEntry { + PgStat_StatTabKey tablekey; + + PgStat_Counter numscans; + + PgStat_Counter tuples_returned; + PgStat_Counter tuples_fetched; + + PgStat_Counter tuples_inserted; + PgStat_Counter tuples_updated; + PgStat_Counter tuples_deleted; + PgStat_Counter tuples_hot_updated; + + PgStat_Counter n_live_tuples; + PgStat_Counter n_dead_tuples; + PgStat_Counter changes_since_analyze; + + PgStat_Counter blocks_fetched; + PgStat_Counter blocks_hit; + + PgStat_Counter cu_mem_hit; + PgStat_Counter cu_hdd_sync; + PgStat_Counter cu_hdd_asyn; + + TimestampTz vacuum_timestamp; /* user initiated vacuum */ + PgStat_Counter vacuum_count; + TimestampTz autovac_vacuum_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_vacuum_count; + TimestampTz analyze_timestamp; /* user initiated */ + PgStat_Counter analyze_count; + TimestampTz autovac_analyze_timestamp; /* autovacuum initiated */ + PgStat_Counter autovac_analyze_count; + TimestampTz data_changed_timestamp; /* start to insert/delete/upate */ + uint64 autovac_status; +} PgStat_StatTabEntry; + +/* ---------- + * PgStat_StatFuncEntry The collector's data per function + * ---------- + */ +typedef struct PgStat_StatFuncEntry { + Oid functionid; + + PgStat_Counter f_numcalls; + + PgStat_Counter f_total_time; /* times in microseconds */ + PgStat_Counter f_self_time; +} PgStat_StatFuncEntry; + +/* + * Global statistics kept in the stats collector + */ +typedef struct PgStat_GlobalStats { + TimestampTz stats_timestamp; /* time of stats file update */ + PgStat_Counter timed_checkpoints; + PgStat_Counter requested_checkpoints; + PgStat_Counter checkpoint_write_time; /* times in milliseconds */ + PgStat_Counter checkpoint_sync_time; + PgStat_Counter buf_written_checkpoints; + PgStat_Counter buf_written_clean; + PgStat_Counter maxwritten_clean; + PgStat_Counter buf_written_backend; + PgStat_Counter buf_fsync_backend; + PgStat_Counter buf_alloc; + TimestampTz stat_reset_timestamp; +} PgStat_GlobalStats; + +/* ---------- + * Backend states + * ---------- + */ +typedef enum BackendState { + STATE_UNDEFINED, + STATE_IDLE, + STATE_RUNNING, + STATE_IDLEINTRANSACTION, + STATE_FASTPATH, + STATE_IDLEINTRANSACTION_ABORTED, + STATE_DISABLED, + STATE_RETRYING, + STATE_COUPLED, + STATE_DECOUPLED, +} BackendState; + +/* ---------- + * Backend waiting states + * NOTE: if you add a WaitState enum value, remember to add it's description in WaitStateDesc. + * ---------- + */ +typedef enum WaitState { + STATE_WAIT_UNDEFINED = 0, + STATE_WAIT_LWLOCK, + STATE_WAIT_LOCK, + STATE_WAIT_IO, + STATE_WAIT_COMM, + STATE_WAIT_POOLER_GETCONN, + STATE_WAIT_POOLER_ABORTCONN, + STATE_WAIT_POOLER_CLEANCONN, + STATE_POOLER_CREATE_CONN, + STATE_POOLER_WAIT_GETCONN, + STATE_POOLER_WAIT_SETCMD, + STATE_POOLER_WAIT_RESETCMD, + STATE_POOLER_WAIT_CANCEL, + STATE_POOLER_WAIT_STOP, + STATE_WAIT_NODE, + STATE_WAIT_XACTSYNC, + STATE_WAIT_WALSYNC, + STATE_WAIT_DATASYNC, + STATE_WAIT_DATASYNC_QUEUE, + STATE_WAIT_FLUSH_DATA, + STATE_STREAM_WAIT_CONNECT_NODES, + STATE_STREAM_WAIT_PRODUCER_READY, + STATE_STREAM_WAIT_THREAD_SYNC_QUIT, + STATE_STREAM_WAIT_NODEGROUP_DESTROY, + STATE_WAIT_ACTIVE_STATEMENT, + STATE_WAIT_MEMORY, + STATE_EXEC_SORT, + STATE_EXEC_SORT_WRITE_FILE, + STATE_EXEC_MATERIAL, + STATE_EXEC_MATERIAL_WRITE_FILE, + STATE_EXEC_HASHJOIN_BUILD_HASH, + STATE_EXEC_HASHJOIN_WRITE_FILE, + STATE_EXEC_HASHAGG_BUILD_HASH, + STATE_EXEC_HASHAGG_WRITE_FILE, + STATE_EXEC_HASHSETOP_BUILD_HASH, + STATE_EXEC_HASHSETOP_WRITE_FILE, + STATE_EXEC_NESTLOOP, + STATE_CREATE_INDEX, + STATE_ANALYZE, + STATE_VACUUM, + STATE_VACUUM_FULL, + STATE_GTM_CONNECT, + STATE_GTM_RESET_XMIN, + STATE_GTM_GET_XMIN, + STATE_GTM_GET_GXID, + STATE_GTM_GET_CSN, + STATE_GTM_GET_SNAPSHOT, + STATE_GTM_BEGIN_TRANS, + STATE_GTM_COMMIT_TRANS, + STATE_GTM_ROLLBACK_TRANS, + STATE_GTM_START_PREPARE_TRANS, + STATE_GTM_PREPARE_TRANS, + STATE_GTM_OPEN_SEQUENCE, + STATE_GTM_CLOSE_SEQUENCE, + STATE_GTM_CREATE_SEQUENCE, + STATE_GTM_ALTER_SEQUENCE, + STATE_GTM_SEQUNCE_GET_NEXT_VAL, + STATE_GTM_SEQUENCE_SET_VAL, + STATE_GTM_DROP_SEQUENCE, + STATE_GTM_RENAME_SEQUENCE, + STATE_WAIT_SYNC_CONSUMER_NEXT_STEP, + STATE_WAIT_SYNC_PRODUCER_NEXT_STEP, + STATE_WAIT_NUM // MUST be last, DO NOT use this value. +} WaitState; + +/* ---------- + * Backend phase for "wait node" status + * NOTE: if you add a WaitStatePhase enum value, remember to add it's description in WaitStatePhaseDesc. + * ---------- + */ +typedef enum WaitStatePhase { + PHASE_NONE = 0, + PHASE_BEGIN, + PHASE_COMMIT, + PHASE_ROLLBACK, + PHASE_WAIT_QUOTA, + PHASE_AUTOVACUUM +} WaitStatePhase; + +/* ---------- + * Wait Event Classes + * ---------- + */ +#define WAIT_EVENT_END 0x00000000U +#define PG_WAIT_LWLOCK 0x01000000U +#define PG_WAIT_LOCK 0x03000000U +#define PG_WAIT_IO 0x0A000000U +#define PG_WAIT_SQL 0x0B000000U + +/* ---------- + * Wait Events - IO + * + * Use this category when a process is waiting for a IO. + * ---------- + */ +typedef enum WaitEventIO { + WAIT_EVENT_BUFFILE_READ = PG_WAIT_IO, + WAIT_EVENT_BUFFILE_WRITE, + WAIT_EVENT_BUF_HASH_SEARCH, + WAIT_EVENT_BUF_STRATEGY_GET, + WAIT_EVENT_CONTROL_FILE_READ, + WAIT_EVENT_CONTROL_FILE_SYNC, + WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE, + WAIT_EVENT_CONTROL_FILE_WRITE, + WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE, + WAIT_EVENT_COPY_FILE_READ, + WAIT_EVENT_COPY_FILE_WRITE, + WAIT_EVENT_DATA_FILE_EXTEND, + WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC, + WAIT_EVENT_DATA_FILE_PREFETCH, + WAIT_EVENT_DATA_FILE_READ, + WAIT_EVENT_DATA_FILE_SYNC, + WAIT_EVENT_DATA_FILE_TRUNCATE, + WAIT_EVENT_DATA_FILE_WRITE, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC, + WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE, + WAIT_EVENT_LOCK_FILE_CREATE_READ, + WAIT_EVENT_LOCK_FILE_CREATE_SYNC, + WAIT_EVENT_LOCK_FILE_CREATE_WRITE, + WAIT_EVENT_RELATION_MAP_READ, + WAIT_EVENT_RELATION_MAP_SYNC, + WAIT_EVENT_RELATION_MAP_WRITE, + WAIT_EVENT_REPLICATION_SLOT_READ, + WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC, + WAIT_EVENT_REPLICATION_SLOT_SYNC, + WAIT_EVENT_REPLICATION_SLOT_WRITE, + WAIT_EVENT_SLRU_FLUSH_SYNC, + WAIT_EVENT_SLRU_READ, + WAIT_EVENT_SLRU_SYNC, + WAIT_EVENT_SLRU_WRITE, + WAIT_EVENT_TWOPHASE_FILE_READ, + WAIT_EVENT_TWOPHASE_FILE_SYNC, + WAIT_EVENT_TWOPHASE_FILE_WRITE, + WAIT_EVENT_WAL_BOOTSTRAP_SYNC, + WAIT_EVENT_WAL_BOOTSTRAP_WRITE, + WAIT_EVENT_WAL_COPY_READ, + WAIT_EVENT_WAL_COPY_SYNC, + WAIT_EVENT_WAL_COPY_WRITE, + WAIT_EVENT_WAL_INIT_SYNC, + WAIT_EVENT_WAL_INIT_WRITE, + WAIT_EVENT_WAL_READ, + WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN, + WAIT_EVENT_WAL_WRITE, + WAIT_EVENT_DW_READ, + WAIT_EVENT_DW_WRITE, + WAIT_EVENT_DW_SINGLE_POS, + WAIT_EVENT_DW_SINGLE_WRITE, + WAIT_EVENT_PREDO_PROCESS_PENDING, + WAIT_EVENT_PREDO_APPLY, + WAIT_EVENT_DISABLE_CONNECT_FILE_READ, + WAIT_EVENT_DISABLE_CONNECT_FILE_SYNC, + WAIT_EVENT_DISABLE_CONNECT_FILE_WRITE, + WAIT_EVENT_MPFL_INIT, + WAIT_EVENT_MPFL_READ, + WAIT_EVENT_MPFL_WRITE, + WAIT_EVENT_OBS_LIST, + WAIT_EVENT_OBS_READ, + WAIT_EVENT_OBS_WRITE, + WAIT_EVENT_LOGCTRL_SLEEP, + IO_EVENT_NUM = WAIT_EVENT_LOGCTRL_SLEEP - WAIT_EVENT_BUFFILE_READ + 1 // MUST be last, DO NOT use this value. +} WaitEventIO; + +/* ---------- + * Wait Events - SQL + * + * Using this to indicate the type of SQL DML event. + * ---------- + */ +typedef enum WaitEventSQL { + WAIT_EVENT_SQL_SELECT = PG_WAIT_SQL, + WAIT_EVENT_SQL_UPDATE, + WAIT_EVENT_SQL_INSERT, + WAIT_EVENT_SQL_DELETE, + WAIT_EVENT_SQL_MERGEINTO, + WAIT_EVENT_SQL_DDL, + WAIT_EVENT_SQL_DML, + WAIT_EVENT_SQL_DCL, + WAIT_EVENT_SQL_TCL +} WaitEventSQL; + +/* ---------- + * WAIT_COUNT_ARRAY_SIZE Size of the array used for user`s sql count + * ---------- + */ +#define WAIT_COUNT_ARRAY_SIZE 128 + +typedef struct { + uint64 total_time; /* total time for sql */ + uint64 avg_time; /* avg time for sql */ + uint64 min_time; /* min time for sql */ + uint64 max_time; /* max time for sql */ +} ElapseTime; +/* ---------- + * PgStat_WaitCount The sql count result used for QPS + * ---------- + */ +typedef struct PgStat_WaitCount { + uint64 wc_sql_select; + uint64 wc_sql_update; + uint64 wc_sql_insert; + uint64 wc_sql_delete; + uint64 wc_sql_mergeinto; + uint64 wc_sql_ddl; + uint64 wc_sql_dml; + uint64 wc_sql_dcl; + uint64 wc_sql_tcl; + ElapseTime insertElapse; + ElapseTime updateElapse; + ElapseTime selectElapse; + ElapseTime deleteElapse; +} PgStat_WaitCount; + +/* ---------- + * PgStat_WaitCountStatus The sql count result for per user + * ---------- + */ +typedef struct PgStat_WaitCountStatus { + PgStat_WaitCount wc_cnt; + uint32 userid; +} PgStat_WaitCountStatus; + +/* ---------- + * PgStat_WaitCountStatusCell The data cell of WaitCountStatusList + * ---------- + */ +typedef struct PgStat_WaitCountStatusCell { + PgStat_WaitCountStatus WaitCountArray[WAIT_COUNT_ARRAY_SIZE]; +} PgStat_WaitCountStatusCell; + +/* ---------- + * WaitCountHashValue The value when find WaitCountHashTbl + * ---------- + */ +typedef struct WaitCountHashValue { + Oid userid; + int idx; +} WaitCountHashValue; + +/* ---------- + * The data type used for performance monitor. + * ---------- + */ +typedef enum WorkloadManagerIOState { + IOSTATE_NONE = 0, + IOSTATE_READ, + IOSTATE_WRITE, + IOSTATE_VACUUM +} WorkloadManagerIOState; + +typedef enum WorkloadManagerStmtTag { STMTTAG_NONE = 0, STMTTAG_READ, STMTTAG_WRITE } WorkloadManagerStmtTag; + +/* ---------- + * Workload manager states + * ---------- + */ +typedef enum WorkloadManagerEnqueueState { + STATE_NO_ENQUEUE, + STATE_MEMORY, + STATE_ACTIVE_STATEMENTS, +} WorkloadManagerEnqueueState; + +typedef struct RemoteInfo { + char remote_name[NAMEDATALEN]; + char remote_ip[MAX_IP_STR_LEN]; + char remote_port[MAX_PORT_LEN]; + int socket; + int logic_id; +} RemoteInfo; + +/* ---------- + * Shared-memory data structures + * ---------- + */ + +/* Reserve 2 additional 3rd plugin lwlocks.*/ +#define LWLOCK_EVENT_NUM (LWTRANCHE_NATIVE_TRANCHE_NUM + 2) +typedef struct WaitStatisticsInfo { + int64 max_duration; + int64 min_duration; + int64 total_duration; + int64 avg_duration; + uint64 counter; + uint64 failed_counter; + TimestampTz last_updated; +} WaitStatisticsInfo; + +typedef struct WaitStatusInfo { + int64 start_time; // current wait starttime + WaitStatisticsInfo statistics_info[STATE_WAIT_NUM + 1]; +} WaitStatusInfo; + +typedef struct WaitEventInfo { + int64 start_time; // current wait starttime + WaitStatisticsInfo io_info[IO_EVENT_NUM]; + WaitStatisticsInfo lock_info[LOCK_EVENT_NUM]; + WaitStatisticsInfo lwlock_info[LWLOCK_EVENT_NUM]; +} WaitEventInfo; + +typedef struct WaitInfo { + WaitEventInfo event_info; + WaitStatusInfo status_info; +} WaitInfo; + +/* ---------- + * PgBackendStatus + * + * Each live backend maintains a PgBackendStatus struct in shared memory + * showing its current activity. (The structs are allocated according to + * BackendId, but that is not critical.) Note that the collector process + * has no involvement in, or even access to, these structs. + * ---------- + */ +typedef struct PgBackendStatus { + /* + * To avoid locking overhead, we use the following protocol: a backend + * increments st_changecount before modifying its entry, and again after + * finishing a modification. A would-be reader should note the value of + * st_changecount, copy the entry into private memory, then check + * st_changecount again. If the value hasn't changed, and if it's even, + * the copy is valid; otherwise start over. This makes updates cheap + * while reads are potentially expensive, but that's the tradeoff we want. + * + * The above protocol needs the memory barriers to ensure that + * the apparent order of execution is as it desires. Otherwise, + * for example, the CPU might rearrange the code so that st_changecount + * is incremented twice before the modification on a machine with + * weak memory ordering. This surprising result can lead to bugs. + */ + int st_changecount; + + /* The entry is valid iff st_procpid > 0, unused if st_procpid == 0 */ + ThreadId st_procpid; + /* The entry is valid when one session is coupled to a thread pool worker */ + uint64 st_sessionid; + + /* Times when current backend, transaction, and activity started */ + TimestampTz st_proc_start_timestamp; + TimestampTz st_xact_start_timestamp; + TimestampTz st_activity_start_timestamp; + TimestampTz st_state_start_timestamp; + + /* Database OID, owning user's OID, connection client address */ + Oid st_databaseid; + Oid st_userid; + SockAddr st_clientaddr; + char* st_clienthostname; /* MUST be null-terminated */ + + void* st_connect_info; /* pool connection state */ + + /* current state */ + BackendState st_state; + + /* application name; MUST be null-terminated */ + char* st_appname; + + /* connection info; */ + char* st_conninfo; + + /* current command string; MUST be null-terminated */ + char* st_activity; + + /* which resource waiting on? */ + WorkloadManagerEnqueueState st_waiting_on_resource; + + /* workload info */ + TimestampTz st_block_start_time; /* block start time */ + TimestampTz st_elapsed_start_time; /* elapsed start time */ + WLMStatistics st_backstat; /* workload backend state */ + void* st_debug_info; /* workload debug info */ + char* st_cgname; /* workload cgroup name */ + WorkloadManagerIOState st_io_state; /* 0: none 1: read: 2: write */ + WorkloadManagerStmtTag st_stmttag; /* 0: none 1: read: 2: write */ + + uint64 st_queryid; /* debug query id of current query */ + UniqueSQLKey st_unique_sql_key; /* get unique sql key */ + pid_t st_tid; /* thread ID */ + uint64 st_parent_sessionid; /* parent session ID, equals parent pid under non thread pool mode */ + int st_thread_level; /* thread level, mark with plan node id of Stream node */ + uint32 st_smpid; /* smp worker id, used for parallel execution */ + WaitState st_waitstatus; /* backend waiting states */ + int st_waitnode_count; /* count of waiting nodes */ + int st_nodeid; /* maybe for nodeoid/nodeidx */ + int st_plannodeid; /* indentify which consumer is receiving data for SCTP */ + int st_numnodes; /* nodes number when reporting waitstatus in case it changed */ + uint32 st_waitevent; /* backend's wait event */ + int st_stmtmem; /* statment mem for query */ + uint64 st_xid; /* for transaction id, fit for 64-bit */ + WaitStatePhase st_waitstatus_phase; /* detailed phase for wait status, now only for 'wait node' status */ + char* st_relname; /* relation name, for analyze, vacuum, .etc.*/ + Oid st_libpq_wait_nodeid; /* for libpq, point to libpq_wait_node*/ + int st_libpq_wait_nodecount; /* for libpq, point to libpq_wait_nodecount*/ + uint32 st_tempid; /* tempid for temp table */ + uint32 st_timelineid; /* timeline id for temp table */ + int4 st_jobid; /* job work id */ + + /* Latest connected GTM host index and time line */ + GtmHostIndex st_gtmhost; + GTM_Timeline st_gtmtimeline; + slock_t use_mutex; /* protect above variables */ + + /* lwlock deadlock check */ + /* +1 before waiting; +1 after holding */ + int lw_count; + /* lwlock object now requiring */ + LWLock* lw_want_lock; + + /* all lwlocks held by this thread */ + int* lw_held_num; /* point to num_held_lwlocks */ + void* lw_held_locks; /* point to held_lwlocks[] */ + volatile bool st_lw_access_flag; /* valid flag */ + volatile bool st_lw_is_cleanning_flag; /* is cleanning lw ptr */ + + RemoteInfo remote_info; + WaitInfo waitInfo; + LOCALLOCKTAG locallocktag; /* locked object */ + /* The entry is valid if st_block_sessionid > 0, unused if st_block_sessionid == 0 */ + volatile uint64 st_block_sessionid; /* block session */ + syscalllock statement_cxt_lock; /* mutex for statement context(between session and statement flush thread) */ + void* statement_cxt; /* statement context of full sql */ +} PgBackendStatus; + +typedef struct PgBackendStatusNode { + PgBackendStatus* data; + NameData database_name; + PgBackendStatusNode* next; +} PgBackendStatusNode; + +typedef struct ThreadWaitStatusInfo { + ParallelFunctionState* state; + TupleTableSlot* slot; +} ThreadWaitStatusInfo; + +typedef struct CommInfoParallel { + ParallelFunctionState* state; + TupleTableSlot* slot; +} CommInfoParallel; + +extern CommInfoParallel* getGlobalCommStatus(TupleDesc tuple_desc, char* queryString); +extern ThreadWaitStatusInfo* getGlobalThreadWaitStatus(TupleDesc tuple_desc); + +extern PgBackendStatus* PgBackendStatusArray; + +/* + * Macros to load and store st_changecount with the memory barriers. + * + * pgstat_increment_changecount_before() and + * pgstat_increment_changecount_after() need to be called before and after + * PgBackendStatus entries are modified, respectively. This makes sure that + * st_changecount is incremented around the modification. + * + * Also pgstat_save_changecount_before() and pgstat_save_changecount_after() + * need to be called before and after PgBackendStatus entries are copied into + * private memory, respectively. + */ +#define pgstat_increment_changecount_before(beentry) \ + do { \ + beentry->st_changecount++; \ + pg_write_barrier(); \ + } while (0) + +#define pgstat_increment_changecount_after(beentry) \ + do { \ + pg_write_barrier(); \ + beentry->st_changecount++; \ + Assert((beentry->st_changecount & 1) == 0); \ + } while (0) + +#define pgstat_save_changecount_before(beentry, save_changecount) \ + do { \ + save_changecount = beentry->st_changecount; \ + pg_read_barrier(); \ + } while (0) + +#define pgstat_save_changecount_after(beentry, save_changecount) \ + do { \ + pg_read_barrier(); \ + save_changecount = beentry->st_changecount; \ + } while (0) + +extern char* getThreadWaitStatusDesc(PgBackendStatus* beentry); +extern const char* pgstat_get_waitstatusdesc(uint32 wait_event_info); +extern const char* pgstat_get_waitstatusname(uint32 wait_event_info); +extern const char* PgstatGetWaitstatephasename(uint32 waitPhaseInfo); +extern pthread_mutex_t nodeDefCopyLock; + +/* + * Working state needed to accumulate per-function-call timing statistics. + */ +typedef struct PgStat_FunctionCallUsage { + /* Link to function's hashtable entry (must still be there at exit!) */ + /* NULL means we are not tracking the current function call */ + PgStat_FunctionCounts* fs; + /* Total time previously charged to function, as of function start */ + instr_time save_f_total_time; + /* Backend-wide total time as of function start */ + instr_time save_total; + /* system clock as of function start */ + instr_time f_start; +} PgStat_FunctionCallUsage; + +extern THR_LOCAL volatile Oid* libpq_wait_nodeid; +extern THR_LOCAL volatile int* libpq_wait_nodecount; + +/* ---------- + * Functions called from postmaster + * ---------- + */ +extern Size BackendStatusShmemSize(void); +extern void CreateSharedBackendStatus(void); + +extern void pgstat_init(void); +extern ThreadId pgstat_start(void); +extern void pgstat_reset_all(void); +extern void allow_immediate_pgstat_restart(void); +extern void PgstatCollectorMain(); + +/* ---------- + * Functions called from backends + * ---------- + */ +const int NUM_PERCENTILE = 2; +extern void pgstat_ping(void); +extern void UpdateWaitStatusStat(volatile WaitInfo* InstrWaitInfo, uint32 waitstatus, int64 duration); +extern void UpdateWaitEventStat(volatile WaitInfo* InstrWaitInfo, uint32 wait_event_info, int64 duration); +extern void UpdateWaitEventFaildStat(volatile WaitInfo* InstrWaitInfo, uint32 wait_event_info); +extern void CollectWaitInfo(WaitInfo* gsInstrWaitInfo, WaitStatusInfo status_info, WaitEventInfo event_info); +extern void InstrWaitEventInitLastUpdated(PgBackendStatus* current_entry, TimestampTz current_time); +extern void pgstat_report_stat(bool force); +extern void pgstat_vacuum_stat(void); +extern void pgstat_drop_database(Oid databaseid); + +extern void pgstat_clear_snapshot(void); +extern void pgstat_reset_counters(void); +extern void pgstat_reset_shared_counters(const char*); +extern void pgstat_reset_single_counter(Oid p_objoid, Oid objectid, PgStat_Single_Reset_Type type); + +extern void pgstat_report_autovac(Oid dboid); +extern void pgstat_report_autovac_timeout(Oid tableoid, uint32 statFlag, bool shared); +extern void pgstat_report_vacuum(Oid tableoid, uint32 statFlag, bool shared, PgStat_Counter tuples); +extern void pgstat_report_truncate(Oid tableoid, uint32 statFlag, bool shared); +extern void pgstat_report_data_changed(Oid tableoid, uint32 statFlag, bool shared); + +extern void pgstat_report_sql_rt(uint64 UniqueSQLId, int64 start_time, int64 rt); +extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples); + +extern void pgstat_report_recovery_conflict(int reason); +extern void pgstat_report_deadlock(void); +const char* remote_conn_type_string(int remote_conn_type); +extern void pgstat_initialize(void); +extern void pgstat_bestart(void); +extern void pgstat_initialize_session(void); +extern void pgstat_deinitialize_session(void); +extern void pgstat_couple_decouple_session(bool is_couple); +extern void pgstat_beshutdown_session(int ctrl_index); + +extern const char* pgstat_get_wait_io(WaitEventIO w); +extern void pgstat_report_activity(BackendState state, const char* cmd_str); +extern void pgstat_report_tempfile(size_t filesize); +extern void pgstat_report_memReserved(int4 memReserved, int reserve_or_release); +extern void pgstat_report_statement_wlm_status(); +extern void pgstat_refresh_statement_wlm_time(volatile PgBackendStatus* beentry); +extern void pgstat_report_wait_count(uint32 wait_event_info); +extern void pgstat_report_appname(const char* appname); +extern void pgstat_report_conninfo(const char* conninfo); +extern void pgstat_report_xact_timestamp(TimestampTz tstamp); +extern void pgstat_report_waiting_on_resource(WorkloadManagerEnqueueState waiting); +extern void pgstat_report_queryid(uint64 queryid); +extern void pgstat_report_jobid(uint64 jobid); +extern void pgstat_report_parent_sessionid(uint64 sessionid, uint32 level = 0); +extern void pgstat_report_smpid(uint32 smpid); +extern void pgstat_report_blocksid(void* waitLockThrd, uint64 blockSessionId); +extern bool pgstat_get_waitlock(uint32 wait_event_info); +extern const char* pgstat_get_wait_event(uint32 wait_event_info); +extern const char* pgstat_get_backend_current_activity(ThreadId pid, bool checkUser); +extern const char* pgstat_get_crashed_backend_activity(ThreadId pid, char* buffer, int buflen); + +extern PgStat_TableStatus* find_tabstat_entry(Oid rel_id, uint32 statFlag); +extern PgStat_BackendFunctionEntry* find_funcstat_entry(Oid func_id); +extern void pgstat_initstats(Relation rel); + +extern void pgstat_report_connected_gtm_host(GtmHostIndex gtm_host); +extern void pgstat_report_connected_gtm_timeline(GTM_Timeline gtm_timeline); +extern void pgstat_cancel_invalid_gtm_conn(void); +extern void pgstat_reply_percentile_record_count(); +extern void pgstat_reply_percentile_record(); +extern int pgstat_fetch_sql_rt_info_counter(); +extern void pgstat_fetch_sql_rt_info_internal(SqlRTInfo* sqlrt); +extern void processCalculatePercentile(void); +void pgstat_update_responstime_singlenode(uint64 UniqueSQLId, int64 start_time, int64 rt); +void pgstate_update_percentile_responsetime(void); + +#define IS_PGSTATE_TRACK_UNDEFINE \ + (!u_sess->attr.attr_common.pgstat_track_activities || !t_thrd.shemem_ptr_cxt.MyBEEntry) + +/* + * Simple way, only updates wait status and return the last wait status + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus(WaitState waitstatus, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + WaitState oldwaitstatus; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + pgstat_increment_changecount_before(beentry); + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + oldwaitstatus = beentry->st_waitstatus; + beentry->st_waitstatus = waitstatus; + if (t_thrd.role == THREADPOOL_WORKER) { + t_thrd.threadpool_cxt.worker->m_waitState = waitstatus; + } + + /* If it switches into STATE_POOLER_CREATE_CONN, point to global thread local parameters. */ + if (STATE_POOLER_CREATE_CONN == waitstatus) { + libpq_wait_nodeid = &(beentry->st_libpq_wait_nodeid); + libpq_wait_nodecount = &(beentry->st_libpq_wait_nodecount); + } + + /* If it is restored to STATE_WAIT_UNDEFINED, restore the related parameters. */ + if (STATE_WAIT_UNDEFINED == waitstatus) { + beentry->st_xid = 0; + beentry->st_nodeid = -1; + beentry->st_waitnode_count = 0; + beentry->st_plannodeid = -1; + beentry->st_numnodes = -1; + beentry->st_relname[0] = '\0'; + beentry->st_relname[NAMEDATALEN * 2 - 1] = '\0'; + beentry->st_libpq_wait_nodecount = 0; + beentry->st_libpq_wait_nodeid = InvalidOid; + } + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) { + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + } else if (u_sess->attr.attr_common.enable_instr_track_wait && + (uint32)oldwaitstatus != (uint32)STATE_WAIT_UNDEFINED && waitstatus == STATE_WAIT_UNDEFINED) { + int64 duration = GetCurrentTimestamp() - beentry->waitInfo.status_info.start_time; + UpdateWaitStatusStat(&beentry->waitInfo, (uint32)oldwaitstatus, duration); + beentry->waitInfo.status_info.start_time = 0; + } + + pgstat_increment_changecount_after(beentry); + + return oldStatus; +} + +/* + * For 64-bit xid, report waitstatus and xid, then return the last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_xid(WaitState waitstatus, uint64 xid, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + beentry->st_xid = xid; + + return oldStatus; +} + +/* + * For status related to relation, eg.vacuum, analyze, etc. report waitstatus and relname. + * Then, return the last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_relname(WaitState waitstatus, char* relname, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + int len = 0; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + /* This should be unnecessary if GUC did its job, but be safe */ + if (relname != NULL) { + len = pg_mbcliplen(relname, strlen(relname), NAMEDATALEN * 2 - 1); + } + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + if (relname != NULL) { + errno_t rc = memcpy_s((char*)beentry->st_relname, NAMEDATALEN * 2, relname, len); + securec_check(rc, "\0", "\0"); + + pfree(relname); + relname = NULL; + } + beentry->st_relname[len] = '\0'; + + return oldStatus; +} + +/* + * For wait status with wait node info, update node info and return last wait status. + * Note. when isOnlyFetch is flaged true, only fetch last waitstatus. + */ +static inline WaitState pgstat_report_waitstatus_comm(WaitState waitstatus, int nodeId = -1, int waitnode_count = -1, + int plannodeid = -1, int numnodes = -1, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return STATE_WAIT_UNDEFINED; + WaitState oldStatus = beentry->st_waitstatus; + + if (isOnlyFetch) + return oldStatus; + + if (u_sess->attr.attr_common.enable_instr_track_wait && (int)waitstatus != (int)STATE_WAIT_UNDEFINED) + beentry->waitInfo.status_info.start_time = GetCurrentTimestamp(); + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus = waitstatus; + beentry->st_nodeid = nodeId; + beentry->st_waitnode_count = waitnode_count; + beentry->st_plannodeid = plannodeid; + beentry->st_numnodes = numnodes; + + return oldStatus; +} + +/* + * For wait status which needs to focus its phase, update phase info and return the last wait phase. + * Note. when isOnlyFetch is flaged true, only fetch last phase. + */ +static inline WaitStatePhase pgstat_report_waitstatus_phase(WaitStatePhase waitstatus_phase, bool isOnlyFetch = false) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return PHASE_NONE; + + WaitStatePhase oldPhase = beentry->st_waitstatus_phase; + + if (isOnlyFetch) + return oldPhase; + + /* + * Since this is a single-byte field in a struct that only this process + * may modify, there seems no need to bother with the st_changecount + * protocol. The update must appear atomic in any case. + */ + beentry->st_waitstatus_phase = waitstatus_phase; + return oldPhase; +} + +static inline void pgstat_report_wait_lock_failed(uint32 wait_event_info) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + if (!u_sess->attr.attr_common.pgstat_track_activities || !u_sess->attr.attr_common.enable_instr_track_wait || + !beentry) + return; + pgstat_increment_changecount_before(beentry); + uint32 old_wait_event_info = beentry->st_waitevent; + UpdateWaitEventFaildStat(&beentry->waitInfo, old_wait_event_info); + pgstat_increment_changecount_after(beentry); +} + +/* ---------- + * pgstat_report_waitevent() - + * + * Called from places where server process needs to wait. This is called + * to report wait event information. The wait information is stored + * as 4-bytes where first byte represents the wait event class (type of + * wait, for different types of wait, refer WaitClass) and the next + * 3-bytes represent the actual wait event. Currently 2-bytes are used + * for wait event which is sufficient for current usage, 1-byte is + * reserved for future usage. + * + * ---------- + */ +static inline void pgstat_report_waitevent(uint32 wait_event_info) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return; + + pgstat_increment_changecount_before(beentry); + /* + * Since this is a four-byte field which is always read and written as + * four-bytes, updates are atomic. + */ + uint32 old_wait_event_info = beentry->st_waitevent; + beentry->st_waitevent = wait_event_info; + + if (u_sess->attr.attr_common.enable_instr_track_wait && wait_event_info != WAIT_EVENT_END) { + beentry->waitInfo.event_info.start_time = GetCurrentTimestamp(); + } else if (u_sess->attr.attr_common.enable_instr_track_wait && old_wait_event_info != WAIT_EVENT_END && + wait_event_info == WAIT_EVENT_END) { + int64 duration = GetCurrentTimestamp() - beentry->waitInfo.event_info.start_time; + UpdateWaitEventStat(&beentry->waitInfo, old_wait_event_info, duration); + beentry->waitInfo.event_info.start_time = 0; + } + + pgstat_increment_changecount_after(beentry); +} + +static inline void pgstat_reset_waitStatePhase(WaitState waitstatus, WaitStatePhase waitstatus_phase) +{ + volatile PgBackendStatus* beentry = t_thrd.shemem_ptr_cxt.MyBEEntry; + + if (IS_PGSTATE_TRACK_UNDEFINE) + return; + + beentry->st_waitstatus = waitstatus; + beentry->st_waitstatus_phase = waitstatus_phase; + + beentry->st_xid = 0; + beentry->st_nodeid = -1; + beentry->st_waitnode_count = 0; + beentry->st_plannodeid = -1; + beentry->st_numnodes = -1; + beentry->st_relname[0] = '\0'; + beentry->st_relname[NAMEDATALEN * 2 - 1] = '\0'; + beentry->st_libpq_wait_nodeid = InvalidOid; + beentry->st_libpq_wait_nodecount = 0; +} + +/* nontransactional event counts are simple enough to inline */ +#define pgstat_count_heap_scan(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_numscans++; \ + pgstatCountHeapScan4SessionLevel(); \ + } while (0) +#define pgstat_count_heap_getnext(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_returned++; \ + } while (0) +#define pgstat_count_heap_fetch(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_fetched++; \ + } while (0) +#define pgstat_count_index_scan(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_numscans++; \ + pgstatCountIndexScan4SessionLevel(); \ + } while (0) +#define pgstat_count_index_tuples(rel, n) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_tuples_returned += (n); \ + } while (0) +#define pgstat_count_buffer_read(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_blocks_fetched++; \ + } while (0) +#define pgstat_count_buffer_hit(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_blocks_hit++; \ + } while (0) +#define pgstat_count_buffer_read_time(n) (u_sess->stat_cxt.pgStatBlockReadTime += (n)) +#define pgstat_count_buffer_write_time(n) (u_sess->stat_cxt.pgStatBlockWriteTime += (n)) + +#define pgstat_count_cu_mem_hit(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_mem_hit++; \ + } while (0) +#define pgstat_count_cu_hdd_sync(rel) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_hdd_sync++; \ + } while (0) +#define pgstat_count_cu_hdd_asyn(rel, n) \ + do { \ + if ((rel)->pgstat_info != NULL) \ + (rel)->pgstat_info->t_counts.t_cu_hdd_asyn += (n); \ + } while (0) + +extern void pgstat_count_heap_insert(Relation rel, int n); +extern void pgstat_count_heap_update(Relation rel, bool hot); +extern void pgstat_count_heap_delete(Relation rel); +extern void pgstat_count_truncate(Relation rel); +extern void pgstat_update_heap_dead_tuples(Relation rel, int delta); + +extern void pgstat_count_cu_update(Relation rel, int n); +extern void pgstat_count_cu_delete(Relation rel, int n); + +#define pgstat_count_cu_insert(rel, n) \ + do { \ + pgstat_count_heap_insert(rel, n); \ + } while (0) + +#define pgstat_count_dfs_insert(rel, n) \ + do { \ + pgstat_count_cu_insert(rel, n); \ + } while (0) +#define pgstat_count_dfs_update(rel, n) \ + do { \ + pgstat_count_cu_update(rel, n); \ + } while (0) +#define pgstat_count_dfs_delete(rel, n) \ + do { \ + pgstat_count_cu_delete(rel, n); \ + } while (0) + +extern void pgstat_init_function_usage(FunctionCallInfoData* fcinfo, PgStat_FunctionCallUsage* fcu); +extern void pgstat_end_function_usage(PgStat_FunctionCallUsage* fcu, bool finalize); + +extern void AtEOXact_PgStat(bool isCommit); +extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth); + +extern void AtPrepare_PgStat(void); +extern void PostPrepare_PgStat(void); + +extern void pgstat_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void pgstat_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern void pgstat_send_bgwriter(void); + +/* ---------- + * Support functions for the SQL-callable functions to + * generate the pgstat* views. + * ---------- + */ +extern PgStat_StatDBEntry* pgstat_fetch_stat_dbentry(Oid dbid); +extern PgStat_StatTabEntry* pgstat_fetch_stat_tabentry(PgStat_StatTabKey* tabkey); +extern PgStat_StatFuncEntry* pgstat_fetch_stat_funcentry(Oid funcid); +extern PgStat_GlobalStats* pgstat_fetch_global(void); +extern PgStat_WaitCountStatus* pgstat_fetch_waitcount(void); + +extern void pgstat_initstats_partition(Partition part); + +typedef enum StatisticsLevel { + STAT_LEVEL_OFF = 0, + STAT_LEVEL_BASIC, + STAT_LEVEL_TYPICAL, + STAT_LEVEL_ALL +} StatisticsLevel; + +/* Values for stat_view --- order is significant! */ +typedef enum STAT_VIEW { + PV_CONFIG_PARAMETER = 0, + PV_ACTIVITY, + PV_LOCK, + PV_SESSION_STAT, + PV_DB_STAT, + PV_INSTANCE_STAT, + PV_STAT_NAME, + PV_OS_RUN_INFO, + PV_BASIC_LEVEL, /*Above are at basic level,defaut on*/ + + PV_LIGHTWEIGHT_LOCK, + PV_WAIT_TYPE, + PV_SESSION_WAIT, + PV_SESSION_WAIT_SUMMARY, + PV_DB_WAIT_SUMMARY, + PV_INSTANCE_WAIT_SUMMARY, + PV_SESSION_MEMORY_INFO, + PV_SESSION_TIME, + PV_DB_TIME, + PV_INSTANCE_TIME, + PV_REDO_STAT, + PV_TYPICAL_LEVEL, /*Above are at typical level,defaut off*/ + + PV_STATEMENT, + PV_FILE_STAT, + PV_IOSTAT_NETWORK, + PV_SHARE_MEMORY_INFO, + PV_PLAN, + PV_ALL_LEVEL /*Above are at all level,defaut off*/ +} STAT_VIEW; + +// static StatisticsLevel viewLevel[]={ +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, +// STAT_LEVEL_BASIC, /*Above are at basic level,defaut on*/ +// +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL, +// STAT_LEVEL_TYPICAL,/*Above are at typical level,defaut off*/ +// +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL, +// STAT_LEVEL_ALL +// }; + +typedef enum OSRunInfoTypes { + /*cpu numbers*/ + NUM_CPUS = 0, + NUM_CPU_CORES, + NUM_CPU_SOCKETS, + + /*cpu times*/ + IDLE_TIME, + BUSY_TIME, + USER_TIME, + SYS_TIME, + IOWAIT_TIME, + NICE_TIME, + + /*avg cpu times*/ + AVG_IDLE_TIME, + AVG_BUSY_TIME, + AVG_USER_TIME, + AVG_SYS_TIME, + AVG_IOWAIT_TIME, + AVG_NICE_TIME, + + /*virtual memory page in/out data*/ + VM_PAGE_IN_BYTES, + VM_PAGE_OUT_BYTES, + + /*os run load*/ + RUNLOAD, + + /*physical memory size*/ + PHYSICAL_MEMORY_BYTES, + + TOTAL_OS_RUN_INFO_TYPES +} OSRunInfoTypes; + +/* + *this is used to represent the numbers of cpu time we should read from file.BUSY_TIME will be + *calculate by USER_TIME plus SYS_TIME,so it wouldn't be counted. + */ +#define NumOfCpuTimeReads (AVG_IDLE_TIME - IDLE_TIME - 1) + +/*the type we restore our collected data. It is a union of all the possible data types of the os run info*/ +typedef union NumericValue { + uint64 int64Value; /*cpu times,vm pgin/pgout size,total memory etc.*/ + float8 float8Value; /*load*/ + uint32 int32Value; /*cpu numbers*/ +} NumericValue; + +/* + *description of the os run info fields. For a particluar field, all the members except got + *are fixed. + */ +typedef struct OSRunInfoDesc { + /*hook to convert our data to Datum type, it decides by the data type the field*/ + Datum (*getDatum)(NumericValue data); + + char* name; /*field name*/ + bool cumulative; /*represent whether the field is cumulative*/ + + /* + *it represent whether we successfully get data of this field. Because some fields may be subject to the + *os platform on which the database is running, or not available in some exception cases. I don't think + *it's a big deal, we just show the infomation we can get. + */ + bool got; + char* comments; /*field comments*/ +} OSRunInfoDesc; + +extern const OSRunInfoDesc osStatDescArrayOrg[TOTAL_OS_RUN_INFO_TYPES]; + +extern int64 getCpuTime(void); +extern int64 JiffiesToSec(uint64); +extern void getCpuNums(void); +extern void getCpuTimes(void); +extern void getVmStat(void); +extern void getTotalMem(void); +extern void getOSRunLoad(void); + +extern Datum Int64GetNumberDatum(NumericValue value); +extern Datum Float8GetNumberDatum(NumericValue value); +extern Datum Int32GetNumberDatum(NumericValue value); + +static inline ssize_t gs_getline(char** lineptr, size_t* n, FILE* stream) +{ + *lineptr = (char*)palloc0(4096); + *n = 4096; + return getline(lineptr, n, stream); +} + +#define SESSION_ID_LEN 32 +extern void getSessionID(char* sessid, pg_time_t startTime, ThreadId Threadid); +extern void getThrdID(char* thrdid, pg_time_t startTime, ThreadId Threadid); + +#define NUM_MOT_SESSION_MEMORY_DETAIL_ELEM 4 + +typedef struct MotSessionMemoryDetail { + ThreadId threadid; + pg_time_t threadStartTime; + int64 totalSize; + int64 freeSize; + int64 usedSize; +} MotSessionMemoryDetail; + +typedef struct MotSessionMemoryDetailPad { + uint32 nelements; + MotSessionMemoryDetail* sessionMemoryDetail; +} MotSessionMemoryDetailPad; + +typedef struct MotMemoryDetail { + int64 numaNode; + int64 reservedMemory; + int64 usedMemory; +} MotMemoryDetail; + +typedef struct MotMemoryDetailPad { + uint32 nelements; + MotMemoryDetail* memoryDetail; +} MotMemoryDetailPad; + +extern MotSessionMemoryDetail* GetMotSessionMemoryDetail(uint32* num); +extern MotMemoryDetail* GetMotMemoryDetail(uint32* num, bool isGlobal); + +#ifdef MEMORY_CONTEXT_CHECKING +typedef enum { STANDARD_DUMP, SHARED_DUMP } DUMP_TYPE; + +extern void DumpMemoryContext(DUMP_TYPE type); +#endif + +extern void getThreadMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc, uint32* procIdx); +extern void getSharedMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc); + +typedef enum TimeInfoType { + DB_TIME = 0, /*total elapsed time while dealing user command.*/ + CPU_TIME, /*total cpu time used while dealing user command.*/ + + /*statistics of specific execution stage.*/ + EXECUTION_TIME, /*total elapsed time of execution stage.*/ + PARSE_TIME, /*total elapsed time of parse stage.*/ + PLAN_TIME, /*total elapsed time of plan stage.*/ + REWRITE_TIME, /*total elapsed time of rewrite stage.*/ + + /*statistics for plpgsql especially*/ + PL_EXECUTION_TIME, /*total elapsed time of plpgsql exection.*/ + PL_COMPILATION_TIME, /*total elapsed time of plpgsql compilation.*/ + + NET_SEND_TIME, + DATA_IO_TIME, + + TOTAL_TIME_INFO_TYPES +} TimeInfoType; + +typedef struct SessionTimeEntry { + /* + *protect the rest part of the entry. + */ + uint32 changeCount; + + bool isActive; + + uint64 sessionid; + pg_time_t myStartTime; + + int64 array[TOTAL_TIME_INFO_TYPES]; +} SessionTimeEntry; + +/* + *this macro is used to read a entry from global array to a local buffer. we use changeCount to + *ensure data consistency. + */ +#define READ_AN_ENTRY(dest, src, changeCount, type) \ + do { \ + for (;;) { \ + uint32 saveChangeCount = changeCount; \ + errno_t rc = 0; \ + rc = memcpy_s(dest, sizeof(type), src, sizeof(type)); \ + securec_check(rc, "\0", "\0"); \ + if ((saveChangeCount & 1) == 0 && saveChangeCount == changeCount) \ + break; \ + CHECK_FOR_INTERRUPTS(); \ + } \ + } while (0) + +#define SessionTimeArraySize (BackendStatusArray_size) + +#define PGSTAT_INIT_TIME_RECORD() int64 startTime = 0; + +#define PGSTAT_START_TIME_RECORD() \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ + startTime = GetCurrentTimestamp(); \ + } while (0) + +#define PGSTAT_END_TIME_RECORD(stage) \ + do { \ + if (t_thrd.shemem_ptr_cxt.mySessionTimeEntry) \ + u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ + } while (0) + +#define PGSTAT_START_PLSQL_TIME_RECORD() \ + do { \ + if (u_sess->stat_cxt.isTopLevelPlSql && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + startTime = GetCurrentTimestamp(); \ + u_sess->stat_cxt.isTopLevelPlSql = false; \ + needRecord = true; \ + } \ + } while (0) + +#define PGSTAT_END_PLSQL_TIME_RECORD(stage) \ + do { \ + if (needRecord == true && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localTimeInfoArray[stage] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.isTopLevelPlSql = true; \ + } \ + } while (0) + +extern const char* TimeInfoTypeName[TOTAL_TIME_INFO_TYPES]; + +extern Size sessionTimeShmemSize(void); +extern void sessionTimeShmemInit(void); + +extern void timeInfoRecordStart(void); +extern void timeInfoRecordEnd(void); + +extern SessionTimeEntry* getSessionTimeStatus(uint32* num); +extern SessionTimeEntry* getInstanceTimeStatus(); + +typedef struct PgStat_RedoEntry { + PgStat_Counter writes; + PgStat_Counter writeBlks; + PgStat_Counter writeTime; + PgStat_Counter avgIOTime; + PgStat_Counter lstIOTime; + PgStat_Counter minIOTime; + PgStat_Counter maxIOTime; +} PgStat_RedoEntry; + +extern PgStat_RedoEntry redoStatistics; +// extern LWLock* redoStatLock; + +extern void reportRedoWrite(PgStat_Counter blks, PgStat_Counter tim); + +typedef struct PgStat_FileEntry { + int changeCount; + + Oid dbid; + Oid spcid; + Oid fn; + + PgStat_Counter reads; + PgStat_Counter writes; + PgStat_Counter readBlks; + PgStat_Counter readTime; + PgStat_Counter writeBlks; + PgStat_Counter writeTime; + PgStat_Counter avgIOTime; + PgStat_Counter lstIOTime; + PgStat_Counter minIOTime; + PgStat_Counter maxIOTime; +} PgStat_FileEntry; + +#define NUM_FILES 2000 +#define STAT_MSG_BATCH 100 // reduce message frequence by count 100 times. + +extern PgStat_FileEntry pgStatFileArray[NUM_FILES]; +extern uint32 fileStatCount; +extern void reportFileStat(PgStat_MsgFile* msg); + +typedef enum SessionStatisticType { + N_COMMIT_SESSION_LEVEL = 0, + N_ROLLBACK_SESSION_LEVEL, + N_SQL_SESSION_LEVEL, + + N_TABLE_SCAN_SESSION_LEVEL, + + N_BLOCKS_FETCHED_SESSION_LEVEL, + N_PHYSICAL_READ_OPERATION_SESSION_LEVEL, /*it is equal to N_BLOCKS_FETCHED_SESSION_LEVEL now*/ + N_SHARED_BLOCKS_DIRTIED_SESSION_LEVEL, + N_LOCAL_BLOCKS_DIRTIED_SESSION_LEVEL, + N_SHARED_BLOCKS_READ_SESSION_LEVEL, + N_LOCAL_BLOCKS_READ_SESSION_LEVEL, + T_BLOCKS_READ_TIME_SESSION_LEVEL, + T_BLOCKS_WRITE_TIME_SESSION_LEVEL, + + N_SORT_IN_MEMORY_SESSION_LEVEL, + N_SORT_IN_DISK_SESSION_LEVEL, + + N_CU_MEM_HIT, + N_CU_HDD_SYNC_READ, + N_CU_HDD_ASYN_READ, + + N_TOTAL_SESSION_STATISTICS_TYPES +} SessionStatisticType; + +typedef struct SessionLevelStatistic { + pg_time_t sessionStartTime; + uint64 sessionid; + bool isValid; + + PgStat_Counter array[N_TOTAL_SESSION_STATISTICS_TYPES]; +} SessionLevelStatistic; + +#define SessionStatArraySize (BackendStatusArray_size) + +#define pgstatCountTransactionCommit4SessionLevel(isCommit) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + if (isCommit) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_COMMIT_SESSION_LEVEL]++; \ + } else { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_ROLLBACK_SESSION_LEVEL]++; \ + } \ + } \ + } while (0) + +#define pgstatCountSQL4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SQL_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountIndexScan4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_TABLE_SCAN_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountHeapScan4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_TABLE_SCAN_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountBlocksFetched4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_BLOCKS_FETCHED_SESSION_LEVEL]++; \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_PHYSICAL_READ_OPERATION_SESSION_LEVEL]++; \ + } \ + } while (0) + +#define pgstatCountSharedBlocksDirtied4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SHARED_BLOCKS_DIRTIED_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountLocalBlocksDirtied4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_LOCAL_BLOCKS_DIRTIED_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountSharedBlocksRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SHARED_BLOCKS_READ_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountLocalBlocksRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_LOCAL_BLOCKS_READ_SESSION_LEVEL]++; \ + } while (0) + +#define pgstatCountBlocksReadTime4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[T_BLOCKS_READ_TIME_SESSION_LEVEL] += value; \ + } while (0) + +#define pgstatCountBlocksWriteTime4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[T_BLOCKS_WRITE_TIME_SESSION_LEVEL] += value; \ + } while (0) + +#define pgstatCountSort4SessionLevel(isSortInMemory) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) { \ + if (isSortInMemory) { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SORT_IN_MEMORY_SESSION_LEVEL]++; \ + } else { \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_SORT_IN_DISK_SESSION_LEVEL]++; \ + } \ + } \ + } while (0) + +#define pgstatCountCUMemHit4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_MEM_HIT]++; \ + } while (0) + +#define pgstatCountCUHDDSyncRead4SessionLevel() \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_HDD_SYNC_READ]++; \ + } while (0) + +#define pgstatCountCUHDDAsynRead4SessionLevel(value) \ + do { \ + if (NULL != t_thrd.shemem_ptr_cxt.mySessionStatEntry) \ + t_thrd.shemem_ptr_cxt.mySessionStatEntry->array[N_CU_HDD_ASYN_READ] += (value); \ + } while (0) + +extern void DumpLWLockInfoToServerLog(void); +extern SessionLevelStatistic* getSessionStatistics(uint32* num); +extern Size sessionStatShmemSize(void); +extern void sessionStatShmemInit(void); + +#define NUM_BUFFERCACHE_PAGES_ELEM 9 + +#define CONNECTIONINFO_LEN 8192 /* Maximum length of GUC parameter connection_info */ + +/* + * Record structure holding the to-be-exposed cache data. + */ +typedef struct { + uint32 bufferid; + Oid relfilenode; + int2 bucketnode; + Oid reltablespace; + Oid reldatabase; + ForkNumber forknum; + BlockNumber blocknum; + bool isvalid; + bool isdirty; + uint16 usagecount; +} BufferCachePagesRec; + +/* + * Function context for data persisting over repeated calls. + */ +typedef struct { + TupleDesc tupdesc; + BufferCachePagesRec* record; +} BufferCachePagesContext; + +/* Function context for table distribution over repeated calls. */ +typedef struct TableDistributionInfo { + ParallelFunctionState* state; + TupleTableSlot* slot; +} TableDistributionInfo; + +typedef struct SessionLevelMemory { + pg_time_t threadStartTime; /* thread start time */ + uint64 sessionid; /* session id */ + bool isValid; /* is valid */ + bool iscomplex; /* is complex query */ + + int initMemInChunks; /* initialize memory */ + int queryMemInChunks; /* query used memory */ + int peakChunksQuery; /* peak memory */ + + int spillCount; /* dn spill count */ + int64 spillSize; /* dn spill size */ + int64 broadcastSize; /* broadcast size */ + int64 estimate_time; /* estimate total time */ + int estimate_memory; /* estimate total memory, unit is MB */ + uint32 warning; /* warning info */ + char* query_plan_issue; /* query plan warning info */ + char* query_plan; /* query plan */ + TimestampTz dnStartTime; /* start time on dn */ + TimestampTz dnEndTime; /* end time on dn */ + uint64 plan_size; +} SessionLevelMemory; + +extern SessionLevelMemory* getSessionMemory(uint32* num); +extern Size sessionMemoryShmemSize(void); +extern void sessionMemoryShmemInit(void); + +extern int pgstat_get_current_active_numbackends(void); +extern PgBackendStatus* pgstat_get_backend_single_entry(ThreadId tid); +extern void pgstat_increase_session_spill(); +extern void pgstat_increase_session_spill_size(int64 size); +extern void pgstat_add_warning_early_spill(); +extern void pgstat_add_warning_spill_on_memory_spread(); +extern void pgstat_add_warning_hash_conflict(); +extern void pgstat_set_io_state(WorkloadManagerIOState iostate); +extern void pgstat_set_stmt_tag(WorkloadManagerStmtTag stmttag); +extern ThreadId* pgstat_get_user_io_entry(Oid userid, int* num); +extern ThreadId* pgstat_get_stmttag_write_entry(int* num); +extern List* pgstat_get_user_backend_entry(Oid userid); +extern void pgstat_reset_current_status(void); +extern WaitInfo* read_current_instr_wait_info(void); +extern TableDistributionInfo* getTableDataDistribution( + TupleDesc tuple_desc, char* schema_name = NULL, char* table_name = NULL); +extern TableDistributionInfo* getTableStat( + TupleDesc tuple_desc, int dirty_pecent, int n_tuples, char* schema_name = NULL); +extern TableDistributionInfo* get_remote_stat_pagewriter(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_ckpt(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_bgwriter(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_single_flush_dw_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_double_write(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_stat_redo(TupleDesc tuple_desc); +extern TableDistributionInfo* get_rto_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_recovery_stat(TupleDesc tuple_desc); +extern TableDistributionInfo* get_remote_node_xid_csn(TupleDesc tuple_desc); + +#define SessionMemoryArraySize (BackendStatusArray_size) + +/* Code Area for LWLock deadlock monitor */ + +#define CHANGECOUNT_IS_EVEN(_x) (((_x)&1) == 0) + +typedef struct { + ThreadId thread_id; + uint64 st_sessionid; +} lock_entry_id; + +typedef struct { + /* thread id for backend */ + lock_entry_id entry_id; + /* light weight change count */ + int lw_count; +} lwm_light_detect; + +typedef struct { + lock_entry_id holder_tid; + LWLockMode lock_sx; +} holding_lockmode; + +typedef struct { + lock_entry_id be_tid; /* thread id */ + int be_idx; /* backend position */ + LWLockAddr want_lwlock; /* lock to acquire */ + int lwlocks_num; /* number of locks held */ + lwlock_id_mode* held_lwlocks; /* held lwlocks */ +} lwm_lwlocks; + +typedef struct FileIOStat { + unsigned int changeCount; + PgStat_Counter reads; /* read count of file */ + PgStat_Counter writes; /* write count of file */ + PgStat_Counter readBlks; /* num of read blocks */ + PgStat_Counter writeBlks; /* num of write blocks */ +} FileIOStat; + +extern lwm_light_detect* pgstat_read_light_detect(void); +extern lwm_lwlocks* pgstat_read_diagnosis_data( + lwm_light_detect* light_det, const int* candidates_idx, int num_candidates); +extern TimestampTz pgstat_read_xact_start_tm(int be_index); + +extern THR_LOCAL HTAB* analyzeCheckHash; +extern void pgstat_read_analyzed(); +typedef struct PgStat_AnaCheckEntry { + Oid tableid; + bool is_analyzed; +} PgStat_AnaCheckEntry; + +extern HTAB* global_bad_block_stat; +extern void initLocalBadBlockStat(); +extern void addBadBlockStat(const RelFileNode* relfilenode, ForkNumber forknum); +extern void resetBadBlockStat(); + +extern bool CalcSQLRowStatCounter( + PgStat_TableCounts* last_total_counter, PgStat_TableCounts* current_sql_table_counter); +extern void GetCurrentTotalTableCounter(PgStat_TableCounts* total_table_counter); + +typedef struct XLogStatCollect { + double entryScanTime; + double IOTime; + double memsetTime; + double entryUpdateTime; + uint64 writeBytes; + uint64 scanEntryCount; + uint64 writeSomethingCount; + uint64 flushWaitCount; + double xlogFlushWaitTime; + uint32 walAuxWakeNum; + XLogRecPtr writeRqstPtr; + XLogRecPtr minCopiedPtr; + double IONotificationTime; + double sendBufferTime; + double memsetNotificationTime; + uint32 remoteFlushWaitCount; +} XLogStatCollect; + +extern THR_LOCAL XLogStatCollect *g_xlog_stat_shared; + +extern void XLogStatShmemInit(void); +extern Size XLogStatShmemSize(void); +extern bool CheckUserExist(Oid userId, bool removeCount); +extern PgBackendStatusNode* gs_stat_read_current_status(uint32* maxCalls); +extern void pgstat_setup_memcxt(void); +extern PgBackendStatus* gs_stat_fetch_stat_beentry(int32 beid); +extern void pgstat_send(void* msg, int len); + +typedef struct PgStat_NgMemSize { + int* ngmemsize; + char** ngname; + uint32 cnti; + uint32 cntj; + uint32 allcnt; +} PgStat_NgMemSize; + +typedef enum NetInfoType { + NET_SEND_TIMES, + NET_SEND_N_CALLS, + NET_SEND_SIZE, + + NET_RECV_TIMES, + NET_RECV_N_CALLS, + NET_RECV_SIZE, + + NET_STREAM_SEND_TIMES, + NET_STREAM_SEND_N_CALLS, + NET_STREAM_SEND_SIZE, + + NET_STREAM_RECV_TIMES, + NET_STREAM_RECV_N_CALLS, + NET_STREAM_RECV_SIZE, + + TOTAL_NET_INFO_TYPES +} NetInfoType; + +#define END_NET_SEND_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_SEND_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_SEND_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_STREAM_SEND_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_SEND_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_RECV_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_RECV_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_RECV_SIZE] += str_len; \ + } \ + } while (0) + +#define END_NET_STREAM_RECV_INFO(str_len) \ + do { \ + if (str_len > 0 && t_thrd.shemem_ptr_cxt.mySessionTimeEntry) { \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_TIMES] += GetCurrentTimestamp() - startTime; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_N_CALLS]++; \ + u_sess->stat_cxt.localNetInfo[NET_STREAM_RECV_SIZE] += str_len; \ + } \ + } while (0) + +#endif /* PGSTAT_H */ diff -uprN postgresql-hll-2.14_old/include/pgtime.h postgresql-hll-2.14/include/pgtime.h --- postgresql-hll-2.14_old/include/pgtime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgtime.h 2020-12-12 17:06:43.355349432 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * pgtime.h + * PostgreSQL internal timezone library + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/pgtime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PGTIME_H +#define _PGTIME_H + +#include "gs_threadlocal.h" + +/* + * The API of this library is generally similar to the corresponding + * C library functions, except that we use pg_time_t which (we hope) is + * 64 bits wide, and which is most definitely signed not unsigned. + */ + +typedef int64 pg_time_t; + +struct pg_tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; /* origin 0, not 1 */ + int tm_year; /* relative to 1900 */ + int tm_wday; + int tm_yday; + int tm_isdst; + long int tm_gmtoff; + const char* tm_zone; +}; + +typedef struct pg_tz pg_tz; +typedef struct pg_tzenum pg_tzenum; + +/* Maximum length of a timezone name (not including trailing null) */ +#define TZ_STRLEN_MAX 255 + +/* these functions are in localtime.c */ + +extern struct pg_tm* pg_localtime(const pg_time_t* timep, const pg_tz* tz); +extern struct pg_tm* pg_gmtime(const pg_time_t* timep); +extern int pg_next_dst_boundary(const pg_time_t* timep, long int* before_gmtoff, int* before_isdst, pg_time_t* boundary, + long int* after_gmtoff, int* after_isdst, const pg_tz* tz); +extern size_t pg_strftime(char* s, size_t max, const char* format, const struct pg_tm* tm); + +extern bool pg_get_timezone_offset(const pg_tz* tz, long int* gmtoff); +extern const char* pg_get_timezone_name(pg_tz* tz); +extern const char* pg_get_abbrevs_name(pg_time_t* timep, pg_tz* tz); + +extern bool pg_tz_acceptable(pg_tz* tz); + +/* these functions and variables are in pgtz.c */ + +extern THR_LOCAL pg_tz* session_timezone; +extern THR_LOCAL pg_tz* log_timezone; + +extern void pg_timezone_initialize(void); +extern pg_tz* pg_tzset(const char* tzname); + +extern pg_tzenum* pg_tzenumerate_start(void); +extern pg_tz* pg_tzenumerate_next(pg_tzenum* dir); +extern void pg_tzenumerate_end(pg_tzenum* dir); + +#endif /* _PGTIME_H */ diff -uprN postgresql-hll-2.14_old/include/pg_trace.h postgresql-hll-2.14/include/pg_trace.h --- postgresql-hll-2.14_old/include/pg_trace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pg_trace.h 2020-12-12 17:06:43.355349432 +0800 @@ -0,0 +1,17 @@ +/* ---------- + * pg_trace.h + * + * Definitions for the PostgreSQL tracing framework + * + * Copyright (c) 2006-2012, PostgreSQL Global Development Group + * + * src/include/pg_trace.h + * ---------- + */ + +#ifndef PG_TRACE_H +#define PG_TRACE_H + +#include "utils/probes.h" /* pgrminclude ignore */ + +#endif /* PG_TRACE_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/barrier.h postgresql-hll-2.14/include/pgxc/barrier.h --- postgresql-hll-2.14_old/include/pgxc/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/barrier.h 2020-12-12 17:06:43.355349432 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * + * Definitions for the PITR barrier handling + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/barrier.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef XC_BARRIER_H +#define XC_BARRIER_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +#define CREATE_BARRIER_PREPARE 'P' +#define CREATE_BARRIER_EXECUTE 'X' +#define CREATE_BARRIER_END 'E' + +#define CREATE_BARRIER_PREPARE_DONE 'p' +#define CREATE_BARRIER_EXECUTE_DONE 'x' + +#define BARRIER_LSN_FILE "barrier_lsn" +#define BARRIER_LSN_FILE_LENGTH 17 + +#define XLOG_BARRIER_CREATE 0x00 + +extern void ProcessCreateBarrierPrepare(const char* id); +extern void ProcessCreateBarrierEnd(const char* id); +extern void ProcessCreateBarrierExecute(const char* id); + +extern void RequestBarrier(const char* id, char* completionTag); +extern void barrier_redo(XLogReaderState* record); +extern void barrier_desc(StringInfo buf, XLogReaderState* record); +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/bucketmap.h postgresql-hll-2.14/include/pgxc/bucketmap.h --- postgresql-hll-2.14_old/include/pgxc/bucketmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/bucketmap.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,35 @@ +#ifndef BUCKETMAP_H +#define BUCKETMAP_H + +#include "c.h" + +#include "access/htup.h" +#include "nodes/parsenodes.h" +#include "storage/itemptr.h" +#include "utils/relcache.h" + +/* + * The element data structure of bucketmap cache, where store the bucketmap that + * palloc-ed form t_thrd.top_mem_cxt, it is created on its first being used + */ +typedef struct BucketMapCache { + /* Search key of bucketmap cache */ + Oid groupoid; + ItemPointerData ctid; + char* groupname; + + /* bucketmap content, palloc()-ed form top memory context */ + uint2* bucketmap; +} NodeGroupBucketMap; + +#define BUCKET_MAP_SIZE 32 +#define BUCKETMAP_MODE_DEFAULT 0 +#define BUCKETMAP_MODE_REMAP 1 + +extern void GenerateConsistentHashBucketmap(CreateGroupStmt* stmt, oidvector* nodes_array, + Relation pgxc_group_rel, HeapTuple tuple, uint2* bucket_ptr, int bucketmap_mode); +extern void BucketMapCacheRemoveEntry(Oid groupoid); +extern char* GetBucketString(uint2* bucket_ptr); +extern void PgxcCopyBucketsFromNew(const char* group_name, const char* src_group_name); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/copyops.h postgresql-hll-2.14/include/pgxc/copyops.h --- postgresql-hll-2.14_old/include/pgxc/copyops.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/copyops.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,27 @@ +/* -------------------------------------------------------------------------- + * + * copyops.h + * Routines for manipulation of remote COPY data + * + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/copyops.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef COPYOPS_H +#define COPYOPS_H + +#include "access/tupdesc.h" + +/* Type of data delimiter used for data redistribution using remote COPY */ +#define COPYOPS_DELIMITER '\t' + +extern char** CopyOps_RawDataToArrayField(TupleDesc tupdesc, char* message, int len); +extern char* CopyOps_BuildOneRowTo(TupleDesc tupdesc, Datum* values, const bool* nulls, int* len); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/csnminsync.h postgresql-hll-2.14/include/pgxc/csnminsync.h --- postgresql-hll-2.14_old/include/pgxc/csnminsync.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/csnminsync.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------- + * + * csnminsync.h + * Synchronize the global min csn between all nodes, head file + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/pgxc/csnminsync.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef CSNMINSYNC_H +#define CSNMINSYNC_H + +#define DEFAULT_CLEANUP_TIME 50000 + +extern void csnminsync_main(void); +extern void csnminsync_thread_shutdown(void); + +#endif /* CSNMINSYNC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/pgxc/execRemote.h postgresql-hll-2.14/include/pgxc/execRemote.h --- postgresql-hll-2.14_old/include/pgxc/execRemote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/execRemote.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,269 @@ +/* ------------------------------------------------------------------------- + * + * execRemote.h + * + * Functions to execute commands on multiple Datanodes + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/execRemote.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef EXECREMOTE_H +#define EXECREMOTE_H +#include "locator.h" +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "access/tupdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "nodes/pg_list.h" +#include "optimizer/pgxcplan.h" +#include "pgxc/remoteCombiner.h" +#include "tcop/dest.h" +#include "tcop/pquery.h" +#include "tcop/utility.h" +#include "utils/lsyscache.h" +#include "utils/snapshot.h" +#include "utils/rowstore.h" + +#define LPROXY_CONTINUE 0 +#define LPROXY_FINISH 1 +#define LPROXY_ERROR 2 + +/* Outputs of handle_response() */ +#define RESPONSE_EOF EOF +#define RESPONSE_COMPLETE 0 +#define RESPONSE_SUSPENDED 1 +#define RESPONSE_TUPDESC 2 +#define RESPONSE_DATAROW 3 +#define RESPONSE_COPY 4 +#define RESPONSE_BARRIER_OK 5 +#define RESPONSE_PLANID_OK 6 +#define RESPONSE_ANALYZE_ROWCNT 7 + +#define REMOTE_CHECKMSG_LEN 8 /* it equals to the count of bytes added in AddCheckMessage when is_stream is false */ +#define STREAM_CHECKMSG_LEN 20 /* it equals to the count of bytes added in AddCheckMessage when is_stream is true */ + +/* with-recursive added messages */ +#define RESPONSE_RECURSIVE_SYNC_R 98 +#define RESPONSE_RECURSIVE_SYNC_F 99 + +#ifdef WIN32 +#define SOCK_ERRNO (WSAGetLastError()) +#define SOCK_STRERROR winsock_strerror +#define SOCK_ERRNO_SET(e) WSASetLastError(e) +#else +#define SOCK_ERRNO errno +#define SOCK_STRERROR pqStrerror +#define SOCK_ERRNO_SET(e) (errno = (e)) +#endif + +#define ERROR_CHECK_TIMEOUT 3 /* time out for checking some normal communication error(s) */ + +/* Add Skewness alarm retry count in case something fails. default 2*/ +#define ALARM_RETRY_COUNT 2 + +/* Combines results of INSERT statements using multiple values */ +typedef struct CombineTag { + CmdType cmdType; /* DML command type */ + char data[COMPLETION_TAG_BUFSIZE]; /* execution result combination data */ +} CombineTag; + +typedef void (*xact_callback)(bool isCommit, const void* args); +typedef void (*strategy_func)(ParallelFunctionState*); + +typedef enum RemoteXactNodeStatus { + RXACT_NODE_NONE, /* Initial state */ + RXACT_NODE_PREPARE_SENT, /* PREPARE request sent */ + RXACT_NODE_PREPARE_FAILED, /* PREPARE failed on the node */ + RXACT_NODE_PREPARED, /* PREPARED successfully on the node */ + RXACT_NODE_COMMIT_SENT, /* COMMIT sent successfully */ + RXACT_NODE_COMMIT_FAILED, /* failed to COMMIT on the node */ + RXACT_NODE_COMMITTED, /* COMMITTed successfully on the node */ + RXACT_NODE_ABORT_SENT, /* ABORT sent successfully */ + RXACT_NODE_ABORT_FAILED, /* failed to ABORT on the node */ + RXACT_NODE_ABORTED /* ABORTed successfully on the node */ +} RemoteXactNodeStatus; + +typedef enum RemoteXactStatus { + RXACT_NONE, /* Initial state */ + RXACT_PREPARE_FAILED, /* PREPARE failed */ + RXACT_PREPARED, /* PREPARED succeeded on all nodes */ + RXACT_COMMIT_FAILED, /* COMMIT failed on all the nodes */ + RXACT_PART_COMMITTED, /* COMMIT failed on some and succeeded on other nodes */ + RXACT_COMMITTED, /* COMMIT succeeded on all the nodes */ + RXACT_ABORT_FAILED, /* ABORT failed on all the nodes */ + RXACT_PART_ABORTED, /* ABORT failed on some and succeeded on other nodes */ + RXACT_ABORTED /* ABORT succeeded on all the nodes */ +} RemoteXactStatus; + +typedef struct RemoteXactState { + /* Current status of the remote 2PC */ + RemoteXactStatus status; + + /* + * Information about all the nodes involved in the transaction. We track + * the number of writers and readers. The first numWriteRemoteNodes entries + * in the remoteNodeHandles and remoteNodeStatus correspond to the writer + * connections and rest correspond to the reader connections. + */ + int numWriteRemoteNodes; + int numReadRemoteNodes; + int maxRemoteNodes; + PGXCNodeHandle** remoteNodeHandles; + RemoteXactNodeStatus* remoteNodeStatus; + + bool preparedLocalNode; + bool need_primary_dn_commit; + char prepareGID[256]; /* GID used for internal 2PC */ +} RemoteXactState; + +#ifdef PGXC +typedef struct abort_callback_type { + xact_callback function; + void* fparams; +} abort_callback_type; +#endif + +static inline char* GetIndexNameForStat(Oid indid, char* relname) +{ + char* indname = get_rel_name(indid); + if (indname == NULL) { + ereport(LOG, + (errmsg("Analyze can not get index name by index id %u on table %s and will skip this index.", + indid, relname))); + } + return indname; +} + +/* Copy command just involves Datanodes */ +extern PGXCNodeHandle** DataNodeCopyBegin(const char* query, List* nodelist, Snapshot snapshot); +extern int DataNodeCopyIn(const char* data_row, int len, const char* eol, ExecNodes* exec_nodes, + PGXCNodeHandle** copy_connections, bool is_binary = false); +extern uint64 DataNodeCopyOut(ExecNodes* exec_nodes, PGXCNodeHandle** copy_connections, TupleDesc tupleDesc, + FILE* copy_file, Tuplestorestate* store, RemoteCopyType remoteCopyType); +extern void DataNodeCopyFinish(PGXCNodeHandle** copy_connections, int n_copy_connections, int primary_dn_index, + CombineType combine_type, Relation rel); +extern bool DataNodeCopyEnd(PGXCNodeHandle* handle, bool is_error); +extern int DataNodeCopyInBinaryForAll(const char* msg_buf, int len, PGXCNodeHandle** copy_connections); + +extern int ExecCountSlotsRemoteQuery(RemoteQuery* node); +extern RemoteQueryState* ExecInitRemoteQuery(RemoteQuery* node, EState* estate, int eflags, bool row_plan = true); +extern TupleTableSlot* ExecRemoteQuery(RemoteQueryState* step); +extern void ExecEndRemoteQuery(RemoteQueryState* step, bool pre_end = false); +extern void FreeParallelFunctionState(ParallelFunctionState* state); +extern void StrategyFuncSum(ParallelFunctionState* state); +extern ParallelFunctionState* RemoteFunctionResultHandler(char* sql_statement, ExecNodes* exec_nodes, + strategy_func function, bool read_only = true, RemoteQueryExecType exec_type = EXEC_ON_DATANODES, + bool non_check_count = false, bool need_tran_block = false, bool need_transform_anyarray = false, + bool active_nodes_only = false); +extern void ExecRemoteUtility(RemoteQuery* node); + +extern void ExecRemoteUtility_ParallelDDLMode(RemoteQuery* node, const char* FirstExecNode); +extern RemoteQueryState* CreateResponseCombinerForBarrier(int nodeCount, CombineType combineType); +extern void CloseCombinerForBarrier(RemoteQueryState* combiner); + +extern HeapTuple* ExecRemoteUtilityWithResults( + VacuumStmt* stmt, RemoteQuery* node, ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); + +extern HeapTuple* RecvRemoteSampleMessage( + VacuumStmt* stmt, RemoteQuery* node, ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); +extern int handle_response(PGXCNodeHandle* conn, RemoteQueryState* combiner, bool isdummy = false); +extern bool is_data_node_ready(PGXCNodeHandle* conn); +extern void HandleCmdComplete(CmdType commandType, CombineTag* combine, const char* msg_body, size_t len); +extern bool FetchTuple( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate = NULL); +extern bool FetchTupleSimple(RemoteQueryState* combiner, TupleTableSlot* slot); +template +extern bool FetchTupleByMultiChannel( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate = NULL); +extern bool FetchBatch(RemoteQueryState* combiner, VectorBatch* batch); + +extern void BufferConnection(PGXCNodeHandle* conn, bool cachedata = true); + +extern void ExecRemoteQueryReScan(RemoteQueryState* node, ExprContext* exprCtxt); + +extern void SetDataRowForExtParams(ParamListInfo params, RemoteQueryState* rq_state); + +extern void ExecCloseRemoteStatement(const char* stmt_name, List* nodelist); + +/* Flags related to temporary objects included in query */ +extern void ExecSetTempObjectIncluded(void); +extern bool ExecIsTempObjectIncluded(void); +extern TupleTableSlot* ExecProcNodeDMLInXC(EState* estate, TupleTableSlot* sourceDataSlot, TupleTableSlot* newDataSlot); + +extern void pgxc_all_success_nodes(ExecNodes** d_nodes, ExecNodes** c_nodes, char** failednodes_msg); +extern int PackConnections(RemoteQueryState* node); +extern void AtEOXact_DBCleanup(bool isCommit); + +extern void set_dbcleanup_callback(xact_callback function, const void* paraminfo, int paraminfo_size); + +extern void do_query(RemoteQueryState* node, bool vectorized = false); +extern bool do_query_for_planrouter(RemoteQueryState* node, bool vectorized = false); +extern void do_query_for_scangather(RemoteQueryState* node, bool vectorized = false); +extern void do_query_for_first_tuple(RemoteQueryState* node, bool vectorized, int regular_conn_count, + PGXCNodeHandle** connections, PGXCNodeHandle* primaryconnection, List* dummy_connections); + +extern void free_RemoteXactState(void); +extern char* repairObjectName(const char* relname); +extern char* repairTempNamespaceName(char* schemaname); + +extern void pgxc_node_report_error(RemoteQueryState* combiner, int elevel = 0); +extern void setSocketError(const char*, const char*); +extern char* getSocketError(int* errcode); +extern int getStreamSocketError(const char* str); + +extern int FetchStatistics4WLM(const char* sql, void* info, Size size, strategy_func func); +extern void FetchGlobalStatistics(VacuumStmt* stmt, Oid relid, RangeVar* parentRel, bool isReplication = false); + +extern bool IsInheritor(Oid relid); +extern Tuplesortstate* tuplesort_begin_merge(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, void* combiner, int workMem); + +extern void pgxc_node_remote_savepoint( + const char* cmdString, RemoteQueryExecType exec_type, bool bNeedXid, bool bNeedBegin, + GlobalTransactionId transactionId = InvalidTransactionId); +extern bool pgxc_start_command_on_connection(PGXCNodeHandle* connection, RemoteQueryState* remotestate, + Snapshot snapshot, const char* compressPlan = NULL, int cLen = 0); +extern PGXCNodeAllHandles* connect_compute_pool(int srvtype); +extern char* generate_begin_command(void); +extern PGXCNodeAllHandles* get_exec_connections( + RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); +extern void send_local_csn_min_to_ccn(); +extern void csnminsync_get_global_csn_min(int conn_count, PGXCNodeHandle** connections); +extern void SendPGXCNodeCommitCsn(uint64 commit_csn); +extern void NotifyDNSetCSN2CommitInProgress(); +extern void AssembleDataRow(StreamState* node); +extern bool isInLargeUpgrade(); +extern uint64 get_datasize(Plan* plan, int srvtype, int* filenum); +extern void report_table_skewness_alarm(AlarmType alarmType, const char* tableName); +extern bool InternalDoQueryForPlanrouter(RemoteQueryState* node, bool vectorized); +extern List* TryGetNeededDNNum(uint64 dnneeded); +extern List* GetDnlistForHdfs(int fnum); +extern void MakeNewSpiltmap(Plan* plan, SplitMap* map); +extern List* ReassignSplitmap(Plan* plan, int dn_num); +extern int ComputeNodeBegin(int conn_count, PGXCNodeHandle** connections, GlobalTransactionId gxid); +extern void sendQuery(const char* sql, const PGXCNodeAllHandles* pgxc_handles, + int conn_count, bool isCoordinator, + RemoteQueryState* remotestate, const Snapshot snapshot); + +StringInfo* SendExplainToDNs(ExplainState*, RemoteQuery*, int*, const char*); +bool CheckPrepared(RemoteQuery* rq, Oid nodeoid); +void FindExecNodesInPBE(RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); +#endif + +#ifdef ENABLE_UT +#include "workload/cpwlm.h" +extern THR_LOCAL List* XactWriteNodes; +extern THR_LOCAL List* XactReadNodes; +extern PGXCNodeAllHandles* connect_compute_pool_for_HDFS(); +extern PGXCNodeAllHandles* make_cp_conn(ComputePoolConfig** configs, int cnum, int srvtype, const char* dbname); +extern List* get_dnlist_for_hdfs(int fnum); +extern void ReloadTransactionNodes(void); +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/globalStatistic.h postgresql-hll-2.14/include/pgxc/globalStatistic.h --- postgresql-hll-2.14_old/include/pgxc/globalStatistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/globalStatistic.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,18 @@ + +#ifndef GLOBAL_STAISTTIC_H +#define GLOBAL_STAISTTIC_H + +typedef enum StatisticKind { + StatisticNone, + StatisticPageAndTuple, + StatisticHistogram, + StatisticMultiHistogram, + StatisticPartitionPageAndTuple +} StatisticKind; + +extern char* construct_fetch_statistics_query(const char* schemaname, const char* relname, List* va_cols, + StatisticKind kind, VacuumStmt* stmt, Oid relid, RangeVar* parentRel); +extern void FetchGlobalStatisticsFromCN(int cn_conn_count, PGXCNodeHandle** pgxc_connections, + RemoteQueryState* remotestate, StatisticKind kind, VacuumStmt* stmt, Oid relid, PGFDWTableAnalyze* info); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/groupmgr.h postgresql-hll-2.14/include/pgxc/groupmgr.h --- postgresql-hll-2.14_old/include/pgxc/groupmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/groupmgr.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * groupmgr.h + * Routines for PGXC node group management + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/groupmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GROUPMGR_H +#define GROUPMGR_H + +#include "c.h" +#include "nodes/parsenodes.h" + +typedef struct nodeinfo { + Oid node_id; + uint2 old_node_index; + uint2 new_node_index; + int old_buckets_num; +#ifdef USE_ASSERT_CHECKING + int new_buckets_num; +#endif + bool deleted; +} nodeinfo; + +/* installation mode for storage node group */ +#define INSTALLATION_MODE "installation" + +#define BUCKETMAPLEN_CONFIG_NAME "buckets_len" +#define MIN_BUCKETMAPLEN 32 +#define MAX_BUCKETMAPLEN 16384 +#define CHAR_BUF_SIZE 512 + +extern void PgxcGroupCreate(CreateGroupStmt* stmt); +extern void PgxcGroupAlter(AlterGroupStmt* stmt); +extern void PgxcGroupRemove(DropGroupStmt* stmt); +extern char* PgxcGroupGetInstallationGroup(); +extern char* PgxcGroupGetInRedistributionGroup(); +extern char* PgxcGroupGetCurrentLogicCluster(); +extern Oid PgxcGroupGetRedistDestGroupOid(); +extern char* PgxcGroupGetStmtExecGroupInRedis(); +extern bool CanPgxcGroupRemove(Oid group_oid, bool ignore_pmk = false); +extern int GetTableCountByDatabase(const char* database_name, char* query); +extern bool GetExecnodeIsInstallationGroup(Oid groupoid); +extern void InitNodeGroupStatus(void); +extern void CleanNodeGroupStatus(void); +extern List* GetNodeGroupOidCompute(Oid role_id); +extern uint2* GetBucketMapByGroupName(const char* groupname); +extern char* DeduceGroupByNodeList(Oid* nodeoids, int numnodes); +extern void PgxcGroupAddNode(Oid group_oid, Oid nodeid); +extern void PgxcGroupRemoveNode(Oid group_oid, Oid nodeid); +extern bool IsNodeInLogicCluster(Oid* oid_array, int count, Oid excluded); +extern bool IsLogicClusterRedistributed(const char* group_name); +extern char* PgxcGroupGetFirstLogicCluster(); +extern bool PgxcGroup_Resizing(); +extern oidvector* GetGroupMemberRef(HeapTuple tup, bool* need_free); +extern char GetGroupKind(HeapTuple tup); + +/* Routines for bucketmap cache */ +extern uint2* BucketMapCacheGetBucketmap(Oid groupoid); +extern uint2* BucketMapCacheGetBucketmap(const char* groupname); +extern void BucketMapCacheDestroy(void); + +extern int GsGlobalConfigGetBucketMapLen(void); +extern void CheckBucketMapLenValid(void); + +#endif /* GROUPMGR_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/groupnodes.h postgresql-hll-2.14/include/pgxc/groupnodes.h --- postgresql-hll-2.14_old/include/pgxc/groupnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/groupnodes.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,18 @@ +#ifndef GROUP_NODES_H +#define GROUP_NODES_H + +#include "c.h" +#include "pgxc/locator.h" + +extern oidvector* exclude_nodes(oidvector* nodes, oidvector* excluded); +extern bool oidvector_eq(oidvector* oid1, oidvector* oid2); +extern oidvector* oidvector_add(oidvector* nodes, oidvector* added); +extern oidvector* oidvector_remove(oidvector* nodes, oidvector* removed); +extern ExecNodes* create_exec_nodes(oidvector* gmember); +extern void delete_exec_nodes(ExecNodes* exec_nodes); +extern oidvector* get_group_member(Oid group_oid); +extern void PgxcOpenGroupRelation(Relation* pgxc_group_rel); +extern void PgxcChangeGroupMember(Oid group_oid, oidvector* gmember); +extern bool PgxcGroupResizing(); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/groupredis.h postgresql-hll-2.14/include/pgxc/groupredis.h --- postgresql-hll-2.14_old/include/pgxc/groupredis.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/groupredis.h 2020-12-12 17:06:43.356349445 +0800 @@ -0,0 +1,13 @@ +#ifndef GROUP_REDIS_H +#define GROUP_REDIS_H + +#include "c.h" + +extern void PgxcChangeRedistribution(Oid group_oid, char in_redistribution); +extern oidvector* PgxcGetRedisNodes(Relation rel, char redist_kind); +extern void PgxcUpdateRedistSrcGroup(Relation rel, oidvector* gmember, + text* bucket_str, char* group_name); +extern void PgxcGroupResize(const char* src_group_name, const char* dest_group_name); +extern void PgxcGroupResizeComplete(); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/locator.h postgresql-hll-2.14/include/pgxc/locator.h --- postgresql-hll-2.14_old/include/pgxc/locator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/locator.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,248 @@ +/* ------------------------------------------------------------------------- + * + * locator.h + * Externally declared locator functions + * + * + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/locator.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCATOR_H +#define LOCATOR_H + +#define LOCATOR_TYPE_REPLICATED 'R' +#define LOCATOR_TYPE_HASH 'H' +#define LOCATOR_TYPE_RANGE 'G' +#define LOCATOR_TYPE_RROBIN 'N' +#define LOCATOR_TYPE_CUSTOM 'C' +#define LOCATOR_TYPE_MODULO 'M' +#define LOCATOR_TYPE_LIST 'L' +#define LOCATOR_TYPE_NONE 'O' +#define LOCATOR_TYPE_DISTRIBUTED \ + 'D' /* for distributed table without specific \ + * scheme, e.g. result of JOIN of \ + * replicated and distributed table */ +/* We may consider the following type as future use */ +/* Maximum number of preferred Datanodes that can be defined in cluster */ +#define MAX_PREFERRED_NODES 64 + +#define HASH_SIZE 4096 +#define HASH_MASK 0x00000FFF; + +#define IsLocatorNone(x) ((x) == LOCATOR_TYPE_NONE) +#define IsLocatorReplicated(x) ((x) == LOCATOR_TYPE_REPLICATED) +#define IsLocatorColumnDistributed(x) \ + ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_RROBIN || \ + (x) == LOCATOR_TYPE_MODULO || (x) == LOCATOR_TYPE_DISTRIBUTED || \ + (x) == LOCATOR_TYPE_LIST || (x) == LOCATOR_TYPE_RANGE) +#define IsLocatorDistributedByValue(x) ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_MODULO || \ + (x) == LOCATOR_TYPE_RANGE || (x) == LOCATOR_TYPE_LIST) + +#define IsLocatorDistributedByHash(x) ((x) == LOCATOR_TYPE_HASH || (x) == LOCATOR_TYPE_RROBIN) +#define IsLocatorDistributedBySlice(x) ((x) == LOCATOR_TYPE_RANGE || (x) == LOCATOR_TYPE_LIST) + +#include "nodes/primnodes.h" +#include "utils/relcache.h" +#include "utils/partitionmap.h" +#include "nodes/nodes.h" +#include "nodes/params.h" + +/* + * How relation is accessed in the query + */ +typedef enum { + RELATION_ACCESS_READ, /* SELECT */ + RELATION_ACCESS_READ_FOR_UPDATE, /* SELECT FOR UPDATE */ + RELATION_ACCESS_UPDATE, /* UPDATE OR DELETE */ + RELATION_ACCESS_INSERT /* INSERT */ +} RelationAccessType; + +/* @hdfs + * Struct stores the information of each file for hdfs foreign scan schedule. + */ +typedef struct SplitInfo { + NodeTag type; + char* filePath; /* Absolute path of the file or folder. */ + char* fileName; /* The name of the file or folder. */ + List* partContentList; /* the partition column value list. */ + int64 ObjectSize; + char* eTag; + int prefixSlashNum; +} SplitInfo; + +/* @hdfs + * Struct stores the mapping of datanode id and list of split assigned to it. + */ +typedef struct SplitMap { + NodeTag type; + int nodeId; /* DataNode Id */ + char locatorType; /* Location type of rel */ + int64 totalSize; /* Total size of objects */ + int fileNums; /* the number of files */ + char* downDiskFilePath; /* the absolute path of down disk file, store in memory if it is null */ + List* lengths; /* the length for each part */ + List* splits; /* Splits to read */ +} SplitMap; + +/*@dfs + * Struct stores the items which will be sent from CN to DN for hdfs foreign scan. + */ +typedef struct DfsPrivateItem { + NodeTag type; + List* columnList; /* The list of all the target columns and the + * restriction columns of the relation. + */ + List* targetList; /* The list of all the target columns. */ + List* restrictColList; /* The list of columns in the restriction. */ + List* partList; /* The list of all the partition columns. */ + /* + * The list of the primitive restrictions, but inputcollid of the OpExpr is + * C_COLLATION_OID. we do not care colation in coarse filter. + */ + List* opExpressionList; + List* dnTask; /* The task list assigned to dn. */ + List* hdfsQual; /* The list of restrictions to push down. */ + int colNum; /* The number of the columns. */ + double* selectivity; /* The array of selectivities for each column. */ +} DfsPrivateItem; + +typedef struct { + Oid relid; /* OID of relation */ + char locatorType; /* locator type, see above */ + List* partAttrNum; /* Distribution column attribute */ + List* nodeList; /* Node indices where data is located */ + ListCell* roundRobinNode; /* Index of the next node to use */ + NameData gname; /* Group name */ + + /* + * Caution!!! don't invoke pfree() + * + * Because we introduce the bucketmap cache where a gaussdb persistent global memory + * area is allocated to hold the bucketmap content, just do pointer-assignment. + */ + uint2* buckets_ptr; /* pointer to local bucket-node mapping */ +} RelationLocInfo; + +#define IsRelationReplicated(rel_loc) IsLocatorReplicated((rel_loc)->locatorType) +#define IsRelationColumnDistributed(rel_loc) IsLocatorColumnDistributed((rel_loc)->locatorType) +#define IsRelationDistributedByValue(rel_loc) IsLocatorDistributedByValue((rel_loc)->locatorType) +#define InvalidateBuckets(rel_loc) ((rel_loc)->buckets_ptr = NULL) + +/* + * Distribution information related with node group + */ +typedef struct Distribution { + Oid group_oid; + Bitmapset* bms_data_nodeids; +} Distribution; + +/* + * list/range distributed table's slice boundaries, + * used for dispatching row/batch in datanode StreamProducer + */ +typedef struct SliceBoundary { + NodeTag type; + int nodeIdx; + int len; + Const *boundary[RANGE_PARTKEYMAXNUM]; +} SliceBoundary; + +typedef struct ExecBoundary { + NodeTag type; + char locatorType; + int32 count; + SliceBoundary **eles; +} ExecBoundary; + +/* + * Nodes to execute on + * primarynodelist is for replicated table writes, where to execute first. + * If it succeeds, only then should it be executed on nodelist. + * primarynodelist should be set to NULL if not doing replicated write operations + * Note on dist_vars: + * dist_vars is a list of Var nodes indicating the columns by which the + * relations (result of query) are distributed. The result of equi-joins between + * distributed relations, can be considered to be distributed by distribution + * columns of either of relation. Hence a list. dist_vars is ignored in case of + * distribution types other than HASH or MODULO. + */ +typedef struct { + NodeTag type; + List* primarynodelist; /* Primary node list indexes */ + List* nodeList; /* Node list indexes */ + Distribution distribution; + char baselocatortype; /* Locator type, see above */ + List* en_expr; /* Expression to evaluate at execution time + * if planner can not determine execution + * nodes */ + Oid en_relid; /* Relation to determine execution nodes */ + + Oid rangelistOid; /* list/range table oid that slice map references */ + bool need_range_prune; /* flag for list/range dynamic slice pruning */ + Index en_varno; /* relation varno */ + ExecBoundary* boundaries; /* slice boundaries that used for list/range redistribution in DML */ + + RelationAccessType accesstype; /* Access type to determine execution + * nodes */ + List* en_dist_vars; /* See above for details */ + int bucketmapIdx; /* the index of bucketmap + * (1) the value -1 means that the bucketmap is generated + * as default way "hashvalue % member_count + * (2) the others values means the index of + * the struct PlannedStmt -> bucketMap */ + bool nodelist_is_nil; /* true if nodeList is NIL when initialization */ + List* original_nodeList; /* used to keep original nodeList when explain analyze pbe */ + List* dynamic_en_expr; /* dynamic judge en_expr that should be judged later */ + /* runtime pbe purning for hashbucket, we keep another copy for safe */ + int bucketid; /* bucket id where the data should be in */ + List *bucketexpr; /* exprs which can be used for bucket purning */ + Oid bucketrelid; /* relid of the purning relation */ + List* hotkeys; /* List of HotkeyInfo */ +} ExecNodes; + +#define INVALID_BUCKET_ID -1 + +#define IsExecNodesReplicated(en) IsLocatorReplicated((en)->baselocatortype) +#define IsExecNodesColumnDistributed(en) IsLocatorColumnDistributed((en)->baselocatortype) +#define IsExecNodesDistributedByValue(en) IsLocatorDistributedByValue((en)->baselocatortype) + +/* Function for RelationLocInfo building and management */ +extern void RelationBuildLocator(Relation rel); +extern RelationLocInfo* GetRelationLocInfo(Oid relid); +extern RelationLocInfo* GetRelationLocInfoDN(Oid relid); +extern RelationLocInfo* CopyRelationLocInfo(RelationLocInfo* srcInfo); +extern void FreeRelationLocInfo(RelationLocInfo* relationLocInfo); +extern List* GetRelationDistribColumn(RelationLocInfo* locInfo); +extern char GetLocatorType(Oid relid); +extern List* GetPreferredReplicationNode(List* relNodes); +extern bool IsTableDistOnPrimary(RelationLocInfo* locInfo); +extern bool IsLocatorInfoEqual(RelationLocInfo* locInfo1, RelationLocInfo* locInfo2); +extern bool IsSliceInfoEqualByOid(Oid tabOid1, Oid tabOid2); +extern int GetRoundRobinNode(Oid relid); +extern bool IsTypeDistributable(Oid colType); +extern bool IsTypeDistributableForSlice(Oid colType); +extern bool IsDistribColumn(Oid relid, AttrNumber attNum); + +extern ExecNodes* GetRelationNodes(RelationLocInfo* rel_loc_info, Datum* values, const bool* nulls, Oid* attr, + List* idx_dist_by_col, RelationAccessType accessType, bool needDistribution = true, bool use_bucketmap = true); +extern ExecNodes* GetRelationNodesByQuals(void* query, Oid reloid, Index varno, Node* quals, + RelationAccessType relaccess, ParamListInfo boundParams, bool useDynamicReduce = false); +/* Global locator data */ +extern Distribution* NewDistribution(); +extern void DestroyDistribution(Distribution* distribution); +extern void FreeExecNodes(ExecNodes** exec_nodes); +extern List* GetAllDataNodes(void); +extern List* GetAllCoordNodes(void); +List* GetNodeGroupNodeList(Oid* members, int nmembers); + +extern int compute_modulo(unsigned int numerator, unsigned int denominator); +extern int get_node_from_modulo(int modulo, List* nodeList); +extern int GetMinDnNum(); +extern Expr* pgxc_check_distcol_opexpr(Index varno, AttrNumber attrNum, OpExpr* opexpr); +extern void RebuildSliceMap(PartitionMap* oldMap, PartitionMap* newMap); +extern void PruningDatanode(ExecNodes* execNodes, ParamListInfo boundParams); + +#endif /* LOCATOR_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/nodemgr.h postgresql-hll-2.14/include/pgxc/nodemgr.h --- postgresql-hll-2.14_old/include/pgxc/nodemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/nodemgr.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------------------- + * + * nodemgr.h + * Routines for node management + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/nodemgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NODEMGR_H +#define NODEMGR_H + +#include "nodes/parsenodes.h" + +#define PGXC_NODENAME_LENGTH 64 + +/* Node definition */ +typedef struct NodeDefinition { + Oid nodeoid; + int nodeid; + NameData nodename; + NameData nodehost; + int nodeport; + int nodectlport; + int nodesctpport; + NameData nodehost1; + int nodeport1; + int nodectlport1; + int nodesctpport1; + bool hostisprimary; + bool nodeisprimary; + bool nodeispreferred; + bool nodeis_central; + bool nodeis_active; + Oid shard_oid; +} NodeDefinition; + +typedef struct { + int num_nodes; /* number of data nodes */ + NodeDefinition* nodesDefinition; /* all data nodes' defination */ +} GlobalNodeDefinition; + +/* Connection statistics info */ +typedef struct { + Oid primaryNodeId; /* original primary nodeid */ + int nodeIndex; /* original primary node subscript */ + bool isSucceed; /* link setup success flag */ + Oid *nodeList; /* nodeid about all nodes in the same segment */ +} NodeRelationInfo; + +typedef struct DNInfo { + Oid oid; + int idx; /* the sequence id of dn */ +}DNInfo; + +extern GlobalNodeDefinition* global_node_definition; + +extern void NodeTablesShmemInit(void); +extern Size NodeTablesShmemSize(void); + +extern void PgxcNodeListAndCount(void); +extern void PgxcNodeGetOids(Oid** coOids, Oid** dnOids, int* num_coords, int* num_dns, bool update_preferred); +extern void PgxcNodeGetStandbyOids(int* num_dns); +extern NodeDefinition* PgxcNodeGetDefinition(Oid node); +extern void PgxcNodeAlter(AlterNodeStmt* stmt); +extern void PgxcNodeCreate(CreateNodeStmt* stmt); +extern char PgxcNodeRemove(DropNodeStmt* stmt); +extern void PgxcCoordinatorAlter(AlterCoordinatorStmt* stmt); + +extern List* PgxcNodeGetAllDataNodeNames(void); +extern List* PgxcNodeGetDataNodeNames(List* nodeList); +extern List* PgxcNodeGetDataNodeOids(List* nodeList); +extern int pickup_random_datanode(int numnodes); +extern List* PgxcGetCoordlist(bool exclude_self); +extern bool PgxcIsCentralCoordinator(const char* NodeName); +extern void PgxcGetNodeName(int node_idx, char* nodenamebuf, int len); +extern int PgxcGetNodeIndex(const char* nodename); +extern Oid PgxcGetNodeOid(int node_idx); +extern int PgxcGetCentralNodeIndex(); + +extern void PgxcNodeFreeDnMatric(void); +extern void PgxcNodeInitDnMatric(void); +extern bool PgxcNodeCheckDnMatric(Oid oid1, Oid oid2); +extern bool PgxcNodeCheckPrimaryHost(Oid oid, const char* host); +extern Oid PgxcNodeGetPrimaryDNFromMatric(Oid oid1); +extern void PgxcNodeCount(int* numCoords, int* numDns); + +extern bool set_dnoid_info_from_matric(NodeRelationInfo *needCreateNode, bool *isMatricVisited); + +/* interface of dataNode to use hash table */ +extern void dn_info_local_hash_create(); +extern int dn_info_hash_search(Oid dn_oid); +extern void dn_info_hash_insert(Oid dn_oid, int row); +extern void dn_info_hash_delete(Oid dn_oid); +extern void dn_info_hash_destory(); + +#endif /* NODEMGR_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/pgFdwRemote.h postgresql-hll-2.14/include/pgxc/pgFdwRemote.h --- postgresql-hll-2.14_old/include/pgxc/pgFdwRemote.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/pgFdwRemote.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,67 @@ + +#ifndef PG_FDW_REMOTE_H +#define PG_FDW_REMOTE_H + +#include "c.h" +#include "nodes/nodes.h" +#include "utils/snapshot.h" + +typedef enum PgFdwMessageTag { + PGFDW_GET_TABLE_INFO = 0, + PGFDW_ANALYZE_TABLE, + PGFDW_QUERY_PARAM, + PGFDW_GET_VERSION, + PGFDW_GET_ENCODE +} PgFdwMessageTag; + +typedef enum PgFdwCheckResult { + PGFDW_CHECK_OK = 0, + PGFDW_CHECK_TABLE_FAIL, + PGFDW_CHECK_RELKIND_FAIL, + PGFDW_CHECK_COLUNM_FAIL +} PgFdwCheckResult; + +/* + * the cooperation analysis version control + * if modify the message which is sended and received, u need do such step + * 1.enmu GcFdwVersion, need add version, + * e.g. GCFDW_VERSION_V1R8C10_1 = 101 GCFDW_VERSION_V1R9C00 = 200 + * 2.modify GCFDW_VERSION, the value need be set the lastest version. + * 3.new logic, need use if conditon with new version + * e.g. if (gc_fdw_run_version >= GCFDW_VERSION_V1R8C10_1) + * { pq_sendint64(&retbuf, u_sess->debug_query_id); } + */ +typedef enum GcFdwVersion { + GCFDW_VERSION_V1R8C10 = 100, /* the first version */ + GCFDW_VERSION_V1R8C10_1 = 101, /* add foreign table option : encode type */ + GCFDW_VERSION_V1R9C00 = 200 +} GcFdwVersion; + +#define GCFDW_VERSION GCFDW_VERSION_V1R8C10_1 + +typedef struct PgFdwRemoteInfo { + NodeTag type; + char reltype; /* relation type */ + int datanodenum; /* datanode num */ + Size snapsize; /* the really size of snapshot */ + Snapshot snapshot; /* snapshot */ +} PgFdwRemoteInfo; + +extern bool PgfdwGetRelAttnum(int2vector* keys, PGFDWTableAnalyze* info); +extern bool PgfdwGetRelAttnum(TupleTableSlot* slot, PGFDWTableAnalyze* info); +extern void pgfdw_send_query(PGXCNodeAllHandles* pgxc_handles, char* query, RemoteQueryState** remotestate); +extern void PgFdwReportError(PgFdwCheckResult check_result); +extern void pgfdw_node_report_error(RemoteQueryState* combiner); +extern void PgFdwSendSnapshot(StringInfo buf, Snapshot snapshot); +extern void PgFdwSendSnapshot(StringInfo buf, Snapshot snapshot, Size snap_size); +extern Snapshot PgFdwRecvSnapshot(StringInfo buf); +extern void PgFdwRemoteSender(PGXCNodeAllHandles* pgxc_handles, const char* keystr, int len, PgFdwMessageTag tag); +extern void PgFdwRemoteReply(StringInfo msg); +extern void PgFdwRemoteReceiver(PGXCNodeAllHandles* pgxc_handles, void* info, int size); +extern bool PgfdwGetTuples(int cn_conn_count, PGXCNodeHandle** pgxc_connections, + RemoteQueryState* remotestate, TupleTableSlot* scanSlot); +extern void FetchGlobalPgfdwStatistics(VacuumStmt* stmt, bool has_var, PGFDWTableAnalyze* info); + +#endif + + diff -uprN postgresql-hll-2.14_old/include/pgxc/pgxc.h postgresql-hll-2.14/include/pgxc/pgxc.h --- postgresql-hll-2.14_old/include/pgxc/pgxc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/pgxc.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,64 @@ +/* ------------------------------------------------------------------------- + * + * pgxc.h + * Postgres-XC flags and connection control information + * + * + * Portions Copyright (c) 1996-2011 PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/pgxc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PGXC_H +#define PGXC_H + +#include "storage/lwlock.h" +#include "postgres.h" +#include "knl/knl_variable.h" +extern bool isRestoreMode; + +// @Temp Table. Normally we only execute "drop schema pg_temp_XXX" on coordinator, +// but initdb use some temp tables too, whose we must do dropping in this case, +extern bool isSingleMode; + +extern bool isSecurityMode; + +typedef enum { + REMOTE_CONN_APP, + REMOTE_CONN_COORD, + REMOTE_CONN_DATANODE, + REMOTE_CONN_GTM, + REMOTE_CONN_GTM_PROXY, + REMOTE_CONN_INTERNAL_TOOL, + REMOTE_CONN_GTM_TOOL +} RemoteConnTypes; + +#ifdef ENABLE_MULTIPLE_NODES +#define IS_PGXC_COORDINATOR (g_instance.role == VCOORDINATOR && !is_streaming_engine()) +#define IS_PGXC_DATANODE (g_instance.role == VDATANODE || g_instance.role == VSINGLENODE || is_streaming_engine()) +#else +#define IS_PGXC_COORDINATOR (g_instance.role == VCOORDINATOR) +#define IS_PGXC_DATANODE (g_instance.role == VDATANODE || g_instance.role == VSINGLENODE) +#endif +#define IS_SINGLE_NODE (g_instance.role == VSINGLENODE) +#define REMOTE_CONN_TYPE u_sess->attr.attr_common.remoteConnType +#define COORDINATOR_NOT_SINGLE (g_instance.role == VDATANODE && g_instance.role != VSINGLENODE) + +#define IsConnFromApp() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_APP) +#define IsConnFromCoord() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_COORD) +#define IsConnFromDatanode() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_DATANODE) +#define IsConnFromGtm() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM) +#define IsConnFromGtmProxy() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM_PROXY) +#define IsConnFromInternalTool() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_INTERNAL_TOOL) +#define IsConnFromGTMTool() (u_sess->attr.attr_common.remoteConnType == REMOTE_CONN_GTM_TOOL) + +/* Is the CN receive SQL statement ? */ +#define IS_MAIN_COORDINATOR (IS_PGXC_COORDINATOR && !IsConnFromCoord()) + +/* key pair to be used as object id while using advisory lock for backup */ +#define XC_LOCK_FOR_BACKUP_KEY_1 0xFFFF +#define XC_LOCK_FOR_BACKUP_KEY_2 0xFFFF + +#endif /* PGXC_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/pgxcnode.h postgresql-hll-2.14/include/pgxc/pgxcnode.h --- postgresql-hll-2.14_old/include/pgxc/pgxcnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/pgxcnode.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,324 @@ +/* ------------------------------------------------------------------------- + * + * pgxcnode.h + * + * Utility functions to communicate to Datanodes and Coordinators + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group ? + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/pgxcnode.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PGXCNODE_H +#define PGXCNODE_H +#include "postgres.h" +#include "knl/knl_variable.h" +#include "gtm/gtm_c.h" +#include "utils/timestamp.h" +#include "nodes/pg_list.h" +#include "utils/globalplancache.h" +#include "utils/snapshot.h" +#include "libcomm/libcomm.h" +#include "getaddrinfo.h" +#include + +#define NO_SOCKET -1 + +/* Message type code of bucket map and dn node index */ +#define MSG_TYPE_PGXC_BUCKET_MAP 'G' + +/* for logic connection sock is useless, type of gstock gives whether current logic connection is ok */ +#define IS_VALID_CONNECTION(handle) \ + ((handle->is_logic_conn) ? (handle->gsock.type != GSOCK_INVALID) : (handle->sock != NO_SOCKET)) + +#define DDL_PBE_VERSION_NUM 92067 /* Version control for DDL PBE */ + +struct StreamNetCtl; +/* Connection to Datanode maintained by Pool Manager */ +typedef struct pg_conn NODE_CONNECTION; +typedef struct pg_cancel NODE_CANCEL; + +/* Helper structure to access Datanode from Session */ +typedef enum { + DN_CONNECTION_STATE_IDLE, /* idle, ready for query */ + DN_CONNECTION_STATE_QUERY, /* query is sent, response expected */ + DN_CONNECTION_STATE_ERROR_FATAL, /* fatal error */ + DN_CONNECTION_STATE_COPY_IN, + DN_CONNECTION_STATE_COPY_OUT +} DNConnectionState; + +typedef enum { HANDLE_IDLE, HANDLE_ERROR, HANDLE_DEFAULT } PGXCNode_HandleRequested; + +/* + * Enumeration for two purposes + * 1. To indicate to the HandleCommandComplete function whether response checking is required or not + * 2. To enable HandleCommandComplete function to indicate whether the response was a ROLLBACK or not + * Response checking is required in case of PREPARE TRANSACTION and should not be done for the rest + * of the cases for performance reasons, hence we have an option to ignore response checking. + * The problem with PREPARE TRANSACTION is that it can result in a ROLLBACK response + * yet Coordinator would think it got done on all nodes. + * If we ignore ROLLBACK response then we would try to COMMIT a transaction that + * never got prepared, which in an incorrect behavior. + */ +typedef enum { + RESP_ROLLBACK_IGNORE, /* Ignore response checking */ + RESP_ROLLBACK_CHECK, /* Check whether response was ROLLBACK */ + RESP_ROLLBACK_RECEIVED, /* Response is ROLLBACK */ + RESP_ROLLBACK_NOT_RECEIVED /* Response is NOT ROLLBACK */ +} RESP_ROLLBACK; + +/* To identify the different uses of CSN */ +typedef enum { + FETCH_CSN, /* A flag to fecth csn from other nodes */ + GLOBAL_CSN_MIN /* The global min csn between all nodes */ +} CsnType; + +#define DN_CONNECTION_STATE_ERROR(dnconn) \ + ((dnconn)->state == DN_CONNECTION_STATE_ERROR_FATAL || (dnconn)->transaction_status == 'E') + +#define HAS_MESSAGE_BUFFERED(conn) \ + ((conn)->inCursor + 4 < (conn)->inEnd && \ + (conn)->inCursor + ntohl(*((uint32_t*)((conn)->inBuffer + (conn)->inCursor + 1))) < (conn)->inEnd) + +/* + * Represents a DataRow message received from a remote node. + * Contains originating node number and message body in DataRow format without + * message code and length. Length is separate field + */ +typedef struct RemoteDataRowData { + char* msg; /* last data row message */ + int msglen; /* length of the data row message */ + int msgnode; /* node number of the data row message */ +} RemoteDataRowData; +typedef RemoteDataRowData* RemoteDataRow; + +struct pgxc_node_handle { + Oid nodeoid; + + /* fd of the connection */ + int sock; + + /* tcp connection */ + int tcpCtlPort; + int listenPort; + /* logic connection socket between cn and dn */ + gsocket gsock; + + char transaction_status; + DNConnectionState state; + struct RemoteQueryState* combiner; + struct StreamState* stream; +#ifdef DN_CONNECTION_DEBUG + bool have_row_desc; +#endif + char* error; + char* hint; + /* Output buffer */ + char* outBuffer; + size_t outSize; + size_t outEnd; + uint64 outNum; + /* Input buffer */ + char* inBuffer; + size_t inSize; + size_t inStart; + size_t inEnd; + size_t inCursor; + + /* + * Have a variable to enable/disable response checking and + * if enable then read the result of response checking + * + * For details see comments of RESP_ROLLBACK + */ + RESP_ROLLBACK ck_resp_rollback; + + char* remoteNodeName; + int nodeIdx; /* datanode index, like t_thrd.postmaster_cxt.PGXCNodeId */ + knl_virtual_role remote_node_type; + PoolConnInfo connInfo; + /* flag to identify logic connection between cn and dn */ + bool is_logic_conn; + NODE_CONNECTION* pg_conn; + MessageCommLog *msgLog; + TransactionId remote_top_txid; +}; +typedef struct pgxc_node_handle PGXCNodeHandle; + +/* + * Because the number of node handles is identical to the number of nodes, + * so here we combine both CN and DN handles together for better maitanences + */ +typedef struct PGXCNodeHandleGroup { + PGXCNodeHandle* nodeHandles; + uint32 nodeHandleNums; + + /* dn and cn slots often process together, so need offset to indicate real postion */ + uint32 offset; +} PGXCNodeHandleGroup; + +typedef struct PGXCNodeNetCtlLayer { + int conn_num; /* size of array */ + struct pollfd* ufds; /* physic poll fds. */ + int* datamarks; /* producer number triggers poll. */ + int* poll2conn; /* poll idx to connection idx. */ + gsocket* gs_sock; /* logic poll gs_sock. */ +} PGXCNodeNetCtlLayer; + +/* Structure used to get all the handles involved in a transaction */ +typedef struct PGXCNodeAllHandles { + PGXCNodeHandle* primary_handle; /* Primary connection to PGXC node */ + int dn_conn_count; /* number of Datanode Handles including primary handle */ + PGXCNodeHandle** datanode_handles; /* an array of Datanode handles */ + List* dummy_datanode_handles; /* only valid for replicate table dml */ + int co_conn_count; /* number of Coordinator handles */ + PGXCNodeHandle** coord_handles; /* an array of Coordinator handles */ +} PGXCNodeAllHandles; + +typedef struct { + int* fds; + gsocket* gsock; + PoolConnInfo* connInfos; + NODE_CONNECTION** pgConn; + int pgConnCnt; +} PoolConnDef; + +extern void InitMultinodeExecutor(bool is_force); + +/* Open/close connection routines (invoked from Pool Manager) */ +extern char *PGXCNodeConnStr(const char *host, int port, const char *dbname, const char *user, + const char *pgoptions, const char *remote_type, int proto_type, const char *remote_nodename); + +extern NODE_CONNECTION* PGXCNodeConnect(char* connstr); +extern int PGXCNodeSendSetQuery(NODE_CONNECTION* conn, const char* sql_command); +extern int PGXCNodeSetQueryGetResult(NODE_CONNECTION* conn); +extern int PGXCNodeSendSetQueryPoolerStatelessReuse(NODE_CONNECTION* conn, const char* sql_command); +extern void PGXCNodeClose(NODE_CONNECTION* conn); +extern int PGXCNodeConnected(NODE_CONNECTION* conn); +extern int PGXCNodeConnClean(NODE_CONNECTION* conn); +extern void PGXCNodeCleanAndRelease(int code, Datum arg); +extern void PGXCConnClean(int code, Datum arg); + +/* Look at information cached in node handles */ +extern int PGXCNodeGetNodeId(Oid nodeoid, char node_type); +extern Oid PGXCNodeGetNodeOid(int nodeid, char node_type); +extern int PGXCNodeGetNodeIdFromName(const char* node_name, char node_type); +extern char* PGXCNodeGetNodeNameFromId(int nodeid, char node_type); +extern int LibcommPacketSend(NODE_CONNECTION* conn, char pack_type, const void* buf, size_t buf_len); +extern bool LibcommCancelOrStop(NODE_CONNECTION* conn, char* errbuf, int errbufsize, int timeout, uint32 request_code); +extern bool LibcommStopQuery(NODE_CONNECTION* conn); +extern int LibcommSendSome(NODE_CONNECTION* conn, int len); +extern int LibcommPutMsgEnd(NODE_CONNECTION* conn); +extern int LibcommFlush(NODE_CONNECTION* conn); +extern int LibcommSendQuery(NODE_CONNECTION* conn, const char* query); +extern int LibcommReadData(NODE_CONNECTION* conn); +extern PGXCNodeAllHandles* get_handles( + List* datanodelist, List* coordlist, bool is_query_coord_only, List* dummydatanodelist = NIL); +extern void pfree_pgxc_all_handles(PGXCNodeAllHandles* handles); + +extern void release_pgxc_handles(PGXCNodeAllHandles* pgxc_handles); +extern void release_handles(void); +extern void destroy_handles(void); +extern void reset_handles_at_abort(void); +extern void cancel_query(void); +extern void cancel_query_without_read(void); +extern void stop_query(void); +extern void clear_all_data(void); + +extern int get_transaction_nodes( + PGXCNodeHandle** connections, char client_conn_type, PGXCNode_HandleRequested type_requested); +extern char* collect_pgxcnode_names( + char* nodestring, int conn_count, PGXCNodeHandle** connections, char client_conn_type); +extern char* collect_localnode_name(char* nodestring); +extern int get_active_nodes(PGXCNodeHandle** connections); + +extern void ensure_in_buffer_capacity(size_t bytes_needed, PGXCNodeHandle* handle); +extern void ensure_out_buffer_capacity(size_t bytes_needed, PGXCNodeHandle* handle); + +extern int pgxc_node_send_threadid(PGXCNodeHandle* handle, uint32 threadid); +extern int pgxc_node_send_queryid(PGXCNodeHandle* handle, uint64 queryid); +extern int pgxc_node_send_cn_identifier(PGXCNodeHandle *handle, PGXCNode_HandleGPC handle_type); + +extern int pgxc_node_send_unique_sql_id(PGXCNodeHandle* handle); +extern int pgxc_node_send_query(PGXCNodeHandle* handle, const char* query, bool isPush = false, + bool trigger_ship = false, bool check_gtm_mode = false, const char *compressPlan = NULL, int cLen = 0); +extern void pgxc_node_send_gtm_mode(PGXCNodeHandle* handle); +extern int pgxc_node_send_plan_with_params(PGXCNodeHandle* handle, const char* query, short num_params, + Oid* param_types, int paramlen, const char* params, int fetch_size); +extern int pgxc_node_send_describe(PGXCNodeHandle* handle, bool is_statement, const char* name); +extern int pgxc_node_send_execute(PGXCNodeHandle* handle, const char* portal, int fetch); +extern int pgxc_node_send_close(PGXCNodeHandle* handle, bool is_statement, const char* name); +extern int pgxc_node_send_sync(PGXCNodeHandle* handle); +extern int pgxc_node_send_bind( + PGXCNodeHandle* handle, const char* portal, const char* statement, int paramlen, const char* params); +extern int pgxc_node_send_parse( + PGXCNodeHandle* handle, const char* statement, const char* query, short num_params, Oid* param_types); +extern int pgxc_node_send_query_extended(PGXCNodeHandle* handle, const char* query, const char* statement, + const char* portal, int num_params, Oid* param_types, int paramlen, const char* params, bool send_describe, + int fetch_size); +extern int pgxc_node_send_gxid(PGXCNodeHandle* handle, GlobalTransactionId gxid, bool isforcheck); +extern int pgxc_node_send_commit_csn(PGXCNodeHandle* handle, uint64 commit_csn); +extern int pgxc_node_send_csn(PGXCNodeHandle* handle, uint64 commit_csn, CsnType csn_type); +extern int pgxc_node_notify_commit(PGXCNodeHandle* handle); +extern int pgxc_node_send_cmd_id(PGXCNodeHandle* handle, CommandId cid); +extern int pgxc_node_send_wlm_cgroup(PGXCNodeHandle* handle); +extern int pgxc_node_dywlm_send_params_for_jobs(PGXCNodeHandle* handle, int tag, const char* keystr); +extern int pgxc_node_dywlm_send_params(PGXCNodeHandle* handle, const void* info); +extern int pgxc_node_dywlm_send_record(PGXCNodeHandle* handle, int tag, const char* infostr); +extern int pgxc_node_send_pgfdw(PGXCNodeHandle* handle, int tag, const char* keystr, int len); +extern int pgxc_node_send_snapshot(PGXCNodeHandle* handle, Snapshot snapshot, int max_push_sqls = 1); +extern int pgxc_node_send_ddl_params(PGXCNodeHandle* handle); +extern int pgxc_node_send_timestamp( + PGXCNodeHandle* handle, TimestampTz gtmstart_timestamp, TimestampTz stmtsys_timestamp); +extern int pgxc_node_send_pushschema(PGXCNodeHandle* handle, bool* isPush); +extern int pgxc_node_send_popschema(PGXCNodeHandle* handle); +extern int pgxc_node_is_data_enqueued(PGXCNodeHandle* conn); +extern int send_some(PGXCNodeHandle* handle, int len); +extern int pgxc_node_flush(PGXCNodeHandle* handle); +extern bool pgxc_node_flush_read(PGXCNodeHandle* handle); +extern int pgxc_all_handles_send_gxid(PGXCNodeAllHandles* pgxc_handles, GlobalTransactionId gxid, bool stop_at_error); +extern int pgxc_all_handles_send_query(PGXCNodeAllHandles* pgxc_handles, const char* buffer, bool stop_at_error); +extern void add_error_message(PGXCNodeHandle* handle, const char *message, ...); +extern char get_message(PGXCNodeHandle *conn, int *len, char **msg); +extern Datum pgxc_execute_on_nodes(int numnodes, Oid* nodelist, char* query); +extern bool pgxc_node_receive(const int conn_count, PGXCNodeHandle** connections, struct timeval* timeout); +extern bool datanode_receive_from_physic_conn( +const int conn_count, PGXCNodeHandle** connections, struct timeval* timeout); +extern bool datanode_receive_from_logic_conn( +const int conn_count, PGXCNodeHandle** connections, StreamNetCtl* ctl, int time_out); + +extern bool pgxc_node_validate(PGXCNodeHandle *conn); +extern int pgxc_node_read_data(PGXCNodeHandle* conn, bool close_if_error, bool StreamConnection = false); +extern int pgxc_node_read_data_from_logic_conn(PGXCNodeHandle* conn, bool close_if_error); +extern void ResetHandleOutBuffer(PGXCNodeHandle* handle); +extern void connect_server( + const char* conn_str, PGXCNodeHandle** handle, const char* host, int port, const char* log_conn_str); +extern void release_conn_to_compute_pool(); +extern void release_pgfdw_conn(); + +extern int pgxc_node_send_userpl(PGXCNodeHandle* handle, int userpl); +extern int pgxc_node_send_userpl(PGXCNodeHandle* handle, int64 userpl); +extern int pgxc_node_send_cpconf(PGXCNodeHandle* handle, char* data); +extern int pgxc_send_bucket_map(PGXCNodeHandle* handle, uint2* bucketMap, int dnNodeIdx); + +extern bool light_node_receive(PGXCNodeHandle* handle); +extern bool light_node_receive_from_logic_conn(PGXCNodeHandle* handle); +extern int pgxc_node_pgstat_send(PGXCNodeHandle* handle, char tag); +extern void pgxc_node_free(PGXCNodeHandle* handle); +extern void pgxc_node_init(PGXCNodeHandle* handle, int sock); +extern void pgxc_node_free_def(PoolConnDef* result); +extern void pgxc_palloc_net_ctl(int conn_num); +extern int ts_get_tag_colnum(Oid relid, bool need_index = false, List** idx_list = NULL); + +#endif /* PGXCNODE_H */ + +#ifdef ENABLE_UT +extern char* getNodenameByIndex(int index); +extern int LibcommSendQueryPoolerStatelessReuse(NODE_CONNECTION* conn, const char* query); +extern int LibcommWaitpoll(NODE_CONNECTION* conn); +extern int light_node_read_data(PGXCNodeHandle* conn); +#endif /* USE_UT */ diff -uprN postgresql-hll-2.14_old/include/pgxc/pgxcXact.h postgresql-hll-2.14/include/pgxc/pgxcXact.h --- postgresql-hll-2.14_old/include/pgxc/pgxcXact.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/pgxcXact.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,26 @@ + +#ifndef PGXC_TRANS_H +#define PGXC_TRANS_H + +#include "c.h" +#include "pgxc/pgxcnode.h" + +extern int pgxc_node_begin(int conn_count, PGXCNodeHandle** connections, + GlobalTransactionId gxid, bool need_tran_block, + bool readOnly, char node_type, bool need_send_queryid = false); +extern bool pgxc_node_remote_prepare(const char* prepareGID, bool WriteCnLocalNode); +extern void pgxc_node_remote_commit(bool barrierLockHeld); +extern int pgxc_node_remote_abort(void); +extern int pgxc_node_receive_responses(const int conn_count, PGXCNodeHandle** connections, + struct timeval* timeout, RemoteQueryState* combiner, bool checkerror = true); +extern List* GetWriterHandles(); +extern List* GetReaderHandles(); +extern void PreCommit_Remote(char* prepareGID, bool barrierLockHeld); +extern void SubXactCancel_Remote(void); +extern char* PrePrepare_Remote(const char* prepareGID, bool implicit, bool WriteCnLocalNode); +extern void PostPrepare_Remote(char* prepareGID, char* nodestring, bool implicit); +extern bool PreAbort_Remote(bool PerfectRollback); +extern void AtEOXact_Remote(void); +extern bool IsTwoPhaseCommitRequired(bool localWrite); +extern void reset_remote_handle_xid(void); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/pgxc/poolcomm.h postgresql-hll-2.14/include/pgxc/poolcomm.h --- postgresql-hll-2.14_old/include/pgxc/poolcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/poolcomm.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * poolcomm.h + * + * Definitions for the Pooler-Seesion communications. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolcomm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POOLCOMM_H +#define POOLCOMM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "lib/stringinfo.h" +#include "libcomm/libcomm.h" +#include "pgxc/pgxcnode.h" + +#define POOL_BUFFER_SIZE 1024 +#define Socket(port) (port).fdsock + +typedef struct { + /* file descriptors */ + int fdsock; + /* receive buffer */ + int RecvLength; + int RecvPointer; + char RecvBuffer[POOL_BUFFER_SIZE]; + /* send buffer */ + int SendPointer; + char SendBuffer[POOL_BUFFER_SIZE]; +} PoolPort; + +extern int pool_listen(unsigned short port, const char* unixSocketName); +extern int pool_connect(unsigned short port, const char* unixSocketName); +extern int pool_getbyte(PoolPort* port); +extern int pool_pollbyte(PoolPort* port); +extern int pool_getmessage(PoolPort* port, StringInfo s, int maxlen); +extern int pool_getbytes(PoolPort* port, char* s, size_t len); +extern int pool_putmessage(PoolPort* port, char msgtype, const char* s, size_t len); +extern int pool_putbytes(PoolPort* port, const char* s, size_t len); +extern int pool_flush(PoolPort* port); +extern int pool_sendconnDefs(PoolPort* port, PoolConnDef* connDef, int count); +extern int pool_recvconnDefs(PoolPort* port, PoolConnDef* connDef, int count); +extern int pool_sendres(PoolPort* port, int res); +extern int pool_recvres(PoolPort* port); +extern int pool_sendpids(PoolPort* port, ThreadId* pids, int count); +extern int pool_recvpids(PoolPort* port, ThreadId** pids); + +#endif /* POOLCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/poolmgr.h postgresql-hll-2.14/include/pgxc/poolmgr.h --- postgresql-hll-2.14_old/include/pgxc/poolmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/poolmgr.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,406 @@ +/* ------------------------------------------------------------------------- + * + * poolmgr.h + * + * Definitions for the Datanode connection pool. + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolmgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POOLMGR_H +#define POOLMGR_H +#include +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "poolcomm.h" +#include "storage/pmsignal.h" +#include "utils/hsearch.h" +#include "executor/execStream.h" + +#define MAX_IDLE_TIME 60 +#define ENABLE_STATELESS_REUSE g_instance.attr.attr_network.PoolerStatelessReuse +/* The handle status is normal, send back socket to the pool */ +#define CONN_STATE_NORMAL 'n' +/* The handle status has an error, drop the socket */ +#define CONN_STATE_ERROR 'e' +/* param number */ +#define FOUR_ARGS (4) +#define FIVE_ARGS (5) +#define SIX_ARGS (6) + +/* + * List of flags related to pooler connection clean up when disconnecting + * a session or relaeasing handles. + * When Local SET commands (POOL_CMD_LOCAL_SET) are used, local parameter + * string is cleaned by the node commit itself. + * When global SET commands (POOL_CMD_GLOBAL_SET) are used, "RESET ALL" + * command is sent down to activated nodes to at session end. At the end + * of a transaction, connections using global SET commands are not sent + * back to pool. + * When temporary object commands are used (POOL_CMD_TEMP), "DISCARD ALL" + * query is sent down to nodes whose connection is activated at the end of + * a session. + * At the end of a transaction, a session using either temporary objects + * or global session parameters has its connections not sent back to pool. + * + * Local parameters are used to change within current transaction block. + * They are sent to remote nodes invloved in the transaction after sending + * BEGIN TRANSACTION using a special firing protocol. + * They cannot be sent when connections are obtained, making them having no + * effect as BEGIN is sent by backend after connections are obtained and + * obtention confirmation has been sent back to backend. + * SET CONSTRAINT, SET LOCAL commands are in this category. + * + * Global parmeters are used to change the behavior of current session. + * They are sent to the nodes when the connections are obtained. + * SET GLOBAL, general SET commands are in this category. + */ +typedef enum { + POOL_CMD_TEMP, /* Temporary object flag */ + POOL_CMD_LOCAL_SET, /* Local SET flag, current transaction block only */ + POOL_CMD_GLOBAL_SET /* Global SET flag */ +} PoolCommandType; + +typedef enum { + POOL_NODE_CN, /* node type: coordinator */ + POOL_NODE_DN /* node type: datanode */ +} PoolNodeType; + +typedef enum { + POOL_NODE_NONE = 0, /* no node mode */ + POOL_NODE_PRIMARY, /* node mode: primary */ + POOL_NODE_STANDBY /* node mode: standby */ +} PoolNodeMode; + +/* Connection pool entry */ +typedef struct PGXCNodePoolSlot { + /* In pooler stateless reuse mode, user_name and pgoptions save in slot to check whether to send params */ + char* user_name; + char* pgoptions; /* Connection options */ + char* session_params; + bool need_validate; + Oid userid; + struct timeval released; + NODE_CONNECTION* conn; + NODE_CANCEL* xc_cancelConn; + pthread_mutex_t slot_lock; + union { + uint32 node_count; /* for list head: numbers of node */ + uint32 used_count; /* for list node: counting the times of the slot be used */ + }; + struct PGXCNodePoolSlot* next; +} PGXCNodePoolSlot; + +/* Pool of connections to specified pgxc node */ +typedef struct { + Oid nodeoid; /* Node Oid related to this pool, Hash key (must be first!) */ + char* connstr; + char* connstr1; + int freeSize; /* available connections */ + int size; /* total pool size */ + bool valid; /* ensure atom initialization of node pool */ + pthread_mutex_t lock; + PGXCNodePoolSlot** slot; /* use in not ENABLE_STATELESS_REUSE */ + HTAB* useridSlotsHash; /* hash table: key(userid), value(PGXCNodePoolSlot*), use in ENABLE_STATELESS_REUSE */ +} PGXCNodePool; + +/* All pools for specified database */ +typedef struct databasepool { + char* database; + char* user_name; + Oid userId; + char* pgoptions; /* Connection options */ + HTAB* nodePools; /* Hashtable of PGXCNodePool, one entry for each Coordinator or DataNode */ + /* lock for nodePools to add/find/remove */ + pthread_mutex_t nodePoolsLock; + MemoryContext mcxt; + struct databasepool* next; /* Reference to next to organize linked list */ +} DatabasePool; + +typedef struct PoolerCleanParams { + DatabasePool **dbPool; + List *nodeList; + Oid *nodeOids; + int totalCleanNums; + int needCleanNumsPerNode; + int totalNodes; + struct timeval *currVal; +} PoolerCleanParams; + +typedef struct { + ThreadId pid; /* Process ID of postmaster child process associated to pool agent */ + int num_invalid_node; /* the num of nodes that connection is invalid */ + int num_connections; /* num of the node connections */ + int result_offset; /* offset of result */ + int* invalid_nodes; /* the nodes that connection is invalid */ + Oid* conn_oids; /* connection id for each node */ + PGXCNodePoolSlot** connections; /* connection for each node */ + DatabasePool* dbpool; /* database pool */ + char* session_params; /* session params */ + char* temp_namespace; /* @Temp table. temp namespace name of session related to this agent. */ + PoolNodeType node_type; /* node type, dn or dn */ + PoolNodeMode* node_mode; /* node mode: primary, standby or none */ + PoolConnDef* conndef; /* pool conn def */ + bool is_retry; /* retry to connect */ + PoolAgent* agent; /* reference to local PoolAgent struct */ +} PoolGeneralInfo; + +/* + * The number of conn slots is recorded based on the number of connSlotNums + * So we bind the two values together to maintain integrity + */ +typedef struct PoolSlotGroup { + PGXCNodePoolSlot** connSlots; + Oid* connOids; + uint32 connSlotNums; + + /* dn and cn slots often process together, so need offset to indicate real postion */ + uint32 offset; +} PoolSlotGroup; + +/* + * Agent of client session (Pool Manager side) + * Acts as a session manager, grouping connections together + * and managing session parameters + */ +typedef struct PoolAgent { + /* Process ID of postmaster child process associated to pool agent */ + ThreadId pid; + /* communication channel */ + PoolPort port; + DatabasePool* pool; + + /* In pooler stateless reuse mode, user_name and pgoptions save in PoolAgent */ + char* user_name; + char* pgoptions; /* Connection options */ + bool has_check_params; // Deal with the situations where SET GUC commands are run within a Transaction block + bool is_thread_pool_session; // use for thread pool + uint64 session_id; /* user session id(when thread pool disabled, equal to pid) */ + + MemoryContext mcxt; + int num_dn_connections; + int num_coord_connections; + int params_set; /* param is set */ + int localParamsSet; /* local param is set */ + int reuse; /* connection reuse flag */ + Oid* dn_conn_oids; /* one for each Datanode */ + Oid* coord_conn_oids; /* one for each Coordinator */ + Oid* dn_connecting_oids; /* current connection dn oids */ + int dn_connecting_cnt; /* current connection dn count */ + Oid* coord_connecting_oids; /* current connection cn oids */ + int coord_connecting_cnt; /* current connection cn count */ + PGXCNodePoolSlot** dn_connections; /* one for each Datanode */ + PGXCNodePoolSlot** coord_connections; /* one for each Coordinator */ + char* session_params; + char* local_params; + char* temp_namespace; /* @Temp table. temp namespace name of session related to this agent. */ + List* params_list; /* session params list */ + List* localParamsList; /* local params list */ + pthread_mutex_t lock; /* protect agent in mutilthread */ +} PoolAgent; + +/* + * Invalid backend entry + * Collect info from pooler and pgxc_node. An invalid backend + * may hold several invalid connections to different node. + */ +typedef struct { + ThreadId tid; + char** node_name; + bool is_thread_pool_session; + + /* + * used to send signal. + * if IS_THREAD_POOL_WORKER, set to session_ctr_index; + * else is MyProcPid + */ + ThreadId send_sig_pid; + + int num_nodes; + int total_len; + bool is_connecting; +} InvalidBackendEntry; + +/* + * PoolConnectionInfo entry for pg_pooler_status view + */ +typedef struct { + char* database; + char* user_name; + ThreadId tid; + char* pgoptions; + bool in_use; + Oid nodeOid; + char *session_params; + int fdsock; + ThreadId remote_pid; + uint32 used_count; /*counting the times of the slot be used*/ +} PoolConnectionInfo; + +/* + * ConnectionStatus entry for pg_conn_status view + */ +typedef struct { + char *remote_name; + char *remote_host; + int remote_port; + bool is_connected; + int sock; +} ConnectionStatus; + +/* Connection information cached */ +typedef struct PGXCNodeConnectionInfo { + Oid nodeoid; + char* host; + int port; + int64 cn_connect_time; + int64 dn_connect_time; +} PGXCNodeConnectionInfo; + +/* Connection statistics info */ +typedef struct { + int count; + int free_count; + int64 memory_size; + int64 free_memory_size; + int dbpool_count; + int nodepool_count; +} PoolConnStat; + +typedef struct DatanodeShardInfo +{ + Oid s_nodeoid; + NameData s_data_shardname; + Oid s_primary_nodeoid; + NameData s_primary_nodename; +} DatanodeShardInfo; + +typedef PoolAgent PoolHandle; + +/* Status inquiry functions */ +extern void PGXCPoolerProcessIam(void); +extern bool IsPGXCPoolerProcess(void); + +/* Initialize internal structures */ +extern int PoolManagerInit(void); + +/* Destroy internal structures */ +extern int PoolManagerDestroy(void); + +/* + * Get handle to pool manager. This function should be called just before + * forking off new session. It creates PoolHandle, PoolAgent and a pipe between + * them. PoolAgent is stored within Postmaster's memory context and Session + * closes it later. PoolHandle is returned and should be store in a local + * variable. After forking off it can be stored in global memory, so it will + * only be accessible by the process running the session. + */ +extern PoolHandle* GetPoolManagerHandle(void); + +/* + * Called from Postmaster(Coordinator) after fork. Close one end of the pipe and + * free memory occupied by PoolHandler + */ +extern void PoolManagerCloseHandle(PoolHandle* handle); + +/* + * Gracefully close connection to the PoolManager + */ +extern void PoolManagerDisconnect(void); + +extern char* session_options(void); + +/* + * Called from Session process after fork(). Associate handle with session + * for subsequent calls. Associate session with specified database and + * initialize respective connection pool + */ +extern void PoolManagerConnect(PoolHandle* handle, const char* database, const char* user_name, const char* pgoptions); + +/* + * Reconnect to pool manager + * This simply does a disconnection followed by a reconnection. + */ +extern void PoolManagerReconnect(void); + +/* + * Save a SET command in Pooler. + * This command is run on existent agent connections + * and stored in pooler agent to be replayed when new connections + * are requested. + */ +extern int PoolManagerSetCommand(PoolCommandType command_type, const char* set_command, const char* name = NULL); + +/* Get pooled connection status */ +extern bool PoolManagerConnectionStatus(List* datanodelist, List* coordlist); + +/* Get pooled connections */ +extern PoolConnDef* PoolManagerGetConnections(List* datanodelist, List* coordlist); + +/* Clean pool connections */ +extern bool PoolManagerCleanConnection( + List* datanodelist, List* coordlist, const char* dbname, const char* username, bool is_missing = false); + +/* Check consistency of connection information cached in pooler with catalogs */ +extern bool PoolManagerCheckConnectionInfo(void); + +/* Reload connection data in pooler and drop all the existing connections of pooler */ +extern void PoolManagerReloadConnectionInfo(void); + +/* Send Abort signal to transactions being run */ +extern int PoolManagerAbortTransactions( + const char* dbname, const char* username, ThreadId** proc_pids, bool** isthreadpool); + +/* Return connections back to the pool, for both Coordinator and Datanode connections */ +extern void PoolManagerReleaseConnections(const char* status_array, int array_size, bool has_error); + +/* return (canceled) invalid backend entry */ +extern InvalidBackendEntry* PoolManagerValidateConnection(bool clear, const char* co_node_name, uint32& count); + +/* Cancel a running query on Datanodes as well as on other Coordinators */ +extern int PoolManagerCancelQuery(int dn_count, const int* dn_list, int co_count, const int* co_list); + +// stop a running query. +extern int PoolManagerStopQuery(int dn_count, const int* dn_list); + +/* Check if pool has a handle */ +extern bool IsPoolHandle(void); + +extern bool test_conn(PGXCNodePoolSlot* slot, Oid nodeid); +extern PoolAgent* get_poolagent(void); + +extern void release_connection(PoolAgent* agent, PGXCNodePoolSlot** ptrSlot, Oid node, bool force_destroy); + +/* Send commands to alter the behavior of current transaction */ +extern int PoolManagerSendLocalCommand(int dn_count, const int* dn_list, int co_count, const int* co_list); + +extern int* StreamConnectNodes(List* datanodelist, int consumerDop, int distrType, NodeDefinition* nodeDef, + struct addrinfo** addrArray, StreamKey key, Oid nodeoid); +extern int* StreamConnectNodes(libcommaddrinfo** addrArray, int connNum); + +extern void PoolManagerInitPoolerAgent(); +extern int get_pool_connection_info(PoolConnectionInfo** connectionEntry); +extern int check_connection_status(ConnectionStatus **connectionEntry); +extern void set_pooler_ping(bool mod); +extern void pooler_get_connection_statinfo(PoolConnStat* conn_stat); +extern int register_pooler_session_param(const char* name, const char* queryString, PoolCommandType command_type); +extern int delete_pooler_session_params(const char* name); +extern void agent_reset_session(PoolAgent* agent, bool need_reset); +extern const char* GetNodeNameByOid(Oid nodeOid); +extern void InitOidNodeNameMappingCache(); +extern void CleanOidNodeNameMappingCache(); +#endif + +#ifdef ENABLE_UT +extern THR_LOCAL PoolHandle* poolHandle; +extern void free_user_name_pgoptions(PGXCNodePoolSlot* slot); +extern void reload_user_name_pgoptions(PoolGeneralInfo* info, PoolAgent* agent, PGXCNodePoolSlot* slot); +extern PGXCNodePoolSlot* alloc_slot_mem(DatabasePool* dbpool); +extern int agent_wait_send_connection_params_pooler_reuse(NODE_CONNECTION* conn); +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/poolutils.h postgresql-hll-2.14/include/pgxc/poolutils.h --- postgresql-hll-2.14_old/include/pgxc/poolutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/poolutils.h 2020-12-12 17:06:43.357349457 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * poolutils.h + * + * Utilities for Postgres-XC Pooler + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/pgxc/poolutils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POOLUTILS_H +#define POOLUTILS_H + +#include "nodes/parsenodes.h" + +#define TIMEOUT_CLEAN_LOOP 15 /* Wait 15s for all the transactions to shutdown */ + +/* Error codes for connection cleaning */ +#define CLEAN_CONNECTION_COMPLETED 0 +#define CLEAN_CONNECTION_NOT_COMPLETED 1 +#define CLEAN_CONNECTION_TX_REMAIN 2 +#define CLEAN_CONNECTION_EOF -1 + +/* Results for pooler connection info check */ +#define POOL_CHECK_SUCCESS 0 +#define POOL_CHECK_FAILED 1 + +void CleanConnection(CleanConnStmt* stmt); +void DropDBCleanConnection(const char* dbname); +void DropRoleCleanConnection(const char* username); + +/* Handle pooler connection reload */ +void processPoolerReload(void); + +#define ResetSessionExecutorInfo(is_force) \ + do { \ + MemoryContext old_context = MemoryContextSwitchTo( \ + SESS_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR)); \ + InitMultinodeExecutor(is_force); \ + PoolManagerReconnect(); \ + MemoryContextSwitchTo(old_context); \ + } while (0) + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/pruningslice.h postgresql-hll-2.14/include/pgxc/pruningslice.h --- postgresql-hll-2.14_old/include/pgxc/pruningslice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/pruningslice.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pruningslice.h + * some routines that be used for slice pruning for list/range distributed table. + * + * + * IDENTIFICATION + * src/include/pgxc/pruningslice.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef PRUNINGSLICE_H_ +#define PRUNINGSLICE_H_ + +void PruningSliceForExecNodes(ExecNodes* exec_nodes, ParamListInfo boundParams); +void PruningSliceForQuals(ExecNodes* execNodes, Index varno, Node* quals, ParamListInfo boundParams); + +void InitDistColIndexMap(int* colMap, List* distColIdxList); +Oid GetRangeNodeFromValue(RelationLocInfo* relLocInfo, Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len); +Oid GetListNodeFromValue(RelationLocInfo* relLocInfo, Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len); + +void PruningRangeSlice(ExecNodes* exec_nodes, RelationLocInfo* relLocInfo, Index varno, RelationAccessType relaccess, + ListCell* last_distcol_cell, Node* quals, ParamListInfo boundParams, bool useDynReduce); + +void ConstructConstFromValues(Datum* datums, const bool* nulls, Oid* attrs, + int* colMap, int len, Const* consts, Const** constPointers); +void ConstructSliceBoundary(ExecNodes* en); +uint2 GetTargetConsumerNodeIdx(ExecBoundary* enBoundary, Const** distValues, int distLen); + + +#endif /* PRUNINGSLICE_H_ */ + diff -uprN postgresql-hll-2.14_old/include/pgxc/redistrib.h postgresql-hll-2.14/include/pgxc/redistrib.h --- postgresql-hll-2.14_old/include/pgxc/redistrib.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/redistrib.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,115 @@ +/* ------------------------------------------------------------------------- + * + * redistrib.h + * Routines related to online data redistribution + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/redistrib.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef REDISTRIB_H +#define REDISTRIB_H + +#include "commands/defrem.h" +#include "nodes/parsenodes.h" +#include "utils/tuplestore.h" +#include "storage/itemptr.h" + +/* + * Type of data redistribution operations. + * Online data redistribution is made of one or more of those operations. + */ +typedef enum RedistribOperation { + DISTRIB_NONE, /* Default operation */ + DISTRIB_DELETE_HASH, /* Perform a DELETE with hash value check */ + DISTRIB_DELETE_MODULO, /* Perform a DELETE with modulo value check */ + DISTRIB_COPY_TO, /* Perform a COPY TO */ + DISTRIB_COPY_FROM, /* Perform a COPY FROM */ + DISTRIB_TRUNCATE, /* Truncate relation */ + DISTRIB_REINDEX /* Reindex relation */ +} RedistribOperation; + +/* + * Determine if operation can be done before or after + * catalog update on local node. + */ +typedef enum RedistribCatalog { + CATALOG_UPDATE_NONE, /* Default state */ + CATALOG_UPDATE_AFTER, /* After catalog update */ + CATALOG_UPDATE_BEFORE, /* Before catalog update */ + CATALOG_UPDATE_BOTH /* Before and after catalog update */ +} RedistribCatalog; + +/* + * Redistribution command + * This contains the tools necessary to perform a redistribution operation. + */ +typedef struct RedistribCommand { + RedistribOperation type; /* Operation type */ + ExecNodes* execNodes; /* List of nodes where to perform operation */ + RedistribCatalog updateState; /* Flag to determine if operation can be done before or after catalog update */ +} RedistribCommand; + +/* + * Redistribution operation state + * Maintainer of redistribution state having the list of commands + * to be performed during redistribution. + * For the list of commands, we use an array and not a simple list as operations + * might need to be done in a certain order. + */ +typedef struct RedistribState { + Oid relid; /* Oid of relation redistributed */ + List* commands; /* List of commands */ + Tuplestorestate* store; /* Tuple store used for temporary data storage */ +} RedistribState; + +extern void PGXCRedistribTable(RedistribState* distribState, RedistribCatalog type); +extern void PGXCRedistribCreateCommandList(RedistribState* distribState, RelationLocInfo* newLocInfo); +extern RedistribCommand* makeRedistribCommand(RedistribOperation type, + RedistribCatalog updateState, ExecNodes* nodes); +extern RedistribState* makeRedistribState(Oid relOid); +extern void FreeRedistribState(RedistribState* state); +extern void FreeRedistribCommand(RedistribCommand* command); + +extern List* AlterTableSetRedistribute(Relation rel, RedisRelAction action, char *merge_list); +extern void AlterTableSetPartRelOptions( + Relation rel, List* defList, AlterTableType operation, LOCKMODE lockmode, char *merge_list, RedisRelAction action); +extern void RelationGetCtids(Relation rel, ItemPointer start_ctid, ItemPointer end_ctid); +extern uint32 RelationGetEndBlock(Relation rel); +extern void get_redis_rel_ctid( + const char* rel_name, const char* partition_name, RedisCtidType ctid_type, ItemPointer result); +#ifdef ENABLE_MULTIPLE_NODES +extern void CheckRedistributeOption(List* options, Oid* rel_cn_oid, + RedisHtlAction* action, char **merge_list, Relation rel); +#else +extern void CheckRedistributeOption(List* options, Oid* rel_cn_oid, + RedisHtlAction* action, Relation rel); +#endif + + +extern bool set_proc_redis(void); +extern bool reset_proc_redis(void); + +extern void RemoveRedisRelOptionsFromList(List** reloptions); +extern Node* eval_redis_func_direct(Relation rel, bool is_func_get_start_ctid, int num_of_slice = 0, int slice_index = 0); +extern List* add_ctid_string_to_reloptions(List *def_list, const char *item_name, ItemPointer ctid); +extern ItemPointer eval_redis_func_direct_slice(ItemPointer start_ctid, ItemPointer end_ctid, bool is_func_get_start_ctid, int num_of_slices, int slice_index); + +/* + * ItemPointerGetBlockNumber + * Returns the block number of a disk item pointer. + */ +#define RedisCtidGetBlockNumber(pointer) (AssertMacro((pointer) != NULL), BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetOffsetNumber + * Returns the offset number of a disk item pointer. + */ +#define RedisCtidGetOffsetNumber(pointer) (AssertMacro((pointer) != NULL), (pointer)->ip_posid) + +#endif /* REDISTRIB_H */ diff -uprN postgresql-hll-2.14_old/include/pgxc/remoteCombiner.h postgresql-hll-2.14/include/pgxc/remoteCombiner.h --- postgresql-hll-2.14_old/include/pgxc/remoteCombiner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/remoteCombiner.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,157 @@ + +#ifndef REMOTE_COMBINER_H +#define REMOTE_COMBINER_H + +#include "locator.h" +#include "nodes/nodes.h" +#include "pgxcnode.h" +#include "access/tupdesc.h" +#include "executor/tuptable.h" +#include "nodes/execnodes.h" +#include "nodes/parsenodes.h" +#include "nodes/pg_list.h" +#include "optimizer/pgxcplan.h" +#include "tcop/dest.h" +#include "tcop/pquery.h" +#include "tcop/utility.h" +#include "utils/lsyscache.h" +#include "utils/snapshot.h" +#include "utils/rowstore.h" + +typedef enum { + REQUEST_TYPE_NOT_DEFINED, /* not determined yet */ + REQUEST_TYPE_COMMAND, /* OK or row count response */ + REQUEST_TYPE_QUERY, /* Row description response */ + REQUEST_TYPE_COPY_IN, /* Copy In response */ + REQUEST_TYPE_COPY_OUT, /* Copy Out response */ + REQUEST_TYPE_COMMITING /* Commiting response */ +} RequestType; + +/* + * Type of requests associated to a remote COPY OUT + */ +typedef enum { + REMOTE_COPY_NONE, /* Not defined yet */ + REMOTE_COPY_STDOUT, /* Send back to client */ + REMOTE_COPY_FILE, /* Write in file */ + REMOTE_COPY_TUPLESTORE /* Store data in tuplestore */ +} RemoteCopyType; + +typedef struct NodeIdxInfo { + Oid nodeoid; + int nodeidx; +} NodeIdxInfo; + +typedef enum { + PBE_NONE = 0, /* no pbe or for initialization */ + PBE_ON_ONE_NODE, /* pbe running on one datanode for now */ + PBE_ON_MULTI_NODES /* pbe running on more than one datanode */ +} PBERunStatus; + +typedef struct ParallelFunctionState { + char* sql_statement; + ExecNodes* exec_nodes; + TupleDesc tupdesc; + Tuplestorestate* tupstore; + int64 result; + void* resultset; + MemoryContext slotmxct; + bool read_only; + bool need_tran_block; + /* if anyarray data received from remote nodes and need store in tuple, this flag shoud be true. + * because remote nodes use anyarry_out transform anyarray to string, so transform string to + * anyarray in local node is required */ + bool need_transform_anyarray; + /* this flag is for execute direct on multi nodes, if set this to true, executer will only get active + * nodes connections. */ + bool active_nodes_only; +} ParallelFunctionState; + +typedef bool (*fetchTupleFun)( + RemoteQueryState* combiner, TupleTableSlot* slot, ParallelFunctionState* parallelfunctionstate); + +typedef struct RemoteQueryState { + ScanState ss; /* its first field is NodeTag */ + int node_count; /* total count of participating nodes */ + PGXCNodeHandle** connections; /* Datanode connections being combined */ + int conn_count; /* count of active connections */ + int current_conn; /* used to balance load when reading from connections */ + CombineType combine_type; /* see CombineType enum */ + int command_complete_count; /* count of received CommandComplete messages */ + RequestType request_type; /* see RequestType enum */ + TupleDesc tuple_desc; /* tuple descriptor to be referenced by emitted tuples */ + int description_count; /* count of received RowDescription messages */ + int copy_in_count; /* count of received CopyIn messages */ + int copy_out_count; /* count of received CopyOut messages */ + int errorCode; /* error code to send back to client */ + char* errorMessage; /* error message to send back to client */ + char* errorDetail; /* error detail to send back to client */ + char* errorContext; /* error context to send back to client */ + char* hint; /* hint message to send back to client */ + char* query; /* query message to send back to client */ + int cursorpos; /* cursor index into query string */ + bool is_fatal_error; /* mark if it is a FATAL error */ + bool query_Done; /* query has been sent down to Datanodes */ + RemoteDataRowData currentRow; /* next data ro to be wrapped into a tuple */ + RowStoreManager row_store; /* buffer where rows are stored when connection + should be cleaned for reuse by other RemoteQuery*/ + /* + * To handle special case - if this RemoteQuery is feeding sorted data to + * Sort plan and if the connection fetching data from the Datanode + * is buffered. If EOF is reached on a connection it should be removed from + * the array, but we need to know node number of the connection to find + * messages in the buffer. So we store nodenum to that array if reach EOF + * when buffering + */ + int* tapenodes; + RemoteCopyType remoteCopyType; /* Type of remote COPY operation */ + FILE* copy_file; /* used if remoteCopyType == REMOTE_COPY_FILE */ + uint64 processed; /* count of data rows when running CopyOut */ + /* cursor support */ + char* cursor; /* cursor name */ + char* update_cursor; /* throw this cursor current tuple can be updated */ + int cursor_count; /* total count of participating nodes */ + PGXCNodeHandle** cursor_connections; /* Datanode connections being combined */ + /* Support for parameters */ + char* paramval_data; /* parameter data, format is like in BIND */ + int paramval_len; /* length of parameter values data */ + Oid* rqs_param_types; /* Types of the remote params */ + int rqs_num_params; + + int eflags; /* capability flags to pass to tuplestore */ + bool eof_underlying; /* reached end of underlying plan? */ + Tuplestorestate* tuplestorestate; + CommandId rqs_cmd_id; /* Cmd id to use in some special cases */ + uint64 rqs_processed; /* Number of rows processed (only for DMLs) */ + uint64 rqs_cur_processed; /* Number of rows processed for currently processed DN */ + + void* tuplesortstate; /* for merge tuplesort */ + void* batchsortstate; /* for merge batchsort */ + fetchTupleFun fetchTuple; + bool need_more_data; + RemoteErrorData remoteErrData; /* error data from remote */ + bool need_error_check; /* if need check other errors? */ + int64 analyze_totalrowcnt[ANALYZEDELTA]; /* save total row count received from dn under analyzing. */ + int64 analyze_memsize[ANALYZEDELTA]; /* save processed row count from dn under analyzing. */ + int valid_command_complete_count; /* count of valid complete count */ + + RemoteQueryType position; /* the position where the RemoteQuery node will run. */ + bool* switch_connection; /* mark if connection reused by other RemoteQuery */ + bool refresh_handles; + NodeIdxInfo* nodeidxinfo; + PBERunStatus pbe_run_status; /* record running status of a pbe remote query */ + + bool resource_error; /* true if error from the compute pool */ + char* previousNodeName; /* previous DataNode that rowcount is different from current DataNode */ + char* serializedPlan; /* the serialized plan tree */ + ParallelFunctionState* parallel_function_state; +} RemoteQueryState; + +extern RemoteQueryState* CreateResponseCombiner(int node_count, CombineType combine_type); +extern RemoteQueryState* CreateResponseCombinerForBarrier(int nodeCount, CombineType combineType); +extern bool validate_combiner(RemoteQueryState* combiner); +extern void CloseCombiner(RemoteQueryState* combiner); +extern void CloseCombinerForBarrier(RemoteQueryState* combiner); +extern bool ValidateAndCloseCombiner(RemoteQueryState* combiner); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/remotecopy.h postgresql-hll-2.14/include/pgxc/remotecopy.h --- postgresql-hll-2.14_old/include/pgxc/remotecopy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/remotecopy.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * remotecopy.h + * Routines for extension of COPY command for cluster management + * + * + * Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/pgxc/remotecopy.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REMOTECOPY_H +#define REMOTECOPY_H + +#include "nodes/parsenodes.h" +#include "commands/formatter.h" + +/* + * This contains the set of data necessary for remote COPY control. + */ +typedef struct RemoteCopyData { + /* COPY FROM/TO? */ + bool is_from; + + /* + * On Coordinator we need to rewrite query. + * While client may submit a copy command dealing with file, Datanodes + * always send/receive data to/from the Coordinator. So we can not use + * original statement and should rewrite statement, specifing STDIN/STDOUT + * as copy source or destination + */ + StringInfoData query_buf; + + /* Execution nodes for COPY */ + ExecNodes* exec_nodes; + + /* Locator information */ + RelationLocInfo* rel_loc; /* the locator key */ + List* idx_dist_by_col; /* index of the distributed by column */ + + PGXCNodeHandle** connections; /* Involved Datanode connections */ +} RemoteCopyData; + +/* + * List of all the options used for query deparse step + * As CopyStateData stays private in copy.c and in order not to + * make Postgres-XC code too much intrusive in PostgreSQL code, + * this intermediate structure is used primarily to generate remote + * COPY queries based on deparsed options. + */ +typedef struct RemoteCopyOptions { + bool rco_oids; /* include OIDs? */ + bool rco_freeze; + bool rco_without_escaping; + bool rco_ignore_extra_data; + char* rco_delim; /* column delimiter (must be 1 byte) */ + char* rco_null_print; /* NULL marker string (server encoding!) */ + char* rco_quote; /* CSV quote char (must be 1 byte) */ + char* rco_escape; /* CSV escape char (must be 1 byte) */ + char* rco_eol; /* user defined EOL string */ + List* rco_force_quote; /* list of column names */ + List* rco_force_notnull; /* list of column names */ + Formatter* rco_formatter; + FileFormat rco_format; + int rco_eol_type; + char* rco_date_format; /* customed date format */ + char* rco_time_format; /* customed time format */ + char* rco_timestamp_format; /* customed timestamp format */ + char* rco_smalldatetime_format; /* customed smalldatetime format */ + bool rco_compatible_illegal_chars; /* compatible illegal chars conversion flag */ + bool rco_fill_missing_fields; /* fill missing fields */ +} RemoteCopyOptions; + +extern void RemoteCopy_BuildStatement( + RemoteCopyData* state, Relation rel, RemoteCopyOptions* options, List* attnamelist, List* attnums); +extern void RemoteCopy_GetRelationLoc(RemoteCopyData* state, Relation rel, List* attnums); +extern RemoteCopyOptions* makeRemoteCopyOptions(void); +extern void FreeRemoteCopyData(RemoteCopyData* state); +extern void FreeRemoteCopyOptions(RemoteCopyOptions* options); +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/remoteHandler.h postgresql-hll-2.14/include/pgxc/remoteHandler.h --- postgresql-hll-2.14_old/include/pgxc/remoteHandler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/remoteHandler.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,11 @@ +#ifndef REMOTE_HANDLER_H +#define REMOTE_HANDLER_H + +#include "pgxcnode.h" +#include "executor/lightProxy.h" + +extern int light_handle_response(PGXCNodeHandle* conn, lightProxyMsgCtl* msgctl, lightProxy* lp); +extern void light_node_report_error(lightProxyErrData* combiner); +extern void HandleCmdComplete(CmdType commandType, CombineTag* combine, const char* msg_body, size_t len); + +#endif diff -uprN postgresql-hll-2.14_old/include/pgxc/route.h postgresql-hll-2.14/include/pgxc/route.h --- postgresql-hll-2.14_old/include/pgxc/route.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/pgxc/route.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,68 @@ +/*--------------------------------------------------------------------------------------- + * + * route.h + * + * route + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/executor/route.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef SENDROUTER_HEADER +#define SENDROUTER_HEADER + +#include "catalog/pg_type.h" +#include "postgres.h" +#include "utils/relcache.h" +#include "utils/guc.h" +#include "nodes/pg_list.h" +#include "pgxcnode.h" + +#define HAS_ROUTER (u_sess->attr.attr_common.enable_router && u_sess->exec_cxt.CurrentRouter != NULL && \ + IS_PGXC_COORDINATOR && IsConnFromApp()) +#define ENABLE_ROUTER(cmdtype) (HAS_ROUTER && ((cmdtype) == CMD_SELECT || (cmdtype) == CMD_UPDATE || \ + (cmdtype) == CMD_INSERT || (cmdtype) == CMD_DELETE || (cmdtype) == CMD_MERGE)) +#define ENABLE_ROUTER_DN (IS_PGXC_DATANODE && u_sess->attr.attr_common.enable_router \ + && u_sess->exec_cxt.is_dn_enable_router) + +extern bool check_router_attr(char** newval, void** extra, GucSource source); +extern void assign_router_attr(const char* newval, void* extra); + +typedef struct RouteMsg { + char* table_name; + List* key_vals; + int key_num; +} RouteMsg; + +class SendRouter : public BaseObject { +public: + SendRouter() + { + m_table_oid = InvalidOid; + m_node_id = -1; + }; + SendRouter(Oid table_oid, int node_id); + ~SendRouter() {}; +public: + static bool ParseRouterAttr(const char* newval, RouteMsg* attr); + static Oid GetRelationOid(const char* table_name); + static int CountNodeId(struct RouteMsg* attr); + int GetRouterNodeId(); + void Destory(); + +private: + Oid m_table_oid; + int m_node_id; +}; + + +#endif /* SENDROUTER_HEADER */ diff -uprN postgresql-hll-2.14_old/include/port/aix.h postgresql-hll-2.14/include/port/aix.h --- postgresql-hll-2.14_old/include/port/aix.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/aix.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,5 @@ +/* + * src/include/port/aix.h + */ +#define CLASS_CONFLICT +#define DISABLE_XOPEN_NLS diff -uprN postgresql-hll-2.14_old/include/port/cygwin.h postgresql-hll-2.14/include/port/cygwin.h --- postgresql-hll-2.14_old/include/port/cygwin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/cygwin.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,22 @@ +/* src/include/port/cygwin.h */ + +#include + +/* + * Check for b20.1 and disable AF_UNIX family socket support. + */ +#if CYGWIN_VERSION_DLL_MAJOR < 1001 +#undef HAVE_UNIX_SOCKETS +#endif + +#if __GNUC__ && !defined(__declspec) +#error You need egcs 1.1 or newer for compiling! +#endif + +#ifdef BUILDING_DLL +#define PGDLLIMPORT __declspec(dllexport) +#else +#define PGDLLIMPORT __declspec(dllimport) +#endif + +#define PGDLLEXPORT diff -uprN postgresql-hll-2.14_old/include/port/darwin.h postgresql-hll-2.14/include/port/darwin.h --- postgresql-hll-2.14_old/include/port/darwin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/darwin.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,12 @@ +/* src/include/port/darwin.h */ +#ifndef PORT_DARWIN_H +#define PORT_DARWIN_H + +#define __darwin__ 1 + +#if HAVE_DECL_F_FULLFSYNC /* not present before OS X 10.3 */ +#define HAVE_FSYNC_WRITETHROUGH + +#endif + +#endif /* PORT_DARWIN_H */ diff -uprN postgresql-hll-2.14_old/include/port/freebsd.h postgresql-hll-2.14/include/port/freebsd.h --- postgresql-hll-2.14_old/include/port/freebsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/freebsd.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/freebsd.h */ +#ifndef PORT_FREEBSD_H +#define PORT_FREEBSD_H + +#endif /* PORT_FREEBSD_H */ diff -uprN postgresql-hll-2.14_old/include/port/hpux.h postgresql-hll-2.14/include/port/hpux.h --- postgresql-hll-2.14_old/include/port/hpux.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/hpux.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/hpux.h */ +#ifndef PORT_HPUX_H +#define PORT_HPUX_H + +/* nothing needed */ +#endif /* PORT_HPUX_H */ + diff -uprN postgresql-hll-2.14_old/include/port/irix.h postgresql-hll-2.14/include/port/irix.h --- postgresql-hll-2.14_old/include/port/irix.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/irix.h 2020-12-12 17:06:43.358349471 +0800 @@ -0,0 +1,12 @@ +/* src/include/port/irix.h */ + +#ifndef PORT_IRIX_H +#define PORT_IRIX_H + +/* + * IRIX 6.5.26f and 6.5.22f (at least) have a strtod() that accepts + * "infinity", but leaves endptr pointing to "inity". + */ +#define HAVE_BUGGY_IRIX_STRTOD + +#endif /* PORT_IRIX_H */ diff -uprN postgresql-hll-2.14_old/include/port/linux.h postgresql-hll-2.14/include/port/linux.h --- postgresql-hll-2.14_old/include/port/linux.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/linux.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,26 @@ +/* src/include/port/linux.h */ + +/* + * As of July 2007, all known versions of the Linux kernel will sometimes + * return EIDRM for a shmctl() operation when EINVAL is correct (it happens + * when the low-order 15 bits of the supplied shm ID match the slot number + * assigned to a newer shmem segment). We deal with this by assuming that + * EIDRM means EINVAL in PGSharedMemoryIsInUse(). This is reasonably safe + * since in fact Linux has no excuse for ever returning EIDRM; it doesn't + * track removed segments in a way that would allow distinguishing them from + * private ones. But someday that code might get upgraded, and we'd have + * to have a kernel version test here. + */ +#ifndef LINUX_H +#define LINUX_H + +#define HAVE_LINUX_EIDRM_BUG + +/* + * Set the default wal_sync_method to fdatasync. With recent Linux versions, + * xlogdefs.h's normal rules will prefer open_datasync, which (a) doesn't + * perform better and (b) causes outright failures on ext4 data=journal + * filesystems, because those don't support O_DIRECT. + */ +#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC +#endif diff -uprN postgresql-hll-2.14_old/include/port/netbsd.h postgresql-hll-2.14/include/port/netbsd.h --- postgresql-hll-2.14_old/include/port/netbsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/netbsd.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/netbsd.h */ +#ifndef PORT_NETBSD_H +#define PORT_NETBSD_H + +#endif /* PORT_NETBSD_H */ diff -uprN postgresql-hll-2.14_old/include/port/openbsd.h postgresql-hll-2.14/include/port/openbsd.h --- postgresql-hll-2.14_old/include/port/openbsd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/openbsd.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/openbsd.h */ +#ifndef PORT_OPENBSD_H +#define PORT_OPENBSD_H + +#endif /* PORT_OPENBSD_H */ diff -uprN postgresql-hll-2.14_old/include/port/osf.h postgresql-hll-2.14/include/port/osf.h --- postgresql-hll-2.14_old/include/port/osf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/osf.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,4 @@ +/* src/include/port/osf.h */ + +#define NOFIXADE +#define DISABLE_XOPEN_NLS diff -uprN postgresql-hll-2.14_old/include/port/pg_bswap.h postgresql-hll-2.14/include/port/pg_bswap.h --- postgresql-hll-2.14_old/include/port/pg_bswap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/pg_bswap.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,65 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_bswap.h + * Byte swapping. + * + * Macros for reversing the byte order of 32-bit and 64-bit unsigned integers. + * For example, 0xAABBCCDD becomes 0xDDCCBBAA. These are just wrappers for + * built-in functions provided by the compiler where support exists. + * + * Note that the GCC built-in functions __builtin_bswap32() and + * __builtin_bswap64() are documented as accepting single arguments of type + * uint32_t and uint64_t respectively (these are also the respective return + * types). Use caution when using these wrapper macros with signed integers. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Copyright (c) 2015-2016, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/port/pg_bswap.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_BSWAP_H +#define PG_BSWAP_H + +#ifdef HAVE__BUILTIN_BSWAP32 +#define BSWAP32(x) __builtin_bswap32(x) +#else +#define BSWAP32(x) \ + (((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) | ((x >> 8) & 0x0000ff00) | ((x >> 24) & 0x000000ff)) +#endif /* HAVE__BUILTIN_BSWAP32 */ + +#ifdef HAVE__BUILTIN_BSWAP64 +#define BSWAP64(x) __builtin_bswap64(x) +#else +#define BSWAP64(x) \ + (((x << 56) & 0xff00000000000000UL) | ((x << 40) & 0x00ff000000000000UL) | ((x << 24) & 0x0000ff0000000000UL) | \ + ((x << 8) & 0x000000ff00000000UL) | ((x >> 8) & 0x00000000ff000000UL) | ((x >> 24) & 0x0000000000ff0000UL) | \ + ((x >> 40) & 0x000000000000ff00UL) | ((x >> 56) & 0x00000000000000ffUL)) +#endif /* HAVE__BUILTIN_BSWAP64 */ + +/* + * Rearrange the bytes of a Datum from big-endian order into the native byte + * order. On big-endian machines, this does nothing at all. Note that the C + * type Datum is an unsigned integer type on all platforms. + * + * One possible application of the DatumBigEndianToNative() macro is to make + * bitwise comparisons cheaper. A simple 3-way comparison of Datums + * transformed by the macro (based on native, unsigned comparisons) will return + * the same result as a memcmp() of the corresponding original Datums, but can + * be much cheaper. It's generally safe to do this on big-endian systems + * without any special transformation occurring first. + */ +#ifdef WORDS_BIGENDIAN +#define DatumBigEndianToNative(x) (x) +#else /* !WORDS_BIGENDIAN */ +#if SIZEOF_DATUM == 8 +#define DatumBigEndianToNative(x) BSWAP64(x) +#else /* SIZEOF_DATUM != 8 */ +#define DatumBigEndianToNative(x) BSWAP32(x) +#endif /* SIZEOF_DATUM == 8 */ +#endif /* WORDS_BIGENDIAN */ + +#endif /* PG_BSWAP_H */ diff -uprN postgresql-hll-2.14_old/include/port/pg_crc32c.h postgresql-hll-2.14/include/port/pg_crc32c.h --- postgresql-hll-2.14_old/include/port/pg_crc32c.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/pg_crc32c.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,103 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_crc32c.h + * Routines for computing CRC-32C checksums. + * + * The speed of CRC-32C calculation has a big impact on performance, so we + * jump through some hoops to get the best implementation for each + * platform. Some CPU architectures have special instructions for speeding + * up CRC calculations (e.g. Intel SSE 4.2), on other platforms we use the + * Slicing-by-8 algorithm which uses lookup tables. + * + * The public interface consists of four macros: + * + * INIT_CRC32C(crc) + * Initialize a CRC accumulator + * + * COMP_CRC32C(crc, data, len) + * Accumulate some (more) bytes into a CRC + * + * FIN_CRC32C(crc) + * Finish a CRC calculation + * + * EQ_CRC32C(c1, c2) + * Check for equality of two CRCs. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/port/pg_crc32c.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_CRC32C_H +#define PG_CRC32C_H + +#include "port/pg_bswap.h" + +typedef uint32 pg_crc32c; + +/* The INIT and EQ macros are the same for all implementations. */ +#define INIT_CRC32C(crc) ((crc) = 0xFFFFFFFF) +#define EQ_CRC32C(c1, c2) ((c1) == (c2)) + +#if defined(__aarch64__) && defined(__GNUC__) +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32 pg_crc32c_hardware(uint32 crc, const void* data, Size len); + +#ifdef __cplusplus +} +#endif + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC32C(crc, data, len) \ + do { \ + (crc) = pg_crc32c_hardware((uint32)(crc), (const void*)(data), (Size)(len)); \ + } while (0) + +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +#elif defined(USE_SSE42_CRC32C) +/* Use SSE4.2 instructions. */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c_sse42((crc), (data), (len))) +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void* data, size_t len); + +#elif defined(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK) +/* + * Use SSE4.2 instructions, but perform a runtime check first to check that + * they are available. + */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c((crc), (data), (len))) +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + +extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void* data, size_t len); +extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void* data, size_t len); +extern pg_crc32c (*pg_comp_crc32c)(pg_crc32c crc, const void* data, size_t len); + +#else +/* + * Use slicing-by-8 algorithm. + * + * On big-endian systems, the intermediate value is kept in reverse byte + * order, to avoid byte-swapping during the calculation. FIN_CRC32C reverses + * the bytes to the final order. + */ +#define COMP_CRC32C(crc, data, len) ((crc) = pg_comp_crc32c_sb8((crc), (data), (len))) +#ifdef WORDS_BIGENDIAN +#define FIN_CRC32C(crc) ((crc) = pg_bswap32(crc) ^ 0xFFFFFFFF) +#else +#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) +#endif + +extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void* data, size_t len); + +#endif + +#endif /* PG_CRC32C_H */ diff -uprN postgresql-hll-2.14_old/include/port/sco.h postgresql-hll-2.14/include/port/sco.h --- postgresql-hll-2.14_old/include/port/sco.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/sco.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,7 @@ +/* + * src/include/port/sco.h + * + * see src/backend/libpq/pqcomm.c */ +#define SCO_ACCEPT_BUG + +#define USE_UNIVEL_CC diff -uprN postgresql-hll-2.14_old/include/port/solaris.h postgresql-hll-2.14/include/port/solaris.h --- postgresql-hll-2.14_old/include/port/solaris.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/solaris.h 2020-12-12 17:06:43.359349483 +0800 @@ -0,0 +1,42 @@ +/* src/include/port/solaris.h */ + +/* + * Sort this out for all operating systems some time. The __xxx + * symbols are defined on both GCC and Solaris CC, although GCC + * doesn't document them. The __xxx__ symbols are only on GCC. + */ +#ifndef SRC_INCLUDE_PORT_SOLARIS_H +#define SRC_INCLUDE_PORT_SOLARIS_H +#if defined(__i386) && !defined(__i386__) +#define __i386__ +#endif + +#if defined(__amd64) && !defined(__amd64__) +#define __amd64__ +#endif + +#if defined(__x86_64) && !defined(__x86_64__) +#define __x86_64__ +#endif + +#if defined(__sparc) && !defined(__sparc__) +#define __sparc__ +#endif + +#if defined(__i386__) +#include +#endif + +/* + * Many versions of Solaris have broken strtod() --- see bug #4751182. + * This has been fixed in current versions of Solaris: + * + * http://sunsolve.sun.com/search/document.do?assetkey=1-21-108993-62-1&searchclause=108993-62 + * http://sunsolve.sun.com/search/document.do?assetkey=1-21-112874-34-1&searchclause=112874-34 + * + * However, many people might not have patched versions, so + * still use our own fix for the buggy version. + */ +#define HAVE_BUGGY_SOLARIS_STRTOD + +#endif // SRC_INCLUDE_PORT_SOLARIS_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/port/unixware.h postgresql-hll-2.14/include/port/unixware.h --- postgresql-hll-2.14_old/include/port/unixware.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/unixware.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,11 @@ +/* + * src/include/port/unixware.h + * + * see src/backend/libpq/pqcomm.c */ +#define SCO_ACCEPT_BUG + +/*************************************** + * Define this if you are compiling with + * the native UNIXWARE C compiler. + ***************************************/ +#define USE_UNIVEL_CC diff -uprN postgresql-hll-2.14_old/include/port/win32/arpa/inet.h postgresql-hll-2.14/include/port/win32/arpa/inet.h --- postgresql-hll-2.14_old/include/port/win32/arpa/inet.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/arpa/inet.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/win32/arpa/inet.h */ +#ifndef WIN32_ARPA_INET_H +#define WIN32_ARPA_INET_H + +#include + +#endif /* WIN32_ARPA_INET_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/dlfcn.h postgresql-hll-2.14/include/port/win32/dlfcn.h --- postgresql-hll-2.14_old/include/port/win32/dlfcn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/dlfcn.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/dlfcn.h */ +#ifndef PORT_WIN32_DLFCN_H +#define PORT_WIN32_DLFCN_H + +#endif /* PORT_WIN32_DLFCN_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/grp.h postgresql-hll-2.14/include/port/win32/grp.h --- postgresql-hll-2.14_old/include/port/win32/grp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/grp.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/grp.h */ +#ifndef PORT_WIN32_GRP_H +#define PORT_WIN32_GRP_H + +#endif /* PORT_WIN32_GRP_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/netdb.h postgresql-hll-2.14/include/port/win32/netdb.h --- postgresql-hll-2.14_old/include/port/win32/netdb.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/netdb.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32/netdb.h */ +#ifndef PORT_WIN32_NETDB_H +#define PORT_WIN32_NETDB_H + +#endif /* PORT_WIN32_NETDB_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/netinet/in.h postgresql-hll-2.14/include/port/win32/netinet/in.h --- postgresql-hll-2.14_old/include/port/win32/netinet/in.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/netinet/in.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,7 @@ +/* src/include/port/win32/netinet/in.h */ +#ifndef WIN32_NETINET_IN_H +#define WIN32_NETINET_IN_H + +#include + +#endif /* WIN32_NETINET_IN_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/pwd.h postgresql-hll-2.14/include/port/win32/pwd.h --- postgresql-hll-2.14_old/include/port/win32/pwd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/pwd.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,8 @@ +/* + * src/include/port/win32/pwd.h + */ + +#ifndef PORT_WIN32_PWD_H +#define PORT_WIN32_PWD_H + +#endif /* PORT_WIN32_PWD_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/sys/socket.h postgresql-hll-2.14/include/port/win32/sys/socket.h --- postgresql-hll-2.14_old/include/port/win32/sys/socket.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/sys/socket.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,33 @@ +/* + * src/include/port/win32/sys/socket.h + */ +#ifndef WIN32_SYS_SOCKET_H +#define WIN32_SYS_SOCKET_H + +/* + * Unfortunately, of VC++ also defines ERROR. + * To avoid the conflict, we include here and undefine ERROR + * immediately. + * + * Note: Don't include directly. It causes compile errors. + */ +#include +#include +#include + +#undef ERROR +#undef small + +/* Restore old ERROR value */ +#ifdef PGERROR +#define ERROR PGERROR +#endif + +/* + * we can't use the windows gai_strerror{AW} functions because + * they are defined inline in the MS header files. So we'll use our + * own + */ +#undef gai_strerror + +#endif /* WIN32_SYS_SOCKET_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32/sys/wait.h postgresql-hll-2.14/include/port/win32/sys/wait.h --- postgresql-hll-2.14_old/include/port/win32/sys/wait.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32/sys/wait.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,7 @@ +/* + * src/include/port/win32/sys/wait.h + */ +#ifndef PORT_WIN32SYS_WAIT_H +#define PORT_WIN32SYS_WAIT_H + +#endif /* PORT_WIN32SYS_WAIT_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32.h postgresql-hll-2.14/include/port/win32.h --- postgresql-hll-2.14_old/include/port/win32.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,468 @@ +/* src/include/port/win32.h */ + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define WIN32_ONLY_COMPILER +#endif + +/* + * Make sure _WIN32_WINNT has the minimum required value. + * Leave a higher value in place. + */ +#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501 +#undef _WIN32_WINNT +#endif +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif +/* + * Always build with SSPI support. Keep it as a #define in case + * we want a switch to disable it sometime in the future. + */ +#ifndef __BORLANDC__ +#define ENABLE_SSPI 1 +#endif + +/* undefine and redefine after #include */ +#undef mkdir + +#undef ERROR + +/* + * The Mingw64 headers choke if this is already defined - they + * define it themselves. + */ +#if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER) +#define _WINSOCKAPI_ +#endif +#include +#include +#include +#undef small +#include +#include +#include +#include +#ifndef __BORLANDC__ +#include /* for non-unicode version */ +#endif +#undef near + +/* Must be here to avoid conflicting with prototype in windows.h */ +#define mkdir(a, b) mkdir(a) + +#define ftruncate(a, b) chsize(a, b) + +/* Windows doesn't have fsync() as such, use _commit() */ +#define fsync(fd) _commit(fd) + +/* + * For historical reasons, we allow setting wal_sync_method to + * fsync_writethrough on Windows, even though it's really identical to fsync + * (both code paths wind up at _commit()). + */ +#define HAVE_FSYNC_WRITETHROUGH +#define FSYNC_WRITETHROUGH_IS_FSYNC + +#define USES_WINSOCK + +/* defines for dynamic linking on Win32 platform */ +#if defined(WIN32) || defined(__CYGWIN__) + +#if __GNUC__ && !defined(__declspec) +#error You need egcs 1.1 or newer for compiling! +#endif + +#ifdef BUILDING_DLL +#define PGDLLIMPORT __declspec(dllexport) +#else /* not BUILDING_DLL */ +#define PGDLLIMPORT __declspec(dllimport) +#endif + +#ifdef _MSC_VER +#define PGDLLEXPORT __declspec(dllexport) +#else +#define PGDLLEXPORT +#endif +#else /* not CYGWIN, not MSVC, not MingW */ +#define PGDLLIMPORT +#define PGDLLEXPORT +#endif + +/* + * IPC defines + */ +#undef HAVE_UNION_SEMUN +#define HAVE_UNION_SEMUN 1 + +#define IPC_RMID 256 +#define IPC_CREAT 512 +#define IPC_EXCL 1024 +#define IPC_PRIVATE 234564 +#define IPC_NOWAIT 2048 +#define IPC_STAT 4096 + +#define EACCESS 2048 +#ifndef EIDRM +#define EIDRM 4096 +#endif + +#define SETALL 8192 +#define GETNCNT 16384 +#define GETVAL 65536 +#define SETVAL 131072 +#define GETPID 262144 + +/* + * Signal stuff + * + * For WIN32, there is no wait() call so there are no wait() macros + * to interpret the return value of system(). Instead, system() + * return values < 0x100 are used for exit() termination, and higher + * values are used to indicated non-exit() termination, which is + * similar to a unix-style signal exit (think SIGSEGV == + * STATUS_ACCESS_VIOLATION). Return values are broken up into groups: + * + * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx + * + * NT_SUCCESS 0 - 0x3FFFFFFF + * NT_INFORMATION 0x40000000 - 0x7FFFFFFF + * NT_WARNING 0x80000000 - 0xBFFFFFFF + * NT_ERROR 0xC0000000 - 0xFFFFFFFF + * + * Effectively, we don't care on the severity of the return value from + * system(), we just need to know if it was because of exit() or generated + * by the system, and it seems values >= 0x100 are system-generated. + * See this URL for a list of WIN32 STATUS_* values: + * + * Wine (URL used in our error messages) - + * http://source.winehq.org/source/include/ntstatus.h + * Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt + * MS SDK - http://www.nologs.com/ntstatus.html + * + * It seems the exception lists are in both ntstatus.h and winnt.h, but + * ntstatus.h has a more comprehensive list, and it only contains + * exception values, rather than winnt, which contains lots of other + * things: + * + * http://www.microsoft.com/msj/0197/exception/exception.aspx + * + * The ExceptionCode parameter is the number that the operating system + * assigned to the exception. You can see a list of various exception codes + * in WINNT.H by searching for #defines that start with "STATUS_". For + * example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is + * 0xC0000005. A more complete set of exception codes can be found in + * NTSTATUS.H from the Windows NT DDK. + * + * Some day we might want to print descriptions for the most common + * exceptions, rather than printing an include file name. We could use + * RtlNtStatusToDosError() and pass to FormatMessage(), which can print + * the text of error values, but MinGW does not support + * RtlNtStatusToDosError(). + */ +#define WIFEXITED(w) (((w)&0XFFFFFF00) == 0) +#define WIFSIGNALED(w) (!WIFEXITED(w)) +#define WEXITSTATUS(w) (w) +#define WTERMSIG(w) (w) + +#define sigmask(sig) (1 << ((sig)-1)) + +/* Signal function return values */ +#undef SIG_DFL +#undef SIG_ERR +#undef SIG_IGN +#define SIG_DFL ((pqsigfunc)0) +#define SIG_ERR ((pqsigfunc)-1) +#define SIG_IGN ((pqsigfunc)1) + +/* Some extra signals */ +#define SIGHUP 1 +#define SIGQUIT 3 +#define SIGTRAP 5 +#define SIGABRT 22 /* Set to match W32 value -- not UNIX value */ +#define SIGKILL 9 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */ +#define SIGWINCH 28 +#ifndef __BORLANDC__ +#define SIGUSR1 30 +#define SIGUSR2 31 +#endif + +/* + * New versions of mingw have gettimeofday() and also declare + * struct timezone to support it. + */ +#ifndef HAVE_GETTIMEOFDAY +struct timezone { + int tz_minuteswest; /* Minutes west of GMT. */ + int tz_dsttime; /* Nonzero if DST is ever in effect. */ +}; +#endif + +/* for setitimer in backend/port/win32/timer.c */ +#define ITIMER_REAL 0 +struct itimerval { + struct timeval it_interval; + struct timeval it_value; +}; + +int setitimer(int which, const struct itimerval* value, struct itimerval* ovalue); + +/* + * WIN32 does not provide 64-bit off_t, but does provide the functions operating + * with 64-bit offsets. + */ +#define pgoff_t __int64 +#ifdef WIN32_ONLY_COMPILER +#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin) +#define ftello(stream) _ftelli64(stream) +#else +#ifndef fseeko +#define fseeko(stream, offset, origin) fseeko64(stream, offset, origin) +#endif +#ifndef ftello +#define ftello(stream) ftello64(stream) +#endif +#endif + +/* + * Supplement to . + * + * Perl already has typedefs for uid_t and gid_t. + */ +#ifndef PLPERL_HAVE_UID_GID +typedef int uid_t; +typedef int gid_t; +#endif +typedef long key_t; + +#ifdef WIN32_ONLY_COMPILER +typedef int pid_t; +#endif + +/* + * Supplement to . + */ +#define lstat(path, sb) stat((path), (sb)) + +/* + * Supplement to . + * This is the same value as _O_NOINHERIT in the MS header file. This is + * to ensure that we don't collide with a future definition. It means + * we cannot use _O_NOINHERIT ourselves. + */ +#define O_DSYNC 0x0080 + +/* + * Supplement to . + */ +#undef EAGAIN +#undef EINTR +#define EINTR WSAEINTR +#define EAGAIN WSAEWOULDBLOCK +#ifndef EMSGSIZE +#define EMSGSIZE WSAEMSGSIZE +#endif +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#ifndef EWOULDBLOCK +#define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef ECONNRESET +#define ECONNRESET WSAECONNRESET +#endif +#ifndef EINPROGRESS +#define EINPROGRESS WSAEINPROGRESS +#endif +#ifndef ENOBUFS +#define ENOBUFS WSAENOBUFS +#endif +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#endif +#ifndef ECONNREFUSED +#define ECONNREFUSED WSAECONNREFUSED +#endif +#ifndef EBADFD +#define EBADFD WSAENOTSOCK +#endif +#ifndef EOPNOTSUPP +#define EOPNOTSUPP WSAEOPNOTSUPP +#endif + +/* + * For Microsoft Visual Studio 2010 and above we intentionally redefine + * the regular Berkeley error constants and set them to the WSA constants. + * Note that this will break if those constants are used for anything else + * than Windows Sockets errors. + */ +#if _MSC_VER >= 1600 +#pragma warning(disable : 4005) +#define EMSGSIZE WSAEMSGSIZE +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ECONNRESET WSAECONNRESET +#define EINPROGRESS WSAEINPROGRESS +#define ENOBUFS WSAENOBUFS +#define ECONNREFUSED WSAECONNREFUSED +#define EOPNOTSUPP WSAEOPNOTSUPP +#pragma warning(default : 4005) +#endif + +/* + * Extended locale functions with gratuitous underscore prefixes. + * (These APIs are nevertheless fully documented by Microsoft.) + */ +#define locale_t _locale_t +#define tolower_l _tolower_l +#define toupper_l _toupper_l +#define towlower_l _towlower_l +#define towupper_l _towupper_l +#define isdigit_l _isdigit_l +#define iswdigit_l _iswdigit_l +#define isalpha_l _isalpha_l +#define iswalpha_l _iswalpha_l +#define isalnum_l _isalnum_l +#define iswalnum_l _iswalnum_l +#define isupper_l _isupper_l +#define iswupper_l _iswupper_l +#define islower_l _islower_l +#define iswlower_l _iswlower_l +#define isgraph_l _isgraph_l +#define iswgraph_l _iswgraph_l +#define isprint_l _isprint_l +#define iswprint_l _iswprint_l +#define ispunct_l _ispunct_l +#define iswpunct_l _iswpunct_l +#define isspace_l _isspace_l +#define iswspace_l _iswspace_l +#define strcoll_l _strcoll_l +#define wcscoll_l _wcscoll_l +#define wcstombs_l _wcstombs_l +#define mbstowcs_l _mbstowcs_l + +/* In backend/port/win32/signal.c */ +extern PGDLLIMPORT volatile int pg_signal_queue; +extern PGDLLIMPORT int pg_signal_mask; +extern HANDLE pgwin32_signal_event; +extern HANDLE pgwin32_initial_signal_pipe; + +#define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask) + +void pgwin32_signal_initialize(void); +HANDLE pgwin32_create_signal_listener(pid_t pid); +void pgwin32_dispatch_queued_signals(void); +void pg_queue_signal(int signum); + +/* In backend/port/win32/socket.c */ +#ifndef FRONTEND +#define socket(af, type, protocol) pgwin32_socket(af, type, protocol) +#define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen) +#define connect(s, name, namelen) pgwin32_connect(s, name, namelen) +#define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout) +#define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags) +#define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags) + +SOCKET pgwin32_socket(int af, int type, int protocol); +SOCKET pgwin32_accept(SOCKET s, struct sockaddr* addr, int* addrlen); +int pgwin32_connect(SOCKET s, const struct sockaddr* name, int namelen); +int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout); +int pgwin32_recv(SOCKET s, char* buf, int len, int flags); +int pgwin32_send(SOCKET s, const void* buf, int len, int flags); + +const char* pgwin32_socket_strerror(int err); +int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout); + +extern int pgwin32_noblock; + +/* in backend/port/win32/security.c */ +extern int pgwin32_is_admin(void); +extern int pgwin32_is_service(void); +#endif + +/* in backend/port/win32_shmem.c */ +extern int pgwin32_ReserveSharedMemoryRegion(HANDLE); + +/* in backend/port/win32/crashdump.c */ +extern void pgwin32_install_crashdump_handler(void); + +/* in port/win32error.c */ +extern void _dosmaperr(unsigned long); + +/* in port/win32env.c */ +extern int pgwin32_putenv(const char*); +extern void pgwin32_unsetenv(const char*); + +#define putenv(x) pgwin32_putenv(x) +#define unsetenv(x) pgwin32_unsetenv(x) + +/* Things that exist in MingW headers, but need to be added to MSVC & BCC */ +#ifdef WIN32_ONLY_COMPILER + +#ifndef _WIN64 +typedef long ssize_t; +#else +typedef __int64 ssize_t; +#endif + +#ifndef __BORLANDC__ +typedef unsigned short mode_t; + +#define S_IRUSR _S_IREAD +#define S_IWUSR _S_IWRITE +#define S_IXUSR _S_IEXEC +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +/* see also S_IRGRP etc below */ +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#endif /* __BORLANDC__ */ + +#define F_OK 0 +#define X_OK 1 /* test for execute or search permission */ +#define W_OK 2 +#define R_OK 4 + +#define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF)) +#define isnan(x) _isnan(x) + +/* Pulled from Makefile.port in mingw */ +#define DLSUFFIX ".dll" + +#ifdef __BORLANDC__ + +/* for port/dirent.c */ +#ifndef INVALID_FILE_ATTRIBUTES +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + +/* for port/open.c */ +#ifndef O_RANDOM +#define O_RANDOM 0x0010 /* File access is primarily random */ +#define O_SEQUENTIAL 0x0020 /* File access is primarily sequential */ +#define O_TEMPORARY 0x0040 /* Temporary file bit */ +#define O_SHORT_LIVED 0x1000 /* Temporary storage file, try not to flush */ +#define _O_SHORT_LIVED O_SHORT_LIVED +#endif /* ifndef O_RANDOM */ +#endif /* __BORLANDC__ */ +#endif /* WIN32_ONLY_COMPILER */ + +/* These aren't provided by either MingW or MSVC */ +#ifndef __BORLANDC__ +#define S_IRGRP 0 +#define S_IWGRP 0 +#define S_IXGRP 0 +#define S_IRWXG 0 +#define S_IROTH 0 +#define S_IWOTH 0 +#define S_IXOTH 0 +#define S_IRWXO 0 + +#endif /* __BORLANDC__ */ diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/dirent.h postgresql-hll-2.14/include/port/win32_msvc/dirent.h --- postgresql-hll-2.14_old/include/port/win32_msvc/dirent.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/dirent.h 2020-12-12 17:06:43.360349496 +0800 @@ -0,0 +1,27 @@ +/* + * Headers for port/dirent.c, win32 native implementation of dirent functions + * + * src/include/port/win32_msvc/dirent.h + */ + +#ifndef _WIN32VC_DIRENT_H +#define _WIN32VC_DIRENT_H + +#ifdef WIN32 +#define MAX_PATH 256 +#endif + +struct dirent { + long d_ino; + unsigned short d_reclen; + unsigned short d_namlen; + char d_name[MAX_PATH]; +}; + +typedef struct DIR DIR; + +DIR* opendir(const char*); +struct dirent* readdir(DIR*); +int closedir(DIR*); + +#endif diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/sys/file.h postgresql-hll-2.14/include/port/win32_msvc/sys/file.h --- postgresql-hll-2.14_old/include/port/win32_msvc/sys/file.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/sys/file.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/file.h */ +#ifndef PORT_32MSVC_SYS_FILE_H +#define PORT_32MSVC_SYS_FILE_H + +#endif /* PORT_32MSVC_SYS_FILE_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/sys/param.h postgresql-hll-2.14/include/port/win32_msvc/sys/param.h --- postgresql-hll-2.14_old/include/port/win32_msvc/sys/param.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/sys/param.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/param.h */ +#ifndef PORT_MSVC_SYS_PARAM_H +#define PORT_MSVC_SYS_PARAM_H + +#endif /* PORT_MSVC_SYS_PARAM_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/sys/time.h postgresql-hll-2.14/include/port/win32_msvc/sys/time.h --- postgresql-hll-2.14_old/include/port/win32_msvc/sys/time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/sys/time.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/sys/time.h */ +#ifndef PORT_32MSVC_SYS_TIME_H +#define PORT_32MSVC_SYS_TIME_H + +#endif /* PORT_32MSVC_SYS_TIME_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/unistd.h postgresql-hll-2.14/include/port/win32_msvc/unistd.h --- postgresql-hll-2.14_old/include/port/win32_msvc/unistd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/unistd.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/unistd.h */ +#ifndef PORT_32MSVC_UNISTD_H +#define PORT_32MSVC_UNISTD_H + +#endif /* PORT_32MSVC_UNISTD_H */ diff -uprN postgresql-hll-2.14_old/include/port/win32_msvc/utime.h postgresql-hll-2.14/include/port/win32_msvc/utime.h --- postgresql-hll-2.14_old/include/port/win32_msvc/utime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port/win32_msvc/utime.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,5 @@ +/* src/include/port/win32_msvc/utime.h */ +#ifndef PORT_32MSVC_UTIME_H +#define PORT_32MSVC_UTIME_H + +#endif /* PORT_32MSVC_UTIME_H */ diff -uprN postgresql-hll-2.14_old/include/portability/instr_time.h postgresql-hll-2.14/include/portability/instr_time.h --- postgresql-hll-2.14_old/include/portability/instr_time.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/portability/instr_time.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,154 @@ +/* ------------------------------------------------------------------------- + * + * instr_time.h + * portable high-precision interval timing + * + * This file provides an abstraction layer to hide portability issues in + * interval timing. On Unix we use gettimeofday(), but on Windows that + * gives a low-precision result so we must use QueryPerformanceCounter() + * instead. These macros also give some breathing room to use other + * high-precision-timing APIs on yet other platforms. + * + * The basic data type is instr_time, which all callers should treat as an + * opaque typedef. instr_time can store either an absolute time (of + * unspecified reference time) or an interval. The operations provided + * for it are: + * + * INSTR_TIME_IS_ZERO(t) is t equal to zero? + * + * INSTR_TIME_SET_ZERO(t) set t to zero (memset is acceptable too) + * + * INSTR_TIME_SET_CURRENT(t) set t to current time + * + * INSTR_TIME_ADD(x, y) x += y + * + * INSTR_TIME_SUBTRACT(x, y) x -= y + * + * INSTR_TIME_ACCUM_DIFF(x, y, z) x += (y - z) + * + * INSTR_TIME_GET_DOUBLE(t) convert t to double (in seconds) + * + * INSTR_TIME_GET_MILLISEC(t) convert t to double (in milliseconds) + * + * INSTR_TIME_GET_MICROSEC(t) convert t to uint64 (in microseconds) + * + * Note that INSTR_TIME_SUBTRACT and INSTR_TIME_ACCUM_DIFF convert + * absolute times to intervals. The INSTR_TIME_GET_xxx operations are + * only useful on intervals. + * + * When summing multiple measurements, it's recommended to leave the + * running sum in instr_time form (ie, use INSTR_TIME_ADD or + * INSTR_TIME_ACCUM_DIFF) and convert to a result format only at the end. + * + * Beware of multiple evaluations of the macro arguments. + * + * + * Copyright (c) 2001-2012, PostgreSQL Global Development Group + * + * src/include/portability/instr_time.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INSTR_TIME_H +#define INSTR_TIME_H + +#ifndef WIN32 + +#include + +typedef struct timeval instr_time; + +#define INSTR_TIME_IS_ZERO(t) ((t).tv_usec == 0 && (t).tv_sec == 0) + +#define INSTR_TIME_IS_INTMAX(t) ((t).tv_usec == LONG_MAX && (t).tv_sec == LONG_MAX) + +#define INSTR_TIME_INITIAL_MIN(t) ((t).tv_usec = LONG_MAX, (t).tv_sec = LONG_MAX) + +#define INSTR_TIME_IS_BIGGER(x, y) ((x).tv_sec >= (y).tv_sec && (x).tv_usec >= (y).tv_usec) + +#define INSTR_TIME_SET_ZERO(t) ((t).tv_sec = 0, (t).tv_usec = 0) + +#define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) + +#define INSTR_TIME_ADD(x, y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define INSTR_TIME_SUBTRACT(x, y) \ + do { \ + (x).tv_sec -= (y).tv_sec; \ + (x).tv_usec -= (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + } while (0) + +#define INSTR_TIME_ACCUM_DIFF(x, y, z) \ + do { \ + (x).tv_sec += (y).tv_sec - (z).tv_sec; \ + (x).tv_usec += (y).tv_usec - (z).tv_usec; \ + /* Normalize after each add to avoid overflow/underflow of tv_usec */ \ + while ((x).tv_usec < 0) { \ + (x).tv_usec += 1000000; \ + (x).tv_sec--; \ + } \ + while ((x).tv_usec >= 1000000) { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + +#define INSTR_TIME_GET_DOUBLE(t) (((double)(t).tv_sec) + ((double)(t).tv_usec) / 1000000.0) + +#define INSTR_TIME_GET_MILLISEC(t) (((double)(t).tv_sec * 1000.0) + ((double)(t).tv_usec) / 1000.0) + +#define INSTR_TIME_GET_MICROSEC(t) (((uint64)(t).tv_sec * (uint64)1000000) + (uint64)(t).tv_usec) +#else /* WIN32 */ + +typedef LARGE_INTEGER instr_time; + +#define INSTR_TIME_IS_ZERO(t) ((t).QuadPart == 0) + +#define INSTR_TIME_IS_INTMAX(t) ((t).QuadPart == LONG_MAX) + +#define INSTR_TIME_SET_ZERO(t) ((t).QuadPart = 0) + +#define INSTR_TIME_INITIAL_MAX(t) ((t).QuadPart = -1) + +#define INSTR_TIME_INITIAL_MIN(t) ((t).QuadPart = LONG_MAX) + +#define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t)) + +#define INSTR_TIME_ADD(x, y) ((x).QuadPart += (y).QuadPart) + +#define INSTR_TIME_IS_BIGGER(x, y) ((x).QuadPart >= (y).QuadPart) + +#define INSTR_TIME_SUBTRACT(x, y) ((x).QuadPart -= (y).QuadPart) + +#define INSTR_TIME_ACCUM_DIFF(x, y, z) ((x).QuadPart += (y).QuadPart - (z).QuadPart) + +#define INSTR_TIME_GET_DOUBLE(t) (((double)(t).QuadPart) / GetTimerFrequency()) + +#define INSTR_TIME_GET_MILLISEC(t) (((double)(t).QuadPart * 1000.0) / GetTimerFrequency()) + +#define INSTR_TIME_GET_MICROSEC(t) ((uint64)(((double)(t).QuadPart * 1000000.0) / GetTimerFrequency())) + +static inline double GetTimerFrequency(void) +{ + LARGE_INTEGER f; + + QueryPerformanceFrequency(&f); + return (double)f.QuadPart; +} +#endif /* WIN32 */ + +#endif /* INSTR_TIME_H */ diff -uprN postgresql-hll-2.14_old/include/port.h postgresql-hll-2.14/include/port.h --- postgresql-hll-2.14_old/include/port.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/port.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,431 @@ +/* ------------------------------------------------------------------------- + * + * port.h + * Header for src/port/ compatibility functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/port.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_PORT_H +#define PG_PORT_H + +#include +#include +#include +#include +#include +#include +#include "gs_threadlocal.h" + +/* socket has a different definition on WIN32 */ +#ifndef WIN32 +typedef int pgsocket; + +#define PGINVALID_SOCKET (-1) +#else +typedef SOCKET pgsocket; + +#define PGINVALID_SOCKET INVALID_SOCKET +#endif + +/* non-blocking */ +extern bool pg_set_noblock(pgsocket sock); +extern bool pg_set_block(pgsocket sock); + +/* Portable path handling for Unix/Win32 (in path.c) */ + +extern bool has_drive_prefix(const char* filename); +extern char* first_dir_separator(const char* filename); +extern char* last_dir_separator(const char* filename); +extern char* first_path_var_separator(const char* pathlist); +extern void join_path_components(char* ret_path, const char* head, const char* tail); +extern void canonicalize_path(char* path); +extern void make_native_path(char* path); +extern bool path_contains_parent_reference(const char* path); +extern bool path_is_relative_and_below_cwd(const char* path); +extern bool path_is_prefix_of_path(const char* path1, const char* path2); +extern const char* get_progname(const char* argv0); +extern void get_share_path(const char* my_exec_path, char* ret_path); +extern void get_etc_path(const char* my_exec_path, char* ret_path, size_t ret_path_len); +extern void get_include_path(const char* my_exec_path, char* ret_path); +extern void get_pkginclude_path(const char* my_exec_path, char* ret_path); +extern void get_includeserver_path(const char* my_exec_path, char* ret_path); +extern void get_lib_path(const char* my_exec_path, char* ret_path); +extern void get_pkglib_path(const char* my_exec_path, char* ret_path); +extern void get_locale_path(const char* my_exec_path, char* ret_path); +extern void get_doc_path(const char* my_exec_path, char* ret_path); +extern void get_html_path(const char* my_exec_path, char* ret_path); +extern void get_man_path(const char* my_exec_path, char* ret_path); +extern bool get_home_path(char* ret_path, size_t sz); +extern void get_parent_directory(char* path); +extern char* pg_strtolower(char* str); +extern int mask_single_passwd(char* passwd); + +/* port/dirmod.c */ +extern char** pgfnames(const char* path); +extern void pgfnames_cleanup(char** filenames); + +/* + * is_absolute_path + * + * By making this a macro we avoid needing to include path.c in libpq. + */ +#ifndef WIN32 +#define IS_DIR_SEP(ch) ((ch) == '/') + +#define is_absolute_path(filename) (IS_DIR_SEP((filename)[0])) +#else +#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\') + +/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */ +#define is_absolute_path(filename) \ + (IS_DIR_SEP((filename)[0]) || \ + (isalpha((unsigned char)((filename)[0])) && (filename)[1] == ':' && IS_DIR_SEP((filename)[2]))) +#endif + +/* Portable locale initialization (in exec.c) */ +extern void set_pglocale_pgservice(const char* argv0, const char* app); + +/* Portable way to find binaries (in exec.c) */ +extern int find_my_exec(const char* argv0, char* retpath); +extern int find_other_exec(const char* argv0, const char* target, const char* versionstr, char* retpath); + +/* Windows security token manipulation (in exec.c) */ +#ifdef WIN32 +extern BOOL AddUserToTokenDacl(HANDLE hToken); +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +#define EXE ".exe" +#else +#define EXE "" +#endif + +#if defined(WIN32) && !defined(__CYGWIN__) +#define DEVNULL "nul" +#else +#define DEVNULL "/dev/null" +#endif + +/* + * Win32 needs double quotes at the beginning and end of system() + * strings. If not, it gets confused with multiple quoted strings. + * It also requires double-quotes around the executable name and + * any files used for redirection. Other args can use single-quotes. + * + * Generated using Win32 "CMD /?": + * + * 1. If all of the following conditions are met, then quote characters + * on the command line are preserved: + * + * - no /S switch + * - exactly two quote characters + * - no special characters between the two quote characters, where special + * is one of: &<>()@^| + * - there are one or more whitespace characters between the two quote + * characters + * - the string between the two quote characters is the name of an + * executable file. + * + * 2. Otherwise, old behavior is to see if the first character is a quote + * character and if so, strip the leading character and remove the last + * quote character on the command line, preserving any text after the last + * quote character. + */ +#if defined(WIN32) && !defined(__CYGWIN__) +#define SYSTEMQUOTE "\"" +#else +#define SYSTEMQUOTE "" +#endif + +/* Portable delay handling */ +extern void pg_usleep(long microsec); +extern void pg_usleep_retry(long microsec, int retry_times); + +/* Portable SQL-like case-independent comparisons and conversions */ +extern int pg_strcasecmp(const char* s1, const char* s2); +extern int pg_strncasecmp(const char* s1, const char* s2, size_t n); +extern unsigned char pg_toupper(unsigned char ch); +extern unsigned char pg_tolower(unsigned char ch); +extern unsigned char pg_ascii_toupper(unsigned char ch); +extern unsigned char pg_ascii_tolower(unsigned char ch); +#ifndef WIN32 +extern bool IsMyPostmasterPid(pid_t pid, const char* data); +#endif + +#if defined(WIN32) +/* + * Versions of libintl >= 0.18? try to replace setlocale() with a macro + * to their own versions. Remove the macro, if it exists, because it + * ends up calling the wrong version when the backend and libintl use + * different versions of msvcrt. + */ +#if defined(setlocale) +#undef setlocale +#endif + +/* + * Define our own wrapper macro around setlocale() to work around bugs in + * Windows' native setlocale() function. + */ +extern char* pgwin32_setlocale(int category, const char* locale); + +#define setlocale(a, b) pgwin32_setlocale(a, b) +#endif /* WIN32 */ + +/* Portable prompt handling */ +extern char* simple_prompt(const char* prompt, int maxlen, bool echo); + +#ifdef WIN32 +#define PG_SIGNAL_COUNT 32 +#define kill(pid, sig) pgkill(pid, sig) +extern int pgkill(int pid, int sig); +#endif + +extern int pclose_check(FILE* stream); + +/* Global variable holding time zone information. */ +#ifndef __CYGWIN__ +#define TIMEZONE_GLOBAL timezone +#define TZNAME_GLOBAL tzname +#else +#define TIMEZONE_GLOBAL _timezone +#define TZNAME_GLOBAL _tzname +#endif + +#if defined(WIN32) || defined(__CYGWIN__) +/* + * Win32 doesn't have reliable rename/unlink during concurrent access. + */ +extern int pgrename(const char* from, const char* to); +extern int pgunlink(const char* path); + +/* Include this first so later includes don't see these defines */ +#ifdef WIN32_ONLY_COMPILER +#include +#endif + +#define rename(from, to) pgrename(from, to) +#define unlink(path) pgunlink(path) +#endif /* defined(WIN32) || defined(__CYGWIN__) */ + +/* + * Win32 also doesn't have symlinks, but we can emulate them with + * junction points on newer Win32 versions. + * + * Cygwin has its own symlinks which work on Win95/98/ME where + * junction points don't, so use those instead. We have no way of + * knowing what type of system Cygwin binaries will be run on. + * Note: Some CYGWIN includes might #define WIN32. + */ +#if defined(WIN32) && !defined(__CYGWIN__) +extern int pgreadlink(const char* path, char* buf, size_t size); +extern bool pgwin32_is_junction(char* path); + +#define readlink(path, buf, size) pgreadlink(path, buf, size) +#endif + +extern bool rmtree(const char* path, bool rmtopdir, bool noent_ok = false); + +/* + * stat() is not guaranteed to set the st_size field on win32, so we + * redefine it to our own implementation that is. + * + * We must pull in sys/stat.h here so the system header definition + * goes in first, and we redefine that, and not the other way around. + * + * Some frontends don't need the size from stat, so if UNSAFE_STAT_OK + * is defined we don't bother with this. + */ +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK) +#include +extern int pgwin32_safestat(const char* path, struct stat* buf); + +#define stat(a, b) pgwin32_safestat(a, b) +#endif + +#if defined(WIN32) && !defined(__CYGWIN__) + +/* + * open() and fopen() replacements to allow deletion of open files and + * passing of other special options. + */ +#define O_DIRECT 0x80000000 +extern int pgwin32_open(const char*, int, ...); +extern FILE* pgwin32_fopen(const char*, const char*); + +#ifndef FRONTEND +#define open(a, b, c) pgwin32_open(a, b, c) +#define fopen(a, b) pgwin32_fopen(a, b) +#endif + +#ifndef popen +#define popen(a, b) _popen(a, b) +#endif +#ifndef pclose +#define pclose(a) _pclose(a) +#endif + +/* New versions of MingW have gettimeofday, old mingw and msvc don't */ +#ifndef HAVE_GETTIMEOFDAY +/* Last parameter not used */ +extern int gettimeofday(struct timeval* tp, struct timezone* tzp); +#endif +#else /* !WIN32 */ + +/* + * Win32 requires a special close for sockets and pipes, while on Unix + * close() does them all. + */ +#define closesocket close +#endif /* WIN32 */ + +/* + * Default "extern" declarations or macro substitutes for library routines. + * When necessary, these routines are provided by files in src/port/. + */ +#ifndef HAVE_CRYPT +extern char* crypt(const char* key, const char* setting); +#endif + +/* WIN32 handled in port/win32.h */ +#ifndef WIN32 +#define pgoff_t off_t +#ifdef __NetBSD__ +extern int fseeko(FILE* stream, off_t offset, int whence); +extern off_t ftello(FILE* stream); +#endif +#endif + +extern double pg_erand48(unsigned short xseed[3]); +extern long pg_lrand48(void); +extern void pg_srand48(long seed); +extern long free_list_lrand48(void); +extern void free_list_srand48(long seed); +extern void pg_reset_srand48(unsigned short xseed[3]); +extern unsigned short* pg_get_srand48(); + +#ifndef HAVE_FLS +extern int fls(int mask); +#endif + +#ifndef HAVE_FSEEKO +#define fseeko(a, b, c) fseek(a, b, c) +#define ftello(a) ftell(a) +#endif + +#ifndef HAVE_GETOPT +extern int getopt(int nargc, char* const* nargv, const char* ostr); +#endif + +#if !defined(HAVE_GETPEEREID) && !defined(WIN32) +extern int getpeereid(int sock, uid_t* uid, gid_t* gid); +#endif + +#ifndef HAVE_ISINF +extern int isinf(double x); +#endif + +#ifndef HAVE_RINT +extern double rint(double x); +#endif + +#ifndef HAVE_INET_ATON +#include +#include +extern int inet_aton(const char* cp, struct in_addr* addr); +#endif + +#if !HAVE_DECL_STRLCAT +extern size_t strlcat(char* dst, const char* src, size_t siz); +#endif + +#if !HAVE_DECL_STRLCPY +extern size_t strlcpy(char* dst, const char* src, size_t siz); +#endif + +#if !defined(HAVE_RANDOM) && !defined(__BORLANDC__) +extern long random(void); +#endif + +#ifndef HAVE_UNSETENV +extern void unsetenv(const char* name); +#endif + +#ifndef HAVE_SRANDOM +extern void srandom(unsigned int seed); +#endif + +#define gs_random() pg_lrand48() +#define gs_srandom(seed) pg_srand48((long int)(seed)) + + +/* thread.h */ +extern char* pqStrerror(int errnum, char* strerrbuf, size_t buflen); + +#if !defined(WIN32) || defined(__CYGWIN__) +extern int pqGetpwuid(uid_t uid, struct passwd* resultbuf, char* buffer, size_t buflen, struct passwd** result); +#endif + +extern int pqGethostbyname( + const char* name, struct hostent* resultbuf, char* buffer, size_t buflen, struct hostent** result, int* herrno); + +extern void pg_qsort(void* base, size_t nel, size_t elsize, int (*cmp)(const void*, const void*)); + +#define qsort(a, b, c, d) pg_qsort(a, b, c, d) + +typedef int (*qsort_arg_comparator)(const void* a, const void* b, void* arg); + +extern void qsort_arg(void* base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void* arg); + +/* port/chklocale.c */ +extern int pg_get_encoding_from_locale(const char* ctype, bool write_message); + +/* port/inet_net_ntop.c */ + +/* port/pgcheckdir.c */ +extern int pg_check_dir(const char* dir); + +/* port/pgmkdirp.c */ +extern int pg_mkdir_p(char* path, int omode); +extern int pg_mkdir_p_used_by_gaussdb(char* path, int omode); + +typedef struct OptParseContext { + char* place; + int opterr; + int optind; + int optopt; + char* optarg; +} OptParseContext; + +extern void initOptParseContext(OptParseContext* pOptCtxt); +extern int getopt_r(int nargc, char* const* nargv, const char* ostr, OptParseContext* pOptArgs); + +/* port/gs_system.c */ +extern int gs_system(const char* command); + +/* port/gs_system_security */ +extern int gs_system_security(const char* command); +extern FILE* popen_security(const char* command, char type); +extern int pclose_security(FILE* fp); +extern int gs_popen_security(const char* command); + +/* port/gs_strerror.c */ + +extern THR_LOCAL char gs_error_buf[]; +extern char* gs_strerror(int errnum); + +/* port/gs_readdir.c */ + +extern THR_LOCAL char gs_dir_buf[]; +extern struct dirent* gs_readdir(DIR* dir); + +/*env thread safe version*/ +extern int gs_putenv_r(char* envvar); +extern char* gs_getenv_r(const char* name); + +#endif /* PG_PORT_H */ diff -uprN postgresql-hll-2.14_old/include/postgres_ext.h postgresql-hll-2.14/include/postgres_ext.h --- postgresql-hll-2.14_old/include/postgres_ext.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postgres_ext.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * postgres_ext.h + * + * This file contains declarations of things that are visible everywhere + * in PostgreSQL *and* are visible to clients of frontend interface libraries. + * For example, the Oid type is part of the API of libpq and other libraries. + * + * Declarations which are specific to a particular interface should + * go in the header file for that interface (such as libpq-fe.h). This + * file is only for fundamental Postgres declarations. + * + * User-written C functions don't count as "external to Postgres." + * Those function much as local modifications to the backend itself, and + * use header files that are otherwise internal to Postgres to interface + * with the backend. + * + * src/include/postgres_ext.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef POSTGRES_EXT_H +#define POSTGRES_EXT_H + +#include "gs_thread.h" +/* + * Object ID is a fundamental type in Postgres. + */ +typedef unsigned int Oid; + +#ifdef __cplusplus +#define InvalidOid (Oid(0)) +#else +#define InvalidOid ((Oid)0) +#endif + +#define VirtualBktOid (Oid(1)) +#define InvalidBktId (-1) + +#define DIR_BUCKET_ID (-2) // relfilenode points to a bucket dir +#define BUCKET_ID_IS_DIR(bucket_node) ((bucket_node) == DIR_BUCKET_ID) +#define BUCKET_NODE_IS_VALID(bucket_node) ((bucket_node) > InvalidBktId) + +#define OID_MAX UINT_MAX + +/* you will need to include to use the above #define */ + +/* + * Identifiers of error message fields. Kept here to keep common + * between frontend and backend, and also to export them to libpq + * applications. + */ +#define PG_DIAG_SEVERITY 'S' +#define PG_DIAG_SQLSTATE 'C' +#define PG_DIAG_INTERNEL_ERRCODE 'c' +#define PG_DIAG_MESSAGE_PRIMARY 'M' +#define PG_DIAG_MESSAGE_DETAIL 'D' +#define PG_DIAG_MESSAGE_HINT 'H' +#define PG_DIAG_STATEMENT_POSITION 'P' +#define PG_DIAG_INTERNAL_POSITION 'p' +#define PG_DIAG_INTERNAL_QUERY 'q' +#define PG_DIAG_CONTEXT 'W' +#define PG_DIAG_SOURCE_FILE 'F' +#define PG_DIAG_SOURCE_LINE 'L' +#define PG_DIAG_SOURCE_FUNCTION 'R' +#define PG_DIAG_MESSAGE_ONLY 'm' +#define PG_DIAG_MODULE_ID 'd' + +#endif diff -uprN postgresql-hll-2.14_old/include/postgres_fe.h postgresql-hll-2.14/include/postgres_fe.h --- postgresql-hll-2.14_old/include/postgres_fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postgres_fe.h 2020-12-12 17:06:43.361349509 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * postgres_fe.h + * Primary include file for PostgreSQL client-side .c files + * + * This should be the first file included by PostgreSQL client libraries and + * application programs --- but not by backend modules, which should include + * postgres.h. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1995, Regents of the University of California + * + * src/include/postgres_fe.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POSTGRES_FE_H +#define POSTGRES_FE_H + +#ifndef FRONTEND +#define FRONTEND 1 +#endif + +#include "c.h" +#include "securec.h" +#include "securec_check.h" +#include + +#ifndef Assert +#ifndef USE_ASSERT_CHECKING +#define Assert(p) +#else +#define Assert(p) assert(p) +#endif /* USE_ASSERT_CHECKING */ +#endif /* Assert */ + + +#ifndef AssertMacro +#define AssertMacro Assert +#endif + +#ifndef BoolGetDatum +#define BoolGetDatum(X) /*lint -e506*/ ((Datum)((X) ? 1 : 0)) /*lint +e506*/ +#endif + +#ifndef PointerGetDatum +#define PointerGetDatum(X) ((Datum)(X)) +#endif + +#ifndef HAVE_DATABASE_TYPE +#define HAVE_DATABASE_TYPE +/* Type of database; increase for sql compatibility */ +typedef enum { + ORA_FORMAT, + TD_FORMAT +} DatabaseType; +#endif // HAVE_DATABASE_TYPE + +#endif /* POSTGRES_FE_H */ diff -uprN postgresql-hll-2.14_old/include/postgres.h postgresql-hll-2.14/include/postgres.h --- postgresql-hll-2.14_old/include/postgres.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postgres.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,914 @@ +/* ------------------------------------------------------------------------- + * + * postgres.h + * Primary include file for PostgreSQL server .c files + * + * This should be the first file included by PostgreSQL backend modules. + * Client-side code should include postgres_fe.h instead. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1995, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/postgres.h + * + * ------------------------------------------------------------------------- + */ +/* + * ---------------------------------------------------------------- + * TABLE OF CONTENTS + * + * When adding stuff to this file, please try to put stuff + * into the relevant section, or add new sections as appropriate. + * + * section description + * ------- ------------------------------------------------ + * 1) variable-length datatypes (TOAST support) + * 2) datum type + support macros + * 3) exception handling definitions + * + * NOTES + * + * In general, this file should contain declarations that are widely needed + * in the backend environment, but are of no interest outside the backend. + * + * Simple type definitions live in c.h, where they are shared with + * postgres_fe.h. We do that since those type definitions are needed by + * frontend modules that want to deal with binary data transmission to or + * from the backend. Type definitions in this file should be for + * representations that never escape the backend, such as Datum or + * TOASTed varlena objects. + * + * ---------------------------------------------------------------- + */ +#ifndef POSTGRES_H +#define POSTGRES_H + +#ifdef PC_LINT +#define THR_LOCAL +#endif + +#include "c.h" +#include "utils/elog.h" +#include "utils/palloc.h" +#include "storage/spin.h" + +#ifndef WIN32 +#include +#endif /* win-odbc */ + +#ifndef HDFS_FDW +#define HDFS_FDW "hdfs_fdw" +#endif + +#ifndef HDFS +#define HDFS "hdfs" +#endif + +#ifndef OBS +#define OBS "obs" +#endif + +#ifndef DIST_FDW +#define DIST_FDW "dist_fdw" +#endif + +#ifndef MYSQL_FDW +#define MYSQL_FDW "mysql_fdw" +#endif + +#ifndef ORACLE_FDW +#define ORACLE_FDW "oracle_fdw" +#endif + +#ifndef POSTGRES_FDW +#define POSTGRES_FDW "postgres_fdw" +#endif + +#ifndef MOT_FDW +#define MOT_FDW "mot_fdw" +#endif + +#ifndef MOT_FDW_SERVER +#define MOT_FDW_SERVER "mot_server" +#endif + +#ifndef DFS_FDW +#define DFS_FDW "dfs_fdw" +#endif + +#ifndef LOG_FDW +#define LOG_FDW "log_fdw" +#define LOG_SRV "log_srv" +#endif /* LOG_FDW */ + +#ifndef GC_FDW +#define GC_FDW "gc_fdw" +#endif + +#include "securec.h" +#include "securec_check.h" + +#define AUXILIARY_BACKENDS 20 +/* the maximum number of autovacuum launcher thread */ +#define AV_LAUNCHER_PROCS 2 + +#define STREAM_RESERVE_PROC_TIMES (16) +/* this struct is used to store connection info got from pool */ +typedef struct { + /* hostname of the connection */ + nameData host; + /* port of the connection */ + int port; +} PoolConnInfo; + +/* this enum type is used to mark om online operation. */ +typedef enum { OM_ONLINE_EXPANSION, OM_ONLINE_NODE_REPLACE } OM_ONLINE_STATE; + +extern void reload_configfile(void); +extern void reload_online_pooler(void); +extern OM_ONLINE_STATE get_om_online_state(void); + +/* ---------------------------------------------------------------- + * Section 1: variable-length datatypes (TOAST support) + * ---------------------------------------------------------------- + */ + +/* + * struct varatt_external is a "TOAST pointer", that is, the information + * needed to fetch a stored-out-of-line Datum. The data is compressed + * if and only if va_extsize < va_rawsize - VARHDRSZ. This struct must not + * contain any padding, because we sometimes compare pointers using memcmp. + * + * Note that this information is stored unaligned within actual tuples, so + * you need to memcpy from the tuple into a local struct variable before + * you can look at these fields! (The reason we use memcmp is to avoid + * having to do that just to detect equality of two TOAST pointers...) + */ +typedef struct varatt_external { + int32 va_rawsize; /* Original data size (includes header) */ + int32 va_extsize; /* External saved size (doesn't) */ + Oid va_valueid; /* Unique ID of value within TOAST table */ + Oid va_toastrelid; /* RelID of TOAST table containing it */ +} varatt_external; + +/* + * Out-of-line Datum thats stored in memory in contrast to varatt_external + * pointers which points to data in an external toast relation. + * + * Note that just as varatt_external's this is stored unaligned within the + * tuple. + */ +typedef struct varatt_indirect { + struct varlena* pointer; /* Pointer to in-memory varlena */ +} varatt_indirect; + +/* + * Type of external toast datum stored. The peculiar value for VARTAG_ONDISK + * comes from the requirement for on-disk compatibility with the older + * definitions of varattrib_1b_e where v_tag was named va_len_1be... + */ +typedef enum vartag_external { VARTAG_INDIRECT = 1, VARTAG_BUCKET = 8, VARTAG_ONDISK = 18 } vartag_external; + +#define VARTAG_SIZE(tag) \ + ((tag) == VARTAG_INDIRECT ? sizeof(varatt_indirect) : \ + (tag) == VARTAG_ONDISK ? sizeof(varatt_external) : \ + (tag) == VARTAG_BUCKET ? sizeof(varatt_external) + sizeof(int2) : \ + TrapMacro(true, "unknown vartag")) + +/* + * These structs describe the header of a varlena object that may have been + * TOASTed. Generally, don't reference these structs directly, but use the + * macros below. + * + * We use separate structs for the aligned and unaligned cases because the + * compiler might otherwise think it could generate code that assumes + * alignment while touching fields of a 1-byte-header varlena. + */ +typedef union { + struct /* Normal varlena (4-byte length) */ + { + uint32 va_header; + char va_data[FLEXIBLE_ARRAY_MEMBER]; + } va_4byte; + struct /* Compressed-in-line format */ + { + uint32 va_header; + uint32 va_rawsize; /* Original data size (excludes header) */ + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Compressed data */ + } va_compressed; +} varattrib_4b; + +typedef struct { + uint8 va_header; + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Data begins here */ +} varattrib_1b; + +#define TRY_LOCK_ACCOUNT 0 +#define TRY_UNLOCK_ACCOUNT 1 +#define MAX_USER_NUM 100 +typedef struct accounttask { + Oid roleid; + int failedcount; +} AccountTask; + +/* inline portion of a short varlena pointing to an external resource */ +typedef struct { + uint8 va_header; /* Always 0x80 or 0x01 */ + uint8 va_tag; /* Type of datum */ + char va_data[FLEXIBLE_ARRAY_MEMBER]; /* Type-specific data */ +} varattrib_1b_e; + +#ifndef HAVE_DATABASE_TYPE +#define HAVE_DATABASE_TYPE +/*Type of database; increase for sql compatibility*/ +typedef enum { A_FORMAT, B_FORMAT, C_FORMAT } DatabaseType; +#endif /* HAVE_DATABASE_TYPE */ + +typedef enum { EXPLAIN_NORMAL, EXPLAIN_PRETTY, EXPLAIN_SUMMARY, EXPLAIN_RUN } ExplainStyle; + +typedef enum { SKEW_OPT_OFF, SKEW_OPT_NORMAL, SKEW_OPT_LAZY } SkewStrategy; + +typedef enum { RESOURCE_TRACK_NONE, RESOURCE_TRACK_QUERY, RESOURCE_TRACK_OPERATOR } ResourceTrackOption; + +typedef enum { + CODEGEN_PARTIAL, /* allow to call c-function in codegen */ + CODEGEN_PURE /* do not allow to call c-function in codegen */ +} CodegenStrategy; + +typedef enum { + MEMORY_TRACKING_NONE, /* not to track the memory usage */ + MEMORY_TRACKING_NORMAL, /* just update the peak information internal */ + MEMORY_TRACKING_EXECUTOR, /* to logging the memory information in executor */ + MEMORY_TRACKING_FULLEXEC /* to logging the all memory context information in executor */ +} MemoryTrackingStyle; + +/* + * Bit layouts for varlena headers on big-endian machines: + * + * 00xxxxxx 4-byte length word, aligned, uncompressed data (up to 1G) + * 01xxxxxx 4-byte length word, aligned, *compressed* data (up to 1G) + * 10000000 1-byte length word, unaligned, TOAST pointer + * 1xxxxxxx 1-byte length word, unaligned, uncompressed data (up to 126b) + * + * Bit layouts for varlena headers on little-endian machines: + * + * xxxxxx00 4-byte length word, aligned, uncompressed data (up to 1G) + * xxxxxx10 4-byte length word, aligned, *compressed* data (up to 1G) + * 00000001 1-byte length word, unaligned, TOAST pointer + * xxxxxxx1 1-byte length word, unaligned, uncompressed data (up to 126b) + * + * The "xxx" bits are the length field (which includes itself in all cases). + * In the big-endian case we mask to extract the length, in the little-endian + * case we shift. Note that in both cases the flag bits are in the physically + * first byte. Also, it is not possible for a 1-byte length word to be zero; + * this lets us disambiguate alignment padding bytes from the start of an + * unaligned datum. (We now *require* pad bytes to be filled with zero!) + */ + +/* + * Endian-dependent macros. These are considered internal --- use the + * external macros below instead of using these directly. + * + * Note: IS_1B is true for external toast records but VARSIZE_1B will return 0 + * for such records. Hence you should usually check for IS_EXTERNAL before + * checking for IS_1B. + */ + +#ifdef WORDS_BIGENDIAN + +#define VARATT_IS_4B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x80) == 0x00) +#define VARATT_IS_4B_U(PTR) ((((varattrib_1b*)(PTR))->va_header & 0xC0) == 0x00) +#define VARATT_IS_4B_C(PTR) ((((varattrib_1b*)(PTR))->va_header & 0xC0) == 0x40) +#define VARATT_IS_1B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x80) == 0x80) +#define VARATT_IS_1B_E(PTR) ((((varattrib_1b*)(PTR))->va_header) == 0x80) +#define VARATT_NOT_PAD_BYTE(PTR) (*((uint8*)(PTR)) != 0) + +/* VARSIZE_4B() should only be used on known-aligned data */ +#define VARSIZE_4B(PTR) (((varattrib_4b*)(PTR))->va_4byte.va_header & 0x3FFFFFFF) +#define VARSIZE_1B(PTR) (((varattrib_1b*)(PTR))->va_header & 0x7F) +#define VARSIZE_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_len_1be) + +#define SET_VARSIZE_4B(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (len)&0x3FFFFFFF) +#define SET_VARSIZE_4B_C(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = ((len)&0x3FFFFFFF) | 0x40000000) +#define SET_VARSIZE_1B(PTR, len) (((varattrib_1b*)(PTR))->va_header = (len) | 0x80) +#define SET_VARTAG_1B_E(PTR, tag) (((varattrib_1b_e*)(PTR))->va_header = 0x80, ((varattrib_1b_e*)(PTR))->va_tag = (tag)) +#else /* !WORDS_BIGENDIAN */ + +#define VARATT_IS_4B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x01) == 0x00) +#define VARATT_IS_4B_U(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x03) == 0x00) +#define VARATT_IS_4B_C(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x03) == 0x02) +#define VARATT_IS_1B(PTR) ((((varattrib_1b*)(PTR))->va_header & 0x01) == 0x01) +#define VARATT_IS_1B_E(PTR) ((((varattrib_1b*)(PTR))->va_header) == 0x01) +#define VARATT_NOT_PAD_BYTE(PTR) (*((uint8*)(PTR)) != 0) + +/* VARSIZE_4B() should only be used on known-aligned data */ +#define VARSIZE_4B(PTR) ((((varattrib_4b*)(PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF) +#define VARSIZE_1B(PTR) ((((varattrib_1b*)(PTR))->va_header >> 1) & 0x7F) +#define VARTAG_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_tag) +#define SET_VARSIZE_4B(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (((uint32)(len)) << 2)) +#define SET_VARSIZE_4B_C(PTR, len) (((varattrib_4b*)(PTR))->va_4byte.va_header = (((uint32)(len)) << 2) | 0x02) +#define SET_VARSIZE_1B(PTR, len) (((varattrib_1b*)(PTR))->va_header = (((uint8)(len)) << 1) | 0x01) +#define SET_VARTAG_1B_E(PTR, tag) (((varattrib_1b_e*)(PTR))->va_header = 0x01, ((varattrib_1b_e*)(PTR))->va_tag = (tag)) +#endif /* WORDS_BIGENDIAN */ + +#define VARHDRSZ_SHORT offsetof(varattrib_1b, va_data) +#define VARATT_SHORT_MAX 0x7F +#define VARATT_CAN_MAKE_SHORT(PTR) \ + (VARATT_IS_4B_U(PTR) && (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) <= VARATT_SHORT_MAX) +#define VARATT_CONVERTED_SHORT_SIZE(PTR) (VARSIZE(PTR) - VARHDRSZ + VARHDRSZ_SHORT) + +#define VARHDRSZ_EXTERNAL offsetof(varattrib_1b_e, va_data) + +#define VARDATA_4B(PTR) (((varattrib_4b*)(PTR))->va_4byte.va_data) +#define VARDATA_4B_C(PTR) (((varattrib_4b*)(PTR))->va_compressed.va_data) +#define VARDATA_1B(PTR) (((varattrib_1b*)(PTR))->va_data) +#define VARDATA_1B_E(PTR) (((varattrib_1b_e*)(PTR))->va_data) + +#define VARRAWSIZE_4B_C(PTR) (((varattrib_4b*)(PTR))->va_compressed.va_rawsize) + +/* Externally visible macros */ + +/* + * VARDATA, VARSIZE, and SET_VARSIZE are the recommended API for most code + * for varlena datatypes. Note that they only work on untoasted, + * 4-byte-header Datums! + * + * Code that wants to use 1-byte-header values without detoasting should + * use VARSIZE_ANY/VARSIZE_ANY_EXHDR/VARDATA_ANY. The other macros here + * should usually be used only by tuple assembly/disassembly code and + * code that specifically wants to work with still-toasted Datums. + * + * WARNING: It is only safe to use VARDATA_ANY() -- typically with + * PG_DETOAST_DATUM_PACKED() -- if you really don't care about the alignment. + * Either because you're working with something like text where the alignment + * doesn't matter or because you're not going to access its constituent parts + * and just use things like memcpy on it anyways. + */ +#define VARDATA(PTR) VARDATA_4B(PTR) +#define VARSIZE(PTR) VARSIZE_4B(PTR) + +#define VARSIZE_SHORT(PTR) VARSIZE_1B(PTR) +#define VARDATA_SHORT(PTR) VARDATA_1B(PTR) + +#define VARTAG_EXTERNAL(PTR) VARTAG_1B_E(PTR) +#define VARSIZE_EXTERNAL(PTR) (VARHDRSZ_EXTERNAL + VARTAG_SIZE(VARTAG_EXTERNAL(PTR))) +#define VARDATA_EXTERNAL(PTR) VARDATA_1B_E(PTR) + +#define VARATT_IS_COMPRESSED(PTR) VARATT_IS_4B_C(PTR) +#define VARATT_IS_EXTERNAL(PTR) VARATT_IS_1B_E(PTR) +#define VARATT_IS_EXTERNAL_ONDISK(PTR) (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_ONDISK) +#define VARATT_IS_EXTERNAL_INDIRECT(PTR) (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_INDIRECT) +#define VARATT_IS_EXTERNAL_BUCKET(PTR) \ + (VARATT_IS_EXTERNAL(PTR) && VARTAG_EXTERNAL(PTR) == VARTAG_BUCKET) +#define VARATT_IS_EXTERNAL_ONDISK_B(PTR) \ + (VARATT_IS_EXTERNAL_ONDISK(PTR) || VARATT_IS_EXTERNAL_BUCKET(PTR)) + +#define VARATT_IS_SHORT(PTR) VARATT_IS_1B(PTR) +#define VARATT_IS_EXTENDED(PTR) (!VARATT_IS_4B_U(PTR)) + +#define SET_VARSIZE(PTR, len) SET_VARSIZE_4B(PTR, len) +#define SET_VARSIZE_SHORT(PTR, len) SET_VARSIZE_1B(PTR, len) +#define SET_VARSIZE_COMPRESSED(PTR, len) SET_VARSIZE_4B_C(PTR, len) +#define SET_VARTAG_EXTERNAL(PTR, tag) SET_VARTAG_1B_E(PTR, tag) + +#define VARSIZE_ANY(PTR) \ + (VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR) : (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) : VARSIZE_4B(PTR))) + +#define VARSIZE_ANY_EXHDR(PTR) \ + (VARATT_IS_1B_E(PTR) ? VARSIZE_EXTERNAL(PTR) - VARHDRSZ_EXTERNAL \ + : (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR) - VARHDRSZ_SHORT : VARSIZE_4B(PTR) - VARHDRSZ)) + +/* caution: this will not work on an external or compressed-in-line Datum */ +/* caution: this will return a possibly unaligned pointer */ +#define VARDATA_ANY(PTR) (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR)) + +/* ---------------------------------------------------------------- + * Section 2: datum type + support macros + * ---------------------------------------------------------------- + */ + +/* + * Port Notes: + * Postgres makes the following assumptions about datatype sizes: + * + * sizeof(Datum) == sizeof(void *) == 4 or 8 + * sizeof(char) == 1 + * sizeof(short) == 2 + * + * When a type narrower than Datum is stored in a Datum, we place it in the + * low-order bits and are careful that the DatumGetXXX macro for it discards + * the unused high-order bits (as opposed to, say, assuming they are zero). + * This is needed to support old-style user-defined functions, since depending + * on architecture and compiler, the return value of a function returning char + * or short may contain garbage when called as if it returned Datum. + */ + +typedef uintptr_t Datum; + +#define SIZEOF_DATUM SIZEOF_VOID_P + +typedef Datum* DatumPtr; + +#define GET_1_BYTE(datum) (((Datum)(datum)) & 0x000000ff) +#define GET_2_BYTES(datum) (((Datum)(datum)) & 0x0000ffff) +#define GET_4_BYTES(datum) (((Datum)(datum)) & 0xffffffff) +#if SIZEOF_DATUM == 8 +#define GET_8_BYTES(datum) ((Datum)(datum)) +#endif +#define SET_1_BYTE(value) (((Datum)(value)) & 0x000000ff) +#define SET_2_BYTES(value) (((Datum)(value)) & 0x0000ffff) +#define SET_4_BYTES(value) (((Datum)(value)) & 0xffffffff) +#if SIZEOF_DATUM == 8 +#define SET_8_BYTES(value) ((Datum)(value)) +#endif + +/* + * DatumGetBool + * Returns boolean value of a datum. + * + * Note: any nonzero value will be considered TRUE, but we ignore bits to + * the left of the width of bool, per comment above. + */ + +#define DatumGetBool(X) ((bool)(((bool)(X)) != 0)) + +/* + * BoolGetDatum + * Returns datum representation for a boolean. + * + * Note: any nonzero value will be considered TRUE. + */ +#ifndef BoolGetDatum +#define BoolGetDatum(X) ((Datum)((X) ? 1 : 0)) +#endif +/* + * DatumGetChar + * Returns character value of a datum. + */ + +#define DatumGetChar(X) ((char)GET_1_BYTE(X)) + +/* + * CharGetDatum + * Returns datum representation for a character. + */ + +#define CharGetDatum(X) ((Datum)SET_1_BYTE((unsigned char)(X))) + +/* + * Int8GetDatum + * Returns datum representation for an 8-bit integer. + */ + +#define Int8GetDatum(X) ((Datum)SET_1_BYTE((uint8)X)) + +/* + * DatumGetInt8 + * Returns 8-bit integer value of a datum. + */ +#define DatumGetInt8(X) ((int8)GET_1_BYTE(X)) + +/* + * DatumGetUInt8 + * Returns 8-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt8(X) ((uint8)GET_1_BYTE(X)) + +/* + * UInt8GetDatum + * Returns datum representation for an 8-bit unsigned integer. + */ + +#define UInt8GetDatum(X) ((Datum)SET_1_BYTE((uint8)(X))) + +/* + * DatumGetInt16 + * Returns 16-bit integer value of a datum. + */ + +#define DatumGetInt16(X) ((int16)GET_2_BYTES(X)) + +/* + * Int16GetDatum + * Returns datum representation for a 16-bit integer. + */ + +#define Int16GetDatum(X) ((Datum)SET_2_BYTES((uint16)(X))) + +/* + * DatumGetUInt16 + * Returns 16-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt16(X) ((uint16)GET_2_BYTES(X)) + +/* + * UInt16GetDatum + * Returns datum representation for a 16-bit unsigned integer. + */ + +#define UInt16GetDatum(X) ((Datum)SET_2_BYTES(X)) + +/* + * DatumGetInt32 + * Returns 32-bit integer value of a datum. + */ + +#define DatumGetInt32(X) ((int32)GET_4_BYTES(X)) + +/* + * Int32GetDatum + * Returns datum representation for a 32-bit integer. + */ + +#define Int32GetDatum(X) ((Datum)SET_4_BYTES((uint32)(X))) + +/* + * DatumGetUInt32 + * Returns 32-bit unsigned integer value of a datum. + */ + +#define DatumGetUInt32(X) ((uint32)GET_4_BYTES(X)) + +/* + * UInt32GetDatum + * Returns datum representation for a 32-bit unsigned integer. + */ + +#define UInt32GetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetObjectId + * Returns object identifier value of a datum. + */ + +#define DatumGetObjectId(X) ((Oid)GET_4_BYTES(X)) + +/* + * ObjectIdGetDatum + * Returns datum representation for an object identifier. + */ + +#define ObjectIdGetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetTransactionId + * Returns transaction identifier value of a datum. + */ + +#define DatumGetTransactionId(X) (DatumGetUInt64(X)) +#define DatumGetShortTransactionId(X) ((ShortTransactionId)GET_4_BYTES(X)) +/* + * TransactionIdGetDatum + * Returns datum representation for a transaction identifier. + */ + +#define TransactionIdGetDatum(X) (UInt64GetDatum(X)) +#define ShortTransactionIdGetDatum(X) ((Datum)SET_4_BYTES((X))) +/* + * DatumGetCommandId + * Returns command identifier value of a datum. + */ + +#define DatumGetCommandId(X) ((CommandId)GET_4_BYTES(X)) + +/* + * CommandIdGetDatum + * Returns datum representation for a command identifier. + */ + +#define CommandIdGetDatum(X) ((Datum)SET_4_BYTES(X)) + +/* + * DatumGetPointer + * Returns pointer value of a datum. + */ + +#define DatumGetPointer(X) ((Pointer)(X)) + +/* + * PointerGetDatum + * Returns datum representation for a pointer. + */ +#ifndef PointerGetDatum +#define PointerGetDatum(X) ((Datum)(X)) +#endif +/* + * DatumGetCString + * Returns C string (null-terminated string) value of a datum. + * + * Note: C string is not a full-fledged Postgres type at present, + * but type input functions use this conversion for their inputs. + */ + +#define DatumGetCString(X) ((char*)DatumGetPointer(X)) + +/* + * CStringGetDatum + * Returns datum representation for a C string (null-terminated string). + * + * Note: C string is not a full-fledged Postgres type at present, + * but type output functions use this conversion for their outputs. + * Note: CString is pass-by-reference; caller must ensure the pointed-to + * value has adequate lifetime. + */ + +#define CStringGetDatum(X) PointerGetDatum(X) + +/* + * DatumGetName + * Returns name value of a datum. + */ + +#define DatumGetName(X) ((Name)DatumGetPointer(X)) + +/* + * NameGetDatum + * Returns datum representation for a name. + * + * Note: Name is pass-by-reference; caller must ensure the pointed-to + * value has adequate lifetime. + */ + +#define NameGetDatum(X) PointerGetDatum(X) + +/* + * DatumGetInt64 + * Returns 64-bit integer value of a datum. + * + * Note: this macro hides whether int64 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +#define DatumGetInt64(X) ((int64)GET_8_BYTES(X)) +#else +#define DatumGetInt64(X) (*((int64*)DatumGetPointer(X))) +#endif + +#define BatchMaxSize 1000 +/* + * Int64GetDatum + * Returns datum representation for a 64-bit integer. + * + * Note: if int64 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +#ifdef USE_FLOAT8_BYVAL +#define Int64GetDatum(X) ((Datum)SET_8_BYTES(X)) +#else +extern Datum Int64GetDatum(int64 X); +#endif + +/* + * DatumGetUInt64 + * Returns 64-bit unsigned integer value of a datum. + * + * Note: this macro hides whether int64 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +#define DatumGetUInt64(X) ((uint64)GET_8_BYTES(X)) +#else +#define DatumGetUInt64(X) (*((uint64*)DatumGetPointer(X))) +#endif + +/* + * UInt64GetDatum + * Returns datum representation for a 64-bit unsigned integer. + * + * Note: if int64 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +#ifdef USE_FLOAT8_BYVAL +#define UInt64GetDatum(X) ((Datum)SET_8_BYTES(X)) +#else +#define UInt64GetDatum(X) Int64GetDatum((int64)(X)) +#endif + +/* + * DatumGetFloat4 + * Returns 4-byte floating point value of a datum. + * + * Note: this macro hides whether float4 is pass by value or by reference. + */ + +#ifdef USE_FLOAT4_BYVAL +extern float4 DatumGetFloat4(Datum X); +#else +#define DatumGetFloat4(X) (*((float4*)DatumGetPointer(X))) +#endif + +/* + * Float4GetDatum + * Returns datum representation for a 4-byte floating point number. + * + * Note: if float4 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +extern Datum Float4GetDatum(float4 X); + +/* + * DatumGetFloat8 + * Returns 8-byte floating point value of a datum. + * + * Note: this macro hides whether float8 is pass by value or by reference. + */ + +#ifdef USE_FLOAT8_BYVAL +extern float8 DatumGetFloat8(Datum X); +#else +#define DatumGetFloat8(X) (*((float8*)DatumGetPointer(X))) +#endif + +/* + * Float8GetDatum + * Returns datum representation for an 8-byte floating point number. + * + * Note: if float8 is pass by reference, this function returns a reference + * to palloc'd space. + */ + +extern Datum Float8GetDatum(float8 X); + +/* + * Int64GetDatumFast + * Float8GetDatumFast + * Float4GetDatumFast + * + * These macros are intended to allow writing code that does not depend on + * whether int64, float8, float4 are pass-by-reference types, while not + * sacrificing performance when they are. The argument must be a variable + * that will exist and have the same value for as long as the Datum is needed. + * In the pass-by-ref case, the address of the variable is taken to use as + * the Datum. In the pass-by-val case, these will be the same as the non-Fast + * macros. + */ + +#ifdef USE_FLOAT8_BYVAL +#define Int64GetDatumFast(X) Int64GetDatum(X) +#define Float8GetDatumFast(X) Float8GetDatum(X) +#else +#define Int64GetDatumFast(X) PointerGetDatum(&(X)) +#define Float8GetDatumFast(X) PointerGetDatum(&(X)) +#endif + +#ifdef USE_FLOAT4_BYVAL +#define Float4GetDatumFast(X) Float4GetDatum(X) +#else +#define Float4GetDatumFast(X) PointerGetDatum(&(X)) +#endif + +#ifdef HAVE_INT64_TIMESTAMP +#define TimeGetDatum(X) Int64GetDatum(X) +#else +#define TimeGetDatum(X) Float8GetDatum(X) +#endif + +/* ---------------------------------------------------------------- + * Section 3: exception handling definitions + * Assert, Trap, etc macros + * ---------------------------------------------------------------- + */ + +#ifdef WIN32 +extern THR_LOCAL bool assert_enabled; +#else +extern THR_LOCAL PGDLLIMPORT bool assert_enabled; +#endif + +/* + * USE_ASSERT_CHECKING, if defined, turns on all the assertions. + * - plai 9/5/90 + * + * It should _NOT_ be defined in releases or in benchmark copies + */ + +/* + * Trap + * Generates an exception if the given condition is true. + */ +#define Trap(condition, errorType) \ + do { \ + if ((assert_enabled) && (condition)) \ + ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__); \ + } while (0) + +/* + * TrapMacro is the same as Trap but it's intended for use in macros: + * + * #define foo(x) (AssertMacro(x != 0), bar(x)) + * + * Isn't CPP fun? + */ +#define TrapMacro(condition, errorType) \ + ((bool)((!assert_enabled) || !(condition) || \ + (ExceptionalCondition(CppAsString(condition), (errorType), __FILE__, __LINE__), 0))) + +#ifdef Assert +#undef Assert +#endif +#ifdef PC_LINT +#define Assert(condition) \ + do { \ + if (!(bool)(condition)) \ + exit(1); \ + } while (0) +#ifndef AssertMacro +#define AssertMacro Assert +#endif +#define AssertArg Assert +#define DBG_ASSERT Assert +#define AssertState Assert + +#else +#ifndef USE_ASSERT_CHECKING +#define Assert(condition) +#ifndef AssertMacro +#define AssertMacro(condition) ((void)true) +#endif /* AssertMacro */ +#define AssertArg(condition) +#define DBG_ASSERT(condition) +#define AssertState(condition) + +#elif defined(FRONTEND) + +#include +#define Assert(p) assert(p) +#ifndef AssertMacro +#define AssertMacro(p) ((void)assert(p)) +#endif +#define AssertArg(condition) assert(condition) +#define DBG_ASSERT(condition) +#define AssertState(condition) assert(condition) +#define AssertPointerAlignment(ptr, bndr) ((void)true) +#else /* USE_ASSERT_CHECKING && !FRONTEND */ + +#define Assert(condition) Trap(!(condition), "FailedAssertion") + +#ifndef AssertMacro +#define AssertMacro(condition) ((void)TrapMacro(!(condition), "FailedAssertion")) +#endif /* AssertMacro */ + +#define AssertArg(condition) Trap(!(condition), "BadArgument") + +#define AssertState(condition) Trap(!(condition), "BadState") +#define DBG_ASSERT Assert +#endif /* USE_ASSERT_CHECKING */ +#endif /* PC_LINT */ + +extern void ExceptionalCondition(const char* conditionName, const char* errorType, const char* fileName, int lineNumber) + __attribute__((noreturn)); + +extern void ConnFree(void* conn); + +extern THR_LOCAL bool IsInitdb; + +extern size_t mmap_threshold; + +/* Set the pooler reload flag when signaled by SIGUSR1 */ +void HandlePoolerReload(void); +void HandleMemoryContextDump(void); +void HandleExecutorFlag(void); + +extern void start_xact_command(void); +extern void finish_xact_command(void); +extern void exec_init_poolhandles(void); + +extern void InitVecFuncMap(void); + +/* load ir file count for each process */ +extern long codegenIRloadProcessCount; + +/* Job worker Process, execute procedure */ +extern void execute_simple_query(const char* query_string); + +/* check the value from environment variablethe to prevent command injection. */ +extern void check_backend_env(const char* input_env_value); +extern bool backend_env_valid(const char* input_env_value, const char* stamp); + +extern void CleanSystemCaches(bool is_in_read_command); + +/*Audit user logout*/ +extern void audit_processlogout_unified(); +extern void audit_processlogout(int code, Datum arg); + +/* free the pointer malloced by cJSON_internal_malloc.*/ +extern void cJSON_internal_free(void* pointer); + +extern void InitThreadLocalWhenSessionExit(); +extern void RemoveTempNamespace(); + +#define CacheIsProcNameArgNsp(cache) ((cache)->id == PROCNAMEARGSNSP) +#define CacheIsProcOid(cache) ((cache)->id == PROCOID) +#define IsBootingPgProc(rel) IsProcRelation(rel) +#define BootUsingBuiltinFunc true + +#define MSG_A_REPEAT_NUM_MAX 1024 +#define OVERRIDE_STACK_LENGTH_MAX 1024 +#endif /* POSTGRES_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/aiocompleter.h postgresql-hll-2.14/include/postmaster/aiocompleter.h --- postgresql-hll-2.14_old/include/postmaster/aiocompleter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/aiocompleter.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,121 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aiocompleter.h + * Exports from postmaster/aiocompleter.c. + * + * + * IDENTIFICATION + * src/include/postmaster/aiocompleter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _AIOCOMPLETER_H +#define _AIOCOMPLETER_H + +#include "storage/block.h" +#include "storage/bufmgr.h" +#include "storage/buf_internals.h" +#include "storage/relfilenode.h" +#include "storage/smgr.h" +#include + +/* + * requests/completers types + */ +typedef enum { + // PageRangePrefetchType=0, + PageListPrefetchType = 0, + // PageRangeBackWriteType, + PageListBackWriteType, + CUListPrefetchType, + CUListWriteType, + NUM_AIOCOMPLTR_TYPES /* Number of types, must be last */ +} AioCompltrType; + +/* + * request priorities (io nice values) + */ +typedef enum { DefaultPri = 0, HighPri = 1, MediumPri = 2, LowPri = 3 } AioPriority; + +typedef enum { AioRead = 0, AioWrite = 1, AioVacummFull = 2, AioUnkown } AioDescType; + +/* + * Context for Page AIO completion + */ +typedef struct BlockDesc { + SMgrRelation smgrReln; + ForkNumber forkNum; + BlockNumber blockNum; + Block buffer; + int32 blockSize; + BufferDesc* bufHdr; + AioCompltrType reqType; + AioDescType descType; +} BlockDesc_t; + +typedef struct AioCUDesc { + char* buf; + uint64 offset; // use uint64 instead of CUPointer for not include + int size; // read: align cu_size; write: cu_size + int fd; + bool* io_error; + int slotId; // read means slotId of cucache; write means cuid + volatile int io_finish; // used for which has no cucache, ep write; + uint64 cu_pointer; // only used for async write, + AioCompltrType reqType; +} AioCUDesc_t; + +/* + * The system iocb and BlockDesc_t are allocated together in an + * AioDispatchDesc. + */ +typedef struct AioDispatchDesc { + struct iocb aiocb; + BlockDesc_t blockDesc; +} AioDispatchDesc_t; + +typedef struct AioDispatchCUDesc { + struct iocb aiocb; + AioCUDesc_t cuDesc; +} AioDispatchCUDesc_t; + +/* GUC options */ +extern int AioCompltrSets; +extern int AioCompltrEvents; + +extern void AioCompltrMain(int ac, char** av); +extern void AioCompltrStop(int signal); +extern int AioCompltrStart(void); +extern bool AioCompltrIsReady(void); +extern io_context_t CompltrContext(AioCompltrType reqType, int h); +extern short CompltrPriority(AioCompltrType reqType); + +/* + * These Storage Manager AIO prototypes would normally + * go in smgr.h, and that file would include this one. + * because the prototypes require the AioDispatchDesc_t. + * However, it is not possible because this file must + * include smgr.h itself. + */ +extern void smgrasyncread(SMgrRelation reln, ForkNumber forknum, AioDispatchDesc_t** dList, int32 dn); +extern void smgrasyncwrite(SMgrRelation reln, ForkNumber forknum, AioDispatchDesc_t** dList, int32 dn); + +extern void mdasyncread(SMgrRelation reln, ForkNumber forkNum, AioDispatchDesc_t** dList, int32 dn); +extern void mdasyncwrite(SMgrRelation reln, ForkNumber forkNumber, AioDispatchDesc_t** dList, int32 dn); + +extern void AioResourceInitialize(void); + +#endif /* _AIOCOMPLETER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/alarmchecker.h postgresql-hll-2.14/include/postmaster/alarmchecker.h --- postgresql-hll-2.14_old/include/postmaster/alarmchecker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/alarmchecker.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * alarmchecker.h + * POSTGRES alarm reporting/logging definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/postmaster/alarmchecker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ALARMCHECKER_H +#define ALARMCHECKER_H +#include "alarm/alarm.h" + +extern bool enable_alarm; + +extern bool isDirExist(const char* dir); +extern ThreadId startAlarmChecker(void); +extern NON_EXEC_STATIC void AlarmCheckerMain(); + +#endif diff -uprN postgresql-hll-2.14_old/include/postmaster/autovacuum.h postgresql-hll-2.14/include/postmaster/autovacuum.h --- postgresql-hll-2.14_old/include/postmaster/autovacuum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/autovacuum.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,77 @@ +/* ------------------------------------------------------------------------- + * + * autovacuum.h + * header file for integrated autovacuum daemon + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/postmaster/autovacuum.h + * + * ------------------------------------------------------------------------- + */ +#include "utils/guc.h" + +#ifndef AUTOVACUUM_H +#define AUTOVACUUM_H + +#include "utils/guc.h" + +#ifdef PGXC /* PGXC_DATANODE */ +#define IsAutoVacuumAnalyzeWorker() (IsAutoVacuumWorkerProcess() && !(MyProc->vacuumFlags & PROC_IN_VACUUM)) + +#define UINT32_MASK ((uint64)((1UL << 32) - 1)) + +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id); +#define AUTOVAC_LOG(level, format, ...) \ + do { \ + if (is_errmodule_enable(level, MOD_AUTOVAC)) { \ + ereport(level, (errmodule(MOD_AUTOVAC), errmsg(format, ##__VA_ARGS__), ignore_interrupt(true))); \ + } \ + } while (0) + +typedef enum { + AUTOVACUUM_DO_ANALYZE, /* just do auto-analyze when autovacuum = true */ + AUTOVACUUM_DO_VACUUM, /* just do auto-vacuum when autovacuum = true */ + AUTOVACUUM_DO_ANALYZE_VACUUM, /* do auto-vacuum and auto-analyze when autovacuum = true */ + AUTOVACUUM_DO_NONE /* do neither auto-vacuum or auto-analyze when autovacuum = true */ +} AutoVacuumModeType; + +#endif + +/* Status inquiry functions */ +extern bool AutoVacuumingActive(void); +extern bool IsAutoVacuumLauncherProcess(void); +extern bool IsAutoVacuumWorkerProcess(void); +extern AutoVacOpts* extract_autovac_opts(HeapTuple tup, TupleDesc pg_class_desc); + +#define IsAnyAutoVacuumProcess() (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess()) + +/* Functions to start autovacuum process, called from postmaster */ +extern void autovac_init(void); + +/* called from postmaster when a worker could not be forked */ +extern void AutoVacWorkerFailed(void); + +/* autovacuum cost-delay balancer */ +extern void AutoVacuumUpdateDelay(void); + +#ifdef EXEC_BACKEND +extern void AutoVacLauncherMain(); +extern void AutoVacWorkerMain(); +extern void AutovacuumWorkerIAm(void); +extern void AutovacuumLauncherIAm(void); +#endif + +/* shared memory stuff */ +extern Size AutoVacuumShmemSize(void); +extern void AutoVacuumShmemInit(void); + +extern bool check_autovacuum_coordinators(char** newval, void** extra, GucSource source); +extern void assign_autovacuum_coordinators(const char* newval, void* extra); +extern void relation_support_autoavac( + HeapTuple tuple, bool* enable_analyze, bool* enable_vacuum, bool* is_internal_relation); + +#endif /* AUTOVACUUM_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/bgwriter.h postgresql-hll-2.14/include/postmaster/bgwriter.h --- postgresql-hll-2.14_old/include/postmaster/bgwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/bgwriter.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * bgwriter.h + * Exports from postmaster/bgwriter.c and postmaster/checkpointer.c. + * + * The bgwriter process used to handle checkpointing duties too. Now + * there is a separate process, but we did not bother to split this header. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/bgwriter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _BGWRITER_H +#define _BGWRITER_H + +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "postmaster/pagewriter.h" + +typedef struct CkptSortItem CkptSortItem; + +#ifdef ENABLE_MOT +typedef enum { + EVENT_CHECKPOINT_CREATE_SNAPSHOT, + EVENT_CHECKPOINT_SNAPSHOT_READY, + EVENT_CHECKPOINT_BEGIN_CHECKPOINT, + EVENT_CHECKPOINT_ABORT +} CheckpointEvent; + +typedef void (*CheckpointCallback)(CheckpointEvent checkpointEvent, XLogRecPtr lsn, void* arg); + +extern void RegisterCheckpointCallback(CheckpointCallback callback, void* arg); +extern void CallCheckpointCallback(CheckpointEvent checkpointEvent, XLogRecPtr lsn); +#endif + +extern void BackgroundWriterMain(void); +extern void CheckpointerMain(void); + +extern void RequestCheckpoint(int flags); +extern void CheckpointWriteDelay(int flags, double progress); + +extern bool ForwardFsyncRequest(const RelFileNode rnode, ForkNumber forknum, BlockNumber segno); +extern void AbsorbFsyncRequests(void); + +extern Size CheckpointerShmemSize(void); +extern void CheckpointerShmemInit(void); + +extern bool FirstCallSinceLastCheckpoint(void); +extern bool IsBgwriterProcess(void); + +/* incremental checkpoint bgwriter thread */ +const int INCRE_CKPT_BGWRITER_VIEW_COL_NUM = 6; +extern const incre_ckpt_view_col g_bgwriter_view_col[INCRE_CKPT_BGWRITER_VIEW_COL_NUM]; +extern void candidate_buf_init(void); +extern void incre_ckpt_bgwriter_cxt_init(); +extern void incre_ckpt_background_writer_main(void); +extern void ckpt_shutdown_bgwriter(); +extern int get_bgwriter_thread_id(void); +extern bool candidate_buf_pop(int *bufId, int threadId); + +typedef struct BgWriterProc { + PGPROC *proc; + CkptSortItem *dirty_buf_list; + uint32 dirty_list_size; + int *cand_buf_list; /* thread candidate buffer list */ + volatile int cand_list_size; /* thread candidate list max size */ + volatile int buf_id_start; /* buffer id start loc */ + pg_atomic_uint64 head; + pg_atomic_uint64 tail; + bool need_flush; + ThrdDwCxt thrd_dw_cxt; /* thread double writer cxt */ + volatile uint32 thread_last_flush; + int32 next_scan_loc; +} BgWriterProc; +#endif /* _BGWRITER_H */ + diff -uprN postgresql-hll-2.14_old/include/postmaster/cbmwriter.h postgresql-hll-2.14/include/postmaster/cbmwriter.h --- postgresql-hll-2.14_old/include/postmaster/cbmwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/cbmwriter.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cbmwriter.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/cbmwriter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _CBMWRITER_H +#define _CBMWRITER_H + +extern void CBMWriterMain(void); + +#endif /* _CBMWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/fencedudf.h postgresql-hll-2.14/include/postmaster/fencedudf.h --- postgresql-hll-2.14_old/include/postmaster/fencedudf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/fencedudf.h 2020-12-12 17:06:43.362349522 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * fencedudf.h + * The header file of implementing to run UDF in fenced mode + * + * The core design is to implement a RPC server and client, run udf in RPC server. + * User defined C function is not safe, because if the UDF has some bugs which can + * cause coredump or memory leak in gaussdb, So we need provide an fenced mode for udf. + * When we run fenecd udf, it will run in RPC server. If UDF cause coredump, there is not + * any impact for gaussdb process. + * + * + * IDENTIFICATION + * src/include/postmaster/fencedudf.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef FENCEDUDF_H +#define FENCEDUDF_H +#include "access/htup.h" + +extern void FencedUDFMasterMain(int argc, char* argv[]); +extern bool RPCInitFencedUDFIfNeed(Oid functionId, FmgrInfo* finfo, HeapTuple procedureTuple); +template +extern Datum RPCFencedUDF(FunctionCallInfo fcinfo); +extern void InitFuncCallUDFInfo(FunctionCallInfoData* finfo, int batchRows, int argN, bool batchMode); + +#endif diff -uprN postgresql-hll-2.14_old/include/postmaster/fork_process.h postgresql-hll-2.14/include/postmaster/fork_process.h --- postgresql-hll-2.14_old/include/postmaster/fork_process.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/fork_process.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,17 @@ +/* ------------------------------------------------------------------------- + * + * fork_process.h + * Exports from postmaster/fork_process.c. + * + * Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/fork_process.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FORK_PROCESS_H +#define FORK_PROCESS_H + +extern pid_t fork_process(void); + +#endif /* FORK_PROCESS_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/licensechecker.h postgresql-hll-2.14/include/postmaster/licensechecker.h --- postgresql-hll-2.14_old/include/postmaster/licensechecker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/licensechecker.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * licensechecker.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/licensechecker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef POSTMASTER_LICENSECHECKER_H +#define POSTMASTER_LICENSECHECKER_H + +extern void LicenseCheckerMain(char* str); + +#endif /* POSTMASTER_LICENSECHECKER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/lwlockmonitor.h postgresql-hll-2.14/include/postmaster/lwlockmonitor.h --- postgresql-hll-2.14_old/include/postmaster/lwlockmonitor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/lwlockmonitor.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lwlockmonitor.h + * Automatically clean two-phase transaction + * + * + * IDENTIFICATION + * src/include/postmaster/lwlockmonitor.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _LWLOCKMONITOR_H +#define _LWLOCKMONITOR_H + +extern void FaultMonitorMain(); + +#endif /* _LWLOCKMONITOR_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/pagewriter.h postgresql-hll-2.14/include/postmaster/pagewriter.h --- postgresql-hll-2.14_old/include/postmaster/pagewriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/pagewriter.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,99 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pagewriter.h + * Data struct to store pagewriter thread variables. + * + * + * IDENTIFICATION + * src/include/postmaster/pagewriter.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _PAGEWRITER_H +#define _PAGEWRITER_H +#include "storage/buf.h" + +typedef struct PGPROC PGPROC; +typedef struct BufferDesc BufferDesc; + +typedef struct ThrdDwCxt { + char* dw_buf; + uint16 write_pos; + volatile int dw_page_idx; /* -1 means data files have been flushed. */ + bool contain_hashbucket; +} ThrdDwCxt; + +typedef struct PageWriterProc { + PGPROC* proc; + volatile uint32 start_loc; + volatile uint32 end_loc; + volatile bool need_flush; + volatile uint32 actual_flush_num; +} PageWriterProc; + +typedef struct PageWriterProcs { + PageWriterProc* writer_proc; + volatile int num; /* number of pagewriter thread */ + pg_atomic_uint32 running_num; /* number of pagewriter thread which flushing dirty page */ + ThrdDwCxt thrd_dw_cxt; +} PageWriterProcs; + +typedef struct DirtyPageQueueSlot { + volatile int buffer; + pg_atomic_uint32 slot_state; +} DirtyPageQueueSlot; + +typedef Datum (*incre_ckpt_view_get_data_func)(); + +const int INCRE_CKPT_VIEW_NAME_LEN = 128; + +typedef struct incre_ckpt_view_col { + char name[INCRE_CKPT_VIEW_NAME_LEN]; + Oid data_type; + incre_ckpt_view_get_data_func get_val; +} incre_ckpt_view_col; + +/* + * The slot location is pre-occupied. When the slot buffer is set, the state will set + * to valid. when remove dirty page form queue, don't change the state, only when move + * the dirty page head, need set the slot state is invalid. + */ +const int SLOT_VALID = 1; + +extern bool IsPagewriterProcess(void); +extern void incre_ckpt_pagewriter_cxt_init(); +extern void ckpt_pagewriter_main(void); + +extern bool push_pending_flush_queue(Buffer buffer); +extern void remove_dirty_page_from_queue(BufferDesc* buf); +extern int64 get_dirty_page_num(); +extern uint64 get_dirty_page_queue_tail(); +extern int get_pagewriter_thread_id(void); +extern bool is_dirty_page_queue_full(BufferDesc* buf); +extern int get_dirty_page_queue_head_buffer(); +/* Shutdown all the page writer threads. */ +extern void ckpt_shutdown_pagewriter(); +extern uint64 get_dirty_page_queue_rec_lsn(); +extern XLogRecPtr ckpt_get_min_rec_lsn(void); +extern uint32 calculate_thread_max_flush_num(bool is_pagewriter); + +const int PAGEWRITER_VIEW_COL_NUM = 8; +const int INCRE_CKPT_VIEW_COL_NUM = 7; + +extern const incre_ckpt_view_col g_ckpt_view_col[INCRE_CKPT_VIEW_COL_NUM]; +extern const incre_ckpt_view_col g_pagewriter_view_col[PAGEWRITER_VIEW_COL_NUM]; + +#endif /* _PAGEWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/pgarch.h postgresql-hll-2.14/include/postmaster/pgarch.h --- postgresql-hll-2.14_old/include/postmaster/pgarch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/pgarch.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * pgarch.h + * Exports from postmaster/pgarch.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/pgarch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PGARCH_H +#define _PGARCH_H + +/* ---------- + * Functions called from postmaster + * ---------- + */ +extern ThreadId pgarch_start(void); + +#ifdef EXEC_BACKEND +extern void PgArchiverMain(); +#endif + +#endif /* _PGARCH_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/postmaster.h postgresql-hll-2.14/include/postmaster/postmaster.h --- postgresql-hll-2.14_old/include/postmaster/postmaster.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/postmaster.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * postmaster.h + * Exports from postmaster/postmaster.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/postmaster/postmaster.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _POSTMASTER_H +#define _POSTMASTER_H + +#include "replication/replicainternal.h" + +extern THR_LOCAL bool comm_client_bind; + +extern bool FencedUDFMasterMode; + +/* the logicTid index for nonProc thread*/ +#define POSTMASTER_LID 1 +#define PGSTAT_LID 2 +#define PGARCH_LID 3 +#define SYSLOGGER_LID 4 + +/* Startup/shutdown state */ +#define NoShutdown 0 +#define SmartShutdown 1 +#define FastShutdown 2 +#define ImmediateShutdown 3 + +extern volatile int Shutdown; + +extern uint32 noProcLogicTid; +extern THR_LOCAL bool stop_mythread; +extern THR_LOCAL ThreadId stop_threadid; + +extern pthread_mutex_t bt_lock; +extern pthread_rwlock_t hba_rwlock; + +typedef enum ReplicationType { + RT_WITH_DUMMY_STANDBY, + RT_WITH_MULTI_STANDBY, + RT_WITHOUT_STANDBY, + RT_NUM +} ReplicationType; + +#define IS_DN_MULTI_STANDYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITH_MULTI_STANDBY) +#define IS_DN_DUMMY_STANDYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITH_DUMMY_STANDBY) +#define IS_DN_WITHOUT_STANDBYS_MODE() (g_instance.attr.attr_storage.replication_type == RT_WITHOUT_STANDBY) + +/* + * We use a simple state machine to control startup, shutdown, and + * crash recovery (which is rather like shutdown followed by startup). + * + * After doing all the postmaster initialization work, we enter PM_STARTUP + * state and the startup process is launched. The startup process begins by + * reading the control file and other preliminary initialization steps. + * In a normal startup, or after crash recovery, the startup process exits + * with exit code 0 and we switch to PM_RUN state. However, archive recovery + * is handled specially since it takes much longer and we would like to support + * hot standby during archive recovery. + * + * When the startup process is ready to start archive recovery, it signals the + * postmaster, and we switch to PM_RECOVERY state. The background writer and + * checkpointer are launched, while the startup process continues applying WAL. + * If Hot Standby is enabled, then, after reaching a consistent point in WAL + * redo, startup process signals us again, and we switch to PM_HOT_STANDBY + * state and begin accepting connections to perform read-only queries. When + * archive recovery is finished, the startup process exits with exit code 0 + * and we switch to PM_RUN state. + * + * Normal child backends can only be launched when we are in PM_RUN or + * PM_HOT_STANDBY state. (We also allow launch of normal + * child backends in PM_WAIT_BACKUP state, but only for superusers.) + * In other states we handle connection requests by launching "dead_end" + * child processes, which will simply send the client an error message and + * quit. (We track these in the g_instance.backend_list so that we can know when they + * are all gone; this is important because they're still connected to shared + * memory, and would interfere with an attempt to destroy the shmem segment, + * possibly leading to SHMALL failure when we try to make a new one.) + * In PM_WAIT_DEAD_END state we are waiting for all the dead_end children + * to drain out of the system, and therefore stop accepting connection + * requests at all until the last existing child has quit (which hopefully + * will not be very long). + * + * Notice that this state variable does not distinguish *why* we entered + * states later than PM_RUN --- g_instance.status and g_instance.fatal_error must be consulted + * to find that out. g_instance.fatal_error is never true in PM_RECOVERY_* or PM_RUN + * states, nor in PM_SHUTDOWN states (because we don't enter those states + * when trying to recover from a crash). It can be true in PM_STARTUP state, + * because we don't clear it until we've successfully started WAL redo. + * Similarly, RecoveryError means that we have crashed during recovery, and + * should not try to restart. + */ +typedef enum { + PM_INIT, /* postmaster starting */ + PM_STARTUP, /* waiting for startup subprocess */ + PM_RECOVERY, /* in archive recovery mode */ + PM_HOT_STANDBY, /* in hot standby mode */ + PM_RUN, /* normal "database is alive" state */ + PM_WAIT_BACKUP, /* waiting for online backup mode to end */ + PM_WAIT_READONLY, /* waiting for read only backends to exit */ + PM_WAIT_BACKENDS, /* waiting for live backends to exit */ + PM_SHUTDOWN, /* waiting for checkpointer to do shutdown + * ckpt */ + PM_SHUTDOWN_2, /* waiting for archiver and walsenders to + * finish */ + PM_WAIT_DEAD_END, /* waiting for dead_end children to exit */ + PM_NO_CHILDREN /* all important children have exited */ +} PMState; + +extern volatile PMState pmState; + +#define MAX_PMSTATE_MSG_LEN 100 +typedef struct PMStateInfo { + PMState pmState; /* PM state */ + char pmStateMsg[MAX_PMSTATE_MSG_LEN]; /* PM state message */ +} PMStateInfo; + +extern const char* GetPMState(const PMState pmState); + +/* + * Constants that represent which of postmaster_alive_fds is held by + * postmaster, and which is used in children to check for postmaster death. + */ +#define POSTMASTER_FD_WATCH \ + 0 /* used in children to check for \ + * postmaster death */ +#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */ + +#define AmPostmasterProcess() (t_thrd.proc_cxt.MyProcPid == PostmasterPid) + +extern const char* progname; + +extern int PostmasterMain(int argc, char* argv[]); +extern void ClosePostmasterPorts(bool am_syslogger); +extern void ExitPostmaster(int status); + +extern int MaxLivePostmasterChildren(void); + +extern Size CBMShmemSize(void); +extern void CBMShmemInit(void); + +extern Size HaShmemSize(void); +extern void HaShmemInit(void); +#ifdef EXEC_BACKEND +extern Size ShmemBackendArraySize(void); +extern void ShmemBackendArrayAllocation(void); +extern int SubPostmasterMain(int argc, char* argv[]); + +#endif +#define MAX_BACKENDS 0x3FFFF +extern void KillGraceThreads(void); + +#define MAX_IPADDR_LEN 32 +#define MAX_PORT_LEN 6 +#define MAX_LISTEN_ENTRY 64 +#define MAX_IP_STR_LEN 64 +#define MAX_UNIX_PATH_LEN 1024 +#define LOCAL_HOST "localhost" +#define LOOP_IP_STRING "127.0.0.1" +#define LOOP_IPV6_IP "::1" + +#define NO_NEED_UN_TCPIP (0x00) +#define NEED_CREATE_UN (0x0F) +#define NEED_CREATE_TCPIP (0xF0) +#define NEED_CREATE_UN_TCPIP (0xFF) + +typedef struct LISTEN_ENTRY { + char ipaddr[MAX_IPADDR_LEN]; + int portnum; + int createmodel; /* type of the socket to be created */ +} LISTEN_ENTRY; + +typedef struct LISTEN_ADDRS { + int usedNum; + LISTEN_ENTRY lsnArray[MAX_LISTEN_ENTRY]; +} LISTEN_ADDRS; + +typedef struct DnUsedSpaceHashEntry { + uint64 query_id; + uint64 dnUsedSpace; +} DnUsedSpaceHashEntry; + +extern void CreateServerSocket( + char* ipaddr, int portNumber, int enCreatemode, int* success, bool add_localaddr_flag, bool is_create_psql_sock); +extern bool CheckSockAddr(struct sockaddr* sock_addr, const char* szIP, int port); + +extern DbState get_local_dbstate(void); +extern const char* wal_get_db_state_string(DbState db_state); + +extern void socket_close_on_exec(void); +extern void HandleChildCrash(ThreadId pid, int exitstatus, const char* procname); + +/* for ReaperBackend thread */ +extern volatile ThreadId ReaperBackendPID; + +extern bool IsCBMWriterRunning(void); + +void SetFlagForGetLCName(bool falg); + +extern ServerMode GetServerMode(); +/* set disable connection */ +extern void set_disable_conn_mode(void); +/* Defines the position where the signal "disable_conn_primary" is saved. */ +#define disable_conn_file "disable_conn_file" +#define POLLING_CONNECTION_STR "polling_connection" +#define SPECIFY_CONNECTION_STR "specify_connection" +#define PROHIBIT_CONNECTION_STR "prohibit_connection" + +#ifdef ENABLE_MULTIPLE_NODES +#define IsConnPortFromCoord(port) \ + ((port)->cmdline_options != NULL && strstr((port)->cmdline_options, "remotetype=coordinator") != NULL) +#else +#define IsConnPortFromCoord(port) false +#endif + +bool IsFromLocalAddr(Port* port); +extern bool IsHASocketAddr(struct sockaddr* sock_addr); +extern bool IsHAPort(Port* port); +extern ThreadId initialize_util_thread(knl_thread_role role, void* payload = NULL); +extern ThreadId initialize_worker_thread(knl_thread_role role, Port* port, void* payload = NULL); +extern void startup_die(SIGNAL_ARGS); +extern void PortInitialize(Port* port, knl_thread_arg* arg); +extern void PreClientAuthorize(); +extern int ClientConnInitilize(Port* port); +extern void CheckClientIp(Port* port); +extern Backend* GetBackend(int slot); +extern Backend* AssignFreeBackEnd(int slot); +extern long PostmasterRandom(void); +extern void signal_child(ThreadId pid, int signal, int be_mode); +extern void GenerateCancelKey(bool isThreadPoolSession); +extern bool SignalCancelAllBackEnd(); +extern bool IsLocalAddr(Port* port); +extern uint64_t mc_timers_us(void); +extern bool SetDBStateFileState(DbState state, bool optional); +extern void GPCResetAll(); +#endif /* _POSTMASTER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/remoteservice.h postgresql-hll-2.14/include/postmaster/remoteservice.h --- postgresql-hll-2.14_old/include/postmaster/remoteservice.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/remoteservice.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,30 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remoteservice.h + * + * + * + * IDENTIFICATION + * src/include/postmaster/remoteservice.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REMOTESERVICE_H +#define _REMOTESERVICE_H + +extern void RemoteServiceMain(void); + +#endif /* _REMOTESERVICE_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/startup.h postgresql-hll-2.14/include/postmaster/startup.h --- postgresql-hll-2.14_old/include/postmaster/startup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/startup.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,42 @@ +/* ------------------------------------------------------------------------- + * + * startup.h + * Exports from postmaster/startup.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/startup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _STARTUP_H +#define _STARTUP_H + +typedef enum { NOTIFY_PRIMARY = 0, NOTIFY_STANDBY, NOTIFY_FAILOVER, NOTIFY_SWITCHOVER, NUM_NOTIFYS } NotifyReason; + +/* + * Save the notify signal reason in the share memory. + * NotifySignalFlags include primary signal, standby signal and promote signal. + */ +typedef struct notifysignaldata { + sig_atomic_t NotifySignalFlags[NUM_NOTIFYS]; +} NotifySignalData; + +extern void StartupProcessMain(void); +extern void PreRestoreCommand(void); +extern void PostRestoreCommand(void); + +extern bool IsFailoverTriggered(void); +extern bool IsSwitchoverTriggered(void); +extern bool IsPrimaryTriggered(void); +extern bool IsStandbyTriggered(void); +extern void ResetSwitchoverTriggered(void); +extern void ResetFailoverTriggered(void); +extern void ResetPrimaryTriggered(void); +extern void ResetStandbyTriggered(void); + +extern Size NotifySignalShmemSize(void); +extern void NotifySignalShmemInit(void); +extern void SendNotifySignal(NotifyReason reason, ThreadId ProcPid); +extern bool CheckNotifySignal(NotifyReason reason); +#endif /* _STARTUP_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/syslogger.h postgresql-hll-2.14/include/postmaster/syslogger.h --- postgresql-hll-2.14_old/include/postmaster/syslogger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/syslogger.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,179 @@ +/* ------------------------------------------------------------------------- + * + * syslogger.h + * Exports from postmaster/syslogger.c. + * + * Copyright (c) 2004-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/syslogger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _SYSLOGGER_H +#define _SYSLOGGER_H + +#include /* for PIPE_BUF */ + +/* + * Primitive protocol structure for writing to syslogger pipe(s). The idea + * here is to divide long messages into chunks that are not more than + * PIPE_BUF bytes long, which according to POSIX spec must be written into + * the pipe atomically. The pipe reader then uses the protocol headers to + * reassemble the parts of a message into a single string. The reader can + * also cope with non-protocol data coming down the pipe, though we cannot + * guarantee long strings won't get split apart. + * + * We use non-nul bytes in is_last to make the protocol a tiny bit + * more robust against finding a false double nul byte prologue. But + * we still might find it in the len and/or pid bytes unless we're careful. + */ + +#ifdef PIPE_BUF +/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */ +#if PIPE_BUF > 65536 +#define LOGPIPE_CHUNK_SIZE 65536 +#else +#define LOGPIPE_CHUNK_SIZE ((int)PIPE_BUF) +#endif +#else /* not defined */ +/* POSIX says the value of PIPE_BUF must be at least 512, so use that */ +#define LOGPIPE_CHUNK_SIZE 512 +#endif + +#define PROFILE_LOG_TAG "gs_profile" +#define PROFILE_LOG_SUFFIX ".prf" +#define SLOWQUERY_LOG_TAG "sql_monitor" +#define ASP_LOG_TAG "asp_data" +#define PERF_JOB_TAG "pg_perf" + +enum LogType { + /* error log */ + LOG_TYPE_ELOG = 0, + + /* profiling log */ + LOG_TYPE_PLOG, + + /* slow query monitor log */ + LOG_TYPE_PLAN_LOG, + /* active session profile log */ + LOG_TYPE_ASP_LOG, + + /* a solider flag, LOG_TYPE_MAXVALID should be <= LOG_TYPE_UPLIMIT */ + LOG_TYPE_MAXVALID, + + /* + * max value of log type. + * it's stored by CHAR datatype. see LogPipeProtoHeader::logtype + */ + LOG_TYPE_UPLIMIT = 127 +}; + +typedef struct LogControlData { + bool inited; + uint16 ver; + + /* rotation request */ + volatile sig_atomic_t rotation_requested; + + /* to flush buffer request */ + volatile sig_atomic_t flush_requested; + + /* log directory */ + char* log_dir; + + /* pattern of log file name */ + char* filename_pattern; + char* file_suffix; + + /* current log file name and its fd */ + char* now_file_name; + FILE* now_file_fd; + + /* log chunk buffer */ + char* log_buf; + int cur_len; + int max_len; +} LogControlData; + +/* + * max length of this node name. this is a arbitrary value. + * just keep it the same with struct NameData. + */ +#define LOG_MAX_NODENAME_LEN 64 + +#define LOG_MAGICNUM 0x2017091810170000 +#define PROTO_HEADER_MAGICNUM 0x123456789ABCDEF0 +/* + * current log version about profile log + * advance it when log struct is modified each time. + */ +#define PROFILE_LOG_VERSION 1 + +/* header data in each binary log file */ +typedef struct { + /* must be the first */ + unsigned long fst_magic; + + uint16 version; + uint8 hostname_len; + uint8 nodename_len; + uint16 timezone_len; + + /* + * part1: hostname <- hostname_len + * part2: nodename <- nodename_len + * part3: timezone <- timezone_len + */ + + /* must be the last */ + unsigned long lst_magic; +} LogFileHeader; + +typedef struct { + char nuls[2]; /* always \0\0 */ + uint16 len; /* size of this chunk (counts data only) */ + char logtype; /* which log type, see LogType */ + char is_last; /* last chunk of message? 't' or 'f' ('T' or + * 'F' for CSV case) */ + /* writer's pid. be placed the last, and make data 8 bytes alligned */ + ThreadId pid; + uint64 magic; /* magic number to check the proto header */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */ +} LogPipeProtoHeader; + +typedef union { + LogPipeProtoHeader proto; + char filler[LOGPIPE_CHUNK_SIZE]; +} LogPipeProtoChunk; + +#define LOGPIPE_HEADER_SIZE offsetof(LogPipeProtoHeader, data) +#define LOGPIPE_MAX_PAYLOAD ((int)(LOGPIPE_CHUNK_SIZE - LOGPIPE_HEADER_SIZE)) + +extern THR_LOCAL bool am_syslogger; + +#ifndef WIN32 + +#else +extern THR_LOCAL HANDLE syslogPipe[2]; +#endif + +extern ThreadId SysLogger_Start(void); + +extern void SysLoggerClose(void); + +extern void write_syslogger_file(char* buffer, int count, int dest); + +#ifdef EXEC_BACKEND +extern void SysLoggerMain(int fd); +#endif + +extern void LogCtlLastFlushBeforePMExit(void); +extern void set_flag_to_flush_buffer(void); +extern void* SQMOpenLogFile(bool *doOpen); +extern void SQMCloseLogFile(); + +extern void* ASPOpenLogFile(bool *doOpen); +extern void ASPCloseLogFile(); +extern void init_instr_log_directory(bool include_nodename, const char* logid); + +#endif /* _SYSLOGGER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/twophasecleaner.h postgresql-hll-2.14/include/postmaster/twophasecleaner.h --- postgresql-hll-2.14_old/include/postmaster/twophasecleaner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/twophasecleaner.h 2020-12-12 17:06:43.363349535 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * twophasecleaner.h + * Automatically clean two-phase transaction + * + * + * IDENTIFICATION + * src/include/postmaster/twophasecleaner.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _TWOPHASECLEANER_H +#define _TWOPHASECLEANER_H + +extern bool bSyncXactsCallGsclean; + +extern PGPROC* twoPhaseCleanerProc; + +extern void TwoPhaseCleanerMain(); + +#endif /* _TWOPHASECLEANER_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/walwriterauxiliary.h postgresql-hll-2.14/include/postmaster/walwriterauxiliary.h --- postgresql-hll-2.14_old/include/postmaster/walwriterauxiliary.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/walwriterauxiliary.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * + * ------------------------------------------------------------------------- + * + * walwriterauxiliary.h + * Exports from postmaster/walwriterauxiliary.c. + * + * IDENTIFICATION + * src/include/postmaster/walwriterauxiliary.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALWRITERAUXILIARY_H +#define _WALWRITERAUXILIARY_H + +extern void WalWriterAuxiliaryMain(void); + +#endif /* _WALWRITERAUXILIARY_H */ diff -uprN postgresql-hll-2.14_old/include/postmaster/walwriter.h postgresql-hll-2.14/include/postmaster/walwriter.h --- postgresql-hll-2.14_old/include/postmaster/walwriter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/postmaster/walwriter.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * walwriter.h + * Exports from postmaster/walwriter.c. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/postmaster/walwriter.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALWRITER_H +#define _WALWRITER_H + +#ifdef ENABLE_MOT +typedef void (*WALCallback)(void* arg); + +extern void RegisterWALCallback(WALCallback callback, void* arg); +extern void CallWALCallback(); +#endif + +extern void WalWriterMain(void); + +#endif /* _WALWRITER_H */ diff -uprN postgresql-hll-2.14_old/include/regex/regcustom.h postgresql-hll-2.14/include/regex/regcustom.h --- postgresql-hll-2.14_old/include/regex/regcustom.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/regex/regcustom.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regcustom.h + */ + +/* headers if any */ +#include "postgres.h" +#include "knl/knl_variable.h" + +#include +#include + +/* + * towlower() and friends should be in , but some pre-C99 systems + * declare them in . + */ +#ifdef HAVE_WCHAR_H +#include +#endif +#ifdef HAVE_WCTYPE_H +#include +#endif + +#include "mb/pg_wchar.h" + +/* overrides for regguts.h definitions, if any */ +#define FUNCPTR(name, args) (*name) args +#define MALLOC(n) selfpalloc(n) +#define FREE(p) selfpfree(VS(p)) +#define REALLOC(p, n) selfrepalloc(VS(p), n) +#ifndef assert +#define assert(x) Assert(x) +#endif + +/* internal character type and related */ +typedef pg_wchar chr; /* the type itself */ +typedef unsigned uchr; /* unsigned type that will hold a chr */ +typedef int celt; /* type to hold chr, or NOCELT */ + +#define NOCELT (-1) /* celt value which is not valid chr */ +#define CHR(c) ((unsigned char)(c)) /* turn char literal into chr literal */ +#define DIGITVAL(c) ((c) - '0') /* turn chr digit into its value */ +#define CHRBITS 32 /* bits in a chr; must not use sizeof */ +#define CHR_MIN 0x00000000 /* smallest and largest chr; the value */ +#define CHR_MAX \ + 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and \ + * CHR_MAX+1 must fit in both chr and celt */ + +/* functions operating on chr */ +#define iscalnum(x) pg_wc_isalnum(x) +#define iscalpha(x) pg_wc_isalpha(x) +#define iscdigit(x) pg_wc_isdigit(x) +#define iscspace(x) pg_wc_isspace(x) + +/* and pick up the standard header */ +#include "regex.h" diff -uprN postgresql-hll-2.14_old/include/regex/regerrs.h postgresql-hll-2.14/include/regex/regerrs.h --- postgresql-hll-2.14_old/include/regex/regerrs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/regex/regerrs.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,45 @@ +/* + * src/include/regex/regerrs.h + */ +#ifndef REGERRS_H +#define REGERRS_H + +{REG_OKAY, "REG_OKAY", "no errors detected"}, + + {REG_NOMATCH, "REG_NOMATCH", "failed to match"}, + + {REG_BADPAT, "REG_BADPAT", "invalid regexp (reg version 0.8)"}, + + {REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"}, + + {REG_ECTYPE, "REG_ECTYPE", "invalid character class"}, + + {REG_EESCAPE, "REG_EESCAPE", "invalid escape \\ sequence"}, + + {REG_ESUBREG, "REG_ESUBREG", "invalid backreference number"}, + + {REG_EBRACK, "REG_EBRACK", "brackets [] not balanced"}, + + {REG_EPAREN, "REG_EPAREN", "parentheses () not balanced"}, + + {REG_EBRACE, "REG_EBRACE", "braces {} not balanced"}, + + {REG_BADBR, "REG_BADBR", "invalid repetition count(s)"}, + + {REG_ERANGE, "REG_ERANGE", "invalid character range"}, + + {REG_ESPACE, "REG_ESPACE", "out of memory"}, + + {REG_BADRPT, "REG_BADRPT", "quantifier operand invalid"}, + + {REG_ASSERT, "REG_ASSERT", "\"cannot happen\" -- you found a bug"}, + + {REG_INVARG, "REG_INVARG", "invalid argument to regex function"}, + + {REG_MIXED, "REG_MIXED", "character widths of regex and string differ"}, + + {REG_BADOPT, "REG_BADOPT", "invalid embedded option"}, + + {REG_ETOOBIG, "REG_ETOOBIG", "regular expression is too complex"}, + +#endif /* REGERRS_H */ diff -uprN postgresql-hll-2.14_old/include/regex/regex.h postgresql-hll-2.14/include/regex/regex.h --- postgresql-hll-2.14_old/include/regex/regex.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/regex/regex.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,179 @@ +#ifndef _REGEX_H_ +#define _REGEX_H_ /* never again */ +/* + * regular expressions + * + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regex.h + */ + +/* + * Add your own defines, if needed, here. + */ +#include "mb/pg_wchar.h" + +/* + * interface types etc. + */ + +/* + * regoff_t has to be large enough to hold either off_t or ssize_t, + * and must be signed; it's only a guess that long is suitable. + */ +typedef long regoff_t; + +/* + * other interface types + */ + +/* the biggie, a compiled RE (or rather, a front end to same) */ +typedef struct { + int re_magic; /* magic number */ + size_t re_nsub; /* number of subexpressions */ + long re_info; /* information about RE */ +#define REG_UBACKREF 000001 +#define REG_ULOOKAROUND 000002 +#define REG_UBOUNDS 000004 +#define REG_UBRACES 000010 +#define REG_UBSALNUM 000020 +#define REG_UPBOTCH 000040 +#define REG_UBBS 000100 +#define REG_UNONPOSIX 000200 +#define REG_UUNSPEC 000400 +#define REG_UUNPORT 001000 +#define REG_ULOCALE 002000 +#define REG_UEMPTYMATCH 004000 +#define REG_UIMPOSSIBLE 010000 +#define REG_USHORTEST 020000 + int re_csize; /* sizeof(character) */ + char* re_endp; /* backward compatibility kludge */ + Oid re_collation; /* Collation that defines LC_CTYPE behavior */ + /* the rest is opaque pointers to hidden innards */ + char* re_guts; /* `char *' is more portable than `void *' */ + char* re_fns; +} regex_t; + +/* result reporting (may acquire more fields later) */ +typedef struct { + regoff_t rm_so; /* start of substring */ + regoff_t rm_eo; /* end of substring */ +} regmatch_t; + +/* supplementary control and reporting */ +typedef struct { + regmatch_t rm_extend; /* see REG_EXPECT */ +} rm_detail_t; + +/* + * regex compilation flags + */ +#define REG_BASIC 000000 /* BREs (convenience) */ +#define REG_EXTENDED 000001 /* EREs */ +#define REG_ADVF 000002 /* advanced features in EREs */ +#define REG_ADVANCED 000003 /* AREs (which are also EREs) */ +#define REG_QUOTE 000004 /* no special characters, none */ +#define REG_NOSPEC REG_QUOTE /* historical synonym */ +#define REG_ICASE 000010 /* ignore case */ +#define REG_NOSUB 000020 /* don't care about subexpressions */ +#define REG_EXPANDED 000040 /* expanded format, white space & comments */ +#define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */ +#define REG_NLANCH 000200 /* ^ matches after \n, $ before */ +#define REG_NEWLINE 000300 /* newlines are line terminators */ +#define REG_PEND 000400 /* ugh -- backward-compatibility hack */ +#define REG_EXPECT 001000 /* report details on partial/limited matches */ +#define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */ +#define REG_DUMP 004000 /* none of your business :-) */ +#define REG_FAKE 010000 /* none of your business :-) */ +#define REG_PROGRESS 020000 /* none of your business :-) */ + +/* + * regex execution flags + */ +#define REG_NOTBOL 0001 /* BOS is not BOL */ +#define REG_NOTEOL 0002 /* EOS is not EOL */ +#define REG_STARTEND 0004 /* backward compatibility kludge */ +#define REG_FTRACE 0010 /* none of your business */ +#define REG_MTRACE 0020 /* none of your business */ +#define REG_SMALL 0040 /* none of your business */ + +/* + * error reporting + * Be careful if modifying the list of error codes -- the table used by + * regerror() is generated automatically from this file! + */ +#define REG_OKAY 0 /* no errors detected */ +#define REG_NOMATCH 1 /* failed to match */ +#define REG_BADPAT 2 /* invalid regexp */ +#define REG_ECOLLATE 3 /* invalid collating element */ +#define REG_ECTYPE 4 /* invalid character class */ +#define REG_EESCAPE 5 /* invalid escape \ sequence */ +#define REG_ESUBREG 6 /* invalid backreference number */ +#define REG_EBRACK 7 /* brackets [] not balanced */ +#define REG_EPAREN 8 /* parentheses () not balanced */ +#define REG_EBRACE 9 /* braces {} not balanced */ +#define REG_BADBR 10 /* invalid repetition count(s) */ +#define REG_ERANGE 11 /* invalid character range */ +#define REG_ESPACE 12 /* out of memory */ +#define REG_BADRPT 13 /* quantifier operand invalid */ +#define REG_ASSERT 15 /* "can't happen" -- you found a bug */ +#define REG_INVARG 16 /* invalid argument to regex function */ +#define REG_MIXED 17 /* character widths of regex and string differ */ +#define REG_BADOPT 18 /* invalid embedded option */ +#define REG_ETOOBIG 19 /* regular expression is too complex */ +/* two specials for debugging and testing */ +#define REG_ATOI 101 /* convert error-code name to number */ +#define REG_ITOA 102 /* convert error-code number to name */ +/* non-error result codes for pg_regprefix */ +#define REG_PREFIX (-1) /* identified a common prefix */ +#define REG_EXACT (-2) /* identified an exact match */ + +/* this is the maximum number of cached regular expressions */ +#ifndef MAX_CACHED_RES +#define MAX_CACHED_RES 32 +#endif + +/* this structure describes one cached regular expression */ +typedef struct cached_re_str { + char* cre_pat; /* original RE (not null terminated!) */ + int cre_pat_len; /* length of original RE, in bytes */ + int cre_flags; /* compile flags: extended,icase etc */ + Oid cre_collation; /* collation to use */ + regex_t cre_re; /* the compiled regular expression */ +} cached_re_str; + +/* + * the prototypes for exported functions + */ +extern int pg_regcomp(regex_t*, const pg_wchar*, size_t, int, Oid); +extern int pg_regexec(regex_t*, const pg_wchar*, size_t, size_t, rm_detail_t*, size_t, regmatch_t[], int); +extern int pg_regprefix(regex_t*, pg_wchar**, size_t*); +extern void pg_regfree(regex_t*); +extern size_t pg_regerror(int, const regex_t*, char*, size_t); +extern void pg_set_regex_collation(Oid collation); + +#endif /* _REGEX_H_ */ diff -uprN postgresql-hll-2.14_old/include/regex/regguts.h postgresql-hll-2.14/include/regex/regguts.h --- postgresql-hll-2.14_old/include/regex/regguts.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/regex/regguts.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,459 @@ +/* + * Internal interface definitions, etc., for the reg package + * + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * + * Development of this software was funded, in part, by Cray Research Inc., + * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics + * Corporation, none of whom are responsible for the results. The author + * thanks all of them. + * + * Redistribution and use in source and binary forms -- with or without + * modification -- are permitted for any purpose, provided that + * redistributions in source form retain this entire copyright notice and + * indicate the origin and nature of any modifications. + * + * I'd appreciate being given credit for this package in the documentation + * of software which uses it, but that is not a requirement. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * src/include/regex/regguts.h + */ + +/* + * Environmental customization. It should not (I hope) be necessary to + * alter the file you are now reading -- regcustom.h should handle it all, + * given care here and elsewhere. + */ +#include "regcustom.h" + +/* + * Things that regcustom.h might override. + */ + +/* assertions */ +#ifndef assert +#ifndef REG_DEBUG +#define NDEBUG /* no assertions */ +#endif +#include +#endif + +/* voids */ +#ifndef DISCARD +#define DISCARD void /* for throwing values away */ +#endif +#ifndef VS +#define VS(x) ((void*)(x)) /* cast something to generic ptr */ +#endif + +/* function-pointer declarator */ +#ifndef FUNCPTR +#define FUNCPTR(name, args) (*(name)) args +#endif + +/* memory allocation */ +#ifndef MALLOC +#define MALLOC(n) selfpalloc(n) +#endif +#ifndef REALLOC +#define REALLOC(p, n) selfrepalloc(VS(p), n) +#endif +#ifndef FREE +#define FREE(p) selfpfree(VS(p)) +#endif + +/* want size of a char in bits, and max value in bounded quantifiers */ +#ifndef CHAR_BIT +#include +#endif +#ifndef _POSIX2_RE_DUP_MAX +#define _POSIX2_RE_DUP_MAX 255 /* normally from */ +#endif + +/* + * misc + */ + +#define NOTREACHED 0 + +#define DUPMAX _POSIX2_RE_DUP_MAX +#ifdef INFINITY +#undef INFINITY +#endif +#define INFINITY (DUPMAX + 1) + +#define REMAGIC 0xfed7 /* magic number for main struct */ + +/* Type codes for lookaround constraints */ +#define LATYPE_AHEAD_POS 03 /* positive lookahead */ +#define LATYPE_AHEAD_NEG 02 /* negative lookahead */ +#define LATYPE_BEHIND_POS 01 /* positive lookbehind */ +#define LATYPE_BEHIND_NEG 00 /* negative lookbehind */ +#define LATYPE_IS_POS(la) ((la)&01) +#define LATYPE_IS_AHEAD(la) ((la)&02) + +/* + * debugging facilities + */ +#ifdef REG_DEBUG +/* FDEBUG does finite-state tracing */ +#define FDEBUG(arglist) \ + { \ + if (v->eflags & REG_FTRACE) \ + printf arglist; \ + } +/* MDEBUG does higher-level tracing */ +#define MDEBUG(arglist) \ + { \ + if (v->eflags & REG_MTRACE) \ + printf arglist; \ + } +#else +#define FDEBUG(arglist) \ + {} +#define MDEBUG(arglist) \ + {} +#endif + +/* + * bitmap manipulation + */ +#define UBITS (CHAR_BIT * sizeof(unsigned)) +#define BSET(uv, sn) ((uv)[(sn) / UBITS] |= (unsigned)1 << ((sn) % UBITS)) +#define ISBSET(uv, sn) ((uv)[(sn) / UBITS] & ((unsigned)1 << ((sn) % UBITS))) + +/* + * We dissect a chr into byts for colormap table indexing. Here we define + * a byt, which will be the same as a byte on most machines... The exact + * size of a byt is not critical, but about 8 bits is good, and extraction + * of 8-bit chunks is sometimes especially fast. + */ +#ifndef BYTBITS +#define BYTBITS 8 /* bits in a byt */ +#endif +#define BYTTAB (1 << BYTBITS) /* size of table with one entry per byt value */ +#define BYTMASK (BYTTAB - 1) /* bit mask for byt */ +#define NBYTS ((CHRBITS + BYTBITS - 1) / BYTBITS) +/* the definition of GETCOLOR(), below, assumes NBYTS <= 4 */ + +/* + * As soon as possible, we map chrs into equivalence classes -- "colors" -- + * which are of much more manageable number. + */ +typedef short color; /* colors of characters */ +typedef int pcolor; /* what color promotes to */ + +#define COLORLESS (-1) /* impossible color */ +#define WHITE 0 /* default color, parent of all others */ + +/* + * A colormap is a tree -- more precisely, a DAG -- indexed at each level + * by a byt of the chr, to map the chr to a color efficiently. Because + * lower sections of the tree can be shared, it can exploit the usual + * sparseness of such a mapping table. The tree is always NBYTS levels + * deep (in the past it was shallower during construction but was "filled" + * to full depth at the end of that); areas that are unaltered as yet point + * to "fill blocks" which are entirely WHITE in color. + */ + +/* the tree itself */ +struct colors { + color ccolor[BYTTAB]; +}; +struct ptrs { + union tree* pptr[BYTTAB]; +}; +union tree { + struct colors colors; + struct ptrs ptrs; +}; + +#define tcolor colors.ccolor +#define tptr ptrs.pptr + +/* + * Per-color data structure for the compile-time color machinery + * + * If "sub" is not NOSUB then it is the number of the color's current + * subcolor, i.e. we are in process of dividing this color (character + * equivalence class) into two colors. See src/backend/regex/README for + * discussion of subcolors. + * + * Currently-unused colors have the FREECOL bit set and are linked into a + * freelist using their "sub" fields, but only if their color numbers are + * less than colormap.max. Any array entries beyond "max" are just garbage. + */ +struct colordesc { + uchr nchrs; /* number of chars of this color */ + color sub; /* open subcolor, if any; or free-chain ptr */ +#define NOSUB COLORLESS /* value of "sub" when no open subcolor */ + struct arc* arcs; /* chain of all arcs of this color */ + chr firstchr; /* char first assigned to this color */ + int flags; /* bit values defined next */ +#define FREECOL 01 /* currently free */ +#define PSEUDO 02 /* pseudocolor, no real chars */ +#define UNUSEDCOLOR(cd) ((cd)->flags & FREECOL) + union tree* block; /* block of solid color, if any */ +}; + +/* + * The color map itself + * + * Much of the data in the colormap struct is only used at compile time. + * However, the bulk of the space usage is in the "tree" structure, so it's + * not clear that there's much point in converting the rest to a more compact + * form when compilation is finished. + */ +struct colormap { + int magic; +#define CMMAGIC 0x876 + struct vars* v; /* for compile error reporting */ + size_t ncds; /* allocated length of colordescs array */ + size_t max; /* highest color number currently in use */ + color free; /* beginning of free chain (if non-0) */ + struct colordesc* cd; /* pointer to array of colordescs */ +#define CDEND(cm) (&(cm)->cd[(cm)->max + 1]) + /* If we need up to NINLINECDS, we store them here to save a malloc */ +#define NINLINECDS ((size_t)10) + struct colordesc cdspace[NINLINECDS]; + union tree tree[NBYTS]; /* tree top, plus lower-level fill blocks */ +}; + +/* optimization magic to do fast chr->color mapping */ +#define B0(c) ((c)&BYTMASK) +#define B1(c) (((c) >> BYTBITS) & BYTMASK) +#define B2(c) (((c) >> (2 * BYTBITS)) & BYTMASK) +#define B3(c) (((c) >> (3 * BYTBITS)) & BYTMASK) +#if NBYTS == 1 +#define GETCOLOR(cm, c) ((cm)->tree->tcolor[B0(c)]) +#endif +/* beware, for NBYTS>1, GETCOLOR() is unsafe -- 2nd arg used repeatedly */ +#if NBYTS == 2 +#define GETCOLOR(cm, c) ((cm)->tree->tptr[B1(c)]->tcolor[B0(c)]) +#endif +#if NBYTS == 4 +#define GETCOLOR(cm, c) ((cm)->tree->tptr[B3(c)]->tptr[B2(c)]->tptr[B1(c)]->tcolor[B0(c)]) +#endif + +/* + * Interface definitions for locale-interface functions in regc_locale.c. + */ + +/* + * Representation of a set of characters. chrs[] represents individual + * code points, ranges[] represents ranges in the form min..max inclusive. + * + * Note that in cvecs gotten from newcvec() and intended to be freed by + * freecvec(), both arrays of chrs are after the end of the struct, not + * separately malloc'd; so chrspace and rangespace are effectively immutable. + */ +struct cvec { + int nchrs; /* number of chrs */ + int chrspace; /* number of chrs allocated in chrs[] */ + chr* chrs; /* pointer to vector of chrs */ + int nranges; /* number of ranges (chr pairs) */ + int rangespace; /* number of ranges allocated in ranges[] */ + chr* ranges; /* pointer to vector of chr pairs */ +}; + +/* + * definitions for NFA internal representation + * + * Having a "from" pointer within each arc may seem redundant, but it + * saves a lot of hassle. + */ +struct state; + +struct arc { + int type; /* 0 if free, else an NFA arc type code */ + color co; + struct state* from; /* where it's from (and contained within) */ + struct state* to; /* where it's to */ + struct arc* outchain; /* link in *from's outs chain or free chain */ + struct arc* outchainRev; /* back-link in *from's outs chain */ +#define freechain outchain /* we do not maintain "freechainRev" */ + struct arc* inchain; /* link in *to's ins chain */ + struct arc* inchainRev; /* back-link in *to's ins chain */ + struct arc* colorchain; /* link in color's arc chain */ + struct arc* colorchainRev; /* back-link in color's arc chain */ +}; + +struct arcbatch { /* for bulk allocation of arcs */ + struct arcbatch* next; +#define ABSIZE 10 + struct arc a[ABSIZE]; +}; + +struct state { + int no; +#define FREESTATE (-1) + char flag; /* marks special states */ + int nins; /* number of inarcs */ + struct arc* ins; /* chain of inarcs */ + int nouts; /* number of outarcs */ + struct arc* outs; /* chain of outarcs */ + struct arc* free; /* chain of free arcs */ + struct state* tmp; /* temporary for traversal algorithms */ + struct state* next; /* chain for traversing all */ + struct state* prev; /* back chain */ + struct arcbatch oas; /* first arcbatch, avoid malloc in easy case */ + int noas; /* number of arcs used in first arcbatch */ +}; + +struct nfa { + struct state* pre; /* pre-initial state */ + struct state* init; /* initial state */ + struct state* final; /* final state */ + struct state* post; /* post-final state */ + int nstates; /* for numbering states */ + struct state* states; /* state-chain header */ + struct state* slast; /* tail of the chain */ + struct state* free; /* free list */ + struct colormap* cm; /* the color map */ + color bos[2]; /* colors, if any, assigned to BOS and BOL */ + color eos[2]; /* colors, if any, assigned to EOS and EOL */ + struct vars* v; /* simplifies compile error reporting */ + struct nfa* parent; /* parent NFA, if any */ +}; + +/* + * definitions for compacted NFA + * + * The main space savings in a compacted NFA is from making the arcs as small + * as possible. We store only the transition color and next-state number for + * each arc. The list of out arcs for each state is an array beginning at + * cnfa.states[statenumber], and terminated by a dummy carc struct with + * co == COLORLESS. + * + * The non-dummy carc structs are of two types: plain arcs and LACON arcs. + * Plain arcs just store the transition color number as "co". LACON arcs + * store the lookaround constraint number plus cnfa.ncolors as "co". LACON + * arcs can be distinguished from plain by testing for co >= cnfa.ncolors. + */ +struct carc { + color co; /* COLORLESS is list terminator */ + int to; /* next-state number */ +}; + +struct cnfa { + int nstates; /* number of states */ + int ncolors; /* number of colors (max color in use + 1) */ + int flags; +#define HASLACONS 01 /* uses lookaround constraints */ + int pre; /* setup state number */ + int post; /* teardown state number */ + color bos[2]; /* colors, if any, assigned to BOS and BOL */ + color eos[2]; /* colors, if any, assigned to EOS and EOL */ + char* stflags; /* vector of per-state flags bytes */ +#define CNFA_NOPROGRESS 01 /* flag bit for a no-progress state */ + struct carc** states; /* vector of pointers to outarc lists */ + /* states[n] are pointers into a single malloc'd array of arcs */ + struct carc* arcs; /* the area for the lists */ +}; + +#define ZAPCNFA(cnfa) ((cnfa).nstates = 0) +#define NULLCNFA(cnfa) ((cnfa).nstates == 0) + +/* + * This symbol limits the transient heap space used by the regex compiler, + * and thereby also the maximum complexity of NFAs that we'll deal with. + * Currently we only count NFA states and arcs against this; the other + * transient data is generally not large enough to notice compared to those. + * Note that we do not charge anything for the final output data structures + * (the compacted NFA and the colormap). + */ +#ifndef REG_MAX_COMPILE_SPACE +#define REG_MAX_COMPILE_SPACE (100000 * sizeof(struct state) + 100000 * sizeof(struct arcbatch)) +#endif + +/* + * subexpression tree + * + * "op" is one of: + * '=' plain regex without interesting substructure (implemented as DFA) + * 'b' back-reference (has no substructure either) + * '(' capture node: captures the match of its single child + * '.' concatenation: matches a match for left, then a match for right + * '|' alternation: matches a match for left or a match for right + * '*' iteration: matches some number of matches of its single child + * + * Note: the right child of an alternation must be another alternation or + * NULL; hence, an N-way branch requires N alternation nodes, not N-1 as you + * might expect. This could stand to be changed. Actually I'd rather see + * a single alternation node with N children, but that will take revising + * the representation of struct subre. + * + * Note: when a backref is directly quantified, we stick the min/max counts + * into the backref rather than plastering an iteration node on top. This is + * for efficiency: there is no need to search for possible division points. + */ +struct subre { + char op; /* see type codes above */ + char flags; +#define LONGER 01 /* prefers longer match */ +#define SHORTER 02 /* prefers shorter match */ +#define MIXED 04 /* mixed preference below */ +#define CAP 010 /* capturing parens below */ +#define BACKR 020 /* back reference below */ +#define INUSE 0100 /* in use in final tree */ +#define LOCAL 03 /* bits which may not propagate up */ +#define LMIX(f) ((f) << 2) /* LONGER -> MIXED */ +#define SMIX(f) ((f) << 1) /* SHORTER -> MIXED */ +#define UP(f) (((f) & ~LOCAL) | (LMIX(f) & SMIX(f) & MIXED)) +#define MESSY(f) ((f) & (MIXED | CAP | BACKR)) +#define PREF(f) ((f)&LOCAL) +#define PREF2(f1, f2) ((PREF(f1) != 0) ? PREF(f1) : PREF(f2)) +#define COMBINE(f1, f2) (UP((f1) | (f2)) | PREF2(f1, f2)) + short id; /* ID of subre (1..ntree-1) */ + int subno; /* subexpression number (for 'b' and '('), or + * LATYPE code for lookaround constraint */ + short min; /* min repetitions for iteration or backref */ + short max; /* max repetitions for iteration or backref */ + struct subre* left; /* left child, if any (also freelist chain) */ + struct subre* right; /* right child, if any */ + struct state* begin; /* outarcs from here... */ + struct state* end; /* ...ending in inarcs here */ + struct cnfa cnfa; /* compacted NFA, if any */ + struct subre* chain; /* for bookkeeping and error cleanup */ +}; + +/* + * table of function pointers for generic manipulation functions + * A regex_t's re_fns points to one of these. + */ +struct fns { + void FUNCPTR(pfree, (regex_t*)); + int FUNCPTR(stack_too_deep, (void)); +}; + +#define STACK_TOO_DEEP(re) ((*((struct fns*)(re)->re_fns)->stack_too_deep)()) + +/* + * the insides of a regex_t, hidden behind a void * + */ +struct guts { + int magic; +#define GUTSMAGIC 0xfed9 + int cflags; /* copy of compile flags */ + long info; /* copy of re_info */ + size_t nsub; /* copy of re_nsub */ + struct subre* tree; + struct cnfa search; /* for fast preliminary search */ + int ntree; /* number of subre's, less one */ + struct colormap cmap; + int FUNCPTR(compare, (const chr*, const chr*, size_t)); + struct subre* lacons; /* lookaround-constraint vector */ + int nlacons; /* size of lacons[]; note that only slots + * numbered 1 .. nlacons-1 are used */ +}; diff -uprN postgresql-hll-2.14_old/include/replication/basebackup.h postgresql-hll-2.14/include/replication/basebackup.h --- postgresql-hll-2.14_old/include/replication/basebackup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/basebackup.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,43 @@ +/* ------------------------------------------------------------------------- + * + * basebackup.h + * Exports from replication/basebackup.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/basebackup.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _BASEBACKUP_H +#define _BASEBACKUP_H + +#include "nodes/replnodes.h" + +/* + * Maximum file size for a tar member: The limit inherent in the + * format is 2^33-1 bytes (nearly 8 GB). But we don't want to exceed + * what we can represent in pgoff_t. + */ +#define MAX_TAR_MEMBER_FILELEN (((int64)1 << Min(33, sizeof(pgoff_t) * 8 - 1)) - 1) + +#define MAX_FILE_SIZE_LIMIT ((0x80000000)) + +typedef struct { + char* oid; + char* path; + char* relativePath; + int64 size; +} tablespaceinfo; + +extern XLogRecPtr XlogCopyStartPtr; + +extern void SendBaseBackup(BaseBackupCmd* cmd); +extern bool is_row_data_file(const char* filePath, int* segNo); +#ifdef ENABLE_MOT +extern void PerformMotCheckpointFetch(); +#endif + +/* ut test */ +extern void ut_save_xlogloc(const char* xloglocation); +#endif /* _BASEBACKUP_H */ diff -uprN postgresql-hll-2.14_old/include/replication/bcm.h postgresql-hll-2.14/include/replication/bcm.h --- postgresql-hll-2.14_old/include/replication/bcm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/bcm.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,171 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bcm.h + * bcm map interface + * + * + * IDENTIFICATION + * src/include/replication/bcm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BCM_H +#define BCM_H + +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +typedef uint32 BCMBitStatus; + +#define SYNCED 0U +#define NOTSYNCED 1 +#define BACKUP 0 +#define NOTBACKUP 1 + +typedef struct BCMHeader { + StorageEngine type; + RelFileNode node; + int32 blockSize; /* one bit corresponding size */ +} BCMHeader; + +/* + * Size of the bitmap on each bcm map page, in bytes. There's no + * extra headers, so the whole page minus the standard page header is + * used for the bitmap. + */ +#define BCMMAPSIZE (BLCKSZ - MAXALIGN(SizeOfPageHeaderData)) + +/* Number of bits allocated for each heap block. */ +#define BCM_BITS_PER_BLOCK 2 + +/* Number of heap blocks we can represent in one byte. */ +#define BCM_BLOCKS_PER_BYTE 4 + +/* Number of blocks we can represent in one bcm map page. */ +#define BCM_BLOCKS_PER_PAGE (BCMMAPSIZE * BCM_BLOCKS_PER_BYTE) + +/* 10 */ +#define BCM_SYNC_BITMASK 2U +/* 01 */ +#define BCM_BACKUP_BITMASK 1 + +/* max continous bits which should be no more than max CU load sizes */ +#define MAXCONTIBITS ((512 * 1024) / ALIGNOF_CUSIZE) + +/* 1000 */ +#define META_SYNC0_BITMASK 8U +/* 0100 */ +#define META_BACKUP0_BITMASK 4 +/* 0010 */ +#define META_SYNC1_BITMASK 2U +/* 0001 */ +#define META_BACKUP1_BITMASK 1 + +/* Number of bits allocated for each bcm block. */ +#define META_BITS_PER_BLOCK 4 + +/* Number of bcm blocks we can represent in one byte. */ +#define META_BLOCKS_PER_BYTE 2 + +/* Number of blocks we can represent in one mata page. */ +#define META_BLOCKS_PER_PAGE (BCMMAPSIZE * META_BLOCKS_PER_BYTE) + +/* + * Mapping from bcm block number to the right bit in the right bcm meta page + * Page0 is for bcm file header, so logically the bcm file is just like as follow: + * Page0-Meta1-Page11-Page12-...Page1N-Meta2-Page21-Page22... + */ +#define BCMBLK_TO_BCMGROUP(x) (((x)-1) / (META_BLOCKS_PER_PAGE + 1)) +#define BCMBLK_TO_METABLOCK(x) (BCMBLK_TO_BCMGROUP(x) * (META_BLOCKS_PER_PAGE + 1) + 1) +#define BCMBLK_TO_METABYTE(x) (((x)-BCMBLK_TO_METABLOCK(x) - 1) / META_BLOCKS_PER_BYTE) +#define BCMBLK_TO_METABIT(x) (((x)-BCMBLK_TO_METABLOCK(x) - 1) % META_BLOCKS_PER_BYTE) + +/* Mapping from heap block number to the right bit in the BCM map */ +/* Page 0 is for bcm file header, Page 1 is for meta page, so we begin from page 2 */ +#define UNITBLK_TO_BCMGROUP(x) ((x) / BCM_BLOCKS_PER_PAGE / META_BLOCKS_PER_PAGE) +#define HEAPBLK_TO_BCMBLOCK(x) (((x) / BCM_BLOCKS_PER_PAGE) + UNITBLK_TO_BCMGROUP(x) + 2) +#define HEAPBLK_TO_BCMBYTE(x) (((x) % BCM_BLOCKS_PER_PAGE) / BCM_BLOCKS_PER_BYTE) +#define HEAPBLK_TO_BCMBIT(x) ((x) % BCM_BLOCKS_PER_BYTE) + +#define SET_SYNC_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(BCM_SYNC_BITMASK << bshift); \ + byteval |= (status << (bshift + 1)); \ + byte = byteval; \ + } while (0) + +#define SET_SYNC0_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(META_SYNC0_BITMASK << bshift); \ + byteval |= (status << (bshift + 3)); \ + byte = byteval; \ + } while (0) + +#define SET_SYNC1_BYTE_STATUS(byte, status, bshift) \ + do { \ + unsigned char byteval = byte; \ + byteval &= ~(unsigned char)(META_SYNC1_BITMASK << bshift); \ + byteval |= (status << (bshift + 1)); \ + byte = byteval; \ + } while (0) + +/* + * The algorithm is very clear, we devide this into two parts: + * 1. the total heap blocks in previous actual bcm pages. + * 2. the total heap blocks in current bcm page + */ +#define GET_HEAP_BLOCK(block, byte, bshift) \ + ((block - BCMBLK_TO_BCMGROUP(block) - 2) * BCM_BLOCKS_PER_PAGE + (byte)*BCM_BLOCKS_PER_BYTE + (bshift)) + +/* Here the block should be meta block */ +#define GET_BCM_BLOCK(block, byte, bshift) (block + (byte)*META_BLOCKS_PER_BYTE + (bshift) + 1) + +/* Create a bcm file and init the file header */ +extern void createBCMFile(Relation rel); + +/* record one bcm xlog for cu */ +extern void BCMLogCU(Relation rel, uint64 offset, int col, BCMBitStatus status, int count); + +/* Set the corresponding bit of the block as status */ +extern void BCMSetStatusBit(Relation rel, uint64 heapBlk, Buffer buf, BCMBitStatus status, int col = 0); + +/* BCM clear */ +extern void BCMClearRel(Relation rel, int col = 0); +extern void BCM_truncate(Relation rel); + +/* BCM Traversal */ +extern void GetBcmFileList(bool clear); +extern void GetIncrementalBcmFileList(); + +/* BCM xlog for setStatusBit is (RM_HEAP2_ID, XLOG_HEAP2_BCM) type */ +/* Functions in heapam.cpp: log_heap_bcm(...);heap_xlog_bcm(...)*/ + +/* BCM pin */ +extern void BCM_pin(Relation rel, BlockNumber heapBlk, Buffer* bcmbuf); + +extern void BCM_CStore_pin(Relation rel, int col, uint64 offset, Buffer* buf); + +extern void check_cu_block(char* mem, int size, int alignSize); + +extern uint64 cstore_offset_to_cstoreblock(uint64 offset, uint64 align_size); + +extern uint64 cstore_offset_to_bcmblock(uint64 offset, uint64 align_size); + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/catchup.h postgresql-hll-2.14/include/replication/catchup.h --- postgresql-hll-2.14_old/include/replication/catchup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/catchup.h 2020-12-12 17:06:43.364349548 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * catchup.h + * Exports from replication/data/catchup.cpp. + * + * + * IDENTIFICATION + * src/include/replication/catchup.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CATCHUP_H +#define CATCHUP_H + +#include + +typedef enum { CATCHUP_NONE = 0, CATCHUP_STARTING, CATCHUP_SEARCHING, RECEIVED_OK, RECEIVED_NONE } CatchupState; + +extern volatile bool catchup_online; +extern volatile bool catchupDone; +extern CatchupState catchupState; + +extern bool IsCatchupProcess(void); +extern ThreadId StartCatchup(void); +extern void CatchupShutdownIfNoDataSender(void); + +#ifdef EXEC_BACKEND +extern void CatchupMain(); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/dataprotocol.h postgresql-hll-2.14/include/replication/dataprotocol.h --- postgresql-hll-2.14_old/include/replication/dataprotocol.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/dataprotocol.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,153 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataprotocol.h + * Definitions relevant to the streaming DATA transmission protocol. + * + * + * IDENTIFICATION + * src/include/replication/dataprotocol.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATAPROTOCOL_H +#define _DATAPROTOCOL_H + +#include "access/xlogdefs.h" +#include "replication/dataqueuedefs.h" +#include "replication/replicainternal.h" +#include "datatype/timestamp.h" + +/* + * All messages from DataSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct { + DataQueuePtr sendPosition; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; + bool catchup; +} DataSndMessage; + +/* + * Header for a data replication message (message type 'd'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual data page. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* data start location of the data queue included in this message */ + DataQueuePtr dataStart; + + /* data end location of the data queue included in this message */ + DataQueuePtr dataEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + bool catchup; +} DataPageMessageHeader; + +/* + * Keepalive message from primary (message type 'k'). (lowercase k) + * This is wrapped within a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef DataSndMessage DataSndKeepaliveMessage; + +/*Notify message structure for dummy scan incremental files for catchup */ +typedef struct { + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} NotifyDummyCatchupMessage; + +/* + * Refence :PrimaryKeepaliveMessage + */ +typedef struct EndDataMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + int percent; +} EndDataMessage; + +/* + * Refence :PrimaryKeepaliveMessage + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct RmDataMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} RmDataMessage; + +/* + * Reply message from standby (message type 'r'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyDataReplyMessage { + DataQueuePtr receivePosition; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the server should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} StandbyDataReplyMessage; + +/* + * Maximum data payload in data message. Must be >= XLOG_BLCKSZ. + * + * We don't have a good idea of what a good value would be; there's some + * overhead per message in both walsender and walreceiver, but on the other + * hand sending large batches makes walsender less responsive to signals + * because signals are checked only between messages. 128kB (with + * default 8k blocks) seems like a reasonable guess for now. + */ +#define MAX_SEND_SIZE (XLOG_BLCKSZ * 16) + +#endif /* _DATAPROTOCOL_H */ diff -uprN postgresql-hll-2.14_old/include/replication/dataqueuedefs.h postgresql-hll-2.14/include/replication/dataqueuedefs.h --- postgresql-hll-2.14_old/include/replication/dataqueuedefs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/dataqueuedefs.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataqueuedefs.h + * Data replication queue pointer r definitions + * + * + * IDENTIFICATION + * src/include/replication/dataqueuedefs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DATAQUEUE_DEFS_H +#define DATAQUEUE_DEFS_H + +/* Pointer to a location in the queue. */ +typedef struct DataQueuePtr { + uint32 queueid; /* data queue id, 0 based */ + uint32 queueoff; /* byte offset of location in current queue */ +} DataQueuePtr; + +/* + * Macros for comparing DataQueuePtrs + * + * Beware of passing expressions with side-effects to these macros, + * since the arguments may be evaluated multiple times. + */ +#define DQByteLT(a, b) ((a).queueid < (b).queueid || ((a).queueid == (b).queueid && (a).queueoff < (b).queueoff)) +#define DQByteLE(a, b) ((a).queueid < (b).queueid || ((a).queueid == (b).queueid && (a).queueoff <= (b).queueoff)) +#define DQByteEQ(a, b) ((a).queueid == (b).queueid && (a).queueoff == (b).queueoff) + +#define DataQueuePtrIsInvalid(r) ((r).queueoff == 0) + +/* + * Macro for advancing a queue pointer by the specified number of bytes. + */ +#define DQByteAdvance(queueptr, nbytes) \ + do { \ + if (queueptr.queueoff > (uint32)g_instance.attr.attr_storage.DataQueueBufSize * 1024 - nbytes) { \ + queueptr.queueid += 1; \ + queueptr.queueoff = \ + (uint32)(queueptr.queueoff + nbytes - (uint32)g_instance.attr.attr_storage.DataQueueBufSize * 1024); \ + } else \ + queueptr.queueoff += nbytes; \ + } while (0) + +#endif /* DATAQUEU_DEFS_H */ diff -uprN postgresql-hll-2.14_old/include/replication/dataqueue.h postgresql-hll-2.14/include/replication/dataqueue.h --- postgresql-hll-2.14_old/include/replication/dataqueue.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/dataqueue.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,119 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dataqueue.h + * + * + * + * IDENTIFICATION + * src/include/replication/dataqueue.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATAQUEUE_H +#define _DATAQUEUE_H + +#include "c.h" +#include "gs_threadlocal.h" +#include "replication/dataqueuedefs.h" +#include "replication/bcm.h" +#include "storage/s_lock.h" +#include "utils/hsearch.h" +#include "utils/pg_crc.h" + +#define WS_MAX_DATA_QUEUE_SIZE (uint32)(g_instance.attr.attr_storage.DataQueueBufSize * 1024) + +#define GETATTID(attid) ((attid) & 0xffff) +#define GETBUCKETID(attid) (((uint)(attid) >> 16) - 1) + +/* + *------------------------------------------------------ + * |****************| |**************| | + * ----------------------------------------------------- + * 0 use_tail1 use_head2 use_tail2 tail + * + * From use_tail1 to use_head2 and from use_tail2 to tail are freespace + */ +typedef struct DataQueueData { + uint32 size; /* memory size */ + + DataQueuePtr use_tail1; + DataQueuePtr use_head2; /* from use_head2 to use_tail2 are elements */ + DataQueuePtr use_tail2; + slock_t use_mutex; /* protect above variables */ + + char* pages; +} DataQueueData, *DataQueue; + +typedef struct DataElementHeaderData { + RelFileNodeOld rnode; + BlockNumber blocknum; + int attid; /* column storage id */ + StorageEngine type; + + uint64 offset; /* offset the element to be written */ + uint32 data_size; /* element size */ + DataQueuePtr queue_offset; /* current page offset in queue */ + + XLogRecPtr ref_rec_ptr; /* the associated ref xlog ptr */ + +#ifdef DATA_DEBUG + pg_crc32 data_crc; /* CRC for current page */ +#endif +} DataElementHeaderData, *DataElementHeader; + +typedef struct BCMElementData { + RelFileNodeOld rnode; + BlockNumber blocknum; + int attid; /* column storage id */ + StorageEngine type; + uint64 offset; /* offset the element to be written */ + uint32 data_size; /* element size */ + bool is_vaild; /* is this block vaild ? */ +} BCMElementData, *BCMElement; + +typedef struct heap_sync_rel_key { + Oid rd_id; /* the relation */ +} heap_sync_rel_key; + +typedef struct heap_sync_rel { + heap_sync_rel_key key; /* hash key ... must be first */ +} heap_sync_rel; + +extern Size DataQueueShmemSize(void); +extern void DataSenderQueueShmemInit(void); +extern void DataWriterQueueShmemInit(void); + +extern DataQueuePtr PushToSenderQueue(const RelFileNode& rnode, BlockNumber blockNum, StorageEngine type, + const char* mem, uint32 data_len, int attid, uint64 offset); +extern DataQueuePtr PushToWriterQueue(const char* mem, uint32 mem_len); + +extern uint32 GetFromDataQueue( + char*& buf, int bufsize, DataQueuePtr& startptr, DataQueuePtr& endptr, bool amIWriter, DataQueueData* data_queue); +extern void PopFromDataQueue(const DataQueuePtr& position, DataQueueData* data_queue); +extern void PushCUToDataQueue(Relation rel, int col, const char* mem, _in_ uint64 offset, _in_ int size, bool setbcm); +extern void ResetDataQueue(DataQueueData* data_queue); +extern bool DataQueueIsEmpty(DataQueueData* data_queue); +extern void CStoreCUReplication( + _in_ Relation rel, _in_ int attrId, _in_ char* cuData, _in_ int cuSize, _in_ uint64 cuFileOffset); +extern bool BCMArrayIsEmpty(void); +extern void ResetBCMArray(void); +extern void ClearBCMArray(void); +extern void BCMArrayDropAllBlocks(const RelFileNode& dropnode); +extern void HeapSyncHashSearch(Oid rd_id, HASHACTION action); +extern void AtAbort_RelationSync(void); +extern void AtCommit_RelationSync(void); +extern void PallocBCMBCMElementArray(void); +#endif diff -uprN postgresql-hll-2.14_old/include/replication/datareceiver.h postgresql-hll-2.14/include/replication/datareceiver.h --- postgresql-hll-2.14_old/include/replication/datareceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/datareceiver.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,149 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datareceiver.h + * + * + * + * IDENTIFICATION + * src/include/replication/datareceiver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATARECEIVER_H +#define _DATARECEIVER_H + +#include "storage/latch.h" +#include "storage/spin.h" +#include "storage/custorage.h" +#include "pgtime.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "replication/bcm.h" +#include "replication/dataqueuedefs.h" +#include "replication/walreceiver.h" + +/* + * MAXCONNINFO: maximum size of a connection string. + * + * XXX: Should this move to pg_config_manual.h? + */ +#define MAXCONNINFO 1024 +#define DUMMY_STANDBY_DATADIR "base/dummy_standby" + +/* + * Values for DataRcv->dataRcvState. + */ +typedef enum { + DATARCV_STOPPED, /* stopped and mustn't start up again */ + DATARCV_STARTING, /* launched, but the process hasn't + * initialized yet */ + DATARCV_RUNNING, /* datareceiver is running */ + DATARCV_STOPPING /* requested to stop, but still running */ +} DataRcvState; + +/* Shared memory area for management of datareceiver process */ +typedef struct DataRcvData { + /* + * PID of currently active datareceiver process, its current state and + * start time (actually, the time at which it was requested to be + * started). + */ + ThreadId pid; + ThreadId writerPid; + int lwpId; + DataRcvState dataRcvState; + pg_time_t startTime; + + bool isRuning; + + /* + * Time of send and receive of any message received. + */ + TimestampTz lastMsgSendTime; + TimestampTz lastMsgReceiptTime; + + /* + * Latest reported end of Data on the sender + */ + TimestampTz latestDataEndTime; + + DataQueuePtr sendPosition; /* sender sent queue position (remote queue) */ + DataQueuePtr receivePosition; /* recvwriter write queue position (remote queue) */ + DataQueuePtr localWritePosition; /* recvwriter write queue position (local queue) */ + + int dummyStandbySyncPercent; + + /* + * connection string; is used for datareceiver to connect with the primary. + */ + char conninfo[MAXCONNINFO]; + ReplConnTarget conn_target; + + Latch* datarcvWriterLatch; + + slock_t mutex; /* locks shared variables shown above */ +} DataRcvData; + +typedef struct data_writer_rel_key { + RelFileNode node; /* the relation */ + ForkNumber forkno; /* the fork number */ + int attid; /* colum id */ + StorageEngine type; +} data_writer_rel_key; + +typedef struct data_writer_rel { + data_writer_rel_key key; /* hash key ... must be first */ + Relation reln; + CUStorage* cuStorage; +} data_writer_rel; + +extern bool dummy_data_writer_use_file; + +/* prototypes for functions in datareceiver.cpp */ +extern void DataReceiverMain(void); + +extern Size DataRcvShmemSize(void); +extern void DataRcvShmemInit(void); + +extern bool DataRcvInProgress(void); +extern void ShutdownDataRcv(void); +extern void StartupDataStreaming(void); +extern void RequestDataStreaming(const char* conninfo, ReplConnTarget conn_target); +extern void InitDummyDataNum(void); + +extern void WakeupDataRcvWriter(void); +extern void wakeupWalRcvWriter(void); + +/* Receive writer */ +extern bool DataRcvWriterInProgress(void); +extern void DataRcvDataCleanup(void); +extern void walRcvDataCleanup(void); + +/* prototypes for functions in datarcvreceiver.cpp */ +extern void DataRcvWriterMain(void); +extern int DataRcvWrite(void); +extern void DataRcvSendReply(bool force, bool requestReply); + +extern void SetDataRcvDummyStandbySyncPercent(int percent); +extern int GetDataRcvDummyStandbySyncPercent(void); +extern void SetDataRcvWriterPID(ThreadId tid); +extern void ProcessDataRcvInterrupts(void); +extern void CloseDataFile(void); + +/* write data to disk */ +extern uint32 DoDataWrite(char* buf, uint32 nbytes); + +#endif /* _DATARECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/replication/datasender.h postgresql-hll-2.14/include/replication/datasender.h --- postgresql-hll-2.14_old/include/replication/datasender.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/datasender.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasender.h + * Exports from replication/datasender.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasender.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASENDER_H +#define _DATASENDER_H + +#include +#include + +#include "fmgr.h" +#include "replication/replicainternal.h" + +#define AmDataSenderToDummyStandby() (t_thrd.datasender_cxt.MyDataSnd->sendRole == SNDROLE_PRIMARY_DUMMYSTANDBY) + +#define AmDataSenderOnDummyStandby() (t_thrd.datasender_cxt.MyDataSnd->sendRole == SNDROLE_DUMMYSTANDBY_STANDBY) + +typedef struct { + char* receivedFileList; /* Buffer where we store the file list*/ + int msgLength; /* File list length we got from dummy */ + slock_t mutex; +} GlobalIncrementalBcmDefinition; + +/* user-settable parameters */ +extern volatile uint32 send_dummy_count; +extern GlobalIncrementalBcmDefinition g_incrementalBcmInfo; + +extern int DataSenderMain(void); +extern void DataSndSignals(void); +extern Size DataSndShmemSize(void); +extern void DataSndShmemInit(void); + +extern void DataSndWakeup(void); +extern bool DataSndInProgress(int type); + +extern Datum pg_stat_get_data_senders(PG_FUNCTION_ARGS); + +bool DataSndInSearching(void); +void ReplaceOrFreeBcmFileListBuffer(char* file_list, int msglength); +void InitGlobalBcm(void); + +#endif /* _DATASENDER_H */ diff -uprN postgresql-hll-2.14_old/include/replication/datasender_private.h postgresql-hll-2.14/include/replication/datasender_private.h --- postgresql-hll-2.14_old/include/replication/datasender_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/datasender_private.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,84 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasender_private.h + * Private definitions from replication/datasender.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasender_private.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASENDER_PRIVATE_H +#define _DATASENDER_PRIVATE_H + +#include "nodes/nodes.h" +#include "replication/syncrep.h" +#include "replication/walsender_private.h" +#include "replication/repl_gramparse.h" +#include "storage/latch.h" +#include "storage/shmem.h" +#include "storage/spin.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +typedef enum DataSndState { DATASNDSTATE_STARTUP = 0, DATASNDSTATE_CATCHUP, DATASNDSTATE_STREAMING } DataSndState; + +/* + * Each datasender has a DataSnd struct in shared memory. + */ +typedef struct DataSnd { + ThreadId pid; /* this datasender's process id, or 0 */ + int lwpId; + DataSndState state; /* this datasender's state */ + TimestampTz catchupTime[2]; /* time stamp of this datasender's catchup */ + SndRole sendRole; /* role of sender */ + bool sendKeepalive; /* do we send keepalives on this connection? */ + bool sending; /* true if sending to standby/dummystandby */ + + DataQueuePtr sendPosition; /* data in queue has been sent up to this position */ + DataQueuePtr receivePosition; /* receiver received queue position */ + + /* Protects shared variables shown above. */ + slock_t mutex; + + /* + * Latch used by backends to wake up this datasender when it has work to + * do. + */ + Latch latch; +} DataSnd; + +/* There is one DataSndCtl struct for the whole database cluster */ +typedef struct DataSndCtlData { + /* + * Synchronous replication queue with one queue per request type. + * Protected by SyncRepLock. + */ + SHM_QUEUE SyncRepQueue; + + /* the queue_offset is to release the waiting queue and transaction */ + DataQueuePtr queue_offset; + + /* Protects shared variables of all datalsnd */ + slock_t mutex; + + DataSnd datasnds[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} DataSndCtlData; + +extern void DataSndSetState(DataSndState state); + +#endif /* _DATASENDER_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/replication/datasyncrep.h postgresql-hll-2.14/include/replication/datasyncrep.h --- postgresql-hll-2.14_old/include/replication/datasyncrep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/datasyncrep.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,31 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * datasyncrep.h + * Exports from replication/datasyncrep.cpp. + * + * + * IDENTIFICATION + * src/include/replication/datasyncrep.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _DATASYNCREP_H +#define _DATASYNCREP_H + +extern void WaitForDataSync(void); +extern void DataSyncRepReleaseWaiters(void); + +#endif /* _DATASYNCREP_H */ diff -uprN postgresql-hll-2.14_old/include/replication/decode.h postgresql-hll-2.14/include/replication/decode.h --- postgresql-hll-2.14_old/include/replication/decode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/decode.h 2020-12-12 17:06:43.365349561 +0800 @@ -0,0 +1,23 @@ +/* --------------------------------------------------------------------------------------- + * + * decode.h + * PostgreSQL WAL to logical transformation + * + * Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/decode.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DECODE_H +#define DECODE_H + +#include "access/xlogreader.h" +#include "replication/reorderbuffer.h" +#include "replication/logical.h" + +void LogicalDecodingProcessRecord(LogicalDecodingContext* ctx, XLogReaderState* record); + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_client.h postgresql-hll-2.14/include/replication/heartbeat/heartbeat_client.h --- postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/heartbeat_client.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_client.h + * Heartbeat client. + * + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_client.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_CLIENT_H +#define _HEARTBEAT_CLIENT_H +#include "replication/heartbeat/heartbeat_conn.h" + +class HeartbeatClient { +public: + HeartbeatClient(int epollfd); + ~HeartbeatClient(); + bool Connect(); + void DisConnect(); + bool IsConnect() const; + bool SendBeatHeartPacket(); + +private: + bool InitConnection(HeartbeatConnection* con, int remotePort); + bool SendStartupPacket(const HeartbeatConnection* con) const; + +private: + int epollfd_; + bool isConnect_; + HeartbeatConnection* hbConn_; +}; + +#endif /* _HEARTBEAT_CLIENT_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_conn.h postgresql-hll-2.14/include/replication/heartbeat/heartbeat_conn.h --- postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_conn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/heartbeat_conn.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,81 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_conn.h + * Data struct to store heartbeat connection. + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_conn.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_CONN_H +#define _HEARTBEAT_CONN_H +#include "utils/timestamp.h" +#include "replication/heartbeat/libpq/libpq-be.h" + +const int INVALID_CHANNEL_ID = -1; +const int AF_INET6_MAX_BITS = 128; +const int AF_INET_MAX_BITS = 32; +const int START_REPLNODE_NUM = 1; + +typedef PureLibpq::Port PurePort; + +#ifndef FREE_AND_RESET +#define FREE_AND_RESET(ptr) \ + do { \ + if (NULL != (ptr)) { \ + pfree(ptr); \ + (ptr) = NULL; \ + } \ + } while (0) +#endif + +typedef struct HeartbeatStartupPacket { + int channelIdentifier; /* Use local heart beat listening port for channel identifier */ + TimestampTz sendTime; +} HeartbeatStartupPacket; + +typedef struct HeartbeatPacket { + TimestampTz sendTime; +} HeartbeatPacket; + +/* releasedConnPtr keeps the connection ptr freed by callback */ +typedef void (*PCallback)(int fd, int events, void* arg, void** releasedConnPtr); + +typedef struct HeartbeatConnection { + int fd; + int epHandle; + int events; + int channelIdentifier; /* use remote heartbeat port for channel identifier. */ + PurePort* port; + char* remoteHost; + TimestampTz lastActiveTime; + PCallback callback; + void* arg; +} HeartbeatConnection; + +HeartbeatConnection* MakeConnection(int fd, PurePort* port); +int EventAdd(int epoll_handle, int events, HeartbeatConnection* conn); +void EventDel(int epollFd, HeartbeatConnection* conn); +bool SendHeartbeatPacket(const HeartbeatConnection* conn); +bool SendPacket(const HeartbeatConnection* con, const char* buf, size_t len); +PurePort* ConnectCreate(int serverFd); +void ConnCloseAndFree(HeartbeatConnection* conn); +void RemoveConn(HeartbeatConnection* con); +void UpdateLastHeartbeatTime(const char* remoteHost, int remotePort, TimestampTz timestamp); + +#endif /* _HEARTBEAT_CONN_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_server.h postgresql-hll-2.14/include/replication/heartbeat/heartbeat_server.h --- postgresql-hll-2.14_old/include/replication/heartbeat/heartbeat_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/heartbeat_server.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,61 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat_server.h + * Heartbeat server. + * + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/heartbeat_server.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_SERVER_H +#define _HEARTBEAT_SERVER_H +#include "replication/heartbeat/heartbeat_conn.h" + +class HeartbeatServer { +public: + HeartbeatServer(int epollfd); + ~HeartbeatServer(); + bool Start(); + void Stop(); + bool Restart(); + bool AddConnection(HeartbeatConnection* conn, HeartbeatConnection** releasedConnPtr); + void RemoveConnection(HeartbeatConnection* conn); + void AddUnidentifiedConnection(HeartbeatConnection* conn, HeartbeatConnection** releasedConnPtr); + void RemoveUnidentifiedConnection(HeartbeatConnection* conn); + +private: + bool InitListenConnections(); + bool IsAlreadyListen(const char* ip, int port) const; + void ClearListenConnections(); + int ReleaseOldestUnidentifiedConnection(HeartbeatConnection** releasedConnPtr); + void CloseListenSockets(); + +private: + int epollfd_; + bool started_; + /* serverListenSocket_ is redundant, keep it for adapt ugly libpq interface */ + int serverListenSocket_[MAX_REPLNODE_NUM]; + HeartbeatConnection* listenConns_[MAX_REPLNODE_NUM]; + /* holds accepted and identified connections */ + HeartbeatConnection* identifiedConns_[MAX_REPLNODE_NUM]; + /* holds accepted but unindentified connections */ + HeartbeatConnection* unidentifiedConns_[MAX_REPLNODE_NUM]; +}; + +#endif /* _HEARTBEAT_SERVER_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq-be.h postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq-be.h --- postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq-be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq-be.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-be.h + * This file contains definitions for structures and externs used + * by the cm server during client coonect. + * + * Note that this is backend-internal and is NOT exported to clients. + * Structs that need to be client-visible are in pqcomm.h. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq-be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_BE_H +#define CM_LIBPQ_BE_H + +#include "replication/heartbeat/libpq/pqcomm.h" + +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_NETINET_TCP_H +#include +#endif +namespace PureLibpq { + +typedef enum PortLastCall { + LastCall_NONE = 0, + LastCall_SEND, + LastCall_RECV, +} PortLastCall; + +/* + * The Port structure maintains the tcp channel information, + * and is kept in palloc'd memory. + * TCP keepalive settings such as keepalives_idle,keepalives_interval + * and keepalives_count art use the default values of system. + */ +typedef struct Port { + int sock; /* File descriptor */ + SockAddr laddr; /* local addr */ + SockAddr raddr; /* remote addr */ + PortLastCall last_call; /* Last syscall to this port */ + int last_errno; /* Last errno. zero if the last call succeeds */ +#define PQ_BUFFER_SIZE (16 * 1024) + + char PqSendBuffer[PQ_BUFFER_SIZE]; + int PqSendPointer; /* Next index to store a byte in PqSendBuffer */ + + char PqRecvBuffer[PQ_BUFFER_SIZE]; + int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */ + int PqRecvLength; /* End of data available in PqRecvBuffer */ +} Port; + +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); +extern int pq_getbyte(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_flush(Port* myport); +extern int SetSocketNoBlock(int isocketId); +extern void CloseAndFreePort(Port* port); + +} // namespace PureLibpq + +#endif /* LIBPQ_BE_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq-fe.h postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq-fe.h --- postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq-fe.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq-fe.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq-fe.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CM_LIBPQ_FE_H +#define CM_LIBPQ_FE_H + +#include "replication/heartbeat/libpq/libpq-be.h" + +namespace PureLibpq { + +/* Synchronous (blocking) */ +extern Port* PQconnect(const char* conninfo); + +} // namespace PureLibpq + +#endif /* CM_LIBPQ_FE_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq.h postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq.h --- postgresql-hll-2.14_old/include/replication/heartbeat/libpq/libpq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/libpq/libpq.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,51 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpq.h + * POSTGRES LIBPQ buffer structure definitions. + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/libpq.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_LIBPQ_H +#define CM_LIBPQ_H + +#include +#include +#include "replication/heartbeat/libpq/libpq-be.h" + +namespace PureLibpq { +extern int StreamServerPort(int family, char* hostName, unsigned short portNumber, int ListenSocket[], int MaxListen); +extern int StreamConnection(int server_fd, Port* port); +extern void StreamClose(int sock); + +extern void pq_comm_reset(void); +extern int pq_getbytes(Port* myport, char* s, size_t len); + +extern int pq_getbyte(Port* myport); + +extern int pq_flush(Port* myport); +extern int pq_putmessage(Port* myport, char msgtype, const char* s, size_t len); +extern int pq_putbytes(Port* myport, const char* s, size_t len); +} // namespace PureLibpq +#endif /* LIBPQ_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat/libpq/pqcomm.h postgresql-hll-2.14/include/replication/heartbeat/libpq/pqcomm.h --- postgresql-hll-2.14_old/include/replication/heartbeat/libpq/pqcomm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat/libpq/pqcomm.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pqcomm.h + * Definitions common to frontends and backends. + * + * NOTE: for historical reasons, this does not correspond to pqcomm.c. + * pqcomm.c's routines are declared in libpq.h. + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * + * IDENTIFICATION + * src/include/replication/heartbeat/libpq/pqcomm.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CM_PQCOMM_H +#define CM_PQCOMM_H + +#include +#include +#ifdef HAVE_SYS_UN_H +#include +#endif +#include + +namespace PureLibpq { + +typedef struct { + struct sockaddr_storage addr; + size_t salen; +} SockAddr; + +/* + * This is the default directory in which AF_UNIX socket files are + * placed. Caution: changing this risks breaking your existing client + * applications, which are likely to continue to look in the old + * directory. But if you just hate the idea of sockets in /tmp, + * here's where to twiddle it. You can also override this at runtime + * with the postmaster's -k switch. + */ +#define DEFAULT_PGSOCKET_DIR "/tmp" + +/* + * In protocol 3.0 and later, the startup packet length is not fixed, but + * we set an arbitrary limit on it anyway. This is just to prevent simple + * denial-of-service attacks via sending enough data to run the server + * out of memory. + */ +#define MAX_STARTUP_PACKET_LENGTH 10000 + +} // namespace PureLibpq + +#endif /* PQCOMM_H */ diff -uprN postgresql-hll-2.14_old/include/replication/heartbeat.h postgresql-hll-2.14/include/replication/heartbeat.h --- postgresql-hll-2.14_old/include/replication/heartbeat.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/heartbeat.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,53 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * heartbeat.h + * Data struct to store heartbeat thread variables. + * + * + * IDENTIFICATION + * src/include/replication/heartbeat.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _HEARTBEAT_H +#define _HEARTBEAT_H + +const int MAX_EVENTS = 512; + +typedef struct channel_info { + TimestampTz connect_time; + TimestampTz last_reply_timestamp; +} channel_info; + +/* + * Heartbeat struct in shared memory. + */ +typedef struct heartbeat_state { + ThreadId pid; /* this heartbeat's process id, or 0 */ + int lwpId; + + channel_info channel_array[MAX_REPLNODE_NUM]; + + /* Protects shared variables shown above. */ + slock_t mutex; +} heartbeat_state; + +extern void heartbeat_main(void); +extern TimestampTz get_last_reply_timestamp(int replindex); +void heartbeat_shmem_init(void); +Size heartbeat_shmem_size(void); + +#endif /* _HEARTBEAT_H */ diff -uprN postgresql-hll-2.14_old/include/replication/libpqwalreceiver.h postgresql-hll-2.14/include/replication/libpqwalreceiver.h --- postgresql-hll-2.14_old/include/replication/libpqwalreceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/libpqwalreceiver.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * libpqwalreceiver.h + * libpqwalreceiver init for WalreceiverMain. + * + * + * IDENTIFICATION + * src/include/replication/libpqwalreceiver.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LIBPQWALRECEIVER_H +#define LIBPQWALRECEIVER_H + +extern int32 pg_atoi(char* s, int size, int c); +extern int32 pg_strtoint32(const char* s); +/* Prototypes for interface functions */ +extern bool libpqrcv_connect_for_TLI(TimeLineID* timeLineID, char* conninfo); +extern bool libpqrcv_connect(char* conninfo, XLogRecPtr* startpoint, char* slotname, int channel_identifier); +extern bool libpqrcv_receive(int timeout, unsigned char* type, char** buffer, int* len); +extern void libpqrcv_send(const char* buffer, int nbytes); +extern void libpqrcv_disconnect(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/logicalfuncs.h postgresql-hll-2.14/include/replication/logicalfuncs.h --- postgresql-hll-2.14_old/include/replication/logicalfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/logicalfuncs.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,30 @@ +/* --------------------------------------------------------------------------------------- + * + * logicalfuncs.h + * PostgreSQL WAL to logical transformation support functions + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/logicalfuncs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LOGICALFUNCS_H +#define LOGICALFUNCS_H + +#include "replication/logical.h" + +extern int logical_read_local_xlog_page(XLogReaderState* state, XLogRecPtr targetPagePtr, int reqLen, + XLogRecPtr targetRecPtr, char* cur_page, TimeLineID* pageTLI); + +extern bool AssignLsn(XLogRecPtr* lsn_ptr, const char* input); +extern Datum pg_logical_slot_get_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_get_binary_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_peek_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_slot_peek_binary_changes(PG_FUNCTION_ARGS); +extern Datum pg_logical_peek_changes(PG_FUNCTION_ARGS); +extern void check_permissions(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/logical.h postgresql-hll-2.14/include/replication/logical.h --- postgresql-hll-2.14_old/include/replication/logical.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/logical.h 2020-12-12 17:06:43.366349574 +0800 @@ -0,0 +1,105 @@ +/* --------------------------------------------------------------------------------------- + * + * logical.h + * PostgreSQL logical decoding coordination + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/logical.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef LOGICAL_H +#define LOGICAL_H + +#include "replication/slot.h" + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "replication/output_plugin.h" + +struct LogicalDecodingContext; + +typedef void (*LogicalOutputPluginWriterWrite)( + struct LogicalDecodingContext* lr, XLogRecPtr Ptr, TransactionId xid, bool last_write); + +typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite; + +typedef struct LogicalDecodingContext { + /* memory context this is all allocated in */ + MemoryContext context; + + /* infrastructure pieces */ + XLogReaderState* reader; + ReplicationSlot* slot; + struct ReorderBuffer* reorder; + struct SnapBuild* snapshot_builder; + /* + * Marks the logical decoding context as fast forward decoding one. + * Such a context does not have plugin loaded so most of the the following + * properties are unused. + */ + bool fast_forward; + + OutputPluginCallbacks callbacks; + OutputPluginOptions options; + + /* + * User specified options + */ + List* output_plugin_options; + + /* + * User-Provided callback for writing/streaming out data. + */ + LogicalOutputPluginWriterPrepareWrite prepare_write; + LogicalOutputPluginWriterWrite write; + + /* + * Output buffer. + */ + StringInfo out; + + /* + * Private data pointer of the output plugin. + */ + void* output_plugin_private; + + /* + * Private data pointer for the data writer. + */ + void* output_writer_private; + + /* + * State for writing output. + */ + bool accept_writes; + bool prepared_write; + XLogRecPtr write_location; + TransactionId write_xid; + + bool random_mode; +} LogicalDecodingContext; + +extern void CheckLogicalDecodingRequirements(Oid databaseId); + +extern LogicalDecodingContext* CreateInitDecodingContext(const char* plugin, List* output_plugin_options, + bool need_full_snapshot, XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write); +extern LogicalDecodingContext* CreateInitDecodingContextInternal(char* plugin, List* output_plugin_options, + XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write, bool set_xmin_horizon, ReplicationSlot* slot); +extern LogicalDecodingContext* CreateDecodingContext(XLogRecPtr start_lsn, List* output_plugin_options, + bool fast_forward, XLogPageReadCB read_page, LogicalOutputPluginWriterPrepareWrite prepare_write, + LogicalOutputPluginWriterWrite do_write); +extern void DecodingContextFindStartpoint(LogicalDecodingContext* ctx); +extern bool DecodingContextReady(LogicalDecodingContext* ctx); +extern void FreeDecodingContext(LogicalDecodingContext* ctx); + +extern void LogicalIncreaseXminForSlot(XLogRecPtr lsn, TransactionId xmin); +extern void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart_lsn); +extern void LogicalConfirmReceivedLocation(XLogRecPtr lsn); +extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext* ctx, RepOriginId origin_id); +#endif diff -uprN postgresql-hll-2.14_old/include/replication/output_plugin.h postgresql-hll-2.14/include/replication/output_plugin.h --- postgresql-hll-2.14_old/include/replication/output_plugin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/output_plugin.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,91 @@ +/* --------------------------------------------------------------------------------------- + * + * output_plugin.h + * PostgreSQL Logical Decode Plugin Interface + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/output_plugin.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef OUTPUT_PLUGIN_H +#define OUTPUT_PLUGIN_H + +#include "replication/reorderbuffer.h" + +struct LogicalDecodingContext; +struct OutputPluginCallbacks; + +typedef enum OutputPluginOutputType { + OUTPUT_PLUGIN_BINARY_OUTPUT, + OUTPUT_PLUGIN_TEXTUAL_OUTPUT +} OutputPluginOutputType; + +/* + * Options set by the output plugin, in the startup callback. + */ +typedef struct OutputPluginOptions { + OutputPluginOutputType output_type; +} OutputPluginOptions; + +/* + * Type of the shared library symbol _PG_output_plugin_init that is looked up + * when loading an output plugin shared library. + */ +typedef void (*LogicalOutputPluginInit)(struct OutputPluginCallbacks* cb); + +/* + * Callback that gets called in a user-defined plugin. ctx->private_data can + * be set to some private data. + * + * "is_init" will be set to "true" if the decoding slot just got defined. When + * the same slot is used from there one, it will be "false". + */ +typedef void (*LogicalDecodeStartupCB)(struct LogicalDecodingContext* ctx, OutputPluginOptions* options, bool is_init); + +/* + * Callback called for every (explicit or implicit) BEGIN of a successful + * transaction. + */ +typedef void (*LogicalDecodeBeginCB)(struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn); + +/* + * Callback for every individual change in a successful transaction. + */ +typedef void (*LogicalDecodeChangeCB)( + struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn, Relation relation, ReorderBufferChange* change); + +/* + * Called for every (explicit or implicit) COMMIT of a successful transaction. + */ +typedef void (*LogicalDecodeCommitCB)(struct LogicalDecodingContext* ctx, ReorderBufferTXN* txn, XLogRecPtr commit_lsn); + +/* + * Called to shutdown an output plugin. + */ +typedef void (*LogicalDecodeShutdownCB)(struct LogicalDecodingContext* ctx); + +/* + * Filter changes by origin. + */ +typedef bool (*LogicalDecodeFilterByOriginCB)(struct LogicalDecodingContext* ctx, RepOriginId origin_id); + +/* + * Output plugin callbacks + */ +typedef struct OutputPluginCallbacks { + LogicalDecodeStartupCB startup_cb; + LogicalDecodeBeginCB begin_cb; + LogicalDecodeChangeCB change_cb; + LogicalDecodeCommitCB commit_cb; + LogicalDecodeShutdownCB shutdown_cb; + LogicalDecodeFilterByOriginCB filter_by_origin_cb; +} OutputPluginCallbacks; + +extern void OutputPluginPrepareWrite(struct LogicalDecodingContext* ctx, bool last_write); +extern void OutputPluginWrite(struct LogicalDecodingContext* ctx, bool last_write); + +#endif /* OUTPUT_PLUGIN_H */ diff -uprN postgresql-hll-2.14_old/include/replication/reorderbuffer.h postgresql-hll-2.14/include/replication/reorderbuffer.h --- postgresql-hll-2.14_old/include/replication/reorderbuffer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/reorderbuffer.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,382 @@ +/* --------------------------------------------------------------------------------------- + * + * reorderbuffer.h + * PostgreSQL logical replay/reorder buffer management. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/reorderbuffer.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REORDERBUFFER_H +#define REORDERBUFFER_H + +#include "lib/ilist.h" + +#include "storage/sinval.h" + +#include "utils/hsearch.h" +#include "utils/rel.h" +#include "utils/snapshot.h" +#include "utils/timestamp.h" + +/* an individual tuple, stored in one chunk of memory */ +typedef struct ReorderBufferTupleBuf { + /* position in preallocated list */ + slist_node node; + + /* tuple header, the interesting bit for users of logical decoding */ + HeapTupleData tuple; + /* pre-allocated size of tuple buffer, different from tuple size */ + Size alloc_tuple_size; + + /* actual tuple data follows */ +} ReorderBufferTupleBuf; +/* pointer to the data stored in a TupleBuf */ +#define ReorderBufferTupleBufData(p) ((HeapTupleHeader)MAXALIGN(((char*)p) + sizeof(ReorderBufferTupleBuf))) + +/* + * Types of the change passed to a 'change' callback. + * + * For efficiency and simplicity reasons we want to keep Snapshots, CommandIds + * and ComboCids in the same list with the user visible INSERT/UPDATE/DELETE + * changes. Users of the decoding facilities will never see changes with + * *_INTERNAL_* actions. + */ +enum ReorderBufferChangeType { + REORDER_BUFFER_CHANGE_INSERT, + REORDER_BUFFER_CHANGE_UPDATE, + REORDER_BUFFER_CHANGE_DELETE, + REORDER_BUFFER_CHANGE_INTERNAL_SNAPSHOT, + REORDER_BUFFER_CHANGE_INTERNAL_COMMAND_ID, + REORDER_BUFFER_CHANGE_INTERNAL_TUPLECID +}; + +/* + * a single 'change', can be an insert (with one tuple), an update (old, new), + * or a delete (old). + * + * The same struct is also used internally for other purposes but that should + * never be visible outside reorderbuffer.c. + */ +typedef struct ReorderBufferChange { + XLogRecPtr lsn; + + /* The type of change. */ + enum ReorderBufferChangeType action; + + RepOriginId origin_id; + + /* + * Context data for the change, which part of the union is valid depends + * on action/action_internal. + */ + union { + /* Old, new tuples when action == *_INSERT|UPDATE|DELETE */ + struct { + /* relation that has been changed */ + RelFileNode relnode; + /* no previously reassembled toast chunks are necessary anymore */ + bool clear_toast_afterwards; + + /* valid for DELETE || UPDATE */ + ReorderBufferTupleBuf* oldtuple; + /* valid for INSERT || UPDATE */ + ReorderBufferTupleBuf* newtuple; + } tp; + + /* New snapshot, set when action == *_INTERNAL_SNAPSHOT */ + Snapshot snapshot; + + /* + * New command id for existing snapshot in a catalog changing tx. Set + * when action == *_INTERNAL_COMMAND_ID. + */ + CommandId command_id; + + /* + * New cid mapping for catalog changing transaction, set when action + * == *_INTERNAL_TUPLECID. + */ + struct { + RelFileNode node; + ItemPointerData tid; + CommandId cmin; + CommandId cmax; + CommandId combocid; + } tuplecid; + } data; + + /* + * While in use this is how a change is linked into a transactions, + * otherwise it's the preallocated list. + */ + dlist_node node; +} ReorderBufferChange; + +typedef struct ReorderBufferTXN { + /* + * The transactions transaction id, can be a toplevel or sub xid. + */ + TransactionId xid; + + /* did the TX have catalog changes */ + bool has_catalog_changes; + + /* Do we know this is a subxact? Xid of top-level txn if so */ + bool is_known_as_subxact; + + TransactionId toplevel_xid; + + /* + * LSN of the first data carrying, WAL record with knowledge about this + * xid. This is allowed to *not* be first record adorned with this xid, if + * the previous records aren't relevant for logical decoding. + */ + XLogRecPtr first_lsn; + + /* ---- + * LSN of the record that lead to this xact to be committed or + * aborted. This can be a + * * plain commit record + * * plain commit record, of a parent transaction + * * prepared transaction commit + * * plain abort record + * * prepared transaction abort + * * error during decoding + * ---- + */ + XLogRecPtr final_lsn; + + /* + * LSN pointing to the end of the commit record + 1. + */ + XLogRecPtr end_lsn; + + /* + * LSN of the last lsn at which snapshot information reside, so we can + * restart decoding from there and fully recover this transaction from + * WAL. + */ + XLogRecPtr restart_decoding_lsn; + + /* origin of the change that caused this transaction */ + RepOriginId origin_id; + + /* The csn of the transaction */ + CommitSeqNo csn; + + /* + * Commit time, only known when we read the actual commit record. + */ + TimestampTz commit_time; + + /* + * Base snapshot or NULL. + * The base snapshot is used to decode all changes until either this + * transaction modifies the catalog, or another catalog-modifying + * transaction commits. + */ + Snapshot base_snapshot; + XLogRecPtr base_snapshot_lsn; + dlist_node base_snapshot_node; /* link in txns_by_base_snapshot_lsn */ + + /* + * How many ReorderBufferChange's do we have in this txn. + * + * Changes in subtransactions are *not* included but tracked separately. + */ + uint64 nentries; + + /* + * How many of the above entries are stored in memory in contrast to being + * spilled to disk. + */ + uint64 nentries_mem; + + /* + * Has this transaction been spilled to disk? It's not always possible to + * deduce that fact by comparing nentries with nentries_mem, because + * e.g. subtransactions of a large transaction might get serialized + * together with the parent - if they're restored to memory they'd have + * nentries_mem == nentries. + */ + bool serialized; + + /* + * List of ReorderBufferChange structs, including new Snapshots and new + * CommandIds + */ + dlist_head changes; + + /* + * List of (relation, ctid) => (cmin, cmax) mappings for catalog tuples. + * Those are always assigned to the toplevel transaction. (Keep track of + * #entries to create a hash of the right size) + */ + dlist_head tuplecids; + uint64 ntuplecids; + + /* + * On-demand built hash for looking up the above values. + */ + HTAB* tuplecid_hash; + + /* + * Hash containing (potentially partial) toast entries. NULL if no toast + * tuples have been found for the current change. + */ + HTAB* toast_hash; + + /* + * non-hierarchical list of subtransactions that are *not* aborted. Only + * used in toplevel transactions. + */ + dlist_head subtxns; + uint32 nsubtxns; + + /* + * Stored cache invalidations. This is not a linked list because we get + * all the invalidations at once. + */ + uint32 ninvalidations; + SharedInvalidationMessage* invalidations; + + /* --- + * Position in one of three lists: + * * list of subtransactions if we are *known* to be subxact + * * list of toplevel xacts (can be a as-yet unknown subxact) + * * list of preallocated ReorderBufferTXNs + * --- + */ + dlist_node node; + +} ReorderBufferTXN; + +/* so we can define the callbacks used inside struct ReorderBuffer itself */ +typedef struct ReorderBuffer ReorderBuffer; + +/* change callback signature */ +typedef void (*ReorderBufferApplyChangeCB)( + ReorderBuffer* rb, ReorderBufferTXN* txn, Relation relation, ReorderBufferChange* change); + +/* begin callback signature */ +typedef void (*ReorderBufferBeginCB)(ReorderBuffer* rb, ReorderBufferTXN* txn); + +/* commit callback signature */ +typedef void (*ReorderBufferCommitCB)(ReorderBuffer* rb, ReorderBufferTXN* txn, XLogRecPtr commit_lsn); + +struct ReorderBuffer { + /* + * xid => ReorderBufferTXN lookup table + */ + HTAB* by_txn; + + /* + * Transactions that could be a toplevel xact, ordered by LSN of the first + * record bearing that xid.. + */ + dlist_head toplevel_by_lsn; + + /* + * Transactions and subtransactions that have a base snapshot, ordered by + * LSN of the record which caused us to first obtain the base snapshot. + * This is not the same as toplevel_by_lsn, because we only set the base + * snapshot on the first logical-decoding-relevant record (eg. heap + * writes), whereas the initial LSN could be set by other operations. + */ + dlist_head txns_by_base_snapshot_lsn; + + /* + * one-entry sized cache for by_txn. Very frequently the same txn gets + * looked up over and over again. + */ + TransactionId by_txn_last_xid; + ReorderBufferTXN* by_txn_last_txn; + + /* + * Callacks to be called when a transactions commits. + */ + ReorderBufferBeginCB begin; + ReorderBufferApplyChangeCB apply_change; + ReorderBufferCommitCB commit; + + /* + * Pointer that will be passed untouched to the callbacks. + */ + void* private_data; + + /* + * Private memory context. + */ + MemoryContext context; + + /* + * Data structure slab cache. + * + * We allocate/deallocate some structures very frequently, to avoid bigger + * overhead we cache some unused ones here. + * + * The maximum number of cached entries is controlled by const variables + * ontop of reorderbuffer.c + */ + + /* cached ReorderBufferTXNs */ + dlist_head cached_transactions; + Size nr_cached_transactions; + + /* cached ReorderBufferChanges */ + dlist_head cached_changes; + Size nr_cached_changes; + + /* cached ReorderBufferTupleBufs */ + slist_head cached_tuplebufs; + Size nr_cached_tuplebufs; + + XLogRecPtr current_restart_decoding_lsn; + + /* buffer for disk<->memory conversions */ + char* outbuf; + Size outbufsize; +}; + +ReorderBuffer* ReorderBufferAllocate(void); +void ReorderBufferFree(ReorderBuffer*); + +ReorderBufferTupleBuf* ReorderBufferGetTupleBuf(ReorderBuffer*, Size tuple_len); +void ReorderBufferReturnTupleBuf(ReorderBuffer*, ReorderBufferTupleBuf* tuple); +ReorderBufferChange* ReorderBufferGetChange(ReorderBuffer*); +void ReorderBufferReturnChange(ReorderBuffer*, ReorderBufferChange*); + +void ReorderBufferQueueChange(ReorderBuffer*, TransactionId, XLogRecPtr lsn, ReorderBufferChange*); +void ReorderBufferCommit(ReorderBuffer*, TransactionId, XLogRecPtr commit_lsn, XLogRecPtr end_lsn, + RepOriginId origin_id, CommitSeqNo csn, TimestampTz commit_time); +void ReorderBufferAssignChild(ReorderBuffer*, TransactionId, TransactionId, XLogRecPtr commit_lsn); +void ReorderBufferCommitChild(ReorderBuffer*, TransactionId, TransactionId, XLogRecPtr commit_lsn, XLogRecPtr end_lsn); +void ReorderBufferAbort(ReorderBuffer*, TransactionId, XLogRecPtr lsn); +void ReorderBufferAbortOld(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +void ReorderBufferForget(ReorderBuffer*, TransactionId, XLogRecPtr lsn); + +void ReorderBufferSetBaseSnapshot(ReorderBuffer*, TransactionId, XLogRecPtr lsn, struct SnapshotData* snap); +void ReorderBufferAddSnapshot(ReorderBuffer*, TransactionId, XLogRecPtr lsn, struct SnapshotData* snap); +void ReorderBufferAddNewCommandId(ReorderBuffer*, TransactionId, XLogRecPtr lsn, CommandId cid); +void ReorderBufferAddNewTupleCids(ReorderBuffer*, TransactionId, XLogRecPtr lsn, const RelFileNode& node, + const ItemPointerData& pt, CommandId cmin, CommandId cmax, CommandId combocid); +void ReorderBufferAddInvalidations( + ReorderBuffer*, TransactionId, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage* msgs); +TransactionId ReorderBufferGetOldestXmin(ReorderBuffer* rb); + +void ReorderBufferProcessXid(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +void ReorderBufferXidSetCatalogChanges(ReorderBuffer*, TransactionId xid, XLogRecPtr lsn); +bool ReorderBufferXidHasCatalogChanges(ReorderBuffer*, TransactionId xid); +bool ReorderBufferXidHasBaseSnapshot(ReorderBuffer*, TransactionId xid); + +ReorderBufferTXN* ReorderBufferGetOldestTXN(ReorderBuffer*); + +void ReorderBufferSetRestartPoint(ReorderBuffer*, XLogRecPtr ptr); + +void StartupReorderBuffer(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/replication/repl_gram.hpp postgresql-hll-2.14/include/replication/repl_gram.hpp --- postgresql-hll-2.14_old/include/replication/repl_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/repl_gram.hpp 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,131 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED +# define YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int replication_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + SCONST = 258, + IDENT = 259, + RECPTR = 260, + ICONST = 261, + K_BASE_BACKUP = 262, + K_IDENTIFY_SYSTEM = 263, + K_IDENTIFY_VERSION = 264, + K_IDENTIFY_MODE = 265, + K_IDENTIFY_MAXLSN = 266, + K_IDENTIFY_CONSISTENCE = 267, + K_IDENTIFY_CHANNEL = 268, + K_IDENTIFY_AZ = 269, + K_LABEL = 270, + K_PROGRESS = 271, + K_FAST = 272, + K_NOWAIT = 273, + K_WAL = 274, + K_DATA = 275, + K_START_REPLICATION = 276, + K_FETCH_MOT_CHECKPOINT = 277, + K_CREATE_REPLICATION_SLOT = 278, + K_DROP_REPLICATION_SLOT = 279, + K_PHYSICAL = 280, + K_LOGICAL = 281, + K_SLOT = 282 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 59 "repl_gram.y" + + replication_scanner_YYSTYPE yy_core; + char *str; + bool boolval; + int ival; + + XLogRecPtr recptr; + Node *node; + List *list; + DefElem *defelt; + + +/* Line 2058 of yacc.c */ +#line 97 "repl_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int replication_yyparse (void *YYPARSE_PARAM); +#else +int replication_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int replication_yyparse (replication_scanner_yyscan_t yyscanner); +#else +int replication_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_REPLICATION_YY_REPL_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/replication/repl_gramparse.h postgresql-hll-2.14/include/replication/repl_gramparse.h --- postgresql-hll-2.14_old/include/replication/repl_gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/repl_gramparse.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,31 @@ +/* --------------------------------------------------------------------------------------- + * + * repl_gramparse.h + * Shared definitions for the "raw" syncrep_parser (flex and bison phases only) + * + * NOTE: this file is only meant to be includedd in the core parsing files. + * copy from parser/gramparse.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/replication/repl_gramparse.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPL_GRAMPARSE_H +#define _REPL_GRAMPARSE_H + +#include "repl.h" +#include "repl_gram.hpp" + +extern int replication_yyparse(replication_scanner_yyscan_t yyscanner); +extern int replication_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, replication_scanner_yyscan_t yyscanner); +extern void replication_yyerror(YYLTYPE* yylloc, replication_scanner_yyscan_t yyscanner, const char* msg); +extern replication_scanner_yyscan_t replication_scanner_init(const char* query_string); +extern void replication_scanner_finish(replication_scanner_yyscan_t yyscanner); +extern void replication_scanner_yyerror(const char* message, replication_scanner_yyscan_t yyscanner); + +#endif /* _SYNCREP_GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/replication/repl.h postgresql-hll-2.14/include/replication/repl.h --- postgresql-hll-2.14_old/include/replication/repl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/repl.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,37 @@ +/* --------------------------------------------------------------------------------------- + * + * repl.h + * MPPDB High Available internal declarations + * + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/repl.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPL_H +#define _REPL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/xlogdefs.h" + +typedef void* replication_scanner_yyscan_t; + +typedef union replication_scanner_YYSTYPE { + char* str; + bool boolval; + int ival; + XLogRecPtr recptr; + Node* node; + List* list; + DefElem* defelt; +} replication_scanner_YYSTYPE; + +extern int replication_scanner_yylex( + replication_scanner_YYSTYPE* lvalp, YYLTYPE* llocp, replication_scanner_yyscan_t yyscanner); +extern void replication_scanner_yyerror(const char* message, replication_scanner_yyscan_t yyscanner); + +#endif /* _REPLICA_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/replication/replicainternal.h postgresql-hll-2.14/include/replication/replicainternal.h --- postgresql-hll-2.14_old/include/replication/replicainternal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/replicainternal.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,151 @@ +/* --------------------------------------------------------------------------------------- + * + * replicainternal.h + * MPPDB High Available internal declarations + * + * Portions Copyright (c) 2010-2012, Postgres-XC Development Group + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/replicainternal.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _REPLICA_INTERNAL_H +#define _REPLICA_INTERNAL_H + +#ifdef EXEC_BACKEND +#include "storage/spin.h" +#endif + +#define IP_LEN 64 +#define PG_PROTOCOL_VERSION "MPPDB" + +/* Notice: the value is same sa GUC_MAX_REPLNODE_NUM */ +#ifdef ENABLE_MULTIPLE_NODES +#define MAX_REPLNODE_NUM 8 +#else +#define MAX_REPLNODE_NUM 9 +#endif + +#define REPL_IDX_PRIMARY 1 +#define REPL_IDX_STANDBY 2 + +typedef enum { NoDemote = 0, SmartDemote, FastDemote } DemoteMode; + +typedef enum { UNUSED_LISTEN_SOCKET = 0, PSQL_LISTEN_SOCKET, HA_LISTEN_SOCKET } ListenSocketType; + +typedef enum { + UNKNOWN_MODE = 0, + NORMAL_MODE, + PRIMARY_MODE, + STANDBY_MODE, + CASCADE_STANDBY_MODE, + PENDING_MODE +} ServerMode; + +typedef enum { + UNKNOWN_STATE = 0, + NORMAL_STATE, + NEEDREPAIR_STATE, + STARTING_STATE, + WAITING_STATE, + DEMOTING_STATE, + PROMOTING_STATE, + BUILDING_STATE, + CATCHUP_STATE, + COREDUMP_STATE +} DbState; + +typedef enum { + NONE_REBUILD = 0, + WALSEGMENT_REBUILD, + CONNECT_REBUILD, + TIMELINE_REBUILD, + SYSTEMID_REBUILD, + VERSION_REBUILD, + MODE_REBUILD +} HaRebuildReason; + +typedef enum { NONE_BUILD = 0, AUTO_BUILD, FULL_BUILD, INC_BUILD } BuildMode; + +typedef struct buildstate { + BuildMode build_mode; + uint64 total_done; + uint64 total_size; + int process_schedule; + int estimated_time; +} BuildState; + +typedef struct gaussstate { + ServerMode mode; + int conn_num; + DbState state; + bool sync_stat; + uint64 lsn; + uint64 term; + BuildState build_info; + HaRebuildReason ha_rebuild_reason; +} GaussState; + +#ifdef EXEC_BACKEND +/* + * Indicate one connect channel + */ +typedef struct replconninfo { + char localhost[IP_LEN]; + int localport; + int localservice; + int localheartbeatport; + char remotehost[IP_LEN]; + int remoteport; + int remoteservice; + int remoteheartbeatport; +} ReplConnInfo; + +/* + * HA share memory struct + */ +typedef struct hashmemdata { + ServerMode current_mode; + bool is_cascade_standby; + HaRebuildReason repl_reason[MAX_REPLNODE_NUM]; + int disconnect_count[MAX_REPLNODE_NUM]; + int current_repl; + int repl_list_num; + int loop_find_times; + slock_t mutex; +} HaShmemData; + +/* + * state of the node in the high availability cluster + * NOTES: NODESTATE_XXX_DEMOTE_REQUEST should equal to XXXDemote + */ +typedef enum ClusterNodeState { + NODESTATE_NORMAL = 0, + NODESTATE_SMART_DEMOTE_REQUEST, + NODESTATE_FAST_DEMOTE_REQUEST, + NODESTATE_STANDBY_WAITING, + NODESTATE_PRIMARY_DEMOTING, + NODESTATE_PROMOTE_APPROVE, + NODESTATE_STANDBY_REDIRECT, + NODESTATE_STANDBY_PROMOTING, + NODESTATE_STANDBY_FAILOVER_PROMOTING, + NODESTATE_PRIMARY_DEMOTING_WAIT_CATCHUP, + NODESTATE_DEMOTE_FAILED +} ClusterNodeState; +#endif + +/* + * Rec crc for wal's handshake + */ +typedef enum { + NONE_REC_CRC = 0, + IGNORE_REC_CRC +} PredefinedRecCrc; + +extern bool data_catchup; +extern bool wal_catchup; + +#endif /* _REPLICA_INTERNAL_H */ diff -uprN postgresql-hll-2.14_old/include/replication/rto_statistic.h postgresql-hll-2.14/include/replication/rto_statistic.h --- postgresql-hll-2.14_old/include/replication/rto_statistic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/rto_statistic.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,64 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rto_statistic.h + * + * + * + * IDENTIFICATION + * src/include/replication/rto_statistic.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RTO_STATISTIC_H +#define RTO_STATISTIC_H + +#include "gs_thread.h" +#include "knl/knl_session.h" + +static const uint32 RTO_VIEW_NAME_SIZE = 32; +static const uint32 RTO_VIEW_COL_SIZE = 2; +static const uint32 MAX_WAL_SENDER = 100; +static const uint32 RTO_INFO_BUFFER_SIZE = 2048 * (1 + MAX_WAL_SENDER); +static const uint32 STANDBY_NAME_SIZE = 1024; +static const uint32 RECOVERY_RTO_VIEW_COL = 9; + +typedef Datum (*GetViewDataFunc)(); + +typedef struct RTOStatsViewObj { + char name[RTO_VIEW_NAME_SIZE]; + Oid data_type; + GetViewDataFunc get_data; +} RTOStatsViewObj; + +/* RTO statistics */ +typedef struct RTOStandbyData { + char id[STANDBY_NAME_SIZE]; + char source_ip[IP_LEN]; + char dest_ip[IP_LEN]; + int source_port; + int dest_port; + int64 current_rto; + int target_rto; + int64 current_sleep_time; +} RTOStandbyData; + +typedef struct knl_g_rto_context { + RTOStandbyData rto_standby_data[MAX_WAL_SENDER]; +} knl_g_rto_context; + +extern const RTOStatsViewObj g_rtoViewArr[RTO_VIEW_COL_SIZE]; +RTOStandbyData* GetRTOStat(uint32* num); +#endif /* RTO_STATISTIC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/replication/slot.h postgresql-hll-2.14/include/replication/slot.h --- postgresql-hll-2.14_old/include/replication/slot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/slot.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,253 @@ +/* --------------------------------------------------------------------------------------- + * + * slot.h + * Replication slot management. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * + * IDENTIFICATION + * src/include/replication/slot.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SLOT_H +#define SLOT_H + +#include "fmgr.h" +#include "access/xlog.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "storage/spin.h" +extern const uint32 EXTRA_SLOT_VERSION_NUM; + +/* + * Behaviour of replication slots, upon release or crash. + * + * Slots marked as PERSISTENT are crashsafe and will not be dropped when + * released. Slots marked as EPHEMERAL will be dropped when released or after + * restarts. + * + * EPHEMERAL slots can be made PERSISTENT by calling ReplicationSlotPersist(). + */ +typedef enum ReplicationSlotPersistency { RS_PERSISTENT, RS_EPHEMERAL } ReplicationSlotPersistency; + +/* + * On-Disk data of a replication slot, preserved across restarts. + */ + +typedef struct ReplicationSlotPersistentData { + /* The slot's identifier */ + NameData name; + + /* database the slot is active on */ + Oid database; + /* + * The slot's behaviour when being dropped (or restored after a crash). + */ + /* !!!!!!!!!!!!!!!!!!we steal two bytes from persistency for extra content length in new version */ + ReplicationSlotPersistency persistency; + bool isDummyStandby; + + /* + * xmin horizon for data + * + * NB: This may represent a value that hasn't been written to disk yet; + * see notes for effective_xmin, below. + */ + TransactionId xmin; + /* + * xmin horizon for catalog tuples + * + * NB: This may represent a value that hasn't been written to disk yet; + * see notes for effective_xmin, below. + */ + TransactionId catalog_xmin; + + /* oldest LSN that might be required by this replication slot */ + XLogRecPtr restart_lsn; + /* oldest LSN that the client has acked receipt for */ + XLogRecPtr confirmed_flush; + /* plugin name */ + NameData plugin; +} ReplicationSlotPersistentData; + +/* + * Replication slot on-disk data structure. + */ +typedef struct ReplicationSlotOnDisk { + /* first part of this struct needs to be version independent */ + + /* data not covered by checksum */ + uint32 magic; + pg_crc32c checksum; + + /* data covered by checksum */ + uint32 version; + uint32 length; + + ReplicationSlotPersistentData slotdata; +} ReplicationSlotOnDisk; + +typedef struct ObsArchiveConfig { + char *obs_address; + char *obs_bucket; + char *obs_ak; + char *obs_sk; +} ObsArchiveConfig; + +/* + * Shared memory state of a single replication slot. + */ +typedef struct ReplicationSlot { + /* lock, on same cacheline as effective_xmin */ + slock_t mutex; + + /* is this slot defined */ + bool in_use; + + /* is somebody streaming out changes for this slot */ + bool active; + + /* any outstanding modifications? */ + bool just_dirtied; + bool dirty; + + /* + * For logical decoding, it's extremely important that we never remove any + * data that's still needed for decoding purposes, even after a crash; + * otherwise, decoding will produce wrong answers. Ordinary streaming + * replication also needs to prevent old row versions from being removed + * too soon, but the worst consequence we might encounter there is unwanted + * query cancellations on the standby. Thus, for logical decoding, + * this value represents the latest xmin that has actually been + * written to disk, whereas for streaming replication, it's just the + * same as the persistent value (data.xmin). + */ + TransactionId effective_xmin; + TransactionId effective_catalog_xmin; + + /* data surviving shutdowns and crashes */ + ReplicationSlotPersistentData data; + + /* is somebody performing io on this slot? */ + LWLock *io_in_progress_lock; + + /* all the remaining data is only used for logical slots */ + + /* ---- + * When the client has confirmed flushes >= candidate_xmin_lsn we can + * advance the catalog xmin, when restart_valid has been passed, + * restart_lsn can be increased. + * ---- + */ + TransactionId candidate_catalog_xmin; + XLogRecPtr candidate_xmin_lsn; + XLogRecPtr candidate_restart_valid; + XLogRecPtr candidate_restart_lsn; + ObsArchiveConfig* archive_obs; + char* extra_content; +} ReplicationSlot; + + +#define ReplicationSlotPersistentDataConstSize sizeof(ReplicationSlotPersistentData) +/* size of the part of the slot that is version independent */ +#define ReplicationSlotOnDiskConstantSize offsetof(ReplicationSlotOnDisk, slotdata) +/* size of the slots that is not version indepenent */ +#define ReplicationSlotOnDiskDynamicSize sizeof(ReplicationSlotOnDisk) - ReplicationSlotOnDiskConstantSize +#define SLOT_MAGIC 0x1051CA1 /* format identifier */ +#define SLOT_VERSION 1 /* version for new files */ +#define SLOT_VERSION_TWO 2 /* version for new files */ + + +#define XLOG_SLOT_CREATE 0x00 +#define XLOG_SLOT_ADVANCE 0x10 +#define XLOG_SLOT_DROP 0x20 +#define XLOG_SLOT_CHECK 0x30 +#define XLOG_TERM_LOG 0x40 +#define INT32_HIGH_MASK 0xFF00 +#define INT32_LOW_MASK 0x00FF + +/* we steal two bytes from persistency for updagrade */ +#define GET_SLOT_EXTRA_DATA_LENGTH(data) (((int)((data).persistency)) >> 16) +#define SET_SLOT_EXTRA_DATA_LENGTH(data, length) ((data).persistency = (ReplicationSlotPersistency)((int)(((data).persistency) & INT32_LOW_MASK) | ((length) << 16))) +#define GET_SLOT_PERSISTENCY(data) (ReplicationSlotPersistency(int16((data).persistency))) +#define SET_SLOT_PERSISTENCY(data, mypersistency) ((data).persistency = (ReplicationSlotPersistency)((int)(((data).persistency) & INT32_HIGH_MASK) | (int16(mypersistency)))) +/* + * Shared memory control area for all of replication slots. + */ +typedef struct ReplicationSlotCtlData { + ReplicationSlot replication_slots[1]; +} ReplicationSlotCtlData; +/* + * ret for computing all of replication slots. + */ +typedef struct ReplicationSlotState { + XLogRecPtr min_required; + XLogRecPtr max_required; + bool exist_in_use; +} ReplicationSlotState; +/* + * Shared memory control area for all of replication slots. + */ +typedef struct LogicalPersistentData { + int SlotNum; + ReplicationSlotPersistentData replication_slots[FLEXIBLE_ARRAY_MEMBER]; +} LogicalPersistentData; + +/* shmem initialization functions */ +extern Size ReplicationSlotsShmemSize(void); +extern void ReplicationSlotsShmemInit(void); + +/* management of individual slots */ +extern void ReplicationSlotCreate(const char* name, ReplicationSlotPersistency persistency, bool isDummyStandby, + Oid databaseId, XLogRecPtr restart_lsn, char* extra_content = NULL); +extern void ReplicationSlotPersist(void); +extern void ReplicationSlotDrop(const char* name); +extern void ReplicationSlotAcquire(const char* name, bool isDummyStandby); +bool ReplicationSlotFind(const char* name); +extern void ReplicationSlotRelease(void); +extern void ReplicationSlotSave(void); +extern void ReplicationSlotMarkDirty(void); +extern void CreateSlotOnDisk(ReplicationSlot* slot); + +/* misc stuff */ +extern bool ReplicationSlotValidateName(const char* name, int elevel); +extern void ValidateName(const char* name); +extern void ReplicationSlotsComputeRequiredXmin(bool already_locked); +extern void ReplicationSlotsComputeRequiredLSN(ReplicationSlotState* repl_slt_state); +extern void ReplicationSlotReportRestartLSN(void); +extern void StartupReplicationSlots(); +extern void CheckPointReplicationSlots(void); +extern void SetDummyStandbySlotLsnInvalid(void); + +extern void CheckSlotRequirements(void); + +/* SQL callable functions */ +extern Datum pg_get_replication_slots(PG_FUNCTION_ARGS); +extern void create_logical_replication_slot( + Name name, Name plugin, bool isDummyStandby, NameData* databaseName, char* str_tmp_lsn); +extern XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN(void); +extern bool ReplicationSlotsCountDBSlots(Oid dboid, int* nslots, int* nactive); +extern Datum pg_create_physical_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_create_physical_replication_slot_extern(PG_FUNCTION_ARGS); +extern Datum pg_create_logical_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_drop_replication_slot(PG_FUNCTION_ARGS); +extern Datum pg_get_replication_slot_name(PG_FUNCTION_ARGS); + +/* slot redo */ +extern void slot_redo(XLogReaderState* record); +extern void slot_desc(StringInfo buf, XLogReaderState* record); +extern void redo_slot_advance(const ReplicationSlotPersistentData* slotInfo); +extern void log_slot_advance(const ReplicationSlotPersistentData* slotInfo); +extern void log_slot_drop(const char* name); +extern void LogCheckSlot(); +extern Size GetAllLogicalSlot(LogicalPersistentData*& LogicalSlot); +extern char* get_my_slot_name(); +extern ObsArchiveConfig* formObsConfigFromStr(char *content, bool encrypted); +extern char *formObsConfigStringFromStruct(ObsArchiveConfig *obs_config); +extern bool is_archive_slot(ReplicationSlotPersistentData data); +extern void log_slot_create(const ReplicationSlotPersistentData *slotInfo, char* extra_content = NULL); + +#endif /* SLOT_H */ diff -uprN postgresql-hll-2.14_old/include/replication/snapbuild.h postgresql-hll-2.14/include/replication/snapbuild.h --- postgresql-hll-2.14_old/include/replication/snapbuild.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/snapbuild.h 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,84 @@ +/* --------------------------------------------------------------------------------------- + * + * snapbuild.h + * Exports from replication/logical/snapbuild.c. + * + * Copyright (c) 2012-2014, PostgreSQL Global Development Group + * + * + * IDENTIFICATION + * src/include/replication/snapbuild.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SNAPBUILD_H +#define SNAPBUILD_H + +#include "access/xlogdefs.h" +#include "utils/snapmgr.h" + +typedef enum { + /* + * Initial state, we can't do much yet. + */ + SNAPBUILD_START = -1, + /* + * Collecting committed transactions, to build the initial catalog + * snapshot. + */ + SNAPBUILD_BUILDING_SNAPSHOT = 0, + + /* + * We have collected enough information to decode tuples in transactions + * that started after this. + * + * yet, because they might be based on transactions that were still running + * when FULL_SNAPSHOT was reached. + */ + SNAPBUILD_FULL_SNAPSHOT = 1, + + /* + * Found a point after SNAPBUILD_FULL_SNAPSHOT where all transactions that + * were running at that point finished. Till we reach that we hold off + * calling any commit callbacks. + */ + SNAPBUILD_CONSISTENT = 2 +} SnapBuildState; + +/* forward declare so we don't have to expose the struct to the public */ +struct SnapBuild; +typedef struct SnapBuild SnapBuild; + +/* forward declare so we don't have to include reorderbuffer.h */ +struct ReorderBuffer; + +/* forward declare so we don't have to include heapam_xlog.h */ +struct xl_heap_new_cid; +struct xl_running_xacts; + +extern void CheckPointSnapBuild(void); + +extern SnapBuild* AllocateSnapshotBuilder( + struct ReorderBuffer* cache, TransactionId xmin_horizon, XLogRecPtr start_lsn, bool need_full_snapshot); +extern void FreeSnapshotBuilder(SnapBuild* cache); + +extern void SnapBuildSnapDecRefcount(Snapshot snap); + +extern const char* SnapBuildExportSnapshot(SnapBuild* snapstate); +extern void SnapBuildClearExportedSnapshot(void); + +extern SnapBuildState SnapBuildCurrentState(SnapBuild* snapstate); + +extern bool SnapBuildXactNeedsSkip(SnapBuild* snapstate, XLogRecPtr ptr); + +extern void SnapBuildCommitTxn( + SnapBuild* builder, XLogRecPtr lsn, TransactionId xid, int nsubxacts, TransactionId* subxacts); +extern bool SnapBuildProcessChange(SnapBuild* builder, TransactionId xid, XLogRecPtr lsn); +extern void SnapBuildProcessNewCid(SnapBuild* builder, TransactionId xid, XLogRecPtr lsn, + struct xl_heap_new_cid* cid, int bucket_id); +extern void SnapBuildProcessRunningXacts(SnapBuild* builder, XLogRecPtr lsn, struct xl_running_xacts* running); +extern void SnapBuildSerializationPoint(SnapBuild* builder, XLogRecPtr lsn); + +extern void SnapBuildSetInitXmin(SnapBuild* builder, TransactionId xmin); +extern void SnapBuildSetState(SnapBuild* builder, SnapBuildState s_state); +#endif /* SNAPBUILD_H */ diff -uprN postgresql-hll-2.14_old/include/replication/syncrep_gram.hpp postgresql-hll-2.14/include/replication/syncrep_gram.hpp --- postgresql-hll-2.14_old/include/replication/syncrep_gram.hpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/syncrep_gram.hpp 2020-12-12 17:06:43.367349587 +0800 @@ -0,0 +1,106 @@ +/* A Bison parser, made by GNU Bison 2.7. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED +# define YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int syncrep_yydebug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + NAME = 258, + NUM = 259, + JUNK = 260, + ANY = 261, + FIRST = 262 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2058 of yacc.c */ +#line 60 "syncrep_gram.y" + + syncrep_scanner_YYSTYPE yy_core; + char *str; + List *list; + SyncRepConfigData *config; + + +/* Line 2058 of yacc.c */ +#line 72 "syncrep_gram.hpp" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int syncrep_yyparse (void *YYPARSE_PARAM); +#else +int syncrep_yyparse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int syncrep_yyparse (syncrep_scanner_yyscan_t yyscanner); +#else +int syncrep_yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_SYNCREP_YY_SYNCREP_GRAM_HPP_INCLUDED */ diff -uprN postgresql-hll-2.14_old/include/replication/syncrep_gramparse.h postgresql-hll-2.14/include/replication/syncrep_gramparse.h --- postgresql-hll-2.14_old/include/replication/syncrep_gramparse.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/syncrep_gramparse.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,29 @@ +/* --------------------------------------------------------------------------------------- + * + * syncrep_gramparse.h + * Shared definitions for the "raw" syncrep_parser (flex and bison phases only) + * + * NOTE: this file is only meant to be includedd in the core parsing files. + * copy from parser/gramparse.h + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/replication/syncrep_gramparse.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _SYNCREP_GRAMPARSE_H +#define _SYNCREP_GRAMPARSE_H + +#include "syncrep.h" +#include "syncrep_gram.hpp" + +extern int syncrep_yyparse(syncrep_scanner_yyscan_t yyscanner); +extern int syncrep_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, syncrep_scanner_yyscan_t yyscanner); +extern syncrep_scanner_yyscan_t syncrep_scanner_init(const char* query_string); +extern void syncrep_scanner_finish(syncrep_scanner_yyscan_t yyscanner); + +#endif /* _SYNCREP_GRAMPARSE_H */ diff -uprN postgresql-hll-2.14_old/include/replication/syncrep.h postgresql-hll-2.14/include/replication/syncrep.h --- postgresql-hll-2.14_old/include/replication/syncrep.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/syncrep.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,102 @@ +/* ------------------------------------------------------------------------- + * + * syncrep.h + * Exports from replication/syncrep.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/replication/syncrep.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _SYNCREP_H +#define _SYNCREP_H + +#include "access/xlogdefs.h" +#include "utils/guc.h" +#include "replication/replicainternal.h" + +#define SyncRepRequested() \ + (g_instance.attr.attr_storage.max_wal_senders > 0 && synchronous_commit > SYNCHRONOUS_COMMIT_LOCAL_FLUSH) + +/* SyncRepWaitMode */ +#define SYNC_REP_NO_WAIT -1 +#define SYNC_REP_WAIT_RECEIVE 0 +#define SYNC_REP_WAIT_WRITE 1 +#define SYNC_REP_WAIT_FLUSH 2 + +#define NUM_SYNC_REP_WAIT_MODE 3 + +/* syncRepState */ +#define SYNC_REP_NOT_WAITING 0 +#define SYNC_REP_WAITING 1 +#define SYNC_REP_WAIT_COMPLETE 2 + +/* syncrep_method of SyncRepConfigData */ +#define SYNC_REP_PRIORITY 0 +#define SYNC_REP_QUORUM 1 + +extern volatile bool most_available_sync; + +#define SyncStandbysDefined() \ + (u_sess->attr.attr_storage.SyncRepStandbyNames != NULL && u_sess->attr.attr_storage.SyncRepStandbyNames[0] != '\0') + +/* + * Struct for the configuration of synchronous replication. + * + * Note: this must be a flat representation that can be held in a single + * chunk of malloc'd memory, so that it can be stored as the "extra" data + * for the synchronous_standby_names GUC. + */ +typedef struct SyncRepConfigData { + int config_size; /* total size of this struct, in bytes */ + int num_sync; /* number of sync standbys that we need to wait for */ + uint8 syncrep_method; /* method to choose sync standbys */ + int nmembers; /* number of members in the following list */ + /* member_names contains nmembers consecutive nul-terminated C strings */ + char member_names[FLEXIBLE_ARRAY_MEMBER]; +} SyncRepConfigData; + +/* called by user backend */ +extern void SyncRepWaitForLSN(XLogRecPtr XactCommitLSN); + +/* called at backend exit */ +extern void SyncRepCleanupAtProcExit(void); + +/* called by wal sender */ +extern void SyncRepInitConfig(void); +extern void SyncRepReleaseWaiters(void); + +/* called by wal writer */ +extern void SyncRepUpdateSyncStandbysDefined(void); + +/* called by wal sender, check if any synchronous standby is alive */ +extern void SyncRepCheckSyncStandbyAlive(void); + +/* called by wal sender and user backend */ +extern List* SyncRepGetSyncStandbys(bool* am_sync, List** catchup_standbys = NULL); + +extern bool check_synchronous_standby_names(char** newval, void** extra, GucSource source); +extern void assign_synchronous_standby_names(const char* newval, void* extra); +extern void assign_synchronous_commit(int newval, void* extra); + +/* + * Internal functions for parsing synchronous_standby_names grammar, + * in syncrep_gram.y and syncrep_scanner.l + */ +#define YYLTYPE int +typedef void* syncrep_scanner_yyscan_t; + +typedef union syncrep_scanner_YYSTYPE { + char* str; + List* list; + SyncRepConfigData* config; +} syncrep_scanner_YYSTYPE; + +extern int syncrep_scanner_yylex(syncrep_scanner_YYSTYPE* lvalp, YYLTYPE* llocp, syncrep_scanner_yyscan_t yyscanner); +extern void syncrep_scanner_yyerror(const char* message, syncrep_scanner_yyscan_t yyscanner); +extern bool SyncRepGetSyncRecPtr(XLogRecPtr* receivePtr, XLogRecPtr* writePtr, XLogRecPtr* flushPtr, bool* am_sync, bool check_am_sync = true); + + +#endif /* _SYNCREP_H */ diff -uprN postgresql-hll-2.14_old/include/replication/walprotocol.h postgresql-hll-2.14/include/replication/walprotocol.h --- postgresql-hll-2.14_old/include/replication/walprotocol.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/walprotocol.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,241 @@ +/* ------------------------------------------------------------------------- + * + * walprotocol.h + * Definitions relevant to the streaming WAL transmission protocol. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walprotocol.h + * + * We tried to expand the traditional WAL protocol to transfer the separated replication data with + * the specified #ref_xlog which could benefit from both the xlog synchronization and the I/O reducing. + * ------------------------------------------------------------------------- + */ +#ifndef _WALPROTOCOL_H +#define _WALPROTOCOL_H + +#include "access/xlogdefs.h" +#include "datatype/timestamp.h" +#include "replication/replicainternal.h" + +/* + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct ConfigModifyTimeMessage { + time_t config_modify_time; +} ConfigModifyTimeMessage; + +/* + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct { + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + ServerMode peer_role; + DbState peer_state; + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; + bool catchup; +} WalSndrMessage; + +/* + * Refence :PrimaryKeepaliveMessage + * All messages from WalSender must contain these fields to allow us to + * correctly calculate the replication delay. + */ +typedef struct RmXLogMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the client should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} RmXLogMessage; + +/* + * Refence :PrimaryKeepaliveMessage + */ +typedef struct EndXLogMessage { + /* Current end of WAL on the sender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + int percent; +} EndXLogMessage; + +/* + * Header for a WAL data message (message type 'w'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual WAL data. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* WAL start location of the data included in this message */ + XLogRecPtr dataStart; + + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + + bool catchup; +} WalDataMessageHeader; + +/* + * Header for a data replication message (message type 'd'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * The header is followed by actual data page. Note that the data length is + * not specified in the header --- it's just whatever remains in the message. + * + * walEnd and sendTime are not essential data, but are provided in case + * the receiver wants to adjust its behavior depending on how far behind + * it is. + */ +typedef struct { + /* the corresponding data_start_ptr and data_end_ptr */ + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} WalDataPageMessageHeader; + +/* + * Keepalive message from primary (message type 'k'). (lowercase k) + * This is wrapped within a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef WalSndrMessage PrimaryKeepaliveMessage; + +/* + * switchover response + */ +typedef enum { + SWITCHOVER_NONE = 0, + SWITCHOVER_PROMOTE_REQUEST, + SWITCHOVER_DEMOTE_FAILED, + SWITCHOVER_DEMOTE_CATCHUP_EXIST +} SwitchResponseCode; + +/* + * switchover response message from primary (message type 'p'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct { + int switchResponse; + + /* Current end of WAL on the sender */ + XLogRecPtr walEnd; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} PrimarySwitchResponseMessage; + +/* + * Reply message from standby (message type 'r'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyReplyMessage { + /* + * The xlog locations that have been received, written, flushed, and applied by + * standby-side. These may be invalid if the standby-side is unable to or + * chooses not to report these. + */ + XLogRecPtr receive; + XLogRecPtr write; + XLogRecPtr flush; + XLogRecPtr apply; + XLogRecPtr applyRead; + + /* local role on walreceiver, they will be sent to walsender */ + ServerMode peer_role; + DbState peer_state; + + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; + + /* + * If replyRequested is set, the server should reply immediately to this + * message, to avoid a timeout disconnect. + */ + bool replyRequested; +} StandbyReplyMessage; + +/* + * Hot Standby feedback from standby (message type 'h'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbyHSFeedbackMessage { + /* + * The current xmin and epoch from the standby, for Hot Standby feedback. + * This may be invalid if the standby-side does not support feedback, or + * Hot Standby is not yet available. + */ + TransactionId xmin; + /* Sender's system clock at the time of transmission */ + TimestampTz sendTime; +} StandbyHSFeedbackMessage; + +/* + * @@GaussDB@@ + * switchover request message from standby (message type 's'). This is wrapped within + * a CopyData message at the FE/BE protocol level. + * + * Note that the data length is not specified here. + */ +typedef struct StandbySwitchRequestMessage { + /* primary demote mode */ + int demoteMode; + + /* receiver's system clock at the time of transmission */ + TimestampTz sendTime; +} StandbySwitchRequestMessage; + +/* + * Maximum data payload in a WAL data message. Must be >= XLOG_BLCKSZ. + * + * We don't have a good idea of what a good value would be; there's some + * overhead per message in both walsender and walreceiver, but on the other + * hand sending large batches makes walsender less responsive to signals + * because signals are checked only between messages. 128kB (with + * default 8k blocks) seems like a reasonable guess for now. + */ +#define MAX_SEND_SIZE (XLOG_BLCKSZ * 16) + +#endif /* _WALPROTOCOL_H */ diff -uprN postgresql-hll-2.14_old/include/replication/walreceiver.h postgresql-hll-2.14/include/replication/walreceiver.h --- postgresql-hll-2.14_old/include/replication/walreceiver.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/walreceiver.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,263 @@ +/* ------------------------------------------------------------------------- + * + * walreceiver.h + * Exports from replication/walreceiverfuncs.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walreceiver.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALRECEIVER_H +#define _WALRECEIVER_H + +#include "access/xlog.h" +#include "access/xlogdefs.h" +#include "lib/stringinfo.h" +#include "fmgr.h" +#include "pgtime.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "replication/dataqueuedefs.h" +#include "replication/replicainternal.h" +#include "storage/latch.h" +#include "storage/spin.h" + +/* + * MAXCONNINFO: maximum size of a connection string. + * + * XXX: Should this move to pg_config_manual.h? + */ +#define MAXCONNINFO 1024 +#define HIGHEST_PERCENT 100 +#define STREAMING_START_PERCENT 90 + +#define DUMMY_STANDBY_DATADIR "base/dummy_standby" + +/* Can we allow the standby to accept replication connection from another standby? */ +#define AllowCascadeReplication() \ + (g_instance.attr.attr_storage.EnableHotStandby && g_instance.attr.attr_storage.max_wal_senders > 0) + +#define SETXLOGLOCATION(a, b) \ + do { \ + a = b; \ + } while (0); + +/* + * Values for WalRcv->walRcvState. + */ +typedef enum { + WALRCV_STOPPED, /* stopped and mustn't start up again */ + WALRCV_STARTING, /* launched, but the process hasn't initialized yet */ + WALRCV_RUNNING, /* walreceiver is running */ + WALRCV_STOPPING /* requested to stop, but still running */ +} WalRcvState; + +/* + * @@GaussDB@@ + * Brief : Indicate the connect error of server try to connect the primary. + * Description : NONE_ERROR (first try to connect the primary) + * CHANNEL_ERROR (server should try next channel) + * REPL_INFO_ERROR (server should try next replconnlist) + */ +typedef enum { NONE_ERROR, CHANNEL_ERROR, REPL_INFO_ERROR } WalRcvConnError; + +typedef struct WalRcvCtlBlock { + XLogRecPtr receivePtr; /* last byte + 1 received in the standby. */ + XLogRecPtr writePtr; /* last byte + 1 written out in the standby */ + XLogRecPtr flushPtr; /* last byte + 1 flushed in the standby */ + XLogRecPtr walStart; + XLogRecPtr lastReadPtr; + int64 walWriteOffset; + int64 walFreeOffset; + int64 walReadOffset; + bool walIsWriting; + slock_t mutex; + + char walReceiverBuffer[FLEXIBLE_ARRAY_MEMBER]; +} WalRcvCtlBlock; + +typedef enum { REPCONNTARGET_DEFAULT, REPCONNTARGET_PRIMARY, REPCONNTARGET_DUMMYSTANDBY, REPCONNTARGET_STANDBY } ReplConnTarget; + +/* Shared memory area for management of walreceiver process */ +typedef struct WalRcvData { + /* + * PID of currently active walreceiver process, its current state and + * start time (actually, the time at which it was requested to be + * started). + */ + ThreadId pid; + ThreadId writerPid; + int lwpId; + WalRcvState walRcvState; + ClusterNodeState node_state; /* state of the node in the cluster */ + pg_time_t startTime; + + ServerMode peer_role; + bool isRuning; + /*walsender and walreceiver xlog locations*/ + XLogRecPtr sender_sent_location; + XLogRecPtr sender_write_location; + XLogRecPtr sender_flush_location; + XLogRecPtr sender_replay_location; + XLogRecPtr receiver_received_location; + XLogRecPtr receiver_write_location; + XLogRecPtr receiver_flush_location; + XLogRecPtr receiver_replay_location; + + DbState peer_state; + + /* + * receiveStart is the first byte position that will be received. When + * startup process starts the walreceiver, it sets receiveStart to the + * point where it wants the streaming to begin. + */ + XLogRecPtr receiveStart; + + /* + * receivedUpto-1 is the last byte position that has already been + * received. At the first startup of walreceiver, receivedUpto is set to + * receiveStart. After that, walreceiver updates this whenever it flushes + * the received WAL to disk. + */ + XLogRecPtr receivedUpto; + + /* + * The xlog locations is used for counting sync percentage in function GetSyncPercent. + */ + XLogRecPtr syncPercentCountStart; + + /* + * latestChunkStart is the starting byte position of the current "batch" + * of received WAL. It's actually the same as the previous value of + * receivedUpto before the last flush to disk. Startup process can use + * this to detect whether it's keeping up or not. + */ + XLogRecPtr latestChunkStart; + + /* + * position and crc of the latest valid WAL record on the receiver. + */ + XLogRecPtr latestValidRecord; + pg_crc32 latestRecordCrc; + + /* + * Time of send and receive of any message received. + */ + TimestampTz lastMsgSendTime; + TimestampTz lastMsgReceiptTime; + + /* + * Latest reported end of WAL on the sender + */ + XLogRecPtr latestWalEnd; + TimestampTz latestWalEndTime; + + /* recvwriter write queue position (local queue) */ + DataQueuePtr local_write_pos; + + int dummyStandbySyncPercent; + /* Flag if failed to connect to dummy when failover */ + bool dummyStandbyConnectFailed; + + /* + * connection string; is used for walreceiver to connect with the primary. + */ + char conninfo[MAXCONNINFO]; + int ntries; + + /* + * replication slot name; is also used for walreceiver to connect with + * the primary + */ + char slotname[NAMEDATALEN]; + + WalRcvConnError conn_errno; + ReplConnInfo conn_channel; + ReplConnTarget conn_target; + + Latch* walrcvWriterLatch; + WalRcvCtlBlock* walRcvCtlBlock; + + slock_t mutex; /* locks shared variables shown above */ + slock_t exitLock; +} WalRcvData; + +extern XLogRecPtr latestValidRecord; +extern pg_crc32 latestRecordCrc; + +extern const char *g_reserve_param[RESERVE_SIZE]; +extern bool ws_dummy_data_writer_use_file; +extern THR_LOCAL uint32 ws_dummy_data_read_file_num; + +/* prototypes for functions in walreceiver.c */ +extern void WalReceiverMain(void); +extern void walrcvWriterMain(void); + +/* prototypes for functions in walrcvwriter.cpp */ +extern int WalDataRcvWrite(void); + +extern void WSDataRcvCheck(char* data_buf, Size nbytes); + +/* prototypes for functions in walreceiverfuncs.c */ +extern Size WalRcvShmemSize(void); +extern void WalRcvShmemInit(void); +extern void ShutdownWalRcv(void); +extern bool WalRcvInProgress(void); +extern void connect_dn_str(char* conninfo, int replIndex); +extern void RequestXLogStreaming( + XLogRecPtr* recptr, const char* conninfo, ReplConnTarget conn_target, const char* slotname); +extern StringInfo get_rcv_slot_name(void); +extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr* latestChunkStart); +extern XLogRecPtr GetWalStartPtr(); +extern bool WalRcvAllReplayIsDone(); +extern bool WalRcvIsDone(); +extern int GetReplicationApplyDelay(void); +extern int GetReplicationTransferLatency(void); +extern int GetWalRcvDummyStandbySyncPercent(void); +extern void SetWalRcvDummyStandbySyncPercent(int percent); +extern void CloseWSDataFileOnDummyStandby(void); +extern void InitWSDataNumOnDummyStandby(void); + +extern WalRcvCtlBlock* getCurrentWalRcvCtlBlock(void); +extern int walRcvWrite(WalRcvCtlBlock* walrcb); +extern int WSWalRcvWrite(WalRcvCtlBlock* walrcb, char* buf, Size nbytes, XLogRecPtr start_ptr); +extern void WalRcvXLogClose(void); +extern bool WalRcvIsShutdown(void); + +extern void ProcessWSRmXLog(void); +extern void ProcessWSRmData(void); +extern void SetWalRcvWriterPID(ThreadId tid); +extern bool WalRcvWriterInProgress(void); +extern bool walRcvCtlBlockIsEmpty(void); +extern void ProcessWalRcvInterrupts(void); +extern ReplConnInfo* GetRepConnArray(int* cur_idx); +extern void XLogWalRcvSendReply(bool force, bool requestReply); +extern int GetSyncPercent(XLogRecPtr startLsn, XLogRecPtr maxLsn, XLogRecPtr nowLsn); +extern const char* wal_get_role_string(ServerMode mode, bool getPeerRole = false); +extern const char* wal_get_rebuild_reason_string(HaRebuildReason reason); +extern Datum pg_stat_get_stream_replications(PG_FUNCTION_ARGS); +extern void GetPrimaryServiceAddress(char* address, size_t address_len); +extern void MakeDebugLog(TimestampTz sendTime, TimestampTz lastMsgReceiptTime, const char* msgFmt); +extern void WalRcvSetPercentCountStartLsn(XLogRecPtr startLsn); +extern void clean_failover_host_conninfo_for_dummy(void); +extern void set_failover_host_conninfo_for_dummy(const char *remote_host, int remote_port); +extern void get_failover_host_conninfo_for_dummy(int *repl); +extern void set_wal_rcv_write_rec_ptr(XLogRecPtr rec_ptr); + + +static inline void WalRcvCtlAcquireExitLock(void) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile WalRcvData *walrcv = t_thrd.walreceiverfuncs_cxt.WalRcv; + SpinLockAcquire(&walrcv->exitLock); +} + +static inline void WalRcvCtlReleaseExitLock(void) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile WalRcvData *walrcv = t_thrd.walreceiverfuncs_cxt.WalRcv; + SpinLockRelease(&walrcv->exitLock); +} +#endif /* _WALRECEIVER_H */ diff -uprN postgresql-hll-2.14_old/include/replication/walsender.h postgresql-hll-2.14/include/replication/walsender.h --- postgresql-hll-2.14_old/include/replication/walsender.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/walsender.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,88 @@ +/* ------------------------------------------------------------------------- + * + * walsender.h + * Exports from replication/walsender.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walsender.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALSENDER_H +#define _WALSENDER_H + +#include + +#include "fmgr.h" +#include "alarm/alarm.h" +#include "replication/replicainternal.h" +#include "utils/tuplestore.h" + +#define WS_MAX_SEND_SIZE (uint32)(g_instance.attr.attr_storage.MaxSendSize * 1024) +#define WS_CU_SEND_SLICE_SIZE (512 * 1024) +#define WS_XLOG_HDR_SIZE (sizeof(uint32) + 1 + sizeof(XLogRecPtr)) +#define WS_DATA_HDR_SIZE sizeof(DataElementHeaderData) +#define WS_DATA_MSG_HDR_SIZE sizeof(WalDataPageMessageHeader) +#define WS_DATA_MSG_PREFIX_LEN (sizeof(uint32) + 1 + sizeof(XLogRecPtr) * 2) +#define AM_WAL_NORMAL_SENDER (t_thrd.role == WAL_NORMAL_SENDER) +#define AM_WAL_STANDBY_SENDER (t_thrd.role == WAL_STANDBY_SENDER) +#define AM_WAL_DB_SENDER (t_thrd.role == WAL_DB_SENDER) +#define AM_WAL_SENDER (AM_WAL_NORMAL_SENDER || AM_WAL_STANDBY_SENDER || AM_WAL_DB_SENDER) + +typedef struct WSXLogJustSendRegion { + XLogRecPtr start_ptr; + XLogRecPtr end_ptr; +} WSXLogJustSendRegion; + +extern int WalSenderMain(void); +extern void GetPMstateAndRecoveryInProgress(void); +extern void WalSndSignals(void); +extern Size WalSndShmemSize(void); +extern void WalSndShmemInit(void); +extern void WalSndWakeup(void); +extern void WalSndRqstFileReload(void); +extern bool WalSndInProgress(int type); +extern void StandbyOrSecondaryIsAlive(void); +extern void StopAliveBuildSender(void); +extern bool IsAllBuildSenderExit(); + +extern bool WalSegmemtRemovedhappened; +extern AlarmCheckResult WalSegmentsRemovedChecker(Alarm* alarm, AlarmAdditionalParam* additionalParam); +extern Datum pg_stat_get_wal_senders(PG_FUNCTION_ARGS); +extern Tuplestorestate* BuildTupleResult(FunctionCallInfo fcinfo, TupleDesc* tupdesc); + +extern void GetFastestReplayStandByServiceAddress( + char* fastest_remote_address, char* second_fastest_remote_address, size_t address_len); +extern bool IsPrimaryStandByReadyToRemoteRead(void); +extern void IdentifyMode(void); +extern bool WalSndAllInProgress(int type); +extern bool WalSndQuorumInProgress(int type); +extern XLogSegNo WalGetSyncCountWindow(void); + +/* + * Remember that we want to wakeup walsenders later + * + * This is separated from doing the actual wakeup because the writeout is done + * while holding contended locks. + */ +#define WalSndWakeupRequest() \ + do { \ + t_thrd.walsender_cxt.wake_wal_senders = true; \ + } while (0) + +/* + * wakeup walsenders if there is work to be done + */ +#define WalSndWakeupProcessRequests() \ + do { \ + if (t_thrd.walsender_cxt.wake_wal_senders) { \ + t_thrd.walsender_cxt.wake_wal_senders = false; \ + if (g_instance.attr.attr_storage.max_wal_senders > 0) \ + WalSndWakeup(); \ + } \ + } while (0) + +#define MAX_XLOG_RECORD(a, b) ((XLByteLT((a), (b))) ? (b) : (a)) + +#endif /* _WALSENDER_H */ diff -uprN postgresql-hll-2.14_old/include/replication/walsender_private.h postgresql-hll-2.14/include/replication/walsender_private.h --- postgresql-hll-2.14_old/include/replication/walsender_private.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/replication/walsender_private.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,172 @@ +/* ------------------------------------------------------------------------- + * + * walsender_private.h + * Private definitions from replication/walsender.c. + * + * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group + * + * src/include/replication/walsender_private.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _WALSENDER_PRIVATE_H +#define _WALSENDER_PRIVATE_H + +#include "access/xlog.h" +#include "nodes/nodes.h" +#include "replication/replicainternal.h" +#include "replication/syncrep.h" +#include "replication/repl_gramparse.h" +#include "storage/latch.h" +#include "storage/shmem.h" +#include "storage/spin.h" +#include "postgres.h" +#include "knl/knl_variable.h" + +typedef enum WalSndState { + WALSNDSTATE_STARTUP = 0, + WALSNDSTATE_BACKUP, + WALSNDSTATE_CATCHUP, + WALSNDSTATE_STREAMING +} WalSndState; + +typedef enum SndRole { + SNDROLE_PRIMARY_STANDBY = 1, /* primary to standby */ + SNDROLE_PRIMARY_BUILDSTANDBY = 2, /* primary to gs_ctl when run build command */ + SNDROLE_PRIMARY_DUMMYSTANDBY = 4, /* primary to dummy standby */ + SNDROLE_DUMMYSTANDBY_STANDBY = 8 /* dummy standby to standby */ +} SndRole; + +typedef struct WSXLogPageReadPrivate { + TimeLineID tli; + XLogSegNo xlogreadlogsegno; + int xlogreadfd; +} WSXLogPageReadPrivate; + +/* For log ctrl. Willing let standby flush and apply log under RTO seconds */ +typedef struct LogCtrlData { + int64 sleep_time; + int64 balance_sleep_time; + int64 prev_RTO; + int64 current_RTO; + uint64 sleep_count; + int64 sleep_count_limit; + XLogRecPtr prev_flush; + XLogRecPtr prev_apply; + TimestampTz prev_reply_time; + uint64 pre_rate1; + uint64 pre_rate2; +} LogCtrlData; + +/* + * Each walsender has a WalSnd struct in shared memory. + */ +typedef struct WalSnd { + ThreadId pid; /* this walsender's process id, or 0 */ + int lwpId; + WalSndState state; /* this walsender's state */ + TimestampTz catchupTime[2]; /* time stamp of this walsender's catchup */ + ClusterNodeState node_state; /* state of the node in the cluster */ + SndRole sendRole; /* role of sender */ + XLogRecPtr sentPtr; /* WAL has been sent up to this point */ + bool needreload; /* does currently-open file need to be + * reloaded? */ + bool sendKeepalive; /* do we send keepalives on this connection? */ + bool replSender; /* is the walsender a normal replication or building */ + + ServerMode peer_role; + DbState peer_state; + /* + * The xlog locations that have been received, written, flushed, and applied by + * standby-side. These may be invalid if the standby-side has not offered + * values yet. + */ + XLogRecPtr receive; + XLogRecPtr write; + XLogRecPtr flush; + XLogRecPtr apply; + + /* if valid means all the required replication data already flushed on the standby */ + XLogRecPtr data_flush; + /* + * The xlog locations is used for counting sync percentage in function GetSyncPercent. + */ + XLogRecPtr syncPercentCountStart; + + ReplConnInfo wal_sender_channel; + int channel_get_replc; + + /* Protects shared variables shown above. */ + slock_t mutex; + + /* + * Latch used by backends to wake up this walsender when it has work to + * do. + */ + Latch latch; + + /* + * The priority order of the standby managed by this WALSender, as listed + * in synchronous_standby_names, or 0 if not-listed. Protected by + * SyncRepLock. + */ + int sync_standby_priority; + int index; + + LogCtrlData log_ctrl; +} WalSnd; + +extern THR_LOCAL WalSnd* MyWalSnd; + +/* There is one WalSndCtl struct for the whole database cluster */ +typedef struct WalSndCtlData { + /* + * Synchronous replication queue with one queue per request type. + * Protected by SyncRepLock. + */ + SHM_QUEUE SyncRepQueue[NUM_SYNC_REP_WAIT_MODE]; + + /* + * Current location of the head of the queue. All waiters should have a + * waitLSN that follows this value. Protected by SyncRepLock. + */ + XLogRecPtr lsn[NUM_SYNC_REP_WAIT_MODE]; + + /* + * Are any sync standbys defined? Waiting backends can't reload the + * config file safely, so checkpointer updates this value as needed. + * Protected by SyncRepLock. + */ + bool sync_standbys_defined; + + /* + * Whether master is allowed to switched to standalone if no synchronous + * Standbys are available. This is copy of GUC variable most_available_sync. + */ + bool most_available_sync; + + /* + * Indicates the current running mode of master node. If it is true means + * there is no synchronous standby available so it is running in standalone + * mode. + */ + bool sync_master_standalone; + + /* + * The demotion of postmaster Also indicates that all the walsenders + * should reject any demote requests if postmaster is doning domotion. + */ + DemoteMode demotion; + + /* Protects shared variables of all walsnds. */ + slock_t mutex; + + WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} WalSndCtlData; + +extern THR_LOCAL WalSndCtlData* WalSndCtl; +extern volatile bool bSyncStat; +extern volatile bool bSyncStatStatBefore; +extern void WalSndSetState(WalSndState state); + +#endif /* _WALSENDER_PRIVATE_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/prs2lock.h postgresql-hll-2.14/include/rewrite/prs2lock.h --- postgresql-hll-2.14_old/include/rewrite/prs2lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/prs2lock.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * prs2lock.h + * data structures for POSTGRES Rule System II (rewrite rules only) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/prs2lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PRS2LOCK_H +#define PRS2LOCK_H + +#include "access/attnum.h" +#include "nodes/pg_list.h" + +/* + * RewriteRule - + * holds a info for a rewrite rule + * + */ +typedef struct RewriteRule { + Oid ruleId; + CmdType event; + AttrNumber attrno; + Node* qual; + List* actions; + char enabled; + bool isInstead; +} RewriteRule; + +/* + * RuleLock - + * all rules that apply to a particular relation. Even though we only + * have the rewrite rule system left and these are not really "locks", + * the name is kept for historical reasons. + */ +typedef struct RuleLock { + int numLocks; + RewriteRule** rules; +} RuleLock; + +#endif /* REWRITE_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteDefine.h postgresql-hll-2.14/include/rewrite/rewriteDefine.h --- postgresql-hll-2.14_old/include/rewrite/rewriteDefine.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteDefine.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,36 @@ +/* ------------------------------------------------------------------------- + * + * rewriteDefine.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteDefine.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEDEFINE_H +#define REWRITEDEFINE_H + +#include "nodes/parsenodes.h" +#include "utils/relcache.h" + +#define RULE_FIRES_ON_ORIGIN 'O' +#define RULE_FIRES_ALWAYS 'A' +#define RULE_FIRES_ON_REPLICA 'R' +#define RULE_DISABLED 'D' + +extern void DefineRule(RuleStmt* stmt, const char* queryString); + +extern void DefineQueryRewrite( + char* rulename, Oid event_relid, Node* event_qual, CmdType event_type, bool is_instead, bool replace, List* action); + +extern void RenameRewriteRule(Oid owningRel, const char* oldName, const char* newName); + +extern void setRuleCheckAsUser(Node* node, Oid userid); + +extern void EnableDisableRule(Relation rel, const char* rulename, char fires_when); + +#endif /* REWRITEDEFINE_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteHandler.h postgresql-hll-2.14/include/rewrite/rewriteHandler.h --- postgresql-hll-2.14_old/include/rewrite/rewriteHandler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteHandler.h 2020-12-12 17:06:43.368349599 +0800 @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------------------- + * + * rewriteHandler.h + * External interface to query rewriter. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteHandler.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEHANDLER_H +#define REWRITEHANDLER_H + +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +extern List* QueryRewrite(Query* parsetree); +extern void AcquireRewriteLocks(Query* parsetree, bool forUpdatePushedDown); +extern Node* build_column_default(Relation rel, int attrno, bool isInsertCmd = false); +extern List* pull_qual_vars(Node* node, int varno = 0, int flags = 0, bool nonRepeat = false); +extern void rewriteTargetListMerge(Query* parsetree, Index result_relation, List* range_table); + +#ifdef PGXC +extern List* QueryRewriteCTAS(Query* parsetree); +extern List* QueryRewriteRefresh(Query *parsetree); +#endif + +#endif /* REWRITEHANDLER_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteManip.h postgresql-hll-2.14/include/rewrite/rewriteManip.h --- postgresql-hll-2.14_old/include/rewrite/rewriteManip.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteManip.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,62 @@ +/* ------------------------------------------------------------------------- + * + * rewriteManip.h + * Querytree manipulation subroutines for query rewriter. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteManip.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEMANIP_H +#define REWRITEMANIP_H + +#include "nodes/parsenodes.h" + +typedef struct replace_rte_variables_context replace_rte_variables_context; + +typedef Node* (*replace_rte_variables_callback)(Var* var, replace_rte_variables_context* context); + +struct replace_rte_variables_context { + replace_rte_variables_callback callback; /* callback function */ + void* callback_arg; /* context data for callback function */ + int target_varno; /* RTE index to search for */ + int sublevels_up; /* (current) nesting depth */ + bool inserted_sublink; /* have we inserted a SubLink? */ +}; + +extern void OffsetVarNodes(Node* node, int offset, int sublevels_up); +extern void ChangeVarNodes(Node* node, int old_varno, int new_varno, int sublevels_up); +extern void IncrementVarSublevelsUp(Node* node, int delta_sublevels_up, int min_sublevels_up); +extern void IncrementVarSublevelsUp_rtable(List* rtable, int delta_sublevels_up, int min_sublevels_up); + +extern bool rangeTableEntry_used(Node* node, int rt_index, int sublevels_up); +extern bool attribute_used(Node* node, int rt_index, int attno, int sublevels_up); + +extern Query* getInsertSelectQuery(Query* parsetree, Query*** subquery_ptr); + +extern void AddQual(Query* parsetree, Node* qual); +extern void AddInvertedQual(Query* parsetree, Node* qual); + +extern bool contain_aggs_of_level_or_above(Node* node, int levelsup); +extern bool contain_aggs_of_level(Node* node, int levelsup); +extern int locate_agg_of_level(Node* node, int levelsup); +extern int locate_windowfunc(Node* node); +extern bool checkExprHasAggs(Node* node); +extern bool checkExprHasWindowFuncs(Node* node); +extern bool checkExprHasSubLink(Node* node); + +extern Node* replace_rte_variables(Node* node, int target_varno, int sublevels_up, + replace_rte_variables_callback callback, void* callback_arg, bool* outer_hasSubLinks); +extern Node* replace_rte_variables_mutator(Node* node, replace_rte_variables_context* context); + +extern Node* map_variable_attnos( + Node* node, int target_varno, int sublevels_up, const AttrNumber* attno_map, int map_length, bool* found_whole_row); + +extern Node* ResolveNew(Node* node, int target_varno, int sublevels_up, RangeTblEntry* target_rte, List* targetlist, + int event, int update_varno, bool* outer_hasSubLinks); + +#endif /* REWRITEMANIP_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteRemove.h postgresql-hll-2.14/include/rewrite/rewriteRemove.h --- postgresql-hll-2.14_old/include/rewrite/rewriteRemove.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteRemove.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,21 @@ +/* ------------------------------------------------------------------------- + * + * rewriteRemove.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteRemove.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITEREMOVE_H +#define REWRITEREMOVE_H + +#include "nodes/parsenodes.h" + +extern void RemoveRewriteRuleById(Oid ruleOid); + +#endif /* REWRITEREMOVE_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteRlsPolicy.h postgresql-hll-2.14/include/rewrite/rewriteRlsPolicy.h --- postgresql-hll-2.14_old/include/rewrite/rewriteRlsPolicy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteRlsPolicy.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,66 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rewriteRlsPolicy.h + * External interface to row level security rewriter. + * + * + * + * IDENTIFICATION + * src/include/rewrite/rewriteRlsPolicy.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REWRITERLSPOLICY_H +#define REWRITERLSPOLICY_H + +#include "nodes/parsenodes.h" +#include "utils/array.h" + +/* + * The struct that can describe Row Level Security Policy. + * Aleady know the relation information, no need to store relation info. + */ +typedef struct RlsPolicy { + Oid policyOid; /* Policy's oid */ + char cmdName; /* the command name the policy applies to */ + bool isPermissive; /* restrictive or permissive policy */ + bool hasSubLink; /* policy quals include sublink or not */ + char* policyName; /* Policy's name */ + ArrayType* roles; /* the roles associated with the policy */ + Expr* usingExpr; /* the policy's condition */ +} RlsPolicy; + +/* + * The struct describe the Row-Level-Security policies related with current relation. + */ +typedef struct RlsPoliciesDesc { + MemoryContext rlsCxt; /* row level security memory context */ + List* rlsPolicies; /* list of row level security policies */ +} RlsPoliciesDesc; + +enum RlsPolicyCheckResult { RLS_POLICY_MATCH, RLS_POLICY_MISMATCH }; + +enum RelationRlsStatus { + RELATION_RLS_DISABLE, + RELATION_RLS_ENABLE, + RELATION_RLS_FORCE_DISABLE, + RELATION_RLS_FORCE_ENABLE +}; + +extern void GetRlsPolicies(const Query* query, const RangeTblEntry* rte, const Relation relation, List** rlsQuals, + int rtIndex, bool& hasRowSecurity, bool& hasSubLink); + +#endif /* REWRITERLSPOLICY_H */ diff -uprN postgresql-hll-2.14_old/include/rewrite/rewriteSupport.h postgresql-hll-2.14/include/rewrite/rewriteSupport.h --- postgresql-hll-2.14_old/include/rewrite/rewriteSupport.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rewrite/rewriteSupport.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * rewriteSupport.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rewrite/rewriteSupport.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REWRITESUPPORT_H +#define REWRITESUPPORT_H + +/* The ON SELECT rule of a view is always named this: */ +#define ViewSelectRuleName "_RETURN" + +extern bool IsDefinedRewriteRule(Oid owningRel, const char* ruleName); + +extern void SetRelationRuleStatus(Oid relationId, bool relHasRules, bool relIsBecomingView); + +extern Oid get_rewrite_oid(Oid relid, const char* rulename, bool missing_ok); +extern Oid get_rewrite_oid_without_relid(const char* rulename, Oid* relid, bool missing_ok); +extern char* get_rewrite_rulename(Oid ruleid, bool missing_ok); +extern bool rel_has_rule(Oid relid, char ev_type); + + +#endif /* REWRITESUPPORT_H */ diff -uprN postgresql-hll-2.14_old/include/rusagestub.h postgresql-hll-2.14/include/rusagestub.h --- postgresql-hll-2.14_old/include/rusagestub.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/rusagestub.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * rusagestub.h + * Stubs for getrusage(3). + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/rusagestub.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RUSAGESTUB_H +#define RUSAGESTUB_H + +#include /* for struct timeval */ +#ifndef WIN32 +#include /* for struct tms */ +#endif +#include /* for CLK_TCK */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN (-1) + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ +}; + +extern int getrusage(int who, struct rusage* rusage); + +#ifndef WIN32 +extern List* get_operator_name(Oid operid, Oid arg1, Oid arg2); +#endif + +#endif /* RUSAGESTUB_H */ diff -uprN postgresql-hll-2.14_old/include/securec_check.h postgresql-hll-2.14/include/securec_check.h --- postgresql-hll-2.14_old/include/securec_check.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/securec_check.h 2020-12-12 17:06:43.369349612 +0800 @@ -0,0 +1,117 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * securec_check.h + * + * + * + * IDENTIFICATION + * src/include/securec_check.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _SECUREC_CHECK_H_ +#define _SECUREC_CHECK_H_ + +#include "securectype.h" +#include +/* free space for error function operator with exit-function mechanism */ +#define freeSecurityFuncSpace_c(str1, str2) \ + { \ + if (str1 != NULL && strlen(str1) > 0) \ + free((char*)str1); \ + if (str2 != NULL && strlen(str2) > 0) \ + free((char*)str2); \ + } + +#ifndef GDS_SERVER +/* gds using gds_securec_check and gds_securec_check_ss */ +#define securec_check_c(errno, str1, str2) \ + { \ + errno_t e_for_securec_check_c = (errno); \ + if (EOK != e_for_securec_check_c) { \ + freeSecurityFuncSpace_c(str1, str2); \ + switch (e_for_securec_check_c) { \ + case EINVAL: \ + printf("ERROR at %s : %d : The destination buffer is NULL or not terminated. The second case " \ + "only occures in function strcat_s/strncat_s.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + printf("ERROR at %s : %d : The source buffer is NULL.\n", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + printf("ERROR at %s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + printf("ERROR at %s : %d : The parameter destMax is too small or parameter count is larger than " \ + "macro parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + printf("ERROR at %s : %d : The destination buffer and source buffer are overlapped.\n", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + printf("ERROR at %s : %d : Unrecognized return type.\n", __FILE__, __LINE__); \ + break; \ + } \ + exit(1); \ + } \ + } + +#define securec_check_ss_c(errno, str1, str2) \ + do { \ + if (errno == -1) { \ + freeSecurityFuncSpace_c(str1, str2); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) +#endif + +/* define a macro about the return value of security function */ +#define securec_check_intval_core(val, express) \ + if (val == -1) { \ + fprintf(stderr, \ + "WARNING: %s:%d failed on calling " \ + "security function.\n", \ + __FILE__, \ + __LINE__); \ + express; \ + } + +#define securec_check_for_sscanf_s(ret, min_num, str1, str2) \ + do { \ + if ((ret) < (min_num)) { \ + freeSecurityFuncSpace_c(str1, str2); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } while (0) +#endif diff -uprN postgresql-hll-2.14_old/include/securec.h postgresql-hll-2.14/include/securec.h --- postgresql-hll-2.14_old/include/securec.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/securec.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,624 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. + * Description: The user of this secure c library should include this header file in you source code. + * This header file declare all supported API prototype of the library, + * such as memcpy_s, strcpy_s, wcscpy_s,strcat_s, strncat_s, sprintf_s, scanf_s, and so on. + * Author: lishunda + * Create: 2014-02-25 + * Notes: Do not modify this file by yourself. + * History: 2018-09-27 zhaozhijian Code base quality improvement + */ + +#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 +#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27 + +#include "securectype.h" +#ifndef SECUREC_HAVE_STDARG_H +#define SECUREC_HAVE_STDARG_H 1 +#endif + +#if SECUREC_HAVE_STDARG_H +#include +#endif + +#ifndef SECUREC_HAVE_ERRNO_H +#define SECUREC_HAVE_ERRNO_H 1 +#endif + +/* EINVAL ERANGE may defined in errno.h */ +#if SECUREC_HAVE_ERRNO_H +#if SECUREC_IN_KERNEL +#include +#else +#include +#endif +#endif + +/* Define error code */ +#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \ + (defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__)) +#ifndef SECUREC_DEFINED_ERRNO_TYPE +#define SECUREC_DEFINED_ERRNO_TYPE +/* Just check whether macrodefinition exists. */ +#ifndef errno_t +typedef int errno_t; +#endif +#endif +#endif + +/* Success */ +#ifndef EOK +#define EOK 0 +#endif + +#ifndef EINVAL +/* The src buffer is not correct and destination buffer cant not be reset */ +#define EINVAL 22 +#endif + +#ifndef EINVAL_AND_RESET +/* Once the error is detected, the dest buffer must be reseted! Value is 22 xor 128 */ +#define EINVAL_AND_RESET 150 +#endif + +#ifndef ERANGE +/* The destination buffer is not long enough and destination buffer can not be reset */ +#define ERANGE 34 +#endif + +#ifndef ERANGE_AND_RESET +/* Once the error is detected, the dest buffer must be reseted! Value is 34 xor 128 */ +#define ERANGE_AND_RESET 162 +#endif + +#ifndef EOVERLAP_AND_RESET +/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 xor 128 */ +#define EOVERLAP_AND_RESET 182 +#endif + +/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */ +#ifndef SECUREC_API +#if defined(SECUREC_DLL_EXPORT) +#define SECUREC_API __declspec(dllexport) +#elif defined(SECUREC_DLL_IMPORT) +#define SECUREC_API __declspec(dllimport) +#else +/* + * Standardized function declaration. If a security function is declared in the your code, + * it may cause a compilation alarm,Please delete the security function you declared. + * Adding extern under windows will cause the system to have inline functions to expand, + * so do not add the extern in default + */ +#if defined(_MSC_VER) +#define SECUREC_API +#else +#define SECUREC_API extern +#endif +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + /* + * Description: The GetHwSecureCVersion function get SecureC Version string and version number. + * Parameter: verNumber - to store version number (for example value is 0x500 | 0xa) + * Return: version string + */ + SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber); + +#if SECUREC_ENABLE_MEMSET + /* + * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of + * the first count characters of the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: c - the value to be copied + * Parameter: count - copies count bytes of value to dest + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count); +#endif + +#ifndef SECUREC_ONLY_DECLARE_MEMSET +#define SECUREC_ONLY_DECLARE_MEMSET 0 +#endif + +#if !SECUREC_ONLY_DECLARE_MEMSET + +#if SECUREC_ENABLE_MEMMOVE + /* + * Description: The memmove_s function copies n characters from the object pointed to by src + * into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count); +#endif + +#if SECUREC_ENABLE_MEMCPY + /* + * Description: The memcpy_s function copies n characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count bytes from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count); +#endif + +#if SECUREC_ENABLE_STRCPY + /* + * Description: The strcpy_s function copies the string pointed to by strSrc (including + * the terminating null character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCPY + /* + * Description: The strncpy_s function copies not more than n successive characters (not including + * the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRCAT + /* + * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including + * the terminating null character) to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCAT + /* + * Description: The strncat_s function appends not more than n successive characters (not including + * the terminating null character) + * from the array pointed to by strSrc to the end of the string pointed to by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Parameter: strSrc - source address + * Parameter: count - copies count characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_VSPRINTF + /* + * Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); +#endif + +#if SECUREC_ENABLE_SPRINTF + /* + * Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax + * and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1. + */ + SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4); +#endif + +#if SECUREC_ENABLE_VSNPRINTF + /* + * Description: The vsnprintf_s function is equivalent to the vsnprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + va_list argList) SECUREC_ATTRIBUTE(4, 0); +#endif + +#if SECUREC_ENABLE_SNPRINTF + /* + * Description: The snprintf_s function is equivalent to the snprintf function except for + * the parameter destMax/count and the explicit runtime-constraints violation + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs + */ + SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, + ...) SECUREC_ATTRIBUTE(4, 5); +#endif + +#if SECUREC_SNPRINTF_TRUNCATED + /* + * Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format, + va_list argList) SECUREC_ATTRIBUTE(3, 0); + + /* + * Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except + * no count parameter and return value + * Parameter: strDest - produce output according to a format ,write to the character string strDest. + * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0') + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null byte '\0'), + * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs + */ + SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax, + const char *format, ...) SECUREC_ATTRIBUTE(3, 4); +#endif + +#if SECUREC_ENABLE_SCANF + /* + * Description: The scanf_s function is equivalent to fscanf_s with the argument stdin + * interposed before the arguments to scanf_s + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int scanf_s(const char *format, ...); +#endif + +#if SECUREC_ENABLE_VSCANF + /* + * Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vscanf_s(const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SSCANF + /* + * Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a + * string (specified by the argument buffer) rather than from a stream + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int sscanf_s(const char *buffer, const char *format, ...); +#endif + +#if SECUREC_ENABLE_VSSCANF + /* + * Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list + * replaced by argList + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_FSCANF + /* + * Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers + * apply to a pair of arguments (unless assignment suppression is indicated by a*) + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fscanf_s(FILE *stream, const char *format, ...); +#endif + +#if SECUREC_ENABLE_VFSCANF + /* + * Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list + * replaced by argList + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList); +#endif + +#if SECUREC_ENABLE_STRTOK + /* + * Description: The strtok_s function parses a string into a sequence of strToken, + * replace all characters in strToken string that match to strDelimit set with 0. + * On the first call to strtok_s the string to be parsed should be specified in strToken. + * In each subsequent call that should parse the same string, strToken should be NULL + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned. + * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call, + * return NULL if the *context string length is equal 0, otherwise return *context. + */ + SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context); +#endif + +#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL + /* + * Description: The gets_s function reads at most one less than the number of characters specified + * by destMax from the stream pointed to by stdin, into the array pointed to by buffer + * Parameter: buffer - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating null character) + * Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL. + */ + SECUREC_API char *gets_s(char *buffer, size_t destMax); +#endif + +#if SECUREC_ENABLE_WCHAR_FUNC +#if SECUREC_ENABLE_MEMCPY + /* + * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to + * by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); +#endif + +#if SECUREC_ENABLE_MEMMOVE + /* + * Description: The wmemmove_s function copies n successive wide characters from the object + * pointed to by src into the object pointed to by dest. + * Parameter: dest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: src - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count); +#endif + +#if SECUREC_ENABLE_STRCPY + /* + * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating + * null wide character) into the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCPY + /* + * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRCAT + /* + * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the + * terminating null wide character) to the end of the wide string pointed to by strDest + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc); +#endif + +#if SECUREC_ENABLE_STRNCAT + /* + * Description: The wcsncat_s function appends not more than n successive wide characters (not including the + * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to + * by strDest. + * Parameter: strDest - destination address + * Parameter: destMax - The maximum length of destination buffer(including the terminating wide character) + * Parameter: strSrc - source address + * Parameter: count - copies count wide characters from the src + * Return: EOK if there was no runtime-constraint violation + */ + SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count); +#endif + +#if SECUREC_ENABLE_STRTOK + /* + * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function + * Parameter: strToken - the string to be delimited + * Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string + * Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function + * Return: a pointer to the first character of a token, or a null pointer if there is no token + * or there is a runtime-constraint violation. + */ + SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context); +#endif + +#if SECUREC_ENABLE_VSPRINTF + /* + * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SPRINTF + + /* + * Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function + * Parameter: strDest - produce output according to a format ,write to the character string strDest + * Parameter: destMax - The maximum length of destination buffer(including the terminating null ) + * Parameter: format - fromat string + * Return: the number of characters printed(not including the terminating null wide characte), + * If an error occurred Return: -1. + */ + SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_FSCANF + /* + * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VFSCANF + /* + * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function + * Parameter: stream - stdio file stream + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SCANF + /* + * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int wscanf_s(const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VSCANF + /* + * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList); +#endif + +#if SECUREC_ENABLE_SSCANF + /* + * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...); +#endif + +#if SECUREC_ENABLE_VSSCANF + /* + * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function + * Parameter: buffer - read character from buffer + * Parameter: format - fromat string + * Parameter: argList - instead of a variable number of arguments + * Return: the number of input items assigned, If an error occurred Return: -1. + */ + SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList); +#endif +#endif /* SECUREC_ENABLE_WCHAR_FUNC */ +#endif + + /* Those functions are used by macro ,must declare hare , also for without function declaration warning */ + extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count); + extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc); + +#if SECUREC_WITH_PERFORMANCE_ADDONS + /* Those functions are used by macro */ + extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count); + extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count); + extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count); + extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count); + +/* The strcpy_sp is a macro, not a function in performance optimization mode. */ +#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCPY_SM((dest), (destMax), (src)) : \ + strcpy_s((dest), (destMax), (src))) + +/* The strncpy_sp is a macro, not a function in performance optimization mode. */ +#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \ + strncpy_s((dest), (destMax), (src), (count))) + +/* The strcat_sp is a macro, not a function in performance optimization mode. */ +#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRCAT_SM((dest), (destMax), (src)) : \ + strcat_s((dest), (destMax), (src))) + +/* The strncat_sp is a macro, not a function in performance optimization mode. */ +#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \ + __builtin_constant_p((destMax)) && \ + __builtin_constant_p((src))) ? \ + SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \ + strncat_s((dest), (destMax), (src), (count))) + +/* The memcpy_sp is a macro, not a function in performance optimization mode. */ +#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \ + memcpy_sOptAsm((dest), (destMax), (src), (count)))) + +/* The memset_sp is a macro, not a function in performance optimization mode. */ +#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \ + (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \ + (__builtin_constant_p((destMax)) ? \ + (((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \ + memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \ + memset_sOptAsm((dest), (destMax), (c), (count)))) + +#endif + +#ifdef __cplusplus +} +#endif +#endif + diff -uprN postgresql-hll-2.14_old/include/securectype.h postgresql-hll-2.14/include/securectype.h --- postgresql-hll-2.14_old/include/securectype.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/securectype.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,569 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2014-2018. All rights reserved. + * Description: Define internal used macro and data type. The marco of SECUREC_ON_64BITS + * will be determined in this header file, which is a switch for part + * of code. Some macro are used to supress warning by MS compiler. + * Author: lishunda + * Create: 2014-02-25 + * Notes: User can change the value of SECUREC_STRING_MAX_LEN and SECUREC_MEM_MAX_LEN + * macro to meet their special need, but The maximum value should not exceed 2G. + * History: 2018-09-27 zhaozhijian Code base quality improvement + */ +/* + * [Standardize-exceptions]: Performance-sensitive + * [reason]: Strict parameter verification has been done before use + */ + +#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 +#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7 + +#ifndef SECUREC_USING_STD_SECURE_LIB +#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__) +/* Security functions have been provided since vs2005, default use of system library functions */ +#define SECUREC_USING_STD_SECURE_LIB 0 +#else +#define SECUREC_USING_STD_SECURE_LIB 1 +#endif +#else +#define SECUREC_USING_STD_SECURE_LIB 0 +#endif +#endif + +/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB) +#ifndef SECUREC_DISABLE_CRT_FUNC +#define SECUREC_DISABLE_CRT_FUNC 1 +#endif +#ifndef SECUREC_DISABLE_CRT_IMP +#define SECUREC_DISABLE_CRT_IMP 1 +#endif +#else /* MSC VER */ +#ifndef SECUREC_DISABLE_CRT_FUNC +#define SECUREC_DISABLE_CRT_FUNC 0 +#endif +#ifndef SECUREC_DISABLE_CRT_IMP +#define SECUREC_DISABLE_CRT_IMP 0 +#endif +#endif + +#if SECUREC_DISABLE_CRT_FUNC +#ifdef __STDC_WANT_SECURE_LIB__ +#undef __STDC_WANT_SECURE_LIB__ +#endif +#define __STDC_WANT_SECURE_LIB__ 0 +#endif + +#if SECUREC_DISABLE_CRT_IMP +#ifdef _CRTIMP_ALTERNATIVE +#undef _CRTIMP_ALTERNATIVE +#endif +#define _CRTIMP_ALTERNATIVE /* Comment microsoft *_s function */ +#endif + +/* Compile in kernel under macro control */ +#ifndef SECUREC_IN_KERNEL +#ifdef __KERNEL__ +#define SECUREC_IN_KERNEL 1 +#else +#define SECUREC_IN_KERNEL 0 +#endif +#endif + +#if SECUREC_IN_KERNEL +#ifndef SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF_FILE 0 +#endif +#ifndef SECUREC_ENABLE_WCHAR_FUNC +#define SECUREC_ENABLE_WCHAR_FUNC 0 +#endif +#else /* SECUREC_IN_KERNEL */ +#ifndef SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF_FILE 1 +#endif +#ifndef SECUREC_ENABLE_WCHAR_FUNC +#define SECUREC_ENABLE_WCHAR_FUNC 1 +#endif +#endif + +/* Default secure function declaration, default declarations for non-standard functions */ +#ifndef SECUREC_SNPRINTF_TRUNCATED +#define SECUREC_SNPRINTF_TRUNCATED 1 +#endif + +#if SECUREC_USING_STD_SECURE_LIB +#if defined(_MSC_VER) && _MSC_VER >= 1400 +/* Declare secure functions that are not available in the VS compiler */ +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 1 +#endif +/* VS 2005 have vsnprintf_s function */ +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */ +#define snprintf_s _snprintf_s +#define SECUREC_ENABLE_SNPRINTF 0 +#endif +/* Before VS 2010 do not have v functions */ +#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS) +#ifndef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSCANF +#define SECUREC_ENABLE_VSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 1 +#endif +#endif + +#else /* MSC VER */ +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 0 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +#define SECUREC_ENABLE_SNPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_MEMMOVE +#define SECUREC_ENABLE_MEMMOVE 0 +#endif +#ifndef SECUREC_ENABLE_MEMCPY +#define SECUREC_ENABLE_MEMCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRCPY +#define SECUREC_ENABLE_STRCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRNCPY +#define SECUREC_ENABLE_STRNCPY 0 +#endif +#ifndef SECUREC_ENABLE_STRCAT +#define SECUREC_ENABLE_STRCAT 0 +#endif +#ifndef SECUREC_ENABLE_STRNCAT +#define SECUREC_ENABLE_STRNCAT 0 +#endif +#ifndef SECUREC_ENABLE_SPRINTF +#define SECUREC_ENABLE_SPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_VSPRINTF +#define SECUREC_ENABLE_VSPRINTF 0 +#endif +#ifndef SECUREC_ENABLE_SSCANF +#define SECUREC_ENABLE_SSCANF 0 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 0 +#endif +#ifndef SECUREC_ENABLE_SCANF +#define SECUREC_ENABLE_SCANF 0 +#endif +#ifndef SECUREC_ENABLE_VSCANF +#define SECUREC_ENABLE_VSCANF 0 +#endif + +#ifndef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif +#ifndef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#ifndef SECUREC_ENABLE_STRTOK +#define SECUREC_ENABLE_STRTOK 0 +#endif +#ifndef SECUREC_ENABLE_GETS +#define SECUREC_ENABLE_GETS 0 +#endif + +#else /* SECUREC USE STD SECURE LIB */ + +#ifndef SECUREC_ENABLE_MEMSET +#define SECUREC_ENABLE_MEMSET 1 +#endif +#ifndef SECUREC_ENABLE_MEMMOVE +#define SECUREC_ENABLE_MEMMOVE 1 +#endif +#ifndef SECUREC_ENABLE_MEMCPY +#define SECUREC_ENABLE_MEMCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRCPY +#define SECUREC_ENABLE_STRCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRNCPY +#define SECUREC_ENABLE_STRNCPY 1 +#endif +#ifndef SECUREC_ENABLE_STRCAT +#define SECUREC_ENABLE_STRCAT 1 +#endif +#ifndef SECUREC_ENABLE_STRNCAT +#define SECUREC_ENABLE_STRNCAT 1 +#endif +#ifndef SECUREC_ENABLE_SPRINTF +#define SECUREC_ENABLE_SPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_VSPRINTF +#define SECUREC_ENABLE_VSPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_SNPRINTF +#define SECUREC_ENABLE_SNPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_VSNPRINTF +#define SECUREC_ENABLE_VSNPRINTF 1 +#endif +#ifndef SECUREC_ENABLE_SSCANF +#define SECUREC_ENABLE_SSCANF 1 +#endif +#ifndef SECUREC_ENABLE_VSSCANF +#define SECUREC_ENABLE_VSSCANF 1 +#endif +#ifndef SECUREC_ENABLE_SCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_SCANF 1 +#else +#define SECUREC_ENABLE_SCANF 0 +#endif +#endif +#ifndef SECUREC_ENABLE_VSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_VSCANF 1 +#else +#define SECUREC_ENABLE_VSCANF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_FSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_FSCANF 1 +#else +#define SECUREC_ENABLE_FSCANF 0 +#endif +#endif +#ifndef SECUREC_ENABLE_VFSCANF +#if SECUREC_ENABLE_SCANF_FILE +#define SECUREC_ENABLE_VFSCANF 1 +#else +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#endif + +#ifndef SECUREC_ENABLE_STRTOK +#define SECUREC_ENABLE_STRTOK 1 +#endif +#ifndef SECUREC_ENABLE_GETS +#define SECUREC_ENABLE_GETS 1 +#endif +#endif /* SECUREC_USE_STD_SECURE_LIB */ + +#if !SECUREC_ENABLE_SCANF_FILE +#if SECUREC_ENABLE_FSCANF +#undef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif +#if SECUREC_ENABLE_VFSCANF +#undef SECUREC_ENABLE_VFSCANF +#define SECUREC_ENABLE_VFSCANF 0 +#endif +#if SECUREC_ENABLE_SCANF +#undef SECUREC_ENABLE_SCANF +#define SECUREC_ENABLE_SCANF 0 +#endif +#if SECUREC_ENABLE_FSCANF +#undef SECUREC_ENABLE_FSCANF +#define SECUREC_ENABLE_FSCANF 0 +#endif + +#endif + +#if SECUREC_IN_KERNEL +#include +#include +#else +#ifndef SECUREC_HAVE_STDIO_H +#define SECUREC_HAVE_STDIO_H 1 +#endif +#ifndef SECUREC_HAVE_STRING_H +#define SECUREC_HAVE_STRING_H 1 +#endif +#ifndef SECUREC_HAVE_STDLIB_H +#define SECUREC_HAVE_STDLIB_H 1 +#endif +#if SECUREC_HAVE_STDIO_H +#include +#endif +#if SECUREC_HAVE_STRING_H +#include +#endif +#if SECUREC_HAVE_STDLIB_H +#include +#endif +#endif + +/* + * If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable. + * The macro is automatically closed on the windows platform and linux kernel + */ +#ifndef SECUREC_WITH_PERFORMANCE_ADDONS +#if SECUREC_IN_KERNEL +#define SECUREC_WITH_PERFORMANCE_ADDONS 0 +#else +#define SECUREC_WITH_PERFORMANCE_ADDONS 1 +#endif +#endif + +/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */ +#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT) +#ifndef SECUREC_COMPATIBLE_WIN_FORMAT +#define SECUREC_COMPATIBLE_WIN_FORMAT +#endif +#endif + +#if defined(SECUREC_COMPATIBLE_WIN_FORMAT) +/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */ +/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */ +#ifdef SECUREC_WITH_PERFORMANCE_ADDONS +#undef SECUREC_WITH_PERFORMANCE_ADDONS +#define SECUREC_WITH_PERFORMANCE_ADDONS 0 +#endif +#endif + +#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \ + defined(SECUREC_VXWORKS_VERSION_5_4) +#ifndef SECUREC_VXWORKS_PLATFORM +#define SECUREC_VXWORKS_PLATFORM +#endif +#endif + +/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */ +#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM) +#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT +#define SECUREC_COMPATIBLE_LINUX_FORMAT +#endif +#endif + +#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT +#ifndef SECUREC_HAVE_STDDEF_H +#define SECUREC_HAVE_STDDEF_H 1 +#endif +/* Some system may no stddef.h */ +#if SECUREC_HAVE_STDDEF_H +#if !SECUREC_IN_KERNEL +#include +#endif +#endif +#endif + +/* + * Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2. + * Default does not check the format is that the same data type in the actual code. + * In the product is different in the original data type definition of VxWorks and Linux. + */ +#ifndef SECUREC_SUPPORT_FORMAT_WARNING +#define SECUREC_SUPPORT_FORMAT_WARNING 0 +#endif + +#if SECUREC_SUPPORT_FORMAT_WARNING +#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y)))) +#else +#define SECUREC_ATTRIBUTE(x, y) +#endif + +/* + * Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if complier can not support __builtin_expect. + */ +#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT +#define SECUREC_SUPPORT_BUILTIN_EXPECT 1 +#endif + +#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))) +/* + * This is a built-in function that can be used without a declaration, if warning for declaration not found occurred, + * you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to complier options + */ +#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE +long __builtin_expect(long exp, long c); +#endif + +#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1) +#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define SECUREC_LIKELY(x) (x) +#define SECUREC_UNLIKELY(x) (x) +#endif + +/* Define the max length of the string */ +#ifndef SECUREC_STRING_MAX_LEN +#define SECUREC_STRING_MAX_LEN 0x7fffffffUL +#endif +#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t)) + +/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */ +#ifndef SECUREC_MEM_MAX_LEN +#define SECUREC_MEM_MAX_LEN 0x7fffffffUL +#endif +#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t)) + +#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL +#error "max string is 2G" +#endif + +#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__)) +#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8) +#error "unsupported system" +#endif +#endif + +#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64) +#define SECUREC_ON_64BITS +#endif + +#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__)) +#if __SIZEOF_POINTER__ == 8 +#define SECUREC_ON_64BITS +#endif +#endif + +#if defined(__SVR4) || defined(__svr4__) +#define SECUREC_ON_SOLARIS +#endif + +#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS)) +#define SECUREC_ON_UNIX +#endif + +/* + * Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknow system on default, + * and strtold. + * The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can + * not support these functions. Here provides a macro to open these functions: + * SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used + */ +#ifndef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 0 +#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT)) +#if defined(__USE_ISOC99) || \ + (defined(_AIX) && defined(_ISOC99_SOURCE)) || \ + (defined(__hpux) && defined(__ia64)) || \ + (defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ + defined(_STDC_C99) || defined(__EXTENSIONS__)) +#undef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 1 +#endif +#endif +#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_))) +#undef SECUREC_SUPPORT_STRTOLD +#define SECUREC_SUPPORT_STRTOLD 0 +#endif +#endif + +#if SECUREC_WITH_PERFORMANCE_ADDONS + +#ifndef SECUREC_TWO_MIN +#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +/* For strncpy_s performance optimization */ +#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \ + (((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \ + (memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count)))) + +#define SECUREC_STRCPY_SM(dest, destMax, src) \ + (((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \ + (strcpy_error((dest), (destMax), (src)))) + +/* For strcat_s performance optimization */ +#if defined(__GNUC__) +#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \ + int catRet_ = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *catTmpDst_ = (char *)(dest); \ + size_t catRestSize_ = (destMax); \ + while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \ + ++catTmpDst_; \ + --catRestSize_; \ + } \ + if (catRestSize_ == 0) { \ + catRet_ = EINVAL; \ + } else if ((strlen(src) + 1) <= catRestSize_) { \ + memcpy(catTmpDst_, (src), strlen(src) + 1); \ + catRet_ = EOK; \ + } else { \ + catRet_ = ERANGE; \ + } \ + if (catRet_ != EOK) { \ + catRet_ = strcat_s((dest), (destMax), (src)); \ + } \ + } else { \ + catRet_ = strcat_s((dest), (destMax), (src)); \ + } \ + catRet_; \ +}) +#else +#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src)) +#endif + +/* For strncat_s performance optimization */ +#if defined(__GNUC__) +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \ + int ncatRet_ = EOK; \ + if ((void *)(dest) != NULL && (void *)(src) != NULL && (size_t)(destMax) > 0 && \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \ + (((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \ + char *ncatTmpDest_ = (char *)(dest); \ + size_t ncatRestSize_ = (size_t)(destMax); \ + while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \ + ++ncatTmpDest_; \ + --ncatRestSize_; \ + } \ + if (ncatRestSize_ == 0) { \ + ncatRet_ = EINVAL; \ + } else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \ + if ((size_t)(count) < strlen(src)) { \ + memcpy(ncatTmpDest_, (src), (count)); \ + *(ncatTmpDest_ + (count)) = '\0'; \ + } else { \ + memcpy(ncatTmpDest_, (src), strlen(src) + 1); \ + } \ + } else { \ + ncatRet_ = ERANGE; \ + } \ + if (ncatRet_ != EOK) { \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ + } \ + } else { \ + ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \ + } \ + ncatRet_; \ +}) +#else +#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count)) +#endif + +/* This macro do not check buffer overlap by default */ +#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \ + (!(((size_t)(destMax) == 0) || \ + (((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((void *)(src) == NULL)) ? \ + (memcpy((dest), (src), (count)), EOK) : \ + (memcpy_s((dest), (destMax), (src), (count)))) + +#define SECUREC_MEMSET_SM(dest, destMax, c, count) \ + (!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \ + ((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \ + (memset((dest), (c), (count)), EOK) : \ + (memset_s((dest), (destMax), (c), (count)))) + +#endif +#endif + diff -uprN postgresql-hll-2.14_old/include/service/rpc_client.h postgresql-hll-2.14/include/service/rpc_client.h --- postgresql-hll-2.14_old/include/service/rpc_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/service/rpc_client.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rpc_client.h + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * IDENTIFICATION + * src/include/service/rpc_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef RPC_CLIENT_H +#define RPC_CLIENT_H + +#include "c.h" + +#include +#include "storage/remote_adapter.h" + +extern std::shared_ptr GetSSlCredential(TlsCertPath clientCert); + +extern int RemoteGetCU(const char* remote_address, uint32 spcnode, uint32 dbnode, uint32 relnode, int32 colid, + uint64 offset, int32 size, uint64 lsn, char* cu_data); + +extern int RemoteGetPage(const char* remote_address, uint32 spcnode, uint32 dbnode, uint32 relnode, int2 bucketnode, + int32 forknum, uint32 blocknum, uint32 blocksize, uint64 lsn, char* page_data); + +#endif /* RPC_CLIENT_H */ diff -uprN postgresql-hll-2.14_old/include/service/rpc_server.h postgresql-hll-2.14/include/service/rpc_server.h --- postgresql-hll-2.14_old/include/service/rpc_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/service/rpc_server.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rpc_server.h + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * IDENTIFICATION + * src/include/service/rpc_server.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef RPC_SERVER_H +#define RPC_SERVER_H + +typedef struct RPCServerContext RPCServerContext; + +extern RPCServerContext* BuildAndStartServer(const char* listen_address); + +extern void ShutdownAndReleaseServer(RPCServerContext* server_context); + +extern void ForceReleaseServer(RPCServerContext* server_context); + +#endif /* RPC_SERVER_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/header.h postgresql-hll-2.14/include/snowball/header.h --- postgresql-hll-2.14_old/include/snowball/header.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/header.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * header.h + * Replacement header file for Snowball stemmer modules + * + * The Snowball stemmer modules do #include "header.h", and think they + * are including snowball/libstemmer/header.h. We adjust the CPPFLAGS + * so that this file is found instead, and thereby we can modify the + * headers they see. The main point here is to ensure that pg_config.h + * is included before any system headers such as ; without that, + * we have portability issues on some platforms due to variation in + * largefile options across different modules in the backend. + * + * NOTE: this file should not be included into any non-snowball sources! + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/snowball/header.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNOWBALL_HEADR_H +#define SNOWBALL_HEADR_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +/* Some platforms define MAXINT and/or MININT, causing conflicts */ +#ifdef MAXINT +#undef MAXINT +#endif +#ifdef MININT +#undef MININT +#endif + +/* Now we can include the original Snowball header.h */ +#include "snowball/libstemmer/header.h" /* pgrminclude ignore */ + +/* + * Redefine standard memory allocation interface to pgsql's one. + * This allows us to control where the Snowball code allocates stuff. + */ +#ifdef malloc +#undef malloc +#endif +#define malloc(a) palloc(a) + +#ifdef calloc +#undef calloc +#endif +#define calloc(a, b) palloc0((a) * (b)) + +#ifdef realloc +#undef realloc +#endif +#define realloc(a, b) repalloc(a, b) + +#ifdef free +#undef free +#endif +#define free(a) pfree(a) + +#endif /* SNOWBALL_HEADR_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/api.h postgresql-hll-2.14/include/snowball/libstemmer/api.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/api.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/api.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,32 @@ +#ifndef API_H +#define API_H + +typedef unsigned char symbol; + +/* Or replace 'char' above with 'short' for 16 bit characters. + + More precisely, replace 'char' with whatever type guarantees the + character width you need. Note however that sizeof(symbol) should divide + HEAD, defined in header.h as 2*sizeof(int), without remainder, otherwise + there is an alignment problem. In the unlikely event of a problem here, + consult Martin Porter. + +*/ +struct SN_env { + symbol* p; + int c; + int l; + int lb; + int bra; + int ket; + symbol** S; + int* I; + unsigned char* B; +}; + +extern struct SN_env* SN_create_env(int S_size, int I_size, int B_size); +extern void SN_close_env(struct SN_env* z, int S_size); + +extern int SN_set_current(struct SN_env* z, int size, const symbol* s); + +#endif /* API_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/header.h postgresql-hll-2.14/include/snowball/libstemmer/header.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/header.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/header.h 2020-12-12 17:06:43.370349625 +0800 @@ -0,0 +1,57 @@ + +#include + +#include "api.h" + +#define MAXINT INT_MAX +#define MININT INT_MIN + +#define HEAD 2 * sizeof(int) + +#define SIZE(p) ((int*)(p))[-1] +#define SET_SIZE(p, n) ((int*)(p))[-1] = n +#define CAPACITY(p) ((int*)(p))[-2] + +struct among { + int s_size; /* number of chars in string */ + const symbol* s; /* search string */ + int substring_i; /* index to longest matching substring */ + int result; /* result of the lookup */ + int (*function)(struct SN_env*); +}; + +extern symbol* create_s(void); +extern void lose_s(symbol* p); + +extern int skip_utf8(const symbol* p, int c, int lb, int l, int n); + +extern int in_grouping_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int in_grouping_b_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_b_U(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); + +extern int in_grouping(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int in_grouping_b(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); +extern int out_grouping_b(struct SN_env* z, const unsigned char* s, int min, int max, int repeat); + +extern int eq_s(struct SN_env* z, int s_size, const symbol* s); +extern int eq_s_b(struct SN_env* z, int s_size, const symbol* s); +extern int eq_v(struct SN_env* z, const symbol* p); +extern int eq_v_b(struct SN_env* z, const symbol* p); + +extern int find_among(struct SN_env* z, const struct among* v, int v_size); +extern int find_among_b(struct SN_env* z, const struct among* v, int v_size); + +extern int replace_s(struct SN_env* z, int c_bra, int c_ket, int s_size, const symbol* s, int* adjustment); +extern int slice_from_s(struct SN_env* z, int s_size, const symbol* s); +extern int slice_from_v(struct SN_env* z, const symbol* p); +extern int slice_del(struct SN_env* z); + +extern int insert_s(struct SN_env* z, int bra, int ket, int s_size, const symbol* s); +extern int insert_v(struct SN_env* z, int bra, int ket, const symbol* p); + +extern symbol* slice_to(struct SN_env* z, symbol* p); +extern symbol* assign_to(struct SN_env* z, symbol* p); + +extern void debug(struct SN_env* z, int number, int line_count); diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_danish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_danish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_danish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_danish.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_DANISH_H +#define STEM_ISO_8859_1_DANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* danish_ISO_8859_1_create_env(void); +extern void danish_ISO_8859_1_close_env(struct SN_env* z); + +extern int danish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_DANISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_dutch.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_DUTCH_H +#define STEM_ISO_8859_1_DUTCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* dutch_ISO_8859_1_create_env(void); +extern void dutch_ISO_8859_1_close_env(struct SN_env* z); + +extern int dutch_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_DUTCH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_english.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_english.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_english.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_english.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_ENGLISH_H +#define STEM_ISO_8859_1_ENGLISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* english_ISO_8859_1_create_env(void); +extern void english_ISO_8859_1_close_env(struct SN_env* z); + +extern int english_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_ENGLISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_finnish.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_FINNISH_H +#define STEM_ISO_8859_1_FINNISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* finnish_ISO_8859_1_create_env(void); +extern void finnish_ISO_8859_1_close_env(struct SN_env* z); + +extern int finnish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_FINNISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_french.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_french.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_french.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_french.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_FRENCH_H +#define STEM_ISO_8859_1_FRENCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* french_ISO_8859_1_create_env(void); +extern void french_ISO_8859_1_close_env(struct SN_env* z); + +extern int french_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_FRENCH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_german.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_german.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_german.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_german.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_GERMAN_H +#define STEM_ISO_8859_1_GERMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* german_ISO_8859_1_create_env(void); +extern void german_ISO_8859_1_close_env(struct SN_env* z); + +extern int german_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_GERMAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_hungarian.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_HUNGARIAN_H +#define STEM_ISO_8859_1_HUNGARIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* hungarian_ISO_8859_1_create_env(void); +extern void hungarian_ISO_8859_1_close_env(struct SN_env* z); + +extern int hungarian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_HUNGARIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_italian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_italian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_italian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_italian.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_ITALIAN_H +#define STEM_ISO_8859_1_ITALIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* italian_ISO_8859_1_create_env(void); +extern void italian_ISO_8859_1_close_env(struct SN_env* z); + +extern int italian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_ITALIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_norwegian.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_NORWEGIAN_H +#define STEM_ISO_8859_1_NORWEGIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* norwegian_ISO_8859_1_create_env(void); +extern void norwegian_ISO_8859_1_close_env(struct SN_env* z); + +extern int norwegian_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_NORWEGIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_porter.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_porter.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_porter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_porter.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_PORTER_H +#define STEM_ISO_8859_1_PORTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* porter_ISO_8859_1_create_env(void); +extern void porter_ISO_8859_1_close_env(struct SN_env* z); + +extern int porter_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_PORTER_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_portuguese.h 2020-12-12 17:06:43.371349638 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_PORTUGUESE_H +#define STEM_ISO_8859_1_PORTUGUESE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* portuguese_ISO_8859_1_create_env(void); +extern void portuguese_ISO_8859_1_close_env(struct SN_env* z); + +extern int portuguese_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_PORTUGUESE_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_spanish.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_SPANISH_H +#define STEM_ISO_8859_1_SPANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* spanish_ISO_8859_1_create_env(void); +extern void spanish_ISO_8859_1_close_env(struct SN_env* z); + +extern int spanish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_SPANISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_1_swedish.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_1_SWEDISH_H +#define STEM_ISO_8859_1_SWEDISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* swedish_ISO_8859_1_create_env(void); +extern void swedish_ISO_8859_1_close_env(struct SN_env* z); + +extern int swedish_ISO_8859_1_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_1_SWEDISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_ISO_8859_2_romanian.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_ISO_8859_2_ROMANIAN_H +#define STEM_ISO_8859_2_ROMANIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* romanian_ISO_8859_2_create_env(void); +extern void romanian_ISO_8859_2_close_env(struct SN_env* z); + +extern int romanian_ISO_8859_2_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_ISO_8859_2_ROMANIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_KOI8_R_russian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_KOI8_R_russian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_KOI8_R_russian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_KOI8_R_russian.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_KOI8_R_RUSSIAN_H +#define STEM_KOI8_R_RUSSIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* russian_KOI8_R_create_env(void); +extern void russian_KOI8_R_close_env(struct SN_env* z); + +extern int russian_KOI8_R_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_KOI8_R_RUSSIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_danish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_danish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_danish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_danish.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_DANISH_H +#define STEM_UTF_8_DANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* danish_UTF_8_create_env(void); +extern void danish_UTF_8_close_env(struct SN_env* z); + +extern int danish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_DANISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_dutch.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_dutch.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_dutch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_dutch.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_DUTCH_H +#define STEM_UTF_8_DUTCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* dutch_UTF_8_create_env(void); +extern void dutch_UTF_8_close_env(struct SN_env* z); + +extern int dutch_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_DUTCH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_english.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_english.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_english.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_english.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ENGLISH_H +#define STEM_UTF_8_ENGLISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* english_UTF_8_create_env(void); +extern void english_UTF_8_close_env(struct SN_env* z); + +extern int english_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ENGLISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_finnish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_finnish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_finnish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_finnish.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_FINNISH_H +#define STEM_UTF_8_FINNISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* finnish_UTF_8_create_env(void); +extern void finnish_UTF_8_close_env(struct SN_env* z); + +extern int finnish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_FINNISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_french.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_french.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_french.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_french.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_FRENCH_H +#define STEM_UTF_8_FRENCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* french_UTF_8_create_env(void); +extern void french_UTF_8_close_env(struct SN_env* z); + +extern int french_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_FRENCH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_german.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_german.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_german.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_german.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_GERMAN_H +#define STEM_UTF_8_GERMAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* german_UTF_8_create_env(void); +extern void german_UTF_8_close_env(struct SN_env* z); + +extern int german_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_GERMAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_hungarian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_hungarian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_hungarian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_hungarian.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_HUNGARIAN_H +#define STEM_UTF_8_HUNGARIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* hungarian_UTF_8_create_env(void); +extern void hungarian_UTF_8_close_env(struct SN_env* z); + +extern int hungarian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_HUNGARIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_italian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_italian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_italian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_italian.h 2020-12-12 17:06:43.372349651 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ITALIAN_H +#define STEM_UTF_8_ITALIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* italian_UTF_8_create_env(void); +extern void italian_UTF_8_close_env(struct SN_env* z); + +extern int italian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ITALIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_norwegian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_norwegian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_norwegian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_norwegian.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_NORWEGIAN_H +#define STEM_UTF_8_NORWEGIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* norwegian_UTF_8_create_env(void); +extern void norwegian_UTF_8_close_env(struct SN_env* z); + +extern int norwegian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_NORWEGIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_porter.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_porter.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_porter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_porter.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_PORTER_H +#define STEM_UTF_8_PORTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* porter_UTF_8_create_env(void); +extern void porter_UTF_8_close_env(struct SN_env* z); + +extern int porter_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_PORTER_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_portuguese.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_portuguese.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_portuguese.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_portuguese.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_PORTUGUESE_H +#define STEM_UTF_8_PORTUGUESE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* portuguese_UTF_8_create_env(void); +extern void portuguese_UTF_8_close_env(struct SN_env* z); + +extern int portuguese_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_PORTUGUESE_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_romanian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_romanian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_romanian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_romanian.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_ROMANIAN_H +#define STEM_UTF_8_ROMANIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* romanian_UTF_8_create_env(void); +extern void romanian_UTF_8_close_env(struct SN_env* z); + +extern int romanian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_ROMANIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_russian.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_russian.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_russian.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_russian.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_RUSSIAN_H +#define STEM_UTF_8_RUSSIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* russian_UTF_8_create_env(void); +extern void russian_UTF_8_close_env(struct SN_env* z); + +extern int russian_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_RUSSIAN_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_spanish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_spanish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_spanish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_spanish.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_SPANISH_H +#define STEM_UTF_8_SPANISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* spanish_UTF_8_create_env(void); +extern void spanish_UTF_8_close_env(struct SN_env* z); + +extern int spanish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_SPANISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_swedish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_swedish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_swedish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_swedish.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_SWEDISH_H +#define STEM_UTF_8_SWEDISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* swedish_UTF_8_create_env(void); +extern void swedish_UTF_8_close_env(struct SN_env* z); + +extern int swedish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_SWEDISH_H */ diff -uprN postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_turkish.h postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_turkish.h --- postgresql-hll-2.14_old/include/snowball/libstemmer/stem_UTF_8_turkish.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/snowball/libstemmer/stem_UTF_8_turkish.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,19 @@ + +/* This file was generated automatically by the Snowball to ANSI C compiler */ +#ifndef STEM_UTF_8_TURKISH_H +#define STEM_UTF_8_TURKISH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct SN_env* turkish_UTF_8_create_env(void); +extern void turkish_UTF_8_close_env(struct SN_env* z); + +extern int turkish_UTF_8_stem(struct SN_env* z); + +#ifdef __cplusplus +} +#endif + +#endif /* STEM_UTF_8_TURKISH_H */ diff -uprN postgresql-hll-2.14_old/include/ssl/gs_openssl_client.h postgresql-hll-2.14/include/ssl/gs_openssl_client.h --- postgresql-hll-2.14_old/include/ssl/gs_openssl_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/ssl/gs_openssl_client.h 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_openssl_client.h + * initialize the ssl system of client which is based on the openssl library + * + * IDENTIFICATION + * src/include/ssl/gs_openssl_client.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef GS_openssl_CLIENT +#define GS_openssl_CLIENT + +#include "cipher.h" + +#include "openssl/ossl_typ.h" +#include "openssl/err.h" +#include "openssl/err.h" +#include "openssl/ssl.h" +#include "openssl/bio.h" +#include "openssl/conf.h" +#include "openssl/crypto.h" +#include "openssl/evp.h" +#include "openssl/rand.h" + +#define OPENSSL_CLI_EXCEPTTION (-4) +#define OPENSSL_CLI_BAD_SOCKET (-3) +#define OPENSSL_CLI_EAGAIN (-2) + +typedef struct gs_openssl_client* gs_openssl_cli; + +extern void gs_openssl_cli_init_system(void); + +/* create a gs_openssl_client object */ +extern gs_openssl_cli gs_openssl_cli_create(void); +/* destroy a gs_openssl_client object */ +extern void gs_openssl_cli_destroy(gs_openssl_cli cli); +/* set the certificate file names before loading them */ +extern void gs_openssl_cli_setfiles( + gs_openssl_cli cli, const char* ssl_dir, const char* rootcert, const char* client_key, const char* clientcert); + +/* the main function of initialize the ssl system of client using openssl */ +extern int gs_openssl_cli_initialize_SSL(gs_openssl_cli cli, int sock_id); + +/* read && write interface */ +extern int gs_openssl_cli_read(gs_openssl_cli cli, char* obuf, int maxlen); +extern int gs_openssl_cli_write(gs_openssl_cli cli, const char* buf, int len); + +#ifdef ENABLE_UT +extern int ossl_init_client_ssl_passwd(SSL_CTX* pstContext, const char* cert_file_dir, GS_UCHAR* cipher_passwd); +extern const char* ossl_error_message(void); +#endif /* ENABLE_UT */ + +#endif /* GS_openssl_CLIENT */ diff -uprN postgresql-hll-2.14_old/include/ssl/openssl_etcd.cnf postgresql-hll-2.14/include/ssl/openssl_etcd.cnf --- postgresql-hll-2.14_old/include/ssl/openssl_etcd.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/ssl/openssl_etcd.cnf 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,72 @@ +# etcd OpenSSL configuration file. +SAN = "IP:127.0.0.1" +dir = . + +[ ca ] +default_ca = etcd_ca + +[ etcd_ca ] +certs = $dir/certs +certificate = $dir/certs/etcd-ca.crt +crl = $dir/crl.pem +crl_dir = $dir/crl +crlnumber = $dir/crlnumber +database = $dir/index.txt +email_in_dn = no +new_certs_dir = $dir/newcerts +private_key = $dir/private/etcd-ca.key +serial = $dir/serial +RANDFILE = $dir/private/.rand +name_opt = ca_default +cert_opt = ca_default +default_days = 7300 +default_crl_days = 30 +default_md = sha512 +preserve = no +policy = policy_etcd + +[ policy_etcd ] +organizationName = optional +commonName = supplied + +[ req ] +default_bits = 4096 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca +string_mask = utf8only +req_extensions = etcd_client + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = US +countryName_min = 2 +countryName_max = 2 +commonName = Common Name (FQDN) +0.organizationName = Organization Name (eg, company) +0.organizationName_default = etcd-ca + +[ req_attributes ] + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = keyCertSign,cRLSign +subjectKeyIdentifier = hash + +[ etcd_client ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth +keyUsage = digitalSignature, keyEncipherment + +[ etcd_peer ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth, serverAuth +keyUsage = digitalSignature, keyEncipherment +subjectAltName = ${ENV::SAN} + +[ etcd_server ] +basicConstraints = CA:FALSE +extendedKeyUsage = clientAuth, serverAuth +keyUsage = digitalSignature, keyEncipherment +subjectAltName = ${ENV::SAN} diff -uprN postgresql-hll-2.14_old/include/ssl/openssl_grpc.cnf postgresql-hll-2.14/include/ssl/openssl_grpc.cnf --- postgresql-hll-2.14_old/include/ssl/openssl_grpc.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/ssl/openssl_grpc.cnf 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,147 @@ +# +# grpc OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +# x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +default_days = 7300 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha512 # which md to use. +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString. +# utf8only: only UTF8Strings. +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings +# so use this option with caution! +string_mask = nombstr + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (eg, YOUR name) +commonName_default = grpc +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ alt_names ] +DNS.1 = localhost + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = cRLSign, keyCertSign +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer +subjectAltName = @alt_names + +[ server ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer +subjectAltName = @alt_names + +[ client ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer +subjectAltName = @alt_names diff -uprN postgresql-hll-2.14_old/include/ssl/openssl_gsql.cnf postgresql-hll-2.14/include/ssl/openssl_gsql.cnf --- postgresql-hll-2.14_old/include/ssl/openssl_gsql.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/ssl/openssl_gsql.cnf 2020-12-12 17:06:43.373349664 +0800 @@ -0,0 +1,139 @@ +# +# gsql OpenSSL configuration file. +# This is mostly being used for generation of certificate requests. +# + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +# x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +default_days = 7300 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha256 # use SHA-256 by default +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (e.g. server FQDN or YOUR name) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ v3_ca ] +basicConstraints = CA:true +keyUsage = cRLSign, keyCertSign +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer + +[ server ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer + +[ client ] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer diff -uprN postgresql-hll-2.14_old/include/ssl/openssl_om.cnf postgresql-hll-2.14/include/ssl/openssl_om.cnf --- postgresql-hll-2.14_old/include/ssl/openssl_om.cnf 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/ssl/openssl_om.cnf 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,352 @@ +# +# OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +# This definition stops the following lines choking if HOME isn't +# defined. +HOME = . +RANDFILE = $ENV::HOME/.rnd + +# Extra OBJECT IDENTIFIER info: +#oid_file = $ENV::HOME/.oid +oid_section = new_oids + +# To use this configuration file with the "-extfile" option of the +# "openssl x509" utility, name here the section containing the +# X.509v3 extensions to use: +# extensions = +# (Alternatively, use a configuration file that has only +# X.509v3 extensions in its main [= default] section.) + +[ new_oids ] + +# We can add new OIDs in here for use by 'ca', 'req' and 'ts'. +# Add a simple OID like this: +# testoid1=1.2.3.4 +# Or use config file substitution like this: +# testoid2=${testoid1}.5.6 + +# Policies used by the TSA examples. +tsa_policy1 = 1.2.3.4.1 +tsa_policy2 = 1.2.3.4.5.6 +tsa_policy3 = 1.2.3.4.5.7 + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several ctificates with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key +RANDFILE = $dir/private/.rand # private random number file + +x509_extensions = usr_cert # The extentions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +# Extension copying option: use with caution. +# copy_extensions = copy + +# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs +# so this is commented out by default to leave a V1 CRL. +# crlnumber must also be commented out to leave a V1 CRL. +# crl_extensions = crl_ext + +default_days = 365 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = sha256 # use SHA-256 by default +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_md = sha256 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extentions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +# req_extensions = v3_req # The extensions to add to a certificate request + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = XX +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +#stateOrProvinceName_default = Default Province + +localityName = Locality Name (eg, city) +localityName_default = Default City + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Default Company Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (eg, your name or your server\'s hostname) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ usr_cert ] + +# These extensions are added when 'ca' signs a request. + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This is required for TSA certificates. +# extendedKeyUsage = critical,timeStamping + +[ v3_req ] + +# Extensions to add to a certificate request + +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +[ v3_ca ] + + +# Extensions for a typical CA + + +# PKIX recommendation. + +subjectKeyIdentifier=hash + +authorityKeyIdentifier=keyid:always,issuer + +# This is what PKIX recommends but some broken software chokes on critical +# extensions. +#basicConstraints = critical,CA:true +# So we do this instead. +basicConstraints = CA:TRUE + +# Key usage: this is typical for a CA certificate. However since it will +# prevent it being used as an test self-signed certificate it is best +# left out by default. +# keyUsage = cRLSign, keyCertSign + +# Some might want this also +# nsCertType = sslCA, emailCA + +# Include email address in subject alt name: another PKIX recommendation +# subjectAltName=email:copy +# Copy issuer details +# issuerAltName=issuer:copy + +# DER hex encoding of an extension: beware experts only! +# obj=DER:02:03 +# Where 'obj' is a standard or added object +# You can even override a supported extension: +# basicConstraints= critical, DER:30:03:01:01:FF + +[ crl_ext ] + +# CRL extensions. +# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. + +# issuerAltName=issuer:copy +authorityKeyIdentifier=keyid:always + +[ proxy_cert_ext ] +# These extensions should be added when creating a proxy certificate + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This really needs to be in place for it to be a proxy certificate. +proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo + +#################################################################### +[ tsa ] + +default_tsa = tsa_config1 # the default TSA section + +[ tsa_config1 ] + +# These are used by the TSA reply generation only. +dir = ./demoCA # TSA root directory +serial = $dir/tsaserial # The current serial number (mandatory) +crypto_device = builtin # OpenSSL engine to use for signing +signer_cert = $dir/tsacert.pem # The TSA signing certificate + # (optional) +certs = $dir/cacert.pem # Certificate chain to include in reply + # (optional) +signer_key = $dir/private/tsakey.pem # The TSA private key (optional) + +default_policy = tsa_policy1 # Policy if request did not specify it + # (optional) +other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) +digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory) +accuracy = secs:1, millisecs:500, microsecs:100 # (optional) +clock_precision_digits = 0 # number of digits after dot. (optional) +ordering = yes # Is ordering defined for timestamps? + # (optional, default: no) +tsa_name = yes # Must the TSA name be included in the reply? + # (optional, default: no) +ess_cert_id_chain = no # Must the ESS cert id chain be included? + # (optional, default: no) diff -uprN postgresql-hll-2.14_old/include/stamp-h postgresql-hll-2.14/include/stamp-h --- postgresql-hll-2.14_old/include/stamp-h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/stamp-h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1 @@ + diff -uprN postgresql-hll-2.14_old/include/storage/backendid.h postgresql-hll-2.14/include/storage/backendid.h --- postgresql-hll-2.14_old/include/storage/backendid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/backendid.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,25 @@ +/* ------------------------------------------------------------------------- + * + * backendid.h + * POSTGRES backend id communication definitions + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/backendid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BACKENDID_H +#define BACKENDID_H + +/* ---------------- + * -cim 8/17/90 + * ---------------- + */ +typedef int BackendId; /* unique currently active backend identifier */ + +#define InvalidBackendId (-1) + +#endif /* BACKENDID_H */ diff -uprN postgresql-hll-2.14_old/include/storage/barrier.h postgresql-hll-2.14/include/storage/barrier.h --- postgresql-hll-2.14_old/include/storage/barrier.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/barrier.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,203 @@ +/* ------------------------------------------------------------------------- + * + * barrier.h + * Memory barrier operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/barrier.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BARRIER_H +#define BARRIER_H + +#include "storage/s_lock.h" + +/* + * A compiler barrier need not (and preferably should not) emit any actual + * machine code, but must act as an optimization fence: the compiler must not + * reorder loads or stores to main memory around the barrier. However, the + * CPU may still reorder loads or stores at runtime, if the architecture's + * memory model permits this. + * + * A memory barrier must act as a compiler barrier, and in addition must + * guarantee that all loads and stores issued prior to the barrier are + * completed before any loads or stores issued after the barrier. Unless + * loads and stores are totally ordered (which is not the case on most + * architectures) this requires issuing some sort of memory fencing + * instruction. + * + * A read barrier must act as a compiler barrier, and in addition must + * guarantee that any loads issued prior to the barrier are completed before + * any loads issued after the barrier. Similarly, a write barrier acts + * as a compiler barrier, and also orders stores. Read and write barriers + * are thus weaker than a full memory barrier, but stronger than a compiler + * barrier. In practice, on machines with strong memory ordering, read and + * write barriers may require nothing more than a compiler barrier. + * + * For an introduction to using memory barriers within the PostgreSQL backend, + * see src/backend/storage/lmgr/README.barrier + */ + +#if defined(DISABLE_BARRIERS) + +/* + * Fall through to the spinlock-based implementation. + */ +#elif defined(__INTEL_COMPILER) + +/* + * icc defines __GNUC__, but doesn't support gcc's inline asm syntax + */ +#define pg_memory_barrier() _mm_mfence() +#define pg_compiler_barrier() __memory_barrier() +#elif defined(__GNUC__) + +/* This works on any architecture, since it's only talking to GCC itself. */ +#define pg_compiler_barrier() __asm__ __volatile__("" : : : "memory") + +#if defined(__i386__) + +/* + * i386 does not allow loads to be reordered with other loads, or stores to be + * reordered with other stores, but a load can be performed before a subsequent + * store. + * + * "lock; addl" has worked for longer than "mfence". + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%esp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__x86_64__) /* 64 bit x86 */ + +/* + * x86_64 has similar ordering characteristics to i386. + * + * Technically, some x86-ish chips support uncached memory access and/or + * special instructions that are weakly ordered. In those cases we'd need + * the read and write barriers to be lfence and sfence. But since we don't + * do those things, a compiler barrier should be enough. + */ +#define pg_memory_barrier() __asm__ __volatile__("lock; addl $0,0(%%rsp)" : : : "memory") +#define pg_read_barrier() pg_compiler_barrier() +#define pg_write_barrier() pg_compiler_barrier() +#elif defined(__aarch64__) +/* + * aarch64 architecure memory barrier. In order to minimize the impact on + * performance, here use dmb memory barrier. + */ +#define pg_memory_barrier_dsb(opt) __asm__ __volatile__("DMB " #opt::: "memory") + +#ifndef ENABLE_THREAD_CHECK + +#define pg_memory_barrier() pg_memory_barrier_dsb(ish) +#define pg_read_barrier() pg_memory_barrier_dsb(ishld) +#define pg_write_barrier() pg_memory_barrier_dsb(ishst) + +#else + +#include "tsan_annotation.h" + +#define pg_memory_barrier() do { \ + TsAnnotateReadBarrier(); \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ish); \ +} while (0) + +#define pg_read_barrier() do { \ + TsAnnotateReadBarrier(); \ + pg_memory_barrier_dsb(ishld); \ +} while (0) + +#define pg_write_barrier() do { \ + TsAnnotateWriteBarrier(); \ + pg_memory_barrier_dsb(ishst); \ +} while (0) + +#endif +#elif defined(__ia64__) || defined(__ia64) + +/* + * Itanium is weakly ordered, so read and write barriers require a full + * fence. + */ +#define pg_memory_barrier() __asm__ __volatile__("mf" : : : "memory") +#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) + +/* + * lwsync orders loads with respect to each other, and similarly with stores. + * But a load can be performed before a subsequent store, so sync must be used + * for a full memory barrier. + */ +#define pg_memory_barrier() __asm__ __volatile__("sync" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("lwsync" : : : "memory") +#elif defined(__alpha) || defined(__alpha__) /* Alpha */ + +/* + * Unlike all other known architectures, Alpha allows dependent reads to be + * reordered, but we don't currently find it necessary to provide a conditional + * read barrier to cover that case. We might need to add that later. + */ +#define pg_memory_barrier() __asm__ __volatile__("mb" : : : "memory") +#define pg_read_barrier() __asm__ __volatile__("rmb" : : : "memory") +#define pg_write_barrier() __asm__ __volatile__("wmb" : : : "memory") +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) + +/* + * If we're on GCC 4.1.0 or higher, we should be able to get a memory + * barrier out of this compiler built-in. But we prefer to rely on our + * own definitions where possible, and use this only as a fallback. + */ +#define pg_memory_barrier() __sync_synchronize() +#endif +#elif defined(__ia64__) || defined(__ia64) + +#define pg_compiler_barrier() _Asm_sched_fence() +#define pg_memory_barrier() _Asm_mf() +#elif defined(WIN32_ONLY_COMPILER) + +/* Should work on both MSVC and Borland. */ +#include +#pragma intrinsic(_ReadWriteBarrier) +#define pg_compiler_barrier() _ReadWriteBarrier() +#define pg_memory_barrier() MemoryBarrier() +#endif + +/* + * If we have no memory barrier implementation for this architecture, we + * fall back to acquiring and releasing a spinlock. This might, in turn, + * fall back to the semaphore-based spinlock implementation, which will be + * amazingly slow. + * + * It's not self-evident that every possible legal implementation of a + * spinlock acquire-and-release would be equivalent to a full memory barrier. + * For example, I'm not sure that Itanium's acq and rel add up to a full + * fence. But all of our actual implementations seem OK in this regard. + */ +#if !defined(pg_memory_barrier) +#define pg_memory_barrier(x) \ + do { \ + S_LOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + S_UNLOCK(&t_thrd.storage_cxt.dummy_spinlock); \ + } while (0) +#endif + +/* + * If read or write barriers are undefined, we upgrade them to full memory + * barriers. + * + * If a compiler barrier is unavailable, you probably don't want a full + * memory barrier instead, so if you have a use case for a compiler barrier, + * you'd better use #ifdef. + */ +#if !defined(pg_read_barrier) +#define pg_read_barrier() pg_memory_barrier() +#endif +#if !defined(pg_write_barrier) +#define pg_write_barrier() pg_memory_barrier() +#endif + +#endif /* BARRIER_H */ diff -uprN postgresql-hll-2.14_old/include/storage/block.h postgresql-hll-2.14/include/storage/block.h --- postgresql-hll-2.14_old/include/storage/block.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/block.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,126 @@ +/* ------------------------------------------------------------------------- + * + * block.h + * POSTGRES disk block definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/block.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BLOCK_H +#define BLOCK_H + +/* + * BlockNumber: + * + * each data file (heap or index) is divided into postgres disk blocks + * (which may be thought of as the unit of i/o -- a postgres buffer + * contains exactly one disk block). the blocks are numbered + * sequentially, 0 to 0xFFFFFFFE. + * + * InvalidBlockNumber is the same thing as P_NEW in buf.h. + * + * the access methods, the buffer manager and the storage manager are + * more or less the only pieces of code that should be accessing disk + * blocks directly. + */ +typedef uint32 BlockNumber; + +#define InvalidBlockNumber ((BlockNumber)0xFFFFFFFF) + +#define MaxBlockNumber ((BlockNumber)0xFFFFFFFE) + +typedef double RelPageType; + +/* + * BlockId: + * + * this is a storage type for BlockNumber. in other words, this type + * is used for on-disk structures (e.g., in HeapTupleData) whereas + * BlockNumber is the type on which calculations are performed (e.g., + * in access method code). + * + * there doesn't appear to be any reason to have separate types except + * for the fact that BlockIds can be SHORTALIGN'd (and therefore any + * structures that contains them, such as ItemPointerData, can also be + * SHORTALIGN'd). this is an important consideration for reducing the + * space requirements of the line pointer (ItemIdData) array on each + * page and the header of each heap or index tuple, so it doesn't seem + * wise to change this without good reason. + */ +typedef struct BlockIdData { + uint16 bi_hi; + uint16 bi_lo; +} BlockIdData; + +typedef BlockIdData* BlockId; /* block identifier */ + +/* Data structure for Algorithm S from Knuth 3.4.2 */ +typedef struct { + BlockNumber N; /* number of blocks, known in advance */ + int n; /* desired sample size */ + BlockNumber t; /* current block number */ + int m; /* blocks selected so far */ +} BlockSamplerData; + +typedef BlockSamplerData* BlockSampler; + +void BlockSampler_Init(BlockSampler bs, BlockNumber nblocks, int samplesize); +bool BlockSampler_HasMore(BlockSampler bs); +BlockNumber BlockSampler_Next(BlockSampler bs); + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * BlockNumberIsValid + * True iff blockNumber is valid. + */ +#define BlockNumberIsValid(blockNumber) ((bool)((BlockNumber)(blockNumber) != InvalidBlockNumber)) + +/* + * BlockIdIsValid + * True iff the block identifier is valid. + */ +#define BlockIdIsValid(blockId) ((bool)PointerIsValid(blockId)) + +/* + * BlockIdSet + * Sets a block identifier to the specified value. + */ +#define BlockIdSet(blockId, blockNumber) \ + (AssertMacro(PointerIsValid(blockId)), \ + (blockId)->bi_hi = (blockNumber) >> 16, \ + (blockId)->bi_lo = (blockNumber)&0xffff) + +/* + * BlockIdCopy + * Copy a block identifier. + */ +#define BlockIdCopy(toBlockId, fromBlockId) \ + (AssertMacro(PointerIsValid(toBlockId)), \ + AssertMacro(PointerIsValid(fromBlockId)), \ + (toBlockId)->bi_hi = (fromBlockId)->bi_hi, \ + (toBlockId)->bi_lo = (fromBlockId)->bi_lo) + +/* + * BlockIdEquals + * Check for block number equality. + */ +#define BlockIdEquals(blockId1, blockId2) \ + ((blockId1)->bi_hi == (blockId2)->bi_hi && (blockId1)->bi_lo == (blockId2)->bi_lo) + +/* + * BlockIdGetBlockNumber + * Retrieve the block number from a block identifier. + */ +#define BlockIdGetBlockNumber(blockId) \ + (AssertMacro(BlockIdIsValid(blockId)), (BlockNumber)(((blockId)->bi_hi << 16) | ((uint16)(blockId)->bi_lo))) + +#endif /* BLOCK_H */ diff -uprN postgresql-hll-2.14_old/include/storage/buffile.h postgresql-hll-2.14/include/storage/buffile.h --- postgresql-hll-2.14_old/include/storage/buffile.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/buffile.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,45 @@ +/* ------------------------------------------------------------------------- + * + * buffile.h + * Management of large buffered files, primarily temporary files. + * + * The BufFile routines provide a partial replacement for stdio atop + * virtual file descriptors managed by fd.c. Currently they only support + * buffered access to a virtual file, without any of stdio's formatting + * features. That's enough for immediate needs, but the set of facilities + * could be expanded if necessary. + * + * BufFile also supports working with temporary files that exceed the OS + * file size limit and/or the largest offset representable in an int. + * It might be better to split that out as a separately accessible module, + * but currently we have no need for oversize temp files without buffered + * access. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buffile.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef BUFFILE_H +#define BUFFILE_H + +/* BufFile is an opaque type whose details are not known outside buffile.c. */ + +typedef struct BufFile BufFile; + +/* + * prototypes for functions in buffile.c + */ + +extern BufFile* BufFileCreateTemp(bool interXact); +extern void BufFileClose(BufFile* file); +extern size_t BufFileRead(BufFile* file, void* ptr, size_t size); +extern size_t BufFileWrite(BufFile* file, void* ptr, size_t size); +extern int BufFileSeek(BufFile* file, int fileno, off_t offset, int whence); +extern void BufFileTell(BufFile* file, int* fileno, off_t* offset); +extern int BufFileSeekBlock(BufFile* file, long blknum); + +#endif /* BUFFILE_H */ diff -uprN postgresql-hll-2.14_old/include/storage/buf.h postgresql-hll-2.14/include/storage/buf.h --- postgresql-hll-2.14_old/include/storage/buf.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/buf.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * buf.h + * Basic buffer manager data types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buf.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUF_H +#define BUF_H + +/* + * Buffer identifiers. + * + * Zero is invalid, positive is the index of a shared buffer (1..NBuffers), + * negative is the index of a local buffer (-1 .. -NLocBuffer). + */ +typedef int Buffer; + +#define InvalidBuffer 0 + +/* + * BufferIsInvalid + * True iff the buffer is invalid. + */ +#define BufferIsInvalid(buffer) ((buffer) == InvalidBuffer) + +/* + * BufferIsLocal + * True iff the buffer is local (not visible to other backends). + */ +#define BufferIsLocal(buffer) ((buffer) < 0) + +/* + * Buffer access strategy objects. + */ +typedef struct BufferAccessStrategyData* BufferAccessStrategy; + +#endif /* BUF_H */ diff -uprN postgresql-hll-2.14_old/include/storage/buf_internals.h postgresql-hll-2.14/include/storage/buf_internals.h --- postgresql-hll-2.14_old/include/storage/buf_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/buf_internals.h 2020-12-12 17:06:43.374349677 +0800 @@ -0,0 +1,325 @@ +/* ------------------------------------------------------------------------- + * + * buf_internals.h + * Internal definitions for buffer manager and the buffer replacement + * strategy. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/buf_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFMGR_INTERNALS_H +#define BUFMGR_INTERNALS_H + +#include "storage/buf.h" +#include "storage/bufmgr.h" +#include "storage/latch.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "storage/smgr.h" +#include "storage/spin.h" +#include "utils/relcache.h" +#include "utils/atomic.h" +#include "access/xlogdefs.h" + +/* + * Buffer state is a single 32-bit variable where following data is combined. + * + * - 18 bits refcount + * - 4 bits usage count + * - 10 bits of flags + * + * Combining these values allows to perform some operations without locking + * the buffer header, by modifying them together with a CAS loop. + * + * The definition of buffer state components is below. + */ +#define BUF_REFCOUNT_ONE 1 +#define BUF_REFCOUNT_MASK ((1U << 18) - 1) +#define BUF_USAGECOUNT_MASK 0x003C0000U +#define BUF_USAGECOUNT_ONE (1U << 18) +#define BUF_USAGECOUNT_SHIFT 18 +#define BUF_FLAG_MASK 0xFFC00000U + +/* Get refcount and usagecount from buffer state */ +#define BUF_STATE_GET_REFCOUNT(state) ((state)&BUF_REFCOUNT_MASK) +#define BUF_STATE_GET_USAGECOUNT(state) (((state)&BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) + +/* + * Flags for buffer descriptors + * + * Note: TAG_VALID essentially means that there is a buffer hashtable + * entry associated with the buffer's tag. + */ +#define BM_LOCKED (1U << 22) /* buffer header is locked */ +#define BM_DIRTY (1U << 23) /* data needs writing */ +#define BM_VALID (1U << 24) /* data is valid */ +#define BM_TAG_VALID (1U << 25) /* tag is assigned */ +#define BM_IO_IN_PROGRESS (1U << 26) /* read or write in progress */ +#define BM_IO_ERROR (1U << 27) /* previous I/O failed */ +#define BM_JUST_DIRTIED (1U << 28) /* dirtied since write started */ +#define BM_PIN_COUNT_WAITER (1U << 29) /* have waiter for sole pin */ +#define BM_CHECKPOINT_NEEDED (1U << 30) /* must write for checkpoint */ +#define BM_PERMANENT \ + (1U << 31) /* permanent relation (not \ + * unlogged, or init fork) ) */ +/* + * The maximum allowed value of usage_count represents a tradeoff between + * accuracy and speed of the clock-sweep buffer management algorithm. A + * large value (comparable to NBuffers) would approximate LRU semantics. + * But it can take as many as BM_MAX_USAGE_COUNT+1 complete cycles of + * clock sweeps to find a free buffer, so in practice we don't want the + * value to be very large. + */ +#define BM_MAX_USAGE_COUNT 5 + +/* + * Buffer tag identifies which disk block the buffer contains. + * + * Note: the BufferTag data must be sufficient to determine where to write the + * block, without reference to pg_class or pg_tablespace entries. It's + * possible that the backend flushing the buffer doesn't even believe the + * relation is visible yet (its xact may have started before the xact that + * created the rel). The storage manager must be able to cope anyway. + * + * Note: if there's any pad bytes in the struct, INIT_BUFFERTAG will have + * to be fixed to zero them, since this struct is used as a hash key. + */ +typedef struct buftag { + RelFileNode rnode; /* physical relation identifier */ + ForkNumber forkNum; + BlockNumber blockNum; /* blknum relative to begin of reln */ +} BufferTag; + +typedef struct buftagnohbkt { + RelFileNodeOld rnode; /* physical relation identifier */ + ForkNumber forkNum; + BlockNumber blockNum; /* blknum relative to begin of reln */ +} BufferTagFirstVer; + + +#define CLEAR_BUFFERTAG(a) \ + ((a).rnode.spcNode = InvalidOid, \ + (a).rnode.dbNode = InvalidOid, \ + (a).rnode.relNode = InvalidOid, \ + (a).rnode.bucketNode = -1,\ + (a).forkNum = InvalidForkNumber, \ + (a).blockNum = InvalidBlockNumber) + +#define INIT_BUFFERTAG(a, xx_rnode, xx_forkNum, xx_blockNum) \ + ((a).rnode = (xx_rnode), (a).forkNum = (xx_forkNum), (a).blockNum = (xx_blockNum)) + +#define BUFFERTAGS_EQUAL(a, b) \ + (RelFileNodeEquals((a).rnode, (b).rnode) && (a).blockNum == (b).blockNum && (a).forkNum == (b).forkNum) + +#define BUFFERTAGS_PTR_EQUAL(a, b) \ + (RelFileNodeEquals((a)->rnode, (b)->rnode) && (a)->blockNum == (b)->blockNum && (a)->forkNum == (b)->forkNum) + +#define BUFFERTAGS_PTR_SET(a, b) \ + ((a)->rnode.spcNode = (b)->rnode.spcNode, \ + (a)->rnode.dbNode = (b)->rnode.dbNode, \ + (a)->rnode.relNode = (b)->rnode.relNode, \ + (a)->rnode.bucketNode = (b)->rnode.bucketNode,\ + (a)->forkNum = (b)->forkNum, \ + (a)->blockNum = (b)->blockNum) + +/* + * The shared buffer mapping table is partitioned to reduce contention. + * To determine which partition lock a given tag requires, compute the tag's + * hash code with BufTableHashCode(), then apply BufMappingPartitionLock(). + * NB: NUM_BUFFER_PARTITIONS must be a power of 2! + */ +#define BufTableHashPartition(hashcode) ((hashcode) % NUM_BUFFER_PARTITIONS) +#define BufMappingPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstBufMappingLock + \ + BufTableHashPartition(hashcode)].lock) +#define BufMappingPartitionLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstBufMappingLock + (i)].lock) + +/* + * BufferDesc -- shared descriptor/state data for a single shared buffer. + * + * Note: Buffer header lock (BM_LOCKED flag) must be held to examine or change + * the tag, state or wait_backend_pid fields. In general, buffer header lock + * is a spinlock which is combined with flags, refcount and usagecount into + * single atomic variable. This layout allow us to do some operations in a + * single atomic operation, without actually acquiring and releasing spinlock; + * for instance, increase or decrease refcount. buf_id field never changes + * after initialization, so does not need locking. The LWLock can take care + * of itself. The buffer header lock is *not* used to control access to the + * data in the buffer! + * + * It's assumed that nobody changes the state field while buffer header lock + * is held. Thus buffer header lock holder can do complex updates of the + * state variable in single write, simultaneously with lock release (cleaning + * BM_LOCKED flag). On the other hand, updating of state without holding + * buffer header lock is restricted to CAS, which insure that BM_LOCKED flag + * is not set. Atomic increment/decrement, OR/AND etc. are not allowed. + * + * An exception is that if we have the buffer pinned, its tag can't change + * underneath us, so we can examine the tag without locking the buffer header. + * Also, in places we do one-time reads of the flags without bothering to + * lock the buffer header; this is generally for situations where we don't + * expect the flag bit being tested to be changing. + * + * We can't physically remove items from a disk page if another backend has + * the buffer pinned. Hence, a backend may need to wait for all other pins + * to go away. This is signaled by storing its own PID into + * wait_backend_pid and setting flag bit BM_PIN_COUNT_WAITER. At present, + * there can be only one such waiter per buffer. + * + * We use this same struct for local buffer headers, but the lock fields + * are not used and not all of the flag bits are useful either. + */ +typedef struct BufferDesc { + BufferTag tag; /* ID of page contained in buffer */ + /* state of the tag, containing flags, refcount and usagecount */ + pg_atomic_uint32 state; + + int buf_id; /* buffer's index number (from 0) */ + + ThreadId wait_backend_pid; /* backend PID of pin-count waiter */ + + LWLock* io_in_progress_lock; /* to wait for I/O to complete */ + LWLock* content_lock; /* to lock access to buffer contents */ + + /* below fields are used for incremental checkpoint */ + pg_atomic_uint64 rec_lsn; /* recovery LSN */ + volatile uint64 dirty_queue_loc; /* actual loc of dirty page queue */ +} BufferDesc; + +/* + * Concurrent access to buffer headers has proven to be more efficient if + * they're cache line aligned. So we force the start of the BufferDescriptors + * array to be on a cache line boundary and force the elements to be cache + * line sized. + * + * XXX: As this is primarily matters in highly concurrent workloads which + * probably all are 64bit these days, and the space wastage would be a bit + * more noticeable on 32bit systems, we don't force the stride to be cache + * line sized on those. If somebody does actual performance testing, we can + * reevaluate. + * + * Note that local buffer descriptors aren't forced to be aligned - as there's + * no concurrent access to those it's unlikely to be beneficial. + * + * We use 64bit as the cache line size here, because that's the most common + * size. Making it bigger would be a waste of memory. Even if running on a + * platform with either 32 or 128 byte line sizes, it's good to align to + * boundaries and avoid false sharing. + */ +#define BUFFERDESC_PAD_TO_SIZE (SIZEOF_VOID_P == 8 ? 128 : 1) + +typedef union BufferDescPadded { + BufferDesc bufferdesc; + char pad[BUFFERDESC_PAD_TO_SIZE]; +} BufferDescPadded; + +#define GetBufferDescriptor(id) (&t_thrd.storage_cxt.BufferDescriptors[(id)].bufferdesc) +#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1) + +/* + * Functions for acquiring/releasing a shared buffer header's spinlock. Do + * not apply these to local buffers! + */ +extern uint32 LockBufHdr(BufferDesc* desc); + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#else +#define TsAnnotateHappensBefore(addr) +#endif + +#define UnlockBufHdr(desc, s) \ + do { \ + /* ENABLE_THREAD_CHECK only, release semantic */ \ + TsAnnotateHappensBefore(&desc->state); \ + pg_write_barrier(); \ + pg_atomic_write_u32(&(desc)->state, (s) & (~BM_LOCKED)); \ + } while (0) + +extern bool retryLockBufHdr(BufferDesc* desc, uint32* buf_state); +/* + * The PendingWriteback & WritebackContext structure are used to keep + * information about pending flush requests to be issued to the OS. + */ +typedef struct PendingWriteback { + /* could store different types of pending flushes here */ + BufferTag tag; +} PendingWriteback; + +/* struct forward declared in bufmgr.h */ +typedef struct WritebackContext { + /* pointer to the max number of writeback requests to coalesce */ + int* max_pending; + + /* current number of pending writeback requests */ + int nr_pending; + + /* pending requests */ + PendingWriteback pending_writebacks[WRITEBACK_MAX_PENDING_FLUSHES]; +} WritebackContext; + +/* in bufmgr.c */ + +/* + * Structure to sort buffers per file on checkpoints. + * + * This structure is allocated per buffer in shared memory, so it should be + * kept as small as possible. + */ +typedef struct CkptSortItem { + Oid tsId; + Oid relNode; + int2 bucketNode; + ForkNumber forkNum; + BlockNumber blockNum; + int buf_id; +} CkptSortItem; + +/* + * Internal routines: only called by bufmgr + */ +/* bufmgr.c */ +extern void WritebackContextInit(WritebackContext* context, int* max_pending); +extern void IssuePendingWritebacks(WritebackContext* context); +extern void ScheduleBufferTagForWriteback(WritebackContext* context, BufferTag* tag); + +/* freelist.c */ +extern BufferDesc *StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state); + +extern void StrategyFreeBuffer(volatile BufferDesc* buf); +extern bool StrategyRejectBuffer(BufferAccessStrategy strategy, BufferDesc* buf); + +extern int StrategySyncStart(uint32* complete_passes, uint32* num_buf_alloc); +extern void StrategyNotifyBgWriter(int bgwprocno); + +extern Size StrategyShmemSize(void); +extern void StrategyInitialize(bool init); + +/* buf_table.c */ +extern Size BufTableShmemSize(int size); +extern void InitBufTable(int size); +extern uint32 BufTableHashCode(BufferTag* tagPtr); +extern int BufTableLookup(BufferTag* tagPtr, uint32 hashcode); +extern int BufTableInsert(BufferTag* tagPtr, uint32 hashcode, int buf_id); +extern void BufTableDelete(BufferTag* tagPtr, uint32 hashcode); + +/* localbuf.c */ +extern void LocalPrefetchBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum); +extern BufferDesc* LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool* foundPtr); +extern void MarkLocalBufferDirty(Buffer buffer); +extern void DropRelFileNodeLocalBuffers(const RelFileNode& rnode, ForkNumber forkNum, BlockNumber firstDelBlock); +extern void DropRelFileNodeAllLocalBuffers(const RelFileNode& rnode); +extern void AtEOXact_LocalBuffers(bool isCommit); +extern void update_wait_lockid(LWLock* lock); +extern void FlushBuffer(void* buf, SMgrRelation reln, ReadBufferMethod flushmethod = WITH_NORMAL_CACHE); +extern void LocalBufferFlushAllBuffer(); +#endif /* BUFMGR_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/storage/bufmgr.h postgresql-hll-2.14/include/storage/bufmgr.h --- postgresql-hll-2.14_old/include/storage/bufmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/bufmgr.h 2020-12-12 17:06:43.375349690 +0800 @@ -0,0 +1,310 @@ +/* ------------------------------------------------------------------------- + * + * bufmgr.h + * POSTGRES buffer manager definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/bufmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFMGR_H +#define BUFMGR_H + +#include "knl/knl_variable.h" +#include "storage/block.h" +#include "storage/buf.h" +#include "storage/bufpage.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" + +typedef void* Block; + +typedef struct PrivateRefCountEntry { + Buffer buffer; + int32 refcount; +} PrivateRefCountEntry; + +/* 64 bytes, about the size of a cache line on common systems */ +#define REFCOUNT_ARRAY_ENTRIES 8 + +/* Possible arguments for GetAccessStrategy() */ +typedef enum BufferAccessStrategyType { + BAS_NORMAL, /* Normal random access */ + BAS_BULKREAD, /* Large read-only scan (hint bit updates are + * ok) */ + BAS_BULKWRITE, /* Large multi-block write (e.g. COPY IN) */ + BAS_VACUUM /* VACUUM */ +} BufferAccessStrategyType; + +/* Possible modes for ReadBufferExtended() */ +typedef enum { + RBM_NORMAL, /* Normal read */ + RBM_ZERO_AND_LOCK, /* Don't read from disk, caller will + * initialize */ + RBM_ZERO_AND_CLEANUP_LOCK, /* Like RBM_ZERO_AND_LOCK, but locks the page + * in "cleanup" mode */ + RBM_ZERO_ON_ERROR, /* Read, but return an all-zeros page on error */ + RBM_NORMAL_NO_LOG, /* Don't log page as invalid during WAL + * replay; otherwise same as RBM_NORMAL */ + RBM_FOR_REMOTE /* Like RBM_NORMAL, but not remote read again when PageIsVerified failed. */ +} ReadBufferMode; + +typedef enum +{ + WITH_NORMAL_CACHE = 0, /* Normal read */ + WITH_LOCAL_CACHE, /* Add for batchredo , the same as localbuf */ + WITH_OUT_CACHE /* without buf, read or write directly */ +} ReadBufferMethod; + +/* + * Private (non-shared) state for managing a ring of shared buffers to re-use. + * This is currently the only kind of BufferAccessStrategy object, but someday + * we might have more kinds. + */ +typedef struct BufferAccessStrategyData { + /* Overall strategy type */ + BufferAccessStrategyType btype; + /* Number of elements in buffers[] array */ + int ring_size; + + /* + * Index of the "current" slot in the ring, ie, the one most recently + * returned by GetBufferFromRing. + */ + int current; + + /* Number of elements to flush behind current */ + int flush_rate; + + /* + * True if the buffer just returned by StrategyGetBuffer had been in the + * ring already. + */ + bool current_was_in_ring; + + /* + * Array of buffer numbers. InvalidBuffer (that is, zero) indicates we + * have not yet selected a buffer for this ring slot. For allocation + * simplicity this is palloc'd together with the fixed fields of the + * struct. + */ + Buffer buffers[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE SIZE ARRAY */ +} BufferAccessStrategyData; + +/* forward declared, to avoid having to expose buf_internals.h here */ +struct WritebackContext; + +/* special block number for ReadBuffer() */ +#define P_NEW InvalidBlockNumber /* grow the file to get a new page */ + +/* Bits in SyncOneBuffer's return value */ +#define BUF_WRITTEN 0x01 +#define BUF_REUSABLE 0x02 +#define BUF_SKIPPED 0x04 + +/* + * Buffer content lock modes (mode argument for LockBuffer()) + */ +#define BUFFER_LOCK_UNLOCK 0 +#define BUFFER_LOCK_SHARE 1 +#define BUFFER_LOCK_EXCLUSIVE 2 + +#define MAX_PREFETCH_REQSIZ 512 +#define MAX_BACKWRITE_REQSIZ 64 + +/* + * BufferIsPinned + * True iff the buffer is pinned (also checks for valid buffer number). + * + * NOTE: what we check here is that *this* backend holds a pin on + * the buffer. We do not care whether some other backend does. + */ +#define BufferIsPinned(bufnum) \ + (!BufferIsValid(bufnum) ? false \ + : BufferIsLocal(bufnum) ? (u_sess->storage_cxt.LocalRefCount[-(bufnum)-1] > 0) \ + : (GetPrivateRefCount(bufnum) > 0)) + +/* + * These routines are beaten on quite heavily, hence the macroization. + */ + +/* + * BufferIsValid + * True iff the given buffer number is valid (either as a shared + * or local buffer). + * + * Note: For a long time this was defined the same as BufferIsPinned, + * that is it would say False if you didn't hold a pin on the buffer. + * I believe this was bogus and served only to mask logic errors. + * Code should always know whether it has a buffer reference, + * independently of the pin state. + * + * Note: For a further long time this was not quite the inverse of the + * BufferIsInvalid() macro, in that it also did sanity checks to verify + * that the buffer number was in range. Most likely, this macro was + * originally intended only to be used in assertions, but its use has + * since expanded quite a bit, and the overhead of making those checks + * even in non-assert-enabled builds can be significant. Thus, we've + * now demoted the range checks to assertions within the macro itself. + */ +#define BufferIsValid(bufnum) \ + (AssertMacro((bufnum) <= g_instance.attr.attr_storage.NBuffers && (bufnum) >= -u_sess->storage_cxt.NLocBuffer), \ + (bufnum) != InvalidBuffer) + +/* + * BufferGetBlock + * Returns a reference to a disk page image associated with a buffer. + * + * Note: + * Assumes buffer is valid. + */ +#define BufferGetBlock(buffer) \ + (AssertMacro(BufferIsValid(buffer)), \ + BufferIsLocal(buffer) ? u_sess->storage_cxt.LocalBufferBlockPointers[-(buffer)-1] \ + : (Block)(t_thrd.storage_cxt.BufferBlocks + ((Size)((uint)(buffer)-1)) * BLCKSZ)) + +/* + * BufferGetPageSize + * Returns the page size within a buffer. + * + * Notes: + * Assumes buffer is valid. + * + * The buffer can be a raw disk block and need not contain a valid + * (formatted) disk page. + */ +/* XXX should dig out of buffer descriptor */ +#define BufferGetPageSize(buffer) (AssertMacro(BufferIsValid(buffer)), (Size)BLCKSZ) + +/* + * BufferGetPage + * Returns the page associated with a buffer. + */ +#define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer)) + +/* Note: these two macros only work on shared buffers, not local ones! */ +#define BufHdrGetBlock(bufHdr) ((Block)(t_thrd.storage_cxt.BufferBlocks + ((Size)(uint32)(bufHdr)->buf_id) * BLCKSZ)) +#define BufferGetLSN(bufHdr) (PageGetLSN(BufHdrGetBlock(bufHdr))) + +/* Note: this macro only works on local buffers, not shared ones! */ +#define LocalBufHdrGetBlock(bufHdr) u_sess->storage_cxt.LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] +#define LocalBufGetLSN(bufHdr) (PageGetLSN(LocalBufHdrGetBlock(bufHdr))) + +/* + * prototypes for functions in bufmgr.c + */ +extern void PrefetchBuffer(Relation reln, ForkNumber forkNum, BlockNumber blockNum); +extern void PageRangePrefetch( + Relation reln, ForkNumber forkNum, BlockNumber blockNum, int32 n, uint32 flags, uint32 col); +extern void PageListPrefetch( + Relation reln, ForkNumber forkNum, BlockNumber* blockList, int32 n, uint32 flags, uint32 col); +extern Buffer ReadBuffer(Relation reln, BlockNumber blockNum); +extern Buffer ReadBufferExtended( + Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy); +extern Buffer ReadBufferWithoutRelcache( + const RelFileNode& rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy); +extern Buffer ReadBufferForRemote(const RelFileNode& rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, + BufferAccessStrategy strategy, bool* hit); + +extern void ReleaseBuffer(Buffer buffer); +extern void UnlockReleaseBuffer(Buffer buffer); +extern void MarkBufferDirty(Buffer buffer); +extern void IncrBufferRefCount(Buffer buffer); +extern Buffer ReleaseAndReadBuffer(Buffer buffer, Relation relation, BlockNumber blockNum); + +extern void InitBufferPool(void); +extern void InitBufferPoolAccess(void); +extern void InitBufferPoolBackend(void); +extern void AtEOXact_Buffers(bool isCommit); +extern void PrintBufferLeakWarning(Buffer buffer); +extern void CheckPointBuffers(int flags, bool doFullCheckpoint); +extern BlockNumber BufferGetBlockNumber(Buffer buffer); +extern BlockNumber RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum, bool estimate = false); +extern void FlushRelationBuffers(Relation rel, HTAB *hashtbl = NULL); +extern void FlushDatabaseBuffers(Oid dbid); + +extern void DropRelFileNodeBuffers(const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber firstDelBlock); +extern void DropTempRelFileNodeAllBuffers(const RelFileNodeBackend& rnode); + + +#define DROP_BUFFER_USING_HASH_DEL_REL_NUM_THRESHOLD 20 +#define IS_DEL_RELS_OVER_HASH_THRESHOLD(ndelrels) ((ndelrels) > DROP_BUFFER_USING_HASH_DEL_REL_NUM_THRESHOLD) + +extern void DropRelFileNodeAllBuffersUsingHash(HTAB* relfilenode_hashtbl); +extern void DropRelFileNodeAllBuffersUsingScan(RelFileNode* rnode, int rnode_len); + +extern void DropDatabaseBuffers(Oid dbid); + +extern BlockNumber PartitionGetNumberOfBlocksInFork(Relation relation, Partition partition, ForkNumber forkNum); + +#define RelationGetNumberOfBlocks(reln) RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM) + +/* + * PartitionGetNumberOfBlocks + * Determines the current number of pages in the partition. + */ +#define PartitionGetNumberOfBlocks(rel, part) PartitionGetNumberOfBlocksInFork(rel, part, MAIN_FORKNUM) + +extern bool BufferIsPermanent(Buffer buffer); + +extern void RemoteReadBlock(const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber blockNum, char* buf); + +#ifdef NOT_USED +extern void PrintPinnedBufs(void); +#endif +extern Size BufferShmemSize(void); +extern void BufferGetTag(Buffer buffer, RelFileNode* rnode, ForkNumber* forknum, BlockNumber* blknum); + +void PinBuffer_Locked(volatile BufferDesc* buf); +void UnpinBuffer(BufferDesc* buf, bool fixOwner); +extern void MarkBufferDirtyHint(Buffer buffer, bool buffer_std); +extern void FlushOneBuffer(Buffer buffer); +extern void UnlockBuffers(void); +extern void LockBuffer(Buffer buffer, int mode); +extern bool ConditionalLockBuffer(Buffer buffer); +extern void LockBufferForCleanup(Buffer buffer); +extern bool ConditionalLockBufferForCleanup(Buffer buffer); +extern bool HoldingBufferPinThatDelaysRecovery(void); +extern void AsyncUnpinBuffer(volatile void* bufHdr, bool forgetBuffer); +extern void AsyncCompltrPinBuffer(volatile void* bufHdr); +extern void AsyncCompltrUnpinBuffer(volatile void* bufHdr); +extern void TerminateBufferIO(volatile BufferDesc* buf, bool clear_dirty, uint32 set_flag_bits); + +extern void AsyncTerminateBufferIO(void* bufHdr, bool clear_dirty, uint32 set_flag_bits); +extern void AsyncAbortBufferIO(void* buf, bool isForInput); +extern void AsyncTerminateBufferIOByVacuum(void* buffer); +extern void AsyncAbortBufferIOByVacuum(void* buffer); +extern void AbortBufferIO(void); +extern void AbortBufferIO_common(BufferDesc* buf, bool isForInput); +extern void AbortAsyncListIO(void); +extern void CheckIOState(volatile void* bufHdr); +extern void BufmgrCommit(void); +extern bool BgBufferSync(struct WritebackContext* wb_context); +extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer); +extern void AtProcExit_Buffers(int code, Datum arg); +extern void AtProcExit_LocalBuffers(void); + +/* in freelist.c */ +extern BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype); +extern void FreeAccessStrategy(BufferAccessStrategy strategy); + +/* dirty page manager */ +extern int ckpt_buforder_comparator(const void* pa, const void* pb); +extern void clean_buf_need_flush_flag(BufferDesc *buf_desc); +extern void ckpt_flush_dirty_page(int thread_id, WritebackContext wb_context); + +extern uint32 SyncOneBuffer( + int buf_id, bool skip_recently_used, WritebackContext* flush_context, bool get_candition_lock = false); + +extern Buffer ReadBuffer_common_for_direct(RelFileNode rnode, char relpersistence, ForkNumber forkNum, + BlockNumber blockNum, ReadBufferMode mode); +extern Buffer ReadBuffer_common_for_localbuf(RelFileNode rnode, char relpersistence, ForkNumber forkNum, + BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy, bool *hit); +extern void DropRelFileNodeShareBuffers(RelFileNode node, ForkNumber forkNum, BlockNumber firstDelBlock); +extern int GetThreadBufferLeakNum(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/bufpage.h postgresql-hll-2.14/include/storage/bufpage.h --- postgresql-hll-2.14_old/include/storage/bufpage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/bufpage.h 2020-12-12 17:06:43.375349690 +0800 @@ -0,0 +1,482 @@ +/* ------------------------------------------------------------------------- + * + * bufpage.h + * Standard POSTGRES buffer page definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/bufpage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUFPAGE_H +#define BUFPAGE_H + +#include "access/xlogdefs.h" +#include "storage/block.h" +#include "storage/item.h" +#include "storage/off.h" +#include "storage/buf.h" + +/* + * A postgres disk page is an abstraction layered on top of a postgres + * disk block (which is simply a unit of i/o, see block.h). + * + * specifically, while a disk block can be unformatted, a postgres + * disk page is always a slotted page of the form: + * + * +----------------+---------------------------------+ + * | PageHeaderData | linp1 linp2 linp3 ... | + * +-----------+----+---------------------------------+ + * | ... linpN | | + * +-----------+--------------------------------------+ + * | ^ pd_lower | + * | | + * | v pd_upper | + * +-------------+------------------------------------+ + * | | tupleN ... | + * +-------------+------------------+-----------------+ + * | ... tuple3 tuple2 tuple1 | "special space" | + * +--------------------------------+-----------------+ + * ^ pd_special + * + * a page is full when nothing can be added between pd_lower and + * pd_upper. + * + * all blocks written out by an access method must be disk pages. + * + * EXCEPTIONS: + * + * obviously, a page is not formatted before it is initialized by + * a call to PageInit. + * + * NOTES: + * + * linp1..N form an ItemId array. ItemPointers point into this array + * rather than pointing directly to a tuple. Note that OffsetNumbers + * conventionally start at 1, not 0. + * + * tuple1..N are added "backwards" on the page. because a tuple's + * ItemPointer points to its ItemId entry rather than its actual + * byte-offset position, tuples can be physically shuffled on a page + * whenever the need arises. + * + * AM-generic per-page information is kept in PageHeaderData. + * + * AM-specific per-page data (if any) is kept in the area marked "special + * space"; each AM has an "opaque" structure defined somewhere that is + * stored as the page trailer. an access method should always + * initialize its pages with PageInit and then set its own opaque + * fields. + */ + +typedef Pointer Page; + +/* + * location (byte offset) within a page. + * + * note that this is actually limited to 2^15 because we have limited + * ItemIdData.lp_off and ItemIdData.lp_len to 15 bits (see itemid.h). + */ +typedef uint16 LocationIndex; + +/* + * For historical reasons, the 64-bit LSN value is stored as two 32-bit + * values. + */ +typedef struct { + uint32 xlogid; /* high bits */ + uint32 xrecoff; /* low bits */ +} PageXLogRecPtr; + +/* + * disk page organization + * + * space management information generic to any page + * + * pd_lsn - identifies xlog record for last change to this page. + * pd_checksum - page checksum, if set. + * pd_flags - flag bits. + * pd_lower - offset to start of free space. + * pd_upper - offset to end of free space. + * pd_special - offset to start of special space. + * pd_pagesize_version - size in bytes and page layout version number. + * pd_prune_xid - oldest XID among potentially prunable tuples on page. + * + * The LSN is used by the buffer manager to enforce the basic rule of WAL: + * "thou shalt write xlog before data". A dirty buffer cannot be dumped + * to disk until xlog has been flushed at least as far as the page's LSN. + * + * pd_checksum stores the page checksum, if it has been set for this page; + * zero is a valid value for a checksum. If a checksum is not in use then + * we leave the field unset. This will typically mean the field is zero + * though non-zero values may also be present if databases have been + * pg_upgraded from releases prior to 9.3, when the same byte offset was + * used to store the current timelineid when the page was last updated. + * Note that there is no indication on a page as to whether the checksum + * is valid or not, a deliberate design choice which avoids the problem + * of relying on the page contents to decide whether to verify it. Hence + * there are no flag bits relating to checksums. + * + * pd_prune_xid is a hint field that helps determine whether pruning will be + * useful. It is currently unused in index pages. + * + * The page version number and page size are packed together into a single + * uint16 field. This is for historical reasons: before PostgreSQL 7.3, + * there was no concept of a page version number, and doing it this way + * lets us pretend that pre-7.3 databases have page version number zero. + * We constrain page sizes to be multiples of 256, leaving the low eight + * bits available for a version number. + * + * Minimum possible page size is perhaps 64B to fit page header, opaque space + * and a minimal tuple; of course, in reality you want it much bigger, so + * the constraint on pagesize mod 256 is not an important restriction. + * On the high end, we can only support pages up to 32KB because lp_off/lp_len + * are 15 bits. + */ +typedef struct { + /* XXX LSN is member of *any* block, not only page-organized ones */ + PageXLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog + * record for last change to this page */ + uint16 pd_checksum; /* checksum */ + uint16 pd_flags; /* flag bits, see below */ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + uint16 pd_pagesize_version; + ShortTransactionId pd_prune_xid; /* oldest prunable XID, or zero if none */ + ItemIdData pd_linp[FLEXIBLE_ARRAY_MEMBER]; /* beginning of line pointer array */ +} PageHeaderData; + +typedef PageHeaderData* PageHeader; + +/* + * HeapPageHeaderData -- data that stored at the begin of each new version heap page. + * pd_xid_base - base value for transaction IDs on page + * pd_multi_base - base value for multixact IDs on page + * + */ +typedef struct { + /* XXX LSN is member of *any* block, not only page-organized ones */ + PageXLogRecPtr pd_lsn; /* LSN: next byte after last byte of xlog + * record for last change to this page */ + uint16 pd_checksum; /* checksum */ + uint16 pd_flags; /* flag bits, see below */ + LocationIndex pd_lower; /* offset to start of free space */ + LocationIndex pd_upper; /* offset to end of free space */ + LocationIndex pd_special; /* offset to start of special space */ + uint16 pd_pagesize_version; + ShortTransactionId pd_prune_xid; /* oldest prunable XID, or zero if none */ + TransactionId pd_xid_base; /* base value for transaction IDs on page */ + TransactionId pd_multi_base; /* base value for multixact IDs on page */ + ItemIdData pd_linp[FLEXIBLE_ARRAY_MEMBER]; /* beginning of line pointer array */ +} HeapPageHeaderData; + +typedef HeapPageHeaderData* HeapPageHeader; + +#define GetPageHeaderSize(page) (PageIs8BXidHeapVersion(page) ? SizeOfHeapPageHeaderData : SizeOfPageHeaderData) + +#define SizeOfHeapPageUpgradeData MAXALIGN(offsetof(HeapPageHeaderData, pd_linp) - offsetof(PageHeaderData, pd_linp)) + +/* + * pd_flags contains the following flag bits. Undefined bits are initialized + * to zero and may be used in the future. + * + * PD_HAS_FREE_LINES is set if there are any LP_UNUSED line pointers before + * pd_lower. This should be considered a hint rather than the truth, since + * changes to it are not WAL-logged. + * + * PD_PAGE_FULL is set if an UPDATE doesn't find enough free space in the + * page for its new tuple version; this suggests that a prune is needed. + * Again, this is just a hint. + */ +#define PD_HAS_FREE_LINES 0x0001 /* are there any unused line pointers? */ +#define PD_PAGE_FULL 0x0002 /* not enough free space for new tuple? */ +#define PD_ALL_VISIBLE 0x0004 /* all tuples on page are visible to everyone */ +#define PD_COMPRESSED_PAGE 0x0008 /* compressed page flag */ +#define PD_LOGICAL_PAGE 0x0010 /* logical page flag used by bulkload or copy */ +#define PD_ENCRYPT_PAGE 0x0020 /* is a encryt cluster */ +#define PD_CHECKSUM_FNV1A 0x0040 /* page checksum using FNV-1a hash */ +#define PD_JUST_AFTER_FPW 0x0080 /* page just after redo full page write */ + +#define PD_VALID_FLAG_BITS 0x00FF /* OR of all valid pd_flags bits */ + +/* + * Page layout version number 0 is for pre-7.3 Postgres releases. + * Releases 7.3 and 7.4 use 1, denoting a new HeapTupleHeader layout. + * Release 8.0 uses 2; it changed the HeapTupleHeader layout again. + * Release 8.1 uses 3; it redefined HeapTupleHeader infomask bits. + * Release 8.3 uses 4; it changed the HeapTupleHeader layout again, and + * added the pd_flags field (by stealing some bits from pd_tli), + * as well as adding the pd_prune_xid field (which enlarges the header). + * + * As of Release 9.3, the checksum version must also be considered when + * handling pages. + */ +#define PG_HEAP_PAGE_LAYOUT_VERSION 6 +#define PG_COMM_PAGE_LAYOUT_VERSION 5 +#define PG_PAGE_4B_LAYOUT_VERSION 4 + +/* ---------------------------------------------------------------- + * page support macros + * ---------------------------------------------------------------- + */ + +/* + * PageIsValid + * True iff page is valid. + */ +#define PageIsValid(page) PointerIsValid(page) + +/* + * line pointer(s) do not count as part of header + */ +#define SizeOfPageHeaderData (offsetof(PageHeaderData, pd_linp)) +#define SizeOfHeapPageHeaderData (offsetof(HeapPageHeaderData, pd_linp)) + +/* + * PageIsEmpty + * returns true iff no itemid has been allocated on the page + */ +#define PageIsEmpty(page) (((PageHeader)(page))->pd_lower <= GetPageHeaderSize(page)) + +/* + * PageIsNew + * returns true iff page has not been initialized (by PageInit) + */ +#define PageIsNew(page) (((PageHeader)(page))->pd_upper == 0) + +/* + * PageGetItemId + * Returns an item identifier of a page. + */ +#define PageGetItemId(page, offsetNumber) \ + (PageIs8BXidHeapVersion(page) ? ((ItemId)(&((HeapPageHeader)(page))->pd_linp[(offsetNumber)-1])) \ + : ((ItemId)(&((PageHeader)(page))->pd_linp[(offsetNumber)-1]))) + +/* + * PageGetContents + * To be used in case the page does not contain item pointers. + * + * Note: prior to 8.3 this was not guaranteed to yield a MAXALIGN'd result. + * Now it is. Beware of old code that might think the offset to the contents + * is just SizeOfPageHeaderData rather than MAXALIGN(SizeOfPageHeaderData). + */ +#define PageGetContents(page) ((char*)(page) + MAXALIGN(GetPageHeaderSize(page))) + +/* ---------------- + * macros to access page size info + * ---------------- + */ + +/* + * PageSizeIsValid + * True iff the page size is valid. + */ +#define PageSizeIsValid(pageSize) ((pageSize) == BLCKSZ) + +/* + * PageGetPageSize + * Returns the page size of a page. + * + * this can only be called on a formatted page (unlike + * BufferGetPageSize, which can be called on an unformatted page). + * however, it can be called on a page that is not stored in a buffer. + */ +#define PageGetPageSize(page) ((Size)(((PageHeader)(page))->pd_pagesize_version & (uint16)0xFF00)) + +/* + * PageGetPageLayoutVersion + * Returns the page layout version of a page. + */ +#define PageGetPageLayoutVersion(page) (((PageHeader)(page))->pd_pagesize_version & 0x00FF) + +#define PageIs8BXidVersion(page) (PageGetPageLayoutVersion(page) == PG_COMM_PAGE_LAYOUT_VERSION) + +#define PageIs4BXidVersion(page) (PageGetPageLayoutVersion(page) == PG_PAGE_4B_LAYOUT_VERSION) + +#define PageIs8BXidHeapVersion(page) (PageGetPageLayoutVersion(page) == PG_HEAP_PAGE_LAYOUT_VERSION) + +/* + * PageSetPageSizeAndVersion + * Sets the page size and page layout version number of a page. + * + * We could support setting these two values separately, but there's + * no real need for it at the moment. + */ +#define PageSetPageSizeAndVersion(page, size, version) \ + (AssertMacro(((size)&0xFF00) == (size)), \ + AssertMacro(((version)&0x00FF) == (version)), \ + ((PageHeader)(page))->pd_pagesize_version = (size) | (version)) + +/* ---------------- + * page special data macros + * ---------------- + */ +/* + * PageGetSpecialSize + * Returns size of special space on a page. + */ +#define PageGetSpecialSize(page) ((uint16)(PageGetPageSize(page) - ((PageHeader)(page))->pd_special)) + +/* + * PageGetSpecialPointer + * Returns pointer to special space on a page. + */ +#define PageGetSpecialPointer(page) \ + (AssertMacro(PageIsValid(page)), (char*)((char*)(page) + ((PageHeader)(page))->pd_special)) + +#define BTPageGetSpecial(page) \ + (PageIs8BXidVersion(page) \ + ? (AssertMacro(((PageHeader)page)->pd_special == BLCKSZ - MAXALIGN(sizeof(BTPageOpaqueData))), \ + (BTPageOpaque)((Pointer)page + BLCKSZ - MAXALIGN(sizeof(BTPageOpaqueData)))) \ + : NULL) + +#define HeapPageSetPruneXid(page, xid) \ + (((PageHeader)(page))->pd_prune_xid = NormalTransactionIdToShort( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, (xid))) + +#define HeapPageGetPruneXid(page) \ + (ShortTransactionIdToNormal( \ + PageIs8BXidHeapVersion(page) ? ((HeapPageHeader)(page))->pd_xid_base : 0, ((PageHeader)(page))->pd_prune_xid)) + +/* + * PageGetItem + * Retrieves an item on the given page. + * + * Note: + * This does not change the status of any of the resources passed. + * The semantics may change in the future. + */ +#define PageGetItem(page, itemId) \ + (AssertMacro(PageIsValid(page)), \ + AssertMacro(ItemIdHasStorage(itemId)), \ + (Item)(((char*)(page)) + ItemIdGetOffset(itemId))) + +/* + * PageGetMaxOffsetNumber + * Returns the maximum offset number used by the given page. + * Since offset numbers are 1-based, this is also the number + * of items on the page. + * + * NOTE: if the page is not initialized (pd_lower == 0), we must + * return zero to ensure sane behavior. Accept double evaluation + * of the argument so that we can ensure this. + */ +inline OffsetNumber PageGetMaxOffsetNumber(char* pghr) +{ + OffsetNumber maxoff = InvalidOffsetNumber; + Size pageheadersize = GetPageHeaderSize(pghr); + + if (((PageHeader)pghr)->pd_lower <= pageheadersize) + maxoff = 0; + else + maxoff = (((PageHeader)pghr)->pd_lower - pageheadersize) / sizeof(ItemIdData); + + return maxoff; +} + +/* + * Additional macros for access to page headers + */ +#define PageGetLSN(page) (((uint64)((PageHeader)(page))->pd_lsn.xlogid << 32) | ((PageHeader)(page))->pd_lsn.xrecoff) +#define PageSetLSNInternal(page, lsn) \ + (((PageHeader)(page))->pd_lsn.xlogid = (uint32)((lsn) >> 32), ((PageHeader)(page))->pd_lsn.xrecoff = (uint32)(lsn)) + +inline void PageSetLSN(Page page, XLogRecPtr LSN, bool check = true) +{ + if (check && XLByteLT(LSN, PageGetLSN(page))) { + elog(PANIC, "The Page's LSN[%lu] bigger than want set LSN [%lu]", PageGetLSN(page), LSN); + } + PageSetLSNInternal(page, LSN); +} + +#define PageHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags & PD_HAS_FREE_LINES) +#define PageSetHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags |= PD_HAS_FREE_LINES) +#define PageClearHasFreeLinePointers(page) (((PageHeader)(page))->pd_flags &= ~PD_HAS_FREE_LINES) + +#define PageIsFull(page) (((PageHeader)(page))->pd_flags & PD_PAGE_FULL) +#define PageSetFull(page) (((PageHeader)(page))->pd_flags |= PD_PAGE_FULL) +#define PageClearFull(page) (((PageHeader)(page))->pd_flags &= ~PD_PAGE_FULL) + +#define PageIsAllVisible(page) (((PageHeader)(page))->pd_flags & PD_ALL_VISIBLE) +#define PageSetAllVisible(page) (((PageHeader)(page))->pd_flags |= PD_ALL_VISIBLE) +#define PageClearAllVisible(page) (((PageHeader)(page))->pd_flags &= ~PD_ALL_VISIBLE) + +#define PageIsCompressed(page) ((bool)(((PageHeader)(page))->pd_flags & PD_COMPRESSED_PAGE)) +#define PageSetCompressed(page) (((PageHeader)(page))->pd_flags |= PD_COMPRESSED_PAGE) +#define PageClearCompressed(page) (((PageHeader)(page))->pd_flags &= ~PD_COMPRESSED_PAGE) + +#define PageIsLogical(page) (((PageHeader)(page))->pd_flags & PD_LOGICAL_PAGE) +#define PageSetLogical(page) (((PageHeader)(page))->pd_flags |= PD_LOGICAL_PAGE) +#define PageClearLogical(page) (((PageHeader)(page))->pd_flags &= ~PD_LOGICAL_PAGE) + +#define PageIsEncrypt(page) (((PageHeader)(page))->pd_flags & PD_ENCRYPT_PAGE) +#define PageSetEncrypt(page) (((PageHeader)(page))->pd_flags |= PD_ENCRYPT_PAGE) +#define PageClearEncrypt(page) (((PageHeader)(page))->pd_flags &= ~PD_ENCRYPT_PAGE) + +#define PageIsChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags & PD_CHECKSUM_FNV1A) +#define PageSetChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags |= PD_CHECKSUM_FNV1A) +#define PageClearChecksumByFNV1A(page) (((PageHeader)(page))->pd_flags &= ~PD_CHECKSUM_FNV1A) + +#define PageIsJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags & PD_JUST_AFTER_FPW) +#define PageSetJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags |= PD_JUST_AFTER_FPW) +#define PageClearJustAfterFullPageWrite(page) (((PageHeader)(page))->pd_flags &= ~PD_JUST_AFTER_FPW) + +#define PageIsPrunable(page, oldestxmin) \ + (AssertMacro(TransactionIdIsNormal(oldestxmin)), \ + TransactionIdIsValid(HeapPageGetPruneXid(page)) && \ + TransactionIdPrecedes(HeapPageGetPruneXid(page), oldestxmin)) +#define PageSetPrunable(page, xid) \ + do { \ + Assert(TransactionIdIsNormal(xid)); \ + if (!TransactionIdIsValid(HeapPageGetPruneXid(page)) || TransactionIdPrecedes(xid, HeapPageGetPruneXid(page))) \ + HeapPageSetPruneXid(page, xid); \ + } while (0) +#define PageClearPrunable(page) (HeapPageSetPruneXid(page, InvalidTransactionId)) + +#define GlobalTempRelationPageIsNotInitialized(rel, page) \ + ((rel)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP && PageIsNew(page)) + +const int PAGE_INDEX_CAN_TUPLE_DELETE = 2; + +/* ---------------------------------------------------------------- + * extern declarations + * --------------------------TerminateBufferIO-------------------------------------- + */ +typedef struct { + int offsetindex; /* linp array index */ + int itemoff; /* page offset of item data */ + Size alignedlen; /* MAXALIGN(item data len) */ + ItemIdData olditemid; /* used only in PageIndexMultiDelete */ +} itemIdSortData; +typedef itemIdSortData* itemIdSort; + +extern void PageInit(Page page, Size pageSize, Size specialSize, bool isheap = false); +extern bool PageIsVerified(Page page, BlockNumber blkno); +extern bool PageHeaderIsValid(PageHeader page); +extern OffsetNumber PageAddItem( + Page page, Item item, Size size, OffsetNumber offsetNumber, bool overwrite, bool is_heap); +extern Page PageGetTempPage(Page page); +extern Page PageGetTempPageCopy(Page page); +extern Page PageGetTempPageCopySpecial(Page page, bool isbtree); +extern void PageRestoreTempPage(Page tempPage, Page oldPage); +extern void PageRepairFragmentation(Page page); +extern Size PageGetFreeSpace(Page page); +extern Size PageGetExactFreeSpace(Page page); +extern Size PageGetHeapFreeSpace(Page page); +extern void PageIndexTupleDelete(Page page, OffsetNumber offset); +extern void PageIndexMultiDelete(Page page, OffsetNumber* itemnos, int nitems); + +extern void PageReinitWithDict(Page page, Size dictSize); +extern bool PageFreeDict(Page page); +extern char* PageDataEncryptIfNeed(Page page); +extern void PageDataDecryptIfNeed(Page page); +extern char* PageSetChecksumCopy(Page page, BlockNumber blkno); +extern void PageSetChecksumInplace(Page page, BlockNumber blkno); + +extern void PageLocalUpgrade(Page page); +extern void DumpPageInfo(Page page, XLogRecPtr newLsn); +#endif /* BUFPAGE_H */ diff -uprN postgresql-hll-2.14_old/include/storage/cache_mgr.h postgresql-hll-2.14/include/storage/cache_mgr.h --- postgresql-hll-2.14_old/include/storage/cache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cache_mgr.h 2020-12-12 17:06:43.375349690 +0800 @@ -0,0 +1,288 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cache_mgr.h + * routines to support common cache + * + * + * + * IDENTIFICATION + * src/include/storage/cache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CacheMgr_H +#define CacheMgr_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "utils/hsearch.h" +#include "storage/lwlock.h" +#include "storage/spin.h" + +// CU Cache Pool sizes. +// + +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * (int)(!!(condition))])) + +typedef int CacheSlotId_t; + +// Cache Block flags +typedef unsigned char CacheFlags; // Modified by CUSlotDesc and CacheMgr +const unsigned char CACHE_BLOCK_NEW = 0x00; // Slot is not on any list +const unsigned char CACHE_BLOCK_VALID = 0x01; // In Hashtable and contains valid data +const unsigned char CACHE_BLOCK_INFREE = 0x02; // slot is in free state +const unsigned char CACHE_BLOCK_FREE = 0x04; // Slot is on the free list +const unsigned char CACHE_BLOCK_IOBUSY = 0x08; // Slot buf r/w in progress +const unsigned char CACHE_BLOCK_ERROR = 0x10; // Slot buf error + +// Special Slot Index values +const int CACHE_BLOCK_INVALID_IDX = -1; // Invalid index -end of this list +const int CACHE_BLOCK_NO_LIST = -2; // Invalid index -not in any list + +#define IsValidCacheSlotID(x) ((x) != CACHE_BLOCK_INVALID_IDX) + +// Max usage count for CLOCK cache strategy +const uint16 CACHE_BLOCK_MAX_USAGE = 5; + +/* common buffer cache function for cu cache and orc cache */ +#define MAX_CACHE_TAG_LEN (32) + +typedef enum CacheType { + /*only used for init cache type, for not exist type*/ + CACHE_TYPE_NONE = 0, + + /* data block*/ + CACHE_COlUMN_DATA, + CACHE_ORC_DATA, + CACHE_OBS_DATA, + CACHE_CARBONDATA_DATA, + + /*index block*/ + CACHE_ORC_INDEX, + + /* metadata block */ + CACHE_CARBONDATA_METADATA +} CacheType; + +typedef enum MgrCacheType { + /* cache manager type */ + MGR_CACHE_TYPE_DATA, + MGR_CACHE_TYPE_INDEX +} MgrCacheType; + +typedef struct CacheTag { + /*cu + RelFileNode rnode; + int32 col_id; + int32 cu_id; + uint32 padding; + CUPointer offset; + */ + + /*orc compress data + RelFileNode m_rnode; + int32 m_fileId; + uint64 m_offset; + uint64 m_length; + */ + + /*orc meta data + RelFileNode fileNode; + int32 fileID; + uint32 stripeID; + uint32 columnID; + */ + + /*common cache tag*/ + int32 type; + char key[MAX_CACHE_TAG_LEN]; +} CacheTag; + +typedef struct CacheDesc { + uint16 m_usage_count; + uint16 m_ring_count; + uint32 m_refcount; + CacheTag m_cache_tag; + + CacheSlotId_t m_slot_id; + CacheSlotId_t m_freeNext; + + /* Light wight lock: i/o busy lock */ + LWLock *m_iobusy_lock; + + /* + * Light wight lock: used for CU + * compress/uncompress busy lock. + * If there are two or more threads + * read one CU where is uncompressing + * we must wait. + */ + LWLock *m_compress_lock; + + /*The data size in the one slot.*/ + int m_datablock_size; + + /* + * This flag used in OBS foreign table. + * Think a scenario, a file located on OBS and + * touched by DW through foreign table. We + * cached part of this file. Now two threads + * want to read this cache and find the file + * eTag has changed, it is this session's responsibility + * to update this cache. There must be a machnism + * to avoid two or more threads to update it concurrently. + * If thread find m_refreshing is yes. It not wait for + * updating finish, but read data from OBS directly. + */ + bool m_refreshing; + + slock_t m_slot_hdr_lock; + + CacheFlags m_flag; +} CacheDesc; + +int CacheMgrNumLocks(int64 cache_size, uint32 each_block_size); +int64 CacheMgrCalcSizeByType(MgrCacheType type); + +/* + * This class is to manage Common Cache. + */ +class CacheMgr : public BaseObject { +public: + CacheMgr(){}; + ~CacheMgr(){}; + void Init(int64 cache_size, uint32 each_block_size, MgrCacheType type, uint32 each_slot_length); + void Destroy(void); + + /* operate cache block */ + void InitCacheBlockTag(CacheTag* cacheTag, int32 type, const void* key, int32 length) const; + CacheSlotId_t FindCacheBlock(CacheTag* cacheTag, bool first_enter_block); + void InvalidateCacheBlock(CacheTag* cacheTag); + void DeleteCacheBlock(CacheTag* cacheTag); + CacheSlotId_t ReserveCacheBlock(CacheTag* cacheTag, int size, bool& hasFound); + bool ReserveCacheBlockWithSlotId(CacheSlotId_t slotId); + bool ReserveCstoreCacheBlockWithSlotId(CacheSlotId_t slotId); + void* GetCacheBlock(CacheSlotId_t slotId); + const CacheTag* GetCacheBlockTag(CacheSlotId_t slotId, uint32* refcount) const; + bool PinCacheBlock(CacheSlotId_t slotId); + void UnPinCacheBlock(CacheSlotId_t slotId); + + /* Manage I/O busy cache block */ + bool IsIOBusy(CacheSlotId_t cuSlotId); + bool WaitIO(CacheSlotId_t slotId); + void CompleteIO(CacheSlotId_t cuSlotId); + + /* async lock used by adio */ + bool LockHeldByMe(CacheSlotId_t slotId); + void LockOwn(CacheSlotId_t slotId); + void LockDisown(CacheSlotId_t slotId); + + /* compress lock */ + void AcquireCompressLock(CacheSlotId_t slotId); + void RealeseCompressLock(CacheSlotId_t slotId); + + /* ring strategy, not used for now */ + void IncRingCount(CacheSlotId_t slotId); + void DecRingCount(CacheSlotId_t slotId); + + /* memory operate */ + int64 GetCurrentMemSize(); + void ReleaseCacheMem(int size); + bool CompressLockHeldByMe(CacheSlotId_t slotId); + + /* IO lock */ + void AcquireCstoreIOLock(CacheSlotId_t slotId); + void RealeseCstoreIOLock(CacheSlotId_t slotId); + bool CstoreIOLockHeldByMe(CacheSlotId_t slotId); + void AdjustCacheMem(CacheSlotId_t slotId, int oldSize, int newSize); + + /* error handle */ + void AbortCacheBlock(CacheSlotId_t slotId); + void SetCacheBlockErrorState(CacheSlotId_t slotId); + + /* + * get the number of cache slot now used. + * notice the number will be bigger and bigger, not smaller. + */ + int GetUsedCacheSlotNum(void) + { + return m_CaccheSlotMax; + } + void CopyCacheBlockTag(CacheSlotId_t slotId, CacheTag* outTag); + + char* m_CacheSlots; + +#ifndef ENABLE_UT +private: +#endif // ENABLE_UT + + uint32 GetHashCode(CacheTag* cacheTag); + + /* internal block operate */ + CacheSlotId_t EvictCacheBlock(int size, int retryNum); + CacheSlotId_t GetFreeCacheBlock(int size); + + /* memory operate */ + bool ReserveCacheMem(int size); + void FreeCacheBlockMem(CacheSlotId_t slotId); + int GetCacheBlockMemSize(CacheSlotId_t slotId); + + /* free list */ + bool CacheFreeListEmpty() const; + int GetFreeListCache(); + void PutFreeListCache(CacheSlotId_t freeSlotIdx); + + /* lock */ + LWLock *LockHashPartion(uint32 hashCode, LWLockMode lockMode) const; + void UnLockHashPartion(uint32 hashCode) const; + void LockCacheDescHeader(CacheSlotId_t slot); + void UnLockCacheDescHeader(CacheSlotId_t slot); + void LockSweep(); + void UnlockSweep(); + + bool CacheBlockIsPinned(CacheSlotId_t slotId) const; + void PinCacheBlock_Locked(CacheSlotId_t slotId); + + CacheSlotId_t AllocateBlockFromCache(CacheTag* cacheTag, uint32 hashCode, int size, bool& hasFound); + void AllocateBlockFromCacheWithSlotId(CacheSlotId_t slotId); + void WaitEvictSlot(CacheSlotId_t slotId); + + MgrCacheType m_cache_type; + HTAB* m_hash; + uint32 m_slot_length; + CacheDesc* m_CacheDesc; + + int m_CacheSlotsNum; /* total slot num */ + int m_CaccheSlotMax; /* used max slot id */ + + int64 m_cstoreMaxSize; + int64 m_cstoreCurrentSize; + + int m_freeListHead; + int m_freeListTail; + slock_t m_freeList_lock; + + int m_csweep; + LWLock *m_csweep_lock; + + int m_partition_lock; + + /* protect memory size counter */ + slock_t m_memsize_lock; +}; + +#endif // define diff -uprN postgresql-hll-2.14_old/include/storage/checksum.h postgresql-hll-2.14/include/storage/checksum.h --- postgresql-hll-2.14_old/include/storage/checksum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/checksum.h 2020-12-12 17:06:43.375349690 +0800 @@ -0,0 +1,26 @@ +/* --------------------------------------------------------------------------------------- + * + * checksum.h + * Checksum implementation for data pages. + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/storage/checksum.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CHECKSUM_H +#define CHECKSUM_H + +#include "storage/block.h" + +/* + * Compute the checksum for a Postgres page. The page must be aligned on a + * 4-byte boundary. + */ +extern uint16 pg_checksum_page(char* page, BlockNumber blkno); + +#endif /* CHECKSUM_H */ diff -uprN postgresql-hll-2.14_old/include/storage/checksum_impl.h postgresql-hll-2.14/include/storage/checksum_impl.h --- postgresql-hll-2.14_old/include/storage/checksum_impl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/checksum_impl.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,164 @@ +/* --------------------------------------------------------------------------------------- + * + * checksum_impl.h + * Checksum implementation for data pages. + * + * This file exists for the benefit of external programs that may wish to + * check Postgres page checksums. They can #include this to get the code + * referenced by storage/checksum.h. (Note: you may need to redefine + * Assert() as empty to compile this successfully externally.) + * + * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/storage/checksum_impl.h + * + * The algorithm used to checksum pages is chosen for very fast calculation. + * Workloads where the database working set fits into OS file cache but not + * into shared buffers can read in pages at a very fast pace and the checksum + * algorithm itself can become the largest bottleneck. + * + * The checksum algorithm itself is based on the FNV-1a hash (FNV is shorthand + * for Fowler/Noll/Vo). The primitive of a plain FNV-1a hash folds in data 1 + * byte at a time according to the formula: + * + * hash = (hash ^ value) * FNV_PRIME + * + * FNV-1a algorithm is described at http://www.isthe.com/chongo/tech/comp/fnv/ + * + * PostgreSQL doesn't use FNV-1a hash directly because it has bad mixing of + * high bits - high order bits in input data only affect high order bits in + * output data. To resolve this we xor in the value prior to multiplication + * shifted right by 17 bits. The number 17 was chosen because it doesn't + * have common denominator with set bit positions in FNV_PRIME and empirically + * provides the fastest mixing for high order bits of final iterations quickly + * avalanche into lower positions. For performance reasons we choose to combine + * 4 bytes at a time. The actual hash formula used as the basis is: + * + * hash = (hash ^ value) * FNV_PRIME ^ ((hash ^ value) >> 17) + * + * The main bottleneck in this calculation is the multiplication latency. To + * hide the latency and to make use of SIMD parallelism multiple hash values + * are calculated in parallel. The page is treated as a 32 column two + * dimensional array of 32 bit values. Each column is aggregated separately + * into a partial checksum. Each partial checksum uses a different initial + * value (offset basis in FNV terminology). The initial values actually used + * were chosen randomly, as the values themselves don't matter as much as that + * they are different and don't match anything in real data. After initializing + * partial checksums each value in the column is aggregated according to the + * above formula. Finally two more iterations of the formula are performed with + * value 0 to mix the bits of the last value added. + * + * The partial checksums are then folded together using xor to form a single + * 32-bit checksum. The caller can safely reduce the value to 16 bits + * using modulo 2^16-1. That will cause a very slight bias towards lower + * values but this is not significant for the performance of the + * checksum. + * + * The algorithm choice was based on what instructions are available in SIMD + * instruction sets. This meant that a fast and good algorithm needed to use + * multiplication as the main mixing operator. The simplest multiplication + * based checksum primitive is the one used by FNV. The prime used is chosen + * for good dispersion of values. It has no known simple patterns that result + * in collisions. Test of 5-bit differentials of the primitive over 64bit keys + * reveals no differentials with 3 or more values out of 100000 random keys + * colliding. Avalanche test shows that only high order bits of the last word + * have a bias. Tests of 1-4 uncorrelated bit errors, stray 0 and 0xFF bytes, + * overwriting page from random position to end with 0 bytes, and overwriting + * random segments of page with 0x00, 0xFF and random data all show optimal + * 2e-16 false positive rate within margin of error. + * + * Vectorization of the algorithm requires 32bit x 32bit -> 32bit integer + * multiplication instruction. As of 2013 the corresponding instruction is + * available on x86 SSE4.1 extensions (pmulld) and ARM NEON (vmul.i32). + * Vectorization requires a compiler to do the vectorization for us. For recent + * GCC versions the flags -msse4.1 -funroll-loops -ftree-vectorize are enough + * to achieve vectorization. + * + * The optimal amount of parallelism to use depends on CPU specific instruction + * latency, SIMD instruction width, throughput and the amount of registers + * available to hold intermediate state. Generally, more parallelism is better + * up to the point that state doesn't fit in registers and extra load-store + * instructions are needed to swap values in/out. The number chosen is a fixed + * part of the algorithm because changing the parallelism changes the checksum + * result. + * + * The parallelism number 32 was chosen based on the fact that it is the + * largest state that fits into architecturally visible x86 SSE registers while + * leaving some free registers for intermediate values. For future processors + * with 256bit vector registers this will leave some performance on the table. + * When vectorization is not available it might be beneficial to restructure + * the computation to calculate a subset of the columns at a time and perform + * multiple passes to avoid register spilling. This optimization opportunity + * is not used. Current coding also assumes that the compiler has the ability + * to unroll the inner loop to avoid loop overhead and minimize register + * spilling. For less sophisticated compilers it might be beneficial to + * manually unroll the inner loop. + * --------------------------------------------------------------------------------------- + */ + +#include "c.h" +#include "storage/bufpage.h" + +/* number of checksums to calculate in parallel */ +#define N_SUMS 32 +/* prime multiplier of FNV-1a hash */ +#define FNV_PRIME 16777619 + +static const uint32 CHECKSUM_CACL_ROUNDS = 2; + +/* + * Base offsets to initialize each of the parallel FNV hashes into a + * different initial state. + */ +static const uint32 g_checksumBaseOffsets[N_SUMS] = {0x5B1F36E9, + 0xB8525960, + 0x02AB50AA, + 0x1DE66D2A, + 0x79FF467A, + 0x9BB9F8A3, + 0x217E7CD2, + 0x83E13D2C, + 0xF8D4474F, + 0xE39EB970, + 0x42C6AE16, + 0x993216FA, + 0x7B093B5D, + 0x98DAFF3C, + 0xF718902A, + 0x0B1C9CDB, + 0xE58F764B, + 0x187636BC, + 0x5D7B3BB1, + 0xE73DE7DE, + 0x92BEC979, + 0xCCA6C0B2, + 0x304A0979, + 0x85AA43D4, + 0x783125BB, + 0x6CA8EAA2, + 0xE407EAC6, + 0x4B5CFC3E, + 0x9FBF8C76, + 0x15CA20BE, + 0xF2CA9FD3, + 0x959BD756}; + +/* + * Calculate one round of the checksum. + */ +#define CHECKSUM_COMP(checksum, value) \ + do { \ + uint32 __tmp = (checksum) ^ (value); \ + (checksum) = __tmp * FNV_PRIME ^ (__tmp >> 17); \ + } while (0) + +/* + * Block checksum algorithm. The data argument must be aligned on a 4-byte + * boundary. + */ +uint32 pg_checksum_block(char* data, uint32 size); + +uint16 pg_checksum_page(char* page, BlockNumber blkno); diff -uprN postgresql-hll-2.14_old/include/storage/compress_kits.h postgresql-hll-2.14/include/storage/compress_kits.h --- postgresql-hll-2.14_old/include/storage/compress_kits.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/compress_kits.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,468 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * compress_kits.h + * kits/tools/implement for compression methods + * + * + * IDENTIFICATION + * src/include/storage/compress_kits.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef COMPRESS_KITS_H +#define COMPRESS_KITS_H + +#include "c.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "zlib.h" + +enum BufMallocType { + Unknown, // buffer is not valid + FromMemCnxt, // buffer is from PG memory context + FromMemProt, // buffer is so big and from protect manager +}; + +typedef struct { + char* buf; + // remember the current buffer size. + Size bufSize; + BufMallocType bufType; +} BufferHelper; + +extern void BufferHelperMalloc(BufferHelper* p, Size s); +extern void BufferHelperRemalloc(BufferHelper* p, Size s); +extern void BufferHelperFree(BufferHelper* p); +void write_data_by_size(_in_ char* inbuf, unsigned int* pos, int64 data, const short size); +int64 read_data_by_size(_in_ char* inbuf, unsigned int* pos, short size); + +// when decompress some extra bytes are appended to the outbuf. +// +#define ZLIB_EXTRA_SIZE 30 + +/// Given the min-value and max-value, return how many bytes needed +/// to remember their difference value. it's byte bound. +extern inline short DeltaGetBytesNum(_in_ int64 mindata, _in_ int64 maxdata) +{ + Assert(mindata <= maxdata); + uint64 diff = maxdata - mindata; + + if ((0 == diff) || (1 == diff)) + return 1; // byte bound + + const uint64 masks[8] = {0x00000000000000FF, + 0x000000000000FF00, + 0x0000000000FF0000, + 0x00000000FF000000, + 0x000000FF00000000, + 0x0000FF0000000000, + 0x00FF000000000000, + 0xFF00000000000000}; + short i = 7; + while (0 == (diff & masks[i])) { + --i; + Assert(i >= 0); + } + return (i + 1); // byte bound +} + +/// judge whether delta can be applied to. +/// if so, store the needed bytes of difference value and return true. +/// otherwise, do nothing and return false. +extern inline bool DeltaCanBeApplied(short* deltaBytes, int64 minVal, int64 maxVal, short valueBytes) +{ + short dltBytes = DeltaGetBytesNum(minVal, maxVal); + if (dltBytes < valueBytes) { + *deltaBytes = dltBytes; + return true; + } + return false; +} + +/// get memory bound for Delta compression. +extern inline int DeltaGetBound(int nValues, short newSize) +{ + return (newSize * nValues); +} + +/// get memory bound for Delta compression. +extern inline int64 RleGetBound1(int inSize, short eachSize) +{ + Assert((eachSize >= (short)sizeof(int8)) && (eachSize <= (short)sizeof(int64))); + Assert(inSize % eachSize == 0); + return (1 + inSize + (((uint32)(inSize / eachSize)) >> 1)); +} + +/// get memory bound for Delta compression. +/// the same to RleGetBound1() but different means for +/// the first input argument. +extern inline int64 RleGetBound2(int nVals, short eachSize) +{ + Assert((eachSize >= (short)sizeof(int8)) && (eachSize <= (short)sizeof(int64))); + Assert(nVals > 0); + return (1 + (eachSize * nVals) + ((uint32)nVals >> 1)); +} + +// RleCoder compress && decompress +// +class RleCoder : public BaseObject { +public: + /// RLE_v1 constructor. + RleCoder(short oneValSize) + { + m_eachValSize = m_markersize = oneValSize; + m_minRepeats = RleMinRepeats_v1; + } + /// RLE_v2 constructor. + /// *minRepeats* is from *RleMinRepeats_v2* + RleCoder(short oneValSize, unsigned int minRepeats) + { + m_eachValSize = m_markersize = oneValSize; + m_minRepeats = minRepeats; + } + virtual ~RleCoder() + {} + + /* + * Given each value' size and input buffer' size, the upmost memory under the worst condition can be computed. + * so before RLE compression, get the upmost memory by calling CompressGetBound(). + * And caller should remember the size of raw data, pass that value during RLE decompressing. + * + * the common steps of compressing are: + * step1: RleCoder rel(each value size); + * step2: int64 outBufSize = rel.CompressGetBound(your input buffer size); + * step3: char* outBufPrt = (char*) malloc(outBufSize); + * step4: int results = rel.Compress(in, outBufPrt, insize, outBufSize); + * + * if results=0, that means raw data cannot be RLE compressed, and you should read + * raw data directly instead of outBufPtr. + * caller must check results returned, and this rule is also applied to Decompress. + */ + int Compress(_in_ char* inbuf, __inout char* outbuf, _in_ const int insize, _in_ const int outsize); + int Decompress(_in_ char* inbuf, __inout char* outbuf, _in_ const int insize, _in_ const int outsize); + + /* + * after RLE compression values has the following three storage formats: + * 1) plain values + * 2) RLE MARKER + REPEATS + SYMBOL (REPEATS >= RleMinRepeats) + * 3) RLE MARKER + REPEATS(1B) (REPEATS < RleMinRepeats) + * the first format doesn't expand extra memory. and the second format will save some memory. so + * that only the third format can expand and hold extra space. the worst case is like: + * ...... + * MARKER1 SYMBOL(NON-MARKER) + * MARKER1 SYMBOL(NON-MARKER) + * ...... + * ...... + * so we know the upmost memory is computed by: + * + * insize + (insize / m_eachValSize) * (1/2) + 1 + */ + FORCE_INLINE + int64 CompressGetBound(const int insize) + { + return RleGetBound1(insize, m_eachValSize); + } + +private: + template + void WriteNonRuns(char* outbuf, unsigned int* outpos, int64 symbol, unsigned int repeat = 1); + + template + void WriteRuns(char* outbuf, unsigned int* outpos, int64 symbol, unsigned int repeat); + +#ifdef USE_ASSERT_CHECKING + int16 NonRunsNeedSpace(bool equalToMarker, int16 repeats = 1); + int16 RunsNeedSpace(int16 repeats); +#endif + + template + int InnerCompress(char* inbuf, char* outbuf, const int insize, const int outsize); + + template + int InnerDecompress(char* inbuf, char* outbuf, const int insize, const int outsize); + +private: + /// RLE_v1 members start here. + short m_eachValSize; + short m_markersize; + /// RLE_v2 members start here. + unsigned int m_minRepeats; + +private: + /// RLE_v1 always uses the constant min-repeats, + /// which is defined by *RleMinRepeats_v1*. + static const int64 RleMarker[sizeof(int64) + 1]; + static const unsigned int RleMinRepeats_v1; + static const unsigned int RleMaxRepeats; + +public: + /// RLE_v2 uses different min-repeats for different + /// value size. it's just an optimization to + /// *RleMinRepeats_v1* in RLE_v1. + /// Don't worry about upgrading. they appear in different cases. + /// we can get better compression ratio from RLE_v2 than RLE_v1. + static const unsigned int RleMinRepeats_v2[sizeof(int64) + 1]; +}; + +class DeltaCoder : public BaseObject { +public: + // for Compress, extra means the max data. + // for Decompress, extra meas the size of decompressed data, or raw data size. + // + DeltaCoder(int64 mindata, int64 extra, bool willCompress); + virtual ~DeltaCoder() + {} + + // this method is shared by Compress and Decompress. it should be called ahead so that + // the memory needed is enough. + // + FORCE_INLINE uint64 GetBound(uint64 dataNum) + { + Assert(m_outValSize > 0); + return (m_outValSize * dataNum); + } + + // for Compress, min/max data are passed by constructor method, and the raw datasize + // is provided with of method Compress(). at the most case, compressed + // datasize is different from raw datasize, which is fetched by calling GetOutValSize() + // + int64 Compress(char* inbuf, char* outbuf, int insize, int outsize, short inDataSize); + FORCE_INLINE short GetOutValSize(void) + { + return m_outValSize; + } + + // for Decompress, mindata && uncompressed datasize are passed by constructor method. + // this method only just need compressed datasize, that's . + // + int64 Decompress(char* inbuf, char* outbuf, int insize, int outsize, short inDataSize); + +private: + template + int DoDeltaOperation(_in_ char* inbuf, _out_ char* outbuf, _in_ int insize, _in_ short outValSize); + + template + int doDeltaOperation(_in_ char* inbuf, _out_ char* outbuf, _in_ int insize); + + int64 m_mindata; +#ifdef USE_ASSERT_CHECKING + int64 m_maxdata; +#endif + short m_outValSize; +}; + +typedef uint16 DicCodeType; + +/* Dictionary Data In Disk + * + * m_totalSize: including this header and items data + * m_itemsCount: holds how many dictionary items after this header + * array of string data(items data) follows this header. + */ +typedef struct DictHeader { + uint32 m_totalSize; + uint32 m_itemsCount; +} DictHeader; + +/* + * Dictionary Data In Memory + * + * m_itemsMaxSize: the max size holding all items data. + * m_itemUsedSize: used size by items data, it must be <= m_itemsMaxSize. + * m_curItemCount: the count of current used slots. + * m_maxItemCount: + * for global dictionary, it is GLOBAL_DIC_SIZE. + * for local dictionary, it will be doubled once it is full; + * m_itemOffset: remembers offsets of each raw value in dict + * data[1]: includes two parts, + * (part 1) + * (part 2) indexes of the string data array, which size is m_maxItemCount*2, and the type is + * uint32 DicDataHashSlot[1]. 0xFFFF means available. + */ +typedef struct DictDataInMemory { + uint32 m_itemsMaxSize; + uint32 m_itemUsedSize; + DicCodeType m_maxItemCount; + DicCodeType m_curItemCount; + uint32* m_itemOffset; + DicCodeType* m_slots; + char* m_data; + DictHeader* m_header; +} DicData; + +// dictionary compress && decompress +// +class DicCoder : public BaseObject { +public: + virtual ~DicCoder(); + DictHeader* GetHeader(void) + { + return m_dictData.m_header; + } + + // compression methods + // + DicCoder(char* inBuf, int inSize, int numVals, int maxItemCnt); + DicCoder(int dataLen, int maxItemCnt); + + int CompressGetBound(void) const; + int Compress(_out_ char* outBuf); + + bool EncodeOneValue(_in_ Datum datum, _out_ DicCodeType& result); + + // decompression methods + // + DicCoder(char* dictInDisk); + int Decompress(char* inBuf, int inBufSize, char* outBuf, int outBufSize); + void DecodeOneValue(_in_ DicCodeType itemIndx, _out_ Datum* result) const; + +private: + int GetHashSlotsCount(void) + { + return (m_dictData.m_maxItemCount * 2); + } + int ComputeDictMaxSize(int itemsMaxSize, int itemsMaxCount) + { + return (sizeof(DictHeader) + itemsMaxSize + sizeof(DicCodeType) * (itemsMaxCount * 2)); + } + bool IsEnoughToAppend(int appendSize) + { + // both space size and item number must be enough to hold extra one + // + return (((m_dictData.m_itemUsedSize + appendSize) <= m_dictData.m_itemsMaxSize) && + (m_dictData.m_curItemCount < m_dictData.m_maxItemCount)); + } + + void InitDictData(int itemsMaxSize, int itemsMaxCount); + +private: + int m_dataLen; + char* m_inBuf; + int m_inSize; + int m_numVals; + DicData m_dictData; +}; + +// LZ4 && LZ4 HC compress and decompress +// +class LZ4Wrapper : public BaseObject { +public: + /* + * compression level is [0, 16] + * the more compression level, the better compression ratio, the lowest decompression; + * the least compression level, the worst compression ratio, the fastest decompression; + */ + static const int8 lz4_min_level = 0; + static const int8 lz4hc_min_level = 1; + static const int8 lz4hc_recommend_level = 9; + static const int8 lz4hc_level_step = 2; + static const int8 lz4hc_max_level = 16; + + typedef struct Lz4Header { + int rawLen; + int compressLen; + char data[FLEXIBLE_ARRAY_MEMBER]; + } Lz4Header; + +public: + LZ4Wrapper() : m_compressionLevel(LZ4Wrapper::lz4hc_min_level) + {} + virtual ~LZ4Wrapper() + {} + + void SetCompressionLevel(int8 level); + int CompressGetBound(int insize) const; + int Compress(const char* source, char* dest, int sourceSize) const; + + int DecompressGetBound(const char* source) const; + int DecompressGetCmprSize(const char* source) const; + int Decompress(const char* source, char* dest, int sourceSize) const; + +private: +#define SizeOfLz4Header offsetof(LZ4Wrapper::Lz4Header, data) + + bool Benefited(const int& outsize, const int& srcsize) const + { + return (outsize > 0 && (((int)SizeOfLz4Header + outsize) < srcsize)); + } + +private: + int8 m_compressionLevel; +}; + +// ZLIB compress && decompress +// +class ZlibEncoder : public BaseObject { +public: + /* the other compression level macro: + * Z_NO_COMPRESSION: no compress + * Z_DEFAULT_COMPRESSION: -1 + * Z_BEST_SPEED: + */ + static const int8 zlib_recommend_level = 6; + static const int8 zlib_max_level = Z_BEST_COMPRESSION; /* level 9 */ + static const int8 zlib_level_step = 1; + +public: + virtual ~ZlibEncoder(); + ZlibEncoder(); + + /* + * Solution 1: + * step 1: call Reset() to set input-buffer and size; + * step 2: char* outbuf[fixedSize]; outsize = fixedSize; + * step 2: done = false + * while ( !done && Compress(outbuf, outsize, done) >= 0 ) { + * store the compressed outbuf data; + * } + * handle the exception cases; + * + * Solution 2: + * step 1: call Reset() to set input-buffer and size; + * step 2: outsize = CompressGetBound(); so that the outsize is enough to Compress; + * char* outbuf = palloc(outsize); + * step 3: Compress(outbuf, outsize, done); Assert(true == done); + */ + void Prepare(int level = Z_DEFAULT_COMPRESSION); + void Reset(unsigned char* inbuf, const int insize); + int CompressGetBound(int insize); + int Compress(unsigned char* outbuf, const int outsize, bool& done); + +private: + z_stream m_strm; + int m_errno; + int m_flush; +}; + +class ZlibDecoder : public BaseObject { +public: + virtual ~ZlibDecoder(); + ZlibDecoder(); + + // step 1: call Prepare() first to set input buffer. + // step 2: call Decompress() again and again, until done is true, or returned value < 0, + // that means some errors happen. + // + int Prepare(unsigned char* inbuf, const int insize); + int Decompress(unsigned char* outbuf, const int outsize, bool& done, bool bufIsEnough = false); + +private: + z_stream m_strm; + int m_errno; + int m_flush; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/copydir.h postgresql-hll-2.14/include/storage/copydir.h --- postgresql-hll-2.14_old/include/storage/copydir.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/copydir.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * copydir.h + * Copy a directory. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/copydir.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COPYDIR_H +#define COPYDIR_H + +extern bool copydir(char* fromdir, char* todir, bool recurse, int elevel); +extern void copy_file(char* fromfile, char* tofile); +extern void copy_file_internal(char* fromfile, char* tofile, bool trunc_file); + +extern void fsync_fname(const char* fname, bool isdir); +extern int durable_rename(const char* oldfile, const char* newfile, int elevel); +extern int durable_link_or_rename(const char* oldfile, const char* newfile, int elevel); + +#endif /* COPYDIR_H */ diff -uprN postgresql-hll-2.14_old/include/storage/cstorealloc.h postgresql-hll-2.14/include/storage/cstorealloc.h --- postgresql-hll-2.14_old/include/storage/cstorealloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cstorealloc.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,139 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstorealloc.h + * + * + * + * IDENTIFICATION + * src/include/storage/cstorealloc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CSTORE_ALLOC_H +#define CSTORE_ALLOC_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/relfilenode.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "cstore.h" + +typedef struct { + uint64 beginOffset; + uint64 size; +} CStoreFreeSpaceDesc; + +typedef CFileNode CStoreColumnFileTag; +typedef CStoreFreeSpaceDesc CStoreSpaceDesc; + +#define DEFAULT_NUM_OF_FREE_SPACE_SLOTS 2000 +#define InvalidCStoreFreeSpace 0xffffffffffffffff +#define InvalidCStoreOffset InvalidCStoreFreeSpace +#define MinAvailableCStoreFSMSize 1024 + +/*Defines max number of holds in column. + * If there are too many holds, we should exec vacuum and do not use the free space. + */ +#define MaxNumOfHoleFSM (100 * 1024 * 1024 / 16) + +#define IsValidCStoreFreeSpaceDesc(desc) ((desc)->size != InvalidCStoreFreeSpace) + +extern Size CStoreAllocatorShmSize(); + +class CStoreFreeSpace : public BaseObject { +public: + CStoreFreeSpace(int maxSize) + { + Initialize(maxSize); + }; + CStoreFreeSpace() + { + Initialize(DEFAULT_NUM_OF_FREE_SPACE_SLOTS); + }; + virtual ~CStoreFreeSpace(); + virtual void Destroy(); + + void Push(_in_ const CStoreFreeSpaceDesc& desc); + + void PopDescWithMaxSize(_out_ CStoreFreeSpaceDesc& desc); + + void GetDescWithMaxSize(_out_ CStoreFreeSpaceDesc& desc); + + bool IsEmpty() + { + return m_descNum == 0; + } + + bool IsFull() + { + return m_descNum == m_maxSize; + } + + bool HasEnoughSpace(Size size); + +public: // STATIC METHODS + static void ComputeFreeSpace(_in_ AttrNumber attno, _in_ Relation cudescIndexRel, _in_ Relation cudescHeapRel, + __inout CStoreFreeSpace* fspace); + +private: + void Initialize(int maxSize); + + CStoreFreeSpaceDesc* m_descs; + int m_descNum; + int m_maxSize; +}; + +class CStoreAllocator : public BaseObject { + +private: + CStoreAllocator(); + virtual ~CStoreAllocator(); + +public: + static void InitColSpaceCache(void); + static void ResetColSpaceCache(void); + + static uint32 GetNextCUID(Relation rel); + + // Now we need lock the relation before acquire space. + static void LockRelForAcquireSpace(Relation rel); + + static void ReleaseRelForAcquireSpace(Relation rel); + + static uint32 AcquireFileSpace(const CFileNode& cnode, uint64 extend_offset, uint64 cu_offset, uint32 cu_size); + // Acquire space for CU + static uint64 AcquireSpace(const CFileNode& cnode, Size size, int align_size); + + // Acquire space for CU from free space + static uint64 TryAcquireSpaceFromFSM(CStoreFreeSpace* fsm, Size size, int align_size); + + // Invalid column cache + static void InvalidColSpaceCache(const CFileNode& cnode); + + static void BuildColSpaceCacheForRel(const CFileNode* cnodes, int nColumn, uint64* offsets, uint32 maxCUID); + static void BuildColSpaceCacheForRel( + _in_ Relation heapRel, _in_ AttrNumber* attrIds, _in_ int attrNum, _in_ List* btreeIndex = NIL); + + static bool ColSpaceCacheExist(const CFileNode* cnodes, int nColumn); + + static uint64 GetExtendOffset(uint64 max_offset); + static uint32 CalcExtendSize(uint64 cu_offset, uint32 cu_size, uint64 extend_offset); + static uint32 recheck_max_cuid(Relation m_rel, uint32 max_cuid, int index_num, Relation* m_idxRelation); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/cstore_compress.h postgresql-hll-2.14/include/storage/cstore_compress.h --- postgresql-hll-2.14_old/include/storage/cstore_compress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cstore_compress.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,388 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_compress.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cstore_compress.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GSCSTORE_COMPRESS_H +#define GSCSTORE_COMPRESS_H + +#include "storage/compress_kits.h" + +// CU_INFOMASK1 >>>> +// +#define CU_DeltaCompressed 0x0001 +#define CU_DicEncode 0x0002 +// CU_CompressExtend is used for extended compression. +// For compression added afterwards, it can be defined as CU_CompressExtend + 0x0001~0x0008 +#define CU_CompressExtend 0x0004 // Used for extended compression +#define CU_Delta2Compressed 0x0005 // CU_Delta2Compressed equals CU_CompressExtend plus 0x0001 +#define CU_XORCompressed 0x0006 // CU_XORCompressed equals CU_CompressExtend plus 0x0002 +#define CU_RLECompressed 0x0008 +#define CU_LzCompressed 0x0010 +#define CU_ZlibCompressed 0x0020 +#define CU_BitpackCompressed 0x0040 +#define CU_IntLikeCompressed 0x0080 + +extern bool NeedToRecomputeMinMax(Oid typeOid); +extern int64 ConvertToInt64Data(_in_ const char* inBuf, _in_ const short eachValSize); +extern void Int64DataConvertTo(_in_ int64 inVal, _in_ short eachValSize, _out_ char* outBuf); + +#define GLOBAL_DICT_SIZE 4096 + +/* compression filter. + * step 1: sample. use the first CU data to sample, and detect + * what compression methods to adopt; + * step 2: apply these filter to subsequent compressing. + */ +struct compression_options { + /* sampling flag */ + bool m_sampling_fihished; + + /* the followings are adopt-compression-method flags */ + + /* flags for numeric to integer */ + bool m_adopt_numeric2int_ascale_rle; + bool m_adopt_numeric2int_int32_rle; + bool m_adopt_numeric2int_int64_rle; + + /* common flags */ + bool m_adopt_dict; /* Dictionary encoding */ + bool m_adopt_rle; /* RLE encoding */ + + void reset(void); + void set_numeric_flags(uint16 modes); + void set_common_flags(uint32 modes); +}; + +// input arguments for compression && +// output arguments for decompression +// +typedef struct { + // shared var by both IntegerCoder && StringCoder + // + char* buf; + int sz; + /* compressing modes include compression and compress level. */ + int16 mode; + /* here int16 padding */ + + // only just for StringCoder, whether to use dictionary + // + void* globalDict; + int numVals; + bool useDict; + bool useGlobalDict; + bool buildGlobalDict; +} CompressionArg1; + +// output arguments for compression && +// input arguments for decompression +// +typedef struct { + char* buf; + int sz; + uint16 modes; +} CompressionArg2; + +class IntegerCoder : public BaseObject { +public: + virtual ~IntegerCoder() + {} + + IntegerCoder(short eachValSize); + void SetMinMaxVal(int64 min, int64 max); + int Compress(_in_ const CompressionArg1& in, _out_ CompressionArg2& out); + int Decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + + /* optimizing flags */ + bool m_adopt_rle; + +private: + void InsertMinMaxVal(char* buf, int* usedSize); + + /* inner implement for compress API */ + template + int CompressInner(const CompressionArg1& in, CompressionArg2& out); + +private: + // m_isValid = true, min/max is passed in by SetMinMaxVal(). + // m_isValid = false, min/max should be computed innerly. + // + int64 m_minVal; + int64 m_maxVal; + bool m_isValid; + short m_eachValSize; +}; + +class StringCoder : public BaseObject { +public: + virtual ~StringCoder() + {} + + StringCoder() : m_adopt_rle(true), m_adopt_dict(true), m_dicCodes(NULL), m_dicCodesNum(0) + {} + + int Compress(_in_ CompressionArg1& in, _in_ CompressionArg2& out); + int Decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + + /* optimizing flags */ + bool m_adopt_rle; + bool m_adopt_dict; + +private: + /* inner implement for compress api */ + template + int CompressInner(CompressionArg1& in, CompressionArg2& out); + + // compress/decompress directly using lz4/zlib but without global/local dictionary + // + int CompressWithoutDict(_in_ char* inBuf, _in_ int inBufSize, _in_ int compressing_modes, _out_ char* outBuf, + _in_ int outBufSize, _out_ int& mode); + int DecompressWithoutDict( + _in_ char* inBuf, _in_ int inBufSize, _in_ uint16 mode, _out_ char* outBuf, _out_ int outBufSize); + + int CompressNumbers( + _in_ int max, _in_ int compressing_modes, __inout char* outBuf, _in_ int outBufSize, _out_ uint16& mode); + void DecompressNumbers( + _in_ char* inBuf, _in_ int inBufSize, _in_ uint16 mode, _out_ char* outBuf, _in_ int outBufSize); + +private: + DicCodeType* m_dicCodes; + DicCodeType m_dicCodesNum; +}; + +/// light-weight implementation for Delta-RLE compression. +class DeltaPlusRLEv2 : public BaseObject { +public: + DeltaPlusRLEv2(int64 minVal, int64 maxVal, int32 nVals, short valueBytes) + { + m_minVal = minVal; + m_nValues = nVals; + m_valueBytes = valueBytes; + + /// m_maxVal is not used during decompression. + /// so that you can skip it. + m_maxVal = maxVal; + + /// m_deltaBytes will be updated later. + m_deltaBytes = valueBytes; + + m_adopt_rle = true; + } + virtual ~DeltaPlusRLEv2() + { /* don't create or destroy any resource. */ + } + + /// API about compressing. + int GetBound(); + int Compress(char** outBuf, int outBufSize, uint16* outModes, char* inBuf, int inBufSize); + + /// API about decompressing. + void SetDltValSize(short dltBytes) + { + /// if delta is used, m_deltaBytes < m_valueBytes. + /// otherwise, they should be equal to. + Assert(dltBytes < m_valueBytes); + m_deltaBytes = dltBytes; + } + int Decompress(char** outBuf, int outBufSize, char* inBuf, int inBufSize, uint16 modes); + + /* optimizing flags */ + bool m_adopt_rle; + +private: + int64 m_minVal; + int64 m_maxVal; + int32 m_nValues; + short m_valueBytes; + short m_deltaBytes; + + /* inner implement for compress API */ + template + int CompressInner(char** out, int outSize, uint16* outModes, char* in, int inSize); +}; + +/// +/// compress the batch of numeric +/// + +// int32 integer: +// ascales in [-2, 2] <--> encoding val [1, 5] +// int64 integer: +// ascales in [-4, 4] <--> encoding val [6, 14] +// we represent status codes with 4 bits, and 0 means that it +// fails to compress. so 15 is unused. +// +#define FAILED_ENCODING 0 +#define MAX_INT32_ASCALE_ENCODING 5 +#define MAX_INT64_ASCALE_ENCODING 14 +#define DIFF_INT32_ASCALE_ENCODING 3 +#define DIFF_INT64_ASCALE_ENCODING 10 + +// dsacle +// 2 bits flag for dscale encoding +#define NUMERIC_DSCALE_ENCODING 0 +#define INT32_DSCALE_ENCODING 1 +#define INT64_DSCALE_ENCODING 2 + +/// bit flags for NUMERIC compressed head info +#define NUMERIC_FLAG_EXIST_OTHERS 0x0001 +#define NUMERIC_FLAG_OTHER_WITH_LZ4 0x0002 +#define NUMERIC_FLAG_EXIST_INT32_VAL 0x0004 +#define NUMERIC_FLAG_INT32_SAME_VAL 0x0008 +#define NUMERIC_FLAG_INT32_SAME_ASCALE 0x0010 +#define NUMERIC_FLAG_INT32_WITH_DELTA 0x0020 +#define NUMERIC_FLAG_INT32_WITH_RLE 0x0040 +#define NUMERIC_FLAG_EXIST_INT64_VAL 0x0080 +#define NUMERIC_FLAG_INT64_SAME_VAL 0x0100 +#define NUMERIC_FLAG_INT64_SAME_ASCALE 0x0200 +#define NUMERIC_FLAG_INT64_WITH_DELTA 0x0400 +#define NUMERIC_FLAG_INT64_WITH_RLE 0x0800 +#define NUMERIC_FLAG_SCALE_WITH_RLE 0x1000 +/// notice: add new bit flag above +#define NUMERIC_FLAG_SIZE (2) // use byte as unit + +/// function type definition. +typedef void (*SetNullNumericFunc)(int which, void* memobj); + +/// struct type definition +typedef struct { + bool* success; /// treat null value as failed. + char* ascale_codes; + int64* int64_values; + int32* int32_values; + + int64 int64_minval; + int64 int64_maxval; + int32 int32_minval; + int32 int32_maxval; + int int64_n_values; + int int32_n_values; + int n_notnull; + int failed_cnt; + int failed_size; + + /// it's needed and used to malloc exact memory during decompressing. + int original_size; + + bool int64_ascales_are_same; + bool int64_values_are_same; + /// valid only when int64_ascales_are_same is true. + char int64_same_ascale; + bool int32_ascales_are_same; + bool int32_values_are_same; + /// valid only when int32_ascales_are_same is true. + char int32_same_ascale; +} numerics_statistics_out; + +typedef struct { + CompressionArg2 int64_out_args; + CompressionArg2 int32_out_args; + int int64_cmpr_size; + int int32_cmpr_size; + + char* other_srcbuf; + char* other_outbuf; + int other_cmpr_size; + bool other_apply_lz4; + + /* compression filter */ + compression_options* filter; +} numerics_cmprs_out; + +/// maybe these values cannot use any compression +/// method. so during decompression we can directly +/// access the memory of compressed data, needn't +/// to copy again, and reduce the number of memcpy() +/// calls. +typedef struct { + char* int64_addr_ref; + char* int32_addr_ref; + char* other_addr_ref; +} numerics_decmprs_addr_ref; + +typedef struct { + Datum* values; + char* nulls; /* nulls bitmap */ + int rows; + + /// *func* and *mobj* must be set if *hasNull* is true. + bool hasNull; + SetNullNumericFunc func; + /// the second argument of *func*. + void* mobj; +} BatchNumeric; + +/// configure the failed ratio. +/// valid value is 1~100. +extern void NumericConfigFailedRatio(int failed_ratio); + +/// given one batch of numeric values, try to compress them. +/// you must set both *setnull* if there are nulls. +/// return the not-exact size of compressed data if compress successfully. +/// otherwise return false, and *compressed_datasize* is undefined. +/// +extern bool NumericCompressBatchValues( + BatchNumeric* batch, numerics_statistics_out* out1, numerics_cmprs_out* out2, int* compressed_datasize, int align_size); + +/// copy the data after compress successfully. +extern char* NumericCopyCompressedBatchValues(char* ptr, numerics_statistics_out* out1, numerics_cmprs_out* out2); +extern void NumericCompressReleaseResource(numerics_statistics_out* statOut, numerics_cmprs_out* cmprOut); + +/// decompress APIs +extern char* NumericDecompressParseHeader( + char* ptr, uint16* out_flags, numerics_statistics_out* out1, numerics_cmprs_out* out2); +extern char* NumericDecompressParseAscales(char* ptr, numerics_statistics_out* out1, uint16 flags); +extern char* NumericDecompressParseEachPart( + char* ptr, numerics_statistics_out* out1, numerics_cmprs_out* out2, numerics_decmprs_addr_ref* out3); +extern char* NumericDecompressParseDscales(char* ptr, numerics_statistics_out* out1, uint16 flags); + +template +extern void NumericDecompressRestoreValues(char* outBuf, int typeMode, numerics_statistics_out* stat_out, + numerics_cmprs_out* cmpr_out, numerics_decmprs_addr_ref* in3); +extern void NumericDecompressReleaseResources( + numerics_statistics_out* decmprStatOut, numerics_cmprs_out* decmprOut, numerics_decmprs_addr_ref* addrRef); + +// fill bitmap according to values[n_values] +// bit should be set to 0 if it's equal to *valueIfUnset*, +// otherwise bit should be set to 1. +template +extern void FillBitmap(char* buf, const T* values, int nValues, T valueIfUnset) +{ + unsigned char* byteBuf = (unsigned char*)(buf - 1); + uint32 bitMask = HIGHBIT; + + for (int cnt = 0; cnt < nValues; ++cnt) { + if (bitMask != HIGHBIT) { + bitMask <<= 1; + } else { + byteBuf++; + *byteBuf = 0x00; + bitMask = 1; + } + if (valueIfUnset == values[cnt]) { + continue; + } + *byteBuf |= bitMask; + } +} +#endif diff -uprN postgresql-hll-2.14_old/include/storage/cstore_mem_alloc.h postgresql-hll-2.14/include/storage/cstore_mem_alloc.h --- postgresql-hll-2.14_old/include/storage/cstore_mem_alloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cstore_mem_alloc.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,76 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cstore_mem_alloc.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cstore_mem_alloc.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CSTORE_MEM_ALLOC_H +#define CSTORE_MEM_ALLOC_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#define MaxPointersArryLen 512U +#define MaxPtrNodeCacheLen 256U + +typedef struct PointerNode { + void* ptr; + PointerNode* next; + + void Reset() + { + ptr = NULL; + next = NULL; + } +} PointerNode; + +typedef struct PointerList { + PointerNode* header; + PointerNode* tail; +} NodeList; + +// CStoreMemAlloc +// It manages the memory pointer from malloc +// When transaction occurs erro, the memory from malloc can be reset in abortTransaction +// When transaction commit, the memory from malloc can be reset +// +class CStoreMemAlloc { +public: + static void* Palloc(Size size, bool toRegister = true); + static void Pfree(void* pointer, bool registered = true); + static void* Repalloc(void* pointer, Size size, Size old_size, bool registered = true); + static void Register(void* pointer); + static void Unregister(const void* pointer); + static void Reset(); + static void Init(); + +private: + static void* AllocPointerNode(); + static void FreePointerNode(PointerNode* pointer); + + static THR_LOCAL PointerList m_tab[MaxPointersArryLen]; + static THR_LOCAL uint64 m_count; + + static THR_LOCAL uint32 m_ptrNodeCacheCount; + static THR_LOCAL PointerNode* m_ptrNodeCache[MaxPtrNodeCacheLen]; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/cucache_mgr.h postgresql-hll-2.14/include/storage/cucache_mgr.h --- postgresql-hll-2.14_old/include/storage/cucache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cucache_mgr.h 2020-12-12 17:06:43.376349703 +0800 @@ -0,0 +1,176 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cucache_mgr.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cucache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CUCACHEMGR_H +#define CUCACHEMGR_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/relfilenode.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/hsearch.h" +#include "storage/lwlock.h" +#include "storage/spin.h" +#include "storage/shmem.h" +#include "storage/cu.h" +#include "storage/cache_mgr.h" +#include "storage/custorage.h" + +#define CUCache (DataCacheMgr::GetInstance()) +#define ORCCache (DataCacheMgr::GetInstance()) +#define OBSCache (DataCacheMgr::GetInstance()) + +int DataCacheMgrNumLocks(); + +// MAX_CACHE_TAG_LEN is max slot tag size +typedef struct CUSlotTag { + RelFileNodeOld m_rnode; + int m_colId; + int32 m_CUId; + uint32 m_padding; + CUPointer m_cuPtr; +} CUSlotTag; + +typedef struct ORCSlotTag { + RelFileNodeOld m_rnode; + int32 m_fileId; + uint64 m_offset; + uint64 m_length; +} ORCSlotTag; + +/* + * be careful, the length of OBSSlotTag + * shoud be <= 32 bytes. The + * max length is defined by macro + * MAX_CACHE_TAG_LEN. + */ +typedef struct OBSSlotTag { + uint32 m_serverHash; + uint32 m_bucketHash; + uint32 m_fileFirstHash; + uint32 m_fileSecondHash; + + uint64 m_offset; + uint64 m_length; +} OBSSlotTag; + +typedef union DataSlotTagKey { + CUSlotTag cuSlotTag; + ORCSlotTag orcSlotTag; + OBSSlotTag obsSlotTag; +} DataSlotTagKey; + +typedef struct DataSlotTag { + DataSlotTagKey slotTag; + CacheType slotType; +} DataSlotTag; + +typedef struct OrcDataValue { + void* value; + uint64 size; +} OrcDataValue; + +/* returned code about uncompressing CU data in CU cache */ +enum CUUncompressedRetCode { CU_OK = 0, CU_ERR_CRC, CU_ERR_MAGIC, CU_ERR_ADIO, CU_RELOADING, CU_ERR_MAX }; + +/* + * This class is to manage Data Cache. + * For integer CU, we should store compressed data. + * For string CU, because the speed of decompressing data is low, + * so store source data. + */ +class DataCacheMgr : public BaseObject { +public: + static DataCacheMgr* GetInstance(void); + static void NewSingletonInstance(void); + + DataSlotTag InitCUSlotTag(RelFileNodeOld* rnode, int colid, uint32 cuid, CUPointer cuPtr); + DataSlotTag InitORCSlotTag(RelFileNode* rnode, int32 fileid, uint64 offset, uint64 length); + DataSlotTag InitOBSSlotTag(uint32 hostNameHash, uint32 bucketNameHash, uint32 fileFirstHalfHash, + uint32 fileSecondHalfHash, uint64 offset, uint64 length) const; + CacheSlotId_t FindDataBlock(DataSlotTag* dataSlotTag, bool first_enter_block); + int ReserveDataBlock(DataSlotTag* dataSlotTag, int size, bool& hasFound); + bool ReserveDataBlockWithSlotId(int slotId); + bool ReserveCstoreDataBlockWithSlotId(int slotId); + CU* GetCUBuf(int cuSlotId); + OrcDataValue* GetORCDataBuf(int cuSlotId); + void UnPinDataBlock(int cuSlotId); + /* Manage I/O busy CUs */ + bool DataBlockWaitIO(int cuSlotId); + void DataBlockCompleteIO(int cuSlotId); + int64 GetCurrentMemSize(); + void PrintDataCacheSlotLeakWarning(CacheSlotId_t slotId); + + void AbortCU(CacheSlotId_t slot); + void TerminateCU(bool abort); + void TerminateVerifyCU(); + void InvalidateCU(RelFileNodeOld* rnode, int colId, uint32 cuId, CUPointer cuPtr); + void DropRelationCUCache(const RelFileNode& rnode); + CUUncompressedRetCode StartUncompressCU(CUDesc* cuDescPtr, CacheSlotId_t slotId, int planNodeId, bool timing, int align_size); + + // async lock used by adio + bool CULWLockHeldByMe(CacheSlotId_t slotId); + void CULWLockOwn(CacheSlotId_t slotId); + void CULWLockDisown(CacheSlotId_t slotId); + + void LockPrivateCache(); + void UnLockPrivateCache(); + + void SetORCDataBlockValue(CacheSlotId_t slotId, const void* buffer, uint64 size); + void SetOBSDataBlockValue( + CacheSlotId_t slotId, const void* buffer, uint64 size, const char* prefix, const char* dataDNA); + + void AcquireCompressLock(CacheSlotId_t slotId); + void RealeseCompressLock(CacheSlotId_t slotId); + + int64 m_cstoreMaxSize; + +#ifndef ENABLE_UT +private: +#endif // ENABLE_UT + + DataCacheMgr() + {} + ~DataCacheMgr() + {} + + static DataCacheMgr* m_data_cache; + CacheMgr* m_cache_mgr; + slock_t m_adio_write_cache_lock; // write private cache, not cucache. I add here because spinlock need init once + // for cstore module +}; + +/* interface for orc data read */ +void ReleaseORCBlock(CacheSlotId_t slot); +CacheSlotId_t ORCCacheAllocBlock( + RelFileNode* rnode, int32 fileid, uint64 offset, uint64 length, bool& found, bool& err_found); +CacheSlotId_t OBSCacheAllocBlock(const char* hostName, const char* bucketName, const char* prefixName, uint64 offset, + uint64 length, bool& found, bool& err_found); +bool OBSCacheRenewBlock(CacheSlotId_t slotID); +OrcDataValue* ORCCacheGetBlock(CacheSlotId_t slot); +void ORCCacheSetBlock(CacheSlotId_t slotId, const void* buffer, uint64 size); +void OBSCacheSetBlock(CacheSlotId_t slotId, const void* buffer, uint64 size, const char* prefix, const char* dataDNA); + +#endif // define diff -uprN postgresql-hll-2.14_old/include/storage/cu.h postgresql-hll-2.14/include/storage/cu.h --- postgresql-hll-2.14_old/include/storage/cu.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/cu.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,549 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cu.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/cu.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CU_H +#define CU_H + +#include "vecexecutor/vectorbatch.h" +#include "cstore.h" +#include "storage/cstore_mem_alloc.h" +#include "utils/datum.h" +#include "storage/lwlock.h" + + +#define ATT_IS_CHAR_TYPE(atttypid) (atttypid == BPCHAROID || atttypid == VARCHAROID || atttypid == NVARCHAR2OID) +#define ATT_IS_NUMERIC_TYPE(atttypid) (atttypid == NUMERICOID) + +// max uint64 value length 19, set 24 for 8 bit align +#define MAX_LEN_CHAR_TO_BIGINT_BUF (24) +#define MAX_LEN_CHAR_TO_BIGINT (19) + +// CU size always is alligned to ALIGNOF_CU +// + +// ADIO requires minimum CU size of 8192 and 512 block alignment +#define ALIGNOF_CUSIZE (8192) +#define ALIGNOF_TIMESERIES_CUSIZE (2) + +enum {TS_COLUMN_ID_BASE = 2000}; + +#define ALLIGN_CUSIZE2(_LEN) TYPEALIGN(2, (_LEN)) +#define ALIGNOF_CUSIZE512(_LEN) TYPEALIGN(512, (_LEN)) +#define ALLIGN_CUSIZE32(_LEN) TYPEALIGN(32, (_LEN)) +#define ALLIGN_CUSIZE(_LEN) TYPEALIGN(ALIGNOF_CUSIZE, (_LEN)) + +#define ASSERT_CUSIZE(_LEN) \ + Assert((_LEN) == ALLIGN_CUSIZE(_LEN) || (_LEN) == ALLIGN_CUSIZE32(_LEN) \ + || (_LEN) == ALIGNOF_CUSIZE512(_LEN) || (_LEN) == ALLIGN_CUSIZE2(_LEN)) + +class CUAlignUtils { +public: + static uint32 AlignCuSize(int len, int align_size); + static int GetCuAlignSizeColumnId(int columnId); +}; + +#define PADDING_CU(_PTR, _LEN) \ + do { \ + char* p = (char*)(_PTR); \ + int len = (_LEN); \ + for (int i = 0; i < len; ++i, ++p) \ + *p = 0; \ + } while (0) + +#define MIN_MAX_LEN 32 + +// CU_INFOMASK1 has all the compression mode info. +// CU_INFOMASK2 has the other data attribute info. +// +#define CU_INFOMASK1 0x00FF +#define CU_INFOMASK2 0xFF00 + +// CU_INFOMASK1 is in file storage/cstore_compress.h +// CU_INFOMASK2 is working for the following +// +#define CU_DSCALE_NUMERIC 0x0100 // flag for numeric dscale compress +#define CU_HasNULL 0x0400 +// indicate that this CRC is just one magic data, and +// CRC computation can be ignored during query. +#define CU_IgnoreCRC 0x0800 +// using CRC32C for checksum +#define CU_CRC32C 0x1000 +// CU is encrypt +#define CU_ENCRYPT 0x2000 + +// the CU_mode of CUDesc +// +#define CU_NORMAL 0x01 +#define CU_FULL_NULL 0x02 +#define CU_SAME_VAL 0x03 +#define CU_NO_MINMAX_CU 0x04 +#define CU_HAS_NULL 0x08 + +// The mask of CU_NORMAL, CU_FULL_NULL, +// CU_SAME_VAL, CU_NO_MINMAX_CU +// +#define CU_MODE_LOWMASK 0x0f + +// how many bits are set 1 in an unsigned byte +// +const uint8 NumberOfBit1Set[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, + 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, + 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, + 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, + 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, + 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, + 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; + +struct CUDesc : public BaseObject { + TransactionId xmin; + /* + * serial-number of CU + */ + uint32 cu_id; + + // The min value of CU + // If type is fixed-length, cu_min stores the value. + // If type is variable-length, cu_min store len and value + // Format: len (1byte) value (len <= MIN_MAX_LEN) + // + char cu_min[MIN_MAX_LEN]; + + // The max value of CU + // If type is fixed-length, cu_max store the value. + // If type is variable-length, cu_max store len and value + // Format: len (1byte) value (len <= MIN_MAX_LEN) + // + char cu_max[MIN_MAX_LEN]; + + /* + * The row number of CU + */ + int row_count; + + /* + * The CU data size + */ + int cu_size; + + /* + * The CU information mask + */ + int cu_mode; + + /* + * The pointer of CU in CU Storage + */ + CUPointer cu_pointer; + + /* + * magic number is used to check CU Data valid + */ + uint32 magic; + +public: + CUDesc(); + ~CUDesc(); + + void SetNullCU(); + bool IsNullCU() const; + void SetNormalCU(); + void SetSameValCU(); + bool IsNormalCU() const; + bool IsSameValCU() const; + void SetNoMinMaxCU(); + bool IsNoMinMaxCU() const; + void SetCUHasNull(); + bool CUHasNull() const; + + void Reset(); + void Destroy() + {} +}; + +/* temp info about CU compression + * because CU data cache exists, we should control used memory and + * reduce as much as possible. So all temp data during compressing + * will be placed together. + */ +struct cu_tmp_compress_info { + /* CU compression options, which type is compression_options */ + void* m_options; + + /* min/max value for integer compression. + * m_valid_minmax indicates whether the two are valid. + */ + int64 m_min_value; + int64 m_max_value; + bool m_valid_minmax; +}; + +/* CU struct: + * before compressing + * + * +------------------------+ <-- m_srcBuf - + * | | | + * | Header Info | m_srcBufSize + * | | | + * +------------------------+ <-- m_nulls - | + * | | | | + * | Null Bitmap | m_bpNullRawSize | + * | | | | + * +------------------------+ <-- m_srcData - | + * | | | | + * | Compressed Data | m_srcDataSize | + * | | | | + * +------------------------+ - | + * | Padding Data | | + * +------------------------+ - + */ +class CU : public BaseObject { +public: + /* Source buffer: nulls bitmap + source data. */ + char* m_srcBuf; + + /* The pointer of Null value in m_srcBuf. */ + unsigned char* m_nulls; + + /* The pointer of source data in m_srcBuf. */ + char* m_srcData; + + /* Compressed buffer: compressed header + compressed data */ + char* m_compressedBuf; + + /* support with accessing datum randomly after loading CU data */ + int32* m_offset; + + /* temp info about CU compression */ + cu_tmp_compress_info* m_tmpinfo; + + /* adio load cu, compressbuf + padding */ + char* m_compressedLoadBuf; + int m_head_padding_size; + + /* the number of m_offset items */ + int32 m_offsetSize; + + /* source buffer size. */ + uint32 m_srcBufSize; + + /* source data size */ + uint32 m_srcDataSize; + + /* Compressed buffer size */ + uint32 m_compressedBufSize; + + /* CU size, including padding data */ + uint32 m_cuSize; + + /* compressed CU size, excluding padding data */ + uint32 m_cuSizeExcludePadding; + + /* CRC check code */ + uint32 m_crc; + + /* magic number is used to check CU Data valid */ + uint32 m_magic; + + /* some information for compressing integer type + * m_eachValSize: the size of each value. -1 or -2 means varlena type. + * m_typeMode: type mode from attribute' typmode. for numeric it has + * precision and scale info. + */ + int m_eachValSize; + int m_typeMode; + + /* + * Nulls Bitmap Size about compressed && uncompressed + * m_bpNullCompressedSize is 0 if the CU has no Nulls. + * otherwise, it's stored in CU header. see FillCompressBufHeader(). + * m_bpNullRawSize can be computed if row count is given. + * it's initialized by InitMem(). + */ + uint16 m_bpNullRawSize; + uint16 m_bpNullCompressedSize; + + /* + * Some information. + * whether has NULL value, compressed mode and so on. + */ + uint16 m_infoMode; + + /* column type id , used for distinguish char and varchar */ + uint32 m_atttypid; + + bool m_adio_error; /* error occur in ADIO mode */ + bool m_cache_compressed; /* describe whether CU compressed in CU cache or not, + * ADIO load cu into memory which compressed, + * when scan use the CU, it should compress first. + */ + bool m_inCUCache; /* whether in CU cache */ + + bool m_numericIntLike; /* whether all data in the numeric CU can be transformed to Int64 */ + +public: + CU(); + CU(int typeLen, int typeMode, uint32 atttypid); + ~CU(); + void Destroy(); + + /* + * Check CRC code + */ + bool CheckCrc(); + + /* + * Generate CRC code + */ + uint32 GenerateCrc(uint16 info_mode) const; + + /* + * Append value + */ + void AppendValue(Datum val, int size); + + /* + * Append value + */ + void AppendValue(const char* val, int size); + + /* + * Append Null value + */ + void AppendNullValue(int row); + + static void AppendCuData(_in_ Datum value, _in_ int repeat, _in_ Form_pg_attribute attr, __inout CU* cu); + + // Compress data + // + int16 GetCUHeaderSize(void) const; + void Compress(int valCount, int16 compress_modes, int align_size); + void FillCompressBufHeader(void); + char* CompressNullBitmapIfNeed(_in_ char* buf); + bool CompressData(_out_ char* outBuf, _in_ int nVals, _in_ int16 compressOption, int align_size); + + // Uncompress data + // + char* UnCompressHeader(_in_ uint32 magic, int align_size); + void UnCompress(_in_ int rowCount, _in_ uint32 magic, int align_size); + char* UnCompressNullBitmapIfNeed(const char* buf, int rowCount); + void UnCompressData(_in_ char* buf, _in_ int rowCount); + template + void UncompressNumeric(char* inBuf, int nNotNulls, int typmode); + + // access datum randomly in CU + // + template + void FormValuesOffset(int rows); + + template + ScalarValue GetValue(int rowIdx); + + /* + * CU to Vector + */ + template + int ToVector(_out_ ScalarVector* vec, _in_ int leftRows, _in_ int rowCursorInCU, __inout int& curScanPos, + _out_ int& deadRows, _in_ uint8* cuDelMask); + + /* + * CU to Vector + */ + template + int ToVectorT(_out_ ScalarVector* vec, _in_ int leftRows, _in_ int rowCursorInCU, __inout int& curScanPos, + _out_ int& deadRows, _in_ uint8* cuDelMask); + + template + int ToVectorLateRead(_in_ ScalarVector* tids, _out_ ScalarVector* vec); + + // GET method is used to set the CUDesc info after compressing CU. + // SET method is used to set the CU info during decompressing CU data. + // + int GetCUSize() const; + void SetCUSize(int cuSize); + + int GetCompressBufSize() const; + + int GetUncompressBufSize() const; + + bool CheckMagic(uint32 magic) const; + void SetMagic(uint32 magic); + uint32 GetMagic() const; + + bool IsVerified(uint32 magic); + + /* + * Is NULL value + */ + bool IsNull(uint32 row) const; + + /* + * The number of NULL before rows. + */ + int CountNullValuesBefore(int rows) const; + + void FreeCompressBuf(); + void FreeSrcBuf(); + + void Reset(); + void SetTypeLen(int typeLen); + void SetTypeMode(int typeMode); + void SetAttTypeId(uint32 atttypid); + void SetAttInfo(int typeLen, int typeMode, uint32 atttypid); + bool HasNullValue() const; + + void InitMem(uint32 initialSize, int rowCount, bool hasNull); + void ReallocMem(Size size); + + template + void FreeMem(); + + /* timeseries function */ + void copy_nullbuf_to_cu(const char* bitmap, uint16 null_size); + uint32 init_field_mem(const int reserved_cu_byte); + uint32 init_time_mem(const int reserved_cu_byte); + void check_cu_consistence(const CUDesc* cudesc) const; + +private: + template + void DeFormNumberStringCU(); + + bool IsNumericDscaleCompress() const; + + // encrypt cu data + void CUDataEncrypt(char* buf); + // decrypt cu data + void CUDataDecrypt(char* buf); +}; + +template +ScalarValue CU::GetValue(int rowIdx) +{ + // Notice: this function don't handle the case where it's a + // NULL value. caller must be sure this prerequisite. + Assert(!(HasNullValue() && IsNull(rowIdx))); + Assert(!hasNull || (hasNull && m_offset && m_offsetSize > 0)); + + ScalarValue destVal; + switch (attlen) { + case sizeof(uint8): { + if (!hasNull) + destVal = *((uint8*)m_srcData + rowIdx); + else + destVal = *(uint8*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint16): { + if (!hasNull) + destVal = *((uint16*)m_srcData + rowIdx); + else + destVal = *(uint16*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint32): { + if (!hasNull) + destVal = *((uint32*)m_srcData + rowIdx); + else + destVal = *(uint32*)(m_srcData + m_offset[rowIdx]); + break; + } + case sizeof(uint64): { + if (!hasNull) + destVal = *((uint64*)m_srcData + rowIdx); + else + destVal = *(uint64*)(m_srcData + m_offset[rowIdx]); + break; + } + case 12: { + if (!hasNull) + destVal = (ScalarValue)((uint8*)m_srcData + (12 * rowIdx)); + else + destVal = (ScalarValue)(m_srcData + m_offset[rowIdx]); + break; + } + case 16: { + if (!hasNull) + destVal = (ScalarValue)((uint8*)m_srcData + (16 * rowIdx)); + else + destVal = (ScalarValue)(m_srcData + m_offset[rowIdx]); + break; + } + case -1: + case -2: + destVal = (ScalarValue)((uint8*)m_srcData + m_offset[rowIdx]); + break; + default: + ereport(ERROR, (errmsg("unsupported datatype branch"))); + break; + } + return destVal; +} + +template +void CU::FreeMem() +{ + if (this->m_srcBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_srcBuf, !this->m_inCUCache); + } else { + free(this->m_srcBuf); + } + this->m_srcBuf = NULL; + this->m_srcBufSize = 0; + } + if (this->m_compressedLoadBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_compressedLoadBuf, !this->m_inCUCache); + } else { + free(this->m_compressedLoadBuf); + } + this->m_compressedBuf = NULL; + this->m_compressedBufSize = 0; + this->m_compressedLoadBuf = NULL; + this->m_head_padding_size = 0; + } else { + if (this->m_compressedBuf) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_compressedBuf, !this->m_inCUCache); + } else { + free(this->m_compressedBuf); + } + this->m_compressedBuf = NULL; + this->m_compressedBufSize = 0; + this->m_compressedLoadBuf = NULL; + this->m_head_padding_size = 0; + } + } + if (this->m_offset) { + if (!freeByCUCacheMgr) { + CStoreMemAlloc::Pfree(this->m_offset, !this->m_inCUCache); + } else { + free(this->m_offset); + } + this->m_offset = NULL; + this->m_offsetSize = 0; + } +} + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/custorage.h postgresql-hll-2.14/include/storage/custorage.h --- postgresql-hll-2.14_old/include/storage/custorage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/custorage.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,172 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * custorage.h + * routines to support ColStore + * + * + * IDENTIFICATION + * src/include/storage/custorage.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef CU_STORAGE_H +#define CU_STORAGE_H + +#include "storage/cu.h" +#include "storage/relfilenode.h" +#include "storage/fd.h" +#include "storage/cstorealloc.h" + +class CUFile; + +class CUStorage : public BaseObject { +public: + CUStorage(const CFileNode& cFileNode, CStoreAllocateStrategy strategy = APPEND_ONLY); + virtual ~CUStorage(); + virtual void Destroy(); + + friend class CUFile; + + // Write CU data into storage + // + void SaveCU(_in_ char* write_buf, _in_ uint64 offset, _in_ int size, bool direct_flag, bool for_extension = false); + + void OverwriteCU( + _in_ char* write_buf, _in_ uint64 offset, _in_ int size, bool direct_flag, bool for_extension = false); + + // Load CU data from storage + // + void LoadCU(_in_ CU* cuPtr, _in_ uint64 offset, _in_ int size, bool direct_flag, bool inCUCache); + + void RemoteLoadCU(_in_ CU* cuPtr, _in_ uint64 offset, _in_ int size, bool direct_flag, bool inCUCache); + + // Load data from file into outbuf + // + void Load(_in_ uint64 offset, _in_ int size, __inout char* outbuf, bool direct_flag); + + int WSLoad(_in_ uint64 offset, _in_ int size, __inout char* outbuf, bool direct_flag); + + void GetFileName(_out_ char* fileName, _in_ const size_t capacity, _in_ const int fileId) const; + bool IsDataFileExist(int fileId) const; + + void GetBcmFileName(_out_ char* bcmfile, _in_ int fileId) const; + bool IsBcmFileExist(_in_ int fileId) const; + + const char* GetColumnFileName() const; + + uint64 AllocSpace(_in_ int size); + + void FlushDataFile() const; + + void SetAllocateStrategy(CStoreAllocateStrategy strategy) + { + m_strategy = strategy; + }; + + void SetFreeSpace(CStoreFreeSpace* fspace) + { + Assert(fspace != NULL); + m_freespace = fspace; + }; + + FORCE_INLINE CStoreFreeSpace* GetFreeSpace() + { + return m_freespace; + }; + + void CreateStorage(int fileId, bool isRedo) const; + + File GetCUFileFd(uint64 offset); + uint64 GetCUOffsetInFile(uint64 offset) const; + bool IsCUStoreInOneFile(uint64 offset, int size) const; + uint64 GetAlignCUOffset(uint64 offset) const; + int GetAlignCUSize(int size) const; + void FastExtendFile(uint64 extend_offset, uint32 size, bool keep_size); + void TruncateDataFile(); + void TruncateBcmFile(); + void Set2ByteAlign(bool is_2byte_align); + bool Is2ByteAlign(); + +private: + void InitFileNamePrefix(_in_ const CFileNode& cFileNode); + File CreateFile(_in_ char* file_name, _in_ int fileId, bool isRedo) const; + File OpenFile(_in_ char* file_name, _in_ int fileId, bool direct_flag); + File WSOpenFile(_in_ char* file_name, _in_ int fileId, bool direct_flag); + void InitCstoreFreeSpace(CStoreAllocateStrategy strategy); + void CloseFile(_in_ File fd) const; + +public: + CFileNode m_cnode; + +private: + // The common prefix of column file name + char m_fileNamePrefix[MAXPGPATH]; + + // The column file name + char m_fileName[MAXPGPATH]; + + // free space alloctor. + CStoreFreeSpace* m_freespace; + + // Currently read/write fd + File m_fd; + + // allocate strategy: append; reuse + CStoreAllocateStrategy m_strategy; + + bool append_only; + + bool is_2byte_align; +}; + +// Notice: the following functions are in physical/low level. +// they don't know CU's concept, and just load data from file. +// +class CUFile : public BaseObject { +public: + CUFile(const RelFileNode& fileNode, int col); + virtual void Destroy(); + virtual ~CUFile(); + char* Read(uint64 offset, int wantSize, int* realSize, int align_size); + +private: + CUStorage* m_colStorage; + +// private buffer +// +#define CUFILE_MAX_BUF_SIZE (512 * 1024) + char* m_buffer; + int m_maxpos; + + // we have to remember the total size and current offset about the physical file. + // that's because neither CU nor CU desc exists, and we cannot know the valid + // offset and size to read. + // + int m_fileId; + uint32 m_maxFileSize; + uint32 m_curFileOffset; +}; + +extern uint64 GetColDataFileSize(Relation rel, int attid); + +extern const uint64 MAX_FILE_SIZE; +// get file id and offset in this file +#define CU_FILE_ID(__pos) ((__pos) / MAX_FILE_SIZE) +#define CU_FILE_OFFSET(__pos) ((__pos) % MAX_FILE_SIZE) + +#define relcolpath(custorage_ptr) ((custorage_ptr)->GetColumnFileName()) + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/dfs/dfscache_mgr.h postgresql-hll-2.14/include/storage/dfs/dfscache_mgr.h --- postgresql-hll-2.14_old/include/storage/dfs/dfscache_mgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/dfs/dfscache_mgr.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfscache_mgr.h + * routines to support dfs + * + * + * IDENTIFICATION + * src/include/storage/dfs/dfscache_mgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef METACACHEMGR_H +#define METACACHEMGR_H + +#include +#include "orc_proto.pb.h" +#include "storage/cache_mgr.h" +#include "storage/relfilenode.h" + +#define MetaCache (MetaCacheMgr::GetInstance()) + +typedef struct OrcMetadataTag { + RelFileNodeOld fileNode; + int32 fileID; + uint32 stripeID; + uint32 columnID; + uint64 padding; +} OrcMetadataTag; + +typedef struct OrcMetadataValue { + /* + * The value of element pointer could be de-referenced into 'DfsInsert *' or + * 'PartitionStagingFile *' + */ + /* type 1 metadeta, file level, only need relID,fileID */ + uint64 footerStart; + std::string* postScript; + std::string* fileFooter; + + /* type 2 metadata, column and stripe level */ + std::string* stripeFooter; + std::string* rowIndex; + + int size; + + /* used in OBS file */ + char* fileName; + + /* data DNA, used in OBS foreign table file */ + char* dataDNA; +} OrcMetadataValue; + +typedef struct CarbonMetadataTag { + RelFileNodeOld fileNode; + int32 fileID; + uint32 BlockletID; + uint32 columnID; + uint64 padding; +} CarbonMetadataTag; + +typedef struct CarbonMetadataValue { + /* type 1 metadeta, file level, only need relID,fileID */ + uint64 headerSize; + uint64 footerSize; + unsigned char* fileHeader; + unsigned char* fileFooter; + + uint64 size; + + /* used in OBS file */ + char* fileName; + + /* data DNA, used in OBS foreign table file */ + char* dataDNA; +} CarbonMetadataValue; + +typedef union MetadataTag { + OrcMetadataTag OrcMetaTag; + CarbonMetadataTag CarbonMetaTag; +} MetadataTag; + +typedef struct MetadataTagKey { + CacheType type; + MetadataTag key; +} MetadataTagKey; + +/* Partition search cache support */ +typedef struct OrcMetadataEntry { + /* key of cache entry */ + OrcMetadataTag key; + int32 slot_id; +} OrcMetadataEntry; + +int MetaCacheMgrNumLocks(); +void ReleaseMetaBlock(CacheSlotId_t slotId); +bool MetaCacheRenewBlock(CacheSlotId_t slotId); +OrcMetadataValue* OrcMetaCacheGetBlock(CacheSlotId_t slotId); +CarbonMetadataValue* CarbonMetaCacheGetBlock(CacheSlotId_t slotId); +int OrcMetaCacheGetBlockSize(CacheSlotId_t slotId); +int CarbonMetaCacheGetBlockSize(CacheSlotId_t slotId); +void MetaCacheSetBlockWithFileName(CacheSlotId_t slotId, const char* fileName); +CacheSlotId_t MetaCacheAllocBlock( + RelFileNodeOld* fileNode, int32 fileID, uint32 stripeOrBlocketID, uint32 columnID, bool& found, int type); +void OrcMetaCacheSetBlock(CacheSlotId_t slotId, uint64 footerStart, const orc::proto::PostScript* postScript, + const orc::proto::Footer* fileFooter, const orc::proto::StripeFooter* stripeFooter, + const orc::proto::RowIndex* rowIndex, const char* fileName, const char* dataDNA); +void CarbonMetaCacheSetBlock(CacheSlotId_t slotId, uint64 headerSize, uint64 footerSize, unsigned char* fileHeader, + unsigned char* fileFooter, const char* fileName, const char* dataDNA); + +class MetaCacheMgr : public BaseObject { +public: + virtual ~MetaCacheMgr() + {} + static MetaCacheMgr* GetInstance(void); + static void NewSingletonInstance(void); + bool ReserveMetaBlockWithSlotId(CacheSlotId_t slotId); + void UnPinMetaBlock(CacheSlotId_t slotId); + + int64 GetCurrentMemSize(); + + void AbortMetaBlock(CacheSlotId_t slotId); + /* Manage I/O busy CUs */ + bool MetaBlockWaitIO(int slotId); + void MetaBlockCompleteIO(int slotId); + int GetOrcMetaBlockSize(CacheSlotId_t slotId); + int GetCarbonMetaBlockSize(CacheSlotId_t slotId); + void SetOrcMetaBlockValue(CacheSlotId_t slotId, uint64 footerStart, const orc::proto::PostScript* postScript, + const orc::proto::Footer* fileFooter, const orc::proto::StripeFooter* stripeFooter, + const orc::proto::RowIndex* rowIndex, const char* fileName, const char* dataDNA); + void SetCarbonMetaBlockValue(CacheSlotId_t slotId, uint64 headerSize, uint64 footerSize, unsigned char* fileHeader, + unsigned char* fileFooter, const char* fileName, const char* dataDNA); + + CacheSlotId_t FindMetaBlock(CacheTag cacheTag); + OrcMetadataValue* GetOrcMetaBlock(CacheSlotId_t slotId); + CarbonMetadataValue* GetCarbonMetaBlock(CacheSlotId_t slotId); + CacheSlotId_t ReserveMetaBlock(CacheTag cacheTag, bool& hasFound); + void PrintMetaCacheSlotLeakWarning(CacheSlotId_t slotId); + void ReleaseMetadataValue(CarbonMetadataValue* nvalue); + OrcMetadataTag InitOrcMetadataTag(RelFileNodeOld* fileNode, int32 fileID, uint32 stripeID, uint32 columnID); + CarbonMetadataTag InitCarbonMetadataTag(RelFileNodeOld* fileNode, int32 fileID, uint32 stripeID, uint32 columnID); + int64 m_cstoreMaxSize; + +private: + MetaCacheMgr() + {} + int CalcOrcMetaBlockSize(OrcMetadataValue* nvalue) const; + int CalcCarbonMetaBlockSize(CarbonMetadataValue* nvalue) const; + void SetOrcMetaBlockSize(CacheSlotId_t slotId, int size); + void SetCarbonMetaBlockSize(CacheSlotId_t slotId, int size); + void ReleaseOrcMetadataValue(OrcMetadataValue* nvalue) const; + void ReleaseCarbonMetadataValue(CarbonMetadataValue* nvalue) const; + static MetaCacheMgr* m_meta_cache; + CacheMgr* m_cache_mgr; +}; + +#endif /* define */ diff -uprN postgresql-hll-2.14_old/include/storage/dfs/dfs_connector.h postgresql-hll-2.14/include/storage/dfs/dfs_connector.h --- postgresql-hll-2.14_old/include/storage/dfs/dfs_connector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/dfs/dfs_connector.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,287 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_connector.h + * + * + * + * IDENTIFICATION + * src/include/storage/dfs/dfs_connector.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DFS_CONNECTOR_H +#define DFS_CONNECTOR_H + +#include +#include "dfs_config.h" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "foreign/foreign.h" +#include "miscadmin.h" +#include "nodes/pg_list.h" + +#define DEFAULT_PERM_MOD (384) + +/* + * DfsSrvOptions holds the option values to be used + * when connecting external server. + */ +typedef struct DfsSrvOptions { + char* filesystem; + char* address; + char* cfgPath; + char* storePath; +} DfsSrvOptions; + +/* + * conn + */ +enum ConnectorType { HDFS_CONNECTOR = 0, OBS_CONNECTOR = 1, UNKNOWN_CONNECTOR }; + +namespace dfs { +/* Store the block information of the file of dfs system. */ +class DFSBlockInfo : public BaseObject { +public: + virtual ~DFSBlockInfo() + {} + + /* Get the number of replications of the current file. */ + virtual int getNumOfReplica() const = 0; + /* + * Get the string including IP:xferPort for accessing the block in the node. + * @_in_param blockIdx: The index of the block to search of the file. + * @_in_param nodeIdx: The index of the node on which to seatch the block. + * @return the string including IP:xferPort. + */ + virtual const char* getNames(int blockIdx, int nodeIdx) const = 0; + + /* + * get whether the location is cached + * @_in_param blockIdx: The index of the block to search of the file. + * @_in_param nodeIdx: The index of the node on which to search the block. + * @return cached-true uncached - false. + */ + virtual bool isCached(int blockIdx, int nodeIdx) const = 0; +}; + +class DFSConnector : public BaseObject { +public: + virtual ~DFSConnector() + {} + + /* + * Check if the path in hdfs is a file not directory, log error if the path does not + * exist. + * @_in param filePath: the path of the hdfs file/directory. + * @return Return true: the path is a file; false: the path is not a file but a directory. + */ + virtual bool isDfsFile(const char* filePath) = 0; + virtual bool isDfsFile(const char* filePath, bool throw_error) = 0; + + /* Check if the path is a empty file, log error if the path does not exist. */ + virtual bool isDfsEmptyFile(const char* filePath) = 0; + + /* + * Get the file size of the path. Return -1 if the path does not exist. + * @_in_param filePath: the path of the hdfs file/directory + * @return Return the size. + */ + virtual int64_t getFileSize(const char* filePath) = 0; + + /* Get the handler to connect the DFS system. */ + virtual void* getHandler() const = 0; + + /* + * Get list of files/directories for a given directory-path. + * hdfsFreeFileInfo is called internally to deallocate memory. + * Log error if the path does not exist. + * @_in_param folderPath: The path of the directory. + * @return Return a list of filepath. Return NULL on error. + */ + virtual List* listDirectory(char* folderPath) = 0; + virtual List* listDirectory(char* folderPath, bool throw_error) = 0; + + virtual List* listObjectsStat(char* searchPath, const char* prefix = NULL) = 0; + + /* + * Get the block information of the file path. + * Log error if the path does not exist. + * @_in_param filePath: The path of the file. + * @return Return a pointer to DFSBlockInfo. + */ + virtual DFSBlockInfo* getBlockLocations(char* filePath) = 0; + + /* + * Drop directory. Return 0 if the path does not exist. + * @_in_param path The path of the directory. + * @_in_param recursive if path is a directory and set to + * non-zero, the directory is deleted else throws an exception. In + * case of a file the recursive argument is irrelevant. + * @return Returns 0 on success, -1 on error. + */ + virtual int dropDirectory(const char* path, int recursive) = 0; + + /* + * Make a directory using the given path. + * @_in_param path The path of the directory. + * @return Returns 0 on success, -1 on error. + */ + virtual int createDirectory(const char* path) = 0; + + /* + * Make a file using the given path. + * @_in_param path The path of the file to make. + * @_in_param flags - an | of bits/fcntl.h file flags - supported flags + * are O_RDONLY, O_WRONLY (meaning create or overwrite i.e., implies O_TRUNCAT), + * O_WRONLY|O_APPEND and O_SYNC. Other flags are generally ignored other than + * (O_RDWR || (O_EXCL & O_CREAT)) which return NULL and set errno equal ENOTSUP. + * return Returns 0 on success, -1 on error. + */ + virtual int openFile(const char* path, int flag) = 0; + + /* Delete the file using the given file path. Before calling this + * function, pathExists must be checked. + * @_in_param path The path of the file. + * @_in_param recursive if path is a directory and set to + * non-zero, the directory is deleted else throws an exception. In + * case of a file the recursive argument is irrelevant. + * @return Returns 0 on success, -1 on error. + */ + virtual int deleteFile(const char* path, int recursive) = 0; + + /* + * pathExists - Checks if a given path exsits on the filesystem + * @param path The path to look for + * @return Returns 0 on success, -1 on error. + */ + virtual bool pathExists(const char* filePath) = 0; + + virtual bool existsFile(const char* path) = 0; + + /* + * check if the current connector has a valid hdfs file handler. + * @return true if the file handler is valid, false on invalid. + */ + virtual bool hasValidFile() const = 0; + + /* + * Write the buffer into the current file according to the length. + * @_in_param buffer: The content to be write to file. + * @_in_param length: The length of the byte to write. + * @return Return the bytes actually write, -1 on error. + */ + virtual int writeCurrentFile(const char* buffer, int length) = 0; + + /* + * Read fixed size from the offset of the file into the buffer. + * @_out_param buffer: The buffer to be filled. + * @_in_param length: The size of bytes expected. + * @_in_param offset: The offset at which the reading starts. + * @return the bytes actually read, -1 on error. + */ + virtual int readCurrentFileFully(char* buffer, int length, int64 offset) = 0; + + /* + * Flush out the data in client's user buffer. After the return of this call, + * new readers will see the data. + * @return 0 on success, -1 on error and sets errno + */ + virtual int flushCurrentFile() = 0; + + /* + * Close the current file. + */ + virtual void closeCurrentFile() = 0; + + /* + * change the file's authority. + * @_in_param filePath: The absolute path of the file to be set. + * @_in_param mode: The mode of the authority like 600 or 755. + * Return 0 if succeed. Return 1 if fail. + */ + virtual int chmod(const char* filePath, short mode) = 0; + + /* + * Set the label expression on dfs file. + * @_in_param filePath: The absolute path of the file to be set. + * @_in_param expression: The label string like "labelA,labelB". + * Return 0 if succeed. Return 1 if fail. + */ + virtual int setLabelExpression(const char* filePath, const char* expression) = 0; + + /* + * Get the timestamp of the last modification. + */ + virtual int64 getLastModifyTime(const char* filePath) = 0; + + /* + * Fetch the configure value from the config file. + */ + virtual const char* getValue(const char* key, const char* defValue) const = 0; + + /* + * Get connection type + */ + virtual int getType() = 0; +}; + +/* + * Construct a connector of DFS which wrappers all the approaches to the DFS. + * @_in_param ctx: The memory context on which to create the connector(not used for now). + * @_in_param foreignTableId: The oid of the relation for which we create the connector. + * @return the constructed connector. + */ +DFSConnector* createConnector(MemoryContext ctx, Oid foreignTableId); +DFSConnector* createTempConnector(MemoryContext ctx, Oid foreignTableId); +DFSConnector* createConnector(MemoryContext ctx, ServerTypeOption srvType, void* options); + +/* + * Construct a connector of DFS which wrappers all the approaches to the DFS. + * @_in_param ctx: The memory context on which to create the connector(not used for now). + * @_in_param srvOptions: information of the server option. + * @_in_param tablespaceOid: tablespace oid. + * @return the constructed connector. + */ +DFSConnector* createConnector(MemoryContext ctx, DfsSrvOptions* srvOptions, Oid tablespaceOid); +DFSConnector* createTempConnector(MemoryContext ctx, DfsSrvOptions* srvOptions, Oid tablespaceOid); + +/* Initialize the global hdfs connector cache hash table. */ +void InitHDFSConnectorCacheLock(); + +/* Remove the connector entry of the hdfs cache according to the server oid. */ +void InvalidHDFSConnectorCache(Oid serverOid); + +/* Initialize the global obs connector cache hash table. */ +void InitOBSConnectorCacheLock(); + +/* + * Remove the connector entry of the obs cache according to the server oid. + * return true if clean it successfully, otherwise return false. + */ +bool InvalidOBSConnectorCache(Oid serverOid); + +/* Clean the thread local variables in kerberos. */ +void clearKerberosObjs(); + +} // namespace dfs + +/* check file path should skip */ +bool checkFileShouldSkip(char* fileName); + +/* check file path should skip */ +bool checkPathShouldSkip(char* pathName); + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/fd.h postgresql-hll-2.14/include/storage/fd.h --- postgresql-hll-2.14_old/include/storage/fd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/fd.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,165 @@ +/* ------------------------------------------------------------------------- + * + * fd.h + * Virtual file descriptor definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fd.h + * + * ------------------------------------------------------------------------- + */ + +/* + * calls: + * + * File {Close, Read, Write, Seek, Tell, Sync} + * {Path Name Open, Allocate, Free} File + * + * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES. + * Use them for all file activity... + * + * File fd; + * fd = FilePathOpenFile("foo", O_RDONLY, 0600); + * + * AllocateFile(); + * FreeFile(); + * + * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then + * use FreeFile, not fclose, to close it. AVOID using stdio for files + * that you intend to hold open for any length of time, since there is + * no way for them to share kernel file descriptors with other files. + * + * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate + * open directories (DIR*), and OpenTransientFile/CloseTransient File for an + * unbuffered file descriptor. + */ +#ifndef FD_H +#define FD_H + +#include +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "postmaster/aiocompleter.h" + +/* + * FileSeek uses the standard UNIX lseek(2) flags. + */ + +typedef char* FileName; + +typedef int File; + +#define FILE_INVALID (-1) + +typedef struct DataFileIdCacheEntry { + /* key field */ + RelFileNodeForkNum dbfid; /* file id */ + /* the following are setted in runtime */ + int fd; + int refcount; +} DataFileIdCacheEntry; + +enum FileExistStatus { FILE_EXIST, FILE_NOT_EXIST, FILE_NOT_REG }; + +/* + * prototypes for functions in fd.c + */ + +/* Operations on virtual Files --- equivalent to Unix kernel file ops */ +extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode, File file = FILE_INVALID); +extern File OpenTemporaryFile(bool interXact); +extern void FileClose(File file); +extern void FileCloseWithThief(File file); +extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info = 0); +extern int FileSync(File file, uint32 wait_event_info = 0); +extern off_t FileSeek(File file, off_t offset, int whence); +extern int FileTruncate(File file, off_t offset, uint32 wait_event_info = 0); +extern void FileWriteback(File file, off_t offset, off_t nbytes); +extern char* FilePathName(File file); + +extern void FileAsyncCUClose(File* vfdList, int32 vfdnum); +extern int FileAsyncRead(AioDispatchDesc_t** dList, int32 dn); +extern int FileAsyncWrite(AioDispatchDesc_t** dList, int32 dn); +extern int FileAsyncCURead(AioDispatchCUDesc_t** dList, int32 dn); +extern int FileAsyncCUWrite(AioDispatchCUDesc_t** dList, int32 dn); +extern void FileFastExtendFile(File file, uint32 offset, uint32 size, bool keep_size); +extern int FileRead(File file, char* buffer, int amount); +extern int FileWrite(File file, const char* buffer, int amount, off_t offset); + +// Threading virtual files IO interface, using pread() / pwrite() +// +extern int FilePRead(File file, char* buffer, int amount, off_t offset, uint32 wait_event_info = 0); +extern int FilePWrite(File file, const char* buffer, int amount, off_t offset, uint32 wait_event_info = 0); + +extern int AllocateSocket(const char* ipaddr, int port); +extern int FreeSocket(int sockfd); + +/* Operations that allow use of regular stdio --- USE WITH CAUTION */ +extern FILE* AllocateFile(const char* name, const char* mode); +extern int FreeFile(FILE* file); + +extern File OpenCacheFile(const char* pathname, bool unlink_owner); +extern void UnlinkCacheFile(const char* pathname); + +/* Operations to allow use of the library routines */ +extern DIR* AllocateDir(const char* dirname); +extern struct dirent* ReadDir(DIR* dir, const char* dirname); +extern int FreeDir(DIR* dir); +/* Operations to allow use of a plain kernel FD, with automatic cleanup */ +extern int OpenTransientFile(FileName fileName, int fileFlags, int fileMode); +extern int CloseTransientFile(int fd); +/* If you've really really gotta have a plain kernel FD, use this */ +extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode); + +/* Miscellaneous support routines */ +extern void InitFileAccess(void); +extern void set_max_safe_fds(void); +extern void CloseGaussPidDir(void); +extern void closeAllVfds(void); +extern void SetTempTablespaces(Oid* tableSpaces, int numSpaces); +extern bool TempTablespacesAreSet(void); +extern Oid GetNextTempTableSpace(void); +extern void AtEOXact_Files(void); +extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern void AtProcExit_Files(int code, Datum arg); +extern void RemovePgTempFiles(void); + +extern void RemoveErrorCacheFiles(); +extern int FileFd(File file); + +extern int pg_fsync(int fd); +extern int pg_fsync_no_writethrough(int fd); +extern int pg_fsync_writethrough(int fd); +extern int pg_fdatasync(int fd); +extern void pg_flush_data(int fd, off_t offset, off_t amount); +extern void DestroyAllVfds(void); + +extern void InitDataFileIdCache(void); +extern Size DataFileIdCacheSize(void); +extern File DataFileIdOpenFile( + FileName fileName, const RelFileNodeForkNum& fileNode, int fileFlags, int fileMode, File file = FILE_INVALID); + +extern RelFileNodeForkNum RelFileNodeForkNumFill( + const RelFileNodeBackend& rnode, ForkNumber forkNum, BlockNumber segno); + +extern void FreeAllAllocatedDescs(void); +extern void GetFdGlobalVariables(void*** global_VfdCache, Size** global_SizeVfdCache); +extern void SwitchToGlobalVfdCache(void** vfd, Size* vfd_size); +extern void ResetToLocalVfdCache(); + +extern int data_sync_elevel(int elevel); + +extern bool FdRefcntIsZero(SMgrRelation reln, ForkNumber forkNum); +extern FileExistStatus CheckFileExists(const char* path); + +/* Filename components for OpenTemporaryFile */ +// Note that this macro must be the same to macro in initdb.cpp +// If you change it, you must also change initdb.cpp +// +#define PG_TEMP_FILES_DIR "pgsql_tmp" +#define PG_TEMP_FILE_PREFIX "pgsql_tmp" + +#endif /* FD_H */ diff -uprN postgresql-hll-2.14_old/include/storage/freespace.h postgresql-hll-2.14/include/storage/freespace.h --- postgresql-hll-2.14_old/include/storage/freespace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/freespace.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * freespace.h + * POSTGRES free space map for quickly finding free space in relations + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/freespace.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FREESPACE_H_ +#define FREESPACE_H_ + +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef uint64 XLogRecPtr; + + +/* + * We use just one byte to store the amount of free space on a page, so we + * divide the amount of free space a page can have into 256 different + * categories. The highest category, 255, represents a page with at least + * MaxFSMRequestSize bytes of free space, and the second highest category + * represents the range from 254 * FSM_CAT_STEP, inclusive, to + * MaxFSMRequestSize, exclusive. + * + * MaxFSMRequestSize depends on the architecture and BLCKSZ, but assuming + * default 8k BLCKSZ, and that MaxFSMRequestSize is 24 bytes, the categories + * look like this + * + * + * Range Category + * 0 - 31 0 + * 32 - 63 1 + * ... ... ... + * 8096 - 8127 253 + * 8128 - 8163 254 + * 8164 - 8192 255 + * + * The reason that MaxFSMRequestSize is special is that if MaxFSMRequestSize + * isn't equal to a range boundary, a page with exactly MaxFSMRequestSize + * bytes of free space wouldn't satisfy a request for MaxFSMRequestSize + * bytes. If there isn't more than MaxFSMRequestSize bytes of free space on a + * completely empty page, that would mean that we could never satisfy a + * request of exactly MaxFSMRequestSize bytes. + */ +#define FSM_CATEGORIES 256 +#define FSM_CAT_STEP (BLCKSZ / FSM_CATEGORIES) +#define MaxFSMRequestSize MaxHeapTupleSize + +/* + * Depth of the on-disk tree. We need to be able to address 2^32-1 blocks, + * and 1626 is the smallest number that satisfies X^3 >= 2^32-1. Likewise, + * 216 is the smallest number that satisfies X^4 >= 2^32-1. In practice, + * this means that 4096 bytes is the smallest BLCKSZ that we can get away + * with a 3-level tree, and 512 is the smallest we support. + */ +#define FSM_TREE_DEPTH ((SlotsPerFSMPage >= 1626) ? 3 : 4) + +#define FSM_ROOT_LEVEL (FSM_TREE_DEPTH - 1) +#define FSM_BOTTOM_LEVEL 0 + +/* + * The internal FSM routines work on a logical addressing scheme. Each + * level of the tree can be thought of as a separately addressable file. + */ +typedef struct { + int level; /* level */ + int logpageno; /* page number within the level */ +} FSMAddress; + + + +/* prototypes for public functions in freespace.c */ +extern Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk); +extern BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded); +extern BlockNumber RecordAndGetPageWithFreeSpace( + Relation rel, BlockNumber oldPage, Size oldSpaceAvail, Size spaceNeeded); +extern void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail); +extern void XLogRecordPageWithFreeSpace(const RelFileNode& rnode, BlockNumber heapBlk, Size spaceAvail); + +extern void FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks); +extern void FreeSpaceMapVacuum(Relation rel); +extern void UpdateFreeSpaceMap(Relation rel, BlockNumber firtsBlkNum, BlockNumber lastBlkNum, Size freespace); +extern BlockNumber FreeSpaceMapCalTruncBlkNo(BlockNumber relBlkNo); +extern void XLogBlockTruncateRelFSM(Relation rel, BlockNumber nblocks); +extern FSMAddress fsm_get_location(BlockNumber heapblk, uint16* slot); +extern BlockNumber fsm_logical_to_physical(const FSMAddress& addr); +extern uint8 fsm_space_avail_to_cat(Size avail); +extern bool fsm_set_avail(Page page, int slot, uint8 value); + +#endif /* FREESPACE_H_ */ diff -uprN postgresql-hll-2.14_old/include/storage/fsm_internals.h postgresql-hll-2.14/include/storage/fsm_internals.h --- postgresql-hll-2.14_old/include/storage/fsm_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/fsm_internals.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,68 @@ +/* ------------------------------------------------------------------------- + * + * fsm_internal.h + * internal functions for free space map + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fsm_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FSM_INTERNALS_H +#define FSM_INTERNALS_H + +#include "storage/buf.h" +#include "storage/bufpage.h" + +/* + * Structure of a FSM page. See src/backend/storage/freespace/README for + * details. + */ +typedef struct { + /* + * fsm_search_avail() tries to spread the load of multiple backends by + * returning different pages to different backends in a round-robin + * fashion. fp_next_slot points to the next slot to be returned (assuming + * there's enough space on it for the request). It's defined as an int, + * because it's updated without an exclusive lock. uint16 would be more + * appropriate, but int is more likely to be atomically + * fetchable/storable. + */ + int fp_next_slot; + + /* + * fp_nodes contains the binary tree, stored in array. The first + * NonLeafNodesPerPage elements are upper nodes, and the following + * LeafNodesPerPage elements are leaf nodes. Unused nodes are zero. + */ + uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]; +} FSMPageData; + +typedef FSMPageData* FSMPage; + +/* + * Number of non-leaf and leaf nodes, and nodes in total, on an FSM page. + * These definitions are internal to fsmpage.c. + */ +#define NodesPerPage (BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - offsetof(FSMPageData, fp_nodes)) + +#define NonLeafNodesPerPage (BLCKSZ / 2 - 1) +#define LeafNodesPerPage (NodesPerPage - NonLeafNodesPerPage) + +/* + * Number of FSM "slots" on a FSM page. This is what should be used + * outside fsmpage.c. + */ +#define SlotsPerFSMPage LeafNodesPerPage + +/* Prototypes for functions in fsmpage.c */ +extern int fsm_search_avail(Buffer buf, uint8 min_cat, bool advancenext, bool exclusive_lock_held); +extern uint8 fsm_get_avail(Page page, int slot); +extern uint8 fsm_get_max_avail(Page page); +extern bool fsm_truncate_avail(Page page, int nslots); +extern bool fsm_rebuild_page(Page page); + +#endif /* FSM_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/storage/indexfsm.h postgresql-hll-2.14/include/storage/indexfsm.h --- postgresql-hll-2.14_old/include/storage/indexfsm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/indexfsm.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,26 @@ +/* ------------------------------------------------------------------------- + * + * indexfsm.h + * POSTGRES free space map for quickly finding an unused page in index + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/indexfsm.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INDEXFSM_H_ +#define INDEXFSM_H_ + +#include "storage/block.h" +#include "utils/relcache.h" + +extern BlockNumber GetFreeIndexPage(Relation rel); +extern void RecordFreeIndexPage(Relation rel, BlockNumber page); +extern void RecordUsedIndexPage(Relation rel, BlockNumber page); + +extern void IndexFreeSpaceMapVacuum(Relation rel); + +#endif /* INDEXFSM_H_ */ diff -uprN postgresql-hll-2.14_old/include/storage/ipc.h postgresql-hll-2.14/include/storage/ipc.h --- postgresql-hll-2.14_old/include/storage/ipc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/ipc.h 2020-12-12 17:06:43.377349716 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * ipc.h + * POSTGRES inter-process communication definitions. + * + * This file is misnamed, as it no longer has much of anything directly + * to do with IPC. The functionality here is concerned with managing + * exit-time cleanup for either a postmaster or a backend. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/ipc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef IPC_H +#define IPC_H + +typedef void (*pg_on_exit_callback)(int code, Datum arg); +typedef void (*shmem_startup_hook_type)(void); + +extern volatile unsigned int alive_threads_waitted; + +#define DEC_NUM_ALIVE_THREADS_WAITTED() alive_threads_waitted-- + +extern void WaitGraceThreadsExit(void); + +/* ---------- + * API for handling cleanup that must occur during either ereport(ERROR) + * or ereport(FATAL) exits from a block of code. (Typical examples are + * undoing transient changes to shared-memory state.) + * + * PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg); + * { + * ... code that might throw ereport(ERROR) or ereport(FATAL) ... + * } + * PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg); + * + * where the cleanup code is in a function declared per pg_on_exit_callback. + * The Datum value "arg" can carry any information the cleanup function + * needs. + * + * This construct ensures that cleanup_function() will be called during + * either ERROR or FATAL exits. It will not be called on successful + * exit from the controlled code. (If you want it to happen then too, + * call the function yourself from just after the construct.) + * + * Note: the macro arguments are multiply evaluated, so avoid side-effects. + * ---------- + */ +#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \ + do { \ + on_shmem_exit(cleanup_function, arg); \ + PG_TRY() + +#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg) \ + cancel_shmem_exit(cleanup_function, arg); \ + PG_CATCH(); \ + { \ + cancel_shmem_exit(cleanup_function, arg); \ + cleanup_function(0, arg); \ + PG_RE_THROW(); \ + } \ + PG_END_TRY(); \ + } \ + while (0) + +struct knl_session_context; +extern void CloseClientSocket(knl_session_context* context, bool closesock); +extern void proc_exit(int code); +extern void sess_exit(int code); +extern void shmem_exit(int code); +extern void on_proc_exit(pg_on_exit_callback function, Datum arg); +extern void on_shmem_exit(pg_on_exit_callback function, Datum arg); +extern void cancel_shmem_exit(pg_on_exit_callback function, Datum arg); +extern void on_exit_reset(void); + +/* ipci.c */ +extern pthread_mutex_t gLocaleMutex; + +extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int port); + +extern void cancelShmemExit(pg_on_exit_callback function, Datum arg); +#endif /* IPC_H */ diff -uprN postgresql-hll-2.14_old/include/storage/item.h postgresql-hll-2.14/include/storage/item.h --- postgresql-hll-2.14_old/include/storage/item.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/item.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,19 @@ +/* ------------------------------------------------------------------------- + * + * item.h + * POSTGRES disk item definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/item.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEM_H +#define ITEM_H + +typedef Pointer Item; + +#endif /* ITEM_H */ diff -uprN postgresql-hll-2.14_old/include/storage/itemid.h postgresql-hll-2.14/include/storage/itemid.h --- postgresql-hll-2.14_old/include/storage/itemid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/itemid.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------- + * + * itemid.h + * Standard POSTGRES buffer page item identifier definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/itemid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEMID_H +#define ITEMID_H + +/* + * An item pointer (also called line pointer) on a buffer page + * + * In some cases an item pointer is "in use" but does not have any associated + * storage on the page. By convention, lp_len == 0 in every item pointer + * that does not have storage, independently of its lp_flags state. + */ +typedef struct ItemIdData { + unsigned lp_off : 15, /* offset to tuple (from start of page) */ + lp_flags : 2, /* state of item pointer, see below */ + lp_len : 15; /* byte length of tuple */ +} ItemIdData; + +typedef ItemIdData* ItemId; + +/* + * lp_flags has these possible states. An UNUSED line pointer is available + * for immediate re-use, the other states are not. + */ +#define LP_UNUSED 0 /* unused (should always have lp_len=0) */ +#define LP_NORMAL 1 /* used (should always have lp_len>0) */ +#define LP_REDIRECT 2 /* HOT redirect (should have lp_len=0) */ +#define LP_DEAD 3 /* dead, may or may not have storage */ + +/* + * Item offsets and lengths are represented by these types when + * they're not actually stored in an ItemIdData. + */ +typedef uint16 ItemOffset; +typedef uint16 ItemLength; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * ItemIdGetLength + */ +#define ItemIdGetLength(itemId) ((itemId)->lp_len) + +/* + * ItemIdGetOffset + */ +#define ItemIdGetOffset(itemId) ((itemId)->lp_off) + +/* + * ItemIdGetFlags + */ +#define ItemIdGetFlags(itemId) ((itemId)->lp_flags) + +/* + * ItemIdGetRedirect + * In a REDIRECT pointer, lp_off holds the link to the next item pointer + */ +#define ItemIdGetRedirect(itemId) ((itemId)->lp_off) + +/* + * ItemIdIsValid + * True iff item identifier is valid. + * This is a pretty weak test, probably useful only in Asserts. + */ +#define ItemIdIsValid(itemId) PointerIsValid(itemId) + +/* + * ItemIdIsUsed + * True iff item identifier is in use. + */ +#define ItemIdIsUsed(itemId) ((itemId)->lp_flags != LP_UNUSED) + +/* + * ItemIdIsNormal + * True iff item identifier is in state NORMAL. + */ +#define ItemIdIsNormal(itemId) ((itemId)->lp_flags == LP_NORMAL) + +/* + * ItemIdIsRedirected + * True iff item identifier is in state REDIRECT. + */ +#define ItemIdIsRedirected(itemId) ((itemId)->lp_flags == LP_REDIRECT) + +/* + * ItemIdIsDead + * True iff item identifier is in state DEAD. + */ +#define ItemIdIsDead(itemId) ((itemId)->lp_flags == LP_DEAD) + +/* + * ItemIdHasStorage + * True iff item identifier has associated storage. + */ +#define ItemIdHasStorage(itemId) ((itemId)->lp_len != 0) + +/* + * ItemIdSetUnused + * Set the item identifier to be UNUSED, with no storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetUnused(itemId) ((itemId)->lp_flags = LP_UNUSED, (itemId)->lp_off = 0, (itemId)->lp_len = 0) + +/* + * ItemIdSetNormal + * Set the item identifier to be NORMAL, with the specified storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetNormal(itemId, off, len) \ + ((itemId)->lp_flags = LP_NORMAL, (itemId)->lp_off = (off), (itemId)->lp_len = (len)) + +/* + * ItemIdSetRedirect + * Set the item identifier to be REDIRECT, with the specified link. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetRedirect(itemId, link) \ + ((itemId)->lp_flags = LP_REDIRECT, (itemId)->lp_off = (link), (itemId)->lp_len = 0) + +/* + * ItemIdSetDead + * Set the item identifier to be DEAD, with no storage. + * Beware of multiple evaluations of itemId! + */ +#define ItemIdSetDead(itemId) ((itemId)->lp_flags = LP_DEAD, (itemId)->lp_off = 0, (itemId)->lp_len = 0) + +/* + * ItemIdMarkDead + * Set the item identifier to be DEAD, keeping its existing storage. + * + * Note: in indexes, this is used as if it were a hint-bit mechanism; + * we trust that multiple processors can do this in parallel and get + * the same result. + */ +#define ItemIdMarkDead(itemId) ((itemId)->lp_flags = LP_DEAD) + +#endif /* ITEMID_H */ diff -uprN postgresql-hll-2.14_old/include/storage/itemptr.h postgresql-hll-2.14/include/storage/itemptr.h --- postgresql-hll-2.14_old/include/storage/itemptr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/itemptr.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,223 @@ +/* ------------------------------------------------------------------------- + * + * itemptr.h + * POSTGRES disk item pointer definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/itemptr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ITEMPTR_H +#define ITEMPTR_H + +#include "storage/block.h" +#include "storage/off.h" + +/* + * ItemPointer: + * + * This is a pointer to an item within a disk page of a known file + * (for example, a cross-link from an index to its parent table). + * blkid tells us which block, posid tells us which entry in the linp + * (ItemIdData) array we want. + * + * Note: because there is an item pointer in each tuple header and index + * tuple header on disk, it's very important not to waste space with + * structure padding bytes. The struct is designed to be six bytes long + * (it contains three int16 fields) but a few compilers will pad it to + * eight bytes unless coerced. We apply appropriate persuasion where + * possible, and to cope with unpersuadable compilers, we try to use + * "SizeOfIptrData" rather than "sizeof(ItemPointerData)" when computing + * on-disk sizes. + */ +typedef struct ItemPointerData { + BlockIdData ip_blkid; + OffsetNumber ip_posid; +} + +#ifdef __arm__ +__attribute__((packed)) /* Appropriate whack upside the head for ARM */ +#endif +ItemPointerData; + +#define SizeOfIptrData (offsetof(ItemPointerData, ip_posid) + sizeof(OffsetNumber)) + +typedef ItemPointerData* ItemPointer; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * ItemPointerIsValid + * True iff the disk item pointer is not NULL. + */ +#define ItemPointerIsValid(pointer) ((bool)(PointerIsValid(pointer) && ((pointer)->ip_posid != 0))) + +/* + * ItemPointerGetBlockNumber + * Returns the block number of a disk item pointer. + */ +#define ItemPointerGetBlockNumber(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetBlockNumberNoCheck + * Returns the block number of a disk item pointer. + */ +#define ItemPointerGetBlockNumberNoCheck(pointer) (BlockIdGetBlockNumber(&(pointer)->ip_blkid)) + +/* + * ItemPointerGetOffsetNumberNoCheck + * Returns the offset number of a disk item pointer. + */ +#define ItemPointerGetOffsetNumberNoCheck(pointer) ((pointer)->ip_posid) + +/* + * ItemPointerGetOffsetNumber + * Returns the offset number of a disk item pointer. + */ +#define ItemPointerGetOffsetNumber(pointer) (AssertMacro(ItemPointerIsValid(pointer)), (pointer)->ip_posid) + +/* + * ItemPointerSet + * Sets a disk item pointer to the specified block and offset. + */ +#define ItemPointerSet(pointer, blockNumber, offNum) \ + (AssertMacro(PointerIsValid(pointer)), \ + BlockIdSet(&((pointer)->ip_blkid), blockNumber), \ + (pointer)->ip_posid = offNum) + +/* + * ItemPointerZero + * Sets a disk item pointer to zero. + */ +#define ItemPointerZero(pointer) \ + (AssertMacro(PointerIsValid(pointer)), \ + (pointer)->ip_blkid.bi_hi = 0, \ + (pointer)->ip_blkid.bi_lo = 0, \ + (pointer)->ip_posid = 0) + +/* + * ItemPointerSetBlockNumber + * Sets a disk item pointer to the specified block. + */ +#define ItemPointerSetBlockNumber(pointer, blockNumber) \ + (AssertMacro(PointerIsValid(pointer)), BlockIdSet(&((pointer)->ip_blkid), blockNumber)) + +/* + * ItemPointerSetOffsetNumber + * Sets a disk item pointer to the specified offset. + */ +#define ItemPointerSetOffsetNumber(pointer, offsetNumber) \ + (AssertMacro(PointerIsValid(pointer)), (pointer)->ip_posid = (offsetNumber)) + +/* + * ItemPointerCopy + * Copies the contents of one disk item pointer to another. + * + * Should there ever be padding in an ItemPointer this would need to be handled + * differently as it's used as hash key. + */ +#define ItemPointerCopy(fromPointer, toPointer) \ + (AssertMacro(PointerIsValid(toPointer)), AssertMacro(PointerIsValid(fromPointer)), *(toPointer) = *(fromPointer)) + +/* + * ItemPointerSetInvalid + * Sets a disk item pointer to be invalid. + */ +#define ItemPointerSetInvalid(pointer) \ + (AssertMacro(PointerIsValid(pointer)), \ + BlockIdSet(&((pointer)->ip_blkid), InvalidBlockNumber), \ + (pointer)->ip_posid = InvalidOffsetNumber) + +/* ---------------- + * externs + * ---------------- + */ + +extern bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2); +extern int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2); + +/* -------------------------------------------------------- + * support macros for dfs ItemPointer + * + * ------------------------------------- + * | 0 | 1 | 2 | 3 | 4 | 5 | memory address(low->high) + * ------------------------------------- + * | ip_blkid | ip_posid | \ + * ------------------------------------- ItemPointerData + * | bi_hi | bi_lo | ip_posid | / + * ------------------------------------- + * | file_id | offset | layout of ItemPointerData for dfs + * ------------------------------------- + * + * for compatibility, only 23 bits of "offset" is dedicated for position in file, + * the highest bit of "ip_posid" is always 1 for valid dfs tid, so the low 8 bit + * of bi_lo and the low 15 bit of ip_posid are used for offset. + * + * Just get/set macros are provided here, the design of tid for dfs provides the + * most compatibility with others macro and function of tid of row and column + * storage. For example, you can use ItemPointerIsValid() to check dfs tid. + * -------------------------------------------------------- + */ + +#define DfsInvalidBlockNumber ((BlockNumber)0x00FFFFFF) +#define DfsMaxBlockNumber ((BlockNumber)0x00FFFFFE) + +#define DfsInvalidOffsetNumber ((uint32)0) +#define DfsFirstOffsetNumber ((uint32)1) +#define DfsMaxOffset (0x007fffff) + +/* + * DfsItemPointerGetFileId + * Returns the file id of a dfs item pointer. + */ +#define DfsItemPointerGetFileId(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), \ + (BlockNumber)(((pointer)->ip_blkid).bi_hi << 8) | (BlockNumber)(((pointer)->ip_blkid).bi_lo >> 8)) + +/* + * DfsItemPointerGetOffset + * Returns the offset in file of a dfs item pointer. + */ +#define DfsItemPointerGetOffset(pointer) \ + (AssertMacro(ItemPointerIsValid(pointer)), \ + (uint32)((((pointer)->ip_blkid).bi_lo & 0x00ff) << 15) | ((pointer)->ip_posid & 0x7fff)) + +/* + * DfsItemPointerSetFileId + * Sets a dfs item pointer to the specified file id. + */ +#define DfsItemPointerSetFileId(pointer, fileId) \ + (AssertMacro(PointerIsValid(pointer)), \ + ((pointer)->ip_blkid).bi_hi = ((fileId) << 8) >> 16, \ + ((pointer)->ip_blkid).bi_lo &= 0x00ff, \ + ((pointer)->ip_blkid).bi_lo |= (((fileId) << 8) & 0xff00)) + +/* + * DfsItemPointerSetOffset + * Sets a dfs item pointer to the specified offset. + */ +#define DfsItemPointerSetOffset(pointer, offset) \ + (AssertMacro(PointerIsValid(pointer)), \ + (pointer)->ip_posid = 0x8000, \ + (pointer)->ip_posid |= ((offset)&0x7fff), \ + ((pointer)->ip_blkid).bi_lo &= 0xff00, \ + ((pointer)->ip_blkid).bi_lo |= (((offset) >> 15) & 0x00ff)) + +/* + * DfsItemPointerSet + * Sets a dfs item pointer to the specified file id and offset. + */ +#define DfsItemPointerSet(pointer, fileId, offset) \ + (AssertMacro(PointerIsValid(pointer)), \ + DfsItemPointerSetFileId(pointer, fileId), \ + DfsItemPointerSetOffset(pointer, offset)) + +#endif /* ITEMPTR_H */ diff -uprN postgresql-hll-2.14_old/include/storage/large_object.h postgresql-hll-2.14/include/storage/large_object.h --- postgresql-hll-2.14_old/include/storage/large_object.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/large_object.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,88 @@ +/* ------------------------------------------------------------------------- + * + * large_object.h + * Declarations for PostgreSQL large objects. POSTGRES 4.2 supported + * zillions of large objects (internal, external, jaquith, inversion). + * Now we only support inversion. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/large_object.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LARGE_OBJECT_H +#define LARGE_OBJECT_H + +#include "utils/snapshot.h" + +/* ---------- + * Data about a currently-open large object. + * + * id is the logical OID of the large object + * snapshot is the snapshot to use for read/write operations + * subid is the subtransaction that opened the desc (or currently owns it) + * offset is the current seek offset within the LO + * flags contains some flag bits + * + * NOTE: before 7.1, we also had to store references to the separate table + * and index of a specific large object. Now they all live in pg_largeobject + * and are accessed via a common relation descriptor. + * ---------- + */ +typedef struct LargeObjectDesc { + Oid id; /* LO's identifier */ + Snapshot snapshot; /* snapshot to use */ + SubTransactionId subid; /* owning subtransaction ID */ + uint32 offset; /* current seek pointer */ + int flags; /* locking info, etc */ + +/* flag bits: */ +#define IFS_RDLOCK (1 << 0) +#define IFS_WRLOCK (1 << 1) + +} LargeObjectDesc; + +/* + * Each "page" (tuple) of a large object can hold this much data + * + * We could set this as high as BLCKSZ less some overhead, but it seems + * better to make it a smaller value, so that not as much space is used + * up when a page-tuple is updated. Note that the value is deliberately + * chosen large enough to trigger the tuple toaster, so that we will + * attempt to compress page tuples in-line. (But they won't be moved off + * unless the user creates a toast-table for pg_largeobject...) + * + * Also, it seems to be a smart move to make the page size be a power of 2, + * since clients will often be written to send data in power-of-2 blocks. + * This avoids unnecessary tuple updates caused by partial-page writes. + */ +#define LOBLKSIZE (BLCKSZ / 4) + +/* compatible with C code for pljava, otherwise pljava will met compile error */ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function definitions... + */ + +/* inversion stuff in inv_api.c */ +extern void close_lo_relation(bool isCommit); +extern Oid inv_create(Oid lobjId); +extern LargeObjectDesc* inv_open(Oid lobjId, int flags, MemoryContext mcxt); +extern void inv_close(LargeObjectDesc* obj_desc); +extern int inv_drop(Oid lobjId); +extern int inv_seek(LargeObjectDesc* obj_desc, int offset, int whence); +extern int inv_tell(LargeObjectDesc* obj_desc); +extern int inv_read(LargeObjectDesc* obj_desc, char* buf, int nbytes); +extern int inv_write(LargeObjectDesc* obj_desc, const char* buf, int nbytes); +extern void inv_truncate(LargeObjectDesc* obj_desc, int len); + +#ifdef __cplusplus +} +#endif + +#endif /* LARGE_OBJECT_H */ diff -uprN postgresql-hll-2.14_old/include/storage/latch.h postgresql-hll-2.14/include/storage/latch.h --- postgresql-hll-2.14_old/include/storage/latch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/latch.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,132 @@ +/* ------------------------------------------------------------------------- + * + * latch.h + * Routines for interprocess latches + * + * A latch is a boolean variable, with operations that let processes sleep + * until it is set. A latch can be set from another process, or a signal + * handler within the same process. + * + * The latch interface is a reliable replacement for the common pattern of + * using pg_usleep() or select() to wait until a signal arrives, where the + * signal handler sets a flag variable. Because on some platforms an + * incoming signal doesn't interrupt sleep, and even on platforms where it + * does there is a race condition if the signal arrives just before + * entering the sleep, the common pattern must periodically wake up and + * poll the flag variable. The pselect() system call was invented to solve + * this problem, but it is not portable enough. Latches are designed to + * overcome these limitations, allowing you to sleep without polling and + * ensuring quick response to signals from other processes. + * + * There are two kinds of latches: local and shared. A local latch is + * initialized by InitLatch, and can only be set from the same process. + * A local latch can be used to wait for a signal to arrive, by calling + * SetLatch in the signal handler. A shared latch resides in shared memory, + * and must be initialized at postmaster startup by InitSharedLatch. Before + * a shared latch can be waited on, it must be associated with a process + * with OwnLatch. Only the process owning the latch can wait on it, but any + * process can set it. + * + * There are three basic operations on a latch: + * + * SetLatch - Sets the latch + * ResetLatch - Clears the latch, allowing it to be set again + * WaitLatch - Waits for the latch to become set + * + * WaitLatch includes a provision for timeouts (which should be avoided + * when possible, as they incur extra overhead) and a provision for + * postmaster child processes to wake up immediately on postmaster death. + * See unix_latch.c for detailed specifications for the exported functions. + * + * The correct pattern to wait for event(s) is: + * + * for (;;) + * { + * ResetLatch(); + * if (work to do) + * Do Stuff(); + * WaitLatch(); + * } + * + * It's important to reset the latch *before* checking if there's work to + * do. Otherwise, if someone sets the latch between the check and the + * ResetLatch call, you will miss it and Wait will incorrectly block. + * + * To wake up the waiter, you must first set a global flag or something + * else that the wait loop tests in the "if (work to do)" part, and call + * SetLatch *after* that. SetLatch is designed to return quickly if the + * latch is already set. + * + * On some platforms, signals will not interrupt the latch wait primitive + * by themselves. Therefore, it is critical that any signal handler that + * is meant to terminate a WaitLatch wait calls SetLatch. + * + * Note that use of the process latch (PGPROC.procLatch) is generally better + * than an ad-hoc shared latch for signaling auxiliary processes. This is + * because generic signal handlers will call SetLatch on the process latch + * only, so using any latch other than the process latch effectively precludes + * use of any generic handler. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/latch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LATCH_H +#define LATCH_H + +#include + +/* + * Latch structure should be treated as opaque and only accessed through + * the public functions. It is defined here to allow embedding Latches as + * part of bigger structs. + */ +typedef struct { + sig_atomic_t is_set; + bool is_shared; + ThreadId owner_pid; +#ifdef WIN32 + HANDLE event; +#endif +} Latch; + +/* Bitmasks for events that may wake-up WaitLatch() clients */ +#define WL_LATCH_SET (1 << 0) +#define WL_SOCKET_READABLE (1 << 1) +#define WL_SOCKET_WRITEABLE (1 << 2) +#define WL_TIMEOUT (1 << 3) +#define WL_POSTMASTER_DEATH (1 << 4) + +/* + * prototypes for functions in latch.c + */ +extern void InitializeLatchSupport(void); +extern void InitLatch(volatile Latch* latch); +extern void InitSharedLatch(volatile Latch* latch); +extern void OwnLatch(volatile Latch* latch); +extern void DisownLatch(volatile Latch* latch); +extern int WaitLatch(volatile Latch* latch, int wakeEvents, long timeout); +extern int WaitLatchOrSocket(volatile Latch* latch, int wakeEvents, pgsocket sock, long timeout); +extern void SetLatch(volatile Latch* latch); +extern void ResetLatch(volatile Latch* latch); + +extern void ClosePipesAtThreadExit(void); + +/* beware of memory ordering issues if you use this macro! */ +#define TestLatch(latch) (((volatile Latch*)(latch))->is_set) + +/* + * Unix implementation uses SIGUSR1 for inter-process signaling. + * Win32 doesn't need this. + */ +#ifndef WIN32 +extern void latch_sigusr1_handler(void); +#else +#define latch_sigusr1_handler() ((void)0) +#endif + +#endif /* LATCH_H */ diff -uprN postgresql-hll-2.14_old/include/storage/lmgr.h postgresql-hll-2.14/include/storage/lmgr.h --- postgresql-hll-2.14_old/include/storage/lmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lmgr.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,108 @@ +/* ------------------------------------------------------------------------- + * + * lmgr.h + * POSTGRES lock manager definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LMGR_H +#define LMGR_H + +#include "lib/stringinfo.h" +#include "storage/itemptr.h" +#include "storage/lock.h" +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "utils/partcache.h" +#include "utils/partitionmap_gs.h" + +extern void RelationInitLockInfo(Relation relation); + +/* Lock a relation */ +extern void LockRelationOid(Oid relid, LOCKMODE lockmode); +extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode); +extern void UnlockRelationId(LockRelId* relid, LOCKMODE lockmode); +extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode); + +extern void LockRelFileNode(const RelFileNode& rnode, LOCKMODE lockmode); +extern void UnlockRelFileNode(const RelFileNode& rnode, LOCKMODE lockmode); + +extern void LockRelation(Relation relation, LOCKMODE lockmode); +extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode); +extern void UnlockRelation(Relation relation, LOCKMODE lockmode); +extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode); + +extern void LockRelationIdForSession(LockRelId* relid, LOCKMODE lockmode); +extern void UnlockRelationIdForSession(LockRelId* relid, LOCKMODE lockmode); + +/* Lock a relation for extension */ +extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode); +extern int RelationExtensionLockWaiterCount(Relation relation); + +extern void LockRelFileNodeForExtension(const RelFileNode& rnode, LOCKMODE lockmode); +extern void UnlockRelFileNodeForExtension(const RelFileNode& rnode, LOCKMODE lockmode); + +/* Lock a page (currently only used within indexes) */ +extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); +extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); +extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode); + +/* Lock a tuple (see heap_lock_tuple before assuming you understand this) */ +extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode, bool allow_con_update = false); +extern bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); +extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode); + +/* Lock an XID (used to wait for a transaction to finish) */ +extern void XactLockTableInsert(TransactionId xid); +extern void XactLockTableDelete(TransactionId xid); +extern void XactLockTableWait(TransactionId xid, bool allow_con_update = false); +extern bool ConditionalXactLockTableWait(TransactionId xid, bool waitparent = true, bool bCareNextxid = false); + +/* Lock a general object (other than a relation) of the current database */ +extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); + +/* Lock a shared-across-databases object (other than a relation) */ +extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); + +extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode); +extern void PartitionInitLockInfo(Partition partition); + +/* Describe a locktag for error messages */ +extern void LockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); +extern bool ConditionalLockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); +extern void UnlockPartition(Oid relid, uint32 seq, LOCKMODE lockmode, int partition_lock_type); + +extern void LockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); +extern bool ConditionalLockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); +extern void UnlockPartitionOid(Oid relid, uint32 seq, LOCKMODE lockmode); + +extern void LockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); +extern bool ConditionalLockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); +extern void UnlockPartitionSeq(Oid relid, uint32 seq, LOCKMODE lockmode); + +extern bool ConditionalLockPartitionWithRetry(Relation relation, Oid partitionId, LOCKMODE lockmode); + +/* for vacuum partition */ +void LockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +bool ConditionalLockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +void UnLockPartitionVacuum(Relation prel, Oid partId, LOCKMODE lockmode); +void LockPartitionVacuumForSession(PartitionIdentifier* partIdtf, Oid partrelid, Oid partid, LOCKMODE lockmode); +void UnLockPartitionVacuumForSession(PartitionIdentifier* partIdtf, Oid partrelid, Oid partid, LOCKMODE lockmode); + +extern void DescribeLockTag(StringInfo buf, const LOCKTAG* tag); + +extern bool ConditionalLockCStoreFreeSpace(Relation relation); +extern void UnlockCStoreFreeSpace(Relation relation); +extern const char* GetLockNameFromTagType(uint16 locktag_type); +#endif /* LMGR_H */ diff -uprN postgresql-hll-2.14_old/include/storage/lock.h postgresql-hll-2.14/include/storage/lock.h --- postgresql-hll-2.14_old/include/storage/lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lock.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,565 @@ +/* ------------------------------------------------------------------------- + * + * lock.h + * POSTGRES low-level lock mechanism + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LOCK_H_ +#define LOCK_H_ + +#include "storage/backendid.h" +#include "storage/lwlock.h" +#include "storage/shmem.h" +#include "gs_thread.h" + +typedef struct PROC_QUEUE { + SHM_QUEUE links; /* head of list of PGPROC objects */ + int size; /* number of entries in list */ +} PROC_QUEUE; + +/* + * Top-level transactions are identified by VirtualTransactionIDs comprising + * the BackendId of the backend running the xact, plus a locally-assigned + * LocalTransactionId. These are guaranteed unique over the short term, + * but will be reused after a database restart; hence they should never + * be stored on disk. + * + * Note that struct VirtualTransactionId can not be assumed to be atomically + * assignable as a whole. However, type LocalTransactionId is assumed to + * be atomically assignable, and the backend ID doesn't change often enough + * to be a problem, so we can fetch or assign the two fields separately. + * We deliberately refrain from using the struct within PGPROC, to prevent + * coding errors from trying to use struct assignment with it; instead use + * GET_VXID_FROM_PGPROC(). + */ +typedef struct VirtualTransactionId { + BackendId backendId; /* determined at backend startup */ + LocalTransactionId localTransactionId; /* backend-local transaction + * id */ +} VirtualTransactionId; + +#define InvalidLocalTransactionId 0 +#define LocalTransactionIdIsValid(lxid) ((lxid) != InvalidLocalTransactionId) +#define VirtualTransactionIdIsValid(vxid) \ + (((vxid).backendId != InvalidBackendId) && LocalTransactionIdIsValid((vxid).localTransactionId)) +#define VirtualTransactionIdEquals(vxid1, vxid2) \ + ((vxid1).backendId == (vxid2).backendId && (vxid1).localTransactionId == (vxid2).localTransactionId) +#define SetInvalidVirtualTransactionId(vxid) \ + ((vxid).backendId = InvalidBackendId, (vxid).localTransactionId = InvalidLocalTransactionId) +#define GET_VXID_FROM_PGPROC(vxid, proc) ((vxid).backendId = (proc).backendId, (vxid).localTransactionId = (proc).lxid) + +/* + * LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit + * mask indicating a set of held or requested lock types (the bit 1<> 32), \ + (locktag).locktag_field3 = 0, \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_TRANSACTION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_VIRTUALTRANSACTION(locktag, vxid) \ + ((locktag).locktag_field1 = (vxid).backendId, \ + (locktag).locktag_field2 = (uint32)((vxid).localTransactionId & 0xFFFFFFFF),\ + (locktag).locktag_field3 = (uint32)((vxid).localTransactionId >> 32), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_VIRTUALTRANSACTION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (classoid), \ + (locktag).locktag_field3 = (objoid), \ + (locktag).locktag_field4 = (objsubid), \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_OBJECT, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_ADVISORY(locktag, id1, id2, id3, id4) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = (id4), \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_ADVISORY, \ + (locktag).locktag_lockmethodid = USER_LOCKMETHOD) + +#define SET_LOCKTAG_PARTITION(locktag, id1, id2, id3) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_PARTITION, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_PARTITION_SEQUENCE(locktag, id1, id2, id3) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = (id3), \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_PARTITION_SEQUENCE, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +#define SET_LOCKTAG_CSTORE_FREESPACE(locktag, id1, id2) \ + ((locktag).locktag_field1 = (id1), \ + (locktag).locktag_field2 = (id2), \ + (locktag).locktag_field3 = 0, \ + (locktag).locktag_field4 = 0, \ + (locktag).locktag_field5 = 0, \ + (locktag).locktag_type = LOCKTAG_CSTORE_FREESPACE, \ + (locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD) + +/* + * Per-locked-object lock information: + * + * tag -- uniquely identifies the object being locked + * grantMask -- bitmask for all lock types currently granted on this object. + * waitMask -- bitmask for all lock types currently awaited on this object. + * procLocks -- list of PROCLOCK objects for this lock. + * waitProcs -- queue of processes waiting for this lock. + * requested -- count of each lock type currently requested on the lock + * (includes requests already granted!!). + * nRequested -- total requested locks of all types. + * granted -- count of each lock type currently granted on the lock. + * nGranted -- total granted locks of all types. + * + * Note: these counts count 1 for each backend. Internally to a backend, + * there may be multiple grabs on a particular lock, but this is not reflected + * into shared memory. + */ +typedef struct LOCK { + /* hash key */ + LOCKTAG tag; /* unique identifier of lockable object */ + + /* data */ + LOCKMASK grantMask; /* bitmask for lock types already granted */ + LOCKMASK waitMask; /* bitmask for lock types awaited */ + SHM_QUEUE procLocks; /* list of PROCLOCK objects assoc. with lock */ + PROC_QUEUE waitProcs; /* list of PGPROC objects waiting on lock */ + int requested[MAX_LOCKMODES]; /* counts of requested locks */ + int nRequested; /* total of requested[] array */ + int granted[MAX_LOCKMODES]; /* counts of granted locks */ + int nGranted; /* total of granted[] array */ +} LOCK; + +#define LOCK_LOCKMETHOD(lock) ((LOCKMETHODID)(lock).tag.locktag_lockmethodid) + +/* + * We may have several different backends holding or awaiting locks + * on the same lockable object. We need to store some per-holder/waiter + * information for each such holder (or would-be holder). This is kept in + * a PROCLOCK struct. + * + * PROCLOCKTAG is the key information needed to look up a PROCLOCK item in the + * proclock hashtable. A PROCLOCKTAG value uniquely identifies the combination + * of a lockable object and a holder/waiter for that object. (We can use + * pointers here because the PROCLOCKTAG need only be unique for the lifespan + * of the PROCLOCK, and it will never outlive the lock or the proc.) + * + * Internally to a backend, it is possible for the same lock to be held + * for different purposes: the backend tracks transaction locks separately + * from session locks. However, this is not reflected in the shared-memory + * state: we only track which backend(s) hold the lock. This is OK since a + * backend can never block itself. + * + * The holdMask field shows the already-granted locks represented by this + * proclock. Note that there will be a proclock object, possibly with + * zero holdMask, for any lock that the process is currently waiting on. + * Otherwise, proclock objects whose holdMasks are zero are recycled + * as soon as convenient. + * + * releaseMask is workspace for LockReleaseAll(): it shows the locks due + * to be released during the current call. This must only be examined or + * set by the backend owning the PROCLOCK. + * + * Each PROCLOCK object is linked into lists for both the associated LOCK + * object and the owning PGPROC object. Note that the PROCLOCK is entered + * into these lists as soon as it is created, even if no lock has yet been + * granted. A PGPROC that is waiting for a lock to be granted will also be + * linked into the lock's waitProcs queue. + */ +typedef struct PROCLOCKTAG { + /* NB: we assume this struct contains no padding! */ + LOCK* myLock; /* link to per-lockable-object information */ + PGPROC* myProc; /* link to PGPROC of owning backend */ +} PROCLOCKTAG; + +typedef struct PROCLOCK { + /* tag */ + PROCLOCKTAG tag; /* unique identifier of proclock object */ + + /* data */ + LOCKMASK holdMask; /* bitmask for lock types currently held */ + LOCKMASK releaseMask; /* bitmask for lock types to be released */ + SHM_QUEUE lockLink; /* list link in LOCK's list of proclocks */ + SHM_QUEUE procLink; /* list link in PGPROC's list of proclocks */ +} PROCLOCK; + +#define PROCLOCK_LOCKMETHOD(proclock) LOCK_LOCKMETHOD(*((proclock).tag.myLock)) + +/* + * Each backend also maintains a local hash table with information about each + * lock it is currently interested in. In particular the local table counts + * the number of times that lock has been acquired. This allows multiple + * requests for the same lock to be executed without additional accesses to + * shared memory. We also track the number of lock acquisitions per + * ResourceOwner, so that we can release just those locks belonging to a + * particular ResourceOwner. + * + * When holding a lock taken "normally", the lock and proclock fields always + * point to the associated objects in shared memory. However, if we acquired + * the lock via the fast-path mechanism, the lock and proclock fields are set + * to NULL, since there probably aren't any such objects in shared memory. + * (If the lock later gets promoted to normal representation, we may eventually + * update our locallock's lock/proclock fields after finding the shared + * objects.) + * + * Caution: a locallock object can be left over from a failed lock acquisition + * attempt. In this case its lock/proclock fields are untrustworthy, since + * the shared lock object is neither held nor awaited, and hence is available + * to be reclaimed. If nLocks > 0 then these pointers must either be valid or + * NULL, but when nLocks == 0 they should be considered garbage. + */ +typedef struct LOCALLOCKTAG { + LOCKTAG lock; /* identifies the lockable object */ + LOCKMODE mode; /* lock mode for this table entry */ +} LOCALLOCKTAG; + +typedef struct LOCALLOCKOWNER { + /* + * Note: if owner is NULL then the lock is held on behalf of the session; + * otherwise it is held on behalf of my current transaction. + * + * Must use a forward struct reference to avoid circularity. + */ + struct ResourceOwnerData* owner; + int64 nLocks; /* # of times held by this owner */ +} LOCALLOCKOWNER; + +typedef struct LOCALLOCK { + /* tag */ + LOCALLOCKTAG tag; /* unique identifier of locallock entry */ + + /* data */ + LOCK* lock; /* associated LOCK object, if any */ + PROCLOCK* proclock; /* associated PROCLOCK object, if any */ + uint32 hashcode; /* copy of LOCKTAG's hash value */ + int64 nLocks; /* total number of times lock is held */ + int numLockOwners; /* # of relevant ResourceOwners */ + int maxLockOwners; /* allocated size of array */ + bool holdsStrongLockCount; /* bumped FastPathStrongRelatonLocks */ + LOCALLOCKOWNER* lockOwners; /* dynamically resizable array */ +} LOCALLOCK; + +#define LOCALLOCK_LOCKMETHOD(llock) ((llock).tag.lock.locktag_lockmethodid) + +/* + * These structures hold information passed from lmgr internals to the lock + * listing user-level functions (in lockfuncs.c). + */ + +typedef struct LockInstanceData { + LOCKTAG locktag; /* locked object */ + LOCKMASK holdMask; /* locks held by this PGPROC */ + LOCKMODE waitLockMode; /* lock awaited by this PGPROC, if any */ + BackendId backend; /* backend ID of this PGPROC */ + LocalTransactionId lxid; /* local transaction ID of this PGPROC */ + ThreadId pid; /* pid of this PGPROC */ + uint64 sessionid; /* session id of this PGPROC */ + bool fastpath; /* taken via fastpath? */ +} LockInstanceData; + +typedef struct LockData { + int nelements; /* The length of the array */ + LockInstanceData* locks; +} LockData; + +/* Result codes for LockAcquire() */ +typedef enum { + LOCKACQUIRE_NOT_AVAIL, /* lock not available, and dontWait=true */ + LOCKACQUIRE_OK, /* lock successfully acquired */ + LOCKACQUIRE_ALREADY_HELD /* incremented count for lock already held */ +} LockAcquireResult; + +/* Deadlock states identified by DeadLockCheck() */ +typedef enum { + DS_NOT_YET_CHECKED, /* no deadlock check has run yet */ + DS_LOCK_TIMEOUT, /* lock acuqire timeout */ + DS_NO_DEADLOCK, /* no deadlock detected */ + DS_SOFT_DEADLOCK, /* deadlock avoided by queue rearrangement */ + DS_HARD_DEADLOCK, /* deadlock, no way out but ERROR */ + DS_BLOCKED_BY_AUTOVACUUM, /* no deadlock; queue blocked by autovacuum worker */ + DS_BLOCKED_BY_REDISTRIBUTION /* no deadlock; queue blocked by data redistribution */ +} DeadLockState; + +/* + * The lockmgr's shared hash tables are partitioned to reduce contention. + * To determine which partition a given locktag belongs to, compute the tag's + * hash code with LockTagHashCode(), then apply one of these macros. + * NB: NUM_LOCK_PARTITIONS must be a power of 2! + */ +#define LockHashPartition(hashcode) ((hashcode) % NUM_LOCK_PARTITIONS) +#define LockHashPartitionLock(hashcode) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[FirstLockMgrLock + LockHashPartition(hashcode)].lock) + +/* + * function prototypes + */ +extern void InitLocks(void); +extern LockMethod GetLocksMethodTable(const LOCK *lock); +extern uint32 LockTagHashCode(const LOCKTAG *locktag); +extern LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, + bool allow_con_update = false); +extern bool LockIncrementIfExists(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock); +extern LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, + bool report_memory_error, bool allow_con_update = false); +extern void AbortStrongLockAcquire(void); +extern bool LockRelease(const LOCKTAG* locktag, LOCKMODE lockmode, bool sessionLock); +extern void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks); +extern void Check_FastpathBit(); + +extern void LockReleaseSession(LOCKMETHODID lockmethodid); +extern void LockReleaseCurrentOwner(void); +extern void LockReassignCurrentOwner(void); +extern bool LockHasWaiters(const LOCKTAG* locktag, LOCKMODE lockmode, bool sessionLock); +extern VirtualTransactionId* GetLockConflicts(const LOCKTAG* locktag, LOCKMODE lockmode); +extern void AtPrepare_Locks(void); +extern void PostPrepare_Locks(TransactionId xid); +extern int LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock, + PGPROC *proc); +extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode); +extern void GrantAwaitedLock(void); +extern void RemoveFromWaitQueue(PGPROC* proc, uint32 hashcode); +extern Size LockShmemSize(void); +extern LockData* GetLockStatusData(void); + +extern void ReportLockTableError(bool report); + +typedef struct xl_standby_lock { + TransactionId xid; /* xid of holder of AccessExclusiveLock */ + Oid dbOid; + Oid relOid; +} xl_standby_lock; + +extern xl_standby_lock* GetRunningTransactionLocks(int* nlocks); +extern const char* GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode); + +extern void lock_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_postabort(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void lock_twophase_standby_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); + +extern DeadLockState DeadLockCheck(PGPROC* proc); +extern PGPROC* GetBlockingAutoVacuumPgproc(void); +extern PGPROC* GetBlockingRedistributionPgproc(void); +extern void DeadLockReport(void); +extern void RememberSimpleDeadLock(PGPROC* proc1, LOCKMODE lockmode, LOCK* lock, PGPROC* proc2); +extern void InitDeadLockChecking(void); + +extern int LockWaiterCount(const LOCKTAG* locktag); +extern bool IsOtherProcRedistribution(PGPROC* otherProc); +#if defined(LOCK_DEBUG) || defined(USE_ASSERT_CHECKING) +extern void DumpLocks(PGPROC* proc); +extern void DumpAllLocks(void); +#endif + +/* Lock a VXID (used to wait for a transaction to finish) */ +extern void VirtualXactLockTableInsert(const VirtualTransactionId& vxid); +extern void VirtualXactLockTableCleanup(void); +extern bool VirtualXactLock(const VirtualTransactionId& vxid, bool wait); +extern char* LocktagToString(LOCKTAG locktag); + +#endif /* LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/storage/lwlock_be.h postgresql-hll-2.14/include/storage/lwlock_be.h --- postgresql-hll-2.14_old/include/storage/lwlock_be.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lwlock_be.h 2020-12-12 17:06:43.378349729 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lwlock_be.h + * bridge between lwlock.h and pgstat.h + * + * + * IDENTIFICATION + * src/include/storage/lwlock_be.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_STORAGE_LWLOCK_BE_H +#define SRC_INCLUDE_STORAGE_LWLOCK_BE_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "storage/lwlock.h" + +extern void remember_lwlock_acquire(LWLock* lockid); +extern void forget_lwlock_acquire(void); + +#endif // SRC_INCLUDE_STORAGE_LWLOCK_BE_H \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/storage/lwlock.h postgresql-hll-2.14/include/storage/lwlock.h --- postgresql-hll-2.14_old/include/storage/lwlock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lwlock.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,348 @@ +/* ------------------------------------------------------------------------- + * + * lwlock.h + * Lightweight lock manager + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/lwlock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LWLOCK_H +#define LWLOCK_H + +#include "lib/ilist.h" +#include "storage/s_lock.h" +#include "utils/atomic.h" +#include "gs_thread.h" + +typedef volatile uint32 pg_atomic_uint32; +typedef volatile uint64 pg_atomic_uint64; + +/* Names for fixed lwlocks and NUM_INDIVIDUAL_LWLOCKS */ +#include "storage/lwlocknames.h" + +extern const char *const MainLWLockNames[]; + +/* + * It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS + * here, but we need them to figure out offsets within MainLWLockArray, and having + * this file include lock.h or bufmgr.h would be backwards. + */ + +/* Number of partitions of the shared operator-level statistics hashtable */ +#define NUM_OPERATOR_REALTIME_PARTITIONS 32 + +#define NUM_OPERATOR_HISTORY_PARTITIONS 64 + +/* Number of partitions of the shared buffer mapping hashtable */ +#define NUM_BUFFER_PARTITIONS 4096 + +/* change 1024 ->2048 for two cache(compress data cache and meta cache) */ +#define NUM_CACHE_BUFFER_PARTITIONS 2048 + +/* Number of partitions of the shared session-level statistics hashtable */ +#define NUM_SESSION_REALTIME_PARTITIONS 32 + +#define NUM_SESSION_HISTORY_PARTITIONS 64 + +/* Number of partitions of the shared instance statistics hashtable */ +#define NUM_INSTANCE_REALTIME_PARTITIONS 32 + +/* CSN log partitions */ +#define NUM_CSNLOG_PARTITIONS 512 + +/* Clog partitions */ +#define NUM_CLOG_PARTITIONS 256 + +/* Number of partitions the shared lock tables are divided into */ +#define LOG2_NUM_LOCK_PARTITIONS 4 +#define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS) + +/* Number of partitions the shared predicate lock tables are divided into */ +#define LOG2_NUM_PREDICATELOCK_PARTITIONS 4 +#define NUM_PREDICATELOCK_PARTITIONS (1 << LOG2_NUM_PREDICATELOCK_PARTITIONS) + +/* Number of partions the shared unique SQL hashtable */ +#define NUM_UNIQUE_SQL_PARTITIONS 64 + +/* Number of partions the shared instr user hashtable */ +#define NUM_INSTR_USER_PARTITIONS 64 + +/* Number of partions the global plan cache hashtable */ +#define NUM_GPC_PARTITIONS 128 + +/* Number of partions normalized query hashtable */ +#define NUM_NORMALIZED_SQL_PARTITIONS 64 + +/* Number of partions the max page flush lsn file */ +#define NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS 1024 + +/* Number of partions the ngroup info hash table */ +#define NUM_NGROUP_INFO_PARTITIONS 256 + +/* Number of partions the io state hashtable */ +#define NUM_IO_STAT_PARTITIONS 128 + +/* Number of partions the global sequence hashtable */ +#define NUM_GS_PARTITIONS 1024 + +/* + * WARNING---Please keep the order of LWLockTrunkOffset and BuiltinTrancheIds consistent!!! +*/ + +/* Offsets for various chunks of preallocated lwlocks in main array. */ +enum LWLockTrunkOffset { + FirstBufMappingLock = NUM_INDIVIDUAL_LWLOCKS, + FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS, + FirstPredicateLockMgrLock = FirstLockMgrLock + NUM_LOCK_PARTITIONS, + FirstOperatorRealTLock = FirstPredicateLockMgrLock+ NUM_PREDICATELOCK_PARTITIONS, + FirstOperatorHistLock = FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS, + FirstSessionRealTLock = FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS, + FirstSessionHistLock = FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS, + FirstInstanceRealTLock = FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS, + /* Cache Mgr lock IDs */ + FirstCacheSlotMappingLock = FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS, + FirstCSNBufMappingLock = FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS, + FirstCBufMappingLock = FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS, + /* Instrumentaion */ + FirstUniqueSQLMappingLock = FirstCBufMappingLock + NUM_CLOG_PARTITIONS, + FirstInstrUserLock = FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS, + /* global plan cache */ + FirstGPCMappingLock = FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS, + FirstGPCPrepareMappingLock = FirstGPCMappingLock + NUM_GPC_PARTITIONS, + /* ASP */ + FirstASPMappingLock = FirstGPCPrepareMappingLock + NUM_GPC_PARTITIONS, + /* global sequence */ + FirstGlobalSeqLock = FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS, + + FirstNormalizedSqlLock = FirstGlobalSeqLock + NUM_GS_PARTITIONS, + FirstMPFLLock = FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS, + + FirstNGroupMappingLock = FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS, + FirstIOStatLock = FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS, + + /* must be last: */ + NumFixedLWLocks = FirstIOStatLock + NUM_IO_STAT_PARTITIONS +}; + +/* + * WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!! + * + * Every tranche ID less than NUM_INDIVIDUAL_LWLOCKS is reserved; also, + * we reserve additional tranche IDs for builtin tranches not included in + * the set of individual LWLocks. A call to LWLockNewTrancheId(to be added in future) will never + * return a value less than LWTRANCHE_NATIVE_TRANCHE_NUM. + */ +enum BuiltinTrancheIds +{ + LWTRANCHE_BUFMAPPING = NUM_INDIVIDUAL_LWLOCKS, + LWTRANCHE_LOCK_MANAGER, + LWTRANCHE_PREDICATE_LOCK_MANAGER, + LWTRANCHE_OPERATOR_REAL_TIME, + LWTRANCHE_OPERATOR_HISTORY, + LWTRANCHE_SESSION_REAL_TIME, + LWTRANCHE_SESSION_HISTORY, + LWTRANCHE_INSTANCE_REAL_TIME, + LWTRANCHE_CACHE_SLOT_MAPPING, + LWTRANCHE_CSN_BUFMAPPING, + LWTRANCHE_CLOG_BUFMAPPING, + LWTRANCHE_UNIQUE_SQLMAPPING, + LWTRANCHE_INSTR_USER, + LWTRANCHE_GPC_MAPPING, + LWTRANCHE_GPC_PREPARE_MAPPING, + LWTRANCHE_ASP_MAPPING, + LWTRANCHE_GlobalSeq, + LWTRANCHE_NORMALIZED_SQL, + LWTRANCHE_BUFFER_IO_IN_PROGRESS, + LWTRANCHE_BUFFER_CONTENT, + LWTRANCHE_DATA_CACHE, + LWTRANCHE_META_CACHE, + LWTRANCHE_PROC, + LWTRANCHE_REPLICATION_SLOT, + LWTRANCHE_ASYNC_CTL, + LWTRANCHE_CLOG_CTL, + LWTRANCHE_CSNLOG_CTL, + LWTRANCHE_MULTIXACTOFFSET_CTL, + LWTRANCHE_MULTIXACTMEMBER_CTL, + LWTRANCHE_OLDSERXID_SLRU_CTL, + LWTRANCHE_WAL_INSERT, + LWTRANCHE_DOUBLE_WRITE, + LWTRANCHE_DW_SINGLE_POS, + LWTRANCHE_DW_SINGLE_WRITE, + LWTRANCHE_ACCOUNT_TABLE, + LWTRANCHE_EXTEND, // For general 3rd plugin + LWTRANCHE_MPFL, + LWTRANCHE_GTT_CTL, // For GTT + LWTRANCHE_NGROUP_MAPPING, + LWTRANCHE_MATVIEW_SEQNO, + LWTRANCHE_IO_STAT, + /* + * Each trancheId above should have a corresponding item in BuiltinTrancheNames; + */ + LWTRANCHE_NATIVE_TRANCHE_NUM, + LWTRANCHE_UNKNOWN = 65535 +}; + +#ifndef cpu_relax +// New lock +#if defined(__x86_64__) || defined(__x86__) +#define cpu_relax() asm volatile("pause\n": : :"memory") +#else // some web says yield:::memory +#define cpu_relax() asm volatile("" : : : "memory") // equivalent to "rep; nop" +#endif +#endif + +typedef enum LWLockMode { + LW_EXCLUSIVE, + LW_SHARED, + LW_WAIT_UNTIL_FREE /* A special mode used in PGPROC->lwlockMode, + * when waiting for lock to become free. Not + * to be used as LWLockAcquire argument */ +} LWLockMode; + +/* To avoid pointer misuse during hash search, we wrapper the LWLock* in the following structure. */ +struct LWLock; +typedef struct { + LWLock* lock; +} LWLockAddr; + +typedef struct { + LWLockAddr lock_addr; + LWLockMode lock_sx; +} lwlock_id_mode; + +struct PGPROC; + +typedef struct LWLock { + uint16 tranche; /* tranche ID */ + pg_atomic_uint32 state; /* state of exlusive/nonexclusive lockers */ + dlist_head waiters; /* list of waiting PGPROCs */ +#ifdef LOCK_DEBUG + pg_atomic_uint32 nwaiters; /* number of waiters */ + struct PGPROC* owner; /* last exlusive owner of the lock */ +#endif +#ifdef ENABLE_THREAD_CHECK + pg_atomic_uint32 rwlock; + pg_atomic_uint32 listlock; +#endif +} LWLock; + +/* + * All the LWLock structs are allocated as an array in shared memory. + * (LWLockIds are indexes into the array.) We force the array stride to + * be a power of 2, which saves a few cycles in indexing, but more + * importantly also ensures that individual LWLocks don't cross cache line + * boundaries. This reduces cache contention problems, especially on AMD + * Opterons. (Of course, we have to also ensure that the array start + * address is suitably aligned.) + * + * On a 32-bit platforms a LWLock will these days fit into 16 bytes, but since + * that didn't use to be the case and cramming more lwlocks into a cacheline + * might be detrimental performancewise we still use 32 byte alignment + * there. So, both on 32 and 64 bit platforms, it should fit into 32 bytes + * unless slock_t is really big. We allow for that just in case. + * + * Add even more padding so that each LWLock takes up an entire cache line; + * this is useful, for example, in the main LWLock array, where the overall number of + * locks is small but some are heavily contended. + * + * In future, the LWLock should be devided into two parts: One uses LWLockPadded, + * the other uses LWLockMinimallyPadded. This should relax the requirement for the single global array. + */ +#ifdef __aarch64__ +#define LWLOCK_PADDED_SIZE PG_CACHE_LINE_SIZE +#else +#define LWLOCK_PADDED_SIZE (sizeof(LWLock) <= 32 ? 32 : 64) +#endif + +typedef union LWLockPadded { + LWLock lock; + char pad[LWLOCK_PADDED_SIZE]; +} LWLockPadded; + +extern PGDLLIMPORT LWLockPadded *MainLWLockArray; + +/* + * We use this structure to keep track of locked LWLocks for release + * during error recovery. The maximum size could be determined at runtime + * if necessary, but it seems unlikely that more than a few locks could + * ever be held simultaneously. + */ +#define MAX_SIMUL_LWLOCKS 4224 + +/* struct representing the LWLocks we're holding */ +typedef struct LWLockHandle { + LWLock* lock; + LWLockMode mode; +} LWLockHandle; + +#define GetMainLWLockByIndex(i) \ + (&t_thrd.shemem_ptr_cxt.mainLWLockArray[i].lock) + +extern void DumpLWLockInfo(); +extern LWLock* LWLockAssign(int trancheId); +extern void LWLockInitialize(LWLock* lock, int tranche_id); +extern bool LWLockAcquire(LWLock* lock, LWLockMode mode, bool need_update_lockid = false); +extern bool LWLockConditionalAcquire(LWLock* lock, LWLockMode mode); +extern bool LWLockAcquireOrWait(LWLock* lock, LWLockMode mode); +extern void LWLockRelease(LWLock* lock); +extern void LWLockReleaseClearVar(LWLock* lock, uint64* valptr, uint64 val); +extern void LWLockReleaseAll(void); +extern bool LWLockHeldByMe(LWLock* lock); +extern bool LWLockHeldByMeInMode(LWLock* lock, LWLockMode mode); +extern void LWLockReset(LWLock* lock); + +extern void LWLockOwn(LWLock* lock); +extern void LWLockDisown(LWLock* lock); + +extern bool LWLockWaitForVar(LWLock* lock, uint64* valptr, uint64 oldval, uint64* newval); +extern void LWLockUpdateVar(LWLock* lock, uint64* valptr, uint64 value); + +extern int NumLWLocks(void); +extern Size LWLockShmemSize(void); +extern void CreateLWLocks(void); + +extern void RequestAddinLWLocks(int n); +extern const char* GetBuiltInTrancheName(int trancheId); + +/* + * There is another, more flexible method of obtaining lwlocks. First, call + * LWLockNewTrancheId just once to obtain a tranche ID; this allocates from + * a shared counter. Next, each individual process using the tranche should + * call LWLockRegisterTranche() to associate that tranche ID with a name. + * Finally, LWLockInitialize should be called just once per lwlock, passing + * the tranche ID as an argument. + * + * It may seem strange that each process using the tranche must register it + * separately, but dynamic shared memory segments aren't guaranteed to be + * mapped at the same address in all coordinating backends, so storing the + * registration in the main shared memory segment wouldn't work for that case. + */ +extern void LWLockRegisterTranche(int tranche_id, const char *tranche_name); + +extern void wakeup_victim(LWLock *lock, ThreadId victim_tid); +extern int *get_held_lwlocks_num(void); +extern uint32 get_held_lwlocks_maxnum(void); +extern void* get_held_lwlocks(void); +extern void copy_held_lwlocks(void* heldlocks, lwlock_id_mode* dst, int num_heldlocks); +extern const char* GetLWLockIdentifier(uint32 classId, uint16 eventId); +extern LWLockMode GetHeldLWLockMode(LWLock* lock); + +extern const char** LWLockTrancheArray; +extern int LWLockTranchesAllocated; + +#define T_NAME(lock) \ + ((lock) ? (LWLockTrancheArray[(lock)->tranche]) : ("")) + +/* + * Peviously, we used an enum type called LWLockId to refer + * to LWLocks. New code should instead use LWLock *. However, for the + * convenience of third-party code, we include the following typedef. + */ +//typedef LWLock *LWLockId; // Uncomment it later. Now should disable to find bugs + +#endif /* LWLOCK_H */ diff -uprN postgresql-hll-2.14_old/include/storage/lwlocknames.h postgresql-hll-2.14/include/storage/lwlocknames.h --- postgresql-hll-2.14_old/include/storage/lwlocknames.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lwlocknames.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,106 @@ +/* autogenerated from src/gausskernel/storage/lmgr/lwlocknames.txt, do not edit */ +/* there is deliberately not an #ifndef LWLOCKNAMES_H here */ + +#define BufFreelistLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[0].lock) +#define CUSlotListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[1].lock) +#define ShmemIndexLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[2].lock) +#define OidGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[3].lock) +#define XidGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[4].lock) +#define ProcArrayLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[5].lock) +#define SInvalReadLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[6].lock) +#define SInvalWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[7].lock) +#define WALBufMappingLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[8].lock) +#define WALWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[9].lock) +#define ControlFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[10].lock) +#define CheckpointLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[11].lock) +#define CLogControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[12].lock) +#define SubtransControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[13].lock) +#define MultiXactGenLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[14].lock) +#define MultiXactOffsetControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[15].lock) +#define MultiXactMemberControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[16].lock) +#define RelCacheInitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[17].lock) +#define CheckpointerCommLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[18].lock) +#define TwoPhaseStateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[19].lock) +#define TablespaceCreateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[20].lock) +#define BtreeVacuumLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[21].lock) +#define AddinShmemInitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[22].lock) +#define AutovacuumLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[23].lock) +#define AutovacuumScheduleLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[24].lock) +#define AutoanalyzeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[25].lock) +#define SyncScanLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[26].lock) +#define BarrierLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[27].lock) +#define NodeTableLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[28].lock) +#define PoolerLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[29].lock) +#define AlterPortLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[30].lock) +#define RelationMappingLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[31].lock) +#define AsyncCtlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[32].lock) +#define AsyncQueueLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[33].lock) +#define SerializableXactHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[34].lock) +#define SerializableFinishedListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[35].lock) +#define SerializablePredicateLockListLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[36].lock) +#define OldSerXidLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[37].lock) +#define FileStatLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[38].lock) +#define SyncRepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[39].lock) +#define DataSyncRepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[40].lock) +#define DataFileIdCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[41].lock) +#define CStoreColspaceCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[42].lock) +#define CStoreCUCacheSweepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[43].lock) +#define MetaCacheSweepLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[44].lock) +#define FdwPartitionCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[45].lock) +#define DfsConnectorCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[46].lock) +#define dummyServerInfoCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[47].lock) +#define ExtensionConnectorLibLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[48].lock) +#define SearchServerLibLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[49].lock) +#define DfsUserLoginLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[50].lock) +#define DfsSpaceCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[51].lock) +#define LsnXlogChkFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[52].lock) +#define GTMHostInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[53].lock) +#define ReplicationSlotAllocationLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[54].lock) +#define ReplicationSlotControlLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[55].lock) +#define FullBuildXlogCopyStartPtrLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[56].lock) +#define LogicalReplicationSlotPersistentDataLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[57].lock) +#define ResourcePoolHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[58].lock) +#define WorkloadStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[59].lock) +#define WorkloadIoStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[60].lock) +#define WorkloadCGroupHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[61].lock) +#define WorkloadSessionInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[62].lock) +#define OBSGetPathLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[63].lock) +#define WorkloadUserInfoLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[64].lock) +#define WorkloadRecordLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[65].lock) +#define WorkloadIOUtilLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[66].lock) +#define WorkloadNodeGroupLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[67].lock) +#define JobShmemLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[68].lock) +#define OBSRuntimeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[69].lock) +#define LLVMDumpIRLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[70].lock) +#define LLVMParseIRLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[71].lock) +#define RPNumberLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[72].lock) +#define ClusterRPLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[73].lock) +#define WaitCountHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[74].lock) +#define InstrWorkloadLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[75].lock) +#define PgfdwLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[76].lock) +#define CBMParseXlogLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[77].lock) +#define DelayDDLLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[78].lock) +#define RelfilenodeReuseLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[79].lock) +#define BadBlockStatHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[80].lock) +#define RowPageReplicationLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[81].lock) +#define RcvWriteLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[82].lock) +#define InstanceTimeLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[83].lock) +#define PercentileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[84].lock) +#define XlogRemoveSegLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[85].lock) +#define DnUsedSpaceHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[86].lock) +#define CsnMinLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[87].lock) +#define GPCCommitLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[88].lock) +#define GPCClearLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[89].lock) +#define GPCTimelineLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[90].lock) +#define TsTagsCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[91].lock) +#define MaxPageFlushLsnFileLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[92].lock) +#define CaptureViewFileHashLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[93].lock) +#define StreamingEngineConnLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[94].lock) +#define StreamingEngineExecLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[95].lock) +#define PartIdCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[96].lock) +#define PartOidCacheLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[97].lock) +#define DeleteCompactionLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[98].lock) +#define DeleteConsumerLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[99].lock) +#define ConsumerStateLock (&t_thrd.shemem_ptr_cxt.mainLWLockArray[100].lock) + +#define NUM_INDIVIDUAL_LWLOCKS 101 diff -uprN postgresql-hll-2.14_old/include/storage/lz4_file.h postgresql-hll-2.14/include/storage/lz4_file.h --- postgresql-hll-2.14_old/include/storage/lz4_file.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/lz4_file.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * lz4_file.h + * All interface of LZ4 compress and write file + * + * IDENTIFICATION + * src/include/storage/lz4_file.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef LZ4FILE_H +#define LZ4FILE_H + +#define LZ4FileSrcBufSize (BLCKSZ * 8) + +typedef struct LZ4File { + File file; + off_t readOffset; + int compressBufSize; + int srcDataSize; + char* srcBuf; /* a temporary buffer for writing data. */ + char* compressBuf; /* a temporary buffer for compress data. */ + off_t curOffset; /* next read/write position in buffer */ + +public: + void Reset() + { + file = FILE_INVALID; + readOffset = 0; + srcDataSize = 0; + srcBuf = NULL; + compressBuf = NULL; + compressBufSize = 0; + curOffset = 0; + } +} LZ4File; + +extern LZ4File* LZ4FileCreate(bool interXact); +extern size_t LZ4FileWrite(LZ4File* lz4File, char* buffer, size_t size); +extern size_t LZ4FileRead(LZ4File* lz4File, char* buffer, size_t size); +extern void LZ4FileClose(LZ4File* lz4File); +extern void LZ4FileRewind(LZ4File* lz4File); +extern void LZ4FileClearBuffer(LZ4File* lz4File); + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/mot/jit_def.h postgresql-hll-2.14/include/storage/mot/jit_def.h --- postgresql-hll-2.14_old/include/storage/mot/jit_def.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/mot/jit_def.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,196 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * jit_def.h + * Jit execution constants. + * + * IDENTIFICATION + * src/include/storage/mot/jit_def.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JIT_DEF_H +#define JIT_DEF_H + +#include + +/** @define Impose a hard coded limit on depth of parsed expression. */ +#define MOT_JIT_MAX_EXPR_DEPTH 10 + +/** @define We support up to 8 arguments for NULL management in expressions. */ +#define MOT_JIT_EXPR_ARG_COUNT 8 + +/** @define The maximum number of registers used in a pseudo-function execution. */ +#define MOT_JIT_MAX_FUNC_REGISTERS 4096 + +/** @define The maximum number of arguments in a Boolean expression. */ +#define MOT_JIT_MAX_BOOL_EXPR_ARGS 2 + +/** @define The maximum number of arguments in a function call expression. */ +#define MOT_JIT_MAX_FUNC_EXPR_ARGS 3 + +namespace JitExec { + +// To debug JIT execution, #define MOT_JIT_DEBUG +// To use advanced WHERE clause operators, #define MOT_JIT_ADVANCED_WHERE_OP +// To enable features required for JIT testing, #define MOT_JIT_TEST + +/** @enum JitCommandType Command types supported by jitted queries. */ +enum JitCommandType : uint8_t { + /** @var Invalid command type. */ + JIT_COMMAND_INVALID, + + /** @var Simple insert command. */ + JIT_COMMAND_INSERT, + + /** @var Simple (point-query) update command. */ + JIT_COMMAND_UPDATE, + + /** @var Simple (point-query) select command. */ + JIT_COMMAND_SELECT, + + /** @var Simple (point-query) delete command. */ + JIT_COMMAND_DELETE, + + /** @var Range update command. */ + JIT_COMMAND_RANGE_UPDATE, + + /** @var Unordered range select command. */ + JIT_COMMAND_RANGE_SELECT, + + /** @var Unordered full-scan select command. */ + JIT_COMMAND_FULL_SELECT, + + /** @var Aggregate range select command. */ + JIT_COMMAND_AGGREGATE_RANGE_SELECT, + + /** @var Join command resulting in a single tuple. */ + JIT_COMMAND_POINT_JOIN, + + /** @var Join range select command. */ + JIT_COMMAND_RANGE_JOIN, + + /** @var Join aggregate command. */ + JIT_COMMAND_AGGREGATE_JOIN, + + /** @var Compound select command (point-select with sub-queries). */ + JIT_COMMAND_COMPOUND_SELECT +}; + +/** @enum JIT context usage constants. */ +enum JitContextUsage : uint8_t { + /** @var JIT context is used in global context. */ + JIT_CONTEXT_GLOBAL, + + /** @var JIT context is used in session-local context. */ + JIT_CONTEXT_LOCAL +}; + +/** @enum Constants for classifying operators in WHERE clause. */ +enum JitWhereOperatorClass : uint8_t { + /** @var Invalid where operator class. */ + JIT_WOC_INVALID, + + /** @var "Equals" where operator class. */ + JIT_WOC_EQUALS, + + /** @var "Less than" where operator class. */ + JIT_WOC_LESS_THAN, + + /* @var "Greater than" where operator class. */ + JIT_WOC_GREATER_THAN, + + /** @var "Less than" or "equals to" where operator class. */ + JIT_WOC_LESS_EQUALS, + + /** @var "Greater than" or "equals to" where operator class */ + JIT_WOC_GREATER_EQUALS +}; + +/** @enum Integer-comparison operator types. */ +enum JitICmpOp { + /** @var Designates "equals" operator. */ + JIT_ICMP_EQ, + + /** @var Designates "not-equals" operator. */ + JIT_ICMP_NE, + + /** @var Designates "greater-than" operator. */ + JIT_ICMP_GT, + + /** @var Designates "greater-equals" operator. */ + JIT_ICMP_GE, + + /** @var Designates "less-than" operator. */ + JIT_ICMP_LT, + + /** @var Designates "less-equals" operator. */ + JIT_ICMP_LE, +}; + +/** @enum Range scan type constants. */ +enum JitRangeScanType { + /** @var No range scan. */ + JIT_RANGE_SCAN_NONE, + + /** @var Main range scan. In JOIN queries this designates the outer loop scan. */ + JIT_RANGE_SCAN_MAIN, + + /** @var Designates inner loop range scan. Can be specified only on JOIN queries.*/ + JIT_RANGE_SCAN_INNER, + + /** @var Sub-query range scan. */ + JIT_RANGE_SCAN_SUB_QUERY +}; + +/** @enum Range bound mode constants. */ +enum JitRangeBoundMode { + /** @var Designates no range bound mode specification. */ + JIT_RANGE_BOUND_NONE, + + /** @var Designates to include the range bound in the range scan. */ + JIT_RANGE_BOUND_INCLUDE, + + /** @var Designates to exclude the range bound from the range scan. */ + JIT_RANGE_BOUND_EXCLUDE +}; + +/** @enum Range iterator type. */ +enum JitRangeIteratorType { + /** @var Designated no range iterator specification. */ + JIT_RANGE_ITERATOR_NONE, + + /** @var Designates the iterator pointing to the start of the range. */ + JIT_RANGE_ITERATOR_START, + + /** @var Designates the iterator pointing to the end of the range. */ + JIT_RANGE_ITERATOR_END +}; + +/** @enum Query sort order */ +enum JitQuerySortOrder { + /** @var Invalid query sort order. */ + JIT_QUERY_SORT_INVALID, + + /** @var Ascending query sort order. */ + JIT_QUERY_SORT_ASCENDING, + + /** @var Descending query sort order. */ + JIT_QUERY_SORT_DESCENDING +}; +} // namespace JitExec + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/mot/jit_exec.h postgresql-hll-2.14/include/storage/mot/jit_exec.h --- postgresql-hll-2.14_old/include/storage/mot/jit_exec.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/mot/jit_exec.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,116 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * jit_exec.h + * Interface for jit execution. + * + * IDENTIFICATION + * src/include/storage/mot/jit_exec.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JIT_EXEC_H +#define JIT_EXEC_H + +#include "postgres.h" +#include "nodes/params.h" +#include "executor/tuptable.h" +#include "nodes/parsenodes.h" + +#include "jit_def.h" + +namespace JitExec { + +// forward declaration +struct JitContext; +struct JitContextPool; +struct JitPlan; + +/** @brief Initializes the JIT module for MOT. */ +extern bool JitInitialize(); + +/** @brief Destroys the JIT module for MOT. */ +extern void JitDestroy(); + +/** @brief Queries whether MOT JIT compilation and execution is enabled. */ +extern bool IsMotCodegenEnabled(); + +/** @brief Quereis whether pseudo-LLVM is forced on platforms where LLVM is natively supported. */ +extern bool IsMotPseudoCodegenForced(); + +/** @brief Queries whether informative printing is enabled for MOT JIT compilation. */ +extern bool IsMotCodegenPrintEnabled(); + +/** @brief Queries for the per-session limit of JIT queries. */ +extern uint32_t GetMotCodegenLimit(); + +/** @brief Turn off MOT JIT compilation and execution. */ +extern void DisableMotCodegen(); + +/** + * @brief Queries whether a SQL query to be executed by MM Engine is jittable. + * @param query The parsed SQL query to examine. + * @param queryString The query text. + * @return The JIT plan if the query is jittable, otherwise NULL. + */ +extern JitPlan* IsJittable(Query* query, const char* queryString); + +/** + * @brief Generate jitted code for a query. + * @param query The parsed SQL query for which jitted code is to be generated. + * @param queryString The query text. + * @param jitPlan The JIT plan produced during the call to @ref IsJittable(). + * @return The context of the jitted code required for later execution. + */ +extern JitContext* JitCodegenQuery(Query* query, const char* queryString, JitPlan* jitPlan); + +/** @brief Resets the scan iteration counter for the JIT context. */ +extern void JitResetScan(JitContext* jitContext); + +/** + * @brief Executed a previously jitted query. + * @param jitContext The context produced by a previous call to @ref JitCodegenQuery(). + * @param params The list of bound parameters passed to the query. + * @param[out] slot The slot used for reporting select result. + * @param[out] tuplesProcessed The variable used to report the number of processed tuples. + * @param[out] scanEnded The variable used to report if a range scan ended. + * @return Zero if succeeded, otherwise an error code. + * @note This function may cause transaction abort. + */ +extern int JitExecQuery( + JitContext* jitContext, ParamListInfo params, TupleTableSlot* slot, uint64_t* tuplesProcessed, int* scanEnded); + +/** + * @brief Purges the global cache of JIT source stencils from all entries that refer the given relation id. + * @param relationId The external identifier of the relation to be purged. + * @param purgeOnly Specifies whether to just purge all keys/indexes referring to the given relation, or should the JIT + * context also be set as expired (which triggers re-compilation of the JIT function). + */ +extern void PurgeJitSourceCache(uint64_t relationId, bool purgeOnly); + +// externalize functions defined elsewhere + +/** @brief Destroys a jit context produced by a previous call to JitCodegenQuery. */ +extern void DestroyJitContext(JitContext* jitContext); + +/** @brief De-allocates a jit context pool for a specific session. */ +extern void FreeSessionJitContextPool(JitContextPool* jitContextPool); + +/** @brief Releases all resources associated with a plan.*/ +extern void JitDestroyPlan(JitPlan* plan); +} // namespace JitExec + +#endif // JIT_EXEC_H diff -uprN postgresql-hll-2.14_old/include/storage/mot/mot_fdw.h postgresql-hll-2.14/include/storage/mot/mot_fdw.h --- postgresql-hll-2.14_old/include/storage/mot/mot_fdw.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/mot/mot_fdw.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * mot_fdw.h + * MOT Foreign Data Wrapper interfaces used by the envelop during + * initialization, recovery, etc. + * + * IDENTIFICATION + * src/include/storage/mot/mot_fdw.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MOT_FDW_H +#define MOT_FDW_H + +#include + +/** @brief Initializes MOT engine. */ +extern void InitMOT(); + +/** @brief Shutdown the MOT engine. */ +extern void TermMOT(); + +/** + * @brief Initializes the thread level and recovers the data from MOT checkpoint. + * Should be called before XLOG recovery in the envelop. + */ +extern void MOTRecover(); + +/** + * @brief Cleans up the resources and finishes the recovery. + * Should be called at the end of recovery in the envelop. + */ +extern void MOTRecoveryDone(); + +/** + * @brief Initializes the thread level resources for MOT redo recovery. + * If the MOT redo recovery is done in a separate thread other than the main thread which calls MOTRecover(), + * this API should be called to initialize the thread before performing redo recovery. + */ +extern void MOTBeginRedoRecovery(); + +/** + * @brief Cleans up the thread level resources. Used with MOTBeginRedoRecovery(). + * Should be called at the end of the thread after finishing redo recovery. + */ +extern void MOTEndRedoRecovery(); + +/** + * @brief Performs a commit or abort on an in-process two-phase transaction. Invoked from gs_clean. + * @param txid Transaction ID + * @param isCommit Specifies to commit or abort the transaction. + */ +extern void MOTProcessRecoveredTransaction(uint64_t txid, bool isCommit); + +/** + * @brief Notification from thread pool that a session ended (only when thread pool is ENABLED). + */ +extern void MOTOnSessionClose(); + +/** + * The following helpers APIs are used by base backup to fetch and send the MOT checkpoint files. + */ +extern void MOTCheckpointFetchLock(); +extern void MOTCheckpointFetchUnlock(); + +/** + * @brief Checks if an MOT checkpoint exists and returns its paths. + * @param ctrlFilePath a buffer to hold the MOT ctrl file path. + * @param ctrlLen the length of the given ctrl file path buffer. + * @param checkpointDir a buffer to hold the checkpoint path. + * @param checkpointLen the length of the given checkpoint path buffer. + * @param basePathLen the length of the base path. + * @return True if an MOT checkpoint exists, False indicates that no MOT checkpoint is present. + */ +extern bool MOTCheckpointExists( + char* ctrlFilePath, size_t ctrlLen, char* checkpointDir, size_t checkpointLen, size_t& basePathLen); + +#endif // MOT_FDW_H diff -uprN postgresql-hll-2.14_old/include/storage/mot/mot_xlog.h postgresql-hll-2.14/include/storage/mot/mot_xlog.h --- postgresql-hll-2.14_old/include/storage/mot/mot_xlog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/mot/mot_xlog.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * mot_xlog.h + * Definitions of MOT xlog interface + * + * IDENTIFICATION + * src/include/storage/mot/mot_xlog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MOT_XLOG_H +#define MOT_XLOG_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +extern void MOTRedo(XLogReaderState *record); +extern void MOTDesc(StringInfo buf, XLogReaderState *record); + +#endif /* MOT_XLOG_H */ diff -uprN postgresql-hll-2.14_old/include/storage/off.h postgresql-hll-2.14/include/storage/off.h --- postgresql-hll-2.14_old/include/storage/off.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/off.h 2020-12-12 17:06:43.379349741 +0800 @@ -0,0 +1,55 @@ +/* ------------------------------------------------------------------------- + * + * off.h + * POSTGRES disk "offset" definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/off.h + * + * ------------------------------------------------------------------------- + */ +#ifndef OFF_H +#define OFF_H + +#include "storage/itemid.h" +/* + * OffsetNumber: + * + * this is a 1-based index into the linp (ItemIdData) array in the + * header of each disk page. + */ +typedef uint16 OffsetNumber; + +#define InvalidOffsetNumber ((OffsetNumber)0) +#define FirstOffsetNumber ((OffsetNumber)1) +#define MaxOffsetNumber ((OffsetNumber)(BLCKSZ / sizeof(ItemIdData))) +#define OffsetNumberMask (0xffff) /* valid uint16 bits */ + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * OffsetNumberIsValid + * True iff the offset number is valid. + */ +#define OffsetNumberIsValid(offsetNumber) \ + ((bool)((offsetNumber != InvalidOffsetNumber) && (offsetNumber <= MaxOffsetNumber))) + +/* + * OffsetNumberNext + * OffsetNumberPrev + * Increments/decrements the argument. These macros look pointless + * but they help us disambiguate the different manipulations on + * OffsetNumbers (e.g., sometimes we subtract one from an + * OffsetNumber to move back, and sometimes we do so to form a + * real C array index). + */ +#define OffsetNumberNext(offsetNumber) ((OffsetNumber)(1 + (offsetNumber))) +#define OffsetNumberPrev(offsetNumber) ((OffsetNumber)(-1 + (offsetNumber))) + +#endif /* OFF_H */ diff -uprN postgresql-hll-2.14_old/include/storage/pagecompress.h postgresql-hll-2.14/include/storage/pagecompress.h --- postgresql-hll-2.14_old/include/storage/pagecompress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/pagecompress.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,300 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * pagecompress.h + * page compression manager routines + * + * + * IDENTIFICATION + * src/include/storage/pagecompress.h + * + * mixed compression methods will be used, including delta/prefix/dict compression. + * delta compression would apply to data types: number; datetime; timestamp; number string; + * prefix compression would apply to data types: string; + * dictionary compression can apply to all the data types. + * one column only use the single one compression method. + * compressed tuples will be placed into one page with compression meta data. + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PAGE_COMPRESS_H +#define PAGE_COMPRESS_H + +#include "c.h" +#include "access/htup.h" +#include "utils/relcache.h" +#include "storage/bufpage.h" +#include "utils/hsearch.h" + +/* Compression Mode + * + * CMPR_NUMSTR is a special kind of CMPR_DELTA. + * chars ('0'-'9') can be handled by delta-compression based on '0'. + * so that each number would be storaged in 4bits, and compression ratio is 2:1. + * !!! Note that You must also change ATT_CMPR_UNDEFINED and others in parsenode.h + * Description: we should refine code to remove these redundancy macro + */ +#define CMPR_DELTA 1 +#define CMPR_DICT 2 +#define CMPR_PREFIX 3 +#define CMPR_NUMSTR 4 +#define CMPR_NONE 0 +#define CMPR_UNDEF 0x7F + +typedef struct DictItemData { + char* itemData; + int16 itemSize; +} DictItemData; + +struct ColArray { + Datum* val; + bool* nulls; + int num; +}; + +struct DeltaCmprMeta { + Datum MinVal; + Datum MaxVal; + int bytes; +}; + +class DictCmprMeta { +public: + typedef struct { + DictItemData item; + unsigned char id; + } ItemEntry; + + void BuildHashTbl(MemoryContext memCxt); + unsigned char GetDictItemId(DictItemData* key, bool& found); + void Destroy(); + void GetDictItems(char* buf) const; + + int dictItemNum; + + /* MAX dictionary item number <= MAX_DICITEMID */ + DictItemData dictItems[256]; + int totalBytes; + + HTAB* m_hash; +}; + +struct PrefixCmprMeta { + char* prefixStr; + int len; +}; + +typedef union CmprMetaUnion { + DeltaCmprMeta deltaInfo; + DictCmprMeta dicInfo; + PrefixCmprMeta prefixInfo; +} CmprMetaUnion; + +typedef int (*CompareFuncPtr)(Datum, Datum); +typedef int64 (*MinusFuncPtr)(Datum, Datum); +typedef Datum (*PlusFuncPtr)(Datum, int64); + +typedef struct { + Oid typeOid; + CompareFuncPtr compare; + MinusFuncPtr minus; + PlusFuncPtr plus; +} NumberTypeOpt; + +typedef struct { + DictItemData key; + int16 hitCount; + bool beChoose; +} DictItemEntry; + +/* + * PageCompress + * Compress one page using multiple compression method. + * 1. Dictonary compression. + * 2. Delta value encoding. + * 3. Prefix compression. + */ +class PageCompress : public BaseObject { +public: + PageCompress(Relation rel, MemoryContext memCtx); + virtual ~PageCompress(); + + /* compress api */ + void SetBatchTuples(HeapTuple* tups, int ntups, bool last); + bool CompressOnePage(void); + + HeapTuple* GetOutputTups(void) + { + return m_outputTups; + } + int GetOutputCount(void) + { + return m_outputTupsNum; + } + const char* GetCmprHeaderData(void) + { + return m_cmprHeaderData; + } + int GetCmprHeaderSize(void) + { + return m_cmprHeaderSize; + } + int Remains(void) + { + return (m_inTupsNum - m_current); + } + const MemoryContext SelfMemCnxt(void) + { + return m_pageMemCnxt; + } + void BackWrite(void); + void ForwardWrite(void); + + /* decompress api */ + static void* FetchAttrCmprMeta(char* metaStart, const int attrRawLen, int* metaSize, char* mode); + static int GetAttrCmprValSize(char mode, int attlen, void* metaInfo, const char* attrStart); + static bool NeedExternalBuf(char mode); + static int UncompressOneAttr(char mode, char attalign, int attlen, void* metaInfo, char* attrStart, + int* attrCmprsValSize, char* uncmprValBuf); + static Datum UncompressOneAttr( + char mode, void* metaInfo, Oid typeOid, int attlen, char* attrStart, int* attrCmprsValSize); + +private: + /* compress methods */ + void CompressOneAttr(Datum val, bool null, FormCmprTupleData* formTuple, int col); + ColArray* DeformTups(HeapTuple* tups, int ntups); + + /* Choose compression method for each column */ + void ChooseMethodForFixedLenType(ColArray* colArray, int col); + void ChooseMethodForVaryLenType(ColArray* colArray, int col); + void ChooseCmprMethod(ColArray* colArray); + bool SetCmprMethod(ColArray* colArray, int col, int mode); + + /* delta compress methods */ + DeltaCmprMeta* DeltaGetCmprMeta(ColArray* colArray, const NumberTypeOpt* opt) const; + bool DeltaCompress(DeltaCmprMeta* deltaInfo, const NumberTypeOpt* opt, Datum val, unsigned char* deltaBuf) const; + static Datum DeltaUncompress(DeltaCmprMeta* delta, const NumberTypeOpt* opt, unsigned char* start); + + /* prefix compress methods */ + template + int PrefixLen(Datum str1, Datum str2); + template + char* PrefixGetCmprMeta(ColArray* colArray, int& prefixLen); + template + bool PrefixCompress(PrefixCmprMeta* prefix, Datum val, Datum& cmprsVal, int& cmprsValSize); + static Datum PrefixUncompress(int attlen, PrefixCmprMeta* prefix, char* start, int* valSize, + char* uncmprValBuf = NULL, int* dataLenWithPadding = NULL, char attalign = 'c'); + + /* dictionary compress methods */ + template + void FillHashKey(DictItemData& key, const int& attlen, const Datum& attval); + template + DictCmprMeta* DictGetCmprMeta(ColArray* colArray, int col, int attlen); + bool DictCompress(int col, Datum val, unsigned char& dictItemId); + static Datum DictUncompress(DictCmprMeta* metaInfo, const char* compressBuf, int attlen); + + /* number string compress mothods */ + template + bool NumstrEvaluate(ColArray* colArray); + template + static Datum NumstrCompress(Datum src, int& outSize); + static Datum NumstrUncompress(Datum src, int attlen, int& cmprValSize, char* uncmprValBuf = NULL, + int* dataLenWithPadding = NULL, char attalign = 'c'); + + /* write compression meta data and set its size*/ + void SetCmprHeaderData(void); + + /* dispatch tuples during compression */ + bool Dispatch(HeapTuple raw, HeapTuple cmpr, int& nowSize, const int& blksize); + bool Dispatch(HeapTuple raw, int& nowSize, const int& blksize); + void OutputRawTupsBeforeCmpr(int nToasts); + void OutputRawTupsAfterCmpr(int nToasts); + void OutputCmprTups(int nToasts); + void OutputToasts(void); + + /* memory context */ + void ResetPerPage(void); + void ResetCmprMeta(void); + +#ifdef USE_ASSERT_CHECKING + void CheckCmprDatum(Datum arg1, Datum arg2, Form_pg_attribute attr); + void CheckCmprAttr(Datum rawVal, bool rawNull, int col, FormCmprTupleData* formTuple); + void CheckCmprTuple(HeapTuple rawTup, HeapTuple cmprTup); + void CheckCmprHeaderData(void); + void CheckOutputTups(HeapTuple* cmpr, int nCmpr, HeapTuple* uncmpr, int nUncmpr, int nToasts); +#endif + +#ifdef TRACE_COMPRESS + void TraceCmprPage( + int flag, HeapTuple* cmpr, HeapTuple* mapped, int nCmpr, HeapTuple* uncmpr, int nUncmpr, int nToasts); + int nLoops; +#endif + + /* Output compressed tuples */ + char* m_cmprHeaderData; + HeapTuple* m_outputTups; + int m_outputTupsNum; + int m_cmprHeaderSize; + + /* + * input original tuples + * if not the last batch, maybe wait for continuing to read more tuples. + * but for the last, all tuples must be handled and written into pages. + */ + Relation m_rel; + HeapTuple* m_inTups; + int m_inTupsNum; + int m_current; + bool m_last; + + Datum* m_deformVals; + bool* m_deformNulls; + + /* compression mode && meta info && number type func */ + char* m_cmprMode; + void** m_cmprMeta; + + /* + * Each element represents for miss times when try to + * choose dictionary compression method for each column + */ + uint32* m_dictMiss; + unsigned char* m_dictItemId; + + const NumberTypeOpt** m_numTypeOpt; + + /* local memory context */ + MemoryContext m_pageMemCnxt; + MemoryContext m_parentMemCxt; + + /* handle toast tuples */ + HeapTuple* m_toastTups; + HeapTuple* m_mappedTups; + HeapTuple* m_cmprTups; + int m_toastTupsNum; + int m_mappedTupsNum; + int m_cmprTupsNum; + int m_uncmprTupIdx; + bool m_nextBatch; +}; + +/* -------------------------------- + * Page Compression Macros + * -------------------------------- + */ + +#define getPageDict(page) (AssertMacro(PageIsCompressed(page)), (PageGetSpecialPointer(page))) + +#endif /* PAGE_COMPRESS_H */ diff -uprN postgresql-hll-2.14_old/include/storage/pg_sema.h postgresql-hll-2.14/include/storage/pg_sema.h --- postgresql-hll-2.14_old/include/storage/pg_sema.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/pg_sema.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,86 @@ +/* ------------------------------------------------------------------------- + * + * pg_sema.h + * Platform-independent API for semaphores. + * + * PostgreSQL requires counting semaphores (the kind that keep track of + * multiple unlock operations, and will allow an equal number of subsequent + * lock operations before blocking). The underlying implementation is + * not the same on every platform. This file defines the API that must + * be provided by each port. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pg_sema.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SEMA_H +#define PG_SEMA_H + +/* + * PGSemaphoreData and pointer type PGSemaphore are the data structure + * representing an individual semaphore. The contents of PGSemaphoreData + * vary across implementations and must never be touched by platform- + * independent code. PGSemaphoreData structures are always allocated + * in shared memory (to support implementations where the data changes during + * lock/unlock). + * + * pg_config.h must define exactly one of the USE_xxx_SEMAPHORES symbols. + */ + +#ifdef USE_NAMED_POSIX_SEMAPHORES + +#include + +typedef sem_t* PGSemaphoreData; +#endif + +#ifdef USE_UNNAMED_POSIX_SEMAPHORES + +#include + +typedef sem_t PGSemaphoreData; +#endif + +#ifdef USE_SYSV_SEMAPHORES + +typedef struct PGSemaphoreData { + int semId; /* semaphore set identifier */ + int semNum; /* semaphore number within set */ +} PGSemaphoreData; +#endif + +#ifdef USE_WIN32_SEMAPHORES + +typedef HANDLE PGSemaphoreData; +#endif + +typedef PGSemaphoreData* PGSemaphore; + +/* concurrent control for locale */ +extern PGSemaphoreData g_locale_sem; + +/* Module initialization (called during postmaster start or shmem reinit) */ +extern void PGReserveSemaphores(int maxSemas, int port); + +/* Initialize a PGSemaphore structure to represent a sema with count 1 */ +extern void PGSemaphoreCreate(PGSemaphore sema); + +/* Reset a previously-initialized PGSemaphore to have count 0 */ +extern void PGSemaphoreReset(PGSemaphore sema); + +/* Lock a semaphore (decrement count), blocking if count would be < 0 */ +extern void PGSemaphoreLock(PGSemaphore sema, bool interruptOK); + +/* Unlock a semaphore (increment count) */ +extern void PGSemaphoreUnlock(PGSemaphore sema); + +/* Lock a semaphore only if able to do so without blocking */ +extern bool PGSemaphoreTryLock(PGSemaphore sema); + +extern void cancelSemphoreRelease(void); + +#endif /* PG_SEMA_H */ diff -uprN postgresql-hll-2.14_old/include/storage/pg_shmem.h postgresql-hll-2.14/include/storage/pg_shmem.h --- postgresql-hll-2.14_old/include/storage/pg_shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/pg_shmem.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * pg_shmem.h + * Platform-independent API for shared memory support. + * + * Every port is expected to support shared memory with approximately + * SysV-ish semantics; in particular, a memory block is not anonymous + * but has an ID, and we must be able to tell whether there are any + * remaining processes attached to a block of a specified ID. + * + * To simplify life for the SysV implementation, the ID is assumed to + * consist of two unsigned long values (these are key and ID in SysV + * terms). Other platforms may ignore the second value if they need + * only one ID number. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pg_shmem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_SHMEM_H +#define PG_SHMEM_H + +typedef struct PGShmemHeader /* standard header for all Postgres shmem */ { + int32 magic; /* magic # to identify Postgres segments */ +#define PGShmemMagic 679834894 + ThreadId creatorPID; /* PID of creating process */ + Size totalsize; /* total size of segment */ + Size freeoffset; /* offset to first free space */ + void* index; /* pointer to ShmemIndex table */ +#ifndef WIN32 /* Windows doesn't have useful inode#s */ + dev_t device; /* device data directory is on */ + ino_t inode; /* inode number of data directory */ +#endif +} PGShmemHeader; + +#ifdef EXEC_BACKEND +#ifndef WIN32 +extern THR_LOCAL unsigned long UsedShmemSegID; +#else +extern THR_LOCAL HANDLE UsedShmemSegID; +#endif +extern THR_LOCAL void* UsedShmemSegAddr; + +extern void PGSharedMemoryReAttach(void); +#endif + +extern THR_LOCAL void* UsedShmemSegAddr; + +#define PGSharedMemoryAttached() (NULL != UsedShmemSegAddr) + +extern PGShmemHeader* PGSharedMemoryCreate(Size size, bool makePrivate, int port); +extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2); +extern void PGSharedMemoryDetach(void); +extern void cancelIpcMemoryDetach(void); + +#endif /* PG_SHMEM_H */ diff -uprN postgresql-hll-2.14_old/include/storage/pmsignal.h postgresql-hll-2.14/include/storage/pmsignal.h --- postgresql-hll-2.14_old/include/storage/pmsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/pmsignal.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,75 @@ +/* ------------------------------------------------------------------------- + * + * pmsignal.h + * routines for signaling the postmaster from its child processes + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pmsignal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PMSIGNAL_H +#define PMSIGNAL_H + +/* + * Reasons for signaling the postmaster. We can cope with simultaneous + * signals for different reasons. If the same reason is signaled multiple + * times in quick succession, however, the postmaster is likely to observe + * only one notification of it. This is okay for the present uses. + */ +typedef enum { + PMSIGNAL_RECOVERY_STARTED, /* recovery has started */ + PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */ + PMSIGNAL_LOCAL_RECOVERY_DONE, /* local recovery has done */ + PMSIGNAL_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */ + PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */ + PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */ + PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */ + PMSIGNAL_START_CATCHUP, /* start a data catchup worker */ + PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */ + PMSIGNAL_START_DATARECEIVER, /* start a datareceiver */ + PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */ + PMSIGNAL_DEMOTE_PRIMARY, /* start to demote primary */ + PMSIGNAL_PROMOTE_STANDBY, /* start to promote standby */ + PMSIGNAL_UPDATE_WAITING, /* update waiting status to gaussdb.state */ + PMSIGNAL_UPDATE_PROMOTING, /* update promoting status to gaussdb.state */ + PMSIGNAL_UPDATE_HAREBUILD_REASON, /* update ha rebuild reason to gaussdb.state */ + PMSIGNAL_UPDATE_NORMAL, /* update normal status to gaussdb.state */ + PMSIGNAL_START_JOB_SCHEDULER, /* start a job scheduler */ + PMSIGNAL_START_JOB_WORKER, /* start a job worker */ + PMSIGNAL_ROLLBACK_STANDBY_PROMOTE, /* roll back standby promoting */ + PMSIGNAL_START_PAGE_WRITER, /* start a new page writer thread */ + PMSIGNAL_START_THREADPOOL_WORKER, /* start thread pool woker */ + NUM_PMSIGNALS /* Must be last value of enum! */ +} PMSignalReason; + +/* PMSignalData is an opaque struct, details known only within pmsignal.c */ +typedef struct PMSignalData PMSignalData; + +/* + * prototypes for functions in pmsignal.c + */ +extern Size PMSignalShmemSize(void); +extern void PMSignalShmemInit(void); +extern void SendPostmasterSignal(PMSignalReason reason); +extern bool CheckPostmasterSignal(PMSignalReason reason); +extern int AssignPostmasterChildSlot(void); +extern bool ReleasePostmasterChildSlot(int slot); +extern bool IsPostmasterChildWalSender(int slot); +extern bool IsPostmasterChildDataSender(int slot); +extern void MarkPostmasterChildActive(void); +extern void MarkPostmasterChildInactive(void); +extern void MarkPostmasterChildWalSender(void); +extern void MarkPostmasterChildDataSender(void); +extern void MarkPostmasterChildNormal(void); +extern bool PostmasterIsAlive(void); +extern void MarkPostmasterChildUnuseForStreamWorker(void); + +extern bool IsPostmasterChildSuspect(int slot); +extern void MarkPostmasterChildSusPect(void); +extern void MarkPostmasterTempBackend(void); +extern bool IsPostmasterChildTempBackend(int slot); +#endif /* PMSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/storage/pos.h postgresql-hll-2.14/include/storage/pos.h --- postgresql-hll-2.14_old/include/storage/pos.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/pos.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + * + * pos.h + * POSTGRES "position" definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/pos.h + * + * ------------------------------------------------------------------------- + */ +#ifndef POS_H +#define POS_H + +/* + * a 'position' used to be in postgres. this has + * been changed to just as the notion of having multiple pages + * within a block has been removed. + * + * the 'offset' abstraction is somewhat confusing. it is NOT a byte + * offset within the page; instead, it is an offset into the line + * pointer array contained on every page that store (heap or index) + * tuples. + */ +typedef bits16 PositionIdData; +typedef PositionIdData* PositionId; + +/* ---------------- + * support macros + * ---------------- + */ + +/* + * PositionIdIsValid + * True iff the position identifier is valid. + */ +#define PositionIdIsValid(positionId) PointerIsValid(positionId) + +/* + * PositionIdSetInvalid + * Make an invalid position. + */ +#define PositionIdSetInvalid(positionId) *(positionId) = (bits16)0 + +/* + * PositionIdSet + * Sets a position identifier to the specified value. + */ +#define PositionIdSet(positionId, offsetNumber) *(positionId) = (offsetNumber) + +/* + * PositionIdGetOffsetNumber + * Retrieve the offset number from a position identifier. + */ +#define PositionIdGetOffsetNumber(positionId) ((OffsetNumber) * (positionId)) + +#endif /* POS_H */ diff -uprN postgresql-hll-2.14_old/include/storage/predicate.h postgresql-hll-2.14/include/storage/predicate.h --- postgresql-hll-2.14_old/include/storage/predicate.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/predicate.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,63 @@ +/* ------------------------------------------------------------------------- + * + * predicate.h + * POSTGRES public predicate locking definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/predicate.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDICATE_H +#define PREDICATE_H + +#include "utils/relcache.h" +#include "utils/snapshot.h" + +/* Number of SLRU buffers to use for predicate locking */ +#define NUM_OLDSERXID_BUFFERS 16 + +/* + * function prototypes + */ + +/* housekeeping for shared memory predicate lock structures */ +extern void InitPredicateLocks(void); +extern Size PredicateLockShmemSize(void); + +extern void CheckPointPredicate(void); + +/* predicate lock reporting */ +extern bool PageIsPredicateLocked(Relation relation, BlockNumber blkno); + +/* predicate lock maintenance */ +extern Snapshot GetSerializableTransactionSnapshot(Snapshot snapshot); +extern void SetSerializableTransactionSnapshot(Snapshot snapshot, TransactionId sourcexid); +extern void RegisterPredicateLockingXid(TransactionId xid); +extern void PredicateLockRelation(Relation relation, Snapshot snapshot); +extern void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot); +extern void PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot); +extern void PredicateLockPageSplit(Relation relation, BlockNumber oldblkno, BlockNumber newblkno); +extern void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno); +extern void TransferPredicateLocksToHeapRelation(Relation relation); +extern void ReleasePredicateLocks(bool isCommit); + +/* conflict detection (may also trigger rollback) */ +extern void CheckForSerializableConflictOut( + bool valid, Relation relation, HeapTuple tuple, Buffer buffer, Snapshot snapshot); +extern void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer); +extern void CheckTableForSerializableConflictIn(Relation relation); + +/* final rollback checking */ +extern void PreCommit_CheckForSerializationFailure(void); + +/* two-phase commit support */ +extern void AtPrepare_PredicateLocks(void); +extern void PostPrepare_PredicateLocks(TransactionId xid); +extern void PredicateLockTwoPhaseFinish(TransactionId xid, bool isCommit); +extern void predicatelock_twophase_recover(TransactionId xid, uint16 info, void* recdata, uint32 len); + +#endif /* PREDICATE_H */ diff -uprN postgresql-hll-2.14_old/include/storage/predicate_internals.h postgresql-hll-2.14/include/storage/predicate_internals.h --- postgresql-hll-2.14_old/include/storage/predicate_internals.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/predicate_internals.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,444 @@ +/* ------------------------------------------------------------------------- + * + * predicate_internals.h + * POSTGRES internal predicate locking definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/predicate_internals.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PREDICATE_INTERNALS_H +#define PREDICATE_INTERNALS_H + +#include "storage/lock.h" + +/* + * Commit number. + */ +typedef uint64 SerCommitSeqNo; + +/* + * Reserved commit sequence numbers: + * - 0 is reserved to indicate a non-existent SLRU entry; it cannot be + * used as a SerCommitSeqNo, even an invalid one + * - InvalidSerCommitSeqNo is used to indicate a transaction that + * hasn't committed yet, so use a number greater than all valid + * ones to make comparison do the expected thing + * - RecoverySerCommitSeqNo is used to refer to transactions that + * happened before a crash/recovery, since we restart the sequence + * at that point. It's earlier than all normal sequence numbers, + * and is only used by recovered prepared transactions + */ +#define InvalidSerCommitSeqNo ((SerCommitSeqNo)UINT64CONST(0xFFFFFFFFFFFFFFFF)) +#define RecoverySerCommitSeqNo ((SerCommitSeqNo)1) +#define FirstNormalSerCommitSeqNo ((SerCommitSeqNo)2) + +/* + * The SERIALIZABLEXACT struct contains information needed for each + * serializable database transaction to support SSI techniques. + * + * A home-grown list is maintained in shared memory to manage these. + * An entry is used when the serializable transaction acquires a snapshot. + * Unless the transaction is rolled back, this entry must generally remain + * until all concurrent transactions have completed. (There are special + * optimizations for READ ONLY transactions which often allow them to be + * cleaned up earlier.) A transaction which is rolled back is cleaned up + * as soon as possible. + * + * Eligibility for cleanup of committed transactions is generally determined + * by comparing the transaction's finishedBefore field to + * SerializableGlobalXmin. + */ +typedef struct SERIALIZABLEXACT { + VirtualTransactionId vxid; /* The executing process always has one of + * these. */ + + /* + * We use two numbers to track the order that transactions commit. Before + * commit, a transaction is marked as prepared, and prepareSeqNo is set. + * Shortly after commit, it's marked as committed, and commitSeqNo is set. + * This doesn't give a strict commit order, but these two values together + * are good enough for us, as we can always err on the safe side and + * assume that there's a conflict, if we can't be sure of the exact + * ordering of two commits. + * + * Note that a transaction is marked as prepared for a short period during + * commit processing, even if two-phase commit is not used. But with + * two-phase commit, a transaction can stay in prepared state for some + * time. + */ + SerCommitSeqNo prepareSeqNo; + SerCommitSeqNo commitSeqNo; + + /* these values are not both interesting at the same time */ + union { + SerCommitSeqNo earliestOutConflictCommit; /* when committed with conflict out */ + SerCommitSeqNo lastCommitBeforeSnapshot; /* when not committed or no conflict out */ + } SeqNo; + SHM_QUEUE outConflicts; /* list of write transactions whose data we couldn't read. */ + SHM_QUEUE inConflicts; /* list of read transactions which couldn't see our write. */ + SHM_QUEUE predicateLocks; /* list of associated PREDICATELOCK objects */ + SHM_QUEUE finishedLink; /* list link in FinishedSerializableTransactions */ + + /* + * for r/o transactions: list of concurrent r/w transactions that we could + * potentially have conflicts with, and vice versa for r/w transactions + */ + SHM_QUEUE possibleUnsafeConflicts; + + TransactionId topXid; /* top level xid for the transaction, if one exists; else invalid */ + TransactionId finishedBefore; /* invalid means still running; else the struct expires when no + * serializable xids are before this. */ + TransactionId xmin; /* the transaction's snapshot xmin */ + uint32 flags; /* OR'd combination of values defined below */ + ThreadId pid; /* pid of associated process */ +} SERIALIZABLEXACT; + +#define SXACT_FLAG_COMMITTED 0x00000001 /* already committed */ +#define SXACT_FLAG_PREPARED 0x00000002 /* about to commit */ +#define SXACT_FLAG_ROLLED_BACK 0x00000004 /* already rolled back */ +#define SXACT_FLAG_DOOMED 0x00000008 /* will roll back */ +/* + * The following flag actually means that the flagged transaction has a + * conflict out *to a transaction which committed ahead of it*. It's hard + * to get that into a name of a reasonable length. + */ +#define SXACT_FLAG_CONFLICT_OUT 0x00000010 +#define SXACT_FLAG_READ_ONLY 0x00000020 +#define SXACT_FLAG_DEFERRABLE_WAITING 0x00000040 +#define SXACT_FLAG_RO_SAFE 0x00000080 +#define SXACT_FLAG_RO_UNSAFE 0x00000100 +#define SXACT_FLAG_SUMMARY_CONFLICT_IN 0x00000200 +#define SXACT_FLAG_SUMMARY_CONFLICT_OUT 0x00000400 + +/* + * The following types are used to provide an ad hoc list for holding + * SERIALIZABLEXACT objects. An HTAB is overkill, since there is no need to + * access these by key -- there are direct pointers to these objects where + * needed. If a shared memory list is created, these types can probably be + * eliminated in favor of using the general solution. + */ +typedef struct PredXactListElementData { + SHM_QUEUE link; + SERIALIZABLEXACT sxact; +} PredXactListElementData; + +typedef struct PredXactListElementData* PredXactListElement; + +#define PredXactListElementDataSize ((Size)MAXALIGN(sizeof(PredXactListElementData))) + +typedef struct PredXactListData { + SHM_QUEUE availableList; + SHM_QUEUE activeList; + + /* + * These global variables are maintained when registering and cleaning up + * serializable transactions. They must be global across all backends, + * but are not needed outside the predicate.c source file. Protected by + * SerializableXactHashLock. + */ + TransactionId SxactGlobalXmin; /* global xmin for active serializable + * transactions */ + int SxactGlobalXminCount; /* how many active serializable + * transactions have this xmin */ + int WritableSxactCount; /* how many non-read-only serializable + * transactions are active */ + SerCommitSeqNo LastSxactCommitSeqNo; /* a strictly monotonically + * increasing number for + * commits of serializable + * transactions */ + /* Protected by SerializableXactHashLock. */ + SerCommitSeqNo CanPartialClearThrough; /* can clear predicate locks + * and inConflicts for + * committed transactions + * through this seq no */ + /* Protected by SerializableFinishedListLock. */ + SerCommitSeqNo HavePartialClearedThrough; /* have cleared through this + * seq no */ + SERIALIZABLEXACT* OldCommittedSxact; /* shared copy of dummy sxact */ + + PredXactListElement element; +} PredXactListData; + +typedef struct PredXactListData* PredXactList; + +#define PredXactListDataSize ((Size)MAXALIGN(sizeof(PredXactListData))) + +/* + * The following types are used to provide lists of rw-conflicts between + * pairs of transactions. Since exactly the same information is needed, + * they are also used to record possible unsafe transaction relationships + * for purposes of identifying safe snapshots for read-only transactions. + * + * When a RWConflictData is not in use to record either type of relationship + * between a pair of transactions, it is kept on an "available" list. The + * outLink field is used for maintaining that list. + */ +typedef struct RWConflictData { + SHM_QUEUE outLink; /* link for list of conflicts out from a sxact */ + SHM_QUEUE inLink; /* link for list of conflicts in to a sxact */ + SERIALIZABLEXACT* sxactOut; + SERIALIZABLEXACT* sxactIn; +} RWConflictData; + +typedef struct RWConflictData* RWConflict; + +#define RWConflictDataSize ((Size)MAXALIGN(sizeof(RWConflictData))) + +typedef struct RWConflictPoolHeaderData { + SHM_QUEUE availableList; + RWConflict element; +} RWConflictPoolHeaderData; + +typedef struct RWConflictPoolHeaderData* RWConflictPoolHeader; + +#define RWConflictPoolHeaderDataSize ((Size)MAXALIGN(sizeof(RWConflictPoolHeaderData))) + +/* + * The SERIALIZABLEXIDTAG struct identifies an xid assigned to a serializable + * transaction or any of its subtransactions. + */ +typedef struct SERIALIZABLEXIDTAG { + TransactionId xid; +} SERIALIZABLEXIDTAG; + +/* + * The SERIALIZABLEXID struct provides a link from a TransactionId for a + * serializable transaction to the related SERIALIZABLEXACT record, even if + * the transaction has completed and its connection has been closed. + * + * These are created as new top level transaction IDs are first assigned to + * transactions which are participating in predicate locking. This may + * never happen for a particular transaction if it doesn't write anything. + * They are removed with their related serializable transaction objects. + * + * The SubTransGetTopmostTransaction method is used where necessary to get + * from an XID which might be from a subtransaction to the top level XID. + */ +typedef struct SERIALIZABLEXID { + /* hash key */ + SERIALIZABLEXIDTAG tag; + + /* data */ + SERIALIZABLEXACT* myXact; /* pointer to the top level transaction data */ +} SERIALIZABLEXID; + +/* + * The PREDICATELOCKTARGETTAG struct identifies a database object which can + * be the target of predicate locks. + * + * Note that the hash function being used doesn't properly respect tag + * length -- it will go to a four byte boundary past the end of the tag. + * If you change this struct, make sure any slack space is initialized, + * so that any random bytes in the middle or at the end are not included + * in the hash. + * + * If we always use the same fields for the same type of value, we + * should rename these. Holding off until it's clear there are no exceptions. + * Since indexes are relations with blocks and tuples, it's looking likely that + * the rename will be possible. If not, we may need to divide the last field + * and use part of it for a target type, so that we know how to interpret the + * data.. + */ +typedef struct PREDICATELOCKTARGETTAG { + uint32 locktag_field1; /* a 32-bit ID field */ + uint32 locktag_field2; /* a 32-bit ID field */ + uint32 locktag_field3; /* a 32-bit ID field */ + uint32 locktag_field4; /* a 32-bit ID field */ + uint32 locktag_field5; /* a 32-bit ID field */ +} PREDICATELOCKTARGETTAG; + +/* + * The PREDICATELOCKTARGET struct represents a database object on which there + * are predicate locks. + * + * A hash list of these objects is maintained in shared memory. An entry is + * added when a predicate lock is requested on an object which doesn't + * already have one. An entry is removed when the last lock is removed from + * its list. + * + * Because a particular target might become obsolete, due to update to a new + * version, before the reading transaction is obsolete, we need some way to + * prevent errors from reuse of a tuple ID. Rather than attempting to clean + * up the targets as the related tuples are pruned or vacuumed, we check the + * xmin on access. This should be far less costly. + */ +typedef struct PREDICATELOCKTARGET { + /* hash key */ + PREDICATELOCKTARGETTAG tag; /* unique identifier of lockable object */ + + /* data */ + SHM_QUEUE predicateLocks; /* list of PREDICATELOCK objects assoc. with + * predicate lock target */ +} PREDICATELOCKTARGET; + +/* + * The PREDICATELOCKTAG struct identifies an individual predicate lock. + * + * It is the combination of predicate lock target (which is a lockable + * object) and a serializable transaction which has acquired a lock on that + * target. + */ +typedef struct PREDICATELOCKTAG { + PREDICATELOCKTARGET* myTarget; + SERIALIZABLEXACT* myXact; +} PREDICATELOCKTAG; + +/* + * The PREDICATELOCK struct represents an individual lock. + * + * An entry can be created here when the related database object is read, or + * by promotion of multiple finer-grained targets. All entries related to a + * serializable transaction are removed when that serializable transaction is + * cleaned up. Entries can also be removed when they are combined into a + * single coarser-grained lock entry. + */ +typedef struct PREDICATELOCK { + /* hash key */ + PREDICATELOCKTAG tag; /* unique identifier of lock */ + + /* data */ + SHM_QUEUE targetLink; /* list link in PREDICATELOCKTARGET's list of + * predicate locks */ + SHM_QUEUE xactLink; /* list link in SERIALIZABLEXACT's list of + * predicate locks */ + SerCommitSeqNo commitSeqNo; /* only used for summarized predicate locks */ +} PREDICATELOCK; + +/* + * The LOCALPREDICATELOCK struct represents a local copy of data which is + * also present in the PREDICATELOCK table, organized for fast access without + * needing to acquire a LWLock. It is strictly for optimization. + * + * Each serializable transaction creates its own local hash table to hold a + * collection of these. This information is used to determine when a number + * of fine-grained locks should be promoted to a single coarser-grained lock. + * The information is maintained more-or-less in parallel to the + * PREDICATELOCK data, but because this data is not protected by locks and is + * only used in an optimization heuristic, it is allowed to drift in a few + * corner cases where maintaining exact data would be expensive. + * + * The hash table is created when the serializable transaction acquires its + * snapshot, and its memory is released upon completion of the transaction. + */ +typedef struct LOCALPREDICATELOCK { + /* hash key */ + PREDICATELOCKTARGETTAG tag; /* unique identifier of lockable object */ + + /* data */ + bool held; /* is lock held, or just its children? */ + int childLocks; /* number of child locks currently held */ +} LOCALPREDICATELOCK; + +/* + * The types of predicate locks which can be acquired. + */ +typedef enum PredicateLockTargetType { + PREDLOCKTAG_RELATION, + PREDLOCKTAG_PAGE, + PREDLOCKTAG_TUPLE + /* Other types may be needed for index locking */ +} PredicateLockTargetType; + +/* + * This structure is used to quickly capture a copy of all predicate + * locks. This is currently used only by the pg_lock_status function, + * which in turn is used by the pg_locks view. + */ +typedef struct PredicateLockData { + int nelements; + PREDICATELOCKTARGETTAG* locktags; + SERIALIZABLEXACT* xacts; +} PredicateLockData; + +/* + * These macros define how we map logical IDs of lockable objects into the + * physical fields of PREDICATELOCKTARGETTAG. Use these to set up values, + * rather than accessing the fields directly. Note multiple eval of target! + */ +#define SET_PREDICATELOCKTARGETTAG_RELATION(locktag, dboid, reloid) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = InvalidBlockNumber, \ + (locktag).locktag_field4 = InvalidOffsetNumber, \ + (locktag).locktag_field5 = InvalidTransactionId) + +#define SET_PREDICATELOCKTARGETTAG_PAGE(locktag, dboid, reloid, blocknum) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = (blocknum), \ + (locktag).locktag_field4 = InvalidOffsetNumber, \ + (locktag).locktag_field5 = InvalidTransactionId) + +#define SET_PREDICATELOCKTARGETTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum, xmin) \ + ((locktag).locktag_field1 = (dboid), \ + (locktag).locktag_field2 = (reloid), \ + (locktag).locktag_field3 = (blocknum), \ + (locktag).locktag_field4 = (offnum), \ + (locktag).locktag_field5 = (xmin)) + +#define GET_PREDICATELOCKTARGETTAG_DB(locktag) ((Oid)(locktag).locktag_field1) +#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag) ((Oid)(locktag).locktag_field2) +#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag) ((BlockNumber)(locktag).locktag_field3) +#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag) ((OffsetNumber)(locktag).locktag_field4) +#define GET_PREDICATELOCKTARGETTAG_XMIN(locktag) ((TransactionId)(locktag).locktag_field5) +#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag) \ + (((locktag).locktag_field4 != InvalidOffsetNumber) \ + ? PREDLOCKTAG_TUPLE \ + : (((locktag).locktag_field3 != InvalidBlockNumber) ? PREDLOCKTAG_PAGE : PREDLOCKTAG_RELATION)) + +/* + * Two-phase commit statefile records. There are two types: for each + * transaction, we generate one per-transaction record and a variable + * number of per-predicate-lock records. + */ +typedef enum TwoPhasePredicateRecordType { + TWOPHASEPREDICATERECORD_XACT, + TWOPHASEPREDICATERECORD_LOCK +} TwoPhasePredicateRecordType; + +/* + * Per-transaction information to reconstruct a SERIALIZABLEXACT. Not + * much is needed because most of it not meaningful for a recovered + * prepared transaction. + * + * In particular, we do not record the in and out conflict lists for a + * prepared transaction because the associated SERIALIZABLEXACTs will + * not be available after recovery. Instead, we simply record the + * existence of each type of conflict by setting the transaction's + * summary conflict in/out flag. + */ +typedef struct TwoPhasePredicateXactRecord { + TransactionId xmin; + uint32 flags; +} TwoPhasePredicateXactRecord; + +/* Per-lock state */ +typedef struct TwoPhasePredicateLockRecord { + PREDICATELOCKTARGETTAG target; +} TwoPhasePredicateLockRecord; + +typedef struct TwoPhasePredicateRecord { + TwoPhasePredicateRecordType type; + union { + TwoPhasePredicateXactRecord xactRecord; + TwoPhasePredicateLockRecord lockRecord; + } data; +} TwoPhasePredicateRecord; + +/* + * Define a macro to use for an "empty" SERIALIZABLEXACT reference. + */ +#define InvalidSerializableXact ((SERIALIZABLEXACT*)NULL) + +/* + * Function definitions for functions needing awareness of predicate + * locking internals. + */ +extern PredicateLockData* GetPredicateLockStatusData(void); + +#endif /* PREDICATE_INTERNALS_H */ diff -uprN postgresql-hll-2.14_old/include/storage/procarray.h postgresql-hll-2.14/include/storage/procarray.h --- postgresql-hll-2.14_old/include/storage/procarray.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/procarray.h 2020-12-12 17:06:43.380349754 +0800 @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------------- + * + * procarray.h + * POSTGRES process array definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/storage/procarray.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCARRAY_H +#define PROCARRAY_H + +#include "storage/standby.h" +#include "utils/snapshot.h" +#include "pgstat.h" + +// EB: removed "static" qualifier +extern void SyncLocalXidWait(TransactionId xid); + +extern Size ProcArrayShmemSize(void); +extern void CreateSharedProcArray(void); +extern void ProcArrayAdd(PGPROC* proc); +extern void ProcArrayRemove(PGPROC* proc, TransactionId latestXid); + +extern Size RingBufferShmemSize(void); +extern void CreateSharedRingBuffer(void); + +extern void ProcArrayEndTransaction(PGPROC* proc, TransactionId latestXid, bool isCommit = true); +extern void ProcArrayClearTransaction(PGPROC* proc); +extern bool TransactionIdIsInProgress( + TransactionId xid, bool* needSync = NULL, bool shortcutByRecentXmin = false, bool bCareNextxid = false); + +#ifdef PGXC /* PGXC_DATANODE */ +extern void SetGlobalSnapshotData( + TransactionId xmin, TransactionId xmax, uint64 scn, GTM_Timeline timeline, bool ss_need_sync_wait_all); +extern void UnsetGlobalSnapshotData(void); +extern void ReloadConnInfoOnBackends(void); +#endif /* PGXC */ +extern char dump_memory_context_name[MEMORY_CONTEXT_NAME_LEN]; +extern void DumpMemoryCtxOnBackend(ThreadId tid, const char* mem_ctx); +extern void ProcArrayInitRecovery(TransactionId initializedUptoXID); +extern void ProcArrayApplyRecoveryInfo(RunningTransactions running); + +extern int GetMaxSnapshotXidCount(void); +extern int GetMaxSnapshotSubxidCount(void); + +#ifndef ENABLE_MULTIPLE_NODES +Snapshot GetSnapshotData(Snapshot snapshot, bool force_local_snapshot, bool forHSFeedBack = false); +#else +extern Snapshot GetSnapshotData(Snapshot snapshot, bool force_local_snapshot); +#endif + +extern Snapshot GetLocalSnapshotData(Snapshot snapshot); +extern void ReleaseSnapshotData(Snapshot snapshot); + +extern bool ProcArrayInstallImportedXmin(TransactionId xmin, TransactionId sourcexid); +extern RunningTransactions GetRunningTransactionData(void); + +extern bool TransactionIdIsActive(TransactionId xid); +extern TransactionId GetRecentGlobalXmin(void); +extern TransactionId GetOldestXmin(Relation rel, bool bFixRecentGlobalXmin = false); +extern void CheckCurrentTimeline(GTM_Timeline timeline); +extern TransactionId GetOldestActiveTransactionId(TransactionId *globalXmin); +extern void FixCurrentSnapshotByGxid(TransactionId gxid); +extern void CheckSnapshotIsValidException(Snapshot snapshot, const char* location); +extern TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly); +extern void CheckSnapshotTooOldException(Snapshot snapshot, const char* location); + +extern VirtualTransactionId* GetVirtualXIDsDelayingChkpt(int* nvxids); +extern bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId* vxids, int nvxids); + +extern PGPROC* BackendPidGetProc(ThreadId pid); +extern int BackendXidGetPid(TransactionId xid); +extern bool IsBackendPid(ThreadId pid); + +extern VirtualTransactionId* GetCurrentVirtualXIDs( + TransactionId limitXmin, bool excludeXmin0, bool allDbs, int excludeVacuum, int* nvxids); +extern VirtualTransactionId* GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid); +extern ThreadId CancelVirtualTransaction(const VirtualTransactionId& vxid, ProcSignalReason sigmode); + +extern bool MinimumActiveBackends(int min); +extern int CountDBBackends(Oid database_oid); +extern int CountDBActiveBackends(Oid database_oid); +extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending); +extern int CountUserBackends(Oid roleid); +extern bool CountOtherDBBackends(Oid databaseId, int* nbackends, int* nprepared); + +extern void XidCacheRemoveRunningXids(TransactionId xid, int nxids, const TransactionId* xids, TransactionId latestXid); +extern void SetPgXactXidInvalid(void); + +extern void ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin, bool already_locked); + +extern void ProcArrayGetReplicationSlotXmin(TransactionId* xmin, TransactionId* catalog_xmin); +extern TransactionId GetGlobal2pcXmin(); + +extern void CSNLogRecordAssignedTransactionId(TransactionId newXid); + +#ifdef PGXC +typedef enum { + SNAPSHOT_UNDEFINED, /* Coordinator has not sent snapshot or not yet connected */ + SNAPSHOT_LOCAL, /* Coordinator has instructed Datanode to build up snapshot from the local procarray */ + SNAPSHOT_COORDINATOR, /* Coordinator has sent snapshot data */ + SNAPSHOT_DIRECT, /* Datanode obtained directly from GTM */ + SNAPSHOT_DATANODE /* obtained directly from other thread in the same datanode*/ +} SnapshotSource; + +extern CommitSeqNo set_proc_csn_and_check( + const char* func, CommitSeqNo csn_min, GTM_SnapshotType gtm_snapshot_type, SnapshotSource from); +#endif + +extern void PrintCurrentSnapshotInfo(int logelevel, TransactionId xid, Snapshot snapshot, const char* action); +extern void ProcSubXidCacheClean(); +extern void InitProcSubXidCacheContext(); +extern void ProcArrayResetXmin(PGPROC* proc); +extern uint64 GetCommitCsn(); +extern void setCommitCsn(uint64 commit_csn); +extern void SyncWaitXidEnd(TransactionId xid, Buffer buffer); +extern CommitSeqNo calculate_local_csn_min(); +extern void proc_cancel_invalid_gtm_lite_conn(); +extern void forward_recent_global_xmin(void); + +extern void UpdateCSNLogAtTransactionEND( + TransactionId xid, int nsubxids, TransactionId* subXids, CommitSeqNo csn, bool isCommit); + +#endif /* PROCARRAY_H */ + +#ifdef ENABLE_UT +extern void ResetProcXidCache(PGPROC* proc, bool needlock); +#endif /* USE_UT */ + +// For GTT +extern TransactionId ListAllThreadGttFrozenxids(int maxSize, ThreadId *pids, TransactionId *xids, int *n); diff -uprN postgresql-hll-2.14_old/include/storage/proc.h postgresql-hll-2.14/include/storage/proc.h --- postgresql-hll-2.14_old/include/storage/proc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/proc.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,439 @@ +/* ------------------------------------------------------------------------- + * + * proc.h + * per-process shared memory data structures + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/proc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PROC_H_ +#define _PROC_H_ + +#include "access/clog.h" +#include "access/xlog.h" +#include "datatype/timestamp.h" +#include "storage/latch.h" +#include "storage/lock.h" +#include "storage/pg_sema.h" +#include "threadpool/threadpool.h" +#include "replication/dataqueuedefs.h" +#include "utils/syscall_lock.h" +#include "pgtime.h" +#include "gtm/gtm_c.h" +#include "alarm/alarm.h" +#include "utils/atomic.h" +#include "access/multi_redo_settings.h" + + +/* + * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds + * for non-aborted subtransactions of its current top transaction. These + * have to be treated as running XIDs by other backends. + * + * We also keep track of whether the cache overflowed (ie, the transaction has + * generated at least one subtransaction that didn't fit in the cache). + * If none of the caches have overflowed, we can assume that an XID that's not + * listed anywhere in the PGPROC array is not a running transaction. Else we + * have to look at pg_subtrans. + */ +#define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */ + +#define PGPROC_INIT_CACHED_SUBXIDS 64 + +struct XidCache { + int maxNumber; /* max number of sub xids */ + TransactionId* xids; /* pointer to sub xids, memory allocate in g_instance.instance_context */ +}; + +/* Flags for PGXACT->vacuumFlags */ +#define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */ +#define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */ +#define PROC_IN_ANALYZE 0x04 /* currently running analyze */ +/* flags reset at EOXact */ +#define PROC_VACUUM_STATE_MASK (PROC_IN_VACUUM | PROC_IN_ANALYZE) +/* + * Flags reused to mark data redistribution xact at online expansion time + * we do not want to introduce a new field in PGXACT for data + * redistribution which increases the sizeof(PGXACT) and possiblely make + * it not fit into CPU cacheline. Please see the comments below for PGXACT + */ +#define PROC_IS_REDIST 0x10 /* currently running data redistribution */ +#define PROC_IN_LOGICAL_DECODING 0x20 /* currently doing logical decoding */ + +#define XACT_NOT_IN_USE 0 +#define XACT_IN_USE 1 + +/* + * We allow a small number of "weak" relation locks (AccesShareLock, + * RowShareLock, RowExclusiveLock) to be recorded in the PGPROC structure + * rather than the main lock table. This eases contention on the lock + * manager LWLocks. See storage/lmgr/README for additional details. + */ +#define FP_LOCK_SLOTS_PER_BACKEND 20 + +typedef struct FastPathTag { + uint32 dbid; + uint32 relid; + uint32 partitionid; +} FastPathTag; + +#define FAST_PATH_TAG_EQUALS(tag1, tag2) \ + (((tag1).dbid == (tag2).dbid) && ((tag1).relid == (tag2).relid) && ((tag1).partitionid == (tag2).partitionid)) + +/* + * An invalid pgprocno. Must be larger than the maximum number of PGPROC + * structures we could possibly have. See comments for MAX_BACKENDS. + */ +#define INVALID_PGPROCNO PG_INT32_MAX + +/* + * Each backend has a PGPROC struct in shared memory. There is also a list of + * currently-unused PGPROC structs that will be reallocated to new backends. + * + * links: list link for any list the PGPROC is in. When waiting for a lock, + * the PGPROC is linked into that lock's waitProcs queue. A recycled PGPROC + * is linked into ProcGlobal's freeProcs list. + * + * Note: twophase.c also sets up a dummy PGPROC struct for each currently + * prepared transaction. These PGPROCs appear in the ProcArray data structure + * so that the prepared transactions appear to be still running and are + * correctly shown as holding locks. A prepared transaction PGPROC can be + * distinguished from a real one at need by the fact that it has pid == 0. + * The semaphore and lock-activity fields in a prepared-xact PGPROC are unused, + * but its myProcLocks[] lists are valid. + */ +struct PGPROC { + /* proc->links MUST BE FIRST IN STRUCT (see ProcSleep,ProcWakeup,etc) */ + SHM_QUEUE links; /* list link if process is in a list */ + + PGSemaphoreData sem; /* ONE semaphore to sleep on */ + int waitStatus; /* STATUS_WAITING, STATUS_OK or STATUS_ERROR */ + /* STATUS_BLOCKING for update block session */ + + Latch procLatch; /* generic latch for process */ + + LocalTransactionId lxid; /* local id of top-level transaction currently + * being executed by this proc, if running; + * else InvalidLocalTransactionId */ + ThreadId pid; /* Backend's process ID; 0 if prepared xact */ + /* + * session id in mySessionMemoryEntry + * stream works share SessionMemoryEntry with their parent sessions, + * so sessMemorySessionid is their parent's as well. + */ + ThreadId sessMemorySessionid; + uint64 sessionid; /* if not zero, session id in thread pool*/ + int logictid; /*logic thread id*/ + TransactionId gtt_session_frozenxid; /* session level global temp table relfrozenxid */ + + int pgprocno; + int nodeno; + + /* These fields are zero while a backend is still starting up: */ + BackendId backendId; /* This backend's backend ID (if assigned) */ + Oid databaseId; /* OID of database this backend is using */ + Oid roleId; /* OID of role using this backend */ + + /* Backend or session working version number. */ + uint32 workingVersionNum; + + /* + * While in hot standby mode, shows that a conflict signal has been sent + * for the current transaction. Set/cleared while holding ProcArrayLock, + * though not required. Accessed without lock, if needed. + */ + bool recoveryConflictPending; + + /* Info about LWLock the process is currently waiting for, if any. */ + bool lwWaiting; /* true if waiting for an LW lock */ + uint8 lwWaitMode; /* lwlock mode being waited for */ + bool lwIsVictim; /* force to give up LWLock acquire */ + dlist_node lwWaitLink; /* next waiter for same LW lock */ + + /* Info about lock the process is currently waiting for, if any. */ + /* waitLock and waitProcLock are NULL if not currently waiting. */ + LOCK* waitLock; /* Lock object we're sleeping on ... */ + PROCLOCK* waitProcLock; /* Per-holder info for awaited lock */ + LOCKMODE waitLockMode; /* type of lock we're waiting for */ + LOCKMASK heldLocks; /* bitmask for lock types already held on this + * lock object by this backend */ + + /* + * Info to allow us to wait for synchronous replication, if needed. + * waitLSN is InvalidXLogRecPtr if not waiting; set only by user backend. + * syncRepState must not be touched except by owning process or WALSender. + * syncRepLinks used only while holding SyncRepLock. + */ + XLogRecPtr waitLSN; /* waiting for this LSN or higher */ + int syncRepState; /* wait state for sync rep */ + bool syncRepInCompleteQueue; /* waiting in complete queue */ + SHM_QUEUE syncRepLinks; /* list link if process is in syncrep queue */ + + DataQueuePtr waitDataSyncPoint; /* waiting for this data sync point */ + int dataSyncRepState; /* wait state for data sync rep */ + SHM_QUEUE dataSyncRepLinks; /* list link if process is in datasyncrep queue */ + + MemoryContext topmcxt; /*top memory context of this backend.*/ + char myProgName[64]; + pg_time_t myStartTime; + syscalllock deleMemContextMutex; + + /* + * All PROCLOCK objects for locks held or awaited by this backend are + * linked into one of these lists, according to the partition number of + * their lock. + */ + SHM_QUEUE myProcLocks[NUM_LOCK_PARTITIONS]; + + /* Support for group XID clearing. */ + /* true, if member of ProcArray group waiting for XID clear */ + bool procArrayGroupMember; + /* next ProcArray group member waiting for XID clear */ + pg_atomic_uint32 procArrayGroupNext; + /* + * latest transaction id among the transaction's main XID and + * subtransactions + */ + TransactionId procArrayGroupMemberXid; + + /* commit sequence number send down */ + CommitSeqNo commitCSN; + + /* Support for group transaction status update. */ + bool clogGroupMember; /* true, if member of clog group */ + pg_atomic_uint32 clogGroupNext; /* next clog group member */ + TransactionId clogGroupMemberXid; /* transaction id of clog group member */ + CLogXidStatus clogGroupMemberXidStatus; /* transaction status of clog + * group member */ + int64 clogGroupMemberPage; /* clog page corresponding to + * transaction id of clog group member */ + XLogRecPtr clogGroupMemberLsn; /* WAL location of commit record for clog + * group member */ +#ifdef __aarch64__ + /* Support for group xlog insert. */ + bool xlogGroupMember; + pg_atomic_uint32 xlogGroupNext; + XLogRecData* xlogGrouprdata; + XLogRecPtr xlogGroupfpw_lsn; + XLogRecPtr* xlogGroupProcLastRecPtr; + XLogRecPtr* xlogGroupXactLastRecEnd; + void* xlogGroupCurrentTransactionState; + XLogRecPtr* xlogGroupRedoRecPtr; + void* xlogGroupLogwrtResult; + XLogRecPtr xlogGroupReturntRecPtr; + TimeLineID xlogGroupTimeLineID; + bool* xlogGroupDoPageWrites; + bool xlogGroupIsFPW; + uint64 snap_refcnt_bitmap; +#endif + + LWLock* subxidsLock; + struct XidCache subxids; /* cache for subtransaction XIDs */ + + volatile GtmHostIndex my_gtmhost; + GtmHostIndex suggested_gtmhost; + pg_atomic_uint32 signal_cancel_gtm_conn_flag; + + /* Per-backend LWLock. Protects fields below. */ + LWLock* backendLock; /* protects the fields below */ + + /* Lock manager data, recording fast-path locks taken by this backend. */ + uint64 fpLockBits; /* lock modes held for each fast-path slot */ + FastPathTag fpRelId[FP_LOCK_SLOTS_PER_BACKEND]; /* slots for rel oids */ + bool fpVXIDLock; /* are we holding a fast-path VXID lock? */ + LocalTransactionId fpLocalTransactionId; /* lxid for fast-path VXID + * lock */ + /* The proc which block cur proc */ + PROCLOCK* blockProcLock; + + /* knl_thrd_context who is waiting for lock. Only valid when itself is in ProcSleep() now. */ + void *waitLockThrd; + char *dw_unaligned_buf; + char *dw_buf; + volatile int32 dw_pos; +}; + +/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */ + +/* the offset of the last padding if exists*/ +#define PGXACT_PAD_OFFSET 55 + +/* + * Prior to PostgreSQL 9.2, the fields below were stored as part of the + * PGPROC. However, benchmarking revealed that packing these particular + * members into a separate array as tightly as possible sped up GetSnapshotData + * considerably on systems with many CPU cores, by reducing the number of + * cache lines needing to be fetched. Thus, think very carefully before adding + * anything else here. + */ +typedef struct PGXACT { + GTM_TransactionHandle handle; /* txn handle in GTM */ + TransactionId xid; /* id of top-level transaction currently being + * executed by this proc, if running and XID + * is assigned; else InvalidTransactionId */ + TransactionId prepare_xid; + + TransactionId xmin; /* minimal running XID as it was when we were + * starting our xact, excluding LAZY VACUUM: + * vacuum must not remove tuples deleted by + * xid >= xmin ! */ + CommitSeqNo csn_min; /* local csn min */ + TransactionId next_xid; /* xid sent down from CN */ + int nxids; /* use int replace uint8, avoid overflow when sub xids >= 256 */ + uint8 vacuumFlags; /* vacuum-related flags, see above */ + + bool needToSyncXid; /* At GTM mode, there's a window between CSN log set and proc array remove. + * In this window, we can get CSN but TransactionIdIsInProgress returns true, + * So we need to sync at this window. + */ + bool delayChkpt; /* true if this proc delays checkpoint start; + * previously called InCommit */ +#ifdef __aarch64__ + char padding[PG_CACHE_LINE_SIZE - PGXACT_PAD_OFFSET]; /*padding to 128 bytes*/ +#endif +} PGXACT; + +/* the offset of the last padding if exists*/ +#define PROC_HDR_PAD_OFFSET 112 + +/* + * There is one ProcGlobal struct for the whole database cluster. + */ +typedef struct PROC_HDR { + /* Array of PGPROC structures (not including dummies for prepared txns) */ + PGPROC** allProcs; + /* Array of PGXACT structures (not including dummies for prepared txns) */ + PGXACT* allPgXact; + /* Length of allProcs array */ + uint32 allProcCount; + /* Length of all non-prepared Procs */ + uint32 allNonPreparedProcCount; + /* Head of list of free PGPROC structures */ + PGPROC* freeProcs; + /* Head of list of autovacuum's free PGPROC structures */ + PGPROC* autovacFreeProcs; + /* Head of list of cm agent's free PGPROC structures */ + PGPROC* cmAgentFreeProcs; + /* Head of list of pg_job's free PGPROC structures */ + PGPROC* pgjobfreeProcs; + /* First pgproc waiting for group XID clear */ + pg_atomic_uint32 procArrayGroupFirst; + /* First pgproc waiting for group transaction status update */ + pg_atomic_uint32 clogGroupFirst; + /* WALWriter process's latch */ + Latch* walwriterLatch; + /* WALWriterAuxiliary process's latch */ + Latch* walwriterauxiliaryLatch; + /* Checkpointer process's latch */ + Latch* checkpointerLatch; + /* BCMWriter process's latch */ + Latch* cbmwriterLatch; + /* Current shared estimate of appropriate spins_per_delay value */ + int spins_per_delay; + /* The proc of the Startup process, since not in ProcArray */ + PGPROC* startupProc; + ThreadId startupProcPid; + /* Buffer id of the buffer that Startup process waits for pin on, or -1 */ + int startupBufferPinWaitBufId; +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - PROC_HDR_PAD_OFFSET]; +#endif +} PROC_HDR; + +/* + * We set aside some extra PGPROC structures for auxiliary processes, + * ie things that aren't full-fledged backends but need shmem access. + * + * Background writer, checkpointer and WAL writer run during normal operation. + * Startup process and WAL receiver also consume 2 slots, but WAL writer is + * launched only after startup has exited, so we only need 4 slots. + * + * PGXC needs another slot for the pool manager process + */ +const int MAX_PAGE_WRITER_THREAD_NUM = 8; +const int MAX_BG_WRITER_THREAD_NUM = 8; +const int MAX_COMPACTION_THREAD_NUM = 100; + +/* number of multi auxiliary threads. */ +#define NUM_MULTI_AUX_PROC \ + (MAX_PAGE_WRITER_THREAD_NUM + \ + MAX_RECOVERY_THREAD_NUM + \ + MAX_BG_WRITER_THREAD_NUM + \ + g_instance.shmem_cxt.ThreadPoolGroupNum + \ + MAX_COMPACTION_THREAD_NUM) + +#define NUM_AUXILIARY_PROCS (NUM_SINGLE_AUX_PROC + NUM_MULTI_AUX_PROC) + +/* max number of CMA's connections */ +#define NUM_CMAGENT_PROCS (10) + +#define GLOBAL_ALL_PROCS \ + (g_instance.shmem_cxt.MaxBackends + \ + NUM_CMAGENT_PROCS + NUM_AUXILIARY_PROCS + g_instance.attr.attr_storage.max_prepared_xacts) + +#define GLOBAL_MAX_SESSION_NUM (2 * g_instance.shmem_cxt.MaxBackends) +#define GLOBAL_RESERVE_SESSION_NUM (g_instance.shmem_cxt.MaxReserveBackendId) +#define MAX_SESSION_SLOT_COUNT (GLOBAL_MAX_SESSION_NUM + GLOBAL_RESERVE_SESSION_NUM) +#define MAX_BACKEND_SLOT \ + (g_instance.attr.attr_common.enable_thread_pool ? MAX_SESSION_SLOT_COUNT : g_instance.shmem_cxt.MaxBackends) +#define MAX_SESSION_TIMEOUT 24 * 60 * 60 /* max session timeout value. */ + +#define BackendStatusArray_size (MAX_BACKEND_SLOT + NUM_AUXILIARY_PROCS) + +extern AlarmCheckResult ConnectionOverloadChecker(Alarm* alarm, AlarmAdditionalParam* additionalParam); + +/* + * Function Prototypes + */ +extern int ProcGlobalSemas(void); +extern Size ProcGlobalShmemSize(void); +extern void InitNuma(void); +extern void InitProcGlobal(void); +extern void InitProcess(void); +extern void InitProcessPhase2(void); +extern void InitAuxiliaryProcess(void); + +extern int GetAuxProcEntryIndex(int baseIdx); +extern void PublishStartupProcessInformation(void); + +extern bool HaveNFreeProcs(int n); +extern void ProcReleaseLocks(bool isCommit); +extern int GetUsedConnectionCount(void); +extern int GetUsedInnerToolConnCount(void); + +extern void ProcQueueInit(PROC_QUEUE* queue); +extern int ProcSleep(LOCALLOCK* locallock, LockMethod lockMethodTable, bool allow_con_update); +extern PGPROC* ProcWakeup(PGPROC* proc, int waitStatus); +extern void ProcLockWakeup(LockMethod lockMethodTable, LOCK* lock, const PROCLOCK* proclock = NULL); +extern bool IsWaitingForLock(void); +extern void LockErrorCleanup(void); + +extern void ProcWaitForSignal(void); +extern void ProcSendSignal(ThreadId pid); + +extern TimestampTz GetStatementFinTime(); + +extern bool enable_sig_alarm(int delayms, bool is_statement_timeout); +extern bool enable_lockwait_sig_alarm(int delayms); +extern bool enable_session_sig_alarm(int delayms); +extern bool disable_session_sig_alarm(void); + +extern bool disable_sig_alarm(bool is_statement_timeout); +extern void handle_sig_alarm(SIGNAL_ARGS); + +extern bool enable_standby_sig_alarm(TimestampTz now, TimestampTz fin_time, bool deadlock_only); +extern bool disable_standby_sig_alarm(void); +extern void handle_standby_sig_alarm(SIGNAL_ARGS); + +extern ThreadId getThreadIdFromLogicThreadId(int logictid); +extern int getLogicThreadIdFromThreadId(ThreadId tid); + +extern bool IsRedistributionWorkerProcess(void); + +void CancelBlockedRedistWorker(LOCK* lock, LOCKMODE lockmode); +#endif /* PROC_H */ diff -uprN postgresql-hll-2.14_old/include/storage/procsignal.h postgresql-hll-2.14/include/storage/procsignal.h --- postgresql-hll-2.14_old/include/storage/procsignal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/procsignal.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,72 @@ +/* ------------------------------------------------------------------------- + * + * procsignal.h + * Routines for interprocess signalling + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/procsignal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PROCSIGNAL_H +#define PROCSIGNAL_H + +#include "storage/backendid.h" + +/* + * Reasons for signalling a Postgres child process (a backend or an auxiliary + * process, like checkpointer). We can cope with concurrent signals for different + * reasons. However, if the same reason is signaled multiple times in quick + * succession, the process is likely to observe only one notification of it. + * This is okay for the present uses. + * + * Also, because of race conditions, it's important that all the signals be + * defined so that no harm is done if a process mistakenly receives one. + */ +#ifdef PGXC +/* + * In the case of Postgres-XC, it may be possible that this backend is + * signaled during a pool manager reload process. In this case it means that + * remote node connection has been changed inside pooler, so backend has to + * abort its current transaction, reconnect to pooler and update its session + * information regarding remote node handles. + */ +#endif +typedef enum { + PROCSIG_CATCHUP_INTERRUPT, /* sinval catchup interrupt */ + PROCSIG_NOTIFY_INTERRUPT, /* listen/notify interrupt */ + PROCSIG_DEFAULTXACT_READONLY, /* default transaction read only */ +#ifdef PGXC + PROCSIG_PGXCPOOL_RELOAD, /* abort current transaction and reconnect to pooler */ + PROCSIG_MEMORYCONTEXT_DUMP, /* dump memory context on all backends */ + PROCSIG_UPDATE_WORKLOAD_DATA, /* update workload data */ + PROCSIG_SPACE_LIMIT, /* space limitation */ +#endif + + /* Recovery conflict reasons */ + PROCSIG_RECOVERY_CONFLICT_DATABASE, + PROCSIG_RECOVERY_CONFLICT_TABLESPACE, + PROCSIG_RECOVERY_CONFLICT_LOCK, + PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, + PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, + PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, + PROCSIG_EXECUTOR_FLAG, + + NUM_PROCSIGNALS /* Must be last! */ +} ProcSignalReason; + +/* + * prototypes for functions in procsignal.c + */ +extern Size ProcSignalShmemSize(void); +extern void ProcSignalShmemInit(void); + +extern void ProcSignalInit(int pss_idx); +extern int SendProcSignal(ThreadId pid, ProcSignalReason reason, BackendId backendId); + +extern void procsignal_sigusr1_handler(SIGNAL_ARGS); + +#endif /* PROCSIGNAL_H */ diff -uprN postgresql-hll-2.14_old/include/storage/reinit.h postgresql-hll-2.14/include/storage/reinit.h --- postgresql-hll-2.14_old/include/storage/reinit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/reinit.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * reinit.h + * Reinitialization of unlogged relations + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/fd.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef REINIT_H +#define REINIT_H + +extern void ResetUnloggedRelations(int op); + +#define UNLOGGED_RELATION_CLEANUP 0x0001 +#define UNLOGGED_RELATION_INIT 0x0002 + +#endif /* REINIT_H */ diff -uprN postgresql-hll-2.14_old/include/storage/relfilenode.h postgresql-hll-2.14/include/storage/relfilenode.h --- postgresql-hll-2.14_old/include/storage/relfilenode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/relfilenode.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,253 @@ +/* ------------------------------------------------------------------------- + * + * relfilenode.h + * Physical access information for relations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/relfilenode.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELFILENODE_H +#define RELFILENODE_H + +#include "storage/backendid.h" +#include "storage/block.h" + +/* + * The physical storage of a relation consists of one or more forks. The + * main fork is always created, but in addition to that there can be + * additional forks for storing various metadata. ForkNumber is used when + * we need to refer to a specific fork in a relation. + */ +typedef int ForkNumber; + +#define PAX_DFS_TRUNCATE_FORKNUM -4 +#define PAX_DFS_FORKNUM -3 +#define DFS_FORKNUM -2 +#define InvalidForkNumber -1 +#define MAIN_FORKNUM 0 +#define FSM_FORKNUM 1 +#define VISIBILITYMAP_FORKNUM 2 +#define BCM_FORKNUM 3 +#define INIT_FORKNUM 4 + +/* + * NOTE: if you add a new fork, change MAX_FORKNUM below and update the + * forkNames array in catalog.c + */ +#define MAX_FORKNUM INIT_FORKNUM + +/* + * RelFileNode must provide all that we need to know to physically access + * a relation, with the exception of the backend ID, which can be provided + * separately. Note, however, that a "physical" relation is comprised of + * multiple files on the filesystem, as each fork is stored as a separate + * file, and each fork can be divided into multiple segments. See md.c. + * + * spcNode identifies the tablespace of the relation. It corresponds to + * pg_tablespace.oid. + * + * dbNode identifies the database of the relation. It is zero for + * "shared" relations (those common to all databases of a cluster). + * Nonzero dbNode values correspond to pg_database.oid. + * + * relNode identifies the specific relation. relNode corresponds to + * pg_class.relfilenode (NOT pg_class.oid, because we need to be able + * to assign new physical files to relations in some situations). + * Notice that relNode is only unique within a particular database. + * + * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is + * zero. We support shared relations only in the "global" tablespace. + * + * Note: in pg_class we allow reltablespace == 0 to denote that the + * relation is stored in its database's "default" tablespace (as + * identified by pg_database.dattablespace). However this shorthand + * is NOT allowed in RelFileNode structs --- the real tablespace ID + * must be supplied when setting spcNode. + * + * Note: in pg_class, relfilenode can be zero to denote that the relation + * is a "mapped" relation, whose current true filenode number is available + * from relmapper.c. Again, this case is NOT allowed in RelFileNodes. + * + * Note: various places use RelFileNode in hashtable keys. Therefore, + * there *must not* be any unused padding bytes in this struct. That + * should be safe as long as all the fields are of type Oid. + */ +typedef struct RelFileNode { + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ + int4 bucketNode; /* bucket */ +} RelFileNode; + +/*RelFileNodeOld: Old version relfilenode. Compatible with older versions of relfilenode.*/ + +typedef struct RelFileNodeOld +{ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ +} RelFileNodeOld; + +#define RelFileNodeRelCopy(relFileNodeRel, relFileNode) \ + do { \ + (relFileNodeRel).spcNode = (relFileNode).spcNode; \ + (relFileNodeRel).dbNode = (relFileNode).dbNode; \ + (relFileNodeRel).relNode = (relFileNode).relNode; \ + } while(0) + +#define RelFileNodeCopy(relFileNode, relFileNodeRel, bucketid) \ + do { \ + (relFileNode).spcNode = (relFileNodeRel).spcNode; \ + (relFileNode).dbNode = (relFileNodeRel).dbNode; \ + (relFileNode).relNode = (relFileNodeRel).relNode; \ + (relFileNode).bucketNode = bucketid; \ + } while(0) + +/*This struct used for remove duplicated file list where we scan part of BCM files*/ +typedef struct RelFileNodeKey { + RelFileNode relfilenode; /*relfilenode*/ + int columnid; /*column for CU store*/ +} RelFileNodeKey; + +typedef struct RelFileNodeKeyEntry { + RelFileNodeKey key; + int number; /*Times the relfilenode occurence*/ +} RelFileNodeKeyEntry; + +/* + * Augmenting a relfilenode with the backend ID provides all the information + * we need to locate the physical storage. The backend ID is InvalidBackendId + * for regular relations (those accessible to more than one backend), or the + * owning backend's ID for backend-local relations. Backend-local relations + * are always transient and removed in case of a database crash; they are + * never WAL-logged or fsync'd. + */ +typedef struct RelFileNodeBackend { + RelFileNode node; + BackendId backend; +} RelFileNodeBackend; + +typedef enum StorageEngine { ROW_STORE = 0, COLUMN_STORE } StorageEngine; + +#define IsSupportSE(se) (ROW_STORE <= se && se <= COLUMN_STORE) + +// key to identify data file +// +typedef struct RelFileNodeForkNum { + RelFileNodeBackend rnode; + BlockNumber segno; + ForkNumber forknumber; + StorageEngine storage; +} RelFileNodeForkNum; + +#define RelFileNodeBackendIsTemp(rnode) ((rnode).backend != InvalidBackendId) + +/* + * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first + * since that is most likely to be different in two unequal RelFileNodes. It + * is probably redundant to compare spcNode if the other fields are found equal, + * but do it anyway to be sure. Likewise for checking the backend ID in + * RelFileNodeBackendEquals. + */ +#define RelFileNodeEquals(node1, node2) \ + ((node1).relNode == (node2).relNode && (node1).dbNode == (node2).dbNode && (node1).spcNode == (node2).spcNode && \ + (node1).bucketNode == (node2).bucketNode) + +#define BucketRelFileNodeEquals(tarnode, srcnode) \ + ((tarnode).relNode == (srcnode).relNode && (tarnode).dbNode == (srcnode).dbNode && (tarnode).spcNode == (srcnode).spcNode && \ + (((tarnode).bucketNode == DIR_BUCKET_ID) || ((tarnode).bucketNode == (srcnode).bucketNode))) + +#define RelFileNodeRelEquals(node1, node2) \ + ((node1).relNode == (node2).relNode && \ + (node1).dbNode == (node2).dbNode && \ + (node1).spcNode == (node2).spcNode) + +#define RelFileNodeBackendEquals(node1, node2) \ + ((node1).node.relNode == (node2).node.relNode && (node1).node.dbNode == (node2).node.dbNode && \ + (node1).backend == (node2).backend && (node1).node.spcNode == (node2).node.spcNode && \ + (node1).node.bucketNode == (node2).node.bucketNode) + +// keep [MAX_FORKNUM, FirstColumnForkNum) unused. +// try my best to reduce the effect on updating. +#define FirstColForkNum (MAX_FORKNUM) + +// ColForkNum include column id information +// +#define IsValidColForkNum(forkNum) ((forkNum) > FirstColForkNum) + +#define IsValidDfsForkNum(forkNum) ((forkNum) == DFS_FORKNUM) + +#define IsValidPaxDfsForkNum(forkNum) ((forkNum) == PAX_DFS_FORKNUM) + +#define IsTruncateDfsForkNum(forkNum) ((forkNum) == PAX_DFS_TRUNCATE_FORKNUM) + +#define ColForkNum2ColumnId(forkNum) (AssertMacro(IsValidColForkNum(forkNum)), ((forkNum)-FirstColForkNum)) + +#define ColumnId2ColForkNum(attid) (AssertMacro(AttrNumberIsForUserDefinedAttr(attid)), (FirstColForkNum + (attid))) + +// fetch column number from forknum given. +#define GetColumnNum(forkNum) (IsValidColForkNum(forkNum) ? ColForkNum2ColumnId(forkNum) : 0) + +typedef struct { + RelFileNode filenode; + // for row table, *forknum* <= MAX_FORKNUM. + // for column table, *forknum* > FirstColForkNum. + ForkNumber forknum; + // relation's owner id + Oid ownerid; +} ColFileNode; + +typedef struct { + RelFileNodeOld filenode; + // for row table, *forknum* <= MAX_FORKNUM. + // for column table, *forknum* > FirstColForkNum. + ForkNumber forknum; + // relation's owner id + Oid ownerid; +} ColFileNodeRel; + +/* + * 1) ForkNumber type should be must be 32-bit; + * 2) forknum value occupies the lower 16-bit; + * 3) bucketid value occupies the upper 16-bit; + * If the upper three condition changes, please consider this function again. + */ +static inline void forknum_add_bucketid(ForkNumber& forknum, int4 bucketid) +{ + forknum = (ForkNumber)(((uint2)forknum) | (((uint2)(bucketid + 1)) << 16)); +} + +/* + * 1) converse ForkNumber to uint to make sure logic right-shift + * 2) converse the logic-right-shift result to int2 to ensure the negative bucketid value + */ +static inline int4 forknum_get_bucketid(const ForkNumber& forknum) +{ + return (int2)((((uint)forknum >> 16) & 0xffff) - 1); +} + +/* + * 1) converse ForkNumber to uint to make sure the bit-operation safe + * 2) converse the lower 16-bit to int2 to ensure the negative forknum + */ +static inline ForkNumber forknum_get_forknum(const ForkNumber& forknum) +{ + return (int2)((uint)forknum & 0xffff); +} + +#define ColFileNodeCopy(colFileNode, colFileNodeRel) \ + do { \ + (colFileNode)->filenode.spcNode = (colFileNodeRel)->filenode.spcNode; \ + (colFileNode)->filenode.dbNode = (colFileNodeRel)->filenode.dbNode; \ + (colFileNode)->filenode.relNode = (colFileNodeRel)->filenode.relNode; \ + (colFileNode)->filenode.bucketNode = forknum_get_bucketid((colFileNodeRel)->forknum); \ + (colFileNode)->forknum = forknum_get_forknum((colFileNodeRel)->forknum); \ + (colFileNode)->ownerid= (colFileNodeRel)->ownerid; \ + } while(0) + +#endif /* RELFILENODE_H */ diff -uprN postgresql-hll-2.14_old/include/storage/remote_adapter.h postgresql-hll-2.14/include/storage/remote_adapter.h --- postgresql-hll-2.14_old/include/storage/remote_adapter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/remote_adapter.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remote_adapter.h + * + * + * + * IDENTIFICATION + * src/include/storage/remote_adapter.h + * + * NOTE + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef REMOTE_ADAPTER_H +#define REMOTE_ADAPTER_H + +#include "c.h" + +#include "storage/remote_read.h" + +#define Free(x) \ + do { \ + if ((x)) \ + free((x)); \ + (x) = NULL; \ + } while (0) + +typedef struct TlsCertPath { + char caPath[MAX_PATH_LEN]; + char keyPath[MAX_PATH_LEN]; + char certPath[MAX_PATH_LEN]; +} TlsCertPath; + +typedef struct RemoteReadContext RemoteReadContext; + +extern RemoteReadContext* InitRemoteReadContext(); + +extern void ReleaseRemoteReadContext(RemoteReadContext* context); + +extern int StandbyReadCUforPrimary(uint32 spcnode, uint32 dbnode, uint32 relnode, int32 colid, uint64 offset, + int32 size, uint64 lsn, RemoteReadContext* context, char** cudata); + +extern int StandbyReadPageforPrimary(uint32 spcnode, uint32 dbnode, uint32 relnode, int16 bucketnode, int32 forknum, uint32 blocknum, + uint32 blocksize, uint64 lsn, RemoteReadContext* context, char** pagedata); + +extern void CleanWorkEnv(); + +extern bool GetCertEnv(const char* envName, char* outputEnvStr, size_t envValueLen); + +extern char* GetCertStr(char* path, int* len); + +extern int GetRemoteReadMode(); + +extern void OutputMsgforRPC(int elevel, const char* fmt, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +#endif /* REMOTE_ADAPTER_H */ diff -uprN postgresql-hll-2.14_old/include/storage/remote_read.h postgresql-hll-2.14/include/storage/remote_read.h --- postgresql-hll-2.14_old/include/storage/remote_read.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/remote_read.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * remote_read.h + * + * + * + * IDENTIFICATION + * src/include/storage/remote_read.h + * + * NOTE + * Don't include any of RPC or PG header file + * Just using simple C API interface + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef REMOTE_READ_H +#define REMOTE_READ_H + +#include "c.h" + +typedef enum { + REMOTE_READ_OFF = 0, /* not allow reomte read */ + REMOTE_READ_NON_AUTH, /* remote read no ssl */ + REMOTE_READ_AUTH /* remote read with SSL */ +} remote_read_param; + +#define REMOTE_READ_OK 0 +#define REMOTE_READ_NEED_WAIT 1 +#define REMOTE_READ_CRC_ERROR 2 +#define REMOTE_READ_RPC_ERROR 3 +#define REMOTE_READ_SIZE_ERROR 4 +#define REMOTE_READ_IO_ERROR 5 +#define REMOTE_READ_RPC_TIMEOUT 6 +#define REMOTE_READ_BLCKSZ_NOT_SAME 7 +#define REMOTE_READ_MEMCPY_ERROR 8 + +#define MAX_PATH_LEN 1024 + +#define MAX_IPADDR_LEN 32 + +extern const char* RemoteReadErrMsg(int error_code); + +extern void GetRemoteReadAddress(char* first_address, char* second_address, size_t address_len); + +extern void GetIPAndPort(char* address, char* ip, char* port, size_t len); + +extern void GetHostnamebyIP(const char* ip, char* hostname, size_t hostnameLen); + +extern bool CanRemoteRead(); + +extern bool IsRemoteReadModeAuth(); + +extern bool IsRemoteReadModeOn(); +extern int SetRemoteReadModeOffAndGetOldMode(); +extern void SetRemoteReadMode(int mode); + +#endif /* REMOTE_READ_H */ diff -uprN postgresql-hll-2.14_old/include/storage/shmem.h postgresql-hll-2.14/include/storage/shmem.h --- postgresql-hll-2.14_old/include/storage/shmem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/shmem.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,78 @@ +/* ------------------------------------------------------------------------- + * + * shmem.h + * shared memory management structures + * + * Historical note: + * A long time ago, Postgres' shared memory region was allowed to be mapped + * at a different address in each process, and shared memory "pointers" were + * passed around as offsets relative to the start of the shared memory region. + * That is no longer the case: each process must map the shared memory region + * at the same address. This means shared memory pointers can be passed + * around directly between different processes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/shmem.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SHMEM_H +#define SHMEM_H + +#include "utils/hsearch.h" + +/* shmqueue.c */ +typedef struct SHM_QUEUE { + struct SHM_QUEUE* prev; + struct SHM_QUEUE* next; +} SHM_QUEUE; + +/* shmem.c */ +extern void InitShmemAccess(void* seghdr); +extern void InitShmemAllocation(void); +extern void* ShmemAlloc(Size size); +extern bool ShmemAddrIsValid(const void* addr); +extern void InitShmemIndex(void); +extern HTAB* ShmemInitHash(const char* name, long init_size, long max_size, HASHCTL* infoP, int hash_flags); +extern void* ShmemInitStruct(const char* name, Size size, bool* foundPtr); +extern Size add_size(Size s1, Size s2); +extern Size mul_size(Size s1, Size s2); + +/* ipci.c */ +extern void RequestAddinShmemSpace(Size size); + +/* size constants for the shmem index table */ +/* max size of data structure string name */ +#define SHMEM_INDEX_KEYSIZE (48) +/* estimated size of the shmem index table (not a hard limit) */ +#define SHMEM_INDEX_SIZE (64) + +/* this is a hash bucket in the shmem index table */ +typedef struct { + char key[SHMEM_INDEX_KEYSIZE]; /* string name */ + void* location; /* location in shared mem */ + Size size; /* # bytes allocated for the structure */ +} ShmemIndexEnt; + +/* + * prototypes for functions in shmqueue.c + */ +extern void SHMQueueInit(SHM_QUEUE* queue); +extern void SHMQueueElemInit(SHM_QUEUE* queue); +extern void SHMQueueDelete(SHM_QUEUE* queue); +extern void SHMQueueInsertBefore(SHM_QUEUE* queue, SHM_QUEUE* elem); +extern void SHMQueueInsertAfter(SHM_QUEUE* queue, SHM_QUEUE* elem); +extern Pointer SHMQueueNext(const SHM_QUEUE* queue, const SHM_QUEUE* curElem, Size linkOffset); +extern Pointer SHMQueuePrev(const SHM_QUEUE* queue, const SHM_QUEUE* curElem, Size linkOffset); +extern bool SHMQueueEmpty(const SHM_QUEUE* queue); +extern bool SHMQueueIsDetached(const SHM_QUEUE* queue); + +// Heap memory allocation +// +extern void* HeapMemAlloc(Size size); +extern HTAB* HeapMemInitHash(const char* name, long init_size, long max_size, HASHCTL* infoP, int hash_flags); +extern void HeapMemResetHash(HTAB* hashtbl, const char* tabname); + +#endif /* SHMEM_H */ diff -uprN postgresql-hll-2.14_old/include/storage/sinvaladt.h postgresql-hll-2.14/include/storage/sinvaladt.h --- postgresql-hll-2.14_old/include/storage/sinvaladt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/sinvaladt.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,43 @@ +/* ------------------------------------------------------------------------- + * + * sinvaladt.h + * POSTGRES shared cache invalidation data manager. + * + * The shared cache invalidation manager is responsible for transmitting + * invalidation messages between backends. Any message sent by any backend + * must be delivered to all already-running backends before it can be + * forgotten. (If we run out of space, we instead deliver a "RESET" + * message to backends that have fallen too far behind.) + * + * The struct type SharedInvalidationMessage, defining the contents of + * a single message, is defined in sinval.h. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/sinvaladt.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SINVALADT_H +#define SINVALADT_H + +#include "storage/proc.h" +#include "storage/sinval.h" + +/* + * prototypes for functions in sinvaladt.c + */ +extern Size SInvalShmemSize(void); +extern void CreateSharedInvalidationState(void); +extern void CleanupWorkSessionInvalidation(void); +extern void SharedInvalBackendInit(bool sendOnly, bool worksession); +extern PGPROC* BackendIdGetProc(int backendID); + +extern void SIInsertDataEntries(const SharedInvalidationMessage* data, int n); +extern int SIGetDataEntries(SharedInvalidationMessage* data, int datasize); +extern void SICleanupQueue(bool callerHasWriteLock, int minFree); + +extern LocalTransactionId GetNextLocalTransactionId(void); + +#endif /* SINVALADT_H */ diff -uprN postgresql-hll-2.14_old/include/storage/sinval.h postgresql-hll-2.14/include/storage/sinval.h --- postgresql-hll-2.14_old/include/storage/sinval.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/sinval.h 2020-12-12 17:06:43.381349767 +0800 @@ -0,0 +1,155 @@ +/* ------------------------------------------------------------------------- + * + * sinval.h + * POSTGRES shared cache invalidation communication definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/sinval.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SINVAL_H +#define SINVAL_H + +#include + +#include "storage/relfilenode.h" + +/* + * We support several types of shared-invalidation messages: + * * invalidate a specific tuple in a specific catcache + * * invalidate all catcache entries from a given system catalog + * * invalidate a relcache entry for a specific logical relation + * * invalidate an smgr cache entry for a specific physical relation + * * invalidate the mapped-relation mapping for a given database + * More types could be added if needed. The message type is identified by + * the first "int8" field of the message struct. Zero or positive means a + * specific-catcache inval message (and also serves as the catcache ID field). + * Negative values identify the other message types, as per codes below. + * + * Catcache inval events are initially driven by detecting tuple inserts, + * updates and deletions in system catalogs (see CacheInvalidateHeapTuple). + * An update can generate two inval events, one for the old tuple and one for + * the new, but this is reduced to one event if the tuple's hash key doesn't + * change. Note that the inval events themselves don't actually say whether + * the tuple is being inserted or deleted. Also, since we transmit only a + * hash key, there is a small risk of unnecessary invalidations due to chance + * matches of hash keys. + * + * Note that some system catalogs have multiple caches on them (with different + * indexes). On detecting a tuple invalidation in such a catalog, separate + * catcache inval messages must be generated for each of its caches, since + * the hash keys will generally be different. + * + * Catcache and relcache invalidations are transactional, and so are sent + * to other backends upon commit. Internally to the generating backend, + * they are also processed at CommandCounterIncrement so that later commands + * in the same transaction see the new state. The generating backend also + * has to process them at abort, to flush out any cache state it's loaded + * from no-longer-valid entries. + * + * smgr and relation mapping invalidations are non-transactional: they are + * sent immediately when the underlying file change is made. + */ + +typedef struct { + int8 id; /* cache ID --- must be first */ + Oid dbId; /* database ID, or 0 if a shared relation */ + uint32 hashValue; /* hash value of key for this catcache */ +} SharedInvalCatcacheMsg; + +#define SHAREDINVALCATALOG_ID (-1) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 if a shared catalog */ + Oid catId; /* ID of catalog whose contents are invalid */ +} SharedInvalCatalogMsg; + +#define SHAREDINVALRELCACHE_ID (-2) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 if a shared relation */ + Oid relId; /* relation ID */ +} SharedInvalRelcacheMsg; + +#define SHAREDINVALSMGR_ID (-3) + +typedef struct { + /* note: field layout chosen to pack into 16 bytes */ + int8 id; /* type field --- must be first */ + int8 backend_hi; /* high bits of backend ID, if temprel */ + uint16 backend_lo; /* low bits of backend ID, if temprel */ + RelFileNodeOld rnode; /* spcNode, dbNode, relNode */ +} SharedInvalSmgrMsg; + +#define SHAREDINVALRELMAP_ID (-4) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID, or 0 for shared catalogs */ +} SharedInvalRelmapMsg; + +#define SHAREDINVALPARTCACHE_ID (-5) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID */ + Oid partId; /* partition ID */ +} SharedInvalPartcacheMsg; + +#define SHAREDINVALHBKTSMGR_ID (-6) + +typedef struct { + /* note: field layout chosen to pack into 16 bytes */ + int8 id; /* type field --- must be first */ + int16 bucketId; /* bucketId */ + RelFileNodeOld rnode; /* spcNode, dbNode, relNode */ +} SharedInvalHbktSmgrMsg; + +#define SHAREDINVALFUNC_ID (-7) + +typedef struct { + int8 id; /* type field --- must be first */ + Oid dbId; /* database ID */ + Oid funcOid; /* function ID */ +} SharedInvalFuncMsg; + +typedef union SharedInvalidationMessage { + int8 id; /* type field --- must be first */ + SharedInvalCatcacheMsg cc; + SharedInvalCatalogMsg cat; + SharedInvalRelcacheMsg rc; + SharedInvalPartcacheMsg pc; + SharedInvalSmgrMsg sm; + SharedInvalHbktSmgrMsg hbksm; + SharedInvalRelmapMsg rm; + SharedInvalFuncMsg fm; +} SharedInvalidationMessage; + +/* Counter of messages processed; don't worry about overflow. */ +extern THR_LOCAL volatile sig_atomic_t catchupInterruptPending; + +extern void SendSharedInvalidMessages(const SharedInvalidationMessage* msgs, int n); +extern void ReceiveSharedInvalidMessages( + void (*invalFunction)(SharedInvalidationMessage* msg), void (*resetFunction)(void)); + +/* signal handler for catchup events (PROCSIG_CATCHUP_INTERRUPT) */ +extern void HandleCatchupInterrupt(void); + +/* + * enable/disable processing of catchup events directly from signal handler. + * The enable routine first performs processing of any catchup events that + * have occurred since the last disable. + */ +extern void ProcessCatchupInterrupt(void); + +extern int xactGetCommittedInvalidationMessages(SharedInvalidationMessage** msgs, bool* RelcacheInitFileInval); +extern void ProcessCommittedInvalidationMessages( + SharedInvalidationMessage* msgs, int nmsgs, bool RelcacheInitFileInval, Oid dbid, Oid tsid); +extern void LocalExecuteInvalidationMessage(SharedInvalidationMessage* msg); +#endif /* SINVAL_H */ diff -uprN postgresql-hll-2.14_old/include/storage/s_lock.h postgresql-hll-2.14/include/storage/s_lock.h --- postgresql-hll-2.14_old/include/storage/s_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/s_lock.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,1134 @@ +/* ------------------------------------------------------------------------- + * + * s_lock.h + * Hardware-dependent implementation of spinlocks. + * + * NOTE: none of the macros in this file are intended to be called directly. + * Call them through the hardware-independent macros in spin.h. + * + * The following hardware-dependent macros must be provided for each + * supported platform: + * + * void S_INIT_LOCK(slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void S_LOCK(slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void S_UNLOCK(slock_t *lock) + * Unlock a previously acquired lock. + * + * bool S_LOCK_FREE(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * void SPIN_DELAY(void) + * Delay operation to occur inside spinlock wait loop. + * + * Note to implementors: there are default implementations for all these + * macros at the bottom of the file. Check if your platform can use + * these or needs to override them. + * + * Usually, S_LOCK() is implemented in terms of even lower-level macros + * TAS() and TAS_SPIN(): + * + * int TAS(slock_t *lock) + * Atomic test-and-set instruction. Attempt to acquire the lock, + * but do *not* wait. Returns 0 if successful, nonzero if unable + * to acquire the lock. + * + * int TAS_SPIN(slock_t *lock) + * Like TAS(), but this version is used when waiting for a lock + * previously found to be contended. By default, this is the + * same as TAS(), but on some architectures it's better to poll a + * contended lock using an unlocked instruction and retry the + * atomic test-and-set only when it appears free. + * + * TAS() and TAS_SPIN() are NOT part of the API, and should never be called + * directly. + * + * CAUTION: on some platforms TAS() and/or TAS_SPIN() may sometimes report + * failure to acquire a lock even when the lock is not locked. For example, + * on Alpha TAS() will "fail" if interrupted. Therefore a retry loop must + * always be used, even if you are certain the lock is free. + * + * It is the responsibility of these macros to make sure that the compiler + * does not re-order accesses to shared memory to precede the actual lock + * acquisition, or follow the lock release. Prior to PostgreSQL 9.5, this + * was the caller's responsibility, which meant that callers had to use + * volatile-qualified pointers to refer to both the spinlock itself and the + * shared data being accessed within the spinlocked critical section. This + * was notationally awkward, easy to forget (and thus error-prone), and + * prevented some useful compiler optimizations. For these reasons, we + * now require that the macros themselves prevent compiler re-ordering, + * so that the caller doesn't need to take special precautions. + * + * On platforms with weak memory ordering, the TAS(), TAS_SPIN(), and + * S_UNLOCK() macros must further include hardware-level memory fence + * instructions to prevent similar re-ordering at the hardware level. + * TAS() and TAS_SPIN() must guarantee that loads and stores issued after + * the macro are not executed until the lock has been obtained. Conversely, + * S_UNLOCK() must guarantee that loads and stores issued before the macro + * have been executed before the lock is released. + * + * On most supported platforms, TAS() uses a tas() function written + * in assembly language to execute a hardware atomic-test-and-set + * instruction. Equivalent OS-supplied mutex routines could be used too. + * + * If no system-specific TAS() is available (ie, HAVE_SPINLOCKS is not + * defined), then we fall back on an emulation that uses SysV semaphores + * (see spin.c). This emulation will be MUCH MUCH slower than a proper TAS() + * implementation, because of the cost of a kernel call per lock or unlock. + * An old report is that Postgres spends around 40% of its time in semop(2) + * when using the SysV semaphore code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/s_lock.h + * + * ------------------------------------------------------------------------- + */ +#ifndef S_LOCK_H +#define S_LOCK_H + +#include "storage/pg_sema.h" + +#if !defined(ENABLE_THREAD_CHECK) || defined(__aarch64__) + +#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +/************************************************************************* + * All the gcc inlines + * Gcc consistently defines the CPU as __cpu__. + * Other compilers use __cpu or __cpu__ so we test for both in those cases. + */ + +/* ---------- + * Standard gcc asm format (assuming "volatile slock_t *lock"): + + __asm__ __volatile__( + " instruction \n" + " instruction \n" + " instruction \n" +: "=r"(_res), "+m"(*lock) // return register, in/out lock value +: "r"(lock) // lock pointer, in input register +: "memory", "cc"); // show clobbered registers here + + * The output-operands list (after first colon) should always include + * "+m"(*lock), whether or not the asm code actually refers to this + * operand directly. This ensures that gcc believes the value in the + * lock variable is used and set by the asm code. Also, the clobbers + * list (after third colon) should always include "memory"; this prevents + * gcc from thinking it can cache the values of shared-memory fields + * across the asm code. Add "cc" if your asm code changes the condition + * code register, and also list any temp registers the code uses. + * ---------- + */ + +#ifdef __i386__ /* 32-bit i386 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * Use a non-locking test before asserting the bus lock. Note that the + * extra test appears to be a small loss on some x86 platforms and a small + * win on others; it's by no means clear that we should keep it. + */ + __asm__ __volatile__(" cmpb $0,%1 \n" + " jne 1f \n" + " lock \n" + " xchgb %0,%1 \n" + "1: \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * This sequence is equivalent to the PAUSE instruction ("rep" is + * ignored by old IA32 processors if the following instruction is + * not a string operation); the IA-32 Architecture Software + * Developer's Manual, Vol. 3, Section 7.7.2 describes why using + * PAUSE in the inner loop of a spin lock is necessary for good + * performance: + * + * The PAUSE instruction improves the performance of IA-32 + * processors supporting Hyper-Threading Technology when + * executing spin-wait loops and other routines where one + * thread is accessing a shared lock or semaphore in a tight + * polling loop. When executing a spin-wait loop, the + * processor can suffer a severe performance penalty when + * exiting the loop because it detects a possible memory order + * violation and flushes the core processor's pipeline. The + * PAUSE instruction provides a hint to the processor that the + * code sequence is a spin-wait loop. The processor uses this + * hint to avoid the memory order violation and prevent the + * pipeline flush. In addition, the PAUSE instruction + * de-pipelines the spin-wait loop to prevent it from + * consuming execution resources excessively. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __i386__ */ + +#ifdef __x86_64__ /* AMD Opteron, Intel EM64T */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + /* + * On Opteron, using a non-locking test before the locking instruction + * is a huge loss. On EM64T, it appears to be a wash or small loss, + * so we needn't bother to try to distinguish the sub-architectures. + */ + __asm__ __volatile__(" lock \n" + " xchgb %0,%1 \n" + : "+q"(_res), "+m"(*lock) + : + : "memory", "cc"); + return (int)_res; +} + +#define SPIN_DELAY() spin_delay() + +static __inline__ void spin_delay(void) +{ + /* + * Adding a PAUSE in the spin delay loop is demonstrably a no-op on + * Opteron, but it may be of some use on EM64T, so we keep it. + */ + __asm__ __volatile__(" rep; nop \n"); +} + +#endif /* __x86_64__ */ + +#if defined(__ia64__) || defined(__ia64) +/* + * Intel Itanium, gcc or Intel's compiler. + * + * Itanium has weak memory ordering, but we rely on the compiler to enforce + * strict ordering of accesses to volatile data. In particular, while the + * xchg instruction implicitly acts as a memory barrier with 'acquire' + * semantics, we do not have an explicit memory fence instruction in the + * S_UNLOCK macro. We use a regular assignment to clear the spinlock, and + * trust that the compiler marks the generated store instruction with the + * ".rel" opcode. + * + * Testing shows that assumption to hold on gcc, although I could not find + * any explicit statement on that in the gcc manual. In Intel's compiler, + * the -m[no-]serialize-volatile option controls that, and testing shows that + * it is enabled by default. + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +#ifndef __INTEL_COMPILER + +static __inline__ int tas(volatile slock_t* lock) +{ + long int ret; + + __asm__ __volatile__(" xchg4 %0=%1,%2 \n" : "=r"(ret), "+m"(*lock) : "r"(1) : "memory"); + return (int)ret; +} + +#else /* __INTEL_COMPILER */ + +static __inline__ int tas(volatile slock_t* lock) +{ + int ret; + + ret = _InterlockedExchange(lock, 1); /* this is a xchg asm macro */ + + return ret; +} + +#endif /* __INTEL_COMPILER */ +#endif /* __ia64__ || __ia64 */ + +/* + * On ARM64, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ + +#if defined(__aarch64__) || defined(__aarch64) + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); + void AnnotateHappensAfter(const char *f, int l, uintptr_t addr); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateHappensAfter(addr) AnnotateHappensAfter(__FILE__, __LINE__, (uintptr_t)addr) +#else +#define TsAnnotateHappensBefore(addr) +#define TsAnnotateHappensAfter(addr) +#endif /* endif ENABLE_THREAD_CHECK */ + +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int +tas(volatile slock_t *lock) +{ + int ret = __sync_lock_test_and_set(lock, 1); + TsAnnotateHappensAfter(lock); + return ret; +} + +extern int (*arm_tas_spin)(volatile slock_t *lock); + +#define S_UNLOCK(lock) do { \ + TsAnnotateHappensBefore(lock); \ + __sync_lock_release(lock); \ +} while(0) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile register slock_t* ulAddr = lock; + register slock_t _res = 1; + unsigned int tmp = 0; + + __asm__ volatile("// __xchg4\n" + "1: ldaxr %w0, %2\n" + " stlxr %w1, %w3, %2\n" + " cbnz %w1, 1b\n" + : "=&r"(_res), "=&r"(tmp), "+Q"(*ulAddr) + : "r"(_res) + : "cc", "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __aarch64__ */ + +/* + * On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if + * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or + * later, so the compiler builtin is preferred if available. Note also that + * the int-width variant of the builtin works on more chips than other widths. + */ +#if defined(__arm__) || defined(__arm) +#define HAS_TEST_AND_SET + +#define TAS(lock) tas(lock) + +#ifdef HAVE_GCC_INT_ATOMICS + +typedef int slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + return __sync_lock_test_and_set(lock, 1); +} + +#define S_UNLOCK(lock) __sync_lock_release(lock) + +#else /* !HAVE_GCC_INT_ATOMICS */ + +typedef unsigned char slock_t; + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res = 1; + + __asm__ __volatile__(" swpb %0, %0, [%2] \n" : "+r"(_res), "+m"(*lock) : "r"(lock) : "memory"); + return (int)_res; +} + +#endif /* HAVE_GCC_INT_ATOMICS */ +#endif /* __arm__ */ + +/* S/390 and S/390x Linux (32- and 64-bit zSeries) */ +#if defined(__s390__) || defined(__s390x__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + int _res = 0; + + __asm__ __volatile__(" cs %0,%3,0(%2) \n" : "+d"(_res), "+m"(*lock) : "a"(lock), "d"(1) : "memory", "cc"); + return _res; +} + +#endif /* __s390__ || __s390x__ */ + +#if defined(__sparc__) /* Sparc */ +/* + * Solaris has always run sparc processors in TSO (total store) mode, but + * linux didn't use to and the *BSDs still don't. So, be careful about + * acquire/release semantics. The CPU will treat superflous membars as NOPs, + * so it's just code space. + */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + /* + * See comment in /pg/backend/port/tas/solaris_sparc.s for why this + * uses "ldstub", and that file uses "cas". gcc currently generates + * sparcv7-targeted binaries, so "cas" use isn't possible. + */ + __asm__ __volatile__(" ldstub [%2], %0 \n" : "=r"(_res), "+m"(*lock) : "r"(lock) : "memory"); +#if defined(__sparcv7) + /* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. + */ +#elif defined(__sparcv8) + /* stbar is available (and required for both PSO, RMO), membar isn't */ + __asm__ __volatile__("stbar \n" ::: "memory"); +#else + /* + * #LoadStore (RMO) | #LoadLoad (RMO) together are the appropriate acquire + * barrier for sparcv8+ upwards. + */ + __asm__ __volatile__("membar #LoadStore | #LoadLoad \n" ::: "memory"); +#endif + return (int)_res; +} + +#if defined(__sparcv7) +/* + * No stbar or membar available, luckily no actually produced hardware + * requires a barrier. We fall through to the default gcc definition of + * S_UNLOCK in this case. + */ +#elif defined(__sparcv8) +/* stbar is available (and required for both PSO, RMO), membar isn't */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("stbar \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#else +/* + * #LoadStore (RMO) | #StoreStore (RMO, PSO) together are the appropriate + * release barrier for sparcv8+ upwards. + */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("membar #LoadStore | #StoreStore \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#endif + +#endif /* __sparc__ */ + +/* PowerPC */ +#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__) +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +/* On PPC, it's a win to use a non-locking test before the lwarx */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) + +/* + * NOTE: per the Enhanced PowerPC Architecture manual, v1.0 dated 7-May-2002, + * an isync is a sufficient synchronization barrier after a lwarx/stwcx loop. + * On newer machines, we can use lwsync instead for better performance. + */ +static __inline__ int tas(volatile slock_t* lock) +{ + slock_t _t; + int _res; + + __asm__ __volatile__( +#ifdef USE_PPC_LWARX_MUTEX_HINT + " lwarx %0,0,%3,1 \n" +#else + " lwarx %0,0,%3 \n" +#endif + " cmpwi %0,0 \n" + " bne 1f \n" + " addi %0,%0,1 \n" + " stwcx. %0,0,%3 \n" + " beq 2f \n" + "1: li %1,1 \n" + " b 3f \n" + "2: \n" +#ifdef USE_PPC_LWSYNC + " lwsync \n" +#else + " isync \n" +#endif + " li %1,0 \n" + "3: \n" + + : "=&r"(_t), "=r"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "cc"); + return _res; +} + +/* + * PowerPC S_UNLOCK is almost standard but requires a "sync" instruction. + * On newer machines, we can use lwsync instead for better performance. + */ +#ifdef USE_PPC_LWSYNC +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" lwsync \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#else +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" sync \n" ::: "memory"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) +#endif /* USE_PPC_LWSYNC */ + +#endif /* powerpc */ + +/* Linux Motorola 68k */ +#if (defined(__mc68000__) || defined(__m68k__)) && defined(__linux__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int rv; + + __asm__ __volatile__(" clrl %0 \n" + " tas %1 \n" + " sne %0 \n" + : "=d"(rv), "+m"(*lock) + : + : "memory", "cc"); + return rv; +} + +#endif /* (__mc68000__ || __m68k__) && __linux__ */ + +/* + * VAXen -- even multiprocessor ones + * (thanks to Tom Ivar Helbekkmo) + */ +#if defined(__vax__) +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" movl $1, %0 \n" + " bbssi $0, (%2), 1f \n" + " clrl %0 \n" + "1: \n" + : "=&r"(_res), "+m"(*lock) + : "r"(lock) + : "memory"); + return _res; +} + +#endif /* __vax__ */ + +#if defined(__ns32k__) /* National Semiconductor 32K */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + __asm__ __volatile__(" sbitb 0, %1 \n" + " sfsd %0 \n" + : "=r"(_res), "+m"(*lock) + : + : "memory"); + return _res; +} + +#endif /* __ns32k__ */ + +#if defined(__alpha) || defined(__alpha__) /* Alpha */ +/* + * Correct multi-processor locking methods are explained in section 5.5.3 + * of the Alpha AXP Architecture Handbook, which at this writing can be + * found at ftp://ftp.netbsd.org/pub/NetBSD/misc/dec-docs/index.html. + * For gcc we implement the handbook's code directly with inline assembler. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register slock_t _res; + + __asm__ __volatile__(" ldq $0, %1 \n" + " bne $0, 2f \n" + " ldq_l %0, %1 \n" + " bne %0, 2f \n" + " mov 1, $0 \n" + " stq_c $0, %1 \n" + " beq $0, 2f \n" + " mb \n" + " br 3f \n" + "2: mov 1, %0 \n" + "3: \n" + : "=&r"(_res), "+m"(*lock) + : + : "memory", "0"); + return (int)_res; +} + +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__(" mb \n"); \ + *((volatile slock_t*)(lock)) = 0; \ + } while (0) + +#endif /* __alpha || __alpha__ */ + +#if defined(__mips__) && !defined(__sgi) /* non-SGI MIPS */ +/* Note: on SGI we use the OS' mutex ABI, see below */ +/* Note: R10000 processors require a separate SYNC */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register volatile slock_t* _l = lock; + register int _res; + register int _tmp; + + __asm__ __volatile__(" .set push \n" + " .set mips2 \n" + " .set noreorder \n" + " .set nomacro \n" + " ll %0, %2 \n" + " or %1, %0, 1 \n" + " sc %1, %2 \n" + " xori %1, 1 \n" + " or %0, %0, %1 \n" + " sync \n" + " .set pop " + : "=&r"(_res), "=&r"(_tmp), "+R"(*_l) + : + : "memory"); + return _res; +} + +/* MIPS S_UNLOCK is almost standard but requires a "sync" instruction */ +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__( \ + " .set push \n" \ + " .set mips2 \n" \ + " .set noreorder \n" \ + " .set nomacro \n" \ + " sync \n" \ + " .set pop " +: +: "memory"); +*((volatile slock_t*)(lock)) = 0; +} +while (0) + +#endif /* __mips__ && !__sgi */ + +#if defined(__m32r__) && defined(HAVE_SYS_TAS_H) /* Renesas' M32R */ +#define HAS_TEST_AND_SET + +#include + + typedef int slock_t; + +#define TAS(lock) tas(lock) + +#endif /* __m32r__ */ + +#if defined(__sh__) /* Renesas' SuperH */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +static __inline__ int tas(volatile slock_t* lock) +{ + register int _res; + + /* + * This asm is coded as if %0 could be any register, but actually SuperH + * restricts the target of xor-immediate to be R0. That's handled by + * the "z" constraint on _res. + */ + __asm__ __volatile__(" tas.b @%2 \n" + " movt %0 \n" + " xor #1,%0 \n" + : "=z"(_res), "+m"(*lock) + : "r"(lock) + : "memory", "t"); + return _res; +} + +#endif /* __sh__ */ + +/* These live in s_lock.c, but only for gcc */ + +#if defined(__m68k__) && !defined(__linux__) /* non-Linux Motorola 68k */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +/* + * Note that this implementation is unsafe for any platform that can speculate + * a memory access (either load or store) after a following store. That + * happens not to be possible x86 and most legacy architectures (some are + * single-processor!), but many modern systems have weaker memory ordering. + * Those that do must define their own version S_UNLOCK() rather than relying + * on this one. + */ +#if !defined(S_UNLOCK) +#if defined(__INTEL_COMPILER) +#define S_UNLOCK(lock) \ + do { \ + __memory_barrier(); \ + *(lock) = 0; \ + } while (0) +#else +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("" : : : "memory"); \ + *(lock) = 0; \ + } while (0) +#endif +#endif + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +/* + * --------------------------------------------------------------------- + * Platforms that use non-gcc inline assembly: + * --------------------------------------------------------------------- + */ + +#if !defined(HAS_TEST_AND_SET) /* We didn't trigger above, let's try here */ + +#if defined(USE_UNIVEL_CC) /* Unixware compiler */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; + +#define TAS(lock) tas(lock) + +asm int tas(volatile slock_t* s_lock) +{ + /* UNIVEL wants %mem in column 1, so we don't pg_indent this file */ + % mem s_lock pushl % ebx movl s_lock, % ebx movl $255, % eax lock xchgb % al, (% ebx) popl % ebx +} + +#endif /* defined(USE_UNIVEL_CC) */ + +#if defined(__alpha) || defined(__alpha__) /* Tru64 Unix Alpha compiler */ +/* + * The Tru64 compiler doesn't support gcc-style inline asm, but it does + * have some builtin functions that accomplish much the same results. + * For simplicity, slock_t is defined as long (ie, quadword) on Alpha + * regardless of the compiler in use. LOCK_LONG and UNLOCK_LONG only + * operate on an int (ie, longword), but that's OK as long as we define + * S_INIT_LOCK to zero out the whole quadword. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include +#define S_INIT_LOCK(lock) (*(lock) = 0) +#define TAS(lock) (__LOCK_LONG_RETRY((lock), 1) == 0) +#define S_UNLOCK(lock) __UNLOCK_LONG(lock) + +#endif /* __alpha || __alpha__ */ + +#if defined(__hppa) || defined(__hppa__) /* HP PA-RISC, GCC and HP compilers */ +/* + * HP's PA-RISC + * + * See src/backend/port/hpux/tas.c.template for details about LDCWX. Because + * LDCWX requires a 16-byte-aligned address, we declare slock_t as a 16-byte + * struct. The active word in the struct is whichever has the aligned address; + * the other three words just sit at -1. + * + * When using gcc, we can inline the required assembly code. + */ +#define HAS_TEST_AND_SET + +typedef struct { + int sema[4]; +} slock_t; + +#define TAS_ACTIVE_WORD(lock) ((volatile int*)(((uintptr_t)(lock) + 15) & ~15)) + +#if defined(__GNUC__) + +static __inline__ int tas(volatile slock_t* lock) +{ + volatile int* lockword = TAS_ACTIVE_WORD(lock); + register int lockval; + + __asm__ __volatile__(" ldcwx 0(0,%2),%0 \n" : "=r"(lockval), "+m"(*lockword) : "r"(lockword) : "memory"); + return (lockval == 0); +} + +#define S_UNLOCK(lock) \ + do { \ + __asm__ __volatile__("" : : : "memory"); \ + *TAS_ACTIVE_WORD(lock) = -1; \ + } while (0) + +#endif /* __GNUC__ */ + +#define S_INIT_LOCK(lock) \ + do { \ + volatile slock_t* lock_ = (lock); \ + lock_->sema[0] = -1; \ + lock_->sema[1] = -1; \ + lock_->sema[2] = -1; \ + lock_->sema[3] = -1; \ + } while (0) + +#define S_LOCK_FREE(lock) (*TAS_ACTIVE_WORD(lock) != 0) + +#endif /* __hppa || __hppa__ */ + +#if defined(__hpux) && defined(__ia64) && !defined(__GNUC__) +/* + * HP-UX on Itanium, non-gcc compiler + * + * We assume that the compiler enforces strict ordering of loads/stores on + * volatile data (see comments on the gcc-version earlier in this file). + * Note that this assumption does *not* hold if you use the + * +Ovolatile=__unordered option on the HP-UX compiler, so don't do that. + * + * See also Implementing Spinlocks on the Intel Itanium Architecture and + * PA-RISC, by Tor Ekqvist and David Graves, for more information. As of + * this writing, version 1.0 of the manual is available at: + * http://h21007.www2.hp.com/portal/download/files/unprot/itanium/spinlocks.pdf + */ +#define HAS_TEST_AND_SET + +typedef unsigned int slock_t; + +#include +#define TAS(lock) _Asm_xchg(_SZ_W, lock, 1, _LDHINT_NONE) +/* On IA64, it's a win to use a non-locking test before the xchg proper */ +#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock)) +#define S_UNLOCK(lock) \ + do { \ + _Asm_sched_fence(); (*(lock)) = 0); \ + } while (0) + +#endif /* HPUX on IA64, non gcc */ + +#if defined(__sgi) /* SGI compiler */ +/* + * SGI IRIX 5 + * slock_t is defined as a unsigned long. We use the standard SGI + * mutex API. + * + * The following comment is left for historical reasons, but is probably + * not a good idea since the mutex ABI is supported. + * + * This stuff may be supplemented in the future with Masato Kataoka's MIPS-II + * assembly from his NECEWS SVR4 port, but we probably ought to retain this + * for the R3000 chips out there. + */ +#define HAS_TEST_AND_SET + +typedef unsigned long slock_t; + +#include "mutex.h" +#define TAS(lock) (test_and_set(lock, 1)) +#define S_UNLOCK(lock) (test_then_and(lock, 0)) +#define S_INIT_LOCK(lock) (test_then_and(lock, 0)) +#define S_LOCK_FREE(lock) (test_then_add(lock, 0) == 0) +#endif /* __sgi */ + +#if defined(sinix) /* Sinix */ +/* + * SINIX / Reliant UNIX + * slock_t is defined as a struct abilock_t, which has a single unsigned long + * member. (Basically same as SGI) + */ +#define HAS_TEST_AND_SET + +#include "abi_mutex.h" +typedef abilock_t slock_t; + +#define TAS(lock) (!acquire_lock(lock)) +#define S_UNLOCK(lock) release_lock(lock) +#define S_INIT_LOCK(lock) init_lock(lock) +#define S_LOCK_FREE(lock) (stat_lock(lock) == UNLOCKED) +#endif /* sinix */ + +#if defined(_AIX) /* AIX */ +/* + * AIX (POWER) + */ +#define HAS_TEST_AND_SET + +#include + +typedef int slock_t; + +#define TAS(lock) _check_lock((slock_t*)(lock), 0, 1) +#define S_UNLOCK(lock) _clear_lock((slock_t*)(lock), 0) +#endif /* _AIX */ + +/* These are in s_lock.c */ + +#if defined(sun3) /* Sun3 */ +#define HAS_TEST_AND_SET + +typedef unsigned char slock_t; +#endif + +#if defined(__SUNPRO_C) && (defined(__i386) || defined(__x86_64__) || defined(__sparc__) || defined(__sparc)) +#define HAS_TEST_AND_SET + +#if defined(__i386) || defined(__x86_64__) || defined(__sparcv9) || defined(__sparcv8plus) +typedef unsigned int slock_t; +#else +typedef unsigned char slock_t; +#endif + +extern slock_t pg_atomic_cas(volatile slock_t* lock, slock_t with, slock_t cmp); + +#define TAS(a) (pg_atomic_cas((a), 1, 0) != 0) +#endif + +#ifdef WIN32_ONLY_COMPILER +typedef LONG slock_t; + +#define HAS_TEST_AND_SET +#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0)) + +#define SPIN_DELAY() spin_delay() + +/* If using Visual C++ on Win64, inline assembly is unavailable. + * Use a _mm_pause instrinsic instead of rep nop. + */ +#if defined(_WIN64) +static __forceinline void spin_delay(void) +{ + _mm_pause(); +} +#else +static __forceinline void spin_delay(void) +{ + /* See comment for gcc code. Same code, MASM syntax */ + __asm rep nop; +} +#endif + +#include +#pragma intrinsic(_ReadWriteBarrier) + +#define S_UNLOCK(lock) \ + do { \ + _ReadWriteBarrier(); \ + (*(lock)) = 0; \ + } while (0) + +#endif + +#endif /* !defined(HAS_TEST_AND_SET) */ + +/* Blow up if we didn't have any way to do spinlocks */ +#ifndef HAS_TEST_AND_SET +#error PostgreSQL does not have native spinlock support on this platform. To continue the compilation, rerun configure using --disable-spinlocks. However, performance will be poor. Please report this to pgsql-bugs@postgresql.org. +#endif + +#else /* !HAVE_SPINLOCKS */ + +/* + * Fake spinlock implementation using semaphores --- slow and prone + * to fall foul of kernel limits on number of semaphores, so don't use this + * unless you must! The subroutines appear in spin.c. + */ +typedef PGSemaphoreData slock_t; + +extern bool s_lock_free_sema(volatile slock_t* lock); +extern void s_unlock_sema(volatile slock_t* lock); +extern void s_init_lock_sema(volatile slock_t* lock); +extern int tas_sema(volatile slock_t* lock); + +#define S_LOCK_FREE(lock) s_lock_free_sema(lock) +#define S_UNLOCK(lock) s_unlock_sema(lock) +#define S_INIT_LOCK(lock) s_init_lock_sema(lock) +#define TAS(lock) tas_sema(lock) + +#endif /* HAVE_SPINLOCKS */ + +/* + * Default Definitions - override these above as needed. + */ + +#if !defined(S_LOCK) +#define S_LOCK(lock) \ + do { \ + if (TAS(lock)) \ + s_lock((lock), __FILE__, __LINE__); \ + } while (0) +#endif /* S_LOCK */ + +#if !defined(S_LOCK_FREE) +#define S_LOCK_FREE(lock) (*(lock) == 0) +#endif /* S_LOCK_FREE */ + +#if !defined(S_UNLOCK) +/* + * Our default implementation of S_UNLOCK is essentially *(lock) = 0. This + * is unsafe if the platform can speculate a memory access (either load or + * store) after a following store; platforms where this is possible must + * define their own S_UNLOCK. But CPU reordering is not the only concern: + * if we simply defined S_UNLOCK() as an inline macro, the compiler might + * reorder instructions from inside the critical section to occur after the + * lock release. Since the compiler probably can't know what the external + * function s_unlock is doing, putting the same logic there should be adequate. + * A sufficiently-smart globally optimizing compiler could break that + * assumption, though, and the cost of a function call for every spinlock + * release may hurt performance significantly, so we use this implementation + * only for platforms where we don't know of a suitable intrinsic. For the + * most part, those are relatively obscure platform/compiler combinations to + * which the PostgreSQL project does not have access. + */ +#define USE_DEFAULT_S_UNLOCK +extern void s_unlock(volatile slock_t* lock); +#define S_UNLOCK(lock) s_unlock(lock) +#endif /* S_UNLOCK */ + +#if !defined(S_INIT_LOCK) +#define S_INIT_LOCK(lock) S_UNLOCK(lock) +#endif /* S_INIT_LOCK */ + +#if !defined(SPIN_DELAY) +#define SPIN_DELAY() ((void)0) +#endif /* SPIN_DELAY */ + +#if !defined(TAS) +extern int tas(volatile slock_t* lock); /* in port/.../tas.s, or + * s_lock.c */ + +#define TAS(lock) tas(lock) +#endif /* TAS */ + +#if !defined(TAS_SPIN) +#define TAS_SPIN(lock) TAS(lock) +#endif /* TAS_SPIN */ + +#else /* ENABLE_THREAD_CHECK */ +#include +typedef pthread_mutex_t slock_t; + +#define S_INIT_LOCK(lock) pthread_mutex_init((pthread_mutex_t*)lock, NULL) +#define S_LOCK(lock) pthread_mutex_lock((pthread_mutex_t*)lock) +#define S_UNLOCK(lock) pthread_mutex_unlock((pthread_mutex_t*)lock) +#define S_LOCK_FREE(lock) pthread_mutex_destroy((pthread_mutex_t*)lock) +#define TAS(lock) (!S_LOCK(lock)) +#endif +/* + * Platform-independent out-of-line support routines + */ +extern int s_lock(volatile slock_t* lock, const char* file, int line); + +/* Support for dynamic adjustment of spins_per_delay */ +#define DEFAULT_SPINS_PER_DELAY 100 + +extern void set_spins_per_delay(int shared_spins_per_delay); +extern int update_spins_per_delay(int shared_spins_per_delay); + +/* + * Support for spin delay which is useful in various places where + * spinlock-like procedures take place. + */ +typedef struct { + int spins; + int delays; + int cur_delay; + void* ptr; + const char* file; + int line; +} SpinDelayStatus; + +#define init_spin_delay(ptr) \ + { \ + 0, 0, 0, (ptr), __FILE__, __LINE__ \ + } +void perform_spin_delay(SpinDelayStatus* status); +void finish_spin_delay(SpinDelayStatus* status); + +#endif /* S_LOCK_H */ diff -uprN postgresql-hll-2.14_old/include/storage/smgr.h postgresql-hll-2.14/include/storage/smgr.h --- postgresql-hll-2.14_old/include/storage/smgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/smgr.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * smgr.h + * storage manager switch public interface declarations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/smgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SMGR_H +#define SMGR_H + +#include "fmgr.h" +#include "lib/ilist.h" +#include "storage/block.h" +#include "storage/relfilenode.h" + +#include "utils/rel.h" +#include "utils/rel_gs.h" +#include "vecexecutor/vectorbatch.h" +#include "nodes/bitmapset.h" + + +/* + * smgr.c maintains a table of SMgrRelation objects, which are essentially + * cached file handles. An SMgrRelation is created (if not already present) + * by smgropen(), and destroyed by smgrclose(). Note that neither of these + * operations imply I/O, they just create or destroy a hashtable entry. + * (But smgrclose() may release associated resources, such as OS-level file + * descriptors.) + * + * An SMgrRelation may have an "owner", which is just a pointer to it from + * somewhere else; smgr.c will clear this pointer if the SMgrRelation is + * closed. We use this to avoid dangling pointers from relcache to smgr + * without having to make the smgr explicitly aware of relcache. There + * can't be more than one "owner" pointer per SMgrRelation, but that's + * all we need. + * + * SMgrRelations that do not have an "owner" are considered to be transient, + * and are deleted at end of transaction. + */ +typedef struct SMgrRelationData { + /* rnode is the hashtable lookup key, so it must be first! */ + RelFileNodeBackend smgr_rnode; /* relation physical identifier */ + + /* pointer to owning pointer, or NULL if none */ + struct SMgrRelationData** smgr_owner; + + /* + * These next three fields are not actually used or manipulated by smgr, + * except that they are reset to InvalidBlockNumber upon a cache flush + * event (in particular, upon truncation of the relation). Higher levels + * store cached state here so that it will be reset when truncation + * happens. In all three cases, InvalidBlockNumber means "unknown". + */ + BlockNumber smgr_targblock; /* current insertion target block */ + BlockNumber smgr_fsm_nblocks; /* last known size of fsm fork */ + BlockNumber smgr_vm_nblocks; /* last known size of vm fork */ + + int smgr_bcmarry_size; + BlockNumber* smgr_bcm_nblocks; /* last known size of bcm fork */ + + /* additional public fields may someday exist here */ + + /* + * Fields below here are intended to be private to smgr.c and its + * submodules. Do not touch them from elsewhere. + */ + int smgr_which; /* storage manager selector */ + + + /* for md.c; NULL for forks that are not open */ + int md_fdarray_size; + struct _MdfdVec** md_fd; + + /* hash table storing specific bucket node's smgr pointer */ + HTAB* bucketnodes_smgrhash; + + /* if unowned, list link in list of all unowned SMgrRelations */ + dlist_node node; +} SMgrRelationData; + + +typedef SMgrRelationData* SMgrRelation; + +#define SmgrIsTemp(smgr) RelFileNodeBackendIsTemp((smgr)->smgr_rnode) + +extern void smgrinit(void); +extern SMgrRelation smgropen(const RelFileNode& rnode, BackendId backend, int col = 0, const oidvector* bucketlist = NULL); +extern bool smgrexists(SMgrRelation reln, ForkNumber forknum); +extern void smgrsetowner(SMgrRelation* owner, SMgrRelation reln); +extern void smgrclearowner(SMgrRelation* owner, SMgrRelation reln); +extern void smgrclose(SMgrRelation reln); +extern void smgrcloseall(void); +extern void smgrclosenode(const RelFileNodeBackend& rnode); +extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo ); +extern void smgrdounlink(SMgrRelation reln, bool isRedo); +extern void smgrdounlinkfork(SMgrRelation reln, ForkNumber forknum, bool isRedo); +extern void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum); +extern bool smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char* buffer); +extern void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks); +extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum); +extern void smgrtruncatefunc(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum); +extern void smgrpreckpt(void); +extern void smgrsync(void); +extern void smgrpostckpt(void); + +extern void AtEOXact_SMgr(void); + +/* internals: move me elsewhere -- ay 7/94 */ + +/* in md.c */ +extern void mdinit(void); +extern void mdclose(SMgrRelation reln, ForkNumber forknum); +extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); +extern void smgrcreatebuckets(SMgrRelation reln, ForkNumber forknum, bool isRedo); + +extern bool mdexists(SMgrRelation reln, ForkNumber forknum); +extern void mdunlink(const RelFileNodeBackend& rnode, ForkNumber forknum, bool isRedo); +extern void mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum); +extern bool mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, char* buffer); +extern void mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const char* buffer, bool skipFsync); +extern void mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks); +extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum); +extern void mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks); +extern void mdimmedsync(SMgrRelation reln, ForkNumber forknum); +extern void mdpreckpt(void); +extern void mdsync(void); +extern void mdpostckpt(void); +extern char* mdsegpath(const RelFileNode& rnode, ForkNumber forknum, BlockNumber blkno); + +extern void SetForwardFsyncRequests(void); +extern void RememberFsyncRequest(const RelFileNode& rnode, ForkNumber forknum, BlockNumber segno); +extern void ForgetRelationFsyncRequests(const RelFileNode& rnode, ForkNumber forknum); +extern void ForgetDatabaseFsyncRequests(Oid dbid); +extern void smgrsync_for_dw(void); +extern void smgrsync_with_absorption(void); + +/* smgrtype.c */ +extern Datum smgrout(PG_FUNCTION_ARGS); +extern Datum smgrin(PG_FUNCTION_ARGS); +extern Datum smgreq(PG_FUNCTION_ARGS); +extern Datum smgrne(PG_FUNCTION_ARGS); + +extern void partition_create_new_storage(Relation rel, Partition part, const RelFileNodeBackend& filenode); +extern ScalarToDatum GetTransferFuncByTypeOid(Oid attTypeOid); +#endif /* SMGR_H */ diff -uprN postgresql-hll-2.14_old/include/storage/spin.h postgresql-hll-2.14/include/storage/spin.h --- postgresql-hll-2.14_old/include/storage/spin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/spin.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * spin.h + * Hardware-independent implementation of spinlocks. + * + * + * The hardware-independent interface to spinlocks is defined by the + * typedef "slock_t" and these macros: + * + * void SpinLockInit(volatile slock_t *lock) + * Initialize a spinlock (to the unlocked state). + * + * void SpinLockAcquire(volatile slock_t *lock) + * Acquire a spinlock, waiting if necessary. + * Time out and abort() if unable to acquire the lock in a + * "reasonable" amount of time --- typically ~ 1 minute. + * + * void SpinLockRelease(volatile slock_t *lock) + * Unlock a previously acquired lock. + * + * bool SpinLockFree(slock_t *lock) + * Tests if the lock is free. Returns TRUE if free, FALSE if locked. + * This does *not* change the state of the lock. + * + * Callers must beware that the macro argument may be evaluated multiple + * times! + * + * CAUTION: Care must be taken to ensure that loads and stores of + * shared memory values are not rearranged around spinlock acquire + * and release. This is done using the "volatile" qualifier: the C + * standard states that loads and stores of volatile objects cannot + * be rearranged *with respect to other volatile objects*. The + * spinlock is always written through a volatile pointer by the + * spinlock macros, but this is not sufficient by itself: code that + * protects shared data with a spinlock MUST reference that shared + * data through a volatile pointer. + * + * Keep in mind the coding rule that spinlocks must not be held for more + * than a few instructions. In particular, we assume it is not possible + * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so + * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros. + * + * These macros are implemented in terms of hardware-dependent macros + * supplied by s_lock.h. There is not currently any extra functionality + * added by this header, but there has been in the past and may someday + * be again. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/spin.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPIN_H +#define SPIN_H + +#include "storage/s_lock.h" + +#define SpinLockInit(lock) S_INIT_LOCK(lock) + +#define SpinLockAcquire(lock) S_LOCK(lock) + +#define SpinLockRelease(lock) S_UNLOCK(lock) + +#define SpinLockFree(lock) S_LOCK_FREE(lock) + +extern int SpinlockSemas(void); + +#endif /* SPIN_H */ diff -uprN postgresql-hll-2.14_old/include/storage/standby.h postgresql-hll-2.14/include/storage/standby.h --- postgresql-hll-2.14_old/include/storage/standby.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/standby.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,133 @@ +/* ------------------------------------------------------------------------- + * + * standby.h + * Definitions for hot standby mode. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/storage/standby.h + * + * ------------------------------------------------------------------------- + */ +#ifndef STANDBY_H +#define STANDBY_H + +#include "access/xlog.h" +#include "access/xlogreader.h" +#include "lib/stringinfo.h" +#include "storage/lock.h" +#include "storage/procsignal.h" +#include "storage/relfilenode.h" + +extern void InitRecoveryTransactionEnvironment(void); +extern void ShutdownRecoveryTransactionEnvironment(void); + +extern void ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, const RelFileNode& node); +extern void ResolveRecoveryConflictWithTablespace(Oid tsid); +extern void ResolveRecoveryConflictWithDatabase(Oid dbid); + +extern void ResolveRecoveryConflictWithBufferPin(void); +extern void SendRecoveryConflictWithBufferPin(ProcSignalReason reason); +extern void CheckRecoveryConflictDeadlock(void); + +/* + * Standby Rmgr (RM_STANDBY_ID) + * + * Standby recovery manager exists to perform actions that are required + * to make hot standby work. That includes logging AccessExclusiveLocks taken + * by transactions and running-xacts snapshots. + */ +extern void StandbyAcquireAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid); +extern void StandbyReleaseLockTree(TransactionId xid, int nsubxids, TransactionId* subxids); +extern void StandbyReleaseAllLocks(void); +extern void StandbyReleaseOldLocks(TransactionId oldestRunningXid); +extern bool HasStandbyLocks(); + +extern bool standbyWillTouchStandbyLocks(XLogReaderState* record); + +/* + * XLOG message types + */ +#define XLOG_STANDBY_LOCK 0x00 +#define XLOG_RUNNING_XACTS 0x10 +#define XLOG_STANDBY_UNLOCK 0x20 +#define XLOG_STANDBY_CSN 0x30 +#ifndef ENABLE_MULTIPLE_NODES +#define XLOG_STANDBY_CSN_COMMITTING 0x40 +#define XLOG_STANDBY_CSN_ABORTED 0x50 +#endif + +typedef struct xl_standby_locks { + int nlocks; /* number of entries in locks array */ + xl_standby_lock locks[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_standby_locks; + +#define MinSizeOfXactStandbyLocks offsetof(xl_standby_locks, locks) + +/* + * When we write running xact data to WAL, we use this structure. + */ +typedef struct xl_running_xacts { + int xcnt; /* # of xact ids in xids[] */ + int subxcnt; /* # of subxact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + TransactionId oldestRunningXid; /* *not* oldestXmin */ + TransactionId latestCompletedXid; /* so we can set xmax */ + + TransactionId xids[FLEXIBLE_ARRAY_MEMBER]; +} xl_running_xacts; + + +#define MinSizeOfXactRunningXacts offsetof(xl_running_xacts, xids) +/* Recovery handlers for the Standby Rmgr (RM_STANDBY_ID) */ +extern void standby_redo(XLogReaderState* record); +extern void standby_desc(StringInfo buf, XLogReaderState* record); +#ifndef ENABLE_MULTIPLE_NODES +extern void StandbyXlogStartup(void); +extern void StandbyXlogCleanup(void); +extern bool StandbySafeRestartpoint(void); +extern bool RemoveCommittedCsnInfo(TransactionId xid); +#endif +typedef struct xl_running_xacts_old { + int xcnt; /* # of xact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + ShortTransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + ShortTransactionId oldestRunningXid; /* *not* oldestXmin */ + ShortTransactionId latestCompletedXid; /* so we can set xmax */ + ShortTransactionId xids[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_running_xacts_old; +/* + * Declarations for GetRunningTransactionData(). Similar to Snapshots, but + * not quite. This has nothing at all to do with visibility on this server, + * so this is completely separate from snapmgr.c and snapmgr.h. + * This data is important for creating the initial snapshot state on a + * standby server. We need lots more information than a normal snapshot, + * hence we use a specific data structure for our needs. This data + * is written to WAL as a separate record immediately after each + * checkpoint. That means that wherever we start a standby from we will + * almost immediately see the data we need to begin executing queries. + */ + +typedef struct RunningTransactionsData { + int xcnt; /* # of xact ids in xids[] */ + int subxcnt; /* # of subxact ids in xids[] */ + bool subxid_overflow; /* snapshot overflowed, subxids missing */ + TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ + TransactionId oldestRunningXid; /* *not* oldestXmin */ + TransactionId globalXmin; /* running xacts's snapshot xmin */ + TransactionId latestCompletedXid; /* copy of ShmemVariableCache-> latestCompletedXid*/ + TransactionId* xids; /* array of (sub)xids still running */ + +} RunningTransactionsData; + +typedef RunningTransactionsData* RunningTransactions; + +extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid); +extern void LogAccessExclusiveLockPrepare(void); +extern void LogReleaseAccessExclusiveLock(TransactionId xid, Oid dbOid, Oid relOid); + +extern XLogRecPtr LogStandbySnapshot(void); +#endif /* STANDBY_H */ diff -uprN postgresql-hll-2.14_old/include/storage/time_series_compress.h postgresql-hll-2.14/include/storage/time_series_compress.h --- postgresql-hll-2.14_old/include/storage/time_series_compress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/time_series_compress.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,132 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * time_series_compress.h + * Data structure for delta-delta compression and XOR compression. + * + * + * IDENTIFICATION + * src/include/storage/time_series_compress.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SERIES_COMPRESS_H +#define SERIES_COMPRESS_H + +#include "c.h" +#include "storage/cstore_compress.h" + +const int DELTA2_RANGE = 8; +const int MAX_COMPRESSLEVEL = 3; + +const unsigned short DELTA2_KEY_MAX = 0x8; + +const int CU_COMPRESS_MASK1 = 0x000F; + +#define ATT_IS_DELTA2_SUPPORT(atttypid) \ + (atttypid == DATEOID || atttypid == TIMESTAMPOID || atttypid == INT4RANGEOID || atttypid == INT2OID || \ + atttypid == INT4OID || atttypid == INT8OID) + +#define ATT_IS_TIMESTAMP(atttypid) (atttypid == TIMESTAMPOID || atttypid == TIMESTAMPTZOID) + +#define ATT_IS_FLOAT(atttypid) (atttypid == FLOAT4OID || atttypid == FLOAT8OID) + +typedef struct Delta2KeyMap { + long unsigned int min; + long unsigned int max; + unsigned short key_suffix; + unsigned short byte_len; +} Delta2KeyMap; + +class Delta2Codec : public BaseObject { +public: + Delta2Codec(int64 extra, bool beCompress); + virtual ~Delta2Codec() + {} + + int64 compress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + + int64 decompress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size) const; + +private: + void write_value(int64 value, unsigned int buf_len, char* outbuf, unsigned int* pos); + int64 read_value(char* inbuf, unsigned int* pos, unsigned int buf_len) const; + short value_size; + short key_idx; + static const short DELTA2_KEY_MASK = 0xFF; + static const short DELTA2_KEY_SIGN_MASK = 0x7; + static const short DELTA2_BYTE_LEN_MASK = 0x8; + static const unsigned int DELTA2_KEY_LEN = 1; /* delta key len--1 byte */ +}; + +class SequenceCodec : public BaseObject { +public: + SequenceCodec(short valSize, uint32 dataType); + virtual ~SequenceCodec() + {} + + int lz4_compress( + int8 compression, int8 compress_level, Size bound_size, BufferHelper* tmpOutBuf, _out_ CompressionArg2& out); + int zlib_compress( + int8 compression, int8 compress_level, Size bound_size, BufferHelper* tmpOutBuf, _out_ CompressionArg2& out); + int compress(_in_ const CompressionArg1& in, _out_ CompressionArg2& out); + int decompress(_in_ const CompressionArg2& in, _out_ CompressionArg1& out); + +private: + short value_size; + uint32 data_type; +}; + +class XORCodec : public BaseObject { +public: + XORCodec(); + virtual ~XORCodec() + {} + + int64 compress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + + int64 decompress(_in_ char* inbuf, _out_ char* outbuf, _in_ unsigned int insize, _in_ unsigned int outsize, + _in_ unsigned short data_size); + +private: + // write compress value to write buffer + void appendValue(int64 value, char* outbuf, unsigned int& out_pos); + void addValueToBitString( + uint64_t value, uint64_t bitsInValue, uint32_t& numBits, char* outbuf, unsigned int& out_pos); + void flushBitString(const uint32_t& numBits, char* outbuf, unsigned int& out_pos); + void flushLastBitString(char* outbuf, unsigned int& out_pos); + + // read compress value to read buffer + int64 readNextValue(uint64_t& bitPos, uint64_t& previousValue, uint64_t& previousLeadingZeros, + uint64_t& previousTrailingZeros, char* inbuf, unsigned int& in_pos); + uint64_t readValueFromBitString(uint64_t& bitPos, uint32_t bitsToRead, char* inbuf, unsigned int& in_pos); + + static constexpr uint32_t kLeadingZerosLengthBits = 5; + static constexpr uint32_t kBlockSizeLengthBits = 6; + static constexpr uint32_t kMaxLeadingZerosLength = (1 << kLeadingZerosLengthBits) - 1; + static constexpr uint32_t kBlockSizeAdjustment = 1; + + uint64_t previousValue_; + uint32_t numBits_; + uint8_t previousValueLeadingZeros_; + uint8_t previousValueTrailingZeros_; + char bitsStore_; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/storage/vfd.h postgresql-hll-2.14/include/storage/vfd.h --- postgresql-hll-2.14_old/include/storage/vfd.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/storage/vfd.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,39 @@ +/* --------------------------------------------------------------------------------------- + * + * vfd.h + * Virtual file descriptor definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/storage/vfd.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VFD_H +#define VFD_H + +#include +#include "utils/resowner.h" +#include "storage/relfilenode.h" + +typedef struct vfd { + int fd; /* current FD, or VFD_CLOSED if none */ + unsigned short fdstate; /* bitflags for VFD's state */ + ResourceOwner resowner; /* owner, for automatic cleanup */ + File nextFree; /* link to next free VFD, if in freelist */ + File lruMoreRecently; /* doubly linked recency-of-use list */ + File lruLessRecently; + off_t seekPos; /* current logical file position */ + off_t fileSize; /* current size of file (0 if not temporary) */ + char* fileName; /* name of file, or NULL for unused VFD */ + bool infdCache; /* true if in fd cache */ + /* NB: fileName is malloc'd, and must be free'd when closing the VFD */ + int fileFlags; /* open(2) flags for (re)opening the file */ + int fileMode; /* mode to pass to open(2) */ + RelFileNodeForkNum fileNode; /* current logical file node */ +} Vfd; + +#endif /* VFD_H */ diff -uprN postgresql-hll-2.14_old/include/streaming/dictcache.h postgresql-hll-2.14/include/streaming/dictcache.h --- postgresql-hll-2.14_old/include/streaming/dictcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/streaming/dictcache.h 2020-12-12 17:06:43.382349780 +0800 @@ -0,0 +1,80 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * connection.h + * Head file for streaming engine connection. + * + * + * IDENTIFICATION + * src/distribute/kernel/extension/streaming/include/connection.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ +#define CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ + +#include "streaming/init.h" +#include "knl/knl_thread.h" +#include "knl/knl_variable.h" + +#define OIDTYPE 0 +#define TEXTTYPE 1 + +#define Natts_dict 2 + +#define Anum_dict_id 1 +#define Anum_dict_value 2 + +#define DICT_SQL_MAX_LEN 1024 +#define DICT_HASH_NELEM 32 + +void init_dict(void); +HeapTuple dict_cache_lookup(int id, Datum key, int type); +#define AEXPR_TO_SUBLINK_SQL "select distinct id from %s where value='%s'" +#define RESTARGET_TO_SUBLINK_SQL "select distinct value from %s where %s=id" + +/* + * Definition of dictionary mapping hash entry + */ +typedef struct DictEntry +{ + uint32 id; /* hash key of DictEntry */ + HeapTuple tuple; /* dict mapping tuple */ + bool valid; /* valid flag*/ +} DictEntry; + +typedef struct DictAnalyzeContext +{ + List *a_exprs; + List *rels; + List *cqtabs; + List *cols; +} DictAnalyzeContext; + +DictAnalyzeContext *make_dict_analyze_context(); + +bool collect_aexprs(Node *node, DictAnalyzeContext *context); +void init_dict(void); +//Oid dict_table_insert(Relation rel, HeapTuple tup); +Oid dict_table_insert(int id, HeapTuple tup, Datum key); +HeapTuple dict_cache_lookup(int id, Datum key, int type); +Datum dict_get_attr(int id, HeapTuple tup, AttrNumber attr, bool *isnull); +int get_id_by_dictrelid(Oid dictrelid); +bool is_contquery_with_dict(Node* node); +bool collect_rels(Node *node, DictAnalyzeContext *context); +bool collect_cols(Node *node, DictAnalyzeContext *context); +void transform_contquery_selectstmt_with_dict(SelectStmt * selectstmt); +#endif /* CONTRIB_STREAMING_INCLUDE_DICTCACHE_H_ */ diff -uprN postgresql-hll-2.14_old/include/streaming/init.h postgresql-hll-2.14/include/streaming/init.h --- postgresql-hll-2.14_old/include/streaming/init.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/streaming/init.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,140 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * init.h + * Head file for streaming engine init. + * + * + * IDENTIFICATION + * src/include/streaming/init.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_STREAMING_INIT_H_ +#define SRC_INCLUDE_STREAMING_INIT_H_ + +#include "gs_thread.h" +#include "streaming/launcher.h" +#include "access/tupdesc.h" + +typedef int StreamingThreadSeqNum; + +typedef struct StreamingBatchStats { + union { + struct { // coordinator stats + volatile uint64 worker_in_rows; /* worker input rows */ + volatile uint64 worker_in_bytes; /* worker input bytes */ + volatile uint64 worker_out_rows; /* worker output rows */ + volatile uint64 worker_out_bytes; /* worker output bytes */ + volatile uint64 worker_pending_times; /* worker pending times */ + volatile uint64 worker_error_times; /* worker error times */ + }; + struct { // datanode stats + volatile uint64 router_in_rows; /* router input rows */ + volatile uint64 router_in_bytes; /* router input bytes */ + volatile uint64 router_out_rows; /* router output rows */ + volatile uint64 router_out_bytes; /* router output bytes */ + volatile uint64 router_error_times; /* router error times */ + volatile uint64 collector_in_rows; /* collector input rows */ + volatile uint64 collector_in_bytes; /* collector input bytes */ + volatile uint64 collector_out_rows; /* collector output rows */ + volatile uint64 collector_out_bytes; /* collector output bytes */ + volatile uint64 collector_pending_times; /* collector pending times */ + volatile uint64 collector_error_times; /* collector error times */ + }; + }; +} StreamingBatchStats; + +typedef struct StreamingSharedMetaData { + volatile uint32 client_push_conn_atomic; /* round robin client push connection atomic */ + void *conn_hash_tbl; /* connection hash table for streaming threads */ + StreamingBatchStats *batch_stats; /* streaming engine microbatch statistics */ +}StreamingSharedMetaData; + +typedef struct StreamingThreadMetaData { + ThreadId tid; + knl_thread_role subrole; + StreamingThreadSeqNum tseq; +}StreamingThreadMetaData; + +typedef struct DictDesc +{ + char *nspname; + char *relname; + char *indname; + Oid relid; + Oid indrelid; + TupleDesc desc; + int nkeys; + int key; +} DictDesc; + +#define DICT_CACHE_SIZE 1024 + +typedef struct knl_t_streaming_context { + volatile bool is_streaming_engine; + volatile bool loaded; /* streaming engine loaded flag */ + void *save_utility_hook; + void *save_post_parse_analyze_hook; + StreamingBackendServerLoopFunc streaming_backend_serverloop_hook; + StreamingBackendShutdownFunc streaming_backend_shutdown_hook; + void *streaming_planner_hook; + volatile bool got_SIGHUP; + volatile bool got_SIGTERM; + int client_push_conn_id; + StreamingThreadMetaData *thread_meta; /* streaming current thread meta */ + unsigned int streaming_context_flags; + TransactionId cont_query_cache_xid; + MemoryContext cont_query_cache_cxt; + void *cont_query_cache; + int current_cont_query_id; + Oid streaming_exec_lock_oid; + MemoryContext ContQueryTransactionContext; + MemoryContext ContQueryBatchContext; + + HTAB *dict_htable[DICT_CACHE_SIZE]; + MemoryContext dict_context; + bool dict_inited; + DictDesc dictdesc[DICT_CACHE_SIZE]; +} knl_t_streaming_context; + +typedef struct knl_g_streaming_context { + MemoryContext meta_cxt; /* streaming engine meta context */ + MemoryContext conn_cxt; /* streaming engine conn context */ + StreamingSharedMetaData *shared_meta; /* streaming shared meta */ + StreamingThreadMetaData *thread_metas; /* streaming thread metas */ + char *krb_server_keyfile; /* kerberos server keyfile */ + volatile bool got_SIGHUP; /* SIGHUP comm with nanomsg auth */ + bool enable; /* streaming engine enable flag */ + int router_port; /* the port router thread listens on */ + int routers; /* number of router threads */ + int workers; /* number of worker threads */ + int combiners; /* number of combiner threads */ + int queues; /* number of queue threads */ + int reapers; /* number of reaper threads */ + int batch_size; /* max number of tuples for streaming microbatch */ + int batch_mem; /* max size (KB) for streaming microbatch */ + int batch_wait; /* receive timeout (ms) for streaming microbatch */ + int flush_mem; /* max size (KB) for streaming disk flush */ + int flush_wait; /* receive timeout (ms) for streaming disk flush */ + bool exec_lock_flag; /* get exec lock flag */ + int gather_window_interval; /* interval (min) of gather window */ +}knl_g_streaming_context; + +bool is_streaming_engine_available(); +void validate_streaming_engine_status(Node *stmt); + +#endif /* SRC_INCLUDE_STREAMING_INIT_H_ */ diff -uprN postgresql-hll-2.14_old/include/streaming/launcher.h postgresql-hll-2.14/include/streaming/launcher.h --- postgresql-hll-2.14_old/include/streaming/launcher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/streaming/launcher.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,48 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hashfuncs.h + * Head file for streaming engine launcher. + * + * + * IDENTIFICATION + * src/include/streaming/launcher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_STREAMING_LAUNCHER_H_ +#define SRC_INCLUDE_STREAMING_LAUNCHER_H_ + +#include "gs_thread.h" + +typedef enum { + STREAMING_BACKEND_INIT = 1, + STREAMING_BACKEND_REAP, + STREAMING_BACKEND_SIGTERM, + STREAMING_BACKEND_SIGHUP, + STREAMING_BACKEND_SHUTDOWN +} StreamingBackendManagerType; + +typedef void (*StreamingBackendServerLoopFunc)(); +typedef void (*StreamingBackendShutdownFunc)(); + +bool is_streaming_engine(); +int streaming_get_thread_count(); +void streaming_backend_main(knl_thread_arg* arg); +extern bool streaming_backend_manager(StreamingBackendManagerType mtype, const void *info = NULL); +bool is_streaming_backend_terminating(); + +#endif /* SRC_INCLUDE_STREAMING_LAUNCHER_H_ */ diff -uprN postgresql-hll-2.14_old/include/streaming/planner.h postgresql-hll-2.14/include/streaming/planner.h --- postgresql-hll-2.14_old/include/streaming/planner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/streaming/planner.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * planner.h + * Head file for the entance of stream to modify the plan tree. + * + * + * IDENTIFICATION + * src/include/streaming/planner.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMING_PLANNER_H +#define STREAMING_PLANNER_H + +#include + +bool is_insert_stream_query(Query *query); +bool is_streaming_hash_group_func(const char* funcname, Oid funcnamespace); +bool is_streaming_invisible_obj(Oid oid); + +#endif diff -uprN postgresql-hll-2.14_old/include/streaming/streaming_catalog.h postgresql-hll-2.14/include/streaming/streaming_catalog.h --- postgresql-hll-2.14_old/include/streaming/streaming_catalog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/streaming/streaming_catalog.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,112 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cont_query.h + * Head file for streaming engine cont_query. + * + * + * IDENTIFICATION + * src/distribute/kernel/extension/streaming/include/cont_query.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STREAMING_INCLUDE_STREAMING_CATALOG_H_ +#define STREAMING_INCLUDE_STREAMING_CATALOG_H_ + +#include "postgres.h" +#include "nodes/primnodes.h" +#include "nodes/parsenodes.h" + +const char TTL_OPTION[] = "ttl_interval"; +const char WINDOW_OPTION[] = "sw_interval"; +const char COLUMN_OPTION[] = "time_column"; +const char ORIENT_OPTION[] = "orientation"; +const char COMPRESS_OPTION[] = "compression"; +const char GATHER_OPTION[] = "gather_interval"; +const char PERIOD_OPTION[] = "partition_interval"; +const char DEACTIVE_TIME_OPTION[] = "deactive_time"; +const char STRING_OPTIMIZE_OPTION[] = "string_optimize"; + +const char ORIENT_COLUMN = 'c'; /* streaming_cont_query: type = 'c' */ +const char ORIENT_ROW = 'r'; /* streaming_cont_query: type = 'r' */ +const char ORIENT_COLUMN_PARTITION = 'p'; /* streaming_cont_query: type = 'p' */ +const int16 TUMBLING_WINDOW = 0; /* streaming_cont_query: step_factor = 0 */ +const int16 SLIDING_WINDOW = 1; /* streaming_cont_query: step_factor = 1 */ +const char STRING_OPTIMIZE_ON[] = "on"; +const char STRING_OPTIMIZE_OFF[] = "off"; + +const int MAX_VERSIONS = 10; +const char INIT_VERSION = '0'; +const int MIN_TTL = 5; +const int MAX_CQS = 1024; +const int STREAMING_EXEC_CONTINUOUS = 0x100000; +const int DEFAULT_PARTITION_NUM = 10; /* default partition numbers when partition table is created */ +const int DEFAULT_NAME_LEN = 64; /* default and auto partition name length */ +const int PERIOD_OFF = -1; /* represention for no partition_interval parameter */ +const int PERIOD_MULT = 5; /* detection interval for auto-partition */ +const int GATHER_OFF = -1; /* represention for no gather_interval parameter */ +const int PARTITION_INTERVAL_MAX = 1; /* partition_interval max value (day) */ +const int PARTITION_INTERVAL_MIN = 30; /* partition_interval min value (minute) */ +const int MSECS_PER_SECS = 1000; /* Milliseconds per second */ + + +typedef struct ContQuery { + Oid id; /*CV ID*/ + RangeVar *name; /*CV name*/ + Oid oid; /*tuple oid*/ + bool active; /*is this CV active*/ + + Oid relid; /*overlay view oid*/ + Oid defrelid; /*definiton view oid*/ + char *sql; /*cont query's plain sql*/ + Query *cvdef; /*def view's query tree*/ + Oid matrelid; /*matrel oid*/ + Oid streamrelid; /*stream oid*/ + Oid dictrelid; /*stream oid*/ + + RangeVar *matrel; /*matrel name*/ + Oid lookupidxid; /*group lookupidx oid*/ + AttrNumber ttl_attno; /*ttl attrNumber*/ + int ttl; /*ttl*/ + int period; /*period*/ + int gather; /* gather (second) */ + int gather_window_interval; /* gather_window_interval (min) */ + + FuncExpr *hash; /*func expr*/ + char type; /*CV type*/ +} ContQuery; + +Query *get_cont_query_def(Oid def_relid); +ContQuery *get_cont_query_for_id(Oid id); +Oid get_defrelid_by_tab_relid(Oid tab_relid); +Oid get_dictrelid_by_tab_relid(Oid tab_relid); +bool rangevar_is_cqtab_with_dict(RangeVar *rv); +bool is_streaming_thread(); +Oid get_cqid_by_dict_relid(Oid relid); + +void streaming_context_set_is_ddl(void); +bool streaming_context_is_ddl(void); +void streaming_context_set_is_def_rel(bool); +void streaming_context_set_group_search(void); +bool streaming_context_is_group_search(void); +bool is_def_rel(void); + +bool is_group_column_by_colname(char *colname, Oid relid); +bool is_group_column_by_attrnum(int attrnum, Oid relid); +bool is_rte_cq(List *rtable); +bool is_streaming_string_optimze_on(Oid relid); + +#endif diff -uprN postgresql-hll-2.14_old/include/tcop/dest.h postgresql-hll-2.14/include/tcop/dest.h --- postgresql-hll-2.14_old/include/tcop/dest.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/dest.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,169 @@ +/* ------------------------------------------------------------------------- + * + * dest.h + * support for communication destinations + * + * Whenever the backend executes a query that returns tuples, the results + * have to go someplace. For example: + * + * - stdout is the destination only when we are running a + * standalone backend (no postmaster) and are returning results + * back to an interactive user. + * + * - a remote process is the destination when we are + * running a backend with a frontend and the frontend executes + * PQexec() or PQfn(). In this case, the results are sent + * to the frontend via the functions in backend/libpq. + * + * - DestNone is the destination when the system executes + * a query internally. The results are discarded. + * + * dest.c defines three functions that implement destination management: + * + * BeginCommand: initialize the destination at start of command. + * CreateDestReceiver: return a pointer to a struct of destination-specific + * receiver functions. + * EndCommand: clean up the destination at end of command. + * + * BeginCommand/EndCommand are executed once per received SQL query. + * + * CreateDestReceiver returns a receiver object appropriate to the specified + * destination. The executor, as well as utility statements that can return + * tuples, are passed the resulting DestReceiver* pointer. Each executor run + * or utility execution calls the receiver's rStartup method, then the + * receiveSlot method (zero or more times), then the rShutdown method. + * The same receiver object may be re-used multiple times; eventually it is + * destroyed by calling its rDestroy method. + * + * In some cases, receiver objects require additional parameters that must + * be passed to them after calling CreateDestReceiver. Since the set of + * parameters varies for different receiver types, this is not handled by + * this module, but by direct calls from the calling code to receiver type + * specific functions. + * + * The DestReceiver object returned by CreateDestReceiver may be a statically + * allocated object (for destination types that require no local state), + * in which case rDestroy is a no-op. Alternatively it can be a palloc'd + * object that has DestReceiver as its first field and contains additional + * fields (see printtup.c for an example). These additional fields are then + * accessible to the DestReceiver functions by casting the DestReceiver* + * pointer passed to them. The palloc'd object is pfree'd by the rDestroy + * method. Note that the caller of CreateDestReceiver should take care to + * do so in a memory context that is long-lived enough for the receiver + * object not to disappear while still needed. + * + * Special provision: None_Receiver is a permanently available receiver + * object for the DestNone destination. This avoids useless creation/destroy + * calls in portal and cursor manipulations. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/dest.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DEST_H +#define DEST_H + +#ifndef FRONTEND_PARSER +#include "executor/tuptable.h" + +/* buffer size to use for command completion tags */ +#define COMPLETION_TAG_BUFSIZE 64 + +/* ---------------- + * CommandDest is a simplistic means of identifying the desired + * destination. Someday this will probably need to be improved. + * + * Note: only the values DestNone, DestDebug, DestRemote are legal for the + * global variable whereToSendOutput. The other values may be used + * as the destination for individual commands. + * ---------------- + */ +typedef enum { + DestNone, /* results are discarded */ + DestDebug, /* results go to debugging output */ + DestRemote, /* results sent to frontend process */ + DestRemoteExecute, /* sent to frontend, in Execute command */ + DestSPI, /* results sent to SPI manager */ + DestTuplestore, /* results sent to Tuplestore */ + DestIntoRel, /* results sent to relation (SELECT INTO) */ + DestCopyOut, /* results sent to COPY TO code */ + DestSQLFunction, /* results sent to SQL-language func mgr */ + DestSPITupleAnalyze, /* results sent to SPI manager when analyze for table sample */ + + DestTupleBroadCast, /* results send to consumer thread in a broadcast way */ + DestTupleLocalBroadCast, /* results send to consumer thread in a local broadcast way */ + DestTupleRedistribute, /* results send to consumer thread in a redistribute way */ + DestTupleLocalRedistribute, /* results send to consumer thread in a local redistribute way */ + DestTupleLocalRoundRobin, /* results send to consumer thread in a local roundrobin way */ + + DestTupleHybrid, + + DestBatchBroadCast, /* results send to consumer thread in a broadcast way */ + DestBatchLocalBroadCast, /* results send to consumer thread in a local broadcast way */ + DestBatchRedistribute, /* results send to consumer thread in a redistribute way */ + DestBatchLocalRedistribute, /* results send to consumer thread in a local redistribute way */ + DestBatchLocalRoundRobin, /* results send to consumer thread in a local roundrobin way */ + + DestBatchHybrid, + DestTransientRel /* results sent to transient relation */ + +} CommandDest; + +class VectorBatch; + +/* ---------------- + * DestReceiver is a base type for destination-specific local state. + * In the simplest cases, there is no state info, just the function + * pointers that the executor must call. + * + * Note: the receiveSlot routine must be passed a slot containing a TupleDesc + * identical to the one given to the rStartup routine. + * ---------------- + */ +typedef struct _DestReceiver DestReceiver; + +struct _DestReceiver { + /* Called for each tuple to be output: */ + void (*receiveSlot)(TupleTableSlot* slot, DestReceiver* self); + /* Per-executor-run initialization and shutdown: */ + void (*rStartup)(DestReceiver* self, int operation, TupleDesc typeinfo); + void (*rShutdown)(DestReceiver* self); + /* Destroy the receiver object itself (if dynamically allocated) */ + void (*rDestroy)(DestReceiver* self); + /* CommandDest code for this receiver */ + CommandDest mydest; + /* Private fields might appear beyond this point... */ + + /* Send batch*/ + void (*sendBatch)(VectorBatch* batch, DestReceiver* self); + + void (*finalizeLocalStream)(DestReceiver* self); + + /* send sample tuple to coordinator for analyze */ + bool forAnalyzeSampleTuple; + + MemoryContext tmpContext; +}; + +extern DestReceiver* None_Receiver; /* permanent receiver for DestNone */ + +/* The primary destination management functions */ + +extern void BeginCommand(const char* commandTag, CommandDest dest); +extern DestReceiver* CreateDestReceiver(CommandDest dest); +extern DestReceiver* CreateReceiverForMerge(CommandDest dest); +extern void EndCommand(const char* commandTag, CommandDest dest); +extern void EndCommand_noblock(const char* commandTag, CommandDest dest); + +/* Additional functions that go with destination management, more or less. */ + +extern void NullCommand(CommandDest dest); +extern void ReadyForQuery(CommandDest dest); +extern void ReadyForQuery_noblock(CommandDest dest, int timeout); + +#endif /* !FRONTEND_PARSER */ +#endif /* DEST_H */ diff -uprN postgresql-hll-2.14_old/include/tcop/fastpath.h postgresql-hll-2.14/include/tcop/fastpath.h --- postgresql-hll-2.14_old/include/tcop/fastpath.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/fastpath.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- + * + * fastpath.h + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/fastpath.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FASTPATH_H +#define FASTPATH_H + +#include "lib/stringinfo.h" + +#define MAX_ARG_SIZE 107374182 + +extern int HandleFunctionRequest(StringInfo msgBuf); + +#endif /* FASTPATH_H */ diff -uprN postgresql-hll-2.14_old/include/tcop/pquery.h postgresql-hll-2.14/include/tcop/pquery.h --- postgresql-hll-2.14_old/include/tcop/pquery.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/pquery.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + * + * pquery.h + * prototypes for pquery.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/pquery.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PQUERY_H +#define PQUERY_H + +#include "nodes/parsenodes.h" +#include "utils/portal.h" + +extern THR_LOCAL PGDLLIMPORT Portal ActivePortal; + +extern PortalStrategy ChoosePortalStrategy(List* stmts); + +extern List* FetchPortalTargetList(Portal portal); + +extern List* FetchStatementTargetList(Node* stmt); + +extern void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot); + +extern void PortalSetResultFormat(Portal portal, int nFormats, int16* formats); + +extern bool PortalRun( + Portal portal, long count, bool isTopLevel, DestReceiver* dest, DestReceiver* altdest, char* completionTag); + +extern long PortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver* dest); + +#endif /* PQUERY_H */ diff -uprN postgresql-hll-2.14_old/include/tcop/stmt_retry.h postgresql-hll-2.14/include/tcop/stmt_retry.h --- postgresql-hll-2.14_old/include/tcop/stmt_retry.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/stmt_retry.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,417 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * stmt_retry.h + * support for statement retry + * + * + * IDENTIFICATION + * src/include/tcop/stmt_retry.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef STMT_RETRY_H +#define STMT_RETRY_H + +#include "c.h" + +#include "lib/stringinfo.h" +#include "utils/palloc.h" +#include "utils/elog.h" +#include "utils/hsearch.h" + +/* + * test stub usage + */ +const uint16 RETRY_STUB_CASE_SIZE = 256; +const uint16 RETRY_STUB_CASE_ECODE_SIZE = 21; + +typedef enum { STUB_DO_RETRY, STUB_PASS } RETRY_STUB_MARKER; + +/* + * log usage + */ +const char* const STUB_PRINT_PREFIX = " [retry stub] "; +const char* const STUB_PRINT_PREFIX_ALERT = " [retry stub alert] "; +const char* const STUB_PRINT_PREFIX_TYPE_S = " ~special path~ "; +const char* const STUB_PRINT_PREFIX_TYPE_R = " ~retry path~ "; +const char* const PRINT_PREFIX_TYPE_ALERT = " alert : "; +const char* const PRINT_PREFIX_TYPE_PATH = " retry path : "; + +/* + * marco for statement retry + */ +#define STMT_RETRY_ENABLED \ + (u_sess->attr.attr_common.max_query_retry_times > 0 && !u_sess->attr.attr_sql.enable_hadoop_env) + +/*message types which retry is supported*/ +const char Q_MESSAGE = 'Q'; +const char P_MESSAGE = 'P'; +const char B_MESSAGE = 'B'; +const char E_MESSAGE = 'E'; +const char D_MESSAGE = 'D'; +const char C_MESSAGE = 'C'; +const char S_MESSAGE = 'S'; +const char U_MESSAGE = 'U'; +const char F_MESSAGE = 'F'; +const char INVALID_MESSAGE = '0'; + +const char* const STMT_TOKEN = ";"; + +inline bool IsExtendQueryMessage(char msg_type) +{ + return ((msg_type == P_MESSAGE) || (msg_type == B_MESSAGE) || (msg_type == E_MESSAGE) || (msg_type == D_MESSAGE) || + (msg_type == C_MESSAGE) || (msg_type == S_MESSAGE) || (msg_type == U_MESSAGE) || (msg_type == F_MESSAGE)) + ? true + : false; +} + +inline bool IsSimpleQueryMessage(char msg_type) +{ + return (msg_type == Q_MESSAGE); +} + +inline bool IsQueryMessage(char msg_type) +{ + return (IsSimpleQueryMessage(msg_type) || IsExtendQueryMessage(msg_type)); +} + +inline bool IsMessageTypeMatchWithProtocol(bool is_extend_query, char msg_type) +{ + return is_extend_query ? IsExtendQueryMessage(msg_type) : IsSimpleQueryMessage(msg_type); +} + +/* + * QueryMessageContext is used to cache retry message context info for now + * in the future. + */ +class QueryMessageContext : public BaseObject { +public: + QueryMessageContext(MemoryContext mem_context) : context_(mem_context) + { + + MemoryContext old_context = MemoryContextSwitchTo(context_); + initStringInfo(&cached_msg_); + (void)MemoryContextSwitchTo(old_context); + } + + ~QueryMessageContext(void) + {} + +public: + void CacheMessage(char msg_type, StringInfo msg_data); + + int MessageSize(void) const + { + return cached_msg_.len; + } + + void DumpHistoryCommandsToPqBuffer(void); + + void Reset(void); + char PeekFirstChar(void) const + { + return cached_msg_.data[0]; + }; + +private: + /* disallow copy*/ + QueryMessageContext(const QueryMessageContext&); + QueryMessageContext& operator=(const QueryMessageContext&); + +private: + StringInfoData cached_msg_; /* If 'P' 'B' 'E''D', msg cached from input_message, If 'Q' cached from + * debug_query string */ + MemoryContext context_; +}; + +typedef enum { + STMT_RETRY_DEFAULT, /*default status of retry, meaning retry is not triggered*/ + STMT_RETRY_SIMPLE_QUREY_RETRYING, /*indicate we are in simple query retry flow*/ + STMT_RETRY_EXTEND_QUREY_RETRYING, /*indicate we are in pbe retry flow*/ +} StatementRetryPhase; + +typedef StatementRetryPhase CombinedStatementRetryPhase; + +typedef struct MessageInfo { + char type; + int len; + + MessageInfo(char _type, int _len) : type(_type), len(_len) + {} +} MessageInfo; + +/* + * since pbe messages in extend query executed in a continues way, for example messages flow can be + * combination of "p-b-d-e-b-e-s", in extend query retry, we treat pbe message flow as a whole, + * PBEFlowTracker track pbe flow and using tracked pbe flow info to check retrying pbe execution if + * retry happens. + */ +class PBEFlowTracker : public BaseObject { +public: + PBEFlowTracker(MemoryContext mem_context) + { + MemoryContext old_context = MemoryContextSwitchTo(mem_context); + + initStringInfo(&pbe_flow_); + initStringInfo(&history_pbe_flow_); + + (void)MemoryContextSwitchTo(old_context); + } + ~PBEFlowTracker(void) + {} + + void Reset(void) + { + resetStringInfo(&pbe_flow_); + resetStringInfo(&history_pbe_flow_); + } + +public: + void TrackPBE(char type) + { + appendStringInfoChar(&pbe_flow_, type); + } + + void InitValidating(void) + { + if (pbe_flow_.len > 0) { + copyStringInfo(&history_pbe_flow_, &pbe_flow_); + resetStringInfo(&pbe_flow_); + } + } + void Validate(char type); + + const char* PBEFlowStr(void) + { + return pbe_flow_.data; + } + +private: + StringInfoData pbe_flow_; /* recording executed pbe message flow */ + StringInfoData history_pbe_flow_; /* recording executed pbe message flow before retrying */ +}; + +/* + * stub for statement retry, use it to Manually construct sql retry both in extended query and simple query + */ +class StatementRetryStub { +public: + StatementRetryStub(void) + { + InitECodeMarker(); + Reset(); + } + ~StatementRetryStub(void) + {} + + void Reset(void); + +public: + void StartOneStubTest(char msg_type); + bool OnStubTest(void) const + { + return on_stub_test; + } + void CloseOneStub(void); + void FinishStubTest(const char* info); + + void InitECodeMarker(void); + void ECodeStubTest(void); + void ECodeValidate(void); + +private: + /* disallow copy*/ + StatementRetryStub(const StatementRetryStub&); + StatementRetryStub& operator=(const StatementRetryStub&); + +private: + uint8 stub_marker[RETRY_STUB_CASE_SIZE]; + int ecode_marker[RETRY_STUB_CASE_ECODE_SIZE]; + uint16 stub_pos; + uint16 ecode_pos; + bool on_stub_test; +}; + +/* + * this is the main class of statement retry control + * 1.A StatementRetryController will track a simple query or a extend query(PBE flow) + * during query execution, tracking behave like cache query string in simple query, + * record p message pointer in extend query. + * 2.once query retry is triggerd, StatementRetryController will control the retry routine, + * such as how to settle the read/send buffer between cn and client, how to ReadCommand and so on + */ +class StatementRetryController : public BaseObject { +public: + StatementRetryController(MemoryContext mem_context) + : retry_id(0), is_retry_enabled(false), cached_msg_context(mem_context), pbe_tracker(mem_context) + { + + MemoryContext old_context = MemoryContextSwitchTo(mem_context); + initStringInfo(&prepared_stmt_name); + (void)MemoryContextSwitchTo(old_context); + + Reset(); + } + ~StatementRetryController(void) + {} + + void Reset(void); + +public: + /* common usage */ + void EnableRetry(void); + void DisableRetry(void); + bool IsRetryEnabled(void) + { + return is_retry_enabled; + } + bool IsExtendQueryRetrying(void) const + { + return STMT_RETRY_EXTEND_QUREY_RETRYING == retry_phase; + } + bool IsSimpleQueryRetrying(void) const + { + return STMT_RETRY_SIMPLE_QUREY_RETRYING == retry_phase; + } + bool IsQueryRetrying(void) const + { + return (IsExtendQueryRetrying() || IsSimpleQueryRetrying()); + } + bool IsTrackedQueryMessageInfoValid(bool is_extend_query); + void TriggerRetry(bool is_extend_query); + void FinishRetry(void); + void CleanPreparedStmt(void); + + void LogTraceInfo(MessageInfo info) + { + if (retry_phase > STMT_RETRY_DEFAULT) { + ereport(DEBUG3, + (errmodule(MOD_CN_RETRY), errmsg("retrying \"%c\" message, length \"%d\"", info.type, info.len))); + } else { + ereport(DEBUG3, + (errmodule(MOD_CN_RETRY), errmsg("executing \"%c\" message, length \"%d\"", info.type, info.len))); + } + } + + /* message caching */ + void CacheCommand(char type, StringInfo data) + { + cached_msg_context.CacheMessage(type, data); + } + void TrackMessageOnExecuting(char type) + { +#if USE_ASSERT_CHECKING + if (IsExtendQueryMessage(type)) + pbe_tracker.TrackPBE(type); +#endif + executing_msg_type = type; + } + void CacheStmtName(const char* stmt_name) + { + appendStringInfoString(&prepared_stmt_name, stmt_name); + appendStringInfoString(&prepared_stmt_name, STMT_TOKEN); + } + char MessageOnExecuting(void) const + { + return executing_msg_type; + } + + /* pbe flow tracking */ + void ValidateExecuting(char type) + { + pbe_tracker.Validate(type); + } + const char* PBEFlowStr(void) + { + return pbe_tracker.PBEFlowStr(); + } + +public: /*in order to compatible with legacy code, declaring all data member as public here */ + uint64 retry_id; /* id for retrying query */ + int retry_times; /* mark current retry times */ + int error_code; /* recording error code that trigger long jump */ + bool is_trans; /* if the query within either a transaction or a transaction block, + * it is not allowed to retry */ + bool is_tempfile_size_exceeded; /* if true, meaning tempfile for caching query result is exceeded, + * so there is no way to make sure the query result can be exact, + * in this situation retry can not be allowed */ + bool is_unsupported_query_type; /* if true, meaning query type can't retry for now */ + bool is_retry_enabled; /* if true, meaning retry feature is enabled, + * now StatementRetryController will track query and trigger retry at long jump point */ + bool is_transaction_committed; /* if true, meaning current transaction is committed, if error happens between + transaction committed and finish, we disallow retry during this period */ + CombinedStatementRetryPhase retry_phase; /* recording current retry phase */ + QueryMessageContext cached_msg_context; /* cached statement context store statement info of a statement to + * be retry subsequently */ + +#ifdef USE_RETRY_STUB + StatementRetryStub stub_; /* test stub for auto trigger sql retry */ +#endif + +private: + char executing_msg_type; /* tracking msg on executing */ + PBEFlowTracker pbe_tracker; /* tracking pbe flow execution */ + StringInfoData prepared_stmt_name; /* caching prepared statement name */ +}; + +/* + *statement retry common usage + */ +extern StatementRetryController* StmtRetryInitController(void); +extern void StmtRetryResetController(void); +extern void StmtRetrySetFileExceededFlag(void); +extern void StmtRetrySetQuerytUnsupportedFlag(void); +extern void StmtRetrySetTransactionCommitFlag(bool flag); +extern void StmtRetryValidate(StatementRetryController* controller); +extern void StmtRetryDisable(void); + +extern bool IsStmtRetryEnabled(void); +extern bool IsStmtRetryQueryRetrying(void); +extern bool IsStmtRetryAvaliable(int elevel, int sqlErrCode); +extern bool IsStmtRetryCapable(StatementRetryController* controller, bool is_extend_query); +extern bool IsStmtNeedRetryByErrCode(const char* ecode_str, int errlevel); + +/* + * lnline functions + */ + +/* + * @Description: check if the sql statement need to retry by error code. + * @in ecode - error code type + * @in elevel - elevel type + * @return - true, statement retry is needed by error code. + */ +inline bool IsStmtNeedRetryByErrCode(int ecode, int errlevel) +{ + char* ecode_str = unpack_sql_state(ecode); + return IsStmtNeedRetryByErrCode(ecode_str, errlevel); +} + +/* + * @Description: filter statement retry by application name, filtering sql from application such as cm_agent and + gs_clean, not to retry. + * @in name - application name + * @return + */ +inline bool IsStmtNeedRetryByApplicationName(const char* name) +{ + return ((name != NULL) && (strcmp(name, "cm_agent") != 0) && (strcmp(name, "gs_clean") != 0) && + (strcmp(name, "gc_fdw") != 0)); +} + +#endif + +/*file end stmt_retry.h */ diff -uprN postgresql-hll-2.14_old/include/tcop/tcopdebug.h postgresql-hll-2.14/include/tcop/tcopdebug.h --- postgresql-hll-2.14_old/include/tcop/tcopdebug.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/tcopdebug.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- + * + * tcopdebug.h + * #defines governing debugging behaviour in the traffic cop + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/tcopdebug.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TCOPDEBUG_H +#define TCOPDEBUG_H + +/* ---------------------------------------------------------------- + * debugging defines. + * + * If you want certain debugging behaviour, then #define + * the variable to 1, else #undef it. -cim 10/26/89 + * ---------------------------------------------------------------- + */ + +/* ---------------- + * TCOP_SHOWSTATS controls whether or not buffer and + * access method statistics are shown for each query. -cim 2/9/89 + * ---------------- + */ +#undef TCOP_SHOWSTATS + +/* ---------------- + * TCOP_DONTUSENEWLINE controls the default setting of + * the UseNewLine variable in postgres.c + * ---------------- + */ +#undef TCOP_DONTUSENEWLINE + +/* ---------------------------------------------------------------- + * #defines controlled by above definitions + * ---------------------------------------------------------------- + */ + +#endif /* TCOPDEBUG_H */ diff -uprN postgresql-hll-2.14_old/include/tcop/tcopprot.h postgresql-hll-2.14/include/tcop/tcopprot.h --- postgresql-hll-2.14_old/include/tcop/tcopprot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/tcopprot.h 2020-12-12 17:06:43.383349793 +0800 @@ -0,0 +1,70 @@ +/* ------------------------------------------------------------------------- + * + * tcopprot.h + * prototypes for postgres.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/tcopprot.h + * + * OLD COMMENTS + * This file was created so that other c files could get the two + * function prototypes without having to include tcop.h which single + * handedly includes the whole f*cking tree -- mer 5 Nov. 1991 + * + * ------------------------------------------------------------------------- + */ +#ifndef TCOPPROT_H +#define TCOPPROT_H + +#include "executor/execdesc.h" +#include "nodes/parsenodes.h" +#include "storage/procsignal.h" +#include "utils/guc.h" + +/* Required daylight between max_stack_depth and the kernel limit, in bytes */ +#define STACK_DEPTH_SLOP (640 * 1024L) + +/* GUC-configurable parameters */ + +typedef enum { + LOGSTMT_NONE, /* log no statements */ + LOGSTMT_DDL, /* log data definition statements */ + LOGSTMT_MOD, /* log modification statements, plus DDL */ + LOGSTMT_ALL /* log all statements */ +} LogStmtLevel; + +extern List* pg_parse_query(const char* query_string, List** query_string_locationlist = NULL); +extern List* pg_analyze_and_rewrite(Node* parsetree, const char* query_string, Oid* paramTypes, int numParams); +extern List* pg_analyze_and_rewrite_params( + Node* parsetree, const char* query_string, ParserSetupHook parserSetup, void* parserSetupArg); +extern PlannedStmt* pg_plan_query( + Query* querytree, int cursorOptions, ParamListInfo boundParams, bool underExplain = false); +extern List* pg_plan_queries(List* querytrees, int cursorOptions, ParamListInfo boundParams); + +extern bool check_max_stack_depth(int* newval, void** extra, GucSource source); +extern void assign_max_stack_depth(int newval, void* extra); + +extern void die(SIGNAL_ARGS); +extern void quickdie(SIGNAL_ARGS); +extern void StatementCancelHandler(SIGNAL_ARGS); +extern void FloatExceptionHandler(SIGNAL_ARGS); +extern void RecoveryConflictInterrupt(ProcSignalReason reason); /* called from SIGUSR1 + * handler */ +extern void prepare_for_client_read(void); +extern void client_read_ended(void); +extern void prepare_for_logic_conn_read(void); +extern void logic_conn_read_check_ended(void); +extern void process_postgres_switches(int argc, char* argv[], GucContext ctx, const char** dbname); +extern int PostgresMain(int argc, char* argv[], const char* dbname, const char* username); +extern long get_stack_depth_rlimit(void); +extern void ResetUsage(void); +extern void ShowUsage(const char* title); +extern int check_log_duration(char* msec_str, bool was_logged); +extern void set_debug_options(int debug_flag, GucContext context, GucSource source); +extern bool set_plan_disabling_options(const char* arg, GucContext context, GucSource source); +extern const char* get_stats_option_name(const char* arg); + +#endif /* TCOPPROT_H */ diff -uprN postgresql-hll-2.14_old/include/tcop/utility.h postgresql-hll-2.14/include/tcop/utility.h --- postgresql-hll-2.14_old/include/tcop/utility.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tcop/utility.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,196 @@ +/* ------------------------------------------------------------------------- + * + * utility.h + * prototypes for utility.c. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tcop/utility.h + * + * ------------------------------------------------------------------------- + */ +#ifndef UTILITY_H +#define UTILITY_H + +#include "pgxc/pgxcnode.h" +#include "tcop/tcopprot.h" + +#define CHOOSE_EXEC_NODES(is_temp) ((is_temp) ? EXEC_ON_DATANODES : EXEC_ON_ALL_NODES) + +#define TRANSFER_DISABLE_DDL(namespaceOid) \ + do { \ + if (!IsInitdb && \ + IS_PGXC_COORDINATOR && !IsConnFromCoord() && \ + IsSchemaInDistribution(namespaceOid) && \ + (u_sess->attr.attr_common.application_name == NULL || \ + strncmp(u_sess->attr.attr_common.application_name, "gs_redis", strlen("gs_redis")) != 0)) { \ + ereport(ERROR, (errcode(ERRCODE_INVALID_OPERATION), \ + errmsg("Disallow DDL while schema transfering."))); \ + } \ + } while(0) \ + +/* Hook for plugins to get control in ProcessUtility() */ +typedef void (*ProcessUtility_hook_type)(Node* parsetree, const char* queryString, ParamListInfo params, + bool isTopLevel, DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); +extern THR_LOCAL PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook; + +extern void ProcessUtility(Node* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, + DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); +extern void standard_ProcessUtility(Node* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, + DestReceiver* dest, +#ifdef PGXC + bool sentToRemote, +#endif /* PGXC */ + char* completionTag); + +extern char* find_first_exec_cn(); +extern bool find_hashbucket_options(List* stmts); + +#ifdef PGXC +extern void CreateCommand( + CreateStmt* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel, bool sentToRemote); +#else +extern void CreateCommand(CreateStmt* parsetree, const char* queryString, ParamListInfo params, bool isTopLevel); +#endif + +extern void ReindexCommand(ReindexStmt* stmt, bool isTopLevel); + +extern bool UtilityReturnsTuples(Node* parsetree); + +extern TupleDesc UtilityTupleDescriptor(Node* parsetree); + +extern Query* UtilityContainsQuery(Node* parsetree); + +extern const char* CreateCommandTag(Node* parsetree); + +extern LogStmtLevel GetCommandLogLevel(Node* parsetree); + +extern bool CommandIsReadOnly(Node* parsetree); + +#ifdef PGXC + +typedef enum { + ARQ_TYPE_TOTALROWCNTS, + ARQ_TYPE_SAMPLE, /* include sample rows or sample table. */ +} ANALYZE_RQTYPE; + +extern void pgxc_lock_for_utility_stmt(Node* parsetree, bool is_temp); +extern void ExecUtilityStmtOnNodes(const char* queryString, ExecNodes* nodes, bool sentToRemote, bool force_autocommit, + RemoteQueryExecType exec_type, bool is_temp, Node* parsetree = NULL); +extern HeapTuple* ExecRemoteVacuumStmt(VacuumStmt* stmt, const char* queryString, bool sentToRemote, + ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL, Oid relid = InvalidOid); + +extern void ExecUtilityStmtOnNodes_ParallelDDLMode(const char* queryString, ExecNodes* nodes, bool sentToRemote, + bool force_autocommit, RemoteQueryExecType exec_type, bool is_temp, const char* FirstExecNode = NULL, + Node* parsetree = NULL); + +extern HeapTuple* ExecUtilityStmtOnNodesWithResults(VacuumStmt* stmt, const char* queryString, bool sentToRemote, + ANALYZE_RQTYPE arq_type, AnalyzeMode eAnalyzeMode = ANALYZENORMAL); +extern void CheckObjectInBlackList(ObjectType objtype, const char* queryString); +extern bool CheckExtensionInWhiteList(const char* extensionName, uint32 hashvalue, bool hashCheck); +/* @hdfs Judge if a foreign table support analyze operation. */ +bool IsHDFSTableAnalyze(Oid foreignTableId); +/* @pgfdw judge if is a gc_fdw foreign table support analysis operation. */ +bool IsPGFDWTableAnalyze(Oid foreignTableId); +#ifdef ENABLE_MOT +/* @MOT IsMOTForeignTbale */ +bool IsMOTForeignTable(Oid foreignTableId); +#endif +/* @hdfs IsForeignTableAnalyze function is called by standard_ProcessUtility */ +bool IsHDFSForeignTableAnalyzable(VacuumStmt* stmt); +void global_stats_set_samplerate(AnalyzeMode eAnalyzeMode, VacuumStmt* stmt, const double* NewSampleRate); +bool check_analyze_permission(Oid rel); + +extern ExecNodes* RelidGetExecNodes(Oid relid, bool isutility = true); +extern bool ObjectsInSameNodeGroup(List* objects, NodeTag stmttype); +extern void EstIdxMemInfo( + Relation rel, RangeVar* relation, UtilityDesc* desc, IndexInfo* info, const char* accessMethod); +extern void AdjustIdxMemInfo(AdaptMem* operatorMem, UtilityDesc* desc); + +/* + * @hdfs The struct HDFSTableAnalyze is used to store datanode work infomation + */ +typedef struct HDFSTableAnalyze { + NodeTag type; + List* DnWorkFlow; + int DnCnt; + bool isHdfsStore; /* the flag identify whether or not the relation for analyze is Dfs store */ + double sampleRate[ANALYZE_MODE_MAX_NUM - 1]; /* There are three sampleRate values for HDFS table, include + main/delta/complex. */ + unsigned int orgCnNodeNo; /* the nodeId identify which CN receive analyze command from client, other CN need to get + stats from it. */ + bool isHdfsForeignTbl; /* the current analyze table is hdfs foreign table or not. */ + bool sampleTableRequired; /* require sample table for get statistic. */ + List* tmpSampleTblNameList; /* identify sample table name if under debugging. */ + DistributionType disttype; /* Distribution type for analyze's table. */ + AdaptMem memUsage; /* meminfo that should pass down to dn */ +} HDFSTableAnalyze; + +typedef struct PGFDWTableAnalyze { + Oid relid; + PGXCNodeAllHandles* pgxc_handles; + + int natts_pg_statistic; + int natts_pg_statistic_ext; + + int natts; + char** attname; + int* attnum; + + bool has_analyze; +} PGFDWTableAnalyze; + +/* + * @hdfs The struct ForeignTableDesc is used to represent foreign table + */ +typedef struct ForeignTableDesc { + NodeTag type; + char* tableName; + char* schemaName; + Oid tableOid; +} ForeignTableDesc; + +/* The struct for verify information*/ +typedef struct VerifyDesc { + bool isCudesc; /* judge cudesc relation and its toast\index relation */ + bool isCudescDamaged; /*judge the relation data corrupt*/ +} VerifyDesc; + +enum FOREIGNTABLEFILETYPE_ { + HDFS_ORC = 1, + MOT_ORC = 2, + MYSQL_ORC = 3, + ORACLE_ORC = 4, + POSTGRES_ORC = 5 +}; + +typedef enum FOREIGNTABLEFILETYPE_ FOREIGNTABLEFILETYPE; + +#endif + +extern void BlockUnsupportedDDL(const Node* parsetree); +extern const char* CreateAlterTableCommandTag(const AlterTableType subtype); + +extern void SetSortMemInfo(UtilityDesc* desc, int rowCnt, int width, bool vectorized, bool indexSort, Size defaultSize, + Relation copyRel = NULL); +extern char* ConstructMesageWithMemInfo(const char* queryString, AdaptMem memInfo); + +extern void AssembleHybridMessage(char** queryStringWithInfo, const char* queryString, const char* schedulingMessage); + +extern void ClearCreateSeqStmtUUID(CreateSeqStmt* stmt); +extern void ClearCreateStmtUUIDS(CreateStmt* stmt); +extern bool IsSchemaInDistribution(const Oid namespaceOid); +extern Oid GetNamespaceIdbyRelId(const Oid relid); + + +#endif /* UTILITY_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_controler.h postgresql-hll-2.14/include/threadpool/threadpool_controler.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_controler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_controler.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,125 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_controler.h + * Controler for thread pool. Class ThreadPoolControler is defined to + * initilize thread pool's worker and listener threads, and dispatch + * new session from postmaster thread to suitable thread group. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_controler.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_CONTROLER_H +#define THREAD_POOL_CONTROLER_H + +#include "utils/memutils.h" +#include "threadpool_group.h" +#include "knl/knl_variable.h" + +class ThreadPoolSessControl; + +enum CPUBindType { NO_CPU_BIND, ALL_CPU_BIND, NODE_BIND, CPU_BIND }; + +typedef struct CPUInfo { + int totalCpuNum; + int activeCpuNum; + int totalNumaNum; + int activeNumaNum; + int* cpuArrSize; + int** cpuArr; + + CPUBindType bindType; + bool* isBindCpuArr; + bool* isBindNumaArr; + bool* isMcsCpuArr; +} CPUInfo; + +typedef struct ThreadPoolAttr { + int threadNum; + int groupNum; + char* bindCpu; +} ThreadPoolAttr; + +class ThreadPoolControler : public BaseObject { +public: + ThreadPoolSessControl* m_sessCtrl; + + ThreadPoolControler(); + ~ThreadPoolControler(); + + void Init(bool enableNumaDistribute); + void ShutDownThreads(bool forceWait = false); + int DispatchSession(Port* port); + void AddWorkerIfNecessary(); + void SetThreadPoolInfo(); + int GetThreadNum(); + ThreadPoolStat* GetThreadPoolStat(uint32* num); + bool StayInAttachMode(); + void CloseAllSessions(); + bool CheckNumaDistribute(int numaNodeNum) const; + CPUBindType GetCpuBindType() const; + void ShutDownListeners(bool forceWait); + void ShutDownScheduler(bool forceWait); + inline ThreadPoolSessControl* GetSessionCtrl() + { + return m_sessCtrl; + } + inline ThreadPoolScheduler* GetScheduler() + { + return m_scheduler; + } + inline int GetGroupNum() + { + return m_groupNum; + } + + inline MemoryContext GetMemCxt() + { + return m_threadPoolContext; + } + + void BindThreadToAllAvailCpu(ThreadId thread) const; + +private: + ThreadPoolGroup* FindThreadGroupWithLeastSession(); + void ParseAttr(); + void ParseBindCpu(); + int ParseRangeStr(char* attr, bool* arr, int totalNum, char* bindtype); + void GetMcsCpuInfo(); + void GetSysCpuInfo(); + void InitCpuInfo(); + void GetCpuAndNumaNum(); + bool IsActiveCpu(int cpuid, int numaid); + void SetGroupAndThreadNum(); + void ConstrainThreadNum(); + void GetInstanceBind(); + bool CheckCpuBind() const; + +private: + MemoryContext m_threadPoolContext; + ThreadPoolGroup** m_groups; + ThreadPoolScheduler* m_scheduler; + CPUInfo m_cpuInfo; + ThreadPoolAttr m_attr; + cpu_set_t m_cpuset; + int m_groupNum; + int m_threadNum; + int m_maxPoolSize; +}; + +#endif /* THREAD_POOL_CONTROLER_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_group.h postgresql-hll-2.14/include/threadpool/threadpool_group.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_group.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_group.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,170 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_group.h + * Thread pool group controls listener and worker threads. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_group.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_GROUP_H +#define THREAD_POOL_GROUP_H + +#include "c.h" +#include "utils/memutils.h" +#include "knl/knl_variable.h" + +#define NUM_THREADPOOL_STATUS_ELEM 8 +#define STATUS_INFO_SIZE 256 + +typedef enum { THREAD_SLOT_UNUSE = 0, THREAD_SLOT_INUSE } ThreadSlotStatus; + +struct ThreadSentryStatus { + int spawntick; + TimestampTz lastSpawnTime; + ThreadSlotStatus slotStatus; +}; + +struct ThreadWorkerSentry { + ThreadSentryStatus stat; + ThreadPoolWorker* worker; + pthread_mutex_t mutex; + pthread_cond_t cond; +}; + +#ifdef ENABLE_MULTIPLE_NODES +struct ThreadStreamSentry { + ThreadSentryStatus stat; + ThreadPoolStream* stream; + pthread_mutex_t mutex; + pthread_cond_t cond; +}; +#endif + +typedef struct ThreadPoolStat { + int groupId; + int numaId; + int bindCpuNum; + int listenerNum; + char workerInfo[STATUS_INFO_SIZE]; + char sessionInfo[STATUS_INFO_SIZE]; + char streamInfo[STATUS_INFO_SIZE]; +} ThreadPoolStat; + +class ThreadPoolGroup : public BaseObject { +public: + ThreadPoolListener* m_listener; + + ThreadPoolGroup(int maxWorkerNum, int expectWorkerNum, int maxStreamNum, + int groupId, int numaId, int cpuNum, int* cpuArr); + ~ThreadPoolGroup(); + void Init(bool enableNumaDistribute); + void InitWorkerSentry(); + void ReleaseWorkerSlot(int i); + void AddWorker(int i); + ThreadId AddStream(StreamProducer* producer); + void ShutDownThreads(); + void AddWorkerIfNecessary(); + bool EnlargeWorkers(int enlargeNum); + void ReduceWorkers(int reduceNum); + void ShutDownPendingWorkers(); + void ReduceStreams(); + void WaitReady(); + float4 GetSessionPerThread(); + void GetThreadPoolGroupStat(ThreadPoolStat* stat); + bool IsGroupHang(); + + inline ThreadPoolListener* GetListener() + { + return m_listener; + } + + inline int GetGroupId() + { + return m_groupId; + } + + inline int GetNumaId() + { + return m_numaId; + } + + inline bool AllSessionClosed() + { + return (m_sessionCount <= 0); + } + + inline bool AllThreadShutDown() + { + return (m_workerNum <= 0); + } + +#ifdef ENABLE_MULTIPLE_NODES + ThreadId GetStreamFromPool(StreamProducer* producer); + void ReturnStreamToPool(Dlelem* elem); + void RemoveStreamFromPool(Dlelem* elem, int idx); + void InitStreamSentry(); + + inline bool HasFreeStream() + { + return (m_idleStreamNum > 0); + } +#endif + + friend class ThreadPoolWorker; + friend class ThreadPoolListener; + friend class ThreadPoolScheduler; + +private: + void AttachThreadToCPU(ThreadId thread, int cpu); + void AttachThreadToNodeLevel(ThreadId thread) const; + +private: + int m_maxWorkerNum; + int m_maxStreamNum; + int m_defaultWorkerNum; + volatile int m_workerNum; + volatile int m_listenerNum; + volatile int m_expectWorkerNum; + volatile int m_idleWorkerNum; + volatile int m_pendingWorkerNum; + volatile int m_streamNum; + volatile int m_idleStreamNum; + volatile int m_sessionCount; // all session count; + volatile int m_waitServeSessionCount; // wait for worker to server + volatile int m_processTaskCount; + + int m_groupId; + int m_numaId; + int m_groupCpuNum; + int* m_groupCpuArr; + bool m_enableNumaDistribute; + cpu_set_t m_nodeCpuSet; /* for numa node distribution only */ + + ThreadWorkerSentry* m_workers; + MemoryContext m_context; + pthread_mutex_t m_mutex; + +#ifdef ENABLE_MULTIPLE_NODES + ThreadStreamSentry* m_streams; + DllistWithLock* m_freeStreamList; +#endif +}; + +#endif /* THREAD_POOL_GROUP_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool.h postgresql-hll-2.14/include/threadpool/threadpool.h --- postgresql-hll-2.14_old/include/threadpool/threadpool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool.h + * Include all thread pool header file. + * + * IDENTIFICATION + * src/include/threadpool/threadpool.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_H +#define THREAD_POOL_H + +#include "threadpool/threadpool_controler.h" +#include "threadpool/threadpool_group.h" +#include "threadpool/threadpool_listener.h" +#include "threadpool/threadpool_sessctl.h" +#include "threadpool/threadpool_worker.h" +#include "threadpool/threadpool_scheduler.h" +#include "threadpool/threadpool_stream.h" + +#define ENABLE_THREAD_POOL (g_threadPoolControler != NULL) +#define IS_THREAD_POOL_WORKER (t_thrd.role == THREADPOOL_WORKER) +#define IS_THREAD_POOL_LISTENER (t_thrd.role == THREADPOOL_LISTENER) +#define IS_THREAD_POOL_SCHEDULER (t_thrd.role == THREADPOOL_SCHEDULER) +#define IS_THREAD_POOL_STREAM (t_thrd.role == THREADPOOL_STREAM) +#define IS_THREAD_POOL_SESSION (u_sess->session_id > 0) +#define BackendIdForTempRelations (ENABLE_THREAD_POOL ? (BackendId)u_sess->session_ctr_index : t_thrd.proc_cxt.MyBackendId) +#define THREAD_CORE_RATIO 1 +#define DEFAULT_THREAD_POOL_SIZE 16 +#define DEFAULT_THREAD_POOL_GROUPS 2 +#define MAX_THREAD_POOL_SIZE 4096 +#define MAX_STREAM_POOL_SIZE 16384 +#define MAX_THREAD_POOL_GROUPS 64 + +extern ThreadPoolControler* g_threadPoolControler; + +extern void BackendWorkerIAm(); + +/* Interface for thread pool listener */ +extern void TpoolListenerMain(ThreadPoolListener* listener); +extern void ThreadPoolListenerIAm(); + +extern void PreventSignal(); +extern void AllowSignal(); + +#endif /* THREAD_POOL_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_listener.h postgresql-hll-2.14/include/threadpool/threadpool_listener.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_listener.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_listener.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,81 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_listener.h + * Listener thread epoll all connections belongs to this thread group, and + * dispatch active session to a free worker. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_listener.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef THREAD_POOL_LISTENER_H +#define THREAD_POOL_LISTENER_H + +#include +#include "lib/dllist.h" +#include "knl/knl_variable.h" + +class ThreadPoolListener : public BaseObject { +public: + ThreadPoolGroup* m_group; + volatile bool m_reaperAllSession; + + ThreadPoolListener(ThreadPoolGroup* group); + ~ThreadPoolListener(); + int StartUp(); + void CreateEpoll(); + void NotifyReady(); + bool TryFeedWorker(ThreadPoolWorker* worker); + void AddNewSession(knl_session_context* session); + void WaitTask(); + void DelSessionFromEpoll(knl_session_context* session); + void RemoveWorkerFromList(ThreadPoolWorker* worker); + void AddEpoll(knl_session_context* session); + void SendShutDown(); + void ReaperAllSession(); + void ShutDown() const; + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + inline ThreadId GetThreadId() + { + return m_tid; + } + inline void ResetThreadId() + { + m_tid = 0; + } +private: + void HandleConnEvent(int nevets); + knl_session_context* GetSessionBaseOnEvent(struct epoll_event* ev); + void DispatchSession(knl_session_context* session); + +private: + ThreadId m_tid; + int m_epollFd; + struct epoll_event* m_epollEvents; + + DllistWithLock* m_freeWorkerList; + DllistWithLock* m_readySessionList; + DllistWithLock* m_idleSessionList; +}; + +#endif /* THREAD_POOL_LISTENER_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_scheduler.h postgresql-hll-2.14/include/threadpool/threadpool_scheduler.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_scheduler.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_scheduler.h 2020-12-12 17:06:43.384349806 +0800 @@ -0,0 +1,62 @@ +/*--------------------------------------------------------------------------------------- + * + * threadpool_scheduler.h + * + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2019, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/threadpool/threadpool_scheduler.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_SCHEDULER_CONTROL_H +#define THREAD_POOL_SCHEDULER_CONTROL_H + +class ThreadPoolScheduler : public BaseObject{ +public: + ThreadPoolScheduler(int groupNum, ThreadPoolGroup** groups); + ~ThreadPoolScheduler(); + int StartUp(); + void DynamicAdjustThreadPool(); + void GPCScheduleCleaner(int* gpc_count); + void CNGPCScheduleCleaner(int* gpc_count); + void ShutDown() const; + inline ThreadId GetThreadId() + { + return m_tid; + } + inline void SetShutDown(bool has_shutdown) + { + m_has_shutdown = has_shutdown; + } + inline bool HasShutDown() + { + return m_has_shutdown; + } +private: + void AdjustWorkerPool(int idx); + void AdjustStreamPool(int idx); + void ReduceWorkerIfNecessary(int groupIdx); + void EnlargeWorkerIfNecessage(int groupIdx); +private: + ThreadId m_tid; + int m_groupNum; + ThreadPoolGroup** m_groups; + uint* m_hangTestCount; + uint* m_freeTestCount; + uint* m_freeStreamCount; + volatile bool m_has_shutdown; +}; + +#define THREAD_SCHEDULER_STEP 8 + +extern void TpoolSchedulerMain(ThreadPoolScheduler* scheduler); + +#endif diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_sessctl.h postgresql-hll-2.14/include/threadpool/threadpool_sessctl.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_sessctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_sessctl.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_sessctl.h + * Class ThreadPoolSessControl is used to control all session info in thread pool. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_sessctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_SESSION_CONTROL_H +#define THREAD_POOL_SESSION_CONTROL_H + +#include "storage/procsignal.h" +#include "knl/knl_variable.h" +#include "utils/tuplestore.h" + +#define MEMORY_CONTEXT_NAME_LEN 64 +#define PROC_NAME_LEN 64 +#define NUM_SESSION_MEMORY_DETAIL_ELEM 8 +#define NUM_THREAD_MEMORY_DETAIL_ELEM 9 +#define NUM_SHARED_MEMORY_DETAIL_ELEM 6 + + +typedef struct knl_sess_control { + Dlelem elem; + int idx; // session array index; + knl_session_context* sess; + volatile sig_atomic_t lock; +} knl_sess_control; + +class ThreadPoolSessControl : public BaseObject { +public: + ThreadPoolSessControl(MemoryContext context); + ~ThreadPoolSessControl(); + knl_session_context* CreateSession(Port* port); + knl_sess_control* AllocateSlot(knl_session_context* sc); + void FreeSlot(int ctrl_index); + void MarkAllSessionClose(); + int SendSignal(int ctrl_index, int signal); + void SendProcSignal(int ctrl_index, ProcSignalReason reason, uint64 query_id); + int CountDBSessions(Oid dbId); + void SigHupHandler(); + void HandlePoolerReload(); + void CheckSessionTimeout(); + void CheckPermissionForSendSignal(knl_session_context* sess); + void getSessionMemoryDetail(Tuplestorestate* tupStore, TupleDesc tupDesc, knl_sess_control** sess); + knl_session_context* GetSessionByIdx(int idx); + int FindCtrlIdxBySessId(uint64 id); + TransactionId ListAllSessionGttFrozenxids(int maxSize, ThreadId *pids, TransactionId *xids, int *n); + + inline int GetActiveSessionCount() + { + return m_activeSessionCount; + } + +private: + void recursiveSessMemCxt( + knl_session_context* sess, const MemoryContext context, Tuplestorestate* tupStore, TupleDesc tupDesc); + void calculateSessMemCxtStats( + knl_session_context* sess, const MemoryContext context, Tuplestorestate* tupStore, TupleDesc tupDesc); + + inline bool IsValidCtrlIndex(int ctrl_index) + { + if (ctrl_index < m_maxReserveSessionCount || ctrl_index - m_maxReserveSessionCount >= m_maxActiveSessionCount) { + ereport(WARNING, + (errmsg("Invalid session control index %d, " + "maxReserveSessionCount %d, m_maxActiveSessionCount %d", + ctrl_index, + m_maxReserveSessionCount, + m_maxActiveSessionCount))); + return false; + } else { + return true; + } + } + +private: + /* session id generate */ + uint64 m_sessionId; + /* current session count. */ + volatile int m_activeSessionCount; + /* max session count we can accept. */ + int m_maxActiveSessionCount; + int m_maxReserveSessionCount; + /* session control structure. */ + knl_sess_control* m_base; + Dllist m_freelist; + Dllist m_activelist; + pthread_mutex_t m_sessCtrlock; + + MemoryContext m_context; +}; + +#endif /* THREAD_POOL_SESSION_CONTROL_H */ diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_stream.h postgresql-hll-2.14/include/threadpool/threadpool_stream.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_stream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_stream.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- +* +* threadpool_stream.h +* stream thread pool Interface +* +* Portions Copyright (c) 2020 Huawei +* IDENTIFICATION +* src/include/distributelayer/threadpool_stream.h +* +* NOTES +* +* ------------------------------------------------------------------------- +*/ + +#ifndef THREAD_POOL_STREAM_H +#define THREAD_POOL_STREAM_H + +#ifdef ENABLE_MULTIPLE_NODES + +#include "knl/knl_variable.h" + +class ThreadPoolStream : public BaseObject { +public: + ThreadPoolStream(); + ~ThreadPoolStream(); + int StartUp(int idx, StreamProducer* producer, ThreadPoolGroup* group, + pthread_mutex_t* mutex, pthread_cond_t* cond); + void WaitMission(); + void WakeUpToWork(StreamProducer* producer); + void WakeUpToUpdate(ThreadStatus status); + void CleanUp(); + void ShutDown(); + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + + inline ThreadId GetThreadId() + { + return m_tid; + } + + inline StreamProducer* GetProducer() + { + return m_producer; + } + +private: + void InitStream(); + +private: + int m_idx; + ThreadId m_tid; + Dlelem m_elem; + ThreadStatus m_threadStatus; + StreamProducer* m_producer; + ThreadPoolGroup* m_group; + + pthread_mutex_t* m_mutex; + pthread_cond_t* m_cond; +}; + +#endif +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/threadpool/threadpool_worker.h postgresql-hll-2.14/include/threadpool/threadpool_worker.h --- postgresql-hll-2.14_old/include/threadpool/threadpool_worker.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/threadpool/threadpool_worker.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,146 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * threadpool_worker.h + * ThreadPoolWorker will get an active session from ThreadPoolListener, + * read command from the session and execute the command. This class is + * also response to init and free session. + * + * IDENTIFICATION + * src/include/threadpool/threadpool_worker.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef THREAD_POOL_WORKER_H +#define THREAD_POOL_WORKER_H + +#include "lib/dllist.h" +#include "knl/knl_variable.h" + +#define THRD_SIGTERM 0x00000001 +#define THRD_EXIT 0x00000010 +extern void SetThreadLocalGUC(knl_session_context* session); +/* + * List of active backends (or child processes anyway; we don't actually + * know whether a given child has become a backend or is still in the + * authorization phase). This is used mainly to keep track of how many + * children we have and send them appropriate signals when necessary. + * + * "Special" children such as the startup, bgwriter and autovacuum launcher + * tasks are not in this list Autovacuum worker and walsender processes are + * in it. Also, "dead_end" children are in it: these are children launched just + * for the purpose of sending a friendly rejection message to a would-be + * client. We must track them because they are attached to shared memory, + * but we know they will never become live backends. dead_end children are + * not assigned a PMChildSlot. + */ +typedef struct Backend { + ThreadId pid; /* process id of backend */ + long cancel_key; /* cancel key for cancels for this backend */ + int child_slot; /* PMChildSlot for this backend, if any */ + bool is_autovacuum; /* is it an autovacuum process? */ + volatile bool dead_end; /* is it going to send an quit? */ + volatile int flag; + Dlelem elem; /* list link in BackendList */ +} Backend; + +typedef enum { + THREAD_UNINIT = 0, + THREAD_RUN, + THREAD_PENDING, + THREAD_EXIT, // set by PM , as PM down. +} ThreadStatus; + +typedef enum { + TWORKER_HOLDSESSIONLOCK = 0, + TWORKER_TWOPHASECOMMIT, + TWORKER_HOLDLWLOCK, + TWORKER_GETNEXTXID, + TWORKER_STILLINTRANS, + TWORKER_UNCONSUMEMESSAGE, + TWORKER_CANSEEKNEXTSESSION, + TWORKER_PREDEADSESSION +} ThreadStayReason; + +class ThreadPoolGroup; +class ThreadPoolWorker : public BaseObject { +public: + ThreadPoolWorker(uint idx, ThreadPoolGroup* group, pthread_mutex_t* mutex, pthread_cond_t* m_cond); + ~ThreadPoolWorker(); + int StartUp(); + void ShutDown(); + void NotifyReady(); + void WaitMission(); + void CleanUpSession(bool threadexit); + void CleanUpSessionWithLock(); + bool WakeUpToWork(knl_session_context* session); + void WakeUpToUpdate(ThreadStatus status); + + friend class ThreadPoolListener; + + inline knl_session_context* GetAttachSession() + { + return m_currentSession; + } + + inline ThreadPoolGroup* GetGroup() + { + return m_group; + } + + inline ThreadId GetThreadId() + { + return m_tid; + } + + inline void SetSession(knl_session_context* session) + { + m_currentSession = session; + } + + static Backend* CreateBackend(); + static void AddBackend(Backend* bn); + +public: + volatile int m_waitState; + +private: + void CleanThread(); + bool AttachSessionToThread(); + void DetachSessionFromThread(); + void WaitNextSession(); + bool InitPort(Port* port); + void FreePort(Port* port); + void Pending(); + void ShutDownIfNecessary(); + void RestoreSessionVariable(); + void RestoreThreadVariable(); + void RestoreLocaleInfo(); + void SetSessionInfo(); + +private: + ThreadId m_tid; + uint m_idx; + knl_session_context* m_currentSession; + volatile ThreadStatus m_threadStatus; + ThreadStayReason m_reason; + Dlelem m_elem; + ThreadPoolGroup* m_group; + pthread_mutex_t* m_mutex; + pthread_cond_t* m_cond; +}; + +#endif /* THREAD_POOL_WORKER_H */ diff -uprN postgresql-hll-2.14_old/include/tsan_annotation.h postgresql-hll-2.14/include/tsan_annotation.h --- postgresql-hll-2.14_old/include/tsan_annotation.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsan_annotation.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,38 @@ +#ifndef TSAN_ANNOTATION_H +#define TSAN_ANNOTATION_H + +#ifdef ENABLE_THREAD_CHECK +extern "C" { + void AnnotateHappensBefore(const char *f, int l, uintptr_t addr); + void AnnotateHappensAfter(const char *f, int l, uintptr_t addr); + void AnnotateRWLockCreate(char *f, int l, uintptr_t m); + void AnnotateRWLockDestroy(char *f, int l, uintptr_t m); + void AnnotateRWLockAcquired(char *f, int l, uintptr_t m, uintptr_t is_w); + void AnnotateRWLockReleased(char *f, int l, uintptr_t m, uintptr_t is_w); + void AnnotateBenignRaceSized(char *f, int l, uintptr_t m, uintptr_t size, char *desc); + void AnnotateReadBarrier(); + void AnnotateWriteBarrier(); +} +#define TsAnnotateHappensBefore(addr) AnnotateHappensBefore(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateHappensAfter(addr) AnnotateHappensAfter(__FILE__, __LINE__, (uintptr_t)addr) +#define TsAnnotateRWLockCreate(m) AnnotateRWLockCreate(__FILE__, __LINE__, (uintptr_t)m) +#define TsAnnotateRWLockDestroy(m) AnnotateRWLockDestroy(__FILE__, __LINE__, (uintptr_t)m) +#define TsAnnotateRWLockAcquired(m, is_w) AnnotateRWLockAcquired(__FILE__, __LINE__, (uintptr_t)m, is_w) +#define TsAnnotateRWLockReleased(m, is_w) AnnotateRWLockReleased(__FILE__, __LINE__, (uintptr_t)m, is_w) +#define TsAnnotateBenignRaceSized(m, size) AnnotateBenignRaceSized(__FILE__, __LINE__, (uintptr_t)m, size, NULL) +#define TsAnnotateWriteBarrier() AnnotateWriteBarrier() +#define TsAnnotateReadBarrier() AnnotateReadBarrier() +#else +#define TsAnnotateHappensBefore(addr) +#define TsAnnotateHappensAfter(addr) +#define TsAnnotateRWLockCreate(m) +#define TsAnnotateRWLockDestroy(m) +#define TsAnnotateRWLockAcquired(m, is_w) +#define TsAnnotateRWLockReleased(m, is_w) +#define TsAnnotateBenignRaceSized(m, size) +#define TsAnnotateWriteBarrier() +#define TsAnnotateReadBarrier() + +#endif /* endif ENABLE_THREAD_CHECK */ + +#endif // TSAN_ANNOTATION_H diff -uprN postgresql-hll-2.14_old/include/tsdb/cache/part_cachemgr.h postgresql-hll-2.14/include/tsdb/cache/part_cachemgr.h --- postgresql-hll-2.14_old/include/tsdb/cache/part_cachemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/cache/part_cachemgr.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,114 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * part_cachemgr.h + * Cache manager of part item + * + * IDENTIFICATION + * src/include/tsdb/cache/part_cachemgr.h + * + * ------------------------------------------------------------------------- + */ + +/************************************************************************* +* PartMgr cache pg_class cudesc oid to avoid conflict * +*************************************************************************/ + +#ifndef TSDB_PART_CACHEMGR_H +#define TSDB_PART_CACHEMGR_H + +#include "storage/cu.h" +#include "utils/hsearch.h" +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "access/htup.h" + +namespace Tsdb { +struct PartItem { + Oid cudesc_oid; + HeapTuple cudesc_tuple; + TupleDesc tuple_desc; + HeapTuple index_cudesc_tuple; + TupleDesc index_tuple_desc; + HeapTuple pg_index_tuple; + pg_atomic_uint32 disable_flag; + pg_atomic_uint32 ref_count; +}; + +struct CacheKey { + Oid partition_oid; +}; +struct CacheEntry { + CacheKey key; + List *part_items; /* element is PartItem */ + + void set_key(Oid partition_id) { + this->key.partition_oid = partition_id; + part_items = NIL; + }; +}; + +struct UncommittedEntry { + uint64 query_id; + List* to_committed_entries; // list of CacheEntry +}; + + +class PartCacheMgr { +public: + static PartCacheMgr& GetInstance() + { + static PartCacheMgr cudesc_oid_cache; + return cudesc_oid_cache; + } + void init(); + void add_cudesc_item(Oid partition_oid, Oid new_cudesc_oid); + void remove_cudesc_item(Oid partition_oid, List* remove_oids); + List* get_cudesc_item(Oid partition_oid); + void build_partition(Oid partition_oid); + void refresh_part_item_cache(Oid partition_oid, Oid new_desc_oid, List* remove_oids); + void clear_cache(); + void clear_partition_cache(Oid partition); + void release_part_items(Oid partition_oid, List* cudesc_oids); + List* filter_removed_part(Oid partition_oid, List* removed_parts); + void commit_item(); + void abort_item(); + static PartItem** search_cached_cudesc(Oid partition_id, int& count); + static void free_part_item(PartItem* item); + static void free_cudesc_items(List* part_items); + bool is_cudesc_exist(Oid partition_oid, Oid cudesc_oid); +private: + PartCacheMgr(); + ~PartCacheMgr(); + void clean_part_list(List* part_list); + List* build_cudesc_item(CacheEntry* entry, Oid cudesc_oid); + List* remove_part_items_inner(List* part_items, List* cudesc_oids); + List* get_valid_parts(List* part_items) const; + void disable_part_items(List* part_items, const List* cudesc_oids); + + void add_uncommitted_item(uint64 query_id, Oid partition_oid, Oid new_cudesc_oid); + void init_uncommitted_cache(); + HTAB* create_hash_cache(Size key_size, Size entry_size, const char* name, HashValueFunc func); + + HTAB* cache; + HTAB* uncommitted_cache; + MemoryContext part_cache_memctx; + const char* MEMORY_CTX_NAME = "PART_CACHE_CONTEXT"; + const char* UNCOMMITTED_CACHE_NAME = "PART_UNCOMMITED_CACHE"; + const uint32 max_part_key = 1024; // max numbre of cached paritions + const uint32 min_part_key = 256; // min numbre of cached paritions +}; +} +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsdb/cache/partid_cachemgr.h postgresql-hll-2.14/include/tsdb/cache/partid_cachemgr.h --- postgresql-hll-2.14_old/include/tsdb/cache/partid_cachemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/cache/partid_cachemgr.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,88 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * partid_cachemgr.h + * Cache manager of partid + * + * IDENTIFICATION + * src/include/tsdb/cache/partid_cachemgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_PARTID_CACHEMGR_H +#define TSDB_PARTID_CACHEMGR_H + +#include "utils/relcache.h" +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "tsdb/utils/constant_def.h" + +/************************************************************************* +* PartIdMgr * +*************************************************************************/ +typedef struct { + RelFileNode partition_rnode; +} PartKey; + +/* + * partid = first_partid + (id_bitmap_idx + 1) * 2 this partid is for partrel, for part index rel, its partid is + * partrel_partid + 1, the partid must be an even number + * because partid is used for compaction and insert, and we must guarantee the compaction speed, so we should left + * enough partid for compaction + */ +typedef struct { + PartKey key; + int16 id_count; /* already used partid count */ + int16 id_bitmap[TsConf::MAX_PART_NUM]; /* if id_bitmap[idx] = 0, means this partid can be used to insert */ +} PartIdEntry; + +/* + * one cu has one partid, the cu file name contains the partid, and the compaction will merge the cudesc, + * so the partid will be changed, if insert is too frequently while compaction is limited on case when + * ts_consumer_workers is too small, the partid will be used up, and raise error + * partid is cu_id of the tuples in cudescrel when col_id = -12 + */ +class PartIdMgr { +public: + static PartIdMgr& GetInstance() + { + static PartIdMgr partid_cache; + return partid_cache; + } + void init(); + void reset(); + void clear(); + void build(Relation relation); + PartNumber next_part_id(const Relation relation, bool is_compaction); + void free_part_id(RelFileNode* rnode, PartNumber part_id); + +private: + void partid_map_set(PartIdEntry* entry, PartNumber partid, uint16 flag); + bool find_free_partid(PartIdEntry* entry, PartNumber& partid); + bool check_partid_enough(PartIdEntry* entry, bool is_compaction); + void clear_partid_map(PartIdEntry* entry); + void set_part_id_used(Relation partiton_rel, Oid cudesc_id); + PartIdMgr(); + ~PartIdMgr(); + + MemoryContext partid_cache_mem; + HTAB* cache; + slock_t partid_lock; + const uint32 max_part_key = 1024; // max number of cached paritions + const uint32 min_part_key = 256; // min number of cached paritions + static const PartNumber first_partid = 2000; // partid start from 2000 +}; +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsdb/cache/queryid_cachemgr.h postgresql-hll-2.14/include/tsdb/cache/queryid_cachemgr.h --- postgresql-hll-2.14_old/include/tsdb/cache/queryid_cachemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/cache/queryid_cachemgr.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,69 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * queryid_cachemgr.h + * Cache manager of queryid + * + * IDENTIFICATION + * src/include/tsdb/cache/tags_cachemgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_QUERYID_CACHEMGR_H +#define TSDB_QUERYID_CACHEMGR_H + +#include "utils/relcache.h" +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "tsdb/utils/constant_def.h" + +namespace Tsdb { +typedef enum RelStatus { + IN_COMPACTION, + IN_DELETION, + INVALID_STATUS +} RelStatus; + +typedef struct { + uint64 query_id; + RelStatus status; +} DeleteEntry; + +class TableStatus { +public: + static TableStatus& GetInstance() + { + static TableStatus table_statue; + return table_statue; + } + bool is_in_deletion() const; + void init(); + void add_query(uint64 query_id); + void remove_query(); + void clear(); + +private: + TableStatus(); + ~TableStatus(); + RelStatus status = INVALID_STATUS; + MemoryContext delete_status_cache_mem; + HTAB* cache; + const char* TABLE_DELETE_NAME = "Timeries Delete Status Cache"; + int count; +}; +} + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsdb/cache/tabinfo_cachemgr.h postgresql-hll-2.14/include/tsdb/cache/tabinfo_cachemgr.h --- postgresql-hll-2.14_old/include/tsdb/cache/tabinfo_cachemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/cache/tabinfo_cachemgr.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,72 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * tabinfo_cachemgr.h + * Cache manager of queryid + * + * IDENTIFICATION + * src/include/tsdb/cache/tabinfo_cachemgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_QUERYID_CACHEMGR_H +#define TSDB_QUERYID_CACHEMGR_H + +#include "utils/relcache.h" +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "tsdb/utils/constant_def.h" + +namespace Tsdb { +typedef struct TabInfoKey { + Oid database_oid; + Oid rel_oid; + Oid partition_oid; +} TabInfoKey; + +typedef struct TabInfoEntry { + TabInfoKey tab_key; + List* cudesc_oid_list; +} TabInfoEntry; + +class TableInfo { +public: + static TableInfo& GetInstance() + { + static TableInfo table_info; + return table_info; + } + void init(); + void clear(); + void reset_partition_list(); + void destroy(); + List *get_cudesc_task_list(Oid database_id, Oid rel_oid, Oid partition_oid); + void put_all_cudesc(Oid partition_oid, Oid cudesc_oid); + void put_one_table(Oid database_oid, Oid rel_oid, Oid partition_oid); + TabInfoEntry* search(Oid database_oid, Oid rel_oid, Oid partition_oid, bool* found); + void union_cudesc_list(List* cudesc_list); + +private: + TableInfo(); + ~TableInfo(); + List* filter_task_list(TabInfoEntry* tab_entry, List *part_cudescrel_list); + static const int HASHCOUNT = 64; + HTAB* tab_info_hash; + TabInfoEntry* m_tab_entry; +}; +} + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsdb/cache/tags_cachemgr.h postgresql-hll-2.14/include/tsdb/cache/tags_cachemgr.h --- postgresql-hll-2.14_old/include/tsdb/cache/tags_cachemgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/cache/tags_cachemgr.h 2020-12-12 17:06:43.385349819 +0800 @@ -0,0 +1,102 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * tags_cachemgr.h + * Cache manager of tags table + * + * IDENTIFICATION + * src/include/tsdb/cache/tags_cachemgr.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TAGS_CACHEMGR_H +#define TSDB_TAGS_CACHEMGR_H + +#include "utils/relcache.h" +#include "utils/hsearch.h" +#include "storage/relfilenode.h" +#include "tsdb/utils/constant_def.h" + +class Tags; + +typedef struct { + RelFileNode m_rnode; + /* + * concat all the relation name and tag value as key, format is + * because tagrel schema always is cstore, so this can guarantee unique + * if the key length is more than MAX_TAGS_STRING_LEN, we cannot get the tag from tagcache, get from tagrel, + * open the tagrel and get the tagid from tag index + */ + char tags[TsConf::MAX_TAGS_STRING_LEN]; +} TagsKey; + +typedef struct { + TagsKey key; + Oid tagid; +} TagsEntry; + +/* + * tags cache is used TagsKey as key, get the tagid by tag value, under insert, we can get all the tag value, + * and can fastly get the tagid by this cache + */ +typedef RelFileNode TsStoreTagFileNode; +typedef struct { + TsStoreTagFileNode tag; + Oid max_tag_id; +} TsStoreFileDesc; + +class TagsCacheMgr { +public: + static TagsCacheMgr& GetInstance() + { + static TagsCacheMgr tags_cache_mgr; + return tags_cache_mgr; + } + + void init(); + void reset(); + void clear(); + Oid search(const Tags& tags, Relation relation); + + void build_tagid_cache(Relation relation); + Oid get_next_tagid(const Relation relation); + +private: + TagsCacheMgr() : tags_cache_memctx(nullptr), tags_cache(nullptr), max_tagid_cache(nullptr) {}; + ~TagsCacheMgr(); + void calc_buf_size(uint64& min_size, uint64& max_size) const; + void refresh(); + char* convert_to_string(Oid typid, Datum value); + Oid get_tagid_from_cache(const Tags& tags, Relation relation, bool* need_in_cache, TagsKey& key); + void add_cache(Oid tagid, const TagsKey& key, Relation relation); + void init_tagid_cache(); + + MemoryContext tags_cache_memctx; + + /* stores tags, map pair is */ + HTAB* tags_cache; + const int eliminate_num = 10; + + /* + * the tag id record, only record one current max tagid, hash cache key is tagrel relfilenode, value is max tagid + * entry is TsStoreFileDesc, fastly get the next tagid under insert + */ + HTAB* max_tagid_cache; + slock_t tagId_lock; + const char* TAG_ID_CACHE_NAME = "TsStore max tag id cache"; +}; + +#endif /* TSDB_TAGS_CACHEMGR_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/common/data_row.h postgresql-hll-2.14/include/tsdb/common/data_row.h --- postgresql-hll-2.14_old/include/tsdb/common/data_row.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/common/data_row.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,169 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * data_row.h + * class for data row vectors + * + * IDENTIFICATION + * src\include\tsdb\common\data_row.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DATA_ROW_H +#define TSDB_DATA_ROW_H + +#include "executor/tuptable.h" +#include "utils/numeric.h" +#include "utils/timestamp.h" + +class Time : public BaseObject { +public: + Time(); + ~Time(); + int column; + bool isnull; + TimestampTz timestamp; +}; + +/* one tag object is one cell of tag table */ +class Tag : public BaseObject { +public: + Tag(); + ~Tag(); + void build(int column, const NameData attname, Datum v, int2 attlen, bool isnull); + + int column; // attribute number of tag table (no tag_id column, start from a of tagrel) + NameData key; + Datum value; + int2 m_attlen; + bool isnull; +}; + +/* + * one tags object is one line of tag table + */ +class Tags : public BaseObject { +public: + Tags(int capacity); + ~Tags(); + Tag* get_tag_by_key(const NameData& key, int* pos = NULL) const; + bool add_tag(int column, const NameData attname, Datum v, int2 attlen, bool isnull); + + Tag** tags; + int count; + int capacity; +}; + +class TagRow : public BaseObject { +public: + TagRow(int attrs); + ~TagRow(); + + Tags* tags; + Oid tag_id; +}; + +/* one TagRows object contains 'row_count' lines of TagRow */ +class TagRows : public BaseObject { +public: + TagRows(MemoryContext memcxt, size_t cap); + ~TagRows(); + void Init(); + void Reset(); + bool IsEmpty() const; + bool IsFull() const; + void AddTagRow(TupleTableSlot* tag_slot); + void Sort(); + TagRow* SearchSortedById(Oid tag_id); + void AddTagRow(TagRow* tagrow); + + MemoryContext memcxt; + TagRow** tag_row_array; + size_t row_count; + /* capacity * sizeof(TagRow*) is memory size we alloc to tag_row_array */ + size_t capacity; +private: + void QuickSort(size_t l, size_t r); +}; + +class TimeRange : public BaseObject { +public: + TimestampTz start_timestamp; + TimestampTz end_timestamp; +}; + +/* the Field is one record of tsfield, usually be numeric, number, text */ +class Field : public BaseObject { +public: + Field(); + ~Field(); + void build(int column, Datum value, int2 attlen, bool isnull, bool copy = true); + void build(const Field& field); + bool is_null() const; + + int column; + Datum field_value; + int2 m_attlen; + bool isnull; +}; + +/* one row of tsfield, tagid and timestamp, used to generate cudesc */ +class DataRow : public BaseObject { +public: + DataRow(); + ~DataRow(); + void add_tag_id(Oid tag_id); + void add_timestamp(int column, TimestampTz timestamp, bool isnull); + void set_size(int size); + bool add_field(int column, Datum value, int2 attlen, bool isnull, bool copy = true); + bool add_field(const Field& field); + void copy_data(const DataRow& data_row); + void shallow_copy_data(const DataRow& data_row); + void shallow_copy_datarow(const DataRow& data_row); + + Oid tag_id; + Field* fields; + int size; /* the length of fields, use API set_size to set it, usually is column number */ + int cur_field_index; /* current index of fields, should be less than size */ + Time time; +}; + +class DataRowVector : public BaseObject { +public: + DataRowVector() : data_row(NULL), mem_context(NULL), capacity(0), count(0) {} + DataRowVector(int capacity, MemoryContext mem_context); + ~DataRowVector(); + void add_data_row(const DataRow& data_row); + int get_count() const; + DataRow* get_by_idx(int idx); + void reset_data_rows_field(); + bool is_empty() const; + bool is_full() const; + void clear(); + void reset(); + void sort(); + + DataRow* data_row; + MemoryContext mem_context; + int capacity; + int count; + +private: + void merge_sort(int start, int end); + void merge(int start, int middle, int end); +}; + +#endif /* TSDB_DATA_ROW_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/common/data_row_transform.h postgresql-hll-2.14/include/tsdb/common/data_row_transform.h --- postgresql-hll-2.14_old/include/tsdb/common/data_row_transform.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/common/data_row_transform.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * data_row_transform.h + * functions for nodes collect info + * + * IDENTIFICATION + * src\include\tsdb\common\data_row_transform.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DATA_ROW_TRANSFORM_H +#define TSDB_DATA_ROW_TRANSFORM_H + +#include "utils/relcache.h" +#include "access/htup.h" + +class DataRow; + +class DataRowTransform { +public: + static void pack(Datum* values, const bool* nulls, Relation relation, DataRow* dest_address, int options); +}; + +#endif /* TSDB_DATA_ROW_TRANSFORM_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/common/delta_ctlg.h postgresql-hll-2.14/include/tsdb/common/delta_ctlg.h --- postgresql-hll-2.14_old/include/tsdb/common/delta_ctlg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/common/delta_ctlg.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,39 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * delta_ctlg.h + * catalog related interfaces of timeseries delta feature + * + * IDENTIFICATION + * src/include/tsdb/common/delta_ctlg.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DELTA_CTLG_H +#define TSDB_DELTA_CTLG_H + +#include "access/xact.h" +#include "utils/relcache.h" + +namespace Tsdb { + extern void CreateDeltaObjects(Relation ts_rel, int deltamerge_interval); + extern void ATDeltaReloptions(Relation ts_rel, const List* defList); + extern void DeleteDeltaByPartition(Snapshot snapshot, Relation ts_rel, Oid partition_id); + extern void UpdateDeltaMergeJobWhat(Relation ts_rel, const char* new_relname); + extern void CancelDeltaMergeJob(Relation ts_rel); +} /* namespace Tsdb */ + +#endif /* TSDB_DELTA_CTLG_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/common/ts_tablecmds.h postgresql-hll-2.14/include/tsdb/common/ts_tablecmds.h --- postgresql-hll-2.14_old/include/tsdb/common/ts_tablecmds.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/common/ts_tablecmds.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * ts_tablecmds.h + * functions for create timeseries table + * + * IDENTIFICATION + * src\include\tsdb\common\ts_tablecmds.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_TABLECMDS_H +#define TSDB_TS_TABLECMDS_H +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +struct TupleDescEntry { + AttrNumber att_num; + const char* att_name; + Oid type_oid; + int32 type_mode; + int32 att_dim; +}; + +extern Oid create_tscudesc_table(Oid partition_id, Relation ts_rel); +extern void create_tscudesc_index(const Oid cudesc_oid, const Oid partition_oid); +extern void create_tag_index(Oid tag_relid, const char* tag_relname, List* index_col_names); +extern void create_ts_store_tables(Oid ts_relid, Datum toast_reloptions); +extern Oid get_tag_relid(Oid ts_relid); +extern Oid get_tag_index_relid(const char* tag_relname); +extern int get_valid_natts_by_kvtype(const Relation ts_rel, const int1 kvtype); +extern int get_tstime_attnum_from_ts_rel(Relation ts_rel); +extern void get_ts_idx_tgt(char* relname, Oid idx_id, bool drop_idx = false, + bool ts_main_tbl = true, const char* suffix_str = NULL); +extern void check_idxcols_validation(Relation ts_rel, List* index_cols); + +#endif diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/compaction_auxiliary_entry.h postgresql-hll-2.14/include/tsdb/compaction/compaction_auxiliary_entry.h --- postgresql-hll-2.14_old/include/tsdb/compaction/compaction_auxiliary_entry.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/compaction_auxiliary_entry.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,52 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * compaction_auxiliary_entry.h + * functions for compaction_auxiliary entry + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/compaction_auxiliary_entry.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_COMPACTION_AUXILIARY_ENTRY_H +#define TSDB_COMPACTION_AUXILIARY_ENTRY_H + +#include "tsdb/utils/constant_def.h" +#include "nodes/pg_list.h" + +struct HTAB; +class CompactionAuxiliaryProcess { +public: + static void compaction_auxiliary_main(); +private: + static void compaction_auxiliary_loop(); + static bool handle_interrupt(); + static void do_search(); + static List* get_delete_list(HTAB* cudesc_hash, Oid drop_db_id); + static void remove_part_file(); + static void limit_task_speed(bool worked); + static void search_one_table(Oid database_oid, Oid rel_oid); + static void search_disabled_cudesc_table(); + static void handle_delay_ddl(); +private: + static Oid cur_db_id; + static int sleep_count; + static Oid drop_db_id; + static List* instant_delete_list; +}; + +#endif /* TSDB_COMPACTION_AUXILIARY_ENTRY_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/compaction_entry.h postgresql-hll-2.14/include/tsdb/compaction/compaction_entry.h --- postgresql-hll-2.14_old/include/tsdb/compaction/compaction_entry.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/compaction_entry.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * compaction_entry.h + * functions for compaction entry + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/compaction_entry.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_COMPACTION_ENTRY_H +#define TSDB_COMPACTION_ENTRY_H + +#include "postgres.h" +#include "gs_thread.h" + +class TaskConsumer; + +class CompactionProcess { +public: + static void compaction_main(); + static bool IsTsCompactionProcess(); + static void init_instance(); +private: + static int compaction_loop(); + static void start_compaction_workers(); + static void stop_all_workers(int code, Datum arg); + static void start_task_consumers(int number); + static TaskConsumer* start_task_consumer(int index); + static void send_end_signal_and_wait(int code); + static void send_signal_all_consumer(int signal); + static void init_memorycontext(); + static void delete_memorycontext(); + static int get_ready_consumer_count(); + static bool is_producer_can_stop(); + static void rearrange_consumers(); + static void wait_consumers_ready(); + static ThreadId create_consumer_thread(TaskConsumer* consumer); + static bool compaction_worker_increase(); + static void compaction_worker_decrease(); + static void rearrange_ready_index(TaskConsumer** ready_consumers, uint32 next_ready_index); + static void rearrange_unready_index( + TaskConsumer** unready_consumers, uint32 next_ready_index, uint32 next_unready_index); + static void flush_invalid_consumer_state(); + static int get_free_origin_id(); + static void check_alive_compaction_worker(); +}; + +#endif /* TSDB_COMPACTION_ENTRY_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/compaction_worker_entry.h postgresql-hll-2.14/include/tsdb/compaction/compaction_worker_entry.h --- postgresql-hll-2.14_old/include/tsdb/compaction/compaction_worker_entry.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/compaction_worker_entry.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * compaction_worker_entry.h + * functions for compaction worker entry + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/compaction_worker_entry.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_COMPACTION_WORKER_ENTRY_H +#define TSDB_COMPACTION_WORKER_ENTRY_H + +#include "c.h" +#include "gs_thread.h" +#include "tsdb/compaction/task_consumer.h" + +class CompactionWorkerProcess { +public: + static void compaction_consumer_main(); + static void SetConsumerThreadLocal(knl_thread_arg *arg); + static int GetMyCompactionConsumerOrignId(); +private: + static int consumer_work_loop(); + static void init_memorycontext(); + static void delete_memorycontext(); +private: + static THR_LOCAL TaskConsumer* task_consumer; +}; + +#endif /* TSDB_COMPACTION_WORKER_ENTRY_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/session_control.h postgresql-hll-2.14/include/tsdb/compaction/session_control.h --- postgresql-hll-2.14_old/include/tsdb/compaction/session_control.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/session_control.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * session_control.h + * functions for session control + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/session_control.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TSDB_SESSION_CONTROL_H +#define TSDB_SESSION_CONTROL_H + +struct knl_session_context; +#include "postgres.h" + +class SessionControl : public BaseObject { +public: + static Oid default_database_oid; + static Oid template0_oid; +public: + static void init_session(const char *db_name); + static void switch_session(Oid database_id); + static knl_session_context* create_compaction_session_context(MemoryContext parent); +private: + static void clean_session(); + static void init_session_inner(Oid database_id); + static void free_session(); +}; + +#endif /* TSDB_SESSION_CONTROL_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/signal_helper.h postgresql-hll-2.14/include/tsdb/compaction/signal_helper.h --- postgresql-hll-2.14_old/include/tsdb/compaction/signal_helper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/signal_helper.h 2020-12-12 17:06:43.386349832 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * signal_helper.h + * functions for signal helper + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/signal_helper.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TSDB_COMPACTION_SIGNAL_HELPER_H +#define TSDB_COMPACTION_SIGNAL_HELPER_H + +#include "c.h" + +class SignalHelper { +public: + static void handle_signal(); + static void handle_sighup_signal(SIGNAL_ARGS); + static void handle_shutdown(SIGNAL_ARGS); + static void handle_quick_die(SIGNAL_ARGS); +}; + +#endif /* TSDB_COMPACTION_SIGNAL_HELPER_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/task_consumer.h postgresql-hll-2.14/include/tsdb/compaction/task_consumer.h --- postgresql-hll-2.14_old/include/tsdb/compaction/task_consumer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/task_consumer.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * task_consumer.h + * functions for task consumer + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/task_consumer.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TSDB_COMPACTION_TASK_CONSUMER_H +#define TSDB_COMPACTION_TASK_CONSUMER_H + +#include "access/parallel_recovery/spsc_blocking_queue.h" +#include "utils/relcache.h" +#include "utils/timestamp.h" +#include "utils/dynahash.h" + +class CompactionTask : public BaseObject { +public: + CompactionTask(); + ~CompactionTask(); + Oid db_oid; + Oid rel_oid; + Oid partition_oid; + int compaction_level; + List* cudesc_relid_list; +}; + +class TaskConsumer : public BaseObject { +public: + TaskConsumer(); + ~TaskConsumer(); + bool init(int index); + void poll_task(); + bool fill_task_queue(CompactionTask* task_context); + uint32 get_task_queue_count(); +public: + gs_thread_t tid; + /* original index of thread */ + int origin_id; + /* rearrange index, because of some threads start failed */ + uint32 id; + Oid cur_oid; +private: + Oid shallow_parser_task_context(Relation relation, Oid partition_oid, List* cudesc_relid_list); + void disable_partition_parts(List* cudesc_relid_list); + void limit_task_speed(bool idle); + void handle_compaction_worker_interrupts(); + void mark_compaction_level(Oid new_cudesc_oid, int compction_level); + void wait_delete_completion(); + void handle_compaction_worker_abort(); + bool is_idle(); + void clean_task_queue(); + void delete_parts(Oid rel_oid, RelFileNode* rel_node, Oid partition_oid, List* cudesc_relid_list); +private: + parallel_recovery::SPSCBlockingQueue* task_queue; + int sleep_count; +}; + +#endif /* TSDB_COMPACTION_TASK_CONSUMER_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/compaction/task_producer.h postgresql-hll-2.14/include/tsdb/compaction/task_producer.h --- postgresql-hll-2.14_old/include/tsdb/compaction/task_producer.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/compaction/task_producer.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,83 @@ +/* + * 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. + * + * task_producer.h + * functions for task producer + * + * IDENTIFICATION + * Code/src/include/tsdb/compaction/task_producer.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_COMPACTION_TASK_PRODUCER_H +#define TSDB_COMPACTION_TASK_PRODUCER_H + +#include "tsdb/compaction/task_consumer.h" +#include "utils/dynahash.h" +#include "utils/relcache.h" + +typedef struct ProducerStrategy { + int min_parts; + int max_parts; + int level_middle; + int level_max; + bool is_fuzzy; +} ProducerStrategy; + + +class TaskProducer : public BaseObject { +public: + static TaskProducer& get_instance(); + void init(); + void uninit(); + void deliver_task(); + void drop_db_handler(); + void guc_handler(); + void add_failed_task(CompactionTask* task); + ~TaskProducer(); + int get_most_vacant_consumer(int level); +public: + TaskConsumer** task_consumers; + int working_consumer_count; + bool add_thread; + ProducerStrategy* producer_strategy; + +private: + TaskProducer(); + void deliver_task_inner(Oid database_id); + void deliver_one_table_task(Oid database_id, Oid rel_oid); + void deliver_each_level_task(Oid database_oid, Oid rel_oid, Oid part_relid, List* cmp_lev_list, int task_length); + void send_task_to_consumer(Oid database_id, Oid rel_oid, Oid partition_oid, List* part_cudescrel_list, int level); + bool send_taskcontext(CompactionTask* task_context, List* temp_list, int level); + CompactionTask* generate_consumer_context(Oid database_id, Oid rel_oid, Oid partition_oid, List* task_list); + List* get_cudesc_level(List* task_list); + void delete_from_task_list(CompactionTask* task_context); + void handle_failed_task(); + void log_queue_task(); + void limit_task_speed(void); + bool handle_interrupt(); + bool is_quit(); + void init_strategy(); + void sighup_handler(); + +private: + slock_t failed_task_lock; + List* failed_task_list; + List* fuzzy_list; + bool has_task; + int sleep_count; +}; + +#endif /* TSDB_COMPACTION_TASK_PRODUCER_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/optimizer/gapfill.h postgresql-hll-2.14/include/tsdb/optimizer/gapfill.h --- postgresql-hll-2.14_old/include/tsdb/optimizer/gapfill.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/optimizer/gapfill.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,115 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gapfill.h + * the strucutre of gapfill + * + * IDENTIFICATION + * src/include/tsdb/optimizer/gapfill.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef GAPFILL_H +#define GAPFILL_H + +#include +#include +#include +#include +#include + +extern const char* FILL_FUNCTION; +extern const char* FILL_LAST_FUNCTION; +extern const char* FILL_FIRST_FUNCTION; +extern const char* FILL_AVERAGE_FUNCTION; + +Node* fill_state_create(ExtensiblePlan*); + +typedef enum FillFetchState { + FETCHED_NONE, /* initial state or initial new group state */ + FETCHED_EXIST, /* slot fetched from sub node is not NULL */ + FETCHED_FILLING, /* fill NULL slot in the last group */ + FETCHED_RETURN, /* return slot in the last group */ + FETCHED_GROUP_FILLING, /* fill NULL slot in new group */ + FETCHED_GROUP_RETURN, /* return slot in new group */ +} FillFetchState; + +typedef enum FillColumnType { + PLAIN_COLUMN, /* plain column without time_fill, fill_first, fill_last, fill_avg */ + TIME_COLUMN, /* time_fill column */ + GROUP_COLUMN, /* group by column. TIME_COLUMN appear in group by but it does't belongs to GROUP_COLUMN */ + FILL_LAST_COLUMN, /* fill_last column */ + FILL_FIRST_COLUMN, /* fill_first column */ + FILL_AVERAGE_COLUMN /* fill_avg column */ +} FillColumnType; + +typedef enum FillType { + FILL_NONE, /* only time_fill in sql statement */ + FILL_FIRST, /* only time_fill and fill_first in sql statement */ + FILL_LAST, /* only time_fill and fill_last in sql statement */ + FILL_AVERAGE /* only time_fill and fill_avg in sql statement */ +} FillType; + +typedef struct FillColumnStateBase { + FillColumnType ctype; + Oid typid; + bool typbyval; + int16 typlen; +} FillColumnStateBase; + +typedef struct FillColumnState { + FillColumnStateBase base; + Datum value; + bool isnull; +} FillColumnState; + +typedef struct FillState { + ExtensiblePlanState epstate; + Plan* subplan; + + int64 fill_start; /* start time in time_fill function */ + int64 fill_end; /* end time in time_fill function */ + int64 fill_period; /* period time in time_fill function */ + + int64 next_timestamp; + + int time_index; /* position of time column */ + TupleTableSlot* last_group_subslot; /* slot cache for new group */ + bool multigroup; /* multiple groupings */ + + int ncolumns; /* same as tupledesc->natts */ + FillColumnStateBase** columns; /* all column info in target list */ + + ProjectionInfo* pi; /* project info */ + TupleTableSlot* scanslot; + FillFetchState state; /* current state */ + + HTAB* htab_first_search; /* hash table for fill_first and fill_avg */ + HTAB* htab_last_search; /* hash table for fill_last and fill_avg */ + + FillType fill_type; /* to decide which hash table will be created */ +} FillState; + +typedef struct FillInfo { + int64 time; + TupleTableSlot* slot; +} FillInfo; + +void fill_begin(ExtensiblePlanState* node, EState* estate, int eflags); +TupleTableSlot* fill_exec(ExtensiblePlanState* node); +void fill_end(ExtensiblePlanState* node); +Datum fill_exec_expr(FillState* state, Expr* expr, bool* isnull); +void fill_state_initialize_columns(FillState* state); +#endif /* GAPFILL_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/optimizer/planner.h postgresql-hll-2.14/include/tsdb/optimizer/planner.h --- postgresql-hll-2.14_old/include/tsdb/optimizer/planner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/optimizer/planner.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * planner.h + * the head of tsdb/planner.cpp + * + * + * IDENTIFICATION + * src/include/tsdb/optimizer/planner.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TIMESERIES_PLANNER_H +#define TIMESERIES_PLANNER_H + +#include +#include + +const Timestamp ONE_HOUR_TIMESTAMP = 3600000000; +extern const char* JOIN_TS_TAG_METHOD_NAME; +extern const char* JOIN_TS_DELTA_METHOD_NAME; +extern ExtensiblePlanMethods join_ts_tag_plan_methods; +extern ExtensiblePlanMethods join_ts_delta_plan_methods; + +typedef bool (*walker)(); +typedef struct FillWalkerContext { + FuncExpr* call; + int fill_func_calls; + int fill_last_func_calls; + int fill_first_func_calls; + int fill_avg_func_calls; + int column_calls; +} FillWalkerContext; + +typedef struct TSDBWalkerContext { + double limit; + AttrNumber sort_by_time_colidx; + bool is_simple_scan; + int series_func_calls; + int top_key_func_arg; + int tsstore_scan_calls; + int cstore_scan_calls; + bool has_sort; + int sortOperators; +} TSDBWalkerContext; + +typedef struct TsStoreScanContext { + Plan* grand_plan; + List* parent_plans; +} TsStoreScanContext; + +extern bool fill_function_call_walker(Node* node, FillWalkerContext* context); +extern bool ts_function_call_walker(FuncExpr* node, TSDBWalkerContext* context); +extern Plan* tsdb_modifier(PlannerInfo* root, List* tlist, Plan* custom_plan); +extern List* tsdb_subtlist_modifier(List* tlist); +extern void tsdb_set_rel_pathlist_hook(PlannerInfo*, RelOptInfo*, Index, RangeTblEntry*); +extern bool tsdb_optimize_walker(Plan* node, TSDBWalkerContext* context); +extern bool tsstore_preprocess(Node* node, void* rtables); + +extern Oid get_meta_rel_oid(Oid ts_rel_oid, bool is_tag); +#endif /* TIMESERIES_PLANNER_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/optimizer/policy.h postgresql-hll-2.14/include/tsdb/optimizer/policy.h --- postgresql-hll-2.14_old/include/tsdb/optimizer/policy.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/optimizer/policy.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/optimizer/policy.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_POLICY_H +#define TSDB_POLICY_H + +#include "utils/relcache.h" +#include "nodes/parsenodes.h" + +extern void update_rel_job_owner(Oid relid, Oid new_owner_id, LOCKMODE lockmode); +extern void alter_part_policy_if_needed(Relation rel, List* defList); +extern void create_part_policy_if_needed(CreateStmt* stmt, Oid relOid); +extern void recreate_part_policy_if_needed(RenameStmt* stmt); + +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/cudesc_merge_reader.h postgresql-hll-2.14/include/tsdb/storage/cudesc_merge_reader.h --- postgresql-hll-2.14_old/include/tsdb/storage/cudesc_merge_reader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/cudesc_merge_reader.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,156 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * cudesc_merge_reader.h + * functions for min heap + * + * IDENTIFICATION + * Code/src/include/tsdb/storage/cudesc_merge_reader.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_MIN_HEAP_H +#define TSDB_MIN_HEAP_H + +#include "utils/relcache.h" +#include "storage/cu.h" +#include "tsdb/storage/part.h" + +struct LoadTSCUDescCtl : public BaseObject { + uint32 cur_read_idx; + uint32 total_load_num; + uint32 next_cuid; + uint32 next_tagid; + Tsdb::TsCUDesc* tscudesc_array; + + LoadTSCUDescCtl(uint32 start_tagid, uint32 start_cuid) + { + Reset(start_tagid, start_cuid); + tscudesc_array = (Tsdb::TsCUDesc*)palloc0(sizeof(Tsdb::TsCUDesc) * u_sess->attr.attr_storage.max_loaded_cudesc); + for (int i = 0; i < u_sess->attr.attr_storage.max_loaded_cudesc; i++) { + tscudesc_array[i].cudesc = (CUDesc*)palloc0(sizeof(CUDesc)); + } + } + + virtual ~LoadTSCUDescCtl() + {} + + virtual void Destroy() + { + if (tscudesc_array != NULL) { + for (int i = 0; i < u_sess->attr.attr_storage.max_loaded_cudesc; i++) { + pfree_ext(tscudesc_array[i].cudesc); + } + pfree(tscudesc_array); + tscudesc_array = NULL; + } + } + + inline bool HasFreeSlot() + { + return total_load_num < (uint32)u_sess->attr.attr_storage.max_loaded_cudesc; + } + + inline void Reset(uint32 start_tagid, uint32 start_cuid) + { + cur_read_idx = 0; + total_load_num = 0; + next_cuid = start_cuid; + next_tagid = start_tagid; + } + + inline Tsdb::TsCUDesc* read_next() + { + return &tscudesc_array[cur_read_idx++]; + } + + inline bool need_reload() + { + return cur_read_idx == total_load_num; + } + + inline Tsdb::TsCUDesc* get_by_idx(uint32 idx) { + return &tscudesc_array[idx]; + } +}; + +struct ColCUDesc : public BaseObject{ + int col_id; + CUDesc cudesc; + CU* cu_ptr; + LoadTSCUDescCtl* tscudesc_ctl; +}; + +class FieldTimeCuDescBlock : public BaseObject { +public: + Oid tag_id; + int field_num; + ColCUDesc* field_cudescs; + ColCUDesc time_cudesc; +public: + void init_tscudesc_ctl(); + void destroy_tscudesc_ctl(); + + bool need_reload(); + uint32 next_load_tagid(); + void last_time_pos(uint32& tagid, uint32& cuid); + void last_field_pos(int field_idx, uint32& tagid, uint32& cuid); + Tsdb::TsCUDesc* next_time_cudesc(); + Tsdb::TsCUDesc* next_field_cudesc(int field_idx); + uint32 get_time_loaded_num(); + bool block_loaded_over(); +}; + +class FieldTimeBlock: public BaseObject { +public: + CU *field_cu; + CU *time_cu; + int size; + int row_count; + Oid tag_id; + int col_id; +}; + +class CudescReader : public BaseObject { +public: + bool next_cudesc_block(); +public: + FieldTimeCuDescBlock cudesc_block; + Relation cudesc_rel; +private: + void load_cudesc(); + void load_time_tscudesc(Relation idex_rel); + void load_field_tscudesc(Relation idx_rel); + +}; + +class CudescReaderMinHeap : public BaseObject { +public: + CudescReaderMinHeap(CudescReader* elements, int max_size); + CudescReader* top(); + CudescReader* pop(); + bool is_empty(); + void insert(CudescReader* elements); +private: + void fix_up_min_heap(int i); + void fix_down_min_heap(int i); + static bool compare(CudescReader *left, CudescReader *right); +private: + int current_size; + int max_size; + CudescReader* heap; +}; +#endif /* TSDB_MIN_HEAP_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/delta_converter.h postgresql-hll-2.14/include/tsdb/storage/delta_converter.h --- postgresql-hll-2.14_old/include/tsdb/storage/delta_converter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/delta_converter.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * delta_converter.h + * help convert delta tuples to other formats + * + * IDENTIFICATION + * src/include/tsdb/storage/delta_converter.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DELTA_CONVERTER_H +#define TSDB_DELTA_CONVERTER_H + +#include "c.h" +#include "gs_threadlocal.h" +#include "access/tupdesc.h" +#include "tsdb/common/data_row.h" +#include "utils/palloc.h" +#include "utils/relcache.h" + +namespace Tsdb { + class DeltaConverter : public BaseObject { + public: + DeltaConverter(Relation ts_rel, Relation delta_rel, MemoryContext memcxt); + ~DeltaConverter(); + void Init(); + void Destroy(); + void DeltaTupleToDataRow(HeapTuple delta_tup, bool copy, DataRow* datarow); + private: + Relation ts_rel; + Relation delta_rel; + TupleDesc ts_tupdesc; + TupleDesc delta_tupdesc; + + MemoryContext memcxt; + + /* tag_id column's index in delta rel */ + int tag_id_idx; + /* time column's index in delta rel */ + int time_idx; + /* from delta attr index to timeseries attr index */ + int* index_map; + }; +} /* namespace Tsdb */ +#endif /* TSDB_DELTA_CONVERTER_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/delta_insert.h postgresql-hll-2.14/include/tsdb/storage/delta_insert.h --- postgresql-hll-2.14_old/include/tsdb/storage/delta_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/delta_insert.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,79 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * delta_insert.h + * data copy/insert related interfaces of timeseries delta feature + * + * IDENTIFICATION + * src/include/tsdb/storage/delta_insert.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DELTA_INSERT_H +#define TSDB_DELTA_INSERT_H + +#include "c.h" +#include "gs_threadlocal.h" +#include "tsdb/common/data_row.h" +#include "tsdb/storage/delta_converter.h" +#include "utils/palloc.h" +#include "utils/relcache.h" + +namespace Tsdb { + /* + * @description: DeltaInsertContext is the context for data copy operation. + * It will be constructed in TsStoreInsert if the delta feature is enabled. + */ + class DeltaInsertContext : public BaseObject { + public: + DeltaInsertContext(Relation ts_rel, MemoryContext memcxt); + ~DeltaInsertContext(); + void Init(); + void Destroy(); + + bool CacheTuple(Datum* ts_vals, bool* ts_nulls); + void FlushTuples(); + + const size_t GetCacheCapacity() const; + void ResetCache(); + void BuildDataRowFromDelta(size_t i, DataRow* data_row); + + private: + void InitCache(); + void DestroyCache(); + + void InitDeltaRels(); + void DestroyDeltaRels(); + + HeapTuple TimeseriesTupleToDeltaTuple(Datum* ts_vals, bool* ts_nulls); + + MemoryContext memcxt; + Relation ts_rel; + Relation delta_rel; + Relation delta_idx_rel; + + /* alloc once, reuse in the whole lifecycle, storing one tuple during inserting */ + Datum* delta_vals; + bool* delta_nulls; + + HeapTuple* cached_tups; + size_t cached_rowcnt; + size_t cache_capacity; + + DeltaConverter* converter; + }; +} /* namespace Tsdb */ +#endif /* TSDB_DELTA_INSERT_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/delta_merge.h postgresql-hll-2.14/include/tsdb/storage/delta_merge.h --- postgresql-hll-2.14_old/include/tsdb/storage/delta_merge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/delta_merge.h 2020-12-12 17:06:43.387349845 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * delta_merge.h + * write delta table's data back to timeseries relation + * + * IDENTIFICATION + * src/include/tsdb/storage/delta_merge.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DELTA_MERGE_H +#define TSDB_DELTA_MERGE_H + +#include "c.h" +#include "postgres.h" +#include "nodes/parsenodes.h" +#include "tsdb/common/data_row.h" +#include "tsdb/storage/part.h" +#include "tsdb/storage/part_insert.h" +#include "utils/partitionmap_gs.h" +#include "utils/relcache.h" + +namespace Tsdb { + extern bool IsDeltaMergeStmt(const VacuumStmt* stmt); + extern void DoDeltaMerge(const RangeVar* var); + extern bool FlushDeltaToPart(Relation ts_rel, Relation delta_rel, bool forced, bool needDelete); + + /* + * The context that handles write datarows into new Parts + */ + class DeltaWriteBackContext : public BaseObject { + public: + DeltaWriteBackContext(Relation ts_rel, MemoryContext cxt); + ~DeltaWriteBackContext(); + void Init(); + void Destroy(); + + void CacheDataRow(const DataRow& datarow); + void FinishWriteBack(); + + private: + void FlushCU(int partSeq); + + MemoryContext memcxt; + + Relation ts_rel; + int n_tot_partition; + int n_actual_partition; + + /* + * a DataRowVector* array + * capacity: n_tot_partition + * each DataRowVector will contain at most TsConf::INSERT_CACHE_CAPACITY rows + * Every DataRowVector is a vector for one partition. Each partition will create only one part. + * If one DataRowVector is full, it will be flushed to the part. + */ + DataRowVector** vecs; + + /* + * each PartInsert object represents one part + * capacity: n_tot_partition + */ + PartInsert** part_inserts; + + /* + * each Part object is a helper helping PartInsert + * capacity: n_tot_partition + */ + Part** parts; + }; +} /* namespace Tsdb */ + +#endif /* TSDB_DELTA_MERGE_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/part.h postgresql-hll-2.14/include/tsdb/storage/part.h --- postgresql-hll-2.14_old/include/tsdb/storage/part.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/part.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,77 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * part.h + * the part of tsdb, as follow + * table + * --> partition1 + * --> part1 + * --> part2 + * --> part3 + * --> partition2 + * --> part1 + * --> part2 + * --> part3 + * CuDesctable named pg_cudesc_part_partitionOid + * cu file name cuCount_rowcount_maxtime_min_time_cudescOid_c1.0 + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/storage/part.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_PART_H +#define TSDB_PART_H + +#include "utils/relcache.h" +#include "storage/cu.h" +#include "storage/cu.h" +#include "tsdb/common/data_row.h" +#include "tsdb/storage/part_insert.h" +#include "tsdb/cache/tags_cachemgr.h" +#include "tsdb/utils/ts_pg_cudesc.h" + + +namespace Tsdb { +class Part : public BaseObject { +public: + Part(Oid partition_oid, Relation relation); + Part(Oid partition_oid, Oid cudesc_oid, Relation relation); + ~Part(); + void flush_data(DataRowVector* data_rows); + void build_part_data(DataRowVector* data_rows, PartInsert* part_insert); + bool get_part_desc(_out_ TsCUDesc& tscudesc); +private: + void form_time_cudata(DataRowVector& data_rows, _out_ CU& cu, _out_ TsCUDesc& tscudesc); + void form_field_cudata(DataRowVector& data_rows, int field_idx, _out_ CU& cu, _out_ TsCUDesc& tscudesc); + void compress_cu(CU& cu, TsCUDesc& tscudesc); + void reset_cu_data(CU& cu, TsCUDesc& tscudesc, int row_count); + + Oid partition_oid; + Oid cudesc_oid; + Relation relation; + const uint32 var_buf_size = 32 * 1024; /* default buffer size to save var_len data */ + + // In order to avoid over-boundary read in the function readData, more 8 byte memory is allocated. + const int reserved_cu_byte = 8; + + uint32 total_field_srcbuf_size; + uint32 total_time_srcbuf_size; +}; +} +#endif /* TSDB_PART_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/part_insert.h postgresql-hll-2.14/include/tsdb/storage/part_insert.h --- postgresql-hll-2.14_old/include/tsdb/storage/part_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/part_insert.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * part_insert.h + * inserter of part + * + * IDENTIFICATION + * src/include/tsdb/storage/part_insert.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_PART_INSERT_H +#define TSDB_PART_INSERT_H + +#include "utils/relcache.h" +#include "tsdb/common/data_row.h" +#include "tsdb/utils/constant_def.h" +#include "access/htup.h" +#include "cstore.h" +#include "storage/custorage.h" + +namespace Tsdb { +struct TsCUDesc; + +class PartInsert : public BaseObject { +public: + PartInsert(Relation relation, Oid partition_oid); + ~PartInsert(); + void flush_part(); + void begin_flush_part(); + void append_timecu(const CU& cu, TsCUDesc& tscudesc, const int colid); + void append_fieldcu(const CU& cu, TsCUDesc& tscudesc, const int colid); + void save_part_desc() const; + void mark_compaction(); + void flush_cu_data(); + Oid get_new_desc_oid() const; + void save_compaction_desc(); + + Oid partition_oid; + Oid cudesc_oid; +private: + uint32 get_next_cuid(); + void multi_insert_cudesc(); + void cache_tuple(HeapTuple tup); + + int part_row_count; + CUStorage* field_storage; + CUStorage* timestamp_storage; + Relation relation; + Relation partition_relation; + TimeRange range; + uint32 cur_cuid; + + /* Used for heap multi insert into cudesc relation */ + static const int MAX_BUFFERED_TUP = 10000; + Relation cudesc_rel; + HeapTuple tuples[MAX_BUFFERED_TUP]; + /* the number of array tuples in this class */ + int tuple_num; + + char* timebuf; + uint32 timebuf_used; + CUPointer time_cupointer; + CUPointer time_cupointer_offset; + char* fieldbuf; + uint32 fieldbuf_used; + CUPointer field_cupointer; + CUPointer field_cupointer_offset; + static const uint32 MAX_CU_BUFFERED_SIZE = 512 * 1024; + PartNumber part_id; + /* will give compaction extra part id ensure compaction work */ + bool is_compaction; + /* the total cudesc rel tuple numbers */ + int cudesc_tup_num; + /* if cudesc_tup_num > CUDESC_IDX_THRESHOLD, create index */ + static const int CUDESC_IDX_THRESHOLD = 100000; +}; +} +#endif /* TSDB_PART_INSERT_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/partition_search.h postgresql-hll-2.14/include/tsdb/storage/partition_search.h --- postgresql-hll-2.14_old/include/tsdb/storage/partition_search.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/partition_search.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,53 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partition_search.h + * tsdb partition search + * + * + * IDENTIFICATION + * src/include/tsdb/storage/partition_search.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_PARTITION_SEARCH_H +#define TSDB_PARTITION_SEARCH_H + +#include "tsdb/storage/part_search.h" +#include "utils/relcache.h" +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +class PartitionSearch : public BaseObject { +public: + PartitionSearch(); + ~PartitionSearch(); + bool init(TsStoreScanState* state); + bool run_scan(TsStoreScanState* state, VectorBatch* vecBatchOut); + void init_rescan(TsStoreScanState* state); + bool is_end_scan() const; + +private: + void build_part_search(TsStoreScanState* state); + void set_timing(TsStoreScanState* state); + void destroy_part_searchers(); + void decrease_part_ref(); + Oid partition_oid; + PartSearch *partSearchers; + int part_num; +}; + +#endif /* TSDB_PARTITION_SEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/part_merge.h postgresql-hll-2.14/include/tsdb/storage/part_merge.h --- postgresql-hll-2.14_old/include/tsdb/storage/part_merge.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/part_merge.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,82 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * part_merger.h + * functions for merge the part + * + * IDENTIFICATION + * src/include/tsdb/storage/part_merge.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TSDB_MERGE_H +#define TSDB_MERGE_H + +#include "tsdb/storage/cudesc_merge_reader.h" +#include "tsdb/storage/part_search.h" +struct List; + +namespace Tsdb { +class PartInsert; + +class MergeUtils : public BaseObject { +public: + static Oid merge_parts(Relation relation, Oid partition_oid, List* cudesc_rel_list); +private: + static void check_src_cudesc_indexes(List* cudesc_rel_list); + static void build_CudescReaderList(List* cudesc_rel_list, CudescReader *cudesc_reader); + static void merge_block(Relation rel, FieldTimeCuDescBlock block1, FieldTimeCuDescBlock block2); + static void init_CudescReader(Relation relation, CudescReader *cudesc_reader, int part_num); + static void destroy_CudescReader(CudescReader *cudesc_reader, int part_num); + static void init_vector(bool is_field, ScalarVector* vector); + static void interrupt_merge(); +}; + +class BlockMerger : public BaseObject { +public: + BlockMerger(); + ~BlockMerger(); + void prepare_merge(Relation rel, Oid partition_oid); + void merge(PartSearch* part_searcher, FieldTimeCuDescBlock* block); + void end_merge(); + void cache_merged_rows(); + Oid get_new_cudesc_oid(); +private: + void load_vectors(); + void add_row(FieldTimeCuDescBlock* block, VectorBatch* vectors, int& idx); + void flush_data(DataRowVector* rows); + void reset_vectors(); + void merge_cu(); + void copy_data_rows(DataRowVector* src, DataRowVector* dst); + void shallow_copy_datarow(DataRow* src, DataRow* dst); + void init_data_rows_filed(DataRowVector* rows); + void reset_data_rows_filed(DataRowVector* rows); +private: + FieldTimeCuDescBlock* block1; + + VectorBatch* vectors; + PartSearch* part_searcher; + + DataRowVector* merged_rows; + DataRowVector* temp_rows; + DataRowVector* toflush_rows; + PartInsert* part_insert; + int merge_block_idx; + + Relation relation; + Oid partition_oid; +}; +} +#endif /* TSDB_MERGE_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/part_search.h postgresql-hll-2.14/include/tsdb/storage/part_search.h --- postgresql-hll-2.14_old/include/tsdb/storage/part_search.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/part_search.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,208 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * part_search.h + * tsdb part search + * + * IDENTIFICATION + * src/include/tsdb/storage/part_search.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_PART_SEARCH_H +#define TSDB_PART_SEARCH_H + +#include "postgres.h" +#include "utils/rel.h" +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" +#include "tsdb/common/data_row.h" +#include "tsdb/cache/part_cachemgr.h" +#include "tsdb/storage/part.h" +#include "tsdb/storage/cudesc_merge_reader.h" +#include "storage/custorage.h" + +struct CUDescVector { + CUDesc* array; + uint32 idx; + uint32 num; +}; + +struct AccessedField { + Field field; + CUDescVector cudesc_vector; +}; + +struct AccessedTime { + Time time; + CUDescVector cudesc_vector; +}; + +class AccessedFields : public BaseObject { +public: + AccessedFields(int num) + { + if (num > 0) { + field_array = (AccessedField*)palloc0(sizeof(AccessedField) * num); + } else { + field_array = NULL; + } + this->num = num; + this->idx = 0; + } + + ~AccessedFields() + { + if (field_array != NULL) { + pfree_ext(field_array); + } + } + + AccessedField* field_array; + uint32 idx; + uint32 num; +}; + +struct CurrentScanPos { + int cu_cursor; + int tag_cursor; + uint32 cuid; + bool all_cu_scanned; + bool cu_scan_end; + int* cu_buf_cursor; + int col_num; +}; + +class AccessSysCol : public BaseObject { +public: + AccessSysCol(); + ~AccessSysCol(); + void init_sys_colid(uint32 sys_column_num); + void free_sys_colid(); + int get_col_id(uint32 idx) const; + uint32 get_total_num() const; + void set(uint32 idx, int colid); + void set_loaded(bool is_load); + bool be_init() const; + bool need_load() const; +private: + /* system column: not user defined query column, used to store extra query info */ + + /* Accessed system column number. length of sys_col_id */ + uint32 sys_col_num; + + /* Accessed system column id array. */ + int* sys_col_id; + + /* Flag to avoid repeat load system colum in part search(timestamp_scan, tag_scan, field_scan) */ + bool is_loaded; +}; + +class PartSearch:public BaseObject { +public: + PartSearch(); + PartSearch(Relation rel, Oid tscudesc_relid, FieldTimeCuDescBlock block); + PartSearch(Relation partition_rel, Oid tscudesc_relid); + ~PartSearch(); + void Destroy(); + bool init(TsStoreScanState* state, Tsdb::PartItem* cudesc_relid, Relation partition_rel); + void run_scan(TsStoreScanState* state, VectorBatch* vecBatchOut); + bool is_end_scan() const; + bool cu_scan_end() const; + void binding_fp_fill_vector(_in_ int colid, _in_ CUDesc* cudesc, ScalarVector* vec, const int attlen); + template + void fill_vector(_in_ int colid, _in_ CUDesc* cudesc, ScalarVector* vec); + void get_cu_deleted_mask(Relation cudesc_rel, _in_ Oid tagid, _in_ uint32 cuid, _in_ Snapshot snapshot); + void refresh_cursor(); + void init_tmp_cursor(); + bool need_scan(TsStoreScanState* state) const; + void set_end_scan(); + void close(); + Oid get_cudesc_id() const; + Relation get_tscudesc_rel(); +private: + void init_sys_columns(const List* sys_attr_list); + + /* Fill data to vector */ + bool const_to_vector(VectorBatch* vecBatchOut); + void field_to_vector(VectorBatch* vecBatchOut, int limit); + void timestamp_to_vector(VectorBatch* vecBatchOut, int limit); + void tags_to_vector(VectorBatch* vecBatchOut, int limit); + bool tagid_exist(Oid tagid); + uint32 syscol_to_vector_ifneed(_in_ CUDesc* cudesc, VectorBatch* vec_batch_out); + uint32 sys_col_to_vector(_in_ int col_idx, _in_ const CUDesc* cudesc, _out_ ScalarVector* vec) const; + void set_syscol_flag(bool is_loaded); + + template + int fill_vector_same(_in_ const CUDesc* cudesc, ScalarVector* vec); + int fill_vector_null(_in_ const CUDesc* cudesc, ScalarVector* vec); + int fill_tag_vector(const Tag* tag, const Tag* access_tag, const CUDesc cudesc, ScalarVector* vec); + CU* get_cu_data(_in_ int colid, _in_ CUDesc* cudesc, int val_size, int& slot_id); + void load_cudesc(); + void refresh_tmp_cursor(int colid, int load_rows, int total_rows); + CUUncompressedRetCode remote_load_cu(CUDesc* cudesc, int colid, int val_size, const int& slot_id); + void retry_load_cu(CUDesc* cudesc, int colid, int val_size, int& slot_id); + void reset_cu_cursor(); + bool check_cudesc(const CUDesc* cudesc); + + /* Load CU data and uncompress */ + bool is_dead_row(uint32 cuid, uint32 row) const; + CU* get_cached_cu(_in_ int colid, _in_ CUDesc* cudesc, int val_size, int& slot_id); + bool find_cucache_slot(_in_ int colid, _in_ const CUDesc* cudesc, int val_size, int& slot_id); + void uncompress_cache_cu(_in_ int colid, _in_ CUDesc* cudesc, int val_size, int& slot_id); + bool init_partid(); + bool init_partid(Relation cudesc_rel); + void init_cursor(); + + List* get_cudesc_list(Oid tagid, int colid, uint32 start_cuid, bool &added_col); + bool check_field_cudesc(CUDesc* cudesc, int limit, bool added_col); + void set_load_rows(int limit, CUDesc* cudesc) const; + + /* scan parameters */ + TimeRange* time_range; + TimeRange self_time_range; + int tag_id_num; + TagRows* tag_rows; + int plan_node_id; + Snapshot snapshot; + + /* current accessed position */ + CurrentScanPos scan_cursor; + CurrentScanPos tmp_cursor; + + /* current cu delete bitmap */ + uint32 del_mask_cuid; + bool has_dead_row; + unsigned char cu_del_mask[TsConf::INSERT_CACHE_CAPACITY]; + + /* Load field and timestamp */ + CUStorage* field_storage; + CUStorage* timestamp_storage; + AccessedFields* access_fields; + AccessedTime access_time; + AccessSysCol access_sys_col; + Tags* accessed_tags; + Relation partition_rel; + Relation tscudesc_rel; + Relation tscudesc_idx_rel; + Oid tscudesc_relid; + uint64 partid; + + /* cached row_count for count(*) */ + int cached_total_rows; +}; + +#endif /* TSDB_PART_SEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/ts_store_delete.h postgresql-hll-2.14/include/tsdb/storage/ts_store_delete.h --- postgresql-hll-2.14_old/include/tsdb/storage/ts_store_delete.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/ts_store_delete.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,82 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/storage/ts_store_delete.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_STORE_DELETE_H +#define TSDB_TS_STORE_DELETE_H + +#include "tsdb/utils/constant_def.h" +#include "access/cstore_vector.h" +#include "utils/relcache.h" +#include "utils/batchsort.h" +#include "vecexecutor/vectorbatch.h" +#include "nodes/execnodes.h" + + +namespace Tsdb { + +class TsStoreDelete : public BaseObject +{ +public: + TsStoreDelete(); + TsStoreDelete( + _in_ Relation rel, _in_ EState* estate, _in_ bool is_update_cu, _in_ Plan* plan, _in_ MemInfoArg* ArgmemInfo); + ~TsStoreDelete(); + void Destroy(); + + void init_sort_state(); + void init_mem_arg(const Plan* plan, const MemInfoArg* mem_arg); + + void put_delete_batch(_in_ const VectorBatch* batch, _in_ const JunkFilter* junkfilter); + uint64 ExecDelete(); + + MemInfoArg* del_mem_info; +private: + void init_sort_state_internal(TupleDesc sortTupDesc); + bool is_full() const; + void reset_sort_state(); + uint64 execute_delete(); + void update_virtual_bitmap(Oid tscudesc_relid, uint32 cuid, _in_ int update_row_num, _in_ Snapshot snapshot); + void update_bitmap_and_partdesc(Oid tscudesc_relid, uint32 cuid, _in_ uint32 update_row_num, _in_ uint64 part_del_num); + void prepare_delete(); + + Relation relation; + EState* estate; + + TupleDesc sort_tupdesc; + bool is_cupdesc_create_byself; + Batchsortstate* del_sort_state; + VectorBatch* sort_batch; + int row_offset[TsConf::INSERT_CACHE_CAPACITY]; + int sorted_rows; + uint64 deleted_rows; + + const AttrNumber SORT_TS_PARTID = 1; + const AttrNumber SORT_TS_TID = 2; + const char *PART_ID_TUPLE_NAME = "tscudescid"; + const char *COL_TID_TUPLE_NAME = "tid"; + +}; + +} + +#endif /* TSDB_TS_STORE_DELETE_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/ts_store_insert.h postgresql-hll-2.14/include/tsdb/storage/ts_store_insert.h --- postgresql-hll-2.14_old/include/tsdb/storage/ts_store_insert.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/ts_store_insert.h 2020-12-12 17:06:43.388349857 +0800 @@ -0,0 +1,81 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * ts_store_insert.h + * inserter of timeseries data + * + * IDENTIFICATION + * src/include/tsdb/storage/ts_store_insert.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_STORE_INSERT_H +#define TSDB_TS_STORE_INSERT_H + +#include "utils/rel.h" +#include "utils/relcache.h" +#include "vecexecutor/vectorbatch.h" +#include "tsdb/common/data_row.h" +#include "tsdb/storage/delta_insert.h" + +namespace Tsdb +{ + +class PartInsert; + +struct CacheTuples{ + HeapTuple* tup; + uint32 idx; +}; + +class TsStoreInsert : public BaseObject { +public: + TsStoreInsert(Relation relation); + void Destroy(); + ~TsStoreInsert(); + void batch_insert(_in_ Datum* values, _in_ bool* nulls, _in_ int options); + void BatchInsert(VectorBatch* batch, int hi_options); + void end_batch_insert(); +private: + void batch_insert_tsstore(_in_ Datum* values, _in_ bool* nulls, _in_ int options); + void end_batch_insert_tsstore(); + DataRowVector* get_data_row_vector(const PartitionIdentifier& match_partition); + void cache_data_row(const DataRow& data_row, const PartitionIdentifier& match_partition); + void init_context(); + void destroy_context(); + void get_vals_batch(ScalarVector* m_arr, int ncols, int row_cnt, Datum* val, bool* null); + void insert_delta_to_tsstore(); + + /* count the number of rows inserted */ + size_t tot_rowcnt = 0; + + /* PartitionIdentifier->partSeq is its index */ + DataRowVector **data_rows_vectors; + /* relevent to data_rows_vectors, same partSeq */ + Oid *partition_oid_vector; + int partition_total; + int partition_num; + Relation m_relation; + + MemoryContext insert_data_mem_cxt; + + bool use_delta; + Tsdb::DeltaInsertContext* delta_cxt; +}; + +}/* end namespace Tsdb */ + +#endif /* TSDB_TS_STORE_INSERT_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/storage/ts_store_search.h postgresql-hll-2.14/include/tsdb/storage/ts_store_search.h --- postgresql-hll-2.14_old/include/tsdb/storage/ts_store_search.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/storage/ts_store_search.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,53 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_store_search.h + * search timeseries data + * + * + * IDENTIFICATION + * src/include/tsdb/storage/ts_store_search.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_STORE_SEARCH_H +#define TSDB_TS_STORE_SEARCH_H + +#include "tsdb/storage/partition_search.h" +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +class TsStoreSearch : public BaseObject { +public: + TsStoreSearch(); + ~TsStoreSearch(); + bool run_scan(_in_ TsStoreScanState* state, _out_ VectorBatch* vecBatchOut); + void init_scan(TsStoreScanState* state); + void init_rescan(TsStoreScanState* state); + void reset(TsStoreScanState* state); + bool is_end_scan() const; + +private: + void set_timing(TsStoreScanState* state); + bool need_scan(_in_ const TsStoreScanState* state) const; + + PartitionSearch* partition_search; + MemoryContext scan_mem_cxt; +}; + +#endif /* TSDB_TS_STORE_SEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/time_bucket.h postgresql-hll-2.14/include/tsdb/time_bucket.h --- postgresql-hll-2.14_old/include/tsdb/time_bucket.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/time_bucket.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,30 @@ +/*--------------------------------------------------------------------------------------- + * + * time_bucket.h + * time_window function, like date_trunc, but more relax + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2019, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/contrib/tsdb/include/time_bucket.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef CONTRIB_TSDB_TIME_BUCKET_H +#define CONTRIB_TSDB_TIME_BUCKET_H + +#include "fmgr.h" +#include "utils/timestamp.h" + +extern "C" Datum time_window(PG_FUNCTION_ARGS); +#ifdef ENABLE_UT +extern "C" int64 get_interval_period_timestamp_units(Interval* interval); +extern "C" TimestampTz time_bucket_ts(int64 period, TimestampTz timestamp, TimestampTz shift); +#endif + +#endif /* CONTRIB_TSDB_TIME_BUCKET_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/tsexecutor/node_join_ts_delta.h postgresql-hll-2.14/include/tsdb/tsexecutor/node_join_ts_delta.h --- postgresql-hll-2.14_old/include/tsdb/tsexecutor/node_join_ts_delta.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/tsexecutor/node_join_ts_delta.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * node_join_ts_delta.h + * JoinTsDelta node executor, which drives tsstorescan and delta scan, then combines + * their results + * + * IDENTIFICATION + * src/include/tsdb/tsexecutor/node_join_ts_delta.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_NODE_JOIN_TS_DELTA_H +#define TSDB_NODE_JOIN_TS_DELTA_H + +#include "nodes/execnodes.h" + +namespace Tsdb { + extern Node* CreateJoinTsDeltaState(ExtensiblePlan* eplan); +} + +#endif /* TSDB_NODE_JOIN_TS_DELTA_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/tsexecutor/node_join_ts_tag.h postgresql-hll-2.14/include/tsdb/tsexecutor/node_join_ts_tag.h --- postgresql-hll-2.14_old/include/tsdb/tsexecutor/node_join_ts_tag.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/tsexecutor/node_join_ts_tag.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * node_join_ts_tag.h + * JoinTsTag node executor, which drives tag scan and then tsstore/delta scan + * + * IDENTIFICATION + * src/include/tsdb/tsexecutor/node_join_ts_tag.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_JOIN_TS_TAG_H +#define TSDB_JOIN_TS_TAG_H + +#include "nodes/execnodes.h" + +namespace Tsdb { + extern Node* CreateJoinTsTagState(ExtensiblePlan* eplan); +} + +#endif /* TSDB_JOIN_TS_TAG_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/tsexecutor/ts_executor_nodes.h postgresql-hll-2.14/include/tsdb/tsexecutor/ts_executor_nodes.h --- postgresql-hll-2.14_old/include/tsdb/tsexecutor/ts_executor_nodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/tsexecutor/ts_executor_nodes.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_executor_nodes.h + * tsdb executor nodes declaration + * + * IDENTIFICATION + * src/include/tsdb/tsexecutor/ts_executor_nodes.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_EXECUTOR_NODES_H +#define TSDB_TS_EXECUTOR_NODES_H + +#include "nodes/execnodes.h" +#include "tsdb/common/data_row.h" + +namespace Tsdb { +typedef struct JoinTsTagState : ExtensiblePlanState { + /* tagrow batch that we are working on */ + TagRows* working_tagbatch; + bool tag_scan_done; +} JoinTsTagState; + +typedef struct JoinTsDeltaState : ExtensiblePlanState { + /* dirty: fake tagbatch for tsstore count(*) query */ + TagRows* ts_count_tagbatch; + /* tagrow batch points to the same place as parent */ + TagRows* working_tagbatch; + /* has current batch been sent to TsStoreScan and Delta? */ + bool tagbatch_sent; +} JoinTsDeltaState; +} +#endif /* TSDB_TS_EXECUTOR_NODES_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/tsexecutor/ts_tag_scan.h postgresql-hll-2.14/include/tsdb/tsexecutor/ts_tag_scan.h --- postgresql-hll-2.14_old/include/tsdb/tsexecutor/ts_tag_scan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/tsexecutor/ts_tag_scan.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,42 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/utils/ts_tag_scan.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_TAG_SCAN_H +#define TSDB_TS_TAG_SCAN_H + +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "access/htup.h" +#include "vecexecutor/vecnodes.h" + +class TsTagScan : public BaseObject +{ +public: + static void convert_tag_qual(const Relation relation, const List* qual); + +private: + static bool unsupported_tag_op(OpExpr* op, NodeTag* nodeTag); + static bool tag_related_qual(const OpExpr* op, const TupleDesc rel_tupdesc); + static bool validate_tag_var(OpExpr* new_op, TupleDesc rel_tupdesc, TupleDesc idx_tupdesc); +}; +#endif diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/constant_def.h postgresql-hll-2.14/include/tsdb/utils/constant_def.h --- postgresql-hll-2.14_old/include/tsdb/utils/constant_def.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/constant_def.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,151 @@ +/*--------------------------------------------------------------------------------------- + * + * constant_def.h + * the definition of tsdb constant + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/utils/constant_def.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef TSDB_CONSTANT_DEF_H +#define TSDB_CONSTANT_DEF_H + +#include "c.h" +#include "access/attnum.h" + +typedef uint16 PartNumber; + +namespace TsConf { + extern const char* DEFAULT_PERIOD; + extern const char* DELTA_RELNAME_PREFIX; + extern const char* TAG_ID_COLUMN_NAME; + extern const AttrNumber TAGID_ATTRNUM; + extern const char* TAG_TABLE_NAME_PREFIX; + extern const char* CUDESC_TABLE_NAME_PREFIX; + extern const char* METRIC_TABLE_NAME_PREFIX; + extern const char* INDEX_TABLE_NAME_SUFFIX; + extern const char* TSSCANMEMORYCONTEXT; + extern const char* TSINSERTMEMORYCONTEXT; + extern const char* TSDATAINSERTDATAROWMEMORYCONTEXT; + extern const int PARTITION_CACHE_CAPACITY; + extern const Oid FIRST_TAG_ID; + extern const Oid MAX_TAG_ID; + extern const Oid TAG_ID_WARING_THRESHOLE; + extern const int TS_RANGE_PARTKEYNUM; + extern const int LOAD_CUDESC_NUM; + extern const int LOAD_BATCHSIZE; + extern const char* TAG_TABLE_CACHE_NAME; + extern const char* PART_ID_CACHE_NAME; + extern const char* PART_ITEM_HASH_NAME; + extern const int TIME_FILE_OFFSET; + extern const uint16 FIRST_PARTID; + extern const int MIN_PART_REFCOUNT_HASHSIZE; + extern const int MAX_PART_REFCOUNT_HASHSIZE; + extern const int MAX_FIX_ATT_LEN; + enum {MAX_CMMON_PREFIX_LEN = 256}; + enum {MAX_TAGS_STRING_LEN = 1024}; + enum {MAX_PART_NUM = 15382}; + enum {INSERT_CACHE_CAPACITY = 60000}; +} + +namespace TimeOprId { + extern Oid TIMESTAMP_OP_MIN; + extern Oid TIMESTAMP_OP_MAX; + extern Oid TIMESTAMP_DATE_OP_MIN; + extern Oid TIMESTAMP_DATE_OP_MAX; +} + +namespace TsCudesc { + /* ts_cudesc attribute number */ + extern const int16 COL_ID; + extern const int16 TAG_ID; + extern const int16 CU_ID; + extern const int16 MIN; + extern const int16 MAX; + extern const int16 ROW_COUNT; + extern const int16 CU_MODE; + extern const int16 CU_SIZE; + extern const int16 CU_POINTER; + extern const int16 MAGIC; + extern const int16 EXTRA; + extern const int32 PART_COL_ID; + extern const int32 COMPACTION_COL_ID; + + /* store auxiliary information of ts_cudesc */ + extern const int32 VIRTUAL_DEL_COL_ID; + enum {MAX_ATT_NUM = 11}; +} + +namespace Compaction { + enum {MAX_TSCOMPATION_NUM = 100}; + enum knl_compaction_state { + COMPACTION_INIT = 0, + COMPACTION_STARTING_BEGIN, + COMPACTION_STARTING_END, + COMPACTION_IN_PROGRESS, + COMPACTION_DONE + }; + + enum { + COMPACTION_WORKER_INVALID = 0, + COMPACTION_WORKER_STOPING, + COMPACTION_WORKER_WORKING + }; + extern const uint32 COMPACTION_QUEUE_SIZE; + extern const int SIGNAL_SLOT_THREADPOOL_LISTENER_GAP; + extern const int COMPACTION_WAIT_SLEEP_TIME; + extern const uint32 MAX_COMPACTION_WAIT_LOOP; + extern const uint64 OUTPUT_WAIT_COUNT; + extern const uint64 PRINT_ALL_WAIT_COUNT; + extern const uint32 EXIT_WAIT_DELAY; + extern const char* DEFAULT_TEMPLATE0; + extern const char* DEFAULT_TEMPLATE1; + extern const uint32 DISABLE_FLAG; + extern const uint32 PARTITION_OID_INDEX; + extern const int TASK_SLOW_THRESHOLD; + extern const int MIN_COMPACTION_PARTS; + extern const int LEVEL_TYPE_NUMBER; + extern const int MAX_COMPACTION_PARTS; + extern const int LEVEL_MID; + extern const int LEVEL_LARGE; + enum {NAMELENGTH = 64}; + enum {MAX_SLEEP_COUNT = 1000}; + extern const int REMOVE_FLAG; +} + +typedef struct CuDescCompactionStatus { +} CuDescCompactionStatus; + +typedef struct TsCompactionWorkerStatus { + ThreadId thread_id; + uint32 thread_state; +} TsCompactionWorkerStatus; + +namespace TsProducer { + extern const int LEVEL_TYPE_NUM; + extern const int MAXTASKCOUNT; + extern const int CONSUMER_BUSY; + extern const int CONSUMER_OVERLOAD; + extern const uint32 MAX_STRATEGY_LEN; + + extern const int MIN_PART_INIT; + extern const int MIN_PART_MIN; + extern const int MIN_PART_MAX; + + extern const int MAX_PART_INIT; + extern const int MAX_PART_MIN; + extern const int MAX_PART_MAX; + + extern const int LEVEL_MID_INIT; + extern const int LEVEL_MID_MIN; + extern const int LEVEL_MID_MAX; + + extern const int LEVEL_MAX_INIT; + extern const int LEVEL_MAX_MIN; + extern const int LEVEL_MAX_MAX; +} +#endif /* TSDB_CONSTANT_DEF_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/ctlg_utils.h postgresql-hll-2.14/include/tsdb/utils/ctlg_utils.h --- postgresql-hll-2.14_old/include/tsdb/utils/ctlg_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/ctlg_utils.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * ctlg_utils.h + * catalog-related (DDL, job, etc.) helper functions + * + * IDENTIFICATION + * src/include/tsdb/utils/ctlg_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_CTLG_UTILS_H +#define TSDB_CTLG_UTILS_H + +#include "nodes/execnodes.h" +#include "utils/partitionmap_gs.h" + +namespace Tsdb { + enum class MetaTableType { + META_TABLE_CUDESC = 0, + META_TABLE_TAGS, + META_TABLE_DELTA, + META_TABLE_INVALID + }; + + extern void RecordDependency(const Oid referenced_relid, const Oid depender_relid); + extern IndexInfo* MakeIndexInfo(); + extern PartitionIdentifier GetMatchedPartition(Relation ts_rel, TimestampTz time_key); + extern void GenMetaRelname(const Oid father_oid, const MetaTableType type, char* meta_relname); + extern void GenIndexRelname(const char* meta_relname, char* meta_idx_relname); + extern void RemoveJobsWhenRemoveRelation(Oid relid); + extern void GenBtSingleColIndexRelname(_in_ const char* tag_relname, _in_ const char* col_name, + _out_ char* meta_idx_relname); +} /* namespace Tsdb */ + +#endif /* TSDB_CTLG_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/delta_utils.h postgresql-hll-2.14/include/tsdb/utils/delta_utils.h --- postgresql-hll-2.14_old/include/tsdb/utils/delta_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/delta_utils.h 2020-12-12 17:06:43.389349871 +0800 @@ -0,0 +1,50 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * delta_utils.h + * delta feature related helper functions & constants + * + * IDENTIFICATION + * src/include/tsdb/utils/delta_utils.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_DELTA_UTILS_H +#define TSDB_DELTA_UTILS_H + +#include "utils/relcache.h" +#include "utils/snapshot.h" + +namespace Tsdb { + static const int DELTAMERGE_INTERVAL_DEFAULT = 5; + static const int DELTAMERGE_INTERVAL_MIN = 1; + static const int DELTAMERGE_INTERVAL_MAX = 1440; + static const int DELTAMERGE_THRESHOLD_DEFAULT = 60000; + static const int DELTAMERGE_THRESHOLD_MIN = 0; + static const int DELTAMERGE_THRESHOLD_MAX = 1000000; + static const int DELTAINSERT_THRESHOLD_DEFAULT = 5000; + static const int DELTAINSERT_THRESHOLD_MIN = 100; + static const int DELTAINSERT_THRESHOLD_MAX = 60000; + + extern bool RelationEnablesTsdbDelta(Relation ts_rel); + extern int RelationGetDeltaMergeInterval(Relation ts_rel); + extern int RelationGetDeltaInsertThreshold(Relation ts_rel); + extern Relation RelationGetDeltaRelation(Relation ts_rel, LOCKMODE lockmode); + extern Relation DeltaRelationGetDeltaIndexRelation(Relation delta_rel, LOCKMODE lockmode); + extern size_t CountDelta(Snapshot snapshot, Relation delta_rel); +} /* namespace Tsdb */ + +#endif /* TSDB_DELTA_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/ts_pg_cudesc.h postgresql-hll-2.14/include/tsdb/utils/ts_pg_cudesc.h --- postgresql-hll-2.14_old/include/tsdb/utils/ts_pg_cudesc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/ts_pg_cudesc.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,93 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/utils/ts_pg_cudesc.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_PG_CUDESC_H +#define TSDB_TS_PG_CUDESC_H + +#include "tsdb/utils/constant_def.h" +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "access/htup.h" +#include "storage/cu.h" + +namespace Tsdb { +struct TsCUDesc : public BaseObject { + CUDesc* cudesc; + Oid tag_id; + + TsCUDesc() { + cudesc = (CUDesc*)palloc0(sizeof(CUDesc)); + cudesc->Reset(); + tag_id = 0; + } + + ~TsCUDesc() { + if (cudesc != NULL) { + pfree_ext(cudesc); + } + } +}; + +class TsCUDescUtils : public BaseObject +{ +public: + TsCUDescUtils(Relation tscudesc_rel); + ~TsCUDescUtils(); + + HeapTuple form_vc_tsudesc(_in_ uint32 colid, const TsCUDesc& tscudesc, const char* del_bitmap); + bool get_del_mask(_in_ Oid tagid, _in_ uint32 cuid, _in_ Snapshot snapshot, + _out_ unsigned char cu_del_mask[TsConf::INSERT_CACHE_CAPACITY]); + void update_del_bitmap(_in_ uint32 cuid, _in_ const int* rowoffset, + _in_ int del_row_num, _in_ Snapshot snapshot); + void update_part_desc(_in_ int del_row_num); + uint64 load_cudesc_only_row(Oid tags_id, int col); + List* load_cudesc(Relation idx_rel, Oid tags_id, int col, uint32 start_cuid); + void deform_tscudesc_tup(HeapTuple tup, _out_ TsCUDesc *tscudesc); + HeapTuple form_tscudesc_tuple(TsCUDesc* tscudesc, + _in_ Datum vals[TsCudesc::MAX_ATT_NUM], _in_ size_t vals_size, + _in_ bool nulls[TsCudesc::MAX_ATT_NUM], _in_ size_t nulls_size, + _in_ Form_pg_attribute attr); + static int make_compation_level(Relation cudesc_rel); + static int get_compation_level(Oid cudec_oid); + void save_by_tscudesc(const TsCUDesc& tscudesc, int32 colid); + bool get_part_desc(_out_ TsCUDesc& tscudesc); + bool get_auxiliary_desc(_out_ TsCUDesc& tscudesc, int32 colid); +private: + int get_delmask_bytes(uint32 row_count) const; + void insert_del_tuple(_in_ uint32 cuid, _in_ const int* rowoffset, _in_ int del_row_num); + bool update_cudesc_index(Relation relation, HeapTuple old_tup, HeapTuple new_tup) const; + HeapTuple form_new_delmask_tup(_in_ uint32 cuid, _in_ const int* rowoffset, _in_ int del_row_num, + _out_ ItemPointerData* old_tup_ctid); + bool get_del_mask_internal(_in_ HeapTuple tup, _in_ const Snapshot snapshot, + _out_ unsigned char cu_del_mask[TsConf::INSERT_CACHE_CAPACITY]); + void insert_del_tuple_internal(_in_ HeapTuple tup, _in_ const int* rowoffset, _in_ const int del_row_num); + + HeapTuple form_new_delmask_tup_internal(_in_ HeapTuple old_tup, _in_ const int* rowoffset, + _in_ const int del_row_num, _out_ ItemPointerData* old_tup_ctid); + + void update_part_desc_internal(_in_ HeapTuple old_tup, _in_ const int del_row_num); + + Relation relation; +}; +} +#endif /* TSDB_TS_CUDESC_H */ diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/ts_pg_tags.h postgresql-hll-2.14/include/tsdb/utils/ts_pg_tags.h --- postgresql-hll-2.14_old/include/tsdb/utils/ts_pg_tags.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/ts_pg_tags.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,43 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/utils/ts_pg_tags.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_TS_PG_TAG_H +#define TSDB_TS_PG_TAG_H + +#include "utils/relcache.h" +#include "utils/snapshot.h" +#include "access/htup.h" +#include "tsdb/common/data_row.h" +#include "access/skey.h" + +class TsTagUtils : public BaseObject +{ +public: + static Oid get_tagid(const Tags& tags, Relation relation); + static Oid get_max_tag_id(Relation relation, Snapshot snapshot_arg); +private: + static int init_tagkey(const Tags& tags, Relation tag_rel, ScanKeyData key[]); + static int type_map(Oid input); + static Oid save_tags(const Tags& tags, Relation tag_rel); +}; +#endif diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/ts_redis.h postgresql-hll-2.14/include/tsdb/utils/ts_redis.h --- postgresql-hll-2.14_old/include/tsdb/utils/ts_redis.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/ts_redis.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------- + * + * ts_redis.h + * ts table redistribute function + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * src/include/tsdb/utils/ts_redis.h + * + *--------------------------------------------------------------------------------------- + */ + +#ifndef TS_REDIS_H +#define TS_REDIS_H + +#include "utils/rel.h" +#include "nodes/parsenodes.h" + +// for copy rule +extern bool is_copy_rule(Query* node); +extern List* query_rewrite_copy(Query* parsetree); + +// for alter table rule +extern bool support_resize_ddl(const AlterTableStmt* stmt); +extern List* query_rewrite_alter_table(Query* parsetree); +extern char* rewrite_query_string(Node* stmt); + +// block unsupport ddl for view and table +extern void block_ts_rangevar_unsupport_ddl(const Node* parsetree); +extern bool is_redis_rule(RuleStmt* stmt); + +#endif diff -uprN postgresql-hll-2.14_old/include/tsdb/utils/ts_relcache.h postgresql-hll-2.14/include/tsdb/utils/ts_relcache.h --- postgresql-hll-2.14_old/include/tsdb/utils/ts_relcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsdb/utils/ts_relcache.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * ts_relcache.h + * functions for search the catalog + * + * IDENTIFICATION + * src\include\tsdb\utils\ts_relcache.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef TSDB_RELCACHE_H +#define TSDB_RELCACHE_H +#include "utils/relcache.h" +#include "nodes/pg_list.h" + +extern List* search_cudesc(Oid partition_id, bool is_snapshow_now); +extern List* search_disabled_cudesc(Oid partition_id, bool is_snapshot_now); +extern List* search_all_cudesc(Oid partition_id, bool is_snapshot_now); +extern double get_total_row_count(Relation ts_rel); +extern void search_cudesc_producer(); +extern List* get_database_list(); +extern bool check_partition_valid_policy(Oid partition_id); +extern List* get_all_ts_table(); +#endif \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsearch/dicts/regis.h postgresql-hll-2.14/include/tsearch/dicts/regis.h --- postgresql-hll-2.14_old/include/tsearch/dicts/regis.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/dicts/regis.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,41 @@ +/* ------------------------------------------------------------------------- + * + * regis.h + * + * Declarations for fast regex subset, used by ISpell + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/dicts/regis.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef __REGIS_H__ +#define __REGIS_H__ + +typedef struct RegisNode { + uint32 type : 2, len : 16, unused : 14; + struct RegisNode* next; + unsigned char data[FLEXIBLE_ARRAY_MEMBER]; +} RegisNode; + +#define RNHDRSZ (offsetof(RegisNode, data)) + +#define RSF_ONEOF 1 +#define RSF_NONEOF 2 + +typedef struct Regis { + RegisNode* node; + uint32 issuffix : 1, nchar : 16, unused : 15; +} Regis; + +bool RS_isRegis(const char* str); + +void RS_compile(Regis* r, bool issuffix, const char* str); +void RS_free(Regis* r); + +/* returns true if matches */ +bool RS_execute(Regis* r, char* str); + +#endif diff -uprN postgresql-hll-2.14_old/include/tsearch/dicts/spell.h postgresql-hll-2.14/include/tsearch/dicts/spell.h --- postgresql-hll-2.14_old/include/tsearch/dicts/spell.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/dicts/spell.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------- + * + * spell.h + * + * Declarations for ISpell dictionary + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/dicts/spell.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef __SPELL_H__ +#define __SPELL_H__ + +#include "regex/regex.h" +#include "tsearch/dicts/regis.h" +#include "tsearch/ts_public.h" + +/* + * SPNode and SPNodeData are used to represent prefix tree (Trie) to store + * a words list. + */ +struct SPNode; + +typedef struct { + uint32 val : 8, isword : 1, + /* Stores compound flags listed below */ + compoundflag : 4, + /* Reference to an entry of the AffixData field */ + affix : 19; + struct SPNode* node; +} SPNodeData; + +/* + * Names of FF_ are correlated with Hunspell options in affix file + * http://hunspell.sourceforge.net/ + */ +#define FF_COMPOUNDONLY 0x01 +#define FF_COMPOUNDBEGIN 0x02 +#define FF_COMPOUNDMIDDLE 0x04 +#define FF_COMPOUNDLAST 0x08 +#define FF_COMPOUNDFLAG (FF_COMPOUNDBEGIN | FF_COMPOUNDMIDDLE | FF_COMPOUNDLAST) +#define FF_COMPOUNDFLAGMASK 0x0f + +typedef struct SPNode { + uint32 length; + SPNodeData data[FLEXIBLE_ARRAY_MEMBER]; +} SPNode; + +#define SPNHDRSZ (offsetof(SPNode, data)) + +/* + * Represents an entry in a words list. + */ +typedef struct spell_struct { + union { + /* + * flag is filled in by NIImportDictionary(). After NISortDictionary(), + * d is used instead of flag. + */ + char* flag; + /* d is used in mkSPNode() */ + struct { + /* Reference to an entry of the AffixData field */ + int affix; + /* Length of the word */ + int len; + } d; + } p; + char word[FLEXIBLE_ARRAY_MEMBER]; /* variable length, null-terminated */ +} SPELL; + +#define SPELLHDRSZ (offsetof(SPELL, word)) + +/* + * Represents an entry in an affix list. + */ +typedef struct aff_struct { + char* flag; + /* FF_SUFFIX or FF_PREFIX */ + uint32 type : 1, flagflags : 7, issimple : 1, isregis : 1, replen : 14; + char* find; + char* repl; + union { + regex_t regex; + Regis regis; + } reg; +} AFFIX; + +/* + * affixes use dictionary flags too + */ +#define FF_COMPOUNDPERMITFLAG 0x10 +#define FF_COMPOUNDFORBIDFLAG 0x20 +#define FF_CROSSPRODUCT 0x40 + +/* + * Don't change the order of these. Initialization sorts by these, + * and expects prefixes to come first after sorting. + */ +#define FF_SUFFIX 1 +#define FF_PREFIX 0 + +/* + * AffixNode and AffixNodeData are used to represent prefix tree (Trie) to store + * an affix list. + */ +struct AffixNode; + +typedef struct { + uint32 val : 8, naff : 24; + AFFIX** aff; + struct AffixNode* node; +} AffixNodeData; + +typedef struct AffixNode { + uint32 isvoid : 1, length : 31; + AffixNodeData data[FLEXIBLE_ARRAY_MEMBER]; +} AffixNode; + +#define ANHRDSZ (offsetof(AffixNode, data)) + +typedef struct { + char* affix; + int len; + bool issuffix; +} CMPDAffix; + +/* + * Type of encoding affix flags in Hunspel dictionaries + */ +typedef enum { + FM_CHAR, /* one character (like ispell) */ + FM_LONG, /* two characters */ + FM_NUM /* number, >= 0 and < 65536 */ +} FlagMode; + +/* + * Structure to store Hunspell options. Flag representation depends on flag + * type. These flags are about support of compound words. + */ +typedef struct CompoundAffixFlag { + union { + /* Flag name if flagMode is FM_CHAR or FM_LONG */ + char* s; + /* Flag name if flagMode is FM_NUM */ + uint32 i; + } flag; + /* we don't have a bsearch_arg version, so, copy FlagMode */ + FlagMode flagMode; + uint32 value; +} CompoundAffixFlag; + +#define FLAGCHAR_MAXSIZE (1 << 8) +#define FLAGNUM_MAXSIZE (1 << 16) + +typedef struct { + int maffixes; + int naffixes; + AFFIX* Affix; + + AffixNode* Suffix; + AffixNode* Prefix; + + SPNode* Dictionary; + /* Array of sets of affixes */ + char** AffixData; + int lenAffixData; + int nAffixData; + bool useFlagAliases; + + CMPDAffix* CompoundAffix; + + bool usecompound; + FlagMode flagMode; + + /* + * All follow fields are actually needed only for initialization + */ + + /* Array of Hunspell options in affix file */ + CompoundAffixFlag* CompoundAffixFlags; + /* number of entries in CompoundAffixFlags array */ + int nCompoundAffixFlag; + /* allocated length of CompoundAffixFlags array */ + int mCompoundAffixFlag; + + /* + * Remaining fields are only used during dictionary construction; they are + * set up by NIStartBuild and cleared by NIFinishBuild. + */ + MemoryContext buildCxt; /* temp context for construction */ + + /* Temporary array of all words in the dict file */ + SPELL** Spell; + int nspell; /* number of valid entries in Spell array */ + int mspell; /* allocated length of Spell array */ + + /* These are used to allocate "compact" data without palloc overhead */ + char* firstfree; /* first free address (always maxaligned) */ + size_t avail; /* free space remaining at firstfree */ +} IspellDict; + +extern TSLexeme* NINormalizeWord(IspellDict* Conf, char* word); + +extern void NIStartBuild(IspellDict* Conf); +extern void NIImportAffixes(IspellDict* Conf, const char* filename); +extern void NIImportDictionary(IspellDict* Conf, const char* filename); +extern void NISortDictionary(IspellDict* Conf); +extern void NISortAffixes(IspellDict* Conf); +extern void NIFinishBuild(IspellDict* Conf); + +#endif diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_cache.h postgresql-hll-2.14/include/tsearch/ts_cache.h --- postgresql-hll-2.14_old/include/tsearch/ts_cache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_cache.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,84 @@ +/* ------------------------------------------------------------------------- + * + * ts_cache.h + * Tsearch related object caches. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/tsearch/ts_cache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TS_CACHE_H +#define TS_CACHE_H + +#include "tsearch/ts_public.h" +#include "utils/guc.h" + +/* + * All TS*CacheEntry structs must share this common header + * (see InvalidateTSCacheCallBack) + */ +typedef struct TSAnyCacheEntry { + Oid objId; + bool isvalid; +} TSAnyCacheEntry; + +typedef struct TSParserCacheEntry { + /* prsId is the hash lookup key and MUST BE FIRST */ + Oid prsId; /* OID of the parser */ + bool isvalid; + + Oid startOid; + Oid tokenOid; + Oid endOid; + Oid headlineOid; + Oid lextypeOid; + + /* + * Pre-set-up fmgr call of most needed parser's methods + */ + FmgrInfo prsstart; + FmgrInfo prstoken; + FmgrInfo prsend; + FmgrInfo prsheadline; +} TSParserCacheEntry; + +typedef struct TSDictionaryCacheEntry { + /* dictId is the hash lookup key and MUST BE FIRST */ + Oid dictId; + bool isvalid; + + /* most frequent fmgr call */ + Oid lexizeOid; + FmgrInfo lexize; + + MemoryContext dictCtx; /* memory context to store private data */ + void* dictData; +} TSDictionaryCacheEntry; + +typedef struct ListDictionary { + int len; + Oid* dictIds; +} ListDictionary; + +typedef struct TSConfigCacheEntry { + /* cfgId is the hash lookup key and MUST BE FIRST */ + Oid cfgId; + bool isvalid; + Oid prsId; + int lenmap; + ListDictionary* map; + ParserCfOpts* opts; /* add configuration options */ +} TSConfigCacheEntry; + +extern TSParserCacheEntry* lookup_ts_parser_cache(Oid prsId); +extern TSDictionaryCacheEntry* lookup_ts_dictionary_cache(Oid dictId); +extern TSConfigCacheEntry* lookup_ts_config_cache(Oid cfgId); + +extern Oid getTSCurrentConfig(bool emitError); +extern bool check_TSCurrentConfig(char** newval, void** extra, GucSource source); +extern void assign_TSCurrentConfig(const char* newval, void* extra); + +#endif /* TS_CACHE_H */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_locale.h postgresql-hll-2.14/include/tsearch/ts_locale.h --- postgresql-hll-2.14_old/include/tsearch/ts_locale.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_locale.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,79 @@ +/* ------------------------------------------------------------------------- + * + * ts_locale.h + * locale compatibility layer for tsearch + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_locale.h + * + * ------------------------------------------------------------------------- + */ +#ifndef __TSLOCALE_H__ +#define __TSLOCALE_H__ + +#include +#include + +#include "utils/pg_locale.h" +#include "mb/pg_wchar.h" + +/* + * towlower() and friends should be in , but some pre-C99 systems + * declare them in . + */ +#ifdef HAVE_WCHAR_H +#include +#endif +#ifdef HAVE_WCTYPE_H +#include +#endif + +/* working state for tsearch_readline (should be a local var in caller) */ +typedef struct { + FILE* fp; + const char* filename; + int lineno; + char* curline; + ErrorContextCallback cb; +} tsearch_readline_state; + +#define TOUCHAR(x) (*((const unsigned char*)(x))) + +#ifdef USE_WIDE_UPPER_LOWER + +extern int t_isdigit(const char* ptr); +extern int t_isspace(const char* ptr); +extern int t_isalpha(const char* ptr); +extern int t_isprint(const char* ptr); + +/* The second argument of t_iseq() must be a plain ASCII character */ +#define t_iseq(x, c) (TOUCHAR(x) == (unsigned char)(c)) + +#define COPYCHAR(d, s) \ + do { \ + int rc = memcpy_s(d, pg_mblen(s), s, pg_mblen(s)); \ + securec_check(rc, "", ""); \ + } while (0) + +#else /* not USE_WIDE_UPPER_LOWER */ + +#define t_isdigit(x) isdigit(TOUCHAR(x)) +#define t_isspace(x) isspace(TOUCHAR(x)) +#define t_isalpha(x) isalpha(TOUCHAR(x)) +#define t_isprint(x) isprint(TOUCHAR(x)) +#define t_iseq(x, c) (TOUCHAR(x) == (unsigned char)(c)) + +#define COPYCHAR(d, s) (*((unsigned char*)(d)) = TOUCHAR(s)) +#endif /* USE_WIDE_UPPER_LOWER */ + +extern char* lowerstr(const char* str); +extern char* lowerstr_with_len(const char* str, int len); + +extern bool tsearch_readline_begin(tsearch_readline_state* stp, const char* filename); +extern char* tsearch_readline(tsearch_readline_state* stp); +extern void tsearch_readline_end(tsearch_readline_state* stp); + +extern char* t_readline(FILE* fp); + +#endif /* __TSLOCALE_H__ */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_public.h postgresql-hll-2.14/include/tsearch/ts_public.h --- postgresql-hll-2.14_old/include/tsearch/ts_public.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_public.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,177 @@ +/* ------------------------------------------------------------------------- + * + * ts_public.h + * Public interface to various tsearch modules, such as + * parsers and dictionaries. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_public.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TS_PUBLIC_H_ +#define _PG_TS_PUBLIC_H_ + +#include "nodes/pg_list.h" +#include "pgxc/pgxc.h" +#include "tsearch/ts_type.h" + +#define DICT_SEPARATOR ('_') + +#define FILE_POSTFIX_DICT ("dict") +#define FILE_POSTFIX_AFFIX ("affix") +#define FILE_POSTFIX_STOP ("stop") +#define FILE_POSTFIX_SYN ("syn") +#define FILE_POSTFIX_THS ("ths") + +#define skipLoad(ddlsql) ((ddlsql) && IsConnFromCoord()) + +/* + * Parser's framework + */ + +/* + * returning type for prslextype method of parser + */ +typedef struct { + int lexid; + char* alias; + char* descr; +} LexDescr; + +/* + * Interface to headline generator + */ +typedef struct { + uint32 selected : 1, in : 1, replace : 1, repeated : 1, skip : 1, unused : 3, type : 8, len : 16; + char* word; + QueryOperand* item; +} HeadlineWordEntry; + +typedef struct { + HeadlineWordEntry* words; + int4 lenwords; + int4 curwords; + char* startsel; + char* stopsel; + char* fragdelim; + int2 startsellen; + int2 stopsellen; + int2 fragdelimlen; +} HeadlineParsedText; + +/* + * Common useful things for tsearch subsystem + */ +extern char* get_tsearch_config_filename(const char* basename, char* pathname, const char* extension, bool newfile); +extern char* get_tsfile_prefix_internal(); +extern List* get_tsfile_postfix(List* filenames, char sep); +extern List* copy_tsfile_to_local(List* filenames, List* postfixes, const char* dictprefix); +extern void copy_tsfile_to_remote(List* filenames, List* postfixes); +extern void copy_tsfile_to_backup(List* filenames); +extern void delete_tsfile_internal(const char* dictprefix, Oid tmplId); +extern bool inCluster(); + +/* + * Often useful stopword list management + */ +typedef struct { + int len; + char** stop; +} StopList; + +extern void readstoplist(const char* fname, StopList* s, char* (*wordop)(const char*)); +extern bool searchstoplist(StopList* s, const char* key); +extern void ts_check_feature_disable(); + +/* + * Interface with dictionaries + */ + +/* return struct for any lexize function */ +typedef struct { + /* ---------- + * Number of current variant of split word. For example the Norwegian + * word 'fotballklubber' has two variants to split: ( fotball, klubb ) + * and ( fot, ball, klubb ). So, dictionary should return: + * + * nvariant lexeme + * 1 fotball + * 1 klubb + * 2 fot + * 2 ball + * 2 klubb + * + * In general, a TSLexeme will be considered to belong to the same split + * variant as the previous one if they have the same nvariant value. + * The exact values don't matter, only changes from one lexeme to next. + * ---------- + */ + uint16 nvariant; + + uint16 flags; /* See flag bits below */ + + char* lexeme; /* C string */ +} TSLexeme; + +/* Flag bits that can appear in TSLexeme.flags */ +#define TSL_ADDPOS 0x01 +#define TSL_PREFIX 0x02 +#define TSL_FILTER 0x04 + +/* + * Struct for supporting complex dictionaries like thesaurus. + * 4th argument for dictlexize method is a pointer to this + */ +typedef struct { + bool isend; /* in: marks for lexize_info about text end is + * reached */ + bool getnext; /* out: dict wants next lexeme */ + void* private_state; /* internal dict state between calls with + * getnext == true */ +} DictSubState; + +/* + * generic superclass for configuration options nodes, and the only one filed + * meas the length of the configuration option struncate + */ +typedef struct ParserCfOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ +} ParserCfOpts; + +/* + * configuration option struncate specail for ngram parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct NgramCfOpts { + int32 vl_len_; + int gram_size; + bool punctuation_ignore; + bool grapsymbol_ignore; +} NgramCfOpts; + +/* + * configuration option struncate specail for ngram parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct PoundCfOpts { + int32 vl_len_; + char* split_flag; +} PoundCfOpts; + +/* + * configuration option struncate specail for Zhparser parser + * see congruent relationship in function tsearch_config_reloptions + */ +typedef struct ZhparserCfOpts { + int32 vl_len_; + bool punctuation_ignore; + bool seg_with_duality; + bool multi_short; + bool multi_duality; + bool multi_zmain; + bool multi_zall; +} ZhparserCfOpts; + +#endif /* _PG_TS_PUBLIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_type.h postgresql-hll-2.14/include/tsearch/ts_type.h --- postgresql-hll-2.14_old/include/tsearch/ts_type.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_type.h 2020-12-12 17:06:43.390349883 +0800 @@ -0,0 +1,279 @@ +/* ------------------------------------------------------------------------- + * + * ts_type.h + * Definitions for the tsvector and tsquery types + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_type.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TSTYPE_H_ +#define _PG_TSTYPE_H_ + +#include "fmgr.h" +#include "utils/memutils.h" +#include "utils/pg_crc.h" + +/* + * TSVector type. + * + * Structure of tsvector datatype: + * 1) standard varlena header + * 2) int4 size - number of lexemes (WordEntry array entries) + * 3) Array of WordEntry - one per lexeme; must be sorted according to + * tsCompareString() (ie, memcmp of lexeme strings). + * WordEntry->pos gives the number of bytes from end of WordEntry + * array to start of lexeme's string, which is of length len. + * 4) Per-lexeme data storage: + * lexeme string (not null-terminated) + * if haspos is true: + * padding byte if necessary to make the position data 2-byte aligned + * uint16 number of positions that follow + * WordEntryPos[] positions + * + * The positions for each lexeme must be sorted. + * + * Note, tsvectorsend/recv believe that sizeof(WordEntry) == 4 + */ +typedef struct { + uint32 haspos : 1, len : 11, /* MAX 2Kb */ + pos : 20; /* MAX 1Mb */ +} WordEntry; + +#define MAXSTRLEN ((1 << 11) - 1) +#define MAXSTRPOS ((1 << 20) - 1) + +/* + * Equivalent to + * typedef struct { + * uint16 + * weight:2, + * pos:14; + * } + */ +typedef uint16 WordEntryPos; + +typedef struct { + uint16 npos; + WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER]; /* variable length */ +} WordEntryPosVector; + +#define WEP_GETWEIGHT(x) ((x) >> 14) +#define WEP_GETPOS(x) ((x)&0x3fff) + +#define WEP_SETWEIGHT(x, v) ((x) = ((v) << 14) | ((x)&0x3fff)) +#define WEP_SETPOS(x, v) ((x) = ((x)&0xc000) | ((v)&0x3fff)) + +#define MAXENTRYPOS (1 << 14) +#define MAXNUMPOS (256) +#define LIMITPOS(x) (((x) >= MAXENTRYPOS) ? (MAXENTRYPOS - 1) : (x)) + +/* This struct represents a complete tsvector datum */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 size; + WordEntry entries[FLEXIBLE_ARRAY_MEMBER]; /* variable length */ + /* lexemes follow the entries[] array */ +} TSVectorData; + +typedef TSVectorData* TSVector; + +#define DATAHDRSIZE (offsetof(TSVectorData, entries)) +#define CALCDATASIZE(nentries, lenstr) (DATAHDRSIZE + (nentries) * sizeof(WordEntry) + (lenstr)) + +/* pointer to start of a tsvector's WordEntry array */ +#define ARRPTR(x) ((x)->entries) + +/* pointer to start of a tsvector's lexeme storage */ +#define STRPTR(x) ((char*)&(x)->entries[(x)->size]) + +#define _POSVECPTR(x, e) ((WordEntryPosVector*)(STRPTR(x) + SHORTALIGN((e)->pos + (e)->len))) +#define POSDATALEN(x, e) (((e)->haspos) ? (_POSVECPTR(x, e)->npos) : 0) +#define POSDATAPTR(x, e) (_POSVECPTR(x, e)->pos) + +/* + * fmgr interface macros + */ +#define DatumGetTSVector(X) ((TSVector)PG_DETOAST_DATUM(X)) +#define DatumGetTSVectorCopy(X) ((TSVector)PG_DETOAST_DATUM_COPY(X)) +#define TSVectorGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_TSVECTOR(n) DatumGetTSVector(PG_GETARG_DATUM(n)) +#define PG_GETARG_TSVECTOR_COPY(n) DatumGetTSVectorCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_TSVECTOR(x) return TSVectorGetDatum(x) + +/* + * I/O + */ +extern Datum tsvectorin(PG_FUNCTION_ARGS); +extern Datum tsvectorout(PG_FUNCTION_ARGS); +extern Datum tsvectorsend(PG_FUNCTION_ARGS); +extern Datum tsvectorrecv(PG_FUNCTION_ARGS); + +/* + * operations with tsvector + */ +extern Datum tsvector_lt(PG_FUNCTION_ARGS); +extern Datum tsvector_le(PG_FUNCTION_ARGS); +extern Datum tsvector_eq(PG_FUNCTION_ARGS); +extern Datum tsvector_ne(PG_FUNCTION_ARGS); +extern Datum tsvector_ge(PG_FUNCTION_ARGS); +extern Datum tsvector_gt(PG_FUNCTION_ARGS); +extern Datum tsvector_cmp(PG_FUNCTION_ARGS); + +extern Datum tsvector_length(PG_FUNCTION_ARGS); +extern Datum tsvector_strip(PG_FUNCTION_ARGS); +extern Datum tsvector_setweight(PG_FUNCTION_ARGS); +extern Datum tsvector_concat(PG_FUNCTION_ARGS); +extern Datum tsvector_update_trigger_byid(PG_FUNCTION_ARGS); +extern Datum tsvector_update_trigger_bycolumn(PG_FUNCTION_ARGS); + +extern Datum ts_match_vq(PG_FUNCTION_ARGS); +extern Datum ts_match_qv(PG_FUNCTION_ARGS); +extern Datum ts_match_tt(PG_FUNCTION_ARGS); +extern Datum ts_match_tq(PG_FUNCTION_ARGS); + +extern Datum ts_stat1(PG_FUNCTION_ARGS); +extern Datum ts_stat2(PG_FUNCTION_ARGS); + +extern Datum ts_rank_tt(PG_FUNCTION_ARGS); +extern Datum ts_rank_wtt(PG_FUNCTION_ARGS); +extern Datum ts_rank_ttf(PG_FUNCTION_ARGS); +extern Datum ts_rank_wttf(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_tt(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_wtt(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_ttf(PG_FUNCTION_ARGS); +extern Datum ts_rankcd_wttf(PG_FUNCTION_ARGS); + +extern Datum tsmatchsel(PG_FUNCTION_ARGS); +extern Datum tsmatchjoinsel(PG_FUNCTION_ARGS); + +extern Datum ts_typanalyze(PG_FUNCTION_ARGS); + +/* + * TSQuery + */ +typedef int8 QueryItemType; + +/* Valid values for QueryItemType: */ +#define QI_VAL 1 +#define QI_OPR 2 +#define QI_VALSTOP \ + 3 /* This is only used in an intermediate stack \ + * representation in parse_tsquery. It's not a \ + * legal type elsewhere. */ +/* + * QueryItem is one node in tsquery - operator or operand. + */ +typedef struct { + QueryItemType type; /* operand or kind of operator (ts_tokentype) */ + uint8 weight; /* weights of operand to search. It's a + * bitmask of allowed weights. if it =0 then + * any weight are allowed. Weights and bit + * map: A: 1<<3 B: 1<<2 C: 1<<1 D: 1<<0 */ + bool prefix; /* true if it's a prefix search */ + int32 valcrc; /* XXX: pg_crc32 would be a more appropriate + * data type, but we use comparisons to signed + * integers in the code. They would need to be + * changed as well. */ + + /* pointer to text value of operand, must correlate with WordEntry */ + uint32 length : 12, distance : 20; +} QueryOperand; + +/* Legal values for QueryOperator.operator */ +#define OP_NOT 1 +#define OP_AND 2 +#define OP_OR 3 + +typedef struct { + QueryItemType type; + int8 oper; /* see above */ + uint32 left; /* pointer to left operand. Right operand is + * item + 1, left operand is placed + * item+item->left */ +} QueryOperator; + +/* + * Note: TSQuery is 4-bytes aligned, so make sure there's no fields + * inside QueryItem requiring 8-byte alignment, like int64. + */ +typedef union { + QueryItemType type; + QueryOperator qoperator; + QueryOperand qoperand; +} QueryItem; + +/* + * Storage: + * (len)(size)(array of QueryItem)(operands as '\0'-terminated c-strings) + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int4 size; /* number of QueryItems */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* data starts here */ +} TSQueryData; + +typedef TSQueryData* TSQuery; + +#define HDRSIZETQ (VARHDRSZ + sizeof(int4)) + +/* Computes the size of header and all QueryItems. size is the number of + * QueryItems, and lenofoperand is the total length of all operands + */ +#define COMPUTESIZE(size, lenofoperand) (HDRSIZETQ + (size) * sizeof(QueryItem) + (lenofoperand)) +#define TSQUERY_TOO_BIG(size, lenofoperand) \ + ((int)(size) > (int)((MaxAllocSize - HDRSIZETQ - (lenofoperand)) / sizeof(QueryItem))) + +/* Returns a pointer to the first QueryItem in a TSQuery */ +#define GETQUERY(x) ((QueryItem*)((char*)(x) + HDRSIZETQ)) + +/* Returns a pointer to the beginning of operands in a TSQuery */ +#define GETOPERAND(x) ((char*)GETQUERY(x) + ((TSQuery)(x))->size * sizeof(QueryItem)) + +/* + * fmgr interface macros + * Note, TSQuery type marked as plain storage, so it can't be toasted + * but PG_DETOAST_DATUM_COPY is used for simplicity + */ +#define DatumGetTSQuery(X) ((TSQuery)DatumGetPointer(X)) +#define DatumGetTSQueryCopy(X) ((TSQuery)PG_DETOAST_DATUM_COPY(X)) +#define TSQueryGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_TSQUERY(n) DatumGetTSQuery(PG_GETARG_DATUM(n)) +#define PG_GETARG_TSQUERY_COPY(n) DatumGetTSQueryCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_TSQUERY(x) return TSQueryGetDatum(x) + +/* + * I/O + */ +extern Datum tsqueryin(PG_FUNCTION_ARGS); +extern Datum tsqueryout(PG_FUNCTION_ARGS); +extern Datum tsquerysend(PG_FUNCTION_ARGS); +extern Datum tsqueryrecv(PG_FUNCTION_ARGS); + +/* + * operations with tsquery + */ +extern Datum tsquery_lt(PG_FUNCTION_ARGS); +extern Datum tsquery_le(PG_FUNCTION_ARGS); +extern Datum tsquery_eq(PG_FUNCTION_ARGS); +extern Datum tsquery_ne(PG_FUNCTION_ARGS); +extern Datum tsquery_ge(PG_FUNCTION_ARGS); +extern Datum tsquery_gt(PG_FUNCTION_ARGS); +extern Datum tsquery_cmp(PG_FUNCTION_ARGS); + +extern Datum tsquerytree(PG_FUNCTION_ARGS); +extern Datum tsquery_numnode(PG_FUNCTION_ARGS); + +extern Datum tsquery_and(PG_FUNCTION_ARGS); +extern Datum tsquery_or(PG_FUNCTION_ARGS); +extern Datum tsquery_not(PG_FUNCTION_ARGS); + +extern Datum tsquery_rewrite(PG_FUNCTION_ARGS); +extern Datum tsquery_rewrite_query(PG_FUNCTION_ARGS); + +extern Datum tsq_mcontains(PG_FUNCTION_ARGS); +extern Datum tsq_mcontained(PG_FUNCTION_ARGS); + +#endif /* _PG_TSTYPE_H_ */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_utils.h postgresql-hll-2.14/include/tsearch/ts_utils.h --- postgresql-hll-2.14_old/include/tsearch/ts_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_utils.h 2020-12-12 17:06:43.391349896 +0800 @@ -0,0 +1,261 @@ +/* ------------------------------------------------------------------------- + * + * ts_utils.h + * helper utilities for tsearch + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/tsearch/ts_utils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_TS_UTILS_H_ +#define _PG_TS_UTILS_H_ + +#include "tsearch/ts_public.h" +#include "tsearch/ts_type.h" +#include "tsearch/ts_zh_ngram.h" +#include "tsearch/ts_zh_pound.h" +#include "nodes/pg_list.h" + +/* + * Common parse definitions for tsvector and tsquery + */ +/* tsvector parser support. */ +struct TSVectorParseStateData; /* opaque struct in tsvector_parser.c */ +typedef struct TSVectorParseStateData* TSVectorParseState; + +extern TSVectorParseState init_tsvector_parser(char* input, bool oprisdelim, bool is_tsquery); +extern void reset_tsvector_parser(TSVectorParseState state, char* input); +extern bool gettoken_tsvector( + TSVectorParseState state, char** token, int* len, WordEntryPos** pos, int* poslen, char** endptr); +extern void close_tsvector_parser(TSVectorParseState state); + +/* parse_tsquery */ +struct TSQueryParserStateData; /* private in backend/utils/adt/tsquery.c */ +typedef struct TSQueryParserStateData* TSQueryParserState; + +typedef void (*PushFunction)(Datum opaque, TSQueryParserState state, const char* token, int tokenlen, + int2 tokenweights, /* bitmap as described + * in QueryOperand + * struct */ + bool prefix); + +extern TSQuery parse_tsquery(char* buf, PushFunction pushval, Datum opaque, bool isplain); + +/* Functions for use by PushFunction implementations */ +extern void pushValue(TSQueryParserState state, const char* strval, int lenval, int2 weight, bool prefix); +extern void pushStop(TSQueryParserState state); +extern void pushOperator(TSQueryParserState state, int8 oper); + +/* + * parse plain text and lexize words + */ +typedef struct { + uint16 len; + uint16 nvariant; + union { + uint16 pos; + + /* + * When apos array is used, apos[0] is the number of elements in the + * array (excluding apos[0]), and alen is the allocated size of the + * array. + */ + uint16* apos; + } pos; + uint16 flags; /* currently, only TSL_PREFIX */ + char* word; + uint32 alen; +} ParsedWord; + +typedef struct { + ParsedWord* words; + int4 lenwords; + int4 curwords; + int4 pos; +} ParsedText; + +extern void parsetext(Oid cfgId, ParsedText* prs, const char* buf, int4 buflen); + +/* + * headline framework, flow in common to generate: + * 1 parse text with hlparsetext + * 2 parser-specific function to find part + * 3 generateHeadline to generate result text + */ +extern void hlparsetext(Oid cfgId, HeadlineParsedText* prs, TSQuery query, const char* buf, int4 buflen); +extern text* generateHeadline(HeadlineParsedText* prs); + +/* + * Common check function for tsvector @@ tsquery + */ +extern bool TS_execute( + QueryItem* curitem, void* checkval, bool calcnot, bool (*chkcond)(const void* checkval, QueryOperand* val)); +extern bool tsquery_requires_match(QueryItem* curitem); + +/* + * to_ts* - text transformation to tsvector, tsquery + */ +extern TSVector make_tsvector(ParsedText* prs); +extern int32 tsCompareString(const char* a, int lena, const char* b, int lenb, bool prefix); + +extern Datum to_tsvector_byid(PG_FUNCTION_ARGS); +extern Datum to_tsvector(PG_FUNCTION_ARGS); +extern Datum to_tsquery_byid(PG_FUNCTION_ARGS); +extern Datum to_tsquery(PG_FUNCTION_ARGS); +extern Datum plainto_tsquery_byid(PG_FUNCTION_ARGS); +extern Datum plainto_tsquery(PG_FUNCTION_ARGS); + +/* + * GiST support function + */ +extern Datum gtsvector_compress(PG_FUNCTION_ARGS); +extern Datum gtsvector_decompress(PG_FUNCTION_ARGS); +extern Datum gtsvector_consistent(PG_FUNCTION_ARGS); +extern Datum gtsvector_union(PG_FUNCTION_ARGS); +extern Datum gtsvector_same(PG_FUNCTION_ARGS); +extern Datum gtsvector_penalty(PG_FUNCTION_ARGS); +extern Datum gtsvector_picksplit(PG_FUNCTION_ARGS); + +/* + * IO functions for pseudotype gtsvector + * used internally in tsvector GiST opclass + */ +extern Datum gtsvectorin(PG_FUNCTION_ARGS); +extern Datum gtsvectorout(PG_FUNCTION_ARGS); + +/* + * GIN support function + */ +extern Datum gin_extract_tsvector(PG_FUNCTION_ARGS); +extern Datum gin_cmp_tslexeme(PG_FUNCTION_ARGS); +extern Datum gin_cmp_prefix(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsquery(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_consistent(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_triconsistent(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsvector_2args(PG_FUNCTION_ARGS); +extern Datum gin_extract_tsquery_5args(PG_FUNCTION_ARGS); +extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS); + +/* + * Possible strategy numbers for indexes + * TSearchStrategyNumber - (tsvector|text) @@ tsquery + * TSearchWithClassStrategyNumber - tsvector @@@ tsquery + */ +#define TSearchStrategyNumber 1 +#define TSearchWithClassStrategyNumber 2 + +/* + * TSQuery Utilities + */ +extern QueryItem* clean_NOT(QueryItem* ptr, int4* len); +extern QueryItem* clean_fakeval(QueryItem* ptr, int4* len); + +typedef struct QTNode { + QueryItem* valnode; + uint32 flags; + int4 nchild; + char* word; + uint32 sign; + struct QTNode** child; +} QTNode; + +/* bits in QTNode.flags */ +#define QTN_NEEDFREE 0x01 +#define QTN_NOCHANGE 0x02 +#define QTN_WORDFREE 0x04 + +typedef uint64 TSQuerySign; + +#define TSQS_SIGLEN (sizeof(TSQuerySign) * BITS_PER_BYTE) + +#define TSQuerySignGetDatum(X) Int64GetDatum((int64)(X)) +#define DatumGetTSQuerySign(X) ((TSQuerySign)DatumGetInt64(X)) +#define PG_RETURN_TSQUERYSIGN(X) return TSQuerySignGetDatum(X) +#define PG_GETARG_TSQUERYSIGN(n) DatumGetTSQuerySign(PG_GETARG_DATUM(n)) + +extern QTNode* QT2QTN(QueryItem* in, char* operand); +extern TSQuery QTN2QT(QTNode* in); +extern void QTNFree(QTNode* in); +extern void QTNSort(QTNode* in); +extern void QTNTernary(QTNode* in); +extern void QTNBinary(QTNode* in); +extern int QTNodeCompare(QTNode* an, QTNode* bn); +extern QTNode* QTNCopy(QTNode* in); +extern void QTNClearFlags(QTNode* in, uint32 flags); +extern bool QTNEq(QTNode* a, QTNode* b); +extern TSQuerySign makeTSQuerySign(TSQuery a); +extern QTNode* findsubquery(QTNode* root, QTNode* ex, QTNode* subs, bool* isfind); + +/* + * TSQuery GiST support + */ +extern Datum gtsquery_compress(PG_FUNCTION_ARGS); +extern Datum gtsquery_decompress(PG_FUNCTION_ARGS); +extern Datum gtsquery_consistent(PG_FUNCTION_ARGS); +extern Datum gtsquery_union(PG_FUNCTION_ARGS); +extern Datum gtsquery_same(PG_FUNCTION_ARGS); +extern Datum gtsquery_penalty(PG_FUNCTION_ARGS); +extern Datum gtsquery_picksplit(PG_FUNCTION_ARGS); + +/* + * Parser interface to SQL + */ +extern Datum ts_token_type_byid(PG_FUNCTION_ARGS); +extern Datum ts_token_type_byname(PG_FUNCTION_ARGS); +extern Datum ts_parse_byid(PG_FUNCTION_ARGS); +extern Datum ts_parse_byname(PG_FUNCTION_ARGS); + +/* + * Default word parser + */ +extern Datum prsd_start(PG_FUNCTION_ARGS); +extern Datum prsd_nexttoken(PG_FUNCTION_ARGS); +extern Datum prsd_end(PG_FUNCTION_ARGS); +extern Datum prsd_headline(PG_FUNCTION_ARGS); +extern Datum prsd_lextype(PG_FUNCTION_ARGS); + +/* + * Dictionary interface to SQL + */ +extern Datum ts_lexize(PG_FUNCTION_ARGS); + +/* + * Simple built-in dictionary + */ +extern Datum dsimple_init(PG_FUNCTION_ARGS); +extern Datum dsimple_lexize(PG_FUNCTION_ARGS); + +/* + * Synonym built-in dictionary + */ +extern Datum dsynonym_init(PG_FUNCTION_ARGS); +extern Datum dsynonym_lexize(PG_FUNCTION_ARGS); + +/* + * ISpell dictionary + */ +extern Datum dispell_init(PG_FUNCTION_ARGS); +extern Datum dispell_lexize(PG_FUNCTION_ARGS); + +/* + * Thesaurus + */ +extern Datum thesaurus_init(PG_FUNCTION_ARGS); +extern Datum thesaurus_lexize(PG_FUNCTION_ARGS); + +/* + * headline + */ +extern Datum ts_headline_byid_opt(PG_FUNCTION_ARGS); +extern Datum ts_headline_byid(PG_FUNCTION_ARGS); +extern Datum ts_headline(PG_FUNCTION_ARGS); +extern Datum ts_headline_opt(PG_FUNCTION_ARGS); + +/* + * current cfg + */ +extern Datum get_current_ts_config(PG_FUNCTION_ARGS); + +#endif /* _PG_TS_UTILS_H_ */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_zh_ngram.h postgresql-hll-2.14/include/tsearch/ts_zh_ngram.h --- postgresql-hll-2.14_old/include/tsearch/ts_zh_ngram.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_zh_ngram.h 2020-12-12 17:06:43.391349896 +0800 @@ -0,0 +1,293 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_ngram.h + * N-gram algorithm functions for full-text search of Chinese + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_ngram.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TS_ZH_NGRAM_H +#define TS_ZH_NGRAM_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" +#include "mb/pg_wchar.h" + +#define MAX_CHAR_LEN 8 +#define MAX_CACHED_CHAR 256 + +typedef uint8 (*zhParser)(const char* ch, uint8* len); + +typedef struct { + zhParser parser; /* text search parser */ + char* str; /* text to parse */ + int len; /* text length */ + char* next; /* next char pointer */ + int post; /* position of parsed string */ + + char* cache; /* pointe to parsed but not returned token */ + int max_cached_num; /* cached char number */ + uint8* char_width; /* array record each char length */ + uint8* char_flag; /* array record each char type */ + int cached_size; /* already dealt bytes in cache */ + int cached_counter; /* already dealt chars in cache */ + bool cached; /* if cahced tokens */ + + char* token; /* token pointer to return */ + int char_size; /* bytes number to return */ + int char_counter; /* char number to return */ + int token_type; /* token type to renturn */ +} ZhParserState; + +/* char type defined for text search */ +#define CHAR_ILLEGALCHAR 0 +#define CHAR_ZHWORD 1 +#define CHAR_DIGHT 2 +#define CHAR_ENLETTER 3 +#define CHAR_BLANK 4 +#define CHAR_RADIXPOINT 5 +#define CHAR_PUNCTUATION 6 +#define CHAR_GRAPSYMBOL 7 + +/* Output token categories */ +#define ZHWORDS 1 +#define ENWORD 2 +#define NUMERIC 3 +#define ALNUM 4 +#define GRAPSYMBOL 5 +#define MULTISYMBOL 6 + +const char* const zh_tok_alias[] = {"", "zh_words", "en_word", "numeric", "alnum", "grapsymbol", "multisymbol"}; + +const char* const zh_lex_descr[] = { + "", "chinese words", "english word", "numeric data", "alnum string", "graphic symbol", "multiple symbol"}; + +extern uint8 ascii_matrix[8][16]; + +extern uint8 gbk_high_byte_matrix[8][16]; + +extern uint8 gbk_zh_word_matrix[3][16][16]; + +extern uint8 gbk_grap_symbol_matrix[10][16][16]; + +extern uint8 utf8_symbols_punctuation_matrix[4][16]; + +extern uint8 fullwidth_ascii_variants_matrix[4][4][16]; + +#define to_unsigned(ch) ((unsigned char)(*(ch))) +#define HFB(ch) ((to_unsigned(ch) & 0x00F0) >> 4) /* hight 4-bit value in a byte */ +#define LFB(ch) (to_unsigned(ch) & 0x0F) /* low 4-bit value in a byte */ + +/* maps to chinese word region if return true */ +#define GBK_ZH_REGION(L, R) (gbk_high_byte_matrix[L][R] & 0x0F) + +/* maps to graphic symbol region if return true */ +#define GBK_GP_REGION(L, R) ((gbk_high_byte_matrix[L][R] & 0x00F0) >> 4) + +/* + * @Description: map a dword char to char type + * + * @in ch: dword char + * @return: predefined char type + */ +inline uint8 gbk_dword_parser(const char* ch) +{ + uint8 HL = HFB(ch) & 0x07; /* (the fist byte's high-4-bit value) - 8 */ + uint8 HR = LFB(ch); /* fist byte's low-4-bit value */ + uint8 LL = HFB(ch + 1); /* second byte's high-4-bit value */ + uint8 LR = LFB(ch + 1); /* second byte's low-4-bit value */ + + if (likely(GBK_ZH_REGION(HL, HR))) /* in chinese word region */ + return gbk_zh_word_matrix[GBK_ZH_REGION(HL, HR)][LL][LR]; + + if (GBK_GP_REGION(HL, HR)) /* in graphic symbol region */ + return gbk_grap_symbol_matrix[GBK_GP_REGION(HL, HR)][LL][LR]; + + return CHAR_ILLEGALCHAR; +} + +/**************************** UTF-8 Encoding Info *****************************/ +/* + * Unicode 8.0 Character Code Charts + */ + +/* + * General Punctuation + * Unnicode Range: 2000 - 206F + * binary: (00100000 00000000 ~ 00100000 01101111) + * + * UTF8 Range: 0xE28080 - 0xE281AF + * binary: (11100010 10000000 10000000 ~ 11100010 10000001 10101111) + */ +#define GENERAL_PUNCTUATION_LOWER 0xE28080 +#define GENERAL_PUNCTUATION_UPPER 0xE281AF + +/* + * CJK Symbols and Punctuation + * Unnicode Range: 3000 - 303F + * binary: (00110000 00000000 ~ 0011 0000 00111111) + * + * UTF8 Range: 0xE38080 - 0xE380BF + * binary: (11100011 10000000 10000000 ~ 11100011 10000000 10111111) + * + * Last byte's range is 10 00 0000 ~ 10 11 1111 + */ +#define CJK_SYMBOLS_AND_PUNCTUATION_LOWER 0xE38080 +#define CJK_SYMBOLS_AND_PUNCTUATION_UPPER 0xE380BF + +#define UTF8_SYMBOLS_PUNCTUATION_REGION(ch) (utf8_symbols_punctuation_matrix[HFB(ch + 2) & 0x03][LFB(ch + 2)]) + +/* + * UTF8 Chinese word region description + * + * CJK Unified Ideographs (3 bytes) + * Unnicode Range: 4E00 - 9FD5 + * binary: (01001110 00000000 ~ 10011111 11010101) + * UTF8 Range: 0xE4B880 - 0xE9BF95 + * binary: (11100100 10111000 10000000 ~ 11101001 10111111 10010101) + * + * CJK Extension-A (3 bytes) + * Unnicode Range: 0x3400 - 0x4DB5 + * binary: (00110100 00000000 ~ 01001101 10110101) + * UTF8 Range: 0xE39080 - 0xE4B6B5 + * binary: (11100011 10010000 10000000 ~ 11100100 10110110 10110101) + * + * CJK Extension-B (4 bytes) + * Unnicode Range: 0x20000 - 0x2A6D6 + * binary: (00000010 00000000 00000000 ~ 00000010 10100110 11010110) + * UTF8 Range: 0xF0A08080 - 0xF0AA9B96 + * binary: (11110000 10100000 10000000 10000000 ~ 11110000 10101010 10011011 10010110) + */ +#define CJK_UNIFIED_IDEOGRAPHS_LOWER 0xE4B880 +#define CJK_UNIFIED_IDEOGRAPHS_UPPER 0xE9BF95 + +#define CJK_EXTENSION_A_LOWER 0xE39080 +#define CJK_EXTENSION_A_UPPER 0xE4B6B5 + +#define CJK_EXTENSION_B_LOWER 0xF0A08080 +#define CJK_EXTENSION_B_UPPER 0xF0AA9B96 + +/* + * + * Halfwidth and Fullwidth Forms description: + * Unnicode Range: FF00 - FFEF + * binary:(11111111 00000000 ~ 11111111 11101111) + * Fullwidth Dight:FF10-FF19 + * binary: (11111111 00010000 ~ 11111111 00011001) + * Fullwidth Uppercase:FF21-FF3A + * binary: (11111111 00100001 ~ 11111111 00111010) + * Fullwidth Lowercase:FF41-FF5A + * binary: (11111111 01000001 ~ 11111111 01011010) + * + * UTF8 Range: 0xEFBC80 - 0xEFBFAF + * binary: (11101111 10111100 10000000 ~ 11101111 10111111 10101111) + * Fullwidth Dight:0xEFBC90-0xEFBC99 + * binary: (11101111 10111100 10010000 ~ 11101111 10111100 10011001) + * Fullwidth Uppercase:0xEFBCA1-0xEFBCBA + * binary: (11101111 10111100 10100001 ~ 11101111 10111100 10111010) + * Fullwidth Lowercase:0xEFBE81-0xEFBD9A + * binary: (11101111 10111101 10000001 ~ 11101111 10111101 10011010) + * + * Last 2-byte's rang is 00 00 0000 ~ 11 10 1111 + * + */ +#define HALFWIDTH_AND_FULLWIDTH_FORMS_LOWER 0xEFBC80 +#define HALFWIDTH_AND_FULLWIDTH_FORMS_UPPER 0xEFBFAF + +#define UTF8_FULLWIDTH_ASCII_VARIANTS_REGION(ch) \ + fullwidth_ascii_variants_matrix[LFB(ch + 1) & 0x03][HFB(ch + 2) & 0x03][LFB(ch + 2)] + +#define utf8_len(value, mask, ch) (value == (mask & to_unsigned(ch))) +/* + * @Description: maps to char type for a UTF8 endcoding char + * + * @in ch: UTF8 endcoding char pointer to parser + * @out len: UTF8 char length + * @return: char type defined in front + */ +inline uint8 utf8_parser(const char* ch, uint8* len) +{ + if (likely(utf8_len(0xC0, 0xE0, ch))) { /* 2 byte */ + *len = 2; + return CHAR_GRAPSYMBOL; + } else if (likely(utf8_len(0xE0, 0xF0, ch))) { /* 3 byte */ + pg_wchar wchar = 0x00FFFFFF; + *len = 3; + wchar = wchar & ((to_unsigned(ch) << 16) | (to_unsigned(ch + 1) << 8) | to_unsigned(ch + 2)); + + if (unlikely(wchar < GENERAL_PUNCTUATION_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar < GENERAL_PUNCTUATION_UPPER)) { + return CHAR_PUNCTUATION; + } else if (unlikely(wchar < CJK_SYMBOLS_AND_PUNCTUATION_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_SYMBOLS_AND_PUNCTUATION_UPPER)) { /* in CJK Symbols and Punctuation Region */ + return UTF8_SYMBOLS_PUNCTUATION_REGION(ch); + } else if (unlikely(wchar < CJK_EXTENSION_A_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_EXTENSION_A_UPPER)) { /* in CJK Extension-A Region */ + return CHAR_ZHWORD; + } else if (unlikely(wchar < CJK_UNIFIED_IDEOGRAPHS_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= CJK_UNIFIED_IDEOGRAPHS_UPPER)) { /* in CJK Unified Ideographs Region */ + return CHAR_ZHWORD; + } else if (unlikely(wchar < HALFWIDTH_AND_FULLWIDTH_FORMS_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (likely(wchar <= HALFWIDTH_AND_FULLWIDTH_FORMS_UPPER)) { /* in Halfwidth and Fullwidth Forms region */ + return UTF8_FULLWIDTH_ASCII_VARIANTS_REGION(ch); + } else { + return CHAR_GRAPSYMBOL; + } + } else if (utf8_len(0xF0, 0xF8, ch)) { /* 4 byte */ + pg_wchar wchar = + ((to_unsigned(ch) << 24) | (to_unsigned(ch + 1) << 16) | (to_unsigned(ch + 2) << 8) | to_unsigned(ch + 3)); + *len = 4; + + if (unlikely(wchar < CJK_EXTENSION_B_LOWER)) { + return CHAR_GRAPSYMBOL; + } else if (wchar <= CJK_EXTENSION_B_UPPER) { + return CHAR_ZHWORD; + } else { + return CHAR_GRAPSYMBOL; + } +#ifdef NOT_USED + } else if (unlikely(utf8_len(0xF8, 0xFC, ch))) { /* 5 byte */ + *len = 5; + return CHAR_GRAPSYMBOL; + } else if (unlikely(utf8_len(0xFC, 0xFE, ch))) { /* 6 byte */ + *len = 6; + return CHAR_GRAPSYMBOL; +#endif + } else { + *len = 1; + return CHAR_GRAPSYMBOL; + } +} + +extern void zhParserStateInit(char* str, int len, ZhParserState* parserState); +extern void zhParserStateDestroy(ZhParserState* parserState); + +/* ngram parser functions for chinese */ +extern Datum ngram_start(PG_FUNCTION_ARGS); +extern Datum ngram_nexttoken(PG_FUNCTION_ARGS); +extern Datum ngram_end(PG_FUNCTION_ARGS); +extern Datum ngram_lextype(PG_FUNCTION_ARGS); + +#endif /* TS_ZH_NGRAM_H */ diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_zh_pound.h postgresql-hll-2.14/include/tsearch/ts_zh_pound.h --- postgresql-hll-2.14_old/include/tsearch/ts_zh_pound.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_zh_pound.h 2020-12-12 17:06:43.391349896 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_pound.h + * '#' split functions for full-text search of Chinese + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_pound.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef TS_ZH_POUND_H +#define TS_ZH_POUND_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "fmgr.h" + +/* pound parser functions for chinese */ +extern Datum pound_start(PG_FUNCTION_ARGS); +extern Datum pound_nexttoken(PG_FUNCTION_ARGS); +extern Datum pound_end(PG_FUNCTION_ARGS); +extern Datum pound_lextype(PG_FUNCTION_ARGS); + +#endif /* TS_ZH_POUND_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/tsearch/ts_zh_zhparser.h postgresql-hll-2.14/include/tsearch/ts_zh_zhparser.h --- postgresql-hll-2.14_old/include/tsearch/ts_zh_zhparser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/tsearch/ts_zh_zhparser.h 2020-12-12 17:06:43.391349896 +0800 @@ -0,0 +1,27 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ts_zh_zhparser.h + * + * + * + * IDENTIFICATION + * src/include/tsearch/ts_zh_zhparser.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ZHPARSER_H +#define ZHPARSER_H +#endif diff -uprN postgresql-hll-2.14_old/include/utils/acl.h postgresql-hll-2.14/include/utils/acl.h --- postgresql-hll-2.14_old/include/utils/acl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/acl.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,380 @@ +/* ------------------------------------------------------------------------- + * + * acl.h + * Definition of (and support for) access control list data structures. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/acl.h + * + * NOTES + * An ACL array is simply an array of AclItems, representing the union + * of the privileges represented by the individual items. A zero-length + * array represents "no privileges". There are no assumptions about the + * ordering of the items, but we do expect that there are no two entries + * in the array with the same grantor and grantee. + * + * For backward-compatibility purposes we have to allow null ACL entries + * in system catalogs. A null ACL will be treated as meaning "default + * protection" (i.e., whatever acldefault() returns). + * ------------------------------------------------------------------------- + */ +#ifndef ACL_H +#define ACL_H + +#include "nodes/parsenodes.h" +#include "utils/array.h" +#include "utils/guc.h" +#include "utils/snapshot.h" + +/* + * typedef AclMode is declared in parsenodes.h, also the individual privilege + * bit meanings are defined there + */ + +#define ACL_ID_PUBLIC 0 /* placeholder for id in a PUBLIC acl item */ + +/* + * AclItem + * + * Note: must be same size on all platforms, because the size is hardcoded + * in the pg_type.h entry for aclitem. + */ +typedef struct AclItem { + Oid ai_grantee; /* ID that this item grants privs to */ + Oid ai_grantor; /* grantor of privs */ + AclMode ai_privs; /* privilege bits */ +} AclItem; + +/* type of privileges */ +typedef enum { DML_PRIVS_INDEX = 0, DDL_PRIVS_INDEX } PRIVS_INDEX; +#define PRIVS_ATTR_NUM 2 + +/* + * The upper 16 bits of the ai_privs field of an AclItem are the grant option + * bits, and the lower 16 bits are the actual privileges. We use "rights" + * to mean the combined grant option and privilege bits fields. + */ +#define ACLITEM_GET_PRIVS(item) ((item).ai_privs & 0xFFFF) +#define ACLITEM_GET_GOPTIONS(item) (((item).ai_privs >> 16) & 0xFFFF) +#define ACLITEM_GET_RIGHTS(item) ((item).ai_privs) + +#define ACL_GRANT_OPTION_FOR(privs) (((AclMode)(privs)&0xFFFF) << 16) +#define ACL_OPTION_TO_PRIVS(privs) (((AclMode)(privs) >> 16) & 0xFFFF) + +#define ACLMODE_FOR_DDL(privs) (((privs) & FLAG_FOR_DDL_ACL) == 0 ? false : true) +/* remove ddl privileges flag from Aclitem */ +#define REMOVE_DDL_FLAG(privs) ((privs) & (~((AclMode)FLAG_FOR_DDL_ACL & 0xFFFF))) +/* add ddl privileges flag to Aclitem */ +#define ADD_DDL_FLAG(privs) ((privs) | ((AclMode)FLAG_FOR_DDL_ACL & 0xFFFF)) + +#define ACLITEM_SET_PRIVS(item, privs) \ + ((item).ai_privs = ((item).ai_privs & ~((AclMode)0xFFFF)) | ((AclMode)(privs)&0xFFFF)) +#define ACLITEM_SET_GOPTIONS(item, goptions) \ + ((item).ai_privs = ((item).ai_privs & ~(((AclMode)0xFFFF) << 16)) | (((AclMode)(goptions)&0xFFFF) << 16)) +#define ACLITEM_SET_RIGHTS(item, rights) ((item).ai_privs = (AclMode)(rights)) + +#define ACLITEM_SET_PRIVS_GOPTIONS(item, privs, goptions) \ + ((item).ai_privs = ((AclMode)(privs)&0xFFFF) | (((AclMode)(goptions)&0xFFFF) << 16)) + +#define ACLITEM_ALL_PRIV_BITS ((AclMode)0xFFFF) +#define ACLITEM_ALL_GOPTION_BITS ((AclMode)0xFFFF << 16) + +/* + * Definitions for convenient access to Acl (array of AclItem). + * These are standard PostgreSQL arrays, but are restricted to have one + * dimension and no nulls. We also ignore the lower bound when reading, + * and set it to one when writing. + * + * CAUTION: as of PostgreSQL 7.1, these arrays are toastable (just like all + * other array types). Therefore, be careful to detoast them with the + * macros provided, unless you know for certain that a particular array + * can't have been toasted. + */ + +/* + * Acl a one-dimensional array of AclItem + */ +typedef ArrayType Acl; + +#define ACL_NUM(ACL) (ARR_DIMS(ACL)[0]) +#define ACL_DAT(ACL) ((AclItem*)ARR_DATA_PTR(ACL)) +#define ACL_N_SIZE(N) (ARR_OVERHEAD_NONULLS(1) + ((N) * sizeof(AclItem))) +#define ACL_SIZE(ACL) ARR_SIZE(ACL) + +/* + * fmgr macros for these types + */ +#define DatumGetAclItemP(X) ((AclItem*)DatumGetPointer(X)) +#define PG_GETARG_ACLITEM_P(n) DatumGetAclItemP(PG_GETARG_DATUM(n)) +#define PG_RETURN_ACLITEM_P(x) PG_RETURN_POINTER(x) + +#define DatumGetAclP(X) ((Acl*)PG_DETOAST_DATUM(X)) +#define DatumGetAclPCopy(X) ((Acl*)PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_ACL_P(n) DatumGetAclP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ACL_P_COPY(n) DatumGetAclPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_ACL_P(x) PG_RETURN_POINTER(x) + +/* + * ACL modification opcodes for aclupdate + */ +#define ACL_MODECHG_ADD 1 +#define ACL_MODECHG_DEL 2 +#define ACL_MODECHG_EQL 3 + +/* + * External representations of the privilege bits --- aclitemin/aclitemout + * represent each possible privilege bit with a distinct 1-character code + */ +#define ACL_INSERT_CHR 'a' /* formerly known as "append" */ +#define ACL_SELECT_CHR 'r' /* formerly known as "read" */ +#define ACL_UPDATE_CHR 'w' /* formerly known as "write" */ +#define ACL_DELETE_CHR 'd' +#define ACL_TRUNCATE_CHR 'D' /* super-delete, as it were */ +#define ACL_REFERENCES_CHR 'x' +#define ACL_TRIGGER_CHR 't' +#define ACL_EXECUTE_CHR 'X' +#define ACL_USAGE_CHR 'U' +#define ACL_CREATE_CHR 'C' +#define ACL_CREATE_TEMP_CHR 'T' +#define ACL_CONNECT_CHR 'c' +#define ACL_COMPUTE_CHR 'p' +#define ACL_READ_CHR 'R' +#define ACL_WRITE_CHR 'W' + +/* string holding all privilege code chars, in order by bitmask position */ +#define ACL_ALL_RIGHTS_STR "arwdDxtXUCTcpRW" + +/* + * Bitmasks defining "all rights" for each supported object type + */ +#define ACL_ALL_RIGHTS_COLUMN (ACL_INSERT | ACL_SELECT | ACL_UPDATE | ACL_REFERENCES) +#define ACL_ALL_RIGHTS_RELATION \ + (ACL_INSERT | ACL_SELECT | ACL_UPDATE | ACL_DELETE | ACL_TRUNCATE | ACL_REFERENCES | ACL_TRIGGER) +#define ACL_ALL_RIGHTS_MATVIEW (ACL_SELECT) +#define ACL_ALL_RIGHTS_SEQUENCE (ACL_USAGE | ACL_SELECT | ACL_UPDATE) +#define ACL_ALL_RIGHTS_DATABASE (ACL_CREATE | ACL_CREATE_TEMP | ACL_CONNECT) +#define ACL_ALL_RIGHTS_FDW (ACL_USAGE) +#define ACL_ALL_RIGHTS_FOREIGN_SERVER (ACL_USAGE) +#define ACL_ALL_RIGHTS_FUNCTION (ACL_EXECUTE) +#define ACL_ALL_RIGHTS_LANGUAGE (ACL_USAGE) +#define ACL_ALL_RIGHTS_LARGEOBJECT (ACL_SELECT | ACL_UPDATE) +#define ACL_ALL_RIGHTS_NAMESPACE (ACL_USAGE | ACL_CREATE) +#define ACL_ALL_RIGHTS_NODEGROUP (ACL_CREATE | ACL_USAGE | ACL_COMPUTE) +#define ACL_ALL_RIGHTS_TABLESPACE (ACL_CREATE) +#define ACL_ALL_RIGHTS_TYPE (ACL_USAGE) +#define ACL_ALL_RIGHTS_DATA_SOURCE (ACL_USAGE) +#define ACL_ALL_RIGHTS_DIRECTORY (ACL_READ | ACL_WRITE) +#define ACL_ALL_RIGHTS_KEY (ACL_USAGE) + +/* External representations of the ddl privilege bits --- aclitemin/aclitemout */ +#define ACL_ALTER_CHR 'A' /* known as "modify" */ +#define ACL_DROP_CHR 'P' /* known as "remove" */ +#define ACL_COMMENT_CHR 'm' /* known as "statement" */ +#define ACL_INDEX_CHR 'i' +#define ACL_VACUUM_CHR 'v' + +/* string holding all ddl privilege code chars, in order by bitmask position */ +#define ACL_ALL_DDL_RIGHTS_STR "APmiv" + +/* Bitmasks defining "all ddl rights" for each supported object type */ +#define ACL_ALL_DDL_RIGHTS_COLUMN (ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_RELATION (ACL_ALTER | ACL_DROP | ACL_COMMENT | ACL_INDEX | ACL_VACUUM) +#define ACL_ALL_DDL_RIGHTS_MATVIEW (ACL_DROP | ACL_COMMENT | ACL_INDEX | ACL_VACUUM) +#define ACL_ALL_DDL_RIGHTS_SEQUENCE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_NODEGROUP (ACL_ALTER | ACL_DROP) +#define ACL_ALL_DDL_RIGHTS_DATABASE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_TABLESPACE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_NAMESPACE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FUNCTION (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_TYPE (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FOREIGN_SERVER (ACL_ALTER | ACL_DROP | ACL_COMMENT) +#define ACL_ALL_DDL_RIGHTS_FDW (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DATA_SOURCE (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DIRECTORY (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_LARGEOBJECT (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_LANGUAGE (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_DOMAIN (ACL_NO_DDL_RIGHTS) +#define ACL_ALL_DDL_RIGHTS_KEY (ACL_DROP) + +/* operation codes for pg_*_aclmask */ +typedef enum { + ACLMASK_ALL, /* normal case: compute all bits */ + ACLMASK_ANY /* return when result is known nonzero */ +} AclMaskHow; + +/* result codes for pg_*_aclcheck */ +typedef enum { ACLCHECK_OK = 0, ACLCHECK_NO_PRIV, ACLCHECK_NOT_OWNER } AclResult; + +typedef struct { + const char* name; + AclMode value; +} priv_map; + +/* this enum covers all object types that can have privilege errors */ +/* currently it's only used to tell aclcheck_error what to say */ +typedef enum AclObjectKind { + ACL_KIND_COLUMN, /* pg_attribute */ + ACL_KIND_CLASS, /* pg_class */ + ACL_KIND_SEQUENCE, /* pg_sequence */ + ACL_KIND_DATABASE, /* pg_database */ + ACL_KIND_PROC, /* pg_proc */ + ACL_KIND_OPER, /* pg_operator */ + ACL_KIND_TYPE, /* pg_type */ + ACL_KIND_LANGUAGE, /* pg_language */ + ACL_KIND_LARGEOBJECT, /* pg_largeobject */ + ACL_KIND_NAMESPACE, /* pg_namespace */ + ACL_KIND_NODEGROUP, /* pgxc_group */ + ACL_KIND_OPCLASS, /* pg_opclass */ + ACL_KIND_OPFAMILY, /* pg_opfamily */ + ACL_KIND_COLLATION, /* pg_collation */ + ACL_KIND_CONVERSION, /* pg_conversion */ + ACL_KIND_TABLESPACE, /* pg_tablespace */ + ACL_KIND_TSDICTIONARY, /* pg_ts_dict */ + ACL_KIND_TSCONFIGURATION, /* pg_ts_config */ + ACL_KIND_FDW, /* pg_foreign_data_wrapper */ + ACL_KIND_FOREIGN_SERVER, /* pg_foreign_server */ + ACL_KIND_EXTENSION, /* pg_extension */ + ACL_KIND_DATA_SOURCE, /* data source */ + ACL_KIND_DIRECTORY, /* pg_directory */ + ACL_KIND_COLUMN_SETTING, /* column setting */ + ACL_KIND_GLOBAL_SETTING, /* master client key */ + MAX_ACL_KIND /* MUST BE LAST */ +} AclObjectKind; + +/* + * routines used internally + */ +extern Acl* acldefault(GrantObjectType objtype, Oid ownerId, Oid objId = InvalidOid); +extern Acl* get_user_default_acl(GrantObjectType objtype, Oid ownerId, Oid nsp_oid); + +extern Acl* aclupdate(const Acl* old_acl, const AclItem* mod_aip, int modechg, Oid ownerId, DropBehavior behavior); +extern Acl* aclnewowner(const Acl* old_acl, Oid oldOwnerId, Oid newOwnerId); +extern Acl* make_empty_acl(void); +extern Acl* aclcopy(const Acl* orig_acl); +extern Acl* aclconcat(const Acl* left_acl, const Acl* right_acl); +extern Acl* aclmerge(const Acl* left_acl, const Acl* right_acl, Oid ownerId); +extern void aclitemsort(Acl* acl); +extern bool aclequal(const Acl* left_acl, const Acl* right_acl); + +extern AclMode aclmask(const Acl* acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how); +extern AclMode aclmask_dbe_perf(const Acl* acl, Oid roleid, Oid ownerId, AclMode mask, AclMaskHow how); +extern int aclmembers(const Acl* acl, Oid** roleids); + +extern bool has_privs_of_role(Oid member, Oid role); +extern bool is_member_of_role(Oid member, Oid role); +extern bool is_member_of_role_nosuper(Oid member, Oid role); +extern bool is_admin_of_role(Oid member, Oid role); +extern void check_is_member_of_role(Oid member, Oid role); +extern Oid get_role_oid(const char* rolname, bool missing_ok); + +extern void select_best_grantor( + Oid roleId, AclMode privileges, AclMode ddl_privileges, const Acl* acl, Oid ownerId, + Oid* grantorId, AclMode* grantOptions, AclMode* ddl_grantOptions, bool is_dbe_perf = false); + +extern void initialize_acl(void); + +/* + * SQL functions (from acl.c) + */ +extern Datum aclitemin(PG_FUNCTION_ARGS); +extern Datum aclitemout(PG_FUNCTION_ARGS); +extern Datum aclinsert(PG_FUNCTION_ARGS); +extern Datum aclremove(PG_FUNCTION_ARGS); +extern Datum aclcontains(PG_FUNCTION_ARGS); +extern Datum makeaclitem(PG_FUNCTION_ARGS); +extern Datum aclitem_eq(PG_FUNCTION_ARGS); +extern Datum hash_aclitem(PG_FUNCTION_ARGS); +extern Datum acldefault_sql(PG_FUNCTION_ARGS); +extern Datum aclexplode(PG_FUNCTION_ARGS); + +/* + * prototypes for functions in aclchk.c + */ +extern List* GrantStmtGetObjectOids(GrantStmt* stmt); +extern void ExecuteGrantStmt(GrantStmt* stmt); +extern void ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt* stmt); + +extern void RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid); +extern void RemoveDefaultACLById(Oid defaclOid); + +extern AclMode pg_attribute_aclmask(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_class_aclmask(Oid table_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_database_aclmask(Oid db_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_directory_aclmask(Oid dir_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_proc_aclmask(Oid proc_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_language_aclmask(Oid lang_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_largeobject_aclmask_snapshot( + Oid lobj_oid, Oid roleid, AclMode mask, AclMaskHow how, Snapshot snapshot); +extern AclMode pg_namespace_aclmask(Oid nsp_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode pg_nodegroup_aclmask(Oid group_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_tablespace_aclmask(Oid spc_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_foreign_data_wrapper_aclmask(Oid fdw_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_foreign_server_aclmask(Oid srv_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_extension_data_source_aclmask(Oid src_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode pg_type_aclmask(Oid type_oid, Oid roleid, AclMode mask, AclMaskHow how); +extern AclMode gs_sec_cmk_aclmask(Oid key_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); +extern AclMode gs_sec_cek_aclmask(Oid key_oid, Oid roleid, AclMode mask, AclMaskHow how, bool check_nodegroup = true); + +extern AclResult pg_attribute_aclcheck(Oid table_oid, AttrNumber attnum, Oid roleid, AclMode mode); +extern AclResult pg_attribute_aclcheck_all(Oid table_oid, Oid roleid, AclMode mode, AclMaskHow how); +extern AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode); +extern AclResult pg_directory_aclcheck(Oid dir_oid, Oid roleid, AclMode mode); +extern AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode); +extern AclResult pg_largeobject_aclcheck_snapshot(Oid lang_oid, Oid roleid, AclMode mode, Snapshot snapshot); +extern AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode, bool check_nodegroup = true); +extern AclResult pg_nodegroup_aclcheck(Oid group_oid, Oid roleid, AclMode mode); +extern AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode); +extern AclResult pg_foreign_data_wrapper_aclcheck(Oid fdw_oid, Oid roleid, AclMode mode); +extern AclResult pg_foreign_server_aclcheck(Oid srv_oid, Oid roleid, AclMode mode); +extern AclResult pg_extension_data_source_aclcheck(Oid src_oid, Oid roleid, AclMode mode); +extern AclResult pg_type_aclcheck(Oid type_oid, Oid roleid, AclMode mode); +extern AclResult gs_sec_cmk_aclcheck(Oid key_oid, Oid roleid, AclMode mode, bool check_nodegroup = false); +extern AclResult gs_sec_cek_aclcheck(Oid key_oid, Oid roleid, AclMode mode, bool check_nodegroup = false); + +extern void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char* objectname); + +extern void aclcheck_error_col(AclResult aclerr, AclObjectKind objectkind, const char* objectname, const char* colname); + +extern void aclcheck_error_type(AclResult aclerr, Oid typeOid); + +/* ownercheck routines just return true (owner) or false (not) */ +extern bool pg_class_ownercheck(Oid class_oid, Oid roleid); +extern bool pg_type_ownercheck(Oid type_oid, Oid roleid); +extern bool pg_oper_ownercheck(Oid oper_oid, Oid roleid); +extern bool pg_proc_ownercheck(Oid proc_oid, Oid roleid); +extern bool pg_language_ownercheck(Oid lan_oid, Oid roleid); +extern bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid); +extern bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid); +extern bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid); +extern bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid); +extern bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid); +extern bool pg_database_ownercheck(Oid db_oid, Oid roleid); +extern bool pg_directory_ownercheck(Oid dir_oid, Oid roleid); +extern bool pg_collation_ownercheck(Oid coll_oid, Oid roleid); +extern bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid); +extern bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid); +extern bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid); +extern bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid); +extern bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid); +extern bool pg_extension_ownercheck(Oid ext_oid, Oid roleid); +extern bool gs_sec_cmk_ownercheck(Oid key_oid, Oid roleid); +extern bool gs_sec_cek_ownercheck(Oid key_oid, Oid roleid); +extern bool pg_extension_data_source_ownercheck(Oid src_oid, Oid roleid); +extern bool pg_synonym_ownercheck(Oid synOid, Oid roleId); +extern bool has_createrole_privilege(Oid roleid); +extern bool has_auditadmin_privilege(Oid roleid); +extern Acl* getAclNodeGroup(); +extern void grantNodeGroupToRole(Oid group_id, Oid roleid, AclMode privileges, bool is_grant); +extern void check_nodegroup_privilege(Oid roleid, Oid ownerId, AclMode mode); +extern Oid get_nodegroup_member_of(Oid roleid); +extern Oid get_nodegroup_privs_of(Oid roleid); +extern bool is_role_independent(Oid roleid); +extern bool is_role_iamauth(Oid roleid); +extern bool independent_priv_aclcheck(AclMode mask, char relkind); +extern bool is_trust_language(Oid lang_oid); +#endif /* ACL_H */ diff -uprN postgresql-hll-2.14_old/include/utils/aes.h postgresql-hll-2.14/include/utils/aes.h --- postgresql-hll-2.14_old/include/utils/aes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/aes.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,86 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aes.h + * AES encryption algorithm + * Interfaces of the AES encryption algorithm + * + * + * IDENTIFICATION + * src/include/utils/aes.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef AES_H +#define AES_H + +#include "c.h" +#include "cipher.h" + +#define MAX_DECRYPT_BUFF_LEN 1024 +#define AES_GROUP_LEN 16 +#define AES_MIX_LEN 4 +#define KEY_MAX_LEN 32 +#define KEY_LEN 16 + +#define AES_TRANSFORM_LEN 2 + +#define CleanupBuffer(buffer, bufflen) \ + do { \ + int rc = memset_s(buffer, bufflen, 0, bufflen); \ + securec_check_c(rc, "", ""); \ + } while (0) + +#define AES_OUTPUT_LEN(inputStrLen) \ + (((inputStrLen + AES_GROUP_LEN - 1) / AES_GROUP_LEN) * AES_GROUP_LEN * AES_TRANSFORM_LEN + 1) +#define AES_ENCRYPT_LEN(inputlen) \ + ((inputlen % AES_GROUP_LEN) ? ((inputlen / AES_GROUP_LEN) * AES_GROUP_LEN + AES_GROUP_LEN) : inputlen) + +typedef struct decrypt_struct { + unsigned char* decryptBuff; + + char currLine[MAX_DECRYPT_BUFF_LEN]; + unsigned char Key[KEY_MAX_LEN]; + bool isCurrLineProcess; + bool encryptInclude; + + /* Encrypt gs_dump file through OpenSSL function */ + bool randget; + unsigned char rand[RANDOM_LEN + 1]; +} DecryptInfo; + +extern void initDecryptInfo(DecryptInfo* pDecryptInfo); +extern char* getLineFromAesEncryptFile(FILE* source, DecryptInfo* pDecryptInfo); +extern bool writeFileAfterEncryption( + FILE* pf, char* inputstr, int inputstrlen, int writeBufflen, unsigned char Key[], unsigned char* rand); +extern bool check_key(const char* key, int NUM); +extern void aesEncrypt(char* inputstr, unsigned long inputstrlen, char* outputstr, unsigned char Key[]); +extern void aesDecrypt(char* inputstr, unsigned long inputstrlen, char* outputstr, unsigned char Key[], bool isBinary); +extern void init_aes_vector(GS_UCHAR* aes_vector); +extern bool init_aes_vector_random(GS_UCHAR* aes_vector, size_t vector_len); +extern bool aes128Encrypt(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UINT32 keylen, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern bool aes128EncryptSpeed(GS_UCHAR* PlainText, GS_UINT32 PlainLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* CipherText, GS_UINT32* CipherLen); +extern bool aes128Decrypt(GS_UCHAR* CipherText, GS_UINT32 CipherLen, GS_UCHAR* Key, GS_UINT32 keylen, + GS_UCHAR* RandSalt, GS_UCHAR* PlainText, GS_UINT32* PlainLen); +extern bool aes128DecryptSpeed(GS_UCHAR* CipherText, GS_UINT32 CipherLen, GS_UCHAR* Key, GS_UCHAR* RandSalt, + GS_UCHAR* PlainText, GS_UINT32* PlainLen); +extern GS_UINT32 aes_ctr_enc_full_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, GS_UCHAR* key, GS_UCHAR* iv); +extern GS_UINT32 aes_ctr_dec_full_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, GS_UCHAR* key, GS_UCHAR* iv); + +#endif /* AES_H */ diff -uprN postgresql-hll-2.14_old/include/utils/aiomem.h postgresql-hll-2.14/include/utils/aiomem.h --- postgresql-hll-2.14_old/include/utils/aiomem.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/aiomem.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aiomem.h + * memory function for adio + * + * + * IDENTIFICATION + * src/include/utils/aiomem.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef _AIOMEM_H +#define _AIOMEM_H + +extern MemoryContext AdioSharedContext; +#define adio_share_alloc(buf_size) MemoryContextAlloc(AdioSharedContext, (buf_size)) +#define adio_share_free(ptr) pfree((ptr)) + +// /sys/block/sda/queue/logical_block_size +#define SYS_LOGICAL_BLOCK_SIZE (512) +#define adio_align_alloc(size) mem_align_alloc(SYS_LOGICAL_BLOCK_SIZE, size) +#define adio_align_free(ptr) mem_align_free(ptr) + +#endif /* _AIOMEM_H */ diff -uprN postgresql-hll-2.14_old/include/utils/anls_opt.h postgresql-hll-2.14/include/utils/anls_opt.h --- postgresql-hll-2.14_old/include/utils/anls_opt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/anls_opt.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,92 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * anls_opt.h + * analysis option information, used to show details in performance and + * context information check. + * + * + * IDENTIFICATION + * src/include/utils/anls_opt.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_ANLS_OPT_H +#define SRC_INCLUDE_UTILS_ANLS_OPT_H + +/* + * Add your analysis options as follows: + * 1. add your analysis option before ANLS_MAX in AnalysisOpt; + * 2. fill up anls_map[] about analysis option name, and keep their ordering; + * + */ +enum AnalysisOpt { + /* fastpath for all modules on/off */ + ANLS_ALL = 0, + + /* add your module id following */ + ANLS_LLVM_COMPILE, /* print LLVM compilation time */ + ANLS_HASH_CONFLICT, /* print length of hash link and hash confilct */ + ANLS_STREAM_DATA_CHECK, /* check buffer context after streaming */ + + /* add your analysis option above */ + ANLS_MAX +}; + +#define ANLS_OPT_IS_VALID(_id) ((_id) >= ANLS_ALL && (_id) < ANLS_MAX) +#define ALL_OPTIONS(_id) (ANLS_ALL == (_id)) + +/* 1 bit <--> 1 analysis option, including ANLS_MAX. its size is + * ((ANLS_MAX+1)+7)/8 = ANLS_MAX/8 + 1 + */ +#define ANLS_BEMD_BITMAP_SIZE (1 + (ANLS_MAX / 8)) + +/* max length of analysis option name */ +#define ANLS_OPT_NAME_MAXLEN (32) + +/* delimiter of dfx option list about GUC parameter */ +#define OPTION_DELIMITER ',' + +/* map about analysis option id and its name */ +typedef struct anls_opt_data { + AnalysisOpt anls_opt; + const char option_name[ANLS_OPT_NAME_MAXLEN]; +} dfx_option_data; + +/******************* analysis option id <--> analysis option name **********************/ +extern AnalysisOpt get_anls_opt_id(const char* dfx_name); + +/* Notice: + * declaration here only for the following inline functions, + * never use it within the other files directly. + */ +extern const anls_opt_data anls_map[]; + +/* + * @Description : find the analysis option name according to the option id. + * @in dfx_opt : analysis option id + * @return : analysis option name + */ +inline const char* get_valid_anls_opt_name(AnalysisOpt dfx_opt) +{ + return anls_map[dfx_opt].option_name; +} + +/******************* analysis options **********************/ +extern bool check_anls_opt_unique(void); +extern void anls_opt_batch_set(AnalysisOpt* options, int nopts, bool turn_on, bool apply_all_opts); +extern bool anls_opt_is_on(AnalysisOpt dfx_opt); + +#endif /* SRC_INCLUDE_UTILS_ANLS_OPT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/array.h postgresql-hll-2.14/include/utils/array.h --- postgresql-hll-2.14_old/include/utils/array.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/array.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * array.h + * Declarations for Postgres arrays. + * + * A standard varlena array has the following internal structure: + * - standard varlena header word + * - number of dimensions of the array + * - offset to stored data, or 0 if no nulls bitmap + * - element type OID + * - length of each array axis (C array of int) + * - lower boundary of each dimension (C array of int) + * - bitmap showing locations of nulls (OPTIONAL) + * - whatever is the stored data + * + * The and arrays each have ndim elements. + * + * The may be omitted if the array contains no NULL elements. + * If it is absent, the field is zero and the offset to the + * stored data must be computed on-the-fly. If the bitmap is present, + * is nonzero and is equal to the offset from the array start + * to the first data element (including any alignment padding). The bitmap + * follows the same conventions as tuple null bitmaps, ie, a 1 indicates + * a non-null entry and the LSB of each bitmap byte is used first. + * + * The actual data starts on a MAXALIGN boundary. Individual items in the + * array are aligned as specified by the array element type. They are + * stored in row-major order (last subscript varies most rapidly). + * + * NOTE: it is important that array elements of toastable datatypes NOT be + * toasted, since the tupletoaster won't know they are there. (We could + * support compressed toasted items; only out-of-line items are dangerous. + * However, it seems preferable to store such items uncompressed and allow + * the toaster to compress the whole array as one input.) + * + * + * The OIDVECTOR and INT2VECTOR datatypes are storage-compatible with + * generic arrays, but they support only one-dimensional arrays with no + * nulls (and no null bitmap). + * + * There are also some "fixed-length array" datatypes, such as NAME and + * POINT. These are simply a sequence of a fixed number of items each + * of a fixed-length datatype, with no overhead; the item size must be + * a multiple of its alignment requirement, because we do no padding. + * We support subscripting on these types, but array_in() and array_out() + * only work with varlena arrays. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/array.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ARRAY_H +#define ARRAY_H + +#include "fmgr.h" + +/* + * Arrays are varlena objects, so must meet the varlena convention that + * the first int32 of the object contains the total object size in bytes. + * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though! + * + * CAUTION: if you change the header for ordinary arrays you will also + * need to change the headers for oidvector and int2vector! + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int ndim; /* # of dimensions */ + int32 dataoffset; /* offset to data, or 0 if no bitmap */ + Oid elemtype; /* element type OID */ +} ArrayType; + +/* + * working state for accumArrayResult() and friends + */ +typedef struct ArrayBuildState { + MemoryContext mcontext; /* where all the temp stuff is kept */ + Datum* dvalues; /* array of accumulated Datums */ + bool* dnulls; /* array of is-null flags for Datums */ + int alen; /* allocated length of above arrays */ + int nelems; /* number of valid entries in above arrays */ + Oid element_type; /* data type of the Datums */ + int16 typlen; /* needed info about datatype */ + bool typbyval; + char typalign; +} ArrayBuildState; + +/* + * structure to cache type metadata needed for array manipulation + */ +typedef struct ArrayMetaState { + Oid element_type; + int16 typlen; + bool typbyval; + char typalign; + char typdelim; + Oid typioparam; + Oid typiofunc; + FmgrInfo proc; +} ArrayMetaState; + +/* + * private state needed by array_map (here because caller must provide it) + */ +typedef struct ArrayMapState { + ArrayMetaState inp_extra; + ArrayMetaState ret_extra; +} ArrayMapState; + +/* ArrayIteratorData is private in arrayfuncs.c */ +typedef struct ArrayIteratorData* ArrayIterator; + +/* + * fmgr macros for array objects + */ +#define DatumGetArrayTypeP(X) ((ArrayType*)PG_DETOAST_DATUM(X)) +#define DatumGetArrayTypePCopy(X) ((ArrayType*)PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_ARRAYTYPE_P(n) DatumGetArrayTypeP(PG_GETARG_DATUM(n)) +#define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_ARRAYTYPE_P(x) PG_RETURN_POINTER(x) + +/* + * Access macros for array header fields. + * + * ARR_DIMS returns a pointer to an array of array dimensions (number of + * elements along the various array axes). + * + * ARR_LBOUND returns a pointer to an array of array lower bounds. + * + * That is: if the third axis of an array has elements 5 through 8, then + * ARR_DIMS(a)[2] == 4 and ARR_LBOUND(a)[2] == 5. + * + * Unlike C, the default lower bound is 1. + */ +#define ARR_SIZE(a) VARSIZE(a) +#define ARR_NDIM(a) ((a)->ndim) +#define ARR_HASNULL(a) ((a)->dataoffset != 0) +#define ARR_ELEMTYPE(a) ((a)->elemtype) + +#define ARR_DIMS(a) ((int*)(((char*)(a)) + sizeof(ArrayType))) +#define ARR_LBOUND(a) ((int*)(((char*)(a)) + sizeof(ArrayType) + sizeof(int) * ARR_NDIM(a))) + +#define ARR_NULLBITMAP(a) \ + (ARR_HASNULL(a) ? (bits8*)(((char*)(a)) + sizeof(ArrayType) + 2 * sizeof(int) * ARR_NDIM(a)) : (bits8*)NULL) + +/* + * The total array header size (in bytes) for an array with the specified + * number of dimensions and total number of items. + */ +#define ARR_OVERHEAD_NONULLS(ndims) MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims)) +#define ARR_OVERHEAD_WITHNULLS(ndims, nitems) \ + MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims) + ((nitems) + 7) / 8) + +#define ARR_DATA_OFFSET(a) (ARR_HASNULL(a) ? (a)->dataoffset : ARR_OVERHEAD_NONULLS(ARR_NDIM(a))) + +/* + * Returns a pointer to the actual array data. + */ +#define ARR_DATA_PTR(a) (((char*)(a)) + ARR_DATA_OFFSET(a)) + +/* + * prototypes for functions defined in arrayfuncs.c + */ +extern Datum array_in(PG_FUNCTION_ARGS); +extern Datum array_out(PG_FUNCTION_ARGS); +extern Datum array_recv(PG_FUNCTION_ARGS); +extern Datum array_send(PG_FUNCTION_ARGS); +extern Datum array_eq(PG_FUNCTION_ARGS); +extern Datum array_ne(PG_FUNCTION_ARGS); +extern Datum array_lt(PG_FUNCTION_ARGS); +extern Datum array_gt(PG_FUNCTION_ARGS); +extern Datum array_le(PG_FUNCTION_ARGS); +extern Datum array_ge(PG_FUNCTION_ARGS); +extern Datum btarraycmp(PG_FUNCTION_ARGS); +extern Datum hash_array(PG_FUNCTION_ARGS); +extern Datum arrayoverlap(PG_FUNCTION_ARGS); +extern Datum arraycontains(PG_FUNCTION_ARGS); +extern Datum arraycontained(PG_FUNCTION_ARGS); +extern Datum array_ndims(PG_FUNCTION_ARGS); +extern Datum array_dims(PG_FUNCTION_ARGS); +extern Datum array_lower(PG_FUNCTION_ARGS); +extern Datum array_upper(PG_FUNCTION_ARGS); +extern Datum array_extend(PG_FUNCTION_ARGS); +extern Datum array_length(PG_FUNCTION_ARGS); +extern Datum array_larger(PG_FUNCTION_ARGS); +extern Datum array_smaller(PG_FUNCTION_ARGS); +extern Datum generate_subscripts(PG_FUNCTION_ARGS); +extern Datum generate_subscripts_nodir(PG_FUNCTION_ARGS); +extern Datum array_fill(PG_FUNCTION_ARGS); +extern Datum array_fill_with_lower_bounds(PG_FUNCTION_ARGS); +extern Datum array_unnest(PG_FUNCTION_ARGS); + +extern Datum array_ref(ArrayType* array, int nSubscripts, const int* indx, int arraytyplen, int elmlen, bool elmbyval, + char elmalign, bool* isNull); +extern ArrayType* array_set(ArrayType* array, int nSubscripts, const int* indx, Datum dataValue, bool isNull, + int arraytyplen, int elmlen, bool elmbyval, char elmalign); +extern ArrayType* array_get_slice(ArrayType* array, int nSubscripts, int* upperIndx, int* lowerIndx, int arraytyplen, + int elmlen, bool elmbyval, char elmalign); +extern ArrayType* array_set_slice(ArrayType* array, int nSubscripts, int* upperIndx, int* lowerIndx, + ArrayType* srcArray, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign); + +extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType, ArrayMapState* amstate); + +extern void array_bitmap_copy(bits8* destbitmap, int destoffset, const bits8* srcbitmap, int srcoffset, int nitems); +extern void CopyArrayEls(ArrayType* array, Datum* values, const bool* nulls, int nitems, int typlen, bool typbyval, + char typalign, bool freedata); + +extern ArrayType* construct_array(Datum* elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign); +extern ArrayType* construct_md_array(Datum* elems, bool* nulls, int ndims, int* dims, const int* lbs, Oid elmtype, + int elmlen, bool elmbyval, char elmalign); +extern ArrayType* construct_empty_array(Oid elmtype); +extern void deconstruct_array(ArrayType* array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum** elemsp, + bool** nullsp, int* nelemsp); +extern bool array_contains_nulls(ArrayType* array); +extern ArrayBuildState* accumArrayResult( + ArrayBuildState* astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext); +extern Datum makeArrayResult(ArrayBuildState* astate, MemoryContext rcontext); +extern Datum makeMdArrayResult( + ArrayBuildState* astate, int ndims, int* dims, int* lbs, MemoryContext rcontext, bool release); + +extern ArrayIterator array_create_iterator(ArrayType* arr, int slice_ndim); +extern bool array_iterate(ArrayIterator iterator, Datum* value, bool* isnull); +extern void array_free_iterator(ArrayIterator iterator); + +extern int ArrayCastAndSet(Datum src, int typlen, bool typbyval, char typalign, char* dest); + +/* + * prototypes for functions defined in arrayutils.c + */ +extern int ArrayGetOffset(int n, const int* dim, const int* lb, const int* indx); +extern int ArrayGetOffset0(int n, const int* tup, const int* scale); +extern int ArrayGetNItems(int ndim, const int* dims); +extern void mda_get_range(int n, int* span, const int* st, const int* endp); +extern void mda_get_prod(int n, const int* range, int* prod); +extern void mda_get_offset_values(int n, int* dist, const int* prod, const int* span); +extern int mda_next_tuple(int n, int* curr, const int* span); +extern int32* ArrayGetIntegerTypmods(ArrayType* arr, int* n); + +/* + * prototypes for functions defined in array_userfuncs.c + */ +extern Datum array_push(PG_FUNCTION_ARGS); +extern Datum array_cat(PG_FUNCTION_ARGS); + +extern ArrayType* create_singleton_array( + FunctionCallInfo fcinfo, Oid element_type, Datum element, bool isNull, int ndims); + +extern Datum array_agg_transfn(PG_FUNCTION_ARGS); +extern Datum array_agg_finalfn(PG_FUNCTION_ARGS); + +/* + * prototypes for functions defined in array_typanalyze.c + */ +extern Datum array_typanalyze(PG_FUNCTION_ARGS); +extern float8* check_float8_array(ArrayType* transarray, const char* caller, int n); + +#endif /* ARRAY_H */ diff -uprN postgresql-hll-2.14_old/include/utils/ascii.h postgresql-hll-2.14/include/utils/ascii.h --- postgresql-hll-2.14_old/include/utils/ascii.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/ascii.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,22 @@ +/* ----------------------------------------------------------------------- + * ascii.h + * + * Portions Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * src/include/utils/ascii.h + * + * ----------------------------------------------------------------------- + */ + +#ifndef _ASCII_H_ +#define _ASCII_H_ + +#include "fmgr.h" + +extern Datum to_ascii_encname(PG_FUNCTION_ARGS); +extern Datum to_ascii_enc(PG_FUNCTION_ARGS); +extern Datum to_ascii_default(PG_FUNCTION_ARGS); + +extern void ascii_safe_strlcpy(char* dest, const char* src, size_t destsiz); + +#endif /* _ASCII_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/aset.h postgresql-hll-2.14/include/utils/aset.h --- postgresql-hll-2.14_old/include/utils/aset.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/aset.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,228 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * aset.h + * + * + * + * IDENTIFICATION + * src/include/utils/aset.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ASET_H_ +#define ASET_H_ +#include "postgres.h" +#include "utils/memutils.h" + +// GUC variables for uncontrolled_memory_context which limit memory alloctations. +typedef struct memory_context_list { + char* value; + struct memory_context_list* next; +} memory_context_list; + +/* + * list all templated value used by method function + */ +extern volatile ThreadId ReaperBackendPID; +typedef enum { IS_PROTECT = 0x0001, IS_SHARED = 0x0010, IS_TRACKED = 0x0100 } template_value; + +typedef enum { + MEM_THRD, + MEM_SESS, + MEM_SHRD, +} MemType; + +class GenericMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class AsanMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class AlignMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc(_in_ MemoryContext context, _in_ Size align, _in_ Size size, const char* file, int line); + + template + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + template + static void* AllocSetRealloc( + _in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, const char* file, int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +// a stack-based memory allocator which +// 1) do not support single pointer free +// 2) more efficient than index-based memory allocator +// 3) do not contain header overhead. +class StackMemoryAllocator { +public: + static MemoryContext AllocSetContextCreate(_in_ MemoryContext parent, _in_ const char* name, + _in_ Size minContextSize, _in_ Size initBlockSize, _in_ Size maxBlockSize, _in_ Size maxSize, + _in_ bool isShared, _in_ bool isSession); + + template + static void* AllocSetAlloc( + _in_ MemoryContext context, _in_ Size align, _in_ Size size, _in_ const char* file, _in_ int line); + + static void AllocSetFree(_in_ MemoryContext context, _in_ void* pointer); + + static void* AllocSetRealloc(_in_ MemoryContext context, _in_ void* pointer, _in_ Size align, _in_ Size size, + _in_ const char* file, _in_ int line); + + static void AllocSetInit(_in_ MemoryContext context); + + template + static void AllocSetReset(_in_ MemoryContext context); + + template + static void AllocSetDelete(_in_ MemoryContext context); + + static Size AllocSetGetChunkSpace(_in_ MemoryContext context, _in_ void* pointer); + + static bool AllocSetIsEmpty(_in_ MemoryContext context); + + static void AllocSetStats(_in_ MemoryContext context, _in_ int level); + +#ifdef MEMORY_CONTEXT_CHECKING + static void AllocSetCheck(_in_ MemoryContext context); +#endif + +private: + static void AllocSetContextSetMethods(_in_ unsigned long value, MemoryContextMethods* method); + + template + static void AllocSetMethodDefinition(MemoryContextMethods* method); +}; + +class MemoryProtectFunctions { +public: + template + static void* gs_memprot_malloc(Size sz, bool needProtect); + + template + static void gs_memprot_free(void* ptr, Size sz); + + template + static void* gs_memprot_realloc(void* ptr, Size sz, Size newsz, bool needProtect); + + template + static int gs_posix_memalign(void** memptr, Size alignment, Size sz, bool needProtect); +}; + +extern int alloc_trunk_size(int width); + +#endif /* ASET_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/atomic_arm.h postgresql-hll-2.14/include/utils/atomic_arm.h --- postgresql-hll-2.14_old/include/utils/atomic_arm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/atomic_arm.h 2020-12-12 17:06:43.392349909 +0800 @@ -0,0 +1,90 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * atomic_arm.h + * Assembly implementation of 128bit exclusive CAS and atomic operations + * leverage ARMv8.1-a large system extension(LSE), which is faster than + * legacy exclusive mode APIs of GNU Built-in functions. + * Create on: 2020-01-11 + * + * + * IDENTIFICATION + * src/include/utils/atomic_arm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef ATOMIC_ARM_H +#define ATOMIC_ARM_H +#include "c.h" +#include "elog.h" + +#ifdef __aarch64__ + +/* + * Exclusive load/store 2 uint64_t variables to fullfil 128bit atomic compare and swap + * */ +static inline uint128_u __excl_compare_and_swap_u128(volatile uint128_u *ptr, uint128_u oldval, uint128_u newval) +{ + uint64_t tmp, ret; + uint128_u old; + asm volatile("1: ldxp %0, %1, %4\n" + " eor %2, %0, %5\n" + " eor %3, %1, %6\n" + " orr %2, %3, %2\n" + " cbnz %2, 2f\n" + " stlxp %w2, %7, %8, %4\n" + " cbnz %w2, 1b\n" + " b 3f\n" + "2:" + " stlxp %w2, %0, %1, %4\n" + " cbnz %w2, 1b\n" + "3:" + " dmb ish\n" + : "=&r"(old.u64[0]), "=&r"(old.u64[1]), "=&r"(ret), "=&r"(tmp), + "+Q"(ptr->u128) + : "r"(oldval.u64[0]), "r"(oldval.u64[1]), "r"(newval.u64[0]), "r"(newval.u64[1]) + : "memory"); + return old; +} + + +/* + * using CASP instinct to atomically compare and swap 2 uint64_t variables to fullfil + * 128bit atomic compare and swap + * */ +static inline uint128_u __lse_compare_and_swap_u128(volatile uint128_u *ptr, uint128_u oldval, uint128_u newval) +{ \ + uint128_u old; \ + register unsigned long x0 asm ("x0") = oldval.u64[0]; \ + register unsigned long x1 asm ("x1") = oldval.u64[1]; \ + register unsigned long x2 asm ("x2") = newval.u64[0]; \ + register unsigned long x3 asm ("x3") = newval.u64[1]; \ + \ + asm volatile(".arch_extension lse\n" \ + " caspal %[old_low], %[old_high], %[new_low], %[new_high], %[v]\n" \ + : [old_low] "+&r" (x0), [old_high] "+&r" (x1), \ + [v] "+Q" (*(ptr)) \ + : [new_low] "r" (x2), [new_high] "r" (x3) \ + : "x30", "memory"); \ + \ + old.u64[0] = x0; \ + old.u64[1] = x1; \ + return old; +} + +#endif /* __aarch64__ */ + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/atomic.h postgresql-hll-2.14/include/utils/atomic.h --- postgresql-hll-2.14_old/include/utils/atomic.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/atomic.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,514 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * atomic.h + * + * IDENTIFICATION + * src/include/utils/atomic.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATOMIC_H +#define ATOMIC_H + +#include +#include "c.h" +#include "storage/barrier.h" +#include "utils/atomic_arm.h" + +typedef volatile uint32 pg_atomic_uint32; +typedef volatile uint64 pg_atomic_uint64; + + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline int32 gs_atomic_add_32(volatile int32* ptr, int32 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the incremented value. + * @IN ptr: int64 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline int64 gs_atomic_add_64(int64* ptr, int64 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic set val into *ptr in a 32-bit address, and return the previous pointed by ptr + * @IN ptr: int32 pointer + * @IN val: value to set + * @Return: old value + * @See also: + */ +static inline int32 gs_lock_test_and_set(volatile int32* ptr, int32 val) +{ + return __sync_lock_test_and_set(ptr, val); +} + +/* + * @Description: Atomic set val into *ptr in a 32-bit address, and return the previous pointed by ptr + * @IN ptr: int64 pointer + * @IN val: value to set + * @Return: old value + * @See also: + */ +static inline int64 gs_lock_test_and_set_64(volatile int64* ptr, int64 val) +{ + return __sync_lock_test_and_set(ptr, val); +} + +/* + * @Description: Atomic compare and set val into *ptr in a 32-bit address, and return compare ok or not + * @IN ptr: int32 pointer + * @IN oldval: value to compare + * @IN newval: value to set + * @Return: true: dest is equal to the old value false: not equal + * @See also: + */ +static inline bool gs_compare_and_swap_32(int32* dest, int32 oldval, int32 newval) +{ + if (oldval == newval) + return true; + + volatile bool res = __sync_bool_compare_and_swap(dest, oldval, newval); + + return res; +} + +/* + * @Description: Atomic compare and set val into *ptr in a 64-bit address, and return compare ok or not + * @IN ptr: int64 pointer + * @IN oldval: value to compare + * @IN newval: value to set + * @Return: true: dest is equal to the old value false: not equal + * @See also: + */ +static inline bool gs_compare_and_swap_64(int64* dest, int64 oldval, int64 newval) +{ + if (oldval == newval) + return true; + + return __sync_bool_compare_and_swap(dest, oldval, newval); +} + +static inline uint32 gs_compare_and_swap_u32(volatile uint32* ptr, uint32 oldval, uint32 newval) +{ + return (uint32)__sync_val_compare_and_swap(ptr, oldval, newval); +} + +static inline uint64 gs_compare_and_swap_u64(volatile uint64* ptr, uint64 oldval, uint64 newval) +{ + return (uint64)__sync_val_compare_and_swap(ptr, oldval, newval); +} + +/* + * @Description: Atomic init in a 32-bit address. + * @IN ptr: int32 pointer + * @IN inc: int32 value + * @Return: void + * @See also: + */ +static inline void pg_atomic_init_u32(volatile uint32* ptr, uint32 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_read_u32(volatile uint32* ptr) +{ + return *ptr; +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_or_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_or(ptr, inc); +} + +/* + * @Description: Atomic and in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: and value + * @Return: oid value + * @See also: + */ +static inline uint32 pg_atomic_fetch_and_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_and(ptr, inc); +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_add_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_add(ptr, inc); +} + +/* + * @Description: Atomic increment in a 32-bit address, and return the incremented value. + * @IN ptr: int32 pointer + * @IN inc: increase value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_add_fetch_u32(volatile uint32* ptr, uint32 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic decrement in a 32-bit address, and return the old value. + * @IN ptr: int32 pointer + * @IN inc: decrease value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_fetch_sub_u32(volatile uint32* ptr, int32 inc) +{ + return __sync_fetch_and_sub(ptr, inc); +} + +/* + * @Description: Atomic decrement in a 32-bit address, and return the decremented value. + * @IN ptr: int32 pointer + * @IN inc: decrease value + * @Return: new value + * @See also: + */ +static inline uint32 pg_atomic_sub_fetch_u32(volatile uint32* ptr, int32 inc) +{ + return __sync_fetch_and_sub(ptr, inc) - inc; +} + +/* + * @Description: Atomic change to given value newval in a 32-bit address, + * if *ptr is equal to *expected. + * @IN ptr: int32 pointer + * @IN expected: int32 pointer, expected value + * @IN newval: new value + * @Return: true if *ptr is equal to *expected. otherwise return false. + * @See also: + */ +static inline bool pg_atomic_compare_exchange_u32(volatile uint32* ptr, uint32* expected, uint32 newval) +{ + bool ret = false; + uint32 current; + current = __sync_val_compare_and_swap(ptr, *expected, newval); + ret = current == *expected; + *expected = current; + return ret; +} + +/* + * @Description: Atomic write in a 32-bit address. + * @IN ptr: int32 pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_u32(volatile uint32* ptr, uint32 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic change to the value newval in a 32-bit address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: int32 pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uint32 pg_atomic_exchange_u32(volatile uint32* ptr, uint32 newval) +{ + uint32 old; + while (true) { + old = pg_atomic_read_u32(ptr); + if (pg_atomic_compare_exchange_u32(ptr, &old, newval)) + break; + } + return old; +} + +/* + * @Description: Atomic init in a 64-bit address. + * @IN ptr: int64 pointer + * @IN inc: int64 value + * @Return: void + * @See also: + */ +static inline void pg_atomic_init_u64(volatile uint64* ptr, uint64 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic read in a 64-bit address, and return the int64 pointer. + * @IN ptr: int64 pointer + * @Return: int64 pointer + * @See also: + */ +static inline uint64 pg_atomic_read_u64(volatile uint64* ptr) +{ + return *ptr; +} + +/* + * @Description: Atomic or in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: or value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_or_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_or(ptr, inc); +} + +/* + * @Description: Atomic and in a 64-bit address, and return the old result. + * @IN ptr: int64 pointer + * @IN inc: and value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_and_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_and(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: incremented value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_add_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_add(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the incremented value. + * @IN ptr: int64 pointer + * @IN inc: incremented value + * @Return: new value + * @See also: + */ +static inline uint64 pg_atomic_add_fetch_u64(volatile uint64* ptr, uint64 inc) +{ + return __sync_fetch_and_add(ptr, inc) + inc; +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the old value. + * @IN ptr: int64 pointer + * @IN inc: delcrease value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_fetch_sub_u64(volatile uint64* ptr, int64 inc) +{ + return __sync_fetch_and_sub(ptr, inc); +} + +/* + * @Description: Atomic increment in a 64-bit address, and return the decremented value. + * @IN ptr: int64 pointer + * @IN inc: decrease value + * @Return: new value + * @See also: + */ +static inline uint64 pg_atomic_sub_fetch_u64(volatile uint64* ptr, int64 inc) +{ + return __sync_fetch_and_sub(ptr, inc) - inc; +} + +/* + * @Description: Atomic change to the given value newval in a 64-bit address, + * if *ptr is equal to *expected. + * @IN ptr: int64 pointer + * @IN expected: int64 pointer, expected value + * @IN newval: new value + * @Return: true if *ptr is equal to *expected. otherwise return false. + * @See also: + */ +static inline bool pg_atomic_compare_exchange_u64(volatile uint64* ptr, uint64* expected, uint64 newval) +{ + bool ret = false; + uint64 current; + current = __sync_val_compare_and_swap(ptr, *expected, newval); + ret = current == *expected; + *expected = current; + return ret; +} + +/* + * @Description: Atomic write in a 34-bit address. + * @IN ptr: int64 pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_u64(volatile uint64* ptr, uint64 val) +{ + *ptr = val; +} + +/* + * @Description: Atomic change to the value newval in a 64-bit address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: int64 pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uint64 pg_atomic_exchange_u64(volatile uint64* ptr, uint64 newval) +{ + uint64 old; + while (true) { + old = pg_atomic_read_u64(ptr); + if (pg_atomic_compare_exchange_u64(ptr, &old, newval)) + break; + } + return old; +} + +#ifdef __aarch64__ +/* + * This static function implements an atomic compare and exchange operation of + * 128bit width variable. This compares the contents of *ptr with the contents of + * *old and if equal, writes newval into *ptr. If they are not equal, the + * current contents of *ptr is written into *old. + * This API is an alternative implementation of __sync_val_compare_and_swap for + * 128bit on ARM64 platforms. + * + * @IN ptr: uint128_u pointer shold be 128bit(16bytes) aligned + * @IN oldval: old value, should be 128bit(16bytes) aligned. + * @IN newval: new value, should be 128bit(16bytes) aligned + * @Return: old value + */ +static inline uint128_u arm_compare_and_swap_u128(volatile uint128_u* ptr, uint128_u oldval, uint128_u newval) +{ +#ifdef __ARM_LSE + return __lse_compare_and_swap_u128(ptr, oldval, newval); +#else + return __excl_compare_and_swap_u128(ptr, oldval, newval); +#endif +} +#endif + +static inline void pg_atomic_init_uintptr(volatile uintptr_t* ptr, uintptr_t val) +{ + pg_atomic_init_u64(ptr, (uint64)val); +} + +static inline uintptr_t pg_atomic_read_uintptr(volatile uintptr_t* ptr) +{ + return (uintptr_t)pg_atomic_read_u64(ptr); +} + +static inline bool pg_atomic_compare_exchange_uintptr(volatile uintptr_t* ptr, uintptr_t* expected, uintptr_t newval) +{ + return pg_atomic_compare_exchange_u64(ptr, (uint64*)expected, (uint64)newval); +} + +/* + * @Description: Atomic write in a uintptr_t address. + * @IN ptr: uintptr_t pointer + * @IN inc: new value + * @See also: + */ +static inline void pg_atomic_write_uintptr(volatile uintptr_t* ptr, uintptr_t val) +{ + pg_atomic_write_u64(ptr, (uint64)val); +} + +/* + * @Description: Atomic change to the value newval in a uintptr_t address, + * if *ptr is equal to *expected, return old value. + * @IN ptr: uintptr_t pointer + * @IN newval: new value + * @Return: old value + * @See also: + */ +static inline uintptr_t pg_atomic_exchange_uintptr(volatile uintptr_t* ptr, uintptr_t newval) +{ + return (uintptr_t)pg_atomic_exchange_u64(ptr, (uint64)newval); +} + +/* + * @Description: Atomic load acquire the value in a uint64 address, + * @IN ptr: uint64 pointer + * @Return: the value of pointer + * @See also: + */ +static inline uint64 pg_atomic_barrier_read_u64(volatile uint64* ptr) +{ + return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); +} + +/* + * @Description This API is an unified wrapper of __sync_val_compare_and_swap for + * 128bit on ARM64 platforms and X86. + * + * @IN ptr: uint128_t pointer shold be 128bit(16bytes) aligned + * @IN oldval: old value, should be 128bit(16bytes) aligned. + * @IN newval: new value, should be 128bit(16bytes) aligned + * @Return: old value + */ +static inline uint128_u atomic_compare_and_swap_u128( + volatile uint128_u* ptr, + uint128_u oldval = uint128_u{0}, + uint128_u newval = uint128_u{0}) +{ +#ifdef __aarch64__ + return arm_compare_and_swap_u128(ptr, oldval, newval); +#else + uint128_u ret; + ret.u128 = __sync_val_compare_and_swap(&ptr->u128, oldval.u128, newval.u128); + return ret; +#endif +} + +#endif /* ATOMIC_H */ + diff -uprN postgresql-hll-2.14_old/include/utils/attoptcache.h postgresql-hll-2.14/include/utils/attoptcache.h --- postgresql-hll-2.14_old/include/utils/attoptcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/attoptcache.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------------------- + * + * attoptcache.h + * Attribute options cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/attoptcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ATTOPTCACHE_H +#define ATTOPTCACHE_H + +/* + * Attribute options. + */ +typedef struct AttributeOpts { + int32 vl_len_; /* varlena header (do not touch directly!) */ + float8 n_distinct; + float8 n_distinct_inherited; +} AttributeOpts; + +AttributeOpts* get_attribute_options(Oid spcid, int attnum); + +#endif /* ATTOPTCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/batchsort.h postgresql-hll-2.14/include/utils/batchsort.h --- postgresql-hll-2.14_old/include/utils/batchsort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/batchsort.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,574 @@ +/* --------------------------------------------------------------------------------------- + * + * batchsort.h + * Generalized tuple sorting routines. + * + * This module handles sorting of heap tuples, index tuples, or single + * Datums (and could easily support other kinds of sortable objects, + * if necessary). It works efficiently for both small and large amounts + * of data. Small amounts are sorted in-memory using qsort(). Large + * amounts are sorted using temporary files and a standard external sort + * algorithm. + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/batchsort.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BATCHSORT_H +#define BATCHSORT_H + +#include "access/itup.h" +#include "executor/tuptable.h" +#include "fmgr.h" +#ifdef PGXC +#include "pgxc/execRemote.h" +#include "vecexecutor/vecnodes.h" +#endif +#include "utils/elog.h" +#include "utils/relcache.h" +#include "vecexecutor/vecstore.h" +#include "utils/logtape.h" +#include "utils/pg_rusage.h" + +extern THR_LOCAL int vsort_mem; +extern const int MINORDER; + +/* + * Possible states of a BatchSort object. + */ +typedef enum { + BS_INITIAL = 0, + BS_BOUNDED, + BS_BUILDRUNS, + BS_SORTEDINMEM, + BS_SORTEDONTAPE, + BS_FINALMERGE +} BatchSortStatus; + +/* + * Private state of a batchsort operation. + */ +class Batchsortstate : public VecStore { +public: + // Memory context for main allocation + MemoryContext sortcontext; + + /* + * enumerated value as shown above + */ + BatchSortStatus m_status; + +#ifdef PGXC + RemoteQueryState* combiner; + VectorBatch** m_connDNBatch; + + int* m_datanodeFetchCursor; + + // merge sort + VecStreamState* streamstate; +#endif + /* + * number of columns in sort key + */ + int m_nKeys; + + /* + * Scan keys + */ + ScanKey m_scanKeys; + + /* + * The sortKeys variable is used by every case other than the hash index + * case; it is set by tuplesort_begin_xxx. + */ + SortSupport sortKeys; /* array of length nKeys */ + + /* + * Additional state for managing "abbreviated key" sortsupport routines + * (which currently may be used by all cases except the hash index case). + * Tracks the intervals at which the optimization's effectiveness is + * tested. + */ + int64 abbrevNext; /* Tuple # at which to next check + * applicability */ + + /* + * did caller request random access? + */ + bool m_randomAccess; + + /* + * did caller specify a maximum number of tuples to return + */ + bool m_bounded; + + /* + * Top N sort + */ + bool m_boundUsed; + + /* + * if bounded, the maximum number of tuples + */ + int m_bound; + + MultiColumnsData m_unsortColumns; + + bool* m_isSortKey; + + long m_lastBlock; + + int m_lastOffset; + + /* + * variables which relate to external sort + */ + int m_maxTapes; + + int m_tapeRange; + + LogicalTapeSet* m_tapeset; + + /* + * While building initial runs, this is the current output run number + * (starting at 0). Afterwards, it is the number of initial runs we made. + */ + int m_curRun; + + /* + * Unless otherwise noted, all pointer variables below are pointers to + * arrays of length maxTapes, holding per-tape data. + */ + + /* + * These variables are only used during merge passes. mergeactive[i] is + * true if we are reading an input run from (actual) tape number i and + * have not yet exhausted that run. mergenext[i] is the memtuples index + * of the next pre-read tuple (next to be loaded into the heap) for tape + * i, or 0 if we are out of pre-read tuples. mergelast[i] similarly + * points to the last pre-read tuple from each tape. mergeavailslots[i] + * is the number of unused memtuples[] slots reserved for tape i, and + * mergeavailmem[i] is the amount of unused space allocated for tape i. + * mergefreelist and mergefirstfree keep track of unused locations in the + * memtuples[] array. The memtuples[].tupindex fields link together + * pre-read tuples for each tape as well as recycled locations in + * mergefreelist. It is OK to use 0 as a null link in these lists, because + * memtuples[0] is part of the merge heap and is never a pre-read tuple. + */ + bool* m_mergeActive; /* active input run source? */ + int* m_mergeNext; /* first preread tuple for each source */ + int* m_mergeLast; /* last preread tuple for each source */ + int* m_mergeAvailslots; /* slots left for prereading each tape */ + long* m_mergeAvailmem; /* availMem for prereading each tape */ + int m_mergeFreeList; /* head of freelist of recycled slots */ + int m_mergeFirstFree; /* first slot never used in this merge */ + + /* + * Variables for Algorithm D. Note that destTape is a "logical" tape + * number, ie, an index into the tp_xxx[] arrays. Be careful to keep + * "logical" and "actual" tape numbers straight! + */ + int m_level; /* Knuth's l */ + int m_destTape; /* current output tape (Knuth's j, less 1) */ + int* m_tpFib; /* Target Fibonacci run counts (A[]) */ + int* m_tpRuns; /* # of real runs on each tape */ + int* m_tpDummy; /* # of dummy runs for each tape (D[]) */ + int* m_tpNum; /* Actual tape numbers (TAPE[]) */ + int m_activeTapes; /* # of active input tapes in merge pass */ + + /* + * These variables are used after completion of sorting to keep track of + * the next tuple to return. (In the tape case, the tape's current read + * position is also critical state.) + */ + int m_resultTape; /* actual tape number of finished output */ + bool m_eofReached; /* reached EOF (needed for cursors) */ + + /* markpos_xxx holds marked position for mark and restore */ + long m_markposBlock; /* tape block# (only used if SORTEDONTAPE) */ + int m_markposOffset; /* saved "current", or offset in tape block */ + bool m_markposEof; /* saved "eof_reached" */ + long m_lastFileBlocks; /* last file blocks used in underlying file */ + + int64 peakMemorySize; /* memory size before writeMultiColumn*/ + + // Resource snapshot for time of sort start. + // +#ifdef TRACE_SORT + PGRUsage m_ruStart; +#endif + + char* jitted_CompareMultiColumn; /* jitted function for CompareMultiColumn */ + char* jitted_CompareMultiColumn_TOPN; /* jitted function for CompareMultiColumn used by Top N sort */ + + /* + * Initialize variables. + */ + + void InitCommon(int64 workMem, bool randomAccess); + + /* + * Based on hyper log log estimation, consider wheather exit abbreviate + * mode or not. + */ + bool ConsiderAbortCommon(); + + void SortInMem(); + + int GetSortMergeOrder(); + + void InitTapes(); + + void DumpMultiColumn(bool all); + + int HeapCompare(MultiColumns* a, MultiColumns* b, bool checkIdx); + + template + int THeapCompare(MultiColumns* a, MultiColumns* b); + + template + void BatchSortHeapInsert(MultiColumns* multiColumn, int multiColumnIdx); + + template + void BatchSortHeapSiftup(); + + void MarkRunEnd(int tapenum); + + void SelectNewTape(); + + void MergeRuns(); + + void BeginMerge(); + + void MergeOneRun(); + + void MergePreReadDone(int srcTape); + + void MergePreRead(); + void GetBatch(bool forward, VectorBatch* batch); + + void (Batchsortstate::*m_getBatchFun)(bool forward, VectorBatch* batch); + + void GetBatchInMemory(bool forward, VectorBatch* batch); + + void GetBatchDisk(bool forward, VectorBatch* batch); + + void GetBatchFinalMerge(bool forward, VectorBatch* batch); + + void BindingGetBatchFun(); + + inline void ReverseDirectionHeap(); + + void MakeBoundedHeap(); + + void SortBoundedHeap(); + + void DumpUnsortColumns(bool all); + + /* + * These function pointers decouple the routines that must know what kind + * of tuple we are sorting from the routines that don't need to know it. + * They are set up by the tuplesort_begin_xxx routines. + * + * Function to compare two tuples; result is per qsort() convention, ie: + * <0, 0, >0 according as ab. The API must match + * qsort_arg_comparator. + */ + int (*compareMultiColumn)(const MultiColumns* a, const MultiColumns* b, Batchsortstate* state); + + /* + * Function to copy a supplied input tuple into palloc'd space and set up + * its SortTuple representation (ie, set tuple/datum1/isnull1). Also, + * state->availMem must be decreased by the amount of space used for the + * tuple copy (note the SortTuple struct itself is not counted). + */ + void (*copyMultiColumn)(Batchsortstate* state, MultiColumns* stup, void* tup); + + /* + * Function to write a stored tuple onto tape. The representation of the + * tuple on tape need not be the same as it is in memory; requirements on + * the tape representation are given below. After writing the tuple, + * pfree() the out-of-line data (not the SortTuple struct!), and increase + * state->availMem by the amount of memory space thereby released. + */ + void (*writeMultiColumn)(Batchsortstate* state, int tapenum, MultiColumns* stup); + + /* + * Function to read a stored tuple from tape back into memory. 'len' is + * the already-read length of the stored tuple. Create a palloc'd copy, + * initialize tuple/datum1/isnull1 in the target SortTuple struct, and + * decrease state->availMem by the amount of memory space consumed. + */ + void (*readMultiColumn)(Batchsortstate* state, MultiColumns& stup, int tapenum, unsigned int len); + +#ifdef PGXC + /* + * Function to read length of next stored tuple. + * Used as 'len' parameter for readtup function. + */ + unsigned int (*getlen)(Batchsortstate* state, int tapenum, bool eofOK); +#endif + + /* + * Function to reverse the sort direction from its current state. (We + * could dispense with this if we wanted to enforce that all variants + * represent the sort key information alike.) + */ + void (*reversedirection)(Batchsortstate* state); + + /* + * Function to accept one batch while collecting input data for sort. + * Note that the input data is always copied; the caller need not save it. + * + * We choose batchsort_putbatch for normal case, choose + * batchsort_putbatch for fast abbreviate comparison function for sort. + * So we need to implement different function of batchsort_putbatch. + */ + void (*sort_putbatch)(Batchsortstate* state, VectorBatch* batch, int start, int end); +}; + +extern Batchsortstate* batchsort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, int64 workMem, bool randomAccess, int64 maxMem = 0, + int planId = 0, int dop = 1); +#ifdef PGXC +extern Batchsortstate* batchsort_begin_merge(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, void* combiner, int64 workMem); +#endif + +extern void batchsort_set_bound(Batchsortstate* state, int64 bound); + +/* + * abbreSortOptimize used to mark whether allocate one more Datum for + * fast compare of two data(text or numeric type) + */ +template +void putbatch(Batchsortstate* state, VectorBatch* batch, int start, int end) +{ + int64 memorySize = 0; + for (int row = start; row < end; ++row) { + MultiColumns multiColumn = state->CopyMultiColumn(batch, row); + + if (abbrevSortOptimize) { + if (state->sortKeys->abbrev_converter && !IS_NULL(multiColumn.m_nulls[state->sortKeys->ssup_attno - 1]) && + !state->ConsiderAbortCommon()) + /* Store abbreviated key representation */ + multiColumn.m_values[batch->m_cols] = state->sortKeys->abbrev_converter( + multiColumn.m_values[state->sortKeys->ssup_attno - 1], state->sortKeys); + else + multiColumn.m_values[batch->m_cols] = multiColumn.m_values[state->sortKeys->ssup_attno - 1]; + } + + switch (state->m_status) { + case BS_INITIAL: + + if ((!state->HasFreeSlot() || state->m_availMem <= 0) && + state->m_storeColumns.m_memRowNum >= MINORDER * 2) { + /* if mem is used up, then adjust capacity */ + if (state->m_availMem <= 0) + state->m_storeColumns.m_capacity = state->m_storeColumns.m_memRowNum + 1; + state->GrowMemValueSlots("VecSort", state->m_planId, state->sortcontext); + } + state->PutValue(multiColumn); + + /* + * Check if it's time to switch over to a bounded heapsort. We do + * so if the input tuple count exceeds twice the desired tuple + * count (this is a heuristic for where heapsort becomes cheaper + * than a quicksort), or if we've just filled workMem and have + * enough tuples to meet the bound. + * + * Note that once we enter TSS_BOUNDED state we will always try to + * complete the sort that way. In the worst case, if later input + * tuples are larger than earlier ones, this might cause us to + * exceed workMem significantly. + */ + if (state->m_bounded && (state->m_storeColumns.m_memRowNum > state->m_bound * 2 || + (state->m_storeColumns.m_memRowNum > state->m_bound && state->LackMem()))) { +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) { + elog(LOG, + "switching to bounded heapsort at %d tuples: %s", + state->m_storeColumns.m_memRowNum, + pg_rusage_show(&state->m_ruStart)); + } +#endif + if (state->m_storeColumns.m_memRowNum > 0) { + state->m_colWidth /= state->m_storeColumns.m_memRowNum; + state->m_addWidth = false; + } + state->MakeBoundedHeap(); + continue; + } + + /* + * Once we do not have enough memory, we will turn to external sort. But before we do + * InitTapes, we should have at least MINORDER * 2 MultiColumns in MultiColumnsData. + * Since the minimal number of tapes we need in external sort is MINORDER. + */ + while (state->LackMem() && (state->m_storeColumns.m_memRowNum < MINORDER * 2)) { + state->m_availMem += state->m_allowedMem; + } + + /* + * Done if we still fit in available memory and have at least MINORDER * 2 array slots. + */ + if ((state->m_storeColumns.m_memRowNum < state->m_storeColumns.m_capacity && !state->LackMem()) || + state->m_storeColumns.m_memRowNum < MINORDER * 2) + continue; + + if (state->m_storeColumns.m_memRowNum > 0) { + state->m_colWidth /= state->m_storeColumns.m_memRowNum; + state->m_addWidth = false; + } + + if (state->LackMem()) { + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling Warning: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); + } + + state->InitTapes(); + + /* + * Cache memory size info Batchsortstate before write to tapes. + * If the memory size has been cached during previous dump, + * do not update the size with current context size. + * note: state->peakMemorySize is only used to log memory size before dump for now. + * Keep caution once it is adopted for other cases in the future.. + */ + if (state->peakMemorySize <= 0) { + memorySize = 0; + CalculateContextSize(state->sortcontext, &memorySize); + state->peakMemorySize = memorySize; + } + +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling LOG: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); +#endif + + state->m_storeColumns.m_capacity = state->m_storeColumns.m_memRowNum; + + /* + * If we are over the memory limit, dump tuples till we're under. + */ + state->DumpMultiColumn(false); + +#ifdef TRACE_SORT + if (u_sess->attr.attr_common.trace_sort) + ereport(LOG, + (errmodule(MOD_VEC_EXECUTOR), + errmsg("Profiling LOG: " + "VecSort(%d) Disk Spilled : workmem: %ldKB, availmem: %ldKB, " + "memRowNum: %d, memCapacity: %d", + state->m_planId, + state->m_allowedMem / 1024L, + state->m_availMem / 1024L, + state->m_storeColumns.m_memRowNum, + state->m_storeColumns.m_capacity))); +#endif + + break; + + case BS_BOUNDED: + + if (state->compareMultiColumn(&multiColumn, state->m_storeColumns.m_memValues, state) <= 0) { + state->FreeMultiColumn(&multiColumn); + } else { + state->FreeMultiColumn(state->m_storeColumns.m_memValues); + state->BatchSortHeapSiftup(); + state->BatchSortHeapInsert(&multiColumn, 0); + } + break; + + case BS_BUILDRUNS: + + if (state->compareMultiColumn(&multiColumn, &state->m_storeColumns.m_memValues[0], state) >= 0) { + state->BatchSortHeapInsert(&multiColumn, state->m_curRun); + } else { + state->BatchSortHeapInsert(&multiColumn, state->m_curRun + 1); + } + + /* + * If we are over the memory limit, dump tuples till we're under. + */ + state->DumpMultiColumn(false); + + break; + + default: + elog(ERROR, "invalid BatchSort state"); + break; + } + } +} + +/* + * Accept one tuple while collecting input data for sort. + * Note that the input data is always copied; the caller need not save it. + * + * When the first column of order_by_columns is text or numeric type, we + * use bttextcmp_abbrev or numeric_cmp_abbrev to speed up compare operation, + * meanwhile we need to allocate one more Datum to store prefix info, so + * set abbreSortOptimize to be true. For other case set abbreSortOptimize + * to be false. + */ +template +void batchsort_putbatch(Batchsortstate* state, VectorBatch* batch, int start, int end) +{ + MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext); + + /* + * it is only initialized once. + */ + if (!state->m_colInfo) { + state->InitColInfo(batch); + } + + putbatch(state, batch, start, end); + + MemoryContextSwitchTo(oldcontext); +} + +extern void batchsort_performsort(Batchsortstate* state); + +extern void batchsort_getbatch(Batchsortstate* state, bool forward, VectorBatch* batch); + +extern void batchsort_end(Batchsortstate* state); + +extern void batchsort_get_stats(Batchsortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +/* + * These routines may only be called if randomAccess was specified 'true'. + * Likewise, backwards scan in gettuple/getdatum is only allowed if + * randomAccess was specified. + */ + +extern void batchsort_rescan(Batchsortstate* state); + +extern void batchsort_markpos(Batchsortstate* state); +extern void batchsort_restorepos(Batchsortstate* state); + +extern void batchsort_get_stats(Batchsortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +#endif /* BATCHSORT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/batchstore.h postgresql-hll-2.14/include/utils/batchstore.h --- postgresql-hll-2.14_old/include/utils/batchstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/batchstore.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,184 @@ +/* --------------------------------------------------------------------------------------- + * + * batchstore.h + * Generalized routines for temporary tuple storage. + * + * This module handles temporary storage of tuples for purposes such + * as Materialize nodes, hashjoin batch files, etc. It is essentially + * a dumbed-down version of tuplesort.c; it does no sorting of tuples + * but can only store and regurgitate a sequence of tuples. However, + * because no sort is required, it is allowed to start reading the sequence + * before it has all been written. This is particularly useful for cursors, + * because it allows random access within the already-scanned portion of + * a query without having to process the underlying scan to completion. + * Also, it is possible to support multiple independent read pointers. + * + * A temporary file is used to handle the data if it exceeds the + * space limit specified by the caller. + * + * Beginning in Postgres 8.2, what is stored is just MinimalTuples; + * callers cannot expect valid system columns in regurgitated tuples. + * Also, we have changed the API to return tuples in TupleTableSlots, + * so that there is a check to prevent attempted access to system columns. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/batchstore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef BATCHSTORE_H +#define BATCHSTORE_H + +#include "executor/tuptable.h" +#include "vecexecutor/vecstore.h" + +/* BatchStore is an opaque type whose details are not known outside + * batchstore.cpp. + */ + +/* + * Possible states of a Tuplestore object. These denote the states that + * persist between calls of Tuplestore routines. + */ +typedef enum { + BSS_INMEM, /* batch still fit in memory */ + BSS_WRITEFILE, /* Writing to temp file */ + BSS_READFILE /* Reading from temp file */ +} BatchStoreStatus; + +/* + * State for a single read pointer. If we are in state INMEM then all the + * read pointers' "current" fields denote the read positions. In state + * WRITEFILE, the file/offset fields denote the read positions. In state + * READFILE, inactive read pointers have valid file/offset, but the active + * read pointer implicitly has position equal to the temp file's seek position. + * + * Special case: if eof_reached is true, then the pointer's read position is + * implicitly equal to the write position, and current/file/offset aren't + * maintained. This way we need not update all the read pointers each time + * we write. + */ +typedef struct BSReadPointer { + int eflags; /* capability flags */ + bool eof_reached; /* read has reached EOF */ + int file; /* temp file# */ + off_t offset; /* byte offset in file */ +} BSReadPointer; + +class BatchStore : public VecStore { + +public: + // Memory context for main allocation + MemoryContext m_storecontext; + + /* + * enumerated value as shown above + */ + BatchStoreStatus m_status; + bool m_backward; /* store extra length words in file? */ + int m_eflags; /* capability flags (OR of pointers' flags) */ + + /* + * remaining memory allowed, in bytes + */ + int m_memtupdeleted; + + BufFile* m_myfile; /* underlying file, or NULL if none */ + + ResourceOwner m_resowner; /* resowner for holding temp files */ + bool m_interXact; /* keep open through transactions? */ + + bool m_eofReached; /* reached EOF (needed for cursors) */ + + /* + * These variables are used to keep track of the current positions. + * + * In state WRITEFILE, the current file seek position is the write point; + * in state READFILE, the write position is remembered in writepos_xxx. + * (The write position is the same as EOF, but since BufFileSeek doesn't + * currently implement SEEK_END, we have to remember it explicitly.) + */ + BSReadPointer* m_readptrs; /* array of read pointers */ + int m_activeptr; /* index of the active read pointer */ + int m_readptrcount; /* number of pointers currently valid */ + int m_readptrsize; /* allocated length of readptrs array */ + + int writepos_file; /* file# (valid if READFILE state) */ + off_t writepos_offset; /* offset (valid if READFILE state) */ + int m_markposOffset; /* saved "current", or offset in tape block */ + int m_lastbatchnum; + int m_lastfile_num; + + int m_lastwritebatchnum; + off_t m_lastwritefile_offset; + + off_t m_lastfile_offset; + bool m_windowagg_use; /* a flag used in windowagg */ + + /* + * Initialize variables. + */ + + void DumpMultiColumn(); + + void GetBatch(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + void PutBatch(VectorBatch* batch); + + void GetBatchInMemory(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + + void GetBatchReadFile(bool forward, VectorBatch* batch, int batch_rows = BatchMaxSize); + void GetBatchWriteFile(bool forward, VectorBatch* batch); + + void PutBatchToMemory(MultiColumns* multiColumn); + + void PutBatchReadFile(MultiColumns* multiColumn); + void PutBatchWriteFile(MultiColumns* multiColumn); + + void WriteMultiColumn(MultiColumns* stup); + + /* + * Function to read a stored tuple from tape back into memory. 'len' is + * the already-read length of the stored tuple. Create a palloc'd copy, + * initialize tuple/datum1/isnull1 in the target SortTuple struct, and + * decrease state->availMem by the amount of memory space consumed. + */ + void (*readMultiColumn)(BatchStore* state, MultiColumns& stup, unsigned int len); + +#ifdef PGXC + /* + * Function to read length of next stored tuple. + * Used as 'len' parameter for readtup function. + */ + unsigned int (*getlen)(BatchStore* state, bool eofOK); +#endif +}; + +/* + * Currently we only need to store MinimalTuples, but it would be easy + * to support the same behavior for IndexTuples and/or bare Datums. + */ + +extern BatchStore* batchstore_begin_heap( + TupleDesc tupDesc, bool randomAccess, bool interXact, int64 maxKBytes, int maxMem = 0, int planId = 0, int dop = 1); + +extern void batchstore_set_eflags(BatchStore* state, int eflags); + +extern void batchstore_putbatch(BatchStore* state, VectorBatch* batch); + +extern int batchstore_alloc_read_pointer(BatchStore* state, int eflags); + +extern void batchstore_trim(BatchStore* state, bool from_memory); +extern void batchstore_restrpos(BatchStore* state); +extern void batchstore_markpos(BatchStore* state, bool from_mem); +extern bool batchstore_getbatch(BatchStore* state, bool forward, VectorBatch* batch); +extern bool batchstore_ateof(BatchStore* state); +extern void batchstore_rescan(BatchStore* state); +extern void batchstore_end(BatchStore* state); +extern void ReadMultiColumn(BatchStore* state, MultiColumns& multiColumn, unsigned int len); + +unsigned int GetLen(BatchStore* state, bool eofOK); + +#endif /* TUPLESTORE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/be_module.h postgresql-hll-2.14/include/utils/be_module.h --- postgresql-hll-2.14_old/include/utils/be_module.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/be_module.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,167 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * be_module.h + * + * + * + * IDENTIFICATION + * src/include/utils/be_module.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_BE_MODULE_H +#define SRC_INCLUDE_UTILS_BE_MODULE_H + +/* + * How to add your module id ? + * 1. add your module id before MOD_MAX in ModuleId; + * 2. fill up module_map[] about module name, and keep their ordering; + * + */ +enum ModuleId { + /* fastpath for all modules on/off */ + MOD_ALL = 0, + /* add your module id following */ + + MOD_DFS, /* DFS */ + MOD_GUC, /* GUC */ + MOD_HDFS, /* HDFS feature */ + MOD_ORC, /* ORC storage format */ + MOD_SLRU, /* Simple LRU buffering manager */ + MOD_MEM, /* Memory Manager */ + MOD_AUTOVAC, /* auto-vacuum */ + MOD_CACHE, /* cache manager include data cache(cu , dfs) ,index cache(dfs)*/ + MOD_ADIO, /* ADIO feature */ + MOD_SSL, /* SSL */ + MOD_GDS, /* GDS */ + MOD_TBLSPC, /* Tablespace */ + MOD_WLM, /* workload manager*/ + MOD_OBS, /* OBS */ + MOD_EXECUTOR, /* Row Executor */ + MOD_OPFUSION, /* Bypass Opfusion */ + MOD_GPC, /* Global plancache */ + MOD_VEC_EXECUTOR, /* Vector Executor */ + MOD_STREAM, /* Stream */ + MOD_LLVM, /* LLVM */ + MOD_OPT, /* Optimizer default module */ + MOD_OPT_REWRITE, /* Optimizer sub-module:rewrite */ + MOD_OPT_JOIN, /* Optimizer sub-module:join */ + MOD_OPT_AGG, /* Optimizer sub-module:agg */ + MOD_OPT_SUBPLAN, /* Optimizer sub-module:subplan */ + MOD_OPT_SETOP, /* Optimizer sub-module:setop */ + MOD_OPT_SKEW, /* Optimizer sub-module:data skew */ + MOD_UDF, /* fenced udf */ + MOD_COOP_ANALYZE, /* cooperation analyze */ + MOD_WLM_CP, /* wlm for the comupte pool */ + MOD_ACCELERATE, /* accelerate with comptue pool */ + MOD_MOT, /* MOT */ + MOD_PLANHINT, /* plan hint */ + MOD_PARQUET, /* Parquet storage format */ + MOD_CARBONDATA, /* Carbondata storage format */ + + /* MODULE FOR TRANSACTION LOG CONTROL , USE LOG LEVEL*/ + MOD_TRANS_SNAPSHOT, /* Snapshot */ + MOD_TRANS_XACT, /* Xact Finite-State-Machine(FSM) */ + MOD_TRANS_HANDLE, /* Handle for Transaction */ + MOD_TRANS_CLOG, /* Clog Write */ + + MOD_EC, /* Extension Connector */ + MOD_REMOTE, /* remote read */ + MOD_CN_RETRY, /* cn retry */ + MOD_PLSQL, /* plpgsql */ + MOD_TS, /* TEXT SEARCH */ + MOD_SEQ, /* sequence */ + MOD_REDO, /* redo log */ + MOD_FUNCTION, /* internal function */ + MOD_PARSER, /* parser module*/ + MOD_INSTR, /* Instrumentation */ + MOD_INCRE_CKPT, /* incremental checkpoint */ + MOD_INCRE_BG, /* incremental checkpoint bgwriter */ + MOD_DW, /* double write */ + MOD_RTO, /* log control */ + MOD_HEARTBEAT, /* heartbeat */ + MOD_COMM_IPC, /* comm ipc performance */ + MOD_COMM_PARAM, /* comm session params */ + MOD_TIMESERIES, /* timeseries feature */ + MOD_SCHEMA, /* schema search */ + MOD_LIGHTPROXY, /* lightProxy */ + MOD_HOTKEY, /* hotkey */ + + /* add your module id above */ + MOD_MAX +}; + +/* 1 bit <--> 1 module, including MOD_MAX. its size is + * ((MOD_MAX+1)+7)/8 = MOD_MAX/8 + 1 + */ +#define BEMD_BITMAP_SIZE (1 + (MOD_MAX / 8)) + +#define MODULE_ID_IS_VALID(_id) ((_id) >= MOD_ALL && (_id) < MOD_MAX) +#define ALL_MODULES(_id) (MOD_ALL == (_id)) + +/* Is it a valid and signle module id ? */ +#define VALID_SINGLE_MODULE(_id) ((_id) > MOD_ALL && (_id) < MOD_MAX) + +/* max length of module name */ +#define MODULE_NAME_MAXLEN (16) + +/* delimiter of module name list about GUC parameter */ +#define MOD_DELIMITER ',' + +/* map about module id and its name */ +typedef struct module_data { + ModuleId mod_id; + const char mod_name[MODULE_NAME_MAXLEN]; +} module_data; + +/******************* be-module id <--> name **********************/ +extern ModuleId get_module_id(const char* module_name); + +/* Notice: + * declaration here only for the following inline functions, + * never use it within the other files directly. + */ +extern const module_data module_map[]; + +/* + * @Description: get the default module name. normally + * this module is not defined in ModuleId. + * @Return: default module name + * @See also: + */ +inline const char* get_default_module_name(void) +{ + return module_map[MOD_MAX].mod_name; +} + +/* + * @Description: find a module's name according to its id. + * @IN module_id: module id + * @Return: module name + * @See also: + */ +inline const char* get_valid_module_name(ModuleId module_id) +{ + return module_map[module_id].mod_name; +} + +/******************* be-module logging **********************/ +extern bool check_module_name_unique(void); +extern void module_logging_batch_set(ModuleId* mods, int nmods, bool turn_on, bool apply_all_modules); +extern bool module_logging_is_on(ModuleId module_id); +extern void module_logging_enable_comm(ModuleId module_id); + +#endif /* SRC_INCLUDE_UTILS_BE_MODULE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/biginteger.h postgresql-hll-2.14/include/utils/biginteger.h --- postgresql-hll-2.14_old/include/utils/biginteger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/biginteger.h 2020-12-12 17:06:43.393349922 +0800 @@ -0,0 +1,281 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * biginteger.h + * Definitions for the big integer data type + * + * Big integer(int64/int128) is one implementation of numeric data + * type, the purpose is to increase speed of numeric operators. + * + * IDENTIFICATION + * src/include/utils/biginteger.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_BIGINTERGER_H_ +#define SRC_INCLUDE_UTILS_BIGINTERGER_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "c.h" +#include "catalog/pg_type.h" +#include "fmgr.h" +#include "vecexecutor/vectorbatch.h" +#include "utils/array.h" +#include "utils/numeric.h" +#include "utils/numeric_gs.h" + +/* + * int32 integer: + * int32 value must in [-2147483648, 2147483647] + * abs(int32_value) < 10^11, so the max dscale of int32 can represent is 10. + * + * int64 integer: + * int64 value must in [-9223372036854775808, 9223372036854775807] + * abs(int64_value) < 10^20, so the max dscale of int64 can represent is 19. + * + * int128 integer: + * int128 value must in [-170141183460469231731687303715884105728, + * 170141183460469231731687303715884105727] + * abs(int128_value) < 10^40, so the max dscale of int128 can represent is + * 39, but some numbers with 39 digits can't be stored by int128, so just + * choose 38 instead because one number with 38 digits must can be stored + * by int128. + */ +#define MAXINT32DIGIT 10 +#define MAXINT64DIGIT 19 +#define MAXINT128DIGIT 38 + +/* the flag of failed dscale encoding */ +#define FAILED_DSCALE_ENCODING -1 + +/* the value of 10^18, it is used for print int128 data */ +#define P10_INT64 1000000000000000000LL /* 18 zeroes */ + +/* this macro represents the first dimension index of BiAggFunMatrix */ +#define BI_AGG_ADD 0 +#define BI_AGG_SMALLER 1 +#define BI_AGG_LARGER 2 + +/* + * determine whether one num can convert to int64 or int128 by the + * num's scale, this macro is used for both executor and storage modules. + */ +#define CAN_CONVERT_BI64(whole_scale) ((whole_scale) <= (MAXINT64DIGIT - 1)) +#define CAN_CONVERT_BI128(whole_scale) ((whole_scale) <= MAXINT128DIGIT) + +/* jduge whether int64 data can be transformed to int8 */ +#define INT64_INT8_EQ(data) ((data) == (int64)((int8)(data))) + +/* jduge whether int64 data can be transformed to int16 */ +#define INT64_INT16_EQ(data) ((data) == (int64)((int16)(data))) + +/* jduge whether int64 data can be transformed to int32 */ +#define INT64_INT32_EQ(data) ((data) == (int64)((int32)(data))) + +/* jduge whether int128 data can be transformed to int64 */ +#define INT128_INT64_EQ(data) ((data) == (int128)((int64)(data))) + +/* + * align two int64 vals by dscale, multipler is factorial of 10. + * set ScaleMultipler[i] = 10^i, i is between 0 and 18. + * 10^19 is out of int64 bound, so set ScaleMultipler[19] to 0. + */ +extern const int64 ScaleMultipler[20]; + +/* + * fast compare whether the result of arg * ScaleMultipler[i] + * is out of int64 bound. + * Int64MultiOutOfBound[i] = INT64_MIN / ScaleMultipler[i] + */ +extern const int64 Int64MultiOutOfBound[20]; + +/* + * @Description: calculates the factorial of 10, align two int128 + * vals by dscale, multipler is factorial of 10, set + * values[i] = 10^i, i is between 0 and 38. + * @IN scale: the scale'th power + * @Return: the factorial of 10 + */ +inline int128 getScaleMultiplier(int scale) +{ + Assert(scale >= 0 && scale <= MAXINT128DIGIT); + static const int128 values[] = {static_cast(1LL), + static_cast(10LL), + static_cast(100LL), + static_cast(1000LL), + static_cast(10000LL), + static_cast(100000LL), + static_cast(1000000LL), + static_cast(10000000LL), + static_cast(100000000LL), + static_cast(1000000000LL), + static_cast(10000000000LL), + static_cast(100000000000LL), + static_cast(1000000000000LL), + static_cast(10000000000000LL), + static_cast(100000000000000LL), + static_cast(1000000000000000LL), + static_cast(10000000000000000LL), + static_cast(100000000000000000LL), + static_cast(1000000000000000000LL), + static_cast(1000000000000000000LL) * 10LL, + static_cast(1000000000000000000LL) * 100LL, + static_cast(1000000000000000000LL) * 1000LL, + static_cast(1000000000000000000LL) * 10000LL, + static_cast(1000000000000000000LL) * 100000LL, + static_cast(1000000000000000000LL) * 1000000LL, + static_cast(1000000000000000000LL) * 10000000LL, + static_cast(1000000000000000000LL) * 100000000LL, + static_cast(1000000000000000000LL) * 1000000000LL, + static_cast(1000000000000000000LL) * 10000000000LL, + static_cast(1000000000000000000LL) * 100000000000LL, + static_cast(1000000000000000000LL) * 1000000000000LL, + static_cast(1000000000000000000LL) * 10000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000LL, + static_cast(1000000000000000000LL) * 1000000000000000LL, + static_cast(1000000000000000000LL) * 10000000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000000LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 10LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 100LL, + static_cast(1000000000000000000LL) * 100000000000000000LL * 1000LL}; + return values[scale]; +} + +/* + * @Description: fast compare whether the result of arg * getScaleMultiplier(i) + * is out of int128 bound. getScaleQuotient(i) equals to + * INT128_MIN / getScaleMultiplier(i) + * @IN scale: num between 0 and MAXINT128DIGIT + * @Return: values[scale] + */ +inline int128 getScaleQuotient(int scale) +{ + Assert(scale >= 0 && scale <= MAXINT128DIGIT); + static const int128 values[] = {INT128_MIN, + INT128_MIN / getScaleMultiplier(1), + INT128_MIN / getScaleMultiplier(2), + INT128_MIN / getScaleMultiplier(3), + INT128_MIN / getScaleMultiplier(4), + INT128_MIN / getScaleMultiplier(5), + INT128_MIN / getScaleMultiplier(6), + INT128_MIN / getScaleMultiplier(7), + INT128_MIN / getScaleMultiplier(8), + INT128_MIN / getScaleMultiplier(9), + INT128_MIN / getScaleMultiplier(10), + INT128_MIN / getScaleMultiplier(11), + INT128_MIN / getScaleMultiplier(12), + INT128_MIN / getScaleMultiplier(13), + INT128_MIN / getScaleMultiplier(14), + INT128_MIN / getScaleMultiplier(15), + INT128_MIN / getScaleMultiplier(16), + INT128_MIN / getScaleMultiplier(17), + INT128_MIN / getScaleMultiplier(18), + INT128_MIN / getScaleMultiplier(19), + INT128_MIN / getScaleMultiplier(20), + INT128_MIN / getScaleMultiplier(21), + INT128_MIN / getScaleMultiplier(22), + INT128_MIN / getScaleMultiplier(23), + INT128_MIN / getScaleMultiplier(24), + INT128_MIN / getScaleMultiplier(25), + INT128_MIN / getScaleMultiplier(26), + INT128_MIN / getScaleMultiplier(27), + INT128_MIN / getScaleMultiplier(28), + INT128_MIN / getScaleMultiplier(29), + INT128_MIN / getScaleMultiplier(30), + INT128_MIN / getScaleMultiplier(31), + INT128_MIN / getScaleMultiplier(32), + INT128_MIN / getScaleMultiplier(33), + INT128_MIN / getScaleMultiplier(34), + INT128_MIN / getScaleMultiplier(35), + INT128_MIN / getScaleMultiplier(36), + INT128_MIN / getScaleMultiplier(37), + INT128_MIN / getScaleMultiplier(38)}; + return values[scale]; +} + +/* + * big integer common operators, we implement corresponding + * functions of big integer for higher performance. + */ +enum biop { + BIADD = 0, // + + BISUB, // - + BIMUL, // * + BIDIV, // / + BIEQ, // = + BINEQ, // != + BILE, // <= + BILT, // < + BIGE, // >= + BIGT, // > + BICMP // > || == || < +}; + +/* + * when adjust scale for two big integer(int64 or int128) data, + * determine the result whether out of bound. + */ +enum BiAdjustScale { BI_AJUST_TRUE = 0, BI_LEFT_OUT_OF_BOUND, BI_RIGHT_OUT_OF_BOUND }; + +/* + * this struct is used for numeric agg function. + * use vechashtable::CopyVarP to decrease memory application. + */ +struct bictl { + Datum store_pos; + MemoryContext context; +}; + +/* + * Function to compute two big integer data(int64 or int128); + * include four operations and comparison operations. + */ +typedef Datum (*biopfun)(Numeric larg, Numeric rarg, bictl* ctl); + +/* + * three dimensional arrays: BiFunMatrix + * this array is used for fast locate the corresponding operation + * functions by operator and type(int64 or int128) + */ +extern const biopfun BiFunMatrix[11][2][2]; + +/* + * three dimensional arrays: BiAggFunMatrix + * this array is used for fast locate the corresponding agg + * functions by operator and type(int64 or int128) + */ +extern const biopfun BiAggFunMatrix[3][2][2]; + +/* convert big integer data to numeric */ +extern Numeric bitonumeric(Datum arg); +/* convert int(int1/int2/int4/int8) to big integer type */ +extern Datum int1_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int2_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int4_numeric_bi(PG_FUNCTION_ARGS); +extern Datum int8_numeric_bi(PG_FUNCTION_ARGS); +/* hash function for big integer(int64/int128/numeric) */ +extern Datum hash_bi(PG_FUNCTION_ARGS); +/* replace numeric hash function and equal function for VecHashAgg/VecHashJoin Node */ +extern void replace_numeric_hash_to_bi(int numCols, FmgrInfo* hashFunctions); +/* bi64 and bi128 output function */ +Datum bi64_out(int64 data, int scale); +Datum bi128_out(int128 data, int scale); + +Datum Simplebi64div64(Numeric larg, Numeric rarg); + +void Int128GetVal(bool is_int128, int128* val, Numeric* arg); + +#endif /* SRC_INCLUDE_UTILS_BIGINTERGER_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/bloom_filter.h postgresql-hll-2.14/include/utils/bloom_filter.h --- postgresql-hll-2.14_old/include/utils/bloom_filter.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/bloom_filter.h 2020-12-12 17:06:43.394349935 +0800 @@ -0,0 +1,465 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * bloom_filter.h + * + * + * + * IDENTIFICATION + * src/include/utils/bloom_filter.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef BLOOM_FILTER_H_ +#define BLOOM_FILTER_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "nodes/nodes.h" + +#define SATISFY_BLOOM_FILTER(dataType) \ + (dataType == INT2OID || dataType == INT4OID || dataType == INT8OID || dataType == FLOAT4OID || \ + dataType == FLOAT8OID || dataType == VARCHAROID || dataType == BPCHAROID || dataType == TEXTOID || \ + dataType == CLOBOID) +#define DEFAULT_ORC_BLOOM_FILTER_ENTRIES 10000 +#define MAX_HASH_FUNCTIONS 4 +#define LSB_IDENTIFY 6 +#define DEFAULT_FPP 0.05 // false positive + +typedef enum { + EQUAL_BLOOM_FILTER, /* for '=' predicate */ + HASHJOIN_BLOOM_FILTER, /* for hashjoin */ + IN_BLOOM_FILTER /* for in/any array */ +} BloomFilterType; + +typedef struct ValueBit { + uint16 position[MAX_HASH_FUNCTIONS]; +} ValueBit; + +/* + * Define the following struct in order to pushdown bloomfilter to computing pool. + * Thr bloomfilter to be stored type is HASHJOIN_BLOOM_FILTER . + */ +typedef struct BloomFilterSet { + NodeTag type; + /* store the BitSet info. */ + uint64* data; + uint64 length; + /* store the BloomFilterImpl info */ + uint64 numBits; + uint64 numHashFunctions; + uint64 numValues; + uint64 maxNumValues; + uint64 startupEntries; + ValueBit* valuePositions; + int64 minIntValue; /* data type to be storeed is one of int2, int4, int8. */ + float8 minFloatValue; /* data type to be storeed is one float4, float8. */ + char* minStringValue; /* data type to be stored is one of varcha, bpchar, text, clob. */ + int64 maxIntValue; /* data type to be storeed is one of int2, int4, int8. */ + float8 maxFloatValue; /* data type to be storeed is one float4, float8. */ + char* maxStringValue; /* data type to be stored is one of varcha, bpchar, text, clob. */ + bool addMinMax; + bool hasMM; + BloomFilterType bfType; + Oid dataType; + int32 typeMod; + Oid collation; +} BloomFilterSet; + +namespace filter { +class BloomFilter : public BaseObject { +public: + virtual ~BloomFilter(); + + /* Get the length of the uint64 array. */ + virtual uint64 getLength() const = 0; + + /* Get the number of bits in the inner set. */ + virtual uint64 getBitSize() const = 0; + + /* Get the number of hash functions used in the current bloom filter. */ + virtual uint64 getNumHashFunctions() const = 0; + + /* Get the number of values added into the current bloom filter. */ + virtual uint64 getNumValues() const = 0; + + /* Get the bitset(uint64 array) in the current bloom filter. */ + virtual const uint64* getBitSet() const = 0; + + /* Get the data type of the current bloom filter. */ + virtual Oid getDataType() const = 0; + virtual int32 getTypeMod() const = 0; + + /* + * Get the type of the current bloom filter: EQUAL_BLOOM_FILTER, + * HASHJOIN_BLOOM_FILTER or IN_BLOOM_FILTER. + */ + virtual BloomFilterType getType() const = 0; + + /* + * Get the flag which indicates whether the current bloom filter + * has min/max statistics. + */ + virtual bool hasMinMax() const = 0; + + /* + * Get the minimum value of all the values added to the + * current blomm filter. + */ + virtual Datum getMin() const = 0; + + /* + * Get the maximum value of all the values added to the + * current blomm filter. + */ + virtual Datum getMax() const = 0; + + /* + * Add a datum into the current bloom filter. + * @_in_param val: The datum to be added. + */ + virtual void addDatum(Datum val) = 0; + + /* + * Add a value of any supported data type into the current + * bloom filter. + * @_in_param value: The value to be added. + */ + template + void addValue(T value) + {} + + /* + * Check if the current bloom filter includes another datum. + * @_in_param value: The datum to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeDatum(Datum value) const = 0; + + /* + * Check if the current bloom filter includes a value of any + * supported data type. + * @_in_param value: The value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + template + bool includeValue(T value) const + { + return true; + } + + /* + * Check if the inner bloom filter is included in a bit set. + * If there is only one value stored in the inner bloom filter, call the + * native singleIncludedIn function. The single value is included in the + * bit set only when all the four bits of the value are set 1 in the bit + * set. If there are mulitple values stored in the inner bloom filter, + * check each of the values to see if there is at least one which is + * included in the bit set. The inner bloom filter does not refute the bit + * set unless on one match. + * @_in_param that: The bit set to be checked. + * @return true if the inner bloom filter is included in the bit set. + */ + virtual bool includedIn(const uint64* that) const = 0; + + /* + * Check if the inner bloom fitler is included in another bloom filter(we + * name it the outer bloom fitler here for easy). + * If there is only one value stored in the inner bloom filter, call the + * native singleIncludedIn function. The single value is included in the + * outer bloom filter only when all the four bits of the value are set 1 in + * the outer bloom filter. If there are mulitple values stored in the inner + * bloom filter, check each of the values to see if there is at least one + * which is included in the outer bloom fitler. The inner bloom filter does + * not refute the outer bloom filter unless on one match. + * @_in_param that: The bloom filter to be checked. + * @return true if the inner bloom filter is included in the outer one. + */ + virtual bool includedIn(const BloomFilter& that) const = 0; + + /* Union another bloom filter with the current bloom filter. */ + virtual void unionAll(const BloomFilter& that) = 0; + + /* Intersect another bloom filter with the current one. */ + virtual void intersectAll(const BloomFilter& that) = 0; + + /* Reset the current bloom filter. */ + virtual void reset() = 0; + /* make one bloomfilterSet struct in order to pushdown bloomfilter inot to computing pool.*/ + virtual BloomFilterSet* makeBloomFilterSet() = 0; + /* Fill the bloomfilter element by bloomFilterSet. */ + virtual void rebuildBloomFilterValue(BloomFilterSet* bloomFilterSet) = 0; + + /* Function pointer point to jitted_bf_addLong machine code */ + char* jitted_bf_addLong; + + /* Function pointer point to jitted_bf_includeLong machine code */ + char* jitted_bf_incLong; + + /* + * Check if the current bloom filter includes an int64 value. + * @_in_param value: The int64 value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeLong(int64 value) const = 0; + +protected: + /* Add an int64 value into the inner bloom filter. */ + virtual void addLong(int64 val) = 0; + + /* Add a double value into the inner bloom filter. */ + virtual void addDouble(double val) = 0; + + /* Add a string into the inner bloom filter. */ + virtual void addString(const char* val) = 0; + + /* + * Check if the current bloom filter includes a double value. + * @_in_param value: The double value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeDouble(double value) const = 0; + + /* + * Check if the current bloom filter includes a string value. + * @_in_param value: The string value to be checked. + * @return true if the value is included in the bloom filter + * or return false. + */ + virtual bool includeString(const char* value) const = 0; +}; + +/* + * Bare metal bit set implementation. For performance reasons, this implementation does not check + * for index bounds nor expand the bit set size if the specified index is greater than the size. + */ +class BitSet : public BaseObject { +public: + BitSet(const MemoryContext& ctx, const uint64 bits); + BitSet(uint64* _data, uint64 _length); + virtual ~BitSet(); + void set(uint64 index); + bool get(uint64 index) const; + uint64 getLength() const; + const uint64* getData() const; + void unionAll(const uint64* array); + void intersectAll(const uint64* array); + void clear(); + +public: + uint64* data; + uint64 length; +}; + +template +class BloomFilterImpl : public BloomFilter { +public: + BloomFilterImpl(MemoryContext& ctx, Oid dataType, int32 typeMod, Oid collation, BloomFilterType type, + int64 expectedEntries, double fpp, bool addMinMax); + BloomFilterImpl(MemoryContext& ctx, BloomFilterSet* bloomFilterSet); + virtual ~BloomFilterImpl(); + +private: + uint64 getLength() const; + uint64 getBitSize() const; + uint64 getNumHashFunctions() const; + uint64 getNumValues() const; + const uint64* getBitSet() const; + Oid getDataType() const; + BloomFilterType getType() const; + int32 getTypeMod() const; + bool hasMinMax() const; + Datum getMin() const; + Datum getMax() const; + void addDatum(Datum val) + {} + void addLong(int64 val) + {} + void addDouble(double val) + {} + void addString(const char* val) + {} + bool includeDatum(Datum value) const + { + return true; + } + bool includeLong(int64 value) const + { + return true; + } + bool includeDouble(double value) const + { + return true; + } + bool includeString(const char* value) const + { + return true; + } + bool includedIn(const uint64* that) const; + bool includedIn(const BloomFilter& that) const; + void unionAll(const BloomFilter& that); + void intersectAll(const BloomFilter& that); + void reset(); + + BloomFilterSet* makeBloomFilterSet(); + /* rebuild the element of BloomFilter. */ + void rebuildBloomFilterValue(BloomFilterSet* bloomFilterSet); + + /* set the min/max value by bloomFilterSet in the bloom filter. */ + void setMinMaxValueByBloomFilterSet(BloomFilterSet* bloomFilterSet){}; + /* set the min/max value for bloomFilterSet by bloom filter object. */ + void setMinMaxValueForBloomFilterSet(BloomFilterSet* bloomFilterSet){}; + + /* Convert data from float into int32. */ + int32 floatToInt32(float x) const; + + /* Store the min max value in the bloom filter. */ + void setMinMax(baseType val); + + /* Add a value which has been hashed in the bloom filter. */ + void addHash(int64 hash64); + + /* + * For integer(long) and float(double) data types, they are all converted + * to long type before been hashed. + */ + void addLongInternal(int64 val); + + /* Calucate the number of functions for hash. */ + uint64 optimalNumOfHashFunctions(int64 n, int m) const; + + /* Calculate the size of bit set which store the value. */ + uint64 optimalNumOfBits(int64 n, double p) const; + + /* Convert data from double into int64. */ + int64 doubleToInt64(double x) const; + + /* Thomas Wang's integer hash function */ + int64 getLongHash(int64 key) const; + + /* Check if a hashed value is included in the bloom filter. */ + bool includeHashInternal(int64 hash64) const; + + /* + * Check if the current bloom filter which has only one element + * is included in the other bitset. + */ + bool singleIncludedIn(const uint64* that) const; + + /* + * Check if the current bloom filter which has more than one elements + * is included in the other bitset. + */ + bool multiInCludedIn(const uint64* that) const; + + /* Convert raw value into datum. */ + Datum valueToDatum(baseType value) const + { + return 0; + } + + /* Convert datum into raw value. */ + baseType datumToValue(Datum datum) const + { + return 0; + } + + /* + * Compare two raw values, return 1 if left is bigger than right, + * return -1 if left is smaller than right, or return 0 if left + * is equal to right. + */ + int compareValue(baseType left, baseType right) const; + + /* + * Use min/max value to check if the current bloom filter + * is included in the other bloom filter. + */ + bool minMaxCheck(const BloomFilter& that) const; + +public: + BitSet* bitSet; + uint64 numBits; + uint64 numHashFunctions; + uint64 numValues; + uint64 maxNumValues; + uint64 startupEntries; + ValueBit* valuePositions; + baseType minValue; + baseType maxValue; + bool addMinMax; + bool hasMM; + BloomFilterType type; + Oid dataType; + int32 typeMod; + Oid collation; + MemoryContext context; +}; + +template <> +inline void BloomFilter::addValue(int64 value) +{ + addLong(value); +} + +template <> +inline void BloomFilter::addValue(double value) +{ + addDouble(value); +} + +template <> +inline void BloomFilter::addValue(char* value) +{ + addString(value); +} + +template <> +inline bool BloomFilter::includeValue(int64 value) const +{ + return includeLong(value); +} + +template <> +inline bool BloomFilter::includeValue(double value) const +{ + return includeDouble(value); +} + +template <> +inline bool BloomFilter::includeValue(char* value) const +{ + return includeString(value); +} + +/* + * Create a new bloom filter with special datatype, typemod, collation, max + * number of values to be added and the flag controlling if min/max statistics + * need to be added. + */ +BloomFilter* createBloomFilter( + Oid dataType, int32 typeMod, Oid collation, BloomFilterType type, int64 maxNumValues, bool addMinMax); +/* + * Create a new bloom filter object with bloomFilterSet struct. + */ +BloomFilter* createBloomFilter(BloomFilterSet* bloomFilterSet); + +} // namespace filter +#endif /* ORC_QUERY_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/builtins.h postgresql-hll-2.14/include/utils/builtins.h --- postgresql-hll-2.14_old/include/utils/builtins.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/builtins.h 2020-12-12 17:06:43.394349935 +0800 @@ -0,0 +1,1557 @@ +/* ------------------------------------------------------------------------- + * + * builtins.h + * Declarations for operations on built-in types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/builtins.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BUILTINS_H +#define BUILTINS_H + +#ifndef FRONTEND_PARSER +#include "fmgr.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#ifdef PGXC +#include "lib/stringinfo.h" +#endif +#include "utils/sortsupport.h" + +/* + * Defined in adt/ + */ + +/* acl.c */ +extern Datum has_any_column_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_any_column_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_name_attnum(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_column_privilege_id_attnum(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_table_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_sequence_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_database_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_directory_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_foreign_data_wrapper_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_function_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_language_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_nodegroup_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_schema_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_server_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_tablespace_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_type_privilege_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id_id(PG_FUNCTION_ARGS); +extern Datum pg_has_role_name(PG_FUNCTION_ARGS); +extern Datum pg_has_role_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_cmk_privilege_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id_id(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_name(PG_FUNCTION_ARGS); +extern Datum has_cek_privilege_id(PG_FUNCTION_ARGS); + +/* bool.c */ +extern Datum boolin(PG_FUNCTION_ARGS); +extern Datum boolout(PG_FUNCTION_ARGS); +extern Datum boolrecv(PG_FUNCTION_ARGS); +extern Datum boolsend(PG_FUNCTION_ARGS); +extern Datum booltext(PG_FUNCTION_ARGS); +extern Datum booleq(PG_FUNCTION_ARGS); +extern Datum boolne(PG_FUNCTION_ARGS); +extern Datum boollt(PG_FUNCTION_ARGS); +extern Datum boolgt(PG_FUNCTION_ARGS); +extern Datum boolle(PG_FUNCTION_ARGS); +extern Datum boolge(PG_FUNCTION_ARGS); +extern Datum disable_conn(PG_FUNCTION_ARGS); +extern Datum read_disable_conn_file(void); +extern Datum booland_statefunc(PG_FUNCTION_ARGS); +extern Datum boolor_statefunc(PG_FUNCTION_ARGS); +extern bool parse_bool(const char* value, bool* result); +extern bool parse_bool_with_len(const char* value, size_t len, bool* result); + +/* char.c */ +extern Datum charin(PG_FUNCTION_ARGS); +extern Datum charout(PG_FUNCTION_ARGS); +extern Datum charrecv(PG_FUNCTION_ARGS); +extern Datum charsend(PG_FUNCTION_ARGS); +extern Datum chareq(PG_FUNCTION_ARGS); +extern Datum charne(PG_FUNCTION_ARGS); +extern Datum charlt(PG_FUNCTION_ARGS); +extern Datum charle(PG_FUNCTION_ARGS); +extern Datum chargt(PG_FUNCTION_ARGS); +extern Datum charge(PG_FUNCTION_ARGS); +extern Datum chartoi4(PG_FUNCTION_ARGS); +extern Datum i4tochar(PG_FUNCTION_ARGS); +extern Datum text_char(PG_FUNCTION_ARGS); +extern Datum char_text(PG_FUNCTION_ARGS); + +/* domains.c */ +extern Datum domain_in(PG_FUNCTION_ARGS); +extern Datum domain_recv(PG_FUNCTION_ARGS); +extern void domain_check(Datum value, bool isnull, Oid domainType, void** extra, MemoryContext mcxt); + +/* encode.c */ +extern Datum binary_encode(PG_FUNCTION_ARGS); +extern Datum binary_decode(PG_FUNCTION_ARGS); +extern unsigned hex_encode(const char* src, unsigned len, char* dst); +extern unsigned hex_decode(const char* src, unsigned len, char* dst); + +/* enum.c */ +extern Datum enum_in(PG_FUNCTION_ARGS); +extern Datum enum_out(PG_FUNCTION_ARGS); +extern Datum enum_recv(PG_FUNCTION_ARGS); +extern Datum enum_send(PG_FUNCTION_ARGS); +extern Datum enum_lt(PG_FUNCTION_ARGS); +extern Datum enum_le(PG_FUNCTION_ARGS); +extern Datum enum_eq(PG_FUNCTION_ARGS); +extern Datum enum_ne(PG_FUNCTION_ARGS); +extern Datum enum_ge(PG_FUNCTION_ARGS); +extern Datum enum_gt(PG_FUNCTION_ARGS); +extern Datum enum_cmp(PG_FUNCTION_ARGS); +extern Datum enum_smaller(PG_FUNCTION_ARGS); +extern Datum enum_larger(PG_FUNCTION_ARGS); +extern Datum enum_first(PG_FUNCTION_ARGS); +extern Datum enum_last(PG_FUNCTION_ARGS); +extern Datum enum_range_bounds(PG_FUNCTION_ARGS); +extern Datum enum_range_all(PG_FUNCTION_ARGS); + +/* int.c */ +extern Datum int2in(PG_FUNCTION_ARGS); +extern Datum int2out(PG_FUNCTION_ARGS); +extern Datum int2recv(PG_FUNCTION_ARGS); +extern Datum int2send(PG_FUNCTION_ARGS); +extern Datum int2vectorin(PG_FUNCTION_ARGS); +extern Datum int2vectorout(PG_FUNCTION_ARGS); +extern Datum int2vectorrecv(PG_FUNCTION_ARGS); +extern Datum int2vectorsend(PG_FUNCTION_ARGS); +extern Datum int2vectoreq(PG_FUNCTION_ARGS); +extern Datum int4in(PG_FUNCTION_ARGS); +extern Datum int4out(PG_FUNCTION_ARGS); +extern Datum int4recv(PG_FUNCTION_ARGS); +extern Datum int4send(PG_FUNCTION_ARGS); +extern Datum i2toi4(PG_FUNCTION_ARGS); +extern Datum i4toi2(PG_FUNCTION_ARGS); +extern Datum int4_bool(PG_FUNCTION_ARGS); +extern Datum bool_int4(PG_FUNCTION_ARGS); +extern Datum int2_bool(PG_FUNCTION_ARGS); +extern Datum bool_int2(PG_FUNCTION_ARGS); +extern Datum int4eq(PG_FUNCTION_ARGS); +extern Datum int4ne(PG_FUNCTION_ARGS); +extern Datum int4lt(PG_FUNCTION_ARGS); +extern Datum int4le(PG_FUNCTION_ARGS); +extern Datum int4gt(PG_FUNCTION_ARGS); +extern Datum int4ge(PG_FUNCTION_ARGS); +extern Datum int2eq(PG_FUNCTION_ARGS); +extern Datum int2ne(PG_FUNCTION_ARGS); +extern Datum int2lt(PG_FUNCTION_ARGS); +extern Datum int2le(PG_FUNCTION_ARGS); +extern Datum int2gt(PG_FUNCTION_ARGS); +extern Datum int2ge(PG_FUNCTION_ARGS); +extern Datum int24eq(PG_FUNCTION_ARGS); +extern Datum int24ne(PG_FUNCTION_ARGS); +extern Datum int24lt(PG_FUNCTION_ARGS); +extern Datum int24le(PG_FUNCTION_ARGS); +extern Datum int24gt(PG_FUNCTION_ARGS); +extern Datum int24ge(PG_FUNCTION_ARGS); +extern Datum int42eq(PG_FUNCTION_ARGS); +extern Datum int42ne(PG_FUNCTION_ARGS); +extern Datum int42lt(PG_FUNCTION_ARGS); +extern Datum int42le(PG_FUNCTION_ARGS); +extern Datum int42gt(PG_FUNCTION_ARGS); +extern Datum int42ge(PG_FUNCTION_ARGS); +extern Datum int4um(PG_FUNCTION_ARGS); +extern Datum int4up(PG_FUNCTION_ARGS); +extern Datum int4pl(PG_FUNCTION_ARGS); +extern Datum int4mi(PG_FUNCTION_ARGS); +extern Datum int4mul(PG_FUNCTION_ARGS); +extern Datum int4div(PG_FUNCTION_ARGS); +extern Datum int4abs(PG_FUNCTION_ARGS); +extern Datum int4inc(PG_FUNCTION_ARGS); +extern Datum int2um(PG_FUNCTION_ARGS); +extern Datum int2up(PG_FUNCTION_ARGS); +extern Datum int2pl(PG_FUNCTION_ARGS); +extern Datum int2mi(PG_FUNCTION_ARGS); +extern Datum int2mul(PG_FUNCTION_ARGS); +extern Datum int2div(PG_FUNCTION_ARGS); +extern Datum int2abs(PG_FUNCTION_ARGS); +extern Datum int24pl(PG_FUNCTION_ARGS); +extern Datum int24mi(PG_FUNCTION_ARGS); +extern Datum int24mul(PG_FUNCTION_ARGS); +extern Datum int24div(PG_FUNCTION_ARGS); +extern Datum int42pl(PG_FUNCTION_ARGS); +extern Datum int42mi(PG_FUNCTION_ARGS); +extern Datum int42mul(PG_FUNCTION_ARGS); +extern Datum int42div(PG_FUNCTION_ARGS); +extern Datum int4mod(PG_FUNCTION_ARGS); +extern Datum int2mod(PG_FUNCTION_ARGS); +extern Datum int2larger(PG_FUNCTION_ARGS); +extern Datum int2smaller(PG_FUNCTION_ARGS); +extern Datum int4larger(PG_FUNCTION_ARGS); +extern Datum int4smaller(PG_FUNCTION_ARGS); +extern Datum int1in(PG_FUNCTION_ARGS); +extern Datum int1out(PG_FUNCTION_ARGS); +extern Datum int1recv(PG_FUNCTION_ARGS); +extern Datum int1send(PG_FUNCTION_ARGS); +extern Datum int1eq(PG_FUNCTION_ARGS); +extern Datum int1ne(PG_FUNCTION_ARGS); +extern Datum int1lt(PG_FUNCTION_ARGS); +extern Datum int1le(PG_FUNCTION_ARGS); +extern Datum int1gt(PG_FUNCTION_ARGS); +extern Datum int1ge(PG_FUNCTION_ARGS); +extern Datum int1cmp(PG_FUNCTION_ARGS); +extern Datum i1toi2(PG_FUNCTION_ARGS); +extern Datum i2toi1(PG_FUNCTION_ARGS); +extern Datum i1toi4(PG_FUNCTION_ARGS); +extern Datum i4toi1(PG_FUNCTION_ARGS); +extern Datum i1toi8(PG_FUNCTION_ARGS); +extern Datum i8toi1(PG_FUNCTION_ARGS); +extern Datum i1tof4(PG_FUNCTION_ARGS); +extern Datum f4toi1(PG_FUNCTION_ARGS); +extern Datum i1tof8(PG_FUNCTION_ARGS); +extern Datum f8toi1(PG_FUNCTION_ARGS); +extern Datum int1_bool(PG_FUNCTION_ARGS); +extern Datum bool_int1(PG_FUNCTION_ARGS); +extern Datum int4_bpchar(PG_FUNCTION_ARGS); +extern Datum int1_bpchar(PG_FUNCTION_ARGS); +extern Datum int2_bpchar(PG_FUNCTION_ARGS); +extern Datum float4_bpchar(PG_FUNCTION_ARGS); +extern Datum float8_bpchar(PG_FUNCTION_ARGS); +extern Datum numeric_bpchar(PG_FUNCTION_ARGS); +extern Datum int1and(PG_FUNCTION_ARGS); +extern Datum int1or(PG_FUNCTION_ARGS); +extern Datum int1xor(PG_FUNCTION_ARGS); +extern Datum int1not(PG_FUNCTION_ARGS); +extern Datum int1shl(PG_FUNCTION_ARGS); +extern Datum int1shr(PG_FUNCTION_ARGS); +extern Datum int1um(PG_FUNCTION_ARGS); +extern Datum int1up(PG_FUNCTION_ARGS); +extern Datum int1pl(PG_FUNCTION_ARGS); +extern Datum int1mi(PG_FUNCTION_ARGS); +extern Datum int1mul(PG_FUNCTION_ARGS); +extern Datum int1div(PG_FUNCTION_ARGS); +extern Datum int1abs(PG_FUNCTION_ARGS); +extern Datum int1mod(PG_FUNCTION_ARGS); +extern Datum int1larger(PG_FUNCTION_ARGS); +extern Datum int1smaller(PG_FUNCTION_ARGS); +extern Datum int1inc(PG_FUNCTION_ARGS); + +extern Datum int4and(PG_FUNCTION_ARGS); +extern Datum int4or(PG_FUNCTION_ARGS); +extern Datum int4xor(PG_FUNCTION_ARGS); +extern Datum int4not(PG_FUNCTION_ARGS); +extern Datum int4shl(PG_FUNCTION_ARGS); +extern Datum int4shr(PG_FUNCTION_ARGS); +extern Datum int2and(PG_FUNCTION_ARGS); +extern Datum int2or(PG_FUNCTION_ARGS); +extern Datum int2xor(PG_FUNCTION_ARGS); +extern Datum int2not(PG_FUNCTION_ARGS); +extern Datum int2shl(PG_FUNCTION_ARGS); +extern Datum int2shr(PG_FUNCTION_ARGS); +extern Datum generate_series_int4(PG_FUNCTION_ARGS); +extern Datum generate_series_step_int4(PG_FUNCTION_ARGS); +extern int2vector* buildint2vector(const int2* int2s, int n); +extern int2vector* int2vectorCopy(int2vector* from); + +/* lsyscache.cpp */ +extern Datum node_oid_name(PG_FUNCTION_ARGS); +/* tablespace.cpp */ +extern Datum tablespace_oid_name(PG_FUNCTION_ARGS); +/* namespace.cpp */ +extern Datum get_schema_oid(PG_FUNCTION_ARGS); +/* name.c */ +extern Datum namein(PG_FUNCTION_ARGS); +extern Datum nameout(PG_FUNCTION_ARGS); +extern Datum namerecv(PG_FUNCTION_ARGS); +extern Datum namesend(PG_FUNCTION_ARGS); +extern Datum nameeq(PG_FUNCTION_ARGS); +extern Datum nameeq_withhead(PG_FUNCTION_ARGS); +extern Datum namene(PG_FUNCTION_ARGS); +extern Datum namelt(PG_FUNCTION_ARGS); +extern Datum namele(PG_FUNCTION_ARGS); +extern Datum namegt(PG_FUNCTION_ARGS); +extern Datum namege(PG_FUNCTION_ARGS); +extern int namestrcpy(Name name, const char* str); +extern int namestrcmp(Name name, const char* str); +extern Datum current_user(PG_FUNCTION_ARGS); +extern Datum session_user(PG_FUNCTION_ARGS); +extern Datum current_schema(PG_FUNCTION_ARGS); +extern Datum current_schemas(PG_FUNCTION_ARGS); +extern Datum pseudo_current_user(PG_FUNCTION_ARGS); +extern uint64 pg_strtouint64(const char* str, char** endptr, int base); + +/* numutils.c */ +extern int32 pg_atoi(char* s, int size, int c); +extern int16 pg_strtoint16(const char* s); +extern int32 pg_strtoint32(const char* s); +extern void pg_itoa(int16 i, char* a); +extern void pg_ltoa(int32 l, char* a); +extern void pg_ctoa(uint8 i, char* a); +extern void pg_lltoa(int64 ll, char* a); + +/* + * Per-opclass comparison functions for new btrees. These are + * stored in pg_amproc; most are defined in access/nbtree/nbtcompare.c + */ +extern Datum btboolcmp(PG_FUNCTION_ARGS); +extern Datum btint2cmp(PG_FUNCTION_ARGS); +extern Datum btint4cmp(PG_FUNCTION_ARGS); +extern Datum btint8cmp(PG_FUNCTION_ARGS); +extern Datum btfloat4cmp(PG_FUNCTION_ARGS); +extern Datum btfloat8cmp(PG_FUNCTION_ARGS); +extern Datum btint48cmp(PG_FUNCTION_ARGS); +extern Datum btint84cmp(PG_FUNCTION_ARGS); +extern Datum btint24cmp(PG_FUNCTION_ARGS); +extern Datum btint42cmp(PG_FUNCTION_ARGS); +extern Datum btint28cmp(PG_FUNCTION_ARGS); +extern Datum btint82cmp(PG_FUNCTION_ARGS); +extern Datum btfloat48cmp(PG_FUNCTION_ARGS); +extern Datum btfloat84cmp(PG_FUNCTION_ARGS); +extern Datum btoidcmp(PG_FUNCTION_ARGS); +extern Datum btoidvectorcmp(PG_FUNCTION_ARGS); +extern Datum btabstimecmp(PG_FUNCTION_ARGS); +extern Datum btreltimecmp(PG_FUNCTION_ARGS); +extern Datum bttintervalcmp(PG_FUNCTION_ARGS); +extern Datum btcharcmp(PG_FUNCTION_ARGS); +extern Datum btnamecmp(PG_FUNCTION_ARGS); +extern Datum bttextcmp(PG_FUNCTION_ARGS); +extern Datum bpchar_sortsupport(PG_FUNCTION_ARGS); +extern Datum bttextsortsupport(PG_FUNCTION_ARGS); +/* + * Per-opclass sort support functions for new btrees. Like the + * functions above, these are stored in pg_amproc; most are defined in + * access/nbtree/nbtcompare.c + */ +extern Datum btint2sortsupport(PG_FUNCTION_ARGS); +extern Datum btint4sortsupport(PG_FUNCTION_ARGS); +extern Datum btint8sortsupport(PG_FUNCTION_ARGS); +extern Datum btfloat4sortsupport(PG_FUNCTION_ARGS); +extern Datum btfloat8sortsupport(PG_FUNCTION_ARGS); +extern Datum btoidsortsupport(PG_FUNCTION_ARGS); +extern Datum btnamesortsupport(PG_FUNCTION_ARGS); + +extern double get_float8_infinity(void); +extern float get_float4_infinity(void); +extern double get_float8_nan(void); +extern float get_float4_nan(void); +extern int is_infinite(double val); + +extern Datum float4in(PG_FUNCTION_ARGS); +extern Datum float4out(PG_FUNCTION_ARGS); +extern Datum float4recv(PG_FUNCTION_ARGS); +extern Datum float4send(PG_FUNCTION_ARGS); +extern Datum float8in(PG_FUNCTION_ARGS); +extern Datum float8out(PG_FUNCTION_ARGS); +extern Datum float8recv(PG_FUNCTION_ARGS); +extern Datum float8send(PG_FUNCTION_ARGS); +extern Datum float4abs(PG_FUNCTION_ARGS); +extern Datum float4um(PG_FUNCTION_ARGS); +extern Datum float4up(PG_FUNCTION_ARGS); +extern Datum float4larger(PG_FUNCTION_ARGS); +extern Datum float4smaller(PG_FUNCTION_ARGS); +extern Datum float8abs(PG_FUNCTION_ARGS); +extern Datum float8um(PG_FUNCTION_ARGS); +extern Datum float8up(PG_FUNCTION_ARGS); +extern Datum float8larger(PG_FUNCTION_ARGS); +extern Datum float8smaller(PG_FUNCTION_ARGS); +extern Datum float4pl(PG_FUNCTION_ARGS); +extern Datum float4mi(PG_FUNCTION_ARGS); +extern Datum float4mul(PG_FUNCTION_ARGS); +extern Datum float4div(PG_FUNCTION_ARGS); +extern Datum float8pl(PG_FUNCTION_ARGS); +extern Datum float8mi(PG_FUNCTION_ARGS); +extern Datum float8mul(PG_FUNCTION_ARGS); +extern Datum float8div(PG_FUNCTION_ARGS); +extern Datum float4eq(PG_FUNCTION_ARGS); +extern Datum float4ne(PG_FUNCTION_ARGS); +extern Datum float4lt(PG_FUNCTION_ARGS); +extern Datum float4le(PG_FUNCTION_ARGS); +extern Datum float4gt(PG_FUNCTION_ARGS); +extern Datum float4ge(PG_FUNCTION_ARGS); +extern Datum float8eq(PG_FUNCTION_ARGS); +extern Datum float8ne(PG_FUNCTION_ARGS); +extern Datum float8lt(PG_FUNCTION_ARGS); +extern Datum float8le(PG_FUNCTION_ARGS); +extern Datum float8gt(PG_FUNCTION_ARGS); +extern Datum float8ge(PG_FUNCTION_ARGS); +extern Datum ftod(PG_FUNCTION_ARGS); +extern Datum i4tod(PG_FUNCTION_ARGS); +extern Datum i2tod(PG_FUNCTION_ARGS); +extern Datum dtof(PG_FUNCTION_ARGS); +extern Datum dtoi4(PG_FUNCTION_ARGS); +extern Datum dtoi2(PG_FUNCTION_ARGS); +extern Datum i4tof(PG_FUNCTION_ARGS); +extern Datum i2tof(PG_FUNCTION_ARGS); +extern Datum ftoi4(PG_FUNCTION_ARGS); +extern Datum ftoi2(PG_FUNCTION_ARGS); +extern Datum dround(PG_FUNCTION_ARGS); +extern Datum dceil(PG_FUNCTION_ARGS); +extern Datum dfloor(PG_FUNCTION_ARGS); +extern Datum dsign(PG_FUNCTION_ARGS); +extern Datum dtrunc(PG_FUNCTION_ARGS); +extern Datum dsqrt(PG_FUNCTION_ARGS); +extern Datum dcbrt(PG_FUNCTION_ARGS); +extern Datum dpow(PG_FUNCTION_ARGS); +extern Datum dexp(PG_FUNCTION_ARGS); +extern Datum dlog1(PG_FUNCTION_ARGS); +extern Datum dlog10(PG_FUNCTION_ARGS); +extern Datum dacos(PG_FUNCTION_ARGS); +extern Datum dasin(PG_FUNCTION_ARGS); +extern Datum datan(PG_FUNCTION_ARGS); +extern Datum datan2(PG_FUNCTION_ARGS); +extern Datum dcos(PG_FUNCTION_ARGS); +extern Datum dcot(PG_FUNCTION_ARGS); +extern Datum dsin(PG_FUNCTION_ARGS); +extern Datum dtan(PG_FUNCTION_ARGS); +extern Datum degrees(PG_FUNCTION_ARGS); +extern Datum dpi(PG_FUNCTION_ARGS); +extern Datum radians(PG_FUNCTION_ARGS); +extern Datum drandom(PG_FUNCTION_ARGS); +extern Datum setseed(PG_FUNCTION_ARGS); +extern Datum float8_accum(PG_FUNCTION_ARGS); +extern Datum float4_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum float8_collect(PG_FUNCTION_ARGS); +#endif +extern Datum float8_avg(PG_FUNCTION_ARGS); +extern Datum float8_var_pop(PG_FUNCTION_ARGS); +extern Datum float8_var_samp(PG_FUNCTION_ARGS); +extern Datum float8_stddev_pop(PG_FUNCTION_ARGS); +extern Datum float8_stddev_samp(PG_FUNCTION_ARGS); +extern Datum float8_regr_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum float8_regr_collect(PG_FUNCTION_ARGS); +#endif +extern Datum float8_regr_sxx(PG_FUNCTION_ARGS); +extern Datum float8_regr_syy(PG_FUNCTION_ARGS); +extern Datum float8_regr_sxy(PG_FUNCTION_ARGS); +extern Datum float8_regr_avgx(PG_FUNCTION_ARGS); +extern Datum float8_regr_avgy(PG_FUNCTION_ARGS); +extern Datum float8_covar_pop(PG_FUNCTION_ARGS); +extern Datum float8_covar_samp(PG_FUNCTION_ARGS); +extern Datum float8_corr(PG_FUNCTION_ARGS); +extern Datum float8_regr_r2(PG_FUNCTION_ARGS); +extern Datum float8_regr_slope(PG_FUNCTION_ARGS); +extern Datum float8_regr_intercept(PG_FUNCTION_ARGS); +extern Datum float48pl(PG_FUNCTION_ARGS); +extern Datum float48mi(PG_FUNCTION_ARGS); +extern Datum float48mul(PG_FUNCTION_ARGS); +extern Datum float48div(PG_FUNCTION_ARGS); +extern Datum float84pl(PG_FUNCTION_ARGS); +extern Datum float84mi(PG_FUNCTION_ARGS); +extern Datum float84mul(PG_FUNCTION_ARGS); +extern Datum float84div(PG_FUNCTION_ARGS); +extern Datum float48eq(PG_FUNCTION_ARGS); +extern Datum float48ne(PG_FUNCTION_ARGS); +extern Datum float48lt(PG_FUNCTION_ARGS); +extern Datum float48le(PG_FUNCTION_ARGS); +extern Datum float48gt(PG_FUNCTION_ARGS); +extern Datum float48ge(PG_FUNCTION_ARGS); +extern Datum float84eq(PG_FUNCTION_ARGS); +extern Datum float84ne(PG_FUNCTION_ARGS); +extern Datum float84lt(PG_FUNCTION_ARGS); +extern Datum float84le(PG_FUNCTION_ARGS); +extern Datum float84gt(PG_FUNCTION_ARGS); +extern Datum float84ge(PG_FUNCTION_ARGS); +extern Datum width_bucket_float8(PG_FUNCTION_ARGS); +Datum float8_multiply_text(PG_FUNCTION_ARGS); +Datum text_multiply_float8(PG_FUNCTION_ARGS); + +/* dbsize.c */ +extern Datum pg_tablespace_size_oid(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_size_name(PG_FUNCTION_ARGS); +extern Datum pg_database_size_oid(PG_FUNCTION_ARGS); +extern Datum pg_database_size_name(PG_FUNCTION_ARGS); +extern Datum get_db_source_datasize(PG_FUNCTION_ARGS); +extern Datum pg_switch_relfilenode_name(PG_FUNCTION_ARGS); +extern Datum pg_relation_size(PG_FUNCTION_ARGS); +extern Datum pg_total_relation_size(PG_FUNCTION_ARGS); +extern Datum pg_size_pretty(PG_FUNCTION_ARGS); +extern Datum pg_size_pretty_numeric(PG_FUNCTION_ARGS); +extern Datum pg_table_size(PG_FUNCTION_ARGS); +extern Datum pg_partition_size(PG_FUNCTION_ARGS); +extern Datum pg_partition_indexes_size(PG_FUNCTION_ARGS); +extern Datum pg_indexes_size(PG_FUNCTION_ARGS); +extern Datum pg_relation_filenode(PG_FUNCTION_ARGS); +extern Datum pg_filenode_relation(PG_FUNCTION_ARGS); +extern Datum pg_relation_filepath(PG_FUNCTION_ARGS); +extern Datum pg_relation_is_scannable(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pg_relation_with_compression(PG_FUNCTION_ARGS); +extern Datum pg_relation_compression_ratio(PG_FUNCTION_ARGS); +#endif +extern Datum pg_partition_filenode(PG_FUNCTION_ARGS); +extern Datum pg_partition_filepath(PG_FUNCTION_ARGS); +/* regioninfo.cpp */ +extern Datum pg_clean_region_info(PG_FUNCTION_ARGS); + +/* genfile.c */ +extern bytea* read_binary_file( + const char* filename, int64 seek_offset, int64 bytes_to_read, bool missing_ok, bool need_check = false); +extern Datum pg_stat_file(PG_FUNCTION_ARGS); +extern Datum pg_read_file(PG_FUNCTION_ARGS); +extern Datum pg_read_file_all(PG_FUNCTION_ARGS); +extern Datum pg_read_binary_file(PG_FUNCTION_ARGS); +extern Datum pg_read_binary_file_all(PG_FUNCTION_ARGS); +extern Datum pg_ls_dir(PG_FUNCTION_ARGS); +extern Datum pg_stat_file_recursive(PG_FUNCTION_ARGS); + +/* misc.c */ +extern Datum current_database(PG_FUNCTION_ARGS); +extern Datum current_query(PG_FUNCTION_ARGS); +extern Datum pg_cancel_backend(PG_FUNCTION_ARGS); +extern Datum pg_cancel_invalid_query(PG_FUNCTION_ARGS); +extern Datum pg_terminate_backend(PG_FUNCTION_ARGS); +extern Datum pg_terminate_session(PG_FUNCTION_ARGS); +extern Datum pg_reload_conf(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS); +extern Datum pg_tablespace_location(PG_FUNCTION_ARGS); +extern Datum pg_rotate_logfile(PG_FUNCTION_ARGS); +extern Datum pg_sleep(PG_FUNCTION_ARGS); +extern Datum pg_get_keywords(PG_FUNCTION_ARGS); +extern Datum pg_typeof(PG_FUNCTION_ARGS); +extern Datum pg_collation_for(PG_FUNCTION_ARGS); +extern Datum pg_sync_cstore_delta(PG_FUNCTION_ARGS); +extern Datum pg_sync_all_cstore_delta(PG_FUNCTION_ARGS); +extern Datum pg_test_err_contain_err(PG_FUNCTION_ARGS); + +/* oid.c */ +extern Datum oidin(PG_FUNCTION_ARGS); +extern Datum oidout(PG_FUNCTION_ARGS); +extern Datum oidrecv(PG_FUNCTION_ARGS); +extern Datum oidsend(PG_FUNCTION_ARGS); +extern Datum oideq(PG_FUNCTION_ARGS); +extern Datum oidne(PG_FUNCTION_ARGS); +extern Datum oidlt(PG_FUNCTION_ARGS); +extern Datum oidle(PG_FUNCTION_ARGS); +extern Datum oidge(PG_FUNCTION_ARGS); +extern Datum oidgt(PG_FUNCTION_ARGS); +extern Datum oidlarger(PG_FUNCTION_ARGS); +extern Datum oidsmaller(PG_FUNCTION_ARGS); +extern Datum oidvectorin(PG_FUNCTION_ARGS); +extern Datum oidvectorout(PG_FUNCTION_ARGS); +extern Datum oidvectorrecv(PG_FUNCTION_ARGS); +extern Datum oidvectorsend(PG_FUNCTION_ARGS); +extern Datum oidvectoreq(PG_FUNCTION_ARGS); +extern Datum oidvectorne(PG_FUNCTION_ARGS); +extern Datum oidvectorlt(PG_FUNCTION_ARGS); +extern Datum oidvectorle(PG_FUNCTION_ARGS); +extern Datum oidvectorge(PG_FUNCTION_ARGS); +extern Datum oidvectorgt(PG_FUNCTION_ARGS); +extern oidvector* buildoidvector(const Oid* oids, int n); +extern Oid oidparse(Node* node); + +/* pseudotypes.c */ +extern Datum cstring_in(PG_FUNCTION_ARGS); +extern Datum cstring_out(PG_FUNCTION_ARGS); +extern Datum cstring_recv(PG_FUNCTION_ARGS); +extern Datum cstring_send(PG_FUNCTION_ARGS); +extern Datum any_in(PG_FUNCTION_ARGS); +extern Datum any_out(PG_FUNCTION_ARGS); +extern Datum anyarray_in(PG_FUNCTION_ARGS); +extern Datum anyarray_out(PG_FUNCTION_ARGS); +extern Datum anyarray_recv(PG_FUNCTION_ARGS); +extern Datum anyarray_send(PG_FUNCTION_ARGS); +extern Datum anynonarray_in(PG_FUNCTION_ARGS); +extern Datum anynonarray_out(PG_FUNCTION_ARGS); +extern Datum anyenum_in(PG_FUNCTION_ARGS); +extern Datum anyenum_out(PG_FUNCTION_ARGS); +extern Datum anyrange_in(PG_FUNCTION_ARGS); +extern Datum anyrange_out(PG_FUNCTION_ARGS); +extern Datum void_in(PG_FUNCTION_ARGS); +extern Datum void_out(PG_FUNCTION_ARGS); +extern Datum void_recv(PG_FUNCTION_ARGS); +extern Datum void_send(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pgxc_node_str(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_backup(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_sp_database(PG_FUNCTION_ARGS); +extern Datum pgxc_unlock_for_sp_database(PG_FUNCTION_ARGS); +extern Datum pgxc_lock_for_transfer(PG_FUNCTION_ARGS); +extern Datum pgxc_unlock_for_transfer(PG_FUNCTION_ARGS); +#endif +extern Datum trigger_in(PG_FUNCTION_ARGS); +extern Datum trigger_out(PG_FUNCTION_ARGS); +extern Datum language_handler_in(PG_FUNCTION_ARGS); +extern Datum language_handler_out(PG_FUNCTION_ARGS); +extern Datum fdw_handler_in(PG_FUNCTION_ARGS); +extern Datum fdw_handler_out(PG_FUNCTION_ARGS); +extern Datum internal_in(PG_FUNCTION_ARGS); +extern Datum internal_out(PG_FUNCTION_ARGS); +extern Datum opaque_in(PG_FUNCTION_ARGS); +extern Datum opaque_out(PG_FUNCTION_ARGS); +extern Datum anyelement_in(PG_FUNCTION_ARGS); +extern Datum anyelement_out(PG_FUNCTION_ARGS); +extern Datum shell_in(PG_FUNCTION_ARGS); +extern Datum shell_out(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_in(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_out(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_recv(PG_FUNCTION_ARGS); +extern Datum pg_node_tree_send(PG_FUNCTION_ARGS); + +/* regexp.c */ +extern Datum textregexsubstr_enforce_oracle(PG_FUNCTION_ARGS); +extern Datum nameregexeq(PG_FUNCTION_ARGS); +extern Datum nameregexne(PG_FUNCTION_ARGS); +extern Datum textregexeq(PG_FUNCTION_ARGS); +extern Datum textregexne(PG_FUNCTION_ARGS); +extern Datum nameicregexeq(PG_FUNCTION_ARGS); +extern Datum nameicregexne(PG_FUNCTION_ARGS); +extern Datum texticregexeq(PG_FUNCTION_ARGS); +extern Datum texticregexne(PG_FUNCTION_ARGS); +extern Datum textregexsubstr(PG_FUNCTION_ARGS); +extern Datum textregexreplace_noopt(PG_FUNCTION_ARGS); +extern Datum textregexreplace(PG_FUNCTION_ARGS); +extern Datum similar_escape(PG_FUNCTION_ARGS); +extern Datum regexp_matches(PG_FUNCTION_ARGS); +extern Datum regexp_matches_no_flags(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_table(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_table_no_flags(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_array(PG_FUNCTION_ARGS); +extern Datum regexp_match_to_array(PG_FUNCTION_ARGS); +extern Datum regexp_split_to_array_no_flags(PG_FUNCTION_ARGS); +extern char* regexp_fixed_prefix(text* text_re, bool case_insensitive, Oid collation, bool* exact); + +/* regproc.c */ +extern Datum regprocin(PG_FUNCTION_ARGS); +extern Datum regprocout(PG_FUNCTION_ARGS); +extern Datum regprocrecv(PG_FUNCTION_ARGS); +extern Datum regprocsend(PG_FUNCTION_ARGS); +extern Datum regprocedurein(PG_FUNCTION_ARGS); +extern Datum regprocedureout(PG_FUNCTION_ARGS); +extern Datum regprocedurerecv(PG_FUNCTION_ARGS); +extern Datum regproceduresend(PG_FUNCTION_ARGS); +extern Datum regoperin(PG_FUNCTION_ARGS); +extern Datum regoperout(PG_FUNCTION_ARGS); +extern Datum regoperrecv(PG_FUNCTION_ARGS); +extern Datum regopersend(PG_FUNCTION_ARGS); +extern Datum regoperatorin(PG_FUNCTION_ARGS); +extern Datum regoperatorout(PG_FUNCTION_ARGS); +extern Datum regoperatorrecv(PG_FUNCTION_ARGS); +extern Datum regoperatorsend(PG_FUNCTION_ARGS); +extern Datum regclassin(PG_FUNCTION_ARGS); +extern Datum regclassout(PG_FUNCTION_ARGS); +extern Datum regclassrecv(PG_FUNCTION_ARGS); +extern Datum regclasssend(PG_FUNCTION_ARGS); +extern Datum regtypein(PG_FUNCTION_ARGS); +extern Datum regtypeout(PG_FUNCTION_ARGS); +extern Datum regtyperecv(PG_FUNCTION_ARGS); +extern Datum regtypesend(PG_FUNCTION_ARGS); +extern Datum regconfigin(PG_FUNCTION_ARGS); +extern Datum regconfigout(PG_FUNCTION_ARGS); +extern Datum regconfigrecv(PG_FUNCTION_ARGS); +extern Datum regconfigsend(PG_FUNCTION_ARGS); +extern Datum regdictionaryin(PG_FUNCTION_ARGS); +extern Datum regdictionaryout(PG_FUNCTION_ARGS); +extern Datum regdictionaryrecv(PG_FUNCTION_ARGS); +extern Datum regdictionarysend(PG_FUNCTION_ARGS); +extern Datum text_regclass(PG_FUNCTION_ARGS); +extern List* stringToQualifiedNameList(const char* string); +extern char* format_procedure(Oid procedure_oid); +extern char* format_operator(Oid operator_oid); + +/* rowtypes.c */ +extern Datum record_in(PG_FUNCTION_ARGS); +extern Datum record_out(PG_FUNCTION_ARGS); +extern Datum record_recv(PG_FUNCTION_ARGS); +extern Datum record_send(PG_FUNCTION_ARGS); +extern Datum record_eq(PG_FUNCTION_ARGS); +extern Datum record_ne(PG_FUNCTION_ARGS); +extern Datum record_lt(PG_FUNCTION_ARGS); +extern Datum record_gt(PG_FUNCTION_ARGS); +extern Datum record_le(PG_FUNCTION_ARGS); +extern Datum record_ge(PG_FUNCTION_ARGS); +extern Datum btrecordcmp(PG_FUNCTION_ARGS); + +/* ruleutils.c */ +extern Datum pg_get_ruledef(PG_FUNCTION_ARGS); +extern Datum pg_get_ruledef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_wrap(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_name(PG_FUNCTION_ARGS); +extern Datum pg_get_viewdef_name_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_indexdef(PG_FUNCTION_ARGS); +extern Datum pg_get_indexdef_ext(PG_FUNCTION_ARGS); +extern char* pg_get_indexdef_string(Oid indexrelid); +extern char* pg_get_indexdef_columns(Oid indexrelid, bool pretty); +extern Datum pg_get_triggerdef(PG_FUNCTION_ARGS); +extern Datum pg_get_triggerdef_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_constraintdef(PG_FUNCTION_ARGS); +extern Datum pg_get_constraintdef_ext(PG_FUNCTION_ARGS); +extern char* pg_get_constraintdef_string(Oid constraintId); +extern Datum pg_get_expr(PG_FUNCTION_ARGS); +extern Datum pg_get_expr_ext(PG_FUNCTION_ARGS); +extern Datum pg_get_userbyid(PG_FUNCTION_ARGS); +extern Datum pg_get_serial_sequence(PG_FUNCTION_ARGS); +extern Datum pg_get_functiondef(PG_FUNCTION_ARGS); +extern Datum pg_get_function_arguments(PG_FUNCTION_ARGS); +extern Datum pg_get_function_identity_arguments(PG_FUNCTION_ARGS); +extern Datum pg_get_function_result(PG_FUNCTION_ARGS); +extern char* deparse_expression(Node* expr, List* dpcontext, bool forceprefix, bool showimplicit); +extern char* deparse_create_sequence(Node* stmt, bool owned_by_none = false); +extern char* deparse_alter_sequence(Node* stmt, bool owned_by_none = false); + +#ifdef PGXC +extern void deparse_query(Query* query, StringInfo buf, List* parentnamespace, bool finalise_aggs, bool sortgroup_colno, + void* parserArg = NULL, bool qrw_phase = false, bool is_fqs = false); +extern void deparse_targetlist(Query* query, List* targetList, StringInfo buf); +#endif +extern List* deparse_context_for(const char* aliasname, Oid relid); +extern List* deparse_context_for_planstate(Node* planstate, List* ancestors, List* rtable); +#ifdef PGXC +extern List* deparse_context_for_plan(Node* plan, List* ancestors, List* rtable); +#endif +extern const char* quote_identifier(const char* ident); +extern char* quote_qualified_identifier(const char* qualifier, const char* ident); +extern char* generate_collation_name(Oid collid); +extern void get_utility_stmt_def(AlterTableStmt* stmt, StringInfo buf); + +/* tid.c */ +extern Datum tidin(PG_FUNCTION_ARGS); +extern Datum tidout(PG_FUNCTION_ARGS); +extern Datum tidrecv(PG_FUNCTION_ARGS); +extern Datum tidsend(PG_FUNCTION_ARGS); +extern Datum tideq(PG_FUNCTION_ARGS); +extern Datum tidne(PG_FUNCTION_ARGS); +extern Datum tidlt(PG_FUNCTION_ARGS); +extern Datum tidle(PG_FUNCTION_ARGS); +extern Datum tidgt(PG_FUNCTION_ARGS); +extern Datum tidge(PG_FUNCTION_ARGS); +extern Datum bttidcmp(PG_FUNCTION_ARGS); +extern Datum tidlarger(PG_FUNCTION_ARGS); +extern Datum tidsmaller(PG_FUNCTION_ARGS); +extern Datum bigint_tid(PG_FUNCTION_ARGS); +extern Datum cstore_tid_out(PG_FUNCTION_ARGS); +extern Datum currtid_byreloid(PG_FUNCTION_ARGS); +extern Datum currtid_byrelname(PG_FUNCTION_ARGS); + +/* varchar.c */ +extern Datum bpcharlenb(PG_FUNCTION_ARGS); +extern Datum bpcharin(PG_FUNCTION_ARGS); +extern Datum bpcharout(PG_FUNCTION_ARGS); +extern Datum bpcharrecv(PG_FUNCTION_ARGS); +extern Datum bpcharsend(PG_FUNCTION_ARGS); +extern Datum bpchartypmodin(PG_FUNCTION_ARGS); +extern Datum bpchartypmodout(PG_FUNCTION_ARGS); +extern Datum bpchar(PG_FUNCTION_ARGS); +extern Datum char_bpchar(PG_FUNCTION_ARGS); +extern Datum name_bpchar(PG_FUNCTION_ARGS); +extern Datum bpchar_name(PG_FUNCTION_ARGS); +extern Datum bpchareq(PG_FUNCTION_ARGS); +extern Datum bpcharne(PG_FUNCTION_ARGS); +extern Datum bpcharlt(PG_FUNCTION_ARGS); +extern Datum bpcharle(PG_FUNCTION_ARGS); +extern Datum bpchargt(PG_FUNCTION_ARGS); +extern Datum bpcharge(PG_FUNCTION_ARGS); +extern Datum bpcharcmp(PG_FUNCTION_ARGS); +extern Datum bpchar_larger(PG_FUNCTION_ARGS); +extern Datum bpchar_smaller(PG_FUNCTION_ARGS); +extern int bpchartruelen(const char* s, int len); +extern Datum bpcharlen(PG_FUNCTION_ARGS); +extern int bcTruelen(BpChar* arg); +extern Datum bpcharoctetlen(PG_FUNCTION_ARGS); +extern Datum hashbpchar(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_lt(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_le(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_gt(PG_FUNCTION_ARGS); +extern Datum bpchar_pattern_ge(PG_FUNCTION_ARGS); +extern Datum btbpchar_pattern_cmp(PG_FUNCTION_ARGS); + +extern Datum varcharin(PG_FUNCTION_ARGS); +extern Datum varcharout(PG_FUNCTION_ARGS); +extern Datum varcharrecv(PG_FUNCTION_ARGS); +extern Datum varcharsend(PG_FUNCTION_ARGS); +extern Datum varchartypmodin(PG_FUNCTION_ARGS); +extern Datum varchartypmodout(PG_FUNCTION_ARGS); +extern Datum varchar_transform(PG_FUNCTION_ARGS); +extern Datum varchar(PG_FUNCTION_ARGS); + +extern Datum nvarchar2in(PG_FUNCTION_ARGS); +extern Datum nvarchar2out(PG_FUNCTION_ARGS); +extern Datum nvarchar2recv(PG_FUNCTION_ARGS); +extern Datum nvarchar2send(PG_FUNCTION_ARGS); +extern Datum nvarchar2typmodin(PG_FUNCTION_ARGS); +extern Datum nvarchar2typmodout(PG_FUNCTION_ARGS); +extern Datum nvarchar2(PG_FUNCTION_ARGS); + +/* varlena.c */ +extern text* cstring_to_text(const char* s); +extern text* cstring_to_text_with_len(const char* s, size_t len); +extern bytea *cstring_to_bytea_with_len(const char *s, int len); +extern char* text_to_cstring(const text* t); +extern void text_to_cstring_buffer(const text* src, char* dst, size_t dst_len); +extern int text_instr_3args(text* textStr, text* textStrToSearch, int32 beginIndex); +extern int text_instr_4args(text* textStr, text* textStrToSearch, int32 beginIndex, int occurTimes); +extern int32 text_length(Datum str); +extern int text_cmp(text* arg1, text* arg2, Oid collid); +extern text* text_substring(Datum str, int32 start, int32 length, bool length_not_specified); +extern Datum instr_3args(PG_FUNCTION_ARGS); +extern Datum instr_4args(PG_FUNCTION_ARGS); +extern Datum byteain(PG_FUNCTION_ARGS); +extern void text_to_bktmap(text* gbucket, uint2* bktmap, int len); + +#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s)) +#define TextDatumGetCString(d) text_to_cstring((text*)DatumGetPointer(d)) + +#define CStringGetByteaDatum(s, len) PointerGetDatum(cstring_to_bytea_with_len(s, len)) + +extern Datum rawin(PG_FUNCTION_ARGS); +extern Datum rawout(PG_FUNCTION_ARGS); +extern Datum rawtotext(PG_FUNCTION_ARGS); +extern Datum texttoraw(PG_FUNCTION_ARGS); +extern Datum raweq(PG_FUNCTION_ARGS); +extern Datum rawne(PG_FUNCTION_ARGS); +extern Datum rawlt(PG_FUNCTION_ARGS); +extern Datum rawle(PG_FUNCTION_ARGS); +extern Datum rawgt(PG_FUNCTION_ARGS); +extern Datum rawge(PG_FUNCTION_ARGS); +extern Datum rawcmp(PG_FUNCTION_ARGS); +extern Datum rawcat(PG_FUNCTION_ARGS); +extern Datum rawlike(PG_FUNCTION_ARGS); +extern Datum rawnlike(PG_FUNCTION_ARGS); +extern Datum textin(PG_FUNCTION_ARGS); +extern Datum textout(PG_FUNCTION_ARGS); +extern Datum textrecv(PG_FUNCTION_ARGS); +extern Datum textsend(PG_FUNCTION_ARGS); +extern Datum textcat(PG_FUNCTION_ARGS); +extern Datum texteq(PG_FUNCTION_ARGS); +extern Datum textne(PG_FUNCTION_ARGS); +extern Datum text_lt(PG_FUNCTION_ARGS); +extern Datum text_le(PG_FUNCTION_ARGS); +extern Datum text_gt(PG_FUNCTION_ARGS); +extern Datum text_ge(PG_FUNCTION_ARGS); +extern Datum text_larger(PG_FUNCTION_ARGS); +extern Datum text_smaller(PG_FUNCTION_ARGS); +extern Datum text_pattern_lt(PG_FUNCTION_ARGS); +extern Datum text_pattern_le(PG_FUNCTION_ARGS); +extern Datum text_pattern_gt(PG_FUNCTION_ARGS); +extern Datum text_pattern_ge(PG_FUNCTION_ARGS); +extern Datum bttext_pattern_cmp(PG_FUNCTION_ARGS); +extern Datum textlen(PG_FUNCTION_ARGS); +extern Datum textoctetlen(PG_FUNCTION_ARGS); +extern Datum textpos(PG_FUNCTION_ARGS); +extern Datum text_substr(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len(PG_FUNCTION_ARGS); +extern Datum text_substr_null(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len_null(PG_FUNCTION_ARGS); +extern Datum text_substr_orclcompat(PG_FUNCTION_ARGS); +extern Datum text_substr_no_len_orclcompat(PG_FUNCTION_ARGS); +extern Datum bytea_substr_orclcompat(PG_FUNCTION_ARGS); +extern Datum bytea_substr_no_len_orclcompat(PG_FUNCTION_ARGS); +extern Datum textoverlay(PG_FUNCTION_ARGS); +extern Datum textoverlay_no_len(PG_FUNCTION_ARGS); +extern Datum name_text(PG_FUNCTION_ARGS); +extern Datum text_name(PG_FUNCTION_ARGS); +extern int varstr_cmp(char* arg1, int len1, char* arg2, int len2, Oid collid); +extern void varstr_sortsupport(SortSupport ssup, Oid collid, bool bpchar); +extern List* textToQualifiedNameList(text* textval); +extern bool SplitIdentifierString(char* rawstring, char separator, List** namelist, bool downCase = true, bool truncateToolong = true); +extern bool SplitIdentifierInteger(char* rawstring, char separator, List** namelist); +extern Datum replace_text(PG_FUNCTION_ARGS); +extern text* replace_text_regexp(text* src_text, void* regexp, text* replace_text, bool glob); +extern Datum split_text(PG_FUNCTION_ARGS); +extern Datum text_to_array(PG_FUNCTION_ARGS); +extern Datum array_to_text(PG_FUNCTION_ARGS); +extern Datum text_to_array_null(PG_FUNCTION_ARGS); +extern Datum array_to_text_null(PG_FUNCTION_ARGS); +extern Datum to_hex32(PG_FUNCTION_ARGS); +extern Datum to_hex64(PG_FUNCTION_ARGS); +extern Datum md5_text(PG_FUNCTION_ARGS); +extern Datum md5_bytea(PG_FUNCTION_ARGS); + +extern Datum unknownin(PG_FUNCTION_ARGS); +extern Datum unknownout(PG_FUNCTION_ARGS); +extern Datum unknownrecv(PG_FUNCTION_ARGS); +extern Datum unknownsend(PG_FUNCTION_ARGS); + +extern Datum pg_column_size(PG_FUNCTION_ARGS); +extern Datum datalength(PG_FUNCTION_ARGS); + +extern Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS); +extern Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum string_agg_transfn(PG_FUNCTION_ARGS); +extern Datum string_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum checksumtext_agg_transfn(PG_FUNCTION_ARGS); + +extern Datum list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum list_agg_finalfn(PG_FUNCTION_ARGS); +extern Datum list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int2_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int2_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int4_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int4_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum int8_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum int8_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum float4_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum float4_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum float8_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum float8_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum numeric_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum numeric_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum date_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum date_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum timestamp_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum timestamp_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum timestamptz_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum timestamptz_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); +extern Datum interval_list_agg_transfn(PG_FUNCTION_ARGS); +extern Datum interval_list_agg_noarg2_transfn(PG_FUNCTION_ARGS); + +extern Datum text_concat(PG_FUNCTION_ARGS); +extern Datum text_concat_ws(PG_FUNCTION_ARGS); +extern Datum text_left(PG_FUNCTION_ARGS); +extern Datum text_right(PG_FUNCTION_ARGS); +extern Datum text_reverse(PG_FUNCTION_ARGS); +extern Datum text_format(PG_FUNCTION_ARGS); +extern Datum text_format_nv(PG_FUNCTION_ARGS); + +/* byteawithoutorderwithequalcol.cpp */ +extern Datum byteawithoutordercolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoltypmodin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoltypmodout(PG_FUNCTION_ARGS); + +/* version.c */ +extern Datum pgsql_version(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum pgxc_version(PG_FUNCTION_ARGS); +#endif + +/* xid.c */ +extern Datum xidin(PG_FUNCTION_ARGS); +extern Datum xidout(PG_FUNCTION_ARGS); +extern Datum xidrecv(PG_FUNCTION_ARGS); +extern Datum xidsend(PG_FUNCTION_ARGS); +extern Datum xideq(PG_FUNCTION_ARGS); +extern Datum xidlt(PG_FUNCTION_ARGS); +extern Datum xid_age(PG_FUNCTION_ARGS); +extern Datum xidin4(PG_FUNCTION_ARGS); +extern Datum xidout4(PG_FUNCTION_ARGS); +extern Datum xidrecv4(PG_FUNCTION_ARGS); +extern Datum xidsend4(PG_FUNCTION_ARGS); +extern Datum xideq4(PG_FUNCTION_ARGS); +extern Datum xidlt4(PG_FUNCTION_ARGS); +extern int xidComparator(const void* arg1, const void* arg2); +extern Datum cidin(PG_FUNCTION_ARGS); +extern Datum cidout(PG_FUNCTION_ARGS); +extern Datum cidrecv(PG_FUNCTION_ARGS); +extern Datum cidsend(PG_FUNCTION_ARGS); +extern Datum cideq(PG_FUNCTION_ARGS); +extern int RemoveRepetitiveXids(TransactionId* xids, int nxid); + +/* like.c */ +#define LIKE_TRUE 1 +#define LIKE_FALSE 0 +#define LIKE_ABORT (-1) + +extern Datum namelike(PG_FUNCTION_ARGS); +extern Datum namenlike(PG_FUNCTION_ARGS); +extern Datum nameiclike(PG_FUNCTION_ARGS); +extern Datum nameicnlike(PG_FUNCTION_ARGS); +extern Datum textlike(PG_FUNCTION_ARGS); +extern Datum textnlike(PG_FUNCTION_ARGS); +extern Datum texticlike(PG_FUNCTION_ARGS); +extern Datum texticnlike(PG_FUNCTION_ARGS); +extern Datum bytealike(PG_FUNCTION_ARGS); +extern Datum byteanlike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlike(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollikebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlikebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollikebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnlikebyteal(PG_FUNCTION_ARGS); +extern Datum like_escape(PG_FUNCTION_ARGS); +extern Datum like_escape_bytea(PG_FUNCTION_ARGS); +extern int GenericMatchText(char* s, int slen, char* p, int plen); + +/* oracle_compat.c */ +extern Datum lower(PG_FUNCTION_ARGS); +extern Datum upper(PG_FUNCTION_ARGS); +extern Datum initcap(PG_FUNCTION_ARGS); +extern Datum lpad(PG_FUNCTION_ARGS); +extern Datum rpad(PG_FUNCTION_ARGS); +extern Datum btrim(PG_FUNCTION_ARGS); +extern Datum btrim1(PG_FUNCTION_ARGS); +extern Datum byteatrim(PG_FUNCTION_ARGS); +extern Datum ltrim(PG_FUNCTION_ARGS); +extern Datum ltrim1(PG_FUNCTION_ARGS); +extern Datum rtrim(PG_FUNCTION_ARGS); +extern Datum rtrim1(PG_FUNCTION_ARGS); +extern Datum translate(PG_FUNCTION_ARGS); +extern Datum chr(PG_FUNCTION_ARGS); +extern Datum repeat(PG_FUNCTION_ARGS); +extern Datum ascii(PG_FUNCTION_ARGS); + +/* inet_cidr_ntop.c */ +extern char* inet_cidr_ntop(int af, const void* src, int bits, char* dst, size_t size); + +/* inet_net_pton.c */ +extern int inet_net_pton(int af, const char* src, void* dst, size_t size); + +/* network.c */ +extern Datum inet_in(PG_FUNCTION_ARGS); +extern Datum inet_out(PG_FUNCTION_ARGS); +extern Datum inet_recv(PG_FUNCTION_ARGS); +extern Datum inet_send(PG_FUNCTION_ARGS); +extern Datum cidr_in(PG_FUNCTION_ARGS); +extern Datum cidr_out(PG_FUNCTION_ARGS); +extern Datum cidr_recv(PG_FUNCTION_ARGS); +extern Datum cidr_send(PG_FUNCTION_ARGS); +extern Datum network_cmp(PG_FUNCTION_ARGS); +extern Datum network_lt(PG_FUNCTION_ARGS); +extern Datum network_le(PG_FUNCTION_ARGS); +extern Datum network_eq(PG_FUNCTION_ARGS); +extern Datum network_ge(PG_FUNCTION_ARGS); +extern Datum network_gt(PG_FUNCTION_ARGS); +extern Datum network_ne(PG_FUNCTION_ARGS); +extern Datum hashinet(PG_FUNCTION_ARGS); +extern Datum network_sub(PG_FUNCTION_ARGS); +extern Datum network_subeq(PG_FUNCTION_ARGS); +extern Datum network_sup(PG_FUNCTION_ARGS); +extern Datum network_supeq(PG_FUNCTION_ARGS); +extern Datum network_network(PG_FUNCTION_ARGS); +extern Datum network_netmask(PG_FUNCTION_ARGS); +extern Datum network_hostmask(PG_FUNCTION_ARGS); +extern Datum network_masklen(PG_FUNCTION_ARGS); +extern Datum network_family(PG_FUNCTION_ARGS); +extern Datum network_broadcast(PG_FUNCTION_ARGS); +extern Datum network_host(PG_FUNCTION_ARGS); +extern Datum network_show(PG_FUNCTION_ARGS); +extern Datum inet_abbrev(PG_FUNCTION_ARGS); +extern Datum cidr_abbrev(PG_FUNCTION_ARGS); +extern double convert_network_to_scalar(Datum value, Oid typid); +extern Datum inet_to_cidr(PG_FUNCTION_ARGS); +extern Datum inet_set_masklen(PG_FUNCTION_ARGS); +extern Datum cidr_set_masklen(PG_FUNCTION_ARGS); +extern Datum network_scan_first(Datum in); +extern Datum network_scan_last(Datum in); +extern Datum inet_client_addr(PG_FUNCTION_ARGS); +extern Datum inet_client_port(PG_FUNCTION_ARGS); +extern Datum inet_server_addr(PG_FUNCTION_ARGS); +extern Datum inet_server_port(PG_FUNCTION_ARGS); +extern Datum inetnot(PG_FUNCTION_ARGS); +extern Datum inetand(PG_FUNCTION_ARGS); +extern Datum inetor(PG_FUNCTION_ARGS); +extern Datum inetpl(PG_FUNCTION_ARGS); +extern Datum inetmi_int8(PG_FUNCTION_ARGS); +extern Datum inetmi(PG_FUNCTION_ARGS); +extern void clean_ipv6_addr(int addr_family, char* addr); + +/* mac.c */ +extern Datum macaddr_in(PG_FUNCTION_ARGS); +extern Datum macaddr_out(PG_FUNCTION_ARGS); +extern Datum macaddr_recv(PG_FUNCTION_ARGS); +extern Datum macaddr_send(PG_FUNCTION_ARGS); +extern Datum macaddr_cmp(PG_FUNCTION_ARGS); +extern Datum macaddr_lt(PG_FUNCTION_ARGS); +extern Datum macaddr_le(PG_FUNCTION_ARGS); +extern Datum macaddr_eq(PG_FUNCTION_ARGS); +extern Datum macaddr_ge(PG_FUNCTION_ARGS); +extern Datum macaddr_gt(PG_FUNCTION_ARGS); +extern Datum macaddr_ne(PG_FUNCTION_ARGS); +extern Datum macaddr_not(PG_FUNCTION_ARGS); +extern Datum macaddr_and(PG_FUNCTION_ARGS); +extern Datum macaddr_or(PG_FUNCTION_ARGS); +extern Datum macaddr_trunc(PG_FUNCTION_ARGS); +extern Datum hashmacaddr(PG_FUNCTION_ARGS); + +/* numeric.c */ +extern Datum numeric_in(PG_FUNCTION_ARGS); +extern Datum numeric_out(PG_FUNCTION_ARGS); +extern Datum numeric_recv(PG_FUNCTION_ARGS); +extern Datum numeric_send(PG_FUNCTION_ARGS); +extern Datum numerictypmodin(PG_FUNCTION_ARGS); +extern Datum numerictypmodout(PG_FUNCTION_ARGS); +extern Datum numeric_transform(PG_FUNCTION_ARGS); +extern Datum numeric(PG_FUNCTION_ARGS); +extern Datum numeric_abs(PG_FUNCTION_ARGS); +extern Datum numeric_uminus(PG_FUNCTION_ARGS); +extern Datum numeric_uplus(PG_FUNCTION_ARGS); +extern Datum numeric_sign(PG_FUNCTION_ARGS); +extern Datum numeric_round(PG_FUNCTION_ARGS); +extern Datum numeric_trunc(PG_FUNCTION_ARGS); +extern Datum numeric_ceil(PG_FUNCTION_ARGS); +extern Datum numeric_floor(PG_FUNCTION_ARGS); +extern Datum numeric_cmp(PG_FUNCTION_ARGS); +extern Datum numeric_eq(PG_FUNCTION_ARGS); +extern Datum numeric_ne(PG_FUNCTION_ARGS); +extern Datum numeric_gt(PG_FUNCTION_ARGS); +extern Datum numeric_ge(PG_FUNCTION_ARGS); +extern Datum numeric_lt(PG_FUNCTION_ARGS); +extern Datum numeric_le(PG_FUNCTION_ARGS); +extern Datum numeric_add(PG_FUNCTION_ARGS); +extern Datum numeric_sub(PG_FUNCTION_ARGS); +extern Datum numeric_mul(PG_FUNCTION_ARGS); +extern Datum numeric_div(PG_FUNCTION_ARGS); +extern Datum numeric_div_trunc(PG_FUNCTION_ARGS); +extern Datum numeric_mod(PG_FUNCTION_ARGS); +extern Datum numeric_inc(PG_FUNCTION_ARGS); +extern Datum numeric_smaller(PG_FUNCTION_ARGS); +extern Datum numeric_larger(PG_FUNCTION_ARGS); +extern Datum numeric_fac(PG_FUNCTION_ARGS); +extern Datum numeric_sqrt(PG_FUNCTION_ARGS); +extern Datum numeric_exp(PG_FUNCTION_ARGS); +extern Datum numeric_ln(PG_FUNCTION_ARGS); +extern Datum numeric_log(PG_FUNCTION_ARGS); +extern Datum numeric_power(PG_FUNCTION_ARGS); +extern Datum int4_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int4(PG_FUNCTION_ARGS); +extern Datum int8_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int8(PG_FUNCTION_ARGS); +extern Datum int2_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int2(PG_FUNCTION_ARGS); +extern Datum int1_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_int1(PG_FUNCTION_ARGS); +extern Datum float8_numeric(PG_FUNCTION_ARGS); +extern Datum float8_interval(PG_FUNCTION_ARGS); +extern Datum numeric_float8(PG_FUNCTION_ARGS); +extern Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS); +extern Datum float4_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_float4(PG_FUNCTION_ARGS); +extern Datum numeric_accum(PG_FUNCTION_ARGS); +extern Datum numeric_avg_accum(PG_FUNCTION_ARGS); +extern Datum int2_accum(PG_FUNCTION_ARGS); +extern Datum int4_accum(PG_FUNCTION_ARGS); +extern Datum int8_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum numeric_collect(PG_FUNCTION_ARGS); +#endif +extern Datum int8_avg_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum numeric_avg_collect(PG_FUNCTION_ARGS); +#endif +extern Datum numeric_avg(PG_FUNCTION_ARGS); +extern Datum numeric_var_pop(PG_FUNCTION_ARGS); +extern Datum numeric_var_samp(PG_FUNCTION_ARGS); +extern Datum numeric_stddev_pop(PG_FUNCTION_ARGS); +extern Datum numeric_stddev_samp(PG_FUNCTION_ARGS); +extern Datum int2_sum(PG_FUNCTION_ARGS); +extern Datum int4_sum(PG_FUNCTION_ARGS); +extern Datum int8_sum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum int8_sum_to_int8(PG_FUNCTION_ARGS); +#endif +extern Datum int1_avg_accum(PG_FUNCTION_ARGS); +extern Datum int2_avg_accum(PG_FUNCTION_ARGS); +extern Datum int4_avg_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum int8_avg_collect(PG_FUNCTION_ARGS); +#endif +extern Datum int8_avg(PG_FUNCTION_ARGS); +extern Datum width_bucket_numeric(PG_FUNCTION_ARGS); +extern Datum hash_numeric(PG_FUNCTION_ARGS); +extern Datum numtodsinterval(PG_FUNCTION_ARGS); +extern Datum numeric_interval(PG_FUNCTION_ARGS); +extern Datum int1_interval(PG_FUNCTION_ARGS); +extern Datum int2_interval(PG_FUNCTION_ARGS); +extern Datum int4_interval(PG_FUNCTION_ARGS); + +/* ri_triggers.c */ +extern Datum RI_FKey_check_ins(PG_FUNCTION_ARGS); +extern Datum RI_FKey_check_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_noaction_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_noaction_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_cascade_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_cascade_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_restrict_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_restrict_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setnull_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setnull_upd(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setdefault_del(PG_FUNCTION_ARGS); +extern Datum RI_FKey_setdefault_upd(PG_FUNCTION_ARGS); + +/* trigfuncs.c */ +extern Datum suppress_redundant_updates_trigger(PG_FUNCTION_ARGS); + +/* encoding support functions */ +extern Datum getdatabaseencoding(PG_FUNCTION_ARGS); +extern Datum database_character_set(PG_FUNCTION_ARGS); +extern Datum pg_client_encoding(PG_FUNCTION_ARGS); +extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS); +extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS); +extern Datum PG_character_set_name(PG_FUNCTION_ARGS); +extern Datum PG_character_set_id(PG_FUNCTION_ARGS); +extern Datum pg_convert(PG_FUNCTION_ARGS); +extern Datum pg_convert_to(PG_FUNCTION_ARGS); +extern Datum pg_convert_nocase(PG_FUNCTION_ARGS); +extern Datum pg_convert_to_nocase(PG_FUNCTION_ARGS); +extern Datum pg_convert_from(PG_FUNCTION_ARGS); +extern Datum length_in_encoding(PG_FUNCTION_ARGS); +extern Datum pg_encoding_max_length_sql(PG_FUNCTION_ARGS); + +/* format_type.c */ +extern Datum format_type(PG_FUNCTION_ARGS); +extern char* format_type_be(Oid type_oid); +extern char* format_type_with_typemod(Oid type_oid, int32 typemod); +extern Datum oidvectortypes(PG_FUNCTION_ARGS); +extern int32 type_maximum_size(Oid type_oid, int32 typemod); + +/* quote.c */ +extern Datum quote_ident(PG_FUNCTION_ARGS); +extern Datum quote_literal(PG_FUNCTION_ARGS); +extern char* quote_literal_cstr(const char* rawstr); +extern Datum quote_nullable(PG_FUNCTION_ARGS); + +/* guc.c */ +extern Datum show_config_by_name(PG_FUNCTION_ARGS); +extern Datum set_config_by_name(PG_FUNCTION_ARGS); +extern Datum show_all_settings(PG_FUNCTION_ARGS); + +/* lockfuncs.c */ +extern Datum pg_lock_status(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_shared_int8(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_try_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_shared_int4(PG_FUNCTION_ARGS); +extern Datum pg_advisory_unlock_all(PG_FUNCTION_ARGS); + +/* txid.c */ +extern Datum txid_snapshot_in(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_out(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_recv(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_send(PG_FUNCTION_ARGS); +extern Datum txid_current(PG_FUNCTION_ARGS); +extern Datum txid_current_snapshot(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xmin(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xmax(PG_FUNCTION_ARGS); +extern Datum txid_snapshot_xip(PG_FUNCTION_ARGS); +extern Datum txid_visible_in_snapshot(PG_FUNCTION_ARGS); +extern Datum pgxc_snapshot_status(PG_FUNCTION_ARGS); + +/* uuid.c */ +extern Datum uuid_in(PG_FUNCTION_ARGS); +extern Datum uuid_out(PG_FUNCTION_ARGS); +extern Datum uuid_send(PG_FUNCTION_ARGS); +extern Datum uuid_recv(PG_FUNCTION_ARGS); +extern Datum uuid_lt(PG_FUNCTION_ARGS); +extern Datum uuid_le(PG_FUNCTION_ARGS); +extern Datum uuid_eq(PG_FUNCTION_ARGS); +extern Datum uuid_ge(PG_FUNCTION_ARGS); +extern Datum uuid_gt(PG_FUNCTION_ARGS); +extern Datum uuid_ne(PG_FUNCTION_ARGS); +extern Datum uuid_cmp(PG_FUNCTION_ARGS); +extern Datum uuid_hash(PG_FUNCTION_ARGS); + +/* windowfuncs.c */ +extern Datum window_row_number(PG_FUNCTION_ARGS); +extern Datum window_rank(PG_FUNCTION_ARGS); +extern Datum window_dense_rank(PG_FUNCTION_ARGS); +extern Datum window_percent_rank(PG_FUNCTION_ARGS); +extern Datum window_cume_dist(PG_FUNCTION_ARGS); +extern Datum window_ntile(PG_FUNCTION_ARGS); +extern Datum window_lag(PG_FUNCTION_ARGS); +extern Datum window_lag_with_offset(PG_FUNCTION_ARGS); +extern Datum window_lag_with_offset_and_default(PG_FUNCTION_ARGS); +extern Datum window_lead(PG_FUNCTION_ARGS); +extern Datum window_lead_with_offset(PG_FUNCTION_ARGS); +extern Datum window_lead_with_offset_and_default(PG_FUNCTION_ARGS); +extern Datum window_first_value(PG_FUNCTION_ARGS); +extern Datum window_last_value(PG_FUNCTION_ARGS); +extern Datum window_nth_value(PG_FUNCTION_ARGS); +extern Datum window_delta(PG_FUNCTION_ARGS); + +/* access/spgist/spgquadtreeproc.c */ +extern Datum spg_quad_config(PG_FUNCTION_ARGS); +extern Datum spg_quad_choose(PG_FUNCTION_ARGS); +extern Datum spg_quad_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_quad_inner_consistent(PG_FUNCTION_ARGS); +extern Datum spg_quad_leaf_consistent(PG_FUNCTION_ARGS); + +/* access/spgist/spgkdtreeproc.c */ +extern Datum spg_kd_config(PG_FUNCTION_ARGS); +extern Datum spg_kd_choose(PG_FUNCTION_ARGS); +extern Datum spg_kd_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_kd_inner_consistent(PG_FUNCTION_ARGS); + +/* access/spgist/spgtextproc.c */ +extern Datum spg_text_config(PG_FUNCTION_ARGS); +extern Datum spg_text_choose(PG_FUNCTION_ARGS); +extern Datum spg_text_picksplit(PG_FUNCTION_ARGS); +extern Datum spg_text_inner_consistent(PG_FUNCTION_ARGS); +extern Datum spg_text_leaf_consistent(PG_FUNCTION_ARGS); + +/* access/gin/ginarrayproc.c */ +extern Datum ginarrayextract(PG_FUNCTION_ARGS); +extern Datum ginarrayextract_2args(PG_FUNCTION_ARGS); +extern Datum ginqueryarrayextract(PG_FUNCTION_ARGS); +extern Datum ginarrayconsistent(PG_FUNCTION_ARGS); +extern Datum ginarraytriconsistent(PG_FUNCTION_ARGS); + +/* storage/ipc/procarray.c */ +extern Datum pg_get_running_xacts(PG_FUNCTION_ARGS); +extern Datum pgxc_gtm_snapshot_status(PG_FUNCTION_ARGS); +extern Datum get_gtm_lite_status(PG_FUNCTION_ARGS); + +/* access/transam/twophase.c */ +extern Datum pg_prepared_xact(PG_FUNCTION_ARGS); +extern Datum pg_parse_clog(PG_FUNCTION_ARGS); + +/* postmaster.c */ +extern Datum pg_log_comm_status(PG_FUNCTION_ARGS); +extern Datum set_working_grand_version_num_manually(PG_FUNCTION_ARGS); + +/* access/transam/varsup.c */ +extern Datum pg_check_xidlimit(PG_FUNCTION_ARGS); +extern Datum pg_get_xidlimit(PG_FUNCTION_ARGS); +extern Datum pg_get_variable_info(PG_FUNCTION_ARGS); + +/* catalogs/dependency.c */ +extern Datum pg_describe_object(PG_FUNCTION_ARGS); + +/* commands/constraint.c */ +extern Datum unique_key_recheck(PG_FUNCTION_ARGS); + +/* commands/extension.c */ +extern Datum pg_available_extensions(PG_FUNCTION_ARGS); +extern Datum pg_available_extension_versions(PG_FUNCTION_ARGS); +extern Datum pg_extension_update_paths(PG_FUNCTION_ARGS); +extern Datum pg_extension_config_dump(PG_FUNCTION_ARGS); + +/* commands/prepare.c */ +extern Datum pg_prepared_statement(PG_FUNCTION_ARGS); + +/* utils/mmgr/portalmem.c */ +extern Datum pg_cursor(PG_FUNCTION_ARGS); + +/* utils/adt/pgstatfuncs.c */ +extern Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS); +extern Datum pg_stat_get_tuples_changed(PG_FUNCTION_ARGS); + +#ifdef PGXC +/* backend/pgxc/pool/poolutils.c */ +extern Datum pgxc_pool_check(PG_FUNCTION_ARGS); +extern Datum pgxc_pool_reload(PG_FUNCTION_ARGS); +extern Datum pgxc_pool_connection_status(PG_FUNCTION_ARGS); +extern Datum pg_pool_validate(PG_FUNCTION_ARGS); +extern Datum pg_pool_ping(PG_FUNCTION_ARGS); +extern Datum comm_check_connection_status(PG_FUNCTION_ARGS); +#endif + +/* backend/access/transam/transam.c */ +#ifdef PGXC +extern Datum pgxc_is_committed(PG_FUNCTION_ARGS); +extern Datum pgxc_get_csn(PG_FUNCTION_ARGS); +#endif + +/*adapt oracle's empty_blob*/ +extern Datum get_empty_blob(PG_FUNCTION_ARGS); +/*adapt oracle's substr*/ +extern Datum substrb_with_lenth(PG_FUNCTION_ARGS); +extern Datum substrb_without_lenth(PG_FUNCTION_ARGS); +/*aes encrypt/decrypt function*/ +extern Datum gs_encrypt_aes128(PG_FUNCTION_ARGS); +extern Datum gs_decrypt_aes128(PG_FUNCTION_ARGS); +extern ScalarVector* vtimestamp_part(PG_FUNCTION_ARGS); +extern ScalarVector* vint4mul(PG_FUNCTION_ARGS); +extern ScalarVector* vint4mi(PG_FUNCTION_ARGS); +extern ScalarVector* vint4pl(PG_FUNCTION_ARGS); +extern ScalarVector* vtextlike(PG_FUNCTION_ARGS); +extern ScalarVector* vtextnlike(PG_FUNCTION_ARGS); +extern ScalarVector* vtextne(PG_FUNCTION_ARGS); +extern ScalarVector* vlower(PG_FUNCTION_ARGS); +extern ScalarVector* vupper(PG_FUNCTION_ARGS); +extern ScalarVector* vlpad(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vsnumeric_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_abs(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_fac(PG_FUNCTION_ARGS); +extern ScalarVector* vnumeric_ne(PG_FUNCTION_ARGS); +extern ScalarVector* vinterval_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vcash_sum(PG_FUNCTION_ARGS); +extern ScalarVector* vintervalpl(PG_FUNCTION_ARGS); +extern ScalarVector* vbpcharlen(PG_FUNCTION_ARGS); + +extern Datum int1_text(PG_FUNCTION_ARGS); +extern Datum int2_text(PG_FUNCTION_ARGS); +extern Datum int4_text(PG_FUNCTION_ARGS); +extern Datum int8_text(PG_FUNCTION_ARGS); +extern Datum float4_text(PG_FUNCTION_ARGS); +extern Datum float8_text(PG_FUNCTION_ARGS); +extern Datum numeric_text(PG_FUNCTION_ARGS); +extern Datum bpchar_numeric(PG_FUNCTION_ARGS); +extern Datum varchar_numeric(PG_FUNCTION_ARGS); +extern Datum varchar_int4(PG_FUNCTION_ARGS); +extern Datum bpchar_int4(PG_FUNCTION_ARGS); +extern Datum varchar_int8(PG_FUNCTION_ARGS); +extern Datum timestampzone_text(PG_FUNCTION_ARGS); +extern Datum timestamp_text(PG_FUNCTION_ARGS); +extern Datum timestamp_varchar(PG_FUNCTION_ARGS); +extern Datum timestamp_diff(PG_FUNCTION_ARGS); +extern Datum int1_varchar(PG_FUNCTION_ARGS); +extern Datum int2_varchar(PG_FUNCTION_ARGS); +extern Datum int4_varchar(PG_FUNCTION_ARGS); +extern Datum int8_varchar(PG_FUNCTION_ARGS); +extern Datum int8_bpchar(PG_FUNCTION_ARGS); +extern Datum numeric_varchar(PG_FUNCTION_ARGS); +extern Datum numeric_bpchar(PG_FUNCTION_ARGS); +extern Datum float4_varchar(PG_FUNCTION_ARGS); +extern Datum float8_varchar(PG_FUNCTION_ARGS); +extern Datum int1_nvarchar2(PG_FUNCTION_ARGS); +extern Datum varchar_timestamp(PG_FUNCTION_ARGS); +extern Datum bpchar_timestamp(PG_FUNCTION_ARGS); +extern Datum text_int1(PG_FUNCTION_ARGS); +extern Datum text_int2(PG_FUNCTION_ARGS); +extern Datum text_int4(PG_FUNCTION_ARGS); +extern Datum text_int8(PG_FUNCTION_ARGS); +extern Datum text_float4(PG_FUNCTION_ARGS); +extern Datum text_float8(PG_FUNCTION_ARGS); +extern Datum text_numeric(PG_FUNCTION_ARGS); +extern Datum getDistributeKey(PG_FUNCTION_ARGS); +extern Datum text_timestamp(PG_FUNCTION_ARGS); +extern void encryptOBS(char* srcplaintext, char destciphertext[], uint32 destcipherlength); +extern void decryptOBS( + const char* srcciphertext, char destplaintext[], uint32 destplainlength, const char* obskey = NULL); +extern void encryptECString(char* src_plain_text, char* dest_cipher_text, uint32 dest_cipher_length); +extern void decryptECString(const char* src_cipher_text, char* dest_plain_text, uint32 dest_plain_length); +extern bool IsECEncryptedString(const char* src_cipher_text); + +/* fencedudf.cpp */ +extern Datum fenced_udf_process(PG_FUNCTION_ARGS); +extern Datum gs_extend_library(PG_FUNCTION_ARGS); + +/* cstore_am.cpp */ +extern Datum cupointer_bigint(PG_FUNCTION_ARGS); +extern void encryptBlockOrCUData( + const char* plainText, const size_t plainLength, char* cipherText, size_t* cipherLength); +extern void decryptBlockOrCUData( + const char* cipherText, const size_t cipherLength, char* plainText, size_t* plainLength); +extern bool isEncryptedCluster(); + +/* pg_lsn.cpp */ +extern Datum pg_lsn_in(PG_FUNCTION_ARGS); + +// template function implementation +// + +/* client logic */ +extern Datum globalsettingin(PG_FUNCTION_ARGS); +extern Datum columnsettingin(PG_FUNCTION_ARGS); + +/* tsdb */ +extern Datum add_job_class_depend_internal(PG_FUNCTION_ARGS); +extern Datum remove_job_class_depend_internal(PG_FUNCTION_ARGS); +extern Datum series_internal(PG_FUNCTION_ARGS); +extern Datum top_key_internal(PG_FUNCTION_ARGS); +extern Datum isubmit_job_on_nodes_internal(PG_FUNCTION_ARGS); +extern Datum job_cancel(PG_FUNCTION_ARGS); +extern void job_update(PG_FUNCTION_ARGS); +extern Datum submit_job_on_nodes(PG_FUNCTION_ARGS); + +/* AI */ +extern Datum gs_index_advise(PG_FUNCTION_ARGS); +extern Datum hypopg_create_index(PG_FUNCTION_ARGS); +extern Datum hypopg_display_index(PG_FUNCTION_ARGS); +extern Datum hypopg_drop_index(PG_FUNCTION_ARGS); +extern Datum hypopg_estimate_size(PG_FUNCTION_ARGS); +extern Datum hypopg_reset_index(PG_FUNCTION_ARGS); + +/* MOT */ +extern Datum mot_global_memory_detail(PG_FUNCTION_ARGS); +extern Datum mot_local_memory_detail(PG_FUNCTION_ARGS); +extern Datum mot_session_memory_detail(PG_FUNCTION_ARGS); + +#endif /* !FRONTEND_PARSER */ +#endif /* BUILTINS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/bytea.h postgresql-hll-2.14/include/utils/bytea.h --- postgresql-hll-2.14_old/include/utils/bytea.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/bytea.h 2020-12-12 17:06:43.394349935 +0800 @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- + * + * bytea.h + * Declarations for BYTEA data type support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/bytea.h + * + * ------------------------------------------------------------------------- + */ +#ifndef BYTEA_H +#define BYTEA_H + +#include "fmgr.h" + +typedef enum { BYTEA_OUTPUT_ESCAPE, BYTEA_OUTPUT_HEX } ByteaOutputType; + +/* functions are in utils/adt/varlena.c */ +extern Datum byteain(PG_FUNCTION_ARGS); +extern Datum byteaout(PG_FUNCTION_ARGS); +extern Datum bytearecv(PG_FUNCTION_ARGS); +extern Datum byteasend(PG_FUNCTION_ARGS); +extern Datum byteaoctetlen(PG_FUNCTION_ARGS); +extern Datum byteaGetByte(PG_FUNCTION_ARGS); +extern Datum byteaGetBit(PG_FUNCTION_ARGS); +extern Datum byteaSetByte(PG_FUNCTION_ARGS); +extern Datum byteaSetBit(PG_FUNCTION_ARGS); +extern Datum byteaeq(PG_FUNCTION_ARGS); +extern Datum byteane(PG_FUNCTION_ARGS); +extern Datum bytealt(PG_FUNCTION_ARGS); +extern Datum byteale(PG_FUNCTION_ARGS); +extern Datum byteagt(PG_FUNCTION_ARGS); +extern Datum byteage(PG_FUNCTION_ARGS); +extern Datum byteacmp(PG_FUNCTION_ARGS); +extern Datum bytea_sortsupport(PG_FUNCTION_ARGS); +extern Datum byteacat(PG_FUNCTION_ARGS); +extern Datum byteapos(PG_FUNCTION_ARGS); +extern Datum bytea_substr(PG_FUNCTION_ARGS); +extern Datum bytea_substr_no_len(PG_FUNCTION_ARGS); +extern Datum byteaoverlay(PG_FUNCTION_ARGS); +extern Datum byteaoverlay_no_len(PG_FUNCTION_ARGS); + +#endif /* BYTEA_H */ diff -uprN postgresql-hll-2.14_old/include/utils/cash.h postgresql-hll-2.14/include/utils/cash.h --- postgresql-hll-2.14_old/include/utils/cash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/cash.h 2020-12-12 17:06:43.394349935 +0800 @@ -0,0 +1,77 @@ +/* + * src/include/utils/cash.h + * + * + * cash.h + * Written by D'Arcy J.M. Cain + * + * Functions to allow input and output of money normally but store + * and handle it as 64 bit integer. + */ + +#ifndef CASH_H +#define CASH_H + +#include "fmgr.h" + +typedef int64 Cash; + +/* Cash is pass-by-reference if and only if int64 is */ +#define DatumGetCash(X) ((Cash)DatumGetInt64(X)) +#define CashGetDatum(X) Int64GetDatum(X) +#define PG_GETARG_CASH(n) DatumGetCash(PG_GETARG_DATUM(n)) +#define PG_RETURN_CASH(x) return CashGetDatum(x) + +extern Datum cash_in(PG_FUNCTION_ARGS); +extern Datum cash_out(PG_FUNCTION_ARGS); +extern Datum cash_recv(PG_FUNCTION_ARGS); +extern Datum cash_send(PG_FUNCTION_ARGS); + +extern Datum cash_eq(PG_FUNCTION_ARGS); +extern Datum cash_ne(PG_FUNCTION_ARGS); +extern Datum cash_lt(PG_FUNCTION_ARGS); +extern Datum cash_le(PG_FUNCTION_ARGS); +extern Datum cash_gt(PG_FUNCTION_ARGS); +extern Datum cash_ge(PG_FUNCTION_ARGS); +extern Datum cash_cmp(PG_FUNCTION_ARGS); + +extern Datum cash_pl(PG_FUNCTION_ARGS); +extern Datum cash_mi(PG_FUNCTION_ARGS); +extern Datum cash_div_cash(PG_FUNCTION_ARGS); + +extern Datum cash_mul_flt8(PG_FUNCTION_ARGS); +extern Datum flt8_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_flt8(PG_FUNCTION_ARGS); + +extern Datum cash_mul_flt4(PG_FUNCTION_ARGS); +extern Datum flt4_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_flt4(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int8(PG_FUNCTION_ARGS); +extern Datum int8_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int8(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int4(PG_FUNCTION_ARGS); +extern Datum int4_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int4(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int2(PG_FUNCTION_ARGS); +extern Datum int2_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int2(PG_FUNCTION_ARGS); + +extern Datum cash_mul_int1(PG_FUNCTION_ARGS); +extern Datum int1_mul_cash(PG_FUNCTION_ARGS); +extern Datum cash_div_int1(PG_FUNCTION_ARGS); + +extern Datum cashlarger(PG_FUNCTION_ARGS); +extern Datum cashsmaller(PG_FUNCTION_ARGS); + +extern Datum cash_words(PG_FUNCTION_ARGS); + +extern Datum cash_numeric(PG_FUNCTION_ARGS); +extern Datum numeric_cash(PG_FUNCTION_ARGS); + +extern Datum int4_cash(PG_FUNCTION_ARGS); +extern Datum int8_cash(PG_FUNCTION_ARGS); + +#endif /* CASH_H */ diff -uprN postgresql-hll-2.14_old/include/utils/catcache.h postgresql-hll-2.14/include/utils/catcache.h --- postgresql-hll-2.14_old/include/utils/catcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/catcache.h 2020-12-12 17:06:43.394349935 +0800 @@ -0,0 +1,206 @@ +/* ------------------------------------------------------------------------- + * + * catcache.h + * Low-level catalog cache definitions. + * + * NOTE: every catalog cache must have a corresponding unique index on + * the system table that it caches --- ie, the index must match the keys + * used to do lookups in this cache. All cache fetches are done with + * indexscans (under normal conditions). The index should be unique to + * guarantee that there can only be one matching row for a key combination. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/catcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef CATCACHE_H +#define CATCACHE_H + +#include "access/htup.h" +#include "access/skey.h" +#include "lib/dllist.h" +#include "utils/relcache.h" + +/* + * struct catctup: individual tuple in the cache. + * struct catclist: list of tuples matching a partial key. + * struct catcache: information for managing a cache. + * struct catcacheheader: information for managing all the caches. + */ + +#define CATCACHE_MAXKEYS 4 + +/* function computing a datum's hash */ +typedef uint32 (*CCHashFN)(Datum datum); + +/* function computing equality of two datums */ +typedef bool (*CCFastEqualFN)(Datum a, Datum b); + +typedef struct CatCache { + int id; /* cache identifier --- see syscache.h */ + int cc_nbuckets; /* # of hash buckets in this cache */ + CatCache* cc_next; /* link to next catcache */ + const char* cc_relname; /* name of relation the tuples come from */ + TupleDesc cc_tupdesc; /* tuple descriptor (copied from reldesc) */ + CCHashFN cc_hashfunc[CATCACHE_MAXKEYS]; /* hash function for each key */ + CCFastEqualFN cc_fastequal[CATCACHE_MAXKEYS]; /* fast equal function for each key */ + Oid cc_reloid; /* OID of relation the tuples come from */ + Oid cc_indexoid; /* OID of index matching cache keys */ + int cc_ntup; /* # of tuples currently in this cache */ + int cc_nkeys; /* # of keys (1..CATCACHE_MAXKEYS) */ + int cc_keyno[CATCACHE_MAXKEYS]; /* AttrNumber of each key */ + bool cc_relisshared; /* is relation shared across databases? */ + Dllist cc_lists; /* list of CatCList structs */ + ScanKeyData cc_skey[CATCACHE_MAXKEYS]; /* precomputed key info for + * heap scans */ +#ifdef CATCACHE_STATS + long cc_searches; /* total # searches against this cache */ + long cc_hits; /* # of matches against existing entry */ + long cc_neg_hits; /* # of matches against negative entry */ + long cc_newloads; /* # of successful loads of new entry */ + + /* + * cc_searches - (cc_hits + cc_neg_hits + cc_newloads) is number of failed + * searches, each of which will result in loading a negative entry + */ + long cc_invals; /* # of entries invalidated from cache */ + long cc_lsearches; /* total # list-searches */ + long cc_lhits; /* # of matches against existing lists */ +#endif + Dllist cc_bucket[FLEXIBLE_ARRAY_MEMBER]; /* hash buckets --- VARIABLE LENGTH ARRAY */ +} CatCache; /* VARIABLE LENGTH STRUCT */ + +typedef struct catctup { + int ct_magic; /* for identifying CatCTup entries */ +#define CT_MAGIC 0x57261502 + + uint32 hash_value; /* hash value for this tuple's keys */ + + /* + * Lookup keys for the entry. By-reference datums point into the tuple for + * positive cache entries, and are separately allocated for negative ones. + */ + Datum keys[CATCACHE_MAXKEYS]; + + /* + * Each tuple in a cache is a member of a Dllist that stores the elements + * of its hash bucket. We keep each Dllist in LRU order to speed repeated + * lookups. + */ + Dlelem cache_elem; /* list member of per-bucket list */ + + /* + * A tuple marked "dead" must not be returned by subsequent searches. + * However, it won't be physically deleted from the cache until its + * refcount goes to zero. (If it's a member of a CatCList, the list's + * refcount must go to zero, too; also, remember to mark the list dead at + * the same time the tuple is marked.) + * + * A negative cache entry is an assertion that there is no tuple matching + * a particular key. This is just as useful as a normal entry so far as + * avoiding catalog searches is concerned. Management of positive and + * negative entries is identical. + */ + int refcount; /* number of active references */ + bool dead; /* dead but not yet removed? */ + bool negative; /* negative cache entry? */ + bool isnailed; /* indicate if we can reomve this cattup from syscache or not */ + HeapTupleData tuple; /* tuple management header */ + + /* + * The tuple may also be a member of at most one CatCList. (If a single + * catcache is list-searched with varying numbers of keys, we may have to + * make multiple entries for the same tuple because of this restriction. + * Currently, that's not expected to be common, so we accept the potential + * inefficiency.) + */ + struct catclist* c_list; /* containing CatCList, or NULL if none */ + CatCache* my_cache; /* link to owning catcache */ +} CatCTup; + +/* + * A CatCList describes the result of a partial search, ie, a search using + * only the first K key columns of an N-key cache. We form the keys used + * into a tuple (with other attributes NULL) to represent the stored key + * set. The CatCList object contains links to cache entries for all the + * table rows satisfying the partial key. (Note: none of these will be + * negative cache entries.) + * + * A CatCList is only a member of a per-cache list; we do not currently + * divide them into hash buckets. + * + * A list marked "dead" must not be returned by subsequent searches. + * However, it won't be physically deleted from the cache until its + * refcount goes to zero. (A list should be marked dead if any of its + * member entries are dead.) + * + * If "ordered" is true then the member tuples appear in the order of the + * cache's underlying index. This will be true in normal operation, but + * might not be true during bootstrap or recovery operations. (namespace.c + * is able to save some cycles when it is true.) + */ +typedef struct catclist { + int cl_magic; /* for identifying CatCList entries */ +#define CL_MAGIC 0x52765103 + + uint32 hash_value; /* hash value for lookup keys */ + + Dlelem cache_elem; /* list member of per-catcache list */ + + /* + * Lookup keys for the entry, with the first nkeys elements being valid. + * All by-reference are separately allocated. + */ + Datum keys[CATCACHE_MAXKEYS]; + + int refcount; /* number of active references */ + bool dead; /* dead but not yet removed? */ + bool isnailed; /* indicate if we can reomve this catlist from syscache or not */ + bool ordered; /* members listed in index order? */ + short nkeys; /* number of lookup keys specified */ + int n_members; /* number of member tuples */ + CatCache* my_cache; /* link to owning catcache */ + CatCTup* members[FLEXIBLE_ARRAY_MEMBER]; /* members --- VARIABLE LENGTH ARRAY */ +} CatCList; /* VARIABLE LENGTH STRUCT */ + +typedef struct CatCacheHeader { + CatCache* ch_caches; /* head of list of CatCache structs */ + int ch_ntup; /* # of tuples in all caches */ +} CatCacheHeader; + +extern void AtEOXact_CatCache(bool isCommit); + +extern CatCache* InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int* key, int nbuckets); +extern void InitCatCachePhase2(CatCache* cache, bool touch_index); + +extern HeapTuple SearchCatCache(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4, int level); +extern HeapTuple SearchCatCache1(CatCache* cache, Datum v1); +extern HeapTuple SearchCatCache2(CatCache* cache, Datum v1, Datum v2); +extern HeapTuple SearchCatCache3(CatCache* cache, Datum v1, Datum v2, Datum v3); +extern HeapTuple SearchCatCache4(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4); + +extern void ReleaseCatCache(HeapTuple tuple); + +extern uint32 GetCatCacheHashValue(CatCache* cache, Datum v1, Datum v2, Datum v3, Datum v4); + +extern CatCList* SearchCatCacheList(CatCache* cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4); +extern void ReleaseCatCacheList(CatCList* list); + +extern void ReleaseTempCatList(const List* volatile ctlist, CatCache* cache); + +extern void ResetCatalogCaches(void); +extern void CatalogCacheFlushCatalog(Oid catId); +extern void CatalogCacheIdInvalidate(int cacheId, uint32 hashValue); +extern void PrepareToInvalidateCacheTuple( + Relation relation, HeapTuple tuple, HeapTuple newtuple, void (*function)(int, uint32, Oid)); + +extern void PrintCatCacheLeakWarning(HeapTuple tuple); +extern void PrintCatCacheListLeakWarning(CatCList* list); +extern bool RelationInvalidatesSnapshotsOnly(Oid); +extern bool RelationHasSysCache(Oid); +extern void InsertBuiltinFuncInBootstrap(); +#endif /* CATCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/clientlogic_bytea.h postgresql-hll-2.14/include/utils/clientlogic_bytea.h --- postgresql-hll-2.14_old/include/utils/clientlogic_bytea.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/clientlogic_bytea.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * clientlogic_bytea.h + * + * IDENTIFICATION + * src\include\utils\clientlogic_bytea.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +#include "fmgr.h" + +typedef enum { + ENCRYPTEDCOL_OUTPUT_ESCAPE, + ENCRYPTEDCOL_OUTPUT_HEX +} EncryptedColOutputType; + +extern THR_LOCAL int byteawithoutorderwithequalcol_output; /* ByteaOutputType, but int for GUC enum */ + +/* functions are in utils/adt/varlena.c */ +extern Datum byteawithoutorderwithequalcolin(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolout(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolrecv(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolsend(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloctetlen(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolGetByte(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolGetBit(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolSetByte(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolSetBit(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleq(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolne(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollt(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolle(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgt(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolge(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmp(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleqbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolltbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgtbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgebytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmpbytear(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoleqbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolnebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolltbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcollebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgtbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolgebyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolcmpbyteal(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_sortsupport(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcolpos(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_substr(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcol_substr_no_len(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloverlay(PG_FUNCTION_ARGS); +extern Datum byteawithoutorderwithequalcoloverlay_no_len(PG_FUNCTION_ARGS); diff -uprN postgresql-hll-2.14_old/include/utils/combocid.h postgresql-hll-2.14/include/utils/combocid.h --- postgresql-hll-2.14_old/include/utils/combocid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/combocid.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,28 @@ +/* ------------------------------------------------------------------------- + * + * combocid.h + * Combo command ID support routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/combocid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef COMBOCID_H +#define COMBOCID_H + +/* + * HeapTupleHeaderGetCmin and HeapTupleHeaderGetCmax function prototypes + * are in access/htup.h, because that's where the macro definitions that + * those functions replaced used to be. + */ + +extern void AtEOXact_ComboCid(void); + +extern void StreamTxnContextSaveComboCid(void* stc); +extern void StreamTxnContextRestoreComboCid(void* stc); + +#endif /* COMBOCID_H */ diff -uprN postgresql-hll-2.14_old/include/utils/date.h postgresql-hll-2.14/include/utils/date.h --- postgresql-hll-2.14_old/include/utils/date.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/date.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------- + * + * date.h + * Definitions for the SQL92 "date" and "time" types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/date.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATE_H +#define DATE_H + +#include + +#include "fmgr.h" +#include "timestamp.h" + +typedef int32 DateADT; + +#ifdef HAVE_INT64_TIMESTAMP +typedef int64 TimeADT; +#else +typedef float8 TimeADT; +#endif + +typedef struct { + TimeADT time; /* all time units other than months and years */ + int32 zone; /* numeric time zone, in seconds */ +} TimeTzADT; + +/* + * Infinity and minus infinity must be the max and min values of DateADT. + * We could use INT_MIN and INT_MAX here, but seems better to not assume that + * int32 == int. + */ +#define DATEVAL_NOBEGIN ((DateADT)(-0x7fffffff - 1)) +#define DATEVAL_NOEND ((DateADT)0x7fffffff) + +#define DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN) +#define DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN) +#define DATE_NOEND(j) ((j) = DATEVAL_NOEND) +#define DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND) +#define DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j)) + +/* + * Macros for fmgr-callable functions. + * + * For TimeADT, we make use of the same support routines as for float8 or int64. + * Therefore TimeADT is pass-by-reference if and only if float8 or int64 is! + */ +#ifdef HAVE_INT64_TIMESTAMP + +#define MAX_TIME_PRECISION 6 + +#define DatumGetDateADT(X) ((DateADT)DatumGetInt32(X)) +#define DatumGetTimeADT(X) ((TimeADT)DatumGetInt64(X)) +#define DatumGetTimeTzADTP(X) ((TimeTzADT*)DatumGetPointer(X)) + +#define DateADTGetDatum(X) Int32GetDatum(X) +#define TimeADTGetDatum(X) Int64GetDatum(X) +#define TimeTzADTPGetDatum(X) PointerGetDatum(X) +#else /* !HAVE_INT64_TIMESTAMP */ + +#define MAX_TIME_PRECISION 10 + +/* round off to MAX_TIME_PRECISION decimal places */ +#define TIME_PREC_INV 10000000000.0 +#define TIMEROUND(j) (rint(((double)(j)) * TIME_PREC_INV) / TIME_PREC_INV) + +#define DatumGetDateADT(X) ((DateADT)DatumGetInt32(X)) +#define DatumGetTimeADT(X) ((TimeADT)DatumGetFloat8(X)) +#define DatumGetTimeTzADTP(X) ((TimeTzADT*)DatumGetPointer(X)) + +#define DateADTGetDatum(X) Int32GetDatum(X) +#define TimeADTGetDatum(X) Float8GetDatum(X) +#define TimeTzADTPGetDatum(X) PointerGetDatum(X) +#endif /* HAVE_INT64_TIMESTAMP */ + +#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x) +#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x) +#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x) + +/* date.c */ +extern double date2timestamp_no_overflow(DateADT dateVal); + +extern Datum date_in(PG_FUNCTION_ARGS); +extern Datum date_out(PG_FUNCTION_ARGS); +extern Datum date_recv(PG_FUNCTION_ARGS); +extern Datum date_send(PG_FUNCTION_ARGS); +extern Datum date_eq(PG_FUNCTION_ARGS); +extern Datum date_ne(PG_FUNCTION_ARGS); +extern Datum date_lt(PG_FUNCTION_ARGS); +extern Datum date_le(PG_FUNCTION_ARGS); +extern Datum date_gt(PG_FUNCTION_ARGS); +extern Datum date_ge(PG_FUNCTION_ARGS); +extern Datum date_cmp(PG_FUNCTION_ARGS); +extern Datum date_sortsupport(PG_FUNCTION_ARGS); +extern Datum date_finite(PG_FUNCTION_ARGS); +extern Datum date_larger(PG_FUNCTION_ARGS); +extern Datum date_smaller(PG_FUNCTION_ARGS); +extern Datum date_mi(PG_FUNCTION_ARGS); +extern Datum date_pli(PG_FUNCTION_ARGS); +extern Datum date_mii(PG_FUNCTION_ARGS); +extern Datum date_eq_timestamp(PG_FUNCTION_ARGS); +extern Datum date_ne_timestamp(PG_FUNCTION_ARGS); +extern Datum date_lt_timestamp(PG_FUNCTION_ARGS); +extern Datum date_le_timestamp(PG_FUNCTION_ARGS); +extern Datum date_gt_timestamp(PG_FUNCTION_ARGS); +extern Datum date_ge_timestamp(PG_FUNCTION_ARGS); +extern Datum date_cmp_timestamp(PG_FUNCTION_ARGS); +extern Datum date_eq_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_ne_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_lt_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_le_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_gt_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_ge_timestamptz(PG_FUNCTION_ARGS); +extern Datum date_cmp_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_eq_date(PG_FUNCTION_ARGS); +extern Datum timestamp_ne_date(PG_FUNCTION_ARGS); +extern Datum timestamp_lt_date(PG_FUNCTION_ARGS); +extern Datum timestamp_le_date(PG_FUNCTION_ARGS); +extern Datum timestamp_gt_date(PG_FUNCTION_ARGS); +extern Datum timestamp_ge_date(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_eq_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_ne_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_lt_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_le_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_gt_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_ge_date(PG_FUNCTION_ARGS); +extern Datum timestamptz_cmp_date(PG_FUNCTION_ARGS); +extern Datum date_pl_interval(PG_FUNCTION_ARGS); +extern Datum date_mi_interval(PG_FUNCTION_ARGS); +extern Datum date_timestamp(PG_FUNCTION_ARGS); +extern Datum date_text(PG_FUNCTION_ARGS); +extern Datum date_varchar(PG_FUNCTION_ARGS); +extern Datum date_bpchar(PG_FUNCTION_ARGS); +extern Datum varchar_date(PG_FUNCTION_ARGS); +extern Datum bpchar_date(PG_FUNCTION_ARGS); +extern Datum text_date(PG_FUNCTION_ARGS); + +extern Datum timestamp2date(Timestamp timestamp); +extern Datum timestamp_date(PG_FUNCTION_ARGS); +extern Datum date_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamptz_date(PG_FUNCTION_ARGS); +extern Datum datetime_timestamp(PG_FUNCTION_ARGS); +extern Datum abstime_date(PG_FUNCTION_ARGS); +extern Timestamp date2timestamp(DateADT dateVal); + +extern Datum time_in(PG_FUNCTION_ARGS); +extern Datum time_out(PG_FUNCTION_ARGS); +extern Datum time_recv(PG_FUNCTION_ARGS); +extern Datum time_send(PG_FUNCTION_ARGS); +extern Datum timetypmodin(PG_FUNCTION_ARGS); +extern Datum timetypmodout(PG_FUNCTION_ARGS); +extern Datum time_transform(PG_FUNCTION_ARGS); +extern Datum time_scale(PG_FUNCTION_ARGS); +extern Datum time_eq(PG_FUNCTION_ARGS); +extern Datum time_ne(PG_FUNCTION_ARGS); +extern Datum time_lt(PG_FUNCTION_ARGS); +extern Datum time_le(PG_FUNCTION_ARGS); +extern Datum time_gt(PG_FUNCTION_ARGS); +extern Datum time_ge(PG_FUNCTION_ARGS); +extern Datum time_cmp(PG_FUNCTION_ARGS); +extern Datum time_hash(PG_FUNCTION_ARGS); +extern Datum overlaps_time(PG_FUNCTION_ARGS); +extern Datum time_larger(PG_FUNCTION_ARGS); +extern Datum time_smaller(PG_FUNCTION_ARGS); +extern Datum time_mi_time(PG_FUNCTION_ARGS); +extern Datum timestamp_time(PG_FUNCTION_ARGS); +extern Datum timestamptz_time(PG_FUNCTION_ARGS); +extern Datum time_interval(PG_FUNCTION_ARGS); +extern Datum interval_time(PG_FUNCTION_ARGS); +extern Datum time_pl_interval(PG_FUNCTION_ARGS); +extern Datum time_mi_interval(PG_FUNCTION_ARGS); +extern Datum time_part(PG_FUNCTION_ARGS); + +extern Datum timetz_in(PG_FUNCTION_ARGS); +extern Datum timetz_out(PG_FUNCTION_ARGS); +extern Datum timetz_recv(PG_FUNCTION_ARGS); +extern Datum timetz_send(PG_FUNCTION_ARGS); +extern Datum timetztypmodin(PG_FUNCTION_ARGS); +extern Datum timetztypmodout(PG_FUNCTION_ARGS); +extern Datum timetz_scale(PG_FUNCTION_ARGS); +extern Datum timetz_eq_withhead(PG_FUNCTION_ARGS); +extern Datum timetz_eq(PG_FUNCTION_ARGS); +extern Datum timetz_ne(PG_FUNCTION_ARGS); +extern Datum timetz_lt(PG_FUNCTION_ARGS); +extern Datum timetz_le(PG_FUNCTION_ARGS); +extern Datum timetz_gt(PG_FUNCTION_ARGS); +extern Datum timetz_ge(PG_FUNCTION_ARGS); +extern Datum timetz_cmp(PG_FUNCTION_ARGS); +extern Datum timetz_hash(PG_FUNCTION_ARGS); +extern Datum overlaps_timetz(PG_FUNCTION_ARGS); +extern Datum timetz_larger(PG_FUNCTION_ARGS); +extern Datum timetz_smaller(PG_FUNCTION_ARGS); +extern Datum timetz_time(PG_FUNCTION_ARGS); +extern Datum time_timetz(PG_FUNCTION_ARGS); +extern Datum timestamptz_timetz(PG_FUNCTION_ARGS); +extern Datum datetimetz_timestamptz(PG_FUNCTION_ARGS); +extern Datum timetz_part(PG_FUNCTION_ARGS); +extern Datum timetz_zone(PG_FUNCTION_ARGS); +extern Datum timetz_izone(PG_FUNCTION_ARGS); +extern Datum timetz_pl_interval(PG_FUNCTION_ARGS); +extern Datum timetz_mi_interval(PG_FUNCTION_ARGS); + +#endif /* DATE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/datetime.h postgresql-hll-2.14/include/utils/datetime.h --- postgresql-hll-2.14_old/include/utils/datetime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/datetime.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,309 @@ +/* ------------------------------------------------------------------------- + * + * datetime.h + * Definitions for date/time support code. + * The support code is shared with other date data types, + * including abstime, reltime, date, and time. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/datetime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATETIME_H +#define DATETIME_H + +#include "nodes/nodes.h" +#include "utils/timestamp.h" + +/* this struct is declared in utils/tzparser.h: */ +struct tzEntry; + +/* ---------------------------------------------------------------- + * time types + support macros + * + * String definitions for standard time quantities. + * + * These strings are the defaults used to form output time strings. + * Other alternative forms are hardcoded into token tables in datetime.c. + * ---------------------------------------------------------------- + */ + +#define DAGO "ago" +#define DCURRENT "current" +#define EPOCH "epoch" +#define INVALID "invalid" +#define EARLY "-infinity" +#define LATE "infinity" +#define NOW "now" +#define TODAY "today" +#define TOMORROW "tomorrow" +#define YESTERDAY "yesterday" +#define ZULU "zulu" + +#define DMICROSEC "usecond" +#define DMILLISEC "msecond" +#define DSECOND "second" +#define DMINUTE "minute" +#define DHOUR "hour" +#define DDAY "day" +#define DWEEK "week" +#define DMONTH "month" +#define DQUARTER "quarter" +#define DYEAR "year" +#define DDECADE "decade" +#define DCENTURY "century" +#define DMILLENNIUM "millennium" +#define DA_D "ad" +#define DB_C "bc" +#define DTIMEZONE "timezone" + +/* + * Fundamental time field definitions for parsing. + * + * Meridian: am, pm, or 24-hour style. + * Millennium: ad, bc + */ + +#define AM 0 +#define PM 1 +#define HR24 2 + +#define AD 0 +#define BC 1 + +/* + * Fields for time decoding. + * + * Can't have more of these than there are bits in an unsigned int + * since these are turned into bit masks during parsing and decoding. + * + * Furthermore, the values for YEAR, MONTH, DAY, HOUR, MINUTE, SECOND + * must be in the range 0..14 so that the associated bitmasks can fit + * into the left half of an INTERVAL's typmod value. Since those bits + * are stored in typmods, you can't change them without initdb! + */ + +#define RESERV 0 +#define MONTH 1 +#define YEAR 2 +#define DAY 3 +#define JULIAN 4 +#define TZ 5 +#define DTZ 6 +#define DTZMOD 7 +#define IGNORE_DTF 8 +#define AMPM 9 +#define HOUR 10 +#define MINUTE 11 +#define SECOND 12 +#define MILLISECOND 13 +#define MICROSECOND 14 +#define DOY 15 +#define DOW 16 +#define UNITS 17 +#define ADBC 18 +/* these are only for relative dates */ +#define AGO 19 +#define ABS_BEFORE 20 +#define ABS_AFTER 21 +/* generic fields to help with parsing */ +#define ISODATE 22 +#define ISOTIME 23 +/* these are only for parsing intervals */ +#define WEEK 24 +#define DECADE 25 +#define CENTURY 26 +#define MILLENNIUM 27 +/* reserved for unrecognized string values */ +#define UNKNOWN_FIELD 31 + +/* + * Token field definitions for time parsing and decoding. + * These need to fit into the datetkn table type. + * At the moment, that means keep them within [-127,127]. + * These are also used for bit masks in DecodeDateDelta() + * so actually restrict them to within [0,31] for now. + * - thomas 97/06/19 + * Not all of these fields are used for masks in DecodeDateDelta + * so allow some larger than 31. - thomas 1997-11-17 + */ + +#define DTK_NUMBER 0 +#define DTK_STRING 1 + +#define DTK_DATE 2 +#define DTK_TIME 3 +#define DTK_TZ 4 +#define DTK_AGO 5 + +#define DTK_SPECIAL 6 +#define DTK_INVALID 7 +#define DTK_CURRENT 8 +#define DTK_EARLY 9 +#define DTK_LATE 10 +#define DTK_EPOCH 11 +#define DTK_NOW 12 +#define DTK_YESTERDAY 13 +#define DTK_TODAY 14 +#define DTK_TOMORROW 15 +#define DTK_ZULU 16 + +#define DTK_DELTA 17 +#define DTK_SECOND 18 +#define DTK_MINUTE 19 +#define DTK_HOUR 20 +#define DTK_DAY 21 +#define DTK_WEEK 22 +#define DTK_MONTH 23 +#define DTK_QUARTER 24 +#define DTK_YEAR 25 +#define DTK_DECADE 26 +#define DTK_CENTURY 27 +#define DTK_MILLENNIUM 28 +#define DTK_MILLISEC 29 +#define DTK_MICROSEC 30 +#define DTK_JULIAN 31 + +#define DTK_DOW 32 +#define DTK_DOY 33 +#define DTK_TZ_HOUR 34 +#define DTK_TZ_MINUTE 35 +#define DTK_ISOYEAR 36 +#define DTK_ISODOW 37 + +/* + * Bit mask definitions for time parsing. + */ + +#define DTK_M(t) (0x01 << (t)) + +/* Convenience: a second, plus any fractional component */ +#define DTK_ALL_SECS_M (DTK_M(SECOND) | DTK_M(MILLISECOND) | DTK_M(MICROSECOND)) +#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY)) +#define DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_ALL_SECS_M) + +/* + * Working buffer size for input and output of interval, timestamp, etc. + * Inputs that need more working space will be rejected early. Longer outputs + * will overrun buffers, so this must suffice for all possible output. As of + * this writing, interval_out() needs the most space at ~90 bytes. + */ +#define MAXDATELEN 128 +/* only this many chars are stored in datetktbl */ +#define TOKMAXLEN 10 + +/* keep this struct small; it gets used a lot */ +typedef struct datetkn { + char token[TOKMAXLEN + 1]; + char type; + char value; /* this may be unsigned, alas */ +} datetkn; + +/* one of its uses is in tables of time zone abbreviations */ +typedef struct TimeZoneAbbrevTable { + int numabbrevs; + datetkn abbrevs[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} TimeZoneAbbrevTable; + +/* FMODULO() + * Macro to replace modf(), which is broken on some platforms. + * t = input and remainder + * q = integer part + * u = divisor + */ +#define FMODULO(t, q, u) \ + do { \ + (q) = (((t) < 0) ? ceil((t) / (u)) : floor((t) / (u))); \ + if ((q) != 0) \ + (t) -= rint((q) * (u)); \ + } while (0) + +/* TMODULO() + * Like FMODULO(), but work on the timestamp datatype (either int64 or float8). + * We assume that int64 follows the C99 semantics for division (negative + * quotients truncate towards zero). + */ +#ifdef HAVE_INT64_TIMESTAMP +#define TMODULO(t, q, u) \ + do { \ + (q) = ((t) / (u)); \ + if ((q) != 0) \ + (t) -= ((q) * (u)); \ + } while (0) +#else +#define TMODULO(t, q, u) \ + do { \ + (q) = (((t) < 0) ? ceil((t) / (u)) : floor((t) / (u))); \ + if ((q) != 0) \ + (t) -= rint((q) * (u)); \ + } while (0) +#endif + +/* + * Date/time validation + * Include check for leap year. + */ + +extern const int day_tab[2][13]; + +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) + +/* + * Datetime input parsing routines (ParseDateTime, DecodeDateTime, etc) + * return zero or a positive value on success. On failure, they return + * one of these negative code values. DateTimeParseError may be used to + * produce a correct ereport. + */ +#define DTERR_BAD_FORMAT (-1) +#define DTERR_FIELD_OVERFLOW (-2) +#define DTERR_MD_FIELD_OVERFLOW (-3) /* triggers hint about u_sess->time_cxt.DateStyle */ +#define DTERR_INTERVAL_OVERFLOW (-4) +#define DTERR_TZDISP_OVERFLOW (-5) + +#ifndef FRONTEND_PARSER +extern void GetCurrentDateTime(struct pg_tm* tm); +extern void GetCurrentTimeUsec(struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern void j2date(int jd, int* year, int* month, int* day); +extern int date2j(int year, int month, int day); + +extern int ParseDateTime( + const char* timestr, char* workbuf, size_t buflen, char** field, int* ftype, int maxfields, int* numfields); +extern int DecodeDateTime(char** field, int* ftype, int nf, int* dtype, struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern int DecodeTimeOnly(char** field, int* ftype, int nf, int* dtype, struct pg_tm* tm, fsec_t* fsec, int* tzp); +extern int DecodeInterval( + char** field, const int* ftype, int nf, int range, int* dtype, struct pg_tm* tm, fsec_t* fsec); +extern int DecodeISO8601Interval(char* str, int* dtype, struct pg_tm* tm, fsec_t* fsec); + +extern void DateTimeParseError(int dterr, const char* str, const char* datatype); + +extern int DetermineTimeZoneOffset(struct pg_tm* tm, pg_tz* tzp); + +extern void EncodeDateOnly(struct pg_tm* tm, int style, char* str); +extern void EncodeTimeOnly(struct pg_tm* tm, fsec_t fsec, bool print_tz, int tz, int style, char* str); +extern void EncodeDateTime(struct pg_tm* tm, fsec_t fsec, bool print_tz, int tz, const char* tzn, int style, char* str); +extern void EncodeInterval(struct pg_tm* tm, fsec_t fsec, int style, char* str); + +extern int DecodeSpecial(int field, const char* lowtoken, int* val); +extern int DecodeUnits(int field, const char* lowtoken, int* val); + +extern int j2day(int jd); + +extern Node* TemporalTransform(int32 max_precis, Node* node); + +extern bool CheckDateTokenTables(void); + +extern void ConvertTimeZoneAbbrevs(TimeZoneAbbrevTable* tbl, struct tzEntry* abbrevs, int n); +extern void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable* tbl); + +extern Datum pg_timezone_abbrevs(PG_FUNCTION_ARGS); +extern Datum pg_timezone_names(PG_FUNCTION_ARGS); + +extern Interval *char_to_interval(char *str, int32 typmod); +#endif // !FRONTEND_PARSER + +#endif /* DATETIME_H */ + diff -uprN postgresql-hll-2.14_old/include/utils/datum.h postgresql-hll-2.14/include/utils/datum.h --- postgresql-hll-2.14_old/include/utils/datum.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/datum.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,48 @@ +/* ------------------------------------------------------------------------- + * + * datum.h + * POSTGRES Datum (abstract data type) manipulation routines. + * + * These routines are driven by the 'typbyval' and 'typlen' information, + * which must previously have been obtained by the caller for the datatype + * of the Datum. (We do it this way because in most situations the caller + * can look up the info just once and use it for many per-datum operations.) + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/datum.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DATUM_H +#define DATUM_H + +/* + * datumGetSize - find the "real" length of a datum + */ +extern Size datumGetSize(Datum value, bool typByVal, int typLen); + +/* + * datumCopy - make a copy of a datum. + * + * If the datatype is pass-by-reference, memory is obtained with palloc(). + */ +extern Datum datumCopy(Datum value, bool typByVal, int typLen); + +/* + * datumFree - free a datum previously allocated by datumCopy, if any. + * + * Does nothing if datatype is pass-by-value. + */ +extern void datumFree(Datum value, bool typByVal, int typLen); + +/* + * datumIsEqual + * return true if two datums of the same type are equal, false otherwise. + * + * XXX : See comments in the code for restrictions! + */ +extern bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen); + +#endif /* DATUM_H */ diff -uprN postgresql-hll-2.14_old/include/utils/dfs_vector.h postgresql-hll-2.14/include/utils/dfs_vector.h --- postgresql-hll-2.14_old/include/utils/dfs_vector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/dfs_vector.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,306 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dfs_vector.h + * + * + * + * IDENTIFICATION + * src/include/utils/dfs_vector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECTOR_H_ +#define VECTOR_H_ + +#include "postgres.h" +#include "securec.h" +#include "securec_check.h" + +/* stands for non-int type */ +struct __type_true {}; + +/* stands for int type */ +struct __type_false {}; + +template +struct _type_traits { + typedef __type_false is_POD_type; +}; + +template <> +struct _type_traits { + typedef __type_true is_POD_type; +}; + +/* + * Afford the dynamic array function. + */ +template +class Vector { +public: + typedef T value_type; + typedef value_type* iterator; + typedef typename _type_traits::is_POD_type is_POD; + + /* Return the start iterator. */ + iterator begin() + { + if (currentSize == 0) { + return 0; + } + + return iterator(vectorHead); + } + + /* Return the last iterator. */ + iterator end() + { + return iterator(vectorHead + currentSize); + } + + /* constructor */ + Vector(int n = 0) : currentSize(n), currentCapacity(n > VECTOR_INIT_SIZE ? n : VECTOR_INIT_SIZE) + { + vectorHead = allocateMemory(is_POD()); + } + + /* constructor */ + Vector(int n, T val) : currentSize(n), currentCapacity(n > VECTOR_INIT_SIZE ? n : VECTOR_INIT_SIZE) + { + vectorHead = allocateMemory(is_POD()); + for (int i = 0; i < n; i++) + vectorHead[i] = val; + } + + /* constructor */ + Vector(const Vector& b) : currentSize(b.currentSize), currentCapacity(b.currentCapacity) + { + errno_t rc = EOK; + + vectorHead = allocateMemory(is_POD()); + if (NULL == vectorHead) { + elog(ERROR, "memory alloc failed!\n"); + } + + rc = memcpy_s(vectorHead, currentCapacity * sizeof(T), b.vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + } + + ~Vector() + { + freeVectorHead(is_POD()); + } + + /* Add a element into the vector. */ + void push_back(T val) + { + /* Current capacity is enough. */ + if (currentSize < currentCapacity) { + vectorHead[currentSize++] = val; + } + /* Enlarge the capacity of vector. */ + else { + currentCapacity = currentCapacity + CAPICITY_INCREASE_STEP; + T* newAllocated = allocateMemory(is_POD()); + errno_t rc = EOK; + rc = memcpy_s(newAllocated, currentCapacity * sizeof(T), vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + newAllocated[currentSize++] = val; + freeVectorHead(is_POD()); + vectorHead = newAllocated; + } + } + + /* Pop off a element from the tail. */ + void pop_back() + { + if (currentSize) + currentSize--; + } + + /* Return the first one. */ + const T& front() const + { + return vectorHead[0]; + } + + /* Return the last one. */ + const T& back() const + { + return vectorHead[currentSize - 1]; + } + + /* Implement the array visit operator. */ + const T& operator[](int i) const + { + return vectorHead[i]; + } + + /* Implement the array visit operator. */ + T& operator[](int i) + { + return vectorHead[i]; + } + + /* Return the size of the current vector. */ + int size() + { + return currentSize; + } + + /* Return the size of the current vector. */ + int size() const + { + return currentSize; + } + + /* Resize the current vector and fill it with the special value. */ + void resize(uint32 new_size, T x) + { + /* Current capacity is enough. */ + if (new_size < currentCapacity) { + if (currentSize < new_size) { + for (uint32 i = currentSize; i < new_size; i++) { + vectorHead[i] = x; + } + } + currentSize = new_size; + } + /* Need to enlarge the capacity. */ + else { + currentCapacity = new_size; + T* newAllocated = allocateMemory(is_POD()); + + if (NULL == newAllocated) { + elog(ERROR, "memory alloc failed!\n"); + } + + errno_t rc = EOK; + + rc = memcpy_s(newAllocated, currentCapacity * sizeof(T), vectorHead, currentSize * sizeof(T)); + securec_check(rc, "\0", "\0"); + + for (uint32 i = currentSize; i < currentCapacity; i++) { + newAllocated[i] = x; + } + freeVectorHead(is_POD()); + vectorHead = newAllocated; + currentSize = new_size; + } + } + + /* Resize the current vector and fill it with NULL. */ + void resize(int new_size) + { + resize(new_size, (T)0); + } + + /* Return the capacity of the current vector. */ + int capacity() + { + return currentCapacity; + } + + /* Implement the equal check operator. */ + bool operator==(const Vector& b) const + { + for (int i = 0; i < std::min(currentSize, b.currentSize); i++) { + if (!(vectorHead[i] == b.vectorHead[i])) + return false; + } + + return currentSize == b.currentSize; + } + + /* Implement the non-equal check operator. */ + bool operator!=(const Vector& b) const + { + return !(*this == b); + } + + /* Clear the dynamic arrays. */ + void clear() + { + errno_t errNo = EOK; + errNo = ::memset_s(vectorHead, sizeof(T) * currentCapacity, 0, sizeof(T) * currentCapacity); + if (EOK != errNo) { + elog(ERROR, "Initialize memory failed."); + } + currentSize = 0; + } + + /* Erase the element on the special position. */ + iterator erase(iterator postion) + { + if (postion < iterator(vectorHead)) { + return vectorHead; + } + + if (postion >= iterator(vectorHead + currentSize)) { + return vectorHead + currentSize; + } + + T* succeedor = postion + 1; + errno_t errNo = EOK; + errNo = ::memmove_s(postion, end() - succeedor, succeedor, end() - succeedor); + if (EOK != errNo) { + elog(ERROR, "Initialize memory failed."); + } + currentSize--; + + return succeedor; + } + +private: + T* allocateMemory(__type_false) + { + if (currentCapacity == 0) { + return 0; + } + T* newAllocated = new T[currentCapacity]; + return newAllocated; + } + + T* allocateMemory(__type_true) + { + if (currentCapacity == 0) { + return 0; + } + T* newAllocated = (T*)palloc(currentCapacity * sizeof(T)); + return newAllocated; + } + + void freeVectorHead(__type_false) + { + delete[] vectorHead; + vectorHead = NULL; + } + void freeVectorHead(__type_true) + { + pfree(vectorHead); + } + +private: + enum { VECTOR_INIT_SIZE = 25 }; + enum { CAPICITY_INCREASE_STEP = 15 }; + + uint32 currentSize; // size + uint32 currentCapacity; // capacity + T* vectorHead; // value array +}; + +#endif /* VECTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/distribute_test.h postgresql-hll-2.14/include/utils/distribute_test.h --- postgresql-hll-2.14_old/include/utils/distribute_test.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/distribute_test.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,174 @@ +/* --------------------------------------------------------------------------------------- + * + * distribute_test.h + * Routines for distributed test framework. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * src/include/utils/distribute_test.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef DISTRIBUTE_TEST_H +#define DISTRIBUTE_TEST_H + +#include "utils/guc.h" +#include "utils/elog.h" + +// work as a switch to enable the macro TEST_STUB +#ifdef USE_ASSERT_CHECKING +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_DISTRIBUTE_TEST +#endif + +#define MAX_GID_STR_LEN (1024) +#define MAX_NAME_STR_LEN (256) +#define DEFAULT_PROBABILITY (0.004) + +/* white-box log handle */ +#define ereport_whitebox_domain(elevel, file, line, func, domain, rest) \ + (errstart(elevel, file, line, func, domain) ? (errfinish rest) : (void)0) + +#define ereport_whitebox(elevel, file, line, func, rest) \ + ereport_whitebox_domain(elevel, file, line, func, TEXTDOMAIN, rest) + +#define WHITEBOX_LOC __FILE__, __LINE__, PG_FUNCNAME_MACRO + +typedef struct DistributeTestParam { + /* use as the guc-control white-box-fault probability + * range [0, 100000], probability 0, 1/100000 -> 1 + */ + int guc_probability; + + /* act as the white-box checkpoint tag, + * eg. "WHITE_BOX_ALL_RANDOM_FAILED" + */ + char test_stub_name[MAX_NAME_STR_LEN]; + + /* fault level, support ERROR and PANIC */ + int elevel; + + /* when white-box fault is WHITEBOX_WAIT, guc can provide "sleep_time" + * for sleep time control, if guc not contain this field, use the default value 30s + */ + int sleep_time; +} DistributeTestParam; + +/* white-box failure injection type definition */ +typedef enum WhiteboxFaillueType { + WHITEBOX_DEFAULT = 0, + WHITEBOX_WAIT, + WHITEBOX_REPEAT, + WHITEBOX_USERDEFINE, + WHITEBOX_BUTT +} WhiteboxFaillueType; + +/* struct created for white-box tesing, support expansion */ +typedef struct WhiteBoxInjectStruct { + /* test location record */ + char filename[MAX_NAME_STR_LEN]; + int lineno; + char funcname[MAX_NAME_STR_LEN]; + + /* failure type, defined above */ + int failureType; + + /* trigger as the probability, 0 -1, if set as 1, definitely trigger */ + double triggerProbability; + + /* white box test info needed */ + TransactionId currentXid; + char currentGid[MAX_GID_STR_LEN]; +} WhiteBoxInjectStruct; + +typedef void (*on_whitebox_callback)(WhiteBoxInjectStruct* wbinfo); +typedef void (*on_add_stub_callback)(void); + +extern bool check_distribute_test_param(char** newval, void** extra, GucSource source); +extern void assign_distribute_test_param(const char* newval, void* extra); +extern bool distribute_test_stub_activator(const char* name, on_add_stub_callback function); +extern void default_error_emit(void); +extern void twophase_default_error_emit(void); +extern bool distribute_whitebox_activator( + const char* name, WhiteBoxInjectStruct* wbinfo, on_whitebox_callback WbCallbackFunc); +extern void default_whitebox_emit(WhiteBoxInjectStruct* wbinfo); +extern bool execute_whitebox( + const char* filename, int lineno, const char* funcname, const char* gid, int failureType, double probability); +extern DistributeTestParam* get_distribute_test_param(); +extern void stub_sleep_emit(void); + +#define TEST_WHITEBOX(_stub_name, _white_box_info, _call_back_func) \ + distribute_whitebox_activator((_stub_name), (_white_box_info), (_call_back_func)) +#define TEST_STUB(_stub_name, _call_back_func) distribute_test_stub_activator((_stub_name), (_call_back_func)) + +/* White-Box Handle Definition */ +#define WHITE_BOX_ALL_RANDOM_FAILED "WHITE_BOX_ALL_RANDOM_FAILED" + +/* GTM exception scenes */ +#define CN_LOCAL_PREPARED_FAILED_A "CN_LOCAL_PREPARED_FAILED_A" +#define CN_LOCAL_PREPARED_FAILED_B "CN_LOCAL_PREPARED_FAILED_B" +#define CN_LOCAL_PREPARED_XLOG_FAILED "CN_LOCAL_PREPARED_XLOG_FAILED" +#define CN_LOCAL_PREPARED_CLOG_FAILED "CN_LOCAL_PREPARED_CLOG_FAILED" +#define CN_PREPARED_SEND_ALL_FAILED "CN_PREPARED_SEND_ALL_FAILED" +#define CN_PREPARED_SEND_PART_FAILED "CN_PREPARED_SEND_PART_FAILED" +#define CN_PREPARED_RESPONSE_FAILED "CN_PREPARED_RESPONSE_FAILED" +#define DN_PREPARED_FAILED "DN_PREPARED_FAILED" +#define CN_PREPARED_MESSAGE_REPEAT "CN_PREPARED_MESSAGE_REPEAT" +#define CN_COMMIT_PREPARED_FAILED "CN_COMMIT_PREPARED_FAILED" +#define DN_COMMIT_PREPARED_FAILED "DN_COMMIT_PREPARED_FAILED" +#define CN_COMMIT_PREPARED_SEND_ALL_FAILED "CN_COMMIT_PREPARED_SEND_ALL_FAILED" +#define CN_COMMIT_PREPARED_SEND_PART_FAILED "CN_COMMIT_PREPARED_SEND_PART_FAILED" +#define CN_COMMIT_PREPARED_RESPONSE_FAILED "CN_COMMIT_PREPARED_RESPONSE_FAILED" +#define CN_COMMIT_PREPARED_MESSAGE_REPEAT "CN_COMMIT_PREPARED_MESSAGE_REPEAT" +#define CN_ABORT_AFTER_ALL_COMMITTED "CN_ABORT_AFTER_ALL_COMMITTED" + +#define CN_ABORT_PREPARED_FAILED "CN_ABORT_PREPARED_FAILED" +#define CN_ABORT_PREPARED_SEND_ALL_FAILED "CN_ABORT_PREPARED_SEND_ALL_FAILED" +#define CN_ABORT_PREPARED_SEND_PART_FAILED "CN_ABORT_PREPARED_SEND_PART_FAILED" +#define CN_ABORT_PREPARED_RESPONSE_FAILED "CN_ABORT_PREPARED_RESPONSE_FAILED" +#define DN_ABORT_PREPARED_FAILED "DN_ABORT_PREPARED_FAILED" + +#define CN_COMMIT_PREPARED_SLEEP "CN_COMMIT_PREPARED_SLEEP" +#define CN_PREPARED_SLEEP "CN_PREPARED_SLEEP" +#define DN_COMMIT_PREPARED_SLEEP "DN_COMMIT_PREPARED_SLEEP" + +/* Exception during subTransaction process */ +#define NON_EXEC_CN_IS_DOWN "NON_EXEC_CN_IS_DOWN" +#define CN_SAVEPOINT_SEND_ALL_FAILED "CN_SAVEPOINT_SEND_ALL_FAILED" +#define CN_SAVEPOINT_SEND_PART_FAILED "CN_SAVEPOINT_SEND_PART_FAILED" +#define CN_SAVEPOINT_RESPONSE_ALL_FAILED "CN_SAVEPOINT_RESPONSE_ALL_FAILED" +#define CN_SAVEPOINT_RESPONSE_PART_FAILED "CN_SAVEPOINT_RESPONSE_PART_FAILED" +#define CN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED "CN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED" +#define DN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED "DN_SAVEPOINT_BEFORE_DEFINE_LOCAL_FAILED" +#define CN_SAVEPOINT_BEFORE_PUSHXACT_FAILED "CN_SAVEPOINT_BEFORE_PUSHXACT_FAILED" +#define DN_SAVEPOINT_BEFORE_PUSHXACT_FAILED "DN_SAVEPOINT_BEFORE_PUSHXACT_FAILED" +#define CN_SAVEPOINT_AFTER_PUSHXACT_FAILED "CN_SAVEPOINT_AFTER_PUSHXACT_FAILED" +#define DN_SAVEPOINT_AFTER_PUSHXACT_FAILED "DN_SAVEPOINT_AFTER_PUSHXACT_FAILED" + +#define CN_ROLLBACKTOSAVEPOINT_BEFORE_SEND_FAILED "CN_ROLLBACKTOSAVEPOINT_BEFORE_SEND_FAILED" +#define DN_ROLLBACKTOSAVEPOINT_AFTER_LOCAL_DEAL_FAILED "DN_ROLLBACKTOSAVEPOINT_AFTER_LOCAL_DEAL_FAILED" + +#define CN_RELEASESAVEPOINT_BEFORE_SEND_FAILED "CN_RELEASESAVEPOINT_BEFORE_SEND_FAILED" +#define DN_RELEASESAVEPOINT_AFTER_LOCAL_DEAL_FAILED "DN_RELEASESAVEPOINT_AFTER_LOCAL_DEAL_FAILED" +#define CN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED "CN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED" +#define DN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED "DN_RELEASESAVEPOINT_BEFORE_LOCAL_DEAL_FAILED" + +#define CN_COMMIT_SUBXACT_BEFORE_SEND_GTM_FAILED "CN_COMMIT_SUBXACT_BEFORE_SEND_GTM_FAILED" +#define CN_COMMIT_SUBXACT_AFTER_SEND_GTM_FAILED "CN_COMMIT_SUBXACT_AFTER_SEND_GTM_FAILED" + +#define CN_CANCEL_SUBQUERY_FLUSH_FAILED "CN_CANCEL_SUBQUERY_FLUSH_FAILED" +#define CN_COMMIT_BEFORE_GTM_FAILED_AND_CANCEL_FLUSH_FAILED "CN_COMMIT_BEFORE_GTM_FAILED_AND_CANCEL_FLUSH_FAILED" + +#define DN_STANDBY_SLEEPIN_SYNCCOMMIT "DN_STANDBY_SLEEPIN_SYNCCOMMIT" +#define DN_XLOGFLUSH "DN_XLOGFLUSH" +#define DN_WALSEND_MAINLOOP "DN_WALSEND_MAINLOOP" +#define DN_WALRECEIVE_MAINLOOP "DN_WALRECEIVE_MAINLOOP" +#define DN_CM_NEW_CONN "DN_CM_NEW_CONN" +#define DN_PRIMARY_CHECKPOINT_KEEPXLOG "DN_PRIMARY_CHECKPOINT_KEEPXLOG" +#define DN_SLAVE_CHECKPOINT_KEEPXLOG "DN_SLAVE_CHECKPOINT_KEEPXLOG" + +#endif /* DEBUG */ +#endif /* DISTRIBUTE_TEST_H */ diff -uprN postgresql-hll-2.14_old/include/utils/dynahash.h postgresql-hll-2.14/include/utils/dynahash.h --- postgresql-hll-2.14_old/include/utils/dynahash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/dynahash.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,124 @@ +/* ------------------------------------------------------------------------- + * + * dynahash + * POSTGRES dynahash.h file definitions + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/dynahash.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DYNAHASH_H +#define DYNAHASH_H + +#include "storage/buf_internals.h" +#include "storage/s_lock.h" +#include "utils/hsearch.h" + +/* Number of freelists to be used for a partitioned hash table. */ +#define NUM_FREELISTS 32 + +/* A hash bucket is a linked list of HASHELEMENTs */ +typedef HASHELEMENT* HASHBUCKET; + +/* A hash segment is an array of bucket headers */ +typedef HASHBUCKET* HASHSEGMENT; + +/* + * Using array of FreeListData instead of separate arrays of mutexes, nentries + * and freeLists prevents, at least partially, sharing one cache line between + * different mutexes (see below). + */ +typedef struct { + slock_t mutex; /* spinlock */ + long nentries; /* number of entries */ + HASHELEMENT* freeList; /* list of free elements */ +} FreeListData; + +/* + * Header structure for a hash table --- contains all changeable info + * + * In a shared-memory hash table, the HASHHDR is in shared memory, while + * each backend has a local HTAB struct. For a non-shared table, there isn't + * any functional difference between HASHHDR and HTAB, but we separate them + * anyway to share code between shared and non-shared tables. + */ +struct HASHHDR { + /* + * The freelist can become a point of contention on high-concurrency hash + * tables, so we use an array of freelist, each with its own mutex and + * nentries count, instead of just a single one. + * + * If hash table is not partitioned only freeList[0] is used and spinlocks + * are not used at all. + */ + FreeListData freeList[NUM_FREELISTS]; + + /* These fields can change, but not in a partitioned table */ + /* Also, dsize can't change in a shared table, even if unpartitioned */ + long dsize; /* directory size */ + long nsegs; /* number of allocated segments (<= dsize) */ + uint32 max_bucket; /* ID of maximum bucket in use */ + uint32 high_mask; /* mask to modulo into entire table */ + uint32 low_mask; /* mask to modulo into lower half of table */ + + /* These fields are fixed at hashtable creation */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + long num_partitions; /* # partitions (must be power of 2), or 0 */ + long ffactor; /* target fill factor */ + long max_dsize; /* 'dsize' limit if directory is fixed size */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ + int nelem_alloc; /* number of entries to allocate at once */ + +#ifdef HASH_STATISTICS + + /* + * Count statistics here. NB: stats code doesn't bother with mutex, so + * counts could be corrupted a bit in a partitioned table. + */ + long accesses; + long collisions; +#endif +}; + +/* the offset of the last padding if exists*/ +#define HTAB_PAD_OFFSET 104 + +/* + * Top control structure for a hashtable --- in a shared table, each backend + * has its own copy (OK since no fields change at runtime) + */ +struct HTAB { + HASHHDR* hctl; /* => shared control information */ + HASHSEGMENT* dir; /* directory of segment starts */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context if default allocator used */ + char* tabname; /* table name (for error messages) */ + bool isshared; /* true if table is in shared memory */ + bool isfixed; /* if true, don't enlarge */ + + /* freezing a shared table isn't allowed, so we can keep state here */ + bool frozen; /* true = no more inserts allowed */ + + /* We keep local copies of these fixed values to reduce contention */ + Size keysize; /* hash key length in bytes */ + long ssize; /* segment size --- must be power of 2 */ + int sshift; /* segment shift = log2(ssize) */ +#ifdef __aarch64__ + char pad[PG_CACHE_LINE_SIZE - HTAB_PAD_OFFSET]; +#endif +}; + +extern int my_log2(long num); +template +void* buf_hash_operate(HTAB* hashp, const BufferTag* keyPtr, uint32 hashvalue, bool* foundPtr); +#endif /* DYNAHASH_H */ diff -uprN postgresql-hll-2.14_old/include/utils/dynamic_loader.h postgresql-hll-2.14/include/utils/dynamic_loader.h --- postgresql-hll-2.14_old/include/utils/dynamic_loader.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/dynamic_loader.h 2020-12-12 17:06:43.395349948 +0800 @@ -0,0 +1,24 @@ +/* ------------------------------------------------------------------------- + * + * dynamic_loader.h + * + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/dynamic_loader.h + * + * ------------------------------------------------------------------------- + */ +#ifndef DYNAMIC_LOADER_H +#define DYNAMIC_LOADER_H + +#include "fmgr.h" + +extern void* pg_dlopen(char* filename); +extern PGFunction pg_dlsym(void* handle, char* funcname); +extern void pg_dlclose(void* handle); +extern char* pg_dlerror(void); + +#endif /* DYNAMIC_LOADER_H */ diff -uprN postgresql-hll-2.14_old/include/utils/elog.h postgresql-hll-2.14/include/utils/elog.h --- postgresql-hll-2.14_old/include/utils/elog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/elog.h 2020-12-12 17:06:43.396349961 +0800 @@ -0,0 +1,614 @@ +/* ------------------------------------------------------------------------- + * + * elog.h + * POSTGRES error reporting/logging definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/elog.h + * + * ------------------------------------------------------------------------- + */ +#ifndef ELOG_H +#define ELOG_H + +#include +#ifdef __GNUC__ +#include +#endif /* __GNUC__ */ + +#include "c.h" +#include "gs_threadlocal.h" +#include "gstrace/gstrace_infra.h" +#include "utils/be_module.h" +#include "utils/syscall_lock.h" +#include "securec.h" +#include "securec_check.h" + +/* Error level codes */ +#define DEBUG5 \ + 10 /* Debugging messages, in categories of \ + * decreasing detail. */ +#define DEBUG4 11 +#define DEBUG3 12 +#define DEBUG2 13 +#define DEBUG1 14 /* used by GUC debug_* variables */ +#define LOG \ + 15 /* Server operational messages; sent only to \ + * server log by default. */ +#define COMMERROR \ + 16 /* Client communication problems; same as LOG \ + * for server reporting, but never sent to \ + * client. */ +#define INFO \ + 17 /* Messages specifically requested by user (eg \ + * VACUUM VERBOSE output); always sent to \ + * client regardless of client_min_messages, \ + * but by default not sent to server log. */ +#define NOTICE \ + 18 /* Helpful messages to users about query \ + * operation; sent to client and server log by \ + * default. */ +#define WARNING \ + 19 /* Warnings. NOTICE is for expected messages \ + * like implicit sequence creation by SERIAL. \ + * WARNING is for unexpected messages. */ +#define ERROR \ + 20 /* user error - abort transaction; return to \ + * known state */ +#define VERBOSEMESSAGE \ + 9 /* indicates to show verbose info for CN and DNs; \ + * for DNs means to send info back to CN */ +/* Save ERROR value in PGERROR so it can be restored when Win32 includes + * modify it. We have to use a constant rather than ERROR because macros + * are expanded only when referenced outside macros. + */ +#ifdef WIN32 +#define PGERROR 20 +#endif +#define FATAL 21 /* fatal error - abort process */ +#define PANIC 22 /* take down the other backends with me */ + +/* MAKE_SQLSTATE('P', '1', '0' , '0', '0')=96 */ +#define CUSTOM_ERRCODE_P1 96 + +/* macros for representing SQLSTATE strings compactly */ +#define PGSIXBIT(ch) (((ch) - '0') & 0x3F) +#define PGUNSIXBIT(val) (((val)&0x3F) + '0') + +#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5) \ + (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24)) + +/* These macros depend on the fact that '0' becomes a zero in SIXBIT */ +#define ERRCODE_TO_CATEGORY(ec) ((ec) & ((1 << 12) - 1)) +#define ERRCODE_IS_CATEGORY(ec) (((ec) & ~((1 << 12) - 1)) == 0) + +/* SQLSTATE codes for errors are defined in a separate file */ +#include "utils/errcodes.h" + +/* Which __func__ symbol do we have, if any? */ +#ifdef HAVE_FUNCNAME__FUNC +#define PG_FUNCNAME_MACRO __func__ +#else +#ifdef HAVE_FUNCNAME__FUNCTION +#define PG_FUNCNAME_MACRO __FUNCTION__ +#else +#define PG_FUNCNAME_MACRO NULL +#endif +#endif + +/* ---------- + * New-style error reporting API: to be used in this way: + * ereport(ERROR, + * (errcode(ERRCODE_UNDEFINED_CURSOR), + * errmsg("portal \"%s\" not found", stmt->portalname), + * ... other errxxx() fields as needed ...)); + * + * The error level is required, and so is a primary error message (errmsg + * or errmsg_internal). All else is optional. errcode() defaults to + * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING + * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is + * NOTICE or below. + * + * ereport_domain() allows a message domain to be specified, for modules that + * wish to use a different message catalog from the backend's. To avoid having + * one copy of the default text domain per .o file, we define it as NULL here + * and have errstart insert the default text domain. Modules can either use + * ereport_domain() directly, or preferably they can override the TEXTDOMAIN + * macro. + * ---------- + */ +#define ereport_domain(elevel, domain, rest) \ + (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? (errfinish rest) : (void)0) + +#ifdef PC_LINT +#define ereport(elevel, rest) \ + do { \ + if (elevel >= ERROR) \ + exit((int)(rest)); \ + } while (0) + +#else +#define ereport(elevel, rest) ereport_domain(elevel, TEXTDOMAIN, rest) +#endif /*PCLINT_CHECK*/ + +#define TEXTDOMAIN NULL + +extern bool errstart(int elevel, const char* filename, int lineno, const char* funcname, const char* domain); +extern void errfinish(int dummy, ...); +#ifdef PC_LINT +#define errcode(sqlerrcode) (1 == (int)(sqlerrcode)) +#else +#if !defined(WIN32) +extern int errcode(int sqlerrcode); +#endif +#endif +extern int errcode_for_file_access(void); +extern int errcode_for_socket_access(void); + +/* set error module */ +extern int errmodule(ModuleId id); + +extern char* maskPassword(const char* query_string); + +#define MASK_PASSWORD_START(mask_string, query_string) \ + do { \ + mask_string = maskPassword(query_string); \ + if (NULL == mask_string) \ + mask_string = (char*)query_string; \ + } while (0) + +#define MASK_PASSWORD_END(mask_string, query_string) \ + do { \ + if (mask_string != query_string) \ + selfpfree(mask_string); \ + } while (0) + +extern int errmsg(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errmsg_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errmsg_plural(const char* fmt_singular, const char* fmt_plural, unsigned long n, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4))) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4))); + +extern int errdetail(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_internal(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_log(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errdetail_plural(const char* fmt_singular, const char* fmt_plural, unsigned long n, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 4))) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 4))); + +extern int errhint(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errquery(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errcontext(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern int errhidestmt(bool hide_stmt); + +extern int errhideprefix(bool hide_prefix); + +extern int errposition(int cursorpos); + +extern int internalerrposition(int cursorpos); +extern int internalerrquery(const char* query); + +extern int geterrcode(void); +extern int geterrposition(void); +extern int getinternalerrposition(void); + +extern void save_error_message(void); + +extern int handle_in_client(bool handle); +extern int ignore_interrupt(bool ignore); + +/* ---------- + * Old-style error reporting API: to be used in this way: + * elog(ERROR, "portal \"%s\" not found", stmt->portalname); + * ---------- + */ + +#ifdef PC_LINT +#define elog(level, ...) \ + do { \ + if (level >= ERROR) \ + exit(0); \ + } while (0) +#else +#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish +#endif /* PCLINT_CHECK */ + +extern void elog_start(const char* filename, int lineno, const char* funcname); +extern void elog_finish(int elevel, const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3))); + +/* Support for constructing error strings separately from ereport() calls */ + +extern void pre_format_elog_string(int errnumber, const char* domain); +extern char* format_elog_string(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +/* Support for attaching context information to error reports */ + +typedef struct ErrorContextCallback { + struct ErrorContextCallback* previous; + void (*callback)(void* arg); + void* arg; +} ErrorContextCallback; + +#ifndef FRONTEND +#define securec_check(errno, charList, ...) \ + { \ + if (EOK != errno) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + switch (errno) { \ + case EINVAL: \ + elog(ERROR, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(ERROR, "%s : %d : The Source Buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(ERROR, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(ERROR, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } + +#else + +#define securec_check(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace_c(charList, ##__VA_ARGS__); \ + printf("ERROR at %s : %d : The destination buffer or format is a NULL pointer or the invalid parameter " \ + "handle is invoked..\n", \ + __FILE__, \ + __LINE__); \ + exit(1); \ + } \ + } + +#endif + +/* Only used in sprintf_s or scanf_s cluster function */ +#define securec_check_ss(errno, charList, ...) \ + { \ + if (errno == -1) { \ + freeSecurityFuncSpace(charList, ##__VA_ARGS__); \ + elog(ERROR, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } + +/* ---------- + * API for catching ereport(ERROR) exits. Use these macros like so: + * + * PG_TRY(); + * { + * ... code that might throw ereport(ERROR) ... + * } + * PG_CATCH(); + * { + * ... error recovery code ... + * } + * PG_END_TRY(); + * + * (The braces are not actually necessary, but are recommended so that + * pg_indent will indent the construct nicely.) The error recovery code + * can optionally do PG_RE_THROW() to propagate the same error outwards. + * + * Note: while the system will correctly propagate any new ereport(ERROR) + * occurring in the recovery section, there is a small limit on the number + * of levels this will work for. It's best to keep the error recovery + * section simple enough that it can't generate any new errors, at least + * not before popping the error stack. + * + * Note: an ereport(FATAL) will not be caught by this construct; control will + * exit straight through proc_exit(). Therefore, do NOT put any cleanup + * of non-process-local resources into the error recovery section, at least + * not without taking thought for what will happen during ereport(FATAL). + * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be + * helpful in such cases. + * + * Note: Don't execute statements such as break, continue, goto, or return in + * PG_TRY. If you need to use these statements, you must recovery + * PG_exception_stack first. + * ---------- + */ +#define PG_TRY() \ + do { \ + sigjmp_buf* save_exception_stack = t_thrd.log_cxt.PG_exception_stack; \ + ErrorContextCallback* save_context_stack = t_thrd.log_cxt.error_context_stack; \ + sigjmp_buf local_sigjmp_buf; \ + int tryCounter, *oldTryCounter = NULL; \ + if (sigsetjmp(local_sigjmp_buf, 0) == 0) { \ + t_thrd.log_cxt.PG_exception_stack = &local_sigjmp_buf; \ + oldTryCounter = gstrace_tryblock_entry(&tryCounter) + +#define PG_CATCH() \ + } \ + else \ + { \ + t_thrd.log_cxt.PG_exception_stack = save_exception_stack; \ + t_thrd.log_cxt.error_context_stack = save_context_stack; \ + gstrace_tryblock_exit(true, oldTryCounter) + +#define PG_END_TRY() \ + } \ + t_thrd.log_cxt.PG_exception_stack = save_exception_stack; \ + t_thrd.log_cxt.error_context_stack = save_context_stack; \ + gstrace_tryblock_exit(false, oldTryCounter); \ + } \ + while (0) + +// ADIO means async direct io +#define ADIO_RUN() if (g_instance.attr.attr_storage.enable_adio_function) { + +#define ADIO_ELSE() \ + } \ + else \ + { + +#define ADIO_END() } + +// BFIO means buffer io +#define BFIO_RUN() if (!g_instance.attr.attr_storage.enable_adio_function) { + +#define BFIO_ELSE() \ + } \ + else \ + { + +#define BFIO_END() } + +#define ADIO_LOG_DB(A) \ + do { \ + if (u_sess->attr.attr_storage.enable_adio_debug) { \ + A; \ + } \ + } while (0) + +/* + * gcc understands __attribute__((noreturn)); for other compilers, insert + * a useless exit() call so that the compiler gets the point. + */ +#ifdef __GNUC__ +#define PG_RE_THROW() pg_re_throw() +#else +#define PG_RE_THROW() (pg_re_throw(), exit(1)) // no need to change exit to pthread_exit +#endif + +/* Stuff that error handlers might want to use */ + +/* + * ErrorData holds the data accumulated during any one ereport() cycle. + * Any non-NULL pointers must point to palloc'd data. + * (The const pointers are an exception; we assume they point at non-freeable + * constant strings.) + */ +typedef struct ErrorData { + int elevel; /* error level */ + bool output_to_server; /* will report to server log? */ + bool output_to_client; /* will report to client? */ + bool handle_in_client; /* true to report to client and also handle in client */ + bool show_funcname; /* true to force funcname inclusion */ + bool hide_stmt; /* true to prevent STATEMENT: inclusion */ + bool hide_prefix; /* true to prevent line prefix inclusion */ + char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + char* funcname; /* __func__ of ereport() call */ + const char* domain; /* message domain */ + int sqlerrcode; /* encoded ERRSTATE */ + ModuleId mod_id; /* which module */ + char* message; /* primary error message */ + char* detail; /* detail error message */ + char* detail_log; /* detail error message for server log only */ + char* hint; /* hint message */ + char* context; /* context message */ + int cursorpos; /* cursor index into query string */ + int internalpos; /* cursor index into internalquery */ + char* internalquery; /* text of internally-generated query */ + int saved_errno; /* errno at entry */ + char* backtrace_log; /* the buffer for backtrace */ + int internalerrcode; /* mppdb internal encoded */ + bool verbose; /* the flag to indicate VACUUM FULL VERBOSE/ANALYZE VERBOSE message */ + bool ignore_interrupt; /* true to ignore interrupt when writing server log */ +} ErrorData; + +/* The error data from remote */ +typedef struct RemoteErrorData { + int internalerrcode; /* mppdb internal encoded */ + char* errorfuncname; /* __func__ of ereport() call */ + char* filename; /* __FILE__ of ereport() call */ + int lineno; /* __LINE__ of ereport() call */ + ModuleId mod_id; +} RemoteErrorData; + +extern int combiner_errdata(RemoteErrorData* pErrData); +extern void EmitErrorReport(void); +extern void stream_send_message_to_server_log(void); +extern void stream_send_message_to_consumer(void); +extern ErrorData* CopyErrorData(void); +extern void UpdateErrorData(ErrorData* edata, ErrorData* newData); +extern void FreeErrorData(ErrorData* edata); +extern void FlushErrorState(void); +extern void FlushErrorStateWithoutDeleteChildrenContext(void); +extern void ReThrowError(ErrorData* edata) __attribute__((noreturn)); +extern void pg_re_throw(void) __attribute__((noreturn)); + +/* GUC-configurable parameters */ + +typedef enum { + PGERROR_TERSE, /* single-line error messages */ + PGERROR_DEFAULT, /* recommended style */ + PGERROR_VERBOSE /* all the facts, ma'am */ +} PGErrorVerbosity; + +/* Log destination bitmap */ +#define LOG_DESTINATION_STDERR 1 +#define LOG_DESTINATION_SYSLOG 2 +#define LOG_DESTINATION_EVENTLOG 4 +#define LOG_DESTINATION_CSVLOG 8 +#define LOG_DESTINATION_QUERYLOG 16 +#define LOG_DESTINATION_ASPLOG 32 + +/* Other exported functions */ +extern void DebugFileOpen(void); +extern char* unpack_sql_state(int sql_state); +extern bool in_error_recursion_trouble(void); + +#ifdef HAVE_SYSLOG +extern void set_syslog_parameters(const char* ident, int facility); +#endif + +#ifndef WIN32 +/* + * @Description: according to module logging rules, + * check this module logging is enable or disable. + * @IN elevel: error level + * @IN mod_id: module id + * @Return: true, enable server log to write; false, disable server logging. + * @See also: send_message_to_server_log() + */ +extern inline bool is_errmodule_enable(int elevel, ModuleId mod_id) +{ + return (elevel >= LOG || module_logging_is_on(mod_id)); +} + +extern inline int defence_errlevel(void) +{ +#ifdef USE_ASSERT_CHECKING + return PANIC; +#else + return ERROR; +#endif +} + +#endif + +/* + * Write errors to stderr (or by equal means when stderr is + * not available). Used before ereport/elog can be used + * safely (memory context, GUC load etc) + */ +extern void write_stderr(const char* fmt, ...) + /* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ + __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + +extern void getElevelAndSqlstate(int* eLevel, int* sqlState); + +void freeSecurityFuncSpace(char* charList, ...); + +extern void SimpleLogToServer(int elevel, bool silent, const char* fmt, ...) + __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4))); + +/* helpful macro */ +#define AssertEreport(condition, module, msg) \ + do { \ + Assert(condition); \ + if (unlikely(!(condition))) \ + ereport(ERROR, \ + (errmodule(module), \ + errcode(ERRORCODE_ASSERT_FAILED), \ + errmsg("failed on assertion in %s line %d. %s", __FILE__, __LINE__, msg))); \ + } while (0) + +/* This Macro reports an error when touching distributed features in single node DB */ +#define DISTRIBUTED_FEATURE_NOT_SUPPORTED() \ + do { \ + ereport(ERROR, \ + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \ + errmsg("Un-support feature"), \ + errdetail("The distributed capability is not supported currently."))); \ + } while (0) + +#define IPC_PERFORMANCE_LOG_OUTPUT(errorMessage) \ + do \ + if (module_logging_is_on(MOD_COMM_IPC) && \ + (t_thrd.proc && t_thrd.proc->workingVersionNum >= 92060)) { \ + ereport(LOG, (errmodule(MOD_COMM_IPC), errmsg((char*)errorMessage))); \ + } \ + while (0) + +#define IPC_PERFORMANCE_LOG_COLLECT(msgLog, buffer, bufferLen, remoteNode, fd, msgOpr) \ + do \ + if (module_logging_is_on(MOD_COMM_IPC) && bufferLen > 0 && \ + (t_thrd.proc && t_thrd.proc->workingVersionNum >= 92060)) { \ + msgLog = gs_comm_ipc_performance(msgLog, buffer, bufferLen, remoteNode, fd, msgOpr); \ + } \ + while (0) + +#define MODULE_LOG_TRACE(trace_mode, ...) \ + do \ + if (module_logging_is_on(trace_mode)) { \ + ereport(LOG, (errmodule(trace_mode), errmsg(__VA_ARGS__))); \ + } \ + while (0) \ + +#endif /* ELOG_H */ diff -uprN postgresql-hll-2.14_old/include/utils/errcodes.h postgresql-hll-2.14/include/utils/errcodes.h --- postgresql-hll-2.14_old/include/utils/errcodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/errcodes.h 2020-12-12 17:06:43.396349961 +0800 @@ -0,0 +1,454 @@ +/* autogenerated from src/backend/utils/errcodes.txt, do not edit */ +/* there is deliberately not an #ifndef ERRCODES_H here */ + +/* Class 00 - Successful Completion */ +#define ERRCODE_SUCCESSFUL_COMPLETION MAKE_SQLSTATE('0','0','0','0','0') + +/* Class 01 - Warning */ +#define ERRCODE_WARNING MAKE_SQLSTATE('0','1','0','0','0') +#define ERRCODE_WARNING_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','1','0','0','C') +#define ERRCODE_WARNING_IMPLICIT_ZERO_BIT_PADDING MAKE_SQLSTATE('0','1','0','0','8') +#define ERRCODE_WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION MAKE_SQLSTATE('0','1','0','0','3') +#define ERRCODE_WARNING_PRIVILEGE_NOT_GRANTED MAKE_SQLSTATE('0','1','0','0','7') +#define ERRCODE_WARNING_PRIVILEGE_NOT_REVOKED MAKE_SQLSTATE('0','1','0','0','6') +#define ERRCODE_WARNING_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('0','1','0','0','4') +#define ERRCODE_WARNING_DEPRECATED_FEATURE MAKE_SQLSTATE('0','1','P','0','1') + +/* Class 02 - No Data (this is also a warning class per the SQL standard) */ +#define ERRCODE_NO_DATA MAKE_SQLSTATE('0','2','0','0','0') +#define ERRCODE_NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED MAKE_SQLSTATE('0','2','0','0','1') +#define ERRCODE_INVALID_OPTION MAKE_SQLSTATE('0','2','0','0','2') + +/* Class 03 - SQL Statement Not Yet Complete */ +#define ERRCODE_SQL_STATEMENT_NOT_YET_COMPLETE MAKE_SQLSTATE('0','3','0','0','0') + +/* Class 08 - Connection Exception */ +#define ERRCODE_CONNECTION_EXCEPTION MAKE_SQLSTATE('0','8','0','0','0') +#define ERRCODE_CONNECTION_DOES_NOT_EXIST MAKE_SQLSTATE('0','8','0','0','3') +#define ERRCODE_CONNECTION_FAILURE MAKE_SQLSTATE('0','8','0','0','6') +#define ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION MAKE_SQLSTATE('0','8','0','0','1') +#define ERRCODE_SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION MAKE_SQLSTATE('0','8','0','0','4') +#define ERRCODE_TRANSACTION_RESOLUTION_UNKNOWN MAKE_SQLSTATE('0','8','0','0','7') +#define ERRCODE_PROTOCOL_VIOLATION MAKE_SQLSTATE('0','8','P','0','1') + +/* Class 09 - Triggered Action Exception */ +#define ERRCODE_TRIGGERED_ACTION_EXCEPTION MAKE_SQLSTATE('0','9','0','0','0') + +/* Class 0A - Feature Not Supported */ +#define ERRCODE_FEATURE_NOT_SUPPORTED MAKE_SQLSTATE('0','A','0','0','0') +#define ERRCODE_STREAM_NOT_SUPPORTED MAKE_SQLSTATE('0','A','1','0','0') + +/* Class 0B - Invalid Transaction Initiation */ +#define ERRCODE_INVALID_TRANSACTION_INITIATION MAKE_SQLSTATE('0','B','0','0','0') + +/* Class 0F - Locator Exception */ +#define ERRCODE_LOCATOR_EXCEPTION MAKE_SQLSTATE('0','F','0','0','0') +#define ERRCODE_L_E_INVALID_SPECIFICATION MAKE_SQLSTATE('0','F','0','0','1') + +/* Class 0L - Invalid Grantor */ +#define ERRCODE_INVALID_GRANTOR MAKE_SQLSTATE('0','L','0','0','0') +#define ERRCODE_INVALID_GRANT_OPERATION MAKE_SQLSTATE('0','L','P','0','1') + +/* Class 0P - Invalid Role Specification */ +#define ERRCODE_INVALID_ROLE_SPECIFICATION MAKE_SQLSTATE('0','P','0','0','0') + +/* Class 0Z - Diagnostics Exception */ +#define ERRCODE_DIAGNOSTICS_EXCEPTION MAKE_SQLSTATE('0','Z','0','0','0') +#define ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER MAKE_SQLSTATE('0','Z','0','0','2') + +/* Class 20 - Case Not Found */ +#define ERRCODE_CASE_NOT_FOUND MAKE_SQLSTATE('2','0','0','0','0') + +/* Class 21 - Cardinality Violation */ +#define ERRCODE_CARDINALITY_VIOLATION MAKE_SQLSTATE('2','1','0','0','0') + +/* Class 22 - Data Exception */ +#define ERRCODE_DATA_EXCEPTION MAKE_SQLSTATE('2','2','0','0','0') +#define ERRCODE_ARRAY_ELEMENT_ERROR MAKE_SQLSTATE('2','2','0','0','E') +#define ERRCODE_ARRAY_SUBSCRIPT_ERROR MAKE_SQLSTATE('2','2','0','2','E') +#define ERRCODE_CHARACTER_NOT_IN_REPERTOIRE MAKE_SQLSTATE('2','2','0','2','1') +#define ERRCODE_DATETIME_FIELD_OVERFLOW MAKE_SQLSTATE('2','2','0','0','8') +#define ERRCODE_DATETIME_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','2','0') +#define ERRCODE_DIVISION_BY_ZERO MAKE_SQLSTATE('2','2','0','1','2') +#define ERRCODE_ERROR_IN_ASSIGNMENT MAKE_SQLSTATE('2','2','0','0','5') +#define ERRCODE_ESCAPE_CHARACTER_CONFLICT MAKE_SQLSTATE('2','2','0','0','B') +#define ERRCODE_INDICATOR_OVERFLOW MAKE_SQLSTATE('2','2','0','2','2') +#define ERRCODE_INTERVAL_FIELD_OVERFLOW MAKE_SQLSTATE('2','2','0','1','5') +#define ERRCODE_INVALID_ARGUMENT_FOR_LOG MAKE_SQLSTATE('2','2','0','1','E') +#define ERRCODE_INVALID_ARGUMENT_FOR_NTILE MAKE_SQLSTATE('2','2','0','1','4') +#define ERRCODE_INVALID_ARGUMENT_FOR_NTH_VALUE MAKE_SQLSTATE('2','2','0','1','6') +#define ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION MAKE_SQLSTATE('2','2','0','1','F') +#define ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION MAKE_SQLSTATE('2','2','0','1','G') +#define ERRCODE_INVALID_CHARACTER_VALUE_FOR_CAST MAKE_SQLSTATE('2','2','0','1','8') +#define ERRCODE_INVALID_DATETIME_FORMAT MAKE_SQLSTATE('2','2','0','0','7') +#define ERRCODE_INVALID_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','0','1','9') +#define ERRCODE_INVALID_ESCAPE_OCTET MAKE_SQLSTATE('2','2','0','0','D') +#define ERRCODE_INVALID_ESCAPE_SEQUENCE MAKE_SQLSTATE('2','2','0','2','5') +#define ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','P','0','6') +#define ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE MAKE_SQLSTATE('2','2','0','1','0') +#define ERRCODE_INVALID_PARAMETER_VALUE MAKE_SQLSTATE('2','2','0','2','3') +#define ERRCODE_INVALID_REGULAR_EXPRESSION MAKE_SQLSTATE('2','2','0','1','B') +#define ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE MAKE_SQLSTATE('2','2','0','1','W') +#define ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE MAKE_SQLSTATE('2','2','0','1','X') +#define ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE MAKE_SQLSTATE('2','2','0','0','9') +#define ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER MAKE_SQLSTATE('2','2','0','0','C') +#define ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH MAKE_SQLSTATE('2','2','0','0','G') +#define ERRCODE_NULL_VALUE_NOT_ALLOWED MAKE_SQLSTATE('2','2','0','0','4') +#define ERRCODE_NULL_VALUE_NO_INDICATOR_PARAMETER MAKE_SQLSTATE('2','2','0','0','2') +#define ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','0','3') +#define ERRCODE_DOP_VALUE_OUT_OF_RANGE MAKE_SQLSTATE('2','2','0','1','7') +#define ERRCODE_STRING_DATA_LENGTH_MISMATCH MAKE_SQLSTATE('2','2','0','2','6') +#define ERRCODE_REGEXP_MISMATCH MAKE_SQLSTATE('2','2','0','2','8') +#define ERRCODE_STRING_DATA_RIGHT_TRUNCATION MAKE_SQLSTATE('2','2','0','0','1') +#define ERRCODE_SUBSTRING_ERROR MAKE_SQLSTATE('2','2','0','1','1') +#define ERRCODE_TRIM_ERROR MAKE_SQLSTATE('2','2','0','2','7') +#define ERRCODE_UNTERMINATED_C_STRING MAKE_SQLSTATE('2','2','0','2','4') +#define ERRCODE_ZERO_LENGTH_CHARACTER_STRING MAKE_SQLSTATE('2','2','0','0','F') +#define ERRCODE_FLOATING_POINT_EXCEPTION MAKE_SQLSTATE('2','2','P','0','1') +#define ERRCODE_INVALID_TEXT_REPRESENTATION MAKE_SQLSTATE('2','2','P','0','2') +#define ERRCODE_INVALID_BINARY_REPRESENTATION MAKE_SQLSTATE('2','2','P','0','3') +#define ERRCODE_BAD_COPY_FILE_FORMAT MAKE_SQLSTATE('2','2','P','0','4') +#define ERRCODE_UNTRANSLATABLE_CHARACTER MAKE_SQLSTATE('2','2','P','0','5') +#define ERRCODE_NOT_AN_XML_DOCUMENT MAKE_SQLSTATE('2','2','0','0','L') +#define ERRCODE_INVALID_XML_DOCUMENT MAKE_SQLSTATE('2','2','0','0','M') +#define ERRCODE_INVALID_XML_CONTENT MAKE_SQLSTATE('2','2','0','0','N') +#define ERRCODE_INVALID_XML_ERROR_CONTEXT MAKE_SQLSTATE('2','2','0','0','O') +#define ERRCODE_INVALID_XML_COMMENT MAKE_SQLSTATE('2','2','0','0','S') +#define ERRCODE_INVALID_XML_PROCESSING_INSTRUCTION MAKE_SQLSTATE('2','2','0','0','T') + +/* Class 23 - Integrity Constraint Violation */ +#define ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('2','3','0','0','0') +#define ERRCODE_RESTRICT_VIOLATION MAKE_SQLSTATE('2','3','0','0','1') +#define ERRCODE_NOT_NULL_VIOLATION MAKE_SQLSTATE('2','3','5','0','2') +#define ERRCODE_FOREIGN_KEY_VIOLATION MAKE_SQLSTATE('2','3','5','0','3') +#define ERRCODE_UNIQUE_VIOLATION MAKE_SQLSTATE('2','3','5','0','5') +#define ERRCODE_CHECK_VIOLATION MAKE_SQLSTATE('2','3','5','1','4') +#define ERRCODE_EXCLUSION_VIOLATION MAKE_SQLSTATE('2','3','P','0','1') + +/* Class 24 - Invalid Cursor State */ +#define ERRCODE_INVALID_CURSOR_STATE MAKE_SQLSTATE('2','4','0','0','0') + +/* Class 25 - Invalid Transaction State */ +#define ERRCODE_INVALID_TRANSACTION_STATE MAKE_SQLSTATE('2','5','0','0','0') +#define ERRCODE_ACTIVE_SQL_TRANSACTION MAKE_SQLSTATE('2','5','0','0','1') +#define ERRCODE_BRANCH_TRANSACTION_ALREADY_ACTIVE MAKE_SQLSTATE('2','5','0','0','2') +#define ERRCODE_HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL MAKE_SQLSTATE('2','5','0','0','8') +#define ERRCODE_INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','3') +#define ERRCODE_INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','4') +#define ERRCODE_NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION MAKE_SQLSTATE('2','5','0','0','5') +#define ERRCODE_READ_ONLY_SQL_TRANSACTION MAKE_SQLSTATE('2','5','0','0','6') +#define ERRCODE_SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED MAKE_SQLSTATE('2','5','0','0','7') +#define ERRCODE_RUN_TRANSACTION_DURING_RECOVERY MAKE_SQLSTATE('2','5','0','0','9') +#define ERRCODE_GXID_DOES_NOT_EXIST MAKE_SQLSTATE('2','5','0','1','0') +#define ERRCODE_NO_ACTIVE_SQL_TRANSACTION MAKE_SQLSTATE('2','5','P','0','1') +#define ERRCODE_IN_FAILED_SQL_TRANSACTION MAKE_SQLSTATE('2','5','P','0','2') + +/* Class 26 - Invalid SQL Statement Name */ +#define ERRCODE_INVALID_SQL_STATEMENT_NAME MAKE_SQLSTATE('2','6','0','0','0') +#define ERRCODE_SLOW_QUERY MAKE_SQLSTATE('2','6','0','0','1') +#define ERRCODE_ACTIVE_SESSION_PROFILE MAKE_SQLSTATE('2','6','0','0','2') + +/* Class 27 - Triggered Data Change Violation */ +#define ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION MAKE_SQLSTATE('2','7','0','0','0') +#define ERRCODE_TRIGGERED_INVALID_TUPLE MAKE_SQLSTATE('2','7','0','0','1') + +/* Class 28 - Invalid Authorization Specification */ +#define ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION MAKE_SQLSTATE('2','8','0','0','0') +#define ERRCODE_INVALID_PASSWORD MAKE_SQLSTATE('2','8','P','0','1') +#define ERRCODE_INITIAL_PASSWORD_NOT_MODIFIED MAKE_SQLSTATE('2','8','P','0','2') + +/* Class 29 - Invalid or Unexpected Status */ +#define ERRCODE_INVALID_STATUS MAKE_SQLSTATE('2','9','0','0','0') +#define ERRCODE_INVALID_TABLESAMPLE_ARGUMENT MAKE_SQLSTATE('2','9','0','0','1') +#define ERRCODE_INVALID_TABLESAMPLE_REPEAT MAKE_SQLSTATE('2','9','0','0','2') +#define ERRORCODE_ASSERT_FAILED MAKE_SQLSTATE('2','9','0','0','3') +#define ERRCODE_CACHE_LOOKUP_FAILED MAKE_SQLSTATE('2','9','P','0','1') +#define ERRCODE_FETCH_DATA_FAILED MAKE_SQLSTATE('2','9','P','0','2') +#define ERRCODE_FLUSH_DATA_SIZE_MISMATCH MAKE_SQLSTATE('2','9','P','0','3') +#define ERRCODE_RELATION_OPEN_ERROR MAKE_SQLSTATE('2','9','P','0','4') +#define ERRCODE_RELATION_CLOSE_ERROR MAKE_SQLSTATE('2','9','P','0','5') +#define ERRCODE_INVALID_CACHE_PLAN MAKE_SQLSTATE('2','9','P','0','6') + +/* Class 2B - Dependent Privilege Descriptors Still Exist */ +#define ERRCODE_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST MAKE_SQLSTATE('2','B','0','0','0') +#define ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST MAKE_SQLSTATE('2','B','P','0','1') + +/* Class 2D - Invalid Transaction Termination */ +#define ERRCODE_INVALID_TRANSACTION_TERMINATION MAKE_SQLSTATE('2','D','0','0','0') + +/* Class 2F - SQL Routine Exception */ +#define ERRCODE_SQL_ROUTINE_EXCEPTION MAKE_SQLSTATE('2','F','0','0','0') +#define ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT MAKE_SQLSTATE('2','F','0','0','5') +#define ERRCODE_S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('2','F','0','0','2') +#define ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED MAKE_SQLSTATE('2','F','0','0','3') +#define ERRCODE_S_R_E_READING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('2','F','0','0','4') + +/* Class 34 - Invalid Cursor Name */ +#define ERRCODE_INVALID_CURSOR_NAME MAKE_SQLSTATE('3','4','0','0','0') + +/* Class 38 - External Routine Exception */ +#define ERRCODE_EXTERNAL_ROUTINE_EXCEPTION MAKE_SQLSTATE('3','8','0','0','0') +#define ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','1') +#define ERRCODE_E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','2') +#define ERRCODE_E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED MAKE_SQLSTATE('3','8','0','0','3') +#define ERRCODE_E_R_E_READING_SQL_DATA_NOT_PERMITTED MAKE_SQLSTATE('3','8','0','0','4') + +/* Class 39 - External Routine Invocation Exception */ +#define ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION MAKE_SQLSTATE('3','9','0','0','0') +#define ERRCODE_E_R_I_E_INVALID_SQLSTATE_RETURNED MAKE_SQLSTATE('3','9','0','0','1') +#define ERRCODE_E_R_I_E_NULL_VALUE_NOT_ALLOWED MAKE_SQLSTATE('3','9','0','0','4') +#define ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED MAKE_SQLSTATE('3','9','P','0','1') +#define ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED MAKE_SQLSTATE('3','9','P','0','2') + +/* Class 3B - Savepoint Exception */ +#define ERRCODE_SAVEPOINT_EXCEPTION MAKE_SQLSTATE('3','B','0','0','0') +#define ERRCODE_S_E_INVALID_SPECIFICATION MAKE_SQLSTATE('3','B','0','0','1') + +/* Class 3D - Invalid Catalog Name */ +#define ERRCODE_INVALID_CATALOG_NAME MAKE_SQLSTATE('3','D','0','0','0') + +/* Class 3F - Invalid Schema Name */ +#define ERRCODE_INVALID_SCHEMA_NAME MAKE_SQLSTATE('3','F','0','0','0') + +/* Class 40 - Transaction Rollback */ +#define ERRCODE_TRANSACTION_ROLLBACK MAKE_SQLSTATE('4','0','0','0','0') +#define ERRCODE_T_R_INTEGRITY_CONSTRAINT_VIOLATION MAKE_SQLSTATE('4','0','0','0','2') +#define ERRCODE_T_R_SERIALIZATION_FAILURE MAKE_SQLSTATE('4','0','0','0','1') +#define ERRCODE_T_R_STATEMENT_COMPLETION_UNKNOWN MAKE_SQLSTATE('4','0','0','0','3') +#define ERRCODE_T_R_DEADLOCK_DETECTED MAKE_SQLSTATE('4','0','P','0','1') + +/* Class 42 - Syntax Error or Access Rule Violation */ +#define ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION MAKE_SQLSTATE('4','2','0','0','0') +#define ERRCODE_SYNTAX_ERROR MAKE_SQLSTATE('4','2','6','0','1') +#define ERRCODE_INSUFFICIENT_PRIVILEGE MAKE_SQLSTATE('4','2','5','0','1') +#define ERRCODE_CANNOT_COERCE MAKE_SQLSTATE('4','2','8','4','6') +#define ERRCODE_GROUPING_ERROR MAKE_SQLSTATE('4','2','8','0','3') +#define ERRCODE_WINDOWING_ERROR MAKE_SQLSTATE('4','2','P','2','0') +#define ERRCODE_INVALID_RECURSION MAKE_SQLSTATE('4','2','P','1','9') +#define ERRCODE_INVALID_FOREIGN_KEY MAKE_SQLSTATE('4','2','8','3','0') +#define ERRCODE_INVALID_NAME MAKE_SQLSTATE('4','2','6','0','2') +#define ERRCODE_NAME_TOO_LONG MAKE_SQLSTATE('4','2','6','2','2') +#define ERRCODE_RESERVED_NAME MAKE_SQLSTATE('4','2','9','3','9') +#define ERRCODE_DATATYPE_MISMATCH MAKE_SQLSTATE('4','2','8','0','4') +#define ERRCODE_INDETERMINATE_DATATYPE MAKE_SQLSTATE('4','2','P','3','8') +#define ERRCODE_COLLATION_MISMATCH MAKE_SQLSTATE('4','2','P','2','1') +#define ERRCODE_INDETERMINATE_COLLATION MAKE_SQLSTATE('4','2','P','2','2') +#define ERRCODE_WRONG_OBJECT_TYPE MAKE_SQLSTATE('4','2','8','0','9') +#define ERRCODE_PARTITION_ERROR MAKE_SQLSTATE('4','2','P','2','3') +#define ERRCODE_INVALID_ATTRIBUTE MAKE_SQLSTATE('4','2','P','2','4') +#define ERRCODE_INVALID_AGG MAKE_SQLSTATE('4','2','P','2','5') +#define ERRCODE_RESOURCE_POOL_ERROR MAKE_SQLSTATE('4','2','P','2','6') +#define ERRCODE_PLAN_PARENT_NOT_FOUND MAKE_SQLSTATE('4','2','P','2','7') +#define ERRCODE_MODIFY_CONFLICTS MAKE_SQLSTATE('4','2','P','2','8') +#define ERRCODE_DISTRIBUTION_ERROR MAKE_SQLSTATE('4','2','P','2','9') +#define ERRCODE_UNDEFINED_COLUMN MAKE_SQLSTATE('4','2','7','0','3') +#define ERRCODE_UNDEFINED_CURSOR MAKE_SQLSTATE('3','4','0','0','1') +#define ERRCODE_UNDEFINED_DATABASE MAKE_SQLSTATE('3','D','0','0','0') +#define ERRCODE_UNDEFINED_FUNCTION MAKE_SQLSTATE('4','2','8','8','3') +#define ERRCODE_UNDEFINED_PSTATEMENT MAKE_SQLSTATE('2','6','0','1','0') +#define ERRCODE_UNDEFINED_SCHEMA MAKE_SQLSTATE('3','F','0','0','1') +#define ERRCODE_UNDEFINED_TABLE MAKE_SQLSTATE('4','2','P','0','1') +#define ERRCODE_UNDEFINED_PARAMETER MAKE_SQLSTATE('4','2','P','0','2') +#define ERRCODE_UNDEFINED_OBJECT MAKE_SQLSTATE('4','2','7','0','4') +#define ERRCODE_DUPLICATE_COLUMN MAKE_SQLSTATE('4','2','7','0','1') +#define ERRCODE_DUPLICATE_CURSOR MAKE_SQLSTATE('4','2','P','0','3') +#define ERRCODE_DUPLICATE_DATABASE MAKE_SQLSTATE('4','2','P','0','4') +#define ERRCODE_DUPLICATE_FUNCTION MAKE_SQLSTATE('4','2','7','2','3') +#define ERRCODE_DUPLICATE_PSTATEMENT MAKE_SQLSTATE('4','2','P','0','5') +#define ERRCODE_DUPLICATE_SCHEMA MAKE_SQLSTATE('4','2','P','0','6') +#define ERRCODE_DUPLICATE_TABLE MAKE_SQLSTATE('4','2','P','0','7') +#define ERRCODE_DUPLICATE_ALIAS MAKE_SQLSTATE('4','2','7','1','2') +#define ERRCODE_DUPLICATE_OBJECT MAKE_SQLSTATE('4','2','7','1','0') +#define ERRCODE_AMBIGUOUS_COLUMN MAKE_SQLSTATE('4','2','7','0','2') +#define ERRCODE_AMBIGUOUS_FUNCTION MAKE_SQLSTATE('4','2','7','2','5') +#define ERRCODE_AMBIGUOUS_PARAMETER MAKE_SQLSTATE('4','2','P','0','8') +#define ERRCODE_AMBIGUOUS_ALIAS MAKE_SQLSTATE('4','2','P','0','9') +#define ERRCODE_INVALID_COLUMN_REFERENCE MAKE_SQLSTATE('4','2','P','1','0') +#define ERRCODE_INVALID_COLUMN_DEFINITION MAKE_SQLSTATE('4','2','6','1','1') +#define ERRCODE_INVALID_CURSOR_DEFINITION MAKE_SQLSTATE('4','2','P','1','1') +#define ERRCODE_INVALID_DATABASE_DEFINITION MAKE_SQLSTATE('4','2','P','1','2') +#define ERRCODE_INVALID_FUNCTION_DEFINITION MAKE_SQLSTATE('4','2','P','1','3') +#define ERRCODE_INVALID_PSTATEMENT_DEFINITION MAKE_SQLSTATE('4','2','P','1','4') +#define ERRCODE_INVALID_SCHEMA_DEFINITION MAKE_SQLSTATE('4','2','P','1','5') +#define ERRCODE_INVALID_TABLE_DEFINITION MAKE_SQLSTATE('4','2','P','1','6') +#define ERRCODE_INVALID_OBJECT_DEFINITION MAKE_SQLSTATE('4','2','P','1','7') +#define ERRCODE_INVALID_TEMP_OBJECTS MAKE_SQLSTATE('4','2','P','1','8') +#define ERRCODE_UNDEFINED_KEY MAKE_SQLSTATE('4','2','7','0','5') +#define ERRCODE_DUPLICATE_KEY MAKE_SQLSTATE('4','2','7','1','1') +#define ERRCODE_UNDEFINED_CL_COLUMN MAKE_SQLSTATE('4','2','7','1','3') + +/* Class 44 - WITH CHECK OPTION Violation */ +#define ERRCODE_WITH_CHECK_OPTION_VIOLATION MAKE_SQLSTATE('4','4','0','0','0') + +/* Class 53 - Insufficient Resources */ +#define ERRCODE_INSUFFICIENT_RESOURCES MAKE_SQLSTATE('5','3','0','0','0') +#define ERRCODE_DISK_FULL MAKE_SQLSTATE('5','3','1','0','0') +#define ERRCODE_OUT_OF_MEMORY MAKE_SQLSTATE('5','3','2','0','0') +#define ERRCODE_TOO_MANY_CONNECTIONS MAKE_SQLSTATE('5','3','3','0','0') +#define ERRCODE_CONFIGURATION_LIMIT_EXCEEDED MAKE_SQLSTATE('5','3','4','0','0') +#define ERRCODE_OUT_OF_BUFFER MAKE_SQLSTATE('5','3','5','0','0') + +/* Class 54 - Program Limit Exceeded */ +#define ERRCODE_PROGRAM_LIMIT_EXCEEDED MAKE_SQLSTATE('5','4','0','0','0') +#define ERRCODE_STATEMENT_TOO_COMPLEX MAKE_SQLSTATE('5','4','0','0','1') +#define ERRCODE_TOO_MANY_COLUMNS MAKE_SQLSTATE('5','4','0','1','1') +#define ERRCODE_TOO_MANY_ARGUMENTS MAKE_SQLSTATE('5','4','0','2','3') + +/* Class 55 - Object Not In Prerequisite State */ +#define ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE MAKE_SQLSTATE('5','5','0','0','0') +#define ERRCODE_OBJECT_IN_USE MAKE_SQLSTATE('5','5','0','0','6') +#define ERRCODE_CANT_CHANGE_RUNTIME_PARAM MAKE_SQLSTATE('5','5','P','0','2') +#define ERRCODE_LOCK_NOT_AVAILABLE MAKE_SQLSTATE('5','5','P','0','3') + +/* Class 57 - Operator Intervention */ +#define ERRCODE_OPERATOR_INTERVENTION MAKE_SQLSTATE('5','7','0','0','0') +#define ERRCODE_QUERY_CANCELED MAKE_SQLSTATE('5','7','0','1','4') +#define ERRCODE_QUERY_INTERNAL_CANCEL MAKE_SQLSTATE('5','7','0','1','5') +#define ERRCODE_ADMIN_SHUTDOWN MAKE_SQLSTATE('5','7','P','0','1') +#define ERRCODE_CRASH_SHUTDOWN MAKE_SQLSTATE('5','7','P','0','2') +#define ERRCODE_CANNOT_CONNECT_NOW MAKE_SQLSTATE('5','7','P','0','3') +#define ERRCODE_DATABASE_DROPPED MAKE_SQLSTATE('5','7','P','0','4') +#define ERRCODE_RU_STOP_QUERY MAKE_SQLSTATE('5','7','P','0','5') + +/* Class 58 - System Error (errors external to PostgreSQL itself) */ +#define ERRCODE_SYSTEM_ERROR MAKE_SQLSTATE('5','8','0','0','0') +#define ERRCODE_IO_ERROR MAKE_SQLSTATE('5','8','0','3','0') +#define ERRCODE_UNDEFINED_FILE MAKE_SQLSTATE('5','8','P','0','1') +#define ERRCODE_DUPLICATE_FILE MAKE_SQLSTATE('5','8','P','0','2') +#define ERRCODE_FILE_READ_FAILED MAKE_SQLSTATE('5','8','P','0','3') +#define ERRCODE_FILE_WRITE_FAILED MAKE_SQLSTATE('5','8','P','0','4') +#define ERRCODE_INVALID_ENCRYPTED_COLUMN_DATA MAKE_SQLSTATE('2','2','0','0','Z') + +/* Class F0 - Configuration File Error */ +#define ERRCODE_CONFIG_FILE_ERROR MAKE_SQLSTATE('F','0','0','0','0') +#define ERRCODE_LOCK_FILE_EXISTS MAKE_SQLSTATE('F','0','0','0','1') + +/* Class HV - Foreign Data Wrapper Error (SQL/MED) */ +#define ERRCODE_FDW_ERROR MAKE_SQLSTATE('H','V','0','0','0') +#define ERRCODE_FDW_COLUMN_NAME_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','5') +#define ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED MAKE_SQLSTATE('H','V','0','0','2') +#define ERRCODE_FDW_FUNCTION_SEQUENCE_ERROR MAKE_SQLSTATE('H','V','0','1','0') +#define ERRCODE_FDW_INCONSISTENT_DESCRIPTOR_INFORMATION MAKE_SQLSTATE('H','V','0','2','1') +#define ERRCODE_FDW_INVALID_ATTRIBUTE_VALUE MAKE_SQLSTATE('H','V','0','2','4') +#define ERRCODE_FDW_INVALID_COLUMN_NAME MAKE_SQLSTATE('H','V','0','0','7') +#define ERRCODE_FDW_INVALID_COLUMN_NUMBER MAKE_SQLSTATE('H','V','0','0','8') +#define ERRCODE_FDW_INVALID_DATA_TYPE MAKE_SQLSTATE('H','V','0','0','4') +#define ERRCODE_FDW_INVALID_DATA_TYPE_DESCRIPTORS MAKE_SQLSTATE('H','V','0','0','6') +#define ERRCODE_FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER MAKE_SQLSTATE('H','V','0','9','1') +#define ERRCODE_FDW_INVALID_HANDLE MAKE_SQLSTATE('H','V','0','0','B') +#define ERRCODE_FDW_INVALID_OPTION_INDEX MAKE_SQLSTATE('H','V','0','0','C') +#define ERRCODE_FDW_INVALID_OPTION_NAME MAKE_SQLSTATE('H','V','0','0','D') +#define ERRCODE_FDW_INVALID_OPTOIN_DATA MAKE_SQLSTATE('H','V','0','0','E') +#define ERRCODE_FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH MAKE_SQLSTATE('H','V','0','9','0') +#define ERRCODE_FDW_INVALID_STRING_FORMAT MAKE_SQLSTATE('H','V','0','0','A') +#define ERRCODE_FDW_INVALID_USE_OF_NULL_POINTER MAKE_SQLSTATE('H','V','0','0','9') +#define ERRCODE_FDW_TOO_MANY_HANDLES MAKE_SQLSTATE('H','V','0','1','4') +#define ERRCODE_FDW_OUT_OF_MEMORY MAKE_SQLSTATE('H','V','0','0','1') +#define ERRCODE_FDW_NO_SCHEMAS MAKE_SQLSTATE('H','V','0','0','P') +#define ERRCODE_FDW_OPTION_NAME_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','J') +#define ERRCODE_FDW_REPLY_HANDLE MAKE_SQLSTATE('H','V','0','0','K') +#define ERRCODE_FDW_SCHEMA_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','Q') +#define ERRCODE_FDW_TABLE_NOT_FOUND MAKE_SQLSTATE('H','V','0','0','R') +#define ERRCODE_FDW_UNABLE_TO_CREATE_EXECUTION MAKE_SQLSTATE('H','V','0','0','L') +#define ERRCODE_FDW_UNABLE_TO_CREATE_REPLY MAKE_SQLSTATE('H','V','0','0','M') +#define ERRCODE_FDW_UNABLE_TO_ESTABLISH_CONNECTION MAKE_SQLSTATE('H','V','0','0','N') +#define ERRCODE_FDW_INVALID_LIST_LENGTH MAKE_SQLSTATE('H','V','0','0','O') +#define ERRCODE_FDW_INVALID_SERVER_TYPE MAKE_SQLSTATE('H','V','0','0','S') +#define ERRCODE_FDW_OPERATION_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','5') +#define ERRCODE_FDW_CROSS_STORAGE_ENGINE_TRANSACTION_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','6') +#define ERRCODE_FDW_CROSS_STORAGE_ENGINE_QUERY_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','7') +#define ERRCODE_FDW_UPDATE_INDEXED_FIELD_NOT_SUPPORTED MAKE_SQLSTATE('H','V','0','2','8') +#define ERRCODE_FDW_TOO_MANY_INDEXES MAKE_SQLSTATE('H','V','0','2','9') +#define ERRCODE_FDW_KEY_SIZE_EXCEEDS_MAX_ALLOWED MAKE_SQLSTATE('H','V','0','3','0') +#define ERRCODE_FDW_DDL_IN_TRANSACTION_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','1') +#define ERRCODE_FDW_TOO_MANY_INDEX_COLUMNS MAKE_SQLSTATE('H','V','0','3','2') +#define ERRCODE_FDW_INDEX_ON_NULLABLE_COLUMN_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','3') +#define ERRCODE_FDW_TOO_MANY_DDL_CHANGES_IN_TRANSACTION_NOT_ALLOWED MAKE_SQLSTATE('H','V','0','3','4') + +/* Class P0 - PL/pgSQL Error */ +#define ERRCODE_PLPGSQL_ERROR MAKE_SQLSTATE('P','0','0','0','0') +#define ERRCODE_RAISE_EXCEPTION MAKE_SQLSTATE('P','0','0','0','1') +#define ERRCODE_NO_DATA_FOUND MAKE_SQLSTATE('P','0','0','0','2') +#define ERRCODE_TOO_MANY_ROWS MAKE_SQLSTATE('P','0','0','0','3') +#define ERRCODE_FORALL_NEED_DML MAKE_SQLSTATE('P','0','0','0','4') + +/* Class XX - Internal Error */ +#define ERRCODE_INTERNAL_ERROR MAKE_SQLSTATE('X','X','0','0','0') +#define ERRCODE_DATA_CORRUPTED MAKE_SQLSTATE('X','X','0','0','1') +#define ERRCODE_INDEX_CORRUPTED MAKE_SQLSTATE('X','X','0','0','2') +#define ERRCODE_STREAM_REMOTE_CLOSE_SOCKET MAKE_SQLSTATE('X','X','0','0','3') +#define ERRCODE_UNRECOGNIZED_NODE_TYPE MAKE_SQLSTATE('X','X','0','0','4') +#define ERRCODE_UNEXPECTED_NULL_VALUE MAKE_SQLSTATE('X','X','0','0','5') +#define ERRCODE_UNEXPECTED_NODE_STATE MAKE_SQLSTATE('X','X','0','0','6') +#define ERRCODE_NULL_JUNK_ATTRIBUTE MAKE_SQLSTATE('X','X','0','0','7') +#define ERRCODE_OPTIMIZER_INCONSISTENT_STATE MAKE_SQLSTATE('X','X','0','0','8') +#define ERRCODE_STREAM_DUPLICATE_QUERY_ID MAKE_SQLSTATE('X','X','0','0','9') +#define ERRCODE_INVALID_BUFFER MAKE_SQLSTATE('X','X','0','1','0') +#define ERRCODE_INVALID_BUFFER_REFERENCE MAKE_SQLSTATE('X','X','0','1','1') +#define ERRCODE_NODE_ID_MISSMATCH MAKE_SQLSTATE('X','X','0','1','2') +#define ERRCODE_CANNOT_MODIFY_XIDBASE MAKE_SQLSTATE('X','X','0','1','3') +#define ERRCODE_UNEXPECTED_CHUNK_VALUE MAKE_SQLSTATE('X','X','0','1','4') +#define ERRCODE_CN_RETRY_STUB MAKE_SQLSTATE('X','X','0','1','5') + +/* Class CG - CodeGen Error */ +#define ERRCODE_CODEGEN_ERROR MAKE_SQLSTATE('C','G','0','0','0') +#define ERRCODE_LOAD_IR_FUNCTION_FAILED MAKE_SQLSTATE('C','G','0','0','1') +#define ERRCODE_LOAD_INTRINSIC_FUNCTION_FAILED MAKE_SQLSTATE('C','G','0','0','2') + +/* Class YY - SQL Retry Error */ +#define ERRCODE_CONNECTION_RESET_BY_PEER MAKE_SQLSTATE('Y','Y','0','0','1') +#define ERRCODE_STREAM_CONNECTION_RESET_BY_PEER MAKE_SQLSTATE('Y','Y','0','0','2') +#define ERRCODE_LOCK_WAIT_TIMEOUT MAKE_SQLSTATE('Y','Y','0','0','3') +#define ERRCODE_CONNECTION_TIMED_OUT MAKE_SQLSTATE('Y','Y','0','0','4') +#define ERRCODE_SET_QUERY MAKE_SQLSTATE('Y','Y','0','0','5') +#define ERRCODE_OUT_OF_LOGICAL_MEMORY MAKE_SQLSTATE('Y','Y','0','0','6') +#define ERRCODE_SCTP_MEMORY_ALLOC MAKE_SQLSTATE('Y','Y','0','0','7') +#define ERRCODE_SCTP_NO_DATA_IN_BUFFER MAKE_SQLSTATE('Y','Y','0','0','8') +#define ERRCODE_SCTP_RELEASE_MEMORY_CLOSE MAKE_SQLSTATE('Y','Y','0','0','9') +#define ERRCODE_SCTP_TCP_DISCONNECT MAKE_SQLSTATE('Y','Y','0','1','0') +#define ERRCODE_SCTP_DISCONNECT MAKE_SQLSTATE('Y','Y','0','1','1') +#define ERRCODE_SCTP_REMOTE_CLOSE MAKE_SQLSTATE('Y','Y','0','1','2') +#define ERRCODE_SCTP_WAIT_POLL_UNKNOW MAKE_SQLSTATE('Y','Y','0','1','3') +#define ERRCODE_SNAPSHOT_INVALID MAKE_SQLSTATE('Y','Y','0','1','4') +#define ERRCODE_CONNECTION_RECEIVE_WRONG MAKE_SQLSTATE('Y','Y','0','1','5') +#define ERRCODE_STREAM_CONCURRENT_UPDATE MAKE_SQLSTATE('Y','Y','0','1','6') + +/* Class SI - SPI Interface Error */ +#define ERRCODE_SPI_ERROR MAKE_SQLSTATE('S','P','0','0','0') +#define ERRCODE_SPI_CONNECTION_FAILURE MAKE_SQLSTATE('S','P','0','0','1') +#define ERRCODE_SPI_FINISH_FAILURE MAKE_SQLSTATE('S','P','0','0','2') +#define ERRCODE_SPI_PREPARE_FAILURE MAKE_SQLSTATE('S','P','0','0','3') +#define ERRCODE_SPI_CURSOR_OPEN_FAILURE MAKE_SQLSTATE('S','P','0','0','4') +#define ERRCODE_SPI_EXECUTE_FAILURE MAKE_SQLSTATE('S','P','0','0','5') +#define ERRORCODE_SPI_IMPROPER_CALL MAKE_SQLSTATE('S','P','0','0','6') +#define ERRCODE_PLDEBUGGER_ERROR MAKE_SQLSTATE('D','0','0','0','0') +#define ERRCODE_DUPLICATE_BREAKPOINT MAKE_SQLSTATE('D','0','0','0','1') +#define ERRCODE_FUNCTION_HASH_NOT_INITED MAKE_SQLSTATE('D','0','0','0','2') +#define ERRCODE_BREAKPOINT_NOT_PRESENT MAKE_SQLSTATE('D','0','0','0','3') +#define ERRCODE_TARGET_SERVER_ALREADY_ATTACHED MAKE_SQLSTATE('D','0','0','0','4') +#define ERRCODE_TARGET_SERVER_NOT_ATTACHED MAKE_SQLSTATE('D','0','0','0','5') +#define ERRCODE_DEBUG_SERVER_ALREADY_SYNC MAKE_SQLSTATE('D','0','0','0','6') +#define ERRCODE_DEBUG_TARGET_SERVERS_NOT_IN_SYNC MAKE_SQLSTATE('D','0','0','0','7') +#define ERRCODE_TARGET_SERVER_ALREADY_SYNC MAKE_SQLSTATE('D','0','0','0','8') +#define ERRCODE_NONEXISTANT_VARIABLE MAKE_SQLSTATE('D','0','0','0','9') +#define ERRCODE_INVALID_TARGET_SESSION_ID MAKE_SQLSTATE('D','0','0','1','0') +#define ERRCODE_INVALID_OPERATION MAKE_SQLSTATE('D','0','0','1','1') +#define ERRCODE_MAX_DEBUG_SESSIONS_REACHED MAKE_SQLSTATE('D','0','0','1','2') +#define ERRCODE_MAX_BREAKPOINTS_REACHED MAKE_SQLSTATE('D','0','0','1','3') +#define ERRCODE_INITIALIZE_FAILED MAKE_SQLSTATE('D','0','0','1','4') +#define ERRCODE_RBTREE_INVALID_NODE_STATE MAKE_SQLSTATE('R','B','0','0','1') +#define ERRCODE_RBTREE_INVALID_ITERATOR_ORDER MAKE_SQLSTATE('R','B','0','0','2') +#define ERRCODE_DEBUG MAKE_SQLSTATE('D','B','0','0','1') +#define ERRCODE_LOG MAKE_SQLSTATE('D','B','0','1','0') +#define ERRCODE_OPERATE_FAILED MAKE_SQLSTATE('O','P','0','0','1') +#define ERRCODE_OPERATE_RESULT_NOT_EXPECTED MAKE_SQLSTATE('O','P','0','0','2') +#define ERRCODE_OPERATE_NOT_SUPPORTED MAKE_SQLSTATE('O','P','0','0','3') +#define ERRCODE_OPERATE_INVALID_PARAM MAKE_SQLSTATE('O','P','0','A','3') +#define ERRCODE_INDEX_OPERATOR_MISMATCH MAKE_SQLSTATE('O','P','0','0','4') +#define ERRCODE_NO_FUNCTION_PROVIDED MAKE_SQLSTATE('O','P','0','0','5') +#define ERRCODE_LOGICAL_DECODE_ERROR MAKE_SQLSTATE('L','L','0','0','1') +#define ERRCODE_RELFILENODEMAP MAKE_SQLSTATE('L','L','0','0','2') + +/* Class TS - Timeseries Error */ +#define ERRCODE_TS_COMMON_ERROR MAKE_SQLSTATE('T','S','0','0','0') +#define ERRCODE_TS_KEYTYPE_MISMATCH MAKE_SQLSTATE('T','S','0','0','1') diff -uprN postgresql-hll-2.14_old/include/utils/evp_cipher.h postgresql-hll-2.14/include/utils/evp_cipher.h --- postgresql-hll-2.14_old/include/utils/evp_cipher.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/evp_cipher.h 2020-12-12 17:06:43.396349961 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * evp_cipher.h + * SM4 encryption algorithm + * Interfaces of the AES encryption algorithm + * + * + * IDENTIFICATION + * src/include/utils/evp_cipher.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SM4_H +#define SM4_H + +#include + +unsigned long sm4_ctr_enc_partial_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, unsigned char* key, unsigned char* iv); +unsigned long sm4_ctr_dec_partial_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, unsigned char* key, unsigned char* iv); +unsigned long aes_ctr_enc_partial_mode(const char* plainText, const size_t plainLength, char* cipherText, + size_t* cipherLength, unsigned char* key, unsigned char* iv); +unsigned long aes_ctr_dec_partial_mode(const char* cipherText, const size_t cipherLength, char* plainText, + size_t* plainLength, unsigned char* key, unsigned char* iv); + +#endif /* SM4_H */ diff -uprN postgresql-hll-2.14_old/include/utils/extended_statistics.h postgresql-hll-2.14/include/utils/extended_statistics.h --- postgresql-hll-2.14_old/include/utils/extended_statistics.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/extended_statistics.h 2020-12-12 17:06:43.396349961 +0800 @@ -0,0 +1,130 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * extended_statistics.h + * Extended statistics and selectivity estimation functions. + * + * + * IDENTIFICATION + * src/include/utils/extended_statistics.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef EXTENDED_STATISTICS_H +#define EXTENDED_STATISTICS_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "catalog/pg_statistic.h" +#include "commands/vacuum.h" +#include "nodes/parsenodes.h" +#include "utils/catcache.h" +#include "utils/relcache.h" + +#define ES_LOGLEVEL DEBUG3 +#define ES_COMMIT_VERSION 91112 + +#define ES_MULTI_COLUMN_STATS_ATTNUM -101 +#define MAX_NUM_MULTI_COLUMN_STATS 1000 +#define ES_MAX_FETCH_NUM_OF_INSTANCE 100 + +typedef enum ES_STATISTIC_KIND { + ES_SEARCH = 0x00u, + ES_NULLFRAC = 0x01u, + ES_WIDTH = 0x02u, + ES_DISTINCT = 0x04u, + ES_DNDISTINCT = 0x08u, + ES_MCV = 0x10u, + ES_NULL_MCV = 0x20u, + ES_ALL = 0x3fu +} ES_STATISTIC_KIND; + +typedef enum ES_COLUMN_NAME_ALIAS { ES_COLUMN_NAME = 0x01u, ES_COLUMN_ALIAS = 0x02u } ES_COLUMN_NAME_ALIAS; + +typedef struct ExtendedStats { + Bitmapset* bms_attnum; + float4 nullfrac; + int4 width; + float4 distinct; + float4 dndistinct; + Datum* mcv_values = NULL; + bool* mcv_nulls = NULL; + int mcv_nvalues; + float4* mcv_numbers = NULL; + int mcv_nnumbers; + float4* other_mcv_numbers = NULL; + int other_mcv_nnumbers; +} ExtendedStats; + +extern void es_free_extendedstats(ExtendedStats* es); +extern void es_free_extendedstats_list(List* es_list); + +extern char es_get_starelkind(); +extern bool es_get_stainherit(); + +extern List* es_attnum_bmslist_add_unique_item(List* bmslist, Bitmapset* bms_attnum); + +extern Form_pg_type es_get_attrtype(Oid typeoid); +extern void es_get_column_typid_typmod(Oid relid, int2 attnum, Oid* atttypid, int* atttypmod); +extern void es_get_columns_typid_typmod( + Oid relid, int2vector* stakey, Oid** p_atttypid_array, int** p_atttypmod_array, unsigned int* p_num_column); +extern Oid es_get_typinput(Oid typeoid); + +extern void es_get_attnum_of_statistic_items( + Relation rel, VacuumStmt* vacstmt, Bitmapset** p_bms_single_column, List** p_list_multi_column); +extern void es_check_alter_table_statistics(Relation rel, AlterTableCmd* cmd); +extern Bitmapset* es_get_attnums_to_analyze(VacAttrStats** vacattrstats, int vacattrstats_size); + +extern VacAttrStats* es_make_vacattrstats(unsigned int num_attrs); + +extern bool es_is_valid_column_to_analyze(Form_pg_attribute attr); +extern bool es_is_type_supported_by_cstore(VacAttrStats* stats); +extern bool es_is_type_distributable(VacAttrStats* stats); + +extern void es_check_availability_for_table(VacuumStmt* stmt, Relation rel, bool inh, bool* replicate_needs_extstats); + +extern bool es_is_variable_width(VacAttrStats* stats); +extern bool es_is_not_null(AnalyzeSampleTableSpecInfo* spec); +extern bool es_is_distributekey_contained_in_multi_column(Oid relid, VacAttrStats* stats); + +/* + * Analyze query + */ +extern char* es_get_column_name_alias(AnalyzeSampleTableSpecInfo* spec, uint32 name_alias_flag, + const char* separator = ", ", const char* prefix = "", const char* postfix = ""); + +/* + * System table + */ +extern Bitmapset* es_get_multi_column_attnum(HeapTuple tuple, Relation relation); +extern List* es_explore_declared_stats(Oid relid, VacuumStmt* vacstmt, bool inh); +extern Datum es_mcv_slot_cstring_array_to_array_array( + Datum cstring_array, unsigned int num_column, const Oid* atttypid_array, const int* atttypmod_array); +extern VacAttrStats** es_build_vacattrstats_array( + Relation rel, List* bmslist_multicolumn, bool add_or_delete, int* array_length, bool inh); +extern ArrayType* es_construct_mcv_value_array(VacAttrStats* stats, int mcv_slot_index); +extern bool es_is_multicolumn_stats_exists(Oid relid, char relkind, bool inh, Bitmapset* bms_attnums); + +/* + * Interfaces for optimizer + */ +extern float4 es_get_multi_column_distinct(Oid relid, char relkind, bool inh, Bitmapset* bms_attnums); +extern ExtendedStats* es_get_multi_column_stats( + Oid relid, char relkind, bool inh, Bitmapset* bms_attnums, bool has_null = false); +extern List* es_get_multi_column_stats(Oid relid, char relkind, bool inh, int* num_stats, bool has_null = false); +extern void es_split_multi_column_stats(List* va_list, List** va_cols, List** va_cols_multi); + +#endif /* EXTENDED_STATISTICS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/fmgroids.h postgresql-hll-2.14/include/utils/fmgroids.h --- postgresql-hll-2.14_old/include/utils/fmgroids.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/fmgroids.h 2020-12-12 17:06:43.397349974 +0800 @@ -0,0 +1,2825 @@ +/*------------------------------------------------------------------------- + * + * fmgroids.h + * Macros that define the OIDs of built-in functions. + * + * These macros can be used to avoid a catalog lookup when a specific + * fmgr-callable function needs to be referenced. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * NOTES + * ****************************** + * *** DO NOT EDIT THIS FILE! *** + * ****************************** + * + * It has been GENERATED by Gen_fmgrtab.pl + * from ../../../../src/common/backend/catalog/builtin_funcs.ini + * + *------------------------------------------------------------------------- + */ +#ifndef FMGROIDS_H +#define FMGROIDS_H + +/* + * Constant macros for the OIDs of entries in pg_proc. + * + * NOTE: macros are named after the prosrc value, ie the actual C name + * of the implementing function, not the proname which may be overloaded. + * For example, we want to be able to assign different macro names to both + * char_text() and name_text() even though these both appear with proname + * 'text'. If the same C function appears in more than one pg_proc entry, + * its equivalent macro will be defined with the lowest OID among those + * entries. + */ +#define F_RI_FKEY_CASCADE_DEL 1646 +#define F_RI_FKEY_CASCADE_UPD 1647 +#define F_RI_FKEY_CHECK_INS 1644 +#define F_RI_FKEY_CHECK_UPD 1645 +#define F_RI_FKEY_NOACTION_DEL 1654 +#define F_RI_FKEY_NOACTION_UPD 1655 +#define F_RI_FKEY_RESTRICT_DEL 1648 +#define F_RI_FKEY_RESTRICT_UPD 1649 +#define F_RI_FKEY_SETDEFAULT_DEL 1652 +#define F_RI_FKEY_SETDEFAULT_UPD 1653 +#define F_RI_FKEY_SETNULL_DEL 1650 +#define F_RI_FKEY_SETNULL_UPD 1651 +#define F_INET_ABBREV 598 +#define F_CIDR_ABBREV 599 +#define F_FLOAT4ABS 1394 +#define F_FLOAT8ABS 1395 +#define F_INT8ABS 1396 +#define F_INT4ABS 1397 +#define F_INT2ABS 1398 +#define F_NUMERIC_ABS 1705 +#define F_TIMESTAMPTZ_ABSTIME 1180 +#define F_TIMESTAMP_ABSTIME TIMESTAMP2ABSTIMEFUNCOID +#define F_ABSTIMEEQ 251 +#define F_ABSTIMEGE 256 +#define F_ABSTIMEGT 254 +#define F_ABSTIMEIN ABSTIMEINFUNCOID +#define F_ABSTIMELE 255 +#define F_ABSTIMELT 253 +#define F_ABSTIMENE 252 +#define F_ABSTIMEOUT ABSTIMEOUTFUNCOID +#define F_ABSTIMERECV 2462 +#define F_ABSTIMESEND 2463 +#define F_ACLCONTAINS 1037 +#define F_ACLDEFAULT_SQL 3943 +#define F_ACLEXPLODE 1689 +#define F_ACLINSERT 1035 +#define F_ACLITEM_EQ 1062 +#define F_ACLITEMIN 1031 +#define F_ACLITEMOUT 1032 +#define F_ACLREMOVE 1036 +#define F_DACOS 1601 +#define F_ADD_JOB_CLASS_DEPEND_INTERNAL 6004 +#define F_ADD_MONTHS 4074 +#define F_XID_AGE 1181 +#define F_TIMESTAMPTZ_AGE 1199 +#define F_TIMESTAMP_AGE 2058 +#define F_ANY_IN 2294 +#define F_ANY_OUT 2295 +#define F_ANYARRAY_IN ANYARRAYINFUNCOID +#define F_ANYARRAY_OUT 2297 +#define F_ANYARRAY_RECV 2502 +#define F_ANYARRAY_SEND 2503 +#define F_ANYELEMENT_IN 2312 +#define F_ANYELEMENT_OUT 2313 +#define F_ANYENUM_IN 3504 +#define F_ANYENUM_OUT 3505 +#define F_ANYNONARRAY_IN 2777 +#define F_ANYNONARRAY_OUT 2778 +#define F_ANYRANGE_IN 3832 +#define F_ANYRANGE_OUT 3833 +#define F_BOX_AREA 975 +#define F_PATH_AREA 979 +#define F_CIRCLE_AREA 1468 +#define F_AREAJOINSEL 140 +#define F_AREASEL 139 +#define F_AGGREGATE_DUMMY ARRAYAGGFUNCOID +#define F_ARRAY_AGG_FINALFN 2334 +#define F_ARRAY_AGG_TRANSFN 2333 +#define F_ARRAY_PUSH 378 +#define F_ARRAY_CAT 383 +#define F_ARRAY_DIMS 747 +#define F_ARRAY_EQ 744 +#define F_ARRAY_EXTEND 3179 +#define F_ARRAY_FILL 1193 +#define F_ARRAY_FILL_WITH_LOWER_BOUNDS 1286 +#define F_ARRAY_GE 396 +#define F_ARRAY_GT 392 +#define F_ARRAY_IN 750 +#define F_ARRAY_LARGER 515 +#define F_ARRAY_LE 393 +#define F_ARRAY_LENGTH 2176 +#define F_ARRAY_LOWER 2091 +#define F_ARRAY_LT 391 +#define F_ARRAY_NDIMS 748 +#define F_ARRAY_NE 390 +#define F_ARRAY_OUT 751 +#define F_ARRAY_RECV 2400 +#define F_ARRAY_SEND 2401 +#define F_ARRAY_SMALLER 516 +#define F_ARRAY_TO_JSON 3153 +#define F_ARRAY_TO_JSON_PRETTY 3154 +#define F_ARRAY_TO_TEXT_NULL ARRAYTOSTRINGNULLFUNCOID +#define F_ARRAY_TO_TEXT ARRAYTOSTRINGFUNCOID +#define F_ARRAY_TYPANALYZE 3816 +#define F_ARRAY_UPPER 2092 +#define F_ARRAYCONTAINED 2749 +#define F_ARRAYCONTAINS 2748 +#define F_ARRAYCONTJOINSEL 3818 +#define F_ARRAYCONTSEL 3817 +#define F_ARRAYOVERLAP 2747 +#define F_ASCII 1620 +#define F_DASIN ARCSINEFUNCOID +#define F_DATAN 1602 +#define F_DATAN2 1603 +#define F_BIGINT_TID 3214 +#define F_BITFROMINT4 1683 +#define F_BIT 1685 +#define F_BITFROMINT8 2075 +#define F_BIT_IN 1564 +#define F_BIT_OUT 1565 +#define F_BIT_RECV 2456 +#define F_BIT_SEND 2457 +#define F_BIT_AND 1673 +#define F_BITCAT 1679 +#define F_BITCMP 1596 +#define F_BITEQ 1581 +#define F_BITGE 1592 +#define F_BITGT 1593 +#define F_BITLE 1594 +#define F_BITLT 1595 +#define F_BITNE 1582 +#define F_BITNOT 1676 +#define F_BIT_OR 1674 +#define F_BITSHIFTLEFT 1677 +#define F_BITSHIFTRIGHT 1678 +#define F_BITTYPMODIN 2919 +#define F_BITTYPMODOUT 2920 +#define F_BITXOR 1675 +#define F_INT4_BOOL 2557 +#define F_BOOL_INT1 5534 +#define F_BOOL_INT2 3181 +#define F_BOOL_INT8 3178 +#define F_BOOLAND_STATEFUNC 2515 +#define F_BOOLEQ 60 +#define F_BOOLGE 1692 +#define F_BOOLGT 57 +#define F_BOOLIN 1242 +#define F_BOOLLE 1691 +#define F_BOOLLT 56 +#define F_BOOLNE 84 +#define F_BOOLOR_STATEFUNC 2516 +#define F_BOOLOUT 1243 +#define F_BOOLRECV 2436 +#define F_BOOLSEND 2437 +#define F_POINTS_BOX 1421 +#define F_POLY_BOX 1446 +#define F_CIRCLE_BOX 1480 +#define F_BOX_ABOVE 2565 +#define F_BOX_ABOVE_EQ 115 +#define F_BOX_ADD 1422 +#define F_BOX_BELOW 2562 +#define F_BOX_BELOW_EQ 116 +#define F_BOX_CENTER 138 +#define F_BOX_CONTAIN 187 +#define F_BOX_CONTAIN_PT 193 +#define F_BOX_CONTAINED 192 +#define F_BOX_DISTANCE 978 +#define F_BOX_DIV 1425 +#define F_BOX_EQ 128 +#define F_BOX_GE 126 +#define F_BOX_GT 127 +#define F_BOX_IN 123 +#define F_BOX_INTERSECT 980 +#define F_BOX_LE 130 +#define F_BOX_LEFT 188 +#define F_BOX_LT 129 +#define F_BOX_MUL 1424 +#define F_BOX_OUT 124 +#define F_BOX_OVERABOVE 2564 +#define F_BOX_OVERBELOW 2563 +#define F_BOX_OVERLAP 125 +#define F_BOX_OVERLEFT 189 +#define F_BOX_OVERRIGHT 190 +#define F_BOX_RECV 2484 +#define F_BOX_RIGHT 191 +#define F_BOX_SAME 186 +#define F_BOX_SEND 2485 +#define F_BOX_SUB 1423 +#define F_NAME_BPCHAR 408 +#define F_BPCHAR 668 +#define F_CHAR_BPCHAR 860 +#define F_BPCHAR_DATE 4163 +#define F_BPCHAR_FLOAT4 4196 +#define F_BPCHAR_FLOAT8 4197 +#define F_BPCHAR_INT4 4175 +#define F_BPCHAR_INT8 4195 +#define F_BPCHAR_LARGER 1063 +#define F_BPCHAR_NUMERIC 4172 +#define F_BPCHAR_PATTERN_GE 2177 +#define F_BPCHAR_PATTERN_GT 2178 +#define F_BPCHAR_PATTERN_LE 2175 +#define F_BPCHAR_PATTERN_LT 2174 +#define F_BPCHAR_SMALLER 1064 +#define F_BPCHAR_SORTSUPPORT 3256 +#define F_BPCHAR_TIMESTAMP 4187 +#define F_BPCHARCMP 1078 +#define F_BPCHAREQ 1048 +#define F_BPCHARGE 1052 +#define F_BPCHARGT 1051 +#define F_TEXTICLIKE 1660 +#define F_TEXTICNLIKE 1661 +#define F_TEXTICREGEXEQ 1656 +#define F_TEXTICREGEXNE 1657 +#define F_BPCHARIN 1044 +#define F_BPCHARLE 1050 +#define F_TEXTLIKE 1631 +#define F_BPCHARLT 1049 +#define F_BPCHARNE 1053 +#define F_TEXTNLIKE 1632 +#define F_BPCHAROUT 1045 +#define F_BPCHARRECV 2430 +#define F_TEXTREGEXEQ 1658 +#define F_TEXTREGEXNE 1659 +#define F_BPCHARSEND 2431 +#define F_BPCHARTYPMODIN 2913 +#define F_BPCHARTYPMODOUT 2914 +#define F_NETWORK_BROADCAST 698 +#define F_BTABSTIMECMP 357 +#define F_BTARRAYCMP 382 +#define F_BTBEGINSCAN 333 +#define F_BTBOOLCMP 1693 +#define F_BTBPCHAR_PATTERN_CMP 2180 +#define F_BTBUILD 338 +#define F_BTBUILDEMPTY 328 +#define F_BTBULKDELETE 332 +#define F_BTCANRETURN 276 +#define F_BTCHARCMP 358 +#define F_BTCOSTESTIMATE 1268 +#define F_BTENDSCAN 335 +#define F_BTFLOAT48CMP 2194 +#define F_BTFLOAT4CMP 354 +#define F_BTFLOAT4SORTSUPPORT 3132 +#define F_BTFLOAT84CMP 2195 +#define F_BTFLOAT8CMP 355 +#define F_BTFLOAT8SORTSUPPORT 3133 +#define F_BTGETBITMAP 636 +#define F_BTGETTUPLE 330 +#define F_BTINSERT 331 +#define F_BTINT24CMP 2190 +#define F_BTINT28CMP 2192 +#define F_BTINT2CMP 350 +#define F_BTINT2SORTSUPPORT 3129 +#define F_BTINT42CMP 2191 +#define F_BTINT48CMP 2188 +#define F_BTINT4CMP 351 +#define F_BTINT4SORTSUPPORT 3130 +#define F_BTINT82CMP 2193 +#define F_BTINT84CMP 2189 +#define F_BTINT8CMP 842 +#define F_BTINT8SORTSUPPORT 3131 +#define F_BTMARKPOS 336 +#define F_BTMERGE 3184 +#define F_BTNAMECMP 359 +#define F_BTNAMESORTSUPPORT 3135 +#define F_BTOIDCMP 356 +#define F_BTOIDSORTSUPPORT 3134 +#define F_BTOIDVECTORCMP 404 +#define F_BTOPTIONS 2785 +#define F_BTRECORDCMP 2987 +#define F_BTRELTIMECMP 380 +#define F_BTRESCAN 334 +#define F_BTRESTRPOS 337 +#define F_BTRIM BTRIMPARAFUNCOID +#define F_BTRIM1 BTRIMFUNCOID +#define F_BYTEATRIM 2015 +#define F_BTTEXT_PATTERN_CMP 2166 +#define F_BTTEXTCMP 360 +#define F_BTTEXTSORTSUPPORT 3255 +#define F_BTTIDCMP 2794 +#define F_BTTINTERVALCMP 381 +#define F_BTVACUUMCLEANUP 972 +#define F_BUCKETABSTIME 4136 +#define F_BUCKETBOOL 4146 +#define F_BUCKETBPCHAR 4107 +#define F_BUCKETBYTEA 4142 +#define F_BUCKETCASH 4140 +#define F_BUCKETCHAR 4109 +#define F_BUCKETDATE 4113 +#define F_BUCKETFLOAT4 4156 +#define F_BUCKETFLOAT8 4158 +#define F_BUCKETINT1 4125 +#define F_BUCKETINT2 4103 +#define F_BUCKETINT2VECTOR 4150 +#define F_BUCKETINT4 4101 +#define F_BUCKETINT8 4105 +#define F_BUCKETINTERVAL 4121 +#define F_BUCKETNAME 4148 +#define F_BUCKETNUMERIC 4132 +#define F_BUCKETNVARCHAR2 4129 +#define F_BUCKETOID 4134 +#define F_BUCKETOIDVECTOR 4154 +#define F_BUCKETRAW 4144 +#define F_BUCKETRELTIME 4138 +#define F_BUCKETSMALLDATETIME 4127 +#define F_BUCKETTEXT 4152 +#define F_BUCKETTIME 4115 +#define F_BUCKETTIMESTAMP 4117 +#define F_BUCKETTIMESTAMPTZ 4123 +#define F_BUCKETTIMETZ 4119 +#define F_BUCKETUUID 6001 +#define F_BUCKETVARCHAR 4111 +#define F_BYTEA_SORTSUPPORT 3452 +#define F_BYTEA_STRING_AGG_FINALFN 3544 +#define F_BYTEA_STRING_AGG_TRANSFN 3543 +#define F_BYTEACAT 2011 +#define F_BYTEACMP 1954 +#define F_BYTEAEQ 1948 +#define F_BYTEAGE 1952 +#define F_BYTEAGT 1951 +#define F_BYTEAIN 1244 +#define F_BYTEALE 1950 +#define F_BYTEALIKE 2005 +#define F_BYTEALT 1949 +#define F_BYTEANE 1953 +#define F_BYTEANLIKE 2006 +#define F_BYTEAOUT 31 +#define F_BYTEARECV 2412 +#define F_BYTEASEND 2413 +#define F_BYTEAWITHOUTORDERCOLIN 4423 +#define F_BYTEAWITHOUTORDERCOLOUT 4428 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMP 4418 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMPBYTEAL 4463 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLCMPBYTEAR 4456 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQ 4412 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQBYTEAL 4457 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLEQBYTEAR 4447 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLIN 4440 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNE 4417 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNEBYTEAL 4561 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLNEBYTEAR 4460 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLOUT 4446 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLRECV 4444 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLSEND 4451 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLTYPMODIN 4449 +#define F_BYTEAWITHOUTORDERWITHEQUALCOLTYPMODOUT 4450 +#define F_CAPTURE_VIEW_TO_JSON 5719 +#define F_CASH_CMP 377 +#define F_CASH_DIV_CASH 3822 +#define F_CASH_DIV_FLT4 847 +#define F_CASH_DIV_FLT8 897 +#define F_CASH_DIV_INT1 3351 +#define F_CASH_DIV_INT2 867 +#define F_CASH_DIV_INT4 865 +#define F_CASH_DIV_INT8 3345 +#define F_CASH_EQ 888 +#define F_CASH_GE 893 +#define F_CASH_GT 892 +#define F_CASH_IN CASHINFUNCOID +#define F_CASH_LE 891 +#define F_CASH_LT 890 +#define F_CASH_MI 895 +#define F_CASH_MUL_FLT4 846 +#define F_CASH_MUL_FLT8 896 +#define F_CASH_MUL_INT1 3350 +#define F_CASH_MUL_INT2 866 +#define F_CASH_MUL_INT4 864 +#define F_CASH_MUL_INT8 3344 +#define F_CASH_NE 889 +#define F_CASH_OUT CASHOUTFUNCOID +#define F_CASH_PL 894 +#define F_CASH_RECV 2492 +#define F_CASH_SEND 2493 +#define F_CASH_WORDS 935 +#define F_CASHLARGER 898 +#define F_CASHSMALLER 899 +#define F_DCBRT 1345 +#define F_CBTREEBUILD 4240 +#define F_CBTREECANRETURN 4245 +#define F_CBTREECOSTESTIMATE 4243 +#define F_CBTREEGETBITMAP 4246 +#define F_CBTREEGETTUPLE 4242 +#define F_CBTREEOPTIONS 4241 +#define F_NUMERIC_CEIL 1711 +#define F_DCEIL 2308 +#define F_CIRCLE_CENTER 1543 +#define F_CGINBUILD 4400 +#define F_CGINGETBITMAP 4401 +#define F_I4TOCHAR 78 +#define F_TEXT_CHAR 944 +#define F_BPCHARLEN 1372 +#define F_TEXTLEN CHARLENFUNCOID +#define F_CHAREQ 61 +#define F_CHARGE 74 +#define F_CHARGT 73 +#define F_CHARIN 1245 +#define F_CHARLE 72 +#define F_CHARLT 1246 +#define F_CHARNE 70 +#define F_CHAROUT 33 +#define F_CHARRECV 2434 +#define F_CHARSEND 2435 +#define F_CHECKSUMTEXT_AGG_TRANSFN 4601 +#define F_CHR 1621 +#define F_CIDEQ 69 +#define F_CIDIN 52 +#define F_CIDOUT 53 +#define F_INET_TO_CIDR 1715 +#define F_CIDR_IN 1267 +#define F_CIDR_OUT 1427 +#define F_CIDR_RECV 2498 +#define F_CIDR_SEND 2499 +#define F_CIDRECV 2442 +#define F_CIDSEND 2443 +#define F_CR_CIRCLE 1473 +#define F_POLY_CIRCLE 1474 +#define F_BOX_CIRCLE 1479 +#define F_CIRCLE_ABOVE 1461 +#define F_CIRCLE_ADD_PT 1146 +#define F_CIRCLE_BELOW 1460 +#define F_CIRCLE_CONTAIN 1453 +#define F_CIRCLE_CONTAIN_PT 1477 +#define F_CIRCLE_CONTAINED 1458 +#define F_CIRCLE_DISTANCE 1471 +#define F_CIRCLE_DIV_PT 1149 +#define F_CIRCLE_EQ 1462 +#define F_CIRCLE_GE 1467 +#define F_CIRCLE_GT 1465 +#define F_CIRCLE_IN 1450 +#define F_CIRCLE_LE 1466 +#define F_CIRCLE_LEFT 1454 +#define F_CIRCLE_LT 1464 +#define F_CIRCLE_MUL_PT 1148 +#define F_CIRCLE_NE 1463 +#define F_CIRCLE_OUT 1451 +#define F_CIRCLE_OVERABOVE 2588 +#define F_CIRCLE_OVERBELOW 2587 +#define F_CIRCLE_OVERLAP 1459 +#define F_CIRCLE_OVERLEFT 1455 +#define F_CIRCLE_OVERRIGHT 1456 +#define F_CIRCLE_RECV 2490 +#define F_CIRCLE_RIGHT 1457 +#define F_CIRCLE_SAME 1452 +#define F_CIRCLE_SEND 2491 +#define F_CIRCLE_SUB_PT 1147 +#define F_CLOCK_TIMESTAMP 2649 +#define F_CLOSE_LB 963 +#define F_CLOSE_LS 1488 +#define F_CLOSE_LSEG 1489 +#define F_CLOSE_PB 367 +#define F_CLOSE_PL 961 +#define F_CLOSE_PS 366 +#define F_CLOSE_SB 368 +#define F_CLOSE_SL 962 +#define F_COMM_CHECK_CONNECTION_STATUS 1982 +#define F_COMM_CLIENT_INFO 1991 +#define F_COMPLEX_ARRAY_IN 756 +#define F_TEXT_CONCAT CONCATFUNCOID +#define F_TEXT_CONCAT_WS CONCATWSFUNCOID +#define F_CONTJOINSEL 1303 +#define F_CONTSEL 1302 +#define F_PG_CONVERT CONVERTFUNCOID +#define F_PG_CONVERT_FROM CONVERTFROMFUNCOID +#define F_PG_CONVERT_TO CONVERTTOFUNCOID +#define F_PG_CONVERT_TO_NOCASE 3198 +#define F_DCOS COSINEFUNCOID +#define F_DCOT 1607 +#define F_CREATE_WDR_SNAPSHOT 5711 +#define F_CSTORE_TID_OUT 3215 +#define F_CSTRING_IN 2292 +#define F_CSTRING_OUT 2293 +#define F_CSTRING_RECV 2500 +#define F_CSTRING_SEND 2501 +#define F_WINDOW_CUME_DIST 3104 +#define F_CUPOINTER_BIGINT 3217 +#define F_CURRENT_DATABASE CURRENTDATABASEFUNCOID +#define F_CURRENT_QUERY 817 +#define F_CURRENT_SCHEMA CURRENTSCHEMAFUNCOID +#define F_CURRENT_SCHEMAS 1403 +#define F_SHOW_CONFIG_BY_NAME 2077 +#define F_CURRENT_USER CURRENTUSERFUNCOID +#define F_CURRTID_BYRELOID 1293 +#define F_CURRTID_BYRELNAME 1294 +#define F_CURRVAL_OID CURRVALFUNCOID +#define F_CURSOR_TO_XML 2925 +#define F_CURSOR_TO_XMLSCHEMA 2928 +#define F_DATABASE_TO_XML 2936 +#define F_DATABASE_TO_XML_AND_XMLSCHEMA 2938 +#define F_DATABASE_TO_XMLSCHEMA 2937 +#define F_DATALENGTH 8050 +#define F_TIMESTAMPTZ_DATE TIMESTAMPTZ2DATEFUNCOID +#define F_ABSTIME_DATE ABSTIME2DATEFUNCOID +#define F_TIMESTAMP_DATE TIMESTAMP2DATEOID +#define F_DATE_BPCHAR 4160 +#define F_DATE_CMP 1092 +#define F_DATE_CMP_TIMESTAMP 2344 +#define F_DATE_CMP_TIMESTAMPTZ DATECMPTIMESTAMPTZFUNCOID +#define F_DATE_EQ 1086 +#define F_DATE_EQ_TIMESTAMP 2340 +#define F_DATE_EQ_TIMESTAMPTZ DATEEQTIMESTAMPTZFUNCOID +#define F_DATE_GE 1090 +#define F_DATE_GE_TIMESTAMP 2342 +#define F_DATE_GE_TIMESTAMPTZ DATEGETIMESTAMPTZFUNCOID +#define F_DATE_GT 1089 +#define F_DATE_GT_TIMESTAMP 2341 +#define F_DATE_GT_TIMESTAMPTZ DATEGTTIMESTAMPTZFUNCOID +#define F_DATE_IN DATEINFUNCOID +#define F_DATE_LARGER 1138 +#define F_DATE_LE 1088 +#define F_DATE_LE_TIMESTAMP 2339 +#define F_DATE_LE_TIMESTAMPTZ DATELETIMESTAMPTZFUNCOID +#define F_DATE_LIST_AGG_NOARG2_TRANSFN 3581 +#define F_DATE_LIST_AGG_TRANSFN 3579 +#define F_DATE_LT 1087 +#define F_DATE_LT_TIMESTAMP 2338 +#define F_DATE_LT_TIMESTAMPTZ DATELTTIMESTAMPTZFUNCOID +#define F_DATE_MI 1140 +#define F_DATE_MI_INTERVAL 2072 +#define F_DATE_MII 1142 +#define F_DATE_NE 1091 +#define F_DATE_NE_TIMESTAMP 2343 +#define F_DATE_NE_TIMESTAMPTZ DATENETIMESTAMPTZFUNCOID +#define F_DATE_OUT DATEOUTFUNCOID +#define F_TIMESTAMPTZ_PART TIMESTAMPTZPARTFUNCOID +#define F_INTERVAL_PART INTERVALPARTFUNCOID +#define F_TIMETZ_PART TIMEZPARTFUNCOID +#define F_TIME_PART TIMEPARTFUNCOID +#define F_TIMESTAMP_PART TIMESTAMPPARTFUNCOID +#define F_DATE_PL_INTERVAL 2071 +#define F_DATE_PLI 1141 +#define F_DATE_RECV 2468 +#define F_DATE_SEND 2469 +#define F_DATE_SMALLER 1139 +#define F_DATE_SORTSUPPORT 3136 +#define F_DATE_TEXT 4159 +#define F_TIMESTAMPTZ_TRUNC TIMESTAMPTZTRUNCFUNCOID +#define F_INTERVAL_TRUNC INTERVALTRUNCFUNCOID +#define F_TIMESTAMP_TRUNC TIMESTAMPTRUNCFUNCOID +#define F_DATE_VARCHAR 4161 +#define F_RANGE_CONSTRUCTOR2 3941 +#define F_RANGE_CONSTRUCTOR3 3942 +#define F_DATERANGE_CANONICAL 3915 +#define F_DATERANGE_SUBDIFF 3925 +#define F_DATETIME_TIMESTAMP 1272 +#define F_DATETIMETZ_TIMESTAMPTZ 1297 +#define F_BINARY_DECODE 1947 +#define F_PSEUDO_CURRENT_USER 3216 +#define F_DEGREES 1608 +#define F_WINDOW_DELTA 4805 +#define F_WINDOW_DENSE_RANK DENSERANKFUNCOID +#define F_DEXP 233 +#define F_BOX_DIAGONAL 981 +#define F_CIRCLE_DIAMETER 1469 +#define F_DISABLE_CONN 4221 +#define F_DISPELL_INIT 3731 +#define F_DISPELL_LEXIZE 3732 +#define F_DIST_CPOLY 728 +#define F_DIST_LB 726 +#define F_DIST_PB 364 +#define F_DIST_PC 1476 +#define F_DIST_PL 725 +#define F_DIST_PPATH 371 +#define F_DIST_PS 363 +#define F_DIST_SB 365 +#define F_DIST_SL 727 +#define F_NUMERIC_DIV_TRUNC 1973 +#define F_DLOG1 234 +#define F_DLOG10 1339 +#define F_DOMAIN_IN 2597 +#define F_DOMAIN_RECV 2598 +#define F_DPOW 232 +#define F_DROUND 228 +#define F_DSIMPLE_INIT 3725 +#define F_DSIMPLE_LEXIZE 3726 +#define F_DSQRT 230 +#define F_DSYNONYM_INIT 3728 +#define F_DSYNONYM_LEXIZE 3729 +#define F_DTRUNC 229 +#define F_ELEM_CONTAINED_BY_RANGE 3860 +#define F_GET_EMPTY_BLOB 3814 +#define F_BINARY_ENCODE 1946 +#define F_ENUM_CMP 3514 +#define F_ENUM_EQ 3508 +#define F_ENUM_FIRST 3528 +#define F_ENUM_GE 3513 +#define F_ENUM_GT 3511 +#define F_ENUM_IN 3506 +#define F_ENUM_LARGER 3525 +#define F_ENUM_LAST 3529 +#define F_ENUM_LE 3512 +#define F_ENUM_LT 3510 +#define F_ENUM_NE 3509 +#define F_ENUM_OUT 3507 +#define F_ENUM_RANGE_BOUNDS 3530 +#define F_ENUM_RANGE_ALL 3531 +#define F_ENUM_RECV 3532 +#define F_ENUM_SEND 3533 +#define F_ENUM_SMALLER 3524 +#define F_EQJOINSEL 105 +#define F_EQSEL EQSELRETURNOID +#define F_EXEC_HADOOP_SQL ECHADOOPFUNCOID +#define F_EXEC_ON_EXTENSION ECEXTENSIONFUNCOID +#define F_NUMERIC_EXP 1732 +#define F_F4TOI1 5530 +#define F_F8TOI1 5532 +#define F_NUMERIC_FAC 1376 +#define F_NETWORK_FAMILY 711 +#define F_FDW_HANDLER_IN 3116 +#define F_FDW_HANDLER_OUT 3117 +#define F_FENCED_UDF_PROCESS 4207 +#define F_WINDOW_FIRST_VALUE 3112 +#define F_I2TOF 236 +#define F_DTOF 312 +#define F_I4TOF 318 +#define F_I8TOF 652 +#define F_NUMERIC_FLOAT4 1745 +#define F_FLOAT48DIV 280 +#define F_FLOAT48EQ 299 +#define F_FLOAT48GE 304 +#define F_FLOAT48GT 303 +#define F_FLOAT48LE 302 +#define F_FLOAT48LT 301 +#define F_FLOAT48MI 282 +#define F_FLOAT48MUL 279 +#define F_FLOAT48NE 300 +#define F_FLOAT48PL 281 +#define F_FLOAT4_ACCUM 208 +#define F_FLOAT4_BPCHAR 4070 +#define F_FLOAT4_LIST_AGG_NOARG2_TRANSFN 3569 +#define F_FLOAT4_LIST_AGG_TRANSFN 3567 +#define F_FLOAT4_TEXT 4169 +#define F_FLOAT4_VARCHAR 4184 +#define F_FLOAT4DIV 203 +#define F_FLOAT4EQ 287 +#define F_FLOAT4GE 292 +#define F_FLOAT4GT 291 +#define F_FLOAT4IN 200 +#define F_FLOAT4LARGER 209 +#define F_FLOAT4LE 290 +#define F_FLOAT4LT 289 +#define F_FLOAT4MI 205 +#define F_FLOAT4MUL 202 +#define F_FLOAT4NE 288 +#define F_FLOAT4OUT 201 +#define F_FLOAT4PL 204 +#define F_FLOAT4RECV 2424 +#define F_FLOAT4SEND 2425 +#define F_FLOAT4SMALLER 211 +#define F_FLOAT4UM 206 +#define F_FLOAT4UP 1913 +#define F_I2TOD 235 +#define F_FTOD 311 +#define F_I4TOD INT4TOFLOAT8FUNCOID +#define F_I8TOD 482 +#define F_NUMERIC_FLOAT8 NUMTOFLOAT8FUNCOID +#define F_FLOAT84DIV 284 +#define F_FLOAT84EQ 305 +#define F_FLOAT84GE 310 +#define F_FLOAT84GT 309 +#define F_FLOAT84LE 308 +#define F_FLOAT84LT 307 +#define F_FLOAT84MI 286 +#define F_FLOAT84MUL 283 +#define F_FLOAT84NE 306 +#define F_FLOAT84PL 285 +#define F_FLOAT8_ACCUM 222 +#define F_FLOAT8_AVG 1830 +#define F_FLOAT8_BPCHAR 4071 +#define F_FLOAT8_COLLECT 2966 +#define F_FLOAT8_CORR 2817 +#define F_FLOAT8_COVAR_POP 2815 +#define F_FLOAT8_COVAR_SAMP 2816 +#define F_FLOAT8_INTERVAL 4229 +#define F_FLOAT8_LIST_AGG_NOARG2_TRANSFN 3573 +#define F_FLOAT8_LIST_AGG_TRANSFN 3571 +#define F_FLOAT8_REGR_ACCUM 2806 +#define F_FLOAT8_REGR_AVGX 2810 +#define F_FLOAT8_REGR_AVGY 2811 +#define F_FLOAT8_REGR_COLLECT 2995 +#define F_FLOAT8_REGR_INTERCEPT 2814 +#define F_FLOAT8_REGR_R2 2812 +#define F_FLOAT8_REGR_SLOPE 2813 +#define F_FLOAT8_REGR_SXX 2807 +#define F_FLOAT8_REGR_SXY 2809 +#define F_FLOAT8_REGR_SYY 2808 +#define F_FLOAT8_STDDEV_POP 2513 +#define F_FLOAT8_STDDEV_SAMP 1832 +#define F_FLOAT8_TEXT 4170 +#define F_FLOAT8_VAR_POP 2512 +#define F_FLOAT8_VAR_SAMP 1831 +#define F_FLOAT8_VARCHAR 4185 +#define F_FLOAT8DIV 217 +#define F_FLOAT8EQ 293 +#define F_FLOAT8GE 298 +#define F_FLOAT8GT 297 +#define F_FLOAT8IN 214 +#define F_FLOAT8LARGER 223 +#define F_FLOAT8LE 296 +#define F_FLOAT8LT 295 +#define F_FLOAT8MI 219 +#define F_FLOAT8MUL 216 +#define F_FLOAT8NE 294 +#define F_FLOAT8OUT 215 +#define F_FLOAT8PL 218 +#define F_FLOAT8RECV 2426 +#define F_FLOAT8SEND 2427 +#define F_FLOAT8SMALLER 224 +#define F_FLOAT8UM 220 +#define F_FLOAT8UP 1914 +#define F_NUMERIC_FLOOR 1712 +#define F_DFLOOR 2309 +#define F_FLT4_MUL_CASH 848 +#define F_FLT8_MUL_CASH 919 +#define F_FMGR_C_VALIDATOR 2247 +#define F_FMGR_INTERNAL_VALIDATOR 2246 +#define F_FMGR_SQL_VALIDATOR 2248 +#define F_TEXT_FORMAT ANYTOTEXTFORMATFUNCOID +#define F_TEXT_FORMAT_NV DEFAULTFORMATFUNCOID +#define F_FORMAT_TYPE 1081 +#define F_GENERATE_SERIES_TIMESTAMP 938 +#define F_GENERATE_SERIES_TIMESTAMPTZ GENERATESERIESFUNCOID +#define F_GENERATE_SERIES_STEP_INT4 1066 +#define F_GENERATE_SERIES_INT4 1067 +#define F_GENERATE_SERIES_STEP_INT8 1068 +#define F_GENERATE_SERIES_INT8 1069 +#define F_GENERATE_SERIES_STEP_NUMERIC 1070 +#define F_GENERATE_SERIES_NUMERIC 1071 +#define F_GENERATE_SUBSCRIPTS 1191 +#define F_GENERATE_SUBSCRIPTS_NODIR 1192 +#define F_GENERATE_WDR_REPORT 5703 +#define F_BYTEAGETBIT 723 +#define F_BITGETBIT 3032 +#define F_BYTEAGETBYTE 721 +#define F_GET_CURRENT_TS_CONFIG 3759 +#define F_GET_DB_SOURCE_DATASIZE 4208 +#define F_GET_GTM_LITE_STATUS 5999 +#define F_GET_HOSTNAME 3977 +#define F_GET_INSTR_RT_PERCENTILE 5712 +#define F_GET_INSTR_UNIQUE_SQL 5702 +#define F_GET_INSTR_USER_LOGIN 5706 +#define F_GET_INSTR_WAIT_EVENT 5705 +#define F_GET_INSTR_WORKLOAD_INFO 5000 +#define F_GET_LOCAL_ACTIVE_SESSION 5721 +#define F_GET_LOCAL_PREPARED_XACT 3332 +#define F_GET_LOCAL_REL_IOSTAT 5708 +#define F_GET_NODE_STAT_RESET_TIME 5720 +#define F_PG_GET_NODENAME 5015 +#define F_GET_PREPARED_PENDING_XID 3199 +#define F_GET_REMOTE_PREPARED_XACTS 3333 +#define F_GET_SCHEMA_OID 3953 +#define F_GET_WAIT_EVENT_INFO 5723 +#define F_GETBUCKET 4046 +#define F_GETDATABASEENCODING 1039 +#define F_GETDISTRIBUTEKEY 4047 +#define F_GIN_CLEAN_PENDING_LIST 3989 +#define F_GIN_CMP_PREFIX 2700 +#define F_GIN_CMP_TSLEXEME 3724 +#define F_GIN_EXTRACT_TSQUERY_5ARGS 3087 +#define F_GIN_EXTRACT_TSQUERY 3657 +#define F_GIN_EXTRACT_TSVECTOR_2ARGS 3077 +#define F_GIN_EXTRACT_TSVECTOR 3656 +#define F_GIN_TSQUERY_CONSISTENT_6ARGS 3088 +#define F_GIN_TSQUERY_CONSISTENT 3658 +#define F_GIN_TSQUERY_TRICONSISTENT 3921 +#define F_GINARRAYCONSISTENT 2744 +#define F_GINARRAYEXTRACT 2743 +#define F_GINARRAYEXTRACT_2ARGS 3076 +#define F_GINARRAYTRICONSISTENT 3920 +#define F_GINBEGINSCAN 2733 +#define F_GINBUILD 2738 +#define F_GINBUILDEMPTY 325 +#define F_GINBULKDELETE 2739 +#define F_GINCOSTESTIMATE 2741 +#define F_GINENDSCAN 2735 +#define F_GINGETBITMAP 2731 +#define F_GININSERT 2732 +#define F_GINMARKPOS 2736 +#define F_GINMERGE 3186 +#define F_GINOPTIONS 2788 +#define F_GINQUERYARRAYEXTRACT 2774 +#define F_GINRESCAN 2734 +#define F_GINRESTRPOS 2737 +#define F_GINVACUUMCLEANUP 2740 +#define F_GIST_BOX_COMPRESS 2579 +#define F_GIST_BOX_CONSISTENT 2578 +#define F_GIST_BOX_DECOMPRESS 2580 +#define F_GIST_BOX_PENALTY 2581 +#define F_GIST_BOX_PICKSPLIT 2582 +#define F_GIST_BOX_SAME 2584 +#define F_GIST_BOX_UNION 2583 +#define F_GIST_CIRCLE_COMPRESS 2592 +#define F_GIST_CIRCLE_CONSISTENT 2591 +#define F_GIST_POINT_COMPRESS 1030 +#define F_GIST_POINT_CONSISTENT 2179 +#define F_GIST_POINT_DISTANCE 3064 +#define F_GIST_POLY_COMPRESS 2586 +#define F_GIST_POLY_CONSISTENT 2585 +#define F_GISTBEGINSCAN 777 +#define F_GISTBUILD 782 +#define F_GISTBUILDEMPTY 326 +#define F_GISTBULKDELETE 776 +#define F_GISTCOSTESTIMATE 772 +#define F_GISTENDSCAN 779 +#define F_GISTGETBITMAP 638 +#define F_GISTGETTUPLE 774 +#define F_GISTINSERT 775 +#define F_GISTMARKPOS 780 +#define F_GISTMERGE 3187 +#define F_GISTOPTIONS 2787 +#define F_GISTRESCAN 778 +#define F_GISTRESTRPOS 781 +#define F_GISTVACUUMCLEANUP 2561 +#define F_GLOBAL_CLEAN_PREPARED_XACTS 3334 +#define F_GLOBAL_COMM_GET_CLIENT_INFO 1992 +#define F_GLOBAL_COMM_GET_RECV_STREAM 1988 +#define F_GLOBAL_COMM_GET_SEND_STREAM 1989 +#define F_GLOBAL_COMM_GET_STATUS 1990 +#define F_GLOBAL_STAT_CLEAN_HOTKEYS 3900 +#define F_GLOBAL_STAT_GET_HOTKEYS_INFO 3903 +#define F_GS_ALL_CONTROL_GROUP_INFO 4502 +#define F_GS_ALL_NODEGROUP_CONTROL_GROUP_INFO 4504 +#define F_GS_CGROUP_MAP_NG_CONF 4503 +#define F_GS_CONTROL_GROUP_INFO 4500 +#define F_GS_DECRYPT_AES128 3465 +#define F_GS_ENCRYPT_AES128 GSENCRYPTAES128FUNCOID +#define F_GS_EXTEND_LIBRARY 4210 +#define F_GS_FAULT_INJECT 4000 +#define F_GS_GET_GLOBAL_BARRIER_STATUS 9032 +#define F_GS_GET_LOCAL_BARRIER_STATUS 9033 +#define F_GS_GET_NEXT_XID_CSN 6224 +#define F_GS_GET_NODEGROUP_TABLECOUNT 5027 +#define F_GS_INDEX_ADVISE 4888 +#define F_GS_PASSWORD_DEADLINE 3469 +#define F_GS_PASSWORD_NOTIFYTIME 3470 +#define F_GS_RESPOOL_EXCEPTION_INFO 4501 +#define F_GS_SET_OBS_DELETE_LOCATION 9031 +#define F_GS_STAT_ACTIVITY_TIMEOUT 4520 +#define F_GS_STAT_CLEAN_HOTKEYS 3805 +#define F_GS_STAT_GET_HOTKEYS_INFO 3803 +#define F_PG_SWITCH_RELFILENODE_NAME 4049 +#define F_GS_TOTAL_NODEGROUP_MEMORY_DETAIL 2847 +#define F_PG_STAT_GET_RESOURCE_POOL_INFO 5004 +#define F_PG_WLM_GET_SESSION_INFO 5009 +#define F_PG_STAT_GET_WLM_USER_INFO 5007 +#define F_PG_WLM_GET_USER_SESSION_INFO 5020 +#define F_PG_STAT_GET_WORKLOAD_RECORDS 5018 +#define F_GS_WLM_NODE_CLEAN 5016 +#define F_GS_WLM_NODE_RECOVER 5017 +#define F_GS_WLM_READJUST_USER_SPACE 5011 +#define F_GS_WLM_READJUST_USER_SPACE_THROUGH_USERNAME 5030 +#define F_GS_WLM_READJUST_USER_SPACE_WITH_RESET_FLAG 5029 +#define F_GS_WLM_REBUILD_USER_RESOURCE_POOL 5006 +#define F_PG_STAT_GET_SESSION_RESPOOL 5021 +#define F_GS_WLM_SWITCH_CGROUP 5005 +#define F_PG_STAT_GET_WLM_USER_RESOURCE_INFO 5012 +#define F_GTSQUERY_COMPRESS 3695 +#define F_GTSQUERY_CONSISTENT 3701 +#define F_GTSQUERY_DECOMPRESS 3696 +#define F_GTSQUERY_PENALTY 3700 +#define F_GTSQUERY_PICKSPLIT 3697 +#define F_GTSQUERY_SAME 3699 +#define F_GTSQUERY_UNION 3698 +#define F_GTSVECTOR_COMPRESS 3648 +#define F_GTSVECTOR_CONSISTENT 3654 +#define F_GTSVECTOR_DECOMPRESS 3649 +#define F_GTSVECTOR_PENALTY 3653 +#define F_GTSVECTOR_PICKSPLIT 3650 +#define F_GTSVECTOR_SAME 3652 +#define F_GTSVECTOR_UNION 3651 +#define F_GTSVECTORIN 3646 +#define F_GTSVECTOROUT 3647 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME_NAME 3024 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME_ID 3025 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID_NAME 3026 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID_ID 3027 +#define F_HAS_ANY_COLUMN_PRIVILEGE_NAME 3028 +#define F_HAS_ANY_COLUMN_PRIVILEGE_ID 3029 +#define F_HAS_CEK_PRIVILEGE_NAME_NAME 9130 +#define F_HAS_CEK_PRIVILEGE_NAME_ID 9131 +#define F_HAS_CEK_PRIVILEGE_ID_NAME 9132 +#define F_HAS_CEK_PRIVILEGE_ID_ID 9133 +#define F_HAS_CEK_PRIVILEGE_NAME 9134 +#define F_HAS_CEK_PRIVILEGE_ID 9135 +#define F_HAS_CMK_PRIVILEGE_NAME_NAME 9024 +#define F_HAS_CMK_PRIVILEGE_NAME_ID 9025 +#define F_HAS_CMK_PRIVILEGE_ID_NAME 9026 +#define F_HAS_CMK_PRIVILEGE_ID_ID 9027 +#define F_HAS_CMK_PRIVILEGE_NAME 9028 +#define F_HAS_CMK_PRIVILEGE_ID 9029 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME_NAME 3012 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME_ATTNUM 3013 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ID_NAME 3014 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ID_ATTNUM 3015 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME_NAME 3016 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME_ATTNUM 3017 +#define F_HAS_COLUMN_PRIVILEGE_ID_ID_NAME 3018 +#define F_HAS_COLUMN_PRIVILEGE_ID_ID_ATTNUM 3019 +#define F_HAS_COLUMN_PRIVILEGE_NAME_NAME 3020 +#define F_HAS_COLUMN_PRIVILEGE_NAME_ATTNUM 3021 +#define F_HAS_COLUMN_PRIVILEGE_ID_NAME 3022 +#define F_HAS_COLUMN_PRIVILEGE_ID_ATTNUM 3023 +#define F_HAS_DATABASE_PRIVILEGE_NAME_NAME 2250 +#define F_HAS_DATABASE_PRIVILEGE_NAME_ID 2251 +#define F_HAS_DATABASE_PRIVILEGE_ID_NAME 2252 +#define F_HAS_DATABASE_PRIVILEGE_ID_ID 2253 +#define F_HAS_DATABASE_PRIVILEGE_NAME 2254 +#define F_HAS_DATABASE_PRIVILEGE_ID 2255 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME_NAME 4700 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME_ID 4701 +#define F_HAS_DIRECTORY_PRIVILEGE_ID_NAME 4702 +#define F_HAS_DIRECTORY_PRIVILEGE_ID_ID 4703 +#define F_HAS_DIRECTORY_PRIVILEGE_NAME 4704 +#define F_HAS_DIRECTORY_PRIVILEGE_ID 4705 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME_NAME 3000 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME_ID 3001 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID_NAME 3002 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID_ID 3003 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_NAME 3004 +#define F_HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE_ID 3005 +#define F_HAS_FUNCTION_PRIVILEGE_NAME_NAME 2256 +#define F_HAS_FUNCTION_PRIVILEGE_NAME_ID 2257 +#define F_HAS_FUNCTION_PRIVILEGE_ID_NAME 2258 +#define F_HAS_FUNCTION_PRIVILEGE_ID_ID 2259 +#define F_HAS_FUNCTION_PRIVILEGE_NAME 2260 +#define F_HAS_FUNCTION_PRIVILEGE_ID 2261 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME_NAME 2262 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME_ID 2263 +#define F_HAS_LANGUAGE_PRIVILEGE_ID_NAME 2264 +#define F_HAS_LANGUAGE_PRIVILEGE_ID_ID 2265 +#define F_HAS_LANGUAGE_PRIVILEGE_NAME 2266 +#define F_HAS_LANGUAGE_PRIVILEGE_ID 2267 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME_NAME 4201 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME_ID 4202 +#define F_HAS_NODEGROUP_PRIVILEGE_ID_NAME 4203 +#define F_HAS_NODEGROUP_PRIVILEGE_ID_ID 4204 +#define F_HAS_NODEGROUP_PRIVILEGE_NAME 4205 +#define F_HAS_NODEGROUP_PRIVILEGE_ID 4206 +#define F_HAS_SCHEMA_PRIVILEGE_NAME_NAME 2268 +#define F_HAS_SCHEMA_PRIVILEGE_NAME_ID 2269 +#define F_HAS_SCHEMA_PRIVILEGE_ID_NAME 2270 +#define F_HAS_SCHEMA_PRIVILEGE_ID_ID 2271 +#define F_HAS_SCHEMA_PRIVILEGE_NAME 2272 +#define F_HAS_SCHEMA_PRIVILEGE_ID 2273 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME_NAME 2181 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME_ID 2182 +#define F_HAS_SEQUENCE_PRIVILEGE_ID_NAME 2183 +#define F_HAS_SEQUENCE_PRIVILEGE_ID_ID 2184 +#define F_HAS_SEQUENCE_PRIVILEGE_NAME 2185 +#define F_HAS_SEQUENCE_PRIVILEGE_ID 2186 +#define F_HAS_SERVER_PRIVILEGE_NAME_NAME 3006 +#define F_HAS_SERVER_PRIVILEGE_NAME_ID 3007 +#define F_HAS_SERVER_PRIVILEGE_ID_NAME 3008 +#define F_HAS_SERVER_PRIVILEGE_ID_ID 3009 +#define F_HAS_SERVER_PRIVILEGE_NAME 3010 +#define F_HAS_SERVER_PRIVILEGE_ID 3011 +#define F_HAS_TABLE_PRIVILEGE_NAME_NAME 1922 +#define F_HAS_TABLE_PRIVILEGE_NAME_ID 1923 +#define F_HAS_TABLE_PRIVILEGE_ID_NAME 1924 +#define F_HAS_TABLE_PRIVILEGE_ID_ID 1925 +#define F_HAS_TABLE_PRIVILEGE_NAME 1926 +#define F_HAS_TABLE_PRIVILEGE_ID 1927 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME_NAME 2390 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME_ID 2391 +#define F_HAS_TABLESPACE_PRIVILEGE_ID_NAME 2392 +#define F_HAS_TABLESPACE_PRIVILEGE_ID_ID 2393 +#define F_HAS_TABLESPACE_PRIVILEGE_NAME 2394 +#define F_HAS_TABLESPACE_PRIVILEGE_ID 2395 +#define F_HAS_TYPE_PRIVILEGE_NAME_NAME 3138 +#define F_HAS_TYPE_PRIVILEGE_NAME_ID 3139 +#define F_HAS_TYPE_PRIVILEGE_ID_NAME 3140 +#define F_HAS_TYPE_PRIVILEGE_ID_ID 3141 +#define F_HAS_TYPE_PRIVILEGE_NAME 3142 +#define F_HAS_TYPE_PRIVILEGE_ID 3143 +#define F_HASH_ACLITEM 329 +#define F_HASH_ARRAY 626 +#define F_HASH_NUMERIC 432 +#define F_HASH_RANGE 3902 +#define F_HASHBEGINSCAN 443 +#define F_HASHBPCHAR HASHBPCHAROID +#define F_HASHBUILD 448 +#define F_HASHBUILDEMPTY 327 +#define F_HASHBULKDELETE 442 +#define F_HASHCHAR 454 +#define F_HASHCOSTESTIMATE 438 +#define F_HASHENDSCAN 445 +#define F_HASHENUM 3515 +#define F_HASHFLOAT4 451 +#define F_HASHFLOAT8 452 +#define F_HASHGETBITMAP 637 +#define F_HASHGETTUPLE 440 +#define F_HASHINET 422 +#define F_HASHINSERT 441 +#define F_HASHINT1 5520 +#define F_HASHINT2 449 +#define F_HASHINT2VECTOR 398 +#define F_HASHINT4 HASHINT4OID +#define F_HASHINT8 HASHINT8OID +#define F_HASHMACADDR 399 +#define F_HASHMARKPOS 446 +#define F_HASHMERGE 3185 +#define F_HASHNAME 455 +#define F_HASHOID 453 +#define F_HASHOIDVECTOR 457 +#define F_HASHOPTIONS 2786 +#define F_HASHRESCAN 444 +#define F_HASHRESTRPOS 447 +#define F_HASHTEXT HASHTEXTOID +#define F_HASHVACUUMCLEANUP 425 +#define F_HASHVARLENA 456 +#define F_BOX_HEIGHT 977 +#define F_TEXTTORAW 4038 +#define F_HLL 4311 +#define F_HLL_ADD 4322 +#define F_HLL_ADD_REV 4323 +#define F_HLL_ADD_TRANS0 4351 +#define F_HLL_ADD_TRANS1 4336 +#define F_HLL_ADD_TRANS2 4337 +#define F_HLL_ADD_TRANS3 4338 +#define F_HLL_ADD_TRANS4 4360 +#define F_HLL_CARDINALITY 4320 +#define F_HLL_EMPTY0 4325 +#define F_HLL_EMPTY1 4326 +#define F_HLL_EMPTY2 4327 +#define F_HLL_EMPTY3 4328 +#define F_HLL_EMPTY4 4329 +#define F_HLL_EQ 4318 +#define F_HLL_EXPTHRESH 4334 +#define F_HLL_HASH_ANY 4345 +#define F_HLL_HASH_ANYS 4359 +#define F_HLL_HASH_8BYTE 4342 +#define F_HLL_HASH_8BYTES 4356 +#define F_HLL_HASH_1BYTE 4339 +#define F_HLL_HASH_1BYTES 4353 +#define F_HLL_HASH_VARLENA 4343 +#define F_HLL_HASH_VARLENAS 4357 +#define F_HLL_HASH_4BYTE 4341 +#define F_HLL_HASH_4BYTES 4355 +#define F_HLL_HASH_2BYTE 4340 +#define F_HLL_HASH_2BYTES 4354 +#define F_HLL_HASHVAL 4316 +#define F_HLL_HASHVAL_EQ 4314 +#define F_HLL_HASHVAL_IN 4312 +#define F_HLL_HASHVAL_INT4 4317 +#define F_HLL_HASHVAL_NE 4315 +#define F_HLL_HASHVAL_OUT 4313 +#define F_HLL_IN 4305 +#define F_HLL_LOG2M 4332 +#define F_HLL_NE 4319 +#define F_HLL_OUT 4306 +#define F_HLL_PACK 4352 +#define F_HLL_PRINT 4324 +#define F_HLL_RECV 4307 +#define F_HLL_REGWIDTH 4333 +#define F_HLL_SCHEMA_VERSION 4330 +#define F_HLL_SEND 4308 +#define F_HLL_SPARSEON 4335 +#define F_HLL_TRANS_IN 4364 +#define F_HLL_TRANS_OUT 4365 +#define F_HLL_TRANS_RECV 4362 +#define F_HLL_TRANS_SEND 4363 +#define F_HLL_TYPE 4331 +#define F_HLL_TYPMOD_IN 4309 +#define F_HLL_TYPMOD_OUT 4310 +#define F_HLL_UNION 4321 +#define F_HLL_UNION_COLLECT 4348 +#define F_HLL_UNION_TRANS 4346 +#define F_NETWORK_HOST 699 +#define F_NETWORK_HOSTMASK 1362 +#define F_HYPOPG_CREATE_INDEX 4889 +#define F_HYPOPG_DISPLAY_INDEX 4890 +#define F_HYPOPG_DROP_INDEX 4891 +#define F_HYPOPG_ESTIMATE_SIZE 4892 +#define F_HYPOPG_RESET_INDEX 4893 +#define F_I1TOF4 5529 +#define F_I1TOF8 5531 +#define F_I1TOI2 5523 +#define F_I1TOI4 5525 +#define F_I1TOI8 5527 +#define F_I2TOI1 5524 +#define F_I4TOI1 5526 +#define F_I8TOI1 5528 +#define F_ICLIKEJOINSEL 1816 +#define F_ICLIKESEL 1814 +#define F_ICNLIKEJOINSEL 1817 +#define F_ICNLIKESEL 1815 +#define F_ICREGEXEQJOINSEL 1826 +#define F_ICREGEXEQSEL 1820 +#define F_ICREGEXNEJOINSEL 1829 +#define F_ICREGEXNESEL 1823 +#define F_INET_CLIENT_ADDR 2196 +#define F_INET_CLIENT_PORT 2197 +#define F_INET_IN 910 +#define F_INET_OUT 911 +#define F_INET_RECV 2496 +#define F_INET_SEND 2497 +#define F_INET_SERVER_ADDR 2198 +#define F_INET_SERVER_PORT 2199 +#define F_INETAND 2628 +#define F_INETMI 2633 +#define F_INETMI_INT8 2632 +#define F_INETNOT 2627 +#define F_INETOR 2629 +#define F_INETPL 2630 +#define F_INITCAP 872 +#define F_TEXTPOS INSTR2FUNCOID +#define F_INSTR_3ARGS INSTR3FUNCOID +#define F_INSTR_4ARGS INSTR4FUNCOID +#define F_INT1_AVG_ACCUM 5548 +#define F_INT1_BOOL 5533 +#define F_INT1_BPCHAR 4067 +#define F_INT1_MUL_CASH 3348 +#define F_INT1_NUMERIC 5521 +#define F_INT1_NVARCHAR2 4066 +#define F_INT1_TEXT 4165 +#define F_INT1_VARCHAR 4065 +#define F_INT1ABS 6113 +#define F_INT1AND 6101 +#define F_INT1CMP 5519 +#define F_INT1DIV 6112 +#define F_INT1EQ 5547 +#define F_INT1GE 5512 +#define F_INT1GT 5511 +#define F_INT1IN 5541 +#define F_INT1INC 6117 +#define F_INT1LARGER 6115 +#define F_INT1LE 5510 +#define F_INT1LT 5509 +#define F_INT1MI 6110 +#define F_INT1MOD 6114 +#define F_INT1MUL 6111 +#define F_INT1NE 5508 +#define F_INT1NOT 6104 +#define F_INT1OR 6102 +#define F_INT1OUT 5542 +#define F_INT1PL 6109 +#define F_INT1RECV 5543 +#define F_INT1SEND 5544 +#define F_INT1SHL 6105 +#define F_INT1SHR 6106 +#define F_INT1SMALLER 6116 +#define F_INT1UM 6108 +#define F_INT1UP 6107 +#define F_INT1XOR 6103 +#define F_DTOI2 237 +#define F_FTOI2 238 +#define F_I4TOI2 314 +#define F_INT82 714 +#define F_NUMERIC_INT2 1783 +#define F_INT24DIV 172 +#define F_INT24EQ 158 +#define F_INT24GE 168 +#define F_INT24GT 162 +#define F_INT24LE 166 +#define F_INT24LT 160 +#define F_INT24MI 182 +#define F_INT24MUL 170 +#define F_INT24NE 164 +#define F_INT24PL 178 +#define F_INT28DIV 948 +#define F_INT28EQ 1850 +#define F_INT28GE 1855 +#define F_INT28GT 1853 +#define F_INT28LE 1854 +#define F_INT28LT 1852 +#define F_INT28MI 942 +#define F_INT28MUL 943 +#define F_INT28NE 1851 +#define F_INT28PL 841 +#define F_INT2_ACCUM 1834 +#define F_INT2_AVG_ACCUM 1962 +#define F_INT2_BOOL 3180 +#define F_INT2_BPCHAR 4068 +#define F_INT2_LIST_AGG_NOARG2_TRANSFN 3557 +#define F_INT2_LIST_AGG_TRANSFN 3555 +#define F_INT2_MUL_CASH 863 +#define F_INT2_SUM 1840 +#define F_INT2_TEXT 4166 +#define F_INT2_VARCHAR 4180 +#define F_INT2AND 1892 +#define F_INT2DIV 153 +#define F_INT2EQ 63 +#define F_INT2GE 151 +#define F_INT2GT 146 +#define F_INT2IN 38 +#define F_INT2LARGER 770 +#define F_INT2LE 148 +#define F_INT2LT 64 +#define F_INT2MI 180 +#define F_INT2MOD 155 +#define F_INT2MUL 152 +#define F_INT2NE 145 +#define F_INT2NOT 1895 +#define F_INT2OR 1893 +#define F_INT2OUT 39 +#define F_INT2PL 176 +#define F_INT2RECV 2404 +#define F_INT2SEND 2405 +#define F_INT2SHL 1896 +#define F_INT2SHR 1897 +#define F_INT2SMALLER 771 +#define F_INT2UM 213 +#define F_INT2UP 1911 +#define F_INT2VECTOREQ 315 +#define F_INT2VECTORIN 40 +#define F_INT2VECTOROUT 41 +#define F_INT2VECTORRECV 2410 +#define F_INT2VECTORSEND 2411 +#define F_INT2XOR 1894 +#define F_CHARTOI4 77 +#define F_I2TOI4 313 +#define F_DTOI4 317 +#define F_FTOI4 319 +#define F_INT84 480 +#define F_BITTOINT4 1684 +#define F_NUMERIC_INT4 1744 +#define F_BOOL_INT4 2558 +#define F_INT42DIV 173 +#define F_INT42EQ 159 +#define F_INT42GE 169 +#define F_INT42GT 163 +#define F_INT42LE 167 +#define F_INT42LT 161 +#define F_INT42MI 183 +#define F_INT42MUL 171 +#define F_INT42NE 165 +#define F_INT42PL 179 +#define F_INT48DIV 1281 +#define F_INT48EQ 852 +#define F_INT48GE 857 +#define F_INT48GT 855 +#define F_INT48LE 856 +#define F_INT48LT 854 +#define F_INT48MI 1279 +#define F_INT48MUL 1280 +#define F_INT48NE 853 +#define F_INT48PL 1278 +#define F_INT4_ACCUM 1835 +#define F_INT4_AVG_ACCUM 1963 +#define F_INT4_BPCHAR 3192 +#define F_INT4_LIST_AGG_NOARG2_TRANSFN 3561 +#define F_INT4_LIST_AGG_TRANSFN 3559 +#define F_INT4_MUL_CASH 862 +#define F_INT4_SUM 1841 +#define F_INT4_TEXT 4167 +#define F_INT4_VARCHAR 4181 +#define F_INT4AND 1898 +#define F_INT4DIV 154 +#define F_INT4EQ 65 +#define F_INT4GE 150 +#define F_INT4GT 147 +#define F_INT4IN 42 +#define F_INT4INC 766 +#define F_INT4LARGER 768 +#define F_INT4LE 149 +#define F_INT4LT 66 +#define F_INT4MI 181 +#define F_INT4MOD 156 +#define F_INT4MUL 141 +#define F_INT4NE 144 +#define F_INT4NOT 1901 +#define F_INT4OR 1899 +#define F_INT4OUT 43 +#define F_INT4PL 177 +#define F_INT4RANGE_CANONICAL 3914 +#define F_INT4RANGE_SUBDIFF 3922 +#define F_INT4RECV 2406 +#define F_INT4SEND 2407 +#define F_INT4SHL 1902 +#define F_INT4SHR 1903 +#define F_INT4SMALLER 769 +#define F_INT4UM 212 +#define F_INT4UP 1912 +#define F_INT4XOR 1900 +#define F_INT48 481 +#define F_DTOI8 483 +#define F_FTOI8 653 +#define F_INT28 754 +#define F_OIDTOI8 1288 +#define F_NUMERIC_INT8 1779 +#define F_BITTOINT8 2076 +#define F_INT82DIV 840 +#define F_INT82EQ 1856 +#define F_INT82GE 1861 +#define F_INT82GT 1859 +#define F_INT82LE 1860 +#define F_INT82LT 1858 +#define F_INT82MI 838 +#define F_INT82MUL 839 +#define F_INT82NE 1857 +#define F_INT82PL 837 +#define F_INT84DIV 1277 +#define F_INT84EQ 474 +#define F_INT84GE 479 +#define F_INT84GT 477 +#define F_INT84LE 478 +#define F_INT84LT 476 +#define F_INT84MI 1275 +#define F_INT84MUL 1276 +#define F_INT84NE 475 +#define F_INT84PL 1274 +#define F_INT8_ACCUM 1836 +#define F_INT8_AVG 1964 +#define F_INT8_AVG_ACCUM 2746 +#define F_INT8_AVG_COLLECT 2965 +#define F_INT8_BOOL 3177 +#define F_INT8_BPCHAR 4069 +#define F_INT8_LIST_AGG_NOARG2_TRANSFN 3565 +#define F_INT8_LIST_AGG_TRANSFN 3563 +#define F_INT8_MUL_CASH 3343 +#define F_INT8_SUM 1842 +#define F_INT8_SUM_TO_INT8 2996 +#define F_INT8_TEXT 4168 +#define F_INT8_VARCHAR 4182 +#define F_INT8AND 1904 +#define F_INT8DIV 466 +#define F_INT8EQ 467 +#define F_INT8GE 472 +#define F_INT8GT 470 +#define F_INT8IN 460 +#define F_INT8INC 1219 +#define F_INT8INC_ANY 2804 +#define F_INT8INC_FLOAT8_FLOAT8 2805 +#define F_INT8LARGER 1236 +#define F_INT8LE 471 +#define F_INT8LT 469 +#define F_INT8MI 464 +#define F_INT8MOD 945 +#define F_INT8MUL 465 +#define F_INT8NE 468 +#define F_INT8NOT 1907 +#define F_INT8OR 1905 +#define F_INT8OUT 461 +#define F_INT8PL 463 +#define F_INT8RANGE_CANONICAL 3928 +#define F_INT8RANGE_SUBDIFF 3923 +#define F_INT8RECV 2408 +#define F_INT8SEND 2409 +#define F_INT8SHL 1908 +#define F_INT8SHR 1909 +#define F_INT8SMALLER 1237 +#define F_INT8UM 462 +#define F_INT8UP 1910 +#define F_INT8XOR 1906 +#define F_INTER_LB 278 +#define F_INTER_SB 373 +#define F_INTER_SL 277 +#define F_INTERNAL_IN 2304 +#define F_INTERNAL_OUT 2305 +#define F_RELTIME_INTERVAL 1177 +#define F_INTERVAL_SCALE 1200 +#define F_TIME_INTERVAL 1370 +#define F_INTERVAL_ACCUM INTERVALACCUMFUNCOID +#define F_INTERVAL_AVG INTERVALAVGFUNCOID +#define F_INTERVAL_CMP 1315 +#define F_INTERVAL_COLLECT 2967 +#define F_INTERVAL_DIV 1326 +#define F_INTERVAL_EQ 1162 +#define F_INTERVAL_GE 1166 +#define F_INTERVAL_GT 1167 +#define F_INTERVAL_HASH 1697 +#define F_INTERVAL_IN INTERVALINFUNCOID +#define F_INTERVAL_LARGER 1198 +#define F_INTERVAL_LE 1165 +#define F_INTERVAL_LIST_AGG_NOARG2_TRANSFN 4507 +#define F_INTERVAL_LIST_AGG_TRANSFN 4505 +#define F_INTERVAL_LT 1164 +#define F_INTERVAL_MI 1170 +#define F_INTERVAL_MUL 1618 +#define F_INTERVAL_NE 1163 +#define F_INTERVAL_OUT 1161 +#define F_INTERVAL_PL 1169 +#define F_INTERVAL_RECV 2478 +#define F_INTERVAL_SEND 2479 +#define F_INTERVAL_SMALLER 1197 +#define F_INTERVAL_TRANSFORM 3918 +#define F_INTERVAL_UM 1168 +#define F_INTERVALTYPMODIN 2903 +#define F_INTERVALTYPMODOUT 2904 +#define F_INTINTERVAL 248 +#define F_PATH_ISCLOSED 1430 +#define F_RANGE_EMPTY 3850 +#define F_ABSTIME_FINITE 275 +#define F_DATE_FINITE 1373 +#define F_TIMESTAMP_FINITE 1389 +#define F_INTERVAL_FINITE 1390 +#define F_POINT_HORIZ 1407 +#define F_LSEG_HORIZONTAL 1411 +#define F_LINE_HORIZONTAL 1415 +#define F_PATH_ISOPEN 1431 +#define F_LSEG_PARALLEL 1408 +#define F_LINE_PARALLEL 1412 +#define F_LSEG_PERP 1409 +#define F_LINE_PERP 1413 +#define F_ISUBMIT_JOB_ON_NODES 5718 +#define F_ISUBMIT_JOB_ON_NODES_INTERNAL 6007 +#define F_POINT_VERT 1406 +#define F_LSEG_VERTICAL 1410 +#define F_LINE_VERTICAL 1414 +#define F_JOB_CANCEL 4800 +#define F_JOB_FINISH 4801 +#define F_JOB_SUBMIT 4802 +#define F_JOB_UPDATE 4803 +#define F_JSON_IN 321 +#define F_JSON_OUT 322 +#define F_JSON_RECV 323 +#define F_JSON_SEND 324 +#define F_INTERVAL_JUSTIFY_DAYS 1295 +#define F_INTERVAL_JUSTIFY_HOURS 1175 +#define F_INTERVAL_JUSTIFY_INTERVAL 2711 +#define F_KILL_SNAPSHOT 5714 +#define F_WINDOW_LAG 3106 +#define F_WINDOW_LAG_WITH_OFFSET 3107 +#define F_WINDOW_LAG_WITH_OFFSET_AND_DEFAULT 3108 +#define F_LANGUAGE_HANDLER_IN 2302 +#define F_LANGUAGE_HANDLER_OUT 2303 +#define F_LAST_DAY 4075 +#define F_WINDOW_LAST_VALUE 3113 +#define F_LASTVAL LASTVALFUNCOID +#define F_WINDOW_LEAD 3109 +#define F_WINDOW_LEAD_WITH_OFFSET 3110 +#define F_WINDOW_LEAD_WITH_OFFSET_AND_DEFAULT 3111 +#define F_TEXT_LEFT 3060 +#define F_LSEG_LENGTH 1530 +#define F_PATH_LENGTH 1531 +#define F_BITLENGTH 1681 +#define F_LENGTH_IN_ENCODING 1713 +#define F_BYTEAOCTETLEN 2010 +#define F_TSVECTOR_LENGTH 3711 +#define F_TEXTOCTETLEN TEXTOCTLENFUNCOID +#define F_BPCHARLENB BPOCTLENFUNCOID +#define F_NAMELIKE 1571 +#define F_LIKE_ESCAPE 1637 +#define F_LIKE_ESCAPE_BYTEA 2009 +#define F_LIKEJOINSEL 1825 +#define F_LIKESEL 1819 +#define F_LINE_CONSTRUCT_PP 1493 +#define F_LINE_DISTANCE 239 +#define F_LINE_EQ 1492 +#define F_LINE_IN 1490 +#define F_LINE_INTERPT 1494 +#define F_LINE_INTERSECT 1495 +#define F_LINE_OUT 1491 +#define F_LINE_RECV 2488 +#define F_LINE_SEND 2489 +#define F_LIST_AGG_FINALFN 3551 +#define F_LIST_AGG_NOARG2_TRANSFN 3553 +#define F_LIST_AGG_TRANSFN 3550 +#define F_NUMERIC_LN 1734 +#define F_LO_CLOSE 953 +#define F_LO_CREAT 957 +#define F_LO_CREATE 715 +#define F_LO_EXPORT 765 +#define F_LO_IMPORT 764 +#define F_LO_IMPORT_WITH_OID 767 +#define F_LO_LSEEK 956 +#define F_LO_OPEN 952 +#define F_LO_TELL 958 +#define F_LO_TRUNCATE 1004 +#define F_LO_UNLINK 964 +#define F_LOCAL_BGWRITER_STAT 4373 +#define F_LOCAL_CKPT_STAT 4371 +#define F_LOCAL_DOUBLE_WRITE_STAT 4384 +#define F_LOCAL_PAGEWRITER_STAT 4361 +#define F_LOCAL_RECOVERY_STATUS 3250 +#define F_LOCAL_REDO_STAT 4388 +#define F_LOCAL_RTO_STAT 3299 +#define F_LOCAL_SINGLE_FLUSH_DW_STAT 4375 +#define F_LOCKTAG_DECODE 5730 +#define F_NUMERIC_LOG 1736 +#define F_LOREAD 954 +#define F_LOWER 870 +#define F_RANGE_LOWER 3848 +#define F_RANGE_LOWER_INC 3851 +#define F_RANGE_LOWER_INF 3853 +#define F_LOWRITE 955 +#define F_LPAD LPADFUNCOID +#define F_LSEG_CONSTRUCT 993 +#define F_LSEG_CENTER 225 +#define F_LSEG_DISTANCE 361 +#define F_LSEG_EQ 999 +#define F_LSEG_GE 1486 +#define F_LSEG_GT 1485 +#define F_LSEG_IN 119 +#define F_LSEG_INTERPT 362 +#define F_LSEG_INTERSECT 994 +#define F_LSEG_LE 1484 +#define F_LSEG_LT 1483 +#define F_LSEG_NE 1482 +#define F_LSEG_OUT 120 +#define F_LSEG_RECV 2480 +#define F_LSEG_SEND 2481 +#define F_LTRIM LTRIMFUNCOID +#define F_LTRIM1 LTRIMPARAFUNCOID +#define F_MACADDR_AND 3145 +#define F_MACADDR_CMP 836 +#define F_MACADDR_EQ 830 +#define F_MACADDR_GE 834 +#define F_MACADDR_GT 833 +#define F_MACADDR_IN 436 +#define F_MACADDR_LE 832 +#define F_MACADDR_LT 831 +#define F_MACADDR_NE 835 +#define F_MACADDR_NOT 3144 +#define F_MACADDR_OR 3146 +#define F_MACADDR_OUT 437 +#define F_MACADDR_RECV 2494 +#define F_MACADDR_SEND 2495 +#define F_MAKEACLITEM 1365 +#define F_NETWORK_MASKLEN 697 +#define F_MD5_TEXT 2311 +#define F_MD5_BYTEA 2321 +#define F_MEDIAN_FLOAT8_FINALFN 5557 +#define F_MEDIAN_INTERVAL_FINALFN 5558 +#define F_MEDIAN_TRANSFN 5559 +#define F_MKTINTERVAL 676 +#define F_NUMERIC_MOD 1728 +#define F_MODE_FINAL 4462 +#define F_INT4_CASH INTEGER2CASHFUNCOID +#define F_INT8_CASH BIGINT2CASHFUNCOID +#define F_NUMERIC_CASH NUMERIC2CASHFUNCOID +#define F_MOT_GLOBAL_MEMORY_DETAIL 6201 +#define F_MOT_LOCAL_MEMORY_DETAIL 6202 +#define F_MOT_SESSION_MEMORY_DETAIL 6200 +#define F_MUL_D_INTERVAL 1624 +#define F_TEXT_MULTIPLY_FLOAT8 3170 +#define F_FLOAT8_MULTIPLY_TEXT 3171 +#define F_TEXT_NAME 407 +#define F_BPCHAR_NAME 409 +#define F_NAMEEQ 62 +#define F_NAMEGE 658 +#define F_NAMEGT 657 +#define F_NAMEICLIKE 1635 +#define F_NAMEICNLIKE 1636 +#define F_NAMEICREGEXEQ 1240 +#define F_NAMEICREGEXNE 1241 +#define F_NAMEIN 34 +#define F_NAMELE 656 +#define F_NAMELT 655 +#define F_NAMENE 659 +#define F_NAMENLIKE 859 +#define F_NAMEOUT 35 +#define F_NAMERECV 2422 +#define F_NAMEREGEXEQ 79 +#define F_NAMEREGEXNE 1252 +#define F_NAMESEND 2423 +#define F_NEQJOINSEL 106 +#define F_NEQSEL NEQSELRETURNOID +#define F_NETWORK_NETMASK 696 +#define F_NETWORK_NETWORK 683 +#define F_NETWORK_CMP 926 +#define F_NETWORK_EQ 920 +#define F_NETWORK_GE 924 +#define F_NETWORK_GT 923 +#define F_NETWORK_LE 922 +#define F_NETWORK_LT 921 +#define F_NETWORK_NE 925 +#define F_NETWORK_SUB 927 +#define F_NETWORK_SUBEQ 928 +#define F_NETWORK_SUP 929 +#define F_NETWORK_SUPEQ 930 +#define F_NEXT_DAY_INT 4076 +#define F_NEXT_DAY_STR 4077 +#define F_NEXTVAL_OID NEXTVALFUNCOID +#define F_NGRAM_END 3788 +#define F_NGRAM_LEXTYPE 3789 +#define F_NGRAM_NEXTTOKEN 3787 +#define F_NGRAM_START 3786 +#define F_NLIKEJOINSEL 1828 +#define F_NLIKESEL 1822 +#define F_NODE_OID_NAME 3950 +#define F_NOW NOWFUNCOID +#define F_PATH_NPOINTS 1545 +#define F_POLY_NPOINTS 1556 +#define F_WINDOW_NTH_VALUE 3114 +#define F_WINDOW_NTILE 3105 +#define F_NUMERIC 1703 +#define F_INT4_NUMERIC 1740 +#define F_FLOAT4_NUMERIC 1742 +#define F_FLOAT8_NUMERIC 1743 +#define F_INT8_NUMERIC 1781 +#define F_INT2_NUMERIC 1782 +#define F_CASH_NUMERIC CASH2NUMERICFUNCOID +#define F_NUMERIC_ACCUM 1833 +#define F_NUMERIC_ADD 1724 +#define F_NUMERIC_AVG 1837 +#define F_NUMERIC_AVG_ACCUM 2858 +#define F_NUMERIC_AVG_COLLECT 2964 +#define F_NUMERIC_BPCHAR 4072 +#define F_NUMERIC_CMP 1769 +#define F_NUMERIC_COLLECT 2968 +#define F_NUMERIC_DIV 1727 +#define F_NUMERIC_EQ 1718 +#define F_NUMERIC_GE 1721 +#define F_NUMERIC_GT 1720 +#define F_NUMERIC_IN 1701 +#define F_NUMERIC_INC 1764 +#define F_NUMERIC_INT1 5522 +#define F_NUMERIC_LARGER 1767 +#define F_NUMERIC_LE 1723 +#define F_NUMERIC_LIST_AGG_NOARG2_TRANSFN 3577 +#define F_NUMERIC_LIST_AGG_TRANSFN 3575 +#define F_NUMERIC_LT 1722 +#define F_NUMERIC_MUL 1726 +#define F_NUMERIC_NE 1719 +#define F_NUMERIC_OUT 1702 +#define F_NUMERIC_POWER 1739 +#define F_NUMERIC_RECV 2460 +#define F_NUMERIC_SEND 2461 +#define F_NUMERIC_SMALLER 1766 +#define F_NUMERIC_SORTSUPPORT 3283 +#define F_NUMERIC_SQRT 1731 +#define F_NUMERIC_STDDEV_POP 2596 +#define F_NUMERIC_STDDEV_SAMP 1839 +#define F_NUMERIC_SUB 1725 +#define F_NUMERIC_TEXT 4171 +#define F_NUMERIC_TRANSFORM 3157 +#define F_NUMERIC_UMINUS 1771 +#define F_NUMERIC_UPLUS 1915 +#define F_NUMERIC_VAR_POP 2514 +#define F_NUMERIC_VAR_SAMP 1838 +#define F_NUMERIC_VARCHAR 4183 +#define F_NUMERICTYPMODIN 2917 +#define F_NUMERICTYPMODOUT 2918 +#define F_TSQUERY_NUMNODE 3672 +#define F_NUMRANGE_SUBDIFF 3924 +#define F_INT1_INTERVAL 3189 +#define F_INT2_INTERVAL 3190 +#define F_INT4_INTERVAL 3191 +#define F_NUMERIC_INTERVAL 3842 +#define F_NUMTODSINTERVAL 3172 +#define F_NVARCHAR2 3961 +#define F_NVARCHAR2IN 3962 +#define F_NVARCHAR2OUT 3963 +#define F_NVARCHAR2RECV 3966 +#define F_NVARCHAR2SEND 3967 +#define F_NVARCHAR2TYPMODIN 3964 +#define F_NVARCHAR2TYPMODOUT 3965 +#define F_BPCHAROCTETLEN 1375 +#define F_BITOCTETLENGTH 1682 +#define F_I8TOOID 1287 +#define F_OIDEQ 184 +#define F_OIDGE 1639 +#define F_OIDGT 1638 +#define F_OIDIN 1798 +#define F_OIDLARGER 1965 +#define F_OIDLE 717 +#define F_OIDLT 716 +#define F_OIDNE 185 +#define F_OIDOUT 1799 +#define F_OIDRECV 2418 +#define F_OIDSEND 2419 +#define F_OIDSMALLER 1966 +#define F_OIDVECTOREQ 679 +#define F_OIDVECTORGE 680 +#define F_OIDVECTORGT 681 +#define F_OIDVECTORIN 54 +#define F_OIDVECTORIN_EXTEND 91 +#define F_OIDVECTORLE 678 +#define F_OIDVECTORLT 677 +#define F_OIDVECTORNE 619 +#define F_OIDVECTOROUT 55 +#define F_OIDVECTOROUT_EXTEND 92 +#define F_OIDVECTORRECV 2420 +#define F_OIDVECTORRECV_EXTEND 3122 +#define F_OIDVECTORSEND 2421 +#define F_OIDVECTORSEND_EXTEND 3123 +#define F_OIDVECTORTYPES 1349 +#define F_ON_PB 136 +#define F_ON_PL 959 +#define F_ON_PPATH 137 +#define F_ON_PS 369 +#define F_ON_SB 372 +#define F_ON_SL 960 +#define F_OPAQUE_IN 2306 +#define F_OPAQUE_OUT 2307 +#define F_ORDERED_SET_TRANSITION 4448 +#define F_OVERLAPS_TIMETZ 1271 +#define F_OVERLAPS_TIMESTAMP 1304 +#define F_OVERLAPS_TIME 1308 +#define F_BYTEAOVERLAY 749 +#define F_BYTEAOVERLAY_NO_LEN 752 +#define F_TEXTOVERLAY 1404 +#define F_TEXTOVERLAY_NO_LEN 1405 +#define F_BITOVERLAY 3030 +#define F_BITOVERLAY_NO_LEN 3031 +#define F_POLY_PATH 1447 +#define F_PATH_ADD 1435 +#define F_PATH_ADD_PT 1436 +#define F_PATH_CENTER 226 +#define F_PATH_DISTANCE 370 +#define F_PATH_DIV_PT 1439 +#define F_PATH_IN 121 +#define F_PATH_INTER 973 +#define F_PATH_MUL_PT 1438 +#define F_PATH_N_EQ 984 +#define F_PATH_N_GE 986 +#define F_PATH_N_GT 983 +#define F_PATH_N_LE 985 +#define F_PATH_N_LT 982 +#define F_PATH_OUT 122 +#define F_PATH_RECV 2482 +#define F_PATH_SEND 2483 +#define F_PATH_SUB_PT 1437 +#define F_PATH_CLOSE 1433 +#define F_WINDOW_PERCENT_RANK 3103 +#define F_PERCENTILE_CONT_FLOAT8_FINAL 4453 +#define F_PERCENTILE_CONT_INTERVAL_FINAL 4455 +#define F_PG_ADVISORY_LOCK_INT8 2880 +#define F_PG_ADVISORY_LOCK_INT4 2886 +#define F_PG_ADVISORY_LOCK_SP_DB_INT4 9016 +#define F_PG_ADVISORY_LOCK_SHARED_INT8 2881 +#define F_PG_ADVISORY_LOCK_SHARED_INT4 2887 +#define F_PG_ADVISORY_UNLOCK_INT8 2884 +#define F_PG_ADVISORY_UNLOCK_INT4 2890 +#define F_PG_ADVISORY_UNLOCK_SP_DB_INT4 9015 +#define F_PG_ADVISORY_UNLOCK_ALL 2892 +#define F_PG_ADVISORY_UNLOCK_SHARED_INT8 2885 +#define F_PG_ADVISORY_UNLOCK_SHARED_INT4 2891 +#define F_PG_ADVISORY_XACT_LOCK_INT8 3089 +#define F_PG_ADVISORY_XACT_LOCK_INT4 3093 +#define F_PG_ADVISORY_XACT_LOCK_SHARED_INT8 3090 +#define F_PG_ADVISORY_XACT_LOCK_SHARED_INT4 3094 +#define F_PG_AUTOVAC_COORDINATOR 4081 +#define F_PG_AUTOVAC_STATUS 3223 +#define F_PG_AUTOVAC_TIMEOUT 4080 +#define F_PG_AVAILABLE_EXTENSION_VERSIONS 3083 +#define F_PG_AVAILABLE_EXTENSIONS 3082 +#define F_PG_BACKEND_PID PGBACKENDPIDFUNCOID +#define F_PG_BUFFERCACHE_PAGES 4130 +#define F_PG_CANCEL_BACKEND 2171 +#define F_PG_CANCEL_INVALID_QUERY 3213 +#define F_PG_CBM_FORCE_TRACK 4655 +#define F_PG_CBM_GET_CHANGED_BLOCK 4653 +#define F_PG_CBM_GET_MERGED_FILE 4652 +#define F_PG_CBM_RECYCLE_FILE 4654 +#define F_PG_CBM_ROTATE_FILE 4660 +#define F_PG_CBM_TRACKED_LOCATION 4651 +#define F_PG_CHAR_TO_ENCODING PGCHARTOENCODINGFUNCOID +#define F_PG_CHECK_AUTHID PGCHECKAUTHIDFUNCOID +#define F_PG_CHECK_XIDLIMIT 1999 +#define F_PG_CLEAN_REGION_INFO 4209 +#define F_PG_CLIENT_ENCODING PGCLIENTENCODINGFUNCOID +#define F_PG_COLLATION_FOR 3162 +#define F_PG_COLLATION_IS_VISIBLE 3815 +#define F_PG_COLUMN_SIZE PGCOLUMNSIZEFUNCOID +#define F_PG_COMM_DELAY 1987 +#define F_PG_COMM_RECV_STREAM 1984 +#define F_PG_COMM_SEND_STREAM 1985 +#define F_PG_COMM_STATUS 1986 +#define F_PG_CONF_LOAD_TIME 2034 +#define F_PG_CONTROL_GROUP_CONFIG 3843 +#define F_PG_CONVERSION_IS_VISIBLE 2093 +#define F_PG_CREATE_LOGICAL_REPLICATION_SLOT 4215 +#define F_PG_CREATE_PHYSICAL_REPLICATION_SLOT 3779 +#define F_PG_CREATE_PHYSICAL_REPLICATION_SLOT_EXTERN 3790 +#define F_PG_CREATE_RESTORE_POINT 3098 +#define F_PG_CURRENT_SESSID 3267 +#define F_PG_CURRENT_SESSIONID 3266 +#define F_PG_CURRENT_USERID 3265 +#define F_PG_CURRENT_XLOG_INSERT_LOCATION 2852 +#define F_PG_CURRENT_XLOG_LOCATION 2849 +#define F_PG_CURSOR 2511 +#define F_PG_DATABASE_SIZE_NAME 2168 +#define F_PG_DATABASE_SIZE_OID 2324 +#define F_PG_DELETE_AUDIT 3781 +#define F_PG_DESCRIBE_OBJECT 3537 +#define F_PG_DISABLE_DELAY_DDL_RECYCLE 4657 +#define F_PG_DISABLE_DELAY_XLOG_RECYCLE 4659 +#define F_PG_DROP_REPLICATION_SLOT 3783 +#define F_PG_ENABLE_DELAY_DDL_RECYCLE 4656 +#define F_PG_ENABLE_DELAY_XLOG_RECYCLE 4658 +#define F_PG_ENCODING_MAX_LENGTH_SQL 2319 +#define F_PG_ENCODING_TO_CHAR PGENCODINGTOCHARFUNCOID +#define F_PG_EXPORT_SNAPSHOT 3809 +#define F_PG_EXPORT_SNAPSHOT_AND_CSN 4396 +#define F_PG_EXTENSION_CONFIG_DUMP 3086 +#define F_PG_EXTENSION_UPDATE_PATHS 3084 +#define F_PG_FILENODE_RELATION 3454 +#define F_PG_FUNCTION_IS_VISIBLE 2081 +#define F_PG_GET_CONSTRAINTDEF 1387 +#define F_PG_GET_CONSTRAINTDEF_EXT 2508 +#define F_PG_GET_EXPR 1716 +#define F_PG_GET_EXPR_EXT 2509 +#define F_PG_GET_FLUSH_LSN 3316 +#define F_PG_GET_FUNCTION_ARGUMENTS 2162 +#define F_PG_GET_FUNCTION_IDENTITY_ARGUMENTS 2232 +#define F_PG_GET_FUNCTION_RESULT 2165 +#define F_PG_GET_FUNCTIONDEF 2098 +#define F_PG_GET_GTT_RELSTATS 3596 +#define F_PG_GET_GTT_STATISTICS 3597 +#define F_PG_GET_INDEXDEF 1643 +#define F_PG_GET_INDEXDEF_EXT 2507 +#define F_PG_GET_KEYWORDS 1686 +#define F_PG_GET_REPLICATION_SLOT_NAME 6003 +#define F_PG_GET_REPLICATION_SLOTS 3784 +#define F_PG_GET_RULEDEF 1573 +#define F_PG_GET_RULEDEF_EXT 2504 +#define F_PG_GET_RUNNING_XACTS 1998 +#define F_PG_GET_SERIAL_SEQUENCE 1665 +#define F_PG_GET_SYNC_FLUSH_LSN 3317 +#define F_PG_GET_TABLEDEF_EXT 4443 +#define F_PG_GET_TRIGGERDEF 1662 +#define F_PG_GET_TRIGGERDEF_EXT 2730 +#define F_PG_GET_USERBYID 1642 +#define F_PG_GET_VARIABLE_INFO 2097 +#define F_PG_GET_VIEWDEF_NAME 1640 +#define F_PG_GET_VIEWDEF 1641 +#define F_PG_GET_VIEWDEF_NAME_EXT 2505 +#define F_PG_GET_VIEWDEF_EXT 2506 +#define F_PG_GET_VIEWDEF_WRAP 3159 +#define F_PG_GET_XIDLIMIT 2000 +#define F_PG_GTT_ATTACHED_PID 3598 +#define F_PG_HAS_ROLE_NAME_NAME 2705 +#define F_PG_HAS_ROLE_NAME_ID 2706 +#define F_PG_HAS_ROLE_ID_NAME 2707 +#define F_PG_HAS_ROLE_ID_ID 2708 +#define F_PG_HAS_ROLE_NAME 2709 +#define F_PG_HAS_ROLE_ID 2710 +#define F_PG_INDEXES_SIZE 2998 +#define F_PG_IS_IN_RECOVERY 3810 +#define F_PG_IS_OTHER_TEMP_SCHEMA 2855 +#define F_PG_IS_XLOG_REPLAY_PAUSED 3073 +#define F_PG_LAST_XACT_REPLAY_TIMESTAMP 3830 +#define F_PG_LAST_XLOG_RECEIVE_LOCATION 3820 +#define F_PG_LAST_XLOG_REPLAY_LOCATION 3821 +#define F_PG_LIST_GTT_RELFROZENXIDS 3599 +#define F_PG_LISTENING_CHANNELS 3035 +#define F_PG_LOCK_STATUS 1371 +#define F_PG_LOG_COMM_STATUS 1983 +#define F_PG_LOGICAL_SLOT_GET_BINARY_CHANGES 4217 +#define F_PG_LOGICAL_SLOT_GET_CHANGES 4216 +#define F_PG_LOGICAL_SLOT_PEEK_BINARY_CHANGES 4219 +#define F_PG_LOGICAL_SLOT_PEEK_CHANGES 4218 +#define F_PG_LS_DIR 2625 +#define F_PG_MY_TEMP_SCHEMA 2854 +#define F_PG_NODE_TREE_IN 195 +#define F_PG_NODE_TREE_OUT 196 +#define F_PG_NODE_TREE_RECV 197 +#define F_PG_NODE_TREE_SEND 198 +#define F_PG_NOTIFY 3036 +#define F_PG_OPCLASS_IS_VISIBLE 2083 +#define F_PG_OPERATOR_IS_VISIBLE 2082 +#define F_PG_OPFAMILY_IS_VISIBLE 3829 +#define F_PG_OPTIONS_TO_TABLE 2289 +#define F_PG_PARSE_CLOG 3212 +#define F_PG_PARTITION_FILENODE 3197 +#define F_PG_PARTITION_FILEPATH 3220 +#define F_PG_PARTITION_INDEXES_SIZE_NAME 3195 +#define F_PG_PARTITION_INDEXES_SIZE_OID 3196 +#define F_PG_PARTITION_SIZE_NAME 3193 +#define F_PG_PARTITION_SIZE_OID 3194 +#define F_PG_POOL_PING 3472 +#define F_PG_POOL_VALIDATE 3471 +#define F_PG_POSTMASTER_START_TIME 2560 +#define F_PG_PREPARED_STATEMENT 2510 +#define F_PG_PREPARED_XACT 1065 +#define F_PG_QUERY_AUDIT 3780 +#define F_PG_READ_BINARY_FILE 3827 +#define F_PG_READ_BINARY_FILE_ALL 3828 +#define F_PG_READ_FILE 2624 +#define F_PG_READ_FILE_ALL 3826 +#define F_PG_RELATION_COMPRESSION_RATIO 3211 +#define F_PG_RELATION_FILENODE 2999 +#define F_PG_RELATION_FILEPATH 3034 +#define F_PG_RELATION_SIZE 2332 +#define F_PG_RELATION_WITH_COMPRESSION 3210 +#define F_PG_RELOAD_CONF 2621 +#define F_PG_REPLICATION_SLOT_ADVANCE 4220 +#define F_PG_RESUME_BKP_FLAG 4445 +#define F_PG_ROTATE_LOGFILE 2622 +#define F_PG_SEQUENCE_PARAMETERS 3078 +#define F_PG_SHARED_MEMCTX_DETAIL 3987 +#define F_PG_SHARED_MEMORY_DETAIL 3986 +#define F_SHOW_ALL_SETTINGS 2084 +#define F_PG_SIZE_PRETTY 2288 +#define F_PG_SIZE_PRETTY_NUMERIC 3166 +#define F_PG_SLEEP 2626 +#define F_PG_START_BACKUP 2172 +#define F_PG_STAT_BAD_BLOCK 3218 +#define F_PG_STAT_BAD_BLOCK_CLEAR 3219 +#define F_PG_STAT_CLEAR_SNAPSHOT 2230 +#define F_PG_STAT_FILE 2623 +#define F_PG_STAT_FILE_RECURSIVE 6321 +#define F_PG_STAT_GET_ACTIVITY 2022 +#define F_PG_STAT_GET_ACTIVITY_FOR_TEMPTABLE 4213 +#define F_PG_STAT_GET_ACTIVITY_NG 5549 +#define F_PG_STAT_GET_ACTIVITY_WITH_CONNINFO 4212 +#define F_PG_STAT_GET_ANALYZE_COUNT 3056 +#define F_PG_STAT_GET_AUTOANALYZE_COUNT 3057 +#define F_PG_STAT_GET_AUTOVACUUM_COUNT 3055 +#define F_PG_STAT_GET_BACKEND_ACTIVITY 1940 +#define F_PG_STAT_GET_BACKEND_ACTIVITY_START 2094 +#define F_PG_STAT_GET_BACKEND_CLIENT_ADDR 1392 +#define F_PG_STAT_GET_BACKEND_CLIENT_PORT 1393 +#define F_PG_STAT_GET_BACKEND_DBID 1938 +#define F_PG_STAT_GET_BACKEND_IDSET 1936 +#define F_PG_STAT_GET_BACKEND_PID PGSTATGETBACKENDPIDFUNCOID +#define F_PG_STAT_GET_BACKEND_START 1391 +#define F_PG_STAT_GET_BACKEND_USERID 1939 +#define F_PG_STAT_GET_BACKEND_WAITING 2853 +#define F_PG_STAT_GET_BACKEND_XACT_START 2857 +#define F_PG_STAT_GET_BGWRITER_BUF_WRITTEN_CHECKPOINTS 2771 +#define F_PG_STAT_GET_BGWRITER_BUF_WRITTEN_CLEAN 2772 +#define F_PG_STAT_GET_BGWRITER_MAXWRITTEN_CLEAN 2773 +#define F_PG_STAT_GET_BGWRITER_REQUESTED_CHECKPOINTS 2770 +#define F_PG_STAT_GET_BGWRITER_STAT_RESET_TIME 3075 +#define F_PG_STAT_GET_BGWRITER_TIMED_CHECKPOINTS 2769 +#define F_PG_STAT_GET_BLOCKS_FETCHED 1934 +#define F_PG_STAT_GET_BLOCKS_HIT 1935 +#define F_PG_STAT_GET_BUF_ALLOC 2859 +#define F_PG_STAT_GET_BUF_FSYNC_BACKEND 3063 +#define F_PG_STAT_GET_BUF_WRITTEN_BACKEND 2775 +#define F_PG_STAT_GET_CGROUP_INFO 5008 +#define F_PG_STAT_GET_CHECKPOINT_SYNC_TIME 3161 +#define F_PG_STAT_GET_CHECKPOINT_WRITE_TIME 3160 +#define F_PG_STAT_GET_CU_HDD_ASYN 3484 +#define F_PG_STAT_GET_CU_HDD_SYNC 3483 +#define F_PG_STAT_GET_CU_MEM_HIT 3480 +#define F_PG_STAT_GET_DATA_SENDERS 3785 +#define F_PG_STAT_GET_DB_BLK_READ_TIME 2844 +#define F_PG_STAT_GET_DB_BLK_WRITE_TIME 2845 +#define F_PG_STAT_GET_DB_BLOCKS_FETCHED 1944 +#define F_PG_STAT_GET_DB_BLOCKS_HIT 1945 +#define F_PG_STAT_GET_DB_CONFLICT_ALL 3070 +#define F_PG_STAT_GET_DB_CONFLICT_BUFFERPIN 3068 +#define F_PG_STAT_GET_DB_CONFLICT_LOCK 3066 +#define F_PG_STAT_GET_DB_CONFLICT_SNAPSHOT 3067 +#define F_PG_STAT_GET_DB_CONFLICT_STARTUP_DEADLOCK 3069 +#define F_PG_STAT_GET_DB_CONFLICT_TABLESPACE 3065 +#define F_PG_STAT_GET_DB_CU_HDD_ASYN 3489 +#define F_PG_STAT_GET_DB_CU_HDD_SYNC 3488 +#define F_PG_STAT_GET_DB_CU_MEM_HIT 3485 +#define F_PG_STAT_GET_DB_DEADLOCKS 3152 +#define F_PG_STAT_GET_DB_NUMBACKENDS 1941 +#define F_PG_STAT_GET_DB_STAT_RESET_TIME 3074 +#define F_PG_STAT_GET_DB_TEMP_BYTES 3151 +#define F_PG_STAT_GET_DB_TEMP_FILES 3150 +#define F_PG_STAT_GET_DB_TUPLES_DELETED 2762 +#define F_PG_STAT_GET_DB_TUPLES_FETCHED 2759 +#define F_PG_STAT_GET_DB_TUPLES_INSERTED 2760 +#define F_PG_STAT_GET_DB_TUPLES_RETURNED 2758 +#define F_PG_STAT_GET_DB_TUPLES_UPDATED 2761 +#define F_PG_STAT_GET_DB_XACT_COMMIT 1942 +#define F_PG_STAT_GET_DB_XACT_ROLLBACK 1943 +#define F_PG_STAT_GET_DEAD_TUPLES 2879 +#define F_PG_STAT_GET_ENV 3982 +#define F_PG_STAT_GET_FILE_STAT 3975 +#define F_PG_STAT_GET_FUNCTION_CALLS 2978 +#define F_PG_STAT_GET_FUNCTION_SELF_TIME 2980 +#define F_PG_STAT_GET_FUNCTION_TOTAL_TIME 2979 +#define F_PG_STAT_GET_LAST_ANALYZE_TIME 2783 +#define F_PG_STAT_GET_LAST_AUTOANALYZE_TIME 2784 +#define F_PG_STAT_GET_LAST_AUTOVACUUM_TIME 2782 +#define F_PG_STAT_GET_LAST_DATA_CHANGED_TIME 5600 +#define F_PG_STAT_GET_LAST_VACUUM_TIME 2781 +#define F_PG_STAT_GET_LIVE_TUPLES 2878 +#define F_PG_STAT_GET_MEM_MBYTES_RESERVED 2846 +#define F_PG_STAT_GET_NUMSCANS 1928 +#define F_PG_STAT_GET_PARTITION_DEAD_TUPLES 4087 +#define F_PG_STAT_GET_PARTITION_LIVE_TUPLES 4092 +#define F_PG_STAT_GET_PARTITION_TUPLES_CHANGED 4086 +#define F_PG_STAT_GET_PARTITION_TUPLES_DELETED 4090 +#define F_PG_STAT_GET_PARTITION_TUPLES_HOT_UPDATED 4091 +#define F_PG_STAT_GET_PARTITION_TUPLES_INSERTED 4088 +#define F_PG_STAT_GET_PARTITION_TUPLES_UPDATED 4089 +#define F_PG_STAT_GET_POOLER_STATUS 3955 +#define F_PG_STAT_GET_REALTIME_INFO_INTERNAL 3500 +#define F_PG_STAT_GET_REDO_STAT 3973 +#define F_GS_GET_ROLE_NAME 5010 +#define F_PG_STAT_GET_SESSION_WLMSTAT 3502 +#define F_PG_STAT_GET_SQL_COUNT 3947 +#define F_PG_STAT_GET_STATUS 3980 +#define F_PG_STAT_GET_STREAM_REPLICATIONS 3499 +#define F_PG_STAT_GET_THREAD 3981 +#define F_PG_STAT_GET_TUPLES_CHANGED 3221 +#define F_PG_STAT_GET_TUPLES_DELETED 1933 +#define F_PG_STAT_GET_TUPLES_FETCHED 1930 +#define F_PG_STAT_GET_TUPLES_HOT_UPDATED 1972 +#define F_PG_STAT_GET_TUPLES_INSERTED 1931 +#define F_PG_STAT_GET_TUPLES_RETURNED 1929 +#define F_PG_STAT_GET_TUPLES_UPDATED 1932 +#define F_PG_STAT_GET_VACUUM_COUNT 3054 +#define F_PG_STAT_GET_WAL_RECEIVER 3819 +#define F_PG_STAT_GET_WAL_SENDERS 3099 +#define F_PG_STAT_GET_WLM_EC_OPERATOR_INFO 5024 +#define F_PG_STAT_GET_WLM_INSTANCE_INFO 5031 +#define F_PG_STAT_GET_WLM_INSTANCE_INFO_WITH_CLEANUP 5032 +#define F_PG_STAT_GET_WLM_NODE_RESOURCE_INFO 5019 +#define F_PG_STAT_GET_WLM_OPERATOR_INFO 5023 +#define F_PG_STAT_GET_WLM_REALTIME_EC_OPERATOR_INFO 5025 +#define F_PG_STAT_GET_WLM_REALTIME_OPERATOR_INFO 5022 +#define F_PG_STAT_GET_WLM_REALTIME_SESSION_INFO 5003 +#define F_PG_STAT_GET_WLM_SESSION_INFO 5002 +#define F_PG_STAT_GET_WLM_SESSION_INFO_INTERNAL 5001 +#define F_PG_STAT_GET_WLM_SESSION_IOSTAT_INFO 5014 +#define F_PG_STAT_GET_WLM_STATISTICS 3501 +#define F_PG_STAT_GET_WORKLOAD_STRUCT_INFO 5026 +#define F_PG_STAT_GET_XACT_BLOCKS_FETCHED 3044 +#define F_PG_STAT_GET_XACT_BLOCKS_HIT 3045 +#define F_PG_STAT_GET_XACT_FUNCTION_CALLS 3046 +#define F_PG_STAT_GET_XACT_FUNCTION_SELF_TIME 3048 +#define F_PG_STAT_GET_XACT_FUNCTION_TOTAL_TIME 3047 +#define F_PG_STAT_GET_XACT_NUMSCANS 3037 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_DELETED 4093 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_HOT_UPDATED 4096 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_INSERTED 4094 +#define F_PG_STAT_GET_XACT_PARTITION_TUPLES_UPDATED 4095 +#define F_PG_STAT_GET_XACT_TUPLES_DELETED 3042 +#define F_PG_STAT_GET_XACT_TUPLES_FETCHED 3039 +#define F_PG_STAT_GET_XACT_TUPLES_HOT_UPDATED 3043 +#define F_PG_STAT_GET_XACT_TUPLES_INSERTED 3040 +#define F_PG_STAT_GET_XACT_TUPLES_RETURNED 3038 +#define F_PG_STAT_GET_XACT_TUPLES_UPDATED 3041 +#define F_PG_STAT_RESET 2274 +#define F_PG_STAT_RESET_SHARED 3775 +#define F_PG_STAT_RESET_SINGLE_FUNCTION_COUNTERS 3777 +#define F_PG_STAT_RESET_SINGLE_TABLE_COUNTERS 3776 +#define F_PG_STAT_SET_LAST_DATA_CHANGED_TIME 5601 +#define F_PG_STOP_BACKUP 2173 +#define F_PG_SWITCH_XLOG 2848 +#define F_PG_SYNC_CSTORE_DELTA 3164 +#define F_PG_SYNC_ALL_CSTORE_DELTA 3534 +#define F_PG_SYSTEM_TIMESTAMP PGSYSTIMESTAMPFUNCOID +#define F_PG_TABLE_IS_VISIBLE 2079 +#define F_PG_TABLE_SIZE 2997 +#define F_PG_TABLESPACE_DATABASES 2556 +#define F_PG_TABLESPACE_LOCATION 3778 +#define F_PG_TABLESPACE_SIZE_OID 2322 +#define F_PG_TABLESPACE_SIZE_NAME 2323 +#define F_PG_TDE_INFO 3999 +#define F_PG_TERMINATE_BACKEND 2096 +#define F_PG_TERMINATE_SESSION 2099 +#define F_PG_TEST_ERR_CONTAIN_ERR 9999 +#define F_PG_TIMEZONE_ABBREVS 2599 +#define F_PG_TIMEZONE_NAMES 2856 +#define F_PG_TOTAL_AUTOVAC_TUPLES 3222 +#define F_PG_TOTAL_RELATION_SIZE 2286 +#define F_PG_TRIGGER_DEPTH 3163 +#define F_PG_TRY_ADVISORY_LOCK_INT8 2882 +#define F_PG_TRY_ADVISORY_LOCK_INT4 2888 +#define F_PG_TRY_ADVISORY_LOCK_SHARED_INT8 2883 +#define F_PG_TRY_ADVISORY_LOCK_SHARED_INT4 2889 +#define F_PG_TRY_ADVISORY_XACT_LOCK_INT8 3091 +#define F_PG_TRY_ADVISORY_XACT_LOCK_INT4 3095 +#define F_PG_TRY_ADVISORY_XACT_LOCK_SHARED_INT8 3092 +#define F_PG_TRY_ADVISORY_XACT_LOCK_SHARED_INT4 3096 +#define F_PG_TS_CONFIG_IS_VISIBLE 3758 +#define F_PG_TS_DICT_IS_VISIBLE 3757 +#define F_PG_TS_PARSER_IS_VISIBLE 3756 +#define F_PG_TS_TEMPLATE_IS_VISIBLE 3768 +#define F_PG_TYPE_IS_VISIBLE 2080 +#define F_PG_TYPEOF PGTYPEOFFUNCOID +#define F_PG_STAT_GET_WLM_USER_IOSTAT_INFO 5013 +#define F_PG_WLM_JUMP_QUEUE 3503 +#define F_PG_XLOG_LOCATION_DIFF 3165 +#define F_PG_XLOG_REPLAY_PAUSE 3071 +#define F_PG_XLOG_REPLAY_RESUME 3072 +#define F_PG_XLOGFILE_NAME 2851 +#define F_PG_XLOGFILE_NAME_OFFSET 2850 +#define F_PGXC_GET_CSN 3960 +#define F_PGXC_STAT_GET_STATUS 3591 +#define F_PGXC_GTM_SNAPSHOT_STATUS 2095 +#define F_PGXC_IS_COMMITTED 3203 +#define F_PGXC_LOCK_FOR_BACKUP 3204 +#define F_PGXC_LOCK_FOR_SP_DATABASE 9014 +#define F_PGXC_LOCK_FOR_TRANSFER 9018 +#define F_PGXC_MAX_DATANODE_SIZE_NAME 5028 +#define F_PGXC_NODE_STR 3202 +#define F_PGXC_POOL_CHECK 3200 +#define F_PGXC_POOL_CONNECTION_STATUS 3954 +#define F_PGXC_POOL_RELOAD 3201 +#define F_PGXC_SNAPSHOT_STATUS 2949 +#define F_PGXC_STAT_ALL_DIRTY_TABLES 4410 +#define F_PGXC_STAT_SCHEMA_DIRTY_TABLES 4411 +#define F_PGXC_UNLOCK_FOR_SP_DATABASE 9017 +#define F_PGXC_UNLOCK_FOR_TRANSFER 9019 +#define F_PGXC_VERSION 90 +#define F_DPI 1610 +#define F_PLAINTO_TSQUERY_BYID 3747 +#define F_PLAINTO_TSQUERY 3751 +#define F_GET_PLAN_SEED 4200 +#define F_GPCPLANCLEAN 3958 +#define F_GS_GLOBALPLANCACHE_STATUS 3957 +#define F_CONSTRUCT_POINT 1440 +#define F_POLY_CENTER 1540 +#define F_POINT_ABOVE 131 +#define F_POINT_ADD 1441 +#define F_POINT_BELOW 134 +#define F_POINT_DISTANCE 991 +#define F_POINT_DIV 1444 +#define F_POINT_EQ 135 +#define F_POINT_IN 117 +#define F_POINT_LEFT 132 +#define F_POINT_MUL 1443 +#define F_POINT_NE 988 +#define F_POINT_OUT 118 +#define F_POINT_RECV 2428 +#define F_POINT_RIGHT 133 +#define F_POINT_SEND 2429 +#define F_POINT_SUB 1442 +#define F_POLY_ABOVE 2569 +#define F_POLY_BELOW 2566 +#define F_POLY_CONTAIN 340 +#define F_POLY_CONTAIN_PT 1428 +#define F_POLY_CONTAINED 345 +#define F_POLY_DISTANCE 729 +#define F_POLY_IN 347 +#define F_POLY_LEFT 341 +#define F_POLY_OUT 348 +#define F_POLY_OVERABOVE 2568 +#define F_POLY_OVERBELOW 2567 +#define F_POLY_OVERLAP 346 +#define F_POLY_OVERLEFT 342 +#define F_POLY_OVERRIGHT 343 +#define F_POLY_RECV 2486 +#define F_POLY_RIGHT 344 +#define F_POLY_SAME 339 +#define F_POLY_SEND 2487 +#define F_BOX_POLY 1448 +#define F_PATH_POLY 1449 +#define F_CIRCLE_POLY 1475 +#define F_PATH_OPEN 1434 +#define F_BITPOSITION BITPOSITIONFUNCOID +#define F_BYTEAPOS BYTEAPOSFUNCOID +#define F_POSITIONJOINSEL 1301 +#define F_POSITIONSEL 1300 +#define F_POSTGRESQL_FDW_VALIDATOR 2316 +#define F_POUND_END 3800 +#define F_POUND_LEXTYPE 3801 +#define F_POUND_NEXTTOKEN 3799 +#define F_POUND_START 3798 +#define F_GS_GLOBALPLANCACHE_PREPARE_STATUS 3959 +#define F_PRSD_END 3719 +#define F_PRSD_HEADLINE 3720 +#define F_PRSD_LEXTYPE 3721 +#define F_PRSD_NEXTTOKEN 3718 +#define F_PRSD_START 3717 +#define F_PSORTBUILD 4040 +#define F_PSORTCANRETURN 4045 +#define F_PSORTCOSTESTIMATE 4044 +#define F_PSORTGETBITMAP 4043 +#define F_PSORTGETTUPLE 4042 +#define F_PSORTOPTIONS 4041 +#define F_PT_CONTAINED_CIRCLE 1478 +#define F_PT_CONTAINED_POLY 1429 +#define F_PV_BUILTIN_FUNCTIONS 5345 +#define F_PV_COMPUTE_POOL_WORKLOAD 4300 +#define F_PV_INSTANCE_TIME 3969 +#define F_PV_OS_RUN_INFO 3970 +#define F_PV_SESSION_MEMCTX_DETAIL 3983 +#define F_PV_SESSION_MEMORY 3984 +#define F_PV_SESSION_MEMORY_DETAIL 3971 +#define F_PV_SESSION_STAT 3974 +#define F_PV_SESSION_TIME 3972 +#define F_PV_THREAD_MEMORY_DETAIL 3968 +#define F_PV_TOTAL_MEMORY_DETAIL 3985 +#define F_QUERY_TO_XML 2924 +#define F_QUERY_TO_XML_AND_XMLSCHEMA 2930 +#define F_QUERY_TO_XMLSCHEMA 2927 +#define F_TSQUERYTREE 3673 +#define F_QUOTE_IDENT 1282 +#define F_QUOTE_LITERAL 1283 +#define F_QUOTE_NULLABLE 1289 +#define F_RADIANS 1609 +#define F_CIRCLE_RADIUS 1470 +#define F_DRANDOM RANDOMFUNCOID +#define F_RANGE_ADJACENT 3862 +#define F_RANGE_AFTER 3864 +#define F_RANGE_BEFORE 3863 +#define F_RANGE_CMP 3870 +#define F_RANGE_CONTAINED_BY 3861 +#define F_RANGE_CONTAINS 3859 +#define F_RANGE_CONTAINS_ELEM 3858 +#define F_RANGE_EQ 3855 +#define F_RANGE_GE 3873 +#define F_RANGE_GIST_COMPRESS 3877 +#define F_RANGE_GIST_CONSISTENT 3875 +#define F_RANGE_GIST_DECOMPRESS 3878 +#define F_RANGE_GIST_PENALTY 3879 +#define F_RANGE_GIST_PICKSPLIT 3880 +#define F_RANGE_GIST_SAME 3881 +#define F_RANGE_GIST_UNION 3876 +#define F_RANGE_GT 3874 +#define F_RANGE_IN 3834 +#define F_RANGE_INTERSECT 3868 +#define F_RANGE_LE 3872 +#define F_RANGE_LT 3871 +#define F_RANGE_MINUS 3869 +#define F_RANGE_NE 3856 +#define F_RANGE_OUT 3835 +#define F_RANGE_OVERLAPS 3857 +#define F_RANGE_OVERLEFT 3865 +#define F_RANGE_OVERRIGHT 3866 +#define F_RANGE_RECV 3836 +#define F_RANGE_SEND 3837 +#define F_RANGE_TYPANALYZE 3916 +#define F_RANGE_UNION 3867 +#define F_WINDOW_RANK RANKFUNCOID +#define F_RAWCAT 3478 +#define F_RAWCMP 3475 +#define F_RAWEQ 3931 +#define F_RAWGE 3939 +#define F_RAWGT 3936 +#define F_RAWIN 4035 +#define F_RAWLE 3935 +#define F_RAWLIKE 3476 +#define F_RAWLT 3932 +#define F_RAWNE 3940 +#define F_RAWNLIKE 3477 +#define F_RAWOUT 4036 +#define F_RAWTOTEXT 4037 +#define F_READ_DISABLE_CONN_FILE 4222 +#define F_RECORD_EQ 2981 +#define F_RECORD_GE 2986 +#define F_RECORD_GT 2984 +#define F_RECORD_IN 2290 +#define F_RECORD_LE 2985 +#define F_RECORD_LT 2983 +#define F_RECORD_NE 2982 +#define F_RECORD_OUT 2291 +#define F_RECORD_RECV 2402 +#define F_RECORD_SEND 2403 +#define F_TEXT_REGCLASS 1079 +#define F_REGCLASSIN 2218 +#define F_REGCLASSOUT 2219 +#define F_REGCLASSRECV 2452 +#define F_REGCLASSSEND 2453 +#define F_REGCONFIGIN 3736 +#define F_REGCONFIGOUT 3737 +#define F_REGCONFIGRECV 3738 +#define F_REGCONFIGSEND 3739 +#define F_REGDICTIONARYIN 3771 +#define F_REGDICTIONARYOUT 3772 +#define F_REGDICTIONARYRECV 3773 +#define F_REGDICTIONARYSEND 3774 +#define F_REGEXEQJOINSEL 1824 +#define F_REGEXEQSEL 1818 +#define F_REGEXNEJOINSEL 1827 +#define F_REGEXNESEL 1821 +#define F_REGEXP_MATCHES_NO_FLAGS 2763 +#define F_REGEXP_MATCHES 2764 +#define F_TEXTREGEXREPLACE_NOOPT 2284 +#define F_TEXTREGEXREPLACE 2285 +#define F_REGEXP_SPLIT_TO_ARRAY_NO_FLAGS 2767 +#define F_REGEXP_SPLIT_TO_ARRAY 2768 +#define F_REGEXP_SPLIT_TO_TABLE_NO_FLAGS 2765 +#define F_REGEXP_SPLIT_TO_TABLE 2766 +#define F_REGOPERATORIN 2216 +#define F_REGOPERATOROUT 2217 +#define F_REGOPERATORRECV 2450 +#define F_REGOPERATORSEND 2451 +#define F_REGOPERIN 2214 +#define F_REGOPEROUT 2215 +#define F_REGOPERRECV 2448 +#define F_REGOPERSEND 2449 +#define F_REGPROCEDUREIN 2212 +#define F_REGPROCEDUREOUT 2213 +#define F_REGPROCEDURERECV 2446 +#define F_REGPROCEDURESEND 2447 +#define F_REGPROCIN 44 +#define F_REGPROCOUT 45 +#define F_REGPROCRECV 2444 +#define F_REGPROCSEND 2445 +#define F_REGTYPEIN 2220 +#define F_REGTYPEOUT 2221 +#define F_REGTYPERECV 2454 +#define F_REGTYPESEND 2455 +#define F_INTERVAL_RELTIME 1194 +#define F_RELTIMEEQ 257 +#define F_RELTIMEGE 262 +#define F_RELTIMEGT 260 +#define F_RELTIMEIN RELTIMEINFUNCOID +#define F_RELTIMELE 261 +#define F_RELTIMELT 259 +#define F_RELTIMENE 258 +#define F_RELTIMEOUT RELTIMEOUTFUNCOID +#define F_RELTIMERECV 2464 +#define F_RELTIMESEND 2465 +#define F_REMOTE_BGWRITER_STAT 4374 +#define F_REMOTE_CKPT_STAT 4372 +#define F_REMOTE_DOUBLE_WRITE_STAT 4385 +#define F_REMOTE_PAGEWRITER_STAT 4368 +#define F_REMOTE_RECOVERY_STATUS 4999 +#define F_REMOTE_REDO_STAT 4389 +#define F_REMOTE_RTO_STAT 4789 +#define F_REMOTE_SINGLE_FLUSH_DW_STAT 4376 +#define F_REMOVE_JOB_CLASS_DEPEND_INTERNAL 6005 +#define F_REPEAT 1622 +#define F_REPLACE_TEXT 2087 +#define F_RESET_UNIQUE_SQL 5716 +#define F_TEXT_REVERSE 3062 +#define F_TEXT_RIGHT 3061 +#define F_NUMERIC_ROUND 1707 +#define F_WINDOW_ROW_NUMBER ROWNUMBERFUNCOID +#define F_ROW_TO_JSON 3155 +#define F_ROW_TO_JSON_PRETTY 3156 +#define F_RPAD RPADFUNCOID +#define F_RTRIM RTRIMFUNCOID +#define F_RTRIM1 RTRIMPARAFUNCOID +#define F_SCALARGTJOINSEL 108 +#define F_SCALARGTSEL 104 +#define F_SCALARLTJOINSEL 107 +#define F_SCALARLTSEL 103 +#define F_SCHEMA_TO_XML 2933 +#define F_SCHEMA_TO_XML_AND_XMLSCHEMA 2935 +#define F_SCHEMA_TO_XMLSCHEMA 2934 +#define F_SERIES_INTERNAL 6006 +#define F_SESSION_USER SESSIONUSERFUNCOID +#define F_SESSIONID_TO_PID 3978 +#define F_BYTEASETBIT 724 +#define F_BITSETBIT 3033 +#define F_BYTEASETBYTE 722 +#define F_SET_CONFIG_BY_NAME 2078 +#define F_SET_HASHBUCKET_INFO 6118 +#define F_INET_SET_MASKLEN 605 +#define F_CIDR_SET_MASKLEN 635 +#define F_SET_WORKING_GRAND_VERSION_NUM_MANUALLY 7998 +#define F_SETSEED 1599 +#define F_SETVAL_OID SETVAL1FUNCOID +#define F_SETVAL3_OID SETVAL3FUNCOID +#define F_TSVECTOR_SETWEIGHT 3624 +#define F_SHELL_IN 2398 +#define F_SHELL_OUT 2399 +#define F_NUMERIC_SIGN 1706 +#define F_DSIGN 2310 +#define F_SIMILAR_ESCAPE 1623 +#define F_DSIN SINEFUNCOID +#define F_POINT_SLOPE 992 +#define F_SMALLDATETIME_CMP 5586 +#define F_SMALLDATETIME_EQ 5580 +#define F_SMALLDATETIME_GE 5584 +#define F_SMALLDATETIME_GT 5585 +#define F_SMALLDATETIME_HASH 5587 +#define F_SMALLDATETIME_IN SMALLDATETIMEINFUNCOID +#define F_SMALLDATETIME_LARGER 9012 +#define F_SMALLDATETIME_LE 5583 +#define F_SMALLDATETIME_LT 5582 +#define F_SMALLDATETIME_NE 5581 +#define F_SMALLDATETIME_OUT SMALLDATETIMEOUTFUNCOID +#define F_SMALLDATETIME_RECV 9007 +#define F_SMALLDATETIME_SEND 9008 +#define F_SMALLDATETIME_SMALLER 9011 +#define F_SMGREQ 762 +#define F_SMGRIN 760 +#define F_SMGRNE 763 +#define F_SMGROUT 761 +#define F_SPG_KD_CHOOSE 4024 +#define F_SPG_KD_CONFIG 4023 +#define F_SPG_KD_INNER_CONSISTENT 4026 +#define F_SPG_KD_PICKSPLIT 4025 +#define F_SPG_QUAD_CHOOSE 4019 +#define F_SPG_QUAD_CONFIG 4018 +#define F_SPG_QUAD_INNER_CONSISTENT 4021 +#define F_SPG_QUAD_LEAF_CONSISTENT 4022 +#define F_SPG_QUAD_PICKSPLIT 4020 +#define F_SPG_TEXT_CHOOSE 4028 +#define F_SPG_TEXT_CONFIG 4027 +#define F_SPG_TEXT_INNER_CONSISTENT 4030 +#define F_SPG_TEXT_LEAF_CONSISTENT 4031 +#define F_SPG_TEXT_PICKSPLIT 4029 +#define F_SPGBEGINSCAN 4004 +#define F_SPGBUILD 4009 +#define F_SPGBUILDEMPTY 4010 +#define F_SPGBULKDELETE 4011 +#define F_SPGCANRETURN 4032 +#define F_SPGCOSTESTIMATE 4013 +#define F_SPGENDSCAN 4006 +#define F_SPGGETBITMAP 4002 +#define F_SPGGETTUPLE 4001 +#define F_SPGINSERT 4003 +#define F_SPGMARKPOS 4007 +#define F_SPGMERGE 3188 +#define F_SPGOPTIONS 4014 +#define F_SPGRESCAN 4005 +#define F_SPGRESTRPOS 4008 +#define F_SPGVACUUMCLEANUP 4012 +#define F_SPLIT_TEXT 2088 +#define F_STATEMENT_DETAIL_DECODE 5732 +#define F_STATEMENT_TIMESTAMP STATEMENTTIMESTAMPFUNCOID +#define F_STRING_AGG_FINALFN 3536 +#define F_STRING_AGG_TRANSFN STRINGAGGTRANSFNFUNCOID +#define F_TEXT_TO_ARRAY_NULL 376 +#define F_TEXT_TO_ARRAY 394 +#define F_TSVECTOR_STRIP 3623 +#define F_SUBMIT_JOB_ON_NODES 5717 +#define F_TEXT_SUBSTR_ORCLCOMPAT SUBSTRFUNCOID +#define F_TEXT_SUBSTR_NO_LEN_ORCLCOMPAT SUBSTRNOLENFUNCOID +#define F_BYTEA_SUBSTR_ORCLCOMPAT BYTEASUBSTRFUNCOID +#define F_BYTEA_SUBSTR_NO_LEN_ORCLCOMPAT BYTEASUBSTRNOLENFUNCOID +#define F_SUBSTRB_WITH_LENTH SUBSTRBWITHLENFUNCOID +#define F_SUBSTRB_WITHOUT_LENTH SUBSTRBNOLENFUNCOID +#define F_TEXT_SUBSTR_NULL TEXTSUBSTRINGFUNCOID +#define F_TEXT_SUBSTR_NO_LEN_NULL TEXTSUBSTRINGNOLENFUNCOID +#define F_BITSUBSTR BITSUBSTRINGFUNOID +#define F_BITSUBSTR_NO_LEN BITSUBSTRINGNOLENFUNCOID +#define F_BYTEA_SUBSTR BYTEASUBSTRINGFUNCOID +#define F_BYTEA_SUBSTR_NO_LEN BYTEASUBSTRINGNOLENOID +#define F_TEXTREGEXSUBSTR TEXTREGEXSUBSTRINGOID +#define F_TEXT_SUBSTR SUBSTRINNFUNCOID +#define F_TEXT_SUBSTR_NO_LEN SUBSTRINNNOLENFUNCOID +#define F_SUPPRESS_REDUNDANT_UPDATES_TRIGGER 1291 +#define F_TABLE_DATA_SKEWNESS TESTSKEWNESSRETURNTYPE +#define F_ALL_TABLE_DISTRIBUTION 4441 +#define F_SINGLE_TABLE_DISTRIBUTION 4442 +#define F_TABLE_TO_XML 2923 +#define F_TABLE_TO_XML_AND_XMLSCHEMA 2929 +#define F_TABLE_TO_XMLSCHEMA 2926 +#define F_TABLESPACE_OID_NAME 3952 +#define F_DTAN 1606 +#define F_NAME_TEXT 406 +#define F_NETWORK_SHOW 730 +#define F_CHAR_TEXT 946 +#define F_XMLTOTEXT 2922 +#define F_BOOLTEXT 2971 +#define F_TEXT_DATE 4164 +#define F_TEXT_FLOAT4 4192 +#define F_TEXT_FLOAT8 4193 +#define F_TEXT_GE 743 +#define F_TEXT_GT 742 +#define F_TEXT_INT1 4188 +#define F_TEXT_INT2 4189 +#define F_TEXT_INT4 4190 +#define F_TEXT_INT8 4191 +#define F_TEXT_LARGER 458 +#define F_TEXT_LE 741 +#define F_TEXT_LT 740 +#define F_TEXT_NUMERIC 4194 +#define F_TEXT_PATTERN_GE 2163 +#define F_TEXT_PATTERN_GT 2164 +#define F_TEXT_PATTERN_LE 2161 +#define F_TEXT_PATTERN_LT 2160 +#define F_TEXT_SMALLER 459 +#define F_TEXT_TIMESTAMP 4073 +#define F_TEXTCAT 1258 +#define F_TEXTEQ 67 +#define F_TEXTIN 46 +#define F_TEXTNE 157 +#define F_TEXTOUT 47 +#define F_TEXTRECV 2414 +#define F_TEXTSEND 2415 +#define F_THESAURUS_INIT 3740 +#define F_THESAURUS_LEXIZE 3741 +#define F_GS_THREADPOOL_STATUS 3956 +#define F_TIDEQ 1292 +#define F_TIDGE 2792 +#define F_TIDGT 2790 +#define F_TIDIN 48 +#define F_TIDLARGER 2795 +#define F_TIDLE 2793 +#define F_TIDLT 2791 +#define F_TIDNE 1265 +#define F_TIDOUT 49 +#define F_TIDRECV 2438 +#define F_TIDSEND 2439 +#define F_TIDSMALLER 2796 +#define F_TIMESTAMP_TIME 1316 +#define F_INTERVAL_TIME 1419 +#define F_TIME_SCALE 1968 +#define F_TIMESTAMPTZ_TIME TIMESTAMPTZ2TIMEFUNCOID +#define F_TIMETZ_TIME 2046 +#define F_TIME_CMP 1107 +#define F_TIME_EQ 1145 +#define F_TIME_GE 1105 +#define F_TIME_GT 1104 +#define F_TIME_HASH 1688 +#define F_TIME_IN TIMEINFUNCOID +#define F_TIME_LARGER 1377 +#define F_TIME_LE 1103 +#define F_TIME_LT 1102 +#define F_TIME_MI_INTERVAL 1748 +#define F_TIME_MI_TIME 1690 +#define F_TIME_NE 1106 +#define F_TIME_OUT TIMEOUTFUNCOID +#define F_TIME_PL_INTERVAL 1747 +#define F_TIME_RECV 2470 +#define F_TIME_SEND 2471 +#define F_TIME_SMALLER 1378 +#define F_TIME_TRANSFORM 3944 +#define F_TIMEMI 245 +#define F_TIMENOW TIMENOWFUNCOID +#define F_TIMEOFDAY 274 +#define F_TIMEPL 244 +#define F_TIMESTAMP_SCALE 1961 +#define F_ABSTIME_TIMESTAMP ABSTIMETIMESTAMPFUNCOID +#define F_DATE_TIMESTAMP 2024 +#define F_TIMESTAMPTZ_TIMESTAMP TIMESTAMPTZ2TIMESTAMPFUNCOID +#define F_TIMESTAMP_CMP 2045 +#define F_TIMESTAMP_CMP_DATE 2370 +#define F_TIMESTAMP_CMP_TIMESTAMPTZ TIMESTAMPCMPTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_DIFF 3227 +#define F_TIMESTAMP_EQ 2052 +#define F_TIMESTAMP_EQ_DATE 2366 +#define F_TIMESTAMP_EQ_TIMESTAMPTZ TIMESTAMPEQTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_GE 2056 +#define F_TIMESTAMP_GE_DATE 2368 +#define F_TIMESTAMP_GE_TIMESTAMPTZ TIMESTAMPGETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_GT 2057 +#define F_TIMESTAMP_GT_DATE 2367 +#define F_TIMESTAMP_GT_TIMESTAMPTZ TIMESTAMPGTTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_HASH TIMESTAMPHASHOID +#define F_TIMESTAMP_IN TIMESTAMPINFUNCOID +#define F_TIMESTAMP_LARGER 2036 +#define F_TIMESTAMP_LE 2055 +#define F_TIMESTAMP_LE_DATE 2365 +#define F_TIMESTAMP_LE_TIMESTAMPTZ TIMESTAMPLETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_LIST_AGG_NOARG2_TRANSFN 3585 +#define F_TIMESTAMP_LIST_AGG_TRANSFN 3583 +#define F_TIMESTAMP_LT 2054 +#define F_TIMESTAMP_LT_DATE 2364 +#define F_TIMESTAMP_LT_TIMESTAMPTZ TIMESTAMPLTTIMESTAMPTZFUNCOID +#define F_TIMESTAMP_MI 2031 +#define F_TIMESTAMP_MI_INTERVAL 2033 +#define F_TIMESTAMP_NE 2053 +#define F_TIMESTAMP_NE_DATE 2369 +#define F_TIMESTAMP_NE_TIMESTAMPTZ TIMESTAMPNETIMESTAMPTZFUNCOID +#define F_TIMESTAMP_OUT TIMESTAMPOUTFUNCOID +#define F_TIMESTAMP_PL_INTERVAL 2032 +#define F_TIMESTAMP_RECV 2474 +#define F_TIMESTAMP_SEND 2475 +#define F_TIMESTAMP_SMALLER 2035 +#define F_TIMESTAMP_SORTSUPPORT 3137 +#define F_TIMESTAMP_TEXT 4178 +#define F_TIMESTAMP_TRANSFORM 3917 +#define F_TIMESTAMP_VARCHAR 4179 +#define F_TIMESTAMPTYPMODIN 2905 +#define F_TIMESTAMPTYPMODOUT 2906 +#define F_ABSTIME_TIMESTAMPTZ 1173 +#define F_DATE_TIMESTAMPTZ DATETIMESTAMPTZFUNCOID +#define F_TIMESTAMPTZ_SCALE 1967 +#define F_TIMESTAMP_TIMESTAMPTZ TIMESTAMP2TIMESTAMPTZFUNCOID +#define F_TIMESTAMPTZ_CMP_DATE TIMESTAMPTZCMPDATEFUNCOID +#define F_TIMESTAMPTZ_CMP_TIMESTAMP TIMESTAMPTZCMPTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_EQ_DATE TIMESTAMPTZEQDATEFUNCOID +#define F_TIMESTAMPTZ_EQ_TIMESTAMP TIMESTAMPTZEQTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_GE_DATE TIMESTAMPTZGEDATEFUNCOID +#define F_TIMESTAMPTZ_GE_TIMESTAMP TIMESTAMPTZGETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_GT_DATE TIMESTAMPTZGTDATEFUNCOID +#define F_TIMESTAMPTZ_GT_TIMESTAMP TIMESTAMPTZGTTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_IN TIMESTAMPTZINFUNCOID +#define F_TIMESTAMPTZ_LE_DATE TIMESTAMPTZLEDATEFUNCOID +#define F_TIMESTAMPTZ_LE_TIMESTAMP TIMESTAMPTZLETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_LIST_AGG_NOARG2_TRANSFN 3589 +#define F_TIMESTAMPTZ_LIST_AGG_TRANSFN 3587 +#define F_TIMESTAMPTZ_LT_DATE TIMESTAMPTZLTDATEFUNCOID +#define F_TIMESTAMPTZ_LT_TIMESTAMP TIMESTAMPTZLTTIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_MI_INTERVAL TIMESTAMPTZMIINTERVALFUNCOID +#define F_TIMESTAMPTZ_NE_DATE TIMESTAMPTZNEDATEFUNCOID +#define F_TIMESTAMPTZ_NE_TIMESTAMP TIMESTAMPTZNETIMESTAMPFUNCOID +#define F_TIMESTAMPTZ_OUT TIMESTAMPTZOUTFUNCOID +#define F_TIMESTAMPTZ_PL_INTERVAL TIMESTAMPTZPLINTERVALFUNCOID +#define F_TIMESTAMPTZ_RECV 2476 +#define F_TIMESTAMPTZ_SEND 2477 +#define F_TIMESTAMPTZTYPMODIN 2907 +#define F_TIMESTAMPTZTYPMODOUT 2908 +#define F_TIMESTAMPZONE_TEXT 4177 +#define F_TIMETYPMODIN 2909 +#define F_TIMETYPMODOUT 2910 +#define F_TIMESTAMPTZ_TIMETZ TIMESTAMPTZ2TIMETZFUNCOID +#define F_TIMETZ_SCALE 1969 +#define F_TIME_TIMETZ TIME2TIMETZFUNCOID +#define F_TIMETZ_CMP 1358 +#define F_TIMETZ_EQ 1352 +#define F_TIMETZ_GE 1356 +#define F_TIMETZ_GT 1357 +#define F_TIMETZ_HASH 1696 +#define F_TIMETZ_IN TIMETZINFUNCOID +#define F_TIMETZ_LARGER 1379 +#define F_TIMETZ_LE 1355 +#define F_TIMETZ_LT 1354 +#define F_TIMETZ_MI_INTERVAL 1750 +#define F_TIMETZ_NE 1353 +#define F_TIMETZ_OUT 1351 +#define F_TIMETZ_PL_INTERVAL 1749 +#define F_TIMETZ_RECV 2472 +#define F_TIMETZ_SEND 2473 +#define F_TIMETZ_SMALLER 1380 +#define F_TIMETZTYPMODIN 2911 +#define F_TIMETZTYPMODOUT 2912 +#define F_TIMESTAMPTZ_IZONE 1026 +#define F_TIMESTAMPTZ_ZONE 1159 +#define F_TIMETZ_ZONE TIMEZONETZFUNCOID +#define F_TIMETZ_IZONE 2038 +#define F_TIMESTAMP_ZONE 2069 +#define F_TIMESTAMP_IZONE 2070 +#define F_TINTERVALCT 264 +#define F_TINTERVALEND 273 +#define F_TINTERVALEQ 784 +#define F_TINTERVALGE 789 +#define F_TINTERVALGT 787 +#define F_TINTERVALIN TINTERVALINFUNCOID +#define F_TINTERVALLE 788 +#define F_TINTERVALLENEQ 266 +#define F_TINTERVALLENGE 271 +#define F_TINTERVALLENGT 269 +#define F_TINTERVALLENLE 270 +#define F_TINTERVALLENLT 268 +#define F_TINTERVALLENNE 267 +#define F_TINTERVALLT 786 +#define F_TINTERVALNE 785 +#define F_TINTERVALOUT TINTERVALOUTFUNCOID +#define F_TINTERVALOV 265 +#define F_TINTERVALRECV 2466 +#define F_TINTERVALREL 249 +#define F_TINTERVALSAME 263 +#define F_TINTERVALSEND 2467 +#define F_TINTERVALSTART 272 +#define F_TO_ASCII_DEFAULT 1845 +#define F_TO_ASCII_ENC 1846 +#define F_TO_ASCII_ENCNAME 1847 +#define F_INTERVAL_TO_CHAR INTERVALTOCHARFUNCOID +#define F_TIMESTAMPTZ_TO_CHAR TIMESTAMPTZ2CHARFUNCOID +#define F_NUMERIC_TO_CHAR NUMERIC2CHARFUNCOID +#define F_INT4_TO_CHAR INTEGER2CHARFUNCOID +#define F_INT8_TO_CHAR BIGINT2CHARFUNCOID +#define F_FLOAT4_TO_CHAR FLOAT4TOCHARFUNCOID +#define F_FLOAT8_TO_CHAR FLOAT8TOCHARFUNCOID +#define F_TIMESTAMP_TO_CHAR TIMESTAMP2CHARFUNCOID +#define F_TIMESTAMP_TO_CHAR_DEFAULT_FORMAT DEFAULTFORMATTIMESTAMP2CHARFUNCOID +#define F_TIMESTAMPTZ_TO_CHAR_DEFAULT_FORMAT DEFAULTFORMATTIMESTAMPTZ2CHARFUNCOID +#define F_TO_TIMESTAMP TODATEFUNCOID +#define F_TO_DATE_DEFAULT_FORMAT TODATEDEFAULTFUNCOID +#define F_TO_HEX32 2089 +#define F_TO_HEX64 2090 +#define F_NUMERIC_TO_NUMBER TONUMBERFUNCOID +#define F_TO_TIMESTAMP_DEFAULT_FORMAT TOTIMESTAMPDEFAULTFUNCOID +#define F_TO_TSQUERY_BYID 3746 +#define F_TO_TSQUERY 3750 +#define F_TO_TSVECTOR_BYID 3745 +#define F_TO_TSVECTOR 3749 +#define F_TOP_KEY_INTERNAL 6008 +#define F_TOTAL_CPU 3976 +#define F_TOTAL_MEMORY 3979 +#define F_TRACK_MEMORY_CONTEXT 3988 +#define F_TRACK_MEMORY_CONTEXT_DETAIL 3990 +#define F_TRANSLATE 878 +#define F_TRIGGER_IN 2300 +#define F_TRIGGER_OUT 2301 +#define F_MACADDR_TRUNC 753 +#define F_NUMERIC_TRUNC 1709 +#define F_TS_HEADLINE_BYID_OPT 3743 +#define F_TS_HEADLINE_BYID 3744 +#define F_TS_HEADLINE_OPT 3754 +#define F_TS_HEADLINE 3755 +#define F_TS_LEXIZE 3723 +#define F_TS_MATCH_QV 3635 +#define F_TS_MATCH_TQ 3761 +#define F_TS_MATCH_TT 3760 +#define F_TS_MATCH_VQ 3634 +#define F_TS_PARSE_BYID 3715 +#define F_TS_PARSE_BYNAME 3716 +#define F_TS_RANK_WTTF 3703 +#define F_TS_RANK_WTT 3704 +#define F_TS_RANK_TTF 3705 +#define F_TS_RANK_TT 3706 +#define F_TS_RANKCD_WTTF 3707 +#define F_TS_RANKCD_WTT 3708 +#define F_TS_RANKCD_TTF 3709 +#define F_TS_RANKCD_TT 3710 +#define F_TSQUERY_REWRITE 3684 +#define F_TSQUERY_REWRITE_QUERY 3685 +#define F_TS_STAT1 3689 +#define F_TS_STAT2 3690 +#define F_TS_TOKEN_TYPE_BYID 3713 +#define F_TS_TOKEN_TYPE_BYNAME 3714 +#define F_TS_TYPANALYZE 3688 +#define F_TSMATCHJOINSEL 3687 +#define F_TSMATCHSEL 3686 +#define F_TSQ_MCONTAINED 3692 +#define F_TSQ_MCONTAINS 3691 +#define F_TSQUERY_AND 3669 +#define F_TSQUERY_CMP 3668 +#define F_TSQUERY_EQ 3664 +#define F_TSQUERY_GE 3666 +#define F_TSQUERY_GT 3667 +#define F_TSQUERY_LE 3663 +#define F_TSQUERY_LT 3662 +#define F_TSQUERY_NE 3665 +#define F_TSQUERY_NOT 3671 +#define F_TSQUERY_OR 3670 +#define F_TSQUERYIN 3612 +#define F_TSQUERYOUT 3613 +#define F_TSQUERYRECV 3641 +#define F_TSQUERYSEND 3640 +#define F_TSRANGE_SUBDIFF 3929 +#define F_TSTZRANGE_SUBDIFF 3930 +#define F_TSVECTOR_CMP 3622 +#define F_TSVECTOR_CONCAT 3625 +#define F_TSVECTOR_EQ 3618 +#define F_TSVECTOR_GE 3620 +#define F_TSVECTOR_GT 3621 +#define F_TSVECTOR_LE 3617 +#define F_TSVECTOR_LT 3616 +#define F_TSVECTOR_NE 3619 +#define F_TSVECTOR_UPDATE_TRIGGER_BYID 3752 +#define F_TSVECTOR_UPDATE_TRIGGER_BYCOLUMN 3753 +#define F_TSVECTORIN 3610 +#define F_TSVECTOROUT 3611 +#define F_TSVECTORRECV 3639 +#define F_TSVECTORSEND 3638 +#define F_TXID_CURRENT 2943 +#define F_TXID_CURRENT_SNAPSHOT 2944 +#define F_TXID_SNAPSHOT_IN 2939 +#define F_TXID_SNAPSHOT_OUT 2940 +#define F_TXID_SNAPSHOT_RECV 2941 +#define F_TXID_SNAPSHOT_SEND 2942 +#define F_TXID_SNAPSHOT_XIP 2947 +#define F_TXID_SNAPSHOT_XMAX 2946 +#define F_TXID_SNAPSHOT_XMIN 2945 +#define F_TXID_VISIBLE_IN_SNAPSHOT 2948 +#define F_UNIQUE_KEY_RECHECK 1250 +#define F_UNKNOWNIN 109 +#define F_UNKNOWNOUT 110 +#define F_UNKNOWNRECV 2416 +#define F_UNKNOWNSEND 2417 +#define F_ARRAY_UNNEST 2331 +#define F_SYN_UPDATE_PG_JOB 3998 +#define F_UPPER 871 +#define F_RANGE_UPPER 3849 +#define F_RANGE_UPPER_INC 3852 +#define F_RANGE_UPPER_INF 3854 +#define F_UUID_CMP 2960 +#define F_UUID_EQ 2956 +#define F_UUID_GE 2957 +#define F_UUID_GT 2958 +#define F_UUID_HASH 2963 +#define F_UUID_IN 2952 +#define F_UUID_LE 2955 +#define F_UUID_LT 2954 +#define F_UUID_NE 2959 +#define F_UUID_OUT 2953 +#define F_UUID_RECV 2961 +#define F_UUID_SEND 2962 +#define F_VARBIT 1687 +#define F_VARBIT_IN 1579 +#define F_VARBIT_OUT 1580 +#define F_VARBIT_RECV 2458 +#define F_VARBIT_SEND 2459 +#define F_VARBIT_TRANSFORM 3158 +#define F_VARBITTYPMODIN 2902 +#define F_VARBITTYPMODOUT 2921 +#define F_VARCHAR 669 +#define F_VARCHAR_DATE 4162 +#define F_VARCHAR_FLOAT4 4198 +#define F_VARCHAR_FLOAT8 4199 +#define F_VARCHAR_INT4 4174 +#define F_VARCHAR_INT8 4176 +#define F_VARCHAR_NUMERIC 4173 +#define F_VARCHAR_TIMESTAMP 4186 +#define F_VARCHAR_TRANSFORM 3097 +#define F_VARCHARIN 1046 +#define F_VARCHAROUT 1047 +#define F_VARCHARRECV 2432 +#define F_VARCHARSEND 2433 +#define F_VARCHARTYPMODIN 2915 +#define F_VARCHARTYPMODOUT 2916 +#define F_PGSQL_VERSION 89 +#define F_VOID_IN 2298 +#define F_VOID_OUT 2299 +#define F_VOID_RECV 3120 +#define F_VOID_SEND 3121 +#define F_WDR_XDB_QUERY 5713 +#define F_BOX_WIDTH 976 +#define F_WIDTH_BUCKET_FLOAT8 320 +#define F_WIDTH_BUCKET_NUMERIC 2170 +#define F_WORKING_VERSION_NUM 5731 +#define F_XIDEQ 68 +#define F_XIDEQ4 71 +#define F_XIDIN 50 +#define F_XIDIN4 58 +#define F_XIDLT 1320 +#define F_XIDLT4 1322 +#define F_XIDOUT 51 +#define F_XIDOUT4 59 +#define F_XIDRECV 2440 +#define F_XIDRECV4 2779 +#define F_XIDSEND 2441 +#define F_XIDSEND4 2780 +#define F_TEXTTOXML 2896 +#define F_XML_IN 2893 +#define F_XML_IS_WELL_FORMED 3051 +#define F_XML_IS_WELL_FORMED_CONTENT 3053 +#define F_XML_IS_WELL_FORMED_DOCUMENT 3052 +#define F_XML_OUT 2894 +#define F_XML_RECV 2898 +#define F_XML_SEND 2899 +#define F_XMLCOMMENT 2895 +#define F_XMLCONCAT2 2900 +#define F_XMLEXISTS 2614 +#define F_XMLVALIDATE 2897 +#define F_XPATH 2931 +#define F_XPATH_EXISTS 3049 +#define F_ZHPRS_END 3794 +#define F_ZHPRS_GETLEXEME 3793 +#define F_ZHPRS_LEXTYPE 3795 +#define F_ZHPRS_START 3792 + +#define nBuiltinFuncs 3146 + +#define NFMGRFUNCS 3096 + +#endif /* FMGROIDS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/fmgrtab.h postgresql-hll-2.14/include/utils/fmgrtab.h --- postgresql-hll-2.14_old/include/utils/fmgrtab.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/fmgrtab.h 2020-12-12 17:06:43.397349974 +0800 @@ -0,0 +1,204 @@ +/* ------------------------------------------------------------------------- + * + * fmgrtab.h + * The function manager's table of internal functions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/fmgrtab.h + * + * ------------------------------------------------------------------------- + */ +#ifndef FMGRTAB_H +#define FMGRTAB_H + +#include "fmgr.h" +#include "catalog/genbki.h" +#include "catalog/pg_proc.h" +#include "c.h" +#include "utils/fmgroids.h" + +/* + * This table stores info about all the built-in functions (ie, functions + * that are compiled into the Postgres executable). The table entries are + * required to appear in Oid order, so that binary search can be used. + */ + +typedef struct { + Oid foid; /* OID of the function */ + const char* funcName; /* C name of the function */ + short nargs; /* 0..FUNC_MAX_ARGS, or -1 if variable count */ + bool strict; /* T if function is "strict" */ + bool retset; /* T if function returns a set */ + PGFunction func; /* pointer to compiled function */ + Oid rettype; // OID of result type +} FmgrBuiltin; + +/* This table stores all info of all builtin function. It inherits from FmgrBuiltin, but + * unlike FmgrBuiltin, its table entries are required to be ordered by funcName, so that + * binary search on funcName can be used when accessing the function info by function name. + * Caution: the order of argmentes in the strunct cannot be changed!*/ +typedef struct { + Oid foid; /* [ 0] */ + const char* funcName; /* [ 1] C name of the function or procedure name */ + int2 nargs; /* [ 2] number of arguments, 0..FUNC_MAX_ARGS, or -1 if variable count */ + bool strict; /* [ 3] strict with respect to NULLs? */ + bool retset; /* [ 4] returns a set? */ + PGFunction func; /* [ 5] pointer to compiled function */ + Oid rettype; /* [ 6] OID of result type */ + Oid pronamespace; /* [ 7] OID of namespace containing this proc */ + Oid proowner; /* [ 8] procedure owner */ + Oid prolang; /* [ 9] OID of pg_language entry, 12 for internal, 14 for SQL statement */ + float4 procost; /* [10] estimated execution cost */ + float4 prorows; /* [11] estimated # of rows out (if proretset) */ + Oid provariadic; /* [12] element type of variadic array, or 0 */ + regproc protransform; /* [13] transforms calls to it during planning */ + bool proisagg; /* [14] is it an aggregate? */ + bool proiswindow; /* [15] is it a window function? */ + bool prosecdef; /* [16] security definer */ + bool proleakproof; /* [17] is it a leak-proof function? */ + char provolatile; /* [18] see PROVOLATILE_ categories below */ + int2 pronargdefaults; /* [19] number of arguments with defaults */ + + /* variable-length fields start here */ + ArrayOid proargtypes; /* [20] parameter types (excludes OUT params) */ + + /* nullable fields start here, they are defined by pointer, if one of them + * is null pointer, it means it has SQL NULL value */ + ArrayOid* proallargtypes; /* [21] all param types (NULL if IN only) */ + ArrayChar* proargmodes; /* [22] parameter modes (NULL if IN only) */ + ArrayCStr* proargnames; /* [23] parameter names (NULL if no names) */ + const char* proargdefaults; /* [24] list of expression trees for argument defaults (NULL if none) */ + const char* prosrc; /* [25] procedure source text */ + const char* probin; /* [26] secondary procedure info (can be NULL) */ + ArrayCStr* proconfig; /* [27] procedure-local GUC settings */ + ArrayAcl* proacl; /* [28] access permissions */ + ArrayInt2* prodefaultargpos; /* [29] */ + bool* fencedmode; /* [30] */ + bool* proshippable; /* [31] if provolatile is not 'i', proshippable will determine if the func can be shipped */ + bool* propackage; /* [32] */ + const char* descr; /* [33] description */ + char prokind; /* [34] f:function, p:procedure*/ +} Builtin_func; + +/* The function has the same names are put in one group */ +typedef struct { + const char* funcName; + int fnums; /* number of functions in this group */ + Builtin_func* funcs; +} FuncGroup; + +static_assert(sizeof(NULL) == sizeof(void*), "NULL must be a 8 byte-length pointer"); + +/* is null indicator? NULL pointer has size 8 */ +#define isnull_indicator(ind) (sizeof(ind) == sizeof(NULL)) + +/* get the number of arguments from a indicator */ +#define GET_ARGNUMS(ind) DatumGetInt32((Datum)ind) + +#define _SetField(field, value) .field = value +#define _SetPointerField(field, ind, value) .field = (isnull_indicator(ind) ? NULL : (value)) + +/* The following _i(value) Macro is used to set the i-th field of Builtin_func */ +#define _0(funcid) _SetField(foid, funcid) +#define _1(fname) _SetField(funcName, fname) +#define _2(fnargs) _SetField(nargs, fnargs) +#define _3(is_strict) _SetField(strict, is_strict) +#define _4(is_retset) _SetField(retset, is_retset) +#define _5(func_ptr) _SetField(func, func_ptr) +#define _6(ret_oid_type) _SetField(rettype, ret_oid_type) +#define _7(namespace_oid) _SetField(pronamespace, namespace_oid) +#define _8(owner_oid) _SetField(proowner, owner_oid) +#define _9(lang_oid) _SetField(prolang, lang_oid) +#define _10(cost) _SetField(procost, cost) +#define _11(rows) _SetField(prorows, rows) +#define _12(vari_oid) _SetField(provariadic, vari_oid) +#define _13(tansf_oid) _SetField(protransform, tansf_oid) +#define _14(is_agg) _SetField(proisagg, is_agg) +#define _15(is_window) _SetField(proiswindow, is_window) +#define _16(is_secdef) _SetField(prosecdef, is_secdef) +#define _17(is_leakproof) _SetField(proleakproof, is_leakproof) + +/* the set provolatile field, 'i', 's', 'v' */ +#define _18(volt_type) _SetField(provolatile, volt_type) + +#define _19(nargdefaults) _SetField(pronargdefaults, nargdefaults) + +/* Set the value for proargtypes, which is an array, The argument cnt of the Macro + * means the number of elements that are used to initialize the array, + * e.g., _20(3, oid1, oid2, oid3), means the array field hash 3 elements oid1, oid2, and oid3 */ +#define _20(cnt, ...) _SetField(proargtypes, MakeArrayOid(cnt, __VA_ARGS__)) + +/* The following Macros are used for initializing nullable fields. + * For an array field, its initializer is like _xx(ind_cnt, ...), e.g., _21, _22, + * it has two ways to initialize the fields: + * _xx(NULL): indicates the array field is NULL + * _xx(3, e1, e2, e3): indicates the fields is a 3-elements array. + * + * For a single-value field, its initializer is like _xx(ind_ff), e.g., _30, _31, + * it has also two ways to initialize the fields: + * _xx(NULL): indicates the field is NULL + * _xx(fvalue): means the field has the value *fvalue* + * */ +/* Set the proallargtypes field. The input must be an array of Oids, e.g., _21(4, oid1, oid2, oid3, oid4) */ +#define _21(ind_cnt, ...) _SetPointerField(proallargtypes, ind_cnt, MakeArrayOidPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* Set the proargmodes field, The input must be an array of chars: 'i', 'o', 'b', 'v', 't' + * the usage is: _22(3, 'i', 'b', 'o') */ +#define _22(ind_cnt, ...) _SetPointerField(proargmodes, ind_cnt, MakeArrayCharPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* The input must be an array of c-string, e.g., _23(3, "argname1", "argname2", "argname3") */ +#define _23(ind_cnt, ...) _SetPointerField(proargnames, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +#define _24(arg_default_expr_str) _SetField(proargdefaults, arg_default_expr_str) +#define _25(proc_src) _SetField(prosrc, proc_src) +#define _26(bin_info) _SetField(probin, bin_info) + +#define _27(ind_cnt, ...) _SetPointerField(proconfig, ind_cnt, MakeArrayCStrPtr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) +#define _28(ind_cnt, ...) _SetPointerField(proacl, ind_cnt, MakeArrayInt4Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) +#define _29(ind_cnt, ...) \ + _SetPointerField(prodefaultargpos, ind_cnt, MakeArrayInt2Ptr(GET_ARGNUMS(ind_cnt), __VA_ARGS__)) + +/* .fencedmode = ((ind_fmode) == NVL ? NULL : (bool[1]) { ind_fmode }) */ +#define _30(ind_fmode) _SetPointerField(fencedmode, ind_fmode, MakeSingleValuePtr(bool, ind_fmode)) +#define _31(ind_shippable) _SetPointerField(proshippable, ind_shippable, MakeSingleValuePtr(bool, ind_shippable)) +#define _32(ind_is_pkg) _SetPointerField(propackage, ind_is_pkg, MakeSingleValuePtr(bool, ind_is_pkg)) +#define _33(desc_str) _SetField(descr, desc_str) +#define _34(c_prokind) _SetField(prokind, c_prokind) +/* Use Marcos _index() to initialize a built-in function, the indices between 0 ~ 20 are necessary, + * and indices between 21 ~ 32 are optional */ +#define AddBuiltinFunc(...) \ + { \ + __VA_ARGS__ \ + } + +#define AddFuncGroup(groupName, nelem, ...) \ + { \ + .funcName = groupName, .fnums = nelem, .funcs = (Builtin_func[nelem]) \ + { \ + __VA_ARGS__ \ + } \ + } + +extern const FmgrBuiltin fmgr_builtins[]; +extern const FmgrBuiltin* fmgr_isbuiltin(Oid id); + +extern const int fmgr_nbuiltins; /* number of entries in table */ + +/* Store all built-in functions ordered by function oid. Actually, it stores the + * function pointers to g_func_groups for saving memories. */ +extern const Builtin_func* g_sorted_funcs[nBuiltinFuncs]; +extern const FmgrBuiltin* g_fmgr_sorted_builtins[NFMGRFUNCS]; + +/* Store all built-in functions, that are grouped by function name in alphabetical + * order with lower case comparison (see pg_strcasecmp). */ +extern FuncGroup g_func_groups[]; + +extern const int g_nfuncgroups; /* number of function groups */ + +void initBuiltinFuncs(); + +const FuncGroup* SearchBuiltinFuncByName(const char* funcname); +const Builtin_func* SearchBuiltinFuncByOid(Oid id); +#endif /* FMGRTAB_H */ diff -uprN postgresql-hll-2.14_old/include/utils/formatting.h postgresql-hll-2.14/include/utils/formatting.h --- postgresql-hll-2.14_old/include/utils/formatting.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/formatting.h 2020-12-12 17:06:43.397349974 +0800 @@ -0,0 +1,143 @@ +/* ----------------------------------------------------------------------- + * formatting.h + * + * src/include/utils/formatting.h + * + * + * Portions Copyright (c) 1999-2012, PostgreSQL Global Development Group + * + * The PostgreSQL routines for a DateTime/int/float/numeric formatting, + * inspire with Oracle TO_CHAR() / TO_DATE() / TO_NUMBER() routines. + * + * Karel Zak + * + * ----------------------------------------------------------------------- + */ + +#ifndef _FORMATTING_H_ +#define _FORMATTING_H_ + +#include "fmgr.h" + +#define NUM_CACHE_SIZE 64 +#define NUM_CACHE_FIELDS 16 +#define DCH_CACHE_SIZE 128 +#define DCH_CACHE_FIELDS 16 + +/* ---------- + * FromCharDateMode + * ---------- + * + * This value is used to nominate one of several distinct (and mutually + * exclusive) date conventions that a keyword can belong to. + */ +typedef enum { + FROM_CHAR_DATE_NONE = 0, /* Value does not affect date mode. */ + FROM_CHAR_DATE_GREGORIAN, /* Gregorian (day, month, year) style date */ + FROM_CHAR_DATE_ISOWEEK /* ISO 8601 week date */ +} FromCharDateMode; + +typedef struct { + const char* name; + int len; + int id; + bool is_digit; + FromCharDateMode date_mode; +} KeyWord; + +/* ---------- + * Number description struct + * ---------- + */ +typedef struct { + int pre, /* (count) numbers before decimal */ + post, /* (count) numbers after decimal */ + lsign, /* want locales sign */ + flag, /* number parameters */ + pre_lsign_num, /* tmp value for lsign */ + multi, /* multiplier for 'V' */ + zero_start, /* position of first zero */ + zero_end, /* position of last zero */ + need_locale; /* needs it locale */ +} NUMDesc; + +typedef struct FormatNode { + int type; /* node type */ + const KeyWord* key; /* if node type is KEYWORD */ + char character; /* if node type is CHAR */ + int suffix; /* keyword suffix */ +} FormatNode; + +typedef struct DCHCacheEntry { + FormatNode format[DCH_CACHE_SIZE + 1]; + char str[DCH_CACHE_SIZE + 1]; + int age; +} DCHCacheEntry; + +typedef struct NUMCacheEntry { + FormatNode format[NUM_CACHE_SIZE + 1]; + char str[NUM_CACHE_SIZE + 1]; + int age; + NUMDesc Num; +} NUMCacheEntry; + +extern char* str_tolower(const char* buff, size_t nbytes, Oid collid); +extern char* str_toupper(const char* buff, size_t nbytes, Oid collid); +extern char* str_toupper_for_raw(const char* buff, size_t nbytes, Oid collid); +extern char* str_initcap(const char* buff, size_t nbytes, Oid collid); + +extern char* asc_tolower(const char* buff, size_t nbytes); +extern char* asc_toupper(const char* buff, size_t nbytes); +extern char* asc_initcap(const char* buff, size_t nbytes); + +extern Datum timestamp_to_char(PG_FUNCTION_ARGS); +extern Datum timestamptz_to_char(PG_FUNCTION_ARGS); +extern Datum interval_to_char(PG_FUNCTION_ARGS); +extern Datum to_timestamp(PG_FUNCTION_ARGS); +extern Datum to_date(PG_FUNCTION_ARGS); +extern Datum numeric_to_number(PG_FUNCTION_ARGS); +extern Datum numeric_to_char(PG_FUNCTION_ARGS); +extern Datum int4_to_char(PG_FUNCTION_ARGS); +extern Datum int8_to_char(PG_FUNCTION_ARGS); +extern Datum float4_to_char(PG_FUNCTION_ARGS); +extern Datum float8_to_char(PG_FUNCTION_ARGS); +#include "pgtime.h" +#include "datatype/timestamp.h" +extern Datum to_timestamp_default_format(PG_FUNCTION_ARGS); +typedef struct TmToChar { + struct pg_tm tm; /* classic 'tm' struct */ + fsec_t fsec; /* fractional seconds */ + const char* tzn; /* timezone */ +} TmToChar; +#define tmtcTm(_X) (&(_X)->tm) +#define tmtcTzn(_X) ((_X)->tzn) +#define tmtcFsec(_X) ((_X)->fsec) + +extern void Init_NUM_cache(void); + +#define ZERO_tm(_X) \ + do { \ + (_X)->tm_sec = (_X)->tm_year = (_X)->tm_min = (_X)->tm_wday = (_X)->tm_hour = (_X)->tm_yday = (_X)->tm_isdst = \ + 0; \ + (_X)->tm_mday = (_X)->tm_mon = 1; \ + } while (0) + +#define ZERO_tmtc(_X) \ + do { \ + ZERO_tm(tmtcTm(_X)); \ + tmtcFsec(_X) = 0; \ + tmtcTzn(_X) = NULL; \ + } while (0) +extern Datum timestamp_to_char_default_format(PG_FUNCTION_ARGS); +extern Datum timestamptz_to_char_default_format(PG_FUNCTION_ARGS); +extern text* datetime_to_char_body(TmToChar* tmtc, text* fmt, bool is_interval, Oid collid); + +extern void check_datetime_format(char* fmt); +extern void* get_time_format(char* fmt_str); +extern void to_timestamp_from_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* format); +#ifdef ENABLE_UT +extern void general_to_timestamp_from_user_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* in_format); +extern void optimized_to_timestamp_from_user_format(struct pg_tm* tm, fsec_t* fsec, char* date_str, void* in_format); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/geo_decls.h postgresql-hll-2.14/include/utils/geo_decls.h --- postgresql-hll-2.14_old/include/utils/geo_decls.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/geo_decls.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,420 @@ +/* ------------------------------------------------------------------------- + * + * geo_decls.h - Declarations for various 2D constructs. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/geo_decls.h + * + * NOTE + * These routines do *not* use the float types from adt/. + * + * XXX These routines were not written by a numerical analyst. + * + * XXX I have made some attempt to flesh out the operators + * and data types. There are still some more to do. - tgl 97/04/19 + * + * ------------------------------------------------------------------------- + */ +#ifndef GEO_DECLS_H +#define GEO_DECLS_H + +#include + +#include "fmgr.h" + +/* -------------------------------------------------------------------- + * Useful floating point utilities and constants. + * ------------------------------------------------------------------- */ + +#define EPSILON 1.0E-06 + +#ifdef EPSILON +#define FPzero(A) (fabs(A) <= EPSILON) +#define FPeq(A, B) (fabs((A) - (B)) <= EPSILON) +#define FPne(A, B) (fabs((A) - (B)) > EPSILON) +#define FPlt(A, B) ((B) - (A) > EPSILON) +#define FPle(A, B) ((A) - (B) <= EPSILON) +#define FPgt(A, B) ((A) - (B) > EPSILON) +#define FPge(A, B) ((B) - (A) <= EPSILON) +#else +#define FPzero(A) ((A) == 0) +#define FPeq(A, B) ((A) == (B)) +#define FPne(A, B) ((A) != (B)) +#define FPlt(A, B) ((A) < (B)) +#define FPle(A, B) ((A) <= (B)) +#define FPgt(A, B) ((A) > (B)) +#define FPge(A, B) ((A) >= (B)) +#endif + +#define HYPOT(A, B) pg_hypot(A, B) + +/* --------------------------------------------------------------------- + * Point - (x,y) + * ------------------------------------------------------------------- */ +typedef struct { + double x, y; +} Point; + +/* --------------------------------------------------------------------- + * LSEG - A straight line, specified by endpoints. + * ------------------------------------------------------------------- */ +typedef struct { + Point p[2]; + + double m; /* precomputed to save time, not in tuple */ +} LSEG; + +/* --------------------------------------------------------------------- + * PATH - Specified by vertex points. + * ------------------------------------------------------------------- */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 npts; + int32 closed; /* is this a closed polygon? */ + int32 dummy; /* padding to make it double align */ + Point p[FLEXIBLE_ARRAY_MEMBER]; /* variable length array of POINTs */ +} PATH; + +/* --------------------------------------------------------------------- + * LINE - Specified by its general equation (Ax+By+C=0). + * If there is a y-intercept, it is C, which + * incidentally gives a freebie point on the line + * (if B=0, then C is the x-intercept). + * Slope m is precalculated to save time; if + * the line is not vertical, m == A. + * ------------------------------------------------------------------- */ +typedef struct { + double A, B, C; + + double m; +} LINE; + +/* --------------------------------------------------------------------- + * BOX - Specified by two corner points, which are + * sorted to save calculation time later. + * ------------------------------------------------------------------- */ +typedef struct { + Point high, low; /* corner POINTs */ +} BOX; + +/* --------------------------------------------------------------------- + * POLYGON - Specified by an array of doubles defining the points, + * keeping the number of points and the bounding box for + * speed purposes. + * ------------------------------------------------------------------- */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 npts; + BOX boundbox; + Point p[FLEXIBLE_ARRAY_MEMBER]; /* variable length array of POINTs */ +} POLYGON; + +/* --------------------------------------------------------------------- + * CIRCLE - Specified by a center point and radius. + * ------------------------------------------------------------------- */ +typedef struct { + Point center; + double radius; +} CIRCLE; + +/* + * fmgr interface macros + * + * Path and Polygon are toastable varlena types, the others are just + * fixed-size pass-by-reference types. + */ + +#define DatumGetPointP(X) ((Point*)DatumGetPointer(X)) +#define PointPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_POINT_P(n) DatumGetPointP(PG_GETARG_DATUM(n)) +#define PG_RETURN_POINT_P(x) return PointPGetDatum(x) + +#define DatumGetLsegP(X) ((LSEG*)DatumGetPointer(X)) +#define LsegPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_LSEG_P(n) DatumGetLsegP(PG_GETARG_DATUM(n)) +#define PG_RETURN_LSEG_P(x) return LsegPGetDatum(x) + +#define DatumGetPathP(X) ((PATH*)PG_DETOAST_DATUM(X)) +#define DatumGetPathPCopy(X) ((PATH*)PG_DETOAST_DATUM_COPY(X)) +#define PathPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_PATH_P(n) DatumGetPathP(PG_GETARG_DATUM(n)) +#define PG_GETARG_PATH_P_COPY(n) DatumGetPathPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_PATH_P(x) return PathPGetDatum(x) + +#define DatumGetLineP(X) ((LINE*)DatumGetPointer(X)) +#define LinePGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_LINE_P(n) DatumGetLineP(PG_GETARG_DATUM(n)) +#define PG_RETURN_LINE_P(x) return LinePGetDatum(x) + +#define DatumGetBoxP(X) ((BOX*)DatumGetPointer(X)) +#define BoxPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_BOX_P(n) DatumGetBoxP(PG_GETARG_DATUM(n)) +#define PG_RETURN_BOX_P(x) return BoxPGetDatum(x) + +#define DatumGetPolygonP(X) ((POLYGON*)PG_DETOAST_DATUM(X)) +#define DatumGetPolygonPCopy(X) ((POLYGON*)PG_DETOAST_DATUM_COPY(X)) +#define PolygonPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_POLYGON_P(n) DatumGetPolygonP(PG_GETARG_DATUM(n)) +#define PG_GETARG_POLYGON_P_COPY(n) DatumGetPolygonPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_POLYGON_P(x) return PolygonPGetDatum(x) + +#define DatumGetCircleP(X) ((CIRCLE*)DatumGetPointer(X)) +#define CirclePGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_CIRCLE_P(n) DatumGetCircleP(PG_GETARG_DATUM(n)) +#define PG_RETURN_CIRCLE_P(x) return CirclePGetDatum(x) + +/* + * in geo_ops.h + */ + +/* public point routines */ +extern Datum point_in(PG_FUNCTION_ARGS); +extern Datum point_out(PG_FUNCTION_ARGS); +extern Datum point_recv(PG_FUNCTION_ARGS); +extern Datum point_send(PG_FUNCTION_ARGS); +extern Datum construct_point(PG_FUNCTION_ARGS); +extern Datum point_left(PG_FUNCTION_ARGS); +extern Datum point_right(PG_FUNCTION_ARGS); +extern Datum point_above(PG_FUNCTION_ARGS); +extern Datum point_below(PG_FUNCTION_ARGS); +extern Datum point_vert(PG_FUNCTION_ARGS); +extern Datum point_horiz(PG_FUNCTION_ARGS); +extern Datum point_eq(PG_FUNCTION_ARGS); +extern Datum point_ne(PG_FUNCTION_ARGS); +extern Datum point_distance(PG_FUNCTION_ARGS); +extern Datum point_slope(PG_FUNCTION_ARGS); +extern Datum point_add(PG_FUNCTION_ARGS); +extern Datum point_sub(PG_FUNCTION_ARGS); +extern Datum point_mul(PG_FUNCTION_ARGS); +extern Datum point_div(PG_FUNCTION_ARGS); + +/* private routines */ +extern double point_dt(Point* pt1, Point* pt2); +extern double point_sl(Point* pt1, Point* pt2); +extern double pg_hypot(double x, double y); + +/* public lseg routines */ +extern Datum lseg_in(PG_FUNCTION_ARGS); +extern Datum lseg_out(PG_FUNCTION_ARGS); +extern Datum lseg_recv(PG_FUNCTION_ARGS); +extern Datum lseg_send(PG_FUNCTION_ARGS); +extern Datum lseg_intersect(PG_FUNCTION_ARGS); +extern Datum lseg_parallel(PG_FUNCTION_ARGS); +extern Datum lseg_perp(PG_FUNCTION_ARGS); +extern Datum lseg_vertical(PG_FUNCTION_ARGS); +extern Datum lseg_horizontal(PG_FUNCTION_ARGS); +extern Datum lseg_eq(PG_FUNCTION_ARGS); +extern Datum lseg_ne(PG_FUNCTION_ARGS); +extern Datum lseg_lt(PG_FUNCTION_ARGS); +extern Datum lseg_le(PG_FUNCTION_ARGS); +extern Datum lseg_gt(PG_FUNCTION_ARGS); +extern Datum lseg_ge(PG_FUNCTION_ARGS); +extern Datum lseg_construct(PG_FUNCTION_ARGS); +extern Datum lseg_length(PG_FUNCTION_ARGS); +extern Datum lseg_distance(PG_FUNCTION_ARGS); +extern Datum lseg_center(PG_FUNCTION_ARGS); +extern Datum lseg_interpt(PG_FUNCTION_ARGS); +extern Datum dist_pl(PG_FUNCTION_ARGS); +extern Datum dist_ps(PG_FUNCTION_ARGS); +extern Datum dist_ppath(PG_FUNCTION_ARGS); +extern Datum dist_pb(PG_FUNCTION_ARGS); +extern Datum dist_sl(PG_FUNCTION_ARGS); +extern Datum dist_sb(PG_FUNCTION_ARGS); +extern Datum dist_lb(PG_FUNCTION_ARGS); +extern Datum close_lseg(PG_FUNCTION_ARGS); +extern Datum close_pl(PG_FUNCTION_ARGS); +extern Datum close_ps(PG_FUNCTION_ARGS); +extern Datum close_pb(PG_FUNCTION_ARGS); +extern Datum close_sl(PG_FUNCTION_ARGS); +extern Datum close_sb(PG_FUNCTION_ARGS); +extern Datum close_ls(PG_FUNCTION_ARGS); +extern Datum close_lb(PG_FUNCTION_ARGS); +extern Datum on_pl(PG_FUNCTION_ARGS); +extern Datum on_ps(PG_FUNCTION_ARGS); +extern Datum on_pb(PG_FUNCTION_ARGS); +extern Datum on_ppath(PG_FUNCTION_ARGS); +extern Datum on_sl(PG_FUNCTION_ARGS); +extern Datum on_sb(PG_FUNCTION_ARGS); +extern Datum inter_sl(PG_FUNCTION_ARGS); +extern Datum inter_sb(PG_FUNCTION_ARGS); +extern Datum inter_lb(PG_FUNCTION_ARGS); + +/* public line routines */ +extern Datum line_in(PG_FUNCTION_ARGS); +extern Datum line_out(PG_FUNCTION_ARGS); +extern Datum line_recv(PG_FUNCTION_ARGS); +extern Datum line_send(PG_FUNCTION_ARGS); +extern Datum line_interpt(PG_FUNCTION_ARGS); +extern Datum line_distance(PG_FUNCTION_ARGS); +extern Datum line_construct_pp(PG_FUNCTION_ARGS); +extern Datum line_intersect(PG_FUNCTION_ARGS); +extern Datum line_parallel(PG_FUNCTION_ARGS); +extern Datum line_perp(PG_FUNCTION_ARGS); +extern Datum line_vertical(PG_FUNCTION_ARGS); +extern Datum line_horizontal(PG_FUNCTION_ARGS); +extern Datum line_eq(PG_FUNCTION_ARGS); + +/* public box routines */ +extern Datum box_in(PG_FUNCTION_ARGS); +extern Datum box_out(PG_FUNCTION_ARGS); +extern Datum box_recv(PG_FUNCTION_ARGS); +extern Datum box_send(PG_FUNCTION_ARGS); +extern Datum box_same(PG_FUNCTION_ARGS); +extern Datum box_overlap(PG_FUNCTION_ARGS); +extern Datum box_left(PG_FUNCTION_ARGS); +extern Datum box_overleft(PG_FUNCTION_ARGS); +extern Datum box_right(PG_FUNCTION_ARGS); +extern Datum box_overright(PG_FUNCTION_ARGS); +extern Datum box_below(PG_FUNCTION_ARGS); +extern Datum box_overbelow(PG_FUNCTION_ARGS); +extern Datum box_above(PG_FUNCTION_ARGS); +extern Datum box_overabove(PG_FUNCTION_ARGS); +extern Datum box_contained(PG_FUNCTION_ARGS); +extern Datum box_contain(PG_FUNCTION_ARGS); +extern Datum box_contain_pt(PG_FUNCTION_ARGS); +extern Datum box_below_eq(PG_FUNCTION_ARGS); +extern Datum box_above_eq(PG_FUNCTION_ARGS); +extern Datum box_lt(PG_FUNCTION_ARGS); +extern Datum box_gt(PG_FUNCTION_ARGS); +extern Datum box_eq(PG_FUNCTION_ARGS); +extern Datum box_le(PG_FUNCTION_ARGS); +extern Datum box_ge(PG_FUNCTION_ARGS); +extern Datum box_area(PG_FUNCTION_ARGS); +extern Datum box_width(PG_FUNCTION_ARGS); +extern Datum box_height(PG_FUNCTION_ARGS); +extern Datum box_distance(PG_FUNCTION_ARGS); +extern Datum box_center(PG_FUNCTION_ARGS); +extern Datum box_intersect(PG_FUNCTION_ARGS); +extern Datum box_diagonal(PG_FUNCTION_ARGS); +extern Datum points_box(PG_FUNCTION_ARGS); +extern Datum box_add(PG_FUNCTION_ARGS); +extern Datum box_sub(PG_FUNCTION_ARGS); +extern Datum box_mul(PG_FUNCTION_ARGS); +extern Datum box_div(PG_FUNCTION_ARGS); + +/* public path routines */ +extern Datum path_area(PG_FUNCTION_ARGS); +extern Datum path_in(PG_FUNCTION_ARGS); +extern Datum path_out(PG_FUNCTION_ARGS); +extern Datum path_recv(PG_FUNCTION_ARGS); +extern Datum path_send(PG_FUNCTION_ARGS); +extern Datum path_n_lt(PG_FUNCTION_ARGS); +extern Datum path_n_gt(PG_FUNCTION_ARGS); +extern Datum path_n_eq(PG_FUNCTION_ARGS); +extern Datum path_n_le(PG_FUNCTION_ARGS); +extern Datum path_n_ge(PG_FUNCTION_ARGS); +extern Datum path_inter(PG_FUNCTION_ARGS); +extern Datum path_distance(PG_FUNCTION_ARGS); +extern Datum path_length(PG_FUNCTION_ARGS); + +extern Datum path_isclosed(PG_FUNCTION_ARGS); +extern Datum path_isopen(PG_FUNCTION_ARGS); +extern Datum path_npoints(PG_FUNCTION_ARGS); + +extern Datum path_close(PG_FUNCTION_ARGS); +extern Datum path_open(PG_FUNCTION_ARGS); +extern Datum path_add(PG_FUNCTION_ARGS); +extern Datum path_add_pt(PG_FUNCTION_ARGS); +extern Datum path_sub_pt(PG_FUNCTION_ARGS); +extern Datum path_mul_pt(PG_FUNCTION_ARGS); +extern Datum path_div_pt(PG_FUNCTION_ARGS); + +extern Datum path_center(PG_FUNCTION_ARGS); +extern Datum path_poly(PG_FUNCTION_ARGS); + +/* public polygon routines */ +extern Datum poly_in(PG_FUNCTION_ARGS); +extern Datum poly_out(PG_FUNCTION_ARGS); +extern Datum poly_recv(PG_FUNCTION_ARGS); +extern Datum poly_send(PG_FUNCTION_ARGS); +extern Datum poly_left(PG_FUNCTION_ARGS); +extern Datum poly_overleft(PG_FUNCTION_ARGS); +extern Datum poly_right(PG_FUNCTION_ARGS); +extern Datum poly_overright(PG_FUNCTION_ARGS); +extern Datum poly_below(PG_FUNCTION_ARGS); +extern Datum poly_overbelow(PG_FUNCTION_ARGS); +extern Datum poly_above(PG_FUNCTION_ARGS); +extern Datum poly_overabove(PG_FUNCTION_ARGS); +extern Datum poly_same(PG_FUNCTION_ARGS); +extern Datum poly_overlap(PG_FUNCTION_ARGS); +extern Datum poly_contain(PG_FUNCTION_ARGS); +extern Datum poly_contained(PG_FUNCTION_ARGS); +extern Datum poly_contain_pt(PG_FUNCTION_ARGS); +extern Datum pt_contained_poly(PG_FUNCTION_ARGS); +extern Datum poly_distance(PG_FUNCTION_ARGS); +extern Datum poly_npoints(PG_FUNCTION_ARGS); +extern Datum poly_center(PG_FUNCTION_ARGS); +extern Datum poly_box(PG_FUNCTION_ARGS); +extern Datum poly_path(PG_FUNCTION_ARGS); +extern Datum box_poly(PG_FUNCTION_ARGS); + +/* public circle routines */ +extern Datum circle_in(PG_FUNCTION_ARGS); +extern Datum circle_out(PG_FUNCTION_ARGS); +extern Datum circle_recv(PG_FUNCTION_ARGS); +extern Datum circle_send(PG_FUNCTION_ARGS); +extern Datum circle_same(PG_FUNCTION_ARGS); +extern Datum circle_overlap(PG_FUNCTION_ARGS); +extern Datum circle_overleft(PG_FUNCTION_ARGS); +extern Datum circle_left(PG_FUNCTION_ARGS); +extern Datum circle_right(PG_FUNCTION_ARGS); +extern Datum circle_overright(PG_FUNCTION_ARGS); +extern Datum circle_contained(PG_FUNCTION_ARGS); +extern Datum circle_contain(PG_FUNCTION_ARGS); +extern Datum circle_below(PG_FUNCTION_ARGS); +extern Datum circle_above(PG_FUNCTION_ARGS); +extern Datum circle_overbelow(PG_FUNCTION_ARGS); +extern Datum circle_overabove(PG_FUNCTION_ARGS); +extern Datum circle_eq(PG_FUNCTION_ARGS); +extern Datum circle_ne(PG_FUNCTION_ARGS); +extern Datum circle_lt(PG_FUNCTION_ARGS); +extern Datum circle_gt(PG_FUNCTION_ARGS); +extern Datum circle_le(PG_FUNCTION_ARGS); +extern Datum circle_ge(PG_FUNCTION_ARGS); +extern Datum circle_contain_pt(PG_FUNCTION_ARGS); +extern Datum pt_contained_circle(PG_FUNCTION_ARGS); +extern Datum circle_add_pt(PG_FUNCTION_ARGS); +extern Datum circle_sub_pt(PG_FUNCTION_ARGS); +extern Datum circle_mul_pt(PG_FUNCTION_ARGS); +extern Datum circle_div_pt(PG_FUNCTION_ARGS); +extern Datum circle_diameter(PG_FUNCTION_ARGS); +extern Datum circle_radius(PG_FUNCTION_ARGS); +extern Datum circle_distance(PG_FUNCTION_ARGS); +extern Datum dist_pc(PG_FUNCTION_ARGS); +extern Datum dist_cpoly(PG_FUNCTION_ARGS); +extern Datum circle_center(PG_FUNCTION_ARGS); +extern Datum cr_circle(PG_FUNCTION_ARGS); +extern Datum box_circle(PG_FUNCTION_ARGS); +extern Datum circle_box(PG_FUNCTION_ARGS); +extern Datum poly_circle(PG_FUNCTION_ARGS); +extern Datum circle_poly(PG_FUNCTION_ARGS); +extern Datum circle_area(PG_FUNCTION_ARGS); + +/* support routines for the GiST access method (access/gist/gistproc.c) */ +extern Datum gist_box_compress(PG_FUNCTION_ARGS); +extern Datum gist_box_decompress(PG_FUNCTION_ARGS); +extern Datum gist_box_union(PG_FUNCTION_ARGS); +extern Datum gist_box_picksplit(PG_FUNCTION_ARGS); +extern Datum gist_box_consistent(PG_FUNCTION_ARGS); +extern Datum gist_box_penalty(PG_FUNCTION_ARGS); +extern Datum gist_box_same(PG_FUNCTION_ARGS); +extern Datum gist_poly_compress(PG_FUNCTION_ARGS); +extern Datum gist_poly_consistent(PG_FUNCTION_ARGS); +extern Datum gist_circle_compress(PG_FUNCTION_ARGS); +extern Datum gist_circle_consistent(PG_FUNCTION_ARGS); +extern Datum gist_point_compress(PG_FUNCTION_ARGS); +extern Datum gist_point_consistent(PG_FUNCTION_ARGS); +extern Datum gist_point_distance(PG_FUNCTION_ARGS); + +/* geo_selfuncs.c */ +extern Datum areasel(PG_FUNCTION_ARGS); +extern Datum areajoinsel(PG_FUNCTION_ARGS); +extern Datum positionsel(PG_FUNCTION_ARGS); +extern Datum positionjoinsel(PG_FUNCTION_ARGS); +extern Datum contsel(PG_FUNCTION_ARGS); +extern Datum contjoinsel(PG_FUNCTION_ARGS); + +#endif /* GEO_DECLS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/.gitignore postgresql-hll-2.14/include/utils/.gitignore --- postgresql-hll-2.14_old/include/utils/.gitignore 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/.gitignore 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,3 @@ +errcodes.h +fmgroids.h +probes.h diff -uprN postgresql-hll-2.14_old/include/utils/globalplancache.h postgresql-hll-2.14/include/utils/globalplancache.h --- postgresql-hll-2.14_old/include/utils/globalplancache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/globalplancache.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,88 @@ +/* + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 2002-2007, PostgreSQL Global Development Group + * + * 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. + * ------------------------------------------------------------------------- + * + * globalplancache.h + * + * IDENTIFICATION + * src/include/utils/globalplancache.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPLANCACHE_H +#define GLOBALPLANCACHE_H + +#include "knl/knl_variable.h" + +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/globalplancore.h" +#include "executor/spi.h" + + +class GlobalPlanCache : public BaseObject +{ +public: + GlobalPlanCache(); + ~GlobalPlanCache(); + + /* global plan cache htab control */ + void Init(); + CachedPlanSource* Fetch(const char *query_string, uint32 query_len, int num_params, SPISign* spi_sign_ptr); + void DropInvalid(); + void AddInvalidList(CachedPlanSource* plansource); + void RemoveEntry(uint32 htblIdx, GPCEntry *entry); + void RemovePlanSourceInRecreate(CachedPlanSource* plansource); + bool TryStore(CachedPlanSource *plansource, PreparedStatement *ps); + Datum PlanClean(); + /* cnretry and pool reload invalid */ + void InvalidPlanSourceForCNretry(CachedPlanSource* plansource); + void InvalidPlanSourceForReload(CachedPlanSource* plansource, char* stmt_name); + + /* cache invalid */ + void InvalMsg(const SharedInvalidationMessage *msgs, int n); + + /* transaction */ + void RecreateCachePlan(PreparedStatement *entry, const char* stmt_name); + void Commit(); + bool CheckRecreateCachePlan(PreparedStatement *entry); + + void CNCommit(); + void DNCommit(); + + /* system function */ + void* GetStatus(uint32 *num); + + static bool MsgCheck(const SharedInvalidationMessage *msg); + static bool NeedDropEntryByLocalMsg(CachedPlanSource* plansource, int tot, const int *idx, const SharedInvalidationMessage *msgs); + static void GetSchemaName(GPCEnv *env); + static void EnvFill(GPCEnv *env); + static void FillClassicEnvSignatures(GPCEnv *env); + static void FillEnvSignatures(GPCEnv *env); + + /* for spi */ + void SPICommit(CachedPlanSource* plansource); + void SPITryStore(CachedPlanSource* plansource, SPIPlanPtr spi_plan, int nth); + bool CheckRecreateSPICachePlan(SPIPlanPtr spi_plan); + void RecreateSPICachePlan(SPIPlanPtr spi_plan); + void RemovePlanCacheInSPIPlan(SPIPlanPtr plan); + +private: + + GPCHashCtl *m_array; + + DList *m_invalid_list; +}; +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/globalplancore.h postgresql-hll-2.14/include/utils/globalplancore.h --- postgresql-hll-2.14_old/include/utils/globalplancore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/globalplancore.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,269 @@ +/*--------------------------------------------------------------------------------------- + * + * globalplancore.h + * + * global plan cache kernel header + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/utils/globalplancore.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPLANCORE_H +#define GLOBALPLANCORE_H + +#include "executor/spi.h" +#include "executor/spi_priv.h" +#include "knl/knl_variable.h" +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/plancache.h" + +#define GPC_NUM_OF_BUCKETS (128) +#define GPC_HTAB_SIZE (128) +#define GLOBALPLANCACHEKEY_MAGIC (953717831) +#define CAS_SLEEP_DURATION (2) +#define MAX_PREPARE_WAIING_TIME \ + (u_sess->attr.attr_common.SessionTimeout > 1200 ? u_sess->attr.attr_common.SessionTimeout * 2 : 1200 * 2) + +#define ENABLE_GPC (g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) + +#define ENABLE_DN_GPC (IS_PGXC_DATANODE && \ + (!(IS_SINGLE_NODE)) && \ + g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) + +#ifdef ENABLE_MULTIPLE_NODES +#define ENABLE_CN_GPC (IS_PGXC_COORDINATOR && \ + g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) +#else +#define ENABLE_CN_GPC (g_instance.attr.attr_common.enable_global_plancache == true && \ + g_instance.attr.attr_common.enable_thread_pool == true) +#endif + +typedef enum PGXCNode_HandleGPC +{ + HANDLE_RUN, + HANDLE_FIRST_SEND +} PGXCNode_HandleGPC; + + +typedef struct GPCHashCtl +{ + int count; + int lockId; + HTAB *hash_tbl; + MemoryContext context; +} GPCHashCtl; + +typedef struct GPCPlainEnv +{ + Oid database_id; + uint16 env_signature_pgxc; + // stores the bool GUC parameters + uint32 env_signature; + uint32 env_signature2; + int best_agg_plan; // QUERY_TUNING_METHOD + int query_dop_tmp; // QUERY_TUNING + int rewrite_rule; // QUERY_TUNING + int codegen_strategy; // QUERY_TUNING + int plan_mode_seed; // QUERY_TUNING_METHOD + int effective_cache_size; // QUERY_TUNING_COST + int codegen_cost_threshold; // QUERY_TUNING_COST + int geqo_threshold; // QUERY_TUNING_GEQO + int Geqo_effort; // QUERY_TUNING_GEQO + int Geqo_pool_size; // QUERY_TUNING_GEQO + int Geqo_generations; // QUERY_TUNING_GEQO + int default_statistics_target; // QUERY_TUNING_OTHER + int from_collapse_limit; // QUERY_TUNING_OTHER + int join_collapse_limit; // QUERY_TUNING_OTHER + int cost_param; // QUERY_TUNING_OTHER + int schedule_splits_threshold; // QUERY_TUNING_OTHER + int hashagg_table_size; // QUERY_TUNING_OTHER + int constraint_exclusion; // QUERY_TUNING_OTHER + int qrw_inlist2join_optmode;// QUERY_TUNING_OTHER2 + int skew_strategy_store;// QUERY_TUNING_OTHER2 + unsigned int behavior_compat_flags; + int datestyle; + int dateorder; + int plancachemode; // QUERY_TUNING_OTHER + int sql_beta_feature; // QUERY_TUNING + + double seq_page_cost; // QUERY_TUNING_COST + double random_page_cost; // QUERY_TUNING_COST + double cpu_tuple_cost; // QUERY_TUNING_COST + double allocate_mem_cost; // QUERY_TUNING_COST + double cpu_index_tuple_cost; // QUERY_TUNING_COST + double cpu_operator_cost; // QUERY_TUNING_COST + double stream_multiple; // QUERY_TUNING_COST + double default_limit_rows; // QUERY_TUNING_COST + double Geqo_selection_bias; // QUERY_TUNING_GEQO + double Geqo_seed; // QUERY_TUNING_GEQO + double cursor_tuple_fraction; // QUERY_TUNING_OTHER +}GPCPlainEnv; + +typedef struct GPCEnv +{ + bool filled; + GPCPlainEnv plainenv; + + //vary name. + int num_params; + struct OverrideSearchPath* search_path; + char schema_name[NAMEDATALEN]; + char expected_computing_nodegroup[NAMEDATALEN]; // QUERY_TUNING_METHOD + char default_storage_nodegroup[NAMEDATALEN]; // QUERY_TUNING_METHOD +} GPCEnv; + +typedef struct GPCKey +{ + uint32 query_length; + const char *query_string; + GPCEnv env; + SPISign spi_signature; +} GPCKey; + +typedef struct GPCVal +{ + CachedPlanSource* plansource; +}GPCVal; + +typedef struct GPCEntry +{ + /* + * We will hash the query_string and its length to find the hash bucket + */ + GPCKey key; + GPCVal val; + +} GPCEntry; + +typedef struct GPCViewStatus +{ + char *query; + //int option; + int refcount; + bool valid; + Oid DatabaseID; + char *schema_name; + int params_num; + Oid func_id; +} GPCViewStatus; + + +/* + * The data structure representing a prepared statement. This is now just + * a thin veneer over a plancache entry --- the main addition is that of + * a name. + * + * Note: all subsidiary storage lives in the referenced plancache entry. + */ +typedef struct PreparedStatement +{ + /* dynahash.c requires key to be first field */ + char stmt_name[NAMEDATALEN]; + CachedPlanSource *plansource; /* the actual cached plan */ + bool from_sql; /* prepared via SQL, not FE/BE protocol? */ + TimestampTz prepare_time; /* the time when the stmt was prepared */ +} PreparedStatement; + +typedef struct GPCPreparedStatement +{ + sess_orient key; + instr_time last_used_time; + bool sess_detach; + DList* prepare_statement_list; /*the list of the prepare statements of the different queries with the same gid, + *we assume the amount of different prepare statements wont be huge, so we chose + *linked list instead of HTAB*/ +} GPCPreparedStatement; + + +typedef struct GPCPrepareStatus +{ + char *statement_name; + char *query; + int refcount; + uint64 cn_sessid; + uint32 cn_node_id; + uint32 cn_time_line; + bool is_shared; +} GPCPrepareStatus; + +typedef struct TimelineEntry +{ + uint32 node_id; //CN index + uint32 timeline; +} TimelineEntry; + +/* for gpc, help to locate plancache and spiplan */ +typedef struct SPIPlanCacheEnt { + uint32 key; + Oid func_oid; + List* SPIplan_list; + bool is_all_shared; // for gpc, flag for indicate each plancache in this entry is shared + bool is_valid; // invalid or not +} plpgsql_SPIPlanCacheEnt; + +inline uint32 GetBucket(uint32 hashvalue) +{ + return (hashvalue % GPC_NUM_OF_BUCKETS); +} + +extern Datum GPCPlanClean(PG_FUNCTION_ARGS); +extern void GPCResetAll(); +void GPCCleanDatanodeStatement(const CachedPlanSource *plansource, const char* stmt_name); +void GPCReGplan(CachedPlanSource* plansource); + +/* for HTAB SPICacheTable, global procedure plancache */ +extern SPIPlanCacheEnt* SPIPlanCacheTableLookup(uint32 key); +extern void SPIPlanCacheTableDeletePlan(uint32 key, SPIPlanPtr plan); +extern void SPIPlanCacheTableDelete(uint32 key); +extern void SPIPlanCacheTableDeleteFunc(Oid func_oid); +extern void SPICacheTableInit(); +extern void SPICacheTableInsert(uint32 key, Oid func_oid); +extern void SPICacheTableInsertPlan(uint32 key, SPIPlanPtr spi_plan); +extern uint32 SPICacheHashFunc(const void *key, Size keysize); +/* set unique id for each PLpgSQL_expr in func */ +extern void set_func_expr_unique_id(PLpgSQL_function* func); + +inline void gpc_record_log(const char* action, const char* filename, int lineno, + CachedPlanSource* plansource, const char* stmtname) +{ + ereport(DEBUG3, (errmodule(MOD_GPC), errcode(ERRCODE_LOG), + errmsg("GPC (%lu,%u,%u), (Action:%s, Location %s,%d), (dn_session:%lu), plansource %p, stmt: %s ", + u_sess->sess_ident.cn_sessid, u_sess->sess_ident.cn_timeline, u_sess->sess_ident.cn_nodeid, + action, filename, lineno, u_sess->session_id, plansource, stmtname))); +} + +#define GPC_LOG(action, plansource, stmt) \ + (gpc_record_log(action, __FILE__, __LINE__, plansource, stmt)) + +inline void cn_gpc_record_log(const char* action, const char* filename, int lineno, + CachedPlanSource* plansource, const char* stmtname) +{ + ereport(DEBUG3, (errmodule(MOD_GPC), errcode(ERRCODE_LOG), + errmsg("CNGPC (Action:%s, Location %s,%d), (cn_session:%lu), plansource %p, stmt: %s ", + action, filename, lineno, u_sess->session_id, plansource, stmtname))); +} + +#define CN_GPC_LOG(action, plansource, stmt) \ + (cn_gpc_record_log(action, __FILE__, __LINE__, plansource, stmt)) + +inline void GPCCheckGuc() +{ + if (unlikely((u_sess->sess_ident.cn_sessid == 0 && u_sess->sess_ident.cn_timeline == 0 && + u_sess->sess_ident.cn_nodeid == 0 && !IS_PGXC_COORDINATOR))) + ereport(ERROR, (errmodule(MOD_GPC), errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cn does not set enable_global_plancache but %s set", g_instance.attr.attr_common.PGXCNodeName))); +} + +#endif /* GLOBALPLANCORE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/globalpreparestmt.h postgresql-hll-2.14/include/utils/globalpreparestmt.h --- postgresql-hll-2.14_old/include/utils/globalpreparestmt.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/globalpreparestmt.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------------------- + * + * globalplancache.h + * + * global plan cache + * + * __ __ __ __ ___ ___ + * \ \/ / \ \ / / | \ | _ ) + * > < \ V / | |) | | _ \ + * /_/\_\ |_| |___/ |___/ + * + * Portions Copyright (c), Huawei Gauss XuanYuan Database Kernel Team (C) 2020, China + * + * IDENTIFICATION + * ${XuanYuan_Home}/Code/src/include/utils/globalplancache.h + * + *--------------------------------------------------------------------------------------- + */ +#ifndef GLOBALPRESTMT_H +#define GLOBALPRESTMT_H + +#include "knl/knl_variable.h" + +#include "pgxc/pgxc.h" +#include "storage/sinval.h" +#include "utils/globalplancore.h" + +class GlobalPrepareStmt : public BaseObject +{ +public: + GlobalPrepareStmt(); + ~GlobalPrepareStmt(); + + /* cache invalid */ + + void Init(); + void InitCnTimelineHTAB(); + void Store(const char *stmt_name,CachedPlanSource *plansource, bool from_sql, bool is_share); + PreparedStatement *Fetch(const char *stmt_name, bool throwError); + void Drop(const char *stmt_name, bool showError); + void DropAll(sess_orient* key, bool need_lock); + void Clean(uint32 cn_id); + + /* transaction */ + void PrepareCleanUpByTime(bool needCheckTime); + void CleanSessionGPC(knl_session_context* currentSession); + void UpdateUseTime(sess_orient* key, bool sess_detach); + + + void CheckTimeline(); + + /* system function */ + + void* GetStatus(uint32 *num); + +private: + + GPCHashCtl *m_array; + HTAB* m_cn_timeline; +}; + + +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/gs_bitmap.h postgresql-hll-2.14/include/utils/gs_bitmap.h --- postgresql-hll-2.14_old/include/utils/gs_bitmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/gs_bitmap.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,63 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gs_bitmap.h + * about null bitmap set/query actions + * 1. bitmap_size + * 2. bitmap_been_set + * 3. bitmap_set + * + * + * IDENTIFICATION + * src/include/utils/gs_bitmap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CODE_SRC_INCLUDE_NULL_BITMAP_H +#define CODE_SRC_INCLUDE_NULL_BITMAP_H + +/* + * bitmap_size + * Return the bitmap byte-size of x number. + */ +#define bitmap_size(x) (((x) + 7) / 8) + +/* + * @Description: query the value is null or not. + * @IN bitmap: null bitmap + * @IN which: which bit + * @Return: true, if this bit is set to 1; + * false, if this bit is set to 0; + * @See also: BitmapSize() + */ +static inline bool bitmap_been_set(char* bitmap, int which) +{ + return (bitmap[which / 8] & (1 << (which % 8))); +} + +/* + * @Description: set NULL bit in bitmap. + * caller must reset the whole bitmap to 0 first. + * @IN/OUT bitmap: NULL bitmap + * @IN which: which value is null + * @See also: + */ +static inline void bitmap_set(char* bitmap, int which) +{ + bitmap[which / 8] |= (1 << (which % 8)); +} + +#endif /* CODE_SRC_INCLUDE_NULL_BITMAP_H */ diff -uprN postgresql-hll-2.14_old/include/utils/guc.h postgresql-hll-2.14/include/utils/guc.h --- postgresql-hll-2.14_old/include/utils/guc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/guc.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,435 @@ +/* -------------------------------------------------------------------- + * guc.h + * + * External declarations pertaining to backend/utils/misc/guc.c and + * backend/utils/misc/guc-file.l + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * + * src/include/utils/guc.h + * -------------------------------------------------------------------- + */ +#ifndef GUC_H +#define GUC_H + +#include "nodes/parsenodes.h" +#include "tcop/dest.h" +#include "utils/array.h" + +/* upper limit for GUC variables measured in kilobytes of memory */ +/* note that various places assume the byte size fits in a "long" variable */ +#if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4 +#define MAX_KILOBYTES INT_MAX +#else +#define MAX_KILOBYTES (INT_MAX / 1024) +#endif + +/* + * Certain options can only be set at certain times. The rules are + * like this: + * + * INTERNAL options cannot be set by the user at all, but only through + * internal processes ("server_version" is an example). These are GUC + * variables only so they can be shown by SHOW, etc. + * + * POSTMASTER options can only be set when the postmaster starts, + * either from the configuration file or the command line. + * + * SIGHUP options can only be set at postmaster startup or by changing + * the configuration file and sending the HUP signal to the postmaster + * or a backend process. (Notice that the signal receipt will not be + * evaluated immediately. The postmaster and the backend check it at a + * certain point in their main loop. It's safer to wait than to read a + * file asynchronously.) + * + * BACKEND options can only be set at postmaster startup, from the + * configuration file, or by client request in the connection startup + * packet (e.g., from libpq's PGOPTIONS variable). Furthermore, an + * already-started backend will ignore changes to such an option in the + * configuration file. The idea is that these options are fixed for a + * given backend once it's started, but they can vary across backends. + * + * SUSET options can be set at postmaster startup, with the SIGHUP + * mechanism, or from SQL if you're a superuser. + * + * USERSET options can be set by anyone any time. + */ +typedef enum { PGC_INTERNAL, PGC_POSTMASTER, PGC_SIGHUP, PGC_BACKEND, PGC_SUSET, PGC_USERSET } GucContext; + +/* + * The following type records the source of the current setting. A + * new setting can only take effect if the previous setting had the + * same or lower level. (E.g, changing the config file doesn't + * override the postmaster command line.) Tracking the source allows us + * to process sources in any convenient order without affecting results. + * Sources <= PGC_S_OVERRIDE will set the default used by RESET, as well + * as the current value. Note that source == PGC_S_OVERRIDE should be + * used when setting a PGC_INTERNAL option. + * + * PGC_S_INTERACTIVE isn't actually a source value, but is the + * dividing line between "interactive" and "non-interactive" sources for + * error reporting purposes. + * + * PGC_S_TEST is used when testing values to be stored as per-database or + * per-user defaults ("doit" will always be false, so this never gets stored + * as the actual source of any value). This is an interactive case, but + * it needs its own source value because some assign hooks need to make + * different validity checks in this case. + * + * NB: see GucSource_Names in guc.c if you change this. + */ +typedef enum { + PGC_S_DEFAULT, /* hard-wired default ("boot_val") */ + PGC_S_DYNAMIC_DEFAULT, /* default computed during initialization */ + PGC_S_ENV_VAR, /* postmaster environment variable */ + PGC_S_FILE, /* postgresql.conf */ + PGC_S_ARGV, /* postmaster command line */ + PGC_S_DATABASE, /* per-database setting */ + PGC_S_USER, /* per-user setting */ + PGC_S_DATABASE_USER, /* per-user-and-database setting */ + PGC_S_CLIENT, /* from client connection request */ + PGC_S_OVERRIDE, /* special case to forcibly set default */ + PGC_S_INTERACTIVE, /* dividing line for error reporting */ + PGC_S_TEST, /* test per-database or per-user setting */ + PGC_S_SESSION /* SET command */ +} GucSource; + +/* + * Parsing the configuration file will return a list of name-value pairs + * with source location info. + */ +typedef struct ConfigVariable { + char* name; + char* value; + char* filename; + int sourceline; + struct ConfigVariable* next; +} ConfigVariable; + +extern bool ParseConfigFile(const char* config_file, const char* calling_file, bool strict, int depth, int elevel, + ConfigVariable** head_p, ConfigVariable** tail_p); +extern bool ParseConfigFp( + FILE* fp, const char* config_file, int depth, int elevel, ConfigVariable** head_p, ConfigVariable** tail_p); +extern void FreeConfigVariables(ConfigVariable* list); + +/* + * The possible values of an enum variable are specified by an array of + * name-value pairs. The "hidden" flag means the value is accepted but + * won't be displayed when guc.c is asked for a list of acceptable values. + */ +struct config_enum_entry { + const char* name; + int val; + bool hidden; +}; + +/* + * Signatures for per-variable check/assign/show hook functions + */ +typedef bool (*GucBoolCheckHook)(bool* newval, void** extra, GucSource source); +typedef bool (*GucIntCheckHook)(int* newval, void** extra, GucSource source); +typedef bool (*GucInt64CheckHook)(int64* newval, void** extra, GucSource source); +typedef bool (*GucRealCheckHook)(double* newval, void** extra, GucSource source); +typedef bool (*GucStringCheckHook)(char** newval, void** extra, GucSource source); +typedef bool (*GucEnumCheckHook)(int* newval, void** extra, GucSource source); + +typedef void (*GucBoolAssignHook)(bool newval, void* extra); +typedef void (*GucIntAssignHook)(int newval, void* extra); +typedef void (*GucInt64AssignHook)(int64 newval, void* extra); +typedef void (*GucRealAssignHook)(double newval, void* extra); +typedef void (*GucStringAssignHook)(const char* newval, void* extra); +typedef void (*GucEnumAssignHook)(int newval, void* extra); + +typedef const char* (*GucShowHook)(void); + +/* + * Miscellaneous + */ +typedef enum { + /* Types of set_config_option actions */ + GUC_ACTION_SET, /* regular SET command */ + GUC_ACTION_LOCAL, /* SET LOCAL command */ + GUC_ACTION_SAVE /* function SET option, or temp assignment */ +} GucAction; + +/* set params entry */ +typedef struct { + char name[NAMEDATALEN]; /* param name */ + char* query; /* set query string */ +} GucParamsEntry; + +#define GUC_QUALIFIER_SEPARATOR '.' + +/* + * bit values in "flags" of a GUC variable + */ +#define GUC_LIST_INPUT 0x0001 /* input can be list format */ +#define GUC_LIST_QUOTE 0x0002 /* double-quote list elements */ +#define GUC_NO_SHOW_ALL 0x0004 /* exclude from SHOW ALL */ +#define GUC_NO_RESET_ALL 0x0008 /* exclude from RESET ALL */ +#define GUC_REPORT 0x0010 /* auto-report changes to client */ +#define GUC_NOT_IN_SAMPLE 0x0020 /* not in postgresql.conf.sample */ +#define GUC_DISALLOW_IN_FILE 0x0040 /* can't set in postgresql.conf */ +#define GUC_CUSTOM_PLACEHOLDER 0x0080 /* placeholder for custom variable */ +#define GUC_SUPERUSER_ONLY 0x0100 /* show only to superusers */ +#define GUC_IS_NAME 0x0200 /* limit string to NAMEDATALEN-1 */ + +#define GUC_UNIT_KB 0x0400 /* value is in kilobytes */ +#define GUC_UNIT_BLOCKS 0x0800 /* value is in blocks */ +#define GUC_UNIT_XBLOCKS 0x0C00 /* value is in xlog blocks */ +#define GUC_UNIT_MEMORY 0x0C00 /* mask for KB, BLOCKS, XBLOCKS */ + +#define GUC_UNIT_MS 0x1000 /* value is in milliseconds */ +#define GUC_UNIT_S 0x2000 /* value is in seconds */ +#define GUC_UNIT_MIN 0x4000 /* value is in minutes */ +#define GUC_UNIT_HOUR 0x5000 /* value is in hour */ +#define GUC_UNIT_TIME 0x7000 /* mask for MS, S, MIN */ + +#define GUC_NOT_WHILE_SEC_REST 0x8000 /* can't set if security restricted */ + +extern THR_LOCAL int log_min_messages; +extern THR_LOCAL bool force_backtrace_messages; +extern THR_LOCAL int client_min_messages; +extern THR_LOCAL int comm_ackchk_time; + +#define SHOW_DEBUG_MESSAGE() (SECUREC_UNLIKELY(log_min_messages <= DEBUG1)) + +/* + * Functions exported by guc.c + */ +extern void SetConfigOption(const char* name, const char* value, GucContext context, GucSource source); + +extern void DefineCustomBoolVariable(const char* name, const char* short_desc, const char* long_desc, bool* valueAddr, + bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, + GucShowHook show_hook); + +extern void DefineCustomIntVariable(const char* name, const char* short_desc, const char* long_desc, int* valueAddr, + int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, + GucIntAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomInt64Variable(const char* name, const char* short_desc, const char* long_desc, int64* valueAddr, + int64 bootValue, int64 minValue, int64 maxValue, GucContext context, int flags, GucInt64CheckHook check_hook, + GucInt64AssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomRealVariable(const char* name, const char* short_desc, const char* long_desc, double* valueAddr, + double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, + GucRealAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomStringVariable(const char* name, const char* short_desc, const char* long_desc, + char** valueAddr, const char* bootValue, GucContext context, int flags, GucStringCheckHook check_hook, + GucStringAssignHook assign_hook, GucShowHook show_hook); + +extern void DefineCustomEnumVariable(const char* name, const char* short_desc, const char* long_desc, int* valueAddr, + int bootValue, const struct config_enum_entry* options, GucContext context, int flags, GucEnumCheckHook check_hook, + GucEnumAssignHook assign_hook, GucShowHook show_hook); + +extern void EmitWarningsOnPlaceholders(const char* className); + +extern const char* GetConfigOption(const char* name, bool missing_ok, bool restrict_superuser); +extern const char* GetConfigOptionResetString(const char* name); +extern void ProcessConfigFile(GucContext context); +extern void InitializeGUCOptions(void); +extern void InitializePostmasterGUC(); +extern void init_sync_guc_variables(void); +extern void repair_guc_variables(void); +extern bool SelectConfigFiles(const char* userDoption, const char* progname); +extern void ResetAllOptions(void); +extern void AtStart_GUC(void); +extern int NewGUCNestLevel(void); +extern void AtEOXact_GUC(bool isCommit, int nestLevel); +extern char* GetGucName(const char *command, char *target_guc_name); +extern void BeginReportingGUCOptions(void); +extern void ParseLongOption(const char* string, char** name, char** value); +extern bool parse_int(const char* value, int* result, int flags, const char** hintmsg); +extern bool parse_int64(const char* value, int64* result, const char** hintmsg); +extern bool parse_real(const char* value, double* result); +extern int set_config_option(const char* name, const char* value, GucContext context, GucSource source, + GucAction action, bool changeVal, int elevel, bool isReload = false); +#ifndef ENABLE_MULTIPLE_NODES +extern void AlterSystemSetConfigFile(AlterSystemStmt* setstmt); +extern void validate_name_and_arguments_in_alter_system_set(AlterSystemStmt* altersysstmt); +#endif +extern char* GetConfigOptionByName(const char* name, const char** varname); +extern void GetConfigOptionByNum(int varnum, const char** values, bool* noshow); +extern int GetNumConfigOptions(void); + +extern void SetPGVariable(const char* name, List* args, bool is_local); +extern void GetPGVariable(const char* name, DestReceiver* dest); +extern TupleDesc GetPGVariableResultDesc(const char* name); + +#ifdef PGXC +extern char* RewriteBeginQuery(char* query_string, const char* name, List* args); +#endif + +extern void ExecSetVariableStmt(VariableSetStmt* stmt); +extern char* ExtractSetVariableArgs(VariableSetStmt* stmt); + +extern void ProcessGUCArray(ArrayType* array, GucContext context, GucSource source, GucAction action); +extern ArrayType* GUCArrayAdd(ArrayType* array, const char* name, const char* value); +extern ArrayType* GUCArrayDelete(ArrayType* array, const char* name); +extern ArrayType* GUCArrayReset(ArrayType* array); + +#ifdef EXEC_BACKEND +extern void write_nondefault_variables(GucContext context); +extern void read_nondefault_variables(void); +#endif + +extern void GUC_check_errcode(int sqlerrcode); + +#define GUC_check_errmsg \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errmsg_string = format_elog_string + +#define GUC_check_errdetail \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errdetail_string = format_elog_string + +#define GUC_check_errhint \ + pre_format_elog_string(errno, TEXTDOMAIN), u_sess->utils_cxt.GUC_check_errhint_string = format_elog_string + +#define guc_free(p) \ + do { \ + if (p != NULL) { \ + free(p); \ + p = NULL; \ + } \ + } while (0) + +/* + * The following functions are not in guc.c, but are declared here to avoid + * having to include guc.h in some widely used headers that it really doesn't + * belong in. + */ + +/* in commands/tablespace.c */ +extern bool check_default_tablespace(char** newval, void** extra, GucSource source); +extern bool check_temp_tablespaces(char** newval, void** extra, GucSource source); +extern void assign_temp_tablespaces(const char* newval, void* extra); + +/* in catalog/namespace.c */ +extern bool check_search_path(char** newval, void** extra, GucSource source); +extern void assign_search_path(const char* newval, void* extra); +extern bool check_percentile(char** newval, void** extra, GucSource source); +extern bool check_numa_distribute_mode(char** newval, void** extra, GucSource source); +extern bool check_asp_flush_mode(char** newval, void** extra, GucSource source); + +/* in access/transam/xlog.c */ +extern bool check_wal_buffers(int* newval, void** extra, GucSource source); +extern void assign_xlog_sync_method(int new_sync_method, void* extra); + +/* in tcop/stmt_retry.cpp */ +extern bool check_errcode_list(char** newval, void** extra, GucSource source); +#define RESERVE_SIZE 33 + +/* + * Error code for config file + */ +typedef enum { + CODE_OK = 0, /* success */ + CODE_UNKNOW_CONFFILE_PATH, /* fail to get the specified config file */ + CODE_OPEN_CONFFILE_FAILED, /* fail to open config file */ + CODE_CLOSE_CONFFILE_FAILED, /* fail to close config file */ + CODE_READE_CONFFILE_ERROR, /* fail to read config file */ + CODE_WRITE_CONFFILE_ERROR, /* fail to write config file */ + CODE_LOCK_CONFFILE_FAILED, + CODE_UNLOCK_CONFFILE_FAILED, + CODE_INTERNAL_ERROR +} ErrCode; + +typedef enum { + NO_REWRITE = 0, /* not allow lazy agg and magic set rewrite*/ + LAZY_AGG = 1, /* allow lazy agg */ + MAGIC_SET = 2, /* allow query qual push */ + PARTIAL_PUSH = 4, /* allow partial push */ + SUBLINK_PULLUP_WITH_UNIQUE_CHECK = 8, /* allow pull sublink with unqiue check */ + SUBLINK_PULLUP_DISABLE_REPLICATED = 16, /* disable pull up sublink with replicated table */ + SUBLINK_PULLUP_IN_TARGETLIST = 32, /* allow pull sublink in targetlist */ + PRED_PUSH = 64, /* push predicate into subquery block */ + PRED_PUSH_NORMAL = 128, + PRED_PUSH_FORCE = 256, +} rewrite_param; + +typedef enum { + NO_BETA_FEATURE = 0, + SEL_SEMI_POISSON = 1, /* use poisson distribution model to calibrate semi join selectivity */ + SEL_EXPR_INSTR = 2, /* use pattern sel to calibrate instr() related base rel selectivity */ + PARAM_PATH_GEN = 4, /* Parametrized Path Generation */ + RAND_COST_OPT = 8, /* Optimizing sc_random_page_cost */ + PARAM_PATH_OPT = 16, /* Parametrized Path Optimization. */ + PAGE_EST_OPT = 32 /* More accurate (rowstored) index pages estimation */ +} sql_beta_param; + +#define ENABLE_PRED_PUSH(root) \ + ((PRED_PUSH & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_NORMAL(root) \ + ((PRED_PUSH_NORMAL & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_FORCE(root) \ + ((PRED_PUSH_FORCE & (uint)u_sess->attr.attr_sql.rewrite_rule) && permit_predpush(root)) + +#define ENABLE_PRED_PUSH_ALL(root) \ + ((ENABLE_PRED_PUSH(root) || ENABLE_PRED_PUSH_NORMAL(root) || ENABLE_PRED_PUSH_FORCE(root)) && permit_predpush(root)) + +#define ENABLE_SQL_BETA_FEATURE(feature) \ + ((bool)((uint)u_sess->attr.attr_sql.sql_beta_feature & feature)) + +typedef enum { + SUMMARY = 0, /* not collect multi column statistics info */ + DETAIL = 1, /* collect multi column statistics info */ +} resource_track_log_param; + +typedef struct { + FILE* fp; + size_t size; +} ConfFileLock; + +#define PG_LOCKFILE_SIZE 1024 +extern void* pg_malloc(size_t size); +extern char* xstrdup(const char* s); + +extern char** read_guc_file(const char* path); +extern ErrCode write_guc_file(const char* path, char** lines); +extern int find_guc_option( + char** optlines, const char* opt_name, int* name_offset, int* name_len, int* value_offset, int* value_len); + +extern void modify_guc_lines(char*** optlines, const char** opt_name, char** copy_from_line); +extern ErrCode copy_guc_lines(char** copy_to_line, char** optlines, const char** opt_name); +extern ErrCode copy_asyn_lines(char* path, char** copy_to_line, const char** opt_name); + +extern ErrCode generate_temp_file(char* buf, char* temppath, size_t size); +extern ErrCode update_temp_file(char* tempfilepath, char** copy_to_line, const char** opt_name); +extern ErrCode get_file_lock(const char* path, ConfFileLock* filelock); +extern void release_file_lock(ConfFileLock* filelock); + +extern void comment_guc_lines(char** optlines, const char** opt_name); +extern int add_guc_optlines_to_buffer(char** optlines, char** buffer); + +/*Add for set command in transaction*/ +extern char* get_set_string(); +extern void reset_set_message(bool); +extern void append_set_message(const char* str); + +extern void init_set_params_htab(void); +extern void make_set_message(void); +extern int check_set_message_to_send(const VariableSetStmt* stmt, const char* queryString); + +#define TRANS_ENCRYPT_SAMPLE_RNDM "1234567890ABCDEF" +#define TRANS_ENCRYPT_SAMPLE_STRING "TRANS_ENCRY_SAMPLE_STRING" + +/* For transparent encryption. For more information, + * see the definition of this variable. + */ +extern THR_LOCAL char* transparent_encrypted_string; +extern THR_LOCAL char* transparent_encrypt_kms_url; +extern THR_LOCAL char* transparent_encrypt_kms_region; + +extern void release_opt_lines(char** opt_lines); +extern char** alloc_opt_lines(int opt_lines_num); + +#ifdef ENABLE_QUNIT +extern void set_qunit_case_number_hook(int newval, void* extra); +#endif + +extern GucContext get_guc_context(); + +#endif /* GUC_H */ diff -uprN postgresql-hll-2.14_old/include/utils/guc_mn.h postgresql-hll-2.14/include/utils/guc_mn.h --- postgresql-hll-2.14_old/include/utils/guc_mn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/guc_mn.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,22 @@ +/* -------------------------------------------------------------------- + * guc.h + * + * External declarations pertaining to backend/utils/misc/guc.c and + * backend/utils/misc/guc-file.l + * + * Copyright (c) 2000-2012, PostgreSQL Global Development Group + * Written by Peter Eisentraut . + * + * src/include/utils/guc.h + * -------------------------------------------------------------------- + */ +#ifndef GUC_MN_H +#define GUC_MN_H + +extern void InitConfigureNamesBoolMultipleNode(); +extern void InitConfigureNamesIntMultipleNode(); +extern void InitConfigureNamesRealMultipleNode(); +extern void InitConfigureNamesStringMultipleNode(); +extern bool check_enable_gtm_free(bool* newval, void** extra, GucSource source); + +#endif /* GUC_MN_H */ diff -uprN postgresql-hll-2.14_old/include/utils/guc_tables.h postgresql-hll-2.14/include/utils/guc_tables.h --- postgresql-hll-2.14_old/include/utils/guc_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/guc_tables.h 2020-12-12 17:06:43.398349987 +0800 @@ -0,0 +1,279 @@ +/* ------------------------------------------------------------------------- + * + * guc_tables.h + * Declarations of tables used by GUC. + * + * See src/backend/utils/misc/README for design notes. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/utils/guc_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef GUC_TABLES_H +#define GUC_TABLES_H 1 + +#include "utils/guc.h" + +/* + * GUC supports these types of variables: + */ +enum config_type { PGC_BOOL, PGC_INT, PGC_INT64, PGC_REAL, PGC_STRING, PGC_ENUM }; + +union config_var_val { + bool boolval; + int intval; + int64 int64val; + double realval; + char* stringval; + int enumval; +}; + +/* + * The actual value of a GUC variable can include a malloc'd opaque struct + * "extra", which is created by its check_hook and used by its assign_hook. + */ +typedef struct config_var_value { + union config_var_val val; + void* extra; +} config_var_value; + +/* + * Groupings to help organize all the run-time options for display + */ +enum config_group { + UNGROUPED, + FILE_LOCATIONS, + CONN_AUTH, + CONN_AUTH_SETTINGS, + CONN_AUTH_SECURITY, + RESOURCES, + RESOURCES_MEM, + RESOURCES_DISK, + RESOURCES_KERNEL, + RESOURCES_VACUUM_DELAY, + RESOURCES_BGWRITER, + RESOURCES_ASYNCHRONOUS, + RESOURCES_RECOVERY, + RESOURCES_WORKLOAD, + WAL, + WAL_SETTINGS, + WAL_CHECKPOINTS, + WAL_ARCHIVING, + REPLICATION, + REPLICATION_SENDING, + REPLICATION_MASTER, + REPLICATION_STANDBY, + QUERY_TUNING, + QUERY_TUNING_METHOD, + QUERY_TUNING_COST, + QUERY_TUNING_GEQO, + QUERY_TUNING_OTHER, + LOGGING, + LOGGING_WHERE, + LOGGING_WHEN, + LOGGING_WHAT, + /* add audit config group. */ + AUDIT_OPTIONS, + STATS, + STATS_MONITORING, + STATS_COLLECTOR, + STREAMING, + AUTOVACUUM, + JOB, + CLIENT_CONN, + CLIENT_CONN_STATEMENT, + CLIENT_CONN_LOCALE, + CLIENT_CONN_OTHER, + LOCK_MANAGEMENT, + COMPAT_OPTIONS, + COMPAT_OPTIONS_PREVIOUS, + COMPAT_OPTIONS_CLIENT, + ERROR_HANDLING_OPTIONS, + PRESET_OPTIONS, + CUSTOM_OPTIONS, + TEXT_SEARCH, + DEVELOPER_OPTIONS, + UPGRADE_OPTIONS, + TSDB, + INSTRUMENTS_OPTIONS, + CE_OPTIONS, +#ifdef PGXC + DATA_NODES, + GTM, + COORDINATORS, + XC_HOUSEKEEPING_OPTIONS +#endif +}; + +/* + * Stack entry for saving the state a variable had prior to an uncommitted + * transactional change + */ +typedef enum { + /* This is almost GucAction, but we need a fourth state for SET+LOCAL */ + GUC_SAVE, /* entry caused by function SET option */ + GUC_SET, /* entry caused by plain SET command */ + GUC_LOCAL, /* entry caused by SET LOCAL command */ + GUC_SET_LOCAL /* entry caused by SET then SET LOCAL */ +} GucStackState; + +typedef struct guc_stack { + struct guc_stack* prev; /* previous stack item, if any */ + int nest_level; /* nesting depth at which we made entry */ + GucStackState state; /* see enum above */ + GucSource source; /* source of the prior value */ + /* masked value's source must be PGC_S_SESSION, so no need to store it */ + GucContext scontext; /* context that set the prior value */ + GucContext masked_scontext; /* context that set the masked value */ + config_var_value prior; /* previous value of variable */ + config_var_value masked; /* SET value in a GUC_SET_LOCAL entry */ +} GucStack; + +/* + * Generic fields applicable to all types of variables + * + * The short description should be less than 80 chars in length. Some + * applications may use the long description as well, and will append + * it to the short description. (separated by a newline or '. ') + * + * Note that sourcefile/sourceline are kept here, and not pushed into stacked + * values, although in principle they belong with some stacked value if the + * active value is session- or transaction-local. This is to avoid bloating + * stack entries. We know they are only relevant when source == PGC_S_FILE. + */ +struct config_generic { + /* constant fields, must be set correctly in initial value: */ + const char* name; /* name of variable - MUST BE FIRST */ + GucContext context; /* context required to set the variable */ + enum config_group group; /* to help organize variables by function */ + const char* short_desc; /* short desc. of this variable's purpose */ + const char* long_desc; /* long desc. of this variable's purpose */ + int flags; /* flag bits, see guc.h */ + /* variable fields, initialized at runtime: */ + enum config_type vartype; /* type of variable (set only at startup) */ + int status; /* status bits, see below */ + GucSource source; /* source of the current actual value */ + GucSource reset_source; /* source of the reset_value */ + GucContext scontext; /* context that set the current value */ + GucContext reset_scontext; /* context that set the reset value */ + GucStack* stack; /* stacked prior values */ + void* extra; /* "extra" pointer for current actual value */ + char* sourcefile; /* file current setting is from (NULL if not + * set in config file) */ + int sourceline; /* line in source file */ +}; + +extern const char* sync_guc_variable_namelist[]; + +/* bit values in status field */ +#define GUC_IS_IN_FILE 0x0001 /* found it in config file */ +/* + * Caution: the GUC_IS_IN_FILE bit is transient state for ProcessConfigFile. + * Do not assume that its value represents useful information elsewhere. + */ + +/* GUC records for specific variable types */ + +struct config_bool { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + bool* variable; + bool boot_val; + GucBoolCheckHook check_hook; + GucBoolAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + bool reset_val; + void* reset_extra; +}; + +struct config_int { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + int min; + int max; + GucIntCheckHook check_hook; + GucIntAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +struct config_int64 { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int64* variable; + int64 boot_val; + int64 min; + int64 max; + GucInt64CheckHook check_hook; + GucInt64AssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int64 reset_val; + void* reset_extra; +}; + +struct config_real { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + double* variable; + double boot_val; + double min; + double max; + GucRealCheckHook check_hook; + GucRealAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + double reset_val; + void* reset_extra; +}; + +struct config_string { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + char** variable; + const char* boot_val; + GucStringCheckHook check_hook; + GucStringAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + char* reset_val; + void* reset_extra; +}; + +struct config_enum { + struct config_generic gen; + /* constant fields, must be set correctly in initial value: */ + int* variable; + int boot_val; + const struct config_enum_entry* options; + GucEnumCheckHook check_hook; + GucEnumAssignHook assign_hook; + GucShowHook show_hook; + /* variable fields, initialized at runtime: */ + int reset_val; + void* reset_extra; +}; + +/* constant tables corresponding to enums above and in guc.h */ +extern const char* const config_group_names[]; +extern const char* const config_type_names[]; +extern const char* const GucContext_Names[]; +extern const char* const GucSource_Names[]; + +/* get the current set of variables */ +extern struct config_generic** get_guc_variables(void); + +extern void build_guc_variables(void); + +/* search in enum options */ +extern const char* config_enum_lookup_by_value(struct config_enum* record, int val); +extern bool config_enum_lookup_by_name(struct config_enum* record, const char* value, int* retval); + +#endif /* GUC_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/utils/hashutils.h postgresql-hll-2.14/include/utils/hashutils.h --- postgresql-hll-2.14_old/include/utils/hashutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/hashutils.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * hashutils.h + * Utilities for working with hash values. + * + * + * IDENTIFICATION + * src/include/utils/hashutils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef HASHUTILS_H +#define HASHUTILS_H + +/* + * Simple inline murmur hash implementation hashing a 32 bit integer, for + * performance. + */ +static inline uint32 murmurhash32(uint32 data) +{ + uint32 h = data; + + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + return h; +} + +#endif /* HASHUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/help_config.h postgresql-hll-2.14/include/utils/help_config.h --- postgresql-hll-2.14_old/include/utils/help_config.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/help_config.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,17 @@ +/* ------------------------------------------------------------------------- + * + * help_config.h + * Interface to the --help-config option of main.c + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * + * src/include/utils/help_config.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HELP_CONFIG_H +#define HELP_CONFIG_H 1 + +extern int GucInfoMain(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/hotkey.h postgresql-hll-2.14/include/utils/hotkey.h --- postgresql-hll-2.14_old/include/utils/hotkey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/hotkey.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,103 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * + * 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. + * --------------------------------------------------------------------------------------- + * + * hotkey.h + * + * + * + * IDENTIFICATION + * src/include/utils/hotkey.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef SRC_INCLUDE_UTILS_HOTKEYS_H +#define SRC_INCLUDE_UTILS_HOTKEYS_H + +#include "postgres.h" +#include "pgstat.h" +#include "pgxc/locator.h" +#include "nodes/nodes.h" +#include "nodes/pg_list.h" +#include "lib/lrucache.h" + +const int LRU_QUEUE_LENGTH = 16; +const int HOTKEYS_QUEUE_LENGTH = 500; +const int FIFO_QUEUE_LENGTH = 32; + +/* basic hotkey info to be present */ +typedef struct HotkeyValue { + char* databaseName; + char* schemaName; + char* relName; + List* constValues; /* List of const nodes */ + Size totalLength; /* Total length of values */ +} HotkeyValue; + +/* missing hotkey info for DFX */ +typedef struct HotkeyMissInfo { + char* databaseName; + char* schemaName; + char* relName; + char* missInfo; +} HotkeyMissInfo; + +/* Hotkey candidates collected from plan */ +typedef struct HotkeyCandidate { + Oid relid; + uint32 hashValue; + HotkeyValue* hotkeyValue; +} HotkeyCandidate; + +/* HotkeyInfo structure */ +typedef struct HotkeyInfo { + uint64 count; /* counter of key */ + Oid relationOid; /* OID of relation the queries depend on */ + Oid databaseOid; /* database oid */ + uint32 hashValue; /* hash value of key */ + HotkeyValue* hotkeyValue; +} HotkeyInfo; + +/* Hotkey statistics info present to caller */ +typedef struct HotkeyGeneralInfo { + char* database; + char* schema; + char* table; + char* value; + uint32 hashValue; + uint64 count; +} HotkeyGeneralInfo; + +extern void CleanHotkeyCandidates(bool deep); +extern bool CmdtypeSupportsHotkey(CmdType commandType); +extern bool ExecOnSingleNode(List* nodeList); +extern void InsertKeysToLRU(HotkeyInfo** temp, int length); +extern void ReportHotkeyCandidate(RelationLocInfo* rel_loc_info, RelationAccessType accessType, List* idx_dist_by_col, + const bool* nulls, Oid* attr, Datum* values, uint32 hashValue); +extern void SendHotkeyToPgstat(); +extern Datum gs_stat_get_hotkeys_info(PG_FUNCTION_ARGS); +extern Datum gs_stat_clean_hotkeys(PG_FUNCTION_ARGS); +extern Datum global_stat_get_hotkeys_info(PG_FUNCTION_ARGS); +extern Datum global_stat_clean_hotkeys(PG_FUNCTION_ARGS); +extern void pgstat_recv_cleanup_hotkeys(PgStat_MsgCleanupHotkeys* msg, int len); +extern void pgstat_send_cleanup_hotkeys(Oid db_oid, Oid t_oid); +extern void PgstatUpdateHotkeys(); +extern bool IsEqual(CmpFuncType fp, void* t1, void* t2); +extern bool IsHotkeyEqual(void* t1, void* t2); +extern void CleanHotkeyInfo(HotkeyInfo* keyInfo); +extern HotkeyInfo* MakeHotkeyInfo(const Oid relationOid, uint32 hashvalue, HotkeyValue* hotkeyValue, MemoryContext cxt); +extern List* CopyHotKeys(List* srcHotKeys); +extern void CheckHotkeys(RemoteQueryState* planstate, ExecNodes* exec_nodes, RemoteQueryExecType exec_type); + +#endif /* SRC_INCLUDE_UTILS_HOTKEYS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/utils/hsearch.h postgresql-hll-2.14/include/utils/hsearch.h --- postgresql-hll-2.14_old/include/utils/hsearch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/hsearch.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,154 @@ +/* ------------------------------------------------------------------------- + * + * hsearch.h + * exported definitions for utils/hash/dynahash.c; see notes therein + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/hsearch.h + * + * ------------------------------------------------------------------------- + */ +#ifndef HSEARCH_H +#define HSEARCH_H + +/* + * Hash functions must have this signature. + */ +typedef uint32 (*HashValueFunc)(const void* key, Size keysize); + +/* + * Key comparison functions must have this signature. Comparison functions + * return zero for match, nonzero for no match. (The comparison function + * definition is designed to allow memcmp() and strncmp() to be used directly + * as key comparison functions.) + */ +typedef int (*HashCompareFunc)(const void* key1, const void* key2, Size keysize); + +/* + * Key copying functions must have this signature. The return value is not + * used. (The definition is set up to allow memcpy() and strncpy() to be + * used directly.) + */ +typedef void* (*HashCopyFunc)(void* dest, const void* src, Size keysize); + +/* + * Space allocation function for a hashtable --- designed to match malloc(). + * Note: there is no free function API; can't destroy a hashtable unless you + * use the default allocator. + */ +typedef void* (*HashAllocFunc)(Size request); + +/* + * Space deallocation function for a hashtable --- designed to match allocator(). + * Note: it's a free function API; you must use it with allocator you defined. + */ +typedef void (*HashDeallocFunc)(void* pointer); + +/* + * HASHELEMENT is the private part of a hashtable entry. The caller's data + * follows the HASHELEMENT structure (on a MAXALIGN'd boundary). The hash key + * is expected to be at the start of the caller's hash entry data structure. + */ +typedef struct HASHELEMENT { + struct HASHELEMENT* link; /* link to next entry in same bucket */ + uint32 hashvalue; /* hash function result for this entry */ +} HASHELEMENT; + +/* Hash table header struct is an opaque type known only within dynahash.c */ +typedef struct HASHHDR HASHHDR; + +/* Hash table control struct is an opaque type known only within dynahash.c */ +typedef struct HTAB HTAB; + +/* Parameter data structure for hash_create */ +/* Only those fields indicated by hash_flags need be set */ +typedef struct HASHCTL { + long num_partitions; /* # partitions (must be power of 2) */ + long ssize; /* segment size */ + long dsize; /* (initial) directory size */ + long max_dsize; /* limit to dsize if dir size is limited */ + long ffactor; /* fill factor */ + Size keysize; /* hash key length in bytes */ + Size entrysize; /* total user element size in bytes */ + HashValueFunc hash; /* hash function */ + HashCompareFunc match; /* key comparison function */ + HashCopyFunc keycopy; /* key copying function */ + HashAllocFunc alloc; /* memory allocator */ + HashDeallocFunc dealloc; /* memory deallocator */ + MemoryContext hcxt; /* memory context to use for allocations */ + HASHHDR* hctl; /* location of header in shared mem */ +} HASHCTL; + +/* Flags to indicate which parameters are supplied */ +#define HASH_PARTITION 0x001 /* Hashtable is used w/partitioned locking */ +#define HASH_SEGMENT 0x002 /* Set segment size */ +#define HASH_DIRSIZE 0x004 /* Set directory size (initial and max) */ +#define HASH_FFACTOR 0x008 /* Set fill factor */ +#define HASH_FUNCTION 0x010 /* Set user defined hash function */ +#define HASH_ELEM 0x020 /* Set keysize and entrysize */ +#define HASH_SHARED_MEM 0x040 /* Hashtable is in shared memory */ +#define HASH_ATTACH 0x080 /* Do not initialize hctl */ +#define HASH_ALLOC 0x100 /* Set memory allocator */ +#define HASH_CONTEXT 0x200 /* Set memory allocation context */ +#define HASH_COMPARE 0x400 /* Set user defined comparison function */ +#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */ +#define HASH_FIXED_SIZE 0x1000 /* Initial size is a hard limit */ +#define HASH_HEAP_MEM 0x2000 /* Hashtable is in heap memory */ +#define HASH_EXTERN_CONTEXT 0x4000 /* use extern context directly */ +#define HASH_SHRCTX 0x8000 /* Set shared memory allocation context */ +#define HASH_DEALLOC 0x10000 /* Set memory deallocator */ +#define HASH_BLOBS 0x20000 /* Select support functions for binary keys */ +#define HASH_NOEXCEPT 0x40000 /* Do not throw exception when malloc memory */ + +/* max_dsize value to indicate expansible directory */ +#define NO_MAX_DSIZE (-1) + +/* hash_search operations */ +typedef enum { HASH_FIND, HASH_ENTER, HASH_REMOVE, HASH_ENTER_NULL } HASHACTION; + +/* hash_seq status (should be considered an opaque type by callers) */ +typedef struct { + HTAB* hashp; + uint32 curBucket; /* index of current bucket */ + HASHELEMENT* curEntry; /* current entry in bucket */ +} HASH_SEQ_STATUS; + +/* + * prototypes for functions in dynahash.c + */ +extern HTAB* hash_create(const char* tabname, long nelem, HASHCTL* info, int flags); +extern void hash_destroy(HTAB* hashp); +extern void hash_remove(HTAB* hashp); +extern void hash_stats(const char* where, HTAB* hashp); +extern void* hash_search(HTAB* hashp, const void* keyPtr, HASHACTION action, bool* foundPtr); +extern uint32 get_hash_value(HTAB* hashp, const void* keyPtr); +extern void* hash_search_with_hash_value( + HTAB* hashp, const void* keyPtr, uint32 hashvalue, HASHACTION action, bool* foundPtr); +extern long hash_get_num_entries(HTAB* hashp); +extern void hash_seq_init(HASH_SEQ_STATUS* status, HTAB* hashp); +extern void* hash_seq_search(HASH_SEQ_STATUS* status); +extern void hash_seq_term(HASH_SEQ_STATUS* status); +extern void hash_freeze(HTAB* hashp); +extern Size hash_estimate_size(long num_entries, Size entrysize); +extern long hash_select_dirsize(long num_entries); +extern Size hash_get_shared_size(HASHCTL* info, int flags); +extern void AtEOXact_HashTables(bool isCommit); +extern void AtEOSubXact_HashTables(bool isCommit, int nestDepth); +extern int hash_get_seq_num(); +extern void release_all_seq_scan(); +extern MemoryContext hash_get_current_dynacxt(void); + +/* + * prototypes for functions in hashfn.c + */ +extern uint32 string_hash(const void* key, Size keysize); +extern uint32 tag_hash(const void* key, Size keysize); +extern uint32 uint32_hash(const void *key, Size keysize); +extern uint32 oid_hash(const void* key, Size keysize); +extern uint32 bitmap_hash(const void* key, Size keysize); +extern int bitmap_match(const void* key1, const void* key2, Size keysize); + +#endif /* HSEARCH_H */ diff -uprN postgresql-hll-2.14_old/include/utils/inet.h postgresql-hll-2.14/include/utils/inet.h --- postgresql-hll-2.14_old/include/utils/inet.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/inet.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------------- + * + * inet.h + * Declarations for operations on INET datatypes. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/inet.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INET_H +#define INET_H + +#include "fmgr.h" + +/* + * This is the internal storage format for IP addresses + * (both INET and CIDR datatypes): + */ +typedef struct { + unsigned char family; /* PGSQL_AF_INET or PGSQL_AF_INET6 */ + unsigned char bits; /* number of bits in netmask */ + unsigned char ipaddr[16]; /* up to 128 bits of address */ +} inet_struct; + +/* + * Referencing all of the non-AF_INET types to AF_INET lets us work on + * machines which may not have the appropriate address family (like + * inet6 addresses when AF_INET6 isn't present) but doesn't cause a + * dump/reload requirement. Existing databases used AF_INET for the family + * type on disk. + */ +#define PGSQL_AF_INET (AF_INET + 0) +#define PGSQL_AF_INET6 (AF_INET + 1) + +/* + * Both INET and CIDR addresses are represented within Postgres as varlena + * objects, ie, there is a varlena header in front of the struct type + * depicted above. This struct depicts what we actually have in memory + * in "uncompressed" cases. Note that since the maximum data size is only + * 18 bytes, INET/CIDR will invariably be stored into tuples using the + * 1-byte-header varlena format. However, we have to be prepared to cope + * with the 4-byte-header format too, because various code may helpfully + * try to "decompress" 1-byte-header datums. + */ +typedef struct { + char vl_len_[4]; /* Do not touch this field directly! */ + inet_struct inet_data; +} inet; + +/* + * This is the internal storage format for MAC addresses: + */ +typedef struct macaddr { + unsigned char a; + unsigned char b; + unsigned char c; + unsigned char d; + unsigned char e; + unsigned char f; +} macaddr; + +/* + * fmgr interface macros + */ +#define DatumGetInetP(X) ((inet*)PG_DETOAST_DATUM(X)) +#define DatumGetInetPP(X) ((inet*)PG_DETOAST_DATUM_PACKED(X)) +#define InetPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) +#define PG_GETARG_INET_PP(n) DatumGetInetPP(PG_GETARG_DATUM(n)) +#define PG_RETURN_INET_P(x) return InetPGetDatum(x) +/* macaddr is a fixed-length pass-by-reference datatype */ +#define DatumGetMacaddrP(X) ((macaddr*)DatumGetPointer(X)) +#define MacaddrPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n)) +#define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x) + +#endif /* INET_H */ diff -uprN postgresql-hll-2.14_old/include/utils/int8.h postgresql-hll-2.14/include/utils/int8.h --- postgresql-hll-2.14_old/include/utils/int8.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/int8.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,137 @@ +/* ------------------------------------------------------------------------- + * + * int8.h + * Declarations for operations on 64-bit integers. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/int8.h + * + * NOTES + * These data types are supported on all 64-bit architectures, and may + * be supported through libraries on some 32-bit machines. If your machine + * is not currently supported, then please try to make it so, then post + * patches to the postgresql.org hackers mailing list. + * + * ------------------------------------------------------------------------- + */ +#ifndef INT8_H +#define INT8_H + +#include "fmgr.h" + +extern bool scanint8(const char* str, bool errorOK, int64* result); + +extern Datum int8in(PG_FUNCTION_ARGS); +extern Datum int8out(PG_FUNCTION_ARGS); +extern Datum int8recv(PG_FUNCTION_ARGS); +extern Datum int8send(PG_FUNCTION_ARGS); + +extern Datum int8eq(PG_FUNCTION_ARGS); +extern Datum int8ne(PG_FUNCTION_ARGS); +extern Datum int8lt(PG_FUNCTION_ARGS); +extern Datum int8gt(PG_FUNCTION_ARGS); +extern Datum int8le(PG_FUNCTION_ARGS); +extern Datum int8ge(PG_FUNCTION_ARGS); + +extern Datum int84eq(PG_FUNCTION_ARGS); +extern Datum int84ne(PG_FUNCTION_ARGS); +extern Datum int84lt(PG_FUNCTION_ARGS); +extern Datum int84gt(PG_FUNCTION_ARGS); +extern Datum int84le(PG_FUNCTION_ARGS); +extern Datum int84ge(PG_FUNCTION_ARGS); + +extern Datum int48eq(PG_FUNCTION_ARGS); +extern Datum int48ne(PG_FUNCTION_ARGS); +extern Datum int48lt(PG_FUNCTION_ARGS); +extern Datum int48gt(PG_FUNCTION_ARGS); +extern Datum int48le(PG_FUNCTION_ARGS); +extern Datum int48ge(PG_FUNCTION_ARGS); + +extern Datum int82eq(PG_FUNCTION_ARGS); +extern Datum int82ne(PG_FUNCTION_ARGS); +extern Datum int82lt(PG_FUNCTION_ARGS); +extern Datum int82gt(PG_FUNCTION_ARGS); +extern Datum int82le(PG_FUNCTION_ARGS); +extern Datum int82ge(PG_FUNCTION_ARGS); + +extern Datum int28eq(PG_FUNCTION_ARGS); +extern Datum int28ne(PG_FUNCTION_ARGS); +extern Datum int28lt(PG_FUNCTION_ARGS); +extern Datum int28gt(PG_FUNCTION_ARGS); +extern Datum int28le(PG_FUNCTION_ARGS); +extern Datum int28ge(PG_FUNCTION_ARGS); + +extern Datum int8um(PG_FUNCTION_ARGS); +extern Datum int8up(PG_FUNCTION_ARGS); +extern Datum int8pl(PG_FUNCTION_ARGS); +extern Datum int8mi(PG_FUNCTION_ARGS); +extern Datum int8mul(PG_FUNCTION_ARGS); +extern Datum int8div(PG_FUNCTION_ARGS); +extern Datum int8abs(PG_FUNCTION_ARGS); +extern Datum int8mod(PG_FUNCTION_ARGS); +extern Datum int8inc(PG_FUNCTION_ARGS); +extern Datum int8inc_any(PG_FUNCTION_ARGS); +extern Datum int8inc_float8_float8(PG_FUNCTION_ARGS); +extern Datum int8larger(PG_FUNCTION_ARGS); +extern Datum int8smaller(PG_FUNCTION_ARGS); + +extern Datum int8and(PG_FUNCTION_ARGS); +extern Datum int8or(PG_FUNCTION_ARGS); +extern Datum int8xor(PG_FUNCTION_ARGS); +extern Datum int8not(PG_FUNCTION_ARGS); +extern Datum int8shl(PG_FUNCTION_ARGS); +extern Datum int8shr(PG_FUNCTION_ARGS); + +extern Datum int84pl(PG_FUNCTION_ARGS); +extern Datum int84mi(PG_FUNCTION_ARGS); +extern Datum int84mul(PG_FUNCTION_ARGS); +extern Datum int84div(PG_FUNCTION_ARGS); + +extern Datum int48pl(PG_FUNCTION_ARGS); +extern Datum int48mi(PG_FUNCTION_ARGS); +extern Datum int48mul(PG_FUNCTION_ARGS); +extern Datum int48div(PG_FUNCTION_ARGS); + +extern Datum int82pl(PG_FUNCTION_ARGS); +extern Datum int82mi(PG_FUNCTION_ARGS); +extern Datum int82mul(PG_FUNCTION_ARGS); +extern Datum int82div(PG_FUNCTION_ARGS); + +extern Datum int28pl(PG_FUNCTION_ARGS); +extern Datum int28mi(PG_FUNCTION_ARGS); +extern Datum int28mul(PG_FUNCTION_ARGS); +extern Datum int28div(PG_FUNCTION_ARGS); + +extern Datum int48(PG_FUNCTION_ARGS); +extern Datum int84(PG_FUNCTION_ARGS); + +extern Datum int28(PG_FUNCTION_ARGS); +extern Datum int82(PG_FUNCTION_ARGS); + +extern Datum i8tod(PG_FUNCTION_ARGS); +extern Datum dtoi8(PG_FUNCTION_ARGS); + +extern Datum i8tof(PG_FUNCTION_ARGS); +extern Datum ftoi8(PG_FUNCTION_ARGS); + +extern Datum i8tooid(PG_FUNCTION_ARGS); +extern Datum oidtoi8(PG_FUNCTION_ARGS); + +extern Datum int8_bool(PG_FUNCTION_ARGS); +extern Datum bool_int8(PG_FUNCTION_ARGS); + +extern Datum generate_series_int8(PG_FUNCTION_ARGS); +extern Datum generate_series_step_int8(PG_FUNCTION_ARGS); + +#ifndef MADLIB +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/int8.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/int4.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/float.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/numeric.inl" +#include "../../gausskernel/runtime/vecexecutor/vecprimitive/varchar.inl" +#endif + +#endif /* INT8_H */ diff -uprN postgresql-hll-2.14_old/include/utils/inval.h postgresql-hll-2.14/include/utils/inval.h --- postgresql-hll-2.14_old/include/utils/inval.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/inval.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * inval.h + * POSTGRES cache invalidation dispatcher definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/inval.h + * + * ------------------------------------------------------------------------- + */ +#ifndef INVAL_H +#define INVAL_H + +#include "access/htup.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef void (*SyscacheCallbackFunction)(Datum arg, int cacheid, uint32 hashvalue); +typedef void (*RelcacheCallbackFunction)(Datum arg, Oid relid); +typedef void (*PartcacheCallbackFunction)(Datum arg, Oid partid); + +/* + * Dynamically-registered callback functions. Current implementation + * assumes there won't be very many of these at once; could improve if needed. + */ + +#define MAX_SYSCACHE_CALLBACKS 20 +#define MAX_RELCACHE_CALLBACKS 5 +#define MAX_PARTCACHE_CALLBACKS 5 + +typedef struct SYSCACHECALLBACK { + int16 id; /* cache number */ + SyscacheCallbackFunction function; + Datum arg; +} SYSCACHECALLBACK; + +typedef struct RELCACHECALLBACK { + RelcacheCallbackFunction function; + Datum arg; +} RELCACHECALLBACK; + +typedef struct PARTCACHECALLBACK { + PartcacheCallbackFunction function; + Datum arg; +} PARTCACHECALLBACK; + +extern void AcceptInvalidationMessages(void); + +extern void AtStart_Inval(void); + +extern void AtSubStart_Inval(void); + +extern void AtEOXact_Inval(bool isCommit); + +extern void AtEOSubXact_Inval(bool isCommit); + +extern void AtPrepare_Inval(void); + +extern void PostPrepare_Inval(void); + +extern void CommandEndInvalidationMessages(void); + +extern void CacheInvalidateHeapTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple); + +extern void CacheInvalidateFunction(Oid funcOid); + +extern void CacheInvalidateCatalog(Oid catalogId); + +extern void CacheInvalidateRelcache(Relation relation); + +extern void CacheInvalidateRelcacheByTuple(HeapTuple classTuple); + +extern void CacheInvalidateRelcacheByRelid(Oid relid); + +extern void CacheInvalidateSmgr(RelFileNodeBackend rnode); + +extern void CacheInvalidateRelmap(Oid databaseId); + +extern void CacheInvalidateHeapTupleInplace(Relation relation, HeapTuple tuple); + +extern void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg); + +extern void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg); + +extern void CallSyscacheCallbacks(int cacheid, uint32 hashvalue); + +extern void inval_twophase_postcommit(TransactionId xid, uint16 info, void* recdata, uint32 len); +extern void CacheRegisterPartcacheCallback(PartcacheCallbackFunction func, Datum arg); +extern void CacheInvalidatePartcache(Partition partition); +extern void CacheInvalidatePartcacheByTuple(HeapTuple partitionTuple); +extern void CacheInvalidatePartcacheByPartid(Oid partid); + +extern void InvalidateSystemCaches(void); + +#endif /* INVAL_H */ diff -uprN postgresql-hll-2.14_old/include/utils/json.h postgresql-hll-2.14/include/utils/json.h --- postgresql-hll-2.14_old/include/utils/json.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/json.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,30 @@ +/* ------------------------------------------------------------------------- + * + * json.h + * Declarations for JSON data type support. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/json.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef JSON_H +#define JSON_H + +#include "fmgr.h" +#include "lib/stringinfo.h" + +extern Datum json_in(PG_FUNCTION_ARGS); +extern Datum json_out(PG_FUNCTION_ARGS); +extern Datum json_recv(PG_FUNCTION_ARGS); +extern Datum json_send(PG_FUNCTION_ARGS); +extern Datum array_to_json(PG_FUNCTION_ARGS); +extern Datum array_to_json_pretty(PG_FUNCTION_ARGS); +extern Datum row_to_json(PG_FUNCTION_ARGS); +extern Datum row_to_json_pretty(PG_FUNCTION_ARGS); +extern void escape_json(StringInfo buf, const char* str); + +#endif /* JSON_H */ diff -uprN postgresql-hll-2.14_old/include/utils/logtape.h postgresql-hll-2.14/include/utils/logtape.h --- postgresql-hll-2.14_old/include/utils/logtape.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/logtape.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,39 @@ +/* ------------------------------------------------------------------------- + * + * logtape.h + * Management of "logical tapes" within temporary files. + * + * See logtape.c for explanations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/logtape.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef LOGTAPE_H +#define LOGTAPE_H + +/* LogicalTapeSet is an opaque type whose details are not known outside logtape.c. */ + +typedef struct LogicalTapeSet LogicalTapeSet; + +/* + * prototypes for functions in logtape.c + */ + +extern LogicalTapeSet* LogicalTapeSetCreate(int ntapes); +extern void LogicalTapeSetClose(LogicalTapeSet* lts); +extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet* lts); +extern size_t LogicalTapeRead(LogicalTapeSet* lts, int tapenum, void* ptr, size_t size); +extern void LogicalTapeWrite(LogicalTapeSet* lts, int tapenum, void* ptr, size_t size); +extern void LogicalTapeRewind(LogicalTapeSet* lts, int tapenum, bool forWrite); +extern void LogicalTapeFreeze(LogicalTapeSet* lts, int tapenum); +extern bool LogicalTapeBackspace(LogicalTapeSet* lts, int tapenum, size_t size); +extern bool LogicalTapeSeek(LogicalTapeSet* lts, int tapenum, long blocknum, int offset); +extern void LogicalTapeTell(LogicalTapeSet* lts, int tapenum, long* blocknum, int* offset); +extern long LogicalTapeSetBlocks(LogicalTapeSet* lts); + +#endif /* LOGTAPE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/lsyscache.h postgresql-hll-2.14/include/utils/lsyscache.h --- postgresql-hll-2.14_old/include/utils/lsyscache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/lsyscache.h 2020-12-12 17:06:43.399349999 +0800 @@ -0,0 +1,219 @@ +/* ------------------------------------------------------------------------- + * + * lsyscache.h + * Convenience routines for common queries in the system catalog cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/lsyscache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef LSYSCACHE_H +#define LSYSCACHE_H + +#include "access/htup.h" +#include "nodes/primnodes.h" +#include "catalog/pg_resource_pool.h" +#include "catalog/pg_workload_group.h" +#include "catalog/pg_app_workloadgroup_mapping.h" +#include "catalog/pgxc_node.h" + +/* Result list element for get_op_btree_interpretation */ +typedef struct OpBtreeInterpretation { + Oid opfamily_id; /* btree opfamily containing operator */ + int strategy; /* its strategy number */ + Oid oplefttype; /* declared left input datatype */ + Oid oprighttype; /* declared right input datatype */ +} OpBtreeInterpretation; + +/* I/O function selector for get_type_io_data */ +typedef enum IOFuncSelector { IOFunc_input, IOFunc_output, IOFunc_receive, IOFunc_send } IOFuncSelector; + +extern bool op_in_opfamily(Oid opno, Oid opfamily); +extern int get_op_opfamily_strategy(Oid opno, Oid opfamily); +extern Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily); +extern void get_op_opfamily_properties( + Oid opno, Oid opfamily, bool ordering_op, int* strategy, Oid* lefttype, Oid* righttype); +extern Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy); +extern bool get_ordering_op_properties(Oid opno, Oid* opfamily, Oid* opcintype, int16* strategy); +extern bool get_compare_function_for_ordering_op(Oid opno, Oid* cmpfunc, bool* reverse); +extern bool get_sort_function_for_ordering_op(Oid opno, Oid* sortfunc, bool* issupport, bool* reverse); +extern Oid get_equality_op_for_ordering_op(Oid opno, bool* reverse); +extern Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type); +extern List* get_mergejoin_opfamilies(Oid opno); +extern bool get_compatible_hash_operators(Oid opno, Oid* lhs_opno, Oid* rhs_opno); +extern bool get_op_hash_functions(Oid opno, RegProcedure* lhs_procno, RegProcedure* rhs_procno); +extern List* get_op_btree_interpretation(Oid opno); +extern bool equality_ops_are_compatible(Oid opno1, Oid opno2); +extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum); +extern char* get_attname(Oid relid, AttrNumber attnum); +extern char* get_relid_attribute_name(Oid relid, AttrNumber attnum); +extern AttrNumber get_attnum(Oid relid, const char* attname); +extern Oid get_atttype(Oid relid, AttrNumber attnum); +extern int32 get_atttypmod(Oid relid, AttrNumber attnum); +extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid* typid, int32* typmod, Oid* collid); +extern char* get_collation_name(Oid colloid); +extern char* get_constraint_name(Oid conoid); +extern Oid get_opclass_family(Oid opclass); +extern Oid get_opclass_input_type(Oid opclass); +extern RegProcedure get_opcode(Oid opno); +extern char* get_opname(Oid opno); +extern void op_input_types(Oid opno, Oid* lefttype, Oid* righttype); +extern bool op_mergejoinable(Oid opno, Oid inputtype); +extern bool op_hashjoinable(Oid opno, Oid inputtype); +extern bool op_strict(Oid opno); +extern char op_volatile(Oid opno); +extern Oid get_commutator(Oid opno); +extern Oid get_equal(Oid opno); +extern Oid get_negator(Oid opno); +extern RegProcedure get_oprrest(Oid opno); +extern RegProcedure get_oprjoin(Oid opno); +extern char* get_func_name(Oid funcid); +extern Oid get_func_namespace(Oid funcid); +extern Oid get_func_rettype(Oid funcid); +extern int get_func_nargs(Oid funcid); +extern Oid get_func_signature(Oid funcid, Oid** argtypes, int* nargs); +extern Oid get_func_variadictype(Oid funcid); +extern bool get_func_retset(Oid funcid); +extern bool func_strict(Oid funcid); +extern char func_volatile(Oid funcid); +extern bool get_func_proshippable(Oid funcid); +extern bool get_func_leakproof(Oid funcid); +extern float4 get_func_cost(Oid funcid); +extern float4 get_func_rows(Oid funcid); +extern Oid get_func_lang(Oid funcid); +extern Oid get_relname_relid(const char* relname, Oid relnamespace); +extern char* get_relname_relid_extend( + const char* relname, Oid relnamespace, Oid* relOid, bool isSupportSynonym, Oid* refSynOid); + +#ifdef PGXC +extern int get_relnatts(Oid relid); +#endif +extern char* get_rel_name(Oid relid); +extern char* getPartitionName(Oid partid, bool missing_ok); +extern Oid get_rel_namespace(Oid relid); +extern char get_rel_persistence(Oid relid); +extern bool is_sys_table(Oid relid); +extern Oid get_rel_type_id(Oid relid); +extern char get_rel_relkind(Oid relid); +extern Oid get_rel_tablespace(Oid relid); +extern bool get_typisdefined(Oid typid); +extern int16 get_typlen(Oid typid); +extern bool get_typbyval(Oid typid); +extern void get_typlenbyval(Oid typid, int16* typlen, bool* typbyval); +extern void get_typlenbyvalalign(Oid typid, int16* typlen, bool* typbyval, char* typalign); +extern Oid getTypeIOParam(HeapTuple typeTuple); +extern void get_type_io_data(Oid typid, IOFuncSelector which_func, int16* typlen, bool* typbyval, char* typalign, + char* typdelim, Oid* typioparam, Oid* func); +extern char get_typstorage(Oid typid); +extern Node* get_typdefault(Oid typid); +extern char get_typtype(Oid typid); +extern bool type_is_rowtype(Oid typid); +extern bool type_is_enum(Oid typid); +extern bool type_is_range(Oid typid); +extern void get_type_category_preferred(Oid typid, char* typcategory, bool* typispreferred); +extern Oid get_typ_typrelid(Oid typid); +extern Oid get_element_type(Oid typid); +extern Oid get_array_type(Oid typid); +extern Oid get_base_element_type(Oid typid); +extern void getTypeInputInfo(Oid type, Oid* typInput, Oid* typIOParam); +extern void getTypeOutputInfo(Oid type, Oid* typOutput, bool* typIsVarlena); +extern void getTypeBinaryInputInfo(Oid type, Oid* typReceive, Oid* typIOParam); +extern void getTypeBinaryOutputInfo(Oid type, Oid* typSend, bool* typIsVarlena); +extern Oid get_typmodin(Oid typid); +extern Oid get_typcollation(Oid typid); +extern bool type_is_collatable(Oid typid); +extern Oid getBaseType(Oid typid); +extern Oid getBaseTypeAndTypmod(Oid typid, int32* typmod); +#ifdef PGXC +extern char* get_cfgname(Oid cfgid); +extern char* get_typename(Oid typid); +extern char* get_enumlabelname(Oid enumlabelid); +extern char* get_exprtypename(Oid enumlabelid); +extern char* get_typename_with_namespace(Oid typid); +extern Oid get_typeoid_with_namespace(const char* typname); +extern char* get_pgxc_nodename(Oid nodeoid, NameData* namedata = NULL); +extern char* get_pgxc_nodename_noexcept(Oid nodeoid, NameData *nodename = NULL); +extern Oid get_pgxc_nodeoid(const char* nodename); +extern Oid get_pgxc_datanodeoid(const char* nodename, bool missingOK); +extern bool check_pgxc_node_name_is_exist( + const char* nodename, const char* host, int port, int comm_sctp_port, int comm_control_port); +extern Oid get_pgxc_primary_datanode_oid(Oid nodeoid); +extern char* get_pgxc_node_name_by_node_id(int4 node_id, bool handle_error = true); +extern uint32 get_pgxc_node_id(Oid nodeid); +extern void get_node_info(const char* nodename, bool* node_is_ccn, ItemPointer tuple_pos); +extern bool is_pgxc_central_nodeid(Oid nodeid); +extern bool is_pgxc_central_nodename(const char*); +extern Oid get_pgxc_central_nodeid(void); +extern char get_pgxc_nodetype(Oid nodeid); +extern char get_pgxc_nodetype_refresh_cache(Oid nodeid); +extern int get_pgxc_nodeport(Oid nodeid); +extern int get_pgxc_nodesctpport(Oid nodeid); +extern int get_pgxc_nodestrmctlport(Oid nodeid); +extern char* get_pgxc_nodehost(Oid nodeid); +extern int get_pgxc_nodeport1(Oid nodeid); +extern int get_pgxc_nodesctpport1(Oid nodeid); +extern int get_pgxc_nodestrmctlport1(Oid nodeid); +extern char* get_pgxc_groupname(Oid groupoid, char* groupname = NULL); +extern char* get_pgxc_nodehost1(Oid nodeid); +extern char* get_pgxc_node_formdata(const char* nodename); +extern bool is_pgxc_nodepreferred(Oid nodeid); +extern bool is_pgxc_nodeprimary(Oid nodeid); +extern bool is_pgxc_nodeactive(Oid nodeid); +extern bool is_pgxc_hostprimary(Oid nodeid); +extern bool node_check_host(const char* host, Oid nodeid); +extern Oid get_pgxc_groupoid(const char* groupname, bool missing_ok = true); +extern char get_pgxc_groupkind(Oid group_oid); +extern int get_pgxc_groupmembers(Oid groupid, Oid** members); +extern int get_pgxc_groupmembers_redist(Oid groupid, Oid** members); +extern char get_pgxc_group_redistributionstatus(Oid groupid); +extern DistributeBy* getTableDistribution(Oid srcRelid); +extern DistributeBy* getTableHBucketDistribution(Relation rel); +extern int get_pgxc_classnodes(Oid tableid, Oid** nodes); +extern Oid get_pgxc_class_groupoid(Oid tableoid); +extern Oid get_resource_pool_oid(const char* poolname); +extern char* get_resource_pool_name(Oid poolid); +extern Form_pg_resource_pool get_resource_pool_param(Oid poolid, Form_pg_resource_pool rp); +extern char* get_resource_pool_ngname(Oid poolid); +extern bool is_resource_pool_foreign(Oid poolid); +extern Oid get_workload_group_oid(const char* groupname); +extern char* get_workload_group_name(Oid groupid); +extern Oid get_application_mapping_oid(const char* appname); +extern char* get_application_mapping_name(Oid appoid); +#endif +extern int32 get_typavgwidth(Oid typid, int32 typmod); +extern int32 get_attavgwidth(Oid relid, AttrNumber attnum, bool ispartition); +extern bool get_attstatsslot(HeapTuple statstuple, Oid atttype, int32 atttypmod, int reqkind, Oid reqop, Oid* actualop, + Datum** values, int* nvalues, float4** numbers, int* nnumbers); +extern bool get_attmultistatsslot(HeapTuple statstuple, Oid atttype, int32 atttypmod, int reqkind, Oid reqop, + Oid* actualop, Datum** values, int* nvalues, float4** numbers, int* nnumbers, bool** nulls = NULL); +extern double get_attstadndistinct(HeapTuple statstuple); +extern void free_attstatsslot(Oid atttype, Datum* values, int nvalues, float4* numbers, int nnumbers); +extern char* get_namespace_name(Oid nspid); +extern Oid get_range_subtype(Oid rangeOid); +extern char* get_cfgnamespace(Oid cfgid); +extern char* get_typenamespace(Oid typid); +extern char* get_enumtypenamespace(Oid enumlabelid); +extern Oid get_typeoid(Oid namespaceId, const char* typname); +extern Oid get_enumlabeloid(Oid enumtypoid, const char* enumlabelname); +extern Oid get_operator_oid(const char* operatorName, Oid operatorNamespace, Oid leftObjectId, Oid rightObjectId); +extern void get_oper_name_namespace_oprs(Oid operid, char** oprname, char** nspname, Oid* oprleft, Oid* oprright); +extern Oid get_func_oid(const char* funcname, Oid funcnamespace, Expr* expr); +extern Oid get_func_oid_ext(const char* funcname, Oid funcnamespace, Oid funcrettype, int funcnargs, Oid* funcargstype); +extern Oid get_my_temp_schema(); +extern bool check_rel_is_partitioned(Oid relid); +extern Oid partid_get_parentid(Oid partid); +extern bool is_not_strict_agg(Oid funcOid); +extern bool is_pgxc_class_table(Oid tableoid); +extern Oid get_valid_relname_relid(const char* relnamespace, const char* relname); +extern bool get_func_iswindow(Oid funcid); + +#define type_is_array(typid) (get_element_type(typid) != InvalidOid) +/* type_is_array_domain accepts both plain arrays and domains over arrays */ +#define type_is_array_domain(typid) (get_base_element_type(typid) != InvalidOid) + +#define TypeIsToastable(typid) (get_typstorage(typid) != 'p') + +#endif /* LSYSCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/median_aggs.h postgresql-hll-2.14/include/utils/median_aggs.h --- postgresql-hll-2.14_old/include/utils/median_aggs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/median_aggs.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,34 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * median_aggs.h + * Aggregate for computing the statistical median + * + * IDENTIFICATION + * src/include/utils/median_aggs.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MEDIAN_AGGS_H +#define MEDIAN_AGGS_H + +#include "fmgr.h" + +extern Datum median_transfn(PG_FUNCTION_ARGS); +extern Datum median_float8_finalfn(PG_FUNCTION_ARGS); +extern Datum median_interval_finalfn(PG_FUNCTION_ARGS); + +#endif /* MEDIAN_AGGS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/utils/memgroup.h postgresql-hll-2.14/include/utils/memgroup.h --- postgresql-hll-2.14_old/include/utils/memgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/memgroup.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,57 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * memgroup.h + * Add memory context group + * + * IDENTIFICATION + * src/include/utils/memgroup.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef MEMGROUP_H +#define MEMGROUP_H + +#include "utils/palloc.h" + +typedef enum { + MEMORY_CONTEXT_CBB, + MEMORY_CONTEXT_COMMUNICATION, + MEMORY_CONTEXT_DEFAULT, + MEMORY_CONTEXT_DFX, + MEMORY_CONTEXT_EXECUTOR, + MEMORY_CONTEXT_NUMA, + MEMORY_CONTEXT_OPTIMIZER, + MEMORY_CONTEXT_SECURITY, + MEMORY_CONTEXT_STORAGE, + MEMORY_CONTEXT_TSDB, + MEMORY_CONTEXT_STREAMING, + MEMORY_CONTEXT_MAX +} MemoryGroupType; + +class MemoryContextGroup : public BaseObject { +public: + MemoryContextGroup(); + ~MemoryContextGroup() {} + void Init(MemoryContext parent, bool is_shared = false); + MemoryContext const GetMemCxtGroup(MemoryGroupType type); + +private: + MemoryContext memory_context_group[MEMORY_CONTEXT_MAX]; + static const char* memory_context_group_name[MEMORY_CONTEXT_MAX]; +}; + +#endif /* MEMGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/utils/memprot.h postgresql-hll-2.14/include/utils/memprot.h --- postgresql-hll-2.14_old/include/utils/memprot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/memprot.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,106 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memprot.h + * + * + * + * IDENTIFICATION + * src/include/utils/memprot.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMPROT_H +#define MEMPROT_H + +#include "c.h" +#include "utils/aset.h" + +#define BITS_IN_MB 20 +#define BITS_IN_KB 10 + +#define MIN_PROCESS_LIMIT (2 * 1024 * 1024) // 2GB +#define MEMPROT_INIT_SIZE 200 // 200MB for initialization memory + +#define CHUNKS_TO_MB(chunks) ((chunks) << (chunkSizeInBits - BITS_IN_MB)) +#define MB_TO_CHUNKS(mb) ((mb) >> (chunkSizeInBits - BITS_IN_MB)) +#define CHUNKS_TO_BYTES(chunks) (((int64)chunks) << chunkSizeInBits) +#define BYTES_TO_CHUNKS(bytes) ((bytes) >> chunkSizeInBits) +#define BYTES_TO_MB(bytes) ((bytes) >> BITS_IN_MB) + +#define HIGH_PROCMEM_MARK 80 // 80% of total node memory +#define LOW_PROCMEM_MARK 60 // 60% of total node memory + +#define LOW_WORKMEM_CHUNK 256 + +#define MAX_MEMORY_FAULT_PERCENT (INT_MAX) + +#define SELF_SHARED_MEMCTX_LIMITATION (100 * 1024 * 1024) // 100MB +#define SELF_GENRIC_MEMCTX_LIMITATION (10 * 1024 * 1024) // 10MB +#define MAX_SHARED_MEMCTX_LIMITATION (2 * 1024) // 2GB +#define MAX_GENRIC_MEMCTX_LIMITATION (100 * 1024 * 1024) // 100MB +#define MAX_SHARED_MEMCTX_SIZE (10 * 1024) // 10GB + +#define MAX_COMM_USED_SIZE (4 * 1024) // 4GB +#define SELF_QUERY_LIMITATION (300) // 300MB + +#define PROCMEM_HIGHWATER_THRESHOLD (5 * 1024) // 5G + +/* 200* 1024 kB */ +/* Must be same as UDF_DEFAULT_MEMORY in agent_main.cpp and udf_memory_limit in cluster_guc.conf */ +#define UDF_DEFAULT_MEMORY (200 * 1024) + +extern unsigned int chunkSizeInBits; + +extern int32 maxChunksPerProcess; +extern int32 processMemInChunks; +extern int32 peakChunksPerProcess; +extern int32 shareTrackedMemChunks; +extern int32 peakChunksSharedContext; +extern int32 maxChunksPerQuery; +extern int32 comm_original_memory; +extern int32 maxSharedMemory; +extern int32 dynmicTrackedMemChunks; +extern int64 storageTrackedBytes; +extern int32 backendReservedMemInChunk; +extern int32 backendUsedMemInChunk; + +/* functions from memprot.cpp */ +#ifdef MEMORY_CONTEXT_CHECKING +extern bool gs_memory_enjection(void); +#endif + +extern bool gs_sysmemory_busy(int64 used, bool strict); + +extern bool gs_sysmemory_avail(int64 requestedBytes); + +extern void gs_memprot_thread_init(void); + +extern void gs_memprot_init(Size size); + +extern void gs_memprot_process_gpu_memory(uint32 size); + +extern void gs_memprot_reset_beyondchunk(void); + +#define GS_MEMPROT_MALLOC(sz, needProtect) MemoryProtectFunctions::gs_memprot_malloc(sz, needProtect) +#define GS_MEMPROT_FREE(ptr, sz) MemoryProtectFunctions::gs_memprot_free(ptr, sz) +#define GS_MEMPROT_REALLOC(ptr, sz, newsz, needProtect) MemoryProtectFunctions::gs_memprot_realloc(ptr, sz, newsz, needProtect) +#define GS_MEMPROT_MEMALIGN(ptr, align, sz, needProtect) MemoryProtectFunctions::gs_posix_memalign(ptr, align, sz, needProtect) +#define GS_MEMPROT_SHARED_MALLOC(sz) MemoryProtectFunctions::gs_memprot_malloc(sz) +#define GS_MEMPROT_SHARED_FREE(ptr, sz) MemoryProtectFunctions::gs_memprot_free(ptr, sz) + +extern int getSessionMemoryUsageMB(); + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/memtrace.h postgresql-hll-2.14/include/utils/memtrace.h --- postgresql-hll-2.14_old/include/utils/memtrace.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/memtrace.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memtrace.h + * + * IDENTIFICATION + * src/include/utils/memtrace.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMTRACE_H +#define MEMTRACE_H + +#include "c.h" +#include "utils/aset.h" +#include "nodes/memnodes.h" + +typedef struct MemoryAllocInfo { + void* pointer; + const char* file; + int line; + Size size; + MemoryContext context; + char context_name[NAMEDATALEN]; +} MemoryAllocInfo; + +typedef struct MemoryAllocDetailKey { + char name[NAMEDATALEN]; + const char* file; + int line; +} MemoryAllocDetailKey; + +typedef struct MemoryAllocDetail { + MemoryAllocDetailKey detail_key; + Size size; +} MemoryAllocDetail; + +typedef struct MemoryAllocDetailList { + MemoryAllocDetail* entry; + MemoryAllocDetailList* next; +} MemoryAllocDetailList; + +extern Datum track_memory_context(PG_FUNCTION_ARGS); +extern bool MemoryContextShouldTrack(const char* name); +extern void InsertTrackMemoryInfo(const void* pointer, const MemoryContext context, const char* file, int line, Size size); +extern void RemoveTrackMemoryInfo(const void* pointer); +extern void RemoveTrackMemoryContext(const MemoryContext context); +extern MemoryAllocDetailList* GetMemoryTrackInfo(); + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/memtrack.h postgresql-hll-2.14/include/utils/memtrack.h --- postgresql-hll-2.14_old/include/utils/memtrack.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/memtrack.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,60 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memtrack.h + * This file contains declarations for memory tracking utility functions. + * The relative GUC to trigger the memory tracking feature is listed: + * enable_memory_tracking: the GUC must be set as ON; + * enable_memory_logging: to generate the file with memory context information + * memory_detail_logging: to generate the file with debug allocation information + * + * + * IDENTIFICATION + * src/include/utils/memtrack.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef MEMTRACK_H +#define MEMTRACK_H + +#include "c.h" +#include "utils/aset.h" +#include "nodes/memnodes.h" + +extern THR_LOCAL int guc_memory_tracking_mode; + +extern THR_LOCAL char mctx_track_name[256]; + +extern THR_LOCAL long mctx_track_value; + +extern void MemoryTrackingInit(void); +extern void MemoryTrackingCreate(MemoryContext set, MemoryContext parent); +extern void MemoryTrackingAllocInfo(MemoryContext context, Size size); +extern void MemoryTrackingFreeInfo(MemoryContext context, Size size); +extern void MemoryTrackingLoggingToFile(MemoryTrack track, int key); +extern void MemoryTrackingNodeFree(MemoryTrack track); +extern void MemoryTrackingOutputFile(void); + +#ifdef MEMORY_CONTEXT_CHECKING + +extern void MemoryTrackingParseGUC(const char* val); + +extern void MemoryTrackingDetailInfo(MemoryContext context, Size reqSize, Size chunkSize, const char* file, int line); + +extern void MemoryTrackingDetailInfoToFile(void); + +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/memutils.h postgresql-hll-2.14/include/utils/memutils.h --- postgresql-hll-2.14_old/include/utils/memutils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/memutils.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,196 @@ +/* ------------------------------------------------------------------------- + * + * memutils.h + * This file contains declarations for memory allocation utility + * functions. These are functions that are not quite widely used + * enough to justify going in utils/palloc.h, but are still part + * of the API of the memory management subsystem. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/memutils.h + * + * ------------------------------------------------------------------------- + */ +#ifndef MEMUTILS_H +#define MEMUTILS_H + +#include "nodes/memnodes.h" +#include "pgtime.h" +#include "storage/proc.h" + +enum MemoryContextType { + STANDARD_CONTEXT, // postgres orignal context + STACK_CONTEXT, // a simple context, do not support free single pointer + SHARED_CONTEXT, // shared context used by different threads + MEMALIGN_CONTEXT, // the context only used to allocate the aligned memory + MEMALIGN_SHRCTX, // the shared context only used to allocate the aligned memory +}; + +/* + * MaxAllocSize + * Quasi-arbitrary limit on size of allocations. + * + * Note: + * There is no guarantee that allocations smaller than MaxAllocSize + * will succeed. Allocation requests larger than MaxAllocSize will + * be summarily denied. + * + * XXX This is deliberately chosen to correspond to the limiting size + * of varlena objects under TOAST. See VARSIZE_4B() and related macros + * in postgres.h. Many datatypes assume that any allocatable size can + * be represented in a varlena header. + * + * XXX Also, various places in aset.c assume they can compute twice an + * allocation's size without overflow, so beware of raising this. + */ +#define MaxAllocSize ((Size)0x3fffffff) /* 1 gigabyte - 1 */ + +#define MaxBuildAllocSize ((Size)0x3ffffff) /* 64MB - 1 */ + +#define AllocSizeIsValid(size) ((Size)(size) <= MaxAllocSize) + +#define MaxAllocHugeSize ((Size)-1 >> 1) /* SIZE_MAX / 2 */ + +#define AllocHugeSizeIsValid(size) ((Size)(size) <= MaxAllocHugeSize) + +/* + * All chunks allocated by any memory context manager are required to be + * preceded by a StandardChunkHeader at a spacing of STANDARDCHUNKHEADERSIZE. + * A currently-allocated chunk must contain a backpointer to its owning + * context as well as the allocated size of the chunk. The backpointer is + * used by pfree() and repalloc() to find the context to call. The allocated + * size is not absolutely essential, but it's expected to be needed by any + * reasonable implementation. + */ +typedef struct StandardChunkHeader { + MemoryContext context; /* owning context */ + Size size; /* size of data space allocated in chunk */ +#ifdef MEMORY_CONTEXT_CHECKING + /* when debugging memory usage, also store actual requested size */ + Size requested_size; + const char* file; + int line; +#endif +} StandardChunkHeader; + +#define STANDARDCHUNKHEADERSIZE MAXALIGN(sizeof(StandardChunkHeader)) + +// Process wise memory context +// +extern MemoryContext AdioSharedContext; +extern MemoryContext ProcSubXidCacheContext; +extern MemoryContext PmTopMemoryContext; +extern MemoryContext StreamInfoContext; + +extern THR_LOCAL PGDLLIMPORT MemoryContext ErrorContext; + +/* + * Memory-context-type-independent functions in mcxt.c + */ +extern void MemoryContextInit(void); +extern void MemoryContextReset(MemoryContext context); +extern void MemoryContextDelete(MemoryContext context); +extern void MemoryContextResetChildren(MemoryContext context); +extern void MemoryContextDeleteChildren(MemoryContext context, List* context_list = NULL); +extern void MemoryContextDestroyAtThreadExit(MemoryContext context); +extern void MemoryContextResetAndDeleteChildren(MemoryContext context); +extern void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent); +extern Size GetMemoryChunkSpace(void* pointer); +extern MemoryContext GetMemoryChunkContext(void* pointer); +extern MemoryContext MemoryContextGetParent(MemoryContext context); +extern bool MemoryContextIsEmpty(MemoryContext context); +extern void MemoryContextStats(MemoryContext context); +extern void MemoryContextSeal(MemoryContext context); +extern void MemoryContextUnSeal(MemoryContext context); +extern void MemoryContextUnSealChildren(MemoryContext context); + +#ifdef MEMORY_CONTEXT_CHECKING +extern void MemoryContextCheck(MemoryContext context, bool own_by_session); +#define MemoryContextCheck2(mctx) +#endif + +extern bool MemoryContextContains(MemoryContext context, void* pointer); + +extern MemoryContext MemoryContextOriginal(const char* node); + +/* + * This routine handles the context-type-independent part of memory + * context creation. It's intended to be called from context-type- + * specific creation routines, and noplace else. + */ +extern MemoryContext MemoryContextCreate( + NodeTag tag, Size size, MemoryContext parent, const char* name, const char* file, int line); + +/* Interface for PosgGIS and has the same structure with PG's MemoryContextCreate*/ +extern MemoryContext MemoryContextCreate( + NodeTag tag, Size size, MemoryContextMethods* methods, MemoryContext parent, const char* name); + +/* + * Memory-context-type-specific functions + */ +#define DEFAULT_MEMORY_CONTEXT_MAX_SIZE 0 /* 0 MB as default value for AllocSetContextCreat function */ +#define SHARED_MEMORY_CONTEXT_MAX_SIZE (100 * 1024 * 1024) /* 100 MB */ +/* aset.c */ +extern MemoryContext AllocSetContextCreate(MemoryContext parent, const char* name, Size minContextSize, + Size initBlockSize, Size maxBlockSize, MemoryContextType type = STANDARD_CONTEXT, + Size maxSize = DEFAULT_MEMORY_CONTEXT_MAX_SIZE, bool isSession = false); + +/* + * Recommended default alloc parameters, suitable for "ordinary" contexts + * that might hold quite a lot of data. + */ +#define ALLOCSET_DEFAULT_MINSIZE 0 +#define ALLOCSET_DEFAULT_INITSIZE (8 * 1024) +#define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024) +#define ALLOCSET_DEFAULT_SIZES ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE + +/* + * Recommended alloc parameters for "small" contexts that are not expected + * to contain much data (for example, a context to contain a query plan). + */ +#define ALLOCSET_SMALL_MINSIZE 0 +#define ALLOCSET_SMALL_INITSIZE (1 * 1024) +#define ALLOCSET_SMALL_MAXSIZE (8 * 1024) + +/* default grow ratio for sort and materialize when it spreads */ +#define DEFAULT_GROW_RATIO 2.0 + +/* default auto spread min ratio, and memory spread under this ratio is abondaned */ +#define MEM_AUTO_SPREAD_MIN_RATIO 0.1 + +// AutoContextSwitch +// Auto object for memoryContext switch +// +class AutoContextSwitch { +public: + AutoContextSwitch(MemoryContext memContext) + { + if (memContext == NULL) { + m_oldMemContext = CurrentMemoryContext; + } else { + m_oldMemContext = MemoryContextSwitchTo(memContext); + } + }; + + ~AutoContextSwitch() + { + MemoryContextSwitchTo(m_oldMemContext); + } + +private: + MemoryContext m_oldMemContext; +}; + +/* In case we haven't init u_sess->when we try to create memory context and alloc memory */ +#define IS_USESS_AVAILABLE (likely(u_sess != NULL)) +#define GS_MP_INITED (t_thrd.utils_cxt.gs_mp_inited) +#define MEMORY_TRACKING_MODE (IS_USESS_AVAILABLE ? u_sess->attr.attr_memory.memory_tracking_mode : 0) +#define ENABLE_MEMORY_CONTEXT_CONTROL \ + (IS_USESS_AVAILABLE ? u_sess->attr.attr_memory.enable_memory_context_control : false) +#define MEMORY_FAULT_PERCENT (IS_USESS_AVAILABLE ? u_sess->attr.attr_resource.memory_fault_percent : 0) +#define STATEMENT_MAX_MEM (IS_USESS_AVAILABLE ? u_sess->attr.attr_sql.statement_max_mem : 0) + +#endif /* MEMUTILS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/mmpool.h postgresql-hll-2.14/include/utils/mmpool.h --- postgresql-hll-2.14_old/include/utils/mmpool.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/mmpool.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,121 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * mmpool.h + * + * + * + * IDENTIFICATION + * src/include/utils/mmpool.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_UTILS_MMPOOL_H_ +#define SRC_INCLUDE_UTILS_MMPOOL_H_ + +#include "postgres.h" +#include "utils/memutils.h" +#include "nodes/pg_list.h" + +struct MemoryBlock { + int64 blkSize; + bool isFree; + + MemoryBlock* prev; + MemoryBlock* next; +}; + +#define MEMORY_BLOCK_HEADER TYPEALIGN(ALIGNOF_LONG, sizeof(MemoryBlock)) +#define MEMORY_BLOCK_MIN_SIZE (2 * MEMORY_BLOCK_HEADER) + +struct MemoryBlockListHeader { + MemoryBlock* start; + MemoryBlock* end; +}; + +#define POOL_INIT_SUCCESS 0 +#define POOL_INIT_FAIL 1 + +class MemoryPool { +public: + // constructor + MemoryPool(); + + // destructor + ~MemoryPool(); + + // init the memory pool. + int CreatePool(); + + // release the memory pool. + void ReleasePool(); + + // Malloc the memory from memory pool. + void* Malloc(int64 sizeBytes); + + // Realloc the memory + void* Realloc(void* addr, int64 sizeBytes); + + // Free the memory + void Free(void* addr); + + // pool is ready? + inline bool Ready() + { + return m_ready; + } + + // static function to init/deinit the memory pool + static int Init(); + + static void Deinit(); + +private: + // Split a block for fit the size + bool SplitFreeList(int idx); + + // Merge block and its buddy + void MergeBlock(void* addr, MemoryBlock* block, MemoryBlock* blockBuddy, int idx); + + MemoryBlock* FindBuddy(MemoryBlock* block, int64 size); + + void AddLast(int idx, MemoryBlock* blk); + + void AddFirst(int idx, MemoryBlock* blk); + + void Remove(int idx, MemoryBlock* blk); + +private: + // the memory buffer + char* m_buf; // + + // memory buffer size + int64 m_size; + + // the usage size of memory buffer + int64 m_use; + + // concurrency control for mutex + pthread_mutex_t m_mutex; // lock + + // free list for the memory pool. + MemoryBlockListHeader m_freeList[64]; + + // flag to indicate the pool is ready + volatile bool m_ready; +}; + +#endif /* SRC_INCLUDE_UTILS_MMPOOL_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/nabstime.h postgresql-hll-2.14/include/utils/nabstime.h --- postgresql-hll-2.14_old/include/utils/nabstime.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/nabstime.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,161 @@ +/* ------------------------------------------------------------------------- + * + * nabstime.h + * Definitions for the "new" abstime code. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/nabstime.h + * + * ------------------------------------------------------------------------- + */ +#ifndef NABSTIME_H +#define NABSTIME_H + +#include + +#include "fmgr.h" +#include "pgtime.h" + +/* ---------------------------------------------------------------- + * + * time types + support macros + * + * ---------------------------------------------------------------- + */ + +/* + * Although time_t generally is a long int on 64 bit systems, these two + * types must be 4 bytes, because that's what pg_type.h assumes. They + * should be yanked (long) before 2038 and be replaced by timestamp and + * interval. + */ +typedef int32 AbsoluteTime; +typedef int32 RelativeTime; + +typedef struct { + int32 status; + AbsoluteTime data[2]; +} TimeIntervalData; + +typedef TimeIntervalData* TimeInterval; + +/* + * Macros for fmgr-callable functions. + */ +#define DatumGetAbsoluteTime(X) ((AbsoluteTime)DatumGetInt32(X)) +#define DatumGetRelativeTime(X) ((RelativeTime)DatumGetInt32(X)) +#define DatumGetTimeInterval(X) ((TimeInterval)DatumGetPointer(X)) + +#define AbsoluteTimeGetDatum(X) Int32GetDatum(X) +#define RelativeTimeGetDatum(X) Int32GetDatum(X) +#define TimeIntervalGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n)) +#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n)) + +#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x) +#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x) +#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x) + +/* + * Reserved values + * Epoch is Unix system time zero, but needs to be kept as a reserved + * value rather than converting to time since timezone calculations + * might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20 + * + * Pre-v6.1 code had large decimal numbers for reserved values. + * These were chosen as special 32-bit bit patterns, + * so redefine them explicitly using these bit patterns. - tgl 97/02/24 + */ +#define INVALID_ABSTIME ((AbsoluteTime)0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ +#define NOEND_ABSTIME ((AbsoluteTime)0x7FFFFFFC) /* 2147483645 (2^31 - 3) */ +#define NOSTART_ABSTIME ((AbsoluteTime)INT_MIN) /* -2147483648 */ + +#define INVALID_RELTIME ((RelativeTime)0x7FFFFFFE) /* 2147483647 (2^31 - 1) */ + +#define AbsoluteTimeIsValid(time) ((bool)((time) != INVALID_ABSTIME)) + +/* + * Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any + * AbsoluteTime values less than it. Therefore, we can code the test + * "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids + * compiler bugs on some platforms. --- tgl & az, 11/2000 + */ +#define AbsoluteTimeIsReal(time) \ + ((bool)(((AbsoluteTime)(time)) < NOEND_ABSTIME && ((AbsoluteTime)(time)) != NOSTART_ABSTIME)) + +#define RelativeTimeIsValid(time) ((bool)(((RelativeTime)(time)) != INVALID_RELTIME)) + +/* + * nabstime.c prototypes + */ +extern Datum abstimein(PG_FUNCTION_ARGS); +extern Datum abstimeout(PG_FUNCTION_ARGS); +extern Datum abstimerecv(PG_FUNCTION_ARGS); +extern Datum abstimesend(PG_FUNCTION_ARGS); + +extern Datum abstimeeq(PG_FUNCTION_ARGS); +extern Datum abstimene(PG_FUNCTION_ARGS); +extern Datum abstimelt(PG_FUNCTION_ARGS); +extern Datum abstimegt(PG_FUNCTION_ARGS); +extern Datum abstimele(PG_FUNCTION_ARGS); +extern Datum abstimege(PG_FUNCTION_ARGS); +extern Datum abstime_finite(PG_FUNCTION_ARGS); + +extern Datum timestamp_abstime(PG_FUNCTION_ARGS); +extern Datum abstime_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_abstime(PG_FUNCTION_ARGS); +extern Datum abstime_timestamptz(PG_FUNCTION_ARGS); + +extern Datum reltimein(PG_FUNCTION_ARGS); +extern Datum reltimeout(PG_FUNCTION_ARGS); +extern Datum reltimerecv(PG_FUNCTION_ARGS); +extern Datum reltimesend(PG_FUNCTION_ARGS); +extern Datum tintervalin(PG_FUNCTION_ARGS); +extern Datum tintervalout(PG_FUNCTION_ARGS); +extern Datum tintervalrecv(PG_FUNCTION_ARGS); +extern Datum tintervalsend(PG_FUNCTION_ARGS); +extern Datum interval_reltime(PG_FUNCTION_ARGS); +extern Datum reltime_interval(PG_FUNCTION_ARGS); +extern Datum mktinterval(PG_FUNCTION_ARGS); +extern Datum timepl(PG_FUNCTION_ARGS); +extern Datum timemi(PG_FUNCTION_ARGS); + +extern Datum intinterval(PG_FUNCTION_ARGS); +extern Datum tintervalrel(PG_FUNCTION_ARGS); +extern Datum timenow(PG_FUNCTION_ARGS); +extern Datum reltimeeq(PG_FUNCTION_ARGS); +extern Datum reltimene(PG_FUNCTION_ARGS); +extern Datum reltimelt(PG_FUNCTION_ARGS); +extern Datum reltimegt(PG_FUNCTION_ARGS); +extern Datum reltimele(PG_FUNCTION_ARGS); +extern Datum reltimege(PG_FUNCTION_ARGS); +extern Datum tintervalsame(PG_FUNCTION_ARGS); +extern Datum tintervaleq_withhead(PG_FUNCTION_ARGS); +extern Datum tintervaleq(PG_FUNCTION_ARGS); +extern Datum tintervalne(PG_FUNCTION_ARGS); +extern Datum tintervallt(PG_FUNCTION_ARGS); +extern Datum tintervalgt(PG_FUNCTION_ARGS); +extern Datum tintervalle(PG_FUNCTION_ARGS); +extern Datum tintervalge(PG_FUNCTION_ARGS); +extern Datum tintervalleneq(PG_FUNCTION_ARGS); +extern Datum tintervallenne(PG_FUNCTION_ARGS); +extern Datum tintervallenlt(PG_FUNCTION_ARGS); +extern Datum tintervallengt(PG_FUNCTION_ARGS); +extern Datum tintervallenle(PG_FUNCTION_ARGS); +extern Datum tintervallenge(PG_FUNCTION_ARGS); +extern Datum tintervalct(PG_FUNCTION_ARGS); +extern Datum tintervalov(PG_FUNCTION_ARGS); +extern Datum tintervalstart(PG_FUNCTION_ARGS); +extern Datum tintervalend(PG_FUNCTION_ARGS); +extern Datum timeofday(PG_FUNCTION_ARGS); + +/* non-fmgr-callable support routines */ +extern AbsoluteTime GetCurrentAbsoluteTime(void); +extern void abstime2tm(AbsoluteTime time, int* tzp, struct pg_tm* tm, char** tzn); + +#endif /* NABSTIME_H */ diff -uprN postgresql-hll-2.14_old/include/utils/numeric_gs.h postgresql-hll-2.14/include/utils/numeric_gs.h --- postgresql-hll-2.14_old/include/utils/numeric_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/numeric_gs.h 2020-12-12 17:06:43.400350012 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * numeric_gs.h + * Definitions for the exact numeric data type of Postgres + * + * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/utils/numeric_gs.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef _PG_NUMERIC_GS_H_ +#define _PG_NUMERIC_GS_H_ + +#include "fmgr.h" + +#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(uint16) + sizeof(int16)) +#define NUMERIC_HDRSZ_SHORT (VARHDRSZ + sizeof(uint16)) + +#define NUMERIC_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_SIGN_MASK) +#define NUMERIC_NB_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_BI_MASK) // nan or biginteger + +#define NUMERIC_IS_NAN(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_NAN) +#define NUMERIC_IS_SHORT(n) (NUMERIC_FLAGBITS(n) == NUMERIC_SHORT) + +/* + * big integer macro + * determine the type of numeric + * verify whether a numeric data is NAN or BI by it's flag. + */ +#define NUMERIC_FLAG_IS_NAN(n) (n == NUMERIC_NAN) +#define NUMERIC_FLAG_IS_NANORBI(n) (n >= NUMERIC_NAN) +#define NUMERIC_FLAG_IS_BI(n) (n > NUMERIC_NAN) +#define NUMERIC_FLAG_IS_BI64(n) (n == NUMERIC_64) +#define NUMERIC_FLAG_IS_BI128(n) (n == NUMERIC_128) + +/* + * big integer macro + * determine the type of numeric + * verify whether a numeric data is NAN or BI by itself. + */ +#define NUMERIC_IS_NANORBI(n) (NUMERIC_NB_FLAGBITS(n) >= NUMERIC_NAN) +#define NUMERIC_IS_BI(n) (NUMERIC_NB_FLAGBITS(n) > NUMERIC_NAN) +#define NUMERIC_IS_BI64(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_64) +#define NUMERIC_IS_BI128(n) (NUMERIC_NB_FLAGBITS(n) == NUMERIC_128) + +/* + * big integer macro + * the size of bi64 or bi128 is fixed. + * the size of bi64 is: + * 4 bytes(vl_len_) + 2 bytes(n_header) + 8 bytes(int64) = 14 bytes + * the size of bi128 is: + * 4 bytes(vl_len_) + 2 bytes(n_header) + 16 bytes(int128) = 22 bytes + */ +#define NUMERIC_64SZ (NUMERIC_HDRSZ_SHORT + sizeof(int64)) +#define NUMERIC_128SZ (NUMERIC_HDRSZ_SHORT + sizeof(int128)) + +/* + * big integer macro + * get the scale of bi64 or bi128. + * scale = n_header & NUMERIC_BI_SCALEMASK + * get the value of bi64 or bi128 + * convert NumericBi.n_data to int64 or int128 pointer, then + * assign value. + */ +#define NUMERIC_BI_SCALE(n) ((n)->choice.n_header & NUMERIC_BI_SCALEMASK) +#define NUMERIC_64VALUE(n) (*((int64*)((n)->choice.n_bi.n_data))) + +/* + * If the flag bits are NUMERIC_SHORT or NUMERIC_NAN, we want the short header; + * otherwise, we want the long one. Instead of testing against each value, we + * can just look at the high bit, for a slight efficiency gain. + */ +#define NUMERIC_HEADER_SIZE(n) (VARHDRSZ + sizeof(uint16) + (((NUMERIC_FLAGBITS(n) & 0x8000) == 0) ? sizeof(int16) : 0)) + +/* + * Short format definitions. + */ +#define NUMERIC_SHORT_SIGN_MASK 0x2000 +#define NUMERIC_SHORT_DSCALE_MASK 0x1F80 +#define NUMERIC_SHORT_DSCALE_SHIFT 7 +#define NUMERIC_SHORT_DSCALE_MAX (NUMERIC_SHORT_DSCALE_MASK >> NUMERIC_SHORT_DSCALE_SHIFT) +#define NUMERIC_SHORT_WEIGHT_SIGN_MASK 0x0040 +#define NUMERIC_SHORT_WEIGHT_MASK 0x003F +#define NUMERIC_SHORT_WEIGHT_MAX NUMERIC_SHORT_WEIGHT_MASK +#define NUMERIC_SHORT_WEIGHT_MIN (-(NUMERIC_SHORT_WEIGHT_MASK + 1)) + +/* + * Extract sign, display scale, weight. + */ +#define NUMERIC_DSCALE_MASK 0x3FFF + +#define NUMERIC_SIGN(n) \ + (NUMERIC_IS_SHORT(n) ? (((n)->choice.n_short.n_header & NUMERIC_SHORT_SIGN_MASK) ? NUMERIC_NEG : NUMERIC_POS) \ + : NUMERIC_FLAGBITS(n)) +#define NUMERIC_DSCALE(n) \ + (NUMERIC_IS_SHORT((n)) ? ((n)->choice.n_short.n_header & NUMERIC_SHORT_DSCALE_MASK) >> NUMERIC_SHORT_DSCALE_SHIFT \ + : ((n)->choice.n_long.n_sign_dscale & NUMERIC_DSCALE_MASK)) +#define NUMERIC_WEIGHT(n) \ + (NUMERIC_IS_SHORT((n)) \ + ? (((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_SIGN_MASK ? ~NUMERIC_SHORT_WEIGHT_MASK : 0) | \ + ((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_MASK)) \ + : ((n)->choice.n_long.n_weight)) +#define NUMERIC_DIGITS(num) (NUMERIC_IS_SHORT(num) ? (num)->choice.n_short.n_data : (num)->choice.n_long.n_data) +#define NUMERIC_NDIGITS(num) ((VARSIZE(num) - NUMERIC_HEADER_SIZE(num)) / sizeof(NumericDigit)) + +/* + * @Description: copy bi64 to ptr, this operation no need to allocate memory + * @IN ptr: the numeric pointer + * @IN value: the value of bi64 + * @IN scale: the scale of bi64 + */ +#define MAKE_NUMERIC64(ptr, value, scale) \ + do { \ + Numeric result = (Numeric)(ptr); \ + SET_VARSIZE(result, NUMERIC_64SZ); \ + result->choice.n_header = NUMERIC_64 + (scale); \ + *((int64*)(result->choice.n_bi.n_data)) = (value); \ + } while (0) + +/* + * @Description: copy bi128 to ptr, this operation no need to allocate memory + * @IN ptr: the numeric pointer + * @IN value: the value of bi128 + * @IN scale: the scale of bi128 + */ +#define MAKE_NUMERIC128(ptr, value, scale) \ + do { \ + Numeric result = (Numeric)(ptr); \ + SET_VARSIZE(result, NUMERIC_128SZ); \ + result->choice.n_header = NUMERIC_128 + (scale); \ + errno_t rc = EOK; \ + rc = memcpy_s(result->choice.n_bi.n_data, sizeof(int128), (&value), sizeof(int128)); \ + securec_check(rc, "\0", "\0"); \ + } while (0) + +/* + * the header size of short numeric is 6 bytes. + * the same to NUMERIC_HEADER_SIZE but for short numeric. + */ +#define SHORT_NUMERIC_HEADER_SIZE (VARHDRSZ + sizeof(uint16)) + +/* + * the same to NUMERIC_NDIGITS but for short numeric. + */ +#define SHORT_NUMERIC_NDIGITS(num) \ + (AssertMacro(NUMERIC_IS_SHORT(num)), ((VARSIZE(num) - SHORT_NUMERIC_HEADER_SIZE) / sizeof(NumericDigit))) + +/* + * the same to NUMERIC_DIGITS but for short numeric. + */ +#define SHORT_NUMERIC_DIGITS(num) (AssertMacro(NUMERIC_IS_SHORT(num)), (num)->choice.n_short.n_data) + +/* + * @Description: allocate memory for bi64, and assign value to it + * @IN value: the value of bi64 + * @IN scale: the scale of bi64 + */ +inline Datum makeNumeric64(int64 value, uint8 scale) +{ + Numeric result; + result = (Numeric)palloc(NUMERIC_64SZ); + SET_VARSIZE(result, NUMERIC_64SZ); + result->choice.n_header = NUMERIC_64 + scale; + *((int64*)(result->choice.n_bi.n_data)) = value; + return (Datum)result; +} + +/* + * @Description: allocate memory for bi128, and assign value to it + * @IN value: the value of bi128 + * @IN scale: the scale of bi128 + */ +inline Datum makeNumeric128(int128 value, uint8 scale) +{ + Numeric result; + result = (Numeric)palloc(NUMERIC_128SZ); + SET_VARSIZE(result, NUMERIC_128SZ); + result->choice.n_header = NUMERIC_128 + scale; + errno_t rc = EOK; + rc = memcpy_s(result->choice.n_bi.n_data, sizeof(int128), &value, sizeof(int128)); + securec_check(rc, "\0", "\0") return (Datum)result; +} + +/* Convert bi64 or bi128 to short numeric */ +extern Numeric convert_int64_to_numeric(int64 data, uint8 scale); +extern Numeric convert_int128_to_numeric(int128 data, int scale); + +/* + * @Description: convert bi64 or bi128 to numeric type + * @IN val: the bi64 or bi128 data + * @Return: the result of numeric type + */ +inline Numeric makeNumericNormal(Numeric val) +{ + Assert(NUMERIC_IS_BI(val)); + + if (NUMERIC_IS_BI64(val)) { + return convert_int64_to_numeric(NUMERIC_64VALUE(val), NUMERIC_BI_SCALE(val)); + } + + else if (NUMERIC_IS_BI128(val)) { + int128 tmp_data = 0; + errno_t rc = EOK; + rc = memcpy_s(&tmp_data, sizeof(int128), val->choice.n_bi.n_data, sizeof(int128)); + securec_check(rc, "\0", "\0"); + return convert_int128_to_numeric(tmp_data, NUMERIC_BI_SCALE(val)); + } + + else { + elog(ERROR, "unrecognized big integer numeric format"); + } + return NULL; +} + +/* + * @Description: Detoast column numeric data. Column numeric is + * a short-header type. + * @IN num: input numeric data + * @return: Numeric - detoast numeric data + */ +inline Numeric DatumGetBINumericShort(Datum num) +{ + /* + * unlikely this is a short-header varlena --- convert to 4-byte header format + */ + struct varlena* new_attr = NULL; + struct varlena* old_attr = (struct varlena*)num; + Size data_size = VARSIZE_SHORT(old_attr) - VARHDRSZ_SHORT; + Size new_size = data_size + VARHDRSZ; + errno_t rc = EOK; + + new_attr = (struct varlena*)palloc(new_size); + SET_VARSIZE(new_attr, new_size); + rc = memcpy_s(VARDATA(new_attr), new_size, VARDATA_SHORT(old_attr), data_size); + securec_check(rc, "", ""); + old_attr = new_attr; + return (Numeric)old_attr; +} + +/* + * @Description: Detoast column numeric data. Column numeric is unlikely + * a short-header type, simplify macro DatumGetNumeric + * + * @IN num: input numeric data + * @return: Numeric - detoast numeric data + */ +inline Numeric DatumGetBINumeric(Datum num) +{ + if (likely(!VARATT_IS_SHORT(num))) { + return (Numeric)num; + } else { + return DatumGetBINumericShort(num); + } +} + +#endif /* _PG_NUMERIC_GS_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/numeric.h postgresql-hll-2.14/include/utils/numeric.h --- postgresql-hll-2.14_old/include/utils/numeric.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/numeric.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,306 @@ +/* ------------------------------------------------------------------------- + * + * numeric.h + * Definitions for the exact numeric data type of Postgres + * + * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane. + * + * Copyright (c) 1998-2012, PostgreSQL Global Development Group + * + * src/include/utils/numeric.h + * + * ------------------------------------------------------------------------- + */ +#ifndef _PG_NUMERIC_H_ +#define _PG_NUMERIC_H_ + +#include "fmgr.h" + +/* ---------- + * Uncomment the following to enable compilation of dump_numeric() + * and dump_var() and to get a dump of any result produced by make_result(). + * ---------- +#define NUMERIC_DEBUG + */ + +/* ---------- + * Local data types + * + * Numeric values are represented in a base-NBASE floating point format. + * Each "digit" ranges from 0 to NBASE-1. The type NumericDigit is signed + * and wide enough to store a digit. We assume that NBASE*NBASE can fit in + * an int. Although the purely calculational routines could handle any even + * NBASE that's less than sqrt(INT_MAX), in practice we are only interested + * in NBASE a power of ten, so that I/O conversions and decimal rounding + * are easy. Also, it's actually more efficient if NBASE is rather less than + * sqrt(INT_MAX), so that there is "headroom" for mul_var and div_var_fast to + * postpone processing carries. + * + * Values of NBASE other than 10000 are considered of historical interest only + * and are no longer supported in any sense; no mechanism exists for the client + * to discover the base, so every client supporting binary mode expects the + * base-10000 format. If you plan to change this, also note the numeric + * abbreviation code, which assumes NBASE=10000. + * ---------- + */ + +#if 1 +#define NBASE 10000 +#define HALF_NBASE 5000 +#define DEC_DIGITS 4 /* decimal digits per NBASE digit */ +#define NUMERIC_SCALE_ADJUST(scale) ((int64)(scale + DEC_DIGITS - 1) / DEC_DIGITS) +#define MUL_GUARD_DIGITS 2 /* these are measured in NBASE digits */ +#define DIV_GUARD_DIGITS 4 + +typedef int16 NumericDigit; +#endif + +/* + * The Numeric type as stored on disk. + * + * If the high bits of the first word of a NumericChoice (n_header, or + * n_short.n_header, or n_long.n_sign_dscale) are NUMERIC_SHORT, then the + * numeric follows the NumericShort format; if they are NUMERIC_POS or + * NUMERIC_NEG, it follows the NumericLong format. If they are NUMERIC_NAN, + * it is a NaN. We currently always store a NaN using just two bytes (i.e. + * only n_header), but previous releases used only the NumericLong format, + * so we might find 4-byte NaNs on disk if a database has been migrated using + * pg_upgrade. In either case, when the high bits indicate a NaN, the + * remaining bits are never examined. Currently, we always initialize these + * to zero, but it might be possible to use them for some other purpose in + * the future. + * + * In the NumericShort format, the remaining 14 bits of the header word + * (n_short.n_header) are allocated as follows: 1 for sign (positive or + * negative), 6 for dynamic scale, and 7 for weight. In practice, most + * commonly-encountered values can be represented this way. + * + * In the NumericLong format, the remaining 14 bits of the header word + * (n_long.n_sign_dscale) represent the display scale; and the weight is + * stored separately in n_weight. + * + * NOTE: by convention, values in the packed form have been stripped of + * all leading and trailing zero digits (where a "digit" is of base NBASE). + * In particular, if the value is zero, there will be no digits at all! + * The weight is arbitrary in that case, but we normally set it to zero. + */ + +struct NumericShort { + uint16 n_header; /* Sign + display scale + weight */ + NumericDigit n_data[1]; /* Digits */ +}; + +struct NumericLong { + uint16 n_sign_dscale; /* Sign + display scale */ + int16 n_weight; /* Weight of 1st digit */ + NumericDigit n_data[1]; /* Digits */ +}; + +/* + * NumericBi is used for big integer(bi64 or bi128) + * n_header stores mark bits and scale of big integer, first 4 bits to + * distinguish bi64 and bi128, next 4 bits are not used, the last 8 bits + * store the scale of bit integer, scale value is between 0 and 38. + * n_data store big integer value(int64 or int128) + * + */ +struct NumericBi { + uint16 n_header; + uint8 n_data[1]; +}; + +/* + * Add NumericBi struct to NumericChoice + */ +union NumericChoice { + uint16 n_header; /* Header word */ + struct NumericLong n_long; /* Long form (4-byte header) */ + struct NumericShort n_short; /* Short form (2-byte header) */ + struct NumericBi n_bi; /* Short form (2-byte header) */ +}; + +struct NumericData { + int32 vl_len_; /* varlena header (do not touch directly!) */ + union NumericChoice choice; /* choice of format */ +}; + +/* The actual contents of Numeric are private to numeric.c */ +struct NumericData; +typedef struct NumericData* Numeric; + +/* + * Interpretation of high bits. + */ + +#define NUMERIC_SIGN_MASK 0xC000 +#define NUMERIC_POS 0x0000 +#define NUMERIC_NEG 0x4000 +#define NUMERIC_SHORT 0x8000 +#define NUMERIC_NAN 0xC000 + +/* + * big integer macro + * n_header is the mark bits of numeric struct, when numeric is NAN, n_header + * marked 0xC000. To distinguish bi64, bi128 and numeric, we use 0xD000 to mark + * bi64, 0xE000 marks bi128, others are numeric type. + */ +#define NUMERIC_64 0xD000 +#define NUMERIC_128 0xE000 +#define NUMERIC_BI_MASK 0xF000 +#define NUMERIC_BI_SCALEMASK 0x00FF +/* + * Hardcoded precision limit - arbitrary, but must be small enough that + * dscale values will fit in 14 bits. + */ +#define NUMERIC_MAX_PRECISION 1000 + +/* + * Internal limits on the scales chosen for calculation results + */ +#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION +#define NUMERIC_MIN_DISPLAY_SCALE 0 + +#define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2) + +/* + * For inherently inexact calculations such as division and square root, + * we try to get at least this many significant digits; the idea is to + * deliver a result no worse than float8 would. + */ +#define NUMERIC_MIN_SIG_DIGITS 16 + +/* + * numeric nan data length exclude header + */ +#define NUMERIC_NAN_DATALENGTH 0 +#define NUMERIC_ZERO_DATALENGTH 2 + +/* + * fmgr interface macros + * DatumGetNumeric function rebuild + */ +#define DatumGetNumeric(X) ((Numeric)PG_DETOAST_DATUM(X)) +#define DatumGetNumericCopy(X) ((Numeric)PG_DETOAST_DATUM_COPY(X)) +#define NumericGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n)) +#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x) + +/* + * Utility functions in numeric.c + */ +extern bool numeric_is_nan(Numeric num); +int32 numeric_maximum_size(int32 typmod); +extern char* numeric_out_sci(Numeric num, int scale); +extern Datum numtodsinterval(PG_FUNCTION_ARGS); +extern int cmp_numerics(Numeric num1, Numeric num2); + +// +// Numeric Compression Codes Area +// +#define INT32_MIN_ASCALE (-2) +#define INT32_MAX_ASCALE (2) +#define INT64_MIN_ASCALE (-4) +#define INT64_MAX_ASCALE (4) + +extern const int16 INT16_MIN_VALUE; +extern const int16 INT16_MAX_VALUE; +extern const int32 INT32_MIN_VALUE; +extern const int32 INT32_MAX_VALUE; +extern const int64 INT64_MIN_VALUE; +extern const int64 INT64_MAX_VALUE; + +#ifdef ENABLE_UT +extern void test_dump_numeric_to_file(_out_ FILE* fd, _in_ const char* str, _in_ Numeric num); +extern bool test_numeric_dscale_equal(_in_ Numeric v1, _in_ Numeric v2); +extern void test_dump_compressed_numeric_to_file(_out_ FILE* fd, _in_ const char* str, _in_ int64 v, _in_ char ascale); +extern char number_of_tail_zeros[10000]; +#endif + +/* + * convert functions between int32|int64|int128 and numerc + * convert numeric to int32, int64 or int128 + * convert int32, int64, int128 to numeric + */ +extern bool convert_short_numeric_to_int32(_in_ int64 v, _in_ char ascale); +extern bool convert_short_numeric_to_int64(_in_ char* inBuf, _out_ int64* v, _out_ char* ascale); +extern int convert_int64_to_short_numeric(_out_ char* outBuf, _in_ int64 v, _in_ char ascale, _in_ int32 typmod); +extern int batch_convert_short_numeric_to_int64(_in_ Datum* batchValues, _in_ char* batchNulls, _in_ int batchRows, + _in_ bool hasNull, _out_ int64* outInt, _out_ char* outAscales, _out_ bool* outSuccess, _out_ int* outNullCount); +extern int convert_int64_to_short_numeric_byscale( + _out_ char* outBuf, _in_ __int128_t v, _in_ int32 typmod, _in_ int32 vscale); +extern int convert_int128_to_short_numeric_byscale( + _out_ char* outBuf, _in_ int128 v, _in_ int32 typmod, _in_ int32 vscale); +extern Datum convert_short_numeric_to_int64(_in_ Numeric inNum, _out_ bool* outSuccess); +extern Datum convert_short_numeric_to_int128(_in_ Numeric inNum, _out_ bool* outSuccess); +extern Datum try_convert_numeric_normal_to_fast(Datum value); +extern int64 convert_short_numeric_to_int64_byscale(_in_ Numeric n, _in_ int scale); +extern void convert_short_numeric_to_int128_byscale(_in_ Numeric n, _in_ int scale, _out_ int128& result); +extern int32 get_ndigit_from_numeric(_in_ Numeric num); + +/* ---------- + * NumericVar is the format we use for arithmetic. The digit-array part + * is the same as the NumericData storage format, but the header is more + * complex. + * + * The value represented by a NumericVar is determined by the sign, weight, + * ndigits, and digits[] array. + * Note: the first digit of a NumericVar's value is assumed to be multiplied + * by NBASE ** weight. Another way to say it is that there are weight+1 + * digits before the decimal point. It is possible to have weight < 0. + * + * buf points at the physical start of the palloc'd digit buffer for the + * NumericVar. digits points at the first digit in actual use (the one + * with the specified weight). We normally leave an unused digit or two + * (preset to zeroes) between buf and digits, so that there is room to store + * a carry out of the top digit without reallocating space. We just need to + * decrement digits (and increment weight) to make room for the carry digit. + * (There is no such extra space in a numeric value stored in the database, + * only in a NumericVar in memory.) + * + * If buf is NULL then the digit buffer isn't actually palloc'd and should + * not be freed --- see the constants below for an example. + * + * dscale, or display scale, is the nominal precision expressed as number + * of digits after the decimal point (it must always be >= 0 at present). + * dscale may be more than the number of physically stored fractional digits, + * implying that we have suppressed storage of significant trailing zeroes. + * It should never be less than the number of stored digits, since that would + * imply hiding digits that are present. NOTE that dscale is always expressed + * in *decimal* digits, and so it may correspond to a fractional number of + * base-NBASE digits --- divide by DEC_DIGITS to convert to NBASE digits. + * + * rscale, or result scale, is the target precision for a computation. + * Like dscale it is expressed as number of *decimal* digits after the decimal + * point, and is always >= 0 at present. + * Note that rscale is not stored in variables --- it's figured on-the-fly + * from the dscales of the inputs. + * + * While we consistently use "weight" to refer to the base-NBASE weight of + * a numeric value, it is convenient in some scale-related calculations to + * make use of the base-10 weight (ie, the approximate log10 of the value). + * To avoid confusion, such a decimal-units weight is called a "dweight". + * + * NB: All the variable-level functions are written in a style that makes it + * possible to give one and the same variable as argument and destination. + * This is feasible because the digit buffer is separate from the variable. + * ---------- + */ +typedef struct NumericVar { + int ndigits; /* # of digits in digits[] - can be 0! */ + int weight; /* weight of first digit */ + int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */ + int dscale; /* display scale */ + NumericDigit* buf; /* start of palloc'd space for digits[] */ + NumericDigit* digits; /* base-NBASE digits */ +} NumericVar; + +#define init_var(v) MemSetAligned(v, 0, sizeof(NumericVar)) +Numeric makeNumeric(NumericVar* var); +extern Numeric make_result(NumericVar *var); +extern void free_var(NumericVar *var); +extern void int64_to_numericvar(int64 val, NumericVar *var); +extern void add_var(NumericVar *var1, NumericVar *var2, NumericVar *result); + + +#endif /* _PG_NUMERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/palloc.h postgresql-hll-2.14/include/utils/palloc.h --- postgresql-hll-2.14_old/include/utils/palloc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/palloc.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,261 @@ +/* ------------------------------------------------------------------------- + * + * palloc.h + * POSTGRES memory allocator definitions. + * + * This file contains the basic memory allocation interface that is + * needed by almost every backend module. It is included directly by + * postgres.h, so the definitions here are automatically available + * everywhere. Keep it lean! + * + * Memory allocation occurs within "contexts". Every chunk obtained from + * palloc()/MemoryContextAlloc() is allocated within a specific context. + * The entire contents of a context can be freed easily and quickly by + * resetting or deleting the context --- this is both faster and less + * prone to memory-leakage bugs than releasing chunks individually. + * We organize contexts into context trees to allow fine-grain control + * over chunk lifetime while preserving the certainty that we will free + * everything that should be freed. See utils/mmgr/README for more info. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/palloc.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PALLOC_H +#define PALLOC_H +#ifndef FRONTEND_PARSER + +/* + * Type MemoryContextData is declared in nodes/memnodes.h. Most users + * of memory allocation should just treat it as an abstract type, so we + * do not provide the struct contents here. + */ +typedef struct MemoryContextData* MemoryContext; + +/* + * CurrentMemoryContext is the default allocation context for palloc(). + * We declare it here so that palloc() can be a macro. Avoid accessing it + * directly! Instead, use MemoryContextSwitchTo() to change the setting. + */ +#ifdef WIN32 +extern THR_LOCAL MemoryContext CurrentMemoryContext; +extern THR_LOCAL MemoryContext SelfMemoryContext; +extern THR_LOCAL MemoryContext TopMemoryContext; +#else +extern THR_LOCAL PGDLLIMPORT MemoryContext CurrentMemoryContext; +extern THR_LOCAL PGDLLIMPORT MemoryContext SelfMemoryContext; +extern THR_LOCAL PGDLLIMPORT MemoryContext TopMemoryContext; +#endif /* WIN32 */ + +/* + * Flags for MemoryContextAllocExtended. + */ +#define MCXT_ALLOC_HUGE 0x01 /* allow huge allocation (> 1 GB) */ +#define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ +#define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ + +#define ENABLE_MEMORY_PROTECT() (t_thrd.utils_cxt.memNeedProtect = true) +#define DISABLE_MEMORY_PROTECT() (t_thrd.utils_cxt.memNeedProtect = false) + +/* Definition for the unchanged interfaces */ +#define MemoryContextAlloc(context, size) MemoryContextAllocDebug(context, size, __FILE__, __LINE__) +#define MemoryContextAllocZero(context, size) MemoryContextAllocZeroDebug(context, size, __FILE__, __LINE__) +#define MemoryContextAllocZeroAligned(context, size) \ + MemoryContextAllocZeroAlignedDebug(context, size, __FILE__, __LINE__) +#define MemoryContextStrdup(context, size) MemoryContextStrdupDebug(context, size, __FILE__, __LINE__) +#define repalloc(pointer, size) repallocDebug(pointer, size, __FILE__, __LINE__) +#define repalloc_noexcept(pointer, size) repalloc_noexcept_Debug(pointer, size, __FILE__, __LINE__) +#define pnstrdup(in, len) pnstrdupDebug(in, len, __FILE__, __LINE__) + +#define INSTANCE_GET_MEM_CXT_GROUP g_instance.mcxt_group->GetMemCxtGroup +#define THREAD_GET_MEM_CXT_GROUP t_thrd.mcxt_group->GetMemCxtGroup +#define SESS_GET_MEM_CXT_GROUP u_sess->mcxt_group->GetMemCxtGroup + +/* + * Fundamental memory-allocation operations (more are in utils/memutils.h) + */ +extern void* MemoryContextAllocDebug(MemoryContext context, Size size, const char* file, int line); +extern void* MemoryContextAllocHugeDebug(MemoryContext context, Size size, const char* file, int line); +extern void* repallocHugeDebug(void* pointer, Size size, const char* file, int line); +extern void* MemoryContextAllocZeroDebug(MemoryContext context, Size size, const char* file, int line); +extern void* MemoryContextAllocZeroAlignedDebug(MemoryContext context, Size size, const char* file, int line); +extern char* MemoryContextStrdupDebug(MemoryContext context, const char* string, const char* file, int line); +extern void* MemoryContextMemalignAllocDebug(MemoryContext context, Size align, Size size, const char* file, int line); +extern void MemoryContextMemalignFree(MemoryContext context, void* pointer); +#ifndef FRONTEND +extern void* palloc_extended(Size size, int flags); +extern void* palloc0_noexcept(Size size); +#define palloc(sz) MemoryContextAlloc(CurrentMemoryContext, (sz)) +#endif +#define palloc0(sz) MemoryContextAllocZero(CurrentMemoryContext, (sz)) + +#define palloc_huge(context, size) MemoryContextAllocHugeDebug(context, size, __FILE__, __LINE__) + +#define repalloc_huge(pointer, size) repallocHugeDebug(pointer, size, __FILE__, __LINE__) + +#define selfpalloc(sz) MemoryContextAlloc(SelfMemoryContext, (sz)) + +#define selfpalloc0(sz) MemoryContextAllocZero(SelfMemoryContext, (sz)) + +#define selfpfree(ptr) pfree((ptr)) + +#define selfrepalloc(ptr, sz) repalloc((ptr), (sz)) + +#define selfpstrdup(str) MemoryContextStrdup(SelfMemoryContext, (str)) + +extern THR_LOCAL MemoryContext AlignMemoryContext; +#define mem_align_alloc(align, size) \ + MemoryContextMemalignAllocDebug(AlignMemoryContext, (align), (size), __FILE__, __LINE__) +#define mem_align_free(ptr) MemoryContextMemalignFree(AlignMemoryContext, (ptr)) + +/* + * The result of palloc() is always word-aligned, so we can skip testing + * alignment of the pointer when deciding which MemSet variant to use. + * Note that this variant does not offer any advantage, and should not be + * used, unless its "sz" argument is a compile-time constant; therefore, the + * issue that it evaluates the argument multiple times isn't a problem in + * practice. + */ +#define palloc0fast(sz) \ + (MemSetTest(0, sz) ? MemoryContextAllocZeroAligned(CurrentMemoryContext, sz) \ + : MemoryContextAllocZero(CurrentMemoryContext, sz)) + +extern void pfree(void* pointer); + +template +bool isConst(T& x) +{ + return false; +} + +template +bool isConst(T const& x) +{ + return true; +} + +#define FREE_POINTER(ptr) \ + do { \ + if ((ptr) != NULL) { \ + pfree((void*)ptr); \ + if (!isConst(ptr)) \ + (ptr) = NULL; \ + } \ + } while (0) + +// call pfree() and set pointer to be NULL. +#define pfree_ext(__p) FREE_POINTER(__p) + +extern void* repallocDebug(void* pointer, Size size, const char* file, int line); +extern void* repalloc_noexcept_Debug(void* pointer, Size size, const char* file, int line); + +/* + * MemoryContextSwitchTo can't be a macro in standard C compilers. + * But we can make it an inline function if the compiler supports it. + * + * This file has to be includable by some non-backend code such as + * pg_resetxlog, so don't expose the CurrentMemoryContext reference + * if FRONTEND is defined. + */ +#if defined(USE_INLINE) && !defined(FRONTEND) + +static inline MemoryContext MemoryContextSwitchTo(MemoryContext context) +{ + MemoryContext old = CurrentMemoryContext; + + CurrentMemoryContext = context; + return old; +} +#else + +extern MemoryContext MemoryContextSwitchTo(MemoryContext context); +#endif /* USE_INLINE && !FRONTEND */ + +/* + * These are like standard strdup() except the copied string is + * allocated in a context, not with malloc(). + */ +extern char* MemoryContextStrdupDebug(MemoryContext context, const char* string, const char* file, int line); + +#define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str)) + +#define pstrdup_ext(str) \ + (((str) == NULL) ? NULL : (pstrdup((const char*)(str)))) + +extern char* pnstrdupDebug(const char* in, Size len, const char* file, int line); + +extern void AllocSetCheckPointer(void* pointer); + +#if defined(WIN32) || defined(__CYGWIN__) +extern void* pgport_palloc(Size sz); +extern char* pgport_pstrdup(const char* str); +extern void pgport_pfree(void* pointer); +#endif + +#define New(pmc) new (pmc, __FILE__, __LINE__) + +// BaseObject is a basic class +// All other class should inherit from BaseObject class which +// override operator new/delete. +// +class BaseObject { +public: + ~BaseObject() + {} + + void* operator new(size_t size, MemoryContextData* pmc, const char* file, int line) + { + return MemoryContextAllocDebug(pmc, size, file, line); + } + + void* operator new[](size_t size, MemoryContextData* pmc, const char* file, int line) + { + return MemoryContextAllocDebug(pmc, size, file, line); + } + + void operator delete(void* p) + { + pfree(p); + } + + void operator delete[](void* p) + { + pfree(p); + } +}; + +/* + *It is used for delete object whose destructor is null and free memory in Destroy() + *_objptr can't include type change, for example (A*)b, that will lead to compile error in (_objptr) = NULL + *If _objptr include type change, please use DELETE_EX_TYPE to complete it. + *It is supplied easily for developers to refactor destructor in the future + */ +#define DELETE_EX(_objptr) \ + do { \ + (_objptr)->Destroy(); \ + delete (_objptr); \ + (_objptr) = NULL; \ + } while (0) + +// used for _objptr need to change to another type +#define DELETE_EX_TYPE(_objptr, _type) \ + do { \ + ((_type*)(_objptr))->Destroy(); \ + delete (_type*)(_objptr); \ + (_objptr) = NULL; \ + } while (0) + +#define DELETE_EX2(_objptr) \ + do { \ + if ((_objptr) != nullptr) { \ + delete (_objptr); \ + (_objptr) = NULL; \ + } \ + } while (0) + +#endif /* !FRONTEND_PARSER */ +#endif /* PALLOC_H */ diff -uprN postgresql-hll-2.14_old/include/utils/partcache.h postgresql-hll-2.14/include/utils/partcache.h --- postgresql-hll-2.14_old/include/utils/partcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/partcache.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,100 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partcache.h + * + * + * + * IDENTIFICATION + * src/include/utils/partcache.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTCACHE_H +#define PARTCACHE_H +#include "access/tupdesc.h" +#include "nodes/bitmapset.h" +#include "utils/relcache.h" + +#define PARTITIONTYPE(partition) (partition->pd_part->parttype) + +#define PartitionIsPartitionedTable(partition) (PART_OBJ_TYPE_PARTED_TABLE == (partition)->pd_part->parttype) + +#define PartitionIsToastTable(partition) (PART_OBJ_TYPE_TOAST_TABLE == (partition)->pd_part->parttype) + +#define PartitionIsTablePartition(partition) (PART_OBJ_TYPE_TABLE_PARTITION == (partition)->pd_part->parttype) + +#define PartitionIsBucket(partition) ((partition)->pd_node.bucketNode > InvalidBktId) + +#define PartitionIsIndexPartition(partition) (PART_OBJ_TYPE_INDEX_PARTITION == (partition)->pd_part->parttype) + +/* + * Routines to open (lookup) and close a partcache entry + */ +extern Partition PartitionIdGetPartition(Oid partitionId, bool isbucket); +extern void PartitionClose(Partition partition); +extern char* PartitionOidGetName(Oid partOid); +extern Oid PartitionOidGetTablespace(Oid partOid); +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void PartitionForgetPartition(Oid partid); +/* + * Routines for backend startup + */ +extern void PartitionCacheInitialize(void); +extern void PartitionCacheInitializePhase2(void); +extern void PartitionCacheInitializePhase3(void); +/* + * Routine to create a partcache entry for an about-to-be-created relation + */ +Partition PartitionBuildLocalPartition(const char* relname, Oid partid, Oid partfilenode, Oid parttablespace); +/* + * Routines for backend startup + */ +extern void PartitionCacheInitialize(void); + +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void PartitionCacheInvalidateEntry(Oid partitionId); +extern void PartitionCacheInvalidate(void); +extern void PartitionCloseSmgrByOid(Oid partitionId); +extern void AtEOXact_PartitionCache(bool isCommit); +extern void AtEOSubXact_PartitionCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); +extern Relation partitionGetRelation(Relation rel, Partition part); + +void releaseDummyRelation(Relation* relation); + +extern void PartitionSetNewRelfilenode(Relation parent, Partition part, TransactionId freezeXid); + +/* + * Routines for global partition index open partition + */ +extern PartStatus PartitionGetMetadataStatus(Oid partOid, bool vacuumFlag); +extern Datum SetWaitCleanGpiRelOptions(Datum oldOptions, bool enable); +extern void PartitionedSetWaitCleanGpi(const char* parentName, Oid parentPartOid, bool enable, bool inplace); +extern void PartitionSetWaitCleanGpi(Oid partOid, bool enable, bool inplace); +extern bool PartitionInvisibleMetadataKeep(Datum datumRelOptions); +extern void PartitionedSetEnabledClean(Oid parentOid); +extern void PartitionSetEnabledClean( + Oid parentOid, const Bitmapset* cleanedParts, const Bitmapset* invisibleParts, bool updatePartitioned); +extern void PartitionSetAllEnabledClean(Oid parentOid); +extern void PartitionGetAllInvisibleParts(Oid parentOid, Bitmapset** invisibleParts); +extern bool PartitionMetadataDisabledClean(Relation pgPartition); + +#endif /* RELCACHE_H */ + diff -uprN postgresql-hll-2.14_old/include/utils/partitionkey.h postgresql-hll-2.14/include/utils/partitionkey.h --- postgresql-hll-2.14_old/include/utils/partitionkey.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/partitionkey.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionkey.h + * + * + * + * IDENTIFICATION + * src/include/utils/partitionkey.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONKEY_H +#define PARTITIONKEY_H + +#include "nodes/pg_list.h" + +/* + * @@GaussDB@@ + * Brief + * Description : transform the list of maxvalue + * (partition's boundary, Const node form) into TEXT array + * input : List of Const + * return value : TEXT array + */ +extern Datum transformPartitionBoundary(List* maxValueList, const bool* isTimestamptz); + +extern Datum transformListBoundary(List* maxValueList, const bool* isTimestamptz); + +/* + * @@GaussDB@@ + * Brief + * Description : transform TEXT array into a list of Value + * input : TEXT Array + * return value : List of Value + * Note : + */ +extern List* untransformPartitionBoundary(Datum options); + +/* + * @@GaussDB@@ + * Brief + * Description : Check if given attnum pos is satisfied with value partitioned policy + * input : atts array and position(attno) of partitioned columns + * return value : None- + * Note : + */ +extern void CheckValuePartitionKeyType(Form_pg_attribute* attrs, List* pos); +#endif diff -uprN postgresql-hll-2.14_old/include/utils/partitionmap_gs.h postgresql-hll-2.14/include/utils/partitionmap_gs.h --- postgresql-hll-2.14_old/include/utils/partitionmap_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/partitionmap_gs.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,456 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionmap_gs.h + * + * this file separates from partitionmap.h, extract major code from partitionmap.h + * to here + * + * IDENTIFICATION + * src/include/utils/partitionmap_gs.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONMAP_GS_H_ +#define PARTITIONMAP_GS_H_ + +#include "postgres.h" +#include "access/heapam.h" +#include "knl/knl_variable.h" +#include "access/htup.h" +#include "catalog/pg_type.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "utils/hsearch.h" +#include "utils/rel.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/partitionmap.h" + +typedef enum PartitionArea { + PART_AREA_NONE = 0, + PART_AREA_RANGE, + PART_AREA_INTERVAL, + PART_AREA_LIST, + PART_AREA_HASH +} PartitionArea; + +/* + * Partition position in partitioned-table + * partition sequence is numbered in range area and interval area separately. + * partition sequec start with 0 + */ +typedef struct PartitionIdentifier { + PartitionArea partArea; + int partSeq; + bool fileExist; + Oid partitionId; +} PartitionIdentifier; + +/** + *partition map is used to find which partition a record is mapping to. + *and pruning the unused partition when querying.the map has two part: + *and range part and interval part. + *range part is a array of RangeElement which is sorted by RangeElement.boundary + *interval part is array of IntervalElement which is sorted by IntervalElement.sequenceNum + *binary search is used to routing in range part of map , and in interval part + *we use (recordValue-lowBoundary_of_interval)/interval to get the sequenceNum of + *a interval partition + * + */ +typedef struct RangeElement { + Oid partitionOid; /*the oid of partition*/ + int len; /*the length of partition key number*/ + Const* boundary[RANGE_PARTKEYMAXNUM]; /*upper bond of partition */ + bool isInterval; /* is interval partition */ +} RangeElement; + +typedef struct IntervalElement { + Oid partitionOid; /* the oid of partition */ + int sequenceNum; /* the logic number of interval partition. */ +} IntervalElement; + +typedef struct ListPartElement { + Oid partitionOid; /* the oid of partition */ + int len; /* the length of values */ + Const** boundary; /* list values */ +} ListPartElement; + +typedef struct HashPartElement { + Oid partitionOid; /* the oid of partition */ + Const* boundary[1]; /* hash bucket */ +} HashPartElement; + +// describe partition info of Value Partitioned-Table +typedef struct ValuePartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + List* partList; /* List Partition key List */ +} ValuePartitionMap; + +// describe partition info of Range Partitioned-Table +typedef struct RangePartitionMap { + PartitionMap type; + Oid relid; /*oid of partitioned table*/ + int2vector* partitionKey; /*partition key*/ + Oid* partitionKeyDataType; /*the data type of partition key*/ + /*section 1: range partition specific*/ + int rangeElementsNum; /* the number of range partition*/ + RangeElement* rangeElements; /* array of RangeElement */ + Interval* intervalValue; /* valid for interval partition */ + oidvector* intervalTablespace; /* valid for interval partition */ +} RangePartitionMap; + +bool ValueSatisfyLowBoudary(Const** partKeyValue, RangeElement* partition, Interval* intervalValue, bool topClosed); +extern int2vector* GetPartitionKey(const PartitionMap* partMap); + +typedef struct ListPartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + int2vector* partitionKey; /* partition key */ + Oid* partitionKeyDataType; /* the data type of partition key */ + /* section 1: list partition specific */ + int listElementsNum; /* the number of list partition */ + ListPartElement* listElements; /* array of listElement */ +} ListPartitionMap; + +typedef struct HashPartitionMap { + PartitionMap type; + Oid relid; /* Oid of partitioned table */ + int2vector* partitionKey; /* partition key */ + Oid* partitionKeyDataType; /* the data type of partition key */ + /* section 1: hash partition specific */ + int hashElementsNum; /* the number of hash partition */ + HashPartElement* hashElements; /* array of hashElement */ +} HashPartitionMap; + +#define PartitionkeyTypeGetIntervalType(type) \ + do { \ + if (DATEOID == (type) || TIMESTAMPOID == (type) || TIMESTAMPTZOID == (type)) { \ + (type) = INTERVALOID; \ + } \ + } while (0) + +#define partitionRoutingForTuple(rel, tuple, partIdentfier) \ + do { \ + TupleDesc tuple_desc = NULL; \ + int2vector* partkey_column = NULL; \ + int partkey_column_n = 0; \ + static THR_LOCAL Const consts[PARTITION_PARTKEYMAXNUM]; \ + static THR_LOCAL Const* values[PARTITION_PARTKEYMAXNUM]; \ + bool isnull = false; \ + Datum column_raw; \ + int i = 0; \ + partkey_column = GetPartitionKey((rel)->partMap); \ + partkey_column_n = partkey_column->dim1; \ + tuple_desc = (rel)->rd_att; \ + for (i = 0; i < partkey_column_n; i++) { \ + isnull = false; \ + column_raw = fastgetattr((tuple), partkey_column->values[i], tuple_desc, &isnull); \ + values[i] = \ + transformDatum2Const((rel)->rd_att, partkey_column->values[i], column_raw, isnull, &consts[i]); \ + } \ + if (PartitionMapIsInterval((rel)->partMap) && values[0]->constisnull) { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), \ + errmsg("inserted partition key does not map to any partition"), \ + errdetail("inserted partition key cannot be NULL for interval-partitioned table"))); \ + } \ + partitionRoutingForValue((rel), values, partkey_column_n, true, false, (partIdentfier)); \ + } while (0) + +#define partitionRoutingForValue(rel, keyValue, valueLen, topClosed, missIsOk, result) \ + do { \ + if ((rel)->partMap->type == PART_TYPE_RANGE || (rel)->partMap->type == PART_TYPE_INTERVAL) { \ + if ((rel)->partMap->type == PART_TYPE_RANGE) { \ + (result)->partArea = PART_AREA_RANGE; \ + } else { \ + Assert((valueLen) == 1); \ + (result)->partArea = PART_AREA_INTERVAL; \ + } \ + (result)->partitionId = getRangePartitionOid((rel)->partMap, (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + RangePartitionMap* partMap = (RangePartitionMap*)((rel)->partMap); \ + if (partMap->rangeElements[(result)->partSeq].isInterval && \ + !ValueSatisfyLowBoudary( \ + keyValue, &partMap->rangeElements[(result)->partSeq], partMap->intervalValue, topClosed)) { \ + (result)->partSeq = -1; \ + (result)->partitionId = InvalidOid; \ + (result)->fileExist = false; \ + } \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_LIST) { \ + (result)->partArea = PART_AREA_LIST; \ + (result)->partitionId = getListPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_HASH) { \ + (result)->partArea = PART_AREA_HASH; \ + (result)->partitionId = getHashPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (rel)->partMap->type))); \ + } \ + } while (0) + +/* + * search >/>= keyValue partition if direction is true + * search type == PART_TYPE_RANGE) { \ + (result)->partArea = PART_AREA_RANGE; \ + } else if ((GetPartitionMap(cxt))->type == PART_TYPE_INTERVAL) { \ + Assert((valueLen) == 1); \ + (result)->partArea = PART_AREA_INTERVAL; \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (GetPartitionMap(cxt))->type))); \ + } \ + (result)->partitionId = getRangePartitionOid((GetPartitionMap(cxt)), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + RangePartitionMap* partMap = (RangePartitionMap*)(GetPartitionMap(cxt)); \ + if (partMap->rangeElements[(result)->partSeq].isInterval && !direction && \ + !ValueSatisfyLowBoudary( \ + keyValue, &partMap->rangeElements[(result)->partSeq], partMap->intervalValue, topClosed)) { \ + --((result)->partSeq); \ + (result)->partitionId = partMap->rangeElements[(result)->partSeq].partitionOid; \ + } \ + } \ + } while (0) + +#define partitionRoutingForValueEqual(rel, keyValue, valueLen, topClosed, result) \ + do { \ + if ((rel)->partMap->type == PART_TYPE_LIST) { \ + (result)->partArea = PART_AREA_LIST; \ + (result)->partitionId = getListPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else if ((rel)->partMap->type == PART_TYPE_HASH) { \ + (result)->partArea = PART_AREA_HASH; \ + (result)->partitionId = getHashPartitionOid((rel), (keyValue), &((result)->partSeq), topClosed); \ + if ((result)->partSeq < 0) { \ + (result)->fileExist = false; \ + } else { \ + (result)->fileExist = true; \ + } \ + } else { \ + ereport(ERROR, \ + (errcode(ERRCODE_INTERNAL_ERROR), errmsg("Unsupported partition strategy:%d", (rel)->partMap->type))); \ + } \ + } while (0) + +typedef enum PruningResultState { PRUNING_RESULT_EMPTY, PRUNING_RESULT_SUBSET, PRUNING_RESULT_FULL } PruningResultState; + +/* + * PruningBoundary is NULL if pruning result is EMPTY, + * all min item and max item are NULLs if pruning result is FULL. + */ +typedef struct PruningBoundary { + PruningResultState state; + int partitionKeyNum; + Datum* min; + bool* minClose; + Datum* max; + bool* maxClose; +} PruningBoundary; + +/* + * hash table that index the fakeRelation cache + */ + +typedef struct partrelidcachekey { + Oid partoid; + int4 bucketid; +} PartRelIdCacheKey; + +typedef struct partrelidcacheent { + Oid partoid; + int4 bucketid; + Relation reldesc; + Partition partdesc; +} PartRelIdCacheEnt; + +#define searchFakeReationForPartitionOid(fakeRels, cxt, rel, partOid, fakeRelation, partition, lmode) \ + do { \ + PartRelIdCacheKey _key = {partOid, -1}; \ + if (PointerIsValid(partition)) { \ + break; \ + } \ + if (RelationIsNonpartitioned(rel)) { \ + fakeRelation = NULL; \ + partition = NULL; \ + break; \ + } \ + if (PointerIsValid(fakeRels)) { \ + FakeRelationIdCacheLookup(fakeRels, _key, fakeRelation, partition); \ + if (!RelationIsValid(fakeRelation)) { \ + partition = partitionOpen(rel, partOid, lmode); \ + fakeRelation = partitionGetRelation(rel, partition); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, partition, -1); \ + } \ + } else { \ + HASHCTL ctl; \ + errno_t errorno = EOK; \ + errorno = memset_s(&ctl, sizeof(ctl), 0, sizeof(ctl)); \ + securec_check_c(errorno, "\0", "\0"); \ + ctl.keysize = sizeof(PartRelIdCacheKey); \ + ctl.entrysize = sizeof(PartRelIdCacheEnt); \ + ctl.hash = tag_hash; \ + ctl.hcxt = cxt; \ + fakeRels = hash_create( \ + "fakeRelationCache by OID", FAKERELATIONCACHESIZE, &ctl, HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); \ + partition = partitionOpen(rel, partOid, lmode); \ + fakeRelation = partitionGetRelation(rel, partition); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, partition, -1); \ + } \ + } while (0) + +#define searchHBucketFakeRelation(fakeRels, cxt, rel, bucketid, fakeRelation) \ + do { \ + PartRelIdCacheKey _key = {(rel->rd_id), bucketid}; \ + Partition partition; \ + Relation parentRel = rel; \ + Assert(RELATION_OWN_BUCKET(rel)); \ + if (bucketid == -1) { \ + ereport(ERROR, \ + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \ + errmsg("Invaild Oid when open hash bucket relation, the target bucket may not exist on current datanode"))); \ + } \ + if (PointerIsValid(fakeRels)) { \ + FakeRelationIdCacheLookup(fakeRels, _key, fakeRelation, partition); \ + if (!RelationIsValid(fakeRelation)) { \ + fakeRelation = bucketGetRelation(parentRel, NULL, bucketid); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, NULL, bucketid); \ + } \ + } else { \ + HASHCTL ctl; \ + errno_t errorno = EOK; \ + errorno = memset_s(&ctl, sizeof(ctl), 0, sizeof(ctl)); \ + securec_check_c(errorno, "\0", "\0"); \ + ctl.keysize = sizeof(PartRelIdCacheKey); \ + ctl.entrysize = sizeof(PartRelIdCacheEnt); \ + ctl.hash = tag_hash; \ + ctl.hcxt = cxt; \ + fakeRels = hash_create("fakeRelationCache by OID", \ + FAKERELATIONCACHESIZE, \ + &ctl, \ + HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT); \ + fakeRelation = bucketGetRelation(parentRel, NULL, bucketid); \ + FakeRelationCacheInsert(fakeRels, fakeRelation, NULL, bucketid); \ + } \ + } while (0) + +#define FakeRelationIdCacheLookup(CACHE, KEY, RELATION, PARTITION) \ + do { \ + PartRelIdCacheEnt* hentry; \ + hentry = (PartRelIdCacheEnt*)hash_search(CACHE, (void*)&(KEY), HASH_FIND, NULL);\ + if (hentry) { \ + RELATION = hentry->reldesc; \ + PARTITION = hentry->partdesc; \ + } else { \ + RELATION = NULL; \ + PARTITION = NULL; \ + } \ + } while (0) + +#define FakeRelationCacheInsert(CACHE, RELATION, PARTITION, BUCKET) \ + do { \ + PartRelIdCacheEnt* idhentry; \ + bool found; \ + PartRelIdCacheKey key={(RELATION->rd_id), BUCKET}; \ + idhentry = (PartRelIdCacheEnt*)hash_search(CACHE, (void*)&(key), HASH_ENTER, &found); \ + /* used to give notice if found -- now just keep quiet */ \ + idhentry->reldesc = RELATION; \ + idhentry->partdesc = PARTITION; \ + } while (0) + +#define FakeRelationCacheDestroy(HTAB) \ + do { \ + HASH_SEQ_STATUS status; \ + PartRelIdCacheEnt* idhentry; \ + Relation parentRelation = NULL; \ + hash_seq_init(&status, (HTAB)); \ + while ((idhentry = (PartRelIdCacheEnt*)hash_seq_search(&status)) != NULL) { \ + if (idhentry->bucketid == InvalidBktId) { \ + parentRelation = relation_open(idhentry->reldesc->parentId, NoLock);\ + releaseDummyRelation(&idhentry->reldesc); \ + partitionClose(parentRelation, idhentry->partdesc, NoLock); \ + relation_close(parentRelation, NoLock); \ + } else { \ + bucketCloseRelation(idhentry->reldesc); \ + } \ + } \ + hash_destroy((HTAB)); \ + (HTAB) = NULL; \ + } while (0) + +typedef struct PruningResult { + NodeTag type; + PruningResultState state; + PruningBoundary* boundary; + Bitmapset* bm_rangeSelectedPartitions; + int intervalOffset; /*the same as intervalMinSeq*/ + /*if interval partitions is empty, intervalOffset=-1*/ + Bitmapset* intervalSelectedPartitions; + List* ls_rangeSelectedPartitions; + Param* paramArg; + OpExpr* exprPart; + Expr* expr; +} PruningResult; + +extern Oid partIDGetPartOid(Relation relation, PartitionIdentifier* partID); +extern PartitionIdentifier* partOidGetPartID(Relation rel, Oid partOid); + +extern void RebuildPartitonMap(PartitionMap* oldMap, PartitionMap* newMap); +extern void RebuildRangePartitionMap(RangePartitionMap* oldMap, RangePartitionMap* newMap); + +bool isPartKeyValuesInPartition(RangePartitionMap* partMap, Const** partKeyValues, int partkeyColumnNum, int partSeq); + +extern int comparePartitionKey(RangePartitionMap* partMap, Const** values1, Const** values2, int partKeyNum); + +extern int lookupHBucketid(oidvector *buckets, int low, int2 bucket_id); + +extern int2 computeTupleBucketId(Relation rel, HeapTuple tuple); + +extern Oid GetNeedDegradToRangePartOid(Relation rel, Oid partOid); +extern RangeElement* CopyRangeElementsWithoutBoundary(const RangeElement* src, int elementNum); +extern char* ReadIntervalStr(HeapTuple tuple, TupleDesc tupleDesc); +extern oidvector* ReadIntervalTablespace(HeapTuple tuple, TupleDesc tupleDesc); +int ValueCmpLowBoudary(Const** partKeyValue, const RangeElement* partition, Interval* intervalValue); +extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval); +extern RangeElement* copyRangeElements(RangeElement* src, int elementNum, int partkeyNum); +extern int rangeElementCmp(const void* a, const void* b); +extern void DestroyListElements(ListPartElement* src, int elementNum); +#endif /* PARTITIONMAP_GS_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/partitionmap.h postgresql-hll-2.14/include/utils/partitionmap.h --- postgresql-hll-2.14_old/include/utils/partitionmap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/partitionmap.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,142 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * partitionmap.h + * + * + * + * IDENTIFICATION + * src/include/utils/partitionmap.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARTITIONMAP_H_ +#define PARTITIONMAP_H_ + +#include "postgres.h" +#include "access/htup.h" +#include "catalog/pg_type.h" +#include "nodes/primnodes.h" +#include "storage/lock.h" +#include "utils/hsearch.h" +#include "utils/relcache.h" +#include "utils/partcache.h" + +typedef enum PartitionType { + PART_TYPE_NONE = 0, + PART_TYPE_RANGE, + PART_TYPE_INTERVAL, + PART_TYPE_HASH, + PART_TYPE_LIST, + PART_TYPE_VALUE +} PartitionType; + +// describe abstract partition map +typedef struct PartitionMap { + PartitionType type; + int refcount; + bool isDirty; +} PartitionMap; + +// describe range partition +#define RANGE_PARTKEYMAXNUM 4 +#define PARTITION_PARTKEYMAXNUM 4 +#define VALUE_PARTKEYMAXNUM 4 +#define INTERVAL_PARTKEYMAXNUM 1 + +#define PartitionLogicalExist(partitionIdentifier) ((partitionIdentifier)->partSeq >= 0) + +#define PartitionPhysicalExist(partitionIdentifier) \ + ((partitionIdentifier)->partArea != PART_AREA_NONE && ((partitionIdentifier)->fileExist) + +void incre_partmap_refcount(PartitionMap* map); +void decre_partmap_refcount(PartitionMap* map); + +#define PartitionMapGetKey(partmap) (((RangePartitionMap*)(partmap))->partitionKey) + +#define PartitionMapGetType(partmap) (((RangePartitionMap*)(partmap))->partitionKeyDataType) + +#define PartitionMapIsRange(partmap) (PART_TYPE_RANGE == ((RangePartitionMap*)(partmap))->type.type) + +#define PartitionMapIsList(partmap) (PART_TYPE_LIST == ((ListPartitionMap*)(partmap))->type.type) + +#define PartitionMapIsHash(partmap) (PART_TYPE_HASH == ((HashPartitionMap*)(partmap))->type.type) + +#define PartitionMapIsInterval(partmap) (PART_TYPE_INTERVAL == ((RangePartitionMap*)(partmap))->type.type) + +#define FAKERELATIONCACHESIZE 100 + +#define BoundaryIsNull(boundary) !(PointerIsValid(boundary)) + +#define BoundaryIsFull(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_FULL) + +#define BoundaryIsEmpty(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_EMPTY) + +#define BoundaryIsSubset(boundary) (PointerIsValid(boundary) && (boundary)->state == PRUNING_RESULT_SUBSET) + +#define PruningResultIsFull(pruningRes) (PointerIsValid(pruningRes) && (pruningRes)->state == PRUNING_RESULT_FULL) + +#define PruningResultIsEmpty(pruningRes) (!PointerIsValid(pruningRes) || (pruningRes)->state == PRUNING_RESULT_EMPTY) + +#define PruningResultIsSubset(pruningRes) (PointerIsValid(pruningRes) && (pruningRes)->state == PRUNING_RESULT_SUBSET) + +extern List* relationGetPartitionOidList(Relation rel); +extern void RelationInitPartitionMap(Relation relation); + +extern int partOidGetPartSequence(Relation rel, Oid partOid); +extern Oid getListPartitionOid(Relation relation, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid getHashPartitionOid(Relation relation, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid getRangePartitionOid(PartitionMap* partitionmap, Const** partKeyValue, int* partIndex, bool topClosed); +extern Oid GetPartitionOidByParam(Relation relation, Param *paramArg, ParamExternData *prm); +extern List* getPartitionBoundaryList(Relation rel, int sequence); +extern Oid partitionKeyValueListGetPartitionOid(Relation rel, List* partKeyValueList, bool topClosed); +extern int getNumberOfRangePartitions(Relation rel); +extern int getNumberOfListPartitions(Relation rel); +extern int getNumberOfHashPartitions(Relation rel); +extern int getNumberOfPartitions(Relation rel); +extern Const* transformDatum2Const(TupleDesc tupledesc, int16 attnum, Datum datumValue, bool isnull, Const* cnst); + +extern List* relationGetPartitionList(Relation relation, LOCKMODE lockmode); +extern List* indexGetPartitionOidList(Relation indexRelation); +extern List* indexGetPartitionList(Relation indexRelation, LOCKMODE lockmode); +extern void releasePartitionList(Relation relation, List** partList, LOCKMODE lockmode); + +extern List* relationGetPartitionOidList(Relation rel); +extern void releasePartitionOidList(List** partList); + +extern int2vector* getPartitionKeyAttrNo( + Oid** typeOids, HeapTuple pg_part_tup, TupleDesc tupledsc, TupleDesc rel_tupledsc); +extern void unserializePartitionStringAttribute(Const** outMax, int outMaxLen, Oid* partKeyType, int partKeyTypeLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); +extern void unserializeListPartitionAttribute(int *len, Const*** listValues, Oid* partKeyType, int partKeyTypeLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); +extern void unserializeHashPartitionAttribute(Const** outMax, int outMaxLen, + Oid relid, int2vector* partkey, HeapTuple pg_part_tup, int att_num, TupleDesc tupledsc); + +extern int partitonKeyCompare(Const** value1, Const** value2, int len); +extern int getPartitionNumber(PartitionMap* map); + +extern bool targetListHasPartitionKey(List* targetList, Oid partitiondtableid); + +extern int constCompare_constType(Const* value1, Const* value2); + +extern bool tupleLocateThePartition(Relation partTableRel, int partSeq, TupleDesc tupleDesc, void* tuple); + +extern bool partitionHasToast(Oid partOid); + +extern void constCompare(Const* value1, Const* value2, int& compare); + +#endif /* PARTITIONMAP_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_crc.h postgresql-hll-2.14/include/utils/pg_crc.h --- postgresql-hll-2.14_old/include/utils/pg_crc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_crc.h 2020-12-12 17:06:43.401350025 +0800 @@ -0,0 +1,164 @@ +/* + * pg_crc.h + * + * PostgreSQL CRC support + * + * See Ross Williams' excellent introduction + * A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from + * http://www.ross.net/crc/ or several other net sites. + * + * We use a normal (not "reflected", in Williams' terms) CRC, using initial + * all-ones register contents and a final bit inversion. + * + * The 64-bit variant is not used as of PostgreSQL 8.1, but we retain the + * code for possible future use. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_crc.h + */ +#ifndef PG_CRC_H +#define PG_CRC_H + +/* ugly hack to let this be used in frontend and backend code on Cygwin */ +#ifdef FRONTEND +#define CRCDLLIMPORT +#else +#define CRCDLLIMPORT PGDLLIMPORT +#endif + +typedef uint32 pg_crc32; + +/* + * The CRC algorithm used for WAL et al in pre-9.5 versions. + * + * This closely resembles the normal CRC-32 algorithm, but is subtly + * different. Using Williams' terms, we use the "normal" table, but with + * "reflected" code. That's bogus, but it was like that for years before + * anyone noticed. It does not correspond to any polynomial in a normal CRC + * algorithm, so it's not clear what the error-detection properties of this + * algorithm actually are. + * + * We still need to carry this around because it is used in a few on-disk + * structures that need to be pg_upgradeable. It should not be used in new + * code. + * + * Deprecated + * + * using CRC32C instead + */ + +/* Initialize a CRC accumulator */ +#define INIT_CRC32(crc) ((crc) = 0xFFFFFFFF) + +/* Finish a CRC calculation */ +#define FIN_CRC32(crc) ((crc) ^= 0xFFFFFFFF) + +/* Check for equality of two CRCs */ +#define EQ_CRC32(c1, c2) ((c1) == (c2)) + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC32(crc, data, len) \ + do { \ + const unsigned char* __data = (const unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)((crc) >> 24) ^ *__data++) & 0xFF; \ + (crc) = pg_crc32_table[__tab_index] ^ ((crc) << 8); \ + } \ + } while (0) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT uint32 pg_crc32_table[]; + +#ifdef PROVIDE_64BIT_CRC + +/* + * If we use a 64-bit integer type, then a 64-bit CRC looks just like the + * usual sort of implementation. However, we can also fake it with two + * 32-bit registers. Experience has shown that the two-32-bit-registers code + * is as fast as, or even much faster than, the 64-bit code on all but true + * 64-bit machines. We use SIZEOF_VOID_P to check the native word width. + */ + +#if SIZEOF_VOID_P < 8 + +/* + * crc0 represents the LSBs of the 64-bit value, crc1 the MSBs. Note that + * with crc0 placed first, the output of 32-bit and 64-bit implementations + * will be bit-compatible only on little-endian architectures. If it were + * important to make the two possible implementations bit-compatible on + * all machines, we could do a configure test to decide how to order the + * two fields, but it seems not worth the trouble. + */ +typedef struct pg_crc64 { + uint32 crc0; + uint32 crc1; +} pg_crc64; + +/* Initialize a CRC accumulator */ +#define INIT_CRC64(crc) ((crc).crc0 = 0xffffffff, (crc).crc1 = 0xffffffff) + +/* Finish a CRC calculation */ +#define FIN_CRC64(crc) ((crc).crc0 ^= 0xffffffff, (crc).crc1 ^= 0xffffffff) + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC64(crc, data, len) \ + do { \ + uint32 __crc0 = (crc).crc0; \ + uint32 __crc1 = (crc).crc1; \ + unsigned char* __data = (unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)(__crc1 >> 24) ^ *__data++) & 0xFF; \ + __crc1 = pg_crc64_table1[__tab_index] ^ ((__crc1 << 8) | (__crc0 >> 24)); \ + __crc0 = pg_crc64_table0[__tab_index] ^ (__crc0 << 8); \ + } \ + (crc).crc0 = __crc0; \ + (crc).crc1 = __crc1; \ + } while (0) + +/* Check for equality of two CRCs */ +#define EQ_CRC64(c1, c2) ((c1).crc0 == (c2).crc0 && (c1).crc1 == (c2).crc1) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT const uint32 pg_crc64_table0[]; +extern CRCDLLIMPORT const uint32 pg_crc64_table1[]; +#else /* use int64 implementation */ + +typedef struct pg_crc64 { + uint64 crc0; +} pg_crc64; + +/* Initialize a CRC accumulator */ +#define INIT_CRC64(crc) ((crc).crc0 = UINT64CONST(0xffffffffffffffff)) + +/* Finish a CRC calculation */ +#define FIN_CRC64(crc) ((crc).crc0 ^= UINT64CONST(0xffffffffffffffff)) + +/* Accumulate some (more) bytes into a CRC */ +#define COMP_CRC64(crc, data, len) \ + do { \ + uint64 __crc0 = (crc).crc0; \ + unsigned char* __data = (unsigned char*)(data); \ + uint32 __len = (len); \ + \ + while (__len-- > 0) { \ + int __tab_index = ((int)(__crc0 >> 56) ^ *__data++) & 0xFF; \ + __crc0 = pg_crc64_table[__tab_index] ^ (__crc0 << 8); \ + } \ + (crc).crc0 = __crc0; \ + } while (0) + +/* Check for equality of two CRCs */ +#define EQ_CRC64(c1, c2) ((c1).crc0 == (c2).crc0) + +/* Constant table for CRC calculation */ +extern CRCDLLIMPORT const uint64 pg_crc64_table[]; +#endif /* SIZEOF_VOID_P < 8 */ +#endif /* PROVIDE_64BIT_CRC */ +#endif /* PG_CRC_H */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_crc_tables.h postgresql-hll-2.14/include/utils/pg_crc_tables.h --- postgresql-hll-2.14_old/include/utils/pg_crc_tables.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_crc_tables.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,1083 @@ +/* ------------------------------------------------------------------------- + * + * pg_crc_tables.h + * Polynomial lookup tables for CRC macros + * + * We make these tables available as a .h file so that programs not linked + * with libpgport can still use the macros in pg_crc.h. They just need + * to #include this header as well. + * + * See Ross Williams' excellent introduction + * A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from + * http://www.ross.net/crc/download/crc_v3.txt or several other net sites. + * + * We use a normal (not "reflected", in Williams' terms) CRC, using initial + * all-ones register contents and a final bit inversion. + * + * The 64-bit variant is not used as of PostgreSQL 8.1, but we retain the + * code for possible future use. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_crc_tables.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_CRC_TABLES_H +#define PG_CRC_TABLES_H + +/* + * This table is based on the polynomial + * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. + * (This is the same polynomial used in Ethernet checksums, for instance.) + */ +uint32 pg_crc32_table[256] = {0x00000000, + 0x77073096, + 0xEE0E612C, + 0x990951BA, + 0x076DC419, + 0x706AF48F, + 0xE963A535, + 0x9E6495A3, + 0x0EDB8832, + 0x79DCB8A4, + 0xE0D5E91E, + 0x97D2D988, + 0x09B64C2B, + 0x7EB17CBD, + 0xE7B82D07, + 0x90BF1D91, + 0x1DB71064, + 0x6AB020F2, + 0xF3B97148, + 0x84BE41DE, + 0x1ADAD47D, + 0x6DDDE4EB, + 0xF4D4B551, + 0x83D385C7, + 0x136C9856, + 0x646BA8C0, + 0xFD62F97A, + 0x8A65C9EC, + 0x14015C4F, + 0x63066CD9, + 0xFA0F3D63, + 0x8D080DF5, + 0x3B6E20C8, + 0x4C69105E, + 0xD56041E4, + 0xA2677172, + 0x3C03E4D1, + 0x4B04D447, + 0xD20D85FD, + 0xA50AB56B, + 0x35B5A8FA, + 0x42B2986C, + 0xDBBBC9D6, + 0xACBCF940, + 0x32D86CE3, + 0x45DF5C75, + 0xDCD60DCF, + 0xABD13D59, + 0x26D930AC, + 0x51DE003A, + 0xC8D75180, + 0xBFD06116, + 0x21B4F4B5, + 0x56B3C423, + 0xCFBA9599, + 0xB8BDA50F, + 0x2802B89E, + 0x5F058808, + 0xC60CD9B2, + 0xB10BE924, + 0x2F6F7C87, + 0x58684C11, + 0xC1611DAB, + 0xB6662D3D, + 0x76DC4190, + 0x01DB7106, + 0x98D220BC, + 0xEFD5102A, + 0x71B18589, + 0x06B6B51F, + 0x9FBFE4A5, + 0xE8B8D433, + 0x7807C9A2, + 0x0F00F934, + 0x9609A88E, + 0xE10E9818, + 0x7F6A0DBB, + 0x086D3D2D, + 0x91646C97, + 0xE6635C01, + 0x6B6B51F4, + 0x1C6C6162, + 0x856530D8, + 0xF262004E, + 0x6C0695ED, + 0x1B01A57B, + 0x8208F4C1, + 0xF50FC457, + 0x65B0D9C6, + 0x12B7E950, + 0x8BBEB8EA, + 0xFCB9887C, + 0x62DD1DDF, + 0x15DA2D49, + 0x8CD37CF3, + 0xFBD44C65, + 0x4DB26158, + 0x3AB551CE, + 0xA3BC0074, + 0xD4BB30E2, + 0x4ADFA541, + 0x3DD895D7, + 0xA4D1C46D, + 0xD3D6F4FB, + 0x4369E96A, + 0x346ED9FC, + 0xAD678846, + 0xDA60B8D0, + 0x44042D73, + 0x33031DE5, + 0xAA0A4C5F, + 0xDD0D7CC9, + 0x5005713C, + 0x270241AA, + 0xBE0B1010, + 0xC90C2086, + 0x5768B525, + 0x206F85B3, + 0xB966D409, + 0xCE61E49F, + 0x5EDEF90E, + 0x29D9C998, + 0xB0D09822, + 0xC7D7A8B4, + 0x59B33D17, + 0x2EB40D81, + 0xB7BD5C3B, + 0xC0BA6CAD, + 0xEDB88320, + 0x9ABFB3B6, + 0x03B6E20C, + 0x74B1D29A, + 0xEAD54739, + 0x9DD277AF, + 0x04DB2615, + 0x73DC1683, + 0xE3630B12, + 0x94643B84, + 0x0D6D6A3E, + 0x7A6A5AA8, + 0xE40ECF0B, + 0x9309FF9D, + 0x0A00AE27, + 0x7D079EB1, + 0xF00F9344, + 0x8708A3D2, + 0x1E01F268, + 0x6906C2FE, + 0xF762575D, + 0x806567CB, + 0x196C3671, + 0x6E6B06E7, + 0xFED41B76, + 0x89D32BE0, + 0x10DA7A5A, + 0x67DD4ACC, + 0xF9B9DF6F, + 0x8EBEEFF9, + 0x17B7BE43, + 0x60B08ED5, + 0xD6D6A3E8, + 0xA1D1937E, + 0x38D8C2C4, + 0x4FDFF252, + 0xD1BB67F1, + 0xA6BC5767, + 0x3FB506DD, + 0x48B2364B, + 0xD80D2BDA, + 0xAF0A1B4C, + 0x36034AF6, + 0x41047A60, + 0xDF60EFC3, + 0xA867DF55, + 0x316E8EEF, + 0x4669BE79, + 0xCB61B38C, + 0xBC66831A, + 0x256FD2A0, + 0x5268E236, + 0xCC0C7795, + 0xBB0B4703, + 0x220216B9, + 0x5505262F, + 0xC5BA3BBE, + 0xB2BD0B28, + 0x2BB45A92, + 0x5CB36A04, + 0xC2D7FFA7, + 0xB5D0CF31, + 0x2CD99E8B, + 0x5BDEAE1D, + 0x9B64C2B0, + 0xEC63F226, + 0x756AA39C, + 0x026D930A, + 0x9C0906A9, + 0xEB0E363F, + 0x72076785, + 0x05005713, + 0x95BF4A82, + 0xE2B87A14, + 0x7BB12BAE, + 0x0CB61B38, + 0x92D28E9B, + 0xE5D5BE0D, + 0x7CDCEFB7, + 0x0BDBDF21, + 0x86D3D2D4, + 0xF1D4E242, + 0x68DDB3F8, + 0x1FDA836E, + 0x81BE16CD, + 0xF6B9265B, + 0x6FB077E1, + 0x18B74777, + 0x88085AE6, + 0xFF0F6A70, + 0x66063BCA, + 0x11010B5C, + 0x8F659EFF, + 0xF862AE69, + 0x616BFFD3, + 0x166CCF45, + 0xA00AE278, + 0xD70DD2EE, + 0x4E048354, + 0x3903B3C2, + 0xA7672661, + 0xD06016F7, + 0x4969474D, + 0x3E6E77DB, + 0xAED16A4A, + 0xD9D65ADC, + 0x40DF0B66, + 0x37D83BF0, + 0xA9BCAE53, + 0xDEBB9EC5, + 0x47B2CF7F, + 0x30B5FFE9, + 0xBDBDF21C, + 0xCABAC28A, + 0x53B39330, + 0x24B4A3A6, + 0xBAD03605, + 0xCDD70693, + 0x54DE5729, + 0x23D967BF, + 0xB3667A2E, + 0xC4614AB8, + 0x5D681B02, + 0x2A6F2B94, + 0xB40BBE37, + 0xC30C8EA1, + 0x5A05DF1B, + 0x2D02EF8D}; + +#ifdef PROVIDE_64BIT_CRC + +/* + * This table is based on the polynomial + * + * x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 + + * x^40 + x^39 + x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 + + * x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 + + * x^7 + x^4 + x + 1 + * + * which is borrowed from the DLT1 spec + * (ECMA-182, available from http://www.ecma.ch/ecma1/STAND/ECMA-182.HTM) + */ + +#if SIZEOF_VOID_P < 8 /* this test must match the one in pg_crc.h */ + +const uint32 pg_crc64_table0[256] = {0x00000000, + 0xA9EA3693, + 0x53D46D26, + 0xFA3E5BB5, + 0x0E42ECDF, + 0xA7A8DA4C, + 0x5D9681F9, + 0xF47CB76A, + 0x1C85D9BE, + 0xB56FEF2D, + 0x4F51B498, + 0xE6BB820B, + 0x12C73561, + 0xBB2D03F2, + 0x41135847, + 0xE8F96ED4, + 0x90E185EF, + 0x390BB37C, + 0xC335E8C9, + 0x6ADFDE5A, + 0x9EA36930, + 0x37495FA3, + 0xCD770416, + 0x649D3285, + 0x8C645C51, + 0x258E6AC2, + 0xDFB03177, + 0x765A07E4, + 0x8226B08E, + 0x2BCC861D, + 0xD1F2DDA8, + 0x7818EB3B, + 0x21C30BDE, + 0x88293D4D, + 0x721766F8, + 0xDBFD506B, + 0x2F81E701, + 0x866BD192, + 0x7C558A27, + 0xD5BFBCB4, + 0x3D46D260, + 0x94ACE4F3, + 0x6E92BF46, + 0xC77889D5, + 0x33043EBF, + 0x9AEE082C, + 0x60D05399, + 0xC93A650A, + 0xB1228E31, + 0x18C8B8A2, + 0xE2F6E317, + 0x4B1CD584, + 0xBF6062EE, + 0x168A547D, + 0xECB40FC8, + 0x455E395B, + 0xADA7578F, + 0x044D611C, + 0xFE733AA9, + 0x57990C3A, + 0xA3E5BB50, + 0x0A0F8DC3, + 0xF031D676, + 0x59DBE0E5, + 0xEA6C212F, + 0x438617BC, + 0xB9B84C09, + 0x10527A9A, + 0xE42ECDF0, + 0x4DC4FB63, + 0xB7FAA0D6, + 0x1E109645, + 0xF6E9F891, + 0x5F03CE02, + 0xA53D95B7, + 0x0CD7A324, + 0xF8AB144E, + 0x514122DD, + 0xAB7F7968, + 0x02954FFB, + 0x7A8DA4C0, + 0xD3679253, + 0x2959C9E6, + 0x80B3FF75, + 0x74CF481F, + 0xDD257E8C, + 0x271B2539, + 0x8EF113AA, + 0x66087D7E, + 0xCFE24BED, + 0x35DC1058, + 0x9C3626CB, + 0x684A91A1, + 0xC1A0A732, + 0x3B9EFC87, + 0x9274CA14, + 0xCBAF2AF1, + 0x62451C62, + 0x987B47D7, + 0x31917144, + 0xC5EDC62E, + 0x6C07F0BD, + 0x9639AB08, + 0x3FD39D9B, + 0xD72AF34F, + 0x7EC0C5DC, + 0x84FE9E69, + 0x2D14A8FA, + 0xD9681F90, + 0x70822903, + 0x8ABC72B6, + 0x23564425, + 0x5B4EAF1E, + 0xF2A4998D, + 0x089AC238, + 0xA170F4AB, + 0x550C43C1, + 0xFCE67552, + 0x06D82EE7, + 0xAF321874, + 0x47CB76A0, + 0xEE214033, + 0x141F1B86, + 0xBDF52D15, + 0x49899A7F, + 0xE063ACEC, + 0x1A5DF759, + 0xB3B7C1CA, + 0x7D3274CD, + 0xD4D8425E, + 0x2EE619EB, + 0x870C2F78, + 0x73709812, + 0xDA9AAE81, + 0x20A4F534, + 0x894EC3A7, + 0x61B7AD73, + 0xC85D9BE0, + 0x3263C055, + 0x9B89F6C6, + 0x6FF541AC, + 0xC61F773F, + 0x3C212C8A, + 0x95CB1A19, + 0xEDD3F122, + 0x4439C7B1, + 0xBE079C04, + 0x17EDAA97, + 0xE3911DFD, + 0x4A7B2B6E, + 0xB04570DB, + 0x19AF4648, + 0xF156289C, + 0x58BC1E0F, + 0xA28245BA, + 0x0B687329, + 0xFF14C443, + 0x56FEF2D0, + 0xACC0A965, + 0x052A9FF6, + 0x5CF17F13, + 0xF51B4980, + 0x0F251235, + 0xA6CF24A6, + 0x52B393CC, + 0xFB59A55F, + 0x0167FEEA, + 0xA88DC879, + 0x4074A6AD, + 0xE99E903E, + 0x13A0CB8B, + 0xBA4AFD18, + 0x4E364A72, + 0xE7DC7CE1, + 0x1DE22754, + 0xB40811C7, + 0xCC10FAFC, + 0x65FACC6F, + 0x9FC497DA, + 0x362EA149, + 0xC2521623, + 0x6BB820B0, + 0x91867B05, + 0x386C4D96, + 0xD0952342, + 0x797F15D1, + 0x83414E64, + 0x2AAB78F7, + 0xDED7CF9D, + 0x773DF90E, + 0x8D03A2BB, + 0x24E99428, + 0x975E55E2, + 0x3EB46371, + 0xC48A38C4, + 0x6D600E57, + 0x991CB93D, + 0x30F68FAE, + 0xCAC8D41B, + 0x6322E288, + 0x8BDB8C5C, + 0x2231BACF, + 0xD80FE17A, + 0x71E5D7E9, + 0x85996083, + 0x2C735610, + 0xD64D0DA5, + 0x7FA73B36, + 0x07BFD00D, + 0xAE55E69E, + 0x546BBD2B, + 0xFD818BB8, + 0x09FD3CD2, + 0xA0170A41, + 0x5A2951F4, + 0xF3C36767, + 0x1B3A09B3, + 0xB2D03F20, + 0x48EE6495, + 0xE1045206, + 0x1578E56C, + 0xBC92D3FF, + 0x46AC884A, + 0xEF46BED9, + 0xB69D5E3C, + 0x1F7768AF, + 0xE549331A, + 0x4CA30589, + 0xB8DFB2E3, + 0x11358470, + 0xEB0BDFC5, + 0x42E1E956, + 0xAA188782, + 0x03F2B111, + 0xF9CCEAA4, + 0x5026DC37, + 0xA45A6B5D, + 0x0DB05DCE, + 0xF78E067B, + 0x5E6430E8, + 0x267CDBD3, + 0x8F96ED40, + 0x75A8B6F5, + 0xDC428066, + 0x283E370C, + 0x81D4019F, + 0x7BEA5A2A, + 0xD2006CB9, + 0x3AF9026D, + 0x931334FE, + 0x692D6F4B, + 0xC0C759D8, + 0x34BBEEB2, + 0x9D51D821, + 0x676F8394, + 0xCE85B507}; + +const uint32 pg_crc64_table1[256] = {0x00000000, + 0x42F0E1EB, + 0x85E1C3D7, + 0xC711223C, + 0x49336645, + 0x0BC387AE, + 0xCCD2A592, + 0x8E224479, + 0x9266CC8A, + 0xD0962D61, + 0x17870F5D, + 0x5577EEB6, + 0xDB55AACF, + 0x99A54B24, + 0x5EB46918, + 0x1C4488F3, + 0x663D78FF, + 0x24CD9914, + 0xE3DCBB28, + 0xA12C5AC3, + 0x2F0E1EBA, + 0x6DFEFF51, + 0xAAEFDD6D, + 0xE81F3C86, + 0xF45BB475, + 0xB6AB559E, + 0x71BA77A2, + 0x334A9649, + 0xBD68D230, + 0xFF9833DB, + 0x388911E7, + 0x7A79F00C, + 0xCC7AF1FF, + 0x8E8A1014, + 0x499B3228, + 0x0B6BD3C3, + 0x854997BA, + 0xC7B97651, + 0x00A8546D, + 0x4258B586, + 0x5E1C3D75, + 0x1CECDC9E, + 0xDBFDFEA2, + 0x990D1F49, + 0x172F5B30, + 0x55DFBADB, + 0x92CE98E7, + 0xD03E790C, + 0xAA478900, + 0xE8B768EB, + 0x2FA64AD7, + 0x6D56AB3C, + 0xE374EF45, + 0xA1840EAE, + 0x66952C92, + 0x2465CD79, + 0x3821458A, + 0x7AD1A461, + 0xBDC0865D, + 0xFF3067B6, + 0x711223CF, + 0x33E2C224, + 0xF4F3E018, + 0xB60301F3, + 0xDA050215, + 0x98F5E3FE, + 0x5FE4C1C2, + 0x1D142029, + 0x93366450, + 0xD1C685BB, + 0x16D7A787, + 0x5427466C, + 0x4863CE9F, + 0x0A932F74, + 0xCD820D48, + 0x8F72ECA3, + 0x0150A8DA, + 0x43A04931, + 0x84B16B0D, + 0xC6418AE6, + 0xBC387AEA, + 0xFEC89B01, + 0x39D9B93D, + 0x7B2958D6, + 0xF50B1CAF, + 0xB7FBFD44, + 0x70EADF78, + 0x321A3E93, + 0x2E5EB660, + 0x6CAE578B, + 0xABBF75B7, + 0xE94F945C, + 0x676DD025, + 0x259D31CE, + 0xE28C13F2, + 0xA07CF219, + 0x167FF3EA, + 0x548F1201, + 0x939E303D, + 0xD16ED1D6, + 0x5F4C95AF, + 0x1DBC7444, + 0xDAAD5678, + 0x985DB793, + 0x84193F60, + 0xC6E9DE8B, + 0x01F8FCB7, + 0x43081D5C, + 0xCD2A5925, + 0x8FDAB8CE, + 0x48CB9AF2, + 0x0A3B7B19, + 0x70428B15, + 0x32B26AFE, + 0xF5A348C2, + 0xB753A929, + 0x3971ED50, + 0x7B810CBB, + 0xBC902E87, + 0xFE60CF6C, + 0xE224479F, + 0xA0D4A674, + 0x67C58448, + 0x253565A3, + 0xAB1721DA, + 0xE9E7C031, + 0x2EF6E20D, + 0x6C0603E6, + 0xF6FAE5C0, + 0xB40A042B, + 0x731B2617, + 0x31EBC7FC, + 0xBFC98385, + 0xFD39626E, + 0x3A284052, + 0x78D8A1B9, + 0x649C294A, + 0x266CC8A1, + 0xE17DEA9D, + 0xA38D0B76, + 0x2DAF4F0F, + 0x6F5FAEE4, + 0xA84E8CD8, + 0xEABE6D33, + 0x90C79D3F, + 0xD2377CD4, + 0x15265EE8, + 0x57D6BF03, + 0xD9F4FB7A, + 0x9B041A91, + 0x5C1538AD, + 0x1EE5D946, + 0x02A151B5, + 0x4051B05E, + 0x87409262, + 0xC5B07389, + 0x4B9237F0, + 0x0962D61B, + 0xCE73F427, + 0x8C8315CC, + 0x3A80143F, + 0x7870F5D4, + 0xBF61D7E8, + 0xFD913603, + 0x73B3727A, + 0x31439391, + 0xF652B1AD, + 0xB4A25046, + 0xA8E6D8B5, + 0xEA16395E, + 0x2D071B62, + 0x6FF7FA89, + 0xE1D5BEF0, + 0xA3255F1B, + 0x64347D27, + 0x26C49CCC, + 0x5CBD6CC0, + 0x1E4D8D2B, + 0xD95CAF17, + 0x9BAC4EFC, + 0x158E0A85, + 0x577EEB6E, + 0x906FC952, + 0xD29F28B9, + 0xCEDBA04A, + 0x8C2B41A1, + 0x4B3A639D, + 0x09CA8276, + 0x87E8C60F, + 0xC51827E4, + 0x020905D8, + 0x40F9E433, + 0x2CFFE7D5, + 0x6E0F063E, + 0xA91E2402, + 0xEBEEC5E9, + 0x65CC8190, + 0x273C607B, + 0xE02D4247, + 0xA2DDA3AC, + 0xBE992B5F, + 0xFC69CAB4, + 0x3B78E888, + 0x79880963, + 0xF7AA4D1A, + 0xB55AACF1, + 0x724B8ECD, + 0x30BB6F26, + 0x4AC29F2A, + 0x08327EC1, + 0xCF235CFD, + 0x8DD3BD16, + 0x03F1F96F, + 0x41011884, + 0x86103AB8, + 0xC4E0DB53, + 0xD8A453A0, + 0x9A54B24B, + 0x5D459077, + 0x1FB5719C, + 0x919735E5, + 0xD367D40E, + 0x1476F632, + 0x568617D9, + 0xE085162A, + 0xA275F7C1, + 0x6564D5FD, + 0x27943416, + 0xA9B6706F, + 0xEB469184, + 0x2C57B3B8, + 0x6EA75253, + 0x72E3DAA0, + 0x30133B4B, + 0xF7021977, + 0xB5F2F89C, + 0x3BD0BCE5, + 0x79205D0E, + 0xBE317F32, + 0xFCC19ED9, + 0x86B86ED5, + 0xC4488F3E, + 0x0359AD02, + 0x41A94CE9, + 0xCF8B0890, + 0x8D7BE97B, + 0x4A6ACB47, + 0x089A2AAC, + 0x14DEA25F, + 0x562E43B4, + 0x913F6188, + 0xD3CF8063, + 0x5DEDC41A, + 0x1F1D25F1, + 0xD80C07CD, + 0x9AFCE626}; +#else /* use int64 implementation */ + +const uint64 pg_crc64_table[256] = {UINT64CONST(0x0000000000000000), + UINT64CONST(0x42F0E1EBA9EA3693), + UINT64CONST(0x85E1C3D753D46D26), + UINT64CONST(0xC711223CFA3E5BB5), + UINT64CONST(0x493366450E42ECDF), + UINT64CONST(0x0BC387AEA7A8DA4C), + UINT64CONST(0xCCD2A5925D9681F9), + UINT64CONST(0x8E224479F47CB76A), + UINT64CONST(0x9266CC8A1C85D9BE), + UINT64CONST(0xD0962D61B56FEF2D), + UINT64CONST(0x17870F5D4F51B498), + UINT64CONST(0x5577EEB6E6BB820B), + UINT64CONST(0xDB55AACF12C73561), + UINT64CONST(0x99A54B24BB2D03F2), + UINT64CONST(0x5EB4691841135847), + UINT64CONST(0x1C4488F3E8F96ED4), + UINT64CONST(0x663D78FF90E185EF), + UINT64CONST(0x24CD9914390BB37C), + UINT64CONST(0xE3DCBB28C335E8C9), + UINT64CONST(0xA12C5AC36ADFDE5A), + UINT64CONST(0x2F0E1EBA9EA36930), + UINT64CONST(0x6DFEFF5137495FA3), + UINT64CONST(0xAAEFDD6DCD770416), + UINT64CONST(0xE81F3C86649D3285), + UINT64CONST(0xF45BB4758C645C51), + UINT64CONST(0xB6AB559E258E6AC2), + UINT64CONST(0x71BA77A2DFB03177), + UINT64CONST(0x334A9649765A07E4), + UINT64CONST(0xBD68D2308226B08E), + UINT64CONST(0xFF9833DB2BCC861D), + UINT64CONST(0x388911E7D1F2DDA8), + UINT64CONST(0x7A79F00C7818EB3B), + UINT64CONST(0xCC7AF1FF21C30BDE), + UINT64CONST(0x8E8A101488293D4D), + UINT64CONST(0x499B3228721766F8), + UINT64CONST(0x0B6BD3C3DBFD506B), + UINT64CONST(0x854997BA2F81E701), + UINT64CONST(0xC7B97651866BD192), + UINT64CONST(0x00A8546D7C558A27), + UINT64CONST(0x4258B586D5BFBCB4), + UINT64CONST(0x5E1C3D753D46D260), + UINT64CONST(0x1CECDC9E94ACE4F3), + UINT64CONST(0xDBFDFEA26E92BF46), + UINT64CONST(0x990D1F49C77889D5), + UINT64CONST(0x172F5B3033043EBF), + UINT64CONST(0x55DFBADB9AEE082C), + UINT64CONST(0x92CE98E760D05399), + UINT64CONST(0xD03E790CC93A650A), + UINT64CONST(0xAA478900B1228E31), + UINT64CONST(0xE8B768EB18C8B8A2), + UINT64CONST(0x2FA64AD7E2F6E317), + UINT64CONST(0x6D56AB3C4B1CD584), + UINT64CONST(0xE374EF45BF6062EE), + UINT64CONST(0xA1840EAE168A547D), + UINT64CONST(0x66952C92ECB40FC8), + UINT64CONST(0x2465CD79455E395B), + UINT64CONST(0x3821458AADA7578F), + UINT64CONST(0x7AD1A461044D611C), + UINT64CONST(0xBDC0865DFE733AA9), + UINT64CONST(0xFF3067B657990C3A), + UINT64CONST(0x711223CFA3E5BB50), + UINT64CONST(0x33E2C2240A0F8DC3), + UINT64CONST(0xF4F3E018F031D676), + UINT64CONST(0xB60301F359DBE0E5), + UINT64CONST(0xDA050215EA6C212F), + UINT64CONST(0x98F5E3FE438617BC), + UINT64CONST(0x5FE4C1C2B9B84C09), + UINT64CONST(0x1D14202910527A9A), + UINT64CONST(0x93366450E42ECDF0), + UINT64CONST(0xD1C685BB4DC4FB63), + UINT64CONST(0x16D7A787B7FAA0D6), + UINT64CONST(0x5427466C1E109645), + UINT64CONST(0x4863CE9FF6E9F891), + UINT64CONST(0x0A932F745F03CE02), + UINT64CONST(0xCD820D48A53D95B7), + UINT64CONST(0x8F72ECA30CD7A324), + UINT64CONST(0x0150A8DAF8AB144E), + UINT64CONST(0x43A04931514122DD), + UINT64CONST(0x84B16B0DAB7F7968), + UINT64CONST(0xC6418AE602954FFB), + UINT64CONST(0xBC387AEA7A8DA4C0), + UINT64CONST(0xFEC89B01D3679253), + UINT64CONST(0x39D9B93D2959C9E6), + UINT64CONST(0x7B2958D680B3FF75), + UINT64CONST(0xF50B1CAF74CF481F), + UINT64CONST(0xB7FBFD44DD257E8C), + UINT64CONST(0x70EADF78271B2539), + UINT64CONST(0x321A3E938EF113AA), + UINT64CONST(0x2E5EB66066087D7E), + UINT64CONST(0x6CAE578BCFE24BED), + UINT64CONST(0xABBF75B735DC1058), + UINT64CONST(0xE94F945C9C3626CB), + UINT64CONST(0x676DD025684A91A1), + UINT64CONST(0x259D31CEC1A0A732), + UINT64CONST(0xE28C13F23B9EFC87), + UINT64CONST(0xA07CF2199274CA14), + UINT64CONST(0x167FF3EACBAF2AF1), + UINT64CONST(0x548F120162451C62), + UINT64CONST(0x939E303D987B47D7), + UINT64CONST(0xD16ED1D631917144), + UINT64CONST(0x5F4C95AFC5EDC62E), + UINT64CONST(0x1DBC74446C07F0BD), + UINT64CONST(0xDAAD56789639AB08), + UINT64CONST(0x985DB7933FD39D9B), + UINT64CONST(0x84193F60D72AF34F), + UINT64CONST(0xC6E9DE8B7EC0C5DC), + UINT64CONST(0x01F8FCB784FE9E69), + UINT64CONST(0x43081D5C2D14A8FA), + UINT64CONST(0xCD2A5925D9681F90), + UINT64CONST(0x8FDAB8CE70822903), + UINT64CONST(0x48CB9AF28ABC72B6), + UINT64CONST(0x0A3B7B1923564425), + UINT64CONST(0x70428B155B4EAF1E), + UINT64CONST(0x32B26AFEF2A4998D), + UINT64CONST(0xF5A348C2089AC238), + UINT64CONST(0xB753A929A170F4AB), + UINT64CONST(0x3971ED50550C43C1), + UINT64CONST(0x7B810CBBFCE67552), + UINT64CONST(0xBC902E8706D82EE7), + UINT64CONST(0xFE60CF6CAF321874), + UINT64CONST(0xE224479F47CB76A0), + UINT64CONST(0xA0D4A674EE214033), + UINT64CONST(0x67C58448141F1B86), + UINT64CONST(0x253565A3BDF52D15), + UINT64CONST(0xAB1721DA49899A7F), + UINT64CONST(0xE9E7C031E063ACEC), + UINT64CONST(0x2EF6E20D1A5DF759), + UINT64CONST(0x6C0603E6B3B7C1CA), + UINT64CONST(0xF6FAE5C07D3274CD), + UINT64CONST(0xB40A042BD4D8425E), + UINT64CONST(0x731B26172EE619EB), + UINT64CONST(0x31EBC7FC870C2F78), + UINT64CONST(0xBFC9838573709812), + UINT64CONST(0xFD39626EDA9AAE81), + UINT64CONST(0x3A28405220A4F534), + UINT64CONST(0x78D8A1B9894EC3A7), + UINT64CONST(0x649C294A61B7AD73), + UINT64CONST(0x266CC8A1C85D9BE0), + UINT64CONST(0xE17DEA9D3263C055), + UINT64CONST(0xA38D0B769B89F6C6), + UINT64CONST(0x2DAF4F0F6FF541AC), + UINT64CONST(0x6F5FAEE4C61F773F), + UINT64CONST(0xA84E8CD83C212C8A), + UINT64CONST(0xEABE6D3395CB1A19), + UINT64CONST(0x90C79D3FEDD3F122), + UINT64CONST(0xD2377CD44439C7B1), + UINT64CONST(0x15265EE8BE079C04), + UINT64CONST(0x57D6BF0317EDAA97), + UINT64CONST(0xD9F4FB7AE3911DFD), + UINT64CONST(0x9B041A914A7B2B6E), + UINT64CONST(0x5C1538ADB04570DB), + UINT64CONST(0x1EE5D94619AF4648), + UINT64CONST(0x02A151B5F156289C), + UINT64CONST(0x4051B05E58BC1E0F), + UINT64CONST(0x87409262A28245BA), + UINT64CONST(0xC5B073890B687329), + UINT64CONST(0x4B9237F0FF14C443), + UINT64CONST(0x0962D61B56FEF2D0), + UINT64CONST(0xCE73F427ACC0A965), + UINT64CONST(0x8C8315CC052A9FF6), + UINT64CONST(0x3A80143F5CF17F13), + UINT64CONST(0x7870F5D4F51B4980), + UINT64CONST(0xBF61D7E80F251235), + UINT64CONST(0xFD913603A6CF24A6), + UINT64CONST(0x73B3727A52B393CC), + UINT64CONST(0x31439391FB59A55F), + UINT64CONST(0xF652B1AD0167FEEA), + UINT64CONST(0xB4A25046A88DC879), + UINT64CONST(0xA8E6D8B54074A6AD), + UINT64CONST(0xEA16395EE99E903E), + UINT64CONST(0x2D071B6213A0CB8B), + UINT64CONST(0x6FF7FA89BA4AFD18), + UINT64CONST(0xE1D5BEF04E364A72), + UINT64CONST(0xA3255F1BE7DC7CE1), + UINT64CONST(0x64347D271DE22754), + UINT64CONST(0x26C49CCCB40811C7), + UINT64CONST(0x5CBD6CC0CC10FAFC), + UINT64CONST(0x1E4D8D2B65FACC6F), + UINT64CONST(0xD95CAF179FC497DA), + UINT64CONST(0x9BAC4EFC362EA149), + UINT64CONST(0x158E0A85C2521623), + UINT64CONST(0x577EEB6E6BB820B0), + UINT64CONST(0x906FC95291867B05), + UINT64CONST(0xD29F28B9386C4D96), + UINT64CONST(0xCEDBA04AD0952342), + UINT64CONST(0x8C2B41A1797F15D1), + UINT64CONST(0x4B3A639D83414E64), + UINT64CONST(0x09CA82762AAB78F7), + UINT64CONST(0x87E8C60FDED7CF9D), + UINT64CONST(0xC51827E4773DF90E), + UINT64CONST(0x020905D88D03A2BB), + UINT64CONST(0x40F9E43324E99428), + UINT64CONST(0x2CFFE7D5975E55E2), + UINT64CONST(0x6E0F063E3EB46371), + UINT64CONST(0xA91E2402C48A38C4), + UINT64CONST(0xEBEEC5E96D600E57), + UINT64CONST(0x65CC8190991CB93D), + UINT64CONST(0x273C607B30F68FAE), + UINT64CONST(0xE02D4247CAC8D41B), + UINT64CONST(0xA2DDA3AC6322E288), + UINT64CONST(0xBE992B5F8BDB8C5C), + UINT64CONST(0xFC69CAB42231BACF), + UINT64CONST(0x3B78E888D80FE17A), + UINT64CONST(0x7988096371E5D7E9), + UINT64CONST(0xF7AA4D1A85996083), + UINT64CONST(0xB55AACF12C735610), + UINT64CONST(0x724B8ECDD64D0DA5), + UINT64CONST(0x30BB6F267FA73B36), + UINT64CONST(0x4AC29F2A07BFD00D), + UINT64CONST(0x08327EC1AE55E69E), + UINT64CONST(0xCF235CFD546BBD2B), + UINT64CONST(0x8DD3BD16FD818BB8), + UINT64CONST(0x03F1F96F09FD3CD2), + UINT64CONST(0x41011884A0170A41), + UINT64CONST(0x86103AB85A2951F4), + UINT64CONST(0xC4E0DB53F3C36767), + UINT64CONST(0xD8A453A01B3A09B3), + UINT64CONST(0x9A54B24BB2D03F20), + UINT64CONST(0x5D45907748EE6495), + UINT64CONST(0x1FB5719CE1045206), + UINT64CONST(0x919735E51578E56C), + UINT64CONST(0xD367D40EBC92D3FF), + UINT64CONST(0x1476F63246AC884A), + UINT64CONST(0x568617D9EF46BED9), + UINT64CONST(0xE085162AB69D5E3C), + UINT64CONST(0xA275F7C11F7768AF), + UINT64CONST(0x6564D5FDE549331A), + UINT64CONST(0x279434164CA30589), + UINT64CONST(0xA9B6706FB8DFB2E3), + UINT64CONST(0xEB46918411358470), + UINT64CONST(0x2C57B3B8EB0BDFC5), + UINT64CONST(0x6EA7525342E1E956), + UINT64CONST(0x72E3DAA0AA188782), + UINT64CONST(0x30133B4B03F2B111), + UINT64CONST(0xF7021977F9CCEAA4), + UINT64CONST(0xB5F2F89C5026DC37), + UINT64CONST(0x3BD0BCE5A45A6B5D), + UINT64CONST(0x79205D0E0DB05DCE), + UINT64CONST(0xBE317F32F78E067B), + UINT64CONST(0xFCC19ED95E6430E8), + UINT64CONST(0x86B86ED5267CDBD3), + UINT64CONST(0xC4488F3E8F96ED40), + UINT64CONST(0x0359AD0275A8B6F5), + UINT64CONST(0x41A94CE9DC428066), + UINT64CONST(0xCF8B0890283E370C), + UINT64CONST(0x8D7BE97B81D4019F), + UINT64CONST(0x4A6ACB477BEA5A2A), + UINT64CONST(0x089A2AACD2006CB9), + UINT64CONST(0x14DEA25F3AF9026D), + UINT64CONST(0x562E43B4931334FE), + UINT64CONST(0x913F6188692D6F4B), + UINT64CONST(0xD3CF8063C0C759D8), + UINT64CONST(0x5DEDC41A34BBEEB2), + UINT64CONST(0x1F1D25F19D51D821), + UINT64CONST(0xD80C07CD676F8394), + UINT64CONST(0x9AFCE626CE85B507)}; +#endif /* SIZEOF_VOID_P < 8 */ +#endif /* PROVIDE_64BIT_CRC */ + +#endif /* PG_CRC_TABLES_H */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_locale.h postgresql-hll-2.14/include/utils/pg_locale.h --- postgresql-hll-2.14_old/include/utils/pg_locale.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_locale.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,78 @@ +/* ----------------------------------------------------------------------- + * + * PostgreSQL locale utilities + * + * src/include/utils/pg_locale.h + * + * Copyright (c) 2002-2012, PostgreSQL Global Development Group + * + * ----------------------------------------------------------------------- + */ + +#ifndef _PG_LOCALE_ +#define _PG_LOCALE_ + +#include +#ifdef LOCALE_T_IN_XLOCALE +#include +#endif + +#include "utils/guc.h" + +extern bool check_locale_messages(char** newval, void** extra, GucSource source); +extern void assign_locale_messages(const char* newval, void* extra); +extern bool check_locale_monetary(char** newval, void** extra, GucSource source); +extern void assign_locale_monetary(const char* newval, void* extra); +extern bool check_locale_numeric(char** newval, void** extra, GucSource source); +extern void assign_locale_numeric(const char* newval, void* extra); +extern bool check_locale_time(char** newval, void** extra, GucSource source); +extern void assign_locale_time(const char* newval, void* extra); + +extern bool check_locale(int category, const char* locale, char** canonname); +extern char* pg_perm_setlocale(int category, const char* locale); + +extern bool lc_collate_is_c(Oid collation); +extern bool lc_ctype_is_c(Oid collation); + +/* + * Return the POSIX lconv struct (contains number/money formatting + * information) with locale information for all categories. + */ +extern struct lconv* PGLC_localeconv(void); + +/* + * Free memory pointed by internal members of u_sess->lc_cxt.cur_lc_conv. These memory + * are allocated by strdup in PGLC_localeconv. + * + * NOT free the memory pointed by u_sess->lc_cxt.cur_lc_conv itself. So we did not set + * u_sess->lc_cxt.cur_lc_conv to NULL. u_sess->lc_cxt.cur_lc_conv is allocated by + * palloc0 in knl_u_locale_init. + */ +extern void localeconv_deinitialize_session(void); + +extern void cache_locale_time(void); + +void freeLocaleCacheAtThreadExit(void); + +/* + * We define our own wrapper around locale_t so we can keep the same + * function signatures for all builds, while not having to create a + * fake version of the standard type locale_t in the global namespace. + * The fake version of pg_locale_t can be checked for truth; that's + * about all it will be needed for. + */ +#ifdef HAVE_LOCALE_T +typedef locale_t pg_locale_t; +#else +typedef int pg_locale_t; +#endif + +extern pg_locale_t pg_newlocale_from_collation(Oid collid); + +/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ +#ifdef USE_WIDE_UPPER_LOWER +extern size_t wchar2char(char* to, const wchar_t* from, size_t tolen, pg_locale_t locale); +extern size_t char2wchar(wchar_t* to, size_t tolen, const char* from, size_t fromlen, pg_locale_t locale); +#endif + +#endif /* _PG_LOCALE_ */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_lsn.h postgresql-hll-2.14/include/utils/pg_lsn.h --- postgresql-hll-2.14_old/include/utils/pg_lsn.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_lsn.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,28 @@ +/* --------------------------------------------------------------------------------------- + * + * pg_lsn.h + * Declarations for operations on log sequence numbers (LSNs) of + * PostgreSQL. + * + * Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd. + * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/pg_lsn.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef PG_LSN_H +#define PG_LSN_H + +#include "fmgr.h" +#include "access/xlogdefs.h" + +#define DatumGetLSN(X) ((XLogRecPtr)DatumGetInt64(X)) +#define LSNGetDatum(X) (Int64GetDatum((int64)(X))) + +#define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n)) +#define PG_RETURN_LSN(x) return LSNGetDatum(x) + +#endif /* PG_LSN_H */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_lzcompress.h postgresql-hll-2.14/include/utils/pg_lzcompress.h --- postgresql-hll-2.14_old/include/utils/pg_lzcompress.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_lzcompress.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,130 @@ +/* ---------- + * pg_lzcompress.h - + * + * Definitions for the builtin LZ compressor + * + * src/include/utils/pg_lzcompress.h + * ---------- + */ + +#ifndef _PG_LZCOMPRESS_H_ +#define _PG_LZCOMPRESS_H_ + +/* ---------- + * PGLZ_Header - + * + * The information at the start of the compressed data. + * ---------- + */ +typedef struct PGLZ_Header { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 rawsize; +} PGLZ_Header; + +/* ---------- + * PGLZ_MAX_OUTPUT - + * + * Macro to compute the buffer size required by pglz_compress(). + * We allow 4 bytes for overrun before detecting compression failure. + * ---------- + */ +#define PGLZ_MAX_OUTPUT(_dlen) ((_dlen) + 4 + sizeof(PGLZ_Header)) + +/* ---------- + * PGLZ_RAW_SIZE - + * + * Macro to determine the uncompressed data size contained + * in the entry. + * ---------- + */ +#define PGLZ_RAW_SIZE(_lzdata) ((_lzdata)->rawsize) + +/* ---------- + * PGLZ_Strategy - + * + * Some values that control the compression algorithm. + * + * min_input_size Minimum input data size to consider compression. + * + * max_input_size Maximum input data size to consider compression. + * + * min_comp_rate Minimum compression rate (0-99%) to require. + * Regardless of min_comp_rate, the output must be + * smaller than the input, else we don't store + * compressed. + * + * first_success_by Abandon compression if we find no compressible + * data within the first this-many bytes. + * + * match_size_good The initial GOOD match size when starting history + * lookup. When looking up the history to find a + * match that could be expressed as a tag, the + * algorithm does not always walk back entirely. + * A good match fast is usually better than the + * best possible one very late. For each iteration + * in the lookup, this value is lowered so the + * longer the lookup takes, the smaller matches + * are considered good. + * + * match_size_drop The percentage by which match_size_good is lowered + * after each history check. Allowed values are + * 0 (no change until end) to 100 (only check + * latest history entry at all). + * ---------- + */ +typedef struct PGLZ_Strategy { + int32 min_input_size; + int32 max_input_size; + int32 min_comp_rate; + int32 first_success_by; + int32 match_size_good; + int32 match_size_drop; +} PGLZ_Strategy; + +/* ---------- + * Local definitions + * ---------- + */ +#define PGLZ_HISTORY_LISTS 8192 /* must be power of 2 */ +#define PGLZ_HISTORY_MASK (PGLZ_HISTORY_LISTS - 1) +#define PGLZ_HISTORY_SIZE 4096 +#define PGLZ_MAX_MATCH 273 + +/* ---------- + * PGLZ_HistEntry - + * + * Linked list for the backward history lookup + * + * All the entries sharing a hash key are linked in a doubly linked list. + * This makes it easy to remove an entry when it's time to recycle it + * (because it's more than 4K positions old). + * ---------- + */ +typedef struct PGLZ_HistEntry { + struct PGLZ_HistEntry* next; /* links for my hash key's list */ + struct PGLZ_HistEntry* prev; + int hindex; /* my current hash key */ + const char* pos; /* my input position */ +} PGLZ_HistEntry; + +/* ---------- + * The standard strategies + * + * PGLZ_strategy_default Recommended default strategy for TOAST. + * + * PGLZ_strategy_always Try to compress inputs of any length. + * Fallback to uncompressed storage only if + * output would be larger than input. + * ---------- + */ +extern const PGLZ_Strategy* const PGLZ_strategy_default; +extern const PGLZ_Strategy* const PGLZ_strategy_always; + +/* ---------- + * Global function declarations + * ---------- + */ +extern bool pglz_compress(const char* source, int32 slen, PGLZ_Header* dest, const PGLZ_Strategy* strategy); +extern void pglz_decompress(const PGLZ_Header* source, char* dest); + +#endif /* _PG_LZCOMPRESS_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/pg_rusage.h postgresql-hll-2.14/include/utils/pg_rusage.h --- postgresql-hll-2.14_old/include/utils/pg_rusage.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/pg_rusage.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * pg_rusage.h + * header file for resource usage measurement support routines + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/pg_rusage.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PG_RUSAGE_H +#define PG_RUSAGE_H + +#include + +#ifdef HAVE_SYS_RESOURCE_H +#include +#else +#include "rusagestub.h" +#endif + +/* State structure for pg_rusage_init/pg_rusage_show */ +typedef struct PGRUsage { + struct timeval tv; + struct rusage ru; +} PGRUsage; + +extern void pg_rusage_init(PGRUsage* ru0); +extern const char* pg_rusage_show(const PGRUsage* ru0); + +#endif /* PG_RUSAGE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/plancache.h postgresql-hll-2.14/include/utils/plancache.h --- postgresql-hll-2.14_old/include/utils/plancache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/plancache.h 2020-12-12 17:06:43.402350038 +0800 @@ -0,0 +1,424 @@ +/* ------------------------------------------------------------------------- + * + * plancache.h + * Plan cache definitions. + * + * See plancache.c for comments. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/plancache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PLANCACHE_H +#define PLANCACHE_H + +#include "access/tupdesc.h" +#include "nodes/params.h" +#include "utils/atomic.h" +#ifdef PGXC +#include "pgxc/locator.h" +#include "nodes/plannodes.h" +#endif + +#ifdef ENABLE_MOT +// forward declaration for MOT JitContext +namespace JitExec +{ + struct JitContext; +} +#endif + +#define CACHEDPLANSOURCE_MAGIC 195726186 +#define CACHEDPLAN_MAGIC 953717834 + +#ifdef ENABLE_MOT +/* different storage engine types that might be used by a query */ +typedef enum { + SE_TYPE_UNSPECIFIED = 0, /* unspecified storage engine */ + SE_TYPE_MOT, /* MOT storage engine */ + SE_TYPE_PAGE_BASED, /* Page Based storage engine */ + SE_TYPE_MIXED /* Mixed (MOT & Page Based) storage engines */ +} StorageEngineType; +#endif + +/* possible values for plan_cache_mode */ +typedef enum { + PLAN_CACHE_MODE_AUTO, + PLAN_CACHE_MODE_FORCE_GENERIC_PLAN, + PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN +} PlanCacheMode; + +typedef enum { + GPC_PRIVATE, + GPC_SHARED, + GPC_CPLAN, // generate cplan + GPC_UNSHARED, // not satisfied share condition, like stream plan +} GPCSourceKind; + +typedef enum { + GPC_SHARE_IN_LOCAL_SAVE_PLAN_LIST, + GPC_SHARE_IN_LOCAL_UNGPC_PLAN_LIST, // contains GPC_PRIVATE, GPC_UNSHARED and GPC_CPLAN plancache + GPC_SHARE_IN_PREPARE_STATEMENT, + GPC_SHARE_IN_SHARE_TABLE, + GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST, +} GPCSourceSharedLoc; + +typedef enum { + GPC_VALID, + GPC_INVALID, +} GPCSourceSharedStatus; + +class GPCPlanStatus +{ +public: + GPCPlanStatus() { + m_kind = GPC_PRIVATE; + m_location = GPC_SHARE_IN_PREPARE_STATEMENT; + m_status = GPC_VALID; + m_refcount = 0; + } + + inline void ShareInit() + { + m_kind = GPC_SHARED; + m_location = GPC_SHARE_IN_PREPARE_STATEMENT; + m_status = GPC_VALID; + m_refcount = 0; + } + // NOTE: can not reset to GPC_PRIVATE + inline void SetKind(GPCSourceKind kind) + { + Assert(kind != GPC_PRIVATE); + pg_memory_barrier(); + m_kind = kind; + } + inline void SetLoc(GPCSourceSharedLoc location) + { + pg_memory_barrier(); + m_location = location; + } + + inline void SetStatus(GPCSourceSharedStatus status) + { + pg_memory_barrier(); + m_status = status; + } + + inline bool IsPrivatePlan() + { + pg_memory_barrier(); + return m_kind == GPC_PRIVATE; + } + + inline bool IsSharePlan() + { + pg_memory_barrier(); + return m_kind == GPC_SHARED; + } + + inline bool IsUnSharedPlan() + { + pg_memory_barrier(); + return m_kind == GPC_UNSHARED; + } + + inline bool IsUnShareCplan() + { + pg_memory_barrier(); + return m_kind == GPC_CPLAN; + } + + inline bool InSavePlanList(GPCSourceKind kind) + { + pg_memory_barrier(); + return m_kind == kind && m_location == GPC_SHARE_IN_LOCAL_SAVE_PLAN_LIST; + } + + inline bool InUngpcPlanList() + { + pg_memory_barrier(); + return (m_kind != GPC_SHARED) && m_location == GPC_SHARE_IN_LOCAL_UNGPC_PLAN_LIST; + } + + inline bool InPrepareStmt() + { + pg_memory_barrier(); + return m_location == GPC_SHARE_IN_PREPARE_STATEMENT; + } + + inline bool InShareTable() + { + pg_memory_barrier(); + return m_kind == GPC_SHARED && (m_location == GPC_SHARE_IN_SHARE_TABLE || m_location == GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST); + } + + inline bool InShareTableInvalidList() + { + pg_memory_barrier(); + return (m_kind == GPC_SHARED && m_location == GPC_SHARE_IN_SHARE_TABLE_INVALID_LIST); + } + + inline bool IsValid() + { + pg_memory_barrier(); + return m_status == GPC_VALID; + } + + inline bool NeedDropSharedGPC() + { + Assert (m_kind == GPC_SHARED); + pg_memory_barrier(); + return m_location == GPC_SHARE_IN_SHARE_TABLE && m_status == GPC_INVALID; + } + + inline void AddRefcount() + { + pg_atomic_fetch_add_u32((volatile uint32*)&m_refcount, 1); + } + + inline void SubRefCount() + { + pg_atomic_fetch_sub_u32((volatile uint32*)&m_refcount, 1); + } + + inline bool RefCountZero() + { + /* if is same as 0 then set 0 and return true, if is different then do nothing and return false */ + uint32 expect = 0; + return pg_atomic_compare_exchange_u32((volatile uint32*)&m_refcount, &expect, 0); + } + + inline int GetRefCount() + { + return m_refcount; + } + + inline bool CheckRefCount() + { + /* m_refcount can not less than 0 */ + int val = (int)pg_atomic_fetch_add_u32((volatile uint32*)&m_refcount, 0); + return val >= 0; + } + +private: + volatile GPCSourceKind m_kind; + volatile GPCSourceSharedLoc m_location; + volatile GPCSourceSharedStatus m_status; + volatile int m_refcount; +}; + +typedef struct GPCSource +{ + GPCPlanStatus status; + struct GPCKey* key; //remember when we generate the plan. +} GPCSource; + +typedef struct SPISign +{ + uint32 spi_key; /* hash value of PLpgSQL_function's fn_hashkey */ + Oid func_oid; + uint32 spi_id; /* spi idx to PLpgSQL_expr, same as plansource's spi_id */ + int plansource_id; /* plansource idx in spiplan's plancache_list */ +} SPISign; + +/* + * CachedPlanSource (which might better have been called CachedQuery) + * represents a SQL query that we expect to use multiple times. It stores + * the query source text, the raw parse tree, and the analyzed-and-rewritten + * query tree, as well as adjunct data. Cache invalidation can happen as a + * result of DDL affecting objects used by the query. In that case we discard + * the analyzed-and-rewritten query tree, and rebuild it when next needed. + * + * An actual execution plan, represented by CachedPlan, is derived from the + * CachedPlanSource when we need to execute the query. The plan could be + * either generic (usable with any set of plan parameters) or custom (for a + * specific set of parameters). plancache.c contains the logic that decides + * which way to do it for any particular execution. If we are using a generic + * cached plan then it is meant to be re-used across multiple executions, so + * callers must always treat CachedPlans as read-only. + * + * Once successfully built and "saved", CachedPlanSources typically live + * for the life of the backend, although they can be dropped explicitly. + * CachedPlans are reference-counted and go away automatically when the last + * reference is dropped. A CachedPlan can outlive the CachedPlanSource it + * was created from. + * + * An "unsaved" CachedPlanSource can be used for generating plans, but it + * lives in transient storage and will not be updated in response to sinval + * events. + * + * CachedPlans made from saved CachedPlanSources are likewise in permanent + * storage, so to avoid memory leaks, the reference-counted references to them + * must be held in permanent data structures or ResourceOwners. CachedPlans + * made from unsaved CachedPlanSources are in children of the caller's + * memory context, so references to them should not be longer-lived than + * that context. (Reference counting is somewhat pro forma in that case, + * though it may be useful if the CachedPlan can be discarded early.) + * + * A CachedPlanSource has two associated memory contexts: one that holds the + * struct itself, the query source text and the raw parse tree, and another + * context that holds the rewritten query tree and associated data. This + * allows the query tree to be discarded easily when it is invalidated. + * + * Some callers wish to use the CachedPlan API even with one-shot queries + * that have no reason to be saved at all. We therefore support a "oneshot" + * variant that does no data copying or invalidation checking. In this case + * there are no separate memory contexts: the CachedPlanSource struct and + * all subsidiary data live in the caller's CurrentMemoryContext, and there + * is no way to free memory short of clearing that entire context. A oneshot + * plan is always treated as unsaved. + * + * Note: the string referenced by commandTag is not subsidiary storage; + * it is assumed to be a compile-time-constant string. As with portals, + * commandTag shall be NULL if and only if the original query string (before + * rewriting) was an empty string. + */ +typedef struct CachedPlanSource { + int magic; /* should equal CACHEDPLANSOURCE_MAGIC */ + Node* raw_parse_tree; /* output of raw_parser() */ + const char* query_string; /* source text of query */ + const char* commandTag; /* command tag (a constant!), or NULL */ + Oid* param_types; /* array of parameter type OIDs, or NULL */ + int num_params; /* length of param_types array */ + ParserSetupHook parserSetup; /* alternative parameter spec method */ + void* parserSetupArg; + int cursor_options; /* cursor options used for planning */ + Oid rewriteRoleId; /* Role ID we did rewriting for */ + bool dependsOnRole; /* is rewritten query specific to role? */ + bool fixed_result; /* disallow change in result tupdesc? */ + TupleDesc resultDesc; /* result type; NULL = doesn't return tuples */ + MemoryContext context; /* memory context holding all above */ + /* These fields describe the current analyzed-and-rewritten query tree: */ + List* query_list; /* list of Query nodes, or NIL if not valid */ + /* + * Notice: be careful to use relationOids as it may contain non-table OID + * in some scenarios, e.g. assignment of relationOids in fix_expr_common. + */ + List* relationOids; /* contain OIDs of relations the queries depend on */ + List* invalItems; /* other dependencies, as PlanInvalItems */ + struct OverrideSearchPath* search_path; /* search_path used for + * parsing and planning */ + MemoryContext query_context; /* context holding the above, or NULL */ + /* If we have a generic plan, this is a reference-counted link to it: */ + struct CachedPlan* gplan; /* generic plan, or NULL if not valid */ + /* Some state flags: */ + bool is_complete; /* has CompleteCachedPlan been done? */ + bool is_saved; /* has CachedPlanSource been "saved"? */ + bool is_valid; /* is the query_list currently valid? */ + bool is_oneshot; /* is it a "oneshot" plan? */ +#ifdef ENABLE_MOT + StorageEngineType storageEngineType; /* which storage engine is used*/ + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif + int generation; /* increments each time we create a plan */ + /* If CachedPlanSource has been saved, it is a member of a global list */ + struct CachedPlanSource* next_saved; /* list link, if so */ + /* State kept to help decide whether to use custom or generic plans: */ + double generic_cost; /* cost of generic plan, or -1 if not known */ + double total_custom_cost; /* total cost of custom plans so far */ + int num_custom_plans; /* number of plans included in total */ + + GPCSource gpc; /* share plan cache */ + SPISign spi_signature; + bool is_support_gplan; /* true if generate gplan */ +#ifdef PGXC + char* stmt_name; /* If set, this is a copy of prepared stmt name */ + bool stream_enabled; /* true if the plan is made with stream operator enabled */ + struct CachedPlan* cplan; /* custom plan, or NULL if not valid */ + ExecNodes* single_exec_node; + bool is_read_only; + void* lightProxyObj; /* light cn object */ + + void* opFusionObj; /* operator fusion object */ + bool is_checked_opfusion; + + bool gplan_is_fqs; /* if gplan is a fqs plan, use generic plan if + so when enable_pbe_optimization is on */ + bool force_custom_plan; /* force to use custom plan */ + bool single_shard_stmt; /* single shard stmt? */ +#endif +} CachedPlanSource; + +/* + * CachedPlan represents an execution plan derived from a CachedPlanSource. + * The reference count includes both the link from the parent CachedPlanSource + * (if any), and any active plan executions, so the plan can be discarded + * exactly when refcount goes to zero. Both the struct itself and the + * subsidiary data live in the context denoted by the context field. + * This makes it easy to free a no-longer-needed cached plan. (However, + * if is_oneshot is true, the context does not belong solely to the CachedPlan + * so no freeing is possible.) + */ +typedef struct CachedPlan { + int magic; /* should equal CACHEDPLAN_MAGIC */ + List* stmt_list; /* list of statement nodes (PlannedStmts and + * bare utility statements) */ + bool is_saved; /* is CachedPlan in a long-lived context? */ + bool is_valid; /* is the stmt_list currently valid? */ + bool is_oneshot; /* is it a "oneshot" plan? */ +#ifdef ENABLE_MOT + StorageEngineType storageEngineType; /* which storage engine is used*/ + JitExec::JitContext* mot_jit_context; /* MOT JIT context required for executing LLVM jitted code */ +#endif + bool dependsOnRole; /* is plan specific to that role? */ + Oid planRoleId; /* Role ID the plan was created for */ + TransactionId saved_xmin; /* if valid, replan when TransactionXmin + * changes from this value */ + int generation; /* parent's generation number for this plan */ + int refcount; /* count of live references to this struct */ + bool single_shard_stmt; /* single shard stmt? */ + MemoryContext context; /* context containing this CachedPlan */ + + volatile int global_refcount; + volatile bool is_share; /* is it gpc share plan? */ + int dn_stmt_num; /* datanode statment num */ + inline bool isShared() + { + pg_memory_barrier(); + return is_share; + } +} CachedPlan; + +extern void InitPlanCache(void); +extern void ResetPlanCache(void); + +extern CachedPlanSource* CreateCachedPlan(Node* raw_parse_tree, const char* query_string, +#ifdef PGXC + const char* stmt_name, +#endif + const char* commandTag, + bool enable_spi_gpc = false); +extern CachedPlanSource* CreateOneShotCachedPlan( + Node* raw_parse_tree, const char* query_string, const char* commandTag); +extern void CompleteCachedPlan(CachedPlanSource* plansource, List* querytree_list, MemoryContext querytree_context, + Oid* param_types, int num_params, ParserSetupHook parserSetup, void* parserSetupArg, int cursor_options, + bool fixed_result, const char* stmt_name, ExecNodes* single_exec_node = NULL, bool is_read_only = false); + +extern void SaveCachedPlan(CachedPlanSource* plansource); +extern void DropCachedPlan(CachedPlanSource* plansource); + +extern void CachedPlanSetParentContext(CachedPlanSource* plansource, MemoryContext newcontext); + +extern CachedPlanSource *CopyCachedPlan(CachedPlanSource *plansource, bool is_share); + +extern bool CachedPlanIsValid(CachedPlanSource* plansource); + +extern List* CachedPlanGetTargetList(CachedPlanSource* plansource); + +extern CachedPlan* GetCachedPlan(CachedPlanSource* plansource, ParamListInfo boundParams, bool useResOwner); +extern void ReleaseCachedPlan(CachedPlan* plan, bool useResOwner); +extern void DropCachedPlanInternal(CachedPlanSource* plansource); +extern List* RevalidateCachedQuery(CachedPlanSource* plansource, bool has_lp = false); + +extern void CheckRelDependency(CachedPlanSource *plansource, Oid relid); +extern void CheckInvalItemDependency(CachedPlanSource *plansource, int cacheid, uint32 hashvalue); +extern void ResetPlanCache(CachedPlanSource *plansource); + +extern void PlanCacheRelCallback(Datum arg, Oid relid); +extern void PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue); +extern void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue); + +#endif /* PLANCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/plog.h postgresql-hll-2.14/include/utils/plog.h --- postgresql-hll-2.14_old/include/utils/plog.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/plog.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,360 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * plog.h + * + * + * + * IDENTIFICATION + * src/include/utils/plog.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_UTILS_PLOG_H_ +#define SRC_INCLUDE_UTILS_PLOG_H_ + +#include "c.h" +#include "miscadmin.h" +#include "portability/instr_time.h" +#include "postmaster/syslogger.h" +#include "replication/replicainternal.h" + +#define RET_TYPE_OK 1 +#define RET_TYPE_FAIL 0 +#define PLOG_ENTRY_MAGICNUM (0xFFFFFFFF) + +enum DataSourceType { + /* magnetic disk */ + DS_MD = 0, + + /* OBS data source */ + DS_OBS, + + /* Hadoop data source */ + DS_HADOOP, + + /* remote datanode */ + DS_REMOTE_DATANODE, + + /* current number of valid data source, maybe equal to DS_UPLIMIT */ + DS_VALID_NUM, + + /* max value of data source */ + DS_UPLIMIT = 127 +}; + +/* data resource require type */ +enum DataResReqType { + /* OBS LIST */ + DSRQ_LIST = 0, + + /* read data from data source */ + DSRQ_READ, + + /* write data to data source */ + DSRQ_WRITE, + + /* OBS OPEN */ + DSRQ_OPEN, + + /* current number of valid requiring type */ + DSRQ_VALID_NUM, + + /* max value of requiring data source */ + DSRQ_UPLIMIT = 127 +}; + +/* + * Add plog_magic to distinguish 32 bits u_sess->debug_query_id + * from 64 bits u_sess->debug_query_id in log files of gs_profile. + * In case of 32 bits u_sess->debug_query_id, gxid and gqid form a 8 byte, and align with 8-byte tid. + * In case of 64 bits u_sess->debug_query_id, gxid and plog_magic form a 8 byte, and align with 8-byte tid. + * Thus, plog_magic can be used to tell us which type of u_sess->debug_query_id is read from the log files. + * Here, byte alignment feature is used. So be careful to maintain this byte alignment + * when revising PLogEntryMeta. + */ +typedef struct { + struct timeval req_time; /* record's time */ + ThreadId tid; /* thread id */ + uint32 gxid; /* global transaction id */ + uint32 plog_magic; /* PLogEntryMeta MAGICNUM */ + uint64 gqid; /* debug query id */ +} PLogEntryMeta; /* 8byte alligned */ + +typedef struct { + uint8 data_src; + uint8 req_type; + uint8 ret_type; /* 1, success; 0, failed */ + uint8 item_num; /* <= PLOG_MD_ITEM_MAX_NUM */ +} PLogEntryHead; /* 4byte alligned */ + +typedef struct { + uint32 sum_count; + uint32 sum_size; /* how many data */ + uint32 sum_usec; /* time to run, upmost is 1 hour */ +} PLogEntryItem; /* 4byte alligned */ + +typedef struct { + uint8 data_src; + uint8 req_type; + + /* RET_TYPE_OK or RET_TYPE_FAIL */ + uint8 ret_type; + + /* + * if ret_type is RET_TYPE_OK, + * dat_size means the real data amount offered by disk/OBS, etc + * if ret_type is RET_TYPE_FAIL, + * dat_size means the data amount required by caller + * + * req_usec always mean the used time to require and server. + */ + uint32 dat_size; /* data size */ + uint32 req_usec; /* required time with us */ +} IndicatorItem; + +typedef struct { + PLogEntryMeta meta; + PLogEntryHead head; + PLogEntryItem item[FLEXIBLE_ARRAY_MEMBER]; + /* the other items */ +} PLogEntry; + +typedef struct { + PLogEntry basic; +} PLogBasicEntry; + +typedef struct { + /* message protocol head */ + char msghead[LOGPIPE_HEADER_SIZE]; + union { + PLogBasicEntry entry; + } msgbody; +} PLogMsg; + +extern void aggregate_profile_logs(IndicatorItem* new_item, struct timeval* nowtm); +extern void flush_plog(void); + +#define SKIPPED_MODE() \ + (t_thrd.xlog_cxt.InRecovery || (t_thrd.postmaster_cxt.HaShmData == NULL) || \ + (t_thrd.postmaster_cxt.HaShmData->current_mode != PRIMARY_MODE && \ + t_thrd.postmaster_cxt.HaShmData->current_mode != NORMAL_MODE)) + +/* if plog is enable */ +#define ENABLE_PLOG() \ + (IsUnderPostmaster && g_instance.attr.attr_common.Logging_collector && \ + u_sess->attr.attr_storage.plog_merge_age > 0 && !SKIPPED_MODE()) + +#define PROFILING_START_TIMER() \ + instr_time __startTime; \ + bool enable_plog = ENABLE_PLOG(); \ + if (enable_plog) { \ + (void)INSTR_TIME_SET_CURRENT(__startTime); \ + } + +#define PROFILING_END_TIMER() \ + instr_time __endTime; \ + instr_time __difTime; \ + (void)INSTR_TIME_SET_CURRENT(__endTime); \ + __difTime = __endTime; \ + INSTR_TIME_SUBTRACT(__difTime, __startTime) + +/* time X > time Y ? */ +#define TM_IS_BIGGER(x, y) (((x).tv_sec == (y).tv_sec) ? ((x).tv_usec > (y).tv_usec) : ((x).tv_sec > (y).tv_sec)) + +/* interface macro about MD(magetic disk) IO monitor */ +#define PROFILING_MDIO_START() PROFILING_START_TIMER() + +#define PROFILING_MDIO_END_READ(__reqsize, __retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_MD; \ + new_item.req_type = DSRQ_READ; \ + if ((__retsize) >= 0) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_MDIO_END_WRITE(__reqsize, __retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_MD; \ + new_item.req_type = DSRQ_WRITE; \ + if ((__retsize) >= 0) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about OBS(Object Storage Service) IO monitor */ +#define PROFILING_OBS_ERROR(__reqsize, __reqtype) \ + do { \ + IndicatorItem new_item; \ + instr_time __nowtime; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = (__reqtype); \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + new_item.req_usec = 0; \ + (void)INSTR_TIME_SET_CURRENT(__nowtime); \ + aggregate_profile_logs(&new_item, &(__nowtime)); \ + } while (0) + +#define PROFILING_OBS_START() PROFILING_START_TIMER() + +#define PROFILING_OBS_END_LIST(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_LIST; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_OBS_END_READ(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_READ; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_OBS_END_WRITE(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_OBS; \ + new_item.req_type = DSRQ_WRITE; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about Hadoop IO monitor */ + +#define PROFILING_HDP_ERROR(__reqsize, __reqtype) \ + do { \ + IndicatorItem new_item; \ + instr_time __nowtime; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = (__reqtype); \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + new_item.req_usec = 0; \ + (void)INSTR_TIME_SET_CURRENT(__nowtime); \ + aggregate_profile_logs(&new_item, &(__nowtime)); \ + } while (0) + +#define PROFILING_HDP_START() PROFILING_START_TIMER() + +#define PROFILING_HDP_END_OPEN(__rettype) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_OPEN; \ + new_item.ret_type = (__rettype); \ + new_item.dat_size = 1; /* only one file */ \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_HDP_END_READ(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_READ; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +#define PROFILING_HDP_END_WRITE(__retsize) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_HADOOP; \ + new_item.req_type = DSRQ_WRITE; \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__retsize); \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +/* interface macro about remote datanode read monitor */ +#define PROFILING_REMOTE_START() PROFILING_START_TIMER() + +#define PROFILING_REMOTE_END_READ(__reqsize, __is_success) \ + do { \ + if (enable_plog) { \ + PROFILING_END_TIMER(); \ + IndicatorItem new_item; \ + new_item.data_src = DS_REMOTE_DATANODE; \ + new_item.req_type = DSRQ_READ; \ + if (__is_success) { \ + new_item.ret_type = RET_TYPE_OK; \ + new_item.dat_size = (__reqsize); \ + } else { \ + new_item.ret_type = RET_TYPE_FAIL; \ + new_item.dat_size = (__reqsize); \ + } \ + new_item.req_usec = INSTR_TIME_GET_MICROSEC(__difTime); \ + aggregate_profile_logs(&new_item, &__endTime); \ + } \ + } while (0) + +extern void init_plog_global_mem(void); + +#endif /* SRC_INCLUDE_UTILS_PLOG_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/plpgsql.h postgresql-hll-2.14/include/utils/plpgsql.h --- postgresql-hll-2.14_old/include/utils/plpgsql.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/plpgsql.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,1008 @@ +/*--------------------------------------------------------------------------------------- + * + * plpgsql.h + * Definitions for the PL/pgSQL procedural language + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/plpgsql.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PLPGSQL_H +#define PLPGSQL_H + +#include "postgres.h" + +#include "access/xact.h" +#include "catalog/namespace.h" +#include "commands/trigger.h" +#include "executor/spi.h" + +/********************************************************************** + * Definitions + **********************************************************************/ + +/* define our text domain for translations */ +#undef TEXTDOMAIN +#define TEXTDOMAIN PG_TEXTDOMAIN("plpgsql") + +#undef _ +#define _(x) dgettext(TEXTDOMAIN, x) + +/* ---------- + * Compiler's namespace item types + * ---------- + */ +enum { + PLPGSQL_NSTYPE_LABEL, + PLPGSQL_NSTYPE_VAR, + PLPGSQL_NSTYPE_ROW, + PLPGSQL_NSTYPE_REC, + PLPGSQL_NSTYPE_RECORD, + PLPGSQL_NSTYPE_REFCURSOR, + PLPGSQL_NSTYPE_VARRAY +}; + +/* ---------- + * Datum array node types + * ---------- + */ +enum { + PLPGSQL_DTYPE_VAR, + PLPGSQL_DTYPE_ROW, + PLPGSQL_DTYPE_REC, + PLPGSQL_DTYPE_RECORD, + PLPGSQL_DTYPE_RECFIELD, + PLPGSQL_DTYPE_ARRAYELEM, + PLPGSQL_DTYPE_EXPR +}; + +// enums token flag +enum { + PLPGSQL_TOK_REFCURSOR, + PLPGSQL_TOK_VARRAY, + PLPGSQL_TOK_VARRAY_FIRST, + PLPGSQL_TOK_VARRAY_LAST, + PLPGSQL_TOK_VARRAY_COUNT, + PLPGSQL_TOK_VARRAY_EXTEND, + PLPGSQL_TOK_VARRAY_VAR, + PLPGSQL_TOK_RECORD +}; + +/* ---------- + * Variants distinguished in PLpgSQL_type structs + * ---------- + */ +enum { + PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */ + PLPGSQL_TTYPE_ROW, /* composite types */ + PLPGSQL_TTYPE_REC, /* RECORD pseudotype */ + PLPGSQL_TTYPE_RECORD, /* RECORD pseudotype complitable oracle */ + PLPGSQL_TTYPE_PSEUDO /* other pseudotypes */ +}; + +/* ---------- + * Execution tree node types + * ---------- + */ +enum PLpgSQL_stmt_types { + PLPGSQL_STMT_BLOCK, + PLPGSQL_STMT_ASSIGN, + PLPGSQL_STMT_IF, + PLPGSQL_STMT_GOTO, + PLPGSQL_STMT_CASE, + PLPGSQL_STMT_LOOP, + PLPGSQL_STMT_WHILE, + PLPGSQL_STMT_FORI, + PLPGSQL_STMT_FORS, + PLPGSQL_STMT_FORC, + PLPGSQL_STMT_FOREACH_A, + PLPGSQL_STMT_EXIT, + PLPGSQL_STMT_RETURN, + PLPGSQL_STMT_RETURN_NEXT, + PLPGSQL_STMT_RETURN_QUERY, + PLPGSQL_STMT_RAISE, + PLPGSQL_STMT_EXECSQL, + PLPGSQL_STMT_DYNEXECUTE, + PLPGSQL_STMT_DYNFORS, + PLPGSQL_STMT_GETDIAG, + PLPGSQL_STMT_OPEN, + PLPGSQL_STMT_FETCH, + PLPGSQL_STMT_CLOSE, + PLPGSQL_STMT_PERFORM, + PLPGSQL_STMT_COMMIT, + PLPGSQL_STMT_ROLLBACK, + PLPGSQL_STMT_NULL +}; + +/* ---------- + * Execution node return codes + * ---------- + */ +enum { PLPGSQL_RC_OK, PLPGSQL_RC_EXIT, PLPGSQL_RC_RETURN, PLPGSQL_RC_CONTINUE, PLPGSQL_RC_GOTO_UNRESOLVED }; + +/* ---------- + * GET DIAGNOSTICS information items + * ---------- + */ +enum { + PLPGSQL_GETDIAG_ROW_COUNT, + PLPGSQL_GETDIAG_RESULT_OID, + PLPGSQL_GETDIAG_ERROR_CONTEXT, + PLPGSQL_GETDIAG_ERROR_DETAIL, + PLPGSQL_GETDIAG_ERROR_HINT, + PLPGSQL_GETDIAG_RETURNED_SQLSTATE, + PLPGSQL_GETDIAG_MESSAGE_TEXT +}; + +/* -------- + * RAISE statement options + * -------- + */ +enum { PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_DETAIL, PLPGSQL_RAISEOPTION_HINT }; + +/* -------- + * Behavioral modes for plpgsql variable resolution + * -------- + */ +typedef enum { + PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */ + PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */ + PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */ +} PLpgSQL_resolve_option; + +/* -------- + * State of cursor found/notfound variable + * -------- + */ +typedef enum { PLPGSQL_TRUE, PLPGSQL_FALSE, PLPGSQL_NULL } PLpgSQL_state; + +/********************************************************************** + * Node and structure definitions + **********************************************************************/ +/* + * PLpgSQL_datum is the common supertype for PLpgSQL_expr, PLpgSQL_var, + * PLpgSQL_row, PLpgSQL_rec, PLpgSQL_recfield, and PLpgSQL_arrayelem + */ +typedef struct PLpgSQL_datum { /* Generic datum array item */ + int dtype; + int dno; +} PLpgSQL_datum; + +/* + * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these + * fields + */ +typedef struct { /* Scalar or composite variable */ + int dtype; + int dno; + char* refname; + int lineno; +} PLpgSQL_variable; + +typedef struct PLpgSQL_expr { /* SQL Query to plan and execute */ + int dtype; + int dno; + char* query; + SPIPlanPtr plan; + Bitmapset* paramnos; /* all dnos referenced by this query */ + + /* function containing this expr (not set until we first parse query) */ + struct PLpgSQL_function* func; + + /* namespace chain visible to this expr */ + struct PLpgSQL_nsitem* ns; + + /* fields for "simple expression" fast-path execution: */ + Expr* expr_simple_expr; /* NULL means not a simple expr */ + int expr_simple_generation; /* plancache generation we checked */ + Oid expr_simple_type; /* result type Oid, if simple */ + bool expr_simple_need_snapshot; /* true means need snapshot */ + + /* + * if expr is simple AND prepared in current transaction, + * expr_simple_state and expr_simple_in_use are valid. Test validity by + * seeing if expr_simple_lxid matches current LXID. (If not, + * expr_simple_state probably points at garbage!) + */ + ExprState* expr_simple_state; /* eval tree for expr_simple_expr */ + bool expr_simple_in_use; /* true if eval tree is active */ + LocalTransactionId expr_simple_lxid; + bool isouttype; /*the parameter will output*/ + uint32 idx; + bool is_cachedplan_shared; +} PLpgSQL_expr; + +typedef struct { /* Postgres data type */ + int dtype; + int dno; + char* typname; /* (simple) name of the type */ + Oid typoid; /* OID of the data type */ + int ttype; /* PLPGSQL_TTYPE_ code */ + int16 typlen; /* stuff copied from its pg_type entry */ + bool typbyval; + Oid typrelid; + Oid typioparam; + Oid collation; /* from pg_type, but can be overridden */ + FmgrInfo typinput; /* lookup info for typinput function */ + int32 atttypmod; /* typmod (taken from someplace else) */ +} PLpgSQL_type; + +typedef struct { /* Scalar variable */ + int dtype; + int dno; + char* refname; + int lineno; + + PLpgSQL_type* datatype; + int isconst; + int notnull; + PLpgSQL_expr* default_val; + PLpgSQL_expr* cursor_explicit_expr; + int cursor_explicit_argrow; + int cursor_options; + + Datum value; + bool isnull; + bool freeval; + bool is_cursor_var; + bool is_cursor_open; +} PLpgSQL_var; + +typedef struct { /* Row variable */ + int dtype; + int dno; + char* refname; + int lineno; + + TupleDesc rowtupdesc; + + /* + * Note: TupleDesc is only set up for named rowtypes, else it is NULL. + * + * Note: if the underlying rowtype contains a dropped column, the + * corresponding fieldnames[] entry will be NULL, and there is no + * corresponding var (varnos[] will be -1). + */ + int nfields; + char** fieldnames; + int* varnos; + int customErrorCode; /* only for exception variable. */ + + int intoplaceholders; /* number of placeholders, for anonymous block in dynamic stmt */ + PLpgSQL_datum** intodatums; +} PLpgSQL_row; + +typedef struct { + char* attrname; + PLpgSQL_type* type; + bool notnull; + PLpgSQL_expr* defaultvalue; +} PLpgSQL_rec_attr; + +typedef struct { + int dtype; + int dno; + char* typname; /* (simple) name of the type */ + Oid typoid; /* OID of the data type */ + int ttype; /* PLPGSQL_TTYPE_ code */ + int16 typlen; /* stuff copied from its pg_type entry */ + bool typbyval; + Oid typrelid; + Oid typioparam; + Oid collation; /* from pg_type, but can be overridden */ + FmgrInfo typinput; /* lookup info for typinput function */ + int32 atttypmod; /* typmod (taken from someplace else) */ + int attrnum; + char** attrnames; + PLpgSQL_type** types; + bool* notnulls; + PLpgSQL_expr** defaultvalues; +} PLpgSQL_rec_type; + +typedef struct { /* Record variable (non-fixed structure) */ + int dtype; + int dno; + char* refname; + int lineno; + + HeapTuple tup; + TupleDesc tupdesc; + bool freetup; + bool freetupdesc; +} PLpgSQL_rec; + +typedef struct { /* Field in record */ + int dtype; + int dno; + char* fieldname; + int recparentno; /* dno of parent record */ +} PLpgSQL_recfield; + +typedef struct { /* Element of array variable */ + int dtype; + int dno; + PLpgSQL_expr* subscript; + int arrayparentno; /* dno of parent array variable */ + /* Remaining fields are cached info about the array variable's type */ + Oid parenttypoid; /* type of array variable; 0 if not yet set */ + int32 parenttypmod; /* typmod of array variable */ + Oid arraytypoid; /* OID of actual array type */ + int32 arraytypmod; /* typmod of array (and its elements too) */ + int16 arraytyplen; /* typlen of array type */ + Oid elemtypoid; /* OID of array element type */ + int16 elemtyplen; /* typlen of element type */ + bool elemtypbyval; /* element type is pass-by-value? */ + char elemtypalign; /* typalign of element type */ +} PLpgSQL_arrayelem; + +typedef struct PLpgSQL_nsitem { /* Item in the compilers namespace tree */ + int itemtype; + int itemno; + struct PLpgSQL_nsitem* prev; + char name[FLEXIBLE_ARRAY_MEMBER]; /* actually, as long as needed */ +} PLpgSQL_nsitem; + +typedef struct { /* Generic execution node */ + int cmd_type; + int lineno; +} PLpgSQL_stmt; + +typedef PLpgSQL_stmt PLpgSQL_stmt_null; + +extern THR_LOCAL List* goto_labels; + +typedef struct { + char* label; + PLpgSQL_stmt* stmt; +} PLpgSQL_gotoLabel; + +typedef struct PLpgSQL_condition { /* One EXCEPTION condition name */ + int sqlerrstate; /* SQLSTATE code */ + char* condname; /* condition name (for debugging) */ + struct PLpgSQL_condition* next; +} PLpgSQL_condition; + +typedef struct { + int sqlstate_varno; + int sqlerrm_varno; + List* exc_list; /* List of WHEN clauses */ +} PLpgSQL_exception_block; + +typedef struct { /* One EXCEPTION ... WHEN clause */ + int lineno; + PLpgSQL_condition* conditions; + List* action; /* List of statements */ +} PLpgSQL_exception; + +typedef struct PLpgSQL_stmt_block { /* Block of statements */ + int cmd_type; + int lineno; + char* label; + List* body; /* List of statements */ + int n_initvars; + int* initvarnos; + PLpgSQL_exception_block* exceptions; +} PLpgSQL_stmt_block; + +typedef struct { /* Assign statement */ + int cmd_type; + int lineno; + int varno; + PLpgSQL_expr* expr; +} PLpgSQL_stmt_assign; + +typedef struct { /* PERFORM statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; +} PLpgSQL_stmt_perform; + +typedef struct { /* Get Diagnostics item */ + int kind; /* id for diagnostic value desired */ + int target; /* where to assign it */ +} PLpgSQL_diag_item; + +typedef struct { /* Get Diagnostics statement */ + int cmd_type; + int lineno; + bool is_stacked; /* STACKED or CURRENT diagnostics area? */ + List* diag_items; /* List of PLpgSQL_diag_item */ +} PLpgSQL_stmt_getdiag; + +typedef struct { /* IF statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* cond; /* boolean expression for THEN */ + List* then_body; /* List of statements */ + List* elsif_list; /* List of PLpgSQL_if_elsif structs */ + List* else_body; /* List of statements */ +} PLpgSQL_stmt_if; + +typedef struct { /* GOTO statement */ + int cmd_type; + int lineno; + char* label; +} PLpgSQL_stmt_goto; + +typedef struct /* one ELSIF arm of IF statement */ +{ + int lineno; + PLpgSQL_expr* cond; /* boolean expression for this case */ + List* stmts; /* List of statements */ +} PLpgSQL_if_elsif; + +typedef struct /* CASE statement */ +{ + int cmd_type; + int lineno; + PLpgSQL_expr* t_expr; /* test expression, or NULL if none */ + int t_varno; /* var to store test expression value into */ + List* case_when_list; /* List of PLpgSQL_case_when structs */ + bool have_else; /* flag needed because list could be empty */ + List* else_stmts; /* List of statements */ +} PLpgSQL_stmt_case; + +typedef struct /* one arm of CASE statement */ +{ + int lineno; + PLpgSQL_expr* expr; /* boolean expression for this case */ + List* stmts; /* List of statements */ +} PLpgSQL_case_when; + +typedef struct { /* Unconditional LOOP statement */ + int cmd_type; + int lineno; + char* label; + List* body; /* List of statements */ +} PLpgSQL_stmt_loop; + +typedef struct { /* WHILE cond LOOP statement */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_expr* cond; + List* body; /* List of statements */ +} PLpgSQL_stmt_while; + +typedef struct { /* FOR statement with integer loopvar */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_var* var; + PLpgSQL_expr* lower; + PLpgSQL_expr* upper; + PLpgSQL_expr* step; /* NULL means default (ie, BY 1) */ + int reverse; + List* body; /* List of statements */ +} PLpgSQL_stmt_fori; + +/* + * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query. + * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc + * and PLpgSQL_dynfors. + */ +typedef struct { + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ +} PLpgSQL_stmt_forq; + +typedef struct { /* FOR statement running over SELECT */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + PLpgSQL_expr* query; +} PLpgSQL_stmt_fors; + +typedef struct { /* FOR statement running over cursor */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + int curvar; + PLpgSQL_expr* argquery; /* cursor arguments if any */ +} PLpgSQL_stmt_forc; + +typedef struct { /* FOR statement running over EXECUTE */ + int cmd_type; + int lineno; + char* label; + PLpgSQL_rec* rec; + PLpgSQL_row* row; + List* body; /* List of statements */ + /* end of fields that must match PLpgSQL_stmt_forq */ + PLpgSQL_expr* query; + List* params; /* USING expressions */ +} PLpgSQL_stmt_dynfors; + +typedef struct { /* FOREACH item in array loop */ + int cmd_type; + int lineno; + char* label; + int varno; /* loop target variable */ + int slice; /* slice dimension, or 0 */ + PLpgSQL_expr* expr; /* array expression */ + List* body; /* List of statements */ +} PLpgSQL_stmt_foreach_a; + +typedef struct { /* OPEN a curvar */ + int cmd_type; + int lineno; + int curvar; + int cursor_options; + PLpgSQL_row* returntype; + PLpgSQL_expr* argquery; + PLpgSQL_expr* query; + PLpgSQL_expr* dynquery; + List* params; /* USING expressions */ +} PLpgSQL_stmt_open; + +typedef struct { /* FETCH or MOVE statement */ + int cmd_type; + int lineno; + PLpgSQL_rec* rec; /* target, as record or row */ + PLpgSQL_row* row; + int curvar; /* cursor variable to fetch from */ + FetchDirection direction; /* fetch direction */ + long how_many; /* count, if constant (expr is NULL) */ + PLpgSQL_expr* expr; /* count, if expression */ + bool is_move; /* is this a fetch or move? */ + bool returns_multiple_rows; /* can return more than one row? */ +} PLpgSQL_stmt_fetch; + +typedef struct { /* CLOSE curvar */ + int cmd_type; + int lineno; + int curvar; +} PLpgSQL_stmt_close; + +typedef struct { /* EXIT or CONTINUE statement */ + int cmd_type; + int lineno; + bool is_exit; /* Is this an exit or a continue? */ + char* label; /* NULL if it's an unlabelled EXIT/CONTINUE */ + PLpgSQL_expr* cond; +} PLpgSQL_stmt_exit; + +typedef struct { /* RETURN statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; + int retvarno; +} PLpgSQL_stmt_return; + +typedef struct { /* RETURN NEXT statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* expr; + int retvarno; +} PLpgSQL_stmt_return_next; + +typedef struct { /* RETURN QUERY statement */ + int cmd_type; + int lineno; + PLpgSQL_expr* query; /* if static query */ + PLpgSQL_expr* dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */ + List* params; /* USING arguments for dynamic query */ +} PLpgSQL_stmt_return_query; + +typedef struct { /* RAISE statement */ + int cmd_type; + int lineno; + int elog_level; + char* condname; /* condition name, SQLSTATE, or NULL */ + char* message; /* old-style message format literal, or NULL */ + List* params; /* list of expressions for old-style message */ + List* options; /* list of PLpgSQL_raise_option */ +} PLpgSQL_stmt_raise; + +typedef struct { /* RAISE statement option */ + int opt_type; + PLpgSQL_expr* expr; +} PLpgSQL_raise_option; + +typedef struct { /* Generic SQL statement to execute */ + int cmd_type; + int lineno; + PLpgSQL_expr* sqlstmt; + bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE? */ + /* note: mod_stmt is set when we plan the query */ + bool into; /* INTO supplied? */ + bool strict; /* INTO STRICT flag */ + PLpgSQL_rec* rec; /* INTO target, if record */ + PLpgSQL_row* row; /* INTO target, if row */ + // oracle function invoke feature + int placeholders; + bool multi_func; +} PLpgSQL_stmt_execsql; + +// Added USING IN/OUT/IN OUT for plpgsql +typedef struct { /* Dynamic SQL string to execute */ + int cmd_type; + int lineno; + PLpgSQL_expr* query; /* string expression */ + bool into; /* INTO supplied? */ + bool strict; /* INTO STRICT flag */ + PLpgSQL_rec* rec; /* INTO target, if record */ + union { + PLpgSQL_row* row; /* INTO target, if row */ + PLpgSQL_row* out_row; /* USING output */ + }; + List* params; /* USING expressions */ + bool isinouttype; /* IN OUT parameters, differ from INTO statment */ + bool isanonymousblock; /* check if it is anonymous block */ + void* ppd; /* IN or IN OUT parameters */ +} PLpgSQL_stmt_dynexecute; + +typedef struct PLpgSQL_func_hashkey { /* Hash lookup key for functions */ + Oid funcOid; + + bool isTrigger; /* true if called as a trigger */ + + /* be careful that pad bytes in this struct get zeroed! */ + + /* + * For a trigger function, the OID of the relation triggered on is part of + * the hash key --- we want to compile the trigger separately for each + * relation it is used with, in case the rowtype is different. Zero if + * not called as a trigger. + */ + Oid trigrelOid; + + /* + * We must include the input collation as part of the hash key too, + * because we have to generate different plans (with different Param + * collations) for different collation settings. + */ + Oid inputCollation; + + /* + * We include actual argument types in the hash key to support polymorphic + * PLpgSQL functions. Be careful that extra positions are zeroed! + */ + Oid argtypes[FUNC_MAX_ARGS]; +} PLpgSQL_func_hashkey; + +typedef struct PLpgSQL_function { /* Complete compiled function */ + char* fn_signature; + Oid fn_oid; + OverrideSearchPath* fn_searchpath; + Oid fn_owner; + TransactionId fn_xmin; + ItemPointerData fn_tid; + bool fn_is_trigger; + Oid fn_input_collation; + PLpgSQL_func_hashkey* fn_hashkey; /* back-link to hashtable key */ + MemoryContext fn_cxt; + + Oid fn_rettype; + int fn_rettyplen; + bool fn_retbyval; + FmgrInfo fn_retinput; + Oid fn_rettypioparam; + bool fn_retistuple; + bool fn_retset; + bool fn_readonly; + + int fn_nargs; + int fn_argvarnos[FUNC_MAX_ARGS]; + int out_param_varno; + int found_varno; + + // magic variables' varno for implicit cursor attributes + int sql_cursor_found_varno; + int sql_notfound_varno; + int sql_isopen_varno; + int sql_rowcount_varno; + + // the magic sqlcode no + int sqlcode_varno; + int new_varno; + int old_varno; + int tg_name_varno; + int tg_when_varno; + int tg_level_varno; + int tg_op_varno; + int tg_relid_varno; + int tg_relname_varno; + int tg_table_name_varno; + int tg_table_schema_varno; + int tg_nargs_varno; + int tg_argv_varno; + + PLpgSQL_resolve_option resolve_option; + + int ndatums; + PLpgSQL_datum** datums; + PLpgSQL_stmt_block* action; + List* goto_labels; + + /* these fields change when the function is used */ + struct PLpgSQL_execstate* cur_estate; + unsigned long use_count; + + /* these fields are used during trigger pre-parsing */ + bool pre_parse_trig; + Relation tg_relation; +} PLpgSQL_function; + +typedef struct PLpgSQL_execstate { /* Runtime execution data */ + PLpgSQL_function* func; /* function being executed */ + + Datum retval; + bool retisnull; + Oid rettype; /* type of current retval */ + + Oid fn_rettype; /* info about declared function rettype */ + bool retistuple; + bool retisset; + + bool readonly_func; + + TupleDesc rettupdesc; + char* exitlabel; /* the "target" label of the current EXIT or + * CONTINUE stmt, if any */ + ErrorData* cur_error; /* current exception handler's error */ + + Tuplestorestate* tuple_store; /* SRFs accumulate results here */ + MemoryContext tuple_store_cxt; + ResourceOwner tuple_store_owner; + ReturnSetInfo* rsi; + + int found_varno; + + /* + * The execute state variable estate->rowcount keeps + * the current rowcount while executing store procedure + */ + int32 rowcount; + + /* magic variables' varno for implicit cursor attributes */ + int sql_cursor_found_varno; + int sql_notfound_varno; + int sql_isopen_varno; + int sql_rowcount_varno; + int sqlcode_varno; + int ndatums; + PLpgSQL_datum** datums; + + /* temporary state for results from evaluation of query or expr */ + SPITupleTable* eval_tuptable; + uint32 eval_processed; + Oid eval_lastoid; + ExprContext* eval_econtext; /* for executing simple expressions */ + PLpgSQL_expr* cur_expr; /* current query/expr being evaluated */ + + /* status information for error context reporting */ + PLpgSQL_stmt* err_stmt; /* current stmt */ + const char* err_text; /* additional state info */ + + void* plugin_info; /* reserved for use by optional plugin */ + + /* support GOTO */ + List* goto_labels; + char* goto_target_label; + PLpgSQL_stmt* goto_target_stmt; /* current GOTO */ + int block_level; /* block level, 0 for topmost */ + Cursor_Data* cursor_return_data; +} PLpgSQL_execstate; + +/* + * A PLpgSQL_plugin structure represents an instrumentation plugin. + * To instrument PL/pgSQL, a plugin library must access the rendezvous + * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct. + * Typically the struct could just be static data in the plugin library. + * We expect that a plugin would do this at library load time (_PG_init()). + * It must also be careful to set the rendezvous variable back to NULL + * if it is unloaded (_PG_fini()). + * + * This structure is basically a collection of function pointers --- at + * various interesting points in pl_exec.c, we call these functions + * (if the pointers are non-NULL) to give the plugin a chance to watch + * what we are doing. + * + * func_setup is called when we start a function, before we've initialized + * the local variables defined by the function. + * + * func_beg is called when we start a function, after we've initialized + * the local variables. + * + * func_end is called at the end of a function. + * + * stmt_beg and stmt_end are called before and after (respectively) each + * statement. + * + * Also, immediately before any call to func_setup, PL/pgSQL fills in the + * error_callback and assign_expr fields with pointers to its own + * plpgsql_exec_error_callback and exec_assign_expr functions. This is + * a somewhat ad-hoc expedient to simplify life for debugger plugins. + */ + +typedef struct PLpgSQL_plugin { + /* Function pointers set up by the plugin */ + void (*func_setup)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*func_beg)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*func_end)(PLpgSQL_execstate* estate, PLpgSQL_function* func); + void (*stmt_beg)(PLpgSQL_execstate* estate, PLpgSQL_stmt* stmt); + void (*stmt_end)(PLpgSQL_execstate* estate, PLpgSQL_stmt* stmt); + + /* Function pointers set by PL/pgSQL itself */ + void (*error_callback)(void* arg); + void (*assign_expr)(PLpgSQL_execstate* estate, PLpgSQL_datum* target, PLpgSQL_expr* expr); + Datum (*eval_expr)(PLpgSQL_execstate* estate, PLpgSQL_expr* expr, bool* isNull, Oid* rettype); + void (*assign_value)(PLpgSQL_execstate* estate, PLpgSQL_datum* target, Datum value, Oid valtype, bool* isNull); + void (*eval_cleanup)(PLpgSQL_execstate* estate); + int (*validate_line)(PLpgSQL_stmt_block* block, int linenum); +} PLpgSQL_plugin; + +/* Struct types used during parsing */ + +typedef struct { + char* ident; /* palloc'd converted identifier */ + bool quoted; /* Was it double-quoted? */ +} PLword; + +typedef struct { + List* idents; /* composite identifiers (list of String) */ +} PLcword; + +typedef struct { + PLpgSQL_datum* datum; /* referenced variable */ + char* ident; /* valid if simple name */ + bool quoted; + List* idents; /* valid if composite name */ +} PLwdatum; + +/********************************************************************** + * Function declarations + **********************************************************************/ + +/* ---------- + * Functions in pl_comp.c + * ---------- + */ + +typedef struct plpgsql_hashent { + PLpgSQL_func_hashkey key; + PLpgSQL_function* function; + DListCell* cell; /* Dlist cell for delete function compile results. */ +} plpgsql_HashEnt; + +extern PLpgSQL_function* plpgsql_compile(FunctionCallInfo fcinfo, bool forValidator); +extern PLpgSQL_function* plpgsql_compile_nohashkey(FunctionCallInfo fcinfo); /* parse trigger func */ +extern PLpgSQL_function* plpgsql_compile_inline(char* proc_source); +extern void plpgsql_parser_setup(struct ParseState* pstate, PLpgSQL_expr* expr); +extern bool plpgsql_parse_word(char* word1, const char* yytxt, PLwdatum* wdatum, PLword* word, int* tok_flag); +extern bool plpgsql_parse_dblword(char* word1, char* word2, PLwdatum* wdatum, PLcword* cword, int* nsflag); +extern bool plpgsql_parse_tripword(char* word1, char* word2, char* word3, PLwdatum* wdatum, PLcword* cword); +extern PLpgSQL_type* plpgsql_parse_wordtype(char* ident); +extern PLpgSQL_type* plpgsql_parse_cwordtype(List* idents); +extern PLpgSQL_type* plpgsql_parse_wordrowtype(char* ident); +extern PLpgSQL_type* plpgsql_parse_cwordrowtype(List* idents); +extern PLpgSQL_type* plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation); +extern PLpgSQL_variable* plpgsql_build_variable( + const char* refname, int lineno, PLpgSQL_type* dtype, bool add2namespace, const char* varname = NULL); +PLpgSQL_variable* plpgsql_build_varrayType(const char* refname, int lineno, PLpgSQL_type* dtype, bool add2namespace); +extern PLpgSQL_rec_type* plpgsql_build_rec_type(const char* typname, int lineno, List* list, bool add2namespace); +extern PLpgSQL_rec* plpgsql_build_record(const char* refname, int lineno, bool add2namespace); +extern int plpgsql_recognize_err_condition(const char* condname, bool allow_sqlstate); +extern PLpgSQL_condition* plpgsql_parse_err_condition(char* condname); +extern void plpgsql_adddatum(PLpgSQL_datum* newm); +extern int plpgsql_add_initdatums(int** varnos); +extern void plpgsql_HashTableInit(void); +extern PLpgSQL_row* build_row_from_rec_type(const char* rowname, int lineno, PLpgSQL_rec_type* type); +extern bool plpgsql_check_colocate(Query* query, RangeTblEntry* rte, void* plpgsql_func); +extern void plpgsql_HashTableDeleteAll(); +extern void plpgsql_HashTableDeleteFunc(Oid func_oid); +extern void plpgsql_HashTableDelete(PLpgSQL_function* func); + +/* ---------- + * Functions in pl_handler.c + * ---------- + */ +extern "C" void _PG_init(void); +extern "C" Datum plpgsql_call_handler(PG_FUNCTION_ARGS); +extern "C" Datum plpgsql_inline_handler(PG_FUNCTION_ARGS); +extern "C" Datum plpgsql_validator(PG_FUNCTION_ARGS); + +/* --- --- --- + * Functions in plsql_packages.c + * --- --- + */ +extern "C" { +Datum regexp_substr(PG_FUNCTION_ARGS); +Datum intervaltonum(PG_FUNCTION_ARGS); +Datum rawtohex(PG_FUNCTION_ARGS); +Datum report_application_error(PG_FUNCTION_ARGS); +} + +extern THR_LOCAL PLpgSQL_execstate* plpgsql_estate; + +/* ---------- + * Functions in pl_exec.c + * ---------- + */ +extern Datum plpgsql_exec_function(PLpgSQL_function* func, FunctionCallInfo fcinfo, bool dynexec_anonymous_block); +extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function* func, TriggerData* trigdata); +extern void plpgsql_xact_cb(XactEvent event, void* arg); +extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void* arg); +extern Oid exec_get_datum_type(PLpgSQL_execstate* estate, PLpgSQL_datum* datum); +extern void exec_get_datum_type_info(PLpgSQL_execstate* estate, PLpgSQL_datum* datum, Oid* typid, int32* typmod, + Oid* collation, PLpgSQL_function* func = NULL); +extern Datum exec_simple_cast_datum( + PLpgSQL_execstate* estate, Datum value, Oid valtype, Oid reqtype, int32 reqtypmod, bool isnull); +extern void ResetCursorOption(Portal portal, bool reset); +extern void exec_assign_value(PLpgSQL_execstate *estate, + PLpgSQL_datum *target, + Datum value, Oid valtype, bool *isNull); +extern void exec_eval_datum(PLpgSQL_execstate *estate, + PLpgSQL_datum *datum, + Oid *typeId, + int32 *typetypmod, + Datum *value, + bool *isnull, + bool isretry); +extern void exec_eval_cleanup(PLpgSQL_execstate *estate); +/* ---------- + * Functions for namespace handling in pl_funcs.c + * ---------- + */ +extern void plpgsql_ns_init(void); +extern void plpgsql_ns_push(const char* label); +extern void plpgsql_ns_pop(void); +extern PLpgSQL_nsitem* plpgsql_ns_top(void); +extern void plpgsql_ns_additem(int itemtype, int itemno, const char* name); +extern PLpgSQL_nsitem* plpgsql_ns_lookup( + PLpgSQL_nsitem* ns_cur, bool localmode, const char* name1, const char* name2, const char* name3, int* names_used); +extern PLpgSQL_nsitem* plpgsql_ns_lookup_label(PLpgSQL_nsitem* ns_cur, const char* name); + +/* ---------- + * Other functions in pl_funcs.c + * ---------- + */ +extern const char* plpgsql_stmt_typename(PLpgSQL_stmt* stmt); +extern const char* plpgsql_getdiag_kindname(int kind); +extern void plpgsql_free_function_memory(PLpgSQL_function* func); +extern void plpgsql_dumptree(PLpgSQL_function* func); +extern bool plpgsql_is_trigger_shippable(PLpgSQL_function* func); + +/* ---------- + * Scanner functions in pl_scanner.c + * ---------- + */ +extern int plpgsql_base_yylex(void); +extern int plpgsql_yylex(void); +extern void plpgsql_push_back_token(int token); +extern void plpgsql_append_source_text(StringInfo buf, int startlocation, int endlocation); +extern void plpgsql_peek2(int* tok1_p, int* tok2_p, int* tok1_loc, int* tok2_loc); +extern int plpgsql_scanner_errposition(int location); +extern void plpgsql_yyerror(const char* message); +extern int plpgsql_location_to_lineno(int location); +extern int plpgsql_latest_lineno(void); +extern void plpgsql_scanner_init(const char* str); +extern void plpgsql_scanner_finish(void); + +/* ---------- + * Externs in gram.y + * ---------- + */ +extern int plpgsql_yyparse(void); +extern bool plpgsql_is_token_match2(int token, int token_next); +extern bool plpgsql_is_token_match(int token); + +#endif /* PLPGSQL_H */ diff -uprN postgresql-hll-2.14_old/include/utils/portal.h postgresql-hll-2.14/include/utils/portal.h --- postgresql-hll-2.14_old/include/utils/portal.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/portal.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,236 @@ +/* ------------------------------------------------------------------------- + * + * portal.h + * POSTGRES portal definitions. + * + * A portal is an abstraction which represents the execution state of + * a running or runnable query. Portals support both SQL-level CURSORs + * and protocol-level portals. + * + * Scrolling (nonsequential access) and suspension of execution are allowed + * only for portals that contain a single SELECT-type query. We do not want + * to let the client suspend an update-type query partway through! Because + * the query rewriter does not allow arbitrary ON SELECT rewrite rules, + * only queries that were originally update-type could produce multiple + * plan trees; so the restriction to a single query is not a problem + * in practice. + * + * For SQL cursors, we support three kinds of scroll behavior: + * + * (1) Neither NO SCROLL nor SCROLL was specified: to remain backward + * compatible, we allow backward fetches here, unless it would + * impose additional runtime overhead to do so. + * + * (2) NO SCROLL was specified: don't allow any backward fetches. + * + * (3) SCROLL was specified: allow all kinds of backward fetches, even + * if we need to take a performance hit to do so. (The planner sticks + * a Materialize node atop the query plan if needed.) + * + * Case #1 is converted to #2 or #3 by looking at the query itself and + * determining if scrollability can be supported without additional + * overhead. + * + * Protocol-level portals have no nonsequential-fetch API and so the + * distinction doesn't matter for them. They are always initialized + * to look like NO SCROLL cursors. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/portal.h + * + * ------------------------------------------------------------------------- + */ +#ifndef PORTAL_H +#define PORTAL_H + +#include "datatype/timestamp.h" +#include "executor/execdesc.h" +#include "utils/resowner.h" + +/* + * We have several execution strategies for Portals, depending on what + * query or queries are to be executed. (Note: in all cases, a Portal + * executes just a single source-SQL query, and thus produces just a + * single result from the user's viewpoint. However, the rule rewriter + * may expand the single source query to zero or many actual queries.) + * + * PORTAL_ONE_SELECT: the portal contains one single SELECT query. We run + * the Executor incrementally as results are demanded. This strategy also + * supports holdable cursors (the Executor results can be dumped into a + * tuplestore for access after transaction completion). + * + * PORTAL_ONE_RETURNING: the portal contains a single INSERT/UPDATE/DELETE + * query with a RETURNING clause (plus possibly auxiliary queries added by + * rule rewriting). On first execution, we run the portal to completion + * and dump the primary query's results into the portal tuplestore; the + * results are then returned to the client as demanded. (We can't support + * suspension of the query partway through, because the AFTER TRIGGER code + * can't cope, and also because we don't want to risk failing to execute + * all the auxiliary queries.) + * + * PORTAL_ONE_MOD_WITH: the portal contains one single SELECT query, but + * it has data-modifying CTEs. This is currently treated the same as the + * PORTAL_ONE_RETURNING case because of the possibility of needing to fire + * triggers. It may act more like PORTAL_ONE_SELECT in future. + * + * PORTAL_UTIL_SELECT: the portal contains a utility statement that returns + * a SELECT-like result (for example, EXPLAIN or SHOW). On first execution, + * we run the statement and dump its results into the portal tuplestore; + * the results are then returned to the client as demanded. + * + * PORTAL_MULTI_QUERY: all other cases. Here, we do not support partial + * execution: the portal's queries will be run to completion on first call. + */ + +/* the four attributes are defined in params.h: CURSOR_ISOPEN, CURSOR_FOUND, CURSOR_NOTFOUND, CURSOR_ROWCOUNT */ +#define CURSOR_ATTRIBUTE_NUMBER 4 + +typedef enum PortalStrategy { + PORTAL_ONE_SELECT, + PORTAL_ONE_RETURNING, + PORTAL_ONE_MOD_WITH, + PORTAL_UTIL_SELECT, + PORTAL_MULTI_QUERY +} PortalStrategy; + +/* + * A portal is always in one of these states. It is possible to transit + * from ACTIVE back to READY if the query is not run to completion; + * otherwise we never back up in status. + */ +typedef enum PortalStatus { + PORTAL_NEW, /* freshly created */ + PORTAL_DEFINED, /* PortalDefineQuery done */ + PORTAL_READY, /* PortalStart complete, can run it */ + PORTAL_ACTIVE, /* portal is running (can't delete it) */ + PORTAL_DONE, /* portal is finished (don't re-run it) */ + PORTAL_FAILED /* portal got error (can't re-run it) */ +} PortalStatus; + +typedef struct PortalData* Portal; + +typedef struct PortalData { + /* Bookkeeping data */ + const char* name; /* portal's name */ + const char* prepStmtName; /* source prepared statement (NULL if none) */ + MemoryContext heap; /* subsidiary memory for portal */ + ResourceOwner resowner; /* resources owned by portal */ + void (*cleanup)(Portal portal); /* cleanup hook */ + + /* + * State data for remembering which subtransaction(s) the portal was + * created or used in. If the portal is held over from a previous + * transaction, both subxids are InvalidSubTransactionId. Otherwise, + * createSubid is the creating subxact and activeSubid is the last subxact + * in which we ran the portal. + */ + SubTransactionId createSubid; /* the creating subxact */ + SubTransactionId activeSubid; /* the last subxact with activity */ + + /* The query or queries the portal will execute */ + const char* sourceText; /* text of query (as of 8.4, never NULL) */ + const char* commandTag; /* command tag for original query */ + List* stmts; /* PlannedStmts and/or utility statements */ + CachedPlan* cplan; /* CachedPlan, if stmts are from one */ + + ParamListInfo portalParams; /* params to pass to query */ + + /* Features/options */ + PortalStrategy strategy; /* see above */ + int cursorOptions; /* DECLARE CURSOR option bits */ + + /* Status data */ + PortalStatus status; /* see above */ + bool portalPinned; /* a pinned portal can't be dropped */ + bool autoHeld; /* was automatically converted from pinned to + * held (see HoldPinnedPortals()) */ + + /* If not NULL, Executor is active; call ExecutorEnd eventually: */ + QueryDesc* queryDesc; /* info needed for executor invocation */ + + TableScanDesc scanDesc; // info needed for reducing memory allocation + // when reusing the portal for too many times + //(e.g., FETCH/MOVE cursor in a loop) + + /* If portal returns tuples, this is their tupdesc: */ + TupleDesc tupDesc; /* descriptor for result tuples */ + /* and these are the format codes to use for the columns: */ + int16* formats; /* a format code for each column */ + + /* + * Where we store tuples for a held cursor or a PORTAL_ONE_RETURNING or + * PORTAL_UTIL_SELECT query. (A cursor held past the end of its + * transaction no longer has any active executor state.) + */ + Tuplestorestate* holdStore; /* store for holdable cursors */ + MemoryContext holdContext; /* memory containing holdStore */ + + /* + * atStart, atEnd and portalPos indicate the current cursor position. + * portalPos is zero before the first row, N after fetching N'th row of + * query. After we run off the end, portalPos = # of rows in query, and + * atEnd is true. If portalPos overflows, set posOverflow (this causes us + * to stop relying on its value for navigation). Note that atStart + * implies portalPos == 0, but not the reverse (portalPos could have + * overflowed). + */ + bool atStart; + bool atEnd; + bool posOverflow; + long portalPos; + + /* Presentation data, primarily used by the pg_cursors system view */ + TimestampTz creation_time; /* time at which this portal was defined */ + bool visible; /* include this portal in pg_cursors? */ + /* Data used by workload manager. */ + int stmtMemCost; /* Estimate of memory usage from the plan */ + void* cursorAttribute[CURSOR_ATTRIBUTE_NUMBER]; + Oid funcOid; /* function oid */ + int funcUseCount; + bool is_from_spi; +} PortalData; + +/* + * PortalIsValid + * True iff portal is valid. + */ +#define PortalIsValid(p) PointerIsValid(p) + +/* + * Access macros for Portal ... use these in preference to field access. + */ +#define PortalGetQueryDesc(portal) ((portal)->queryDesc) +#define PortalGetHeapMemory(portal) ((portal)->heap) +#define PortalGetPrimaryStmt(portal) PortalListGetPrimaryStmt((portal)->stmts) + +/* Prototypes for functions in utils/mmgr/portalmem.c */ +extern void EnablePortalManager(void); +extern bool PreCommit_Portals(bool isPrepare = true, bool STP_commit = false); +extern void AtAbort_Portals(bool STP_rollback = false); +extern void AtCleanup_Portals(void); +extern void PortalErrorCleanup(void); +extern void AtSubCommit_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner parentXactOwner); +extern void AtSubAbort_Portals( + SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner); +extern void AtSubCleanup_Portals(SubTransactionId mySubid); +extern Portal CreatePortal(const char* name, bool allowDup, bool dupSilent, bool is_from_spi = false); +extern Portal CreateNewPortal(bool is_from_spi = false); +extern void PinPortal(Portal portal); +extern void UnpinPortal(Portal portal); +extern void MarkPortalActive(Portal portal); +extern void MarkPortalDone(Portal portal); +extern void MarkPortalFailed(Portal portal); +extern void PortalDrop(Portal portal, bool isTopCommit); +extern Portal GetPortalByName(const char* name); +extern void PortalDefineQuery(Portal portal, const char* prepStmtName, const char* sourceText, const char* commandTag, + List* stmts, CachedPlan* cplan); +extern Node* PortalListGetPrimaryStmt(List* stmts); +extern void PortalCreateHoldStore(Portal portal); +extern void PortalHashTableDeleteAll(void); +extern bool ThereAreNoReadyPortals(void); +extern void ResetPortalCursor(SubTransactionId mySubid, Oid funOid, int funUseCount); +extern void HoldPinnedPortals(void); +#endif /* PORTAL_H */ diff -uprN postgresql-hll-2.14_old/include/utils/postinit.h postgresql-hll-2.14/include/utils/postinit.h --- postgresql-hll-2.14_old/include/utils/postinit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/postinit.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,179 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * postinit.h + * init postgres thread. + * + * + * IDENTIFICATION + * src/include/utils/postinit.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef UTILS_POSTINIT_H +#define UTILS_POSTINIT_H + +#define PGAUDIT_MAXLENGTH 1024 + +/* -------------------------------- + * POSTGRES Initialize POSTGRES. + * + * The database can be specified by name, using the in_dbname parameter, or by + * OID, using the dboid parameter. In the latter case, the actual database + * name can be returned to the caller in out_dbname. If out_dbname isn't + * NULL, it must point to a buffer of size NAMEDATALEN. + * + * In bootstrap mode no parameters are used. The autovacuum launcher process + * doesn't use any parameters either, because it only goes far enough to be + * able to read pg_database; it doesn't connect to any particular database. + * In walsender mode only username is used. + * + * We expect InitProcess() was already called, so we already have a PGPROC struct ... + * but it's not completely filled in yet. + * + * Note: + * Be very careful with the order of calls in the InitPostgres function. + * -------------------------------- + */ + +class PostgresInitializer : public BaseObject { +public: + PostgresInitializer(); + + ~PostgresInitializer(); + + void SetDatabaseAndUser(const char* in_dbname, Oid dboid, const char* username); + + void GetDatabaseName(char* out_dbname); + + void InitBootstrap(); + + void InitJobScheduler(); + + void InitJobExecuteWorker(); + + void InitSnapshotWorker(); + + void InitAspWorker(); + + void InitStatementWorker(); + + void InitPercentileWorker(); + + void InitAutoVacLauncher(); + + void InitAutoVacWorker(); + + void InitCsnminSync(); + + void InitCatchupWorker(); + + void InitStreamWorker(); + + void InitBackendWorker(); + + void InitWLM(); + + void InitWAL(); + + void InitSession(); + + void InitStreamingBackend(); + + void InitCompactionWorker(); + + void InitCompactionWorkerSwitchSession(); + + void InitStreamSession(); + +public: + const char* m_indbname; + + Oid m_dboid; + + const char* m_username; + +private: + void InitThread(); + + void InitSysCache(); + + void SetProcessExitCallback(); + + void StartXact(); + + void CheckAuthentication(); + + void SetSuperUserStandalone(); + + void SetSuperUserAndDatabase(); + + void CheckAtLeastOneRoles(); + + void InitUser(); + + void CheckConnPermission(); + + void CheckConnPermissionInShutDown(); + + void CheckConnPermissionInBinaryUpgrade(); + + void CheckConnLimitation(); + + void InitPlainWalSender(); + + void SetDefaultDatabase(); + + void SetDatabase(); + + void SetDatabaseByName(); + + void SetDatabaseByOid(); + + void LockDatabase(); + + void RecheckDatabaseExists(); + + void SetDatabasePath(); + + void LoadSysCache(); + + void ProcessStartupOpt(); + + void InitDatabase(); + + void InitPGXCPort(); + + void InitSettings(); + + void FinishInit(); + + void AuditUserLogin(); + + void InitCompactionThread(); + +private: + bool m_isSuperUser; + + char m_dbname[NAMEDATALEN]; + + char m_details[PGAUDIT_MAXLENGTH]; + + char* m_fullpath; +}; + +void ShutdownPostgres(int code, Datum arg); + +#endif /* UTILS_POSTINIT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/probes.h postgresql-hll-2.14/include/utils/probes.h --- postgresql-hll-2.14_old/include/utils/probes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/probes.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,118 @@ +#define TRACE_POSTGRESQL_TRANSACTION_START(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_START_ENABLED() (0) +#define TRACE_POSTGRESQL_TRANSACTION_COMMIT(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_COMMIT_ENABLED() (0) +#define TRACE_POSTGRESQL_TRANSACTION_ABORT(INT1) +#define TRACE_POSTGRESQL_TRANSACTION_ABORT_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_ACQUIRE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_ACQUIRE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_RELEASE(INT1) +#define TRACE_POSTGRESQL_LWLOCK_RELEASE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_START(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_DONE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_CONDACQUIRE_FAIL_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_ENABLED() (0) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_FAIL(INT1, INT2) +#define TRACE_POSTGRESQL_LWLOCK_WAIT_UNTIL_FREE_FAIL_ENABLED() (0) +#define TRACE_POSTGRESQL_LOCK_WAIT_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_LOCK_WAIT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_LOCK_WAIT_DONE(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_LOCK_WAIT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PARSE_START(INT1) +#define TRACE_POSTGRESQL_QUERY_PARSE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PARSE_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_PARSE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_REWRITE_START(INT1) +#define TRACE_POSTGRESQL_QUERY_REWRITE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_REWRITE_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_REWRITE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PLAN_START() +#define TRACE_POSTGRESQL_QUERY_PLAN_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_PLAN_DONE() +#define TRACE_POSTGRESQL_QUERY_PLAN_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_EXECUTE_START() +#define TRACE_POSTGRESQL_QUERY_EXECUTE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_EXECUTE_DONE() +#define TRACE_POSTGRESQL_QUERY_EXECUTE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_START(INT1) +#define TRACE_POSTGRESQL_QUERY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_QUERY_DONE(INT1) +#define TRACE_POSTGRESQL_QUERY_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_STATEMENT_STATUS(INT1) +#define TRACE_POSTGRESQL_STATEMENT_STATUS_ENABLED() (0) +#define TRACE_POSTGRESQL_SORT_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_SORT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SORT_DONE(INT1, INT2) +#define TRACE_POSTGRESQL_SORT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_READ_START(INT1, INT2, INT3, INT4, INT5, INT6, INT7) +#define TRACE_POSTGRESQL_BUFFER_READ_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_READ_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_BUFFER_READ_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_FLUSH_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_SYNC_START() +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_SYNC_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_DONE() +#define TRACE_POSTGRESQL_BUFFER_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_START(INT1, INT2) +#define TRACE_POSTGRESQL_BUFFER_SYNC_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN(INT1) +#define TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_SYNC_DONE(INT1, INT2, INT3) +#define TRACE_POSTGRESQL_BUFFER_SYNC_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_START(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_BUFFER_WRITE_DIRTY_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_DEADLOCK_FOUND() +#define TRACE_POSTGRESQL_DEADLOCK_FOUND_ENABLED() (0) +#define TRACE_POSTGRESQL_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CHECKPOINT_DONE(INT1, INT2, INT3, INT4, INT5) +#define TRACE_POSTGRESQL_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_CSNLOG_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_START(INT1) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_DONE(INT1) +#define TRACE_POSTGRESQL_MULTIXACT_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_START() +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_START_ENABLED() (0) +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_DONE() +#define TRACE_POSTGRESQL_TWOPHASE_CHECKPOINT_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_READ_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_SMGR_MD_READ_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_READ_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_SMGR_MD_READ_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_START(INT1, INT2, INT3, INT4, INT5, INT6) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_START_ENABLED() (0) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_DONE(INT1, INT2, INT3, INT4, INT5, INT6, INT7, INT8) +#define TRACE_POSTGRESQL_SMGR_MD_WRITE_DONE_ENABLED() (0) +#define TRACE_POSTGRESQL_XLOG_INSERT(INT1, INT2) +#define TRACE_POSTGRESQL_XLOG_INSERT_ENABLED() (0) +#define TRACE_POSTGRESQL_XLOG_SWITCH() +#define TRACE_POSTGRESQL_XLOG_SWITCH_ENABLED() (0) +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_START() +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_START_ENABLED() (0) +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_DONE() +#define TRACE_POSTGRESQL_WAL_BUFFER_WRITE_DIRTY_DONE_ENABLED() (0) diff -uprN postgresql-hll-2.14_old/include/utils/ps_status.h postgresql-hll-2.14/include/utils/ps_status.h --- postgresql-hll-2.14_old/include/utils/ps_status.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/ps_status.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- + * + * ps_status.h + * + * Declarations for backend/utils/misc/ps_status.c + * + * src/include/utils/ps_status.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef PS_STATUS_H +#define PS_STATUS_H + +extern char** save_ps_display_args(int argc, char** argv); + +extern void init_ps_display(const char* username, const char* dbname, const char* host_info, const char* initial_str); + +extern void set_ps_display(const char* activity, bool force); + +extern const char* get_ps_display(int* displen); + +#endif /* PS_STATUS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/rangetypes.h postgresql-hll-2.14/include/utils/rangetypes.h --- postgresql-hll-2.14_old/include/utils/rangetypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/rangetypes.h 2020-12-12 17:06:43.403350051 +0800 @@ -0,0 +1,177 @@ +/* ------------------------------------------------------------------------- + * + * rangetypes.h + * Declarations for Postgres range types. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/rangetypes.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RANGETYPES_H +#define RANGETYPES_H + +#include "utils/typcache.h" + +/* + * Ranges are varlena objects, so must meet the varlena convention that + * the first int32 of the object contains the total object size in bytes. + * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though! + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + Oid rangetypid; /* range type's own OID */ + /* Following the OID are zero to two bound values, then a flags byte */ +} RangeType; + +/* Use this macro in preference to fetching rangetypid field directly */ +#define RangeTypeGetOid(r) ((r)->rangetypid) + +/* A range's flags byte contains these bits: */ +#define RANGE_EMPTY 0x01 /* range is empty */ +#define RANGE_LB_INC 0x02 /* lower bound is inclusive */ +#define RANGE_UB_INC 0x04 /* upper bound is inclusive */ +#define RANGE_LB_INF 0x08 /* lower bound is -infinity */ +#define RANGE_UB_INF 0x10 /* upper bound is +infinity */ +#define RANGE_LB_NULL 0x20 /* lower bound is null (NOT USED) */ +#define RANGE_UB_NULL 0x40 /* upper bound is null (NOT USED) */ +#define RANGE_CONTAIN_EMPTY \ + 0x80 /* marks a GiST internal-page entry whose \ + * subtree contains some empty ranges */ + +#define RANGE_HAS_LBOUND(flags) (!((flags) & (RANGE_EMPTY | RANGE_LB_NULL | RANGE_LB_INF))) + +#define RANGE_HAS_UBOUND(flags) (!((flags) & (RANGE_EMPTY | RANGE_UB_NULL | RANGE_UB_INF))) + +#define RangeIsEmpty(r) (((unsigned int)range_get_flags(r) & RANGE_EMPTY) != 0) +#define RangeIsOrContainsEmpty(r) (((unsigned int)range_get_flags(r) & (RANGE_EMPTY | RANGE_CONTAIN_EMPTY)) != 0) + +/* Internal representation of either bound of a range (not what's on disk) */ +typedef struct { + Datum val; /* the bound value, if any */ + bool infinite; /* bound is +/- infinity */ + bool inclusive; /* bound is inclusive (vs exclusive) */ + bool lower; /* this is the lower (vs upper) bound */ +} RangeBound; + +/* + * fmgr macros for range type objects + */ +#define DatumGetRangeType(X) ((RangeType*)PG_DETOAST_DATUM(X)) +#define DatumGetRangeTypeCopy(X) ((RangeType*)PG_DETOAST_DATUM_COPY(X)) +#define RangeTypeGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_RANGE(n) DatumGetRangeType(PG_GETARG_DATUM(n)) +#define PG_GETARG_RANGE_COPY(n) DatumGetRangeTypeCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_RANGE(x) return RangeTypeGetDatum(x) + +/* + * prototypes for functions defined in rangetypes.c + */ + +/* I/O */ +extern Datum range_in(PG_FUNCTION_ARGS); +extern Datum range_out(PG_FUNCTION_ARGS); +extern Datum range_recv(PG_FUNCTION_ARGS); +extern Datum range_send(PG_FUNCTION_ARGS); + +/* constructors */ +extern Datum range_constructor2(PG_FUNCTION_ARGS); +extern Datum range_constructor3(PG_FUNCTION_ARGS); + +/* range -> subtype */ +extern Datum range_lower(PG_FUNCTION_ARGS); +extern Datum range_upper(PG_FUNCTION_ARGS); + +/* range -> bool */ +extern Datum range_empty(PG_FUNCTION_ARGS); +extern Datum range_lower_inc(PG_FUNCTION_ARGS); +extern Datum range_upper_inc(PG_FUNCTION_ARGS); +extern Datum range_lower_inf(PG_FUNCTION_ARGS); +extern Datum range_upper_inf(PG_FUNCTION_ARGS); + +/* range, element -> bool */ +extern Datum range_contains_elem(PG_FUNCTION_ARGS); +extern Datum elem_contained_by_range(PG_FUNCTION_ARGS); + +extern bool range_contains_elem_internal(TypeCacheEntry* typcache, RangeType* r, Datum val); + +/* range, range -> bool */ +extern Datum range_eq(PG_FUNCTION_ARGS); +extern Datum range_ne(PG_FUNCTION_ARGS); +extern Datum range_contains(PG_FUNCTION_ARGS); +extern Datum range_contained_by(PG_FUNCTION_ARGS); +extern Datum range_before(PG_FUNCTION_ARGS); +extern Datum range_after(PG_FUNCTION_ARGS); +extern Datum range_adjacent(PG_FUNCTION_ARGS); +extern Datum range_overlaps(PG_FUNCTION_ARGS); +extern Datum range_overleft(PG_FUNCTION_ARGS); +extern Datum range_overright(PG_FUNCTION_ARGS); + +/* internal versions of the above */ +extern bool range_eq_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_ne_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_contains_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_contained_by_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_before_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_after_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_adjacent_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overlaps_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overleft_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); +extern bool range_overright_internal(TypeCacheEntry* typcache, RangeType* r1, RangeType* r2); + +/* range, range -> range */ +extern Datum range_minus(PG_FUNCTION_ARGS); +extern Datum range_union(PG_FUNCTION_ARGS); +extern Datum range_intersect(PG_FUNCTION_ARGS); + +/* BTree support */ +extern Datum range_cmp(PG_FUNCTION_ARGS); +extern Datum range_lt(PG_FUNCTION_ARGS); +extern Datum range_le(PG_FUNCTION_ARGS); +extern Datum range_ge(PG_FUNCTION_ARGS); +extern Datum range_gt(PG_FUNCTION_ARGS); + +/* Hash support */ +extern Datum hash_range(PG_FUNCTION_ARGS); + +/* ANALYZE support */ +extern Datum range_typanalyze(PG_FUNCTION_ARGS); + +/* Canonical functions */ +extern Datum int4range_canonical(PG_FUNCTION_ARGS); +extern Datum int8range_canonical(PG_FUNCTION_ARGS); +extern Datum daterange_canonical(PG_FUNCTION_ARGS); + +/* Subtype Difference functions */ +extern Datum int4range_subdiff(PG_FUNCTION_ARGS); +extern Datum int8range_subdiff(PG_FUNCTION_ARGS); +extern Datum numrange_subdiff(PG_FUNCTION_ARGS); +extern Datum daterange_subdiff(PG_FUNCTION_ARGS); +extern Datum tsrange_subdiff(PG_FUNCTION_ARGS); +extern Datum tstzrange_subdiff(PG_FUNCTION_ARGS); + +/* assorted support functions */ +extern TypeCacheEntry* range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid); +extern RangeType* range_serialize(TypeCacheEntry* typcache, RangeBound* lower, RangeBound* upper, bool empty); +extern void range_deserialize( + TypeCacheEntry* typcache, RangeType* range, RangeBound* lower, RangeBound* upper, bool* empty); +extern char range_get_flags(RangeType* range); +extern void range_set_contain_empty(RangeType* range); +extern RangeType* make_range(TypeCacheEntry* typcache, RangeBound* lower, RangeBound* upper, bool empty); +extern int range_cmp_bounds(TypeCacheEntry* typcache, RangeBound* b1, RangeBound* b2); +extern int range_cmp_bound_values(TypeCacheEntry* typcache, RangeBound* b1, RangeBound* b2); +extern RangeType* make_empty_range(TypeCacheEntry* typcache); + +/* GiST support (in rangetypes_gist.c) */ +extern Datum range_gist_consistent(PG_FUNCTION_ARGS); +extern Datum range_gist_compress(PG_FUNCTION_ARGS); +extern Datum range_gist_decompress(PG_FUNCTION_ARGS); +extern Datum range_gist_union(PG_FUNCTION_ARGS); +extern Datum range_gist_penalty(PG_FUNCTION_ARGS); +extern Datum range_gist_picksplit(PG_FUNCTION_ARGS); +extern Datum range_gist_same(PG_FUNCTION_ARGS); + +#endif /* RANGETYPES_H */ diff -uprN postgresql-hll-2.14_old/include/utils/rbtree.h postgresql-hll-2.14/include/utils/rbtree.h --- postgresql-hll-2.14_old/include/utils/rbtree.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/rbtree.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,60 @@ +/* ------------------------------------------------------------------------- + * + * rbtree.h + * interface for PostgreSQL generic Red-Black binary tree package + * + * Copyright (c) 2009-2012, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/include/utils/rbtree.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RBTREE_H +#define RBTREE_H + +/* + * RBNode is intended to be used as the first field of a larger struct, + * whose additional fields carry whatever payload data the caller needs + * for a tree entry. (The total size of that larger struct is passed to + * rb_create.) RBNode is declared here to support this usage, but + * callers must treat it as an opaque struct. + */ +typedef struct RBNode { + char iteratorState; /* workspace for iterating through tree */ + char color; /* node's current color, red or black */ + struct RBNode* left; /* left child, or RBNIL if none */ + struct RBNode* right; /* right child, or RBNIL if none */ + struct RBNode* parent; /* parent, or NULL (not RBNIL!) if none */ +} RBNode; + +/* Opaque struct representing a whole tree */ +typedef struct RBTree RBTree; + +/* Available tree iteration orderings */ +typedef enum RBOrderControl { + LeftRightWalk, /* inorder: left child, node, right child */ + RightLeftWalk, /* reverse inorder: right, node, left */ + DirectWalk, /* preorder: node, left child, right child */ + InvertedWalk /* postorder: left child, right child, node */ +} RBOrderControl; + +/* Support functions to be provided by caller */ +typedef int (*rb_comparator)(const RBNode* a, const RBNode* b, void* arg); +typedef void (*rb_combiner)(RBNode* existing, const RBNode* newdata, void* arg); +typedef RBNode* (*rb_allocfunc)(void* arg); +typedef void (*rb_freefunc)(RBNode* x, void* arg); + +extern RBTree* rb_create(Size node_size, rb_comparator comparator, rb_combiner combiner, rb_allocfunc allocfunc, + rb_freefunc freefunc, void* arg); + +extern RBNode* rb_find(RBTree* rb, const RBNode* data); +extern RBNode* rb_leftmost(RBTree* rb); + +extern RBNode* rb_insert(RBTree* rb, const RBNode* data, bool* isNew); +extern void rb_delete(RBTree* rb, RBNode* node); + +extern void rb_begin_iterate(RBTree* rb, RBOrderControl ctrl); +extern RBNode* rb_iterate(RBTree* rb); + +#endif /* RBTREE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/relcache.h postgresql-hll-2.14/include/utils/relcache.h --- postgresql-hll-2.14_old/include/utils/relcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/relcache.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,152 @@ +/* ------------------------------------------------------------------------- + * + * relcache.h + * Relation descriptor cache definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/relcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELCACHE_H +#define RELCACHE_H + +#include "access/tupdesc.h" +#include "nodes/bitmapset.h" +#include "utils/hsearch.h" + +#define IsValidCatalogParam(catalogDesc) (catalogDesc.oid != InvalidOid) + +typedef struct RelationData* Relation; +typedef struct PartitionData* Partition; +struct HeapTupleData; +typedef HeapTupleData* HeapTuple; +typedef int LOCKMODE; + +/* ---------------- + * RelationPtr is used in the executor to support index scans + * where we have to keep track of several index relations in an + * array. -cim 9/10/89 + * ---------------- + */ +typedef Relation* RelationPtr; + +typedef struct CatalogRelationBuildParam { + Oid oid; + const char* relationName; + Oid relationReltype; + bool isshared; + bool hasoids; + int natts; + const FormData_pg_attribute* attrs; + bool isnailed; + bool insertIt; +} CatalogRelationBuildParam; + +/* + * Routines to open (lookup) and close a relcache entry + */ +extern Relation RelationIdGetRelation(Oid relationId); +extern void RelationClose(Relation relation); + +/* + * Routines to compute/retrieve additional cached information + */ +extern List* PartitionGetPartIndexList(Partition part); +extern List* RelationGetIndexList(Relation relation); +extern List* RelationGetSpecificKindIndexList(Relation relation, bool isGlobal); +extern List* RelationGetIndexInfoList(Relation relation); +extern int RelationGetIndexNum(Relation relation); +extern Oid RelationGetOidIndex(Relation relation); +extern Oid RelationGetReplicaIndex(Relation relation); +extern List* RelationGetIndexExpressions(Relation relation); +extern List* RelationGetIndexExpressions(Relation relation); +extern List* RelationGetDummyIndexExpressions(Relation relation); +extern List* RelationGetIndexPredicate(Relation relation); + +typedef enum IndexAttrBitmapKind { + INDEX_ATTR_BITMAP_ALL, + INDEX_ATTR_BITMAP_KEY, + INDEX_ATTR_BITMAP_IDENTITY_KEY +} IndexAttrBitmapKind; + +typedef enum PartitionMetadataStatus { + PART_METADATA_NOEXIST, /* partition is not exists */ + PART_METADATA_LIVE, /* partition is live, normal use */ + PART_METADATA_CREATING, /* partition is being created */ + PART_METADATA_INVISIBLE /* partition is invisible, being droped */ +} PartStatus; + +extern Bitmapset* RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind keyAttrs); + +extern void RelationGetExclusionInfo(Relation indexRelation, Oid** operators, Oid** procs, uint16** strategies); + +extern void RelationSetIndexList(Relation relation, List* indexIds, Oid oidIndex); + +extern void RelationInitIndexAccessInfo(Relation relation, HeapTuple index_tuple = NULL); + +/* + * Routines for backend startup + */ +extern void RelationCacheInitialize(void); +extern void RelationCacheInitializePhase2(void); +extern void RelationCacheInitializePhase3(void); + +/* + * Routine to create a relcache entry for an about-to-be-created relation + */ +extern Relation RelationBuildLocalRelation(const char* relname, Oid relnamespace, TupleDesc tupDesc, Oid relid, + Oid relfilenode, Oid reltablespace, bool shared_relation, bool mapped_relation, char relpersistence, char relkind, + int8 row_compress, TableAmType tam_type); + +/* + * Routine to manage assignment of new relfilenode to a relation + */ +extern void DescTableSetNewRelfilenode(Oid relid, TransactionId freezeXid, bool partition); +extern void DeltaTableSetNewRelfilenode(Oid relid, TransactionId freezeXid, bool partition); +extern void RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid, bool isDfsTruncate = false); + +/* + * Routines for flushing/rebuilding relcache entries in various scenarios + */ +extern void RelationForgetRelation(Oid rid); + +extern void RelationCacheInvalidateEntry(Oid relationId); + +extern void RelationCacheInvalidate(void); + +extern void RelationCacheInvalidateBuckets(); + +extern void RelationCloseSmgrByOid(Oid relationId); +extern Oid RelationGetBucketOid(Relation relation); + +extern void AtEOXact_RelationCache(bool isCommit); +extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid); + +/* + * Routines to help manage rebuilding of relcache init files + */ +extern bool RelationIdIsInInitFile(Oid relationId); +extern void RelationCacheInitFilePreInvalidate(void); +extern void RelationCacheInitFilePostInvalidate(void); +extern void RelationCacheInitFileRemove(void); + +extern TupleDesc BuildHardcodedDescriptor(int natts, const FormData_pg_attribute* attrs, bool hasoids); +extern TupleDesc GetDefaultPgClassDesc(void); +extern TupleDesc GetDefaultPgIndexDesc(void); + +extern bool CheckRelationInRedistribution(Oid rel_oid); + +extern CatalogRelationBuildParam GetCatalogParam(Oid id); + +extern HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_historic); + +/* + * this function is used for timeseries database, do not call this function directly!!! + */ +extern Relation tuple_get_rel(HeapTuple pg_class_tuple, LOCKMODE lockmode, TupleDesc tuple_desc, HeapTuple pg_indextuple = NULL); +extern THR_LOCAL bool needNewLocalCacheFile; +#endif /* RELCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/relfilenodemap.h postgresql-hll-2.14/include/utils/relfilenodemap.h --- postgresql-hll-2.14_old/include/utils/relfilenodemap.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/relfilenodemap.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,20 @@ +/* --------------------------------------------------------------------------------------- + * + * relfilenodemap.h + * relfilenode to oid mapping cache. + * + * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/relfilenodemap.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef RELFILENODEMAP_H +#define RELFILENODEMAP_H + +extern Oid RelidByRelfilenode(Oid reltablespace, Oid relfilenode); +extern Oid PartitionRelidByRelfilenode(Oid reltablespace, Oid relfilenode, Oid& partationReltoastrelid); + +#endif /* RELFILENODEMAP_H */ diff -uprN postgresql-hll-2.14_old/include/utils/rel_gs.h postgresql-hll-2.14/include/utils/rel_gs.h --- postgresql-hll-2.14_old/include/utils/rel_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/rel_gs.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,701 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rel_gs.h + * POSTGRES relation descriptor (a/k/a relcache entry) definitions. + * + * + * IDENTIFICATION + * src/include/utils/rel_gs.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef REL_GS_H +#define REL_GS_H + +/* + * Relation Compression Type + * REL_CMPRS_NOT_SUPPORT: + * relation doesn't support compression. That means these relations have constant + * commpression attr. 'ALTER TABLE ... SET COMPRESS/UNCOMPRESS' mustn't applies + * to these relations. For examples, system relations, index, etc. + * REL_CMPRS_PAGE_PLAIN: + * relation support compression with 'CREATE/ALTER TABLE ... [SET] COMPRESS/UNCOMPRESS' clause. + * Under this condition, all the data in this relation are stored in plain format. + * REL_CMPRS_PAGE_DICT: + * relation support compression with 'CREATE/ALTER TABLE ... [SET] COMPRESS/UNCOMPRESS' clause. + * Under this condition, many tuples of one page in this relation are stored after compressing. + * REL_CMPRS_MAX_TYPE: + * The other types must be defined above this value. + */ +typedef enum { + REL_CMPRS_NOT_SUPPORT = 0, + REL_CMPRS_PAGE_PLAIN, + REL_CMPRS_FIELDS_EXTRACT, + REL_CMPRS_MAX_TYPE +} RelCompressType; + +#ifndef FRONTEND_PARSER +#include "catalog/pg_partition.h" +#include "catalog/pg_hashbucket.h" +#include "catalog/catalog.h" +#include "catalog/pg_namespace.h" +#include "utils/partitionmap_gs.h" +#include "rel.h" + +#define CHECK_CMPRS_VALID(compress) ((compress) > REL_CMPRS_NOT_SUPPORT && (compress) < REL_CMPRS_MAX_TYPE) +#define CHECK_CMPRS_NOT_SUPPORT(compress) (REL_CMPRS_NOT_SUPPORT == (compress)) + +typedef struct PartitionData { + RelFileNode pd_node; /* relation physical identifier */ + /* use "struct" here to avoid needing to include smgr.h: */ + struct SMgrRelationData* pd_smgr; /* cached file handle, or NULL */ + int pd_refcnt; /* reference count */ + bool pd_isvalid; /* partcache entry is valid */ + char pd_indexvalid; /* state of pd_indexlist: 0 = not valid, 1 = + * valid, 2 = temporarily forced */ + + /* + * rd_createSubid is the ID of the highest subtransaction the rel has + * survived into; or zero if the rel was not created in the current top + * transaction. This should be relied on only for optimization purposes; + * it is possible for new-ness to be "forgotten" (eg, after CLUSTER). + * Likewise, rd_newRelfilenodeSubid is the ID of the highest + * subtransaction the relfilenode change has survived into, or zero if not + * changed in the current transaction (or we have forgotten changing it). + */ + SubTransactionId pd_createSubid; /* rel was created in current xact */ + SubTransactionId pd_newRelfilenodeSubid; /* new relfilenode assigned in + * current xact */ + + Form_pg_partition pd_part; /* PARTITION tuple */ + Oid pd_id; /* partition's object id */ + List* pd_indexlist; /* list of OIDs of indexes on partition */ + Bitmapset* pd_indexattr; /* identifies columns used in indexes */ + Oid pd_oidindex; /* OID of unique index on OID, if any */ + LockInfoData pd_lockInfo; /* lock mgr's info for locking relation */ /*?*/ + /* + * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new + * version of a table, we need to make any toast pointers inserted into it + * have the existing toast table's OID, not the OID of the transient toast + * table. If rd_toastoid isn't InvalidOid, it is the OID to place in + * toast pointers inserted into this rel. (Note it's set on the new + * version of the main heap, not the toast table itself.) This also + * causes toast_save_datum() to try to preserve toast value OIDs. + */ + Oid pd_toastoid; /* Real TOAST table's OID from pg_partition, or InvalidOid */ + /* use "struct" here to avoid needing to include pgstat.h: */ + bytea* rd_options; /* partition's reloptions */ + struct PgStat_TableStatus* pd_pgstat_info; /* statistics collection area */ + Partition parent; +} PartitionData; + +typedef struct AttrMetaData { + NodeTag type; + + char* attname; /* name of attribute */ + Oid atttypid; + int2 attlen; + int2 attnum; + int4 atttypmod; + bool attbyval; + char attstorage; + char attalign; + bool attnotnull; + bool atthasdef; + bool attisdropped; + bool attislocal; + int1 attkvtype; + int1 attcmprmode; + int4 attinhcount; + Oid attcollation; +} AttrMetaData; + +typedef struct RelationMetaData { + NodeTag type; + + Oid rd_id; /* relation's object id */ + + // RelFileNode rd_node; /* relation physical identifier */ + Oid spcNode; /* tablespace */ + Oid dbNode; /* database */ + Oid relNode; /* relation */ + int4 bucketNode; /* bucket */ + + // Form_pg_class rd_rel; /* RELATION tuple */ + char* relname; /* class name */ + char relkind; /* see RELKIND_xxx constants below */ + char parttype; /* 'p' for partitioned relation, 'n' for non-partitioned relation */ + + // TupleDesc rd_att; /* tuple descriptor */ + int natts; /* number of attributes in the tuple */ + List* attrs; /* the list of AttrMetaData */ +} RelationMetaData; + +#define ORIENTATION_ROW "row" +#define ORIENTATION_COLUMN "column" +#define ORIENTATION_ORC "orc" +#define ORIENTATION_TIMESERIES "timeseries" + +#define TIME_ONE_HOUR "1 HOUR" +#define TIME_ONE_DAY "1 DAY" +#define TIME_ONE_WEEK "1 WEEK" +#define TIME_ONE_MONTH "1 MONTH" +#define TIME_ONE_YEAR "1 YEAR" +#define TIME_UNDEFINED "UNDEFINED" + +#define COLUMN_UNDEFINED "UNDEFINED" + +#define ORC_VERSION_011 "0.11" +#define ORC_VERSION_012 "0.12" + +#define COMPRESSION_NO "no" +#define COMPRESSION_YES "yes" +#define COMPRESSION_LOW "low" +#define COMPRESSION_MIDDLE "middle" +#define COMPRESSION_HIGH "high" +#define COMPRESSION_ZLIB "zlib" +#define COMPRESSION_SNAPPY "snappy" +#define COMPRESSION_LZ4 "lz4" + +/* + * values for different table access method types. + */ +#define TABLE_ACCESS_METHOD_HEAP "HEAP" +#define TABLE_ACCESS_METHOD_USTORE "USTORE" + +#define FILESYSTEM_GENERAL "general" +#define FILESYSTEM_HDFS "hdfs" + +#define OptIgnoreEnableHadoopEnv "ignore_enable_hadoop_env" +#define TS_PSEUDO_DIST_COLUMN "ts_pseudo_distcol" + +#define OptEnabledWaitCleanGpi "y" +#define OptDisabledWaitCleanGpi "n" + +#define INTERNAL_MASK_DISABLE 0x0 +#define INTERNAL_MASK_ENABLE 0x8000 +#define INTERNAL_MASK_DINSERT 0x01 // disable insert +#define INTERNAL_MASK_DDELETE 0x02 // disable delete +#define INTERNAL_MASK_DALTER 0x04 // disable alter +#define INTERNAL_MASK_DSELECT 0x08 // disable select +#define INTERNAL_MASK_DUPDATE 0x0100 // disable update + +#define StdRdOptionsGetStringData(_basePtr, _memberName, _defaultVal) \ + (((_basePtr) && (((StdRdOptions*)(_basePtr))->_memberName)) \ + ? (((char*)(_basePtr) + *(int*)&(((StdRdOptions*)(_basePtr))->_memberName))) \ + : (_defaultVal)) + +/* + * ReltionGetTableAccessMethoType + * Returns the relations TableAmType + */ +#define RelationGetTableAccessMethodType(_reloptions) \ + StdRdOptionsGetStringData(_reloptions, table_access_method, TABLE_ACCESS_METHOD_HEAP) + +#define RelationIsTableAccessMethodHeapType(_reloptions) \ + pg_strcasecmp(RelationGetTableAccessMethodType(_reloptions), TABLE_ACCESS_METHOD_HEAP) == 0 + +#define RelationIsTableAccessMethodUStoreType(_reloptions) \ + pg_strcasecmp(RelationGetTableAccessMethodType(_reloptions), TABLE_ACCESS_METHOD_USTORE) == 0 + + +/* + * @Description: get TableAmType type from Relation's reloptions data. + * @IN reloptions: Table's reloptions. + * @Return: return TableAmType type for this relation. + */ +static inline TableAmType get_tableam_from_reloptions(bytea* reloptions, char relkind) +{ + if (relkind == RELKIND_RELATION) + { + if (reloptions!= NULL) + { + if (RelationIsTableAccessMethodHeapType(reloptions)) + { + return TAM_HEAP; + } + else if (RelationIsTableAccessMethodUStoreType(reloptions)) + { + return TAM_USTORE; + } + + return TAM_HEAP; + } + else //For System Tables reloptions can be NULL. + { + return TAM_HEAP; + } + } + else if (relkind == RELKIND_INDEX || + relkind == RELKIND_TOASTVALUE || + relkind == RELKIND_SEQUENCE || + relkind == RELKIND_COMPOSITE_TYPE || + relkind == RELKIND_VIEW || + relkind == RELKIND_FOREIGN_TABLE) + { + return TAM_HEAP; + } + + return TAM_HEAP; +} + +/* RelationGetOrientation + * Return the relations' orientation + */ +#define RelationGetOrientation(relation) StdRdOptionsGetStringData((relation)->rd_options, orientation, ORIENTATION_ROW) + +#define RaletionGetStoreVersion(relation) StdRdOptionsGetStringData((relation)->rd_options, version, ORC_VERSION_012) + +#define RelationGetFileSystem(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, filesystem, FILESYSTEM_GENERAL) + +#define RelationIsCUFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_COLUMN) == 0) + +#define RelationIsRowFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_ROW) == 0) + +#define RelationIsColumnFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && (RelationIsCUFormat(relation) || RelationIsPAXFormat(relation))) + +#define RelationGetCUDescRelId(r) ((r)->rd_rel->relcudescrelid) +#define RelationGetDeltaRelId(r) ((r)->rd_rel->reldeltarelid) +#define RelationGetRelFileNode(r) ((r)->rd_rel->relfilenode) + +/* + * @Description: get columnar relation's compress level. + * @IN rel: columnar heap relation + * @Return: return user explictly defined compresslevel, + * or return compresslevel zero. + * @See also: + */ +static inline int relation_get_compresslevel(Relation rel) +{ + Assert(rel != NULL); + if ((RELKIND_RELATION == rel->rd_rel->relkind) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->compresslevel; + } + /* Otherwise just return zero */ + return 0; +} + +static inline int RelationGetInternalMask(Relation rel) +{ + /* Now internal mask is only available for ordinary relation */ + if ((RELKIND_RELATION == rel->rd_rel->relkind) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->internalMask; + } else { + return INTERNAL_MASK_DISABLE; + } +} + +#define RelationIsInternal(relation) (RelationGetInternalMask(relation) != INTERNAL_MASK_DISABLE) + +#define RelationIsRelation(relation) (RELKIND_RELATION == (relation)->rd_rel->relkind) + +#define RelationIsMatview(relation) (RELKIND_MATVIEW == (relation)->rd_rel->relkind) + +/* + * Mgr for Redistribute + */ +static inline RedisHtlAction RelationGetAppendMode(Relation rel) +{ + Assert(rel != NULL); + if (RelationIsRelation(rel) && rel->rd_options) { + return ((StdRdOptions*)rel->rd_options)->append_mode_internal; + } + + /* Otherwise just return zero */ + return REDIS_REL_NORMAL; +} + +/* + * RelationIsPAXFormat + * Return the relations' orientation. Pax format includes ORC format. + */ +#define RelationIsPAXFormat(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_ORC) == 0) + +/* RelationIsColStore + * Return relation whether is column store, which includes CU format and PAX format. + */ +#define RelationIsColStore(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && (RelationIsCUFormat(relation) || RelationIsPAXFormat(relation))) + +#define RelationOptionIsDfsStore(optionValue) (optionValue && 0 == pg_strncasecmp(optionValue, HDFS, strlen(HDFS))) + +#define RelationIsTsStore(relation) \ + ((RELKIND_RELATION == relation->rd_rel->relkind) && \ + pg_strcasecmp(RelationGetOrientation(relation), ORIENTATION_TIMESERIES) == 0) + +#define TsRelWithImplDistColumn(attribute, pos) \ + (((attribute)[pos]->attkvtype == ATT_KV_HIDE) && \ + namestrcmp(&((attribute)[pos]->attname), TS_PSEUDO_DIST_COLUMN) == 0) + +// Helper Macro Defination +// +#define StdRelOptGetOrientation(__stdRelOpt) StdRdOptionsGetStringData((__stdRelOpt), orientation, ORIENTATION_ROW) + +#define StdRelOptIsColStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_COLUMN, StdRelOptGetOrientation(__stdRelOpt))) + +#define StdRelOptIsRowStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_ROW, StdRelOptGetOrientation(__stdRelOpt))) + +#define StdRelOptIsTsStore(__stdRelOpt) (0 == pg_strcasecmp(ORIENTATION_TIMESERIES, \ + StdRelOptGetOrientation(__stdRelOpt))) + + +/* get internal_mask option from reloption */ +#define StdRelOptGetInternalMask(__stdRelOpt) StdRdOptionsGetStringData((__stdRelOpt), internalMask, 0) + +// RelationGetCompression +// Return the relation's compression option +// +#define RelationGetCompression(relation) StdRdOptionsGetStringData((relation)->rd_options, compression, COMPRESSION_LOW) + +// make sure that: +// 1. RelDefaultFullCuSize = N * BatchMaxSize +// 2. RelDefaultPartialClusterRows = M * RelDefaultFullCuSize +// +#define RelMaxFullCuSize (60 * BatchMaxSize) +#define RelDefaultFullCuSize RelMaxFullCuSize +#define RelDefaultPartialClusterRows (70 * RelDefaultFullCuSize) +#define RelDefaultDletaRows 100 + +/* the min/max values about compress-level option */ +#define REL_MIN_COMPRESSLEVEL (0) +#define REL_MAX_COMPRESSLEVEL (3) + +#define RelRoundIntOption(_v1, _v2) (AssertMacro((_v1) >= (_v2)), ((_v2) * ((_v1) / (_v2)))) + +// RelationGetMaxBatchRows +// Return the relation's max_batch_rows option +// +#define RelationGetMaxBatchRows(relation) \ + ((relation)->rd_options ? RelRoundIntOption(((StdRdOptions*)(relation)->rd_options)->max_batch_rows, BatchMaxSize) \ + : RelDefaultFullCuSize) + +// RelationGetDeltaRowsThreshold +// Return the relation's delta_rows_threshold option +// +#define RelationGetDeltaRowsThreshold(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->delta_rows_threshold : RelDefaultDletaRows) + +// RelationGetPartialClusterRows +// Return the relation's partial_cluster_rows option(return max value for -1) +// +#define RelationGetPartialClusterRows(relation) \ + ((relation)->rd_options \ + ? ((((StdRdOptions*)(relation)->rd_options)->partial_cluster_rows < 0) \ + ? RelRoundIntOption(0x7fffffff, RelationGetMaxBatchRows(relation)) \ + : RelRoundIntOption(((StdRdOptions*)(relation)->rd_options)->partial_cluster_rows, \ + RelationGetMaxBatchRows(relation))) \ + : RelDefaultPartialClusterRows) + +/* Relation whether create in current xact */ +static inline bool RelationCreateInCurrXact(Relation rel) +{ + return rel->rd_createSubid != InvalidTransactionId; +} + +/* RelationGetPgClassOid + * return the pg_class OID of this relation. + * if this is a PARTITION, return its parent oid; + * otherwise the same to macro RelationGetRelid(). + */ +#define RelationGetPgClassOid(relation, isPartition) \ + ((isPartition) ? ((relation)->parentId) : RelationGetRelid(relation)) + +/* + * PartitionOpenSmgr + * Open the partition at the smgr level, if not already done. + */ +#define PartitionOpenSmgr(partition) \ + do { \ + if ((partition)->pd_smgr == NULL) \ + smgrsetowner(&((partition)->pd_smgr), smgropen((partition)->pd_node, InvalidBackendId)); \ + } while (0) + + +/* + * PartionCloseSmgr + * Close the partition at the smgr level, if not already done. + * + * Note: smgrclose should unhook from owner pointer, hence the Assert. + */ +#define PartitionCloseSmgr(partition) \ + do { \ + if ((partition)->pd_smgr != NULL) { \ + smgrclose((partition)->pd_smgr); \ + Assert(PartitionIsBucket(partition) || (partition)->pd_smgr == NULL); \ + } \ + } while (0) + +/* + * PartitionGetTargetBlock + * Fetch partition's current insertion target block. + * + * Returns InvalidBlockNumber if there is no current target block. Note + * that the target block status is discarded on any smgr-level invalidation. + */ +#define PartitionGetTargetBlock(partition) \ + ((partition)->pd_smgr != NULL ? (partition)->pd_smgr->smgr_targblock : InvalidBlockNumber) +/* + * PartitionSetTargetBlock + * Set relation's current insertion target block. + */ +/* + * PartitionGetPartitionName + * Returns the part's name. + * + * Note that the name is only unique within the containing namespace. + */ +#define PartitionGetPartitionName(partition) (NameStr((partition)->pd_part->relname)) +/* + * PartitionGetPartid + * Returns the OID of the partition + */ +#define PartitionGetPartid(partition) ((partition)->pd_id) + +#define PartitionGetRelid(partition) ((partition)->pd_part->parentid) + +/* + * PartitionIsValid + * True iff partition descriptor is valid. + */ +#define PartitionIsValid(partition) PointerIsValid(partition) + +/* + * true if the relation is construct from a partition + */ +#define RelationIsPartition(relation) \ + (OidIsValid((relation)->parentId) && (PARTTYPE_NON_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + ((RELKIND_RELATION == (relation)->rd_rel->relkind) || (RELKIND_INDEX == (relation)->rd_rel->relkind))) + +#define InvalidPartition ((Partition)NULL) + +#define InvalidBktId (-1) +#define RelationIsBucket(relation) \ + ((relation)->rd_node.bucketNode > InvalidBktId) + +/* + * PartitionHasReferenceCountZero + * True iff partition reference count is zero. + * + * Note: + * Assumes partition descriptor is valid. + */ +#define PartitionHasReferenceCountZero(partition) ((bool)((partition)->pd_refcnt == 0)) +/* routines in utils/cache/partcache.c */ +extern void PartitionIncrementReferenceCount(Partition part); +extern void PartitionDecrementReferenceCount(Partition part); + +#define PartitionIsMapped(part) ((part)->pd_part->relfilenode == InvalidOid) + +#define CStoreRelationOpenSmgr(relation, col) \ + do { \ + if ((relation)->rd_smgr == NULL) \ + smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node, (relation)->rd_backend, (col))); \ + else { \ + SMgrRelation tmp; \ + tmp = smgropen((relation)->rd_node, (relation)->rd_backend, (col)); \ + Assert((relation)->rd_smgr == tmp); \ + } \ + } while (0) + +#define RelationIsLocalTemp(relation) \ + ((relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempNamespace || \ + (relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempToastNamespace) + +#define RelationIsUnlogged(relation) ((relation)->rd_rel->relnamespace == RELPERSISTENCE_UNLOGGED) + +#define RelationIsGlobalIndex(relation) (RELKIND_GLOBAL_INDEX == (relation)->rd_rel->relkind) + +#define RelationIsIndex(relation) (RELKIND_INDEX == (relation)->rd_rel->relkind || RelationIsGlobalIndex(relation)) + +#define RelationIsSequnce(relation) (RELKIND_SEQUENCE == (relation)->rd_rel->relkind) + +#define RelationIsToast(relation) (RELKIND_TOASTVALUE == (relation)->rd_rel->relkind) + +#define RelationIsView(relation) (RELKIND_VIEW == (relation)->rd_rel->relkind) + +#define RelationIsContquery(relation) (RELKIND_CONTQUERY == (relation)->rd_rel->relkind) + +#define RelationIsForeignTable(relation) (RELKIND_FOREIGN_TABLE == (relation)->rd_rel->relkind) + +#define RelationIsStream(relation) (RELKIND_STREAM == (relation)->rd_rel->relkind) + +#define RelationIsUnCataloged(relation) (RELKIND_UNCATALOGED == (relation)->rd_rel->relkind) + +#define RelationIsPartitioned(relation) (PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) +#define RelationIsRangePartitioned(relation) (PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +#define RelationIsValuePartitioned(relation) (PARTTYPE_VALUE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +#define RelationGetValuePartitionList(relation) \ + (RelationIsValuePartitioned(relation) ? ((ValuePartitionMap*)relation->partMap)->partList : NIL) + +#define RelationIsNonpartitioned(relation) (PARTTYPE_NON_PARTITIONED_RELATION == (relation)->rd_rel->parttype) + +/* + * RELATION_IS_OTHER_TEMP + * Test for a temporary relation that belongs to some other session. + * + * Beware of multiple eval of argument + */ +#define RELATION_IS_OTHER_TEMP(relation) \ + (STMT_RETRY_ENABLED ? ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \ + u_sess->catalog_cxt.myTempNamespace != (relation)->rd_rel->relnamespace && \ + u_sess->catalog_cxt.myTempToastNamespace != (relation)->rd_rel->relnamespace && \ + CSTORE_NAMESPACE != (relation)->rd_rel->relnamespace && \ + PG_TOAST_NAMESPACE != (relation)->rd_rel->relnamespace) \ + : ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \ + u_sess->catalog_cxt.myTempNamespace != (relation)->rd_rel->relnamespace && \ + u_sess->catalog_cxt.myTempToastNamespace != (relation)->rd_rel->relnamespace)) + +#define RELATION_IS_PARTITIONED(relation) \ + ((PARTTYPE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + (RELKIND_RELATION == (relation)->rd_rel->relkind)) + +#define RELATION_IS_VALUE_PARTITIONED(relation) \ + ((PARTTYPE_VALUE_PARTITIONED_RELATION == (relation)->rd_rel->parttype) && \ + (RELKIND_RELATION == (relation)->rd_rel->relkind)) + +/* + * type bucketOid bucketKey meaning + * N INV INV relation has no bucket + * B 1 KEY relation has bucket but without bucket storage + * S OID INV relation has bucket storage without bucket key + * K OID KEY relation has bucket key + */ +#define REALTION_BUCKETKEY_INITED(relation) \ + ((relation)->rd_bucketkey != (RelationBucketKey*)&((relation)->rd_bucketkey)) + +#define REALTION_BUCKETKEY_VALID(relation) \ + (REALTION_BUCKETKEY_INITED(relation) && \ + PointerIsValid((relation)->rd_bucketkey)) + +/* type: SKB*/ +#define RELATION_HAS_BUCKET(relation) \ + (OidIsValid((relation)->rd_bucketoid)) + +/* type: SK */ +#define RELATION_OWN_BUCKET(relation) \ + (RELATION_HAS_BUCKET(relation) && \ + (VirtualBktOid != (relation)->rd_bucketoid)) + +/* type: K*/ +#define RELATION_OWN_BUCKETKEY(relation) \ + (RELATION_OWN_BUCKET(relation) && \ + RelationIsPartitioned(relation)) + +/* type: SK && Non-part*/ +#define RELATION_CREATE_BUCKET(relation) \ + (RelationIsNonpartitioned(relation) && \ + RELATION_OWN_BUCKET(relation)) + + +#define RELATION_IS_DELTA(relation) \ + (IsCStoreNamespace(RelationGetNamespace(relation)) && \ + pg_strncasecmp(RelationGetRelationName(relation), "pg_delta", strlen("pg_delta")) == 0) + +#define RELATION_GET_CMPRS_ATTR(relation) ((relation)->rd_rel->relcmprs) +#define RELATION_SET_CMPRS_ATTR(relation, cmprs) ((relation)->rd_rel->relcmprs = cmprs) + +static inline bool IsCompressedByCmprsInPgclass(const RelCompressType cmprInPgclass) +{ + return (cmprInPgclass > REL_CMPRS_PAGE_PLAIN && cmprInPgclass < REL_CMPRS_MAX_TYPE); +} + +/* at default row relation is not compressed in options */ +/* maybe exsiting compressed row-table don't modify compression option synchronously */ +#define RowRelationIsCompressed(relation) \ + (pg_strcasecmp(COMPRESSION_NO, StdRdOptionsGetStringData(relation->rd_options, compression, COMPRESSION_NO)) != 0 || \ + IsCompressedByCmprsInPgclass((RelCompressType)relation->rd_rel->relcmprs)) + +#define RelIsSpecifiedFTbl(rte, SepcifiedType) \ + ((rte->relkind == RELKIND_FOREIGN_TABLE || rte->relkind == RELKIND_STREAM) \ + && isSpecifiedSrvTypeFromRelId(rte->relid, SepcifiedType)) + +#define RelationGetStartCtidInternal(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, start_ctid_internal, NULL) + +#define RelationGetEndCtidInternal(relation) StdRdOptionsGetStringData((relation)->rd_options, end_ctid_internal, NULL) + +#define RelationInRedistribute(relation) (REDIS_REL_NORMAL < (RelationGetAppendMode(relation)) ? true : false) + +#define RelationInRedistributeReadOnly(relation) \ + (REDIS_REL_READ_ONLY == (RelationGetAppendMode(relation)) ? true : false) + +#define RelationInRedistributeEndCatchup(relation) \ + (REDIS_REL_END_CATCHUP == (RelationGetAppendMode(relation)) ? true : false) + +#define RelationIsRedistributeDest(relation) \ + (REDIS_REL_DESTINATION == (RelationGetAppendMode(relation)) ? true : false) + +/* Get info */ +#define RelationGetRelCnOid(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->rel_cn_oid : InvalidOid) + +#define RelationGetRelMergeList(relation) \ + StdRdOptionsGetStringData((relation)->rd_options, merge_list, NULL) + +#define ParitionGetWaitCleanGpi(partition) StdRdOptionsGetStringData((partition)->rd_options, wait_clean_gpi, OptDisabledWaitCleanGpi) +#define RelationGetWaitCleanGpi(relation) StdRdOptionsGetStringData((relation)->rd_options, wait_clean_gpi, OptDisabledWaitCleanGpi) + +/* Partition get reloptions whether have wait_clean_gpi for parition */ +static inline bool PartitionEnableWaitCleanGpi(Partition partition) +{ + if (PointerIsValid(partition) && partition->rd_options != NULL && + pg_strcasecmp(OptEnabledWaitCleanGpi, ParitionGetWaitCleanGpi(partition)) == 0) { + return true; + } + + return false; +} + +/* Relation get reloptions whether have wait_clean_gpi for relation */ +static inline bool RelationEnableWaitCleanGpi(Relation relation) +{ + if (PointerIsValid(relation) && relation->rd_options != NULL && + pg_strcasecmp(OptEnabledWaitCleanGpi, RelationGetWaitCleanGpi(relation)) == 0) { + return true; + } + + return false; +} + +/* routines in utils/cache/relcache.c */ +extern bool RelationIsDfsStore(Relation relatioin); +extern bool RelationIsPaxFormatByOid(Oid relid); +#ifdef ENABLE_MOT +extern bool RelationIsMOTTableByOid(Oid relid); +#endif +extern bool RelationIsCUFormatByOid(Oid relid); + +#define IS_FOREIGNTABLE(rel) ((rel)->rd_rel->relkind == RELKIND_FOREIGN_TABLE) +#define IS_STREAM_TABLE(rel) ((rel)->rd_rel->relkind == RELKIND_STREAM) +extern bool have_useft_privilege(void); + +extern RelationMetaData* make_relmeta(Relation rel); +extern Relation get_rel_from_meta(RelationMetaData* frel); +extern bool CheckRelOrientationByPgClassTuple(HeapTuple tuple, TupleDesc tupdesc, const char* orientation); + +#endif // !FRONTEND_PARSER +#endif /* REL_GS_H */ + diff -uprN postgresql-hll-2.14_old/include/utils/rel.h postgresql-hll-2.14/include/utils/rel.h --- postgresql-hll-2.14_old/include/utils/rel.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/rel.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,614 @@ +/* ------------------------------------------------------------------------- + * + * rel.h + * POSTGRES relation descriptor (a/k/a relcache entry) definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/rel.h + * + * ------------------------------------------------------------------------- + */ +#ifndef REL_H +#define REL_H + +#include "access/tupdesc.h" +#include "catalog/pg_am.h" +#include "catalog/pg_class.h" +#include "catalog/pg_index.h" + + +#include "fmgr.h" +#include "nodes/bitmapset.h" +#include "nodes/nodes.h" +#ifdef PGXC +#include "pgxc/locator.h" +#endif +#include "rewrite/prs2lock.h" +#include "storage/block.h" +#include "storage/relfilenode.h" +#include "tcop/stmt_retry.h" +#include "utils/relcache.h" +#include "utils/partcache.h" +#include "utils/reltrigger.h" +#include "utils/partitionmap.h" +#include "catalog/pg_hashbucket_fn.h" + + +#ifndef HDFS +#define HDFS "hdfs" +#endif +#ifndef OBS +#define OBS "obs" +#endif + +/* + * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient + * to declare them here so we can have a LockInfoData field in a Relation. + */ + +typedef struct LockRelId { + Oid relId; /* a relation identifier */ + Oid dbId; /* a database identifier */ + Oid bktId; /* a bucket identifier = bucketid + 1 */ +} LockRelId; + +typedef struct LockInfoData { + LockRelId lockRelId; +} LockInfoData; + +typedef LockInfoData* LockInfo; +#define InvalidLockRelId { InvalidOid, InvalidOid, InvalidOid} +#define LockRelIdIsInvalid(__lockrelid) (((__lockrelid).relId == InvalidOid) && ((__lockrelid).dbId == InvalidOid)) + +/* + * Cached lookup information for the index access method functions defined + * by the pg_am row associated with an index relation. + */ +typedef struct RelationAmInfo { + FmgrInfo aminsert; + FmgrInfo ambeginscan; + FmgrInfo amgettuple; + FmgrInfo amgetbitmap; + FmgrInfo amrescan; + FmgrInfo amendscan; + FmgrInfo ammarkpos; + FmgrInfo amrestrpos; + FmgrInfo ammerge; + FmgrInfo ambuild; + FmgrInfo ambuildempty; + FmgrInfo ambulkdelete; + FmgrInfo amvacuumcleanup; + FmgrInfo amcanreturn; + FmgrInfo amcostestimate; + FmgrInfo amoptions; +} RelationAmInfo; + +//describe bucket info of hash Bucketed-Table +typedef struct RelationBucketKey +{ + int2vector *bucketKey; /*bucket key*/ + Oid *bucketKeyType; /*the data type of partition key*/ +}RelationBucketKey; + +/* + * Here are the contents of a relation cache entry. + */ + +typedef struct RelationData { + + RelFileNode rd_node; /* relation physical identifier */ + /* use "struct" here to avoid needing to include smgr.h: */ + struct SMgrRelationData* rd_smgr; /* cached file handle, or NULL */ + int rd_refcnt; /* reference count */ + BackendId rd_backend; /* owning backend id, if temporary relation */ + bool rd_isscannable; /* rel can be scanned */ + bool rd_isnailed; /* rel is nailed in cache */ + bool rd_isvalid; /* relcache entry is valid */ + char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1 = + * valid, 2 = temporarily forced */ + bool rd_islocaltemp; /* rel is a temp rel of this session */ + + /* + * rd_createSubid is the ID of the highest subtransaction the rel has + * survived into; or zero if the rel was not created in the current top + * transaction. This should be relied on only for optimization purposes; + * it is possible for new-ness to be "forgotten" (eg, after CLUSTER). + * Likewise, rd_newRelfilenodeSubid is the ID of the highest + * subtransaction the relfilenode change has survived into, or zero if not + * changed in the current transaction (or we have forgotten changing it). + */ + SubTransactionId rd_createSubid; /* rel was created in current xact */ + SubTransactionId rd_newRelfilenodeSubid; /* new relfilenode assigned in + * current xact */ + + Form_pg_class rd_rel; /* RELATION tuple */ + TupleDesc rd_att; /* tuple descriptor */ + Oid rd_id; /* relation's object id */ + + LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */ + RuleLock* rd_rules; /* rewrite rules */ + MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */ + TriggerDesc* trigdesc; /* Trigger info, or NULL if rel has none */ + /* use "struct" here to avoid needing to include rewriteRlsPolicy.h */ + struct RlsPoliciesDesc* rd_rlsdesc; /* Row level security policies, or NULL */ + /* data managed by RelationGetIndexList: */ + List* rd_indexlist; /* list of OIDs of indexes on relation */ + Oid rd_oidindex; /* OID of unique index on OID, if any */ + Oid rd_refSynOid; /* OID of referenced synonym Oid, if mapping indeed. */ + + /* data managed by RelationGetIndexAttrBitmap: */ + Bitmapset* rd_indexattr; /* identifies columns used in indexes */ + Bitmapset* rd_idattr; /* included in replica identity index */ + + /* + * The index chosen as the relation's replication identity or + * InvalidOid. Only set correctly if RelationGetIndexList has been + * called/rd_indexvalid > 0. + */ + Oid rd_replidindex; + + /* + * rd_options is set whenever rd_rel is loaded into the relcache entry. + * Note that you can NOT look into rd_rel for this data. NULL means "use + * defaults". + */ + bytea* rd_options; /* parsed pg_class.reloptions */ + + /* These are non-NULL only for an index relation: */ + Oid rd_partHeapOid; /* partition index's partition oid */ + Form_pg_index rd_index; /* pg_index tuple describing this index */ + /* use "struct" here to avoid needing to include htup.h: */ + struct HeapTupleData* rd_indextuple; /* all of pg_index tuple */ + Form_pg_am rd_am; /* pg_am tuple for index's AM */ + int rd_indnkeyatts; /* index relation's indexkey nums */ + TableAmType rd_tam_type; /*Table accessor method type*/ + + /* + * index access support info (used only for an index relation) + * + * Note: only default support procs for each opclass are cached, namely + * those with lefttype and righttype equal to the opclass's opcintype. The + * arrays are indexed by support function number, which is a sufficient + * identifier given that restriction. + * + * Note: rd_amcache is available for index AMs to cache private data about + * an index. This must be just a cache since it may get reset at any time + * (in particular, it will get reset by a relcache inval message for the + * index). If used, it must point to a single memory chunk palloc'd in + * rd_indexcxt. A relcache reset will include freeing that chunk and + * setting rd_amcache = NULL. + */ + MemoryContext rd_indexcxt; /* private memory cxt for this stuff */ + RelationAmInfo* rd_aminfo; /* lookup info for funcs found in pg_am */ + Oid* rd_opfamily; /* OIDs of op families for each index col */ + Oid* rd_opcintype; /* OIDs of opclass declared input data types */ + RegProcedure* rd_support; /* OIDs of support procedures */ + FmgrInfo* rd_supportinfo; /* lookup info for support procedures */ + int16* rd_indoption; /* per-column AM-specific flags */ + List* rd_indexprs; /* index expression trees, if any */ + List* rd_indpred; /* index predicate tree, if any */ + Oid* rd_exclops; /* OIDs of exclusion operators, if any */ + Oid* rd_exclprocs; /* OIDs of exclusion ops' procs, if any */ + uint16* rd_exclstrats; /* exclusion ops' strategy numbers, if any */ + void* rd_amcache; /* available for use by index AM */ + Oid* rd_indcollation; /* OIDs of index collations */ + + /* + * foreign-table support + * + * rd_fdwroutine must point to a single memory chunk palloc'd in + * t_thrd.mem_cxt.cache_mem_cxt. It will be freed and reset to NULL on a relcache + * reset. + */ + + /* use "struct" here to avoid needing to include fdwapi.h: */ + struct FdwRoutine* rd_fdwroutine; /* cached function pointers, or NULL */ + + /* + * Hack for CLUSTER, rewriting ALTER TABLE, etc: when writing a new + * version of a table, we need to make any toast pointers inserted into it + * have the existing toast table's OID, not the OID of the transient toast + * table. If rd_toastoid isn't InvalidOid, it is the OID to place in + * toast pointers inserted into this rel. (Note it's set on the new + * version of the main heap, not the toast table itself.) This also + * causes toast_save_datum() to try to preserve toast value OIDs. + */ + Oid rd_toastoid; /* Real TOAST table's OID, or InvalidOid */ + Oid rd_bucketoid;/* bucket OID in pg_hashbucket*/ + + /*bucket key info, indicating which keys are used to comoute hash value */ + RelationBucketKey *rd_bucketkey; + + /* For 1-level hash table, it points into a HashBucketMap instances; + * For 2-level hash table, e.g. range-hash, it points into a RangePartitionMap + * instances. */ + + PartitionMap* partMap; + Oid parentId; /*if this is construct by partitionGetRelation,this is Partition Oid,else this is InvalidOid*/ + /* use "struct" here to avoid needing to include pgstat.h: */ + struct PgStat_TableStatus* pgstat_info; /* statistics collection area */ +#ifdef PGXC + RelationLocInfo* rd_locator_info; + PartitionMap* sliceMap; +#endif + Relation parent; + + /* double linked list node, partition and bucket relation would be stored in fakerels list of resource owner */ + dlist_node node; + + Oid rd_mlogoid; +} RelationData; + +/* + * StdRdOptions + * Standard contents of rd_options for heaps and generic indexes. + * + * RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only + * be applied to relations that use this format or a superset for + * private options data. + */ +/* autovacuum-related reloptions. */ +typedef struct AutoVacOpts { + bool enabled; + int vacuum_threshold; + int analyze_threshold; + int vacuum_cost_delay; + int vacuum_cost_limit; + int64 freeze_min_age; + int64 freeze_max_age; + int64 freeze_table_age; + float8 vacuum_scale_factor; + float8 analyze_scale_factor; +} AutoVacOpts; + +typedef enum RedisCtidType { REDIS_START_CTID = 0, REDIS_END_CTID } RedisCtidType; + +typedef enum RedisRelAction { + REDIS_REL_INVALID = -1, + REDIS_REL_NORMAL, + REDIS_REL_APPEND, + REDIS_REL_READ_ONLY, + REDIS_REL_END_CATCHUP, + REDIS_REL_REFRESH, + REDIS_REL_DESTINATION, + REDIS_REL_RESET_CTID +} RedisHtlAction; + +typedef struct StdRdOptions { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int fillfactor; /* page fill factor in percent (0..100) */ + AutoVacOpts autovacuum; /* autovacuum-related options */ + bool security_barrier; /* for views */ + bool enable_rowsecurity; /* enable row level security or not */ + bool force_rowsecurity; /* force row level security or not */ + bool enable_tsdb_delta; /* enable delta table for timeseries relations */ + + int tsdb_deltamerge_interval; /* interval for tsdb delta merge job */ + int tsdb_deltamerge_threshold; /* data threshold for tsdb delta merge job */ + int tsdb_deltainsert_threshold; /* data threshold for tsdb delta insert */ + int max_batch_rows; /* the upmost rows at each batch inserting */ + int delta_rows_threshold; /* the upmost rows delta table holds */ + int partial_cluster_rows; /* row numbers of partial cluster feature */ + int compresslevel; /* compress level, see relation storage options 'compresslevel' */ + int internalMask; /*internal mask*/ + bool ignore_enable_hadoop_env; /* ignore enable_hadoop_env */ + bool user_catalog_table; /* use as an additional catalog relation */ + bool hashbucket; /* enable hash bucket for this relation */ + + /* info for redistribution */ + Oid rel_cn_oid; + RedisHtlAction append_mode_internal; + + // Important: + // for string type, data is appended at the tail of its parent struct. + // CHAR* member of this STRUCT stores the offset of its string data. + // offset=0 means that it's a NULL string. + // + // Take Care !!! + // CHAR* member CANNOT be accessed directly. + // StdRdOptionsGetStringData macro must be used for accessing CHAR* type member. + // + char* compression; /* compress or not compress */ + char* table_access_method; /*table access method kind */ + char* orientation; /* row-store or column-store */ + char* ttl; /* time to live for tsdb data management */ + char* period; /* partition range for tsdb data management */ + char* partition_interval; /* partition interval for streaming contquery table */ + char* time_column; /* time column for streaming contquery table */ + char* ttl_interval; /* ttl interval for streaming contquery table */ + char* gather_interval; /* gather interval for streaming contquery table */ + char* string_optimize; /* string optimize for streaming contquery table */ + char* version; + char* wait_clean_gpi; /* pg_partition system catalog wait gpi-clean or not */ + /* item for online expand */ + char* append_mode; + char* start_ctid_internal; + char* end_ctid_internal; + char *merge_list; + bool on_commit_delete_rows; /* global temp table */ +} StdRdOptions; + +#define HEAP_MIN_FILLFACTOR 10 +#define HEAP_DEFAULT_FILLFACTOR 100 + +/* + * RelationIsUsedAsCatalogTable + * Returns whether the relation should be treated as a catalog table + * from the pov of logical decoding. + */ +#define RelationIsUsedAsCatalogTable(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->user_catalog_table : false) + +#define RelationIsInternal(relation) (RelationGetInternalMask(relation) != INTERNAL_MASK_DISABLE) + +/* + * RelationGetFillFactor + * Returns the relation's fillfactor. Note multiple eval of argument! + */ +#define RelationGetFillFactor(relation, defaultff) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->fillfactor : (defaultff)) + +/* + * RelationGetTargetPageUsage + * Returns the relation's desired space usage per page in bytes. + */ +#define RelationGetTargetPageUsage(relation, defaultff) (BLCKSZ * RelationGetFillFactor(relation, defaultff) / 100) + +/* + * RelationGetTargetPageFreeSpace + * Returns the relation's desired freespace per page in bytes. + */ +#define RelationGetTargetPageFreeSpace(relation, defaultff) \ + (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100) + +/* + * RelationIsSecurityView + * Returns whether the relation is security view, or not + */ +#define RelationIsSecurityView(relation) \ + ((relation)->rd_options ? ((StdRdOptions*)(relation)->rd_options)->security_barrier : false) + +/* + * RelationIsValid + * True iff relation descriptor is valid. + */ +#define RelationIsValid(relation) PointerIsValid(relation) + +#define InvalidRelation ((Relation)NULL) + +/* + * RelationHasReferenceCountZero + * True iff relation reference count is zero. + * + * Note: + * Assumes relation descriptor is valid. + */ +#define RelationHasReferenceCountZero(relation) ((bool)((relation)->rd_refcnt == 0)) + +/* + * RelationGetForm + * Returns pg_class tuple for a relation. + * + * Note: + * Assumes relation descriptor is valid. + */ +#define RelationGetForm(relation) ((relation)->rd_rel) + +/* + * RelationGetRelid + * Returns the OID of the relation + */ +#define RelationGetRelid(relation) ((relation)->rd_id) + +#define RelationGetBktid(relation) ((relation)->rd_node.bucketNode) + +/* + * RelationGetNumberOfAttributes + * Returns the total number of attributes in a relation. + */ +#define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts) + +/* + * IndexRelationGetNumberOfAttributes + * Returns the number of attributes in an index. + */ +#define IndexRelationGetNumberOfAttributes(relation) ((relation)->rd_index->indnatts) + +/* + * IndexRelationGetNumberOfKeyAttributes + * Returns the number of key attributes in an index. + */ +#define IndexRelationGetNumberOfKeyAttributes(relation) \ + (AssertMacro((relation)->rd_indnkeyatts != 0), ((relation)->rd_indnkeyatts)) + + +/* + * RelationGetDescr + * Returns tuple descriptor for a relation. + */ +#define RelationGetDescr(relation) ((relation)->rd_att) + +/* + * RelationGetRelationName + * Returns the rel's name. + * + * Note that the name is only unique within the containing namespace. + */ +#define RelationGetRelationName(relation) (NameStr((relation)->rd_rel->relname)) + +#define PartitionGetPartitionName(partition) (NameStr((partition)->pd_part->relname)) + +#define RelationGetPartType(relation) ((relation)->rd_rel->parttype) + +/* + * RelationGetNamespace + * Returns the rel's namespace OID. + */ +#define RelationGetNamespace(relation) ((relation)->rd_rel->relnamespace) + +/* + * RelationIsMapped + * True if the relation uses the relfilenode map. + * + * NB: this is only meaningful for relkinds that have storage, else it + * will misleadingly say "true". + */ +#define RelationIsMapped(relation) ((relation)->rd_rel->relfilenode == InvalidOid) + +/* + * RelationOpenSmgr + * Open the relation at the smgr level, if not already done. + */ +#define RelationOpenSmgr(relation) \ + do { \ + if ((relation)->rd_smgr == NULL) { \ + oidvector* bucketlist = NULL; \ + if (RELATION_CREATE_BUCKET(relation)) { \ + bucketlist = searchHashBucketByOid(relation->rd_bucketoid); \ + } \ + smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node, (relation)->rd_backend, 0, bucketlist)); \ + } \ + } while (0) + +/* + * RelationCloseSmgr + * Close the relation at the smgr level, if not already done. + * + * Note: smgrclose should unhook from owner pointer, hence the Assert. + */ +#define RelationCloseSmgr(relation) \ + do { \ + if ((relation)->rd_smgr != NULL) { \ + smgrclose((relation)->rd_smgr); \ + Assert(RelationIsBucket(relation) || (relation)->rd_smgr == NULL); \ + } \ + } while (0) + +/* + * RelationGetTargetBlock + * Fetch relation's current insertion target block. + * + * Returns InvalidBlockNumber if there is no current target block. Note + * that the target block status is discarded on any smgr-level invalidation. + */ +#define RelationGetTargetBlock(relation) \ + ((relation)->rd_smgr != NULL ? (relation)->rd_smgr->smgr_targblock : InvalidBlockNumber) + +/* + * RelationSetTargetBlock + * Set relation's current insertion target block. + */ +#define RelationSetTargetBlock(relation, targblock) \ + do { \ + RelationOpenSmgr(relation); \ + (relation)->rd_smgr->smgr_targblock = (targblock); \ + } while (0) + +/* + * RelationNeedsWAL + * True if relation needs WAL. + */ +#define RelationNeedsWAL(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT || \ + (((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP) && STMT_RETRY_ENABLED)) + +/* + * RelationUsesLocalBuffers + * True if relation's pages are stored in local buffers. + */ +#define RelationUsesLocalBuffers(relation) \ + ((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) +#define RelationIsLocalTemp(relation) \ + ((relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempNamespace || \ + (relation)->rd_rel->relnamespace == u_sess->catalog_cxt.myTempToastNamespace) + +#define RelationIsRelation(relation) (RELKIND_RELATION == (relation)->rd_rel->relkind) + +#define isPartitionedRelation(classForm) (PARTTYPE_PARTITIONED_RELATION == (classForm)->parttype) + +#ifdef PGXC +/* + * RelationGetLocInfo + * Return the location info of relation + */ +#define RelationGetLocInfo(relation) ((relation)->rd_locator_info) +#endif + +/* + * RelationGetBucketKey + * Fetch relation's current bucket key. + * + * Returns NULL if there is no hash bucket in current Relation + */ +#define RelationGetBucketKey(relation) \ + ((relation)->rd_bucketkey != NULL) ? (relation)->rd_bucketkey->bucketKey : NULL + +/* + * RELATION_IS_LOCAL + * If a rel is either local temp or global temp relation + * or newly created in the current transaction, + * it can be assumed to be accessible only to the current backend. + * This is typically used to decide that we can skip acquiring locks. + * + * Beware of multiple eval of argument + */ +#define RELATION_IS_LOCAL(relation) \ + ((relation)->rd_islocaltemp || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP || \ + (relation)->rd_createSubid != InvalidSubTransactionId) + +/* + * RELATION_IS_TEMP + * Test a rel is either local temp relation of this session + * or global temp relation. + */ +#define RELATION_IS_TEMP(relation) \ + ((relation)->rd_islocaltemp || \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) + +/* global temp table implementations */ +#define RELATION_IS_GLOBAL_TEMP(relation) \ + ((relation) != NULL && (relation)->rd_rel != NULL && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP) + +#define RELATION_GTT_ON_COMMIT_DELETE(relation) \ + ((relation)->rd_options && (relation)->rd_rel->relkind == RELKIND_RELATION && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_GLOBAL_TEMP ? \ + (reinterpret_cast((relation)->rd_options))->on_commit_delete_rows : false) + +#define RelationGetRelPersistence(relation) ((relation)->rd_rel->relpersistence) + +/* routines in utils/cache/relcache.c */ +extern void RelationIncrementReferenceCount(Relation rel); +extern void RelationDecrementReferenceCount(Relation rel); + +/* + * RelationIsAccessibleInLogicalDecoding + * True if we need to log enough information to have access via + * decoding snapshot. + */ +#define RelationIsAccessibleInLogicalDecoding(relation) \ + (XLogLogicalInfoActive() && RelationNeedsWAL(relation) && \ + (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) + +/* + * RelationIsLogicallyLogged + * True if we need to log enough information to extract the data from the + * WAL stream. + * + * We don't log information for unlogged tables (since they don't WAL log + * anyway) and for system tables (their content is hard to make sense of, and + * it would complicate decoding slightly for little gain). Note that we *do* + * log information for user defined catalog tables since they presumably are + * interesting to the user... + */ +#define RelationIsLogicallyLogged(relation) \ + (XLogLogicalInfoActive() && RelationNeedsWAL(relation) && !IsCatalogRelation(relation)) + +#endif /* REL_H */ + diff -uprN postgresql-hll-2.14_old/include/utils/relmapper.h postgresql-hll-2.14/include/utils/relmapper.h --- postgresql-hll-2.14_old/include/utils/relmapper.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/relmapper.h 2020-12-12 17:06:43.404350064 +0800 @@ -0,0 +1,94 @@ +/* ------------------------------------------------------------------------- + * + * relmapper.h + * Catalog-to-filenode mapping + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/relmapper.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELMAPPER_H +#define RELMAPPER_H + +#include "access/xlogreader.h" +#include "lib/stringinfo.h" + +/* + * The map file is critical data: we have no automatic method for recovering + * from loss or corruption of it. We use a CRC so that we can detect + * corruption. To minimize the risk of failed updates, the map file should + * be kept to no more than one standard-size disk sector (ie 512 bytes), + * and we use overwrite-in-place rather than playing renaming games. + * The struct layout below is designed to occupy exactly 512 bytes, which + * might make filesystem updates a bit more efficient. + * + * Entries in the mappings[] array are in no particular order. We could + * speed searching by insisting on OID order, but it really shouldn't be + * worth the trouble given the intended size of the mapping sets. + */ +#define RELMAPPER_FILENAME "pg_filenode.map" +#define RELMAPPER_FILENAME_BAK "pg_filenode.map.backup" + +#define RELMAPPER_FILEMAGIC 0x592717 /* version ID value */ + +#define MAX_MAPPINGS 62 /* 62 * 8 + 16 = 512 */ + +typedef struct RelMapping { + Oid mapoid; /* OID of a catalog */ + Oid mapfilenode; /* its filenode number */ +} RelMapping; + +typedef struct RelMapFile { + int32 magic; /* always RELMAPPER_FILEMAGIC */ + int32 num_mappings; /* number of valid RelMapping entries */ + RelMapping mappings[MAX_MAPPINGS]; + int32 crc; /* CRC of all above */ + int32 pad; /* to make the struct size be 512 exactly */ +} RelMapFile; + +/* ---------------- + * relmap-related XLOG entries + * ---------------- + */ + +#define XLOG_RELMAP_UPDATE 0x00 + +typedef struct xl_relmap_update { + Oid dbid; /* database ID, or 0 for shared map */ + Oid tsid; /* database's tablespace, or pg_global */ + int32 nbytes; /* size of relmap data */ + char data[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */ +} xl_relmap_update; + +#define MinSizeOfRelmapUpdate offsetof(xl_relmap_update, data) + +extern Oid RelationMapOidToFilenode(Oid relationId, bool shared); +extern Oid RelationMapFilenodeToOid(Oid relationId, bool shared); + +extern void RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared, bool immediate); + +extern void RelationMapRemoveMapping(Oid relationId); + +extern void RelationMapInvalidate(bool shared); +extern void RelationMapInvalidateAll(void); + +extern void AtCCI_RelationMap(void); +extern void AtEOXact_RelationMap(bool isCommit); +extern void AtPrepare_RelationMap(void); + +extern void CheckPointRelationMap(void); + +extern void RelationMapFinishBootstrap(void); + +extern void RelationMapInitialize(void); +extern void RelationMapInitializePhase2(void); +extern void RelationMapInitializePhase3(void); + +extern void relmap_redo(XLogReaderState* record); +extern void relmap_desc(StringInfo buf, XLogReaderState* record); + +#endif /* RELMAPPER_H */ diff -uprN postgresql-hll-2.14_old/include/utils/reltrigger.h postgresql-hll-2.14/include/utils/reltrigger.h --- postgresql-hll-2.14_old/include/utils/reltrigger.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/reltrigger.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- + * + * reltrigger.h + * POSTGRES relation trigger definitions. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/reltrigger.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RELTRIGGER_H +#define RELTRIGGER_H + +/* + * These struct really belongs to trigger.h, but we put it separately so that + * it can be cleanly included in rel.h and other places. + */ + +typedef struct Trigger { + Oid tgoid; /* OID of trigger (pg_trigger row) */ + /* Remaining fields are copied from pg_trigger, see pg_trigger.h */ + char* tgname; + Oid tgfoid; + uint16 tgtype; + char tgenabled; + bool tgisinternal; + Oid tgconstrrelid; + Oid tgconstrindid; + Oid tgconstraint; + bool tgdeferrable; + bool tginitdeferred; + int16 tgnargs; + int16 tgnattr; + int16* tgattr; + char** tgargs; + char* tgqual; + Oid tgowner; +} Trigger; + +typedef struct TriggerDesc { + Trigger* triggers; /* array of Trigger structs */ + int numtriggers; /* number of array entries */ + + /* + * These flags indicate whether the array contains at least one of each + * type of trigger. We use these to skip searching the array if not. + */ + bool trig_insert_before_row; + bool trig_insert_after_row; + bool trig_insert_instead_row; + bool trig_insert_before_statement; + bool trig_insert_after_statement; + bool trig_update_before_row; + bool trig_update_after_row; + bool trig_update_instead_row; + bool trig_update_before_statement; + bool trig_update_after_statement; + bool trig_delete_before_row; + bool trig_delete_after_row; + bool trig_delete_instead_row; + bool trig_delete_before_statement; + bool trig_delete_after_statement; + /* there are no row-level truncate triggers */ + bool trig_truncate_before_statement; + bool trig_truncate_after_statement; +} TriggerDesc; + +#endif /* RELTRIGGER_H */ diff -uprN postgresql-hll-2.14_old/include/utils/resowner.h postgresql-hll-2.14/include/utils/resowner.h --- postgresql-hll-2.14_old/include/utils/resowner.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/resowner.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,156 @@ +/* ------------------------------------------------------------------------- + * + * resowner.h + * POSTGRES resource owner definitions. + * + * Query-lifespan resources are tracked by associating them with + * ResourceOwner objects. This provides a simple mechanism for ensuring + * that such resources are freed at the right time. + * See utils/resowner/README for more info. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/resowner.h + * + * ------------------------------------------------------------------------- + */ +#ifndef RESOWNER_H +#define RESOWNER_H + +#include "storage/fd.h" +#include "utils/catcache.h" +#include "utils/plancache.h" +#include "utils/snapshot.h" +#include "utils/partcache.h" +#include "storage/cucache_mgr.h" + +/* + * ResourceOwner objects are an opaque data structure known only within + * resowner.c. + */ +typedef struct ResourceOwnerData* ResourceOwner; + +extern THR_LOCAL PGDLLIMPORT ResourceOwner IsolatedResourceOwner; + +/* + * Resource releasing is done in three phases: pre-locks, locks, and + * post-locks. The pre-lock phase must release any resources that are + * visible to other backends (such as pinned buffers); this ensures that + * when we release a lock that another backend may be waiting on, it will + * see us as being fully out of our transaction. The post-lock phase + * should be used for backend-internal cleanup. + */ +typedef enum { + RESOURCE_RELEASE_BEFORE_LOCKS, + RESOURCE_RELEASE_LOCKS, + RESOURCE_RELEASE_AFTER_LOCKS +} ResourceReleasePhase; + +/* + * Dynamically loaded modules can get control during ResourceOwnerRelease + * by providing a callback of this form. + */ +typedef void (*ResourceReleaseCallback)(ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void* arg); + +/* + * Functions in resowner.c + */ + +/* generic routines */ +extern ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char* name, MemoryGroupType memGroup); +extern void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel); +extern void ResourceOwnerDelete(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetParent(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetNextChild(ResourceOwner owner); +extern const char * ResourceOwnerGetName(ResourceOwner owner); +extern ResourceOwner ResourceOwnerGetFirstChild(ResourceOwner owner); +extern void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent); +extern void RegisterResourceReleaseCallback(ResourceReleaseCallback callback, void* arg); +extern void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback, const void* arg); + +/* support for buffer refcount management */ +extern void ResourceOwnerEnlargeBuffers(ResourceOwner owner); +extern void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer); +extern void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer); + +/* support for catcache refcount management */ +extern void ResourceOwnerEnlargeCatCacheRefs(ResourceOwner owner); +extern void ResourceOwnerRememberCatCacheRef(ResourceOwner owner, HeapTuple tuple); +extern void ResourceOwnerForgetCatCacheRef(ResourceOwner owner, HeapTuple tuple); +extern void ResourceOwnerEnlargeCatCacheListRefs(ResourceOwner owner); +extern void ResourceOwnerRememberCatCacheListRef(ResourceOwner owner, CatCList* list); +extern void ResourceOwnerForgetCatCacheListRef(ResourceOwner owner, CatCList* list); + +/* support for relcache refcount management */ +extern void ResourceOwnerEnlargeRelationRefs(ResourceOwner owner); +extern void ResourceOwnerRememberRelationRef(ResourceOwner owner, Relation rel); +extern void ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel); +/* support for partcache refcount management */ +extern void ResourceOwnerEnlargePartitionRefs(ResourceOwner owner); + +extern void ResourceOwnerRememberPartitionRef(ResourceOwner owner, + Partition part); +extern void ResourceOwnerForgetPartitionRef(ResourceOwner owner, + Partition part); + +extern void ResourceOwnerRememberFakerelRef(ResourceOwner owner, Relation fakerel); +extern void ResourceOwnerForgetFakerelRef(ResourceOwner owner, Relation fakerel); + +/* support for fakepart refcount management */ +extern void ResourceOwnerEnlargeFakepartRefs(ResourceOwner owner); +extern void ResourceOwnerRememberFakepartRef(ResourceOwner owner, + Partition fakepart); +extern void ResourceOwnerForgetFakepartRef(ResourceOwner owner, + Partition fakerel); + +/* support for plancache refcount management */ +extern void ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner); +extern void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan* plan); +extern void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan* plan); + +/* support for tupledesc refcount management */ +extern void ResourceOwnerEnlargeTupleDescs(ResourceOwner owner); +extern void ResourceOwnerRememberTupleDesc(ResourceOwner owner, TupleDesc tupdesc); +extern void ResourceOwnerForgetTupleDesc(ResourceOwner owner, TupleDesc tupdesc); + +/* support for snapshot refcount management */ +extern void ResourceOwnerEnlargeSnapshots(ResourceOwner owner); +extern void ResourceOwnerRememberSnapshot(ResourceOwner owner, Snapshot snapshot); +extern void ResourceOwnerForgetSnapshot(ResourceOwner owner, Snapshot snapshot); +extern void ResourceOwnerDecrementNsnapshots(ResourceOwner owner, void* queryDesc); +extern void ResourceOwnerDecrementNPlanRefs(ResourceOwner owner, bool useResOwner); + +/* support for temporary file management */ +extern void ResourceOwnerEnlargeFiles(ResourceOwner owner); +extern void ResourceOwnerRememberFile(ResourceOwner owner, File file); +extern void ResourceOwnerForgetFile(ResourceOwner owner, File file); + +/* support for data cache refcount management */ +extern void ResourceOwnerEnlargeDataCacheSlot(ResourceOwner owner); +extern void ResourceOwnerRememberDataCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); +extern void ResourceOwnerForgetDataCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); + +/* support for meta cache refcount management */ +extern void ResourceOwnerEnlargeMetaCacheSlot(ResourceOwner owner); +extern void ResourceOwnerRememberMetaCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); +extern void ResourceOwnerForgetMetaCacheSlot(ResourceOwner owner, CacheSlotId_t slotid); + +// support for pthread mutex +// +extern void ResourceOwnerForgetPthreadMutex(ResourceOwner owner, pthread_mutex_t* pMutex); + +extern void ResourceOwnerRememberPthreadMutex(ResourceOwner owner, pthread_mutex_t* pMutex); + +extern void ResourceOwnerEnlargePthreadMutex(ResourceOwner owner); + +extern void PrintPthreadMutexLeakWarning(pthread_mutex_t* pMutex); +extern void PrintResourceOwnerLeakWarning(); +extern void ResourceOwnerReleasePthreadMutex(); + +extern void ResourceOwnerEnlargePartitionMapRefs(ResourceOwner owner); +extern void ResourceOwnerRememberPartitionMapRef(ResourceOwner owner, PartitionMap* partmap); +extern void ResourceOwnerForgetPartitionMapRef(ResourceOwner owner, PartitionMap* partmap); + +#endif /* RESOWNER_H */ diff -uprN postgresql-hll-2.14_old/include/utils/rowstore.h postgresql-hll-2.14/include/utils/rowstore.h --- postgresql-hll-2.14_old/include/utils/rowstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/rowstore.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,168 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * rowstore.h + * Generalized routines for buffer row storage rotine + * + * Description: Generalized data row store routines. + * + * What is row store? + * ------------------- + * Quite like tuple store, row store is for storing the row data(serialized + * tuple recieved from dn) and providing the disk swap ability. If the tuple + * size stored in RowStore exceeds the max memory allowed (work_mem), the + * following coming data will be written into disk. + * + * You might ask why don't we use tuple/batch store instead? + * (1) for performance. The tuple/batch store will de-serialize data when store + * the row data. That cause un-needed CPU overhead. That's why we have row store + * which have the ability to put the row data in its original format. + * (2) the tuple/batch store cannot store the nodeid of a row. + * + * + * The design of row store + * ------------------------ + * row store coming with the features such as + * (1) FIFO: which perserved data order. + * (2) DiskOnDemand: the comming data will be written to disk only when the + * memory is full. and unlike tuple/batch store all data(including the data + * in the memory) is written to disk, the rowstore only write those data + * who cannot fit into memory. + * (3) O(1) for read and write. The data row is directly read/write from/to the + * node's bank. Because we allocate a bank for each node. + * + * + * The internal of row store + * ------------------------ + * The data structure for the row store is as follows: + * + * [row store] + * bank[1]---->[m][m][m].....[m][d][d][d]......[d] + * bank[2]---->[m][m][m].....[m][d][d][d]......[d] + * bank[3]---->[m][m][m].....[m][d][d][d]......[d] + * bank[N]---->[m][m][m].....[m][d][d][d]......[d] + * *----in mem----*------in disk-----* + * + * The row store has many banks(NumDataNodes), each datanode has its own bank. + * Each bank contains many cells. The input data row is directed to its own + * bank based on the msgid, and append to the bank's cell list. If the bank + * has enough memory to hold the cell, the cell will be appeded to the in mem + * list, otherwise will be append to the in disk list. The cell will be compressed + * to save both memory and diskspace. + * + * Relation of structs + * ------------------------- + * RowStoreManager: holds all meta-data for a row store and have one bank for each datanode + * Bank: holds all cells of a given datanode + * RowStoreCell: each datarow convert to a cell and stored in bank + * + * introduce to the APIs + * ------------------------- + * First of all, have to invoke RowStoreAlloc() to initialize a RowStoreManager + * And then you can use RowStoreInsert() to insert DataRow into the RowStore. + * If the row store contains any data, you can use RowStoreFetch() to get the data + * in the row store. + * Finally, you have to invoke RowStoreDestory() to do the clean up work. + * + * IDENTIFICATION + * src/include/utils/rowstore.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef ROWSTORE_H +#define ROWSTORE_H + +#include "storage/buffile.h" +#include "utils/memprot.h" +#include "utils/memutils.h" +#include "pgxc/pgxcnode.h" + +#ifdef USE_ASSERT_CHECKING +#define CHECK_MEM(rs) MemoryContextCheck(rs->context, rs->context->session_id > 0) +#else +#define CHECK_MEM(rs) +#endif + +#define ROW_STORE_MAX_MEM \ + (u_sess->attr.attr_memory.work_mem * 1024L) /* use u_sess->attr.attr_memory.work_mem, default 64MB */ + +/* + * bank holds all cell of a given datanode + */ +typedef struct Bank { + List* mem; /* in memory list */ + BufFile* file; /* in disk list */ + size_t max_size; /* max memory allowed by this bank */ + size_t current_size; /* current memory allocated for this bank */ + int write_fileno; /* disk file no for write */ + off_t write_offset; /* file no offset for write */ + int read_fileno; /* disk file no for read */ + off_t read_offset; /* file no offset for read */ + int length; /* how many tuples stored in this bank */ +} Bank; + +/* + * each row convert to a cell and stored in the bank + */ +typedef struct RowStoreCellData { + char* msg; /* data row msg, might be compressed */ + int msglen; /* length of the data row message */ + int msgnode; /* node number of the data row message */ + int clen; /* compressed length of the msg */ +} RowStoreCellData; + +typedef RowStoreCellData* RowStoreCell; + +/* + * row store manager holds all meta-data for a row store. + */ +typedef struct RowStoreManagerData { + + MemoryContext context; /* memory context for the RowStore */ + + Bank** cn_banks; /* each coordinator has its own bank */ + int cn_bank_num; /* total number of cn_banks, should equal to NumCoordinates */ + + Bank** dn_banks; /* each datanode has its own bank */ + int dn_bank_num; /* total number of dn_banks, should equal to NumDataNodes */ +} RowStoreManagerData; + + +typedef RowStoreManagerData* RowStoreManager; + +/*===============API================*/ + +/* initialize a row store */ +extern RowStoreManager RowStoreAlloc(MemoryContext context, size_t max_size); + +/* insert a value into row store */ +extern void RowStoreInsert(RowStoreManager rs, RemoteDataRow data); + +/* fetch data row based on node id */ +extern bool RowStoreFetch(RowStoreManager rs, Oid nodeid, RemoteDataRow datarow); + +/* fetch data row */ +extern bool RowStoreFetch(RowStoreManager rs, RemoteDataRow datarow); + +/* get the length of row store */ +extern int RowStoreLen(RowStoreManager rs); + +/* reset a row store */ +extern void RowStoreReset(RowStoreManager rs); + +/* distory a row store */ +extern void RowStoreDestory(RowStoreManager rs); + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/sec_rls_utils.h postgresql-hll-2.14/include/utils/sec_rls_utils.h --- postgresql-hll-2.14_old/include/utils/sec_rls_utils.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/sec_rls_utils.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,119 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * sec_rls_utils.h + * Security Module. + * Utility commands used in Row Level Security Policy. + * + * + * IDENTIFICATION + * src/include/utils/sec_rls_utils.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef UTILS_SEC_RLS_UTILS_H +#define UTILS_SEC_RLS_UTILS_H + +#include "pgxc/pgxc.h" +/* + * If enable_rowsecurity for one relation is false then return RLS_DISABLED. + * If enable_rowsecurity for one relation is true, but current user can + * bypass the RLS policies for this relation, then return RLS_DEPEND to + * indicate that if the environment changes, we need to invalidate and + * replan. Finally, if enable_rowsecurity for one relation is true and + * current user can not bypss the RLS policies, then return RLS_ENABLED, + * which means we also need to invalidate if the environment changes. + */ +enum EnableRlsFeature { RLS_DISABLED, RLS_DEPEND, RLS_ENABLED }; + +/* + * SupportRlsOnCurrentNode + * Check whether support ddl(create, change, drop) operation or apply + * rls policy on current node(cn, dn, single_node). + * + * @return: support row level security on current node or not. + */ +inline bool SupportRlsOnCurrentNode() +{ + return (IS_PGXC_COORDINATOR || IS_SINGLE_NODE); +} + +/* + * RelationEnableRowSecurity + * Returns whether the relation enable row level security, or not + * + * @param (in) relation: Relation information. + * @return: enable row level security or not. + */ +inline bool RelationEnableRowSecurity(const Relation relation) +{ + /* Check whether support RLS on current node */ + if (SupportRlsOnCurrentNode() == false) { + return false; + } + /* Only check this option for normal relation */ + if (relation->rd_rel->relkind != RELKIND_RELATION) { + return false; + } + if (relation->rd_options != NULL) { + /* + * Only when relation is normal relation, rd_options + * can be casted to StdRdOptions type. Index has its + * own rd_options type, so it is dangerous to cast + * rd_options to StdRdOptions for index relation. + */ + StdRdOptions* rd_options = (StdRdOptions*)relation->rd_options; + return rd_options->enable_rowsecurity; + } + return false; +} + +/* + * RelationForceRowSecurity + * Returns whether the relation force row level security, or not + * + * @param (in) relation: Relation information. + * @return: force row level security or not. + */ +inline bool RelationForceRowSecurity(const Relation relation) +{ + /* Check whether support RLS on current node */ + if (SupportRlsOnCurrentNode() == false) { + return false; + } + /* Only check this option for normal relation */ + if (relation->rd_rel->relkind != RELKIND_RELATION) { + return false; + } + if (relation->rd_options != NULL) { + /* + * Only when relation is normal relation, rd_options + * can be casted to StdRdOptions type. Index has its + * own rd_options type, so it is dangerous to cast + * rd_options to StdRdOptions for index relation. + */ + StdRdOptions* rd_options = (StdRdOptions*)relation->rd_options; + return rd_options->force_rowsecurity; + } + return false; +} + +extern EnableRlsFeature CheckEnableRlsPolicies(const Relation relation, Oid roleid); +extern SelectStmt* MakeRlsSelectStmtForCopyTo(const Relation relation, const CopyStmt* stmt); +extern void LicenseSupportRls(); +extern void SupportRlsForRel(const Relation relation); + +#endif /* UTILS_SEC_RLS_UTILS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/selfuncs.h postgresql-hll-2.14/include/utils/selfuncs.h --- postgresql-hll-2.14_old/include/utils/selfuncs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/selfuncs.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,262 @@ +/* ------------------------------------------------------------------------- + * + * selfuncs.h + * Selectivity functions and index cost estimation functions for + * standard operators and index access methods. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/selfuncs.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SELFUNCS_H +#define SELFUNCS_H + +#include "fmgr.h" +#include "access/htup.h" +#include "nodes/relation.h" +#include "optimizer/nodegroups.h" + +/* + * Note: the default selectivity estimates are not chosen entirely at random. + * We want them to be small enough to ensure that indexscans will be used if + * available, for typical table densities of ~100 tuples/page. Thus, for + * example, 0.01 is not quite small enough, since that makes it appear that + * nearly all pages will be hit anyway. Also, since we sometimes estimate + * eqsel as 1/num_distinct, we probably want DEFAULT_NUM_DISTINCT to equal + * 1/DEFAULT_EQ_SEL. + */ + +/* default selectivity estimate for equalities such as "A = b" */ +#define DEFAULT_EQ_SEL 0.005 + +/* default selectivity estimate for inequalities such as "A < b" */ +#define DEFAULT_INEQ_SEL 0.3333333333333333 + +/* default selectivity estimate for range inequalities "A > b AND A < c" */ +#define DEFAULT_RANGE_INEQ_SEL 0.005 + +/* default selectivity estimate for pattern-match operators such as LIKE */ +#define DEFAULT_MATCH_SEL 0.005 + +/* default number of distinct values in a table */ +#define DEFAULT_NUM_DISTINCT 200 + +/* default number of rows */ +#define DEFAULT_NUM_ROWS 10 + +/* default number of distinct values and biase for the special expression */ +#define DEFAULT_SPECIAL_EXPR_DISTINCT 10 +#define DEFAULT_SPECIAL_EXPR_BIASE (pow(u_sess->pgxc_cxt.NumDataNodes, (double)1 / 2) / u_sess->pgxc_cxt.NumDataNodes) + +/* default selectivity estimate for boolean and null test nodes */ +#define DEFAULT_UNK_SEL 0.005 +#define DEFAULT_NOT_UNK_SEL (1.0 - DEFAULT_UNK_SEL) + +/* default selectivity estimate for neq anti join */ +#define MIN_NEQ_ANTI_SEL 0.05 +#define MAX_NEQ_SEMI_SEL (1.0 - MIN_NEQ_ANTI_SEL) + +/* If the selectivity is too high, we do not use POISSON to estimate the numbwe of distinct values */ +#define SELECTIVITY_THRESHOLD_TO_USE_POISSON 0.95 + +/* Estimate local distinct of join or agg after filter or join for scattered distribution. */ +#define NUM_DISTINCT_SELECTIVITY_FOR_POISSON(distinct, input_rows, selectivity) \ + (double)((distinct) * (1 - exp(-((input_rows) * (selectivity) / (distinct))))) + +/* Estimate distinct from global to local for scattered distribution. */ +#define NUM_DISTINCT_GTL_FOR_POISSON(gdistinct, input_rows, num_datanodes, dop) \ + (double)(NUM_DISTINCT_SELECTIVITY_FOR_POISSON(gdistinct, input_rows, 1.0 / num_datanodes / (dop))) + +/* Estimate thread distinct from dn distinct num. */ +#define NUM_PARALLEL_DISTINCT_GTL_FOR_POISSON(dn_distinct, dn_rows, dop) \ + (double)(NUM_DISTINCT_SELECTIVITY_FOR_POISSON(dn_distinct, dn_rows, 1.0 / (dop))) + +/* + * Clamp a computed probability estimate (which may suffer from roundoff or + * estimation errors) to valid range. Argument must be a float variable. + */ +#define CLAMP_PROBABILITY(p) \ + do { \ + if (p < 0.0) \ + p = 0.0; \ + else if (p > 1.0) \ + p = 1.0; \ + } while (0) + +/* Return data from examine_variable and friends */ +typedef struct VariableStatData { + Node* var; /* the Var or expression tree */ + RelOptInfo* rel; /* Relation, or NULL if not identifiable */ + HeapTuple statsTuple; /* pg_statistic tuple, or NULL if none */ + /* NB: if statsTuple!=NULL, it must be freed when caller is done */ + void (*freefunc)(HeapTuple tuple); /* how to free statsTuple */ + Oid vartype; /* exposed type of expression */ + Oid atttype; /* type to pass to get_attstatsslot */ + int32 atttypmod; /* typmod to pass to get_attstatsslot */ + bool isunique; /* matches unique index or DISTINCT clause */ + bool enablePossion; /* indentify we can use possion or not */ +} VariableStatData; + +#define ReleaseVariableStats(vardata) \ + do { \ + if (HeapTupleIsValid((vardata).statsTuple)) \ + (*(vardata).freefunc)((vardata).statsTuple); \ + } while (0) + +typedef enum { Pattern_Type_Like, Pattern_Type_Like_IC, Pattern_Type_Regex, Pattern_Type_Regex_IC } Pattern_Type; + +typedef enum { Pattern_Prefix_None, Pattern_Prefix_Partial, Pattern_Prefix_Exact } Pattern_Prefix_Status; + +typedef enum { STATS_TYPE_GLOBAL, STATS_TYPE_LOCAL } STATS_EST_TYPE; + +/* + * Helper routine for estimate_num_groups: add an item to a list of + * GroupVarInfos, but only if it's not known equal to any of the existing + * entries. + */ +typedef struct { + Node* var; /* might be an expression, not just a Var */ + RelOptInfo* rel; /* relation it belongs to */ + double ndistinct; /* # distinct values */ + bool isdefault; /* if estimated distinct value is default value */ + bool es_is_used; /* true if extended statistic is used*/ + Bitmapset* es_attnums; /* number of correlated attributes */ +} GroupVarInfo; + +extern void set_local_rel_size(PlannerInfo* root, RelOptInfo* rel); +extern double get_multiple_by_distkey(PlannerInfo* root, List* distkey, double rows); +extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Plan* plan, const double* numGroups); +extern double estimate_agg_num_distinct(PlannerInfo* root, List* group_exprs, Path* path, const double* numGroups); +extern void output_noanalyze_rellist_to_log(int lev); +extern void set_noanalyze_rellist(Oid relid, AttrNumber attid); +extern double estimate_local_numdistinct(PlannerInfo* root, Node* hashkey, Path* path, SpecialJoinInfo* sjinfo, + double* global_distinct, bool* isdefault, VariableStatData* vardata); +extern void get_num_distinct(PlannerInfo* root, List* groupExprs, double local_rows, double global_rows, + unsigned int num_datanodes, double* numdistinct, List** pgset = NULL); + +extern double get_local_rows(double global_rows, double multiple, bool replicate, unsigned int num_data_nodes); +extern double get_global_rows(double local_rows, double multiple, unsigned int num_data_nodes); + +#define PATH_LOCAL_ROWS(path) \ + get_local_rows( \ + (path)->rows, (path)->multiple, IsLocatorReplicated((path)->locator_type), ng_get_dest_num_data_nodes(path)) +#define PLAN_LOCAL_ROWS(plan) \ + get_local_rows( \ + (plan)->plan_rows, (plan)->multiple, (plan)->exec_type != EXEC_ON_DATANODES, ng_get_dest_num_data_nodes(plan)) +#define RELOPTINFO_LOCAL_FIELD(root, rel, fldname) \ + get_local_rows((rel)->fldname, \ + (rel)->multiple, \ + IsLocatorReplicated((rel)->locator_type), \ + ng_get_dest_num_data_nodes((root), (rel))) +#define IDXOPTINFO_LOCAL_FIELD(root, idx, fldname) \ + get_local_rows((idx)->fldname, \ + (idx)->rel->multiple, \ + IsLocatorReplicated((idx)->rel->locator_type), \ + ng_get_dest_num_data_nodes((root), (idx)->rel)) + +/* Functions in selfuncs.c */ + +extern void examine_variable(PlannerInfo* root, Node* node, int varRelid, VariableStatData* vardata); +extern bool get_restriction_variable( + PlannerInfo* root, List* args, int varRelid, VariableStatData* vardata, Node** other, bool* varonleft); +extern void get_join_variables(PlannerInfo* root, List* args, SpecialJoinInfo* sjinfo, VariableStatData* vardata1, + VariableStatData* vardata2, bool* join_is_reversed); +extern double get_variable_numdistinct(VariableStatData* vardata, bool* isdefault, bool adjust_rows = true, + double join_ratio = 1.0, SpecialJoinInfo* sjinfo = NULL, STATS_EST_TYPE eType = STATS_TYPE_GLOBAL); +extern double mcv_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft, + double* sumcommonp, Oid equaloperator, bool* inmcv, double* lastcommonp = NULL); +extern double histogram_selectivity(VariableStatData* vardata, FmgrInfo* opproc, Datum constval, bool varonleft, + int min_hist_size, int n_skip, int* hist_size); + +extern Pattern_Prefix_Status pattern_fixed_prefix( + Const* patt, Pattern_Type ptype, Oid collation, Const** prefix, Selectivity* rest_selec); +extern Const* make_greater_string(const Const* str_const, FmgrInfo* ltproc, Oid collation); + +extern Datum eqsel(PG_FUNCTION_ARGS); +extern Datum neqsel(PG_FUNCTION_ARGS); +extern Datum scalarltsel(PG_FUNCTION_ARGS); +extern Datum scalargtsel(PG_FUNCTION_ARGS); +extern Datum regexeqsel(PG_FUNCTION_ARGS); +extern Datum icregexeqsel(PG_FUNCTION_ARGS); +extern Datum likesel(PG_FUNCTION_ARGS); +extern Datum iclikesel(PG_FUNCTION_ARGS); +extern Datum regexnesel(PG_FUNCTION_ARGS); +extern Datum icregexnesel(PG_FUNCTION_ARGS); +extern Datum nlikesel(PG_FUNCTION_ARGS); +extern Datum icnlikesel(PG_FUNCTION_ARGS); + +extern Datum eqjoinsel(PG_FUNCTION_ARGS); +extern Datum neqjoinsel(PG_FUNCTION_ARGS); +extern Datum scalarltjoinsel(PG_FUNCTION_ARGS); +extern Datum scalargtjoinsel(PG_FUNCTION_ARGS); +extern Datum regexeqjoinsel(PG_FUNCTION_ARGS); +extern Datum icregexeqjoinsel(PG_FUNCTION_ARGS); +extern Datum likejoinsel(PG_FUNCTION_ARGS); +extern Datum iclikejoinsel(PG_FUNCTION_ARGS); +extern Datum regexnejoinsel(PG_FUNCTION_ARGS); +extern Datum icregexnejoinsel(PG_FUNCTION_ARGS); +extern Datum nlikejoinsel(PG_FUNCTION_ARGS); +extern Datum icnlikejoinsel(PG_FUNCTION_ARGS); + +extern Selectivity booltestsel( + PlannerInfo* root, BoolTestType booltesttype, Node* arg, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern Selectivity nulltestsel( + PlannerInfo* root, NullTestType nulltesttype, Node* arg, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); +extern Selectivity scalararraysel(PlannerInfo* root, ScalarArrayOpExpr* clause, bool is_join_clause, int varRelid, + JoinType jointype, SpecialJoinInfo* sjinfo); +extern int estimate_array_length(Node* arrayexpr); +extern Selectivity rowcomparesel( + PlannerInfo* root, RowCompareExpr* clause, int varRelid, JoinType jointype, SpecialJoinInfo* sjinfo); + +extern void mergejoinscansel(PlannerInfo* root, Node* clause, Oid opfamily, int strategy, bool nulls_first, + Selectivity* leftstart, Selectivity* leftend, Selectivity* rightstart, Selectivity* rightend); + +extern double estimate_num_groups(PlannerInfo* root, List* groupExprs, double input_rows, unsigned int num_datanodes, + STATS_EST_TYPE eType = STATS_TYPE_GLOBAL, List** pgset = NULL); + +extern Selectivity estimate_hash_bucketsize( + PlannerInfo* root, Node* hashkey, double nbuckets, Path* inner_path, SpecialJoinInfo* sjinfo, double* distinctnum); + +extern Datum btcostestimate(PG_FUNCTION_ARGS); +extern Datum hashcostestimate(PG_FUNCTION_ARGS); +extern Datum gistcostestimate(PG_FUNCTION_ARGS); +extern Datum spgcostestimate(PG_FUNCTION_ARGS); +extern Datum gincostestimate(PG_FUNCTION_ARGS); +extern Datum psortcostestimate(PG_FUNCTION_ARGS); + +/* Functions in array_selfuncs.c */ + +extern Selectivity scalararraysel_containment( + PlannerInfo* root, Node* leftop, Node* rightop, Oid elemtype, bool isEquality, bool useOr, int varRelid); +extern Datum arraycontsel(PG_FUNCTION_ARGS); +extern Datum arraycontjoinsel(PG_FUNCTION_ARGS); + +/* the type for var data ratio we cached. */ +typedef enum { RatioType_Filter, RatioType_Join } RatioType; + +/* var ratio structure for one relation after join with other relation or filter by self. */ +typedef struct VarRatio { + RatioType ratiotype; /* filter ratio or join ratio. */ + Node* var; /* the var of local rel in restriction clause. */ + double ratio; /* identify joinratio or filterratio if after compute join selectivity, + others it means selectivity of filter. */ + Relids joinrelids; /* the joinrel relids. */ +} VarRatio; + +typedef struct VarEqRatio { + Var* var; /* the var of local rel in restriction clause. */ + double ratio; /* identify joinratio or filterratio if after compute join selectivity, + others it means selectivity of filter. */ + Relids joinrelids; /* the joinrel relids. */ +} VarEqRatio; + +extern void set_varratio_after_calc_selectivity( + VariableStatData* vardata, RatioType type, double ratio, SpecialJoinInfo* sjinfo); +extern double get_windowagg_selectivity(PlannerInfo* root, WindowClause* wc, WindowFunc* wfunc, List* partitionExprs, + int32 constval, double tuples, unsigned int num_datanodes); +extern bool contain_single_col_stat(List* stat_list); +#endif /* SELFUNCS_H */ diff -uprN postgresql-hll-2.14_old/include/utils/snapmgr.h postgresql-hll-2.14/include/utils/snapmgr.h --- postgresql-hll-2.14_old/include/utils/snapmgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/snapmgr.h 2020-12-12 17:06:43.405350077 +0800 @@ -0,0 +1,98 @@ +/* ------------------------------------------------------------------------- + * + * snapmgr.h + * POSTGRES snapshot manager + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/snapmgr.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNAPMGR_H +#define SNAPMGR_H + +#include "utils/resowner.h" +#include "utils/snapshot.h" +#include "access/transam.h" + +/* Static variables representing various special snapshot semantics */ +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotNowData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotSelfData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotAnyData; +extern THR_LOCAL PGDLLIMPORT SnapshotData SnapshotToastData; + +#define SnapshotNow (&SnapshotNowData) +#define SnapshotSelf (&SnapshotSelfData) +#define SnapshotAny (&SnapshotAnyData) +#define SnapshotToast (&SnapshotToastData) + +#ifdef USE_ASSERT_CHECKING +#define LatestTransactionStatusError(xid, snapshot, action) PrintCurrentSnapshotInfo(PANIC, xid, snapshot, action) +#else +#define LatestTransactionStatusError(xid, snapshot, action) PrintCurrentSnapshotInfo(ERROR, xid, snapshot, action) +#endif + +extern bool XidVisibleInSnapshot(TransactionId xid, Snapshot snapshot, TransactionIdStatus *hintstatus, + Buffer buffer, bool *sync); +extern bool XidVisibleInLocalSnapshot(TransactionId xid, Snapshot snapshot); +extern bool CommittedXidVisibleInSnapshot(TransactionId xid, Snapshot snapshot, Buffer buffer); +extern bool IsXidVisibleInGtmLiteLocalSnapshot(TransactionId xid, Snapshot snapshot, TransactionIdStatus hint_status, + bool xmin_equal_xmax, Buffer buffer, bool *sync); +/* + * We don't provide a static SnapshotDirty variable because it would be + * non-reentrant. Instead, users of that snapshot type should declare a + * local variable of type SnapshotData, and initialize it with this macro. + */ +#define InitDirtySnapshot(snapshotdata) ((snapshotdata).satisfies = SNAPSHOT_DIRTY) + +/* This macro encodes the knowledge of which snapshots are MVCC-safe */ +#define IsMVCCSnapshot(snapshot) \ + ((((snapshot)->satisfies) == SNAPSHOT_MVCC) || (((snapshot)->satisfies) == SNAPSHOT_HISTORIC_MVCC)) + +extern Snapshot GetTransactionSnapshot(bool force_local_snapshot = false); +extern Snapshot GetLatestSnapshot(void); +extern Snapshot GetCatalogSnapshot(Oid relid); +extern void SnapshotSetCommandId(CommandId curcid); +extern Snapshot GetNonHistoricCatalogSnapshot(Oid relid); + +extern void PushActiveSnapshot(Snapshot snapshot); +extern void PushCopiedSnapshot(Snapshot snapshot); +extern void UpdateActiveSnapshotCommandId(void); +extern void PopActiveSnapshot(void); +extern Snapshot GetActiveSnapshot(void); +extern bool ActiveSnapshotSet(void); + +extern Snapshot RegisterSnapshot(Snapshot snapshot); +extern void UnregisterSnapshot(Snapshot snapshot); +extern Snapshot RegisterSnapshotOnOwner(Snapshot snapshot, ResourceOwner owner); +extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner); +extern void RegisterStreamSnapshots(); +extern void ForgetRegisterStreamSnapshots(); + +extern void UnRegisterStreamSnapshots(); + +extern void AtSubCommit_Snapshot(int level); +extern void AtSubAbort_Snapshot(int level); +extern void AtEOXact_Snapshot(bool isCommit); + +extern Datum pg_export_snapshot(PG_FUNCTION_ARGS); +extern void ImportSnapshot(const char* idstr); +extern bool XactHasExportedSnapshots(void); +extern void DeleteAllExportedSnapshotFiles(void); + +extern void StreamTxnContextSaveSnapmgr(void* stc); +extern void StreamTxnContextRestoreSnapmgr(const void* stc); +extern void StreamTxnContextSetSnapShot(void* snapshotPtr); +extern bool ThereAreNoPriorRegisteredSnapshots(void); +extern Snapshot PgFdwCopySnapshot(Snapshot snapshot); +extern char* ExportSnapshot(Snapshot snapshot, CommitSeqNo *snapshotcsn); + +/* Support for catalog timetravel for logical decoding */ +struct HTAB; +extern struct HTAB* HistoricSnapshotGetTupleCids(void); +extern void SetupHistoricSnapshot(Snapshot snapshot_now, struct HTAB* tuplecids); +extern void TeardownHistoricSnapshot(bool is_error); +extern bool HistoricSnapshotActive(void); +#endif /* SNAPMGR_H */ diff -uprN postgresql-hll-2.14_old/include/utils/snapshot.h postgresql-hll-2.14/include/utils/snapshot.h --- postgresql-hll-2.14_old/include/utils/snapshot.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/snapshot.h 2020-12-12 17:06:43.406350090 +0800 @@ -0,0 +1,260 @@ +/* ------------------------------------------------------------------------- + * + * snapshot.h + * POSTGRES snapshot definition + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/snapshot.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SNAPSHOT_H +#define SNAPSHOT_H + +#include "access/htup.h" +#include "storage/buf.h" +#include "gtm/gtm_c.h" + +/* + * The different snapshot types. We use SnapshotData structures to represent + * both "regular" (MVCC) snapshots and "special" snapshots that have non-MVCC + * semantics. The specific semantics of a snapshot are encoded by its type. + * + * The behaviour of each type of snapshot should be documented alongside its + * enum value, best in terms that are not specific to an individual table AM. + * + * The reason the snapshot type rather than a callback as it used to be is + * that that allows to use the same snapshot for different table AMs without + * having one callback per AM. + */ +typedef enum SnapshotSatisfiesMethod +{ + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid for the given MVCC snapshot. + * + * Here, we consider the effects of: + * - all transactions committed as of the time of the given snapshot + * - previous commands of this transaction + * + * Does _not_ include: + * - transactions shown as in-progress by the snapshot + * - transactions started after the snapshot was taken + * - changes made by the current command + * ------------------------------------------------------------------------- + */ + SNAPSHOT_MVCC = 0, + + /* ------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid for the given local MVCC snapshot. + * + * Here, we consider the effects of: + * - all transactions local committed as of the time of the given snapshot + * - previous commands of this transaction + * + * Does _not_ include: + * - transactions committed in gtm but not committed locally + * - transactions shown as in-progress by the snapshot + * - transactions started after the snapshot was taken + * - changes made by the current command + * ------------------------------------------------------------------------- + */ + SNAPSHOT_LOCAL_MVCC, + + /* ------------------------------------------------------------------------- + * A tuple is visible iff heap tuple is valid "now". + * + * Here, we consider the effects of: + * - all committed transactions (as of the current instant) + * - previous commands of this transaction + * + * Does _not_ include: + * - changes made by the current command. + * ------------------------------------------------------------------------- + */ + SNAPSHOT_NOW, + + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid "for itself". + * + * Here, we consider the effects of: + * - all committed transactions (as of the current instant) + * - previous commands of this transaction + * - changes made by the current command + * + * Does _not_ include: + * - in-progress transactions (as of the current instant) + * ------------------------------------------------------------------------- + */ + SNAPSHOT_SELF, + + /* + * Any tuple is visible. + */ + SNAPSHOT_ANY, + + /* + * A tuple is visible iff the tuple is valid as a TOAST row. + */ + SNAPSHOT_TOAST, + + /*------------------------------------------------------------------------- + * A tuple is visible iff the tuple is valid including effects of open + * transactions. + * + * Here, we consider the effects of: + * - all committed and in-progress transactions (as of the current instant) + * - previous commands of this transaction + * - changes made by the current command + * + * This is essentially like SNAPSHOT_SELF as far as effects of the current + * transaction and committed/aborted xacts are concerned. However, it + * also includes the effects of other xacts still in progress. + * + * A special hack is that when a snapshot of this type is used to + * determine tuple visibility, the passed-in snapshot struct is used as an + * output argument to return the xids of concurrent xacts that affected + * the tuple. snapshot->xmin is set to the tuple's xmin if that is + * another transaction that's still in progress; or to + * InvalidTransactionId if the tuple's xmin is committed good, committed + * dead, or my own xact. Similarly for snapshot->xmax and the tuple's + * xmax. If the tuple was inserted speculatively, meaning that the + * inserter might still back down on the insertion without aborting the + * whole transaction, the associated token is also returned in + * snapshot->speculativeToken. See also InitDirtySnapshot(). + * ------------------------------------------------------------------------- + */ + SNAPSHOT_DIRTY, + + /* + * A tuple is visible iff it follows the rules of SNAPSHOT_MVCC, but + * supports being called in timetravel context (for decoding catalog + * contents in the context of logical decoding). + */ + SNAPSHOT_HISTORIC_MVCC, +} SnapshotSatisfiesMethod; + +typedef struct SnapshotData* Snapshot; + +#define InvalidSnapshot ((Snapshot)NULL) + +/* + * Struct representing all kind of possible snapshots. + * + * There are several different kinds of snapshots: + * * Normal MVCC snapshots + * * MVCC snapshots taken during recovery (in Hot-Standby mode) + * * Historic MVCC snapshots used during logical decoding + * * snapshots passed to HeapTupleSatisfiesDirty() + * * snapshots used for SatisfiesAny, Toast, Self where no members are + * accessed. + * + * It's probably a good idea to split this struct using a NodeTag + * similar to how parser and executor nodes are handled, with one type for + * each different kind of snapshot to avoid overloading the meaning of + * individual fields. + */ + +typedef struct SnapshotData { + SnapshotSatisfiesMethod satisfies; /* satisfies type. */ + + /* + * The remaining fields are used only for MVCC snapshots, and are normally + * just zeroes in special snapshots. (But xmin and xmax are used + * specially by HeapTupleSatisfiesDirty.) + * + * An MVCC snapshot can never see the effects of XIDs >= xmax. It can see + * the effects of all older XIDs except those listed in the snapshot. xmin + * is stored as an optimization to avoid needing to search the XID arrays + * for most tuples. + */ + TransactionId xmin; /* all XID < xmin are visible to me */ + TransactionId xmax; /* all XID >= xmax are invisible to me */ + /* + * For normal MVCC snapshot this contains the all xact IDs that are in + * progress, unless the snapshot was taken during recovery in which case + * it's empty. For historic MVCC snapshots, the meaning is inverted, + * i.e. it contains *committed* transactions between xmin and xmax. + */ + TransactionId* xip; + /* + * For non-historic MVCC snapshots, this contains subxact IDs that are in + * progress (and other transactions that are in progress if taken during + * recovery). For historic snapshot it contains *all* xids assigned to the + * replayed transaction, including the toplevel xid. + */ + TransactionId* subxip; + + uint32 xcnt; /* # of xact ids in xip[] */ + GTM_Timeline timeline; /* GTM timeline */ +#ifdef PGXC /* PGXC_COORD */ + uint32 max_xcnt; /* Max # of xact in xip[] */ +#endif + /* note: all ids in xip[] satisfy xmin <= xip[i] < xmax */ + int32 subxcnt; /* # of xact ids in subxip[] */ + int32 maxsubxcnt; /* # max xids could store in subxip[] */ + bool suboverflowed; /* has the subxip array overflowed? */ + + /* + * This snapshot can see the effects of all transactions with CSN <= + * snapshotcsn. + */ + CommitSeqNo snapshotcsn; + + /* For GTMLite local snapshot, we keep an array of prepared transaction xids for MVCC */ + int prepared_array_capacity; + int prepared_count; + TransactionId* prepared_array; + + bool takenDuringRecovery; /* recovery-shaped snapshot? */ + bool copied; /* false if it's a static snapshot */ + + /* + * note: all ids in subxip[] are >= xmin, but we don't bother filtering + * out any that are >= xmax + */ + CommandId curcid; /* in my xact, CID < curcid are visible */ + uint32 active_count; /* refcount on ActiveSnapshot stack */ + uint32 regd_count; /* refcount on RegisteredSnapshotList */ + void* user_data; /* for local multiversion snapshot */ + GTM_SnapshotType gtm_snapshot_type; +} SnapshotData; + +/* + * Result codes for AM API tuple_{update,delete,lock}, and for visibility. + */ +typedef enum TM_Result +{ + /* + * Signals that the action succeeded (i.e. update/delete performed, lock + * was acquired) + */ + TM_Ok, + + /* The affected tuple wasn't visible to the relevant snapshot */ + TM_Invisible, + + /* The affected tuple was already modified by the calling backend */ + TM_SelfModified, + + /* + * The affected tuple was updated by another transaction. + */ + TM_Updated, + + /* The affected tuple was deleted by another transaction */ + TM_Deleted, + + /* + * The affected tuple is currently being modified by another session. This + * will only be returned if (update/delete/lock)_tuple are instructed not + * to wait. + */ + TM_BeingModified, + TM_SelfCreated, + TM_SelfUpdated +} TM_Result; + +#endif /* SNAPSHOT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/sortsupport_gs.h postgresql-hll-2.14/include/utils/sortsupport_gs.h --- postgresql-hll-2.14_old/include/utils/sortsupport_gs.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/sortsupport_gs.h 2020-12-12 17:06:43.406350090 +0800 @@ -0,0 +1,91 @@ +/* --------------------------------------------------------------------------------------- + * + * sortsupport_gs.h + * Framework for accelerated sorting. + * + * Traditionally, PostgreSQL has implemented sorting by repeatedly invoking + * an SQL-callable comparison function "cmp(x, y) returns int" on pairs of + * values to be compared, where the comparison function is the BTORDER_PROC + * pg_amproc support function of the appropriate btree index opclass. + * + * This file defines alternative APIs that allow sorting to be performed with + * reduced overhead. To support lower-overhead sorting, a btree opclass may + * provide a BTSORTSUPPORT_PROC pg_amproc entry, which must take a single + * argument of type internal and return void. The argument is actually a + * pointer to a SortSupportData struct, which is defined below. + * + * If provided, the BTSORTSUPPORT function will be called during sort setup, + * and it must initialize the provided struct with pointers to function(s) + * that can be called to perform sorting. This API is defined to allow + * multiple acceleration mechanisms to be supported, but no opclass is + * required to provide all of them. The BTSORTSUPPORT function should + * simply not set any function pointers for mechanisms it doesn't support. + * (However, all opclasses that provide BTSORTSUPPORT are required to provide + * the comparator function.) + * + * All sort support functions will be passed the address of the + * SortSupportData struct when called, so they can use it to store + * additional private data as needed. In particular, for collation-aware + * datatypes, the ssup_collation field is set before calling BTSORTSUPPORT + * and is available to all support functions. Additional opclass-dependent + * data can be stored using the ssup_extra field. Any such data + * should be allocated in the ssup_cxt memory context. + * + * Note: since pg_amproc functions are indexed by (lefttype, righttype) + * it is possible to associate a BTSORTSUPPORT function with a cross-type + * comparison. This could sensibly be used to provide a fast comparator + * function for such cases, but probably not any other acceleration method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/utils/sortsupport_gs.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SORTSUPPORT_GS_H +#define SORTSUPPORT_GS_H + +#include "access/attnum.h" + +/* ApplySortComparator should be inlined if possible */ +#ifdef USE_INLINE + +/* + * Apply a sort comparator function and return a 3-way comparison using full, + * authoritative comparator. This takes care of handling reverse-sort and + * NULLs-ordering properly. + */ +static inline int ApplySortAbbrevFullComparator( + Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup) +{ + int compare; + + if (isNull1) { + if (isNull2) + compare = 0; /* NULL "=" NULL */ + else if (ssup->ssup_nulls_first) + compare = -1; /* NULL "<" NOT_NULL */ + else + compare = 1; /* NULL ">" NOT_NULL */ + } else if (isNull2) { + if (ssup->ssup_nulls_first) + compare = 1; /* NOT_NULL ">" NULL */ + else + compare = -1; /* NOT_NULL "<" NULL */ + } else { + compare = (*ssup->abbrev_full_comparator)(datum1, datum2, ssup); + if (ssup->ssup_reverse) + compare = -compare; + } + + return compare; +} +#else +extern int ApplySortAbbrevFullComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup); +#endif /* USE_INLINE */ + +#endif /* SORTSUPPORT_GS_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/utils/sortsupport.h postgresql-hll-2.14/include/utils/sortsupport.h --- postgresql-hll-2.14_old/include/utils/sortsupport.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/sortsupport.h 2020-12-12 17:06:43.406350090 +0800 @@ -0,0 +1,228 @@ +/* ------------------------------------------------------------------------- + * + * sortsupport.h + * Framework for accelerated sorting. + * + * Traditionally, PostgreSQL has implemented sorting by repeatedly invoking + * an SQL-callable comparison function "cmp(x, y) returns int" on pairs of + * values to be compared, where the comparison function is the BTORDER_PROC + * pg_amproc support function of the appropriate btree index opclass. + * + * This file defines alternative APIs that allow sorting to be performed with + * reduced overhead. To support lower-overhead sorting, a btree opclass may + * provide a BTSORTSUPPORT_PROC pg_amproc entry, which must take a single + * argument of type internal and return void. The argument is actually a + * pointer to a SortSupportData struct, which is defined below. + * + * If provided, the BTSORTSUPPORT function will be called during sort setup, + * and it must initialize the provided struct with pointers to function(s) + * that can be called to perform sorting. This API is defined to allow + * multiple acceleration mechanisms to be supported, but no opclass is + * required to provide all of them. The BTSORTSUPPORT function should + * simply not set any function pointers for mechanisms it doesn't support. + * (However, all opclasses that provide BTSORTSUPPORT are required to provide + * the comparator function.) + * + * All sort support functions will be passed the address of the + * SortSupportData struct when called, so they can use it to store + * additional private data as needed. In particular, for collation-aware + * datatypes, the ssup_collation field is set before calling BTSORTSUPPORT + * and is available to all support functions. Additional opclass-dependent + * data can be stored using the ssup_extra field. Any such data + * should be allocated in the ssup_cxt memory context. + * + * Note: since pg_amproc functions are indexed by (lefttype, righttype) + * it is possible to associate a BTSORTSUPPORT function with a cross-type + * comparison. This could sensibly be used to provide a fast comparator + * function for such cases, but probably not any other acceleration method. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/sortsupport.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SORTSUPPORT_H +#define SORTSUPPORT_H + +#include "access/attnum.h" + +typedef struct SortSupportData* SortSupport; + +typedef struct SortSupportData { + /* + * These fields are initialized before calling the BTSORTSUPPORT function + * and should not be changed later. + */ + MemoryContext ssup_cxt; /* Context containing sort info */ + Oid ssup_collation; /* Collation to use, or InvalidOid */ + + /* + * Additional sorting parameters; but unlike ssup_collation, these can be + * changed after BTSORTSUPPORT is called, so don't use them in selecting + * sort support functions. + */ + bool ssup_reverse; /* descending-order sort? */ + bool ssup_nulls_first; /* sort nulls first? */ + + /* + * These fields are workspace for callers, and should not be touched by + * opclass-specific functions. + */ + AttrNumber ssup_attno; /* column number to sort */ + + /* + * ssup_extra is zeroed before calling the BTSORTSUPPORT function, and is + * not touched subsequently by callers. + */ + void* ssup_extra; /* Workspace for opclass functions */ + + /* + * Function pointers are zeroed before calling the BTSORTSUPPORT function, + * and must be set by it for any acceleration methods it wants to supply. + * The comparator pointer must be set, others are optional. + */ + + /* + * Comparator function has the same API as the traditional btree + * comparison function, ie, return <0, 0, or >0 according as x is less + * than, equal to, or greater than y. Note that x and y are guaranteed + * not null, and there is no way to return null either. Do not return + * INT_MIN, as callers are allowed to negate the result before using it. + * + * This may be either the authoritative comparator, or the abbreviated + * comparator. Core code may switch this over the initial preference of an + * opclass support function despite originally indicating abbreviation was + * applicable, by assigning the authoritative comparator back. + */ + int (*comparator)(Datum x, Datum y, SortSupport ssup); + + /* + * "Abbreviated key" infrastructure follows. + * + * All callbacks must be set by sortsupport opclasses that make use of this + * optional additional infrastructure (unless for whatever reasons the + * opclass doesn't proceed with abbreviation, in which case + * abbrev_converter must not be set). + * + * This allows opclass authors to supply a conversion routine, used to + * create an alternative representation of the underlying type (an + * "abbreviated key"). Typically, this representation is an ad-hoc, + * pass-by-value Datum format that only the opclass has knowledge of. An + * alternative comparator, used only with this alternative representation + * must also be provided (which is assigned to "comparator"). This + * representation is a simple approximation of the original Datum. It must + * be possible to compare datums of this representation with each other + * using the supplied alternative comparator, and have any non-zero return + * value be a reliable proxy for what a proper comparison would indicate. + * Returning zero from the alternative comparator does not indicate + * equality, as with a conventional support routine 1, though -- it + * indicates that it wasn't possible to determine how the two abbreviated + * values compared. A proper comparison, using "abbrev_full_comparator"/ + * ApplySortAbbrevFullComparator() is therefore required. In many cases + * this results in most or all comparisons only using the cheap alternative + * comparison func, which is typically implemented as code that compiles to + * just a few CPU instructions. CPU cache miss penalties are expensive; to + * get good overall performance, sort infrastructure must heavily weigh + * cache performance. + * + * Opclass authors must consider the final cardinality of abbreviated keys + * when devising an encoding scheme. It's possible for a strategy to work + * better than an alternative strategy with one usage pattern, while the + * reverse might be true for another usage pattern. All of these factors + * must be considered. + */ + + /* + * "abbreviate" concerns whether or not the abbreviated key optimization is + * applicable in principle (that is, the sortsupport routine needs to know + * if its dealing with a key where an abbreviated representation can + * usefully be packed together. Conventionally, this is the leading + * attribute key). Note, however, that in order to determine that + * abbreviation is not in play, the core code always checks whether or not + * the opclass has set abbrev_converter. This is a one way, one time + * message to the opclass. + */ + bool abbreviate; + + /* + * Converter to abbreviated format, from original representation. Core + * code uses this callback to convert from a pass-by-reference "original" + * Datum to a pass-by-value abbreviated key Datum. Note that original is + * guaranteed NOT NULL, because it doesn't make sense to factor NULLness + * into ad-hoc cost model. + * + * abbrev_converter is tested to see if abbreviation is in play. Core code + * may set it to NULL to indicate abbreviation should not be used (which is + * something sortsupport routines need not concern themselves with). + * However, sortsupport routines must not set it when it is immediately + * established that abbreviation should not proceed (for abbreviation + * calls, or platform-specific impediments to using abbreviation). + */ + Datum (*abbrev_converter)(Datum original, SortSupport ssup); + + /* + * abbrev_abort callback allows clients to verify that the current strategy + * is working out, using a sortsupport routine defined ad-hoc cost model. + * If there is a lot of duplicate abbreviated keys in practice, it's useful + * to be able to abandon the strategy before paying too high a cost in + * conversion (perhaps certain opclass-specific adaptations are useful + * too). + */ + bool (*abbrev_abort)(int memtupcount, SortSupport ssup); + + /* + * Full, authoritative comparator for key that an abbreviated + * representation was generated for, used when an abbreviated comparison + * was inconclusive (by calling ApplySortComparatorFull()), or used to + * replace "comparator" when core system ultimately decides against + * abbreviation. + */ + int (*abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup); +} SortSupportData; + +/* ApplySortComparator should be inlined if possible */ +#ifdef USE_INLINE + +/* + * Apply a sort comparator function and return a 3-way comparison result. + * This takes care of handling reverse-sort and NULLs-ordering properly. + */ +static inline int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup) +{ + int compare; + + if (isNull1) { + if (isNull2) + compare = 0; /* NULL "=" NULL */ + else if (ssup->ssup_nulls_first) + compare = -1; /* NULL "<" NOT_NULL */ + else + compare = 1; /* NULL ">" NOT_NULL */ + } else if (isNull2) { + if (ssup->ssup_nulls_first) + compare = 1; /* NOT_NULL ">" NULL */ + else + compare = -1; /* NOT_NULL "<" NULL */ + } else { + compare = (*ssup->comparator)(datum1, datum2, ssup); + if (ssup->ssup_reverse) + compare = -compare; + } + + return compare; +} + +#else + +extern int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup); + +#endif /* USE_INLINE */ + +/* Other functions in utils/sort/sortsupport.c */ +extern void PrepareSortSupportComparisonShim(Oid cmpFunc, SortSupport ssup); +extern void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup); + +#endif /* SORTSUPPORT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/spccache.h postgresql-hll-2.14/include/utils/spccache.h --- postgresql-hll-2.14_old/include/utils/spccache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/spccache.h 2020-12-12 17:06:43.406350090 +0800 @@ -0,0 +1,18 @@ +/* ------------------------------------------------------------------------- + * + * spccache.h + * Tablespace cache. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/spccache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SPCCACHE_H +#define SPCCACHE_H + +void get_tablespace_page_costs(Oid spcid, float8* spc_random_page_cost, float8* spc_seq_page_cost); + +#endif /* SPCCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/syscache.h postgresql-hll-2.14/include/utils/syscache.h --- postgresql-hll-2.14_old/include/utils/syscache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/syscache.h 2020-12-12 17:06:43.406350090 +0800 @@ -0,0 +1,214 @@ +/* ------------------------------------------------------------------------- + * + * syscache.h + * System catalog cache definitions. + * + * See also lsyscache.h, which provides convenience routines for + * common cache-lookup operations. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * Portions Copyright (c) 2010-2012 Postgres-XC Development Group + * + * src/include/utils/syscache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef SYSCACHE_H +#define SYSCACHE_H + +#include "utils/catcache.h" + +/* + * SysCache identifiers. + * + * The order of these identifiers must match the order + * of the entries in the array cacheinfo[] in syscache.c. + * Keep them in alphabetical order (renumbering only costs a + * backend rebuild). + */ +#define STATRELATTINH STATRELKINDATTINH + +enum SysCacheIdentifier { + AGGFNOID = 0, + AMNAME, + AMOID, + AMOPOPID, + AMOPSTRATEGY, + AMPROCNUM, + ATTNAME, + ATTNUM, + AUTHMEMMEMROLE, + AUTHMEMROLEMEM, + AUTHNAME, + AUTHOID, + BUCKETRELID, + CASTSOURCETARGET, + CEOID, + CERELIDCOUMNNAME, + CLAAMNAMENSP, + CLAOID, + COLLNAMEENCNSP, + COLLOID, + COLUMNSETTINGDISTID, + COLUMNSETTINGNAME, + COLUMNSETTINGOID, + CONDEFAULT, + CONNAMENSP, + CONSTROID, + CONVOID, + DATABASEOID, + DATASOURCENAME, + DATASOURCEOID, + DEFACLROLENSPOBJ, + DIRECTORYNAME, + DIRECTORYOID, + ENUMOID, + ENUMTYPOIDNAME, + FOREIGNDATAWRAPPERNAME, + FOREIGNDATAWRAPPEROID, + FOREIGNSERVERNAME, + FOREIGNSERVEROID, + FOREIGNTABLEREL, + GLOBALSETTINGNAME, + GLOBALSETTINGOID, + INDEXRELID, + LANGNAME, + LANGOID, + NAMESPACENAME, + NAMESPACEOID, + OPERNAMENSP, + OPEROID, + OPFAMILYAMNAMENSP, + OPFAMILYOID, + PARTRELID, + PARTPARTOID, + PGJOBID, + PGJOBPROCID, + PGOBJECTID, +#ifdef PGXC + PGXCCLASSRELID, + PGXCGROUPNAME, + PGXCGROUPOID, + PGXCNODENAME, + PGXCNODEOID, + PGXCNODEIDENTIFIER, + PGXCRESOURCEPOOLNAME, + PGXCRESOURCEPOOLOID, + PGXCWORKLOADGROUPNAME, + PGXCWORKLOADGROUPOID, + PGXCAPPWGMAPPINGNAME, + PGXCAPPWGMAPPINGOID, + PGXCSLICERELID, +#endif + POLICYLABELNAME, + POLICYLABELOID, + PROCNAMEARGSNSP, + PROCOID, + RANGETYPE, + RELNAMENSP, + RELOID, + RULERELNAME, + STATRELKINDATTINH, /* single column statistics */ + STATRELKINDKEYINH, /* multi column statistics */ + STREAMCQDEFRELID, + STREAMCQID, + STREAMCQLOOKUPID, + STREAMCQMATRELID, + STREAMCQOID, + STREAMCQRELID, + STREAMCQSCHEMACHANGE, + STREAMOID, + STREAMRELID, + REAPERCQOID, + REAPERSTATUSOID, + SYNOID, + SYNONYMNAMENSP, + TABLESPACEOID, + TSCONFIGMAP, + TSCONFIGNAMENSP, + TSCONFIGOID, + TSDICTNAMENSP, + TSDICTOID, + TSPARSERNAMENSP, + TSPARSEROID, + TSTEMPLATENAMENSP, + TSTEMPLATEOID, + TYPENAMENSP, + TYPEOID, + USERMAPPINGOID, + USERMAPPINGUSERSERVER, + USERSTATUSOID, + USERSTATUSROLEID, + STREAMINGGATHERAGGOID +}; + +extern int SysCacheSize; + +extern void InitCatalogCache(void); +extern void InitCatalogCachePhase2(void); + +extern HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4, int level = DEBUG2); +/* + * The use of argument specific numbers is encouraged. They're faster, andTENAMENSP,TENAMENSP, + * insulates the caller from changes in the maximum number of keys. + */ +extern HeapTuple SearchSysCache1(int cacheId, Datum key1); +extern HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2); +extern HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3); +extern HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +extern void ReleaseSysCache(HeapTuple tuple); + +/* convenience routines */ +extern HeapTuple SearchSysCacheCopy(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4, int level = DEBUG2); +extern bool SearchSysCacheExists(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); +extern Oid GetSysCacheOid(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +extern HeapTuple SearchSysCacheAttName(Oid relid, const char* attname); +extern HeapTuple SearchSysCacheCopyAttName(Oid relid, const char* attname); +extern bool SearchSysCacheExistsAttName(Oid relid, const char* attname); + +extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool* isNull); + +extern uint32 GetSysCacheHashValue(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4); + +/* list-search interface. Users of this must import catcache.h too */ +extern struct catclist* SearchSysCacheList(int cacheId, int nkeys, Datum key1, Datum key2, Datum key3, Datum key4); + +/* + * The use of the macros below rather than direct calls to the corresponding + * functions is encouraged, as it insulates the caller from changes in the + * maximum number of keys. + */ +#define SearchSysCache1WithLogLevel(cacheId, key1, level) SearchSysCache(cacheId, key1, 0, 0, 0, level) + +#define SearchSysCacheCopy1(cacheId, key1) SearchSysCacheCopy(cacheId, key1, 0, 0, 0) +#define SearchSysCacheCopy2(cacheId, key1, key2) SearchSysCacheCopy(cacheId, key1, key2, 0, 0) +#define SearchSysCacheCopy3(cacheId, key1, key2, key3) SearchSysCacheCopy(cacheId, key1, key2, key3, 0) +#define SearchSysCacheCopy4(cacheId, key1, key2, key3, key4) SearchSysCacheCopy(cacheId, key1, key2, key3, key4) +#define SearchSysCacheCopyWithLogLevel(cacheId, key1, level) SearchSysCacheCopy(cacheId, key1, 0, 0, 0, level) + +#define SearchSysCacheExists1(cacheId, key1) SearchSysCacheExists(cacheId, key1, 0, 0, 0) +#define SearchSysCacheExists2(cacheId, key1, key2) SearchSysCacheExists(cacheId, key1, key2, 0, 0) +#define SearchSysCacheExists3(cacheId, key1, key2, key3) SearchSysCacheExists(cacheId, key1, key2, key3, 0) +#define SearchSysCacheExists4(cacheId, key1, key2, key3, key4) SearchSysCacheExists(cacheId, key1, key2, key3, key4) + +#define GetSysCacheOid1(cacheId, key1) GetSysCacheOid(cacheId, key1, 0, 0, 0) +#define GetSysCacheOid2(cacheId, key1, key2) GetSysCacheOid(cacheId, key1, key2, 0, 0) +#define GetSysCacheOid3(cacheId, key1, key2, key3) GetSysCacheOid(cacheId, key1, key2, key3, 0) +#define GetSysCacheOid4(cacheId, key1, key2, key3, key4) GetSysCacheOid(cacheId, key1, key2, key3, key4) + +#define GetSysCacheHashValue1(cacheId, key1) GetSysCacheHashValue(cacheId, key1, 0, 0, 0) +#define GetSysCacheHashValue2(cacheId, key1, key2) GetSysCacheHashValue(cacheId, key1, key2, 0, 0) +#define GetSysCacheHashValue3(cacheId, key1, key2, key3) GetSysCacheHashValue(cacheId, key1, key2, key3, 0) +#define GetSysCacheHashValue4(cacheId, key1, key2, key3, key4) GetSysCacheHashValue(cacheId, key1, key2, key3, key4) + +#define SearchSysCacheList1(cacheId, key1) SearchSysCacheList(cacheId, 1, key1, 0, 0, 0) +#define SearchSysCacheList2(cacheId, key1, key2) SearchSysCacheList(cacheId, 2, key1, key2, 0, 0) +#define SearchSysCacheList3(cacheId, key1, key2, key3) SearchSysCacheList(cacheId, 3, key1, key2, key3, 0) +#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) SearchSysCacheList(cacheId, 4, key1, key2, key3, key4) + +#define ReleaseSysCacheList(x) ReleaseCatCacheList(x) + +#endif /* SYSCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/syscall_lock.h postgresql-hll-2.14/include/utils/syscall_lock.h --- postgresql-hll-2.14_old/include/utils/syscall_lock.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/syscall_lock.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,55 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * syscall_lock.h + * + * + * + * IDENTIFICATION + * src/include/utils/syscall_lock.h + * + * NOTE + * some function in lib has not thread safe version , use lock to protect them + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SYSCALL_LOCK_H_ +#define SYSCALL_LOCK_H_ + +#ifndef WIN32 +#include "pthread.h" +#else +#include +#include "pthread-win32.h" +#endif + +typedef pthread_mutex_t syscalllock; + +#define syscalllockInit(lock) pthread_mutex_init(lock, NULL) +#define syscalllockAcquire(lock) pthread_mutex_lock(lock) +#define syscalllockRelease(lock) pthread_mutex_unlock(lock) +#define syscalllockFree(lock) pthread_mutex_destroy(lock) + +/* + * the locks declared here should be initialized in syscall_lock_init function + */ +extern syscalllock getpwuid_lock; +extern syscalllock env_lock; +extern syscalllock dlerror_lock; +extern syscalllock kerberos_conn_lock; +extern syscalllock read_cipher_lock; + +#endif /* SYSCALL_LOCK_H_ */ diff -uprN postgresql-hll-2.14_old/include/utils/timestamp.h postgresql-hll-2.14/include/utils/timestamp.h --- postgresql-hll-2.14_old/include/utils/timestamp.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/timestamp.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,274 @@ +/* ------------------------------------------------------------------------- + * + * timestamp.h + * Definitions for the SQL92 "timestamp" and "interval" types. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/timestamp.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TIMESTAMP_H +#define TIMESTAMP_H + +#define TIMESTAMP_MASK(b) (1 << (b)) +#define INTERVAL_MASK(b) (1 << (b)) + +/* Macros to handle packing and unpacking the typmod field for intervals */ +#define INTERVAL_FULL_RANGE (0x7FFF) +#define INTERVAL_RANGE_MASK (0x7FFF) +#define INTERVAL_FULL_PRECISION (0xFFFF) +#define INTERVAL_PRECISION_MASK (0xFFFF) +#define INTERVAL_TYPMOD(p, r) ((((r)&INTERVAL_RANGE_MASK) << 16) | ((p)&INTERVAL_PRECISION_MASK)) +#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK) +#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK) + + +#ifndef FRONTEND_PARSER +#include "datatype/timestamp.h" +#include "fmgr.h" +#include "pgtime.h" + +/* + * Macros for fmgr-callable functions. + * + * For Timestamp, we make use of the same support routines as for int64 + * or float8. Therefore Timestamp is pass-by-reference if and only if + * int64 or float8 is! + */ +#ifdef HAVE_INT64_TIMESTAMP + +#define DatumGetTimestamp(X) ((Timestamp)DatumGetInt64(X)) +#define DatumGetTimestampTz(X) ((TimestampTz)DatumGetInt64(X)) +#define DatumGetIntervalP(X) ((Interval*)DatumGetPointer(X)) + +#define TimestampGetDatum(X) Int64GetDatum(X) +#define TimestampTzGetDatum(X) Int64GetDatum(X) +#define IntervalPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n)) +#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x) +#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x) +#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x) +#else /* !HAVE_INT64_TIMESTAMP */ + +#define DatumGetTimestamp(X) ((Timestamp)DatumGetFloat8(X)) +#define DatumGetTimestampTz(X) ((TimestampTz)DatumGetFloat8(X)) +#define DatumGetIntervalP(X) ((Interval*)DatumGetPointer(X)) + +#define TimestampGetDatum(X) Float8GetDatum(X) +#define TimestampTzGetDatum(X) Float8GetDatum(X) +#define IntervalPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n)) +#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n)) +#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n)) + +#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x) +#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x) +#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x) +#endif /* HAVE_INT64_TIMESTAMP */ + +#ifdef HAVE_INT64_TIMESTAMP +#define TimestampTzPlusMilliseconds(tz, ms) ((tz) + ((ms) * (int64)1000)) +#else +#define TimestampTzPlusMilliseconds(tz, ms) ((tz) + ((ms) / 1000.0)) +#endif + +#ifdef PGXC +#define InvalidGlobalTimestamp ((TimestampTz)0) +#define GlobalTimestampIsValid(timestamp) ((TimestampTz)(timestamp)) != InvalidGlobalTimestamp +#endif + +#ifndef MAX_INT32 +#define MAX_INT32 2147483600 +#endif + +/* + * timestamp.c prototypes + */ +extern Datum smalldatetime_eq(PG_FUNCTION_ARGS); +extern Datum smalldatetime_ne(PG_FUNCTION_ARGS); +extern Datum smalldatetime_lt(PG_FUNCTION_ARGS); +extern Datum smalldatetime_gt(PG_FUNCTION_ARGS); +extern Datum smalldatetime_le(PG_FUNCTION_ARGS); +extern Datum smalldatetime_ge(PG_FUNCTION_ARGS); +extern Datum smalldatetime_cmp(PG_FUNCTION_ARGS); +extern Datum smalldatetime_hash(PG_FUNCTION_ARGS); +extern Datum smalldatetime_in(PG_FUNCTION_ARGS); +extern Datum smalldatetime_out(PG_FUNCTION_ARGS); +extern Datum smalldatetime_recv(PG_FUNCTION_ARGS); +extern Datum smalldatetime_send(PG_FUNCTION_ARGS); +extern Datum smalldatetime_smaller(PG_FUNCTION_ARGS); +extern Datum smalldatetime_larger(PG_FUNCTION_ARGS); +extern Datum timestamp_in(PG_FUNCTION_ARGS); +extern Datum timestamp_out(PG_FUNCTION_ARGS); +extern Datum timestamp_recv(PG_FUNCTION_ARGS); +extern Datum timestamp_send(PG_FUNCTION_ARGS); +extern Datum timestamptypmodin(PG_FUNCTION_ARGS); +extern Datum timestamptypmodout(PG_FUNCTION_ARGS); +extern Datum timestamp_transform(PG_FUNCTION_ARGS); +extern Datum timestamp_scale(PG_FUNCTION_ARGS); +extern Datum timestamp_eq(PG_FUNCTION_ARGS); +extern Datum timestamp_ne(PG_FUNCTION_ARGS); +extern Datum timestamp_lt(PG_FUNCTION_ARGS); +extern Datum timestamp_le(PG_FUNCTION_ARGS); +extern Datum timestamp_ge(PG_FUNCTION_ARGS); +extern Datum timestamp_gt(PG_FUNCTION_ARGS); +extern Datum timestamp_finite(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp(PG_FUNCTION_ARGS); +extern Datum timestamp_sortsupport(PG_FUNCTION_ARGS); +extern Datum timestamp_hash(PG_FUNCTION_ARGS); +extern Datum timestamp_smaller(PG_FUNCTION_ARGS); +extern Datum timestamp_larger(PG_FUNCTION_ARGS); +extern Datum to_date_default_format(PG_FUNCTION_ARGS); + +extern Datum timestamp_eq_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_ne_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_lt_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_le_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_gt_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_ge_timestamptz(PG_FUNCTION_ARGS); +extern Datum timestamp_cmp_timestamptz(PG_FUNCTION_ARGS); + +extern Datum timestamptz_eq_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_ne_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_lt_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_le_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_gt_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_ge_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_cmp_timestamp(PG_FUNCTION_ARGS); +extern Datum add_months(PG_FUNCTION_ARGS); +extern Datum next_day_str(PG_FUNCTION_ARGS); +extern Datum next_day_int(PG_FUNCTION_ARGS); +extern Datum last_day(PG_FUNCTION_ARGS); + +extern Datum interval_in(PG_FUNCTION_ARGS); +extern Datum interval_out(PG_FUNCTION_ARGS); +extern Datum interval_recv(PG_FUNCTION_ARGS); +extern Datum interval_send(PG_FUNCTION_ARGS); +extern Datum intervaltypmodin(PG_FUNCTION_ARGS); +extern Datum intervaltypmodout(PG_FUNCTION_ARGS); +extern Datum interval_transform(PG_FUNCTION_ARGS); +extern Datum interval_scale(PG_FUNCTION_ARGS); +extern Datum interval_eq_withhead(PG_FUNCTION_ARGS); +extern Datum interval_eq(PG_FUNCTION_ARGS); +extern Datum interval_ne(PG_FUNCTION_ARGS); +extern Datum interval_lt(PG_FUNCTION_ARGS); +extern Datum interval_le(PG_FUNCTION_ARGS); +extern Datum interval_ge(PG_FUNCTION_ARGS); +extern Datum interval_gt(PG_FUNCTION_ARGS); +extern Datum interval_finite(PG_FUNCTION_ARGS); +extern Datum interval_cmp(PG_FUNCTION_ARGS); +extern Datum interval_hash(PG_FUNCTION_ARGS); +extern Datum interval_smaller(PG_FUNCTION_ARGS); +extern Datum interval_larger(PG_FUNCTION_ARGS); +extern Datum interval_justify_interval(PG_FUNCTION_ARGS); +extern Datum interval_justify_hours(PG_FUNCTION_ARGS); +extern Datum interval_justify_days(PG_FUNCTION_ARGS); + +extern Datum timestamp_trunc(PG_FUNCTION_ARGS); +extern Datum interval_trunc(PG_FUNCTION_ARGS); +extern Datum timestamp_part(PG_FUNCTION_ARGS); +extern Datum interval_part(PG_FUNCTION_ARGS); +extern Datum timestamp_zone(PG_FUNCTION_ARGS); +extern Datum timestamp_izone(PG_FUNCTION_ARGS); +extern Datum timestamp_timestamptz(PG_FUNCTION_ARGS); + +extern Datum timestamptz_in(PG_FUNCTION_ARGS); +extern Datum timestamptz_out(PG_FUNCTION_ARGS); +extern Datum timestamptz_recv(PG_FUNCTION_ARGS); +extern Datum timestamptz_send(PG_FUNCTION_ARGS); +extern Datum timestamptztypmodin(PG_FUNCTION_ARGS); +extern Datum timestamptztypmodout(PG_FUNCTION_ARGS); +extern Datum timestamptz_scale(PG_FUNCTION_ARGS); +extern Datum timestamptz_timestamp(PG_FUNCTION_ARGS); +extern Datum timestamptz_zone(PG_FUNCTION_ARGS); +extern Datum timestamptz_izone(PG_FUNCTION_ARGS); +extern Datum timestamptz_timestamptz(PG_FUNCTION_ARGS); + +extern Datum interval_um(PG_FUNCTION_ARGS); +extern Datum interval_pl(PG_FUNCTION_ARGS); +extern Datum interval_mi(PG_FUNCTION_ARGS); +extern Datum interval_mul(const Interval* span, float8 factor); +extern Datum interval_mul(PG_FUNCTION_ARGS); +extern Datum mul_d_interval(PG_FUNCTION_ARGS); +extern Datum interval_div(PG_FUNCTION_ARGS); +extern Datum interval_accum(PG_FUNCTION_ARGS); +#ifdef PGXC +extern Datum interval_collect(PG_FUNCTION_ARGS); +#endif +extern Datum interval_avg(PG_FUNCTION_ARGS); + +extern Datum timestamp_mi(Timestamp dt1, Timestamp dt2); +extern Datum timestamp_mi(PG_FUNCTION_ARGS); +extern Datum timestamp_pl_interval(Timestamp timestamp, const Interval* span); +extern Datum timestamp_pl_interval(PG_FUNCTION_ARGS); +extern Datum timestamp_mi_interval(Timestamp timestamp, const Interval* span); +extern Datum timestamp_mi_interval(PG_FUNCTION_ARGS); +extern Datum timestamp_age(PG_FUNCTION_ARGS); +extern Datum timestamp_diff(PG_FUNCTION_ARGS); +extern Datum overlaps_timestamp(PG_FUNCTION_ARGS); + +extern Datum timestamptz_pl_interval(PG_FUNCTION_ARGS); +extern Datum timestamptz_mi_interval(PG_FUNCTION_ARGS); +extern Datum timestamptz_age(PG_FUNCTION_ARGS); +extern Datum timestamptz_trunc(PG_FUNCTION_ARGS); +extern Datum timestamptz_part(PG_FUNCTION_ARGS); + +extern Datum now(PG_FUNCTION_ARGS); +extern Datum statement_timestamp(PG_FUNCTION_ARGS); +extern Datum clock_timestamp(PG_FUNCTION_ARGS); + +extern Datum pg_postmaster_start_time(PG_FUNCTION_ARGS); +extern Datum get_node_stat_reset_time(PG_FUNCTION_ARGS); + +extern Datum pg_conf_load_time(PG_FUNCTION_ARGS); + +extern Datum generate_series_timestamp(PG_FUNCTION_ARGS); +extern Datum generate_series_timestamptz(PG_FUNCTION_ARGS); + +/* Internal routines (not fmgr-callable) */ + +extern TimestampTz GetCurrentTimestamp(void); +extern TimestampTz timestamp2timestamptz(Timestamp timestamp); + +extern void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long* secs, int* microsecs); +extern int ComputeTimeStamp(TimestampTz start); +extern bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec); + +extern TimestampTz time_t_to_timestamptz(pg_time_t tm); +extern pg_time_t timestamptz_to_time_t(TimestampTz t); + +extern const char* timestamptz_to_str(TimestampTz t); + +extern int tm2timestamp(struct pg_tm* tm, const fsec_t fsec, const int* tzp, Timestamp* dt); +extern int timestamp2tm(Timestamp dt, int* tzp, struct pg_tm* tm, fsec_t* fsec, const char** tzn, pg_tz* attimezone); +extern void dt2time(Timestamp dt, int* hour, int* min, int* sec, fsec_t* fsec); + +extern int interval2tm(Interval span, struct pg_tm* tm, fsec_t* fsec); +extern int tm2interval(struct pg_tm* tm, fsec_t fsec, Interval* span); +extern int interval_cmp_internal(Interval* interval1, Interval* interval2); + +extern Timestamp SetEpochTimestamp(void); +extern void GetEpochTime(struct pg_tm* tm); + +extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2); + +/* timestamp comparison works for timestamptz also */ +#define timestamptz_cmp_internal(dt1, dt2) timestamp_cmp_internal(dt1, dt2) + +extern int isoweek2j(int year, int week); +extern void isoweek2date(int woy, int* year, int* mon, int* mday); +extern void isoweekdate2date(int isoweek, int isowday, int* year, int* mon, int* mday); +extern int date2isoweek(int year, int mon, int mday); +extern int date2isoyear(int year, int mon, int mday); +extern int date2isoyearday(int year, int mon, int mday); + +#endif // !FRONTEND_PARSER +#endif /* TIMESTAMP_H */ diff -uprN postgresql-hll-2.14_old/include/utils/tuplesort.h postgresql-hll-2.14/include/utils/tuplesort.h --- postgresql-hll-2.14_old/include/utils/tuplesort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/tuplesort.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,122 @@ +/* ------------------------------------------------------------------------- + * + * tuplesort.h + * Generalized tuple sorting routines. + * + * This module handles sorting of heap tuples, index tuples, or single + * Datums (and could easily support other kinds of sortable objects, + * if necessary). It works efficiently for both small and large amounts + * of data. Small amounts are sorted in-memory using qsort(). Large + * amounts are sorted using temporary files and a standard external sort + * algorithm. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tuplesort.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPLESORT_H +#define TUPLESORT_H + +#include "access/itup.h" +#include "executor/tuptable.h" +#include "fmgr.h" +#include "utils/relcache.h" +#include "utils/tuplestore.h" + +/* Tuplesortstate is an opaque type whose details are not known outside + * tuplesort.c. + */ +typedef struct Tuplesortstate Tuplesortstate; + +/* + * We provide multiple interfaces to what is essentially the same code, + * since different callers have different data to be sorted and want to + * specify the sort key information differently. There are two APIs for + * sorting HeapTuples and two more for sorting IndexTuples. Yet another + * API supports sorting bare Datums. + * + * The "heap" API actually stores/sorts MinimalTuples, which means it doesn't + * preserve the system columns (tuple identity and transaction visibility + * info). The sort keys are specified by column numbers within the tuples + * and sort operator OIDs. We save some cycles by passing and returning the + * tuples in TupleTableSlots, rather than forming actual HeapTuples (which'd + * have to be converted to MinimalTuples). This API works well for sorts + * executed as parts of plan trees. + * + * The "cluster" API stores/sorts full HeapTuples including all visibility + * info. The sort keys are specified by reference to a btree index that is + * defined on the relation to be sorted. Note that putheaptuple/getheaptuple + * go with this API, not the "begin_heap" one! + * + * The "index_btree" API stores/sorts IndexTuples (preserving all their + * header fields). The sort keys are specified by a btree index definition. + * + * The "index_hash" API is similar to index_btree, but the tuples are + * actually sorted by their hash codes not the raw data. + */ + +extern Tuplesortstate* tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber* attNums, Oid* sortOperators, + Oid* sortCollations, const bool* nullsFirstFlags, int64 workMem, bool randomAccess, int64 maxMem = 0, + int planId = 0, int dop = 1); +extern Tuplesortstate* tuplesort_begin_cluster( + TupleDesc tupDesc, Relation indexRel, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_index_btree( + Relation indexRel, bool enforceUnique, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_index_hash( + Relation indexRel, uint32 hash_mask, int workMem, bool randomAccess, int maxMem); +extern Tuplesortstate* tuplesort_begin_datum( + Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, bool randomAccess); +#ifdef PGXC +extern void tuplesort_puttupleslotontape(Tuplesortstate* state, TupleTableSlot* slot); +extern void tuplesort_remoteread_end(Tuplesortstate* state); +#endif + +extern void tuplesort_set_bound(Tuplesortstate* state, int64 bound); + +extern void tuplesort_puttupleslot(Tuplesortstate* state, TupleTableSlot* slot); +extern void tuplesort_putheaptuple(Tuplesortstate* state, HeapTuple tup); +extern void tuplesort_putindextuplevalues( + Tuplesortstate* state, Relation rel, ItemPointer self, Datum* values, const bool* isnull); +extern void tuplesort_putdatum(Tuplesortstate* state, Datum val, bool isNull); + +extern void tuplesort_performsort(Tuplesortstate* state); + +extern bool tuplesort_gettupleslot(Tuplesortstate* state, bool forward, TupleTableSlot* slot, Datum* abbrev); +extern bool tuplesort_gettupleslot_into_tuplestore( + Tuplesortstate* state, bool forward, TupleTableSlot* slot, Datum* abbrev, Tuplestorestate* tstate); +extern HeapTuple tuplesort_getheaptuple(Tuplesortstate* state, bool forward, bool* should_free); +extern IndexTuple tuplesort_getindextuple(Tuplesortstate* state, bool forward, bool* should_free); +extern bool tuplesort_getdatum(Tuplesortstate* state, bool forward, Datum* val, bool* isNull); + +extern void tuplesort_end(Tuplesortstate* state); + +extern void tuplesort_get_stats(Tuplesortstate* state, int* sortMethodId, int* spaceTypeId, long* spaceUsed); + +extern int tuplesort_merge_order(double allowedMem); + +/* + * These routines may only be called if randomAccess was specified 'true'. + * Likewise, backwards scan in gettuple/getdatum is only allowed if + * randomAccess was specified. + */ + +extern void tuplesort_rescan(Tuplesortstate* state); +extern void tuplesort_markpos(Tuplesortstate* state); +extern void tuplesort_restorepos(Tuplesortstate* state); + +extern void sort_count(Tuplesortstate* state); + +extern int64 tuplesort_get_avgwidth(Tuplesortstate* state); +extern bool tuplesort_get_busy_status(Tuplesortstate* state); +extern int tuplesort_get_spread_num(Tuplesortstate* state); +extern bool tuplesort_skiptuples(Tuplesortstate* state, int64 ntuples, bool forward); + +/* + * Return the int64 value of tuplesortstate->peakMemorySize + */ +extern int64 tuplesort_get_peak_memory(Tuplesortstate* state); + +#endif /* TUPLESORT_H */ diff -uprN postgresql-hll-2.14_old/include/utils/tuplestore.h postgresql-hll-2.14/include/utils/tuplestore.h --- postgresql-hll-2.14_old/include/utils/tuplestore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/tuplestore.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * tuplestore.h + * Generalized routines for temporary tuple storage. + * + * This module handles temporary storage of tuples for purposes such + * as Materialize nodes, hashjoin batch files, etc. It is essentially + * a dumbed-down version of tuplesort.c; it does no sorting of tuples + * but can only store and regurgitate a sequence of tuples. However, + * because no sort is required, it is allowed to start reading the sequence + * before it has all been written. This is particularly useful for cursors, + * because it allows random access within the already-scanned portion of + * a query without having to process the underlying scan to completion. + * Also, it is possible to support multiple independent read pointers. + * + * A temporary file is used to handle the data if it exceeds the + * space limit specified by the caller. + * + * Beginning in Postgres 8.2, what is stored is just MinimalTuples; + * callers cannot expect valid system columns in regurgitated tuples. + * Also, we have changed the API to return tuples in TupleTableSlots, + * so that there is a check to prevent attempted access to system columns. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tuplestore.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TUPLESTORE_H +#define TUPLESTORE_H + +#include "executor/tuptable.h" + +/* Tuplestorestate is an opaque type whose details are not known outside + * tuplestore.c. + */ +typedef struct Tuplestorestate Tuplestorestate; + +/* + * Currently we only need to store MinimalTuples, but it would be easy + * to support the same behavior for IndexTuples and/or bare Datums. + */ + +extern Tuplestorestate* tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes, int maxMem = 0, + int planId = 0, int dop = 1, bool isAddMemCtl = false); + +extern void tuplestore_set_eflags(Tuplestorestate* state, int eflags); + +extern void tuplestore_puttupleslot(Tuplestorestate* state, TupleTableSlot* slot, bool need_transform_anyarray = false); +extern void tuplestore_puttuple(Tuplestorestate* state, HeapTuple tuple); +extern void tuplestore_putvalues(Tuplestorestate* state, TupleDesc tdesc, Datum* values, const bool* isnull); + +/* tuplestore_donestoring() used to be required, but is no longer used */ +#define tuplestore_donestoring(state) ((void)0) + +extern int tuplestore_alloc_read_pointer(Tuplestorestate* state, int eflags); + +extern void tuplestore_select_read_pointer(Tuplestorestate* state, int ptr); + +extern void tuplestore_copy_read_pointer(Tuplestorestate* state, int srcptr, int destptr); + +extern void tuplestore_trim(Tuplestorestate* state); + +extern bool tuplestore_in_memory(Tuplestorestate* state); + +extern bool tuplestore_gettupleslot(Tuplestorestate* state, bool forward, bool copy, TupleTableSlot* slot); +extern bool tuplestore_advance(Tuplestorestate* state, bool forward); + +extern bool tuplestore_ateof(Tuplestorestate* state); + +extern void tuplestore_rescan(Tuplestorestate* state); + +extern void tuplestore_clear(Tuplestorestate* state); + +extern void tuplestore_end(Tuplestorestate* state); + +extern int64 tuplestore_get_avgwidth(Tuplestorestate* state); +extern bool tuplestore_get_busy_status(Tuplestorestate* state); +extern int tuplestore_get_spread_num(Tuplestorestate* state); + +#endif /* TUPLESTORE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/typcache.h postgresql-hll-2.14/include/utils/typcache.h --- postgresql-hll-2.14_old/include/utils/typcache.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/typcache.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,121 @@ +/* ------------------------------------------------------------------------- + * + * typcache.h + * Type cache definitions. + * + * The type cache exists to speed lookup of certain information about data + * types that is not directly available from a type's pg_type row. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/typcache.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TYPCACHE_H +#define TYPCACHE_H + +#include "access/tupdesc.h" +#include "fmgr.h" + +/* TypeCacheEnumData is an opaque struct known only within typcache.c */ +struct TypeCacheEnumData; + +typedef struct TypeCacheEntry { + /* typeId is the hash lookup key and MUST BE FIRST */ + Oid type_id; /* OID of the data type */ + + /* some subsidiary information copied from the pg_type row */ + int16 typlen; + bool typbyval; + char typalign; + char typstorage; + char typtype; + Oid typrelid; + + /* + * Information obtained from opfamily entries + * + * These will be InvalidOid if no match could be found, or if the + * information hasn't yet been requested. Also note that for array and + * composite types, typcache.c checks that the contained types are + * comparable or hashable before allowing eq_opr etc to become set. + */ + Oid btree_opf; /* the default btree opclass' family */ + Oid btree_opintype; /* the default btree opclass' opcintype */ + Oid hash_opf; /* the default hash opclass' family */ + Oid hash_opintype; /* the default hash opclass' opcintype */ + Oid eq_opr; /* the equality operator */ + Oid lt_opr; /* the less-than operator */ + Oid gt_opr; /* the greater-than operator */ + Oid cmp_proc; /* the btree comparison function */ + Oid hash_proc; /* the hash calculation function */ + + /* + * Pre-set-up fmgr call info for the equality operator, the btree + * comparison function, and the hash calculation function. These are kept + * in the type cache to avoid problems with memory leaks in repeated calls + * to functions such as array_eq, array_cmp, hash_array. There is not + * currently a need to maintain call info for the lt_opr or gt_opr. + */ + FmgrInfo eq_opr_finfo; + FmgrInfo cmp_proc_finfo; + FmgrInfo hash_proc_finfo; + + /* + * Tuple descriptor if it's a composite type (row type). NULL if not + * composite or information hasn't yet been requested. (NOTE: this is a + * reference-counted tupledesc.) + */ + TupleDesc tupDesc; + + /* + * Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not + * a range type or information hasn't yet been requested. Note that + * rng_cmp_proc_finfo could be different from the element type's default + * btree comparison function. + */ + struct TypeCacheEntry* rngelemtype; /* range's element type */ + Oid rng_collation; /* collation for comparisons, if any */ + FmgrInfo rng_cmp_proc_finfo; /* comparison function */ + FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */ + FmgrInfo rng_subdiff_finfo; /* difference function, if any */ + + /* Private data, for internal use of typcache.c only */ + int flags; /* flags about what we've computed */ + + /* + * Private information about an enum type. NULL if not enum or + * information hasn't been requested. + */ + struct TypeCacheEnumData* enumData; +} TypeCacheEntry; + +/* Bit flags to indicate which fields a given caller needs to have set */ +#define TYPECACHE_EQ_OPR 0x0001 +#define TYPECACHE_LT_OPR 0x0002 +#define TYPECACHE_GT_OPR 0x0004 +#define TYPECACHE_CMP_PROC 0x0008 +#define TYPECACHE_HASH_PROC 0x0010 +#define TYPECACHE_EQ_OPR_FINFO 0x0020 +#define TYPECACHE_CMP_PROC_FINFO 0x0040 +#define TYPECACHE_HASH_PROC_FINFO 0x0080 +#define TYPECACHE_TUPDESC 0x0100 +#define TYPECACHE_BTREE_OPFAMILY 0x0200 +#define TYPECACHE_HASH_OPFAMILY 0x0400 +#define TYPECACHE_RANGE_INFO 0x0800 + +extern TypeCacheEntry* lookup_type_cache(Oid type_id, int flags); + +extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod); + +extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError); + +extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod); + +extern void assign_record_type_typmod(TupleDesc tupDesc); + +extern int compare_values_of_enum(TypeCacheEntry* tcache, Oid arg1, Oid arg2); + +#endif /* TYPCACHE_H */ diff -uprN postgresql-hll-2.14_old/include/utils/tzparser.h postgresql-hll-2.14/include/utils/tzparser.h --- postgresql-hll-2.14_old/include/utils/tzparser.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/tzparser.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,35 @@ +/* ------------------------------------------------------------------------- + * + * tzparser.h + * Timezone offset file parsing definitions. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/tzparser.h + * + * ------------------------------------------------------------------------- + */ +#ifndef TZPARSER_H +#define TZPARSER_H + +#include "utils/datetime.h" + +/* + * The result of parsing a timezone configuration file is an array of + * these structs, in order by abbrev. We export this because datetime.c + * needs it. + */ +typedef struct tzEntry { + /* the actual data: TZ abbrev (downcased), offset, DST flag */ + char* abbrev; + int offset; /* in seconds from UTC */ + bool is_dst; + /* source information (for error messages) */ + int lineno; + const char* filename; +} tzEntry; + +extern TimeZoneAbbrevTable* load_tzoffsets(const char* filename); + +#endif /* TZPARSER_H */ diff -uprN postgresql-hll-2.14_old/include/utils/uuid.h postgresql-hll-2.14/include/utils/uuid.h --- postgresql-hll-2.14_old/include/utils/uuid.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/uuid.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,34 @@ +/* ------------------------------------------------------------------------- + * + * uuid.h + * Header file for the "uuid" ADT. In C, we use the name pg_uuid_t, + * to avoid conflicts with any uuid_t type that might be defined by + * the system headers. + * + * Copyright (c) 2007-2012, PostgreSQL Global Development Group + * + * src/include/utils/uuid.h + * + * ------------------------------------------------------------------------- + */ +#ifndef UUID_H +#define UUID_H + +/* guid size in bytes */ +#define UUID_LEN 16 + +struct pg_uuid_t { + unsigned char data[UUID_LEN]; +}; + +/* opaque struct; defined in uuid.c */ +typedef struct pg_uuid_t pg_uuid_t; + +/* fmgr interface macros */ +#define UUIDPGetDatum(X) PointerGetDatum(X) +#define PG_RETURN_UUID_P(X) return UUIDPGetDatum(X) +#define DatumGetUUIDP(X) ((pg_uuid_t*)DatumGetPointer(X)) +#define PG_GETARG_UUID_P(X) DatumGetUUIDP(PG_GETARG_DATUM(X)) + +Datum uuid_hash(PG_FUNCTION_ARGS); +#endif /* UUID_H */ diff -uprN postgresql-hll-2.14_old/include/utils/varbit.h postgresql-hll-2.14/include/utils/varbit.h --- postgresql-hll-2.14_old/include/utils/varbit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/varbit.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,110 @@ +/* ------------------------------------------------------------------------- + * + * varbit.h + * Functions for the SQL datatypes BIT() and BIT VARYING(). + * + * Code originally contributed by Adriaan Joubert. + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/varbit.h + * + * ------------------------------------------------------------------------- + */ +#ifndef VARBIT_H +#define VARBIT_H + +#include +#include "fmgr.h" + +/* + * Modeled on struct varlena from postgres.h, but data type is bits8. + */ +typedef struct { + int32 vl_len_; /* varlena header (do not touch directly!) */ + int32 bit_len; /* number of valid bits */ + bits8 bit_dat[FLEXIBLE_ARRAY_MEMBER]; /* bit string, most sig. byte first */ +} VarBit; + +/* + * fmgr interface macros + * + * BIT and BIT VARYING are toastable varlena types. They are the same + * as far as representation goes, so we just have one set of macros. + */ +#define DatumGetVarBitP(X) ((VarBit*)PG_DETOAST_DATUM(X)) +#define DatumGetVarBitPCopy(X) ((VarBit*)PG_DETOAST_DATUM_COPY(X)) +#define VarBitPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_VARBIT_P(n) DatumGetVarBitP(PG_GETARG_DATUM(n)) +#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n)) +#define PG_RETURN_VARBIT_P(x) return VarBitPGetDatum(x) + +/* Header overhead *in addition to* VARHDRSZ */ +#define VARBITHDRSZ sizeof(int32) +/* Number of bits in this bit string */ +#define VARBITLEN(PTR) (((VarBit*)(PTR))->bit_len) +/* Pointer to the first byte containing bit string data */ +#define VARBITS(PTR) (((VarBit*)(PTR))->bit_dat) +/* Number of bytes in the data section of a bit string */ +#define VARBITBYTES(PTR) (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ) +/* Padding of the bit string at the end (in bits) */ +#define VARBITPAD(PTR) (VARBITBYTES(PTR) * BITS_PER_BYTE - VARBITLEN(PTR)) +/* Number of bytes needed to store a bit string of a given length */ +#define VARBITTOTALLEN(BITLEN) (((BITLEN) + BITS_PER_BYTE - 1) / BITS_PER_BYTE + VARHDRSZ + VARBITHDRSZ) +/* + * Maximum number of bits. Several code sites assume no overflow from + * computing bitlen + X; VARBITTOTALLEN() has the largest such X. + */ +#define VARBITMAXLEN (INT_MAX - BITS_PER_BYTE + 1) +/* pointer beyond the end of the bit string (like end() in STL containers) */ +#define VARBITEND(PTR) (((bits8*)(PTR)) + VARSIZE(PTR)) +/* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */ +#define BITMASK 0xFF + +extern Datum bit_in(PG_FUNCTION_ARGS); +extern Datum bit_out(PG_FUNCTION_ARGS); +extern Datum bit_recv(PG_FUNCTION_ARGS); +extern Datum bit_send(PG_FUNCTION_ARGS); +extern Datum bittypmodin(PG_FUNCTION_ARGS); +extern Datum bittypmodout(PG_FUNCTION_ARGS); +extern Datum varbit_in(PG_FUNCTION_ARGS); +extern Datum varbit_out(PG_FUNCTION_ARGS); +extern Datum varbit_recv(PG_FUNCTION_ARGS); +extern Datum varbit_send(PG_FUNCTION_ARGS); +extern Datum varbittypmodin(PG_FUNCTION_ARGS); +extern Datum varbittypmodout(PG_FUNCTION_ARGS); +extern Datum bit(PG_FUNCTION_ARGS); +extern Datum varbit_transform(PG_FUNCTION_ARGS); +extern Datum varbit(PG_FUNCTION_ARGS); +extern Datum biteq(PG_FUNCTION_ARGS); +extern Datum bitne(PG_FUNCTION_ARGS); +extern Datum bitlt(PG_FUNCTION_ARGS); +extern Datum bitle(PG_FUNCTION_ARGS); +extern Datum bitgt(PG_FUNCTION_ARGS); +extern Datum bitge(PG_FUNCTION_ARGS); +extern Datum bitcmp(PG_FUNCTION_ARGS); + +/* avoid the names bitand and bitor, since they are C++ keywords */ +extern Datum bit_and(PG_FUNCTION_ARGS); +extern Datum bit_or(PG_FUNCTION_ARGS); +extern Datum bitxor(PG_FUNCTION_ARGS); +extern Datum bitnot(PG_FUNCTION_ARGS); +extern Datum bitshiftleft(PG_FUNCTION_ARGS); +extern Datum bitshiftright(PG_FUNCTION_ARGS); +extern Datum bitcat(PG_FUNCTION_ARGS); +extern Datum bitsubstr(PG_FUNCTION_ARGS); +extern Datum bitsubstr_no_len(PG_FUNCTION_ARGS); +extern Datum bitoverlay(PG_FUNCTION_ARGS); +extern Datum bitoverlay_no_len(PG_FUNCTION_ARGS); +extern Datum bitlength(PG_FUNCTION_ARGS); +extern Datum bitoctetlength(PG_FUNCTION_ARGS); +extern Datum bitfromint4(PG_FUNCTION_ARGS); +extern Datum bittoint4(PG_FUNCTION_ARGS); +extern Datum bitfromint8(PG_FUNCTION_ARGS); +extern Datum bittoint8(PG_FUNCTION_ARGS); +extern Datum bitposition(PG_FUNCTION_ARGS); +extern Datum bitsetbit(PG_FUNCTION_ARGS); +extern Datum bitgetbit(PG_FUNCTION_ARGS); + +#endif diff -uprN postgresql-hll-2.14_old/include/utils/xml.h postgresql-hll-2.14/include/utils/xml.h --- postgresql-hll-2.14_old/include/utils/xml.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/xml.h 2020-12-12 17:06:43.407350103 +0800 @@ -0,0 +1,83 @@ +/* ------------------------------------------------------------------------- + * + * xml.h + * Declarations for XML data type support. + * + * + * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/utils/xml.h + * + * ------------------------------------------------------------------------- + */ + +#ifndef XML_H +#define XML_H + +#include "fmgr.h" +#include "nodes/execnodes.h" +#include "nodes/primnodes.h" +#include "utils/xmltypes.h" + +#define DatumGetXmlP(X) ((xmltype*)PG_DETOAST_DATUM(X)) +#define XmlPGetDatum(X) PointerGetDatum(X) + +#define PG_GETARG_XML_P(n) DatumGetXmlP(PG_GETARG_DATUM(n)) +#define PG_RETURN_XML_P(x) PG_RETURN_POINTER(x) + +extern Datum xml_in(PG_FUNCTION_ARGS); +extern Datum xml_out(PG_FUNCTION_ARGS); +extern Datum xml_recv(PG_FUNCTION_ARGS); +extern Datum xml_send(PG_FUNCTION_ARGS); +extern Datum xmlcomment(PG_FUNCTION_ARGS); +extern Datum xmlconcat2(PG_FUNCTION_ARGS); +extern Datum texttoxml(PG_FUNCTION_ARGS); +extern Datum xmltotext(PG_FUNCTION_ARGS); +extern Datum xmlvalidate(PG_FUNCTION_ARGS); +extern Datum xpath(PG_FUNCTION_ARGS); +extern Datum xpath_exists(PG_FUNCTION_ARGS); +extern Datum xmlexists(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed_document(PG_FUNCTION_ARGS); +extern Datum xml_is_well_formed_content(PG_FUNCTION_ARGS); + +extern Datum table_to_xml(PG_FUNCTION_ARGS); +extern Datum query_to_xml(PG_FUNCTION_ARGS); +extern Datum cursor_to_xml(PG_FUNCTION_ARGS); +extern Datum table_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum query_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum cursor_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum table_to_xml_and_xmlschema(PG_FUNCTION_ARGS); +extern Datum query_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern Datum schema_to_xml(PG_FUNCTION_ARGS); +extern Datum schema_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum schema_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern Datum database_to_xml(PG_FUNCTION_ARGS); +extern Datum database_to_xmlschema(PG_FUNCTION_ARGS); +extern Datum database_to_xml_and_xmlschema(PG_FUNCTION_ARGS); + +extern void pg_xml_init_library(void); +extern PgXmlErrorContext* pg_xml_init(PgXmlStrictness strictness); +extern void pg_xml_done(PgXmlErrorContext* errcxt, bool isError); +extern bool pg_xml_error_occurred(PgXmlErrorContext* errcxt); +extern void xml_ereport(PgXmlErrorContext* errcxt, int level, int sqlcode, const char* msg); + +extern xmltype* xmlconcat(List* args); +extern xmltype* xmlelement(XmlExprState* xmlExpr, ExprContext* econtext); +extern xmltype* xmlparse(text* data, XmlOptionType xmloption, bool preserve_whitespace); +extern xmltype* xmlpi(char* target, text* arg, bool arg_is_null, bool* result_is_null); +extern xmltype* xmlroot(xmltype* data, text* version, int standalone); +extern bool xml_is_document(xmltype* arg); +extern text* xmltotext_with_xmloption(xmltype* data, XmlOptionType xmloption_arg); +extern char* escape_xml(const char* str); + +extern char* map_sql_identifier_to_xml_name(char* ident, bool fully_escaped, bool escape_period); +extern char* map_xml_name_to_sql_identifier(char* name); +extern char* map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings); + +extern THR_LOCAL int xmloption; /* XmlOptionType, but int for guc enum */ + +#endif /* XML_H */ diff -uprN postgresql-hll-2.14_old/include/utils/xmltypes.h postgresql-hll-2.14/include/utils/xmltypes.h --- postgresql-hll-2.14_old/include/utils/xmltypes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/xmltypes.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,49 @@ +/* + * 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. + * ------------------------------------------------------------------------- + * + * xmltypes.h + * + * IDENTIFICATION + * src\include\utils\xmltypes.h + * + * ------------------------------------------------------------------------- + */ + +#pragma once + +typedef struct varlena xmltype; + +typedef enum { + XML_STANDALONE_YES, + XML_STANDALONE_NO, + XML_STANDALONE_NO_VALUE, + XML_STANDALONE_OMITTED +} XmlStandaloneType; + +typedef enum { + XMLBINARY_BASE64, + XMLBINARY_HEX +} XmlBinaryType; + +typedef enum { + PG_XML_STRICTNESS_LEGACY, /* ignore errors unless function result + * indicates error condition */ + PG_XML_STRICTNESS_WELLFORMED, /* ignore non-parser messages */ + PG_XML_STRICTNESS_ALL /* report all notices/warnings/errors */ +} PgXmlStrictness; + +/* struct PgXmlErrorContext is private to xml.c */ +typedef struct PgXmlErrorContext PgXmlErrorContext; + diff -uprN postgresql-hll-2.14_old/include/utils/zfiles.h postgresql-hll-2.14/include/utils/zfiles.h --- postgresql-hll-2.14_old/include/utils/zfiles.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/utils/zfiles.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * zfiles.h + * + * + * + * IDENTIFICATION + * src/include/utils/zfiles.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef _LOG_FDW_ZFILES_H_ +#define _LOG_FDW_ZFILES_H_ + +#include "ioapi.h" +#include "unzip.h" + +typedef struct opaque_vfd { + int m_tmp_vfd; /* virtual fd */ + int m_errno; /* io error no */ + off_t m_cur_off; /* file offset */ + long m_max_off; /* file max offset */ +} opaque_vfd; + +typedef struct zip_reader { + unzFile m_unz; + unz_global_info64 m_unz_gi; + ZPOS64_T m_unz_curfile; + opaque_vfd m_vfd; +} zip_reader; + +typedef struct gz_reader { + gzFile m_gzf; + opaque_vfd* m_vfd; +} gz_reader; + +extern void pm_set_unzip_memfuncs(void); + +/* unzip postgresql-2018-03-31_000000.zip log file and read its contents */ +extern void set_unzip_filefuncs(zlib_filefunc64_def* funcs, voidpf opaque); +extern void* unzip_open(const char* zipfile); +extern int unzip_read(void* zr, char* buf, int bufsize); +extern void unzip_close(void* zr); + +extern void* vfd_file_open(const char* logfile); +extern int vfd_file_read(void* fobj, char* buf, int bufsize); +extern void vfd_file_close(void* fobj); +extern void vfd_file_close_with_thief(void* fobj); + +extern void* gz_open(const char* gzfile); +extern int gz_read(void* gzfd, char* buf, int bufsize); +extern void gz_close(void* gzfd); + +#endif /* _LOG_FDW_ZFILES_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecagg.h postgresql-hll-2.14/include/vecexecutor/vecagg.h --- postgresql-hll-2.14_old/include/vecexecutor/vecagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecagg.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,248 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecagg.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECAGG_H_ +#define VECAGG_H_ + +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecnodes.h" +#include "utils/batchsort.h" + +extern VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags); +extern VectorBatch* ExecVecAggregation(VecAggState* node); +extern void ExecEndVecAggregation(VecAggState* node); +extern void ExecReScanVecAggregation(VecAggState* node); +extern void ExecEarlyFreeVecAggregation(VecAggState* node); + +#define AGG_PREPARE 0 +#define AGG_BUILD 1 +#define AGG_FETCH 2 +#define AGG_RETURN 3 +#define AGG_RETURN_LAST 4 +#define AGG_RETURN_NULL 5 + +struct finalAggInfo { + int idx; + VecAggInfo* info; +}; + +typedef struct SortDistinct { + Batchsortstate** batchsortstate; + VectorBatch** aggDistinctBatch; + ScalarValue* lastVal; + hashCell* m_distinctLoc; + int* lastValLen; +} SortDistinct; + +class BaseAggRunner : public hashBasedOperator { +public: + BaseAggRunner(VecAggState* runtime, bool isHashAgg); + BaseAggRunner(); + + void init_aggInfo(int agg_num, VecAggInfo* aggInfo); + + virtual bool ResetNecessary(VecAggState* node) = 0; + + virtual VectorBatch* Run() = 0; + + void (BaseAggRunner::*m_buildScanBatch)(hashCell* cell); + + void init_index(); + + template + void initCellValue(VectorBatch* batch, hashCell* cell, int idx); + + void BatchAggregation(VectorBatch* batch); + + template + bool match_key(VectorBatch* batch, int batchIdx, hashCell* cell); + + void AggregationOnScalar(VecAggInfo* aggInfo, ScalarVector* pVector, int idx, hashCell** location); + + // build scan batch + void BuildScanBatchSimple(hashCell* cell); + + void BuildScanBatchFinal(hashCell* cell); + + // build result batch + VectorBatch* ProducerBatch(); + + /* Filter repeat value which be used when agg need distinct.*/ + bool FilterRepeatValue(FmgrInfo* equalfns, int currentSet, int aggno, bool first); + + /*Add for sort agg*/ + void BatchSortAggregation(int i, int workMem, int maxMem, int planId, int dop); + + void initialize_sortstate(int workMem, int maxMem, int planId, int dop); + + void build_batch(); + + /*keep last values, when need distinct operation. This value need compare with the values of next batch*/ + void copyLastValues(Oid typOid, ScalarValue m_vals, int aggno, int currentSet); + + void BatchNoSortAgg(VectorBatch* batch); + + void AppendBatchForSortAgg(VectorBatch* batch, int start, int end, int currentSet); + +public: + VecAggState* m_runtime; + + int m_cellVarLen; + // how many aggregation function (column) + int m_aggNum; + + bool* m_aggCount; + + // the agg index in the tuple,as some agg function may split into two function + // e.g avg + int* m_aggIdx; + + int* m_cellBatchMap; + + int* m_keyIdxInCell; + + bool m_finish; + + bool m_hasDistinct; + + int m_keySimple; // whether the key is simple. 1:is simple 2: not simple + // simple means there is no variable length data type or complex expression evaluation. + + // the index which need do some final calc. + finalAggInfo* m_finalAggInfo; + + int m_finalAggNum; + + // Batch for scan the hash table. + VectorBatch* m_scanBatch; + + // projection batch. The projection code binds column offset with outer batch, so we + // shall keep the outer batch to leverage it. Notice that we have actually copied + // accessible columns to the hash table already (due to aggregation semantics), so + // we simply use outer batch offset only. + // + VectorBatch* m_proBatch; + + // same structure as outer node return batch + VectorBatch* m_outerBatch; + + // runtime state. + int m_runState; + + // the location for entry to be insert + hashCell* m_Loc[BatchMaxSize]; + + SortDistinct* m_sortDistinct; + + VarBuf* m_sortCurrentBuf; + + int m_projected_set; + + /* expression-evaluation context */ + ExprContext* m_econtext; + +private: + void init_Baseindex(); + void prepare_projection_batch(); + + virtual void BindingFp() = 0; +}; + +#define DO_AGGEGATION(tbl) (((BaseAggRunner*)tbl)->Run)() + +template +void BaseAggRunner::initCellValue(VectorBatch* batch, hashCell* cell, int idx) +{ + int k; + ScalarVector* pVector = NULL; + + for (k = 0; k < m_cellVarLen; k++) { + pVector = &batch->m_arr[m_cellBatchMap[k]]; + + if (simple || pVector->m_desc.encoded == false) { + cell->m_val[k].val = pVector->m_vals[idx]; + cell->m_val[k].flag = pVector->m_flag[idx]; + } else { + if (likely(pVector->IsNull(idx) == false)) { + /* For hashagg, CurrentMemoryContext is hashcell context */ + cell->m_val[k].val = sortAgg ? addToVarBuffer(m_sortCurrentBuf, pVector->m_vals[idx]) + : addVariable(CurrentMemoryContext, pVector->m_vals[idx]); + if (!sortAgg && m_tupleCount >= 0) + m_colWidth += VARSIZE_ANY(pVector->m_vals[idx]); + } + + cell->m_val[k].flag = pVector->m_flag[idx]; + } + } + + // set the init value. + for (k = 0; k < m_aggNum; k++) { + if (m_aggCount[k]) { + cell->m_val[m_aggIdx[k]].val = 0; + SET_NOTNULL(cell->m_val[m_aggIdx[k]].flag); + } else + SET_NULL(cell->m_val[m_aggIdx[k]].flag); + } +} + +template +bool BaseAggRunner::match_key(VectorBatch* batch, int batchIdx, hashCell* cell) +{ + bool match = true; + int i; + ScalarVector* pVector = NULL; + hashVal* hashval = NULL; + FunctionCallInfoData fcinfo; + Datum args[2]; + + fcinfo.arg = &args[0]; + + for (i = 0; i < m_key; i++) { + pVector = &batch->m_arr[m_keyIdx[i]]; + hashval = &cell->m_val[m_keyIdxInCell[i]]; + + if (BOTH_NOT_NULL(pVector->m_flag[batchIdx], hashval->flag)) { + if (simpleKey || pVector->m_desc.encoded == false) { + if (pVector->m_vals[batchIdx] == hashval->val) + continue; + else + return false; + } else { + fcinfo.arg[0] = ScalarVector::Decode(pVector->m_vals[batchIdx]); + fcinfo.arg[1] = ScalarVector::Decode(hashval->val); + fcinfo.flinfo = (m_eqfunctions + i); + match = m_eqfunctions[i].fn_addr(&fcinfo); + if (match == false) + return false; + } + } else if (IS_NULL(pVector->m_flag[batchIdx]) && IS_NULL(hashval->flag)) // both null is equal + continue; + else if (IS_NULL(pVector->m_flag[batchIdx]) || IS_NULL(hashval->flag)) + return false; + } + + return true; +} + +#endif diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecappend.h postgresql-hll-2.14/include/vecexecutor/vecappend.h --- postgresql-hll-2.14_old/include/vecexecutor/vecappend.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecappend.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecappend.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecappend.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECAPPEND_H +#define NODEVECAPPEND_H + +#include "vecexecutor/vecnodes.h" + +extern VecAppendState* ExecInitVecAppend(VecAppend* node, EState* estate, int eflags); +extern VectorBatch* ExecVecAppend(VecAppendState* node); +extern void ExecEndVecAppend(VecAppendState* node); +extern void ExecReScanVecAppend(VecAppendState* node); + +#endif /* NODEVECAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecexecutor.h postgresql-hll-2.14/include/vecexecutor/vecexecutor.h --- postgresql-hll-2.14_old/include/vecexecutor/vecexecutor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecexecutor.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,59 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexecutor.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecexecutor.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef VECEXECUTOR_H_ +#define VECEXECUTOR_H_ + +#include "nodes/execnodes.h" +#include "utils/builtins.h" +#include "utils/date.h" +#include "utils/bytea.h" +#include "utils/geo_decls.h" +#include "utils/nabstime.h" +#include "utils/timestamp.h" + +#define initEcontextBatch(m_scanbatch, m_outerbatch, m_innerbatch, m_aggbatch) \ + { \ + econtext->ecxt_scanbatch = m_scanbatch; \ + econtext->ecxt_outerbatch = m_outerbatch; \ + econtext->ecxt_innerbatch = m_innerbatch; \ + econtext->ecxt_aggbatch = m_aggbatch; \ + } + +extern VectorBatch* VectorEngine(PlanState* node); +extern VectorBatch* ExecVecProject(ProjectionInfo* projInfo, bool selReSet = true, ExprDoneCond* isDone = NULL); +extern ExprState* ExecInitVecExpr(Expr* node, PlanState* parent); + +extern ScalarVector* ExecVecQual(List* qual, ExprContext* econtext, bool resultForNull, bool isReset = true); + +typedef VectorBatch* (*ExecVecScanAccessMtd)(ScanState* node); +typedef bool (*ExecVecScanRecheckMtd)(ScanState* node, VectorBatch* batch); +extern VectorBatch* ExecVecScan(ScanState* node, ExecVecScanAccessMtd accessMtd, ExecVecScanRecheckMtd recheckMtd); +extern void ExecAssignVecScanProjectionInfo(ScanState* node); +extern void ExecVecMarkPos(PlanState* node); +extern void ExecVecRestrPos(PlanState* node); +extern void VecExecReScan(PlanState* node); + +#endif /* VECEXECUTOR_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecexpression.h postgresql-hll-2.14/include/vecexecutor/vecexpression.h --- postgresql-hll-2.14_old/include/vecexecutor/vecexpression.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecexpression.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecexpression.h + * Vectorized Expression Engine + * + * IDENTIFICATION + * src/include/vecexecutor/vecexpression.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECEXPRESSION_H_ +#define VECEXPRESSION_H_ + +#include "fmgr.h" +#include "vecexecutor/vectorbatch.h" + +#define VectorExprEngine(expr, econtext, selVector, inputVector, isDone) \ + ((expr)->vecExprFun ? (*(expr)->vecExprFun)(expr, econtext, selVector, inputVector, isDone) \ + : (elog(ERROR, "Unsupported expressions for vector engine"), ((ScalarVector*)NULL))) + +GenericArgExtract ChooseExtractFun(Oid Dtype, Oid fn_oid = 0); + +#endif /* VECEXPRESSION_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecfunc.h postgresql-hll-2.14/include/vecexecutor/vecfunc.h --- postgresql-hll-2.14_old/include/vecexecutor/vecfunc.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecfunc.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecfunc.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecfunc.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECFUNC_H +#define VECFUNC_H + +#include "utils/hsearch.h" + +#include "utils/builtins.h" +#include "utils/fmgrtab.h" +#include "mb/pg_wchar.h" + +#define FUNCACHE_NUM 8 + +typedef struct { + /* fn_oid is the hash key and so must be first! */ + Oid fn_oid; /* OID of an external C function */ + VectorFunction vec_fn_cache[FUNCACHE_NUM]; /* address of its info record */ + VectorFunction vec_agg_cache[FUNCACHE_NUM]; + + /* + * function cache pointer to the sonic hash agg function if supported + */ + VectorFunction vec_sonic_agg_cache[FUNCACHE_NUM]; + + /* vec_transform_function has three applications + * 1. this function is used for the last stage of avg(vec_aggfinal_function); + * 2. we can replace some native PGFunctions to our transformed function for some reasons; + * (such as: int_numeric TO int_numeric_bi) + * 3. this interface is reserved for later use. + */ + PGFunction vec_transform_function[FUNCACHE_NUM]; + + /* + * sonic transform functions, which have the same meanings as vec_transform_function, but + * used only for sonic cases. + */ + PGFunction vec_sonic_transform_function[FUNCACHE_NUM]; + +} VecFuncCacheEntry; + +typedef Datum (*sub_Array)(Datum str, int32 start, int32 length, bool* isnull, mblen_converter fun_mblen); + +extern sub_Array substr_Array[32]; + +#endif /* VECFUNC_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecgroup.h postgresql-hll-2.14/include/vecexecutor/vecgroup.h --- postgresql-hll-2.14_old/include/vecexecutor/vecgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecgroup.h 2020-12-12 17:06:43.408350116 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecgroup.h + * Prototypes for vectorized group + * + * IDENTIFICATION + * src/include/vecexecutor/vecgroup.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECGROUP_H +#define VECGROUP_H + +#include "vecexecutor/vecnodes.h" + +extern VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags); +extern VectorBatch* ExecVecGroup(VecGroupState* node); +extern void ExecEndVecGroup(VecGroupState* node); +extern void ExecReScanVecGroup(VecGroupState* node); + +#endif /* VECGROUP_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecgrpuniq.h postgresql-hll-2.14/include/vecexecutor/vecgrpuniq.h --- postgresql-hll-2.14_old/include/vecexecutor/vecgrpuniq.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecgrpuniq.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,263 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecgrpuniq.h + * Prototypes for vectorized unique and group + * + * IDENTIFICATION + * src/include/vecexecutor/vecgrpuniq.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECGRPUNIQ_H +#define VECGRPUNIQ_H +#include "vecexecutor/vectorbatch.h" +#include "vecexecutor/vecexecutor.h" + +// The value of cell which is contained in GUCell +// +struct GUCellVal { + ScalarValue val; + uint8 flag; +}; + +// The container to store cells which are used to produce outer batch +// +struct GUCell { + int dummy; /* a dummy field to avoid compile error for sigle var-len array in an empty struct*/ + GUCellVal val[FLEXIBLE_ARRAY_MEMBER]; +}; + +// The encapsulation of VectorBatch, cols and colIdx. Use this to reduce the parameter number, +// create and fill it in vecgroup and vecunique seperately to avoid using if in template because +// of the different name of colIdx(grpColIdx, uniqColIdx). +// +struct Encap { + VectorBatch* batch; + int cols; + int outerCols; + AttrNumber* colIdx; + FmgrInfo* eqfunctions; +}; + +inline ScalarValue AddVar(VarBuf* buf, ScalarValue value) +{ + return PointerGetDatum(buf->Append(DatumGetPointer(value), VARSIZE_ANY(value))); +} + +template +static void InitCellValue(Encap* cap, GUCell* cell, int idx, VarBuf* currentBuf) +{ + int k = 0; + ScalarVector* pVector = NULL; + VectorBatch* batch = cap->batch; + ScalarVector* arr = batch->m_arr; + GUCellVal* val = cell->val; + int outerCols = cap->outerCols; + + for (k = 0; k < outerCols; k++) { + pVector = &arr[k]; + if (simple || pVector->m_desc.encoded == false) { + val[k].val = pVector->m_vals[idx]; + val[k].flag = pVector->m_flag[idx]; + } else { + if (likely(pVector->IsNull(idx) == false)) + val[k].val = AddVar(currentBuf, pVector->m_vals[idx]); + + val[k].flag = pVector->m_flag[idx]; + } + } +} + +template +static bool Match(Encap* cap, int batchIdx, GUCell* cell) +{ + bool match = true; + int i = 0; + ScalarVector* pVector = NULL; + ScalarDesc desc; + GUCellVal* cellVal = NULL; + Datum key1; + Datum key2; + ScalarVector* arr = cap->batch->m_arr; + GUCellVal* val = cell->val; + int cols = cap->cols; + AttrNumber* colIdx = cap->colIdx; + FmgrInfo* eqfuncs = cap->eqfunctions; + + for (i = 0; i < cols; i++) { + pVector = &arr[colIdx[i] - 1]; + cellVal = &val[colIdx[i] - 1]; + desc = pVector->m_desc; + + if (BOTH_NOT_NULL(pVector->m_flag[batchIdx], cellVal->flag)) { + if (simpleKey || desc.encoded == false) { + if (pVector->m_vals[batchIdx] == cellVal->val) + continue; + else + return false; + } else { + key1 = ScalarVector::Decode(pVector->m_vals[batchIdx]); + key2 = ScalarVector::Decode(cellVal->val); + + match = DatumGetBool(FunctionCall2((eqfuncs + i), key1, key2)); + if (match == false) + return false; + } + } + // both null is equal + else if (IS_NULL(pVector->m_flag[batchIdx]) && IS_NULL(cellVal->flag)) + continue; + else if (IS_NULL(pVector->m_flag[batchIdx]) || IS_NULL(cellVal->flag)) + return false; + } + + return true; +} + +// Build the container filled with cells which not match others. +// +template +Datum BuildFunc(PG_FUNCTION_ARGS) +{ + T* node = (T*)PG_GETARG_DATUM(0); + Encap* cap = (Encap*)PG_GETARG_DATUM(1); + VectorBatch* batch = cap->batch; + int i = 0; + int rows = batch->m_rows; + int cellSize = node->cellSize; + GUCell* cell = NULL; + void** container = node->container; + VarBuf* currentBuf = node->currentBuf; + uint16* idx = &(node->idx); + + for (i = 0; i < rows; i++) { + cell = (GUCell*)container[*idx]; + if (cell == NULL || !Match(cap, i, cell)) { + // means we got match fail + if (cell != NULL) { + (*idx)++; + if (*idx == BatchMaxSize) { + // switch buffer + VarBuf* tmp; + tmp = node->currentBuf; + node->currentBuf = node->bckBuf; + node->bckBuf = tmp; + currentBuf = node->currentBuf; + } + } + cell = (GUCell*)currentBuf->Allocate(cellSize); + container[*idx] = cell; + + InitCellValue(cap, cell, i, currentBuf); + } + } + + PG_FREE_IF_COPY(node, 0); + PG_FREE_IF_COPY(cap, 1); + + PG_RETURN_DATUM(0); +} + +Datum BuildScanBatch(PG_FUNCTION_ARGS); + +template +static void BindingFp(T* node) +{ + node->buildScanFunc->fn_addr = BuildScanBatch; + if (node->keySimple) { + node->buildFunc->fn_addr = BuildFunc; + } else { + node->buildFunc->fn_addr = BuildFunc; + } +} + +template +static void ReplaceGrpUniqEqfunc(Encap* cap, Form_pg_attribute* attrs) +{ + AttrNumber* colIdx = cap->colIdx; + FmgrInfo* eqfunctions = cap->eqfunctions; + + for (int i = 0; i < cap->cols; i++) { + switch (attrs[colIdx[i] - 1]->atttypid) { + case TIMETZOID: + eqfunctions[i].fn_addr = timetz_eq_withhead; + break; + case TINTERVALOID: + eqfunctions[i].fn_addr = tintervaleq_withhead; + break; + case INTERVALOID: + eqfunctions[i].fn_addr = interval_eq_withhead; + break; + case NAMEOID: + eqfunctions[i].fn_addr = nameeq_withhead; + break; + default: + break; + } + } +} + +template +void InitGrpUniq(T* state, int cols, AttrNumber* colIdx) +{ + int i = 0; + Encap* cap = (Encap*)state->cap; + + // Initialize the variables used in Vector execution process and bind the function in FmgrInfo. + state->idx = 0; + state->keySimple = true; + state->container = (void**)palloc0(2 * BatchMaxSize * sizeof(GUCell*)); + + TupleDesc outDesc = outerPlanState(state)->ps_ResultTupleSlot->tts_tupleDescriptor; + state->cellSize = offsetof(GUCell, val) + outDesc->natts * sizeof(GUCellVal); + cap->cols = cols; + cap->outerCols = outDesc->natts; + cap->colIdx = colIdx; + cap->eqfunctions = state->eqfunctions; + Form_pg_attribute* attrs = outDesc->attrs; + + for (i = 0; i < cap->outerCols; i++) { + if (COL_IS_ENCODE(attrs[i]->atttypid)) { + state->keySimple = false; + break; + } + } + + ReplaceGrpUniqEqfunc(cap, attrs); + + state->scanBatch = New(CurrentMemoryContext) VectorBatch(CurrentMemoryContext, outDesc); + state->currentBuf = New(CurrentMemoryContext) VarBuf(CurrentMemoryContext); + state->currentBuf->Init(); + state->bckBuf = New(CurrentMemoryContext) VarBuf(CurrentMemoryContext); + state->bckBuf->Init(); + state->buildFunc = (FmgrInfo*)palloc0(sizeof(FmgrInfo)); + state->buildScanFunc = (FmgrInfo*)palloc0(sizeof(FmgrInfo)); + BindingFp(state); +} + +template +void ReScanGrpUniq(T* node) +{ + errno_t rc; + // clear the container and buffers which will be used in the next scan with a clean status. + rc = memset_s(node->container, 2 * BatchMaxSize * sizeof(GUCell*), 0, 2 * BatchMaxSize * sizeof(GUCell*)); + securec_check(rc, "\0", "\0"); + node->idx = 0; + node->currentBuf->Reset(); +} + +#endif /* VECGRPUNIQ_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vechashagg.h postgresql-hll-2.14/include/vecexecutor/vechashagg.h --- postgresql-hll-2.14_old/include/vecexecutor/vechashagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vechashagg.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashagg.h + * hash agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vechashagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHAGG_H_ +#define VECHASHAGG_H_ + +#include "vecexecutor/vecagg.h" + +struct AggStateLog { + bool restore; + hashCell* lastCell; + int lastIdx; + int lastSeg; +}; + +class HashAggRunner : public BaseAggRunner { +public: + HashAggRunner(VecAggState* runtime); + ~HashAggRunner(){}; + + bool ResetNecessary(VecAggState* node); + + /* Wrap allocate new hash cell and initialization */ + template + void AllocHashSlot(VectorBatch* batch, int i); + void HashTableGrowUp(); + +private: + /* Different build function, if we exceed the threshold in memory row number,we need to flush to the disk.*/ + template + void buildAggTbl(VectorBatch* batch); + + void Build(); + + VectorBatch* Probe(); + + /* Hash based aggregation.*/ + VectorBatch* Run(); + + /* Get the hash source.*/ + hashSource* GetHashSource(); + + void BindingFp(); + + template + int64 computeHashTableSize(int64 newsize); + ScalarValue getHashValue(hashCell* hashentry); + + FORCE_INLINE uint32 get_bucket(uint32 hashvalue) + { + return hashvalue & (m_hashSize - 1); + } + + template + void dyHashSlotTmp(VectorBatch* batch, int i, int hash_idx, int start_idx); + + void GetPosbyLoc(uint64 idx, int* nseg, int64* pos); + + template + void BuildHashTable(int64 oldsize); + + void Profile(char* stats, bool* can_wlm_warning_statistics); + +private: + /* Some status log.*/ + AggStateLog m_statusLog; + + /* Hash source.*/ + hashSource* m_hashSource; + + /* Hash value to store.*/ + ScalarValue m_hashVal[BatchMaxSize]; + int m_fileIdx; + bool m_can_grow; /* mark weather can grow up */ + int64 m_max_hashsize; /* memory allowed max hashtable size */ + int64 m_grow_threshold; /* the threshold to grow up */ + double m_hashbuild_time; + double m_hashagg_time; + MemoryContext m_hashcell_context; /* stack context for hashcell */ + HashSegTbl* m_hashData; /*hashagg table */ + int m_segnum; /* segment number */ + int m_hashseg_max; /* max hashsize for one segment */ + int64 m_hashSize; /* total hash size */ + void (HashAggRunner::*m_buildFun)(VectorBatch* batch); + int m_spill_times; /* spill time */ +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vechashjoin.h postgresql-hll-2.14/include/vecexecutor/vechashjoin.h --- postgresql-hll-2.14_old/include/vecexecutor/vechashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vechashjoin.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,341 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashjoin.h + * Prototypes for vectorized hash join + * + * IDENTIFICATION + * src/include/vecexecutor/vechashjoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHJOIN_H_ +#define VECHASHJOIN_H_ + +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecnodes.h" +#include "workload/workload.h" +// hash join runtime state +#define HASH_BUILD 0 +#define HASH_PROBE 1 +#define HASH_END 2 + +typedef enum { + HASH_JOIN_INNER = 0, + HASH_JOIN_LEFT, + HASH_JOIN_RIGHT, + HASH_JOIN_SEMI, + HASH_JOIN_ANTI, + HASH_JOIN_RIGHT_SEMI, + HASH_JOIN_RIGHT_ANTI, + HASH_JOIN_LEFT_ANTI_FULL, + HASH_JOIN_RIGHT_ANTI_FULL, + HASH_JOIN_TYPE_NUM +} hashJoinType; + +// hash strategy +#define MEMORY_HASH 0 +#define GRACE_HASH 1 + +// probe status +#define PROBE_FETCH 0 +#define PROBE_PARTITION_FILE 1 +#define PROBE_DATA 2 +#define PROBE_FINAL 3 +#define PROBE_PREPARE_PAIR 4 + +extern VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int eflags); +extern VectorBatch* ExecVecHashJoin(VecHashJoinState* node); +extern void ExecEndVecHashJoin(VecHashJoinState* node); +extern void ExecReScanVecHashJoin(VecHashJoinState* node); +extern long ExecGetMemCostVecHash(VecHashJoin*); +extern void ExecEarlyFreeVecHashJoin(VecHashJoinState* node); + +// Save current probing place for next join iteration +// +struct JoinStateLog { + int lastBuildIdx; + hashCell* lastCell; + bool restore; +}; + +// Record hash key matching passed cells +// +struct ReCheckCellLoc { + hashCell* cell; + int resultIdx; + int oriIdx; +}; + +// Vectorized hash join implementation class +// +class HashJoinTbl : public hashBasedOperator { +public: + HashJoinTbl(VecHashJoinState* runtimeContext); + + void Build(); + + VectorBatch* Probe(); + + void ResetNecessary(); + +public: + // number of columns in outer child + // + int m_outCols; + + // list of join keys in outer child + // + int* m_outKeyIdx; + + // list of original value of varattno on join keys in outer child + int* m_outOKeyIdx; + + // list of OID of collation on join keys in outer child + Oid* m_outKeyCollation; + + // a list for cache the data. + List* m_cache; + + // the status flag to indicate the probe. + int m_probeStatus; + + bool m_complicateJoinKey; + + // the cjVector is only alloced and used when m_complicateJoinKey is true + // + ScalarVector* m_cjVector; + + // out batch is simple + bool m_outSimple; + + // inner batch is simple + bool m_innerSimple; + + // whether check the key match + bool m_doProbeData; + + // inner batch + VectorBatch* m_innerBatch; + + // outer batch + VectorBatch* m_outerBatch; + + // complicate inner batch + VectorBatch* m_complicate_innerBatch; + + // complicate outer batch + VectorBatch* m_complicate_outerBatch; + + // inner qual batch + VectorBatch* m_inQualBatch; + + // outer qual batch + VectorBatch* m_outQualBatch; + + // out raw batch + VectorBatch* m_outRawBatch; + + VectorBatch* m_result; + + // runtime state + VecHashJoinState* m_runtime; + + // hash Join type. + hashJoinType m_joinType; + + // memory hash or grace hash + int m_strategy; + + JoinStateLog m_joinStateLog; + // prob source + hashOpSource* m_probOpSource; // prob source + + ReCheckCellLoc m_reCheckCell[BatchMaxSize]; + + // flag the row match + bool m_match[BatchMaxSize]; + + int m_probeIdx; + + // for null-eq special case + bool m_nulleqmatch[BatchMaxSize]; + + // build file source + hashFileSource* m_buildFileSource; + + // probe file source + hashFileSource* m_probeFileSource; + + bool* m_simpletype; + + Oid* m_outerkeyType; + + /* partition level of each file source: for repartition process */ + uint8* m_pLevel; + + /* maximum partition level need to be paid attention */ + uint8 m_maxPLevel; + + /* partition is from a valid repartition process or not: for repartition process */ + bool* m_isValid; + + /* Point to cell in semiJoin, in order to return value of righttree.*/ + hashCell** cellPoint; + + /* Print warning message after partitioned three times */ + bool m_isWarning; + + double m_build_time; + double m_probe_time; + +private: + void SetJoinType(); + void PrepareProbe(); + + template + void buildHashTable(hashSource* source, int64 rownum); + + template + void bindingFp(); + + // prepare for disk hash. + void initFile(bool buildSide, VectorBatch* templateBatch, int fileNum); + + // probe the in memory hash table. + VectorBatch* probeMemory(); + + // probe the hash table in a grace way. + VectorBatch* probeGrace(); + + // probe in memory hash table + VectorBatch* probeHashTable(hashSource* probSource); + + // probe the partition. + template + void probePartition(); + + /* repartition file source of a specific file */ + template + void RePartitionFileSource(hashFileSource* hashSource, int fileIdx); + + /* record partition info into log file */ + void recordPartitionInfo(bool buildside, int fileIdx, int istart, int iend); + + // prepare the partition join. + void preparePartition(); + + // init memory control parameter + void initMemoryControl(); + + // calc the spilling file. + int calcSpillFile(); + + // end hash join + VectorBatch* endJoin(); + + // build result batch. + VectorBatch* buildResult(VectorBatch* inBatch, VectorBatch* outBatch, bool checkqual); + + bool* checkQual(VectorBatch* inBatch, VectorBatch* outBatch); + + // match key + + template + void matchKey(ScalarVector* key, int nrows, int hashValKeyIdx, int key_num); + + bool simpletype(Oid type); + + void matchComplicateKey(VectorBatch* batch); + + void DispatchKeyInnerFunction(int KeyIdx); + + template + void DispatchKeyOuterFunction(int KeyIdx); + + // different join function + // full join + template + VectorBatch* innerJoinT(VectorBatch* batch); + + template + VectorBatch* leftJoinT(VectorBatch* batch); + + template + VectorBatch* leftJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightJoinT(VectorBatch* batch); + + template + VectorBatch* rightJoinWithQualT(VectorBatch* batch); + + // semi join + template + VectorBatch* semiJoinT(VectorBatch* batch); + + template + VectorBatch* semiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* antiJoinT(VectorBatch* batch); + + template + VectorBatch* antiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightSemiJoinT(VectorBatch* batch); + + template + VectorBatch* rightSemiJoinWithQualT(VectorBatch* batch); + + template + VectorBatch* rightAntiJoinT(VectorBatch* batch); + + template + VectorBatch* rightAntiJoinWithQualT(VectorBatch* batch); + + void PushDownFilterIfNeed(); + +private: + // build function array. + void (HashJoinTbl::*m_funBuild[2])(VectorBatch* batch); // the build function; + + void CalcComplicateHashVal(VectorBatch* batch, List* hashKeys, bool inner); + + bool HasEnoughMem(int nrows); + + template + void SaveToMemory(VectorBatch* batch); + + template + void flushToDisk(); + + template + void SaveToDisk(VectorBatch* batch); + + VectorBatch* (HashJoinTbl::*m_probeFun[2])(); // the probe function; + + VectorBatch* (HashJoinTbl::*m_joinFun)(VectorBatch* batch); // join function + + VectorBatch* (HashJoinTbl::*m_joinFunArray[36])(VectorBatch* batch); + + typedef void (HashJoinTbl::*pMatchKeyFunc)(ScalarVector* key, int nrows, int hashValKeyIdx, int key_num); + + pMatchKeyFunc* m_matchKeyFunction; +}; + +#endif /* VECHASHJOIN_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vechashtable.h postgresql-hll-2.14/include/vecexecutor/vechashtable.h --- postgresql-hll-2.14_old/include/vecexecutor/vechashtable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vechashtable.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,697 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vechashtable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vechashtable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECHASHTABLE_H_ +#define VECHASHTABLE_H_ + +#include "vecexecutor/vectorbatch.h" +#include "nodes/execnodes.h" +#include "access/hash.h" +#include "storage/buffile.h" +#include "utils/memutils.h" +#include "utils/batchsort.h" +#include "utils/memprot.h" + +#ifdef USE_ASSERT_CHECKING +#define HASH_BASED_DEBUG(A) A /* for debug only */ +#else +#define HASH_BASED_DEBUG(A) +#endif + +/* hash key type */ +typedef uint32 HashKey; +class vechashtable; + +// row base hash value +struct hashVal { + ScalarValue val; + uint8 flag; +}; + +// we do not store the column number and row number here +// as it is duplicate information, we can remember it outside the struct. +struct hashCell { + union { + hashCell* m_next; + int m_rows; + } flag; + + hashVal m_val[FLEXIBLE_ARRAY_MEMBER]; // data begins here +}; + +typedef struct HashSegTbl { + int tbl_size; // hash table size + hashCell** tbl_data; // hash table data. +} HashSegTbl; + +#define GET_NTH_CELL(cellHead, i) (hashCell*)((char*)cellHead + i * m_cellSize) +#define CELL_NTH_VAL(cell, i) (cell)->m_val[i].val +#define CELL_NTH_FLAG(cell, i) (cell)->m_val[i].flag +#define FILL_FACTOR 1.2 +#define MHASH_FUN 0 // for in memory hash function +#define DHASH_FUN 1 // decide which partition the value will store in temp file +#define INNER_SIDE 0 // for use inner hash function +#define OUTER_SIDE 1 // for use outer hash function +#define MIN_HASH_TABLE_SIZE 4096 +#define MAX_BUCKET_NUM (MaxAllocSize / sizeof(hashCell*) - 1) +#define MAX_LOG_LEN 1024 + +#define HASH_PREFETCH_DISTANCE 10 + +#define HASH_VARBUFSIZE 2 * 1024 * 1024 // 2M for buf +#define SCALAR_FUN 0 +#define VAR_FUN 1 + +#define HASH_IN_MEMORY 0 +#define HASH_IN_DISK 1 +#define HASH_RESPILL 2 + +#define HASH_EXPAND_THRESHOLD 2 /* threshold for hashtable expanding */ +#define HASH_EXPAND_SIZE 2 + +class hashSource : public BaseObject { +public: + virtual VectorBatch* getBatch() + { + Assert(false); + return NULL; + } + + virtual hashCell* getCell() + { + Assert(false); + return NULL; + } + + virtual void close(int idx) + { + Assert(false); + } + + virtual TupleTableSlot* getTup() + { + Assert(false); + return NULL; + } + + virtual ~hashSource() + {} +}; + +class hashOpSource : public hashSource { +public: + hashOpSource(PlanState* op); + ~hashOpSource(){}; + + VectorBatch* getBatch(); + + int64 getFileSize(); + + TupleTableSlot* getTup(); + + void close(int idx) + { + return; + } + +private: + // data source operator; + PlanState* m_op; +}; + +typedef ScalarValue (*stripValFun)(ScalarValue* val); + +class hashMemSource : public hashSource { +public: + hashMemSource(List* data); + ~hashMemSource(){}; + + hashCell* getCell(); + +private: + List* m_list; + + ListCell* m_cell; +}; + +class hashFileSource : public hashSource { +public: + hashFileSource(VectorBatch* batch, MemoryContext context, int cellSize, hashCell* cellArray, bool complicateJoin, + int m_write_cols, int fileNum, TupleDesc tupleDescritor); + + hashFileSource(TupleTableSlot* hashslot, int fileNum); + ~hashFileSource(){}; + + TupleTableSlot* getTup(); + + void writeTup(MinimalTupleData* Tup, int idx); + + void rewind(int idx); + + void close(int idx); + + void closeAll(); + + void freeFileSource(); + + void setCurrentIdx(int idx); + + int getCurrentIdx(); + + int64 getCurrentIdxRownum(int64 rows_in_mem); + + bool next(); + + void enlargeFileSource(int fileNum); + + void writeCell(hashCell* cell, HashKey key); + void writeBatch(VectorBatch* batch, int idx, HashKey key); + void writeBatchToFile(VectorBatch* batch, int idx, int fileIdx); + + void writeBatchWithHashval(VectorBatch* batch, int idx, HashKey key); + void writeBatchWithHashval(VectorBatch* batch, int idx, HashKey key, int fileIdx); + + void resetFileSource(); + + void initFileSource(int fileNum); + + VectorBatch* getBatch(); + + int64 getFileSize(); + + hashCell* getCell(); + + void resetVariableMemberIfNecessary(int fileNum); + + /* release the buffer in file handler if necessary */ + void ReleaseFileHandlerBuffer(int fileIdx); + void ReleaseAllFileHandlerBuffer(); + + /* prepare the buffer in file handler if necessary */ + void PrepareFileHandlerBuffer(int fileIdx); + +public: + int m_cellSize; + + int64* m_rownum; + + int64 m_total_filesize; + + int64* m_spill_size; + + int64* m_fileSize; + + int m_cols; + + int m_write_cols; // just for right join + + int* m_funType; + + VectorBatch* m_batch; + + hashCell* m_cellArray; // a bunch of cell + + MemoryContext m_context; + + void** m_file; + + TupleTableSlot* m_hashTupleSlot; + + MinimalTuple m_tuple; + + uint32 m_tupleSize; + + int m_currentFileIdx; + + int m_fileNum; + + Datum* m_values; + + bool* m_isnull; + + uint32 m_varSpaceLen; + + stripValFun* m_stripFunArray; + + size_t (hashFileSource::*m_write[2])(ScalarValue val, uint8 flag, int idx); + + size_t (hashFileSource::*m_read[2])(ScalarValue* val, uint8* flag); + + size_t (hashFileSource::*m_writeTuple)(MinimalTupleData* Tup, int idx); + + TupleTableSlot* (hashFileSource::*m_getTuple)(); + + hashCell* (hashFileSource::*m_getCell)(); + + void (hashFileSource::*m_rewind)(int idx); + void (hashFileSource::*m_close)(int idx); + + size_t (hashFileSource::*m_writeCell)(hashCell* cell, int idx); + + size_t (hashFileSource::*m_writeBatch)(VectorBatch* batch, int idx, int fileIdx); + + VectorBatch* (hashFileSource::*m_getBatch)(); + + size_t (hashFileSource::*m_writeBatchWithHashval)(VectorBatch* batch, int idx, HashKey key, int fileIdx); + +private: + // write the value from the file. + template + size_t writeScalar(ScalarValue val, uint8 flag, int fileIdx); + template + size_t writeVar(ScalarValue val, uint8 flag, int fileIdx); + + // read the value from the file. + template + size_t readScalar(ScalarValue* val, uint8* flag); + template + size_t readVar(ScalarValue* val, uint8* flag); + + size_t writeBatchNoCompress(VectorBatch* batch, int idx, int fileIdx); + + size_t writeBatchCompress(VectorBatch* batch, int idx, int fileIdx); + + void assembleBatch(TupleTableSlot* slot, int idx); + + template + VectorBatch* getBatchCompress(); + + template + VectorBatch* getBatchNoCompress(); + + void rewindCompress(int idx); + void rewindNoCompress(int idx); + void closeCompress(int idx); + void closeNoCompress(int idx); + + template + size_t writeCellNoCompress(hashCell* cell, int fileIdx); + + template + size_t writeCellCompress(hashCell* cell, int fileIdx); + + template + hashCell* getCellNoCompress(); + + template + hashCell* getCellCompress(); + + template + size_t writeTupCompress(MinimalTupleData* Tup, int idx); + + template + TupleTableSlot* getTupCompress(); + + template + size_t writeBatchWithHashvalCompress(VectorBatch* batch, int idx, HashKey key, int fileIdx); +}; + +class hashSortSource : public hashSource { +public: + hashSortSource(Batchsortstate* batchSortState, VectorBatch* sortBatch); + ~hashSortSource(){}; + + VectorBatch* getBatch(); + + VectorBatch* m_SortBatch; + +private: + Batchsortstate* m_batchSortStateIn; +}; + +inline int getPower2LessNum(int num) +{ + int i = 1; + int count = 0; + + for (;;) { + num = num / 2; + if (num == 0) + break; + count++; + } + i <<= count; + + return i; +} + +inline int getPower2NextNum(int num) +{ + int i = 1; + int count = 0; + + // guard too long number + if (num > INT_MAX / 2) + num = INT_MAX / 2; + + num = num - 1; + for (;;) { + num = num / 2; + if (num == 0) + break; + count++; + } + + i <<= (count + 1); + return i; +} + +/* we need split the hash table implementation and some hash-based + * operator common structure. */ +class hashBasedOperator : public BaseObject { +public: + hashBasedOperator() : m_spillToDisk(false), m_rows(0), m_totalMem(0), m_availmems(0) + { + m_filesource = NULL; + m_innerHashFuncs = NULL; + m_key = 0; + m_cols = 0; + m_sysBusy = false; + m_outerHashFuncs = NULL; + m_overflowsource = NULL; + m_hashContext = NULL; + m_keyDesc = NULL; + m_tupleCount = 0; + m_hashTbl = NULL; + m_colWidth = 0; + m_cellSize = 0; + m_tmpContext = NULL; + m_colDesc = NULL; + m_spreadNum = 0; + m_okeyIdx = NULL; + m_fill_table_rows = 0; + m_keyIdx = NULL; + m_keySimple = false; + m_eqfunctions = NULL; + m_strategy = 0; + m_maxMem = 0; + } + + virtual ~hashBasedOperator() + {} + + // build a hash table + virtual void Build() = 0; + + // probe the hash table. + virtual VectorBatch* Probe() = 0; + + // create temprorary file. + hashFileSource* CreateTempFile(VectorBatch* batch, int fileNum, PlanState* planstate); + + // close temprorary file. + void closeFile(); + + FORCE_INLINE + int64 getRows() + { + return m_rows; + } + + int getFileNum() + { + if (m_filesource != NULL) + return m_filesource->m_fileNum; + else + return 0; + } + + int calcFileNum(long numGroups); + + // replace some equal function. + void ReplaceEqfunc(); + + // judge memory over flow. + void JudgeMemoryOverflow(char* opname, int planid, int dop, Instrumentation* instrument = NULL); + + /* judge memory allow table expnd */ + bool JudgeMemoryAllowExpand(); + + // free memory context. + void freeMemoryContext(); + + // simple hash function without string type in the key + template + void hashCellT(hashCell* cell, int keyIdx, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes); + + template + void hashColT(ScalarVector* val, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes); + + inline void hashBatch( + VectorBatch* batch, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill = false); + + inline void hashCellArray( + hashCell* cell, int nrows, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill = false); + +public: + vechashtable* m_hashTbl; + + // memory context for hash. + MemoryContext m_hashContext; + + // memory context for temprorary calculation. + MemoryContext m_tmpContext; + + /* memory context for hashtable and hashcell. + * need not free and apply memory again, only do reset when rescan. + */ + + // cache location + ScalarValue m_cacheLoc[BatchMaxSize]; + + hashCell* m_cellCache[BatchMaxSize]; + + // flag the key match + bool m_keyMatch[BatchMaxSize]; + + FmgrInfo* m_eqfunctions; /* equal function */ + + FmgrInfo* m_outerHashFuncs; /* lookup data for hash functions */ + + FmgrInfo* m_innerHashFuncs; /* lookup data for hash functions */ + + // spilling file. + hashFileSource* m_filesource; + + hashFileSource* m_overflowsource; + + // whether spill to disk. + bool m_spillToDisk; + + // memory or disk. + int m_strategy; + + // how many rows in hash table + int64 m_rows; + + /*total memory, in bytes*/ + int64 m_totalMem; + + /*avail memory */ + int64 m_availmems; + + // how many cols in the hash table. + int m_cols; + + // how many key in the hash table. + int m_key; + + int* m_keyIdx; /* list of varattno on hash keys. */ + int* m_okeyIdx; /* list of original value of varattno on hash keys. */ + + ScalarDesc* m_keyDesc; // indicate key desc + + ScalarDesc* m_colDesc; // indicate col desc; + + // whether the key is simple. 1:is simple 2: not simple + // simple means there is no variable length data type or complex expression evaluation. + bool m_keySimple; + + int m_cellSize; + + /* row numbers in memory of first spill */ + int m_fill_table_rows; + + /* records avg width of encoded columns in memory */ + int64 m_tupleCount; + int64 m_colWidth; + + /* record memory auto spread info */ + int64 m_maxMem; + int m_spreadNum; + + /* If disk spill caused by system resource danger */ + bool m_sysBusy; +}; + +// chain +class vechashtable : public BaseObject { +public: + vechashtable(int hashSize) : m_size(hashSize), m_data(0) + { + m_data = (hashCell**)palloc0(m_size * sizeof(hashCell*)); + } + // depend the sub class to init the member variable. + ~vechashtable() + { + if (m_data) + pfree(m_data); + + m_data = NULL; + m_size = 0; + } + + void Reset() + { + Assert(m_size != 0); + m_data = (hashCell**)palloc0(m_size * sizeof(hashCell*)); + } + + void Profile(char* stats, bool* can_wlm_warning_statistics); + +public: + int m_size; // hash table size + + hashCell** m_data; // hash table data. +}; + +#define GET_HASH_TABLE(node) (((vechashtable*)(node->hashTbl))) + +// simple hash function without string type in the key +template +inline void hashBasedOperator::hashCellT(hashCell* cell, int keyIdx, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes) +{ + hashVal val; + ScalarValue hashV; + FunctionCallInfoData fcinfo; + Datum args[2]; + fcinfo.arg = &args[0]; + fcinfo.flinfo = hashFmgr; + PGFunction func = hashFmgr->fn_addr; + + for (int j = 0; j < nval; j++) { + val = cell->m_val[keyIdx]; + if (likely(NOT_NULL(val.flag))) { + fcinfo.arg[0] = val.val; + if (reHash) { + /* rotate hashkey left 1 bit at each rehash step */ + hashV = hashRes[j]; + hashV = (hashV << 1) | ((hashV & 0x80000000) ? 1 : 0); + hashV ^= func(&fcinfo); + hashRes[j] = hashV; + } else + hashRes[j] = func(&fcinfo); + } else { + if (!reHash) + hashRes[j] = 0; // give the init value; + } + + cell = (hashCell*)((char*)cell + m_cellSize); + } +} + +// simple hash function without string type in the key +template +inline void hashBasedOperator::hashColT(ScalarVector* val, FmgrInfo* hashFmgr, int nval, ScalarValue* hashRes) +{ + ScalarValue* value = val->m_vals; + uint8* flag = val->m_flag; + FunctionCallInfoData fcinfo; + Datum args[2]; + fcinfo.arg = &args[0]; + fcinfo.flinfo = hashFmgr; + PGFunction func = hashFmgr->fn_addr; + ScalarValue hashV; + + for (int j = 0; j < nval; j++) { + if (likely(NOT_NULL(flag[j]))) { + fcinfo.arg[0] = value[j]; + if (reHash) { + /* rotate hashkey left 1 bit at each rehash step */ + hashV = hashRes[j]; + hashV = (hashV << 1) | ((hashV & 0x80000000) ? 1 : 0); + hashV ^= func(&fcinfo); + hashRes[j] = hashV; + } else + hashRes[j] = func(&fcinfo); + } else { + if (!reHash) + hashRes[j] = 0; // give the init value; + } + } +} + +inline void hashBasedOperator::hashBatch( + VectorBatch* batch, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill) +{ + int i; + int nrows = batch->m_rows; + ScalarVector* pVector = batch->m_arr; + AutoContextSwitch memGuard(m_tmpContext); + + hashColT(&pVector[keyIdx[0]], hashFmgr, nrows, hashRes); + + for (i = 1; i < m_key; i++) + hashColT(&pVector[keyIdx[i]], (hashFmgr + i), nrows, hashRes); + + /* Rehash the hash value for avoiding the key and distribute key using the same hash function. */ + for (i = 0; i < nrows; i++) { + if (needSpill) + hashRes[i] = hash_new_uint32(DatumGetUInt32(hashRes[i])); + else + hashRes[i] = hash_uint32(DatumGetUInt32(hashRes[i])); + } + + MemoryContextReset(m_tmpContext); +} + +inline void hashBasedOperator::hashCellArray( + hashCell* cell, int nrows, int* keyIdx, ScalarValue* hashRes, FmgrInfo* hashFmgr, bool needSpill) +{ + int i; + AutoContextSwitch memGuard(m_tmpContext); + + hashCellT(cell, keyIdx[0], hashFmgr, nrows, hashRes); + + for (i = 1; i < m_key; i++) + hashCellT(cell, keyIdx[i], (hashFmgr + i), nrows, hashRes); + + /* Rehash the hash value for avoiding the key and distribute key using the same hash function. */ + for (i = 0; i < nrows; i++) { + if (needSpill) + hashRes[i] = hash_new_uint32(DatumGetUInt32(hashRes[i])); + else + hashRes[i] = hash_uint32(DatumGetUInt32(hashRes[i])); + } + + MemoryContextReset(m_tmpContext); +} + +extern ScalarValue addVariable(MemoryContext context, ScalarValue val); +extern ScalarValue replaceVariable(MemoryContext context, ScalarValue oldVal, ScalarValue val); +extern ScalarValue addToVarBuffer(VarBuf* buf, ScalarValue value); +extern void* TempFileCreate(); +extern ScalarValue DatumToScalarInContext(MemoryContext context, Datum datumVal, Oid datumType); + +#endif /* VECHASHTABLE_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/veclimit.h postgresql-hll-2.14/include/vecexecutor/veclimit.h --- postgresql-hll-2.14_old/include/vecexecutor/veclimit.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/veclimit.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * veclimit.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/veclimit.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODELIMIT_H +#define VECNODELIMIT_H + +#include "vecexecutor/vecnodes.h" + +extern VectorBatch* ExecVecLimit(VecLimitState* node); +extern VecLimitState* ExecInitVecLimit(VecLimit* node, EState* estate, int eflags); +extern void ExecEndVecLimit(VecLimitState* node); +extern void ExecReScanVecLimit(VecLimitState* node); + +#endif /*VECNODELIMIT_H*/ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecmaterial.h postgresql-hll-2.14/include/vecexecutor/vecmaterial.h --- postgresql-hll-2.14_old/include/vecexecutor/vecmaterial.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecmaterial.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmaterial.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmaterial.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMATERIAL_H +#define VECMATERIAL_H + +#include "vecexecutor/vecnodes.h" + +extern VecMaterialState* ExecInitVecMaterial(VecMaterial* node, EState* estate, int eflags); +extern VectorBatch* ExecVecMaterial(VecMaterialState* node); +extern void ExecEndVecMaterial(VecMaterialState* node); +extern void ExecVecMaterialMarkPos(VecMaterialState* node); +extern void ExecVecMaterialRestrPos(VecMaterialState* node); +extern void ExecVecReScanMaterial(VecMaterialState* node); +extern void ExecEarlyFreeVecMaterial(VecMaterialState* node); + +#endif /* VECMATERIAL_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecmergeinto.h postgresql-hll-2.14/include/vecexecutor/vecmergeinto.h --- postgresql-hll-2.14_old/include/vecexecutor/vecmergeinto.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecmergeinto.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmergeinto.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmergeinto.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMERGEINTO_H +#define VECMERGEINTO_H + +#include "nodes/execnodes.h" + +struct VecModifyTableState; + +extern void ExecVecMerge(VecModifyTableState* mtstate); + +extern void ExecInitVecMerge(ModifyTableState* mtstate, EState* estate, ResultRelInfo* resultRelInfo); + +#endif /* VECMERGEINTO_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecmergejoin.h postgresql-hll-2.14/include/vecexecutor/vecmergejoin.h --- postgresql-hll-2.14_old/include/vecexecutor/vecmergejoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecmergejoin.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmergejoin.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmergejoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMERGEJOIN_H +#define VECMERGEJOIN_H + +#include "nodes/execnodes.h" +#include "executor/nodeMergejoin.h" +extern VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int eflags); +extern VectorBatch* ExecVecMergeJoin(VecMergeJoinState* node); +extern void ExecEndVecMergeJoin(VecMergeJoinState* node); +extern void ExecReScanVecMergeJoin(VecMergeJoinState* node); + +#endif /* EVECMERGEJOIN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecmodifytable.h postgresql-hll-2.14/include/vecexecutor/vecmodifytable.h --- postgresql-hll-2.14_old/include/vecexecutor/vecmodifytable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecmodifytable.h 2020-12-12 17:06:43.409350129 +0800 @@ -0,0 +1,54 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecmodifytable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecmodifytable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECMODIFYTABLE_H +#define VECMODIFYTABLE_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" + +extern VecModifyTableState* ExecInitVecModifyTable(VecModifyTable* node, EState* estate, int eflags); + +extern VectorBatch* ExecVecModifyTable(VecModifyTableState* node); + +extern void ExecEndVecModifyTable(VecModifyTableState* node); + +extern void ExecReScanVecModifyTable(VecModifyTableState* node); + +template +extern VectorBatch* ExecVecUpdate( + VecModifyTableState* state, T* update_op, VectorBatch* batch, EState* estate, bool canSetTag, int options); + +template +extern VectorBatch* ExecVecInsert(VecModifyTableState* state, T* insert_op, VectorBatch* batch, VectorBatch* planBatch, + EState* estate, bool canSetTag, int options); + +extern bool checkInsertScanPartitionSame(VecModifyTableState* mtstate); + +struct InsertArg; +extern void* CreateOperatorObject(CmdType operation, bool isPartitioned, Relation resultRelationDesc, + ResultRelInfo* resultRelInfo, EState* estate, TupleDesc sortTupDesc, InsertArg* args, Relation* dataDestRel, + VecModifyTableState* node); + +#endif /* VECMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnestloop.h postgresql-hll-2.14/include/vecexecutor/vecnestloop.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnestloop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnestloop.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,113 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnestloop.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnestloop.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNESTLOOP_H +#define VECNESTLOOP_H + +#include "vecexecutor/vecnodes.h" + +extern VectorBatch* ExecVecNestloop(VecNestLoopState* node); +extern VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int eflags); +extern void ExecEndVecNestLoop(VecNestLoopState* node); +extern void ExecReScanVecNestLoop(VecNestLoopState* node); + +#define NL_NEEDNEWOUTER 1 +#define NL_NEEDNEXTOUTROW 2 +#define NL_EXECQUAL 3 +#define NL_END 4 + +class VecNestLoopRuntime : public BaseObject { + +public: + VecNestLoopRuntime(VecNestLoopState* runtime); + + template + VectorBatch* JoinT(); + + void Rescan(); + + /* To avoid Coverity Warning: missing_user_dtor */ + virtual ~VecNestLoopRuntime(); + +private: + template + void FetchOuterT(); + + void NextOuterRow(); + + void OutJoinBatchAlignInnerJoinBatch(int rows); + + template + VectorBatch* JoinQualT(); + + template + void InitT(List* joinqual, List* otherqual, ProjectionInfo* projInfo); + + void BindingFp(); + + VectorBatch* (VecNestLoopRuntime::*WrapperBatch)(VectorBatch* batch); + + VectorBatch* (VecNestLoopRuntime::*JoinOnQual)(); + + void (VecNestLoopRuntime::*FetchOuter)(); + +private: + VecNestLoopState* m_runtime; + + // runtime status + // + int m_status; + + // a batch with 1 null row, for left/anti join + // + VectorBatch* m_innerNullBatch; + + // outer batch + // + VectorBatch* m_outerBatch; + + // 1 row from outer batch, but we set for a batch max size + // + VectorBatch* m_outJoinBatch; + + int m_outReadIdx; + + JoinType m_joinType; + + bool m_matched; + + VectorBatch* m_currentBatch; + + VectorBatch* m_bckBatch; + + int m_bufferRows; + + bool m_SimpletargetCol; + + bool m_outerTargetIsNull; + + int m_outJoinBatchRows; +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexand.h postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexand.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexand.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexand.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexand.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexand.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXAND_H +#define VECNODECSTOREINDEXAND_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexAndState* ExecInitCstoreIndexAnd(CStoreIndexAnd* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexAnd(CStoreIndexAndState* node); +extern void ExecEndCstoreIndexAnd(CStoreIndexAndState* node); +extern void ExecReScanCstoreIndexAnd(CStoreIndexAndState* node); + +#endif /* VECNODECSTOREINDEXAND_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexctidscan.h postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexctidscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexctidscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexctidscan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexctidscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexctidscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXCTIDSCAN_H +#define VECNODECSTOREINDEXCTIDSCAN_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexCtidScanState* ExecInitCstoreIndexCtidScan(CStoreIndexCtidScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecEndCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecReScanCstoreIndexCtidScan(CStoreIndexCtidScanState* state); +extern void ExecInitPartitionForBitmapIndexScan(BitmapIndexScanState* indexstate, EState* estate, Relation rel); + +#endif /* CSTOREINDEXCTIDSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexheapscan.h postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexheapscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexheapscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexheapscan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexheapscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexheapscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTOREINDEXHEAPSCAN_H +#define VECNODECSTOREINDEXHEAPSCAN_H + +extern CStoreIndexHeapScanState* ExecInitCstoreIndexHeapScan(CStoreIndexHeapScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexHeapScan(CStoreIndexHeapScanState* state); +extern void ExecEndCstoreIndexHeapScan(CStoreIndexHeapScanState* state); +extern void ExecReScanCstoreIndexHeapScan(CStoreIndexHeapScanState* state); + +#endif /* CSTOREINDEXHEAPSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexor.h postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexor.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexor.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexor.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexor.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexor.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECCSTOREINDEXOR_H +#define VECCSTOREINDEXOR_H + +#include "vecexecutor/vecnodes.h" + +extern CStoreIndexOrState* ExecInitCstoreIndexOr(CStoreIndexOr* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexOr(CStoreIndexOrState* node); +extern void ExecEndCstoreIndexOr(CStoreIndexOrState* node); +extern void ExecReScanCstoreIndexOr(CStoreIndexOrState* node); + +#endif /* VECCSTOREINDEXOR_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexscan.h postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstoreindexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstoreindexscan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,41 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstoreindexscan.h + * + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstoreindexscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEINDEXSCAN_H +#define VECNODEINDEXSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" + +// Column index scan interfaces +// +extern CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* estate, int eflags); +extern VectorBatch* ExecCstoreIndexScan(CStoreIndexScanState* node); +extern void ExecEndCstoreIndexScan(CStoreIndexScanState* node); +extern void ExecCstoreIndexMarkPos(CStoreIndexScanState* node); +extern void ExecCstoreIndexRestrPos(CStoreIndexScanState* node); +extern void ExecReScanCStoreIndexScan(CStoreIndexScanState* node); + +#endif /* VECNODEINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodecstorescan.h postgresql-hll-2.14/include/vecexecutor/vecnodecstorescan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodecstorescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodecstorescan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,71 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodecstorescan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodecstorescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODECSTORESCAN_H +#define VECNODECSTORESCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" +#include "access/cstoreskey.h" +#include "vecexecutor/vecexecutor.h" +#include "executor/executor.h" +#include "utils/memutils.h" + +typedef enum { BTREE_INDEX, BTREE_INDEX_ONLY, PSORT_INDEX, PSORT_INDEX_ONLY } IndexType; + +extern CStoreScanState* ExecInitCStoreScan(CStoreScan* node, Relation parentHeapRel, EState* estate, int eflags, + bool indexFlag = false, bool codegenInUplevel = false); +extern DfsScanState* ExecInitDfsScan( + DfsScan* node, Relation parentHeapRel, EState* estate, int eflags, bool indexFlag = false); +extern VectorBatch* ExecCStoreScan(CStoreScanState* node); +extern VectorBatch* ExecDfsScan(DfsScanState* node); +extern void ExecReScanDfsScan(DfsScanState* node); +extern void ExecEndCStoreScan(CStoreScanState* node, bool indexFlag); +extern void ExecEndDfsScan(DfsScanState* node); +extern void ExecReSetRuntimeKeys(CStoreScanState* node); +extern void ExecReScanCStoreScan(CStoreScanState* node); +extern void ExecCStoreBuildScanKeys(CStoreScanState* state, List* quals, CStoreScanKey* scankeys, int* numScanKeys); +extern void ExecReScanCStoreIndexScan(CStoreIndexScanState* node); + +extern void OptimizeProjectionAndFilter(CStoreScanState* node); + +extern VectorBatch* ApplyProjectionAndFilter( + CStoreScanState* node, VectorBatch* pScanBatch, ExprDoneCond* isDone = NULL); + +extern TupleDesc BuildTupleDescByTargetList(List* tlist); +extern void BuildCBtreeIndexScan(CBTreeScanState* btreeIndexScan, ScanState* scanstate, Scan* node, EState* estate, + Relation indexRel, List* indexqual, List* indexorderby); +extern void BuildCBtreeIndexOnlyScan(CBTreeOnlyScanState* btreeIndexOnlyScan, ScanState* scanstate, Scan* node, + EState* estate, Relation indexRel, List* indexqual, List* indexorderby); +extern Batchsortstate* InitTidSortState(TupleDesc sortTupDesc, int tidAttNo, int sortMem = 0, int maxMem = 0); +extern void PutBatchToSorter(IndexSortState* sort, VectorBatch* batch); +extern bool IsSorterEmpty(IndexSortState* sort); +extern void ResetSorter(IndexSortState* sort); +extern void RunSorter(IndexSortState* sort); +extern void FetchBatchFromSorter(IndexSortState* sort, VectorBatch* tids); +extern void FetchTids(IndexScanDesc scandesc, List* indexScanTargetList, PlanState* ps, IndexSortState* sort, + VectorBatch* tids, bool indexOnly); + +#endif /* NODECSTORESCAN_H */ + diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodedfsindexscan.h postgresql-hll-2.14/include/vecexecutor/vecnodedfsindexscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodedfsindexscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodedfsindexscan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodedfsindexscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodedfsindexscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEDFSINDEXSCAN_H +#define VECNODEDFSINDEXSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "nodes/plannodes.h" + +// Column index scan interfaces +// +extern DfsIndexScanState* ExecInitDfsIndexScan(DfsIndexScan* node, EState* estate, int eflags); +extern VectorBatch* ExecDfsIndexScan(DfsIndexScanState* node); +extern void ExecEndDfsIndexScan(DfsIndexScanState* node); +extern void ExecReScanDfsIndexScan(DfsIndexScanState* node); + +#endif /* VECNODEDFSINDEXSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodeforeignscan.h postgresql-hll-2.14/include/vecexecutor/vecnodeforeignscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodeforeignscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodeforeignscan.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,38 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodeforeignscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodeforeignscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEFOREIGIGNSCAN_H +#define VECNODEFOREIGIGNSCAN_H + +#include "nodes/plannodes.h" +#include "vecexecutor/vecnodes.h" + +extern VecForeignScanState* ExecInitVecForeignScan(VecForeignScan* node, EState* estate, int eflags); + +extern VectorBatch* ExecVecForeignScan(VecForeignScanState* node); + +extern void ExecEndVecForeignScan(VecForeignScanState* node); +extern void ExecReScanVecForeignScan(VecForeignScanState* node); + +#endif /* VECNODEFOREIGIGNSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodemodifytable.h postgresql-hll-2.14/include/vecexecutor/vecnodemodifytable.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodemodifytable.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodemodifytable.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,28 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodemodifytable.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodemodifytable.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEMODIFYTABLE_H +#define VECNODEMODIFYTABLE_H + +#endif /* VECNODEMODIFYTABLE_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnoderesult.h postgresql-hll-2.14/include/vecexecutor/vecnoderesult.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnoderesult.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnoderesult.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnoderesult.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnoderesult.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODERESULT_H +#define VECNODERESULT_H + +#include "vecexecutor/vecnodes.h" + +extern VecResultState* ExecInitVecResult(VecResult* node, EState* estate, int eflags); +extern VectorBatch* ExecVecResult(VecResultState* node); +extern void ExecEndVecResult(VecResultState* node); +extern void ExecReScanVecResult(VecResultState* node); + +#endif /* NODERESULT_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnoderowtovector.h postgresql-hll-2.14/include/vecexecutor/vecnoderowtovector.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnoderowtovector.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnoderowtovector.h 2020-12-12 17:06:43.410350141 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnoderowtovector.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnoderowtovector.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODEROWTOVECTOR_H +#define VECNODEROWTOVECTOR_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +extern RowToVecState* ExecInitRowToVec(RowToVec* node, EState* estate, int eflags); +extern VectorBatch* ExecRowToVec(RowToVecState* node); +extern void ExecEndRowToVec(RowToVecState* node); +extern void ExecReScanRowToVec(RowToVecState* node); +extern bool VectorizeOneTuple(VectorBatch* pBatch, TupleTableSlot* slot, MemoryContext transformContext); +#endif /* NODEROWTOVEC_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodes.h postgresql-hll-2.14/include/vecexecutor/vecnodes.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodes.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodes.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,393 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodes.h + * Definition for vector executor state nodes. + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodes.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODES_H_ +#define VECNODES_H_ + +#include "access/dfs/dfs_am.h" +#include "executor/execStream.h" +#include "nodes/execnodes.h" +#include "access/cstore_am.h" +#include "pgxc/execRemote.h" +#include "access/cstoreskey.h" +#include "tsdb/common/data_row.h" + +typedef ScalarVector* (*vecqual_func)(ExprContext* econtext); + +/* runtime bloomfilter */ +typedef struct BloomFilterRuntime { + List* bf_var_list; /* bloomfilter var list. */ + List* bf_filter_index; /* bloomfilter array index. */ + filter::BloomFilter** bf_array; /* bloomfilter array. */ +} BloomFilterRuntime; + +typedef struct VecHashJoinState : public HashJoinState { + int joinState; + + void* hashTbl; + + FmgrInfo* eqfunctions; + + /* + * function pointer to LLVM machine code if hash join qual + * can be LLVM optimiezed. + */ + vecqual_func jitted_joinqual; /* LLVM IR function pointer to point to + * codegened hash->joinqual expr */ + vecqual_func jitted_hashclause; /* LLVM IR function pointer to point to + * codegened hash clause expr */ + + char* jitted_innerjoin; /* jitted inner hash join */ + char* jitted_matchkey; /* jitted matchKey for hash join*/ + char* jitted_buildHashTable; /* jitted buildHashTable*/ + char* jitted_probeHashTable; /* jitted probeHashTable*/ + int enable_fast_keyMatch; /* fast path for key match + * 0 : normal keyMatch + * 1 : one hash clause + * 2 : fast path keyMatch + */ + BloomFilterRuntime bf_runtime; /* runtime bloomfilter */ + char* jitted_hashjoin_bfaddLong; + char* jitted_hashjoin_bfincLong; + + char* jitted_buildHashTable_NeedCopy; +} VecHashJoinState; + +typedef enum VecAggType { + AGG_COUNT = 0, + AGG_SUM, + AGG_AVG, + AGG_MIN, + AGG_MAX, +} VecAggType; + +typedef struct VecAggInfo { + FunctionCallInfoData vec_agg_function; + FunctionCallInfoData vec_final_function; + VectorFunction* vec_agg_cache; + VectorFunction* vec_sonic_agg_cache; + PGFunction* vec_agg_final; +} VecAggInfo; + +typedef struct VecAggState : public AggState { + void* aggRun; + + VecAggInfo* aggInfo; + char* jitted_hashing; /* LLVM function pointer to point to + * the codegened hashing function */ + char* jitted_sglhashing; /* LLVM function pointer to point to + * the codegened hashing function for + * only single hash table case */ + char* jitted_batchagg; /* LLVM function pointer to point to + * the codegened BatchAggregation + * function */ + char* jitted_sonicbatchagg; /* LLVM function pointer to point to + * the codegened BatchAggregation + * with sonic format */ + char* jitted_SortAggMatchKey; /* LLVM jitted function pointer */ + +} VecAggState; + +typedef struct VecWindowAggState : public WindowAggState { + void* VecWinAggRuntime; + VecAggInfo* windowAggInfo; +} VecWindowAggState; + +struct VecGroupState : public GroupState { + void** container; + void* cap; + uint16 idx; + int cellSize; + bool keySimple; + FmgrInfo* buildFunc; + FmgrInfo* buildScanFunc; + VectorBatch* scanBatch; + VarBuf* currentBuf; + VarBuf* bckBuf; + vecqual_func jitted_vecqual; /* LLVM IR function pointer to point to + * codegened grpstate->ss.ps.qual expr */ +}; + +struct VecUniqueState : public UniqueState { + bool uniqueDone; + void** container; + void* cap; + uint16 idx; + int cellSize; + bool keySimple; + FmgrInfo* buildFunc; + FmgrInfo* buildScanFunc; + VectorBatch* scanBatch; + VarBuf* currentBuf; + VarBuf* bckBuf; +}; + +typedef struct VecSetOpState : public SetOpState { + void* vecSetOpInfo; +} VecSetOpState; + +typedef struct VecSortState : public SortState { + VectorBatch* m_pCurrentBatch; + char* jitted_CompareMultiColumn; /* jitted function for CompareMultiColumn */ + char* jitted_CompareMultiColumn_TOPN; /* jitted function for CompareMultiColumn used by Top N sort */ +} VecSortState; + +typedef struct VecRemoteQueryState : public RemoteQueryState { + VectorBatch* resultBatch; + +} VecRemoteQueryState; + +typedef struct VecToRowState VecToRowState; +typedef void (*DevectorizeFun)(VecToRowState* state, ScalarVector* pColumn, int rows, int cols, int i); +typedef struct VecToRowState { + PlanState ps; + + VectorBatch* m_pCurrentBatch; // current active batch in outputing + int m_currentRow; // position to current row in outpting + int nattrs; // number of attributes + TupleTableSlot* tts; // template of the current returning tts + Datum* m_ttsvalues; // column values of the active batch + bool* m_ttsisnull; // indicator if one column value is null + + DevectorizeFun* devectorizeFunRuntime; + +} VecToRowState; + +typedef struct RowToVecState { + PlanState ps; + + bool m_fNoMoreRows; // does it has more rows to output + VectorBatch* m_pCurrentBatch; // current active batch in outputing +} RowToVecState; + +typedef struct VecResultState : public ResultState { +} VecResultState; + +struct VecAppendState : public AppendState { + // Nothing special for vectorized append +}; + +struct VecStreamState; + +typedef void (*assembleBatchFun)(VecStreamState* vsstate, VectorBatch* batch); + +typedef struct VecStreamState : public StreamState { + VectorBatch* m_CurrentBatch; + assembleBatchFun batchForm; + bool redistribute; + int bitNumericLen; + int bitNullLen; + uint32* m_colsType; + +} VecStreamState; + +typedef struct CStoreScanRunTimeKeyInfo { + CStoreScanKey scan_key; + ExprState* key_expr; +} CStoreScanRunTimeKeyInfo; + +typedef struct CStoreScanState : ScanState { + Relation ss_currentDeltaRelation; + Relation ss_partition_parent; + TableScanDesc ss_currentDeltaScanDesc; + bool ss_deltaScan; + bool ss_deltaScanEnd; + + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + CStoreScanRunTimeKeyInfo* m_pScanRunTimeKeys; + int m_ScanRunTimeKeysNum; + bool m_ScanRunTimeKeysReady; + + CStore* m_CStore; + /*Optimizer Information*/ + CStoreScanKey csss_ScanKeys; // support pushing predicate down to cstore scan. + int csss_NumScanKeys; + + // Optimization for access pattern + // + bool m_fSimpleMap; // if it is simple without need to invoke projection code + bool m_fUseColumnRef; // Use column reference without copy to return data + + vecqual_func jitted_vecqual; + + bool m_isReplicaTable; /* If it is a replication table? */ +} CStoreScanState; + +typedef struct DfsScanState : ScanState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + MemoryContext m_scanCxt; + bool m_done; + dfs::reader::ReaderState* m_readerState; + dfs::reader::Reader* m_fileReader; + List* m_splitList; +} DfsScanState; + +class TimeRange; +class TagFilters; +class TsStoreSearch; + +typedef struct TsStoreScanState : ScanState { + /* Determined by upper layer */ + int top_key_func_arg; + bool is_simple_scan; + bool has_sort; + int limit; // If is limit n + AttrNumber sort_by_time_colidx; // If is sort by tstime limit n + TagRows* tag_rows; + /* regular member */ + VectorBatch* scanBatch; // batch to work on + VectorBatch* currentBatch; // output batch + Relation ss_partition_parent; + vecqual_func jitted_vecqual; + /* ts special */ + TsStoreSearch* ts_store_search; + int tag_id_num; + bool only_const_col; + bool early_stop; + bool tags_scan_done; // cu data has not been finished + TimeRange* time_range; // time range + int* field_column_id; + int field_count; + int scaned_tuples; + bool first_scan; +} TsStoreScanState; + +class Batchsortstate; + +typedef struct IndexSortState { + VectorBatch* m_tids; + int64 m_sortCount; + Batchsortstate* m_sortState; + TupleDesc m_sortTupleDesc; + bool m_tidEnd; +} IndexSortState; + +typedef struct CBTreeScanState : IndexScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CBTreeScanState; + +typedef struct CBTreeOnlyScanState : IndexOnlyScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CBTreeOnlyScanState; + +struct CStoreIndexScanState; +struct DfsIndexScanState; +typedef VectorBatch* (*cstoreIndexScanFunc)(CStoreIndexScanState* state); +typedef void (*dfsIndexScanFunc)(DfsIndexScanState* state); + +typedef struct CstoreBitmapIndexScanState : BitmapIndexScanState { + IndexSortState* m_sort; + List* m_indexScanTList; +} CstoreBitmapIndexScanState; + +typedef struct DfsIndexScanState : DfsScanState { + CStoreScanState* m_indexScan; /* index scan state */ + CBTreeScanState* m_btreeIndexScan; /* cbtree index scan state */ + CBTreeOnlyScanState* m_btreeIndexOnlyScan; /* cbtree index only scan state */ + IndexSortState* m_sort; + List* m_dfsPreparedCols; /* the list of prepared columns(index) */ + bool m_indexonly; /* index only scan flag */ + dfsIndexScanFunc m_dfsIndexScanFunc; +} DfsIndexScanState; + +/* ---------------- + * CstoreIndexScanState information + * A column index scan employees two scan: one for index scan to retrieve + * ctids and the other is the base table scan based on ctids. + */ +typedef struct CStoreIndexScanState : CStoreScanState { + CStoreScanState* m_indexScan; + CBTreeScanState* m_btreeIndexScan; + CBTreeOnlyScanState* m_btreeIndexOnlyScan; + List* m_deltaQual; + bool index_only_scan; + + // scan index and then output tid, these columns in base table + // + int* m_indexOutBaseTabAttr; + int* m_idxInTargetList; + int m_indexOutAttrNo; + cstoreIndexScanFunc m_cstoreIndexScanFunc; +} CStoreIndexScanState; + +typedef struct CStoreIndexCtidScanState : CStoreIndexScanState { + CstoreBitmapIndexScanState* m_cstoreBitmapIndexScan; +} CStoreIndexCtidScanState; + +typedef struct CStoreIndexHeapScanState : CStoreIndexScanState { +} CStoreIndexHeapScanState; + +typedef struct CStoreIndexAndState : public BitmapAndState { + StringInfo resultTids; + uint64 fetchCount; + VectorBatch* m_resultBatch; +} CStoreIndexAndState; + +typedef struct CStoreIndexOrState : public BitmapOrState { + StringInfo resultTids; + uint64 fetchCount; + VectorBatch* m_resultBatch; +} CStoreIndexOrState; + +typedef void (*AddVarFunc)(ScalarVector* vec, Datum v, int row); + +typedef struct VecForeignScanState : public ForeignScanState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch + MemoryContext m_scanCxt; + bool m_done; + Datum* m_values; + bool* m_nulls; +} VecForeignScanState; + +typedef struct VecModifyTableState : public ModifyTableState { + VectorBatch* m_pScanBatch; // batch to work on + VectorBatch* m_pCurrentBatch; // output batch +} VecModifyTableState; + +typedef struct VecSubqueryScanState : public SubqueryScanState { +} VecSubqueryScanState; + +struct VecNestLoopState : public NestLoopState { + void* vecNestLoopRuntime; + vecqual_func jitted_vecqual; + vecqual_func jitted_joinqual; +}; + +typedef struct VecPartIteratorState : public PartIteratorState { +} VecPartIteratorState; + +class BatchStore; + +typedef struct VecMaterialState : public MaterialState { + VectorBatch* m_pCurrentBatch; + BatchStore* batchstorestate; + bool from_memory; +} VecMaterialState; + +#endif /* VECNODES_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodesort.h postgresql-hll-2.14/include/vecexecutor/vecnodesort.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodesort.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodesort.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,44 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodesort.h + * + * + * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodesort.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECSORT_H +#define NODEVECSORT_H + +#include "nodes/execnodes.h" +#include "vecexecutor/vecnodes.h" +#include "workload/workload.h" + +extern VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags); +extern VectorBatch* ExecVecSort(VecSortState* node); +extern void ExecEndVecSort(VecSortState* node); +extern void ExecVecSortMarkPos(VecSortState* node); +extern void ExecVecSortRestrPos(VecSortState* node); +extern void ExecReScanVecSort(VecSortState* node); +extern long ExecGetMemCostVecSort(VecSort*); +extern void ExecEarlyFreeVecSort(VecSortState* node); + +#endif /* NODEVECSORT_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecnodevectorow.h postgresql-hll-2.14/include/vecexecutor/vecnodevectorow.h --- postgresql-hll-2.14_old/include/vecexecutor/vecnodevectorow.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecnodevectorow.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,36 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecnodevectorow.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecnodevectorow.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECTOROW_H +#define NODEVECTOROW_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" + +extern VecToRowState* ExecInitVecToRow(VecToRow* node, EState* estate, int eflags); +extern TupleTableSlot* ExecVecToRow(VecToRowState* node); +extern void ExecEndVecToRow(VecToRowState* node); +extern void ExecReScanVecToRow(VecToRowState* node); + +#endif /* NODEVECTOROW_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecpartiterator.h postgresql-hll-2.14/include/vecexecutor/vecpartiterator.h --- postgresql-hll-2.14_old/include/vecexecutor/vecpartiterator.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecpartiterator.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecpartiterator.h + * Partition Iterator is a new execution operator for partition wise join. + * + * IDENTIFICATION + * src/include/vecexecutor/vecpartiterator.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECPARTITERATOR_H +#define VECPARTITERATOR_H + +#include "vecexecutor/vecnodes.h" + +extern VecPartIteratorState* ExecInitVecPartIterator(VecPartIterator* node, EState* estate, int eflags); +extern VectorBatch* ExecVecPartIterator(VecPartIteratorState* node); +extern void ExecEndVecPartIterator(VecPartIteratorState* node); +extern void ExecReScanVecPartIterator(VecPartIteratorState* node); + +#endif /* VECPARTITERATOR_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecplainagg.h postgresql-hll-2.14/include/vecexecutor/vecplainagg.h --- postgresql-hll-2.14_old/include/vecexecutor/vecplainagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecplainagg.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,62 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecplainagg.h + * plain agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vecplainagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECPLAINAGG_H +#define VECPLAINAGG_H + +#include "vecexecutor/vecagg.h" + +class PlainAggRunner : public BaseAggRunner { +public: + VectorBatch* Run(); + + PlainAggRunner(VecAggState* runtime); + ~PlainAggRunner(){}; + + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node); + + void endPlainAgg(); + +private: + /* Plain aggregation without group by.*/ + template + VectorBatch* RunPlain(); + + void BindingFp(); + + VectorBatch* (PlainAggRunner::*plainAggregation)(); + + template + void buildPlaintAgg(VectorBatch* outerBatch, bool first_batch); +}; + +#endif /* VECPLAINAGG_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecremotequery.h postgresql-hll-2.14/include/vecexecutor/vecremotequery.h --- postgresql-hll-2.14_old/include/vecexecutor/vecremotequery.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecremotequery.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,33 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecremotequery.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecremotequery.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECREMOTEQUERY_H_ +#define VECREMOTEQUERY_H_ + +extern VectorBatch* ExecVecRemoteQuery(VecRemoteQueryState* node); +extern VecRemoteQueryState* ExecInitVecRemoteQuery(VecRemoteQuery* node, EState* estate, int eflags); +extern void ExecEndVecRemoteQuery(VecRemoteQueryState* node); +extern void ExecVecRemoteQueryReScan(VecRemoteQueryState* node, ExprContext* exprCtxt); + +#endif /* VECREMOTEQUERY_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecsetop.h postgresql-hll-2.14/include/vecexecutor/vecsetop.h --- postgresql-hll-2.14_old/include/vecexecutor/vecsetop.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecsetop.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,170 @@ +/* + * 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; /* number of left-input dups in group */ + long numRight; /* number of right-input dups in group */ +} VecSetOpStatePerGroupData; + +struct SetOpHashCell { + SetOpHashCell* m_next; + VecSetOpStatePerGroupData perGroup; + hashVal m_val[FLEXIBLE_ARRAY_MEMBER]; +}; + +struct SetOpStateLog { + bool restore; /* indicate that the output scanbatch is full, and need to restore one */ + int lastIdx; /* store the last idx in m_setOpHashData */ + int numOutput; /* store the remaining number of ouput for the current cell */ + SetOpHashCell* lastCell; /* store the last SetOpHashCell for the next time to go on processing */ +}; + +class setOpTbl : public hashBasedOperator { +public: + setOpTbl(VecSetOpState* runtime); + ~setOpTbl(){}; + + // reset the environment if necessary when rescan + // + void ResetNecessary(VecSetOpState* node); + + /* the entrance to start build the hashtable */ + void Build(); + + /* probe the established hash table to get the result batch */ + VectorBatch* Probe(); + + /* the function point pointing to execute the mainly task */ + VectorBatch* (setOpTbl::*Operation)(); + +private: + /* bind the function point to the coresponding function */ + void BindingFp(); + + /* hash based Set Operation */ + VectorBatch* RunHash(); + + /* sort based Set Operation */ + template + 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); + + /* get the hash source */ + hashSource* GetHashSource(); + + /* function point to build the hash table */ + void (setOpTbl::*m_BuildFun)(VectorBatch* batch); + + /* function point to build the scan batch for the output result */ + void (setOpTbl::*m_BuildScanBatch)(SetOpHashCell* cell); + + /* the implemental function to build hash table */ + template + void BuildSetOpTbl(VectorBatch* batch); + + /* the function to initialize the hashCell, which is also used to initialize the firstCell in sort strategy */ + template + void InitCell(SetOpHashCell* cell, VectorBatch* batch, int row, int flag); + + /* the function to compare row in batch and cell */ + template + bool MatchKey(VectorBatch* batch, int batchIdx, SetOpHashCell* cell); + + /* the implemental function to build scan batch */ + void BuildScanBatch(SetOpHashCell* cell); + template + int computeHashTableSize(int oldsize); + void HashTableGrowUp(); + + FORCE_INLINE uint32 get_bucket(uint32 hashvalue) + { + return hashvalue & (m_size - 1); + } + template + void AllocHashSlot(VectorBatch* batch, int i, int flag, bool foundMatch, SetOpHashCell* cell); + ScalarValue getHashValue(SetOpHashCell* hashentry); + +private: + VecSetOpState* m_runtime; + + /* the number of output columns, include additional column*/ + int m_outerColNum; + + int m_runState; + + /* flag to identify which side of the input */ + int m_firstFlag; + + /* indicate the flag column added by system */ + AttrNumber m_junkCol; + + hashSource* m_hashSource; + + /* include four types which use different strategy to compute the numOutput */ + int m_cmd; + + /* some status log */ + SetOpStateLog m_statusLog; + + /* the batch for scan the result */ + VectorBatch* m_scanBatch; + + /* this is used to store all heads of SetOpHashCell linked lists like m_data */ + SetOpHashCell** m_setOpHashData; + + /* set op hash table size*/ + int m_size; + + VectorBatch* m_lastBatch; + + int m_max_hashsize; /* memory allowed max hashtable size */ + bool m_can_grow; /* mark weather can grow up */ + int64 m_grow_threshold; /* the threshold to grow up */ +}; + +#define DO_SETOPERATION(tbl) (((setOpTbl*)tbl)->*(((setOpTbl*)tbl)->Operation))() + +#endif /* VECSETOP_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecsortagg.h postgresql-hll-2.14/include/vecexecutor/vecsortagg.h --- postgresql-hll-2.14_old/include/vecexecutor/vecsortagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecsortagg.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,133 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsortagg.h + * sort agg class and class member declare. + * + * IDENTIFICATION + * src/include/vecexecutor/vecsortagg.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef VECSORTAGG_H_ +#define VECSORTAGG_H_ + +#include "vecexecutor/vecagg.h" + +#define GET_MATCH_KEY 0 +#define SORT_MATCH 1 + +#define GET_SOURCE 0 +#define RUN_SORT 1 +#define SWITCH_PARSE 2 + +typedef struct GroupintAtomContainer { + hashCell* sortGrp[2 * BatchMaxSize]; + + /* we need double space for extreme case.*/ + VarBuf* sortBckBuf; + + VarBuf* sortCurrentBuf; + + /* the structure to support the sort group aggregation.*/ + int sortGrpIdx; + +} GroupintAtomContainer; + +class SortAggRunner : public BaseAggRunner { +public: + SortAggRunner(VecAggState* runtime); + ~SortAggRunner(){}; + + void endSortAgg(); + + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node); + +private: + hashSource* GetSortSource(); + + template + void buildSortAgg(VectorBatch* batch); + + void init_phase(); + + void BindingFp(); + + void switch_phase(); + + void init_indexForApFun(); + + template + void FreeSortGrpMem(int num); + + VectorBatch* ReturnData(); + + VectorBatch* ReturnLastData(); + + void BuildNullScanBatch(); + + bool set_group_num(int current_grp); + + VectorBatch* ReturnNullData(); + + void set_key(); + + template + void BatchMatchAndAgg(int current_grp, VectorBatch* batch); + + VectorBatch* RunSort(); + + /* sort aggregation*/ + VectorBatch* Run(); + +private: + bool m_FreeMem; + + bool m_ApFun; + + bool m_noData; + + int m_prepareState; + + /* group state*/ + int m_groupState; + + GroupintAtomContainer* m_sortGrps; + + /* add for AP function*/ + Batchsortstate* m_batchSortIn; + + /* add for AP function*/ + Batchsortstate* m_batchSortOut; + + /* storage result of sort for cube or grouping set*/ + VectorBatch* m_SortBatch; + + hashSource* m_sortSource; + + void (SortAggRunner::*m_buildSortFun)(VectorBatch* batch); +}; + +#endif diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecstore.h postgresql-hll-2.14/include/vecexecutor/vecstore.h --- postgresql-hll-2.14_old/include/vecexecutor/vecstore.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecstore.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,345 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecstore.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecstore.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECSTORE_H +#define VECSTORE_H + +#include "executor/executor.h" +#include "nodes/execnodes.h" +#include "pgstat.h" +#include "storage/buffile.h" +#include "utils/memutils.h" +#include "utils/memprot.h" +#include "utils/datum.h" +#include "vecexecutor/vectorbatch.h" +#include "workload/workload.h" + +/* BatchStore is an opaque type whose details are not known outside + * batchstore.cpp. + * If the first sort column is text or numeric type, allocate one + * more Datum to store the prefixal data for fast compare. + */ + +typedef struct MultiColumns { + Datum* m_values; + uint8* m_nulls; + + int idx; + int size; + + int GetLen(int colNum); + +} MultiColumns; + +/* + * The data of those column to be sorted or unsorted + */ +typedef struct MultiColumnsData { + + MultiColumns* m_memValues; + + /* + * The number of columns + */ + int m_colNum; + + /* + * The capacity of storing row in memory + */ + int m_capacity; + + /* + * The current row number in memory + */ + int m_memRowNum; + + /* + * Initialize variables + */ + void Init(int capacity); + + bool HasFreeSlot(); + + void PutValue(MultiColumns val); + + inline MultiColumns* GetValue(int row); + +} MultiColumnsData; + +class VecStore : public BaseObject { +public: + char* GetData(int colNum, MultiColumns* multiColumn); + void SetData(char* dataPtr, int size, MultiColumns* multiColumn); + void InitColInfo(VectorBatch* batch); + + bool HasFreeSlot(); + + void PutValue(MultiColumns multiColumn); + + void UseMem(int64 size); + + void FreeMem(int64 size); + + bool LackMem(); + + bool GrowMemValueSlots(char* opname, int planid, MemoryContext context); + + void AppendBatch(VectorBatch* batch, MultiColumns& multiColumn, int curRow, bool isfree = true); + + /* + * abbreSortOptimize used to mark whether allocate one more Datum for + * fast compare of two data(text or numeric type) + */ + template + MultiColumns CopyMultiColumn(VectorBatch* batch, int row) + { + MultiColumns multiColValue; + m_colNum = batch->m_cols; + if (abbreSortOptimize) + multiColValue.m_values = (ScalarValue*)palloc((batch->m_cols + 1) * sizeof(Datum)); + else + multiColValue.m_values = (ScalarValue*)palloc(batch->m_cols * sizeof(Datum)); + UseMem(GetMemoryChunkSpace(multiColValue.m_values)); + + multiColValue.m_nulls = (uint8*)palloc(batch->m_cols * sizeof(uint8)); + UseMem(GetMemoryChunkSpace(multiColValue.m_nulls)); + if (m_addWidth) + m_colWidth += batch->m_cols * sizeof(Datum) + batch->m_cols * sizeof(uint8); + multiColValue.size = 0; + uint8 flag; + + /* + * When faced with NULL, we just skip, in the following produce, we do the same thing. + */ + for (int col = 0; col < batch->m_cols; ++col) { + Form_pg_attribute attr = tupDesc->attrs[col]; + + flag = batch->m_arr[col].m_flag[row]; + multiColValue.m_nulls[col] = flag; + multiColValue.size += sizeof(uint8); + + if (!IS_NULL(flag)) { + if (NeedDecode(col)) { + ScalarValue val = batch->m_arr[col].m_vals[row]; + Datum v = ScalarVector::Decode(val); + multiColValue.m_values[col] = datumCopy(v, attr->attbyval, VARSIZE_ANY(v)); + if (m_addWidth) + m_colWidth += VARSIZE_ANY(v); + char* p = DatumGetPointer(multiColValue.m_values[col]); + UseMem(GetMemoryChunkSpace(p)); + multiColValue.size += datumGetSize(v, attr->attbyval, VARSIZE_ANY(v)); + } else { + multiColValue.m_values[col] = PointerGetDatum(batch->m_arr[col].m_vals[row]); + multiColValue.size += sizeof(Datum); + } + } + } + return multiColValue; + } + + FORCE_INLINE bool NeedDecode(int col) + { + if (m_colInfo[col].m_desc.encoded) + return true; + return false; + } + void FreeMultiColumn(MultiColumns* pMultiColumn); + +public: + MultiColumnsData m_storeColumns; + + /* + * remaining memory allowed, in bytes + */ + int64 m_availMem; + /* + * total memory allowed, in bytes + */ + int64 m_allowedMem; + ScalarVector* m_colInfo; + int m_colNum; + TupleDesc tupDesc; + int64 m_lastFetchCursor; + int64 m_curFetchCursor; + + int64 m_colWidth; + bool m_addWidth; + bool m_sysBusy; + int64 m_maxMem; + int m_spreadNum; + int m_planId; + int m_dop; +}; + +inline bool MultiColumnsData::HasFreeSlot() +{ + return m_memRowNum < m_capacity - 1; +} + +inline void MultiColumnsData::PutValue(MultiColumns val) +{ + m_memValues[m_memRowNum] = val; + ++m_memRowNum; +} + +inline int MultiColumns::GetLen(int colNum) +{ + return size; +} + +inline MultiColumns* MultiColumnsData::GetValue(int row) +{ + return m_memValues + row; +} + +inline void VecStore::UseMem(int64 size) +{ + m_availMem -= size; +} + +inline void VecStore::FreeMem(int64 size) +{ + m_availMem += size; +} + +inline bool VecStore::LackMem() +{ + int64 usedMem = m_allowedMem - m_availMem; + + if (m_availMem < 0 || gs_sysmemory_busy(usedMem * m_dop, true)) + return true; + + return false; +} + +inline bool VecStore::HasFreeSlot() +{ + return m_storeColumns.HasFreeSlot(); +} + +inline bool VecStore::GrowMemValueSlots(char* opname, int planid, MemoryContext context) +{ + double grow_ratio = + Min(DEFAULT_GROW_RATIO, ((double)(MaxAllocSize / sizeof(MultiColumns))) / m_storeColumns.m_capacity); + double unspread_ratio = grow_ratio; + bool need_spread = false; + int64 mem_used = m_allowedMem - m_availMem; + + if (m_availMem < mem_used) + unspread_ratio = Min(unspread_ratio, (double)m_allowedMem / mem_used); + + /* No grow of rows, so return */ + if (m_storeColumns.m_capacity * unspread_ratio <= m_storeColumns.m_capacity) { + if (m_maxMem < m_allowedMem) + return false; + else + need_spread = true; + } else + grow_ratio = unspread_ratio; + + if (gs_sysmemory_busy((m_allowedMem - m_availMem) * m_dop, true)) { + m_sysBusy = true; + AllocSet sortContext = (AllocSet)context; + sortContext->maxSpaceSize = m_allowedMem - m_availMem; + m_allowedMem = m_allowedMem - m_availMem; + MEMCTL_LOG(LOG, + "%s(%d) early spilled, workmem: %ldKB, freemem: %ldKB.", + opname, + planid, + m_allowedMem / 1024L, + m_availMem / 1024L); + pgstat_add_warning_early_spill(); + return false; + } + + /* For concurrent case, we don't allow sort/materialize to spread a lot */ + if (need_spread && (m_spreadNum < 2 || g_instance.wlm_cxt->stat_manager.comp_count == 1)) { + if (m_availMem < 0) + m_allowedMem -= m_availMem; + int64 spreadMem = Min(Min(dywlm_client_get_memory() * 1024L, m_allowedMem), m_maxMem - m_allowedMem); + if (spreadMem <= m_allowedMem * MEM_AUTO_SPREAD_MIN_RATIO) { + MEMCTL_LOG(LOG, + "%s(%d) auto mem spread %ldKB failed, and work mem is %ldKB.", + opname, + planid, + spreadMem / 1024L, + m_allowedMem / 1024L); + if (m_spreadNum > 0) { + pgstat_add_warning_spill_on_memory_spread(); + } + return false; + } + grow_ratio = Min(grow_ratio, 1 + (double)spreadMem / m_allowedMem); + m_allowedMem += spreadMem; + m_availMem = spreadMem; + AllocSet sortContext = (AllocSet)context; + sortContext->maxSpaceSize += spreadMem; + m_spreadNum++; + MEMCTL_LOG(DEBUG2, + "%s(%d) auto mem spread %ldKB succeed, and work mem is %ldKB.", + opname, + planid, + spreadMem / 1024L, + m_allowedMem / 1024L); + } + + /* if there's no more space after grow, then fail */ + if (m_storeColumns.m_capacity * grow_ratio <= m_storeColumns.m_capacity) { + MEMCTL_LOG(LOG, "%s(%d) mem limit reached.", opname, planid); + return false; + } + + if (!gs_sysmemory_avail(mem_used * (grow_ratio - 1))) { + MEMCTL_LOG(LOG, + "%s(%d) mem lack, workmem: %ldKB, freemem: %ldKB," + "usedmem: %ldKB, grow ratio: %.2f.", + opname, + planid, + m_allowedMem / 1024L, + m_availMem / 1024L, + mem_used / 1024L, + grow_ratio); + return false; + } + + FreeMem(GetMemoryChunkSpace(m_storeColumns.m_memValues)); + + m_storeColumns.m_capacity *= grow_ratio; + m_storeColumns.m_memValues = + (MultiColumns*)repalloc(m_storeColumns.m_memValues, m_storeColumns.m_capacity * sizeof(MultiColumns)); + + UseMem(GetMemoryChunkSpace(m_storeColumns.m_memValues)); + + if (m_availMem < 0) + return false; + + return true; +} + +inline void VecStore::PutValue(MultiColumns multiColValue) +{ + m_storeColumns.PutValue(multiColValue); +} + +#endif /* VECSTORE_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecstream.h postgresql-hll-2.14/include/vecexecutor/vecstream.h --- postgresql-hll-2.14_old/include/vecexecutor/vecstream.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecstream.h 2020-12-12 17:06:43.411350154 +0800 @@ -0,0 +1,37 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecstream.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecstream.h + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VECNODE_H +#define VECNODE_H + +#include "vecexecutor/vecnodes.h" + +// Extern functions +// +extern void HandleStreamBatch(VecStreamState* node, char* msg, int msg_len); +extern VecStreamState* ExecInitVecStream(Stream* node, EState* estate, int eflags); +extern VectorBatch* ExecVecStream(VecStreamState* node); +extern void ExecEndVecStream(VecStreamState* node); +extern void redistributeStreamInitType(TupleDesc desc, uint32* colsType); + +#endif /* VECNODE_H */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecsubplan.h postgresql-hll-2.14/include/vecexecutor/vecsubplan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecsubplan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecsubplan.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,32 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsubplan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecsubplan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ +#define SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ + +#include "nodes/execnodes.h" + +extern SubPlanState* ExecInitVecSubPlan(SubPlan* subplan, PlanState* parent); + +#endif /* SRC_INCLUDE_VECEXECUTOR_VECSUBPLAN_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecsubqueryscan.h postgresql-hll-2.14/include/vecexecutor/vecsubqueryscan.h --- postgresql-hll-2.14_old/include/vecexecutor/vecsubqueryscan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecsubqueryscan.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,40 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecsubqueryscan.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecsubqueryscan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODESUBQUERYSCAN_H +#define VECNODESUBQUERYSCAN_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vectorbatch.h" +#include "nodes/execnodes.h" +#include "nodes/plannodes.h" + +// Vectorized implementation +// +extern VecSubqueryScanState* ExecInitVecSubqueryScan(VecSubqueryScan* node, EState* estate, int eflags); +extern VectorBatch* ExecVecSubqueryScan(VecSubqueryScanState* node); +extern void ExecEndVecSubqueryScan(VecSubqueryScanState* node); +extern void ExecReScanVecSubqueryScan(VecSubqueryScanState* node); + +#endif /* NODESUBQUERYSCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vectorbatch.h postgresql-hll-2.14/include/vecexecutor/vectorbatch.h --- postgresql-hll-2.14_old/include/vecexecutor/vectorbatch.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vectorbatch.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,593 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectorbatch.h + * Core data structure definition for vector engine. + * + * + * IDENTIFICATION + * src/include/vecexecutor/vectorbatch.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECTORBATCH_H_ +#define VECTORBATCH_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "access/tupdesc.h" +#include "lib/stringinfo.h" +#include "catalog/pg_type.h" +// Scalar data type +// +typedef uint64 ScalarValue; + +#define V_NULL_MASK 0b00000001 +#define V_NOTNULL_MASK 0b00000000 +// steal bit to identify variable value +#define MASK_VAR 0xC000000000000000ULL +#define MASK_VAR_POINTER 0x0000000000000000ULL +#define MASK_VAR_STORAGE 0x8000000000000000ULL +#define MASK_POINTER 0x0FFFFFFFFFFFFFFFULL + +#define VAR_POINTER(val) ((val & MASK_VAR) == MASK_VAR_POINTER) +#define VAR_STORAGE(val) ((val & MASK_VAR) == MASK_VAR_STORAGE) + +typedef enum BatchCompressType { BCT_NOCOMP, BCT_LZ4 } BatchCompressType; + +inline bool COL_IS_ENCODE(int typeId) +{ + // we search the sys table to find [0,8] attlen data type + // select typname,typlen from pg_type where typlen >= 0 and typlen <=8; + switch (typeId) { + case CHAROID: + case BOOLOID: + case INT2OID: + case INT8OID: + case INT1OID: + case INT4OID: + case FLOAT4OID: + case FLOAT8OID: + case CASHOID: + case DATEOID: + case TIMEOID: + case TIMESTAMPOID: + case TIMESTAMPTZOID: + case SMALLDATETIMEOID: + case OIDOID: + case TIDOID: + case CIDOID: + case ABSTIMEOID: + case RELTIMEOID: + case ANYOID: + case VOIDOID: + case TRIGGEROID: + case INTERNALOID: + case OPAQUEOID: + case ANYELEMENTOID: + case ANYNONARRAYOID: + case LANGUAGE_HANDLEROID: + case REGPROCOID: + case XIDOID: + case REGPROCEDUREOID: + case REGOPEROID: + case REGOPERATOROID: + case REGCLASSOID: + case REGTYPEOID: + case REGCONFIGOID: + case REGDICTIONARYOID: + case ANYENUMOID: + case FDW_HANDLEROID: + case HLL_HASHVAL_OID: + case SMGROID: + return false; + default: + return true; + } +} + +template +bool COL_IS_ENCODE_T() +{ + return COL_IS_ENCODE(typeId); +} + +#define BOTH_NOT_NULL(flag1, flag2) (likely(NOT_NULL((flag1) | (flag2)))) +#define IS_NULL(flag) (unlikely(((flag)&V_NULL_MASK) == V_NULL_MASK)) +#define NOT_NULL(flag) ((((unsigned int)flag) & V_NULL_MASK) == V_NOTNULL_MASK) +#define SET_NULL(flag) ((flag) = (flag) | V_NULL_MASK) +#define BOTH_NULL(flag1, flag2) (IS_NULL((flag1) & (flag2))) + +#define SET_NOTNULL(flag) ((flag) = (flag) & (~V_NULL_MASK)) +#define BatchIsNull(pBatch) ((pBatch) == NULL || (pBatch)->m_rows == 0) +#define VAR_BUF_SIZE 16384 + +// Retrieve selection vector guarded by selection usage flag +// +#define SelectionVector(pBatch) ((pBatch)->m_checkSel ? (pBatch)->m_sel : NULL) + +#define ShallowCopyVector(targetVector, sourceVector) \ + ((targetVector).m_rows = (sourceVector).m_rows, \ + (targetVector).m_vals = (sourceVector).m_vals, \ + (targetVector).m_flag = (sourceVector).m_flag, \ + (targetVector).m_buf = (sourceVector).m_buf) + +struct ScalarDesc : public BaseObject { + + // Scalar Value type Oid. + Oid typeId; + + // atttypmod records type-specific data supplied at table creation time + // The value will generally be -1 for types that do not need typmod. + int4 typeMod; + + // this value means that the value in the scalarvector may be encoded, on storage/pointer to some + // where else, may be inlined(in which case it is not encode) + // it can be deduct from typeId, + bool encoded : 1; + + ScalarDesc() + { + typeId = InvalidOid; + typeMod = -1; + encoded = false; + }; +}; + +struct varBuf : public BaseObject { + char* buf; + int len; + int size; + varBuf* next; +}; + +class VarBuf : public BaseObject { +public: + // constructor .deconstructor + VarBuf(MemoryContext context); + + ~VarBuf(); + + // init + void Init(); + + void Init(int bufLen); + + void DeInit(bool needFree = true); + + // reset the buf. + void Reset(); + + // append a binary object + char* Append(const char* data, int datalen); + + // allocate a space. + char* Allocate(int datalen); + // add a var + + FORCE_INLINE + ScalarValue AddVar(ScalarValue value) + { + return PointerGetDatum(Append(DatumGetPointer(value), VARSIZE_ANY(value))); + } + +private: + // create a buffer; + varBuf* CreateBuf(int datalen); + + varBuf* m_head; + + varBuf* m_current; + + MemoryContext m_context; + + int m_bufNum; + + int m_bufInitLen; +}; + +// the core data structure for a column +class ScalarVector : public BaseObject { + friend class VectorBatch; + +public: + // number of values. + int m_rows; + + // type desciption information for this scalar value. + ScalarDesc m_desc; + + // this value means that the value in the scalarvector is always the same + bool m_const; + + // flags in the scalar value array. + uint8* m_flag; + + // a company buffer for store the data if the data type is not plain. + VarBuf* m_buf; + + // the value array. + ScalarValue* m_vals; + +public: + // decode a variable length data. + // null value judgement should be outside of this function. + FORCE_INLINE + static Datum Decode(ScalarValue val) + { + return val; + } + + // convert a datum to scalar value + static ScalarValue DatumToScalar(Datum datumVal, Oid datumType, bool isNull); + + template + static ScalarValue DatumToScalarT(Datum datumVal, bool isNull); + +public: + // constructor/deconstructor. + ScalarVector(); + ~ScalarVector(); + + // init the ScalarVector. + // + void init(MemoryContext cxt, ScalarDesc desc); + + // used in tsdb. init with another ScalarVector object. + // + void init(MemoryContext cxt, ScalarVector* vec, const int batchSize); + + // serialize the Scalar vector + // + void Serialize(StringInfo buf); + + // serialize the Scalar vector of the particular index + // + void Serialize(StringInfo buf, int idx); + + // Deserialize the vector + // + char* Deserialize(char* msg, size_t len); + + // Add a variable length data + // this var may be from + // cstring, fixed length(> 8) data type, or pg traditional header-contain variable length + Datum AddVar(Datum data, int index); + + // Add a header-contain variable + Datum AddVarWithHeader(Datum data); + + // Add a variable without header on a special position. The original variable will be + // transfered in together with the length of the content. And inside the funtion, the header + // of the ScalarValue will be added before the actual content according to the data type. + Datum AddBPCharWithoutHeader(const char* data, int maxLen, int len, int aindex); + Datum AddVarCharWithoutHeader(const char* data, int len, int aindex); + + // Add a short decimal without header on a special position. The value of decimal + // will be transfered in by int64 format together with the scale of it. And inside the function, + // the header will be added and the value will be converted into PG format. Here we only support + // short decimal which can be stored using int64. + Datum AddShortNumericWithoutHeader(int64 value, uint8 scale, int aindex); + Datum AddBigNumericWithoutHeader(int128 value, uint8 scale, int aindex); + + char* AddVars(const char* src, int length); + + // add a normal header-contain val + Datum AddHeaderVar(Datum data, int index); + + // add a cstring type val + Datum AddCStringVar(Datum data, int index); + + // add a fixed length val + template + Datum AddFixLenVar(Datum data, int index); + + // copy a vector + void copy(ScalarVector* vector, int start_idx, int endIdx); + void copy(ScalarVector* vector); + + void copyDeep(ScalarVector* vector, int start_idx, int endIdx); + void copyNth(ScalarVector* vector, int Nth); + + void copy(ScalarVector* vector, const bool* pSel); + + // convert a cstring to Scalar value. + static Datum DatumCstringToScalar(Datum data, Size len); + + // convert a fixed len datatype to Scalar Value + static Datum DatumFixLenToScalar(Datum data, Size len); + + FORCE_INLINE + bool IsNull(int i) + { + Assert(i >= 0 && i < m_rows); + return ((m_flag[i] & V_NULL_MASK) == V_NULL_MASK); + } + + FORCE_INLINE + void SetNull(int i) + { + Assert(i >= 0 && i < BatchMaxSize); + m_flag[i] |= V_NULL_MASK; + } + + FORCE_INLINE + void SetAllNull() + { + for (int i = 0; i < m_rows; i++) { + SetNull(i); + } + } + +private: + // init some function pointer. + void BindingFp(); + + Datum (ScalarVector::*m_addVar)(Datum data, int index); +}; + +struct SysColContainer : public BaseObject { + int sysColumns; + ScalarVector* m_ppColumns; + uint8 sysColumpMap[9]; +}; + +#define SelectionVector(pBatch) ((pBatch)->m_checkSel ? (pBatch)->m_sel : NULL) + +// A batch of vectorize rows +// +class VectorBatch : public BaseObject { +public: + // number of rows in the batch. + // + int m_rows; + + // number of columns in the batch. + // + int m_cols; + + // Shall we check the selection vector. + // + bool m_checkSel; + + // Selection vector; + // + bool* m_sel; + + // ScalarVector + // + ScalarVector* m_arr; + + // SysColumns + // + SysColContainer* m_sysColumns; + + // Compress buffer + // + StringInfo m_pCompressBuf; + +public: + // Many Constructors + // + VectorBatch(MemoryContext cxt, TupleDesc desc); + + VectorBatch(MemoryContext cxt, VectorBatch* batch); + + VectorBatch(MemoryContext cxt, ScalarDesc* desc, int ncols); + + // Deconstructor. + // + ~VectorBatch(); + + // Serialize the particular data index of the batch into the buffer. + // + void Serialize(StringInfo buf, int idx); + + // Deserialze the per-row msg into the batch + // + void Deserialize(char* msg); + + // Serialize the batch into the buffer without compress. + // + void SerializeWithoutCompress(StringInfo buf); + + // Deserialze the msg into the batch without compress. + // + void DeserializeWithoutDecompress(char* msg, size_t msglen); + + // Serialize the batch into the buffer with lz4 compress. + // + void SerializeWithLZ4Compress(StringInfo buf); + + // Deserialze the compressed msg into the batch with lz4 compress. + // + void DeserializeWithLZ4Decompress(char* msg, size_t msglen); + + // Reset + // + void Reset(bool resetflag = false); + + void ResetSelection(bool value); + + // Test the batch is valid or not + // + bool IsValid(); + + void FixRowCount(); + + void FixRowCount(int rows); + + // Pack the batch + // + void Pack(const bool* sel); + + /* Optimzed Pack function */ + void OptimizePack(const bool* sel, List* CopyVars); + + /* Optimzed Pack function for later read. later read cols and ctid col*/ + void OptimizePackForLateRead(const bool* sel, List* lateVars, int ctidColIdx); + + // SysColumns + // + void CreateSysColContainer(MemoryContext cxt, List* sysVarList); + ScalarVector* GetSysVector(int sysColIdx); + int GetSysColumnNum(); + + template + void Copy(VectorBatch* batch, int start_idx = 0, int endIdx = -1); + + void CopyNth(VectorBatch* batchSrc, int Nth); + +public: + /* Pack template function. */ + template + void PackT(_in_ const bool* sel); + + /* Optimize template function. */ + template + void OptimizePackT(_in_ const bool* sel, _in_ List* CopyVars); + + /* Optimize template function for later read. */ + template + void OptimizePackTForLateRead(_in_ const bool* sel, _in_ List* lateVars, int ctidColIdx); + +private: + // init the vectorbatch. + void init(MemoryContext cxt, TupleDesc desc); + + void init(MemoryContext cxt, VectorBatch* batch); + + void init(MemoryContext cxt, ScalarDesc* desc, int ncols); +}; + +/* + * @Description: copy batch with specific rows + * @in batch - current batch to be copyed. + * @in startIdx - start index at current batch + * @in endIdx - end index at current batch + * @template deep - weather a deep copy + * @template add - add rows or not + */ +template +void VectorBatch::Copy(VectorBatch* batch, int start_idx, int endIdx) +{ + int copy_end_idx; + copy_end_idx = (endIdx == -1) ? batch->m_rows : endIdx; + for (int i = 0; i < m_cols; i++) { + if (false == add) + m_arr[i].m_rows = 0; + if (deep) { + m_arr[i].copyDeep(&batch->m_arr[i], start_idx, copy_end_idx); + } else { + m_arr[i].copy(&batch->m_arr[i], start_idx, copy_end_idx); + } + } + + if (false == add) + m_rows = 0; + m_rows += copy_end_idx - start_idx; +} + +template +inline ScalarValue ScalarVector::DatumToScalarT(Datum datumVal, bool isNull) +{ + ScalarValue val = 0; + Size datumLen; /* length of the datum */ + + DBG_ASSERT(datumType != InvalidOid); + + if (!isNull) { + if (COL_IS_ENCODE_T()) { + switch (datumType) { + case MACADDROID: + val = DatumFixLenToScalar(datumVal, 6); + break; + case TIMETZOID: + case TINTERVALOID: + val = DatumFixLenToScalar(datumVal, 12); + break; + case INTERVALOID: + case UUIDOID: + val = DatumFixLenToScalar(datumVal, 16); + break; + case NAMEOID: + val = DatumFixLenToScalar(datumVal, 64); + break; + case UNKNOWNOID: + case CSTRINGOID: + datumLen = strlen((char*)datumVal); + val = DatumCstringToScalar(datumVal, datumLen); + break; + default: + val = datumVal; + break; + } + } else + val = datumVal; + } + + return val; +} + +extern Datum ExtractAddrType(Datum* val); +extern Datum ExtractFixedType(Datum* val); +extern Datum ExtractVarType(Datum* val); +extern Datum ExtractCstringType(Datum* val); + +/* + * Convert the scalar value of vector batch to the datum of row tuple. + * @_in_param val: The scalar value to be converted. + * @return the converted datum to be returned. + */ +typedef Datum (*ScalarToDatum)(ScalarValue); +template +Datum convertScalarToDatumT(ScalarValue val) +{ + Datum datum = 0; + switch (typid) { + case VARCHAROID: { + datum = ScalarVector::Decode(val); + break; + } + case TIMETZOID: { + char* result = (char*)(ScalarVector::Decode(val)) + VARHDRSZ_SHORT; + datum = PointerGetDatum(result); + break; + } + case TIDOID: { + datum = PointerGetDatum(val); + break; + } + case UNKNOWNOID: { + Datum tmp = ScalarVector::Decode(val); + char* result = NULL; + if (VARATT_IS_1B(tmp)) { + result = (char*)tmp + VARHDRSZ_SHORT; + } else { + result = (char*)tmp + VARHDRSZ; + } + datum = PointerGetDatum(result); + break; + } + default: { + datum = (Datum)val; + break; + } + } + return datum; +} + +#endif /* VECTORBATCH_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vectorbatch.inl postgresql-hll-2.14/include/vecexecutor/vectorbatch.inl --- postgresql-hll-2.14_old/include/vecexecutor/vectorbatch.inl 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vectorbatch.inl 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,264 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectorbatch.inl + * Core data structure template implementation for vEngine + * + * IDENTIFICATION + * src/include/vecexecutor/vectorbatch.inl + * + * --------------------------------------------------------------------------------------- + */ +#ifndef VECTORBATCH_INL +#define VECTORBATCH_INL + + +/* + * @Description: If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + * @in sel - flag which row we should move. + * @in Copyvars - flag which column we should move. + * @template copyMatch - copy match pattern which always true. + * @template hasSysCol - whether has System column data need to move. + */ +template +void VectorBatch::OptimizePackT(_in_ const bool * sel, _in_ List * CopyVars) +{ + int i, j, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + // Copy all values what we need indeed instead of copy whole table. + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + /* + * If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + */ + ListCell *var = NULL; + foreach (var, CopyVars) + { + int k = lfirst_int(var) - 1; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + + writeIdx ++; + } + } + + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + + +/* + * @Description: If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePackTForLateRead func to move specific column data + * that we want in later read situation. + * @in sel - flag which row we should move. + * @in lateVars - flag which column we should move in late read. + * @in ctidColIdx - flag which ctid column data. + * @template copyMatch - copy match pattern which always true. + * @template hasSysCol - whether has System column data need to move. + */ +template +void VectorBatch::OptimizePackTForLateRead(_in_ const bool * sel, _in_ List * lateVars, int ctidColIdx) +{ + int i, j, k, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + // Copy all values what we need indeed instead of copy whole table. + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + /* + * If we call original Pack func to pack data. + * There are unnecessarily operations that all column data will be moved. + * An optimization is using OptimizePack func to move specific column data that we want. + */ + + ListCell *var = NULL; + foreach (var, lateVars) + { + k = lfirst_int(var) - 1; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + k = ctidColIdx; + pValues = pColumns[k].m_vals; + pFlag = pColumns[k].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + writeIdx ++; + } + } + + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + + + +template +void VectorBatch::PackT (_in_ const bool *sel) +{ + int i, j, writeIdx = 0; + ScalarVector *pColumns = m_arr; + int cRows = m_rows; + int cColumns = m_cols; + ScalarValue *pValues = NULL; + uint8* pFlag = NULL; + errno_t rc = EOK; + + Assert (IsValid()); + + + // Copy all values + // + for (i = 0; i < cRows; i++) + { + bool curSel = *sel ++; + + curSel = copyMatch ?curSel:!curSel; + if (curSel) + { + if (i != writeIdx) + { + Assert (i > writeIdx); + + for (j = 0; j < cColumns; j++) + { + pValues = pColumns[j].m_vals; + pFlag = pColumns[j].m_flag; + + pValues[writeIdx] = pValues[i]; + pFlag[writeIdx] = pFlag[i]; + } + + if(hasSysCol) + { + Assert(m_sysColumns != NULL); + for(j = 0 ; j < m_sysColumns->sysColumns; j++) + { + //sys column do not need null flag + pValues = m_sysColumns->m_ppColumns[j].m_vals; + pValues[writeIdx] = pValues[i]; + } + } + } + + writeIdx ++; + } + } + + // Restore constant columns + // + for (j = 0; j < cColumns; j++) + { + pColumns[j].m_rows = writeIdx; + } + + m_rows = writeIdx; + Assert(m_rows >= 0 && m_rows <= BatchMaxSize); + rc = memset_s(m_sel, BatchMaxSize * sizeof(bool), true, m_rows * sizeof(bool)); + securec_check(rc,"\0","\0"); + Assert (IsValid()); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vectsstorescan.h postgresql-hll-2.14/include/vecexecutor/vectsstorescan.h --- postgresql-hll-2.14_old/include/vecexecutor/vectsstorescan.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vectsstorescan.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,45 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vectsstorescan.h + * tsstore scan + * + * IDENTIFICATION + * src/include/vecexecutor/vectsstorescan.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECNODETSSTORESCAN_H +#define VECNODETSSTORESCAN_H + +#include "utils/relcache.h" + +struct TsStoreScan; +struct EState; +struct TsStoreScanState; +struct VectorBatch; + +extern TsStoreScanState* ExecInitTsStoreScan(TsStoreScan* node, Relation parentHeapRel, EState* estate, int eflags, + bool indexFlag = false, bool codegenInUplevel = false); +extern VectorBatch* ExecTsStoreScan(TsStoreScanState* node); +extern void ExecEndTsStoreScan(TsStoreScanState* node, bool indexFlag); +extern void ExecReScanTsStoreScan(TsStoreScanState* node); +extern VectorBatch* ts_apply_projection_and_filter(TsStoreScanState* node, + VectorBatch* pScanBatch, + ExprDoneCond* isDone); +void reset_sys_vector(const List* sys_attr_list, VectorBatch* vector); + +#endif /* VECNODETSSTORESCAN_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecunique.h postgresql-hll-2.14/include/vecexecutor/vecunique.h --- postgresql-hll-2.14_old/include/vecexecutor/vecunique.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecunique.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,35 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecunique.h + * Prototypes for vectorized unique + * + * IDENTIFICATION + * src/include/vecexecutor/vecunique.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECUNIQUE_H +#define VECUNIQUE_H + +#include "vecexecutor/vecnodes.h" + +extern VecUniqueState* ExecInitVecUnique(VecUnique* node, EState* estate, int eflags); +extern VectorBatch* ExecVecUnique(VecUniqueState* node); +extern void ExecEndVecUnique(VecUniqueState* node); +extern void ExecReScanVecUnique(VecUniqueState* node); + +#endif /* VECUNIQUE_H */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecvar.h postgresql-hll-2.14/include/vecexecutor/vecvar.h --- postgresql-hll-2.14_old/include/vecexecutor/vecvar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecvar.h 2020-12-12 17:06:43.412350167 +0800 @@ -0,0 +1,87 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecvar.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecvar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef VECVAR_H_ +#define VECVAR_H_ + +#include "vecexecutor/vectorbatch.h" +#include "utils/relcache.h" + +#define GETSLOTID(val) (((val)&0x3FFFFFFFFFFFFFFFULL) >> 48) +#define GETCODE(val) ((val)&0x0000FFFFFFFFFFFFULL) +#define STORAGEVAR_SIZE_STEP 10 + +class StorageVar : public BaseObject { +public: + // constructor deconstructor + // + StorageVar(); + + ~StorageVar(); + + // set the Attr + // + void SetAttr(Relation rel, int colId); + + // decode the data. + // + Datum Decode(Size code); + +private: + // related colid and relation. + int m_colId; + + Relation m_rel; +}; + +class StorageVarManager { +public: + StorageVarManager(); + + ~StorageVarManager(); + + // add a variable storage var container. + StorageVar* AddStorageVar(); + + // get the storage variable length. + StorageVar* GetStorageVar(int16 vindex); + + // Decode a value. + Datum Decode(ScalarValue val); + +private: + StorageVar** m_varData; + + // storage var manager size. + int m_size; + + // current storage var index. + int m_index; + + // manager related context. + // + MemoryContext m_context; +}; + +#endif /* VECVAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/vecexecutor/vecwindowagg.h postgresql-hll-2.14/include/vecexecutor/vecwindowagg.h --- postgresql-hll-2.14_old/include/vecexecutor/vecwindowagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vecexecutor/vecwindowagg.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,376 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vecwindowagg.h + * + * + * IDENTIFICATION + * src/include/vecexecutor/vecwindowagg.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef NODEVECWINDOWAGG_H +#define NODEVECWINDOWAGG_H + +#include "vecexecutor/vecnodes.h" +#include "vecexecutor/vecagg.h" +#include "windowapi.h" + +extern VecWindowAggState* ExecInitVecWindowAgg(VecWindowAgg* node, EState* estate, int eflags); +extern const VectorBatch* ExecVecWindowAgg(VecWindowAggState* node); +extern void ExecEndVecWindowAgg(VecWindowAggState* node); +extern void ExecReScanVecWindowAgg(VecWindowAggState* node); +#define VA_FETCHBATCH 0 +#define VA_EVALFUNCTION 1 +#define VA_END 2 + +#define WINDOW_RANK 0 +#define WINDOW_ROWNUMBER 1 + +/* Save current probing place for next probe */ +typedef struct WindowStoreLog { + int lastFetchIdx; /* frame idx */ + int lastFrameRows; /* rows idx in a frame */ + bool restore; + void set(bool flag, int new_idx, int new_rows); +} WindowStoreLog; + +/* window aggregation info */ +typedef struct WindowAggIdxInfo { + int aggIdx; /* the idx of agg */ + bool is_final; /* if has final function */ +} WindowAggIdxInfo; + +class VecWinAggRuntime : public BaseAggRunner { +public: + // constructor/ + VecWinAggRuntime(VecWindowAggState* runtime); + ~VecWinAggRuntime(){}; + + // return the result batch. + const VectorBatch* getBatch(); + + /* virtual function in BaseAggRunner */ + void Build() + {} + + VectorBatch* Probe() + { + return NULL; + } + + bool ResetNecessary(VecAggState* node) + { + return true; + } + + VectorBatch* Run() + { + return NULL; + } + + void BindingFp() + {} + + /* return agg number */ + int get_aggNum() + { + return m_aggNum; + } + + bool MatchPeerByOrder(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2); + + bool MatchPeerByPartition(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2); + + void MatchSequenceByOrder(VectorBatch* batch, int start, int end); + + void MatchSequenceByPartition(VectorBatch* batch, int start, int end); + void ReplaceEqfunc(); + void ResetNecessary(); + +private: + void FetchBatch(); + + template + const VectorBatch* EvalWindow(); + VectorBatch* EvalAllBatch(); + const VectorBatch* EvalPerBatch(); + void DispatchAssembleFunc(); + + void InitAggIdxInfo(VecAggInfo* aggInfo); + + void EvalWindowFunction(WindowStatePerFunc perfuncstate, int idx); + + void DispatchWindowFunction(WindowStatePerFunc perfuncstate, int i); + void DispatchAggFunction(WindowStatePerAgg peraggState, WindowStatePerFunc perfuncstate, VecAggInfo* aggInfo); + void EvalWindowAggNopartition(VectorBatch* batch); + bool CheckAggEncoded(Oid type_id); + +public: + // executor state + VecWindowAggState* m_winruntime; + + VectorBatch* m_currentBatch; + + VectorBatch* m_outBatch; + + /* to store last batch value */ + VectorBatch* m_lastBatch; + + /* store batch value */ + BatchStore* m_batchstorestate; + + // runtime status + int m_status; + + // down side has pop all data? + bool m_noInput; + + FunctionCallInfoData* m_windowFunc; + + int m_winFuns; + + // is the key column simple + bool m_simplePartKey; + + int m_partitionkey; // partition by + + int* m_partitionkeyIdx; + + ScalarDesc* m_pkeyDesc; + + bool m_simpleSortKey; + + int m_sortKey; // sort by + + int* m_sortKeyIdx; + + ScalarDesc* m_skeyDesc; + + uint8 m_winSequence[BatchMaxSize]; + /* array for order equal result */ + uint8 m_winSequence_dup[BatchMaxSize]; + FmgrInfo* m_parteqfunctions; + FmgrInfo* m_ordeqfunctions; + + /* the number of frames */ + int m_windowIdx; + + /* array for window func index */ + int* m_funcIdx; + + /* we need one more BatchMaxSize space for last batch */ + hashCell* m_windowGrp[BatchMaxSize + 1]; + + /* the numbers in each frame */ + int m_framrows[BatchMaxSize + 1]; + + int m_result_rows; /* the rows for agg */ + + /* the store state for each function to probe data */ + WindowStoreLog* m_window_store; + + ScalarVector* m_vector; /* the vector for expression */ + + /* the same window with last batch for no agg case */ + bool m_same_frame; + + bool* m_cellvar_encoded; /* trans-value is encoded */ + VarBuf* m_windowCurrentBuf; /* window agg buffer */ + WindowAggIdxInfo* m_windowagg_idxinfo; /* window agg info */ + +private: + template + bool AssembleAggWindow(VectorBatch* batch); + + template + bool MatchPeer(VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + template + void MatchSequence(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + template + void buildWindowAgg(VectorBatch* batch); + + template + void buildWindowNoAgg(VectorBatch* batch); + + bool (VecWinAggRuntime::*m_assembeFun)(VectorBatch* batch); + + const VectorBatch* (VecWinAggRuntime::*m_EvalFunc)(); + + void (VecWinAggRuntime::*m_buildScanBatch)(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + + bool (VecWinAggRuntime::*m_MatchPeerOrd)( + VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + bool (VecWinAggRuntime::*m_MatchPeerPart)( + VectorBatch* batch1, int idx1, VectorBatch* batch2, int idx2, int nkeys, const int* keyIdx); + + void (VecWinAggRuntime::*m_MatchSeqOrd)(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + + void (VecWinAggRuntime::*m_MatchSeqPart)(VectorBatch* batch, int start, int end, int nkeys, const int* keyIdx); + template + bool AssemblePerBatch(VectorBatch* batch); + void RefreshLastbatch(VectorBatch* batch); + + template + void initCellValue(hashCell* cell, hashCell* last_cell, int m_frame_rows); + + void BatchAggregation(VectorBatch* batch); + void BuildScanBatchSimple(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + void BuildScanBatchFinal(hashCell* cell, ScalarVector* result_vector, int agg_idx, int final_idx); + + template + void EvalWindowAgg(); + + bool CheckStoreValid(); + + template + void buildWindowAggWithSort(VectorBatch* batch); + + void EvalWindowFuncRank(int whichFn, int idx); + + bool IsFinal(int idx); +}; + +/* + *@Description: set WindowStoreLog + */ +inline void WindowStoreLog::set(bool flag, int new_idx, int new_rows) +{ + lastFetchIdx = new_idx; + lastFrameRows = new_rows; + restore = flag; +} + +extern ScalarVector* vwindow_row_number(PG_FUNCTION_ARGS); +extern ScalarVector* vwindow_rank(PG_FUNCTION_ARGS); +extern ScalarVector* vwindow_denserank(PG_FUNCTION_ARGS); + +template +extern ScalarVector* vwindowfunc_withsort(PG_FUNCTION_ARGS); + +/* + * @Description: Evaluate window_rank and winow_rownumber with sort + * @template which_func - which func, window_rank is 0 and window_number is 1 + */ +template +ScalarVector* vwindowfunc_withsort(PG_FUNCTION_ARGS) +{ + WindowObject winobj = PG_WINDOW_OBJECT(); + int whichFn = PG_GETARG_INT32(0); + VecWindowAggState* state; + VecWinAggRuntime* winRuntime; + ScalarVector* pResCol; + VectorBatch* curWinBatch; + VectorBatch* preWinBatch; + + int j; + int batch_rows = 0; + int start_idx = 0; + int start_rows = 0; /* the position for frame start */ + int idx = 0; /* vector index */ + int frame_number = 0; + int fun_idx; + + state = (VecWindowAggState*)winobj->winstate; + winRuntime = (VecWinAggRuntime*)state->VecWinAggRuntime; + + /* the number of window frame */ + frame_number = winRuntime->m_windowIdx; + preWinBatch = winRuntime->m_lastBatch; + curWinBatch = winRuntime->m_currentBatch; + + /* which func, rank or row_number */ + fun_idx = winRuntime->m_funcIdx[whichFn]; + + /* result vector */ + pResCol = state->perfunc[whichFn].wfuncstate->m_resultVector; + pResCol->m_rows = 0; + batch_rows = winRuntime->m_currentBatch->m_rows; + + /* means that there are remain data in last frame */ + if (winRuntime->m_window_store[whichFn].restore == true) { + start_idx = winRuntime->m_window_store[whichFn].lastFetchIdx; + start_rows = winRuntime->m_window_store[whichFn].lastFrameRows; + winRuntime->m_window_store[whichFn].set(false, 0, 0); + } + + /* the last frame and there is no data in outer plan */ + if (winRuntime->m_noInput == true) { + /* rows of current frame */ + int rows = winRuntime->m_framrows[frame_number]; + bool first = true; + + for (int m = start_rows; m < rows; m++) { + if (first || which_func == WINDOW_RANK) { + pResCol->m_vals[idx] = winRuntime->m_windowGrp[frame_number]->m_val[fun_idx].val; + first = false; + } else + pResCol->m_vals[idx] = pResCol->m_vals[idx - 1] + 1; + + pResCol->m_rows++; + idx++; + + if (idx == curWinBatch->m_rows && m < rows - 1) { + winRuntime->m_window_store[whichFn].set(true, frame_number, m + 1); + break; + } + } + } else { + for (j = start_idx; j < frame_number; j++) { + /* rows of current frame */ + int n_rows = winRuntime->m_framrows[j]; + int m = 0; + /* the number of rows to be fetched from current frame */ + int frame_calcu_rows = rtl::min(batch_rows - idx, n_rows - start_rows); + for (m = start_rows; m < frame_calcu_rows + start_rows; m++) { + pResCol->m_vals[idx] = ((m == start_rows) || (which_func == WINDOW_RANK)) ? + winRuntime->m_windowGrp[j]->m_val[fun_idx].val : (pResCol->m_vals[idx - 1] + 1); + + pResCol->m_rows++; + idx++; + } + + /* current batch is full */ + if (idx == batch_rows) { + if (which_func == WINDOW_RANK) + state->currentpos = n_rows; + if (m < n_rows) /* current frame is not end */ + { + winRuntime->m_window_store[whichFn].set(true, j, m); + } else { + if (j < frame_number - 1) /* still has frame to be fetch */ + { + winRuntime->m_window_store[whichFn].set(true, j + 1, 0); + } else { + winRuntime->m_window_store[whichFn].set(false, 0, 0); + } + } + break; + } + /* for a new frame, set start_rows to be 0 */ + start_rows = 0; + } + } + + Assert(pResCol->m_rows <= BatchMaxSize); + Assert(pResCol->m_rows == batch_rows); + + return NULL; +} + +#endif /* NODEVECAPPEND_H */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicarray.h postgresql-hll-2.14/include/vectorsonic/vsonicarray.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicarray.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicarray.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,257 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicarray.h + * Routines to handle Sonic datum array. + * SonicDatumArray is the base class to store data and flag. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicarray.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +struct atom { + char* data; + char* nullFlag; +}; + +struct DatumDesc { + Oid typeId; + int typeMod; + int typeSize; + int dataType; + + DatumDesc() + { + typeId = InvalidOid; + typeMod = -1; + typeSize = 0; + dataType = 0; + }; +}; + +#pragma pack(1) +struct n1pack { + uint8 scale; + uint8 val; +}; + +struct n2pack { + uint8 scale; + uint16 val; +}; + +struct n4pack { + uint8 scale; + uint32 val; +}; + +struct n8pack { + uint8 scale; + uint64 val; +}; + +#pragma pack() + +struct ArrayIdx { + int arrIdx; + int16 atomIdx; +}; + +#define INIT_ARR_CONTAINER_SIZE 16 +#define MAX_DIC_ENCODE_ITEMS 256 +#define INIT_DATUM_ARRAY_SIZE (16 * 1024) + +#define SONIC_INT_TYPE 0 +#define SONIC_FIXLEN_TYPE 1 +#define SONIC_CHAR_DIC_TYPE 2 +#define SONIC_VAR_TYPE 3 +#define SONIC_NUMERIC_COMPRESS_TYPE 4 +#define SONIC_TOTAL_TYPES 5 + +#define getArrayIndx(nth, nbit) (nth >> (nbit)) +#define getArrayLoc(nth, mask) (nth & (unsigned int)(mask)) + +class SonicDatumArray : public BaseObject { +public: + SonicDatumArray(MemoryContext cxt, int capacity); + + virtual ~SonicDatumArray() + {} + + /* descr area, static information */ + MemoryContext m_cxt; /* context */ + DatumDesc m_desc; /* datum descrption */ + bool m_nullFlag; /* Whether atom has null flag array */ + int m_arrSize; /* The number of allocated atoms. Init value is INIT_ARR_CONTAINER_SIZE 16 */ + const uint32 m_atomSize; /* The size of one atom. Def value is INIT_DATUM_ARRAY_SIZE 16k */ + int m_atomTypeSize; /* Element type size in atom. */ + const uint32 m_nbit; /* log2(m_atomSize) */ + + /*data area*/ + atom** m_arr; /* Record atoms address.. Each element points to one atom. */ + atom* m_curAtom; /* Current atom */ + + /*index area*/ + int m_arrIdx; /* m_arrIdx + 1 == the number of used atoms. Init value -1 */ + int m_atomIdx; /* Current position in atom */ + + char* m_curData; /* record the current data in atom */ + uint8* m_curFlag; /* record the current flag in atom */ + +public: + virtual void genNewArray(bool genBitMap); + + /* put function. */ + void putArray(ScalarValue* vals, uint8* flag, int rows); + + void loadArrayByRow(void* file); + + void loadArray(void* file, int64 rows); + + /* get function */ + int64 getRows(); + + FORCE_INLINE + uint8 getNthNullFlag(int arrIdx, int atomIdx) + { + return m_arr[arrIdx]->nullFlag[atomIdx]; + } + + void getNthDatumFlag(uint32 nth, ScalarValue* val, uint8* toflag); + + Datum getNthDatum(uint32 nth); + + void getArrayAtomIdx(int nrows, uint32* locs, ArrayIdx* arrayIdx); + + /* set function. */ + ScalarValue replaceVariable(ScalarValue oldVal, ScalarValue val); + + FORCE_INLINE + void setNthNullFlag(uint32 nth, bool isNull) + { + int arrIdx; + int atomIdx; + arrIdx = getArrayIndx(nth, m_nbit); + atomIdx = getArrayLoc(nth, m_atomSize - 1); + m_arr[arrIdx]->nullFlag[atomIdx] = isNull; + } + + FORCE_INLINE + void setNthNullFlag(int arrIdx, int atomIdx, bool isNull) + { + m_arr[arrIdx]->nullFlag[atomIdx] = isNull; + } + + virtual void setNthDatum(uint32 nth, ScalarValue* val) + { + Assert(false); + } + + virtual void setValue(ScalarValue val, bool isNull, int arrIndx, int atomIndx) + { + Assert(false); + } + + virtual void getDatumArray(int nrows, int* arrayIdx, int* atomIdx, Datum* data) + { + Assert(false); + } + + virtual void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag) + { + Assert(false); + } + + virtual void getDatumFlagArrayWithMatch( + int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx) + { + Assert(false); + } + + virtual size_t flushDatumFlagArrayByRow( + int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows) + { + return 0; + } + + virtual size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows) + { + return 0; + } + + virtual void loadIntValArray(void* file, int nrows) + { + Assert(false); + } + + virtual void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows) + { + Assert(false); + } + + virtual void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* toflag) + { + Assert(false); + } + +private: + void putNullFlagArray(uint8* flag, int rows); + + virtual void loadDatumFlagArray(void* file, int rows) + { + Assert(false); + } + + virtual void loadDatumFlagArrayByRow(void* file, int leftrows) + { + Assert(false); + } + + virtual Datum getDatum(int arrIdx, int atomIdx) + { + Assert(false); + return 0; + } +}; + +extern int getDataMinLen(Oid typeOid, int typeMod); +extern void getDataDesc(DatumDesc* desc, int typeSize, Form_pg_attribute attr, bool isHashKey); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICARRAY_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicchar.h postgresql-hll-2.14/include/vectorsonic/vsonicchar.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicchar.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,106 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicchar.h + * Routines to handle Character data type like char, bpchar. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicchar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICCHAR_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICCHAR_H_ + +#include "vectorsonic/vsonicarray.h" + +class SonicCharDatumArray : public SonicDatumArray { +public: + SonicCharDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicCharDatumArray(){}; + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + void loadDatumFlagArray(void* file, int rows); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + Datum getDatum(int arrIdx, int atomIdx); + + void initCharDatumArray(); + +private: + void initDict(); + + void initResultBuf(); + + void initFunc(); + + void putDicDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void putCharDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getCharDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getDicDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getCharDatum(int arrIdx, int atomIdx); + + Datum getDicDatum(int arrIdx, int atomIdx); + + void rebuildFromDict(); + + typedef void (SonicCharDatumArray::*putFunc)(ScalarValue* vals, uint8* flag, int rows); + + typedef void (SonicCharDatumArray::*putDatumFunc)(ScalarValue* vals, uint8* flag); + + typedef void (SonicCharDatumArray::*getDatumFlagFunc)(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + typedef Datum (SonicCharDatumArray::*getDatumFunc)(int arrIdx, int atomIdx); + + /* put and get functions */ + putFunc m_putFunc; + getDatumFunc m_getDatumFunc[2]; + getDatumFlagFunc m_getDatumFlagFunc[2]; + + /* store dict */ + void* m_dict; + + /* tag dict and char data, + * for atom whose arrIdx < m_dictArrLen + * stores dict data, otherwise stores char + */ + int m_dictArrLen; + + /* buffer to store results */ + char* m_resultBuf; + + /* temp varible to get buffer data */ + int m_resultBufIndx; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicencodingchar.h postgresql-hll-2.14/include/vectorsonic/vsonicencodingchar.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicencodingchar.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicencodingchar.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicencodingchar.h + * Routines to handle variable length data type. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicencodingchar.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ + +#include "vectorsonic/vsonicarray.h" + +class SonicEncodingDatumArray : public SonicDatumArray { +public: + SonicEncodingDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicEncodingDatumArray(){}; + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void setValue(ScalarValue val, bool isNull, int arrIndx, int atomIndx); + + Datum getDatum(int arrIdx, int atomIdx); + +private: + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void loadDatumFlagArray(void* file, int rows); +}; + +class SonicStackEncodingDatumArray : public SonicEncodingDatumArray { +public: + SonicStackEncodingDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicStackEncodingDatumArray(){}; + +private: + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void putDatumFlag(ScalarValue* vals, uint8* flag); + + void loadDatumFlagArray(void* fileSource, int rows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + VarBuf* m_buf; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICENCODINGCHAR_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicfilesource.h postgresql-hll-2.14/include/vectorsonic/vsonicfilesource.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicfilesource.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicfilesource.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,385 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicfilesource.h + * sonic file source class and class member declare + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicfilesource.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "vectorsonic/vsonicarray.h" + +#define CheckReadIsValid(nread, toread) \ + if ((nread) != (toread)) { \ + ereport(ERROR, (errcode_for_file_access(), errmsg("could not read from sonic hash-join temporary file: %m"))); \ + } + +/* file info for every file type */ +typedef struct FileInfo { + /* record the original position in targetlist. */ + uint32 partColIdx; + + /* typeSize of current column in file */ + int typeSize; + + /* record the varheadlen of difference column in same file */ + uint8 varheadlen; +} FileInfo; + +class SonicHashFileSource : public BaseObject { +public: + SonicHashFileSource(MemoryContext context); + + SonicHashFileSource(MemoryContext context, DatumDesc* desc); + + virtual ~SonicHashFileSource() + {} + + /* memory context */ + MemoryContext m_context; + + /* data description */ + DatumDesc m_desc; + + /* pointer of temp file */ + void* m_file; + + /* columns include */ + uint32 m_cols; + + /* total column width */ + size_t m_colWidth; + + /* colIdx in current file */ + uint32 m_nextColIdx; + + /* fileinfo include colIdx in targetlist and typeSize of current colIdx */ + FileInfo* m_fileInfo; + + /* + * record the size of varible data which will not contained within the Atom's allocated space + * when loading into memory, such as SONIC_NUMERIC_COMPRESS_TYPE and SONIC_VAR_TYPE, + * whose data may stored in buffers (eg. VarBuf) other than Atom. + * The Atom only holds the pointers of the data. + */ + size_t* m_varSize; + + /* write and read functions to and from temp file*/ + size_t (SonicHashFileSource::*m_writeScalarValue)(ScalarValue* val, uint8 flag); + + size_t (SonicHashFileSource::*m_readScalarValue)(ScalarValue* val, uint8* flag); + + size_t (SonicHashFileSource::*m_readTempFile)(void* file, void* data, size_t size); + + size_t (SonicHashFileSource::*m_writeTempFile)(void* file, void* data, size_t size); + + /* rewind function */ + void (SonicHashFileSource::*m_rewind)(); + + /* close function */ + void (SonicHashFileSource::*m_close)(); + + void prepareFileHandlerBuffer(); + + void releaseFileHandlerBuffer(); + + size_t write(void* data, size_t size); + + size_t read(void* data, size_t size); + +public: + virtual void setBuffer() + { + return; + } + + /* get typeSize in current column */ + size_t getTypeSize(int colIdx) + { + return (size_t)m_fileInfo[colIdx].typeSize; + } + + /* m_cols means max column number in filesource */ + uint32 getMaxCols() + { + return m_cols; + } + + size_t getColWidth() + { + return m_colWidth; + } + size_t writeVal(char* val, uint8 flag = V_NOTNULL_MASK); + + size_t writeVal(ScalarValue* val, uint8 flag); + + size_t readVal(char* val, uint8* flag = NULL); + + size_t readVal(ScalarValue* val, uint8* flag); + + void rewind(); + + void close(); + +private: + virtual size_t writeScalar(ScalarValue* val, uint8 flag) + { + return 0; + } + + virtual size_t readScalar(ScalarValue* val, uint8* flag) + { + return 0; + } + + virtual size_t writeScalarOpt(ScalarValue* val, uint8 flag) + { + return 0; + } + + virtual size_t readScalarOpt(ScalarValue* val, uint8* flag) + { + return 0; + } + + virtual void init(DatumDesc* desc, uint16 fileIdx) + { + Assert(false); + } + + size_t writeCompress(void* file, void* data, size_t size); + + size_t writeNoCompress(void* file, void* data, size_t size); + + size_t readCompress(void* file, void* data, size_t size); + + size_t readNoCompress(void* file, void* data, size_t size); + + void rewindCompress(); + + void rewindNoCompress(); + + void closeCompress(); + + void closeNoCompress(); +}; + +class SonicHashIntFileSource : public SonicHashFileSource { + +private: + /* write function according to the integer bytes */ + size_t (SonicHashIntFileSource::*m_writeIntScalarValue)(ScalarValue* val, uint8 flag); + + /* read function according to the integer bytes */ + size_t (SonicHashIntFileSource::*m_readIntScalarValue)(ScalarValue* val, uint8* flag); + + /* write function according to the integer bytes */ + typedef size_t (SonicHashIntFileSource::*pWriteIntScalarValue)(ScalarValue* val, uint8 flag); + + /* read function according to the integer bytes */ + typedef size_t (SonicHashIntFileSource::*pReadIntScalarValue)(ScalarValue* val, uint8* flag); + + pWriteIntScalarValue* m_writeIntScalarValueFuncs; + + pReadIntScalarValue* m_readIntScalarValueFuncs; + +public: + SonicHashIntFileSource(MemoryContext context, DatumDesc* desc, bool hasFlag = true); + + ~SonicHashIntFileSource(){}; + + SonicHashIntFileSource(MemoryContext context, uint32 maxCols, bool hasFlag = true); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t write1ByteScalar(ScalarValue* val, uint8 flag); + + size_t write1ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write2ByteScalar(ScalarValue* val, uint8 flag); + + size_t write2ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write4ByteScalar(ScalarValue* val, uint8 flag); + + size_t write4ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t write8ByteScalar(ScalarValue* val, uint8 flag); + + size_t write8ByteScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + + size_t read1ByteScalar(ScalarValue* val, uint8* flag); + + size_t read1ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read2ByteScalar(ScalarValue* val, uint8* flag); + + size_t read2ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read4ByteScalar(ScalarValue* val, uint8* flag); + + size_t read4ByteScalarOpt(ScalarValue* val, uint8* flag); + + size_t read8ByteScalar(ScalarValue* val, uint8* flag); + + size_t read8ByteScalarOpt(ScalarValue* val, uint8* flag); + + /* init typeSize and m_cols in SONIC_INT_TYPE file */ + void init(DatumDesc* desc, uint16 fileIdx); + +private: + size_t readValue(char* val, uint8* flag); +}; + +class SonicHashNumericFileSource : public SonicHashFileSource { +public: + SonicHashNumericFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashNumericFileSource(MemoryContext context, uint32 maxCols); + + ~SonicHashNumericFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + /* temp buffer to store one numeric */ + char* m_packBuf; + + /* buffer to store 128 numeric data */ + VarBuf* m_buf; +}; + +class SonicHashEncodingFileSource : public SonicHashFileSource { +public: + SonicHashEncodingFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashEncodingFileSource(MemoryContext context, uint32 maxCols); + + ~SonicHashEncodingFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + /* buffer to store real data */ + VarBuf* m_buf; +}; + +class SonicHashCharFileSource : public SonicHashFileSource { + +private: + /* temp pointer to buffer */ + char* m_buf; + + /* buffer to store a batch */ + char* m_batchBuf; + + /* actual header size */ + uint8 m_varheadlen; + +public: + SonicHashCharFileSource(MemoryContext context, DatumDesc* desc); + + SonicHashCharFileSource(MemoryContext context, int typeSize, uint32 maxCols); + + ~SonicHashCharFileSource(){}; + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + void initBatchBuf(); +}; + +class SonicHashFixLenFileSource : public SonicHashFileSource { + +private: + /* actual header size */ + uint8 m_varheadlen; + + /* buffer to store a batch */ + char* m_batchBuf; + + /* temp pointer to buffer */ + char* m_buf; + + char* m_tmpvalue; + +public: + SonicHashFixLenFileSource(MemoryContext context, DatumDesc* desc); + + ~SonicHashFixLenFileSource(){}; + + SonicHashFixLenFileSource(MemoryContext context, uint32 maxCols); + + void init(DatumDesc* desc, uint16 fileIdx); + + void setBuffer(); + + size_t writeScalar(ScalarValue* val, uint8 flag); + + size_t writeScalarOpt(ScalarValue* val, uint8 flag); + + size_t readScalar(ScalarValue* val, uint8* flag); + + size_t readScalarOpt(ScalarValue* val, uint8* flag); + +private: + void initBatchBuf(); +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICFILESOURCE_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicfixlen.h postgresql-hll-2.14/include/vectorsonic/vsonicfixlen.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicfixlen.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicfixlen.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,67 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicfixlen.h + * Routines to handle data type that attribute has fixed length. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicfixlen.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ + +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicchar.h" + +class SonicFixLenDatumArray : public SonicDatumArray { +public: + SonicFixLenDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicFixLenDatumArray(){}; + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArray(void* fileSource, int rows); + + void loadDatumFlagArrayByRow(void* fileSource, int leftrows); + +private: + void initResultBuf(); + + /* buffer to assemble results */ + char* m_resultBuf; + + /* index in the buffer */ + int m_resultBufIndx; + + /* header size*/ + int m_varheadlen; +}; +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICFIXLEN_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonichashagg.h postgresql-hll-2.14/include/vectorsonic/vsonichashagg.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonichashagg.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonichashagg.h 2020-12-12 17:06:43.413350180 +0800 @@ -0,0 +1,284 @@ +/* + * 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(){}; + + /* Main sonic HashAgg function */ + VectorBatch* Run(); + + /* Main process to build hash table */ + void Build(); + + /* Main process to produce result */ + VectorBatch* Probe(); + + /* Get the hash source */ + SonicHashSource* GetHashSource(); + + /* Reset current status */ + bool ResetNecessary(VecAggState* node); + + /* Show number of partition files */ + 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. + */ + /* match function. */ + template + bool matchValue(ScalarVector* pVector, uint16 keyIdx, int16 pVectorIdx, uint32 cmpIdx); + + template + void matchArray(ScalarVector* pVector, uint16 keyIdx, uint16 cmpRows); + + /* build sonic hash table function */ + template + void buildAggTblBatch(VectorBatch* batch); + + int64 insertHashTbl(VectorBatch* batch, int idx, uint32 hashval, uint32 hashLoc); + + void calcHashContextSize(MemoryContext ctx, int64* memorySize, int64* freeSize); + + /* judge current used memory context */ + void judgeMemoryOverflow(char* opname, int planId, int dop, Instrumentation* instrument, int64 size_needed); + + bool judgeMemoryAllowExpand(); + + /* calculate hash table size */ + template + int64 calcHashTableSize(int64 oldSize); + + /* Following function are used for alloc new hash table or expand it. */ + void AllocHashTbl(VectorBatch* batch, int idx, uint32 hashval, int hashLoc); + + void tryExpandHashTable(); + + void expandHashTable(); + + /* following functions are about partiton function */ + 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: + /* runtime state */ + VecAggState* m_runtime; + + /* runtime stage (source, build, probe) */ + int m_runState; + + /* memory or disk. */ + int m_strategy; + + /* record avg width of encoded columns in memory */ + int64 m_tupleCount; + int64 m_colWidth; + int m_arrayElementSize; + + /* record memory need for each expand */ + int64 m_arrayExpandSize; + + /* row numbers in memory of first spill */ + int m_fill_table_rows; + + /* expression-evaluation context */ + ExprContext* m_econtext; + + /* Sonic hash source */ + SonicHashSource* m_sonicHashSource; + + /* partitions for hash source(file source) */ + SonicHashPartition** m_partFileSource; + + /* partitions for respill hash source */ + SonicHashPartition** m_overflowFileSource; + + /* number of partitions */ + uint16 m_partNum; + + /* number of overflow partitions */ + uint16 m_overflowNum; + + /* current partition index */ + 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. + */ + + /* the actual structure for the table is bucket, hash, next, hash_needed cols, agg cols + * number of columns needed in hash table + */ + uint16 m_hashNeed; + uint16* m_hashInBatchIdx; + uint16* m_keyIdxInSonic; + + /* the information to describe the aggregation */ + /* number of aggregation function */ + uint16 m_aggNum; + + /* number of aggregation function need to transform */ + uint16 m_finalAggNum; + + /* check if current agg function is count(*)/count(any) or not. */ + bool* m_aggCount; + + /* agg index in the tupe, as some agg function may split into two function */ + uint16* m_aggIdx; + + /* whether the key is simple or not */ + bool m_keySimple; + + /* the index which need to do some final calculation */ + finalAggInfo* m_finalAggInfo; + + /* equal function used to match values. */ + FmgrInfo* m_equalFuncs; + + /* batch infomation used during aggregation */ + /* batch for scaning the hash table */ + VectorBatch* m_scanBatch; + + /* projection batch. */ + VectorBatch* m_proBatch; + + /* same structure as outer node return batch */ + VectorBatch* m_outBatch; + + /* batch used to store data from file */ + VectorBatch* m_sourceBatch; + + /* flag used to mark */ + bool m_useSegHashTbl; + + /* number of segment hash table */ + int m_segNum; + + /* segment index hash table */ + SonicDatumArray* m_segBucket; + + /* where we put the next data */ + SonicDatumArray* m_next; + + /* mark weather hash table can grow up */ + bool m_enableExpansion; + + /* build function pointer */ + void (SonicHashAgg::*m_buildFun)(VectorBatch* batch); + + /* hash build time */ + double m_hashbuild_time; + + /* hash agg-calc time */ + double m_calcagg_time; + + /* match function array. */ + pKeyMatchArrayFunc* m_arrayKeyMatch; + pKeyMatchValueFunc* m_valueKeyMatch; + + /* record the miss match idx. */ + uint16 m_missIdx[BatchMaxSize]; + uint16 m_missNum; + + /* record the suspect idx which need to be match. */ + uint16 m_suspectIdx[BatchMaxSize]; + uint16 m_suspectNum; + + /* record the bucket location. */ + uint32 m_bucketLoc[BatchMaxSize]; + + /* handle duplicate, record the orginial the location. */ + uint32 m_orgLoc[BatchMaxSize]; +}; +#endif diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonichash.h postgresql-hll-2.14/include/vectorsonic/vsonichash.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonichash.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonichash.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,317 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonichash.h + * Routines to handle vector sonic hash nodes. + * SonicHash is base class of SonicHashJoin and SonicHashAgg. + * This file also contains many hash functions. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonichash.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ + +#include "vecexecutor/vectorbatch.h" +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicnumeric.h" +#include "vectorsonic/vsonicint.h" +#include "vectorsonic/vsonicchar.h" +#include "vectorsonic/vsonicencodingchar.h" +#include "vectorsonic/vsonicfixlen.h" + +#define PROBE_FETCH 0 +#define PROBE_PARTITION_FILE 1 +#define PROBE_DATA 2 +#define PROBE_FINAL 3 +#define PROBE_PREPARE_PAIR 4 +#define PROBE_PARTITION_MEM 5 + +#define USE_PRIME + +#ifdef USE_PRIME +/* + * The prime calculated via hashfindrprime() with rows + * larger than SONIC_MAX_ROWS will be larger than UINT_MAX. + */ +#define SONIC_MAX_ROWS 4080218831 +#else +#define SONIC_MAX_ROWS 4294950910 +#endif + +typedef enum { CALC_BASE = 0, CALC_SPILL, CALC_HASHTABLE } CalcBatchHashType; + +struct hashStateLog { + int lastProcessIdx; + bool restore; +}; + +struct SonicHashMemoryControl { + + bool sysBusy; + /* record spill info */ + bool spillToDisk; /* true when next batch should put into disk */ + int spillNum; + /* record memory auto spread info */ + uint64 maxMem; + int spreadNum; + /* record context memory info */ + uint64 totalMem; + uint64 availMem; + uint64 allocatedMem; + MemoryContext hashContext; + MemoryContext tmpContext; + + SonicHashMemoryControl() + { + sysBusy = false; + spillToDisk = false; + spillNum = 0; + maxMem = 0; + spreadNum = 0; + totalMem = 0; + availMem = 0; + allocatedMem = 0; + hashContext = NULL; + tmpContext = NULL; + }; +}; + +class SonicHashSource : public BaseObject { +public: + virtual VectorBatch* getBatch() + { + Assert(false); + return NULL; + } + + virtual ~SonicHashSource() + {} +}; + +class SonicHashOpSource : public SonicHashSource { +public: + SonicHashOpSource(PlanState* op) : m_op(op) + {} + ~SonicHashOpSource(){}; + + VectorBatch* getBatch() + { + return VectorEngine(m_op); + } + +private: + /* data source operator */ + PlanState* m_op; +}; + +class SonicHash : public BaseObject { +public: + SonicHash(int size); + + virtual ~SonicHash() + {} + + void initHashFunc(TupleDesc desc, void* hashFun, uint16* m_keyIndx, bool isAtom = false); + + /* Hash Functions */ + /* Specialized for int8, int16, int32 */ + template + void hashInteger(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + /* Specialized for int64 */ + template + void hashInteger8(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashbpchar(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashtext(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashtext_compatible(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + template + void hashnumeric(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr = NULL); + + /* General hash functions */ + template + void hashGeneralFunc(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr); + + void freeMemoryContext(); + + int64 getRows(); + + bool integerType(Oid typeId); + + bool isHashKey(Oid typeOid, int attidx, uint16* keyIdx, int keyNum); + + void replaceEqFunc(); + + inline void hashBatchArray(VectorBatch* batch, void* hashFun, FmgrInfo* hashFmgr, uint16* keyIndx, uint32* hashRes) + { + int i; + AutoContextSwitch memGuard(m_memControl.tmpContext); + hashValFun* hashfun = (hashValFun*)hashFun; + + for (i = 0; i < m_buildOp.keyNum; i++) + RuntimeBinding(hashfun, i)((char*)batch->m_arr[keyIndx[i]].m_vals, + (uint8*)batch->m_arr[keyIndx[i]].m_flag, + batch->m_rows, + hashRes, + (hashFmgr + i)); + + MemoryContextReset(m_memControl.tmpContext); + } + + inline void hashAtomArray(SonicDatumArray** array, int nrows, int arrIdx, void* hashFun, FmgrInfo* hashFmgr, + uint16* keyIndx, uint32* hashRes) + { + int i; + AutoContextSwitch memGuard(m_memControl.tmpContext); + atom* datum_arr; + hashValFun* hashfun = (hashValFun*)hashFun; + + for (i = 0; i < m_buildOp.keyNum; i++) { + datum_arr = array[keyIndx[i]]->m_arr[arrIdx]; + RuntimeBinding(hashfun, i)( + (char*)datum_arr->data, (uint8*)datum_arr->nullFlag, nrows, hashRes, (hashFmgr + i)); + } + + MemoryContextReset(m_memControl.tmpContext); + } + + template + void matchCheckColT(ScalarVector* val, SonicDatumArray* array, int nrows, int keyNum) + { + bool* boolloc = m_match; + uint16* loc1 = m_selectIndx; + Datum* data = m_matchKeys; + uint8* flag = m_nullFlag; + + bool notnullcheck = false; + bool nullcheck = false; + + array->getArrayAtomIdx(nrows, m_loc, m_arrayIdx); + array->getDatumFlagArrayWithMatch(nrows, m_arrayIdx, m_matchKeys, m_nullFlag, m_match); + + for (int i = 0; i < nrows; i++) { + notnullcheck = BOTH_NOT_NULL(val->m_flag[*loc1], m_nullFlag[i]); + nullcheck = nulleqnull & (uint8)BOTH_NULL((unsigned char)val->m_flag[*loc1], (unsigned char)m_nullFlag[i]); + if (simpleType) + *boolloc = + *boolloc && (nullcheck || (notnullcheck && ((outerType)val->m_vals[*loc1] == (innerType)(*data)))); + else { + FunctionCallInfoData fcinfo; + PGFunction cmpfun = m_eqfunctions[keyNum].fn_addr; + Datum args[2]; + fcinfo.arg = &args[0]; + + fcinfo.arg[0] = val->m_vals[*loc1]; + fcinfo.arg[1] = *data; + fcinfo.flinfo = (m_eqfunctions + keyNum); + *boolloc = *boolloc && (nullcheck || (notnullcheck && (bool)cmpfun(&fcinfo))); + } + + boolloc++; + loc1++; + data++; + flag++; + } + } + +public: + typedef void (SonicHash::*hashValFun)(char* val, uint8* flag, int nval, uint32* res, FmgrInfo* hashFmgr); + + typedef void (SonicHash::*matchFun)(ScalarVector* val, SonicDatumArray* array, int nrows, int keyNum); + + typedef void (SonicHash::*profileFun)(); + + typedef struct SonicHashInputOpAttr { + bool simple; /* without encoding */ + + uint16* keyIndx; + + uint16* oKeyIndx; + + uint16 keyNum; + + hashValFun* hashFunc; + + hashValFun* hashAtomFunc; + + FmgrInfo* hashFmgr; + + VectorBatch* batch; + + uint16 cols; + + TupleDesc tupleDesc; + + SonicHashInputOpAttr() + { + simple = false; + keyIndx = NULL; + oKeyIndx = NULL; + keyNum = 0; + hashFunc = NULL; + hashAtomFunc = NULL; + hashFmgr = NULL; + batch = NULL; + cols = 0; + tupleDesc = NULL; + } + } SonicHashInputOpAttr; + + /* the hash data and the desc */ + SonicDatumArray** m_data; + SonicDatumArray* m_hash; + char* m_bucket; + uint8 m_bucketTypeSize; + + int m_atomSize; /* array size for atom structure */ + int64 m_hashSize; + int64 m_rows; + + /* runtime status and binding function. */ + matchFun* m_matchKey; /* matching functions */ + hashStateLog m_stateLog; + uint8 m_probeStatus; + uint8 m_status; + SonicHashInputOpAttr m_buildOp; + FmgrInfo* m_eqfunctions; /* equal functions */ + + /* memory control.*/ + SonicHashMemoryControl m_memControl; + + /* temporary space for vector processing */ + uint32 m_hashVal[INIT_DATUM_ARRAY_SIZE]; /* temp hash values */ + uint32 m_loc[BatchMaxSize]; /* record position from inner atom */ + uint32 m_partLoc[BatchMaxSize]; /* record partition number */ + uint16 m_selectIndx[BatchMaxSize]; /* record position from outer batch */ + uint16 m_selectRows; /* matched tuple number */ + bool m_match[BatchMaxSize]; + Datum m_matchKeys[BatchMaxSize]; + uint8 m_nullFlag[BatchMaxSize]; + ArrayIdx m_arrayIdx[BatchMaxSize]; /* record matched idx */ +}; + +extern uint64 hashfindprime(uint64 n); +extern uint32 hashquickany(uint32 seed, register const unsigned char* data, register int len); +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHASH_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonichashjoin.h postgresql-hll-2.14/include/vectorsonic/vsonichashjoin.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonichashjoin.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonichashjoin.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,305 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonichashjoin.h + * Routines to handle vector sonic hashjoin nodes. + * Sonic Hash Join nodes are based on the column-based hash table. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonichashjoin.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ + +#include "vectorsonic/vsonichash.h" +#include "vectorsonic/vsonicpartition.h" + +/* + * Max partition number when doing partition or repartition. + * Total partition number can be larger than this value. + */ +#define SONIC_PART_MAX_NUM 1024 + +typedef enum { reportTypeBuild = 1, reportTypeProbe, reportTypeRepartition } ReportType; + +struct BatchPos { + uint32 partIdx; + int rowIdx; +}; + +class SonicHashJoin : public SonicHash { +public: + SonicHashJoin(int size, VecHashJoinState* node); + + ~SonicHashJoin(){}; + + void Build(); + + VectorBatch* Probe(); + + void closeAllFiles(); + + void ResetNecessary(); + + void freeMemoryContext(); + +private: + /* init functions */ + void setHashIndex(uint16* keyIndx, uint16* oKeyIndx, List* hashKeys); + + void initMemoryControl(); + + void initHashTable(uint8 byteSize, uint32 curPartIdx); + + void initHashFmgr(); + + /* binding function pointer. */ + template + void bindingFp(); + + /* build side functions to put data */ + template + void saveToMemory(VectorBatch* batch); + + template + void saveToDisk(VectorBatch* batch); + + template + void flushToDisk(); + + template + void buildHashTable(uint32 curPartIdx); + + uint64 calcHashSize(int64 nrows); + + void prepareProbe(); + + /* output functions */ + VectorBatch* buildRes(VectorBatch* inBatch, VectorBatch* outBatch); + + /* Memory functions */ + bool hasEnoughMem(); + + void judgeMemoryOverflow(uint64 hash_head_size); + + void calcHashContextSize(MemoryContext ctx, uint64* allocateSize, uint64* freeSize); + + void calcDatumArrayExpandSize(); + + /* probe functions */ + VectorBatch* probeMemory(); + + VectorBatch* probeGrace(); + + template + VectorBatch* probeMemoryTable(SonicHashSource* probeP); + + template + VectorBatch* probePartition(SonicHashSource* probeP = NULL); + + /* join functions */ + template + VectorBatch* innerJoin(VectorBatch* batch); + + /* profiling functions */ + void profile(bool writeLog, uint32 partIdx, uint8 bucketTypeSize); + + template + void profileFunc(char* stats, uint32 partIdx); + + /* Match Functions */ + void initMatchFunc(TupleDesc desc, uint16 keyNum); + + void DispatchKeyInnerFunction(int KeyIndx); + + template + void DispatchKeyOuterFunction(int KeyIndx); + + /* complicate join key */ + void CalcComplicateHashVal(VectorBatch* batch, List* hashKeys, bool inner); + + /* Match Functions for complicate join key */ + template + void matchComplicateKey(VectorBatch* batch, SonicHashMemPartition* inPartition = NULL); + + /* partitions functions */ + uint32 calcPartitionNum(); + + void calcPartIdx(uint32* hashVal, uint32 partNum, int nrows); + + void calcRePartIdx(uint32* hashVal, uint32 partNum, uint32 rbit, int nrows); + + bool preparePartition(); + + void initProbePartitions(); + + template + void rePartition(uint32 rePartIdx); + + void recordPartitionInfo(bool buildside, int32 partIdx, uint32 istart, uint32 iend); + + void analyzePartition(bool buildside, uint32 startPartIdx, uint32 endPartIdx, int64* totalFileNum, + long* totalFileSize, long* partSizeMin, long* partSizeMax, int* spillPartNum); + + void reportSorthashinfo(ReportType reportType, uint32 totalPartNum, int32 rePartIdx = -1); + + template + void initPartition(SonicHashPartition* partition); + + void loadInnerPartitions(uint64 memorySize); + + void loadInnerPartition(uint32 partIdx); + + void loadMultiInnerPartition(uint32 partIdx, SonicHashMemPartition* memPartition); + + void quickSort(uint32* elements, const int start, const int end); + + void sortPartitionSize(uint64 memorySize); + + template + void saveProbePartition(); + + /* bloom filter functions */ + void pushDownFilterIfNeed(); + + /* clean functions */ + void finishJoinPartition(uint32 partIdx); + + void closePartFiles(uint32 partIdx); + + void releaseAllFileHandlerBuffer(bool isInner); + + void resetMemoryControl(); + uint64 get_hash_head_size(int64 rows); + +public: + double m_build_time; + double m_probe_time; + +private: + VectorBatch* (SonicHashJoin::*m_probeFun[2])(); + + typedef VectorBatch* (SonicHashJoin::*probeTypeFun)(SonicHashSource* probeP); + + /* save probe partition function */ + void (SonicHashJoin::*m_saveProbePartition)(); + + /* the build function */ + void (SonicHashJoin::*m_funBuild[2])(VectorBatch* batch); + + /* static information */ + probeTypeFun m_probeTypeFun; + + bool m_complicatekey; + + /* describe outer operator */ + SonicHashInputOpAttr m_probeOp; + + /* describe whether hash key is integer. */ + bool* m_integertype; + + /* runtime state */ + VecHashJoinState* m_runtime; + + /* where we put data */ + char* m_next; + + /* join strategy */ + uint8 m_strategy; + + /* runtime attribute */ + VectorBatch* m_outRawBatch; + + /* record matched position. */ + uint32 m_innerMatchLoc[2 * BatchMaxSize]; + uint32 m_innerPartMatchLoc[2 * BatchMaxSize]; + uint16 m_outerMatchLoc[2 * BatchMaxSize]; + uint16 m_matchLocIndx; + + /* rocord partition indexes of data in atom or batch */ + uint32 m_partIdx[INIT_DATUM_ARRAY_SIZE]; + uint32 m_probeIdx; + + /* memory need for each expand */ + size_t m_arrayExpandSize; + + /* partitions for inner source */ + SonicHashPartition** m_innerPartitions; + + /* partitions for outer source */ + SonicHashPartition** m_outerPartitions; + + /* + * Get build side data from lower operator. + * Used for join without spilling. + */ + SonicHashOpSource* m_hashOpPartition; + + /* status for probePartition() */ + uint8 m_probePartStatus; + + /* + * number of partitions. + * inner and outer should have the same number of partitions. + */ + uint32 m_partNum; + + /* partition index ordered by size */ + uint32* m_partSizeOrderedIdx; + + /* the offset in m_partSizeOrderedIdx that have been loaded */ + int32 m_partLoadedOffset; + + /* hash level for repartition */ + uint8* m_pLevel; + + /* maximum partition level need to be paid attention */ + uint8 m_maxPLevel; + + /* partition is from a valid repartition process or not: for repartition process */ + bool* m_isValid; + + /* + * the cjVector is only allocated and + * used when m_complicateJoinKey is true + */ + ScalarVector* m_cjVector; + /* complicate inner batch */ + VectorBatch* m_complicate_innerBatch; + /* complicate outer batch */ + VectorBatch* m_complicate_outerBatch; + + bool m_nulleqmatch[BatchMaxSize]; + + /* + * flag to show whether the build side partition is in memory. + * SONIC_PART_MAX_NUM is enough, because this array is not + * used after probePartition. + */ + bool m_memPartFlag[SONIC_PART_MAX_NUM]; + + /* record file partition info. */ + BatchPos m_diskPartIdx[BatchMaxSize]; + + /* number of data in m_diskPartIdx[] */ + uint32 m_diskPartNum; +}; + +extern bool isSonicHashJoinEnable(HashJoin* hj); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICHASHJOIN_H_ */ \ No newline at end of file diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicint.h postgresql-hll-2.14/include/vectorsonic/vsonicint.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicint.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicint.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,318 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicint.h + * Routines to handle data type whose attribute length is + * 1, 2, 4, 8. + * The length of type can be retrieved from query below: + * select oid, typname from pg_type where typlen = len; + * There is one exception: + * TIDOID's length is 6, and use atomTypeSize 8. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicint.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +#include "vectorsonic/vsonicarray.h" + +template +class SonicIntTemplateDatumArray : public SonicDatumArray { +public: + SonicIntTemplateDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicIntTemplateDatumArray(){}; + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + void getDatumArray(int nrows, int* arrIdx, int* atomIdx, Datum* data); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* file, int leftrows); + + void loadDatumFlagArray(void* file, int rows); + + void loadIntValArray(void* file, int nrows); + + void loadIntVal(void* file, int rows); + + void setNthDatum(uint32 nth, ScalarValue* val); + + void putIntValArray(T* val, int nrows); + + void putIntVal(T* val, int nrows); +}; + +/* + * @Description: constructor. + * @in cxt - memory context. + * @in capacity - atom size. + * @in genBitMap - Whether use null flag. + * @in desc - data description. + */ +template +SonicIntTemplateDatumArray::SonicIntTemplateDatumArray( + MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc) + : SonicDatumArray(cxt, capacity) +{ + Assert(desc); + AutoContextSwitch memGuard(m_cxt); + + m_nullFlag = genBitMap; + m_desc = *desc; + m_atomTypeSize = m_desc.typeSize; + genNewArray(genBitMap); + /* + * The first position in the first atom doesn't have data. + * And set the first flag to NULL. + */ + if (m_nullFlag) + setNthNullFlag(0, true); + + m_atomIdx = 1; +} + +/* + * @Description: put function. + * keep parameter flag to keep the same interfaces as + * as other data types. Do not check flag for better efficiency. + * @in vals - data to put. + * @in flag - flag, not used here. + * @in rows - the number of data to put. + */ +template +void SonicIntTemplateDatumArray::putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows) +{ + T* dst = (T*)(m_curAtom->data + sizeof(T) * m_atomIdx); + for (int i = 0; i < rows; i++) { + *dst = (T)(*vals); + dst++; + vals++; + } +} + +/* + * @Description: Get function. Get val. + * @in arrIdx - array index. + * @in atomIdx - index in atom. + * @in val - output value. + * @return - Datum values. + */ +template +Datum SonicIntTemplateDatumArray::getDatum(int arrIdx, int atomIdx) +{ + Assert(0 <= arrIdx && arrIdx < m_arrSize); + Assert(0 <= atomIdx && (uint32)atomIdx < m_atomSize); + + return (Datum)((T*)m_arr[arrIdx]->data)[atomIdx]; +} + +/* + * @Description: Get function. Get both val and flag. + * @in arrIdx - array index. + * @in atomIdx - index in atom. + * @in val - output value. + * @in flag - output flag. + */ +template +void SonicIntTemplateDatumArray::getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag) +{ + Assert(0 <= arrIdx && arrIdx < m_arrSize); + Assert(0 <= atomIdx && (uint32)atomIdx < m_atomSize); + + *val = ((T*)m_arr[arrIdx]->data)[atomIdx]; + *flag = getNthNullFlag(arrIdx, atomIdx); +} + +/* + * @Description: Get function. Get vals. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumArray(int nrows, int* arrIdx, int* atomIdx, Datum* data) +{ + Assert(nrows <= BatchMaxSize); + int i; + + for (i = 0; i < nrows; i++) { + *data = (Datum)((T*)m_arr[*arrIdx]->data)[*atomIdx]; + arrIdx++; + atomIdx++; + data++; + } +} + +/* + * @Description: Get function. Get both vals and flags. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * @in flag - output flags. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag) +{ + Assert(nrows <= BatchMaxSize); + int i; + + for (i = 0; i < nrows; i++) { + *flag = getNthNullFlag(arrayIdx->arrIdx, arrayIdx->atomIdx); + *data = (Datum)((T*)m_arr[arrayIdx->arrIdx]->data)[arrayIdx->atomIdx]; + arrayIdx++; + data++; + flag++; + } +} + +/* + * @Description: Get function when does hash key matching. Get data and flag from atoms. + * @in nrows - the number of data to get. + * @in arrIdx - array index. The size should be nrows. + * @in atomIdx - index in atom. The size should be nrows. + * @in data - output values. + * @in flag - output flags. + * @in matchIdx - matched array. If false, means current tuple pair doesn't match, + * so no need to get datum and flag any more, skip it. + * The space of data and flag should be allocated by caller. + */ +template +void SonicIntTemplateDatumArray::getDatumFlagArrayWithMatch( + int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx) +{ + Assert(nrows <= BatchMaxSize); + for (int i = 0; i < nrows; i++) { + if (*matchIdx) { + int arrIdx = arrayIdx->arrIdx; + int atomIdx = arrayIdx->atomIdx; + + *flag = m_arr[arrIdx]->nullFlag[atomIdx]; + *data = (Datum)((T*)m_arr[arrIdx]->data)[atomIdx]; + } + matchIdx++; + arrayIdx++; + data++; + flag++; + } +} + +/* + * @Description: set value into nth position in atom. + * The space in atom must be valid. + * @in nth - value position. + * @in val - value to put. + */ +template +void SonicIntTemplateDatumArray::setNthDatum(uint32 nth, ScalarValue* val) +{ + int arrIndx; + int atomIndx; + + arrIndx = (int)getArrayIndx(nth, m_nbit); + atomIndx = (int)getArrayLoc(nth, m_atomSize - 1); + + // Make sure the space is already allocated. + Assert(&(((T*)m_arr[arrIndx]->data)[atomIndx])); + ((T*)m_arr[arrIndx]->data)[atomIndx] = (T)*val; +} + +/* + * @Description: put data into atom. + * Do not consider flag in this function. + * If more space is needed, allocate it. + * @in val - data to put. + * @in nrows - the number of data. + */ +template +void SonicIntTemplateDatumArray::putIntValArray(T* val, int nrows) +{ + int loopRows; + + bool needExpand = (uint32)nrows > (m_atomSize - m_atomIdx); + loopRows = needExpand ? (m_atomSize - m_atomIdx) : nrows; + + if (loopRows > 0) { + putIntVal(val, loopRows); + m_atomIdx += loopRows; + } + + if (needExpand) { + genNewArray(m_nullFlag); + putIntValArray(val + loopRows, nrows - loopRows); + } +} + +/* + * @Description: put data into single atom. + * Do not consider flag in this function. + * The atom used must be valid. + * @in val - data to put. + * @in nrows - the number of data. + */ +template +void SonicIntTemplateDatumArray::putIntVal(T* val, int nrows) +{ + T* dst = (uint32*)(m_curAtom->data + sizeof(T) * m_atomIdx); + for (int i = 0; i < nrows; i++) { + *dst = *val; + dst++; + val++; + } +} + +extern SonicDatumArray* AllocateIntArray( + MemoryContext createContext, MemoryContext internalContext, int capacity, bool genNullFlag, DatumDesc* desc); + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICINT_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicnumeric.h postgresql-hll-2.14/include/vectorsonic/vsonicnumeric.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicnumeric.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicnumeric.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,97 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicnumeric.h + * Routines to handle Numeric data type. + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicnumeric.h + * + * --------------------------------------------------------------------------------------- + */ + + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ + +#include "vecexecutor/vechashjoin.h" +#include "vecexecutor/vechashtable.h" +#include "vecexecutor/vecexecutor.h" +#include "vecexecutor/vectorbatch.inl" +#include "postgres.h" +#include "knl/knl_variable.h" +#include "executor/executor.h" +#include "commands/explain.h" +#include "utils/anls_opt.h" +#include "utils/biginteger.h" +#include "utils/builtins.h" +#include "utils/numeric.h" +#include "miscadmin.h" +#include "vecexecutor/vecexpression.h" +#include "fmgr.h" +#include "foreign/fdwapi.h" +#include "tcop/utility.h" +#include "utils/bloom_filter.h" +#include "utils/lsyscache.h" + +#include "vectorsonic/vsonicarray.h" + +class SonicNumericDatumArray : public SonicDatumArray { +public: + SonicNumericDatumArray(MemoryContext cxt, int capacity, bool genBitMap, DatumDesc* desc); + + ~SonicNumericDatumArray(){}; + + void genAdditonArr(); + + void genNewArray(bool genBitMap); + + void setResultBuf(char* resultBuf, int* bufIndx); + + void putDatumArrayWithNullCheck(ScalarValue* vals, uint8* flag, int rows); + + void getDatumFlag(int arrIdx, int atomIdx, ScalarValue* val, uint8* flag); + + Datum getDatum(int arrIdx, int atomIdx); + + void getDatumFlagArray(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag); + + void getDatumFlagArrayWithMatch(int nrows, ArrayIdx* arrayIdx, Datum* data, uint8* flag, const bool* matchIdx); + + size_t flushDatumFlagArrayByRow(int arrIdx, uint32* partIdx, void** filePartitions, uint32 colIdx, int rowIdx); + + size_t flushDatumFlagArray(int arrIdx, uint32* partIdx, void** innerPartitions, uint32 colIdx, int nrows); + + void loadDatumFlagArrayByRow(void* fileSource, int leftrows); + + void loadDatumFlagArray(void* fileSource, int rows); + +public: + /* Used for non-numeric64. */ + VarBuf* m_buf; + /* Manage multiple m_curOffset. */ + uint32** m_offsetArr; + /* Record current offset. */ + uint32* m_curOffset; + int m_offArrSize; + uint32 m_internalLen; + uint32 m_curLen; + /* Used for numeric64 when get from atom. */ + char* m_tmpBuf; + int m_tmpBufIdx; + char* m_atomBuf; +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICNUMERIC_H_ */ diff -uprN postgresql-hll-2.14_old/include/vectorsonic/vsonicpartition.h postgresql-hll-2.14/include/vectorsonic/vsonicpartition.h --- postgresql-hll-2.14_old/include/vectorsonic/vsonicpartition.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/vectorsonic/vsonicpartition.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,233 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * vsonicpartition.h + * sonic partition class and class member declare + * + * IDENTIFICATION + * src/include/vectorsonic/vsonicpartition.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ +#define SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "vectorsonic/vsonichash.h" +#include "vectorsonic/vsonicarray.h" +#include "vectorsonic/vsonicfilesource.h" + +/* int typeSize has 4 values:1,2,4,8. */ +#define int_typeSize_1Byte 1 +#define int_typeSize_2Byte 2 +#define int_typeSize_4Byte 4 +#define int_typeSize_8Byte 8 + +typedef enum { + partitionStatusInitial = 1, + partitionStatusMemory, + partitionStatusFile, + partitionStatusFinish +} PartitionStatus; + +class SonicHashPartition : public SonicHashSource { + +public: + /* memory context partition holds */ + MemoryContext m_context; + + /* partition status */ + PartitionStatus m_status; + + /* number of columns */ + uint16 m_cols; + + /* number of rows partition holds */ + int64 m_rows; + + /* number of records in each files */ + uint64* m_fileRecords; + + /* total byte size of data */ + size_t m_size; + +public: + SonicHashPartition(const char* cxtname, uint16 cols, int64 workMem); + ~SonicHashPartition(){}; + + virtual void freeResources() + { + Assert(false); + } + + virtual void init(uint16 colIdx, DatumDesc* desc) + { + Assert(false); + } + + virtual void putHash(uint32* hashValues, uint64 nrows = 1) + { + Assert(false); + } + + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + Assert(false); + } + + virtual bool isValid() + { + Assert(false); + return false; + } +}; + +class SonicHashMemPartition : public SonicHashPartition { + +public: + /* where to put data */ + SonicDatumArray** m_data; + + /* For complicate join key */ + SonicDatumArray* m_hash; + + uint8 m_bucketTypeSize; + + uint32 m_hashSize; + + uint32 m_mask; + + bool m_segHashTable; + + /* non-segment hashtable */ + char* m_bucket; + + char* m_next; + + /* Segment hashtable */ + SonicDatumArray* m_segBucket; + + SonicDatumArray* m_segNext; + +public: + SonicHashMemPartition(const char* cxtname, bool hasHash, TupleDesc tupleDesc, int64 workMem); + ~SonicHashMemPartition(){}; + + void init(uint16 colIdx, DatumDesc* desc); + + void freeResources(); + + void putBatch(VectorBatch* batch); + + void flushPartition(int arrIdx, uint32* partIdx, SonicHashPartition** filePartitions, int nrows); + + void loadPartition(void* filePartition); + + void loadHash(void* partition); + + void putHash(uint32* hashValues, uint64 nrows); + + inline bool isValid(); + +private: + /* + * @Description: put ScalarValue column into SonicDatumArray per column + * actually, in memory, putVal has not been used. + * @in val - data to put + * @in flag - flag to put + * @in colIdx - column index this data belongs to + */ + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + m_data[colIdx]->putArray(val, flag, 1); + } +}; + +class SonicHashFilePartition : public SonicHashPartition { + +public: + /* number of files */ + uint16 m_fileNum; + + /* pointers of files */ + SonicHashFileSource** m_files; + + /* + * record the size of varible data which will not contained within the Atom's allocated space + * when loading into memory, such as SONIC_NUMERIC_COMPRESS_TYPE and SONIC_VAR_TYPE, + * whose data may stored in buffers (eg. VarBuf) other than Atom. + * The Atom only holds the pointers of the data. + */ + size_t m_varSize; + + /* assembled batch */ + VectorBatch* m_batch; + + int* m_filetype; + +public: + SonicHashFilePartition(const char* cxtname, bool hasHash, TupleDesc tupleDesc, int64 workMem); + + SonicHashFilePartition(const char* cxtname, VectorBatch* out_batch, int64 workMem); + + ~SonicHashFilePartition(){}; + + void init(uint16 fileIdx, DatumDesc* desc); + + void prepareFileHandlerBuffer(); + + void releaseFileHandlerBuffer(); + + void freeResources(); + + template + void putVal(ScalarValue* val, uint8* flag, uint16 colIdx) + { + if (optspill) { + int fileidx = m_filetype[colIdx]; + size_t written = m_files[fileidx]->writeVal(val, *flag); + /* fix row number */ + m_fileRecords[fileidx]++; + /* record written size */ + m_size += written; + pgstat_increase_session_spill_size(written); + } else { + size_t written = m_files[colIdx]->writeVal(val, *flag); + /* fix row number */ + m_fileRecords[colIdx]++; + /* record written size */ + m_size += written; + pgstat_increase_session_spill_size(written); + } + } + + void putHash(uint32* hashValues, uint64 nrows = 1); + + void getHash(uint32* hashValues, uint64 nrows); + + VectorBatch* getBatch(); + + void closeFiles(); + + void rewindFiles(); + + inline bool isValid(); +}; + +#endif /* SRC_INCLUDE_VECTORSONIC_VSONICPARTITION_H_ */ diff -uprN postgresql-hll-2.14_old/include/windowapi.h postgresql-hll-2.14/include/windowapi.h --- postgresql-hll-2.14_old/include/windowapi.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/windowapi.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,162 @@ +/* ------------------------------------------------------------------------- + * + * windowapi.h + * API for window functions to extract data from their window + * + * A window function does not receive its arguments in the normal way + * (and therefore the concept of strictness is irrelevant). Instead it + * receives a "WindowObject", which it can fetch with PG_WINDOW_OBJECT() + * (note V1 calling convention must be used). Correct call context can + * be tested with WindowObjectIsValid(). Although argument values are + * not passed, the call is correctly set up so that PG_NARGS() can be + * used and argument type information can be obtained with + * get_fn_expr_argtype(), get_fn_expr_arg_stable(), etc. + * + * Operations on the WindowObject allow the window function to find out + * the current row number, total number of rows in the partition, etc + * and to evaluate its argument expression(s) at various rows in the + * window partition. See the header comments for each WindowObject API + * function in nodeWindowAgg.c for details. + * + * + * Portions Copyright (c) 2000-2012, PostgreSQL Global Development Group + * + * src/include/windowapi.h + * + * ------------------------------------------------------------------------- + */ +#ifndef WINDOWAPI_H +#define WINDOWAPI_H + +/* values of "seektype" */ +#define WINDOW_SEEK_CURRENT 0 +#define WINDOW_SEEK_HEAD 1 +#define WINDOW_SEEK_TAIL 2 +#include "nodes/execnodes.h" + +typedef struct rownumber_context { + int64 rownumber; +} rownumber_context; + +/* + * ranking process information + */ +typedef struct rank_context { + int64 rank; /* current rank */ +} rank_context; +/* + * All the window function APIs are called with this object, which is passed + * to window functions as fcinfo->context. + */ +typedef struct WindowObjectData { + NodeTag type; + WindowAggState* winstate; /* parent WindowAggState */ + List* argstates; /* ExprState trees for fn's arguments */ + void* localmem; /* WinGetPartitionLocalMemory's chunk */ + int markptr; /* tuplestore mark pointer for this fn */ + int readptr; /* tuplestore read pointer for this fn */ + int64 markpos; /* row that markptr is positioned on */ + int64 seekpos; /* row that readptr is positioned on */ +} WindowObjectData; + +/* this struct is private in nodeWindowAgg.c */ +typedef struct WindowObjectData* WindowObject; +/* + * We have one WindowStatePerFunc struct for each window function and + * window aggregate handled by this node. + */ +typedef struct WindowStatePerFuncData { + /* Links to WindowFunc expr and state nodes this working state is for */ + WindowFuncExprState* wfuncstate; + WindowFunc* wfunc; + + int numArguments; /* number of arguments */ + + FmgrInfo flinfo; /* fmgr lookup data for window function */ + + Oid winCollation; /* collation derived for window function */ + + /* + * We need the len and byval info for the result of each function in order + * to know how to copy/delete values. + */ + int16 resulttypeLen; + bool resulttypeByVal; + + bool plain_agg; /* is it just a plain aggregate function? */ + int aggno; /* if so, index of its PerAggData */ + + WindowObject winobj; /* object used in window function API */ + + // Vectorization specific + // + AttrNumber m_resultCol; // position in the output batch + +} WindowStatePerFuncData; + +/* + * For plain aggregate window functions, we also have one of these. + */ +typedef struct WindowStatePerAggData { + /* Oids of transfer functions */ + Oid transfn_oid; + Oid finalfn_oid; /* may be InvalidOid */ + + /* + * fmgr lookup data for transfer functions --- only valid when + * corresponding oid is not InvalidOid. Note in particular that fn_strict + * flags are kept here. + */ + FmgrInfo transfn; + FmgrInfo finalfn; + + /* + * initial value from pg_aggregate entry + */ + Datum initValue; + bool initValueIsNull; + + /* + * cached value for current frame boundaries + */ + Datum resultValue; + bool resultValueIsNull; + + /* + * We need the len and byval info for the agg's input, result, and + * transition data types in order to know how to copy/delete values. + */ + int16 inputtypeLen, resulttypeLen, transtypeLen; + bool inputtypeByVal, resulttypeByVal, transtypeByVal; + + int wfuncno; /* index of associated PerFuncData */ + + /* Current transition value */ + Datum transValue; /* current transition value */ + bool transValueIsNull; + + bool noTransValue; /* true if transValue not set yet */ +} WindowStatePerAggData; + +#define PG_WINDOW_OBJECT() ((WindowObject)fcinfo->context) + +#define WindowObjectIsValid(winobj) ((winobj) != NULL && IsA(winobj, WindowObjectData)) + +extern void* WinGetPartitionLocalMemory(WindowObject winobj, Size sz); + +extern int64 WinGetCurrentPosition(WindowObject winobj); +extern int64 WinGetPartitionRowCount(WindowObject winobj); + +extern void WinSetMarkPosition(WindowObject winobj, int64 markpos); + +extern bool WinRowsArePeers(WindowObject winobj, int64 pos1, int64 pos2); + +extern Datum WinGetFuncArgInPartition( + WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool* isnull, bool* isout); + +extern Datum WinGetFuncArgInFrame( + WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool* isnull, bool* isout); + +extern Datum WinGetFuncArgCurrent(WindowObject winobj, int argno, bool* isnull); + +#endif /* WINDOWAPI_H */ diff -uprN postgresql-hll-2.14_old/include/workload/commgr.h postgresql-hll-2.14/include/workload/commgr.h --- postgresql-hll-2.14_old/include/workload/commgr.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/commgr.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,68 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * commgr.h + * definitions for statistics control functions + * + * IDENTIFICATION + * src/include/workload/commgr.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef WORKLOAD_COMMGR_H +#define WORKLOAD_COMMGR_H + +#include "pgxc/pgxcnode.h" + +typedef void (*WLMParseDetail)(const char*, void*); +typedef void (*WLMParseMessage)(StringInfo, void*, int); + +typedef enum WLMCollectTag { + WLM_COLLECT_NONE = 0, + WLM_COLLECT_UTIL, + WLM_COLLECT_USERINFO, + WLM_COLLECT_SESSINFO, + WLM_COLLECT_IO_RUNTIME, + WLM_COLLECT_PROCINFO, + WLM_COLLECT_ANY, + WLM_COLLECT_OPERATOR_RUNTIME, + WLM_COLLECT_OPERATOR_SESSION, + WLM_COLLECT_ADJUST, + WLM_COLLECT_JOBINFO +} WLMCollectTag; + +extern LWLock* LockSessRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockSessHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockSessRealTHashPartition(uint32 hashCode); +extern void UnLockSessHistHashPartition(uint32 hashCode); +extern LWLock* LockInstanceRealTHashPartition(uint32 hashCode, LWLockMode lockMode); +extern LWLock* LockInstanceHistHashPartition(uint32 hashCode, LWLockMode lockMode); +extern void UnLockInstanceRealTHashPartition(uint32 hashCode); +extern void UnLockInstanceHistHashPartition(uint32 hashCode); +extern void WLMLocalInfoCollector(StringInfo msg); +extern List* WLMRemoteJobInfoCollector(const char* keystr, void* suminfo, WLMCollectTag tag); +extern void WLMRemoteInfoCollector( + const char* keystr, void* suminfo, WLMCollectTag tag, int size, WLMParseMessage parse_func); +extern PGXCNodeAllHandles* WLMRemoteInfoCollectorStart(void); +extern int WLMRemoteInfoSenderByNG(const char* group_name, const char* keystr, WLMCollectTag tag); +extern int WLMRemoteInfoSender(PGXCNodeAllHandles* pgxc_handles, const char* keystr, WLMCollectTag tag); +extern void WLMRemoteInfoReceiverByNG(const char* group_name, void* suminfo, int size, WLMParseMessage parse_func); +extern void WLMRemoteInfoReceiver( + PGXCNodeAllHandles* pgxc_handles, void* suminfo, int size, WLMParseMessage parse_func); +extern void WLMRemoteInfoCollectorFinish(PGXCNodeAllHandles* pgxc_handles); +extern void WLMRemoteNodeExecuteSql(const char* sql, int nodeid = 0); + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/cpwlm.h postgresql-hll-2.14/include/workload/cpwlm.h --- postgresql-hll-2.14_old/include/workload/cpwlm.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/cpwlm.h 2020-12-12 17:06:43.414350193 +0800 @@ -0,0 +1,77 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * cpwlm.h + * + * + * IDENTIFICATION + * src/include/workload/cpwlm.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CPWLM_H +#define CPWLM_H + +#include "lib/stringinfo.h" +#include "pgxc/pgxcnode.h" + +/* core data in CCN of the compute pool */ +typedef struct DNState { + bool is_normal; + int num_rp; +} DNState; + +/* core data in CCN of the compute pool */ +typedef struct { + DNState* dn_state; + int dn_num; +} ComputePoolState; + +/* from the CN of the compute pool */ +typedef struct { + int dnnum; + int freerp; + char* version; +} CPRuntimeInfo; + +/* from the conf file in CN data directory of DWS. */ +typedef struct { + char* cpip; + char* cpport; + char* username; + char* password; + char* version; + int dnnum; + int pl; + int rpthreshold; +} ComputePoolConfig; + +extern List* get_dnlist(int neededDNnum); +extern ComputePoolState* get_cluster_state(); +extern void process_request(StringInfo input_message); +extern void get_cp_runtime_info(PGXCNodeHandle* handle); +extern char* get_version(); +extern ComputePoolConfig** get_cp_conninfo(int* cnum = NULL); + +extern char* trim(char* src); + +extern bool check_version_compatibility(const char* remote_version); + +/* just run on DN */ +extern void decrease_rp_number(); +extern void increase_rp_number(); + +#endif // CPWLM_H diff -uprN postgresql-hll-2.14_old/include/workload/ctxctl.h postgresql-hll-2.14/include/workload/ctxctl.h --- postgresql-hll-2.14_old/include/workload/ctxctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/ctxctl.h 2020-12-12 17:06:43.415350206 +0800 @@ -0,0 +1,521 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ctxctl.h + * definitions for context control functions + * + * IDENTIFICATION + * src/include/workload/ctxctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef CTXCTL_H +#define CTXCTL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +#include "gstrace/gstrace_infra.h" + +#define THREADID (gettid()) +#define PROCESSID (getpid()) + +#define DUP_ARRAY_POINTER(p, n) pobjdup(p, n) +#define DUP_POINTER(p) DUP_ARRAY_POINTER(p, 1) + +/* use a mutext lock */ +#define USE_CONTEXT_LOCK(mutex) \ + WLMContextLock sp_mutex_lock(mutex); \ + sp_mutex_lock.Lock() +/* use a lwlock */ +#define USE_AUTO_LWLOCK(lockid, lockmode) \ + WLMAutoLWLock sp_lwlock(lockid, lockmode); \ + sp_lwlock.AutoLWLockAcquire() +/* use a memory context */ +#define USE_MEMORY_CONTEXT(context) \ + WLMContextGuard spcxt((CleanHandler)MemoryContextSwitchTo, MemoryContextSwitchTo(context)) +/* use a smart context guard */ +#define USE_CONTEXT_GUARD(handler, object) WLMContextGuard sp_guard((CleanHandler)handler, object) +/* make ptr a smart pointer */ +#define MAKE_SMART_POINTER(ptr) USE_CONTEXT_GUARD(pfree, ptr) + +#define RELEASE_CONTEXT_LOCK() sp_mutex_lock.UnLock() +#define RELEASE_AUTO_LWLOCK() sp_lwlock.AutoLWLockRelease() +#define REVERT_MEMORY_CONTEXT() spcxt.handle() + +#define USE_LOCK_TO_ADD(mutex, src, inc) \ + do { \ + USE_CONTEXT_LOCK(&mutex); \ + src += inc; \ + if (src < 0) \ + src = 0; \ + } while (0); + +#define HANDLE_CONTEXT_GUARD() sp_guard.handle() + +#define IS_MUTEX_HELD(mutex, pid) ((mutex)->__data.__owner == pid) + +#define securec_check_errval(errno, express, elevel) \ + do { \ + errno_t resno = errno; \ + if (EOK != resno) { \ + express; \ + switch (resno) { \ + case EINVAL: \ + elog(elevel, \ + "%s : %d : The destination buffer is NULL or not terminated. The second case only occures in " \ + "function strcat_s/strncat_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EINVAL_AND_RESET: \ + elog(elevel, "%s : %d : The Source Buffer is NULL.", __FILE__, __LINE__); \ + break; \ + case ERANGE: \ + elog(elevel, \ + "%s : %d : The parameter destMax is equal to zero or larger than the macro : " \ + "SECUREC_STRING_MAX_LEN.", \ + __FILE__, \ + __LINE__); \ + break; \ + case ERANGE_AND_RESET: \ + elog(elevel, \ + "%s : %d : The parameter destMax is too small or parameter count is larger than macro " \ + "parameter SECUREC_STRING_MAX_LEN. The second case only occures in functions " \ + "strncat_s/strncpy_s.", \ + __FILE__, \ + __LINE__); \ + break; \ + case EOVERLAP_AND_RESET: \ + elog(elevel, \ + "%s : %d : The destination buffer and source buffer are overlapped.", \ + __FILE__, \ + __LINE__); \ + break; \ + default: \ + elog(elevel, "%s : %d : Unrecognized return type.", __FILE__, __LINE__); \ + break; \ + } \ + } \ + } while (0) + +#define securec_check_ssval(errno, express, elevel) \ + do { \ + errno_t resno = errno; \ + if (resno == -1) { \ + express; \ + elog(elevel, \ + "%s : %d : The destination buffer or format is a NULL pointer or the invalid parameter handle is " \ + "invoked.", \ + __FILE__, \ + __LINE__); \ + } \ + } while (0) + +typedef void (*CleanHandler)(void*); + +extern void* palloc0_noexcept(Size size); + +template +struct smart_ptr { + smart_ptr() : m_handler(NULL), m_ptr(NULL) + {} + + explicit smart_ptr(T* ptr) : m_handler(pfree), m_ptr(ptr) + {} + + smart_ptr(CleanHandler myHandler, T* ptr) : m_handler(myHandler), m_ptr(ptr) + {} + + ~smart_ptr() + { + handle(); + } + + T* set(Size size) + { + m_handler = pfree; + m_ptr = palloc0(size); + + return m_ptr; + } + + void set(T* ptr) + { + m_handler = pfree; + m_ptr = ptr; + } + + void set(CleanHandler handler, T* ptr) + { + m_handler = handler; + m_ptr = ptr; + } + + void reset() + { + m_handler = NULL; + m_ptr = NULL; + } + + T* ptr() + { + return m_ptr; + } + + T* operator->() const + { + return m_ptr; + } + + void handle() + { + if (m_handler) + m_handler(m_ptr); + + reset(); + } + +protected: + smart_ptr(const smart_ptr&); + smart_ptr& operator=(const smart_ptr&); + +private: + CleanHandler m_handler; + T* m_ptr; +}; + +struct WLMContextLock { + WLMContextLock(pthread_mutex_t* mutex) + : m_mutex(mutex), m_isLocked(false), m_exitUnlock(true), m_clean(NULL), m_ptr(NULL), m_tid(THREADID) + {} + + WLMContextLock(pthread_mutex_t* mutex, bool thread_exit_unlock) + : m_mutex(mutex), + m_isLocked(false), + m_exitUnlock(thread_exit_unlock), + m_clean(NULL), + m_ptr(NULL), + m_tid(THREADID) + {} + + ~WLMContextLock() + { + if (t_thrd.proc_cxt.proc_exit_inprogress && !m_exitUnlock) { + m_isLocked = false; + } + UnLock(); + } + + void Lock(bool isForce = false) + { + if (isForce || !m_isLocked) { + if (!IsOwner()) + (void)pthread_mutex_lock(m_mutex); + m_isLocked = true; + } + } + + bool TryLock() + { + if (!m_isLocked) { + int ret = pthread_mutex_trylock(m_mutex); + if (ret == 0) + m_isLocked = true; + } + + return m_isLocked; + } + + void UnLock(bool isSafe = false) + { + if (m_isLocked) { + clean(); + + if (!isSafe || IsOwner()) + (void)pthread_mutex_unlock(m_mutex); + + m_isLocked = false; + } + } + + bool IsOwner() + { + return IS_MUTEX_HELD(m_mutex, m_tid); + } + + void ReleaseLock(pthread_mutex_t* mutex) + { + pthread_mutex_t* old_mutex = m_mutex; + + m_mutex = mutex; + + if (IsOwner()) + (void)pthread_mutex_unlock(m_mutex); + + m_mutex = old_mutex; + } + + bool replace(pthread_mutex_t* mutex) + { + if (!m_isLocked) { + m_mutex = mutex; + return true; + } + + return false; + } + + void set(CleanHandler func, void* ptr) + { + m_clean = func; + m_ptr = ptr; + } + /* + * function name: reset + * description : reset params to handle for context lock. + * return value : void + */ + void reset() + { + m_clean = NULL; + m_ptr = NULL; + } + /* + * function name: clean + * description : execute the clean handler for context lock. + * return value : void + */ + void clean() + { + if (m_clean) { + m_clean(m_ptr); + reset(); + } + } + /* + * function name: ConditionWait + * description : execute the condition wait + * return value : void + */ + void ConditionWait(pthread_cond_t* condition) + { + (void)pthread_cond_wait(condition, m_mutex); + } + + void ConditionTimedWait(pthread_cond_t* condition, int seconds) + { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += seconds; + (void)pthread_cond_timedwait(condition, m_mutex, &ts); + } + + void ConditionWakeUp(pthread_cond_t* condition) + { + (void)pthread_cond_signal(condition); + } + +private: + pthread_mutex_t* m_mutex; + bool m_isLocked; + bool m_exitUnlock; + + CleanHandler m_clean; + void* m_ptr; + + pid_t m_tid; +}; + +#define WORKLOAD_LOCK_NUM ((int)WorkloadNodeGroupLock + 10) + +class WLMAutoLWLock { +public: + WLMAutoLWLock(LWLock *lock, LWLockMode lockMode) : m_lockId(lock), m_lockMode(lockMode), m_isLocked(false) + {} + + ~WLMAutoLWLock() + { + AutoLWLockRelease(); + } + + inline void AutoLWLockAcquire() + { + // Guard against recursive lock + if (!m_isLocked) { + LWLockAcquire(m_lockId, m_lockMode); + m_isLocked = true; + } + } + + inline void AutoLWLockRelease() + { + if (m_isLocked && !t_thrd.port_cxt.thread_is_exiting) { + /* maybe there is try-catch operation, + * it resets the t_thrd.int_cxt.InterruptHoldoffCount as 0. + * So reset it again to avoid core issue */ + if (t_thrd.int_cxt.InterruptHoldoffCount == 0) + HOLD_INTERRUPTS(); + LWLockRelease(m_lockId); + m_isLocked = false; + } + } + +private: + LWLock *m_lockId; + LWLockMode m_lockMode; + bool m_isLocked; +}; + +typedef smart_ptr WLMContextGuard; + +template +T* pobjdup(T* ptr, size_t n) +{ + if (ptr == NULL) + return ptr; + + T* duptr = (T*)palloc0_noexcept(sizeof(T) * n); + + if (duptr == NULL) + return duptr; + + errno_t errval = memcpy_s(duptr, n * sizeof(T), ptr, n * sizeof(T)); + securec_check_errval(errval, , LOG); + + return duptr; +} + +template +NodeType* search_node(const List* list, const KeyType* keydata) +{ + foreach_cell(cell, list) + { + NodeType* node = (NodeType*)lfirst(cell); + + if (node->equals(keydata)) + return node; + } + + return NULL; +} + +template +ListCell* search_list(const List* list, const KeyType* keydata, bool* found) +{ + ListCell* curr = NULL; + ListCell* prev = NULL; + NodeType* node = NULL; + + if (found != NULL) + *found = false; + + foreach (curr, list) { + node = (NodeType*)lfirst(curr); + + int comp = node->compare(keydata); + + if (comp == 0) { + if (found != NULL) + *found = true; + + return curr; + } else if (comp > 0) + return prev; + + prev = curr; + } + + return prev; +} + +template +ListCell* append_to_list(List** list, const KeyType* keydata, NodeType* node = NULL) +{ + bool found = false; + + ListCell* lcnode = search_list(*list, keydata, &found); + + if (found) + return lcnode; + + /* cannot find the node with this priority, we must create a new one. */ + if (ToAlloc) + node = (NodeType*)palloc0_noexcept(sizeof(NodeType)); + + if (node == NULL) + return NULL; + + PG_TRY(); + { + if (lcnode == NULL) { + *list = lcons(node, *list); + + lcnode = list_head(*list); + } else { + lcnode = lappend_cell(*list, lcnode, node); + } + } + PG_CATCH(); + { + lcnode = NULL; + + if (ToAlloc) + pfree(node); + + FlushErrorState(); + } + PG_END_TRY(); + + return lcnode; +} + +/* + * @Description: scan hash table, assign all the info "is_dirty" true + * @IN htab: hash table + * @Return: void + * @See also: + */ +template +void AssignHTabInfoDirtyWithLock(HTAB* htab, LWLock *lwlock) +{ + DataType* hdata = NULL; + + HASH_SEQ_STATUS hash_seq; + + USE_AUTO_LWLOCK(lwlock, LW_EXCLUSIVE); + + hash_seq_init(&hash_seq, htab); + + while ((hdata = (DataType*)hash_seq_search(&hash_seq)) != NULL) + hdata->is_dirty = true; +} + +template +void ProcessHTabRecordWithLock(HTAB* htab, LWLock *lwlock, CleanHandler handle) +{ + DataType* hdata = NULL; + + HASH_SEQ_STATUS hash_seq; + + USE_AUTO_LWLOCK(lwlock, LW_EXCLUSIVE); + + hash_seq_init(&hash_seq, htab); + + while ((hdata = (DataType*)hash_seq_search(&hash_seq)) != NULL) + handle(hdata); +} + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/dywlm_client.h postgresql-hll-2.14/include/workload/dywlm_client.h --- postgresql-hll-2.14_old/include/workload/dywlm_client.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/dywlm_client.h 2020-12-12 17:06:43.415350206 +0800 @@ -0,0 +1,191 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dywlm_client.h + * definitions for parallel control functions + * + * + * IDENTIFICATION + * src/include/workload/dywlm_client.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DYWLM_CLIENT1_H +#define DYWLM_CLIENT1_H + +#include "utils/hsearch.h" +#include "nodes/pg_list.h" +#include "workload/gscgroup.h" +#include "workload/statctl.h" +#include "workload/parctl.h" +#include "executor/execdesc.h" + +#define DYWLM_SEND_OK -5000 +#define DYWLM_SEND_FAILED -5001 +#define DYWLM_NO_NODE -5002 +#define DYWLM_NO_RECORD -5003 +#define DYWLM_NO_NGROUP -5004 + +#define DYWLM_TOP_QUOTA 90 +#define DYWLM_HIGH_QUOTA 80 +#define DYWLM_MEDIUM_QUOTA 60 +#define DYWLM_LOW_QUOTA 10 + +typedef struct ClientDynamicManager { + int active_statements; /* the number of active statements */ + int max_info_count; /* max info count in the hash table */ + int max_active_statements; /* global max active statements */ + int max_support_statements; /* max supported statement count */ + int max_statements; /* max statements in active */ + int current_support_statements; /* current statements who occupy memory */ + int central_waiting_count; /* count number in central queue waiting list */ + + int usedsize; /* used memory for client */ + int cluster; /* whether is cluster */ + int freesize; /* free memory size */ + + int running_count; /* count of complicated query */ + + bool recover; /* recovering mode */ + + char* group_name; /* group name */ + void* srvmgr; /* server manager */ + + HTAB* dynamic_info_hashtbl; /* resource pool is stored in this hash table*/ + List* statements_waiting_list; /* list for statements are waiting to do due to active statements over + max_active_statements */ + pthread_mutex_t statement_list_mutex; /* a mutex to lock statements waiting list */ +} ClientDynamicManager; + +struct DynamicInfoNode { + Qid qid; /* a id of a query */ + ThreadId threadid; /* thread id for a query */ + + int memsize; /* memory size to reserve */ + int max_memsize; /* max memory size to reserve */ + int min_memsize; /* min memory size to reserve */ + int priority; /* priority */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a query in the resource pool */ + + pthread_cond_t condition; /* The condition of the node to wake up */ + pthread_mutex_t mutex; /* mutex to wake up thread */ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char ngroup[NAMEDATALEN]; /* node group name */ + + bool wakeup; /* whether is woken up */ + bool is_dirty; /* whether is dirty */ + bool use_planb; /* whether use plan b */ +}; + +struct DynamicMessageInfo { + Qid qid; /* a id of a query */ + int memsize; /* memory size to reserve */ + int max_memsize; /* max memory size to reserve */ + int min_memsize; /* min memory size to reserve */ + int priority; /* priority */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a query in the resource pool */ + + ParctlType qtype; /* parallel control type */ + EnqueueType etype; /* enqueue type */ + + bool isserver; /* check the message whether is from server */ + bool use_max_mem; /* check whether use maximum memsize to execute */ + bool subquery; /* check whether is subquery */ + bool insubquery; /* check whether is the first subquery in one query*/ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char nodename[NAMEDATALEN]; /* node name */ + char groupname[NAMEDATALEN]; /* node group name */ +}; + +struct DynamicWorkloadRecord { + Qid qid; /* a id of a query */ + + int memsize; /* memory size reserved for a query */ + int max_memsize; /* max memory size reserved for a query */ + int min_memsize; /* min memory size reserved for a query */ + int actpts; /* active points for a query */ + int max_actpts; /* max active points for a query */ + int min_actpts; /* min active points for a query */ + int maxpts; /* max active points for a resource pool */ + int priority; /* priority of the record */ + + ParctlType qtype; /* parallel control type */ + WLMListNode* pnode; /* head of the queue, point to priority queue node */ + + char rpname[NAMEDATALEN]; /* resource pool name */ + char nodename[NAMEDATALEN]; /* node name */ + char groupname[NAMEDATALEN]; /* node group name */ + + bool try_wakeup; /* trying to wake up the query */ + bool removed; /* query already be removed */ + bool is_dirty; /* record is dirty */ + bool maybe_deleted; /* the record is already deleted probably */ + bool use_planb; /* check whether use planb to execute */ + + bool equals(const Qid* qid) + { + return IsQidEqual(&this->qid, qid); /* check qid is matched */ + } +}; + +extern ClientDynamicManager g_client_dywlm; +extern THR_LOCAL bool WLMProcessExiting; + +extern void dywlm_client_receive(StringInfo msg); +extern void dywlm_client_release(ParctlState* state); +extern void dywlm_client_reserve(void); +extern void dywlm_parallel_ready(const char* sqltext); +extern int dywlm_client_post(ClientDynamicManager*, const DynamicMessageInfo* msginfo); +extern int dywlm_get_central_node_idx(void); +extern void dywlm_client_write_catalog(StringInfo input_message); +extern void dywlm_client_recover(ClientDynamicManager*); +extern void dywlm_client_max_reserve(void); +extern void dywlm_client_max_release(ParctlState* state); +extern void dywlm_update_max_statements(int active_stetements); + +extern char* dywlm_get_node_name(Oid nodeidx, char* nodename); +extern int dywlm_get_node_idx(const char* nodename); +extern int dywlm_client_physical_info(int* total_mem, int* free_mem); +extern DynamicWorkloadRecord* dywlm_get_records(int* num); + +extern void dywlm_client_move_node_to_list(void* ng, ThreadId tid, const char* cgroup); +extern int dywlm_client_jump_queue(ClientDynamicManager*, ThreadId tid); +extern bool dywlm_client_is_cluster(); +extern int64 dywlm_client_get_memory(void); +extern int64 dywlm_client_get_max_memory(bool* use_tenant); +extern int64 dywlm_client_get_free_memory(void); +extern void dywlm_client_get_memory_info(int* total_mem, int* free_mem, bool* use_tenant); +extern void dywlm_client_set_respool_memory(int size, WLMStatusTag); +extern void dywlm_client_clean(void* ptr); +extern void dywlm_client_manager(QueryDesc* queryDesc, bool isQueryDesc = true); +extern void dywlm_client_verify_register(void); +extern int dywlm_get_cpu_count(void); +extern int dywlm_get_cpu_util(void); +extern int dywlm_get_active_statement_count(void); + +extern void dywlm_client_proc_release(void); + +extern void dywlm_client_display_climgr_info(StringInfo strinfo); +bool dywlm_is_local_node(); +#endif diff -uprN postgresql-hll-2.14_old/include/workload/dywlm_server.h postgresql-hll-2.14/include/workload/dywlm_server.h --- postgresql-hll-2.14_old/include/workload/dywlm_server.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/dywlm_server.h 2020-12-12 17:06:43.415350206 +0800 @@ -0,0 +1,109 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * dywlm_server.h + * definitions for parallel control functions + * + * + * IDENTIFICATION + * src/include/workload/dywlm_server.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef DYWLM_SERVER1_H +#define DYWLM_SERVER1_H + +#define UPDATE_FREQUENCY 3 /*updating resource utilization in COMPUTATION ACCELERATION cluster*/ + +#define COMP_ACC_CLUSTER \ + g_instance.attr.attr_sql.enable_acceleration_cluster_wlm /*COMPUTATION ACCELERATION cluster flag*/ + +typedef struct ServerDynamicManager { + int totalsize; /* total memory size for server */ + int freesize; /* free size for server */ + int freesize_inc; /* free memory increment between booking and DNs */ + int freesize_update; /* freesize is updated */ + int freesize_limit; + int rp_memsize; /* memory size occupied on resource pool */ + int active_count; /* COMPUTATION ACCELERATION cluster: active statement count */ + int statement_quota; /* COMPUTATION ACCELERATION cluster*/ + bool recover; /* recovering mode */ + bool try_wakeup; /* are waking up some requests*/ + + char* group_name; /* group name */ + + List* global_waiting_list; /* the queue complicate statements is waiting for waking up */ + HTAB* global_info_hashtbl; /* resource pool is stored in this hash table*/ + + ClientDynamicManager* climgr; /* client manager of the current server */ + + pthread_mutex_t global_list_mutex; /* a mutex to lock statements waiting list */ +} ServerDynamicManager; + +struct DynamicNodeData { + char host[NAMEDATALEN]; /* node host */ + Oid* group_members; /* group members of one node group */ + int group_count; /* group count of one node group */ + int used_memory; /* node used memory */ + int total_memory; /* node total memory */ + int estimate_memory; /* node estimate memory */ + + int phy_totalmem; /* physical total memory */ + int phy_freemem; /* physical free memory */ + int phy_usemem_rate; /* physical memory use rate */ + + int fp_memsize; /* setting memory for foreign users */ + int fp_usedsize; /* memory used for foreign users */ + int fp_estmsize; /* memory used for foreign users */ + int fp_mempct; /* memory used for foreign users */ + + int cpu_util; /* max physical cpu util of all nodes */ + int cpu_count; /* max physical cpu count of all nodes */ + int io_util; /* max io count of all nodes */ + + int min_freesize; /* minimum free size of nodes */ + + int min_memutil; /* minimum memory usage rate */ + int max_memutil; /* maximum memory usage rate */ + int min_cpuutil; /* minimum cpu usage rate */ + int max_cpuutil; /* maximum cpu usage rate */ + int min_ioutil; /* minimum io usage rate */ + int max_ioutil; /* maximum io usage rate */ + + HTAB* nodedata_htab; /* node data hash table */ +}; + +extern Oid dywlm_get_node_id(Oid procid); +extern void dywlm_server_receive(StringInfo msg); + +extern EnqueueType dywlm_server_reserve(ServerDynamicManager*, DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_release(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_cancel(ServerDynamicManager*, DynamicMessageInfo* msginfo); +extern void dywlm_server_clean(const char* nodename); +extern EnqueueType dywlm_server_clean_internal(ServerDynamicManager*, const char* nodename); +extern EnqueueType dywlm_server_move_node_to_list(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern EnqueueType dywlm_server_jump_queue(ServerDynamicManager*, const DynamicMessageInfo* msginfo); +extern void dywlm_node_recover(bool isForce); +extern DynamicWorkloadRecord* dywlm_server_get_records(ServerDynamicManager*, const char* nodename, int* num); +extern void dywlm_server_collector(void); +extern void dywlm_server_sync_records(void); +extern DynamicNodeData* dywlm_get_resource_info(ServerDynamicManager* srvmgr); +extern void dywlm_server_check_resource_pool(void); +extern void dywlm_server_get_respool_params(const char* rpname, int* running_count, int* waiting_count); + +extern void dywlm_server_display_srvmgr_info(StringInfo strinfo); +extern void dywlm_server_display_respool_info(StringInfo strinfo); +#endif diff -uprN postgresql-hll-2.14_old/include/workload/gscgroup.h postgresql-hll-2.14/include/workload/gscgroup.h --- postgresql-hll-2.14_old/include/workload/gscgroup.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/gscgroup.h 2020-12-12 17:06:43.415350206 +0800 @@ -0,0 +1,482 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * gscgroup.h + * header file to export the functions to use cgroup + * + * IDENTIFICATION + * src/include/workload/gscgroup.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef __GS_CGROUPS__ +#define __GS_CGROUPS__ + +#ifndef gettid + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include + +#include "c.h" +#include "gs_threadlocal.h" + +#include "datatype/timestamp.h" + +#define gettid() (pid_t) syscall(__NR_gettid) + +#endif + +#include "securec.h" +#include "securec_check.h" + +#define securec_check_berrno(errno, express, retval) \ + { \ + if (errno != EOK) { \ + express; \ + return retval; \ + } \ + } + +#define check_errno(errno, express, retval, file, line) \ + { \ + if (EOK != errno) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_errno(errno, express, retval) check_errno(errno, express, retval, __FILE__, __LINE__) + +#define check_intval(errno, express, retval, file, line) \ + { \ + if (errno == -1) { \ + fprintf(stderr, \ + "%s:%d failed on calling " \ + "security function.\n", \ + file, \ + line); \ + express; \ + return retval; \ + } \ + } + +#define securec_check_intval(val, express, retval) check_intval(val, express, retval, __FILE__, __LINE__) + +/* + * Cgroups is divided into 4 purposes: + * Backend Cgroup: used to control the backend threads + * Class Cgroup: used to specify the resource percentage for classes + * DefaultWD Cgroup: used to control the default workload threads + * Timeshare Cgroup: used to control the timeshare threads + * + * Usually, Gaussdb cgroup has 80% dynamic resource of the whole system, + * but it can't beyond the 95% hard limitation. + * + * The resource Ratio for Class and Backend will be 1:2 as default. + * + * Each class can be assigned the specified resource percentage from + * Class cgroup based on requirement. + * + * Under each class cgroup, the default workload cgroup can be assigned the + * specified resource percentage; and its maximum level will be 5 as default. + * + * Each Class cgroup has the timeshare cgroups; + * The resource for timeshare is the remained resource of the class; + * So it must make sure that all resource for default workload is not the total of user. + * + * The logic graph of cgroup is deployed. + * a. /dev/cgroups is the mount point of cgroups + * b. Gaussdb is the top cgroup of Gauss Database + * c. Backend is the cgroup of backend threads + * e. Class is the top cgroup of users' query threads + * f. The name rule for default workload cgroups should be made up with "name:level" + * h. The default Class and default workload cgroup are provided + * i. At most, there are 6 levels for each user (4 levels for defaultwd and 2 level for timeshare) + * j. There are only 2 cgroups for default workload in each level + * f. Rush/High/Medium/Low is the timeshare cgroup in the bottom line of each tree path + + + /dev/cgroups/ ------- mount point + | + tasks (non-gaussdb threads) Gaussdb/ ------- database topdir + | + Backend/ tasks(no threads) Class/ ------- top class dir + | | + Vacuum/ ... tasks(backend threads) DefaultClass/ Class1/ ... --- class dir + | | + tasks(vacuum thread) DefaultWD:1/ RemainWD:1/ tasks(no threads) --- defaultwd dir (Level 1) + | | + tasks (query) DefaultWD:2/ RemainWD:2/ tasks(no threads) --- defaultwd dir (Level 2) + | + Timeshare:3/ tasks(no threads) --- top timeshare dir (Level 3) + | + Rush:4/ High:4/ Medium:4/ Low:4/ tasks(no threads) --- timeshare dir (Level 4) + | + tasks(query threads) + + + * Default values: + * 0. The top level cgroup number is 4: mountpoint, Gaussdb, Backend and Class; + * 1. The maximum number for backend cgroup is 16; + * 2. The maximum number for class cgroup is 64; + * 3. The maximum number for defaultwd and timeshare cgroup is 256 (64 * 4 = all timeshare cgroups); + * If user want to create one defaultwd cgroup, but there is no slot, it will fail. + * 4. + */ + +#define MOUNT_SUBSYS_KINDS 5 +#define MOUNT_CPU_ID 0 +#define MOUNT_CPUACCT_ID 1 /* cpu and cpuacct could not be separated */ +#define MOUNT_BLKIO_ID 2 +#define MOUNT_CPUSET_ID 3 +#define MOUNT_MEMORY_ID 4 + +#define MOUNT_CPU_NAME "cpu" +#define MOUNT_BLKIO_NAME "blkio" +#define MOUNT_CPUSET_NAME "cpuset" +#define MOUNT_CPUACCT_NAME "cpuacct" +#define MOUNT_MEMORY_NAME "memory" + +#define GSCGROUP_CONF_DIR "etc" +#define GSCFG_BACKUP ".bak" + +#define GSCGROUP_MOUNT_POINT "/sys/fs/cgroup" +#define GSCGROUP_MOUNT_POINT_OLD "/dev/cgroups" + +#define GSCGROUP_ROOT "Root" +#define GSCGROUP_TOP_DATABASE "Gaussdb" +#define GSCGROUP_CM "CM" +#define GSCGROUP_TOP_BACKEND "Backend" +#define GSCGROUP_TOP_CLASS "Class" +#define GSCGROUP_DEFAULT_CLASS "DefaultClass" +#define GSCGROUP_REMAIN_WORKLOAD "RemainWD" +#define GSCGROUP_TOP_TIMESHARE "Timeshare" +#define GSCGROUP_RUSH_TIMESHARE "Rush" +#define GSCGROUP_HIGH_TIMESHARE "High" +#define GSCGROUP_MEDIUM_TIMESHARE "Medium" +#define GSCGROUP_LOW_TIMESHARE "Low" +#define GSCGROUP_DEFAULT_BACKEND "DefaultBackend" +#define GSCGROUP_VACUUM "Vacuum" +#define GSCGROUP_TOP_WORKLOAD "TopWD" +#define GSCGROUP_INVALID_GROUP "InvalidGroup" + +#define GSCGROUP_DEFAULT_CGNAME GSCGROUP_MEDIUM_TIMESHARE + +#define GSCGROUP_TOPNUM 4 /* 4 groups for top cgroups */ +#define GSCGROUP_BAKNUM 16 /* 16 groups for backend threads */ +#define GSCGROUP_CLASSNUM 64 /* 64 groups for classes */ +#define GSCGROUP_WDNUM_OLD 256 /* 256 groups for default workload threads */ +#define GSCGROUP_WDNUM 640 /* 640 groups for default workload threads */ +#define GSCGROUP_TSNUM 4 /* 4 groups for timeshare workload threads */ +#define GSCGROUP_ALLNUM_OLD \ + (GSCGROUP_TOPNUM + GSCGROUP_BAKNUM + GSCGROUP_CLASSNUM + GSCGROUP_WDNUM_OLD + GSCGROUP_TSNUM) +#define GSCGROUP_ALLNUM (GSCGROUP_TOPNUM + GSCGROUP_BAKNUM + GSCGROUP_CLASSNUM + GSCGROUP_WDNUM + GSCGROUP_TSNUM) + +/* Timeshare Rate Value */ +#define TS_RUSH_RATE 8 /* the rate of rush timeshare group */ +#define TS_HIGH_RATE 4 /* the rate of high timeshare group */ +#define TS_MEDIUM_RATE 2 /* the rate of medium timeshare group */ +#define TS_LOW_RATE 1 /* the rate of low timeshare group */ +#define TS_ALL_RATE (TS_RUSH_RATE + TS_HIGH_RATE + TS_MEDIUM_RATE + TS_LOW_RATE) + +#define TOPCG_START_ID 0 +#define TOPCG_ROOT 0 +#define TOPCG_GAUSSDB 1 +#define TOPCG_BACKEND 2 +#define TOPCG_CLASS 3 +#define TOPCG_END_ID (GSCGROUP_TOPNUM - 1) /*3*/ + +#define BACKENDCG_START_ID (TOPCG_END_ID + 1) /*4*/ +#define BACKENDCG_END_ID (BACKENDCG_START_ID + GSCGROUP_BAKNUM - 1) /*19*/ + +#define CLASSCG_START_ID (BACKENDCG_END_ID + 1) /*20*/ +#define CLASSCG_END_ID (CLASSCG_START_ID + GSCGROUP_CLASSNUM - 1) /*83*/ + +#define WDCG_START_ID (CLASSCG_END_ID + 1) /*84*/ +#define WDCG_END_ID_OLD (WDCG_START_ID + GSCGROUP_WDNUM_OLD - 1) /*84+255*/ +#define WDCG_END_ID (WDCG_START_ID + GSCGROUP_WDNUM - 1) /*84+640-1*/ + +#define TSCG_START_ID_OLD (WDCG_END_ID_OLD + 1) +#define TSCG_START_ID (WDCG_END_ID + 1) +#define TSCG_END_ID (TSCG_START_ID + GSCGROUP_TSNUM - 1) + +#define DEFAULT_CPU_SHARES 1024 +#define DEFAULT_GAUSS_CPUSHARES 5120 /* about 5x non-database resource */ +#define DEFAULT_CM_CPUSHARES 8192 /* about 8x non-database resource */ +#define MAX_CLASS_CPUSHARES 10000 /* for easy calculation */ + +#define TOP_BACKEND_PERCENT 40 /* 40% percentage of gaussdb resource */ +#define TOP_CLASS_PERCENT (100 - TOP_BACKEND_PERCENT) /* 60% percentage of gaussdb resource */ + +#define DEFAULT_BACKEND_PERCENT 80 /* 80% percentage of top backend resource */ +#define VACUUM_PERCENT 20 /* 20% percentage of top backend resource */ +#define DEFAULT_CLASS_PERCENT 20 /* 20% percentage of top class resource */ +#define OTHER_CLASS_PERCENT (100 - DEFAULT_CLASS_PERCENT) /* 60% percentage of other class resource */ +#define DEFAULT_WORKLOAD_PERCENT 20 /* 20% percentage of default class resource */ +#define TOPWD_PERCENT 90 /* 90% percentage of Class used for top wd */ + +#define DEFAULT_CPU_PERIOD 100000 +#define DEFAULT_IO_WEIGHT 500 +#define MIN_IO_WEIGHT 100 +#define MAX_IO_WEIGHT 1000 + +#define GROUP_ALL_PERCENT 100 +#define TOPWD_PERCENT 90 +#define NORMALWD_PERCENT 10 + +#define DEFAULT_CPUSKEWPCT 30 +#define DEFAULT_QUALITIME 1800 + +/* gscgroup.cfg saves the cgroups information and is placed under etc directory */ +#define GSCFG_PREFIX "gscgroup" +#define GSCFG_SUFFIX ".cfg" + +#define WD_TOP_LEVEL 1 +#define MAX_WD_LEVEL 10 +#define GPNAME_LEN 64 /* name:level */ +#define IODATA_LEN 96 /* support about 6 ~ 8 disk devices */ +#define EXCEPT_LEN 256 +#define USERNAME_LEN 56 /* 64 - sizeof("Gaussdb:") */ +#define GPNAME_PATH_LEN (GPNAME_LEN * (MAX_WD_LEVEL + 1)) +#define PROCLINE_LEN 4096 +#define CPUSET_OLD_LEN 8 +#define CPUSET_LEN 64 +#define SUBSYS_LEN 8 + +#define NANOSECS_PER_SEC ((int64)(1000000000)) + +#define IO_WEIGHT_CALC(weight, percent) \ + ((weight * (percent) / 100) > MIN_IO_WEIGHT ? (weight * (percent) / 100) : MIN_IO_WEIGHT) + +#define CPU_SHARES "cpu.shares" +#define CPU_QUOTA "cpu.cfs_quota_us" +#define CPU_PERIOD "cpu.cfs_period_us" +#define BLKIO_WEIGHT "blkio.weight" +#define BLKIO_BPSREAD "blkio.throttle.read_bps_device" +#define BLKIO_IOPSREAD "blkio.throttle.read_iops_device" +#define BLKIO_BPSWRITE "blkio.throttle.write_bps_device" +#define BLKIO_IOPSWRITE "blkio.throttle.write_iops_device" +#define CPUSET_CPUS "cpuset.cpus" +#define CPUSET_MEMS "cpuset.mems" +#define CPUACCT_USAGE "cpuacct.usage" + +#define EXCEPT_ALL_KINDS 2 + +#define EXCEPT_ERROR -2 +#define EXCEPT_NONE -1 +#define EXCEPT_ABORT 0 +#define EXCEPT_PENALTY 1 + +#define EXCEPT_FLAG(eflag) ((eflag) + 1) +#define IS_EXCEPT_FLAG(eflag, except) ((eflag) == EXCEPT_FLAG((except))) + +#define CGroupIsValid(group) (NULL != (void*)group && *group && strcmp(group, GSCGROUP_INVALID_GROUP) != 0) +#define CGroupIsDefault(group) (NULL != (void*)group && *group && strcmp(group, "DefaultClass:Medium") == 0) + +#define V1R5_VERSION 1 /* used for upgrade from v1r5 */ +#define V1R6_VERSION 2 /* used for upgrade from v1r6 */ + +/* + * get the cpuset start value + * astart: the upper level cpu core start value + * aend: the upper level cpu core end value + * bsum: the sum of cpu cores except the current updating group + * bmax: the max cpu core of the same level other groups + * blen: the length of the cpu cores of the current updating group + */ +#define GET_CPUSET_START_VALUE(astart, aend, bsum, bmax, blen) \ + (((bsum) + (blen) <= (aend) - (astart) + 1) \ + ? (((aend) - (bmax) >= (blen)) ? (((bsum) > 0) ? ((bmax) + 1) : (astart)) : ((astart) + (bsum))) \ + : ((aend) - (blen) + 1)) + +/* type of all cgroups */ +typedef enum { + GROUP_NONE, + GROUP_TOP, /* the top cgroup */ + GROUP_CLASS, /* the class cgroup with the given resource, + not to control any threads */ + GROUP_BAKWD, /* the cgroup to control the backend threads */ + GROUP_DEFWD, /* the default workload cgroup for each class, + to control the query threads in the given level */ + GROUP_TSWD /* the timeshare group for each user, + to control the query threads in the bottom level */ +} group_type; + +/* type of resource allocation */ +typedef enum { + ALLOC_DYNAMIC, /* the dynamic allocation method */ + ALLOC_FIXED /* the fixed allocation method */ +} alloc_type; + +typedef struct { + int shares; /* the value of cpu.shares */ + int weight; /* the value of blkio.weight */ + int quota; /* the percentage of cpuset. */ + char iopsread[IODATA_LEN]; /* the value of blkio.throttle.read_iops_device */ + char iopswrite[IODATA_LEN]; /* the value of blkio.throttle.write_iops_device */ + char bpsread[IODATA_LEN]; /* the value of blkio.throttle.read_bps_device */ + char bpswrite[IODATA_LEN]; /* the value of blkio.throttle.write_bps_device */ +} alloc_old_info_t; + +typedef struct { + int shares; /* the value of cpu.shares */ + int weight; /* the value of blkio.weight */ + int quota; /* the percentage of cpuset. */ + int spare; /* not used */ + char iopsread[IODATA_LEN]; /* the value of blkio.throttle.read_iops_device */ + char iopswrite[IODATA_LEN]; /* the value of blkio.throttle.write_iops_device */ + char bpsread[IODATA_LEN]; /* the value of blkio.throttle.read_bps_device */ + char bpswrite[IODATA_LEN]; /* the value of blkio.throttle.write_bps_device */ +} alloc_info_t; + +typedef struct { + int percent; /* the percent value in gaussdb */ +} gscgroup_top_t; + +typedef struct { + int tgid; /* top gid */ + int maxlevel; /* the maxlevel of defaultwd cgroup */ + int percent; /* the percentage value in top class */ + int rempct; /* the remain percentage for workload */ +} gscgroup_class_t; + +typedef struct { + int cgid; /* class gid */ + int wdlevel; /* the level of the defaultwd cgroup */ + int percent; /* the percentage value in parent class */ +} gscgroup_wd_t; + +typedef struct { + int cgid; /* class gid */ + int rate; /* the rate based on the default value */ +} gscgroup_ts_t; + +typedef union { + gscgroup_top_t top; /* top group special information */ + gscgroup_class_t cls; /* class group special information */ + gscgroup_wd_t wd; /* defaultwd group special information */ + gscgroup_ts_t ts; /* timeshare group special information */ +} group_info_t; + +/* the throttle value for exception verification */ +typedef struct { + unsigned int blocktime; /* the start time - the submit time of query */ + unsigned int elapsedtime; /* the end time - the start time */ + unsigned int allcputime; /* the CPU time of all the node */ + unsigned int qualitime; /* the qualification time of all the node */ + unsigned int skewpercent; /* the CPU skew percent is the cuptime/allcputime */ + unsigned int spare[5]; /* not used */ +} except_old_data_t; + +/* the throttle value for exception verification */ +typedef struct { + unsigned int blocktime; /* the start time - the submit time of query */ + unsigned int elapsedtime; /* the end time - the start time */ + unsigned int allcputime; /* the CPU time of all the node */ + unsigned int qualitime; /* the qualification time of all the node */ + unsigned int skewpercent; /* the CPU skew percent is the cuptime/allcputime */ + unsigned int reserved; /* reserved flag */ + int64 spoolsize; /* spill size, unit is MB*/ + int64 broadcastsize; /* broadcast size, unit is MB*/ + unsigned int spare[14]; /* not used */ +} except_data_t; + +/* old version group information */ +typedef struct { + unsigned short used; /* flag if this group has been used */ + unsigned short gid; /* the group id */ + group_type gtype; /* top, backend, class, defaultwd or timeshare */ + group_info_t ginfo; /* group special information */ + unsigned short percent; /* the percentage value calculated by dynamic or fixed value */ + char grpname[GPNAME_LEN]; /* the cgroup name */ + alloc_old_info_t ainfo; /* resource alloc information */ + except_old_data_t except[EXCEPT_ALL_KINDS]; /* the exception data for aborting */ + char cpuset[CPUSET_OLD_LEN]; /* cpuset info */ + int spare[3]; /* not used */ +} gscgroup_old_grp_t; + +/* group information */ +typedef struct { + unsigned short used; /* flag if this group has been used */ + unsigned short gid; /* the group id */ + group_type gtype; /* top, backend, class, defaultwd or timeshare */ + group_info_t ginfo; /* group special information */ + char grpname[GPNAME_LEN]; /* the cgroup name */ + alloc_info_t ainfo; /* resource alloc information */ + except_data_t except[EXCEPT_ALL_KINDS]; /* the exception data for aborting */ + char cpuset[CPUSET_LEN]; /* cpuset info */ + unsigned int percent; /* the percentage value calculated by dynamic or fixed value */ + int spare[63]; /* not used , total size is 1024 bytes */ +} gscgroup_grp_t; + +typedef struct { + char name[GPNAME_LEN]; /* classname:workloadname */ + int percent; /* percent of the group */ + int cpuUtil; /* percent of the cpu usage */ + int cpuCount; /* the count of the cpu cores */ + int usedCpuCount; /* used cpu cores */ + int64 cpuUsedAcct; /* cpu usage value */ + int64 cpuLastAcct; /* last cpu value */ + TimestampTz lastTime; /* last collect time */ + struct cgroup* cg; /* cgroup structure */ + struct cgroup* oldcg; /* old cgroup structure */ +} gscgroup_entry_t; + +typedef struct { + gscgroup_entry_t entry; /* cgroup entry */ + char relpath[GPNAME_PATH_LEN]; /* relative path */ + char cpuset[CPUSET_LEN]; /* cpu set */ + char nodegroup[GPNAME_LEN]; /* node group name */ + int shares; /* cpu shares */ + bool valid; /* cgroup is valid or not */ +} gscgroup_info_t; + +typedef enum { GSCGROUP_NONE_STMT = 0, GSCGROUP_NORMAL_STMT, GSCGROUP_TOP_STMT, GSCGROUP_VACUUM_STMT } gscgroup_stmt_t; + +/* get the file size */ +extern long gsutil_filesize(const char* fname); + +/* return mapping address */ +extern void* gsutil_filemap(const char* fname, size_t nbytes, int prot, int flags, struct passwd* passwd_user); + +/* get the parent path of workload group */ +extern char* gscgroup_get_parent_wdcg_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); + +/* get the top timeshare path of class group */ +extern char* gscgroup_get_topts_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); +/* get the relative path of any specified group */ +extern char* gscgroup_get_relative_path(int cnt, gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM], char* nodegroup = NULL); +/* print exception flag */ +extern char* gsutil_print_exception_flag(int eflag); + +/* check the exception whether is valid */ +extern int gsutil_exception_is_valid(gscgroup_grp_t* grp, int kinds); + +/* check the exception kiind whether is valid */ +extern int gsutil_exception_kind_is_valid(gscgroup_grp_t* grp, int kind); + +/* get the cpu count */ +extern int gsutil_get_cpu_count(); + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/ioschdl.h postgresql-hll-2.14/include/workload/ioschdl.h --- postgresql-hll-2.14_old/include/workload/ioschdl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/ioschdl.h 2020-12-12 17:06:43.415350206 +0800 @@ -0,0 +1,182 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * ioschdl.h + * definitions for IO control parameters + * + * IDENTIFICATION + * src/include/workload/ioschdl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef IOSCHDL_H +#define IOSCHDL_H + +#include "postgres.h" +#include "knl/knl_variable.h" +/* IO types */ +#define IO_TYPE_WRITE 0 // IO type write +#define IO_TYPE_READ 1 // IO type read +#define IO_TYPE_COLUMN 0 // IO type for column +#define IO_TYPE_ROW 1 // IO type for row + +/* iostat */ +#define MAX_DEVICE_DIR 256 +#define UTIL_COUNT_LEN 3 + +/* util threshold */ +#define UTIL_HIGH_THRESHOLD 50 +#define UTIL_LOW_THRESHOLD 30 + +/* util state */ +#define UTIL_LOW 0 +#define UTIL_MEDIUM 1 +#define UTIL_HIGH 2 + +#define FETCH_IOSTAT 0 +#define RESET_IOSTAT 1 + +#define IO_MIN_COST 50000 + +#define IOCONTROL_UNIT 6000 + +// write take 30% +#define W_RATIO_THRESHOLD 30 +// iops cannot be lower than 5 +#define IOPS_LOW_LIMIT 5 + +#define FULL_PERCENT 100 + +#define IOPRIORITY_NONE 0 +#define IOPRIORITY_LOW 10 +#define IOPRIORITY_MEDIUM 20 +#define IOPRIORITY_HIGH 50 + +#define WLM_AUTOWAKE_INTERVAL 1 + +#define IOLIMIT_WAKE_TIME 1 +#define CPUSTAT_WAKE_TIME 8 + +#define IOPRIORITY_LOW_WAKE_TIME 3 +#define IOPRIORITY_MEDIUM_WAKE_TIME 2 +#define IOPRIORITY_HIGH_WAKE_TIME 1 + +#define FILE_DISKSTAT "/proc/diskstats" +#define FILE_CPUSTAT "/proc/stat" +#define FILE_MOUNTS "/proc/mounts" + +#define AVERAGE_DISK_VALUE(m, n, p, u) (((double)((n) - (m))) / (p)*u) + +typedef struct IORequestEntry { + int amount; // IO amount + int rqst_type; // IO type + int count; // iocount + + int count_down; // count of time wlmmonitor thread is wakened + pthread_cond_t io_proceed_cond; +} IORequestEntry; + +struct blkio_info { + int used; + uint64 rd_ios; /* Read I/O operations */ + uint64 wr_ios; /* Write I/O operations */ + uint64 rd_sectors; /* Sectors read */ + uint64 wr_sectors; /* Sectors written */ + uint64 tot_ticks; /* Time of requests in queue */ +}; + +typedef struct WLMmonitor_iostat { + // updated on DN + char device[MAX_DEVICE_DIR]; /* device name */ + + // iostat + double rs; /* r/s */ + double ws; /* w/s */ + double util; /* %util */ + double w_ratio; /* write proportion */ + + // cpu util + double cpu_util; + int cpu_util_count; + int cpu_count; + + // for io scheduler + unsigned char device_util_tbl[UTIL_COUNT_LEN]; /* whether it is below the threshold*/ + int total_tbl_util; + int tick_count; + + // updated on CN + int maxIOUtil; + int minIOUtil; + int maxCpuUtil; + int minCpuUtil; + + int node_count; /* count of DN */ +} WLMmonitor_iostat; + +typedef struct WLMIOContext { + /* waiting list and mutex */ + List* waiting_list; + pthread_mutex_t waiting_list_mutex; + + /* cpu cores */ + int cpu_nr; + + /* + * cpu total time calculated from /proc/stat, + * the first element stores the last one, + * and the second stores the current + */ + uint64 uptime[2]; + /* cpu0 total calculated from /proc/stat */ + uint64 uptime0[2]; + /* cpu user time */ + uint64 cputime_user[2]; + + /* timestamp of the previous and the current */ + TimestampTz prev_timestamp; + TimestampTz cur_timestamp; + + /* hz per second */ + uint32 hz; + + /* blockio info, got from /proc/diskstats */ + struct blkio_info new_blkio; + struct blkio_info old_blkio; + + /* device iostat */ + WLMmonitor_iostat WLMmonitorDeviceStat; + + /* device init */ + bool device_init; +} WLMIOContext; + +extern void IOStatistics(int type, int count, int size); +extern void IOSchedulerAndUpdate(int type, int count, int store_type); +extern void WLMmonitor_check_and_update_IOCost(PlannerInfo* root, NodeTag node, Cost IOcost); + +/* monitoring thread use */ +extern ThreadId StartWLMmonitor(void); + +/* arbiter thread use */ +extern ThreadId StartWLMarbiter(void); + +#ifdef EXEC_BACKEND +extern void WLMmonitorMain(); +extern void WLMarbiterMain(); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/memctl.h postgresql-hll-2.14/include/workload/memctl.h --- postgresql-hll-2.14_old/include/workload/memctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/memctl.h 2020-12-12 17:06:43.416350219 +0800 @@ -0,0 +1,47 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * memctl.h + * Routines related to memory quota for queries. + * + * IDENTIFICATION + * src/include/workload/memctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef MEMCTL_H_ +#define MEMCTL_H_ + +/* + * during mem decrease procedure, we want to assign decreased mem to large mem, + * so just through the mem gap, and after decrease, large item should be at least 20% + * large than the small one + */ +#define DECREASED_MIN_CMP_GAP 0.1 + +/* Memory usage larger than 4GB is incredible */ +#define MAX_OP_MEM 4 * 1024L * 1024L + +/* min memory allocate for memory intensive operator for sake of huge initial mem allocation */ +#define MIN_OP_MEM 16 * 1024L + +extern void CalculateQueryMemMain(PlannedStmt* stmt, bool use_tenant, bool called_by_wlm); + +extern bool QueryNeedPlanB(PlannedStmt* stmt); +extern void ReSetNgQueryMem(PlannedStmt* result); +extern THR_LOCAL Oid lc_replan_nodegroup; + +#endif /* MEMQUOTA_H_ */ diff -uprN postgresql-hll-2.14_old/include/workload/parctl.h postgresql-hll-2.14/include/workload/parctl.h --- postgresql-hll-2.14_old/include/workload/parctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/parctl.h 2020-12-12 17:06:43.416350219 +0800 @@ -0,0 +1,164 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * parctl.h + * definitions for parallel control functions + * + * IDENTIFICATION + * src/include/workload/parctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef PARCTLS_H +#define PARCTLS_H +#define MAX_PARCTL_MEMORY ((unsigned int)maxChunksPerProcess << (chunkSizeInBits - BITS_IN_MB)) +/*the process memory while query running */ +#define PARCTL_PROCESS_MEMORY 32 /* MB */ + +/*the memory size of a query to start to do parallel control*/ +#define PARCTL_MEMORY_UNIT 3 /* MB */ + +#define PARCTL_ACTIVE_PERCENT 80 +#define PARCTL_ALL_PERCENT 100 + +typedef enum ParctlType { + PARCTL_NONE = 0, /* no parallel control */ + PARCTL_RESERVE, /* reserve resource request */ + PARCTL_GLOBAL, /* global parallel control */ + PARCTL_RESPOOL, /* resource pool parallel control */ + PARCTL_ACTIVE, /* query is running */ + PARCTL_RELEASE, /* release resource request */ + PARCTL_CANCEL, /* cancel query request */ + PARCTL_CLEAN, /* client recover request */ + PARCTL_SYNC, /* server recover request */ + PARCTL_TRANSACT, /* query is in the transaction block */ + PARCTL_MVNODE, /* move statement to new priority */ + PARCTL_JPQUEUE, /* move statement to highest priority */ + PARCTL_TYPES, /* count of types for parallel control, it's always the last one */ +} ParctlType; + +typedef enum EnqueueType { + ENQUEUE_NONE = 0, /* default state */ + ENQUEUE_BLOCK, /* query should be blocked */ + ENQUEUE_ERROR, /* query is in error state */ + ENQUEUE_NORESPOOL, /* target resource pool is not exist */ + ENQUEUE_MEMERR, /* query is in error state due to out of memory */ + ENQUEUE_RECOVERY, /* server is in recover state */ + ENQUEUE_CONNERR, /* connect to target node failed */ + ENQUEUE_PRIVILEGE, /* has privilege to run */ + ENQUEUE_GROUPERR, /* node group error */ + ENQUEUE_UNKNOWN /* parctl type is not valid, unknown to handle it */ +} EnqueueType; + +typedef struct RespoolData { + Oid rpoid; /* resource pool oid*/ + int max_pts; /* active statements for the resource pool */ + int max_stmt_simple; /* max statements for the resource pool for simple queries */ + int max_dop; /* max dop */ + int mem_size; /* memory pool size, kb */ + int act_pts; /* active statement points */ + int max_act_pts; /* active statement points */ + int min_act_pts; /* active statement points */ + int iops_limits; /* iops limits */ + int io_priority; /* io priority */ + bool superuser; /* Am I super user? */ + bool cgchange; /* check cgroup whether is changed */ + char rpname[NAMEDATALEN]; + char* cgroup; /* control group in resource pool */ +} RespoolData; + +/* used for BuildResourcePoolHash function, avoid dead lock */ +typedef struct TmpResourcePool +{ + Oid rpoid; /* resource pool id */ + Oid parentoid; /* resource pool id */ + int32 iops_limits; /* iops limit for each resource pool */ + int io_priority; /* io_percent for each resource pool */ + int mempct; /* setting percent */ + bool is_foreign; /* indicate that the resource pool is used for foreign users */ + + char cgroup[NAMEDATALEN]; /* cgroup information */ + char ngroup[NAMEDATALEN]; /* nodegroup information */ +} TmpResourcePool; + +typedef struct ParctlManager { + int max_active_statements; /* global max active statements */ + int statements_waiting_count; /* count of statements in waiting */ + int statements_runtime_count; /* count of statements in running */ + int statements_runtime_plus; /* increased of statements in running */ + int max_statements; /* max statements in active */ + int max_support_statements; /* max supported statements */ + int current_support_statements; /* current supported statements */ + int respool_waiting_count; /* count of statements waiting in resource pool */ + + List* statements_waiting_list; /* the queue complicate statements is waiting for waking up */ + + HTAB* resource_pool_hashtbl; /* resource pool is stored in this hash table*/ + + pthread_mutex_t statements_list_mutex; /* a mutex to lock statements waiting list */ +} ParctlManager; + +typedef struct WLMListNode { + int data; /* The priority of the node */ + List* request_list; /* list for statements with this priority in waiting */ + + bool equals(const int* data) + { + return this->data == *data; + } + + int compare(const int* data) + { + if (this->data == *data) + return 0; + + return ((this->data < *data) ? 1 : -1); + } +} WLMListNode; + +extern bool IsQueuedSubquery(void); +extern void WLMParctlReady(const char*); +/*Reserve workload resource*/ +extern void WLMParctlReserve(ParctlType); +/*Release workload resource*/ +extern void WLMParctlRelease(ParctlState*); +/*Handle simple stmt except for dywlm*/ +extern void WLMHandleDywlmSimpleExcept(bool proc_exit); +/*Initialize workload group hash table*/ +extern void InitializeUserResourcePoolHashTable(); +/* Switch node in the waiting list from old priority to new priority */ +extern void WLMSwitchQNodeList(ParctlManager*, int priority_old, int priority_new); +extern void WLMCreateResourcePoolInHash(Oid); +extern bool WLMCheckResourcePoolIsIdle(Oid); + +extern int WLMJumpQueue(ParctlManager*, ThreadId); +extern void WLMSetMaxStatements(int); +extern int WLMGetActiveStatments(); +/* get resource pool data info from hash table */ +extern void* WLMGetResourcePoolDataInfo(int* num); +extern ListCell* WLMSearchAndCheckMaxNode(const List* list); + +extern int WLMGetMaxDop(); +extern void WLMVerifyGlobalParallelControl(ParctlManager*); +extern int WLMGetMaxStatements(int active_statements); +extern void WLMCheckResourcePool(); + +extern void WLMProcReleaseActiveStatement(void); + +extern int WLMReleaseGroupActiveStatement(void); +void WLMCheckDefaultXactReadOnly(void); + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/qnode.h postgresql-hll-2.14/include/workload/qnode.h --- postgresql-hll-2.14_old/include/workload/qnode.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/qnode.h 2020-12-12 17:06:43.416350219 +0800 @@ -0,0 +1,74 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * qnode.h + * definitions for query node information in workload manager + * + * IDENTIFICATION + * src/include/workload/qnode.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef QNODE_H +#define QNODE_H + +typedef struct ResourcePool { + Oid rpoid; /* resource pool id */ + Oid parentoid; /* resource pool id */ + int ref_count; /* ref count of the resource pool */ + int active_points; /* the count of active statements in the resource pool */ + int server_actpts; /* server active points */ + int running_count; /* the count of running statements */ + int waiting_count; /* the count of waiting statements */ + int running_count_simple; /* the count of running statements for simple queries */ + int32 iops_limits; /* iops limit for each resource pool */ + int io_priority; /* io_percent for each resource pool */ + int memsize; /* setting memory size */ + int memused; /* used memory size */ + int mempct; /* setting percent */ + int actpct; /* real percent */ + int peakmem; /* peak used memory size */ + int estmsize; /* estimated memory size */ + bool is_dirty; /* resource pool is dirty, it will be removed while it's dirty */ + bool reset; /* reset */ + bool is_foreign; /* indicate that the resource pool is used for foreign users */ + List* waiters; /* list for statements are waiting in resource pool */ + List* waiters_simple; /* list for statements are waiting in resource pool for simple queries */ + void* node_group; /* node group pointer */ + List* entry_list; /* Used to save the foreign query list on datanode */ + struct ResourcePool* foreignrp; /* foreign resource pool of one parent */ + struct ResourcePool* parentrp; /* foreign resource pool of one parent */ + + char cgroup[NAMEDATALEN]; /* cgroup information */ + char ngroup[NAMEDATALEN]; /* nodegroup information */ + + pthread_mutex_t mutex; /* mutex to lock workload group */ +} ResourcePool; + +typedef struct WLMQNodeInfo { + pthread_cond_t condition; /* pthread condtion */ + Oid userid; /* The user id of the thread */ + bool removed; /* whether is removed from the waiting list */ + bool privilege; /* the query has privilege? */ + uint64 sessid; /* session id of current session */ + int priority; /* priority of the query */ + int max_pts; /* max pts for complicate or max stmt for simple */ + int act_pts; /* stmt active points */ + ListCell* lcnode; /* head of the queue */ + ResourcePool* rp; /* resource pool of the node */ +} WLMQNodeInfo; + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/statctl.h postgresql-hll-2.14/include/workload/statctl.h --- postgresql-hll-2.14_old/include/workload/statctl.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/statctl.h 2020-12-12 17:06:43.416350219 +0800 @@ -0,0 +1,795 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * statctl.h + * definitions for statistics control functions + * + * IDENTIFICATION + * src/include/workload/statctl.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef STATCTL_H +#define STATCTL_H + +#include "workload/parctl.h" +#include "instruments/list.h" +#define StringIsValid(pstr) (pstr && *pstr) +#define SqlIsValid(sql) (StringIsValid(sql) && strcmp(sql, ";") != 0) + +#define KBYTES 1024 +#define MBYTES (KBYTES * KBYTES) + +#define MAX_SLEEP_TIME 5 /*seconds*/ + +#define STAT_PATH_LEN KBYTES +#define INFO_STR_LEN 94 +/* + * warning includes + * - 256 byte reserved for warnings from query-executor + * - 2kb reserved for warnings from query-optimizer + */ +#define WARNING_INFO_LEN 2304 + +#define WARNING_SPILL_SIZE 256 /* 256MB */ +#define WARNING_BROADCAST_SIZE 100 /* 100MB */ +#define WARNING_SPILL_TIME 3 +#define WARNING_HASH_CONFLICT_LEN 256 + +#define GSUSER_ALLNUM 102400 +#define PAST_TIME_COUNT 3 +#define SIG_RECVDATA_COUNT 16 +#define GSWLM_CONF_DIR "etc" +#define GSWLMCFG_PREFIX "gswlm" +#define GSCONF_NAME "userinfo" +#define MAX_DEVICE_LEN 64 +#define ALL_USER "0000" //"0000" is an invalid user name, means update all user used space + +#define AVERAGE_VALUE(m, n, p) (((n) > (m)) ? (((int)((n) - (m))) / (p)) : (0)) +#define GET_LARGER_VALUE(x, y) (((x) > (y)) ? (x) : (y)) +#define PEAK_VALUE(start, end, intval, cmp) (GET_LARGER_VALUE(AVERAGE_VALUE((start), (end), (intval)), (cmp))) + +/*get max and min data in the session info, min value maybe 0, so set -1 as init value*/ +#define GetMaxAndMinCollectInfo(info, elem, data) \ + do { \ + if (data > info->max##elem) \ + info->max##elem = data; \ + if (info->min##elem == -1) \ + info->min##elem = data; \ + else if (data < info->min##elem) \ + info->min##elem = data; \ + } while (0) + +#define WLM_USER_RESOURCE_HISTORY "gs_wlm_user_resource_history" +#define WLM_INSTANCE_HISTORY "gs_wlm_instance_history" +#define WLM_EC_OPERATOR_INFO "gs_wlm_ec_operator_info" +#define WLM_OPERATOR_INFO "gs_wlm_operator_info" +#define WLM_SESSION_INFO "gs_wlm_session_query_info_all" + +enum WLMActionTag { + WLM_ACTION_REMAIN = 0, /* keep thread running */ + WLM_ACTION_ADJUST, /* change control group of statement */ + WLM_ACTION_ABORT, /* abort the statement */ + WLM_ACTION_FINISHED, /* finish the statement */ + WLM_ACTION_FETCHSESS, /* fetch session info */ + WLM_ACTION_REMOVED /* info removed */ +}; + +enum WLMStatusTag { + WLM_STATUS_RESERVE = 0, /* a status before waiting in wlm queue */ + WLM_STATUS_PENDING, /* waiting in the wlm queue */ + WLM_STATUS_RUNNING, /* statement is running */ + WLM_STATUS_FINISHED, /* statement is finished */ + WLM_STATUS_ABORT, /* statement is abort */ + WLM_STATUS_RELEASE /* wlm collect infomation is into db list or release statistics ctrl*/ +}; + +enum WLMAttrTag { + WLM_ATTR_NORMAL = 0, /* Normal is not into db */ + WLM_ATTR_INDB, /* push collect infomation into db list */ + WLM_ATTR_INVALID /* collect info is invalid */ +}; + +enum WLMWarnTag { + WLM_WARN_NONE = 0, /* no warn */ + WLM_WARN_SPILL, + WLM_WARN_EARLY_SPILL, + WLM_WARN_SPILL_TIMES_LARGE, + WLM_WARN_SPILL_FILE_LARGE, + WLM_WARN_BROADCAST_LARGE, + WLM_WARN_SPILL_ON_MEMORY_SPREAD, + WLM_WARN_HASH_CONFLICT +}; + +enum WLMExceptTag { + WLM_EXCEPT_NONE = 0, + WLM_EXCEPT_CPU, + WLM_EXCEPT_SPOOL, + WLM_EXCEPT_QUEUE_TIMEOUT, + WLM_EXCEPT_RUN_TIMEOUT +}; + +struct Qid { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ +}; + +/* user info in the user config file */ +struct WLMUserInfo { + Oid userid; /* user id */ + Oid rpoid; /* resource pool id */ + Oid parentid; /* parent user id */ + int childcount; /* count of the child user */ + int64 space; /* user space */ + int64 spacelimit; /* user space limit */ + int used; /* user info is used */ + bool admin; /* user is admin user? */ + char* children; /* child list string */ +}; + +/* general params */ +struct WLMGeneralParam { + Qid qid; /* a tag of a query */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char ngroup[NAMEDATALEN]; /* node group name */ + unsigned char cpuctrl; /* under cpu control? */ + unsigned char memtrack; /* track memory ? */ + unsigned char iotrack; /* track IO? */ + unsigned char iocontrol; /* need control IO ?*/ + unsigned char infoinit; /* hash tab init */ + unsigned char iostate; /* workload io state*/ + unsigned char complicate; /* query is complicated */ + unsigned char complicate_stream; /* query is complicated & thread is stream */ + unsigned char privilege; /* flags reserved */ + RespoolData rpdata; /* resource pool in use */ + int memsize; /* statement memory size, mb */ + int max_memsize; /*max statement memory size */ + int min_memsize; /* min statement memory size */ + int dopvalue; /* current dop value */ + int iops_limits; /* iops_limits */ + int io_priority; /* io percentage transfered from io_priority */ + int iocount; /* io count */ + void* infoptr; /* a pointer to user info in configure file */ + void* ptr; /* a pointer in general param */ + void* ioptr; /* io info pointer */ + void* rp; /* resource pool */ + void* userdata; /* user data */ + bool use_planA; /* force use plan A*/ +}; + +template +struct WLMDataIndicator { + DataType min_value; + DataType max_value; + DataType total_value; + DataType avg_value; + int skew_percent; +}; + +/* collect user information from DN */ +struct WLMUserCollInfoDetail { + char nodeName[NAMEDATALEN]; /* node name */ + WLMDataIndicator usedMemoryData; /* used memory data */ + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ + int cpuUsedCnt; /* cpu core counts used */ + int cpuTotalCnt; /* cpu core counts used */ + int nodeCount; /* node count */ + int64 totalSpace; /* total used space */ + /* IO flow data */ + uint64 readBytes; /* current readKb for all DN */ + uint64 writeBytes; /* current writeKb for all DN */ + uint64 readCounts; /* current read counts for all DN */ + uint64 writeCounts; /* current write counts for all DN */ + + int64 tmpSpace; /* total used temp space*/ + int64 spillSpace; /* total used spill space*/ +}; + +/* collect realtime info detail */ +struct WLMCollectInfoDetail { + char nodeName[NAMEDATALEN]; /* node name */ + Oid* group_members; /* group members of one node group */ + int group_count; /* group count of one node group */ + + int usedMemory; /* memory used */ + int peakMemory; /* peak memory */ + int spillCount; /* count for spill */ + int warning; /* warning info */ + int nodeCount; /* node count */ + int maxUsedMemory; /* max used memory */ + int avgUsedMemory; /* average used memory */ + int cpuCnt; /* cpu core counts used */ + int64 dnTime; /* query used time on dn */ + uint64 space; /* table space used */ + int64 cpuTime; /* cpu time used */ + + int maxIOUtil; /* max IO util */ + int minIOUtil; /* min IO util */ + int maxCpuUtil; /* max CPU util */ + int minCpuUtil; /* min CPU util */ + + int peak_iops; /* peak iops */ + int curr_iops; /* current iops */ + + int64 spillSize; /* spill size*/ + int64 broadcastSize; /* broadcast size */ + + char misc[NAMEDATALEN]; +}; + +struct WLMGeneralInfo { + int64 totalCpuTime; /* total query cpu time on dn */ + int64 maxCpuTime; /* max query cpu time on dn */ + int64 minCpuTime; /* min query cpu time on dn */ + int64 dnTime; /* query used time on dn */ + + int maxUsedMemory; /* max used memory */ + int maxPeakChunksQuery; /* max peak chunks for query */ + int minPeakChunksQuery; /* min peak chunks for query */ + + int spillCount; /* total spill count */ + int spillNodeCount; /* the count of the data node with spilled */ + int64 spillSize; /* spill size*/ + int64 broadcastSize; /* broadcast size, unit is bytes */ + int64 broadcastThreshold; /* Threshold of broadcast size, unit is bytes */ + + int scanCount; /* scan counter */ + int nodeCount; /* data node counter */ + + uint64 totalSpace; /* total table space */ + WLMActionTag action; /* data node num */ + + char* nodeInfo; /* node info string */ +}; + +struct WLMGeneralData { + WLMDataIndicator peakMemoryData; /* peak memory data */ + WLMDataIndicator usedMemoryData; /* used memory data */ + WLMDataIndicator spillData; /* spill data */ + WLMDataIndicator broadcastData; /* broadcast data */ + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ + WLMDataIndicator dnTimeData; /* query used time on dn */ + WLMDataIndicator cpuData; /* query cpu time on dn */ + + int nodeCount; /* node count */ + int spillNodeCount; /* spill node count */ + int warning; /* warning info */ + + uint64 totalSpace; /* total table space */ + WLMTopDnList* WLMCPUTopDnInfo; /* top5 cpu dn list */ + WLMTopDnList* WLMMEMTopDnInfo; /* top5 mem dn list */ + SlowQueryInfo slowQueryInfo; + List* query_plan; + int tag; +}; + +struct WLMIoGeninfo { + // calculated variable from io_priority + int curr_iops_limit; /* current iops_limits calculated from io_priority*/ + int prio_count_down; /* count down for io_priority 3, 2, 1 */ + int io_count; /* update when write/read is running reset every io_priority gap (0.5, 1, 1.5) */ + int hist_iops_tbl[PAST_TIME_COUNT]; /* history io_count table */ + + // iops collectinfo + int io_count_persec; /* IO count for io_priority*** ----reset every second*/ + int tick_count_down; /* count down for collect info */ + + // iops statistics --update each second + int curr_iops; /* current mean iops */ + int peak_iops; /* peak mean iops */ + + int nodeCount; /* count of node */ + /* IO flow */ + uint64 read_bytes[2]; /* logical read_bytes */ + uint64 write_bytes[2]; /* logical write_bytes */ + uint64 read_counts[2]; /* read operation counts */ + uint64 write_counts[2]; /* write operation counts */ + uint64 group_value[4]; /* used for group user */ + uint64 read_speed; /* read speed */ + uint64 write_speed; /* write speed */ + + TimestampTz timestampTz; /* last timestamp */ + + // the belowing is only updated on CN + WLMDataIndicator currIopsData; /* current iops for all DN */ + WLMDataIndicator peakIopsData; /* peak iops for all DN */ +}; + +/* reply statement info */ +struct WLMStmtReplyDetail { + Oid procId; /* cn id for the statement */ + uint64 queryId; /* query id for statement, it's a session id */ + TimestampTz stamp; /* query time stamp */ + int estimate_memory; /* estimate total memory */ + WLMStatusTag status; /* wlm status of statement */ +}; + +/* statement info */ +struct WLMStmtDetail { + Qid qid; /* qid for query */ + + Oid databaseid; /* database id */ + Oid userid; /* user id */ + uint64 debug_query_id; /* debug query id */ + uint64 plan_size; /* plan size */ + Oid rpoid; /* resource pool oid */ + char respool[NAMEDATALEN]; /* resource pool */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char appname[NAMEDATALEN]; /* application name */ + char* username; /* user name */ + char* schname; /* schema name */ + char* msg; /* statement's message to show */ + char* query_plan_issue; /* query plan issue */ + char* query_plan; /* query plan */ + char* query_band; /* query band */ + char* statement; /* sql statement text */ + char* clienthostname; /* MUST be null-terminated */ + void* clientaddr; /* client address */ + + WLMGeneralInfo geninfo; /* general session info */ + WLMIoGeninfo ioinfo; /* session IO info */ + SlowQueryInfo slowQueryInfo; /* slow query info */ + + ThreadId threadid; /* thread id */ + bool valid; /* detail info is valid? */ + + TimestampTz start_time; /* query start time stamp */ + TimestampTz fintime; /* query finish time stamp */ + TimestampTz exptime; /* record expire time */ + + WLMStatusTag status; /* wlm status of statement */ + int64 block_time; /* query block time */ + int64 estimate_time; /* estimate total time */ + int estimate_memory; /* estimate total memory */ + int warning; /* warning info */ +}; + +/* data node resource info update */ +struct WLMNodeUpdateInfo { + Qid qid; /* id for statement on dn */ + char nodegroup[NAMEDATALEN]; /* node group name */ + unsigned char cpuctrl; /* reference counter */ + WLMGeneralInfo geninfo; /* general info for the dnode collect info */ +}; + +/* data node resource info, it's used on CN and DN */ +struct WLMDNodeInfo { + Qid qid; /* id for statement on dn */ + Oid userid; /* user id */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char schname[NAMEDATALEN]; /* schema name */ + char* statement; /* sql statement text */ + char* qband; /* query band string */ + ThreadId tid; /* cn pid */ + int threadCount; /* a counter of thread */ + unsigned char cpuctrl; /* reference counter */ + unsigned char restrack; /* resource track flag */ + unsigned char flags[2]; /* reserve flags */ + WLMActionTag tag; /* action tag */ + void* mementry; /* session memory entry */ + void* respool; /* resource pool in htab */ + void* userdata; /* user info pointer */ + WLMGeneralInfo geninfo; /* general info for the dnode collect info */ + int64 block_time; /* query block time */ + TimestampTz start_time; /* query start time stamp */ +}; + +struct WLMDNodeIOInfo { + Qid qid; /* id for statement on dn */ + ThreadId tid; /* cn pid */ + WLMActionTag tag; /* action tag */ + char nodegroup[NAMEDATALEN]; /* node group name */ + + // user set GUC variables + int io_priority; /* user set io percent for query */ + int iops_limits; /* user set iops_limits for each query */ + + void* userptr; /* UserData pointer in the htab */ + + int io_state; /* IOSTATE_WRITE? IOSTATE_READ? */ + int threadCount; /* thread attached for the query */ + + WLMIoGeninfo io_geninfo; /* io general info for query */ +}; + +/* data node real time resource info */ +struct WLMDNRealTimeInfoDetail { + Qid qid; /* id for statement on dn */ + + int64 cpuStartTime; /* start cpu time */ + int64 cpuEndTime; /* end cpu time */ + + pid_t tid; /* a key of this detail info, it's a thread id */ + unsigned char cpuctrl; /* cpu control is valid ? */ + unsigned char flags[3]; /* save it in the collect info list? */ + WLMStatusTag status; /* status of the detail info */ +}; + +/* cgroup info */ +struct WLMCGroupInfo { + gscgroup_grp_t* grpinfo; /* cgroup exception infomation */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + bool attaching; /* check the thread whether is attaching a new cgroup */ + bool invalid; /* check the cgroup whether is invalid */ +}; + +/* collect info on cn */ +struct WLMCollectInfo { + WLMStmtDetail sdetail; /* statement info detail */ + + WLMCGroupInfo cginfo; /* control group info */ + + TimestampTz blockStartTime; /* query block start time */ + TimestampTz blockEndTime; /* query block end time for a period of time*/ + TimestampTz execStartTime; /* query exec start time */ + TimestampTz execEndTime; /* query exec end time for a period of time*/ + + int trait; /* trait for exception handler */ + int update; /* reserved */ + + int64 max_mem; /* max memory for thread */ + int64 avail_mem; /* available memory for thread */ + + WLMStatusTag status; /* wlm status of statement */ + WLMActionTag action; /* wlm action for statement process */ + WLMAttrTag attribute; /* wlm attribute of statement */ +}; + +/* exception manager */ +struct ExceptionManager { + TimestampTz blockEndTime; /* statement block end time */ + TimestampTz execEndTime; /* statement execute end time */ + TimestampTz adjustEndTime; /* statement penalty end time for a period of time */ + TimestampTz intvalEndTime; /* interval end time */ + TimestampTz qualiEndTime; /* qualification end time */ + + int max_waiting_time; /* statement max block time */ + int max_running_time; /* statement max execute time */ + int max_adjust_time; /* statement max penalty time */ + int max_interval_time; /* statement max interval time */ + + except_data_t except[EXCEPT_ALL_KINDS]; /* cgroup exception infomation */ +}; + +struct WLMIoStatisticsGenenral { + ThreadId tid; + + int maxcurr_iops; /* max current iops for all DN */ + int mincurr_iops; /* max current iops for all DN */ + + int maxpeak_iops; /* max current iops for all DN */ + int minpeak_iops; /* max current iops for all DN */ + + int iops_limits; + int io_priority; + int curr_iops_limit; /* iops_limit calculated from io_priority*/ +}; + +struct WLMIoStatisticsList { + WLMIoStatisticsGenenral* node; + WLMIoStatisticsList* next; +}; + +/* query runtime info for pg_session_wlmstat */ +struct WLMStatistics { + char stmt[KBYTES]; /* statement */ + int64 blocktime; /* query block time while waiting in the queue */ + int64 elapsedtime; /* elapsed time of the query */ + int64 maxcputime; /* max cpu time of the query */ + int64 totalcputime; /* total cpu time of the query */ + int64 qualitime; /* the qualification time of the query */ + int skewpercent; /* the skew percent of the query */ + int priority; /* priority in the queue */ + int stmt_mem; /* statement memory */ + int act_pts; /* active points */ + int dop_value; /* dop value */ + char cgroup[NAMEDATALEN]; /* control group */ + char srespool[NAMEDATALEN]; /* session_respool */ + char* status; /* status */ + char* action; /* action */ + char* enqueue; /* enqueue state: respool, global or none. */ + char* qtype; /* statement's type, simple or complicated. */ + bool is_planA; /* statement's type, simple or complicated. */ + char groupname[NAMEDATALEN]; /* node group name */ +}; + +/* session history resource info for gs_wlm_session_query_info_all */ +struct WLMSessionStatistics { + char respool[NAMEDATALEN]; /* resource pool */ + char cgroup[NAMEDATALEN]; /* cgroup name */ + char nodegroup[NAMEDATALEN]; /* node group name */ + char spillInfo[16]; /* spill info */ + + WLMGeneralData gendata; /* wlm general data on dn */ + + Qid qid; /* qid for the query */ + Oid databaseid; /* database id */ + Oid userid; /* user id */ + uint64 debug_query_id; /* debug query id */ + TimestampTz start_time; /* query start time stamp */ + TimestampTz fintime; /* query finish time stamp */ + ThreadId tid; /* thread id */ + WLMStatusTag status; /* wlm status of statement */ + int64 block_time; /* query block time */ + int64 estimate_time; /* estimate total time */ + int64 duration; /* query excute time */ + char* query_band; /* query band */ + char* query_plan; /* query plan */ + char* query_plan_issue; /* query plan issue */ + char* err_msg; /* error message */ + char* statement; /* sql statement text */ + char* schname; /* schema name */ + char* appname; /* application name */ + char* clienthostname; /* client host name */ + char* username; /* user name */ + + void* clientaddr; /* client address */ + bool remove; /* remove info from hash table */ + int estimate_memory; /* estimate total memory */ + uint64 n_returned_rows; +}; + +struct WLMSigReceiveData { + char cgroup[NAMEDATALEN]; /* cgroup name */ + pthread_t tid; /* thread id */ + int priority; /* priority of cgroup */ + int used; /* slot is used */ +}; + +typedef struct IOHashCtrl { + int lockId; /* lock id */ + HTAB* hashTable; /* hash tables */ +} IOHashCtrl; + +/* statistics control */ +struct WLMStatManager { + int max_collectinfo_num; /* max collect info num in list */ + int max_statistics_num; /* max collect info num in list */ + int max_iostatinfo_num; /* max iostat info num in list */ + int max_detail_num; /* max session info num in the hash table */ + int index; /* index of the statistics memory */ + int comp_count; /* complicated statement count */ + + unsigned char stop; /* a flag to stop running. */ + unsigned char overwrite; /* check the statistics memory whether is overwritten */ + unsigned char datainit; /* a flag to check collect_info_hashtbl whether has record. */ + unsigned char remain; + + char user[NAMEDATALEN]; /* user name to use in the backend thread */ + char mon_user[NAMEDATALEN]; /* user name to use in wlm monitor thread */ + + char database[NAMEDATALEN]; /* database name to use in the backend thread */ + + char execdir[STAT_PATH_LEN]; /* the path for binaries */ + char datadir[STAT_PATH_LEN]; /* the path for log */ + + unsigned int infoinit; /* htab init ok */ + unsigned int sendsig; /* send signal */ + + TimestampTz scanEndTime; /* a timer for collect data persistence */ + + ThreadId thread_id; /* backend thread id */ + + HTAB* collect_info_hashtbl; /* collect information hash table */ + HTAB* session_info_hashtbl; /* session fino hash table for the query finished */ + HTAB* user_info_hashtbl; /* user info hash tbale */ + IOHashCtrl* iostat_info_hashtbl; /* iostat info control */ + HTAB* node_group_hashtbl; /* node group hash table */ + HASH_SEQ_STATUS collect_info_seq; /* collect info hash table seq */ + HASH_SEQ_STATUS iostat_info_seq; /* collect info hash table seq */ + + WLMStatistics* statistics; /* the pointer to statistics memory */ + WLMSigReceiveData* recvdata; /* received data */ + + WLMUserInfo** userinfo; /* user info list */ + + pthread_mutex_t statistics_mutex; /* mutex to lock the statistics list */ + pthread_mutex_t collectinfo_list_mutex; /* mutex to lock the list */ +}; + +/* Structures for I/O stats. */ +struct DiskIOStats { + unsigned long long total_io; /* total io operation */ + unsigned long read_sectors; /* read sectors */ + unsigned long write_sectors; /* write sectors */ + unsigned long read_io; /* read io operation */ + unsigned long read_merges; /* read requests merged */ + unsigned long write_io; /* write io operation */ + unsigned long write_merges; /* write requests merged */ + unsigned int read_ticks; /* Time of read requests in queue */ + unsigned int write_ticks; /* Time of write requests in queue */ + unsigned int discard_ticks; /* Time of discard requests in queue */ + unsigned int total_ticks; /* total ticks */ + unsigned int queue_ticks; /* Time of ticks requests spent in queue */ +}; + +/* I/O stats calculcate result. */ +struct DiskIOStatsMetric { + double rsectors; /* rsec/s */ + double wsectors; /* wsec/s */ + double util; /* disk util */ + double await; /* disk await */ +}; + +/* dn instance info */ +typedef struct WLMInstanceInfo { + TimestampTz timestamp; /* timestamp */ + double usr_cpu; /* userspace cpu usage */ + double sys_cpu; /* system cpu usage */ + int free_mem; /* instance free mem, max_process_mem - process_used_memory */ + int used_mem; /* instance used mem */ + double io_await; /* disk io_await */ + double io_util; /* disk io_util */ + double disk_read; /* disk read speed */ + double disk_write; /* disk write speed */ + uint64 process_read_speed; /* gaussdb process read speed */ + uint64 process_write_speed; /* gaussdb process write speed */ + uint64 read_counts; /* logical read counts */ + uint64 write_counts; /* logical write counts */ + uint64 logical_read_speed; /* logical read speed */ + uint64 logical_write_speed; /* logical write speed */ +} WLMInstanceInfo; + +/* dn instance statistics control */ +typedef struct WLMInstanceStatManager { + int max_stat_num; /* max stat info num in list */ + int collect_interval; /* the collect info interval */ + int persistence_interval; /* the persistence interval */ + int cleanup_interval; /* the cleanup history info interval */ + + char instancename[NAMEDATALEN]; /* dn instance name */ + char diskname[MAX_DEVICE_LEN]; /* the dn diskname */ + + uint64 totalCPUTime[2]; /* total time of the cpu,0 is old value,1 is new value */ + uint64 userCPUTime[2]; /*cpu time of the process user mode,0 is old value,1 is new value*/ + uint64 sysCPUTime[2]; /*cpu time of the process systerm mode,0 is old value,1 is new value*/ + + unsigned long long uptime[2]; /* uptime array */ + DiskIOStats device[2]; /* dev statistics */ + + uint64 process_read_bytes[2]; /* gaussdb process read bytes */ + uint64 process_write_bytes[2]; /* gaussdb process write bytes */ + + uint64 logical_read_bytes[2]; /* logical write bytes */ + uint64 logical_write_bytes[2]; /* logical write bytes */ + + uint64 read_counts[2]; /* logical read counts */ + uint64 write_counts[2]; /* logical write counts */ + + TimestampTz last_timestamp; /* a timer for collect data*/ + TimestampTz recent_timestamp; /* a timer for collect data*/ + + HTAB* instance_info_hashtbl; /* instance info hash table */ +} WLMInstanceStatManager; + +/* process wlm workload manager */ +extern int WLMProcessWorkloadManager(); +/* get hashCode of io statistics from qid */ +extern uint32 GetIoStatBucket(const Qid* qid); +/* get lockId of io statistics from hashCode */ +extern int GetIoStatLockId(const uint32 bucket); +/* initialize stat info */ +extern void WLMInitializeStatInfo(); +/* set stat info */ +extern void WLMSetStatInfo(const char*); +/* reset stat info for exception */ +extern void WLMResetStatInfo4Exception(); +/* generate a hash code by a key */ +extern uint32 WLMHashCode(const void* key, Size keysize); +/* set collect info status to finished */ +extern void WLMSetCollectInfoStatusFinish(); +/* set collect info status */ +extern void WLMSetCollectInfoStatus(WLMStatusTag); +/* create collect info on datanodes */ +extern void WLMCreateDNodeInfoOnDN(const QueryDesc*); +/* get wlm backend state */ +extern void WLMGetStatistics(TimestampTz*, TimestampTz*, WLMStatistics*); +/* get wlm statistics for handling exception */ +extern WLMStatistics* WLMGetStatistics(int*); +/* initialize worker thread */ +extern void WLMWorkerInitialize(struct Port*); +/* worker thread main function */ +extern int WLMProcessThreadMain(); +/* shut down the worker thread*/ +extern void WLMProcessThreadShutDown(); +/* get session info */ +extern void* WLMGetSessionInfo(const Qid* qid, int removed, int* num); +/* get instance info */ +extern void* WLMGetInstanceInfo(int* num, bool isCleanup); +/* plan list format string */ +extern char* PlanListToString(const List* query_plan); +/* get session info from each data nodes */ +extern char* WLMGetSessionLevelInfoInternal(Qid* qid, WLMGeneralInfo* geninfo); +/* get wlm session statistics */ +extern void* WLMGetSessionStatistics(int* num); +/* get wlm session io statistics */ +extern void* WLMGetIoStatistics(int* num); +/* switch cgroup with cn thread id */ +extern bool WLMAjustCGroupByCNSessid(uint64 sess_id, const char* cgroup); +extern void WLMAdjustCGroup4EachThreadOnDN(WLMDNodeInfo* info); +/* get spill info string */ +extern char* WLMGetSpillInfo(char* spillInfo, int size, int spillNodeCount); +/* get warn info string */ +extern void WLMGetWarnInfo(char* warnInfo, int size, unsigned int warn_bit, int spill_size, int broadcast_size, + WLMSessionStatistics* session_stat = NULL); +/* get skew ratio of datanodes */ +extern int GetSkewRatioOfDN(const WLMGeneralInfo* pGenInfo); +/* get each datanode session info for a thread */ +extern WLMCollectInfoDetail* WLMGetSessionInfo4Thread(ThreadId threadid, int* num); +/* parse node info string */ +extern void WLMParseInfoString(const char* infostr, WLMCollectInfoDetail* detail); +/* parse collect info string */ +extern void WLMParseFunc4CollectInfo(StringInfo msg, void* suminfo, int size); +/* alloc function for hash table */ +extern void* WLMAlloc0NoExcept4Hash(Size size); +/* check user info htab init is ok */ +extern bool WLMIsInfoInit(void); +/* get user info from the user config */ +extern WLMUserInfo* WLMGetUserInfoFromConfig(Oid uid, bool* found); +/* get user cgroup cpu util */ +extern int WLMGetGroupCpuUtil(char* nodegroup, void* handles, const char* cgroup); + +extern uint32 WLMHashCode(const void* key, Size keysize); +extern int WLMHashMatch(const void* key1, const void* key2, Size keysize); +extern bool IsQidInvalid(const Qid* qid); +extern bool IsQidEqual(const Qid* qid1, const Qid* qid2); +extern void WLMLocalInfoCollector(StringInfo msg); +extern void WLMAdjustCGroup4EachThreadOnDN(WLMDNodeInfo* info); +extern void WLMCreateIOInfoOnDN(void); +extern WLMIoStatisticsList* WLMGetIOStatisticsGeneral(); +extern void WLMCleanUpIoInfo(void); +extern void WLMUpdateCgroupCPUInfo(void); +extern void WLMInitTransaction(bool* backinit); +extern void WLMInitPostgres(); +extern void WLMCleanIOHashTable(); +extern void WLMSetBuildHashStat(int status); +extern bool WLMIsQueryFinished(void); +extern void WLMReadjustAllUserSpace(Oid uid); +extern void WLMReadjustUserSpaceThroughAllDbs(const char* username); +extern void WLMReadjustUserSpaceByNameWithResetFlag(const char* username, bool resetFlag); +extern WLMCollectInfoDetail* WLMGetUserSessionInfo4Thread(const char* uname, int* num); +extern void WLMSetExecutorStartTime(void); +extern bool WLMIsDumpActive(const char* sql); +extern void WLMCheckSigRecvData(void); +extern char* GetStatusName(WLMStatusTag tag); + +extern char* WLMGetExceptWarningMsg(WLMExceptTag tag); +extern int64 WLMGetTimestampDuration(TimestampTz start, TimestampTz end); +extern void WLMInitQueryPlan(QueryDesc* queryDesc, bool isQueryDesc = true); +extern double WLMGetTotalCost(const QueryDesc* desc, bool isQueryDesc); +extern int WLMGetQueryMem(const QueryDesc* desc, bool isQueryDesc, bool max = true); +extern bool WLMGetInComputePool(const QueryDesc* desc, bool isQueryDesc); +extern int WLMGetMinMem(const QueryDesc* desc, bool isQueryDesc, bool max = true); +extern int WLMGetAvailbaleMemory(const char* ngname); +extern bool WLMChoosePlanA(PlannedStmt* stmt); +extern void WLMGetWorkloadStruct(StringInfo strinfo); +extern void WLMDefaultXactReadOnlyCheckAndHandle(void); +extern void WLMTopSQLReady(QueryDesc* queryDesc); + +#define WORKLOAD_STAT_HASH_SIZE 64 +// default database name +#define DEFDBNAME "postgres" + +#ifdef ENABLE_UT +void ut_to_update(void*); +#endif + +#endif diff -uprN postgresql-hll-2.14_old/include/workload/workload.h postgresql-hll-2.14/include/workload/workload.h --- postgresql-hll-2.14_old/include/workload/workload.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/include/workload/workload.h 2020-12-12 17:06:43.416350219 +0800 @@ -0,0 +1,603 @@ +/* + * 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. + * --------------------------------------------------------------------------------------- + * + * workload.h + * definitions for workload manager + * + * IDENTIFICATION + * src/include/workload/workload.h + * + * --------------------------------------------------------------------------------------- + */ + +#ifndef WORKLOAD_H +#define WORKLOAD_H + +#include "postgres.h" +#include "knl/knl_variable.h" + +#include "gs_threadlocal.h" +#include "nodes/parsenodes.h" +#include "nodes/nodes.h" +#include "nodes/plannodes.h" +#include "utils/datetime.h" +#include "utils/portal.h" +#include "utils/palloc.h" +#include "postmaster/postmaster.h" + +#include "workload/gscgroup.h" +#include "workload/ctxctl.h" +#include "workload/parctl.h" +#include "workload/statctl.h" +#include "workload/memctl.h" +#include "workload/dywlm_client.h" +#include "workload/dywlm_server.h" +#include "workload/ioschdl.h" +#include "workload/cpwlm.h" + +#define FULL_PERCENT 100 +#define OTHER_USED_PERCENT 60 /* 60 aviable memory for other uses */ + +#define STATEMENT_MIN_MEM 256 /*MB*/ +#define STATEMETN_MIN_MODIFY_MEM 2 * 1024 /*MB, 2gb*/ +#define MEM_THRESHOLD 32 /*MB*/ +#define SIMPLE_THRESHOLD (32 * 1024) /* 32MB */ +#define HOLD_NODE_GROUP(group) gs_lock_test_and_set((int*)&group->used, 1) +#define RESUME_NODE_GROUP(group) gs_lock_test_and_set((int*)&group->used, 0) + +#define NodeGroupIsDefault(group) (NULL == (void*)group || *group == '\0' || strcmp(group, "installation") == 0) + +#define ENABLE_WORKLOAD_CONTROL \ + (u_sess->attr.attr_resource.use_workload_manager || u_sess->attr.attr_resource.bypass_workload_manager) + +#define DY_MEM_ADJ(stmt) \ + g_instance.wlm_cxt->dynamic_workload_inited&& t_thrd.wlm_cxt.parctl_state.enqueue && \ + (stmt)->query_mem[0] >= MEM_THRESHOLD * 1024L +#define ASSIGNED_QUERY_MEM(mem, max_mem) ((max_mem) > 0 ? Min((mem), (max_mem)) : (mem)) +#define VALID_QUERY_MEM() \ + (ASSIGNED_QUERY_MEM(u_sess->attr.attr_sql.statement_mem, u_sess->attr.attr_sql.statement_max_mem) > 0) + +extern THR_LOCAL bool log_workload_manager; + +typedef enum CGSwitchState { CG_ORIGINAL = 0, CG_USERSET, CG_USING, CG_RESPOOL } CGSwitchState; + +typedef enum DataSpaceType { SP_PERM = 0, SP_TEMP, SP_SPILL } DataSpaceType; + +typedef struct UserData { + Oid userid; /* user id */ + bool is_super; /* user is admin user */ + bool is_dirty; /* userinfo is dirty, temorarily used in BuildUserInfoHash*/ + unsigned char adjust; /* adjust space flag */ + unsigned char keepdata; /* keep memory size */ + int64 totalspace; /* user used total space */ + int64 global_totalspace; /* user used total space on all cns and dns in bytes*/ + int64 reAdjustPermSpace; /* for wlm_readjust_user_space */ + int64 spacelimit; /* user space limit in bytes*/ + bool spaceUpdate; /* user used total space or temp space updated ? */ + int64 tmpSpace; /* user used temp space in bytes */ + int64 globalTmpSpace; /* user used temp space on all cns and dns in bytes */ + int64 reAdjustTmpSpace; /* for wlm_readjust_user_space */ + int64 tmpSpaceLimit; /* user temp space limit in bytes */ + int64 spillSpace; /* user used spill space in bytes */ + int64 globalSpillSpace; /* user used spill space on all cns and dns in bytes */ + int64 spillSpaceLimit; /* user spill space limit in bytes */ + Oid rpoid; /* resource pool in htab */ + int memsize; /* user used memory */ + int usedCpuCnt; /* average used CPU counts */ + int totalCpuCnt; /* average total CPU counts */ + volatile int referenceCnt; /* reference count, avoid wrong remove */ + ResourcePool* respool; /* resource pool in htab */ + UserData* parent; /* parent user data in htab */ + List* childlist; /* child list */ + WLMUserInfo* infoptr; /* user info */ + int query_count; /* how many IO complicated queries are active now */ + WLMIoGeninfo ioinfo; /* io info*/ + pthread_mutex_t mutex; /* entry list mutex */ + List* entry_list; /* session entry list */ + + int compare(const Oid* userid) + { + if (this->userid == *userid) + return 0; + + return ((this->userid < *userid) ? 1 : -1); + } +} UserData; + +/* used for BuildUserInfoHash function, avoid dead lock */ +typedef struct TmpUserData { + Oid userid; /* user id */ + Oid puid; /* parent id */ + bool is_super; /* user is admin user */ + bool is_dirty; /* userinfo is dirty, temorarily used in BuildUserInfoHash*/ + int64 spacelimit; /* user space limit in bytes*/ + int64 tmpSpaceLimit; /* user temp space limit in bytes */ + int64 spillSpaceLimit; /* user spill space limit in bytes */ + Oid rpoid; /* resource pool in htab */ + ResourcePool *respool; /* resource pool in htab */ +} TmpUserData; + +typedef struct UserResourceData { + Oid userid; /* user oid */ + int total_memory; /* user total memroy */ + int used_memory; /* user used memory */ + int total_cpuset; /* user total cpuset */ + int used_cpuset; /* user used cpuset */ + int64 total_space; /* user total space limit */ + int64 used_space; /* user used space */ + int64 total_temp_space; /* user total temp space limit */ + int64 used_temp_space; /* user used temp space */ + int64 total_spill_space; /* user total spill space limit */ + int64 used_spill_space; /* user used spill space */ + + /* io collect information for user */ + int mincurr_iops; /* user min current iops */ + int maxcurr_iops; /* user max current iops */ + int minpeak_iops; /* user min peak iops */ + int maxpeak_iops; /* user max peak iops */ + + int iops_limits; /* iops_limits for user */ + int io_priority; /* io_priority for user */ + int curr_iops_limit; /* iops_limit calculated from io_priority */ + /* IO flow data */ + uint64 read_bytes; /* read bytes during the monitor interval */ + uint64 write_bytes; /* write bytes during the monitor interval */ + uint64 read_counts; /* read counts during the monitor interval */ + uint64 write_counts; /* write counts during the monitor interval */ + uint64 read_speed; /* read speed */ + uint64 write_speed; /* write speed */ +} UserResourceData; + +typedef struct WLMNodeGroupInfo { + char group_name[NAMEDATALEN]; /* node group name */ + + int used_memory; /* node used memory */ + int total_memory; /* node total memory */ + int estimate_memory; /* node estimate memory */ + + int min_freesize; /* minimum free size of nodes */ + + unsigned int used; /* if it is in use */ + + ClientDynamicManager climgr; /* client manager */ + ServerDynamicManager srvmgr; /* server manager */ + ParctlManager parctl; /* static parallel manager */ + + gscgroup_grp_t* vaddr[GSCGROUP_ALLNUM]; /* control group info */ + HTAB* cgroups_htab; /* cgroup hash table of the node group */ + pthread_mutex_t cgroups_mutex; /* not used */ + + List* node_list; /* node list of the node group */ + + ResourcePool* foreignrp; /* foreign resource pool */ + + bool is_dirty; /* the node group is dirty */ + +} WLMNodeGroupInfo; + +/* debug info */ +typedef struct WLMDebugInfo { + WLMGeneralParam* wparams; /* debug info for general params */ + ExceptionManager* statctl; /* debug info for statctl manager */ + WLMCollectInfo* colinfo; /* debug info for collect info */ + + ParctlState* pstate; /* debug info for parctl state */ + ParctlManager* parctl; /* debug info for parctl manager */ + ClientDynamicManager* climgr; /* debug info for client manager */ + ServerDynamicManager* srvmgr; /* debug info for server manager */ + + int active_statement; + bool* reserved_in_transaction; + +} WLMDebugInfo; + +typedef struct knl_g_wlm_context { + /* The default node group when there is no logical cluster */ + WLMNodeGroupInfo MyDefaultNodeGroup; + + /* the node group information for foreign users */ + WLMNodeGroupInfo* local_dn_nodegroup; + + /* the global variable of workload manager memory context */ + MemoryContext workload_manager_mcxt; + + /* the global variable of query resource track memory context */ + MemoryContext query_resource_track_mcxt; + + /* the global variable of operator resource track memory context */ + MemoryContext oper_resource_track_mcxt; + + /* stat manager */ + WLMStatManager stat_manager; + + /* dn instance statistics manager */ + WLMInstanceStatManager instance_manager; + + /* resource pool is stored in this hash table*/ + HTAB* resource_pool_hashtbl; + + /* flag to enable dynamic workload */ + bool dynamic_workload_inited; + + /* Dynamic DNs memory collected flag */ + bool dynamic_memory_collected = false; + + /* the memory unused in parallel control */ + int parctl_process_memory; + + /* cgroup initialized completed */ + int gscgroup_init_done; + + /* config parsed completed */ + int gscgroup_config_parsed; + + /* CPU count */ + int gscgroup_cpucnt; + + /* the node group for local datanode */ + char local_dn_ngname[NAMEDATALEN]; + + /* configure file */ + gscgroup_grp_t* gscgroup_vaddr[GSCGROUP_ALLNUM]; + + /* vacuum cgroup structure */ + struct cgroup* gscgroup_vaccg; + + /* default backend cgroup structure */ + struct cgroup* gscgroup_bkdcg; + + /* root cgroup structure */ + struct cgroup* gscgroup_rootcg; + + /* default workload cgroup structure */ + struct cgroup* gscgroup_defwdcg; + + /* default topwd cgroup structure */ + struct cgroup* gscgroup_deftopwdcg; + + /* used for io scheduler */ + WLMIOContext io_context; + + // cluster state + struct DNState* cluster_state; + + // dn count in cluster state + int dnnum_in_cluster_state; + + // indicate if the node is cnn + bool is_ccn; + + // the index count of cnn + int ccn_idx; + + /* record the resource package number in datanode */ + int rp_number_in_dn; +} knl_g_wlm_context; + +typedef struct knl_u_wlm_context { + /* save the Cgroup name */ + char control_group[NAMEDATALEN]; + + /* indicate if the name of control_group has changed */ + CGSwitchState cgroup_state; + + /* save control group switch status */ + gscgroup_stmt_t cgroup_stmt; + gscgroup_stmt_t cgroup_last_stmt; + + /* if the session resource pool is changed */ + bool session_respool_switch; + + /* session_respool is initialized or not */ + bool session_respool_initialize; + + /* get is_foreign for updating hash table */ + bool respool_is_foreign; + + /* flag to update user hash table */ + bool wlmcatalog_update_user; + + /*cancel job due to workload manager exception*/ + bool cancel_from_wlm; + + /*cancel job due to space limitation*/ + bool cancel_from_space_limit; + + /*cancel job due to transcation readonly */ + bool cancel_from_defaultXact_readOnly; + + /* save the session_respool name */ + char session_respool[NAMEDATALEN]; + + /* get oid of the created resource pool for updating hash table */ + Oid respool_create_oid; + + /* get oid of the altered resource pool for updating hash table */ + Oid respool_alter_oid; + + /*record last stmt session respool*/ + Oid respool_old_oid; + + /* get oid list of the resource pool dropping list for updating hash table */ + List* respool_delete_list; + + /* mempct for updating hash table */ + int respool_foreign_mempct; + + /* actual percent for updating hash table */ + int respool_foreign_actpct; + + /* parentid for updating hash table */ + Oid respool_parentid; + + /* get io_limits for updating hash table */ + int32 respool_io_limit_update; + + /* get io_priority for updating hash table */ + char respool_io_pri_update[NAMEDATALEN]; + + /* get io_priority for updating hash table */ + char respool_nodegroup[NAMEDATALEN]; + + /* get io_priority for updating hash table */ + char respool_controlgroup[NAMEDATALEN]; + + /* which node group resource pool belong to */ + WLMNodeGroupInfo* respool_node_group; + + /* local foreign respool */ + ResourcePool* local_foreign_respool; + + /* workload debug info */ + WLMDebugInfo wlm_debug_info; + + /* workload session info */ + WLMGeneralParam wlm_params; + + /* the num of streams' thread */ + int wlm_num_streams; + + /* the keyname of the control group */ + char group_keyname[GPNAME_LEN]; + + /* indicate if it is in transcation */ + bool is_reserved_in_transaction; + + /* indicate if the parallel queue is reset */ + bool is_active_statements_reset; + + /* indicate if the query is forced to run */ + bool forced_running; + + /* indicate if the query has running one time */ + bool query_count_record; + + /* record if the computing pool task is running */ + bool cp_task_running; + + /* reserved count in global active statements */ + int reserved_in_active_statements; + + /* reserved count in resource pool active statements */ + int reserved_in_group_statements; + + /* reserved count for simple query in resource pool active statements */ + int reserved_in_group_statements_simple; + + /* the count which is waiting in resouce pool */ + int reserved_in_respool_waiting; + + int reserved_in_central_waiting; + + /* used to record the user when inserting data */ + UserData* spmgr_userdata; + + HTAB* TmptableCacheHash; + + /* computing pool runtime information */ + CPRuntimeInfo* cp_runtime_info; + + /* Track storage usage in bytes at individual thread level when space increasing */ + uint64 spmgr_space_bytes; + + /* Mark query reach the spill limit */ + bool spill_limit_error; + + /* user pl */ + int64 wlm_userpl; + + /* the reserved query string */ + char reserved_debug_query[1024]; + + unsigned char stroedproc_rp_reserve; + + unsigned char stroedproc_rp_release; + + unsigned char stroedproc_release; + + /* mark the session already do paralle control */ + unsigned char parctl_state_control; + + /* mark the session already exit */ + unsigned char parctl_state_exit; +} knl_u_wlm_context; + +extern void dywlm_client_init(WLMNodeGroupInfo*); +extern void dywlm_server_init(WLMNodeGroupInfo*); +extern void WLMParctlInit(WLMNodeGroupInfo*); +extern void InitializeWorkloadManager(void); + +extern void SetCpuAffinity(int64 setting); + +extern void WLMSetControlGroup(const char* cgname); +extern gscgroup_stmt_t WLMIsSpecialCommand(const Node* parsetree, const Portal); +extern bool WLMIsSimpleQuery(const QueryDesc* queryDesc, bool force_control, bool isQueryDesc); +extern bool WLMNeedTrackResource(const QueryDesc* queryDesc); +extern bool WLMIsSpecialQuery(const char* query); +extern unsigned char WLMCheckToAttachCgroup(const QueryDesc* queryDesc); +extern void WLMSetUserInfo(); +extern void GetCurrentCgroup(char* cgroup, const char* curr_group, int len); +extern void WLMSwitchCGroup(void); +extern char* GetMemorySizeWithUnit(char* memory, int size, int memsize); +extern bool CheckWLMSessionInfoTableValid(const char* tablename); +extern WLMUserInfo* WLMGetUserInfo(Oid userid, WLMUserInfo* info); +extern int ParseUserInfoConfigFile(void); +extern UserData* GetUserDataFromHTab(Oid roleid, bool is_noexcept); +extern bool BuildUserRPHash(void); +extern void* WLMGetAllUserData(int* num); /* get all user data from htab */ +extern void WLMReAdjustUserSpace(UserData* userdata, bool isForce = false); +extern char* GenerateResourcePoolStmt(CreateResourcePoolStmt* stmt, const char* origin_query); + +extern void CreateResourcePool(CreateResourcePoolStmt* stmt); +extern void AlterResourcePool(AlterResourcePoolStmt* stmt); +extern void RemoveResourcePool(Oid pool_oid); +extern void DropResourcePool(DropResourcePoolStmt* stmt); + +extern void CreateWorkloadGroup(CreateWorkloadGroupStmt* stmt); +extern void AlterWorkloadGroup(AlterWorkloadGroupStmt* stmt); +extern void RemoveWorkloadGroup(Oid group_oid); +extern void DropWorkloadGroup(DropWorkloadGroupStmt* stmt); + +extern void CreateAppWorkloadGroupMapping(CreateAppWorkloadGroupMappingStmt* stmt); +extern void AlterAppWorkloadGroupMapping(AlterAppWorkloadGroupMappingStmt* stmt); +extern void RemoveAppWorkloadGroupMapping(Oid app_oid); +extern void DropAppWorkloadGroupMapping(DropAppWorkloadGroupMappingStmt* stmt); + +extern bool UsersInOneGroup(UserData* user1, UserData* user2); +extern void CheckUserRelation(Oid roleid, Oid parentid, Oid rpoid, bool isDefault, int issuper); +extern int UserGetChildRoles(Oid roleid, DropRoleStmt* stmt); +extern void GetUserDataFromCatalog(Oid userid, Oid* rpoid, Oid* parentid, bool* issuper, int64* spacelimit, + int64* tmpspacelimit, int64* spillspacelimit, char* groupname = NULL, int lenNgroup = 0); +extern bool GetUserChildlistFromCatalog(Oid userid, List** childlist, bool findall); +extern UserResourceData* GetUserResourceData(const char* username); +extern void CheckUserSpaceLimit(Oid roleid, Oid parentid, int64 spacelimit, int64 tmpspacelimit, + int64 spillspacelimit, bool is_default, bool changed, bool tmpchanged, bool spillchanged); +extern ResourcePool* GetRespoolFromHTab(Oid rpoid, bool is_noexcept = true); +extern void perm_space_increase(Oid ownerID, uint64 size, DataSpaceType type); +extern void perm_space_decrease(Oid ownerID, uint64 size, DataSpaceType type); +extern void perm_space_value_reset(void); +extern bool SearchUsedSpace(Oid userID, int64* permSpace, int64* tempSpace); +extern void UpdateUsedSpace(Oid userID, int64 permSpace, int64 tempSpace); + +extern void CheckUserInfoHash(); +extern void UpdateWlmCatalogInfoHash(void); +extern void ResetWlmCatalogFlag(void); +extern unsigned int GetRPMemorySize(int pct, Oid parentid); + +extern void WLMCheckSessionRespool(const char* respool); +extern void WLMSetSessionRespool(const char* respool); + +extern int WLMGetUserMemory(UserData* userdata); +extern void WLMCheckSpaceLimit(void); +extern WLMNodeGroupInfo* WLMGetNodeGroupFromHTAB(const char* group_name); +extern WLMNodeGroupInfo* WLMMustGetNodeGroupFromHTAB(const char* group_name); +extern WLMNodeGroupInfo* WLMGetNodeGroupByUserId(Oid userid); +extern WLMNodeGroupInfo* CreateNodeGroupInfoInHTAB(const char* group_name); +extern void RemoveNodeGroupInfoInHTAB(const char* group_name); +extern void WLMInitNodeGroupInfo(WLMNodeGroupInfo* info); + +/* get debug info string */ +extern void WLMGetDebugInfo(StringInfo strinfo, WLMDebugInfo* debug_info); +/* init cgroup */ +extern void gscgroup_init(void); + +/* free cgroup */ +extern void gscgroup_free(void); + +/* get the percent of specified group */ +extern int gscgroup_get_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* attach task into cgroup */ +extern void gscgroup_attach_task(WLMNodeGroupInfo* ng, const char* gname); + +/* attach batch task into cgroup with tid */ +extern int gscgroup_attach_task_batch(WLMNodeGroupInfo* ng, const char* gname, pid_t tid, int* is_first); + +/* attach backend task into cgroup */ +extern int gscgroup_attach_backend_task(const char* gname, bool is_noexcept); + +/* check if the group has been set */ +extern int gscgroup_check_group_name(WLMNodeGroupInfo* ng, const char* gname); + +/* check if the node in the waiting list need switch */ +extern int gscgroup_check_group_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* switch cgroup */ +extern bool WLMAjustCGroupByCNSessid(WLMNodeGroupInfo* ng, uint64 sess_id, const char* cgroup); + +/* get cgroup name from cgroup */ +char* gsutil_get_cgroup_name(struct cgroup* cg); + +/* get the group configuration information */ +extern gscgroup_grp_t* gscgroup_get_grpconf(WLMNodeGroupInfo* ng, const char* gname); + +/* check if the cgroup is class cgroup */ +extern int gscgroup_is_class(WLMNodeGroupInfo* ng, const char* gname); + +/* switch to TopWD cgroup */ +extern void gscgroup_switch_topwd(WLMNodeGroupInfo* ng); + +/* Back to Current cgroup */ +extern void gscgroup_switch_vacuum(void); + +/* update the hash table */ +extern void gscgroup_update_hashtbl(WLMNodeGroupInfo* ng, const char* keyname); + +/* get group entry from hash table */ +extern gscgroup_entry_t* gscgroup_lookup_hashtbl(WLMNodeGroupInfo* ng, const char* name); + +/* get the next group */ +extern int gscgroup_get_next_group(WLMNodeGroupInfo* ng, char* gname); + +/* get the top group name */ +extern char* gscgroup_get_top_group_name(WLMNodeGroupInfo* ng, char* gname, int len); + +/* look up cgroup from htab */ +extern struct cgroup* gscgroup_lookup_cgroup(WLMNodeGroupInfo* ng, const char* gname, bool* found = NULL); + +/* update cgroup cpu info */ +extern void gscgroup_update_hashtbl_cpuinfo(WLMNodeGroupInfo* ng); + +/* get cgroup info */ +extern gscgroup_info_t* gscgroup_get_cgroup_info(int* num); + +/* get cgroup cpu info */ +extern void gscgroup_get_cpuinfo(gscgroup_entry_t* entry); + +/* get cpu usage percent */ +extern int gscgroup_get_cpu_usage_percent(WLMNodeGroupInfo* ng, const char* gname); + +/* check the cgroups whether are in the same class */ +extern bool gscgroup_is_brother_group(const char* cgroup1, const char* cgroup2); + +/* check whether parentcg is parent cgroup of childcg */ +extern bool gscgroup_is_child_group(const char* parentcg, const char* childcg); + +/* check whether gname is timeshare or not */ +extern int gscgroup_is_timeshare(const char* gname); + +/* convert cgroup name to tthe name without level info */ +extern char* gscgroup_convert_cgroup(char* gname); + +/* check Cgroup percent */ +extern int WLMCheckCgroupPercent(WLMNodeGroupInfo* ng, const char*); + +/* move node to list */ +extern void WLMMoveNodeToList(WLMNodeGroupInfo* ng, ThreadId tid, const char* cgroup); + +/* release active statements while proc exiting */ +extern void WLMReleaseAtThreadExit(); + +#endif Binary files postgresql-hll-2.14_old/libhll.so and postgresql-hll-2.14/libhll.so differ diff -uprN postgresql-hll-2.14_old/Makefile postgresql-hll-2.14/Makefile --- postgresql-hll-2.14_old/Makefile 2019-11-15 18:39:18.000000000 +0800 +++ postgresql-hll-2.14/Makefile 2020-12-12 17:06:43.417350232 +0800 @@ -1,44 +1,20 @@ -# Copyright 2013 Aggregate Knowledge, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -EXTENSION = hll -EXTVERSIONS = 2.10 2.11 2.12 2.13 2.14 +#top_builddir := $(shell pwd)/../../../../GaussDBKernel-server +#include $(top_builddir)/src/Makefile.global -DATA_built = $(foreach v,$(EXTVERSIONS),$(EXTENSION)--$(v).sql) -DATA = $(wildcard $(EXTENSION)--*--*.sql) +#PLAT_FORM_STR = $(shell sh ${PWD}/../../../build/get_PlatForm_str.sh) -MODULE_big = $(EXTENSION) -OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c)) $(patsubst %.cpp,%.o,$(wildcard src/*.cpp)) +CPPFLAGS := -I./include +#ifndef PG_CONFIG +#PG_CONFIG = pg_config +#endif +#PGXS := $(shell $(PG_CONFIG) --pgxs) +#include $(PGXS) +#CPPFLAGS += -I$(top_builddir)/../binarylibs/${PLAT_FORM_STR}/openssl/comm/include + +#LDFLAGS := -I$(top_builddir)/../binarylibs/${PLAT_FORM_STR}/cjson/comm/lib +#LDFLAGS += -I$(top_builddir)/../Platform/${PLAT_FORM_STR}/libobs/comm/lib +#LDFLAGS += -I$(top_builddir)/../binarylibs/${PLAT_FORM_STR}/kerberos/comm/lib -PG_CPPFLAGS = -fPIC -Wall -Wextra -Werror -Wno-unused-parameter -Wno-implicit-fallthrough -Iinclude -I$(libpq_srcdir) +all: + g++ -std=c++11 -DPGXC -Wall -Werror -Wendif-labels -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wno-write-strings -Wno-attributes -Wno-unused-but-set-variable -fstack-protector -s -D_FORTIFY_SOURCE=2 -O2 -fno-strict-aliasing -fno-common -pipe -Wl,-z,relro,-z,now $(CPPFLAGS) ./hll.cpp ./MurmurHash3.cpp -fpic -shared $(LDFLAGS) -o libhll.so -REGRESS = setup $(filter-out setup,$(patsubst sql/%.sql,%,$(sort $(wildcard sql/*.sql)))) - -PG_CONFIG ?= pg_config -PGXS = $(shell $(PG_CONFIG) --pgxs) -include $(PGXS) - -SHLIB_LINK += -lstdc++ - -src/hll.o: override CFLAGS += -std=c99 - -$(EXTENSION)--2.10.sql: $(EXTENSION).sql - cat $^ > $@ -$(EXTENSION)--2.11.sql: $(EXTENSION)--2.10.sql $(EXTENSION)--2.10--2.11.sql - cat $^ > $@ -$(EXTENSION)--2.12.sql: $(EXTENSION)--2.11.sql $(EXTENSION)--2.11--2.12.sql - cat $^ > $@ -$(EXTENSION)--2.13.sql: $(EXTENSION)--2.12.sql $(EXTENSION)--2.12--2.13.sql - cat $^ > $@ -$(EXTENSION)--2.14.sql: $(EXTENSION)--2.13.sql $(EXTENSION)--2.13--2.14.sql - cat $^ > $@ diff -uprN postgresql-hll-2.14_old/MurmurHash3.cpp postgresql-hll-2.14/MurmurHash3.cpp --- postgresql-hll-2.14_old/MurmurHash3.cpp 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/MurmurHash3.cpp 2020-12-12 17:06:43.417350232 +0800 @@ -0,0 +1,346 @@ +/*$$$!!Warning: Huawei key information asset. No spread without permission.$$$*/ +/*CODEMARK:WQcKBKQLgyHkXlCLiGIlSvGdiRVlDYpIJLLeBa8CyrNJleUkOpTtwkJAoYct18IqCBpJnKNz +xHjEu+uXc8LQFsBPAN6RG3/a8MnU36eZoStdshKdySYPRbwAIpth0SoG2y9LyT4zsfl8J/br +RRAPG2sXD3KByorVWURnqNslU/wP8VL5gALPQuIENGcs1BeJRs4xK8Ia/GcK1pCH0YXmU8j0 +v7qKZtRkGyUGrwN5qtTb/Q1s6BKVHOcqkBZZgzHUTAObp5NdElhOQ68b3NGfMA==#*/ +/*$$$!!Warning: Deleting or modifying the preceding information is prohibited.$$$*/ +// **************************************************************************** +// This file originally from: +// http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp +// **************************************************************************** + +//----------------------------------------------------------------------------- +// MurmurHash3 was written by Austin Appleby, and is placed in the public +// domain. The author hereby disclaims copyright to this source code. + +// Note - The x86 and x64 versions do _not_ produce the same results, as the +// algorithms are optimized for their respective platforms. You can still +// compile and run any of them on any platform, but your performance with the +// non-native version will be less than optimal. + +#include "MurmurHash3.h" + +//----------------------------------------------------------------------------- +// Platform-specific functions and macros + +// Microsoft Visual Studio + +#if defined(_MSC_VER) + +#define FORCE_INLINE __forceinline + +#include + +#define ROTL32(x,y) _rotl(x,y) +#define ROTL64(x,y) _rotl64(x,y) + +#define BIG_CONSTANT(x) (x) + +// Other compilers + +#else // defined(_MSC_VER) + +#define FORCE_INLINE __attribute__((always_inline)) inline + +inline uint32_t rotl32 ( uint32_t x, int8_t r ) +{ + return (x << (uint8_t)r) | (x >> (uint8_t)(32 - r)); +} + +inline uint64_t rotl64 ( uint64_t x, int8_t r ) +{ + return (x << (uint8_t)r) | (x >> (uint8_t)(64 - r)); +} + +#define ROTL32(x,y) rotl32(x,y) +#define ROTL64(x,y) rotl64(x,y) + +#define BIG_CONSTANT(x) (x##LLU) + +#endif // !defined(_MSC_VER) + +//----------------------------------------------------------------------------- +// Block read - if your platform needs to do endian-swapping or can only +// handle aligned reads, do the conversion here + +FORCE_INLINE uint32_t getblock ( const uint32_t * p, int i ) +{ + return p[i]; +} + +FORCE_INLINE uint64_t getblock ( const uint64_t * p, int i ) +{ + return p[i]; +} + +//----------------------------------------------------------------------------- +// Finalization mix - force all bits of a hash block to avalanche + +FORCE_INLINE uint32_t fmix ( uint32_t h ) +{ + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + + return h; +} + +//---------- + +FORCE_INLINE uint64_t fmix ( uint64_t k ) +{ + k ^= k >> 33; + k *= BIG_CONSTANT(0xff51afd7ed558ccd); + k ^= k >> 33; + k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53); + k ^= k >> 33; + + return k; +} + +//----------------------------------------------------------------------------- + +void MurmurHash3_x86_32 ( const void * key, int len, + uint32_t seed, void * out ) +{ + const uint8_t * data = (const uint8_t*)key; + const int nblocks = len / 4; + + uint32_t h1 = seed; + + const uint32_t c1 = 0xcc9e2d51; + const uint32_t c2 = 0x1b873593; + + //---------- + // body + + const uint32_t * blocks = (const uint32_t *)(data + nblocks*4); + + for(int i = -nblocks; i; i++) + { + uint32_t k1 = getblock(blocks,i); + + k1 *= c1; + k1 = ROTL32(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = ROTL32(h1,13); + h1 = h1*5+0xe6546b64; + } + + //---------- + // tail + + const uint8_t * tail = (const uint8_t*)(data + nblocks*4); + + uint32_t k1 = 0; + + switch((unsigned int)len & 3) + { + case 3: k1 ^= tail[2] << 16; + case 2: k1 ^= tail[1] << 8; + case 1: k1 ^= tail[0]; + k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; + }; + + //---------- + // finalization + + h1 ^= (unsigned int)len; + + h1 = fmix(h1); + + *(uint32_t*)out = h1; +} + +//----------------------------------------------------------------------------- + +void MurmurHash3_x86_128 ( const void * key, const int len, + uint32_t seed, void * out ) +{ + const uint8_t * data = (const uint8_t*)key; + const int nblocks = len / 16; + + uint32_t h1 = seed; + uint32_t h2 = seed; + uint32_t h3 = seed; + uint32_t h4 = seed; + + const uint32_t c1 = 0x239b961b; + const uint32_t c2 = 0xab0e9789; + const uint32_t c3 = 0x38b34ae5; + const uint32_t c4 = 0xa1e38b93; + + //---------- + // body + + const uint32_t * blocks = (const uint32_t *)(data + nblocks*16); + + for(int i = -nblocks; i; i++) + { + uint32_t k1 = getblock(blocks,i*4+0); + uint32_t k2 = getblock(blocks,i*4+1); + uint32_t k3 = getblock(blocks,i*4+2); + uint32_t k4 = getblock(blocks,i*4+3); + + k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; + + h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b; + + k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; + + h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747; + + k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; + + h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35; + + k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; + + h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17; + } + + //---------- + // tail + + const uint8_t * tail = (const uint8_t*)(data + nblocks*16); + + uint32_t k1 = 0; + uint32_t k2 = 0; + uint32_t k3 = 0; + uint32_t k4 = 0; + + switch((unsigned int)len & 15) + { + case 15: k4 ^= tail[14] << 16; + case 14: k4 ^= tail[13] << 8; + case 13: k4 ^= tail[12] << 0; + k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; + + case 12: k3 ^= tail[11] << 24; + case 11: k3 ^= tail[10] << 16; + case 10: k3 ^= tail[ 9] << 8; + case 9: k3 ^= tail[ 8] << 0; + k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; + + case 8: k2 ^= tail[ 7] << 24; + case 7: k2 ^= tail[ 6] << 16; + case 6: k2 ^= tail[ 5] << 8; + case 5: k2 ^= tail[ 4] << 0; + k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; + + case 4: k1 ^= tail[ 3] << 24; + case 3: k1 ^= tail[ 2] << 16; + case 2: k1 ^= tail[ 1] << 8; + case 1: k1 ^= tail[ 0] << 0; + k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; + }; + + //---------- + // finalization + + h1 ^= (unsigned int)len; h2 ^= (unsigned int)len; h3 ^= (unsigned int)len; h4 ^= (unsigned int)len; + + h1 += h2; h1 += h3; h1 += h4; + h2 += h1; h3 += h1; h4 += h1; + + h1 = fmix(h1); + h2 = fmix(h2); + h3 = fmix(h3); + h4 = fmix(h4); + + h1 += h2; h1 += h3; h1 += h4; + h2 += h1; h3 += h1; h4 += h1; + + ((uint32_t*)out)[0] = h1; + ((uint32_t*)out)[1] = h2; + ((uint32_t*)out)[2] = h3; + ((uint32_t*)out)[3] = h4; +} + +//----------------------------------------------------------------------------- + +void MurmurHash3_x64_128 ( const void * key, const int len, + const uint32_t seed, void * out ) +{ + const uint8_t * data = (const uint8_t*)key; + const int nblocks = len / 16; + + uint64_t h1 = seed; + uint64_t h2 = seed; + + const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5); + const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f); + + //---------- + // body + + const uint64_t * blocks = (const uint64_t *)(data); + + for(int i = 0; i < nblocks; i++) + { + uint64_t k1 = getblock(blocks,i*2+0); + uint64_t k2 = getblock(blocks,i*2+1); + + k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; + + h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729; + + k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; + + h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5; + } + + //---------- + // tail + + const uint8_t * tail = (const uint8_t*)(data + nblocks*16); + + uint64_t k1 = 0; + uint64_t k2 = 0; + + switch((unsigned int)len & 15) + { + case 15: k2 ^= uint64_t(tail[14]) << 48; + case 14: k2 ^= uint64_t(tail[13]) << 40; + case 13: k2 ^= uint64_t(tail[12]) << 32; + case 12: k2 ^= uint64_t(tail[11]) << 24; + case 11: k2 ^= uint64_t(tail[10]) << 16; + case 10: k2 ^= uint64_t(tail[ 9]) << 8; + case 9: k2 ^= uint64_t(tail[ 8]) << 0; + k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; + + case 8: k1 ^= uint64_t(tail[ 7]) << 56; + case 7: k1 ^= uint64_t(tail[ 6]) << 48; + case 6: k1 ^= uint64_t(tail[ 5]) << 40; + case 5: k1 ^= uint64_t(tail[ 4]) << 32; + case 4: k1 ^= uint64_t(tail[ 3]) << 24; + case 3: k1 ^= uint64_t(tail[ 2]) << 16; + case 2: k1 ^= uint64_t(tail[ 1]) << 8; + case 1: k1 ^= uint64_t(tail[ 0]) << 0; + k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; + }; + + //---------- + // finalization + + h1 ^= (unsigned int)len; h2 ^= (unsigned int)len; + + h1 += h2; + h2 += h1; + + h1 = fmix(h1); + h2 = fmix(h2); + + h1 += h2; + h2 += h1; + + ((uint64_t*)out)[0] = h1; + ((uint64_t*)out)[1] = h2; +} + +//----------------------------------------------------------------------------- + diff -uprN postgresql-hll-2.14_old/MurmurHash3.h postgresql-hll-2.14/MurmurHash3.h --- postgresql-hll-2.14_old/MurmurHash3.h 1970-01-01 08:00:00.000000000 +0800 +++ postgresql-hll-2.14/MurmurHash3.h 2020-12-12 17:06:43.417350232 +0800 @@ -0,0 +1,50 @@ +// **************************************************************************** +// This file originally from: +// http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.h +// **************************************************************************** + +//----------------------------------------------------------------------------- +// MurmurHash3 was written by Austin Appleby, and is placed in the public +// domain. The author hereby disclaims copyright to this source code. + +#ifndef _MURMURHASH3_H_ +#define _MURMURHASH3_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +//----------------------------------------------------------------------------- +// Platform-specific functions and macros + +// Microsoft Visual Studio + +#if defined(_MSC_VER) + +typedef unsigned char uint8_t; +typedef unsigned long uint32_t; +typedef unsigned __int64 uint64_t; + +// Other compilers + +#else // defined(_MSC_VER) + +#include + +#endif // !defined(_MSC_VER) + +//----------------------------------------------------------------------------- + +void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ); + +void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ); + +void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ); + +//----------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif + +#endif // _MURMURHASH3_H_ diff -uprN postgresql-hll-2.14_old/src/hll.c postgresql-hll-2.14/src/hll.c --- postgresql-hll-2.14_old/src/hll.c 2019-11-15 18:39:18.000000000 +0800 +++ postgresql-hll-2.14/src/hll.c 1970-01-01 08:00:00.000000000 +0800 @@ -1,3712 +0,0 @@ -/* Copyright 2013 Aggregate Knowledge, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include // Needs to be first. - -#if defined(__APPLE__) -#include -#define bswap_64 OSSwapInt64 -#elif defined(__FreeBSD__) || defined(__DragonFly__) -#include -#define bswap_64 bswap64 -#else -#include -#endif - -#include -#include -#include -#include -#include -#include -#if PG_VERSION_NUM >= 120000 -#include "access/genam.h" -#include "access/heapam.h" -#endif -#include "access/sysattr.h" -#include "access/htup_details.h" -#include "commands/extension.h" -#include "optimizer/planner.h" -#include "utils/array.h" -#include "utils/bytea.h" -#include "utils/builtins.h" -#include "utils/fmgroids.h" -#if (PG_VERSION_NUM >= 100000) -#include "utils/fmgrprotos.h" -#endif -#include "utils/guc.h" -#include "utils/int8.h" -#include "utils/lsyscache.h" -#include "utils/memutils.h" -#if (PG_VERSION_NUM >= 100000) -#include "utils/regproc.h" -#endif -#include "catalog/indexing.h" -#include "catalog/namespace.h" -#include "catalog/pg_type.h" -#include "catalog/pg_extension.h" -#include "lib/stringinfo.h" -#include "libpq/pqformat.h" -#include "nodes/print.h" -#if PG_VERSION_NUM >= 120000 -#include "optimizer/optimizer.h" -#else -#include "optimizer/var.h" -#endif -#include "miscadmin.h" - -#include "MurmurHash3.h" - -#ifdef PG_MODULE_MAGIC -PG_MODULE_MAGIC; -#endif - -// ---------------------------------------------------------------- -// Output Version Control -// ---------------------------------------------------------------- - -// Set the default output schema. -static uint8_t g_output_version = 1; - -// ---------------------------------------------------------------- -// Type Modifiers -// ---------------------------------------------------------------- - -// The type modifiers need to be packed in the lower 31 bits -// of an int32. We currently use the lowest 15 bits. -// -#define LOG2M_BITS 5 -#define REGWIDTH_BITS 3 -#define EXPTHRESH_BITS 6 -#define SPARSEON_BITS 1 -#define TYPMOD_BITS 15 - -#define MAX_BITVAL(nbits) ((1 << nbits) - 1) - -// Defaults if type modifier values are not specified. -// -#define DEFAULT_LOG2M 11 -#define DEFAULT_REGWIDTH 5 -#define DEFAULT_EXPTHRESH -1 -#define DEFAULT_SPARSEON 1 - -static int32 g_default_log2m = DEFAULT_LOG2M; -static int32 g_default_regwidth = DEFAULT_REGWIDTH; -static int64 g_default_expthresh = DEFAULT_EXPTHRESH; -static int32 g_default_sparseon = DEFAULT_SPARSEON; - -enum { - MST_UNDEFINED = 0x0, // Invalid/undefined set. - MST_EMPTY = 0x1, // Empty set. - MST_EXPLICIT = 0x2, // List of explicit ids. - MST_SPARSE = 0x3, // Sparse set of compression registers. - MST_COMPRESSED = 0x4, // Array of compression registers. - - MST_UNINIT = 0xffff, // Internal uninitialized. -}; - -// Support disabling hash aggregation functionality for PG > 9.6 -#if PG_VERSION_NUM >= 90600 - -#define EXTENSION_NAME "hll" -#define ADD_AGG_NAME "hll_add_agg" -#define UNION_AGG_NAME "hll_union_agg" -#define HLL_AGGREGATE_COUNT 6 - -static Oid hllAggregateArray[HLL_AGGREGATE_COUNT]; -static bool aggregateValuesInitialized = false; - -bool ForceGroupAgg = false; - -static create_upper_paths_hook_type previous_upper_path_hook; -static void RegisterConfigVariables(void); - -#if (PG_VERSION_NUM >= 110000) -static void hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, - RelOptInfo *input_rel, RelOptInfo *output_rel, - void *extra); -#else -static void hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, - RelOptInfo *input_rel, RelOptInfo *output_rel); -#endif - -static void MaximizeCostOfHashAggregate(Path *path); -static Oid get_extension_schema(Oid ext_oid); -static Oid FunctionOid(const char *schemaName, const char *functionName, int argumentCount, bool missingOk); -static void InitializeHllAggregateOids(void); -static bool HllAggregateOid(Oid aggregateOid); - -void _PG_init(void); -void _PG_fini(void); - -/* _PG_init is the shared library initialization function */ -void _PG_init(void) -{ - /* - * Register HLL configuration variables. - */ - RegisterConfigVariables(); - - previous_upper_path_hook = create_upper_paths_hook; - create_upper_paths_hook = hll_aggregation_restriction_hook; -} - -/* - * hll_aggregation_restriction_hook is assigned to create_upper_paths_hook to - * check whether there exist a path with hash aggregate. If that aggregate is - * introduced by hll, it's cost is maximized to force planner to not to select - * hash aggregate. - * - * Since the signature of the hook changes after PG 11, we define the signature - * and the previous hook call part of this function depending on the PG version. - */ -static void -#if (PG_VERSION_NUM >= 110000) - -hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, - RelOptInfo *input_rel, RelOptInfo *output_rel, - void *extra) -#else -hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, - RelOptInfo *input_rel, RelOptInfo *output_rel) -#endif -{ - Oid extensionOid = InvalidOid; - - // If previous hook exist, call it first to get most update path - if (previous_upper_path_hook != NULL) - { - #if (PG_VERSION_NUM >= 110000) - previous_upper_path_hook(root, stage, input_rel, output_rel, extra); - #else - previous_upper_path_hook(root, stage, input_rel, output_rel); - #endif - } - - /* If HLL extension is not loaded, do nothing */ - extensionOid = get_extension_oid(EXTENSION_NAME, true); - if (!OidIsValid(extensionOid)) - { - return; - } - - /* If we have the extension, that means we also have aggregations */ - if (!aggregateValuesInitialized) - { - InitializeHllAggregateOids(); - } - - /* - * If the client force the group agg, maximize the cost of the path with - * the hash agg to force planner to choose group agg instead. - */ - if (ForceGroupAgg) - { - if (stage == UPPERREL_GROUP_AGG || stage == UPPERREL_FINAL) - { - ListCell *pathCell = list_head(output_rel->pathlist); - foreach(pathCell, output_rel->pathlist) - { - Path *path = (Path *) lfirst(pathCell); - if(path->pathtype == T_Agg && ((AggPath *)path)->aggstrategy == AGG_HASHED) - { - MaximizeCostOfHashAggregate(path); - } - } - } - } -} - -/* - * InitializeHllAggregateOids initializes the array of hll aggregate oids. - */ -static void -InitializeHllAggregateOids() -{ - Oid extensionId = get_extension_oid(EXTENSION_NAME, false); - Oid hllSchemaOid = get_extension_schema(extensionId); - const char *hllSchemaName = get_namespace_name(hllSchemaOid); - char *aggregateName = NULL; - Oid aggregateOid = InvalidOid; - int addAggArgumentCounter; - - /* Initialize HLL_UNION_AGG oid */ - aggregateName = UNION_AGG_NAME; - aggregateOid = FunctionOid(hllSchemaName, aggregateName, 1, true); - hllAggregateArray[0] = aggregateOid; - - /* Initialize HLL_ADD_AGG with different signatures */ - aggregateName = ADD_AGG_NAME; - for (addAggArgumentCounter = 1 ; addAggArgumentCounter < HLL_AGGREGATE_COUNT ; addAggArgumentCounter++) - { - aggregateOid = FunctionOid(hllSchemaName, aggregateName, addAggArgumentCounter, true); - hllAggregateArray[addAggArgumentCounter] = aggregateOid; - } - - aggregateValuesInitialized = true; -} - -/* - * get_extension_schema - given an extension OID, fetch its extnamespace - * Returns InvalidOid if no such extension. - * - * Copied from postgresql extension.c. - */ -static Oid -get_extension_schema(Oid ext_oid) -{ - Oid result; - Relation rel; - SysScanDesc scandesc; - HeapTuple tuple; - ScanKeyData entry[1]; - - rel = heap_open(ExtensionRelationId, AccessShareLock); - - ScanKeyInit(&entry[0], -#if PG_VERSION_NUM >= 120000 - Anum_pg_extension_oid, -#else - ObjectIdAttributeNumber, -#endif - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(ext_oid)); - - scandesc = systable_beginscan(rel, ExtensionOidIndexId, true, - NULL, 1, entry); - - tuple = systable_getnext(scandesc); - - /* We assume that there can be at most one matching tuple */ - if (HeapTupleIsValid(tuple)) - result = ((Form_pg_extension) GETSTRUCT(tuple))->extnamespace; - else - result = InvalidOid; - - systable_endscan(scandesc); - - heap_close(rel, AccessShareLock); - - return result; -} - -/* - * FunctionOid searches for a given function identified by schema, functionName - * and argumentCount. It reports error if the function is not found or there - * are more than one match. If the missingOK parameter is set and there are - * no matches, then the function returns InvalidOid. - */ -static Oid -FunctionOid(const char *schemaName, const char *functionName, int argumentCount, - bool missingOK) -{ - FuncCandidateList functionList = NULL; - Oid functionOid = InvalidOid; - - char *qualifiedFunctionName = quote_qualified_identifier(schemaName, functionName); - List *qualifiedFunctionNameList = stringToQualifiedNameList(qualifiedFunctionName); - List *argumentList = NIL; - const bool findVariadics = false; - const bool findDefaults = false; - - functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount, - argumentList, findVariadics, - findDefaults, true); - - if (functionList == NULL) - { - if (missingOK) - { - return InvalidOid; - } - - ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION), - errmsg("function \"%s\" does not exist", functionName))); - } - else if (functionList->next != NULL) - { - ereport(ERROR, (errcode(ERRCODE_AMBIGUOUS_FUNCTION), - errmsg("more than one function named \"%s\"", functionName))); - } - - /* get function oid from function list's head */ - functionOid = functionList->oid; - - return functionOid; -} - -/* - * MaximizeCostOfHashAggregate maximizes the cost of the path if it tries - * to run hll aggregate function with hash aggregate. - */ -static void -MaximizeCostOfHashAggregate(Path *path) -{ - List *varList = pull_var_clause((Node*) path->pathtarget->exprs, - PVC_INCLUDE_AGGREGATES); - ListCell *varCell = NULL; - - foreach(varCell, varList) - { - Var *var = (Var *) lfirst(varCell); - - if (nodeTag(var) == T_Aggref) - { - Aggref *aggref = (Aggref *) var; - - if(HllAggregateOid(aggref->aggfnoid)) - { - path->total_cost = INT_MAX; - } - } - } -} - -/* - * HllAggregateOid checkes whether the given Oid is an id of any hll aggregate - * function using the pre-initialized hllAggregateArray. - */ -static bool -HllAggregateOid(Oid aggregateOid) -{ - int arrayCounter; - - for (arrayCounter = 0 ; arrayCounter < HLL_AGGREGATE_COUNT ; arrayCounter++) - { - if (aggregateOid == hllAggregateArray[arrayCounter]) - { - return true; - } - } - - return false; -} - -/* Register HLL configuration variables. */ -static void -RegisterConfigVariables(void) -{ - DefineCustomBoolVariable( - "hll.force_groupagg", - gettext_noop("Forces using group aggregate with hll aggregate functions"), - NULL, - &ForceGroupAgg, - false, - PGC_USERSET, - 0, - NULL, NULL, NULL); -} - -/* _PG_fini uninstalls extension hooks */ -void _PG_fini(void) -{ - create_upper_paths_hook = previous_upper_path_hook; -} -#endif - -static int32 typmod_log2m(int32 typmod) -{ - return (typmod >> (TYPMOD_BITS - LOG2M_BITS)) - & MAX_BITVAL(LOG2M_BITS); -} - -static int32 typmod_regwidth(int32 typmod) -{ - return (typmod >> (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS)) - & MAX_BITVAL(REGWIDTH_BITS); -} - -static int32 typmod_expthresh(int32 typmod) -{ - return (typmod >> (TYPMOD_BITS - LOG2M_BITS - - REGWIDTH_BITS - EXPTHRESH_BITS)) - & MAX_BITVAL(EXPTHRESH_BITS); -} - -static int32 typmod_sparseon(int32 typmod) -{ - return (typmod >> (TYPMOD_BITS - LOG2M_BITS - - REGWIDTH_BITS - EXPTHRESH_BITS - SPARSEON_BITS)) - & MAX_BITVAL(SPARSEON_BITS); -} - -// The expthresh is represented in a encoded format in the -// type modifier to save metadata bits. This routine is used -// when the expthresh comes from a typmod value or hll header. -// -static int64 decode_expthresh(int32 encoded_expthresh) -{ - // This routine presumes the encoded value is correct and - // doesn't range check. - // - if (encoded_expthresh == 63) - return -1LL; - else if (encoded_expthresh == 0) - return 0; - else - return 1LL << (encoded_expthresh - 1); -} - -static int32 integer_log2(int64 val) -{ - // Take the log2 of the expthresh. - int32 count = 0; - int64 value = val; - - Assert(val >= 0); - - while (value) - { - ++count; - value >>= 1; - } - return count - 1; -} - -// This routine is used to encode an expthresh value to be stored -// in the typmod metadata or a hll header. -// -static int32 encode_expthresh(int64 expthresh) -{ - // This routine presumes the uncompressed value is correct and - // doesn't range check. - // - if (expthresh == -1) - return 63; - else if (expthresh == 0) - return 0; - else - return integer_log2(expthresh) + 1; -} - -// If expthresh == -1 (auto select expthresh) determine -// the expthresh to use from nbits and nregs. -// -static size_t -expthresh_value(int64 expthresh, size_t nbits, size_t nregs) -{ - if (expthresh != -1) - { - return (size_t) expthresh; - } - else - { - // Auto is selected, choose the maximum number of explicit - // registers that fits in the same space as the compressed - // encoding. - size_t cmpsz = ((nbits * nregs) + 7) / 8; - return cmpsz / sizeof(uint64_t); - } -} - -// ---------------------------------------------------------------- -// Maximum Sparse Control -// ---------------------------------------------------------------- - -// By default we set the sparse to full compressed threshold -// automatically to the point where the sparse representation would -// start to be larger. This can be overridden with the -// hll_set_max_sparse directive ... -// -static int g_max_sparse = -1; - - -// ---------------------------------------------------------------- -// Aggregating Data Structure -// ---------------------------------------------------------------- - -typedef struct -{ - size_t mse_nelem; - uint64_t mse_elems[0]; - -} ms_explicit_t; - -// Defines the *unpacked* register. -typedef uint8_t compreg_t; - -typedef struct -{ - compreg_t msc_regs[0]; - -} ms_compressed_t; - -// Size of the compressed or explicit data. -#define MS_MAXDATA (128 * 1024) - -typedef struct -{ - size_t ms_nbits; - size_t ms_nregs; - size_t ms_log2nregs; - int64 ms_expthresh; - bool ms_sparseon; - - uint64_t ms_type; // size is only for alignment. - - union - { - // MST_EMPTY and MST_UNDEFINED don't need data. - // MST_SPARSE is only used in the packed format. - // - ms_explicit_t as_expl; // MST_EXPLICIT - ms_compressed_t as_comp; // MST_COMPRESSED - uint8_t as_size[MS_MAXDATA]; // sizes the union. - - } ms_data; - -} multiset_t; - -typedef struct -{ - size_t brc_nbits; // Read size. - uint32_t brc_mask; // Read mask. - uint8_t const * brc_curp; // Current byte. - size_t brc_used; // Used bits. - -} bitstream_read_cursor_t; - -static uint32_t -bitstream_unpack(bitstream_read_cursor_t * brcp) -{ - uint32_t retval; - - // Fetch the quadword containing our data. - uint64_t qw = * (uint64_t const *) brcp->brc_curp; - - // Swap the bytes. - qw = bswap_64(qw); - - // Shift the bits we want into place. - qw >>= 64 - brcp->brc_nbits - brcp->brc_used; - - // Mask the bits we want. - retval = (uint32_t) (qw & 0xffffffff) & brcp->brc_mask; - - // We've used some more bits now. - brcp->brc_used += brcp->brc_nbits; - - // Normalize the cursor. - while (brcp->brc_used >= 8) - { - brcp->brc_used -= 8; - brcp->brc_curp += 1; - } - - return retval; -} - -static void -compressed_unpack(compreg_t * i_regp, - size_t i_width, - size_t i_nregs, - uint8_t const * i_bitp, - size_t i_size, - uint8_t i_vers) -{ - size_t bitsz; - size_t padsz; - - bitstream_read_cursor_t brc; - - bitsz = i_width * i_nregs; - - // Fail fast if the compressed array isn't big enough. - if (i_size * 8 < bitsz) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("compressed hll argument not large enough"))); - - padsz = i_size * 8 - bitsz; - - // Fail fast if the pad size doesn't make sense. - if (padsz >= 8) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistent padding in compressed hll argument"))); - - brc.brc_nbits = i_width; - brc.brc_mask = (1 << i_width) - 1; - brc.brc_curp = i_bitp; - brc.brc_used = 0; - - for (size_t ndx = 0; ndx < i_nregs; ++ndx) - { - uint32_t val = bitstream_unpack(&brc); - i_regp[ndx] = val; - } -} - -static void -sparse_unpack(compreg_t * i_regp, - size_t i_width, - size_t i_log2nregs, - size_t i_nfilled, - uint8_t const * i_bitp, - size_t i_size) -{ - size_t bitsz; - size_t padsz; - size_t chunksz; - uint32_t regmask; - - bitstream_read_cursor_t brc; - - chunksz = i_log2nregs + i_width; - bitsz = chunksz * i_nfilled; - padsz = i_size * 8 - bitsz; - - // Fail fast if the pad size doesn't make sense. - if (padsz >= 8) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistent padding in sparse hll argument"))); - - regmask = (1 << i_width) - 1; - - brc.brc_nbits = chunksz; - brc.brc_mask = (1 << chunksz) - 1; - brc.brc_curp = i_bitp; - brc.brc_used = 0; - - for (size_t ii = 0; ii < i_nfilled; ++ii) - { - uint32_t buffer = bitstream_unpack(&brc); - uint32_t val = buffer & regmask; - uint32_t ndx = buffer >> i_width; - i_regp[ndx] = val; - } -} - -typedef struct -{ - size_t bwc_nbits; // Write size. - uint8_t * bwc_curp; // Current byte. - size_t bwc_used; // Used bits. - -} bitstream_write_cursor_t; - -static void -bitstream_pack(bitstream_write_cursor_t * bwcp, uint32_t val) -{ - size_t bits_left_in_first_byte = 8 - bwcp->bwc_used; - size_t bits_to_write_after_first_byte = bwcp->bwc_nbits - bits_left_in_first_byte; - size_t full_bytes_to_write = bits_to_write_after_first_byte / 8; - size_t remainder_bits_after_full_bytes = bits_to_write_after_first_byte % 8; - - // write is small enough that it fits in current byte's remaining space with - // room to spare, so pad the bottom of the byte by left-shifting - if (bwcp->bwc_nbits < bits_left_in_first_byte) - { - * bwcp->bwc_curp = (* bwcp->bwc_curp) | ((uint8_t)(val << (bits_left_in_first_byte - bwcp->bwc_nbits))); - - // consume part of the byte and exit - bwcp->bwc_used += bwcp->bwc_nbits; - return; - } - - // write fits exactly in current byte's remaining space, so just OR it in to - // the bottom bits of the byte - if (bwcp->bwc_nbits == bits_left_in_first_byte) - { - * bwcp->bwc_curp = (* bwcp->bwc_curp) | (uint8_t)(val); - - // consume remainder of byte and exit - bwcp->bwc_used = 0; - bwcp->bwc_curp += 1; - return; - } - - // write DOES NOT fit into current byte, so shift off all but the topmost - // bits from the value and OR those into the bottom bits of the byte - /* bwcp->bwc_nbits > bits_left_in_first_byte */ - * bwcp->bwc_curp = (* bwcp->bwc_curp) | ((uint8_t)(val >> (bwcp->bwc_nbits - bits_left_in_first_byte))); - - // consume remainder of byte - bwcp->bwc_used = 0; - bwcp->bwc_curp += 1; - - // if there are 8 or more bits of the value left to write, write them in one - // byte chunks, higher chunks first - if (full_bytes_to_write > 0) - { - for (size_t i = 0; i < full_bytes_to_write; ++i) - { - size_t bits_to_keep = bits_left_in_first_byte + (8 * (i + 1)); - size_t right_shift = (bwcp->bwc_nbits - bits_to_keep); - - // no OR here because byte is guaranteed to be completely unused - // see above, before conditional - * bwcp->bwc_curp = (uint8_t)(val >> right_shift); - - // consume entire byte - bwcp->bwc_used = 0; - bwcp->bwc_curp += 1; - } - } - if (remainder_bits_after_full_bytes > 0) - { - uint8_t mask = (1 << remainder_bits_after_full_bytes) - 1; - // no OR here because byte is guaranteed to be completely unused - * bwcp->bwc_curp = ((uint8_t)val & mask) << (8 - remainder_bits_after_full_bytes); - - // consume part of the byte - bwcp->bwc_used = remainder_bits_after_full_bytes; - } -} - -static void -compressed_pack(compreg_t const * i_regp, - size_t i_width, - size_t i_nregs, - uint8_t * o_bitp, - size_t i_size, - uint8_t i_vers) -{ - size_t bitsz; - size_t padsz; - - bitstream_write_cursor_t bwc; - - // We need to zero the output array because we use - // an bitwise-or-accumulator below. - memset(o_bitp, '\0', i_size); - - bitsz = i_width * i_nregs; - - // Fail fast if the compressed array isn't big enough. - if (i_size * 8 < bitsz) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("compressed output buffer not large enough"))); - - padsz = i_size * 8 - bitsz; - - // Fail fast if the pad size doesn't make sense. - if (padsz >= 8) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistent compressed output pad size"))); - - bwc.bwc_nbits = i_width; - bwc.bwc_curp = o_bitp; - bwc.bwc_used = 0; - - for (size_t ndx = 0; ndx < i_nregs; ++ndx) - bitstream_pack(&bwc, i_regp[ndx]); -} - -static void -sparse_pack(compreg_t const * i_regp, - size_t i_width, - size_t i_nregs, - size_t i_log2nregs, - size_t i_nfilled, - uint8_t * o_bitp, - size_t i_size) -{ - size_t bitsz; - size_t padsz; - - bitstream_write_cursor_t bwc; - - // We need to zero the output array because we use - // an bitwise-or-accumulator below. - memset(o_bitp, '\0', i_size); - - bitsz = i_nfilled * (i_log2nregs + i_width); - - // Fail fast if the compressed array isn't big enough. - if (i_size * 8 < bitsz) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("sparse output buffer not large enough"))); - - padsz = i_size * 8 - bitsz; - - // Fail fast if the pad size doesn't make sense. - if (padsz >= 8) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistent sparse output pad size"))); - - bwc.bwc_nbits = i_log2nregs + i_width; - bwc.bwc_curp = o_bitp; - bwc.bwc_used = 0; - - for (size_t ndx = 0; ndx < i_nregs; ++ndx) - { - if (i_regp[ndx] != 0) - { - uint32_t buffer = (ndx << i_width) | i_regp[ndx]; - bitstream_pack(&bwc, buffer); - } - } -} - -static void -check_metadata(multiset_t const * i_omp, multiset_t const * i_imp) -{ - if (i_omp->ms_nbits != i_imp->ms_nbits) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("register width does not match: " - "source uses %zu and dest uses %zu", - i_imp->ms_nbits, i_omp->ms_nbits))); - } - - if (i_omp->ms_nregs != i_imp->ms_nregs) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("register count does not match: " - "source uses %zu and dest uses %zu", - i_imp->ms_nregs, i_omp->ms_nregs))); - } - - // Don't need to compare log2nregs because we compared nregs ... - - if (i_omp->ms_expthresh != i_imp->ms_expthresh) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("explicit threshold does not match: " - "source uses " INT64_FORMAT " and dest uses " INT64_FORMAT, - i_imp->ms_expthresh, i_omp->ms_expthresh))); - } - - if (i_omp->ms_sparseon != i_imp->ms_sparseon) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("sparse enable does not match: " - "source uses %d and dest uses %d", - i_imp->ms_sparseon, i_omp->ms_sparseon))); - } -} - -static void -copy_metadata(multiset_t * o_msp, multiset_t const * i_msp) -{ - o_msp->ms_nbits = i_msp->ms_nbits; - o_msp->ms_nregs = i_msp->ms_nregs; - o_msp->ms_log2nregs = i_msp->ms_log2nregs; - o_msp->ms_expthresh = i_msp->ms_expthresh; - o_msp->ms_sparseon = i_msp->ms_sparseon; -} - -static void -compressed_add(multiset_t * o_msp, uint64_t elem) -{ - size_t nbits = o_msp->ms_nbits; - size_t nregs = o_msp->ms_nregs; - size_t log2nregs = o_msp->ms_log2nregs; - - ms_compressed_t * mscp = &o_msp->ms_data.as_comp; - - uint64_t mask = nregs - 1; - - size_t maxregval = (1 << nbits) - 1; - - size_t ndx = elem & mask; - - uint64_t ss_val = elem >> log2nregs; - - size_t p_w = ss_val == 0 ? 0 : __builtin_ctzll(ss_val) + 1; - - if (p_w > maxregval) - p_w = maxregval; - - if (mscp->msc_regs[ndx] < p_w) - mscp->msc_regs[ndx] = p_w; -} - -static void -compressed_explicit_union(multiset_t * o_msp, multiset_t const * i_msp) -{ - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - for (size_t ii = 0; ii < msep->mse_nelem; ++ii) - compressed_add(o_msp, msep->mse_elems[ii]); -} - -static void -explicit_to_compressed(multiset_t * msp) -{ - // Make a copy of the explicit multiset. - multiset_t ms; - memcpy(&ms, msp, sizeof(ms)); - - // Clear the multiset. - memset(msp, '\0', sizeof(*msp)); - - // Restore the metadata. - copy_metadata(msp, &ms); - - // Make it MST_COMPRESSED. - msp->ms_type = MST_COMPRESSED; - - // Add all the elements back into the compressed multiset. - compressed_explicit_union(msp, &ms); -} - -static int -element_compare(void const * ptr1, void const * ptr2) -{ - // We used signed integer comparison to be compatible - // with the java code. - - int64_t v1 = * (int64_t const *) ptr1; - int64_t v2 = * (int64_t const *) ptr2; - - return (v1 < v2) ? -1 : (v1 > v2) ? 1 : 0; -} - -static size_t numfilled(multiset_t const * i_msp) -{ - ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; - size_t nfilled = 0; - size_t nregs = i_msp->ms_nregs; - for (size_t ii = 0; ii < nregs; ++ii) - if (mscp->msc_regs[ii] > 0) - ++nfilled; - - return nfilled; -} - -static char * -multiset_tostring(multiset_t const * i_msp) -{ - char expbuf[256]; - char * retstr; - size_t len; - size_t used; - size_t nbits = i_msp->ms_nbits; - size_t nregs = i_msp->ms_nregs; - int64 expthresh = i_msp->ms_expthresh; - size_t sparseon = i_msp->ms_sparseon; - - size_t expval = expthresh_value(expthresh, nbits, nregs); - - // If the expthresh is set to -1 (auto) augment the value - // with the automatically determined value. - // - if (expthresh == -1) - snprintf(expbuf, sizeof(expbuf), INT64_FORMAT "(%zu)", expthresh, expval); - else - snprintf(expbuf, sizeof(expbuf), INT64_FORMAT, expthresh); - - // Allocate an initial return buffer. - len = 1024; - retstr = (char *) palloc(len); - memset(retstr, '\0', len); - - // We haven't used any return buffer yet. - used = 0; - - // Print in a type-dependent way. - switch (i_msp->ms_type) - { - case MST_EMPTY: - used += snprintf(retstr, len, "EMPTY, " - "nregs=%zu, nbits=%zu, expthresh=%s, sparseon=%zu", - nregs, nbits, expbuf, sparseon); - break; - case MST_EXPLICIT: - { - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - size_t size = msep->mse_nelem; - char linebuf[1024]; - ssize_t rv; - - used += snprintf(retstr, len, "EXPLICIT, %zu elements, " - "nregs=%zu, nbits=%zu, " - "expthresh=%s, sparseon=%zu:", - size, nregs, nbits, expbuf, sparseon); - for (size_t ii = 0; ii < size; ++ii) - { - int64_t val = * (int64_t const *) & msep->mse_elems[ii]; - rv = snprintf(linebuf, sizeof(linebuf), - "\n%zu: %20" PRIi64 " ", - ii, val); - // Do we need to reallocate the return buffer? - if (rv + used > len - 1) - { - len += 1024; - retstr = (char *) repalloc(retstr, len); - } - strncpy(&retstr[used], linebuf, len - used); - used += rv; - } - } - break; - case MST_COMPRESSED: - { - ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; - - char linebuf[1024]; - - size_t rowsz = 32; - size_t nrows = nregs / rowsz; - size_t ndx = 0; - - used += snprintf(retstr, len, - "COMPRESSED, %zu filled " - "nregs=%zu, nbits=%zu, expthresh=%s, " - "sparseon=%zu:", - numfilled(i_msp), - nregs, nbits, expbuf, sparseon); - - for (size_t rr = 0; rr < nrows; ++rr) - { - size_t pos = 0; - pos = snprintf(linebuf, sizeof(linebuf), "\n%4zu: ", ndx); - for (size_t cc = 0; cc < rowsz; ++cc) - { - pos += snprintf(&linebuf[pos], sizeof(linebuf) - pos, - "%2d ", mscp->msc_regs[ndx]); - ++ndx; - } - - // Do we need to reallocate the return buffer? - if (pos + used > len - 1) - { - len += 1024; - retstr = (char *) repalloc(retstr, len); - } - strncpy(&retstr[used], linebuf, len - used); - used += pos; - } - } - break; - case MST_UNDEFINED: - used += snprintf(retstr, len, "UNDEFINED " - "nregs=%zu, nbits=%zu, expthresh=%s, sparseon=%zu", - nregs, nbits, expbuf, sparseon); - break; - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unexpected multiset type value"))); - break; - } - - return retstr; -} - -static void -explicit_validate(multiset_t const * i_msp, ms_explicit_t const * i_msep) -{ - // Allow explicit multisets with no elements. - if (i_msep->mse_nelem == 0) - return; - - // Confirm that all elements are ascending with no duplicates. - for (size_t ii = 0; ii < i_msep->mse_nelem - 1; ++ii) - { - if (element_compare(&i_msep->mse_elems[ii], - &i_msep->mse_elems[ii + 1]) != -1) - { - char * buf = multiset_tostring(i_msp); - - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("duplicate or descending explicit elements: %s", - buf))); - - pfree(buf); - } - } -} - -static size_t -upper_bound(const uint64_t elements[], size_t n, uint64_t value) -{ - size_t low = 0; - size_t high = n; - - while (low < high) - { - size_t middle = low + (high - low) / 2; - int cmp = element_compare(&value, &elements[middle]); - if (cmp == 0) { - low = high = middle; - } - else if (cmp > 0) { - low = middle + 1; - } - else { - high = middle; - } - } - return low; -} - -static void -multiset_add(multiset_t * o_msp, uint64_t element) -{ - // WARNING! This routine can change the type of the multiset! - - size_t expval = expthresh_value(o_msp->ms_expthresh, - o_msp->ms_nbits, - o_msp->ms_nregs); - - switch (o_msp->ms_type) - { - case MST_EMPTY: - // Are we forcing compressed? - if (expval == 0) - { - // Now we're explicit with no elements. - o_msp->ms_type = MST_EXPLICIT; - o_msp->ms_data.as_expl.mse_nelem = 0; - - // Convert it to compressed. - explicit_to_compressed(o_msp); - - // Add the element in compressed format. - compressed_add(o_msp, element); - } - else - { - // Now we're explicit with one element. - o_msp->ms_type = MST_EXPLICIT; - o_msp->ms_data.as_expl.mse_nelem = 1; - o_msp->ms_data.as_expl.mse_elems[0] = element; - } - break; - - case MST_EXPLICIT: - { - ms_explicit_t * msep = &o_msp->ms_data.as_expl; - size_t insert_pos = upper_bound(msep->mse_elems, msep->mse_nelem, element); - // If the element is already in the set we're done. - if (insert_pos < msep->mse_nelem && - element_compare(&element, &msep->mse_elems[insert_pos]) == 0) - { - return; - } - - // Is the explicit multiset full? - if (msep->mse_nelem == expval) - { - // Convert it to compressed. - explicit_to_compressed(o_msp); - - // Add the element in compressed format. - compressed_add(o_msp, element); - } - else - { - // If not at end, move all elements one step - if (insert_pos < msep->mse_nelem) - { - memmove(&msep->mse_elems[insert_pos + 1], - &msep->mse_elems[insert_pos], - (msep->mse_nelem - insert_pos) * sizeof(uint64_t)); - } - // Actually add the element - msep->mse_nelem += 1; - msep->mse_elems[insert_pos] = element; - } - } - break; - - case MST_COMPRESSED: - compressed_add(o_msp, element); - break; - - case MST_UNDEFINED: - // Result is unchanged. - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #1"))); - break; - } -} - -static void -explicit_union(multiset_t * o_msp, ms_explicit_t const * i_msep) -{ - // NOTE - This routine is optimized to add a batch of elements; - // it doesn't resort until they are all added ... - // - // WARNING! This routine can change the type of the target multiset! - - size_t expval = expthresh_value(o_msp->ms_expthresh, - o_msp->ms_nbits, - o_msp->ms_nregs); - - ms_explicit_t * msep = &o_msp->ms_data.as_expl; - - // Note the starting size of the target set. - size_t orig_nelem = msep->mse_nelem; - - for (size_t ii = 0; ii < i_msep->mse_nelem; ++ii) - { - uint64_t element = i_msep->mse_elems[ii]; - - switch (o_msp->ms_type) - { - case MST_EXPLICIT: - if (bsearch(&element, - msep->mse_elems, - orig_nelem, - sizeof(uint64_t), - element_compare)) - continue; - - if (msep->mse_nelem < expval) - { - // Add the element at the end. - msep->mse_elems[msep->mse_nelem++] = element; - } - else - { - // Convert it to compressed. - explicit_to_compressed(o_msp); - - // Add the element in compressed format. - compressed_add(o_msp, element); - } - break; - - case MST_COMPRESSED: - compressed_add(o_msp, element); - break; - } - } - - // If the target multiset is still explicit it needs to be - // resorted. - if (o_msp->ms_type == MST_EXPLICIT) - { - // Resort the elements. - qsort(msep->mse_elems, - msep->mse_nelem, - sizeof(uint64_t), - element_compare); - } -} - -static void unpack_header(multiset_t * o_msp, - uint8_t const * i_bitp, - uint8_t vers, - uint8_t type) -{ - o_msp->ms_nbits = (i_bitp[1] >> 5) + 1; - o_msp->ms_log2nregs = i_bitp[1] & 0x1f; - o_msp->ms_nregs = 1 << o_msp->ms_log2nregs; - o_msp->ms_expthresh = decode_expthresh(i_bitp[2] & 0x3f); - o_msp->ms_sparseon = (i_bitp[2] >> 6) & 0x1; -} - -static uint8_t -multiset_unpack(multiset_t * o_msp, - uint8_t const * i_bitp, - size_t i_size, - uint8_t * o_encoded_type) -{ - // First byte is the version and type header. - uint8_t vers = (i_bitp[0] >> 4) & 0xf; - uint8_t type = i_bitp[0] & 0xf; - - if (vers != 1) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unknown schema version %d", (int) vers))); - - if (o_encoded_type != NULL) - *o_encoded_type = type; - - // Set the type. NOTE - MST_SPARSE are converted to MST_COMPRESSED. - o_msp->ms_type = (type == MST_SPARSE) ? MST_COMPRESSED : type; - - switch (type) - { - case MST_EMPTY: - if (vers == 1) - { - size_t hdrsz = 3; - - // Make sure the size is consistent. - if (i_size != hdrsz) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistently sized empty multiset"))); - } - - unpack_header(o_msp, i_bitp, vers, type); - } - else - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unsupported empty version %d", - (int) vers))); - } - - break; - - case MST_EXPLICIT: - if (vers == 1) - { - ms_explicit_t * msep = &o_msp->ms_data.as_expl; - size_t hdrsz = 3; - size_t nelem = (i_size - hdrsz) / 8; - size_t ndx = hdrsz; - - // Make sure the size is consistent. - if (((i_size - hdrsz) % 8) != 0) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistently sized explicit multiset"))); - } - - // Make sure the explicit array fits in memory. - if ((i_size - hdrsz) > MS_MAXDATA) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("explicit multiset too large"))); - } - - unpack_header(o_msp, i_bitp, vers, type); - - msep->mse_nelem = nelem; - for (size_t ii = 0; ii < nelem; ++ii) - { - uint64_t val = 0; - val |= ((uint64_t) i_bitp[ndx++] << 56); - val |= ((uint64_t) i_bitp[ndx++] << 48); - val |= ((uint64_t) i_bitp[ndx++] << 40); - val |= ((uint64_t) i_bitp[ndx++] << 32); - val |= ((uint64_t) i_bitp[ndx++] << 24); - val |= ((uint64_t) i_bitp[ndx++] << 16); - val |= ((uint64_t) i_bitp[ndx++] << 8); - val |= ((uint64_t) i_bitp[ndx++] << 0); - msep->mse_elems[ii] = val; - } - - explicit_validate(o_msp, msep); - } - else - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unsupported explicit version %d", - (int) vers))); - } - break; - - case MST_COMPRESSED: - if (vers == 1) - { - size_t hdrsz = 3; - - // Decode the parameter byte. - uint8_t param = i_bitp[1]; - size_t nbits = (param >> 5) + 1; - size_t log2nregs = param & 0x1f; - size_t nregs = 1 << log2nregs; - - // Make sure the size is consistent. - size_t bitsz = nbits * nregs; - size_t packedbytesz = (bitsz + 7) / 8; - if ((i_size - hdrsz) != packedbytesz) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("inconsistently sized " - "compressed multiset"))); - } - - // Make sure the compressed array fits in memory. - if (nregs * sizeof(compreg_t) > MS_MAXDATA) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("compressed multiset too large"))); - } - - unpack_header(o_msp, i_bitp, vers, type); - - // Fill the registers. - compressed_unpack(o_msp->ms_data.as_comp.msc_regs, - nbits, nregs, &i_bitp[hdrsz], i_size - hdrsz, - vers); - } - else - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unsupported compressed version %d", - (int) vers))); - } - break; - - case MST_UNDEFINED: - if (vers == 1) - { - size_t hdrsz = 3; - - // Make sure the size is consistent. - if (i_size != hdrsz) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset value"))); - } - - unpack_header(o_msp, i_bitp, vers, type); - } - else - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unsupported undefined version %d", - (int) vers))); - } - - break; - - case MST_SPARSE: - if (vers == 1) - { - size_t hdrsz = 3; - - ms_compressed_t * mscp; - - if (i_size < hdrsz) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("sparse multiset too small"))); - } - else - { - // Decode the parameter byte. - uint8_t param = i_bitp[1]; - size_t nbits = (param >> 5) + 1; - size_t log2nregs = param & 0x1f; - size_t nregs = 1 << log2nregs; - - // Figure out how many encoded registers are in the - // bitstream. We depend on the log2nregs + nbits being - // greater then the pad size so we aren't left with - // ambiguity in the final pad byte. - - size_t bitsz = (i_size - hdrsz) * 8; - size_t chunksz = log2nregs + nbits; - size_t nfilled = bitsz / chunksz; - - // Make sure the compressed array fits in memory. - if (nregs * sizeof(compreg_t) > MS_MAXDATA) - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("sparse multiset too large"))); - } - - unpack_header(o_msp, i_bitp, vers, type); - - mscp = &o_msp->ms_data.as_comp; - - // Pre-zero the registers since sparse only fills - // in occasional ones. - // - for (size_t ii = 0; ii < nregs; ++ii) - mscp->msc_regs[ii] = 0; - - // Fill the registers. - sparse_unpack(mscp->msc_regs, - nbits, log2nregs, nfilled, - &i_bitp[hdrsz], i_size - hdrsz); - } - } - else - { - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("unsupported sparse version %d", - (int) vers))); - } - break; - - default: - // This is always an error. - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type"))); - break; - } - - return vers; -} - -static size_t -pack_header(uint8_t * o_bitp, - uint8_t vers, - uint8_t type, - size_t nbits, - size_t log2nregs, - int64 expthresh, - size_t sparseon) -{ - size_t ndx = 0; - - o_bitp[ndx++] = (vers << 4) | type; - o_bitp[ndx++] = ((nbits - 1) << 5) | log2nregs; - o_bitp[ndx++] = (sparseon << 6) | encode_expthresh(expthresh); - - return ndx; -} - -static void -multiset_pack(multiset_t const * i_msp, uint8_t * o_bitp, size_t i_size) -{ - uint8_t vers = g_output_version; - - size_t nbits = i_msp->ms_nbits; - size_t log2nregs = i_msp->ms_log2nregs; - int64 expthresh = i_msp->ms_expthresh; - size_t sparseon = i_msp->ms_sparseon; - - switch (i_msp->ms_type) - { - case MST_EMPTY: - pack_header(o_bitp, vers, MST_EMPTY, - nbits, log2nregs, expthresh, sparseon); - break; - - case MST_EXPLICIT: - { - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - size_t size = msep->mse_nelem; - - size_t ndx = pack_header(o_bitp, vers, MST_EXPLICIT, - nbits, log2nregs, expthresh, sparseon); - - for (size_t ii = 0; ii < size; ++ii) - { - uint64_t val = msep->mse_elems[ii]; - - o_bitp[ndx++] = (val >> 56) & 0xff; - o_bitp[ndx++] = (val >> 48) & 0xff; - o_bitp[ndx++] = (val >> 40) & 0xff; - o_bitp[ndx++] = (val >> 32) & 0xff; - o_bitp[ndx++] = (val >> 24) & 0xff; - o_bitp[ndx++] = (val >> 16) & 0xff; - o_bitp[ndx++] = (val >> 8) & 0xff; - o_bitp[ndx++] = (val >> 0) & 0xff; - } - } - break; - - case MST_COMPRESSED: - { - ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; - size_t nregs = i_msp->ms_nregs; - size_t nfilled = numfilled(i_msp); - - // Should we pack this as MST_SPARSE or MST_COMPRESSED? - // IMPORTANT - matching code in multiset_packed_size! - size_t sparsebitsz; - size_t cmprssbitsz; - sparsebitsz = nfilled * (log2nregs + nbits); - cmprssbitsz = nregs * nbits; - - // If the vector does not have sparse enabled use - // compressed. - // - // If the vector is smaller then the max sparse size use - // compressed. - // - // If the max sparse size is auto (-1) use if smaller then - // compressed. - // - if (sparseon && - ((g_max_sparse != -1 && nfilled <= (size_t) g_max_sparse) || - (g_max_sparse == -1 && sparsebitsz < cmprssbitsz))) - { - size_t ndx = pack_header(o_bitp, vers, MST_SPARSE, - nbits, log2nregs, expthresh, sparseon); - - // Marshal the registers. - sparse_pack(mscp->msc_regs, - nbits, nregs, log2nregs, nfilled, - &o_bitp[ndx], i_size - ndx); - } - else - { - size_t ndx = pack_header(o_bitp, vers, MST_COMPRESSED, - nbits, log2nregs, expthresh, sparseon); - - // Marshal the registers. - compressed_pack(mscp->msc_regs, nbits, nregs, - &o_bitp[ndx], i_size - ndx, vers); - } - break; - } - - case MST_UNDEFINED: - pack_header(o_bitp, vers, MST_UNDEFINED, - nbits, log2nregs, expthresh, sparseon); - break; - - case MST_SPARSE: - // We only marshal (pack) into sparse format; complain if - // an in-memory multiset claims it is sparse. - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("invalid internal sparse format"))); - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #2"))); - break; - } -} - -static size_t -multiset_copy_size(multiset_t const * i_msp) -{ - size_t retval = 0; - - switch (i_msp->ms_type) - { - case MST_EMPTY: - retval = __builtin_offsetof(multiset_t, ms_data); - break; - - case MST_EXPLICIT: - { - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - retval = __builtin_offsetof(multiset_t, ms_data.as_expl.mse_elems); - retval += (msep->mse_nelem * sizeof(uint64_t)); - } - break; - - case MST_COMPRESSED: - { - retval = __builtin_offsetof(multiset_t, ms_data.as_comp.msc_regs); - retval += (i_msp->ms_nregs * sizeof(compreg_t)); - } - break; - - case MST_UNDEFINED: - retval = __builtin_offsetof(multiset_t, ms_data); - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #3"))); - break; - } - - return retval; -} - -static size_t -multiset_packed_size(multiset_t const * i_msp) -{ - uint8_t vers = g_output_version; - - size_t retval = 0; - - switch (i_msp->ms_type) - { - case MST_EMPTY: - switch (vers) - { - case 1: - retval = 3; - break; - default: - Assert(vers == 1); - } - break; - - case MST_EXPLICIT: - switch (vers) - { - case 1: - { - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - retval = 3 + (8 * msep->mse_nelem); - } - break; - default: - Assert(vers == 1); - } - break; - - case MST_COMPRESSED: - if (vers == 1) - { - size_t hdrsz = 3; - size_t nbits = i_msp->ms_nbits; - size_t nregs = i_msp->ms_nregs; - size_t nfilled = numfilled(i_msp); - size_t log2nregs = i_msp->ms_log2nregs; - size_t sparseon = i_msp->ms_sparseon; - size_t sparsebitsz; - size_t cmprssbitsz; - - // Should we pack this as MST_SPARSE or MST_COMPRESSED? - // IMPORTANT - matching code in multiset_pack! - // - sparsebitsz = numfilled(i_msp) * (log2nregs + nbits); - cmprssbitsz = nregs * nbits; - - // If the vector does not have sparse enabled use - // compressed. - // - // If the vector is smaller then the max sparse size use - // compressed. - // - // If the max sparse size is auto (-1) use if smaller then - // compressed. - // - if (sparseon && - ((g_max_sparse != -1 && nfilled <= (size_t) g_max_sparse) || - (g_max_sparse == -1 && sparsebitsz < cmprssbitsz))) - - { - // MST_SPARSE is more compact. - retval = hdrsz + ((sparsebitsz + 7) / 8); - } - else - { - // MST_COMPRESSED is more compact. - retval = hdrsz + ((cmprssbitsz + 7) / 8); - } - } - else - { - Assert(vers == 1); - } - break; - - case MST_UNDEFINED: - if (vers == 1) - { - size_t hdrsz = 3; - retval = hdrsz; - } - else - { - Assert(vers == 1); - } - break; - - case MST_SPARSE: - // We only marshal (pack) into sparse format; complain if - // an in-memory multiset claims it is sparse. - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("invalid internal sparse format"))); - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #4"))); - break; - } - - return retval; -} - -PG_FUNCTION_INFO_V1(hll_in); -Datum hll_in(PG_FUNCTION_ARGS); -Datum -hll_in(PG_FUNCTION_ARGS) -{ - Datum dd = DirectFunctionCall1(byteain, PG_GETARG_DATUM(0)); - - int32 typmod = PG_GETARG_INT32(2); - - // Unpack to make sure the data is valid. - bytea * bp = DatumGetByteaP(dd); - size_t sz = VARSIZE(bp) - VARHDRSZ; - multiset_t ms; - multiset_unpack(&ms, (uint8_t *) VARDATA(bp), sz, NULL); - - // The typmod value will be valid for COPY and \COPY statements. - // Check the metadata consistency in these cases. - if (typmod != -1) - { - int32 log2m = typmod_log2m(typmod); - int32 regwidth = typmod_regwidth(typmod); - int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); - int32 sparseon = typmod_sparseon(typmod); - - // Create a placeholder w/ declared metadata. - multiset_t msx; - msx.ms_nbits = regwidth; - msx.ms_nregs = (1 << log2m); - msx.ms_log2nregs = log2m; - msx.ms_expthresh = expthresh; - msx.ms_sparseon = sparseon; - - // Make sure the declared metadata matches the incoming. - check_metadata(&msx, &ms); - } - - return dd; -} - -PG_FUNCTION_INFO_V1(hll_out); -Datum hll_out(PG_FUNCTION_ARGS); -Datum -hll_out(PG_FUNCTION_ARGS) -{ - // NOTE - It's still worth interposing on these calls in case - // we want to support alternate representations in the future. - - Datum dd = DirectFunctionCall1(byteaout, PG_GETARG_DATUM(0)); - return dd; -} - -PG_FUNCTION_INFO_V1(hll); -Datum hll(PG_FUNCTION_ARGS); -Datum -hll(PG_FUNCTION_ARGS) -{ - Datum dd = PG_GETARG_DATUM(0); - bytea * bp = DatumGetByteaP(dd); - size_t sz = VARSIZE(bp) - VARHDRSZ; - int32 typmod = PG_GETARG_INT32(1); // !! DIFFERENT THEN IN hll_in! - bool isexplicit = PG_GETARG_BOOL(2); // explicit cast, not explicit vector - int32 log2m = typmod_log2m(typmod); - int32 regwidth = typmod_regwidth(typmod); - int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); - int32 sparseon = typmod_sparseon(typmod); - - multiset_t ms; - multiset_t msx; - - // Unpack the bit data. - multiset_unpack(&ms, (uint8_t *) VARDATA(bp), sz, NULL); - - // Make the compiler happpy. - (void) isexplicit; - - // Create a placeholder w/ declared metadata. - msx.ms_nbits = regwidth; - msx.ms_nregs = (1 << log2m); - msx.ms_log2nregs = log2m; - msx.ms_expthresh = expthresh; - msx.ms_sparseon = sparseon; - - // Make sure the declared metadata matches the incoming. - check_metadata(&msx, &ms); - - // If we make it here we're good. - return dd; -} - -PG_FUNCTION_INFO_V1(hll_hashval_in); -Datum hll_hashval_in(PG_FUNCTION_ARGS); -Datum -hll_hashval_in(PG_FUNCTION_ARGS) -{ - Datum dd = DirectFunctionCall1(int8in, PG_GETARG_DATUM(0)); - return dd; -} - -PG_FUNCTION_INFO_V1(hll_hashval_out); -Datum hll_hashval_out(PG_FUNCTION_ARGS); -Datum -hll_hashval_out(PG_FUNCTION_ARGS) -{ - Datum dd = DirectFunctionCall1(int8out, PG_GETARG_DATUM(0)); - return dd; -} - -PG_FUNCTION_INFO_V1(hll_hashval_eq); -Datum hll_hashval_eq(PG_FUNCTION_ARGS); -Datum -hll_hashval_eq(PG_FUNCTION_ARGS) -{ - int64 aa = PG_GETARG_INT64(0); - int64 bb = PG_GETARG_INT64(1); - PG_RETURN_BOOL(aa == bb); -} - -PG_FUNCTION_INFO_V1(hll_hashval_ne); -Datum hll_hashval_ne(PG_FUNCTION_ARGS); -Datum -hll_hashval_ne(PG_FUNCTION_ARGS) -{ - int64 aa = PG_GETARG_INT64(0); - int64 bb = PG_GETARG_INT64(1); - PG_RETURN_BOOL(aa != bb); -} - -PG_FUNCTION_INFO_V1(hll_hashval); -Datum hll_hashval(PG_FUNCTION_ARGS); -Datum -hll_hashval(PG_FUNCTION_ARGS) -{ - int64 aa = PG_GETARG_INT64(0); - PG_RETURN_INT64(aa); -} - -PG_FUNCTION_INFO_V1(hll_hashval_int4); -Datum hll_hashval_int4(PG_FUNCTION_ARGS); -Datum -hll_hashval_int4(PG_FUNCTION_ARGS) -{ - int32 aa = PG_GETARG_INT32(0); - int64 aaaa = aa; // extend value to 64 bits. - PG_RETURN_INT64(aaaa); -} - -static void -check_modifiers(int32 log2m, int32 regwidth, int64 expthresh, int32 sparseon) -{ - // Range check each of the modifiers. - if (log2m < 0 || log2m > MAX_BITVAL(LOG2M_BITS)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("log2m modifier must be between 0 and 31"))); - - if (regwidth < 0 || regwidth > MAX_BITVAL(REGWIDTH_BITS)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("regwidth modifier must be between 0 and 7"))); - - if (expthresh < -1 || expthresh > 4294967296LL) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("expthresh modifier must be between -1 and 2^32"))); - - if (expthresh > 0 && (1LL << integer_log2(expthresh)) != expthresh) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("expthresh modifier must be power of 2"))); - - if (sparseon < 0 || sparseon > MAX_BITVAL(SPARSEON_BITS)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("sparseon modifier must be 0 or 1"))); -} - -// This routine is cloned from the arrayutils ArrayGetIntegerTypmods -// and converted to return 64 bit integers. -// -static int64 * -ArrayGetInteger64Typmods(ArrayType *arr, int *n) -{ - int64 *result; - Datum *elem_values; - int i; - - if (ARR_ELEMTYPE(arr) != CSTRINGOID) - ereport(ERROR, - (errcode(ERRCODE_ARRAY_ELEMENT_ERROR), - errmsg("typmod array must be type cstring[]"))); - - if (ARR_NDIM(arr) != 1) - ereport(ERROR, - (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), - errmsg("typmod array must be one-dimensional"))); - - if (array_contains_nulls(arr)) - ereport(ERROR, - (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), - errmsg("typmod array must not contain nulls"))); - - /* hardwired knowledge about cstring's representation details here */ - deconstruct_array(arr, CSTRINGOID, - -2, false, 'c', - &elem_values, NULL, n); - - result = (int64 *) palloc(*n * sizeof(int64)); - - for (i = 0; i < *n; i++) - { - char * endp = NULL; - result[i] = strtoll(DatumGetCString(elem_values[i]), &endp, 0); - if (*endp != '\0') - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("typmod array must contain integers"))); - } - - pfree(elem_values); - - return result; -} - -PG_FUNCTION_INFO_V1(hll_typmod_in); -Datum hll_typmod_in(PG_FUNCTION_ARGS); -Datum -hll_typmod_in(PG_FUNCTION_ARGS) -{ - ArrayType * ta = PG_GETARG_ARRAYTYPE_P(0); - int64 * tl; - int nmods; - int32 typmod; - int32 log2m; - int32 regwidth; - int64 expthresh; - int32 sparseon; - - tl = ArrayGetInteger64Typmods(ta, &nmods); - - // Make sure the number of type modifiers is in a valid range. - if (nmods > 4 || nmods < 0) - { - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid number of type modifiers"))); - typmod = 0; /* keep compiler quiet */ - } - else - { - // Process the type modifiers, supply defaults if necessary. - log2m = (nmods >= 1) ? tl[0] : g_default_log2m; - regwidth = (nmods >= 2) ? tl[1] : g_default_regwidth; - expthresh = (nmods >= 3) ? tl[2] : g_default_expthresh; - sparseon = (nmods == 4) ? tl[3] : g_default_sparseon; - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - // Construct the typmod value. - typmod = - (log2m << (TYPMOD_BITS - LOG2M_BITS)) | - (regwidth << (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS)) | - (encode_expthresh(expthresh) << - (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS - - EXPTHRESH_BITS)) | - (sparseon << (TYPMOD_BITS - LOG2M_BITS - REGWIDTH_BITS - - EXPTHRESH_BITS - SPARSEON_BITS)); - } - - PG_RETURN_INT32(typmod); -} - -PG_FUNCTION_INFO_V1(hll_typmod_out); -Datum hll_typmod_out(PG_FUNCTION_ARGS); -Datum -hll_typmod_out(PG_FUNCTION_ARGS) -{ - int32 typmod = (uint32) PG_GETARG_INT32(0); - int32 log2m = typmod_log2m(typmod); - int32 regwidth = typmod_regwidth(typmod); - int64 expthresh = decode_expthresh(typmod_expthresh(typmod)); - int32 sparseon = typmod_sparseon(typmod); - - char buffer[1024]; - size_t len; - char * typmodstr; - - memset(buffer, '\0', sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "(%d,%d," INT64_FORMAT ",%d)", - log2m, regwidth, expthresh, sparseon); - - len = strlen(buffer) + 1; - typmodstr = (char *) palloc(len); - strncpy(typmodstr, buffer, len); - - PG_RETURN_CSTRING(typmodstr); -} - -static void -multiset_union(multiset_t * o_msap, multiset_t const * i_msbp) -{ - int typea = o_msap->ms_type; - int typeb = i_msbp->ms_type; - - // If either multiset is MST_UNDEFINED result is MST_UNDEFINED. - if (typea == MST_UNDEFINED || typeb == MST_UNDEFINED) - { - o_msap->ms_type = MST_UNDEFINED; - return; - } - - // If B is MST_EMPTY, we're done, A is unchanged. - if (typeb == MST_EMPTY) - return; - - // If A is MST_EMPTY, return B instead. - if (typea == MST_EMPTY) - { - memcpy(o_msap, i_msbp, multiset_copy_size(i_msbp)); - return; - } - - switch (typea) - { - case MST_EXPLICIT: - { - switch (typeb) - { - case MST_EXPLICIT: - { - ms_explicit_t const * msebp = - (ms_explicit_t const *) &i_msbp->ms_data.as_expl; - - // Note - we may not be explicit after this ... - explicit_union(o_msap, msebp); - } - break; - - case MST_COMPRESSED: - { - // Make a copy of B since we can't modify it in place. - multiset_t mst; - memcpy(&mst, i_msbp, multiset_copy_size(i_msbp)); - // Union into the copy. - compressed_explicit_union(&mst, o_msap); - // Copy the result over the A argument. - memcpy(o_msap, &mst, multiset_copy_size(&mst)); - } - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #5"))); - break; - } - } - break; - - case MST_COMPRESSED: - { - ms_compressed_t * mscap = - (ms_compressed_t *) &o_msap->ms_data.as_comp; - - switch (typeb) - { - case MST_EXPLICIT: - { - compressed_explicit_union(o_msap, i_msbp); - } - break; - - case MST_COMPRESSED: - { - ms_compressed_t const * mscbp = - (ms_compressed_t const *) &i_msbp->ms_data.as_comp; - - // The compressed vectors must be the same length. - if (o_msap->ms_nregs != i_msbp->ms_nregs) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("union of differently length " - "compressed vectors not supported"))); - - for (unsigned ii = 0; ii < o_msap->ms_nregs; ++ii) - { - if (mscap->msc_regs[ii] < mscbp->msc_regs[ii]) - mscap->msc_regs[ii] = mscbp->msc_regs[ii]; - } - } - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #6"))); - break; - } - } - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #7"))); - break; - } -} - -double gamma_register_count_squared(int nregs); -double -gamma_register_count_squared(int nregs) -{ - if (nregs <= 8) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("number of registers too small"))); - - switch (nregs) - { - case 16: return 0.673 * nregs * nregs; - case 32: return 0.697 * nregs * nregs; - case 64: return 0.709 * nregs * nregs; - default: return (0.7213 / (1.0 + 1.079 / nregs)) * nregs * nregs; - } -} - -static double -multiset_card(multiset_t const * i_msp) -{ - size_t nbits = i_msp->ms_nbits; - size_t log2m = i_msp->ms_log2nregs; - - double retval = 0.0; - - uint64 max_register_value = (1ULL << nbits) - 1; - uint64 pw_bits = (max_register_value - 1); - uint64 total_bits = (pw_bits + log2m); - uint64 two_to_l = (1ULL << total_bits); - - double large_estimator_cutoff = (double) two_to_l/30.0; - - switch (i_msp->ms_type) - { - case MST_EMPTY: - retval = 0.0; - break; - - case MST_EXPLICIT: - { - ms_explicit_t const * msep = &i_msp->ms_data.as_expl; - return msep->mse_nelem; - } - break; - - case MST_COMPRESSED: - { - unsigned ii; - double sum; - int zero_count; - uint64_t rval; - double estimator; - - ms_compressed_t const * mscp = &i_msp->ms_data.as_comp; - size_t nregs = i_msp->ms_nregs; - - sum = 0.0; - zero_count = 0; - - for (ii = 0; ii < nregs; ++ii) - { - rval = mscp->msc_regs[ii]; - sum += 1.0 / (1L << rval); - if (rval == 0) - ++zero_count; - } - - estimator = gamma_register_count_squared(nregs) / sum; - - if ((zero_count != 0) && (estimator < (5.0 * nregs / 2.0))) - retval = nregs * log((double) nregs / zero_count); - else if (estimator <= large_estimator_cutoff) - retval = estimator; - else - return (-1 * (int64_t)two_to_l) * log(1.0 - (estimator/two_to_l)); - } - break; - - case MST_UNDEFINED: - // Our caller will convert this to a NULL. - retval = -1.0; - break; - - default: - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined multiset type value #8"))); - break; - } - - return retval; -} - -// Cardinality of a multiset. -// -PG_FUNCTION_INFO_V1(hll_cardinality); -Datum hll_cardinality(PG_FUNCTION_ARGS); -Datum -hll_cardinality(PG_FUNCTION_ARGS) -{ - double retval = 0.0; - - bytea * ab; - size_t asz; - multiset_t ms; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - multiset_unpack(&ms, (uint8_t *) VARDATA(ab), asz, NULL); - - retval = multiset_card(&ms); - - if (retval == -1.0) - PG_RETURN_NULL(); - else - PG_RETURN_FLOAT8(retval); -} - -// Union of a pair of multiset. -// -PG_FUNCTION_INFO_V1(hll_union); -Datum hll_union(PG_FUNCTION_ARGS); -Datum -hll_union(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - bytea * bb; - size_t bsz; - - bytea * cb; - size_t csz; - - multiset_t msa; - multiset_t msb; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - bb = PG_GETARG_BYTEA_P(1); - bsz = VARSIZE(bb) - VARHDRSZ; - - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - multiset_unpack(&msb, (uint8_t *) VARDATA(bb), bsz, NULL); - - check_metadata(&msa, &msb); - - multiset_union(&msa, &msb); - - csz = multiset_packed_size(&msa); - cb = (bytea *) palloc(VARHDRSZ + csz); - SET_VARSIZE(cb, VARHDRSZ + csz); - - multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); - - PG_RETURN_BYTEA_P(cb); -} - -// Add an integer hash to a multiset. -// -PG_FUNCTION_INFO_V1(hll_add); -Datum hll_add(PG_FUNCTION_ARGS); -Datum -hll_add(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - int64 val; - - bytea * cb; - size_t csz; - - multiset_t msa; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - val = PG_GETARG_INT64(1); - - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - multiset_add(&msa, val); - - csz = multiset_packed_size(&msa); - cb = (bytea *) palloc(VARHDRSZ + csz); - SET_VARSIZE(cb, VARHDRSZ + csz); - - multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); - - PG_RETURN_BYTEA_P(cb); -} - -// Add a multiset to an integer hash. -// -PG_FUNCTION_INFO_V1(hll_add_rev); -Datum hll_add_rev(PG_FUNCTION_ARGS); -Datum -hll_add_rev(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - int64 val; - - bytea * cb; - size_t csz; - - multiset_t msa; - - val = PG_GETARG_INT64(0); - - ab = PG_GETARG_BYTEA_P(1); - asz = VARSIZE(ab) - VARHDRSZ; - - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - multiset_add(&msa, val); - - csz = multiset_packed_size(&msa); - cb = (bytea *) palloc(VARHDRSZ + csz); - SET_VARSIZE(cb, VARHDRSZ + csz); - - multiset_pack(&msa, (uint8_t *) VARDATA(cb), csz); - - PG_RETURN_BYTEA_P(cb); -} - -// Pretty-print a multiset -// -PG_FUNCTION_INFO_V1(hll_print); -Datum hll_print(PG_FUNCTION_ARGS); -Datum -hll_print(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - char * retstr; - multiset_t msa; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - retstr = multiset_tostring(&msa); - - PG_RETURN_CSTRING(retstr); -} - -// Create an empty multiset with parameters. -// -PG_FUNCTION_INFO_V1(hll_empty4); -Datum hll_empty4(PG_FUNCTION_ARGS); -Datum -hll_empty4(PG_FUNCTION_ARGS) -{ - bytea * cb; - size_t csz; - - int32 log2m = PG_GETARG_INT32(0); - int32 regwidth = PG_GETARG_INT32(1); - int64 expthresh = PG_GETARG_INT64(2); - int32 sparseon = PG_GETARG_INT32(3); - - multiset_t ms; - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(&ms, '\0', sizeof(ms)); - - ms.ms_type = MST_EMPTY; - ms.ms_nbits = regwidth; - ms.ms_nregs = 1 << log2m; - ms.ms_log2nregs = log2m; - ms.ms_expthresh = expthresh; - ms.ms_sparseon = sparseon; - - csz = multiset_packed_size(&ms); - cb = (bytea *) palloc(VARHDRSZ + csz); - SET_VARSIZE(cb, VARHDRSZ + csz); - - multiset_pack(&ms, (uint8_t *) VARDATA(cb), csz); - - PG_RETURN_BYTEA_P(cb); -} - -// Create an empty multiset with parameters. -// -PG_FUNCTION_INFO_V1(hll_empty3); -Datum hll_empty3(PG_FUNCTION_ARGS); -Datum -hll_empty3(PG_FUNCTION_ARGS) -{ - PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(2), - Int32GetDatum(g_default_sparseon))); -} - -// Create an empty multiset with parameters. -// -PG_FUNCTION_INFO_V1(hll_empty2); -Datum hll_empty2(PG_FUNCTION_ARGS); -Datum -hll_empty2(PG_FUNCTION_ARGS) -{ - PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1), - Int64GetDatum(g_default_expthresh), - Int32GetDatum(g_default_sparseon))); -} - -// Create an empty multiset with parameters. -// -PG_FUNCTION_INFO_V1(hll_empty1); -Datum hll_empty1(PG_FUNCTION_ARGS); -Datum -hll_empty1(PG_FUNCTION_ARGS) -{ - PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, - PG_GETARG_DATUM(0), - Int32GetDatum(g_default_regwidth), - Int64GetDatum(g_default_expthresh), - Int32GetDatum(g_default_sparseon))); -} - -// Create an empty multiset with parameters. -// -PG_FUNCTION_INFO_V1(hll_empty0); -Datum hll_empty0(PG_FUNCTION_ARGS); -Datum -hll_empty0(PG_FUNCTION_ARGS) -{ - PG_RETURN_DATUM(DirectFunctionCall4(hll_empty4, - Int32GetDatum(g_default_log2m), - Int32GetDatum(g_default_regwidth), - Int64GetDatum(g_default_expthresh), - Int32GetDatum(g_default_sparseon))); -} - -// Returns the schema version of an hll. -// -PG_FUNCTION_INFO_V1(hll_schema_version); -Datum hll_schema_version(PG_FUNCTION_ARGS); -Datum -hll_schema_version(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - uint8_t vers; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - vers = multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - PG_RETURN_INT32(vers); -} - -// Returns the type of an hll. -// -PG_FUNCTION_INFO_V1(hll_type); -Datum hll_type(PG_FUNCTION_ARGS); -Datum -hll_type(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - uint8_t type; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, &type); - - PG_RETURN_INT32(type); -} - -// Returns the log2m of an hll. -// -PG_FUNCTION_INFO_V1(hll_log2m); -Datum hll_log2m(PG_FUNCTION_ARGS); -Datum -hll_log2m(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - PG_RETURN_INT32(msa.ms_log2nregs); -} - -// Returns the regwidth of an hll. -// -PG_FUNCTION_INFO_V1(hll_regwidth); -Datum hll_regwidth(PG_FUNCTION_ARGS); -Datum -hll_regwidth(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - PG_RETURN_INT32(msa.ms_nbits); -} - -// Returns the expthresh of an hll. -// -PG_FUNCTION_INFO_V1(hll_expthresh); -Datum hll_expthresh(PG_FUNCTION_ARGS); -Datum -hll_expthresh(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - - size_t nbits; - size_t nregs; - int64 expthresh; - - int64 effective; - - Datum result; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - nbits = msa.ms_nbits; - nregs = msa.ms_nregs; - expthresh = msa.ms_expthresh; - - effective = expthresh_value(expthresh, nbits, nregs); - - // Build the result tuple. - { - TupleDesc tupleDesc; - int j; - char * values[2]; - HeapTuple tuple; - - /* Build a tuple descriptor for our result type */ - if (get_call_result_type(fcinfo, NULL, &tupleDesc) != - TYPEFUNC_COMPOSITE) - elog(ERROR, "return type must be a row type"); - - j = 0; - - values[j] = palloc(32); - snprintf(values[j++], 32, INT64_FORMAT, expthresh); - values[j] = palloc(32); - snprintf(values[j++], 32, INT64_FORMAT, effective); - - tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), - values); - - result = HeapTupleGetDatum(tuple); - } - - PG_RETURN_DATUM(result); -} - -// Returns the sparseon of an hll. -// -PG_FUNCTION_INFO_V1(hll_sparseon); -Datum hll_sparseon(PG_FUNCTION_ARGS); -Datum -hll_sparseon(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - multiset_t msa; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - // Unpack the multiset. - multiset_unpack(&msa, (uint8_t *) VARDATA(ab), asz, NULL); - - PG_RETURN_INT32(msa.ms_sparseon); -} - -// Set the output version. -// -PG_FUNCTION_INFO_V1(hll_set_output_version); -Datum hll_set_output_version(PG_FUNCTION_ARGS); -Datum -hll_set_output_version(PG_FUNCTION_ARGS) -{ - int32 old_vers = g_output_version; - int32 vers = PG_GETARG_INT32(0); - - if (vers != 1) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("output version must be 1"))); - - g_output_version = vers; - - PG_RETURN_INT32(old_vers); -} - -// Set sparse to full compressed threshold to fixed value. -// -PG_FUNCTION_INFO_V1(hll_set_max_sparse); -Datum hll_set_max_sparse(PG_FUNCTION_ARGS); -Datum -hll_set_max_sparse(PG_FUNCTION_ARGS) -{ - int32 old_maxsparse = g_max_sparse; - int32 maxsparse = PG_GETARG_INT32(0); - - if (maxsparse < -1) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("sparse threshold must be in range [-1,MAXINT]"))); - - g_max_sparse = maxsparse; - - PG_RETURN_INT32(old_maxsparse); -} - -// Change the default type modifier, empty and add aggregate defaults. -// -PG_FUNCTION_INFO_V1(hll_set_defaults); -Datum hll_set_defaults(PG_FUNCTION_ARGS); -Datum -hll_set_defaults(PG_FUNCTION_ARGS) -{ - int32 old_log2m = g_default_log2m; - int32 old_regwidth = g_default_regwidth; - int64 old_expthresh = g_default_expthresh; - int32 old_sparseon = g_default_sparseon; - - int32 log2m = PG_GETARG_INT32(0); - int32 regwidth = PG_GETARG_INT32(1); - int64 expthresh = PG_GETARG_INT64(2); - int32 sparseon = PG_GETARG_INT32(3); - - Datum result; - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - g_default_log2m = log2m; - g_default_regwidth = regwidth; - g_default_expthresh = expthresh; - g_default_sparseon = sparseon; - - // Build the result tuple. - { - TupleDesc tupleDesc; - int j; - char * values[4]; - HeapTuple tuple; - - /* Build a tuple descriptor for our result type */ - if (get_call_result_type(fcinfo, NULL, &tupleDesc) != - TYPEFUNC_COMPOSITE) - elog(ERROR, "return type must be a row type"); - - j = 0; - values[j] = palloc(32); - snprintf(values[j++], 32, "%d", old_log2m); - values[j] = palloc(32); - snprintf(values[j++], 32, "%d", old_regwidth); - values[j] = palloc(32); - snprintf(values[j++], 32, INT64_FORMAT, old_expthresh); - values[j] = palloc(32); - snprintf(values[j++], 32, "%d", old_sparseon); - - tuple = BuildTupleFromCStrings(TupleDescGetAttInMetadata(tupleDesc), - values); - - result = HeapTupleGetDatum(tuple); - } - - PG_RETURN_DATUM(result); -} - -// Hash a 1 byte fixed-size object. -// -PG_FUNCTION_INFO_V1(hll_hash_1byte); -Datum hll_hash_1byte(PG_FUNCTION_ARGS); -Datum -hll_hash_1byte(PG_FUNCTION_ARGS) -{ - char key = PG_GETARG_CHAR(0); - int32 seed = PG_GETARG_INT32(1); - uint64 out[2]; - - if (seed < 0) - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("negative seed values not compatible"))); - - MurmurHash3_x64_128(&key, sizeof(key), seed, out); - - PG_RETURN_INT64(out[0]); -} - - -// Hash a 2 byte fixed-size object. -// -PG_FUNCTION_INFO_V1(hll_hash_2byte); -Datum hll_hash_2byte(PG_FUNCTION_ARGS); -Datum -hll_hash_2byte(PG_FUNCTION_ARGS) -{ - int16 key = PG_GETARG_INT16(0); - int32 seed = PG_GETARG_INT32(1); - uint64 out[2]; - - if (seed < 0) - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("negative seed values not compatible"))); - - MurmurHash3_x64_128(&key, sizeof(key), seed, out); - - PG_RETURN_INT64(out[0]); -} - -// Hash a 4 byte fixed-size object. -// -PG_FUNCTION_INFO_V1(hll_hash_4byte); -Datum hll_hash_4byte(PG_FUNCTION_ARGS); -Datum -hll_hash_4byte(PG_FUNCTION_ARGS) -{ - int32 key = PG_GETARG_INT32(0); - int32 seed = PG_GETARG_INT32(1); - uint64 out[2]; - - if (seed < 0) - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("negative seed values not compatible"))); - - MurmurHash3_x64_128(&key, sizeof(key), seed, out); - - PG_RETURN_INT64(out[0]); -} - -// Hash an 8 byte fixed-size object. -// -PG_FUNCTION_INFO_V1(hll_hash_8byte); -Datum hll_hash_8byte(PG_FUNCTION_ARGS); -Datum -hll_hash_8byte(PG_FUNCTION_ARGS) -{ - int64 key = PG_GETARG_INT64(0); - int32 seed = PG_GETARG_INT32(1); - uint64 out[2]; - - if (seed < 0) - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("negative seed values not compatible"))); - - MurmurHash3_x64_128(&key, sizeof(key), seed, out); - - PG_RETURN_INT64(out[0]); -} - -// Hash a varlena object. -// -PG_FUNCTION_INFO_V1(hll_hash_varlena); -Datum hll_hash_varlena(PG_FUNCTION_ARGS); -Datum -hll_hash_varlena(PG_FUNCTION_ARGS) -{ - struct varlena * vlap = PG_GETARG_VARLENA_PP(0); - - void * keyp = VARDATA_ANY(vlap); - int len = VARSIZE_ANY_EXHDR(vlap); - - int32 seed = PG_GETARG_INT32(1); - - uint64 out[2]; - - if (seed < 0) - ereport(WARNING, - (errcode(ERRCODE_WARNING), - errmsg("negative seed values not compatible"))); - - MurmurHash3_x64_128(keyp, len, seed, out); - - /* Avoid leaking memory for toasted inputs */ - PG_FREE_IF_COPY(vlap, 0); - - PG_RETURN_INT64(out[0]); -} - - -// Hash any scalar data type. -// -PG_FUNCTION_INFO_V1(hll_hash_any); -Datum hll_hash_any(PG_FUNCTION_ARGS); -Datum -hll_hash_any(PG_FUNCTION_ARGS) -{ - Datum keyDatum = PG_GETARG_DATUM(0); - Datum seedDatum = PG_GETARG_DATUM(1); - Datum hashResultDatum = 0; - - Oid keyTypeId = get_fn_expr_argtype(fcinfo->flinfo, 0); - int16 keyTypeLength = get_typlen(keyTypeId); - - /* dispatch to corresponding hash function for key type */ - switch (keyTypeLength) - { - case 1: - hashResultDatum = DirectFunctionCall2(hll_hash_1byte, keyDatum, seedDatum); - break; - - case 2: - hashResultDatum = DirectFunctionCall2(hll_hash_2byte, keyDatum, seedDatum); - break; - - case 4: - hashResultDatum = DirectFunctionCall2(hll_hash_4byte, keyDatum, seedDatum); - break; - - case 8: - hashResultDatum = DirectFunctionCall2(hll_hash_8byte, keyDatum, seedDatum); - break; - - case -1: - case -2: - hashResultDatum = DirectFunctionCall2(hll_hash_varlena, keyDatum, seedDatum); - break; - - default: - { - /* - * We have a fixed-size type such as char(10), macaddr, circle, etc. We - * first convert this type to its variable-length binary representation - * and then dispatch to the variable-length hashing function. - */ - Oid keyTypeSendFunction = InvalidOid; - bool keyTypeVarlena = false; - Datum keyBinaryDatum = 0; - - /* no need to worry about SPI for these types' output functions */ - getTypeBinaryOutputInfo(keyTypeId, &keyTypeSendFunction, &keyTypeVarlena); - keyBinaryDatum = OidFunctionCall1(keyTypeSendFunction, keyDatum); - - hashResultDatum = DirectFunctionCall2(hll_hash_varlena, keyBinaryDatum, - seedDatum); - break; - } - } - - PG_RETURN_INT64(hashResultDatum); -} - - -PG_FUNCTION_INFO_V1(hll_eq); -Datum hll_eq(PG_FUNCTION_ARGS); -Datum -hll_eq(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - bytea * bb; - size_t bsz; - bool retval; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - bb = PG_GETARG_BYTEA_P(1); - bsz = VARSIZE(bb) - VARHDRSZ; - - if (asz != bsz) - { - retval = false; - } - else - { - void const * ap = VARDATA(ab); - void const * bp = VARDATA(bb); - int rv = memcmp(ap, bp, asz); - retval = rv == 0; - } - - PG_FREE_IF_COPY(ab, 0); - PG_FREE_IF_COPY(bb, 1); - PG_RETURN_BOOL(retval); -} - -PG_FUNCTION_INFO_V1(hll_ne); -Datum hll_ne(PG_FUNCTION_ARGS); -Datum -hll_ne(PG_FUNCTION_ARGS) -{ - bytea * ab; - size_t asz; - bytea * bb; - size_t bsz; - bool retval; - - ab = PG_GETARG_BYTEA_P(0); - asz = VARSIZE(ab) - VARHDRSZ; - - bb = PG_GETARG_BYTEA_P(1); - bsz = VARSIZE(bb) - VARHDRSZ; - - if (asz != bsz) - { - retval = true; - } - else - { - void const * ap = VARDATA(ab); - void const * bp = VARDATA(bb); - int rv = memcmp(ap, bp, asz); - retval = rv != 0; - } - - PG_FREE_IF_COPY(ab, 0); - PG_FREE_IF_COPY(bb, 1); - PG_RETURN_BOOL(retval); -} - -// This function creates a multiset_t in a temporary context. -// -multiset_t * setup_multiset(MemoryContext rcontext); -multiset_t * -setup_multiset(MemoryContext rcontext) -{ - MemoryContext tmpcontext; - MemoryContext oldcontext; - multiset_t * msp; - - tmpcontext = AllocSetContextCreate(rcontext, - "multiset", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); - - oldcontext = MemoryContextSwitchTo(tmpcontext); - - msp = (multiset_t *) palloc(sizeof(multiset_t)); - - msp->ms_type = MST_UNINIT; - - MemoryContextSwitchTo(oldcontext); - - return msp; -} - -// Union aggregate transition function, first arg unpacked, second packed. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_union_trans); -Datum hll_union_trans(PG_FUNCTION_ARGS); -Datum -hll_union_trans(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - bytea * bb; - size_t bsz; - - multiset_t * msap; - - multiset_t msb; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_union_trans outside transition context"))); - - // Is the first argument a NULL? - if (PG_ARGISNULL(0)) - { - msap = setup_multiset(aggctx); - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - // This is the packed "argument" vector. - bb = PG_GETARG_BYTEA_P(1); - bsz = VARSIZE(bb) - VARHDRSZ; - - multiset_unpack(&msb, (uint8_t *) VARDATA(bb), bsz, NULL); - - // Was the first argument uninitialized? - if (msap->ms_type == MST_UNINIT) - { - // Yes, clone the metadata from the second arg. - copy_metadata(msap, &msb); - msap->ms_type = MST_EMPTY; - } - else - { - // Nope, make sure the metadata is compatible. - check_metadata(msap, &msb); - } - - multiset_union(msap, &msb); - } - - PG_RETURN_POINTER(msap); -} - -// Add aggregate transition function. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_add_trans4); -Datum hll_add_trans4(PG_FUNCTION_ARGS); -Datum -hll_add_trans4(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_add_trans4 outside transition context"))); - - // If the first argument is a NULL on first call, init an hll_empty - if (PG_ARGISNULL(0)) - { - int32 log2m = PG_GETARG_INT32(2); - int32 regwidth = PG_GETARG_INT32(3); - int64 expthresh = PG_GETARG_INT64(4); - int32 sparseon = PG_GETARG_INT32(5); - - msap = setup_multiset(aggctx); - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(msap, '\0', sizeof(multiset_t)); - - msap->ms_type = MST_EMPTY; - msap->ms_nbits = regwidth; - msap->ms_nregs = 1 << log2m; - msap->ms_log2nregs = log2m; - msap->ms_expthresh = expthresh; - msap->ms_sparseon = sparseon; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - int64 val = PG_GETARG_INT64(1); - - multiset_add(msap, val); - } - - PG_RETURN_POINTER(msap); -} - -// Add aggregate transition function. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_add_trans3); -Datum hll_add_trans3(PG_FUNCTION_ARGS); -Datum -hll_add_trans3(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_add_trans3 outside transition context"))); - - // If the first argument is a NULL on first call, init an hll_empty - if (PG_ARGISNULL(0)) - { - int32 log2m = PG_GETARG_INT32(2); - int32 regwidth = PG_GETARG_INT32(3); - int64 expthresh = PG_GETARG_INT64(4); - int32 sparseon = g_default_sparseon; - - msap = setup_multiset(aggctx); - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(msap, '\0', sizeof(multiset_t)); - - msap->ms_type = MST_EMPTY; - msap->ms_nbits = regwidth; - msap->ms_nregs = 1 << log2m; - msap->ms_log2nregs = log2m; - msap->ms_expthresh = expthresh; - msap->ms_sparseon = sparseon; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - int64 val = PG_GETARG_INT64(1); - - multiset_add(msap, val); - } - - PG_RETURN_POINTER(msap); -} - -// Add aggregate transition function. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_add_trans2); -Datum hll_add_trans2(PG_FUNCTION_ARGS); -Datum -hll_add_trans2(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_add_trans2 outside transition context"))); - - // If the first argument is a NULL on first call, init an hll_empty - if (PG_ARGISNULL(0)) - { - int32 log2m = PG_GETARG_INT32(2); - int32 regwidth = PG_GETARG_INT32(3); - int64 expthresh = g_default_expthresh; - int32 sparseon = g_default_sparseon; - - msap = setup_multiset(aggctx); - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(msap, '\0', sizeof(multiset_t)); - - msap->ms_type = MST_EMPTY; - msap->ms_nbits = regwidth; - msap->ms_nregs = 1 << log2m; - msap->ms_log2nregs = log2m; - msap->ms_expthresh = expthresh; - msap->ms_sparseon = sparseon; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - int64 val = PG_GETARG_INT64(1); - - multiset_add(msap, val); - } - - PG_RETURN_POINTER(msap); -} - -// Add aggregate transition function. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_add_trans1); -Datum hll_add_trans1(PG_FUNCTION_ARGS); -Datum -hll_add_trans1(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_add_trans1 outside transition context"))); - - // If the first argument is a NULL on first call, init an hll_empty - if (PG_ARGISNULL(0)) - { - int32 log2m = PG_GETARG_INT32(2); - int32 regwidth = g_default_regwidth; - int64 expthresh = g_default_expthresh; - int32 sparseon = g_default_sparseon; - - msap = setup_multiset(aggctx); - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(msap, '\0', sizeof(multiset_t)); - - msap->ms_type = MST_EMPTY; - msap->ms_nbits = regwidth; - msap->ms_nregs = 1 << log2m; - msap->ms_log2nregs = log2m; - msap->ms_expthresh = expthresh; - msap->ms_sparseon = sparseon; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - int64 val = PG_GETARG_INT64(1); - - multiset_add(msap, val); - } - - PG_RETURN_POINTER(msap); -} - -// Add aggregate transition function. -// -// NOTE - This function is not declared STRICT, it is initialized with -// a NULL ... -// -PG_FUNCTION_INFO_V1(hll_add_trans0); -Datum hll_add_trans0(PG_FUNCTION_ARGS); -Datum -hll_add_trans0(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_add_trans0 outside transition context"))); - - // If the first argument is a NULL on first call, init an hll_empty - if (PG_ARGISNULL(0)) - { - int32 log2m = g_default_log2m; - int32 regwidth = g_default_regwidth; - int64 expthresh = g_default_expthresh; - int32 sparseon = g_default_sparseon; - - msap = setup_multiset(aggctx); - - check_modifiers(log2m, regwidth, expthresh, sparseon); - - memset(msap, '\0', sizeof(multiset_t)); - - msap->ms_type = MST_EMPTY; - msap->ms_nbits = regwidth; - msap->ms_nregs = 1 << log2m; - msap->ms_log2nregs = log2m; - msap->ms_expthresh = expthresh; - msap->ms_sparseon = sparseon; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - } - - // Is the second argument non-null? - if (!PG_ARGISNULL(1)) - { - int64 val = PG_GETARG_INT64(1); - - multiset_add(msap, val); - } - - PG_RETURN_POINTER(msap); -} - -// Final function, converts multiset_t into packed format. -// -PG_FUNCTION_INFO_V1(hll_pack); -Datum hll_pack(PG_FUNCTION_ARGS); -Datum -hll_pack(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - bytea * cb; - size_t csz; - - multiset_t * msap; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_pack outside aggregate context"))); - - // Is the first argument a NULL? - if (PG_ARGISNULL(0)) - { - PG_RETURN_NULL(); - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - - // Was the aggregation uninitialized? - if (msap->ms_type == MST_UNINIT) - { - PG_RETURN_NULL(); - } - else - { - csz = multiset_packed_size(msap); - cb = (bytea *) palloc(VARHDRSZ + csz); - SET_VARSIZE(cb, VARHDRSZ + csz); - - multiset_pack(msap, (uint8_t *) VARDATA(cb), csz); - - // We don't need to pfree the msap memory because it is zone - // allocated inside postgres. - // - // Furthermore, sometimes final functions are called multiple - // times so deallocating it the first time leads to badness. - - PG_RETURN_BYTEA_P(cb); - } - } -} - -// Final function, computes cardinality of unpacked bytea. -// -PG_FUNCTION_INFO_V1(hll_card_unpacked); -Datum hll_card_unpacked(PG_FUNCTION_ARGS); -Datum -hll_card_unpacked(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - double retval; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_card_unpacked outside aggregate context"))); - - // Is the first argument a NULL? - if (PG_ARGISNULL(0)) - { - retval = -1.0; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - - if (msap->ms_type == MST_UNINIT) - { - retval = -1.0; - } - else - { - retval = multiset_card(msap); - } - - // We don't need to pfree the msap memory because it is zone - // allocated inside postgres. - // - // Furthermore, sometimes final functions are called multiple - // times so deallocating it the first time leads to badness. - } - - if (retval == -1.0) - PG_RETURN_NULL(); - else - PG_RETURN_FLOAT8(retval); -} - -// Final function, computes floor of cardinality of multiset_t. -// -PG_FUNCTION_INFO_V1(hll_floor_card_unpacked); -Datum hll_floor_card_unpacked(PG_FUNCTION_ARGS); -Datum -hll_floor_card_unpacked(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - double retval; - int64_t floorval; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_floor_card_unpacked " - "outside aggregate context"))); - - // Is the first argument a NULL? - if (PG_ARGISNULL(0)) - { - retval = -1.0; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - - if (msap->ms_type == MST_UNINIT) - { - retval = -1.0; - } - else - { - retval = multiset_card(msap); - } - - // NOTE - The following comment from array_agg_final suggests we - // should not free the memory here: - // - // "Make the result. We cannot release the ArrayBuildState - // because sometimes aggregate final functions are - // re-executed. Rather, it is nodeAgg.c's responsibility to reset the - // aggcontext when it's safe to do so." - } - - if (retval == -1.0) - { - PG_RETURN_NULL(); - } - else - { - // Take the floor of the value. - floorval = (int64) floor(retval); - PG_RETURN_INT64(floorval); - } -} - -// Final function, computes ceil of cardinality of multiset_t. -// -PG_FUNCTION_INFO_V1(hll_ceil_card_unpacked); -Datum hll_ceil_card_unpacked(PG_FUNCTION_ARGS); -Datum -hll_ceil_card_unpacked(PG_FUNCTION_ARGS) -{ - MemoryContext aggctx; - - multiset_t * msap; - - double retval; - int64_t ceilval; - - // We must be called as a transition routine or we fail. - if (!AggCheckCallContext(fcinfo, &aggctx)) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("hll_ceil_card_unpacked outside aggregate context"))); - - // Is the first argument a NULL? - if (PG_ARGISNULL(0)) - { - retval = -1.0; - } - else - { - msap = (multiset_t *) PG_GETARG_POINTER(0); - - if (msap->ms_type == MST_UNINIT) - { - retval = -1.0; - } - else - { - retval = multiset_card(msap); - } - - // We don't need to pfree the msap memory because it is zone - // allocated inside postgres. - // - // Furthermore, sometimes final functions are called multiple - // times so deallocating it the first time leads to badness. - } - - if (retval == -1.0) - { - PG_RETURN_NULL(); - } - else - { - // Take the ceil of the value. - ceilval = (int64) ceil(retval); - PG_RETURN_INT64(ceilval); - } -} - -PG_FUNCTION_INFO_V1(hll_recv); -Datum hll_recv(PG_FUNCTION_ARGS); -Datum -hll_recv(PG_FUNCTION_ARGS) -{ - Datum dd = DirectFunctionCall1(bytearecv, PG_GETARG_DATUM(0)); - return dd; -} - -PG_FUNCTION_INFO_V1(hll_send); -Datum hll_send(PG_FUNCTION_ARGS); -Datum -hll_send(PG_FUNCTION_ARGS) -{ - Datum dd = PG_GETARG_DATUM(0); - bytea* bp = DatumGetByteaP(dd); - StringInfoData buf; - pq_begintypsend(&buf); - pq_sendbytes(&buf, VARDATA(bp), VARSIZE(bp) - VARHDRSZ); - PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); -} diff -uprN postgresql-hll-2.14_old/src/MurmurHash3.cpp postgresql-hll-2.14/src/MurmurHash3.cpp --- postgresql-hll-2.14_old/src/MurmurHash3.cpp 2019-11-15 18:39:18.000000000 +0800 +++ postgresql-hll-2.14/src/MurmurHash3.cpp 1970-01-01 08:00:00.000000000 +0800 @@ -1,340 +0,0 @@ -// **************************************************************************** -// This file originally from: -// http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp -// **************************************************************************** - -//----------------------------------------------------------------------------- -// MurmurHash3 was written by Austin Appleby, and is placed in the public -// domain. The author hereby disclaims copyright to this source code. - -// Note - The x86 and x64 versions do _not_ produce the same results, as the -// algorithms are optimized for their respective platforms. You can still -// compile and run any of them on any platform, but your performance with the -// non-native version will be less than optimal. - -#include "MurmurHash3.h" - -//----------------------------------------------------------------------------- -// Platform-specific functions and macros - -// Microsoft Visual Studio - -#if defined(_MSC_VER) - -#define FORCE_INLINE __forceinline - -#include - -#define ROTL32(x,y) _rotl(x,y) -#define ROTL64(x,y) _rotl64(x,y) - -#define BIG_CONSTANT(x) (x) - -// Other compilers - -#else // defined(_MSC_VER) - -#define FORCE_INLINE __attribute__((always_inline)) inline - -inline uint32_t rotl32 ( uint32_t x, int8_t r ) -{ - return (x << r) | (x >> (32 - r)); -} - -inline uint64_t rotl64 ( uint64_t x, int8_t r ) -{ - return (x << r) | (x >> (64 - r)); -} - -#define ROTL32(x,y) rotl32(x,y) -#define ROTL64(x,y) rotl64(x,y) - -#define BIG_CONSTANT(x) (x##LLU) - -#endif // !defined(_MSC_VER) - -//----------------------------------------------------------------------------- -// Block read - if your platform needs to do endian-swapping or can only -// handle aligned reads, do the conversion here - -FORCE_INLINE uint32_t getblock ( const uint32_t * p, int i ) -{ - return p[i]; -} - -FORCE_INLINE uint64_t getblock ( const uint64_t * p, int i ) -{ - return p[i]; -} - -//----------------------------------------------------------------------------- -// Finalization mix - force all bits of a hash block to avalanche - -FORCE_INLINE uint32_t fmix ( uint32_t h ) -{ - h ^= h >> 16; - h *= 0x85ebca6b; - h ^= h >> 13; - h *= 0xc2b2ae35; - h ^= h >> 16; - - return h; -} - -//---------- - -FORCE_INLINE uint64_t fmix ( uint64_t k ) -{ - k ^= k >> 33; - k *= BIG_CONSTANT(0xff51afd7ed558ccd); - k ^= k >> 33; - k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53); - k ^= k >> 33; - - return k; -} - -//----------------------------------------------------------------------------- - -void MurmurHash3_x86_32 ( const void * key, int len, - uint32_t seed, void * out ) -{ - const uint8_t * data = (const uint8_t*)key; - const int nblocks = len / 4; - - uint32_t h1 = seed; - - const uint32_t c1 = 0xcc9e2d51; - const uint32_t c2 = 0x1b873593; - - //---------- - // body - - const uint32_t * blocks = (const uint32_t *)(data + nblocks*4); - - for(int i = -nblocks; i; i++) - { - uint32_t k1 = getblock(blocks,i); - - k1 *= c1; - k1 = ROTL32(k1,15); - k1 *= c2; - - h1 ^= k1; - h1 = ROTL32(h1,13); - h1 = h1*5+0xe6546b64; - } - - //---------- - // tail - - const uint8_t * tail = (const uint8_t*)(data + nblocks*4); - - uint32_t k1 = 0; - - switch(len & 3) - { - case 3: k1 ^= tail[2] << 16; - case 2: k1 ^= tail[1] << 8; - case 1: k1 ^= tail[0]; - k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; - }; - - //---------- - // finalization - - h1 ^= len; - - h1 = fmix(h1); - - *(uint32_t*)out = h1; -} - -//----------------------------------------------------------------------------- - -void MurmurHash3_x86_128 ( const void * key, const int len, - uint32_t seed, void * out ) -{ - const uint8_t * data = (const uint8_t*)key; - const int nblocks = len / 16; - - uint32_t h1 = seed; - uint32_t h2 = seed; - uint32_t h3 = seed; - uint32_t h4 = seed; - - const uint32_t c1 = 0x239b961b; - const uint32_t c2 = 0xab0e9789; - const uint32_t c3 = 0x38b34ae5; - const uint32_t c4 = 0xa1e38b93; - - //---------- - // body - - const uint32_t * blocks = (const uint32_t *)(data + nblocks*16); - - for(int i = -nblocks; i; i++) - { - uint32_t k1 = getblock(blocks,i*4+0); - uint32_t k2 = getblock(blocks,i*4+1); - uint32_t k3 = getblock(blocks,i*4+2); - uint32_t k4 = getblock(blocks,i*4+3); - - k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; - - h1 = ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b; - - k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; - - h2 = ROTL32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747; - - k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; - - h3 = ROTL32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35; - - k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; - - h4 = ROTL32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17; - } - - //---------- - // tail - - const uint8_t * tail = (const uint8_t*)(data + nblocks*16); - - uint32_t k1 = 0; - uint32_t k2 = 0; - uint32_t k3 = 0; - uint32_t k4 = 0; - - switch(len & 15) - { - case 15: k4 ^= tail[14] << 16; - case 14: k4 ^= tail[13] << 8; - case 13: k4 ^= tail[12] << 0; - k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; - - case 12: k3 ^= tail[11] << 24; - case 11: k3 ^= tail[10] << 16; - case 10: k3 ^= tail[ 9] << 8; - case 9: k3 ^= tail[ 8] << 0; - k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; - - case 8: k2 ^= tail[ 7] << 24; - case 7: k2 ^= tail[ 6] << 16; - case 6: k2 ^= tail[ 5] << 8; - case 5: k2 ^= tail[ 4] << 0; - k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; - - case 4: k1 ^= tail[ 3] << 24; - case 3: k1 ^= tail[ 2] << 16; - case 2: k1 ^= tail[ 1] << 8; - case 1: k1 ^= tail[ 0] << 0; - k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; - }; - - //---------- - // finalization - - h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len; - - h1 += h2; h1 += h3; h1 += h4; - h2 += h1; h3 += h1; h4 += h1; - - h1 = fmix(h1); - h2 = fmix(h2); - h3 = fmix(h3); - h4 = fmix(h4); - - h1 += h2; h1 += h3; h1 += h4; - h2 += h1; h3 += h1; h4 += h1; - - ((uint32_t*)out)[0] = h1; - ((uint32_t*)out)[1] = h2; - ((uint32_t*)out)[2] = h3; - ((uint32_t*)out)[3] = h4; -} - -//----------------------------------------------------------------------------- - -void MurmurHash3_x64_128 ( const void * key, const int len, - const uint32_t seed, void * out ) -{ - const uint8_t * data = (const uint8_t*)key; - const int nblocks = len / 16; - - uint64_t h1 = seed; - uint64_t h2 = seed; - - const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5); - const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f); - - //---------- - // body - - const uint64_t * blocks = (const uint64_t *)(data); - - for(int i = 0; i < nblocks; i++) - { - uint64_t k1 = getblock(blocks,i*2+0); - uint64_t k2 = getblock(blocks,i*2+1); - - k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; - - h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729; - - k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - - h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5; - } - - //---------- - // tail - - const uint8_t * tail = (const uint8_t*)(data + nblocks*16); - - uint64_t k1 = 0; - uint64_t k2 = 0; - - switch(len & 15) - { - case 15: k2 ^= uint64_t(tail[14]) << 48; - case 14: k2 ^= uint64_t(tail[13]) << 40; - case 13: k2 ^= uint64_t(tail[12]) << 32; - case 12: k2 ^= uint64_t(tail[11]) << 24; - case 11: k2 ^= uint64_t(tail[10]) << 16; - case 10: k2 ^= uint64_t(tail[ 9]) << 8; - case 9: k2 ^= uint64_t(tail[ 8]) << 0; - k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - - case 8: k1 ^= uint64_t(tail[ 7]) << 56; - case 7: k1 ^= uint64_t(tail[ 6]) << 48; - case 6: k1 ^= uint64_t(tail[ 5]) << 40; - case 5: k1 ^= uint64_t(tail[ 4]) << 32; - case 4: k1 ^= uint64_t(tail[ 3]) << 24; - case 3: k1 ^= uint64_t(tail[ 2]) << 16; - case 2: k1 ^= uint64_t(tail[ 1]) << 8; - case 1: k1 ^= uint64_t(tail[ 0]) << 0; - k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; - }; - - //---------- - // finalization - - h1 ^= len; h2 ^= len; - - h1 += h2; - h2 += h1; - - h1 = fmix(h1); - h2 = fmix(h2); - - h1 += h2; - h2 += h1; - - ((uint64_t*)out)[0] = h1; - ((uint64_t*)out)[1] = h2; -} - -//----------------------------------------------------------------------------- -